changeset 13899:0bcf78798346

3311 Want a test framework for arbitrary OS unit tests 3312 Add a testrunner package for OS unit tests 3313 Add a testrunner package to convert ZFS tests from STF Reviewed by: Matt Ahrens <matthew.ahrens@delphix.com> Reviewed by: Will Guyette <will.guyette@delphix.com> Reviewed by: Dan Kimmel <dan.kimmel@delphix.com> Reviewed by: Adam Leventhal <ahl@delphix.com> Reviewed by: Henrik Mattson <henrik.mattson@delphix.com> Reviewed by: Sonu Pillai <sonu.pillai@delphix.com> Reviewed by: Christopher Siden <chris.siden@delphix.com> Reviewed by: George Wilson <george.wilson@delphix.com> Reviewed by: Richard Lowe <richlowe@richlowe.net> Approved by: Richard Lowe <richlowe@richlowe.net>
author John Wren Kennedy <john.kennedy@delphix.com>
date Wed, 05 Dec 2012 22:04:50 -0500
parents 7f822b09519b
children 660fc1013b42
files exception_lists/keywords usr/src/Makefile usr/src/Makefile.lint usr/src/pkg/manifests/system-test-ostest.mf usr/src/pkg/manifests/system-test-testrunner.mf usr/src/pkg/manifests/system-test-zfstest.mf usr/src/test/Makefile usr/src/test/Makefile.com usr/src/test/os-tests/Makefile usr/src/test/os-tests/cmd/Makefile usr/src/test/os-tests/cmd/ostest.ksh usr/src/test/os-tests/doc/Makefile usr/src/test/os-tests/doc/README usr/src/test/os-tests/runfiles/Makefile usr/src/test/os-tests/runfiles/delphix.run usr/src/test/os-tests/runfiles/openindiana.run usr/src/test/os-tests/tests/Makefile usr/src/test/os-tests/tests/poll/Makefile usr/src/test/os-tests/tests/poll/poll_test.c usr/src/test/test-runner/Makefile usr/src/test/test-runner/cmd/Makefile usr/src/test/test-runner/cmd/run.py usr/src/test/test-runner/man/Makefile usr/src/test/test-runner/man/run.1 usr/src/test/test-runner/stf/Makefile usr/src/test/test-runner/stf/README usr/src/test/test-runner/stf/contrib/include/Makefile usr/src/test/test-runner/stf/contrib/include/logapi.shlib usr/src/test/test-runner/stf/include/Makefile usr/src/test/test-runner/stf/include/stf.shlib usr/src/test/zfs-tests/Makefile usr/src/test/zfs-tests/cmd/Makefile usr/src/test/zfs-tests/cmd/Makefile.subdirs usr/src/test/zfs-tests/cmd/chg_usr_exec/Makefile usr/src/test/zfs-tests/cmd/chg_usr_exec/chg_usr_exec.c usr/src/test/zfs-tests/cmd/devname2devid/Makefile usr/src/test/zfs-tests/cmd/devname2devid/devname2devid.c usr/src/test/zfs-tests/cmd/dir_rd_update/Makefile usr/src/test/zfs-tests/cmd/dir_rd_update/dir_rd_update.c usr/src/test/zfs-tests/cmd/file_check/Makefile usr/src/test/zfs-tests/cmd/file_check/file_check.c usr/src/test/zfs-tests/cmd/file_common.h usr/src/test/zfs-tests/cmd/file_trunc/Makefile usr/src/test/zfs-tests/cmd/file_trunc/file_trunc.c usr/src/test/zfs-tests/cmd/file_write/Makefile usr/src/test/zfs-tests/cmd/file_write/file_write.c usr/src/test/zfs-tests/cmd/largest_file/Makefile usr/src/test/zfs-tests/cmd/largest_file/largest_file.c usr/src/test/zfs-tests/cmd/mkbusy/Makefile usr/src/test/zfs-tests/cmd/mkbusy/mkbusy.c usr/src/test/zfs-tests/cmd/mktree/Makefile usr/src/test/zfs-tests/cmd/mktree/mktree.c usr/src/test/zfs-tests/cmd/mmapwrite/Makefile usr/src/test/zfs-tests/cmd/mmapwrite/mmapwrite.c usr/src/test/zfs-tests/cmd/randfree_file/Makefile usr/src/test/zfs-tests/cmd/randfree_file/randfree_file.c usr/src/test/zfs-tests/cmd/readmmap/Makefile usr/src/test/zfs-tests/cmd/readmmap/readmmap.c usr/src/test/zfs-tests/cmd/rename_dir/Makefile usr/src/test/zfs-tests/cmd/rename_dir/rename_dir.c usr/src/test/zfs-tests/cmd/rm_lnkcnt_zero_file/Makefile usr/src/test/zfs-tests/cmd/rm_lnkcnt_zero_file/rm_lnkcnt_zero_file.c usr/src/test/zfs-tests/cmd/scripts/Makefile usr/src/test/zfs-tests/cmd/scripts/zfstest.ksh usr/src/test/zfs-tests/doc/Makefile usr/src/test/zfs-tests/doc/README usr/src/test/zfs-tests/include/Makefile usr/src/test/zfs-tests/include/commands.cfg usr/src/test/zfs-tests/include/default.cfg usr/src/test/zfs-tests/include/libtest.shlib usr/src/test/zfs-tests/include/math.shlib usr/src/test/zfs-tests/include/properties.shlib usr/src/test/zfs-tests/runfiles/Makefile usr/src/test/zfs-tests/runfiles/delphix.run usr/src/test/zfs-tests/runfiles/openindiana.run usr/src/test/zfs-tests/tests/Makefile usr/src/test/zfs-tests/tests/functional/Makefile usr/src/test/zfs-tests/tests/functional/acl/Makefile usr/src/test/zfs-tests/tests/functional/acl/acl.cfg usr/src/test/zfs-tests/tests/functional/acl/acl_common.kshlib usr/src/test/zfs-tests/tests/functional/acl/cifs/Makefile usr/src/test/zfs-tests/tests/functional/acl/cifs/cifs.kshlib usr/src/test/zfs-tests/tests/functional/acl/cifs/cifs_attr_001_pos.ksh usr/src/test/zfs-tests/tests/functional/acl/cifs/cifs_attr_002_pos.ksh usr/src/test/zfs-tests/tests/functional/acl/cifs/cifs_attr_003_pos.ksh usr/src/test/zfs-tests/tests/functional/acl/cifs/cleanup.ksh usr/src/test/zfs-tests/tests/functional/acl/cifs/setup.ksh usr/src/test/zfs-tests/tests/functional/acl/nontrivial/Makefile usr/src/test/zfs-tests/tests/functional/acl/nontrivial/cleanup.ksh usr/src/test/zfs-tests/tests/functional/acl/nontrivial/setup.ksh usr/src/test/zfs-tests/tests/functional/acl/nontrivial/zfs_acl_chmod_001_neg.ksh usr/src/test/zfs-tests/tests/functional/acl/nontrivial/zfs_acl_chmod_002_pos.ksh usr/src/test/zfs-tests/tests/functional/acl/nontrivial/zfs_acl_chmod_aclmode_001_pos.ksh usr/src/test/zfs-tests/tests/functional/acl/nontrivial/zfs_acl_chmod_compact_001_pos.ksh usr/src/test/zfs-tests/tests/functional/acl/nontrivial/zfs_acl_chmod_delete_001_pos.ksh usr/src/test/zfs-tests/tests/functional/acl/nontrivial/zfs_acl_chmod_inherit_001_pos.ksh usr/src/test/zfs-tests/tests/functional/acl/nontrivial/zfs_acl_chmod_inherit_002_neg.ksh usr/src/test/zfs-tests/tests/functional/acl/nontrivial/zfs_acl_chmod_inherit_002_pos.ksh usr/src/test/zfs-tests/tests/functional/acl/nontrivial/zfs_acl_chmod_inherit_003_pos.ksh usr/src/test/zfs-tests/tests/functional/acl/nontrivial/zfs_acl_chmod_inherit_004_pos.ksh usr/src/test/zfs-tests/tests/functional/acl/nontrivial/zfs_acl_chmod_owner_001_pos.ksh usr/src/test/zfs-tests/tests/functional/acl/nontrivial/zfs_acl_chmod_rwacl_001_pos.ksh usr/src/test/zfs-tests/tests/functional/acl/nontrivial/zfs_acl_chmod_rwx_001_pos.ksh usr/src/test/zfs-tests/tests/functional/acl/nontrivial/zfs_acl_chmod_rwx_002_pos.ksh usr/src/test/zfs-tests/tests/functional/acl/nontrivial/zfs_acl_chmod_rwx_003_pos.ksh usr/src/test/zfs-tests/tests/functional/acl/nontrivial/zfs_acl_chmod_rwx_004_pos.ksh usr/src/test/zfs-tests/tests/functional/acl/nontrivial/zfs_acl_chmod_xattr_001_pos.ksh usr/src/test/zfs-tests/tests/functional/acl/nontrivial/zfs_acl_chmod_xattr_002_pos.ksh usr/src/test/zfs-tests/tests/functional/acl/nontrivial/zfs_acl_cp_001_pos.ksh usr/src/test/zfs-tests/tests/functional/acl/nontrivial/zfs_acl_cp_002_pos.ksh usr/src/test/zfs-tests/tests/functional/acl/nontrivial/zfs_acl_cpio_001_pos.ksh usr/src/test/zfs-tests/tests/functional/acl/nontrivial/zfs_acl_cpio_002_pos.ksh usr/src/test/zfs-tests/tests/functional/acl/nontrivial/zfs_acl_find_001_pos.ksh usr/src/test/zfs-tests/tests/functional/acl/nontrivial/zfs_acl_ls_001_pos.ksh usr/src/test/zfs-tests/tests/functional/acl/nontrivial/zfs_acl_mv_001_pos.ksh usr/src/test/zfs-tests/tests/functional/acl/nontrivial/zfs_acl_tar_001_pos.ksh usr/src/test/zfs-tests/tests/functional/acl/nontrivial/zfs_acl_tar_002_pos.ksh usr/src/test/zfs-tests/tests/functional/acl/trivial/Makefile usr/src/test/zfs-tests/tests/functional/acl/trivial/cleanup.ksh usr/src/test/zfs-tests/tests/functional/acl/trivial/setup.ksh usr/src/test/zfs-tests/tests/functional/acl/trivial/zfs_acl_chmod_001_pos.ksh usr/src/test/zfs-tests/tests/functional/acl/trivial/zfs_acl_compress_001_pos.ksh usr/src/test/zfs-tests/tests/functional/acl/trivial/zfs_acl_cp_001_pos.ksh usr/src/test/zfs-tests/tests/functional/acl/trivial/zfs_acl_cp_002_neg.ksh usr/src/test/zfs-tests/tests/functional/acl/trivial/zfs_acl_cp_003_neg.ksh usr/src/test/zfs-tests/tests/functional/acl/trivial/zfs_acl_find_001_pos.ksh usr/src/test/zfs-tests/tests/functional/acl/trivial/zfs_acl_find_002_neg.ksh usr/src/test/zfs-tests/tests/functional/acl/trivial/zfs_acl_ls_001_pos.ksh usr/src/test/zfs-tests/tests/functional/acl/trivial/zfs_acl_ls_002_neg.ksh usr/src/test/zfs-tests/tests/functional/acl/trivial/zfs_acl_mv_001_pos.ksh usr/src/test/zfs-tests/tests/functional/acl/trivial/zfs_acl_pack_001_pos.ksh usr/src/test/zfs-tests/tests/functional/acl/trivial/zfs_acl_pax_001_pos.ksh usr/src/test/zfs-tests/tests/functional/acl/trivial/zfs_acl_pax_002_pos.ksh usr/src/test/zfs-tests/tests/functional/acl/trivial/zfs_acl_pax_003_pos.ksh usr/src/test/zfs-tests/tests/functional/acl/trivial/zfs_acl_pax_004_pos.ksh usr/src/test/zfs-tests/tests/functional/acl/trivial/zfs_acl_pax_005_pos.ksh usr/src/test/zfs-tests/tests/functional/acl/trivial/zfs_acl_pax_006_pos.ksh usr/src/test/zfs-tests/tests/functional/acl/trivial/zfs_acl_tar_001_pos.ksh usr/src/test/zfs-tests/tests/functional/acl/trivial/zfs_acl_tar_002_neg.ksh usr/src/test/zfs-tests/tests/functional/atime/Makefile usr/src/test/zfs-tests/tests/functional/atime/atime.cfg usr/src/test/zfs-tests/tests/functional/atime/atime_001_pos.ksh usr/src/test/zfs-tests/tests/functional/atime/atime_002_neg.ksh usr/src/test/zfs-tests/tests/functional/atime/atime_common.kshlib usr/src/test/zfs-tests/tests/functional/atime/cleanup.ksh usr/src/test/zfs-tests/tests/functional/atime/setup.ksh usr/src/test/zfs-tests/tests/functional/bootfs/Makefile usr/src/test/zfs-tests/tests/functional/bootfs/bootfs_001_pos.ksh usr/src/test/zfs-tests/tests/functional/bootfs/bootfs_002_neg.ksh usr/src/test/zfs-tests/tests/functional/bootfs/bootfs_003_pos.ksh usr/src/test/zfs-tests/tests/functional/bootfs/bootfs_004_neg.ksh usr/src/test/zfs-tests/tests/functional/bootfs/bootfs_005_neg.ksh usr/src/test/zfs-tests/tests/functional/bootfs/bootfs_006_pos.ksh usr/src/test/zfs-tests/tests/functional/bootfs/bootfs_007_neg.ksh usr/src/test/zfs-tests/tests/functional/bootfs/bootfs_008_neg.ksh usr/src/test/zfs-tests/tests/functional/cli_root/Makefile usr/src/test/zfs-tests/tests/functional/cli_root/cli_common.kshlib usr/src/test/zfs-tests/tests/functional/cli_root/zdb/Makefile usr/src/test/zfs-tests/tests/functional/cli_root/zdb/zdb_001_neg.ksh usr/src/test/zfs-tests/tests/functional/cli_root/zfs/Makefile usr/src/test/zfs-tests/tests/functional/cli_root/zfs/cleanup.ksh usr/src/test/zfs-tests/tests/functional/cli_root/zfs/setup.ksh usr/src/test/zfs-tests/tests/functional/cli_root/zfs/zfs_001_neg.ksh usr/src/test/zfs-tests/tests/functional/cli_root/zfs/zfs_002_pos.ksh usr/src/test/zfs-tests/tests/functional/cli_root/zfs/zfs_003_neg.ksh usr/src/test/zfs-tests/tests/functional/cli_root/zfs_clone/Makefile usr/src/test/zfs-tests/tests/functional/cli_root/zfs_clone/cleanup.ksh usr/src/test/zfs-tests/tests/functional/cli_root/zfs_clone/setup.ksh usr/src/test/zfs-tests/tests/functional/cli_root/zfs_clone/zfs_clone_001_neg.ksh usr/src/test/zfs-tests/tests/functional/cli_root/zfs_clone/zfs_clone_002_pos.ksh usr/src/test/zfs-tests/tests/functional/cli_root/zfs_clone/zfs_clone_003_pos.ksh usr/src/test/zfs-tests/tests/functional/cli_root/zfs_clone/zfs_clone_004_pos.ksh usr/src/test/zfs-tests/tests/functional/cli_root/zfs_clone/zfs_clone_005_pos.ksh usr/src/test/zfs-tests/tests/functional/cli_root/zfs_clone/zfs_clone_006_pos.ksh usr/src/test/zfs-tests/tests/functional/cli_root/zfs_clone/zfs_clone_007_pos.ksh usr/src/test/zfs-tests/tests/functional/cli_root/zfs_clone/zfs_clone_008_neg.ksh usr/src/test/zfs-tests/tests/functional/cli_root/zfs_clone/zfs_clone_009_neg.ksh usr/src/test/zfs-tests/tests/functional/cli_root/zfs_clone/zfs_clone_010_pos.ksh usr/src/test/zfs-tests/tests/functional/cli_root/zfs_copies/Makefile usr/src/test/zfs-tests/tests/functional/cli_root/zfs_copies/cleanup.ksh usr/src/test/zfs-tests/tests/functional/cli_root/zfs_copies/setup.ksh usr/src/test/zfs-tests/tests/functional/cli_root/zfs_copies/zfs_copies.cfg usr/src/test/zfs-tests/tests/functional/cli_root/zfs_copies/zfs_copies.kshlib usr/src/test/zfs-tests/tests/functional/cli_root/zfs_copies/zfs_copies_001_pos.ksh usr/src/test/zfs-tests/tests/functional/cli_root/zfs_copies/zfs_copies_002_pos.ksh usr/src/test/zfs-tests/tests/functional/cli_root/zfs_copies/zfs_copies_003_pos.ksh usr/src/test/zfs-tests/tests/functional/cli_root/zfs_copies/zfs_copies_004_neg.ksh usr/src/test/zfs-tests/tests/functional/cli_root/zfs_copies/zfs_copies_005_neg.ksh usr/src/test/zfs-tests/tests/functional/cli_root/zfs_copies/zfs_copies_006_pos.ksh usr/src/test/zfs-tests/tests/functional/cli_root/zfs_create/Makefile usr/src/test/zfs-tests/tests/functional/cli_root/zfs_create/cleanup.ksh usr/src/test/zfs-tests/tests/functional/cli_root/zfs_create/properties.kshlib usr/src/test/zfs-tests/tests/functional/cli_root/zfs_create/setup.ksh usr/src/test/zfs-tests/tests/functional/cli_root/zfs_create/zfs_create.cfg usr/src/test/zfs-tests/tests/functional/cli_root/zfs_create/zfs_create_001_pos.ksh usr/src/test/zfs-tests/tests/functional/cli_root/zfs_create/zfs_create_002_pos.ksh usr/src/test/zfs-tests/tests/functional/cli_root/zfs_create/zfs_create_003_pos.ksh usr/src/test/zfs-tests/tests/functional/cli_root/zfs_create/zfs_create_004_pos.ksh usr/src/test/zfs-tests/tests/functional/cli_root/zfs_create/zfs_create_005_pos.ksh usr/src/test/zfs-tests/tests/functional/cli_root/zfs_create/zfs_create_006_pos.ksh usr/src/test/zfs-tests/tests/functional/cli_root/zfs_create/zfs_create_007_pos.ksh usr/src/test/zfs-tests/tests/functional/cli_root/zfs_create/zfs_create_008_neg.ksh usr/src/test/zfs-tests/tests/functional/cli_root/zfs_create/zfs_create_009_neg.ksh usr/src/test/zfs-tests/tests/functional/cli_root/zfs_create/zfs_create_010_neg.ksh usr/src/test/zfs-tests/tests/functional/cli_root/zfs_create/zfs_create_011_pos.ksh usr/src/test/zfs-tests/tests/functional/cli_root/zfs_create/zfs_create_012_pos.ksh usr/src/test/zfs-tests/tests/functional/cli_root/zfs_create/zfs_create_013_pos.ksh usr/src/test/zfs-tests/tests/functional/cli_root/zfs_create/zfs_create_common.kshlib usr/src/test/zfs-tests/tests/functional/cli_root/zfs_destroy/Makefile usr/src/test/zfs-tests/tests/functional/cli_root/zfs_destroy/cleanup.ksh usr/src/test/zfs-tests/tests/functional/cli_root/zfs_destroy/setup.ksh usr/src/test/zfs-tests/tests/functional/cli_root/zfs_destroy/zfs_destroy.cfg usr/src/test/zfs-tests/tests/functional/cli_root/zfs_destroy/zfs_destroy_001_pos.ksh usr/src/test/zfs-tests/tests/functional/cli_root/zfs_destroy/zfs_destroy_002_pos.ksh usr/src/test/zfs-tests/tests/functional/cli_root/zfs_destroy/zfs_destroy_003_pos.ksh usr/src/test/zfs-tests/tests/functional/cli_root/zfs_destroy/zfs_destroy_004_pos.ksh usr/src/test/zfs-tests/tests/functional/cli_root/zfs_destroy/zfs_destroy_005_neg.ksh usr/src/test/zfs-tests/tests/functional/cli_root/zfs_destroy/zfs_destroy_006_neg.ksh usr/src/test/zfs-tests/tests/functional/cli_root/zfs_destroy/zfs_destroy_007_neg.ksh usr/src/test/zfs-tests/tests/functional/cli_root/zfs_destroy/zfs_destroy_008_pos.ksh usr/src/test/zfs-tests/tests/functional/cli_root/zfs_destroy/zfs_destroy_009_pos.ksh usr/src/test/zfs-tests/tests/functional/cli_root/zfs_destroy/zfs_destroy_010_pos.ksh usr/src/test/zfs-tests/tests/functional/cli_root/zfs_destroy/zfs_destroy_011_pos.ksh usr/src/test/zfs-tests/tests/functional/cli_root/zfs_destroy/zfs_destroy_012_pos.ksh usr/src/test/zfs-tests/tests/functional/cli_root/zfs_destroy/zfs_destroy_013_neg.ksh usr/src/test/zfs-tests/tests/functional/cli_root/zfs_destroy/zfs_destroy_014_pos.ksh usr/src/test/zfs-tests/tests/functional/cli_root/zfs_destroy/zfs_destroy_015_pos.ksh usr/src/test/zfs-tests/tests/functional/cli_root/zfs_destroy/zfs_destroy_016_pos.ksh usr/src/test/zfs-tests/tests/functional/cli_root/zfs_destroy/zfs_destroy_common.kshlib usr/src/test/zfs-tests/tests/functional/cli_root/zfs_get/Makefile usr/src/test/zfs-tests/tests/functional/cli_root/zfs_get/cleanup.ksh usr/src/test/zfs-tests/tests/functional/cli_root/zfs_get/setup.ksh usr/src/test/zfs-tests/tests/functional/cli_root/zfs_get/zfs_get_001_pos.ksh usr/src/test/zfs-tests/tests/functional/cli_root/zfs_get/zfs_get_002_pos.ksh usr/src/test/zfs-tests/tests/functional/cli_root/zfs_get/zfs_get_003_pos.ksh usr/src/test/zfs-tests/tests/functional/cli_root/zfs_get/zfs_get_004_pos.ksh usr/src/test/zfs-tests/tests/functional/cli_root/zfs_get/zfs_get_005_neg.ksh usr/src/test/zfs-tests/tests/functional/cli_root/zfs_get/zfs_get_006_neg.ksh usr/src/test/zfs-tests/tests/functional/cli_root/zfs_get/zfs_get_007_neg.ksh usr/src/test/zfs-tests/tests/functional/cli_root/zfs_get/zfs_get_008_pos.ksh usr/src/test/zfs-tests/tests/functional/cli_root/zfs_get/zfs_get_009_pos.ksh usr/src/test/zfs-tests/tests/functional/cli_root/zfs_get/zfs_get_010_neg.ksh usr/src/test/zfs-tests/tests/functional/cli_root/zfs_get/zfs_get_common.kshlib usr/src/test/zfs-tests/tests/functional/cli_root/zfs_get/zfs_get_list_d.kshlib usr/src/test/zfs-tests/tests/functional/cli_root/zfs_inherit/Makefile usr/src/test/zfs-tests/tests/functional/cli_root/zfs_inherit/cleanup.ksh usr/src/test/zfs-tests/tests/functional/cli_root/zfs_inherit/setup.ksh usr/src/test/zfs-tests/tests/functional/cli_root/zfs_inherit/zfs_inherit_001_neg.ksh usr/src/test/zfs-tests/tests/functional/cli_root/zfs_inherit/zfs_inherit_002_neg.ksh usr/src/test/zfs-tests/tests/functional/cli_root/zfs_inherit/zfs_inherit_003_pos.ksh usr/src/test/zfs-tests/tests/functional/cli_root/zfs_mount/Makefile usr/src/test/zfs-tests/tests/functional/cli_root/zfs_mount/cleanup.ksh usr/src/test/zfs-tests/tests/functional/cli_root/zfs_mount/setup.ksh usr/src/test/zfs-tests/tests/functional/cli_root/zfs_mount/zfs_mount.cfg usr/src/test/zfs-tests/tests/functional/cli_root/zfs_mount/zfs_mount.kshlib usr/src/test/zfs-tests/tests/functional/cli_root/zfs_mount/zfs_mount_001_pos.ksh usr/src/test/zfs-tests/tests/functional/cli_root/zfs_mount/zfs_mount_002_pos.ksh usr/src/test/zfs-tests/tests/functional/cli_root/zfs_mount/zfs_mount_003_pos.ksh usr/src/test/zfs-tests/tests/functional/cli_root/zfs_mount/zfs_mount_004_pos.ksh usr/src/test/zfs-tests/tests/functional/cli_root/zfs_mount/zfs_mount_005_pos.ksh usr/src/test/zfs-tests/tests/functional/cli_root/zfs_mount/zfs_mount_006_pos.ksh usr/src/test/zfs-tests/tests/functional/cli_root/zfs_mount/zfs_mount_007_pos.ksh usr/src/test/zfs-tests/tests/functional/cli_root/zfs_mount/zfs_mount_008_pos.ksh usr/src/test/zfs-tests/tests/functional/cli_root/zfs_mount/zfs_mount_009_neg.ksh usr/src/test/zfs-tests/tests/functional/cli_root/zfs_mount/zfs_mount_010_neg.ksh usr/src/test/zfs-tests/tests/functional/cli_root/zfs_mount/zfs_mount_011_neg.ksh usr/src/test/zfs-tests/tests/functional/cli_root/zfs_mount/zfs_mount_all_001_pos.ksh usr/src/test/zfs-tests/tests/functional/cli_root/zfs_promote/Makefile usr/src/test/zfs-tests/tests/functional/cli_root/zfs_promote/cleanup.ksh usr/src/test/zfs-tests/tests/functional/cli_root/zfs_promote/setup.ksh usr/src/test/zfs-tests/tests/functional/cli_root/zfs_promote/zfs_promote.cfg usr/src/test/zfs-tests/tests/functional/cli_root/zfs_promote/zfs_promote_001_pos.ksh usr/src/test/zfs-tests/tests/functional/cli_root/zfs_promote/zfs_promote_002_pos.ksh usr/src/test/zfs-tests/tests/functional/cli_root/zfs_promote/zfs_promote_003_pos.ksh usr/src/test/zfs-tests/tests/functional/cli_root/zfs_promote/zfs_promote_004_pos.ksh usr/src/test/zfs-tests/tests/functional/cli_root/zfs_promote/zfs_promote_005_pos.ksh usr/src/test/zfs-tests/tests/functional/cli_root/zfs_promote/zfs_promote_006_neg.ksh usr/src/test/zfs-tests/tests/functional/cli_root/zfs_promote/zfs_promote_007_neg.ksh usr/src/test/zfs-tests/tests/functional/cli_root/zfs_promote/zfs_promote_008_pos.ksh usr/src/test/zfs-tests/tests/functional/cli_root/zfs_property/Makefile usr/src/test/zfs-tests/tests/functional/cli_root/zfs_property/cleanup.ksh usr/src/test/zfs-tests/tests/functional/cli_root/zfs_property/setup.ksh usr/src/test/zfs-tests/tests/functional/cli_root/zfs_property/zfs_written_property_001_pos.ksh usr/src/test/zfs-tests/tests/functional/cli_root/zfs_receive/Makefile usr/src/test/zfs-tests/tests/functional/cli_root/zfs_receive/cleanup.ksh usr/src/test/zfs-tests/tests/functional/cli_root/zfs_receive/setup.ksh usr/src/test/zfs-tests/tests/functional/cli_root/zfs_receive/zfs_receive_001_pos.ksh usr/src/test/zfs-tests/tests/functional/cli_root/zfs_receive/zfs_receive_002_pos.ksh usr/src/test/zfs-tests/tests/functional/cli_root/zfs_receive/zfs_receive_003_pos.ksh usr/src/test/zfs-tests/tests/functional/cli_root/zfs_receive/zfs_receive_004_neg.ksh usr/src/test/zfs-tests/tests/functional/cli_root/zfs_receive/zfs_receive_005_neg.ksh usr/src/test/zfs-tests/tests/functional/cli_root/zfs_receive/zfs_receive_006_pos.ksh usr/src/test/zfs-tests/tests/functional/cli_root/zfs_receive/zfs_receive_007_neg.ksh usr/src/test/zfs-tests/tests/functional/cli_root/zfs_receive/zfs_receive_008_pos.ksh usr/src/test/zfs-tests/tests/functional/cli_root/zfs_receive/zfs_receive_009_neg.ksh usr/src/test/zfs-tests/tests/functional/cli_root/zfs_rename/Makefile usr/src/test/zfs-tests/tests/functional/cli_root/zfs_rename/cleanup.ksh usr/src/test/zfs-tests/tests/functional/cli_root/zfs_rename/setup.ksh usr/src/test/zfs-tests/tests/functional/cli_root/zfs_rename/zfs_rename.cfg usr/src/test/zfs-tests/tests/functional/cli_root/zfs_rename/zfs_rename.kshlib usr/src/test/zfs-tests/tests/functional/cli_root/zfs_rename/zfs_rename_001_pos.ksh usr/src/test/zfs-tests/tests/functional/cli_root/zfs_rename/zfs_rename_002_pos.ksh usr/src/test/zfs-tests/tests/functional/cli_root/zfs_rename/zfs_rename_003_pos.ksh usr/src/test/zfs-tests/tests/functional/cli_root/zfs_rename/zfs_rename_004_neg.ksh usr/src/test/zfs-tests/tests/functional/cli_root/zfs_rename/zfs_rename_005_neg.ksh usr/src/test/zfs-tests/tests/functional/cli_root/zfs_rename/zfs_rename_006_pos.ksh usr/src/test/zfs-tests/tests/functional/cli_root/zfs_rename/zfs_rename_007_pos.ksh usr/src/test/zfs-tests/tests/functional/cli_root/zfs_rename/zfs_rename_008_pos.ksh usr/src/test/zfs-tests/tests/functional/cli_root/zfs_rename/zfs_rename_009_neg.ksh usr/src/test/zfs-tests/tests/functional/cli_root/zfs_rename/zfs_rename_010_neg.ksh usr/src/test/zfs-tests/tests/functional/cli_root/zfs_rename/zfs_rename_011_pos.ksh usr/src/test/zfs-tests/tests/functional/cli_root/zfs_rename/zfs_rename_012_neg.ksh usr/src/test/zfs-tests/tests/functional/cli_root/zfs_rename/zfs_rename_013_pos.ksh usr/src/test/zfs-tests/tests/functional/cli_root/zfs_reservation/Makefile usr/src/test/zfs-tests/tests/functional/cli_root/zfs_reservation/cleanup.ksh usr/src/test/zfs-tests/tests/functional/cli_root/zfs_reservation/setup.ksh usr/src/test/zfs-tests/tests/functional/cli_root/zfs_reservation/zfs_reservation_001_pos.ksh usr/src/test/zfs-tests/tests/functional/cli_root/zfs_reservation/zfs_reservation_002_pos.ksh usr/src/test/zfs-tests/tests/functional/cli_root/zfs_rollback/Makefile usr/src/test/zfs-tests/tests/functional/cli_root/zfs_rollback/cleanup.ksh usr/src/test/zfs-tests/tests/functional/cli_root/zfs_rollback/setup.ksh usr/src/test/zfs-tests/tests/functional/cli_root/zfs_rollback/zfs_rollback.cfg usr/src/test/zfs-tests/tests/functional/cli_root/zfs_rollback/zfs_rollback_001_pos.ksh usr/src/test/zfs-tests/tests/functional/cli_root/zfs_rollback/zfs_rollback_002_pos.ksh usr/src/test/zfs-tests/tests/functional/cli_root/zfs_rollback/zfs_rollback_003_neg.ksh usr/src/test/zfs-tests/tests/functional/cli_root/zfs_rollback/zfs_rollback_004_neg.ksh usr/src/test/zfs-tests/tests/functional/cli_root/zfs_rollback/zfs_rollback_common.kshlib usr/src/test/zfs-tests/tests/functional/cli_root/zfs_send/Makefile usr/src/test/zfs-tests/tests/functional/cli_root/zfs_send/cleanup.ksh usr/src/test/zfs-tests/tests/functional/cli_root/zfs_send/setup.ksh usr/src/test/zfs-tests/tests/functional/cli_root/zfs_send/zfs_send.cfg usr/src/test/zfs-tests/tests/functional/cli_root/zfs_send/zfs_send_001_pos.ksh usr/src/test/zfs-tests/tests/functional/cli_root/zfs_send/zfs_send_002_pos.ksh usr/src/test/zfs-tests/tests/functional/cli_root/zfs_send/zfs_send_003_pos.ksh usr/src/test/zfs-tests/tests/functional/cli_root/zfs_send/zfs_send_004_neg.ksh usr/src/test/zfs-tests/tests/functional/cli_root/zfs_send/zfs_send_005_pos.ksh usr/src/test/zfs-tests/tests/functional/cli_root/zfs_send/zfs_send_006_pos.ksh usr/src/test/zfs-tests/tests/functional/cli_root/zfs_set/Makefile usr/src/test/zfs-tests/tests/functional/cli_root/zfs_set/cache_001_pos.ksh usr/src/test/zfs-tests/tests/functional/cli_root/zfs_set/cache_002_neg.ksh usr/src/test/zfs-tests/tests/functional/cli_root/zfs_set/canmount_001_pos.ksh usr/src/test/zfs-tests/tests/functional/cli_root/zfs_set/canmount_002_pos.ksh usr/src/test/zfs-tests/tests/functional/cli_root/zfs_set/canmount_003_pos.ksh usr/src/test/zfs-tests/tests/functional/cli_root/zfs_set/canmount_004_pos.ksh usr/src/test/zfs-tests/tests/functional/cli_root/zfs_set/checksum_001_pos.ksh usr/src/test/zfs-tests/tests/functional/cli_root/zfs_set/cleanup.ksh usr/src/test/zfs-tests/tests/functional/cli_root/zfs_set/compression_001_pos.ksh usr/src/test/zfs-tests/tests/functional/cli_root/zfs_set/mountpoint_001_pos.ksh usr/src/test/zfs-tests/tests/functional/cli_root/zfs_set/mountpoint_002_pos.ksh usr/src/test/zfs-tests/tests/functional/cli_root/zfs_set/mountpoint_003_pos.ksh usr/src/test/zfs-tests/tests/functional/cli_root/zfs_set/onoffs_001_pos.ksh usr/src/test/zfs-tests/tests/functional/cli_root/zfs_set/property_alias_001_pos.ksh usr/src/test/zfs-tests/tests/functional/cli_root/zfs_set/readonly_001_pos.ksh usr/src/test/zfs-tests/tests/functional/cli_root/zfs_set/reservation_001_neg.ksh usr/src/test/zfs-tests/tests/functional/cli_root/zfs_set/ro_props_001_pos.ksh usr/src/test/zfs-tests/tests/functional/cli_root/zfs_set/setup.ksh usr/src/test/zfs-tests/tests/functional/cli_root/zfs_set/share_mount_001_neg.ksh usr/src/test/zfs-tests/tests/functional/cli_root/zfs_set/snapdir_001_pos.ksh usr/src/test/zfs-tests/tests/functional/cli_root/zfs_set/user_property_001_pos.ksh usr/src/test/zfs-tests/tests/functional/cli_root/zfs_set/user_property_002_pos.ksh usr/src/test/zfs-tests/tests/functional/cli_root/zfs_set/user_property_003_neg.ksh usr/src/test/zfs-tests/tests/functional/cli_root/zfs_set/user_property_004_pos.ksh usr/src/test/zfs-tests/tests/functional/cli_root/zfs_set/version_001_neg.ksh usr/src/test/zfs-tests/tests/functional/cli_root/zfs_set/zfs_set_001_neg.ksh usr/src/test/zfs-tests/tests/functional/cli_root/zfs_set/zfs_set_002_neg.ksh usr/src/test/zfs-tests/tests/functional/cli_root/zfs_set/zfs_set_003_neg.ksh usr/src/test/zfs-tests/tests/functional/cli_root/zfs_set/zfs_set_common.kshlib usr/src/test/zfs-tests/tests/functional/cli_root/zfs_share/Makefile usr/src/test/zfs-tests/tests/functional/cli_root/zfs_share/cleanup.ksh usr/src/test/zfs-tests/tests/functional/cli_root/zfs_share/setup.ksh usr/src/test/zfs-tests/tests/functional/cli_root/zfs_share/zfs_share.cfg usr/src/test/zfs-tests/tests/functional/cli_root/zfs_share/zfs_share_001_pos.ksh usr/src/test/zfs-tests/tests/functional/cli_root/zfs_share/zfs_share_002_pos.ksh usr/src/test/zfs-tests/tests/functional/cli_root/zfs_share/zfs_share_003_pos.ksh usr/src/test/zfs-tests/tests/functional/cli_root/zfs_share/zfs_share_004_pos.ksh usr/src/test/zfs-tests/tests/functional/cli_root/zfs_share/zfs_share_005_pos.ksh usr/src/test/zfs-tests/tests/functional/cli_root/zfs_share/zfs_share_006_pos.ksh usr/src/test/zfs-tests/tests/functional/cli_root/zfs_share/zfs_share_007_neg.ksh usr/src/test/zfs-tests/tests/functional/cli_root/zfs_share/zfs_share_008_neg.ksh usr/src/test/zfs-tests/tests/functional/cli_root/zfs_share/zfs_share_009_neg.ksh usr/src/test/zfs-tests/tests/functional/cli_root/zfs_share/zfs_share_010_neg.ksh usr/src/test/zfs-tests/tests/functional/cli_root/zfs_share/zfs_share_011_pos.ksh usr/src/test/zfs-tests/tests/functional/cli_root/zfs_snapshot/Makefile usr/src/test/zfs-tests/tests/functional/cli_root/zfs_snapshot/cleanup.ksh usr/src/test/zfs-tests/tests/functional/cli_root/zfs_snapshot/setup.ksh usr/src/test/zfs-tests/tests/functional/cli_root/zfs_snapshot/zfs_snapshot.cfg usr/src/test/zfs-tests/tests/functional/cli_root/zfs_snapshot/zfs_snapshot_001_neg.ksh usr/src/test/zfs-tests/tests/functional/cli_root/zfs_snapshot/zfs_snapshot_002_neg.ksh usr/src/test/zfs-tests/tests/functional/cli_root/zfs_snapshot/zfs_snapshot_003_neg.ksh usr/src/test/zfs-tests/tests/functional/cli_root/zfs_snapshot/zfs_snapshot_004_neg.ksh usr/src/test/zfs-tests/tests/functional/cli_root/zfs_snapshot/zfs_snapshot_005_neg.ksh usr/src/test/zfs-tests/tests/functional/cli_root/zfs_snapshot/zfs_snapshot_006_pos.ksh usr/src/test/zfs-tests/tests/functional/cli_root/zfs_snapshot/zfs_snapshot_007_neg.ksh usr/src/test/zfs-tests/tests/functional/cli_root/zfs_snapshot/zfs_snapshot_008_neg.ksh usr/src/test/zfs-tests/tests/functional/cli_root/zfs_snapshot/zfs_snapshot_009_pos.ksh usr/src/test/zfs-tests/tests/functional/cli_root/zfs_unmount/Makefile usr/src/test/zfs-tests/tests/functional/cli_root/zfs_unmount/cleanup.ksh usr/src/test/zfs-tests/tests/functional/cli_root/zfs_unmount/setup.ksh usr/src/test/zfs-tests/tests/functional/cli_root/zfs_unmount/zfs_unmount.cfg usr/src/test/zfs-tests/tests/functional/cli_root/zfs_unmount/zfs_unmount.kshlib usr/src/test/zfs-tests/tests/functional/cli_root/zfs_unmount/zfs_unmount_001_pos.ksh usr/src/test/zfs-tests/tests/functional/cli_root/zfs_unmount/zfs_unmount_002_pos.ksh usr/src/test/zfs-tests/tests/functional/cli_root/zfs_unmount/zfs_unmount_003_pos.ksh usr/src/test/zfs-tests/tests/functional/cli_root/zfs_unmount/zfs_unmount_004_pos.ksh usr/src/test/zfs-tests/tests/functional/cli_root/zfs_unmount/zfs_unmount_005_pos.ksh usr/src/test/zfs-tests/tests/functional/cli_root/zfs_unmount/zfs_unmount_006_pos.ksh usr/src/test/zfs-tests/tests/functional/cli_root/zfs_unmount/zfs_unmount_007_neg.ksh usr/src/test/zfs-tests/tests/functional/cli_root/zfs_unmount/zfs_unmount_008_neg.ksh usr/src/test/zfs-tests/tests/functional/cli_root/zfs_unmount/zfs_unmount_009_pos.ksh usr/src/test/zfs-tests/tests/functional/cli_root/zfs_unmount/zfs_unmount_all_001_pos.ksh usr/src/test/zfs-tests/tests/functional/cli_root/zfs_unshare/Makefile usr/src/test/zfs-tests/tests/functional/cli_root/zfs_unshare/cleanup.ksh usr/src/test/zfs-tests/tests/functional/cli_root/zfs_unshare/setup.ksh usr/src/test/zfs-tests/tests/functional/cli_root/zfs_unshare/zfs_unshare_001_pos.ksh usr/src/test/zfs-tests/tests/functional/cli_root/zfs_unshare/zfs_unshare_002_pos.ksh usr/src/test/zfs-tests/tests/functional/cli_root/zfs_unshare/zfs_unshare_003_pos.ksh usr/src/test/zfs-tests/tests/functional/cli_root/zfs_unshare/zfs_unshare_004_neg.ksh usr/src/test/zfs-tests/tests/functional/cli_root/zfs_unshare/zfs_unshare_005_neg.ksh usr/src/test/zfs-tests/tests/functional/cli_root/zfs_upgrade/Makefile usr/src/test/zfs-tests/tests/functional/cli_root/zfs_upgrade/cleanup.ksh usr/src/test/zfs-tests/tests/functional/cli_root/zfs_upgrade/setup.ksh usr/src/test/zfs-tests/tests/functional/cli_root/zfs_upgrade/zfs_upgrade.kshlib usr/src/test/zfs-tests/tests/functional/cli_root/zfs_upgrade/zfs_upgrade_001_pos.ksh usr/src/test/zfs-tests/tests/functional/cli_root/zfs_upgrade/zfs_upgrade_002_pos.ksh usr/src/test/zfs-tests/tests/functional/cli_root/zfs_upgrade/zfs_upgrade_003_pos.ksh usr/src/test/zfs-tests/tests/functional/cli_root/zfs_upgrade/zfs_upgrade_004_pos.ksh usr/src/test/zfs-tests/tests/functional/cli_root/zfs_upgrade/zfs_upgrade_005_pos.ksh usr/src/test/zfs-tests/tests/functional/cli_root/zfs_upgrade/zfs_upgrade_006_neg.ksh usr/src/test/zfs-tests/tests/functional/cli_root/zfs_upgrade/zfs_upgrade_007_neg.ksh usr/src/test/zfs-tests/tests/functional/cli_root/zpool/Makefile usr/src/test/zfs-tests/tests/functional/cli_root/zpool/cleanup.ksh usr/src/test/zfs-tests/tests/functional/cli_root/zpool/setup.ksh usr/src/test/zfs-tests/tests/functional/cli_root/zpool/zpool_001_neg.ksh usr/src/test/zfs-tests/tests/functional/cli_root/zpool/zpool_002_pos.ksh usr/src/test/zfs-tests/tests/functional/cli_root/zpool/zpool_003_pos.ksh usr/src/test/zfs-tests/tests/functional/cli_root/zpool_add/Makefile usr/src/test/zfs-tests/tests/functional/cli_root/zpool_add/cleanup.ksh usr/src/test/zfs-tests/tests/functional/cli_root/zpool_add/setup.ksh usr/src/test/zfs-tests/tests/functional/cli_root/zpool_add/zpool_add.cfg usr/src/test/zfs-tests/tests/functional/cli_root/zpool_add/zpool_add.kshlib usr/src/test/zfs-tests/tests/functional/cli_root/zpool_add/zpool_add_001_pos.ksh usr/src/test/zfs-tests/tests/functional/cli_root/zpool_add/zpool_add_002_pos.ksh usr/src/test/zfs-tests/tests/functional/cli_root/zpool_add/zpool_add_003_pos.ksh usr/src/test/zfs-tests/tests/functional/cli_root/zpool_add/zpool_add_004_pos.ksh usr/src/test/zfs-tests/tests/functional/cli_root/zpool_add/zpool_add_005_pos.ksh usr/src/test/zfs-tests/tests/functional/cli_root/zpool_add/zpool_add_006_pos.ksh usr/src/test/zfs-tests/tests/functional/cli_root/zpool_add/zpool_add_007_neg.ksh usr/src/test/zfs-tests/tests/functional/cli_root/zpool_add/zpool_add_008_neg.ksh usr/src/test/zfs-tests/tests/functional/cli_root/zpool_add/zpool_add_009_neg.ksh usr/src/test/zfs-tests/tests/functional/cli_root/zpool_attach/Makefile usr/src/test/zfs-tests/tests/functional/cli_root/zpool_attach/cleanup.ksh usr/src/test/zfs-tests/tests/functional/cli_root/zpool_attach/setup.ksh usr/src/test/zfs-tests/tests/functional/cli_root/zpool_attach/zpool_attach_001_neg.ksh usr/src/test/zfs-tests/tests/functional/cli_root/zpool_clear/Makefile usr/src/test/zfs-tests/tests/functional/cli_root/zpool_clear/cleanup.ksh usr/src/test/zfs-tests/tests/functional/cli_root/zpool_clear/setup.ksh usr/src/test/zfs-tests/tests/functional/cli_root/zpool_clear/zpool_clear.cfg usr/src/test/zfs-tests/tests/functional/cli_root/zpool_clear/zpool_clear_001_pos.ksh usr/src/test/zfs-tests/tests/functional/cli_root/zpool_clear/zpool_clear_002_neg.ksh usr/src/test/zfs-tests/tests/functional/cli_root/zpool_clear/zpool_clear_003_neg.ksh usr/src/test/zfs-tests/tests/functional/cli_root/zpool_create/Makefile usr/src/test/zfs-tests/tests/functional/cli_root/zpool_create/cleanup.ksh usr/src/test/zfs-tests/tests/functional/cli_root/zpool_create/setup.ksh usr/src/test/zfs-tests/tests/functional/cli_root/zpool_create/zpool_create.cfg usr/src/test/zfs-tests/tests/functional/cli_root/zpool_create/zpool_create.shlib usr/src/test/zfs-tests/tests/functional/cli_root/zpool_create/zpool_create_001_pos.ksh usr/src/test/zfs-tests/tests/functional/cli_root/zpool_create/zpool_create_002_pos.ksh usr/src/test/zfs-tests/tests/functional/cli_root/zpool_create/zpool_create_003_pos.ksh usr/src/test/zfs-tests/tests/functional/cli_root/zpool_create/zpool_create_004_pos.ksh usr/src/test/zfs-tests/tests/functional/cli_root/zpool_create/zpool_create_005_pos.ksh usr/src/test/zfs-tests/tests/functional/cli_root/zpool_create/zpool_create_006_pos.ksh usr/src/test/zfs-tests/tests/functional/cli_root/zpool_create/zpool_create_007_neg.ksh usr/src/test/zfs-tests/tests/functional/cli_root/zpool_create/zpool_create_008_pos.ksh usr/src/test/zfs-tests/tests/functional/cli_root/zpool_create/zpool_create_009_neg.ksh usr/src/test/zfs-tests/tests/functional/cli_root/zpool_create/zpool_create_010_neg.ksh usr/src/test/zfs-tests/tests/functional/cli_root/zpool_create/zpool_create_011_neg.ksh usr/src/test/zfs-tests/tests/functional/cli_root/zpool_create/zpool_create_012_neg.ksh usr/src/test/zfs-tests/tests/functional/cli_root/zpool_create/zpool_create_013_neg.ksh usr/src/test/zfs-tests/tests/functional/cli_root/zpool_create/zpool_create_014_neg.ksh usr/src/test/zfs-tests/tests/functional/cli_root/zpool_create/zpool_create_015_neg.ksh usr/src/test/zfs-tests/tests/functional/cli_root/zpool_create/zpool_create_016_pos.ksh usr/src/test/zfs-tests/tests/functional/cli_root/zpool_create/zpool_create_017_neg.ksh usr/src/test/zfs-tests/tests/functional/cli_root/zpool_create/zpool_create_018_pos.ksh usr/src/test/zfs-tests/tests/functional/cli_root/zpool_create/zpool_create_019_pos.ksh usr/src/test/zfs-tests/tests/functional/cli_root/zpool_create/zpool_create_020_pos.ksh usr/src/test/zfs-tests/tests/functional/cli_root/zpool_create/zpool_create_021_pos.ksh usr/src/test/zfs-tests/tests/functional/cli_root/zpool_create/zpool_create_022_pos.ksh usr/src/test/zfs-tests/tests/functional/cli_root/zpool_create/zpool_create_023_neg.ksh usr/src/test/zfs-tests/tests/functional/cli_root/zpool_create/zpool_create_features_001_pos.ksh usr/src/test/zfs-tests/tests/functional/cli_root/zpool_create/zpool_create_features_002_pos.ksh usr/src/test/zfs-tests/tests/functional/cli_root/zpool_create/zpool_create_features_003_pos.ksh usr/src/test/zfs-tests/tests/functional/cli_root/zpool_create/zpool_create_features_004_neg.ksh usr/src/test/zfs-tests/tests/functional/cli_root/zpool_destroy/Makefile usr/src/test/zfs-tests/tests/functional/cli_root/zpool_destroy/zpool_destroy.cfg usr/src/test/zfs-tests/tests/functional/cli_root/zpool_destroy/zpool_destroy_001_pos.ksh usr/src/test/zfs-tests/tests/functional/cli_root/zpool_destroy/zpool_destroy_002_pos.ksh usr/src/test/zfs-tests/tests/functional/cli_root/zpool_destroy/zpool_destroy_003_neg.ksh usr/src/test/zfs-tests/tests/functional/cli_root/zpool_detach/Makefile usr/src/test/zfs-tests/tests/functional/cli_root/zpool_detach/cleanup.ksh usr/src/test/zfs-tests/tests/functional/cli_root/zpool_detach/setup.ksh usr/src/test/zfs-tests/tests/functional/cli_root/zpool_detach/zpool_detach_001_neg.ksh usr/src/test/zfs-tests/tests/functional/cli_root/zpool_expand/Makefile usr/src/test/zfs-tests/tests/functional/cli_root/zpool_expand/cleanup.ksh usr/src/test/zfs-tests/tests/functional/cli_root/zpool_expand/setup.ksh usr/src/test/zfs-tests/tests/functional/cli_root/zpool_expand/zpool_expand.cfg usr/src/test/zfs-tests/tests/functional/cli_root/zpool_expand/zpool_expand_001_pos.ksh usr/src/test/zfs-tests/tests/functional/cli_root/zpool_expand/zpool_expand_002_pos.ksh usr/src/test/zfs-tests/tests/functional/cli_root/zpool_expand/zpool_expand_003_neg.ksh usr/src/test/zfs-tests/tests/functional/cli_root/zpool_export/Makefile usr/src/test/zfs-tests/tests/functional/cli_root/zpool_export/cleanup.ksh usr/src/test/zfs-tests/tests/functional/cli_root/zpool_export/setup.ksh usr/src/test/zfs-tests/tests/functional/cli_root/zpool_export/zpool_export_001_pos.ksh usr/src/test/zfs-tests/tests/functional/cli_root/zpool_export/zpool_export_002_pos.ksh usr/src/test/zfs-tests/tests/functional/cli_root/zpool_export/zpool_export_003_neg.ksh usr/src/test/zfs-tests/tests/functional/cli_root/zpool_export/zpool_export_004_pos.ksh usr/src/test/zfs-tests/tests/functional/cli_root/zpool_get/Makefile usr/src/test/zfs-tests/tests/functional/cli_root/zpool_get/cleanup.ksh usr/src/test/zfs-tests/tests/functional/cli_root/zpool_get/setup.ksh usr/src/test/zfs-tests/tests/functional/cli_root/zpool_get/zpool_get.cfg usr/src/test/zfs-tests/tests/functional/cli_root/zpool_get/zpool_get_001_pos.ksh usr/src/test/zfs-tests/tests/functional/cli_root/zpool_get/zpool_get_002_pos.ksh usr/src/test/zfs-tests/tests/functional/cli_root/zpool_get/zpool_get_003_pos.ksh usr/src/test/zfs-tests/tests/functional/cli_root/zpool_get/zpool_get_004_neg.ksh usr/src/test/zfs-tests/tests/functional/cli_root/zpool_history/Makefile usr/src/test/zfs-tests/tests/functional/cli_root/zpool_history/cleanup.ksh usr/src/test/zfs-tests/tests/functional/cli_root/zpool_history/setup.ksh usr/src/test/zfs-tests/tests/functional/cli_root/zpool_history/zpool_history_001_neg.ksh usr/src/test/zfs-tests/tests/functional/cli_root/zpool_history/zpool_history_002_pos.ksh usr/src/test/zfs-tests/tests/functional/cli_root/zpool_import/Makefile usr/src/test/zfs-tests/tests/functional/cli_root/zpool_import/blockfiles/Makefile usr/src/test/zfs-tests/tests/functional/cli_root/zpool_import/blockfiles/README usr/src/test/zfs-tests/tests/functional/cli_root/zpool_import/blockfiles/unclean_export.dat.bz2 usr/src/test/zfs-tests/tests/functional/cli_root/zpool_import/cleanup.ksh usr/src/test/zfs-tests/tests/functional/cli_root/zpool_import/setup.ksh usr/src/test/zfs-tests/tests/functional/cli_root/zpool_import/zpool_import.cfg usr/src/test/zfs-tests/tests/functional/cli_root/zpool_import/zpool_import_001_pos.ksh usr/src/test/zfs-tests/tests/functional/cli_root/zpool_import/zpool_import_002_pos.ksh usr/src/test/zfs-tests/tests/functional/cli_root/zpool_import/zpool_import_003_pos.ksh usr/src/test/zfs-tests/tests/functional/cli_root/zpool_import/zpool_import_004_pos.ksh usr/src/test/zfs-tests/tests/functional/cli_root/zpool_import/zpool_import_005_pos.ksh usr/src/test/zfs-tests/tests/functional/cli_root/zpool_import/zpool_import_006_pos.ksh usr/src/test/zfs-tests/tests/functional/cli_root/zpool_import/zpool_import_007_pos.ksh usr/src/test/zfs-tests/tests/functional/cli_root/zpool_import/zpool_import_008_pos.ksh usr/src/test/zfs-tests/tests/functional/cli_root/zpool_import/zpool_import_009_neg.ksh usr/src/test/zfs-tests/tests/functional/cli_root/zpool_import/zpool_import_010_pos.ksh usr/src/test/zfs-tests/tests/functional/cli_root/zpool_import/zpool_import_011_neg.ksh usr/src/test/zfs-tests/tests/functional/cli_root/zpool_import/zpool_import_012_pos.ksh usr/src/test/zfs-tests/tests/functional/cli_root/zpool_import/zpool_import_013_neg.ksh usr/src/test/zfs-tests/tests/functional/cli_root/zpool_import/zpool_import_all_001_pos.ksh usr/src/test/zfs-tests/tests/functional/cli_root/zpool_import/zpool_import_features_001_pos.ksh usr/src/test/zfs-tests/tests/functional/cli_root/zpool_import/zpool_import_features_002_neg.ksh usr/src/test/zfs-tests/tests/functional/cli_root/zpool_import/zpool_import_features_003_pos.ksh usr/src/test/zfs-tests/tests/functional/cli_root/zpool_import/zpool_import_missing_001_pos.ksh usr/src/test/zfs-tests/tests/functional/cli_root/zpool_import/zpool_import_missing_002_pos.ksh usr/src/test/zfs-tests/tests/functional/cli_root/zpool_import/zpool_import_missing_003_pos.ksh usr/src/test/zfs-tests/tests/functional/cli_root/zpool_import/zpool_import_rename_001_pos.ksh usr/src/test/zfs-tests/tests/functional/cli_root/zpool_offline/Makefile usr/src/test/zfs-tests/tests/functional/cli_root/zpool_offline/cleanup.ksh usr/src/test/zfs-tests/tests/functional/cli_root/zpool_offline/setup.ksh usr/src/test/zfs-tests/tests/functional/cli_root/zpool_offline/zpool_offline_001_pos.ksh usr/src/test/zfs-tests/tests/functional/cli_root/zpool_offline/zpool_offline_002_neg.ksh usr/src/test/zfs-tests/tests/functional/cli_root/zpool_online/Makefile usr/src/test/zfs-tests/tests/functional/cli_root/zpool_online/cleanup.ksh usr/src/test/zfs-tests/tests/functional/cli_root/zpool_online/setup.ksh usr/src/test/zfs-tests/tests/functional/cli_root/zpool_online/zpool_online_001_pos.ksh usr/src/test/zfs-tests/tests/functional/cli_root/zpool_online/zpool_online_002_neg.ksh usr/src/test/zfs-tests/tests/functional/cli_root/zpool_remove/Makefile usr/src/test/zfs-tests/tests/functional/cli_root/zpool_remove/cleanup.ksh usr/src/test/zfs-tests/tests/functional/cli_root/zpool_remove/setup.ksh usr/src/test/zfs-tests/tests/functional/cli_root/zpool_remove/zpool_remove.cfg usr/src/test/zfs-tests/tests/functional/cli_root/zpool_remove/zpool_remove_001_neg.ksh usr/src/test/zfs-tests/tests/functional/cli_root/zpool_remove/zpool_remove_002_pos.ksh usr/src/test/zfs-tests/tests/functional/cli_root/zpool_remove/zpool_remove_003_pos.ksh usr/src/test/zfs-tests/tests/functional/cli_root/zpool_replace/Makefile usr/src/test/zfs-tests/tests/functional/cli_root/zpool_replace/cleanup.ksh usr/src/test/zfs-tests/tests/functional/cli_root/zpool_replace/setup.ksh usr/src/test/zfs-tests/tests/functional/cli_root/zpool_replace/zpool_replace_001_neg.ksh usr/src/test/zfs-tests/tests/functional/cli_root/zpool_scrub/Makefile usr/src/test/zfs-tests/tests/functional/cli_root/zpool_scrub/cleanup.ksh usr/src/test/zfs-tests/tests/functional/cli_root/zpool_scrub/setup.ksh usr/src/test/zfs-tests/tests/functional/cli_root/zpool_scrub/zpool_scrub.cfg usr/src/test/zfs-tests/tests/functional/cli_root/zpool_scrub/zpool_scrub_001_neg.ksh usr/src/test/zfs-tests/tests/functional/cli_root/zpool_scrub/zpool_scrub_002_pos.ksh usr/src/test/zfs-tests/tests/functional/cli_root/zpool_scrub/zpool_scrub_003_pos.ksh usr/src/test/zfs-tests/tests/functional/cli_root/zpool_scrub/zpool_scrub_004_pos.ksh usr/src/test/zfs-tests/tests/functional/cli_root/zpool_scrub/zpool_scrub_005_pos.ksh usr/src/test/zfs-tests/tests/functional/cli_root/zpool_set/Makefile usr/src/test/zfs-tests/tests/functional/cli_root/zpool_set/zpool_set_001_pos.ksh usr/src/test/zfs-tests/tests/functional/cli_root/zpool_set/zpool_set_002_neg.ksh usr/src/test/zfs-tests/tests/functional/cli_root/zpool_set/zpool_set_003_neg.ksh usr/src/test/zfs-tests/tests/functional/cli_root/zpool_status/Makefile usr/src/test/zfs-tests/tests/functional/cli_root/zpool_status/cleanup.ksh usr/src/test/zfs-tests/tests/functional/cli_root/zpool_status/setup.ksh usr/src/test/zfs-tests/tests/functional/cli_root/zpool_status/zpool_status_001_pos.ksh usr/src/test/zfs-tests/tests/functional/cli_root/zpool_status/zpool_status_002_pos.ksh usr/src/test/zfs-tests/tests/functional/cli_root/zpool_upgrade/Makefile usr/src/test/zfs-tests/tests/functional/cli_root/zpool_upgrade/blockfiles/Makefile usr/src/test/zfs-tests/tests/functional/cli_root/zpool_upgrade/blockfiles/README usr/src/test/zfs-tests/tests/functional/cli_root/zpool_upgrade/blockfiles/zfs-broken-mirror1.dat.bz2 usr/src/test/zfs-tests/tests/functional/cli_root/zpool_upgrade/blockfiles/zfs-broken-mirror2.dat.bz2 usr/src/test/zfs-tests/tests/functional/cli_root/zpool_upgrade/blockfiles/zfs-pool-v1.dat.bz2 usr/src/test/zfs-tests/tests/functional/cli_root/zpool_upgrade/blockfiles/zfs-pool-v10.dat.bz2 usr/src/test/zfs-tests/tests/functional/cli_root/zpool_upgrade/blockfiles/zfs-pool-v11.dat.bz2 usr/src/test/zfs-tests/tests/functional/cli_root/zpool_upgrade/blockfiles/zfs-pool-v12.dat.bz2 usr/src/test/zfs-tests/tests/functional/cli_root/zpool_upgrade/blockfiles/zfs-pool-v13.dat.bz2 usr/src/test/zfs-tests/tests/functional/cli_root/zpool_upgrade/blockfiles/zfs-pool-v14.dat.bz2 usr/src/test/zfs-tests/tests/functional/cli_root/zpool_upgrade/blockfiles/zfs-pool-v15.dat.bz2 usr/src/test/zfs-tests/tests/functional/cli_root/zpool_upgrade/blockfiles/zfs-pool-v1mirror1.dat.bz2 usr/src/test/zfs-tests/tests/functional/cli_root/zpool_upgrade/blockfiles/zfs-pool-v1mirror2.dat.bz2 usr/src/test/zfs-tests/tests/functional/cli_root/zpool_upgrade/blockfiles/zfs-pool-v1mirror3.dat.bz2 usr/src/test/zfs-tests/tests/functional/cli_root/zpool_upgrade/blockfiles/zfs-pool-v1raidz1.dat.bz2 usr/src/test/zfs-tests/tests/functional/cli_root/zpool_upgrade/blockfiles/zfs-pool-v1raidz2.dat.bz2 usr/src/test/zfs-tests/tests/functional/cli_root/zpool_upgrade/blockfiles/zfs-pool-v1raidz3.dat.bz2 usr/src/test/zfs-tests/tests/functional/cli_root/zpool_upgrade/blockfiles/zfs-pool-v1stripe1.dat.bz2 usr/src/test/zfs-tests/tests/functional/cli_root/zpool_upgrade/blockfiles/zfs-pool-v1stripe2.dat.bz2 usr/src/test/zfs-tests/tests/functional/cli_root/zpool_upgrade/blockfiles/zfs-pool-v1stripe3.dat.bz2 usr/src/test/zfs-tests/tests/functional/cli_root/zpool_upgrade/blockfiles/zfs-pool-v2.dat.bz2 usr/src/test/zfs-tests/tests/functional/cli_root/zpool_upgrade/blockfiles/zfs-pool-v2mirror1.dat.bz2 usr/src/test/zfs-tests/tests/functional/cli_root/zpool_upgrade/blockfiles/zfs-pool-v2mirror2.dat.bz2 usr/src/test/zfs-tests/tests/functional/cli_root/zpool_upgrade/blockfiles/zfs-pool-v2mirror3.dat.bz2 usr/src/test/zfs-tests/tests/functional/cli_root/zpool_upgrade/blockfiles/zfs-pool-v2raidz1.dat.bz2 usr/src/test/zfs-tests/tests/functional/cli_root/zpool_upgrade/blockfiles/zfs-pool-v2raidz2.dat.bz2 usr/src/test/zfs-tests/tests/functional/cli_root/zpool_upgrade/blockfiles/zfs-pool-v2raidz3.dat.bz2 usr/src/test/zfs-tests/tests/functional/cli_root/zpool_upgrade/blockfiles/zfs-pool-v2stripe1.dat.bz2 usr/src/test/zfs-tests/tests/functional/cli_root/zpool_upgrade/blockfiles/zfs-pool-v2stripe2.dat.bz2 usr/src/test/zfs-tests/tests/functional/cli_root/zpool_upgrade/blockfiles/zfs-pool-v2stripe3.dat.bz2 usr/src/test/zfs-tests/tests/functional/cli_root/zpool_upgrade/blockfiles/zfs-pool-v3.dat.bz2 usr/src/test/zfs-tests/tests/functional/cli_root/zpool_upgrade/blockfiles/zfs-pool-v3hotspare1.dat.bz2 usr/src/test/zfs-tests/tests/functional/cli_root/zpool_upgrade/blockfiles/zfs-pool-v3hotspare2.dat.bz2 usr/src/test/zfs-tests/tests/functional/cli_root/zpool_upgrade/blockfiles/zfs-pool-v3hotspare3.dat.bz2 usr/src/test/zfs-tests/tests/functional/cli_root/zpool_upgrade/blockfiles/zfs-pool-v3mirror1.dat.bz2 usr/src/test/zfs-tests/tests/functional/cli_root/zpool_upgrade/blockfiles/zfs-pool-v3mirror2.dat.bz2 usr/src/test/zfs-tests/tests/functional/cli_root/zpool_upgrade/blockfiles/zfs-pool-v3mirror3.dat.bz2 usr/src/test/zfs-tests/tests/functional/cli_root/zpool_upgrade/blockfiles/zfs-pool-v3raidz1.dat.bz2 usr/src/test/zfs-tests/tests/functional/cli_root/zpool_upgrade/blockfiles/zfs-pool-v3raidz2.dat.bz2 usr/src/test/zfs-tests/tests/functional/cli_root/zpool_upgrade/blockfiles/zfs-pool-v3raidz21.dat.bz2 usr/src/test/zfs-tests/tests/functional/cli_root/zpool_upgrade/blockfiles/zfs-pool-v3raidz22.dat.bz2 usr/src/test/zfs-tests/tests/functional/cli_root/zpool_upgrade/blockfiles/zfs-pool-v3raidz23.dat.bz2 usr/src/test/zfs-tests/tests/functional/cli_root/zpool_upgrade/blockfiles/zfs-pool-v3raidz3.dat.bz2 usr/src/test/zfs-tests/tests/functional/cli_root/zpool_upgrade/blockfiles/zfs-pool-v3stripe1.dat.bz2 usr/src/test/zfs-tests/tests/functional/cli_root/zpool_upgrade/blockfiles/zfs-pool-v3stripe2.dat.bz2 usr/src/test/zfs-tests/tests/functional/cli_root/zpool_upgrade/blockfiles/zfs-pool-v3stripe3.dat.bz2 usr/src/test/zfs-tests/tests/functional/cli_root/zpool_upgrade/blockfiles/zfs-pool-v4.dat.bz2 usr/src/test/zfs-tests/tests/functional/cli_root/zpool_upgrade/blockfiles/zfs-pool-v5.dat.bz2 usr/src/test/zfs-tests/tests/functional/cli_root/zpool_upgrade/blockfiles/zfs-pool-v6.dat.bz2 usr/src/test/zfs-tests/tests/functional/cli_root/zpool_upgrade/blockfiles/zfs-pool-v7.dat.bz2 usr/src/test/zfs-tests/tests/functional/cli_root/zpool_upgrade/blockfiles/zfs-pool-v8.dat.bz2 usr/src/test/zfs-tests/tests/functional/cli_root/zpool_upgrade/blockfiles/zfs-pool-v9.dat.bz2 usr/src/test/zfs-tests/tests/functional/cli_root/zpool_upgrade/blockfiles/zfs-pool-v999.dat.bz2 usr/src/test/zfs-tests/tests/functional/cli_root/zpool_upgrade/blockfiles/zfs-pool-vBROKEN.dat.bz2 usr/src/test/zfs-tests/tests/functional/cli_root/zpool_upgrade/cleanup.ksh usr/src/test/zfs-tests/tests/functional/cli_root/zpool_upgrade/setup.ksh usr/src/test/zfs-tests/tests/functional/cli_root/zpool_upgrade/zpool_upgrade.cfg usr/src/test/zfs-tests/tests/functional/cli_root/zpool_upgrade/zpool_upgrade.kshlib usr/src/test/zfs-tests/tests/functional/cli_root/zpool_upgrade/zpool_upgrade_001_pos.ksh usr/src/test/zfs-tests/tests/functional/cli_root/zpool_upgrade/zpool_upgrade_002_pos.ksh usr/src/test/zfs-tests/tests/functional/cli_root/zpool_upgrade/zpool_upgrade_003_pos.ksh usr/src/test/zfs-tests/tests/functional/cli_root/zpool_upgrade/zpool_upgrade_004_pos.ksh usr/src/test/zfs-tests/tests/functional/cli_root/zpool_upgrade/zpool_upgrade_005_neg.ksh usr/src/test/zfs-tests/tests/functional/cli_root/zpool_upgrade/zpool_upgrade_006_neg.ksh usr/src/test/zfs-tests/tests/functional/cli_root/zpool_upgrade/zpool_upgrade_007_pos.ksh usr/src/test/zfs-tests/tests/functional/cli_root/zpool_upgrade/zpool_upgrade_008_pos.ksh usr/src/test/zfs-tests/tests/functional/cli_root/zpool_upgrade/zpool_upgrade_009_neg.ksh usr/src/test/zfs-tests/tests/functional/nopwrite/Makefile usr/src/test/zfs-tests/tests/functional/nopwrite/cleanup.ksh usr/src/test/zfs-tests/tests/functional/nopwrite/nopwrite.shlib usr/src/test/zfs-tests/tests/functional/nopwrite/nopwrite_copies.ksh usr/src/test/zfs-tests/tests/functional/nopwrite/nopwrite_mtime.ksh usr/src/test/zfs-tests/tests/functional/nopwrite/nopwrite_negative.ksh usr/src/test/zfs-tests/tests/functional/nopwrite/nopwrite_promoted_clone.ksh usr/src/test/zfs-tests/tests/functional/nopwrite/nopwrite_recsize.ksh usr/src/test/zfs-tests/tests/functional/nopwrite/nopwrite_sync.ksh usr/src/test/zfs-tests/tests/functional/nopwrite/nopwrite_varying_compression.ksh usr/src/test/zfs-tests/tests/functional/nopwrite/nopwrite_volume.ksh usr/src/test/zfs-tests/tests/functional/nopwrite/setup.ksh usr/src/test/zfs-tests/tests/functional/truncate/Makefile usr/src/test/zfs-tests/tests/functional/truncate/cleanup.ksh usr/src/test/zfs-tests/tests/functional/truncate/setup.ksh usr/src/test/zfs-tests/tests/functional/truncate/truncate.cfg usr/src/test/zfs-tests/tests/functional/truncate/truncate_001_pos.ksh usr/src/test/zfs-tests/tests/functional/truncate/truncate_002_pos.ksh usr/src/test/zfs-tests/tests/stress/Makefile
diffstat 682 files changed, 58680 insertions(+), 3 deletions(-) [+]
line wrap: on
line diff
--- a/exception_lists/keywords	Thu Dec 06 09:47:56 2012 -0800
+++ b/exception_lists/keywords	Wed Dec 05 22:04:50 2012 -0500
@@ -23,8 +23,6 @@
 #
 
 syntax: glob
-#exception_lists/cstyle
-#exception_lists/hdrchk
 usr/src/cmd/localedef/data/zh_CN.UTF-8.src
 usr/src/cmd/localedef/data/zh_HK.UTF-8.src
 usr/src/cmd/localedef/data/zh_MO.UTF-8.src
@@ -33,3 +31,5 @@
 usr/src/cmd/terminfo/termcap.src
 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/test-runner/cmd/run.py
--- a/usr/src/Makefile	Thu Dec 06 09:47:56 2012 -0800
+++ b/usr/src/Makefile	Wed Dec 05 22:04:50 2012 -0500
@@ -18,9 +18,12 @@
 #
 # CDDL HEADER END
 #
+
 #
 # Copyright (c) 1989, 2010, Oracle and/or its affiliates. All rights reserved.
+# Copyright (c) 2012 by Delphix. All rights reserved.
 #
+
 #
 # Makefile for system source
 #
@@ -31,7 +34,7 @@
 # it defines TARGETDIRS and ROOTDIRS.
 include Targetdirs
 
-COMMON_SUBDIRS=	uts lib cmd ucblib ucbcmd psm man
+COMMON_SUBDIRS=	uts lib cmd ucblib ucbcmd psm man test
 sparc_SUBDIRS= stand
 i386_SUBDIRS= grub
 
--- a/usr/src/Makefile.lint	Thu Dec 06 09:47:56 2012 -0800
+++ b/usr/src/Makefile.lint	Wed Dec 05 22:04:50 2012 -0500
@@ -469,6 +469,7 @@
 	lib/udapl \
 	lib/watchmalloc \
 	psm \
+	test \
 	ucbcmd/basename \
 	ucbcmd/biff \
 	ucbcmd/echo \
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/usr/src/pkg/manifests/system-test-ostest.mf	Wed Dec 05 22:04:50 2012 -0500
@@ -0,0 +1,33 @@
+#
+# 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) 2012 by Delphix. All rights reserved.
+#
+
+set name=pkg.fmri value=pkg:/system/test/ostest@$(PKGVERS)
+set name=pkg.description value="Miscellaneous OS Unit Tests"
+set name=pkg.summary value="OS Unit Test Suite"
+set name=info.classification \
+    value=org.opensolaris.category.2008:Development/System
+set name=variant.arch value=$(ARCH)
+dir path=opt/os-tests
+dir path=opt/os-tests/bin
+dir path=opt/os-tests/runfiles
+dir path=opt/os-tests/tests
+file path=opt/os-tests/README mode=0444
+file path=opt/os-tests/bin/ostest mode=0555
+file path=opt/os-tests/runfiles/delphix.run mode=0444
+file path=opt/os-tests/runfiles/openindiana.run mode=0444
+file path=opt/os-tests/tests/poll_test mode=0555
+license cr_Sun license=cr_Sun
+license lic_CDDL license=lic_CDDL
+depend fmri=system/test/testrunner type=require
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/usr/src/pkg/manifests/system-test-testrunner.mf	Wed Dec 05 22:04:50 2012 -0500
@@ -0,0 +1,36 @@
+#
+# 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) 2012 by Delphix. All rights reserved.
+#
+
+set name=pkg.fmri value=pkg:/system/test/testrunner@$(PKGVERS)
+set name=pkg.description value="Test Runner"
+set name=pkg.summary value="Unit Test Framework"
+set name=info.classification \
+    value=org.opensolaris.category.2008:Development/System
+set name=variant.arch value=$(ARCH)
+dir path=opt/test-runner
+dir path=opt/test-runner/bin
+dir path=opt/test-runner/man
+dir path=opt/test-runner/man/man1
+dir path=opt/test-runner/stf
+dir path=opt/test-runner/stf/contrib
+dir path=opt/test-runner/stf/contrib/include
+dir path=opt/test-runner/stf/include
+file path=opt/test-runner/bin/run mode=0555
+file path=opt/test-runner/man/man1/run.1 mode=0444
+file path=opt/test-runner/stf/contrib/include/logapi.shlib mode=0555
+file path=opt/test-runner/stf/include/stf.shlib mode=0555
+license cr_Sun license=cr_Sun
+license lic_CDDL license=lic_CDDL
+depend fmri=security/sudo type=require
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/usr/src/pkg/manifests/system-test-zfstest.mf	Wed Dec 05 22:04:50 2012 -0500
@@ -0,0 +1,1401 @@
+#
+# 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) 2012 by Delphix. All rights reserved.
+#
+
+set name=pkg.fmri value=pkg:/system/test/zfstest@$(PKGVERS)
+set name=pkg.description value="ZFS Test Suite"
+set name=pkg.summary value="ZFS Functional and Stress Tests"
+set name=info.classification \
+    value=org.opensolaris.category.2008:Development/System
+set name=variant.arch value=$(ARCH)
+dir path=opt/zfs-tests
+dir path=opt/zfs-tests/bin
+dir path=opt/zfs-tests/include
+dir path=opt/zfs-tests/runfiles
+dir path=opt/zfs-tests/tests
+dir path=opt/zfs-tests/tests/functional
+dir path=opt/zfs-tests/tests/functional/acl
+dir path=opt/zfs-tests/tests/functional/acl/cifs
+dir path=opt/zfs-tests/tests/functional/acl/nontrivial
+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/cli_root
+dir path=opt/zfs-tests/tests/functional/cli_root/zdb
+dir path=opt/zfs-tests/tests/functional/cli_root/zfs
+dir path=opt/zfs-tests/tests/functional/cli_root/zfs_clone
+dir path=opt/zfs-tests/tests/functional/cli_root/zfs_copies
+dir path=opt/zfs-tests/tests/functional/cli_root/zfs_create
+dir path=opt/zfs-tests/tests/functional/cli_root/zfs_destroy
+dir path=opt/zfs-tests/tests/functional/cli_root/zfs_get
+dir path=opt/zfs-tests/tests/functional/cli_root/zfs_inherit
+dir path=opt/zfs-tests/tests/functional/cli_root/zfs_mount
+dir path=opt/zfs-tests/tests/functional/cli_root/zfs_promote
+dir path=opt/zfs-tests/tests/functional/cli_root/zfs_property
+dir path=opt/zfs-tests/tests/functional/cli_root/zfs_receive
+dir path=opt/zfs-tests/tests/functional/cli_root/zfs_rename
+dir path=opt/zfs-tests/tests/functional/cli_root/zfs_reservation
+dir path=opt/zfs-tests/tests/functional/cli_root/zfs_rollback
+dir path=opt/zfs-tests/tests/functional/cli_root/zfs_send
+dir path=opt/zfs-tests/tests/functional/cli_root/zfs_set
+dir path=opt/zfs-tests/tests/functional/cli_root/zfs_share
+dir path=opt/zfs-tests/tests/functional/cli_root/zfs_snapshot
+dir path=opt/zfs-tests/tests/functional/cli_root/zfs_unmount
+dir path=opt/zfs-tests/tests/functional/cli_root/zfs_unshare
+dir path=opt/zfs-tests/tests/functional/cli_root/zfs_upgrade
+dir path=opt/zfs-tests/tests/functional/cli_root/zpool
+dir path=opt/zfs-tests/tests/functional/cli_root/zpool_add
+dir path=opt/zfs-tests/tests/functional/cli_root/zpool_attach
+dir path=opt/zfs-tests/tests/functional/cli_root/zpool_clear
+dir path=opt/zfs-tests/tests/functional/cli_root/zpool_create
+dir path=opt/zfs-tests/tests/functional/cli_root/zpool_destroy
+dir path=opt/zfs-tests/tests/functional/cli_root/zpool_detach
+dir path=opt/zfs-tests/tests/functional/cli_root/zpool_expand
+dir path=opt/zfs-tests/tests/functional/cli_root/zpool_export
+dir path=opt/zfs-tests/tests/functional/cli_root/zpool_get
+dir path=opt/zfs-tests/tests/functional/cli_root/zpool_history
+dir path=opt/zfs-tests/tests/functional/cli_root/zpool_import
+dir path=opt/zfs-tests/tests/functional/cli_root/zpool_import/blockfiles
+dir path=opt/zfs-tests/tests/functional/cli_root/zpool_offline
+dir path=opt/zfs-tests/tests/functional/cli_root/zpool_online
+dir path=opt/zfs-tests/tests/functional/cli_root/zpool_remove
+dir path=opt/zfs-tests/tests/functional/cli_root/zpool_replace
+dir path=opt/zfs-tests/tests/functional/cli_root/zpool_scrub
+dir path=opt/zfs-tests/tests/functional/cli_root/zpool_set
+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/nopwrite
+dir path=opt/zfs-tests/tests/functional/truncate
+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
+file path=opt/zfs-tests/bin/dir_rd_update mode=0555
+file path=opt/zfs-tests/bin/file_check mode=0555
+file path=opt/zfs-tests/bin/file_trunc mode=0555
+file path=opt/zfs-tests/bin/file_write mode=0555
+file path=opt/zfs-tests/bin/largest_file mode=0555
+file path=opt/zfs-tests/bin/mkbusy mode=0555
+file path=opt/zfs-tests/bin/mktree mode=0555
+file path=opt/zfs-tests/bin/mmapwrite mode=0555
+file path=opt/zfs-tests/bin/randfree_file mode=0555
+file path=opt/zfs-tests/bin/readmmap mode=0555
+file path=opt/zfs-tests/bin/rename_dir mode=0555
+file path=opt/zfs-tests/bin/rm_lnkcnt_zero_file mode=0555
+file path=opt/zfs-tests/bin/zfstest mode=0555
+file path=opt/zfs-tests/include/commands.cfg mode=0555
+file path=opt/zfs-tests/include/default.cfg mode=0555
+file path=opt/zfs-tests/include/libtest.shlib mode=0555
+file path=opt/zfs-tests/include/math.shlib mode=0555
+file path=opt/zfs-tests/include/properties.shlib mode=0555
+file path=opt/zfs-tests/runfiles/delphix.run mode=0444
+file path=opt/zfs-tests/runfiles/openindiana.run mode=0444
+file path=opt/zfs-tests/tests/functional/acl/acl.cfg mode=0555
+file path=opt/zfs-tests/tests/functional/acl/acl_common.kshlib mode=0555
+file path=opt/zfs-tests/tests/functional/acl/cifs/cifs.kshlib mode=0555
+file path=opt/zfs-tests/tests/functional/acl/cifs/cifs_attr_001_pos mode=0555
+file path=opt/zfs-tests/tests/functional/acl/cifs/cifs_attr_002_pos mode=0555
+file path=opt/zfs-tests/tests/functional/acl/cifs/cifs_attr_003_pos mode=0555
+file path=opt/zfs-tests/tests/functional/acl/cifs/cleanup mode=0555
+file path=opt/zfs-tests/tests/functional/acl/cifs/setup mode=0555
+file path=opt/zfs-tests/tests/functional/acl/nontrivial/cleanup mode=0555
+file path=opt/zfs-tests/tests/functional/acl/nontrivial/setup mode=0555
+file path=opt/zfs-tests/tests/functional/acl/nontrivial/zfs_acl_chmod_001_neg \
+    mode=0555
+file path=opt/zfs-tests/tests/functional/acl/nontrivial/zfs_acl_chmod_002_pos \
+    mode=0555
+file \
+    path=opt/zfs-tests/tests/functional/acl/nontrivial/zfs_acl_chmod_aclmode_001_pos \
+    mode=0555
+file \
+    path=opt/zfs-tests/tests/functional/acl/nontrivial/zfs_acl_chmod_compact_001_pos \
+    mode=0555
+file \
+    path=opt/zfs-tests/tests/functional/acl/nontrivial/zfs_acl_chmod_delete_001_pos \
+    mode=0555
+file \
+    path=opt/zfs-tests/tests/functional/acl/nontrivial/zfs_acl_chmod_inherit_001_pos \
+    mode=0555
+file \
+    path=opt/zfs-tests/tests/functional/acl/nontrivial/zfs_acl_chmod_inherit_002_neg \
+    mode=0555
+file \
+    path=opt/zfs-tests/tests/functional/acl/nontrivial/zfs_acl_chmod_inherit_002_pos \
+    mode=0555
+file \
+    path=opt/zfs-tests/tests/functional/acl/nontrivial/zfs_acl_chmod_inherit_003_pos \
+    mode=0555
+file \
+    path=opt/zfs-tests/tests/functional/acl/nontrivial/zfs_acl_chmod_inherit_004_pos \
+    mode=0555
+file \
+    path=opt/zfs-tests/tests/functional/acl/nontrivial/zfs_acl_chmod_owner_001_pos \
+    mode=0555
+file \
+    path=opt/zfs-tests/tests/functional/acl/nontrivial/zfs_acl_chmod_rwacl_001_pos \
+    mode=0555
+file \
+    path=opt/zfs-tests/tests/functional/acl/nontrivial/zfs_acl_chmod_rwx_001_pos \
+    mode=0555
+file \
+    path=opt/zfs-tests/tests/functional/acl/nontrivial/zfs_acl_chmod_rwx_002_pos \
+    mode=0555
+file \
+    path=opt/zfs-tests/tests/functional/acl/nontrivial/zfs_acl_chmod_rwx_003_pos \
+    mode=0555
+file \
+    path=opt/zfs-tests/tests/functional/acl/nontrivial/zfs_acl_chmod_rwx_004_pos \
+    mode=0555
+file \
+    path=opt/zfs-tests/tests/functional/acl/nontrivial/zfs_acl_chmod_xattr_001_pos \
+    mode=0555
+file \
+    path=opt/zfs-tests/tests/functional/acl/nontrivial/zfs_acl_chmod_xattr_002_pos \
+    mode=0555
+file path=opt/zfs-tests/tests/functional/acl/nontrivial/zfs_acl_cp_001_pos \
+    mode=0555
+file path=opt/zfs-tests/tests/functional/acl/nontrivial/zfs_acl_cp_002_pos \
+    mode=0555
+file path=opt/zfs-tests/tests/functional/acl/nontrivial/zfs_acl_cpio_001_pos \
+    mode=0555
+file path=opt/zfs-tests/tests/functional/acl/nontrivial/zfs_acl_cpio_002_pos \
+    mode=0555
+file path=opt/zfs-tests/tests/functional/acl/nontrivial/zfs_acl_find_001_pos \
+    mode=0555
+file path=opt/zfs-tests/tests/functional/acl/nontrivial/zfs_acl_ls_001_pos \
+    mode=0555
+file path=opt/zfs-tests/tests/functional/acl/nontrivial/zfs_acl_mv_001_pos \
+    mode=0555
+file path=opt/zfs-tests/tests/functional/acl/nontrivial/zfs_acl_tar_001_pos \
+    mode=0555
+file path=opt/zfs-tests/tests/functional/acl/nontrivial/zfs_acl_tar_002_pos \
+    mode=0555
+file path=opt/zfs-tests/tests/functional/acl/trivial/cleanup mode=0555
+file path=opt/zfs-tests/tests/functional/acl/trivial/setup mode=0555
+file path=opt/zfs-tests/tests/functional/acl/trivial/zfs_acl_chmod_001_pos \
+    mode=0555
+file path=opt/zfs-tests/tests/functional/acl/trivial/zfs_acl_compress_001_pos \
+    mode=0555
+file path=opt/zfs-tests/tests/functional/acl/trivial/zfs_acl_cp_001_pos \
+    mode=0555
+file path=opt/zfs-tests/tests/functional/acl/trivial/zfs_acl_cp_002_neg \
+    mode=0555
+file path=opt/zfs-tests/tests/functional/acl/trivial/zfs_acl_cp_003_neg \
+    mode=0555
+file path=opt/zfs-tests/tests/functional/acl/trivial/zfs_acl_find_001_pos \
+    mode=0555
+file path=opt/zfs-tests/tests/functional/acl/trivial/zfs_acl_find_002_neg \
+    mode=0555
+file path=opt/zfs-tests/tests/functional/acl/trivial/zfs_acl_ls_001_pos \
+    mode=0555
+file path=opt/zfs-tests/tests/functional/acl/trivial/zfs_acl_ls_002_neg \
+    mode=0555
+file path=opt/zfs-tests/tests/functional/acl/trivial/zfs_acl_mv_001_pos \
+    mode=0555
+file path=opt/zfs-tests/tests/functional/acl/trivial/zfs_acl_pack_001_pos \
+    mode=0555
+file path=opt/zfs-tests/tests/functional/acl/trivial/zfs_acl_pax_001_pos \
+    mode=0555
+file path=opt/zfs-tests/tests/functional/acl/trivial/zfs_acl_pax_002_pos \
+    mode=0555
+file path=opt/zfs-tests/tests/functional/acl/trivial/zfs_acl_pax_003_pos \
+    mode=0555
+file path=opt/zfs-tests/tests/functional/acl/trivial/zfs_acl_pax_004_pos \
+    mode=0555
+file path=opt/zfs-tests/tests/functional/acl/trivial/zfs_acl_pax_005_pos \
+    mode=0555
+file path=opt/zfs-tests/tests/functional/acl/trivial/zfs_acl_pax_006_pos \
+    mode=0555
+file path=opt/zfs-tests/tests/functional/acl/trivial/zfs_acl_tar_001_pos \
+    mode=0555
+file path=opt/zfs-tests/tests/functional/acl/trivial/zfs_acl_tar_002_neg \
+    mode=0555
+file path=opt/zfs-tests/tests/functional/atime/atime.cfg mode=0555
+file path=opt/zfs-tests/tests/functional/atime/atime_001_pos mode=0555
+file path=opt/zfs-tests/tests/functional/atime/atime_002_neg mode=0555
+file path=opt/zfs-tests/tests/functional/atime/atime_common.kshlib mode=0555
+file path=opt/zfs-tests/tests/functional/atime/cleanup mode=0555
+file path=opt/zfs-tests/tests/functional/atime/setup mode=0555
+file path=opt/zfs-tests/tests/functional/bootfs/bootfs_001_pos mode=0555
+file path=opt/zfs-tests/tests/functional/bootfs/bootfs_002_neg mode=0555
+file path=opt/zfs-tests/tests/functional/bootfs/bootfs_003_pos mode=0555
+file path=opt/zfs-tests/tests/functional/bootfs/bootfs_004_neg mode=0555
+file path=opt/zfs-tests/tests/functional/bootfs/bootfs_005_neg mode=0555
+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/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
+file path=opt/zfs-tests/tests/functional/cli_root/zfs/setup mode=0555
+file path=opt/zfs-tests/tests/functional/cli_root/zfs/zfs_001_neg mode=0555
+file path=opt/zfs-tests/tests/functional/cli_root/zfs/zfs_002_pos mode=0555
+file path=opt/zfs-tests/tests/functional/cli_root/zfs/zfs_003_neg mode=0555
+file path=opt/zfs-tests/tests/functional/cli_root/zfs_clone/cleanup mode=0555
+file path=opt/zfs-tests/tests/functional/cli_root/zfs_clone/setup mode=0555
+file path=opt/zfs-tests/tests/functional/cli_root/zfs_clone/zfs_clone_001_neg \
+    mode=0555
+file path=opt/zfs-tests/tests/functional/cli_root/zfs_clone/zfs_clone_002_pos \
+    mode=0555
+file path=opt/zfs-tests/tests/functional/cli_root/zfs_clone/zfs_clone_003_pos \
+    mode=0555
+file path=opt/zfs-tests/tests/functional/cli_root/zfs_clone/zfs_clone_004_pos \
+    mode=0555
+file path=opt/zfs-tests/tests/functional/cli_root/zfs_clone/zfs_clone_005_pos \
+    mode=0555
+file path=opt/zfs-tests/tests/functional/cli_root/zfs_clone/zfs_clone_006_pos \
+    mode=0555
+file path=opt/zfs-tests/tests/functional/cli_root/zfs_clone/zfs_clone_007_pos \
+    mode=0555
+file path=opt/zfs-tests/tests/functional/cli_root/zfs_clone/zfs_clone_008_neg \
+    mode=0555
+file path=opt/zfs-tests/tests/functional/cli_root/zfs_clone/zfs_clone_009_neg \
+    mode=0555
+file path=opt/zfs-tests/tests/functional/cli_root/zfs_clone/zfs_clone_010_pos \
+    mode=0555
+file path=opt/zfs-tests/tests/functional/cli_root/zfs_copies/cleanup mode=0555
+file path=opt/zfs-tests/tests/functional/cli_root/zfs_copies/setup mode=0555
+file path=opt/zfs-tests/tests/functional/cli_root/zfs_copies/zfs_copies.cfg \
+    mode=0555
+file path=opt/zfs-tests/tests/functional/cli_root/zfs_copies/zfs_copies.kshlib \
+    mode=0555
+file \
+    path=opt/zfs-tests/tests/functional/cli_root/zfs_copies/zfs_copies_001_pos \
+    mode=0555
+file \
+    path=opt/zfs-tests/tests/functional/cli_root/zfs_copies/zfs_copies_002_pos \
+    mode=0555
+file \
+    path=opt/zfs-tests/tests/functional/cli_root/zfs_copies/zfs_copies_003_pos \
+    mode=0555
+file \
+    path=opt/zfs-tests/tests/functional/cli_root/zfs_copies/zfs_copies_004_neg \
+    mode=0555
+file \
+    path=opt/zfs-tests/tests/functional/cli_root/zfs_copies/zfs_copies_005_neg \
+    mode=0555
+file \
+    path=opt/zfs-tests/tests/functional/cli_root/zfs_copies/zfs_copies_006_pos \
+    mode=0555
+file path=opt/zfs-tests/tests/functional/cli_root/zfs_create/cleanup mode=0555
+file path=opt/zfs-tests/tests/functional/cli_root/zfs_create/properties.kshlib \
+    mode=0555
+file path=opt/zfs-tests/tests/functional/cli_root/zfs_create/setup mode=0555
+file path=opt/zfs-tests/tests/functional/cli_root/zfs_create/zfs_create.cfg \
+    mode=0555
+file \
+    path=opt/zfs-tests/tests/functional/cli_root/zfs_create/zfs_create_001_pos \
+    mode=0555
+file \
+    path=opt/zfs-tests/tests/functional/cli_root/zfs_create/zfs_create_002_pos \
+    mode=0555
+file \
+    path=opt/zfs-tests/tests/functional/cli_root/zfs_create/zfs_create_003_pos \
+    mode=0555
+file \
+    path=opt/zfs-tests/tests/functional/cli_root/zfs_create/zfs_create_004_pos \
+    mode=0555
+file \
+    path=opt/zfs-tests/tests/functional/cli_root/zfs_create/zfs_create_005_pos \
+    mode=0555
+file \
+    path=opt/zfs-tests/tests/functional/cli_root/zfs_create/zfs_create_006_pos \
+    mode=0555
+file \
+    path=opt/zfs-tests/tests/functional/cli_root/zfs_create/zfs_create_007_pos \
+    mode=0555
+file \
+    path=opt/zfs-tests/tests/functional/cli_root/zfs_create/zfs_create_008_neg \
+    mode=0555
+file \
+    path=opt/zfs-tests/tests/functional/cli_root/zfs_create/zfs_create_009_neg \
+    mode=0555
+file \
+    path=opt/zfs-tests/tests/functional/cli_root/zfs_create/zfs_create_010_neg \
+    mode=0555
+file \
+    path=opt/zfs-tests/tests/functional/cli_root/zfs_create/zfs_create_011_pos \
+    mode=0555
+file \
+    path=opt/zfs-tests/tests/functional/cli_root/zfs_create/zfs_create_012_pos \
+    mode=0555
+file \
+    path=opt/zfs-tests/tests/functional/cli_root/zfs_create/zfs_create_013_pos \
+    mode=0555
+file \
+    path=opt/zfs-tests/tests/functional/cli_root/zfs_create/zfs_create_common.kshlib \
+    mode=0555
+file path=opt/zfs-tests/tests/functional/cli_root/zfs_destroy/cleanup \
+    mode=0555
+file path=opt/zfs-tests/tests/functional/cli_root/zfs_destroy/setup mode=0555
+file path=opt/zfs-tests/tests/functional/cli_root/zfs_destroy/zfs_destroy.cfg \
+    mode=0555
+file \
+    path=opt/zfs-tests/tests/functional/cli_root/zfs_destroy/zfs_destroy_001_pos \
+    mode=0555
+file \
+    path=opt/zfs-tests/tests/functional/cli_root/zfs_destroy/zfs_destroy_002_pos \
+    mode=0555
+file \
+    path=opt/zfs-tests/tests/functional/cli_root/zfs_destroy/zfs_destroy_003_pos \
+    mode=0555
+file \
+    path=opt/zfs-tests/tests/functional/cli_root/zfs_destroy/zfs_destroy_004_pos \
+    mode=0555
+file \
+    path=opt/zfs-tests/tests/functional/cli_root/zfs_destroy/zfs_destroy_005_neg \
+    mode=0555
+file \
+    path=opt/zfs-tests/tests/functional/cli_root/zfs_destroy/zfs_destroy_006_neg \
+    mode=0555
+file \
+    path=opt/zfs-tests/tests/functional/cli_root/zfs_destroy/zfs_destroy_007_neg \
+    mode=0555
+file \
+    path=opt/zfs-tests/tests/functional/cli_root/zfs_destroy/zfs_destroy_008_pos \
+    mode=0555
+file \
+    path=opt/zfs-tests/tests/functional/cli_root/zfs_destroy/zfs_destroy_009_pos \
+    mode=0555
+file \
+    path=opt/zfs-tests/tests/functional/cli_root/zfs_destroy/zfs_destroy_010_pos \
+    mode=0555
+file \
+    path=opt/zfs-tests/tests/functional/cli_root/zfs_destroy/zfs_destroy_011_pos \
+    mode=0555
+file \
+    path=opt/zfs-tests/tests/functional/cli_root/zfs_destroy/zfs_destroy_012_pos \
+    mode=0555
+file \
+    path=opt/zfs-tests/tests/functional/cli_root/zfs_destroy/zfs_destroy_013_neg \
+    mode=0555
+file \
+    path=opt/zfs-tests/tests/functional/cli_root/zfs_destroy/zfs_destroy_014_pos \
+    mode=0555
+file \
+    path=opt/zfs-tests/tests/functional/cli_root/zfs_destroy/zfs_destroy_015_pos \
+    mode=0555
+file \
+    path=opt/zfs-tests/tests/functional/cli_root/zfs_destroy/zfs_destroy_016_pos \
+    mode=0555
+file \
+    path=opt/zfs-tests/tests/functional/cli_root/zfs_destroy/zfs_destroy_common.kshlib \
+    mode=0555
+file path=opt/zfs-tests/tests/functional/cli_root/zfs_get/cleanup mode=0555
+file path=opt/zfs-tests/tests/functional/cli_root/zfs_get/setup mode=0555
+file path=opt/zfs-tests/tests/functional/cli_root/zfs_get/zfs_get_001_pos \
+    mode=0555
+file path=opt/zfs-tests/tests/functional/cli_root/zfs_get/zfs_get_002_pos \
+    mode=0555
+file path=opt/zfs-tests/tests/functional/cli_root/zfs_get/zfs_get_003_pos \
+    mode=0555
+file path=opt/zfs-tests/tests/functional/cli_root/zfs_get/zfs_get_004_pos \
+    mode=0555
+file path=opt/zfs-tests/tests/functional/cli_root/zfs_get/zfs_get_005_neg \
+    mode=0555
+file path=opt/zfs-tests/tests/functional/cli_root/zfs_get/zfs_get_006_neg \
+    mode=0555
+file path=opt/zfs-tests/tests/functional/cli_root/zfs_get/zfs_get_007_neg \
+    mode=0555
+file path=opt/zfs-tests/tests/functional/cli_root/zfs_get/zfs_get_008_pos \
+    mode=0555
+file path=opt/zfs-tests/tests/functional/cli_root/zfs_get/zfs_get_009_pos \
+    mode=0555
+file path=opt/zfs-tests/tests/functional/cli_root/zfs_get/zfs_get_010_neg \
+    mode=0555
+file \
+    path=opt/zfs-tests/tests/functional/cli_root/zfs_get/zfs_get_common.kshlib \
+    mode=0555
+file \
+    path=opt/zfs-tests/tests/functional/cli_root/zfs_get/zfs_get_list_d.kshlib \
+    mode=0555
+file path=opt/zfs-tests/tests/functional/cli_root/zfs_inherit/cleanup \
+    mode=0555
+file path=opt/zfs-tests/tests/functional/cli_root/zfs_inherit/setup mode=0555
+file \
+    path=opt/zfs-tests/tests/functional/cli_root/zfs_inherit/zfs_inherit_001_neg \
+    mode=0555
+file \
+    path=opt/zfs-tests/tests/functional/cli_root/zfs_inherit/zfs_inherit_002_neg \
+    mode=0555
+file \
+    path=opt/zfs-tests/tests/functional/cli_root/zfs_inherit/zfs_inherit_003_pos \
+    mode=0555
+file path=opt/zfs-tests/tests/functional/cli_root/zfs_mount/cleanup mode=0555
+file path=opt/zfs-tests/tests/functional/cli_root/zfs_mount/setup mode=0555
+file path=opt/zfs-tests/tests/functional/cli_root/zfs_mount/zfs_mount.cfg \
+    mode=0555
+file path=opt/zfs-tests/tests/functional/cli_root/zfs_mount/zfs_mount.kshlib \
+    mode=0555
+file path=opt/zfs-tests/tests/functional/cli_root/zfs_mount/zfs_mount_001_pos \
+    mode=0555
+file path=opt/zfs-tests/tests/functional/cli_root/zfs_mount/zfs_mount_002_pos \
+    mode=0555
+file path=opt/zfs-tests/tests/functional/cli_root/zfs_mount/zfs_mount_003_pos \
+    mode=0555
+file path=opt/zfs-tests/tests/functional/cli_root/zfs_mount/zfs_mount_004_pos \
+    mode=0555
+file path=opt/zfs-tests/tests/functional/cli_root/zfs_mount/zfs_mount_005_pos \
+    mode=0555
+file path=opt/zfs-tests/tests/functional/cli_root/zfs_mount/zfs_mount_006_pos \
+    mode=0555
+file path=opt/zfs-tests/tests/functional/cli_root/zfs_mount/zfs_mount_007_pos \
+    mode=0555
+file path=opt/zfs-tests/tests/functional/cli_root/zfs_mount/zfs_mount_008_pos \
+    mode=0555
+file path=opt/zfs-tests/tests/functional/cli_root/zfs_mount/zfs_mount_009_neg \
+    mode=0555
+file path=opt/zfs-tests/tests/functional/cli_root/zfs_mount/zfs_mount_010_neg \
+    mode=0555
+file path=opt/zfs-tests/tests/functional/cli_root/zfs_mount/zfs_mount_011_neg \
+    mode=0555
+file \
+    path=opt/zfs-tests/tests/functional/cli_root/zfs_mount/zfs_mount_all_001_pos \
+    mode=0555
+file path=opt/zfs-tests/tests/functional/cli_root/zfs_promote/cleanup \
+    mode=0555
+file path=opt/zfs-tests/tests/functional/cli_root/zfs_promote/setup mode=0555
+file path=opt/zfs-tests/tests/functional/cli_root/zfs_promote/zfs_promote.cfg \
+    mode=0555
+file \
+    path=opt/zfs-tests/tests/functional/cli_root/zfs_promote/zfs_promote_001_pos \
+    mode=0555
+file \
+    path=opt/zfs-tests/tests/functional/cli_root/zfs_promote/zfs_promote_002_pos \
+    mode=0555
+file \
+    path=opt/zfs-tests/tests/functional/cli_root/zfs_promote/zfs_promote_003_pos \
+    mode=0555
+file \
+    path=opt/zfs-tests/tests/functional/cli_root/zfs_promote/zfs_promote_004_pos \
+    mode=0555
+file \
+    path=opt/zfs-tests/tests/functional/cli_root/zfs_promote/zfs_promote_005_pos \
+    mode=0555
+file \
+    path=opt/zfs-tests/tests/functional/cli_root/zfs_promote/zfs_promote_006_neg \
+    mode=0555
+file \
+    path=opt/zfs-tests/tests/functional/cli_root/zfs_promote/zfs_promote_007_neg \
+    mode=0555
+file \
+    path=opt/zfs-tests/tests/functional/cli_root/zfs_promote/zfs_promote_008_pos \
+    mode=0555
+file path=opt/zfs-tests/tests/functional/cli_root/zfs_property/cleanup \
+    mode=0555
+file path=opt/zfs-tests/tests/functional/cli_root/zfs_property/setup mode=0555
+file \
+    path=opt/zfs-tests/tests/functional/cli_root/zfs_property/zfs_written_property_001_pos \
+    mode=0555
+file path=opt/zfs-tests/tests/functional/cli_root/zfs_receive/cleanup \
+    mode=0555
+file path=opt/zfs-tests/tests/functional/cli_root/zfs_receive/setup mode=0555
+file \
+    path=opt/zfs-tests/tests/functional/cli_root/zfs_receive/zfs_receive_001_pos \
+    mode=0555
+file \
+    path=opt/zfs-tests/tests/functional/cli_root/zfs_receive/zfs_receive_002_pos \
+    mode=0555
+file \
+    path=opt/zfs-tests/tests/functional/cli_root/zfs_receive/zfs_receive_003_pos \
+    mode=0555
+file \
+    path=opt/zfs-tests/tests/functional/cli_root/zfs_receive/zfs_receive_004_neg \
+    mode=0555
+file \
+    path=opt/zfs-tests/tests/functional/cli_root/zfs_receive/zfs_receive_005_neg \
+    mode=0555
+file \
+    path=opt/zfs-tests/tests/functional/cli_root/zfs_receive/zfs_receive_006_pos \
+    mode=0555
+file \
+    path=opt/zfs-tests/tests/functional/cli_root/zfs_receive/zfs_receive_007_neg \
+    mode=0555
+file \
+    path=opt/zfs-tests/tests/functional/cli_root/zfs_receive/zfs_receive_008_pos \
+    mode=0555
+file \
+    path=opt/zfs-tests/tests/functional/cli_root/zfs_receive/zfs_receive_009_neg \
+    mode=0555
+file path=opt/zfs-tests/tests/functional/cli_root/zfs_rename/cleanup mode=0555
+file path=opt/zfs-tests/tests/functional/cli_root/zfs_rename/setup mode=0555
+file path=opt/zfs-tests/tests/functional/cli_root/zfs_rename/zfs_rename.cfg \
+    mode=0555
+file path=opt/zfs-tests/tests/functional/cli_root/zfs_rename/zfs_rename.kshlib \
+    mode=0555
+file \
+    path=opt/zfs-tests/tests/functional/cli_root/zfs_rename/zfs_rename_001_pos \
+    mode=0555
+file \
+    path=opt/zfs-tests/tests/functional/cli_root/zfs_rename/zfs_rename_002_pos \
+    mode=0555
+file \
+    path=opt/zfs-tests/tests/functional/cli_root/zfs_rename/zfs_rename_003_pos \
+    mode=0555
+file \
+    path=opt/zfs-tests/tests/functional/cli_root/zfs_rename/zfs_rename_004_neg \
+    mode=0555
+file \
+    path=opt/zfs-tests/tests/functional/cli_root/zfs_rename/zfs_rename_005_neg \
+    mode=0555
+file \
+    path=opt/zfs-tests/tests/functional/cli_root/zfs_rename/zfs_rename_006_pos \
+    mode=0555
+file \
+    path=opt/zfs-tests/tests/functional/cli_root/zfs_rename/zfs_rename_007_pos \
+    mode=0555
+file \
+    path=opt/zfs-tests/tests/functional/cli_root/zfs_rename/zfs_rename_008_pos \
+    mode=0555
+file \
+    path=opt/zfs-tests/tests/functional/cli_root/zfs_rename/zfs_rename_009_neg \
+    mode=0555
+file \
+    path=opt/zfs-tests/tests/functional/cli_root/zfs_rename/zfs_rename_010_neg \
+    mode=0555
+file \
+    path=opt/zfs-tests/tests/functional/cli_root/zfs_rename/zfs_rename_011_pos \
+    mode=0555
+file \
+    path=opt/zfs-tests/tests/functional/cli_root/zfs_rename/zfs_rename_012_neg \
+    mode=0555
+file \
+    path=opt/zfs-tests/tests/functional/cli_root/zfs_rename/zfs_rename_013_pos \
+    mode=0555
+file path=opt/zfs-tests/tests/functional/cli_root/zfs_reservation/cleanup \
+    mode=0555
+file path=opt/zfs-tests/tests/functional/cli_root/zfs_reservation/setup \
+    mode=0555
+file \
+    path=opt/zfs-tests/tests/functional/cli_root/zfs_reservation/zfs_reservation_001_pos \
+    mode=0555
+file \
+    path=opt/zfs-tests/tests/functional/cli_root/zfs_reservation/zfs_reservation_002_pos \
+    mode=0555
+file path=opt/zfs-tests/tests/functional/cli_root/zfs_rollback/cleanup \
+    mode=0555
+file path=opt/zfs-tests/tests/functional/cli_root/zfs_rollback/setup mode=0555
+file \
+    path=opt/zfs-tests/tests/functional/cli_root/zfs_rollback/zfs_rollback.cfg \
+    mode=0555
+file \
+    path=opt/zfs-tests/tests/functional/cli_root/zfs_rollback/zfs_rollback_001_pos \
+    mode=0555
+file \
+    path=opt/zfs-tests/tests/functional/cli_root/zfs_rollback/zfs_rollback_002_pos \
+    mode=0555
+file \
+    path=opt/zfs-tests/tests/functional/cli_root/zfs_rollback/zfs_rollback_003_neg \
+    mode=0555
+file \
+    path=opt/zfs-tests/tests/functional/cli_root/zfs_rollback/zfs_rollback_004_neg \
+    mode=0555
+file \
+    path=opt/zfs-tests/tests/functional/cli_root/zfs_rollback/zfs_rollback_common.kshlib \
+    mode=0555
+file path=opt/zfs-tests/tests/functional/cli_root/zfs_send/cleanup mode=0555
+file path=opt/zfs-tests/tests/functional/cli_root/zfs_send/setup mode=0555
+file path=opt/zfs-tests/tests/functional/cli_root/zfs_send/zfs_send.cfg \
+    mode=0555
+file path=opt/zfs-tests/tests/functional/cli_root/zfs_send/zfs_send_001_pos \
+    mode=0555
+file path=opt/zfs-tests/tests/functional/cli_root/zfs_send/zfs_send_002_pos \
+    mode=0555
+file path=opt/zfs-tests/tests/functional/cli_root/zfs_send/zfs_send_003_pos \
+    mode=0555
+file path=opt/zfs-tests/tests/functional/cli_root/zfs_send/zfs_send_004_neg \
+    mode=0555
+file path=opt/zfs-tests/tests/functional/cli_root/zfs_send/zfs_send_005_pos \
+    mode=0555
+file path=opt/zfs-tests/tests/functional/cli_root/zfs_send/zfs_send_006_pos \
+    mode=0555
+file path=opt/zfs-tests/tests/functional/cli_root/zfs_set/cache_001_pos \
+    mode=0555
+file path=opt/zfs-tests/tests/functional/cli_root/zfs_set/cache_002_neg \
+    mode=0555
+file path=opt/zfs-tests/tests/functional/cli_root/zfs_set/canmount_001_pos \
+    mode=0555
+file path=opt/zfs-tests/tests/functional/cli_root/zfs_set/canmount_002_pos \
+    mode=0555
+file path=opt/zfs-tests/tests/functional/cli_root/zfs_set/canmount_003_pos \
+    mode=0555
+file path=opt/zfs-tests/tests/functional/cli_root/zfs_set/canmount_004_pos \
+    mode=0555
+file path=opt/zfs-tests/tests/functional/cli_root/zfs_set/checksum_001_pos \
+    mode=0555
+file path=opt/zfs-tests/tests/functional/cli_root/zfs_set/cleanup mode=0555
+file path=opt/zfs-tests/tests/functional/cli_root/zfs_set/compression_001_pos \
+    mode=0555
+file path=opt/zfs-tests/tests/functional/cli_root/zfs_set/mountpoint_001_pos \
+    mode=0555
+file path=opt/zfs-tests/tests/functional/cli_root/zfs_set/mountpoint_002_pos \
+    mode=0555
+file path=opt/zfs-tests/tests/functional/cli_root/zfs_set/mountpoint_003_pos \
+    mode=0555
+file path=opt/zfs-tests/tests/functional/cli_root/zfs_set/onoffs_001_pos \
+    mode=0555
+file \
+    path=opt/zfs-tests/tests/functional/cli_root/zfs_set/property_alias_001_pos \
+    mode=0555
+file path=opt/zfs-tests/tests/functional/cli_root/zfs_set/readonly_001_pos \
+    mode=0555
+file path=opt/zfs-tests/tests/functional/cli_root/zfs_set/reservation_001_neg \
+    mode=0555
+file path=opt/zfs-tests/tests/functional/cli_root/zfs_set/ro_props_001_pos \
+    mode=0555
+file path=opt/zfs-tests/tests/functional/cli_root/zfs_set/setup mode=0555
+file path=opt/zfs-tests/tests/functional/cli_root/zfs_set/share_mount_001_neg \
+    mode=0555
+file path=opt/zfs-tests/tests/functional/cli_root/zfs_set/snapdir_001_pos \
+    mode=0555
+file \
+    path=opt/zfs-tests/tests/functional/cli_root/zfs_set/user_property_001_pos \
+    mode=0555
+file \
+    path=opt/zfs-tests/tests/functional/cli_root/zfs_set/user_property_002_pos \
+    mode=0555
+file \
+    path=opt/zfs-tests/tests/functional/cli_root/zfs_set/user_property_003_neg \
+    mode=0555
+file \
+    path=opt/zfs-tests/tests/functional/cli_root/zfs_set/user_property_004_pos \
+    mode=0555
+file path=opt/zfs-tests/tests/functional/cli_root/zfs_set/version_001_neg \
+    mode=0555
+file path=opt/zfs-tests/tests/functional/cli_root/zfs_set/zfs_set_001_neg \
+    mode=0555
+file path=opt/zfs-tests/tests/functional/cli_root/zfs_set/zfs_set_002_neg \
+    mode=0555
+file path=opt/zfs-tests/tests/functional/cli_root/zfs_set/zfs_set_003_neg \
+    mode=0555
+file \
+    path=opt/zfs-tests/tests/functional/cli_root/zfs_set/zfs_set_common.kshlib \
+    mode=0555
+file path=opt/zfs-tests/tests/functional/cli_root/zfs_share/cleanup mode=0555
+file path=opt/zfs-tests/tests/functional/cli_root/zfs_share/setup mode=0555
+file path=opt/zfs-tests/tests/functional/cli_root/zfs_share/zfs_share.cfg \
+    mode=0555
+file path=opt/zfs-tests/tests/functional/cli_root/zfs_share/zfs_share_001_pos \
+    mode=0555
+file path=opt/zfs-tests/tests/functional/cli_root/zfs_share/zfs_share_002_pos \
+    mode=0555
+file path=opt/zfs-tests/tests/functional/cli_root/zfs_share/zfs_share_003_pos \
+    mode=0555
+file path=opt/zfs-tests/tests/functional/cli_root/zfs_share/zfs_share_004_pos \
+    mode=0555
+file path=opt/zfs-tests/tests/functional/cli_root/zfs_share/zfs_share_005_pos \
+    mode=0555
+file path=opt/zfs-tests/tests/functional/cli_root/zfs_share/zfs_share_006_pos \
+    mode=0555
+file path=opt/zfs-tests/tests/functional/cli_root/zfs_share/zfs_share_007_neg \
+    mode=0555
+file path=opt/zfs-tests/tests/functional/cli_root/zfs_share/zfs_share_008_neg \
+    mode=0555
+file path=opt/zfs-tests/tests/functional/cli_root/zfs_share/zfs_share_009_neg \
+    mode=0555
+file path=opt/zfs-tests/tests/functional/cli_root/zfs_share/zfs_share_010_neg \
+    mode=0555
+file path=opt/zfs-tests/tests/functional/cli_root/zfs_share/zfs_share_011_pos \
+    mode=0555
+file path=opt/zfs-tests/tests/functional/cli_root/zfs_snapshot/cleanup \
+    mode=0555
+file path=opt/zfs-tests/tests/functional/cli_root/zfs_snapshot/setup mode=0555
+file \
+    path=opt/zfs-tests/tests/functional/cli_root/zfs_snapshot/zfs_snapshot.cfg \
+    mode=0555
+file \
+    path=opt/zfs-tests/tests/functional/cli_root/zfs_snapshot/zfs_snapshot_001_neg \
+    mode=0555
+file \
+    path=opt/zfs-tests/tests/functional/cli_root/zfs_snapshot/zfs_snapshot_002_neg \
+    mode=0555
+file \
+    path=opt/zfs-tests/tests/functional/cli_root/zfs_snapshot/zfs_snapshot_003_neg \
+    mode=0555
+file \
+    path=opt/zfs-tests/tests/functional/cli_root/zfs_snapshot/zfs_snapshot_004_neg \
+    mode=0555
+file \
+    path=opt/zfs-tests/tests/functional/cli_root/zfs_snapshot/zfs_snapshot_005_neg \
+    mode=0555
+file \
+    path=opt/zfs-tests/tests/functional/cli_root/zfs_snapshot/zfs_snapshot_006_pos \
+    mode=0555
+file \
+    path=opt/zfs-tests/tests/functional/cli_root/zfs_snapshot/zfs_snapshot_007_neg \
+    mode=0555
+file \
+    path=opt/zfs-tests/tests/functional/cli_root/zfs_snapshot/zfs_snapshot_008_neg \
+    mode=0555
+file \
+    path=opt/zfs-tests/tests/functional/cli_root/zfs_snapshot/zfs_snapshot_009_pos \
+    mode=0555
+file path=opt/zfs-tests/tests/functional/cli_root/zfs_unmount/cleanup \
+    mode=0555
+file path=opt/zfs-tests/tests/functional/cli_root/zfs_unmount/setup mode=0555
+file path=opt/zfs-tests/tests/functional/cli_root/zfs_unmount/zfs_unmount.cfg \
+    mode=0555
+file \
+    path=opt/zfs-tests/tests/functional/cli_root/zfs_unmount/zfs_unmount.kshlib \
+    mode=0555
+file \
+    path=opt/zfs-tests/tests/functional/cli_root/zfs_unmount/zfs_unmount_001_pos \
+    mode=0555
+file \
+    path=opt/zfs-tests/tests/functional/cli_root/zfs_unmount/zfs_unmount_002_pos \
+    mode=0555
+file \
+    path=opt/zfs-tests/tests/functional/cli_root/zfs_unmount/zfs_unmount_003_pos \
+    mode=0555
+file \
+    path=opt/zfs-tests/tests/functional/cli_root/zfs_unmount/zfs_unmount_004_pos \
+    mode=0555
+file \
+    path=opt/zfs-tests/tests/functional/cli_root/zfs_unmount/zfs_unmount_005_pos \
+    mode=0555
+file \
+    path=opt/zfs-tests/tests/functional/cli_root/zfs_unmount/zfs_unmount_006_pos \
+    mode=0555
+file \
+    path=opt/zfs-tests/tests/functional/cli_root/zfs_unmount/zfs_unmount_007_neg \
+    mode=0555
+file \
+    path=opt/zfs-tests/tests/functional/cli_root/zfs_unmount/zfs_unmount_008_neg \
+    mode=0555
+file \
+    path=opt/zfs-tests/tests/functional/cli_root/zfs_unmount/zfs_unmount_009_pos \
+    mode=0555
+file \
+    path=opt/zfs-tests/tests/functional/cli_root/zfs_unmount/zfs_unmount_all_001_pos \
+    mode=0555
+file path=opt/zfs-tests/tests/functional/cli_root/zfs_unshare/cleanup \
+    mode=0555
+file path=opt/zfs-tests/tests/functional/cli_root/zfs_unshare/setup mode=0555
+file \
+    path=opt/zfs-tests/tests/functional/cli_root/zfs_unshare/zfs_unshare_001_pos \
+    mode=0555
+file \
+    path=opt/zfs-tests/tests/functional/cli_root/zfs_unshare/zfs_unshare_002_pos \
+    mode=0555
+file \
+    path=opt/zfs-tests/tests/functional/cli_root/zfs_unshare/zfs_unshare_003_pos \
+    mode=0555
+file \
+    path=opt/zfs-tests/tests/functional/cli_root/zfs_unshare/zfs_unshare_004_neg \
+    mode=0555
+file \
+    path=opt/zfs-tests/tests/functional/cli_root/zfs_unshare/zfs_unshare_005_neg \
+    mode=0555
+file path=opt/zfs-tests/tests/functional/cli_root/zfs_upgrade/cleanup \
+    mode=0555
+file path=opt/zfs-tests/tests/functional/cli_root/zfs_upgrade/setup mode=0555
+file \
+    path=opt/zfs-tests/tests/functional/cli_root/zfs_upgrade/zfs_upgrade.kshlib \
+    mode=0555
+file \
+    path=opt/zfs-tests/tests/functional/cli_root/zfs_upgrade/zfs_upgrade_001_pos \
+    mode=0555
+file \
+    path=opt/zfs-tests/tests/functional/cli_root/zfs_upgrade/zfs_upgrade_002_pos \
+    mode=0555
+file \
+    path=opt/zfs-tests/tests/functional/cli_root/zfs_upgrade/zfs_upgrade_003_pos \
+    mode=0555
+file \
+    path=opt/zfs-tests/tests/functional/cli_root/zfs_upgrade/zfs_upgrade_004_pos \
+    mode=0555
+file \
+    path=opt/zfs-tests/tests/functional/cli_root/zfs_upgrade/zfs_upgrade_005_pos \
+    mode=0555
+file \
+    path=opt/zfs-tests/tests/functional/cli_root/zfs_upgrade/zfs_upgrade_006_neg \
+    mode=0555
+file \
+    path=opt/zfs-tests/tests/functional/cli_root/zfs_upgrade/zfs_upgrade_007_neg \
+    mode=0555
+file path=opt/zfs-tests/tests/functional/cli_root/zpool/cleanup mode=0555
+file path=opt/zfs-tests/tests/functional/cli_root/zpool/setup mode=0555
+file path=opt/zfs-tests/tests/functional/cli_root/zpool/zpool_001_neg \
+    mode=0555
+file path=opt/zfs-tests/tests/functional/cli_root/zpool/zpool_002_pos \
+    mode=0555
+file path=opt/zfs-tests/tests/functional/cli_root/zpool/zpool_003_pos \
+    mode=0555
+file path=opt/zfs-tests/tests/functional/cli_root/zpool_add/cleanup mode=0555
+file path=opt/zfs-tests/tests/functional/cli_root/zpool_add/setup mode=0555
+file path=opt/zfs-tests/tests/functional/cli_root/zpool_add/zpool_add.cfg \
+    mode=0555
+file path=opt/zfs-tests/tests/functional/cli_root/zpool_add/zpool_add.kshlib \
+    mode=0555
+file path=opt/zfs-tests/tests/functional/cli_root/zpool_add/zpool_add_001_pos \
+    mode=0555
+file path=opt/zfs-tests/tests/functional/cli_root/zpool_add/zpool_add_002_pos \
+    mode=0555
+file path=opt/zfs-tests/tests/functional/cli_root/zpool_add/zpool_add_003_pos \
+    mode=0555
+file path=opt/zfs-tests/tests/functional/cli_root/zpool_add/zpool_add_004_pos \
+    mode=0555
+file path=opt/zfs-tests/tests/functional/cli_root/zpool_add/zpool_add_005_pos \
+    mode=0555
+file path=opt/zfs-tests/tests/functional/cli_root/zpool_add/zpool_add_006_pos \
+    mode=0555
+file path=opt/zfs-tests/tests/functional/cli_root/zpool_add/zpool_add_007_neg \
+    mode=0555
+file path=opt/zfs-tests/tests/functional/cli_root/zpool_add/zpool_add_008_neg \
+    mode=0555
+file path=opt/zfs-tests/tests/functional/cli_root/zpool_add/zpool_add_009_neg \
+    mode=0555
+file path=opt/zfs-tests/tests/functional/cli_root/zpool_attach/cleanup \
+    mode=0555
+file path=opt/zfs-tests/tests/functional/cli_root/zpool_attach/setup mode=0555
+file \
+    path=opt/zfs-tests/tests/functional/cli_root/zpool_attach/zpool_attach_001_neg \
+    mode=0555
+file path=opt/zfs-tests/tests/functional/cli_root/zpool_clear/cleanup \
+    mode=0555
+file path=opt/zfs-tests/tests/functional/cli_root/zpool_clear/setup mode=0555
+file path=opt/zfs-tests/tests/functional/cli_root/zpool_clear/zpool_clear.cfg \
+    mode=0555
+file \
+    path=opt/zfs-tests/tests/functional/cli_root/zpool_clear/zpool_clear_001_pos \
+    mode=0555
+file \
+    path=opt/zfs-tests/tests/functional/cli_root/zpool_clear/zpool_clear_002_neg \
+    mode=0555
+file \
+    path=opt/zfs-tests/tests/functional/cli_root/zpool_clear/zpool_clear_003_neg \
+    mode=0555
+file path=opt/zfs-tests/tests/functional/cli_root/zpool_create/cleanup \
+    mode=0555
+file path=opt/zfs-tests/tests/functional/cli_root/zpool_create/setup mode=0555
+file \
+    path=opt/zfs-tests/tests/functional/cli_root/zpool_create/zpool_create.cfg \
+    mode=0555
+file \
+    path=opt/zfs-tests/tests/functional/cli_root/zpool_create/zpool_create.shlib \
+    mode=0555
+file \
+    path=opt/zfs-tests/tests/functional/cli_root/zpool_create/zpool_create_001_pos \
+    mode=0555
+file \
+    path=opt/zfs-tests/tests/functional/cli_root/zpool_create/zpool_create_002_pos \
+    mode=0555
+file \
+    path=opt/zfs-tests/tests/functional/cli_root/zpool_create/zpool_create_003_pos \
+    mode=0555
+file \
+    path=opt/zfs-tests/tests/functional/cli_root/zpool_create/zpool_create_004_pos \
+    mode=0555
+file \
+    path=opt/zfs-tests/tests/functional/cli_root/zpool_create/zpool_create_005_pos \
+    mode=0555
+file \
+    path=opt/zfs-tests/tests/functional/cli_root/zpool_create/zpool_create_006_pos \
+    mode=0555
+file \
+    path=opt/zfs-tests/tests/functional/cli_root/zpool_create/zpool_create_007_neg \
+    mode=0555
+file \
+    path=opt/zfs-tests/tests/functional/cli_root/zpool_create/zpool_create_008_pos \
+    mode=0555
+file \
+    path=opt/zfs-tests/tests/functional/cli_root/zpool_create/zpool_create_009_neg \
+    mode=0555
+file \
+    path=opt/zfs-tests/tests/functional/cli_root/zpool_create/zpool_create_010_neg \
+    mode=0555
+file \
+    path=opt/zfs-tests/tests/functional/cli_root/zpool_create/zpool_create_011_neg \
+    mode=0555
+file \
+    path=opt/zfs-tests/tests/functional/cli_root/zpool_create/zpool_create_012_neg \
+    mode=0555
+file \
+    path=opt/zfs-tests/tests/functional/cli_root/zpool_create/zpool_create_013_neg \
+    mode=0555
+file \
+    path=opt/zfs-tests/tests/functional/cli_root/zpool_create/zpool_create_014_neg \
+    mode=0555
+file \
+    path=opt/zfs-tests/tests/functional/cli_root/zpool_create/zpool_create_015_neg \
+    mode=0555
+file \
+    path=opt/zfs-tests/tests/functional/cli_root/zpool_create/zpool_create_016_pos \
+    mode=0555
+file \
+    path=opt/zfs-tests/tests/functional/cli_root/zpool_create/zpool_create_017_neg \
+    mode=0555
+file \
+    path=opt/zfs-tests/tests/functional/cli_root/zpool_create/zpool_create_018_pos \
+    mode=0555
+file \
+    path=opt/zfs-tests/tests/functional/cli_root/zpool_create/zpool_create_019_pos \
+    mode=0555
+file \
+    path=opt/zfs-tests/tests/functional/cli_root/zpool_create/zpool_create_020_pos \
+    mode=0555
+file \
+    path=opt/zfs-tests/tests/functional/cli_root/zpool_create/zpool_create_021_pos \
+    mode=0555
+file \
+    path=opt/zfs-tests/tests/functional/cli_root/zpool_create/zpool_create_022_pos \
+    mode=0555
+file \
+    path=opt/zfs-tests/tests/functional/cli_root/zpool_create/zpool_create_023_neg \
+    mode=0555
+file \
+    path=opt/zfs-tests/tests/functional/cli_root/zpool_create/zpool_create_features_001_pos \
+    mode=0555
+file \
+    path=opt/zfs-tests/tests/functional/cli_root/zpool_create/zpool_create_features_002_pos \
+    mode=0555
+file \
+    path=opt/zfs-tests/tests/functional/cli_root/zpool_create/zpool_create_features_003_pos \
+    mode=0555
+file \
+    path=opt/zfs-tests/tests/functional/cli_root/zpool_create/zpool_create_features_004_neg \
+    mode=0555
+file \
+    path=opt/zfs-tests/tests/functional/cli_root/zpool_destroy/zpool_destroy.cfg \
+    mode=0555
+file \
+    path=opt/zfs-tests/tests/functional/cli_root/zpool_destroy/zpool_destroy_001_pos \
+    mode=0555
+file \
+    path=opt/zfs-tests/tests/functional/cli_root/zpool_destroy/zpool_destroy_002_pos \
+    mode=0555
+file \
+    path=opt/zfs-tests/tests/functional/cli_root/zpool_destroy/zpool_destroy_003_neg \
+    mode=0555
+file path=opt/zfs-tests/tests/functional/cli_root/zpool_detach/cleanup \
+    mode=0555
+file path=opt/zfs-tests/tests/functional/cli_root/zpool_detach/setup mode=0555
+file \
+    path=opt/zfs-tests/tests/functional/cli_root/zpool_detach/zpool_detach_001_neg \
+    mode=0555
+file path=opt/zfs-tests/tests/functional/cli_root/zpool_expand/cleanup \
+    mode=0555
+file path=opt/zfs-tests/tests/functional/cli_root/zpool_expand/setup mode=0555
+file \
+    path=opt/zfs-tests/tests/functional/cli_root/zpool_expand/zpool_expand.cfg \
+    mode=0555
+file \
+    path=opt/zfs-tests/tests/functional/cli_root/zpool_expand/zpool_expand_001_pos \
+    mode=0555
+file \
+    path=opt/zfs-tests/tests/functional/cli_root/zpool_expand/zpool_expand_002_pos \
+    mode=0555
+file \
+    path=opt/zfs-tests/tests/functional/cli_root/zpool_expand/zpool_expand_003_neg \
+    mode=0555
+file path=opt/zfs-tests/tests/functional/cli_root/zpool_export/cleanup \
+    mode=0555
+file path=opt/zfs-tests/tests/functional/cli_root/zpool_export/setup mode=0555
+file \
+    path=opt/zfs-tests/tests/functional/cli_root/zpool_export/zpool_export_001_pos \
+    mode=0555
+file \
+    path=opt/zfs-tests/tests/functional/cli_root/zpool_export/zpool_export_002_pos \
+    mode=0555
+file \
+    path=opt/zfs-tests/tests/functional/cli_root/zpool_export/zpool_export_003_neg \
+    mode=0555
+file \
+    path=opt/zfs-tests/tests/functional/cli_root/zpool_export/zpool_export_004_pos \
+    mode=0555
+file path=opt/zfs-tests/tests/functional/cli_root/zpool_get/cleanup mode=0555
+file path=opt/zfs-tests/tests/functional/cli_root/zpool_get/setup mode=0555
+file path=opt/zfs-tests/tests/functional/cli_root/zpool_get/zpool_get.cfg \
+    mode=0555
+file path=opt/zfs-tests/tests/functional/cli_root/zpool_get/zpool_get_001_pos \
+    mode=0555
+file path=opt/zfs-tests/tests/functional/cli_root/zpool_get/zpool_get_002_pos \
+    mode=0555
+file path=opt/zfs-tests/tests/functional/cli_root/zpool_get/zpool_get_003_pos \
+    mode=0555
+file path=opt/zfs-tests/tests/functional/cli_root/zpool_get/zpool_get_004_neg \
+    mode=0555
+file path=opt/zfs-tests/tests/functional/cli_root/zpool_history/cleanup \
+    mode=0555
+file path=opt/zfs-tests/tests/functional/cli_root/zpool_history/setup \
+    mode=0555
+file \
+    path=opt/zfs-tests/tests/functional/cli_root/zpool_history/zpool_history_001_neg \
+    mode=0555
+file \
+    path=opt/zfs-tests/tests/functional/cli_root/zpool_history/zpool_history_002_pos \
+    mode=0555
+file \
+    path=opt/zfs-tests/tests/functional/cli_root/zpool_import/blockfiles/unclean_export.dat.bz2 \
+    mode=0444
+file path=opt/zfs-tests/tests/functional/cli_root/zpool_import/cleanup \
+    mode=0555
+file path=opt/zfs-tests/tests/functional/cli_root/zpool_import/setup mode=0555
+file \
+    path=opt/zfs-tests/tests/functional/cli_root/zpool_import/zpool_import.cfg \
+    mode=0555
+file \
+    path=opt/zfs-tests/tests/functional/cli_root/zpool_import/zpool_import_001_pos \
+    mode=0555
+file \
+    path=opt/zfs-tests/tests/functional/cli_root/zpool_import/zpool_import_002_pos \
+    mode=0555
+file \
+    path=opt/zfs-tests/tests/functional/cli_root/zpool_import/zpool_import_003_pos \
+    mode=0555
+file \
+    path=opt/zfs-tests/tests/functional/cli_root/zpool_import/zpool_import_004_pos \
+    mode=0555
+file \
+    path=opt/zfs-tests/tests/functional/cli_root/zpool_import/zpool_import_005_pos \
+    mode=0555
+file \
+    path=opt/zfs-tests/tests/functional/cli_root/zpool_import/zpool_import_006_pos \
+    mode=0555
+file \
+    path=opt/zfs-tests/tests/functional/cli_root/zpool_import/zpool_import_007_pos \
+    mode=0555
+file \
+    path=opt/zfs-tests/tests/functional/cli_root/zpool_import/zpool_import_008_pos \
+    mode=0555
+file \
+    path=opt/zfs-tests/tests/functional/cli_root/zpool_import/zpool_import_009_neg \
+    mode=0555
+file \
+    path=opt/zfs-tests/tests/functional/cli_root/zpool_import/zpool_import_010_pos \
+    mode=0555
+file \
+    path=opt/zfs-tests/tests/functional/cli_root/zpool_import/zpool_import_011_neg \
+    mode=0555
+file \
+    path=opt/zfs-tests/tests/functional/cli_root/zpool_import/zpool_import_012_pos \
+    mode=0555
+file \
+    path=opt/zfs-tests/tests/functional/cli_root/zpool_import/zpool_import_013_neg \
+    mode=0555
+file \
+    path=opt/zfs-tests/tests/functional/cli_root/zpool_import/zpool_import_all_001_pos \
+    mode=0555
+file \
+    path=opt/zfs-tests/tests/functional/cli_root/zpool_import/zpool_import_features_001_pos \
+    mode=0555
+file \
+    path=opt/zfs-tests/tests/functional/cli_root/zpool_import/zpool_import_features_002_neg \
+    mode=0555
+file \
+    path=opt/zfs-tests/tests/functional/cli_root/zpool_import/zpool_import_features_003_pos \
+    mode=0555
+file \
+    path=opt/zfs-tests/tests/functional/cli_root/zpool_import/zpool_import_missing_001_pos \
+    mode=0555
+file \
+    path=opt/zfs-tests/tests/functional/cli_root/zpool_import/zpool_import_missing_002_pos \
+    mode=0555
+file \
+    path=opt/zfs-tests/tests/functional/cli_root/zpool_import/zpool_import_missing_003_pos \
+    mode=0555
+file \
+    path=opt/zfs-tests/tests/functional/cli_root/zpool_import/zpool_import_rename_001_pos \
+    mode=0555
+file path=opt/zfs-tests/tests/functional/cli_root/zpool_offline/cleanup \
+    mode=0555
+file path=opt/zfs-tests/tests/functional/cli_root/zpool_offline/setup \
+    mode=0555
+file \
+    path=opt/zfs-tests/tests/functional/cli_root/zpool_offline/zpool_offline_001_pos \
+    mode=0555
+file \
+    path=opt/zfs-tests/tests/functional/cli_root/zpool_offline/zpool_offline_002_neg \
+    mode=0555
+file path=opt/zfs-tests/tests/functional/cli_root/zpool_online/cleanup \
+    mode=0555
+file path=opt/zfs-tests/tests/functional/cli_root/zpool_online/setup mode=0555
+file \
+    path=opt/zfs-tests/tests/functional/cli_root/zpool_online/zpool_online_001_pos \
+    mode=0555
+file \
+    path=opt/zfs-tests/tests/functional/cli_root/zpool_online/zpool_online_002_neg \
+    mode=0555
+file path=opt/zfs-tests/tests/functional/cli_root/zpool_remove/cleanup \
+    mode=0555
+file path=opt/zfs-tests/tests/functional/cli_root/zpool_remove/setup mode=0555
+file \
+    path=opt/zfs-tests/tests/functional/cli_root/zpool_remove/zpool_remove.cfg \
+    mode=0555
+file \
+    path=opt/zfs-tests/tests/functional/cli_root/zpool_remove/zpool_remove_001_neg \
+    mode=0555
+file \
+    path=opt/zfs-tests/tests/functional/cli_root/zpool_remove/zpool_remove_002_pos \
+    mode=0555
+file \
+    path=opt/zfs-tests/tests/functional/cli_root/zpool_remove/zpool_remove_003_pos \
+    mode=0555
+file path=opt/zfs-tests/tests/functional/cli_root/zpool_replace/cleanup \
+    mode=0555
+file path=opt/zfs-tests/tests/functional/cli_root/zpool_replace/setup \
+    mode=0555
+file \
+    path=opt/zfs-tests/tests/functional/cli_root/zpool_replace/zpool_replace_001_neg \
+    mode=0555
+file path=opt/zfs-tests/tests/functional/cli_root/zpool_scrub/cleanup \
+    mode=0555
+file path=opt/zfs-tests/tests/functional/cli_root/zpool_scrub/setup mode=0555
+file path=opt/zfs-tests/tests/functional/cli_root/zpool_scrub/zpool_scrub.cfg \
+    mode=0555
+file \
+    path=opt/zfs-tests/tests/functional/cli_root/zpool_scrub/zpool_scrub_001_neg \
+    mode=0555
+file \
+    path=opt/zfs-tests/tests/functional/cli_root/zpool_scrub/zpool_scrub_002_pos \
+    mode=0555
+file \
+    path=opt/zfs-tests/tests/functional/cli_root/zpool_scrub/zpool_scrub_003_pos \
+    mode=0555
+file \
+    path=opt/zfs-tests/tests/functional/cli_root/zpool_scrub/zpool_scrub_004_pos \
+    mode=0555
+file \
+    path=opt/zfs-tests/tests/functional/cli_root/zpool_scrub/zpool_scrub_005_pos \
+    mode=0555
+file path=opt/zfs-tests/tests/functional/cli_root/zpool_set/zpool_set_001_pos \
+    mode=0555
+file path=opt/zfs-tests/tests/functional/cli_root/zpool_set/zpool_set_002_neg \
+    mode=0555
+file path=opt/zfs-tests/tests/functional/cli_root/zpool_set/zpool_set_003_neg \
+    mode=0555
+file path=opt/zfs-tests/tests/functional/cli_root/zpool_status/cleanup \
+    mode=0555
+file path=opt/zfs-tests/tests/functional/cli_root/zpool_status/setup mode=0555
+file \
+    path=opt/zfs-tests/tests/functional/cli_root/zpool_status/zpool_status_001_pos \
+    mode=0555
+file \
+    path=opt/zfs-tests/tests/functional/cli_root/zpool_status/zpool_status_002_pos \
+    mode=0555
+file \
+    path=opt/zfs-tests/tests/functional/cli_root/zpool_upgrade/blockfiles/zfs-broken-mirror1.dat.bz2 \
+    mode=0444
+file \
+    path=opt/zfs-tests/tests/functional/cli_root/zpool_upgrade/blockfiles/zfs-broken-mirror2.dat.bz2 \
+    mode=0444
+file \
+    path=opt/zfs-tests/tests/functional/cli_root/zpool_upgrade/blockfiles/zfs-pool-v1.dat.bz2 \
+    mode=0444
+file \
+    path=opt/zfs-tests/tests/functional/cli_root/zpool_upgrade/blockfiles/zfs-pool-v10.dat.bz2 \
+    mode=0444
+file \
+    path=opt/zfs-tests/tests/functional/cli_root/zpool_upgrade/blockfiles/zfs-pool-v11.dat.bz2 \
+    mode=0444
+file \
+    path=opt/zfs-tests/tests/functional/cli_root/zpool_upgrade/blockfiles/zfs-pool-v12.dat.bz2 \
+    mode=0444
+file \
+    path=opt/zfs-tests/tests/functional/cli_root/zpool_upgrade/blockfiles/zfs-pool-v13.dat.bz2 \
+    mode=0444
+file \
+    path=opt/zfs-tests/tests/functional/cli_root/zpool_upgrade/blockfiles/zfs-pool-v14.dat.bz2 \
+    mode=0444
+file \
+    path=opt/zfs-tests/tests/functional/cli_root/zpool_upgrade/blockfiles/zfs-pool-v15.dat.bz2 \
+    mode=0444
+file \
+    path=opt/zfs-tests/tests/functional/cli_root/zpool_upgrade/blockfiles/zfs-pool-v1mirror1.dat.bz2 \
+    mode=0444
+file \
+    path=opt/zfs-tests/tests/functional/cli_root/zpool_upgrade/blockfiles/zfs-pool-v1mirror2.dat.bz2 \
+    mode=0444
+file \
+    path=opt/zfs-tests/tests/functional/cli_root/zpool_upgrade/blockfiles/zfs-pool-v1mirror3.dat.bz2 \
+    mode=0444
+file \
+    path=opt/zfs-tests/tests/functional/cli_root/zpool_upgrade/blockfiles/zfs-pool-v1raidz1.dat.bz2 \
+    mode=0444
+file \
+    path=opt/zfs-tests/tests/functional/cli_root/zpool_upgrade/blockfiles/zfs-pool-v1raidz2.dat.bz2 \
+    mode=0444
+file \
+    path=opt/zfs-tests/tests/functional/cli_root/zpool_upgrade/blockfiles/zfs-pool-v1raidz3.dat.bz2 \
+    mode=0444
+file \
+    path=opt/zfs-tests/tests/functional/cli_root/zpool_upgrade/blockfiles/zfs-pool-v1stripe1.dat.bz2 \
+    mode=0444
+file \
+    path=opt/zfs-tests/tests/functional/cli_root/zpool_upgrade/blockfiles/zfs-pool-v1stripe2.dat.bz2 \
+    mode=0444
+file \
+    path=opt/zfs-tests/tests/functional/cli_root/zpool_upgrade/blockfiles/zfs-pool-v1stripe3.dat.bz2 \
+    mode=0444
+file \
+    path=opt/zfs-tests/tests/functional/cli_root/zpool_upgrade/blockfiles/zfs-pool-v2.dat.bz2 \
+    mode=0444
+file \
+    path=opt/zfs-tests/tests/functional/cli_root/zpool_upgrade/blockfiles/zfs-pool-v2mirror1.dat.bz2 \
+    mode=0444
+file \
+    path=opt/zfs-tests/tests/functional/cli_root/zpool_upgrade/blockfiles/zfs-pool-v2mirror2.dat.bz2 \
+    mode=0444
+file \
+    path=opt/zfs-tests/tests/functional/cli_root/zpool_upgrade/blockfiles/zfs-pool-v2mirror3.dat.bz2 \
+    mode=0444
+file \
+    path=opt/zfs-tests/tests/functional/cli_root/zpool_upgrade/blockfiles/zfs-pool-v2raidz1.dat.bz2 \
+    mode=0444
+file \
+    path=opt/zfs-tests/tests/functional/cli_root/zpool_upgrade/blockfiles/zfs-pool-v2raidz2.dat.bz2 \
+    mode=0444
+file \
+    path=opt/zfs-tests/tests/functional/cli_root/zpool_upgrade/blockfiles/zfs-pool-v2raidz3.dat.bz2 \
+    mode=0444
+file \
+    path=opt/zfs-tests/tests/functional/cli_root/zpool_upgrade/blockfiles/zfs-pool-v2stripe1.dat.bz2 \
+    mode=0444
+file \
+    path=opt/zfs-tests/tests/functional/cli_root/zpool_upgrade/blockfiles/zfs-pool-v2stripe2.dat.bz2 \
+    mode=0444
+file \
+    path=opt/zfs-tests/tests/functional/cli_root/zpool_upgrade/blockfiles/zfs-pool-v2stripe3.dat.bz2 \
+    mode=0444
+file \
+    path=opt/zfs-tests/tests/functional/cli_root/zpool_upgrade/blockfiles/zfs-pool-v3.dat.bz2 \
+    mode=0444
+file \
+    path=opt/zfs-tests/tests/functional/cli_root/zpool_upgrade/blockfiles/zfs-pool-v3hotspare1.dat.bz2 \
+    mode=0444
+file \
+    path=opt/zfs-tests/tests/functional/cli_root/zpool_upgrade/blockfiles/zfs-pool-v3hotspare2.dat.bz2 \
+    mode=0444
+file \
+    path=opt/zfs-tests/tests/functional/cli_root/zpool_upgrade/blockfiles/zfs-pool-v3hotspare3.dat.bz2 \
+    mode=0444
+file \
+    path=opt/zfs-tests/tests/functional/cli_root/zpool_upgrade/blockfiles/zfs-pool-v3mirror1.dat.bz2 \
+    mode=0444
+file \
+    path=opt/zfs-tests/tests/functional/cli_root/zpool_upgrade/blockfiles/zfs-pool-v3mirror2.dat.bz2 \
+    mode=0444
+file \
+    path=opt/zfs-tests/tests/functional/cli_root/zpool_upgrade/blockfiles/zfs-pool-v3mirror3.dat.bz2 \
+    mode=0444
+file \
+    path=opt/zfs-tests/tests/functional/cli_root/zpool_upgrade/blockfiles/zfs-pool-v3raidz1.dat.bz2 \
+    mode=0444
+file \
+    path=opt/zfs-tests/tests/functional/cli_root/zpool_upgrade/blockfiles/zfs-pool-v3raidz2.dat.bz2 \
+    mode=0444
+file \
+    path=opt/zfs-tests/tests/functional/cli_root/zpool_upgrade/blockfiles/zfs-pool-v3raidz21.dat.bz2 \
+    mode=0444
+file \
+    path=opt/zfs-tests/tests/functional/cli_root/zpool_upgrade/blockfiles/zfs-pool-v3raidz22.dat.bz2 \
+    mode=0444
+file \
+    path=opt/zfs-tests/tests/functional/cli_root/zpool_upgrade/blockfiles/zfs-pool-v3raidz23.dat.bz2 \
+    mode=0444
+file \
+    path=opt/zfs-tests/tests/functional/cli_root/zpool_upgrade/blockfiles/zfs-pool-v3raidz3.dat.bz2 \
+    mode=0444
+file \
+    path=opt/zfs-tests/tests/functional/cli_root/zpool_upgrade/blockfiles/zfs-pool-v3stripe1.dat.bz2 \
+    mode=0444
+file \
+    path=opt/zfs-tests/tests/functional/cli_root/zpool_upgrade/blockfiles/zfs-pool-v3stripe2.dat.bz2 \
+    mode=0444
+file \
+    path=opt/zfs-tests/tests/functional/cli_root/zpool_upgrade/blockfiles/zfs-pool-v3stripe3.dat.bz2 \
+    mode=0444
+file \
+    path=opt/zfs-tests/tests/functional/cli_root/zpool_upgrade/blockfiles/zfs-pool-v4.dat.bz2 \
+    mode=0444
+file \
+    path=opt/zfs-tests/tests/functional/cli_root/zpool_upgrade/blockfiles/zfs-pool-v5.dat.bz2 \
+    mode=0444
+file \
+    path=opt/zfs-tests/tests/functional/cli_root/zpool_upgrade/blockfiles/zfs-pool-v6.dat.bz2 \
+    mode=0444
+file \
+    path=opt/zfs-tests/tests/functional/cli_root/zpool_upgrade/blockfiles/zfs-pool-v7.dat.bz2 \
+    mode=0444
+file \
+    path=opt/zfs-tests/tests/functional/cli_root/zpool_upgrade/blockfiles/zfs-pool-v8.dat.bz2 \
+    mode=0444
+file \
+    path=opt/zfs-tests/tests/functional/cli_root/zpool_upgrade/blockfiles/zfs-pool-v9.dat.bz2 \
+    mode=0444
+file \
+    path=opt/zfs-tests/tests/functional/cli_root/zpool_upgrade/blockfiles/zfs-pool-v999.dat.bz2 \
+    mode=0444
+file \
+    path=opt/zfs-tests/tests/functional/cli_root/zpool_upgrade/blockfiles/zfs-pool-vBROKEN.dat.bz2 \
+    mode=0444
+file path=opt/zfs-tests/tests/functional/cli_root/zpool_upgrade/cleanup \
+    mode=0555
+file path=opt/zfs-tests/tests/functional/cli_root/zpool_upgrade/setup \
+    mode=0555
+file \
+    path=opt/zfs-tests/tests/functional/cli_root/zpool_upgrade/zpool_upgrade.cfg \
+    mode=0555
+file \
+    path=opt/zfs-tests/tests/functional/cli_root/zpool_upgrade/zpool_upgrade.kshlib \
+    mode=0555
+file \
+    path=opt/zfs-tests/tests/functional/cli_root/zpool_upgrade/zpool_upgrade_001_pos \
+    mode=0555
+file \
+    path=opt/zfs-tests/tests/functional/cli_root/zpool_upgrade/zpool_upgrade_002_pos \
+    mode=0555
+file \
+    path=opt/zfs-tests/tests/functional/cli_root/zpool_upgrade/zpool_upgrade_003_pos \
+    mode=0555
+file \
+    path=opt/zfs-tests/tests/functional/cli_root/zpool_upgrade/zpool_upgrade_004_pos \
+    mode=0555
+file \
+    path=opt/zfs-tests/tests/functional/cli_root/zpool_upgrade/zpool_upgrade_005_neg \
+    mode=0555
+file \
+    path=opt/zfs-tests/tests/functional/cli_root/zpool_upgrade/zpool_upgrade_006_neg \
+    mode=0555
+file \
+    path=opt/zfs-tests/tests/functional/cli_root/zpool_upgrade/zpool_upgrade_007_pos \
+    mode=0555
+file \
+    path=opt/zfs-tests/tests/functional/cli_root/zpool_upgrade/zpool_upgrade_008_pos \
+    mode=0555
+file \
+    path=opt/zfs-tests/tests/functional/cli_root/zpool_upgrade/zpool_upgrade_009_neg \
+    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
+file path=opt/zfs-tests/tests/functional/nopwrite/nopwrite_mtime mode=0555
+file path=opt/zfs-tests/tests/functional/nopwrite/nopwrite_negative mode=0555
+file path=opt/zfs-tests/tests/functional/nopwrite/nopwrite_promoted_clone \
+    mode=0555
+file path=opt/zfs-tests/tests/functional/nopwrite/nopwrite_recsize mode=0555
+file path=opt/zfs-tests/tests/functional/nopwrite/nopwrite_sync mode=0555
+file path=opt/zfs-tests/tests/functional/nopwrite/nopwrite_varying_compression \
+    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/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
+license cr_Sun license=cr_Sun
+license lic_CDDL license=lic_CDDL
+depend fmri=system/file-system/zfs/tests type=require
+depend fmri=system/test/testrunner type=require
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/usr/src/test/Makefile	Wed Dec 05 22:04:50 2012 -0500
@@ -0,0 +1,20 @@
+#
+# 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) 2012 by Delphix. All rights reserved.
+#
+
+.PARALLEL: $(SUBDIRS)
+
+SUBDIRS = os-tests test-runner zfs-tests
+
+include Makefile.com
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/usr/src/test/Makefile.com	Wed Dec 05 22:04:50 2012 -0500
@@ -0,0 +1,35 @@
+#
+# 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) 2012 by Delphix. All rights reserved.
+#
+
+all     :=      TARGET = all
+install :=      TARGET = install
+clean   :=      TARGET = clean
+clobber :=      TARGET = clobber
+lint    :=      TARGET = lint
+
+.KEEP_STATE:
+
+all clean clobber install lint: $(SUBDIRS)
+
+lint_PROG:
+	$(LINT.c) $(PROG).c $(LDLIBS)
+
+lint_SRCS:
+	$(LINT.c) $(SRCS) $(LDLIBS)
+
+$(SUBDIRS): FRC
+	@cd $@; pwd; $(MAKE) $(TARGET)
+
+FRC:
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/usr/src/test/os-tests/Makefile	Wed Dec 05 22:04:50 2012 -0500
@@ -0,0 +1,20 @@
+#
+# 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) 2012 by Delphix. All rights reserved.
+#
+
+.PARALLEL: $(SUBDIRS)
+
+SUBDIRS = cmd runfiles tests doc
+
+include $(SRC)/test/Makefile.com
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/usr/src/test/os-tests/cmd/Makefile	Wed Dec 05 22:04:50 2012 -0500
@@ -0,0 +1,37 @@
+#
+# 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) 2012 by Delphix. All rights reserved.
+#
+
+include $(SRC)/Makefile.master
+include $(SRC)/test/Makefile.com
+
+ROOTOPTPKG = $(ROOT)/opt/os-tests
+ROOTBIN = $(ROOTOPTPKG)/bin
+
+PROGS = ostest
+
+CMDS = $(PROGS:%=$(ROOTBIN)/%)
+$(CMDS) := FILEMODE = 0555
+
+all lint clean clobber:
+
+install: $(CMDS)
+
+$(CMDS): $(ROOTBIN)
+
+$(ROOTBIN):
+	$(INS.dir)
+
+$(ROOTBIN)/%: %.ksh
+	$(INS.rename)
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/usr/src/test/os-tests/cmd/ostest.ksh	Wed Dec 05 22:04:50 2012 -0500
@@ -0,0 +1,54 @@
+#!/usr/bin/ksh
+
+#
+# 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) 2012 by Delphix. All rights reserved.
+#
+
+export OS_TESTS="/opt/os-tests"
+runner="/opt/test-runner/bin/run"
+
+function fail
+{
+	echo $1
+	exit ${2:-1}
+}
+
+function find_runfile
+{
+	typeset distro=
+	if [[ -d /opt/delphix && -h /etc/delphix/version ]]; then
+		distro=delphix
+	elif [[ 0 -ne $(grep -c OpenIndiana /etc/release 2>/dev/null) ]]; then
+		distro=openindiana
+	fi
+
+	[[ -n $distro ]] && echo $OS_TESTS/runfiles/$distro.run
+}
+
+while getopts c: c; do
+	case $c in
+	'c')
+		runfile=$OPTARG
+		[[ -f $runfile ]] || fail "Cannot read file: $runfile"
+		;;
+	esac
+done
+shift $((OPTIND - 1))
+
+[[ -z $runfile ]] && runfile=$(find_runfile)
+[[ -z $runfile ]] && fail "Couldn't determine distro"
+
+$runner -c $runfile
+
+exit $?
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/usr/src/test/os-tests/doc/Makefile	Wed Dec 05 22:04:50 2012 -0500
@@ -0,0 +1,35 @@
+#
+# 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) 2012 by Delphix. All rights reserved.
+#
+
+include $(SRC)/Makefile.master
+
+READMES = README
+
+ROOTOPTPKG = $(ROOT)/opt/os-tests
+
+FILES = $(READMES:%=$(ROOTOPTPKG)/%)
+$(FILES) := FILEMODE = 0444
+
+all: $(READMES)
+
+install: $(ROOTOPTPKG) $(FILES)
+
+clean lint clobber:
+
+$(ROOTOPTPKG):
+	$(INS.dir)
+
+$(ROOTOPTPKG)/%: %
+	$(INS.file)
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/usr/src/test/os-tests/doc/README	Wed Dec 05 22:04:50 2012 -0500
@@ -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) 2012 by Delphix. All rights reserved.
+#
+
+OS Unit Test Suite README
+
+1. Building and installing the OS Unit Test Suite
+2. Running the OS Unit Test Suite
+3. Test results
+
+--------------------------------------------------------------------------------
+
+1. Building and installing the OS Unit Test Suite
+
+The OS Unit Test Suite runs under the testrunner framework (which can be
+installed as pkg:/system/test/testrunner). To build both the OS Unit Test Suite
+and the testrunner without running a full nightly:
+
+	build_machine$ bldenv [-d] <your_env_file>
+	build_machine$ cd $SRC/test
+	build_machine$ dmake install
+	build_machine$ cd $SRC/pkg
+	build_machine$ dmake install
+
+Then set the publisher on the test machine to point to your repository and
+install the OS Unit Test Suite.
+
+	test_machine# pkg install pkg:/system/test/zfstest
+
+Note, the framework will be installed automatically, as the OS Unit Test Suite
+depends on it.
+
+2. Running the OS Unit Test Suite
+
+The pre-requisites for running the OS Unit Test Suite are:
+	- A non-root user with the ability to sudo(1M) to root without a
+	  password or the root user must run the test.
+
+Once the pre-requisites are satisfied, simply run the ostest script:
+
+	test_machine$ /opt/os-tests/bin/ostest
+
+3. Test results
+
+While the OS Unit Test Suite is running, one informational line is printed at
+the end of each test, and a results summary is printed at the end of the run.
+The results summary includes the location of the complete logs, which is of the
+form /var/tmp/test_results/<ISO 8601 date>.
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/usr/src/test/os-tests/runfiles/Makefile	Wed Dec 05 22:04:50 2012 -0500
@@ -0,0 +1,39 @@
+#
+# 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) 2012 by Delphix. All rights reserved.
+#
+
+include $(SRC)/Makefile.master
+
+SRCS = delphix.run \
+	openindiana.run
+
+ROOTOPTPKG = $(ROOT)/opt/os-tests
+RUNFILES = $(ROOTOPTPKG)/runfiles
+
+CMDS = $(SRCS:%=$(RUNFILES)/%)
+$(CMDS) := FILEMODE = 0444
+
+all: $(SRCS)
+
+install: $(CMDS)
+
+clean lint clobber:
+
+$(CMDS): $(RUNFILES) $(SRCS)
+
+$(RUNFILES):
+	$(INS.dir)
+
+$(RUNFILES)/%: %
+	$(INS.file)
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/usr/src/test/os-tests/runfiles/delphix.run	Wed Dec 05 22:04:50 2012 -0500
@@ -0,0 +1,26 @@
+#
+# 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) 2012 by Delphix. All rights reserved.
+#
+
+[DEFAULT]
+pre =
+verbose = False
+quiet = False
+user = root
+timeout = 60
+post =
+outputdir = /var/tmp/test_results
+
+[/opt/os-tests/tests/poll_test]
+
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/usr/src/test/os-tests/runfiles/openindiana.run	Wed Dec 05 22:04:50 2012 -0500
@@ -0,0 +1,26 @@
+#
+# 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) 2012 by Delphix. All rights reserved.
+#
+
+[DEFAULT]
+pre =
+verbose = False
+quiet = False
+user = root
+timeout = 60
+post =
+outputdir = /var/tmp/test_results
+
+[/opt/os-tests/tests/poll_test]
+
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/usr/src/test/os-tests/tests/Makefile	Wed Dec 05 22:04:50 2012 -0500
@@ -0,0 +1,18 @@
+#
+# 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) 2012 by Delphix. All rights reserved.
+#
+
+SUBDIRS = poll
+
+include $(SRC)/test/Makefile.com
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/usr/src/test/os-tests/tests/poll/Makefile	Wed Dec 05 22:04:50 2012 -0500
@@ -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) 2012 by Delphix. All rights reserved.
+#
+
+include $(SRC)/cmd/Makefile.cmd
+include $(SRC)/test/Makefile.com
+
+PROG = poll_test
+OBJS = $(PROG:%=%.o)
+SRCS = $(OBJS:%.o=%.c)
+
+LDLIBS += -lsocket
+C99MODE = -xc99=%all
+
+ROOTOPTPKG = $(ROOT)/opt/os-tests
+TESTDIR = $(ROOTOPTPKG)/tests
+
+CMDS = $(PROG:%=$(TESTDIR)/%)
+$(CMDS) := FILEMODE = 0555
+
+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)
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/usr/src/test/os-tests/tests/poll/poll_test.c	Wed Dec 05 22:04:50 2012 -0500
@@ -0,0 +1,559 @@
+/*
+ * 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) 2012 by Delphix. All rights reserved.
+ */
+
+#include <stdlib.h>
+#include <stdio.h>
+#include <stdarg.h>
+#include <string.h>
+#include <fcntl.h>
+#include <pthread.h>
+#include <assert.h>
+#include <errno.h>
+#include <ctype.h>
+#include <unistd.h>
+#include <poll.h>
+#include <sys/types.h>
+#include <sys/wait.h>
+#include <sys/stat.h>
+#include <sys/socket.h>
+#include <sys/devpoll.h>
+
+/*
+ * poll_test.c --
+ *
+ *      This file implements some simple tests to verify the behavior of the
+ *      poll system call and the DP_POLL ioctl on /dev/poll.
+ *
+ * Background:
+ *
+ *      Several customers recently ran into an issue where threads in grizzly
+ *      (java http server implementation) would randomly wake up from a java
+ *      call to select against a java.nio.channels.Selector with no events ready
+ *      but well before the specified timeout expired. The
+ *      java.nio.channels.Selector select logic is implemented via /dev/poll.
+ *      The selector opens /dev/poll, writes the file descriptors it wants to
+ *      select on to the file descritpor, and then issues a DP_POLL ioctl to
+ *      wait for events to be ready.
+ *
+ *      The DP_POLL ioctl arguments include a relative timeout in milliseconds,
+ *      according to man poll.7d the ioctl should block until events are ready,
+ *      the timeout expires, or a signal was received. In this case we noticed
+ *      that DP_POLL was returning before the timeout expired despite no events
+ *      being ready and no signal being delivered.
+ *
+ *      Using dtrace we discovered that DP_POLL was returning in cases where the
+ *      system time was changed and the thread calling DP_POLL was woken up as
+ *      a result of the process forking. The DP_POLL logic was in a loop
+ *      checking if events were ready and then calling cv_waituntil_sig to
+ *      block. cv_waituntil_sig will return -1 if the system time has changed,
+ *      causing the DP_POLL to complete prematurely.
+ *
+ *      Looking at the code it turns out the same problem exists in
+ *      the implementation for poll.2 as well.
+ *
+ * Fix:
+ *
+ *      The fix changes dpioctl and poll_common to use cv_relwaituntil_sig
+ *      rather then cv_waituntil_sig. cv_reltimedwait_sig expects a
+ *      relative timeout rather then an absolute timeout, so we avoid the
+ *      problem.
+ *
+ * Test:
+ *
+ *      The test verifies that changing the date does not wake up threads
+ *      blocked processing a poll request or a DP_POLL ioctl. The test spawns
+ *      one thread that changes the date and forks (to force the threads to
+ *      wakeup from cv_reltimedwait_sig) every two seconds. The test spawns
+ *      a second thread that issues poll / DP_POLL on an fd set that will
+ *      never have events ready and verifies that it does not return until
+ *      the specified timeout expires.
+ */
+
+/*
+ * The maximum amount of skew in seconds allowed between the
+ * expected an actual time that a test takes.
+ */
+#define	TIME_DRIFT	1
+
+static pthread_mutex_t	exitLock = PTHREAD_MUTEX_INITIALIZER;
+static pthread_cond_t	exitCond = PTHREAD_COND_INITIALIZER;
+static int		terminated = 0;
+
+/*
+ * Set via -d to enable debug logging
+ */
+static int debug = 0;
+
+static void
+debug_log(const char *format, ...)
+{
+	va_list	args;
+
+	if (!debug) {
+		return;
+	}
+
+	(void) printf("DEBUG: ");
+
+	va_start(args, format);
+	(void) vprintf(format, args);
+	va_end(args);
+}
+
+static void
+test_start(const char *testName, const char *format, ...)
+{
+	va_list	args;
+
+	(void) printf("TEST STARTING %s: ", testName);
+
+	va_start(args, format);
+	(void) vprintf(format, args);
+	va_end(args);
+	(void) fflush(stdout);
+}
+
+static void
+test_failed(const char *testName, const char *format, ...)
+{
+	va_list	args;
+
+	(void) printf("TEST FAILED %s: ", testName);
+
+	va_start(args, format);
+	(void) vprintf(format, args);
+	va_end(args);
+
+	(void) exit(-1);
+}
+
+static void
+test_passed(const char *testName)
+{
+	(void) printf("TEST PASS: %s\n", testName);
+	(void) fflush(stdout);
+}
+
+static int
+check_time(time_t elapsed, time_t expected)
+{
+	time_t	diff = expected - elapsed;
+
+	/*
+	 * We may take slightly more or less time then expected,
+	 * we allow for a small fudge factor if things completed
+	 * before we expect them to.
+	 */
+	return (elapsed >= expected || diff <= TIME_DRIFT);
+}
+
+static int
+poll_wrapper(pollfd_t *fds, nfds_t nfds, int timeout, time_t *elapsed)
+{
+	int		ret;
+	time_t		start = time(NULL);
+
+	debug_log("POLL start: (0x%p, %d, %d)\n", fds, nfds, timeout);
+
+	ret = poll(fds, nfds, timeout);
+
+	*elapsed = time(NULL) - start;
+
+	debug_log("POLL end: (0x%p, %d, %d) returns %d (elapse=%d)\n",
+	    fds, nfds, timeout, ret, (*elapsed));
+
+	return (ret);
+}
+
+static int
+dppoll(int pollfd, pollfd_t *fds, nfds_t nfds, int timeout, time_t *elapsed)
+{
+	struct dvpoll	arg;
+	int		ret;
+	time_t		start = time(NULL);
+
+	arg.dp_fds = fds;
+	arg.dp_nfds = nfds;
+	arg.dp_timeout = timeout;
+
+	debug_log("DP_POLL start: (0x%p, %d, %d)\n", fds, nfds, timeout);
+
+	ret = ioctl(pollfd, DP_POLL, &arg);
+
+	*elapsed = time(NULL) - start;
+
+	debug_log("DP_POLL end: (0x%p, %d, %d) returns %d (elapse=%d)\n",
+	    fds, arg.dp_nfds, arg.dp_timeout, ret, (*elapsed));
+
+	return (ret);
+}
+
+static void
+clear_fd(const char *testName, int pollfd, int testfd)
+{
+	int		ret;
+	pollfd_t	fd;
+
+	fd.fd = testfd;
+	fd.events = POLLREMOVE;
+	fd.revents = 0;
+
+	ret = write(pollfd, &fd, sizeof (pollfd_t));
+
+	if (ret != sizeof (pollfd_t)) {
+		if (ret < 0) {
+			test_failed(testName, "Failed to clear fd %d: %s",
+			    testfd, strerror(ret));
+		}
+
+
+		test_failed(testName, "Failed to clear fd %d: %d", testfd, ret);
+	}
+}
+
+/*
+ * TEST: poll with no FDs set, verify we wait the appropriate amount of time.
+ */
+static void
+poll_no_fd_test(void)
+{
+	const char	*testName = __func__;
+	time_t		elapsed;
+	int		timeout = 10;
+	int		ret;
+
+	test_start(testName, "poll for %d sec with no fds\n", timeout);
+
+	ret = poll_wrapper(NULL, 0, timeout * 1000, &elapsed);
+
+	if (ret != 0) {
+		test_failed(testName, "POLL returns %d (expected 0)\n", ret);
+	}
+
+	if (!check_time(elapsed, timeout)) {
+		test_failed(testName, "took %d (expected %d)\n",
+		    elapsed, timeout);
+	}
+
+	test_passed(testName);
+}
+
+/*
+ * TEST: POLL with a valid FD set, verify that we wait the appropriate amount
+ * of time.
+ */
+static void
+poll_with_fds_test(int testfd)
+{
+	const char	*testName = __func__;
+	time_t		elapsed;
+	int		timeout = 10;
+	int		ret;
+	pollfd_t	fd;
+
+	fd.fd = testfd;
+	fd.events = 0;
+	fd.revents = 0;
+
+	test_start(testName, "poll for %d sec with fds\n", timeout);
+
+	ret = poll_wrapper(&fd, 1, timeout * 1000, &elapsed);
+
+	if (ret != 0) {
+		test_failed(testName, "POLL returns %d (expected 0)\n", ret);
+	}
+
+	if (!check_time(elapsed, timeout)) {
+		test_failed(testName, "took %d (expected %d)\n",
+		    elapsed, timeout);
+	}
+
+	test_passed(testName);
+}
+
+/*
+ * TEST: DP_POLL with no FDs set, verify we wait the appropriate
+ * amount of time.
+ */
+static void
+dev_poll_no_fd_test(int pollfd)
+{
+	const char	*testName = __func__;
+	time_t		elapsed;
+	int		timeout = 10;
+	int		ret;
+
+	test_start(testName, "poll for %d sec with no fds\n", timeout);
+
+	ret = dppoll(pollfd, NULL, 0, timeout * 1000, &elapsed);
+
+	if (ret != 0) {
+		test_failed(testName, "DP_POLL returns %d (expected 0)\n", ret);
+	}
+
+	if (!check_time(elapsed, timeout)) {
+		test_failed(testName, "took %d (expected %d)\n",
+		    elapsed, timeout);
+	}
+
+	test_passed(testName);
+}
+
+/*
+ * TEST: DP_POLL with a valid FD set, verify that we wait
+ * the appropriate amount of time.
+ */
+static void
+dev_poll_with_fds_test(int pollfd, int testfd)
+{
+	const char	*testName = __func__;
+	time_t		elapsed;
+	int		timeout = 10;
+	int		ret;
+	pollfd_t	fds[5];
+
+	test_start(testName, "poll for %d sec with fds\n", timeout);
+
+	/*
+	 * Clear the FD in case it's already in the cached set
+	 */
+	clear_fd(testName, pollfd, testfd);
+
+	/*
+	 * Add the FD with POLLIN
+	 */
+	fds[0].fd = testfd;
+	fds[0].events = POLLIN;
+	fds[0].revents = 0;
+
+	ret = write(pollfd, fds, sizeof (pollfd_t));
+
+	if (ret != sizeof (pollfd_t)) {
+		if (ret < 0) {
+			test_failed(testName, "Failed to set fds: %s",
+			    strerror(ret));
+		}
+
+		test_failed(testName, "Failed to set fds: %d", ret);
+	}
+
+	ret = dppoll(pollfd, fds, 5, timeout * 1000, &elapsed);
+
+	if (ret != 0) {
+		test_failed(testName, "DP_POLL returns %d (expected 0)\n", ret);
+	}
+
+	if (!check_time(elapsed, timeout)) {
+		test_failed(testName, "took %d (expected %d)\n",
+		    elapsed, timeout);
+	}
+
+	clear_fd(testName, pollfd, testfd);
+
+	test_passed(testName);
+}
+
+/* ARGSUSED */
+static void *
+poll_thread(void *data)
+{
+	int	pollfd;
+	int	testfd;
+
+	pollfd = open("/dev/poll", O_RDWR);
+
+	if (pollfd <  0) {
+		perror("Failed to open /dev/poll: ");
+		exit(-1);
+	}
+
+	/*
+	 * Create a dummy FD that will never have POLLIN set
+	 */
+	testfd = socket(PF_INET, SOCK_STREAM, 0);
+
+	poll_no_fd_test();
+	poll_with_fds_test(testfd);
+
+	dev_poll_no_fd_test(pollfd);
+	dev_poll_with_fds_test(pollfd, testfd);
+
+	(void) close(testfd);
+	(void) close(pollfd);
+
+	pthread_exit(0);
+	return (NULL);
+}
+
+/*
+ * This function causes any threads blocked in cv_timedwait_sig_hires
+ * to wakeup, which allows us to test how dpioctl handles spurious
+ * wakeups.
+ */
+static void
+trigger_wakeup(void)
+{
+	pid_t   child;
+
+	/*
+	 * Forking will force all of the threads to be woken up so
+	 * they can be moved to a well known state.
+	 */
+	child = vfork();
+
+	if (child == -1) {
+		perror("Fork failed: ");
+		exit(-1);
+	} else if (child == 0) {
+		_exit(0);
+	} else {
+		pid_t   result = -1;
+		int	status;
+
+		do {
+			result = waitpid(child, &status, 0);
+
+			if (result == -1 && errno != EINTR) {
+				(void) printf("Waitpid for %ld failed: %s\n",
+				    child, strerror(errno));
+				exit(-1);
+			}
+		} while (result != child);
+
+		if (status != 0) {
+			(void) printf("Child pid %ld failed: %d\n",
+			    child, status);
+			exit(-1);
+		}
+	}
+}
+
+/*
+ * This function changes the system time, which has the side
+ * effect of updating timechanged in the kernel.
+ */
+static void
+change_date(void)
+{
+	int	ret;
+	struct timeval  tp;
+
+	ret = gettimeofday(&tp, NULL);
+	assert(ret == 0);
+
+	tp.tv_usec++;
+	ret = settimeofday(&tp, NULL);
+	assert(ret == 0);
+}
+
+/*
+ * The helper thread runs in a loop changing the time and
+ * forcing wakeups every 2 seconds.
+ */
+/* ARGSUSED */
+static void *
+helper_thread(void *data)
+{
+	int	exit;
+	struct	timespec ts = {2, 0};
+
+	debug_log("Helper thread started ...\n");
+
+	/* CONSTCOND */
+	while (1) {
+		(void) pthread_mutex_lock(&exitLock);
+		(void) pthread_cond_reltimedwait_np(&exitCond, &exitLock, &ts);
+		exit = terminated;
+		(void) pthread_mutex_unlock(&exitLock);
+
+		if (exit) {
+			break;
+		}
+
+		change_date();
+		trigger_wakeup();
+		debug_log("Time changed and force wakeup issued\n");
+	}
+
+	debug_log("Helper thread exiting ...\n");
+
+	pthread_exit(0);
+	return (NULL);
+}
+
+static void
+stop_threads(void)
+{
+	(void) pthread_mutex_lock(&exitLock);
+	terminated = 1;
+	(void) pthread_cond_broadcast(&exitCond);
+	(void) pthread_mutex_unlock(&exitLock);
+}
+
+static void
+run_tests(void)
+{
+	pthread_t	pollThread;
+	pthread_t	helperThread;
+	int		ret;
+
+	ret = pthread_create(&helperThread, NULL, helper_thread, NULL);
+
+	if (ret != 0) {
+		(void) printf("Failed to create date thread: %s",
+		    strerror(ret));
+		exit(-1);
+	}
+
+	ret = pthread_create(&pollThread, NULL, poll_thread, NULL);
+
+	if (ret != 0) {
+		(void) printf("Failed to create poll thread: %s",
+		    strerror(ret));
+		exit(-1);
+	}
+
+	(void) pthread_join(pollThread, NULL);
+	stop_threads();
+	(void) pthread_join(helperThread, NULL);
+}
+
+int
+main(int argc, char * const argv[])
+{
+	int	c;
+
+	while ((c = getopt(argc, argv, "d")) != -1) {
+		switch (c) {
+		case 'd':
+			debug = 1;
+			break;
+		default:
+			break;
+		}
+	}
+
+	/*
+	 * We need to be root to change the system time
+	 */
+	if (getuid() != 0 && geteuid() != 0) {
+		(void) printf("%s must be run as root\n", argv[0]);
+		exit(-1);
+	}
+
+	run_tests();
+
+	exit(0);
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/usr/src/test/test-runner/Makefile	Wed Dec 05 22:04:50 2012 -0500
@@ -0,0 +1,20 @@
+#
+# 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) 2012 by Delphix. All rights reserved.
+#
+
+.PARALLEL: $(SUBDIRS)
+
+SUBDIRS = cmd stf man
+
+include $(SRC)/test/Makefile.com
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/usr/src/test/test-runner/cmd/Makefile	Wed Dec 05 22:04:50 2012 -0500
@@ -0,0 +1,37 @@
+#
+# 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) 2012 by Delphix. All rights reserved.
+#
+
+include $(SRC)/Makefile.master
+include $(SRC)/test/Makefile.com
+
+ROOTOPTPKG = $(ROOT)/opt/test-runner
+ROOTBIN = $(ROOTOPTPKG)/bin
+
+PROGS = run
+
+CMDS = $(PROGS:%=$(ROOTBIN)/%)
+$(CMDS) := FILEMODE = 0555
+
+all lint clean clobber:
+
+install: $(CMDS)
+
+$(CMDS): $(ROOTBIN)
+
+$(ROOTBIN):
+	$(INS.dir)
+
+$(ROOTBIN)/%: %.py
+	$(INS.rename)
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/usr/src/test/test-runner/cmd/run.py	Wed Dec 05 22:04:50 2012 -0500
@@ -0,0 +1,839 @@
+#!/usr/bin/python2.6
+
+#
+# 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) 2012 by Delphix. All rights reserved.
+#
+
+import ConfigParser
+import os
+import logging
+from datetime import datetime
+from optparse import OptionParser
+from pwd import getpwnam
+from pwd import getpwuid
+from select import select
+from subprocess import PIPE
+from subprocess import Popen
+from sys import argv
+from sys import exit
+from threading import Timer
+from time import time
+
+BASEDIR = '/var/tmp/test_results'
+KILL = '/usr/bin/kill'
+TRUE = '/usr/bin/true'
+SUDO = '/usr/bin/sudo'
+
+
+class Result(object):
+    total = 0
+    runresults = {'PASS': 0, 'FAIL': 0, 'SKIP': 0, 'KILLED': 0}
+
+    def __init__(self):
+        self.starttime = None
+        self.returncode = None
+        self.runtime = ''
+        self.stdout = []
+        self.stderr = []
+        self.result = ''
+
+    def done(self, proc, killed):
+        """
+        Finalize the results of this Cmd.
+        """
+        Result.total += 1
+        m, s = divmod(time() - self.starttime, 60)
+        self.runtime = '%02d:%02d' % (m, s)
+        self.returncode = proc.returncode
+        if killed:
+            self.result = 'KILLED'
+            Result.runresults['KILLED'] += 1
+        elif self.returncode is 0:
+            self.result = 'PASS'
+            Result.runresults['PASS'] += 1
+        elif self.returncode is not 0:
+            self.result = 'FAIL'
+            Result.runresults['FAIL'] += 1
+
+
+class Output(object):
+    """
+    This class is a slightly modified version of the 'Stream' class found
+    here: http://goo.gl/aSGfv
+    """
+    def __init__(self, stream):
+        self.stream = stream
+        self._buf = ''
+        self.lines = []
+
+    def fileno(self):
+        return self.stream.fileno()
+
+    def read(self, drain=0):
+        """
+        Read from the file descriptor. If 'drain' set, read until EOF.
+        """
+        while self._read() is not None:
+            if not drain:
+                break
+
+    def _read(self):
+        """
+        Read up to 4k of data from this output stream. Collect the output
+        up to the last newline, and append it to any leftover data from a
+        previous call. The lines are stored as a (timestamp, data) tuple
+        for easy sorting/merging later.
+        """
+        fd = self.fileno()
+        buf = os.read(fd, 4096)
+        if not buf:
+            return None
+        if '\n' not in buf:
+            self._buf += buf
+            return []
+
+        buf = self._buf + buf
+        tmp, rest = buf.rsplit('\n', 1)
+        self._buf = rest
+        now = datetime.now()
+        rows = tmp.split('\n')
+        self.lines += [(now, r) for r in rows]
+
+
+class Cmd(object):
+    verified_users = []
+
+    def __init__(self, pathname, outputdir=None, timeout=None, user=None):
+        self.pathname = pathname
+        self.outputdir = outputdir or 'BASEDIR'
+        self.timeout = timeout or 60
+        self.user = user or ''
+        self.killed = False
+        self.result = Result()
+
+    def __str__(self):
+        return "Pathname: %s\nOutputdir: %s\nTimeout: %s\nUser: %s\n" % (
+                self.pathname, self.outputdir, self.timeout, self.user)
+
+    def kill_cmd(self, proc):
+        """
+        Kill a running command due to timeout, or ^C from the keyboard. If
+        sudo is required, this user was verified previously.
+        """
+        self.killed = True
+        do_sudo = len(self.user) != 0
+        signal = '-TERM'
+
+        cmd = [SUDO, KILL, signal, str(proc.pid)]
+        if not do_sudo:
+            del cmd[0]
+
+        try:
+            kp = Popen(cmd)
+            kp.wait()
+        except:
+            pass
+
+    def update_cmd_privs(self, cmd, user):
+        """
+        If a user has been specified to run this Cmd and we're not already
+        running as that user, prepend the appropriate sudo command to run
+        as that user.
+        """
+        me = getpwuid(os.getuid())
+
+        if not user or user is me:
+            return cmd
+
+        ret = '%s -E -u %s %s' % (SUDO, user, cmd)
+        return ret.split(' ')
+
+    def collect_output(self, proc):
+        """
+        Read from stdout/stderr as data becomes available, until the
+        process is no longer running. Return the lines from the stdout and
+        stderr Output objects.
+        """
+        out = Output(proc.stdout)
+        err = Output(proc.stderr)
+        res = []
+        while proc.returncode is None:
+            proc.poll()
+            res = select([out, err], [], [], .1)
+            for fd in res[0]:
+                fd.read()
+        for fd in res[0]:
+            fd.read(drain=1)
+
+        return out.lines, err.lines
+
+    def run(self, options):
+        """
+        This is the main function that runs each individual test.
+        Determine whether or not the command requires sudo, and modify it
+        if needed. Run the command, and update the result object.
+        """
+        if options.dryrun is True:
+            print self
+            return
+
+        privcmd = self.update_cmd_privs(self.pathname, self.user)
+        try:
+            old = os.umask(0)
+            if not os.path.isdir(self.outputdir):
+                os.makedirs(self.outputdir, mode=0777)
+            os.umask(old)
+        except OSError, e:
+            fail('%s' % e)
+
+        try:
+            self.result.starttime = time()
+            proc = Popen(privcmd, stdout=PIPE, stderr=PIPE)
+            t = Timer(int(self.timeout), self.kill_cmd, [proc])
+            t.start()
+            self.result.stdout, self.result.stderr = self.collect_output(proc)
+        except KeyboardInterrupt:
+            self.kill_cmd(proc)
+            fail('\nRun terminated at user request.')
+        finally:
+            t.cancel()
+
+        self.result.done(proc, self.killed)
+
+    def skip(self):
+        """
+        Initialize enough of the test result that we can log a skipped
+        command.
+        """
+        Result.total += 1
+        Result.runresults['SKIP'] += 1
+        self.result.stdout = self.result.stderr = []
+        self.result.starttime = time()
+        m, s = divmod(time() - self.result.starttime, 60)
+        self.result.runtime = '%02d:%02d' % (m, s)
+        self.result.result = 'SKIP'
+
+    def log(self, logger, options):
+        """
+        This function is responsible for writing all output. This includes
+        the console output, the logfile of all results (with timestamped
+        merged stdout and stderr), and for each test, the unmodified
+        stdout/stderr/merged in it's own file.
+        """
+        if logger is None:
+            return
+
+        user = ' (run as %s)' % self.user if len(self.user) else ''
+        msga = 'Test: %s%s ' % (self.pathname, user)
+        msgb = '[%s] [%s]' % (self.result.runtime, self.result.result)
+        pad = ' ' * (80 - (len(msga) + len(msgb)))
+
+        # If -q is specified, only print a line for tests that didn't pass.
+        # This means passing tests need to be logged as DEBUG, or the one
+        # line summary will only be printed in the logfile for failures.
+        if not options.quiet:
+            logger.info('%s%s%s' % (msga, pad, msgb))
+        elif self.result.result is not 'PASS':
+            logger.info('%s%s%s' % (msga, pad, msgb))
+        else:
+            logger.debug('%s%s%s' % (msga, pad, msgb))
+
+        lines = self.result.stdout + self.result.stderr
+        for dt, line in sorted(lines):
+            logger.debug('%s %s' % (dt.strftime("%H:%M:%S.%f ")[:11], line))
+
+        if len(self.result.stdout):
+            with open(os.path.join(self.outputdir, 'stdout'), 'w') as out:
+                for _, line in self.result.stdout:
+                    os.write(out.fileno(), '%s\n' % line)
+        if len(self.result.stderr):
+            with open(os.path.join(self.outputdir, 'stderr'), 'w') as err:
+                for _, line in self.result.stderr:
+                    os.write(err.fileno(), '%s\n' % line)
+        if len(self.result.stdout) and len(self.result.stderr):
+            with open(os.path.join(self.outputdir, 'merged'), 'w') as merged:
+                for _, line in sorted(lines):
+                    os.write(merged.fileno(), '%s\n' % line)
+
+
+class Test(Cmd):
+    props = ['outputdir', 'timeout', 'user', 'pre', 'pre_user', 'post',
+             'post_user']
+
+    def __init__(self, pathname, outputdir=None, timeout=None, user=None,
+                 pre=None, pre_user=None, post=None, post_user=None):
+        super(Test, self).__init__(pathname, outputdir, timeout, user)
+        self.pre = pre or ''
+        self.pre_user = pre_user or ''
+        self.post = post or ''
+        self.post_user = post_user or ''
+
+    def __str__(self):
+        post_user = pre_user = ''
+        if len(self.pre_user):
+            pre_user = ' (as %s)' % (self.pre_user)
+        if len(self.post_user):
+            post_user = ' (as %s)' % (self.post_user)
+        return "Pathname: %s\nOutputdir: %s\nTimeout: %s\nPre: %s%s\nPost: " \
+               "%s%s\nUser: %s\n" % (self.pathname, self.outputdir,
+                self.timeout, self.pre, pre_user, self.post, post_user,
+                self.user)
+
+    def verify(self, logger):
+        """
+        Check the pre/post scripts, user and Test. Omit the Test from this
+        run if there are any problems.
+        """
+        files = [self.pre, self.pathname, self.post]
+        users = [self.pre_user, self.user, self.post_user]
+
+        for f in [f for f in files if len(f)]:
+            if not verify_file(f):
+                logger.info("Warning: Test '%s' not added to this run because"
+                            " it failed verification." % f)
+                return False
+
+        for user in [user for user in users if len(user)]:
+            if not verify_user(user, logger):
+                logger.info("Not adding Test '%s' to this run." %
+                            self.pathname)
+                return False
+
+        return True
+
+    def run(self, logger, options):
+        """
+        Create Cmd instances for the pre/post scripts. If the pre script
+        doesn't pass, skip this Test. Run the post script regardless.
+        """
+        pretest = Cmd(self.pre, outputdir=os.path.join(self.outputdir,
+                      os.path.basename(self.pre)), timeout=self.timeout,
+                      user=self.pre_user)
+        test = Cmd(self.pathname, outputdir=self.outputdir,
+                   timeout=self.timeout, user=self.user)
+        posttest = Cmd(self.post, outputdir=os.path.join(self.outputdir,
+                       os.path.basename(self.post)), timeout=self.timeout,
+                       user=self.post_user)
+
+        cont = True
+        if len(pretest.pathname):
+            pretest.run(options)
+            cont = pretest.result.result is 'PASS'
+            pretest.log(logger, options)
+
+        if cont:
+            test.run(options)
+        else:
+            test.skip()
+
+        test.log(logger, options)
+
+        if len(posttest.pathname):
+            posttest.run(options)
+            posttest.log(logger, options)
+
+
+class TestGroup(Test):
+    props = Test.props + ['tests']
+
+    def __init__(self, pathname, outputdir=None, timeout=None, user=None,
+                 pre=None, pre_user=None, post=None, post_user=None,
+                 tests=None):
+        super(TestGroup, self).__init__(pathname, outputdir, timeout, user,
+                                        pre, pre_user, post, post_user)
+        self.tests = tests or []
+
+    def __str__(self):
+        post_user = pre_user = ''
+        if len(self.pre_user):
+            pre_user = ' (as %s)' % (self.pre_user)
+        if len(self.post_user):
+            post_user = ' (as %s)' % (self.post_user)
+        return "Pathname: %s\nOutputdir: %s\nTests: %s\nTimeout: %s\n" \
+               "Pre: %s%s\nPost: %s%s\nUser: %s\n" % (self.pathname,
+                self.outputdir, self.tests, self.timeout, self.pre, pre_user,
+                self.post, post_user, self.user)
+
+    def verify(self, logger):
+        """
+        Check the pre/post scripts, user and tests in this TestGroup. Omit
+        the TestGroup entirely, or simply delete the relevant tests in the
+        group, if that's all that's required.
+        """
+        # If the pre or post scripts are relative pathnames, convert to
+        # absolute, so they stand a chance of passing verification.
+        if len(self.pre) and not os.path.isabs(self.pre):
+            self.pre = os.path.join(self.pathname, self.pre)
+        if len(self.post) and not os.path.isabs(self.post):
+            self.post = os.path.join(self.pathname, self.post)
+
+        auxfiles = [self.pre, self.post]
+        users = [self.pre_user, self.user, self.post_user]
+
+        for f in [f for f in auxfiles if len(f)]:
+            if self.pathname != os.path.dirname(f):
+                logger.info("Warning: TestGroup '%s' not added to this run. "
+                            "Auxiliary script '%s' exists in a different "
+                            "directory." % (self.pathname, f))
+                return False
+
+            if not verify_file(f):
+                logger.info("Warning: TestGroup '%s' not added to this run. "
+                            "Auxiliary script '%s' failed verification." %
+                            (self.pathname, f))
+                return False
+
+        for user in [user for user in users if len(user)]:
+            if not verify_user(user, logger):
+                logger.info("Not adding TestGroup '%s' to this run." %
+                            self.pathname)
+                return False
+
+        # If one of the tests is invalid, delete it, log it, and drive on.
+        for test in self.tests:
+            if not verify_file(os.path.join(self.pathname, test)):
+                del self.tests[self.tests.index(test)]
+                logger.info("Warning: Test '%s' removed from TestGroup '%s' "
+                            "because it failed verification." % (test,
+                            self.pathname))
+
+        return len(self.tests) is not 0
+
+    def run(self, logger, options):
+        """
+        Create Cmd instances for the pre/post scripts. If the pre script
+        doesn't pass, skip all the tests in this TestGroup. Run the post
+        script regardless.
+        """
+        pretest = Cmd(self.pre, outputdir=os.path.join(self.outputdir,
+                      os.path.basename(self.pre)), timeout=self.timeout,
+                      user=self.pre_user)
+        posttest = Cmd(self.post, outputdir=os.path.join(self.outputdir,
+                       os.path.basename(self.post)), timeout=self.timeout,
+                       user=self.post_user)
+
+        cont = True
+        if len(pretest.pathname):
+            pretest.run(options)
+            cont = pretest.result.result is 'PASS'
+            pretest.log(logger, options)
+
+        for fname in self.tests:
+            test = Cmd(os.path.join(self.pathname, fname),
+                       outputdir=os.path.join(self.outputdir, fname),
+                       timeout=self.timeout, user=self.user)
+            if cont:
+                test.run(options)
+            else:
+                test.skip()
+
+            test.log(logger, options)
+
+        if len(posttest.pathname):
+            posttest.run(options)
+            posttest.log(logger, options)
+
+
+class TestRun(object):
+    props = ['quiet', 'outputdir']
+
+    def __init__(self, options):
+        self.tests = {}
+        self.testgroups = {}
+        self.starttime = time()
+        self.timestamp = datetime.now().strftime('%Y%m%dT%H%M%S')
+        self.outputdir = os.path.join(options.outputdir, self.timestamp)
+        self.logger = self.setup_logging(options)
+        self.defaults = [
+            ('outputdir', BASEDIR),
+            ('quiet', False),
+            ('timeout', 60),
+            ('user', ''),
+            ('pre', ''),
+            ('pre_user', ''),
+            ('post', ''),
+            ('post_user', '')
+        ]
+
+    def __str__(self):
+        s = 'TestRun:\n    outputdir: %s\n' % self.outputdir
+        s += 'TESTS:\n'
+        for key in sorted(self.tests.keys()):
+            s += '%s%s' % (self.tests[key].__str__(), '\n')
+        s += 'TESTGROUPS:\n'
+        for key in sorted(self.testgroups.keys()):
+            s += '%s%s' % (self.testgroups[key].__str__(), '\n')
+        return s
+
+    def addtest(self, pathname, options):
+        """
+        Create a new Test, and apply any properties that were passed in
+        from the command line. If it passes verification, add it to the
+        TestRun.
+        """
+        test = Test(pathname)
+        for prop in Test.props:
+            setattr(test, prop, getattr(options, prop))
+
+        if test.verify(self.logger):
+            self.tests[pathname] = test
+
+    def addtestgroup(self, dirname, filenames, options):
+        """
+        Create a new TestGroup, and apply any properties that were passed
+        in from the command line. If it passes verification, add it to the
+        TestRun.
+        """
+        if dirname not in self.testgroups:
+            testgroup = TestGroup(dirname)
+            for prop in Test.props:
+                setattr(testgroup, prop, getattr(options, prop))
+
+            # Prevent pre/post scripts from running as regular tests
+            for f in [testgroup.pre, testgroup.post]:
+                if f in filenames:
+                    del filenames[filenames.index(f)]
+
+            self.testgroups[dirname] = testgroup
+            self.testgroups[dirname].tests = sorted(filenames)
+
+            testgroup.verify(self.logger)
+
+    def read(self, logger, options):
+        """
+        Read in the specified runfile, and apply the TestRun properties
+        listed in the 'DEFAULT' section to our TestRun. Then read each
+        section, and apply the appropriate properties to the Test or
+        TestGroup. Properties from individual sections override those set
+        in the 'DEFAULT' section. If the Test or TestGroup passes
+        verification, add it to the TestRun.
+        """
+        config = ConfigParser.RawConfigParser()
+        if not len(config.read(options.runfile)):
+            fail("Coulnd't read config file %s" % options.runfile)
+
+        for opt in TestRun.props:
+            if config.has_option('DEFAULT', opt):
+                setattr(self, opt, config.get('DEFAULT', opt))
+        self.outputdir = os.path.join(self.outputdir, self.timestamp)
+
+        for section in config.sections():
+            if 'tests' in config.options(section):
+                testgroup = TestGroup(section)
+                for prop in TestGroup.props:
+                    try:
+                        setattr(testgroup, prop, config.get('DEFAULT', prop))
+                        setattr(testgroup, prop, config.get(section, prop))
+                    except ConfigParser.NoOptionError:
+                        pass
+
+                # Repopulate tests using eval to convert the string to a list
+                testgroup.tests = eval(config.get(section, 'tests'))
+
+                if testgroup.verify(logger):
+                    self.testgroups[section] = testgroup
+            else:
+                test = Test(section)
+                for prop in Test.props:
+                    try:
+                        setattr(test, prop, config.get('DEFAULT', prop))
+                        setattr(test, prop, config.get(section, prop))
+                    except ConfigParser.NoOptionError:
+                        pass
+                if test.verify(logger):
+                    self.tests[section] = test
+
+    def write(self, options):
+        """
+        Create a configuration file for editing and later use. The
+        'DEFAULT' section of the config file is created from the
+        properties that were specified on the command line. Tests are
+        simply added as sections that inherit everything from the
+        'DEFAULT' section. TestGroups are the same, except they get an
+        option including all the tests to run in that directory.
+        """
+
+        defaults = dict([(prop, getattr(options, prop)) for prop, _ in
+                        self.defaults])
+        config = ConfigParser.RawConfigParser(defaults)
+
+        for test in sorted(self.tests.keys()):
+            config.add_section(test)
+
+        for testgroup in sorted(self.testgroups.keys()):
+            config.add_section(testgroup)
+            config.set(testgroup, 'tests', self.testgroups[testgroup].tests)
+
+        try:
+            with open(options.template, 'w') as f:
+                return config.write(f)
+        except IOError:
+            fail('Could not open \'%s\' for writing.' % options.template)
+
+    def complete_outputdirs(self, options):
+        """
+        Collect all the pathnames for Tests, and TestGroups. Work
+        backwards one pathname component at a time, to create a unique
+        directory name in which to deposit test output. Tests will be able
+        to write output files directly in the newly modified outputdir.
+        TestGroups will be able to create one subdirectory per test in the
+        outputdir, and are guaranteed uniqueness because a group can only
+        contain files in one directory. Pre and post tests will create a
+        directory rooted at the outputdir of the Test or TestGroup in
+        question for their output.
+        """
+        done = False
+        components = 0
+        tmp_dict = dict(self.tests.items() + self.testgroups.items())
+        total = len(tmp_dict)
+        base = self.outputdir
+
+        while not done:
+            l = []
+            components -= 1
+            for testfile in tmp_dict.keys():
+                uniq = '/'.join(testfile.split('/')[components:]).lstrip('/')
+                if not uniq in l:
+                    l.append(uniq)
+                    tmp_dict[testfile].outputdir = os.path.join(base, uniq)
+                else:
+                    break
+            done = total == len(l)
+
+    def setup_logging(self, options):
+        """
+        Two loggers are set up here. The first is for the logfile which
+        will contain one line summarizing the test, including the test
+        name, result, and running time. This logger will also capture the
+        timestamped combined stdout and stderr of each run. The second
+        logger is optional console output, which will contain only the one
+        line summary. The loggers are initialized at two different levels
+        to facilitate segregating the output.
+        """
+        if options.dryrun is True:
+            return
+
+        testlogger = logging.getLogger(__name__)
+        testlogger.setLevel(logging.DEBUG)
+
+        if options.cmd is not 'wrconfig':
+            try:
+                old = os.umask(0)
+                os.makedirs(self.outputdir, mode=0777)
+                os.umask(old)
+            except OSError, e:
+                fail('%s' % e)
+            filename = os.path.join(self.outputdir, 'log')
+
+            logfile = logging.FileHandler(filename)
+            logfile.setLevel(logging.DEBUG)
+            logfilefmt = logging.Formatter('%(message)s')
+            logfile.setFormatter(logfilefmt)
+            testlogger.addHandler(logfile)
+
+        cons = logging.StreamHandler()
+        cons.setLevel(logging.INFO)
+        consfmt = logging.Formatter('%(message)s')
+        cons.setFormatter(consfmt)
+        testlogger.addHandler(cons)
+
+        return testlogger
+
+    def run(self, options):
+        """
+        Walk through all the Tests and TestGroups, calling run().
+        """
+        try:
+            os.chdir(self.outputdir)
+        except OSError:
+            fail('Could not change to directory %s' % self.outputdir)
+        for test in sorted(self.tests.keys()):
+            self.tests[test].run(self.logger, options)
+        for testgroup in sorted(self.testgroups.keys()):
+            self.testgroups[testgroup].run(self.logger, options)
+
+    def summary(self):
+        if Result.total is 0:
+            return
+
+        print '\nResults Summary'
+        for key in Result.runresults.keys():
+            if Result.runresults[key] is not 0:
+                print '%s\t% 4d' % (key, Result.runresults[key])
+
+        m, s = divmod(time() - self.starttime, 60)
+        h, m = divmod(m, 60)
+        print '\nRunning Time:\t%02d:%02d:%02d' % (h, m, s)
+        print 'Percent passed:\t%.1f%%' % ((float(Result.runresults['PASS']) /
+               float(Result.total)) * 100)
+        print 'Log directory:\t%s' % self.outputdir
+
+
+def verify_file(pathname):
+    """
+    Verify that the supplied pathname is an executable regular file.
+    """
+    if os.path.isdir(pathname) or os.path.islink(pathname):
+        return False
+
+    if os.path.isfile(pathname) and os.access(pathname, os.X_OK):
+        return True
+
+    return False
+
+
+def verify_user(user, logger):
+    """
+    Verify that the specified user exists on this system, and can execute
+    sudo without being prompted for a password.
+    """
+    testcmd = [SUDO, '-n', '-u', user, TRUE]
+    can_sudo = exists = True
+
+    if user in Cmd.verified_users:
+        return True
+
+    try:
+        _ = getpwnam(user)
+    except KeyError:
+        exists = False
+        logger.info("Warning: user '%s' does not exist.", user)
+        return False
+
+    p = Popen(testcmd)
+    p.wait()
+    if p.returncode is not 0:
+        logger.info("Warning: user '%s' cannot use paswordless sudo.", user)
+        return False
+    else:
+        Cmd.verified_users.append(user)
+
+    return True
+
+
+def find_tests(testrun, options):
+    """
+    For the given list of pathnames, add files as Tests. For directories,
+    if do_groups is True, add the directory as a TestGroup. If False,
+    recursively search for executable files.
+    """
+
+    for p in sorted(options.pathnames):
+        if os.path.isdir(p):
+            for dirname, _, filenames in os.walk(p):
+                if options.do_groups:
+                    testrun.addtestgroup(dirname, filenames, options)
+                else:
+                    for f in sorted(filenames):
+                        testrun.addtest(os.path.join(dirname, f), options)
+        else:
+            testrun.addtest(p, options)
+
+
+def fail(retstr, ret=1):
+    print '%s: %s' % (argv[0], retstr)
+    exit(ret)
+
+
+def options_cb(option, opt_str, value, parser):
+    path_options = ['runfile', 'outputdir', 'template']
+
+    if option.dest is 'runfile' and '-w' in parser.rargs or \
+        option.dest is 'template' and '-c' in parser.rargs:
+        fail('-c and -w are mutually exclusive.')
+
+    if opt_str in parser.rargs:
+        fail('%s may only be specified once.' % opt_str)
+
+    if option.dest is 'runfile':
+        parser.values.cmd = 'rdconfig'
+    if option.dest is 'template':
+        parser.values.cmd = 'wrconfig'
+
+    setattr(parser.values, option.dest, value)
+    if option.dest in path_options:
+        setattr(parser.values, option.dest, os.path.abspath(value))
+
+
+def parse_args():
+    parser = OptionParser()
+    parser.add_option('-c', action='callback', callback=options_cb,
+                      type='string', dest='runfile', metavar='runfile',
+                      help='Specify tests to run via config file.')
+    parser.add_option('-d', action='store_true', default=False, dest='dryrun',
+                      help='Dry run. Print tests, but take no other action.')
+    parser.add_option('-g', action='store_true', default=False,
+                      dest='do_groups', help='Make directories TestGroups.')
+    parser.add_option('-o', action='callback', callback=options_cb,
+                      default=BASEDIR, dest='outputdir', type='string',
+                      metavar='outputdir', help='Specify an output directory.')
+    parser.add_option('-p', action='callback', callback=options_cb,
+                      default='', dest='pre', metavar='script',
+                      type='string', help='Specify a pre script.')
+    parser.add_option('-P', action='callback', callback=options_cb,
+                      default='', dest='post', metavar='script',
+                      type='string', help='Specify a post script.')
+    parser.add_option('-q', action='store_true', default=False, dest='quiet',
+                      help='Silence on the console during a test run.')
+    parser.add_option('-t', action='callback', callback=options_cb, default=60,
+                      dest='timeout', metavar='seconds', type='int',
+                      help='Timeout (in seconds) for an individual test.')
+    parser.add_option('-u', action='callback', callback=options_cb,
+                      default='', dest='user', metavar='user', type='string',
+                      help='Specify a different user name to run as.')
+    parser.add_option('-w', action='callback', callback=options_cb,
+                      default=None, dest='template', metavar='template',
+                      type='string', help='Create a new config file.')
+    parser.add_option('-x', action='callback', callback=options_cb, default='',
+                      dest='pre_user', metavar='pre_user', type='string',
+                      help='Specify a user to execute the pre script.')
+    parser.add_option('-X', action='callback', callback=options_cb, default='',
+                      dest='post_user', metavar='post_user', type='string',
+                      help='Specify a user to execute the post script.')
+    (options, pathnames) = parser.parse_args()
+
+    if not options.runfile and not options.template:
+        options.cmd = 'runtests'
+
+    if options.runfile and len(pathnames):
+        fail('Extraneous arguments.')
+
+    options.pathnames = [os.path.abspath(path) for path in pathnames]
+
+    return options
+
+
+def main(args):
+    options = parse_args()
+    testrun = TestRun(options)
+
+    if options.cmd is 'runtests':
+        find_tests(testrun, options)
+    elif options.cmd is 'rdconfig':
+        testrun.read(testrun.logger, options)
+    elif options.cmd is 'wrconfig':
+        find_tests(testrun, options)
+        testrun.write(options)
+        exit(0)
+    else:
+        fail('Unknown command specified')
+
+    testrun.complete_outputdirs(options)
+    testrun.run(options)
+    testrun.summary()
+    exit(0)
+
+
+if __name__ == '__main__':
+    main(argv[1:])
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/usr/src/test/test-runner/man/Makefile	Wed Dec 05 22:04:50 2012 -0500
@@ -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) 2012 by Delphix. All rights reserved.
+#
+
+include $(SRC)/Makefile.master
+
+MANSRCS = run.1
+
+ROOTOPTPKG = $(ROOT)/opt/test-runner
+MANDIR = $(ROOTOPTPKG)/man/man1
+
+FILES = $(MANSRCS:%=$(MANDIR)/%)
+$(FILES) := FILEMODE = 0444
+
+all: $(MANSRCS)
+
+install: $(FILES)
+
+clean lint clobber:
+
+$(FILES): $(MANDIR) $(MANSRCS)
+
+$(MANDIR):
+	$(INS.dir)
+
+$(MANDIR)/%: %
+	$(INS.file)
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/usr/src/test/test-runner/man/run.1	Wed Dec 05 22:04:50 2012 -0500
@@ -0,0 +1,370 @@
+.\"
+.\" 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) 2012 by Delphix. All rights reserved.
+.\"
+.TH run 1 "23 Sep 2012"
+.SH NAME
+run \- find, execute, and log the results of tests
+.SH SYNOPSIS
+.LP
+.nf
+\fBrun\fR [\fB-dgq] [\fB-o\fR \fIoutputdir\fR] [\fB-pP\fR \fIscript\fR] [\fB-t\fR \fIseconds\fR] [\fB-uxX\fR \fIusername\fR]
+    \fIpathname\fR ...
+.fi
+
+.LP
+.nf
+\fBrun\fR \fB-w\fR \fIrunfile\fR [\fB-gq\fR] [\fB-o\fR \fIoutputdir\fR] [\fB-pP\fR \fIscript\fR] [\fB-t\fR \fIseconds\fR]
+    [\fB-uxX\fR \fIusername\fR] \fIpathname\fR ...
+.fi
+
+.LP
+.nf
+\fBrun\fR \fB-c\fR \fIrunfile\fR [\fB-dq\fR]
+.fi
+
+.LP
+.nf
+\fBrun\fR [\fB-h\fR]
+.fi
+
+.SH DESCRIPTION
+.sp
+.LP
+The \fBrun\fR command has three basic modes of operation. With neither the
+\fB-c\fR nor the \fB-w\fR option, \fBrun\fR processes the arguments provided on
+the command line, adding them to the list for this run. If a specified
+\fIpathname\fR is an executable file, it is added as a test. If a specified
+\fIpathname\fR is a directory, the behavior depends upon the \fB-g\fR option.
+If \fB-g\fR is specified, the directory is treated as a test group. See the
+section on "Test Groups" below. Without the \fB-g\fR option, \fBrun\fR simply
+descends into the directory looking for executable files. The tests are then
+executed, and the results are logged.
+
+With the \fB-w\fR option, \fBrun\fR finds tests in the manner described above.
+Rather than executing the tests and logging the results, the test configuration
+is stored in a \fIrunfile\fR which can be used in future invocations, or edited
+to modify which tests are executed and which options are applied. Options
+included on the command line with \fB-w\fR become defaults in the
+\fIrunfile\fR.
+
+With the \fB-c\fR option, \fBrun\fR parses a \fIrunfile\fR, which can specify a
+series of tests and test groups to be executed. The tests are then executed,
+and the results are logged.
+.sp
+.SS "Test Groups"
+.sp
+.LP
+A test group is comprised of a set of executable files, all of which exist in
+one directory. The options specified on the command line or in a \fIrunfile\fR
+apply to individual tests in the group. The exception is options pertaining to
+pre and post scripts, which act on all tests as a group. Rather than running
+before and after each test, these scripts are run only once each at the start
+and end of the test group.
+.SS "Test Execution"
+.sp
+.LP
+The specified tests run serially, and are typically assigned results according
+to exit values. Tests that exit zero and non-zero are marked "PASS" and "FAIL"
+respectively. When a pre script fails for a test group, only the post script is
+executed, and the remaining tests are marked "SKIPPED." Any test that exceeds
+its \fItimeout\fR is terminated, and marked "KILLED."
+
+By default, tests are executed with the credentials of the \fBrun\fR script.
+Executing tests with other credentials is done via \fBsudo\fR(1m), which must
+be configured to allow execution without prompting for a password. Environment
+variables from the calling shell are available to individual tests. During test
+execution, the working directory is changed to \fIoutputdir\fR.
+.SS "Output Logging"
+.sp
+.LP
+By default, \fBrun\fR will print one line on standard output at the conclusion
+of each test indicating the test name, result and elapsed time. Additionally,
+for each invocation of \fBrun\fR, a directory is created using the ISO 8601
+date format. Within this directory is a file named \fIlog\fR containing all the
+test output with timestamps, and a directory for each test. Within the test
+directories, there is one file each for standard output, standard error and
+merged output. The default location for the \fIoutputdir\fR is
+\fI/var/tmp/test_results\fR.
+.SS "Runfiles"
+.sp
+.LP
+The \fIrunfile\fR is an ini style configuration file that describes a test run.
+The file has one section named "DEFAULT," which contains configuration option
+names and their values in "name = value" format. The values in this section
+apply to all the subsequent sections, unless they are also specified there, in
+which case the default is overridden. The remaining section names are the
+absolute pathnames of files and direcotries, describing tests and test groups
+respectively. The legal option names are:
+.sp
+.ne 2
+.na
+\fBoutputdir\fR = \fIpathname\fR
+.ad
+.sp .6
+.RS 4n
+The name of the directory that holds test logs.
+.RE
+.sp
+.ne 2
+.na
+\fBpre\fR = \fIscript\fR
+.ad
+.sp .6
+.RS 4n
+Run \fIscript\fR prior to the test or test group.
+.RE
+.sp
+.ne 2
+.na
+\fBpre_user\fR = \fIusername\fR
+.ad
+.sp .6
+.RS 4n
+Execute the pre script as \fIusername\fR.
+.RE
+.sp
+.ne 2
+.na
+\fBpost\fR = \fIscript\fR
+.ad
+.sp .6
+.RS 4n
+Run \fIscript\fR after the test or test group.
+.RE
+.sp
+.ne 2
+.na
+\fBpost_user\fR = \fIusername\fR
+.ad
+.sp .6
+.RS 4n
+Execute the post script as \fIusername\fR.
+.RE
+.sp
+.ne 2
+.na
+\fBquiet\fR = [\fITrue\fR|\fIFalse\fR]
+.ad
+.sp .6
+.RS 4n
+If set to True, only the results summary is printed to standard out.
+.RE
+.sp
+.ne 2
+.na
+\fBtests\fR = [\fI'filename'\fR [,...]]
+.ad
+.sp .6
+.RS 4n
+Specify a list of \fIfilenames\fR for this test group. Only the basename of the
+absolute path is required. This option is only valid for test groups, and each
+\fIfilename\fR must be single quoted.
+.RE
+.sp
+.ne 2
+.na
+\fBtimeout\fR = \fIn\fR
+.ad
+.sp .6
+.RS 4n
+A timeout value of \fIn\fR seconds.
+.RE
+.sp
+.ne 2
+.na
+\fBuser\fR = \fIusername\fR
+.ad
+.sp .6
+.RS 4n
+Execute the test or test group as \fIusername\fR.
+.RE
+
+.SH OPTIONS
+.sp
+.LP
+The following options are available for the \fBrun\fR command.
+.sp
+.ne 2
+.na
+\fB-c\fR \fIrunfile\fR
+.ad
+.RS 6n
+Specify a \fIrunfile\fR to be consumed by the run command.
+.RE
+
+.ne 2
+.na
+\fB-d\fR
+.ad
+.RS 6n
+Dry run mode. Execute no tests, but print a description of each test that would
+have been run.
+.RE
+
+.ne 2
+.na
+\fB-g\fR
+.ad
+.RS 6n
+Create test groups from any directories found while searching for tests.
+.RE
+
+.ne 2
+.na
+\fB-o\fR \fIoutputdir\fR
+.ad
+.RS 6n
+Specify the directory in which to write test results.
+.RE
+
+.ne 2
+.na
+\fB-p\fR \fIscript\fR
+.ad
+.RS 6n
+Run \fIscript\fR prior to any test or test group.
+.RE
+
+.ne 2
+.na
+\fB-P\fR \fIscript\fR
+.ad
+.RS 6n
+Run \fIscript\fR after any test or test group.
+.RE
+
+.ne 2
+.na
+\fB-q\fR
+.ad
+.RS 6n
+Print only the results sumary to the standard output.
+.RE
+
+.ne 2
+.na
+\fB-t\fR \fIn\fR
+.ad
+.RS 6n
+Specify a timeout value of \fIn\fR seconds per test.
+.RE
+
+.ne 2
+.na
+\fB-u\fR \fIusername\fR
+.ad
+.RS 6n
+Execute tests or test groups as \fIusername\fR.
+.RE
+
+.ne 2
+.na
+\fB-w\fR \fIrunfile\fR
+.ad
+.RS 6n
+Specify the name of the \fIrunfile\fR to create.
+.RE
+
+.ne 2
+.na
+\fB-x\fR \fIusername\fR
+.ad
+.RS 6n
+Execute the pre script as \fIusername\fR.
+.RE
+
+.ne 2
+.na
+\fB-X\fR \fIusername\fR
+.ad
+.RS 6n
+Execute the post script as \fIusername\fR.
+.RE
+
+.SH EXAMPLES
+.LP
+\fBExample 1\fR Running ad-hoc tests.
+.sp
+.LP
+This example demonstrates the simplest invocation of \fBrun\fR.
+
+.sp
+.in +2
+.nf
+% \fBrun my-tests\fR
+Test: /home/jkennedy/my-tests/test-01                    [00:02] [PASS]
+Test: /home/jkennedy/my-tests/test-02                    [00:04] [PASS]
+Test: /home/jkennedy/my-tests/test-03                    [00:01] [PASS]
+
+Results Summary
+PASS       3
+
+Running Time:   00:00:07
+Percent passed: 100.0%
+Log directory:  /var/tmp/test_results/20120923T180654
+.fi
+.in -2
+
+.LP
+\fBExample 2\fR Creating a \fIrunfile\fR for future use.
+.sp
+.LP
+This example demonstrates creating a \fIrunfile\fR with non default options.
+
+.sp
+.in +2
+.nf
+% \fBrun -p setup -x root -g -w new-tests.run new-tests\fR
+% \fBcat new-tests.run\fR
+[DEFAULT]
+pre = setup
+post_user =
+quiet = False
+user =
+timeout = 60
+post =
+pre_user = root
+outputdir = /var/tmp/test_results
+
+[/home/jkennedy/new-tests]
+tests = ['test-01', 'test-02', 'test-03']
+.fi
+.in -2
+
+.SH EXIT STATUS
+.sp
+.LP
+The following exit values are returned:
+.sp
+.ne 2
+.na
+\fB\fB0\fR\fR
+.ad
+.sp .6
+.RS 4n
+Successful completion.
+.RE
+.sp
+.ne 2
+.na
+\fB\fB1\fR\fR
+.ad
+.sp .6
+.RS 4n
+An error occurred.
+.RE
+
+.SH SEE ALSO
+.sp
+.LP
+\fBsudo\fR(1m)
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/usr/src/test/test-runner/stf/Makefile	Wed Dec 05 22:04:50 2012 -0500
@@ -0,0 +1,20 @@
+#
+# 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) 2012 by Delphix. All rights reserved.
+#
+
+.PARALLEL: $(SUBDIRS)
+
+SUBDIRS = contrib/include include
+
+include $(SRC)/test/Makefile.com
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/usr/src/test/test-runner/stf/README	Wed Dec 05 22:04:50 2012 -0500
@@ -0,0 +1,19 @@
+#
+# 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) 2012 by Delphix. All rights reserved.
+#
+
+This directory contains shell libraries used by the Solaris Test
+Framework (STF). They are duplicated here to allow test suites (like
+the ZFS Test Suite) that were written for STF to be easily ported
+to this framework.
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/usr/src/test/test-runner/stf/contrib/include/Makefile	Wed Dec 05 22:04:50 2012 -0500
@@ -0,0 +1,37 @@
+#
+# 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) 2012 by Delphix. All rights reserved.
+#
+
+include $(SRC)/Makefile.master
+include $(SRC)/test/Makefile.com
+
+ROOTOPTPKG = $(ROOT)/opt/test-runner
+INCLUDEDIR = $(ROOTOPTPKG)/stf/contrib/include
+
+PROGS = logapi.shlib
+
+CMDS = $(PROGS:%=$(INCLUDEDIR)/%)
+$(CMDS) := FILEMODE = 0555
+
+all lint clean clobber:
+
+install: $(CMDS)
+
+$(CMDS): $(INCLUDEDIR)
+
+$(INCLUDEDIR):
+	$(INS.dir)
+
+$(INCLUDEDIR)/%: %
+	$(INS.file)
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/usr/src/test/test-runner/stf/contrib/include/logapi.shlib	Wed Dec 05 22:04:50 2012 -0500
@@ -0,0 +1,384 @@
+#
+# CDDL HEADER START
+#
+# The contents of this file are subject to the terms of the
+# Common Development and Distribution License (the "License").
+# You may not use this file except in compliance with the License.
+#
+# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
+# or http://www.opensolaris.org/os/licensing.
+# See the License for the specific language governing permissions
+# and limitations under the License.
+#
+# When distributing Covered Code, include this CDDL HEADER in each
+# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
+# If applicable, add the following below this CDDL HEADER, with the
+# fields enclosed by brackets "[]" replaced with your own identifying
+# information: Portions Copyright [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.
+#
+
+. ${STF_TOOLS}/include/stf.shlib
+
+# Output an assertion
+#
+# $@ - assertion text
+
+function log_assert
+{
+	_printline ASSERTION: "$@"
+}
+
+# Output a comment
+#
+# $@ - comment text
+
+function log_note
+{
+	_printline NOTE: "$@"
+}
+
+# Execute and print command with status where success equals non-zero result
+#
+# $@ - command to execute
+#
+# return 0 if command fails, otherwise return 1
+
+function log_neg
+{
+	log_neg_expect ""  "$@"
+	return $?
+}
+
+# Execute a positive test and exit $STF_FAIL is test fails
+#
+# $@ - command to execute
+
+function log_must
+{
+	log_pos "$@"
+	(( $? != 0 )) && log_fail
+}
+
+# Execute a negative test and exit $STF_FAIL if test passes
+#
+# $@ - command to execute
+
+function log_mustnot
+{
+	log_neg "$@"
+	(( $? != 0 )) && log_fail
+}
+
+# Execute a negative test with keyword expected, and exit
+# $STF_FAIL if test passes
+#
+# $1 - keyword expected
+# $2-$@ - command to execute
+
+function log_mustnot_expect
+{
+	log_neg_expect "$@"
+	(( $? != 0 )) && log_fail
+}
+
+# Execute and print command with status where success equals non-zero result
+# or output includes expected keyword
+#
+# $1 - keyword expected
+# $2-$@ - command to execute
+#
+# return 0 if command fails, or the output contains the keyword expected,
+# return 1 otherwise
+
+function log_neg_expect
+{
+	typeset out=""
+	typeset logfile="/tmp/log.$$"
+	typeset ret=1
+	typeset expect=$1
+	shift
+
+	while [[ -e $logfile ]]; do
+		logfile="$logfile.$$"
+	done
+
+	"$@" 2>$logfile
+	typeset status=$?
+	out="/usr/bin/cat $logfile"
+
+	# unexpected status
+	if (( $status == 0 )); then
+		 print -u2 $($out)
+		_printerror "$@" "unexpectedly exited $status"
+	# missing binary
+	elif (( $status == 127 )); then
+		print -u2 $($out)
+		_printerror "$@" "unexpectedly exited $status (File not found)"
+	# bus error - core dump
+	elif (( $status == 138 )); then
+		print -u2 $($out)
+		_printerror "$@" "unexpectedly exited $status (Bus Error)"
+	# segmentation violation - core dump
+	elif (( $status == 139 )); then
+		print -u2 $($out)
+		_printerror "$@" "unexpectedly exited $status (SEGV)"
+	else
+		$out | /usr/bin/egrep -i "internal error|assertion failed" \
+			> /dev/null 2>&1
+		# internal error or assertion failed
+		if (( $? == 0 )); then
+			print -u2 $($out)
+			_printerror "$@" "internal error or assertion failure" \
+				" exited $status"
+		elif [[ -n $expect ]] ; then
+			$out | /usr/bin/grep -i "$expect" > /dev/null 2>&1
+			if (( $? == 0 )); then
+				ret=0
+			else
+				print -u2 $($out)
+				_printerror "$@" "unexpectedly exited $status"
+			fi
+		else
+			ret=0
+		fi
+
+		if (( $ret == 0 )); then
+			[[ -n $LOGAPI_DEBUG ]] && print $($out)
+			_printsuccess "$@" "exited $status"
+		fi
+	fi
+	_recursive_output $logfile "false"
+	return $ret
+}
+
+# Execute and print command with status where success equals zero result
+#
+# $@ command to execute
+#
+# return command exit status
+
+function log_pos
+{
+	typeset out=""
+	typeset logfile="/tmp/log.$$"
+
+	while [[ -e $logfile ]]; do
+		logfile="$logfile.$$"
+	done
+
+	"$@" 2>$logfile
+	typeset status=$?
+	out="/usr/bin/cat $logfile"
+
+	if (( $status != 0 )) ; then
+		print -u2 $($out)
+		_printerror "$@" "exited $status"
+	else
+		$out | /usr/bin/egrep -i "internal error|assertion failed" \
+			> /dev/null 2>&1
+		# internal error or assertion failed
+		if [[ $? -eq 0 ]]; then
+			print -u2 $($out)
+			_printerror "$@" "internal error or assertion failure" \
+				" exited $status"
+			status=1
+		else
+			[[ -n $LOGAPI_DEBUG ]] && print $($out)
+			_printsuccess "$@"
+		fi
+	fi
+	_recursive_output $logfile "false"
+	return $status
+}
+
+# Set an exit handler
+#
+# $@ - function(s) to perform on exit
+
+function log_onexit
+{
+	_CLEANUP="$@"
+}
+
+#
+# Exit functions
+#
+
+# Perform cleanup and exit $STF_PASS
+#
+# $@ - message text
+
+function log_pass
+{
+	_endlog $STF_PASS "$@"
+}
+
+# Perform cleanup and exit $STF_FAIL
+#
+# $@ - message text
+
+function log_fail
+{
+	_endlog $STF_FAIL "$@"
+}
+
+# Perform cleanup and exit $STF_UNRESOLVED
+#
+# $@ - message text
+
+function log_unresolved
+{
+	_endlog $STF_UNRESOLVED "$@"
+}
+
+# Perform cleanup and exit $STF_NOTINUSE
+#
+# $@ - message text
+
+function log_notinuse
+{
+	_endlog $STF_NOTINUSE "$@"
+}
+
+# Perform cleanup and exit $STF_UNSUPPORTED
+#
+# $@ - message text
+
+function log_unsupported
+{
+	_endlog $STF_UNSUPPORTED "$@"
+}
+
+# Perform cleanup and exit $STF_UNTESTED
+#
+# $@ - message text
+
+function log_untested
+{
+	_endlog $STF_UNTESTED "$@"
+}
+
+# Perform cleanup and exit $STF_UNINITIATED
+#
+# $@ - message text
+
+function log_uninitiated
+{
+	_endlog $STF_UNINITIATED "$@"
+}
+
+# Perform cleanup and exit $STF_NORESULT
+#
+# $@ - message text
+
+function log_noresult
+{
+	_endlog $STF_NORESULT "$@"
+}
+
+# Perform cleanup and exit $STF_WARNING
+#
+# $@ - message text
+
+function log_warning
+{
+	_endlog $STF_WARNING "$@"
+}
+
+# Perform cleanup and exit $STF_TIMED_OUT
+#
+# $@ - message text
+
+function log_timed_out
+{
+	_endlog $STF_TIMED_OUT "$@"
+}
+
+# Perform cleanup and exit $STF_OTHER
+#
+# $@ - message text
+
+function log_other
+{
+	_endlog $STF_OTHER "$@"
+}
+
+#
+# Internal functions
+#
+
+# Perform cleanup and exit
+#
+# $1 - stf exit code
+# $2-$n - message text
+
+function _endlog
+{
+	typeset logfile="/tmp/log.$$"
+	_recursive_output $logfile
+
+	if [[ -n $_CLEANUP ]] ; then
+		typeset cleanup=$_CLEANUP
+		log_onexit ""
+		log_note "Performing local cleanup via log_onexit ($cleanup)"
+		$cleanup
+	fi
+	typeset exitcode=$1
+	shift
+	(( ${#@} > 0 )) && _printline "$@"
+	exit $exitcode
+}
+
+# Output a formatted line
+#
+# $@ - message text
+
+function _printline
+{
+	print "$@"
+}
+
+# Output an error message
+#
+# $@ - message text
+
+function _printerror
+{
+	_printline ERROR: "$@"
+}
+
+# Output a success message
+#
+# $@ - message text
+
+function _printsuccess
+{
+	_printline SUCCESS: "$@"
+}
+
+# Output logfiles recursively
+#
+# $1 - start file
+# $2 - indicate whether output the start file itself, default as yes.
+
+function _recursive_output #logfile
+{
+	typeset logfile=$1
+
+	while [[ -e $logfile ]]; do
+		if [[ -z $2 || $logfile != $1 ]]; then
+			/usr/bin/cat $logfile
+		fi
+		/usr/bin/rm -f $logfile
+		logfile="$logfile.$$"
+        done
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/usr/src/test/test-runner/stf/include/Makefile	Wed Dec 05 22:04:50 2012 -0500
@@ -0,0 +1,37 @@
+#
+# 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) 2012 by Delphix. All rights reserved.
+#
+
+include $(SRC)/Makefile.master
+include $(SRC)/test/Makefile.com
+
+ROOTOPTPKG = $(ROOT)/opt/test-runner
+INCLUDEDIR = $(ROOTOPTPKG)/stf/include
+
+PROGS = stf.shlib
+
+CMDS = $(PROGS:%=$(INCLUDEDIR)/%)
+$(CMDS) := FILEMODE = 0555
+
+all lint clean clobber:
+
+install: $(CMDS)
+
+$(CMDS): $(INCLUDEDIR)
+
+$(INCLUDEDIR):
+	$(INS.dir)
+
+$(INCLUDEDIR)/%: %
+	$(INS.file)
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/usr/src/test/test-runner/stf/include/stf.shlib	Wed Dec 05 22:04:50 2012 -0500
@@ -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) 2012 by Delphix. All rights reserved.
+#
+
+
+STF_PASS=0
+STF_FAIL=1
+STF_UNRESOLVED=2
+STF_NOTINUSE=3
+STF_UNSUPPORTED=4
+STF_UNTESTED=5
+STF_UNINITIATED=6
+STF_NORESULT=7
+STF_WARNING=8
+STF_TIMED_OUT=9
+STF_OTHER=10
+
+# do this to use the names: eval echo \$STF_RESULT_NAME_${result}
+STF_RESULT_NAME_0="PASS"
+STF_RESULT_NAME_1="FAIL"
+STF_RESULT_NAME_2="UNRESOLVED"
+STF_RESULT_NAME_3="NOTINUSE"
+STF_RESULT_NAME_4="UNSUPPORTED"
+STF_RESULT_NAME_5="UNTESTED"
+STF_RESULT_NAME_6="UNINITIATED"
+STF_RESULT_NAME_7="NORESULT"
+STF_RESULT_NAME_8="WARNING"
+STF_RESULT_NAME_9="TIMED_OUT"
+STF_RESULT_NAME_10="OTHER"
+
+# do this to use the array: ${STF_RESULT_NAMES[$result]}
+STF_RESULT_NAMES=( "PASS" "FAIL" "UNRESOLVED" "NOTINUSE" "UNSUPPORTED" \
+    "UNTESTED" "UNINITIATED" "NORESULT" "WARNING" "TIMED_OUT" "OTHER" )
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/usr/src/test/zfs-tests/Makefile	Wed Dec 05 22:04:50 2012 -0500
@@ -0,0 +1,20 @@
+#
+# 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) 2012 by Delphix. All rights reserved.
+#
+
+.PARALLEL: $(SUBDIRS)
+
+SUBDIRS = cmd include runfiles tests doc
+
+include $(SRC)/test/Makefile.com
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/usr/src/test/zfs-tests/cmd/Makefile	Wed Dec 05 22:04:50 2012 -0500
@@ -0,0 +1,34 @@
+#
+# 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) 2012 by Delphix. All rights reserved.
+#
+
+.PARALLEL: $(SUBDIRS)
+
+SUBDIRS = chg_usr_exec \
+	devname2devid \
+	dir_rd_update \
+	file_check \
+	file_trunc \
+	file_write \
+	largest_file \
+	mkbusy \
+	mktree \
+	mmapwrite \
+	randfree_file \
+	readmmap \
+	rename_dir \
+	rm_lnkcnt_zero_file \
+	scripts
+
+include $(SRC)/test/Makefile.com
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/usr/src/test/zfs-tests/cmd/Makefile.subdirs	Wed Dec 05 22:04:50 2012 -0500
@@ -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) 2012 by Delphix. All rights reserved.
+#
+
+include $(SRC)/test/Makefile.com
+
+ROOTOPTPKG = $(ROOT)/opt/zfs-tests
+ROOTBIN = $(ROOTOPTPKG)/bin
+
+OBJS = $(PROG:%=%.o)
+SRCS = $(OBJS:%.o=%.c)
+
+CMDS = $(PROG:%=$(ROOTBIN)/%)
+$(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): $(ROOTBIN) $(PROG)
+
+$(ROOTBIN):
+	$(INS.dir)
+
+$(ROOTBIN)/%: %
+	$(INS.file)
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/usr/src/test/zfs-tests/cmd/chg_usr_exec/Makefile	Wed Dec 05 22:04:50 2012 -0500
@@ -0,0 +1,19 @@
+#
+# 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) 2012 by Delphix. All rights reserved.
+#
+
+PROG = chg_usr_exec
+
+include $(SRC)/cmd/Makefile.cmd
+include ../Makefile.subdirs
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/usr/src/test/zfs-tests/cmd/chg_usr_exec/chg_usr_exec.c	Wed Dec 05 22:04:50 2012 -0500
@@ -0,0 +1,77 @@
+/*
+ * CDDL HEADER START
+ *
+ * The contents of this file are subject to the terms of the
+ * Common Development and Distribution License (the "License").
+ * You may not use this file except in compliance with the License.
+ *
+ * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
+ * or http://www.opensolaris.org/os/licensing.
+ * See the License for the specific language governing permissions
+ * and limitations under the License.
+ *
+ * When distributing Covered Code, include this CDDL HEADER in each
+ * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
+ * If applicable, add the following below this CDDL HEADER, with the
+ * fields enclosed by brackets "[]" replaced with your own identifying
+ * information: Portions Copyright [yyyy] [name of copyright owner]
+ *
+ * CDDL HEADER END
+ */
+
+/*
+ * Copyright 2007 Sun Microsystems, Inc.  All rights reserved.
+ * Use is subject to license terms.
+ */
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <unistd.h>
+#include <string.h>
+#include <errno.h>
+#include <pwd.h>
+
+/* extern int errno = 0; */
+
+int
+main(int argc, char *argv[])
+{
+	char *plogin = NULL;
+	char cmds[BUFSIZ] = { 0 };
+	char sep[] = " ";
+	struct passwd *ppw = NULL;
+	int i, len;
+
+	if (argc < 3 || strlen(argv[1]) == 0) {
+		(void) printf("\tUsage: %s <login> <commands> ...\n", argv[0]);
+		return (1);
+	}
+
+	plogin = argv[1];
+	len = 0;
+	for (i = 2; i < argc; i++) {
+		(void) snprintf(cmds+len, sizeof (cmds)-len,
+		    "%s%s", argv[i], sep);
+		len += strlen(argv[i]) + strlen(sep);
+	}
+
+	if ((ppw = getpwnam(plogin)) == NULL) {
+		perror("getpwnam");
+		return (errno);
+	}
+	if (setgid(ppw->pw_gid) != 0) {
+		perror("setgid");
+		return (errno);
+	}
+	if (setuid(ppw->pw_uid) != 0) {
+		perror("setuid");
+		return (errno);
+	}
+
+	if (execl("/usr/xpg4/bin/sh", "sh",  "-c", cmds, (char *)0) != 0) {
+		perror("execl");
+		return (errno);
+	}
+
+	return (0);
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/usr/src/test/zfs-tests/cmd/devname2devid/Makefile	Wed Dec 05 22:04:50 2012 -0500
@@ -0,0 +1,22 @@
+#
+# 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) 2012 by Delphix. All rights reserved.
+#
+
+PROG = devname2devid
+
+include $(SRC)/cmd/Makefile.cmd
+
+LDLIBS += -ldevid
+
+include ../Makefile.subdirs
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/usr/src/test/zfs-tests/cmd/devname2devid/devname2devid.c	Wed Dec 05 22:04:50 2012 -0500
@@ -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 2007 Sun Microsystems, Inc.  All rights reserved.
+ * Use is subject to license terms.
+ */
+
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <devid.h>
+#include <errno.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <fcntl.h>
+
+/*
+ * Usage: devname2devid <devicepath>
+ *
+ * Examples:
+ *	# ./devname2devid /dev/dsk/c1t4d0s0
+ *	devid id1,sd@SSEAGATE_ST318404LSUN18G_3BT2G0Z300002146G4CR/a
+ *	# ./devname2devid /dev/dsk/c1t4d0
+ *	devid id1,sd@SSEAGATE_ST318404LSUN18G_3BT2G0Z300002146G4CR/wd
+ *	# ./devname2devid /dev/dsk/c1t4d0s1
+ *	devid id1,sd@SSEAGATE_ST318404LSUN18G_3BT2G0Z300002146G4CR/b
+ *	#
+ *
+ * This program accepts a disk or disk slice path and prints a
+ * device id.
+ *
+ * Exit values:
+ *	0 - means success
+ *	1 - means failure
+ *
+ */
+int
+main(int argc, char *argv[])
+{
+	int		fd;
+	ddi_devid_t	devid;
+	char		*minor_name, *devidstr, *device;
+#ifdef DEBUG
+	devid_nmlist_t  *list = NULL;
+	char		*search_path;
+	int		i;
+#endif
+
+	if (argc == 1) {
+		(void) printf("%s <devicepath> [search path]\n",
+		    argv[0]);
+		exit(1);
+	}
+	device = argv[1];
+
+	if ((fd = open(device, O_RDONLY|O_NDELAY)) < 0) {
+		perror(device);
+		exit(1);
+	}
+	if (devid_get(fd, &devid) != 0) {
+		perror("devid_get");
+		exit(1);
+	}
+	if (devid_get_minor_name(fd, &minor_name) != 0) {
+		perror("devid_get_minor_name");
+		exit(1);
+	}
+	if ((devidstr = devid_str_encode(devid, minor_name)) == 0) {
+		perror("devid_str_encode");
+		exit(1);
+	}
+
+	(void) printf("devid %s\n", devidstr);
+
+	devid_str_free(devidstr);
+
+#ifdef DEBUG
+	if (argc == 3) {
+		search_path = argv[2];
+	} else {
+		search_path = "/dev/rdsk";
+	}
+
+	if (devid_deviceid_to_nmlist(search_path, devid, DEVID_MINOR_NAME_ALL,
+	    &list)) {
+		perror("devid_deviceid_to_nmlist");
+		exit(1);
+	}
+
+	/* loop through list and process device names and numbers */
+	for (i = 0; list[i].devname != NULL; i++) {
+		(void) printf("devname: %s %p\n", list[i].devname, list[i].dev);
+	}
+	devid_free_nmlist(list);
+
+#endif /* DEBUG */
+
+	devid_str_free(minor_name);
+	devid_free(devid);
+
+	return (0);
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/usr/src/test/zfs-tests/cmd/dir_rd_update/Makefile	Wed Dec 05 22:04:50 2012 -0500
@@ -0,0 +1,19 @@
+#
+# 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) 2012 by Delphix. All rights reserved.
+#
+
+PROG = dir_rd_update
+
+include $(SRC)/cmd/Makefile.cmd
+include ../Makefile.subdirs
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/usr/src/test/zfs-tests/cmd/dir_rd_update/dir_rd_update.c	Wed Dec 05 22:04:50 2012 -0500
@@ -0,0 +1,117 @@
+/*
+ * CDDL HEADER START
+ *
+ * The contents of this file are subject to the terms of the
+ * Common Development and Distribution License (the "License").
+ * You may not use this file except in compliance with the License.
+ *
+ * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
+ * or http://www.opensolaris.org/os/licensing.
+ * See the License for the specific language governing permissions
+ * and limitations under the License.
+ *
+ * When distributing Covered Code, include this CDDL HEADER in each
+ * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
+ * If applicable, add the following below this CDDL HEADER, with the
+ * fields enclosed by brackets "[]" replaced with your own identifying
+ * information: Portions Copyright [yyyy] [name of copyright owner]
+ *
+ * CDDL HEADER END
+ */
+
+/*
+ * Copyright 2007 Sun Microsystems, Inc.  All rights reserved.
+ * Use is subject to license terms.
+ */
+
+/*
+ * Assertion:
+ *
+ *	A read operation and directory update operation performed
+ *      concurrently on the same directory can lead to deadlock
+ *	on a UFS logging file system, but not on a ZFS file system.
+ */
+
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <errno.h>
+#include <fcntl.h>
+#include <string.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <unistd.h>
+#define	TMP_DIR /tmp
+
+static char dirpath[256];
+
+int
+main(int argc, char **argv)
+{
+	char *cp1 = "";
+	int i = 0;
+	int ret = 0;
+	int testdd = 0;
+	pid_t pid;
+	static const int op_num = 5;
+
+	if (argc == 1) {
+		(void) printf("Usage: %s <mount point>\n", argv[0]);
+		exit(-1);
+	}
+	for (i = 0; i < 256; i++) {
+		dirpath[i] = 0;
+	}
+
+	cp1 = argv[1];
+	(void) strcpy(&dirpath[0], (const char *)cp1);
+	(void) strcat(&dirpath[strlen(dirpath)], "TMP_DIR");
+
+	ret = mkdir(dirpath, 0777);
+	if (ret != 0) {
+		if (errno != EEXIST) {
+			(void) printf("%s: mkdir(<%s>, 0777) failed: errno "
+			    "(decimal)=%d\n", argv[0], dirpath, errno);
+			exit(-1);
+		}
+	}
+	testdd = open(dirpath, O_RDONLY|O_RSYNC|O_SYNC|O_DSYNC);
+	if (testdd < 0) {
+		(void) printf("%s: open(<%s>, O_RDONLY|O_RSYNC|O_SYNC|O_DSYNC)"
+		    " failed: errno (decimal)=%d\n", argv[0], dirpath, errno);
+		exit(-1);
+	} else {
+		(void) close(testdd);
+	}
+	pid = fork();
+	if (pid > 0) {
+		int fd = open(dirpath, O_RDONLY|O_RSYNC|O_SYNC|O_DSYNC);
+		char buf[16];
+		int rdret;
+		int j = 0;
+
+		while (j < op_num) {
+			(void) sleep(1);
+			rdret = read(fd, buf, 16);
+			if (rdret == -1) {
+				(void) printf("readdir failed");
+			}
+			j++;
+		}
+	} else if (pid == 0) {
+		int fd = open(dirpath, O_RDONLY);
+		int chownret;
+		int k = 0;
+
+		while (k < op_num) {
+			(void) sleep(1);
+			chownret = fchown(fd, 0, 0);
+			if (chownret == -1) {
+				(void) printf("chown failed");
+			}
+
+			k++;
+		}
+	}
+
+	return (0);
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/usr/src/test/zfs-tests/cmd/file_check/Makefile	Wed Dec 05 22:04:50 2012 -0500
@@ -0,0 +1,19 @@
+#
+# 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) 2012 by Delphix. All rights reserved.
+#
+
+PROG = file_check
+
+include $(SRC)/cmd/Makefile.cmd
+include ../Makefile.subdirs
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/usr/src/test/zfs-tests/cmd/file_check/file_check.c	Wed Dec 05 22:04:50 2012 -0500
@@ -0,0 +1,86 @@
+/*
+ * CDDL HEADER START
+ *
+ * The contents of this file are subject to the terms of the
+ * Common Development and Distribution License (the "License").
+ * You may not use this file except in compliance with the License.
+ *
+ * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
+ * or http://www.opensolaris.org/os/licensing.
+ * See the License for the specific language governing permissions
+ * and limitations under the License.
+ *
+ * When distributing Covered Code, include this CDDL HEADER in each
+ * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
+ * If applicable, add the following below this CDDL HEADER, with the
+ * fields enclosed by brackets "[]" replaced with your own identifying
+ * information: Portions Copyright [yyyy] [name of copyright owner]
+ *
+ * CDDL HEADER END
+ */
+
+/*
+ * Copyright 2007 Sun Microsystems, Inc.  All rights reserved.
+ * Use is subject to license terms.
+ */
+
+#include "../file_common.h"
+
+static unsigned char bigbuffer[BIGBUFFERSIZE];
+
+/*
+ * Given a filename, check that the file consists entirely
+ * of a particular pattern. If the pattern is not specified a
+ * default will be used. For default values see file_common.h
+ */
+int
+main(int argc, char **argv)
+{
+	int		bigfd;
+	long		i, n;
+	uchar_t		fillchar = DATA;
+	int		bigbuffersize = BIGBUFFERSIZE;
+	int64_t		read_count = 0;
+
+	/*
+	 * Validate arguments
+	 */
+	if (argc < 2) {
+		(void) printf("Usage: %s filename [pattern]\n",
+		    argv[0]);
+		exit(1);
+	}
+
+	if (argv[2]) {
+		fillchar = atoi(argv[2]);
+	}
+
+	/*
+	 * Read the file contents and check every character
+	 * against the supplied pattern. Abort if the
+	 * pattern check fails.
+	 */
+	if ((bigfd = open(argv[1], O_RDONLY)) == -1) {
+		(void) printf("open %s failed %d\n", argv[1], errno);
+		exit(1);
+	}
+
+	do {
+		if ((n = read(bigfd, &bigbuffer, bigbuffersize)) == -1) {
+			(void) printf("read failed (%ld), %d\n", n, errno);
+			exit(errno);
+		}
+
+		for (i = 0; i < n; i++) {
+			if (bigbuffer[i] != fillchar) {
+				(void) printf("error %s: 0x%x != 0x%x)\n",
+				    argv[1], bigbuffer[i], fillchar);
+				exit(1);
+			}
+		}
+
+		read_count += n;
+	} while (n == bigbuffersize);
+
+	return (0);
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/usr/src/test/zfs-tests/cmd/file_common.h	Wed Dec 05 22:04:50 2012 -0500
@@ -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.
+ */
+
+#ifndef FILE_COMMON_H
+#define	FILE_COMMON_H
+
+/*
+ * header file for file_* utilities. These utilities
+ * are used by the test cases to perform various file
+ * operations (append writes, for example).
+ */
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <errno.h>
+#include <fcntl.h>
+#include <stdio.h>
+#include <unistd.h>
+#include <stdlib.h>
+#include <strings.h>
+
+#define	BLOCKSZ		8192
+#define	DATA		0xa5
+#define	DATA_RANGE	120
+#define	BIGBUFFERSIZE	0x800000
+#define	BIGFILESIZE	20
+
+extern char *optarg;
+extern int optind, opterr, optopt;
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* FILE_COMMON_H */
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/usr/src/test/zfs-tests/cmd/file_trunc/Makefile	Wed Dec 05 22:04:50 2012 -0500
@@ -0,0 +1,19 @@
+#
+# 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) 2012 by Delphix. All rights reserved.
+#
+
+PROG = file_trunc
+
+include $(SRC)/cmd/Makefile.cmd
+include ../Makefile.subdirs
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/usr/src/test/zfs-tests/cmd/file_trunc/file_trunc.c	Wed Dec 05 22:04:50 2012 -0500
@@ -0,0 +1,242 @@
+/*
+ * CDDL HEADER START
+ *
+ * The contents of this file are subject to the terms of the
+ * Common Development and Distribution License (the "License").
+ * You may not use this file except in compliance with the License.
+ *
+ * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
+ * or http://www.opensolaris.org/os/licensing.
+ * See the License for the specific language governing permissions
+ * and limitations under the License.
+ *
+ * When distributing Covered Code, include this CDDL HEADER in each
+ * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
+ * If applicable, add the following below this CDDL HEADER, with the
+ * fields enclosed by brackets "[]" replaced with your own identifying
+ * information: Portions Copyright [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.
+ */
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <unistd.h>
+#include <limits.h>
+#include <errno.h>
+#include <fcntl.h>
+#include <sys/types.h>
+#include <sys/fcntl.h>
+#include <sys/stat.h>
+#include <sys/statvfs.h>
+#include <sys/errno.h>
+#include <sys/time.h>
+#include <sys/ioctl.h>
+#include <sys/wait.h>
+#include <sys/param.h>
+#include <string.h>
+
+#define	FSIZE	256*1024*1024
+#define	BSIZE	512
+
+/* Initialize Globals */
+static long	fsize = FSIZE;
+static size_t	bsize = BSIZE;
+static int	count = 0;
+static int	rflag = 0;
+static int	seed = 0;
+static int	vflag = 0;
+static int	errflag = 0;
+static off_t	offset = 0;
+static char	*filename = NULL;
+
+static void usage(char *execname);
+static void parse_options(int argc, char *argv[]);
+static void do_write(int fd);
+static void do_trunc(int fd);
+
+static void
+usage(char *execname)
+{
+	(void) fprintf(stderr,
+	    "usage: %s [-b blocksize] [-c count] [-f filesize]"
+	    " [-o offset] [-s seed] [-r] [-v] filename\n", execname);
+	(void) exit(1);
+}
+
+int
+main(int argc, char *argv[])
+{
+	int i = 0;
+	int fd = -1;
+
+	parse_options(argc, argv);
+
+	fd = open(filename, O_RDWR|O_CREAT|O_TRUNC, 0666);
+	if (fd < 0) {
+		perror("open");
+		exit(3);
+	}
+
+	while (i < count) {
+		(void) do_write(fd);
+		(void) do_trunc(fd);
+
+		i++;
+	}
+
+	(void) close(fd);
+	return (0);
+}
+
+static void
+parse_options(int argc, char *argv[])
+{
+	int c;
+
+	extern char *optarg;
+	extern int optind, optopt;
+
+	count = fsize / bsize;
+	seed = time(NULL);
+	while ((c = getopt(argc, argv, "b:c:f:o:rs:v")) != -1) {
+		switch (c) {
+			case 'b':
+				bsize = atoi(optarg);
+				break;
+
+			case 'c':
+				count = atoi(optarg);
+				break;
+
+			case 'f':
+				fsize = atoi(optarg);
+				break;
+
+			case 'o':
+				offset = atoi(optarg);
+				break;
+
+			case 'r':
+				rflag++;
+				break;
+
+			case 's':
+				seed = atoi(optarg);
+				break;
+
+			case 'v':
+				vflag++;
+				break;
+
+			case ':':
+				(void) fprintf(stderr,
+				    "Option -%c requires an operand\n", optopt);
+				errflag++;
+				break;
+
+			case '?':
+				(void) fprintf(stderr,
+				    "Unrecognized option: -%c\n", optopt);
+				errflag++;
+				break;
+		}
+
+		if (errflag) {
+			(void) usage(argv[0]);
+		}
+	}
+	if (argc <= optind) {
+		(void) fprintf(stderr,
+		    "No filename specified\n");
+		usage(argv[0]);
+	}
+	filename = argv[optind];
+
+	if (vflag) {
+		(void) fprintf(stderr, "Seed = %d\n", seed);
+	}
+	srandom(seed);
+}
+
+static void
+do_write(int fd)
+{
+	off_t	roffset = 0;
+	char	*buf = NULL;
+	char	*rbuf = NULL;
+
+	buf = (char *)calloc(1, bsize);
+	rbuf = (char *)calloc(1, bsize);
+	if (buf == NULL || rbuf == NULL) {
+		perror("malloc");
+		exit(4);
+	}
+
+	roffset = random() % fsize;
+	if (lseek64(fd, (offset + roffset), SEEK_SET) < 0) {
+		perror("lseek");
+		exit(5);
+	}
+
+	buf = "ZFS Test Suite Truncation Test";
+	if (write(fd, buf, bsize) < bsize) {
+		perror("write");
+		exit(6);
+	}
+
+	if (rflag) {
+		if (lseek64(fd, (offset + roffset), SEEK_SET) < 0) {
+			perror("lseek");
+			exit(7);
+		}
+
+		if (read(fd, rbuf, bsize) < bsize) {
+			perror("read");
+			exit(8);
+		}
+
+		if (memcmp(buf, rbuf, bsize) != 0) {
+			perror("memcmp");
+			exit(9);
+		}
+	}
+	if (vflag) {
+		(void) fprintf(stderr,
+		    "Wrote to offset %lld\n", (offset + roffset));
+		if (rflag) {
+			(void) fprintf(stderr,
+			    "Read back from offset %lld\n", (offset + roffset));
+		}
+	}
+
+	(void) free(buf);
+	(void) free(rbuf);
+}
+
+static void
+do_trunc(int fd)
+{
+	off_t   roffset = 0;
+
+	roffset = random() % fsize;
+	if (ftruncate64(fd, (offset + roffset))  < 0) {
+		perror("truncate");
+		exit(7);
+	}
+
+	if (vflag) {
+		(void) fprintf(stderr,
+		    "Truncated at offset %lld\n",
+		    (offset + roffset));
+	}
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/usr/src/test/zfs-tests/cmd/file_write/Makefile	Wed Dec 05 22:04:50 2012 -0500
@@ -0,0 +1,19 @@
+#
+# 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) 2012 by Delphix. All rights reserved.
+#
+
+PROG = file_write
+
+include $(SRC)/cmd/Makefile.cmd
+include ../Makefile.subdirs
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/usr/src/test/zfs-tests/cmd/file_write/file_write.c	Wed Dec 05 22:04:50 2012 -0500
@@ -0,0 +1,231 @@
+/*
+ * CDDL HEADER START
+ *
+ * The contents of this file are subject to the terms of the
+ * Common Development and Distribution License (the "License").
+ * You may not use this file except in compliance with the License.
+ *
+ * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
+ * or http://www.opensolaris.org/os/licensing.
+ * See the License for the specific language governing permissions
+ * and limitations under the License.
+ *
+ * When distributing Covered Code, include this CDDL HEADER in each
+ * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
+ * If applicable, add the following below this CDDL HEADER, with the
+ * fields enclosed by brackets "[]" replaced with your own identifying
+ * information: Portions Copyright [yyyy] [name of copyright owner]
+ *
+ * CDDL HEADER END
+ */
+
+/*
+ * Copyright 2007 Sun Microsystems, Inc.  All rights reserved.
+ * Use is subject to license terms.
+ */
+
+#include "../file_common.h"
+#include <libgen.h>
+
+static unsigned char bigbuffer[BIGBUFFERSIZE];
+
+/*
+ * Writes (or appends) a given value to a file repeatedly.
+ * See header file for defaults.
+ */
+
+static void usage(void);
+
+int
+main(int argc, char **argv)
+{
+	int		bigfd;
+	int		c;
+	int		oflag = 0;
+	int		err = 0;
+	int		k;
+	long		i;
+	int64_t		good_writes = 0;
+	uchar_t		nxtfillchar;
+	/*
+	 * Default Parameters
+	 */
+	int		write_count = BIGFILESIZE;
+	uchar_t		fillchar = DATA;
+	int		block_size = BLOCKSZ;
+	char		*filename = NULL;
+	char		*operation = NULL;
+	offset_t	noffset, offset = 0;
+	int		verbose = 0;
+	int		rsync = 0;
+	int		wsync = 0;
+
+	/*
+	 * Process Arguments
+	 */
+	while ((c = getopt(argc, argv, "b:c:d:s:f:o:vwr")) != -1) {
+		switch (c) {
+			case 'b':
+				block_size = atoi(optarg);
+				break;
+			case 'c':
+				write_count = atoi(optarg);
+				break;
+			case 'd':
+				fillchar = atoi(optarg);
+				break;
+			case 's':
+				offset = atoll(optarg);
+				break;
+			case 'f':
+				filename = optarg;
+				break;
+			case 'o':
+				operation = optarg;
+				break;
+			case 'v':
+				verbose = 1;
+				break;
+			case 'w':
+				wsync = 1;
+				break;
+			case 'r':
+				rsync = 1;
+				break;
+			case '?':
+				(void) printf("unknown arg %c\n", optopt);
+				usage();
+				break;
+		}
+	}
+
+	/*
+	 * Validate Parameters
+	 */
+	if (!filename) {
+		(void) printf("Filename not specified (-f <file>)\n");
+		err++;
+	}
+
+	if (!operation) {
+		(void) printf("Operation not specified (-o <operation>).\n");
+		err++;
+	}
+
+	if (block_size > BIGBUFFERSIZE) {
+		(void) printf("block_size is too large max==%d.\n",
+		    BIGBUFFERSIZE);
+		err++;
+	}
+
+	if (err) usage();
+
+	/*
+	 * Prepare the buffer and determine the requested operation
+	 */
+	nxtfillchar = fillchar;
+	k = 0;
+
+	for (i = 0; i < block_size; i++) {
+		bigbuffer[i] = nxtfillchar;
+
+		if (fillchar == 0) {
+			if ((k % DATA_RANGE) == 0) {
+				k = 0;
+			}
+			nxtfillchar = k++;
+		}
+	}
+
+	/*
+	 * using the strncmp of operation will make the operation match the
+	 * first shortest match - as the operations are unique from the first
+	 * character this means that we match single character operations
+	 */
+	if ((strncmp(operation, "create", strlen(operation) + 1)) == 0 ||
+	    (strncmp(operation, "overwrite", strlen(operation) + 1)) == 0) {
+		oflag = (O_RDWR|O_CREAT);
+	} else if ((strncmp(operation, "append", strlen(operation) + 1)) == 0) {
+		oflag = (O_RDWR|O_APPEND);
+	} else {
+		(void) printf("valid operations are <create|append> not '%s'\n",
+		    operation);
+		usage();
+	}
+
+	if (rsync) {
+		oflag = oflag | O_RSYNC;
+	}
+
+	if (wsync) {
+		oflag = oflag | O_SYNC;
+	}
+
+	/*
+	 * Given an operation (create/overwrite/append), open the file
+	 * accordingly and perform a write of the appropriate type.
+	 */
+	if ((bigfd = open(filename, oflag, 0666)) == -1) {
+		(void) printf("open %s: failed [%s]%d. Aborting!\n", filename,
+		    strerror(errno), errno);
+		exit(errno);
+	}
+	noffset = llseek(bigfd, offset, SEEK_SET);
+	if (noffset != offset) {
+		(void) printf("llseek %s (%lld/%lld) failed [%s]%d.Aborting!\n",
+		    filename, offset, noffset, strerror(errno), errno);
+		exit(errno);
+	}
+
+	if (verbose) {
+		(void) printf("%s: block_size = %d, write_count = %d, "
+		    "offset = %lld, data = %s%d\n", filename, block_size,
+		    write_count, offset,
+		    (fillchar == 0) ? "0->" : "",
+		    (fillchar == 0) ? DATA_RANGE : fillchar);
+	}
+
+	for (i = 0; i < write_count; i++) {
+		ssize_t n;
+
+		if ((n = write(bigfd, &bigbuffer, block_size)) == -1) {
+			(void) printf("write failed (%ld), good_writes = %lld, "
+			    "error: %s[%d]\n", (long)n, good_writes,
+			    strerror(errno),
+			    errno);
+			exit(errno);
+		}
+		good_writes++;
+	}
+
+	if (verbose) {
+		(void) printf("Success: good_writes = %lld (%lld)\n",
+		    good_writes, (good_writes * block_size));
+	}
+
+	return (0);
+}
+
+static void
+usage(void)
+{
+	char *base = (char *)"file_write";
+	char *exec = (char *)getexecname();
+
+	if (exec != NULL)
+		exec = strdup(exec);
+	if (exec != NULL)
+		base = basename(exec);
+
+	(void) printf("Usage: %s [-v] -o {create,overwrite,append} -f file_name"
+	    " [-b block_size]\n"
+	    "\t[-s offset] [-c write_count] [-d data]\n"
+	    "\twhere [data] equal to zero causes chars "
+	    "0->%d to be repeated throughout\n", base, DATA_RANGE);
+
+	if (exec) {
+		free(exec);
+	}
+
+	exit(1);
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/usr/src/test/zfs-tests/cmd/largest_file/Makefile	Wed Dec 05 22:04:50 2012 -0500
@@ -0,0 +1,19 @@
+#
+# 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) 2012 by Delphix. All rights reserved.
+#
+
+PROG = largest_file
+
+include $(SRC)/cmd/Makefile.cmd
+include ../Makefile.subdirs
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/usr/src/test/zfs-tests/cmd/largest_file/largest_file.c	Wed Dec 05 22:04:50 2012 -0500
@@ -0,0 +1,134 @@
+/*
+ * CDDL HEADER START
+ *
+ * The contents of this file are subject to the terms of the
+ * Common Development and Distribution License (the "License").
+ * You may not use this file except in compliance with the License.
+ *
+ * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
+ * or http://www.opensolaris.org/os/licensing.
+ * See the License for the specific language governing permissions
+ * and limitations under the License.
+ *
+ * When distributing Covered Code, include this CDDL HEADER in each
+ * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
+ * If applicable, add the following below this CDDL HEADER, with the
+ * fields enclosed by brackets "[]" replaced with your own identifying
+ * information: Portions Copyright [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.
+ */
+
+#include "../file_common.h"
+#include <sys/param.h>
+#include <signal.h>
+#include <stdio.h>
+
+/*
+ * --------------------------------------------------------------
+ *
+ *	Assertion:
+ *		The last byte of the largest file size can be
+ *		accessed without any errors.  Also, the writing
+ *		beyond the last byte of the largest file size
+ *		will produce an errno of EFBIG.
+ *
+ * --------------------------------------------------------------
+ *	If the write() system call below returns a "1",
+ *	then the last byte can be accessed.
+ * --------------------------------------------------------------
+ */
+static void	sigxfsz(int);
+static void	usage(char *);
+
+int
+main(int argc, char **argv)
+{
+	int		fd = 0;
+	offset_t	offset = (MAXOFFSET_T - 1);
+	offset_t	llseek_ret = 0;
+	int		write_ret = 0;
+	int		err = 0;
+	char		mybuf[5];
+	char		*testfile;
+	mode_t		mode = S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH;
+
+	if (argc != 2) {
+		usage(argv[0]);
+	}
+
+	(void) sigset(SIGXFSZ, sigxfsz);
+
+	testfile = strdup(argv[1]);
+
+	fd = open(testfile, O_CREAT | O_RDWR, mode);
+	if (fd < 0) {
+		perror("Failed to create testfile");
+		err = errno;
+		goto out;
+	}
+
+	llseek_ret = llseek(fd, offset, SEEK_SET);
+	if (llseek_ret < 0) {
+		perror("Failed to seek to end of testfile");
+		err = errno;
+		goto out;
+	}
+
+	write_ret = write(fd, mybuf, 1);
+	if (write_ret < 0) {
+		perror("Failed to write to end of file");
+		err = errno;
+		goto out;
+	}
+
+	offset = 0;
+	llseek_ret = llseek(fd, offset, SEEK_CUR);
+	if (llseek_ret < 0) {
+		perror("Failed to seek to end of file");
+		err = errno;
+		goto out;
+	}
+
+	write_ret = write(fd, mybuf, 1);
+	if (write_ret < 0) {
+		if (errno == EFBIG) {
+			(void) printf("write errno=EFBIG: success\n");
+			err = 0;
+		} else {
+			perror("Did not receive EFBIG");
+			err = errno;
+		}
+	} else {
+		(void) printf("write completed successfully, test failed\n");
+		err = 1;
+	}
+
+out:
+	(void) unlink(testfile);
+	free(testfile);
+	return (err);
+}
+
+static void
+usage(char *name)
+{
+	(void) printf("%s <testfile>\n", name);
+	exit(1);
+}
+
+/* ARGSUSED */
+static void
+sigxfsz(int signo)
+{
+	(void) printf("\nlargest_file: sigxfsz() caught SIGXFSZ\n");
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/usr/src/test/zfs-tests/cmd/mkbusy/Makefile	Wed Dec 05 22:04:50 2012 -0500
@@ -0,0 +1,22 @@
+#
+# 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) 2012 by Delphix. All rights reserved.
+#
+
+PROG = mkbusy
+
+include $(SRC)/cmd/Makefile.cmd
+
+LINTFLAGS += -erroff=E_FUNC_SET_NOT_USED
+
+include ../Makefile.subdirs
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/usr/src/test/zfs-tests/cmd/mkbusy/mkbusy.c	Wed Dec 05 22:04:50 2012 -0500
@@ -0,0 +1,180 @@
+/*
+ * 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) 2012 by Delphix. All rights reserved.
+ */
+
+/*
+ * Make a directory busy. If the argument is an existing file or directory,
+ * simply open it directly and pause. If not, verify that the parent directory
+ * exists, and create a new file in that directory.
+ */
+
+#include <stdio.h>
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <fcntl.h>
+#include <dirent.h>
+#include <strings.h>
+#include <stdlib.h>
+#include <unistd.h>
+#include <errno.h>
+
+static void
+usage(char *progname)
+{
+	(void) fprintf(stderr, "Usage: %s <dirname|filename>\n", progname);
+	exit(1);
+}
+
+static void
+fail(char *err, int rval)
+{
+	perror(err);
+	exit(rval);
+}
+
+static void
+daemonize(void)
+{
+	pid_t	pid;
+
+	if ((pid = fork()) < 0) {
+		fail("fork", 1);
+	} else if (pid != 0) {
+		(void) fprintf(stdout, "%ld\n", pid);
+		exit(0);
+	}
+
+	(void) setsid();
+	(void) close(0);
+	(void) close(1);
+	(void) close(2);
+}
+
+int
+main(int argc, char *argv[])
+{
+	int		ret, c;
+	boolean_t	isdir = B_FALSE;
+	boolean_t	fflag = B_FALSE;
+	boolean_t	rflag = B_FALSE;
+	struct stat	sbuf;
+	char		*fpath = NULL;
+	char		*prog = argv[0];
+
+	while ((c = getopt(argc, argv, "fr")) != -1) {
+		switch (c) {
+		/* Open the file or directory read only */
+		case 'r':
+			rflag = B_TRUE;
+			break;
+		/* Run in the foreground */
+		case 'f':
+			fflag = B_TRUE;
+			break;
+		default:
+			usage(prog);
+		}
+	}
+
+	argc -= optind;
+	argv += optind;
+
+	if (argc != 1)
+		usage(prog);
+
+	if ((ret = stat(argv[0], &sbuf)) != 0) {
+		char	*arg, *dname, *fname;
+		int	arglen, dlen, flen;
+		char	*slash;
+
+		/*
+		 * The argument supplied doesn't exist. Copy the path, and
+		 * remove the trailing slash if presnt.
+		 */
+		if ((arg = strdup(argv[0])) == NULL)
+			fail("strdup", 1);
+		arglen = strlen(arg);
+		if (arg[arglen - 1] == '/')
+			arg[arglen - 1] = '\0';
+
+		/*
+		 * Get the directory and file names, using the current directory
+		 * if the provided path doesn't specify a directory at all.
+		 */
+		if ((slash = strrchr(arg, '/')) == NULL) {
+			dname = strdup(".");
+			fname = strdup(arg);
+		} else {
+			*slash = '\0';
+			dname = strdup(arg);
+			fname = strdup(slash + 1);
+		}
+		free(arg);
+		if (dname == NULL || fname == NULL)
+			fail("strdup", 1);
+		dlen = strlen(dname);
+		flen = strlen(fname);
+
+		/* The directory portion of the path must exist */
+		if ((ret = stat(dname, &sbuf)) != 0 || !(sbuf.st_mode &
+		    S_IFDIR))
+			usage(prog);
+
+		if ((fpath = (char *)malloc(dlen + 1 + flen + 1)) == NULL)
+			fail("malloc", 1);
+		(void) memset(fpath, '\0', dlen + 1 + flen + 1);
+
+		(void) strncpy(fpath, dname, dlen);
+		fpath[dlen] = '/';
+		(void) strncat(fpath, fname, flen);
+		free(dname);
+		free(fname);
+	} else if ((sbuf.st_mode & S_IFMT) == S_IFREG ||
+	    (sbuf.st_mode & S_IFMT) == S_IFLNK ||
+	    (sbuf.st_mode & S_IFMT) == S_IFCHR ||
+	    (sbuf.st_mode & S_IFMT) == S_IFBLK) {
+		fpath = strdup(argv[0]);
+	} else if ((sbuf.st_mode & S_IFMT) == S_IFDIR) {
+		fpath = strdup(argv[0]);
+		isdir = B_TRUE;
+	} else {
+		usage(prog);
+	}
+
+	if (fpath == NULL)
+		fail("strdup", 1);
+
+	if (isdir == B_FALSE) {
+		int	fd, flags;
+		mode_t	mode = S_IRUSR | S_IWUSR;
+
+		flags = rflag == B_FALSE ? O_CREAT | O_RDWR : O_RDONLY;
+
+		if ((fd = open(fpath, flags, mode)) < 0)
+			fail("open", 1);
+	} else {
+		DIR	*dp;
+
+		if ((dp = opendir(fpath)) == NULL)
+			fail("opendir", 1);
+	}
+	free(fpath);
+
+	if (fflag == B_FALSE)
+		daemonize();
+	(void) pause();
+
+	/* NOTREACHED */
+	return (0);
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/usr/src/test/zfs-tests/cmd/mktree/Makefile	Wed Dec 05 22:04:50 2012 -0500
@@ -0,0 +1,19 @@
+#
+# 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) 2012 by Delphix. All rights reserved.
+#
+
+PROG = mktree
+
+include $(SRC)/cmd/Makefile.cmd
+include ../Makefile.subdirs
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/usr/src/test/zfs-tests/cmd/mktree/mktree.c	Wed Dec 05 22:04:50 2012 -0500
@@ -0,0 +1,191 @@
+/*
+ * CDDL HEADER START
+ *
+ * The contents of this file are subject to the terms of the
+ * Common Development and Distribution License (the "License").
+ * You may not use this file except in compliance with the License.
+ *
+ * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
+ * or http://www.opensolaris.org/os/licensing.
+ * See the License for the specific language governing permissions
+ * and limitations under the License.
+ *
+ * When distributing Covered Code, include this CDDL HEADER in each
+ * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
+ * If applicable, add the following below this CDDL HEADER, with the
+ * fields enclosed by brackets "[]" replaced with your own identifying
+ * information: Portions Copyright [yyyy] [name of copyright owner]
+ *
+ * CDDL HEADER END
+ */
+
+/*
+ * Copyright 2007 Sun Microsystems, Inc.  All rights reserved.
+ * Use is subject to license terms.
+ */
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <unistd.h>
+#include <string.h>
+#include <fcntl.h>
+#include <sys/stat.h>
+#include <sys/types.h>
+#include <sys/errno.h>
+#include <sys/param.h>
+
+#define	TYPE_D 'D'
+#define	TYPE_F 'F'
+
+extern int errno;
+
+static char fdname[MAXPATHLEN] = {0};
+static char *pbasedir = NULL;
+static int nlevel = 2;
+static int ndir = 2;
+static int nfile = 2;
+
+static void  usage(char *this);
+static void  crtfile(char *pname);
+static char *getfdname(char *pdir, char type, int level, int dir, int file);
+static int   mktree(char *pbasedir, int level);
+
+int
+main(int argc, char *argv[])
+{
+	int c, ret;
+
+	while ((c = getopt(argc, argv, "b:l:d:f:")) != -1) {
+		switch (c) {
+		case 'b':
+			pbasedir = optarg;
+			break;
+		case 'l':
+			nlevel = atoi(optarg);
+			break;
+		case 'd':
+			ndir = atoi(optarg);
+			break;
+		case 'f':
+			nfile = atoi(optarg);
+			break;
+		case '?':
+			usage(argv[0]);
+		}
+	}
+	if (nlevel < 0 || ndir < 0 || nfile < 0 || pbasedir == NULL) {
+		usage(argv[0]);
+	}
+
+	ret = mktree(pbasedir, 1);
+
+	return (ret);
+}
+
+static void
+usage(char *this)
+{
+	(void) fprintf(stderr,
+	    "\tUsage: %s -b <base_dir> -l [nlevel] -d [ndir] -f [nfile]\n",
+	    this);
+	exit(1);
+}
+
+static int
+mktree(char *pdir, int level)
+{
+	int d, f;
+	char dname[MAXPATHLEN] = {0};
+	char fname[MAXPATHLEN] = {0};
+
+	if (level > nlevel) {
+		return (1);
+	}
+
+	for (d = 0; d < ndir; d++) {
+		(void) memset(dname, '\0', sizeof (dname));
+		(void) strcpy(dname, getfdname(pdir, TYPE_D, level, d, 0));
+
+		if (mkdir(dname, 0777) != 0) {
+			(void) fprintf(stderr, "mkdir(%s) failed."
+			    "\n[%d]: %s.\n",
+			    dname, errno, strerror(errno));
+			exit(errno);
+		}
+
+		/*
+		 * No sub-directory need be created, only create files in it.
+		 */
+		if (mktree(dname, level+1) != 0) {
+			for (f = 0; f < nfile; f++) {
+				(void) memset(fname, '\0', sizeof (fname));
+				(void) strcpy(fname,
+				    getfdname(dname, TYPE_F, level+1, d, f));
+				crtfile(fname);
+			}
+		}
+	}
+
+	for (f = 0; f < nfile; f++) {
+		(void) memset(fname, '\0', sizeof (fname));
+		(void) strcpy(fname, getfdname(pdir, TYPE_F, level, d, f));
+		crtfile(fname);
+	}
+
+	return (0);
+}
+
+static char *
+getfdname(char *pdir, char type, int level, int dir, int file)
+{
+	(void) snprintf(fdname, sizeof (fdname),
+	    "%s/%c-l%dd%df%d", pdir, type, level, dir, file);
+	return (fdname);
+}
+
+static void
+crtfile(char *pname)
+{
+	int fd = -1;
+	int afd = -1;
+	int i, size;
+	char *context = "0123456789ABCDF";
+	char *pbuf;
+
+	if (pname == NULL) {
+		exit(1);
+	}
+
+	size = sizeof (char) * 1024;
+	pbuf = (char *)valloc(size);
+	for (i = 0; i < size / strlen(context); i++) {
+		int offset = i * strlen(context);
+		(void) snprintf(pbuf+offset, size-offset, "%s", context);
+	}
+
+	if ((fd = open(pname, O_CREAT|O_RDWR, 0777)) < 0) {
+		(void) fprintf(stderr, "open(%s, O_CREAT|O_RDWR, 0777) failed."
+		    "\n[%d]: %s.\n", pname, errno, strerror(errno));
+		exit(errno);
+	}
+	if (write(fd, pbuf, 1024) < 1024) {
+		(void) fprintf(stderr, "write(fd, pbuf, 1024) failed."
+		    "\n[%d]: %s.\n", errno, strerror(errno));
+		exit(errno);
+	}
+
+	if ((afd = openat(fd, "xattr", O_CREAT | O_RDWR | O_XATTR, 0777)) < 0) {
+		(void) fprintf(stderr, "openat failed.\n[%d]: %s.\n",
+		    errno, strerror(errno));
+		exit(errno);
+	}
+	if (write(afd, pbuf, 1024) < 1024) {
+		(void) fprintf(stderr, "write(afd, pbuf, 1024) failed."
+		    "\n[%d]: %s.\n", errno, strerror(errno));
+		exit(errno);
+	}
+
+	(void) close(afd);
+	(void) close(fd);
+	free(pbuf);
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/usr/src/test/zfs-tests/cmd/mmapwrite/Makefile	Wed Dec 05 22:04:50 2012 -0500
@@ -0,0 +1,19 @@
+#
+# 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) 2012 by Delphix. All rights reserved.
+#
+
+PROG = mmapwrite
+
+include $(SRC)/cmd/Makefile.cmd
+include ../Makefile.subdirs
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/usr/src/test/zfs-tests/cmd/mmapwrite/mmapwrite.c	Wed Dec 05 22:04:50 2012 -0500
@@ -0,0 +1,95 @@
+/*
+ * CDDL HEADER START
+ *
+ * The contents of this file are subject to the terms of the
+ * Common Development and Distribution License (the "License").
+ * You may not use this file except in compliance with the License.
+ *
+ * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
+ * or http://www.opensolaris.org/os/licensing.
+ * See the License for the specific language governing permissions
+ * and limitations under the License.
+ *
+ * When distributing Covered Code, include this CDDL HEADER in each
+ * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
+ * If applicable, add the following below this CDDL HEADER, with the
+ * fields enclosed by brackets "[]" replaced with your own identifying
+ * information: Portions Copyright [yyyy] [name of copyright owner]
+ *
+ * CDDL HEADER END
+ */
+
+/*
+ * Copyright 2007 Sun Microsystems, Inc.  All rights reserved.
+ * Use is subject to license terms.
+ */
+
+#include <unistd.h>
+#include <fcntl.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <sys/mman.h>
+#include <pthread.h>
+
+/*
+ * --------------------------------------------------------------------
+ * Bug Id: 5032643
+ *
+ * Simply writing to a file and mmaping that file at the same time can
+ * result in deadlock.  Nothing perverse like writing from the file's
+ * own mapping is required.
+ * --------------------------------------------------------------------
+ */
+
+static void *
+mapper(void *fdp)
+{
+	void *addr;
+	int fd = *(int *)fdp;
+
+	if ((addr =
+	    mmap(0, 8192, PROT_READ, MAP_SHARED, fd, 0)) == MAP_FAILED) {
+		perror("mmap");
+		exit(1);
+	}
+	for (;;) {
+		if (mmap(addr, 8192, PROT_READ,
+		    MAP_SHARED|MAP_FIXED, fd, 0) == MAP_FAILED) {
+			perror("mmap");
+			exit(1);
+		}
+	}
+	/* NOTREACHED */
+	return ((void *)1);
+}
+
+int
+main(int argc, char **argv)
+{
+	int fd;
+	char buf[BUFSIZ];
+
+	if (argc != 2) {
+		(void) printf("usage: %s <file name>\n", argv[0]);
+		exit(1);
+	}
+
+	if ((fd = open(argv[1], O_RDWR|O_CREAT|O_TRUNC, 0666)) == -1) {
+		perror("open");
+		exit(1);
+	}
+
+	if (pthread_create(NULL, NULL, mapper, &fd) != 0) {
+		perror("pthread_create");
+		exit(1);
+	}
+	for (;;) {
+		if (write(fd, buf, sizeof (buf)) == -1) {
+			perror("write");
+			exit(1);
+		}
+	}
+
+	/* NOTREACHED */
+	return (0);
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/usr/src/test/zfs-tests/cmd/randfree_file/Makefile	Wed Dec 05 22:04:50 2012 -0500
@@ -0,0 +1,19 @@
+#
+# 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) 2012 by Delphix. All rights reserved.
+#
+
+PROG = randfree_file
+
+include $(SRC)/cmd/Makefile.cmd
+include ../Makefile.subdirs
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/usr/src/test/zfs-tests/cmd/randfree_file/randfree_file.c	Wed Dec 05 22:04:50 2012 -0500
@@ -0,0 +1,103 @@
+/*
+ * CDDL HEADER START
+ *
+ * The contents of this file are subject to the terms of the
+ * Common Development and Distribution License (the "License").
+ * You may not use this file except in compliance with the License.
+ *
+ * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
+ * or http://www.opensolaris.org/os/licensing.
+ * See the License for the specific language governing permissions
+ * and limitations under the License.
+ *
+ * When distributing Covered Code, include this CDDL HEADER in each
+ * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
+ * If applicable, add the following below this CDDL HEADER, with the
+ * fields enclosed by brackets "[]" replaced with your own identifying
+ * information: Portions Copyright [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.
+ */
+
+#include "../file_common.h"
+
+/*
+ * Create a file with assigned size and then free the specified
+ * section of the file
+ */
+
+static void usage(char *progname);
+
+static void
+usage(char *progname)
+{
+	(void) fprintf(stderr,
+	    "usage: %s [-l filesize] [-s start-offset]"
+	    "[-n section-len] filename\n", progname);
+	exit(1);
+}
+
+int
+main(int argc, char *argv[])
+{
+	char *filename = NULL;
+	char *buf;
+	size_t filesize = 0;
+	off_t start_off = 0;
+	off_t off_len = 0;
+	int  fd, ch;
+	struct flock fl;
+	mode_t mode = S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH;
+
+	while ((ch = getopt(argc, argv, "l:s:n:")) != EOF) {
+		switch (ch) {
+		case 'l':
+			filesize = atoll(optarg);
+			break;
+		case 's':
+			start_off = atoll(optarg);
+			break;
+		case 'n':
+			off_len = atoll(optarg);
+			break;
+		default:
+			usage(argv[0]);
+			break;
+		}
+	}
+
+	if (optind == argc - 1)
+		filename = argv[optind];
+	else
+		usage(argv[0]);
+
+	buf = (char *)malloc(filesize);
+
+	if ((fd = open(filename, O_RDWR | O_CREAT | O_TRUNC, mode)) < 0) {
+		perror("open");
+		return (1);
+	}
+	if (write(fd, buf, filesize) < filesize) {
+		perror("write");
+		return (1);
+	}
+	fl.l_whence = SEEK_SET;
+	fl.l_start = start_off;
+	fl.l_len = off_len;
+	if (fcntl(fd, F_FREESP, &fl) != 0) {
+		perror("fcntl");
+		return (1);
+	}
+
+	free(buf);
+	return (0);
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/usr/src/test/zfs-tests/cmd/readmmap/Makefile	Wed Dec 05 22:04:50 2012 -0500
@@ -0,0 +1,19 @@
+#
+# 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) 2012 by Delphix. All rights reserved.
+#
+
+PROG = readmmap
+
+include $(SRC)/cmd/Makefile.cmd
+include ../Makefile.subdirs
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/usr/src/test/zfs-tests/cmd/readmmap/readmmap.c	Wed Dec 05 22:04:50 2012 -0500
@@ -0,0 +1,137 @@
+/*
+ * CDDL HEADER START
+ *
+ * The contents of this file are subject to the terms of the
+ * Common Development and Distribution License (the "License").
+ * You may not use this file except in compliance with the License.
+ *
+ * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
+ * or http://www.opensolaris.org/os/licensing.
+ * See the License for the specific language governing permissions
+ * and limitations under the License.
+ *
+ * When distributing Covered Code, include this CDDL HEADER in each
+ * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
+ * If applicable, add the following below this CDDL HEADER, with the
+ * fields enclosed by brackets "[]" replaced with your own identifying
+ * information: Portions Copyright [yyyy] [name of copyright owner]
+ *
+ * CDDL HEADER END
+ */
+
+/*
+ * Copyright 2007 Sun Microsystems, Inc.  All rights reserved.
+ * Use is subject to license terms.
+ */
+
+/*
+ * --------------------------------------------------------------
+ *	BugId 5047993 : Getting bad read data.
+ *
+ *	Usage: readmmap <filename>
+ *
+ *	where:
+ *		filename is an absolute path to the file name.
+ *
+ *	Return values:
+ *		1 : error
+ *		0 : no errors
+ * --------------------------------------------------------------
+ */
+#include <stdio.h>
+#include <stdlib.h>
+#include <unistd.h>
+#include <fcntl.h>
+#include <errno.h>
+#include <sys/mman.h>
+
+int
+main(int argc, char **argv)
+{
+	char *filename = "badfile";
+	size_t size = 4395;
+	size_t idx = 0;
+	char *buf = NULL;
+	char *map = NULL;
+	int fd = -1, bytes, retval = 0;
+	unsigned seed;
+
+	if (argc < 2 || optind == argc) {
+		(void) fprintf(stderr,
+		    "usage: %s <file name>\n", argv[0]);
+		exit(1);
+	}
+
+	if ((buf = calloc(1, size)) == NULL) {
+		perror("calloc");
+		exit(1);
+	}
+
+	filename = argv[optind];
+
+	(void) remove(filename);
+
+	fd = open(filename, O_RDWR|O_CREAT|O_TRUNC, 0666);
+	if (fd == -1) {
+		perror("open to create");
+		retval = 1;
+		goto end;
+	}
+
+	bytes = write(fd, buf, size);
+	if (bytes != size) {
+		(void) printf("short write: %d != %ud\n", bytes, size);
+		retval = 1;
+		goto end;
+	}
+
+	map = mmap(0, size, PROT_READ|PROT_WRITE, MAP_SHARED, fd, 0);
+	if (map == MAP_FAILED) {
+		perror("mmap");
+		retval = 1;
+		goto end;
+	}
+	seed = time(NULL);
+	srandom(seed);
+
+	idx = random() % size;
+	map[idx] = 1;
+
+	if (msync(map, size, MS_SYNC) != 0) {
+		perror("msync");
+		retval = 1;
+		goto end;
+	}
+
+	if (munmap(map, size) != 0) {
+		perror("munmap");
+		retval = 1;
+		goto end;
+	}
+
+	bytes = pread(fd, buf, size, 0);
+	if (bytes != size) {
+		(void) printf("short read: %d != %ud\n", bytes, size);
+		retval = 1;
+		goto end;
+	}
+
+	if (buf[idx] != 1) {
+		(void) printf(
+		    "bad data from read!  got buf[%ud]=%d, expected 1\n",
+		    idx, buf[idx]);
+		retval = 1;
+		goto end;
+	}
+
+	(void) printf("good data from read: buf[%ud]=1\n", idx);
+end:
+	if (fd != -1) {
+		(void) close(fd);
+	}
+	if (buf != NULL) {
+		free(buf);
+	}
+
+	return (retval);
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/usr/src/test/zfs-tests/cmd/rename_dir/Makefile	Wed Dec 05 22:04:50 2012 -0500
@@ -0,0 +1,19 @@
+#
+# 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) 2012 by Delphix. All rights reserved.
+#
+
+PROG = rename_dir
+
+include $(SRC)/cmd/Makefile.cmd
+include ../Makefile.subdirs
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/usr/src/test/zfs-tests/cmd/rename_dir/rename_dir.c	Wed Dec 05 22:04:50 2012 -0500
@@ -0,0 +1,88 @@
+/*
+ * CDDL HEADER START
+ *
+ * The contents of this file are subject to the terms of the
+ * Common Development and Distribution License (the "License").
+ * You may not use this file except in compliance with the License.
+ *
+ * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
+ * or http://www.opensolaris.org/os/licensing.
+ * See the License for the specific language governing permissions
+ * and limitations under the License.
+ *
+ * When distributing Covered Code, include this CDDL HEADER in each
+ * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
+ * If applicable, add the following below this CDDL HEADER, with the
+ * fields enclosed by brackets "[]" replaced with your own identifying
+ * information: Portions Copyright [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.
+ */
+
+/*
+ * Assertion:
+ * Create two directory trees in zfs filesystem, and rename
+ * directory across the directory structure. ZFS can handle
+ * the race situation.
+ */
+
+/*
+ * Need to create the following directory structures before
+ * running this program:
+ *
+ * mkdir -p 1/2/3/4/5 a/b/c/d/e
+ */
+
+
+#include <stdlib.h>
+#include <unistd.h>
+#include <stdio.h>
+#include <strings.h>
+
+int
+main()
+{
+	int i = 1;
+
+	switch (fork()) {
+	case -1:
+		perror("fork");
+		exit(1);
+		break;
+	case 0:
+		while (i > 0) {
+			int c_count = 0;
+			if (rename("a/b/c", "1/2/3/c") == 0)
+				c_count++;
+			if (rename("1/2/3/c", "a/b/c") == 0)
+				c_count++;
+			if (c_count) {
+				(void) fprintf(stderr, "c_count: %d", c_count);
+			}
+		}
+		break;
+	default:
+		while (i > 0) {
+			int p_count = 0;
+			if (rename("1", "a/b/c/d/e/1") == 0)
+				p_count++;
+			if (rename("a/b/c/d/e/1", "1") == 0)
+				p_count++;
+			if (p_count) {
+				(void) fprintf(stderr, "p_count: %d", p_count);
+			}
+		}
+		break;
+	}
+
+	return (0);
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/usr/src/test/zfs-tests/cmd/rm_lnkcnt_zero_file/Makefile	Wed Dec 05 22:04:50 2012 -0500
@@ -0,0 +1,19 @@
+#
+# 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) 2012 by Delphix. All rights reserved.
+#
+
+PROG = rm_lnkcnt_zero_file
+
+include $(SRC)/cmd/Makefile.cmd
+include ../Makefile.subdirs
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/usr/src/test/zfs-tests/cmd/rm_lnkcnt_zero_file/rm_lnkcnt_zero_file.c	Wed Dec 05 22:04:50 2012 -0500
@@ -0,0 +1,152 @@
+/*
+ * CDDL HEADER START
+ *
+ * The contents of this file are subject to the terms of the
+ * Common Development and Distribution License (the "License").
+ * You may not use this file except in compliance with the License.
+ *
+ * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
+ * or http://www.opensolaris.org/os/licensing.
+ * See the License for the specific language governing permissions
+ * and limitations under the License.
+ *
+ * When distributing Covered Code, include this CDDL HEADER in each
+ * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
+ * If applicable, add the following below this CDDL HEADER, with the
+ * fields enclosed by brackets "[]" replaced with your own identifying
+ * information: Portions Copyright [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.
+ */
+
+/*
+ * --------------------------------------------------------------------
+ * The purpose of this test is to see if the bug reported (#4723351) for
+ * UFS exists when using a ZFS file system.
+ * --------------------------------------------------------------------
+ *
+ */
+#define	_REENTRANT 1
+#include <stdio.h>
+#include <fcntl.h>
+#include <pthread.h>
+#include <thread.h>
+#include <errno.h>
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <stdlib.h>
+#include <unistd.h>
+#include <strings.h>
+
+static const int TRUE = 1;
+static char *filebase;
+
+static int
+pickidx()
+{
+	return (random() % 1000);
+}
+
+/* ARGSUSED */
+static void *
+mover(void *a)
+{
+	char buf[256];
+	int idx, len, ret;
+
+	len = strlen(filebase) + 5;
+
+	while (TRUE) {
+		idx = pickidx();
+		(void) snprintf(buf, len, "%s.%03d", filebase, idx);
+		ret = rename(filebase, buf);
+		if (ret < 0 && errno != ENOENT)
+			(void) perror("renaming file");
+	}
+
+	return (NULL);
+}
+
+/* ARGSUSED */
+static void *
+cleaner(void *a)
+{
+	char buf[256];
+	int idx, len, ret;
+
+	len = strlen(filebase) + 5;
+
+	while (TRUE) {
+		idx = pickidx();
+		(void) snprintf(buf, len, "%s.%03d", filebase, idx);
+		ret = remove(buf);
+		if (ret < 0 && errno != ENOENT)
+			(void) perror("removing file");
+	}
+
+	return (NULL);
+}
+
+static void *
+writer(void *a)
+{
+	int *fd = (int *)a;
+
+	while (TRUE) {
+		(void) close (*fd);
+		*fd = open(filebase, O_APPEND | O_RDWR | O_CREAT, 0644);
+		if (*fd < 0)
+			perror("refreshing file");
+		(void) write(*fd, "test\n", 5);
+	}
+
+	return (NULL);
+}
+
+int
+main(int argc, char **argv)
+{
+	int fd;
+	pthread_t tid;
+
+	if (argc == 1) {
+		(void) printf("Usage: %s <filebase>\n", argv[0]);
+		exit(-1);
+	}
+
+	filebase = argv[1];
+	fd = open(filebase, O_APPEND | O_RDWR | O_CREAT, 0644);
+	if (fd < 0) {
+		perror("creating test file");
+		exit(-1);
+	}
+
+	(void) thr_setconcurrency(4);	/* 3 threads + main */
+	(void) pthread_create(&tid, NULL, mover, NULL);
+	(void) pthread_create(&tid, NULL, cleaner, NULL);
+	(void) pthread_create(&tid, NULL, writer, (void *) &fd);
+
+	while (TRUE) {
+		int ret;
+		struct stat st;
+
+		ret = stat(filebase, &st);
+		if (ret == 0 && (st.st_nlink > 2 || st.st_nlink < 1)) {
+			(void) printf("st.st_nlink = %d, exiting\n", \
+			    (int)st.st_nlink);
+			exit(0);
+		}
+		(void) sleep(1);
+	}
+
+	return (0);
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/usr/src/test/zfs-tests/cmd/scripts/Makefile	Wed Dec 05 22:04:50 2012 -0500
@@ -0,0 +1,36 @@
+#
+# 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) 2012 by Delphix. All rights reserved.
+#
+
+include $(SRC)/Makefile.master
+
+ROOTOPTPKG = $(ROOT)/opt/zfs-tests
+ROOTBIN = $(ROOTOPTPKG)/bin
+
+PROGS = zfstest
+
+CMDS = $(PROGS:%=$(ROOTBIN)/%)
+$(CMDS) := FILEMODE = 0555
+
+all lint clean clobber:
+
+install: $(CMDS)
+
+$(CMDS): $(ROOTBIN)
+
+$(ROOTBIN):
+	$(INS.dir)
+
+$(ROOTBIN)/%: %.ksh
+	$(INS.rename)
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/usr/src/test/zfs-tests/cmd/scripts/zfstest.ksh	Wed Dec 05 22:04:50 2012 -0500
@@ -0,0 +1,133 @@
+#!/usr/bin/ksh
+
+#
+# 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) 2012 by Delphix. All rights reserved.
+#
+
+export STF_SUITE="/opt/zfs-tests"
+export STF_TOOLS="/opt/test-runner/stf"
+runner="/opt/test-runner/bin/run"
+auto_detect=false
+
+function fail
+{
+	echo $1
+	exit ${2:-1}
+}
+
+function find_disks
+{
+	typeset all_disks=$(echo '' | sudo /usr/sbin/format | awk \
+	    '/c[0-9]/ {print $2}')
+	typeset used_disks=$(/sbin/zpool status | awk \
+	    '/c[0-9]*t[0-9a-f]*d[0-9]/ {print $1}' | sed 's/s[0-9]//g')
+
+	typeset disk used avail_disks
+	for disk in $all_disks; do
+		for used in $used_disks; do
+			[[ "$disk" = "$used" ]] && continue 2
+		done
+		[[ -n $avail_disks ]] && avail_disks="$avail_disks $disk"
+		[[ -z $avail_disks ]] && avail_disks="$disk"
+	done
+
+	echo $avail_disks
+}
+
+function find_rpool
+{
+	typeset ds=$(/usr/sbin/mount | awk '/^\/ / {print $3}')
+	echo ${ds%%/*}
+}
+
+function find_runfile
+{
+	typeset distro=
+	if [[ -d /opt/delphix && -h /etc/delphix/version ]]; then
+		distro=delphix
+	elif [[ 0 -ne $(grep -c OpenIndiana /etc/release 2>/dev/null) ]]; then
+		distro=openindiana
+	fi
+
+	[[ -n $distro ]] && echo $STF_SUITE/runfiles/$distro.run
+}
+
+function verify_id
+{
+	[[ $(id -u) = "0" ]] && fail "This script must not be run as root."
+
+	sudo -n id >/dev/null 2>&1
+	[[ $? -eq 0 ]] || fail "User must be able to sudo without a password."
+
+	typeset -i priv_cnt=$(ppriv $$ | egrep -v \
+	    ": basic$|	L:| <none>|$$:" | wc -l)
+	[[ $priv_cnt -ne 0 ]] && fail "User must only have basic privileges."
+}
+
+function verify_disks
+{
+	typeset disk
+	for disk in $DISKS; do
+		sudo /usr/sbin/prtvtoc /dev/rdsk/${disk}s0 >/dev/null 2>&1
+		[[ $? -eq 0 ]] || return 1
+	done
+	return 0
+}
+
+verify_id
+
+while getopts ac:q c; do
+	case $c in
+	'a')
+		auto_detect=true
+		;;
+	'c')
+		runfile=$OPTARG
+		[[ -f $runfile ]] || fail "Cannot read file: $runfile"
+		;;
+	'q')
+		quiet='-q'
+		;;
+	esac
+done
+shift $((OPTIND - 1))
+
+# If the user specified -a, then use free disks, otherwise use those in $DISKS.
+if $auto_detect; then
+	export DISKS=$(find_disks)
+elif [[ -z $DISKS ]]; then
+	fail "\$DISKS not set in env, and -a not specified."
+else
+	verify_disks || fail "Couldn't verify all the disks in \$DISKS"
+fi
+
+# Add the rpool to $KEEP according to its contents. It's ok to list it twice.
+if [[ -z $KEEP ]]; then
+	export KEEP="^$(find_rpool)\$"
+else
+	export KEEP="^$(echo $KEEP | sed 's/ /|$/')\$"
+	KEEP+="|^$(find_rpool)\$"
+fi
+
+[[ -z $runfile ]] && runfile=$(find_runfile)
+[[ -z $runfile ]] && fail "Couldn't determine distro"
+
+. $STF_SUITE/include/default.cfg
+
+num_disks=$(echo $DISKS | awk '{print NF}')
+[[ $num_disks -lt 3 ]] && fail "Not enough disks to run ZFS Test Suite"
+
+$runner $quiet -c $runfile
+
+exit $?
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/usr/src/test/zfs-tests/doc/Makefile	Wed Dec 05 22:04:50 2012 -0500
@@ -0,0 +1,35 @@
+#
+# 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) 2012 by Delphix. All rights reserved.
+#
+
+include $(SRC)/Makefile.master
+
+READMES = README
+
+ROOTOPTPKG = $(ROOT)/opt/zfs-tests
+
+FILES = $(READMES:%=$(ROOTOPTPKG)/%)
+$(FILES) := FILEMODE = 0444
+
+all: $(READMES)
+
+install: $(ROOTOPTPKG) $(FILES)
+
+clean lint clobber:
+
+$(ROOTOPTPKG):
+	$(INS.dir)
+
+$(ROOTOPTPKG)/%: %
+	$(INS.file)
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/usr/src/test/zfs-tests/doc/README	Wed Dec 05 22:04:50 2012 -0500
@@ -0,0 +1,77 @@
+#
+# 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) 2012 by Delphix. All rights reserved.
+#
+
+ZFS Test Suite README
+
+1. Building and installing the ZFS Test Suite
+2. Running the ZFS Test Suite
+3. Test results
+
+--------------------------------------------------------------------------------
+
+1. Building and installing the ZFS Test Suite
+
+The ZFS Test Suite runs under the testrunner framework (which can be installed
+as pkg:/system/test/testrunner). To build both the ZFS Test Suite and the
+testrunner without running a full nightly:
+
+	build_machine$ bldenv [-d] <your_env_file>
+	build_machine$ cd $SRC/test
+	build_machine$ dmake install
+	build_machine$ cd $SRC/pkg
+	build_machine$ dmake install
+
+Then set the publisher on the test machine to point to your repository and
+install the ZFS Test Suite.
+
+	test_machine# pkg install pkg:/system/test/zfstest
+
+Note, the framework will be installed automatically, as the ZFS Test Suite
+depends on it.
+
+2. Running the ZFS Test Suite
+
+The pre-requisites for running the ZFS Test Suite are:
+	- Three scratch disks
+	  - Specify the disks you wish to use in the $DISKS variable, as a
+	    space delimited list like this: DISKS='c3t1d0 c3t2d0 c3t3d0'
+	  - Use the '-a' option to the zfstest script and all unused disks on
+	    the system are eligible. With '-a' specified, $DISKS is ignored.
+	- A non-root user with the full set of basic privileges and the ability
+	  to sudo(1M) to root without a password to run the test.
+	- Specify any pools you wish to preserve as a space delimited list in
+	  the $KEEP variable. The root pool is added automatically.
+
+Once the pre-requisites are satisfied, simply run the zfstest script:
+
+	test_machine$ /opt/zfs-tests/bin/zfstest [-aq]
+
+When the '-q' option is specified, it is passed to run(1) which causes output
+to be written to the console only for tests that do not pass and the results
+summary. 
+
+The ZFS Test Suite allows the user to specify a subset of the tests via a
+runfile. The format of the runfile is explained in run(1), and the files that
+zfstest uses are available for reference under /opt/zfs-tests/runfiles. To
+specify a custom runfile, use the -c option:
+
+	test_machine$ /opt/zfs-tests/bin/zfstest [-aq] -c my_tests.run
+
+3. Test results
+
+While the ZFS Test Suite is running, one informational line is printed at the
+end of each test, and a results summary is printed at the end of the run. The
+results summary includes the location of the complete logs, which is of the
+form /var/tmp/test_results/<ISO 8601 date>.
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/usr/src/test/zfs-tests/include/Makefile	Wed Dec 05 22:04:50 2012 -0500
@@ -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) 2012 by Delphix. All rights reserved.
+#
+
+include $(SRC)/test/Makefile.com
+
+include $(SRC)/Makefile.master
+
+SRCS = commands.cfg \
+	default.cfg \
+	libtest.shlib \
+	math.shlib \
+	properties.shlib
+
+ROOTOPTPKG = $(ROOT)/opt/zfs-tests
+INCLUDEDIR = $(ROOTOPTPKG)/include
+
+CMDS = $(SRCS:%=$(INCLUDEDIR)/%)
+$(CMDS) := FILEMODE = 0555
+
+all: $(SRCS)
+
+install: $(CMDS)
+
+clean lint clobber:
+
+$(CMDS): $(INCLUDEDIR) $(SRCS)
+
+$(INCLUDEDIR):
+	$(INS.dir)
+
+$(INCLUDEDIR)/%: %
+	$(INS.file)
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/usr/src/test/zfs-tests/include/commands.cfg	Wed Dec 05 22:04:50 2012 -0500
@@ -0,0 +1,161 @@
+#
+# 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) 2012 by Delphix. All rights reserved.
+#
+
+export ARP="/usr/sbin/arp"
+export AWK="/usr/bin/awk"
+export BASENAME="/usr/bin/basename"
+export BC="/usr/bin/bc"
+export BUNZIP2="/usr/bin/bunzip2"
+export BZCAT="/usr/bin/bzcat"
+# bzip2, bunzip2 and bzcat prepend the contents of $BZIP2 or $BZIP to any
+# arguments. Setting BZIP2 here will lead to hard-to-diagnose unhappiness.
+export CAT="/usr/bin/cat"
+export CD="/usr/bin/cd"
+export CHGRP="/usr/bin/chgrp"
+export CHMOD="/usr/bin/chmod"
+export CHOWN="/usr/bin/chown"
+export CKSUM="/usr/bin/cksum"
+export CLRI="/usr/sbin/clri"
+export CMP="/usr/bin/cmp"
+export COMPRESS="/usr/bin/compress"
+export COREADM="/usr/bin/coreadm"
+export CP="/usr/bin/cp"
+export CPIO="/usr/bin/cpio"
+export CUT="/usr/bin/cut"
+export DATE="/usr/bin/date"
+export DD="/usr/bin/dd"
+export DEVFSADM="/usr/sbin/devfsadm"
+export DF="/usr/bin/df"
+export DIFF="/usr/bin/diff"
+export DIRCMP="/usr/bin/dircmp"
+export DIRNAME="/usr/bin/dirname"
+export DU="/usr/bin/du"
+export DUMPADM="/usr/sbin/dumpadm"
+export ECHO="/usr/bin/echo"
+export EGREP="/usr/bin/egrep"
+# Don't use $ENV here, because in ksh scripts it evaluates to
+# $HOME/.kshrc - likely not what you wanted.
+export FDISK="/usr/sbin/fdisk"
+export FF="/usr/sbin/ff"
+export FGREP="/usr/bin/fgrep"
+export FILE="/usr/bin/file"
+export FIND="/usr/bin/find"
+export FMADM="/usr/sbin/fmadm"
+export FMDUMP="/usr/sbin/fmdump"
+export FORMAT="/usr/sbin/format"
+export FSCK="/usr/sbin/fsck"
+export FSDB="/usr/sbin/fsdb"
+export FSIRAND="/usr/sbin/fsirand"
+export FSTYP="/usr/sbin/fstyp"
+export GETENT="/usr/bin/getent"
+export GETMAJOR="/usr/sbin/getmajor"
+export GNUDD="/usr/gnu/bin/dd"
+export GREP="/usr/bin/grep"
+export GROUPADD="/usr/sbin/groupadd"
+export GROUPDEL="/usr/sbin/groupdel"
+export GROUPMOD="/usr/sbin/groupmod"
+export GROUPS="/usr/bin/groups"
+export HEAD="/usr/bin/head"
+export HOSTNAME="/usr/bin/hostname"
+export ID="/usr/bin/id"
+export ISAINFO="/usr/bin/isainfo"
+export ISCSIADM="/usr/sbin/iscsiadm"
+export KILL="/usr/bin/kill"
+export KSH="/usr/bin/ksh"
+export KSTAT="/usr/bin/kstat"
+export LABELIT="/usr/sbin/labelit"
+export LOCKFS="/usr/sbin/lockfs"
+export LOFIADM="/usr/sbin/lofiadm"
+export LOGNAME="/usr/bin/logname"
+export LS="/usr/bin/ls"
+export MD5SUM="/usr/bin/md5sum"
+export MDB="/usr/bin/mdb"
+export METACLEAR="/usr/sbin/metaclear"
+export METADB="/usr/sbin/metadb"
+export METAINIT="/usr/sbin/metainit"
+export METASTAT="/usr/sbin/metastat"
+export MKDIR="/usr/bin/mkdir"
+export MKFILE="/usr/sbin/mkfile"
+export MKNOD="/usr/sbin/mknod"
+export MODINFO="/usr/sbin/modinfo"
+export MODUNLOAD="/usr/sbin/modunload"
+export MOUNT="/usr/sbin/mount"
+export MV="/usr/bin/mv"
+export NAWK="/usr/bin/nawk"
+export NCHECK="/usr/sbin/ncheck"
+export NEWFS="/usr/sbin/newfs"
+export PACK="/usr/bin/pack"
+export PAGESIZE="/usr/bin/pagesize"
+export PAX="/usr/bin/pax"
+export PFEXEC="/usr/bin/pfexec"
+export PGREP="/usr/bin/pgrep"
+export PING="/usr/sbin/ping"
+export PKGINFO="/usr/bin/pkginfo"
+export PKILL="/usr/bin/pkill"
+export PPRIV="/usr/bin/ppriv"
+export PRINTF="/usr/bin/printf"
+export PRTVTOC="/usr/sbin/prtvtoc"
+export PS="/usr/bin/ps"
+export PSRINFO="/usr/sbin/psrinfo"
+export PWD="/usr/bin/pwd"
+export PYTHON="/usr/bin/python"
+export QUOTAON="/usr/sbin/quotaon"
+export RCP="/usr/bin/rcp"
+export REBOOT="/usr/sbin/reboot"
+export RM="/usr/bin/rm"
+export RMDIR="/usr/bin/rmdir"
+export RSH="/usr/bin/rsh"
+export RUNAT="/usr/bin/runat"
+export SED="/usr/bin/sed"
+export SHARE="/usr/sbin/share"
+export SHUF="/usr/bin/shuf"
+export SLEEP="/usr/bin/sleep"
+export SORT="/usr/bin/sort"
+export STRINGS="/usr/bin/strings"
+export SU="/usr/bin/su"
+export SUM="/usr/bin/sum"
+export SVCADM="/usr/sbin/svcadm"
+export SVCS="/usr/bin/svcs"
+export SWAP="/usr/sbin/swap"
+export SWAPADD="/sbin/swapadd"
+export SYNC="/usr/bin/sync"
+export TAIL="/usr/bin/tail"
+export TAR="/usr/sbin/tar"
+export TOUCH="/usr/bin/touch"
+export TR="/usr/bin/tr"
+export TRUE="/usr/bin/true"
+export TUNEFS="/usr/sbin/tunefs"
+export UFSDUMP="/usr/sbin/ufsdump"
+export UFSRESTORE="/usr/sbin/ufsrestore"
+export UMASK="/usr/bin/umask"
+export UMOUNT="/usr/sbin/umount"
+export UNAME="/usr/bin/uname"
+export UNCOMPRESS="/usr/bin/uncompress"
+export UNIQ="/usr/bin/uniq"
+export UNPACK="/usr/bin/unpack"
+export UNSHARE="/usr/sbin/unshare"
+export USERADD="/usr/sbin/useradd"
+export USERDEL="/usr/sbin/userdel"
+export USERMOD="/usr/sbin/usermod"
+export WAIT="/usr/bin/wait"
+export WC="/usr/bin/wc"
+export ZDB="/usr/sbin/zdb"
+export ZFS="/usr/sbin/zfs"
+export ZHACK="/usr/sbin/zhack"
+export ZLOGIN="/usr/sbin/zlogin"
+export ZONEADM="/usr/sbin/zoneadm"
+export ZONECFG="/usr/sbin/zonecfg"
+export ZONENAME="/usr/bin/zonename"
+export ZPOOL="/usr/sbin/zpool"
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/usr/src/test/zfs-tests/include/default.cfg	Wed Dec 05 22:04:50 2012 -0500
@@ -0,0 +1,149 @@
+#
+# CDDL HEADER START
+#
+# The contents of this file are subject to the terms of the
+# Common Development and Distribution License (the "License").
+# You may not use this file except in compliance with the License.
+#
+# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
+# or http://www.opensolaris.org/os/licensing.
+# See the License for the specific language governing permissions
+# and limitations under the License.
+#
+# When distributing Covered Code, include this CDDL HEADER in each
+# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
+# If applicable, add the following below this CDDL 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.
+#
+
+. $STF_SUITE/include/commands.cfg
+. $STF_SUITE/include/libtest.shlib
+
+# Define run length constants
+export RT_LONG="3"
+export RT_MEDIUM="2"
+export RT_SHORT="1"
+
+# Define macro for zone test
+export ZONE_POOL="zonepool"
+export ZONE_CTR="zonectr"
+
+# Test Suite Specific Commands
+export CHG_USR_EXEC="/opt/zfs-tests/bin/chg_usr_exec"
+export DEVNAME2DEVID="/opt/zfs-tests/bin/devname2devid"
+export DIR_RD_UPDATE="/opt/zfs-tests/bin/dir_rd_update"
+export FILE_CHECK="/opt/zfs-tests/bin/file_check"
+export FILE_TRUNC="/opt/zfs-tests/bin/file_trunc"
+export FILE_WRITE="/opt/zfs-tests/bin/file_write"
+export LARGEST_FILE="/opt/zfs-tests/bin/largest_file"
+export MKBUSY="/opt/zfs-tests/bin/mkbusy"
+export MKTREE="/opt/zfs-tests/bin/mktree"
+export MMAPWRITE="/opt/zfs-tests/bin/mmapwrite"
+export RANDFREE_FILE="/opt/zfs-tests/bin/randfree_file"
+export READMMAP="/opt/zfs-tests/bin/readmmap"
+export RENAME_DIR="/opt/zfs-tests/bin/rename_dir"
+export RM_LNKCNT_ZERO_FILE="/opt/zfs-tests/bin/rm_lnkcnt_zero_file"
+
+# ensure we're running in the C locale, since
+# localised messages may result in test failures
+export LC_ALL="C"
+export LANG="C"
+
+#
+# pattern to ignore from 'zpool list'.
+#
+export NO_POOLS="no pools available"
+
+# pattern to ignore from 'zfs list'.
+export NO_DATASETS="no datasets available"
+
+export TEST_BASE_DIR="/"
+
+# Default to compression ON
+export COMPRESSION_PROP=on
+
+# Default to using the checksum
+export CHECKSUM_PROP=on
+
+# some common variables used by test scripts :
+
+# some test pool names
+export TESTPOOL=testpool.$$
+export TESTPOOL1=testpool1.$$
+export TESTPOOL2=testpool2.$$
+export TESTPOOL3=testpool3.$$
+
+# some test file system names
+export TESTFS=testfs.$$
+export TESTFS1=testfs1.$$
+export TESTFS2=testfs2.$$
+export TESTFS3=testfs3.$$
+
+# some test directory names
+export TESTDIR=${TEST_BASE_DIR%%/}/testdir$$
+export TESTDIR0=${TEST_BASE_DIR%%/}/testdir0$$
+export TESTDIR1=${TEST_BASE_DIR%%/}/testdir1$$
+export TESTDIR2=${TEST_BASE_DIR%%/}/testdir2$$
+
+export ZFSROOT=
+
+export TESTSNAP=testsnap$$
+export TESTSNAP1=testsnap1$$
+export TESTSNAP2=testsnap2$$
+export TESTCLONE=testclone$$
+export TESTCLONE1=testclone1$$
+export TESTCLONE2=testclone2$$
+export TESTCLCT=testclct$$
+export TESTCTR=testctr$$
+export TESTCTR1=testctr1$$
+export TESTCTR2=testctr2$$
+export TESTVOL=testvol$$
+export TESTVOL1=testvol1$$
+export TESTVOL2=testvol2$$
+export TESTFILE0=testfile0.$$
+export TESTFILE1=testfile1.$$
+export TESTFILE2=testfile2.$$
+
+export LONGPNAME="poolname50charslong_012345678901234567890123456789"
+export LONGFSNAME="fsysname50charslong_012345678901234567890123456789"
+export SNAPFS="$TESTPOOL/$TESTFS@$TESTSNAP"
+export SNAPFS1="$TESTPOOL/$TESTVOL@$TESTSNAP"
+
+export VOLSIZE=150m
+export BIGVOLSIZE=1eb
+
+# Default to limit disks to be checked
+export MAX_FINDDISKSNUM=6
+
+# For iscsi target support
+export ISCSITGTFILE=/tmp/iscsitgt_file
+export ISCSITGT_FMRI=svc:/system/iscsitgt:default
+
+export AUTO_SNAP=$($SVCS -a | $GREP auto-snapshot | $GREP online | $AWK \
+    '{print $3}')
+
+#
+# finally, if we're running in a local zone
+# we take some additional actions
+if ! is_global_zone; then
+	reexport_pool
+fi
+
+export ZFS_VERSION=5
+export ZFS_ALL_VERSIONS="1 2 3 4 5"
+
+for i in $ZFS_ALL_VERSIONS; do
+	eval 'export ZFS_VERSION_$i="v${i}-fs"'
+done
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/usr/src/test/zfs-tests/include/libtest.shlib	Wed Dec 05 22:04:50 2012 -0500
@@ -0,0 +1,2571 @@
+#
+# CDDL HEADER START
+#
+# The contents of this file are subject to the terms of the
+# Common Development and Distribution License (the "License").
+# You may not use this file except in compliance with the License.
+#
+# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
+# or http://www.opensolaris.org/os/licensing.
+# See the License for the specific language governing permissions
+# and limitations under the License.
+#
+# When distributing Covered Code, include this CDDL HEADER in each
+# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
+# If applicable, add the following below this CDDL 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) 2012 by Delphix. All rights reserved.
+#
+
+. ${STF_TOOLS}/contrib/include/logapi.shlib
+
+ZFS=${ZFS:-/usr/sbin/zfs}
+ZPOOL=${ZPOOL:-/usr/sbin/zpool}
+
+# Determine whether a dataset is mounted
+#
+# $1 dataset name
+# $2 filesystem type; optional - defaulted to zfs
+#
+# Return 0 if dataset is mounted; 1 if unmounted; 2 on error
+
+function ismounted
+{
+	typeset fstype=$2
+	[[ -z $fstype ]] && fstype=zfs
+	typeset out dir name ret
+
+	case $fstype in
+		zfs)
+			if [[ "$1" == "/"* ]] ; then
+				for out in $($ZFS mount | $AWK '{print $2}'); do
+					[[ $1 == $out ]] && return 0
+				done
+			else
+				for out in $($ZFS mount | $AWK '{print $1}'); do
+					[[ $1 == $out ]] && return 0
+				done
+			fi
+		;;
+		ufs|nfs)
+			out=$($DF -F $fstype $1 2>/dev/null)
+			ret=$?
+			(($ret != 0)) && return $ret
+
+			dir=${out%%\(*}
+			dir=${dir%% *}
+			name=${out##*\(}
+			name=${name%%\)*}
+			name=${name%% *}
+
+			[[ "$1" == "$dir" || "$1" == "$name" ]] && return 0
+		;;
+	esac
+
+	return 1
+}
+
+# Return 0 if a dataset is mounted; 1 otherwise
+#
+# $1 dataset name
+# $2 filesystem type; optional - defaulted to zfs
+
+function mounted
+{
+	ismounted $1 $2
+	(($? == 0)) && return 0
+	return 1
+}
+
+# Return 0 if a dataset is unmounted; 1 otherwise
+#
+# $1 dataset name
+# $2 filesystem type; optional - defaulted to zfs
+
+function unmounted
+{
+	ismounted $1 $2
+	(($? == 1)) && return 0
+	return 1
+}
+
+# split line on ","
+#
+# $1 - line to split
+
+function splitline
+{
+	$ECHO $1 | $SED "s/,/ /g"
+}
+
+function default_setup
+{
+	default_setup_noexit "$@"
+
+	log_pass
+}
+
+#
+# Given a list of disks, setup storage pools and datasets.
+#
+function default_setup_noexit
+{
+	typeset disklist=$1
+	typeset container=$2
+	typeset volume=$3
+
+	if is_global_zone; then
+		if poolexists $TESTPOOL ; then
+			destroy_pool $TESTPOOL
+		fi
+		[[ -d /$TESTPOOL ]] && $RM -rf /$TESTPOOL
+		log_must $ZPOOL create -f $TESTPOOL $disklist
+	else
+		reexport_pool
+	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
+
+	if [[ -n $container ]]; then
+		$RM -rf $TESTDIR1  || \
+			log_unresolved Could not remove $TESTDIR1
+		$MKDIR -p $TESTDIR1 || \
+			log_unresolved Could not create $TESTDIR1
+
+		log_must $ZFS create $TESTPOOL/$TESTCTR
+		log_must $ZFS set canmount=off $TESTPOOL/$TESTCTR
+		log_must $ZFS create $TESTPOOL/$TESTCTR/$TESTFS1
+		log_must $ZFS set mountpoint=$TESTDIR1 \
+		    $TESTPOOL/$TESTCTR/$TESTFS1
+	fi
+
+	if [[ -n $volume ]]; then
+		if is_global_zone ; then
+			log_must $ZFS create -V $VOLSIZE $TESTPOOL/$TESTVOL
+		else
+			log_must $ZFS create $TESTPOOL/$TESTVOL
+		fi
+	fi
+}
+
+#
+# Given a list of disks, setup a storage pool, file system and
+# a container.
+#
+function default_container_setup
+{
+	typeset disklist=$1
+
+	default_setup "$disklist" "true"
+}
+
+#
+# Given a list of disks, setup a storage pool,file system
+# and a volume.
+#
+function default_volume_setup
+{
+	typeset disklist=$1
+
+	default_setup "$disklist" "" "true"
+}
+
+#
+# Given a list of disks, setup a storage pool,file system,
+# a container and a volume.
+#
+function default_container_volume_setup
+{
+	typeset disklist=$1
+
+	default_setup "$disklist" "true" "true"
+}
+
+#
+# Create a snapshot on a filesystem or volume. Defaultly create a snapshot on
+# filesystem
+#
+# $1 Existing filesystem or volume name. Default, $TESTFS
+# $2 snapshot name. Default, $TESTSNAP
+#
+function create_snapshot
+{
+	typeset fs_vol=${1:-$TESTFS}
+	typeset snap=${2:-$TESTSNAP}
+
+	[[ -z $fs_vol ]] && log_fail "Filesystem or volume's name is undefined."
+	[[ -z $snap ]] && log_fail "Snapshot's name is undefined."
+
+	if snapexists $fs_vol@$snap; then
+		log_fail "$fs_vol@$snap already exists."
+	fi
+	datasetexists $fs_vol || \
+		log_fail "$fs_vol must exist."
+
+	log_must $ZFS snapshot $fs_vol@$snap
+}
+
+#
+# Create a clone from a snapshot, default clone name is $TESTCLONE.
+#
+# $1 Existing snapshot, $TESTPOOL/$TESTFS@$TESTSNAP is default.
+# $2 Clone name, $TESTPOOL/$TESTCLONE is default.
+#
+function create_clone   # snapshot clone
+{
+	typeset snap=${1:-$TESTPOOL/$TESTFS@$TESTSNAP}
+	typeset clone=${2:-$TESTPOOL/$TESTCLONE}
+
+	[[ -z $snap ]] && \
+		log_fail "Snapshot name is undefined."
+	[[ -z $clone ]] && \
+		log_fail "Clone name is undefined."
+
+	log_must $ZFS clone $snap $clone
+}
+
+function default_mirror_setup
+{
+	default_mirror_setup_noexit $1 $2 $3
+
+	log_pass
+}
+
+#
+# Given a pair of disks, set up a storage pool and dataset for the mirror
+# @parameters: $1 the primary side of the mirror
+#   $2 the secondary side of the mirror
+# @uses: ZPOOL ZFS TESTPOOL TESTFS
+function default_mirror_setup_noexit
+{
+	readonly func="default_mirror_setup_noexit"
+	typeset primary=$1
+	typeset secondary=$2
+
+	[[ -z $primary ]] && \
+		log_fail "$func: No parameters passed"
+	[[ -z $secondary ]] && \
+		log_fail "$func: No secondary partition passed"
+	[[ -d /$TESTPOOL ]] && $RM -rf /$TESTPOOL
+	log_must $ZPOOL create -f $TESTPOOL mirror $@
+	log_must $ZFS create $TESTPOOL/$TESTFS
+	log_must $ZFS set mountpoint=$TESTDIR $TESTPOOL/$TESTFS
+}
+
+#
+# create a number of mirrors.
+# We create a number($1) of 2 way mirrors using the pairs of disks named
+# on the command line. These mirrors are *not* mounted
+# @parameters: $1 the number of mirrors to create
+#  $... the devices to use to create the mirrors on
+# @uses: ZPOOL ZFS TESTPOOL
+function setup_mirrors
+{
+	typeset -i nmirrors=$1
+
+	shift
+	while ((nmirrors > 0)); do
+		log_must test -n "$1" -a -n "$2"
+		[[ -d /$TESTPOOL$nmirrors ]] && $RM -rf /$TESTPOOL$nmirrors
+		log_must $ZPOOL create -f $TESTPOOL$nmirrors mirror $1 $2
+		shift 2
+		((nmirrors = nmirrors - 1))
+	done
+}
+
+#
+# create a number of raidz pools.
+# We create a number($1) of 2 raidz pools  using the pairs of disks named
+# on the command line. These pools are *not* mounted
+# @parameters: $1 the number of pools to create
+#  $... the devices to use to create the pools on
+# @uses: ZPOOL ZFS TESTPOOL
+function setup_raidzs
+{
+	typeset -i nraidzs=$1
+
+	shift
+	while ((nraidzs > 0)); do
+		log_must test -n "$1" -a -n "$2"
+		[[ -d /$TESTPOOL$nraidzs ]] && $RM -rf /$TESTPOOL$nraidzs
+		log_must $ZPOOL create -f $TESTPOOL$nraidzs raidz $1 $2
+		shift 2
+		((nraidzs = nraidzs - 1))
+	done
+}
+
+#
+# Destroy the configured testpool mirrors.
+# the mirrors are of the form ${TESTPOOL}{number}
+# @uses: ZPOOL ZFS TESTPOOL
+function destroy_mirrors
+{
+	default_cleanup_noexit
+
+	log_pass
+}
+
+#
+# Given a minimum of two disks, set up a storage pool and dataset for the raid-z
+# $1 the list of disks
+#
+function default_raidz_setup
+{
+	typeset disklist="$*"
+	disks=(${disklist[*]})
+
+	if [[ ${#disks[*]} -lt 2 ]]; then
+		log_fail "A raid-z requires a minimum of two disks."
+	fi
+
+	[[ -d /$TESTPOOL ]] && $RM -rf /$TESTPOOL
+	log_must $ZPOOL create -f $TESTPOOL raidz $1 $2 $3
+	log_must $ZFS create $TESTPOOL/$TESTFS
+	log_must $ZFS set mountpoint=$TESTDIR $TESTPOOL/$TESTFS
+
+	log_pass
+}
+
+#
+# Common function used to cleanup storage pools and datasets.
+#
+# Invoked at the start of the test suite to ensure the system
+# is in a known state, and also at the end of each set of
+# sub-tests to ensure errors from one set of tests doesn't
+# impact the execution of the next set.
+
+function default_cleanup
+{
+	default_cleanup_noexit
+
+	log_pass
+}
+
+function default_cleanup_noexit
+{
+	typeset exclude=""
+	typeset pool=""
+	#
+	# Destroying the pool will also destroy any
+	# filesystems it contains.
+	#
+	if is_global_zone; then
+		$ZFS unmount -a > /dev/null 2>&1
+		exclude=`eval $ECHO \"'(${KEEP})'\"`
+		ALL_POOLS=$($ZPOOL list -H -o name \
+		    | $GREP -v "$NO_POOLS" | $EGREP -v "$exclude")
+		# Here, we loop through the pools we're allowed to
+		# destroy, only destroying them if it's safe to do
+		# so.
+		while [ ! -z ${ALL_POOLS} ]
+		do
+			for pool in ${ALL_POOLS}
+			do
+				if safe_to_destroy_pool $pool ;
+				then
+					destroy_pool $pool
+				fi
+				ALL_POOLS=$($ZPOOL list -H -o name \
+				    | $GREP -v "$NO_POOLS" \
+				    | $EGREP -v "$exclude")
+			done
+		done
+
+		$ZFS mount -a
+	else
+		typeset fs=""
+		for fs in $($ZFS list -H -o name \
+		    | $GREP "^$ZONE_POOL/$ZONE_CTR[01234]/"); do
+			datasetexists $fs && \
+				log_must $ZFS destroy -Rf $fs
+		done
+
+		# Need cleanup here to avoid garbage dir left.
+		for fs in $($ZFS list -H -o name); do
+			[[ $fs == /$ZONE_POOL ]] && continue
+			[[ -d $fs ]] && log_must $RM -rf $fs/*
+		done
+
+		#
+		# Reset the $ZONE_POOL/$ZONE_CTR[01234] file systems property to
+		# the default value
+		#
+		for fs in $($ZFS list -H -o name); do
+			if [[ $fs == $ZONE_POOL/$ZONE_CTR[01234] ]]; then
+				log_must $ZFS set reservation=none $fs
+				log_must $ZFS set recordsize=128K $fs
+				log_must $ZFS set mountpoint=/$fs $fs
+				typeset enc=""
+				enc=$(get_prop encryption $fs)
+				if [[ $? -ne 0 ]] || [[ -z "$enc" ]] || \
+					[[ "$enc" == "off" ]]; then
+					log_must $ZFS set checksum=on $fs
+				fi
+				log_must $ZFS set compression=off $fs
+				log_must $ZFS set atime=on $fs
+				log_must $ZFS set devices=off $fs
+				log_must $ZFS set exec=on $fs
+				log_must $ZFS set setuid=on $fs
+				log_must $ZFS set readonly=off $fs
+				log_must $ZFS set snapdir=hidden $fs
+				log_must $ZFS set aclmode=groupmask $fs
+				log_must $ZFS set aclinherit=secure $fs
+			fi
+		done
+	fi
+
+	[[ -d $TESTDIR ]] && \
+		log_must $RM -rf $TESTDIR
+}
+
+
+#
+# Common function used to cleanup storage pools, file systems
+# and containers.
+#
+function default_container_cleanup
+{
+	if ! is_global_zone; then
+		reexport_pool
+	fi
+
+	ismounted $TESTPOOL/$TESTCTR/$TESTFS1
+	[[ $? -eq 0 ]] && \
+	    log_must $ZFS unmount $TESTPOOL/$TESTCTR/$TESTFS1
+
+	datasetexists $TESTPOOL/$TESTCTR/$TESTFS1 && \
+	    log_must $ZFS destroy -R $TESTPOOL/$TESTCTR/$TESTFS1
+
+	datasetexists $TESTPOOL/$TESTCTR && \
+	    log_must $ZFS destroy -Rf $TESTPOOL/$TESTCTR
+
+	[[ -e $TESTDIR1 ]] && \
+	    log_must $RM -rf $TESTDIR1 > /dev/null 2>&1
+
+	default_cleanup
+}
+
+#
+# Common function used to cleanup snapshot of file system or volume. Default to
+# delete the file system's snapshot
+#
+# $1 snapshot name
+#
+function destroy_snapshot
+{
+	typeset snap=${1:-$TESTPOOL/$TESTFS@$TESTSNAP}
+
+	if ! snapexists $snap; then
+		log_fail "'$snap' does not existed."
+	fi
+
+	#
+	# For the sake of the value which come from 'get_prop' is not equal
+	# to the really mountpoint when the snapshot is unmounted. So, firstly
+	# check and make sure this snapshot's been mounted in current system.
+	#
+	typeset mtpt=""
+	if ismounted $snap; then
+		mtpt=$(get_prop mountpoint $snap)
+		(($? != 0)) && \
+			log_fail "get_prop mountpoint $snap failed."
+	fi
+
+	log_must $ZFS destroy $snap
+	[[ $mtpt != "" && -d $mtpt ]] && \
+		log_must $RM -rf $mtpt
+}
+
+#
+# Common function used to cleanup clone.
+#
+# $1 clone name
+#
+function destroy_clone
+{
+	typeset clone=${1:-$TESTPOOL/$TESTCLONE}
+
+	if ! datasetexists $clone; then
+		log_fail "'$clone' does not existed."
+	fi
+
+	# With the same reason in destroy_snapshot
+	typeset mtpt=""
+	if ismounted $clone; then
+		mtpt=$(get_prop mountpoint $clone)
+		(($? != 0)) && \
+			log_fail "get_prop mountpoint $clone failed."
+	fi
+
+	log_must $ZFS destroy $clone
+	[[ $mtpt != "" && -d $mtpt ]] && \
+		log_must $RM -rf $mtpt
+}
+
+# Return 0 if a snapshot exists; $? otherwise
+#
+# $1 - snapshot name
+
+function snapexists
+{
+	$ZFS list -H -t snapshot "$1" > /dev/null 2>&1
+	return $?
+}
+
+#
+# Set a property to a certain value on a dataset.
+# Sets a property of the dataset to the value as passed in.
+# @param:
+#	$1 dataset who's property is being set
+#	$2 property to set
+#	$3 value to set property to
+# @return:
+#	0 if the property could be set.
+#	non-zero otherwise.
+# @use: ZFS
+#
+function dataset_setprop
+{
+	typeset fn=dataset_setprop
+
+	if (($# < 3)); then
+		log_note "$fn: Insufficient parameters (need 3, had $#)"
+		return 1
+	fi
+	typeset output=
+	output=$($ZFS set $2=$3 $1 2>&1)
+	typeset rv=$?
+	if ((rv != 0)); then
+		log_note "Setting property on $1 failed."
+		log_note "property $2=$3"
+		log_note "Return Code: $rv"
+		log_note "Output: $output"
+		return $rv
+	fi
+	return 0
+}
+
+#
+# Assign suite defined dataset properties.
+# This function is used to apply the suite's defined default set of
+# properties to a dataset.
+# @parameters: $1 dataset to use
+# @uses: ZFS COMPRESSION_PROP CHECKSUM_PROP
+# @returns:
+#   0 if the dataset has been altered.
+#   1 if no pool name was passed in.
+#   2 if the dataset could not be found.
+#   3 if the dataset could not have it's properties set.
+#
+function dataset_set_defaultproperties
+{
+	typeset dataset="$1"
+
+	[[ -z $dataset ]] && return 1
+
+	typeset confset=
+	typeset -i found=0
+	for confset in $($ZFS list); do
+		if [[ $dataset = $confset ]]; then
+			found=1
+			break
+		fi
+	done
+	[[ $found -eq 0 ]] && return 2
+	if [[ -n $COMPRESSION_PROP ]]; then
+		dataset_setprop $dataset compression $COMPRESSION_PROP || \
+			return 3
+		log_note "Compression set to '$COMPRESSION_PROP' on $dataset"
+	fi
+	if [[ -n $CHECKSUM_PROP ]]; then
+		dataset_setprop $dataset checksum $CHECKSUM_PROP || \
+			return 3
+		log_note "Checksum set to '$CHECKSUM_PROP' on $dataset"
+	fi
+	return 0
+}
+
+#
+# Check a numeric assertion
+# @parameter: $@ the assertion to check
+# @output: big loud notice if assertion failed
+# @use: log_fail
+#
+function assert
+{
+	(($@)) || log_fail "$@"
+}
+
+#
+# Function to format partition size of a disk
+# Given a disk cxtxdx reduces all partitions
+# to 0 size
+#
+function zero_partitions #<whole_disk_name>
+{
+	typeset diskname=$1
+	typeset i
+
+	for i in 0 1 3 4 5 6 7
+	do
+		set_partition $i "" 0mb $diskname
+	done
+}
+
+#
+# Given a slice, size and disk, this function
+# formats the slice to the specified size.
+# Size should be specified with units as per
+# the `format` command requirements eg. 100mb 3gb
+#
+function set_partition #<slice_num> <slice_start> <size_plus_units>  <whole_disk_name>
+{
+	typeset -i slicenum=$1
+	typeset start=$2
+	typeset size=$3
+	typeset disk=$4
+	[[ -z $slicenum || -z $size || -z $disk ]] && \
+	    log_fail "The slice, size or disk name is unspecified."
+	typeset format_file=/var/tmp/format_in.$$
+
+	$ECHO "partition" >$format_file
+	$ECHO "$slicenum" >> $format_file
+	$ECHO "" >> $format_file
+	$ECHO "" >> $format_file
+	$ECHO "$start" >> $format_file
+	$ECHO "$size" >> $format_file
+	$ECHO "label" >> $format_file
+	$ECHO "" >> $format_file
+	$ECHO "q" >> $format_file
+	$ECHO "q" >> $format_file
+
+	$FORMAT -e -s -d $disk -f $format_file
+	typeset ret_val=$?
+	$RM -f $format_file
+	[[ $ret_val -ne 0 ]] && \
+	    log_fail "Unable to format $disk slice $slicenum to $size"
+	return 0
+}
+
+#
+# Get the end cyl of the given slice
+#
+function get_endslice #<disk> <slice>
+{
+	typeset disk=$1
+	typeset slice=$2
+	if [[ -z $disk || -z $slice ]] ; then
+		log_fail "The disk name or slice number is unspecified."
+	fi
+
+	disk=${disk#/dev/dsk/}
+	disk=${disk#/dev/rdsk/}
+	disk=${disk%s*}
+
+	typeset -i ratio=0
+	ratio=$($PRTVTOC /dev/rdsk/${disk}s2 | \
+		$GREP "sectors\/cylinder" | \
+		$AWK '{print $2}')
+
+	if ((ratio == 0)); then
+		return
+	fi
+
+	typeset -i endcyl=$($PRTVTOC -h /dev/rdsk/${disk}s2 |
+		$NAWK -v token="$slice" '{if ($1==token) print $6}')
+
+	((endcyl = (endcyl + 1) / ratio))
+	echo $endcyl
+}
+
+
+#
+# Given a size,disk and total slice number,  this function formats the
+# disk slices from 0 to the total slice number with the same specified
+# size.
+#
+function partition_disk	#<slice_size> <whole_disk_name>	<total_slices>
+{
+	typeset -i i=0
+	typeset slice_size=$1
+	typeset disk_name=$2
+	typeset total_slices=$3
+	typeset cyl
+
+	zero_partitions $disk_name
+	while ((i < $total_slices)); do
+		if ((i == 2)); then
+			((i = i + 1))
+			continue
+		fi
+		set_partition $i "$cyl" $slice_size $disk_name
+		cyl=$(get_endslice $disk_name $i)
+		((i = i+1))
+	done
+}
+
+#
+# This function continues to write to a filenum number of files into dirnum
+# number of directories until either $FILE_WRITE returns an error or the
+# maximum number of files per directory have been written.
+#
+# Usage:
+# fill_fs [destdir] [dirnum] [filenum] [bytes] [num_writes] [data]
+#
+# Return value: 0 on success
+#		non 0 on error
+#
+# Where :
+#	destdir:    is the directory where everything is to be created under
+#	dirnum:	    the maximum number of subdirectories to use, -1 no limit
+#	filenum:    the maximum number of files per subdirectory
+#	bytes:	    number of bytes to write
+#	num_writes: numer of types to write out bytes
+#	data:	    the data that will be writen
+#
+#	E.g.
+#	file_fs /testdir 20 25 1024 256 0
+#
+# Note: bytes * num_writes equals the size of the testfile
+#
+function fill_fs # destdir dirnum filenum bytes num_writes data
+{
+	typeset destdir=${1:-$TESTDIR}
+	typeset -i dirnum=${2:-50}
+	typeset -i filenum=${3:-50}
+	typeset -i bytes=${4:-8192}
+	typeset -i num_writes=${5:-10240}
+	typeset -i data=${6:-0}
+
+	typeset -i odirnum=1
+	typeset -i idirnum=0
+	typeset -i fn=0
+	typeset -i retval=0
+
+	log_must $MKDIR -p $destdir/$idirnum
+	while (($odirnum > 0)); do
+		if ((dirnum >= 0 && idirnum >= dirnum)); then
+			odirnum=0
+			break
+		fi
+		$FILE_WRITE -o create -f $destdir/$idirnum/$TESTFILE.$fn \
+		    -b $bytes -c $num_writes -d $data
+		retval=$?
+		if (($retval != 0)); then
+			odirnum=0
+			break
+		fi
+		if (($fn >= $filenum)); then
+			fn=0
+			((idirnum = idirnum + 1))
+			log_must $MKDIR -p $destdir/$idirnum
+		else
+			((fn = fn + 1))
+		fi
+	done
+	return $retval
+}
+
+#
+# Simple function to get the specified property. If unable to
+# get the property then exits.
+#
+# Note property is in 'parsable' format (-p)
+#
+function get_prop # property dataset
+{
+	typeset prop_val
+	typeset prop=$1
+	typeset dataset=$2
+
+	prop_val=$($ZFS get -pH -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
+}
+
+#
+# Simple function to get the specified property of pool. If unable to
+# get the property then exits.
+#
+function get_pool_prop # property pool
+{
+	typeset prop_val
+	typeset prop=$1
+	typeset pool=$2
+
+	if poolexists $pool ; then
+		prop_val=$($ZPOOL get $prop $pool 2>/dev/null | $TAIL -1 | \
+			$AWK '{print $3}')
+		if [[ $? -ne 0 ]]; then
+			log_note "Unable to get $prop property for pool " \
+			"$pool"
+			return 1
+		fi
+	else
+		log_note "Pool $pool not exists."
+		return 1
+	fi
+
+	$ECHO $prop_val
+	return 0
+}
+
+# Return 0 if a pool exists; $? otherwise
+#
+# $1 - pool name
+
+function poolexists
+{
+	typeset pool=$1
+
+	if [[ -z $pool ]]; then
+		log_note "No pool name given."
+		return 1
+	fi
+
+	$ZPOOL get name "$pool" > /dev/null 2>&1
+	return $?
+}
+
+# Return 0 if all the specified datasets exist; $? otherwise
+#
+# $1-n  dataset name
+function datasetexists
+{
+	if (($# == 0)); then
+		log_note "No dataset name given."
+		return 1
+	fi
+
+	while (($# > 0)); do
+		$ZFS get name $1 > /dev/null 2>&1 || \
+			return $?
+		shift
+	done
+
+	return 0
+}
+
+# return 0 if none of the specified datasets exists, otherwise return 1.
+#
+# $1-n  dataset name
+function datasetnonexists
+{
+	if (($# == 0)); then
+		log_note "No dataset name given."
+		return 1
+	fi
+
+	while (($# > 0)); do
+		$ZFS list -H -t filesystem,snapshot,volume $1 > /dev/null 2>&1 \
+		    && return 1
+		shift
+	done
+
+	return 0
+}
+
+#
+# Given a mountpoint, or a dataset name, determine if it is shared.
+#
+# Returns 0 if shared, 1 otherwise.
+#
+function is_shared
+{
+	typeset fs=$1
+	typeset mtpt
+
+	if [[ $fs != "/"* ]] ; then
+		if datasetnonexists "$fs" ; then
+			return 1
+		else
+			mtpt=$(get_prop mountpoint "$fs")
+			case $mtpt in
+				none|legacy|-) return 1
+					;;
+				*)	fs=$mtpt
+					;;
+			esac
+		fi
+	fi
+
+	for mtpt in `$SHARE | $AWK '{print $2}'` ; do
+		if [[ $mtpt == $fs ]] ; then
+			return 0
+		fi
+	done
+
+	typeset stat=$($SVCS -H -o STA nfs/server:default)
+	if [[ $stat != "ON" ]]; then
+		log_note "Current nfs/server status: $stat"
+	fi
+
+	return 1
+}
+
+#
+# Given a mountpoint, determine if it is not shared.
+#
+# Returns 0 if not shared, 1 otherwise.
+#
+function not_shared
+{
+	typeset fs=$1
+
+	is_shared $fs
+	if (($? == 0)); then
+		return 1
+	fi
+
+	return 0
+}
+
+#
+# Helper function to unshare a mountpoint.
+#
+function unshare_fs #fs
+{
+	typeset fs=$1
+
+	is_shared $fs
+	if (($? == 0)); then
+		log_must $ZFS unshare $fs
+	fi
+
+	return 0
+}
+
+#
+# Check NFS server status and trigger it online.
+#
+function setup_nfs_server
+{
+	# Cannot share directory in non-global zone.
+	#
+	if ! is_global_zone; then
+		log_note "Cannot trigger NFS server by sharing in LZ."
+		return
+	fi
+
+	typeset nfs_fmri="svc:/network/nfs/server:default"
+	if [[ $($SVCS -Ho STA $nfs_fmri) != "ON" ]]; then
+		#
+		# Only really sharing operation can enable NFS server
+		# to online permanently.
+		#
+		typeset dummy=/tmp/dummy
+
+		if [[ -d $dummy ]]; then
+			log_must $RM -rf $dummy
+		fi
+
+		log_must $MKDIR $dummy
+		log_must $SHARE $dummy
+
+		#
+		# Waiting for fmri's status to be the final status.
+		# Otherwise, in transition, an asterisk (*) is appended for
+		# instances, unshare will reverse status to 'DIS' again.
+		#
+		# Waiting for 1's at least.
+		#
+		log_must $SLEEP 1
+		timeout=10
+		while [[ timeout -ne 0 && $($SVCS -Ho STA $nfs_fmri) == *'*' ]]
+		do
+			log_must $SLEEP 1
+
+			((timeout -= 1))
+		done
+
+		log_must $UNSHARE $dummy
+		log_must $RM -rf $dummy
+	fi
+
+	log_note "Current NFS status: '$($SVCS -Ho STA,FMRI $nfs_fmri)'"
+}
+
+#
+# To verify whether calling process is in global zone
+#
+# Return 0 if in global zone, 1 in non-global zone
+#
+function is_global_zone
+{
+	typeset cur_zone=$($ZONENAME 2>/dev/null)
+	if [[ $cur_zone != "global" ]]; then
+		return 1
+	fi
+	return 0
+}
+
+#
+# Verify whether test is permitted to run from
+# global zone, local zone, or both
+#
+# $1 zone limit, could be "global", "local", or "both"(no limit)
+#
+# Return 0 if permitted, otherwise exit with log_unsupported
+#
+function verify_runnable # zone limit
+{
+	typeset limit=$1
+
+	[[ -z $limit ]] && return 0
+
+	if is_global_zone ; then
+		case $limit in
+			global|both)
+				;;
+			local)	log_unsupported "Test is unable to run from "\
+					"global zone."
+				;;
+			*)	log_note "Warning: unknown limit $limit - " \
+					"use both."
+				;;
+		esac
+	else
+		case $limit in
+			local|both)
+				;;
+			global)	log_unsupported "Test is unable to run from "\
+					"local zone."
+				;;
+			*)	log_note "Warning: unknown limit $limit - " \
+					"use both."
+				;;
+		esac
+
+		reexport_pool
+	fi
+
+	return 0
+}
+
+# Return 0 if create successfully or the pool exists; $? otherwise
+# Note: In local zones, this function should return 0 silently.
+#
+# $1 - pool name
+# $2-n - [keyword] devs_list
+
+function create_pool #pool devs_list
+{
+	typeset pool=${1%%/*}
+
+	shift
+
+	if [[ -z $pool ]]; then
+		log_note "Missing pool name."
+		return 1
+	fi
+
+	if poolexists $pool ; then
+		destroy_pool $pool
+	fi
+
+	if is_global_zone ; then
+		[[ -d /$pool ]] && $RM -rf /$pool
+		log_must $ZPOOL create -f $pool $@
+	fi
+
+	return 0
+}
+
+# Return 0 if destroy successfully or the pool exists; $? otherwise
+# Note: In local zones, this function should return 0 silently.
+#
+# $1 - pool name
+# Destroy pool with the given parameters.
+
+function destroy_pool #pool
+{
+	typeset pool=${1%%/*}
+	typeset mtpt
+
+	if [[ -z $pool ]]; then
+		log_note "No pool name given."
+		return 1
+	fi
+
+	if is_global_zone ; then
+		if poolexists "$pool" ; then
+			mtpt=$(get_prop mountpoint "$pool")
+			log_must $ZPOOL destroy -f $pool
+
+			[[ -d $mtpt ]] && \
+				log_must $RM -rf $mtpt
+		else
+			log_note "Pool not exist. ($pool)"
+			return 1
+		fi
+	fi
+
+	return 0
+}
+
+#
+# Firstly, create a pool with 5 datasets. Then, create a single zone and
+# export the 5 datasets to it. In addition, we also add a ZFS filesystem
+# and a zvol device to the zone.
+#
+# $1 zone name
+# $2 zone root directory prefix
+# $3 zone ip
+#
+function zfs_zones_setup #zone_name zone_root zone_ip
+{
+	typeset zone_name=${1:-$(hostname)-z}
+	typeset zone_root=${2:-"/zone_root"}
+	typeset zone_ip=${3:-"10.1.1.10"}
+	typeset prefix_ctr=$ZONE_CTR
+	typeset pool_name=$ZONE_POOL
+	typeset -i cntctr=5
+	typeset -i i=0
+
+	# Create pool and 5 container within it
+	#
+	[[ -d /$pool_name ]] && $RM -rf /$pool_name
+	log_must $ZPOOL create -f $pool_name $DISKS
+	while ((i < cntctr)); do
+		log_must $ZFS create $pool_name/$prefix_ctr$i
+		((i += 1))
+	done
+
+	# create a zvol
+	log_must $ZFS create -V 1g $pool_name/zone_zvol
+
+	#
+	# If current system support slog, add slog device for pool
+	#
+	if verify_slog_support ; then
+		typeset sdevs="/var/tmp/sdev1 /var/tmp/sdev2"
+		log_must $MKFILE 100M $sdevs
+		log_must $ZPOOL add $pool_name log mirror $sdevs
+	fi
+
+	# this isn't supported just yet.
+	# Create a filesystem. In order to add this to
+	# the zone, it must have it's mountpoint set to 'legacy'
+	# log_must $ZFS create $pool_name/zfs_filesystem
+	# log_must $ZFS set mountpoint=legacy $pool_name/zfs_filesystem
+
+	[[ -d $zone_root ]] && \
+		log_must $RM -rf $zone_root/$zone_name
+	[[ ! -d $zone_root ]] && \
+		log_must $MKDIR -p -m 0700 $zone_root/$zone_name
+
+	# Create zone configure file and configure the zone
+	#
+	typeset zone_conf=/tmp/zone_conf.$$
+	$ECHO "create" > $zone_conf
+	$ECHO "set zonepath=$zone_root/$zone_name" >> $zone_conf
+	$ECHO "set autoboot=true" >> $zone_conf
+	i=0
+	while ((i < cntctr)); do
+		$ECHO "add dataset" >> $zone_conf
+		$ECHO "set name=$pool_name/$prefix_ctr$i" >> \
+			$zone_conf
+		$ECHO "end" >> $zone_conf
+		((i += 1))
+	done
+
+	# add our zvol to the zone
+	$ECHO "add device" >> $zone_conf
+	$ECHO "set match=/dev/zvol/dsk/$pool_name/zone_zvol" >> $zone_conf
+	$ECHO "end" >> $zone_conf
+
+	# add a corresponding zvol rdsk to the zone
+	$ECHO "add device" >> $zone_conf
+	$ECHO "set match=/dev/zvol/rdsk/$pool_name/zone_zvol" >> $zone_conf
+	$ECHO "end" >> $zone_conf
+
+	# once it's supported, we'll add our filesystem to the zone
+	# $ECHO "add fs" >> $zone_conf
+	# $ECHO "set type=zfs" >> $zone_conf
+	# $ECHO "set special=$pool_name/zfs_filesystem" >> $zone_conf
+	# $ECHO "set dir=/export/zfs_filesystem" >> $zone_conf
+	# $ECHO "end" >> $zone_conf
+
+	$ECHO "verify" >> $zone_conf
+	$ECHO "commit" >> $zone_conf
+	log_must $ZONECFG -z $zone_name -f $zone_conf
+	log_must $RM -f $zone_conf
+
+	# Install the zone
+	$ZONEADM -z $zone_name install
+	if (($? == 0)); then
+		log_note "SUCCESS: $ZONEADM -z $zone_name install"
+	else
+		log_fail "FAIL: $ZONEADM -z $zone_name install"
+	fi
+
+	# Install sysidcfg file
+	#
+	typeset sysidcfg=$zone_root/$zone_name/root/etc/sysidcfg
+	$ECHO "system_locale=C" > $sysidcfg
+	$ECHO  "terminal=dtterm" >> $sysidcfg
+	$ECHO  "network_interface=primary {" >> $sysidcfg
+	$ECHO  "hostname=$zone_name" >> $sysidcfg
+	$ECHO  "}" >> $sysidcfg
+	$ECHO  "name_service=NONE" >> $sysidcfg
+	$ECHO  "root_password=mo791xfZ/SFiw" >> $sysidcfg
+	$ECHO  "security_policy=NONE" >> $sysidcfg
+	$ECHO  "timezone=US/Eastern" >> $sysidcfg
+
+	# Boot this zone
+	log_must $ZONEADM -z $zone_name boot
+}
+
+#
+# Reexport TESTPOOL & TESTPOOL(1-4)
+#
+function reexport_pool
+{
+	typeset -i cntctr=5
+	typeset -i i=0
+
+	while ((i < cntctr)); do
+		if ((i == 0)); then
+			TESTPOOL=$ZONE_POOL/$ZONE_CTR$i
+			if ! ismounted $TESTPOOL; then
+				log_must $ZFS mount $TESTPOOL
+			fi
+		else
+			eval TESTPOOL$i=$ZONE_POOL/$ZONE_CTR$i
+			if eval ! ismounted \$TESTPOOL$i; then
+				log_must eval $ZFS mount \$TESTPOOL$i
+			fi
+		fi
+		((i += 1))
+	done
+}
+
+#
+# Verify a given disk is online or offline
+#
+# Return 0 is pool/disk matches expected state, 1 otherwise
+#
+function check_state # pool disk state{online,offline}
+{
+	typeset pool=$1
+	typeset disk=${2#/dev/dsk/}
+	typeset state=$3
+
+	$ZPOOL status -v $pool | grep "$disk"  \
+	    | grep -i "$state" > /dev/null 2>&1
+
+	return $?
+}
+
+#
+# Get the mountpoint of snapshot
+# For the snapshot use <mp_filesystem>/.zfs/snapshot/<snap>
+# as its mountpoint
+#
+function snapshot_mountpoint
+{
+	typeset dataset=${1:-$TESTPOOL/$TESTFS@$TESTSNAP}
+
+	if [[ $dataset != *@* ]]; then
+		log_fail "Error name of snapshot '$dataset'."
+	fi
+
+	typeset fs=${dataset%@*}
+	typeset snap=${dataset#*@}
+
+	if [[ -z $fs || -z $snap ]]; then
+		log_fail "Error name of snapshot '$dataset'."
+	fi
+
+	$ECHO $(get_prop mountpoint $fs)/.zfs/snapshot/$snap
+}
+
+#
+# Given a pool and file system, this function will verify the file system
+# using the zdb internal tool. Note that the pool is exported and imported
+# to ensure it has consistent state.
+#
+function verify_filesys # pool filesystem dir
+{
+	typeset pool="$1"
+	typeset filesys="$2"
+	typeset zdbout="/tmp/zdbout.$$"
+
+	shift
+	shift
+	typeset dirs=$@
+	typeset search_path=""
+
+	log_note "Calling $ZDB to verify filesystem '$filesys'"
+	$ZFS unmount -a > /dev/null 2>&1
+	log_must $ZPOOL export $pool
+
+	if [[ -n $dirs ]] ; then
+		for dir in $dirs ; do
+			search_path="$search_path -d $dir"
+		done
+	fi
+
+	log_must $ZPOOL import $search_path $pool
+
+	$ZDB -cudi $filesys > $zdbout 2>&1
+	if [[ $? != 0 ]]; then
+		log_note "Output: $ZDB -cudi $filesys"
+		$CAT $zdbout
+		log_fail "$ZDB detected errors with: '$filesys'"
+	fi
+
+	log_must $ZFS mount -a
+	log_must $RM -rf $zdbout
+}
+
+#
+# Given a pool, and this function list all disks in the pool
+#
+function get_disklist # pool
+{
+	typeset disklist=""
+
+	disklist=$($ZPOOL iostat -v $1 | $NAWK '(NR >4) {print $1}' | \
+	    $GREP -v "\-\-\-\-\-" | \
+	    $EGREP -v -e "^(mirror|raidz1|raidz2|spare|log|cache)$")
+
+	$ECHO $disklist
+}
+
+#
+# Destroy all existing metadevices and state database
+#
+function destroy_metas
+{
+	typeset metad
+
+	for metad in $($METASTAT -p | $AWK '{print $1}'); do
+		log_must $METACLEAR -rf $metad
+	done
+
+	for metad in $($METADB | $CUT -f6 | $GREP dev | $UNIQ); do
+		log_must $METADB -fd $metad
+	done
+}
+
+# /**
+#  This function kills a given list of processes after a time period. We use
+#  this in the stress tests instead of STF_TIMEOUT so that we can have processes
+#  run for a fixed amount of time, yet still pass. Tests that hit STF_TIMEOUT
+#  would be listed as FAIL, which we don't want : we're happy with stress tests
+#  running for a certain amount of time, then finishing.
+#
+# @param $1 the time in seconds after which we should terminate these processes
+# @param $2..$n the processes we wish to terminate.
+# */
+function stress_timeout
+{
+	typeset -i TIMEOUT=$1
+	shift
+	typeset cpids="$@"
+
+	log_note "Waiting for child processes($cpids). " \
+		"It could last dozens of minutes, please be patient ..."
+	log_must $SLEEP $TIMEOUT
+
+	log_note "Killing child processes after ${TIMEOUT} stress timeout."
+	typeset pid
+	for pid in $cpids; do
+		$PS -p $pid > /dev/null 2>&1
+		if (($? == 0)); then
+			log_must $KILL -USR1 $pid
+		fi
+	done
+}
+
+#
+# Verify a given hotspare disk is inuse or avail
+#
+# Return 0 is pool/disk matches expected state, 1 otherwise
+#
+function check_hotspare_state # pool disk state{inuse,avail}
+{
+	typeset pool=$1
+	typeset disk=${2#/dev/dsk/}
+	typeset state=$3
+
+	cur_state=$(get_device_state $pool $disk "spares")
+
+	if [[ $state != ${cur_state} ]]; then
+		return 1
+	fi
+	return 0
+}
+
+#
+# Verify a given slog disk is inuse or avail
+#
+# Return 0 is pool/disk matches expected state, 1 otherwise
+#
+function check_slog_state # pool disk state{online,offline,unavail}
+{
+	typeset pool=$1
+	typeset disk=${2#/dev/dsk/}
+	typeset state=$3
+
+	cur_state=$(get_device_state $pool $disk "logs")
+
+	if [[ $state != ${cur_state} ]]; then
+		return 1
+	fi
+	return 0
+}
+
+#
+# Verify a given vdev disk is inuse or avail
+#
+# Return 0 is pool/disk matches expected state, 1 otherwise
+#
+function check_vdev_state # pool disk state{online,offline,unavail}
+{
+	typeset pool=$1
+	typeset disk=${2#/dev/dsk/}
+	typeset state=$3
+
+	cur_state=$(get_device_state $pool $disk)
+
+	if [[ $state != ${cur_state} ]]; then
+		return 1
+	fi
+	return 0
+}
+
+#
+# Check the output of 'zpool status -v <pool>',
+# and to see if the content of <token> contain the <keyword> specified.
+#
+# Return 0 is contain, 1 otherwise
+#
+function check_pool_status # pool token keyword
+{
+	typeset pool=$1
+	typeset token=$2
+	typeset keyword=$3
+
+	$ZPOOL status -v "$pool" 2>/dev/null | $NAWK -v token="$token:" '
+		($1==token) {print $0}' \
+	| $GREP -i "$keyword" > /dev/null 2>&1
+
+	return $?
+}
+
+#
+# These 5 following functions are instance of check_pool_status()
+#	is_pool_resilvering - to check if the pool is resilver in progress
+#	is_pool_resilvered - to check if the pool is resilver completed
+#	is_pool_scrubbing - to check if the pool is scrub in progress
+#	is_pool_scrubbed - to check if the pool is scrub completed
+#	is_pool_scrub_stopped - to check if the pool is scrub stopped
+#
+function is_pool_resilvering #pool
+{
+	check_pool_status "$1" "scan" "resilver in progress since "
+	return $?
+}
+
+function is_pool_resilvered #pool
+{
+	check_pool_status "$1" "scan" "resilvered "
+	return $?
+}
+
+function is_pool_scrubbing #pool
+{
+	check_pool_status "$1" "scan" "scrub in progress since "
+	return $?
+}
+
+function is_pool_scrubbed #pool
+{
+	check_pool_status "$1" "scan" "scrub repaired"
+	return $?
+}
+
+function is_pool_scrub_stopped #pool
+{
+	check_pool_status "$1" "scan" "scrub canceled"
+	return $?
+}
+
+#
+# Use create_pool()/destroy_pool() to clean up the infomation in
+# in the given disk to avoid slice overlapping.
+#
+function cleanup_devices #vdevs
+{
+	typeset pool="foopool$$"
+
+	if poolexists $pool ; then
+		destroy_pool $pool
+	fi
+
+	create_pool $pool $@
+	destroy_pool $pool
+
+	return 0
+}
+
+#
+# Verify the rsh connectivity to each remote host in RHOSTS.
+#
+# Return 0 if remote host is accessible; otherwise 1.
+# $1 remote host name
+# $2 username
+#
+function verify_rsh_connect #rhost, username
+{
+	typeset rhost=$1
+	typeset username=$2
+	typeset rsh_cmd="$RSH -n"
+	typeset cur_user=
+
+	$GETENT hosts $rhost >/dev/null 2>&1
+	if (($? != 0)); then
+		log_note "$rhost cannot be found from" \
+			"administrative database."
+		return 1
+	fi
+
+	$PING $rhost 3 >/dev/null 2>&1
+	if (($? != 0)); then
+		log_note "$rhost is not reachable."
+		return 1
+	fi
+
+	if ((${#username} != 0)); then
+		rsh_cmd="$rsh_cmd -l $username"
+		cur_user="given user \"$username\""
+	else
+		cur_user="current user \"`$LOGNAME`\""
+	fi
+
+	 if ! $rsh_cmd $rhost $TRUE; then
+		log_note "$RSH to $rhost is not accessible" \
+			"with $cur_user."
+		return 1
+	fi
+
+	return 0
+}
+
+#
+# Verify the remote host connection via rsh after rebooting
+# $1 remote host
+#
+function verify_remote
+{
+	rhost=$1
+
+	#
+	# The following loop waits for the remote system rebooting.
+	# Each iteration will wait for 150 seconds. there are
+	# total 5 iterations, so the total timeout value will
+	# be 12.5  minutes for the system rebooting. This number
+	# is an approxiate number.
+	#
+	typeset -i count=0
+	while ! verify_rsh_connect $rhost; do
+		sleep 150
+		((count = count + 1))
+		if ((count > 5)); then
+			return 1
+		fi
+	done
+	return 0
+}
+
+#
+# Replacement function for /usr/bin/rsh. This function will include
+# the /usr/bin/rsh and meanwhile return the execution status of the
+# last command.
+#
+# $1 usrname passing down to -l option of /usr/bin/rsh
+# $2 remote machine hostname
+# $3... command string
+#
+
+function rsh_status
+{
+	typeset ruser=$1
+	typeset rhost=$2
+	typeset -i ret=0
+	typeset cmd_str=""
+	typeset rsh_str=""
+
+	shift; shift
+	cmd_str="$@"
+
+	err_file=/tmp/${rhost}.$$.err
+	if ((${#ruser} == 0)); then
+		rsh_str="$RSH -n"
+	else
+		rsh_str="$RSH -n -l $ruser"
+	fi
+
+	$rsh_str $rhost /usr/bin/ksh -c "'$cmd_str; \
+		print -u 2 \"status=\$?\"'" \
+		>/dev/null 2>$err_file
+	ret=$?
+	if (($ret != 0)); then
+		$CAT $err_file
+		$RM -f $std_file $err_file
+		log_fail  "$RSH itself failed with exit code $ret..."
+	fi
+
+	 ret=$($GREP -v 'print -u 2' $err_file | $GREP 'status=' | \
+		$CUT -d= -f2)
+	(($ret != 0)) && $CAT $err_file >&2
+
+	$RM -f $err_file >/dev/null 2>&1
+	return $ret
+}
+
+#
+# Get the SUNWstc-fs-zfs package installation path in a remote host
+# $1 remote host name
+#
+function get_remote_pkgpath
+{
+	typeset rhost=$1
+	typeset pkgpath=""
+
+	pkgpath=$($RSH -n $rhost "$PKGINFO -l SUNWstc-fs-zfs | $GREP BASEDIR: |\
+			$CUT -d: -f2")
+
+	$ECHO $pkgpath
+}
+
+#/**
+# A function to find and locate free disks on a system or from given
+# disks as the parameter. It works by locating disks that are in use
+# as swap devices, SVM devices, and dump devices, and also disks
+# listed in /etc/vfstab
+#
+# $@ given disks to find which are free, default is all disks in
+# the test system
+#
+# @return a string containing the list of available disks
+#*/
+function find_disks
+{
+	sfi=/tmp/swaplist.$$
+	msi=/tmp/metastat.$$
+	dmpi=/tmp/dumpdev.$$
+	max_finddisksnum=${MAX_FINDDISKSNUM:-6}
+
+	$SWAP -l > $sfi
+	$METASTAT -c > $msi 2>/dev/null
+	$DUMPADM > $dmpi 2>/dev/null
+
+# write an awk script that can process the output of format
+# to produce a list of disks we know about. Note that we have
+# to escape "$2" so that the shell doesn't interpret it while
+# we're creating the awk script.
+# -------------------
+	$CAT > /tmp/find_disks.awk <<EOF
+#!/bin/nawk -f
+	BEGIN { FS="."; }
+
+	/^Specify disk/{
+		searchdisks=0;
+	}
+
+	{
+		if (searchdisks && \$2 !~ "^$"){
+			split(\$2,arr," ");
+			print arr[1];
+		}
+	}
+
+	/^AVAILABLE DISK SELECTIONS:/{
+		searchdisks=1;
+	}
+EOF
+#---------------------
+
+	$CHMOD 755 /tmp/find_disks.awk
+	disks=${@:-$($ECHO "" | $FORMAT -e 2>/dev/null | /tmp/find_disks.awk)}
+	$RM /tmp/find_disks.awk
+
+	unused=""
+	for disk in $disks; do
+	# Check for mounted
+		$GREP "${disk}[sp]" /etc/mnttab >/dev/null
+		(($? == 0)) && continue
+	# Check for swap
+		$GREP "${disk}[sp]" $sfi >/dev/null
+		(($? == 0)) && continue
+	# Check for SVM
+		$GREP "${disk}" $msi >/dev/null
+		(($? == 0)) && continue
+	# check for dump device
+		$GREP "${disk}[sp]" $dmpi >/dev/null
+		(($? == 0)) && continue
+	# check to see if this disk hasn't been explicitly excluded
+	# by a user-set environment variable
+		$ECHO "${ZFS_HOST_DEVICES_IGNORE}" | $GREP "${disk}" > /dev/null
+		(($? == 0)) && continue
+		unused_candidates="$unused_candidates $disk"
+	done
+	$RM $sfi
+	$RM $msi
+	$RM $dmpi
+
+# now just check to see if those disks do actually exist
+# by looking for a device pointing to the first slice in
+# each case. limit the number to max_finddisksnum
+	count=0
+	for disk in $unused_candidates; do
+		if [ -b /dev/dsk/${disk}s0 ]; then
+		if [ $count -lt $max_finddisksnum ]; then
+			unused="$unused $disk"
+			# do not impose limit if $@ is provided
+			[[ -z $@ ]] && ((count = count + 1))
+		fi
+		fi
+	done
+
+# finally, return our disk list
+	$ECHO $unused
+}
+
+#
+# Add specified user to specified group
+#
+# $1 group name
+# $2 user name
+# $3 base of the homedir (optional)
+#
+function add_user #<group_name> <user_name> <basedir>
+{
+	typeset gname=$1
+	typeset uname=$2
+	typeset basedir=${3:-"/var/tmp"}
+
+	if ((${#gname} == 0 || ${#uname} == 0)); then
+		log_fail "group name or user name are not defined."
+	fi
+
+	log_must $USERADD -g $gname -d $basedir/$uname -m $uname
+
+	return 0
+}
+
+#
+# Delete the specified user.
+#
+# $1 login name
+# $2 base of the homedir (optional)
+#
+function del_user #<logname> <basedir>
+{
+	typeset user=$1
+	typeset basedir=${2:-"/var/tmp"}
+
+	if ((${#user} == 0)); then
+		log_fail "login name is necessary."
+	fi
+
+	if $ID $user > /dev/null 2>&1; then
+		log_must $USERDEL $user
+	fi
+
+	[[ -d $basedir/$user ]] && $RM -fr $basedir/$user
+
+	return 0
+}
+
+#
+# Select valid gid and create specified group.
+#
+# $1 group name
+#
+function add_group #<group_name>
+{
+	typeset group=$1
+
+	if ((${#group} == 0)); then
+		log_fail "group name is necessary."
+	fi
+
+	# Assign 100 as the base gid
+	typeset -i gid=100
+	while true; do
+		$GROUPADD -g $gid $group > /dev/null 2>&1
+		typeset -i ret=$?
+		case $ret in
+			0) return 0 ;;
+			# The gid is not  unique
+			4) ((gid += 1)) ;;
+			*) return 1 ;;
+		esac
+	done
+}
+
+#
+# Delete the specified group.
+#
+# $1 group name
+#
+function del_group #<group_name>
+{
+	typeset grp=$1
+	if ((${#grp} == 0)); then
+		log_fail "group name is necessary."
+	fi
+
+	$GROUPMOD -n $grp $grp > /dev/null 2>&1
+	typeset -i ret=$?
+	case $ret in
+		# Group does not exist.
+		6) return 0 ;;
+		# Name already exists as a group name
+		9) log_must $GROUPDEL $grp ;;
+		*) return 1 ;;
+	esac
+
+	return 0
+}
+
+#
+# This function will return true if it's safe to destroy the pool passed
+# as argument 1. It checks for pools based on zvols and files, and also
+# files contained in a pool that may have a different mountpoint.
+#
+function safe_to_destroy_pool { # $1 the pool name
+
+	typeset pool=""
+	typeset DONT_DESTROY=""
+
+	# We check that by deleting the $1 pool, we're not
+	# going to pull the rug out from other pools. Do this
+	# by looking at all other pools, ensuring that they
+	# aren't built from files or zvols contained in this pool.
+
+	for pool in $($ZPOOL list -H -o name)
+	do
+		ALTMOUNTPOOL=""
+
+		# this is a list of the top-level directories in each of the
+		# files that make up the path to the files the pool is based on
+		FILEPOOL=$($ZPOOL status -v $pool | $GREP /$1/ | \
+			$AWK '{print $1}')
+
+		# this is a list of the zvols that make up the pool
+		ZVOLPOOL=$($ZPOOL status -v $pool | $GREP "/dev/zvol/dsk/$1$" \
+		    | $AWK '{print $1}')
+
+		# also want to determine if it's a file-based pool using an
+		# alternate mountpoint...
+		POOL_FILE_DIRS=$($ZPOOL status -v $pool | \
+					$GREP / | $AWK '{print $1}' | \
+					$AWK -F/ '{print $2}' | $GREP -v "dev")
+
+		for pooldir in $POOL_FILE_DIRS
+		do
+			OUTPUT=$($ZFS list -H -r -o mountpoint $1 | \
+					$GREP "${pooldir}$" | $AWK '{print $1}')
+
+			ALTMOUNTPOOL="${ALTMOUNTPOOL}${OUTPUT}"
+		done
+
+
+		if [ ! -z "$ZVOLPOOL" ]
+		then
+			DONT_DESTROY="true"
+			log_note "Pool $pool is built from $ZVOLPOOL on $1"
+		fi
+
+		if [ ! -z "$FILEPOOL" ]
+		then
+			DONT_DESTROY="true"
+			log_note "Pool $pool is built from $FILEPOOL on $1"
+		fi
+
+		if [ ! -z "$ALTMOUNTPOOL" ]
+		then
+			DONT_DESTROY="true"
+			log_note "Pool $pool is built from $ALTMOUNTPOOL on $1"
+		fi
+	done
+
+	if [ -z "${DONT_DESTROY}" ]
+	then
+		return 0
+	else
+		log_note "Warning: it is not safe to destroy $1!"
+		return 1
+	fi
+}
+
+#
+# Get IP address of hostname
+# $1 hostname
+#
+function getipbyhost
+{
+	typeset ip
+	ip=`$ARP $1 2>/dev/null | $AWK -F\) '{print $1}' \
+		| $AWK -F\('{print $2}'`
+	$ECHO $ip
+}
+
+#
+# Setup iSCSI initiator to target
+# $1 target hostname
+#
+function iscsi_isetup
+{
+	# check svc:/network/iscsi_initiator:default state, try to enable it
+	# if the state is not ON
+	typeset ISCSII_FMRI="svc:/network/iscsi_initiator:default"
+	if [[ "ON" != $($SVCS -H -o sta $ISCSII_FMRI) ]]; then
+		log_must $SVCADM enable $ISCSII_FMRI
+
+		typeset -i retry=20
+		while [[ "ON" != $($SVCS -H -o sta $ISCSII_FMRI) && \
+			($retry -ne 0) ]]
+		do
+			((retry = retry - 1))
+			$SLEEP 1
+		done
+
+		if [[ "ON" != $($SVCS -H -o sta $ISCSII_FMRI) ]]; then
+			log_fail "$ISCSII_FMRI service can not be enabled!"
+		fi
+	fi
+
+	log_must $ISCSIADM add discovery-address $(getipbyhost $1)
+	log_must $ISCSIADM modify discovery --sendtargets enable
+	log_must $DEVFSADM -i iscsi
+}
+
+#
+# Check whether iscsi parameter is set as remote
+#
+# return 0 if iscsi is set as remote, otherwise 1
+#
+function check_iscsi_remote
+{
+	if [[ $iscsi == "remote" ]] ; then
+		return 0
+	else
+		return 1
+	fi
+}
+
+#
+# Check if a volume is a valide iscsi target
+# $1 volume name
+# return 0 if suceeds, otherwise, return 1
+#
+function is_iscsi_target
+{
+	typeset dataset=$1
+	typeset target targets
+
+	[[ -z $dataset ]] && return 1
+
+	targets=$($ISCSITADM list target | $GREP "Target:" | $AWK '{print $2}')
+	[[ -z $targets ]] && return 1
+
+	for target in $targets; do
+		[[ $dataset == $target ]] && return 0
+	done
+
+	return 1
+}
+
+#
+# Get the iSCSI name of a target
+# $1 target name
+#
+function iscsi_name
+{
+	typeset target=$1
+	typeset name
+
+	[[ -z $target ]] && log_fail "No parameter."
+
+	if ! is_iscsi_target $target ; then
+		log_fail "Not a target."
+	fi
+
+	name=$($ISCSITADM list target $target | $GREP "iSCSI Name:" \
+		| $AWK '{print $2}')
+
+	return $name
+}
+
+#
+# check svc:/system/iscsitgt:default state, try to enable it if the state
+# is not ON
+#
+function iscsitgt_setup
+{
+	log_must $RM -f $ISCSITGTFILE
+	if [[ "ON" == $($SVCS -H -o sta $ISCSITGT_FMRI) ]]; then
+		log_note "iscsitgt is already enabled"
+		return
+	fi
+
+	log_must $SVCADM enable -t $ISCSITGT_FMRI
+
+	typeset -i retry=20
+	while [[ "ON" != $($SVCS -H -o sta $ISCSITGT_FMRI) && \
+		($retry -ne 0) ]]
+	do
+		$SLEEP 1
+		((retry = retry - 1))
+	done
+
+	if [[ "ON" != $($SVCS -H -o sta $ISCSITGT_FMRI) ]]; then
+		log_fail "$ISCSITGT_FMRI service can not be enabled!"
+	fi
+
+	log_must $TOUCH $ISCSITGTFILE
+}
+
+#
+# set DISABLED state of svc:/system/iscsitgt:default
+# which is the most suiteable state if $ISCSITGTFILE exists
+#
+function iscsitgt_cleanup
+{
+	if [[ -e $ISCSITGTFILE ]]; then
+		log_must $SVCADM disable $ISCSITGT_FMRI
+		log_must $RM -f $ISCSITGTFILE
+	fi
+}
+
+#
+# Close iSCSI initiator to target
+# $1 target hostname
+#
+function iscsi_iclose
+{
+	log_must $ISCSIADM modify discovery --sendtargets disable
+	log_must $ISCSIADM remove discovery-address $(getipbyhost $1)
+	$DEVFSADM -Cv
+}
+
+#
+# Get the available ZFS compression options
+# $1 option type zfs_set|zfs_compress
+#
+function get_compress_opts
+{
+	typeset COMPRESS_OPTS
+	typeset GZIP_OPTS="gzip gzip-1 gzip-2 gzip-3 gzip-4 gzip-5 \
+			gzip-6 gzip-7 gzip-8 gzip-9"
+
+	if [[ $1 == "zfs_compress" ]] ; then
+		COMPRESS_OPTS="on lzjb"
+	elif [[ $1 == "zfs_set" ]] ; then
+		COMPRESS_OPTS="on off lzjb"
+	fi
+	typeset valid_opts="$COMPRESS_OPTS"
+	$ZFS get 2>&1 | $GREP gzip >/dev/null 2>&1
+	if [[ $? -eq 0 ]]; then
+		valid_opts="$valid_opts $GZIP_OPTS"
+	fi
+	$ECHO "$valid_opts"
+}
+
+#
+# Verify zfs operation with -p option work as expected
+# $1 operation, value could be create, clone or rename
+# $2 dataset type, value could be fs or vol
+# $3 dataset name
+# $4 new dataset name
+#
+function verify_opt_p_ops
+{
+	typeset ops=$1
+	typeset datatype=$2
+	typeset dataset=$3
+	typeset newdataset=$4
+
+	if [[ $datatype != "fs" && $datatype != "vol" ]]; then
+		log_fail "$datatype is not supported."
+	fi
+
+	# check parameters accordingly
+	case $ops in
+		create)
+			newdataset=$dataset
+			dataset=""
+			if [[ $datatype == "vol" ]]; then
+				ops="create -V $VOLSIZE"
+			fi
+			;;
+		clone)
+			if [[ -z $newdataset ]]; then
+				log_fail "newdataset should not be empty" \
+					"when ops is $ops."
+			fi
+			log_must datasetexists $dataset
+			log_must snapexists $dataset
+			;;
+		rename)
+			if [[ -z $newdataset ]]; then
+				log_fail "newdataset should not be empty" \
+					"when ops is $ops."
+			fi
+			log_must datasetexists $dataset
+			log_mustnot snapexists $dataset
+			;;
+		*)
+			log_fail "$ops is not supported."
+			;;
+	esac
+
+	# make sure the upper level filesystem does not exist
+	if datasetexists ${newdataset%/*} ; then
+		log_must $ZFS destroy -rRf ${newdataset%/*}
+	fi
+
+	# without -p option, operation will fail
+	log_mustnot $ZFS $ops $dataset $newdataset
+	log_mustnot datasetexists $newdataset ${newdataset%/*}
+
+	# with -p option, operation should succeed
+	log_must $ZFS $ops -p $dataset $newdataset
+	if ! datasetexists $newdataset ; then
+		log_fail "-p option does not work for $ops"
+	fi
+
+	# when $ops is create or clone, redo the operation still return zero
+	if [[ $ops != "rename" ]]; then
+		log_must $ZFS $ops -p $dataset $newdataset
+	fi
+
+	return 0
+}
+
+#
+# Get configuration of pool
+# $1 pool name
+# $2 config name
+#
+function get_config
+{
+	typeset pool=$1
+	typeset config=$2
+	typeset alt_root
+
+	if ! poolexists "$pool" ; then
+		return 1
+	fi
+	alt_root=$($ZPOOL list -H $pool | $AWK '{print $NF}')
+	if [[ $alt_root == "-" ]]; then
+		value=$($ZDB -C $pool | $GREP "$config:" | $AWK -F: \
+		    '{print $2}')
+	else
+		value=$($ZDB -e $pool | $GREP "$config:" | $AWK -F: \
+		    '{print $2}')
+	fi
+	if [[ -n $value ]] ; then
+		value=${value#'}
+		value=${value%'}
+	fi
+	echo $value
+
+	return 0
+}
+
+#
+# Privated function. Random select one of items from arguments.
+#
+# $1 count
+# $2-n string
+#
+function _random_get
+{
+	typeset cnt=$1
+	shift
+
+	typeset str="$@"
+	typeset -i ind
+	((ind = RANDOM % cnt + 1))
+
+	typeset ret=$($ECHO "$str" | $CUT -f $ind -d ' ')
+	$ECHO $ret
+}
+
+#
+# Random select one of item from arguments which include NONE string
+#
+function random_get_with_non
+{
+	typeset -i cnt=$#
+	((cnt =+ 1))
+
+	_random_get "$cnt" "$@"
+}
+
+#
+# Random select one of item from arguments which doesn't include NONE string
+#
+function random_get
+{
+	_random_get "$#" "$@"
+}
+
+#
+# Detect if the current system support slog
+#
+function verify_slog_support
+{
+	typeset dir=/tmp/disk.$$
+	typeset pool=foo.$$
+	typeset vdev=$dir/a
+	typeset sdev=$dir/b
+
+	$MKDIR -p $dir
+	$MKFILE 64M $vdev $sdev
+
+	typeset -i ret=0
+	if ! $ZPOOL create -n $pool $vdev log $sdev > /dev/null 2>&1; then
+		ret=1
+	fi
+	$RM -r $dir
+
+	return $ret
+}
+
+#
+# The function will generate a dataset name with specific length
+# $1, the length of the name
+# $2, the base string to construct the name
+#
+function gen_dataset_name
+{
+	typeset -i len=$1
+	typeset basestr="$2"
+	typeset -i baselen=${#basestr}
+	typeset -i iter=0
+	typeset l_name=""
+
+	if ((len % baselen == 0)); then
+		((iter = len / baselen))
+	else
+		((iter = len / baselen + 1))
+	fi
+	while ((iter > 0)); do
+		l_name="${l_name}$basestr"
+
+		((iter -= 1))
+	done
+
+	$ECHO $l_name
+}
+
+#
+# Get cksum tuple of dataset
+# $1 dataset name
+#
+# sample zdb output:
+# Dataset data/test [ZPL], ID 355, cr_txg 2413856, 31.0K, 7 objects, rootbp
+# DVA[0]=<0:803046400:200> DVA[1]=<0:81199000:200> [L0 DMU objset] fletcher4
+# lzjb LE contiguous unique double size=800L/200P birth=2413856L/2413856P
+# fill=7 cksum=11ce125712:643a9c18ee2:125e25238fca0:254a3f74b59744
+function datasetcksum
+{
+	typeset cksum
+	$SYNC
+	cksum=$($ZDB -vvv $1 | $GREP "^Dataset $1 \[" | $GREP "cksum" \
+		| $AWK -F= '{print $7}')
+	$ECHO $cksum
+}
+
+#
+# Get cksum of file
+# #1 file path
+#
+function checksum
+{
+	typeset cksum
+	cksum=$($CKSUM $1 | $AWK '{print $1}')
+	$ECHO $cksum
+}
+
+#
+# Get the given disk/slice state from the specific field of the pool
+#
+function get_device_state #pool disk field("", "spares","logs")
+{
+	typeset pool=$1
+	typeset disk=${2#/dev/dsk/}
+	typeset field=${3:-$pool}
+
+	state=$($ZPOOL status -v "$pool" 2>/dev/null | \
+		$NAWK -v device=$disk -v pool=$pool -v field=$field \
+		'BEGIN {startconfig=0; startfield=0; }
+		/config:/ {startconfig=1}
+		(startconfig==1) && ($1==field) {startfield=1; next;}
+		(startfield==1) && ($1==device) {print $2; exit;}
+		(startfield==1) &&
+		($1==field || $1 ~ "^spares$" || $1 ~ "^logs$") {startfield=0}')
+	echo $state
+}
+
+
+#
+# print the given directory filesystem type
+#
+# $1 directory name
+#
+function get_fstype
+{
+	typeset dir=$1
+
+	if [[ -z $dir ]]; then
+		log_fail "Usage: get_fstype <directory>"
+	fi
+
+	#
+	#  $ df -n /
+	#  /		  : ufs
+	#
+	$DF -n $dir | $AWK '{print $3}'
+}
+
+#
+# Given a disk, label it to VTOC regardless what label was on the disk
+# $1 disk
+#
+function labelvtoc
+{
+	typeset disk=$1
+	if [[ -z $disk ]]; then
+		log_fail "The disk name is unspecified."
+	fi
+	typeset label_file=/var/tmp/labelvtoc.$$
+	typeset arch=$($UNAME -p)
+
+	if [[ $arch == "i386" ]]; then
+		$ECHO "label" > $label_file
+		$ECHO "0" >> $label_file
+		$ECHO "" >> $label_file
+		$ECHO "q" >> $label_file
+		$ECHO "q" >> $label_file
+
+		$FDISK -B $disk >/dev/null 2>&1
+		# wait a while for fdisk finishes
+		$SLEEP 60
+	elif [[ $arch == "sparc" ]]; then
+		$ECHO "label" > $label_file
+		$ECHO "0" >> $label_file
+		$ECHO "" >> $label_file
+		$ECHO "" >> $label_file
+		$ECHO "" >> $label_file
+		$ECHO "q" >> $label_file
+	else
+		log_fail "unknown arch type"
+	fi
+
+	$FORMAT -e -s -d $disk -f $label_file
+	typeset -i ret_val=$?
+	$RM -f $label_file
+	#
+	# wait the format to finish
+	#
+	$SLEEP 60
+	if ((ret_val != 0)); then
+		log_fail "unable to label $disk as VTOC."
+	fi
+
+	return 0
+}
+
+#
+# check if the system was installed as zfsroot or not
+# return: 0 ture, otherwise false
+#
+function is_zfsroot
+{
+	$DF -n / | $GREP zfs > /dev/null 2>&1
+	return $?
+}
+
+#
+# get the root filesystem name if it's zfsroot system.
+#
+# return: root filesystem name
+function get_rootfs
+{
+	typeset rootfs=""
+	rootfs=$($AWK '{if ($2 == "/" && $3 == "zfs") print $1}' \
+		/etc/mnttab)
+	if [[ -z "$rootfs" ]]; then
+		log_fail "Can not get rootfs"
+	fi
+	$ZFS list $rootfs > /dev/null 2>&1
+	if (($? == 0)); then
+		$ECHO $rootfs
+	else
+		log_fail "This is not a zfsroot system."
+	fi
+}
+
+#
+# get the rootfs's pool name
+# return:
+#       rootpool name
+#
+function get_rootpool
+{
+	typeset rootfs=""
+	typeset rootpool=""
+	rootfs=$($AWK '{if ($2 == "/" && $3 =="zfs") print $1}' \
+		 /etc/mnttab)
+	if [[ -z "$rootfs" ]]; then
+		log_fail "Can not get rootpool"
+	fi
+	$ZFS list $rootfs > /dev/null 2>&1
+	if (($? == 0)); then
+		rootpool=`$ECHO $rootfs | awk -F\/ '{print $1}'`
+		$ECHO $rootpool
+	else
+		log_fail "This is not a zfsroot system."
+	fi
+}
+
+#
+# Get the sub string from specified source string
+#
+# $1 source string
+# $2 start position. Count from 1
+# $3 offset
+#
+function get_substr #src_str pos offset
+{
+	typeset pos offset
+
+	$ECHO $1 | \
+		$NAWK -v pos=$2 -v offset=$3 '{print substr($0, pos, offset)}'
+}
+
+#
+# Check if the given device is physical device
+#
+function is_physical_device #device
+{
+	typeset device=${1#/dev/dsk/}
+	device=${device#/dev/rdsk/}
+
+	$ECHO $device | $EGREP "^c[0-F]+([td][0-F]+)+$" > /dev/null 2>&1
+	return $?
+}
+
+#
+# Get the directory path of given device
+#
+function get_device_dir #device
+{
+	typeset device=$1
+
+	if ! $(is_physical_device $device) ; then
+		if [[ $device != "/" ]]; then
+			device=${device%/*}
+		fi
+		$ECHO $device
+	else
+		$ECHO "/dev/dsk"
+	fi
+}
+
+#
+# Get the package name
+#
+function get_package_name
+{
+	typeset dirpath=${1:-$STC_NAME}
+
+	echo "SUNWstc-${dirpath}" | /usr/bin/sed -e "s/\//-/g"
+}
+
+#
+# Get the word numbers from a string separated by white space
+#
+function get_word_count
+{
+	$ECHO $1 | $WC -w
+}
+
+#
+# To verify if the require numbers of disks is given
+#
+function verify_disk_count
+{
+	typeset -i min=${2:-1}
+
+	typeset -i count=$(get_word_count "$1")
+
+	if ((count < min)); then
+		log_untested "A minimum of $min disks is required to run." \
+			" You specified $count disk(s)"
+	fi
+}
+
+function ds_is_volume
+{
+	typeset type=$(get_prop type $1)
+	[[ $type = "volume" ]] && return 0
+	return 1
+}
+
+function ds_is_filesystem
+{
+	typeset type=$(get_prop type $1)
+	[[ $type = "filesystem" ]] && return 0
+	return 1
+}
+
+function ds_is_snapshot
+{
+	typeset type=$(get_prop type $1)
+	[[ $type = "snapshot" ]] && return 0
+	return 1
+}
+
+#
+# Check if Trusted Extensions are installed and enabled
+#
+function is_te_enabled
+{
+	$SVCS -H -o state labeld 2>/dev/null | $GREP "enabled"
+	if (($? != 0)); then
+		return 1
+	else
+		return 0
+	fi
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/usr/src/test/zfs-tests/include/math.shlib	Wed Dec 05 22:04:50 2012 -0500
@@ -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) 2012 by Delphix. All rights reserved.
+#
+
+#
+# Return 0 if the percentage difference between $a and $b is $percent or
+# greater. Return 1 if the percentage is lower or if we would divide by
+# zero. For use like this:
+#
+# Do $action if the calculated percentage is greater or equal to that passed in:
+#	within_percent A B P && $action
+# Do $action if the calculated percentage is less than that passed in:
+#	within_percent A B P || $action
+#
+function within_percent
+{
+	typeset a=$1
+	typeset b=$1
+	typeset percent=$3
+
+	# Set $a or $b to $2 such that a >= b
+	[[ '1' = $($ECHO "if ($2 > $a) 1" | $BC) ]] && a=$2 || b=$2
+
+	# Prevent division by 0
+	[[ $a =~ [1-9] ]] || return 1
+
+	typeset p=$($ECHO "scale=2; $b * 100 / $a" | $BC)
+	log_note "Comparing $a and $b given $percent% (calculated: $p%)"
+	[[ '1' = $($ECHO "scale=2; if ($p >= $percent) 1" | $BC) ]] && return 0
+
+	return 1
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/usr/src/test/zfs-tests/include/properties.shlib	Wed Dec 05 22:04:50 2012 -0500
@@ -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) 2012 by Delphix. All rights reserved.
+#
+
+typeset -a compress_props=('on' 'off' 'lzjb' 'gzip' 'gzip-1' 'gzip-2' 'gzip-3'
+    'gzip-4' 'gzip-5' 'gzip-6' 'gzip-7' 'gzip-8' 'gzip-9' 'zle')
+
+typeset -a checksum_props=('on' 'off' 'fletcher2' 'fletcher4' 'sha256')
+
+#
+# Given the property array passed in, return 'num_props' elements to the
+# user, excluding any elements below 'start.' This allows us to exclude
+# 'off' and 'on' which can be either unwanted, or a duplicate of another
+# property respectively.
+#
+function get_rand_prop
+{
+	typeset prop_array=($(eval echo \${$1[@]}))
+	typeset -i num_props=$2
+	typeset -i start=$3
+	typeset retstr=""
+
+	[[ -z $prop_array || -z $num_props || -z $start ]] && \
+	    log_fail "get_rand_prop: bad arguments"
+
+	typeset prop_max=$((${#prop_array[@]} - 1))
+	typeset -i i
+	for i in $($SHUF -i $start-$prop_max -n $num_props); do
+		retstr="${prop_array[$i]} $retstr"
+	done
+	echo $retstr
+}
+
+function get_rand_compress
+{
+	get_rand_prop compress_props $1 2
+}
+
+function get_rand_compress_any
+{
+	get_rand_prop compress_props $1 0
+}
+
+function get_rand_checksum
+{
+	get_rand_prop checksum_props $1 2
+}
+
+function get_rand_checksum_any
+{
+	get_rand_prop checksum_props $1 0
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/usr/src/test/zfs-tests/runfiles/Makefile	Wed Dec 05 22:04:50 2012 -0500
@@ -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) 2012 by Delphix. All rights reserved.
+#
+
+include $(SRC)/Makefile.master
+
+SRCS = delphix.run openindiana.run
+
+ROOTOPTPKG = $(ROOT)/opt/zfs-tests
+RUNFILES = $(ROOTOPTPKG)/runfiles
+
+CMDS = $(SRCS:%=$(RUNFILES)/%)
+$(CMDS) := FILEMODE = 0444
+
+all: $(SRCS)
+
+install: $(CMDS)
+
+clean lint clobber:
+
+$(CMDS): $(RUNFILES) $(SRCS)
+
+$(RUNFILES):
+	$(INS.dir)
+
+$(RUNFILES)/%: %
+	$(INS.file)
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/usr/src/test/zfs-tests/runfiles/delphix.run	Wed Dec 05 22:04:50 2012 -0500
@@ -0,0 +1,272 @@
+#
+# 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) 2012 by Delphix. All rights reserved.
+#
+
+[DEFAULT]
+pre = setup
+quiet = False
+pre_user = root
+user = root
+timeout = 600
+post_user = root
+post = cleanup
+outputdir = /var/tmp/test_results
+
+[/opt/zfs-tests/tests/functional/acl/cifs]
+tests = ['cifs_attr_001_pos', 'cifs_attr_002_pos', 'cifs_attr_003_pos']
+
+[/opt/zfs-tests/tests/functional/acl/nontrivial]
+tests = ['zfs_acl_chmod_001_neg', 'zfs_acl_chmod_002_pos',
+    'zfs_acl_chmod_aclmode_001_pos', 'zfs_acl_chmod_compact_001_pos',
+    'zfs_acl_chmod_delete_001_pos', 'zfs_acl_chmod_inherit_001_pos',
+    'zfs_acl_chmod_inherit_002_neg', 'zfs_acl_chmod_inherit_002_pos',
+    'zfs_acl_chmod_inherit_003_pos', 'zfs_acl_chmod_inherit_004_pos',
+    'zfs_acl_chmod_owner_001_pos', 'zfs_acl_chmod_rwacl_001_pos',
+    'zfs_acl_chmod_rwx_001_pos', 'zfs_acl_chmod_rwx_002_pos',
+    'zfs_acl_chmod_rwx_003_pos', 'zfs_acl_chmod_rwx_004_pos',
+    'zfs_acl_chmod_xattr_001_pos', 'zfs_acl_chmod_xattr_002_pos',
+    'zfs_acl_cp_001_pos', 'zfs_acl_cp_002_pos', 'zfs_acl_cpio_001_pos',
+    'zfs_acl_cpio_002_pos', 'zfs_acl_find_001_pos', 'zfs_acl_ls_001_pos',
+    'zfs_acl_mv_001_pos', 'zfs_acl_tar_001_pos', 'zfs_acl_tar_002_pos']
+
+[/opt/zfs-tests/tests/functional/acl/trivial]
+tests = ['zfs_acl_chmod_001_pos', 'zfs_acl_compress_001_pos',
+    'zfs_acl_cp_001_pos', 'zfs_acl_cp_002_neg', 'zfs_acl_cp_003_neg',
+    'zfs_acl_find_001_pos', 'zfs_acl_find_002_neg', 'zfs_acl_ls_001_pos',
+    'zfs_acl_ls_002_neg', 'zfs_acl_mv_001_pos', 'zfs_acl_pack_001_pos',
+    'zfs_acl_pax_001_pos', 'zfs_acl_pax_002_pos', 'zfs_acl_pax_003_pos',
+    'zfs_acl_pax_004_pos', 'zfs_acl_pax_005_pos', 'zfs_acl_pax_006_pos',
+    'zfs_acl_tar_001_pos', 'zfs_acl_tar_002_neg']
+
+[/opt/zfs-tests/tests/functional/atime]
+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']
+pre =
+post =
+
+[/opt/zfs-tests/tests/functional/cli_root/zdb]
+tests = ['zdb_001_neg']
+pre =
+post =
+
+[/opt/zfs-tests/tests/functional/cli_root/zfs]
+tests = ['zfs_001_neg', 'zfs_002_pos', 'zfs_003_neg']
+
+[/opt/zfs-tests/tests/functional/cli_root/zfs_clone]
+tests = ['zfs_clone_001_neg', 'zfs_clone_002_pos', 'zfs_clone_003_pos',
+    'zfs_clone_004_pos', 'zfs_clone_005_pos', 'zfs_clone_006_pos',
+    'zfs_clone_007_pos', 'zfs_clone_008_neg', 'zfs_clone_009_neg',
+    'zfs_clone_010_pos']
+
+[/opt/zfs-tests/tests/functional/cli_root/zfs_copies]
+tests = ['zfs_copies_001_pos', 'zfs_copies_002_pos', 'zfs_copies_003_pos',
+    'zfs_copies_004_neg', 'zfs_copies_005_neg', 'zfs_copies_006_pos']
+
+[/opt/zfs-tests/tests/functional/cli_root/zfs_create]
+tests = ['zfs_create_001_pos', 'zfs_create_002_pos', 'zfs_create_003_pos',
+    'zfs_create_004_pos', 'zfs_create_005_pos', 'zfs_create_006_pos',
+    'zfs_create_007_pos', 'zfs_create_008_neg', 'zfs_create_009_neg',
+    'zfs_create_010_neg', 'zfs_create_011_pos', 'zfs_create_012_pos',
+    'zfs_create_013_pos']
+
+[/opt/zfs-tests/tests/functional/cli_root/zfs_destroy]
+tests = ['zfs_destroy_001_pos', 'zfs_destroy_002_pos', 'zfs_destroy_003_pos',
+    'zfs_destroy_004_pos', 'zfs_destroy_005_neg', 'zfs_destroy_006_neg',
+    'zfs_destroy_007_neg', 'zfs_destroy_008_pos', 'zfs_destroy_009_pos',
+    'zfs_destroy_010_pos', 'zfs_destroy_011_pos', 'zfs_destroy_012_pos',
+    'zfs_destroy_013_neg', 'zfs_destroy_014_pos', 'zfs_destroy_015_pos',
+    'zfs_destroy_016_pos']
+
+[/opt/zfs-tests/tests/functional/cli_root/zfs_get]
+tests = ['zfs_get_001_pos', 'zfs_get_002_pos', 'zfs_get_003_pos',
+    'zfs_get_004_pos', 'zfs_get_005_neg', 'zfs_get_006_neg', 'zfs_get_007_neg',
+    'zfs_get_008_pos', 'zfs_get_009_pos', 'zfs_get_010_neg']
+
+[/opt/zfs-tests/tests/functional/cli_root/zfs_inherit]
+tests = ['zfs_inherit_001_neg', 'zfs_inherit_002_neg', 'zfs_inherit_003_pos']
+
+[/opt/zfs-tests/tests/functional/cli_root/zfs_mount]
+tests = ['zfs_mount_001_pos', 'zfs_mount_002_pos', 'zfs_mount_003_pos',
+    'zfs_mount_004_pos', 'zfs_mount_005_pos', 'zfs_mount_006_pos',
+    'zfs_mount_007_pos', 'zfs_mount_008_pos', 'zfs_mount_009_neg',
+    'zfs_mount_010_neg', 'zfs_mount_011_neg', 'zfs_mount_all_001_pos']
+
+[/opt/zfs-tests/tests/functional/cli_root/zfs_promote]
+tests = ['zfs_promote_001_pos', 'zfs_promote_002_pos', 'zfs_promote_003_pos',
+    'zfs_promote_004_pos', 'zfs_promote_005_pos', 'zfs_promote_006_neg',
+    'zfs_promote_007_neg', 'zfs_promote_008_pos']
+
+[/opt/zfs-tests/tests/functional/cli_root/zfs_property]
+tests = ['zfs_written_property_001_pos']
+
+[/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_007_neg', 'zfs_receive_008_pos', 'zfs_receive_009_neg']
+
+[/opt/zfs-tests/tests/functional/cli_root/zfs_rename]
+tests = ['zfs_rename_001_pos', 'zfs_rename_002_pos', 'zfs_rename_003_pos',
+    'zfs_rename_004_neg', 'zfs_rename_005_neg', 'zfs_rename_006_pos',
+    'zfs_rename_007_pos', 'zfs_rename_008_pos', 'zfs_rename_009_neg',
+    'zfs_rename_010_neg', 'zfs_rename_011_pos', 'zfs_rename_012_neg',
+    'zfs_rename_013_pos']
+
+[/opt/zfs-tests/tests/functional/cli_root/zfs_reservation]
+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']
+
+[/opt/zfs-tests/tests/functional/cli_root/zfs_send]
+tests = ['zfs_send_001_pos', 'zfs_send_002_pos', 'zfs_send_003_pos',
+    'zfs_send_004_neg', 'zfs_send_005_pos', 'zfs_send_006_pos']
+
+[/opt/zfs-tests/tests/functional/cli_root/zfs_set]
+tests = ['cache_001_pos', 'cache_002_neg', 'canmount_001_pos',
+    'canmount_002_pos', 'canmount_003_pos', 'canmount_004_pos',
+    'checksum_001_pos', 'compression_001_pos', 'mountpoint_001_pos',
+    'mountpoint_002_pos', 'mountpoint_003_pos', 'onoffs_001_pos',
+    'property_alias_001_pos', 'readonly_001_pos', 'reservation_001_neg',
+    'ro_props_001_pos', 'share_mount_001_neg', 'snapdir_001_pos',
+    'user_property_001_pos', 'user_property_002_pos', 'user_property_003_neg',
+    'user_property_004_pos', 'version_001_neg', 'zfs_set_001_neg',
+    'zfs_set_002_neg', 'zfs_set_003_neg']
+
+[/opt/zfs-tests/tests/functional/cli_root/zfs_share]
+tests = ['zfs_share_001_pos', 'zfs_share_002_pos', 'zfs_share_003_pos',
+    'zfs_share_004_pos', 'zfs_share_005_pos', 'zfs_share_006_pos',
+    'zfs_share_007_neg', 'zfs_share_008_neg', 'zfs_share_009_neg',
+    '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']
+
+[/opt/zfs-tests/tests/functional/cli_root/zfs_unmount]
+tests = ['zfs_unmount_001_pos', 'zfs_unmount_002_pos', 'zfs_unmount_003_pos',
+    'zfs_unmount_004_pos', 'zfs_unmount_005_pos', 'zfs_unmount_006_pos',
+    'zfs_unmount_007_neg', 'zfs_unmount_008_neg', 'zfs_unmount_009_pos',
+    'zfs_unmount_all_001_pos']
+
+[/opt/zfs-tests/tests/functional/cli_root/zfs_unshare]
+tests = ['zfs_unshare_001_pos', 'zfs_unshare_002_pos', 'zfs_unshare_003_pos',
+    'zfs_unshare_004_neg', 'zfs_unshare_005_neg']
+
+[/opt/zfs-tests/tests/functional/cli_root/zfs_upgrade]
+tests = ['zfs_upgrade_001_pos', 'zfs_upgrade_002_pos', 'zfs_upgrade_003_pos',
+    'zfs_upgrade_004_pos', 'zfs_upgrade_005_pos', 'zfs_upgrade_006_neg',
+    'zfs_upgrade_007_neg']
+
+[/opt/zfs-tests/tests/functional/cli_root/zpool]
+tests = ['zpool_001_neg', 'zpool_002_pos', 'zpool_003_pos']
+
+[/opt/zfs-tests/tests/functional/cli_root/zpool_add]
+tests = ['zpool_add_001_pos', 'zpool_add_002_pos', 'zpool_add_003_pos',
+    'zpool_add_004_pos', 'zpool_add_005_pos', 'zpool_add_006_pos',
+    'zpool_add_007_neg', 'zpool_add_008_neg', 'zpool_add_009_neg']
+
+[/opt/zfs-tests/tests/functional/cli_root/zpool_attach]
+tests = ['zpool_attach_001_neg']
+
+[/opt/zfs-tests/tests/functional/cli_root/zpool_clear]
+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',
+    'zpool_create_features_001_pos', 'zpool_create_features_002_pos',
+    'zpool_create_features_003_pos', 'zpool_create_features_004_neg']
+
+[/opt/zfs-tests/tests/functional/cli_root/zpool_destroy]
+tests = ['zpool_destroy_001_pos', 'zpool_destroy_002_pos',
+    'zpool_destroy_003_neg']
+pre =
+post =
+
+[/opt/zfs-tests/tests/functional/cli_root/zpool_detach]
+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']
+
+[/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']
+
+[/opt/zfs-tests/tests/functional/cli_root/zpool_get]
+tests = ['zpool_get_001_pos', 'zpool_get_002_pos', 'zpool_get_003_pos',
+    'zpool_get_004_neg']
+
+[/opt/zfs-tests/tests/functional/cli_root/zpool_history]
+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',
+    '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',
+    'zpool_import_rename_001_pos']
+
+[/opt/zfs-tests/tests/functional/cli_root/zpool_offline]
+tests = ['zpool_offline_001_pos', 'zpool_offline_002_neg']
+
+[/opt/zfs-tests/tests/functional/cli_root/zpool_online]
+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']
+
+[/opt/zfs-tests/tests/functional/cli_root/zpool_replace]
+tests = ['zpool_replace_001_neg']
+
+[/opt/zfs-tests/tests/functional/cli_root/zpool_scrub]
+tests = ['zpool_scrub_001_neg', 'zpool_scrub_002_pos', 'zpool_scrub_003_pos',
+    'zpool_scrub_004_pos', 'zpool_scrub_005_pos']
+
+[/opt/zfs-tests/tests/functional/cli_root/zpool_set]
+tests = ['zpool_set_001_pos', 'zpool_set_002_neg', 'zpool_set_003_neg']
+pre =
+post =
+
+[/opt/zfs-tests/tests/functional/cli_root/zpool_status]
+tests = ['zpool_status_001_pos', 'zpool_status_002_pos']
+
+[/opt/zfs-tests/tests/functional/cli_root/zpool_upgrade]
+tests = ['zpool_upgrade_001_pos', 'zpool_upgrade_002_pos',
+    'zpool_upgrade_003_pos', 'zpool_upgrade_004_pos', 'zpool_upgrade_005_neg',
+    '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/nopwrite]
+tests = ['nopwrite_copies', 'nopwrite_mtime', 'nopwrite_negative',
+    'nopwrite_promoted_clone', 'nopwrite_recsize', 'nopwrite_sync',
+    'nopwrite_varying_compression', 'nopwrite_volume']
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/usr/src/test/zfs-tests/runfiles/openindiana.run	Wed Dec 05 22:04:50 2012 -0500
@@ -0,0 +1,272 @@
+#
+# 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) 2012 by Delphix. All rights reserved.
+#
+
+[DEFAULT]
+pre = setup
+quiet = False
+pre_user = root
+user = root
+timeout = 600
+post_user = root
+post = cleanup
+outputdir = /var/tmp/test_results
+
+[/opt/zfs-tests/tests/functional/acl/cifs]
+tests = ['cifs_attr_001_pos', 'cifs_attr_002_pos', 'cifs_attr_003_pos']
+
+[/opt/zfs-tests/tests/functional/acl/nontrivial]
+tests = ['zfs_acl_chmod_001_neg', 'zfs_acl_chmod_002_pos',
+    'zfs_acl_chmod_aclmode_001_pos', 'zfs_acl_chmod_compact_001_pos',
+    'zfs_acl_chmod_delete_001_pos', 'zfs_acl_chmod_inherit_001_pos',
+    'zfs_acl_chmod_inherit_002_neg', 'zfs_acl_chmod_inherit_002_pos',
+    'zfs_acl_chmod_inherit_003_pos', 'zfs_acl_chmod_inherit_004_pos',
+    'zfs_acl_chmod_owner_001_pos', 'zfs_acl_chmod_rwacl_001_pos',
+    'zfs_acl_chmod_rwx_001_pos', 'zfs_acl_chmod_rwx_002_pos',
+    'zfs_acl_chmod_rwx_003_pos', 'zfs_acl_chmod_rwx_004_pos',
+    'zfs_acl_chmod_xattr_001_pos', 'zfs_acl_chmod_xattr_002_pos',
+    'zfs_acl_cp_001_pos', 'zfs_acl_cp_002_pos', 'zfs_acl_cpio_001_pos',
+    'zfs_acl_cpio_002_pos', 'zfs_acl_find_001_pos', 'zfs_acl_ls_001_pos',
+    'zfs_acl_mv_001_pos', 'zfs_acl_tar_001_pos', 'zfs_acl_tar_002_pos']
+
+[/opt/zfs-tests/tests/functional/acl/trivial]
+tests = ['zfs_acl_chmod_001_pos', 'zfs_acl_compress_001_pos',
+    'zfs_acl_cp_001_pos', 'zfs_acl_cp_002_neg', 'zfs_acl_cp_003_neg',
+    'zfs_acl_find_001_pos', 'zfs_acl_find_002_neg', 'zfs_acl_ls_001_pos',
+    'zfs_acl_ls_002_neg', 'zfs_acl_mv_001_pos', 'zfs_acl_pack_001_pos',
+    'zfs_acl_pax_001_pos', 'zfs_acl_pax_002_pos', 'zfs_acl_pax_003_pos',
+    'zfs_acl_pax_004_pos', 'zfs_acl_pax_005_pos', 'zfs_acl_pax_006_pos',
+    'zfs_acl_tar_001_pos', 'zfs_acl_tar_002_neg']
+
+[/opt/zfs-tests/tests/functional/atime]
+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']
+pre =
+post =
+
+[/opt/zfs-tests/tests/functional/cli_root/zdb]
+tests = ['zdb_001_neg']
+pre =
+post =
+
+[/opt/zfs-tests/tests/functional/cli_root/zfs]
+tests = ['zfs_001_neg', 'zfs_002_pos', 'zfs_003_neg']
+
+[/opt/zfs-tests/tests/functional/cli_root/zfs_clone]
+tests = ['zfs_clone_001_neg', 'zfs_clone_002_pos', 'zfs_clone_003_pos',
+    'zfs_clone_004_pos', 'zfs_clone_005_pos', 'zfs_clone_006_pos',
+    'zfs_clone_007_pos', 'zfs_clone_008_neg', 'zfs_clone_009_neg',
+    'zfs_clone_010_pos']
+
+[/opt/zfs-tests/tests/functional/cli_root/zfs_copies]
+tests = ['zfs_copies_001_pos', 'zfs_copies_002_pos', 'zfs_copies_003_pos',
+    'zfs_copies_004_neg', 'zfs_copies_005_neg', 'zfs_copies_006_pos']
+
+[/opt/zfs-tests/tests/functional/cli_root/zfs_create]
+tests = ['zfs_create_001_pos', 'zfs_create_002_pos', 'zfs_create_003_pos',
+    'zfs_create_004_pos', 'zfs_create_005_pos', 'zfs_create_006_pos',
+    'zfs_create_007_pos', 'zfs_create_008_neg', 'zfs_create_009_neg',
+    'zfs_create_010_neg', 'zfs_create_011_pos', 'zfs_create_012_pos',
+    'zfs_create_013_pos']
+
+[/opt/zfs-tests/tests/functional/cli_root/zfs_destroy]
+tests = ['zfs_destroy_001_pos', 'zfs_destroy_002_pos', 'zfs_destroy_003_pos',
+    'zfs_destroy_004_pos', 'zfs_destroy_005_neg', 'zfs_destroy_006_neg',
+    'zfs_destroy_007_neg', 'zfs_destroy_008_pos', 'zfs_destroy_009_pos',
+    'zfs_destroy_010_pos', 'zfs_destroy_011_pos', 'zfs_destroy_012_pos',
+    'zfs_destroy_013_neg', 'zfs_destroy_014_pos', 'zfs_destroy_015_pos',
+    'zfs_destroy_016_pos']
+
+[/opt/zfs-tests/tests/functional/cli_root/zfs_get]
+tests = ['zfs_get_001_pos', 'zfs_get_002_pos', 'zfs_get_003_pos',
+    'zfs_get_004_pos', 'zfs_get_005_neg', 'zfs_get_006_neg', 'zfs_get_007_neg',
+    'zfs_get_008_pos', 'zfs_get_009_pos', 'zfs_get_010_neg']
+
+[/opt/zfs-tests/tests/functional/cli_root/zfs_inherit]
+tests = ['zfs_inherit_001_neg', 'zfs_inherit_002_neg', 'zfs_inherit_003_pos']
+
+[/opt/zfs-tests/tests/functional/cli_root/zfs_mount]
+tests = ['zfs_mount_001_pos', 'zfs_mount_002_pos', 'zfs_mount_003_pos',
+    'zfs_mount_004_pos', 'zfs_mount_005_pos', 'zfs_mount_006_pos',
+    'zfs_mount_007_pos', 'zfs_mount_008_pos', 'zfs_mount_009_neg',
+    'zfs_mount_010_neg', 'zfs_mount_011_neg', 'zfs_mount_all_001_pos']
+
+[/opt/zfs-tests/tests/functional/cli_root/zfs_promote]
+tests = ['zfs_promote_001_pos', 'zfs_promote_002_pos', 'zfs_promote_003_pos',
+    'zfs_promote_004_pos', 'zfs_promote_005_pos', 'zfs_promote_006_neg',
+    'zfs_promote_007_neg', 'zfs_promote_008_pos']
+
+[/opt/zfs-tests/tests/functional/cli_root/zfs_property]
+tests = ['zfs_written_property_001_pos']
+
+[/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_007_neg', 'zfs_receive_008_pos', 'zfs_receive_009_neg']
+
+[/opt/zfs-tests/tests/functional/cli_root/zfs_rename]
+tests = ['zfs_rename_001_pos', 'zfs_rename_002_pos', 'zfs_rename_003_pos',
+    'zfs_rename_004_neg', 'zfs_rename_005_neg', 'zfs_rename_006_pos',
+    'zfs_rename_007_pos', 'zfs_rename_008_pos', 'zfs_rename_009_neg',
+    'zfs_rename_010_neg', 'zfs_rename_011_pos', 'zfs_rename_012_neg',
+    'zfs_rename_013_pos']
+
+[/opt/zfs-tests/tests/functional/cli_root/zfs_reservation]
+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']
+
+[/opt/zfs-tests/tests/functional/cli_root/zfs_send]
+tests = ['zfs_send_001_pos', 'zfs_send_002_pos', 'zfs_send_003_pos',
+    'zfs_send_004_neg', 'zfs_send_005_pos', 'zfs_send_006_pos']
+
+[/opt/zfs-tests/tests/functional/cli_root/zfs_set]
+tests = ['cache_001_pos', 'cache_002_neg', 'canmount_001_pos',
+    'canmount_002_pos', 'canmount_003_pos', 'canmount_004_pos',
+    'checksum_001_pos', 'compression_001_pos', 'mountpoint_001_pos',
+    'mountpoint_002_pos', 'mountpoint_003_pos', 'onoffs_001_pos',
+    'property_alias_001_pos', 'readonly_001_pos', 'reservation_001_neg',
+    'ro_props_001_pos', 'share_mount_001_neg', 'snapdir_001_pos',
+    'user_property_001_pos', 'user_property_002_pos', 'user_property_003_neg',
+    'user_property_004_pos', 'version_001_neg', 'zfs_set_001_neg',
+    'zfs_set_002_neg', 'zfs_set_003_neg']
+
+[/opt/zfs-tests/tests/functional/cli_root/zfs_share]
+tests = ['zfs_share_001_pos', 'zfs_share_002_pos', 'zfs_share_003_pos',
+    'zfs_share_004_pos', 'zfs_share_005_pos', 'zfs_share_006_pos',
+    'zfs_share_007_neg', 'zfs_share_008_neg', 'zfs_share_009_neg',
+    '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']
+
+[/opt/zfs-tests/tests/functional/cli_root/zfs_unmount]
+tests = ['zfs_unmount_001_pos', 'zfs_unmount_002_pos', 'zfs_unmount_003_pos',
+    'zfs_unmount_004_pos', 'zfs_unmount_005_pos', 'zfs_unmount_006_pos',
+    'zfs_unmount_007_neg', 'zfs_unmount_008_neg', 'zfs_unmount_009_pos',
+    'zfs_unmount_all_001_pos']
+
+[/opt/zfs-tests/tests/functional/cli_root/zfs_unshare]
+tests = ['zfs_unshare_001_pos', 'zfs_unshare_002_pos', 'zfs_unshare_003_pos',
+    'zfs_unshare_004_neg', 'zfs_unshare_005_neg']
+
+[/opt/zfs-tests/tests/functional/cli_root/zfs_upgrade]
+tests = ['zfs_upgrade_001_pos', 'zfs_upgrade_002_pos', 'zfs_upgrade_003_pos',
+    'zfs_upgrade_004_pos', 'zfs_upgrade_005_pos', 'zfs_upgrade_006_neg',
+    'zfs_upgrade_007_neg']
+
+[/opt/zfs-tests/tests/functional/cli_root/zpool]
+tests = ['zpool_001_neg', 'zpool_002_pos', 'zpool_003_pos']
+
+[/opt/zfs-tests/tests/functional/cli_root/zpool_add]
+tests = ['zpool_add_001_pos', 'zpool_add_002_pos', 'zpool_add_003_pos',
+    'zpool_add_004_pos', 'zpool_add_005_pos', 'zpool_add_006_pos',
+    'zpool_add_007_neg', 'zpool_add_008_neg', 'zpool_add_009_neg']
+
+[/opt/zfs-tests/tests/functional/cli_root/zpool_attach]
+tests = ['zpool_attach_001_neg']
+
+[/opt/zfs-tests/tests/functional/cli_root/zpool_clear]
+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',
+    'zpool_create_features_001_pos', 'zpool_create_features_002_pos',
+    'zpool_create_features_003_pos', 'zpool_create_features_004_neg']
+
+[/opt/zfs-tests/tests/functional/cli_root/zpool_destroy]
+tests = ['zpool_destroy_001_pos', 'zpool_destroy_002_pos',
+    'zpool_destroy_003_neg']
+pre =
+post =
+
+[/opt/zfs-tests/tests/functional/cli_root/zpool_detach]
+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']
+
+[/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']
+
+[/opt/zfs-tests/tests/functional/cli_root/zpool_get]
+tests = ['zpool_get_001_pos', 'zpool_get_002_pos', 'zpool_get_003_pos',
+    'zpool_get_004_neg']
+
+[/opt/zfs-tests/tests/functional/cli_root/zpool_history]
+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',
+    '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',
+    'zpool_import_rename_001_pos']
+
+[/opt/zfs-tests/tests/functional/cli_root/zpool_offline]
+tests = ['zpool_offline_001_pos', 'zpool_offline_002_neg']
+
+[/opt/zfs-tests/tests/functional/cli_root/zpool_online]
+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']
+
+[/opt/zfs-tests/tests/functional/cli_root/zpool_replace]
+tests = ['zpool_replace_001_neg']
+
+[/opt/zfs-tests/tests/functional/cli_root/zpool_scrub]
+tests = ['zpool_scrub_001_neg', 'zpool_scrub_002_pos', 'zpool_scrub_003_pos',
+    'zpool_scrub_004_pos', 'zpool_scrub_005_pos']
+
+[/opt/zfs-tests/tests/functional/cli_root/zpool_set]
+tests = ['zpool_set_001_pos', 'zpool_set_002_neg', 'zpool_set_003_neg']
+pre =
+post =
+
+[/opt/zfs-tests/tests/functional/cli_root/zpool_status]
+tests = ['zpool_status_001_pos', 'zpool_status_002_pos']
+
+[/opt/zfs-tests/tests/functional/cli_root/zpool_upgrade]
+tests = ['zpool_upgrade_001_pos', 'zpool_upgrade_002_pos',
+    'zpool_upgrade_003_pos', 'zpool_upgrade_004_pos', 'zpool_upgrade_005_neg',
+    '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/nopwrite]
+tests = ['nopwrite_copies', 'nopwrite_mtime', 'nopwrite_negative',
+    'nopwrite_promoted_clone', 'nopwrite_recsize', 'nopwrite_sync',
+    'nopwrite_varying_compression', 'nopwrite_volume']
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/usr/src/test/zfs-tests/tests/Makefile	Wed Dec 05 22:04:50 2012 -0500
@@ -0,0 +1,20 @@
+#
+# 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) 2012 by Delphix. All rights reserved.
+#
+
+.PARALLEL: $(SUBDIRS)
+
+SUBDIRS = functional stress
+
+include $(SRC)/test/Makefile.com
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/usr/src/test/zfs-tests/tests/functional/Makefile	Wed Dec 05 22:04:50 2012 -0500
@@ -0,0 +1,25 @@
+#
+# 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) 2012 by Delphix. All rights reserved.
+#
+
+.PARALLEL: $(SUBDIRS)
+
+SUBDIRS = acl \
+	atime \
+	bootfs \
+	cli_root \
+	nopwrite \
+	truncate
+
+include $(SRC)/test/Makefile.com
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/usr/src/test/zfs-tests/tests/functional/acl/Makefile	Wed Dec 05 22:04:50 2012 -0500
@@ -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) 2012 by Delphix. All rights reserved.
+#
+
+.PARALLEL: $(SUBDIRS)
+
+include $(SRC)/Makefile.master
+
+ROOTOPTPKG = $(ROOT)/opt/zfs-tests
+TESTDIR = $(ROOTOPTPKG)/tests/functional/acl
+
+PROGS = acl.cfg \
+	acl_common.kshlib
+
+CMDS = $(PROGS:%=$(TESTDIR)/%)
+$(CMDS) := FILEMODE = 0555
+
+all lint clean clobber:
+
+install: $(CMDS)
+
+$(CMDS): $(TESTDIR)
+
+$(TESTDIR):
+	$(INS.dir)
+
+$(TESTDIR)/%: %
+	$(INS.file)
+
+SUBDIRS = cifs nontrivial trivial
+
+include $(SRC)/test/Makefile.com
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/usr/src/test/zfs-tests/tests/functional/acl/acl.cfg	Wed Dec 05 22:04:50 2012 -0500
@@ -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 2008 Sun Microsystems, Inc.  All rights reserved.
+# Use is subject to license terms.
+#
+
+. $STF_SUITE/include/libtest.shlib
+
+export NISSTAFILE=/var/tmp/nis_state
+export TESTFILE=testfile$$
+export TESTFILE0=testfile0.$$
+export TESTFILE2=testfile2.$$
+
+# Define super user 'admin'
+export ZFS_ACL_ADMIN=admin
+
+export ZFS_ACL_STAFF_GROUP=zfsgrp
+export ZFS_ACL_STAFF1=staff1
+export ZFS_ACL_STAFF2=staff2
+
+export ZFS_ACL_OTHER_GROUP=othergrp
+export ZFS_ACL_OTHER1=other1
+export ZFS_ACL_OTHER2=other2
+
+# Define the current user who run 'usr_exec'
+export ZFS_ACL_CUR_USER=""
+
+# Define global error string
+export ZFS_ACL_ERR_STR=""
+
+# Define test file and test directory which will be operated by chmod
+export testfile=$TESTDIR/testfile
+export testdir=$TESTDIR/testdir
+
+# Define several directories for trivial ACLs function test.
+export RES_DIR=$TESTDIR/RES
+export INI_DIR=$TESTDIR/INIT
+export TST_DIR=$TESTDIR/TEST
+export TMP_DIR=$TESTDIR/TMP
+
+# Define test files and their attributes files number for trivial
+# ACLs function test
+export NUM_FILE=5
+export NUM_ATTR=10
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/usr/src/test/zfs-tests/tests/functional/acl/acl_common.kshlib	Wed Dec 05 22:04:50 2012 -0500
@@ -0,0 +1,626 @@
+#
+# CDDL HEADER START
+#
+# The contents of this file are subject to the terms of the
+# Common Development and Distribution License (the "License").
+# You may not use this file except in compliance with the License.
+#
+# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
+# or http://www.opensolaris.org/os/licensing.
+# See the License for the specific language governing permissions
+# and limitations under the License.
+#
+# When distributing Covered Code, include this CDDL HEADER in each
+# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
+# If applicable, add the following below this CDDL 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.
+#
+
+. $STF_SUITE/tests/functional/acl/acl.cfg
+. $STF_SUITE/include/libtest.shlib
+
+#
+# Get the given file/directory access mode
+#
+# $1 object -- file or directroy
+#
+function get_mode #<obj>
+{
+	typeset obj=$1
+	if (( ${#obj} == 0 )); then
+		return 1
+	fi
+
+	$LS -ld $obj | $AWK '{print $1}'
+}
+
+#
+# Get the given file/directory ACL
+#
+# $1 object -- file or directroy
+#
+function get_acl #<obj>
+{
+        typeset obj=$1
+	if (( ${#obj} == 0 )); then
+		return 1
+	fi
+
+	$LS -vd $obj | $NAWK '(NR != 1) {print $0}'
+}
+
+#
+# Get the given file/directory ACL
+#
+# $1 object -- file or directroy
+#
+function get_compact_acl #<obj>
+{
+        typeset obj=$1
+	if (( ${#obj} == 0 )); then
+		return 1
+	fi
+
+	$LS -Vd $obj | $NAWK '(NR != 1) {print $0}'
+}
+
+#
+# Check the given two files/directories have the same ACLs
+#
+# Return 0, if source object acl is equal to target object acl.
+#
+# $1 source object
+# $2 target object
+#
+function compare_acls #<src> <tgt>
+{
+        typeset src=$1
+        typeset tgt=$2
+
+	(( ${#src} == 0 || ${#tgt} == 0 )) && return 1
+	[[ $src == $tgt ]] && return 0
+
+	typeset tmpsrc=/tmp/compare_acls.src.$$
+	typeset tmptgt=/tmp/compare_acls.tgt.$$
+
+	get_acl $src > $tmpsrc
+	get_acl $tgt > $tmptgt
+	typeset -i ret=0
+	$DIFF $tmpsrc $tmptgt > /dev/null 2>&1
+	ret=$?
+	$RM -f $tmpsrc $tmptgt
+
+	if (( ret != 0 )); then
+		return $ret
+	fi
+
+	get_compact_acl $src > $tmpsrc
+	get_compact_acl $tgt > $tmptgt
+	$DIFF $tmpsrc $tmptgt > /dev/null 2>&1
+	ret=$?
+	$RM -f $tmpsrc $tmptgt
+
+	return $ret
+}
+
+#
+# Check that the given two objects have the same modes.
+# Return 0, if their modes are equal with each other. Otherwise, return 1.
+#
+# $1 source object
+# $2 target object
+#
+function compare_modes #<src> <tgt>
+{
+        typeset src=$1
+        typeset tgt=$2
+        typeset -i i=0
+        set -A mode
+
+	(( ${#src} == 0 || ${#tgt} == 0 )) && return 1
+	[[ $src == $tgt ]] && return 0
+
+	typeset obj
+        for obj in $src $tgt
+        do
+                mode[i]=$(get_mode $obj)
+
+                (( i = i + 1 ))
+        done
+
+        [[ ${mode[0]} != ${mode[1]} ]] && return 1
+
+        return 0
+}
+
+#
+# Check that the given two objects have the same xattrs.
+# Return 0, if their xattrs are equal with each other. Otherwise, return 1.
+#
+# $1 source object
+# $2 target object
+#
+function compare_xattrs #<src> <tgt>
+{
+        typeset src=$1
+        typeset tgt=$2
+
+	(( ${#src} == 0 || ${#tgt} == 0 )) && return 1
+	[[ $src == $tgt ]] && return 0
+
+	typeset tmpsrc=/tmp/compare_xattrs.src.$$
+	typeset tmptgt=/tmp/compare_xattrs.tgt.$$
+
+	get_xattr $src > $tmpsrc
+	get_xattr $tgt > $tmptgt
+	typeset -i ret=0
+	$DIFF $tmpsrc $tmptgt > /dev/null 2>&1
+	ret=$?
+	$RM -f $tmpsrc $tmptgt
+
+        return $ret
+}
+
+#
+# Check '+' is set for a given file/directory with 'ls [-l]' command
+#
+# $1 object -- file or directory.
+#
+function plus_sign_check_l #<obj>
+{
+	typeset obj=$1
+	if (( ${#obj} == 0 )); then
+		return 1
+	fi
+
+	$LS -ld $obj | $AWK '{print $1}' | $GREP "+\>" > /dev/null
+
+        return $?
+}
+
+#
+# Check '+' is set for a given file/directory with 'ls [-v]' command
+#
+# $1 object -- file or directory.
+#
+function plus_sign_check_v #<obj>
+{
+	typeset obj=$1
+	if (( ${#obj} == 0 )); then
+		return 1
+	fi
+
+	$LS -vd $obj | $NAWK '(NR == 1) {print $1}' | $GREP "+\>" > /dev/null
+
+        return $?
+}
+
+#
+# A wrapper function of c program
+#
+# $1 legal login name
+# $2-n commands and options
+#
+function chgusr_exec #<login_name> <commands> [...]
+{
+	$CHG_USR_EXEC $@
+	return $?
+}
+
+#
+# Export the current user for the following usr_exec operating.
+#
+# $1 legal login name
+#
+function set_cur_usr #<login_name>
+{
+	export ZFS_ACL_CUR_USER=$1
+}
+
+#
+# Run commands by $ZFS_ACL_CUR_USER
+#
+# $1-n commands and options
+#
+function usr_exec #<commands> [...]
+{
+	$CHG_USR_EXEC "$ZFS_ACL_CUR_USER" $@
+	return $?
+}
+
+#
+# Count how many ACEs for the speficied file or directory.
+#
+# $1 file or directroy name
+#
+function count_ACE #<file or dir name>
+{
+	if [[ ! -e $1 ]]; then
+		log_note "Need input file or directroy name."
+		return 1
+	fi
+
+	$LS -vd $1 | $NAWK 'BEGIN {count=0}
+			(NR != 1)&&(/[0-9]:/) {count++}
+			END {print count}'
+
+	return 0
+}
+
+#
+# Get specified number ACE content of specified file or directory.
+#
+# $1 file or directory name
+# $2 specified number
+#
+function get_ACE #<file or dir name> <specified number> <verbose|compact>
+{
+	if [[ ! -e $1 || $2 -ge $(count_ACE $1) ]]; then
+		return 1
+	fi
+
+	typeset file=$1
+	typeset -i num=$2
+	typeset format=${3:-verbose}
+	typeset -i next_num=-1
+
+        typeset tmpfile=/tmp/tmp_get_ACE.$$
+        typeset line=""
+	typeset args
+
+	case $format in
+		verbose) args="-vd"
+			;;
+		compact) args="-Vd"
+			;;
+		*) log_fail "Invalid parameter as ($format), " \
+			"only verbose|compact is supported."
+			;;
+	esac
+
+	$LS $args $file > $tmpfile
+	(( $? != 0 )) && log_fail "FAIL: $LS $args $file > $tmpfile"
+	while read line; do
+		[[ -z $line ]] && continue
+		if [[ $args == -vd ]]; then
+			if [[ $line == "$num":* ]]; then
+				(( next_num = num + 1 ))
+			fi
+			if [[ $line == "$next_num":* ]]; then
+				break
+			fi
+			if (( next_num != -1 )); then
+				print -n $line
+			fi
+		else
+			if (( next_num == num )); then
+				print -n $line
+			fi
+			(( next_num += 1 ))
+		fi
+	done < $tmpfile
+
+	$RM -f $tmpfile
+	(( $? != 0 )) && log_fail "FAIL: $RM -f $tmpfile"
+}
+
+#
+# Cleanup exist user/group.
+#
+function cleanup_user_group
+{
+	del_user $ZFS_ACL_ADMIN
+
+	del_user $ZFS_ACL_STAFF1
+	del_user $ZFS_ACL_STAFF2
+	del_group $ZFS_ACL_STAFF_GROUP
+
+	del_user $ZFS_ACL_OTHER1
+	del_user $ZFS_ACL_OTHER2
+	del_group $ZFS_ACL_OTHER_GROUP
+
+	return 0
+}
+
+#
+# Clean up testfile and test directory
+#
+function cleanup
+{
+	if [[ -d $TESTDIR ]]; then
+		cd $TESTDIR
+		$RM -rf $TESTDIR/*
+	fi
+}
+
+#
+# According to specified access or acl_spec, do relevant operating by using the
+# specified user.
+#
+# $1 specified user
+# $2 node
+# $3 acl_spec or access
+#
+function rwx_node #user node acl_spec|access
+{
+	typeset user=$1
+	typeset node=$2
+	typeset acl_spec=$3
+
+	if [[ $user == "" || $node == "" || $acl_spec == "" ]]; then
+		log_note "node or acl_spec are not defined."
+		return 1
+	fi
+
+	if [[ -d $node ]]; then
+		case $acl_spec in
+		*:read_data:*|read_data)
+			chgusr_exec $user $LS -l $node > /dev/null 2>&1
+			return $? ;;
+		*:write_data:*|write_data)
+			if [[ -f ${node}/tmpfile ]]; then
+				log_must $RM -f ${node}/tmpfile
+			fi
+			chgusr_exec $user $TOUCH ${node}/tmpfile > \
+				/dev/null 2>&1
+			return $? ;;
+		*"execute:"*|execute)
+			chgusr_exec $user $FIND $node > /dev/null 2>&1
+			return $? ;;
+		esac
+	else
+		case $acl_spec in
+		*:read_data:*|read_data)
+			chgusr_exec $user $CAT $node > /dev/null 2>&1
+			return $? ;;
+		*:write_data:*|write_data)
+			chgusr_exec $user $DD if=/usr/bin/ls of=$node > \
+				/dev/null 2>&1
+			return $? ;;
+		*"execute:"*|execute)
+			ZFS_ACL_ERR_STR=$(chgusr_exec $user $node 2>&1)
+			return $? ;;
+		esac
+	fi
+}
+
+#
+# Get the given file/directory xattr
+#
+# $1 object -- file or directroy
+#
+function get_xattr #<obj>
+{
+        typeset obj=$1
+	typeset xattr
+	if (( ${#obj} == 0 )); then
+		return 1
+	fi
+
+	for xattr in `$RUNAT $obj $LS | \
+		/usr/xpg4/bin/egrep -v -e SUNWattr_ro -e SUNWattr_rw` ; do
+		$RUNAT $obj $SUM $xattr
+	done
+}
+
+#
+# Get the owner of a file/directory
+#
+function get_owner #node
+{
+	typeset node=$1
+	typeset value
+
+	if [[ -z $node ]]; then
+		log_fail "node are not defined."
+	fi
+
+	if [[ -d $node ]]; then
+		value=$($LS -dl $node | $AWK '{print $3}')
+	elif [[ -e $node ]]; then
+		value=$($LS -l $node | $AWK '{print $3}')
+	fi
+
+	$ECHO $value
+}
+
+#
+# Get the group of a file/directory
+#
+function get_group #node
+{
+	typeset node=$1
+	typeset value
+
+	if [[ -z $node ]]; then
+		log_fail "node are not defined."
+	fi
+
+	if [[ -d $node ]]; then
+		value=$($LS -dl $node | $AWK '{print $4}')
+	elif [[ -e $node ]]; then
+		value=$($LS -l $node | $AWK '{print $4}')
+	fi
+
+	$ECHO $value
+}
+
+
+#
+# Get the group name that a UID belongs to
+#
+function get_user_group #uid
+{
+	typeset uid=$1
+	typeset value
+
+	if [[ -z $uid ]]; then
+		log_fail "UID not defined."
+	fi
+
+	value=$(id $uid)
+
+	if [[ $? -eq 0 ]]; then
+		value=${value##*\(}
+		value=${value%%\)*}
+		$ECHO $value
+	else
+		log_fail "Invalid UID (uid)."
+	fi
+}
+
+#
+# Get the specified item of the specified string
+#
+# $1:	Item number, count from 0.
+# $2-n: strings
+#
+function getitem
+{
+	typeset -i n=$1
+	shift
+
+	(( n += 1 ))
+	eval echo \${$n}
+}
+
+#
+# This function calculate the specified directory files checksum and write
+# to the specified array.
+#
+# $1 directory in which the files will be cksum.
+# $2 file array name which was used to store file cksum information.
+# $3 attribute array name which was used to store attribute information.
+#
+function cksum_files #<dir> <file_array_name> <attribute_array_name>
+{
+	typeset dir=$1
+	typeset farr_name=$2
+	typeset aarr_name=$3
+
+	[[ ! -d $dir ]] && return
+	typeset oldpwd=$PWD
+	cd $dir
+	typeset files=$($LS file*)
+
+	typeset -i i=0
+	typeset -i n=0
+	while (( i < NUM_FILE )); do
+		typeset f=$(getitem $i $files)
+		eval $farr_name[$i]=\$\(\$CKSUM $f\)
+
+		typeset -i j=0
+		while (( j < NUM_ATTR )); do
+			eval $aarr_name[$n]=\$\(\$RUNAT \$f \$CKSUM \
+				attribute.$j\)
+
+			(( j += 1 ))
+			(( n += 1 ))
+		done
+
+		(( i += 1 ))
+	done
+
+	cd $oldpwd
+}
+
+#
+# This function compare two cksum results array.
+#
+# $1 The array name which stored the cksum before operation.
+# $2 The array name which stored the cksum after operation.
+#
+function compare_cksum #<array1> <array2>
+{
+	typeset before=$1
+	typeset after=$2
+	eval typeset -i count=\${#$before[@]}
+
+	typeset -i i=0
+	while (( i < count )); do
+		eval typeset var1=\${$before[$i]}
+		eval typeset var2=\${$after[$i]}
+
+		if [[ $var1 != $var2 ]]; then
+			return 1
+		fi
+
+		(( i += 1 ))
+	done
+
+	return 0
+}
+
+#
+# This function calculate all the files cksum information in current directory
+# and output them to the specified file.
+#
+# $1 directory from which the files will be cksum.
+# $2 cksum output file
+#
+function record_cksum #<outfile>
+{
+	typeset dir=$1
+	typeset outfile=$2
+
+	[[ ! -d ${outfile%/*} ]] && usr_exec $MKDIR -p ${outfile%/*}
+
+	usr_exec cd $dir ; $FIND . -depth -type f -exec cksum {} \\\; | \
+	    $SORT > $outfile
+	usr_exec cd $dir ; $FIND . -depth -type f -xattr -exec runat {} \
+		cksum attribute* \\\; | $SORT >> $outfile
+}
+
+#
+# The function create_files creates the directories and files that the script
+# will operate on to test extended attribute functionality.
+#
+# $1 The base directory in which to create directories and files.
+#
+function create_files #<directory>
+{
+	typeset basedir=$1
+
+	[[ ! -d $basedir ]] && usr_exec $MKDIR -m 777 $basedir
+	[[ ! -d $RES_DIR  ]] && usr_exec $MKDIR -m 777 $RES_DIR
+	[[ ! -d $INI_DIR ]] && usr_exec $MKDIR -m 777 $INI_DIR
+	[[ ! -d $TST_DIR ]] && usr_exec $MKDIR -m 777 $TST_DIR
+	[[ ! -d $TMP_DIR  ]] && usr_exec $MKDIR -m 777 $TMP_DIR
+
+	#
+	# Create the original file and its attribute files.
+	#
+	[[ ! -a $RES_DIR/file ]] && \
+		usr_exec $FILE_WRITE -o create -f $RES_DIR/file \
+			-b 1024 -d 0 -c 1
+	[[ ! -a $RES_DIR/attribute ]] && \
+		usr_exec $CP $RES_DIR/file $RES_DIR/attribute
+
+	typeset oldpwd=$PWD
+	cd $INI_DIR
+
+	typeset -i i=0
+	while (( i < NUM_FILE )); do
+		typeset dstfile=$INI_DIR/file.$$.$i
+		usr_exec $CP $RES_DIR/file $dstfile
+
+		typeset -i j=0
+		while (( j < NUM_ATTR )); do
+			usr_exec $RUNAT $dstfile \
+				$CP $RES_DIR/attribute ./attribute.$j
+			(( j += 1 ))
+		done
+
+		(( i += 1 ))
+	done
+
+	cd $oldpwd
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/usr/src/test/zfs-tests/tests/functional/acl/cifs/Makefile	Wed Dec 05 22:04:50 2012 -0500
@@ -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) 2012 by Delphix. All rights reserved.
+#
+
+include $(SRC)/Makefile.master
+
+ROOTOPTPKG = $(ROOT)/opt/zfs-tests
+TESTDIR = $(ROOTOPTPKG)/tests/functional/acl/cifs
+
+PROGS = cleanup \
+	setup \
+	cifs_attr_001_pos \
+	cifs_attr_002_pos \
+	cifs_attr_003_pos
+
+FILES = cifs.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	Thu Jan 01 00:00:00 1970 +0000
+++ b/usr/src/test/zfs-tests/tests/functional/acl/cifs/cifs.kshlib	Wed Dec 05 22:04:50 2012 -0500
@@ -0,0 +1,76 @@
+#
+# CDDL HEADER START
+#
+# The contents of this file are subject to the terms of the
+# Common Development and Distribution License (the "License").
+# You may not use this file except in compliance with the License.
+#
+# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
+# or http://www.opensolaris.org/os/licensing.
+# See the License for the specific language governing permissions
+# and limitations under the License.
+#
+# When distributing Covered Code, include this CDDL HEADER in each
+# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
+# If applicable, add the following below this CDDL 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.
+#
+
+. $STF_SUITE/include/libtest.shlib
+
+#
+# Create a file or direcotry
+#
+# $1: The type specified, "file" or "dir"
+# $2: The given node name
+# $3: Owner of the node
+#
+function create_object
+{
+	typeset type=$1
+	typeset object=$2
+	typeset owner=$3
+
+	destroy_object $object
+
+	case $type in
+	dir)
+		$MKDIR -p $object
+		;;
+	file)
+		$ECHO "ZFS test suites" > $object
+		;;
+	esac
+
+	if [[ -n $owner ]]; then
+		$CHOWN $owner $object
+	fi
+	return 0
+}
+
+#
+# Destroy the given node(s)
+#
+# $@: The node(s) need to be destroyed
+#
+function destroy_object
+{
+	for object in $@ ; do
+		if [[ -e $object ]]; then
+
+			# clear_attribute is a common function name,
+			# but each case should have their own implement.
+			log_must clear_attribute $object
+			log_must $RM -rf $object
+		fi
+	done
+	return 0
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/usr/src/test/zfs-tests/tests/functional/acl/cifs/cifs_attr_001_pos.ksh	Wed Dec 05 22:04:50 2012 -0500
@@ -0,0 +1,241 @@
+#!/bin/ksh -p
+#
+# CDDL HEADER START
+#
+# The contents of this file are subject to the terms of the
+# Common Development and Distribution License (the "License").
+# You may not use this file except in compliance with the License.
+#
+# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
+# or http://www.opensolaris.org/os/licensing.
+# See the License for the specific language governing permissions
+# and limitations under the License.
+#
+# When distributing Covered Code, include this CDDL HEADER in each
+# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
+# If applicable, add the following below this CDDL 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.
+#
+
+. $STF_SUITE/tests/functional/acl/acl_common.kshlib
+. $STF_SUITE/tests/functional/acl/cifs/cifs.kshlib
+
+#
+# DESCRIPTION:
+#	Verify the user with write_attributes permission or
+#	PRIV_FILE_OWNER privilege could set/clear DOS attributes.
+#	(Readonly, Hidden, Archive, System)
+#
+# STRATEGY:
+#	1. Loop super user and non-super user to run the test case.
+#	2. Create basedir and a set of subdirectores and files within it.
+#	3. Grant user has write_attributes permission or
+#		PRIV_FILE_OWNER privilege
+#	4. Verify set/clear DOS attributes should succeed.
+#
+
+verify_runnable "both"
+
+function cleanup
+{
+	for fs in $TESTPOOL/$TESTFS $TESTPOOL ; do
+		mtpt=$(get_prop mountpoint $fs)
+		log_must $RM -rf $mtpt/file.* $mtpt/dir.*
+	done
+}
+
+#
+# Set the special attribute to the given node
+#
+# $1: The given node (file/dir)
+# $2: The special attribute to be set
+# $3: Execute username
+#
+function set_attribute
+{
+	typeset object=$1
+	typeset attr=${2:-AHRS}
+	typeset user=$3
+	typeset ret=0
+
+	if [[ -z $object ]]; then
+		log_fail "Object not defined."
+	fi
+
+	if [[ -n $user ]]; then
+		$SU $user -c "$CHMOD S+c${attr} $object"
+		ret=$?
+	else
+		$CHMOD S+c${attr} $object
+		ret=$?
+	fi
+
+	return $ret
+}
+
+#
+# Clear the special attribute to the given node
+#
+# $1: The given node (file/dir)
+# $2: The special attribute to be cleared
+# $3: Execute username
+#
+function clear_attribute
+{
+	typeset object=$1
+	typeset attr=${2:-AHRS}
+	typeset user=$3
+	typeset ret=0
+
+	if [[ -z $object ]]; then
+		log_fail "Object not defined."
+	fi
+
+	if [[ -n $user ]]; then
+		$SU $user -c "$CHMOD S-c${attr} $object"
+		ret=$?
+	else
+		$CHMOD S-c${attr} $object
+		ret=$?
+	fi
+
+	return $ret
+}
+
+#
+# Grant the ace of write_attributes to the given user
+#
+# $1: The given user
+# $2: The given node (file/dir)
+#
+function grant_attr
+{
+	typeset user=$1
+	typeset object=$2
+
+	if [[ -z $user || -z $object ]]; then
+		log_fail "User($user), Object($object) not defined."
+	fi
+
+	# To increase the coverage, here we set 'deny' against
+	# superuser and owner.
+	# Only grant the user explicitly while it's not root neither owner.
+
+	if [[ $user == "root" ]]; then
+		log_must $CHMOD A+user:root:write_attributes:deny $object
+	elif [[ $user == $(get_owner $object) ]]; then
+		if (((RANDOM % 2) == 0)); then
+			log_must $CHMOD A+owner@:write_attributes:deny $object
+		else
+			log_must $CHMOD A+user:$user:write_attributes:deny \
+			    $object
+		fi
+	else
+		log_must $CHMOD A+user:$user:write_attributes:allow $object
+	fi
+	attr_mod="write_attributes"
+}
+
+#
+# Revoke the ace of write_attributes from the given user
+#
+# $1: The given user
+# $2: The given node (file/dir)
+#
+function revoke_attr
+{
+	typeset user=$1
+	typeset object=$2
+
+	if [[ -z $user || -z $object ]]; then
+		log_fail "User($user), Object($object) not defined."
+	fi
+
+	log_must $CHMOD A0- $object
+	attr_mod=
+}
+
+#
+# Invoke the function and verify whether its return code as expected
+#
+# $1: Function be invoked
+# $2: The given node (file/dir)
+# $3: Execute user
+# $4: Option
+#
+function verify_attr
+{
+	typeset func=$1
+	typeset object=$2
+	typeset opt=$3
+	typeset user=$4
+	typeset expect="log_mustnot"
+
+	if [[ -z $func || -z $object ]]; then
+		log_fail "Func($func), Object($object), User($user), \
+		    Opt($opt) not defined."
+	fi
+
+	# If user is superuser or has write_attributes permission or
+	# PRIV_FILE_OWNER privilege, it should log_must,
+	# otherwise log_mustnot.
+
+	if [[ -z $user ||  $user == "root"  || $user == \
+	    $(get_owner $object) || $attr_mod == *"write_attributes"* ]] ; then
+		expect="log_must"
+	fi
+
+	$expect $func $object $opt $user
+}
+
+log_assert "Verify set/clear DOS attributes will succeed while user has " \
+    "write_attributes permission or PRIV_FILE_OWNER privilege"
+log_onexit cleanup
+
+file="file.0"
+dir="dir.0"
+XATTROPTIONS="H S R A"
+
+for fs in $TESTPOOL $TESTPOOL/$TESTFS ; do
+	mtpt=$(get_prop mountpoint $fs)
+	for owner in root $ZFS_ACL_STAFF1 ; do
+
+		create_object "file" $mtpt/$file $owner
+		create_object "dir" $mtpt/$dir $owner
+
+		for object in $mtpt/$file $mtpt/$dir ; do
+			for user in root $ZFS_ACL_STAFF2 ; do
+				for opt in $XATTROPTIONS ; do
+					verify_attr set_attribute \
+					    $object $opt $user
+					verify_attr clear_attribute \
+					    $object $opt $user
+				done
+				log_must grant_attr $user $object
+				for opt in $XATTROPTIONS ; do
+					verify_attr set_attribute \
+					    $object $opt $user
+					verify_attr clear_attribute \
+					    $object $opt $user
+				done
+				log_must revoke_attr $user $object
+			done
+		done
+		destroy_object $mtpt/$file $mtpt/$dir
+	done
+done
+
+log_pass "Set/Clear DOS attributes succeed while user has " \
+    "write_attributes permission or PRIV_FILE_OWNER privilege"
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/usr/src/test/zfs-tests/tests/functional/acl/cifs/cifs_attr_002_pos.ksh	Wed Dec 05 22:04:50 2012 -0500
@@ -0,0 +1,208 @@
+#!/bin/ksh -p
+#
+# CDDL HEADER START
+#
+# The contents of this file are subject to the terms of the
+# Common Development and Distribution License (the "License").
+# You may not use this file except in compliance with the License.
+#
+# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
+# or http://www.opensolaris.org/os/licensing.
+# See the License for the specific language governing permissions
+# and limitations under the License.
+#
+# When distributing Covered Code, include this CDDL HEADER in each
+# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
+# If applicable, add the following below this CDDL 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.
+#
+
+. $STF_SUITE/tests/functional/acl/acl_common.kshlib
+. $STF_SUITE/tests/functional/acl/cifs/cifs.kshlib
+
+#
+# DESCRIPTION:
+#	Verify the user with PRIV_FILE_FLAG_SET/PRIV_FILE_FLAG_CLEAR
+#	could set/clear BSD'ish attributes.
+#	(Immutable, nounlink, and appendonly)
+#
+# STRATEGY:
+#	1. Loop super user and non-super user to run the test case.
+#	2. Create basedir and a set of subdirectores and files within it.
+#	3. Grant user has PRIV_FILE_FLAG_SET/PRIV_FILE_FLAG_CLEAR separately.
+#	4. Verify set/clear BSD'ish attributes should succeed.
+#
+
+verify_runnable "global"
+
+function cleanup
+{
+	$RM -f $mntpt/file $mntpt/dir || log_fail
+	    "$($LS -d/ c $mntpt/file $mntpt/dir)"
+
+	log_must $CP $orig_user_attr /etc/user_attr
+	log_must $RM -f $orig_user_attr
+}
+
+function try
+{
+	typeset obj=$1		# The file or dir to operate on
+	typeset attr=$2		# The attribute to set or clear
+	typeset user=$3		# The user to run the command as
+	typeset priv=$4		# What privilege to run with if non-root
+	typeset op=$5		# Whether to set or clear the attribute
+
+	typeset cmd="$CHMOD $op$attr $obj"
+
+	#
+	# No one can add 'q' (av_quarantine) to a directory. root can do
+	# anything else. A regular user can remove no attributes without the
+	# 'all' privilege, and can add attributes (other than 'q' on a
+	# directory) with the 'file_flag_set' or 'all' privileges.
+	#
+	if [[ $user == 'root' ]]; then
+		if [[ $attr =~ 'q' && -d $obj && $op == $add ]]; then
+			log_mustnot $cmd
+		else
+			log_must $cmd
+		fi
+	else
+		if [[ $attr =~ 'q' && -d $obj && $op == $add ]]; then
+			log_mustnot $SU $user -c "$cmd"
+		else
+			if [[ $op == $add ]]; then
+				if [[ -n $priv ]]; then
+					log_must $SU $user -c "$cmd"
+				else
+					log_mustnot $SU $user -c "$cmd"
+				fi
+			else
+				if [[ $attr = 'q' && -d $obj ]]; then
+					log_must $SU $user -c "$cmd"
+				elif [[ $priv =~ 'all' ]]; then
+					log_must $SU $user -c "$cmd"
+				else
+					log_mustnot $SU $user -c "$cmd"
+					#
+					# Remove the attribute, so the next
+					# iteration starts with a known state.
+					#
+					log_must $cmd
+				fi
+			fi
+		fi
+	fi
+
+
+	# Can't add av_quarantine to a directory, so don't check for that
+	[[ $attr == 'q' && $op == $add && -d $obj ]] && return
+	chk_attr $op $obj $attr
+}
+
+function chk_attr
+{
+	typeset op=$1
+	typeset obj=$2
+	typeset attr=$3
+
+	# Extract the attribute string - just the text inside the braces
+	typeset attrstr="$($LS -d/ c $obj | $SED '1d; s/.*{\(.*\)}.*/\1/g')"
+
+	if [[ $op == $add ]]; then
+		[[ $attrstr =~ $attr ]] || log_fail "$op $attr -> $attrstr"
+	else
+		[[ $attrstr =~ $attr ]] && log_fail "$op $attr -> $attrstr"
+	fi
+}
+
+#
+# Grant the privset to the given user
+#
+# $1: The given user
+# $2: The given privset
+#
+function grant_priv
+{
+	typeset user=$1
+	typeset priv=$2
+
+	if [[ -z $user || -z $priv ]]; then
+		log_fail "User($user), Priv($priv) not defined."
+	fi
+
+	priv_mod=",$priv"
+
+	# If we're root, don't modify /etc/user_attr
+	[[ $user == 'root' ]] && return 0
+
+	$ECHO "$user::::type=normal;defaultpriv=basic$priv_mod" >> \
+	    /etc/user_attr
+	return $?
+}
+
+#
+# Revoke the all additional privset from the given user
+#
+# $1: The given user
+#
+function reset_privs
+{
+	typeset user=$1
+
+	if [[ -z $user ]]; then
+		log_fail "User not defined."
+	fi
+
+	priv_mod=
+
+	$CP $orig_user_attr /etc/user_attr || log_fail "Couldn't modify user_attr"
+	return 0
+}
+
+log_assert "Verify set/clear BSD'ish attributes will succeed while user has " \
+    "file_flag_set or all privilege"
+log_onexit cleanup
+
+add='S+c'
+del='S-c'
+mntpt=$(get_prop mountpoint $TESTPOOL/$TESTFS)
+orig_user_attr="/tmp/user_attr.$$"
+attributes="u i a d q m"
+
+log_must $CP /etc/user_attr $orig_user_attr
+
+for owner in root $ZFS_ACL_STAFF1 $ZFS_ACL_STAFF2; do
+	$TOUCH $mntpt/file || log_fail "Failed to create $mntpt/file"
+	$MKDIR $mntpt/dir || log_fail "Failed to mkdir $mntpt/dir"
+	$CHOWN $owner $mntpt/file $mntpt/dir || log_fail "Failed to chown file"
+	for user in 'root' $ZFS_ACL_STAFF2; do
+		for attr in $attributes; do
+			for priv in 'file_flag_set' 'all'; do
+				log_note "Trying $owner $user $attr $priv"
+				grant_priv $user $priv
+				try $mntpt/file $attr $user $priv $add
+				try $mntpt/file $attr $user $priv $del
+				try $mntpt/dir $attr $user $priv $add
+				try $mntpt/dir $attr $user $priv $del
+				reset_privs $user
+			done
+		done
+	done
+	$RM -rf $mntpt/file $mntpt/dir || log_fail \
+	    "$($LS -d/ c $mntpt/file $mntpt/dir)"
+done
+
+log_pass "Set/Clear BSD'ish attributes succeed while user has " \
+    "PRIV_FILE_FLAG_SET/PRIV_FILE_FLAG_CLEAR privilege"
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/usr/src/test/zfs-tests/tests/functional/acl/cifs/cifs_attr_003_pos.ksh	Wed Dec 05 22:04:50 2012 -0500
@@ -0,0 +1,602 @@
+#!/bin/ksh -p
+#
+# CDDL HEADER START
+#
+# The contents of this file are subject to the terms of the
+# Common Development and Distribution License (the "License").
+# You may not use this file except in compliance with the License.
+#
+# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
+# or http://www.opensolaris.org/os/licensing.
+# See the License for the specific language governing permissions
+# and limitations under the License.
+#
+# When distributing Covered Code, include this CDDL HEADER in each
+# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
+# If applicable, add the following below this CDDL 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) 2012 by Delphix. All rights reserved.
+#
+
+. $STF_SUITE/tests/functional/acl/acl_common.kshlib
+. $STF_SUITE/tests/functional/acl/cifs/cifs.kshlib
+
+#
+# DESCRIPTION:
+#	Verify the DOS attributes (Readonly, Hidden, Archive, System)
+#	and BSD'ish attributes (Immutable, nounlink, and appendonly)
+#	will provide the proper access limitation as expected.
+#
+#	Readonly means that the content of a file can't be modified, but
+#	timestamps, mode and so on can.
+#
+#	Archive - Indicates if a file should be included in the next backup
+#	of the file system.  ZFS will set this bit whenever a file is
+#	modified.
+#
+#	Hidden and System (ZFS does nothing special with these, other than
+#	letting a user/application set them.
+#
+#	Immutable (The data can't, change nor can mode, ACL, size and so on)
+#	The only attribute that can be updated is the access time.
+#
+#	Nonunlink - Sort of like immutable except that a file/dir can't be
+#	removed.
+#	This will also effect a rename operation, since that involes a
+#	remove.
+#
+#	Appendonly - File can only be appended to.
+#
+#	nodump, settable, opaque (These are for the MacOS port) we will
+#	allow them to be set, but have no semantics tied to them.
+#
+# STRATEGY:
+#	1. Loop super user and non-super user to run the test case.
+#	2. Create basedir and a set of subdirectores and files within it.
+#	3. Set the file/dir with each kind of special attribute.
+#	4. Verify the access limitation works as expected.
+#
+
+verify_runnable "both"
+
+function cleanup
+{
+	if [[ -n $gobject ]]; then
+		destroy_object $gobject
+	fi
+
+	for fs in $TESTPOOL/$TESTFS $TESTPOOL ; do
+		mtpt=$(get_prop mountpoint $fs)
+		log_must $RM -rf $mtpt/file.* $mtpt/dir.*
+	done
+
+	[[ -f $TESTFILE ]] && $RM $TESTFILE
+}
+
+#
+# Set the special attribute to the given node
+#
+# $1: The given node (file/dir)
+# $2: The special attribute to be set
+#
+function set_attribute
+{
+	typeset object=$1
+	typeset attr=$2
+
+	if [[ -z $attr ]]; then
+		attr="AHRSadimu"
+		if [[ -f $object ]]; then
+			attr="${attr}q"
+		fi
+	fi
+	$CHMOD S+c${attr} $object
+	return $?
+}
+
+#
+# Clear the special attribute to the given node
+#
+# $1: The given node (file/dir)
+# $2: The special attribute to be cleared
+#
+function clear_attribute
+{
+	typeset object=$1
+	typeset attr=$2
+
+	if [[ -z $attr ]]; then
+		if is_global_zone ; then
+			attr="AHRSadimu"
+			if [[ -f $object ]]; then
+				attr="${attr}q"
+			fi
+		else
+			attr="AHRS"
+		fi
+	fi
+
+	$CHMOD S-c${attr} $object
+	return $?
+}
+
+#
+# A wrapper function to call test function according to the given attr
+#
+# $1: The given node (file/dir)
+# $2: The special attribute to be test
+#
+function test_wrapper
+{
+	typeset object=$1
+	typeset attr=$2
+
+	if [[ -z $object || -z $attr ]]; then
+		log_fail "Object($object), Attr($attr) not defined."
+	fi
+
+	case $attr in
+		R)	func=test_readonly
+			;;
+		i)	func=test_immutable
+			;;
+		u)	func=test_nounlink
+			;;
+		a)	func=test_appendonly
+			;;
+	esac
+
+	if [[ -n $func ]]; then
+		$func $object
+	fi
+}
+
+#
+# Invoke the function and verify whether its return code as expected
+#
+# $1: Expect value
+# $2-$n: Function and args need to be invoked
+#
+function verify_expect
+{
+	typeset -i expect=$1
+	typeset status
+
+	shift
+
+	"$@" > /dev/null 2>&1
+	status=$?
+	if  [[ $status -eq 0 ]]; then
+		if ((expect != 0)); then
+			log_fail "$@ unexpect return 0"
+		fi
+	else
+		if ((expect == 0)); then
+			log_fail "$@ unexpect return $status"
+		fi
+	fi
+}
+
+#
+# Unit testing function against overwrite file
+#
+# $1: The given file node
+# $2: Execute user
+# $3: Expect value, default to be zero
+#
+function unit_writefile
+{
+	typeset object=$1
+	typeset user=$2
+	typeset expect=${3:-0}
+	if [[ -f $object ]]; then
+		verify_expect $expect $CHG_USR_EXEC $user \
+		    $CP $TESTFILE $object
+		verify_expect $expect $CHG_USR_EXEC $user \
+		    $EVAL "$ECHO '$TESTSTR' > $object"
+	fi
+}
+
+#
+# Unit testing function against write new stuffs into a directory
+#
+# $1: The given directory node
+# $2: Execute user
+# $3: Expect value, default to be zero
+#
+function unit_writedir
+{
+	typeset object=$1
+	typeset user=$2
+	typeset expect=${3:-0}
+
+	if [[ -d $object ]]; then
+		verify_expect $expect $CHG_USR_EXEC $user \
+		    $CP $TESTFILE $object
+		verify_expect $expect $CHG_USR_EXEC $user \
+		    $MKDIR -p $object/$TESTDIR
+	fi
+}
+
+function unit_appenddata
+{
+	typeset object=$1
+	typeset user=$2
+	typeset expect=${3:-0}
+
+	if [[ ! -d $object ]]; then
+		verify_expect $expect $CHG_USR_EXEC $user \
+		    $EVAL "$ECHO '$TESTSTR' >> $object"
+	fi
+}
+
+#
+# Unit testing function against delete content from a directory
+#
+# $1: The given node, dir
+# $2: Execute user
+# $3: Expect value, default to be zero
+#
+function unit_deletecontent
+{
+	typeset object=$1
+	typeset user=$2
+	typeset expect=${3:-0}
+
+	if [[ -d $object ]]; then
+		for target in $object/${TESTFILE##*/} $object/$TESTDIR ; do
+			if [[ -e $target ]]; then
+				verify_expect $expect $CHG_USR_EXEC $user \
+				    $EVAL "$MV $target $target.new"
+				verify_expect $expect $CHG_USR_EXEC $user \
+				    $EVAL "$ECHO y | $RM -r $target.new"
+			fi
+		done
+	fi
+}
+
+#
+# Unit testing function against delete a node
+#
+# $1: The given node, file/dir
+# $2: Execute user
+# $3: Expect value, default to be zero
+#
+function unit_deletedata
+{
+	typeset object=$1
+	typeset user=$2
+	typeset expect=${3:-0}
+
+	verify_expect $expect $CHG_USR_EXEC $user \
+	    $EVAL "$ECHO y | $RM -r $object"
+
+}
+
+#
+# Unit testing function against write xattr to a node
+#
+# $1: The given node, file/dir
+# $2: Execute user
+# $3: Expect value, default to be zero
+#
+function unit_writexattr
+{
+	typeset object=$1
+	typeset user=$2
+	typeset expect=${3:-0}
+
+	verify_expect $expect $CHG_USR_EXEC $user \
+	    $RUNAT $object "$CP $TESTFILE $TESTATTR"
+	verify_expect $expect $CHG_USR_EXEC $user \
+	    $EVAL "$RUNAT $object \"$ECHO '$TESTSTR' > $TESTATTR\""
+	verify_expect $expect $CHG_USR_EXEC $user \
+	    $EVAL "$RUNAT $object \"$ECHO '$TESTSTR' >> $TESTATTR\""
+	if [[ $expect -eq 0 ]]; then
+		verify_expect $expect $CHG_USR_EXEC $user \
+		    $RUNAT $object "$RM -f $TESTATTR"
+	fi
+}
+
+#
+# Unit testing function against modify accesstime of a node
+#
+# $1: The given node, file/dir
+# $2: Execute user
+# $3: Expect value, default to be zero
+#
+function unit_accesstime
+{
+	typeset object=$1
+	typeset user=$2
+	typeset expect=${3:-0}
+
+	if [[ -d $object ]]; then
+		verify_expect $expect $CHG_USR_EXEC $user $LS $object
+	else
+		verify_expect $expect $CHG_USR_EXEC $user $CAT $object
+	fi
+}
+
+#
+# Unit testing function against modify updatetime of a node
+#
+# $1: The given node, file/dir
+# $2: Execute user
+# $3: Expect value, default to be zero
+#
+function unit_updatetime
+{
+	typeset object=$1
+	typeset user=$2
+	typeset expect=${3:-0}
+	typeset immutable_expect=${4:-$expect}
+	verify_expect $expect $CHG_USR_EXEC $user $TOUCH $object
+	verify_expect $immutable_expect $CHG_USR_EXEC $user $TOUCH -a $object
+	verify_expect $expect $CHG_USR_EXEC $user $TOUCH -m $object
+}
+
+#
+# Unit testing function against write acl of a node
+#
+# $1: The given node, file/dir
+# $2: Execute user
+# $3: Expect value, default to be zero
+#
+function unit_writeacl
+{
+	typeset object=$1
+	typeset user=$2
+	typeset expect=${3:-0}
+
+	verify_expect $expect $CHG_USR_EXEC $user $CHMOD A+$TESTACL $object
+	verify_expect $expect $CHG_USR_EXEC $user $CHMOD A+$TESTACL $object
+	verify_expect $expect $CHG_USR_EXEC $user $CHMOD A0- $object
+	verify_expect $expect $CHG_USR_EXEC $user $CHMOD A0- $object
+	oldmode=$(get_mode $object)
+	verify_expect $expect $CHG_USR_EXEC $user $CHMOD $TESTMODE $object
+}
+
+#
+# Testing function to verify the given node is readonly
+#
+# $1: The given node, file/dir
+#
+function test_readonly
+{
+	typeset object=$1
+
+	if [[ -z $object ]]; then
+		log_fail "Object($object) not defined."
+	fi
+
+	log_note "Testing readonly of $object"
+
+	for user in $ZFS_ACL_CUR_USER root $ZFS_ACL_STAFF2; do
+		if [[ -d $object ]]; then
+			log_must usr_exec $CHMOD \
+			    A+user:$user:${ace_dir}:allow $object
+		else
+			log_must usr_exec $CHMOD \
+			    A+user:$user:${ace_file}:allow $object
+		fi
+
+		log_must set_attribute $object "R"
+
+		unit_writefile $object $user 1
+		unit_writedir $object $user
+		unit_appenddata $object $user 1
+
+		if [[ -d $object ]]; then
+			unit_writexattr $object $user
+		else
+			unit_writexattr $object $user 1
+		fi
+
+		unit_accesstime $object $user
+		unit_updatetime $object $user
+		unit_writeacl $object $user
+		unit_deletecontent $object $user
+		unit_deletedata $object $user
+
+		if [[ -d $object ]] ;then
+			create_object "dir" $object $ZFS_ACL_CUR_USER
+		else
+			create_object "file" $object $ZFS_ACL_CUR_USER
+		fi
+	done
+}
+
+#
+# Testing function to verify the given node is immutable
+#
+# $1: The given node, file/dir
+#
+function test_immutable
+{
+	typeset object=$1
+
+	if [[ -z $object ]]; then
+		log_fail "Object($object) not defined."
+	fi
+
+	log_note "Testing immutable of $object"
+
+	for user in $ZFS_ACL_CUR_USER root $ZFS_ACL_STAFF2; do
+		if [[ -d $object ]]; then
+			log_must usr_exec $CHMOD \
+			    A+user:$user:${ace_dir}:allow $object
+		else
+			log_must usr_exec $CHMOD \
+			    A+user:$user:${ace_file}:allow $object
+		fi
+		log_must set_attribute $object "i"
+
+		unit_writefile $object $user 1
+		unit_writedir $object $user 1
+		unit_appenddata $object $user 1
+		unit_writexattr $object $user 1
+		unit_accesstime $object $user
+		unit_updatetime $object $user 1 0
+		unit_writeacl $object $user 1
+		unit_deletecontent $object $user 1
+		unit_deletedata $object $user 1
+
+		if [[ -d $object ]] ;then
+			create_object "dir" $object $ZFS_ACL_CUR_USER
+		else
+			create_object "file" $object $ZFS_ACL_CUR_USER
+		fi
+	done
+}
+
+#
+# Testing function to verify the given node is nounlink
+#
+# $1: The given node, file/dir
+#
+function test_nounlink
+{
+	typeset object=$1
+
+	if [[ -z $object ]]; then
+		log_fail "Object($object) not defined."
+	fi
+
+	$ECHO "Testing nounlink of $object"
+
+	for user in $ZFS_ACL_CUR_USER root $ZFS_ACL_STAFF2; do
+		if [[ -d $object ]]; then
+			log_must usr_exec $CHMOD \
+			    A+user:$user:${ace_dir}:allow $object
+		else
+			log_must usr_exec $CHMOD \
+			    A+user:$user:${ace_file}:allow $object
+		fi
+		log_must set_attribute $object "u"
+
+		unit_writefile $object $user
+		unit_writedir $object $user
+		unit_appenddata $object $user
+		unit_writexattr $object $user
+		unit_accesstime $object $user
+		unit_updatetime $object $user
+		unit_writeacl $object $user
+		unit_deletecontent $object $user 1
+		unit_deletedata $object $user 1
+
+		if [[ -d $object ]] ;then
+			create_object "dir" $object $ZFS_ACL_CUR_USER
+		else
+			create_object "file" $object $ZFS_ACL_CUR_USER
+		fi
+	done
+}
+
+#
+# Testing function to verify the given node is appendonly
+#
+# $1: The given node, file/dir
+#
+function test_appendonly
+{
+	typeset object=$1
+
+	if [[ -z $object ]]; then
+		log_fail "Object($object) not defined."
+	fi
+
+	log_note "Testing appendonly of $object"
+
+	for user in $ZFS_ACL_CUR_USER root $ZFS_ACL_STAFF2; do
+		if [[ -d $object ]]; then
+			log_must usr_exec $CHMOD \
+			    A+user:$user:${ace_dir}:allow $object
+		else
+			log_must usr_exec $CHMOD \
+			    A+user:$user:${ace_file}:allow $object
+		fi
+		log_must set_attribute $object "a"
+
+		unit_writefile $object $user 1
+		unit_writedir $object $user
+		unit_appenddata $object $user
+		unit_writexattr $object $user
+		unit_accesstime $object $user
+		unit_updatetime $object $user
+		unit_writeacl $object $user
+		unit_deletecontent $object $user
+		unit_deletedata $object $user
+
+		if [[ -d $object ]] ;then
+			create_object "dir" $object $ZFS_ACL_CUR_USER
+		else
+			create_object "file" $object $ZFS_ACL_CUR_USER
+		fi
+	done
+}
+
+FILES="file.0 file.1"
+DIRS="dir.0 dir.1"
+XATTRS="attr.0 attr.1"
+FS="$TESTPOOL $TESTPOOL/$TESTFS"
+
+if is_global_zone ; then
+	ATTRS="R i u a"
+else
+	ATTRS="R"
+fi
+
+TESTFILE=/tmp/tfile
+TESTDIR=tdir
+TESTATTR=tattr
+TESTACL=user:$ZFS_ACL_OTHER1:write_data:allow
+TESTMODE=777
+TESTSTR="ZFS test suites"
+
+ace_file="write_data/append_data/write_xattr/write_acl/write_attributes"
+ace_dir="add_file/add_subdirectory/${ace_file}"
+
+log_assert "Verify DOS & BSD'ish attributes will provide the " \
+    "access limitation as expected."
+log_onexit cleanup
+
+$ECHO "$TESTSTR" > $TESTFILE
+
+typeset gobject
+typeset gattr
+for gattr in $ATTRS ; do
+	for fs in $FS ; do
+		mtpt=$(get_prop mountpoint $fs)
+		$CHMOD 777 $mtpt
+		for user in root $ZFS_ACL_STAFF1; do
+			log_must set_cur_usr $user
+			for file in $FILES ; do
+				gobject=$mtpt/$file
+				create_object "file" $gobject $ZFS_ACL_CUR_USER
+				test_wrapper $gobject $gattr
+				destroy_object $gobject
+			done
+
+			for dir in $DIRS ; do
+				gobject=$mtpt/$dir
+				create_object "dir" $gobject $ZFS_ACL_CUR_USER
+				test_wrapper $gobject $gattr
+				destroy_object $gobject
+			done
+		done
+	done
+done
+
+log_pass "DOS & BSD'ish attributes provide the access limitation as expected."
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/usr/src/test/zfs-tests/tests/functional/acl/cifs/cleanup.ksh	Wed Dec 05 22:04:50 2012 -0500
@@ -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.
+#
+
+. $STF_SUITE/include/libtest.shlib
+. $STF_SUITE/tests/functional/acl/acl_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
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/usr/src/test/zfs-tests/tests/functional/acl/cifs/setup.ksh	Wed Dec 05 22:04:50 2012 -0500
@@ -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.
+#
+
+. $STF_SUITE/include/libtest.shlib
+. $STF_SUITE/tests/functional/acl/acl_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
+
+# Add root group user
+log_must add_user root $ZFS_ACL_ADMIN
+
+# Create staff group and add two user to it
+log_must add_group $ZFS_ACL_STAFF_GROUP
+log_must add_user $ZFS_ACL_STAFF_GROUP $ZFS_ACL_STAFF1
+log_must add_user $ZFS_ACL_STAFF_GROUP $ZFS_ACL_STAFF2
+
+# Create other group and add two user to it
+log_must add_group $ZFS_ACL_OTHER_GROUP
+log_must add_user $ZFS_ACL_OTHER_GROUP $ZFS_ACL_OTHER1
+log_must add_user $ZFS_ACL_OTHER_GROUP $ZFS_ACL_OTHER2
+
+DISK=${DISKS%% *}
+default_setup_noexit $DISK
+log_must $CHMOD 777 $TESTDIR
+
+log_pass
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/usr/src/test/zfs-tests/tests/functional/acl/nontrivial/Makefile	Wed Dec 05 22:04:50 2012 -0500
@@ -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) 2012 by Delphix. All rights reserved.
+#
+
+include $(SRC)/Makefile.master
+
+ROOTOPTPKG = $(ROOT)/opt/zfs-tests
+TESTDIR = $(ROOTOPTPKG)/tests/functional/acl/nontrivial
+
+PROGS = cleanup \
+	setup \
+	zfs_acl_chmod_001_neg \
+	zfs_acl_chmod_002_pos \
+	zfs_acl_chmod_aclmode_001_pos \
+	zfs_acl_chmod_compact_001_pos \
+	zfs_acl_chmod_delete_001_pos \
+	zfs_acl_chmod_inherit_001_pos \
+	zfs_acl_chmod_inherit_002_neg \
+	zfs_acl_chmod_inherit_002_pos \
+	zfs_acl_chmod_inherit_003_pos \
+	zfs_acl_chmod_inherit_004_pos \
+	zfs_acl_chmod_owner_001_pos \
+	zfs_acl_chmod_rwacl_001_pos \
+	zfs_acl_chmod_rwx_001_pos \
+	zfs_acl_chmod_rwx_002_pos \
+	zfs_acl_chmod_rwx_003_pos \
+	zfs_acl_chmod_rwx_004_pos \
+	zfs_acl_chmod_xattr_001_pos \
+	zfs_acl_chmod_xattr_002_pos \
+	zfs_acl_cp_001_pos \
+	zfs_acl_cp_002_pos \
+	zfs_acl_cpio_001_pos \
+	zfs_acl_cpio_002_pos \
+	zfs_acl_find_001_pos \
+	zfs_acl_ls_001_pos \
+	zfs_acl_mv_001_pos \
+	zfs_acl_tar_001_pos \
+	zfs_acl_tar_002_pos
+
+CMDS = $(PROGS:%=$(TESTDIR)/%)
+$(CMDS) := FILEMODE = 0555
+
+all lint clean clobber:
+
+install: $(CMDS)
+
+$(CMDS): $(TESTDIR)
+
+$(TESTDIR):
+	$(INS.dir)
+
+$(TESTDIR)/%: %.ksh
+	$(INS.rename)
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/usr/src/test/zfs-tests/tests/functional/acl/nontrivial/cleanup.ksh	Wed Dec 05 22:04:50 2012 -0500
@@ -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.
+#
+
+. $STF_SUITE/include/libtest.shlib
+. $STF_SUITE/tests/functional/acl/acl_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
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/usr/src/test/zfs-tests/tests/functional/acl/nontrivial/setup.ksh	Wed Dec 05 22:04:50 2012 -0500
@@ -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.
+#
+
+. $STF_SUITE/include/libtest.shlib
+. $STF_SUITE/tests/functional/acl/acl_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
+
+# Add root group user
+log_must add_user root $ZFS_ACL_ADMIN
+
+# Create staff group and add two user to it
+log_must add_group $ZFS_ACL_STAFF_GROUP
+log_must add_user $ZFS_ACL_STAFF_GROUP $ZFS_ACL_STAFF1
+log_must add_user $ZFS_ACL_STAFF_GROUP $ZFS_ACL_STAFF2
+
+# Create other group and add two user to it
+log_must add_group $ZFS_ACL_OTHER_GROUP
+log_must add_user $ZFS_ACL_OTHER_GROUP $ZFS_ACL_OTHER1
+log_must add_user $ZFS_ACL_OTHER_GROUP $ZFS_ACL_OTHER2
+
+DISK=${DISKS%% *}
+default_setup_noexit $DISK
+log_must $CHMOD 777 $TESTDIR
+
+log_pass
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/usr/src/test/zfs-tests/tests/functional/acl/nontrivial/zfs_acl_chmod_001_neg.ksh	Wed Dec 05 22:04:50 2012 -0500
@@ -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 2009 Sun Microsystems, Inc.  All rights reserved.
+# Use is subject to license terms.
+#
+
+. $STF_SUITE/tests/functional/acl/acl_common.kshlib
+
+#
+# DESCRIPTION:
+#	Verify  1) Illegal options to chmod should fail.
+#		2) Delete all the ACE will lead to fail.
+#		3) Add ACE exceed 1024 will cause to fail.
+#
+# STRATEGY:
+#	1. Loop root and non-root users
+#	2. Verify all kinds of illegal option will lead to chmod failed.
+#	3. Verify 'chmod A0-' will fail when try to delete all the ACE.
+#	4. Verify 'chmod A+' will succeed when the ACE number exceed 1024.
+#
+
+verify_runnable "both"
+
+log_assert "Verify illegal operating to ACL, it will fail."
+log_onexit cleanup
+
+function err_opts #node
+{
+	typeset A_opts="+A@ -A#- +A% =A^ =A# =A@ +A#\ asd \
+			A+@ A-#- A+% A=^ A=# A=@ A+#"
+
+	log_note "Illegal option to chmod should fail."
+	for A in ${A_opts[@]}; do
+		log_mustnot usr_exec $CHMOD ${A}owner@:read_data:allow $node
+		log_mustnot usr_exec $CHMOD A+ asd owner@:execute:deny $node
+	done
+
+	typeset type_opts="everyone groups owner user@ users"
+	for tp in ${type_opts[@]}; do
+		log_mustnot usr_exec $CHMOD A+$tp:read_data:deny $node
+	done
+
+	return 0
+}
+
+function del_all_ACE #node
+{
+	typeset node=$1
+	typeset -i cnt
+
+	cnt=$(count_ACE $node)
+	while (( cnt > 0 )); do
+		if (( cnt == 1 )); then
+			log_mustnot $CHMOD A0- $node
+		else
+			log_must $CHMOD A0- $node
+		fi
+
+		(( cnt -= 1 ))
+	done
+
+	return 0
+}
+
+function exceed_max_ACE #node
+{
+	typeset node=$1
+	typeset -i max=1024
+	typeset -i cnt
+
+	cnt=$(count_ACE $node)
+
+	# One more ACE exceed the max limitation.
+	(( max = max - cnt + 1 ))
+	while (( max > 0 )); do
+		if (( max == 1 )); then
+			log_mustnot $CHMOD A+owner@:read_data:allow $node
+		else
+			$CHMOD A+owner@:read_data:allow $node
+			if (($? != 0)); then
+				((cnt = 1024 - max))
+				log_fail "Add No.$cnt ACL item failed."
+			fi
+		fi
+
+		(( max -= 1 ))
+	done
+
+	return 0
+}
+
+typeset node
+typeset func_name="err_opts del_all_ACE exceed_max_ACE"
+
+for usr in "root" "$ZFS_ACL_STAFF1"; do
+	log_must set_cur_usr $usr
+
+	for node in $testfile $testdir; do
+		log_must usr_exec $TOUCH $testfile
+		log_must usr_exec $MKDIR $testdir
+
+		for func in $func_name; do
+			log_must eval "$func $node"
+		done
+
+		log_must usr_exec $RM -rf $testfile $testdir
+	done
+done
+
+log_pass "Verify illegal operating to ACL passed."
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/usr/src/test/zfs-tests/tests/functional/acl/nontrivial/zfs_acl_chmod_002_pos.ksh	Wed Dec 05 22:04:50 2012 -0500
@@ -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 2009 Sun Microsystems, Inc.  All rights reserved.
+# Use is subject to license terms.
+#
+
+. $STF_SUITE/include/libtest.shlib
+
+#
+# DESCRIPTION:
+#	Verify acl after upgrading.
+# STRATEGY:
+#	1. Create a low version fs.
+#	2. Create a directory and chmod it.
+#	3. Upgrade the fs.
+#	4. Create a file under the directory and list it.
+#
+
+verify_runnable "both"
+
+function acl_upgrade_cleannup
+{
+	log_must $ZFS destroy -rR $ACL_UPGRADE_FS
+}
+
+log_assert "Verify acl after upgrading."
+log_onexit acl_upgrade_cleannup
+
+ACL_UPGRADE_FS=$TESTPOOL/acl_upgrade_fs.$$
+
+log_must $ZFS create -o version=2 $ACL_UPGRADE_FS
+mntpnt=$(get_prop mountpoint $ACL_UPGRADE_FS)
+log_must $MKDIR $mntpnt/dir.$$
+log_must $CHMOD A+owner@:rwxp:f:allow,group@:rwxp:f:allow $mntpnt/dir.$$
+log_must $ZFS upgrade $ACL_UPGRADE_FS
+log_must $TOUCH $mntpnt/dir.$$/file.$$
+log_must eval "$LS -V $mntpnt/dir.$$/file.$$ > /dev/null 2>&1"
+
+log_pass "Verify acl after upgrading."
+
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/usr/src/test/zfs-tests/tests/functional/acl/nontrivial/zfs_acl_chmod_aclmode_001_pos.ksh	Wed Dec 05 22:04:50 2012 -0500
@@ -0,0 +1,555 @@
+#!/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.
+#
+
+
+. $STF_SUITE/tests/functional/acl/acl_common.kshlib
+
+#
+# DESCRIPTION:
+#	Verify chmod have correct behaviour on directories and files when
+#	filesystem has the different aclmode setting
+#
+# STRATEGY:
+#	1. Loop super user and non-super user to run the test case.
+#	2. Create basedir and a set of subdirectores and files within it.
+#	3. Separately chmod basedir with different aclmode options,
+#	   combine with the variable setting of aclmode:
+#	   "discard", "groupmask", or "passthrough".
+#	4. Verify each directories and files have the correct access control
+#	   capability.
+#
+
+verify_runnable "both"
+
+function cleanup
+{
+	# Cleanup tarfile & basedir.
+
+	(( ${#cwd} != 0 )) && cd $cwd
+
+	if [[ -f $TARFILE ]]; then
+		log_must $RM -f $TARFILE
+	fi
+
+	if [[ -d $basedir ]]; then
+		log_must $RM -rf $basedir
+	fi
+}
+
+log_assert "Verify chmod have correct behaviour to directory and file when " \
+	"filesystem has the different aclmode setting."
+log_onexit cleanup
+
+# Define aclmode flag
+set -A aclmode_flag discard groupmask passthrough
+
+set -A ace_prefix "user:$ZFS_ACL_OTHER1" \
+		"user:$ZFS_ACL_OTHER2" \
+		"group:$ZFS_ACL_STAFF_GROUP" \
+		"group:$ZFS_ACL_OTHER_GROUP"
+
+set -A argv  "000" "444" "644" "777" "755" "231" "562" "413"
+
+set -A ace_file_preset "read_data" \
+		"write_data" \
+		"append_data" \
+		"execute" \
+		"read_data/write_data" \
+		"read_data/write_data/append_data" \
+		"write_data/append_data" \
+		"read_data/execute" \
+		"write_data/append_data/execute" \
+		"read_data/write_data/append_data/execute"
+
+# Defile the based directory and file
+basedir=$TESTDIR/basedir;  ofile=$basedir/ofile; odir=$basedir/odir
+nfile=$basedir/nfile; ndir=$basedir/ndir
+
+TARFILE=$TESTDIR/tarfile
+
+# Verify all the node have expected correct access control
+allnodes="$nfile $ndir"
+
+#
+# According to the original bits, the input ACE access and ACE type, return the
+# expect bits after 'chmod A0{+|=}'.
+#
+# $1 isdir indicate if the target is a directory
+# $2 bits which was make up of three bit 'rwx'
+# $3 bits_limit which was make up of three bit 'rwx'
+# $4 ACE access which is read_data, write_data or execute
+# $5 ctrl which is to determine allow or deny according to owner/group bit
+#
+function cal_bits # isdir bits bits_limit acl_access ctrl
+{
+	typeset -i isdir=$1
+	typeset -i bits=$2
+	typeset -i bits_limit=$3
+	typeset acl_access=$4
+	typeset -i ctrl=${5:-0}
+	typeset flagr=0 flagw=0 flagx=0
+	typeset tmpstr
+
+	if (( ctrl == 0 )); then
+		if (( (( bits & 4 )) != 0 )); then
+			flagr=1
+		fi
+		if (( (( bits & 2 )) != 0 )); then
+			flagw=1
+		fi
+		if (( (( bits & 1 )) != 0 )); then
+			flagx=1
+		fi
+	else
+		#Determine ACE as per owner/group bit
+		flagr=1
+		flagw=1
+		flagx=1
+
+		if (( ((bits & 4)) != 0 )) && \
+			(( ((bits_limit & 4)) != 0 )); then
+			flagr=0
+		fi
+		if (( ((bits & 2)) != 0 )) && \
+			(( ((bits_limit & 2)) != 0 )); then
+			flagw=0
+		fi
+		if (( ((bits & 1)) != 0 )) && \
+			(( ((bits_limit & 1)) != 0 )); then
+			flagx=0
+		fi
+	fi
+	if ((flagr != 0)); then
+		if [[ $acl_access == *"read_data"* ]]; then
+			if [[ $acl_access == *"allow"*  && $passthrough == 0 ]]; then
+					tmpstr=${tmpstr}
+			else
+				if ((isdir == 0)); then
+					tmpstr=${tmpstr}/read_data
+				else
+					tmpstr=${tmpstr}/list_directory/read_data
+				fi
+			fi
+		fi
+	fi
+
+	if ((flagw != 0)); then
+		if [[ $acl_access == *"allow"* && $passthrough == 0 ]]; then
+			tmpstr=${tmpstr}
+		else
+			if [[ $acl_access == *"write_data"* ]]; then
+				if ((isdir == 0)); then
+					tmpstr=${tmpstr}/write_data
+				else
+					tmpstr=${tmpstr}/add_file/write_data
+				fi
+			fi
+			if [[ $acl_access == *"append_data"* ]]; then
+				if ((isdir == 0)); then
+					tmpstr=${tmpstr}/append_data
+				else
+					tmpstr=${tmpstr}/add_subdirectory/append_data
+				fi
+			fi
+		fi
+	fi
+	if ((flagx != 0)); then
+		if [[ $acl_access == *"execute"* ]]; then
+			if [[ $acl_access == *"allow"* && $passthrough == 0 ]]; then
+				tmpstr=${tmpstr}
+			else
+				tmpstr=${tmpstr}/execute
+			fi
+		fi
+	fi
+
+	tmpstr=${tmpstr#/}
+
+	$ECHO "$tmpstr"
+}
+
+#
+# To translate an ace if the node is dir
+#
+# $1 isdir indicate if the target is a directory
+# $2 acl to be translated
+#
+function translate_acl # isdir acl
+{
+	typeset -i isdir=$1
+	typeset acl=$2
+	typeset who prefix acltemp action
+
+	if ((isdir != 0)); then
+		who=${acl%%:*}
+		prefix=$who
+		acltemp=${acl#*:}
+		acltemp=${acltemp%%:*}
+		prefix=$prefix:$acltemp
+		action=${acl##*:}
+		acl=$prefix:$(cal_bits $isdir 7 7 $acl 0):$action
+	fi
+	$ECHO "$acl"
+}
+
+#
+# To verify if a new ACL is generated as result of
+# chmod operation.
+#
+# $1 bit indicates whether owner/group bit
+# $2 newmode indicates the mode changed using chmod
+# $3 isdir indicate if the target is a directory
+#
+function check_new_acl # bit newmode isdir
+{
+	typeset bits=$1
+	typeset mode=$2
+	typeset -i isdir=$3
+	typeset new_acl
+	typeset gbit
+	typeset ebit
+	typeset str=":"
+	gbit=$(get_substr $mode 2 1)
+	ebit=$(get_substr $mode 3 1)
+	if (( ((bits & 4)) == 0 )); then
+		if (( ((gbit & 4)) != 0 || \
+		    ((ebit & 4)) != 0 )); then
+			if ((isdir == 0)); then
+				new_acl=${new_acl}${str}read_data
+			else
+				new_acl=${new_acl}${str}list_directory/read_data
+			fi
+			str="/"
+		fi
+	fi
+	if (( ((bits & 2)) == 0 )); then
+		if (( ((gbit & 2)) != 0 || \
+		    ((ebit & 2)) != 0 )); then
+			if ((isdir == 0)); then
+				new_acl=${new_acl}${str}write_data/append_data
+			else
+				new_acl=${new_acl}${str}add_file/write_data/
+				new_acl=${new_acl}add_subdirectory/append_data
+			fi
+			str="/"
+		fi
+	fi
+	if (( ((bits & 1)) == 0 )); then
+		if (( ((gbit & 1)) != 0 || \
+		    ((ebit & 1)) != 0 )); then
+				new_acl=${new_acl}${str}execute
+		fi
+	fi
+	$ECHO "$new_acl"
+}
+
+function build_new_acl # newmode isdir
+{
+	typeset newmode=$1
+	typeset isdir=$2
+	typeset expect
+	if ((flag == 0)); then
+		prefix="owner@"
+		bit=$(get_substr $newmode 1 1)
+		status=$(check_new_acl $bit $newmode $isdir)
+
+	else
+		prefix="group@"
+		bit=$(get_substr $newmode 2 1)
+		status=$(check_new_acl $bit $newmode $isdir)
+	fi
+	expect=$prefix$status:deny
+	$ECHO $expect
+}
+
+#
+# According to inherited flag, verify subdirectories and files within it has
+# correct inherited access control.
+#
+function verify_aclmode # <aclmode> <node> <newmode>
+{
+	# Define the nodes which will be affected by inherit.
+	typeset aclmode=$1
+	typeset node=$2
+	typeset newmode=$3
+
+	# count: the ACE item to fetch
+	# pass: to mark if the current ACE should apply to the target
+	# passcnt: counter, if it achieves to maxnumber,
+	#	then no additional ACE should apply.
+
+	typeset -i count=0 pass=0 passcnt=0
+	typeset -i bits=0 obits=0 bits_owner=0 isdir=0
+	typeset -i total_acl
+	typeset -i acl_count=$(count_ACE $node)
+
+	((total_acl = maxnumber + 3))
+
+	if [[ -d $node ]]; then
+		((isdir = 1))
+	fi
+
+	((i = maxnumber - 1))
+	count=0
+	passcnt=0
+	flag=0
+	while ((i >= 0)); do
+		pass=0
+		expect1=${acls[$i]}
+		passthrough=0
+		#
+		# aclmode=passthrough,
+		# no changes will be made to the ACL other than
+		# generating the necessary ACL entries to represent
+		# the new mode of the file or directory.
+		#
+		# aclmode=discard,
+		# delete all ACL entries that don't represent
+		# the mode of the file.
+		#
+		# aclmode=groupmask,
+		# reduce user or group permissions.  The permissions are
+		# reduced, such that they are no greater than the group
+		# permission bits, unless it is a user entry that has the
+		# same UID as the owner of the file or directory.
+		# Then, the ACL permissions are reduced so that they are
+		# no greater than owner permission bits.
+		#
+
+		case $aclmode in
+			passthrough)
+				if ((acl_count > total_acl)); then
+					expect1=$(build_new_acl $newmode $isdir)
+					flag=1
+					((total_acl = total_acl + 1))
+					((i = i + 1))
+				else
+					passthrough=1
+					expect1=$(translate_acl $isdir $expect1)
+				fi
+				;;
+			groupmask)
+				if ((acl_count > total_acl)); then
+					expect1=$(build_new_acl $newmode $isdir)
+					flag=1
+					((total_acl = total_acl + 1))
+					((i = i + 1))
+
+				elif [[ $expect1 == *":allow"* ]]; then
+					who=${expect1%%:*}
+					aclaction=${expect1##*:}
+					prefix=$who
+					acltemp=""
+					reduce=0
+					#
+					# To determine the mask bits
+					# according to the entry type.
+					#
+					case $who in
+						owner@)
+							pos=1
+							;;
+						group@)
+							pos=2
+							;;
+						everyone@)
+							pos=3
+							;;
+						user)
+							acltemp=${expect1#*:}
+							acltemp=${acltemp%%:*}
+							owner=$(get_owner $node)
+							group=$(get_group $node)
+							if [[ $acltemp == \
+							    $owner ]]; then
+								pos=1
+							else
+								pos=2
+							fi
+							prefix=$prefix:$acltemp
+							;;
+						group)
+							acltemp=${expect1#*:}
+							acltemp=${acltemp%%:*}
+							pos=2
+							prefix=$prefix:$acltemp
+							reduce=1
+							;;
+					esac
+					obits=$(get_substr $newmode $pos 1)
+					((bits = $obits))
+					#
+					# permission should no greater than the
+					# group permission bits
+					#
+					if ((reduce != 0)); then
+						((bits &= \
+						    $(get_substr $newmode 2 1)))
+					# The ACL permissions are reduced so
+					# that they are no greater than owner
+					# permission bits.
+
+						((bits_owner = \
+						    $(get_substr $newmode 1 1)))
+						((bits &= $bits_owner))
+					fi
+
+					if ((bits < obits)) && \
+					    [[ -n $acltemp ]]; then
+						expect2=$prefix:
+						new_bit=$(cal_bits $isdir $obits $bits_owner $expect1 1)
+						expect2=${expect2}${new_bit}:allow
+					else
+						expect2=$prefix:
+						new_bit=$(cal_bits $isdir $obits $obits $expect1 1)
+						expect2=${expect2}${new_bit}:allow
+					fi
+					priv=$(cal_bits $isdir $obits $bits_owner $expect2 0)
+					expect1=$prefix:$priv:$aclaction
+				else
+					expect1=$(translate_acl $isdir $expect1)
+				fi
+				;;
+			discard)
+				passcnt=maxnumber
+				break
+				;;
+		esac
+
+		if ((pass == 0)) ; then
+			# Get the first ACE to do comparison
+
+			aclcur=$(get_ACE $node $count)
+			aclcur=${aclcur#$count:}
+			if [[ -n $expect1 && $expect1 != $aclcur ]]; then
+				$LS -vd $node
+				log_fail "$aclmode $i #$count " \
+					"ACE: $aclcur, expect to be " \
+					"$expect1"
+			fi
+		((count = count + 1))
+		fi
+		((i = i - 1))
+	done
+
+	#
+	# If there's no any ACE be checked, it should be identify as
+	# an normal file/dir, verify it.
+	#
+	if ((passcnt == maxnumber)); then
+		if [[ -d $node ]]; then
+			compare_acls $node $odir
+		elif [[	-f $node ]]; then
+			compare_acls $node $ofile
+		fi
+
+		if [[ $? -ne 0 ]]; then
+			$LS -vd $node
+			log_fail "Unexpect acl: $node, $aclmode ($newmode)"
+		fi
+	fi
+}
+
+
+
+typeset -i maxnumber=0
+typeset acl
+typeset target
+typeset -i passthrough=0
+typeset -i flag=0
+cwd=$PWD
+cd $TESTDIR
+
+for mode in "${aclmode_flag[@]}"; do
+
+	#
+	# Set different value of aclmode
+	#
+
+	log_must $ZFS set aclmode=$mode $TESTPOOL/$TESTFS
+
+	for user in root $ZFS_ACL_STAFF1; do
+		log_must set_cur_usr $user
+
+		log_must usr_exec $MKDIR $basedir
+
+		log_must usr_exec $MKDIR $odir
+		log_must usr_exec $TOUCH $ofile
+		log_must usr_exec $MKDIR $ndir
+		log_must usr_exec $TOUCH $nfile
+
+		for obj in $allnodes; do
+			maxnumber=0
+			for preset in "${ace_file_preset[@]}"; do
+				for prefix in "${ace_prefix[@]}"; do
+					acl=$prefix:$preset
+
+					case $((maxnumber % 2)) in
+						0)
+							acl=$acl:deny
+							;;
+						1)
+							acl=$acl:allow
+							;;
+					esac
+
+				#
+				# Place on the target should succeed.
+				#
+					log_must usr_exec $CHMOD A+$acl $obj
+					acls[$maxnumber]=$acl
+
+					((maxnumber = maxnumber + 1))
+				done
+			done
+			# Archive the file and directory
+			log_must $TAR cpf@ $TARFILE $basedir
+
+			if [[ -d $obj ]]; then
+				target=$odir
+			elif [[ -f $obj ]]; then
+				target=$ofile
+			fi
+			for newmode in "${argv[@]}"; do
+				log_must usr_exec $CHMOD $newmode $obj
+				log_must usr_exec $CHMOD $newmode $target
+				log_must verify_aclmode $mode $obj $newmode
+
+				# Restore the tar archive
+				log_must $TAR xpf@ $TARFILE
+			done
+		done
+
+		log_must usr_exec $RM -rf $basedir $TARFILE
+	done
+done
+
+log_pass "Verify chmod behaviour co-op with aclmode setting passed."
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/usr/src/test/zfs-tests/tests/functional/acl/nontrivial/zfs_acl_chmod_compact_001_pos.ksh	Wed Dec 05 22:04:50 2012 -0500
@@ -0,0 +1,243 @@
+#!/bin/ksh -p
+#
+# CDDL HEADER START
+#
+# The contents of this file are subject to the terms of the
+# Common Development and Distribution License (the "License").
+# You may not use this file except in compliance with the License.
+#
+# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
+# or http://www.opensolaris.org/os/licensing.
+# See the License for the specific language governing permissions
+# and limitations under the License.
+#
+# When distributing Covered Code, include this CDDL HEADER in each
+# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
+# If applicable, add the following below this CDDL 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) 2012 by Delphix. All rights reserved.
+#
+
+. $STF_SUITE/tests/functional/acl/acl_common.kshlib
+
+#
+# DESCRIPTION:
+#	chmod A{+|-|=} could set compact ACL correctly.
+#
+# STRATEGY:
+#	1. Loop root and non-root user.
+#	2. Get the random compact ACL string.
+#	4. Separately chmod +|-|=
+#	5. Check compact ACL display as expected
+#
+
+verify_runnable "both"
+
+log_assert "chmod A{+|=} should set compact ACL correctly."
+log_onexit cleanup
+
+typeset a_flag=('owner' 'group' 'everyone')
+typeset a_access=('r' 'w' 'x' 'p' 'd' 'D' 'a' 'A' 'R' 'W' 'c' 'C' 'o' 's')
+typeset a_inherit_object=('f' 'd')
+typeset a_inherit_strategy=('i' 'n')
+typeset a_type=('allow' 'deny')
+
+#
+# Get a random item from an array.
+#
+# $1 the base set
+#
+function random_select
+{
+	typeset arr_name=$1
+	typeset -i ind
+
+	eval typeset -i cnt=\${#${arr_name}[@]}
+	((ind = $RANDOM % cnt))
+
+	eval print \${${arr_name}[$ind]}
+}
+
+#
+# Create a random string according to array name, the item number and
+# separated tag.
+#
+# $1 array name where the function get the elements
+# $2 the items number which you want to form the random string
+# $3 the separated tag
+#
+function form_random_str
+{
+	typeset arr_name=$1
+	typeset -i count=${2:-1}
+	typeset sep=${3:-""}
+
+	typeset str=""
+	while ((count > 0)); do
+		str="${str}$(random_select $arr_name)${sep}"
+
+		((count -= 1))
+	done
+
+	print $str
+}
+
+#
+# According to the input ACE access,ACE type, and inherit flags, return the
+# expect compact ACE that could be used by chmod A0{+|=}'.
+#
+# $1 ACE flag which is owner, group, or everyone
+# $2 ACE access generated by the element of a_access
+# $3 ACE inherit_object generated by the element of a_inherit_object
+# $4 ACE inherit_strategy generated by the element of a_inherit_strategy
+# $5 ACE type which is allow or deny
+#
+function cal_ace
+{
+	typeset acl_flag=$1
+	typeset acl_access=$2
+	typeset acl_inherit_object=$3
+	typeset acl_inherit_strategy=$4
+	typeset acl_type=$5
+
+	tmp_ace=${acl_flag}@:
+
+	for element in ${a_access[@]} ; do
+		if [[ $acl_access == *"$element"* ]]; then
+			tmp_ace="${tmp_ace}${element}"
+		else
+			tmp_ace="${tmp_ace}-"
+		fi
+	done
+	tmp_ace=${tmp_ace}:
+
+	for element in ${a_inherit_object[@]} ; do
+		if [[ $acl_inherit_object == *"$element"* ]]; then
+			tmp_ace="${tmp_ace}${element}"
+		else
+			tmp_ace="${tmp_ace}-"
+		fi
+	done
+	for element in ${a_inherit_strategy[@]} ; do
+		if [[ $acl_inherit_strategy == *"$element"* ]]; then
+			tmp_ace="${tmp_ace}${element}"
+		else
+			tmp_ace="${tmp_ace}-"
+		fi
+	done
+
+	tmp_ace=${tmp_ace}---:${acl_type}
+
+	echo "${tmp_ace}"
+}
+
+#
+# Check if chmod set the compact ACE correctly.
+#
+function check_test_result
+{
+	typeset node=$1
+	typeset acl_flag=$2
+	typeset acl_access=$3
+	typeset acl_inherit_object=$4
+	typeset acl_inherit_strategy=$5
+	typeset acl_type=$6
+
+	typeset expect_ace=$(cal_ace "$acl_flag" "$acl_access" \
+	    "$acl_inherit_object" "$acl_inherit_strategy" "$acl_type")
+
+	typeset cur_ace=$(get_ACE $node 0 "compact")
+
+	if [[ $cur_ace != $expect_ace ]]; then
+		log_fail "FAIL: Current map($cur_ace) !=  \
+		    expected ace($expect_ace)"
+	fi
+}
+
+function test_chmod_map
+{
+	typeset node=$1
+	typeset acl_flag acl_access acl_inherit_object acl_inherit_strategy \
+	    acl_type
+	typeset -i cnt
+
+	if ((${#node} == 0)); then
+		log_fail "FAIL: file name or directroy name is not defined."
+	fi
+
+        # Get ACL flag, access & type
+	acl_flag=$(form_random_str a_flag)
+	((cnt = ($RANDOM % ${#a_access[@]}) + 1))
+	acl_access=$(form_random_str a_access $cnt)
+	acl_access=${acl_access%/}
+	acl_type=$(form_random_str a_type 1)
+
+	acl_spec=${acl_flag}@:${acl_access}
+	if [[ -d $node ]]; then
+		# Get ACL inherit_object & inherit_strategy
+		((cnt = ($RANDOM % ${#a_inherit_object[@]}) + 1))
+		acl_inherit_object=$(form_random_str a_inherit_object $cnt)
+		((cnt = ($RANDOM % ${#a_inherit_strategy[@]}) + 1))
+		acl_inherit_strategy=$(form_random_str a_inherit_strategy $cnt)
+		acl_spec=${acl_spec}:${acl_inherit_object}${acl_inherit_strategy}
+	fi
+	acl_spec=${acl_spec}:${acl_type}
+
+	# Set the initial map and back the initial ACEs
+	typeset orig_ace=/tmp/orig_ace.$$
+	typeset cur_ace=/tmp/cur_ace.$$
+
+	for operator in "A0+" "A0="; do
+		log_must usr_exec eval "$LS -Vd $node > $orig_ace"
+
+		# To "A=", firstly add one ACE which can't modify map
+		if [[ $operator == "A0=" ]]; then
+			log_must $CHMOD A0+user:$ZFS_ACL_OTHER1:execute:deny \
+			    $node
+		fi
+		log_must usr_exec $CHMOD ${operator}${acl_spec} $node
+
+		check_test_result "$node" "$acl_flag" "$acl_access" \
+		    "$acl_inherit_object" "$acl_inherit_strategy" "$acl_type"
+
+		# Check "chmod A-"
+		log_must usr_exec $CHMOD A0- $node
+		log_must usr_exec eval "$LS -Vd $node > $cur_ace"
+
+		$DIFF $orig_ace $cur_ace
+		[[ $? -ne 0 ]] && log_fail "FAIL: 'chmod A-' failed."
+	done
+
+	[[ -f $orig_ace ]] && log_must usr_exec $RM -f $orig_ace
+	[[ -f $cur_ace ]] && log_must usr_exec $RM -f $cur_ace
+}
+
+for user in root $ZFS_ACL_STAFF1; do
+	set_cur_usr $user
+
+	typeset -i loop_cnt=2
+	while ((loop_cnt > 0)); do
+		log_must usr_exec $TOUCH $testfile
+		test_chmod_map $testfile
+		log_must $RM -f $testfile
+
+		log_must usr_exec $MKDIR $testdir
+		test_chmod_map $testdir
+		log_must $RM -rf $testdir
+
+		((loop_cnt -= 1))
+	done
+done
+
+log_pass "chmod A{+|=} set compact ACL correctly."
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/usr/src/test/zfs-tests/tests/functional/acl/nontrivial/zfs_acl_chmod_delete_001_pos.ksh	Wed Dec 05 22:04:50 2012 -0500
@@ -0,0 +1,301 @@
+#!/bin/ksh -p
+#
+# CDDL HEADER START
+#
+# The contents of this file are subject to the terms of the
+# Common Development and Distribution License (the "License").
+# You may not use this file except in compliance with the License.
+#
+# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
+# or http://www.opensolaris.org/os/licensing.
+# See the License for the specific language governing permissions
+# and limitations under the License.
+#
+# When distributing Covered Code, include this CDDL HEADER in each
+# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
+# If applicable, add the following below this CDDL 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.
+#
+
+. $STF_SUITE/tests/functional/acl/acl_common.kshlib
+
+#
+# DESCRIPTION:
+#	Verify that the combined delete_child/delete permission for
+#	owner/group/everyone are correct.
+#
+#        -------------------------------------------------------
+#        |   Parent Dir  |           Target Object Permissions |
+#        |  permissions  |                                     |
+#        -------------------------------------------------------
+#        |               | ACL Allows | ACL Denies| Delete     |
+#        |               |  Delete    |  Delete   | unspecified|
+#        -------------------------------------------------------
+#        |  ACL Allows   | Permit     | Permit    | Permit     |
+#        |  DELETE_CHILD |                                     |
+#        -------------------------------------------------------
+#        |  ACL Denies   | Permit     | Deny      | Deny       |
+#        |  DELETE_CHILD |            |           |            |
+#        -------------------------------------------------------
+#        | ACL specifies |            |           |            |
+#        | only allows   | Permit     | Permit    | Permit     |
+#        | write and     |            |           |            |
+#        | execute       |            |           |            |
+#        -------------------------------------------------------
+#        | ACL denies    |            |           |            |
+#        | write and     | Permit     | Deny      | Deny       |
+#        | execute       |            |           |            |
+#        -------------------------------------------------------
+#
+# STRATEGY:
+# 1. Create file and  directory in zfs filesystem
+# 2. Set special ACE combination to the file and directory
+# 3. Try to remove the file
+# 4. Verify that combined permissions for owner/group/everyone are correct.
+#
+
+verify_runnable "both"
+
+function cleanup
+{
+	if [[ ! -e $target ]]; then
+		log_must $TAR xpf $TESTDIR/$ARCHIVEFILE
+	fi
+
+	(( ${#cwd} != 0 )) && cd $cwd
+	cleanup_test_files $TESTDIR/basedir
+	if [[ -e $TESTDIR/$ARCHIVEFILE ]]; then
+		log_must $RM -f $TESTDIR/$ARCHIVEFILE
+	fi
+	return 0
+}
+
+#owner@	          group	                 group_users       other_users
+set -A users \
+"root"            "root"                 "$ZFS_ACL_ADMIN"  "$ZFS_ACL_OTHER1" \
+"$ZFS_ACL_STAFF1" "$ZFS_ACL_STAFF_GROUP" "$ZFS_ACL_STAFF2" "$ZFS_ACL_OTHER1"
+
+set -A access_parent \
+	"delete_child:allow" \
+	"delete_child:deny" \
+	"write_data:allow" \
+	"write_data:deny" \
+	"delete_child:deny write_data:allow" \
+	"delete_child:allow write_data:deny"
+
+set -A access_target \
+	"delete:allow" \
+	"delete:deny" \
+	""
+
+set -A a_flag "owner@" "group@" "everyone@" "user:$ZFS_ACL_STAFF1"
+
+log_assert "Verify that the combined delete_child/delete permission for" \
+	"owner/group/everyone are correct."
+log_onexit cleanup
+
+function operate_node #user node
+{
+	typeset user=$1
+	typeset node=$2
+	typeset ret
+
+	if [[ $user == "" || $node == "" ]]; then
+		log_fail "user, node are not defined."
+	fi
+	if [[ -d $node ]]; then
+		chgusr_exec $user $RM -rf $node ; ret=$?
+	else
+		chgusr_exec $user $RM -f $node ; ret=$?
+	fi
+
+	if [[ -e $node ]]; then
+		if [[ $ret -eq 0 ]]; then
+			log_note "$node not removed, but return code is 0."
+			return 1
+		fi
+	else
+		log_must $TAR xpf $TESTDIR/$ARCHIVEFILE
+		if [[ $ret -ne 0 ]]; then
+			log_note "$node removed, but return code is $ret."
+			return 1
+		fi
+	fi
+	return $ret
+}
+
+function logname #acl_parent acl_target user
+{
+	typeset acl_parent=$1
+	typeset acl_target=$2
+	typeset user=$3
+
+	# To super user, read and write deny permission was override.
+	if [[ $user == root || $acl_target == *:allow ]]; then
+		print "log_must"
+	elif [[ $acl_parent == *"delete_child"* ]]; then
+		if [[ $acl_parent == *"delete_child:allow"* ]]; then
+			print "log_must"
+		else
+			print "log_mustnot"
+		fi
+	elif [[ $acl_parent == *"write_data"* ]]; then
+		if [[ $acl_parent == *"write_data:allow"* ]]; then
+			print "log_must"
+		else
+			print "log_mustnot"
+		fi
+	else
+		print "log_mustnot"
+	fi
+}
+
+function check_chmod_results #node flag acl_parent acl_target g_usr o_usr
+{
+	typeset node=$1
+	typeset flag=$2
+	typeset acl_parent=$3
+	typeset acl_target=$2:$4
+	typeset g_usr=$5
+	typeset o_usr=$6
+	typeset log acl_tmp
+
+	for acl in $acl_parent ; do
+		acl_tmp="$2:$acl $acl_tmp"
+	done
+	acl_parent=$acl_tmp
+
+	if [[ $flag == "owner@" || $flag == "everyone@" ]]; then
+		log=$(logname "$acl_parent" $acl_target $ZFS_ACL_CUR_USER)
+		$log operate_node $ZFS_ACL_CUR_USER $node
+	fi
+	if [[ $flag == "group@" || $flag == "everyone@" ]]; then
+		log=$(logname "$acl_parent" $acl_target $g_usr)
+		$log operate_node $g_usr $node
+	fi
+	if [[ $flag == "everyone@" ]]; then
+		log=$(logname "$acl_parent" $acl_target $o_usr)
+		$log operate_node $o_usr $node
+	fi
+	if [[ $flag == "user:"* ]]; then
+		typeset user=${flag#user:}
+		log=$(logname "$acl_parent" $acl_target $user)
+		$log operate_node $user $node
+	fi
+}
+
+function test_chmod_basic_access #node g_usr o_usr
+{
+	typeset node=${1%/}
+	typeset g_usr=$2
+	typeset o_usr=$3
+	typeset flag acl_p acl_t parent
+	typeset -i i=0
+
+	parent=${node%/*}
+
+	for flag in ${a_flag[@]}; do
+	for acl_p in "${access_parent[@]}"; do
+		i=0
+		for acl in $acl_p ; do
+			log_must usr_exec $CHMOD A+$flag:$acl $parent
+			(( i = i + 1))
+		done
+
+		for acl_t in "${access_target[@]}"; do
+			[[ -n $acl_t ]] && \
+				log_must usr_exec $CHMOD A+$flag:$acl_t $node
+
+			log_must $TAR cpf $TESTDIR/$ARCHIVEFILE basedir
+
+			check_chmod_results "$node" "$flag" \
+				 "$acl_p" "$acl_t" "$g_usr" "$o_usr"
+
+			[[ -n $acl_t ]] && \
+				log_must usr_exec $CHMOD A0- $node
+		done
+
+		while (( i > 0 )); do
+			log_must usr_exec $CHMOD A0- $parent
+			(( i = i - 1 ))
+		done
+	done
+	done
+}
+
+function setup_test_files #base_node user group
+{
+	typeset base_node=$1
+	typeset user=$2
+	typeset group=$3
+
+	cleanup_test_files $base_node
+
+	log_must $MKDIR -p $base_node
+	log_must $CHOWN $user:$group $base_node
+
+	log_must set_cur_usr $user
+
+	# Prepare all files/sub-dirs for testing.
+	file0=$base_node/testfile_rm
+	dir0=$base_node/testdir_rm
+
+	log_must usr_exec $TOUCH $file0
+	log_must usr_exec $CHMOD 444 $file0
+
+	log_must usr_exec $MKDIR -p $dir0
+	log_must usr_exec $CHMOD 444 $dir0
+
+	log_must usr_exec $CHMOD 555 $base_node
+	return 0
+}
+
+function cleanup_test_files #base_node
+{
+	typeset base_node=$1
+
+	if [[ -d $base_node ]]; then
+		log_must $RM -rf $base_node
+	elif [[ -e $base_node ]]; then
+		log_must $RM -f $base_node
+	fi
+
+	return 0
+}
+
+typeset cwd=$PWD
+typeset ARCHIVEFILE=archive.tar
+
+typeset -i i=0
+typeset -i j=0
+typeset target
+cd $TESTDIR
+while (( i < ${#users[@]} )); do
+	setup_test_files $TESTDIR/basedir ${users[i]} ${users[((i+1))]}
+
+	j=0
+	while (( j < 1 )); do
+		eval target=\$file$j
+		test_chmod_basic_access $target \
+			"${users[((i+2))]}" "${users[((i+3))]}"
+
+		eval target=\$dir$j
+		test_chmod_basic_access $target \
+			"${users[((i+2))]}" "${users[((i+3))]}"
+
+		(( j = j + 1 ))
+	done
+
+	(( i += 4 ))
+done
+
+log_pass "Verify that the combined delete_child/delete permission for" \
+	"owner/group/everyone are correct."
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/usr/src/test/zfs-tests/tests/functional/acl/nontrivial/zfs_acl_chmod_inherit_001_pos.ksh	Wed Dec 05 22:04:50 2012 -0500
@@ -0,0 +1,173 @@
+#!/bin/ksh -p
+#
+# CDDL HEADER START
+#
+# The contents of this file are subject to the terms of the
+# Common Development and Distribution License (the "License").
+# You may not use this file except in compliance with the License.
+#
+# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
+# or http://www.opensolaris.org/os/licensing.
+# See the License for the specific language governing permissions
+# and limitations under the License.
+#
+# When distributing Covered Code, include this CDDL HEADER in each
+# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
+# If applicable, add the following below this CDDL 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.
+#
+
+. $STF_SUITE/tests/functional/acl/acl_common.kshlib
+
+#
+# DESCRIPTION:
+#	Verify chmod have correct behaviour to directory and file when setting
+#	different inherit strategy to them.
+#
+# STRATEGY:
+#	1. Loop super user and non-super user to run the test case.
+#	2. Create basedir and a set of subdirectores and files within it.
+#	3. Separately chmod basedir with different inherite options.
+#	4. Then create nested directories and files like the following.
+#
+#                                                   _ odir4
+#                                                  |_ ofile4
+#                                         _ odir3 _|
+#                                        |_ ofile3
+#                               _ odir1 _|
+#                              |_ ofile2
+#                     basefile |
+#          chmod -->  basedir -|
+#                              |_ nfile1
+#                              |_ ndir1 _
+#                                        |_ nfile2
+#                                        |_ ndir2 _
+#                                                  |_ nfile3
+#                                                  |_ ndir3
+#
+#	5. Verify each directories and files have the correct access control
+#	   capability.
+#
+
+verify_runnable "both"
+
+function cleanup
+{
+	if [[ -f $basefile ]]; then
+		log_must $RM -f $basefile
+	fi
+	if [[ -d $basedir ]]; then
+		log_must $RM -rf $basedir
+	fi
+}
+
+log_assert "Verify chmod have correct behaviour to directory and file when " \
+	"setting different inherit strategies to them."
+log_onexit cleanup
+
+# Define inherit flag
+set -A object_flag file_inherit dir_inherit file_inherit/dir_inherit
+set -A strategy_flag "" inherit_only no_propagate inherit_only/no_propagate
+
+# Defile the based directory and file
+basedir=$TESTDIR/basedir;  basefile=$TESTDIR/basefile
+
+# Define the existed files and directories before chmod
+odir1=$basedir/odir1; odir2=$odir1/odir2; odir3=$odir2/odir3
+ofile1=$basedir/ofile1; ofile2=$odir1/ofile2; ofile3=$odir2/ofile3
+
+# Define the files and directories will be created after chmod
+ndir1=$basedir/ndir1; ndir2=$ndir1/ndir2; ndir3=$ndir2/ndir3
+nfile1=$basedir/nfile1; nfile2=$ndir1/nfile2; nfile3=$ndir2/nfile3
+
+# Verify all the node have expected correct access control
+allnodes="$basedir $ndir1 $ndir2 $ndir3 $nfile1 $nfile2 $nfile3"
+allnodes="$allnodes $odir1 $odir2 $odir3 $ofile1 $ofile2 $ofile3"
+
+#
+# According to inherited flag, verify subdirectories and files within it has
+# correct inherited access control.
+#
+function verify_inherit #<object> [strategy]
+{
+	# Define the nodes which will be affected by inherit.
+	typeset inherit_nodes
+	typeset obj=$1
+	typeset str=$2
+
+	log_must usr_exec $MKDIR -p $ndir3
+	log_must usr_exec $TOUCH $nfile1 $nfile2 $nfile3
+
+	# Except for inherit_only, the basedir was affected always.
+	if [[ $str != *"inherit_only"* ]]; then
+		inherit_nodes="$inherit_nodes $basedir"
+	fi
+	# Get the files which inherited ACE.
+	if [[ $obj == *"file_inherit"* ]]; then
+		inherit_nodes="$inherit_nodes $nfile1"
+
+		if [[ $str != *"no_propagate"* ]]; then
+			inherit_nodes="$inherit_nodes $nfile2 $nfile3"
+		fi
+	fi
+	# Get the directores which inherited ACE.
+	if [[ $obj == *"dir_inherit"* ]]; then
+		inherit_nodes="$inherit_nodes $ndir1"
+
+		if [[ $str != *"no_propagate"* ]]; then
+			inherit_nodes="$inherit_nodes $ndir2 $ndir3"
+		fi
+	fi
+
+	for node in $allnodes; do
+		if [[ " $inherit_nodes " == *" $node "* ]]; then
+			log_mustnot chgusr_exec $ZFS_ACL_OTHER1 $LS -vd $node \
+				> /dev/null 2>&1
+		else
+			log_must chgusr_exec $ZFS_ACL_OTHER1 $LS -vd $node \
+				> /dev/null 2>&1
+		fi
+	done
+}
+
+for user in root $ZFS_ACL_STAFF1; do
+	log_must set_cur_usr $user
+
+	for obj in "${object_flag[@]}"; do
+		for str in "${strategy_flag[@]}"; do
+			typeset inh_opt=$obj
+			(( ${#str} != 0 )) && inh_opt=$inh_opt/$str
+			aclspec="A+user:$ZFS_ACL_OTHER1:read_acl:$inh_opt:deny"
+
+			log_must usr_exec $MKDIR $basedir
+			log_must usr_exec $TOUCH $basefile
+			log_must usr_exec $MKDIR -p $odir3
+			log_must usr_exec $TOUCH $ofile1 $ofile2 $ofile3
+
+			#
+			# Inherit flag can only be placed on a directory,
+			# otherwise it will fail.
+			#
+			log_must usr_exec $CHMOD $aclspec $basefile
+
+			#
+			# Place on a directory should succeed.
+			#
+			log_must usr_exec $CHMOD $aclspec $basedir
+
+			verify_inherit $obj $str
+
+			log_must usr_exec $RM -rf $basefile $basedir
+		done
+	done
+done
+
+log_pass "Verify chmod inherit behaviour passed."
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/usr/src/test/zfs-tests/tests/functional/acl/nontrivial/zfs_acl_chmod_inherit_002_neg.ksh	Wed Dec 05 22:04:50 2012 -0500
@@ -0,0 +1,339 @@
+#!/bin/ksh -p
+#
+# CDDL HEADER START
+#
+# The contents of this file are subject to the terms of the
+# Common Development and Distribution License (the "License").
+# You may not use this file except in compliance with the License.
+#
+# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
+# or http://www.opensolaris.org/os/licensing.
+# See the License for the specific language governing permissions
+# and limitations under the License.
+#
+# When distributing Covered Code, include this CDDL HEADER in each
+# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
+# If applicable, add the following below this CDDL 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.
+#
+
+. $STF_SUITE/tests/functional/acl/acl_common.kshlib
+
+#
+# DESCRIPTION:
+#	Verify chmod have correct behaviour to directory and file not inherited
+#	when filesystem has the different aclinherit setting
+#
+# STRATEGY:
+#	1. Loop super user and non-super user to run the test case.
+#	2. Create basedir and a set of subdirectores and files within it.
+#	3. Separately chmod basedir with different inherite options,
+#	combine with the variable setting of aclinherit:
+#		"discard", "noallow", "restricted" or "passthrough".
+#	4. Then create nested directories and files like the following.
+#
+#                     ofile
+#                     odir
+#          chmod -->  basedir -|
+#                              |_ nfile1
+#                              |_ ndir1 _
+#                                        |_ nfile2
+#                                        |_ ndir2 _
+#                                                  |_ nfile3
+#                                                  |_ ndir3
+#
+#	5. Verify non-inherited directories and files have the correct access
+#	   control capability.
+#
+
+verify_runnable "both"
+
+function cleanup
+{
+	typeset dir
+
+	# Cleanup basedir, compared file and dir.
+
+	if [[ -f $ofile ]]; then
+		log_must $RM -f $ofile
+	fi
+
+	for dir in $odir $basedir ; do
+		if [[ -d $dir ]]; then
+			log_must $RM -rf $dir
+		fi
+	done
+	log_must $ZFS set aclmode=discard $TESTPOOL/$TESTFS
+}
+
+log_assert "Verify chmod have correct behaviour to directory and file when " \
+    "filesystem has the different aclinherit setting."
+log_onexit cleanup
+
+# Define inherit flag
+typeset aclinherit_flag=(discard noallow restricted passthrough)
+typeset object_flag=(file_inherit dir_inherit file_inherit/dir_inherit)
+typeset strategy_flag=("" inherit_only no_propagate inherit_only/no_propagate)
+
+typeset ace_prefix1="user:$ZFS_ACL_OTHER1"
+typeset ace_prefix2="user:$ZFS_ACL_OTHER2"
+typeset ace_discard ace_noallow ace_secure ace_passthrough
+typeset ace_secure_new
+
+# Defile the based directory and file
+basedir=$TESTDIR/basedir;  ofile=$TESTDIR/ofile; odir=$TESTDIR/odir
+
+# Define the files and directories will be created after chmod
+ndir1=$basedir/ndir1; ndir2=$ndir1/ndir2; ndir3=$ndir2/ndir3
+nfile1=$basedir/nfile1; nfile2=$ndir1/nfile2; nfile3=$ndir2/nfile3
+
+# Verify all the node have expected correct access control
+allnodes="$ndir1 $ndir2 $ndir3 $nfile1 $nfile2 $nfile3"
+
+#
+# According to inherited flag, verify subdirectories and files within it has
+# correct inherited access control.
+#
+function verify_inherit #<aclinherit> <object> [strategy]
+{
+	# Define the nodes which will be affected by inherit.
+	typeset non_inherit_nodes=""
+	typeset inherit=$1
+	typeset obj=$2
+	typeset str=$3
+	typeset inherit_type
+	typeset str1="/inherit_only/inherited:"
+	typeset str2="/inherited:"
+
+	# count: the ACE item to fetch
+	# maxnumber: predefine as 4
+	# passcnt: counter, if it achieves to maxnumber,
+	#	then no additional ACE should apply.
+	# isinherit: indicate if the current target is in the inherit list.
+
+	typeset -i count=0 pass=0 passcnt=0 isinherit=0 maxnumber=4 no_propagate=0
+
+	log_must usr_exec $MKDIR -p $ndir3
+	log_must usr_exec $TOUCH $nfile1 $nfile2 $nfile3
+
+	# Get the inherit type/object_flag and non-inherited nodes.
+	if [[ $obj == *"file_inherit"* && $obj == *"dir_inherit"* ]]; then
+		inherit_type="both"
+		if [[ $str == *"no_propagate"* ]]; then
+			non_inherit_nodes= $ndir2 $ndir3 $nfile2 $nfile3
+			no_propagate=1
+		fi
+	elif [[ $obj == *"dir_inherit"* ]]; then
+		inherit_type="directory"
+		non_inherit_nodes="$nfile1 $nfile2 $nfile3"
+		if [[ $str == *"no_propagate"* ]]; then
+			non_inherit_nodes="$non_inherit_nodes $ndir2 $ndir3"
+			no_propagate=1
+		fi
+	else
+		inherit_type="file"
+		non_inherit_nodes="$ndir1 $ndir2 $ndir3"
+		if [[ $str == *"no_propagate"* ]]; then
+			non_inherit_nodes="$non_inherit_nodes $nfile2 $nfile3"
+			no_propagate=1
+		fi
+	fi
+	# Verify ACE's for all the dirs/files under $basedir
+	for node in $allnodes; do
+		if [[ " $non_inherit_nodes " == *" $node "* ]]; then
+			no_inherit=1
+		else
+			no_inherit=0
+		fi
+		i=0
+		count=0
+		passcnt=0
+		while ((i < maxnumber)); do
+			pass=0
+			eval expect1=\$acl$i
+			case $inherit in
+				noallow)
+					[[ $expect1 == *":allow" ]] && pass=1
+					;;
+				discard)
+					passcnt=maxnumber
+					break
+					;;
+			esac
+			if ((pass == 0 && no_inherit == 1)); then
+				aclaction=${expect1##*:}
+				acltemp=${expect1%:*}
+				# Verify ACE's for sub-directory
+				if [[ -d $node ]]; then
+					eval expect1=\$acl$i
+					acltemp=${expect1%:*}
+					if [[ $inherit_type == "directory" || \
+					    $inherit_type == "both" ]]; then
+						expect1=${acltemp}/inherited:
+						expect1=${expect1}${aclaction}
+					elif [[ $inherit_type == "file" ]]; then
+						if [[ $expect1 != \
+						    *"inherit_only"* ]]; then
+							#
+							# directory should append
+							# "inherit_only" if not have
+							#
+							expect1=${acltemp}${str1}
+							expect1=${expect1}${aclaction}
+						else
+							expect1=${acltemp}${str2}
+							expect1=${expect1}${aclaction}
+						fi
+					fi
+					aclcur=$(get_ACE $node $count)
+					aclcur=${aclcur#$count:}
+					if [[ $no_propagate == 0 ]]; then
+						if [[ $expect1 != $aclcur ]]; then
+							$LS -vd $basedir
+							$LS -vd $node
+							log_fail "$inherit $i #"\
+							    "$count ACE: $aclcur"\
+							    "expect to be $expect1"
+						fi
+					else
+						# compare if directory has basic
+						# ACL's
+						compare_acls $node $odir
+						if [[ $? -ne 0 ]]; then
+							$LS -vd $basedir
+							$LS -vd $node
+							log_fail "Unexpect acl:"\
+							    " $node, $inherit"
+							    "($str)"
+						fi
+					fi
+				# Verify ACE's for nested file
+				elif [[ -f $node ]]; then
+					compare_acls $node $ofile
+					if [[ $? -ne 0 ]]; then
+						$LS -vd $basedir
+						$LS -vd $node
+						log_fail "Unexpect acl: $node," \
+						    "$inherit ($str)"
+					fi
+
+				fi
+				((count = count + 1))
+			fi
+			((i = i + 1))
+		done
+
+		#
+		# If there's no any ACE be checked, it should be identify as
+		# an normal file/dir, verify it.
+		#
+
+		if ((passcnt == maxnumber)); then
+			if [[ -d $node ]]; then
+				compare_acls $node $odir
+			elif [[	-f $node ]]; then
+				compare_acls $node $ofile
+			fi
+
+			if [[ $? -ne 0 ]]; then
+				$LS -vd $basedir
+				$LS -vd $node
+				log_fail "Unexpect acl: $node, $inherit ($str)"
+			fi
+		fi
+	done
+}
+
+typeset -i i=0
+typeset acl0 acl1 acl2 acl3
+typeset acls0 acls1 acls2 acls3
+
+#
+# Set aclmode=passthrough to make sure
+# the acl will not change during chmod.
+# A general testing should verify the combination of
+# aclmode/aclinherit works well,
+# here we just simple test them separately.
+#
+
+log_must $ZFS set aclmode=passthrough $TESTPOOL/$TESTFS
+
+for inherit in "${aclinherit_flag[@]}"; do
+
+	#
+	# Set different value of aclinherit
+	#
+
+	log_must $ZFS set aclinherit=$inherit $TESTPOOL/$TESTFS
+
+	for user in root $ZFS_ACL_STAFF1; do
+		log_must set_cur_usr $user
+
+		for obj in "${object_flag[@]}"; do
+			for str in "${strategy_flag[@]}"; do
+				typeset inh_opt=$obj
+				((${#str} != 0)) && inh_opt=$inh_opt/$str
+
+				#
+				# Prepare 4 ACES, which should include :
+				# deny -> to verify "noallow"
+				# write_acl/write_owner -> to verify "secure"
+				#
+
+				acl0=${ace_prefix1}":read_xattr/write_acl/"
+				acl0=${acl0}"write_owner:"${inh_opt}":deny"
+				acl1="$ace_prefix2:read_xattr/write_acl/"
+				acl1=${acl1}"write_owner:$inh_opt:allow"
+				acl2="$ace_prefix1:read_xattr:$inh_opt:deny"
+				acl3="$ace_prefix2:read_xattr:$inh_opt:allow"
+
+				#
+				# The ACE filtered by write_acl/write_owner
+				#
+
+				acls0="$ace_prefix1:read_xattr:$inh_opt:deny"
+				acls1="$ace_prefix2:read_xattr:$inh_opt:allow"
+				acls2=$acl2
+				acls3=$acl3
+				#
+				# Create basedir and tmp dir/file
+				# for comparison.
+				#
+				log_note "$user: $CHMOD $acl $basedir"
+				log_must usr_exec $MKDIR $basedir
+				log_must usr_exec $MKDIR $odir
+				log_must usr_exec $TOUCH $ofile
+
+				i=3
+				while ((i >= 0)); do
+					eval acl=\$acl$i
+
+				#
+				# Place on a directory should succeed.
+				#
+					log_must usr_exec $CHMOD A+$acl $basedir
+
+					((i = i - 1))
+				done
+				log_note "verify_inherit $inherit $obj $str"
+				log_must verify_inherit $inherit $obj $str
+
+				log_must usr_exec $RM -rf $ofile $odir $basedir
+			done
+		done
+	done
+done
+
+log_pass "Verify chmod inherit behaviour co-op with aclinherit setting passed."
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/usr/src/test/zfs-tests/tests/functional/acl/nontrivial/zfs_acl_chmod_inherit_002_pos.ksh	Wed Dec 05 22:04:50 2012 -0500
@@ -0,0 +1,357 @@
+#!/bin/ksh -p
+#
+# CDDL HEADER START
+#
+# The contents of this file are subject to the terms of the
+# Common Development and Distribution License (the "License").
+# You may not use this file except in compliance with the License.
+#
+# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
+# or http://www.opensolaris.org/os/licensing.
+# See the License for the specific language governing permissions
+# and limitations under the License.
+#
+# When distributing Covered Code, include this CDDL HEADER in each
+# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
+# If applicable, add the following below this CDDL 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.
+#
+
+. $STF_SUITE/tests/functional/acl/acl_common.kshlib
+
+#
+# DESCRIPTION:
+#	Verify chmod have correct behaviour to directory and file when
+#	filesystem has the different aclinherit setting
+#
+# STRATEGY:
+#	1. Loop super user and non-super user to run the test case.
+#	2. Create basedir and a set of subdirectores and files within it.
+#	3. Separately chmod basedir with different inherite options,
+#	combine with the variable setting of aclinherit:
+#		"discard", "noallow", "restricted" or "passthrough".
+#	4. Then create nested directories and files like the following.
+#
+#                     ofile
+#                     odir
+#          chmod -->  basedir -|
+#                              |_ nfile1
+#                              |_ ndir1 _
+#                                        |_ nfile2
+#                                        |_ ndir2 _
+#                                                  |_ nfile3
+#                                                  |_ ndir3
+#
+#	5. Verify each directories and files have the correct access control
+#	   capability.
+#
+
+verify_runnable "both"
+
+function cleanup
+{
+	typeset dir
+
+	# Cleanup basedir, compared file and dir.
+
+	if [[ -f $ofile ]]; then
+		log_must $RM -f $ofile
+	fi
+
+	for dir in $odir $basedir ; do
+		if [[ -d $dir ]]; then
+			log_must $RM -rf $dir
+		fi
+	done
+	log_must $ZFS set aclmode=discard $TESTPOOL/$TESTFS
+}
+
+log_assert "Verify chmod have correct behaviour to directory and file when " \
+	"filesystem has the different aclinherit setting."
+log_onexit cleanup
+
+# Define inherit flag
+typeset aclinherit_flag=(discard noallow restricted passthrough)
+typeset object_flag=(file_inherit dir_inherit file_inherit/dir_inherit)
+typeset strategy_flag=("" inherit_only no_propagate inherit_only/no_propagate)
+
+typeset ace_prefix1="user:$ZFS_ACL_OTHER1"
+typeset ace_prefix2="user:$ZFS_ACL_OTHER2"
+
+# Defile the based directory and file
+basedir=$TESTDIR/basedir;  ofile=$TESTDIR/ofile; odir=$TESTDIR/odir
+
+# Define the files and directories will be created after chmod
+ndir1=$basedir/ndir1; ndir2=$ndir1/ndir2; ndir3=$ndir2/ndir3
+nfile1=$basedir/nfile1; nfile2=$ndir1/nfile2; nfile3=$ndir2/nfile3
+
+# Verify all the node have expected correct access control
+allnodes="$ndir1 $ndir2 $ndir3 $nfile1 $nfile2 $nfile3"
+
+#
+# According to inherited flag, verify subdirectories and files within it has
+# correct inherited access control.
+#
+function verify_inherit #<aclinherit> <object> [strategy]
+{
+	# Define the nodes which will be affected by inherit.
+	typeset inherit_nodes
+	typeset inherit=$1
+	typeset obj=$2
+	typeset str=$3
+	typeset str1="/inherited:"
+
+	# count: the ACE item to fetch
+	# pass: to mark if the current ACE should apply to the target
+	# maxnumber: predefine as 4
+	# passcnt: counter, if it achieves to maxnumber,
+	#	then no additional ACE should apply.
+	# isinherit: indicate if the current target is in the inherit list.
+
+	typeset -i count=0 pass=0 passcnt=0 isinherit=0 maxnumber=4
+
+	log_must usr_exec $MKDIR -p $ndir3
+	log_must usr_exec $TOUCH $nfile1 $nfile2 $nfile3
+
+	# Get the files which inherited ACE.
+	if [[ $obj == *"file_inherit"* ]]; then
+		inherit_nodes="$inherit_nodes $nfile1"
+
+		if [[ $str != *"no_propagate"* ]]; then
+			inherit_nodes="$inherit_nodes $nfile2 $nfile3"
+		fi
+	fi
+	# Get the directores which inherited ACE.
+	if [[ $obj == *"dir_inherit"* ]]; then
+		inherit_nodes="$inherit_nodes $ndir1"
+
+		if [[ $str != *"no_propagate"* ]]; then
+			inherit_nodes="$inherit_nodes $ndir2 $ndir3"
+		fi
+	fi
+
+	for node in $allnodes; do
+		if [[ " $inherit_nodes " == *" $node "* ]]; then
+			isinherit=1
+		else
+			isinherit=0
+		fi
+
+		i=0
+		count=0
+		passcnt=0
+		while ((i < maxnumber)); do
+			pass=0
+			eval expect1=\$acl$i
+
+		#
+		# aclinherit=passthrough,
+		# inherit all inheritable ACL entries without any
+		# modifications made to the ACL entries when they
+		# are inherited.
+		#
+		# aclinherit=restricted,
+		# any inheritable ACL entries will remove
+		# write_acl and write_owner permissions when the ACL entry is
+		# inherited.
+		#
+		# aclinherit=noallow,
+		# only inherit inheritable ACE that specify "deny" permissions
+		#
+		# aclinherit=discard
+		# will not inherit any ACL entries
+		#
+
+			case $inherit in
+				passthrough)
+					;;
+				restricted)
+					[[ $expect1 == *":allow" ]] && \
+						eval expect1=\$acls$i
+					;;
+				noallow)
+					if [[ $expect1 == *":allow" ]]; then
+						pass=1
+						((passcnt = passcnt + 1))
+					fi
+					;;
+				discard)
+					passcnt=maxnumber
+					break
+					;;
+			esac
+			propagate=0
+			# verify ACE's only for inherited nodes
+			if ((pass == 0 && isinherit == 1)); then
+				aclaction=${expect1##*:}
+
+				if [[ $expect1 == *"propagate"* ]]; then
+					# strip strategy flags from the expect
+					# value
+					acltemp=${expect1%/*}
+					expect1=${acltemp}
+					propagate=1
+				fi
+				acltemp=${expect1%:*}
+				if [[ -d $node ]]; then
+					if [[ $expect1 == *"inherit_only"* \
+					    && $propagate == 0 ]]; then
+						# prepare expect value for
+						# "inherit_only" nodes
+						acltemp_subdir=${expect1%/*}
+						expect1=${acltemp_subdir}${str1}
+						expect1=${expect1}${aclaction}
+
+					elif [[ $propagate == 1 ]]; then
+						# prepare expect value for
+						# "propagate" nodes
+						expect1=${acltemp}:inherited:
+						expect1=${expect1}${aclaction}
+
+					else
+						# prepare expect value for nodes
+						# with no starategy flags
+						expect1=${acltemp}${str1}
+						expect1=${expect1}${aclaction}
+					fi
+
+				elif [[ -f $node ]]; then
+					acltemp_subfile=${expect1%file*}
+					expect1=${acltemp_subfile}inherited:
+					expect1=${expect1}${aclaction}
+				fi
+
+				# Get the first ACE to do comparison
+
+				aclcur=$(get_ACE $node $count)
+				aclcur=${aclcur#$count:}
+				if [[ -n $expect1 && $expect1 != $aclcur ]]; then
+					$LS -vd $basedir
+					$LS -vd $node
+					log_fail "$inherit $i #$count " \
+						"ACE: $aclcur, expect to be " \
+						"$expect1"
+				fi
+
+				((count = count + 1))
+			fi
+			((i = i + 1))
+		done
+
+		#
+		# If there's no any ACE be checked, it should be identify as
+		# an normal file/dir, verify it.
+		#
+
+		if ((passcnt == maxnumber)); then
+			if [[ -d $node ]]; then
+				compare_acls $node $odir
+			elif [[	-f $node ]]; then
+				compare_acls $node $ofile
+			fi
+
+			if [[ $? -ne 0 ]]; then
+				$LS -vd $basedir
+				$LS -vd $node
+				log_fail "Unexpect acl: $node, $inherit ($str)"
+			fi
+		fi
+	done
+}
+
+typeset -i i=0
+typeset acl0 acl1 acl2 acl3
+typeset acls0 acls1 acls2 acls3
+
+#
+# Set aclmode=passthrough to make sure
+# the acl will not change during chmod.
+# A general testing should verify the combination of
+# aclmode/aclinherit works well,
+# here we just simple test them separately.
+#
+
+log_must $ZFS set aclmode=passthrough $TESTPOOL/$TESTFS
+
+for inherit in "${aclinherit_flag[@]}"; do
+
+	#
+	# Set different value of aclinherit
+	#
+
+	log_must $ZFS set aclinherit=$inherit $TESTPOOL/$TESTFS
+
+	for user in root $ZFS_ACL_STAFF1; do
+		log_must set_cur_usr $user
+
+		for obj in "${object_flag[@]}"; do
+			for str in "${strategy_flag[@]}"; do
+				typeset inh_opt=$obj
+				((${#str} != 0)) && inh_opt=$inh_opt/$str
+
+				#
+				# Prepare 4 ACES, which should include :
+				# deny -> to verify "noallow"
+				# write_acl/write_owner -> to verify "restricted"
+				#
+
+				acl0=${ace_prefix1}":read_xattr/write_acl"
+				acl0=${acl0}"/write_owner:$inh_opt:deny"
+				acl1=${ace_prefix2}":read_xattr/write_acl/"
+				acl1=${acl1}"write_owner:$inh_opt:allow"
+				acl2="$ace_prefix1:read_xattr:$inh_opt:deny"
+				acl3="$ace_prefix2:read_xattr:$inh_opt:allow"
+
+				#
+				# The ACE filtered by write_acl/write_owner
+				#
+
+				acls0="$ace_prefix1:read_xattr:$inh_opt:deny"
+				acls1="$ace_prefix2:read_xattr:$inh_opt:allow"
+				acls2=$acl2
+				acls3=$acl3
+
+
+				#
+				# Create basedir and tmp dir/file
+				# for comparison.
+				#
+
+				log_note "$user: $CHMOD $acl $basedir"
+				log_must usr_exec $MKDIR $basedir
+				log_must usr_exec $MKDIR $odir
+				log_must usr_exec $TOUCH $ofile
+
+				i=3
+				while ((i >= 0)); do
+					eval acl=\$acl$i
+
+				#
+				# Place on a directory should succeed.
+				#
+					log_must usr_exec $CHMOD A+$acl $basedir
+
+					((i = i - 1))
+				done
+
+				verify_inherit $inherit $obj $str
+
+				log_must usr_exec $RM -rf $ofile $odir $basedir
+			done
+		done
+	done
+done
+
+log_pass "Verify chmod inherit behaviour co-op with aclinherit setting passed."
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/usr/src/test/zfs-tests/tests/functional/acl/nontrivial/zfs_acl_chmod_inherit_003_pos.ksh	Wed Dec 05 22:04:50 2012 -0500
@@ -0,0 +1,406 @@
+#!/bin/ksh -p
+#
+# CDDL HEADER START
+#
+# The contents of this file are subject to the terms of the
+# Common Development and Distribution License (the "License").
+# You may not use this file except in compliance with the License.
+#
+# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
+# or http://www.opensolaris.org/os/licensing.
+# See the License for the specific language governing permissions
+# and limitations under the License.
+#
+# When distributing Covered Code, include this CDDL HEADER in each
+# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
+# If applicable, add the following below this CDDL 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.
+#
+
+. $STF_SUITE/tests/functional/acl/acl_common.kshlib
+
+#
+# DESCRIPTION:
+#	Verify chmod have correct behaviour to directory and file when
+#	filesystem has the different aclinherit setting
+#
+# STRATEGY:
+#	1. Loop super user and non-super user to run the test case.
+#	2. Create basedir and a set of subdirectores and files within it.
+#	3. Separately chmod basedir with different inherite options,
+#		combine with the variable setting of aclinherit:
+#		"discard", "noallow", "secure" or "passthrough".
+#	4. Then create nested directories and files like the following.
+#
+#                     ofile
+#                     odir
+#          chmod -->  basedir -|
+#                              |_ nfile1
+#                              |_ ndir1 _
+#                                        |_ nfile2
+#                                        |_ ndir2 _
+#                                                  |_ nfile3
+#                                                  |_ ndir3
+#
+#	5. Verify each directories and files have the correct access control
+#	   capability.
+#
+
+verify_runnable "both"
+
+function cleanup
+{
+	typeset dir
+
+	# Cleanup basedir, compared file and dir.
+
+	if [[ -f $ofile ]]; then
+		log_must $RM -f $ofile
+	fi
+
+	for dir in $odir $basedir ; do
+		if [[ -d $dir ]]; then
+			log_must $RM -rf $dir
+		fi
+	done
+}
+
+log_assert "Verify chmod have correct behaviour to directory and file when " \
+    "filesystem has the different aclinherit setting."
+log_onexit cleanup
+
+# Define inherit flag
+typeset aclinherit_flag=(discard noallow secure passthrough)
+typeset object_flag=("f-" "-d" "fd")
+typeset strategy_flag=("--" "i-" "-n" "in")
+
+typeset ace_prefix1="owner@"
+typeset ace_prefix2="group@"
+typeset ace_prefix3="everyone@"
+typeset ace_discard ace_noallow ace_secure ace_passthrough
+typeset ace_secure_new
+
+# Defile the based directory and file
+basedir=$TESTDIR/basedir;  ofile=$TESTDIR/ofile; odir=$TESTDIR/odir
+
+# Define the files and directories will be created after chmod
+ndir1=$basedir/ndir1; ndir2=$ndir1/ndir2; ndir3=$ndir2/ndir3
+nfile1=$basedir/nfile1; nfile2=$ndir1/nfile2; nfile3=$ndir2/nfile3
+
+# Verify all the node have expected correct access control
+allnodes="$ndir1 $ndir2 $ndir3 $nfile1 $nfile2 $nfile3"
+
+#
+# According to inherited flag, verify subdirectories and files within it has
+# correct inherited access control.
+#
+function verify_inherit #<aclinherit> <object> [strategy]
+{
+	# Define the nodes which will be affected by inherit.
+	typeset inherit_nodes
+	typeset inherit=$1
+	typeset obj=$2
+	typeset str=$3
+
+	# count: the ACE item to fetch
+	# pass: to mark if the current ACE should apply to the target
+	# maxnumber: predefine as 4
+	# passcnt: counter, if it achieves to maxnumber,
+	#	then no additional ACE should apply.
+	# isinherit: indicate if the current target is in the inherit list.
+	# step: indicate if the ACE be split during inherit.
+
+	typeset -i count=0 pass=0 passcnt=0 isinherit=0 maxnumber=4 step=0
+
+	log_must usr_exec $MKDIR -p $ndir3
+	log_must usr_exec $TOUCH $nfile1 $nfile2 $nfile3
+
+	# Get the files which inherited ACE.
+	if [[ $(get_substr $obj 1 1) == f ]]; then
+		inherit_nodes="$inherit_nodes $nfile1"
+
+		if [[ $(get_substr $str 2 1) != n ]]; then
+			inherit_nodes="$inherit_nodes $nfile2 $nfile3"
+		fi
+	fi
+	# Get the directores which inherited ACE.
+	if [[ $(get_substr $obj 2 1) == d ]]; then
+		inherit_nodes="$inherit_nodes $ndir1"
+
+		if [[ $(get_substr $str 2 1) != n ]]; then
+			inherit_nodes="$inherit_nodes $ndir2 $ndir3"
+		fi
+	fi
+
+	for node in $allnodes; do
+		step=0
+		if [[ " $inherit_nodes " == *" $node "* ]]; then
+			isinherit=1
+			if [[ -d $node ]] ; then
+				step=1
+			fi
+		else
+			isinherit=0
+		fi
+
+		i=0
+		count=0
+		passcnt=0
+		while ((i < maxnumber)); do
+			pass=0
+			eval expect1=\$acl$i
+			expect2=$expect1
+
+		#
+		# aclinherit=passthrough,
+		# inherit all inheritable ACL entries without any
+		# modifications made to the ACL entries when they
+		# are inherited.
+		#
+		# aclinherit=secure,
+		# any inheritable ACL entries will remove
+		# write_acl and write_owner permissions when the ACL entry is
+		# inherited.
+		#
+		# aclinherit=noallow,
+		# only inherit inheritable ACE that specify "deny" permissions
+		#
+		# aclinherit=discard
+		# will not inherit any ACL entries
+		#
+
+			case $inherit in
+				passthrough)
+					action=${expect1##*:}
+					expect1=${expect1%:$action}
+					expect1=${expect1%-}
+					expect1=${expect1%I}
+					expect1=${expect1}I:$action
+					;;
+				secure)
+					eval expect2=\$acls$i
+					;;
+				noallow)
+					if [[ $expect1 == *":allow" ]] ; then
+						pass=1
+						((passcnt = passcnt + 1))
+					else
+						eval expect2=\$acls$i
+					fi
+					;;
+				discard)
+					passcnt=maxnumber
+					break
+					;;
+			esac
+
+			if ((pass == 0)) ; then
+				acltemp=${expect2%:*}
+				acltemp=${acltemp%:*}
+				aclaction=${expect2##*:}
+				expect2=${acltemp}:------I:${aclaction}
+
+				acltemp=${expect1%:*}
+				inh=${acltemp##*:}
+
+				if [[ -d $node ]]; then
+					if [[ $(get_substr $inh 4 1) == n ]]; then
+
+						#
+						# if no_propagate is set,
+						# then clear all inherit flags,
+						# only one ACE should left.
+						#
+
+						step=0
+						expect1=""
+
+					elif [[ $(get_substr $inh 3 1) != i ]]; then
+
+						#
+						# directory should append
+						# "inherit_only" if not have
+						#
+						acltemp=${acltemp%i*}
+						expect1=${acltemp}i---I:${aclaction}
+					else
+						acltemp=${acltemp%-}
+						acltemp=${acltemp%I}
+						expect1=${acltemp}I:${aclaction}
+					fi
+
+					#
+					# cleanup the first ACE if the directory
+					# not in inherit list
+					#
+
+					if ((isinherit == 0)); then
+						expect1=""
+					fi
+				elif [[ -f $node ]] ; then
+					expect1=""
+				fi
+
+				# Get the first ACE to do comparison
+
+				aclcur=$(get_ACE $node $count compact)
+				aclcur=${aclcur#$count:}
+				if [[ -n $expect1 && $expect1 != $aclcur ]]; then
+					$LS -Vd $basedir
+					$LS -Vd $node
+					log_fail "$inherit $i #$count " \
+					    "ACE: $aclcur, expect to be " \
+					    "$expect1"
+				fi
+
+				#
+				# Get the second ACE (if should have) to do
+				# comparison
+				#
+				if ((step > 0)); then
+					((count = count + step))
+
+					aclcur=$(get_ACE $node $count compact)
+					aclcur=${aclcur#$count:}
+					if [[ -n $expect2 && \
+					    $expect2 != $aclcur ]]; then
+
+						$LS -Vd $basedir
+						$LS -Vd $node
+						log_fail "$inherit $i " \
+						    "#$count ACE: $aclcur, " \
+						    "expect to be $expect2"
+					fi
+				fi
+				((count = count + 1))
+			fi
+			((i = i + 1))
+		done
+
+		#
+		# If there's no any ACE be checked, it should be identify as
+		# an normal file/dir, verify it.
+		#
+
+		if ((passcnt == maxnumber)); then
+			if [[ -d $node ]]; then
+				compare_acls $node $odir
+			elif [[	-f $node ]]; then
+				compare_acls $node $ofile
+			fi
+
+			if [[ $? -ne 0 ]]; then
+				$LS -Vd $basedir
+				$LS -Vd $node
+				log_fail "Unexpect acl: $node, $inherit ($str)"
+			fi
+		fi
+	done
+}
+
+typeset -i i=0
+typeset acl0 acl1 acl2 acl3
+typeset acls0 acls1 acls2 acls3
+
+#
+# Set aclmode=passthrough to make sure
+# the acl will not change during chmod.
+# A general testing should verify the combination of
+# aclmode/aclinherit works well,
+# here we just simple test them separately.
+#
+
+log_must $ZFS set aclmode=passthrough $TESTPOOL/$TESTFS
+
+for inherit in "${aclinherit_flag[@]}"; do
+
+	#
+	# Set different value of aclinherit
+	#
+
+	log_must $ZFS set aclinherit=$inherit $TESTPOOL/$TESTFS
+
+	for user in root $ZFS_ACL_STAFF1; do
+		log_must set_cur_usr $user
+
+		for obj in "${object_flag[@]}"; do
+			for str in "${strategy_flag[@]}"; do
+				typeset inh_opt=$obj
+				((${#str} != 0)) && inh_opt=${inh_opt}${str}--
+
+				inh_a=${inh_opt}-
+				inh_b=${inh_opt}I
+
+				#
+				# Prepare 4 ACES, which should include :
+				# deny -> to verify "noallow"
+				# write_acl/write_owner -> to verify "secure"
+				#
+
+				acl0="$ace_prefix1:rwxp---A-W-Co-:${inh_a}:allow"
+				acl1="$ace_prefix2:rwxp---A-W-Co-:${inh_a}:deny"
+				acl2="$ace_prefix3:rwxp---A-W-Co-:${inh_a}:allow"
+				acl3="$ace_prefix1:-------A-W----:${inh_a}:deny"
+				acl4="$ace_prefix2:-------A-W----:${inh_a}:allow"
+				acl5="$ace_prefix3:-------A-W----:${inh_a}:deny"
+
+
+				#
+				# The ACE filtered by write_acl/write_owner
+				#
+
+				if [[ $inheri == "passthrough" ]]; then
+					acls0="$ace_prefix1:rwxp---A-W----:${inh_b}:allow"
+					acls1="$ace_prefix2:rwxp---A-W----:${inh_b}:deny"
+					acls2="$ace_prefix3:rwxp---A-W----:${inh_b}:allow"
+					acls3="$ace_prefix1:rwxp---A-W----:${inh_b}:deny"
+					acls4="$ace_prefix2:rwxp---A-W----:${inh_b}:allow"
+					acls5="$ace_prefix3:rwxp---A-W----:${inh_b}:deny"
+				else
+					acls0="$ace_prefix1:-------A-W----:${inh_b}:allow"
+					acls1="$ace_prefix2:-------A-W-Co-:${inh_b}:deny"
+					acls2="$ace_prefix3:-------A-W----:${inh_b}:allow"
+					acls3="$ace_prefix1:-------A-W----:${inh_b}:deny"
+					acls4="$ace_prefix2:-------A-W----:${inh_b}:allow"
+					acls5="$ace_prefix3:-------A-W----:${inh_b}:deny"
+				fi
+
+				#
+				# Create basedir and tmp dir/file
+				# for comparison.
+				#
+
+				log_note "$user: $CHMOD $acl $basedir"
+				log_must usr_exec $MKDIR $basedir
+				log_must usr_exec $MKDIR $odir
+				log_must usr_exec $TOUCH $ofile
+
+				i=5
+				while ((i >= 0)); do
+					eval acl=\$acl$i
+
+				#
+				# Place on a directory should succeed.
+				#
+					log_must usr_exec $CHMOD A+$acl $basedir
+
+					((i = i - 1))
+				done
+
+				verify_inherit $inherit $obj $str
+
+				log_must usr_exec $RM -rf $ofile $odir $basedir
+			done
+		done
+	done
+done
+
+log_pass "Verify chmod inherit behaviour co-op with aclinherit setting passed."
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/usr/src/test/zfs-tests/tests/functional/acl/nontrivial/zfs_acl_chmod_inherit_004_pos.ksh	Wed Dec 05 22:04:50 2012 -0500
@@ -0,0 +1,149 @@
+#!/bin/ksh -p
+#
+# CDDL HEADER START
+#
+# The contents of this file are subject to the terms of the
+# Common Development and Distribution License (the "License").
+# You may not use this file except in compliance with the License.
+#
+# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
+# or http://www.opensolaris.org/os/licensing.
+# See the License for the specific language governing permissions
+# and limitations under the License.
+#
+# When distributing Covered Code, include this CDDL HEADER in each
+# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
+# If applicable, add the following below this CDDL 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) 2012 by Delphix. All rights reserved.
+#
+
+. $STF_SUITE/tests/functional/acl/acl_common.kshlib
+
+#
+# DESCRIPTION:
+#	Verify aclinherit=passthrough-x will inherit the 'x' bits while mode request.
+#
+# STRATEGY:
+#	1. Loop super user and non-super user to run the test case.
+#	2. Create basedir and a set of subdirectores and files within it.
+#	3. Set aclinherit=passthrough-x
+#	4. Verify only passthrough-x will inherit the 'x' bits while mode request.
+#
+
+verify_runnable "both"
+
+function cleanup
+{
+	if [[ -d $basedir ]]; then
+		log_must $RM -rf $basedir
+	fi
+}
+$ZPOOL upgrade -v
+$ZPOOL upgrade -v | $GREP "passthrough-x aclinherit" > /dev/null 2>&1
+if (($? != 0)); then
+	log_unsupported "passthrough-x aclinherit not supported."
+fi
+
+log_assert "Verify aclinherit=passthrough-x will inherit the 'x' bits while" \
+    " mode request."
+log_onexit cleanup
+
+set -A aces \
+    "owner@:read_data/write_data/add_subdirectory/append_data/execute:dir_inherit/inherit_only:allow" \
+    "owner@:read_data/write_data/add_subdirectory/append_data/execute::allow" \
+    "group@:add_subdirectory/append_data/execute:dir_inherit/inherit_only:allow" \
+    "group@:add_subdirectory/append_data/execute::allow" \
+    "everyone@:add_subdirectory/append_data/execute:dir_inherit/inherit_only:allow" \
+    "everyone@:add_subdirectory/append_data/execute::allow" \
+    "owner@:read_data/write_data/add_subdirectory/append_data/execute:file_inherit/inherit_only:allow" \
+    "group@:read_data/add_subdirectory/append_data/execute:file_inherit/inherit_only:allow" \
+    "everyone@:read_data/add_subdirectory/append_data/execute:file_inherit/inherit_only:allow"
+
+# Defile the based directory and file
+basedir=$TESTDIR/basedir
+
+
+#
+# According to inherited flag, verify subdirectories and files within it has
+# correct inherited access control.
+#
+function verify_inherit # <object>
+{
+	typeset obj=$1
+
+	# Define the files and directories will be created after chmod
+	ndir1=$obj/ndir1; ndir2=$ndir1/ndir2
+	nfile1=$ndir1/nfile1.c; nfile2=$ndir1/nfile2
+
+	log_must usr_exec $MKDIR -p $ndir1
+
+	typeset -i i=0
+	while ((i < ${#aces[*]})); do
+		if ((i < 3)); then
+			log_must usr_exec $CHMOD A$i=${aces[i]} $ndir1
+		else
+			log_must usr_exec $CHMOD A$i+${aces[i]} $ndir1
+		fi
+		((i = i + 1))
+	done
+	log_must usr_exec $MKDIR -p $ndir2
+	log_must usr_exec $TOUCH $nfile1
+
+	$CAT > $nfile1 <<EOF
+#include <stdlib.h>
+#include <stdio.h>
+int main()
+{ return 0; }
+EOF
+
+	mode=$(get_mode $ndir2)
+	if [[ $mode != "drwx--x--x"* ]]; then
+		log_fail "Unexpect mode of $ndir2, expect: drwx--x--x, current: $mode"
+	fi
+
+	mode=$(get_mode $nfile1)
+	if [[ $mode != "-rw-r--r--"* ]]; then
+		log_fail "Unexpect mode of $nfile1, expect: -rw-r--r--, current: $mode"
+	fi
+
+	if [[ -x /usr/sfw/bin/gcc ]]; then
+		log_must /usr/sfw/bin/gcc -o $nfile2 $nfile1
+		mode=$(get_mode $nfile2)
+		if [[ $mode != "-rwxr-xr-x"* ]]; then
+			log_fail "Unexpect mode of $nfile2, expect: -rwxr-xr-x, current: $mode"
+		fi
+	fi
+}
+
+#
+# Set aclmode=passthrough to make sure
+# the acl will not change during chmod.
+# A general testing should verify the combination of
+# aclmode/aclinherit works well,
+# here we just simple test them separately.
+#
+
+log_must $ZFS set aclmode=passthrough $TESTPOOL/$TESTFS
+log_must $ZFS set aclinherit=passthrough-x $TESTPOOL/$TESTFS
+
+for user in root $ZFS_ACL_STAFF1; do
+	log_must set_cur_usr $user
+
+	verify_inherit $basedir
+
+	cleanup
+done
+
+log_pass "Verify aclinherit=passthrough-x will inherit the 'x' bits while mode request."
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/usr/src/test/zfs-tests/tests/functional/acl/nontrivial/zfs_acl_chmod_owner_001_pos.ksh	Wed Dec 05 22:04:50 2012 -0500
@@ -0,0 +1,324 @@
+#!/bin/ksh -p
+#
+# CDDL HEADER START
+#
+# The contents of this file are subject to the terms of the
+# Common Development and Distribution License (the "License").
+# You may not use this file except in compliance with the License.
+#
+# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
+# or http://www.opensolaris.org/os/licensing.
+# See the License for the specific language governing permissions
+# and limitations under the License.
+#
+# When distributing Covered Code, include this CDDL HEADER in each
+# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
+# If applicable, add the following below this CDDL 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) 2012 by Delphix. All rights reserved.
+#
+
+. $STF_SUITE/tests/functional/acl/acl_common.kshlib
+
+#
+# DESCRIPTION:
+#	Verify that the write_owner for
+#	owner/group/everyone are correct.
+#
+# STRATEGY:
+# 1. Create file and  directory in zfs filesystem
+# 2. Set special write_owner ACE to the file and directory
+# 3. Try to chown/chgrp of the file and directory to take owner/group
+# 4. Verify that the owner/group are correct. Follow these rules:
+#	(1) If uid is granted the write_owner permission, then it can only do
+#	    chown to its own uid, or a group that they are a member of.
+#	(2) Owner will ignore permission of (1) even write_owner not granted.
+#	(3) Superuser will always permit whatever they do.
+#
+
+verify_runnable "both"
+
+function cleanup
+{
+	[[ -d $basedir ]] && $RM -rf $basedir
+	[[ -f $TESTDIR/$ARCHIVEFILE ]] && log_must $RM -f $TESTDIR/$ARCHIVEFILE
+	return 0
+}
+
+log_assert "Verify that the chown/chgrp could take owner/group " \
+	"while permission is granted."
+log_onexit cleanup
+
+#
+# Get the owner of a file/directory
+#
+function get_owner
+{
+	typeset node=$1
+
+	if [[ -z $node ]]; then
+		log_fail "node are not defined."
+	fi
+
+	$ECHO $($LS -dl $node | $AWK '{print $3}')
+}
+
+#
+# Get the group of a file/directory
+#
+function get_group
+{
+	typeset node=$1
+
+	if [[ -z $node ]]; then
+		log_fail "node are not defined."
+	fi
+
+	$ECHO $($LS -dl $node | $AWK '{print $4}')
+}
+
+
+#
+# Get the group name that a UID belongs to
+#
+function get_user_group
+{
+	typeset uid=$1
+	typeset value
+
+	if [[ -z $uid ]]; then
+		log_fail "UID not defined."
+	fi
+
+	value=$(id $uid)
+
+	if [[ $? -eq 0 ]]; then
+		value=${value##*\(}
+		value=${value%%\)*}
+		$ECHO $value
+	else
+		log_fail "Invalid UID (uid)."
+	fi
+}
+
+function operate_node_owner
+{
+	typeset user=$1
+	typeset node=$2
+	typeset old_owner=$3
+	typeset expect_owner=$4
+	typeset ret new_owner
+
+	if [[ $user == "" || $node == "" ]]; then
+		log_fail "user, node are not defined."
+	fi
+
+	$SU $user -c "$CHOWN $expect_owner $node"
+	ret=$?
+	new_owner=$(get_owner $node)
+
+	if [[ $new_owner != $old_owner ]]; then
+		$TAR xpf $TESTDIR/$ARCHIVEFILE
+	fi
+
+	if [[ $ret -eq 0 ]]; then
+		if [[ $new_owner != $expect_owner ]]; then
+			log_note "Owner not changed as expected " \
+				"($old_owner|$new_owner|$expect_owner), " \
+				"but return code is $ret."
+			return 1
+		fi
+	elif [[ $ret -ne 0 && $new_owner != $old_owner ]]; then
+		log_note "Owner changed ($old_owner|$new_owner), " \
+			"but return code is $ret."
+		return 2
+	fi
+
+	return $ret
+}
+
+function operate_node_group
+{
+	typeset user=$1
+	typeset node=$2
+	typeset old_group=$3
+	typeset expect_group=$4
+	typeset ret new_group
+
+	if [[ $user == "" || $node == "" ]]; then
+		log_fail "user, node are not defined."
+	fi
+
+	$SU $user -c "$CHGRP $expect_group $node"
+	ret=$?
+	new_group=$(get_group $node)
+
+	if [[ $new_group != $old_group ]]; then
+		$TAR xpf $TESTDIR/$ARCHIVEFILE
+	fi
+
+	if [[ $ret -eq 0 ]]; then
+		if [[ $new_group != $expect_group ]]; then
+			log_note "Group not changed as expected " \
+				"($old_group|$new_group|$expect_group), " \
+				"but return code is $ret."
+			return 1
+		fi
+	elif [[ $ret -ne 0 && $new_group != $old_group ]]; then
+		log_note "Group changed ($old_group|$new_group), " \
+			"but return code is $ret."
+		return 2
+	fi
+
+	return $ret
+}
+
+function logname
+{
+	typeset acl_target=$1
+	typeset user=$2
+	typeset old=$3
+	typeset new=$4
+	typeset ret="log_mustnot"
+
+	# To super user, read and write deny permission was override.
+	if [[ $user == root ]]; then
+		ret="log_must"
+	elif [[ $user == $new ]] ; then
+		if [[ $user == $old || $acl_target == *:allow ]]; then
+			ret="log_must"
+		fi
+	fi
+
+	print $ret
+}
+
+function check_chmod_results
+{
+	typeset user=$1
+	typeset node=$2
+	typeset flag=$3
+	typeset acl_target=$3:$4
+	typeset g_usr=$5
+	typeset o_usr=$6
+	typeset log old_owner old_group new_owner new_group
+
+	old_owner=$(get_owner $node)
+	old_group=$(get_group $node)
+
+	if [[ $flag == "owner@" || $flag == "everyone@" ]]; then
+		for new_owner in $user "nobody"; do
+			new_group=$(get_user_group $new_owner)
+
+			log=$(logname $acl_target $user \
+				$old_owner $new_owner)
+
+			$log operate_node_owner $user $node \
+				$old_owner $new_owner
+
+			$log operate_node_group $user $node \
+				$old_group $new_group
+		done
+	fi
+	if [[ $flag == "group@" || $flag == "everyone@" ]]; then
+		for new_owner in $g_usr "nobody"; do
+			new_group=$(get_user_group $new_owner)
+
+			log=$(logname $acl_target $g_usr $old_owner \
+				$new_owner)
+
+			$log operate_node_owner $g_usr $node \
+				$old_owner $new_owner
+
+			$log operate_node_group $g_usr \
+				$node $old_group $new_group
+		done
+	fi
+	if [[ $flag == "everyone@" ]]; then
+		for new_owner in $g_usr "nobody"; do
+			new_group=$(get_user_group $new_owner)
+
+			log=$(logname $acl_target $o_usr $old_owner \
+				$new_owner)
+
+			$log operate_node_owner $o_usr $node \
+				$old_owner $new_owner
+
+			$log operate_node_group $o_usr $node \
+				$old_group $new_group
+		done
+	fi
+}
+
+function test_chmod_basic_access
+{
+	typeset user=$1
+	typeset node=${2%/}
+	typeset g_usr=$3
+	typeset o_usr=$4
+	typeset flag acl_t
+
+	for flag in $a_flag; do
+		for acl_t in $a_access; do
+			log_must $SU $user -c "$CHMOD A+$flag:$acl_t $node"
+
+			$TAR cpf $TESTDIR/$ARCHIVEFILE basedir
+
+			check_chmod_results $user $node $flag $acl_t $g_usr \
+			    $o_usr
+
+			log_must $SU $user -c "$CHMOD A0- $node"
+		done
+	done
+}
+
+function setup_test_files
+{
+	typeset base_node=$1
+	typeset user=$2
+	typeset group=$3
+
+	$RM -rf $base_node
+
+	log_must $MKDIR -p $base_node
+	log_must $CHOWN $user:$group $base_node
+
+	# Prepare all files/sub-dirs for testing.
+	log_must $SU $user -c "$TOUCH $file"
+	log_must $SU $user -c "$CHMOD 444 $file"
+	log_must $SU $user -c "$MKDIR -p $dir"
+	log_must $SU $user -c "$CHMOD 444 $dir"
+	log_must $SU $user -c "$CHMOD 555 $base_node"
+}
+
+typeset ARCHIVEFILE=archive.tar
+typeset a_access="write_owner:allow write_owner:deny"
+typeset a_flag="owner@ group@ everyone@"
+typeset basedir="$TESTDIR/basedir"
+typeset file="$basedir/file"
+typeset dir="$basedir/dir"
+
+cd $TESTDIR
+setup_test_files $basedir 'root' 'root'
+test_chmod_basic_access 'root' $file $ZFS_ACL_ADMIN  $ZFS_ACL_OTHER1
+test_chmod_basic_access 'root' $dir $ZFS_ACL_ADMIN  $ZFS_ACL_OTHER1
+$RM -rf $basedir
+
+setup_test_files $basedir $ZFS_ACL_STAFF1 $ZFS_ACL_STAFF_GROUP
+test_chmod_basic_access $ZFS_ACL_STAFF1 $file $ZFS_ACL_STAFF2 $ZFS_ACL_OTHER1
+test_chmod_basic_access $ZFS_ACL_STAFF1 $dir $ZFS_ACL_STAFF2 $ZFS_ACL_OTHER1
+$RM -rf $basedir
+
+log_pass "Verify that the chown/chgrp could take owner/group " \
+    "while permission is granted."
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/usr/src/test/zfs-tests/tests/functional/acl/nontrivial/zfs_acl_chmod_rwacl_001_pos.ksh	Wed Dec 05 22:04:50 2012 -0500
@@ -0,0 +1,242 @@
+#!/bin/ksh -p
+#
+# CDDL HEADER START
+#
+# The contents of this file are subject to the terms of the
+# Common Development and Distribution License (the "License").
+# You may not use this file except in compliance with the License.
+#
+# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
+# or http://www.opensolaris.org/os/licensing.
+# See the License for the specific language governing permissions
+# and limitations under the License.
+#
+# When distributing Covered Code, include this CDDL HEADER in each
+# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
+# If applicable, add the following below this CDDL 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.
+#
+
+. $STF_SUITE/tests/functional/acl/acl_common.kshlib
+
+#
+# DESCRIPTION:
+#	Verify assigned read_acl/write_acl to owner@/group@/everyone@,
+#	specificied user and group. File have the correct access permission.
+#
+# STRATEGY:
+#	1. Separatedly verify file and directory was assigned read_acl/write_acl
+#	   by root and non-root user.
+#	2. Verify owner always can read and write acl, even deny.
+#	3. Verify group access permission, when group was assigned
+#	   read_acl/write_acl.
+#	4. Verify access permission, after everyone was assigned read_acl/write.
+#	5. Verify everyone@ was deny except specificied user, this user can read
+#	   and write acl.
+#	6. Verify the group was deny except specified user, this user can read
+#	   and write acl
+#
+
+verify_runnable "both"
+
+log_assert "Verify chmod A[number]{+|-|=} read_acl/write_acl have correct " \
+	"behaviour to access permission."
+log_onexit cleanup
+
+function read_ACL #<node> <user1> <user2> ...
+{
+	typeset node=$1
+	typeset user
+	typeset -i ret
+
+	shift
+	for user in $@; do
+		chgusr_exec $user $LS -vd $node > /dev/null 2>&1
+		ret=$?
+		(( ret != 0 )) && return $ret
+
+		shift
+	done
+
+	return 0
+}
+
+function write_ACL #<node> <user1> <user2> ...
+{
+	typeset node=$1
+	typeset user
+	typeset -i ret before_cnt after_cnt
+
+	shift
+	for user in "$@"; do
+		before_cnt=$(count_ACE $node)
+		ret=$?;
+		(( ret != 0 )) && return $ret
+
+		chgusr_exec $user $CHMOD A0+owner@:read_data:allow $node
+		ret=$?
+		(( ret != 0 )) && return $ret
+
+		after_cnt=$(count_ACE $node)
+		ret=$?
+		(( ret != 0 )) && return $ret
+
+		chgusr_exec $user $CHMOD A0- $node
+		ret=$?
+		(( ret != 0 )) && return $ret
+
+		if (( after_cnt - before_cnt != 1 )); then
+			return 1
+		fi
+
+		shift
+	done
+
+	return 0
+}
+
+function check_owner #<node>
+{
+	typeset node=$1
+
+	for acc in allow deny; do
+		log_must usr_exec \
+			$CHMOD A0+owner@:read_acl/write_acl:$acc $node
+		log_must read_ACL $node $ZFS_ACL_CUR_USER
+		log_must write_ACL $node $ZFS_ACL_CUR_USER
+		log_must usr_exec $CHMOD A0- $node
+	done
+}
+
+function check_group #<node>
+{
+	typeset node=$1
+
+	typeset grp_usr=""
+	if [[ $ZFS_ACL_CUR_USER == root ]]; then
+		grp_usr=$ZFS_ACL_ADMIN
+	elif [[ $ZFS_ACL_CUR_USER == $ZFS_ACL_STAFF1 ]]; then
+		grp_usr=$ZFS_ACL_STAFF2
+	fi
+
+	log_must usr_exec $CHMOD A0+group@:read_acl/write_acl:allow $node
+	log_must read_ACL $node $grp_usr
+	log_must write_ACL $node $grp_usr
+	log_must usr_exec $CHMOD A0- $node
+
+	log_must usr_exec $CHMOD A0+group@:read_acl/write_acl:deny $node
+	log_mustnot read_ACL $node $grp_usr
+	log_mustnot write_ACL $node $grp_usr
+	log_must usr_exec $CHMOD A0- $node
+}
+
+function check_everyone #<node>
+{
+	typeset node=$1
+
+	typeset flag
+	for flag in allow deny; do
+		if [[ $flag == allow ]]; then
+			log=log_must
+		else
+			log=log_mustnot
+		fi
+
+		log_must usr_exec \
+			$CHMOD A0+everyone@:read_acl/write_acl:$flag $node
+
+		$log read_ACL $node $ZFS_ACL_OTHER1 $ZFS_ACL_OTHER2
+		$log write_ACL $node $ZFS_ACL_OTHER1 $ZFS_ACL_OTHER2
+
+		log_must usr_exec $CHMOD A0- $node
+	done
+}
+
+function check_spec_user #<node>
+{
+	typeset node=$1
+
+	log_must usr_exec $CHMOD A0+everyone@:read_acl/write_acl:deny $node
+	log_must usr_exec \
+		$CHMOD A0+user:$ZFS_ACL_OTHER1:read_acl/write_acl:allow $node
+
+	# The specified user can read and write acl
+	log_must read_ACL $node $ZFS_ACL_OTHER1
+	log_must write_ACL $node $ZFS_ACL_OTHER1
+
+	# All the other user can't read and write acl
+	log_mustnot \
+		read_ACL $node $ZFS_ACL_ADMIN $ZFS_ACL_STAFF2 $ZFS_ACL_OTHER2
+	log_mustnot \
+		write_ACL $node $ZFS_ACL_ADMIN $ZFS_ACL_STAFF2 $ZFS_ACL_OTHER2
+
+	log_must usr_exec $CHMOD A0- $node
+	log_must usr_exec $CHMOD A0- $node
+}
+
+function check_spec_group #<node>
+{
+	typeset node=$1
+
+	log_must usr_exec $CHMOD A0+everyone@:read_acl/write_acl:deny $node
+	log_must usr_exec $CHMOD \
+		A0+group:$ZFS_ACL_OTHER_GROUP:read_acl/write_acl:allow $node
+
+	# The specified group can read and write acl
+	log_must read_ACL $node $ZFS_ACL_OTHER1 $ZFS_ACL_OTHER2
+	log_must write_ACL $node $ZFS_ACL_OTHER1 $ZFS_ACL_OTHER2
+
+	# All the other user can't read and write acl
+	log_mustnot read_ACL $node $ZFS_ACL_ADMIN $ZFS_ACL_STAFF2
+	log_mustnot write_ACL $node $ZFS_ACL_ADMIN $ZFS_ACL_STAFF2
+}
+
+function check_user_in_group #<node>
+{
+	typeset node=$1
+
+	log_must usr_exec $CHMOD \
+		A0+group:$ZFS_ACL_OTHER_GROUP:read_acl/write_acl:deny $node
+	log_must usr_exec $CHMOD \
+		A0+user:$ZFS_ACL_OTHER1:read_acl/write_acl:allow $node
+	log_must read_ACL $node $ZFS_ACL_OTHER1
+	log_must write_ACL $node $ZFS_ACL_OTHER1
+	log_mustnot read_ACL $node $ZFS_ACL_OTHER2
+	log_mustnot write_ACL $node $ZFS_ACL_OTHER2
+
+	log_must usr_exec $CHMOD A0- $node
+	log_must usr_exec $CHMOD A0- $node
+}
+
+set -A func_name check_owner \
+		check_group \
+		check_everyone \
+		check_spec_user \
+		check_spec_group \
+		check_user_in_group
+
+for user in root $ZFS_ACL_STAFF1; do
+	log_must set_cur_usr $user
+
+	log_must usr_exec $TOUCH $testfile
+	log_must usr_exec $MKDIR $testdir
+
+	typeset func node
+	for func in ${func_name[@]}; do
+		for node in $testfile $testdir; do
+			eval $func \$node
+		done
+	done
+
+	log_must usr_exec $RM -rf $testfile $testdir
+done
+
+log_pass "Verify chmod A[number]{+|-|=} read_acl/write_acl passed."
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/usr/src/test/zfs-tests/tests/functional/acl/nontrivial/zfs_acl_chmod_rwx_001_pos.ksh	Wed Dec 05 22:04:50 2012 -0500
@@ -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) 2012 by Delphix. All rights reserved.
+#
+
+. $STF_SUITE/tests/functional/acl/acl_common.kshlib
+
+#
+# DESCRIPTION:
+#	chmod A{+|-|=} have the correct behaviour to the ACL list.
+#
+# STRATEGY:
+#	1. loop check root and non-root users
+#	2. chmod file or dir with specified options
+#	3. get ACE after behaviours of chmod
+#	4. compare specified ACE and expect ACE
+#
+
+verify_runnable "both"
+
+log_assert "chmod A{+|-|=} have the correct behaviour to the ACL list."
+log_onexit cleanup
+
+typeset -i trival_count=3 head=0 mid end
+((mid = RANDOM % $trival_count))
+((end = trival_count - 1))
+
+opts="+ - ="
+nums="$head $mid $end"
+set -A file_ACEs \
+    "user:$ZFS_ACL_STAFF1:read_data:allow" \
+    "user:$ZFS_ACL_STAFF2:write_data:allow" \
+    "user:$ZFS_ACL_OTHER1:execute:allow"
+set -A dir_ACEs \
+    "user:$ZFS_ACL_STAFF1:list_directory/read_data:allow" \
+    "user:$ZFS_ACL_STAFF2:add_file/write_data:allow" \
+    "user:$ZFS_ACL_OTHER1:execute:allow"
+
+function test_chmod_ACE_list #$opt $num $ace-spec $node
+{
+	typeset opt=A$2$1
+	typeset -i num=$2
+	typeset ace=$3
+	typeset node=$4
+	typeset -i expect_count=0
+
+	# Get expect ACE count
+	case $opt in
+		A[0-9]*+) (( expect_count = trival_count + 1 )) ;;
+		A[0-9]*-) (( expect_count = trival_count - 1 )) ;;
+		A[0-9]*=) (( expect_count = trival_count )) ;;
+		*) log_fail "Error option: '$opt'" ;;
+	esac
+
+	# Invoke chmod A[number]{+|-|=}<acl-specification> file|dir
+	if [[ $opt == A[0-9]*+ || $opt == A[0-9]*= ]]; then
+		log_must usr_exec $CHMOD "$opt$ace" "$node"
+	else
+		log_must usr_exec $CHMOD "$opt" "$node"
+	fi
+
+	# Get the current ACE count and specified ACE
+	typeset cur_ace cur_count
+	cur_ace=$(get_ACE $node $num)
+	cur_count=$(count_ACE $node)
+
+	# Compare with expected results
+	if [[ $opt == A[0-9]*+ || $opt == A[0-9]*= ]]; then
+		if [[ "$num:$ace" != "$cur_ace" ]]; then
+			log_fail "FAIL: $CHMOD $opt$ace $node"
+		fi
+	fi
+	if [[ "$expect_count" != "$cur_count" ]]; then
+		log_fail "FAIL: '$expect_count' != '$cur_count'"
+	fi
+}
+
+for user in root $ZFS_ACL_STAFF1 $ZFS_ACL_OTHER1; do
+	log_must set_cur_usr $user
+
+	for opt in $opts; do
+		for num in $nums; do
+			for ace in $file_ACEs; do
+				ls -l $TESTDIR
+				log_must usr_exec $TOUCH $testfile
+				test_chmod_ACE_list $opt $num $ace $testfile
+				log_must $RM -f $testfile
+			done
+			for ace in $dir_ACEs; do
+				ls -l $TESTDIR
+				log_must usr_exec $MKDIR -p $testdir
+				test_chmod_ACE_list $opt $num $ace $testdir
+				log_must $RM -rf $testdir
+			done
+		done
+	done
+done
+
+log_pass "chmod A{+|-|=} behave to the ACL list passed."
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/usr/src/test/zfs-tests/tests/functional/acl/nontrivial/zfs_acl_chmod_rwx_002_pos.ksh	Wed Dec 05 22:04:50 2012 -0500
@@ -0,0 +1,241 @@
+#!/bin/ksh -p
+#
+# CDDL HEADER START
+#
+# The contents of this file are subject to the terms of the
+# Common Development and Distribution License (the "License").
+# You may not use this file except in compliance with the License.
+#
+# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
+# or http://www.opensolaris.org/os/licensing.
+# See the License for the specific language governing permissions
+# and limitations under the License.
+#
+# When distributing Covered Code, include this CDDL HEADER in each
+# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
+# If applicable, add the following below this CDDL 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.
+#
+
+. $STF_SUITE/tests/functional/acl/acl_common.kshlib
+
+#
+# DESCRIPTION:
+#	chmod A{+|-|=} read_data|write_data|execute for owner@ group@ or
+#	everyone@ correctly alters mode bits .
+#
+# STRATEGY:
+#	1. Loop root and non-root user.
+#	2. Get the random initial map.
+#	3. Get the random ACL string.
+#	4. Separately chmod +|-|= read_data|write_data|execute
+#	5. Check map bits
+#
+
+verify_runnable "both"
+
+log_assert "chmod A{+|-|=} read_data|write_data|execute for owner@, group@ " \
+	"or everyone@ correctly alters mode bits."
+log_onexit cleanup
+
+set -A bits 0 1 2 3 4 5 6 7
+set -A a_flag owner group everyone
+set -A a_access read_data write_data execute
+set -A a_type allow deny
+
+#
+# Get a random item from an array.
+#
+# $1 the base set
+#
+function random_select #array_name
+{
+	typeset arr_name=$1
+	typeset -i ind
+
+	eval typeset -i cnt=\${#${arr_name}[@]}
+	(( ind = $RANDOM % cnt ))
+
+	eval print \${${arr_name}[$ind]}
+}
+
+#
+# Create a random string according to array name, the item number and
+# separated tag.
+#
+# $1 array name where the function get the elements
+# $2 the items number which you want to form the random string
+# $3 the separated tag
+#
+function form_random_str #<array_name> <count> <sep>
+{
+	typeset arr_name=$1
+	typeset -i count=${2:-1}
+	typeset sep=${3:-""}
+
+	typeset str=""
+	while (( count > 0 )); do
+		str="${str}$(random_select $arr_name)${sep}"
+
+		(( count -= 1 ))
+	done
+
+	print $str
+}
+
+#
+# According to the original bits, the input ACE access and ACE type, return the
+# expect bits after 'chmod A0{+|=}'.
+#
+# $1 bits which was make up of three bit 'rwx'
+# $2 ACE access which is read_data, write_data or execute
+# $3 ACE type which is allow or deny
+#
+function cal_bits #bits acl_access acl_type
+{
+	typeset bits=$1
+	typeset acl_access=$2
+	typeset acl_type=$3
+	set -A bit r w x
+
+	typeset tmpbits=""
+	typeset -i i=0 j
+	while (( i < 3 )); do
+		if [[ $acl_access == *"${a_access[i]}"* ]]; then
+			if [[ $acl_type == "allow" ]]; then
+				tmpbits="$tmpbits${bit[i]}"
+			elif [[ $acl_type == "deny" ]]; then
+				tmpbits="${tmpbits}-"
+			fi
+		else
+			(( j = i + 1 ))
+			tmpbits="$tmpbits$(get_substr $bits $j 1)"
+		fi
+
+		(( i += 1 ))
+	done
+
+	echo "$tmpbits"
+}
+
+#
+# Based on the initial node map before chmod and the ace-spec, check if chmod
+# has the correct behaven to map bits.
+#
+function check_test_result #init_mode node acl_flag acl_access a_type
+{
+	typeset init_mode=$1
+	typeset node=$2
+	typeset acl_flag=$3
+	typeset acl_access=$4
+	typeset acl_type=$5
+
+	typeset -3L u_bits=$init_mode
+	typeset g_bits=$(get_substr $init_mode 4 3)
+	typeset -3R o_bits=$init_mode
+
+	if [[ $acl_flag == "owner" || $acl_flag == "everyone" ]]; then
+		u_bits=$(cal_bits $u_bits $acl_access $acl_type)
+	fi
+	if [[ $acl_flag == "group" || $acl_flag == "everyone" ]]; then
+		g_bits=$(cal_bits $g_bits $acl_access $acl_type)
+	fi
+	if [[ $acl_flag == "everyone" ]]; then
+		o_bits=$(cal_bits $o_bits $acl_access $acl_type)
+	fi
+
+	typeset cur_mode=$(get_mode $node)
+	cur_mode=$(get_substr $cur_mode 2 9)
+
+	if [[ $cur_mode == $u_bits$g_bits$o_bits ]]; then
+		log_note "SUCCESS: Current map($cur_mode) ==" \
+			"expected map($u_bits$g_bits$o_bits)"
+	else
+		log_fail "FAIL: Current map($cur_mode) != " \
+			"expected map($u_bits$g_bits$o_bits)"
+	fi
+}
+
+function test_chmod_map #<node>
+{
+	typeset node=$1
+	typeset init_mask acl_flag acl_access acl_type
+	typeset -i cnt
+
+	if (( ${#node} == 0 )); then
+		log_fail "FAIL: file name or directroy name is not defined."
+	fi
+
+	# Get the initial map
+	init_mask=$(form_random_str bits 3)
+	# Get ACL flag, access & type
+	acl_flag=$(form_random_str a_flag)
+	(( cnt = ($RANDOM % ${#a_access[@]}) + 1 ))
+	acl_access=$(form_random_str a_access $cnt '/')
+	acl_access=${acl_access%/}
+	acl_type=$(form_random_str a_type)
+
+	typeset acl_spec=${acl_flag}@:${acl_access}:${acl_type}
+
+	# Set the initial map and back the initial ACEs
+	typeset orig_ace=/tmp/orig_ace.$$
+	typeset cur_ace=/tmp/cur_ace.$$
+
+	for operator in "A0+" "A0="; do
+		log_must usr_exec $CHMOD $init_mask $node
+		init_mode=$(get_mode $node)
+		init_mode=$(get_substr $init_mode 2 9)
+		log_must usr_exec eval "$LS -vd $node > $orig_ace"
+
+		# To "A=", firstly add one ACE which can't modify map
+		if [[ $operator == "A0=" ]]; then
+			log_must $CHMOD A0+user:$ZFS_ACL_OTHER1:execute:deny \
+				$node
+		fi
+		log_must usr_exec $CHMOD $operator$acl_spec $node
+		check_test_result \
+			$init_mode $node $acl_flag $acl_access $acl_type
+
+		# Check "chmod A-"
+		log_must usr_exec $CHMOD A0- $node
+		log_must usr_exec eval "$LS -vd $node > $cur_ace"
+
+		if $DIFF $orig_ace $cur_ace; then
+			log_note "SUCCESS: original ACEs equivalence the " \
+				"current ACEs. 'chmod A-' succeeded."
+		else
+			log_fail "FAIL: 'chmod A-' failed."
+		fi
+	done
+
+	[[ -f $orig_ace ]] && log_must usr_exec $RM -f $orig_ace
+	[[ -f $cur_ace ]] && log_must usr_exec $RM -f $cur_ace
+}
+
+for user in root $ZFS_ACL_STAFF1; do
+	set_cur_usr $user
+
+	typeset -i loop_cnt=20
+	while (( loop_cnt > 0 )); do
+		log_must usr_exec $TOUCH $testfile
+		test_chmod_map $testfile
+		log_must $RM -f $testfile
+
+		log_must usr_exec $MKDIR $testdir
+		test_chmod_map $testdir
+		log_must $RM -rf $testdir
+
+		(( loop_cnt -= 1 ))
+	done
+done
+
+log_pass "chmod A{+|-|=} read_data|write_data|execute for owner@, group@ " \
+	"oreveryone@ correctly alters mode bits passed."
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/usr/src/test/zfs-tests/tests/functional/acl/nontrivial/zfs_acl_chmod_rwx_003_pos.ksh	Wed Dec 05 22:04:50 2012 -0500
@@ -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.
+#
+
+. $STF_SUITE/tests/functional/acl/acl_common.kshlib
+
+#
+# DESCRIPTION:
+#	Verify that the read_data/write_data/execute permission for
+#	owner/group/everyone are correct.
+#
+# STRATEGY:
+#	1. Loop root and non-root user.
+#	2. Separated verify type@:access:allow|deny to file and directory
+#	3. To super user, read and write deny was override.
+#	4. According to ACE list and override rule, expect that
+#	   read/write/execute file or directory succeed or fail.
+#
+
+verify_runnable "both"
+
+#	owner@			group_users		other_users
+set -A users \
+	"root"			"$ZFS_ACL_ADMIN"	"$ZFS_ACL_OTHER1" \
+	"$ZFS_ACL_STAFF1"	"$ZFS_ACL_STAFF2"	"$ZFS_ACL_OTHER1"
+
+# In order to test execute permission, read_data was need firstly.
+set -A a_access "read_data" "write_data" "read_data/execute"
+set -A a_flag "owner@" "group@" "everyone@"
+
+log_assert "Verify that the read_data/write_data/execute permission for" \
+	"owner/group/everyone are correct."
+log_onexit cleanup
+
+function logname #node acl_spec user
+{
+	typeset node=$1
+	typeset acl_spec=$2
+	typeset user=$3
+
+	# To super user, read and write deny permission was override.
+	if [[ $acl_spec == *:allow ]] || \
+		[[ $user == root && -d $node ]] || \
+		[[ $user == root && $acl_spec != *"execute"* ]]
+	then
+		print "log_must"
+	elif [[ $acl_spec == *:deny ]]; then
+		print "log_mustnot"
+	fi
+}
+
+function check_chmod_results #node acl_spec g_usr o_usr
+{
+	typeset node=$1
+	typeset acl_spec=$2
+	typeset g_usr=$3
+	typeset o_usr=$4
+	typeset log
+
+	if [[ $acl_spec == "owner@:"* || $acl_spec == "everyone@:"* ]]; then
+		log=$(logname $node $acl_spec $ZFS_ACL_CUR_USER)
+		$log rwx_node $ZFS_ACL_CUR_USER $node $acl_spec
+	fi
+	if [[ $acl_spec == "group@:"* || $acl_spec == "everyone@:"* ]]; then
+		log=$(logname $node $acl_spec $g_usr)
+		$log rwx_node $g_usr $node $acl_spec
+	fi
+	if [[ $acl_spec == "everyone@"* ]]; then
+		log=$(logname $node $acl_spec $o_usr)
+		$log rwx_node $o_usr $node $acl_spec
+	fi
+}
+
+function test_chmod_basic_access #node group_user other_user
+{
+	typeset node=$1
+	typeset g_usr=$2
+	typeset o_usr=$3
+	typeset flag access acl_spec
+
+	for flag in ${a_flag[@]}; do
+		for access in ${a_access[@]}; do
+			for tp in allow deny; do
+				acl_spec="$flag:$access:$tp"
+				log_must usr_exec $CHMOD A+$acl_spec $node
+				check_chmod_results \
+					$node $acl_spec $g_usr $o_usr
+				log_must usr_exec $CHMOD A0- $node
+			done
+		done
+	done
+}
+
+typeset -i i=0
+while (( i < ${#users[@]} )); do
+	log_must set_cur_usr ${users[i]}
+
+	log_must usr_exec $TOUCH $testfile
+	test_chmod_basic_access $testfile ${users[((i+1))]} ${users[((i+2))]}
+	log_must usr_exec $MKDIR $testdir
+	test_chmod_basic_access $testdir ${users[((i+1))]} ${users[((i+2))]}
+
+	log_must usr_exec $RM -rf $testfile $testdir
+
+	(( i += 3 ))
+done
+
+log_pass "Verify that the read_data/write_data/execute permission for" \
+	"owner/group/everyone passed."
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/usr/src/test/zfs-tests/tests/functional/acl/nontrivial/zfs_acl_chmod_rwx_004_pos.ksh	Wed Dec 05 22:04:50 2012 -0500
@@ -0,0 +1,138 @@
+#!/bin/ksh -p
+#
+# CDDL HEADER START
+#
+# The contents of this file are subject to the terms of the
+# Common Development and Distribution License (the "License").
+# You may not use this file except in compliance with the License.
+#
+# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
+# or http://www.opensolaris.org/os/licensing.
+# See the License for the specific language governing permissions
+# and limitations under the License.
+#
+# When distributing Covered Code, include this CDDL HEADER in each
+# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
+# If applicable, add the following below this CDDL HEADER, with the
+# fields enclosed by brackets "[]" replaced with your own identifying
+# information: Portions Copyright [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.
+#
+
+. $STF_SUITE/tests/functional/acl/acl_common.kshlib
+
+#
+# DESCRIPTION:
+#	Verify that explicit ACL setting to specified user or group will
+#	override existed access rule.
+#
+# STRATEGY:
+#	1. Loop root and non-root user.
+#	2. Loop the specified access one by one.
+#	3. Loop verify explicit ACL set to specified user and group.
+#
+
+verify_runnable "both"
+
+function check_access #log user node access rflag
+{
+	typeset log=$1
+	typeset user=$2
+	typeset node=$3
+	typeset access=$4
+	typeset rflag=$5
+
+	if [[ $rflag == "allow" && $access == execute ]]; then
+		rwx_node $user $node $access
+		#
+		# When everyone@ were deny, this file can't execute.
+		# So,'cannot execute' means user has the permission to
+		# execute, just the file can't be execute.
+		#
+		if [[ $ZFS_ACL_ERR_STR == *"cannot execute"* ]]; then
+			log_note "SUCCESS: rwx_node $user $node $access"
+		else
+			log_fail "FAIL: rwx_node $user $node $access"
+		fi
+	else
+		$log rwx_node $user $node $access
+	fi
+}
+
+function verify_explicit_ACL_rule #node access flag
+{
+	typeset node=$1
+	typeset access=$2
+	typeset flag=$3
+	typeset log rlog rflag
+
+	# Get the expect log check
+	if [[ $flag == allow ]]; then
+		log=log_mustnot
+		rlog=log_must
+		rflag=deny
+	else
+		log=log_must
+		rlog=log_mustnot
+		rflag=allow
+	fi
+
+	log_must usr_exec $CHMOD A+everyone@:$access:$flag $node
+	log_must usr_exec $CHMOD A+user:$ZFS_ACL_OTHER1:$access:$rflag $node
+	check_access $log $ZFS_ACL_OTHER1 $node $access $rflag
+	log_must usr_exec $CHMOD A0- $node
+
+	log_must usr_exec \
+		$CHMOD A+group:$ZFS_ACL_OTHER_GROUP:$access:$rflag $node
+	check_access $log $ZFS_ACL_OTHER1 $node $access $rflag
+	check_access $log $ZFS_ACL_OTHER2 $node $access $rflag
+	log_must usr_exec $CHMOD A0- $node
+	log_must usr_exec $CHMOD A0- $node
+
+	log_must usr_exec \
+		$CHMOD A+group:$ZFS_ACL_OTHER_GROUP:$access:$flag $node
+	log_must usr_exec $CHMOD A+user:$ZFS_ACL_OTHER1:$access:$rflag $node
+	$log rwx_node $ZFS_ACL_OTHER1 $node $access
+	$rlog rwx_node $ZFS_ACL_OTHER2 $node $access
+	log_must usr_exec $CHMOD A0- $node
+	log_must usr_exec $CHMOD A0- $node
+}
+
+log_assert "Verify that explicit ACL setting to specified user or group will" \
+	"override existed access rule."
+log_onexit cleanup
+
+set -A a_access "read_data" "write_data" "execute"
+set -A a_flag "allow" "deny"
+typeset node
+
+for user in root $ZFS_ACL_STAFF1; do
+	log_must set_cur_usr $user
+
+	log_must usr_exec $TOUCH $testfile
+	log_must usr_exec $MKDIR $testdir
+	log_must usr_exec $CHMOD 755 $testfile $testdir
+
+	for node in $testfile $testdir; do
+		for access in ${a_access[@]}; do
+			for flag in ${a_flag[@]}; do
+				verify_explicit_ACL_rule $node $access $flag
+			done
+		done
+	done
+
+	log_must usr_exec $RM -rf $testfile $testdir
+done
+
+log_pass "Explicit ACL setting to specified user or group will override " \
+	"existed access rule passed."
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/usr/src/test/zfs-tests/tests/functional/acl/nontrivial/zfs_acl_chmod_xattr_001_pos.ksh	Wed Dec 05 22:04:50 2012 -0500
@@ -0,0 +1,238 @@
+#!/bin/ksh -p
+#
+# CDDL HEADER START
+#
+# The contents of this file are subject to the terms of the
+# Common Development and Distribution License (the "License").
+# You may not use this file except in compliance with the License.
+#
+# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
+# or http://www.opensolaris.org/os/licensing.
+# See the License for the specific language governing permissions
+# and limitations under the License.
+#
+# When distributing Covered Code, include this CDDL HEADER in each
+# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
+# If applicable, add the following below this CDDL 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.
+#
+
+. $STF_SUITE/tests/functional/acl/acl_common.kshlib
+
+#
+# DESCRIPTION:
+#	Verify that the read_xattr/write_xattr for
+#	owner/group/everyone are correct.
+#
+# STRATEGY:
+# 1. Create file and  directory in zfs filesystem
+# 2. Set special read_xattr ACE to the file and directory
+# 3. Try to list the extended attributes of the file and directory
+# 4. Set special write_xattr ACE to the file and directory
+# 5. Try to add new extended attributes to the file and directory
+# 6. Verify above operation is successful.
+#
+
+verify_runnable "both"
+
+function cleanup
+{
+	cd $cwd
+
+	cleanup_test_files $TESTDIR/basedir
+
+	if [[ -e $TESTDIR/$ARCHIVEFILE ]]; then
+		log_must $RM -f $TESTDIR/$ARCHIVEFILE
+	fi
+
+	return 0
+}
+
+#   owner@	group	group_users		other_users
+set -A users \
+    "root"	"root"	"$ZFS_ACL_ADMIN"	"$ZFS_ACL_OTHER1" \
+    "$ZFS_ACL_STAFF1"	"$ZFS_ACL_STAFF_GROUP"	"$ZFS_ACL_STAFF2" \
+    "$ZFS_ACL_OTHER1"
+
+set -A a_access \
+	"read_xattr:allow" \
+	"read_xattr:deny" \
+	"write_xattr:allow" \
+	"write_xattr:deny"
+
+set -A a_flag "owner@" "group@" "everyone@"
+
+MYTESTFILE=/etc/passwd
+
+log_assert "Verify that the permission of read_xattr/write_xattr for " \
+	"owner/group/everyone are correct."
+log_onexit cleanup
+
+function operate_node #user node acl
+{
+	typeset user=$1
+	typeset node=$2
+	typeset acl_t=$3
+	typeset ret
+
+	if [[ $user == "" || $node == "" ]]; then
+		log_fail "user, node are not defined."
+	fi
+
+	if [[ $acl_t == *read_xattr* ]]; then
+		chgusr_exec $user $RUNAT $node $LS > /dev/null 2>&1; ret=$?
+	elif [[ $acl_t == *write_xattr* ]]; then
+		chgusr_exec $user $RUNAT $node $CP $MYTESTFILE attr.1 ; ret=$?
+
+		if [[ $ret -eq 0 ]]; then
+			log_must cleanup_test_files $TESTDIR/basedir
+			log_must $TAR xpf@ $TESTDIR/$ARCHIVEFILE
+		fi
+	fi
+
+	return $ret
+}
+
+function logname #acl_target user
+{
+	typeset acl_target=$1
+	typeset user=$2
+	typeset ret="log_mustnot"
+
+	# To super user, read and write deny permission was override.
+	if [[ $user == root || $acl_target == *:allow ]] then
+		ret="log_must"
+	fi
+
+	print $ret
+}
+
+function check_chmod_results #node flag acl_target g_usr o_usr
+{
+	typeset node=$1
+	typeset flag=$2
+	typeset acl_target=$2:$3
+	typeset g_usr=$4
+	typeset o_usr=$5
+	typeset log
+
+	if [[ $flag == "owner@" || $flag == "everyone@" ]]; then
+		log=$(logname $acl_target $ZFS_ACL_CUR_USER)
+		$log operate_node $ZFS_ACL_CUR_USER $node $acl_target
+	fi
+	if [[ $flag == "group@" || $flag == "everyone@" ]]; then
+		log=$(logname $acl_target $g_usr)
+		$log operate_node $g_usr $node $acl_target
+	fi
+	if [[ $flag == "everyone@" ]]; then
+		log=$(logname $acl_target $o_usr)
+		$log operate_node $o_usr $node $acl_target
+	fi
+}
+
+function test_chmod_basic_access #node g_usr o_usr
+{
+	typeset node=${1%/}
+	typeset g_usr=$2
+	typeset o_usr=$3
+	typeset flag acl_p acl_t parent
+
+	parent=${node%/*}
+
+	for flag in ${a_flag[@]}; do
+		for acl_t in "${a_access[@]}"; do
+			log_must usr_exec $CHMOD A+$flag:$acl_t $node
+
+			log_must $TAR cpf@ $TESTDIR/$ARCHIVEFILE basedir
+
+			check_chmod_results "$node" "$flag" \
+				"$acl_t" "$g_usr" "$o_usr"
+
+			log_must usr_exec $CHMOD A0- $node
+		done
+	done
+}
+
+function setup_test_files #base_node user group
+{
+	typeset base_node=$1
+	typeset user=$2
+	typeset group=$3
+
+	cleanup_test_files $base_node
+
+	log_must $MKDIR -p $base_node
+	log_must $CHOWN $user:$group $base_node
+
+	log_must set_cur_usr $user
+
+	# Prepare all files/sub-dirs for testing.
+
+	file0=$base_node/testfile_rm
+
+	dir0=$base_node/testdir_rm
+
+	log_must usr_exec $TOUCH $file0
+	log_must usr_exec $CHMOD 444 $file0
+
+	log_must usr_exec $RUNAT $file0 $CP $MYTESTFILE attr.0
+
+	log_must usr_exec $MKDIR -p $dir0
+	log_must usr_exec $CHMOD 555 $dir0
+
+	log_must usr_exec $RUNAT $dir0 $CP $MYTESTFILE attr.0
+
+	log_must usr_exec $CHMOD 777 $base_node
+	return 0
+}
+
+function cleanup_test_files #base_node
+{
+	typeset base_node=$1
+
+	if [[ -d $base_node ]]; then
+		log_must $RM -rf $base_node
+	elif [[ -e $base_node ]]; then
+		log_must $RM -f $base_node
+	fi
+
+	return 0
+}
+
+typeset cwd=$PWD
+typeset ARCHIVEFILE=archive.tar
+
+typeset -i i=0
+typeset -i j=0
+typeset target
+
+while (( i < ${#users[@]} )); do
+	setup_test_files $TESTDIR/basedir ${users[i]} ${users[((i+1))]}
+	cd $TESTDIR
+
+	j=0
+	while (( j < 1 )); do
+		eval target=\$file$j
+		test_chmod_basic_access $target \
+			"${users[((i+2))]}" "${users[((i+3))]}"
+
+		eval target=\$dir$j
+		test_chmod_basic_access $target \
+			"${users[((i+2))]}" "${users[((i+3))]}"
+
+		(( j = j + 1 ))
+	done
+
+	(( i += 4 ))
+done
+
+log_pass "Verify that the permission of read_xattr/write_xattr for " \
+	"owner/group/everyone are correct."
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/usr/src/test/zfs-tests/tests/functional/acl/nontrivial/zfs_acl_chmod_xattr_002_pos.ksh	Wed Dec 05 22:04:50 2012 -0500
@@ -0,0 +1,233 @@
+#!/bin/ksh -p
+#
+# CDDL HEADER START
+#
+# The contents of this file are subject to the terms of the
+# Common Development and Distribution License (the "License").
+# You may not use this file except in compliance with the License.
+#
+# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
+# or http://www.opensolaris.org/os/licensing.
+# See the License for the specific language governing permissions
+# and limitations under the License.
+#
+# When distributing Covered Code, include this CDDL HEADER in each
+# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
+# If applicable, add the following below this CDDL 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.
+#
+
+. $STF_SUITE/tests/functional/acl/acl_common.kshlib
+
+#
+# DESCRIPTION:
+#	Verify that the write_xattr for remove the extended attributes of
+#	owner/group/everyone are correct.
+#
+# STRATEGY:
+# 1. Create file and  directory in zfs filesystem
+# 2. Set special write_xattr ACE to the file and directory
+# 3. Try to remove the extended attributes of the file and directory
+# 4. Verify above operation is successful.
+#
+
+verify_runnable "both"
+
+function cleanup
+{
+	cd $cwd
+
+	cleanup_test_files $TESTDIR/basedir
+
+	if [[ -e $TESTDIR/$ARCHIVEFILE ]]; then
+		log_must $RM -f $TESTDIR/$ARCHIVEFILE
+	fi
+
+	return 0
+}
+
+#	owner@	group	group_users		other_users
+set -A users \
+	"root"	"root"	"$ZFS_ACL_ADMIN"	"$ZFS_ACL_OTHER1" \
+	"$ZFS_ACL_STAFF1"	"$ZFS_ACL_STAFF_GROUP"	"$ZFS_ACL_STAFF2" \
+	"$ZFS_ACL_OTHER1"
+
+set -A a_access \
+	"write_xattr:allow" \
+	"write_xattr:deny"
+
+set -A a_flag "owner@" "group@" "everyone@"
+
+MYTESTFILE=/etc/passwd
+
+log_assert "Verify that the permission of write_xattr for " \
+	"owner/group/everyone while remove extended attributes are correct."
+log_onexit cleanup
+
+function operate_node #user node acl
+{
+	typeset user=$1
+	typeset node=$2
+	typeset acl_t=$3
+	typeset ret
+
+	if [[ $user == "" || $node == "" ]]; then
+		log_fail "user, node are not defined."
+	fi
+
+	chgusr_exec $user $RUNAT $node $RM -f attr.0 ; ret=$?
+
+	if [[ $ret -eq 0 ]]; then
+		log_must cleanup_test_files $TESTDIR/basedir
+		log_must $TAR xpf@ $TESTDIR/$ARCHIVEFILE
+	fi
+
+	return $ret
+}
+
+function logname #acl_target owner user
+{
+	typeset acl_target=$1
+	typeset owner=$2
+	typeset user=$3
+	typeset ret="log_mustnot"
+
+	# To super user, read and write deny permission was override.
+	if [[ $user == root || $owner == $user ]] then
+		ret="log_must"
+	fi
+
+	print $ret
+}
+
+function check_chmod_results #node flag acl_target owner g_usr o_usr
+{
+	typeset node=$1
+	typeset flag=$2
+	typeset acl_target=$2:$3
+	typeset owner=$4
+	typeset g_usr=$5
+	typeset o_usr=$6
+	typeset log
+
+	if [[ $flag == "owner@" || $flag == "everyone@" ]]; then
+		log=$(logname $acl_target $owner $ZFS_ACL_CUR_USER)
+		$log operate_node $ZFS_ACL_CUR_USER $node $acl_target
+	fi
+	if [[ $flag == "group@" || $flag == "everyone@" ]]; then
+		log=$(logname $acl_target $owner $g_usr)
+		$log operate_node $g_usr $node $acl_target
+	fi
+	if [[ $flag == "everyone@" ]]; then
+		log=$(logname $acl_target $owner $o_usr)
+		$log operate_node $o_usr $node $acl_target
+	fi
+}
+
+function test_chmod_basic_access #node owner g_usr o_usr
+{
+	typeset node=${1%/}
+	typeset owner=$2
+	typeset g_usr=$3
+	typeset o_usr=$4
+	typeset flag acl_p acl_t parent
+
+	parent=${node%/*}
+
+	for flag in ${a_flag[@]}; do
+		for acl_t in "${a_access[@]}"; do
+			log_must usr_exec $CHMOD A+$flag:$acl_t $node
+
+			log_must $TAR cpf@ $TESTDIR/$ARCHIVEFILE basedir
+
+			check_chmod_results "$node" "$flag" \
+				"$acl_t" "$owner" "$g_usr" "$o_usr"
+
+			log_must usr_exec $CHMOD A0- $node
+		done
+	done
+}
+
+function setup_test_files #base_node user group
+{
+	typeset base_node=$1
+	typeset user=$2
+	typeset group=$3
+
+	cleanup_test_files $base_node
+
+	log_must $MKDIR -p $base_node
+	log_must $CHOWN $user:$group $base_node
+
+	log_must set_cur_usr $user
+
+	# Prepare all files/sub-dirs for testing.
+
+	file0=$base_node/testfile_rm
+
+	dir0=$base_node/testdir_rm
+
+	log_must usr_exec $TOUCH $file0
+	log_must usr_exec $CHMOD 444 $file0
+
+	log_must usr_exec $RUNAT $file0 $CP $MYTESTFILE attr.0
+
+	log_must usr_exec $MKDIR -p $dir0
+	log_must usr_exec $CHMOD 555 $dir0
+
+	log_must usr_exec $RUNAT $dir0 $CP $MYTESTFILE attr.0
+
+	log_must usr_exec $CHMOD 555 $base_node
+	return 0
+}
+
+function cleanup_test_files #base_node
+{
+	typeset base_node=$1
+
+	if [[ -d $base_node ]]; then
+		log_must $RM -rf $base_node
+	elif [[ -e $base_node ]]; then
+		log_must $RM -f $base_node
+	fi
+
+	return 0
+}
+
+typeset cwd=$PWD
+typeset ARCHIVEFILE=archive.tar
+
+typeset -i i=0
+typeset -i j=0
+typeset target
+
+while (( i < ${#users[@]} )); do
+	setup_test_files $TESTDIR/basedir ${users[i]} ${users[((i+1))]}
+	cd $TESTDIR
+
+	j=0
+	while (( j < 1 )); do
+		eval target=\$file$j
+		test_chmod_basic_access $target ${users[i]} \
+			"${users[((i+2))]}" "${users[((i+3))]}"
+
+		eval target=\$dir$j
+		test_chmod_basic_access $target ${users[i]} \
+			"${users[((i+2))]}" "${users[((i+3))]}"
+
+		(( j = j + 1 ))
+	done
+
+	(( i += 4 ))
+done
+
+log_pass "Verify that the permission of write_xattr for " \
+	"owner/group/everyone while remove extended attributes are correct."
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/usr/src/test/zfs-tests/tests/functional/acl/nontrivial/zfs_acl_cp_001_pos.ksh	Wed Dec 05 22:04:50 2012 -0500
@@ -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 2007 Sun Microsystems, Inc.  All rights reserved.
+# Use is subject to license terms.
+#
+
+. $STF_SUITE/tests/functional/acl/acl_common.kshlib
+
+#
+# DESCRIPTION:
+#	Verify that '/usr/bin/cp [-p]' supports ZFS ACL
+#
+# STRATEGY:
+#	1. Create file and  directory in zfs filesystem
+#	2. Set special ACE to the file and directory
+#	3. Copy the file/directory within and across zfs file system
+#	4. Verify that the ACL of file/directroy is not changed, when you are
+#	   inserting an ACL with a user: or group: entry on the top.
+#	   (abstractions entry are treated special, since they represent the
+#	   traditional permission bit mapping.)
+#
+
+verify_runnable "both"
+
+function cleanup
+{
+	if datasetexists $TESTPOOL/$TESTFS1; then
+		log_must $ZFS destroy -f $TESTPOOL/$TESTFS1
+	fi
+	[[ -d $TESTDIR1 ]] && log_must $RM -rf $TESTDIR1
+	[[ -d $TESTDIR ]] && log_must $RM -rf $TESTDIR/*
+}
+
+log_assert "Verify that '$CP [-p]' supports ZFS ACLs."
+log_onexit cleanup
+
+log_note "Create the second zfs file system: $TESTPOOL/$TESTFS1."
+log_must $ZFS create $TESTPOOL/$TESTFS1
+log_must $ZFS set mountpoint=$TESTDIR1 $TESTPOOL/$TESTFS1
+log_must $ZFS set aclmode=passthrough $TESTPOOL/$TESTFS1
+log_must $CHMOD 777 $TESTDIR1
+
+# Define target directory.
+dstdir=$TESTDIR1/dstdir.$$
+
+for user in root $ZFS_ACL_STAFF1; do
+	# Set the current user
+	log_must set_cur_usr $user
+
+	for obj in $testfile $testdir; do
+		# Create source object and target directroy
+		log_must usr_exec $TOUCH $testfile
+		log_must usr_exec $MKDIR $testdir $dstdir
+
+		# Add the new ACE on the head.
+		log_must usr_exec $CHMOD \
+			A0+user:$ZFS_ACL_OTHER1:read_acl:deny $obj
+
+		cmd_str="$CP -p"
+		[[ -d $obj ]] && cmd_str="$CP -rp"
+		log_must usr_exec $cmd_str $obj $dstdir
+		log_must usr_exec $cmd_str $obj $TESTDIR1
+
+		for dir in $dstdir $TESTDIR1; do
+			log_must compare_modes $obj $dir/${obj##*/}
+			log_must compare_acls $obj $dir/${obj##*/}
+		done
+
+		# Delete all the test file and directory
+		log_must usr_exec $RM -rf $TESTDIR/* $TESTDIR1/*
+	done
+done
+
+log_pass "'$CP [-p]' succeeds to support ZFS ACLs."
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/usr/src/test/zfs-tests/tests/functional/acl/nontrivial/zfs_acl_cp_002_pos.ksh	Wed Dec 05 22:04:50 2012 -0500
@@ -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.
+#
+
+. $STF_SUITE/tests/functional/acl/acl_common.kshlib
+
+#
+# DESCRIPTION:
+#	Verify that '/usr/bin/cp [-p@]' supports ZFS ACL & xattrs
+#
+# STRATEGY:
+#	1. Create file and  directory in zfs filesystem
+#	2. Set special ACE to the file and directory
+#	3. Create xattr of the file and directory
+#	4. Copy the file/directory within and across zfs file system
+#	5. Verify that the ACL & xattrs of the file/directroy is not changed,
+#	   when you are inserting an ACL with user: or group: entry on the top.
+#	   (abstractions entry are treated special, since they represent the
+#	   traditional permission bit mapping.)
+#
+
+verify_runnable "both"
+
+function cleanup
+{
+	if datasetexists $TESTPOOL/$TESTFS1; then
+		log_must $ZFS destroy -f $TESTPOOL/$TESTFS1
+	fi
+	[[ -d $TESTDIR1 ]] && log_must $RM -rf $TESTDIR1
+	[[ -d $TESTDIR ]] && log_must $RM -rf $TESTDIR/*
+}
+
+log_assert "Verify that '$CP [-p]' supports ZFS ACLs."
+log_onexit cleanup
+
+log_note "Create the second zfs file system: $TESTPOOL/$TESTFS1."
+log_must $ZFS create $TESTPOOL/$TESTFS1
+log_must $ZFS set mountpoint=$TESTDIR1 $TESTPOOL/$TESTFS1
+log_must $ZFS set aclmode=passthrough $TESTPOOL/$TESTFS1
+log_must $CHMOD 777 $TESTDIR1
+
+# Define target directory.
+dstdir=$TESTDIR1/dstdir.$$
+mytestfile=/kernel/drv/zfs
+
+for user in root $ZFS_ACL_STAFF1; do
+	# Set the current user
+	log_must set_cur_usr $user
+
+	for obj in $testfile $testdir; do
+		# Create source object and target directroy
+		log_must usr_exec $TOUCH $testfile
+		log_must usr_exec $MKDIR $testdir $dstdir
+
+		log_must usr_exec $RUNAT $testfile $CP $mytestfile attr.0
+		log_must usr_exec $RUNAT $testdir $CP $mytestfile attr.0
+
+		# Add the new ACE on the head.
+		log_must usr_exec $CHMOD \
+			A0+user:$ZFS_ACL_OTHER1:read_acl:deny $obj
+
+		cmd_str="$CP -p@"
+		[[ -d $obj ]] && cmd_str="$CP -rp@"
+		log_must usr_exec $cmd_str $obj $dstdir
+		log_must usr_exec $cmd_str $obj $TESTDIR1
+
+		for dir in $dstdir $TESTDIR1; do
+			log_must compare_modes $obj $dir/${obj##*/}
+			log_must compare_acls $obj $dir/${obj##*/}
+			log_must compare_xattrs $obj $dir/${obj##*/}
+		done
+
+		# Delete all the test file and directory
+		log_must usr_exec $RM -rf $TESTDIR/* $TESTDIR1/*
+	done
+done
+
+log_pass "'$CP [-p@]' succeeds to support ZFS ACLs."
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/usr/src/test/zfs-tests/tests/functional/acl/nontrivial/zfs_acl_cpio_001_pos.ksh	Wed Dec 05 22:04:50 2012 -0500
@@ -0,0 +1,122 @@
+#!/bin/ksh -p
+#
+# CDDL HEADER START
+#
+# The contents of this file are subject to the terms of the
+# Common Development and Distribution License (the "License").
+# You may not use this file except in compliance with the License.
+#
+# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
+# or http://www.opensolaris.org/os/licensing.
+# See the License for the specific language governing permissions
+# and limitations under the License.
+#
+# When distributing Covered Code, include this CDDL HEADER in each
+# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
+# If applicable, add the following below this CDDL HEADER, with the
+# fields enclosed by brackets "[]" replaced with your own identifying
+# information: Portions Copyright [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 Marcelo Leal. All rights reserved.
+#
+. $STF_SUITE/tests/functional/acl/acl_common.kshlib
+
+#
+# DESCRIPTION:
+# Verify that '$CPIO' command with -P option supports to archive ZFS ACLs
+#
+# STRATEGY:
+# 1. Create file and directory in zfs filesystem
+# 2. Add new ACE in ACL or change mode of file and directory
+# 3. Use $CPIO to archive file and directory
+# 4. Extract the archive file
+# 5. Verify that the restored ACLs of file and directory identify
+#    with the origional ones.
+#
+
+verify_runnable "both"
+
+function cleanup
+{
+	if datasetexists $TESTPOOL/$TESTFS1; then
+		log_must $ZFS destroy -f $TESTPOOL/$TESTFS1
+	fi
+	if (( ${#orig_dir} != 0 )); then
+		cd $orig_dir
+	fi
+	[[ -d $TESTDIR1 ]] && log_must $RM -rf $TESTDIR1
+	[[ -d $TESTDIR ]] && log_must $RM -rf $TESTDIR/*
+}
+
+log_assert "Verify that '$CPIO' command supports to archive ZFS ACLs."
+log_onexit cleanup
+
+set -A ops "A+user:$ZFS_ACL_OTHER1:execute:allow" \
+	"A3+user:$ZFS_ACL_OTHER1:write_data:deny" \
+	"A0+user:$ZFS_ACL_OTHER1:write_data:deny" \
+	"A3+group:$ZFS_ACL_OTHER_GROUP:read_data:deny" \
+	"A1=user:$ZFS_ACL_STAFF1:write_data:deny" \
+	"A1=group:$ZFS_ACL_STAFF_GROUP:write_data:deny"
+
+log_note "Create second zfs file system to restore the cpio archive."
+log_must $ZFS create $TESTPOOL/$TESTFS1
+log_must $ZFS set mountpoint=$TESTDIR1 $TESTPOOL/$TESTFS1
+log_must $CHMOD 777 $TESTDIR1
+
+# Define test fine and record the original directory.
+CPIOFILE=cpiofile.$$
+file=$TESTFILE0
+dir=dir.$$
+orig_dir=$PWD
+
+typeset user
+for user in root $ZFS_ACL_STAFF1; do
+	# Set the current user
+	log_must set_cur_usr $user
+
+	typeset -i i=0
+	while (( i < ${#ops[*]} )); do
+		log_note "Create file $file and directory $dir " \
+			"in zfs filesystem. "
+		cd $TESTDIR
+		log_must usr_exec $TOUCH $file
+		log_must usr_exec $MKDIR $dir
+
+		log_note "Change the ACLs of file and directory with " \
+			"'$CHMOD ${ops[i]}'."
+		for obj in $file $dir; do
+			log_must usr_exec $CHMOD ${ops[i]} $obj
+		done
+
+		log_note "Archive the file and directory."
+		cd $TESTDIR
+		log_must eval "usr_exec $LS | " \
+			"usr_exec $CPIO -ocP -O $CPIOFILE > /dev/null 2>&1"
+
+		log_note "Restore the cpio archive."
+		log_must usr_exec $MV $CPIOFILE $TESTDIR1
+		cd $TESTDIR1
+		log_must eval "usr_exec $CAT $CPIOFILE | " \
+			"usr_exec $CPIO -icP > /dev/null 2>&1"
+
+		log_note "Verify that the ACLs of restored file/directory " \
+			"have no changes."
+		for obj in $file $dir; do
+			log_must compare_modes $TESTDIR/$obj $TESTDIR1/$obj
+			log_must compare_acls $TESTDIR/$obj $TESTDIR1/$obj
+		done
+
+		log_must usr_exec $RM -rf $TESTDIR/* $TESTDIR1/*
+
+		(( i = i + 1 ))
+	done
+done
+
+log_pass "'$CPIO' command succeeds to support ZFS ACLs."
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/usr/src/test/zfs-tests/tests/functional/acl/nontrivial/zfs_acl_cpio_002_pos.ksh	Wed Dec 05 22:04:50 2012 -0500
@@ -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 2007 Sun Microsystems, Inc.  All rights reserved.
+# Use is subject to license terms.
+#
+# Copyright (c) 2012 by Marcelo Leal. All rights reserved.
+#
+
+. $STF_SUITE/tests/functional/acl/acl_common.kshlib
+
+#
+# DESCRIPTION:
+# Verify that '$CPIO' command with -P@ option supports to archive ZFS ACLs
+#
+# STRATEGY:
+# 1. Create file and directory in zfs filesystem
+# 2. Add new ACE in ACL or change mode of file and directory
+# 3. Create xattr of the file and directory
+# 4. Use $CPIO to archive file and directory
+# 5. Extract the archive file
+# 6. Verify that the restored ACLs of file and directory identify
+#    with the origional ones.
+#
+
+verify_runnable "both"
+
+function cleanup
+{
+	if datasetexists $TESTPOOL/$TESTFS1; then
+		log_must $ZFS destroy -f $TESTPOOL/$TESTFS1
+	fi
+	if (( ${#orig_dir} != 0 )); then
+		cd $orig_dir
+	fi
+	[[ -d $TESTDIR1 ]] && log_must $RM -rf $TESTDIR1
+	[[ -d $TESTDIR ]] && log_must $RM -rf $TESTDIR/*
+}
+
+log_assert "Verify that '$CPIO' command supports to archive ZFS ACLs & xattrs."
+log_onexit cleanup
+
+set -A ops "A+user:$ZFS_ACL_OTHER1:execute:allow" \
+	"A3+user:$ZFS_ACL_OTHER1:write_data:deny" \
+	"A0+user:$ZFS_ACL_OTHER1:write_data:deny" \
+	"A3+group:$ZFS_ACL_OTHER_GROUP:read_data:deny" \
+	"A1=user:$ZFS_ACL_STAFF1:write_data:deny" \
+	"A1=group:$ZFS_ACL_STAFF_GROUP:write_data:deny"
+
+log_note "Create second zfs file system to restore the cpio archive."
+log_must $ZFS create $TESTPOOL/$TESTFS1
+log_must $ZFS set mountpoint=$TESTDIR1 $TESTPOOL/$TESTFS1
+log_must $CHMOD 777 $TESTDIR1
+
+# Define test fine and record the original directory.
+CPIOFILE=cpiofile.$$
+file=$TESTFILE0
+dir=dir.$$
+orig_dir=$PWD
+mytestfile=/kernel/drv/zfs
+
+typeset user
+for user in root $ZFS_ACL_STAFF1; do
+	# Set the current user
+	log_must set_cur_usr $user
+
+	typeset -i i=0
+	while (( i < ${#ops[*]} )); do
+		log_note "Create file $file and directory $dir " \
+			"in zfs filesystem. "
+		cd $TESTDIR
+		log_must usr_exec $TOUCH $file
+		log_must usr_exec $MKDIR $dir
+		log_must usr_exec $RUNAT $file $CP $mytestfile attr.0
+		log_must usr_exec $RUNAT $dir $CP $mytestfile attr.0
+
+		log_note "Change the ACLs of file and directory with " \
+			"'$CHMOD ${ops[i]}'."
+		for obj in $file $dir; do
+			log_must usr_exec $CHMOD ${ops[i]} $obj
+		done
+
+		log_note "Archive the file and directory."
+		cd $TESTDIR
+		log_must eval "usr_exec $LS | " \
+			"usr_exec $CPIO -ocP@ -O $CPIOFILE > /dev/null 2>&1"
+
+		log_note "Restore the cpio archive."
+		log_must usr_exec $MV $CPIOFILE $TESTDIR1
+		cd $TESTDIR1
+		log_must eval "usr_exec $CAT $CPIOFILE | " \
+			"usr_exec $CPIO -icP@ > /dev/null 2>&1"
+
+		log_note "Verify that the ACLs of restored file/directory " \
+			"have no changes."
+		for obj in $file $dir; do
+			log_must compare_modes $TESTDIR/$obj $TESTDIR1/$obj
+			log_must compare_acls $TESTDIR/$obj $TESTDIR1/$obj
+			log_must compare_xattrs $TESTDIR/$obj $TESTDIR1/$obj
+		done
+
+		log_must usr_exec $RM -rf $TESTDIR/* $TESTDIR1/*
+
+		(( i = i + 1 ))
+	done
+done
+
+log_pass "'$CPIO' command succeeds to support ZFS ACLs & xattrs."
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/usr/src/test/zfs-tests/tests/functional/acl/nontrivial/zfs_acl_find_001_pos.ksh	Wed Dec 05 22:04:50 2012 -0500
@@ -0,0 +1,129 @@
+#!/bin/ksh -p
+#
+# CDDL HEADER START
+#
+# The contents of this file are subject to the terms of the
+# Common Development and Distribution License (the "License").
+# You may not use this file except in compliance with the License.
+#
+# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
+# or http://www.opensolaris.org/os/licensing.
+# See the License for the specific language governing permissions
+# and limitations under the License.
+#
+# When distributing Covered Code, include this CDDL HEADER in each
+# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
+# If applicable, add the following below this CDDL HEADER, with the
+# fields enclosed by brackets "[]" replaced with your own identifying
+# information: Portions Copyright [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.
+#
+
+. $STF_SUITE/tests/functional/acl/acl_common.kshlib
+
+#
+# DESCRIPTION:
+# Verify that '$FIND' command with '-ls' and '-acl' options supports ZFS ACL
+#
+# STRATEGY:
+# 1. Create 5 files and 5 directories in zfs filesystem
+# 2. Select a file or directory and add a few ACEs to it
+# 3. Use $FIND -ls to check the "+" existen only with the selected file or
+#    directory
+# 4. Use $FIND -acl to check only the selected file/directory in the list
+#
+
+verify_runnable "both"
+
+function cleanup
+{
+	[[ -d $TESTDIR ]] && $RM -rf $TESTDIR/*
+	(( ${#cmd} != 0 )) && cd $cwd
+	(( ${#mask} != 0 )) && $UMASK $mask
+}
+
+function find_ls_acl #<opt> <obj>
+{
+	typeset opt=$1 # -ls or -acl
+	typeset obj=$2
+	typeset rst_str=""
+
+	if [[ $opt == "ls" ]]; then
+		rst_str=`$FIND . -ls | $GREP "+" | $AWK '{print $11}'`
+	else
+		rst_str=`$FIND . -acl`
+	fi
+
+	if [[ $rst_str == "./$obj" ]]; then
+		return 0
+	else
+		return 1
+	fi
+}
+
+log_assert "Verify that '$FIND' command supports ZFS ACLs."
+
+log_onexit cleanup
+
+set -A ops " A+user:$ZFS_ACL_STAFF1:read_data:allow" \
+	" A+user:$ZFS_ACL_STAFF1:write_data:allow"
+
+f_base=testfile.$$ # Base file name for tested files
+d_base=testdir.$$ # Base directory name for tested directory
+cwd=$PWD
+mask=`$UMASK`
+
+log_note "Create five files and directories in the zfs filesystem. "
+cd $TESTDIR
+$UMASK 0777
+typeset -i i=0
+while ((i < 5))
+do
+	log_must $TOUCH ${f_base}.$i
+	log_must $MKDIR ${d_base}.$i
+
+	((i = i + 1))
+done
+
+for obj in ${f_base}.3 ${d_base}.3
+do
+	i=0
+	while ((i < ${#ops[*]}))
+	do
+		log_must $CHMOD ${ops[i]} $obj
+
+		((i = i + 1))
+	done
+
+	for opt in "ls" "acl"
+	do
+		log_must find_ls_acl $opt $obj
+	done
+
+	log_note "Check the file access permission according to the added ACEs"
+	if [[ ! -r $obj || ! -w $obj ]]; then
+		log_fail "The added ACEs for $obj cannot be represented in " \
+			"mode."
+	fi
+
+	log_note "Remove the added ACEs from ACL."
+	i=0
+	while ((i < ${#ops[*]}))
+	do
+		log_must $CHMOD A0- $obj
+
+		((i = i + 1))
+	done
+done
+
+log_pass "'$FIND' command succeeds to support ZFS ACLs."
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/usr/src/test/zfs-tests/tests/functional/acl/nontrivial/zfs_acl_ls_001_pos.ksh	Wed Dec 05 22:04:50 2012 -0500
@@ -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 2007 Sun Microsystems, Inc.  All rights reserved.
+# Use is subject to license terms.
+#
+
+. $STF_SUITE/tests/functional/acl/acl_common.kshlib
+
+#
+# DESCRIPTION:
+# Verify that '/usr/bin/ls' command option supports ZFS ACL
+#
+# STRATEGY:
+# 1. Create file and  directory in zfs filesystem
+# 2. Verify that 'ls [-dv]' can list the ACEs of ACL of
+#    file/directroy
+# 3. Change the file/directory's acl
+# 4. Verify that 'ls -l' can use the '+' to indicate the non-trivial
+#    acl.
+#
+
+verify_runnable "both"
+
+function cleanup
+{
+	(( ${#cwd} != 0 )) && cd $cwd
+	[[ -d $TESTDIR ]] && log_must $RM -rf $TESTDIR/*
+	(( ${#mask} != 0 )) && log_must $UMASK $mask
+}
+
+log_assert "Verify that '$LS' command supports ZFS ACLs."
+
+log_onexit cleanup
+
+file=$TESTFILE0
+dir=dir.$$
+cwd=$PWD
+mask=`$UMASK`
+spec_ace="everyone@:write_acl:allow"
+
+$UMASK 0022
+
+log_note "Create file and directory in the zfs filesystem. "
+cd $TESTDIR
+log_must $TOUCH $file
+log_must $MKDIR $dir
+
+log_note "Verify that '$LS [-dv]' can list file/directory ACEs of its acl."
+
+typeset -i ace_num=0
+for obj in $file $dir
+do
+	typeset ls_str=""
+	if [[ -f $obj ]]; then
+		ls_str="$LS -v"
+	else
+		ls_str="$LS -dv"
+	fi
+
+	for ace_type in "owner@" "group@" "everyone@"
+	do
+		$ls_str $obj | $GREP $ace_type > /dev/null 2>&1
+		(( $? == 0 )) && (( ace_num += 1 ))
+	done
+
+	(( ace_num < 1 )) && \
+		log_fail "'$LS [-dv] fails to list file/directroy acls."
+done
+
+log_note "Verify that '$LS [-dl] [-dv]' can output '+' to indicate " \
+	"the acl existent."
+
+for obj in $file $dir
+do
+	$CHMOD A0+$spec_ace $obj
+
+	log_must eval "$LS -ld -vd $obj | $GREP "+" > /dev/null"
+	log_must plus_sign_check_v $obj
+
+	log_must eval "$LS -ld -vd $obj | $GREP $spec_ace > /dev/null"
+	log_must plus_sign_check_l $obj
+done
+
+log_pass "'$LS' command succeeds to support ZFS ACLs."
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/usr/src/test/zfs-tests/tests/functional/acl/nontrivial/zfs_acl_mv_001_pos.ksh	Wed Dec 05 22:04:50 2012 -0500
@@ -0,0 +1,171 @@
+#!/bin/ksh -p
+#
+# CDDL HEADER START
+#
+# The contents of this file are subject to the terms of the
+# Common Development and Distribution License (the "License").
+# You may not use this file except in compliance with the License.
+#
+# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
+# or http://www.opensolaris.org/os/licensing.
+# See the License for the specific language governing permissions
+# and limitations under the License.
+#
+# When distributing Covered Code, include this CDDL HEADER in each
+# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
+# If applicable, add the following below this CDDL HEADER, with the
+# fields enclosed by brackets "[]" replaced with your own identifying
+# information: Portions Copyright [yyyy] [name of copyright owner]
+#
+# CDDL HEADER END
+#
+
+#
+# Copyright 2007 Sun Microsystems, Inc.  All rights reserved.
+# Use is subject to license terms.
+#
+. $STF_SUITE/tests/functional/acl/acl_common.kshlib
+
+#
+# DESCRIPTION:
+# Verify that '/usr/bin/mv' supports ZFS ACL
+#
+# STRATEGY:
+# 1. Create file and  directory in zfs filesystem
+# 2. Set special ACE to the file and directory
+# 3. Copy the file/directory within and across zfs file system
+# 4. Verify that the ACL of file/directroy is not changed
+#
+
+verify_runnable "both"
+
+function cleanup
+{
+	(( ${#cwd} != 0 )) && cd $cwd
+	[[ -d $TESTDIR ]] && log_must $RM -rf $TESTDIR/*
+	[[ -d $TESTDIR1 ]] && log_must $RM -rf $TESTDIR1
+	(( ${#mask} != 0 )) && log_must $UMASK $mask
+}
+
+function testing_mv #<flag for file|dir> <file1|dir1> <file2|dir2>
+{
+	typeset flag=$1
+	set -A obj $2 $3
+	typeset -i i=0
+	typeset orig_acl=""
+	typeset orig_mode=""
+	typeset dst_acl=""
+	typeset dst_mode=""
+
+	if [[ $flag == "f" ]]; then
+	while (( i < ${#obj[*]} ))
+	do
+		orig_acl="$(get_acl ${obj[i]})"
+		orig_mode="$(get_mode ${obj[i]})"
+		if (( i < 1 )); then
+			log_must $MV ${obj[i]} $dst_file
+			dst_acl=$(get_acl $dst_file)
+			dst_mode=$(get_mode $dst_file)
+		else
+			log_must $MV ${obj[i]} $TESTDIR1
+			dst_acl=$(get_acl $TESTDIR1/${obj[i]})
+			dst_mode=$(get_mode $TESTDIR1/${obj[i]})
+		fi
+
+		if [[ "$dst_mode" != "$orig_mode" ]] || \
+			[[ "$dst_acl" != "$orig_acl" ]]; then
+			log_fail "$MV fails to keep the acl for file."
+		fi
+
+		(( i = i + 1 ))
+	done
+	else
+	while (( i < ${#obj[*]} ))
+	do
+		typeset orig_nested_acl=""
+		typeset orig_nested_mode=""
+		typeset dst_nested_acl=""
+		typeset dst_nested_mode=""
+
+		orig_acl=$(get_acl ${obj[i]})
+		orig_mode=$(get_mode ${obj[i]})
+		orig_nested_acl=$(get_acl ${obj[i]}/$nestedfile)
+		orig_nested_mode=$(get_mode ${obj[i]}/$nestedfile)
+		if (( i < 1 )); then
+			log_must $MV ${obj[i]} $dst_dir
+			dst_acl=$(get_acl $dst_dir)
+			dst_mode=$(get_mode $dst_dir)
+			dst_nested_acl=$(get_acl $dst_dir/$nestedfile)
+			dst_nested_mode=$(get_mode $dst_dir/$nestedfile)
+		else
+			log_must $MV ${obj[i]} $TESTDIR1
+			dst_acl=$(get_acl $TESTDIR1/${obj[i]})
+			dst_mode=$(get_mode $TESTDIR1/${obj[i]})
+			dst_nested_acl=$(get_acl \
+				$TESTDIR1/${obj[i]}/$nestedfile)
+			dst_nested_mode=$(get_mode \
+				$TESTDIR1/${obj[i]}/$nestedfile)
+		fi
+
+		if [[ "$orig_mode" != "$dst_mode" ]] || \
+		   [[ "$orig_acl" != "$dst_acl" ]] || \
+		   [[ "$dst_nested_mode" != "$orig_nested_mode" ]] || \
+		   [[ "$dst_nested_acl" != "$orig_nested_acl" ]]; then
+			log_fail "$MV fails to recursively keep the acl for " \
+				"directory."
+		fi
+
+		(( i = i + 1 ))
+	done
+	fi
+}
+
+log_assert "Verify that '$MV' supports ZFS ACLs."
+
+log_onexit cleanup
+
+spec_ace="everyone@:execute:allow"
+set -A orig_file "origfile1.$$" "origfile2.$$"
+set -A orig_dir "origdir1.$$" "origdir2.$$"
+nestedfile="nestedfile.$$"
+dst_file=dstfile.$$
+dst_dir=dstdir.$$
+cwd=$PWD
+mask=`$UMASK`
+$UMASK 0022
+
+#
+# This assertion should only test 'mv' within the same filesystem
+#
+TESTDIR1=$TESTDIR/testdir1$$
+
+[[ ! -d $TESTDIR1 ]] && \
+	log_must $MKDIR -p $TESTDIR1
+
+log_note "Create files and directories and set special ace on them for testing. "
+cd $TESTDIR
+typeset -i i=0
+while (( i < ${#orig_file[*]} ))
+do
+	log_must $TOUCH ${orig_file[i]}
+	log_must $CHMOD A0+$spec_ace ${orig_file[i]}
+
+	(( i = i + 1 ))
+done
+i=0
+while (( i < ${#orig_dir[*]} ))
+do
+	log_must $MKDIR ${orig_dir[i]}
+	log_must $TOUCH ${orig_dir[i]}/$nestedfile
+
+	for obj in ${orig_dir[i]} ${orig_dir[i]}/$nestedfile; do
+		log_must $CHMOD A0+$spec_ace $obj
+	done
+
+	(( i = i + 1 ))
+done
+
+testing_mv "f" ${orig_file[0]} ${orig_file[1]}
+testing_mv "d" ${orig_dir[0]} ${orig_dir[1]}
+
+log_pass "'$MV' succeeds to support ZFS ACLs."
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/usr/src/test/zfs-tests/tests/functional/acl/nontrivial/zfs_acl_tar_001_pos.ksh	Wed Dec 05 22:04:50 2012 -0500
@@ -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) 2012 by Marcelo Leal. All rights reserved.
+#
+. $STF_SUITE/tests/functional/acl/acl_common.kshlib
+
+#
+# DESCRIPTION:
+# Verify that '$TAR' command with -p option supports to archive ZFS ACLs
+#
+# STRATEGY:
+# 1. Create file and directory in zfs filesystem
+# 2. Add new ACE in ACL of file and directory
+# 3. Use $TAR to archive file and directory
+# 4. Extract the archive file
+# 5. Verify that the restored ACLs of file and directory identify
+#    with the origional ones.
+#
+
+verify_runnable "both"
+
+function cleanup
+{
+	if datasetexists $TESTPOOL/$TESTFS1; then
+		log_must $ZFS destroy -f $TESTPOOL/$TESTFS1
+	fi
+
+	(( ${#cwd} != 0 )) && cd $cwd
+	[[ -d $TESTDIR1 ]] && log_must $RM -rf $TESTDIR1
+	[[ -d $TESTDIR/ ]] && log_must $RM -rf $TESTDIR/*
+}
+
+log_assert "Verify that '$TAR' command supports to archive ZFS ACLs."
+
+log_onexit cleanup
+
+set -A ops " A+user:other1:add_file:allow" "A+everyone@:execute:allow" "a-x" "777"
+
+TARFILE=tarfile.$$.tar
+file=$TESTFILE0
+dir=dir.$$
+cwd=$PWD
+
+log_note "Create second zfs file system to restore the tar archive."
+log_must $ZFS create $TESTPOOL/$TESTFS1
+[[ ! -d $TESTDIR1 ]] && \
+	log_must $MKDIR -p $TESTDIR1
+log_must $ZFS set mountpoint=$TESTDIR1 $TESTPOOL/$TESTFS1
+
+log_note "Create a file: $file, and directory: $dir, in zfs filesystem. "
+cd $TESTDIR
+log_must $TOUCH $file
+log_must $MKDIR $dir
+
+typeset -i i=0
+while (( i < ${#ops[*]} ))
+do
+	log_note "Change the ACLs of file and directory with " \
+		"'$CHMOD ${ops[i]}'."
+	cd $TESTDIR
+	for obj in $file $dir; do
+		log_must $CHMOD ${ops[i]} $obj
+	done
+	log_note "Archive the file and directory."
+	log_must $TAR cpf $TARFILE $file $dir
+
+	log_note "Restore the tar archive."
+	log_must $MV $TARFILE $TESTDIR1
+	cd $TESTDIR1
+	log_must $TAR xpf $TARFILE
+
+	log_note "Verify the ACLs of restored file/directory have no changes."
+	for obj in $file $dir; do
+		log_must compare_modes $TESTDIR/$obj $TESTDIR1/$obj
+		log_must compare_acls $TESTDIR/$obj $TESTDIR1/$obj
+	done
+
+	log_must $RM -rf $TESTDIR1/*
+
+	(( i = i + 1 ))
+done
+
+log_pass "'$TAR' command succeeds to support ZFS ACLs."
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/usr/src/test/zfs-tests/tests/functional/acl/nontrivial/zfs_acl_tar_002_pos.ksh	Wed Dec 05 22:04:50 2012 -0500
@@ -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) 2012 by Marcelo Leal. All rights reserved.
+#
+
+. $STF_SUITE/tests/functional/acl/acl_common.kshlib
+
+#
+# DESCRIPTION:
+# Verify that '$TAR' command with -p@ option supports to archive ZFS ACLs
+#	& xattrs
+#
+# STRATEGY:
+# 1. Create file and directory in zfs filesystem
+# 2. Add new ACE in ACL of file and directory
+# 3. Create xattr of the file and directory
+# 4. Use $TAR cf@ to archive file and directory
+# 5. Use $TAR xf@ to extract the archive file
+# 6. Verify that the restored ACLs & xttrs of file and directory identify
+#    with the origional ones.
+#
+
+verify_runnable "both"
+
+function cleanup
+{
+	if datasetexists $TESTPOOL/$TESTFS1; then
+		log_must $ZFS destroy -f $TESTPOOL/$TESTFS1
+	fi
+
+	(( ${#cwd} != 0 )) && cd $cwd
+	[[ -d $TESTDIR1 ]] && log_must $RM -rf $TESTDIR1
+	[[ -d $TESTDIR/ ]] && log_must $RM -rf $TESTDIR/*
+}
+
+log_assert "Verify that '$TAR' command supports to archive ZFS ACLs & xattrs."
+
+log_onexit cleanup
+
+set -A ops " A+user:other1:add_file:allow" "A+everyone@:execute:allow" "a-x" \
+    "777"
+mytestfile=/kernel/drv/zfs
+
+TARFILE=tarfile.$$.tar
+cwd=$PWD
+
+log_note "Create second zfs file system to restore the tar archive."
+log_must $ZFS create $TESTPOOL/$TESTFS1
+[[ ! -d $TESTDIR1 ]] && \
+	log_must $MKDIR -p $TESTDIR1
+log_must $ZFS set mountpoint=$TESTDIR1 $TESTPOOL/$TESTFS1
+
+log_note "Create a file: $testfile, and directory: $testdir, in zfs " \
+    "filesystem. And prepare for there xattr files."
+
+for user in root $ZFS_ACL_STAFF1; do
+	# Set the current user
+	log_must set_cur_usr $user
+
+	# Create source object and target directroy
+	cd $TESTDIR
+	log_must usr_exec $TOUCH $testfile
+	log_must usr_exec $MKDIR $testdir
+
+	log_must usr_exec $RUNAT $testfile $CP $mytestfile attr.0
+	log_must usr_exec $RUNAT $testdir $CP $mytestfile attr.0
+
+	# Add the new ACE on the head.
+	log_note "Change the ACLs of file and directory with " \
+		"'$CHMOD ${ops[0]}'."
+	log_must usr_exec $CHMOD ${ops[0]} $testfile
+	log_must usr_exec $CHMOD ${ops[0]} $testdir
+
+	log_note "Archive the file and directory."
+	log_must $TAR cpf@ $TARFILE ${testfile#$TESTDIR/} ${testdir#$TESTDIR/}
+
+	log_note "Restore the tar archive."
+	cd $TESTDIR1
+	log_must $TAR xpf@ $TESTDIR/$TARFILE
+
+	log_note "Verify the ACLs of restored file/directory have no changes."
+	for obj in $testfile $testdir; do
+		log_must compare_modes $obj $TESTDIR1/${obj##*/}
+		log_must compare_acls $obj $TESTDIR1/${obj##*/}
+		log_must compare_xattrs $obj $TESTDIR1/${obj##*/}
+	done
+
+	log_must $RM -rf $TESTDIR/* $TESTDIR1/*
+done
+
+log_pass "'$TAR' command succeeds to support ZFS ACLs."
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/usr/src/test/zfs-tests/tests/functional/acl/trivial/Makefile	Wed Dec 05 22:04:50 2012 -0500
@@ -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) 2012 by Delphix. All rights reserved.
+#
+
+include $(SRC)/Makefile.master
+
+ROOTOPTPKG = $(ROOT)/opt/zfs-tests
+TESTDIR = $(ROOTOPTPKG)/tests/functional/acl/trivial
+
+PROGS = cleanup \
+	setup \
+	zfs_acl_chmod_001_pos \
+	zfs_acl_compress_001_pos \
+	zfs_acl_cp_001_pos \
+	zfs_acl_cp_002_neg \
+	zfs_acl_cp_003_neg \
+	zfs_acl_find_001_pos \
+	zfs_acl_find_002_neg \
+	zfs_acl_ls_001_pos \
+	zfs_acl_ls_002_neg \
+	zfs_acl_mv_001_pos \
+	zfs_acl_pack_001_pos \
+	zfs_acl_pax_001_pos \
+	zfs_acl_pax_002_pos \
+	zfs_acl_pax_003_pos \
+	zfs_acl_pax_004_pos \
+	zfs_acl_pax_005_pos \
+	zfs_acl_pax_006_pos \
+	zfs_acl_tar_001_pos \
+	zfs_acl_tar_002_neg
+
+CMDS = $(PROGS:%=$(TESTDIR)/%)
+$(CMDS) := FILEMODE = 0555
+
+all lint clean clobber:
+
+install: $(CMDS)
+
+$(CMDS): $(TESTDIR)
+
+$(TESTDIR):
+	$(INS.dir)
+
+$(TESTDIR)/%: %.ksh
+	$(INS.rename)
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/usr/src/test/zfs-tests/tests/functional/acl/trivial/cleanup.ksh	Wed Dec 05 22:04:50 2012 -0500
@@ -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.
+#
+
+. $STF_SUITE/include/libtest.shlib
+. $STF_SUITE/tests/functional/acl/acl_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
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/usr/src/test/zfs-tests/tests/functional/acl/trivial/setup.ksh	Wed Dec 05 22:04:50 2012 -0500
@@ -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.
+#
+
+. $STF_SUITE/include/libtest.shlib
+. $STF_SUITE/tests/functional/acl/acl_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
+
+# Add root group user
+log_must add_user root $ZFS_ACL_ADMIN
+
+# Create staff group and add two user to it
+log_must add_group $ZFS_ACL_STAFF_GROUP
+log_must add_user $ZFS_ACL_STAFF_GROUP $ZFS_ACL_STAFF1
+log_must add_user $ZFS_ACL_STAFF_GROUP $ZFS_ACL_STAFF2
+
+# Create other group and add two user to it
+log_must add_group $ZFS_ACL_OTHER_GROUP
+log_must add_user $ZFS_ACL_OTHER_GROUP $ZFS_ACL_OTHER1
+log_must add_user $ZFS_ACL_OTHER_GROUP $ZFS_ACL_OTHER2
+
+DISK=${DISKS%% *}
+default_setup_noexit $DISK
+log_must $CHMOD 777 $TESTDIR
+
+log_pass
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/usr/src/test/zfs-tests/tests/functional/acl/trivial/zfs_acl_chmod_001_pos.ksh	Wed Dec 05 22:04:50 2012 -0500
@@ -0,0 +1,140 @@
+#!/bin/ksh -p
+#
+# CDDL HEADER START
+#
+# The contents of this file are subject to the terms of the
+# Common Development and Distribution License (the "License").
+# You may not use this file except in compliance with the License.
+#
+# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
+# or http://www.opensolaris.org/os/licensing.
+# See the License for the specific language governing permissions
+# and limitations under the License.
+#
+# When distributing Covered Code, include this CDDL HEADER in each
+# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
+# If applicable, add the following below this CDDL 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) 2012 by Delphix. All rights reserved.
+#
+
+. $STF_SUITE/tests/functional/acl/acl_common.kshlib
+
+#
+# DESCRIPTION:
+#	Verify chmod permission settings on files and directories, as both root
+#	and non-root users.
+#
+# STRATEGY:
+#	1. Loop root and $ZFS_ACL_STAFF1 as root and non-root users.
+#	2. Create test file and directory in zfs filesystem.
+#	3. Execute 'chmod' with specified options.
+#	4. Check 'ls -l' output and compare with expect results.
+#
+# NOTE:
+#	The test does not work for default "discard" aclmode property.
+#	The test is modified to run with "passthrough" aclmode property.
+
+verify_runnable "both"
+
+function cleanup
+{
+	# reset aclmode=discard
+	log_must $ZFS set aclmode=discard $TESTPOOL/$TESTFS
+}
+
+#	"init_map" "options" "expect_map"
+set -A argv \
+	"000" "a+rw"	"rw-rw-rw-"	"000" "a+rwx"	"rwxrwxrwx" \
+	"000" "u+xr"	"r-x------"	"000" "gu-xw"	"---------" \
+	"644" "a-r"	"-w-------"	"644" "augo-x"	"rw-r--r--" \
+	"644" "=x"	"--x--x--x"	"644" "u-rw"	"---r--r--" \
+	"644" "uo+x"	"rwxr--r-x"	"644" "ga-wr"	"---------" \
+	"777" "augo+x"	"rwxrwxrwx"	"777" "go-xr"	"rwx-w--w-" \
+	"777" "o-wx"	"rwxrwxr--"	"777" "ou-rx"	"-w-rwx-w-" \
+	"777" "a+rwx"	"rwxrwxrwx"	"777" "u=rw"	"rw-rwxrwx" \
+	"000" "123"	"--x-w--wx"	"000" "412"	"r----x-w-" \
+	"231" "562"	"r-xrw--w-"	"712" "000"	"---------" \
+	"777" "121"	"--x-w---x"	"123" "775"	"rwxrwxr-x"
+
+log_assert " Verify chmod permission settings on files and directories"
+log_onexit cleanup
+
+#
+# Verify file or directory have correct map after chmod
+#
+# $1 file or directory
+#
+function test_chmod_mapping #<file-dir>
+{
+	typeset node=$1
+	typeset -i i=0
+
+	while ((i < ${#argv[@]})); do
+		usr_exec $CHMOD ${argv[i]} $node
+		if (($? != 0)); then
+			log_note "usr_exec $CHMOD ${argv[i]} $node"
+			return 1
+		fi
+		usr_exec $CHMOD ${argv[((i + 1))]} $node
+		if (($? != 0)); then
+			log_note "usr_exec $CHMOD ${argv[((i + 1))]} $node"
+			return 1
+		fi
+
+		typeset mode
+		mode=$(get_mode ${node})
+
+		if [[ $mode != "-${argv[((i + 2))]}"* && \
+			$mode != "d${argv[((i + 2))]}"* ]]
+		then
+			log_fail "FAIL: '${argv[i]}' '${argv[((i + 1))]}' \
+				'${argv[((i + 2))]}'"
+		fi
+
+		((i += 3))
+	done
+
+	return 0
+}
+
+# set aclmode=passthrough
+log_must $ZFS set aclmode=passthrough $TESTPOOL/$TESTFS
+
+for user in root $ZFS_ACL_STAFF1; do
+	log_must set_cur_usr $user
+
+	# Test file
+	log_must usr_exec $TOUCH $testfile
+	log_must test_chmod_mapping $testfile
+	log_must usr_exec $CHMOD A+user:$ZFS_ACL_STAFF2:write_acl:allow $testfile
+
+	# Test directory
+	log_must usr_exec $MKDIR $testdir
+	log_must test_chmod_mapping $testdir
+	log_must usr_exec $CHMOD A+user:$ZFS_ACL_STAFF2:write_acl:allow $testdir
+
+	# Grant privileges of write_acl and retest the chmod commands.
+
+	log_must set_cur_usr $ZFS_ACL_STAFF2
+	log_must test_chmod_mapping $testfile
+	log_must test_chmod_mapping $testdir
+
+	log_must set_cur_usr $user
+
+	log_must usr_exec $RM $testfile
+	log_must usr_exec $RM -rf $testdir
+done
+
+log_pass "Setting permissions using 'chmod' completed successfully."
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/usr/src/test/zfs-tests/tests/functional/acl/trivial/zfs_acl_compress_001_pos.ksh	Wed Dec 05 22:04:50 2012 -0500
@@ -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.
+#
+
+. $STF_SUITE/tests/functional/acl/acl_common.kshlib
+
+#
+# DESCRIPTION:
+#	The function verifies that compress will keep file attribute intact
+#	after the file is compressed and uncompressed.
+#
+# STRATEGY:
+#	1. In directory A, create several files and add attribute files for them
+#	2. Save all files and their attribute files cksum value, then compress
+#	   all the files.
+#	3. Move them to another directory B.
+#	4. Uncompress them and calculate all the files and attribute files cksum
+#	5. Verify all the cksum are identical
+#
+
+verify_runnable "both"
+
+log_assert "Compress will keep file attribute intact after the file is " \
+	"compressed and uncompressed"
+log_onexit cleanup
+
+set -A BEFORE_FCKSUM
+set -A BEFORE_ACKSUM
+set -A AFTER_FCKSUM
+set -A AFTER_ACKSUM
+
+for user in root $ZFS_ACL_STAFF1; do
+	log_must set_cur_usr $user
+
+	log_must create_files $TESTDIR
+
+	log_must cksum_files $INI_DIR BEFORE_FCKSUM BEFORE_ACKSUM
+	log_must usr_exec $COMPRESS $INI_DIR/*
+	log_must usr_exec $MV $INI_DIR/* $TST_DIR
+	log_must usr_exec $UNCOMPRESS $TST_DIR/*
+	log_must cksum_files $TST_DIR AFTER_FCKSUM AFTER_ACKSUM
+
+	log_must compare_cksum BEFORE_FCKSUM AFTER_FCKSUM
+	log_must compare_cksum BEFORE_ACKSUM AFTER_ACKSUM
+
+	log_must cleanup
+done
+
+log_pass "compress/uncompress test passed."
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/usr/src/test/zfs-tests/tests/functional/acl/trivial/zfs_acl_cp_001_pos.ksh	Wed Dec 05 22:04:50 2012 -0500
@@ -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.
+#
+
+. $STF_SUITE/tests/functional/acl/acl_common.kshlib
+
+#
+# DESCRIPTION:
+#	Verifies that cp will include file attribute when using the -@ flag
+#
+# STRATEGY:
+#	1. In directory A, create several files and add attribute files for them
+#	2. Save all files and their attribute files cksum value, then 'cp -@p'
+#	   all the files to to another directory B.
+#	3. Calculate all the cksum in directory B.
+#	4. Verify all the cksum are identical
+#
+
+verify_runnable "both"
+
+log_assert "Verifies that cp will include file attribute when using the -@ flag"
+log_onexit cleanup
+
+set -A BEFORE_FCKSUM
+set -A BEFORE_ACKSUM
+set -A AFTER_FCKSUM
+set -A AFTER_ACKSUM
+
+for user in root $ZFS_ACL_STAFF1; do
+	log_must set_cur_usr $user
+
+	log_must create_files $TESTDIR
+	log_must cksum_files $INI_DIR BEFORE_FCKSUM BEFORE_ACKSUM
+
+	initfiles=$($LS -R $INI_DIR/*)
+	typeset -i i=0
+	while ((i < NUM_FILE)); do
+		f=$(getitem $i $initfiles)
+
+		usr_exec $CP -@p $f $TST_DIR
+
+		((i += 1))
+	done
+
+	log_must cksum_files $TST_DIR AFTER_FCKSUM AFTER_ACKSUM
+	log_must compare_cksum BEFORE_FCKSUM AFTER_FCKSUM
+	log_must compare_cksum BEFORE_ACKSUM AFTER_ACKSUM
+
+	log_must cleanup
+done
+
+log_pass "'cp -@' include file attribute passed."
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/usr/src/test/zfs-tests/tests/functional/acl/trivial/zfs_acl_cp_002_neg.ksh	Wed Dec 05 22:04:50 2012 -0500
@@ -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.
+#
+
+. $STF_SUITE/tests/functional/acl/acl_common.kshlib
+
+#
+# DESCRIPTION:
+#	Verifies that cp will not include file attribute when the -@ flag is not
+#	present.
+#
+# STRATEGY:
+#	1. In directory A, create several files and add attribute files for them
+#	2. Implement cp to files without '-@'
+#	3. Verify attribute files will not include file attribute
+#
+
+verify_runnable "both"
+
+log_assert "Verifies that cp will not include file attribute when the -@ flag "\
+	"is not present."
+log_onexit cleanup
+
+for user in root $ZFS_ACL_STAFF1; do
+	log_must set_cur_usr $user
+
+	log_must create_files $TESTDIR
+
+	initfiles=$($LS -R $INI_DIR/*)
+	typeset -i i=0
+	while (( i < NUM_FILE )); do
+		typeset f=$(getitem $i $initfiles)
+		usr_exec $CP $f $TST_DIR
+
+		testfiles=$($LS -R $TST_DIR/*)
+		tf=$(getitem $i $testfiles)
+		ls_attr=$($LS -@ $tf | $AWK '{print substr($1, 11, 1)}')
+		if [[ $ls_attr == "@" ]]; then
+			log_fail "cp of attribute should fail without " \
+				"-@ or -p option"
+		fi
+
+		(( i += 1 ))
+	done
+
+	log_must cleanup
+done
+
+log_pass "'cp' won't include file attribute passed."
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/usr/src/test/zfs-tests/tests/functional/acl/trivial/zfs_acl_cp_003_neg.ksh	Wed Dec 05 22:04:50 2012 -0500
@@ -0,0 +1,118 @@
+#!/bin/ksh -p
+#
+# CDDL HEADER START
+#
+# The contents of this file are subject to the terms of the
+# Common Development and Distribution License (the "License").
+# You may not use this file except in compliance with the License.
+#
+# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
+# or http://www.opensolaris.org/os/licensing.
+# See the License for the specific language governing permissions
+# and limitations under the License.
+#
+# When distributing Covered Code, include this CDDL HEADER in each
+# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
+# If applicable, add the following below this CDDL HEADER, with the
+# fields enclosed by brackets "[]" replaced with your own identifying
+# information: Portions Copyright [yyyy] [name of copyright owner]
+#
+# CDDL HEADER END
+#
+
+#
+# Copyright 2007 Sun Microsystems, Inc.  All rights reserved.
+# Use is subject to license terms.
+#
+
+. $STF_SUITE/tests/functional/acl/acl_common.kshlib
+
+#
+# DESCRIPTION:
+#	Verifies that cp will not be able to include file attribute when
+#	attribute is unreadable (unless the user is root)
+#
+# STRATEGY:
+#	1. In directory A, create several files and add attribute files for them
+#	2. chmod all files'the attribute files to '000'.
+#	3. Implement 'cp -@p' to files.
+#	4. Verify attribute files are not existing for non-root user.
+#
+
+verify_runnable "both"
+
+log_assert "Verifies that cp won't be able to include file attribute when " \
+	"attribute is unreadable (except root)"
+log_onexit cleanup
+
+function test_unreadable_attr
+{
+	typeset initfiles=$($LS -R $INI_DIR/*)
+
+	typeset -i i=0
+	while (( i < NUM_FILE )); do
+		typeset f=$(getitem $i $initfiles)
+		typeset -i j=0
+		while (( j < NUM_ATTR )); do
+			# chmod all the attribute files to '000'.
+			usr_exec $RUNAT $f $CHMOD 000 attribute.$j
+
+			(( j += 1 ))
+		done
+
+		#
+		# Implement 'cp -@p' to the file whose attribute files
+		# models are '000'.
+		#
+		usr_exec $CP -@p $f $TST_DIR > /dev/null 2>&1
+
+		typeset testfiles=$($LS -R $TST_DIR/*)
+		typeset tf=$(getitem $i $testfiles)
+		typeset ls_attr=$(usr_exec $LS -@ $tf | \
+			$AWK '{print substr($1, 11, 1)}')
+
+		case $ZFS_ACL_CUR_USER in
+		root)
+			case $ls_attr in
+			@)
+				log_note "SUCCESS: root enable to cp attribute"\
+					"when attribute files is unreadable"
+				break ;;
+			*)
+				log_fail "root should enable to cp attribute " \
+					"when attribute files is unreadable"
+				break ;;
+			esac
+			;;
+		$ZFS_ACL_STAFF1)
+			case $ls_attr in
+			@)
+				log_fail "non-root shouldn't enable to cp " \
+					"attribute when attribute files is " \
+					"unreadable."
+				break ;;
+			*)
+				log_note "SUCCESS: non-root doesn't enable to "\
+					"cp attribute when attribute files is "\
+					"unreadable."
+				break ;;
+			esac
+			;;
+		*)
+		esac
+
+
+		(( i += 1 ))
+	done
+}
+
+for user in root $ZFS_ACL_STAFF1; do
+	log_must set_cur_usr $user
+
+	log_must create_files $TESTDIR
+	test_unreadable_attr
+
+	log_must cleanup
+done
+
+log_pass "'cp -@p' won't include file attribute passed."
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/usr/src/test/zfs-tests/tests/functional/acl/trivial/zfs_acl_find_001_pos.ksh	Wed Dec 05 22:04:50 2012 -0500
@@ -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 2007 Sun Microsystems, Inc.  All rights reserved.
+# Use is subject to license terms.
+#
+
+. $STF_SUITE/tests/functional/acl/acl_common.kshlib
+
+#
+# DESCRIPTION:
+#	Verifies ability to find files with attribute with -xattr flag and using
+#	"-exec runat ls".
+#
+# STRATEGY:
+#	1. In directory A, create several files and add attribute files for them
+#	2. Verify all the specified files can be found with '-xattr',
+#	3. Verify all the attribute files can be found with '-exec runat ls'
+#
+
+verify_runnable "both"
+
+log_assert "Verifies ability to find files with attribute with" \
+		"-xattr flag and using '-exec runat ls'"
+log_onexit cleanup
+
+for user in root $ZFS_ACL_STAFF1; do
+	log_must set_cur_usr $user
+
+	log_must create_files $TESTDIR
+	initfiles=$($LS -R $INI_DIR/*)
+
+	typeset -i i=0
+	while (( i < NUM_FILE )); do
+		f=$(getitem $i $initfiles)
+		ff=$(usr_exec $FIND $INI_DIR -type f -name ${f##*/} \
+			-xattr -print)
+		if [[ $ff != $f ]]; then
+			log_fail "find file containing attribute fail."
+		else
+			log_note "find $f by '-xattr'."
+		fi
+
+		typeset -i j=0
+		while (( j < NUM_ATTR )); do
+			typeset af=attribute.$j
+			fa=$(usr_exec $FIND $INI_DIR -type f -name ${f##*/} \
+				-xattr -exec runat {} ls $af \\\;)
+			if [[ $fa != $af ]]; then
+				log_fail "find file attribute fail"
+			fi
+			(( j += 1 ))
+		done
+		(( i += 1 ))
+		log_note "find all attribute files of $f"
+	done
+
+	log_must cleanup
+done
+
+log_pass "find files with -xattr passed."
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/usr/src/test/zfs-tests/tests/functional/acl/trivial/zfs_acl_find_002_neg.ksh	Wed Dec 05 22:04:50 2012 -0500
@@ -0,0 +1,87 @@
+#!/bin/ksh -p
+#
+# CDDL HEADER START
+#
+# The contents of this file are subject to the terms of the
+# Common Development and Distribution License (the "License").
+# You may not use this file except in compliance with the License.
+#
+# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
+# or http://www.opensolaris.org/os/licensing.
+# See the License for the specific language governing permissions
+# and limitations under the License.
+#
+# When distributing Covered Code, include this CDDL HEADER in each
+# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
+# If applicable, add the following below this CDDL HEADER, with the
+# fields enclosed by brackets "[]" replaced with your own identifying
+# information: Portions Copyright [yyyy] [name of copyright owner]
+#
+# CDDL HEADER END
+#
+
+#
+# Copyright 2007 Sun Microsystems, Inc.  All rights reserved.
+# Use is subject to license terms.
+#
+
+. $STF_SUITE/tests/functional/acl/acl_common.kshlib
+
+#
+# DESCRIPTION:
+#	Verifies ability to find files with attribute with -xattr flag and using
+#	"-exec runat ls".
+#
+# STRATEGY:
+#	1. In directory A, create several files and add attribute files for them
+#	2. Delete all the attribute files.
+#	2. Verify all the specified files can not be found with '-xattr',
+#	3. Verify all the attribute files can not be found with '-exec runat ls'
+#
+
+verify_runnable "both"
+
+log_assert "verifies -xattr doesn't include files without " \
+		"attribute and using '-exec runat ls'"
+log_onexit cleanup
+
+for user in root $ZFS_ACL_STAFF1; do
+	log_must set_cur_usr $user
+
+	log_must create_files $TESTDIR
+
+	initfiles=$($LS -R $INI_DIR/*)
+	typeset -i i=0
+	while (( i < NUM_FILE )); do
+		f=$(getitem $i $initfiles)
+		usr_exec $RUNAT $f $RM attribute*
+		(( i += 1 ))
+	done
+
+	i=0
+	while (( i < NUM_FILE )); do
+		f=$(getitem $i $initfiles)
+		ff=$(usr_exec $FIND $INI_DIR -type f -name ${f##*/} \
+			-xattr -print)
+		if [[ $ff == $f ]]; then
+			log_fail "find not containing attribute should fail."
+		fi
+
+		typeset -i j=0
+		while (( j < NUM_ATTR )); do
+			fa=$(usr_exec $FIND $INI_DIR -type f -name ${f##*/} \
+				-xattr -exec $RUNAT {} $LS attribute.$j \\\;)
+			if [[ $fa == attribute.$j ]]; then
+				log_fail "find file attribute should fail."
+			fi
+			(( j += 1 ))
+		done
+		log_note "Failed to find $f and its attribute file as expected."
+
+		(( i += 1 ))
+	done
+
+	log_must cleanup
+done
+
+log_pass "find files which have no attrabute files with -xattr passed."
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/usr/src/test/zfs-tests/tests/functional/acl/trivial/zfs_acl_ls_001_pos.ksh	Wed Dec 05 22:04:50 2012 -0500
@@ -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.
+#
+
+. $STF_SUITE/tests/functional/acl/acl_common.kshlib
+
+#
+# DESCRIPTION:
+#	Verifies that ls displays @ in the file permissions using ls -@
+#	for files with attribute.
+#
+# STRATEGY:
+#	1. Create files with attribute files in directory A.
+#	2. Verify 'ls -l' can display @ in file permissions.
+#
+
+verify_runnable "both"
+
+log_assert "Verifies that ls displays @ in the file permissions using ls -@ " \
+	"for files with attribute."
+log_onexit cleanup
+
+for user in root $ZFS_ACL_STAFF1; do
+	log_must set_cur_usr $user
+
+	log_must create_files $TESTDIR
+
+	initfiles=$($LS -R $INI_DIR/*)
+	typeset -i i=0
+	while (( i < NUM_FILE )); do
+		f=$(getitem $i $initfiles)
+		ls_attr=$(usr_exec $LS -@ $f | $AWK '{print substr($1, 11, 1)}')
+		if [[ $ls_attr != "@" ]]; then
+			log_fail "ls -@ $f with attribute should success."
+		else
+			log_note "ls -@ $f with attribute success."
+		fi
+
+		(( i += 1 ))
+	done
+
+	log_must cleanup
+done
+
+log_pass "ls display @ in file permission passed."
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/usr/src/test/zfs-tests/tests/functional/acl/trivial/zfs_acl_ls_002_neg.ksh	Wed Dec 05 22:04:50 2012 -0500
@@ -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.
+#
+
+. $STF_SUITE/tests/functional/acl/acl_common.kshlib
+
+#
+# DESCRIPTION:
+#	Verifies that ls doesn't display @ in the file permissions using ls -@
+#	for files without attribute.
+#
+# STRATEGY:
+#	1. Create files with attribute files in directory A.
+#	2. Removed all attribute files.
+#	3. Verify 'ls -l' can't display @ in file permission.
+#
+
+verify_runnable "both"
+
+log_assert  "Verifies that ls doesn't display @ in the file " \
+	"permissions using ls -@ for files without attribute."
+log_onexit cleanup
+
+for user in root $ZFS_ACL_STAFF1; do
+	log_must set_cur_usr $user
+
+	log_must create_files $TESTDIR
+
+	initfiles=$($LS -R $INI_DIR/*)
+	typeset -i i=0
+	while (( i < NUM_FILE )); do
+		f=$(getitem $i $initfiles)
+		log_must usr_exec $RUNAT $f $RM attribute*
+
+		ls_attr=$(usr_exec $LS -l $f | $AWK '{print substr($1, 11, 1)}')
+		if [[ $ls_attr == "@" ]]; then
+			log_fail "ls with attribute shouldn't success."
+		fi
+
+		(( i += 1 ))
+	done
+
+	log_must cleanup
+done
+
+log_pass "ls doesn't display @ in file permissions passed."
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/usr/src/test/zfs-tests/tests/functional/acl/trivial/zfs_acl_mv_001_pos.ksh	Wed Dec 05 22:04:50 2012 -0500
@@ -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.
+#
+
+. $STF_SUITE/tests/functional/acl/acl_common.kshlib
+
+#
+# DESCRIPTION:
+#	Verifies that mv will include file attribute.
+#
+# STRATEGY:
+#	1. In directory A, create several files and add attribute files for them
+#	2. Save all files and their attribute files cksum value
+#	3. Move them to another directory B.
+#	4. Calculate all the files and attribute files cksum
+#	5. Verify all the cksum are identical
+#
+
+verify_runnable "both"
+
+log_assert "Verifies that mv will include file attribute."
+log_onexit cleanup
+
+set -A BEFORE_FCKSUM
+set -A BEFORE_ACKSUM
+set -A AFTER_FCKSUM
+set -A AFTER_ACKSUM
+
+for user in root $ZFS_ACL_STAFF1; do
+	log_must set_cur_usr $user
+
+	log_must create_files $TESTDIR
+
+	log_must cksum_files $INI_DIR BEFORE_FCKSUM BEFORE_ACKSUM
+	log_must usr_exec $MV $INI_DIR/* $TST_DIR
+	log_must cksum_files $TST_DIR AFTER_FCKSUM AFTER_ACKSUM
+
+	log_must compare_cksum BEFORE_FCKSUM AFTER_FCKSUM
+	log_must compare_cksum BEFORE_ACKSUM AFTER_ACKSUM
+
+	log_must cleanup
+done
+
+log_pass "mv file include attribute passed."
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/usr/src/test/zfs-tests/tests/functional/acl/trivial/zfs_acl_pack_001_pos.ksh	Wed Dec 05 22:04:50 2012 -0500
@@ -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.
+#
+
+. $STF_SUITE/tests/functional/acl/acl_common.kshlib
+
+#
+# DESCRIPTION:
+#	Verifies that pack will keep file attribute intact afterthe file is
+#	packed and unpacked.
+#
+# STRATEGY:
+#	1. In directory A, create several files and add attribute files for them
+#	2. Save all files and their attribute files cksum value, then pack
+#	   all the files.
+#	3. Move them to another directory B.
+#	4. Unpack them and calculate all the files and attribute files cksum
+#	5. Verify all the cksum are identical
+#
+
+verify_runnable "both"
+
+log_assert "Verifies that pack will keep file attribute intact after the file "\
+	"is packed and unpacked"
+log_onexit cleanup
+
+set -A BEFORE_FCKSUM
+set -A BEFORE_ACKSUM
+set -A AFTER_FCKSUM
+set -A AFTER_ACKSUM
+
+for user in root $ZFS_ACL_STAFF1; do
+	log_must set_cur_usr $user
+
+	log_must create_files $TESTDIR
+
+	log_must cksum_files $INI_DIR BEFORE_FCKSUM BEFORE_ACKSUM
+	log_must eval "usr_exec $PACK -f $INI_DIR/* > /dev/null 2>&1"
+	log_must usr_exec $MV $INI_DIR/* $TST_DIR
+	log_must eval "usr_exec $UNPACK $TST_DIR/* > /dev/null 2>&1"
+	log_must cksum_files $TST_DIR AFTER_FCKSUM AFTER_ACKSUM
+
+	log_must compare_cksum BEFORE_FCKSUM AFTER_FCKSUM
+	log_must compare_cksum BEFORE_ACKSUM AFTER_ACKSUM
+
+	log_must cleanup
+done
+
+log_pass "pack/unpack test passed."
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/usr/src/test/zfs-tests/tests/functional/acl/trivial/zfs_acl_pax_001_pos.ksh	Wed Dec 05 22:04:50 2012 -0500
@@ -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.
+#
+
+. $STF_SUITE/tests/functional/acl/acl_common.kshlib
+
+#
+# DESCRIPTION:
+#	Verify directories include attribute in pax archive and restore with pax
+#	should succeed.
+#
+# STRATEGY:
+#	1. Use mktree create a set of directories in directory A.
+#	2. Enter into directory A and record all directory information.
+#	3. pax all the files to directory B.
+#	4. Then pax the pax file to directory C.
+#	5. Record all the directories informat in derectory C.
+#	6. Verify the two records should be identical.
+#
+
+verify_runnable "both"
+
+log_assert "Verify include attribute in pax archive and restore with pax " \
+	"should succeed."
+log_onexit cleanup
+
+for user in root $ZFS_ACL_STAFF1; do
+	log_must set_cur_usr $user
+
+	[[ ! -d $INI_DIR ]] && log_must usr_exec $MKDIR -m 777 -p $INI_DIR
+	log_must usr_exec $MKTREE -b $INI_DIR -l 6 -d 2 -f 2
+
+	#
+	# Enter into initial directory and record all directory information,
+	# then pax all the files to $TMP_DIR/files.pax.
+	#
+	[[ ! -d $TMP_DIR ]] && log_must usr_exec $MKDIR $TMP_DIR
+	initout=$TMP_DIR/initout.$$
+	paxout=$TMP_DIR/files.pax
+
+	cd $INI_DIR
+	log_must eval "record_cksum $INI_DIR $initout > /dev/null 2>&1"
+	log_must eval "usr_exec $PAX -w -@ -f $paxout * > /dev/null 2>&1"
+
+	#
+	# Enter into test directory and pax $TMP_DIR/files.pax to current
+	# directory. Record all directory information and compare with initial
+	# directory record.
+	#
+	[[ ! -d $TST_DIR ]] && log_must usr_exec $MKDIR -m 777 $TST_DIR
+	testout=$TMP_DIR/testout.$$
+	cd $TST_DIR
+	log_must eval "usr_exec $PAX -r -@ -f $paxout > /dev/null 2>&1"
+	log_must eval "record_cksum $TST_DIR $testout > /dev/null 2>&1"
+
+	log_must usr_exec $DIFF $initout $testout
+
+	log_must cleanup
+done
+
+log_pass "Directories pax archive and restre with pax passed."
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/usr/src/test/zfs-tests/tests/functional/acl/trivial/zfs_acl_pax_002_pos.ksh	Wed Dec 05 22:04:50 2012 -0500
@@ -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.
+#
+
+. $STF_SUITE/tests/functional/acl/acl_common.kshlib
+
+#
+# DESCRIPTION:
+#	Verify directories which include attribute in pax archive and restore
+#	with tar should succeed.
+#
+# STRATEGY:
+#	1. Use mktree create a set of directories in directory A.
+#	2. Enter into directory A and record all directory information.
+#	3. pax all the files to directory B.
+#	4. Then tar the pax file to directory C.
+#	5. Record all the directories informat in derectory C.
+#	6. Verify the two records should be identical.
+#
+
+verify_runnable "both"
+
+log_assert "Verify include attribute in pax archive and restore with tar " \
+	"should succeed."
+log_onexit cleanup
+
+for user in root $ZFS_ACL_STAFF1; do
+	log_must set_cur_usr $user
+
+	[[ ! -d $INI_DIR ]] && log_must usr_exec $MKDIR -m 777 $INI_DIR
+	log_must usr_exec $MKTREE -b $INI_DIR -l 6 -d 2 -f 2
+
+	#
+	# Enter into initial directory and record all directory information,
+	# then pax all the files to $TMP_DIR/files.pax.
+	#
+	[[ ! -d $TMP_DIR ]] && log_must usr_exec $MKDIR -m 777 $TMP_DIR
+	initout=$TMP_DIR/initout.$$
+	paxout=$TMP_DIR/files.tar
+	cd $INI_DIR
+	log_must eval "record_cksum $INI_DIR $initout > /dev/null 2>&1"
+	log_must eval "usr_exec $PAX -w -x ustar -@ -f $paxout *>/dev/null 2>&1"
+
+	#
+	# Enter into test directory and tar $TMP_DIR/files.pax to current
+	# directory. Record all directory information and compare with initial
+	# directory record.
+	#
+	[[ ! -d $TST_DIR ]] && log_must usr_exec $MKDIR -m 777 $TST_DIR
+	testout=$TMP_DIR/testout.$$
+	cd $TST_DIR
+	log_must eval "usr_exec $TAR xpf@ $paxout > /dev/null 2>&1"
+	log_must eval "record_cksum $TST_DIR $testout > /dev/null 2>&1"
+
+	log_must usr_exec $DIFF $initout $testout
+
+	log_must cleanup
+done
+
+log_pass "Directories pax archive and restore with pax passed."
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/usr/src/test/zfs-tests/tests/functional/acl/trivial/zfs_acl_pax_003_pos.ksh	Wed Dec 05 22:04:50 2012 -0500
@@ -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.
+#
+
+. $STF_SUITE/tests/functional/acl/acl_common.kshlib
+
+#
+# DESCRIPTION:
+#	Verify directories which include attribute in pax archive and restore
+#	with cpio should succeed.
+#
+# STRATEGY:
+#	1. Create several files in directory A.
+#	2. Enter into directory A and record all directory cksum.
+#	3. pax all the files to directory B.
+#	4. Then cpio the pax file to directory C.
+#	5. Record all the files cksum in derectory C.
+#	6. Verify the two records should be identical.
+#
+
+verify_runnable "both"
+
+log_assert "Verify include attribute in pax archive and restore with cpio " \
+	"should succeed."
+log_onexit cleanup
+
+for user in root $ZFS_ACL_STAFF1; do
+	log_must set_cur_usr $user
+
+	[[ ! -d $INI_DIR ]] && log_must usr_exec $MKDIR -m 777 -p $INI_DIR
+	log_must usr_exec $MKTREE -b $INI_DIR -l 6 -d 2 -f 2
+
+	initout=$TMP_DIR/initout.$$
+	paxout=$TMP_DIR/files.cpio
+	cd $INI_DIR
+	log_must eval "record_cksum $INI_DIR $initout > /dev/null 2>&1"
+	log_must eval "usr_exec $PAX -w -x cpio -@ -f $paxout * >/dev/null 2>&1"
+
+	#
+	# Enter into test directory and cpio $TMP_DIR/files.pax to current
+	# directory. Record all directory information and compare with initial
+	# directory record.
+	#
+	[[ ! -d $TST_DIR ]] && log_must usr_exec $MKDIR -m 777 $TST_DIR
+	testout=$TMP_DIR/testout.$$
+	cd $TST_DIR
+	log_must eval "usr_exec $CPIO -ivd@ < $paxout" > /dev/null 2>&1
+	log_must eval "record_cksum $TST_DIR $testout > /dev/null 2>&1"
+
+	log_must usr_exec $DIFF $initout $testout
+
+	log_must cleanup
+done
+
+log_pass "Directories pax archive and restore with cpio passed."
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/usr/src/test/zfs-tests/tests/functional/acl/trivial/zfs_acl_pax_004_pos.ksh	Wed Dec 05 22:04:50 2012 -0500
@@ -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.
+#
+
+. $STF_SUITE/tests/functional/acl/acl_common.kshlib
+
+#
+# DESCRIPTION:
+#	Verify files include attribute in pax archive and restore with pax
+#	should succeed.
+#
+# STRATEGY:
+#	1. Create several files which contains contribute files in directory A.
+#	2. Enter into directory A and record all files cksum.
+#	3. pax all the files to directory B.
+#	4. Then pax the pax file to directory C.
+#	5. Record all the files cksum in derectory C.
+#	6. Verify the two records should be identical.
+#
+
+verify_runnable "both"
+
+log_assert "Verify files include attribute in pax archive and restore with pax " \
+	"should succeed."
+log_onexit cleanup
+
+set -A BEFORE_FCKSUM
+set -A BEFORE_ACKSUM
+set -A AFTER_FCKSUM
+set -A AFTER_ACKSUM
+
+for user in root $ZFS_ACL_STAFF1; do
+	log_must set_cur_usr $user
+
+	log_must create_files $TESTDIR
+
+	#
+	# Enter into initial directory and record all files cksum,
+	# then pax all the files to $TMP_DIR/files.pax.
+	#
+	paxout=$TMP_DIR/files.pax
+	cd $INI_DIR
+	log_must cksum_files $INI_DIR BEFORE_FCKSUM BEFORE_ACKSUM
+	log_must eval "usr_exec $PAX -w -@ -f $paxout * > /dev/null 2>&1"
+
+	#
+	# Enter into test directory and pax $TMP_DIR/files.pax to current
+	# directory. Record all directory information and compare with initial
+	# directory record.
+	#
+	cd $TST_DIR
+	log_must eval "usr_exec $PAX -r -@ -f $paxout > /dev/null 2>&1"
+	log_must cksum_files $TST_DIR AFTER_FCKSUM AFTER_ACKSUM
+
+	log_must compare_cksum BEFORE_FCKSUM AFTER_FCKSUM
+	log_must compare_cksum BEFORE_ACKSUM AFTER_ACKSUM
+
+	log_must cleanup
+done
+
+log_pass "Files pax archive and restre with pax passed."
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/usr/src/test/zfs-tests/tests/functional/acl/trivial/zfs_acl_pax_005_pos.ksh	Wed Dec 05 22:04:50 2012 -0500
@@ -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.
+#
+
+. $STF_SUITE/tests/functional/acl/acl_common.kshlib
+
+#
+# DESCRIPTION:
+#	Verify files include attribute in cpio archive and restore with cpio
+#	should succeed.
+#
+# STRATEGY:
+#	1. Create several files which contains contribute files in directory A.
+#	2. Enter into directory A and record all files cksum.
+#	3. pax all the files to directory B.
+#	4. Then pax the pax file to directory C.
+#	5. Record all the files cksum in derectory C.
+#	6. Verify the two records should be identical.
+#
+
+verify_runnable "both"
+
+log_assert "Verify files include attribute in cpio archive and restore with " \
+	"cpio should succeed."
+log_onexit cleanup
+
+set -A BEFORE_FCKSUM
+set -A BEFORE_ACKSUM
+set -A AFTER_FCKSUM
+set -A AFTER_ACKSUM
+
+for user in root $ZFS_ACL_STAFF1; do
+	log_must set_cur_usr $user
+
+	log_must create_files $TESTDIR
+
+	#
+	# Enter into initial directory and record all files cksum,
+	# then pax all the files to $TMP_DIR/files.pax.
+	#
+	paxout=$TMP_DIR/files.cpio
+	cd $INI_DIR
+	log_must cksum_files $INI_DIR BEFORE_FCKSUM BEFORE_ACKSUM
+	log_must eval "usr_exec $PAX -w -x cpio -@ -f $paxout * >/dev/null 2>&1"
+
+	#
+	# Enter into test directory and pax $TMP_DIR/files.cpio to current
+	# directory. Record all directory information and compare with initial
+	# directory record.
+	#
+	cd $TST_DIR
+	log_must eval "usr_exec $PAX -r -x cpio -@ -f $paxout > /dev/null 2>&1"
+	log_must cksum_files $TST_DIR AFTER_FCKSUM AFTER_ACKSUM
+
+	log_must compare_cksum BEFORE_FCKSUM AFTER_FCKSUM
+	log_must compare_cksum BEFORE_ACKSUM AFTER_ACKSUM
+
+	log_must usr_exec $RM -rf *
+	log_must eval "usr_exec $CPIO -iv@ < $paxout > /dev/null 2>&1"
+	log_must cksum_files $TST_DIR AFTER_FCKSUM AFTER_ACKSUM
+
+	log_must compare_cksum BEFORE_FCKSUM AFTER_FCKSUM
+	log_must compare_cksum BEFORE_ACKSUM AFTER_ACKSUM
+
+	log_must cleanup
+done
+
+log_pass "Files 'pax cpio' archive and restre with 'pax cpio' passed."
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/usr/src/test/zfs-tests/tests/functional/acl/trivial/zfs_acl_pax_006_pos.ksh	Wed Dec 05 22:04:50 2012 -0500
@@ -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.
+#
+
+. $STF_SUITE/tests/functional/acl/acl_common.kshlib
+
+#
+# DESCRIPTION:
+#	Verify files include attribute in tar archive and restore with tar
+#	should succeed.
+#
+# STRATEGY:
+#	1. Create several files which contains contribute files in directory A.
+#	2. Enter into directory A and record all files cksum.
+#	3. 'pax ustar' all the files to directory B.
+#	4. Then 'pax ustar' the pax file to directory C.
+#	5. Record all the files cksum in derectory C.
+#	6. Verify the two records should be identical.
+#
+
+verify_runnable "both"
+
+log_assert "Verify files include attribute in tar archive and restore with " \
+	"tar should succeed."
+log_onexit cleanup
+
+set -A BEFORE_FCKSUM
+set -A BEFORE_ACKSUM
+set -A AFTER_FCKSUM
+set -A AFTER_ACKSUM
+
+for user in root $ZFS_ACL_STAFF1; do
+	log_must set_cur_usr $user
+
+	log_must create_files $TESTDIR
+
+	#
+	# Enter into initial directory and record all files cksum,
+	# then pax all the files to $TMP_DIR/files.pax.
+	#
+	paxout=$TMP_DIR/files.tar
+	cd $INI_DIR
+	log_must cksum_files $INI_DIR BEFORE_FCKSUM BEFORE_ACKSUM
+	log_must eval "usr_exec $PAX -w -x ustar -@ -f $paxout *>/dev/null 2>&1"
+
+	#
+	# Enter into test directory and pax $TMP_DIR/files.tar to current
+	# directory. Record all directory information and compare with initial
+	# directory record.
+	#
+	cd $TST_DIR
+	log_must eval "usr_exec $PAX -r -x ustar -@ -f $paxout > /dev/null 2>&1"
+	log_must cksum_files $TST_DIR AFTER_FCKSUM AFTER_ACKSUM
+
+	log_must compare_cksum BEFORE_FCKSUM AFTER_FCKSUM
+	log_must compare_cksum BEFORE_ACKSUM AFTER_ACKSUM
+
+	log_must usr_exec $RM -rf *
+	log_must usr_exec $TAR xf@ $paxout
+	log_must cksum_files $TST_DIR AFTER_FCKSUM AFTER_ACKSUM
+
+	log_must compare_cksum BEFORE_FCKSUM AFTER_FCKSUM
+	log_must compare_cksum BEFORE_ACKSUM AFTER_ACKSUM
+
+	log_must cleanup
+done
+
+log_pass "Files 'pax tar' archive and restre with 'pax tar' passed."
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/usr/src/test/zfs-tests/tests/functional/acl/trivial/zfs_acl_tar_001_pos.ksh	Wed Dec 05 22:04:50 2012 -0500
@@ -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.
+#
+
+. $STF_SUITE/tests/functional/acl/acl_common.kshlib
+
+#
+# DESCRIPTION:
+#	Verifies that tar will include file attribute when @ flag is present.
+#
+# STRATEGY:
+#	1. Use mktree create a set of directories in directory A.
+#	2. Enter into directory A and record all directory information.
+#	3. tar all the files to directory B.
+#	4. Then tar the tar file to directory C.
+#	5. Record all the directories informat in derectory C.
+#	6. Verify the two records should be identical.
+#
+
+verify_runnable "both"
+
+log_assert "Verifies that tar will include file attribute when @ flag is " \
+	"present."
+log_onexit cleanup
+
+for user in root $ZFS_ACL_STAFF1; do
+	log_must set_cur_usr $user
+
+	[[ ! -d $INI_DIR ]] && $MKDIR -m 777 -p $INI_DIR
+	log_must usr_exec $MKTREE -b $INI_DIR -l 5 -d 2 -f 2
+
+	#
+	# Enter into initial directory and record all directory information,
+	# then tar all the files to $TMP_DIR/files.tar.
+	#
+	[[ ! -d $TMP_DIR ]] && usr_exec $MKDIR $TMP_DIR
+	initout=$TMP_DIR/initout.$$
+	tarout=$TMP_DIR/files.tar
+	cd $INI_DIR
+	log_must record_cksum $INI_DIR $initout
+	log_must usr_exec $TAR cpf@ $tarout *
+
+	#
+	# Enter into test directory and tar $TMP_DIR/files.tar to current
+	# directory. Record all directory information and compare with initial
+	# directory record.
+	#
+	[[ ! -d $TST_DIR ]] && $MKDIR -m 777 $TST_DIR
+	testout=$TMP_DIR/testout.$$
+	cd $TST_DIR
+	log_must usr_exec $TAR xpf@ $tarout
+	log_must record_cksum $TST_DIR $testout
+
+	log_must usr_exec $DIFF $initout $testout
+
+	log_must cleanup
+done
+
+log_pass "Verify tar with @ passed."
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/usr/src/test/zfs-tests/tests/functional/acl/trivial/zfs_acl_tar_002_neg.ksh	Wed Dec 05 22:04:50 2012 -0500
@@ -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 2007 Sun Microsystems, Inc.  All rights reserved.
+# Use is subject to license terms.
+#
+
+. $STF_SUITE/tests/functional/acl/acl_common.kshlib
+
+#
+# DESCRIPTION:
+#	Verifies that tar will not include files attribute when @ flag is not
+#	present.
+#
+# STRATEGY:
+#	1. Create several files with attribute files.
+#	2. Enter into directory A and record all files cksum
+#	3. tar all the files to directory B.
+#	4. Then tar the tar file to directory C.
+#	5. Record all the files cksum in derectory C.
+#	6. Verify the two records should be not identical.
+#
+
+verify_runnable "both"
+
+log_assert "Verifies that tar will not include files attribute when @ flag is "\
+	"not present"
+log_onexit cleanup
+
+set -A BEFORE_FCKSUM
+set -A BEFORE_ACKSUM
+set -A AFTER_FCKSUM
+set -A AFTER_ACKSUM
+
+for user in root $ZFS_ACL_STAFF1; do
+	log_must set_cur_usr $user
+
+	log_must create_files $TESTDIR
+
+	#
+	# Enter into initial directory and record all directory information,
+	# then tar all the files to $TMP_DIR/files.tar.
+	#
+	tarout=$TMP_DIR/files.tar
+	cd $INI_DIR
+	log_must cksum_files $INI_DIR BEFORE_FCKSUM BEFORE_ACKSUM
+	log_must usr_exec $TAR cpf $tarout *
+
+	#
+	# Enter into test directory and tar $TMP_DIR/files.tar to current
+	# directory. Record all directory information and compare with initial
+	# directory record.
+	#
+	cd $TST_DIR
+	log_must usr_exec $CP $tarout $TST_DIR
+	log_must usr_exec $TAR xpf $tarout
+
+	testfiles=$($LS -R $TST_DIR/*)
+	typeset -i i=0
+	while (( i < NUM_FILE )); do
+		f=$(getitem $i $testfiles)
+		ls_attr=$($LS -@ $f | $AWK '{print substr($1, 11, 1)}')
+		if [[ $ls_attr == "@" ]]; then
+			log_fail "extraction of attribute successful w/ -@ flag"
+		fi
+
+		(( i += 1 ))
+	done
+
+	log_must cksum_files $TST_DIR AFTER_FCKSUM AFTER_ACKSUM
+
+	log_must compare_cksum BEFORE_FCKSUM AFTER_FCKSUM
+	log_mustnot compare_cksum BEFORE_ACKSUM AFTER_ACKSUM
+
+	log_must cleanup
+done
+
+log_pass "Verify tar without @ passed."
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/usr/src/test/zfs-tests/tests/functional/atime/Makefile	Wed Dec 05 22:04:50 2012 -0500
@@ -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) 2012 by Delphix. All rights reserved.
+#
+
+include $(SRC)/Makefile.master
+
+ROOTOPTPKG = $(ROOT)/opt/zfs-tests
+TESTDIR = $(ROOTOPTPKG)/tests/functional/atime
+
+PROGS = cleanup \
+	setup \
+	atime_001_pos \
+	atime_002_neg
+
+FILES = atime.cfg \
+	atime_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	Thu Jan 01 00:00:00 1970 +0000
+++ b/usr/src/test/zfs-tests/tests/functional/atime/atime.cfg	Wed Dec 05 22:04:50 2012 -0500
@@ -0,0 +1,30 @@
+#
+# CDDL HEADER START
+#
+# The contents of this file are subject to the terms of the
+# Common Development and Distribution License (the "License").
+# You may not use this file except in compliance with the License.
+#
+# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
+# or http://www.opensolaris.org/os/licensing.
+# See the License for the specific language governing permissions
+# and limitations under the License.
+#
+# When distributing Covered Code, include this CDDL HEADER in each
+# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
+# If applicable, add the following below this CDDL 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.
+#
+
+export TESTCLONE=testclone$$
+export TESTSNAP=testsnap$$
+
+export TESTFILE=testfile
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/usr/src/test/zfs-tests/tests/functional/atime/atime_001_pos.ksh	Wed Dec 05 22:04:50 2012 -0500
@@ -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.
+#
+
+. $STF_SUITE/tests/functional/atime/atime_common.kshlib
+
+#
+# DESCRIPTION:
+# When atime=on, verify the access time for files is updated when read. It
+# is available to fs and clone. To snapshot, it is unavailable.
+#
+# STRATEGY:
+# 1. Create pool and fs.
+# 2. Create '$TESTFILE' for fs.
+# 3. Create snapshot and clone.
+# 4. Setting atime=on on datasets except snapshot, and read '$TESTFILE'.
+# 5. Expect the access time is updated on datasets except snapshot.
+#
+
+verify_runnable "both"
+
+log_assert "Setting atime=on, the access time for files is updated when read."
+log_onexit cleanup
+
+#
+# Create $TESTFILE, snapshot and clone.
+#
+setup_snap_clone
+
+for dst in $TESTPOOL/$TESTFS $TESTPOOL/$TESTCLONE $TESTPOOL/$TESTFS@$TESTSNAP
+do
+	typeset mtpt=$(get_prop mountpoint $dst)
+
+	if [[ $dst == $TESTPOOL/$TESTFS@$TESTSNAP ]]; then
+		mtpt=$(snapshot_mountpoint $dst)
+		log_mustnot check_atime_updated $mtpt/$TESTFILE
+	else
+		log_must $ZFS set atime=on $dst
+		log_must check_atime_updated $mtpt/$TESTFILE
+	fi
+done
+
+log_pass "Verify the property atime=on passed."
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/usr/src/test/zfs-tests/tests/functional/atime/atime_002_neg.ksh	Wed Dec 05 22:04:50 2012 -0500
@@ -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.
+#
+
+. $STF_SUITE/tests/functional/atime/atime_common.kshlib
+
+#
+# DESCRIPTION:
+# When atime=off, verify the access time for files is not updated when read.
+# It is available to pool, fs snapshot and clone.
+#
+# STRATEGY:
+# 1. Create pool, fs.
+# 2. Create '$TESTFILE' for fs.
+# 3. Create snapshot and clone.
+# 4. Setting atime=off on dataset and read '$TESTFILE'.
+# 5. Verify the access time is not updated.
+#
+
+verify_runnable "both"
+
+log_assert "Setting atime=off, the access time for files will not be updated \
+	when read."
+log_onexit cleanup
+
+#
+# Create $TESTFILE, snapshot and clone.
+#
+setup_snap_clone
+
+for dst in $TESTPOOL/$TESTFS $TESTPOOL/$TESTCLONE $TESTPOOL/$TESTFS@$TESTSNAP
+do
+	typeset mtpt=$(get_prop mountpoint $dst)
+
+	if [[ $dst == $TESTPOOL/$TESTFS@$TESTSNAP ]]; then
+		mtpt=$(snapshot_mountpoint $dst)
+	else
+		log_must $ZFS set atime=off $dst
+	fi
+
+	log_mustnot check_atime_updated $mtpt/$TESTFILE
+done
+
+log_pass "Verify the property atime=off passed."
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/usr/src/test/zfs-tests/tests/functional/atime/atime_common.kshlib	Wed Dec 05 22:04:50 2012 -0500
@@ -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.
+#
+
+. $STF_SUITE/tests/functional/atime/atime.cfg
+. $STF_SUITE/include/libtest.shlib
+
+#
+# Check if the access time for specified file is updated.
+#
+# $1 Given an absolute path to a file name
+#
+# Return value:
+#	0 -> The access time is updated.
+#	1 -> The access time is not updated.
+#
+function check_atime_updated
+{
+	typeset filename=$1
+
+	typeset before=$($LS -Eu $filename | $AWK '{print $7}')
+	log_must $CAT $filename
+	typeset after=$($LS -Eu $filename | $AWK '{print $7}')
+
+	if [[ $before != $after ]]; then
+		return 0
+	else
+		return 1
+	fi
+}
+
+function setup_snap_clone
+{
+	# Create two file to verify snapshot.
+	log_must $TOUCH $TESTDIR/$TESTFILE
+
+	create_snapshot $TESTPOOL/$TESTFS $TESTSNAP
+	create_clone $TESTPOOL/$TESTFS@$TESTSNAP $TESTPOOL/$TESTCLONE
+}
+
+function cleanup
+{
+	destroy_clone $TESTPOOL/$TESTCLONE
+	destroy_snapshot $TESTPOOL/$TESTFS@$TESTSNAP
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/usr/src/test/zfs-tests/tests/functional/atime/cleanup.ksh	Wed Dec 05 22:04:50 2012 -0500
@@ -0,0 +1,30 @@
+#!/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.
+#
+
+. $STF_SUITE/include/libtest.shlib
+
+default_cleanup
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/usr/src/test/zfs-tests/tests/functional/atime/setup.ksh	Wed Dec 05 22:04:50 2012 -0500
@@ -0,0 +1,31 @@
+#!/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.
+#
+
+. $STF_SUITE/include/libtest.shlib
+
+DISK=${DISKS%% *}
+default_setup $DISK
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/usr/src/test/zfs-tests/tests/functional/bootfs/Makefile	Wed Dec 05 22:04:50 2012 -0500
@@ -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) 2012 by Delphix. All rights reserved.
+#
+
+include $(SRC)/Makefile.master
+
+ROOTOPTPKG = $(ROOT)/opt/zfs-tests
+TESTDIR = $(ROOTOPTPKG)/tests/functional/bootfs
+
+PROGS = bootfs_001_pos \
+	bootfs_002_neg \
+	bootfs_003_pos \
+	bootfs_004_neg \
+	bootfs_005_neg \
+	bootfs_006_pos \
+	bootfs_007_neg \
+	bootfs_008_neg
+
+CMDS = $(PROGS:%=$(TESTDIR)/%)
+$(CMDS) := FILEMODE = 0555
+
+all lint clean clobber:
+
+install: $(CMDS)
+
+$(CMDS): $(TESTDIR)
+
+$(TESTDIR):
+	$(INS.dir)
+
+$(TESTDIR)/%.cfg: %.cfg
+	$(INS.file)
+
+$(TESTDIR)/%: %.ksh
+	$(INS.rename)
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/usr/src/test/zfs-tests/tests/functional/bootfs/bootfs_001_pos.ksh	Wed Dec 05 22:04:50 2012 -0500
@@ -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.
+#
+
+. $STF_SUITE/include/libtest.shlib
+
+#
+# DESCRIPTION:
+#
+# Valid datasets are accepted as bootfs property values
+#
+# STRATEGY:
+# 1. Create a set of datasets in a test pool
+# 2. Try setting them as boot filesystems
+#
+
+verify_runnable "global"
+
+function cleanup {
+	if poolexists $TESTPOOL ; then
+		log_must $ZPOOL destroy $TESTPOOL
+	fi
+
+	if [[ -f $VDEV ]]; then
+		log_must $RM -f $VDEV
+	fi
+}
+
+$ZPOOL set 2>&1 | $GREP bootfs > /dev/null
+if [ $? -ne 0 ]
+then
+        log_unsupported "bootfs pool property not supported on this release."
+fi
+
+log_assert "Valid datasets are accepted as bootfs property values"
+log_onexit cleanup
+
+typeset VDEV=/bootfs_001_pos_a.$$.dat
+
+log_must $MKFILE 400m $VDEV
+create_pool "$TESTPOOL" "$VDEV"
+log_must $ZFS create $TESTPOOL/$TESTFS
+
+log_must $ZFS snapshot $TESTPOOL/$TESTFS@snap
+log_must $ZFS clone $TESTPOOL/$TESTFS@snap $TESTPOOL/clone
+
+log_must $ZPOOL set bootfs=$TESTPOOL/$TESTFS $TESTPOOL
+log_must $ZPOOL set bootfs=$TESTPOOL/clone $TESTPOOL
+
+log_must $ZFS promote $TESTPOOL/clone
+log_must $ZPOOL set bootfs=$TESTPOOL/clone $TESTPOOL
+log_pass "Valid datasets are accepted as bootfs property values"
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/usr/src/test/zfs-tests/tests/functional/bootfs/bootfs_002_neg.ksh	Wed Dec 05 22:04:50 2012 -0500
@@ -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.
+#
+
+. $STF_SUITE/include/libtest.shlib
+
+#
+# DESCRIPTION:
+#
+# Invalid datasets are rejected as boot property values
+#
+# STRATEGY:
+#
+# 1. Create a snapshot and a zvol
+# 2. Verify that we can't set the bootfs to those datasets
+#
+
+verify_runnable "global"
+
+function cleanup {
+	if snapexists $TESTPOOL/$TESTFS@snap
+	then
+		$ZFS destroy $TESTPOOL/$TESTFS@snap
+	fi
+	if datasetexists $TESTPOOL/$TESTFS
+	then
+		log_must $ZFS destroy $TESTPOOL/$TESTFS
+	fi
+	if datasetexists $TESTPOOL/vol
+	then
+		log_must $ZFS destroy $TESTPOOL/vol
+	fi
+	if poolexists $TESTPOOL
+	then
+		log_must $ZPOOL destroy $TESTPOOL
+	fi
+}
+
+
+$ZPOOL set 2>&1 | $GREP bootfs > /dev/null
+if [ $? -ne 0 ]
+then
+	log_unsupported "bootfs pool property not supported on this release."
+fi
+
+log_assert "Invalid datasets are rejected as boot property values"
+log_onexit cleanup
+
+DISK=${DISKS%% *}
+
+log_must $ZPOOL create $TESTPOOL $DISK
+log_must $ZFS create $TESTPOOL/$TESTFS
+log_must $ZFS snapshot $TESTPOOL/$TESTFS@snap
+log_must $ZFS create -V 10m $TESTPOOL/vol
+
+log_mustnot $ZPOOL set bootfs=$TESTPOOL/$TESTFS@snap $TESTPOOL
+log_mustnot $ZPOOL set bootfs=$TESTPOOL/vol $TESTPOOL
+
+log_pass "Invalid datasets are rejected as boot property values"
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/usr/src/test/zfs-tests/tests/functional/bootfs/bootfs_003_pos.ksh	Wed Dec 05 22:04:50 2012 -0500
@@ -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 2008 Sun Microsystems, Inc.  All rights reserved.
+# Use is subject to license terms.
+#
+
+. $STF_SUITE/include/libtest.shlib
+
+#
+# DESCRIPTION:
+#
+# Valid pool names are accepted
+#
+# STRATEGY:
+# 1. Using a list of valid pool names
+# 2. Create a filesystem in that pool
+# 2. Verify we can set the bootfs to that filesystem
+#
+
+verify_runnable "global"
+
+set -A pools "pool.$$" "pool123" "mypool"
+
+function cleanup {
+	if poolexists $POOL ; then
+		log_must $ZPOOL destroy $POOL
+	fi
+	$RM /bootfs_003.$$.dat
+}
+
+
+$ZPOOL set 2>&1 | $GREP bootfs > /dev/null
+if [ $? -ne 0 ]
+then
+        log_unsupported "bootfs pool property not supported on this release."
+fi
+
+log_onexit cleanup
+
+log_assert "Valid pool names are accepted by zpool set bootfs"
+$MKFILE 64m /bootfs_003.$$.dat
+
+typeset -i i=0;
+
+while [ $i -lt "${#pools[@]}" ]
+do
+	POOL=${pools[$i]}
+	log_must $ZPOOL create $POOL /bootfs_003.$$.dat
+	log_must $ZFS create $POOL/$TESTFS
+
+	log_must $ZPOOL set bootfs=$POOL/$TESTFS $POOL
+	RES=$($ZPOOL get bootfs $POOL | $TAIL -1 | $AWK '{print $3}' )
+	if [ $RES != "$POOL/$TESTFS" ]
+	then
+		log_fail "Expected $RES == $POOL/$TESTFS"
+	fi
+	log_must $ZPOOL destroy $POOL
+	i=$(( $i + 1 ))
+done
+
+log_pass "Valid pool names are accepted by zpool set bootfs"
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/usr/src/test/zfs-tests/tests/functional/bootfs/bootfs_004_neg.ksh	Wed Dec 05 22:04:50 2012 -0500
@@ -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.
+#
+
+. $STF_SUITE/include/libtest.shlib
+
+#
+# DESCRIPTION:
+#
+# Invalid pool names are rejected by zpool set bootfs
+#
+# STRATEGY:
+#	1. Try to set bootfs on some non-existent pools
+#
+#
+#
+
+verify_runnable "global"
+
+set -A pools "pool//$$" "pool%d123" "mirror" "c0t0d0s0" "pool*23*" "*po!l" \
+	"%s££%^"
+
+function cleanup {
+	if poolexists $POOL; then
+		log_must $ZPOOL destroy $POOL
+	fi
+	$RM /bootfs_004.$$.dat
+}
+
+
+$ZPOOL set 2>&1 | $GREP bootfs > /dev/null
+if [ $? -ne 0 ]
+then
+        log_unsupported "bootfs pool property not supported on this release."
+fi
+
+log_assert "Invalid pool names are rejected by zpool set bootfs"
+log_onexit cleanup
+
+# here, we build up a large string and add it to the list of pool names
+# a word to the ksh-wary, ${#array[@]} gives you the
+# total number of entries in an array, so array[${#array[@]}]
+# will index the last entry+1, ksh arrays start at index 0.
+COUNT=0
+while [ $COUNT -le 1025 ]
+do
+        bigname="${bigname}o"
+        COUNT=$(( $COUNT + 1 ))
+done
+pools[${#pools[@]}]="$bigname"
+
+
+
+$MKFILE 64m /bootfs_004.$$.dat
+
+typeset -i i=0;
+
+while [ $i -lt "${#pools[@]}" ]
+do
+	POOL=${pools[$i]}/$TESTFS
+	log_mustnot $ZPOOL create $POOL /bootfs_004.$$.dat
+	log_mustnot $ZFS create $POOL/$TESTFS
+	log_mustnot $ZPOOL set bootfs=$POOL/$TESTFS $POOL
+
+	i=$(( $i + 1 ))
+done
+
+log_pass "Invalid pool names are rejected by zpool set bootfs"
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/usr/src/test/zfs-tests/tests/functional/bootfs/bootfs_005_neg.ksh	Wed Dec 05 22:04:50 2012 -0500
@@ -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 2008 Sun Microsystems, Inc.  All rights reserved.
+# Use is subject to license terms.
+#
+
+. $STF_SUITE/include/libtest.shlib
+. $STF_SUITE/tests/functional/cli_root/zpool_upgrade/zpool_upgrade.kshlib
+
+#
+# DESCRIPTION:
+#
+# Boot properties cannot be set on pools with older versions
+#
+# STRATEGY:
+# 1. Copy and import some pools of older versions
+# 2. Create a filesystem on each
+# 3. Verify that zpool set bootfs fails on each
+#
+
+verify_runnable "global"
+
+function cleanup {
+
+	#
+	# we need destroy pools that created on top of $TESTPOOL first
+	#
+	typeset pool_name
+	for config in $CONFIGS; do
+		pool_name=$(eval $ECHO \$ZPOOL_VERSION_${config}_NAME)
+		if poolexists $pool_name; then
+			log_must $ZPOOL destroy $pool_name
+		fi
+	done
+
+	if poolexists $TESTPOOL ; then
+		log_must $ZPOOL destroy $TESTPOOL
+	fi
+}
+
+log_assert "Boot properties cannot be set on pools with older versions"
+
+# These are configs from zpool_upgrade.cfg - see that file for more info.
+CONFIGS="1 2 3"
+
+log_onexit cleanup
+log_must $ZPOOL create -f $TESTPOOL $DISKS
+
+for config in $CONFIGS
+do
+	create_old_pool $config
+	POOL_NAME=$(eval $ECHO \$ZPOOL_VERSION_${config}_NAME)
+	log_must $ZFS create $POOL_NAME/$TESTFS
+	log_mustnot $ZPOOL set bootfs=$POOL_NAME/$TESTFS $POOL_NAME
+	log_must destroy_upgraded_pool $config
+done
+
+log_pass "Boot properties cannot be set on pools with older versions"
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/usr/src/test/zfs-tests/tests/functional/bootfs/bootfs_006_pos.ksh	Wed Dec 05 22:04:50 2012 -0500
@@ -0,0 +1,142 @@
+#!/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.
+#
+
+. $STF_SUITE/include/libtest.shlib
+
+#
+# DESCRIPTION:
+#
+# Pools of correct vdev types accept boot property
+#
+# STRATEGY:
+# 1. create pools of each vdev type (raid, raidz, raidz2, mirror + hotspares)
+# 2. verify we can set bootfs on each pool type according to design
+#
+
+verify_runnable "global"
+
+
+$ZPOOL set 2>&1 | $GREP bootfs > /dev/null
+if [ $? -ne 0 ]
+then
+	log_unsupported "bootfs pool property not supported on this release."
+fi
+
+VDEV1=/bootfs_006_pos_a.$$.dat
+VDEV2=/bootfs_006_pos_b.$$.dat
+VDEV3=/bootfs_006_pos_c.$$.dat
+VDEV4=/bootfs_006_pos_d.$$.dat
+
+function verify_bootfs { # $POOL
+	POOL=$1
+	log_must $ZFS create $POOL/$TESTFS
+
+	log_must $ZPOOL set bootfs=$POOL/$TESTFS $POOL
+	VAL=$($ZPOOL get bootfs $POOL | $TAIL -1 | $AWK '{print $3}' )
+	if [ $VAL != "$POOL/$TESTFS" ]
+	then
+		log_must $ZPOOL status -v $POOL
+		log_fail \
+		    "set/get failed on $POOL - expected $VAL == $POOL/$TESTFS"
+	fi
+	log_must $ZPOOL destroy $POOL
+}
+
+function verify_no_bootfs { # $POOL
+	POOL=$1
+	log_must $ZFS create $POOL/$TESTFS
+	log_mustnot $ZPOOL set bootfs=$POOL/$TESTFS $POOL
+	VAL=$($ZPOOL get bootfs $POOL | $TAIL -1 | $AWK '{print $3}' )
+	if [ $VAL == "$POOL/$TESTFS" ]
+	then
+		log_must $ZPOOL status -v $POOL
+		log_fail "set/get unexpectedly failed $VAL != $POOL/$TESTFS"
+	fi
+	log_must $ZPOOL destroy $POOL
+}
+
+function cleanup {
+	if poolexists $TESTPOOL
+	then
+		log_must $ZPOOL destroy $TESTPOOL
+	fi
+	log_must $RM $VDEV1 $VDEV2 $VDEV3 $VDEV4
+}
+
+log_assert "Pools of correct vdev types accept boot property"
+
+
+
+log_onexit cleanup
+log_must $MKFILE 64m $VDEV1 $VDEV2 $VDEV3 $VDEV4
+
+
+## the following configurations are supported bootable pools
+
+# normal
+log_must $ZPOOL create $TESTPOOL $VDEV1
+verify_bootfs $TESTPOOL
+
+# normal + hotspare
+log_must $ZPOOL create $TESTPOOL $VDEV1 spare $VDEV2
+verify_bootfs $TESTPOOL
+
+# mirror
+log_must $ZPOOL create $TESTPOOL mirror $VDEV1 $VDEV2
+verify_bootfs $TESTPOOL
+
+# mirror + hotspare
+log_must $ZPOOL create $TESTPOOL mirror $VDEV1 $VDEV2 spare $VDEV3
+verify_bootfs $TESTPOOL
+
+## the following configurations are not supported as bootable pools
+
+# stripe
+log_must $ZPOOL create $TESTPOOL $VDEV1 $VDEV2
+verify_no_bootfs $TESTPOOL
+
+# stripe + hotspare
+log_must $ZPOOL create $TESTPOOL $VDEV1 $VDEV2 spare $VDEV3
+verify_no_bootfs $TESTPOOL
+
+# raidz
+log_must $ZPOOL create $TESTPOOL raidz $VDEV1 $VDEV2
+verify_no_bootfs $TESTPOOL
+
+# raidz + hotspare
+log_must $ZPOOL create $TESTPOOL raidz $VDEV1 $VDEV2 spare $VDEV3
+verify_no_bootfs $TESTPOOL
+
+# raidz2
+log_must $ZPOOL create $TESTPOOL raidz2 $VDEV1 $VDEV2 $VDEV3
+verify_no_bootfs $TESTPOOL
+
+# raidz2 + hotspare
+log_must $ZPOOL create $TESTPOOL raidz2 $VDEV1 $VDEV2 $VDEV3 spare $VDEV4
+verify_no_bootfs $TESTPOOL
+
+log_pass "Pools of correct vdev types accept boot property"
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/usr/src/test/zfs-tests/tests/functional/bootfs/bootfs_007_neg.ksh	Wed Dec 05 22:04:50 2012 -0500
@@ -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 2009 Sun Microsystems, Inc.  All rights reserved.
+# Use is subject to license terms.
+#
+
+. $STF_SUITE/include/libtest.shlib
+
+#
+# DESCRIPTION:
+#
+# Setting bootfs on a pool which was configured with the whole disk
+# (i.e. EFI) will fail
+#
+# STRATEGY:
+# 1. create a pool with a whole disk
+# 2. create a filesystem on this pool
+# 3. verify we can not set bootfs on the filesystem we just created.
+#
+
+verify_runnable "global"
+
+function cleanup {
+	if poolexists $TESTPOOL ; then
+		destroy_pool "$TESTPOOL"
+	fi
+}
+
+log_onexit cleanup
+
+DISK=${DISKS%% *}
+typeset EFI_BOOTFS=$TESTPOOL/efs
+typeset assert_mesg="setting bootfs on a pool which was configured with the \
+    whole disk will fail"
+
+log_assert $assert_mesg
+create_pool "$TESTPOOL" "$DISK"
+log_must $ZFS create $EFI_BOOTFS
+
+log_mustnot $ZPOOL set bootfs=$EFI_BOOTFS $TESTPOOL
+
+log_pass $assert_mesg
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/usr/src/test/zfs-tests/tests/functional/bootfs/bootfs_008_neg.ksh	Wed Dec 05 22:04:50 2012 -0500
@@ -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.
+#
+
+. $STF_SUITE/include/libtest.shlib
+
+#
+# DESCRIPTION:
+#
+# setting bootfs on a dataset which has gzip compression enabled will fail
+#
+# STRATEGY:
+# 1. create pools based on a valid vdev
+# 2. create a filesytem on this pool and set the compression property to gzip1-9
+# 3. set the pool's bootfs property to filesystem we just configured which
+#    should fail
+#
+
+verify_runnable "global"
+
+function cleanup {
+	if poolexists $TESTPOOL ; then
+		destroy_pool "$TESTPOOL"
+	fi
+
+	if [[ -f $VDEV ]]; then
+		log_must $RM -f $VDEV
+	fi
+}
+
+typeset assert_msg="setting bootfs on a dataset which has gzip \
+    compression enabled will fail"
+
+typeset VDEV=/bootfs_008_neg_a.$$.dat
+typeset COMP_FS=$TESTPOOL/COMP_FS
+
+log_onexit cleanup
+log_assert $assert_msg
+
+log_must $MKFILE 300m $VDEV
+log_must $ZPOOL create $TESTPOOL $VDEV
+log_must $ZFS create $COMP_FS
+
+typeset -i i=0
+set -A gtype "gzip" "gzip-1" "gzip-2" "gzip-3" "gzip-4" "gzip-5" \
+	     "gzip-6" "gzip-7" "gzip-8" "gzip-9"
+
+while (( i < ${#gtype[@]} )); do
+	log_must $ZFS set compression=${gtype[i]} $COMP_FS
+	log_mustnot $ZPOOL set bootfs=$COMP_FS $TESTPOOL
+	log_must $ZFS set compression=off $COMP_FS
+	(( i += 1 ))
+done
+
+log_pass $assert_msg
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/usr/src/test/zfs-tests/tests/functional/cli_root/Makefile	Wed Dec 05 22:04:50 2012 -0500
@@ -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) 2012 by Delphix. All rights reserved.
+#
+
+.PARALLEL: $(SUBDIRS)
+
+include $(SRC)/Makefile.master
+
+ROOTOPTPKG = $(ROOT)/opt/zfs-tests
+TESTDIR = $(ROOTOPTPKG)/tests/functional/cli_root
+
+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 = zdb \
+	zfs \
+	zfs_clone \
+	zfs_copies \
+	zfs_create \
+	zfs_destroy \
+	zfs_get \
+	zfs_inherit \
+	zfs_mount \
+	zfs_promote \
+	zfs_property \
+	zfs_receive \
+	zfs_rename \
+	zfs_reservation \
+	zfs_rollback \
+	zfs_send \
+	zfs_set \
+	zfs_share \
+	zfs_snapshot \
+	zfs_unmount \
+	zfs_unshare \
+	zfs_upgrade \
+	zpool \
+	zpool_add \
+	zpool_attach \
+	zpool_clear \
+	zpool_create \
+	zpool_destroy \
+	zpool_detach \
+	zpool_expand \
+	zpool_export \
+	zpool_get \
+	zpool_history \
+	zpool_import \
+	zpool_offline \
+	zpool_online \
+	zpool_remove \
+	zpool_replace \
+	zpool_scrub \
+	zpool_set \
+	zpool_status \
+	zpool_upgrade
+
+include $(SRC)/test/Makefile.com
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/usr/src/test/zfs-tests/tests/functional/cli_root/cli_common.kshlib	Wed Dec 05 22:04:50 2012 -0500
@@ -0,0 +1,86 @@
+#
+# CDDL HEADER START
+#
+# The contents of this file are subject to the terms of the
+# Common Development and Distribution License (the "License").
+# You may not use this file except in compliance with the License.
+#
+# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
+# or http://www.opensolaris.org/os/licensing.
+# See the License for the specific language governing permissions
+# and limitations under the License.
+#
+# When distributing Covered Code, include this CDDL HEADER in each
+# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
+# If applicable, add the following below this CDDL HEADER, with the
+# fields enclosed by brackets "[]" replaced with your own identifying
+# information: Portions Copyright [yyyy] [name of copyright owner]
+#
+# CDDL HEADER END
+#
+
+#
+# Copyright 2007 Sun Microsystems, Inc.  All rights reserved.
+# Use is subject to license terms.
+#
+
+. $STF_SUITE/include/libtest.shlib
+
+#
+# Get the checksum and size of the file.
+#
+function get_cksum # <file path>
+{
+	return $($CKSUM $1 | $AWK '{print $1 $2}')
+}
+
+#
+# Compare the check sum of target files with the original file
+#
+
+function compare_cksum #<orig_data> <target_data1>...<target_datan>
+{
+	typeset orig_data=$1
+	typeset orig_sum=$(get_cksum $orig_data)
+	typeset target_sum=""
+	typeset bad_data_list=""
+	typeset -i bad_count=0
+
+	shift
+	for data in $@; do
+		if [[ ! -e $data ]]; then
+			bad_data_list="$bad_data_list $data"
+			(( bad_count +=1 ))
+			continue
+		fi
+
+		target_sum=$(get_cksum $data)
+		if [[ $target_sum != $orig_sum ]]; then
+			bad_data_list="$bad_data_list $data"
+			(( bad_count +=1 ))
+		fi
+	done
+
+	[[ $bad_data_list != "" ]] && \
+		log_fail "Data corruptions appear during send->receive." \
+			"There are total $bad_count corruptions. They are:\n"\
+			"$bad_data_list"
+}
+
+#
+# Check the received dataset exists or not
+#
+function receive_check #<dataset1>...<datasetn>
+{
+	typeset bad_rst_tgts=""
+
+	for dataset in $@; do
+		! datasetexists $dataset && \
+			bad_rst_tgts="$bad_rst_tgts $dataset"
+	done
+
+	if [[ $bad_rst_tgts != "" ]]; then
+		log_fail "Restoring fails. The specified datasets"\
+			"$bad_rst_tgts are not being received."
+	fi
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/usr/src/test/zfs-tests/tests/functional/cli_root/zdb/Makefile	Wed Dec 05 22:04:50 2012 -0500
@@ -0,0 +1,39 @@
+#
+# 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) 2012 by Delphix. All rights reserved.
+#
+
+include $(SRC)/Makefile.master
+
+ROOTOPTPKG = $(ROOT)/opt/zfs-tests
+TESTDIR = $(ROOTOPTPKG)/tests/functional/cli_root/zdb
+
+PROGS = zdb_001_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	Thu Jan 01 00:00:00 1970 +0000
+++ b/usr/src/test/zfs-tests/tests/functional/cli_root/zdb/zdb_001_neg.ksh	Wed Dec 05 22:04:50 2012 -0500
@@ -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) 2012 by Delphix. All rights reserved.
+#
+
+. $STF_SUITE/include/libtest.shlib
+
+#
+# DESCRIPTION:
+# A badly formed parameter passed to zdb(1) should
+# return an error.
+#
+# STRATEGY:
+# 1. Create an array containg bad zdb parameters.
+# 2. For each element, execute the sub-command.
+# 3. Verify it returns an error.
+#
+
+verify_runnable "global"
+
+set -A args "create" "add" "destroy" "import fakepool" \
+    "export fakepool" "create fakepool" "add fakepool" \
+    "create mirror" "create raidz" \
+    "create mirror fakepool" "create raidz fakepool" \
+    "create raidz1 fakepool" "create raidz2 fakepool" \
+    "create fakepool mirror" "create fakepool raidz" \
+    "create fakepool raidz1" "create fakepool raidz2" \
+    "add fakepool mirror" "add fakepool raidz" \
+    "add fakepool raidz1" "add fakepool raidz2" \
+    "add mirror fakepool" "add raidz fakepool" \
+    "add raidz1 fakepool" "add raidz2 fakepool" \
+    "setvprop" "blah blah" "-%" "--?" "-*" "-=" \
+    "-a" "-f" "-g" "-h" "-j" "-k" "-m" "-n" "-o" "-p" "-p /tmp" \
+    "-q" "-r" "-t" "-w" "-x" "-y" "-z" \
+    "-D" "-E" "-G" "-H" "-I" "-J" "-K" "-M" \
+    "-N" "-Q" "-R" "-S" "-T" "-V" "-W" "-Y" "-Z"
+
+log_assert "Execute zdb using invalid parameters."
+
+typeset -i i=0
+while [[ $i -lt ${#args[*]} ]]; do
+	log_mustnot $ZDB ${args[i]}
+
+	((i = i + 1))
+done
+
+log_pass "Badly formed zdb parameters fail as expected."
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/usr/src/test/zfs-tests/tests/functional/cli_root/zfs/Makefile	Wed Dec 05 22:04:50 2012 -0500
@@ -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) 2012 by Delphix. All rights reserved.
+#
+
+include $(SRC)/Makefile.master
+
+ROOTOPTPKG = $(ROOT)/opt/zfs-tests
+TESTDIR = $(ROOTOPTPKG)/tests/functional/cli_root/zfs
+
+PROGS = cleanup \
+	setup \
+	zfs_001_neg \
+	zfs_002_pos \
+	zfs_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	Thu Jan 01 00:00:00 1970 +0000
+++ b/usr/src/test/zfs-tests/tests/functional/cli_root/zfs/cleanup.ksh	Wed Dec 05 22:04:50 2012 -0500
@@ -0,0 +1,30 @@
+#!/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.
+#
+
+. $STF_SUITE/include/libtest.shlib
+
+default_cleanup
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/usr/src/test/zfs-tests/tests/functional/cli_root/zfs/setup.ksh	Wed Dec 05 22:04:50 2012 -0500
@@ -0,0 +1,32 @@
+#!/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.
+#
+
+. $STF_SUITE/include/libtest.shlib
+
+DISK=${DISKS%% *}
+
+default_setup $DISK
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/usr/src/test/zfs-tests/tests/functional/cli_root/zfs/zfs_001_neg.ksh	Wed Dec 05 22:04:50 2012 -0500
@@ -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.
+#
+. $STF_SUITE/include/libtest.shlib
+
+#
+# DESCRIPTION:
+# Try each zfs(1) 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 "both"
+
+
+set -A args  "" "create" "create -s" "create -V" "create -s -V" \
+    "destroy" "destroy -f" "destroy -r" "destroy -R" "destroy -rRf" \
+    "snapshot" "snapshot -r" \
+    "rollback" "rollback -r" "rollback -R" "rollback -f" "rollback -rRf" \
+    "clone" "clone -p" "promote" "rename" "rename -p" "rename -r" "list blah" \
+    "set" "get" "get -rHp" "get -o" "get -s" \
+    "inherit" "inherit -r"  "quota=" \
+    "set reservation=" "set atime=" "set checksum=" "set compression=" \
+    "set type="  "set creation=" "set used=" "set available=" "set referenced=" \
+    "set compressratio=" "set mounted=" "set origin=" "set quota=" \
+    "set reservation=" "set volsize=" " set volblocksize=" "set recordsize=" \
+    "set mountpoint=" "set devices=" "set exec=" "set setuid=" "set readonly=" \
+    "set zoned=" "set snapdir=" "set aclmode=" "set aclinherit=" \
+    "set quota=blah" "set reservation=blah" "set atime=blah" "set checksum=blah" \
+    "set compression=blah" \
+    "upgrade blah" "mount blah" "mount -o" \
+    "umount blah" "unmount" "unmount blah" "unmount -f" \
+    "share" "unshare" "send" "send -i" "receive" "receive -d" "receive -vnF" \
+    "recv" "recv -d" "recv -vnF" "allow" "unallow" \
+    "blah blah" "-%" "--" "--?" "-*" "-="
+
+log_assert "Badly-formed zfs sub-command should return an error."
+
+typeset -i i=0
+while (( $i < ${#args[*]} )); do
+	log_mustnot $ZFS ${args[i]}
+	((i = i + 1))
+done
+
+log_pass "Badly formed zfs sub-commands fail as expected."
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/usr/src/test/zfs-tests/tests/functional/cli_root/zfs/zfs_002_pos.ksh	Wed Dec 05 22:04:50 2012 -0500
@@ -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) 2012 by Delphix. All rights reserved.
+#
+
+. $STF_SUITE/include/libtest.shlib
+
+#
+# DESCRIPTION:
+# With ZFS_ABORT set, all zfs commands should be able to abort and generate a
+# core file.
+#
+# STRATEGY:
+# 1. Create an array of zfs command
+# 2. Execute each command in the array
+# 3. Verify the command aborts and generate a core file
+#
+
+verify_runnable "both"
+
+function cleanup
+{
+	unset ZFS_ABORT
+
+	if [[ -d $corepath ]]; then
+		$RM -rf $corepath
+	fi
+	for ds in $fs1 $fs $ctr; do
+		if datasetexists $ds; then
+			log_must $ZFS destroy -rRf $ds
+		fi
+	done
+}
+
+log_assert "With ZFS_ABORT set, all zfs commands can abort and generate a " \
+    "core file."
+log_onexit cleanup
+
+#preparation work for testing
+corepath=$TESTDIR/core
+if [[ -d $corepath ]]; then
+	$RM -rf $corepath
+fi
+log_must $MKDIR $corepath
+
+ctr=$TESTPOOL/$TESTCTR
+log_must $ZFS create $ctr
+
+fs=$ctr/$TESTFS
+fs1=$ctr/$TESTFS1
+snap=$fs@$TESTSNAP
+clone=$ctr/$TESTCLONE
+streamf=$corepath/s.$$
+
+typeset cmds=("create $fs" "list $fs" "snapshot $snap" "set snapdir=hidden $fs" \
+    "get snapdir $fs" "rollback $snap" "inherit snapdir $fs" \
+    "rename $fs $fs-new" "rename $fs-new $fs" "unmount $fs" \
+    "mount $fs" "share $fs" "unshare $fs" "send $snap \>$streamf" \
+    "receive $fs1 \<$streamf" "clone $snap $clone" "promote $clone" \
+    "promote $fs" "destroy -rRf $fs")
+
+typeset badparams=("" "create" "destroy" "snapshot" "rollback" "clone" \
+    "promote" "rename" "list -*" "set" "get -*" "inherit" "mount -A" \
+    "unmount" "share" "unshare" "send" "receive")
+
+log_must $COREADM -p ${corepath}/core.%f
+log_must export ZFS_ABORT=yes
+
+for subcmd in "${cmds[@]}" "${badparams[@]}"; do
+	$ZFS $subcmd >/dev/null 2>&1 && log_fail "$subcmd passed incorrectly."
+	corefile=${corepath}/core.zfs
+	if [[ ! -e $corefile ]]; then
+		log_fail "$ZFS $subcmd cannot generate core file with " \
+		    "ZFS_ABORT set."
+	fi
+	log_must $RM -f $corefile
+done
+
+log_pass "With ZFS_ABORT set, zfs command can abort and generate core file " \
+    "as expected."
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/usr/src/test/zfs-tests/tests/functional/cli_root/zfs/zfs_003_neg.ksh	Wed Dec 05 22:04:50 2012 -0500
@@ -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.
+#
+. $STF_SUITE/include/libtest.shlib
+
+#
+# DESCRIPTION:
+# zfs command will failed with unexpected scenarios:
+# (1) ZFS_DEV cannot be opened
+# (2) MNTTAB cannot be opened
+#
+# STRATEGY:
+# 1. Create an array of zfs command
+# 2. Execute each command in the array
+# 3. Verify the command aborts and generate a core file
+#
+
+verify_runnable "global"
+
+log_assert "zfs fails with unexpected scenarios."
+
+#verify zfs failed if ZFS_DEV cannot be opened
+ZFS_DEV=/dev/zfs
+MNTTAB=/etc/mnttab
+
+for file in $ZFS_DEV $MNTTAB; do
+	if [[ -e $file ]]; then
+		$MV $file ${file}.bak
+	fi
+	for cmd in "" "list" "get all" "mount"; do
+		log_mustnot eval "$ZFS $cmd >/dev/null 2>&1"
+	done
+	$MV ${file}.bak $file
+done
+
+log_pass "zfs fails with unexpected scenarios as expected."
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/usr/src/test/zfs-tests/tests/functional/cli_root/zfs_clone/Makefile	Wed Dec 05 22:04:50 2012 -0500
@@ -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) 2012 by Delphix. All rights reserved.
+#
+
+include $(SRC)/Makefile.master
+
+ROOTOPTPKG = $(ROOT)/opt/zfs-tests
+TESTDIR = $(ROOTOPTPKG)/tests/functional/cli_root/zfs_clone
+
+PROGS = cleanup \
+	setup \
+	zfs_clone_001_neg \
+	zfs_clone_002_pos \
+	zfs_clone_003_pos \
+	zfs_clone_004_pos \
+	zfs_clone_005_pos \
+	zfs_clone_006_pos \
+	zfs_clone_007_pos \
+	zfs_clone_008_neg \
+	zfs_clone_009_neg \
+	zfs_clone_010_pos
+
+CMDS = $(PROGS:%=$(TESTDIR)/%)
+$(CMDS) := FILEMODE = 0555
+
+all lint clean clobber:
+
+install: $(CMDS)
+
+$(CMDS): $(TESTDIR)
+
+$(TESTDIR):
+	$(INS.dir)
+
+$(TESTDIR)/%: %.ksh
+	$(INS.rename)
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/usr/src/test/zfs-tests/tests/functional/cli_root/zfs_clone/cleanup.ksh	Wed Dec 05 22:04:50 2012 -0500
@@ -0,0 +1,30 @@
+#!/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.
+#
+
+. $STF_SUITE/include/libtest.shlib
+
+default_container_cleanup
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/usr/src/test/zfs-tests/tests/functional/cli_root/zfs_clone/setup.ksh	Wed Dec 05 22:04:50 2012 -0500
@@ -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) 2012 by Delphix. All rights reserved.
+#
+
+. $STF_SUITE/include/libtest.shlib
+
+DISK=${DISKS%% *}
+
+default_container_volume_setup ${DISK}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/usr/src/test/zfs-tests/tests/functional/cli_root/zfs_clone/zfs_clone_001_neg.ksh	Wed Dec 05 22:04:50 2012 -0500
@@ -0,0 +1,123 @@
+#!/bin/ksh -p
+#
+# CDDL HEADER START
+#
+# The contents of this file are subject to the terms of the
+# Common Development and Distribution License (the "License").
+# You may not use this file except in compliance with the License.
+#
+# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
+# or http://www.opensolaris.org/os/licensing.
+# See the License for the specific language governing permissions
+# and limitations under the License.
+#
+# When distributing Covered Code, include this CDDL HEADER in each
+# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
+# If applicable, add the following below this CDDL 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) 2012 by Delphix. All rights reserved.
+#
+
+. $STF_SUITE/include/libtest.shlib
+
+#
+# DESCRIPTION:
+#	'zfs clone' should fail with inapplicable scenarios, including:
+#		* Null arguments
+#		* non-existant snapshots.
+#		* invalid characters in ZFS namesapec
+#		* Leading slash in the target clone name
+#		* The argument contains an empty component.
+#		* The pool specified in the target doesn't exist.
+#		* The parent dataset of the target doesn't exist.
+#		* The argument refer to a pool, not dataset.
+#		* The target clone already exists.
+#		* Null target clone argument.
+#		* Too many arguments.
+#
+# 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 "both"
+
+typeset target1=$TESTPOOL/$TESTFS1
+typeset target2=$TESTPOOL/$TESTCTR1/$TESTFS1
+typeset targets="$target1 $target2 $NONEXISTPOOLNAME/$TESTFS"
+
+set -A args "" \
+	"$TESTPOOL/$TESTFS@blah $target1" "$TESTPOOL/$TESTVOL@blah $target1" \
+	"$TESTPOOL/$TESTFS@blah* $target1" "$TESTPOOL/$TESTVOL@blah* $target1" \
+	"$SNAPFS $target1*" "$SNAPFS1 $target1*" \
+	"$SNAPFS /$target1" "$SNAPFS1 /$target1" \
+	"$SNAPFS $TESTPOOL//$TESTFS1" "$SNAPFS1 $TESTPOOL//$TESTFS1" \
+	"$SNAPFS $NONEXISTPOOLNAME/$TESTFS" "$SNAPFS1 $NONEXISTPOOLNAME/$TESTFS" \
+	"$SNAPFS" "$SNAPFS1" \
+	"$SNAPFS $target1 $target2" "$SNAPFS1 $target1 $target2"
+typeset -i argsnum=${#args[*]}
+typeset -i j=0
+while (( j < argsnum )); do
+	args[((argsnum+j))]="-p ${args[j]}"
+	((j = j + 1))
+done
+
+set -A moreargs "$SNAPFS $target2" "$SNAPFS1 $target2" \
+	"$SNAPFS $TESTPOOL" "$SNAPFS1 $TESTPOOL" \
+	"$SNAPFS $TESTPOOL/$TESTCTR" "$SNAPFS $TESTPOOL/$TESTFS" \
+	"$SNAPFS1 $TESTPOOL/$TESTCTR" "$SNAPFS1 $TESTPOOL/$TESTFS"
+
+set -A args ${args[*]} ${moreargs[*]}
+
+function setup_all
+{
+	log_note "Create snapshots and mount them..."
+
+	for snap in $SNAPFS $SNAPFS1 ; do
+		if ! snapexists $snap ; then
+			log_must $ZFS snapshot $snap
+		fi
+	done
+
+	return 0
+}
+
+function cleanup_all
+{
+	for fs in $targets; do
+		datasetexists $fs && log_must $ZFS destroy -f $fs
+	done
+
+	for snap in $SNAPFS $SNAPFS1 ; do
+		snapexists $snap && log_must $ZFS destroy -Rf $snap
+	done
+
+	return 0
+}
+
+log_assert "Badly-formed 'zfs clone' with inapplicable scenarios" \
+	"should return an error."
+log_onexit cleanup_all
+
+setup_all
+
+typeset -i i=0
+while (( i < ${#args[*]} )); do
+	log_mustnot $ZFS clone ${args[i]}
+	((i = i + 1))
+done
+
+log_pass "Badly formed 'zfs clone' with inapplicable scenarios" \
+	"fail as expected."
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/usr/src/test/zfs-tests/tests/functional/cli_root/zfs_clone/zfs_clone_002_pos.ksh	Wed Dec 05 22:04:50 2012 -0500
@@ -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 2009 Sun Microsystems, Inc.  All rights reserved.
+# Use is subject to license terms.
+#
+
+#
+# Copyright (c) 2012 by Delphix. All rights reserved.
+#
+
+. $STF_SUITE/include/libtest.shlib
+
+#
+# DESCRIPTION:
+#	'zfs clone -p' should work as expected
+#
+# STRATEGY:
+#	1. prepare snapshots
+#	2. make sure without -p option, 'zfs clone' will fail
+#	3. with -p option, the clone can be created
+#	4. run 'zfs clone -p' again, the exit code should be zero
+#
+
+verify_runnable "both"
+
+function setup_all
+{
+	log_note "Create snapshots and mount them..."
+
+	for snap in $SNAPFS $SNAPFS1 ; do
+		if ! snapexists $snap ; then
+			log_must $ZFS snapshot $snap
+		fi
+	done
+
+	return 0
+}
+
+function cleanup_all
+{
+
+	if datasetexists $TESTPOOL/notexist ; then
+		log_must $ZFS destroy -rRf $TESTPOOL/notexist
+	fi
+
+	for snap in $SNAPFS $SNAPFS1 ; do
+		if snapexists $snap ; then
+			log_must $ZFS destroy -Rf $snap
+		fi
+	done
+
+	return 0
+}
+
+log_assert "clone -p should work as expected."
+log_onexit cleanup_all
+
+setup_all
+
+log_must verify_opt_p_ops "clone" "fs" $SNAPFS \
+	 $TESTPOOL/notexist/new/clonefs$$
+
+if is_global_zone ; then
+	log_must verify_opt_p_ops "clone" "vol" $SNAPFS1 \
+		 $TESTPOOL/notexist/new/clonevol$$
+fi
+
+log_pass "clone -p should work as expected."
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/usr/src/test/zfs-tests/tests/functional/cli_root/zfs_clone/zfs_clone_003_pos.ksh	Wed Dec 05 22:04:50 2012 -0500
@@ -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) 2012 by Delphix. All rights reserved.
+#
+
+. $STF_SUITE/include/libtest.shlib
+. $STF_SUITE/tests/functional/cli_root/zfs_create/zfs_create_common.kshlib
+. $STF_SUITE/tests/functional/cli_root/zfs_create/properties.kshlib
+
+#
+# DESCRIPTION:
+# 'zfs clone -o property=value filesystem' can successfully create a ZFS
+# clone filesystem with correct property set.
+#
+# STRATEGY:
+# 1. Create a ZFS clone filesystem in the storage pool with -o option
+# 2. Verify the filesystem created successfully
+# 3. Verify the property is correctly set
+#
+
+verify_runnable "both"
+
+function cleanup
+{
+	if snapexists $SNAPFS ; then
+		log_must $ZFS destroy -Rf $SNAPFS
+	fi
+}
+
+log_onexit cleanup
+
+
+log_assert "'zfs clone -o property=value filesystem' can successfully create" \
+	   "a ZFS clone filesystem with correct property set."
+
+log_must $ZFS snapshot $SNAPFS
+
+typeset -i i=0
+while (( $i < ${#RW_FS_PROP[*]} )); do
+	log_must $ZFS clone -o ${RW_FS_PROP[$i]} $SNAPFS $TESTPOOL/$TESTCLONE
+	datasetexists $TESTPOOL/$TESTCLONE || \
+		log_fail "zfs clone $TESTPOOL/$TESTCLONE fail."
+	propertycheck $TESTPOOL/$TESTCLONE ${RW_FS_PROP[i]} || \
+		log_fail "${RW_FS_PROP[i]} is failed to set."
+	log_must $ZFS destroy -f $TESTPOOL/$TESTCLONE
+	(( i = i + 1 ))
+done
+
+log_pass "'zfs clone -o property=value filesystem' can successfully create" \
+         "a ZFS clone filesystem with correct property set."
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/usr/src/test/zfs-tests/tests/functional/cli_root/zfs_clone/zfs_clone_004_pos.ksh	Wed Dec 05 22:04:50 2012 -0500
@@ -0,0 +1,87 @@
+#!/bin/ksh -p
+#
+# CDDL HEADER START
+#
+# The contents of this file are subject to the terms of the
+# Common Development and Distribution License (the "License").
+# You may not use this file except in compliance with the License.
+#
+# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
+# or http://www.opensolaris.org/os/licensing.
+# See the License for the specific language governing permissions
+# and limitations under the License.
+#
+# When distributing Covered Code, include this CDDL HEADER in each
+# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
+# If applicable, add the following below this CDDL 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) 2012 by Delphix. All rights reserved.
+#
+
+. $STF_SUITE/include/libtest.shlib
+. $STF_SUITE/tests/functional/cli_root/zfs_create/zfs_create_common.kshlib
+. $STF_SUITE/tests/functional/cli_root/zfs_create/properties.kshlib
+
+#
+# DESCRIPTION:
+# 'zfs clone -o property=value filesystem' can successfully create a ZFS
+# clone filesystem with multiple properties set.
+#
+# STRATEGY:
+# 1. Create a ZFS clone filesystem in the storage pool with multiple -o options
+# 2. Verify the filesystem created successfully
+# 3. Verify the properties are correctly set
+#
+
+verify_runnable "both"
+
+function cleanup
+{
+	if snapexists $SNAPFS ; then
+		log_must $ZFS destroy -Rf $SNAPFS
+	fi
+}
+
+log_onexit cleanup
+
+log_assert "'zfs clone -o property=value filesystem' can successfully create" \
+	   "a ZFS clone filesystem with multiple properties set."
+
+typeset -i i=0
+typeset opts=""
+
+log_must $ZFS snapshot $SNAPFS
+
+while (( $i < ${#RW_FS_PROP[*]} )); do
+        if [[ ${RW_FS_PROP[$i]} != *"checksum"* ]]; then
+		opts="$opts -o ${RW_FS_PROP[$i]}"
+	fi
+	(( i = i + 1 ))
+done
+
+log_must $ZFS clone $opts $SNAPFS $TESTPOOL/$TESTCLONE
+datasetexists $TESTPOOL/$TESTCLONE || \
+	log_fail "zfs create $TESTPOOL/$TESTCLONE fail."
+
+i=0
+while (( $i < ${#RW_FS_PROP[*]} )); do
+        if [[ ${RW_FS_PROP[$i]} != *"checksum"* ]]; then
+		propertycheck $TESTPOOL/$TESTCLONE ${RW_FS_PROP[i]} || \
+			log_fail "${RW_FS_PROP[i]} is failed to set."
+	fi
+	(( i = i + 1 ))
+done
+
+log_pass "'zfs clone -o property=value filesystem' can successfully create" \
+         "a ZFS clone filesystem with multiple properties set."
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/usr/src/test/zfs-tests/tests/functional/cli_root/zfs_clone/zfs_clone_005_pos.ksh	Wed Dec 05 22:04:50 2012 -0500
@@ -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 2009 Sun Microsystems, Inc.  All rights reserved.
+# Use is subject to license terms.
+#
+
+#
+# Copyright (c) 2012 by Delphix. All rights reserved.
+#
+
+. $STF_SUITE/include/libtest.shlib
+. $STF_SUITE/tests/functional/cli_root/zfs_create/zfs_create_common.kshlib
+. $STF_SUITE/tests/functional/cli_root/zfs_create/properties.kshlib
+
+#
+# DESCRIPTION:
+# 'zfs clone -o property=value -V size volume' can successfully create a ZFS
+# clone volume with correct property set.
+#
+# STRATEGY:
+# 1. Create a ZFS clone volume in the storage pool with -o option
+# 2. Verify the volume created successfully
+# 3. Verify the property is correctly set
+#
+
+verify_runnable "global"
+
+function cleanup
+{
+	if snapexists $SNAPFS1 ; then
+		log_must $ZFS destroy -Rf $SNAPFS1
+	fi
+}
+
+log_onexit cleanup
+
+log_assert "'zfs clone -o property=value -V size volume' can successfully" \
+	   "create a ZFS clone volume with correct property set."
+
+log_must $ZFS snapshot $SNAPFS1
+typeset -i i=0
+while (( $i < ${#RW_VOL_CLONE_PROP[*]} )); do
+	log_must $ZFS clone -o ${RW_VOL_CLONE_PROP[$i]} $SNAPFS1 $TESTPOOL/$TESTCLONE
+	datasetexists $TESTPOOL/$TESTCLONE || \
+		log_fail "zfs clone $TESTPOOL/$TESTCLONE fail."
+	propertycheck $TESTPOOL/$TESTCLONE ${RW_VOL_CLONE_PROP[i]} || \
+		log_fail "${RW_VOL_CLONE_PROP[i]} is failed to set."
+	log_must $ZFS destroy -f $TESTPOOL/$TESTCLONE
+
+	(( i = i + 1 ))
+done
+
+log_pass "'zfs clone -o property=value volume' can successfully" \
+	"create a ZFS clone volume with correct property set."
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/usr/src/test/zfs-tests/tests/functional/cli_root/zfs_clone/zfs_clone_006_pos.ksh	Wed Dec 05 22:04:50 2012 -0500
@@ -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) 2012 by Delphix. All rights reserved.
+#
+
+
+. $STF_SUITE/include/libtest.shlib
+. $STF_SUITE/tests/functional/cli_root/zfs_create/zfs_create_common.kshlib
+. $STF_SUITE/tests/functional/cli_root/zfs_create/properties.kshlib
+
+#
+# DESCRIPTION:
+# 'zfs clone -o property=value volume' can successfully create a ZFS
+# clone volume with multiple properties set.
+#
+# STRATEGY:
+# 1. Create a ZFS clone volume in the storage pool with -o option
+# 2. Verify the volume created successfully
+# 3. Verify the properties are correctly set
+#
+
+verify_runnable "global"
+
+function cleanup
+{
+	if snapexists $SNAPFS1 ; then
+		log_must $ZFS destroy -Rf $SNAPFS1
+	fi
+}
+
+log_onexit cleanup
+
+log_assert "'zfs clone -o property=value volume' can successfully" \
+	   "create a ZFS clone volume with multiple correct properties set."
+
+typeset -i i=0
+typeset opts=""
+
+log_must $ZFS snapshot $SNAPFS1
+
+while (( $i < ${#RW_VOL_CLONE_PROP[*]} )); do
+	if [[ ${RW_VOL_CLONE_PROP[$i]} != *"checksum"* ]]; then
+		opts="$opts -o ${RW_VOL_CLONE_PROP[$i]}"
+	fi
+	(( i = i + 1 ))
+done
+
+log_must $ZFS clone $opts $SNAPFS1 $TESTPOOL/$TESTCLONE
+
+i=0
+while (( $i < ${#RW_VOL_CLONE_PROP[*]} )); do
+	if [[ ${RW_VOL_CLONE_PROP[$i]} != *"checksum"* ]]; then
+		propertycheck $TESTPOOL/$TESTCLONE ${RW_VOL_CLONE_PROP[i]} || \
+			log_fail "${RW_VOL_CLONE_PROP[i]} is failed to set."
+	fi
+	(( i = i + 1 ))
+done
+
+log_pass "'zfs clone -o property=value volume' can successfully" \
+	"create a ZFS clone volume with multiple correct properties set."
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/usr/src/test/zfs-tests/tests/functional/cli_root/zfs_clone/zfs_clone_007_pos.ksh	Wed Dec 05 22:04:50 2012 -0500
@@ -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) 2012 by Delphix. All rights reserved.
+#
+
+. $STF_SUITE/include/libtest.shlib
+
+#
+# DESCRIPTION:
+# 'zfs clone -o version=' could upgrade version, but downgrade is denied.
+#
+# STRATEGY:
+# 1. Create clone with "-o version=" specified
+# 2. Verify it succeed while upgrade, but fails while the version downgraded.
+#
+
+ZFS_VERSION=$($ZFS upgrade | $HEAD -1 | $AWK '{print $NF}' \
+	| $SED -e 's/\.//g')
+
+verify_runnable "both"
+
+function cleanup
+{
+	if snapexists $SNAPFS ; then
+			log_must $ZFS destroy -Rf $SNAPFS
+	fi
+}
+
+log_onexit cleanup
+
+log_assert "'zfs clone -o version=' could upgrade version," \
+	"but downgrade is denied."
+
+log_must $ZFS snapshot $SNAPFS
+
+typeset -i ver
+
+if (( ZFS_TEST_VERSION == 0 )) ; then
+	(( ZFS_TEST_VERSION = ZFS_VERSION ))
+fi
+
+(( ver = ZFS_TEST_VERSION ))
+while (( ver <= ZFS_VERSION )); do
+	log_must $ZFS clone -o version=$ver $SNAPFS $TESTPOOL/$TESTCLONE
+	cleanup
+	(( ver = ver + 1 ))
+done
+
+(( ver = 0 ))
+while (( ver < ZFS_TEST_VERSION  )); do
+	log_mustnot $ZFS clone -o version=$ver \
+		$SNAPFS $TESTPOOL/$TESTCLONE
+	log_mustnot datasetexists $TESTPOOL/$TESTCLONE
+	cleanup
+	(( ver = ver + 1 ))
+done
+
+log_pass "'zfs clone -o version=' could upgrade version," \
+	"but downgrade is denied."
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/usr/src/test/zfs-tests/tests/functional/cli_root/zfs_clone/zfs_clone_008_neg.ksh	Wed Dec 05 22:04:50 2012 -0500
@@ -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) 2012 by Delphix. All rights reserved.
+#
+
+. $STF_SUITE/include/libtest.shlib
+. $STF_SUITE/tests/functional/cli_root/zfs_create/properties.kshlib
+
+#
+# DESCRIPTION:
+# 'zfs clone -o <filesystem>' fails with bad <filesystem> arguments, including:
+#	*Same property set multiple times via '-o property=value'
+#	*Volume's property set on filesystem
+#
+# STRATEGY:
+# 1. Create an array of <filesystem> arguments
+# 2. Execute 'zfs clone -o <filesystem>' with each argument
+# 3. Verify an error is returned.
+#
+
+verify_runnable "both"
+
+function cleanup
+{
+	if snapexists $SNAPFS ; then
+		log_must $ZFS destroy -Rf $SNAPFS
+	fi
+}
+
+log_onexit cleanup
+
+log_assert "Verify 'zfs clone -o <filesystem>' fails with bad <filesystem> argument."
+
+log_must $ZFS snapshot $SNAPFS
+
+typeset -i i=0
+while (( $i < ${#RW_FS_PROP[*]} )); do
+	log_mustnot $ZFS clone -o ${RW_FS_PROP[i]} -o ${RW_FS_PROP[i]} \
+		$SNAPFS $TESTPOOL/$TESTCLONE
+	log_mustnot $ZFS clone -p -o ${RW_FS_PROP[i]} -o ${RW_FS_PROP[i]} \
+		$SNAPFS $TESTPOOL/$TESTCLONE
+	((i = i + 1))
+done
+
+i=0
+while (( $i < ${#VOL_ONLY_PROP[*]} )); do
+	log_mustnot $ZFS clone -o ${VOL_ONLY_PROP[i]} \
+		$SNAPFS $TESTPOOL/$TESTCLONE
+	log_mustnot $ZFS clone -p -o ${VOL_ONLY_PROP[i]} \
+		$SNAPFS $TESTPOOL/$TESTCLONE
+	((i = i + 1))
+done
+
+log_pass "'zfs clone -o <filesystem>' fails with bad <filesystem> argument."
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/usr/src/test/zfs-tests/tests/functional/cli_root/zfs_clone/zfs_clone_009_neg.ksh	Wed Dec 05 22:04:50 2012 -0500
@@ -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) 2012 by Delphix. All rights reserved.
+#
+
+. $STF_SUITE/include/libtest.shlib
+. $STF_SUITE/tests/functional/cli_root/zfs_create/properties.kshlib
+
+#
+# DESCRIPTION:
+# 'zfs clone -o <volume>' fails with badly formed arguments,including:
+#       *Same property set multiple times via '-o property=value'
+#       *Filesystems's property set on volume
+#
+# STRATEGY:
+# 1. Create an array of badly formed arguments
+# 2. For each argument, execute 'zfs clone -o <volume>'
+# 3. Verify an error is returned.
+#
+
+verify_runnable "global"
+
+function cleanup
+{
+	if snapexists $SNAPFS1 ; then
+		log_must $ZFS destroy -Rf $SNAPFS1
+	fi
+}
+
+log_onexit cleanup
+
+log_assert "Verify 'zfs clone -o <volume>' fails with bad <volume> argument."
+
+log_must $ZFS snapshot $SNAPFS1
+
+typeset -i i=0
+while (( $i < ${#RW_VOL_PROP[*]} )); do
+	log_mustnot $ZFS clone -o ${RW_VOL_PROP[i]} -o ${RW_VOL_PROP[i]} \
+		$SNAPFS1 $TESTPOOL/$TESTCLONE
+	log_mustnot $ZFS clone -p -o ${RW_VOL_PROP[i]} -o ${RW_VOL_PROP[i]} \
+		$SNAPFS1 $TESTPOOL/$TESTCLONE
+	((i = i + 1))
+done
+
+i=0
+while (( $i < ${#FS_ONLY_PROP[*]} )); do
+	log_mustnot $ZFS clone  -o ${FS_ONLY_PROP[i]} \
+		$SNAPFS1 $TESTPOOL/$TESTCLONE
+	log_mustnot $ZFS clone -p -o ${FS_ONLY_PROP[i]} \
+		$SNAPFS1 $TESTPOOL/$TESTCLONE
+	((i = i + 1))
+done
+
+log_pass "Verify 'zfs clone -o <volume>' fails with bad <volume> argument."
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/usr/src/test/zfs-tests/tests/functional/cli_root/zfs_clone/zfs_clone_010_pos.ksh	Wed Dec 05 22:04:50 2012 -0500
@@ -0,0 +1,233 @@
+#!/bin/ksh
+#
+# CDDL HEADER START
+#
+# 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.
+#
+# CDDL HEADER END
+#
+
+#
+# Copyright (c) 2012 by Delphix. All rights reserved.
+#
+
+. $STF_SUITE/include/libtest.shlib
+
+#
+# DESCRIPTION:
+#	Verify 'zfs list -t all -o name,origin,clones' prints the correct
+#	clone information
+#
+# STRATEGY:
+#	1. Create datasets
+#	2. Create recursive snapshots and their clones
+#	3. Verify zfs clones property displays right information for different
+#	   cases
+#
+
+verify_runnable "both"
+
+function local_cleanup
+{
+	typeset -i i=1
+	for ds in $datasets; do
+                datasetexists $ds/$TESTCLONE.$i && \
+		    log_must $ZFS destroy -rf $ds/$TESTCLONE.$i
+                datasetexists $ds && log_must $ZFS destroy -Rf $ds
+		((i=i+1))
+	done
+}
+
+# Set up filesystem with clones
+function setup_ds
+{
+	typeset -i i=1
+	# create nested datasets
+	log_must $ZFS create -p $TESTPOOL/$TESTFS1/$TESTFS2/$TESTFS3
+
+	# verify dataset creation
+	for ds in $datasets; do
+		datasetexists $ds || log_fail "Create $ds dataset fail."
+	done
+
+	# create recursive nested snapshot
+	log_must $ZFS snapshot -r $TESTPOOL/$TESTFS1@snap
+	for ds in $datasets; do
+		datasetexists $ds@snap || \
+		    log_fail "Create $ds@snap snapshot fail."
+	done
+	for ds in $datasets; do
+		for fs in $datasets; do
+			log_must $ZFS clone $ds@snap $fs/$TESTCLONE.$i
+		done
+		((i=i+1))
+	done
+}
+
+# Verify clone list
+function verify_clones
+{
+	typeset -i no_clones=$1
+	typeset unexpected=$2
+	typeset clone_snap=$3
+	typeset -i i=1
+	for ds in $datasets; do
+		if [[ -n $clone_snap ]]; then
+			clone_snap=/$TESTCLONE.$i
+		fi
+		snapshot=$($ECHO "$names" | $GREP $ds$clone_snap@snap)
+		actual_clone=$($ZFS list -t all -o clones $snapshot | $TAIL -1)
+		save=$IFS
+		IFS=','
+		typeset -a clones=()
+		for token in $actual_clone; do
+			clones=( "${clones[@]}" "$token" )
+		done
+		IFS=$save
+		[[ ${#clones[*]} -ne $no_clones ]] && \
+		    log_fail "$snapshot has unexpected number of clones" \
+		        " ${#clones[*]}"
+		expected_clone=""
+		unexpected_clone=""
+		if [[ $unexpected -eq 1 ]]; then
+			for fs in $datasets; do
+				if [[ $fs == $ds ]]; then
+					if [[ -z $clone_snap ]]; then
+						unexpected_clone=$fs/$TESTCLONE.$i
+						(for match in ${clones[@]};do
+						[[ $match != $unexpected_clone ]] && \
+						    exit 0; done) || log_fail \
+					            "Unexpected clones of the snapshot"
+					else
+						expected_clone=$fs
+						unexpected_clone=$fs/$TESTCLONE.$i
+						(for match in ${clones[@]};do
+						[[ $match == $expected_clone ]] && \
+						    [[ $match != $unexpected_clone ]] \
+						    && exit 0; done) || log_fail \
+						    "Unexpected clones of the snapshot"
+					fi
+				else
+					expected_clone=$fs/$TESTCLONE.$i
+					(for match in ${clones[@]};do
+					[[ $match == $expected_clone ]] && \
+					    exit 0; done) || log_fail \
+					    "Unexpected clones of the snapshot"
+				fi
+			done
+		else
+			for fs in $datasets; do
+				expected_clone=$fs/$TESTCLONE.$i
+				(for match in ${clones[@]};do
+				[[ $match == $expected_clone ]] && exit 0; \
+				    done) || log_fail "Unexpected clones" \
+				    " of the snapshot"
+			done
+		fi
+		((i=i+1))
+	done
+}
+
+
+log_onexit local_cleanup
+datasets="$TESTPOOL/$TESTFS1 $TESTPOOL/$TESTFS1/$TESTFS2
+    $TESTPOOL/$TESTFS1/$TESTFS2/$TESTFS3"
+
+typeset -a d_clones
+typeset -a deferred_snaps
+typeset -i i
+i=1
+log_must setup_ds
+
+log_note "Verify zfs clone propery for multiple clones"
+names=$($ZFS list -rt all -o name $TESTPOOL)
+log_must verify_clones 3 0
+
+log_note "verfify clone property for clone deletion"
+i=1
+for ds in $datasets; do
+	log_must $ZFS destroy $ds/$TESTCLONE.$i
+	((i=i+1))
+done
+names=$($ZFS list -rt all -o name $TESTPOOL)
+i=1
+log_must verify_clones 2 1
+
+log_must local_cleanup
+log_must setup_ds
+
+log_note "verify zfs deferred destroy on clones property"
+i=1
+names=$($ZFS list -rt all -o name $TESTPOOL)
+for ds in $datasets; do
+	log_must $ZFS destroy -d $ds@snap
+	deferred_snaps=( "${deferred_snaps[@]}" "$ds@snap" )
+	((i=i+1))
+done
+log_must verify_clones 3 0
+
+log_note "verify zfs deferred destroy by destroying clones on clones property"
+d_clones=()
+i=1
+for ds in $datasets; do
+	for fs in $datasets; do
+		log_must $ZFS destroy $fs/$TESTCLONE.$i
+		d_clones=( "${d_clones[@]}" "$fs/$TESTCLONE.$i" )
+	done
+	((i=i+1))
+done
+names=$($ZFS list -rtall -o name $TESTPOOL)
+for snap in ${deferred_snaps[@]}; do
+	status=$($ECHO "$names" | $GREP $snap)
+	[[ -z $status ]] || \
+	    log_fail "$snap exist after deferred destroy"
+done
+for dclone in ${d_clones[@]}; do
+	log_note "D CLONE = $dclone"
+	status=$($ECHO "$names" | $GREP $dclone)
+	[[ -z $status ]] || \
+	    log_fail "$dclone exist after deferred destroy"
+done
+
+log_must local_cleanup
+log_must setup_ds
+log_note "verify clone property for zfs promote"
+i=1
+for ds in $datasets; do
+	log_must $ZFS promote $ds/$TESTCLONE.$i
+	((i=i+1))
+done
+names=$($ZFS list -rt all -o name,clones $TESTPOOL)
+log_must verify_clones 3 1 $TESTCLONE
+i=1
+for ds in $datasets; do
+	log_must $ZFS promote $ds
+	((i=i+1))
+done
+log_must local_cleanup
+
+log_note "verify clone list truncated correctly"
+typeset -i j=200
+i=1
+fs=$TESTPOOL/$TESTFS1
+log_must $ZFS create $fs
+log_must $ZFS snapshot $fs@snap
+while((i < 7)); do
+	log_must $ZFS clone $fs@snap $fs/$TESTCLONE$(python -c 'print "x" * 200').$i
+	((i=i+1))
+	((j=j+200))
+done
+clone_list=$($ZFS list -o clones $fs@snap)
+char_count=$($ECHO "$clone_list" | $TAIL -1 | wc | $AWK '{print $3}')
+[[ $char_count -eq 1024 ]] || \
+    log_fail "Clone list not truncated correctly. Unexpected character count" \
+        "$char_count"
+
+log_pass "'zfs list -o name,origin,clones prints the correct clone information."
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/usr/src/test/zfs-tests/tests/functional/cli_root/zfs_copies/Makefile	Wed Dec 05 22:04:50 2012 -0500
@@ -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) 2012 by Delphix. All rights reserved.
+#
+
+include $(SRC)/Makefile.master
+
+ROOTOPTPKG = $(ROOT)/opt/zfs-tests
+TESTDIR = $(ROOTOPTPKG)/tests/functional/cli_root/zfs_copies
+
+PROGS = cleanup \
+	setup \
+	zfs_copies_001_pos \
+	zfs_copies_002_pos \
+	zfs_copies_003_pos \
+	zfs_copies_004_neg \
+	zfs_copies_005_neg \
+	zfs_copies_006_pos
+
+FILES = zfs_copies.cfg \
+	zfs_copies.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	Thu Jan 01 00:00:00 1970 +0000
+++ b/usr/src/test/zfs-tests/tests/functional/cli_root/zfs_copies/cleanup.ksh	Wed Dec 05 22:04:50 2012 -0500
@@ -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) 2012 by Delphix. All rights reserved.
+#
+
+. $STF_SUITE/tests/functional/cli_root/zfs_copies/zfs_copies.kshlib
+. $STF_SUITE/tests/functional/cli_root/zfs_copies/zfs_copies.cfg
+
+#
+# umount the ufs fs if there is timedout in the ufs test
+#
+
+if ismounted $UFS_MNTPOINT ufs ; then
+	log_must $UMOUNT -f $UFS_MNTPOINT
+	$RM -fr $UFS_MNTPOINT
+fi
+
+default_cleanup
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/usr/src/test/zfs-tests/tests/functional/cli_root/zfs_copies/setup.ksh	Wed Dec 05 22:04:50 2012 -0500
@@ -0,0 +1,31 @@
+#!/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.
+#
+
+. $STF_SUITE/include/libtest.shlib
+
+DISK=${DISKS%% *}
+default_volume_setup $DISK
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/usr/src/test/zfs-tests/tests/functional/cli_root/zfs_copies/zfs_copies.cfg	Wed Dec 05 22:04:50 2012 -0500
@@ -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 2007 Sun Microsystems, Inc.  All rights reserved.
+# Use is subject to license terms.
+#
+
+#
+# Copyright (c) 2012 by Delphix. All rights reserved.
+#
+
+export ZPOOL_VERSION_1_FILES="zfs-pool-v1.dat.bz2"
+export ZPOOL_VERSION_1_NAME="v1-pool"
+
+export FILESIZE=10m
+export FILE=file.copies
+export SLEEPTIME=30
+export UFS_MNTPOINT=/testdir_nfs_mntpoint
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/usr/src/test/zfs-tests/tests/functional/cli_root/zfs_copies/zfs_copies.kshlib	Wed Dec 05 22:04:50 2012 -0500
@@ -0,0 +1,144 @@
+#
+# CDDL HEADER START
+#
+# The contents of this file are subject to the terms of the
+# Common Development and Distribution License (the "License").
+# You may not use this file except in compliance with the License.
+#
+# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
+# or http://www.opensolaris.org/os/licensing.
+# See the License for the specific language governing permissions
+# and limitations under the License.
+#
+# When distributing Covered Code, include this CDDL HEADER in each
+# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
+# If applicable, add the following below this CDDL 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.
+#
+
+. $STF_SUITE/include/libtest.shlib
+. $STF_SUITE/tests/functional/cli_root/zfs_copies/zfs_copies.cfg
+
+#
+# Compare the value of copies property with specified value
+# $1, the dataset name
+# $2, the expected copies value
+#
+function cmp_prop
+{
+	typeset ds=$1
+	typeset	val_expect=$2
+	typeset val_actual
+
+	val_actual=$(get_prop copies $ds)
+	if [[ $val_actual != $val_expect ]]; then
+		log_fail "Expected value ($val_expect) != actual value " \
+		    "($val_actual)"
+	fi
+}
+
+#
+# Get the value of property used via zfs list
+# $1, the dataset name
+#
+function get_used_prop
+{
+	typeset ds=$1
+	typeset used
+
+	used=`$ZFS list -H -o used $ds`
+	used=${used%[m|M]}
+	if [[ $used == *K ]]; then
+		used=0
+	fi
+	$ECHO $used
+}
+
+#
+# Check the used space is charged correctly
+# $1, the number of used space
+# $2, the expected common factor between the used space and the file space
+#
+function check_used
+{
+	typeset charged_spc=$1
+	typeset -i used
+	typeset -i expected_cfactor=$2
+	typeset -i cfactor
+	typeset -i fsize=${FILESIZE%[m|M]}
+
+	((used = ${charged_spc%[m|M]}))
+	((cfactor = used / fsize))
+	if ((cfactor != expected_cfactor)); then
+		log_fail "The space is not charged correctly while setting" \
+		    "copies as $expected_cfactor."
+	fi
+}
+
+#
+# test ncopies on volume
+# $1  test type zfs|ufs, default zfs
+# $2  copies
+# $3  mntp for ufs test
+function do_vol_test
+{
+	typeset type=$1
+	typeset copy=$2
+	typeset mntp=$3
+
+	vol=$TESTPOOL/$TESTVOL1
+	vol_b_path=/dev/zvol/dsk/$TESTPOOL/$TESTVOL1
+	vol_r_path=/dev/zvol/rdsk/$TESTPOOL/$TESTVOL1
+
+	log_must $ZFS create -V $VOLSIZE -o copies=$copy $vol
+	log_must $ZFS set refreservation=none $vol
+	if [[ $type == "ufs" ]]; then
+		log_must $ECHO y | $NEWFS $vol_r_path >/dev/null 2>&1
+		log_must $MOUNT -F ufs -o rw $vol_b_path $mntp
+	else
+		log_must $ZPOOL create $TESTPOOL1 $vol_b_path
+		log_must $ZFS create $TESTPOOL1/$TESTFS1
+	fi
+
+	((nfilesize = copy * ${FILESIZE%m}))
+	pre_used=$(get_used_prop $vol)
+	((target_size = pre_used + nfilesize))
+
+	if [[ $type == "ufs" ]]; then
+		log_must $MKFILE $FILESIZE $mntp/$FILE
+	else
+		log_must $MKFILE $FILESIZE /$TESTPOOL1/$TESTFS1/$FILE
+	fi
+
+	post_used=$(get_used_prop $vol)
+	while ((post_used < target_size)) ; do
+		sleep 1
+		post_used=$(get_used_prop $vol)
+	done
+
+	((used = post_used - pre_used))
+	if ((used < nfilesize)); then
+		log_fail "The space is not charged correctly while setting" \
+		    "copies as $copy"
+	fi
+
+	if [[ $type == "ufs" ]]; then
+		$UMOUNT $mntp
+	else
+		log_must $ZPOOL destroy $TESTPOOL1
+	fi
+
+	log_must $ZFS destroy $vol
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/usr/src/test/zfs-tests/tests/functional/cli_root/zfs_copies/zfs_copies_001_pos.ksh	Wed Dec 05 22:04:50 2012 -0500
@@ -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 2007 Sun Microsystems, Inc.  All rights reserved.
+# Use is subject to license terms.
+#
+
+. $STF_SUITE/include/libtest.shlib
+. $STF_SUITE/tests/functional/cli_root/zfs_copies/zfs_copies.kshlib
+
+#
+# DESCRIPTION:
+#	Verify "copies" property can be correctly set as 1,2 and 3 and different
+#	filesystem can have different value of "copies" property within the same pool.
+#
+# STRATEGY:
+#	1. Create different filesystems with copies set as 1,2,3;
+#	2. Verify that the "copies" property has been set correctly
+#
+
+verify_runnable "both"
+
+function cleanup
+{
+	typeset ds
+
+	for ds in $fs1 $fs2 $vol1 $vol2; do
+		if datasetexists $ds; then
+			log_must $ZFS destroy $ds
+		fi
+	done
+}
+
+log_assert "Verify 'copies' property with correct arguments works or not."
+log_onexit cleanup
+
+fs=$TESTPOOL/$TESTFS
+fs1=$TESTPOOL/$TESTFS1
+fs2=$TESTPOOL/$TESTFS2
+vol=$TESTPOOL/$TESTVOL
+vol1=$TESTPOOL/$TESTVOL1
+vol2=$TESTPOOL/$TESTVOL2
+
+#
+# Check the default value for copies property
+#
+for ds in $fs $vol; do
+	cmp_prop $ds 1
+done
+
+for val in 1 2 3; do
+	log_must $ZFS create -o copies=$val $fs1
+	if is_global_zone; then
+		log_must $ZFS create -V $VOLSIZE -o copies=$val $vol1
+	else
+		log_must $ZFS create -o copies=$val $vol1
+	fi
+	for ds in $fs1 $vol1; do
+		cmp_prop $ds $val
+	done
+
+	for val2 in 3 2 1; do
+		log_must $ZFS create -o copies=$val2 $fs2
+		if is_global_zone; then
+			log_must $ZFS create -V $VOLSIZE -o copies=$val2 $vol2
+		else
+			log_must $ZFS create -o copies=$val2 $vol2
+		fi
+		for ds in $fs2 $vol2; do
+			cmp_prop $ds $val2
+			log_must $ZFS destroy $ds
+		done
+	done
+
+	for ds in $fs1 $vol1; do
+		log_must $ZFS destroy $ds
+	done
+
+done
+
+for val in 3 2 1; do
+	for ds in $fs $vol; do
+		log_must $ZFS set copies=$val $ds
+		cmp_prop $ds $val
+	done
+done
+
+log_pass "'copies' property with correct arguments works as expected. "
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/usr/src/test/zfs-tests/tests/functional/cli_root/zfs_copies/zfs_copies_002_pos.ksh	Wed Dec 05 22:04:50 2012 -0500
@@ -0,0 +1,99 @@
+#!/bin/ksh
+#
+# CDDL HEADER START
+#
+# The contents of this file are subject to the terms of the
+# Common Development and Distribution License (the "License").
+# You may not use this file except in compliance with the License.
+#
+# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
+# or http://www.opensolaris.org/os/licensing.
+# See the License for the specific language governing permissions
+# and limitations under the License.
+#
+# When distributing Covered Code, include this CDDL HEADER in each
+# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
+# If applicable, add the following below this CDDL HEADER, with the
+# fields enclosed by brackets "[]" replaced with your own identifying
+# information: Portions Copyright [yyyy] [name of copyright owner]
+#
+# CDDL HEADER END
+#
+
+#
+# Copyright 2007 Sun Microsystems, Inc.  All rights reserved.
+# Use is subject to license terms.
+#
+
+. $STF_SUITE/include/libtest.shlib
+. $STF_SUITE/tests/functional/cli_root/zfs_copies/zfs_copies.kshlib
+
+#
+# DESCRIPTION:
+#	Verify that the space used by multiple copies is charged correctly
+#
+# STRATEGY:
+#	1. Create filesystems with copies set as 2,3 respectively;
+#	2. Copy specified size data into each filesystem;
+#	3. Verify that the space is charged as expected with zfs list, ls -s, df(1m),
+#	   du(1) commands;
+#
+
+verify_runnable "both"
+
+function cleanup
+{
+	typeset val
+
+	for val in 1 2 3; do
+		if datasetexists $TESTPOOL/fs_$val; then
+			log_must $ZFS destroy $TESTPOOL/fs_$val
+		fi
+	done
+}
+
+log_assert "Verify that the space used by multiple copies is charged correctly."
+log_onexit cleanup
+
+for val in 1 2 3; do
+	log_must $ZFS create -o copies=$val $TESTPOOL/fs_$val
+
+	log_must $MKFILE $FILESIZE /$TESTPOOL/fs_$val/$FILE
+done
+
+#
+# Sync up the filesystem
+#
+$SYNC
+
+#
+# Verify 'zfs list' can correctly list the space charged
+#
+log_note "Verify 'zfs list' can correctly list the space charged."
+fsize=${FILESIZE%[m|M]}
+for val in 1 2 3; do
+	used=$(get_used_prop $TESTPOOL/fs_$val)
+	check_used $used $val
+done
+
+log_note "Verify 'ls -s' can correctly list the space charged."
+for val in 1 2 3; do
+	blks=`$LS -ls /$TESTPOOL/fs_$val/$FILE | $AWK '{print $1}'`
+	(( used = blks * 512 / (1024 * 1024) ))
+	check_used $used $val
+done
+
+log_note "Verify df(1M) can corectly display the space charged."
+for val in 1 2 3; do
+	used=`$DF -F zfs -h /$TESTPOOL/fs_$val/$FILE | $GREP $TESTPOOL/fs_$val \
+		| $AWK '{print $3}'`
+	check_used $used $val
+done
+
+log_note "Verify du(1) can correctly display the space charged."
+for val in 1 2 3; do
+	used=`$DU -h /$TESTPOOL/fs_$val/$FILE | $AWK '{print $1}'`
+	check_used $used $val
+done
+
+log_pass "The space used by multiple copies is charged correctly as expected. "
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/usr/src/test/zfs-tests/tests/functional/cli_root/zfs_copies/zfs_copies_003_pos.ksh	Wed Dec 05 22:04:50 2012 -0500
@@ -0,0 +1,64 @@
+#!/bin/ksh
+#
+# CDDL HEADER START
+#
+# The contents of this file are subject to the terms of the
+# Common Development and Distribution License (the "License").
+# You may not use this file except in compliance with the License.
+#
+# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
+# or http://www.opensolaris.org/os/licensing.
+# See the License for the specific language governing permissions
+# and limitations under the License.
+#
+# When distributing Covered Code, include this CDDL HEADER in each
+# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
+# If applicable, add the following below this CDDL HEADER, with the
+# fields enclosed by brackets "[]" replaced with your own identifying
+# information: Portions Copyright [yyyy] [name of copyright owner]
+#
+# CDDL HEADER END
+#
+
+#
+# Copyright 2007 Sun Microsystems, Inc.  All rights reserved.
+# Use is subject to license terms.
+#
+
+. $STF_SUITE/tests/functional/cli_root/zfs_copies/zfs_copies.kshlib
+
+#
+# DESCRIPTION:
+#	Verify that the volume space used by multiple copies is charged correctly
+#
+# STRATEGY:
+#	1. Create volume;
+#	2. Create ZFS filesystem based on the volume;
+#	3. Set the copies property of volume to 1,2 or 3;
+#	4. Copy specified size data into each filesystem;
+#	5. Verify that the volume space is charged as expected.
+#
+
+verify_runnable "global"
+
+function cleanup
+{
+	if poolexists $TESTPOOL1; then
+		destroy_pool $TESTPOOL1
+	fi
+
+	if datasetexists $vol; then
+		log_must $ZFS destroy $vol
+	fi
+}
+
+log_assert "Verify that ZFS volume space used by multiple copies is charged correctly."
+log_onexit cleanup
+vol=$TESTPOOL/$TESTVOL1
+
+
+for val in 1 2 3; do
+	do_vol_test zfs $val
+done
+
+log_pass "The volume space used by multiple copies is charged correctly as expected. "
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/usr/src/test/zfs-tests/tests/functional/cli_root/zfs_copies/zfs_copies_004_neg.ksh	Wed Dec 05 22:04:50 2012 -0500
@@ -0,0 +1,53 @@
+#!/bin/ksh
+#
+# CDDL HEADER START
+#
+# The contents of this file are subject to the terms of the
+# Common Development and Distribution License (the "License").
+# You may not use this file except in compliance with the License.
+#
+# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
+# or http://www.opensolaris.org/os/licensing.
+# See the License for the specific language governing permissions
+# and limitations under the License.
+#
+# When distributing Covered Code, include this CDDL HEADER in each
+# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
+# If applicable, add the following below this CDDL 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.
+#
+
+. $STF_SUITE/include/libtest.shlib
+. $STF_SUITE/tests/functional/cli_root/zfs_copies/zfs_copies.kshlib
+
+#
+# DESCRIPTION:
+#	Verify that copies cannot be set to other value except for 1, 2 or 3
+#
+# STRATEGY:
+#	1. Create filesystems with copies set as any value other than 1, 2 or 3
+#	2. Verify that the create operations fail
+#
+
+verify_runnable "both"
+
+log_assert "Verify that copies property cannot be set to any value other than 1,2 or 3"
+
+set -A badval 0 01 02 03 0 -1 -2 -3 10 20 30 4 5 6 ? * blah
+
+for val in ${badval[@]}; do
+	log_mustnot $ZFS create -o copies=$val $TESTPOOL/$TESTFS1
+	log_mustnot $ZFS create -V $VOLSIZE -o copies=$val $TESTPOOL/$TESTVOL1
+	log_mustnot $ZFS set copies=$val $TESTPOOL/$TESTFS
+	log_mustnot $ZFS set copies=$val $TESTPOOL/$TESTVOL
+done
+
+log_pass "The copies property cannot be set to any value other than 1,2 or 3 as expected"
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/usr/src/test/zfs-tests/tests/functional/cli_root/zfs_copies/zfs_copies_005_neg.ksh	Wed Dec 05 22:04:50 2012 -0500
@@ -0,0 +1,71 @@
+#!/bin/ksh
+#
+# CDDL HEADER START
+#
+# The contents of this file are subject to the terms of the
+# Common Development and Distribution License (the "License").
+# You may not use this file except in compliance with the License.
+#
+# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
+# or http://www.opensolaris.org/os/licensing.
+# See the License for the specific language governing permissions
+# and limitations under the License.
+#
+# When distributing Covered Code, include this CDDL HEADER in each
+# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
+# If applicable, add the following below this CDDL 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.
+#
+
+. $STF_SUITE/include/libtest.shlib
+. $STF_SUITE/tests/functional/cli_root/zfs_copies/zfs_copies.kshlib
+
+#
+# DESCRIPTION:
+#	Verify that copies cannot be set with pool version 1
+#
+# STRATEGY:
+#	1. Create filesystems with copies set in a pool with version 1
+#	2. Verify that the create operations fail
+#
+
+verify_runnable "global"
+
+function cleanup
+{
+	if poolexists $ZPOOL_VERSION_1_NAME; then
+		destroy_pool $ZPOOL_VERSION_1_NAME
+	fi
+
+	if [[ -f $TESTDIR/$ZPOOL_VERSION_1_FILES ]]; then
+		rm -f $TESTDIR/$ZPOOL_VERSION_1_FILES
+	fi
+}
+
+log_assert "Verify that copies cannot be set with pool version 1"
+log_onexit cleanup
+
+$CP $STF_SUITE/tests/functional/cli_root/zpool_upgrade/blockfiles/$ZPOOL_VERSION_1_FILES $TESTDIR
+$BUNZIP2 $TESTDIR/$ZPOOL_VERSION_1_FILES
+log_must $ZPOOL import -d $TESTDIR $ZPOOL_VERSION_1_NAME
+log_must $ZFS create $ZPOOL_VERSION_1_NAME/$TESTFS
+log_must $ZFS create -V 1m $ZPOOL_VERSION_1_NAME/$TESTVOL
+
+for val in 3 2 1; do
+	for ds in $ZPOOL_VERSION_1_NAME/$TESTFS $ZPOOL_VERSION_1_NAME/$TESTVOL; do
+		log_mustnot $ZFS set copies=$val $ds
+	done
+	for ds in $ZPOOL_VERSION_1_NAME/$TESTFS1 $ZPOOL_VERSION_1_NAME/$TESTVOL1; do
+		log_mustnot $ZFS create -o copies=$val $ds
+	done
+done
+
+log_pass "Verification pass: copies cannot be set with pool version 1. "
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/usr/src/test/zfs-tests/tests/functional/cli_root/zfs_copies/zfs_copies_006_pos.ksh	Wed Dec 05 22:04:50 2012 -0500
@@ -0,0 +1,73 @@
+#!/bin/ksh
+#
+# CDDL HEADER START
+#
+# The contents of this file are subject to the terms of the
+# Common Development and Distribution License (the "License").
+# You may not use this file except in compliance with the License.
+#
+# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
+# or http://www.opensolaris.org/os/licensing.
+# See the License for the specific language governing permissions
+# and limitations under the License.
+#
+# When distributing Covered Code, include this CDDL HEADER in each
+# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
+# If applicable, add the following below this CDDL 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.
+#
+
+. $STF_SUITE/tests/functional/cli_root/zfs_copies/zfs_copies.kshlib
+
+#
+# DESCRIPTION:
+#	Verify that the volume space used by multiple copies is charged correctly
+#
+# STRATEGY:
+#	1. Create volume
+#	2. Create UFS filesystem based on the volume
+#	3. Set the copies property of volume to 1,2 or 3
+#	4. Copy specified size data into each filesystem
+#	5. Verify that the volume space is charged as expected
+#
+
+verify_runnable "global"
+
+function cleanup
+{
+	if ismounted $mntp ufs ; then
+		log_must $UMOUNT $mntp
+	fi
+
+	if datasetexists $vol; then
+		log_must $ZFS destroy $vol
+	fi
+
+	if [[ -d $mntp ]]; then
+                $RM -rf $mntp
+        fi
+}
+
+
+log_assert "Verify that ZFS volume space used by multiple copies is charged correctly."
+log_onexit cleanup
+mntp=$UFS_MNTPOINT
+vol=$TESTPOOL/$TESTVOL1
+
+if [[ ! -d $mntp ]]; then
+	$MKDIR -p $mntp
+fi
+
+for val in 1 2 3; do
+	do_vol_test ufs $val $mntp
+done
+
+log_pass "The volume space used by multiple copies is charged correctly as expected. "
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/usr/src/test/zfs-tests/tests/functional/cli_root/zfs_create/Makefile	Wed Dec 05 22:04:50 2012 -0500
@@ -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) 2012 by Delphix. All rights reserved.
+#
+
+include $(SRC)/Makefile.master
+
+ROOTOPTPKG = $(ROOT)/opt/zfs-tests
+TESTDIR = $(ROOTOPTPKG)/tests/functional/cli_root/zfs_create
+
+PROGS = cleanup \
+	setup \
+	zfs_create_001_pos \
+	zfs_create_002_pos \
+	zfs_create_003_pos \
+	zfs_create_004_pos \
+	zfs_create_005_pos \
+	zfs_create_006_pos \
+	zfs_create_007_pos \
+	zfs_create_008_neg \
+	zfs_create_009_neg \
+	zfs_create_010_neg \
+	zfs_create_011_pos \
+	zfs_create_012_pos \
+	zfs_create_013_pos
+
+FILES = properties.kshlib \
+	zfs_create_common.kshlib \
+	zfs_create.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	Thu Jan 01 00:00:00 1970 +0000
+++ b/usr/src/test/zfs-tests/tests/functional/cli_root/zfs_create/cleanup.ksh	Wed Dec 05 22:04:50 2012 -0500
@@ -0,0 +1,30 @@
+#!/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.
+#
+
+. $STF_SUITE/include/libtest.shlib
+
+default_cleanup
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/usr/src/test/zfs-tests/tests/functional/cli_root/zfs_create/properties.kshlib	Wed Dec 05 22:04:50 2012 -0500
@@ -0,0 +1,77 @@
+#
+# CDDL HEADER START
+#
+# The contents of this file are subject to the terms of the
+# Common Development and Distribution License (the "License").
+# You may not use this file except in compliance with the License.
+#
+# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
+# or http://www.opensolaris.org/os/licensing.
+# See the License for the specific language governing permissions
+# and limitations under the License.
+#
+# When distributing Covered Code, include this CDDL HEADER in each
+# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
+# If applicable, add the following below this CDDL 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) 2012 by Delphix. All rights reserved.
+#
+
+set -A RW_FS_PROP "quota=512M" \
+		  "reservation=512M" \
+		  "recordsize=64K" \
+		  "mountpoint=/tmp/mnt$$" \
+		  "checksum=fletcher2" \
+		  "compression=lzjb" \
+		  "atime=off" \
+		  "devices=off" \
+		  "exec=off" \
+		  "setuid=off" \
+		  "readonly=on" \
+		  "snapdir=visible" \
+		  "aclmode=discard" \
+		  "aclinherit=discard" \
+		  "canmount=off" \
+		  "local:department=123"
+
+is_global_zone && \
+	set -A RW_FS_PROP ${RW_FS_PROP[*]} "sharenfs=on" "zoned=on"
+
+set -A RW_VOL_PROP "volblocksize=16K" \
+		   "checksum=fletcher2" \
+		   "compression=lzjb" \
+		   "readonly=on" \
+		   "local:department=123"
+
+set -A RW_VOL_CLONE_PROP "checksum=fletcher2" \
+		   "compression=lzjb" \
+		   "readonly=on" \
+		   "local:department=123"
+
+set -A FS_ONLY_PROP "quota=512M" \
+                    "recordsize=64K" \
+                    "mountpoint=/tmp/mnt$$" \
+                    "sharenfs=on" \
+                    "atime=off" \
+                    "devices=off" \
+                    "exec=off" \
+                    "setuid=off" \
+                    "zoned=on" \
+                    "snapdir=visible" \
+                    "aclmode=discard" \
+                    "aclinherit=discard" \
+		    "canmount=off" \
+		    "version=1"
+
+set -A VOL_ONLY_PROP "volblocksize=16K" "volsize=512M"
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/usr/src/test/zfs-tests/tests/functional/cli_root/zfs_create/setup.ksh	Wed Dec 05 22:04:50 2012 -0500
@@ -0,0 +1,32 @@
+#!/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.
+#
+
+. $STF_SUITE/include/libtest.shlib
+
+DISK=${DISKS%% *}
+
+default_setup $DISK
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/usr/src/test/zfs-tests/tests/functional/cli_root/zfs_create/zfs_create.cfg	Wed Dec 05 22:04:50 2012 -0500
@@ -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 2007 Sun Microsystems, Inc.  All rights reserved.
+# Use is subject to license terms.
+#
+
+#
+# Copyright (c) 2012 by Delphix. All rights reserved.
+#
+
+export BYND_MAX_NAME="byondmaxnamelength\
+012345678901234567890123456789\
+012345678901234567890123456789\
+012345678901234567890123456789\
+012345678901234567890123456789\
+012345678901234567890123456789\
+012345678901234567890123456789\
+012345678901234567890123456789\
+012345678901234567890123456789"
+
+# 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"
+
+set -A size "8k" "8K" "1m" "1M" "1mb" "1mB" "1Mb" "1MB" "1g" "1G" \
+	"1p" "1P" "1z" "1Z" "1gb" "1gB" "1Gb" "1GB" "1pb" "1pB" "1Pb" \
+	"1PB" "1zb" "1zB" "1Zb" "1ZB"
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/usr/src/test/zfs-tests/tests/functional/cli_root/zfs_create/zfs_create_001_pos.ksh	Wed Dec 05 22:04:50 2012 -0500
@@ -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.
+#
+. $STF_SUITE/include/libtest.shlib
+
+#
+# DESCRIPTION:
+# 'zfs create <filesystem>' can create a ZFS filesystem in the namespace.
+#
+# STRATEGY:
+# 1. Create a ZFS filesystem in the storage pool
+# 2. Verify the filesystem created successfully
+#
+
+verify_runnable "both"
+
+
+function cleanup
+{
+	typeset -i i=0
+	while (( $i < ${#datasets[*]} )); do
+		datasetexists ${datasets[$i]} && \
+			log_must $ZFS destroy -f ${datasets[$i]}
+		((i = i + 1))
+	done
+}
+
+log_onexit cleanup
+
+set -A datasets "$TESTPOOL/$TESTFS1" "$TESTPOOL/$LONGFSNAME" "$TESTPOOL/..." \
+		"$TESTPOOL/_1234_"
+
+log_assert "'zfs create <filesystem>' can create a ZFS filesystem in the namespace."
+
+typeset -i i=0
+while (( $i < ${#datasets[*]} )); do
+	log_must $ZFS create ${datasets[$i]}
+	datasetexists ${datasets[$i]} || \
+		log_fail "zfs create ${datasets[$i]} fail."
+	((i = i + 1))
+done
+
+log_pass "'zfs create <filesystem>' works as expected."
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/usr/src/test/zfs-tests/tests/functional/cli_root/zfs_create/zfs_create_002_pos.ksh	Wed Dec 05 22:04:50 2012 -0500
@@ -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.
+#
+. $STF_SUITE/include/libtest.shlib
+. $STF_SUITE/tests/functional/cli_root/zfs_create/zfs_create.cfg
+
+#
+# DESCRIPTION:
+# 'zfs create -s -V <size> <volume>' can create various-size sparse volume.
+#
+# STRATEGY:
+# 1. Create a volume in the storage pool.
+# 2. Verify the volume is created correctly.
+#
+
+verify_runnable "global"
+
+function cleanup
+{
+	typeset -i j=0
+	while [[ $j -lt ${#size[*]} ]]; do
+		if datasetexists $TESTPOOL/${TESTVOL}${size[j]}; then
+			log_must $ZFS destroy $TESTPOOL/${TESTVOL}${size[j]}
+		fi
+		((j = j + 1))
+	done
+}
+
+log_onexit cleanup
+
+
+log_assert "'zfs create -s -V <size> <volume>' succeeds"
+
+typeset -i j=0
+while (( $j < ${#size[*]} )); do
+	typeset cmdline="$ZFS create -s -V ${size[j]}  \
+			 $TESTPOOL/${TESTVOL}${size[j]}"
+
+	str=$(eval $cmdline 2>&1)
+	if (( $? == 0 )); then
+		log_note "SUCCESS: $cmdline"
+		log_must datasetexists $TESTPOOL/${TESTVOL}${size[j]}
+	elif [[ $str == *${VOL_LIMIT_KEYWORD1}* || \
+		$str == *${VOL_LIMIT_KEYWORD2}* || \
+		$str == *${VOL_LIMIT_KEYWORD3}* ]]
+	then
+		log_note "UNSUPPORTED: $cmdline"
+	else
+		log_fail "$cmdline"
+	fi
+
+	((j = j + 1))
+
+done
+log_pass "'zfs create -s -V <size> <volume>' works as expected."
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/usr/src/test/zfs-tests/tests/functional/cli_root/zfs_create/zfs_create_003_pos.ksh	Wed Dec 05 22:04:50 2012 -0500
@@ -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) 2012 by Delphix. All rights reserved.
+#
+
+. $STF_SUITE/include/libtest.shlib
+. $STF_SUITE/tests/functional/cli_root/zfs_create/zfs_create.cfg
+
+#
+# DESCRIPTION:
+# 'zfs create [-b <blocksize>] -V <size> <volume>' can create a volume
+# with specified blocksize, which is power of 2 between 512 - 128k.
+#
+# STRATEGY:
+# 1. Create a volume with blocksize in the storage pool
+# 2. Verify the volume created successfully
+#
+
+verify_runnable "global"
+
+function cleanup
+{
+	datasetexists $vol && \
+		log_must $ZFS destroy -f $vol
+}
+
+log_assert "Verify creating volume with specified blocksize works."
+log_onexit cleanup
+
+set -A options "" "-b 1k" "-b 1K" "-b 1024" "-b 1024b"
+vol=$TESTPOOL/$TESTVOL
+
+typeset -i i=0
+while (( i < ${#options[*]} )); do
+	log_must $ZFS create ${options[i]} -V $VOLSIZE $vol
+	datasetexists $vol || \
+		log_fail "zfs create ${options[i]} -V $VOLSIZE $vol fail."
+
+	log_must $ZFS destroy -f $vol
+	((i = i + 1))
+done
+
+log_pass "'zfs create [-b <blocksize>] -V <size> <volume>' works as expected."
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/usr/src/test/zfs-tests/tests/functional/cli_root/zfs_create/zfs_create_004_pos.ksh	Wed Dec 05 22:04:50 2012 -0500
@@ -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.
+#
+
+. $STF_SUITE/include/libtest.shlib
+. $STF_SUITE/tests/functional/cli_root/zfs_create/zfs_create_common.kshlib
+. $STF_SUITE/tests/functional/cli_root/zfs_create/properties.kshlib
+
+#
+# DESCRIPTION:
+# 'zfs create -o property=value filesystem' can successfully create a ZFS
+# filesystem with correct property set.
+#
+# STRATEGY:
+# 1. Create a ZFS filesystem in the storage pool with -o option
+# 2. Verify the filesystem created successfully
+# 3. Verify the property is correctly set
+#
+
+verify_runnable "both"
+
+function cleanup
+{
+	datasetexists $TESTPOOL/$TESTFS1 && \
+		log_must $ZFS destroy -f $TESTPOOL/$TESTFS1
+}
+
+log_onexit cleanup
+
+
+log_assert "'zfs create -o property=value filesystem' can successfully create \
+	   a ZFS filesystem with correct property set."
+
+typeset -i i=0
+while (( $i < ${#RW_FS_PROP[*]} )); do
+	log_must $ZFS create -o ${RW_FS_PROP[$i]} $TESTPOOL/$TESTFS1
+	datasetexists $TESTPOOL/$TESTFS1 || \
+		log_fail "zfs create $TESTPOOL/$TESTFS1 fail."
+	propertycheck $TESTPOOL/$TESTFS1 ${RW_FS_PROP[i]} || \
+		log_fail "${RW_FS_PROP[i]} is failed to set."
+	log_must $ZFS destroy -f $TESTPOOL/$TESTFS1
+	(( i = i + 1 ))
+done
+
+log_pass "'zfs create -o property=value filesystem' can successfully create \
+         a ZFS filesystem with correct property set."
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/usr/src/test/zfs-tests/tests/functional/cli_root/zfs_create/zfs_create_005_pos.ksh	Wed Dec 05 22:04:50 2012 -0500
@@ -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 2009 Sun Microsystems, Inc.  All rights reserved.
+# Use is subject to license terms.
+#
+
+. $STF_SUITE/include/libtest.shlib
+. $STF_SUITE/tests/functional/cli_root/zfs_create/zfs_create_common.kshlib
+. $STF_SUITE/tests/functional/cli_root/zfs_create/properties.kshlib
+
+#
+# DESCRIPTION:
+# 'zfs create -o property=value filesystem' can successfully create a ZFS
+# filesystem with multiple properties set.
+#
+# STRATEGY:
+# 1. Create a ZFS filesystem in the storage pool with multiple -o options
+# 2. Verify the filesystem created successfully
+# 3. Verify the properties are correctly set
+#
+
+verify_runnable "both"
+
+function cleanup
+{
+	datasetexists $TESTPOOL/$TESTFS1 && \
+		log_must $ZFS destroy -f $TESTPOOL/$TESTFS1
+}
+
+log_onexit cleanup
+
+
+log_assert "'zfs create -o property=value filesystem' can successfully create \
+	   a ZFS filesystem with multiple properties set."
+
+typeset -i i=0
+typeset opts=""
+
+while (( $i < ${#RW_FS_PROP[*]} )); do
+        if [[ ${RW_FS_PROP[$i]} != *"checksum"* ]]; then
+		opts="$opts -o ${RW_FS_PROP[$i]}"
+	fi
+	(( i = i + 1 ))
+done
+
+log_must $ZFS create $opts $TESTPOOL/$TESTFS1
+datasetexists $TESTPOOL/$TESTFS1 || \
+	log_fail "zfs create $TESTPOOL/$TESTFS1 fail."
+
+i=0
+while (( $i < ${#RW_FS_PROP[*]} )); do
+        if [[ ${RW_FS_PROP[$i]} != *"checksum"* ]]; then
+		propertycheck $TESTPOOL/$TESTFS1 ${RW_FS_PROP[i]} || \
+			log_fail "${RW_FS_PROP[i]} is failed to set."
+	fi
+	(( i = i + 1 ))
+done
+
+log_pass "'zfs create -o property=value filesystem' can successfully create \
+         a ZFS filesystem with multiple properties set."
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/usr/src/test/zfs-tests/tests/functional/cli_root/zfs_create/zfs_create_006_pos.ksh	Wed Dec 05 22:04:50 2012 -0500
@@ -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 2009 Sun Microsystems, Inc.  All rights reserved.
+# Use is subject to license terms.
+#
+
+#
+# Copyright (c) 2012 by Delphix. All rights reserved.
+#
+
+. $STF_SUITE/include/libtest.shlib
+. $STF_SUITE/tests/functional/cli_root/zfs_create/zfs_create.cfg
+. $STF_SUITE/tests/functional/cli_root/zfs_create/zfs_create_common.kshlib
+. $STF_SUITE/tests/functional/cli_root/zfs_create/properties.kshlib
+
+#
+# DESCRIPTION:
+# 'zfs create -o property=value -V size volume' can successfully create a ZFS
+# volume with correct property set.
+#
+# STRATEGY:
+# 1. Create a ZFS volume in the storage pool with -o option
+# 2. Verify the volume created successfully
+# 3. Verify the property is correctly set
+#
+
+verify_runnable "global"
+
+function cleanup
+{
+	datasetexists $TESTPOOL/$TESTVOL1 && \
+		log_must $ZFS destroy -f $TESTPOOL/$TESTVOL1
+}
+
+log_onexit cleanup
+
+
+log_assert "'zfs create -o property=value -V size volume' can successfully \
+	   create a ZFS volume with correct property set."
+
+typeset -i i=0
+while (( $i < ${#RW_VOL_PROP[*]} )); do
+	log_must $ZFS create -o ${RW_VOL_PROP[$i]} -V $VOLSIZE \
+		$TESTPOOL/$TESTVOL1
+	datasetexists $TESTPOOL/$TESTVOL1 || \
+		log_fail "zfs create -V size $TESTPOOL/$TESTVOL1 fail."
+	propertycheck $TESTPOOL/$TESTVOL1 ${RW_VOL_PROP[i]} || \
+		log_fail "${RW_VOL_PROP[i]} is failed to set."
+	log_must $ZFS destroy -f $TESTPOOL/$TESTVOL1
+
+	log_must $ZFS create -s -o ${RW_VOL_PROP[$i]} -V $VOLSIZE \
+		$TESTPOOL/$TESTVOL1
+	datasetexists $TESTPOOL/$TESTVOL1 || \
+		log_fail "zfs create -s -V $TESTPOOL/$TESTVOL1 fail."
+	propertycheck $TESTPOOL/$TESTVOL1 ${RW_VOL_PROP[i]} || \
+		log_fail "${RW_VOL_PROP[i]} is failed to set."
+	log_must $ZFS destroy -f $TESTPOOL/$TESTVOL1
+
+	(( i = i + 1 ))
+done
+
+log_pass "'zfs create -o property=value -V size volume' can successfully \
+	   create a ZFS volume with correct property set."
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/usr/src/test/zfs-tests/tests/functional/cli_root/zfs_create/zfs_create_007_pos.ksh	Wed Dec 05 22:04:50 2012 -0500
@@ -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) 2012 by Delphix. All rights reserved.
+#
+
+. $STF_SUITE/include/libtest.shlib
+. $STF_SUITE/tests/functional/cli_root/zfs_create/zfs_create.cfg
+. $STF_SUITE/tests/functional/cli_root/zfs_create/zfs_create_common.kshlib
+. $STF_SUITE/tests/functional/cli_root/zfs_create/properties.kshlib
+
+#
+# DESCRIPTION:
+# 'zfs create -o property=value -V size volume' can successfully create a ZFS
+# volume with multiple properties set.
+#
+# STRATEGY:
+# 1. Create a ZFS volume in the storage pool with -o option
+# 2. Verify the volume created successfully
+# 3. Verify the properties are correctly set
+#
+
+verify_runnable "global"
+
+function cleanup
+{
+	datasetexists $TESTPOOL/$TESTVOL1 && \
+		log_must $ZFS destroy -f $TESTPOOL/$TESTVOL1
+}
+
+log_onexit cleanup
+
+
+log_assert "'zfs create -o property=value -V size volume' can successfully \
+	   create a ZFS volume with correct property set."
+
+typeset -i i=0
+typeset opts=""
+
+while (( $i < ${#RW_VOL_PROP[*]} )); do
+	if [[ ${RW_VOL_PROP[$i]} != *"checksum"* ]]; then
+		opts="$opts -o ${RW_VOL_PROP[$i]}"
+	fi
+	(( i = i + 1 ))
+done
+
+log_must $ZFS create $opts -V $VOLSIZE $TESTPOOL/$TESTVOL
+datasetexists $TESTPOOL/$TESTVOL || \
+	log_fail "zfs create $TESTPOOL/$TESTVOL fail."
+log_must $ZFS create -s $opts -V $VOLSIZE $TESTPOOL/$TESTVOL1
+datasetexists $TESTPOOL/$TESTVOL1 || \
+	log_fail "zfs create $TESTPOOL/$TESTVOL1 fail."
+
+i=0
+while (( $i < ${#RW_VOL_PROP[*]} )); do
+	if [[ ${RW_VOL_PROP[$i]} != *"checksum"* ]]; then
+		propertycheck $TESTPOOL/$TESTVOL ${RW_VOL_PROP[i]} || \
+			log_fail "${RW_VOL_PROP[i]} is failed to set."
+		propertycheck $TESTPOOL/$TESTVOL1 ${RW_VOL_PROP[i]} || \
+			log_fail "${RW_VOL_PROP[i]} is failed to set."
+	fi
+	(( i = i + 1 ))
+done
+
+log_pass "'zfs create -o property=value -V size volume' can successfully \
+	   create a ZFS volume with correct property set."
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/usr/src/test/zfs-tests/tests/functional/cli_root/zfs_create/zfs_create_008_neg.ksh	Wed Dec 05 22:04:50 2012 -0500
@@ -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) 2012 by Delphix. All rights reserved.
+#
+
+. $STF_SUITE/include/libtest.shlib
+. $STF_SUITE/tests/functional/cli_root/zfs_create/zfs_create.cfg
+
+#
+# DESCRIPTION:
+# 'zfs create' should return an error with badly formed parameters.
+#
+# STRATEGY:
+# 1. Create an array of parameters
+# 2. For each parameter in the array, execute 'zfs create'
+# 3. Verify an error is returned.
+#
+
+verify_runnable "both"
+
+function cleanup
+{
+	if datasetexists $TESTPOOL/$TESTFS1 ; then
+		log_must $ZFS destroy -f $TESTPOOL/$TESTFS1
+	fi
+}
+
+log_onexit cleanup
+
+set -A args "ab" "-?" "-cV" "-Vc" "-c -V" "c" "V" "--c" "-e" "-s" \
+    "-blah" "-cV 12k" "-s -cV 1P" "-sc" "-Vs 5g" "-o" "--o" "-O" "--O" \
+    "-o QuOta=none" "-o quota=non" "-o quota=abcd" "-o quota=0" "-o quota=" \
+    "-o ResErVaTi0n=none" "-o reserV=none" "-o reservation=abcd" "-o reserv=" \
+    "-o recorDSize=64k" "-o recordsize=256K" "-o recordsize=256" \
+    "-o recsize=" "-o recsize=zero" "-o recordsize=0" \
+    "-o mountPoint=/tmp/tmpfile$$" "-o mountpoint=non0" "-o mountpoint=" \
+    "-o mountpoint=LEGACY" "-o mounpoint=none" \
+    "-o sharenfs=ON" "-o ShareNFS=off" "-o sharenfs=sss" \
+    "-o checkSUM=on" "-o checksum=SHA256" "-o chsum=off" "-o checksum=aaa" \
+    "-o checkSUM=on -V $VOLSIZE" "-o checksum=SHA256 -V $VOLSIZE" \
+    "-o chsum=off -V $VOLSIZE" "-o checksum=aaa -V $VOLSIZE" \
+    "-o compression=of" "-o ComPression=lzjb" "-o compress=ON" "-o compress=a" \
+    "-o compression=of -V $VOLSIZE" "-o ComPression=lzjb -V $VOLSIZE" \
+    "-o compress=ON -V $VOLSIZE" "-o compress=a -V $VOLSIZE" \
+    "-o atime=ON" "-o ATime=off" "-o atime=bbb" \
+    "-o deviCes=on" "-o devices=OFF" "-o devices=aaa" \
+    "-o exec=ON" "-o EXec=off" "-o exec=aaa" \
+    "-o readonly=ON" "-o reADOnly=off" "-o rdonly=OFF" "-o rdonly=aaa" \
+    "-o readonly=ON -V $VOLSIZE" "-o reADOnly=off -V $VOLSIZE" \
+    "-o rdonly=OFF -V $VOLSIZE" "-o rdonly=aaa -V $VOLSIZE" \
+    "-o zoned=ON" "-o ZoNed=off" "-o zoned=aaa" \
+    "-o snapdIR=hidden" "-o snapdir=VISible" "-o snapdir=aaa" \
+    "-o aclmode=DIScard" "-o aclmODE=groupmask" "-o aclmode=aaa" \
+    "-o aclinherit=deny" "-o aclinHerit=secure" "-o aclinherit=aaa" \
+    "-o type=volume" "-o type=snapshot" "-o type=filesystem" \
+    "-o type=volume -V $VOLSIZE" "-o type=snapshot -V $VOLSIZE" \
+    "-o type=filesystem -V $VOLSIZE" \
+    "-o creation=aaa" "-o creation=aaa -V $VOLSIZE" \
+    "-o used=10K" "-o used=10K -V $VOLSIZE" \
+    "-o available=10K" "-o available=10K -V $VOLSIZE" \
+    "-o referenced=10K" "-o referenced=10K -V $VOLSIZE" \
+    "-o compressratio=1.00x" "-o compressratio=1.00x -V $VOLSIZE" \
+    "-o version=0" "-o version=1.234" "-o version=10K" "-o version=-1" \
+    "-o version=aaa" "-o version=999"
+
+log_assert "'zfs create' should return an error with badly-formed parameters."
+
+typeset -i i=0
+while [[ $i -lt ${#args[*]} ]]; do
+	log_mustnot $ZFS create ${args[i]} $TESTPOOL/$TESTFS1
+	log_mustnot $ZFS create -p ${args[i]} $TESTPOOL/$TESTFS1
+	((i = i + 1))
+done
+
+log_pass "'zfs create' with badly formed parameters failed as expected."
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/usr/src/test/zfs-tests/tests/functional/cli_root/zfs_create/zfs_create_009_neg.ksh	Wed Dec 05 22:04:50 2012 -0500
@@ -0,0 +1,127 @@
+#!/bin/ksh -p
+#
+# CDDL HEADER START
+#
+# The contents of this file are subject to the terms of the
+# Common Development and Distribution License (the "License").
+# You may not use this file except in compliance with the License.
+#
+# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
+# or http://www.opensolaris.org/os/licensing.
+# See the License for the specific language governing permissions
+# and limitations under the License.
+#
+# When distributing Covered Code, include this CDDL HEADER in each
+# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
+# If applicable, add the following below this CDDL HEADER, with the
+# fields enclosed by brackets "[]" replaced with your own identifying
+# information: Portions Copyright [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.
+#
+
+. $STF_SUITE/include/libtest.shlib
+. $STF_SUITE/tests/functional/cli_root/zfs_create/zfs_create.cfg
+. $STF_SUITE/tests/functional/cli_root/zfs_create/properties.kshlib
+
+#
+# DESCRIPTION:
+# 'zfs create <filesystem>' fails with bad <filesystem> arguments, including:
+#	*Invalid character against the ZFS namespace
+#	*Incomplete component
+#	*Too many arguments
+#	*Filesystem already exists
+#	*Beyond maximal name length.
+#	*Same property set multiple times via '-o property=value'
+#	*Volume's property set on filesystem
+#
+# STRATEGY:
+# 1. Create an array of <filesystem> arguments
+# 2. Execute 'zfs create <filesystem>' with each argument
+# 3. Verify an error is returned.
+#
+
+verify_runnable "both"
+
+function cleanup
+{
+	typeset -i i
+	typeset found
+
+	#
+	# check to see if there is any new fs created during the test
+	# if so destroy it.
+	#
+	for dset in $($ZFS list -H | \
+		$AWK '{print $1}' | $GREP / ); do
+		found=false
+		i=0
+		while (( $i < ${#existed_fs[*]} )); do
+			if [[ $dset == ${existed_fs[i]} ]]; then
+				found=true
+				break
+			fi
+			(( i = i  + 1 ))
+		done
+
+		#
+		# new fs created during the test, cleanup it
+		#
+		if [[ $found == "false" ]]; then
+			log_must $ZFS destroy -f $dset
+		fi
+	done
+}
+
+log_onexit cleanup
+
+set -A args  "$TESTPOOL/" "$TESTPOOL//blah" "$TESTPOOL/@blah" \
+	"$TESTPOOL/blah@blah" "$TESTPOOL/blah^blah" "$TESTPOOL/blah%blah" \
+	"$TESTPOOL/blah*blah" "$TESTPOOL/blah blah" \
+	"-s $TESTPOOL/$TESTFS1" "-b 1092 $TESTPOOL/$TESTFS1" \
+	"-b 64k $TESTPOOL/$TESTFS1" "-s -b 32k $TESTPOOL/$TESTFS1" \
+	"$TESTPOOL/$BYND_MAX_NAME"
+
+log_assert "Verify 'zfs create <filesystem>' fails with bad <filesystem> argument."
+
+datasetexists $TESTPOOL/$TESTFS || \
+	log_must $ZFS create $TESTPOOL/$TESTFS
+
+set -A existed_fs $($ZFS list -H | $AWK '{print $1}' | $GREP / )
+
+log_mustnot $ZFS create $TESTPOOL
+log_mustnot $ZFS create $TESTPOOL/$TESTFS
+
+typeset -i i=0
+while (( $i < ${#args[*]} )); do
+	log_mustnot $ZFS create ${args[$i]}
+	log_mustnot $ZFS create -p ${args[$i]}
+	((i = i + 1))
+done
+
+i=0
+while (( $i < ${#RW_FS_PROP[*]} )); do
+	log_mustnot $ZFS create -o ${RW_FS_PROP[i]} -o ${RW_FS_PROP[i]} \
+		$TESTPOOL/$TESTFS1
+	log_mustnot $ZFS create -p -o ${RW_FS_PROP[i]} -o ${RW_FS_PROP[i]} \
+		$TESTPOOL/$TESTFS1
+	((i = i + 1))
+done
+
+i=0
+while (( $i < ${#VOL_ONLY_PROP[*]} )); do
+	log_mustnot $ZFS create -o ${VOL_ONLY_PROP[i]} $TESTPOOL/$TESTFS1
+	log_mustnot $ZFS create -p -o ${VOL_ONLY_PROP[i]} $TESTPOOL/$TESTFS1
+	((i = i + 1))
+done
+
+log_pass "'zfs create <filesystem>' fails as expected with bad <filesystem> argument."
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/usr/src/test/zfs-tests/tests/functional/cli_root/zfs_create/zfs_create_010_neg.ksh	Wed Dec 05 22:04:50 2012 -0500
@@ -0,0 +1,149 @@
+#!/bin/ksh -p
+#
+# CDDL HEADER START
+#
+# The contents of this file are subject to the terms of the
+# Common Development and Distribution License (the "License").
+# You may not use this file except in compliance with the License.
+#
+# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
+# or http://www.opensolaris.org/os/licensing.
+# See the License for the specific language governing permissions
+# and limitations under the License.
+#
+# When distributing Covered Code, include this CDDL HEADER in each
+# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
+# If applicable, add the following below this CDDL HEADER, with the
+# fields enclosed by brackets "[]" replaced with your own identifying
+# information: Portions Copyright [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.
+#
+
+. $STF_SUITE/include/libtest.shlib
+. $STF_SUITE/tests/functional/cli_root/zfs_create/zfs_create.cfg
+. $STF_SUITE/tests/functional/cli_root/zfs_create/properties.kshlib
+
+#
+# DESCRIPTION:
+# 'zfs create [-b <blocksize> ] -V <size> <volume>' fails with badly formed
+# <size> or <volume> arguments,including:
+#	*Invalid volume size and volume name
+#	*Invalid blocksize
+#	*Incomplete component in the dataset tree
+#	*The volume already exists
+#	*The volume name beyond the maximal name length - 256.
+#       *Same property set multiple times via '-o property=value'
+#       *Filesystems's property set on volume
+#
+# STRATEGY:
+# 1. Create an array of badly formed arguments
+# 2. For each argument, execute 'zfs create -V <size> <volume>'
+# 3. Verify an error is returned.
+#
+
+verify_runnable "global"
+
+function cleanup
+{
+	typeset -i i
+	typeset found
+
+	#
+	# check to see if there is any new fs created during the test
+	# if so destroy it.
+	#
+	for dset in $($ZFS list -H | \
+		$AWK '{print $1}' | $GREP / ); do
+		found=false
+		i=0
+		while (( $i < ${#existed_fs[*]} )); do
+			if [[ $dset == ${existed_fs[i]} ]]; then
+				found=true
+				break
+			fi
+			(( i = i  + 1 ))
+		done
+
+		#
+		# new fs created during the test, cleanup it
+		#
+		if [[ $found == "false" ]]; then
+			log_must $ZFS destroy -f $dset
+		fi
+	done
+}
+
+log_onexit cleanup
+
+log_assert "Verify 'zfs create [-s] [-b <blocksize> ] -V <size> <volume>' fails with" \
+    "badly-formed <size> or <volume> arguments."
+
+set -A args "$VOLSIZE" "$TESTVOL1" \
+	"$VOLSIZE $TESTVOL1" "0 $TESTPOOL/$TESTVOL1" \
+	"-1gb $TESTPOOL/$TESTVOL1" "1g? $TESTPOOL/$TESTVOL1" \
+	"1.01BB $TESTPOOL/$TESTVOL1" "1%g $TESTPOOL/$TESTVOL1" \
+	"1g% $TESTPOOL/$TESTVOL1" "1g$ $TESTPOOL/$TESTVOL1" \
+	"$m $TESTPOOL/$TESTVOL1" "1m$ $TESTPOOL/$TESTVOL1" \
+	"1m! $TESTPOOL/$TESTVOL1" \
+	"1gbb $TESTPOOL/blah" "1blah $TESTPOOL/blah" "blah $TESTPOOL/blah" \
+	"$VOLSIZE $TESTPOOL" "$VOLSIZE $TESTPOOL/" "$VOLSIZE $TESTPOOL//blah"\
+	"$VOLSIZE $TESTPOOL/blah@blah" "$VOLSIZE $TESTPOOL/blah^blah" \
+	"$VOLSIZE $TESTPOOL/blah*blah" "$VOLSIZE $TESTPOOL/blah%blah" \
+	"$VOLSIZE blah" "$VOLSIZE $TESTPOOL/$BYND_MAX_NAME" \
+	"1m -b $TESTPOOL/$TESTVOL1" "1m -b 11k $TESTPOOL/$TESTVOL1" \
+	"1m -b 511 $TESTPOOL/$TESTVOL1" "1m -b 256k $TESTPOOL/$TESTVOL1"
+
+set -A options "" "-s"
+
+datasetexists $TESTPOOL/$TESTVOL || \
+		log_must $ZFS create -V $VOLSIZE $TESTPOOL/$TESTVOL
+
+set -A existed_fs $($ZFS list -H | $AWK '{print $1}' | $GREP / )
+
+log_mustnot $ZFS create -V $VOLSIZE $TESTPOOL/$TESTVOL
+log_mustnot $ZFS create -s -V $VOLSIZE $TESTPOOL/$TESTVOL
+
+typeset -i i=0
+typeset -i j=0
+while (( i < ${#options[*]} )); do
+
+	j=0
+	while (( j < ${#args[*]} )); do
+		log_mustnot $ZFS create ${options[$i]} -V ${args[$j]}
+		log_mustnot $ZFS create -p ${options[$i]} -V ${args[$j]}
+
+		((j = j + 1))
+	done
+
+	j=0
+	while (( $j < ${#RW_VOL_PROP[*]} )); do
+		log_mustnot $ZFS create ${options[$i]} -o ${RW_VOL_PROP[j]} \
+		    -o ${RW_VOL_PROP[j]} -V $VOLSIZE $TESTPOOL/$TESTVOL1
+		log_mustnot $ZFS create -p ${options[$i]} -o ${RW_VOL_PROP[j]} \
+		    -o ${RW_VOL_PROP[j]} -V $VOLSIZE $TESTPOOL/$TESTVOL1
+		((j = j + 1))
+	done
+
+	j=0
+	while (( $j < ${#FS_ONLY_PROP[*]} )); do
+		log_mustnot $ZFS create ${options[$i]} -o ${FS_ONLY_PROP[j]} \
+		    -V $VOLSIZE $TESTPOOL/$TESTVOL1
+		log_mustnot $ZFS create -p ${options[$i]} -o ${FS_ONLY_PROP[j]} \
+		    -V $VOLSIZE $TESTPOOL/$TESTVOL1
+		((j = j + 1))
+	done
+
+	((i = i + 1))
+done
+
+log_pass "'zfs create [-s][-b <blocksize>] -V <size> <volume>' fails as expected."
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/usr/src/test/zfs-tests/tests/functional/cli_root/zfs_create/zfs_create_011_pos.ksh	Wed Dec 05 22:04:50 2012 -0500
@@ -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.
+#
+. $STF_SUITE/include/libtest.shlib
+
+#
+# DESCRIPTION:
+# 'zfs create -p'  should work as expecteed
+#
+# STRATEGY:
+# 1. To create $newdataset with -p option, first make sure the upper level
+#    of $newdataset does not exist
+# 2. Make sure without -p option, 'zfs create' will fail
+# 3. Create $newdataset with -p option, verify it is created
+# 4. Run 'zfs create -p $newdataset' again, the exit code should be zero
+#    even $newdataset exists
+#
+
+verify_runnable "both"
+
+function cleanup
+{
+	if datasetexists $TESTPOOL/$TESTFS1 ; then
+		log_must $ZFS destroy -rf $TESTPOOL/$TESTFS1
+	fi
+}
+
+log_onexit cleanup
+
+typeset newdataset1="$TESTPOOL/$TESTFS1/$TESTFS/$TESTFS1"
+typeset newdataset2="$TESTPOOL/$TESTFS1/$TESTFS/$TESTVOL1"
+
+log_assert "'zfs create -p' works as expected."
+
+log_must verify_opt_p_ops "create" "fs" $newdataset1
+
+# verify volume creation
+if is_global_zone; then
+	log_must verify_opt_p_ops "create" "vol" $newdataset2
+fi
+
+log_pass "'zfs create -p' works as expected."
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/usr/src/test/zfs-tests/tests/functional/cli_root/zfs_create/zfs_create_012_pos.ksh	Wed Dec 05 22:04:50 2012 -0500
@@ -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 2009 Sun Microsystems, Inc.  All rights reserved.
+# Use is subject to license terms.
+#
+. $STF_SUITE/include/libtest.shlib
+. $STF_SUITE/tests/functional/cli_root/zfs_upgrade/zfs_upgrade.kshlib
+
+#
+# DESCRIPTION:
+# 'zfs create -p -o version=1' should only cause the leaf filesystem to be version=1
+#
+# STRATEGY:
+# 1. Create $newdataset with -p option, verify it is created
+# 2. Verify only the leaf filesystem to be version=1, others use the current version
+#
+
+ZFS_VERSION=$($ZFS upgrade | $HEAD -1 | $AWK '{print $NF}' \
+	| $SED -e 's/\.//g')
+
+verify_runnable "both"
+
+function cleanup
+{
+	if datasetexists $TESTPOOL/$TESTFS1 ; then
+		log_must $ZFS destroy -rf $TESTPOOL/$TESTFS1
+	fi
+}
+
+log_onexit cleanup
+
+
+typeset newdataset1="$TESTPOOL/$TESTFS1/$TESTFS/$TESTFS1"
+
+log_assert "'zfs create -p -o version=1' only cause the leaf filesystem to be version=1."
+
+log_must $ZFS create -p -o version=1 $newdataset1
+log_must datasetexists $newdataset1
+
+log_must check_fs_version $TESTPOOL/$TESTFS1/$TESTFS/$TESTFS1 1
+for fs in $TESTPOOL/$TESTFS1 $TESTPOOL/$TESTFS1/$TESTFS ; do
+	log_must check_fs_version $fs $ZFS_VERSION
+done
+
+log_pass "'zfs create -p -o version=1' only cause the leaf filesystem to be version=1."
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/usr/src/test/zfs-tests/tests/functional/cli_root/zfs_create/zfs_create_013_pos.ksh	Wed Dec 05 22:04:50 2012 -0500
@@ -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.
+#
+. $STF_SUITE/include/libtest.shlib
+. $STF_SUITE/tests/functional/cli_root/zfs_create/zfs_create.cfg
+
+#
+# DESCRIPTION:
+# 'zfs create -s -V <size> <volume>' can create various-size sparse volume
+#  with long fs name
+#
+# STRATEGY:
+# 1. Create a volume in the storage pool.
+# 2. Verify the volume is created correctly.
+#
+
+verify_runnable "global"
+
+function cleanup
+{
+	typeset -i j=0
+	while [[ $j -lt ${#size[*]} ]]; do
+		datasetexists $TESTPOOL/${LONGFSNAME}${size[j]} && \
+		    log_must $ZFS destroy $TESTPOOL/${LONGFSNAME}${size[j]}
+		((j = j + 1))
+	done
+}
+
+log_onexit cleanup
+
+
+log_assert "'zfs create -s -V <size> <volume>' succeeds"
+
+typeset -i j=0
+while (( $j < ${#size[*]} )); do
+	typeset cmdline="$ZFS create -s -V ${size[j]} \
+			 $TESTPOOL/${LONGFSNAME}${size[j]}"
+
+	str=$(eval $cmdline 2>&1)
+	if (( $? == 0 )); then
+		log_note "SUCCESS: $cmdline"
+		log_must datasetexists $TESTPOOL/${LONGFSNAME}${size[j]}
+	elif [[ $str == *${VOL_LIMIT_KEYWORD1}* || \
+		$str == *${VOL_LIMIT_KEYWORD2}* || \
+		$str == *${VOL_LIMIT_KEYWORD3}* ]]
+	then
+		log_note "UNSUPPORTED: $cmdline"
+	else
+		log_fail "$cmdline"
+	fi
+
+	((j = j + 1))
+done
+
+log_pass "'zfs create -s -V <size> <volume>' works as expected."
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/usr/src/test/zfs-tests/tests/functional/cli_root/zfs_create/zfs_create_common.kshlib	Wed Dec 05 22:04:50 2012 -0500
@@ -0,0 +1,51 @@
+#
+# CDDL HEADER START
+#
+# The contents of this file are subject to the terms of the
+# Common Development and Distribution License (the "License").
+# You may not use this file except in compliance with the License.
+#
+# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
+# or http://www.opensolaris.org/os/licensing.
+# See the License for the specific language governing permissions
+# and limitations under the License.
+#
+# When distributing Covered Code, include this CDDL HEADER in each
+# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
+# If applicable, add the following below this CDDL HEADER, with the
+# fields enclosed by brackets "[]" replaced with your own identifying
+# information: Portions Copyright [yyyy] [name of copyright owner]
+#
+# CDDL HEADER END
+#
+
+#!/bin/ksh -p
+#
+# Copyright 2007 Sun Microsystems, Inc.  All rights reserved.
+# Use is subject to license terms.
+#
+
+. $STF_SUITE/include/libtest.shlib
+
+#
+# Check if the user property is identical to the expected value.
+#
+# $1 dataset
+# $2 property string
+#
+function propertycheck
+{
+	typeset dtst=$1
+	typeset propstr=$2
+
+	typeset prop=$($ECHO $propstr | $AWK -F= '{print $1}')
+	typeset expect_value=$($ECHO $propstr | $AWK -F= '{print $2}')
+	typeset value=$($ZFS get -H -o value $prop $dtst)
+
+
+	if [[ "$expect_value" == "$value" ]]; then
+		return 0
+	else
+		return 1
+	fi
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/usr/src/test/zfs-tests/tests/functional/cli_root/zfs_destroy/Makefile	Wed Dec 05 22:04:50 2012 -0500
@@ -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) 2012 by Delphix. All rights reserved.
+#
+
+include $(SRC)/Makefile.master
+
+ROOTOPTPKG = $(ROOT)/opt/zfs-tests
+TESTDIR = $(ROOTOPTPKG)/tests/functional/cli_root/zfs_destroy
+
+PROGS = cleanup \
+	setup \
+	zfs_destroy_001_pos \
+	zfs_destroy_002_pos \
+	zfs_destroy_003_pos \
+	zfs_destroy_004_pos \
+	zfs_destroy_005_neg \
+	zfs_destroy_006_neg \
+	zfs_destroy_007_neg \
+	zfs_destroy_008_pos \
+	zfs_destroy_009_pos \
+	zfs_destroy_010_pos \
+	zfs_destroy_011_pos \
+	zfs_destroy_012_pos \
+	zfs_destroy_013_neg \
+	zfs_destroy_014_pos \
+	zfs_destroy_015_pos \
+	zfs_destroy_016_pos
+
+FILES = zfs_destroy_common.kshlib \
+	zfs_destroy.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	Thu Jan 01 00:00:00 1970 +0000
+++ b/usr/src/test/zfs-tests/tests/functional/cli_root/zfs_destroy/cleanup.ksh	Wed Dec 05 22:04:50 2012 -0500
@@ -0,0 +1,32 @@
+#!/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.
+#
+
+. $STF_SUITE/tests/functional/cli_root/zfs_destroy/zfs_destroy_common.kshlib
+
+cleanup_testenv
+
+default_cleanup
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/usr/src/test/zfs-tests/tests/functional/cli_root/zfs_destroy/setup.ksh	Wed Dec 05 22:04:50 2012 -0500
@@ -0,0 +1,32 @@
+#!/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.
+#
+
+. $STF_SUITE/include/libtest.shlib
+
+DISK=${DISKS%% *}
+
+default_setup $DISK
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/usr/src/test/zfs-tests/tests/functional/cli_root/zfs_destroy/zfs_destroy.cfg	Wed Dec 05 22:04:50 2012 -0500
@@ -0,0 +1,39 @@
+#
+# CDDL HEADER START
+#
+# The contents of this file are subject to the terms of the
+# Common Development and Distribution License (the "License").
+# You may not use this file except in compliance with the License.
+#
+# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
+# or http://www.opensolaris.org/os/licensing.
+# See the License for the specific language governing permissions
+# and limitations under the License.
+#
+# When distributing Covered Code, include this CDDL HEADER in each
+# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
+# If applicable, add the following below this CDDL HEADER, with the
+# fields enclosed by brackets "[]" replaced with your own identifying
+# information: Portions Copyright [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.
+#
+
+export TESTFSCLONE=${TESTFS}clone
+export TESTVOLCLONE=${TESTVOL}clone
+export CTR=$TESTPOOL/$TESTCTR
+export FS=$CTR/$TESTFS
+export VOL=$CTR/$TESTVOL
+export FSSNAP=$FS@$TESTSNAP
+export VOLSNAP=$VOL@$TESTSNAP
+export FSCLONE=$TESTPOOL/$TESTFSCLONE
+export VOLCLONE=$TESTPOOL/$TESTVOLCLONE
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/usr/src/test/zfs-tests/tests/functional/cli_root/zfs_destroy/zfs_destroy_001_pos.ksh	Wed Dec 05 22:04:50 2012 -0500
@@ -0,0 +1,221 @@
+#!/bin/ksh -p
+#
+# CDDL HEADER START
+#
+# The contents of this file are subject to the terms of the
+# Common Development and Distribution License (the "License").
+# You may not use this file except in compliance with the License.
+#
+# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
+# or http://www.opensolaris.org/os/licensing.
+# See the License for the specific language governing permissions
+# and limitations under the License.
+#
+# When distributing Covered Code, include this CDDL HEADER in each
+# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
+# If applicable, add the following below this CDDL 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) 2012 by Delphix. All rights reserved.
+#
+
+. $STF_SUITE/include/libtest.shlib
+. $STF_SUITE/tests/functional/cli_root/zfs_destroy/zfs_destroy.cfg
+. $STF_SUITE/tests/functional/cli_root/zfs_destroy/zfs_destroy_common.kshlib
+
+#
+# DESCRIPTION:
+#	'zfs destroy -r|-rf|-R|-Rf <fs|ctr|vol|snap>' should recursively destroy
+#	all children and clones based on options.
+#
+# STRATEGY:
+#	1. Create test environment according to options. There are three test
+#	models can be created. Only ctr, fs & vol; with snap; with clone.
+#	2. According to option, make the dataset busy or not.
+#	3. Run 'zfs destroy [-rRf] <dataset>'
+#	4. According to dataset and option, check if get the expected results.
+#
+
+verify_runnable "both"
+
+#
+# According to parameters, 1st, create suitable testing environment. 2nd,
+# run 'zfs destroy $opt <dataset>'. 3rd, check the system status.
+#
+# $1 option of 'zfs destroy'
+# $2 dataset will be destroied.
+#
+function test_n_check
+{
+	typeset opt=$1
+	typeset dtst=$2
+
+	if ! is_global_zone ; then
+		if [[ $dtst == $VOL || $dtst == $VOLSNAP ]]; then
+			log_note "UNSUPPORTED: Volume are unavailable in LZ."
+			return
+		fi
+	fi
+
+	# '-f' has no effect on non-filesystems
+	if [[ $opt == -f ]]; then
+		if [[ $dtst != $FS ]]; then
+			log_note "UNSUPPORTED: '-f ' is only available for " \
+			    "leaf FS."
+			return
+		fi
+	fi
+
+	# Clean the test environment and make it clear.
+	if datasetexists $CTR; then
+		log_must $ZFS destroy -Rf $CTR
+	fi
+
+	# According to option create test compatible environment.
+	case $opt in
+		-r|-rf) setup_testenv snap ;;
+		-R|-Rf) setup_testenv clone ;;
+		-f)	setup_testenv ;;
+		*)	log_fail "Incorrect option: '$opt'." ;;
+	esac
+
+	#
+	# According to different dataset type, create busy condition when try to
+	# destroy this dataset.
+	#
+	typeset mpt_dir
+	case $dtst in
+		$CTR|$FS)
+			if [[ $opt == *f* ]]; then
+				mpt_dir=$(get_prop mountpoint $FS)
+				pidlist="$pidlist $($MKBUSY \
+				    $mpt_dir/$TESTFILE0)"
+				log_note "$MKBUSY $mpt_dir/$TESTFILE0 " \
+				    "(pidlist: $pidlist)"
+				[[ -z $pidlist ]] && \
+				    log_fail "Failure from $MKBUSY"
+				log_mustnot $ZFS destroy -rR $dtst
+			fi
+			;;
+		$VOL)
+			if [[ $opt == *f* ]]; then
+				pidlist="$pidlist $($MKBUSY \
+				    $TESTDIR1/$TESTFILE0)"
+				log_note "$MKBUSY $TESTDIR1/$TESTFILE0 " \
+				    "(pidlist: $pidlist)"
+				[[ -z $pidlist ]] && \
+				    log_fail "Failure from $MKBUSY"
+				log_mustnot $ZFS destroy -rR $dtst
+			fi
+			;;
+		$VOLSNAP)
+			if [[ $opt == *f* ]]; then
+				pidlist="$pidlist $($MKBUSY \
+				    $TESTDIR1/$TESTFILE0)"
+				log_note "$MKBUSY $TESTDIR1/$TESTFILE0 " \
+				    "(pidlist: $pidlist)"
+				[[ -z $pidlist ]] && \
+				    log_fail "Failure from $MKBUSY"
+				log_must $ZFS destroy -rR $dtst
+				log_must $ZFS snapshot $dtst
+			fi
+			;;
+		$FSSNAP)
+			if [[ $opt == *f* ]]; then
+				mpt_dir=$(snapshot_mountpoint $dtst)
+				pidlist="$pidlist $($MKBUSY $mpt_dir)"
+				log_note "$MKBUSY $mpt_dir (pidlist: $pidlist)"
+				[[ -z $pidlist ]] && \
+				    log_fail "Failure from $MKBUSY"
+				log_must $ZFS destroy -rR $dtst
+				log_must $ZFS snapshot $dtst
+			fi
+			;;
+		*)	log_fail "Unsupported dataset: '$dtst'."
+	esac
+
+	# Firstly, umount ufs filesystem which was created by zfs volume.
+	if is_global_zone; then
+		log_must $UMOUNT -f $TESTDIR1
+	fi
+
+	# Invoke 'zfs destroy [-rRf] <dataset>'
+	log_must $ZFS destroy $opt $dtst
+
+	# Kill any lingering instances of mkbusy, and clear the list.
+	[[ -z $pidlist ]] || log_must $KILL -TERM $pidlist
+	pidlist=""
+	log_mustnot $PGREP -fl $MKBUSY
+
+	case $dtst in
+		$CTR)	check_dataset datasetnonexists \
+					$CTR $FS $VOL $FSSNAP $VOLSNAP
+			if [[ $opt == *R* ]]; then
+				check_dataset datasetnonexists \
+					$FSCLONE $VOLCLONE
+			fi
+			;;
+		$FS)	check_dataset datasetexists $CTR $VOL
+			check_dataset datasetnonexists $FS
+			if [[ $opt != -f ]]; then
+				check_dataset datasetexists $VOLSNAP
+				check_dataset datasetnonexists $FSSNAP
+			fi
+			if [[ $opt == *R* ]]; then
+				check_dataset datasetexists $VOLCLONE
+				check_dataset datasetnonexists $FSCLONE
+			fi
+			;;
+		$VOL)	check_dataset datasetexists $CTR $FS $FSSNAP
+			check_dataset datasetnonexists $VOL $VOLSNAP
+			if [[ $opt == *R* ]]; then
+				check_dataset datasetexists $FSCLONE
+				check_dataset datasetnonexists $VOLCLONE
+			fi
+			;;
+		$FSSNAP)
+			check_dataset datasetexists $CTR $FS $VOL $VOLSNAP
+			check_dataset datasetnonexists $FSSNAP
+			if [[ $opt == *R* ]]; then
+				check_dataset datasetexists $VOLCLONE
+				check_dataset datasetnonexists $FSCLONE
+			fi
+			;;
+		$VOLSNAP)
+			check_dataset datasetexists $CTR $FS $VOL $FSSNAP
+			check_dataset datasetnonexists $VOLSNAP
+			if [[ $opt == *R* ]]; then
+				check_dataset datasetexists $FSCLONE
+				check_dataset datasetnonexists $VOLCLONE
+			fi
+			;;
+	esac
+
+	log_note "'$ZFS destroy $opt $dtst' passed."
+}
+
+log_assert "'zfs destroy -r|-R|-f|-rf|-Rf <fs|ctr|vol|snap>' should " \
+	"recursively destroy all children."
+log_onexit cleanup_testenv
+
+typeset dtst=""
+typeset opt=""
+typeset pidlist=""
+for dtst in $CTR $FS $VOL $FSSNAP $VOLSNAP; do
+	for opt in "-r" "-R" "-f" "-rf" "-Rf"; do
+		log_note "Starting test: $ZFS destroy $opt $dtst"
+		test_n_check $opt $dtst
+	done
+done
+
+log_pass "'zfs destroy -r|-R|-f|-rf|-Rf <fs|ctr|vol|snap>' passed."
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/usr/src/test/zfs-tests/tests/functional/cli_root/zfs_destroy/zfs_destroy_002_pos.ksh	Wed Dec 05 22:04:50 2012 -0500
@@ -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) 2012 by Delphix. All rights reserved.
+#
+
+. $STF_SUITE/include/libtest.shlib
+. $STF_SUITE/tests/functional/cli_root/zfs_destroy/zfs_destroy.cfg
+
+#
+# DESCRIPTION:
+#	'zfs destroy <filesystem|volume|snapshot>' can successfully destroy
+#	the specified dataset which has no active dependents.
+#
+# STRATEGY:
+#	1. Create a filesystem,volume and snapshot in the storage pool
+#	2. Destroy the filesystem,volume and snapshot
+#	3. Verify the datasets are destroyed successfully
+#
+
+verify_runnable "both"
+
+function cleanup
+{
+	typeset -i i=0
+	while (( $i < ${#data_objs[*]} )); do
+		datasetexists "${data_objs[i]}" && \
+			$ZFS destroy -rf ${data_objs[i]}
+		((i = i + 1))
+	done
+}
+
+log_assert "Verify 'zfs destroy' can destroy the specified datasets without active" \
+	"dependents."
+log_onexit cleanup
+
+if is_global_zone ; then
+	set -A data_objs "$TESTPOOL/$TESTFS@$TESTSNAP" "$TESTPOOL/$TESTFS1" \
+		"$TESTPOOL/$TESTVOL" "$TESTPOOL/$TESTVOL1"
+else
+	set -A data_objs "$TESTPOOL/$TESTFS@$TESTSNAP" "$TESTPOOL/$TESTFS1"
+fi
+
+log_must $ZFS create $TESTPOOL/$TESTFS1
+log_must $ZFS snapshot $TESTPOOL/$TESTFS@$TESTSNAP
+
+if is_global_zone ; then
+	log_must $ZFS create -V $VOLSIZE $TESTPOOL/$TESTVOL
+
+	# Max volume size is 1TB on 32-bit systems
+	[[ $($ISAINFO -b) == 32 ]] && \
+		BIGVOLSIZE=1Tb
+	log_must $ZFS create -sV $BIGVOLSIZE $TESTPOOL/$TESTVOL1
+fi
+
+typeset -i i=0
+while (( $i < ${#data_objs[*]} )); do
+	datasetexists ${data_objs[i]} || \
+		log_fail "Create <filesystem>|<volume>|<snapshot> fail."
+	((i = i + 1))
+done
+
+i=0
+while (( $i < ${#data_objs[*]} )); do
+	log_must $ZFS destroy ${data_objs[i]}
+	datasetexists ${data_objs[i]} && \
+		log_fail "'zfs destroy <filesystem>|<volume>|<snapshot>' fail."
+	((i = i + 1))
+done
+
+log_pass "'zfs destroy <filesystem>|<volume>|<snapshot>' works as expected."
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/usr/src/test/zfs-tests/tests/functional/cli_root/zfs_destroy/zfs_destroy_003_pos.ksh	Wed Dec 05 22:04:50 2012 -0500
@@ -0,0 +1,156 @@
+#!/bin/ksh -p
+#
+# CDDL HEADER START
+#
+# The contents of this file are subject to the terms of the
+# Common Development and Distribution License (the "License").
+# You may not use this file except in compliance with the License.
+#
+# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
+# or http://www.opensolaris.org/os/licensing.
+# See the License for the specific language governing permissions
+# and limitations under the License.
+#
+# When distributing Covered Code, include this CDDL HEADER in each
+# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
+# If applicable, add the following below this CDDL HEADER, with the
+# fields enclosed by brackets "[]" replaced with your own identifying
+# information: Portions Copyright [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.
+#
+
+. $STF_SUITE/include/libtest.shlib
+. $STF_SUITE/tests/functional/cli_root/zfs_destroy/zfs_destroy.cfg
+
+#
+# DESCRIPTION:
+#	Verify 'zfs destroy [-rR]' succeeds as root.
+#
+# STRATEGY:
+#	1. Create two datasets in the storage pool
+#	2. Create fs,vol,ctr,snapshot and clones of snapshot in the two datasets
+#	3. Create clone in the second dataset for the snapshot in the first dataset
+#	4. Verify 'zfs destroy -r' fails to destroy dataset with clone outside it
+#	5. Verify 'zfs destroy -R' succeeds to destroy dataset with clone outside it
+#	6. Verify 'zfs destroy -r' succeeds to destroy dataset without clone outside it.
+#
+
+verify_runnable "both"
+
+function cleanup
+{
+	for obj in $ctr2 $ctr1 $ctr; do
+		datasetexists $obj && \
+			log_must $ZFS destroy -Rf $obj
+	done
+
+	for mntp in $TESTDIR1 $TESTDIR2; do
+		[[ -d $mntp ]] && \
+			log_must $RM -rf $mntp
+	done
+}
+
+log_assert "Verify that 'zfs destroy [-rR]' succeeds as root. "
+
+log_onexit cleanup
+
+#
+# Preparations for testing
+#
+for dir in $TESTDIR1 $TESTDIR2; do
+	[[ ! -d $dir ]] && \
+		log_must $MKDIR -p $dir
+done
+
+ctr=$TESTPOOL/$TESTCTR
+ctr1=$TESTPOOL/$TESTCTR1
+ctr2=$ctr/$TESTCTR2
+ctr3=$ctr1/$TESTCTR2
+child_fs=$ctr/$TESTFS1
+child_fs1=$ctr1/$TESTFS2
+child_fs_mntp=$TESTDIR1
+child_fs1_mntp=$TESTDIR2
+child_vol=$ctr/$TESTVOL
+child_vol1=$ctr1/$TESTVOL
+child_fs_snap=$child_fs@snap
+child_fs1_snap=$child_fs1@snap
+child_fs_snap_clone=$ctr/$TESTCLONE
+child_fs_snap_clone1=$ctr1/${TESTCLONE}_across_ctr
+child_fs_snap_clone2=$ctr2/$TESTCLONE2
+child_fs1_snap_clone=$ctr1/$TESTCLONE1
+child_fs1_snap_clone1=$ctr/${TESTCLONE1}_across_ctr
+
+#
+# Create two datasets in the storage pool
+#
+log_must $ZFS create $ctr
+log_must $ZFS create $ctr1
+
+#
+# Create children datasets fs,vol,snapshot in the datasets, and
+# clones across two datasets
+#
+log_must $ZFS create $ctr2
+
+for fs in $child_fs $child_fs1; do
+	log_must $ZFS create $fs
+done
+
+log_must $ZFS set mountpoint=$child_fs_mntp $child_fs
+log_must $ZFS set mountpoint=$child_fs1_mntp $child_fs1
+
+for snap in $child_fs_snap $child_fs1_snap; do
+	log_must $ZFS snapshot $snap
+done
+
+if is_global_zone ; then
+	for vol in $child_vol $child_vol1; do
+		log_must $ZFS create -V $VOLSIZE $vol
+	done
+fi
+
+for clone in $child_fs_snap_clone $child_fs_snap_clone1; do
+	log_must $ZFS clone $child_fs_snap $clone
+done
+
+
+for clone in $child_fs1_snap_clone $child_fs1_snap_clone1; do
+	log_must $ZFS clone $child_fs1_snap $clone
+done
+
+log_note "Verify that 'zfs destroy -r' fails to destroy dataset " \
+	"with clone dependant outside it."
+
+for obj in $child_fs $child_fs1 $ctr $ctr1; do
+	log_mustnot $ZFS destroy -r $obj
+	datasetexists $obj || \
+		log_fail "'zfs destroy -r' fails to keep clone " \
+			"dependant outside the hirearchy."
+done
+
+
+log_note "Verify that 'zfs destroy -R' succeeds to destroy dataset " \
+	"with clone dependant outside it."
+
+log_must $ZFS destroy -R $ctr1
+datasetexists $ctr1 && \
+	log_fail "'zfs destroy -R' fails to destroy dataset with clone outside it."
+
+log_note "Verify that 'zfs destroy -r' succeeds to destroy dataset " \
+	"without clone dependant outside it."
+
+log_must $ZFS destroy -r $ctr
+datasetexists $ctr && \
+	log_fail "'zfs destroy -r' fails to destroy dataset with clone outside it."
+
+log_pass "'zfs destroy [-rR] succeeds as root."
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/usr/src/test/zfs-tests/tests/functional/cli_root/zfs_destroy/zfs_destroy_004_pos.ksh	Wed Dec 05 22:04:50 2012 -0500
@@ -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 2007 Sun Microsystems, Inc.  All rights reserved.
+# Use is subject to license terms.
+#
+
+#
+# Copyright (c) 2012 by Delphix. All rights reserved.
+#
+
+. $STF_SUITE/include/libtest.shlib
+. $STF_SUITE/tests/functional/cli_root/zfs_destroy/zfs_destroy.cfg
+
+#
+# DESCRIPTION:
+#	Verify 'zfs destroy -f' succeeds as root.
+#
+# STRATEGY:
+#	1. Create filesystem in the storage pool
+#	2. Set mountpoint for the filesystem and make it busy
+#	3. Verify that 'zfs destroy' fails to destroy the filesystem
+#	4. Verify 'zfs destroy -f' succeeds to destroy the filesystem.
+#
+
+verify_runnable "both"
+
+function cleanup
+{
+	cd $olddir
+
+	datasetexists $clone && \
+		log_must $ZFS destroy -f $clone
+
+	snapexists $snap && \
+		log_must $ZFS destroy -f $snap
+
+	for fs in $fs1 $fs2; do
+		datasetexists $fs && \
+			log_must $ZFS destroy -f $fs
+	done
+
+	for dir in $TESTDIR1 $TESTDIR2; do
+		[[ -d $dir ]] && \
+			log_must $RM -rf $dir
+	done
+}
+
+log_assert "Verify that 'zfs destroy -f' succeeds as root. "
+
+log_onexit cleanup
+
+#
+# Preparations for testing
+#
+olddir=$PWD
+
+for dir in $TESTDIR1 $TESTDIR2; do
+	[[ ! -d $dir ]] && \
+		log_must $MKDIR -p $dir
+done
+
+fs1=$TESTPOOL/$TESTFS1
+mntp1=$TESTDIR1
+fs2=$TESTPOOL/$TESTFS2
+snap=$TESTPOOL/$TESTFS2@snap
+clone=$TESTPOOL/$TESTCLONE
+mntp2=$TESTDIR2
+
+#
+# Create filesystem and clone in the storage pool,  mount them and
+# make the mountpoint busy
+#
+for fs in $fs1 $fs2; do
+	log_must $ZFS create $fs
+done
+
+log_must $ZFS snapshot $snap
+log_must $ZFS clone $snap $clone
+
+log_must $ZFS set mountpoint=$mntp1 $fs1
+log_must $ZFS set mountpoint=$mntp2 $clone
+
+for arg in "$fs1 $mntp1" "$clone $mntp2"; do
+	fs=`$ECHO $arg | $AWK '{print $1}'`
+	mntp=`$ECHO $arg | $AWK '{print $2}'`
+
+	log_note "Verify that 'zfs destroy' fails to" \
+			"destroy filesystem when it is busy."
+	cd $mntp
+	log_mustnot $ZFS destroy $fs
+
+	log_must $ZFS destroy -f $fs
+	datasetexists $fs && \
+		log_fail "'zfs destroy -f' fails to destroy busy filesystem."
+
+	cd $olddir
+done
+
+log_pass "'zfs destroy -f' succeeds as root."
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/usr/src/test/zfs-tests/tests/functional/cli_root/zfs_destroy/zfs_destroy_005_neg.ksh	Wed Dec 05 22:04:50 2012 -0500
@@ -0,0 +1,212 @@
+#!/bin/ksh -p
+#
+# CDDL HEADER START
+#
+# The contents of this file are subject to the terms of the
+# Common Development and Distribution License (the "License").
+# You may not use this file except in compliance with the License.
+#
+# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
+# or http://www.opensolaris.org/os/licensing.
+# See the License for the specific language governing permissions
+# and limitations under the License.
+#
+# When distributing Covered Code, include this CDDL HEADER in each
+# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
+# If applicable, add the following below this CDDL 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) 2012 by Delphix. All rights reserved.
+#
+
+. $STF_SUITE/include/libtest.shlib
+. $STF_SUITE/tests/functional/cli_root/zfs_destroy/zfs_destroy.cfg
+. $STF_SUITE/tests/functional/cli_root/zfs_destroy/zfs_destroy_common.kshlib
+
+#
+# DESCRIPTION:
+#	Seperately verify 'zfs destroy -f|-r|-rf|-R|-rR <dataset>' will fail in
+#       different conditions.
+#
+# STRATEGY:
+#	1. Create pool, fs & vol.
+#	2. Create snapshot for fs & vol.
+#	3. Invoke 'zfs destroy ''|-f <dataset>', it should fail.
+#	4. Create clone for fs & vol.
+#	5. Invoke 'zfs destroy -r|-rf <dataset>', it should fail.
+#	6. Write file to filesystem or enter snapshot mountpoint.
+#	7. Invoke 'zfs destroy -R|-rR <dataset>', it should fail.
+#
+
+verify_runnable "both"
+
+log_assert "Seperately verify 'zfs destroy -f|-r|-rf|-R|-rR <dataset>' will " \
+	"fail in different conditions."
+log_onexit cleanup_testenv
+
+#
+# Run 'zfs destroy [-rRf] <dataset>', make sure it fail.
+#
+# $1 the collection of options
+# $2 the collection of datasets
+#
+function negative_test
+{
+	typeset options=$1
+	typeset datasets=$2
+
+	for dtst in $datasets; do
+		if ! is_global_zone; then
+			if [[ $dtst == $VOL || $dtst == $VOLSNAP || \
+				$dtst == $VOLCLONE ]]
+			then
+				log_note "UNSUPPORTED: " \
+					"Volume is unavailable in LZ."
+				continue
+			fi
+		fi
+		for opt in $options; do
+			log_mustnot $ZFS destroy $opt $dtst
+		done
+	done
+}
+
+#
+# Create snapshots for filesystem and volume,
+# and verify 'zfs destroy' fails without '-r' or '-R'.
+#
+setup_testenv snap
+negative_test "-f" "$CTR $FS $VOL"
+
+#
+# Create clones for filesystem and volume,
+# and verify 'zfs destroy' fails without '-R'.
+#
+setup_testenv clone
+negative_test "-r -rf" "$CTR $FS $VOL"
+
+#
+# Get $FS mountpoint and make it busy, and verify 'zfs destroy $CTR' fails
+# without '-f'. Then verify the remaining datasets are correct. See below for
+# an explanation of what 'correct' means for this test.
+#
+mntpt=$(get_prop mountpoint $FS)
+pidlist=$($MKBUSY $mntpt/$TESTFILE0)
+log_note "$MKBUSY $mntpt/$TESTFILE0 (pidlist: $pidlist)"
+[[ -z $pidlist ]] && log_fail "Failure from mkbusy"
+negative_test "-R -rR" $CTR
+
+#
+# Checking the outcome of the test above is tricky, because the order in
+# which datasets are destroyed is not deterministic. Both $FS and $VOL are
+# busy, and the remaining datasets will be different depending on whether we
+# tried (and failed) to delete $FS or $VOL first.
+
+# The following datasets will exist independent of the order
+check_dataset datasetexists $CTR $FS $VOL
+
+if datasetexists $VOLSNAP && datasetnonexists $FSSNAP; then
+	# The recursive destroy failed on $FS
+	check_dataset datasetnonexists $FSSNAP $FSCLONE
+	check_dataset datasetexists $VOLSNAP $VOLCLONE
+elif datasetexists $FSSNAP && datasetnonexists $VOLSNAP; then
+	# The recursive destroy failed on $VOL
+	check_dataset datasetnonexists $VOLSNAP $VOLCLONE
+	check_dataset datasetexists $FSSNAP $FSCLONE
+else
+	log_must $ZFS list -rtall
+	log_fail "Unexpected datasets remaining"
+fi
+
+#
+# Create the clones for test environment, and verify 'zfs destroy $FS' fails
+# without '-f'.  Then verify the FS snap and clone are the only datasets
+# that were removed.
+#
+setup_testenv clone
+negative_test "-R -rR" $FS
+check_dataset datasetexists $CTR $FS $VOL $VOLSNAP $VOLCLONE
+check_dataset datasetnonexists $FSSNAP $FSCLONE
+
+log_must $KILL $pidlist
+log_mustnot $PGREP -fl $MKBUSY
+pidlist=""
+
+#
+# Create the clones for test environment and make the volume busy.
+# Then verify 'zfs destroy $CTR' fails without '-f'.
+#
+# Then verify the expected datasets exist (see below).
+#
+if is_global_zone; then
+	setup_testenv clone
+	pidlist=$($MKBUSY $TESTDIR1/$TESTFILE0)
+	log_note "$MKBUSY $TESTDIR1/$TESTFILE0 (pidlist: $pidlist)"
+	[[ -z $pidlist ]] && log_fail "Failure from mkbusy"
+	negative_test "-R -rR" $CTR
+	check_dataset datasetexists $CTR $VOL
+	check_dataset datasetnonexists $VOLSNAP $VOLCLONE
+
+	# Here again, the non-determinism of destroy order is a factor. $FS,
+	# $FSSNAP and $FSCLONE will still exist here iff we attempted to destroy
+	# $VOL (and failed) first. So check that either all of the datasets are
+	# present, or they're all gone.
+	if datasetexists $FS; then
+		check_dataset datasetexists $FS $FSSNAP $FSCLONE
+	else
+		check_dataset datasetnonexists $FS $FSSNAP $FSCLONE
+	fi
+fi
+
+#
+# Create the clones for test environment and make the volume busy.
+# Then verify 'zfs destroy $VOL' fails without '-f'.
+#
+# Then verify the snapshot and clone are destroyed, but nothing else is.
+#
+if is_global_zone; then
+	setup_testenv clone
+	negative_test "-R -rR" $VOL
+	check_dataset datasetexists $CTR $VOL $FS $FSSNAP $FSCLONE
+	check_dataset datasetnonexists $VOLSNAP $VOLCLONE
+fi
+
+log_must $KILL $pidlist
+log_mustnot $PGREP -fl $MKBUSY
+pidlist=""
+
+#
+# Create the clones for test environment and make the snapshot busy.
+# Then verify 'zfs destroy $snap' succeeds without '-f'.
+#
+# Then verify the snapshot and clone are destroyed, but nothing else is.
+#
+
+mntpt=$(snapshot_mountpoint $FSSNAP)
+pidlist=$($MKBUSY $mntpt)
+log_note "$MKBUSY $mntpt (pidlist: $pidlist)"
+[[ -z $pidlist ]] && log_fail "Failure from mkbusy"
+
+for option in -R -rR ; do
+	setup_testenv clone
+	log_must $ZFS destroy $option $FSSNAP
+	check_dataset datasetexists $CTR $FS $VOL
+	check_dataset datasetnonexists $FSSNAP $FSCLONE
+done
+
+log_must $KILL $pidlist
+log_mustnot $PGREP -fl $MKBUSY
+pidlist=""
+
+log_pass "zfs destroy -f|-r|-rf|-R|-rR <dataset>' failed in different " \
+	"condition passed."
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/usr/src/test/zfs-tests/tests/functional/cli_root/zfs_destroy/zfs_destroy_006_neg.ksh	Wed Dec 05 22:04:50 2012 -0500
@@ -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) 2012 by Delphix. All rights reserved.
+#
+
+. $STF_SUITE/include/libtest.shlib
+. $STF_SUITE/tests/functional/cli_root/zfs_destroy/zfs_destroy.cfg
+
+#
+# DESCRIPTION:
+# 'zfs destroy' should return an error with badly formed parameters,
+# including null destroyed object parameter, invalid options excluding
+# '-r' and '-f', non-existent datasets.
+#
+# STRATEGY:
+# 1. Create an array of parameters
+# 2. For each parameter in the array, execute 'zfs destroy'
+# 3. Verify an error is returned.
+#
+
+verify_runnable "both"
+
+
+set -A args "" "-r" "-f" "-rf" "-fr" "$TESTPOOL" "-f $TESTPOOL" \
+	"-? $TESTPOOL/$TESTFS" "$TESTPOOL/blah"\
+        "-r $TESTPOOL/blah" "-f $TESTPOOL/blah" "-rf $TESTPOOL/blah" \
+	"-fr $TESTPOOL/blah" "-$ $TESTPOOL/$TESTFS" "-5 $TESTPOOL/$TESTFS" \
+	"-rfgh $TESTPOOL/$TESTFS" "-rghf $TESTPOOL/$TESTFS" \
+	"$TESTPOOL/$TESTFS@blah" "/$TESTPOOL/$TESTFS" "-f /$TESTPOOL/$TESTFS" \
+	"-rf /$TESTPOOL/$TESTFS" "$TESTPOOL/$TESTFS $TESTPOOL/$TESTFS" \
+	"-rRf $TESTPOOL/$TESTFS $TESTPOOL/$TESTFS"
+
+log_assert "'zfs destroy' should return an error with badly-formed parameters."
+
+typeset -i i=0
+while (( $i < ${#args[*]} )); do
+	log_mustnot $ZFS destroy ${args[i]}
+	((i = i + 1))
+done
+
+log_pass "'zfs destroy' badly formed parameters fail as expected."
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/usr/src/test/zfs-tests/tests/functional/cli_root/zfs_destroy/zfs_destroy_007_neg.ksh	Wed Dec 05 22:04:50 2012 -0500
@@ -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) 2012 by Delphix. All rights reserved.
+#
+
+. $STF_SUITE/include/libtest.shlib
+. $STF_SUITE/tests/functional/cli_root/zfs_destroy/zfs_destroy.cfg
+
+#
+# DESCRIPTION:
+#	'zpool destroy' failed if this filesystem is namespace-parent
+#	of origin.
+#
+# STRATEGY:
+#	1. Create pool, fs and snapshot.
+#	2. Create a namespace-parent of origin clone.
+#	3. Promote this clone
+#	4. Verify the original fs can not be destroyed.
+#
+
+verify_runnable "both"
+
+function cleanup
+{
+	if datasetexists $clonesnap; then
+		log_must $ZFS promote $fs
+	fi
+	datasetexists $clone && log_must $ZFS destroy $clone
+	datasetexists $fssnap && log_must $ZFS destroy $fssnap
+}
+
+log_assert "Destroy dataset which is namespace-parent of origin should failed."
+log_onexit cleanup
+
+# Define variable $fssnap & and namespace-parent of origin clone.
+fs=$TESTPOOL/$TESTFS
+fssnap=$fs@snap
+clone=$fs/clone
+clonesnap=$fs/clone@snap
+
+# Define key word for expected failure.
+KEY_WORDS="filesystem has children"
+
+log_must $ZFS snapshot $fssnap
+log_must $ZFS clone $fssnap $clone
+log_must $ZFS promote $clone
+log_mustnot_expect "$KEY_WORDS" $ZFS destroy $fs
+log_mustnot_expect "$KEY_WORDS" $ZFS destroy $clone
+
+log_pass "Destroy dataset which is namespace-parent of origin passed."
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/usr/src/test/zfs-tests/tests/functional/cli_root/zfs_destroy/zfs_destroy_008_pos.ksh	Wed Dec 05 22:04:50 2012 -0500
@@ -0,0 +1,51 @@
+#!/bin/ksh -p
+#
+# CDDL HEADER START
+#
+# The contents of this file are subject to the terms of the
+# Common Development and Distribution License (the "License").
+# You may not use this file except in compliance with the License.
+#
+# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
+# or http://www.opensolaris.org/os/licensing.
+# See the License for the specific language governing permissions
+# and limitations under the License.
+#
+# When distributing Covered Code, include this CDDL HEADER in each
+# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
+# If applicable, add the following below this CDDL HEADER, with the
+# fields enclosed by brackets "[]" replaced with your own identifying
+# information: Portions Copyright [yyyy] [name of copyright owner]
+#
+# CDDL HEADER END
+#
+
+#
+# Copyright (c) 2012 by Delphix. All rights reserved.
+#
+
+. $STF_SUITE/include/libtest.shlib
+. $STF_SUITE/tests/functional/cli_root/zfs_destroy/zfs_destroy.cfg
+. $STF_SUITE/tests/functional/cli_root/zfs_destroy/zfs_destroy_common.kshlib
+
+################################################################################
+#
+# 'zfs destroy -d <snap>' should destroy the snapshot when no clone exists.
+#
+# 1. Create test environment without clones.
+# 2. 'zfs destroy -d <snap>'
+# 3. Verify that the snapshot was destroyed.
+#
+################################################################################
+
+log_assert "'zfs destroy -d <snap>' destroys snapshot if there is no clone"
+log_onexit cleanup_testenv
+
+setup_testenv snap
+
+for snap in $FSSNAP $VOLSNAP; do
+    log_must $ZFS destroy -d $snap
+    log_mustnot datasetexists $snap
+done
+
+log_pass "'zfs destroy -d <snap>' destroys snapshot if there is no clone"
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/usr/src/test/zfs-tests/tests/functional/cli_root/zfs_destroy/zfs_destroy_009_pos.ksh	Wed Dec 05 22:04:50 2012 -0500
@@ -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 (c) 2012 by Delphix. All rights reserved.
+#
+
+. $STF_SUITE/include/libtest.shlib
+. $STF_SUITE/tests/functional/cli_root/zfs_destroy/zfs_destroy.cfg
+. $STF_SUITE/tests/functional/cli_root/zfs_destroy/zfs_destroy_common.kshlib
+
+################################################################################
+#
+# 'zfs destroy -d <snap>' should mark snapshot for deferred destroy when
+# clone exists and destroy when clone is destroyed.
+#
+# 1. Create test environment with clones.
+# 2. 'zfs destroy -d <snap>'
+# 3. Verify snapshot is marked for deferred destroy.
+# 4. 'zfs destroy <clone>'
+# 3. Verify that the snapshot and clone are destroyed.
+#
+################################################################################
+
+log_assert "'zfs destroy -d <snap>' marks cloned snapshot for deferred destroy"
+log_onexit cleanup_testenv
+
+setup_testenv clone
+
+for dstype in FS VOL; do
+    snap=$(eval echo \$${dstype}SNAP)
+    clone=$(eval echo \$${dstype}CLONE)
+    log_must $ZFS destroy -d $snap
+    log_must datasetexists $snap
+    log_must eval "[[ $(get_prop defer_destroy $snap) == 'on' ]]"
+    log_must $ZFS destroy $clone
+    log_mustnot datasetexists $snap
+    log_mustnot datasetexists $clone
+done
+
+log_pass "'zfs destroy -d <snap>' marks cloned snapshot for deferred destroy"
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/usr/src/test/zfs-tests/tests/functional/cli_root/zfs_destroy/zfs_destroy_010_pos.ksh	Wed Dec 05 22:04:50 2012 -0500
@@ -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 (c) 2012 by Delphix. All rights reserved.
+#
+
+. $STF_SUITE/include/libtest.shlib
+. $STF_SUITE/tests/functional/cli_root/zfs_destroy/zfs_destroy.cfg
+. $STF_SUITE/tests/functional/cli_root/zfs_destroy/zfs_destroy_common.kshlib
+
+################################################################################
+#
+# When using 'zfs destroy -R' on a file system heirarchy that inclues a
+# snapshot and a clone of that snapshot, and the snapshot has been
+# defer-destroyed, make sure that the 'zfs destroy -R' works as expected.
+# In particular make sure that libzfs is not confused by the fact that the
+# kernel will automatically remove the defer-destroyed snapshot when the
+# clone is destroyed.
+#
+# 1. Create test environment.
+# 2. Create a clone of the snapshot.
+# 3. 'zfs destroy -d <snap>'
+# 4. 'zfs destroy -R'
+# 5. Verify that the snapshot and clone are destroyed.
+#
+################################################################################
+
+log_assert "'zfs destroy -R' works on deferred destroyed snapshots"
+log_onexit cleanup_testenv
+
+setup_testenv clone
+log_must $UMOUNT -f $TESTDIR1
+
+for dstype in FS VOL; do
+    ds=$(eval echo \$${dstype})
+    snap=$(eval echo \$${dstype}SNAP)
+    clone=$(eval echo \$${dstype}CLONE)
+    log_must $ZFS destroy -d $snap
+    log_must datasetexists $snap
+    log_must $ZFS destroy -R $ds
+    log_mustnot datasetexists $snap
+    log_mustnot datasetexists $clone
+done
+
+log_pass "'zfs destroy -R' works on deferred destroyed snapshots"
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/usr/src/test/zfs-tests/tests/functional/cli_root/zfs_destroy/zfs_destroy_011_pos.ksh	Wed Dec 05 22:04:50 2012 -0500
@@ -0,0 +1,50 @@
+#!/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) 2012 by Delphix. All rights reserved.
+#
+
+. $STF_SUITE/include/libtest.shlib
+. $STF_SUITE/tests/functional/cli_root/zfs_destroy/zfs_destroy.cfg
+. $STF_SUITE/tests/functional/cli_root/zfs_destroy/zfs_destroy_common.kshlib
+
+################################################################################
+#
+# 'zfs destroy -d <snap>' should mark snapshot for deferred destroy when
+# there is a user hold.
+#
+# 1. Create test environment without clones.
+# 2. 'zfs hold <tag> <snap>'
+# 3. 'zfs destroy -d <snap>'
+# 4. Verify snapshot is marked for deferred destroy.
+# 5. 'zfs release <tag> <snap>'
+# 6. Verify that the snapshot is destroyed.
+#
+################################################################################
+
+log_assert "'zfs destroy -d <snap>' marks held snapshot for deferred destroy"
+log_onexit cleanup_testenv
+
+setup_testenv snap
+
+for dstype in FS VOL; do
+    snap=$(eval echo \$${dstype}SNAP)
+    log_must $ZFS hold zfstest $snap
+    log_must $ZFS destroy -d $snap
+    log_must datasetexists $snap
+    log_must eval "[[ $(get_prop defer_destroy $snap) == 'on' ]]"
+    log_must $ZFS release zfstest $snap
+    log_mustnot datasetexists $snap
+done
+
+log_pass "'zfs destroy -d <snap>' marks held snapshot for deferred destroy"
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/usr/src/test/zfs-tests/tests/functional/cli_root/zfs_destroy/zfs_destroy_012_pos.ksh	Wed Dec 05 22:04:50 2012 -0500
@@ -0,0 +1,62 @@
+#!/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) 2012 by Delphix. All rights reserved.
+#
+
+. $STF_SUITE/include/libtest.shlib
+. $STF_SUITE/tests/functional/cli_root/zfs_destroy/zfs_destroy.cfg
+. $STF_SUITE/tests/functional/cli_root/zfs_destroy/zfs_destroy_common.kshlib
+
+################################################################################
+#
+# Deferred destroyed snapshots remain until the last hold is released.
+#
+# 1. Create test environment without clones.
+# 2. 'zfs hold <tag1> <snap>'
+# 3. 'zfs destroy -d <snap>'
+# 4. Sequence of holds/releases including invalid ones that should fail.
+# 4. Verify snapshot still exists.
+# 5. Release all holds.
+# 6. Verify that the snapshot is destroyed.
+#
+################################################################################
+
+log_assert "deferred destroyed snapshots remain until last hold is released"
+log_onexit cleanup_testenv
+
+setup_testenv snap
+
+for dstype in FS VOL; do
+    snap=$(eval echo \$${dstype}SNAP)
+    log_must $ZFS hold zfstest1 $snap
+    log_must $ZFS destroy -d $snap
+    log_must datasetexists $snap
+    log_must eval "[[ $(get_prop defer_destroy $snap) == 'on' ]]"
+
+    log_must $ZFS hold zfstest2 $snap
+    log_mustnot $ZFS hold zfstest1 $snap
+    log_mustnot $ZFS hold zfstest2 $snap
+
+    log_must $ZFS release zfstest1 $snap
+    log_must datasetexists $snap
+    log_mustnot $ZFS release zfstest1 $snap
+    log_must datasetexists $snap
+    log_mustnot $ZFS release zfstest3 $snap
+    log_must datasetexists $snap
+
+    log_must $ZFS release zfstest2 $snap
+    log_mustnot datasetexists $snap
+done
+
+log_pass "deferred destroyed snapshots remain until last hold is released"
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/usr/src/test/zfs-tests/tests/functional/cli_root/zfs_destroy/zfs_destroy_013_neg.ksh	Wed Dec 05 22:04:50 2012 -0500
@@ -0,0 +1,49 @@
+#!/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) 2012 by Delphix. All rights reserved.
+#
+
+. $STF_SUITE/include/libtest.shlib
+. $STF_SUITE/tests/functional/cli_root/zfs_destroy/zfs_destroy.cfg
+. $STF_SUITE/tests/functional/cli_root/zfs_destroy/zfs_destroy_common.kshlib
+
+################################################################################
+#
+# Destroy of held snapshot should fail.
+#
+# 1. Create test environment without clones.
+# 2. 'zfs hold <tag> <snap>'
+# 3. 'zfs destroy <snap>' should fail.
+# 4. Verify snapshot still exists.
+# 5. 'zfs release <tag> <snap>'
+# 6. Verify that we can destroy the snapshot.
+#
+################################################################################
+
+log_assert "zfs destroy of held snapshots fails"
+log_onexit cleanup_testenv
+
+setup_testenv snap
+
+for dstype in FS VOL; do
+    snap=$(eval echo \$${dstype}SNAP)
+    log_must $ZFS hold zfstest $snap
+    log_mustnot $ZFS destroy $snap
+    log_must datasetexists $snap
+    log_must $ZFS release zfstest $snap
+    log_must $ZFS destroy $snap
+    log_mustnot datasetexists $snap
+done
+
+log_pass "zfs destroy of held snapshots fails"
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/usr/src/test/zfs-tests/tests/functional/cli_root/zfs_destroy/zfs_destroy_014_pos.ksh	Wed Dec 05 22:04:50 2012 -0500
@@ -0,0 +1,79 @@
+#!/bin/ksh -p
+#
+# CDDL HEADER START
+#
+# 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.
+#
+# CDDL HEADER END
+#
+
+#
+# Copyright (c) 2012 by Delphix. All rights reserved.
+#
+
+. $STF_SUITE/include/libtest.shlib
+. $STF_SUITE/tests/functional/cli_root/zfs_destroy/zfs_destroy.cfg
+
+#
+# DESCRIPTION:
+#	'zfs destroy -R <snapshot>' can destroy all the child
+#	 snapshots and preserves all the nested datasetss.
+#
+# STRATEGY:
+#	1. Create nested datasets in the storage pool.
+#	2. Create recursive snapshots for all the nested datasets.
+#	3. Verify when snapshots are destroyed recursively, all
+#          the nested datasets still exist.
+#
+
+verify_runnable "both"
+
+log_assert "Verify 'zfs destroy -R <snapshot>' does not destroy" \
+	"nested datasets."
+log_onexit cleanup
+
+datasets="$TESTPOOL/$TESTFS1 $TESTPOOL/$TESTFS1/$TESTFS2
+    $TESTPOOL/$TESTFS1/$TESTFS2/$TESTFS3"
+
+function cleanup
+{
+	for ds in $datasets; do
+		datasetexists $ds && $ZFS destroy -rf $ds
+	done
+}
+
+# create nested datasets
+log_must $ZFS create -p $TESTPOOL/$TESTFS1/$TESTFS2/$TESTFS3
+
+# verify dataset creation
+for ds in $datasets; do
+	datasetexists $ds || log_fail "Create $ds dataset fail."
+done
+
+# create recursive nestedd snapshot
+log_must $ZFS snapshot -r $TESTPOOL/$TESTFS1@snap
+for ds in $datasets; do
+	datasetexists $ds@snap || log_fail "Create $ds@snap snapshot fail."
+done
+
+# destroy nested snapshot recursively
+log_must $ZFS destroy -R $TESTPOOL/$TESTFS1@snap
+
+# verify snapshot destroy
+for ds in $datasets; do
+	datasetexists $ds@snap && log_fail "$ds@snap exists. Destroy failed!"
+done
+
+# verify nested datasets still exist
+for ds in $datasets; do
+	datasetexists $ds || log_fail "Recursive snapshot destroy deleted $ds"
+done
+
+log_pass "'zfs destroy -R <snapshot>' works as expected."
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/usr/src/test/zfs-tests/tests/functional/cli_root/zfs_destroy/zfs_destroy_015_pos.ksh	Wed Dec 05 22:04:50 2012 -0500
@@ -0,0 +1,161 @@
+#!/bin/ksh
+#
+# 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) 2012 by Delphix. All rights reserved.
+#
+
+# DESCRIPTION
+#	zfs destroy <dataset@snap1,snap2..> can destroy a list of multiple
+#	snapshots from the same datasets
+#
+# STRATEGY
+#	1. Create multiple snapshots for the same datset
+#	2. Run zfs destroy for these snapshots for a mix of valid and
+#	   invalid snapshot names
+#	3. Run zfs destroy for snapshots from different datasets and
+#	   pools
+
+. $STF_SUITE/include/libtest.shlib
+. $STF_SUITE/tests/functional/cli_root/zfs_destroy/zfs_destroy.cfg
+
+function cleanup
+{
+	datasetexists $TESTPOOL/$TESTFS1 && $ZFS destroy -R $TESTPOOL/$TESTFS1
+	datasetexists $TESTPOOL/$TESTFS2 && $ZFS destroy -R $TESTPOOL/$TESTFS2
+	poolexists $TESTPOOL2 && $ZPOOL destroy $TESTPOOL2
+	$RM -rf $VIRTUAL_DISK
+}
+
+log_assert "zfs destroy for multiple snapshot is handled correctly"
+log_onexit cleanup
+
+$ZFS create $TESTPOOL/$TESTFS1
+typeset -i i=1
+snaplist=""
+log_note "zfs destroy on valid snapshot names"
+for i in 1 2 3 4 5; do
+	log_must $ZFS snapshot $TESTPOOL/$TESTFS1@snap$i
+	snaplist=$snaplist,snap$i
+done
+snaplist=${snaplist#,}
+log_must $ZFS destroy $TESTPOOL/$TESTFS1@$snaplist
+for i in 1 2 3 4 5; do
+	log_mustnot snapexists $TESTPOOL/$TESFS1@snap$i
+done
+
+log_note "zfs destroy with all bogus snapshot names"
+log_mustnot $ZFS destroy $TESTPOOL/$TESTFS1@snap12,snap21,sna@pple1@,s""nappy2
+
+log_note "zfs destroy with some bogus snapshot names"
+for i in 1 2 3; do
+	log_must $ZFS snapshot $TESTPOOL/$TESTFS1@snap$i
+done
+log_must $ZFS destroy $TESTPOOL/$TESTFS1@snap1,snap2,snapple1,snappy2,snap3
+for i in 1 2 3; do
+	log_mustnot snapexists $TESTPOOL/$TESTFS1@snap$i
+done
+
+log_note "zfs destroy with some snapshot names having special characters"
+for i in 1 2 3; do
+	log_must $ZFS snapshot $TESTPOOL/$TESTFS1@snap$i
+done
+log_must $ZFS destroy $TESTPOOL/$TESTFS1@snap1,@,snap2,,,,snap3,
+for i in 1 2 3; do
+	log_mustnot snapexists $TESTPOOL/$TESTFS1@snap$i
+done
+log_note "zfs destroy for too many snapshots"
+snaplist=""
+for i in {1..100}; do
+	log_must $ZFS snapshot $TESTPOOL/$TESTFS1@snap$i
+	snaplist=$snaplist,snap$i
+done
+snaplist=${snaplist#,}
+log_must $ZFS destroy $TESTPOOL/$TESTFS1@$snaplist
+for i in {1..100}; do
+	log_mustnot snapexists $TESTPOOL/$TESTFS1@snap$i
+done
+log_note "zfs destroy multiple snapshots with hold"
+snaplist=""
+for i in 1 2 3 4 5; do
+	log_must $ZFS snapshot $TESTPOOL/$TESTFS1@snap$i
+	log_must $ZFS hold keep $TESTPOOL/$TESTFS1@snap$i
+	snaplist=$snaplist,snap$i
+done
+snaplist=${snaplist#,}
+log_mustnot $ZFS destroy $TESTPOOL/$TESTFS1@$snaplist
+for i in 1 2 3 4 5; do
+	log_must $ZFS release keep $TESTPOOL/$TESTFS1@snap$i
+done
+log_must $ZFS destroy $TESTPOOL/$TESTFS1@$snaplist
+
+log_note "zfs destroy for multiple snapshots having clones"
+for i in 1 2 3 4 5; do
+	log_must $ZFS snapshot $TESTPOOL/$TESTFS1@snap$i
+done
+snaplist=""
+for i in 1 2 3 4 5; do
+	log_must $ZFS clone $TESTPOOL/$TESTFS1@snap$i $TESTPOOL/$TESTFS1/clone$i
+	snaplist=$snaplist,snap$i
+done
+snaplist=${snaplist#,}
+log_mustnot $ZFS destroy $TESTPOOL/$TESTFS1@$snaplist
+for i in 1 2 3 4 5; do
+	log_must snapexists $TESTPOOL/$TESTFS1@snap$i
+	log_must $ZFS destroy $TESTPOOL/$TESTFS1/clone$i
+done
+
+log_note "zfs destroy for snapshots for different datasets"
+log_must $ZFS create $TESTPOOL/$TESTFS2
+log_must $ZFS snapshot $TESTPOOL/$TESTFS2@fs2snap
+log_must $ZFS create $TESTPOOL/$TESTFS1/$TESTFS2
+log_must $ZFS snapshot $TESTPOOL/$TESTFS1/$TESTFS2@fs12snap
+
+long_arg=$TESTPOOL/$TESTFS1@snap1,$TESTPOOL/$TESTFS2@fs2snap,
+long_arg=$long_arg$TESTPOOL/$TESTFS1/$TESTFS2@fs12snap
+log_must $ZFS destroy $long_arg
+log_mustnot snapexists $TESTPOOL/$TESTFS1@snap1
+log_must snapexists $TESTPOOL/$TESTFS2@fs2snap
+log_must snapexists $TESTPOOL/$TESTFS1/$TESTFS2@fs12snap
+
+log_must $ZFS destroy $TESTPOOL/$TESTFS1@fs2snap,fs12snap,snap2
+log_must snapexists $TESTPOOL/$TESTFS2@fs2snap
+log_must snapexists $TESTPOOL/$TESTFS1/$TESTFS2@fs12snap
+log_mustnot snapexists $TESTPOOL/$TESTFS1@snap2
+
+log_must $ZFS destroy $TESTPOOL/$TESTFS2@fs2snap,fs12snap,snap3
+log_mustnot snapexists $TESTPOOL/$TESTFS2@fs2snap
+log_must snapexists $TESTPOOL/$TESTFS1/$TESTFS2@fs12snap
+log_must snapexists $TESTPOOL/$TESTFS1@snap3
+
+log_note "zfs destroy for snapshots from different pools"
+VIRTUAL_DISK=/var/tmp/disk
+log_must $DD if=/dev/urandom of=$VIRTUAL_DISK bs=1M count=64
+log_must $ZPOOL create $TESTPOOL2 $VIRTUAL_DISK
+log_must poolexists $TESTPOOL2
+
+log_must $ZFS create $TESTPOOL2/$TESTFS1
+log_must $ZFS snapshot $TESTPOOL2/$TESTFS1@snap
+long_arg=$TESTPOOL2/$TESTFS1@snap,$TESTPOOL/$TESTFS1@snap3,
+long_arg=$long_arg$TESTPOOL/$TESTFS1@snap5
+log_must $ZFS destroy $long_arg
+log_mustnot snapexists $TESTPOOL2/$TESTFS1@snap
+log_must snapexists $TESTPOOL/$TESTFS1@snap3
+log_must snapexists $TESTPOOL/$TESTFS1@snap5
+
+log_must $ZFS snapshot $TESTPOOL2/$TESTFS1@snap
+log_must $ZFS destroy $TESTPOOL2/$TESTFS1@snap5,snap3,snap
+log_mustnot snapexists $TESTPOOL2/$TESTFS1@snap
+log_must snapexists $TESTPOOL/$TESTFS1@snap3
+log_must snapexists $TESTPOOL/$TESTFS1@snap5
+
+log_pass "zfs destroy for multiple snapshots passes"
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/usr/src/test/zfs-tests/tests/functional/cli_root/zfs_destroy/zfs_destroy_016_pos.ksh	Wed Dec 05 22:04:50 2012 -0500
@@ -0,0 +1,186 @@
+# !/bin/ksh
+#
+# 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) 2012 by Delphix. All rights reserved.
+#
+
+# DESCRIPTION
+# Verify zfs destroy test for range of snapshots by giving a list
+# of valid and invalid arguments.
+
+# STRATEGY
+# 1. Create a list of valid and invalid arguments for range snapshot
+#     destroy.
+# 2. Set up a filesystem and a volume with multiple snapshots
+# 3. Run zfs destroy for all the arguments and verify existence of snapshots
+# 4. Verify the destroy for snapshots with clones and hold
+
+. $STF_SUITE/include/libtest.shlib
+
+function cleanup
+{
+	datasetexists $TESTPOOL/$TESTFS1 && \
+	    log_must $ZFS destroy -R $TESTPOOL/$TESTFS1
+	datasetexists $TESTPOOL/$TESTVOL && \
+	    log_must $ZFS destroy -Rf $TESTPOOL/$TESTVOL
+}
+
+function setup_snapshots
+{
+	for i in $snaps; do
+		datasetexists $TESTPOOL/$TESTFS1@snap$i && \
+		    log_must $ZFS destroy $TESTPOOL/$TESTFS1@snap$i
+		datasetexists $TESTPOOL/$TESTVOL@snap$i && \
+		    log_must $ZFS destroy $TESTPOOL/$TESTVOL@snap$i
+		log_must $ZFS snapshot $TESTPOOL/$TESTFS1@snap$i
+		log_must $ZFS snapshot $TESTPOOL/$TESTVOL@snap$i
+	done
+}
+
+function verify_snapshots
+{
+	typeset snap_exists=${1:-0}
+	if [[ $snap_exists == 1 ]]; then
+		for i in $range; do
+			snapexists $TESTPOOL/$TESTFS1@snap$i || \
+			    log_fail "zfs destroy should not have destroyed" \
+			    "$TESTPOOL/$TESTFS1@snap$i"
+			snapexists $TESTPOOL/$TESTVOL@snap$i || \
+			    log_fail "zfs destroy should not have destroyed" \
+			    "$TESTPOOL/$TESTVOL@snap$i"
+		done
+	else
+		for i in $range; do
+			snapexists $TESTPOOL/$TESTFS1@snap$i && \
+			    log_fail "zfs destroy should have destroyed" \
+			    "$TESTPOOL/$TESTFS1@snap$i"
+			snapexists $TESTPOOL/$TESTVOL@snap$i && \
+			    log_fail "zfs destroy should have destroyed" \
+			    "$TESTPOOL/$TESTVOL@snap$i"
+		done
+	fi
+}
+
+invalid_args="@snap0%snap5 @snap1%snap6 @snap0%snap6 @snap5%snap1 \
+    @snap1%$TESTPOOL/$TESTFS1@snap5 @snap1%%snap5 @snap1%@snap5 \
+    @@snap1%snap5 snap1%snap5 snap1%snap3%snap5"
+valid_args="@snap1%snap5 @%"
+log_assert "zfs destroy deletes ranges of snapshots"
+log_onexit cleanup
+
+log_must $ZFS create $TESTPOOL/$TESTFS1
+log_must $ZFS create -V $VOLSIZE $TESTPOOL/$TESTVOL
+snaps="1 2 3 4 5"
+log_note "Verify the valid arguments"
+range="1 2 3 4 5"
+for args in $valid_args; do
+	setup_snapshots
+	log_must $ZFS destroy $TESTPOOL/$TESTFS1$args
+	log_must $ZFS destroy $TESTPOOL/$TESTVOL$args
+	verify_snapshots
+done
+
+log_note "Verify invalid arguements"
+setup_snapshots
+for args in $invalid_args; do
+	log_mustnot $ZFS destroy $TESTPOOL/$TESTFS1$args
+	log_mustnot $ZFS destroy $TESTPOOL/$TESTVOL$args
+	log_must verify_snapshots 1
+done
+
+log_note "Destroy the begining range"
+
+log_must $ZFS destroy $TESTPOOL/$TESTFS1@%snap3
+log_must $ZFS destroy $TESTPOOL/$TESTVOL@%snap3
+range="1 2 3"
+verify_snapshots
+range="4 5"
+verify_snapshots 1
+
+setup_snapshots
+log_note "Destroy the mid range"
+log_must $ZFS destroy $TESTPOOL/$TESTFS1@snap2%snap4
+log_must $ZFS destroy $TESTPOOL/$TESTVOL@snap2%snap4
+range="2 3 4"
+verify_snapshots
+log_must $ZFS destroy $TESTPOOL/$TESTFS1@snap1%snap5
+log_must $ZFS destroy $TESTPOOL/$TESTVOL@snap1%snap5
+range="1 5"
+verify_snapshots
+
+setup_snapshots
+log_note "Destroy the end range"
+log_must $ZFS destroy $TESTPOOL/$TESTFS1@snap3%
+log_must $ZFS destroy $TESTPOOL/$TESTVOL@snap3%
+range="1 2"
+verify_snapshots 1
+range="3 4 5"
+verify_snapshots
+
+setup_snapshots
+log_note "Destroy a simple list"
+log_must $ZFS destroy $TESTPOOL/$TESTFS1@snap2,snap4
+log_must $ZFS destroy $TESTPOOL/$TESTVOL@snap2,snap4
+range="2 4"
+verify_snapshots
+range="1 3 5"
+verify_snapshots 1
+
+setup_snapshots
+log_note "Destroy a list and range together"
+log_must $ZFS destroy $TESTPOOL/$TESTFS1@snap1%snap3,snap5
+log_must $ZFS destroy $TESTPOOL/$TESTVOL@snap1%snap3,snap5
+range="1 2 3 5"
+verify_snapshots
+range=4
+verify_snapshots 1
+
+snaps="1 2 3 5 6 7 8 9 10"
+setup_snapshots
+log_note "Destroy a list of ranges"
+log_must $ZFS destroy $TESTPOOL/$TESTFS1@snap1%snap3,snap5
+log_must $ZFS destroy $TESTPOOL/$TESTVOL@snap1%snap3,snap5
+range="1 2 3 5"
+verify_snapshots
+range=4
+verify_snapshots 1
+
+snaps="1 2 3 4 5"
+setup_snapshots
+log_note "Snapshot destory with hold"
+range="1 2 3 4 5"
+for i in 1 2 3 4 5; do
+	log_must $ZFS hold keep $TESTPOOL/$TESTFS1@snap$i
+	log_must $ZFS hold keep $TESTPOOL/$TESTVOL@snap$i
+done
+log_mustnot $ZFS destroy $TESTPOOL/$TESTFS1@snap1%snap5
+log_mustnot $ZFS destroy $TESTPOOL/$TESTVOL@snap1%snap5
+verify_snapshots 1
+for i in 1 2 3 4 5; do
+	log_must $ZFS release keep $TESTPOOL/$TESTFS1@snap$i
+	log_must $ZFS release keep $TESTPOOL/$TESTVOL@snap$i
+done
+log_must $ZFS destroy $TESTPOOL/$TESTFS1@snap1%snap5
+log_must $ZFS destroy $TESTPOOL/$TESTVOL@snap1%snap5
+verify_snapshots
+
+log_note "Range destroy for snapshots having clones"
+setup_snapshots
+for i in 1 2 3 4 5; do
+	log_must $ZFS clone $TESTPOOL/$TESTFS1@snap$i $TESTPOOL/$TESTFS1/clone$i
+done
+log_must $ZFS destroy -R $TESTPOOL/$TESTFS1@snap1%snap5
+log_must $ZFS destroy $TESTPOOL/$TESTVOL@snap1%snap5
+verify_snapshots
+
+log_pass "'zfs destroy' successfully destroys ranges of snapshots"
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/usr/src/test/zfs-tests/tests/functional/cli_root/zfs_destroy/zfs_destroy_common.kshlib	Wed Dec 05 22:04:50 2012 -0500
@@ -0,0 +1,146 @@
+#
+# CDDL HEADER START
+#
+# The contents of this file are subject to the terms of the
+# Common Development and Distribution License (the "License").
+# You may not use this file except in compliance with the License.
+#
+# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
+# or http://www.opensolaris.org/os/licensing.
+# See the License for the specific language governing permissions
+# and limitations under the License.
+#
+# When distributing Covered Code, include this CDDL HEADER in each
+# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
+# If applicable, add the following below this CDDL HEADER, with the
+# fields enclosed by brackets "[]" replaced with your own identifying
+# information: Portions Copyright [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.
+#
+
+. $STF_SUITE/include/libtest.shlib
+. $STF_SUITE/tests/functional/cli_root/zfs_destroy/zfs_destroy.cfg
+
+#
+# Create or recover a set of test environment which include ctr, vol, fs,
+# snap & clone. It looks like the following.
+#
+# pool
+#    |ctr
+#    |  |fs
+#    |  | |fssnap
+#    |  |vol
+#    |     |volsnap
+#    |fsclone
+#    |volclone
+#
+# $1 indicate which dependent dataset need be created. Such as 'snap', 'clone'.
+#
+function setup_testenv #[dtst]
+{
+	typeset dtst=$1
+
+	if ! datasetexists $CTR; then
+		log_must $ZFS create $CTR
+	fi
+	if ! datasetexists $FS; then
+		log_must $ZFS create $FS
+	fi
+	# Volume test is only availible on globle zone
+	if ! datasetexists $VOL && is_global_zone; then
+		log_must $ZFS create -V $VOLSIZE $VOL
+
+		$ECHO "y" | $NEWFS /dev/zvol/dsk/$VOL > /dev/null 2>&1
+		if (( $? == 0 )); then
+			log_note "SUCCESS: $NEWFS /dev/zvol/dsk/$VOL>/dev/null"
+		else
+			log_fail "$NEWFS /dev/zvol/dsk/$VOL > /dev/null"
+		fi
+
+		if [[ ! -d $TESTDIR1 ]]; then
+			log_must $MKDIR $TESTDIR1
+		fi
+		log_must $MOUNT /dev/zvol/dsk/$VOL $TESTDIR1
+	fi
+
+	if [[ $dtst == snap || $dtst == clone ]]; then
+		if ! datasetexists $FSSNAP; then
+			log_must $ZFS snapshot $FSSNAP
+		fi
+		if ! datasetexists $VOLSNAP && is_global_zone; then
+			log_must $ZFS snapshot $VOLSNAP
+		fi
+	fi
+
+	if [[ $dtst == clone ]]; then
+		if ! datasetexists $FSCLONE; then
+			log_must $ZFS clone $FSSNAP $FSCLONE
+		fi
+		if ! datasetexists $VOLCLONE && is_global_zone; then
+			log_must $ZFS clone $VOLSNAP $VOLCLONE
+		fi
+	fi
+}
+
+# Clean up the testing environment
+#
+function cleanup_testenv
+{
+	if is_global_zone && ismounted "$TESTDIR1" "ufs" ; then
+		log_must $UMOUNT -f $TESTDIR1
+	fi
+	if [[ -d $TESTDIR1 ]]; then
+		log_must $RM -rf $TESTDIR1
+	fi
+
+	$PKILL $MKBUSY
+
+	if datasetexists $CTR; then
+		log_must $ZFS destroy -Rf $CTR
+	fi
+}
+
+#
+# Delete volume and related datasets from list, if the test cases was
+# runing in local zone. Then check them are existed or non-exists.
+#
+# $1   function name
+# $2-n datasets name
+#
+function check_dataset
+{
+	typeset funname=$1
+	typeset newlist=""
+	typeset dtst
+	shift
+
+	for dtst in "$@"; do
+		# Volume and related stuff are unvailable in local zone
+		if ! is_global_zone; then
+			if [[ $dtst == $VOL || $dtst == $VOLSNAP || \
+				$dtst == $VOLCLONE ]]
+			then
+				continue
+			fi
+		fi
+		newlist="$newlist $dtst"
+	done
+
+	if (( ${#newlist} != 0 )); then
+		# Run each item in $newlist individually so on failure, the
+		# probelmatic dataset is listed in the logs.
+		for i in $newlist; do
+			log_must $funname $i
+		done
+	fi
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/usr/src/test/zfs-tests/tests/functional/cli_root/zfs_get/Makefile	Wed Dec 05 22:04:50 2012 -0500
@@ -0,0 +1,53 @@
+#
+# 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) 2012 by Delphix. All rights reserved.
+#
+
+include $(SRC)/Makefile.master
+
+ROOTOPTPKG = $(ROOT)/opt/zfs-tests
+TESTDIR = $(ROOTOPTPKG)/tests/functional/cli_root/zfs_get
+
+PROGS = cleanup \
+	setup \
+	zfs_get_001_pos \
+	zfs_get_002_pos \
+	zfs_get_003_pos \
+	zfs_get_004_pos \
+	zfs_get_005_neg \
+	zfs_get_006_neg \
+	zfs_get_007_neg \
+	zfs_get_008_pos \
+	zfs_get_009_pos \
+	zfs_get_010_neg
+
+FILES = zfs_get_common.kshlib \
+	zfs_get_list_d.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	Thu Jan 01 00:00:00 1970 +0000
+++ b/usr/src/test/zfs-tests/tests/functional/cli_root/zfs_get/cleanup.ksh	Wed Dec 05 22:04:50 2012 -0500
@@ -0,0 +1,30 @@
+#!/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.
+#
+
+. $STF_SUITE/include/libtest.shlib
+
+default_cleanup
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/usr/src/test/zfs-tests/tests/functional/cli_root/zfs_get/setup.ksh	Wed Dec 05 22:04:50 2012 -0500
@@ -0,0 +1,32 @@
+#!/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.
+#
+
+. $STF_SUITE/include/libtest.shlib
+
+DISK=${DISKS%% *}
+
+default_container_volume_setup $DISK
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/usr/src/test/zfs-tests/tests/functional/cli_root/zfs_get/zfs_get_001_pos.ksh	Wed Dec 05 22:04:50 2012 -0500
@@ -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 2009 Sun Microsystems, Inc.  All rights reserved.
+# Use is subject to license terms.
+#
+
+. $STF_SUITE/tests/functional/cli_root/zfs_get/zfs_get_common.kshlib
+. $STF_SUITE/tests/functional/cli_root/zfs_get/zfs_get_list_d.kshlib
+
+#
+# DESCRIPTION:
+# Setting the valid option and properties, 'zfs get' should return the
+# correct property value.
+#
+# STRATEGY:
+# 1. Create pool, filesystem, volume and snapshot.
+# 2. Setting valid parameter, 'zfs get' should succeed.
+# 3. Compare the output property name with the original input property.
+#
+
+verify_runnable "both"
+
+typeset options=("" "-p" "-r" "-H")
+
+typeset -i i=${#options[*]}
+typeset -i j=0
+while ((j<${#depth_options[*]}));
+do
+	options[$i]=-"${depth_options[$j]}"
+	((j+=1))
+	((i+=1))
+done
+
+typeset zfs_props=("type" used available creation volsize referenced \
+    compressratio mounted origin recordsize quota reservation mountpoint \
+    sharenfs checksum compression atime devices exec readonly setuid zoned \
+    snapdir aclmode aclinherit canmount primarycache secondarycache \
+    usedbychildren usedbydataset usedbyrefreservation usedbysnapshots \
+    version)
+
+typeset userquota_props=(userquota@root groupquota@root userused@root \
+    groupused@root)
+typeset all_props=("${zfs_props[@]}" "${userquota_props[@]}")
+typeset dataset=($TESTPOOL/$TESTCTR $TESTPOOL/$TESTFS $TESTPOOL/$TESTVOL \
+	$TESTPOOL/$TESTFS@$TESTSNAP $TESTPOOL/$TESTVOL@$TESTSNAP)
+
+#
+# According to dataset and option, checking if 'zfs get' return correct
+# property information.
+#
+# $1 dataset
+# $2 properties which are expected to output into $TESTDIR/$TESTFILE0
+# $3 option
+#
+function check_return_value
+{
+	typeset dst=$1
+	typeset props=$2
+	typeset opt=$3
+	typeset -i found=0
+	typeset p
+
+	for p in $props; do
+		found=0
+
+		while read line; do
+			typeset item
+			item=$($ECHO $line | $AWK '{print $2}' 2>&1)
+
+			if [[ $item == $p ]]; then
+				((found += 1))
+				break
+			fi
+		done < $TESTDIR/$TESTFILE0
+
+		if ((found == 0)); then
+			log_fail "'zfs get $opt $props $dst' return " \
+			    "error message.'$p' haven't been found."
+		fi
+	done
+
+	log_note "SUCCESS: '$ZFS get $opt $prop $dst'."
+}
+
+log_assert "Setting the valid options and properties 'zfs get' should return " \
+    "the correct property value."
+log_onexit cleanup
+
+# Create filesystem and volume's snapshot
+create_snapshot $TESTPOOL/$TESTFS $TESTSNAP
+create_snapshot $TESTPOOL/$TESTVOL $TESTSNAP
+
+typeset -i i=0
+while ((i < ${#dataset[@]})); do
+	for opt in "${options[@]}"; do
+		for prop in ${all_props[@]}; do
+			eval "$ZFS get $opt $prop ${dataset[i]} > \
+			    $TESTDIR/$TESTFILE0"
+			ret=$?
+			if [[ $ret != 0 ]]; then
+				log_fail "$ZFS get returned: $ret"
+			fi
+			check_return_value ${dataset[i]} "$prop" "$opt"
+		done
+	done
+	((i += 1))
+done
+
+log_pass "Setting the valid options to dataset, it should succeed and return " \
+    "valid value. 'zfs get' pass."
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/usr/src/test/zfs-tests/tests/functional/cli_root/zfs_get/zfs_get_002_pos.ksh	Wed Dec 05 22:04:50 2012 -0500
@@ -0,0 +1,87 @@
+#!/bin/ksh -p
+#
+# CDDL HEADER START
+#
+# The contents of this file are subject to the terms of the
+# Common Development and Distribution License (the "License").
+# You may not use this file except in compliance with the License.
+#
+# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
+# or http://www.opensolaris.org/os/licensing.
+# See the License for the specific language governing permissions
+# and limitations under the License.
+#
+# When distributing Covered Code, include this CDDL HEADER in each
+# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
+# If applicable, add the following below this CDDL 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.
+#
+
+. $STF_SUITE/tests/functional/cli_root/zfs_get/zfs_get_common.kshlib
+
+#
+# DESCRIPTION:
+# Setting the valid option and properties 'zfs get' return correct value.
+# It should be successful.
+#
+# STRATEGY:
+# 1. Create pool, filesystem, dataset, volume and snapshot.
+# 2. Getting the options and properties random combination.
+# 3. Using the combination as the parameters of 'zfs get' to check the
+# command line return value.
+#
+
+verify_runnable "both"
+
+typeset options=(" " p r H)
+
+typeset zfs_props=("type" used available creation volsize referenced \
+    compressratio mounted origin recordsize quota reservation mountpoint \
+    sharenfs checksum compression atime devices exec readonly setuid zoned \
+    snapdir aclmode aclinherit canmount primarycache secondarycache \
+    usedbychildren usedbydataset usedbyrefreservation usedbysnapshots version)
+
+typeset userquota_props=(userquota@root groupquota@root userused@root \
+    groupused@root)
+typeset props=("${zfs_props[@]}" "${userquota_props[@]}")
+typeset dataset=($TESTPOOL/$TESTCTR $TESTPOOL/$TESTFS $TESTPOOL/$TESTVOL \
+	$TESTPOOL/$TESTFS@$TESTSNAP $TESTPOOL/$TESTVOL@$TESTSNAP)
+
+log_assert "Setting the valid options and properties 'zfs get' return " \
+    "correct value. It should be successful."
+log_onexit cleanup
+
+# Create volume and filesystem's snapshot
+create_snapshot $TESTPOOL/$TESTFS $TESTSNAP
+create_snapshot $TESTPOOL/$TESTVOL $TESTSNAP
+
+#
+# Begin to test 'get [-prH] <property[,property]...>
+#		<filesystem|dataset|volume|snapshot>'
+#		'get [-prH] <-a|-d> <filesystem|dataset|volume|snapshot>"
+#
+typeset -i opt_numb=8
+typeset -i prop_numb=20
+for dst in ${dataset[@]}; do
+	# option can be empty, so "" is necessary.
+	for opt in "" $(gen_option_str "${options[*]}" "-" "" $opt_numb); do
+		for prop in $(gen_option_str "${props[*]}" "" "," $prop_numb)
+		do
+			$ZFS get $opt $prop $dst > /dev/null 2>&1
+			ret=$?
+			if [[ $ret != 0 ]]; then
+				log_fail "$ZFS get $opt $prop $dst (Code: $ret)"
+			fi
+		done
+	done
+done
+
+log_pass "Setting the valid options to dataset, 'zfs get' pass."
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/usr/src/test/zfs-tests/tests/functional/cli_root/zfs_get/zfs_get_003_pos.ksh	Wed Dec 05 22:04:50 2012 -0500
@@ -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 2009 Sun Microsystems, Inc.  All rights reserved.
+# Use is subject to license terms.
+#
+
+. $STF_SUITE/include/libtest.shlib
+
+#
+# DESCRIPTION:
+#	'zfs get' should get consistent report with different options.
+#
+# STRATEGY:
+#	1. Create pool and filesystem.
+#	2. 'zfs mount -o remount,noatime <fs>.'
+#	3. Verify the value of 'zfs get atime' and 'zfs get all | grep atime'
+#	   are identical.
+#
+
+verify_runnable "both"
+
+function cleanup
+{
+	log_must $ZFS mount -o remount,atime $TESTPOOL/$TESTFS
+}
+
+log_assert "'zfs get' should get consistent report with different option."
+log_onexit cleanup
+
+log_must $ZFS set atime=on $TESTPOOL/$TESTFS
+log_must $ZFS mount -o remount,noatime $TESTPOOL/$TESTFS
+
+value1=$($ZFS get -H atime $TESTPOOL/$TESTFS | $AWK '{print $3}')
+value2=$($ZFS get -H all $TESTPOOL/$TESTFS | $AWK '{print $2 " " $3}' | \
+	$GREP ^atime | $AWK '{print $2}')
+if [[ $value1 != $value2 ]]; then
+	log_fail "value1($value1) != value2($value2)"
+fi
+
+log_pass "'zfs get'  get consistent report with different option passed."
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/usr/src/test/zfs-tests/tests/functional/cli_root/zfs_get/zfs_get_004_pos.ksh	Wed Dec 05 22:04:50 2012 -0500
@@ -0,0 +1,227 @@
+#!/bin/ksh -p
+#
+# CDDL HEADER START
+#
+# The contents of this file are subject to the terms of the
+# Common Development and Distribution License (the "License").
+# You may not use this file except in compliance with the License.
+#
+# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
+# or http://www.opensolaris.org/os/licensing.
+# See the License for the specific language governing permissions
+# and limitations under the License.
+#
+# When distributing Covered Code, include this CDDL HEADER in each
+# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
+# If applicable, add the following below this CDDL HEADER, with the
+# fields enclosed by brackets "[]" replaced with your own identifying
+# information: Portions Copyright [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.
+#
+
+. $STF_SUITE/include/libtest.shlib
+
+#
+# DESCRIPTION:
+# Verify 'zfs get all' can get all properties for all datasets in the system
+#
+# STRATEGY:
+#	1. Create datasets for testing
+#	2. Issue 'zfs get all' command
+#	3. Verify the command gets all available properties of all datasets
+#
+
+verify_runnable "both"
+
+function cleanup
+{
+	[[ -e $propfile ]] && $RM -f $propfile
+
+	datasetexists $clone  && \
+		log_must $ZFS destroy $clone
+	for snap in $fssnap $volsnap ; do
+		snapexists $snap && \
+			log_must $ZFS destroy $snap
+	done
+
+	if [[ -n $globalzone ]] ; then
+		for pool in $TESTPOOL1 $TESTPOOL2 $TESTPOOL3; do
+			poolexists $pool && \
+				log_must $ZPOOL destroy -f $pool
+		done
+		for file in `$LS $TESTDIR1/poolfile*`; do
+			$RM -f $file
+		done
+	else
+		for fs in $TESTPOOL/$TESTFS1 $TESTPOOL/$TESTFS2 $TESTPOOL/$TESTFS3; do
+			datasetexists $fs && \
+				log_must $ZFS destroy -rf $fs
+		done
+	fi
+}
+
+log_assert "Verify the functions of 'zfs get all' work."
+log_onexit cleanup
+
+typeset globalzone=""
+
+if is_global_zone ; then
+	globalzone="true"
+fi
+
+set -A opts "" "-r" "-H" "-p" "-rHp" "-o name" \
+	"-s local,default,temporary,inherited,none" \
+	"-o name -s local,default,temporary,inherited,none" \
+	"-rHp -o name -s local,default,temporary,inherited,none"
+set -A usrprops "a:b=c" "d_1:1_e=0f" "123:456=789"
+
+fs=$TESTPOOL/$TESTFS
+fssnap=$fs@$TESTSNAP
+clone=$TESTPOOL/$TESTCLONE
+volsnap=$TESTPOOL/$TESTVOL@$TESTSNAP
+
+#set user defined properties for $TESTPOOL
+for usrprop in ${usrprops[@]}; do
+	log_must $ZFS set $usrprop $TESTPOOL
+done
+# create snapshot and clone in $TESTPOOL
+log_must $ZFS snapshot $fssnap
+log_must $ZFS clone $fssnap $clone
+log_must $ZFS snapshot $volsnap
+
+# collect datasets which can be set user defined properties
+usrpropds="$clone $fs"
+
+# collect all datasets which we are creating
+allds="$fs $clone $fssnap $volsnap"
+
+#create pool and datasets to guarantee testing under multiple pools and datasets.
+file=$TESTDIR1/poolfile
+typeset -i FILESIZE=104857600    #100M
+(( DFILESIZE = FILESIZE * 2 ))   # double of FILESIZE
+typeset -i VOLSIZE=10485760      #10M
+availspace=$(get_prop available $TESTPOOL)
+typeset -i i=0
+
+# make sure 'availspace' is larger then twice of FILESIZE to create a new pool.
+# If any, we only totally create 3 pools for multple datasets testing to limit
+# testing time
+while (( availspace > DFILESIZE )) && (( i < 3 )) ; do
+	(( i += 1 ))
+
+	if [[ -n $globalzone ]] ; then
+		log_must $MKFILE $FILESIZE ${file}$i
+		eval pool=\$TESTPOOL$i
+		log_must $ZPOOL create $pool ${file}$i
+	else
+		eval pool=$TESTPOOL/\$TESTFS$i
+		log_must $ZFS create $pool
+	fi
+
+	#set user defined properties for testing
+	for usrprop in ${usrprops[@]}; do
+		log_must $ZFS set $usrprop $pool
+	done
+
+	#create datasets in pool
+	log_must $ZFS create $pool/$TESTFS
+	log_must $ZFS snapshot $pool/$TESTFS@$TESTSNAP
+	log_must $ZFS clone $pool/$TESTFS@$TESTSNAP $pool/$TESTCLONE
+
+	if [[ -n $globalzone ]] ; then
+		log_must $ZFS create -V $VOLSIZE $pool/$TESTVOL
+	else
+		log_must $ZFS create $pool/$TESTVOL
+	fi
+
+	ds=`$ZFS list -H -r -o name -t filesystem,volume $pool`
+	usrpropds="$usrpropds $pool/$TESTFS $pool/$TESTCLONE $pool/$TESTVOL"
+	allds="$allds $pool/$TESTFS $pool/$TESTCLONE $pool/$TESTVOL \
+		$pool/$TESTFS@$TESTSNAP"
+
+	availspace=$(get_prop available $TESTPOOL)
+done
+
+#the expected number of property for each type of dataset in this testing
+typeset -i fspropnum=27
+typeset -i snappropnum=8
+typeset -i volpropnum=15
+propfile=/var/tmp/allpropfile.$$
+
+typeset -i i=0
+typeset -i propnum=0
+typeset -i failflag=0
+while (( i < ${#opts[*]} )); do
+	[[ -e $propfile ]] && $RM -f $propfile
+	log_must eval "$ZFS get ${opts[i]} all >$propfile"
+
+	for ds in $allds; do
+		$GREP $ds $propfile >/dev/null 2>&1
+		(( $? != 0 )) && \
+			log_fail "There is no property for" \
+				"dataset $ds in 'get all' output."
+
+		propnum=`$CAT $propfile | $AWK '{print $1}' | \
+			$GREP "${ds}$" | $WC -l`
+		ds_type=`$ZFS get -H -o value type $ds`
+		case $ds_type in
+			filesystem )
+				(( propnum < fspropnum )) && \
+				(( failflag += 1 ))
+				;;
+			snapshot )
+				(( propnum < snappropnum )) && \
+				(( failflag += 1 ))
+				;;
+			volume )
+				(( propnum < volpropnum )) && \
+				(( failflag += 1 ))
+				;;
+		esac
+
+		(( failflag != 0 )) && \
+			log_fail " 'zfs get all' fails to get out " \
+				"all properties for dataset $ds."
+
+		(( propnum = 0 ))
+		(( failflag = 0 ))
+	done
+
+	(( i += 1 ))
+done
+
+log_note "'zfs get' can get particular property for all datasets with that property."
+
+function do_particular_prop_test #<property> <suitable datasets>
+{
+	typeset	props="$1"
+	typeset ds="$2"
+
+	for prop in ${commprops[*]}; do
+		ds=`$ZFS get -H -o name $prop`
+
+		[[ "$ds" != "$allds" ]] && \
+			log_fail "The result datasets are $ds, but all suitable" \
+				"datasets are $allds for the property $prop"
+	done
+}
+
+# Here, we do a testing for user defined properties and the most common properties
+# for all datasets.
+commprop="type creation used referenced compressratio"
+usrprop="a:b d_1:1_e 123:456"
+
+do_particular_prop_test "$commprop" "$allds"
+do_particular_prop_test "$usrprop" "$usrpropds"
+
+log_pass "'zfs get all' works as expected."
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/usr/src/test/zfs-tests/tests/functional/cli_root/zfs_get/zfs_get_005_neg.ksh	Wed Dec 05 22:04:50 2012 -0500
@@ -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 2009 Sun Microsystems, Inc.  All rights reserved.
+# Use is subject to license terms.
+#
+
+. $STF_SUITE/tests/functional/cli_root/zfs_get/zfs_get_common.kshlib
+
+#
+# DESCRIPTION:
+# Setting the invalid option and properties, 'zfs get' should failed.
+#
+# STRATEGY:
+# 1. Create pool, filesystem, volume and snapshot.
+# 2. Getting incorrect combination by invalid parameters
+# 3. Using the combination as the parameters of 'zfs get' to check the
+# command line return value.
+#
+
+verify_runnable "both"
+
+typeset val_opts=(p r H)
+typeset v_props=(type used available creation volsize referenced compressratio \
+    mounted origin recordsize quota reservation mountpoint sharenfs checksum \
+    compression atime devices exec readonly setuid zoned snapdir aclmode \
+    aclinherit canmount primarycache secondarycache \
+    usedbychildren usedbydataset usedbyrefreservation usedbysnapshots version)
+
+typeset  userquota_props=(userquota@root groupquota@root userused@root \
+    groupused@root)
+typeset val_pros=(-- "${v_props[@]}" "${userquota_props[@]}")
+set -f	# Force shell does not parse '?' and '*' as the wildcard
+typeset inval_opts=(P R h ? *)
+typeset inval_props=(Type 0 ? * -on --on readonl time USED RATIO MOUNTED)
+
+typeset dataset=($TESTPOOL/$TESTFS $TESTPOOL/$TESTCTR $TESTPOOL/$TESTVOL \
+    $TESTPOOL/$TESTFS@$TESTSNAP $TESTPOOL/$TESTVOL@$TESTSNAP)
+
+typeset -i opt_numb=6
+typeset -i prop_numb=12
+
+val_opts_str=$(gen_option_str "${val_opts[*]}" "-" "" $opt_numb)
+val_props_str=$(gen_option_str "${val_props[*]}" "" "," $prop_numb)
+val_props_str="$val_props_str -a -d"
+
+inval_opts_str=$(gen_option_str "${inval_opts[*]}" "-" "" $opt_numb)
+inval_props_str=$(gen_option_str "${inval_props[*]}" "" "," $prop_numb)
+
+#
+# Test different options and properties combination.
+#
+# $1 options
+# $2 properties
+#
+function test_options
+{
+	typeset opts=$1
+	typeset props=$2
+
+	for dst in ${dataset[@]}; do
+		for opt in $opts; do
+			for prop in $props; do
+				$ZFS get $opt $prop $dst > /dev/null 2>&1
+				ret=$?
+				if [[ $ret == 0 ]]; then
+					log_fail "$ZFS get $opt $prop $dst " \
+					    "unexpectedly succeeded."
+				fi
+			done
+		done
+	done
+}
+
+log_assert "Setting the invalid option and properties, 'zfs get' should be \
+    failed."
+log_onexit cleanup
+
+# Create filesystem and volume's snapshot
+create_snapshot $TESTPOOL/$TESTFS $TESTSNAP
+create_snapshot $TESTPOOL/$TESTVOL $TESTSNAP
+
+log_note "Valid options + invalid properties, 'zfs get' should fail."
+test_options "$val_opts_str" "$inval_props_str"
+
+log_note "Invalid options + valid properties, 'zfs get' should fail."
+test_options "$inval_opts_str" "$val_props_str"
+
+log_note "Invalid options + invalid properties, 'zfs get' should fail."
+test_options "$inval_opts_str" "$inval_props_str"
+
+log_pass "Setting the invalid options to dataset, 'zfs get' pass."
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/usr/src/test/zfs-tests/tests/functional/cli_root/zfs_get/zfs_get_006_neg.ksh	Wed Dec 05 22:04:50 2012 -0500
@@ -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.
+#
+
+. $STF_SUITE/tests/functional/cli_root/zfs_get/zfs_get_common.kshlib
+
+#
+# DESCRIPTION:
+# Verify 'zfs get all' can deal with invalid scenarios
+#
+# STRATEGY:
+# 1. Define invalid scenarios for 'zfs get all'
+# 2. Run zfs get with those invalid scenarios
+# 3. Verify that zfs get fails with invalid scenarios
+#
+
+verify_runnable "both"
+
+log_assert "Verify 'zfs get all' fails with invalid combination scenarios."
+
+set -f	# Force ksh ignore '?' and '*'
+set -A  bad_combine "ALL" "\-R all" "-P all" "-h all" "-rph all" "-RpH all" "-PrH all" \
+		"-o all" "-s all" "-? all" "-* all" "-?* all" "all -r" "all -p" \
+		"all -H" "all -rp" "all -rH" "all -ph" "all -rpH" "all -r $TESTPOOL" \
+		"all -H $TESTPOOL" "all -p $TESTPOOL" "all -r -p -H $TESTPOOL" \
+		"all -rph $TESTPOOL" "all,available,reservation $TESTPOOL" \
+		"all $TESTPOOL?" "all $TESTPOOL*" "all nonexistpool"
+
+typeset -i i=0
+while (( i < ${#bad_combine[*]} ))
+do
+	log_mustnot eval "$ZFS get ${bad_combine[i]} >/dev/null"
+
+	(( i = i + 1 ))
+done
+
+log_pass "'zfs get all' fails with invalid combinations scenarios as expected."
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/usr/src/test/zfs-tests/tests/functional/cli_root/zfs_get/zfs_get_007_neg.ksh	Wed Dec 05 22:04:50 2012 -0500
@@ -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.
+#
+
+. $STF_SUITE/tests/functional/cli_root/zfs_get/zfs_get_common.kshlib
+
+#
+# DESCRIPTION:
+# 'zfs get -o' should fail with invalid column names
+#
+# STRATEGY:
+# 1. Run zfs get -o with invalid column name combinations
+# 2. Verify that zfs get returns error
+#
+
+verify_runnable "both"
+
+log_assert "'zfs get -o' fails with invalid options or column names"
+
+set -A  badargs "o name,property,value,resource" "o name" \
+	"-O name,property,value,source" "-oo name" "-o blah" \
+	"-o name,property,blah,source" "-o name,name,name,name,name" \
+	"-o name,property,value,," "-o *,*,*,*" "-o ?,?,?,?" \
+	"-o" "-o ,,,,," "-o -o -o -o" "-o NAME,PROPERTY,VALUE,SOURCE" \
+	"-o name,properTy,value,source" "-o name, property, value,source" \
+	"-o name:property:value:source" "-o name,property:value,source" \
+	"-o name;property;value;source"
+
+typeset -i i=0
+while (( i < ${#badargs[*]} ))
+do
+	log_mustnot eval "$ZFS get \"${badargs[i]}\" >/dev/null 2>&1"
+
+	(( i = i + 1 ))
+done
+
+log_pass "'zfs get -o' fails with invalid options or column name as expected."
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/usr/src/test/zfs-tests/tests/functional/cli_root/zfs_get/zfs_get_008_pos.ksh	Wed Dec 05 22:04:50 2012 -0500
@@ -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.
+#
+
+. $STF_SUITE/tests/functional/cli_root/zfs_get/zfs_get_common.kshlib
+. $STF_SUITE/tests/functional/cli_root/zfs_get/zfs_get_list_d.kshlib
+
+#
+# DESCRIPTION:
+# Verify "-d <n>" can work with other options
+#
+# STRATEGY:
+# 1. Create pool, filesystem, dataset, volume and snapshot.
+# 2. Getting an -d option, other options and properties random combination.
+# 3. Using the combination as the parameters of 'zfs get' to check the
+# command line return value.
+#
+
+verify_runnable "both"
+
+set -A options " " "-r" "-H" "-p" "-rHp" "-o name" \
+	"-s local,default,temporary,inherited,none" \
+	"-o name -s local,default,temporary,inherited,none" \
+	"-rHp -o name -s local,default,temporary,inherited,none"
+
+set -A props type used available creation volsize referenced compressratio \
+	mounted origin recordsize quota reservation mountpoint sharenfs \
+	checksum compression atime devices exec readonly setuid zoned snapdir \
+	aclmode aclinherit canmount primarycache secondarycache \
+	usedbychildren usedbydataset usedbyrefreservation usedbysnapshots \
+	userquota@root groupquota@root userused@root groupused@root
+
+$ZFS upgrade -v > /dev/null 2>&1
+if [[ $? -eq 0 ]]; then
+	set -A all_props ${all_props[*]} version
+fi
+
+set -A dataset $TESTPOOL/$TESTCTR $TESTPOOL/$TESTFS $TESTPOOL/$TESTVOL \
+	$TESTPOOL/$TESTFS@$TESTSNAP $TESTPOOL/$TESTVOL@$TESTSNAP
+
+log_assert "Verify '-d <n>' can work with other options"
+log_onexit cleanup
+
+# Create volume and filesystem's snapshot
+create_snapshot $TESTPOOL/$TESTFS $TESTSNAP
+create_snapshot $TESTPOOL/$TESTVOL $TESTSNAP
+
+typeset -i opt_numb=16
+typeset -i prop_numb=16
+typeset -i i=0
+typeset -i item=0
+typeset -i depth_item=0
+
+for dst in ${dataset[@]}; do
+	(( i=0 ))
+	while (( i < opt_numb )); do
+		(( item = $RANDOM % ${#options[@]} ))
+		(( depth_item = $RANDOM % ${#depth_options[@]} ))
+		for prop in $(gen_option_str "${props[*]}" "" "," $prop_numb)
+		do
+			log_must eval "$ZFS get -${depth_options[depth_item]} ${options[item]} $prop $dst > /dev/null 2>&1"
+		done
+		(( i += 1 ))
+	done
+done
+
+log_pass "Verify '-d <n>' can work with other options"
+
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/usr/src/test/zfs-tests/tests/functional/cli_root/zfs_get/zfs_get_009_pos.ksh	Wed Dec 05 22:04:50 2012 -0500
@@ -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 2009 Sun Microsystems, Inc.  All rights reserved.
+# Use is subject to license terms.
+#
+
+. $STF_SUITE/tests/functional/cli_root/zfs_get/zfs_get_common.kshlib
+. $STF_SUITE/tests/functional/cli_root/zfs_get/zfs_get_list_d.kshlib
+
+#
+# DESCRIPTION:
+#	'zfs get -d <n>' should get expected output.
+#
+# STRATEGY:
+#	1. Create a multiple depth filesystem.
+#	2. 'zfs get -d <n>' to get the output.
+#	3. 'zfs get -r|egrep' to get the expected output.
+#	4. Compare the two outputs, they shoud be same.
+#
+
+verify_runnable "both"
+
+log_assert "'zfs get -d <n>' should get expected output."
+log_onexit depth_fs_cleanup
+
+set -A all_props type used available creation volsize referenced \
+	compressratio mounted origin recordsize quota reservation mountpoint \
+	sharenfs checksum compression atime devices exec readonly setuid \
+	zoned snapdir aclmode aclinherit canmount primarycache secondarycache \
+	usedbychildren usedbydataset usedbyrefreservation usedbysnapshots \
+	userquota@root groupquota@root userused@root groupused@root
+
+$ZFS upgrade -v > /dev/null 2>&1
+if [[ $? -eq 0 ]]; then
+	set -A all_props ${all_props[*]} version
+fi
+
+depth_fs_setup
+
+mntpnt=$(get_prop mountpoint $DEPTH_FS)
+DEPTH_OUTPUT="$mntpnt/depth_output"
+EXPECT_OUTPUT="$mntpnt/expect_output"
+typeset -i prop_numb=16
+typeset -i old_val=0
+typeset -i j=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
+	for prop in $(gen_option_str "${all_props[*]}" "" "," $prop_numb); do
+		log_must eval "$ZFS get -H -d $dp -o name $prop $DEPTH_FS > $DEPTH_OUTPUT"
+		log_must eval "$ZFS get -rH -o name $prop $DEPTH_FS | $EGREP -e '$eg_opt' > $EXPECT_OUTPUT"
+		log_must $DIFF $DEPTH_OUTPUT $EXPECT_OUTPUT
+	done
+	(( old_val=dp ))
+done
+
+log_pass "'zfs get -d <n>' should get expected output."
+
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/usr/src/test/zfs-tests/tests/functional/cli_root/zfs_get/zfs_get_010_neg.ksh	Wed Dec 05 22:04:50 2012 -0500
@@ -0,0 +1,55 @@
+#!/bin/ksh -p
+#
+# CDDL HEADER START
+#
+# The contents of this file are subject to the terms of the
+# Common Development and Distribution License (the "License").
+# You may not use this file except in compliance with the License.
+#
+# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
+# or http://www.opensolaris.org/os/licensing.
+# See the License for the specific language governing permissions
+# and limitations under the License.
+#
+# When distributing Covered Code, include this CDDL HEADER in each
+# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
+# If applicable, add the following below this CDDL 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.
+#
+
+. $STF_SUITE/tests/functional/cli_root/zfs_get/zfs_get_common.kshlib
+. $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 get -d <n>'
+#
+# STRATEGY:
+# 1. Run zfs get -d with negative depth or non numeric depth
+# 2. Verify that zfs get returns error
+#
+
+verify_runnable "both"
+
+log_assert "A negative depth or a non numeric depth should fail in 'zfs get -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 get -d ${badargs[i]} $TESTPOOL/$TESTFS >/dev/null 2>&1"
+	(( i = i + 1 ))
+done
+
+log_pass "A negative depth or a non numeric depth should fail in 'zfs get -d <n>'"
+
+
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/usr/src/test/zfs-tests/tests/functional/cli_root/zfs_get/zfs_get_common.kshlib	Wed Dec 05 22:04:50 2012 -0500
@@ -0,0 +1,97 @@
+#
+# CDDL HEADER START
+#
+# The contents of this file are subject to the terms of the
+# Common Development and Distribution License (the "License").
+# You may not use this file except in compliance with the License.
+#
+# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
+# or http://www.opensolaris.org/os/licensing.
+# See the License for the specific language governing permissions
+# and limitations under the License.
+#
+# When distributing Covered Code, include this CDDL HEADER in each
+# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
+# If applicable, add the following below this CDDL HEADER, with the
+# fields enclosed by brackets "[]" replaced with your own identifying
+# information: Portions Copyright [yyyy] [name of copyright owner]
+#
+# CDDL HEADER END
+#
+
+#
+# Copyright 2007 Sun Microsystems, Inc.  All rights reserved.
+# Use is subject to license terms.
+#
+
+. $STF_SUITE/include/libtest.shlib
+
+#
+# According to $elements, $prefix and $separator, the function random produce
+# the number of $counter combination.
+#
+# $1 elements which is used to get the combination.
+# $2 prefix is appended to the combination
+# $3 separator between the combination, such as ' ' or ','
+# $4 counter is the number of combination which you want to get.
+#
+function gen_option_str # $elements $prefix $separator $counter
+{
+	typeset elements=""
+	typeset prefix=${2}
+	typeset separator=${3}
+	typeset -i counter=${4:-0}
+	typeset -i i=0
+	typeset comb_str=""
+
+	for e in $1; do
+		elements[i]="$e"
+		(( i += 1 ))
+	done
+	(( ${#elements[@]} == 0 )) && log_fail "The elements can't be empty."
+
+	typeset -i item=0
+	typeset -i j=0
+	typeset -i numb_item=0
+
+	# Loop and get the specified number combination strings.
+	i=0
+	while (( i < counter )); do
+		j=0
+		numb_item=0
+		comb_str=""
+
+		# Get random number items for each combinations.
+		(( numb_item = ($RANDOM % ${#elements[@]}) + 1 ))
+
+		while (( j < numb_item )); do
+			# Random select elements from the array
+			(( item = $RANDOM % ${#elements[@]} ))
+
+			if (( ${#comb_str} == 0 )); then
+				comb_str=${elements[item]}
+			else
+				comb_str=$comb_str$separator${elements[item]}
+			fi
+			(( j += 1 ))
+		done
+
+		echo "$prefix$comb_str"
+
+		(( i += 1 ))
+	done
+}
+
+#
+# Cleanup the volume snapshot and filesystem snapshot were created for
+# this test case.
+#
+function cleanup
+{
+	datasetexists $TESTPOOL/$TESTVOL@$TESTSNAP && \
+		destroy_snapshot $TESTPOOL/$TESTVOL@$TESTSNAP
+	datasetexists $TESTPOOL/$TESTFS@$TESTSNAP && \
+		destroy_snapshot $TESTPOOL/$TESTFS@$TESTSNAP
+
+	[[ -e $TESTFILE0 ]] && log_must $RM $TESTFILE0
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/usr/src/test/zfs-tests/tests/functional/cli_root/zfs_get/zfs_get_list_d.kshlib	Wed Dec 05 22:04:50 2012 -0500
@@ -0,0 +1,79 @@
+#
+# CDDL HEADER START
+#
+# The contents of this file are subject to the terms of the
+# Common Development and Distribution License (the "License").
+# You may not use this file except in compliance with the License.
+#
+# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
+# or http://www.opensolaris.org/os/licensing.
+# See the License for the specific language governing permissions
+# and limitations under the License.
+#
+# When distributing Covered Code, include this CDDL HEADER in each
+# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
+# If applicable, add the following below this CDDL 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.
+#
+
+. $STF_SUITE/include/libtest.shlib
+
+DEPTH_FS=$TESTPOOL/depth_fs
+MAX_DEPTH=3
+DS_COUNT=3
+set -A depth_options  "d 0" "d 1" "d 2" "d 4" "d 32"
+set -A depth_array  0 1 2 4 32
+
+#
+# Setup multiple depths datasets, including fs, volume and snapshot.
+#
+function depth_fs_setup
+{
+	typeset -i i j k
+	typeset fslist
+
+	log_must $ZFS create $DEPTH_FS
+
+	(( i=1 ))
+	while (( i<=MAX_DEPTH )); do
+		if (( i==1 )); then
+			fslist=$DEPTH_FS
+		else
+			(( k=i-1 ))
+			fslist=$($ZFS list -rH -t filesystem -o name $DEPTH_FS|$GREP depth"$k"$)
+			if (( $? != 0 )); then
+				log_fail "No depth$k filesystem"
+			fi
+		fi
+		for fs in $fslist; do
+			(( j=1 ))
+			while (( j<=DS_COUNT )); do
+				log_must $ZFS create $fs/fs_"$j"_depth"$i"
+				if is_global_zone ; then
+					log_must $ZFS create -V 8M $fs/vol_"$j"_depth"$i"
+				fi
+				log_must $ZFS snapshot $fs@snap_"$j"_depth"$i"
+				(( j=j+1 ))
+			done
+		done
+		(( i=i+1 ))
+	done
+}
+
+#
+# Cleanup multiple depths filesystem.
+#
+function depth_fs_cleanup
+{
+	log_must $ZFS destroy -rR $DEPTH_FS
+}
+
+
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/usr/src/test/zfs-tests/tests/functional/cli_root/zfs_inherit/Makefile	Wed Dec 05 22:04:50 2012 -0500
@@ -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) 2012 by Delphix. All rights reserved.
+#
+
+include $(SRC)/Makefile.master
+
+ROOTOPTPKG = $(ROOT)/opt/zfs-tests
+TESTDIR = $(ROOTOPTPKG)/tests/functional/cli_root/zfs_inherit
+
+PROGS = cleanup \
+	setup \
+	zfs_inherit_001_neg \
+	zfs_inherit_002_neg \
+	zfs_inherit_003_pos
+
+CMDS = $(PROGS:%=$(TESTDIR)/%)
+$(CMDS) := FILEMODE = 0555
+
+all lint clean clobber:
+
+install: $(CMDS)
+
+$(CMDS): $(TESTDIR)
+
+$(TESTDIR):
+	$(INS.dir)
+
+$(TESTDIR)/%: %.ksh
+	$(INS.rename)
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/usr/src/test/zfs-tests/tests/functional/cli_root/zfs_inherit/cleanup.ksh	Wed Dec 05 22:04:50 2012 -0500
@@ -0,0 +1,30 @@
+#!/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.
+#
+
+. $STF_SUITE/include/libtest.shlib
+
+default_cleanup
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/usr/src/test/zfs-tests/tests/functional/cli_root/zfs_inherit/setup.ksh	Wed Dec 05 22:04:50 2012 -0500
@@ -0,0 +1,32 @@
+#!/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.
+#
+
+. $STF_SUITE/include/libtest.shlib
+
+DISK=${DISKS%% *}
+
+default_container_volume_setup $DISK
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/usr/src/test/zfs-tests/tests/functional/cli_root/zfs_inherit/zfs_inherit_001_neg.ksh	Wed Dec 05 22:04:50 2012 -0500
@@ -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 2008 Sun Microsystems, Inc.  All rights reserved.
+# Use is subject to license terms.
+#
+
+. $STF_SUITE/include/libtest.shlib
+
+#
+# DESCRIPTION:
+# 'zfs inherit' should return an error when attempting to inherit
+# properties which are not inheritable.
+#
+# STRATEGY:
+# 1. Create an array of properties which cannot be inherited
+# 2. For each property in the array, execute 'zfs inherit'
+# 3. Verify an error is returned.
+#
+
+verify_runnable "both"
+
+# Define uninherited properties and their short name.
+typeset props_str="type used available avail creation referenced refer \
+		compressratio ratio mounted origin quota reservation \
+		reserv volsize volblocksize volblock"
+
+$ZFS upgrade -v > /dev/null 2>&1
+if [[ $? -eq 0 ]]; then
+	props_str="$props_str version"
+fi
+
+set -A prop $props_str canmount
+
+
+log_assert "'zfs inherit' should return an error when attempting to inherit" \
+	" un-inheritable properties."
+
+typeset -i i=0
+for obj in $TESTPOOL/$TESTFS $TESTPOOL/$TESTVOL; do
+	i=0
+	while [[ $i -lt ${#prop[*]} ]]; do
+		orig_val=$(get_prop ${prop[i]} $obj)
+
+		log_mustnot $ZFS inherit ${prop[i]} $obj
+
+		new_val=$(get_prop ${prop[i]} $obj)
+
+		if [[ $new_val != $orig_val ]]; then
+			log_fail "${prop[i]} property changed from $orig_val "
+				" to $new_val"
+		fi
+		((i = i + 1))
+	done
+done
+
+log_pass "'zfs inherit' failed as expected when attempting to inherit" \
+	" un-inheritable properties."
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/usr/src/test/zfs-tests/tests/functional/cli_root/zfs_inherit/zfs_inherit_002_neg.ksh	Wed Dec 05 22:04:50 2012 -0500
@@ -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) 2011 by Delphix. All rights reserved.
+#
+
+. $STF_SUITE/include/libtest.shlib
+
+#
+# DESCRIPTION:
+# 'zfs inherit' should return an error with bad parameters in one command.
+#
+# STRATEGY:
+# 1. Set an array of bad options and invlid properties to 'zfs inherit'
+# 2. Execute 'zfs inherit' with bad options and passing invlid properties
+# 3. Verify an error is returned.
+#
+
+verify_runnable "both"
+
+function cleanup
+{
+	if snapexists $TESTPOOL/$TESTFS@$TESTSNAP; then
+		log_must $ZFS destroy $TESTPOOL/$TESTFS@$TESTSNAP
+	fi
+}
+
+log_assert "'zfs inherit' should return an error with bad parameters in \
+one command."
+log_onexit cleanup
+
+set -A badopts "r" "R" "-R" "-rR" "-a" "-" "-?" "-1" "-2" "-v" "-n"
+set -A props "recordsize" "mountpoint" "sharenfs" "checksum" "compression" \
+    "atime" "devices" "exec" "setuid" "readonly" "zoned" "snapdir" "aclmode" \
+    "aclinherit" "xattr" "copies"
+set -A illprops "shareiscsi" "recordsiz" "mountpont" "sharen" "compres" \
+    "atme" "???" "***" "blah"
+
+log_must $ZFS snapshot $TESTPOOL/$TESTFS@$TESTSNAP
+
+typeset -i i=0
+for ds in $TESTPOOL $TESTPOOL/$TESTFS $TESTPOOL/$TESTVOL \
+	$TESTPOOL/$TESTFS@$TESTSNAP; do
+
+	# zfs inherit should fail with bad options
+	for opt in ${badopts[@]}; do
+		for prop in ${props[@]}; do
+			log_mustnot eval "$ZFS inherit $opt $prop $ds \
+			    >/dev/null 2>&1"
+		done
+	done
+
+	# zfs inherit should fail with invalid properties
+	for prop in "${illprops[@]}"; do
+		log_mustnot eval "$ZFS inherit $prop $ds >/dev/null 2>&1"
+		log_mustnot eval "$ZFS inherit -r $prop $ds >/dev/null 2>&1"
+	done
+
+	# zfs inherit should fail with too many arguments
+	(( i = 0 ))
+	while (( i < ${#props[*]} -1 )); do
+		log_mustnot eval "$ZFS inherit ${props[(( i ))]} \
+				${props[(( i + 1 ))]} $ds >/dev/null 2>&1"
+		log_mustnot eval "$ZFS inherit -r ${props[(( i ))]} \
+				${props[(( i + 1 ))]} $ds >/dev/null 2>&1"
+
+		(( i = i + 2 ))
+	done
+
+done
+
+# zfs inherit should fail with missing datasets
+for prop in ${props[@]}; do
+	log_mustnot eval "$ZFS inherit $prop >/dev/null 2>&1"
+	log_mustnot eval "$ZFS inherit -r $prop >/dev/null 2>&1"
+done
+
+log_pass "'zfs inherit' failed as expected when passing illegal arguments."
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/usr/src/test/zfs-tests/tests/functional/cli_root/zfs_inherit/zfs_inherit_003_pos.ksh	Wed Dec 05 22:04:50 2012 -0500
@@ -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.
+#
+
+. $STF_SUITE/include/libtest.shlib
+. $STF_SUITE/tests/functional/cli_root/zfs_set/zfs_set_common.kshlib
+
+#
+# DESCRIPTION:
+# 'zfs inherit' should return an error with bad parameters in one command.
+#
+# STRATEGY:
+# 1. Set an array of bad options and invlid properties to 'zfs inherit'
+# 2. Execute 'zfs inherit' with bad options and passing invlid properties
+# 3. Verify an error is returned.
+#
+
+verify_runnable "both"
+
+function cleanup
+{
+	for ds in $TESTPOOL $TESTPOOL/$TESTFS $TESTPOOL/$TESTVOL ; do
+		if snapexists $ds@$TESTSNAP; then
+			log_must $ZFS destroy $ds@$TESTSNAP
+		fi
+	done
+	cleanup_user_prop $TESTPOOL
+}
+
+log_assert "'zfs inherit' should inherit user property."
+log_onexit cleanup
+
+for ds in $TESTPOOL $TESTPOOL/$TESTFS $TESTPOOL/$TESTVOL ; do
+        typeset prop_name=$(valid_user_property 10)
+        typeset value=$(user_property_value 16)
+
+	log_must eval "$ZFS set $prop_name='$value' $ds"
+
+	log_must $ZFS snapshot $ds@$TESTSNAP
+
+	typeset snapvalue=$(get_prop $prop_name $ds@$TESTSNAP)
+
+	if [[ "$snapvalue" != "$value" ]] ; then
+		log_fail "The '$ds@$TESTSNAP '$prop_name' value '$snapvalue' " \
+			"not equal to the expected value '$value'."
+	fi
+
+	snapvalue=$(user_property_value 16)
+	log_must eval "$ZFS set $prop_name='$snapvalue' $ds@$TESTSNAP"
+
+	log_must $ZFS inherit $prop_name $ds@$TESTSNAP
+
+	snapvalue=$(get_prop $prop_name $ds@$TESTSNAP)
+
+	if [[ "$snapvalue" != "$value" ]] ; then
+		log_fail "The '$ds@$TESTSNAP '$prop_name' value '$snapvalue' " \
+			"not equal to the expected value '$value'."
+	fi
+
+
+done
+
+log_pass "'zfs inherit' inherit user property."
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/usr/src/test/zfs-tests/tests/functional/cli_root/zfs_mount/Makefile	Wed Dec 05 22:04:50 2012 -0500
@@ -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) 2012 by Delphix. All rights reserved.
+#
+
+include $(SRC)/Makefile.master
+
+ROOTOPTPKG = $(ROOT)/opt/zfs-tests
+TESTDIR = $(ROOTOPTPKG)/tests/functional/cli_root/zfs_mount
+
+PROGS = cleanup \
+	setup \
+	zfs_mount_001_pos \
+	zfs_mount_002_pos \
+	zfs_mount_003_pos \
+	zfs_mount_004_pos  \
+	zfs_mount_005_pos \
+	zfs_mount_006_pos \
+	zfs_mount_007_pos \
+	zfs_mount_008_pos \
+	zfs_mount_009_neg \
+	zfs_mount_010_neg \
+	zfs_mount_011_neg \
+	zfs_mount_all_001_pos
+
+FILES = zfs_mount.cfg \
+	zfs_mount.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	Thu Jan 01 00:00:00 1970 +0000
+++ b/usr/src/test/zfs-tests/tests/functional/cli_root/zfs_mount/cleanup.ksh	Wed Dec 05 22:04:50 2012 -0500
@@ -0,0 +1,30 @@
+#!/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.
+#
+
+. $STF_SUITE/include/libtest.shlib
+
+default_cleanup
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/usr/src/test/zfs-tests/tests/functional/cli_root/zfs_mount/setup.ksh	Wed Dec 05 22:04:50 2012 -0500
@@ -0,0 +1,32 @@
+#!/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.
+#
+
+. $STF_SUITE/include/libtest.shlib
+
+DISK=${DISKS%% *}
+
+default_setup $DISK
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/usr/src/test/zfs-tests/tests/functional/cli_root/zfs_mount/zfs_mount.cfg	Wed Dec 05 22:04:50 2012 -0500
@@ -0,0 +1,39 @@
+#
+# CDDL HEADER START
+#
+# The contents of this file are subject to the terms of the
+# Common Development and Distribution License (the "License").
+# You may not use this file except in compliance with the License.
+#
+# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
+# or http://www.opensolaris.org/os/licensing.
+# See the License for the specific language governing permissions
+# and limitations under the License.
+#
+# When distributing Covered Code, include this CDDL HEADER in each
+# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
+# If applicable, add the following below this CDDL HEADER, with the
+# fields enclosed by brackets "[]" replaced with your own identifying
+# information: Portions Copyright [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.
+#
+
+export mountcmd=mount
+export mountforce="$mountcmd -f"
+export mountall="$mountcmd -a"
+
+export unmountcmd=unmount
+export unmountforce="$unmountcmd -f"
+export unmountall="$unmountcmd -a"
+
+export NONEXISTFSNAME="nonexistfs50charslong_0123456789012345678901234567"
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/usr/src/test/zfs-tests/tests/functional/cli_root/zfs_mount/zfs_mount.kshlib	Wed Dec 05 22:04:50 2012 -0500
@@ -0,0 +1,131 @@
+#
+# CDDL HEADER START
+#
+# The contents of this file are subject to the terms of the
+# Common Development and Distribution License (the "License").
+# You may not use this file except in compliance with the License.
+#
+# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
+# or http://www.opensolaris.org/os/licensing.
+# See the License for the specific language governing permissions
+# and limitations under the License.
+#
+# When distributing Covered Code, include this CDDL HEADER in each
+# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
+# If applicable, add the following below this CDDL 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.
+#
+
+. $STF_SUITE/include/libtest.shlib
+. $STF_SUITE/tests/functional/cli_root/zfs_mount/zfs_mount.cfg
+
+function force_unmount #dev
+{
+	typeset dev=$1
+
+	ismounted $dev
+	if (( $? == 0 )); then
+		log_must $ZFS $unmountforce $dev
+	fi
+	return 0
+}
+
+# Create pool and  ( fs | container | vol ) with the given parameters,
+# it'll destroy prior exist one that has the same name.
+
+function setup_filesystem #disklist #pool #fs #mntpoint #type #vdev
+{
+	typeset disklist=$1
+	typeset pool=$2
+	typeset fs=${3##/}
+	typeset mntpoint=$4
+	typeset type=$5
+	typeset vdev=$6
+
+	if [[ -z $pool || -z $fs || -z $mntpoint ]]; then
+		log_note "Missing parameter: (\"$pool\", \"$fs\", \"$mntpoint\")"
+		return 1
+	fi
+
+	if is_global_zone && [[ -z $disklist ]] ; then
+		log_note "Missing disklist."
+		return 1
+	fi
+
+	if [[ $vdev != "" && \
+		$vdev != "mirror" && \
+		$vdev != "raidz" ]] ; then
+
+		log_note "Wrong vdev: (\"$vdev\")"
+		return 1
+	fi
+
+	poolexists $pool || \
+		create_pool $pool $vdev $disklist
+
+	datasetexists $pool/$fs && \
+		log_must cleanup_filesystem $pool $fs
+
+	$RMDIR $mntpoint > /dev/null 2>&1
+	if [[ ! -d $mntpoint ]]; then
+		log_must $MKDIR -p $mntpoint
+	fi
+
+	case "$type" in
+		'ctr')	log_must $ZFS create $pool/$fs
+			log_must $ZFS set mountpoint=$mntpoint $pool/$fs
+			;;
+		'vol')	log_must $ZFS create -V $VOLSIZE $pool/$fs
+			;;
+		*)	log_must $ZFS create $pool/$fs
+			log_must $ZFS set mountpoint=$mntpoint $pool/$fs
+			;;
+	esac
+
+	return 0
+}
+
+# Destroy ( fs | container | vol ) with the given parameters.
+function cleanup_filesystem #pool #fs
+{
+	typeset pool=$1
+	typeset fs=${2##/}
+	typeset mtpt=""
+
+	if [[ -z $pool || -z $fs ]]; then
+		log_note "Missing parameter: (\"$pool\", \"$fs\")"
+		return 1
+	fi
+
+	if datasetexists "$pool/$fs" ; then
+		mtpt=$(get_prop mountpoint "$pool/$fs")
+		log_must $ZFS destroy -r $pool/$fs
+
+		[[ -d $mtpt ]] && \
+			log_must $RM -rf $mtpt
+	else
+		return 1
+	fi
+
+	return 0
+}
+
+# Make sure 'zfs mount' should display all ZFS filesystems currently mounted.
+# The results of 'zfs mount' and 'df -F zfs' should be identical.
+function verify_mount_display
+{
+	typeset fs
+
+	for fs in $($ZFS $mountcmd | $AWK '{print $1}') ; do
+		log_must mounted $fs
+	done
+	return 0
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/usr/src/test/zfs-tests/tests/functional/cli_root/zfs_mount/zfs_mount_001_pos.ksh	Wed Dec 05 22:04:50 2012 -0500
@@ -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.
+#
+
+. $STF_SUITE/include/libtest.shlib
+. $STF_SUITE/tests/functional/cli_root/zfs_mount/zfs_mount.kshlib
+
+#
+# DESCRIPTION:
+# Invoke "zfs mount <filesystem>" with a regular name of filesystem,
+# will mount that filesystem successfully.
+#
+# STRATEGY:
+# 1. Make sure that the ZFS filesystem is unmounted.
+# 2. Invoke 'zfs mount <filesystem>'.
+# 3. Verify that the filesystem is mounted.
+#
+
+verify_runnable "both"
+
+function cleanup
+{
+	log_must force_unmount $TESTPOOL/$TESTFS
+	return 0
+}
+
+log_assert "Verify that '$ZFS $mountcmd <filesystem>' succeeds as root."
+
+log_onexit cleanup
+
+unmounted $TESTPOOL/$TESTFS || \
+	log_must cleanup
+
+log_must $ZFS $mountcmd $TESTPOOL/$TESTFS
+
+log_note "Make sure the filesystem $TESTPOOL/$TESTFS is mounted"
+mounted $TESTPOOL/$TESTFS || \
+	log_fail Filesystem $TESTPOOL/$TESTFS is unmounted
+
+log_pass "'$ZFS $mountcmd <filesystem>' succeeds as root."
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/usr/src/test/zfs-tests/tests/functional/cli_root/zfs_mount/zfs_mount_002_pos.ksh	Wed Dec 05 22:04:50 2012 -0500
@@ -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.
+#
+
+. $STF_SUITE/include/libtest.shlib
+. $STF_SUITE/tests/functional/cli_root/zfs_mount/zfs_mount.kshlib
+
+#
+# DESCRIPTION:
+# Invoking "zfs mount <filesystem>" with a filesystem whose name is not in
+# "zfs list", will fail with a return code of 1.
+#
+# STRATEGY:
+# 1. Make sure the NONEXISTFSNAME ZFS filesystem is not in 'zfs list'.
+# 2. Invoke 'zfs mount <filesystem>'.
+# 3. Verify that mount failed with return code of 1.
+#
+
+verify_runnable "both"
+
+function cleanup
+{
+	typeset fs
+	for fs in $NONEXISTFSNAME $TESTFS ; do
+		log_must force_unmount $TESTPOOL/$fs
+	done
+}
+
+
+log_assert "Verify that '$ZFS $mountcmd' with a filesystem " \
+	"whose name is not in 'zfs list' will fail with return code 1."
+
+log_onexit cleanup
+
+log_note "Make sure the filesystem $TESTPOOL/$NONEXISTFSNAME " \
+	"is not in 'zfs list'"
+log_mustnot $ZFS list $TESTPOOL/$NONEXISTFSNAME
+
+typeset -i ret=0
+$ZFS $mountcmd $TESTPOOL/$NONEXISTFSNAME
+ret=$?
+(( ret == 1 )) || \
+	log_fail "'$ZFS $mountcmd $TESTPOOL/$NONEXISTFSNAME' " \
+		"unexpected return code of $ret."
+
+log_note "Make sure the filesystem $TESTPOOL/$NONEXISTFSNAME is unmounted"
+unmounted $TESTPOOL/$NONEXISTFSNAME || \
+	log_fail Filesystem $TESTPOOL/$NONEXISTFSNAME is mounted
+
+log_pass "'$ZFS $mountcmd' with a filesystem " \
+	"whose name is not in 'zfs list' failed with return code 1."
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/usr/src/test/zfs-tests/tests/functional/cli_root/zfs_mount/zfs_mount_003_pos.ksh	Wed Dec 05 22:04:50 2012 -0500
@@ -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.
+#
+
+. $STF_SUITE/include/libtest.shlib
+. $STF_SUITE/tests/functional/cli_root/zfs_mount/zfs_mount.kshlib
+
+#
+# DESCRIPTION:
+# Invoke "zfs mount <filesystem>" with a filesystem whose mountpoint property
+# is 'legacy' or 'none',
+# it will fail with a return code of 1 and issue an error message.
+#
+# STRATEGY:
+# 1. Make sure that the ZFS filesystem is unmounted.
+# 2. Mount the filesystem using the various combinations
+#	- zfs set mountpoint=legacy <filesystem>
+#	- zfs set mountpoint=none <filesystem>
+# 3. Verify that mount failed with return code of 1.
+#
+
+verify_runnable "both"
+
+function cleanup
+{
+	log_must $ZFS set mountpoint=$TESTDIR $TESTPOOL/$TESTFS
+	log_must force_unmount $TESTPOOL/$TESTFS
+	return 0
+}
+
+log_assert "Verify that '$ZFS $mountcmd' with a filesystem " \
+	"whose mountpoint property is 'legacy' or 'none' " \
+	"will fail with return code 1."
+
+log_onexit cleanup
+
+set -A mopt "legacy" "none"
+
+typeset -i ret=0
+typeset -i i=0
+
+while (( i < ${#mopt[*]} )); do
+	unmounted $TESTPOOL/$TESTFS || \
+		log_must cleanup
+
+	log_must $ZFS set mountpoint=${mopt[i]} $TESTPOOL/$TESTFS
+
+	$ZFS $mountcmd $TESTPOOL/$TESTFS
+	ret=$?
+	(( ret == 1)) || \
+		log_fail "'$ZFS $mountcmd $TESTPOOL/$TESTFS' " \
+			"unexpected return code of $ret."
+
+	log_note "Make sure the filesystem $TESTPOOL/$TESTFS is unmounted"
+	unmounted $TESTPOOL/$TESTFS || \
+		log_fail Filesystem $TESTPOOL/$TESTFS is mounted
+
+	((i = i + 1))
+done
+
+log_pass "Verify that '$ZFS $mountcmd' with a filesystem " \
+	"whose mountpoint property is 'legacy' or 'none' " \
+	"will fail with return code 1."
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/usr/src/test/zfs-tests/tests/functional/cli_root/zfs_mount/zfs_mount_004_pos.ksh	Wed Dec 05 22:04:50 2012 -0500
@@ -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.
+#
+
+. $STF_SUITE/include/libtest.shlib
+. $STF_SUITE/tests/functional/cli_root/zfs_mount/zfs_mount.kshlib
+
+#
+# DESCRIPTION:
+# Invoke "zfs mount <filesystem>" with a filesystem
+# which has been already mounted,
+# it will fail with a return code of 1
+#
+# STRATEGY:
+# 1. Make sure that the ZFS filesystem is unmounted.
+# 2. Invoke 'zfs mount <filesystem>'.
+# 3. Verify that the filesystem is mounted.
+# 4. Invoke 'zfs mount <filesystem>' the second times.
+# 5. Verify the last mount operation failed with return code of 1.
+#
+
+verify_runnable "both"
+
+function cleanup
+{
+	log_must force_unmount $TESTPOOL/$TESTFS
+	return 0
+}
+
+typeset -i ret=0
+
+log_assert "Verify that '$ZFS $mountcmd <filesystem>' " \
+	"with a mounted filesystem will fail with return code 1."
+
+log_onexit cleanup
+
+unmounted $TESTPOOL/$TESTFS || \
+	log_must cleanup
+
+log_must $ZFS $mountcmd $TESTPOOL/$TESTFS
+
+mounted $TESTPOOL/$TESTFS || \
+	log_unresolved "Filesystem $TESTPOOL/$TESTFS is unmounted"
+
+$ZFS $mountcmd $TESTPOOL/$TESTFS
+ret=$?
+(( ret == 1 )) || \
+	log_fail "'$ZFS $mountcmd $TESTPOOL/$TESTFS' " \
+		"unexpected return code of $ret."
+
+log_note "Make sure the filesystem $TESTPOOL/$TESTFS is mounted"
+mounted $TESTPOOL/$TESTFS || \
+	log_fail Filesystem $TESTPOOL/$TESTFS is unmounted
+
+log_pass "'$ZFS $mountcmd <filesystem>' with a mounted filesystem " \
+	"will fail with return code 1."
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/usr/src/test/zfs-tests/tests/functional/cli_root/zfs_mount/zfs_mount_005_pos.ksh	Wed Dec 05 22:04:50 2012 -0500
@@ -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.
+#
+
+. $STF_SUITE/include/libtest.shlib
+. $STF_SUITE/tests/functional/cli_root/zfs_mount/zfs_mount.kshlib
+
+#
+# DESCRIPTION:
+# Invoke "zfs mount <filesystem>" with a filesystem
+# but its mountpoint is currently in use,
+# it will fail with a return code of 1
+# and issue an error message.
+#
+# STRATEGY:
+# 1. Make sure that the ZFS filesystem is unmounted.
+# 2. Apply 'zfs set mountpoint=path <filesystem>'.
+# 3. Change directory to that given mountpoint.
+# 3. Invoke 'zfs mount <filesystem>'.
+# 4. Verify that mount failed with return code of 1.
+#
+
+verify_runnable "both"
+
+function cleanup
+{
+	log_must $ZFS set mountpoint=$TESTDIR $TESTPOOL/$TESTFS
+	log_must force_unmount $TESTPOOL/$TESTFS
+	return 0
+}
+
+typeset -i ret=0
+
+log_assert "Verify that '$ZFS $mountcmd' with a filesystem " \
+	"whose mountpoint is currently in use will fail with return code 1."
+
+log_onexit cleanup
+
+unmounted $TESTPOOL/$TESTFS || \
+	log_must cleanup
+
+[[ -d $TESTDIR ]] || \
+	log_must $MKDIR -p $TESTDIR
+
+cd $TESTDIR || \
+	log_unresolved "Unable change directory to $TESTDIR"
+
+$ZFS $mountcmd $TESTPOOL/$TESTFS
+ret=$?
+(( ret == 1 )) || \
+	log_fail "'$ZFS $mountcmd $TESTPOOL/$TESTFS' " \
+		"unexpected return code of $ret."
+
+log_note "Make sure the filesystem $TESTPOOL/$TESTFS is unmounted"
+unmounted $TESTPOOL/$TESTFS || \
+	log_fail Filesystem $TESTPOOL/$TESTFS is mounted
+
+log_pass "'$ZFS $mountcmd' with a filesystem " \
+	"whose mountpoint is currently in use failed with return code 1."
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/usr/src/test/zfs-tests/tests/functional/cli_root/zfs_mount/zfs_mount_006_pos.ksh	Wed Dec 05 22:04:50 2012 -0500
@@ -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 2007 Sun Microsystems, Inc.  All rights reserved.
+# Use is subject to license terms.
+#
+
+. $STF_SUITE/include/libtest.shlib
+. $STF_SUITE/tests/functional/cli_root/zfs_mount/zfs_mount.kshlib
+
+#
+# DESCRIPTION:
+#	Invoke "zfs mount <filesystem>" with a filesystem
+#	which mountpoint be the identical or the top of an existing one,
+#	it will fail with a return code of 1
+#
+# STRATEGY:
+#	1. Prepare an existing mounted filesystem.
+#	2. Setup a new filesystem and make sure that it is unmounted.
+#       3. Mount the new filesystem using the various combinations
+#		- zfs set mountpoint=<identical path> <filesystem>
+#		- zfs set mountpoint=<top path> <filesystem>
+#       4. Verify that mount failed with return code of 1.
+#
+
+verify_runnable "both"
+
+function cleanup
+{
+	log_must force_unmount $TESTPOOL/$TESTFS
+
+	datasetexists $TESTPOOL/$TESTFS1 && \
+		cleanup_filesystem $TESTPOOL $TESTFS1
+
+	[[ -d $TESTDIR ]] && \
+		log_must $RM -rf $TESTDIR
+	log_must $ZFS set mountpoint=$TESTDIR $TESTPOOL/$TESTFS
+	log_must force_unmount $TESTPOOL/$TESTFS
+
+	return 0
+}
+
+typeset -i ret=0
+
+log_assert "Verify that '$ZFS $mountcmd <filesystem>' " \
+	"which mountpoint be the identical or the top of an existing one " \
+	"will fail with return code 1."
+
+log_onexit cleanup
+
+unmounted $TESTPOOL/$TESTFS || \
+	log_must force_unmount $TESTPOOL/$TESTFS
+
+[[ -d $TESTDIR ]] && \
+	log_must $RM -rf $TESTDIR
+
+typeset -i MAXDEPTH=3
+typeset -i depth=0
+typeset mtpt=$TESTDIR
+
+while (( depth < MAXDEPTH )); do
+	mtpt=$mtpt/$depth
+	(( depth = depth + 1))
+done
+
+log_must $ZFS set mountpoint=$mtpt $TESTPOOL/$TESTFS
+log_must $ZFS $mountcmd $TESTPOOL/$TESTFS
+
+mounted $TESTPOOL/$TESTFS || \
+	log_unresolved "Filesystem $TESTPOOL/$TESTFS is unmounted"
+
+log_must $ZFS create $TESTPOOL/$TESTFS1
+
+unmounted $TESTPOOL/$TESTFS1 || \
+	log_must force_unmount $TESTPOOL/$TESTFS1
+
+while [[ -n $mtpt ]] ; do
+	(( depth == MAXDEPTH )) && \
+		log_note "Verify that '$ZFS $mountcmd <filesystem>' " \
+		"which mountpoint be the identical of an existing one " \
+		"will fail with return code 1."
+
+	log_must $ZFS set mountpoint=$mtpt $TESTPOOL/$TESTFS1
+	log_mustnot $ZFS $mountcmd $TESTPOOL/$TESTFS1
+
+	unmounted $TESTPOOL/$TESTFS1 || \
+		log_fail "Filesystem $TESTPOOL/$TESTFS1 is mounted."
+
+	mtpt=${mtpt%/*}
+
+	(( depth == MAXDEPTH )) && \
+		log_note "Verify that '$ZFS $mountcmd <filesystem>' " \
+		"which mountpoint be the top of an existing one " \
+		"will fail with return code 1."
+	(( depth = depth - 1 ))
+done
+
+log_pass "'$ZFS $mountcmd <filesystem>' " \
+	"which mountpoint be the identical or the top of an existing one " \
+	"will fail with return code 1."
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/usr/src/test/zfs-tests/tests/functional/cli_root/zfs_mount/zfs_mount_007_pos.ksh	Wed Dec 05 22:04:50 2012 -0500
@@ -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 2007 Sun Microsystems, Inc.  All rights reserved.
+# Use is subject to license terms.
+#
+
+. $STF_SUITE/tests/functional/cli_root/zfs_mount/zfs_mount.kshlib
+
+#
+# DESCRIPTION:
+# The following options can be set on a temporary basis using the -o option
+# without affecting the on-disk property. The original on-disk value will be
+# restored when the file system is unmounted and mounted.
+#
+#         PROPERTY		MOUNT OPTION
+#	  atime			atime/noatime
+#	  devices		devices/nodevices
+#	  exec			exec/noexec
+#	  readonly		ro/rw
+#	  setuid		setuid/nosetuid
+#
+# STRATEGY:
+#	1. Create filesystem and get origianl property value.
+#	2. Using 'zfs mount -o' to set filesystem property.
+#	3. Verify the property was set temporarily.
+#	4. Verify it will not affect the property that is stored on disk.
+#
+
+function cleanup
+{
+	if ! ismounted $TESTPOOL/$TESTFS; then
+		log_must $ZFS mount $TESTPOOL/$TESTFS
+	fi
+}
+
+log_assert "Verify '-o' will set filesystem property temporarily, " \
+	"without affecting the property that is stored on disk."
+log_onexit cleanup
+
+set -A properties "atime" "devices" "exec" "readonly" "setuid"
+
+#
+# Get the specified filesystem property reverse mount option.
+#
+# $1 filesystem
+# $2 property
+#
+function get_reverse_option
+{
+	typeset fs=$1
+	typeset prop=$2
+
+	# Define property value: "reverse if value=on" "reverse if value=off"
+	set -A values "noatime"   "atime" \
+		      "nodevices" "devices" \
+		      "noexec"    "exec" \
+		      "rw"        "ro" \
+		      "nosetuid"  "setuid"
+
+	typeset -i i=0
+	while (( i < ${#properties[@]} )); do
+		if [[ $prop == ${properties[$i]} ]]; then
+			break
+		fi
+
+		(( i += 1 ))
+	done
+	if (( i >= ${#properties[@]} )); then
+		log_fail "Incorrect option: $prop"
+	fi
+
+	typeset val
+	typeset -i ind=0
+	val=$(get_prop $prop $fs) || log_fail "get_prop $prop $fs"
+	if [[ $val == "on" ]]; then
+		(( ind = i * 2 ))
+	else
+		(( ind = i * 2 + 1 ))
+	fi
+
+	$ECHO ${values[$ind]}
+}
+
+fs=$TESTPOOL/$TESTFS
+cleanup
+
+for property in ${properties[@]}; do
+	orig_val=$(get_prop $property $fs)
+	(($? != 0)) && log_fail "get_prop $property $fs"
+
+	# Set filesystem property temporarily
+	reverse_opt=$(get_reverse_option $fs $property)
+	log_must $ZFS mount -o remount,$reverse_opt $fs
+
+	cur_val=$(get_prop $property $fs)
+	(($? != 0)) && log_fail "get_prop $property $fs"
+
+	# In LZ, a user with all zone privileges can never with "devices"
+	if ! is_global_zone && [[ $property == devices ]] ; then
+		if [[ $cur_val != off || $orig_val != off ]]; then
+			log_fail "'devices' property shouldn't " \
+				"be enabled in LZ"
+		fi
+	elif [[ $orig_val == $cur_val ]]; then
+		log_fail "zfs mount -o remount,$reverse_opt " \
+			"doesn't change property."
+	fi
+
+	# unmount & mount will revert property to the original value
+	log_must $ZFS unmount $fs
+	log_must $ZFS mount $fs
+
+	cur_val=$(get_prop $property $fs)
+	(($? != 0)) && log_fail "get_prop $property $fs"
+	if [[ $orig_val != $cur_val ]]; then
+		log_fail "zfs mount -o remount,$reverse_opt " \
+			"change the property that is stored on disks"
+	fi
+done
+
+log_pass "Verify '-o' set filesystem property temporarily passed."
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/usr/src/test/zfs-tests/tests/functional/cli_root/zfs_mount/zfs_mount_008_pos.ksh	Wed Dec 05 22:04:50 2012 -0500
@@ -0,0 +1,92 @@
+#!/bin/ksh -p
+#
+# CDDL HEADER START
+#
+# The contents of this file are subject to the terms of the
+# Common Development and Distribution License (the "License").
+# You may not use this file except in compliance with the License.
+#
+# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
+# or http://www.opensolaris.org/os/licensing.
+# See the License for the specific language governing permissions
+# and limitations under the License.
+#
+# When distributing Covered Code, include this CDDL HEADER in each
+# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
+# If applicable, add the following below this CDDL 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.
+#
+
+. $STF_SUITE/tests/functional/cli_root/zfs_mount/zfs_mount.kshlib
+
+#
+# DESCRIPTION:
+#	'zfs mount -O' allow the file system to be mounted over an existing
+#	mount point, making the underlying file system inaccessible.
+#
+# STRATEGY:
+#	1. Create two filesystem fs & fs1, and create two test files for them.
+#	2. Unmount fs1 and set mountpoint property is identical to fs.
+#	3. Verify 'zfs mount -O' will make the underlying filesystem fs
+#	   inaccessible.
+#
+
+function cleanup
+{
+	! ismounted $fs && log_must $ZFS mount $fs
+
+	if datasetexists $fs1; then
+		log_must $ZFS destroy $fs1
+	fi
+
+	if [[ -f $testfile ]]; then
+		log_must $RM -f $testfile
+	fi
+}
+
+log_assert "Verify 'zfs mount -O' will override existing mount point."
+log_onexit cleanup
+
+fs=$TESTPOOL/$TESTFS; fs1=$TESTPOOL/$TESTFS1
+
+cleanup
+
+# Get the original mountpoint of $fs and $fs1
+mntpnt=$(get_prop mountpoint $fs)
+log_must $ZFS create $fs1
+mntpnt1=$(get_prop mountpoint $fs1)
+
+testfile=$mntpnt/$TESTFILE0; testfile1=$mntpnt1/$TESTFILE1
+log_must $MKFILE 1M $testfile $testfile1
+
+log_must $ZFS unmount $fs1
+log_must $ZFS set mountpoint=$mntpnt $fs1
+log_mustnot $ZFS mount $fs1
+log_must $ZFS mount -O $fs1
+
+# Create new file in override mountpoint
+log_must $MKFILE 1M $mntpnt/$TESTFILE2
+
+# Verify the underlying file system inaccessible
+log_mustnot $LS $testfile
+log_must $LS $mntpnt/$TESTFILE1 $mntpnt/$TESTFILE2
+
+# Verify $TESTFILE2 was created in $fs1, rather then $fs
+log_must $ZFS unmount $fs1
+log_must $ZFS set mountpoint=$mntpnt1 $fs1
+log_must $ZFS mount $fs1
+log_must $LS $testfile1 $mntpnt1/$TESTFILE2
+
+# Verify $TESTFILE2 was not created in $fs, and $fs is accessable again.
+log_mustnot $LS $mntpnt/$TESTFILE2
+log_must $LS $testfile
+
+log_pass "Verify 'zfs mount -O' override mount point passed."
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/usr/src/test/zfs-tests/tests/functional/cli_root/zfs_mount/zfs_mount_009_neg.ksh	Wed Dec 05 22:04:50 2012 -0500
@@ -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) 2012 by Delphix. All rights reserved.
+#
+
+. $STF_SUITE/include/libtest.shlib
+. $STF_SUITE/tests/functional/cli_root/zfs_mount/zfs_mount.kshlib
+
+#
+# DESCRIPTION:
+#	Try each 'zfs mount' with inapplicable scenarios to make sure
+#	it returns an error. include:
+#		* '-a', but also with a specific filesystem.
+#
+# 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 "both"
+
+multifs="$TESTFS $TESTFS1"
+datasets=""
+
+for fs in $multifs ; do
+	datasets="$datasets $TESTPOOL/$fs"
+done
+
+set -A args "$mountall $TESTPOOL/$TESTFS"
+
+function setup_all
+{
+	typeset fs
+
+	for fs in $multifs ; do
+		setup_filesystem "$DISKS" "$TESTPOOL" \
+			"$fs" \
+			"${TEST_BASE_DIR%%/}/testroot$$/$TESTPOOL/$fs"
+	done
+	return 0
+}
+
+function cleanup_all
+{
+	typeset fs
+
+	cleanup_filesystem "$TESTPOOL" "$TESTFS1"
+	log_must $ZFS set mountpoint=$TESTDIR $TESTPOOL/$TESTFS
+
+	[[ -d ${TEST_BASE_DIR%%/}/testroot$$ ]] && \
+		$RM -rf ${TEST_BASE_DIR%%/}/testroot$$
+
+
+	return 0
+}
+
+function verify_all
+{
+	typeset fs
+
+	for fs in $multifs ; do
+		log_must unmounted $TESTPOOL/$fs
+	done
+	return 0
+}
+
+log_assert "Badly-formed 'zfs $mountcmd' with inapplicable scenarios " \
+	"should return an error."
+log_onexit cleanup_all
+
+log_must setup_all
+
+log_must $ZFS $unmountall
+
+typeset -i i=0
+while (( i < ${#args[*]} )); do
+	log_mustnot $ZFS ${args[i]}
+	((i = i + 1))
+done
+
+log_must verify_all
+
+log_pass "Badly formed 'zfs $mountcmd' with inapplicable scenarios " \
+	"fail as expected."
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/usr/src/test/zfs-tests/tests/functional/cli_root/zfs_mount/zfs_mount_010_neg.ksh	Wed Dec 05 22:04:50 2012 -0500
@@ -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.
+#
+
+. $STF_SUITE/include/libtest.shlib
+
+#
+# DESCRIPTION:
+# Verify that zfs mount should fail when mounting a mounted zfs filesystem or
+# the mountpoint is busy
+#
+# STRATEGY:
+# 1. Make a zfs filesystem mounted or mountpoint busy
+# 2. Use zfs mount to mount the filesystem
+# 3. Verify that zfs mount returns error
+#
+
+verify_runnable "both"
+
+function cleanup
+{
+	if ! ismounted $fs; then
+		log_must $ZFS mount $fs
+	fi
+}
+
+log_assert "zfs mount fails with mounted filesystem or busy mountpoint"
+log_onexit cleanup
+
+fs=$TESTPOOL/$TESTFS
+if ! ismounted $fs; then
+	log_must $ZFS mount $fs
+fi
+
+log_mustnot $ZFS mount $fs
+
+mpt=$(get_prop mountpoint $fs)
+log_must $ZFS umount $fs
+curpath=`$DIRNAME $0`
+cd $mpt
+log_mustnot $ZFS mount $fs
+cd $curpath
+
+log_pass "zfs mount fails with mounted filesystem or busy moutpoint as expected."
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/usr/src/test/zfs-tests/tests/functional/cli_root/zfs_mount/zfs_mount_011_neg.ksh	Wed Dec 05 22:04:50 2012 -0500
@@ -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.
+#
+
+. $STF_SUITE/include/libtest.shlib
+
+#
+# DESCRIPTION:
+# Verify that zfs mount should fail with bad parameters
+#
+# STRATEGY:
+# 1. Make an array of bad parameters
+# 2. Use zfs mount to mount the filesystem
+# 3. Verify that zfs mount returns error
+#
+
+verify_runnable "both"
+
+function cleanup
+{
+	if snapexists $TESTPOOL/$TESTFS@$TESTSNAP; then
+		log_must $ZFS destroy $TESTPOOL/$TESTFS@$TESTSNAP
+	fi
+
+	if is_global_zone && datasetexists $TESTPOOL/$TESTVOL; then
+		log_must $ZFS destroy $TESTPOOL/$TESTVOL
+	fi
+}
+
+log_assert "zfs mount fails with bad parameters"
+log_onexit cleanup
+
+fs=$TESTPOOL/$TESTFS
+set -A badargs "A" "-A" "-" "-x" "-?" "=" "-o *" "-a"
+
+for arg in "${badargs[@]}"; do
+	log_mustnot eval "$ZFS mount $arg $fs >/dev/null 2>&1"
+done
+
+#verify that zfs mount fails with invalid dataset
+for opt in "-o abc" "-O"; do
+	log_mustnot eval "$ZFS mount $opt /$fs >/dev/null 2>&1"
+done
+
+#verify that zfs mount fails with volume and snapshot
+log_must $ZFS snapshot $TESTPOOL/$TESTFS@$TESTSNAP
+log_mustnot eval "$ZFS mount $TESTPOOL/$TESTFS@$TESTSNAP >/dev/null 2>&1"
+
+if is_global_zone; then
+	log_must $ZFS create -V 10m $TESTPOOL/$TESTVOL
+	log_mustnot eval "$ZFS mount $TESTPOOL/$TESTVOL >/dev/null 2>&1"
+fi
+
+log_pass "zfs mount fails with bad parameters as expected."
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/usr/src/test/zfs-tests/tests/functional/cli_root/zfs_mount/zfs_mount_all_001_pos.ksh	Wed Dec 05 22:04:50 2012 -0500
@@ -0,0 +1,197 @@
+#!/bin/ksh -p
+#
+# CDDL HEADER START
+#
+# The contents of this file are subject to the terms of the
+# Common Development and Distribution License (the "License").
+# You may not use this file except in compliance with the License.
+#
+# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
+# or http://www.opensolaris.org/os/licensing.
+# See the License for the specific language governing permissions
+# and limitations under the License.
+#
+# When distributing Covered Code, include this CDDL HEADER in each
+# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
+# If applicable, add the following below this CDDL HEADER, with the
+# fields enclosed by brackets "[]" replaced with your own identifying
+# information: Portions Copyright [yyyy] [name of copyright owner]
+#
+# CDDL HEADER END
+#
+
+#
+# Copyright 2007 Sun Microsystems, Inc.  All rights reserved.
+# Use is subject to license terms.
+#
+. $STF_SUITE/include/libtest.shlib
+. $STF_SUITE/tests/functional/cli_root/zfs_mount/zfs_mount.kshlib
+
+# DESCRIPTION:
+#       Verify that 'zfs mount -a' succeeds as root.
+#
+# STRATEGY:
+#       1. Create a group of pools with specified vdev.
+#       2. Create zfs filesystems within the given pools.
+#       3. Unmount all the filesystems.
+#       4. Verify that 'zfs mount -a' command succeed,
+#	   and all available ZFS filesystems are mounted.
+#	5. Verify that 'zfs mount' is identical with 'df -F zfs'
+#
+
+verify_runnable "both"
+
+set -A fs "$TESTFS" "$TESTFS1"
+set -A ctr "" "$TESTCTR" "$TESTCTR/$TESTCTR1" "$TESTCTR1"
+set -A vol "$TESTVOL" "$TESTVOL1"
+
+function setup_all
+{
+	typeset -i i=0
+	typeset -i j=0
+	typeset path
+
+	while (( i < ${#ctr[*]} )); do
+
+		path=${TEST_BASE_DIR%%/}/testroot$$/$TESTPOOL
+		if [[ -n ${ctr[i]} ]]; then
+			path=$path/${ctr[i]}
+
+			setup_filesystem "$DISKS" "$TESTPOOL" \
+				"${ctr[i]}" "$path" \
+				"ctr"
+		fi
+
+		if is_global_zone ; then
+			j=0
+			while (( j < ${#vol[*]} )); do
+				setup_filesystem "$DISKS" "$TESTPOOL" \
+					"${ctr[i]}/${vol[j]}" \
+					"$path/${vol[j]}" \
+					"vol"
+				((j = j + 1))
+			done
+		fi
+
+		j=0
+		while (( j < ${#fs[*]} )); do
+			setup_filesystem "$DISKS" "$TESTPOOL" \
+				"${ctr[i]}/${fs[j]}" \
+				"$path/${fs[j]}"
+			((j = j + 1))
+		done
+
+		((i = i + 1))
+	done
+
+	return 0
+}
+
+function cleanup_all
+{
+	typeset -i i=0
+	typeset -i j=0
+	typeset path
+
+	((i = ${#ctr[*]} - 1))
+
+	while (( i >= 0 )); do
+		if is_global_zone ; then
+			j=0
+			while (( j < ${#vol[*]} )); do
+				cleanup_filesystem "$TESTPOOL" \
+					"${ctr[i]}/${vol[j]}"
+				((j = j + 1))
+			done
+		fi
+
+		j=0
+		while (( j < ${#fs[*]} )); do
+			cleanup_filesystem "$TESTPOOL" \
+				"${ctr[i]}/${fs[j]}"
+			((j = j + 1))
+		done
+
+		[[ -n ${ctr[i]} ]] && \
+			cleanup_filesystem "$TESTPOOL" "${ctr[i]}"
+
+		((i = i - 1))
+	done
+
+	[[ -d ${TEST_BASE_DIR%%/}/testroot$$ ]] && \
+		$RM -rf ${TEST_BASE_DIR%%/}/testroot$$
+}
+
+#
+# This function takes a single true/false argument. If true it will verify that
+# all file systems are mounted. If false it will verify that they are not
+# mounted.
+#
+function verify_all
+{
+	typeset -i i=0
+	typeset -i j=0
+	typeset path
+	typeset logfunc
+
+	if $1; then
+		logfunc=log_must
+	else
+		logfunc=log_mustnot
+	fi
+
+	while (( i < ${#ctr[*]} )); do
+
+		path=$TESTPOOL
+		[[ -n ${ctr[i]} ]] && \
+			path=$path/${ctr[i]}
+
+		if is_global_zone ; then
+			j=0
+			while (( j < ${#vol[*]} )); do
+				log_mustnot mounted "$path/${vol[j]}"
+				((j = j + 1))
+			done
+		fi
+
+		j=0
+		while (( j < ${#fs[*]} )); do
+			$logfunc mounted "$path/${fs[j]}"
+			((j = j + 1))
+		done
+
+		$logfunc mounted "$path"
+
+		((i = i + 1))
+	done
+
+	return 0
+}
+
+
+log_assert "Verify that 'zfs $mountall' succeeds as root, " \
+	"and all available ZFS filesystems are mounted."
+
+log_onexit cleanup_all
+
+log_must setup_all
+
+export __ZFS_POOL_RESTRICT="$TESTPOOL"
+log_must $ZFS $unmountall
+unset __ZFS_POOL_RESTRICT
+
+verify_all false
+
+export __ZFS_POOL_RESTRICT="$TESTPOOL"
+log_must $ZFS $mountall
+unset __ZFS_POOL_RESTRICT
+
+verify_all true
+
+log_note "Verify that 'zfs $mountcmd' will display " \
+	"all ZFS filesystems currently mounted."
+
+verify_mount_display
+
+log_pass "'zfs $mountall' succeeds as root, " \
+	"and all available ZFS filesystems are mounted."
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/usr/src/test/zfs-tests/tests/functional/cli_root/zfs_promote/Makefile	Wed Dec 05 22:04:50 2012 -0500
@@ -0,0 +1,50 @@
+#
+# 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) 2012 by Delphix. All rights reserved.
+#
+
+include $(SRC)/Makefile.master
+
+ROOTOPTPKG = $(ROOT)/opt/zfs-tests
+TESTDIR = $(ROOTOPTPKG)/tests/functional/cli_root/zfs_promote
+
+PROGS = cleanup \
+	setup \
+	zfs_promote_001_pos \
+	zfs_promote_002_pos \
+	zfs_promote_003_pos \
+	zfs_promote_004_pos \
+	zfs_promote_005_pos \
+	zfs_promote_006_neg \
+	zfs_promote_007_neg \
+	zfs_promote_008_pos
+
+FILES = zfs_promote.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	Thu Jan 01 00:00:00 1970 +0000
+++ b/usr/src/test/zfs-tests/tests/functional/cli_root/zfs_promote/cleanup.ksh	Wed Dec 05 22:04:50 2012 -0500
@@ -0,0 +1,30 @@
+#!/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.
+#
+
+. $STF_SUITE/include/libtest.shlib
+
+default_cleanup
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/usr/src/test/zfs-tests/tests/functional/cli_root/zfs_promote/setup.ksh	Wed Dec 05 22:04:50 2012 -0500
@@ -0,0 +1,32 @@
+#!/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.
+#
+
+. $STF_SUITE/include/libtest.shlib
+
+DISK=${DISKS%% *}
+
+default_volume_setup ${DISK}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/usr/src/test/zfs-tests/tests/functional/cli_root/zfs_promote/zfs_promote.cfg	Wed Dec 05 22:04:50 2012 -0500
@@ -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) 2012 by Delphix. All rights reserved.
+#
+
+export FILESIZE=1m
+
+export TESTSNAP3=testsnap3.promote
+export TESTSNAP4=testsnap4.promote
+export TESTSNAP5=testsnap5.promote
+export TESTFILE3=testfile3.promote
+
+export CLONEFILE=clonefile.promote
+export CLONEFILE1=clonefile1.promote
+export CLONEFILE2=clonefile2.promote
+export CLONEFILE3=clonefile3.promote
+
+
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/usr/src/test/zfs-tests/tests/functional/cli_root/zfs_promote/zfs_promote_001_pos.ksh	Wed Dec 05 22:04:50 2012 -0500
@@ -0,0 +1,127 @@
+#!/bin/ksh -p
+#
+# CDDL HEADER START
+#
+# The contents of this file are subject to the terms of the
+# Common Development and Distribution License (the "License").
+# You may not use this file except in compliance with the License.
+#
+# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
+# or http://www.opensolaris.org/os/licensing.
+# See the License for the specific language governing permissions
+# and limitations under the License.
+#
+# When distributing Covered Code, include this CDDL HEADER in each
+# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
+# If applicable, add the following below this CDDL HEADER, with the
+# fields enclosed by brackets "[]" replaced with your own identifying
+# information: Portions Copyright [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.
+#
+
+. $STF_SUITE/tests/functional/cli_root/zfs_promote/zfs_promote.cfg
+. $STF_SUITE/include/libtest.shlib
+
+#
+# DESCRIPTION:
+#	'zfs promote' can promote a clone filesystem to no longer be dependent
+#	on its "origin" snapshot.
+#
+# STRATEGY:
+#	1. Create a snapshot and a clone of the snapshot
+#	2. Promote the clone filesystem
+#	3. Verify the promoted filesystem become independent
+#
+
+verify_runnable "both"
+
+function cleanup
+{
+	if snapexists $csnap; then
+		log_must $ZFS promote $fs
+	fi
+	snapexists $snap && \
+		log_must $ZFS destroy -rR $snap
+
+	typeset data
+	for data in $file0 $file1; do
+		[[ -e $data ]] && $RM -f $data
+	done
+}
+
+function testing_verify
+{
+	typeset ds=$1
+	typeset ds_file=$2
+	typeset snap_file=$3
+	typeset c_ds=$4
+	typeset c_file=$5
+	typeset csnap_file=$6
+	typeset origin_prop=""
+
+
+	snapexists $ds@$TESTSNAP && \
+		log_fail "zfs promote cannot promote $ds@$TESTSNAP."
+	! snapexists $c_ds@$TESTSNAP && \
+		log_fail "The $c_ds@$TESTSNAP after zfs promote doesn't exist."
+
+	origin_prop=$(get_prop origin $ds)
+	[[ "$origin_prop" != "$c_ds@$TESTSNAP" ]] && \
+		log_fail "The dependency of $ds is not correct."
+	origin_prop=$(get_prop origin $c_ds)
+	[[ "$origin_prop" != "-" ]] && \
+		log_fail "The dependency of $c_ds is not correct."
+
+	if [[ -e $snap_file ]] || [[ ! -e $csnap_file ]]; then
+		log_fail "Data file $snap_file cannot be correctly promoted."
+	fi
+	if [[ ! -e $ds_file ]] || [[ ! -e $c_file ]]; then
+		log_fail "There exists data file losing after zfs promote."
+	fi
+
+	log_mustnot $ZFS destroy -r $c_ds
+}
+
+log_assert "'zfs promote' can promote a clone filesystem."
+log_onexit cleanup
+
+fs=$TESTPOOL/$TESTFS
+file0=$TESTDIR/$TESTFILE0
+file1=$TESTDIR/$TESTFILE1
+snap=$fs@$TESTSNAP
+snapfile=$TESTDIR/.zfs/snapshot/$TESTSNAP/$TESTFILE0
+clone=$TESTPOOL/$TESTCLONE
+cfile=/$clone/$CLONEFILE
+csnap=$clone@$TESTSNAP
+csnapfile=/$clone/.zfs/snapshot/$TESTSNAP/$TESTFILE0
+
+# setup for promte testing
+log_must $MKFILE $FILESIZE $file0
+log_must $ZFS snapshot $snap
+log_must $MKFILE $FILESIZE $file1
+log_must $RM -f $file0
+log_must $ZFS clone $snap $clone
+log_must $MKFILE $FILESIZE $cfile
+
+log_must $ZFS promote $clone
+# verify the 'promote' operation
+testing_verify $fs $file1 $snapfile $clone $cfile $csnapfile
+
+log_note "Verify 'zfs promote' can change back the dependency relationship."
+log_must $ZFS promote $fs
+#verify the result
+testing_verify $clone $cfile $csnapfile $fs $file1 $snapfile
+
+log_pass "'zfs promote' reverses the clone parent-child dependency relationship"\
+	"as expected."
+
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/usr/src/test/zfs-tests/tests/functional/cli_root/zfs_promote/zfs_promote_002_pos.ksh	Wed Dec 05 22:04:50 2012 -0500
@@ -0,0 +1,102 @@
+#!/bin/ksh -p
+#
+# CDDL HEADER START
+#
+# The contents of this file are subject to the terms of the
+# Common Development and Distribution License (the "License").
+# You may not use this file except in compliance with the License.
+#
+# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
+# or http://www.opensolaris.org/os/licensing.
+# See the License for the specific language governing permissions
+# and limitations under the License.
+#
+# When distributing Covered Code, include this CDDL HEADER in each
+# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
+# If applicable, add the following below this CDDL HEADER, with the
+# fields enclosed by brackets "[]" replaced with your own identifying
+# information: Portions Copyright [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.
+#
+
+. $STF_SUITE/tests/functional/cli_root/zfs_promote/zfs_promote.cfg
+. $STF_SUITE/include/libtest.shlib
+
+#
+# DESCRIPTION:
+#	'zfs promote' can deal with multiple snapshots in the origin filesystem.
+#
+# STRATEGY:
+#	1. Create multiple snapshots and a clone of the last snapshot
+#	2. Promote the clone filesystem
+#	3. Verify the promoted filesystem included all snapshots
+#
+
+verify_runnable "both"
+
+function cleanup
+{
+	if snapexists $csnap1; then
+		log_must $ZFS promote $fs
+	fi
+
+	typeset ds
+	typeset data
+	for ds in $snap $snap1; do
+		log_must $ZFS destroy -rR $ds
+	done
+	for file in $TESTDIR/$TESTFILE0 $TESTDIR/$TESTFILE1; do
+		[[ -e $file ]] && $RM -f $file
+	done
+}
+
+log_assert "'zfs promote' can deal with multiple snapshots in a filesystem."
+log_onexit cleanup
+
+fs=$TESTPOOL/$TESTFS
+snap=$fs@$TESTSNAP
+snap1=$fs@$TESTSNAP1
+clone=$TESTPOOL/$TESTCLONE
+csnap=$clone@$TESTSNAP
+csnap1=$clone@$TESTSNAP1
+
+# setup for promote testing
+log_must $MKFILE $FILESIZE $TESTDIR/$TESTFILE0
+log_must $ZFS snapshot $snap
+log_must $MKFILE $FILESIZE $TESTDIR/$TESTFILE1
+log_must $RM -f $testdir/$TESTFILE0
+log_must $ZFS snapshot $snap1
+log_must $ZFS clone $snap1 $clone
+log_must $MKFILE $FILESIZE /$clone/$CLONEFILE
+
+log_must $ZFS promote $clone
+
+# verify the 'promote' operation
+for ds in $csnap $csnap1; do
+	! snapexists $ds && \
+		log_fail "Snapshot $ds doesn't exist after zfs promote."
+done
+for ds in $snap $snap1; do
+	snapexists $ds && \
+		log_fail "Snapshot $ds is still there after zfs promote."
+done
+
+origin_prop=$(get_prop origin $fs)
+[[ "$origin_prop" != "$csnap1" ]] && \
+	log_fail "The dependency of $fs is not correct."
+origin_prop=$(get_prop origin $clone)
+[[ "$origin_prop" != "-" ]] && \
+	 log_fail "The dependency of $clone is not correct."
+
+log_pass "'zfs promote' deal with multiple snapshots as expected."
+
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/usr/src/test/zfs-tests/tests/functional/cli_root/zfs_promote/zfs_promote_003_pos.ksh	Wed Dec 05 22:04:50 2012 -0500
@@ -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) 2012 by Delphix. All rights reserved.
+#
+
+. $STF_SUITE/tests/functional/cli_root/zfs_promote/zfs_promote.cfg
+. $STF_SUITE/include/libtest.shlib
+
+#
+# DESCRIPTION:
+#	'zfs promote' can deal with multi-point snapshots.
+#
+# STRATEGY:
+#	1. Create multiple snapshots and a clone to a middle point snapshot
+#	2. Promote the clone filesystem
+#	3. Verify the origin filesystem and promoted filesystem include
+#	   correct datasets seperated by the clone point.
+#
+
+verify_runnable "both"
+
+function cleanup
+{
+	if snapexists ${csnap[2]}; then
+		log_must $ZFS promote $fs
+	fi
+
+	typeset ds
+	typeset data
+	for ds in ${snap[*]}; do
+		snapexists $ds && \
+			log_must $ZFS destroy -rR $ds
+	done
+	for data in ${file[*]}; do
+		[[ -e $data ]] && $RM -f $data
+	done
+
+}
+
+log_assert "'zfs promote' can deal with multi-point snapshots."
+log_onexit cleanup
+
+fs=$TESTPOOL/$TESTFS
+clone=$TESTPOOL/$TESTCLONE
+
+# Define some arrays here to use loop to reduce code amount
+
+# Array which stores the origin snapshots created in the origin filesystem
+set -A snap "${fs}@$TESTSNAP" "${fs}@$TESTSNAP1" "${fs}@$TESTSNAP2" "${fs}@$TESTSNAP3"
+# Array which stores the snapshots existing in the clone after promote operation
+set -A csnap "${clone}@$TESTSNAP" "${clone}@$TESTSNAP1" "${clone}@$TESTSNAP2" \
+	"${clone}@$TESTSNAP3"
+# The data will inject into the origin filesystem
+set -A file "$TESTDIR/$TESTFILE0" "$TESTDIR/$TESTFILE1" "$TESTDIR/$TESTFILE2" \
+		"$TESTDIR/$TESTFILE3"
+snapdir=$TESTDIR/.zfs/snapshot
+# The data which will exist in the snapshot after creation of snapshot
+set -A snapfile "$snapdir/$TESTSNAP/$TESTFILE0" "$snapdir/$TESTSNAP1/$TESTFILE1" \
+	"$snapdir/$TESTSNAP2/$TESTFILE2" "$snapdir/$TESTSNAP3/$TESTFILE3"
+csnapdir=/$clone/.zfs/snapshot
+# The data which will exist in the snapshot of clone filesystem after promote
+set -A csnapfile "${csnapdir}/$TESTSNAP/$TESTFILE0" "${csnapdir}/$TESTSNAP1/$TESTFILE1" \
+	"${csnapdir}/$TESTSNAP2/$TESTFILE2"
+
+# setup for promote testing
+typeset -i i=0
+while (( i < 4 )); do
+	log_must $MKFILE $FILESIZE ${file[i]}
+	(( i>0 )) && log_must $RM -f ${file[((i-1))]}
+	log_must $ZFS snapshot ${snap[i]}
+
+	(( i = i + 1 ))
+done
+log_must $ZFS clone ${snap[2]} $clone
+log_must $MKFILE $FILESIZE /$clone/$CLONEFILE
+log_must $RM -f /$clone/$TESTFILE2
+log_must $ZFS snapshot ${csnap[3]}
+
+log_must $ZFS promote $clone
+
+# verify the 'promote' operation
+for ds in ${snap[3]} ${csnap[*]}; do
+	! snapexists $ds && \
+		log_fail "The snapshot $ds disappear after zfs promote."
+done
+for data in ${csnapfile[*]} $TESTDIR/$TESTFILE3 /$clone/$CLONEFILE; do
+	[[ ! -e $data ]] && \
+		log_fail "The data file $data loses after zfs promote."
+done
+
+for ds in ${snap[0]} ${snap[1]} ${snap[2]}; do
+	snapexists $ds && \
+		log_fail "zfs promote cannot promote the snapshot $ds."
+done
+for data in ${snapfile[0]} ${snapfile[1]} ${snapfile[2]}; do
+	[[ -e $data ]] && \
+		log_fail "zfs promote cannot promote the data $data."
+done
+
+origin_prop=$(get_prop origin $fs)
+[[ "$origin_prop" != "${csnap[2]}" ]] && \
+	log_fail "The dependency is not correct for $fs after zfs promote."
+origin_prop=$(get_prop origin $clone)
+[[ "$origin_prop" != "-" ]] && \
+	log_fail "The dependency is not correct for $clone after zfs promote."
+
+log_pass "'zfs promote' deal with multi-point snapshots as expected."
+
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/usr/src/test/zfs-tests/tests/functional/cli_root/zfs_promote/zfs_promote_004_pos.ksh	Wed Dec 05 22:04:50 2012 -0500
@@ -0,0 +1,140 @@
+#!/bin/ksh -p
+#
+# CDDL HEADER START
+#
+# The contents of this file are subject to the terms of the
+# Common Development and Distribution License (the "License").
+# You may not use this file except in compliance with the License.
+#
+# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
+# or http://www.opensolaris.org/os/licensing.
+# See the License for the specific language governing permissions
+# and limitations under the License.
+#
+# When distributing Covered Code, include this CDDL HEADER in each
+# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
+# If applicable, add the following below this CDDL HEADER, with the
+# fields enclosed by brackets "[]" replaced with your own identifying
+# information: Portions Copyright [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.
+#
+
+. $STF_SUITE/tests/functional/cli_root/zfs_promote/zfs_promote.cfg
+. $STF_SUITE/include/libtest.shlib
+
+#
+# DESCRIPTION:
+#	'zfs promote' can deal with multi-level clones.
+#
+# STRATEGY:
+#	1. Create multiple snapshots and multi-level clones
+#	2. Promote a clone filesystem
+#	3. Verify the dataset dependency relationships are correct after promotion.
+#
+
+verify_runnable "both"
+
+function cleanup
+{
+	if snapexists ${c1snap[1]}; then
+		log_must $ZFS promote $clone
+	fi
+
+	typeset ds
+	typeset data
+	for ds in ${snap[*]}; do
+		snapexists $ds && \
+			log_must $ZFS destroy -rR $ds
+	done
+	for data in ${file[*]}; do
+		[[ -e $data ]] && $RM -f $data
+	done
+}
+
+log_assert "'zfs promote' can deal with multi-level clone."
+log_onexit cleanup
+
+fs=$TESTPOOL/$TESTFS
+clone=$TESTPOOL/$TESTCLONE
+clone1=$TESTPOOL/$TESTCLONE1
+
+# Define some arrays here to use loop to reduce code amount
+
+# Array which stores the origin snapshots created in the origin filesystem
+set -A snap "${fs}@$TESTSNAP" "${fs}@$TESTSNAP1" "${fs}@$TESTSNAP2" "${fs}@$TESTSNAP3"
+# Array which stores the snapshots existing in the first clone
+set -A csnap "${clone}@$TESTSNAP3" "${clone}@$TESTSNAP4" "${clone}@$TESTSNAP5"
+# Array which stores the snapshots existing in the second clone after promote operation
+set -A c1snap "${clone1}@$TESTSNAP3" "${clone1}@$TESTSNAP4" "${clone1}@$TESTSNAP5"
+# The data will inject into the origin filesystem
+set -A file "$TESTDIR/$TESTFILE0" "$TESTDIR/$TESTFILE1" "$TESTDIR/$TESTFILE2" \
+		"$TESTDIR/$TESTFILE3"
+cdir=/$TESTPOOL/$TESTCLONE
+# The data will inject into the first clone
+set -A cfile "${cdir}/$CLONEFILE" "${cdir}/$CLONEFILE1" "${cdir}/$CLONEFILE2"
+c1snapdir=/$TESTPOOL/$TESTCLONE1/.zfs/snapshot
+# The data which will exist in the snapshot of the second clone filesystem after promote
+set -A c1snapfile "${c1snapdir}/$TESTSNAP3/$CLONEFILE" \
+	"${c1snapdir}/$TESTSNAP4/$CLONEFILE1" \
+	"${c1snapdir}/$TESTSNAP5/$CLONEFILE2"
+
+# setup for promote testing
+typeset -i i=0
+while (( i < 4 )); do
+	log_must $MKFILE $FILESIZE ${file[i]}
+	(( i>0 )) && log_must $RM -f ${file[((i-1))]}
+	log_must $ZFS snapshot ${snap[i]}
+
+	(( i = i + 1 ))
+done
+log_must $ZFS clone ${snap[2]} $clone
+
+log_must $RM -f /$clone/$TESTFILE2
+i=0
+while (( i < 3 )); do
+	log_must $MKFILE $FILESIZE ${cfile[i]}
+	(( i>0 )) && log_must $RM -f ${cfile[(( i-1 ))]}
+	log_must $ZFS snapshot ${csnap[i]}
+
+	(( i = i + 1 ))
+done
+
+log_must $ZFS clone ${csnap[1]} $clone1
+log_must $MKFILE $FILESIZE /$clone1/$CLONEFILE2
+log_must $RM -f /$clone1/$CLONEFILE1
+log_must $ZFS snapshot ${c1snap[2]}
+
+log_must $ZFS promote $clone1
+
+# verify the 'promote' operation
+for ds in ${snap[*]} ${csnap[2]} ${c1snap[*]}; do
+	! snapexists $ds && \
+		log_fail "The snapshot $ds disappear after zfs promote."
+done
+for data in ${c1snapfile[*]}; do
+	[[ ! -e $data ]] && \
+		log_fail "The data file $data loses after zfs promote."
+done
+
+origin_prop=$(get_prop origin $fs)
+[[ "$origin_prop" != "-" ]] && \
+	log_fail "The dependency is not correct for $fs after zfs promote."
+origin_prop=$(get_prop origin $clone)
+[[ "$origin_prop" != "${c1snap[1]}" ]] && \
+	log_fail "The dependency is not correct for $clone after zfs promote."
+origin_prop=$(get_prop origin $clone1)
+[[ "$origin_prop" != "${snap[2]}" ]] && \
+	log_fail "The dependency is not correct for $clone1 after zfs promote."
+
+log_pass "'zfs promote' deal with multi-level clones as expected."
+
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/usr/src/test/zfs-tests/tests/functional/cli_root/zfs_promote/zfs_promote_005_pos.ksh	Wed Dec 05 22:04:50 2012 -0500
@@ -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.
+#
+
+. $STF_SUITE/include/libtest.shlib
+
+#
+# DESCRIPTION:
+#	The original fs was unmounted, 'zfs promote' still should succeed.
+#
+# STRATEGY:
+#	1. Create pool, fs and snapshot.
+#	2. Create clone of fs.
+#	3. Unmount fs, then verify 'zfs promote' clone still succeed.
+#
+
+verify_runnable "both"
+
+function cleanup
+{
+	if datasetexists $fssnap ; then
+		datasetexists $clone && log_must $ZFS destroy $clone
+		log_must $ZFS destroy $fssnap
+	fi
+	if datasetexists $clone ; then
+		log_must $ZFS promote $fs
+		log_must $ZFS destroy $clone
+		log_must $ZFS destroy $fssnap
+	fi
+}
+
+log_assert "The original fs was unmounted, 'zfs promote' still should succeed."
+log_onexit cleanup
+
+fs=$TESTPOOL/$TESTFS
+clone=$TESTPOOL/$TESTCLONE
+fssnap=$fs@fssnap
+
+log_must $ZFS snapshot $fssnap
+log_must $ZFS clone $fssnap $clone
+log_must $ZFS unmount $fs
+log_must $ZFS promote $clone
+log_must $ZFS unmount $clone
+log_must $ZFS promote $fs
+
+log_pass "Unmount original fs, 'zfs promote' passed."
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/usr/src/test/zfs-tests/tests/functional/cli_root/zfs_promote/zfs_promote_006_neg.ksh	Wed Dec 05 22:04:50 2012 -0500
@@ -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 2007 Sun Microsystems, Inc.  All rights reserved.
+# Use is subject to license terms.
+#
+. $STF_SUITE/include/libtest.shlib
+
+#
+# DESCRIPTION:
+#	'zfs promote' will fail with invalid arguments:
+#	(1) NULL arguments
+#	(2) non-existent clone
+#	(3) non-clone datasets:
+#		pool, fs, snapshot,volume
+#	(4) too many arguments.
+#	(5) invalid options
+#
+# STRATEGY:
+#	1. Create an array of invalid arguments
+#	2. For each invalid argument in the array, 'zfs promote' should fail
+#	3. Verify the return code from zfs promote
+#
+
+verify_runnable "both"
+
+snap=$TESTPOOL/$TESTFS@$TESTSNAP
+set -A args "" \
+	"$TESTPOOL/blah" \
+	"$TESTPOOL" "$TESTPOOL/$TESTFS" "$snap" \
+	"$TESTPOOL/$TESTVOL" "$TESTPOL $TESTPOOL/$TESTFS" \
+	"$clone $TESTPOOL/$TESTFS" "- $clone" "-? $clone"
+
+function cleanup
+{
+	if datasetexists $clone; then
+		log_must $ZFS destroy $clone
+	fi
+
+	if snapexists $snap; then
+		destroy_snapshot  $snap
+	fi
+}
+
+log_assert "'zfs promote' will fail with invalid arguments. "
+log_onexit cleanup
+
+snap=$TESTPOOL/$TESTFS@$TESTSNAP
+clone=$TESTPOOL/$TESTCLONE
+log_must $ZFS snapshot $snap
+log_must $ZFS clone $snap $clone
+
+typeset -i i=0
+while (( i < ${#args[*]} )); do
+	log_mustnot $ZFS promote ${args[i]}
+
+	(( i = i + 1 ))
+done
+
+log_pass "'zfs promote' fails with invalid argument as expected."
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/usr/src/test/zfs-tests/tests/functional/cli_root/zfs_promote/zfs_promote_007_neg.ksh	Wed Dec 05 22:04:50 2012 -0500
@@ -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) 2012 by Delphix. All rights reserved.
+#
+
+. $STF_SUITE/tests/functional/cli_root/zfs_promote/zfs_promote.cfg
+. $STF_SUITE/include/libtest.shlib
+
+#
+# DESCRIPTION:
+#	'zfs promote' can deal with conflicts in the namespaces.
+#
+# STRATEGY:
+#	1. Create a snapshot and a clone of the snapshot
+#	2. Create the same name snapshot for the clone
+#	3. Promote the clone filesystem
+#	4. Verify the promote operation fail due to the name conflicts.
+#
+
+verify_runnable "both"
+
+function cleanup
+{
+	snapexists $snap && \
+		log_must $ZFS destroy -rR $snap
+
+	typeset data
+	for data in $TESTDIR/$TESTFILE0 $TESTDIR/$TESTFILE1; do
+		[[ -e $data ]] && $RM -f $data
+	done
+}
+
+log_assert "'zfs promote' can deal with name conflicts."
+log_onexit cleanup
+
+snap=$TESTPOOL/$TESTFS@$TESTSNAP
+clone=$TESTPOOL/$TESTCLONE
+clonesnap=$TESTPOOL/$TESTCLONE@$TESTSNAP
+
+# setup for promte testing
+log_must $MKFILE $FILESIZE $TESTDIR/$TESTFILE0
+log_must $ZFS snapshot $snap
+log_must $MKFILE $FILESIZE $TESTDIR/$TESTFILE1
+log_must $RM -f $TESTDIR/$TESTFILE0
+log_must $ZFS clone $snap $clone
+log_must $MKFILE $FILESIZE /$clone/$CLONEFILE
+log_must $ZFS snapshot $clonesnap
+
+log_mustnot $ZFS promote $clone
+
+log_pass "'zfs promote' deals with name conflicts as expected."
+
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/usr/src/test/zfs-tests/tests/functional/cli_root/zfs_promote/zfs_promote_008_pos.ksh	Wed Dec 05 22:04:50 2012 -0500
@@ -0,0 +1,79 @@
+#!/bin/ksh
+#
+# CDDL HEADER START
+#
+# The contents of this file are subject to the terms of the
+# Common Development and Distribution License (the "License").
+# You may not use this file except in compliance with the License.
+#
+# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
+# or http://www.opensolaris.org/os/licensing.
+# See the License for the specific language governing permissions
+# and limitations under the License.
+#
+# When distributing Covered Code, include this CDDL HEADER in each
+# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
+# If applicable, add the following below this CDDL HEADER, with the
+# fields enclosed by brackets "[]" replaced with your own identifying
+# information: Portions Copyright [yyyy] [name of copyright owner]
+#
+# CDDL HEADER END
+#
+
+#
+# Copyright 2007 Sun Microsystems, Inc.  All rights reserved.
+# Use is subject to license terms.
+#
+. $STF_SUITE/include/libtest.shlib
+
+#
+# DESCRIPTION:
+#	'zfs promote' can successfully promote a volume clone.
+#
+# STRATEGY:
+#	1. Create a volume clone
+#	2. Promote the volume clone
+#	3. Verify the dependency changed.
+#
+
+verify_runnable "global"
+
+function cleanup
+{
+	if snapexists $csnap; then
+		log_must $ZFS promote $vol
+	fi
+
+	log_must $ZFS destroy -rR $snap
+}
+
+log_assert "'zfs promote' can promote a volume clone."
+log_onexit cleanup
+
+vol=$TESTPOOL/$TESTVOL
+snap=$vol@$TESTSNAP
+clone=$TESTPOOL/volclone
+csnap=$clone@$TESTSNAP
+
+if ! snapexists $snap ; then
+	log_must $ZFS snapshot $snap
+	log_must $ZFS clone $snap $clone
+fi
+
+log_must $ZFS promote $clone
+
+# verify the 'promote' operation
+! snapexists $csnap && \
+		log_fail "Snapshot $csnap doesn't exist after zfs promote."
+snapexists $snap && \
+	log_fail "Snapshot $snap is still there after zfs promote."
+
+origin_prop=$(get_prop origin $vol)
+[[ "$origin_prop" != "$csnap" ]] && \
+	log_fail "The dependency of $vol is not correct."
+origin_prop=$(get_prop origin $clone)
+[[ "$origin_prop" != "-" ]] && \
+	 log_fail "The dependency of $clone is not correct."
+
+log_pass "'zfs promote' can promote volume clone as expected."
+
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/usr/src/test/zfs-tests/tests/functional/cli_root/zfs_property/Makefile	Wed Dec 05 22:04:50 2012 -0500
@@ -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) 2012 by Delphix. All rights reserved.
+#
+
+include $(SRC)/Makefile.master
+
+ROOTOPTPKG = $(ROOT)/opt/zfs-tests
+TESTDIR = $(ROOTOPTPKG)/tests/functional/cli_root/zfs_property
+
+PROGS = cleanup \
+	setup \
+	zfs_written_property_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	Thu Jan 01 00:00:00 1970 +0000
+++ b/usr/src/test/zfs-tests/tests/functional/cli_root/zfs_property/cleanup.ksh	Wed Dec 05 22:04:50 2012 -0500
@@ -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) 2012 by Delphix. All rights reserved.
+#
+
+. $STF_SUITE/include/libtest.shlib
+
+default_cleanup
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/usr/src/test/zfs-tests/tests/functional/cli_root/zfs_property/setup.ksh	Wed Dec 05 22:04:50 2012 -0500
@@ -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) 2012 by Delphix. All rights reserved.
+#
+
+. $STF_SUITE/include/libtest.shlib
+
+DISK=${DISKS%% *}
+
+default_setup $DISK
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/usr/src/test/zfs-tests/tests/functional/cli_root/zfs_property/zfs_written_property_001_pos.ksh	Wed Dec 05 22:04:50 2012 -0500
@@ -0,0 +1,230 @@
+# !/bin/ksh
+#
+# 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) 2012 by Delphix. All rights reserved.
+#
+
+#
+# DESCRIPTION
+# Verify that "zfs list" gives correct values for written and written@
+# proerties for the dataset when different operations are on done on it
+#
+#
+# STRATEGY
+# 1) Create recursive datasets
+# 2) Take snapshots, write data and verify  written/ written@ properties for
+#    following cases
+#    a) Delete data
+#    b) Write Data
+#    c) Clone
+#    d) Delete snapshot
+#    e) Recursive datasets
+
+. $STF_SUITE/include/libtest.shlib
+. $STF_SUITE/include/math.shlib
+
+function cleanup
+{
+	for ds in $datasets; do
+		datasetexists $ds && log_must $ZFS destroy -R $TESTPOOL/$TESTFS1
+	done
+}
+function get_prop_mb
+{
+	typeset prop=$1
+	typeset dataset=$2
+	typeset -l value=$(get_prop $prop $dataset)
+	((value = value / mb_block))
+	$ECHO $value
+}
+
+datasets="$TESTPOOL/$TESTFS1 $TESTPOOL/$TESTFS1/$TESTFS2 \
+    $TESTPOOL/$TESTFS1/$TESTFS2/$TESTFS3"
+
+log_assert "verify zfs written and written@ property"
+log_onexit cleanup
+
+typeset -l i=1
+typeset -l blocks=50
+typeset -l expected_written=0
+typeset -l expected_writtenat=0
+typeset -l written=0
+typeset -l total=0
+typeset -l snap1_size=0
+typeset -l snap2_size=0
+typeset -l snap3_size=0
+typeset -l metadata=0
+typeset -l mb_block=0
+((mb_block = 1024 * 1024))
+# approximate metadata on dataset when empty is 32KB
+((metadata = 32 * 1024))
+
+log_note "verify written property statistics for dataset"
+log_must $ZFS create -p $TESTPOOL/$TESTFS1/$TESTFS2/$TESTFS3
+for i in 1 2 3; do
+	log_must $ZFS snapshot $TESTPOOL/$TESTFS1@snap$i
+	log_must $DD if=/dev/urandom of=/$TESTPOOL/$TESTFS1/testfile.$i bs=1M \
+	    count=$blocks
+	log_must $SYNC
+	written=$(get_prop written $TESTPOOL/$TESTFS1)
+	((expected_written=blocks * mb_block))
+	within_percent $written $expected_written 99.5 || \
+	    log_fail "Unexpected written value $written $expected_written"
+	((total = total + blocks))
+	((blocks = blocks + 50))
+done
+
+log_note "verify written property statistics for snapshots"
+blocks=0
+for i in 1 2 3; do
+	written=$(get_prop written $TESTPOOL/$TESTFS1@snap$i)
+	if [[ $blocks -eq 0 ]]; then
+		expected_written=$metadata
+	else
+		((expected_written = blocks * mb_block))
+	fi
+	within_percent $written $expected_written 99.5 || \
+	    log_fail "Unexpected written value $written $expected_written $i"
+	((blocks = blocks + 50))
+done
+
+snap1_size=$total
+((snap2_size = total-50))
+((snap3_size = total-100))
+
+log_note "verify written@ for the same dataset"
+blocks=50
+for i in 1 2 3; do
+	writtenat=$(get_prop written@snap$i $TESTPOOL/$TESTFS1)
+	((expected_writtenat = total * mb_block))
+	within_percent $writtenat $expected_writtenat 99.5 || \
+	    log_fail "Unexpected written@ value"
+	((total = total - blocks))
+	((blocks = blocks + 50))
+done
+log_note "delete data"
+before_written=$(get_prop written $TESTPOOL/$TESTFS1)
+log_must $RM /$TESTPOOL/$TESTFS1/testfile.3
+snap3_size=0
+log_must $SYNC
+written=$(get_prop written $TESTPOOL/$TESTFS1)
+writtenat3=$(get_prop written@snap3 $TESTPOOL/$TESTFS1)
+[[ $written -eq $writtenat3 ]] || \
+    log_fail "Written and written@ dont match $written $writtenat3"
+within_percent $written $before_written 0.1 && \
+    log_fail "Unexpected written value after delete $written $before_written"
+writtenat=$(get_prop written@snap1 $TESTPOOL/$TESTFS1)
+((snap1_size = snap1_size - 150))
+((expected_writtenat = snap1_size * mb_block))
+within_percent $writtenat $expected_writtenat 99.5 || \
+    log_fail "Unexpected written value after delete $writtenat $expected_writtenat"
+writtenat=$(get_prop written@snap2 $TESTPOOL/$TESTFS1)
+((snap2_size = snap2_size - 150))
+((expected_writtenat = snap2_size * mb_block))
+within_percent $writtenat $expected_writtenat 99.5 || \
+    log_fail "Unexpected written value after delete"
+
+log_note "write data"
+blocks=20
+log_must $DD if=/dev/urandom of=/$TESTPOOL/$TESTFS1/testfile.3 bs=1M \
+    count=$blocks
+log_must $SYNC
+written=$(get_prop written $TESTPOOL/$TESTFS1)
+writtenat1=$(get_prop written@snap1 $TESTPOOL/$TESTFS1)
+writtenat2=$(get_prop written@snap2 $TESTPOOL/$TESTFS1)
+writtenat3=$(get_prop written@snap3 $TESTPOOL/$TESTFS1)
+((snap3_size = snap3_size + blocks))
+((expected_writtenat = snap3_size * mb_block))
+[[ $written -eq $writtenat3 ]] || \
+    log_fail "Unexpected_written value"
+within_percent $writtenat3 $expected_writtenat 99.5 || \
+    log_fail "Unexpected_written@ value for snap3"
+((snap2_size = snap2_size + blocks))
+((expected_writtenat = snap2_size * mb_block))
+within_percent $writtenat2 $expected_writtenat 99.5 || \
+    log_fail "Unexpected_written@ value for snap2"
+((snap1_size = snap1_size + blocks))
+((expected_writtenat = snap1_size * mb_block))
+within_percent $writtenat1 $expected_writtenat 99.5 || \
+    log_fail "Unexpected_written@ value for snap1"
+
+log_note "write data to a clone"
+before_clone=$(get_prop written $TESTPOOL/$TESTFS1)
+log_must $ZFS clone $TESTPOOL/$TESTFS1@snap1 $TESTPOOL/$TESTFS1/snap1.clone
+log_must $DD if=/dev/urandom of=/$TESTPOOL/$TESTFS1/snap1.clone/testfile bs=1M \
+    count=40
+after_clone=$(get_prop written $TESTPOOL/$TESTFS1)
+[[ $before_clone -eq $after_clone ]] || \
+    log_fail "unexpected written for clone $before_clone $after_clone"
+
+log_note "deleted snapshot"
+typeset -l before_written1=$(get_prop_mb written@snap1 $TESTPOOL/$TESTFS1)
+typeset -l before_written3=$(get_prop_mb written@snap3 $TESTPOOL/$TESTFS1)
+typeset -l snap_before_written2=$(get_prop_mb written $TESTPOOL/$TESTFS1@snap2)
+typeset -l snap_before_written3=$(get_prop_mb written $TESTPOOL/$TESTFS1@snap3)
+log_must $ZFS destroy $TESTPOOL/$TESTFS1@snap2
+log_mustnot snapexists $TESTPOOL/$TESTFS1@snap2
+log_must $SYNC
+written1=$(get_prop_mb written@snap1 $TESTPOOL/$TESTFS1)
+written3=$(get_prop_mb written@snap3 $TESTPOOL/$TESTFS1)
+[[ $before_written1 -eq $written1 && $before_written3 -eq $written3 ]] || \
+    log_fail "unexpected written values $before_written1 $written1"
+typeset -l expected_written3
+((expected_written3 = snap_before_written2 + snap_before_written3))
+prev_written=$(get_prop_mb written $TESTPOOL/$TESTFS1@snap3)
+within_percent $prev_written $expected_written3 99.5 || \
+    log_fail "unexpected written value $prev_written $expected_written3"
+
+log_must $ZFS destroy $TESTPOOL/$TESTFS1@snap3
+log_mustnot snapexists $TESTPOOL/$TESTFS1@snap3
+written=$(get_prop written $TESTPOOL/$TESTFS1)
+writtenat1=$(get_prop written@snap1 $TESTPOOL/$TESTFS1)
+[[ $written -ne $writtenat1 ]] && \
+    log_fail "Unexpected last snapshot written value"
+
+log_note "verify written@ property for recursive datasets"
+blocks=10
+log_must $ZFS snapshot -r $TESTPOOL/$TESTFS1@now
+for ds in $datasets; do
+	writtenat=$(get_prop written@now $ds)
+	[[ $writtenat -ne 0 ]] && \
+	    log_fail "Unexpected written@ value"
+	log_must $DD if=/dev/urandom of=/$ds/testfile bs=1M count=$blocks
+	log_must $SYNC
+	writtenat=$(get_prop written@now $ds)
+	((expected_writtenat = blocks * mb_block))
+	within_percent $writtenat $expected_writtenat 0.1 || \
+	    log_fail "Unexpected written value"
+	((blocks = blocks + 10))
+done
+
+log_note "verify written@ output for recursive datasets"
+blocks=20
+for ds in $datasets; do
+	log_must $ZFS snapshot $ds@current
+	log_must $DD if=/dev/urandom of=/$ds/testfile bs=1M \
+	    count=$blocks
+	log_must $SYNC
+done
+recursive_output=$($ZFS get -r written@current $TESTPOOL | \
+    $GREP -v $TESTFS1@ | $GREP -v $TESTFS2@ | $GREP -v $TESTFS3@ | \
+    $GREP -v "VALUE" | $GREP -v "-")
+expected="20.0M"
+for ds in $datasets; do
+	writtenat=$($ECHO "$recursive_output" | $GREP -v $ds/)
+	writtenat=$($ECHO "$writtenat" | $GREP $ds | $AWK '{print $3}')
+	[[ $writtenat == $expected ]] || \
+	    log_fail "recursive written property output mismatch"
+done
+
+log_pass "zfs written and written@ property fields print correct values"
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/usr/src/test/zfs-tests/tests/functional/cli_root/zfs_receive/Makefile	Wed Dec 05 22:04:50 2012 -0500
@@ -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) 2012 by Delphix. All rights reserved.
+#
+
+include $(SRC)/Makefile.master
+
+ROOTOPTPKG = $(ROOT)/opt/zfs-tests
+TESTDIR = $(ROOTOPTPKG)/tests/functional/cli_root/zfs_receive
+
+PROGS = cleanup \
+	setup \
+	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_007_neg \
+	zfs_receive_008_pos \
+	zfs_receive_009_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	Thu Jan 01 00:00:00 1970 +0000
+++ b/usr/src/test/zfs-tests/tests/functional/cli_root/zfs_receive/cleanup.ksh	Wed Dec 05 22:04:50 2012 -0500
@@ -0,0 +1,33 @@
+#!/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.
+#
+
+. $STF_SUITE/include/libtest.shlib
+
+poolexists $TESTPOOL1 && \
+	destroy_pool $TESTPOOL1
+
+default_cleanup
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/usr/src/test/zfs-tests/tests/functional/cli_root/zfs_receive/setup.ksh	Wed Dec 05 22:04:50 2012 -0500
@@ -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.
+#
+
+. $STF_SUITE/include/libtest.shlib
+
+DISK=${DISKS%% *}
+if is_global_zone; then
+	default_volume_setup $DISK
+else
+	default_setup $DISK
+fi
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/usr/src/test/zfs-tests/tests/functional/cli_root/zfs_receive/zfs_receive_001_pos.ksh	Wed Dec 05 22:04:50 2012 -0500
@@ -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) 2012 by Delphix. All rights reserved.
+#
+
+. $STF_SUITE/tests/functional/cli_root/cli_common.kshlib
+
+#
+# DESCRIPTION:
+#	Verifying 'zfs receive [<filesystem|snapshot>] -d <filesystem>' works.
+#
+# STRATEGY:
+#	1. Fill in fs with some data
+#	2. Create full and incremental send stream
+#	3. Receive the send stream
+#	4. Verify the restoring results.
+#
+
+verify_runnable "both"
+
+function cleanup
+{
+	typeset -i i=0
+
+	datasetexists $rst_root && \
+		log_must $ZFS destroy -Rf $rst_root
+	while (( i < 2 )); do
+		snapexists ${orig_snap[$i]} && \
+			log_must $ZFS destroy -f ${orig_snap[$i]}
+		log_must $RM -f ${bkup[$i]}
+
+		(( i = i + 1 ))
+	done
+
+	log_must $RM -rf $TESTDIR1
+}
+
+function recreate_root
+{
+	datasetexists $rst_root && \
+		log_must $ZFS destroy -Rf $rst_root
+	if [[ -d $TESTDIR1 ]] ; then
+		log_must $RM -rf $TESTDIR1
+	fi
+	log_must $ZFS create $rst_root
+	log_must $ZFS set mountpoint=$TESTDIR1 $rst_root
+}
+
+log_assert "Verifying 'zfs receive [<filesystem|snapshot>] -d <filesystem>' works."
+log_onexit cleanup
+
+typeset datasets="$TESTPOOL/$TESTFS $TESTPOOL"
+set -A bkup "/var/tmp/fullbkup" "/var/tmp/incbkup"
+orig_sum=""
+rst_sum=""
+rst_root=$TESTPOOL/rst_ctr
+rst_fs=${rst_root}/$TESTFS
+
+for orig_fs in $datasets ; do
+	#
+	# Preparations for testing
+	#
+	recreate_root
+
+	set -A orig_snap "${orig_fs}@init_snap" "${orig_fs}@inc_snap"
+	typeset mntpnt=$(get_prop mountpoint ${orig_fs})
+	set -A orig_data "${mntpnt}/$TESTFILE1" "${mntpnt}/$TESTFILE2"
+
+	typeset relative_path=""
+	if [[ ${orig_fs} == *"/"* ]]; then
+		relative_path=${orig_fs#*/}
+	fi
+
+	typeset leaf_fs=${rst_root}/${relative_path}
+	leaf_fs=${leaf_fs%/}
+	rst_snap=${leaf_fs}@snap
+
+	set -A rst_snap "$rst_root/$TESTFS@init_snap" "$rst_root/$TESTFS@inc_snap"
+	set -A rst_snap2 "${leaf_fs}@init_snap" "${leaf_fs}@inc_snap"
+	set -A rst_data "$TESTDIR1/$TESTFS/$TESTFILE1" "$TESTDIR1/$TESTFS/$TESTFILE2"
+	set -A rst_data2 "$TESTDIR1/${relative_path}/$TESTFILE1" "$TESTDIR1/${relative_path}/$TESTFILE2"
+
+	typeset -i i=0
+	while (( i < ${#orig_snap[*]} )); do
+		$FILE_WRITE -o create -f ${orig_data[$i]} -b 512 \
+		    -c 8 >/dev/null 2>&1
+		(( $? != 0 )) && \
+			log_fail "Writing data into zfs filesystem fails."
+		log_must $ZFS snapshot ${orig_snap[$i]}
+		if (( i < 1 )); then
+			log_must eval "$ZFS send ${orig_snap[$i]} > ${bkup[$i]}"
+		else
+			log_must eval "$ZFS send -i ${orig_snap[(( i - 1 ))]} \
+				${orig_snap[$i]} > ${bkup[$i]}"
+		fi
+
+		(( i = i + 1 ))
+	done
+
+	log_note "Verifying 'zfs receive <filesystem>' works."
+	i=0
+	while (( i < ${#bkup[*]} )); do
+		if (( i > 0 )); then
+			log_must $ZFS rollback ${rst_snap[0]}
+		fi
+		log_must eval "$ZFS receive $rst_fs < ${bkup[$i]}"
+		snapexists ${rst_snap[$i]} || \
+			log_fail "Restoring filesystem fails. ${rst_snap[$i]} not exist"
+		compare_cksum ${orig_data[$i]} ${rst_data[$i]}
+
+		(( i = i + 1 ))
+	done
+
+	log_must $ZFS destroy -Rf $rst_fs
+
+	log_note "Verifying 'zfs receive <snapshot>' works."
+	i=0
+	while (( i < ${#bkup[*]} )); do
+		if (( i > 0 )); then
+			log_must $ZFS rollback ${rst_snap[0]}
+		fi
+		log_must eval "$ZFS receive ${rst_snap[$i]} <${bkup[$i]}"
+		snapexists ${rst_snap[$i]} || \
+			log_fail "Restoring filesystem fails. ${rst_snap[$i]} not exist"
+		compare_cksum ${orig_data[$i]} ${rst_data[$i]}
+
+		(( i = i + 1 ))
+	done
+
+	log_must $ZFS destroy -Rf $rst_fs
+
+	log_note "Verfiying 'zfs receive -d <filesystem>' works."
+
+	i=0
+	while (( i < ${#bkup[*]} )); do
+		if (( i > 0 )); then
+			log_must $ZFS rollback ${rst_snap2[0]}
+		fi
+		log_must eval "$ZFS receive -d -F $rst_root <${bkup[$i]}"
+		snapexists ${rst_snap2[$i]} || \
+			log_fail "Restoring filesystem fails. ${rst_snap2[$i]} not exist"
+		compare_cksum ${orig_data[$i]} ${rst_data2[$i]}
+
+		(( i = i + 1 ))
+	done
+
+	cleanup
+done
+
+log_pass "Verifying 'zfs receive [<filesystem|snapshot>] -d <filesystem>' succeeds."
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/usr/src/test/zfs-tests/tests/functional/cli_root/zfs_receive/zfs_receive_002_pos.ksh	Wed Dec 05 22:04:50 2012 -0500
@@ -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 2007 Sun Microsystems, Inc.  All rights reserved.
+# Use is subject to license terms.
+#
+
+. $STF_SUITE/tests/functional/cli_root/cli_common.kshlib
+
+#
+# DESCRIPTION:
+#	Verifying 'zfs receive <volume>' works.
+#
+# STRATEGY:
+#	1. Fill in volume with some data
+#	2. Create full and incremental send stream
+#	3. Restore the send stream
+#	4. Verify the restoring results.
+#
+
+verify_runnable "global"
+
+function cleanup
+{
+	typeset -i i=0
+	typeset ds
+
+	while (( i < ${#orig_snap[*]} )); do
+		snapexists ${rst_snap[$i]} && \
+			log_must $ZFS destroy -f ${rst_snap[$i]}
+		snapexists ${orig_snap[$i]} && \
+			log_must $ZFS destroy -f ${orig_snap[$i]}
+		[[ -e ${bkup[$i]} ]] && \
+			log_must $RM -rf ${bkup[$i]}
+
+		(( i = i + 1 ))
+	done
+
+	for ds in $rst_vol $rst_root; do
+		datasetexists $ds && \
+			log_must $ZFS destroy -Rf $ds
+	done
+}
+
+log_assert "Verifying 'zfs receive <volume>' works."
+log_onexit cleanup
+
+set -A orig_snap "$TESTPOOL/$TESTVOL@init_snap" "$TESTPOOL/$TESTVOL@inc_snap"
+set -A bkup "/var/tmp/fullbkup" "/var/tmp/incbkup"
+rst_root=$TESTPOOL/rst_ctr
+rst_vol=$rst_root/$TESTVOL
+set -A rst_snap "${rst_vol}@init_snap" "${rst_vol}@inc_snap"
+
+#
+# Preparations for testing
+#
+log_must $ZFS create $rst_root
+[[ ! -d $TESTDIR1 ]] && \
+	log_must $MKDIR -p $TESTDIR1
+log_must $ZFS set mountpoint=$TESTDIR1 $rst_root
+
+typeset -i i=0
+while (( i < ${#orig_snap[*]} )); do
+	log_must $ZFS snapshot ${orig_snap[$i]}
+	if (( i < 1 )); then
+		log_must eval "$ZFS send ${orig_snap[$i]} > ${bkup[$i]}"
+	else
+		log_must eval "$ZFS send -i ${orig_snap[(( i - 1 ))]} \
+				${orig_snap[$i]} > ${bkup[$i]}"
+	fi
+
+	(( i = i + 1 ))
+done
+
+i=0
+while (( i < ${#bkup[*]} )); do
+	log_must eval "$ZFS receive $rst_vol < ${bkup[$i]}"
+	! datasetexists $rst_vol || ! snapexists ${rst_snap[$i]} && \
+		log_fail "Restoring volume fails."
+
+	(( i = i + 1 ))
+done
+
+log_pass "Verifying 'zfs receive <volume>' succeeds."
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/usr/src/test/zfs-tests/tests/functional/cli_root/zfs_receive/zfs_receive_003_pos.ksh	Wed Dec 05 22:04:50 2012 -0500
@@ -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.
+#
+
+. $STF_SUITE/include/libtest.shlib
+
+#
+# DESCRIPTION:
+#	'zfs recv -F' to force rollback.
+#
+# STRATEGY:
+#	1. Create pool and fs.
+#	2. Create some files in fs and take a snapshot1.
+#	3. Create another files in fs and take snapshot2.
+#	4. Create incremental stream from snapshot1 to snapshot2.
+#	5. fs rollback to snapshot1 and modify fs.
+#	6. Verify 'zfs recv -F' can force rollback.
+#
+
+verify_runnable "both"
+
+function cleanup
+{
+	for snap in $snap2 $snap1; do
+		datasetexists $snap && log_must $ZFS destroy -rf $snap
+	done
+	for file in $ibackup $mntpnt/file1 $mntpnt/file2; do
+		[[ -f $file ]] && log_must $RM -f $file
+	done
+}
+
+log_assert "'zfs recv -F' to force rollback."
+log_onexit cleanup
+
+ibackup=/var/tmp/ibackup.$$
+fs=$TESTPOOL/$TESTFS; snap1=$fs@snap1; snap2=$fs@snap2
+
+mntpnt=$(get_prop mountpoint $fs) || log_fail "get_prop mountpoint $fs"
+log_must $MKFILE 10m $mntpnt/file1
+log_must $ZFS snapshot $snap1
+log_must $MKFILE 10m $mntpnt/file2
+log_must $ZFS snapshot $snap2
+
+log_must eval "$ZFS send -i $snap1 $snap2 > $ibackup"
+
+log_note "Verify 'zfs receive' succeed, if filesystem was not modified."
+log_must $ZFS rollback -r $snap1
+log_must eval "$ZFS receive $fs < $ibackup"
+if [[ ! -f $mntpnt/file1 || ! -f $mntpnt/file2 ]]; then
+	log_fail "'$ZFS receive' failed."
+fi
+
+log_note "Verify 'zfs receive' failed if filesystem was modified."
+log_must $ZFS rollback -r $snap1
+log_must $RM -rf $mntpnt/file1
+log_mustnot eval "$ZFS receive $fs < $ibackup"
+
+# Verify 'zfs receive -F' to force rollback whatever filesystem was modified.
+log_must $ZFS rollback -r $snap1
+log_must $RM -rf $mntpnt/file1
+log_must eval "$ZFS receive -F $fs < $ibackup"
+if [[ ! -f $mntpnt/file1 || ! -f $mntpnt/file2 ]]; then
+	log_fail "'$ZFS receive -F' failed."
+fi
+
+log_pass "'zfs recv -F' to force rollback passed."
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/usr/src/test/zfs-tests/tests/functional/cli_root/zfs_receive/zfs_receive_004_neg.ksh	Wed Dec 05 22:04:50 2012 -0500
@@ -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) 2012 by Delphix. All rights reserved.
+#
+
+. $STF_SUITE/tests/functional/cli_root/cli_common.kshlib
+
+#
+# DESCRIPTION:
+#	Verify 'zfs receive' fails with malformed parameters.
+#
+# STRATEGY:
+#	1. Denfine malformed parameters array
+#	2. Feed the malformed parameters to 'zfs receive'
+#	3. Verify the command should be failed
+#
+
+verify_runnable "both"
+
+function cleanup
+{
+	typeset snap
+	typeset bkup
+
+	for snap in $init_snap $inc_snap $init_topsnap $inc_topsnap ; do
+		snapexists $snap && \
+			log_must $ZFS destroy -Rf $snap
+	done
+
+	for bkup in $full_bkup $inc_bkup $full_topbkup $inc_topbkup; do
+		[[ -e $bkup ]] && \
+			log_must $RM -f $bkup
+	done
+}
+
+log_assert "Verify that invalid parameters to 'zfs receive' are caught."
+log_onexit cleanup
+
+init_snap=$TESTPOOL/$TESTFS@initsnap
+inc_snap=$TESTPOOL/$TESTFS@incsnap
+full_bkup=/var/tmp/full_bkup.$$
+inc_bkup=/var/tmp/inc_bkup.$$
+
+init_topsnap=$TESTPOOL@initsnap
+inc_topsnap=$TESTPOOL@incsnap
+full_topbkup=/var/tmp/full_topbkup.$$
+inc_topbkup=/var/tmp/inc_topbkup.$$
+
+log_must $ZFS snapshot $init_topsnap
+log_must eval "$ZFS send $init_topsnap > $full_topbkup"
+log_must $TOUCH /$TESTPOOL/foo
+
+log_must $ZFS snapshot $inc_topsnap
+log_must eval "$ZFS send -i $init_topsnap $inc_topsnap > $inc_topbkup"
+log_must $TOUCH /$TESTPOOL/bar
+
+log_must $ZFS snapshot $init_snap
+log_must eval "$ZFS send $init_snap > $full_bkup"
+log_must $TOUCH /$TESTDIR/foo
+
+log_must $ZFS snapshot $inc_snap
+log_must eval "$ZFS send -i $init_snap $inc_snap > $inc_bkup"
+log_must $TOUCH /$TESTDIR/bar
+
+$SYNC
+
+set -A badargs \
+    "" "nonexistent-snap" "blah@blah" "-d" "-d nonexistent-dataset" \
+    "$TESTPOOL/$TESTFS" "$TESTPOOL1" "$TESTPOOL/fs@" "$TESTPOOL/fs@@mysnap" \
+    "$TESTPOOL/fs@@" "$TESTPOOL/fs/@mysnap" "$TESTPOOL/fs@/mysnap" \
+    "$TESTPOOL/nonexistent-fs/nonexistent-fs" "-d $TESTPOOL/nonexistent-fs" \
+    "-d $TESTPOOL/$TESTFS/nonexistent-fs"
+
+if is_global_zone ; then
+	typeset -i n=${#badargs[@]}
+	badargs[$n]="-d $TESTPOOL"
+fi
+
+typeset -i i=0
+while (( i < ${#badargs[*]} ))
+do
+	for bkup in $full_bkup $inc_bkup $full_topbkup $inc_topbkup ; do
+		log_mustnot eval "$ZFS receive ${badargs[i]} < $bkup"
+	done
+
+	(( i = i + 1 ))
+done
+
+log_pass "Invalid parameters to 'zfs receive' are caught as expected."
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/usr/src/test/zfs-tests/tests/functional/cli_root/zfs_receive/zfs_receive_005_neg.ksh	Wed Dec 05 22:04:50 2012 -0500
@@ -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 2007 Sun Microsystems, Inc.  All rights reserved.
+# Use is subject to license terms.
+#
+
+. $STF_SUITE/tests/functional/cli_root/cli_common.kshlib
+
+#
+# DESCRIPTION:
+#	Verify 'zfs receive' fails with unsupported scenarios.
+#	including:
+#	(1) Invalid send streams;
+#	(2) The received incremental send doesn't match the filesystem
+#	    latest status.
+#
+# STRATEGY:
+#	1. Preparation for unsupported scenarios
+#	2. Execute 'zfs receive'
+#	3. Verify the results are failed
+#
+
+verify_runnable "both"
+
+function cleanup
+{
+	typeset snap
+	typeset bkup
+
+	for snap in $init_snap $inc_snap; do
+		snapexists $snap && \
+			log_must $ZFS destroy -f $snap
+	done
+
+	datasetexists $rst_root && \
+		log_must $ZFS destroy -Rf $rst_root
+
+	for bkup in $full_bkup $inc_bkup; do
+		[[ -e $bkup ]] && \
+			log_must $RM -f $bkup
+	done
+}
+
+log_assert "Verify 'zfs receive' fails with unsupported scenarios."
+log_onexit cleanup
+
+init_snap=$TESTPOOL/$TESTFS@initsnap
+inc_snap=$TESTPOOL/$TESTFS@incsnap
+rst_root=$TESTPOOL/rst_ctr
+rst_init_snap=$rst_root/$TESTFS@init_snap
+rst_inc_snap=$rst_root/$TESTFS@inc_snap
+full_bkup=/var/tmp/full_bkup.$$
+inc_bkup=/var/tmp/inc_bkup.$$
+
+log_must $ZFS create $rst_root
+log_must $ZFS snapshot $init_snap
+log_must eval "$ZFS send $init_snap > $full_bkup"
+
+log_note "'zfs receive' fails with invalid send streams."
+log_mustnot eval "$ZFS receive $rst_init_snap < /dev/zero"
+log_mustnot eval "$ZFS receive -d $rst_root </dev/zero"
+
+log_must eval "$ZFS receive $rst_init_snap < $full_bkup"
+
+log_note "Unmatched send stream with restoring filesystem" \
+	" cannot be received."
+log_must $ZFS snapshot $inc_snap
+log_must eval "$ZFS send -i $init_snap $inc_snap > $inc_bkup"
+#make changes on the restoring filesystem
+log_must $TOUCH $ZFSROOT/$rst_root/$TESTFS/tmpfile
+log_mustnot eval "$ZFS receive $rst_inc_snap < $inc_bkup"
+log_mustnot eval "$ZFS receive -d $rst_root < $inc_bkup"
+
+log_pass "Unsupported scenarios to 'zfs receive' fail as expected."
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/usr/src/test/zfs-tests/tests/functional/cli_root/zfs_receive/zfs_receive_006_pos.ksh	Wed Dec 05 22:04:50 2012 -0500
@@ -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 2007 Sun Microsystems, Inc.  All rights reserved.
+# Use is subject to license terms.
+#
+
+. $STF_SUITE/include/libtest.shlib
+
+#
+# DESCRIPTION:
+#	'zfs recv -d <fs>' should create ancestor filesystem if it does not
+#   exist and it should not fail if it exists
+#
+# STRATEGY:
+#	1. Create pool and fs.
+#	2. Create some files in fs and take snapshots.
+#	3. Keep the stream and restore the stream to the pool
+#	4. Verify receiving the stream succeeds, and the ancestor filesystem
+#	   is created if it did not exist
+#	5. Verify receiving the stream still succeeds when ancestor filesystem
+#	   exists
+#
+
+verify_runnable "both"
+
+function cleanup
+{
+	for snap in $snap2 $snap1; do
+		datasetexists $snap && log_must $ZFS destroy -rf $snap
+	done
+	for file in $fbackup1 $fbackup2 $mntpnt/file1 $mntpnt/file2; do
+		[[ -f $file ]] && log_must $RM -f $file
+	done
+
+	if is_global_zone; then
+		datasetexists $TESTPOOL/$TESTFS/$TESTFS1 && \
+			log_must $ZFS destroy -rf $TESTPOOL/$TESTFS/$TESTFS1
+	else
+		datasetexists $TESTPOOL/${ZONE_CTR}0 && \
+			log_must $ZFS destroy -rf $TESTPOOL/${ZONE_CTR}0
+	fi
+
+}
+
+log_assert "'zfs recv -d <fs>' should succeed no matter ancestor filesystem \
+	exists."
+log_onexit cleanup
+
+ancestor_fs=$TESTPOOL/$TESTFS
+fs=$TESTPOOL/$TESTFS/$TESTFS1
+snap1=$fs@snap1
+snap2=$fs@snap2
+fbackup1=/var/tmp/fbackup1.$$
+fbackup2=/var/tmp/fbackup2.$$
+
+datasetexists $ancestor_fs || \
+	log_must $ZFS create $ancestor_fs
+log_must $ZFS create $fs
+
+mntpnt=$(get_prop mountpoint $fs) || log_fail "get_prop mountpoint $fs"
+log_must $MKFILE 10m $mntpnt/file1
+log_must $ZFS snapshot $snap1
+log_must $MKFILE 10m $mntpnt/file2
+log_must $ZFS snapshot $snap2
+
+log_must eval "$ZFS send $snap1 > $fbackup1"
+log_must eval "$ZFS send $snap2 > $fbackup2"
+
+log_note "Verify 'zfs receive -d' succeed and create ancestor filesystem \
+	 if it did not exist. "
+log_must $ZFS destroy -rf $ancestor_fs
+log_must eval "$ZFS receive -d $TESTPOOL < $fbackup1"
+is_global_zone || ancestor_fs=$TESTPOOL/${ZONE_CTR}0/$TESTFS
+datasetexists $ancestor_fs || \
+	log_fail "ancestor filesystem is not created"
+
+log_note "Verify 'zfs receive -d' still succeed if ancestor filesystem exists"
+is_global_zone || fs=$TESTPOOL/${ZONE_CTR}0/$TESTFS/$TESTFS1
+log_must $ZFS destroy -rf $fs
+log_must eval "$ZFS receive -d $TESTPOOL < $fbackup2"
+
+log_pass "'zfs recv -d <fs>' should succeed no matter ancestor filesystem \
+	exists."
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/usr/src/test/zfs-tests/tests/functional/cli_root/zfs_receive/zfs_receive_007_neg.ksh	Wed Dec 05 22:04:50 2012 -0500
@@ -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 2007 Sun Microsystems, Inc.  All rights reserved.
+# Use is subject to license terms.
+#
+
+. $STF_SUITE/include/libtest.shlib
+
+#
+# DESCRIPTION:
+#	'zfs recv -F' should fail if the incremental stream does not match
+#
+# STRATEGY:
+#	1. Create pool and fs.
+#	2. Create some files in fs and take snapshots.
+#	3. Keep the incremental stream and restore the stream to the pool
+#	4. Verify receiving the stream fails
+#
+
+verify_runnable "both"
+
+function cleanup
+{
+	for snap in $snap2 $snap1; do
+		datasetexists $snap && log_must $ZFS destroy -rf $snap
+	done
+	for file in $ibackup $mntpnt/file1 $mntpnt/file2; do
+		[[ -f $file ]] && log_must $RM -f $file
+	done
+}
+
+log_assert "'zfs recv -F' should fail if the incremental stream does not match"
+log_onexit cleanup
+
+fs=$TESTPOOL/$TESTFS
+snap1=$fs@snap1
+snap2=$fs@snap2
+ibackup=/var/tmp/ibackup.$$
+
+datasetexists $fs || log_must $ZFS create $fs
+
+mntpnt=$(get_prop mountpoint $fs) || log_fail "get_prop mountpoint $fs"
+log_must $MKFILE 10m $mntpnt/file1
+log_must $ZFS snapshot $snap1
+log_must $MKFILE 10m $mntpnt/file2
+log_must $ZFS snapshot $snap2
+
+log_must eval "$ZFS send -i $snap1 $snap2 > $ibackup"
+
+log_must $ZFS destroy $snap1
+log_must $ZFS destroy $snap2
+log_mustnot eval "$ZFS receive -F $fs < $ibackup"
+
+log_must $MKFILE 20m $mntpnt/file1
+log_must $RM -rf $mntpnt/file2
+log_must $ZFS snapshot $snap1
+log_mustnot eval "$ZFS receive -F $snap2 < $ibackup"
+
+log_pass "'zfs recv -F' should fail if the incremental stream does not match"
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/usr/src/test/zfs-tests/tests/functional/cli_root/zfs_receive/zfs_receive_008_pos.ksh	Wed Dec 05 22:04:50 2012 -0500
@@ -0,0 +1,144 @@
+#!/bin/ksh -p
+#
+# CDDL HEADER START
+#
+# The contents of this file are subject to the terms of the
+# Common Development and Distribution License (the "License").
+# You may not use this file except in compliance with the License.
+#
+# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
+# or http://www.opensolaris.org/os/licensing.
+# See the License for the specific language governing permissions
+# and limitations under the License.
+#
+# When distributing Covered Code, include this CDDL HEADER in each
+# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
+# If applicable, add the following below this CDDL 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.
+#
+
+. $STF_SUITE/tests/functional/cli_root/cli_common.kshlib
+
+#
+# DESCRIPTION:
+#	Verifying 'zfs receive -vn [<filesystem|snapshot>]
+#		   and zfs receive -vn -d <filesystem>'
+#
+# STRATEGY:
+#	1. Fill in fs with some data
+#	2. Create full and incremental send stream
+#	3. run zfs receive with -v option
+#	3. Dryrun zfs receive with -vn option
+#	3. Dryrun zfs receive with -vn -d option
+#	4. Verify receive output and result
+#
+function cleanup
+{
+	for dset in $rst_snap $rst_fs $orig_snap; do
+		if datasetexists $dset; then
+			log_must $ZFS destroy -fr $dset
+		fi
+	done
+
+	for file in $fbackup $mnt_file $tmp_out; do
+		if [[ -f $file ]]; then
+			log_must $RM -f $file
+		fi
+	done
+
+	if datasetexists $TESTPOOL/$TESTFS; then
+		log_must $ZFS destroy -Rf $TESTPOOL/$TESTFS
+		log_must $ZFS create $TESTPOOL/$TESTFS
+		log_must $ZFS set mountpoint=$TESTDIR $TESTPOOL/$TESTFS
+	fi
+}
+
+verify_runnable "both"
+log_assert "Verifying 'zfs receive -vn [<filesystem|snapshot>] " \
+		"and zfs receive -vn -d <filesystem>'"
+
+log_onexit cleanup
+
+typeset datasets="$TESTPOOL/$TESTFS $TESTPOOL"
+typeset rst_fs=$TESTPOOL/$TESTFS/$TESTFS
+typeset fbackup=/var/tmp/fbackup.$$
+typeset tmp_out=/var/tmp/tmpout.$$
+
+for orig_fs in $datasets ; do
+	typeset rst_snap=$rst_fs@snap
+	typeset orig_snap=$orig_fs@snap
+	typeset verb_msg="receiving full stream of ${orig_snap} into ${rst_snap}"
+	typeset dryrun_msg="would receive full stream of ${orig_snap} into ${rst_snap}"
+
+	if ! datasetexists $orig_fs; then
+		log_must $ZFS create $orig_fs
+	fi
+
+	typeset mntpnt
+	mntpnt=$(get_prop mountpoint $orig_fs)
+	if [[ $? -ne 0 ]] ; then
+		log_fail "get_prop mountpoint $orig_fs failed"
+	fi
+
+	typeset mnt_file=$mntpnt/file1
+
+	log_must $MKFILE 100m $mnt_file
+	log_must $ZFS snapshot $orig_snap
+	log_must eval "$ZFS send $orig_snap > $fbackup"
+
+	for opt in "-v"  "-vn"; do
+		if datasetexists $rst_fs; then
+			log_must $ZFS destroy -fr $rst_fs
+		fi
+		log_note "Check ZFS receive $opt [<filesystem|snapshot>]"
+		log_must eval "$ZFS receive $opt $rst_fs < $fbackup > $tmp_out 2>&1"
+		if [[ $opt == "-v" ]]; then
+			log_must eval "$GREP \"$verb_msg\" $tmp_out >/dev/null 2>&1"
+			if ! datasetexists $rst_snap; then
+				log_fail "dataset was not received, even though the"\
+					" -v flag was used."
+			fi
+		else
+			log_must eval "$GREP \"$dryrun_msg\" $tmp_out >/dev/null 2>&1"
+			if datasetexists $rst_snap; then
+				log_fail "dataset was received, even though the -nv"\
+					" flag was used."
+			fi
+		fi
+	done
+
+	log_note "Check ZFS receive -vn -d <filesystem>"
+	if ! datasetexists $rst_fs; then
+		log_must $ZFS create $rst_fs
+	fi
+	log_must eval "$ZFS receive -vn -d -F $rst_fs <$fbackup >$tmp_out 2>&1"
+	typeset relative_path=""
+	if [[ ${orig_fs} == *"/"* ]]; then
+		relative_path=${orig_fs#*/}
+	fi
+
+	typeset leaf_fs=${rst_fs}/${relative_path}
+	leaf_fs=${leaf_fs%/}
+	rst_snap=${leaf_fs}@snap
+	dryrun_msg="would receive full stream of ${orig_snap} into ${rst_snap}"
+
+	log_must eval "$GREP \"$dryrun_msg\" $tmp_out > /dev/null 2>&1"
+
+	if datasetexists $rst_snap; then
+		log_fail "dataset $rst_snap should not existed."
+	fi
+	log_must $ZFS destroy -Rf $rst_fs
+
+	cleanup
+done
+
+log_pass "zfs receive -vn [<filesystem|snapshot>] and " \
+	"zfs receive -vn -d <filesystem>' succeed."
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/usr/src/test/zfs-tests/tests/functional/cli_root/zfs_receive/zfs_receive_009_neg.ksh	Wed Dec 05 22:04:50 2012 -0500
@@ -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 2007 Sun Microsystems, Inc.  All rights reserved.
+# Use is subject to license terms.
+#
+
+. $STF_SUITE/tests/functional/cli_root/cli_common.kshlib
+
+#
+# DESCRIPTION:
+#	Verify 'zfs receive' fails with bad options, missing argument or too many
+#	arguments.
+#
+# STRATEGY:
+#	1. Set a array of illegal arguments
+#	2. Execute 'zfs receive' with illegal arguments
+#	3. Verify the command should be failed
+#
+
+verify_runnable "both"
+
+function cleanup
+{
+	typeset ds
+
+	if snapexists $snap; then
+		log_must $ZFS destroy $snap
+	fi
+	for ds in $ctr1 $ctr2 $fs1; do
+		if datasetexists $ds; then
+			log_must $ZFS destroy -rf $ds
+		fi
+	done
+	if [[ -d $TESTDIR2 ]]; then
+		$RM -rf $TESTDIR2
+	fi
+}
+
+log_assert "Verify 'zfs receive' fails with bad option, missing or too many arguments"
+log_onexit cleanup
+
+set -A badopts "v" "n" "F" "d" "-V" "-N" "-f" "-D" "-VNfD" "-vNFd" "-vnFD" "-dVnF" \
+		"-vvvNfd" "-blah" "-12345" "-?" "-*" "-%"
+set -A validopts "" "-v" "-n" "-F" "-vn" "-nF" "-vnF" "-vd" "-nd" "-Fd" "-vnFd"
+
+ctr1=$TESTPOOL/$TESTCTR1
+ctr2=$TESTPOOL/$TESTCTR2
+fs1=$TESTPOOL/$TESTFS1
+fs2=$TESTPOOL/$TESTFS2
+fs3=$TESTPOOL/$TESTFS3
+snap=$TESTPOOL/$TESTFS@$TESTSNAP
+bkup=$TESTDIR2/bkup.$$
+
+# Preparations for negative testing
+for ctr in $ctr1 $ctr2; do
+	log_must $ZFS create $ctr
+done
+if [[ -d $TESTDIR2 ]]; then
+	$RM -rf $TESTDIR2
+fi
+log_must $ZFS create -o mountpoint=$TESTDIR2 $fs1
+log_must $ZFS snapshot $snap
+log_must eval "$ZFS send $snap > $bkup"
+
+#Testing zfs receive fails with input from terminal
+log_mustnot eval "$ZFS recv $fs3 </dev/console"
+
+# Testing with missing argument and too many arguments
+typeset -i i=0
+while (( i < ${#validopts[*]} )); do
+	log_mustnot eval "$ZFS recv < $bkup"
+
+	$ECHO ${validopts[i]} | $GREP "d" >/dev/null 2>&1
+	if (( $? != 0 )); then
+		log_mustnot eval "$ZFS recv ${validopts[i]} $fs2 $fs3 < $bkup"
+	else
+		log_mustnot eval "$ZFS recv ${validopts[i]} $ctr1 $ctr2 < $bkup"
+	fi
+
+	(( i += 1 ))
+done
+
+# Testing with bad options
+i=0
+while (( i < ${#badopts[*]} ))
+do
+	log_mustnot eval "$ZFS recv ${badopts[i]} $ctr1 < $bkup"
+	log_mustnot eval "$ZFS recv ${badopts[i]} $fs2 < $bkup"
+
+	(( i = i + 1 ))
+done
+
+log_pass "'zfs receive' as expected with bad options, missing or too many arguments."
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/usr/src/test/zfs-tests/tests/functional/cli_root/zfs_rename/Makefile	Wed Dec 05 22:04:50 2012 -0500
@@ -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) 2012 by Delphix. All rights reserved.
+#
+
+include $(SRC)/Makefile.master
+
+ROOTOPTPKG = $(ROOT)/opt/zfs-tests
+TESTDIR = $(ROOTOPTPKG)/tests/functional/cli_root/zfs_rename
+
+PROGS = cleanup \
+	setup \
+	zfs_rename_001_pos \
+	zfs_rename_002_pos \
+	zfs_rename_003_pos \
+	zfs_rename_004_neg \
+	zfs_rename_005_neg \
+	zfs_rename_006_pos \
+	zfs_rename_007_pos \
+	zfs_rename_008_pos \
+	zfs_rename_009_neg \
+	zfs_rename_010_neg \
+	zfs_rename_011_pos \
+	zfs_rename_012_neg \
+	zfs_rename_013_pos
+
+FILES = zfs_rename.cfg \
+	zfs_rename.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	Thu Jan 01 00:00:00 1970 +0000
+++ b/usr/src/test/zfs-tests/tests/functional/cli_root/zfs_rename/cleanup.ksh	Wed Dec 05 22:04:50 2012 -0500
@@ -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.
+#
+
+. $STF_SUITE/include/libtest.shlib
+
+default_cleanup_noexit
+
+if [[ -d $TESTDIR2 ]]; then
+        $RM -rf $TESTDIR2
+        if (( $? != 0 )); then
+                log_unresolved Could not remove $TESTDIR2
+        fi
+fi
+
+log_pass
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/usr/src/test/zfs-tests/tests/functional/cli_root/zfs_rename/setup.ksh	Wed Dec 05 22:04:50 2012 -0500
@@ -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) 2012 by Delphix. All rights reserved.
+#
+
+. $STF_SUITE/include/libtest.shlib
+. $STF_SUITE/tests/functional/cli_root/zfs_rename/zfs_rename.kshlib
+
+DISK=${DISKS%% *}
+
+default_setup_noexit "$DISK" "true" "true"
+
+if [[ -d $TESTDIR2 ]]; then
+	$RM -rf $TESTDIR2
+	if (( $? != 0 )); then
+		log_unresolved Could not remove $TESTDIR2
+	fi
+fi
+log_must $ZFS create $TESTPOOL/$DATAFS
+log_must $ZFS set mountpoint=$TESTDIR2 $TESTPOOL/$DATAFS
+log_must eval "$DD if=$IF of=$OF bs=$BS count=$CNT >/dev/null 2>&1"
+
+log_pass
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/usr/src/test/zfs-tests/tests/functional/cli_root/zfs_rename/zfs_rename.cfg	Wed Dec 05 22:04:50 2012 -0500
@@ -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 2007 Sun Microsystems, Inc.  All rights reserved.
+# Use is subject to license terms.
+#
+
+#
+# Copyright (c) 2012 by Delphix. All rights reserved.
+#
+
+export DATAFS=datafs.rename
+export DATA=$TESTDIR2/data.rename
+export IF=/dev/urandom
+export OF=$DATA
+export BS=512
+export CNT=2048
+export VOL_R_PATH=/dev/zvol/rdsk/$TESTPOOL/$TESTVOL
+export VOLDATA=$TESTDIR2/voldata.rename
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/usr/src/test/zfs-tests/tests/functional/cli_root/zfs_rename/zfs_rename.kshlib	Wed Dec 05 22:04:50 2012 -0500
@@ -0,0 +1,123 @@
+#
+# CDDL HEADER START
+#
+# The contents of this file are subject to the terms of the
+# Common Development and Distribution License (the "License").
+# You may not use this file except in compliance with the License.
+#
+# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
+# or http://www.opensolaris.org/os/licensing.
+# See the License for the specific language governing permissions
+# and limitations under the License.
+#
+# When distributing Covered Code, include this CDDL HEADER in each
+# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
+# If applicable, add the following below this CDDL HEADER, with the
+# fields enclosed by brackets "[]" replaced with your own identifying
+# information: Portions Copyright [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.
+#
+
+. $STF_SUITE/tests/functional/cli_root/zfs_rename/zfs_rename.cfg
+
+function additional_setup
+{
+	# Create testfile
+	log_must $CP $DATA $TESTDIR/$TESTFILE0
+	log_must $CP $DATA $TESTDIR1/$TESTFILE0
+
+	# Create snapshot
+	if ! snapexists $TESTPOOL/$TESTFS@snapshot; then
+		log_must $ZFS snapshot $TESTPOOL/$TESTFS@snapshot
+		log_must $ZFS clone $TESTPOOL/$TESTFS@snapshot \
+		    $TESTPOOL/$TESTFS-clone
+	fi
+
+	# Create file system
+	datasetexists $TESTPOOL/$TESTFS1 || \
+		log_must $ZFS create $TESTPOOL/$TESTFS1
+
+	# Create testfile
+	log_must $CP $DATA $(get_prop mountpoint $TESTPOOL/$TESTFS1)/$TESTFILE0
+
+	# Create container
+	datasetexists $TESTPOOL/$TESTCTR1 || \
+		log_must $ZFS create $TESTPOOL/$TESTCTR1
+	log_must $CP $DATA $(get_prop mountpoint $TESTPOOL/$TESTCTR1)/$TESTFILE0
+
+	# Create data in zvol
+	if is_global_zone; then
+		log_must eval "$DD if=$DATA of=$VOL_R_PATH bs=$BS count=$CNT \
+				>/dev/null 2>&1"
+	else
+		log_must $CP $DATA $(get_prop mountpoint $TESTPOOL/$TESTVOL)/$TESTFILE0
+	fi
+
+}
+
+function rename_dataset # src dest
+{
+	typeset src=$1
+	typeset dest=$2
+
+	log_must $ZFS rename $src $dest
+
+	#
+	# Verify src name no longer in use
+	#
+	log_mustnot datasetexists $src
+	log_must datasetexists $dest
+}
+
+function cleanup
+{
+	typeset -i i=0
+	while ((i < ${#dataset[*]} )); do
+		if ! datasetexists ${dataset[i]}-new ; then
+			((i = i + 1))
+			continue
+		fi
+
+                if [[ ${dataset[i]}-new != *@* ]] ; then
+                        $ZFS rename ${dataset[i]}-new ${dataset[i]}
+                        if [[ $? -ne 0 ]]; then
+                                typeset newfs=${dataset[i]}-new
+                                typeset oldfs=${dataset[i]}
+                                typeset mntp=$(get_prop mountpoint  $newfs)
+                                log_must $ZFS destroy -f $newfs
+                                log_must $ZFS create -p $oldfs
+                                log_must $ZFS set mountpoint=$mntp $oldfs
+                        fi
+                else
+                        log_must $ZFS destroy -fR ${dataset[i]}-new
+                fi
+
+                ((i = i + 1))
+	done
+
+	if snapexists $TESTPOOL/$TESTFS@snapshot; then
+		log_must $ZFS destroy -fR $TESTPOOL/$TESTFS@snapshot
+	fi
+
+}
+
+function cmp_data #<$1 src data, $2 tgt data>
+{
+        typeset src=$1
+        typeset tgt=$2
+
+        $CMP $src $tgt >/dev/null 2>&1
+
+        return $?
+}
+
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/usr/src/test/zfs-tests/tests/functional/cli_root/zfs_rename/zfs_rename_001_pos.ksh	Wed Dec 05 22:04:50 2012 -0500
@@ -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 2007 Sun Microsystems, Inc.  All rights reserved.
+# Use is subject to license terms.
+#
+. $STF_SUITE/include/libtest.shlib
+. $STF_SUITE/tests/functional/cli_root/zfs_rename/zfs_rename.kshlib
+
+#
+# DESCRIPTION:
+#       'zfs rename' should successfully rename valid datasets.
+#       As a sub-assertion we check to ensure the datasets that can
+#       be mounted are mounted.
+#
+# STRATEGY:
+#       1. Given a file system, snapshot and volume.
+#       2. Rename each dataset object to a new name.
+#       3. Verify that only the new name is displayed by zfs list.
+#       4. Verify mountable datasets are mounted.
+#
+###############################################################################
+
+verify_runnable "both"
+
+set -A dataset "$TESTPOOL/$TESTFS@snapshot" "$TESTPOOL/$TESTFS1" \
+   "$TESTPOOL/$TESTCTR/$TESTFS1" "$TESTPOOL/$TESTCTR1" \
+    "$TESTPOOL/$TESTVOL" "$TESTPOOL/$TESTFS-clone"
+set -A mountable "$TESTPOOL/$TESTFS1-new" "$TESTPOOL/$TESTFS@snapshot-new" \
+    "$TESTPOOL/$TESTCTR/$TESTFS1-new" "$TESTPOOL/$TESTFS-clone-new"
+
+#
+# cleanup defined in zfs_rename.kshlib
+#
+log_onexit cleanup
+
+log_assert "'zfs rename' should successfully rename valid datasets"
+
+additional_setup
+
+typeset -i i=0
+while (( i < ${#dataset[*]} )); do
+	rename_dataset ${dataset[i]} ${dataset[i]}-new
+
+	((i = i + 1))
+done
+
+log_note "Verify mountable datasets are mounted in their new namespace."
+typeset mtpt
+i=0
+while (( i < ${#mountable[*]} )); do
+	# Snapshot have no mountpoint
+	if [[ ${mountable[i]} != *@* ]]; then
+		log_must mounted ${mountable[i]}
+		mtpt=$(get_prop mountpoint ${mountable[i]})
+	else
+		mtpt=$(snapshot_mountpoint ${mountable[i]})
+	fi
+
+	if ! cmp_data $DATA $mtpt/$TESTFILE0 ; then
+		log_fail "$mtpt/$TESTFILE0 gets corrupted after rename operation."
+	fi
+
+	((i = i + 1))
+done
+
+#verify the data integrity in zvol
+if is_global_zone; then
+	log_must eval "$DD if=${VOL_R_PATH}-new of=$VOLDATA bs=$BS count=$CNT >/dev/null 2>&1"
+	if ! cmp_data $VOLDATA $DATA ; then
+		log_fail "$VOLDATA gets corrupted after rename operation."
+	fi
+fi
+
+# rename back fs
+typeset -i i=0
+while ((i < ${#dataset[*]} )); do
+	if datasetexists ${dataset[i]}-new ; then
+                log_must $ZFS rename ${dataset[i]}-new ${dataset[i]}
+	fi
+        ((i = i + 1))
+done
+
+log_pass "'zfs rename' successfully renamed each dataset type."
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/usr/src/test/zfs-tests/tests/functional/cli_root/zfs_rename/zfs_rename_002_pos.ksh	Wed Dec 05 22:04:50 2012 -0500
@@ -0,0 +1,87 @@
+#!/bin/ksh -p
+#
+# CDDL HEADER START
+#
+# The contents of this file are subject to the terms of the
+# Common Development and Distribution License (the "License").
+# You may not use this file except in compliance with the License.
+#
+# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
+# or http://www.opensolaris.org/os/licensing.
+# See the License for the specific language governing permissions
+# and limitations under the License.
+#
+# When distributing Covered Code, include this CDDL HEADER in each
+# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
+# If applicable, add the following below this CDDL HEADER, with the
+# fields enclosed by brackets "[]" replaced with your own identifying
+# information: Portions Copyright [yyyy] [name of copyright owner]
+#
+# CDDL HEADER END
+#
+
+#
+# Copyright 2007 Sun Microsystems, Inc.  All rights reserved.
+# Use is subject to license terms.
+#
+. $STF_SUITE/include/libtest.shlib
+. $STF_SUITE/tests/functional/cli_root/zfs_rename/zfs_rename.kshlib
+
+#
+# DESCRIPTION:
+#       'zfs rename' should successfully be capable of renaming
+#       valid datasets back and forth multiple times.
+#
+# STRATEGY:
+#       1. Given a file system, snapshot and volume.
+#       2. Rename each dataset object to a new name.
+#       3. Rename each dataset back to its original name.
+#       4. Repeat steps 2 and 3 multiple times.
+#       5. Verify that the correct name is displayed by zfs list.
+#
+###############################################################################
+
+verify_runnable "both"
+
+set -A dataset "$TESTPOOL/$TESTFS@snapshot" "$TESTPOOL/$TESTFS1" \
+   "$TESTPOOL/$TESTCTR/$TESTFS1" "$TESTPOOL/$TESTCTR1" \
+    "$TESTPOOL/$TESTVOL" "$TESTPOOL/$TESTFS-clone"
+
+#
+# cleanup defined in zfs_rename.kshlib
+#
+log_onexit cleanup
+
+log_assert "'zfs rename' should successfully rename valid datasets"
+
+additional_setup
+
+typeset -i i=0
+typeset -i iters=10
+
+while ((i < ${#dataset[*]} )); do
+	j=0
+	while ((j < iters )); do
+		rename_dataset ${dataset[i]} ${dataset[i]}-new
+		rename_dataset ${dataset[i]}-new ${dataset[i]}
+
+		((j = j + 1))
+	done
+
+	if [[ ${dataset[i]} == *@* ]]; then
+		data=$(snapshot_mountpoint ${dataset[i]})/$TESTFILE0
+	elif [[ ${dataset[i]} == "$TESTPOOL/$TESTVOL" ]] && is_global_zone; then
+		log_must eval "$DD if=$VOL_R_PATH of=$VOLDATA bs=$BS count=$CNT >/dev/null 2>&1"
+		data=$VOLDATA
+	else
+		data=$(get_prop mountpoint ${dataset[i]})/$TESTFILE0
+	fi
+
+	if ! cmp_data $DATA $data; then
+		log_fail "$data gets corrupted after $iters times rename operations."
+	fi
+
+	((i = i + 1))
+done
+
+log_pass "'zfs rename' renamed each dataset type multiple times as expected."
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/usr/src/test/zfs-tests/tests/functional/cli_root/zfs_rename/zfs_rename_003_pos.ksh	Wed Dec 05 22:04:50 2012 -0500
@@ -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.
+#
+
+. $STF_SUITE/include/libtest.shlib
+
+#
+# DESCRIPTION:
+#	'zfs rename' can address the abbreviated snapshot name.
+#
+# STRATEGY:
+#	1. Create pool, fs and snap.
+#	2. Verify 'zfs rename' support the abbreviated snapshot name.
+#
+
+verify_runnable "both"
+
+function cleanup
+{
+	datasetexists $snap && log_must $ZFS destroy $snap
+}
+
+log_assert "'zfs rename' can address the abbreviated snapshot name."
+log_onexit cleanup
+
+fs=$TESTPOOL/$TESTFS; snap=$fs@snap
+set -A newname "$fs@new-snap" "@new-snap" "new-snap"
+
+log_must $ZFS snapshot $snap
+log_must datasetexists $snap
+
+typeset -i i=0
+while ((i < ${#newname[*]} )); do
+        log_must $ZFS rename $snap ${newname[$i]}
+	log_must datasetexists ${snap%%@*}@${newname[$i]##*@}
+	log_must $ZFS rename ${snap%%@*}@${newname[$i]##*@} $snap
+
+	((i += 1))
+done
+
+log_pass "'zfs rename' address the abbreviated snapshot name passed."
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/usr/src/test/zfs-tests/tests/functional/cli_root/zfs_rename/zfs_rename_004_neg.ksh	Wed Dec 05 22:04:50 2012 -0500
@@ -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.
+#
+. $STF_SUITE/include/libtest.shlib
+. $STF_SUITE/tests/functional/cli_root/zfs_rename/zfs_rename.kshlib
+
+#
+# DESCRIPTION:
+#       'zfs rename' should fail when this dataset was changed to an existed
+#	dataset name or datasets are of different types.
+#       For example, a filesystem cannot be renamed as a volume.
+#
+# STRATEGY:
+#       1. Given a file system, snapshot and volume.
+#       2. Rename each dataset object to a different type.
+#       3. Verify that only the original name is displayed by zfs list.
+#
+
+verify_runnable "both"
+
+#
+# This array is a list of pairs:
+#	item i: original type
+#	item i + 1: new type
+#
+set -A bad_dataset $TESTPOOL/$TESTFS1 $TESTPOOL/$TESTCTR1 \
+	$TESTPOOL/$TESTFS1 $TESTPOOL/$TESTCTR/$TESTFS1 \
+	$TESTPOOL/$TESTFS1 $TESTPOOL/$TESTVOL \
+	$TESTPOOL/$TESTFS1 $TESTPOOL/$TESTFS1/$TESTFS1 \
+	$TESTPOOL/$TESTFS1 $TESTPOOL/$TESTFS@snapshot \
+	$TESTPOOL/$TESTCTR1 $TESTPOOL/$TESTVOL \
+	$TESTPOOL/$TESTCTR1 $TESTPOOL/$TESTFS@snapshot \
+	$TESTPOOL/$TESTCTR1 $TESTPOOL/$TESTFS1 \
+	$TESTPOOL/$TESTCTR1 $TESTPOOL/$TESTCTR/$TESTFS1 \
+	$TESTPOOL/$TESTCTR/$TESTFS1  $TESTPOOL/$TESTVOL \
+	$TESTPOOL/$TESTCTR/$TESTFS1  $TESTPOOL/$TESTFS@snapshot \
+	$TESTPOOL/$TESTCTR/$TESTFS1  $TESTPOOL/$TESTFS1 \
+	$TESTPOOL/$TESTCTR/$TESTFS1  $TESTPOOL/$TESTCTR1 \
+	$TESTPOOL/$TESTVOL $TESTPOOL/$TESTCTR1 \
+	$TESTPOOL/$TESTVOL $TESTPOOL/$TESTFS@snapshot \
+	$TESTPOOL/$TESTVOL $TESTPOOL/$TESTFS1 \
+	$TESTPOOL/$TESTVOL $TESTPOOL/$TESTCTR/$TESTFS1 \
+	$TESTPOOL/$TESTFS@snapshot $TESTPOOL/$TESTCTR1 \
+	$TESTPOOL/$TESTFS@snapshot $TESTPOOL/$TESTVOL \
+	$TESTPOOL/$TESTFS@snapshot $TESTPOOL/$TESTFS1 \
+	$TESTPOOL/$TESTFS@snapshot $TESTPOOL/$TESTCTR/$TESTFS1 \
+	$TESTPOOL/$TESTFS1 $TESTPOOL/${TESTFS1}%c \
+	$TESTPOOL/$TESTFS1 $TESTPOOL/${TESTFS1}%d \
+	$TESTPOOL/$TESTFS1 $TESTPOOL/${TESTFS1}%x \
+	$TESTPOOL/$TESTFS1 $TESTPOOL/${TESTFS1}%p \
+	$TESTPOOL/$TESTFS1 $TESTPOOL/${TESTFS1}%s \
+	$TESTPOOL/$TESTFS@snapshot \
+	$TESTPOOL/$TESTFS@snapshot/fs
+
+#
+# cleanup defined in zfs_rename.kshlib
+#
+log_onexit cleanup
+
+log_assert "'zfs rename' should fail when datasets are of a different type."
+
+additional_setup
+
+typeset -i i=0
+while ((i < ${#bad_dataset[*]} )); do
+        log_mustnot $ZFS rename ${bad_dataset[i]} ${bad_dataset[((i + 1))]}
+        log_must datasetexists ${bad_dataset[i]}
+
+        log_mustnot $ZFS rename -p ${bad_dataset[i]} ${bad_dataset[((i + 1))]}
+        log_must datasetexists ${bad_dataset[i]}
+
+	((i = i + 2))
+done
+
+#verify 'rename -p' can not work with snapshots
+
+log_mustnot $ZFS rename -p $TESTPOOL/$TESTFS@snapshot \
+		$TESTPOOL/$TESTFS@snapshot2
+log_must datasetexists $TESTPOOL/$TESTFS@snapshot
+log_mustnot $ZFS rename -p $TESTPOOL/$TESTFS@snapshot \
+		$TESTPOOL/$TESTFS/$TESTFS@snapshot2
+log_must datasetexists $TESTPOOL/$TESTFS@snapshot
+
+log_pass "'zfs rename' fails as expected when given different dataset types."
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/usr/src/test/zfs-tests/tests/functional/cli_root/zfs_rename/zfs_rename_005_neg.ksh	Wed Dec 05 22:04:50 2012 -0500
@@ -0,0 +1,87 @@
+#!/bin/ksh -p
+#
+# CDDL HEADER START
+#
+# The contents of this file are subject to the terms of the
+# Common Development and Distribution License (the "License").
+# You may not use this file except in compliance with the License.
+#
+# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
+# or http://www.opensolaris.org/os/licensing.
+# See the License for the specific language governing permissions
+# and limitations under the License.
+#
+# When distributing Covered Code, include this CDDL HEADER in each
+# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
+# If applicable, add the following below this CDDL 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.
+#
+. $STF_SUITE/include/libtest.shlib
+. $STF_SUITE/tests/functional/cli_root/zfs_rename/zfs_rename.kshlib
+
+#
+# DESCRIPTION:
+#       'zfs rename' should fail when the dataset are not within the same pool
+#
+# STRATEGY:
+#       1. Given a file system, snapshot and volume.
+#       2. Rename each dataset object to a different pool.
+#       3. Verify the operation fails, and only the original name
+#	   is displayed by zfs list.
+#
+
+verify_runnable "global"
+
+function my_cleanup
+{
+	poolexists $TESTPOOL1 && \
+		destroy_pool $TESTPOOL1
+	[[ -e $TESTDIR/$TESTFILE1 ]] && \
+		log_must $RM -f $TESTDIR/$TESTFILE1
+	cleanup
+}
+
+set -A src_dataset \
+    "$TESTPOOL/$TESTFS1" "$TESTPOOL/$TESTCTR1" \
+    "$TESTPOOL/$TESTCTR/$TESTFS1" "$TESTPOOL/$TESTVOL" \
+    "$TESTPOOL/$TESTFS@snapshot" "$TESTPOOL/$TESTFS-clone"
+
+#
+# cleanup defined in zfs_rename.kshlib
+#
+log_onexit my_cleanup
+
+log_assert "'zfs rename' should fail while datasets are within different pool."
+
+additional_setup
+
+typeset FILESIZE=64m
+log_must $MKFILE $FILESIZE $TESTDIR/$TESTFILE1
+create_pool $TESTPOOL1 $TESTDIR/$TESTFILE1
+
+for src in ${src_dataset[@]} ; do
+	dest=${src#$TESTPOOL/}
+	if [[ $dest == *"@"* ]]; then
+		dest=${dest#*@}
+		dest=${TESTPOOL1}@$dest
+	else
+		dest=${TESTPOOL1}/$dest
+	fi
+	log_mustnot $ZFS rename $src $dest
+	log_mustnot $ZFS rename -p $src $dest
+
+	#
+	# Verify original dataset name still in use
+	#
+	log_must datasetexists $src
+done
+
+log_pass "'zfs rename' fail while datasets are within different pool."
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/usr/src/test/zfs-tests/tests/functional/cli_root/zfs_rename/zfs_rename_006_pos.ksh	Wed Dec 05 22:04:50 2012 -0500
@@ -0,0 +1,75 @@
+#!/bin/ksh
+#
+# CDDL HEADER START
+#
+# The contents of this file are subject to the terms of the
+# Common Development and Distribution License (the "License").
+# You may not use this file except in compliance with the License.
+#
+# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
+# or http://www.opensolaris.org/os/licensing.
+# See the License for the specific language governing permissions
+# and limitations under the License.
+#
+# When distributing Covered Code, include this CDDL HEADER in each
+# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
+# If applicable, add the following below this CDDL HEADER, with the
+# fields enclosed by brackets "[]" replaced with your own identifying
+# information: Portions Copyright [yyyy] [name of copyright owner]
+#
+# CDDL HEADER END
+#
+
+#
+# Copyright 2007 Sun Microsystems, Inc.  All rights reserved.
+# Use is subject to license terms.
+#
+. $STF_SUITE/include/libtest.shlib
+. $STF_SUITE/tests/functional/cli_root/zfs_rename/zfs_rename.kshlib
+
+#
+# DESCRIPTION:
+#       'zfs rename' can successfully rename a volume snapshot.
+#
+# STRATEGY:
+#       1. Create a snapshot of volume.
+#       2. Rename volume snapshot to a new one.
+#	3. Rename volume to a new one.
+#       5. Verify that the rename operations are successful and zfs list can
+#	   list them.
+#
+###############################################################################
+
+verify_runnable "global"
+
+#
+# cleanup defined in zfs_rename.kshlib
+#
+log_onexit cleanup
+
+log_assert "'zfs rename' can successfully rename a volume snapshot."
+
+vol=$TESTPOOL/$TESTVOL
+snap=$TESTSNAP
+
+log_must eval "$DD if=$DATA of=$VOL_R_PATH bs=$BS count=$CNT >/dev/null 2>&1"
+if ! snapexists $vol@$snap; then
+	log_must $ZFS snapshot $vol@$snap
+fi
+
+rename_dataset $vol@$snap $vol@${snap}-new
+rename_dataset $vol ${vol}-new
+rename_dataset ${vol}-new@${snap}-new ${vol}-new@$snap
+rename_dataset ${vol}-new $vol
+
+#verify data integrity
+for input in $VOL_R_PATH ${VOL_R_PATH}@$snap; do
+	log_must eval "$DD if=$input of=$VOLDATA bs=$BS count=$CNT >/dev/null 2>&1"
+	if ! cmp_data $VOLDATA $DATA ; then
+		log_fail "$input gets corrupted after rename operation."
+	fi
+done
+
+log_must $ZFS destroy $vol@$snap
+
+log_pass "'zfs rename' can rename volume snapshot as expected."
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/usr/src/test/zfs-tests/tests/functional/cli_root/zfs_rename/zfs_rename_007_pos.ksh	Wed Dec 05 22:04:50 2012 -0500
@@ -0,0 +1,151 @@
+#!/bin/ksh -p
+#
+# CDDL HEADER START
+#
+# The contents of this file are subject to the terms of the
+# Common Development and Distribution License (the "License").
+# You may not use this file except in compliance with the License.
+#
+# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
+# or http://www.opensolaris.org/os/licensing.
+# See the License for the specific language governing permissions
+# and limitations under the License.
+#
+# When distributing Covered Code, include this CDDL HEADER in each
+# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
+# If applicable, add the following below this CDDL HEADER, with the
+# fields enclosed by brackets "[]" replaced with your own identifying
+# information: Portions Copyright [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.
+#
+
+. $STF_SUITE/include/libtest.shlib
+. $STF_SUITE/tests/functional/cli_root/zfs_rename/zfs_rename.kshlib
+
+#
+# DESCRIPTION:
+#	Rename dataset, verify that the data haven't changed.
+#
+# STRATEGY:
+#	1. Create random data and copy to dataset.
+#	2. Perform renaming commands.
+#	3. Verify that the data haven't changed.
+#
+
+verify_runnable "both"
+
+function cleanup
+{
+	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
+
+	$RM -f $SRC_FILE $DST_FILE
+}
+
+function target_obj
+{
+	typeset dtst=$1
+
+	typeset obj
+	typeset type=$(get_prop type $dtst)
+	if [[ $type == "filesystem" ]]; then
+		obj=$(get_prop mountpoint $dtst)/${SRC_FILE##*/}
+	elif [[ $type == "volume" ]]; then
+		obj=/dev/zvol/dsk/$dtst
+	fi
+
+	echo $obj
+}
+
+log_assert "Rename dataset, verify that the data haven't changed."
+log_onexit cleanup
+
+# Generate random data
+#
+BS=512 ; CNT=2048
+SRC_FILE=/tmp/srcfile.$$
+DST_FILE=/tmp/dstfile.$$
+log_must $DD if=/dev/random of=$SRC_FILE bs=$BS count=$CNT
+
+fs=$TESTPOOL/$TESTFS/fs.$$
+fsclone=$TESTPOOL/$TESTFS/fsclone.$$
+log_must $ZFS create $fs
+
+obj=$(target_obj $fs)
+log_must $CP $SRC_FILE $obj
+
+snap=${fs}@snap.$$
+log_must $ZFS snapshot $snap
+log_must $ZFS clone $snap $fsclone
+
+# Rename dataset & clone
+#
+log_must $ZFS rename $fs ${fs}-new
+log_must $ZFS rename $fsclone ${fsclone}-new
+
+# Compare source file and target file
+#
+obj=$(target_obj ${fs}-new)
+log_must $DIFF $SRC_FILE $obj
+obj=$(target_obj ${fsclone}-new)
+log_must $DIFF $SRC_FILE $obj
+
+# Rename snapshot and re-clone dataset
+#
+log_must $ZFS rename ${fs}-new $fs
+log_must $ZFS rename $snap ${snap}-new
+log_must $ZFS clone ${snap}-new $fsclone
+
+# Compare source file and target file
+#
+obj=$(target_obj $fsclone)
+log_must $DIFF $SRC_FILE $obj
+
+if is_global_zone; then
+	vol=$TESTPOOL/$TESTFS/vol.$$ ;	volclone=$TESTPOOL/$TESTFS/volclone.$$
+	log_must $ZFS create -V 100M $vol
+
+	obj=$(target_obj $vol)
+	log_must $DD if=$SRC_FILE of=$obj bs=$BS count=$CNT
+
+	snap=${vol}@snap.$$
+	log_must $ZFS snapshot $snap
+	log_must $ZFS clone $snap $volclone
+
+	# Rename dataset & clone
+	log_must $ZFS rename $vol ${vol}-new
+	log_must $ZFS rename $volclone ${volclone}-new
+
+	# Compare source file and target file
+	obj=$(target_obj ${vol}-new)
+	log_must $DD if=$obj of=$DST_FILE bs=$BS count=$CNT
+	log_must $DIFF $SRC_FILE $DST_FILE
+	obj=$(target_obj ${volclone}-new)
+	log_must $DD if=$obj of=$DST_FILE bs=$BS count=$CNT
+	log_must $DIFF $SRC_FILE $DST_FILE
+
+	# Rename snapshot and re-clone dataset
+	log_must $ZFS rename ${vol}-new $vol
+	log_must $ZFS rename $snap ${snap}-new
+	log_must $ZFS clone ${snap}-new $volclone
+
+	# Compare source file and target file
+	obj=$(target_obj $volclone)
+	log_must $DD if=$obj of=$DST_FILE bs=$BS count=$CNT
+	log_must $DIFF $SRC_FILE $DST_FILE
+fi
+
+log_pass "Rename dataset, the data haven't changed passed."
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/usr/src/test/zfs-tests/tests/functional/cli_root/zfs_rename/zfs_rename_008_pos.ksh	Wed Dec 05 22:04:50 2012 -0500
@@ -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) 2012 by Delphix. All rights reserved.
+#
+
+. $STF_SUITE/include/libtest.shlib
+
+#
+# DESCRIPTION:
+#	zfs rename -r can rename snapshot recursively.
+#
+# STRATEGY:
+#	1. Create snapshot recursively.
+#	2. Rename snapshot recursively.
+#	3. Verify rename -r snapshot correctly.
+#
+
+verify_runnable "both"
+
+function cleanup
+{
+	typeset -i i=0
+	while ((i < ${#datasets[@]})); do
+		if datasetexists ${datasets[$i]}@snap ; then
+			log_must $ZFS destroy ${datasets[$i]}@snap
+		fi
+		if datasetexists ${datasets[$i]}@snap-new ; then
+			log_must $ZFS destroy ${datasets[$i]}@snap-new
+		fi
+
+		((i += 1))
+	done
+}
+
+log_assert "zfs rename -r can rename snapshot recursively."
+log_onexit cleanup
+
+set -A datasets $TESTPOOL		$TESTPOOL/$TESTCTR \
+	$TESTPOOL/$TESTCTR/$TESTFS1	$TESTPOOL/$TESTFS
+if is_global_zone; then
+	datasets[${#datasets[@]}]=$TESTPOOL/$TESTVOL
+fi
+
+log_must $ZFS snapshot -r ${TESTPOOL}@snap
+typeset -i i=0
+while ((i < ${#datasets[@]})); do
+	log_must datasetexists ${datasets[$i]}@snap
+
+	((i += 1))
+done
+
+log_must $ZFS rename -r ${TESTPOOL}@snap ${TESTPOOL}@snap-new
+i=0
+while ((i < ${#datasets[@]})); do
+	log_must datasetexists ${datasets[$i]}@snap-new
+
+	((i += 1))
+done
+
+log_must $ZFS destroy -rf ${TESTPOOL}@snap-new
+
+log_pass "Verify zfs rename -r passed."
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/usr/src/test/zfs-tests/tests/functional/cli_root/zfs_rename/zfs_rename_009_neg.ksh	Wed Dec 05 22:04:50 2012 -0500
@@ -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) 2012 by Delphix. All rights reserved.
+#
+
+. $STF_SUITE/include/libtest.shlib
+
+#
+# DESCRIPTION:
+#	A snapshot already exists with the new name, then none of the
+#	snapshots is renamed.
+#
+# STRATEGY:
+#	1. Create snapshot for a set of datasets.
+#	2. Create a new snapshot for one of datasets.
+#	3. Using rename -r command with exists snapshot name.
+#	4. Verify none of the snapshots is renamed.
+#
+
+verify_runnable "both"
+
+function cleanup
+{
+	typeset snaps=$($ZFS list -H -t snapshot -o name)
+	typeset exclude
+	typeset snap
+	typeset pool_name
+
+	if [[ -n $KEEP ]]; then
+		exclude=`eval $ECHO \"'(${KEEP})'\"`
+	fi
+
+	for snap in $snaps; do
+		pool_name=$($ECHO "$snap" | $AWK -F/ '{print $1}')
+		if [[ -n $exclude ]]; then
+			$ECHO "$pool_name" | $EGREP -v "$exclude" > /dev/null 2>&1
+			if [[ $? -eq 0 ]]; then
+				log_must $ZFS destroy $snap
+			fi
+		else
+			log_must $ZFS destroy $snap
+		fi
+	done
+}
+
+log_assert "zfs rename -r failed, when snapshot name is already existing."
+log_onexit cleanup
+
+set -A datasets $TESTPOOL		$TESTPOOL/$TESTCTR \
+	$TESTPOOL/$TESTCTR/$TESTFS1	$TESTPOOL/$TESTFS
+if is_global_zone; then
+	datasets[${#datasets[@]}]=$TESTPOOL/$TESTVOL
+fi
+
+log_must $ZFS snapshot -r ${TESTPOOL}@snap
+typeset -i i=0
+while ((i < ${#datasets[@]})); do
+	# Create one more snapshot
+	log_must $ZFS snapshot ${datasets[$i]}@snap2
+	log_mustnot $ZFS rename -r ${TESTPOOL}@snap ${TESTPOOL}@snap2
+	log_must $ZFS destroy ${datasets[$i]}@snap2
+
+	# Check datasets, make sure none of them was renamed.
+	typeset -i j=0
+	while ((j < ${#datasets[@]})); do
+		if datasetexists ${datasets[$j]}@snap2 ; then
+			log_fail "${datasets[$j]}@snap2 should not exist."
+		fi
+		((j += 1))
+	done
+
+	((i += 1))
+done
+
+log_pass "zfs rename -r failed, when snapshot name is already existing passed."
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/usr/src/test/zfs-tests/tests/functional/cli_root/zfs_rename/zfs_rename_010_neg.ksh	Wed Dec 05 22:04:50 2012 -0500
@@ -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) 2012 by Delphix. All rights reserved.
+#
+
+. $STF_SUITE/include/libtest.shlib
+
+#
+# DESCRIPTION:
+#	The recursive flag -r can only be used for snapshots and not for
+#	volumes/filesystems.
+#
+# STRATEGY:
+#	1. Loop pool, fs, container and volume.
+#	2. Verify none of them can be rename by rename -r.
+#
+
+verify_runnable "both"
+
+log_assert "The recursive flag -r can only be used for snapshots."
+
+set -A datasets $TESTPOOL		$TESTPOOL/$TESTCTR \
+	$TESTPOOL/$TESTCTR/$TESTFS1	$TESTPOOL/$TESTFS
+if is_global_zone; then
+	datasets[${#datasets[@]}]=$TESTPOOL/$TESTVOL
+fi
+
+for opts in "-r" "-r -p"; do
+	typeset -i i=0
+	while ((i < ${#datasets[@]})); do
+		log_mustnot $ZFS rename $opts ${datasets[$i]} \
+			${datasets[$i]}-new
+
+		# Check datasets, make sure none of them was renamed.
+		typeset -i j=0
+		while ((j < ${#datasets[@]})); do
+			if datasetexists ${datasets[$j]}-new ; then
+				log_fail "${datasets[$j]}-new should not exists."
+			fi
+			((j += 1))
+		done
+
+		((i += 1))
+	done
+done
+
+log_pass "The recursive flag -r can only be used for snapshots passed."
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/usr/src/test/zfs-tests/tests/functional/cli_root/zfs_rename/zfs_rename_011_pos.ksh	Wed Dec 05 22:04:50 2012 -0500
@@ -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.
+#
+. $STF_SUITE/include/libtest.shlib
+. $STF_SUITE/tests/functional/cli_root/zfs_rename/zfs_rename.kshlib
+
+#
+# DESCRIPTION
+#       'zfs rename -p' should work as expected
+#
+# STRATEGY:
+#	1. Make sure the upper level of $newdataset does not exist
+#       2. Make sure without -p option, 'zfs rename' will fail
+#       3. With -p option, rename works
+#
+
+verify_runnable "both"
+
+function additional_cleanup
+{
+	if datasetexists $TESTPOOL/notexist ; then
+		log_must $ZFS destroy -Rf $TESTPOOL/notexist
+	fi
+
+	if datasetexists $TESTPOOL/$TESTFS ; then
+		log_must $ZFS destroy -Rf $TESTPOOL/$TESTFS
+	fi
+	log_must $ZFS create $TESTPOOL/$TESTFS
+
+	if is_global_zone ; then
+		if datasetexists $TESTPOOL/$TESTVOL ; then
+			log_must $ZFS destroy -Rf $TESTPOOL/$TESTVOL
+		fi
+		log_must $ZFS create -V $VOLSIZE $TESTPOOL/$TESTVOL
+	fi
+}
+
+log_onexit additional_cleanup
+
+log_assert "'zfs rename -p' should work as expected"
+
+log_must verify_opt_p_ops "rename" "fs" "$TESTPOOL/$TESTFS" \
+	"$TESTPOOL/notexist/new/$TESTFS1"
+
+if is_global_zone; then
+	log_must verify_opt_p_ops "rename" "vol" "$TESTPOOL/$TESTVOL" \
+		"$TESTPOOL/notexist/new/$TESTVOL1"
+fi
+
+log_pass "'zfs rename -p' should work as expected"
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/usr/src/test/zfs-tests/tests/functional/cli_root/zfs_rename/zfs_rename_012_neg.ksh	Wed Dec 05 22:04:50 2012 -0500
@@ -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) 2012 by Delphix. All rights reserved.
+#
+
+. $STF_SUITE/include/libtest.shlib
+
+#
+# DESCRIPTION:
+#	'zfs rename' should be failed with bad option, null target dataset,
+#	too many datasets and long target dataset name.
+#
+# STRATEGY:
+#	1. Create a set of ZFS datasets;
+#	2. Try 'zfs rename' with various illegal scenarios;
+#	3. Verify 'zfs rename' command should be failed.
+#
+
+verify_runnable "both"
+
+log_assert "'zfs rename' should fail with bad option, null target dataset and" \
+		"too long target dataset name."
+
+badopts=( "r" "R" "-R" "-rR" "-Rr" "-P" "-pP" "-Pp" "-r*" "-p*" "-?" "-*" "-"
+    "-o")
+datasets=("$TESTPOOL" "$TESTPOOL/$TESTFS" "$TESTPOOL/$TESTFS@$TESTSNAP"
+    "$TESTPOOL/$TESTCTR" "$TESTPOOL/$TESTCTR/$TESTFS1" "$TESTPOOL/$TESTVOL")
+
+longname="$(gen_dataset_name 260 abcdefg)"
+
+log_must $ZFS snapshot $TESTPOOL/$TESTFS@$TESTSNAP
+for ds in ${datasets[@]}; do
+	for opt in ${badopts[@]}; do
+		log_mustnot $ZFS rename $opt $ds ${ds}-new
+	done
+	log_mustnot $ZFS rename $ds
+	log_mustnot $ZFS rename $ds ${ds}-new ${ds}-new1
+	log_mustnot $ZFS rename $ds ${ds}.$longname
+done
+
+log_pass "'zfs rename' fails with illegal scenarios as expected."
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/usr/src/test/zfs-tests/tests/functional/cli_root/zfs_rename/zfs_rename_013_pos.ksh	Wed Dec 05 22:04:50 2012 -0500
@@ -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) 2012 by Delphix. All rights reserved.
+#
+
+. $STF_SUITE/include/libtest.shlib
+
+#
+# DESCRIPTION:
+#	zfs rename -r can rename snapshot when child datasets
+#	don't have a snapshot of the given name.
+#
+# STRATEGY:
+#	1. Create snapshot.
+#	2. Rename snapshot recursively.
+#	3. Verify rename -r snapshot correctly.
+#
+
+verify_runnable "both"
+
+function cleanup
+{
+	if datasetexists $TESTPOOL/$TESTCTR@snap-new ; then
+		log_must $ZFS destroy -f $TESTPOOL/$TESTCTR@snap-new
+	fi
+
+	if datasetexists $TESTPOOL/$TESTCTR@snap ; then
+		log_must $ZFS destroy -f $TESTPOOL/$TESTCTR@snap
+	fi
+
+	if datasetexists $TESTPOOL@snap-new ; then
+		log_must $ZFS destroy -f $TESTPOOL@snap-new
+	fi
+
+	if datasetexists $TESTPOOL@snap ; then
+		log_must $ZFS destroy -f $TESTPOOL@snap
+	fi
+}
+
+log_assert "zfs rename -r can rename snapshot when child datasets" \
+	"don't have a snapshot of the given name."
+
+log_onexit cleanup
+
+log_must $ZFS snapshot $TESTPOOL/$TESTCTR@snap
+log_must $ZFS rename -r $TESTPOOL/$TESTCTR@snap $TESTPOOL/$TESTCTR@snap-new
+log_must datasetexists $TESTPOOL/$TESTCTR@snap-new
+
+log_must $ZFS snapshot $TESTPOOL@snap
+log_must $ZFS rename -r $TESTPOOL@snap $TESTPOOL@snap-new
+log_must datasetexists $TESTPOOL/$TESTCTR@snap-new
+log_must datasetexists $TESTPOOL@snap-new
+
+log_must $ZFS destroy -f $TESTPOOL/$TESTCTR@snap-new
+log_must $ZFS destroy -f $TESTPOOL@snap-new
+
+log_pass "Verify zfs rename -r passed when child datasets" \
+	"don't have a snapshot of the given name."
+
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/usr/src/test/zfs-tests/tests/functional/cli_root/zfs_reservation/Makefile	Wed Dec 05 22:04:50 2012 -0500
@@ -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) 2012 by Delphix. All rights reserved.
+#
+
+include $(SRC)/Makefile.master
+
+ROOTOPTPKG = $(ROOT)/opt/zfs-tests
+TESTDIR = $(ROOTOPTPKG)/tests/functional/cli_root/zfs_reservation
+
+PROGS = cleanup \
+	setup \
+	zfs_reservation_001_pos \
+	zfs_reservation_002_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	Thu Jan 01 00:00:00 1970 +0000
+++ b/usr/src/test/zfs-tests/tests/functional/cli_root/zfs_reservation/cleanup.ksh	Wed Dec 05 22:04:50 2012 -0500
@@ -0,0 +1,30 @@
+#!/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.
+#
+
+. $STF_SUITE/include/libtest.shlib
+
+default_cleanup
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/usr/src/test/zfs-tests/tests/functional/cli_root/zfs_reservation/setup.ksh	Wed Dec 05 22:04:50 2012 -0500
@@ -0,0 +1,32 @@
+#!/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.
+#
+
+. $STF_SUITE/include/libtest.shlib
+
+DISK=${DISKS%% *}
+
+default_setup $DISK
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/usr/src/test/zfs-tests/tests/functional/cli_root/zfs_reservation/zfs_reservation_001_pos.ksh	Wed Dec 05 22:04:50 2012 -0500
@@ -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.
+#
+. $STF_SUITE/include/libtest.shlib
+
+#
+# DESCRIPTION:
+# Exceed the maximum limit for a reservation and ensure it fails.
+#
+# STRATEGY:
+# 1. Create a reservation file system.
+# 2. Set the reservation to an absurd value.
+# 3. Verify the return code is an error.
+#
+
+verify_runnable "both"
+
+RESERVATION="reserve"
+
+function cleanup
+{
+	if datasetexists $TESTPOOL/$RESERVATION ; then
+		log_must $ZFS unmount $TESTPOOL/$RESERVATION
+		log_must $ZFS destroy $TESTPOOL/$RESERVATION
+	fi
+}
+
+log_onexit cleanup
+
+log_assert "Verify that a reservation > 2^64 -1 fails."
+
+log_must $ZFS create $TESTPOOL/$RESERVATION
+
+log_mustnot $ZFS set reservation=18446744073709551615 $TESTPOOL/$RESERVATION
+
+log_pass "Unable to set a reservation > 2^64 - 1"
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/usr/src/test/zfs-tests/tests/functional/cli_root/zfs_reservation/zfs_reservation_002_pos.ksh	Wed Dec 05 22:04:50 2012 -0500
@@ -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.
+#
+. $STF_SUITE/include/libtest.shlib
+
+#
+# DESCRIPTION:
+# A reservation of 'none' (which is an alias for 0) should be allowed. This
+# test verifies that is true.
+#
+# STRATEGY:
+# 1. Create a new file system in the test pool.
+# 2. Set the reservation to 'none'.
+# 3. Verify the associated reservation is indeed 0.
+# 4. Repeat with reservation set to 0.
+#
+
+verify_runnable "both"
+
+# Use a unique value so earlier test failures will not impact this test.
+RESERVATION="reserve"-$$
+RESERVATION2="reserve2"-$$
+
+function cleanup
+{
+	typeset FS
+	for FS in $TESTPOOL/$RESERVATION $TESTPOOL/$RESERVATION2
+	do
+		if datasetexists $FS ; then
+			log_must $ZFS unmount $FS
+			log_must $ZFS destroy $FS
+		fi
+	done
+}
+
+log_onexit cleanup
+
+log_assert "Ensure a reservation of 0 or 'none' is allowed."
+
+log_must $ZFS create $TESTPOOL/$RESERVATION
+log_must $ZFS create $TESTPOOL/$RESERVATION2
+
+log_must $ZFS set reservation=0 $TESTPOOL/$RESERVATION
+log_must $ZFS set reservation=none $TESTPOOL/$RESERVATION2
+
+for FS in $TESTPOOL/$RESERVATION $TESTPOOL/$RESERVATION2
+do
+
+	reserve=`$ZFS get -pH reservation $FS | $AWK '{print $3}'`
+	if [[ $reserve -ne 0 ]]; then
+		log_fail "ZFS get -p reservation did not return 0"
+	fi
+
+	reserve=`$ZFS get -H reservation $FS | $AWK '{print $3}'`
+	if [[ $reserve != "none" ]]; then
+		log_fail "ZFS get reservation did not return 'none'"
+	fi
+done
+
+log_pass "Successfully set reservation to 0 and 'none'"
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/usr/src/test/zfs-tests/tests/functional/cli_root/zfs_rollback/Makefile	Wed Dec 05 22:04:50 2012 -0500
@@ -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) 2012 by Delphix. All rights reserved.
+#
+
+include $(SRC)/Makefile.master
+
+ROOTOPTPKG = $(ROOT)/opt/zfs-tests
+TESTDIR = $(ROOTOPTPKG)/tests/functional/cli_root/zfs_rollback
+
+PROGS = cleanup \
+	setup \
+	zfs_rollback_001_pos \
+	zfs_rollback_002_pos \
+	zfs_rollback_003_neg \
+	zfs_rollback_004_neg
+
+FILES = zfs_rollback.cfg \
+	zfs_rollback_common.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	Thu Jan 01 00:00:00 1970 +0000
+++ b/usr/src/test/zfs-tests/tests/functional/cli_root/zfs_rollback/cleanup.ksh	Wed Dec 05 22:04:50 2012 -0500
@@ -0,0 +1,32 @@
+#!/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.
+#
+
+. $STF_SUITE/tests/functional/cli_root/zfs_rollback/zfs_rollback_common.kshlib
+
+cleanup_env
+
+default_cleanup
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/usr/src/test/zfs-tests/tests/functional/cli_root/zfs_rollback/setup.ksh	Wed Dec 05 22:04:50 2012 -0500
@@ -0,0 +1,31 @@
+#!/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.
+#
+
+. $STF_SUITE/include/libtest.shlib
+
+DISK=${DISKS%% *}
+default_volume_setup $DISK
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/usr/src/test/zfs-tests/tests/functional/cli_root/zfs_rollback/zfs_rollback.cfg	Wed Dec 05 22:04:50 2012 -0500
@@ -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.
+#
+. $STF_SUITE/include/libtest.shlib
+
+export FS=$TESTPOOL/$TESTFS
+export VOL=$TESTPOOL/$TESTVOL
+
+export FSSNAP0=$FS@$TESTSNAP
+export FSSNAP1=$FS@$TESTSNAP1
+export FSSNAP2=$FS@$TESTSNAP2
+
+export VOLSNAP0=$VOL@$TESTSNAP
+export VOLSNAP1=$VOL@$TESTSNAP1
+export VOLSNAP2=$VOL@$TESTSNAP2
+
+export FSCLONE0=$FS$TESTCLONE
+export FSCLONE1=$FS$TESTCLONE1
+export FSCLONE2=$FS$TESTCLONE2
+
+export VOLCLONE0=$VOL$TESTCLONE
+export VOLCLONE1=$VOL$TESTCLONE1
+export VOLCLONE2=$VOL$TESTCLONE2
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/usr/src/test/zfs-tests/tests/functional/cli_root/zfs_rollback/zfs_rollback_001_pos.ksh	Wed Dec 05 22:04:50 2012 -0500
@@ -0,0 +1,163 @@
+#!/bin/ksh -p
+#
+# CDDL HEADER START
+#
+# The contents of this file are subject to the terms of the
+# Common Development and Distribution License (the "License").
+# You may not use this file except in compliance with the License.
+#
+# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
+# or http://www.opensolaris.org/os/licensing.
+# See the License for the specific language governing permissions
+# and limitations under the License.
+#
+# When distributing Covered Code, include this CDDL HEADER in each
+# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
+# If applicable, add the following below this CDDL 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.
+#
+
+. $STF_SUITE/include/libtest.shlib
+. $STF_SUITE/tests/functional/cli_root/zfs_rollback/zfs_rollback_common.kshlib
+
+#
+# DESCRIPTION:
+#	'zfs rollback -r|-rf|-R|-Rf' will recursively destroy any snapshots
+#	more recent than the one specified.
+#
+# STRATEGY:
+#	1. Create pool, fs & volume.
+#	2. Separately create three snapshots or clones for fs & volume
+#	3. Roll back to the second snapshot and check the results.
+#	4. Create the third snapshot or clones for fs & volume again.
+#	5. Roll back to the first snapshot and check the results.
+#	6. Separately create two snapshots for fs & volume.
+#	7. Roll back to the first snapshot and check the results.
+#
+
+verify_runnable "both"
+
+log_assert "'zfs rollback -r|-rf|-R|-Rf' will recursively destroy any " \
+	"snapshots more recent than the one specified."
+log_onexit cleanup_env
+
+#
+# Create suitable test environment and run 'zfs rollback', then compare with
+# expected value to check the system status.
+#
+# $1 option.
+# $2 the number of snapshots or clones.
+# $3 the number of snapshot point which we want to rollback.
+#
+function test_n_check #opt num_snap_clone num_rollback
+{
+	typeset opt=$1
+	typeset -i cnt=$2
+	typeset -i pointcnt=$3
+	typeset dtst
+
+	(( cnt > 3 || pointcnt > cnt )) && \
+		log_fail "Unsupported testing condition."
+
+	# Clean up the test environment
+	datasetexists $FS && log_must $ZFS destroy -Rf $FS
+	if datasetexists $VOL; then
+		$DF -lhF ufs "/dev/zvol/dsk/$VOL" > /dev/null 2>&1
+		(( $? == 0 )) && log_must $UMOUNT -f $TESTDIR1
+
+		log_must $ZFS destroy -Rf $VOL
+	fi
+
+	# Create specified test environment
+	case $opt in
+		*r*) setup_snap_env $cnt ;;
+		*R*) setup_clone_env $cnt ;;
+	esac
+
+	all_snap="$TESTSNAP $TESTSNAP1 $TESTSNAP2"
+	all_clone="$TESTCLONE $TESTCLONE1 $TESTCLONE2"
+	typeset snap_point
+	typeset exist_snap
+	typeset exist_clone
+	case $pointcnt in
+		1) snap_point=$TESTSNAP
+		   exist_snap=$TESTSNAP
+		   [[ $opt == *R* ]] && exist_clone=$TESTCLONE
+		   ;;
+		2) snap_point=$TESTSNAP1
+		   exist_snap="$TESTSNAP $TESTSNAP1"
+		   [[ $opt == *R* ]] && exist_clone="$TESTCLONE $TESTCLONE1"
+		   ;;
+	esac
+
+	typeset snap
+	for dtst in $FS $VOL; do
+		# Volume is not available in Local Zone.
+		if [[ $dtst == $VOL ]]; then
+			if ! is_global_zone; then
+				break
+			fi
+		fi
+		if [[ $opt == *f* ]]; then
+			# To write data to the mountpoint directory,
+			write_mountpoint_dir $dtst
+			opt=${opt%f}
+		fi
+
+		if [[ $dtst == $VOL ]]; then
+			log_must $UMOUNT -f $TESTDIR1
+			log_must $ZFS rollback $opt $dtst@$snap_point
+			log_must $MOUNT \
+				/dev/zvol/dsk/$TESTPOOL/$TESTVOL $TESTDIR1
+		else
+			log_must $ZFS rollback $opt $dtst@$snap_point
+		fi
+
+		for snap in $all_snap; do
+			if [[ " $exist_snap " == *" $snap "* ]]; then
+				log_must datasetexists $dtst@$snap
+			else
+				log_must datasetnonexists $dtst@$snap
+			fi
+		done
+		for clone in $all_clone; do
+			if [[ " $exist_clone " == *" $clone "* ]]; then
+				log_must datasetexists $dtst$clone
+			else
+				log_must datasetnonexists $dtst$clone
+			fi
+		done
+
+		check_files $dtst@$snap_point
+	done
+}
+
+typeset opt
+for opt in "-r" "-rf" "-R" "-Rf"; do
+	#
+	# Currently, the test case was limited to create and rollback
+	# in three snapshots
+	#
+	log_note "Create 3 snapshots, rollback to the 2nd snapshot " \
+		"using $opt."
+	test_n_check "$opt" 3 2
+
+	log_note "Create 3 snapshots and rollback to the 1st snapshot " \
+		"using $opt."
+	test_n_check "$opt" 3 1
+
+	log_note "Create 2 snapshots and rollback to the 1st snapshot " \
+		"using $opt."
+	test_n_check "$opt" 2 1
+done
+
+log_pass "'zfs rollback -r|-rf|-R|-Rf' recursively destroy any snapshots more "\
+	"recent than the one specified passed."
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/usr/src/test/zfs-tests/tests/functional/cli_root/zfs_rollback/zfs_rollback_002_pos.ksh	Wed Dec 05 22:04:50 2012 -0500
@@ -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.
+#
+
+. $STF_SUITE/include/libtest.shlib
+. $STF_SUITE/tests/functional/cli_root/zfs_rollback/zfs_rollback_common.kshlib
+
+#
+# DESCRIPTION:
+#	'zfs rollback -f' will force unmount any filesystems.
+#
+# STRATEGY:
+#	1. Create pool & fs.
+#	2. Create the snapshot of this file system.
+#	3. Write the mountpoint directory of this file system.
+#	4. Make sure 'zfs rollback -f' succeeds.
+#
+
+verify_runnable "both"
+
+log_assert "'zfs rollback -f' will force unmount any filesystems."
+log_onexit cleanup_env
+
+# Create a snapshot of this file system: FSSNAP0
+setup_snap_env 1
+
+#
+# Write file and make the mountpoint directory busy when try to unmount
+# the file system that was mounted on it.
+#
+write_mountpoint_dir ${FSSNAP0%%@*}
+
+log_must $ZFS rollback $FSSNAP0
+log_must $ZFS rollback -f $FSSNAP0
+log_must datasetexists $FSSNAP0
+
+$PKILL ${DD##*/}
+
+check_files $FSSNAP0
+
+log_pass "'zfs rollback -f' force unmount any filesystem passed."
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/usr/src/test/zfs-tests/tests/functional/cli_root/zfs_rollback/zfs_rollback_003_neg.ksh	Wed Dec 05 22:04:50 2012 -0500
@@ -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.
+#
+
+. $STF_SUITE/include/libtest.shlib
+. $STF_SUITE/tests/functional/cli_root/zfs_rollback/zfs_rollback_common.kshlib
+
+#
+# DESCRIPTION:
+#	Seperately verify 'zfs rollback ''|-f|-r|-rf|-R|-rR will fail in
+#	different conditions.
+#
+# STRATEGY:
+#	1. Create pool and file system
+#	2. Create 'snap' and 'snap1' of this file system.
+#	3. Run 'zfs rollback ""|-f <snap>' and it should fail.
+#	4. Create 'clone1' based on 'snap1'.
+#	5. Run 'zfs rollback -r|-rf <snap>' and it should fail.
+#
+
+verify_runnable "both"
+
+function cleanup
+{
+	$PKILL ${DD##*/}
+	for snap in $FSSNAP0 $FSSNAP1 $FSSNAP2; do
+		if snapexists $snap; then
+			log_must $ZFS destroy -Rf $snap
+		fi
+	done
+}
+
+log_assert "Seperately verify 'zfs rollback ''|-f|-r|-rf will fail in " \
+	"different conditions."
+log_onexit cleanup
+
+# Create snapshot1 and snapshot2 for this file system.
+#
+create_snapshot $TESTPOOL/$TESTFS $TESTSNAP
+create_snapshot $TESTPOOL/$TESTFS $TESTSNAP1
+
+# Run 'zfs rollback ""|-f <snap>' and it should fail.
+#
+log_mustnot $ZFS rollback $TESTPOOL/$TESTFS@$TESTSNAP
+log_mustnot $ZFS rollback -f $TESTPOOL/$TESTFS@$TESTSNAP
+
+# Create 'clone1' based on 'snap1'.
+#
+create_clone $TESTPOOL/$TESTFS@$TESTSNAP1 $TESTPOOL/$TESTCLONE1
+
+# Run 'zfs rollback -r|-rf <snap>' and it should fail.
+#
+log_mustnot $ZFS rollback -r $TESTPOOL/$TESTFS@$TESTSNAP
+log_mustnot $ZFS rollback -rf $TESTPOOL/$TESTFS@$TESTSNAP
+
+log_pass "zfs rollback ''|-f|-r|-rf will fail in different conditions " \
+	"passed."
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/usr/src/test/zfs-tests/tests/functional/cli_root/zfs_rollback/zfs_rollback_004_neg.ksh	Wed Dec 05 22:04:50 2012 -0500
@@ -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.
+#
+
+. $STF_SUITE/include/libtest.shlib
+. $STF_SUITE/tests/functional/cli_root/zfs_rollback/zfs_rollback_common.kshlib
+
+#
+# DESCRIPTION:
+#	'zfs rollback' should fail when passing invalid options, too many
+#	arguments,non-snapshot datasets or missing datasets
+#
+# STRATEGY:
+#	1. Create an array of invalid options
+#	2. Execute 'zfs rollback' with invalid options, too many arguments
+#	   or missing datasets
+#	3. Verify 'zfs rollback' return with errors
+#
+
+verify_runnable "both"
+
+function cleanup
+{
+	typeset ds
+
+	for ds in $TESTPOOL $TESTPOOL/$TESTFS $TESTPOOL/$TESTVOL; do
+		if snapexists ${ds}@$TESTSNAP; then
+			log_must $ZFS destroy ${ds}@$TESTSNAP
+		fi
+	done
+}
+
+log_assert "'zfs rollback' should fail with bad options,too many arguments," \
+	"non-snapshot datasets or missing datasets."
+log_onexit cleanup
+
+set -A badopts "r" "R" "f" "-F" "-rF" "-RF" "-fF" "-?" "-*" "-blah" "-1" "-2"
+
+for ds in $TESTPOOL $TESTPOOL/$TESTFS $TESTPOOL/$TESTVOL; do
+	log_must $ZFS snapshot ${ds}@$TESTSNAP
+done
+
+for ds in $TESTPOOL $TESTPOOL/$TESTFS $TESTPOOL/$TESTVOL; do
+	for opt in "" "-r" "-R" "-f" "-rR" "-rf" "-rRf"; do
+		log_mustnot eval "$ZFS rollback $opt $ds >/dev/null 2>&1"
+		log_mustnot eval "$ZFS rollback $opt ${ds}@$TESTSNAP \
+			${ds}@$TESTSNAP >/dev/null 2>&1"
+		log_mustnot eval "$ZFS rollback $opt >/dev/null 2>&1"
+		# zfs rollback should fail with non-existen snapshot
+		log_mustnot eval "$ZFS rollback $opt ${ds}@nosnap >/dev/null 2>&1"
+	done
+
+	for badopt in ${badopts[@]}; do
+		log_mustnot eval "$ZFS rollback $badopt ${ds}@$TESTSNAP \
+				>/dev/null 2>&1"
+	done
+done
+
+log_pass "'zfs rollback' fails as expected with illegal arguments."
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/usr/src/test/zfs-tests/tests/functional/cli_root/zfs_rollback/zfs_rollback_common.kshlib	Wed Dec 05 22:04:50 2012 -0500
@@ -0,0 +1,305 @@
+#
+# CDDL HEADER START
+#
+# The contents of this file are subject to the terms of the
+# Common Development and Distribution License (the "License").
+# You may not use this file except in compliance with the License.
+#
+# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
+# or http://www.opensolaris.org/os/licensing.
+# See the License for the specific language governing permissions
+# and limitations under the License.
+#
+# When distributing Covered Code, include this CDDL HEADER in each
+# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
+# If applicable, add the following below this CDDL 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.
+#
+
+. $STF_SUITE/include/libtest.shlib
+. $STF_SUITE/tests/functional/cli_root/zfs_rollback/zfs_rollback.cfg
+
+# Get file sum
+#
+# $1 full file name
+function getsum #fname
+{
+	(( ${#1} == 0 )) && \
+		log_fail "Need give file name."
+	return $($SUM $1 | $AWK '{print $1}')
+}
+
+# Define global variable checksum, get the original file sum.
+#
+origsum=$(getsum /etc/passwd)
+
+#
+# Setup or recover the test environment. Firstly, copy /etc/passwd to ZFS file
+# system or volume, then make a snapshot or clone. Repeat up to three times.
+#
+# $1 number of snapshot. Note: Currently only support three snapshots.
+# $2 indicate if it is necessary to create clone
+#
+function setup_snap_env
+{
+	typeset -i cnt=${1:-3}
+	typeset createclone=${2:-"false"}
+
+	if datasetnonexists $FS; then
+		log_must $ZFS create $FS
+		log_must $ZFS set mountpoint=$TESTDIR $FS
+	fi
+	# Volume can't be created in Local Zone.
+	if datasetnonexists $VOL && is_global_zone; then
+		log_must $ZFS create -V $VOLSIZE $VOL
+	fi
+
+	# Make sure $VOL is volume
+	typeset type=$(get_prop type $VOL)
+	if datasetexists $VOL && \
+		[[ $type == 'volume' ]]; then
+		#
+		# At the first time, Make a UFS file system in volume and
+		# mount it. Otherwise, only check if this ufs file system
+		# was mounted.
+		#
+		log_must eval "$ECHO "y" | \
+			$NEWFS -v /dev/zvol/dsk/$VOL > /dev/null 2>&1"
+
+		[[ ! -d $TESTDIR1 ]] && log_must $MKDIR $TESTDIR1
+
+		# Make sure the ufs filesystem hasn't been mounted,
+		# then mount the new ufs filesystem.
+		$DF -lhF ufs "/dev/zvol/dsk/$VOL" > /dev/null 2>&1
+		if (( $? != 0 )); then
+			log_must $MOUNT \
+				/dev/zvol/dsk/$TESTPOOL/$TESTVOL $TESTDIR1
+		fi
+	fi
+
+	# Separately Create three snapshots for file system & volume
+	typeset -i ind=0
+	typeset dtst
+	for dtst in $FS $VOL; do
+		# Volume can be created in Local Zone.
+		if [[ $dtst == $VOL ]]; then
+			if ! is_global_zone; then
+				break
+			fi
+		fi
+
+		ind=0
+		while (( ind < cnt )); do
+			case $dtst in
+			$FS)
+				eval typeset snap=\$FSSNAP$ind
+				eval typeset clone=\$FSCLONE$ind
+				eval typeset fname=\$TESTDIR/\$TESTFILE$ind
+				;;
+			$VOL)
+				eval typeset snap=\$VOLSNAP$ind
+				eval typeset clone=\$VOLCLONE$ind
+				eval typeset fname=\$TESTDIR1/\$TESTFILE$ind
+				;;
+			esac
+
+			if datasetnonexists $snap; then
+				log_must $CP /etc/passwd $fname
+				#
+				# using 'lockfs -f' to flush the writes to disk
+				# before taking a snapshot.
+				#
+				if [[ $dtst == $VOL ]]; then
+					log_must /usr/sbin/lockfs -f $TESTDIR1
+				fi
+				log_must $ZFS snapshot $snap
+			fi
+			if [[ $createclone == "true" ]]; then
+				if datasetnonexists $clone; then
+					log_must $ZFS clone $snap $clone
+				fi
+			fi
+			(( ind += 1 ))
+		done
+	done
+}
+
+function setup_clone_env
+{
+	setup_snap_env $1 "true"
+}
+
+#
+# Clean up the test environmnet
+#
+# $1 number of snapshot Note: Currently only support three snapshots.
+#
+function cleanup_env
+{
+	typeset -i cnt=${1:-3}
+	typeset -i ind=0
+	typeset dtst
+	typeset snap
+
+	$PKILL ${DD##*/}
+
+	$DF -lhF ufs "/dev/zvol/dsk/$VOL" > /dev/null 2>&1
+	if (( $? == 0 )); then
+		log_must $UMOUNT -f $TESTDIR1
+	fi
+
+	[[ -d $TESTDIR ]] && log_must $RM -rf $TESTDIR/*
+	[[ -d $TESTDIR1 ]] && log_must $RM -rf $TESTDIR1/*
+
+	for dtst in $FS $VOL; do
+		for snap in $TESTSNAP $TESTSNAP1 $TESTSNAP2; do
+			if snapexists $dtst@$snap; then
+				 log_must $ZFS destroy -Rf $dtst@$snap
+			fi
+		done
+	done
+
+	# Restore original test environment
+	if datasetnonexists $FS ; then
+		log_must $ZFS create $FS
+	fi
+	if datasetnonexists $VOL ; then
+		if is_global_zone ; then
+			log_must $ZFS create -V $VOLSIZE $VOL
+		else
+			log_must $ZFS create $VOL
+		fi
+	fi
+}
+
+#
+# check if the specified files have specified status.
+#
+# $1 expected status
+# $2-n full file name
+# If it is true return 0, else return 1
+#
+function file_status
+{
+	(( $# == 0 )) && \
+		log_fail "The file name is not defined."
+
+	typeset opt
+	case $1 in
+		exist)	opt="-e" ;;
+		nonexist) opt="! -e" ;;
+		*)	log_fail "Unsupported file status." ;;
+	esac
+
+	shift
+	while (( $# > 0 )); do
+		eval [[ $opt $1 ]] || return 1
+		shift
+	done
+
+	return 0
+}
+
+function files_exist
+{
+	file_status "exist" $@
+}
+
+function files_nonexist
+{
+	file_status "nonexist" $@
+}
+
+#
+# According to snapshot check if the file system was recovered to the right
+# point.
+#
+# $1 snapshot. fs@snap or vol@snap
+#
+function check_files
+{
+	typeset dtst=$1
+
+	if [[ $(get_prop type $dtst) != snapshot ]]; then
+		log_fail "Parameter must be a snapshot."
+	fi
+
+	typeset fsvol=${dtst%%@*}
+	typeset snap=${dtst##*@}
+	if [[ $(get_prop type $fsvol) == "filesystem" ]]; then
+		ind=""
+	else
+		ind="1"
+	fi
+
+	eval typeset file0=\$TESTDIR$ind/\$TESTFILE0
+	eval typeset file1=\$TESTDIR$ind/\$TESTFILE1
+	eval typeset file2=\$TESTDIR$ind/\$TESTFILE2
+
+	case $snap in
+		$TESTSNAP2)
+			log_must files_exist $file0 $file1 $file2
+
+			typeset sum0=$(getsum $file0)
+			typeset sum1=$(getsum $file1)
+			typeset sum2=$(getsum $file2)
+			if [[ $sum0 != $origsum || \
+				$sum1 != $origsum || sum2 != $origsum ]]
+			then
+				log_fail "After rollback, file sum is changed."
+			fi
+			;;
+		$TESTSNAP1)
+			log_must files_exist $file0 $file1
+			log_must files_nonexist $file2
+
+			typeset sum0=$(getsum $file0)
+			typeset sum1=$(getsum $file1)
+			if [[ $sum0 != $origsum || $sum1 != $origsum ]]
+			then
+				log_fail "After rollback, file sum is changed."
+			fi
+			;;
+		$TESTSNAP)
+			log_must files_exist $file0
+			log_must files_nonexist $file1 $file2
+
+			typeset sum0=$(getsum $file0)
+			if [[ $sum0 != $origsum ]]; then
+				log_fail "After rollback, file sum is changed."
+			fi
+			;;
+	esac
+}
+
+# According to dataset type, write file to different directories.
+#
+# $1 dataset
+#
+function write_mountpoint_dir
+{
+	typeset dtst=$1
+	typeset dir
+
+	if [[ $dtst == $FS ]]; then
+		dir=$TESTDIR
+		log_must ismounted $dir
+	else
+		dir=$TESTDIR1
+		log_must ismounted $dir "ufs"
+	fi
+	$DD if=/dev/urandom of=$dir/$TESTFILE1 &
+	log_must $SLEEP 3
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/usr/src/test/zfs-tests/tests/functional/cli_root/zfs_send/Makefile	Wed Dec 05 22:04:50 2012 -0500
@@ -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) 2012 by Delphix. All rights reserved.
+#
+
+include $(SRC)/Makefile.master
+
+ROOTOPTPKG = $(ROOT)/opt/zfs-tests
+TESTDIR = $(ROOTOPTPKG)/tests/functional/cli_root/zfs_send
+
+PROGS = cleanup \
+	setup \
+	zfs_send_001_pos \
+	zfs_send_002_pos \
+	zfs_send_003_pos \
+	zfs_send_004_neg \
+	zfs_send_005_pos \
+	zfs_send_006_pos
+
+FILES = zfs_send.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	Thu Jan 01 00:00:00 1970 +0000
+++ b/usr/src/test/zfs-tests/tests/functional/cli_root/zfs_send/cleanup.ksh	Wed Dec 05 22:04:50 2012 -0500
@@ -0,0 +1,33 @@
+#!/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.
+#
+
+. $STF_SUITE/include/libtest.shlib
+
+poolexists $TESTPOOL1 && \
+	destroy_pool $TESTPOOL1
+
+default_cleanup
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/usr/src/test/zfs-tests/tests/functional/cli_root/zfs_send/setup.ksh	Wed Dec 05 22:04:50 2012 -0500
@@ -0,0 +1,32 @@
+#!/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.
+#
+
+. $STF_SUITE/include/libtest.shlib
+
+DISK=${DISKS%% *}
+
+default_setup $DISK
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/usr/src/test/zfs-tests/tests/functional/cli_root/zfs_send/zfs_send.cfg	Wed Dec 05 22:04:50 2012 -0500
@@ -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 2007 Sun Microsystems, Inc.  All rights reserved.
+# Use is subject to license terms.
+#
+
+#
+# Copyright (c) 2012 by Delphix. All rights reserved.
+#
+
+export BLOCK_SIZE=512
+export WRITE_COUNT=8
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/usr/src/test/zfs-tests/tests/functional/cli_root/zfs_send/zfs_send_001_pos.ksh	Wed Dec 05 22:04:50 2012 -0500
@@ -0,0 +1,127 @@
+#!/bin/ksh -p
+#
+# CDDL HEADER START
+#
+# The contents of this file are subject to the terms of the
+# Common Development and Distribution License (the "License").
+# You may not use this file except in compliance with the License.
+#
+# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
+# or http://www.opensolaris.org/os/licensing.
+# See the License for the specific language governing permissions
+# and limitations under the License.
+#
+# When distributing Covered Code, include this CDDL HEADER in each
+# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
+# If applicable, add the following below this CDDL HEADER, with the
+# fields enclosed by brackets "[]" replaced with your own identifying
+# information: Portions Copyright [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.
+#
+
+. $STF_SUITE/tests/functional/cli_root/cli_common.kshlib
+. $STF_SUITE/tests/functional/cli_root/zfs_send/zfs_send.cfg
+
+#
+# DESCRIPTION:
+#	Verify 'zfs send' can create valid send streams as expected.
+#
+# STRATEGY:
+#	1. Fill in fs with some data
+#	2. Create a full send streams with the fs
+#	3. Receive the send stream and verify the data integrity
+#	4. Fill in fs with some new data
+#	5. Create an incremental send stream with the fs
+#	6. Receive the incremental send stream and verify the data integrity.
+#
+
+verify_runnable "both"
+
+function cleanup
+{
+	for snap in $init_snap $inc_snap $rst_snap $rst_inc_snap; do
+                snapexists $snap && \
+                        log_must $ZFS destroy -f $snap
+        done
+
+	datasetexists $rst_root && \
+		log_must $ZFS destroy -Rf $rst_root
+
+	for file in $full_bkup $inc_bkup \
+			$init_data $inc_data
+	do
+		[[ -e $file ]] && \
+			log_must $RM -f $file
+	done
+
+	[[ -d $TESTDIR1 ]] && \
+		log_must $RM -rf $TESTDIR1
+
+}
+
+log_assert "Verify 'zfs send' can create valid send streams as expected."
+log_onexit cleanup
+
+init_snap=$TESTPOOL/$TESTFS@init_snap
+inc_snap=$TESTPOOL/$TESTFS@inc_snap
+full_bkup=/var/tmp/fullbkup.$$
+inc_bkup=/var/tmp/incbkup.$$
+init_data=$TESTDIR/$TESTFILE1
+inc_data=$TESTDIR/$TESTFILE2
+orig_sum=""
+rst_sum=""
+rst_root=$TESTPOOL/rst_ctr
+rst_snap=$rst_root/$TESTFS@init_snap
+rst_inc_snap=$rst_root/$TESTFS@inc_snap
+rst_data=$TESTDIR1/$TESTFS/$TESTFILE1
+rst_inc_data=$TESTDIR1/$TESTFS/$TESTFILE2
+
+
+log_note "Verify 'zfs send' can create full send stream."
+
+#Pre-paration
+log_must $ZFS create $rst_root
+[[ ! -d $TESTDIR1 ]] && \
+	log_must $MKDIR -p $TESTDIR1
+log_must $ZFS set mountpoint=$TESTDIR1 $rst_root
+
+$FILE_WRITE -o create -f $init_data -b $BLOCK_SIZE -c $WRITE_COUNT
+
+log_must $ZFS snapshot $init_snap
+$ZFS send $init_snap > $full_bkup
+(( $? != 0 )) && \
+	log_fail "'$ZFS send' fails to create full send"
+
+log_note "Verify the send stream is valid to receive."
+
+log_must $ZFS receive $rst_snap <$full_bkup
+receive_check $rst_snap ${rst_snap%%@*}
+compare_cksum $init_data $rst_data
+
+log_note "Verify 'zfs send -i' can create incremental send stream."
+
+$FILE_WRITE -o create -f $inc_data -b $BLOCK_SIZE -c $WRITE_COUNT -d 0
+
+log_must $ZFS snapshot $inc_snap
+$ZFS send -i $init_snap $inc_snap > $inc_bkup
+(( $? != 0 )) && \
+	log_fail "'$ZFS send -i' fails to create incremental send"
+
+log_note "Verify the incremental send stream is valid to receive."
+
+log_must $ZFS rollback $rst_snap
+log_must $ZFS receive $rst_inc_snap <$inc_bkup
+receive_check $rst_inc_snap
+compare_cksum $inc_data $rst_inc_data
+
+log_pass "Verifying 'zfs receive' succeed."
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/usr/src/test/zfs-tests/tests/functional/cli_root/zfs_send/zfs_send_002_pos.ksh	Wed Dec 05 22:04:50 2012 -0500
@@ -0,0 +1,139 @@
+#!/bin/ksh -p
+#
+# CDDL HEADER START
+#
+# The contents of this file are subject to the terms of the
+# Common Development and Distribution License (the "License").
+# You may not use this file except in compliance with the License.
+#
+# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
+# or http://www.opensolaris.org/os/licensing.
+# See the License for the specific language governing permissions
+# and limitations under the License.
+#
+# When distributing Covered Code, include this CDDL HEADER in each
+# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
+# If applicable, add the following below this CDDL HEADER, with the
+# fields enclosed by brackets "[]" replaced with your own identifying
+# information: Portions Copyright [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.
+#
+
+. $STF_SUITE/tests/functional/cli_root/cli_common.kshlib
+. $STF_SUITE/tests/functional/cli_root/zfs_send/zfs_send.cfg
+
+#
+# DESCRIPTION:
+#	Verify 'zfs send' can generate valid streams with a property setup.
+#
+# STRATEGY:
+#	1. Setup property for filesystem
+#	2. Fill in some data into filesystem
+#	3. Create a full send streams
+#	4. Receive the send stream
+#	5. Verify the receive result
+#
+
+verify_runnable "both"
+
+function cleanup
+{
+	snapexists $snap && \
+		log_must $ZFS destroy $snap
+
+	datasetexists $ctr && \
+		log_must $ZFS destroy -r $ctr
+
+	[[ -e $origfile ]] && \
+		log_must $RM -f $origfile
+
+	[[ -e $stream ]] && \
+		log_must $RM -f $stream
+}
+
+function do_testing # <prop> <prop_value>
+{
+	typeset property=$1
+	typeset prop_val=$2
+
+	log_must $ZFS set $property=$prop_val $fs
+	$FILE_WRITE -o create -f $origfile -b $BLOCK_SIZE -c $WRITE_COUNT
+	log_must $ZFS snapshot $snap
+	$ZFS send $snap > $stream
+	(( $? != 0 )) && \
+		log_fail "'$ZFS send' fails to create send streams."
+	$ZFS receive -d $ctr <$stream
+	(( $? != 0 )) && \
+		log_fail "'$ZFS receive' fails to receive send streams."
+
+	#verify receive result
+	! datasetexists $rstfs && \
+		log_fail "'$ZFS receive' fails to restore $rstfs"
+	! snapexists $rstfssnap && \
+		log_fail "'$ZFS receive' fails to restore $rstfssnap"
+	if [[ ! -e $rstfile ]] || [[ ! -e $rstsnapfile ]]; then
+		log_fail " Data lost after receiving stream"
+	fi
+
+	compare_cksum $origfile $rstfile
+	compare_cksum $origsnapfile $rstsnapfile
+
+	#Destroy datasets and stream for next testing
+	log_must $ZFS destroy $snap
+	if is_global_zone ; then
+		log_must $ZFS destroy -r $rstfs
+	else
+		log_must $ZFS destroy -r $ds_path
+	fi
+	log_must $RM -f $stream
+}
+
+log_assert "Verify 'zfs send' generates valid streams with a property setup"
+log_onexit cleanup
+
+fs=$TESTPOOL/$TESTFS
+snap=$fs@$TESTSNAP
+ctr=$TESTPOOL/$TESTCTR
+if is_global_zone; then
+	rstfs=$ctr/$TESTFS
+else
+	ds_path=$ctr/${ZONE_CTR}0
+	rstfs=$ds_path/$TESTFS
+fi
+rstfssnap=$rstfs@$TESTSNAP
+snapdir=".zfs/snapshot/$TESTSNAP"
+origfile=$TESTDIR/$TESTFILE1
+rstfile=/$rstfs/$TESTFILE1
+origsnapfile=$TESTDIR/$snapdir/$TESTFILE1
+rstsnapfile=/$rstfs/$snapdir/$TESTFILE1
+stream=/var/tmp/streamfile.$$
+
+set -A props "compression" "checksum" "recordsize"
+set -A propval "on lzjb" "on fletcher2 fletcher4 sha256" \
+	"512 1k 4k 8k 16k 32k 64k 128k"
+
+#Create a dataset to receive the send stream
+log_must $ZFS create $ctr
+
+typeset -i i=0
+while (( i < ${#props[*]} ))
+do
+	for value in ${propval[i]}
+	do
+		do_testing ${props[i]} $value
+	done
+
+	(( i = i + 1 ))
+done
+
+log_pass "'zfs send' generates streams with a property setup as expected."
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/usr/src/test/zfs-tests/tests/functional/cli_root/zfs_send/zfs_send_003_pos.ksh	Wed Dec 05 22:04:50 2012 -0500
@@ -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.
+#
+
+. $STF_SUITE/include/libtest.shlib
+
+#
+# DESCRIPTION:
+#	'zfs send -i' can deal with abbreviated snapshot name.
+#
+# STRATEGY:
+#	1. Create pool, fs and two snapshots.
+#	2. Make sure 'zfs send -i' support abbreviated snapshot name.
+#
+
+verify_runnable "both"
+
+function cleanup
+{
+	datasetexists $snap1 && log_must $ZFS destroy $snap1
+	datasetexists $snap2 && log_must $ZFS destroy $snap2
+}
+
+log_assert "'zfs send -i' can deal with abbreviated snapshot name."
+log_onexit cleanup
+
+snap1=$TESTPOOL/$TESTFS@snap1; snap2=$TESTPOOL/$TESTFS@snap2
+
+set -A args "$snap1 $snap2" \
+	"${snap1##*@} $snap2" "@${snap1##*@} $snap2"
+
+log_must $ZFS snapshot $snap1
+log_must $ZFS snapshot $snap2
+
+typeset -i i=0
+while (( i < ${#args[*]} )); do
+	log_must eval "$ZFS send -i ${args[i]} > /dev/null"
+
+	(( i += 1 ))
+done
+
+log_pass "'zfs send -i' deal with abbreviated snapshot name passed."
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/usr/src/test/zfs-tests/tests/functional/cli_root/zfs_send/zfs_send_004_neg.ksh	Wed Dec 05 22:04:50 2012 -0500
@@ -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.
+#
+
+. $STF_SUITE/tests/functional/cli_root/cli_common.kshlib
+
+#
+# DESCRIPTION:
+#	Verify 'zfs send' fails with malformed parameters.
+#
+# STRATEGY:
+#	1. Define malformed parameters in array
+#	2. Feed the parameters to 'zfs send'
+#	3. Verify the result
+#
+
+verify_runnable "both"
+
+function cleanup
+{
+	typeset snap f
+
+	for snap in $snap1 $snap2 $snap3; do
+		snapexists $snap && \
+			log_must $ZFS destroy -f $snap
+	done
+
+	for f in $tmpfile1 $tmpfile2; do
+		if [[ -e $f ]]; then
+			$RM -f $f
+		fi
+	done
+}
+
+fs=$TESTPOOL/$TESTFS
+snap1=$fs@snap1
+snap2=$fs@snap2
+snap3=$fs@snap3
+
+set -A badargs \
+	"" "$TESTPOOL" "$TESTFS" "$fs" "$fs@nonexisten_snap" "?" \
+	"$snap1/blah" "$snap1@blah" "-i" "-x" "-i $fs" \
+	"-x $snap1 $snap2" "-i $snap1" \
+	"-i $snap2 $snap1" "$snap1 $snap2" "-i $snap1 $snap2 $snap3" \
+	"-ii $snap1 $snap2" "-iii $snap1 $snap2" " -i $snap2 $snap1/blah" \
+	"-i $snap2/blah $snap1" \
+	"-i $snap2/blah $snap1/blah" \
+	"-i $snap1 blah@blah" \
+	"-i blah@blah $snap1" \
+	"-i $snap1 ${snap2##*@}" "-i $snap1 @${snap2##*@}" \
+	"-i ${snap1##*@} ${snap2##*@}" "-i @${snap1##*@} @${snap2##*@}" \
+	"-i ${snap1##*@} $snap2/blah" "-i @${snap1##*@} $snap2/blah" \
+	"-i @@${snap1##*@} $snap2" "-i $snap1 -i $snap1 $snap2" \
+	"-i snap1 snap2" "-i $snap1 snap2" \
+	"-i $snap1 $snap2 -i $snap1 $snap2" \
+	"-i snap1 $snap2 -i snap1 $snap2"
+
+log_assert "Verify that invalid parameters to 'zfs send' are caught."
+log_onexit cleanup
+
+log_must $ZFS snapshot $snap1
+tmpfile1=$TESTDIR/testfile1.$$
+log_must $TOUCH $tmpfile1
+log_must $ZFS snapshot $snap2
+tmpfile2=$TESTDIR/testfile2.$$
+log_must $TOUCH $tmpfile2
+log_must $ZFS snapshot $snap3
+
+typeset -i i=0
+while (( i < ${#badargs[*]} ))
+do
+	log_mustnot eval "$ZFS send ${badargs[i]} >/dev/null"
+
+	(( i = i + 1 ))
+done
+
+#Testing zfs send fails by send backup stream to terminal
+for arg in "$snap1" "-i $snap1 $snap2"; do
+	log_mustnot eval "$ZFS send $arg >/dev/console"
+done
+
+log_pass "Invalid parameters to 'zfs send' are caught as expected."
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/usr/src/test/zfs-tests/tests/functional/cli_root/zfs_send/zfs_send_005_pos.ksh	Wed Dec 05 22:04:50 2012 -0500
@@ -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) 2012 by Delphix. All rights reserved.
+#
+
+. $STF_SUITE/include/libtest.shlib
+
+#
+# DESCRIPTION:
+# 'zfs send -R' can send from read-only imported pool. It needs to
+# detect that the pool is read-only and not try to place holds on
+# datasets being sent.
+#
+# STRATEGY:
+# 1. Create a recursive snapshot on the whole pool.
+# 2. 'zfs send -R' the recursive snapshots.
+#
+
+verify_runnable "both"
+
+function cleanup
+{
+	poolexists $TESTPOOL && log_must $ZPOOL export $TESTPOOL
+	log_must $ZPOOL import $TESTPOOL
+
+	datasetexists $TESTPOOL@snap && \
+	    log_must $ZFS destroy -r $TESTPOOL@snap
+}
+
+log_assert "'zfs send -R' can send from read-only pools"
+log_onexit cleanup
+
+log_must $ZFS snapshot -r $TESTPOOL@snap
+
+log_must $ZPOOL export $TESTPOOL
+log_must $ZPOOL import -o readonly=on $TESTPOOL
+
+log_must eval "$ZFS send -R $TESTPOOL@snap >/dev/null"
+
+log_pass "'zfs send -R' can send from read-only pools"
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/usr/src/test/zfs-tests/tests/functional/cli_root/zfs_send/zfs_send_006_pos.ksh	Wed Dec 05 22:04:50 2012 -0500
@@ -0,0 +1,194 @@
+#!/bin/ksh
+#
+# CDDL HEADER START
+#
+# 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.
+#
+# CDDL HEADER END
+#
+
+#
+# Copyright (c) 2012 by Delphix. All rights reserved.
+#
+
+. $STF_SUITE/include/libtest.shlib
+#
+# DESCRIPTION:
+#	Verify 'zfs send' can generate valid streams with different options
+#
+# STRATEGY:
+#	1. Create datasets
+#	2. Write some data to the datasets
+#	3. Create a full send streams
+#	4. Receive the send stream
+#	5. Do a dry run with different options and verify the generated size
+#          estimate against the received stream
+#
+
+verify_runnable "both"
+
+function cleanup
+{
+	for ds in $datasets; do
+                datasetexists $ds && $ZFS destroy -rf $ds
+	done
+}
+
+function cal_percentage
+{
+	typeset value=$1
+	return=$($ECHO "$PERCENT * $value" | bc)
+	return=$($ECHO "$return / 100" | bc)
+	echo $return
+}
+
+function get_estimate_size
+{
+	typeset snapshot=$1
+	typeset option=$2
+	typeset base_snapshot=${3:-""}
+	if [[ -z $3 ]];then
+		typeset total_size=$($ZFS send $option $snapshot 2>&1 | $TAIL -1)
+	else
+		typeset total_size=$($ZFS send $option $base_snapshot $snapshot \
+		     2>&1 | $TAIL -1)
+	fi
+	if [[ $options == *"P"* ]]; then
+		total_size=$($ECHO "$total_size" | $AWK '{print $2}')
+	else
+		total_size=$($ECHO "$total_size" | $AWK '{print $5}')
+		total_size=${total_size%M}
+		total_size=$($ECHO "$total_size * $block_count" | bc)
+	fi
+	$ECHO $total_size
+
+}
+
+function verify_size_estimates
+{
+	typeset options=$1
+	typeset file_size=$2
+	typeset refer_diff=$($ECHO "$refer_size - $estimate_size" | bc)
+	refer_diff=$($ECHO "$refer_diff / 1" | bc)
+	refer_diff=$($ECHO "$refer_diff" | $NAWK '{print ($1 < 0) ? ($1 * -1): $1'})
+	typeset file_diff=$($ECHO "$file_size - $estimate_size" | bc)
+	file_diff=$($ECHO "$file_diff / 1" | bc)
+	file_diff=$($ECHO "$file_diff" | $NAWK '{print ($1 < 0) ? ($1 * -1):$1'})
+	typeset expected_diff=$(cal_percentage $refer_size)
+
+	[[ -z $refer_diff && -z $file_diff && -z $expected_diff ]] && \
+	    log_fail "zfs send $options failed"
+	[[ $refer_diff -le $expected_diff &&  \
+	    $file_diff -le $expected_diff ]] || \
+	    log_fail "zfs send $options gives wrong size estimates"
+}
+
+log_assert "Verify 'zfs send -nvP' generates valid stream estimates"
+log_onexit cleanup
+typeset -l block_count=0
+typeset -l block_size
+typeset -i PERCENT=1
+
+((block_count=1024*1024))
+
+# create dataset
+log_must $ZFS create $TESTPOOL/$TESTFS1
+
+# create multiple snapshot for the dataset with data
+for block_size in 64 128 256; do
+	log_must $DD if=/dev/urandom of=/$TESTPOOL/$TESTFS1/file$block_size \
+	    bs=1M count=$block_size
+	log_must $ZFS snapshot $TESTPOOL/$TESTFS1@snap$block_size
+done
+
+full_snapshot="$TESTPOOL/$TESTFS1@snap64"
+increamental_snapshot="$TESTPOOL/$TESTFS1@snap256"
+
+full_size=$($ZFS send $full_snapshot 2>&1 | wc -c)
+increamental_size=$($ZFS send $increamental_snapshot 2>&1 | wc -c)
+increamental_send=$($ZFS send -i $full_snapshot $increamental_snapshot 2>&1 | wc -c)
+
+log_note "verify zfs send -nv"
+options="-nv"
+refer_size=$(get_prop refer $full_snapshot)
+estimate_size=$(get_estimate_size $full_snapshot $options)
+log_must verify_size_estimates $options $full_size
+
+log_note "verify zfs send -Pnv"
+options="-Pnv"
+
+estimate_size=$(get_estimate_size $full_snapshot $options)
+log_must verify_size_estimates $options $full_size
+
+log_note "verify zfs send -nv for multiple snapshot send"
+options="-nv"
+refer_size=$(get_prop refer $increamental_snapshot)
+
+estimate_size=$(get_estimate_size $increamental_snapshot $options)
+log_must verify_size_estimates $options $increamental_size
+
+log_note "verify zfs send -vPn for multiple snapshot send"
+options="-vPn"
+
+estimate_size=$(get_estimate_size $increamental_snapshot $options)
+log_must verify_size_estimates $options $increamental_size
+
+log_note "verify zfs send -inv for increamental send"
+options="-nvi"
+refer_size=$(get_prop refer $increamental_snapshot)
+deduct_size=$(get_prop refer $full_snapshot)
+refer_size=$($ECHO "$refer_size - $deduct_size" | bc)
+
+estimate_size=$(get_estimate_size $increamental_snapshot $options $full_snapshot)
+log_must verify_size_estimates $options $increamental_send
+
+log_note "verify zfs send -ivPn for increamental send"
+options="-vPni"
+
+estimate_size=$(get_estimate_size $increamental_snapshot $options $full_snapshot)
+log_must verify_size_estimates $options $increamental_send
+
+log_must $ZFS destroy -r $TESTPOOL/$TESTFS1
+
+#setup_recursive_send
+datasets="$TESTPOOL/$TESTFS1 $TESTPOOL/$TESTFS1/$TESTFS2
+    $TESTPOOL/$TESTFS1/$TESTFS2/$TESTFS3"
+# create nested datasets
+log_must $ZFS create -p $TESTPOOL/$TESTFS1/$TESTFS2/$TESTFS3
+
+# verify dataset creation
+for ds in $datasets; do
+        datasetexists $ds || log_fail "Create $ds dataset fail."
+done
+for ds in $datasets; do
+	log_must $DD if=/dev/urandom of=/$ds/file64 \
+	    bs=1M count=64
+done
+
+# create recursive nested snapshot
+log_must $ZFS snapshot -r $TESTPOOL/$TESTFS1@snap64
+for ds in $datasets; do
+        datasetexists $ds@snap64 || log_fail "Create $ds@snap64 snapshot fail."
+done
+recursive_size=$($ZFS send -R $full_snapshot 2>&1 | wc -c)
+log_note "verify zfs send -Rnv for recursive send"
+options="-Rnv"
+refer_size=$(get_prop refer $full_snapshot)
+refer_size=$($ECHO "$refer_size * 3" | bc)
+
+estimate_size=$(get_estimate_size $full_snapshot $options)
+log_must verify_size_estimates $options $recursive_size
+
+log_note "verify zfs send -RvPn for recursive send"
+options="-RvPn"
+estimate_size=$(get_estimate_size $full_snapshot $options)
+log_must verify_size_estimates $options $recursive_size
+
+log_pass "'zfs send' prints the correct size estimates using '-n' and '-P' options."
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/usr/src/test/zfs-tests/tests/functional/cli_root/zfs_set/Makefile	Wed Dec 05 22:04:50 2012 -0500
@@ -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) 2012 by Delphix. All rights reserved.
+#
+
+include $(SRC)/Makefile.master
+
+ROOTOPTPKG = $(ROOT)/opt/zfs-tests
+TESTDIR = $(ROOTOPTPKG)/tests/functional/cli_root/zfs_set
+
+PROGS = cleanup \
+	setup \
+	cache_001_pos \
+	cache_002_neg \
+	canmount_001_pos \
+	canmount_002_pos \
+	canmount_003_pos \
+	canmount_004_pos \
+	checksum_001_pos \
+	compression_001_pos \
+	mountpoint_001_pos \
+	mountpoint_002_pos \
+	mountpoint_003_pos \
+	onoffs_001_pos \
+	property_alias_001_pos \
+	readonly_001_pos \
+	reservation_001_neg \
+	ro_props_001_pos \
+	share_mount_001_neg \
+	snapdir_001_pos \
+	user_property_001_pos \
+	user_property_002_pos \
+	user_property_003_neg \
+	user_property_004_pos \
+	version_001_neg \
+	zfs_set_001_neg \
+	zfs_set_002_neg \
+	zfs_set_003_neg
+
+FILES = zfs_set_common.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	Thu Jan 01 00:00:00 1970 +0000
+++ b/usr/src/test/zfs-tests/tests/functional/cli_root/zfs_set/cache_001_pos.ksh	Wed Dec 05 22:04:50 2012 -0500
@@ -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.
+#
+
+. $STF_SUITE/include/libtest.shlib
+. $STF_SUITE/tests/functional/cli_root/zfs_set/zfs_set_common.kshlib
+
+#
+# DESCRIPTION:
+# Setting a valid primarycache and secondarycache on file system or volume.
+# It should be successful.
+#
+# STRATEGY:
+# 1. Create pool, then create filesystem & volume within it.
+# 2. Setting valid cache value, it should be successful.
+#
+
+verify_runnable "both"
+
+set -A dataset "$TESTPOOL" "$TESTPOOL/$TESTFS" "$TESTPOOL/$TESTVOL"
+set -A values  "none" "all" "metadata"
+
+log_assert "Setting a valid {primary|secondary}cache on file system and volume, " \
+	"It should be successful."
+
+typeset -i i=0
+typeset -i j=0
+for propname in "primarycache" "secondarycache"
+do
+	while (( i < ${#dataset[@]} )); do
+		j=0
+		while (( j < ${#values[@]} )); do
+			set_n_check_prop "${values[j]}" "$propname" "${dataset[i]}"
+			(( j += 1 ))
+		done
+		(( i += 1 ))
+	done
+done
+
+log_pass "Setting a valid {primary|secondary}cache on file system or volume pass."
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/usr/src/test/zfs-tests/tests/functional/cli_root/zfs_set/cache_002_neg.ksh	Wed Dec 05 22:04:50 2012 -0500
@@ -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.
+#
+
+. $STF_SUITE/include/libtest.shlib
+. $STF_SUITE/tests/functional/cli_root/zfs_set/zfs_set_common.kshlib
+
+#
+# DESCRIPTION:
+# Setting invalid primarycache and secondarycache on file system or volume.
+# It should fail.
+#
+# STRATEGY:
+# 1. Create pool, then create filesystem & volume within it.
+# 2. Setting invalid {primary|secondary}cache value, it should fail.
+#
+
+verify_runnable "both"
+
+set -A dataset "$TESTPOOL" "$TESTPOOL/$TESTFS" "$TESTPOOL/$TESTVOL"
+set -A values  "12345" "null" "not_existed" "abcd1234"
+
+log_assert "Setting invalid {primary|secondary}cache on fs and volume, " \
+	"It should fail."
+
+typeset -i i=0
+typeset -i j=0
+for propname in "primarycache" "secondarycache"
+do
+	while (( i < ${#dataset[@]} )); do
+		j=0
+		while (( j < ${#values[@]} )); do
+			log_mustnot $ZFS set $propname=${values[j]} ${dataset[i]}
+			(( j += 1 ))
+		done
+		(( i += 1 ))
+	done
+done
+
+log_pass "Setting invalid {primary|secondary}cache on fs or volume fail as expeced."
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/usr/src/test/zfs-tests/tests/functional/cli_root/zfs_set/canmount_001_pos.ksh	Wed Dec 05 22:04:50 2012 -0500
@@ -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 2009 Sun Microsystems, Inc.  All rights reserved.
+# Use is subject to license terms.
+#
+
+. $STF_SUITE/include/libtest.shlib
+. $STF_SUITE/tests/functional/cli_root/zfs_set/zfs_set_common.kshlib
+
+#
+# DESCRIPTION:
+# Setting valid canmount to filesystem, it is successful.
+# Whatever is set to volume or snapshot, it is failed.
+# 'zfs set canmount=on|off <fs>'
+#
+# STRATEGY:
+# 1. Setup a pool and create fs, volume, snapshot clone within it.
+# 2. Loop all the valid mountpoint value.
+# 3. Check the return value.
+#
+
+verify_runnable "both"
+
+set -A dataset_pos \
+	"$TESTPOOL/$TESTFS" "$TESTPOOL/$TESTCTR" "$TESTPOOL/$TESTCLONE"
+
+if is_global_zone ; then
+	set -A dataset_neg \
+		"$TESTPOOL/$TESTVOL" "$TESTPOOL/$TESTFS@$TESTSNAP" \
+		"$TESTPOOL/$TESTVOL@$TESTSNAP"  "$TESTPOOL/$TESTCLONE1"
+else
+	set -A dataset_neg \
+		"$TESTPOOL/$TESTFS@$TESTSNAP" "$TESTPOOL/$TESTVOL@$TESTSNAP"
+fi
+
+
+set -A values "on" "off"
+
+function cleanup
+{
+	if snapexists $TESTPOOL/$TESTFS@$TESTSNAP ; then
+		log_must $ZFS destroy -R $TESTPOOL/$TESTFS@$TESTSNAP
+	fi
+	if snapexists $TESTPOOL/$TESTVOL@$TESTSNAP ; then
+		log_must $ZFS destroy -R $TESTPOOL/$TESTVOL@$TESTSNAP
+	fi
+
+	[[ -n $old_ctr_canmount ]] && \
+		log_must $ZFS set canmount=$old_ctr_canmount $TESTPOOL/$TESTCTR
+	[[ -n $old_fs_canmount ]] && \
+		log_must $ZFS set canmount=$old_fs_canmount $TESTPOOL/$TESTFS
+
+	$ZFS unmount -a > /dev/null 2>&1
+	log_must $ZFS mount -a
+}
+
+log_assert "Setting a valid property of canmount to file system, it must be successful."
+log_onexit cleanup
+
+typeset old_fs_canmount="" old_ctr_canmount=""
+
+old_fs_canmount=$(get_prop canmount $TESTPOOL/$TESTFS)
+[[ $? != 0 ]] && \
+	log_fail "Get the $TESTPOOL/$TESTFS canmount error."
+old_ctr_canmount=$(get_prop canmount $TESTPOOL/$TESTCTR)
+[[ $? != 0 ]] && \
+	log_fail "Get the $TESTPOOL/$TESTCTR canmount error."
+
+log_must $ZFS snapshot $TESTPOOL/$TESTFS@$TESTSNAP
+log_must $ZFS snapshot $TESTPOOL/$TESTVOL@$TESTSNAP
+log_must $ZFS clone $TESTPOOL/$TESTFS@$TESTSNAP $TESTPOOL/$TESTCLONE
+log_must $ZFS clone $TESTPOOL/$TESTVOL@$TESTSNAP $TESTPOOL/$TESTCLONE1
+
+for dataset in "${dataset_pos[@]}" ; do
+	for value in "${values[@]}" ; do
+		set_n_check_prop "$value" "canmount" "$dataset"
+		if [[ $value == "off" ]]; then
+			log_mustnot ismounted $dataset
+			log_mustnot $ZFS mount $dataset
+			log_mustnot ismounted $dataset
+		else
+			if ! ismounted $dataset ; then
+				log_must $ZFS mount $dataset
+			fi
+			log_must ismounted $dataset
+		fi
+	done
+done
+
+for dataset in "${dataset_neg[@]}" ; do
+	for value in "${values[@]}" ; do
+		set_n_check_prop "$value" "canmount" \
+			"$dataset" "false"
+		log_mustnot ismounted $dataset
+	done
+done
+
+log_pass "Setting canmount to filesystem pass."
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/usr/src/test/zfs-tests/tests/functional/cli_root/zfs_set/canmount_002_pos.ksh	Wed Dec 05 22:04:50 2012 -0500
@@ -0,0 +1,150 @@
+#!/bin/ksh -p
+#
+# CDDL HEADER START
+#
+# The contents of this file are subject to the terms of the
+# Common Development and Distribution License (the "License").
+# You may not use this file except in compliance with the License.
+#
+# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
+# or http://www.opensolaris.org/os/licensing.
+# See the License for the specific language governing permissions
+# and limitations under the License.
+#
+# When distributing Covered Code, include this CDDL HEADER in each
+# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
+# If applicable, add the following below this CDDL 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) 2012 by Delphix. All rights reserved.
+#
+
+. $STF_SUITE/include/libtest.shlib
+. $STF_SUITE/tests/functional/cli_root/zfs_set/zfs_set_common.kshlib
+
+#
+# DESCRIPTION:
+# Setting valid canmount to filesystem, it is successful.
+# Whatever is set to volume or snapshot, it is failed.
+# 'zfs set canmount=noauto <fs>'
+#
+# STRATEGY:
+# 1. Setup a pool and create fs, volume, snapshot clone within it.
+# 2. Set canmount=noauto for each dataset and check the retuen value
+#    and check if it still can be mounted by mount -a.
+# 3. mount each dataset(except volume) to see if it can be mounted.
+#
+
+verify_runnable "both"
+
+set -A dataset_pos \
+	"$TESTPOOL/$TESTFS" "$TESTPOOL/$TESTCTR" "$TESTPOOL/$TESTCLONE"
+
+if is_global_zone ; then
+	set -A dataset_neg \
+		"$TESTPOOL/$TESTVOL" "$TESTPOOL/$TESTFS@$TESTSNAP" \
+		"$TESTPOOL/$TESTVOL@$TESTSNAP"  "$TESTPOOL/$TESTCLONE1"
+else
+	set -A dataset_neg \
+		"$TESTPOOL/$TESTFS@$TESTSNAP" "$TESTPOOL/$TESTVOL@$TESTSNAP"
+fi
+
+function cleanup
+{
+	i=0
+	while (( i < ${#dataset_pos[*]} )); do
+		ds=${dataset_pos[i]}
+		if datasetexists $ds; then
+			log_must $ZFS set mountpoint=${old_mnt[i]} $ds
+			log_must $ZFS set canmount=${old_canmount[i]} $ds
+		fi
+		(( i = i + 1 ))
+	done
+
+	ds=$TESTPOOL/$TESTCLONE
+	if datasetexists $ds; then
+		mntp=$(get_prop mountpoint $ds)
+		log_must $ZFS destroy $ds
+		if [[ -d $mntp ]]; then
+			$RM -fr $mntp
+		fi
+	fi
+
+	if snapexists $TESTPOOL/$TESTFS@$TESTSNAP ; then
+		log_must $ZFS destroy -R $TESTPOOL/$TESTFS@$TESTSNAP
+	fi
+	if snapexists $TESTPOOL/$TESTVOL@$TESTSNAP ; then
+		log_must $ZFS destroy -R $TESTPOOL/$TESTVOL@$TESTSNAP
+	fi
+
+	$ZFS unmount -a > /dev/null 2>&1
+	log_must $ZFS mount -a
+
+	if [[ -d $tmpmnt ]]; then
+		$RM -fr $tmpmnt
+	fi
+}
+
+log_assert "Setting canmount=noauto to file system, it must be successful."
+log_onexit cleanup
+
+set -A old_mnt
+set -A old_canmount
+typeset tmpmnt=/tmpmount$$
+typeset ds
+
+log_must $ZFS snapshot $TESTPOOL/$TESTFS@$TESTSNAP
+log_must $ZFS snapshot $TESTPOOL/$TESTVOL@$TESTSNAP
+log_must $ZFS clone $TESTPOOL/$TESTFS@$TESTSNAP $TESTPOOL/$TESTCLONE
+log_must $ZFS clone $TESTPOOL/$TESTVOL@$TESTSNAP $TESTPOOL/$TESTCLONE1
+
+typeset -i i=0
+while (( i < ${#dataset_pos[*]} )); do
+	ds=${dataset_pos[i]}
+	old_mnt[i]=$(get_prop mountpoint $ds)
+	old_canmount[i]=$(get_prop canmount $ds)
+	(( i = i + 1 ))
+done
+
+i=0
+while (( i < ${#dataset_pos[*]} )) ; do
+	dataset=${dataset_pos[i]}
+	set_n_check_prop "noauto" "canmount" "$dataset"
+	log_must $ZFS set mountpoint=$tmpmnt $dataset
+	if  ismounted $dataset; then
+		$ZFS unmount -a > /dev/null 2>&1
+		log_must mounted $dataset
+		log_must $ZFS unmount $dataset
+		log_must unmounted $dataset
+		log_must $ZFS mount -a
+		log_must unmounted $dataset
+	else
+		log_must $ZFS mount -a
+		log_must unmounted $dataset
+		$ZFS unmount -a > /dev/null 2>&1
+		log_must unmounted $dataset
+	fi
+
+	log_must $ZFS mount $dataset
+	log_must mounted $dataset
+	log_must $ZFS set canmount="${old_canmount[i]}" $dataset
+	log_must $ZFS set mountpoint="${old_mnt[i]}" $dataset
+	(( i = i + 1 ))
+done
+
+for dataset in "${dataset_neg[@]}" ; do
+	set_n_check_prop "noauto" "canmount" "$dataset" "false"
+	log_mustnot ismounted $dataset
+done
+
+log_pass "Setting canmount=noauto to filesystem pass."
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/usr/src/test/zfs-tests/tests/functional/cli_root/zfs_set/canmount_003_pos.ksh	Wed Dec 05 22:04:50 2012 -0500
@@ -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 2009 Sun Microsystems, Inc.  All rights reserved.
+# Use is subject to license terms.
+#
+
+#
+# Copyright (c) 2012 by Delphix. All rights reserved.
+#
+
+. $STF_SUITE/include/libtest.shlib
+. $STF_SUITE/tests/functional/cli_root/zfs_set/zfs_set_common.kshlib
+
+#
+# DESCRIPTION:
+# While canmount=noauto and  the dataset is mounted,
+# zfs must not attempt to unmount it.
+#
+# STRATEGY:
+# 1. Setup a pool and create fs, volume, snapshot clone within it.
+# 2. Set canmount=noauto for each dataset and check the return value
+#    and check if it still can not be unmounted when the dataset is mounted
+#
+
+verify_runnable "both"
+
+set -A dataset_pos "$TESTPOOL/$TESTFS" "$TESTPOOL/$TESTCLONE"
+
+function cleanup
+{
+	i=0
+	cd $pwd
+	while (( i < ${#dataset_pos[*]} )); do
+		ds=${dataset_pos[i]}
+		if datasetexists $ds; then
+			log_must $ZFS set mountpoint=${old_mnt[i]} $ds
+			log_must $ZFS set canmount=${old_canmount[i]} $ds
+		fi
+		(( i = i + 1 ))
+	done
+
+	ds=$TESTPOOL/$TESTCLONE
+	if datasetexists $ds; then
+		mntp=$(get_prop mountpoint $ds)
+		log_must $ZFS destroy $ds
+		if [[ -d $mntp ]]; then
+			log_must $RM -fr $mntp
+		fi
+	fi
+
+	if snapexists $TESTPOOL/$TESTFS@$TESTSNAP ; then
+		log_must $ZFS destroy -R $TESTPOOL/$TESTFS@$TESTSNAP
+	fi
+
+	$ZFS unmount -a > /dev/null 2>&1
+	log_must $ZFS mount -a
+}
+
+log_assert "While canmount=noauto and  the dataset is mounted,"\
+		" zfs must not attempt to unmount it"
+log_onexit cleanup
+
+set -A old_mnt
+set -A old_canmount
+typeset ds
+typeset pwd=$PWD
+
+log_must $ZFS snapshot $TESTPOOL/$TESTFS@$TESTSNAP
+log_must $ZFS clone $TESTPOOL/$TESTFS@$TESTSNAP $TESTPOOL/$TESTCLONE
+
+typeset -i i=0
+while (( i < ${#dataset_pos[*]} )); do
+	ds=${dataset_pos[i]}
+	old_mnt[i]=$(get_prop mountpoint $ds)
+	old_canmount[i]=$(get_prop canmount $ds)
+	(( i = i + 1 ))
+done
+
+i=0
+while (( i < ${#dataset_pos[*]} )) ; do
+	dataset=${dataset_pos[i]}
+	if  ismounted $dataset; then
+		log_must cd ${old_mnt[i]}
+		set_n_check_prop "noauto" "canmount" "$dataset"
+		log_must mounted $dataset
+	fi
+	(( i = i + 1 ))
+done
+
+log_pass "Setting canmount=noauto to filesystem while dataset busy pass."
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/usr/src/test/zfs-tests/tests/functional/cli_root/zfs_set/canmount_004_pos.ksh	Wed Dec 05 22:04:50 2012 -0500
@@ -0,0 +1,92 @@
+#!/bin/ksh -p
+#
+# CDDL HEADER START
+#
+# The contents of this file are subject to the terms of the
+# Common Development and Distribution License (the "License").
+# You may not use this file except in compliance with the License.
+#
+# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
+# or http://www.opensolaris.org/os/licensing.
+# See the License for the specific language governing permissions
+# and limitations under the License.
+#
+# When distributing Covered Code, include this CDDL HEADER in each
+# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
+# If applicable, add the following below this CDDL 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.
+#
+
+. $STF_SUITE/include/libtest.shlib
+
+#
+# DESCRIPTION:
+# Verify canmount=noauto work fine when setting sharenfs or sharesmb.
+#
+# STRATEGY:
+# 1. Create a fs canmount=noauto.
+# 2. Set sharenfs or sharesmb.
+# 3. Verify the fs is umounted.
+#
+
+verify_runnable "global"
+
+# properties
+set -A sharenfs_prop "off" "on" "rw"
+set -A sharesmb_prop "off" "on"
+
+function cleanup
+{
+	log_must $ZFS destroy -rR $CS_FS
+}
+
+function assert_unmounted
+{
+	mnted=$(get_prop mounted $CS_FS)
+	if [[ "$mnted" == "yes" ]]; then
+		canmnt=$(get_prop canmount $CS_FS)
+		shnfs=$(get_prop sharenfs $CS_FS)
+		shsmb=$(get_prop sharesmb $CS_FS)
+		mntpt=$(get_prop mountpoint $CS_FS)
+		log_fail "$CS_FS should be unmounted" \
+		"[canmount=$canmnt,sharenfs=$shnfs,sharesmb=$shsmb,mountpoint=$mntpt]."
+	fi
+}
+
+log_assert "Verify canmount=noauto work fine when setting sharenfs or sharesmb."
+log_onexit cleanup
+
+CS_FS=$TESTPOOL/$TESTFS/cs_fs.$$
+oldmpt=$TESTDIR/old_cs_fs.$$
+newmpt=$TESTDIR/new_cs_fs.$$
+
+log_must $ZFS create -o canmount=noauto -o mountpoint=$oldmpt $CS_FS
+assert_unmounted
+
+for n in ${sharenfs_prop[@]}; do
+	log_must $ZFS set sharenfs="$n" $CS_FS
+	assert_unmounted
+	for s in ${sharesmb_prop[@]}; do
+		log_must $ZFS set sharesmb="$s" $CS_FS
+		assert_unmounted
+
+		mntpt=$(get_prop mountpoint $CS_FS)
+		if [[ "$mntpt" == "$oldmpt" ]]; then
+			log_must $ZFS set mountpoint="$newmpt" $CS_FS
+		else
+			log_must $ZFS set mountpoint="$oldmpt" $CS_FS
+		fi
+		assert_unmounted
+	done
+done
+
+log_pass "Verify canmount=noauto work fine when setting sharenfs or sharesmb."
+
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/usr/src/test/zfs-tests/tests/functional/cli_root/zfs_set/checksum_001_pos.ksh	Wed Dec 05 22:04:50 2012 -0500
@@ -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) 2012 by Delphix. All rights reserved.
+#
+
+. $STF_SUITE/include/libtest.shlib
+. $STF_SUITE/tests/functional/cli_root/zfs_set/zfs_set_common.kshlib
+
+#
+# DESCRIPTION:
+# Setting a valid checksum on a pool, file system, volume, it should be
+# successful.
+#
+# STRATEGY:
+# 1. Create pool, then create filesystem and volume within it.
+# 2. Setting different valid checksum to each dataset.
+# 3. Check the return value and make sure it is 0.
+#
+
+verify_runnable "both"
+
+set -A dataset "$TESTPOOL" "$TESTPOOL/$TESTFS" "$TESTPOOL/$TESTVOL"
+set -A values "on" "off" "fletcher2" "fletcher4" "sha256"
+
+log_assert "Setting a valid checksum on a file system, volume," \
+	"it should be successful."
+
+typeset -i i=0
+typeset -i j=0
+while (( i < ${#dataset[@]} )); do
+	j=0
+	while (( j < ${#values[@]} )); do
+		set_n_check_prop "${values[j]}" "checksum" "${dataset[i]}"
+		(( j += 1 ))
+	done
+	(( i += 1 ))
+done
+
+log_pass "Setting a valid checksum on a file system, volume pass."
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/usr/src/test/zfs-tests/tests/functional/cli_root/zfs_set/cleanup.ksh	Wed Dec 05 22:04:50 2012 -0500
@@ -0,0 +1,30 @@
+#!/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.
+#
+
+. $STF_SUITE/include/libtest.shlib
+
+default_container_cleanup
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/usr/src/test/zfs-tests/tests/functional/cli_root/zfs_set/compression_001_pos.ksh	Wed Dec 05 22:04:50 2012 -0500
@@ -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.
+#
+
+. $STF_SUITE/include/libtest.shlib
+. $STF_SUITE/tests/functional/cli_root/zfs_set/zfs_set_common.kshlib
+
+#
+# DESCRIPTION:
+# Setting a valid compression on file system or volume.
+# It should be successful.
+#
+# STRATEGY:
+# 1. Create pool, then create filesystem & volume within it.
+# 2. Setting valid value, it should be successful.
+#
+
+verify_runnable "both"
+
+set -A dataset "$TESTPOOL" "$TESTPOOL/$TESTFS" "$TESTPOOL/$TESTVOL"
+set -A values $(get_compress_opts zfs_set)
+
+log_assert "Setting a valid compression on file system and volume, " \
+	"It should be successful."
+
+typeset -i i=0
+typeset -i j=0
+for propname in "compression" "compress"
+do
+	while (( i < ${#dataset[@]} )); do
+		j=0
+		while (( j < ${#values[@]} )); do
+			set_n_check_prop "${values[j]}" "$propname" "${dataset[i]}"
+			(( j += 1 ))
+		done
+		(( i += 1 ))
+	done
+done
+
+log_pass "Setting a valid compression on file system or volume pass."
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/usr/src/test/zfs-tests/tests/functional/cli_root/zfs_set/mountpoint_001_pos.ksh	Wed Dec 05 22:04:50 2012 -0500
@@ -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) 2012 by Delphix. All rights reserved.
+#
+
+. $STF_SUITE/include/libtest.shlib
+. $STF_SUITE/tests/functional/cli_root/zfs_set/zfs_set_common.kshlib
+
+#
+# DESCRIPTION:
+# Setting valid mountpoint to filesystem, it is successful.
+# Whatever is set to volume, it is failed.
+# 'zfs set mountpoint=<path>|legacy|none <fs|ctr|vol>'
+#
+# STRATEGY:
+# 1. Setup a pool and create fs, ctr within it.
+# 2. Loop all the valid mountpoint value.
+# 3. Check the return value.
+#
+
+verify_runnable "both"
+
+export TESTDIR_NOTEXISTING=${TEST_BASE_DIR%%/}/testdir_notexisting$$
+
+if is_global_zone ; then
+	set -A dataset \
+		"$TESTPOOL/$TESTFS" "$TESTPOOL/$TESTCTR" "$TESTPOOL/$TESTVOL"
+else
+	set -A dataset "$TESTPOOL/$TESTFS" "$TESTPOOL/$TESTCTR"
+fi
+
+set -A values "$TESTDIR2" "legacy" "none" "$TESTDIR_NOTEXISTING"
+
+function cleanup
+{
+	log_must $ZFS set mountpoint=$old_ctr_mpt $TESTPOOL/$TESTCTR
+	log_must $ZFS set mountpoint=$old_fs_mpt $TESTPOOL/$TESTFS
+	[[ -d $TESTDIR2 ]] && log_must $RM -r $TESTDIR2
+	[[ -d $TESTDIR_NOTEXISTING ]] && log_must $RM -r $TESTDIR_NOTEXISTING
+}
+
+log_assert "Setting a valid mountpoint to file system, it must be successful."
+log_onexit cleanup
+
+old_fs_mpt=$(get_prop mountpoint $TESTPOOL/$TESTFS)
+[[ $? != 0 ]] && \
+	log_fail "Get the $TESTPOOL/$TESTFS mountpoint error."
+old_ctr_mpt=$(get_prop mountpoint $TESTPOOL/$TESTCTR)
+[[ $? != 0 ]] && \
+	log_fail "Get the $TESTPOOL/$TESTCTR mountpoint error."
+
+if [[ ! -d $TESTDIR2 ]]; then
+	log_must $MKDIR $TESTDIR2
+fi
+
+typeset -i i=0
+typeset -i j=0
+while (( i < ${#dataset[@]} )); do
+	j=0
+	while (( j < ${#values[@]} )); do
+		if [[ ${dataset[i]} == "$TESTPOOL/$TESTVOL" ]]; then
+			set_n_check_prop "${values[j]}" "mountpoint" \
+				"${dataset[i]}" "false"
+		else
+			set_n_check_prop "${values[j]}" "mountpoint" \
+				"${dataset[i]}"
+		fi
+		(( j += 1 ))
+	done
+	cleanup
+	(( i += 1 ))
+done
+
+log_pass "Setting mountpoint to filesystem pass."
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/usr/src/test/zfs-tests/tests/functional/cli_root/zfs_set/mountpoint_002_pos.ksh	Wed Dec 05 22:04:50 2012 -0500
@@ -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 2007 Sun Microsystems, Inc.  All rights reserved.
+# Use is subject to license terms.
+#
+
+#
+# Copyright (c) 2012 by Delphix. All rights reserved.
+#
+
+. $STF_SUITE/include/libtest.shlib
+. $STF_SUITE/tests/functional/cli_root/zfs_set/zfs_set_common.kshlib
+
+#
+# DESCRIPTION:
+#	If ZFS is currently managing the file system but it is currently unmoutned,
+#	and the mountpoint property is changed, the file system remains unmounted.
+#
+# STRATEGY:
+# 1. Setup a pool and create fs, ctr within it.
+# 2. Unmount that dataset
+# 2. Change the mountpoint to the valid mountpoint value.
+# 3. Check the file system remains unmounted.
+#
+
+verify_runnable "both"
+
+export TESTDIR_NOTEXISTING=${TEST_BASE_DIR%%/}/testdir_notexisting$$
+
+set -A dataset "$TESTPOOL/$TESTFS" "$TESTPOOL/$TESTCTR"
+
+set -A values "$TESTDIR2" "$TESTDIR_NOTEXISTING"
+
+function cleanup
+{
+	log_must $ZFS set mountpoint=$old_ctr_mpt $TESTPOOL/$TESTCTR
+	log_must $ZFS set mountpoint=$old_fs_mpt $TESTPOOL/$TESTFS
+	log_must $ZFS mount -a
+	[[ -d $TESTDIR2 ]] && log_must $RM -r $TESTDIR2
+	[[ -d $TESTDIR_NOTEXISTING ]] && log_must $RM -r $TESTDIR_NOTEXISTING
+}
+
+log_assert "Setting a valid mountpoint for an unmounted file system, \
+	it remains unmounted."
+log_onexit cleanup
+
+old_fs_mpt=$(get_prop mountpoint $TESTPOOL/$TESTFS)
+[[ $? != 0 ]] && \
+	log_fail "Unable to get the mountpoint property for $TESTPOOL/$TESTFS"
+old_ctr_mpt=$(get_prop mountpoint $TESTPOOL/$TESTCTR)
+[[ $? != 0 ]] && \
+	log_fail "Unable to get the mountpoint property for $TESTPOOL/$TESTCTR"
+
+if [[ ! -d $TESTDIR2 ]]; then
+	log_must $MKDIR $TESTDIR2
+fi
+
+typeset -i i=0
+typeset -i j=0
+while (( i < ${#dataset[@]} )); do
+	j=0
+	if ismounted ${dataset[i]} ; then
+		log_must $ZFS unmount ${dataset[i]}
+	fi
+	log_mustnot ismounted ${dataset[i]}
+	while (( j < ${#values[@]} )); do
+		set_n_check_prop "${values[j]}" "mountpoint" \
+			"${dataset[i]}"
+		log_mustnot ismounted ${dataset[i]}
+		(( j += 1 ))
+	done
+	cleanup
+	(( i += 1 ))
+done
+
+log_pass "Setting a valid mountpoint for an unmounted file system, \
+	it remains unmounted."
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/usr/src/test/zfs-tests/tests/functional/cli_root/zfs_set/mountpoint_003_pos.ksh	Wed Dec 05 22:04:50 2012 -0500
@@ -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 2009 Sun Microsystems, Inc.  All rights reserved.
+# Use is subject to license terms.
+#
+
+. $STF_SUITE/include/libtest.shlib
+
+#
+# DESCRIPTION:
+#	Verify FSType-specific option works well with legacy mount.
+#
+# STRATEGY:
+#	1. Set up FSType-specific options and expected keywords array.
+#	2. Create a test ZFS file system and set mountpoint=legacy.
+#	3. Mount ZFS test filesystem with specific options.
+#	4. Verify the filesystem was mounted with specific option.
+#	5. Loop check all the options.
+#
+
+verify_runnable "both"
+
+function cleanup
+{
+	ismounted $tmpmnt && log_must $UMOUNT $tmpmnt
+	[[ -d $tmpmnt ]] && log_must $RM -rf $tmpmnt
+	[[ -n $oldmpt ]] && log_must $ZFS set mountpoint=$oldmpt $testfs
+	! ismounted $oldmpt && log_must $ZFS mount $testfs
+}
+
+log_assert "With legacy mount, FSType-specific option works well."
+log_onexit cleanup
+
+#
+#  /mnt on pool/fs read/write/setuid/devices/noexec/xattr/atime/dev=2d9009e
+#
+#	FSType-				FSType-
+#	specific	Keyword		specific	Keyword
+#	option				option
+#
+set -A args \
+	"devices"	"/devices/"	"nodevices"	"/nodevices/"	\
+	"exec"		"/exec/"	"noexec"	"/noexec/"	\
+	"nbmand"	"/nbmand/"	"nonbmand"	"/nonbmand/"	\
+	"ro"		"read only"	"rw"		"read/write"	\
+	"setuid"	"/setuid/"	"nosetuid"	"/nosetuid/"	\
+	"xattr"		"/xattr/"	"noxattr"	"/noxattr/"	\
+	"atime"		"/atime/"	"noatime"	"/noatime/"
+
+tmpmnt=/tmpmnt.$$
+[[ -d $tmpmnt ]] && $RM -rf $tmpmnt
+testfs=$TESTPOOL/$TESTFS
+log_must $MKDIR $tmpmnt
+oldmpt=$(get_prop mountpoint $testfs)
+log_must $ZFS set mountpoint=legacy $testfs
+
+typeset i=0
+while ((i < ${#args[@]})); do
+	log_must $MOUNT -F zfs -o ${args[$i]} $testfs $tmpmnt
+	msg=$($MOUNT | $GREP "^$tmpmnt ")
+
+	# In LZ, a user with all zone privileges can never with "devices"
+	if ! is_global_zone && [[ ${args[$i]} == devices ]] ; then
+		args[((i+1))]="/nodevices/"
+	fi
+
+	$ECHO $msg | $GREP "${args[((i+1))]}" > /dev/null 2>&1
+	if (($? != 0)) ; then
+		log_fail "Expected option: ${args[((i+1))]} \n" \
+			 "Real option: $msg"
+	fi
+
+	log_must $UMOUNT $tmpmnt
+	((i += 2))
+done
+
+log_pass "With legacy mount, FSType-specific option works well passed."
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/usr/src/test/zfs-tests/tests/functional/cli_root/zfs_set/onoffs_001_pos.ksh	Wed Dec 05 22:04:50 2012 -0500
@@ -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.
+#
+
+. $STF_SUITE/include/libtest.shlib
+. $STF_SUITE/tests/functional/cli_root/zfs_set/zfs_set_common.kshlib
+
+#
+# DESCRIPTION:
+# Setting a valid value to atime, readonly, setuid or zoned on file
+# system or volume. It should be successful.
+#
+# STRATEGY:
+# 1. Create pool and filesystem & volume within it.
+# 2. Setting valid value, it should be successful.
+#
+
+verify_runnable "both"
+
+function cleanup
+{
+	log_must $ZFS mount -a
+}
+
+log_onexit cleanup
+
+set -A props "atime" "readonly" "setuid" "zoned"
+set -A values "on" "off"
+
+if is_global_zone ; then
+	set -A dataset "$TESTPOOL/$TESTFS" "$TESTPOOL/$TESTCTR" "$TESTPOOL/$TESTVOL"
+else
+	set -A dataset "$TESTPOOL/$TESTFS" "$TESTPOOL/$TESTCTR"
+fi
+
+log_assert "Setting a valid value to atime, readonly, setuid or zoned on file" \
+	"system or volume. It should be successful."
+
+typeset -i i=0
+typeset -i j=0
+typeset -i k=0
+while (( i < ${#dataset[@]} )); do
+	j=0
+	while (( j < ${#props[@]} )); do
+		k=0
+		while (( k < ${#values[@]} )); do
+			if [[ ${dataset[i]} == "$TESTPOOL/$TESTVOL" &&  \
+			    ${props[j]} != "readonly" ]]
+			then
+				set_n_check_prop "${values[k]}" "${props[j]}" \
+				    "${dataset[i]}" "false"
+			elif [[ ${props[j]} == "zoned" ]] ; then
+				if is_global_zone ; then
+					set_n_check_prop \
+					    "${values[k]}" "${props[j]}" \
+					    "${dataset[i]}"
+				else
+					set_n_check_prop \
+					    "${values[k]}" "${props[j]}" \
+					    "${dataset[i]}" "false"
+				fi
+
+			else
+				set_n_check_prop "${values[k]}" "${props[j]}" \
+					"${dataset[i]}"
+			fi
+
+			(( k += 1 ))
+		done
+		(( j += 1 ))
+	done
+	(( i += 1 ))
+done
+
+log_pass "Setting a valid value to atime, readonly, setuid or zoned on file" \
+	"system or volume pass."
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/usr/src/test/zfs-tests/tests/functional/cli_root/zfs_set/property_alias_001_pos.ksh	Wed Dec 05 22:04:50 2012 -0500
@@ -0,0 +1,140 @@
+#!/bin/ksh -p
+#
+# CDDL HEADER START
+#
+# The contents of this file are subject to the terms of the
+# Common Development and Distribution License (the "License").
+# You may not use this file except in compliance with the License.
+#
+# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
+# or http://www.opensolaris.org/os/licensing.
+# See the License for the specific language governing permissions
+# and limitations under the License.
+#
+# When distributing Covered Code, include this CDDL HEADER in each
+# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
+# If applicable, add the following below this CDDL 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.
+#
+
+. $STF_SUITE/include/libtest.shlib
+. $STF_SUITE/tests/functional/cli_root/zfs_set/zfs_set_common.kshlib
+
+#
+# DESCRIPTION:
+# Verify the properties with aliases also work with those aliases
+#
+# STRATEGY:
+# 1. Create pool, then create filesystem & volume within it.
+# 2. Set or retrieve property via alias with datasets.
+# 3. Verify the result should be successful.
+#
+
+verify_runnable "both"
+
+function set_and_check #<dataset><set_prop_name><set_value><check_prop_name>
+{
+	typeset ds=$1
+	typeset setprop=$2
+	typeset setval=$3
+	typeset chkprop=$4
+	typeset getval
+
+	log_must $ZFS set $setprop=$setval $ds
+	if [[ $setval == "gzip-6" ]]; then
+		setval="gzip"
+	fi
+	getval=$(get_prop $chkprop $ds)
+
+	case $setprop in
+		reservation|reserv )
+			if [[ $setval == "none" ]]; then
+				 [[ $getval != "0" ]] && \
+					log_fail "Setting the property $setprop" \
+						"with value $setval fails."
+                        elif [[ $getval != $setval ]]; then
+				log_fail "Setting the property $setprop with" \
+					"with $setval fails."
+			fi
+                        ;;
+                 * )
+                        [[ $getval != $setval ]] && \
+				log_fail "Setting the property $setprop with value \
+					$setval fails."
+                        ;;
+         esac
+}
+
+log_assert "Properties with aliases also work with those aliases."
+
+set -A ro_prop "available" "avail" "referenced" "refer"
+set -A rw_prop "readonly" "rdonly" "compression" "compress" "reservation" "reserv"
+set -A chk_prop "rdonly" "readonly" "compress" "compression" "reserv" "reservation"
+set -A size "512" "1024" "2048" "4096" "8192" "16384" "32768" "65536" "131072"
+
+pool=$TESTPOOL
+fs=$TESTPOOL/$TESTFS
+vol=$TESTPOOL/$TESTVOL
+typeset -l avail_space=$(get_prop avail $pool)
+typeset -l reservsize
+typeset -i i=0
+
+for ds in $pool $fs $vol; do
+	for propname in ${ro_prop[*]}; do
+		$ZFS get -pH -o value $propname $ds >/dev/null 2>&1
+		(( $? != 0 )) && \
+			log_fail "Get the property $proname of $ds failed."
+	done
+	i=0
+	while (( i < ${#rw_prop[*]} )); do
+		case ${rw_prop[i]} in
+		readonly|rdonly )
+			for val in "on" "off"; do
+				set_and_check $ds ${rw_prop[i]} $val ${chk_prop[i]}
+			done
+			;;
+		compression|compress )
+			for val in $(get_compress_opts zfs_set); do
+				set_and_check $ds ${rw_prop[i]} $val ${chk_prop[i]}
+			done
+			;;
+		reservation|reserv )
+			(( reservsize = $avail_space % $RANDOM ))
+			for val in "0" "$reservsize" "none"; do
+				set_and_check $ds ${rw_prop[i]} $val ${chk_prop[i]}
+			done
+			;;
+		esac
+
+		(( i = i + 1 ))
+	done
+	if [[ $ds == $vol ]]; then
+		for propname in "volblocksize" "volblock" ; do
+			$ZFS get -pH -o value $propname $ds >/dev/null 2>&1
+			(( $? != 0 )) && \
+				log_fail "Get the property $propname of $ds failed."
+		done
+	fi
+done
+
+for ds in $pool $fs; do
+	for propname in "recordsize" "recsize"; do
+		for val in ${size[*]}; do
+			if [[ $propname == "recordsize" ]]; then
+				set_and_check $ds $propname $val "recsize"
+			else
+				set_and_check $ds $propname $val "recordsize"
+			fi
+		done
+	done
+done
+
+log_pass "The alias of a property works as expected."
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/usr/src/test/zfs-tests/tests/functional/cli_root/zfs_set/readonly_001_pos.ksh	Wed Dec 05 22:04:50 2012 -0500
@@ -0,0 +1,154 @@
+#!/bin/ksh -p
+#
+# CDDL HEADER START
+#
+# The contents of this file are subject to the terms of the
+# Common Development and Distribution License (the "License").
+# You may not use this file except in compliance with the License.
+#
+# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
+# or http://www.opensolaris.org/os/licensing.
+# See the License for the specific language governing permissions
+# and limitations under the License.
+#
+# When distributing Covered Code, include this CDDL HEADER in each
+# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
+# If applicable, add the following below this CDDL 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.
+#
+
+. $STF_SUITE/tests/functional/cli_root/zfs_set/zfs_set_common.kshlib
+
+#
+# DESCRIPTION:
+# Setting readonly on a dataset, it should keep the dataset as readonly.
+#
+# STRATEGY:
+# 1. Create pool, then create filesystem and volume within it.
+# 2. Setting readonly to each dataset.
+# 3. Check the return value and make sure it is 0.
+# 4. Verify the stuff under mountpoint is readonly.
+#
+
+verify_runnable "both"
+
+function cleanup
+{
+	for dataset in $TESTPOOL/$TESTFS $TESTPOOL/$TESTVOL ; do
+		snapexists ${dataset}@$TESTSNAP && \
+			log_must $ZFS destroy -R ${dataset}@$TESTSNAP
+	done
+}
+
+function initial_dataset # $1 dataset
+{
+	typeset dataset=$1
+
+	typeset fstype=$(get_prop type $dataset)
+
+	if [[ $fstype == "filesystem" ]] ; then
+		typeset mtpt=$(get_prop mountpoint $dataset)
+		log_must $TOUCH $mtpt/$TESTFILE0
+		log_must $MKDIR -p $mtpt/$TESTDIR0
+	fi
+}
+
+
+function cleanup_dataset # $1 dataset
+{
+	typeset dataset=$1
+
+	typeset fstype=$(get_prop type $dataset)
+
+	if [[ $fstype == "filesystem" ]] ; then
+		typeset mtpt=$(get_prop mountpoint $dataset)
+		log_must $RM -f $mtpt/$TESTFILE0
+		log_must $RM -rf $mtpt/$TESTDIR0
+	fi
+}
+
+function verify_readonly # $1 dataset, $2 on|off
+{
+	typeset dataset=$1
+	typeset value=$2
+
+	if datasetnonexists $dataset ; then
+		log_note "$dataset not exist!"
+		return 1
+	fi
+
+	typeset fstype=$(get_prop type $dataset)
+
+	expect="log_must"
+
+	if [[ $2 == "on" ]] ; then
+		expect="log_mustnot"
+	fi
+
+	case $fstype in
+		filesystem)
+			typeset mtpt=$(get_prop mountpoint $dataset)
+			$expect $TOUCH $mtpt/$TESTFILE1
+			$expect $MKDIR -p $mtpt/$TESTDIR1
+			$expect $ECHO 'y' | $RM $mtpt/$TESTFILE0
+			$expect $RMDIR $mtpt/$TESTDIR0
+
+			if [[ $expect == "log_must" ]] ; then
+				log_must $ECHO 'y' | $RM $mtpt/$TESTFILE1
+				log_must $RMDIR $mtpt/$TESTDIR1
+				log_must $TOUCH $mtpt/$TESTFILE0
+				log_must $MKDIR -p $mtpt/$TESTDIR0
+			fi
+			;;
+		volume)
+			$expect eval "$ECHO 'y' | $NEWFS /dev/zvol/dsk/$dataset > /dev/null 2>&1"
+			;;
+		*)
+			;;
+	esac
+
+	return 0
+}
+
+log_onexit cleanup
+
+log_assert "Setting a valid readonly property on a dataset succeeds."
+
+typeset all_datasets
+
+log_must $ZFS mount -a
+
+log_must $ZFS snapshot $TESTPOOL/$TESTFS@$TESTSNAP
+log_must $ZFS clone $TESTPOOL/$TESTFS@$TESTSNAP $TESTPOOL/$TESTCLONE
+
+if is_global_zone ; then
+	log_must $ZFS snapshot $TESTPOOL/$TESTVOL@$TESTSNAP
+	log_must $ZFS clone $TESTPOOL/$TESTVOL@$TESTSNAP $TESTPOOL/$TESTCLONE1
+	all_datasets="$TESTPOOL $TESTPOOL/$TESTFS $TESTPOOL/$TESTVOL $TESTPOOL/$TESTCLONE $TESTPOOL/$TESTCLONE1"
+else
+	all_datasets="$TESTPOOL $TESTPOOL/$TESTFS $TESTPOOL/$TESTCLONE"
+fi
+
+
+for dataset in $all_datasets; do
+	for value in on off; do
+		set_n_check_prop "off" "readonly" "$dataset"
+		initial_dataset $dataset
+
+		set_n_check_prop "$value" "readonly" "$dataset"
+		verify_readonly $dataset $value
+
+		set_n_check_prop "off" "readonly" "$dataset"
+		cleanup_dataset $dataset
+	done
+done
+
+log_pass "Setting a valid readonly property on a dataset succeeds."
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/usr/src/test/zfs-tests/tests/functional/cli_root/zfs_set/reservation_001_neg.ksh	Wed Dec 05 22:04:50 2012 -0500
@@ -0,0 +1,97 @@
+#! /bin/ksh -p
+#
+# CDDL HEADER START
+#
+# The contents of this file are subject to the terms of the
+# Common Development and Distribution License (the "License").
+# You may not use this file except in compliance with the License.
+#
+# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
+# or http://www.opensolaris.org/os/licensing.
+# See the License for the specific language governing permissions
+# and limitations under the License.
+#
+# When distributing Covered Code, include this CDDL HEADER in each
+# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
+# If applicable, add the following below this CDDL HEADER, with the
+# fields enclosed by brackets "[]" replaced with your own identifying
+# information: Portions Copyright [yyyy] [name of copyright owner]
+#
+# CDDL HEADER END
+#
+
+#
+# Copyright 2007 Sun Microsystems, Inc.  All rights reserved.
+# Use is subject to license terms.
+#
+
+. $STF_SUITE/include/libtest.shlib
+
+#
+# DESCRIPTION:
+# Valid reservation values should be positive integers only.
+#
+# STRATEGY:
+# 1) Form an array of invalid reservation values (negative and
+# incorrectly formed)
+# 2) Attempt to set each invalid reservation value in turn on a
+# filesystem and volume.
+# 3) Verify that attempt fails and the reservation value remains
+# unchanged
+#
+
+verify_runnable "both"
+
+log_assert "Verify invalid reservation values are rejected"
+
+set -A suffix "b" "k" "m" "t" "p" "e" "K" "M" "G" "T" "P" "E" "kb" "Mb" "Gb" \
+	"Tb" "Pb" "Eb" "KB" "MB" "GB" "TB" "PB" "EB"
+
+set -A values '' '-1' '-1.0' '-1.8' '-9999999999999999' '0x1' '0b' '1b' '1.1b'
+
+#
+# Function to loop through a series of bad reservation
+# values, checking they are when we attempt to set them
+# on a dataset.
+#
+function set_n_check # data-set
+{
+	typeset obj=$1
+	typeset -i i=0
+	typeset -i j=0
+
+	orig_resv_val=$(get_prop reservation $obj)
+
+	while (( $i < ${#values[*]} )); do
+		j=0
+		while (( $j < ${#suffix[*]} )); do
+
+			$ZFS set \
+				reservation=${values[$i]}${suffix[$j]} $obj \
+				> /dev/null 2>&1
+			if [ $? -eq 0 ]
+			then
+				log_note "$ZFS set \
+				reservation=${values[$i]}${suffix[$j]} $obj"
+				log_fail "The above reservation set returned 0!"
+			fi
+
+			new_resv_val=$(get_prop reservation $obj)
+
+			if [[ $new_resv_val != $orig_resv_val ]]; then
+				log_fail "$obj : reservation values changed " \
+					"($orig_resv_val : $new_resv_val)"
+			fi
+			(( j = j + 1 ))
+		done
+
+	(( i = i + 1 ))
+	done
+}
+
+for dataset in $TESTPOOL/$TESTFS $TESTPOOL/$TESTCTR $TESTPOOL/$TESTVOL
+do
+	set_n_check $dataset
+done
+
+log_pass "Invalid reservation values correctly rejected"
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/usr/src/test/zfs-tests/tests/functional/cli_root/zfs_set/ro_props_001_pos.ksh	Wed Dec 05 22:04:50 2012 -0500
@@ -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.
+#
+
+. $STF_SUITE/include/libtest.shlib
+. $STF_SUITE/tests/functional/cli_root/zfs_set/zfs_set_common.kshlib
+
+#
+# DESCRIPTION:
+# Verify that read-only properties are immutable.
+#
+# STRATEGY:
+# 1. Create pool, fs, vol, fs@snap & vol@snap.
+# 2. Get the original property value and set value to those properties.
+# 3. Check return value.
+# 4. Compare the current property value with the original one.
+#
+
+verify_runnable "both"
+
+set -A values filesystem volume snapshot -3 0 1 50K 10G 80G \
+	2005/06/17 30K 20x yes no \
+	on off default pool/fs@snap $TESTDIR
+set -A dataset $TESTPOOL $TESTPOOL/$TESTFS $TESTPOOL/$TESTVOL \
+	$TESTPOOL/$TESTCTR/$TESTFS1 $TESTPOOL/$TESTFS@$TESTSNAP \
+	$TESTPOOL/$TESTVOL@$TESTSNAP
+typeset ro_props="type used available avail creation referenced refer compressratio \
+	mounted origin"
+typeset snap_ro_props="volsize recordsize recsize quota reservation reserv mountpoint \
+	sharenfs checksum compression compress atime devices exec readonly rdonly \
+	setuid zoned"
+
+$ZFS upgrade -v > /dev/null 2>&1
+if [[ $? -eq 0 ]]; then
+	snap_ro_props="$snap_ro_props version"
+fi
+
+function cleanup
+{
+	datasetexists $TESTPOOL/$TESTVOL@$TESTSNAP && \
+		destroy_snapshot $TESTPOOL/$TESTVOL@$TESTSNAP
+	datasetexists $TESTPOOL/$TESTFS@$TESTSNAP && \
+		destroy_snapshot $TESTPOOL/$TESTFS@$TESTSNAP
+}
+
+log_assert "Verify that read-only properties are immutable."
+log_onexit cleanup
+
+# Create filesystem and volume's snapshot
+create_snapshot $TESTPOOL/$TESTFS $TESTSNAP
+create_snapshot $TESTPOOL/$TESTVOL $TESTSNAP
+
+typeset -i i=0
+typeset -i j=0
+typeset cur_value=""
+typeset props=""
+
+while (( i < ${#dataset[@]} )); do
+	props=$ro_props
+
+	dst_type=$(get_prop type ${dataset[i]})
+	if [[ $dst_type == 'snapshot' ]]; then
+		props="$ro_props $snap_ro_props"
+	fi
+
+	for prop in $props; do
+		cur_value=$(get_prop $prop ${dataset[i]})
+
+		j=0
+		while (( j < ${#values[@]} )); do
+			#
+			# If the current property value is equal to values[j],
+			# just expect it failed. Otherwise, set it to dataset,
+			# expecting it failed and the property value is not
+			# equal to values[j].
+			#
+			if [[ $cur_value == ${values[j]} ]]; then
+				log_mustnot $ZFS set $prop=${values[j]} \
+					${dataset[i]}
+			else
+				set_n_check_prop ${values[j]} $prop \
+					${dataset[i]} false
+			fi
+			(( j += 1 ))
+		done
+	done
+	(( i += 1 ))
+done
+
+log_pass "Setting uneditable properties should failed. It passed."
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/usr/src/test/zfs-tests/tests/functional/cli_root/zfs_set/setup.ksh	Wed Dec 05 22:04:50 2012 -0500
@@ -0,0 +1,31 @@
+#!/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.
+#
+
+. $STF_SUITE/include/libtest.shlib
+
+DISK=${DISKS%% *}
+default_container_volume_setup $DISK
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/usr/src/test/zfs-tests/tests/functional/cli_root/zfs_set/share_mount_001_neg.ksh	Wed Dec 05 22:04:50 2012 -0500
@@ -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.
+#
+
+. $STF_SUITE/tests/functional/cli_root/zfs_set/zfs_set_common.kshlib
+
+#
+# DESCRIPTION:
+# Verify that we cannot share or mount legacy filesystems.
+#
+# STRATEGY:
+# 1. Set mountpoint as legacy or none
+# 2. Use zfs share or zfs mount to share or mount the filesystem
+# 3. Verify that the command returns error
+#
+
+verify_runnable "both"
+
+function cleanup
+{
+	log_must $ZFS set mountpoint=$oldmpt $fs
+}
+
+log_assert "Verify that we cannot share or mount legacy filesystems."
+log_onexit cleanup
+
+fs=$TESTPOOL/$TESTFS
+oldmpt=$(get_prop mountpoint $fs)
+
+for propval in "legacy" "none"; do
+	log_must $ZFS set mountpoint=$propval $fs
+
+	log_mustnot $ZFS mount $fs
+	log_mustnot $ZFS share $fs
+done
+
+log_pass "We cannot share or mount legacy filesystems as expected."
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/usr/src/test/zfs-tests/tests/functional/cli_root/zfs_set/snapdir_001_pos.ksh	Wed Dec 05 22:04:50 2012 -0500
@@ -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 2007 Sun Microsystems, Inc.  All rights reserved.
+# Use is subject to license terms.
+#
+
+. $STF_SUITE/tests/functional/cli_root/zfs_set/zfs_set_common.kshlib
+
+#
+# DESCRIPTION:
+# Setting a valid snapdir on a dataset, it should be successful.
+#
+# STRATEGY:
+# 1. Create pool, then create filesystem and volume within it.
+# 2. Create a snapshot for each dataset.
+# 3. Setting different valid snapdir to each dataset.
+# 4. Check the return value and make sure it is 0.
+# 5. Verify .zfs directory is hidden|visible according to the snapdir setting.
+#
+
+verify_runnable "both"
+
+function cleanup
+{
+	for dataset in $all_datasets; do
+		snapexists ${dataset}@snap && \
+			log_must $ZFS destroy ${dataset}@snap
+	done
+}
+
+function verify_snapdir_visible # $1 dataset, $2 hidden|visible
+{
+	typeset dataset=$1
+	typeset value=$2
+	typeset mtpt=$(get_prop mountpoint $dataset)
+	typeset name
+
+	for name in `$LS -a $mtpt`; do
+		if [[ $name == ".zfs" ]]; then
+			if [[ $value == "visible" ]]; then
+				return 0
+			else
+				return 1
+			fi
+		fi
+	done
+
+	if [[ $value == "visible" ]]; then
+		return 1
+	else
+		return 0
+	fi
+}
+
+
+typeset all_datasets
+
+if is_global_zone ; then
+	all_datasets="$TESTPOOL $TESTPOOL/$TESTFS $TESTPOOL/$TESTVOL"
+else
+	all_datasets="$TESTPOOL $TESTPOOL/$TESTFS"
+fi
+
+log_onexit cleanup
+
+for dataset in $all_datasets; do
+	log_must $ZFS snapshot ${dataset}@snap
+done
+
+log_assert "Setting a valid snapdir property on a dataset succeeds."
+
+for dataset in $all_datasets; do
+	for value in hidden visible; do
+		if [[ $dataset == "$TESTPOOL/$TESTVOL" ]] ; then
+			set_n_check_prop "$value" "snapdir" \
+				"$dataset" "false"
+		else
+			set_n_check_prop "$value" "snapdir" \
+				"$dataset"
+			verify_snapdir_visible $dataset $value
+			[[ $? -eq 0 ]] || \
+				log_fail "$dataset/.zfs is not $value as expect."
+		fi
+	done
+done
+
+log_pass "Setting a valid snapdir property on a dataset succeeds."
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/usr/src/test/zfs-tests/tests/functional/cli_root/zfs_set/user_property_001_pos.ksh	Wed Dec 05 22:04:50 2012 -0500
@@ -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.
+#
+
+. $STF_SUITE/tests/functional/cli_root/zfs_set/zfs_set_common.kshlib
+
+#
+# DESCRIPTION:
+#	ZFS can set any valid user defined property to the non-readonly dataset.
+#
+# STRATEGY:
+#	1. Loop pool, fs and volume.
+#	2. Combine all kind of valid characters into a valid user defined
+#	   property name.
+#	3. Random get a string as the value.
+#	4. Verify all the valid user defined properties can be set to the
+#	   dataset in #1.
+#
+
+verify_runnable "both"
+
+log_assert "ZFS can set any valid user defined property to the non-readonly " \
+	"dataset."
+log_onexit cleanup_user_prop $TESTPOOL
+
+typeset -i i=0
+while ((i < 10)); do
+	typeset -i len
+	((len = RANDOM % 32))
+	typeset user_prop=$(valid_user_property $len)
+	((len = RANDOM % 512))
+	typeset value=$(user_property_value $len)
+
+	for dtst in $TESTPOOL $TESTPOOL/$TESTFS $TESTPOOL/$TESTVOL; do
+		log_must eval "$ZFS set $user_prop='$value' $dtst"
+		log_must eval "check_user_prop $dtst $user_prop '$value'"
+	done
+
+	((i += 1))
+done
+
+log_pass "ZFS can set any valid user defined property passed."
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/usr/src/test/zfs-tests/tests/functional/cli_root/zfs_set/user_property_002_pos.ksh	Wed Dec 05 22:04:50 2012 -0500
@@ -0,0 +1,118 @@
+#!/bin/ksh -p
+#
+# CDDL HEADER START
+#
+# The contents of this file are subject to the terms of the
+# Common Development and Distribution License (the "License").
+# You may not use this file except in compliance with the License.
+#
+# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
+# or http://www.opensolaris.org/os/licensing.
+# See the License for the specific language governing permissions
+# and limitations under the License.
+#
+# When distributing Covered Code, include this CDDL HEADER in each
+# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
+# If applicable, add the following below this CDDL HEADER, with the
+# fields enclosed by brackets "[]" replaced with your own identifying
+# information: Portions Copyright [yyyy] [name of copyright owner]
+#
+# CDDL HEADER END
+#
+
+#
+# Copyright 2007 Sun Microsystems, Inc.  All rights reserved.
+# Use is subject to license terms.
+#
+
+. $STF_SUITE/tests/functional/cli_root/zfs_set/zfs_set_common.kshlib
+
+#
+# DESCRIPTION:
+#	User defined property are always inherited from its parent dataset
+#	directly.
+#
+# STRATEGY:
+#	1. Create pool, fs, volume, fsclone & volclone.
+#	2. Get random user property name and set to the pool
+#	3. Verify all dataset user property inherit from pool.
+#	4. Set intermediate dataset and verify its children will inherit user
+#	   property from it directly.
+#
+
+verify_runnable "both"
+
+function cleanup
+{
+	datasetexists $new_vol && log_must $ZFS rename $new_vol $vol
+
+	typeset dtst
+	for dtst in $new_fsclone $new_volclone $fsclone $volclone \
+	    $fssnap $volsnap; do
+		if datasetexists $dtst; then
+			log_must $ZFS destroy -f $dtst
+		fi
+	done
+
+	cleanup_user_prop $pool
+}
+
+#
+# Verify options datasets (3-n) inherit from the inherited dataset $2.
+#
+# $1 user property
+# $2 inherited dataset
+# $3-n datasets
+#
+function inherit_check
+{
+	typeset prop=$1
+	typeset inherited_dtst=$2
+	shift 2
+	[[ -z $@ ]] && return 1
+
+	typeset inherited_value=$(get_prop $prop $inherited_dtst)
+	for dtst in $@; do
+		typeset value=$(get_prop $prop $dtst)
+		typeset source=$(get_source $prop $dtst)
+		if [[ "$value" != "$inherited_value" || \
+		      "$source" != "inherited from $inherited_dtst" ]]
+		then
+			return 1
+		fi
+
+		shift
+	done
+
+	return 0
+}
+
+log_assert "User defined property inherited from its parent."
+log_onexit cleanup
+
+pool=$TESTPOOL; fs=$pool/$TESTFS; vol=$pool/$TESTVOL
+fssnap=$fs@snap; volsnap=$vol@snap;
+log_must $ZFS snapshot $fssnap
+log_must $ZFS snapshot $volsnap
+fsclone=$pool/fsclone; volclone=$pool/volclone
+log_must $ZFS clone $fssnap $fsclone
+log_must $ZFS clone $volsnap $volclone
+
+prop_name=$(valid_user_property 10)
+value=$(user_property_value 16)
+log_must eval "$ZFS set $prop_name='$value' $pool"
+log_must eval "check_user_prop $pool $prop_name '$value'"
+log_must inherit_check $prop_name $pool $fs $vol $fsclone $volclone
+
+new_fsclone=$fs/fsclone; new_volclone=$fs/volclone
+log_must $ZFS rename $fsclone $new_fsclone
+log_must $ZFS rename $volclone $new_volclone
+log_must inherit_check $prop_name $pool $fs $new_fsclone $new_volclone
+
+log_note "Set intermediate dataset will change the inherited relationship."
+new_value=$(user_property_value 16)
+log_must eval "$ZFS set $prop_name='$new_value' $fs"
+log_must eval "check_user_prop $fs $prop_name '$new_value'"
+log_must inherit_check $prop_name $fs $new_fsclone $new_volclone
+
+log_pass "User defined property inherited from its parent passed."
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/usr/src/test/zfs-tests/tests/functional/cli_root/zfs_set/user_property_003_neg.ksh	Wed Dec 05 22:04:50 2012 -0500
@@ -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.
+#
+
+. $STF_SUITE/tests/functional/cli_root/zfs_set/zfs_set_common.kshlib
+
+#
+# DESCRIPTION:
+#	ZFS can handle any invalid user defined property.
+#
+# STRATEGY:
+#	1. Loop pool, fs and volume.
+#	2. Combine all kind of invalid user property names.
+#	3. Random get a string as the value.
+#	4. Verify all the invalid user defined properties can not be set to the
+#	   dataset in #1.
+#
+
+verify_runnable "both"
+
+log_assert "ZFS can handle invalid user property."
+log_onexit cleanup_user_prop $TESTPOOL
+
+typeset -i i=0
+while ((i < 10)); do
+	typeset -i len
+	((len = RANDOM % 32))
+	typeset user_prop=$(invalid_user_property $len)
+	((len = RANDOM % 512))
+	typeset value=$(user_property_value $len)
+
+	for dtst in $TESTPOOL $TESTPOOL/$TESTFS $TESTPOOL/$TESTVOL ; do
+		log_mustnot $ZFS set $user_prop=$value $dtst
+		log_mustnot check_user_prop $dtst \"$user_prop\" \"$value\"
+	done
+
+	((i += 1))
+done
+
+log_pass "ZFS can handle invalid user property passed."
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/usr/src/test/zfs-tests/tests/functional/cli_root/zfs_set/user_property_004_pos.ksh	Wed Dec 05 22:04:50 2012 -0500
@@ -0,0 +1,97 @@
+#!/bin/ksh -p
+#
+# CDDL HEADER START
+#
+# The contents of this file are subject to the terms of the
+# Common Development and Distribution License (the "License").
+# You may not use this file except in compliance with the License.
+#
+# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
+# or http://www.opensolaris.org/os/licensing.
+# See the License for the specific language governing permissions
+# and limitations under the License.
+#
+# When distributing Covered Code, include this CDDL HEADER in each
+# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
+# If applicable, add the following below this CDDL 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.
+#
+
+. $STF_SUITE/tests/functional/cli_root/zfs_set/zfs_set_common.kshlib
+
+#
+# DESCRIPTION:
+#	User property has no effect to snapshot until 'Snapshot properties' supported.
+#
+# STRATEGY:
+#	1. Verify user properties could be transformed by 'zfs snapshot'
+#	2. Verify user properties could be set upon snapshot.
+#
+
+verify_runnable "both"
+
+function cleanup
+{
+	for fs in $TESTPOOL/$TESTFS $TESTPOOL/$TESTVOL $TESTPOOL ; do
+		typeset fssnap=$fs@snap
+		if datasetexists $fssnap ; then
+			log_must $ZFS destroy -f $fssnap
+		fi
+	done
+	cleanup_user_prop $TESTPOOL
+}
+
+function nonexist_user_prop
+{
+	typeset user_prop=$1
+	typeset dtst=$2
+
+	typeset source=$(get_source $user_prop $dtst)
+	typeset value=$(get_prop $user_prop $dtst)
+	if [[ $source == '-' && $value == '-' ]]; then
+		return 0
+	else
+		return 1
+	fi
+}
+
+log_assert "User property has no effect to snapshot until 'Snapshot properties' supported."
+log_onexit cleanup
+
+typeset snap_property=
+
+$ZPOOL upgrade -v | $GREP "Snapshot properties" > /dev/null 2>&1
+if (( $? == 0 )) ; then
+	snap_property="true"
+fi
+
+for fs in $TESTPOOL/$TESTFS $TESTPOOL/$TESTVOL $TESTPOOL ; do
+	typeset fssnap=$fs@snap
+	prop_name=$(valid_user_property 10)
+	value=$(user_property_value 16)
+	log_must eval "$ZFS set $prop_name='$value' $fs"
+	log_must eval "check_user_prop $fs $prop_name '$value'"
+
+	log_must $ZFS snapshot $fssnap
+
+	if [[ -n $snap_property ]] ; then
+		log_mustnot nonexist_user_prop $prop_name $fssnap
+
+		log_must eval "$ZFS set $prop_name='$value' $fssnap"
+		log_mustnot nonexist_user_prop $prop_name $fssnap
+	else
+		log_must nonexist_user_prop $prop_name $fssnap
+		log_mustnot eval "$ZFS set $prop_name='$value' $fssnap"
+		log_must nonexist_user_prop $prop_name $fssnap
+	fi
+done
+
+log_pass "User properties has effect upon snapshot."
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/usr/src/test/zfs-tests/tests/functional/cli_root/zfs_set/version_001_neg.ksh	Wed Dec 05 22:04:50 2012 -0500
@@ -0,0 +1,87 @@
+#! /bin/ksh -p
+#
+# CDDL HEADER START
+#
+# The contents of this file are subject to the terms of the
+# Common Development and Distribution License (the "License").
+# You may not use this file except in compliance with the License.
+#
+# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
+# or http://www.opensolaris.org/os/licensing.
+# See the License for the specific language governing permissions
+# and limitations under the License.
+#
+# When distributing Covered Code, include this CDDL HEADER in each
+# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
+# If applicable, add the following below this CDDL 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.
+#
+
+. $STF_SUITE/include/libtest.shlib
+. $STF_SUITE/tests/functional/cli_root/zfs_upgrade/zfs_upgrade.kshlib
+
+#
+# DESCRIPTION:
+# Valid version values should be positive integers only.
+#
+# STRATEGY:
+# 1) Form an array of invalid reservation values (negative and
+# incorrectly formed)
+# 2) Attempt to set each invalid version value in turn on a
+# filesystem and volume.
+# 3) Verify that attempt fails and the version value remains
+# unchanged
+#
+
+verify_runnable "both"
+
+log_assert "Verify invalid version values are rejected"
+
+typeset values=('' '-1' '-1.0' '-1.8' '-9999999999999999' \
+	'0x1' '0b' '1b' '1.1b' '0' '0.000' '1.234')
+
+#
+# Function to loop through a series of bad reservation
+# values, checking they are when we attempt to set them
+# on a dataset.
+#
+function set_n_check # data-set
+{
+	typeset obj=$1
+	typeset -i i=0
+	typeset -i j=0
+
+	orig_val=$(get_prop version $obj)
+
+	while (($i < ${#values[*]})); do
+		$ZFS set version=${values[$i]} $obj  > /dev/null 2>&1
+		if [[ $? -eq 0 ]]; then
+			log_note "$ZFS set version=${values[$i]} $obj"
+			log_fail "The above version set returned 0!"
+		fi
+
+		new_val=$(get_prop version $obj)
+
+		if [[ $new_val != $orig_val ]]; then
+			log_fail "$obj : version values changed " \
+				"($orig_val : $new_val)"
+		fi
+
+		((i = i + 1))
+	done
+}
+
+for dataset in $TESTPOOL/$TESTFS $TESTPOOL/$TESTCTR $TESTPOOL/$TESTVOL
+do
+	set_n_check $dataset
+done
+
+log_pass "Invalid version values correctly rejected"
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/usr/src/test/zfs-tests/tests/functional/cli_root/zfs_set/zfs_set_001_neg.ksh	Wed Dec 05 22:04:50 2012 -0500
@@ -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.
+#
+
+. $STF_SUITE/include/libtest.shlib
+. $STF_SUITE/tests/functional/cli_root/zfs_set/zfs_set_common.kshlib
+
+#
+# DESCRIPTION:
+# Setting invalid value to mountpoint, checksum, atime, readonly, setuid,
+# zoned or canmount on a file system, volume. It should be failed.
+#
+# STRATEGY:
+# 1. Create pool, then create file system & volume within it.
+# 2. Setting invalid value, it should be failed.
+#
+
+verify_runnable "both"
+
+set -A props "" "mountpoint" "checksum" "compression" "atime" "readonly" \
+	"setuid" "zoned" "canmount"
+
+set -A values "" "mountpoint" "checksum" "compression" "atime" "readonly" \
+	"setuid" "zoned" "0" "-?" "-on" "--on" "*" "?" "Legacy" "NONE" "oN" \
+	"On" "ON" "ofF" "OFf" "oFF" "Off" "OfF" "OFF" "LzJb" "lZJb" "LZjB" \
+	"blad" "default" "TESTPOOL" "$TESTPOOL/$TESTCTR" \
+	"$TESTPOOL/$TESTCTR/$TESTFS" "$TESTPOOL/$TESTFS"
+set -A dataset "$TESTPOOL" "$TESTPOOL/$TESTFS" "$TESTPOOL/$TESTVOL"
+
+log_assert "Setting invalid value to mountpoint, checksum, compression, atime,"\
+	"readonly, setuid, zoned or canmount on a file system file system or volume." \
+	"It should be failed."
+
+typeset -i i=0
+typeset -i j=0
+typeset -i k=0
+while (( i < ${#dataset[@]} )); do
+	j=0
+	while (( j < ${#props[@]} )); do
+		k=0
+		while (( k < ${#values[@]} )); do
+			set_n_check_prop "${values[k]}" "${props[j]}" \
+				"${dataset[i]}" false
+			(( k += 1 ))
+		done
+		(( j += 1 ))
+	done
+	(( i += 1 ))
+done
+
+log_pass "Setting invalid value to mountpoint, checksum, compression, atime, " \
+	"readonly, setuid, zoned or canmount on file system or volume pass."
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/usr/src/test/zfs-tests/tests/functional/cli_root/zfs_set/zfs_set_002_neg.ksh	Wed Dec 05 22:04:50 2012 -0500
@@ -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) 2011 by Delphix. All rights reserved.
+#
+
+. $STF_SUITE/tests/functional/cli_root/zfs_set/zfs_set_common.kshlib
+
+#
+# DESCRIPTION:
+# 'zfs set' should fail with invalid arguments
+#
+# STRATEGY:
+# 1. Create an array of invalid arguments
+# 1. Run zfs set with each invalid argument
+# 2. Verify that zfs set returns error
+#
+
+verify_runnable "both"
+
+log_assert "'zfs set' fails with invalid arguments"
+
+set -A editable_props "quota" "reservation" "reserv" "volsize" "recordsize" "recsize" \
+		"mountpoint" "checksum" "compression" "compress" "atime" \
+		"devices" "exec" "setuid" "readonly" "zoned" "snapdir" "aclmode" \
+		"aclinherit" "canmount" "xattr" "copies" "version"
+
+for ds in $TESTPOOL $TESTPOOL/$TESTFS $TESTPOOL/$TESTVOL \
+	$TESTPOOL/$TESTFS@$TESTSNAP; do
+	for badarg in "" "-" "-?"; do
+		for prop in ${editable_props[@]}; do
+			log_mustnot eval "$ZFS set $badarg $prop= $ds >/dev/null 2>&1"
+		done
+	done
+done
+
+log_pass "'zfs set' fails with invalid arguments as expected."
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/usr/src/test/zfs-tests/tests/functional/cli_root/zfs_set/zfs_set_003_neg.ksh	Wed Dec 05 22:04:50 2012 -0500
@@ -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.
+#
+
+. $STF_SUITE/tests/functional/cli_root/zfs_set/zfs_set_common.kshlib
+
+#
+# DESCRIPTION:
+# 'zfs set mountpoint/sharenfs' should fail when the mountpoint is invlid
+#
+# STRATEGY:
+# 1. Create invalid scenarios
+# 2. Run zfs set mountpoint/sharenfs with invalid value
+# 3. Verify that zfs set returns expected errors
+#
+
+verify_runnable "both"
+
+function cleanup
+{
+	if [ -e $badpath ]; then
+		$RM -f $badpath
+	fi
+	if datasetexists $TESTPOOL/foo; then
+		log_must $ZFS destroy $TESTPOOL/foo
+	fi
+}
+
+log_assert "'zfs set mountpoint/sharenfs' fails with invalid scenarios"
+log_onexit cleanup
+
+badpath=/tmp/foo1.$$
+$TOUCH $badpath
+longpath=$(gen_dataset_name 1030 "abcdefg")
+
+log_must $ZFS create -o mountpoint=legacy $TESTPOOL/foo
+
+# Do the negative testing about "property may be set but unable to remount filesystem"
+log_mustnot eval "$ZFS set mountpoint=$badpath $TESTPOOL/foo >/dev/null 2>&1"
+
+# Do the negative testing about "property may be set but unable to reshare filesystem"
+log_mustnot eval "$ZFS set sharenfs=on $TESTPOOL/foo >/dev/null 2>&1"
+
+# Do the negative testing about "sharenfs property can not be set to null"
+log_mustnot eval "$ZFS set sharenfs= $TESTPOOL/foo >/dev/null 2>&1"
+
+# Do the too long pathname testing (>1024)
+log_mustnot eval "$ZFS set mountpoint=/$longpath $TESTPOOL/foo >/dev/null 2>&1"
+
+log_pass "'zfs set mountpoint/sharenfs' fails with invalid scenarios as expected."
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/usr/src/test/zfs-tests/tests/functional/cli_root/zfs_set/zfs_set_common.kshlib	Wed Dec 05 22:04:50 2012 -0500
@@ -0,0 +1,260 @@
+#
+# CDDL HEADER START
+#
+# The contents of this file are subject to the terms of the
+# Common Development and Distribution License (the "License").
+# You may not use this file except in compliance with the License.
+#
+# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
+# or http://www.opensolaris.org/os/licensing.
+# See the License for the specific language governing permissions
+# and limitations under the License.
+#
+# When distributing Covered Code, include this CDDL HEADER in each
+# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
+# If applicable, add the following below this CDDL 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.
+#
+
+. $STF_SUITE/include/libtest.shlib
+
+set -A VALID_NAME_CHAR 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 \
+    0 1 2 3 4 5 6 7 8 9 ':' '-' '.' '_'
+set -A INVALID_NAME_CHAR 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 \
+    '`' '~' '!' '@' '#' '$' '%' '^' '&' '(' ')' '+' '=' '|' "\\" '{' '[' ']' \
+    '}' ';' '"' '<' ',' '>' '?' '/' ' '
+set -A ALL_CHAR ${VALID_NAME_CHAR[*]} ${INVALID_NAME_CHAR[*]}
+
+#
+# Firstly, set the property value to dataset. Then checking if the property
+# value is equal with the expected value, according to the expected result.
+#
+# $1 property value
+# $2 property name
+# $3 dataset
+# $4 expected result
+#
+function set_n_check_prop
+{
+	typeset expect_value=$1
+	typeset prop=$2
+	typeset dataset=$3
+	typeset expect_result=${4:-true}
+
+	typeset old_value=""
+	typeset cur_value=""
+
+	[[ -n $prop ]] && old_value=$(get_prop $prop $dataset)
+
+	if [[ $expect_result == true ]]; then
+		[[ -z $prop || -z $dataset ]] && \
+			log_fail "property or dataset isn't defined."
+
+		log_must $ZFS set $prop=$expect_value $dataset
+		if [[ $expect_value == "gzip-6" ]]; then
+			expect_value="gzip"
+		fi
+
+		[[ -n $prop ]] && cur_value=$(get_prop $prop $dataset)
+
+		case $prop in
+			reservation|reserv|quota )
+				if [[ $expect_value == "none" ]]; then
+					[[ $cur_value != "0" ]] && \
+						log_fail "The '$dataset' '$prop' value \
+						'$cur_value' is not expected."
+				elif [[ $cur_value != $expect_value ]]; then
+					log_fail "The '$dataset' '$prop' value '$cur_value' \
+					does not equal the expected value '$expect_value'."
+				fi
+				;;
+			* )
+				if [[ $cur_value != $expect_value ]]; then
+					log_fail "The '$dataset' '$prop' value '$cur_value' \
+					does not equal the expected value '$expect_value'."
+				fi
+				;;
+		esac
+
+	else
+		log_mustnot $ZFS set $prop=$expect_value $dataset
+
+		[[ -n $prop ]] && cur_value=$(get_prop $prop $dataset)
+
+		if [[ "$expect_value" != "" && "$cur_value" != "$old_value" ]];
+		then
+			log_fail "The '$dataset' '$prop' value '$cur_value' \
+				should equal with '$old_value'."
+		fi
+	fi
+}
+
+#
+# Cleanup all the user properties of the pool and the dataset reside it.
+#
+# $1 pool name
+#
+function cleanup_user_prop
+{
+	typeset pool=$1
+	typeset dtst=$($ZFS list -H -r -o name -t filesystem,volume $pool)
+
+	typeset user_prop
+	for dt in $dtst; do
+		user_prop=$($ZFS get -H -o property all $dtst | grep ":")
+
+		typeset prop
+		for prop in $user_prop; do
+			$ZFS inherit $prop $dt
+			(($? != 0)) && log_must $ZFS inherit $prop $dt
+		done
+	done
+}
+
+#
+# Random select charactor from the specified charactor set and combine into a
+# random string
+#
+# $1 character set name
+# $2 String length
+#
+function random_string
+{
+	typeset char_set=${1:-VALID_NAME_CHAR}
+	typeset -i len=${2:-5}
+
+	eval typeset -i count=\${#$char_set[@]}
+
+	typeset str
+	typeset -i i=0
+	while ((i < len)); do
+		typeset -i ind
+		((ind = RANDOM % count))
+		eval str=\${str}\${$char_set[\$ind]}
+
+		((i += 1))
+	done
+
+	$ECHO "$str"
+}
+
+#
+# Get vaild user defined property name
+#
+# $1 user defined property name length
+#
+function valid_user_property
+{
+	typeset -i sumlen=${1:-10}
+	((sumlen < 2 )) && sumlen=2
+	typeset -i len
+	((len = RANDOM % sumlen))
+	typeset part1 part2
+
+	while true; do
+		part1="$(random_string VALID_NAME_CHAR $len)"
+		if [[ "$part1" == "-"* ]]; then
+			continue
+		fi
+		break
+	done
+	((len = sumlen - (len + 1)))
+
+	while true; do
+		part2="$(random_string VALID_NAME_CHAR $len)"
+		if [[ -z $part1 && -z $part2 ]]; then
+			continue
+		fi
+		break
+	done
+
+	$ECHO "${part1}:${part2}"
+}
+
+#
+# Get invaild user defined property name
+#
+# $1 user defined property name length
+#
+function invalid_user_property
+{
+	typeset -i sumlen=${1:-10}
+	((sumlen == 0)) && sumlen=1
+	typeset -i len
+	((len = RANDOM % sumlen))
+
+	typeset part1 part2
+	while true; do
+		part1="$(random_string VALID_NAME_CHAR $len)"
+		((len = sumlen - len))
+		part2="$(random_string INVALID_NAME_CHAR $len)"
+
+		# Avoid $part1 is *:* and $part2 is "=*"
+		if [[ "$part1" == *":"* && "$part2" == "="* ]]; then
+			continue
+		fi
+		break
+	done
+
+	$ECHO "${part1}${part2}"
+}
+
+#
+# Get user property value
+#
+# $1 user defined property name length
+#
+function user_property_value
+{
+	typeset -i len=${1:-100}
+
+	typeset value=$(random_string ALL_CHAR $len)
+
+	$ECHO "$value"
+}
+
+#
+# Check if the user property is identical to the expected value.
+#
+# $1 dataset
+# $2 user property
+# $3 expected value
+#
+function check_user_prop
+{
+	typeset dtst=$1
+	typeset user_prop="$2"
+	typeset expect_value="$3"
+	typeset value=$($ZFS get -p -H -o value "$user_prop" $dtst 2>&1)
+
+	if [[ "$expect_value" == "$value" ]]; then
+		return 0
+	else
+		return 1
+	fi
+}
+
+#
+# Get source of the dataset
+#
+function get_source
+{
+	typeset prop=$1
+	typeset dataset=$2
+	typeset source
+
+	source=$($ZFS get -H -o source $prop $dataset)
+        if (($? != 0)); then
+                log_fail "Unable to get $prop source for dataset $dataset"
+        fi
+
+	$ECHO "$source"
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/usr/src/test/zfs-tests/tests/functional/cli_root/zfs_share/Makefile	Wed Dec 05 22:04:50 2012 -0500
@@ -0,0 +1,53 @@
+#
+# 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) 2012 by Delphix. All rights reserved.
+#
+
+include $(SRC)/Makefile.master
+
+ROOTOPTPKG = $(ROOT)/opt/zfs-tests
+TESTDIR = $(ROOTOPTPKG)/tests/functional/cli_root/zfs_share
+
+PROGS = cleanup \
+	setup \
+	zfs_share_001_pos \
+	zfs_share_002_pos \
+	zfs_share_003_pos \
+	zfs_share_004_pos \
+	zfs_share_005_pos \
+	zfs_share_006_pos \
+	zfs_share_007_neg \
+	zfs_share_008_neg \
+	zfs_share_009_neg \
+	zfs_share_010_neg \
+	zfs_share_011_pos
+
+FILES = zfs_share.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	Thu Jan 01 00:00:00 1970 +0000
+++ b/usr/src/test/zfs-tests/tests/functional/cli_root/zfs_share/cleanup.ksh	Wed Dec 05 22:04:50 2012 -0500
@@ -0,0 +1,30 @@
+#!/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.
+#
+
+. $STF_SUITE/include/libtest.shlib
+
+default_cleanup
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/usr/src/test/zfs-tests/tests/functional/cli_root/zfs_share/setup.ksh	Wed Dec 05 22:04:50 2012 -0500
@@ -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.
+#
+
+. $STF_SUITE/include/libtest.shlib
+
+# Make sure NFS server is running before testing.
+setup_nfs_server
+
+DISK=${DISKS%% *}
+default_container_volume_setup $DISK
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/usr/src/test/zfs-tests/tests/functional/cli_root/zfs_share/zfs_share.cfg	Wed Dec 05 22:04:50 2012 -0500
@@ -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 2007 Sun Microsystems, Inc.  All rights reserved.
+# Use is subject to license terms.
+#
+
+#
+# Copyright (c) 2012 by Delphix. All rights reserved.
+#
+
+export SNAPROOT=".zfs/snapshot"
+export NONEXISTFSNAME="nonexistfs50charslong_0123456789012345678901234567"
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/usr/src/test/zfs-tests/tests/functional/cli_root/zfs_share/zfs_share_001_pos.ksh	Wed Dec 05 22:04:50 2012 -0500
@@ -0,0 +1,145 @@
+#!/bin/ksh -p
+#
+# CDDL HEADER START
+#
+# The contents of this file are subject to the terms of the
+# Common Development and Distribution License (the "License").
+# You may not use this file except in compliance with the License.
+#
+# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
+# or http://www.opensolaris.org/os/licensing.
+# See the License for the specific language governing permissions
+# and limitations under the License.
+#
+# When distributing Covered Code, include this CDDL HEADER in each
+# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
+# If applicable, add the following below this CDDL HEADER, with the
+# fields enclosed by brackets "[]" replaced with your own identifying
+# information: Portions Copyright [yyyy] [name of copyright owner]
+#
+# CDDL HEADER END
+#
+
+#
+# Copyright 2007 Sun Microsystems, Inc.  All rights reserved.
+# Use is subject to license terms.
+#
+
+. $STF_SUITE/include/libtest.shlib
+
+#
+# DESCRIPTION:
+# Verify that 'zfs set sharenfs' and 'zfs share' shares a given dataset.
+#
+# STRATEGY:
+# 1. Invoke 'zfs set sharenfs'.
+# 2. Verify that the file system is shared.
+# 3. Invoke 'zfs share'.
+# 4. Verify that the file system is shared.
+# 5. Verify that a shared filesystem cannot be shared again.
+# 6. Verify that share -a succeeds.
+#
+
+verify_runnable "global"
+
+set -A fs \
+    "$TESTDIR" "$TESTPOOL/$TESTFS" \
+    "$TESTDIR1" "$TESTPOOL/$TESTCTR/$TESTFS1" \
+    "$TESTDIR2" "$TESTPOOL/$TESTFS-clone"
+
+function cleanup
+{
+	typeset -i i=0
+	while (( i < ${#fs[*]} )); do
+		log_must $ZFS set sharenfs=off ${fs[((i+1))]}
+		unshare_fs ${fs[i]}
+
+		((i = i + 2))
+	done
+
+	if mounted $TESTPOOL/$TESTFS-clone; then
+		log_must $ZFS unmount $TESTDIR2
+	fi
+
+	datasetexists $TESTPOOL/$TESTFS-clone && \
+		log_must $ZFS destroy -f $TESTPOOL/$TESTFS-clone
+
+	if snapexists "$TESTPOOL/$TESTFS@snapshot"; then
+		log_must $ZFS destroy -f $TESTPOOL/$TESTFS@snapshot
+	fi
+}
+
+
+#
+# Main test routine.
+#
+# Given a mountpoint and file system this routine will attempt
+# share the mountpoint and then verify it has been shared.
+#
+function test_share # mntp filesystem
+{
+	typeset mntp=$1
+	typeset filesystem=$2
+
+	not_shared $mntp || \
+	    log_fail "File system $filesystem is already shared."
+
+	log_must $ZFS set sharenfs=on $filesystem
+	is_shared $mntp || \
+	    log_fail "File system $filesystem is not shared (set sharenfs)."
+
+	#
+	# Verify 'zfs share' works as well.
+	#
+	log_must $ZFS unshare $filesystem
+	is_shared $mntp && \
+	    log_fail "File system $filesystem is still shared."
+
+	log_must $ZFS share $filesystem
+	is_shared $mntp || \
+	    log_fail "file system $filesystem is not shared (zfs share)."
+
+	log_note "Sharing a shared file system fails."
+	log_mustnot $ZFS share $filesystem
+}
+
+log_assert "Verify that 'zfs share' succeeds as root."
+log_onexit cleanup
+
+log_must $ZFS snapshot $TESTPOOL/$TESTFS@snapshot
+log_must $ZFS clone $TESTPOOL/$TESTFS@snapshot $TESTPOOL/$TESTFS-clone
+log_must $ZFS set mountpoint=$TESTDIR2 $TESTPOOL/$TESTFS-clone
+
+typeset -i i=0
+while (( i < ${#fs[*]} )); do
+	test_share ${fs[i]} ${fs[((i + 1))]}
+
+	((i = i + 2))
+done
+
+log_note "Verify 'zfs share -a' succeeds."
+
+#
+# Unshare each of the file systems.
+#
+i=0
+while (( i < ${#fs[*]} )); do
+	unshare_fs ${fs[i]}
+
+	((i = i + 2))
+done
+
+#
+# Try a zfs share -a and verify all file systems are shared.
+#
+log_must $ZFS share -a
+
+i=0
+while (( i < ${#fs[*]} )); do
+	is_shared ${fs[i]} || \
+	    log_fail "File system ${fs[i]} is not shared (share -a)"
+
+	((i = i + 2))
+done
+
+log_pass "'$ZFS share [ -a ] <filesystem>' succeeds as root."
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/usr/src/test/zfs-tests/tests/functional/cli_root/zfs_share/zfs_share_002_pos.ksh	Wed Dec 05 22:04:50 2012 -0500
@@ -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) 2012 by Delphix. All rights reserved.
+#
+
+. $STF_SUITE/include/libtest.shlib
+. $STF_SUITE/tests/functional/cli_root/zfs_share/zfs_share.cfg
+
+#
+# DESCRIPTION:
+# Verify that "zfs share" with a non-existent file system fails.
+#
+# STRATEGY:
+# 1. Make sure the NONEXISTFSNAME ZFS file system is not in 'zfs list'.
+# 2. Invoke 'zfs share <file system>'.
+# 3. Verify that share fails
+#
+
+verify_runnable "both"
+
+function cleanup
+{
+	typeset fs
+	for fs in $NONEXISTFSNAME $TESTFS ; do
+		log_must unshare_fs $TESTPOOL/$fs
+	done
+}
+
+typeset -i ret=0
+
+log_assert "Verify that "zfs share" with a non-existent file system fails."
+
+log_onexit cleanup
+
+log_mustnot $ZFS list $TESTPOOL/$NONEXISTFSNAME
+
+$ZFS share $TESTPOOL/$NONEXISTFSNAME
+ret=$?
+(( ret == 1)) || \
+	log_fail "'$ZFS share $TESTPOOL/$NONEXISTFSNAME' " \
+		"failed with an unexpected return code of $ret."
+
+log_note "Make sure the file system $TESTPOOL/$NONEXISTFSNAME is unshared"
+not_shared $TESTPOOL/$NONEXISTFSNAME || \
+	log_fail "File system $TESTPOOL/$NONEXISTFSNAME is unexpectedly shared."
+
+log_pass "'$ZFS share' with a non-existent file system fails."
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/usr/src/test/zfs-tests/tests/functional/cli_root/zfs_share/zfs_share_003_pos.ksh	Wed Dec 05 22:04:50 2012 -0500
@@ -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 2007 Sun Microsystems, Inc.  All rights reserved.
+# Use is subject to license terms.
+#
+
+. $STF_SUITE/include/libtest.shlib
+
+#
+# DESCRIPTION:
+# Invoking "zfs share <file system>" with a file system
+# whose sharenfs property is 'off' , will fail with a
+# return code of 1 and issue an error message.
+#
+# STRATEGY:
+# 1. Make sure that the ZFS file system is unshared.
+# 2. Mount the file system using the various combinations
+# - zfs set sharenfs=off <file system>
+# - zfs set sharenfs=none <file system>
+# 3. Verify that share failed with return code of 1.
+#
+
+verify_runnable "both"
+
+set -A fs \
+    "$TESTDIR" "$TESTPOOL/$TESTFS" \
+    "$TESTDIR1" "$TESTPOOL/$TESTCTR/$TESTFS1"
+
+function cleanup
+{
+	typeset -i i=0
+	while (( i < ${#fs[*]} )); do
+		log_must $ZFS inherit -r sharenfs ${fs[((i + 1))]}
+		log_must unshare_fs ${fs[i]}
+
+		((i = i + 2))
+	done
+}
+
+
+#
+# Main test routine.
+#
+# Given a mountpoint and file system this routine will attempt
+# to share a legacy mountpoint and then verify the share fails as
+# expected.
+#
+function test_legacy_share # mntp filesystem
+{
+	typeset mntp=$1
+	typeset filesystem=$2
+
+	not_shared $mntp || \
+	    log_fail "File system $filesystem is already shared."
+
+	if is_global_zone ; then
+		log_must $ZFS set sharenfs=off $filesystem
+		not_shared $mntp || \
+		    log_fail "File system $filesystem is still shared (set sharenfs)."
+	fi
+
+	$ZFS share $filesystem
+	ret=$?
+	(( ret == 1)) || \
+	    log_fail "'$ZFS share $filesystem' " \
+		"unexpected return code of $ret."
+
+	not_shared $mntp || \
+	    log_fail "file system $filesystem is shared (zfs share)."
+}
+
+log_assert "Verify that '$ZFS share' with a file system " \
+        "whose sharenfs property is 'off'  " \
+        "will fail with return code 1."
+log_onexit cleanup
+
+typeset -i i=0
+while (( i < ${#fs[*]} )); do
+	test_legacy_share ${fs[i]} ${fs[((i + 1))]}
+
+	((i = i + 2))
+done
+
+log_pass "Verify that '$ZFS share' with a file system " \
+        "whose sharenfs property is 'off' fails."
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/usr/src/test/zfs-tests/tests/functional/cli_root/zfs_share/zfs_share_004_pos.ksh	Wed Dec 05 22:04:50 2012 -0500
@@ -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) 2012 by Delphix. All rights reserved.
+#
+
+. $STF_SUITE/include/libtest.shlib
+. $STF_SUITE/tests/functional/cli_root/zfs_share/zfs_share.cfg
+
+#
+# DESCRIPTION:
+# Verify that a file system and its snapshot are shared.
+#
+# STRATEGY:
+# 1. Create a file system
+# 2. Set the sharenfs property on the file system
+# 3. Create a snapshot
+# 4. Verify that both are shared.
+#
+
+verify_runnable "global"
+
+function cleanup
+{
+	if snapexists $TESTPOOL/$TESTFS@snapshot; then
+		log_must $ZFS destroy $TESTPOOL/$TESTFS@snapshot
+	fi
+
+	log_must $ZFS set sharenfs=off $TESTPOOL/$TESTFS
+	log_must unshare_fs $TESTPOOL/$TESTFS
+}
+
+#
+# Main test routine.
+#
+# Given a mountpoint and file system this routine will attempt
+# share the mountpoint and then verify a snapshot of the mounpoint
+# is also shared.
+#
+function test_snap_share # mntp filesystem
+{
+        typeset mntp=$1
+        typeset filesystem=$2
+
+        not_shared $mntp || \
+            log_fail "File system $filesystem is already shared."
+
+        log_must $ZFS set sharenfs=on $filesystem
+        is_shared $mntp || \
+            log_fail "File system $filesystem is not shared (set sharenfs)."
+
+	log_must $LS -l  $mntp/$SNAPROOT/snapshot
+        #
+        # Verify 'zfs share' works as well.
+        #
+        log_must $ZFS unshare $filesystem
+        log_must $ZFS share $filesystem
+
+        is_shared $mntp || \
+            log_fail "file system $filesystem is not shared (zfs share)."
+
+	log_must $LS -l  $mntp/$SNAPROOT/snapshot
+}
+
+log_assert "Verify that a file system and its snapshot are shared."
+log_onexit cleanup
+
+log_must $ZFS snapshot $TESTPOOL/$TESTFS@snapshot
+test_snap_share $TESTDIR $TESTPOOL/$TESTFS
+
+log_pass "A file system and its snapshot are both shared as expected."
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/usr/src/test/zfs-tests/tests/functional/cli_root/zfs_share/zfs_share_005_pos.ksh	Wed Dec 05 22:04:50 2012 -0500
@@ -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.
+#
+
+. $STF_SUITE/include/libtest.shlib
+
+#
+# DESCRIPTION:
+# Verify that NFS share options are propagated correctly.
+#
+# STRATEGY:
+# 1. Create a ZFS file system.
+# 2. For each option in the list, set the sharenfs property.
+# 3. Verify through the share command that the options are propagated.
+#
+
+verify_runnable "global"
+
+function cleanup
+{
+	log_must $ZFS set sharenfs=off $TESTPOOL/$TESTFS
+	is_shared $TESTPOOL/$TESTFS && \
+		log_must unshare_fs $TESTPOOL/$TESTFS
+}
+
+set -A shareopts \
+    "ro" "ro=machine1" "ro=machine1:machine2" \
+    "rw" "rw=machine1" "rw=machine1:machine2" \
+    "ro=machine1:machine2,rw" "anon=0" "anon=0,sec=sys,rw" \
+    "nosuid" "root=machine1:machine2" "rw=.mydomain.mycompany.com" \
+    "rw=-terra:engineering" "log" "public"
+
+log_assert "Verify that NFS share options are propagated correctly."
+log_onexit cleanup
+
+cleanup
+
+typeset -i i=0
+while (( i < ${#shareopts[*]} ))
+do
+	log_must $ZFS set sharenfs="${shareopts[i]}" $TESTPOOL/$TESTFS
+
+	option=`get_prop sharenfs $TESTPOOL/$TESTFS`
+	if [[ $option != ${shareopts[i]} ]]; then
+		log_fail "get sharenfs failed. ($option != ${shareopts[i]})"
+	fi
+
+	$SHARE | $GREP $option > /dev/null 2>&1
+	if (( $? != 0 )); then
+		log_fail "The '$option' option was not found in share output."
+	fi
+
+	((i = i + 1))
+done
+
+log_pass "NFS options were propagated correctly."
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/usr/src/test/zfs-tests/tests/functional/cli_root/zfs_share/zfs_share_006_pos.ksh	Wed Dec 05 22:04:50 2012 -0500
@@ -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.
+#
+
+. $STF_SUITE/include/libtest.shlib
+
+#
+# DESCRIPTION:
+# Verify that a dataset could not be shared but filesystems are shared.
+#
+# STRATEGY:
+# 1. Create a dataset and file system
+# 2. Set the sharenfs property on the dataset
+# 3. Verify that the dataset is unable be shared.
+# 4. Add a new file system to the dataset.
+# 5. Verify that the newly added file system be shared.
+#
+
+verify_runnable "global"
+
+function cleanup
+{
+	log_must $ZFS set sharenfs=off $TESTPOOL/$TESTCTR
+	if mounted $TESTDIR2; then
+		log_must $ZFS unmount $TESTDIR2
+	fi
+
+	datasetexists $TESTPOOL/$TESTCTR/$TESTFS2 && \
+		log_must $ZFS destroy $TESTPOOL/$TESTCTR/$TESTFS2
+
+	typeset fs=""
+	for fs in $mntp $TESTDIR1 $TESTDIR2
+	do
+		log_must unshare_fs $fs
+	done
+}
+
+#
+# Main test routine.
+#
+# Given a mountpoint and a dataset, this routine will set the
+# sharenfs property on the dataset and verify that dataset
+# is unable to be shared but the existing contained file systems
+# could be shared.
+#
+function test_ctr_share # mntp ctr
+{
+	typeset mntp=$1
+	typeset ctr=$2
+
+	not_shared $mntp || \
+	    log_fail "Mountpoint: $mntp is already shared."
+
+	log_must $ZFS set sharenfs=on $ctr
+
+	not_shared $mntp || \
+		log_fail "File system $mntp is shared (set sharenfs)."
+
+	#
+	# Add a new file system to the dataset and verify it is shared.
+	#
+	typeset mntp2=$TESTDIR2
+	log_must $ZFS create $ctr/$TESTFS2
+	log_must $ZFS set mountpoint=$mntp2 $ctr/$TESTFS2
+
+	is_shared $mntp2 || \
+	    log_fail "File system $mntp2 was not shared (set sharenfs)."
+}
+
+log_assert "Verify that a dataset could not be shared, " \
+	"but its sub-filesystems could be shared."
+log_onexit cleanup
+
+typeset mntp=$(get_prop mountpoint $TESTPOOL/$TESTCTR)
+test_ctr_share $mntp $TESTPOOL/$TESTCTR
+
+log_pass "A dataset could not be shared, " \
+	"but its sub-filesystems could be shared as expect."
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/usr/src/test/zfs-tests/tests/functional/cli_root/zfs_share/zfs_share_007_neg.ksh	Wed Dec 05 22:04:50 2012 -0500
@@ -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 2007 Sun Microsystems, Inc.  All rights reserved.
+# Use is subject to license terms.
+#
+
+. $STF_SUITE/include/libtest.shlib
+
+#
+# DESCRIPTION:
+# Verify that invalid share parameters and options are caught.
+#
+# STRATEGY:
+# 1. Create a ZFS file system.
+# 2. For each option in the list, set the sharenfs property.
+# 3. Verify that the error code and sharenfs property.
+#
+
+verify_runnable "both"
+
+function cleanup {
+	if is_global_zone; then
+		log_must $ZFS set sharenfs=off $TESTPOOL/$TESTFS
+	fi
+}
+
+set -A badopts \
+    "r0" "r0=machine1" "r0=machine1:machine2" \
+    "-g" "-b" "-c" "-d" "--invalid" \
+    "$TESTPOOL" "$TESTPOOL/$TESTFS" "$TESTPOOL\$TESTCTR\$TESTFS1"
+
+log_assert "Verify that invalid share parameters and options are caught."
+log_onexit cleanup
+
+typeset -i i=0
+while (( i < ${#badopts[*]} ))
+do
+	log_note "Setting sharenfs=${badopts[i]} $i "
+	log_mustnot $ZFS set sharenfs="${badopts[i]}" $TESTPOOL/$TESTFS
+
+	$SHARE | $GREP $option > /dev/null 2>&1
+	if (( $? == 0 )); then
+		log_fail "An invalid setting '$option' was propagated."
+	fi
+
+	#
+	# To global zone, sharenfs must be set 'off' before malformed testing.
+	# Otherwise, the malformed test return '0'.
+	#
+	# To non-global zone, sharenfs can be set even 'off' or 'on'.
+	#
+	if is_global_zone; then
+		log_note "Resetting sharenfs option"
+		log_must $ZFS set sharenfs=off $TESTPOOL/$TESTFS
+	fi
+
+	((i = i + 1))
+done
+
+log_pass "Invalid share parameters and options we caught as expected."
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/usr/src/test/zfs-tests/tests/functional/cli_root/zfs_share/zfs_share_008_neg.ksh	Wed Dec 05 22:04:50 2012 -0500
@@ -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.
+#
+
+. $STF_SUITE/include/libtest.shlib
+
+#
+# DESCRIPTION:
+# Verify that sharing a dataset other than filesystem fails.
+#
+# STRATEGY:
+# 1. Create a ZFS file system.
+# 2. For each dataset in the list, set the sharenfs property.
+# 3. Verify that the invalid datasets are not shared.
+#
+
+verify_runnable "global"
+
+if is_global_zone ; then
+	set -A datasets \
+	    "$TESTPOOL/$TESTVOL" "$TESTDIR"
+fi
+
+log_assert "Verify that sharing a dataset other than filesystem fails."
+
+typeset -i i=0
+while (( i < ${#datasets[*]} ))
+do
+	log_mustnot $ZFS set sharenfs=on ${datasets[i]}
+
+	option=`get_prop sharenfs ${datasets[i]}`
+	if [[ $option == ${datasets[i]} ]]; then
+		log_fail "set sharenfs failed. ($option == ${datasets[i]})"
+	fi
+
+	not_shared ${datasets[i]} || \
+	    log_fail "An invalid setting '$option' was propagated."
+
+	log_mustnot $ZFS share ${datasets[i]}
+
+	not_shared ${datasets[i]} || \
+	    log_fail "An invalid dataset '${datasets[i]}' was shared."
+
+	((i = i + 1))
+done
+
+log_pass "Sharing datasets other than filesystems failed as expected."
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/usr/src/test/zfs-tests/tests/functional/cli_root/zfs_share/zfs_share_009_neg.ksh	Wed Dec 05 22:04:50 2012 -0500
@@ -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.
+#
+
+. $STF_SUITE/include/libtest.shlib
+
+#
+# DESCRIPTION:
+# Verify that zfs share should fail when sharing a shared zfs filesystem
+#
+# STRATEGY:
+# 1. Make a zfs filesystem shared
+# 2. Use zfs share to share the filesystem
+# 3. Verify that zfs share returns error
+#
+
+verify_runnable "global"
+
+function cleanup
+{
+	typeset val
+
+	val=$(get_prop sharenfs $fs)
+	if [[ $val == on ]]; then
+		log_must $ZFS set sharenfs=off $fs
+	fi
+}
+
+log_assert "zfs share fails with shared filesystem"
+log_onexit cleanup
+
+fs=$TESTPOOL/$TESTFS
+sharenfs_val=$(get_prop sharenfs $fs)
+mpt=$(get_prop mountpoint $fs)
+if [[ $sharenfs_val == off ]]; then
+	log_must $ZFS set sharenfs=on $fs
+fi
+
+$SHARE | $GREP $mpt >/dev/null 2>&1
+if (( $? != 0 )); then
+	log_must $ZFS share $fs
+fi
+
+log_mustnot $ZFS share $fs
+
+log_pass "zfs share fails with shared filesystem as expected."
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/usr/src/test/zfs-tests/tests/functional/cli_root/zfs_share/zfs_share_010_neg.ksh	Wed Dec 05 22:04:50 2012 -0500
@@ -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.
+#
+
+. $STF_SUITE/include/libtest.shlib
+
+#
+# DESCRIPTION:
+# Verify that zfs share should fail with bad parameters
+#
+# STRATEGY:
+# 1. Make an array of bad parameters
+# 2. Use zfs share to share the filesystem
+# 3. Verify that zfs share returns error
+#
+
+verify_runnable "both"
+
+log_assert "zfs share fails with bad parameters"
+
+fs=$TESTPOOL/$TESTFS
+set -A badargs "A" "-A" "-" "-x" "-?" "=" "-a *" "-a"
+
+for arg in "${badargs[@]}"; do
+	log_mustnot eval "$ZFS share $arg $fs >/dev/null 2>&1"
+done
+
+#zfs share failed when missing arguments or invalid datasetname
+for obj in "" "/$fs"; do
+	log_mustnot eval "$ZFS share $obj >/dev/null 2>&1"
+done
+
+log_pass "zfs share fails with bad parameters as expected."
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/usr/src/test/zfs-tests/tests/functional/cli_root/zfs_share/zfs_share_011_pos.ksh	Wed Dec 05 22:04:50 2012 -0500
@@ -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 2008 Sun Microsystems, Inc.  All rights reserved.
+# Use is subject to license terms.
+#
+
+. $STF_SUITE/include/libtest.shlib
+
+#
+# DESCRIPTION:
+# Verify that umount and destroy fail, and do not unshare the shared
+# file system
+#
+# STRATEGY:
+# 1. Share the filesystem via 'zfs set sharenfs'.
+# 2. Try umount failure, and verify that the file system is still shared.
+# 3. Try destroy failure, and verify that the file system is still shared.
+#
+
+verify_runnable "global"
+
+function cleanup
+{
+	log_must cd $origdir
+
+	log_must $ZFS set sharenfs=off $TESTPOOL/$TESTFS
+	unshare_fs $TESTPOOL/$TESTFS
+
+	if snapexists "$TESTPOOL/$TESTFS@snapshot"; then
+		log_must $ZFS destroy -f $TESTPOOL/$TESTFS@snapshot
+	fi
+
+	if datasetexists $TESTPOOL/$TESTFS/fs2 ; then
+		log_must $ZFS destroy -f $TESTPOOL/$TESTFS/fs2
+	fi
+}
+
+log_assert "Verify that umount and destroy fail, and do not unshare the shared" \
+	"file system"
+log_onexit cleanup
+
+typeset origdir=$PWD
+
+# unmount fails will not unshare the shared filesystem
+log_must $ZFS set sharenfs=on $TESTPOOL/$TESTFS
+log_must is_shared $TESTDIR
+if cd $TESTDIR ; then
+	log_mustnot $ZFS umount $TESTPOOL/$TESTFS
+else
+	log_fail "cd $TESTDIR fails"
+fi
+log_must is_shared $TESTDIR
+
+# destroy fails will not unshare the shared filesystem
+log_must $ZFS create $TESTPOOL/$TESTFS/fs2
+if cd $TESTDIR/fs2 ; then
+	log_mustnot $ZFS destroy $TESTPOOL/$TESTFS/fs2
+else
+	log_fail "cd $TESTDIR/fs2 fails"
+fi
+log_must is_shared $TESTDIR/fs2
+
+log_pass "Verify that umount and destroy fail, and do not unshare the shared" \
+	"file system"
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/usr/src/test/zfs-tests/tests/functional/cli_root/zfs_snapshot/Makefile	Wed Dec 05 22:04:50 2012 -0500
@@ -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) 2012 by Delphix. All rights reserved.
+#
+
+include $(SRC)/Makefile.master
+
+ROOTOPTPKG = $(ROOT)/opt/zfs-tests
+TESTDIR = $(ROOTOPTPKG)/tests/functional/cli_root/zfs_snapshot
+
+PROGS = cleanup \
+	setup \
+	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
+
+FILES = zfs_snapshot.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	Thu Jan 01 00:00:00 1970 +0000
+++ b/usr/src/test/zfs-tests/tests/functional/cli_root/zfs_snapshot/cleanup.ksh	Wed Dec 05 22:04:50 2012 -0500
@@ -0,0 +1,30 @@
+#!/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.
+#
+
+. $STF_SUITE/include/libtest.shlib
+
+default_container_cleanup
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/usr/src/test/zfs-tests/tests/functional/cli_root/zfs_snapshot/setup.ksh	Wed Dec 05 22:04:50 2012 -0500
@@ -0,0 +1,32 @@
+#!/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.
+#
+
+. $STF_SUITE/include/libtest.shlib
+
+DISK=${DISKS%% *}
+
+default_container_volume_setup ${DISK}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/usr/src/test/zfs-tests/tests/functional/cli_root/zfs_snapshot/zfs_snapshot.cfg	Wed Dec 05 22:04:50 2012 -0500
@@ -0,0 +1,42 @@
+#
+# CDDL HEADER START
+#
+# The contents of this file are subject to the terms of the
+# Common Development and Distribution License (the "License").
+# You may not use this file except in compliance with the License.
+#
+# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
+# or http://www.opensolaris.org/os/licensing.
+# See the License for the specific language governing permissions
+# and limitations under the License.
+#
+# When distributing Covered Code, include this CDDL HEADER in each
+# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
+# If applicable, add the following below this CDDL HEADER, with the
+# fields enclosed by brackets "[]" replaced with your own identifying
+# information: Portions Copyright [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.
+#
+
+. $STF_SUITE/include/libtest.shlib
+
+export SNAPFS="$TESTPOOL/$TESTFS@$TESTSNAP"
+export SNAPFS1="$TESTPOOL/$TESTVOL@$TESTSNAP"
+export SNAPDIR="$TESTDIR@$TESTSNAP"
+export SNAPDIR1="$ZFSROOT/$SNAPFS1"
+export SNAPDEV1="/$TESTDIR/snap1.dat"
+export SNAPDEV2="/$TESTDIR/snap2.dat"
+
+# Name lengths for snappool1 and snappool2 must the same
+export SNAPPOOL1="snappool1"
+export SNAPPOOL2="snappool2"
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/usr/src/test/zfs-tests/tests/functional/cli_root/zfs_snapshot/zfs_snapshot_001_neg.ksh	Wed Dec 05 22:04:50 2012 -0500
@@ -0,0 +1,117 @@
+#!/bin/ksh -p
+#
+# CDDL HEADER START
+#
+# The contents of this file are subject to the terms of the
+# Common Development and Distribution License (the "License").
+# You may not use this file except in compliance with the License.
+#
+# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
+# or http://www.opensolaris.org/os/licensing.
+# See the License for the specific language governing permissions
+# and limitations under the License.
+#
+# When distributing Covered Code, include this CDDL HEADER in each
+# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
+# If applicable, add the following below this CDDL HEADER, with the
+# fields enclosed by brackets "[]" replaced with your own identifying
+# information: Portions Copyright [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.
+#
+
+. $STF_SUITE/include/libtest.shlib
+. $STF_SUITE/tests/functional/cli_root/zfs_snapshot/zfs_snapshot.cfg
+
+#
+# DESCRIPTION:
+#	Try each 'zfs snapshot' with inapplicable scenarios to make sure
+#	it returns an error. include:
+#		* No arguments given.
+#		* The argument contains invalid characters for the ZFS namesapec
+#		* Leading slash in snapshot name
+#		* The argument contains an empty component.
+#		* Missing '@' delimiter.
+#		* Multiple '@' delimiters in snapshot name.
+#		* The snapshot already exist.
+#		* Create snapshot upon the pool.
+#			(Be removed since pool is treated as filesystem as well)
+#		* Create snapshot upon a non-existent filesystem.
+#		* Too many arguments.
+#
+# 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 "both"
+
+set -A args "" \
+	"$TESTPOOL/$TESTFS@blah*" "$TESTPOOL/$TESTFS@blah?" \
+	"$TESTPOOL/$TESTVOL@blah*" "$TESTPOOL/$TESTVOL@blah?" \
+	"/$TESTPOOL/$TESTFS@$TESTSNAP" "/$TESTPOOL/$TESTVOL@$TESTSNAP" \
+	"@$TESTSNAP" "$TESTPOOL/$TESTFS@" "$TESTPOOL/$TESTVOL@" \
+	"$TESTPOOL//$TESTFS@$TESTSNAP" "$TESTPOOL//$TESTVOL@$TESTSNAP" \
+	"$TESTPOOL/$TESTFS/$TESTSNAP" "$TESTPOOL/$TESTVOL/$TESTSNAP" \
+	"$TESTPOOL/$TESTFS@$TESTSNAP@$TESTSNAP1" \
+	"$TESTPOOL/$TESTVOL@$TESTSNAP@$TESTSNAP1" \
+	"$SNAPFS" "$SNAPFS1" \
+	"blah/blah@$TESTSNAP"
+
+
+
+function setup_all
+{
+	log_note "Create snapshots and mount them..."
+
+	for snap in $SNAPFS $SNAPFS1; do
+		if ! snapexists $snap; then
+			log_must $ZFS snapshot $snap
+		fi
+	done
+
+	return 0
+}
+
+function cleanup_all
+{
+	typeset -i i=0
+
+	while (( i < ${#args[*]} )); do
+		for snap in ${args[i]}; do
+			snapexists $snap && log_must $ZFS destroy -f $snap
+		done
+		(( i = i + 1 ))
+	done
+
+	for mtpt in $SNAPDIR $SNAPDIR1; do
+		[[ -d $mtpt ]] && log_must $RM -rf $mtpt
+	done
+
+	return 0
+}
+
+log_assert "Badly-formed 'zfs snapshot' with inapplicable scenarios " \
+	"should return an error."
+log_onexit cleanup_all
+
+setup_all
+
+typeset -i i=0
+while (( i < ${#args[*]} )); do
+	log_mustnot $ZFS snapshot ${args[i]}
+	((i = i + 1))
+done
+
+log_pass "Badly formed 'zfs snapshot' with inapplicable scenarios " \
+	"fail as expected."
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/usr/src/test/zfs-tests/tests/functional/cli_root/zfs_snapshot/zfs_snapshot_002_neg.ksh	Wed Dec 05 22:04:50 2012 -0500
@@ -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.
+#
+. $STF_SUITE/include/libtest.shlib
+
+#
+# DESCRIPTION:
+#	"zfs snapshot -r" fails with invalid arguments or scenarios.
+#	The invalid scenarios may include:
+#	(1) The child filesystem already has snapshot with the same name
+#	(2) The child volume already has snapshot with the same name
+#
+# STRATEGY:
+#	1. Create an array of invalid arguments
+#	2. Execute 'zfs snapshot -r' with each argument in the array,
+#	3. Verify an error is returned.
+#
+
+verify_runnable "both"
+
+function cleanup
+{
+	typeset snap
+
+	for snap in $TESTPOOL/$TESTCTR/$TESTFS1@$TESTSNAP \
+		$TESTPOOL/$TESTCTR/$TESTVOL@$TESTSNAP;
+	do
+		snapexists $snap && \
+			log_must $ZFS destroy $snap
+	done
+
+	datasetexists $TESTPOOL/$TESTCTR/$TESTVOL && \
+		log_must $ZFS destroy -rf $TESTPOOL/$TESTCTR/$TESTVOL
+
+}
+
+log_assert "'zfs snapshot -r' fails with invalid arguments or scenarios. "
+log_onexit cleanup
+
+set -A args "" \
+    "$TESTPOOL/$TESTCTR@$TESTSNAP" "$TESTPOOL/$TESTCTR@blah?" \
+    "$TESTPOOL/$TESTCTR@blah*" "@$TESTSNAP" "$TESTPOOL/$TESTCTR@" \
+    "$TESTPOOL/$TESTFS/$TESTSNAP" "blah/blah@$TESTSNAP" \
+    "$TESTPOOL/$TESTCTR@$TESTSNAP@$TESTSNAP"
+
+# setup preparations
+log_must $ZFS snapshot $TESTPOOL/$TESTCTR/$TESTFS1@$TESTSNAP
+
+# testing
+typeset -i i=0
+while (( i < ${#args[*]} )); do
+	log_mustnot $ZFS snapshot -r ${args[i]}
+
+	((i = i + 1))
+done
+
+# Testing the invalid senario: the child volume already has an
+# identical name snapshot, zfs snapshot -r should fail when
+# creating snapshot with -r for the parent
+log_must $ZFS destroy $TESTPOOL/$TESTCTR/$TESTFS1@$TESTSNAP
+if is_global_zone; then
+	log_must $ZFS create -V $VOLSIZE $TESTPOOL/$TESTCTR/$TESTVOL
+else
+	log_must $ZFS create $TESTPOOL/$TESTCTR/$TESTVOL
+fi
+log_must $ZFS snapshot $TESTPOOL/$TESTCTR/$TESTVOL@$TESTSNAP
+
+log_mustnot $ZFS snapshot -r $TESTPOOL/$TESTCTR@$TESTSNAP
+
+log_pass "'zfs snapshot -r' fails with invalid arguments or scenarios as expected."
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/usr/src/test/zfs-tests/tests/functional/cli_root/zfs_snapshot/zfs_snapshot_003_neg.ksh	Wed Dec 05 22:04:50 2012 -0500
@@ -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.
+#
+. $STF_SUITE/include/libtest.shlib
+
+#
+# DESCRIPTION:
+#	"zfs snapshot" fails with bad options,too many arguments or too long
+#	snapshot name
+#
+# STRATEGY:
+#	1. Create an array of invalid arguments
+#	2. Execute 'zfs snapshot' with each argument in the array,
+#	3. Verify an error is returned.
+#
+
+verify_runnable "both"
+
+log_assert "'zfs snapshot' fails with bad options, or too many arguments. "
+
+set -A badopts "r" "R" "-R" "-x" "-rR" "-?" "-*" "-123"
+
+# set too long snapshot name (>256)
+l_name="$(gen_dataset_name 260 abcdefg)"
+
+for ds in $TESTPOOL/$TESTFS $TESTPOOL/$TESTCTR $TESTPOOL/$TESTVOL; do
+	for opt in ${badopts[@]}; do
+		log_mustnot $ZFS snapshot $opt $ds@$TESTSNAP
+	done
+
+	log_mustnot $ZFS snapshot $ds@snap $ds@snap1
+	log_mustnot $ZFS snapshot -r $ds@snap $ds@snap1
+
+	log_mustnot $ZFS snapshot $ds@$l_name
+	log_mustnot $ZFS snapshot -r $ds@$l_name
+done
+
+log_pass "'zfs snapshot' fails with bad options or too many arguments as expected."
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/usr/src/test/zfs-tests/tests/functional/cli_root/zfs_snapshot/zfs_snapshot_004_neg.ksh	Wed Dec 05 22:04:50 2012 -0500
@@ -0,0 +1,92 @@
+#!/bin/ksh -p
+#
+# CDDL HEADER START
+#
+# The contents of this file are subject to the terms of the
+# Common Development and Distribution License (the "License").
+# You may not use this file except in compliance with the License.
+#
+# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
+# or http://www.opensolaris.org/os/licensing.
+# See the License for the specific language governing permissions
+# and limitations under the License.
+#
+# When distributing Covered Code, include this CDDL HEADER in each
+# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
+# If applicable, add the following below this CDDL 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.
+#
+
+. $STF_SUITE/include/libtest.shlib
+
+#
+# DESCRIPTION:
+#	Verify recursive snapshotting could not break ZFS.
+#
+# STRATEGY:
+#	1. Create deeply-nested filesystems until it is too long to create snap
+#	2. Verify zfs snapshot -r pool@snap will not break ZFS
+#
+
+verify_runnable "both"
+
+function cleanup
+{
+	if datasetexists $initfs ; then
+		log_must $ZFS destroy -rf $initfs
+	fi
+}
+
+log_assert "Verify recursive snapshotting could not break ZFS."
+log_onexit cleanup
+
+initfs=$TESTPOOL/$TESTFS/$TESTFS
+basefs=$initfs
+typeset -i ret=0 len snaplen
+while ((ret == 0)); do
+	$ZFS create $basefs
+	$ZFS snapshot $basefs@snap1
+	ret=$?
+
+	if ((ret != 0)); then
+		len=$($ECHO $basefs| $WC -c)
+		log_note "The deeply-nested filesystem len: $len"
+
+		#
+		# Make sure there are at lease 2 characters left
+		# for snapshot name space, otherwise snapshot name
+		# is incorrect
+		#
+		if ((len >= 255)); then
+			if datasetexists $basefs; then
+				log_must $ZFS destroy -r $basefs
+			fi
+			basefs=${basefs%/*}
+			len=$($ECHO $basefs| $WC -c)
+		fi
+		break
+	fi
+
+	basefs=$basefs/$TESTFS
+done
+
+# Make snapshot name is longer than the max length
+((snaplen = 256 - len + 10))
+snap=$(gen_dataset_name $snaplen "s")
+log_mustnot $ZFS snapshot -r $TESTPOOL@$snap
+
+log_must datasetnonexists $TESTPOOL@$snap
+while [[ $basefs != $TESTPOOL ]]; do
+	log_must datasetnonexists $basefs@$snap
+	basefs=${basefs%/*}
+done
+
+log_pass "Verify recursive snapshotting could not break ZFS."
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/usr/src/test/zfs-tests/tests/functional/cli_root/zfs_snapshot/zfs_snapshot_005_neg.ksh	Wed Dec 05 22:04:50 2012 -0500
@@ -0,0 +1,92 @@
+#!/bin/ksh -p
+#
+# CDDL HEADER START
+#
+# The contents of this file are subject to the terms of the
+# Common Development and Distribution License (the "License").
+# You may not use this file except in compliance with the License.
+#
+# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
+# or http://www.opensolaris.org/os/licensing.
+# See the License for the specific language governing permissions
+# and limitations under the License.
+#
+# When distributing Covered Code, include this CDDL HEADER in each
+# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
+# If applicable, add the following below this CDDL 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.
+#
+
+. $STF_SUITE/include/libtest.shlib
+
+#
+# DESCRIPTION:
+#	Long name filesystem with snapshot should not break ZFS.
+#
+# STRATEGY:
+#	1. Create filesystem and snapshot.
+#	2. When the snapshot length is 256, rename the filesystem.
+#	3. Verify it does not break ZFS
+#
+
+verify_runnable "both"
+
+function cleanup
+{
+	if datasetexists $initfs ; then
+		log_must $ZFS destroy -rf $initfs
+	fi
+}
+
+log_assert "Verify long name filesystem with snapshot should not break ZFS."
+log_onexit cleanup
+
+initfs=$TESTPOOL/$TESTFS/$TESTFS
+basefs=$initfs
+typeset -i ret=0 len snaplen
+while ((ret == 0)); do
+	$ZFS create $basefs
+	$ZFS snapshot $basefs@snap1
+	ret=$?
+
+	if ((ret != 0)); then
+		len=$($ECHO $basefs | $WC -c)
+		log_note "The deeply-nested filesystem len: $len"
+
+		#
+		# Make sure there are at lease 2 characters left
+		# for snapshot name space, otherwise snapshot name
+		# is incorrect
+		#
+		if ((len >= 255)); then
+			if datasetexists $basefs; then
+				log_must $ZFS destroy -r $basefs
+			fi
+			basefs=${basefs%/*}
+			len=$($ECHO $basefs| $WC -c)
+		fi
+		break
+	fi
+
+	basefs=$basefs/$TESTFS
+done
+
+# Make snapshot name length match the longest one
+((snaplen = 256 - len - 1)) # 1: @
+snap=$(gen_dataset_name $snaplen "s")
+log_must $ZFS snapshot $basefs@$snap
+
+log_mustnot $ZFS rename $basefs ${basefs}a
+log_mustnot $ZFS rename $basefs ${basefs}-new
+log_mustnot $ZFS rename $initfs ${initfs}-new
+log_mustnot $ZFS rename $TESTPOOL/$TESTFS $TESTPOOL/$TESTFS-new
+
+log_pass "Verify long name filesystem with snapshot should not break ZFS."
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/usr/src/test/zfs-tests/tests/functional/cli_root/zfs_snapshot/zfs_snapshot_006_pos.ksh	Wed Dec 05 22:04:50 2012 -0500
@@ -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) 2012 by Delphix. All rights reserved.
+#
+
+. $STF_SUITE/tests/functional/cli_root/zfs_set/zfs_set_common.kshlib
+
+#
+# DESCRIPTION:
+#	User property could be set via creation time by 'zfs snapshot -o'
+#
+# STRATEGY:
+#	1. Create snapshot and give '-o property=value'
+#	2. Verify the snapshot be created and user property have been set.
+#
+
+verify_runnable "both"
+
+function cleanup
+{
+	for fs in $TESTPOOL/$TESTFS $TESTPOOL/$TESTVOL $TESTPOOL ; do
+		typeset fssnap=$fs@snap
+		if datasetexists $fssnap ; then
+			log_must $ZFS destroy -rf $fssnap
+		fi
+	done
+	cleanup_user_prop $TESTPOOL
+}
+
+function nonexist_user_prop
+{
+	typeset user_prop=$1
+	typeset dtst=$2
+
+	typeset source=$(get_source $user_prop $dtst)
+	typeset value=$(get_prop $user_prop $dtst)
+	if [[ $source == '-' && $value == '-' ]]; then
+		return 0
+	else
+		return 1
+	fi
+}
+
+log_assert "User property could be set upon snapshot via 'zfs snapshot -o'."
+log_onexit cleanup
+
+typeset snap_property=
+
+for fs in $TESTPOOL/$TESTFS $TESTPOOL/$TESTVOL $TESTPOOL ; do
+	typeset fssnap=$fs@snap
+	prop_name=$(valid_user_property 10)
+	value=$(user_property_value 16)
+
+	log_must eval "$ZFS snapshot -o $prop_name='$value' $fssnap"
+	log_must snapexists $fssnap
+	log_mustnot nonexist_user_prop $prop_name $fssnap
+
+	log_must $ZFS destroy -f $fssnap
+
+	prop_name2=$(valid_user_property 10)
+	value2=$(user_property_value 16)
+
+	log_must eval "$ZFS snapshot -o $prop_name='$value' -o $prop_name2='$value2' $fssnap"
+	log_must snapexists $fssnap
+	log_mustnot nonexist_user_prop $prop_name $fssnap
+	log_mustnot nonexist_user_prop $prop_name2 $fssnap
+done
+
+cleanup
+
+prop_name=$(valid_user_property 10)
+value=$(user_property_value 16)
+
+log_must eval "$ZFS snapshot -r -o $prop_name='$value' $TESTPOOL@snap"
+for fs in $TESTPOOL/$TESTFS $TESTPOOL/$TESTVOL $TESTPOOL ; do
+	typeset fssnap=$fs@snap
+	log_must snapexists $fssnap
+	log_mustnot nonexist_user_prop $prop_name $fssnap
+
+	log_must $ZFS destroy -rf $fssnap
+done
+
+cleanup
+
+prop_name2=$(valid_user_property 10)
+value2=$(user_property_value 16)
+
+log_must eval "$ZFS snapshot -r -o $prop_name='$value' -o $prop_name2='$value2' $TESTPOOL@snap"
+for fs in $TESTPOOL/$TESTFS $TESTPOOL/$TESTVOL $TESTPOOL ; do
+	typeset fssnap=$fs@snap
+	log_must snapexists $fssnap
+	log_mustnot nonexist_user_prop $prop_name $fssnap
+	log_mustnot nonexist_user_prop $prop_name2 $fssnap
+
+	log_must $ZFS destroy -rf $fssnap
+done
+
+log_pass "User property could be set upon snapshot via 'zfs snapshot -o'."
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/usr/src/test/zfs-tests/tests/functional/cli_root/zfs_snapshot/zfs_snapshot_007_neg.ksh	Wed Dec 05 22:04:50 2012 -0500
@@ -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.
+#
+
+. $STF_SUITE/tests/functional/cli_root/zfs_set/zfs_set_common.kshlib
+
+#
+# DESCRIPTION:
+#	'zfs snapshot -o' cannot set properties other than user property
+#
+# STRATEGY:
+#	1. Create snapshot and give '-o property=value' with regular property.
+#	2. Verify the snapshot creation failed.
+#
+
+verify_runnable "both"
+
+function cleanup
+{
+	for fs in $TESTPOOL/$TESTFS $TESTPOOL/$TESTVOL $TESTPOOL/$TESTCTR $TESTPOOL ; do
+		typeset fssnap=$fs@snap
+		if datasetexists $fssnap ; then
+			log_must $ZFS destroy -rf $fssnap
+		fi
+	done
+	cleanup_user_prop $TESTPOOL
+}
+
+function nonexist_user_prop
+{
+	typeset user_prop=$1
+	typeset dtst=$2
+
+	typeset source=$(get_source $user_prop $dtst)
+	typeset value=$(get_prop $user_prop $dtst)
+	if [[ $source == '-' && $value == '-' ]]; then
+		return 0
+	else
+		return 1
+	fi
+}
+
+log_assert "'zfs snapshot -o' cannot set properties other than user property."
+log_onexit cleanup
+
+typeset ro_props="type used available avail creation referenced refer compressratio \
+	mounted origin"
+typeset snap_ro_props="volsize recordsize recsize quota reservation reserv mountpoint \
+	sharenfs checksum compression compress atime devices exec readonly rdonly \
+	setuid zoned"
+
+$ZFS upgrade -v > /dev/null 2>&1
+if [[ $? -eq 0 ]]; then
+	snap_ro_props="$snap_ro_props version"
+fi
+
+
+for fs in $TESTPOOL/$TESTFS $TESTPOOL/$TESTVOL $TESTPOOL/$TESTCTR $TESTPOOL ; do
+	typeset fssnap=$fs@snap
+	prop_name=$(valid_user_property 10)
+	value=$(user_property_value 16)
+
+	log_must eval "$ZFS snapshot -o $prop_name='$value' $fssnap"
+	log_must snapexists $fssnap
+	log_mustnot nonexist_user_prop $prop_name $fssnap
+
+	log_must $ZFS destroy -f $fssnap
+
+	prop_name2=$(valid_user_property 10)
+	value2=$(user_property_value 16)
+
+	log_must eval "$ZFS snapshot -o $prop_name='$value' -o $prop_name2='$value2' $fssnap"
+	log_must snapexists $fssnap
+	log_mustnot nonexist_user_prop $prop_name $fssnap
+	log_mustnot nonexist_user_prop $prop_name2 $fssnap
+
+	log_must $ZFS destroy -f $fssnap
+done
+
+cleanup
+
+prop_name=$(valid_user_property 10)
+value=$(user_property_value 16)
+
+log_must eval "$ZFS snapshot -r -o $prop_name='$value' $TESTPOOL@snap"
+for fs in $TESTPOOL/$TESTFS $TESTPOOL/$TESTVOL $TESTPOOL/$TESTCTR $TESTPOOL ; do
+	typeset fssnap=$fs@snap
+	log_must snapexists $fssnap
+	log_mustnot nonexist_user_prop $prop_name $fssnap
+done
+
+cleanup
+
+prop_name2=$(valid_user_property 10)
+value2=$(user_property_value 16)
+
+log_must eval "$ZFS snapshot -r -o $prop_name='$value' -o $prop_name2='$value2' $TESTPOOL@snap"
+for fs in $TESTPOOL/$TESTFS $TESTPOOL/$TESTVOL $TESTPOOL/$TESTCTR $TESTPOOL ; do
+	typeset fssnap=$fs@snap
+	log_must snapexists $fssnap
+	log_mustnot nonexist_user_prop $prop_name $fssnap
+	log_mustnot nonexist_user_prop $prop_name2 $fssnap
+done
+
+log_pass "'zfs snapshot -o' cannot set properties other than user property."
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/usr/src/test/zfs-tests/tests/functional/cli_root/zfs_snapshot/zfs_snapshot_008_neg.ksh	Wed Dec 05 22:04:50 2012 -0500
@@ -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 (c) 2012 by Delphix. All rights reserved.
+#
+
+. $STF_SUITE/tests/functional/cli_root/zfs_snapshot/zfs_snapshot.cfg
+
+#
+# DESCRIPTION:
+#	'zfs snapshot pool1@snap pool2@snap' should fail since both snapshots
+#	are not in the same pool.
+#
+# STRATEGY:
+#	1. Create 2 separate zpools, zpool name lenghts must be the same.
+#	2. Attempt to simultaneously create a snapshot of each pool.
+#	3. Veriy the snapshot creation failed.
+#
+
+verify_runnable "both"
+
+function cleanup
+{
+	for pool in $SNAPPOOL1 $SNAPPOOL2 ; do
+		if poolexists $pool ; then
+			log_must $ZPOOL destroy -f $pool
+		fi
+	done
+
+	for dev in $SNAPDEV1 $SNAPDEV2 ; do
+		if [[ -f $dev ]] ; then
+			log_must rm -f $dev
+		fi
+	done
+}
+
+log_assert "'zfs snapshot pool1@snap1 pool2@snap2' should fail since snapshots are in different pools."
+log_onexit cleanup
+
+log_must $MKFILE 64m $SNAPDEV1
+log_must $MKFILE 64m $SNAPDEV2
+
+log_must $ZPOOL create $SNAPPOOL1 $SNAPDEV1
+log_must $ZPOOL create $SNAPPOOL2 $SNAPDEV2
+
+log_mustnot $ZFS snapshot $SNAPPOOL1@snap1 $SNAPPOOL2@snap2
+
+log_pass "'zfs snapshot pool1@snap1 pool2@snap2' should fail since snapshots are in different pools."
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/usr/src/test/zfs-tests/tests/functional/cli_root/zfs_snapshot/zfs_snapshot_009_pos.ksh	Wed Dec 05 22:04:50 2012 -0500
@@ -0,0 +1,102 @@
+#!/bin/ksh
+#
+# 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) 2012 by Delphix. All rights reserved.
+#
+
+#
+# DESCRIPTION
+# verify 'zfs snapshot <list of snapshots>' works correctly
+#
+# STRATEGY
+# 1. Create multiple datasets
+# 2. Create mutiple snapshots with a list of valid and invalid
+#    snapshot names
+# 3. Verify the valid snpashot creation
+
+. $STF_SUITE/include/libtest.shlib
+
+function cleanup
+{
+	for ds in $datasets; do
+		datasetexists $ds && log_must $ZFS destroy -r $ds
+	done
+	$ZFS destroy -r $TESTPOOL/TESTFS4
+}
+datasets="$TESTPOOL/$TESTFS1 $TESTPOOL/$TESTFS2
+    $TESTPOOL/$TESTFS3"
+
+invalid_args=("$TESTPOOL/$TESTFS1@now $TESTPOOL/$TESTFS2@now \
+    $TESTPOOL/$TESTFS@blah?" "$TESTPOOL/$TESTFS1@blah* \
+    $TESTPOOL/$TESTFS2@blah? $TESTPOOL/$TESTFS3@blah%" \
+    "$TESTPOOL/$TESTFS1@$($PYTHON -c 'print "x" * 300') $TESTPOOL/$TESTFS2@300 \
+    $TESTPOOL/$TESTFS3@300")
+
+valid_args=("$TESTPOOL/$TESTFS1@snap $TESTPOOL/$TESTFS2@snap \
+    $TESTPOOL/$TESTFS3@snap" "$TESTPOOL/$TESTFS1@$($PYTHON -c 'print "x" * 200')\
+    $TESTPOOL/$TESTFS2@2 $TESTPOOL/$TESTFS3@s")
+
+log_assert "verify zfs supports multiple consistent snapshots"
+log_onexit cleanup
+typeset -i i=1
+test_data=$STF_SUITE/tests/functional/cli_root/zpool_upgrade/blockfiles
+
+log_note "destroy a list of valid snapshots"
+for ds in $datasets; do
+	log_must $ZFS create $ds
+	log_must $CP -r $test_data /$ds
+done
+i=0
+while (( i < ${#valid_args[*]} )); do
+	log_must $ZFS snapshot ${valid_args[i]}
+	for token in ${valid_args[i]}; do
+		log_must snapexists $token && \
+		    log_must $ZFS destroy $token
+	done
+	((i = i + 1))
+done
+log_note "destroy a list of invalid snapshots"
+i=0
+while (( i < ${#invalid_args[*]} )); do
+	log_mustnot $ZFS snapshot ${invalid_args[i]}
+	for token in ${invalid_args[i]}; do
+		log_mustnot snapexists $token
+	done
+	((i = i + 1))
+done
+log_note "verify multiple snapshot transaction group"
+txg_group=$($ZDB -Pd $TESTPOOL | $GREP snap | $AWK '{print $7}')
+for i in 1 2 3; do
+	txg_tag=$($ECHO "$txg_group" | $NAWK -v j=$i 'FNR == j {print}')
+	[[ $txg_tag != $($ECHO "$txg_group" | \
+	    $NAWK -v j=$i 'FNR == j {print}') ]] \
+	    && log_fail "snapshots belong to differnt transaction groups"
+done
+log_note "verify snapshot contents"
+for ds in $datasets; do
+	status=$($DIRCMP /$ds /$ds/.zfs/snapshot/snap | $GREP "different")
+	[[ -z $status ]] || log_fail "snapshot contents are different from" \
+	    "the filesystem"
+done
+
+log_note "verify multiple snapshot with -r option"
+log_must $ZFS create $TESTPOOL/TESTFS4
+log_must $ZFS create -p $TESTPOOL/$TESTFS3/TESTFSA$($PYTHON -c 'print "x" * 210')/TESTFSB
+log_mustnot $ZFS snapshot -r $TESTPOOL/$TESTFS1@snap1 $TESTPOOL/$TESTFS2@snap1 \
+        $TESTPOOL/$TESTFS3@snap1 $TESTPOOL/TESTFS4@snap1
+log_must $ZFS rename  $TESTPOOL/$TESTFS3/TESTFSA$($PYTHON -c 'print "x" * 210') \
+    $TESTPOOL/$TESTFS3/TESTFSA
+log_must $ZFS snapshot -r $TESTPOOL/$TESTFS1@snap1 $TESTPOOL/$TESTFS2@snap1 \
+        $TESTPOOL/$TESTFS3@snap1 $TESTPOOL/TESTFS4@snap1
+
+log_pass "zfs multiple snapshot verified correctly"
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/usr/src/test/zfs-tests/tests/functional/cli_root/zfs_unmount/Makefile	Wed Dec 05 22:04:50 2012 -0500
@@ -0,0 +1,53 @@
+#
+# 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) 2012 by Delphix. All rights reserved.
+#
+
+include $(SRC)/Makefile.master
+
+ROOTOPTPKG = $(ROOT)/opt/zfs-tests
+TESTDIR = $(ROOTOPTPKG)/tests/functional/cli_root/zfs_unmount
+
+PROGS = cleanup \
+	setup \
+	zfs_unmount_001_pos \
+	zfs_unmount_002_pos \
+	zfs_unmount_003_pos \
+	zfs_unmount_004_pos \
+	zfs_unmount_005_pos \
+	zfs_unmount_006_pos \
+	zfs_unmount_007_neg \
+	zfs_unmount_008_neg \
+	zfs_unmount_009_pos \
+	zfs_unmount_all_001_pos
+
+FILES = zfs_unmount.cfg \
+	zfs_unmount.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	Thu Jan 01 00:00:00 1970 +0000
+++ b/usr/src/test/zfs-tests/tests/functional/cli_root/zfs_unmount/cleanup.ksh	Wed Dec 05 22:04:50 2012 -0500
@@ -0,0 +1,30 @@
+#!/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.
+#
+
+. $STF_SUITE/include/libtest.shlib
+
+default_cleanup
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/usr/src/test/zfs-tests/tests/functional/cli_root/zfs_unmount/setup.ksh	Wed Dec 05 22:04:50 2012 -0500
@@ -0,0 +1,32 @@
+#!/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.
+#
+
+. $STF_SUITE/include/libtest.shlib
+
+DISK=${DISKS%% *}
+
+default_setup $DISK
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/usr/src/test/zfs-tests/tests/functional/cli_root/zfs_unmount/zfs_unmount.cfg	Wed Dec 05 22:04:50 2012 -0500
@@ -0,0 +1,39 @@
+#
+# CDDL HEADER START
+#
+# The contents of this file are subject to the terms of the
+# Common Development and Distribution License (the "License").
+# You may not use this file except in compliance with the License.
+#
+# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
+# or http://www.opensolaris.org/os/licensing.
+# See the License for the specific language governing permissions
+# and limitations under the License.
+#
+# When distributing Covered Code, include this CDDL HEADER in each
+# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
+# If applicable, add the following below this CDDL HEADER, with the
+# fields enclosed by brackets "[]" replaced with your own identifying
+# information: Portions Copyright [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.
+#
+
+export mountcmd=mount
+export mountforce="$mountcmd -f"
+export mountall="$mountcmd -a"
+
+export unmountcmd=unmount
+export unmountforce="$unmountcmd -f"
+export unmountall="$unmountcmd -a"
+
+export NONEXISTFSNAME="nonexistfs50charslong_0123456789012345678901234567"
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/usr/src/test/zfs-tests/tests/functional/cli_root/zfs_unmount/zfs_unmount.kshlib	Wed Dec 05 22:04:50 2012 -0500
@@ -0,0 +1,77 @@
+#
+# CDDL HEADER START
+#
+# The contents of this file are subject to the terms of the
+# Common Development and Distribution License (the "License").
+# You may not use this file except in compliance with the License.
+#
+# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
+# or http://www.opensolaris.org/os/licensing.
+# See the License for the specific language governing permissions
+# and limitations under the License.
+#
+# When distributing Covered Code, include this CDDL HEADER in each
+# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
+# If applicable, add the following below this CDDL HEADER, with the
+# fields enclosed by brackets "[]" replaced with your own identifying
+# information: Portions Copyright [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.
+#
+
+. $STF_SUITE/tests/functional/cli_root/zfs_unmount/zfs_unmount.cfg
+
+function do_unmount #cmd #opt #mnt #expect
+{
+	typeset cmd=$1
+	typeset opt=$2
+	typeset mnt=$3
+	typeset -i expect=${4-0}
+	typeset -i ret
+	typeset -i wasmounted=1
+
+	mounted $mnt || wasmounted=0
+
+	if (( expect == 0 )) ; then
+		log_must $ZFS $cmd $opt $mnt
+
+		log_must unmounted $mnt
+
+		log_note "Successfully $ZFS $cmd $opt $mnt"
+
+	else
+		log_note "$ZFS $cmd $opt $mnt"
+
+		$ZFS $cmd $opt $mnt
+		ret=$?
+		if (( ret != expect)); then
+			log_fail "'$ZFS $cmd $opt $mnt' " \
+				"unexpected return code of $ret."
+		fi
+
+		if (( wasmounted == 1 )) ; then
+			log_must mounted $mnt
+		else
+			log_must unmounted $mnt
+		fi
+		log_note "Mount status of $mnt not changed."
+	fi
+}
+
+function cleanup
+{
+	[[ -n $cwd ]] && cd $cwd
+
+	log_must $ZFS set mountpoint=$TESTDIR $TESTPOOL/$TESTFS
+	mounted $TESTPOOL/$TESTFS || \
+		log_must $ZFS $mountcmd $TESTPOOL/$TESTFS
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/usr/src/test/zfs-tests/tests/functional/cli_root/zfs_unmount/zfs_unmount_001_pos.ksh	Wed Dec 05 22:04:50 2012 -0500
@@ -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.
+#
+. $STF_SUITE/include/libtest.shlib
+
+#
+# DESCRIPTION:
+# Creates a file system and verifies that it can be unmounted
+# using each of the various unmount options and sub-command
+# variants.
+#
+# STRATEGY:
+# 1. Create and mount a file system as necessary.
+# 2. Umount the file system using the various combinations.
+#	- With force option.
+#	- Without force option.
+#	- Using the unmount sub-command.
+#	- Using the umount sub-command.
+#
+
+verify_runnable "both"
+
+
+function cleanup
+{
+	mounted $TESTDIR2 && \
+		log_must $ZFS umount -f $TESTDIR2
+
+	datasetexists $TESTPOOL/$TESTFS2 && \
+		log_must $ZFS destroy $TESTPOOL/$TESTFS2
+
+	[[ -d $TESTDIR2 ]] && \
+		log_must $RM -rf $TESTDIR2
+}
+function do_unmount
+{
+	typeset cmd=$1
+	typeset opt=$2
+	typeset mnt=$3
+
+	[[ ! -d $TESTDIR2 ]] && \
+	    log_must $MKDIR $TESTDIR2
+
+	if ! datasetexists $TESTPOOL/$TESTFS2 ; then
+		log_must $ZFS create $TESTPOOL/$TESTFS2
+		log_must $ZFS set mountpoint=$TESTDIR2 \
+		    $TESTPOOL/$TESTFS2
+	fi
+
+	unmounted $TESTPOOL/$TESTFS2 && \
+		log_must $ZFS mount $TESTPOOL/$TESTFS2
+
+	log_must $ZFS $cmd $options $mnt
+
+	unmounted "$mnt" || \
+		log_fail "Unable to unmount $options $mnt"
+
+	log_note "Successfully unmounted $options $mnt"
+}
+
+log_onexit cleanup
+
+set -A cmd "umount" "unmount"
+set -A options "" "-f"
+set -A dev "$TESTPOOL/$TESTFS2" "$TESTDIR2"
+
+log_assert "Verify the u[n]mount [-f] sub-command."
+
+typeset -i i=0
+typeset -i j=0
+typeset -i k=0
+while [[ $i -lt ${#cmd[*]} ]]; do
+	j=0
+	while [[ $j -lt ${#options[*]} ]]; do
+		k=0
+		while [[ $k -lt ${#dev[*]} ]]; do
+			do_unmount "${cmd[i]}" "${options[j]}" \
+			    "${dev[k]}"
+
+			((k = k + 1))
+		done
+
+		((j = j + 1))
+	done
+
+	((i = i + 1))
+done
+
+log_pass "zfs u[n]mount [-f] completed successfully."
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/usr/src/test/zfs-tests/tests/functional/cli_root/zfs_unmount/zfs_unmount_002_pos.ksh	Wed Dec 05 22:04:50 2012 -0500
@@ -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 2007 Sun Microsystems, Inc.  All rights reserved.
+# Use is subject to license terms.
+#
+
+. $STF_SUITE/include/libtest.shlib
+. $STF_SUITE/tests/functional/cli_root/zfs_unmount/zfs_unmount.kshlib
+
+#
+# DESCRIPTION:
+# If invoke "zfs unmount [-f]" with a filesystem|mountpoint
+# whose name is not in "zfs list",
+# it will fail with a return code of 1
+# and issue an error message.
+#
+# STRATEGY:
+# 1. Make sure that the non-existent ZFS filesystem|mountpoint
+# not in 'zfs list'.
+# 2. Unmount the file system using the various combinations.
+#	- Without force option. (FAILED)
+#	- With force option. (FAILED)
+# 3. Unmount the mountpoint using the various combinations.
+#	- Without force option. (FAILED)
+#	- With force option. (FAILED)
+# 4. Verify the above expected results of the filesystem|mountpoint.
+#
+
+verify_runnable "both"
+
+
+set -A cmd "umount" "unmount"
+set -A options "" "-f"
+set -A dev "$TESTPOOL/$NONEXISTFSNAME" "${TEST_BASE_DIR%%/}/$NONEXISTFSNAME"
+
+function do_unmount_multiple #options #expect
+{
+	typeset opt=$1
+	typeset -i expect=${2-0}
+
+	typeset -i i=0
+	typeset -i j=0
+
+	while (( i <  ${#cmd[*]} )); do
+		j=0
+		while (( j < ${#dev[*]} )); do
+			log_note "Make sure ${dev[j]} is not in 'zfs list'"
+			log_mustnot $ZFS list ${dev[j]}
+
+			do_unmount "${cmd[i]}" "$opt" \
+				"${dev[j]}" $expect
+
+			((j = j + 1))
+		done
+
+		((i = i + 1))
+	done
+}
+
+log_assert "Verify that '$ZFS $unmountcmd [-f] <filesystem|mountpoint>' " \
+	"whose name is not in 'zfs list' will fail with return code 1."
+
+log_onexit cleanup
+
+typeset -i i=0
+
+while (( i <  ${#options[*]} )); do
+	do_unmount_multiple "${options[i]}" 1
+	((i = i + 1))
+done
+
+log_pass "'$ZFS $unmountcmd [-f] <filesystem|mountpoint>' " \
+	"whose name is not in 'zfs list' failed with return code 1."
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/usr/src/test/zfs-tests/tests/functional/cli_root/zfs_unmount/zfs_unmount_003_pos.ksh	Wed Dec 05 22:04:50 2012 -0500
@@ -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 2007 Sun Microsystems, Inc.  All rights reserved.
+# Use is subject to license terms.
+#
+
+. $STF_SUITE/include/libtest.shlib
+. $STF_SUITE/tests/functional/cli_root/zfs_unmount/zfs_unmount.kshlib
+
+#
+# DESCRIPTION:
+# If invoke "zfs unmount [-f]" with a filesystem|mountpoint
+# whose mountpoint property is 'legacy' or 'none',
+# it will fail with a return code of 1
+# and issue an error message.
+#
+# STRATEGY:
+# 1. Make sure that the ZFS filesystem is mounted.
+# 2. Apply 'zfs set mountpoint=legacy|none <filesystem>'.
+# 3. Unmount the file system using the various combinations.
+#	- Without force option. (FAILED)
+#	- With force option. (FAILED)
+# 4. Unmount the mountpoint using the various combinations.
+#	- Without force option. (FAILED)
+#	- With force option. (FAILED)
+# 5. Verify the above expected results of the filesystem|mountpoint.
+#
+
+verify_runnable "both"
+
+
+set -A cmd "umount" "unmount"
+set -A options "" "-f"
+set -A dev "$TESTPOOL/$TESTFS" "$TESTDIR"
+set -A mopts "legacy" "none"
+
+function do_unmount_multiple #options #expect #mountpoint
+{
+	typeset opt=$1
+	typeset -i expect=${2-0}
+	typeset mopt=$3
+
+	typeset -i i=0
+	typeset -i j=0
+
+	while (( i <  ${#cmd[*]} )); do
+		j=0
+		while (( j < ${#dev[*]} )); do
+			[[ -n $mopt ]] && \
+				log_must $ZFS set mountpoint=$mopt ${dev[0]}
+
+			do_unmount "${cmd[i]}" "$opt" \
+				"${dev[j]}" $expect
+
+			cleanup
+
+			((j = j + 1))
+		done
+
+		((i = i + 1))
+	done
+}
+
+log_assert "Verify that '$ZFS $unmountcmd [-f] <filesystem|mountpoint>' " \
+	"whose mountpoint property is 'legacy' or 'none' " \
+	"will fail with return code 1."
+
+log_onexit cleanup
+
+typeset -i i=0
+typeset -i j=0
+
+while (( i < ${#mopts[*]} )); do
+	j=0
+	while (( j <  ${#options[*]} )); do
+		do_unmount_multiple "${options[j]}" 1 "${mopts[i]}"
+		((j = j + 1))
+	done
+	((i = i + 1))
+done
+
+log_pass "'$ZFS $unmountcmd [-f] <filesystem|mountpoint>' " \
+	"whose mountpoint property is 'legacy' or 'none' " \
+	"will fail with return code 1."
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/usr/src/test/zfs-tests/tests/functional/cli_root/zfs_unmount/zfs_unmount_004_pos.ksh	Wed Dec 05 22:04:50 2012 -0500
@@ -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 2007 Sun Microsystems, Inc.  All rights reserved.
+# Use is subject to license terms.
+#
+
+. $STF_SUITE/include/libtest.shlib
+. $STF_SUITE/tests/functional/cli_root/zfs_unmount/zfs_unmount.kshlib
+
+#
+# DESCRIPTION:
+# If invoke "zfs unmount [-f]" with a specific filesystem|mountpoint,
+# which is not currently mounted,
+# it will fail with a return code of 1
+# and issue an error message.
+#
+# STRATEGY:
+# 1. Make sure that the ZFS filesystem is mounted.
+# 2. Invoke 'zfs unmount <filesystem>'.
+# 3. Verify that the filesystem is unmounted.
+# 4. Unmount the file system using the various combinations.
+#	- Without force option. (FAILED)
+#	- With force option. (FAILED)
+# 5. Unmount the mountpoint using the various combinations.
+#	- Without force option. (FAILED)
+#	- With force option. (FAILED)
+# 6. Verify the above expected results of the filesystem|mountpoint.
+#
+
+verify_runnable "both"
+
+
+set -A cmd "umount" "unmount"
+set -A options "" "-f"
+set -A dev "$TESTPOOL/$TESTFS" "$TESTDIR"
+
+function do_unmount_multiple #options #expect
+{
+	typeset opt=$1
+	typeset -i expect=${2-0}
+
+	typeset -i i=0
+	typeset -i j=0
+
+	while (( i <  ${#cmd[*]} )); do
+		j=0
+		while (( j < ${#dev[*]} )); do
+			unmounted ${dev[j]} || \
+				log_must $ZFS $unmountforce ${dev[j]}
+
+			do_unmount "${cmd[i]}" "$opt" \
+				"${dev[j]}" $expect
+
+			((j = j + 1))
+		done
+
+		((i = i + 1))
+	done
+}
+
+log_assert "Verify that '$ZFS $unmountcmd [-f] <filesystem|mountpoint>' " \
+	"with an unmounted filesystem will fail with return code 1."
+
+log_onexit cleanup
+
+typeset -i i=0
+
+while (( i <  ${#options[*]} )); do
+	do_unmount_multiple "${options[i]}" 1
+	((i = i + 1))
+done
+
+log_pass "'$ZFS $unmountcmd [-f] <filesystem|mountpoint>' " \
+	"with an unmounted filesystem failed with return code 1."
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/usr/src/test/zfs-tests/tests/functional/cli_root/zfs_unmount/zfs_unmount_005_pos.ksh	Wed Dec 05 22:04:50 2012 -0500
@@ -0,0 +1,109 @@
+#!/bin/ksh -p
+#
+# CDDL HEADER START
+#
+# The contents of this file are subject to the terms of the
+# Common Development and Distribution License (the "License").
+# You may not use this file except in compliance with the License.
+#
+# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
+# or http://www.opensolaris.org/os/licensing.
+# See the License for the specific language governing permissions
+# and limitations under the License.
+#
+# When distributing Covered Code, include this CDDL HEADER in each
+# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
+# If applicable, add the following below this CDDL HEADER, with the
+# fields enclosed by brackets "[]" replaced with your own identifying
+# information: Portions Copyright [yyyy] [name of copyright owner]
+#
+# CDDL HEADER END
+#
+
+#
+# Copyright 2007 Sun Microsystems, Inc.  All rights reserved.
+# Use is subject to license terms.
+#
+
+. $STF_SUITE/include/libtest.shlib
+. $STF_SUITE/tests/functional/cli_root/zfs_unmount/zfs_unmount.kshlib
+
+#
+# DESCRIPTION:
+# If invoke "zfs unmount" with a specific filesystem|mountpoint
+# that have been mounted, but it's currently in use,
+# it will fail with a return code of 1
+# and issue an error message.
+# But unmount forcefully will bypass this restriction and
+# unmount that given filesystem successfully.
+#
+# STRATEGY:
+# 1. Make sure that the ZFS filesystem is mounted.
+# 2. Change directory to that given mountpoint.
+# 3. Unmount the file system using the various combinations.
+#	- Without force option. (FAILED)
+#	- With force option. (PASS)
+# 4. Unmount the mountpoint using the various combinations.
+#	- Without force option. (FAILED)
+#	- With force option. (PASS)
+# 5. Verify the above expected results of the filesystem|mountpoint.
+#
+
+verify_runnable "both"
+
+
+set -A cmd "umount" "unmount"
+set -A options "" "-f"
+set -A dev "$TESTPOOL/$TESTFS" "$TESTDIR"
+
+function do_unmount_multiple #options #expect
+{
+	typeset opt=$1
+	typeset -i expect=${2-0}
+
+	typeset -i i=0
+	typeset -i j=0
+
+	while (( i <  ${#cmd[*]} )); do
+		j=0
+		while (( j < ${#dev[*]} )); do
+			mounted ${dev[j]} || \
+				log_must $ZFS $mountcmd ${dev[0]}
+
+			cd $TESTDIR || \
+				log_unresolved "Unable change dir to $TESTDIR"
+
+			do_unmount "${cmd[i]}" "$opt" \
+				"${dev[j]}" $expect
+
+			cleanup
+
+			((j = j + 1))
+		done
+
+		((i = i + 1))
+	done
+}
+
+log_assert "Verify that '$ZFS $unmountcmd <filesystem|mountpoint>' " \
+	"with a filesystem which mountpoint is currently in use " \
+	"will fail with return code 1, and forcefully will succeeds as root."
+
+log_onexit cleanup
+
+cwd=$PWD
+
+typeset -i i=0
+
+while (( i <  ${#options[*]} )); do
+	if [[ ${options[i]} == "-f" ]]; then
+		do_unmount_multiple "${options[i]}"
+	else
+		do_unmount_multiple "${options[i]}" 1
+	fi
+        ((i = i + 1))
+done
+
+log_pass "'$ZFS $unmountcmd <filesystem|mountpoint>' " \
+	"with a filesystem which mountpoint is currently in use " \
+	"will fail with return code 1, and forcefully will succeeds as root."
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/usr/src/test/zfs-tests/tests/functional/cli_root/zfs_unmount/zfs_unmount_006_pos.ksh	Wed Dec 05 22:04:50 2012 -0500
@@ -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.
+#
+
+. $STF_SUITE/include/libtest.shlib
+
+#
+# DESCRIPTION:
+#	Re-creating zfs files, 'zfs unmount' still succeed.
+#
+# STRATEGY:
+#	1. Create pool and filesystem.
+#	2. Recreating the same file in this fs for a while, then breaking out.
+#	3. Verify the filesystem can be unmount successfully.
+#
+
+verify_runnable "both"
+
+function cleanup
+{
+	if ! ismounted $TESTPOOL/$TESTFS ; then
+		log_must $ZFS mount $TESTPOOL/$TESTFS
+	fi
+}
+
+log_assert "Re-creating zfs files, 'zfs unmount' still succeed."
+log_onexit cleanup
+
+# Call cleanup to make sure the file system are mounted.
+cleanup
+mntpnt=$(get_prop mountpoint $TESTPOOL/$TESTFS)
+(($? != 0)) && log_fail "get_prop mountpoint $TESTPOOL/$TESTFS"
+
+typeset -i i=0
+while (( i < 10000 )); do
+	$CP $STF_SUITE/include/libtest.shlib $mntpnt
+
+	(( i += 1 ))
+done
+log_note "Recreating zfs files for 10000 times."
+
+log_must $ZFS unmount $TESTPOOL/$TESTFS
+
+log_pass "Re-creating zfs files, 'zfs unmount' passed."
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/usr/src/test/zfs-tests/tests/functional/cli_root/zfs_unmount/zfs_unmount_007_neg.ksh	Wed Dec 05 22:04:50 2012 -0500
@@ -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 2007 Sun Microsystems, Inc.  All rights reserved.
+# Use is subject to license terms.
+#
+
+. $STF_SUITE/tests/functional/cli_root/zfs_mount/zfs_mount.kshlib
+. $STF_SUITE/tests/functional/cli_root/zfs_unmount/zfs_unmount.kshlib
+
+#
+# DESCRIPTION:
+#	Try each 'zfs unmount' with inapplicable scenarios to make sure
+#	it returns an error. include:
+#		* Multiple filesystem|mountpoint specified
+#		* '-a', but also with a specific filesystem|mountpoint.
+#
+# 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 "both"
+
+multifs="$TESTFS $TESTFS1"
+datasets=""
+
+for fs in $multifs ; do
+	datasets="$datasets $TESTPOOL/$fs"
+done
+
+set -A args "$unmountall $TESTPOOL/$TESTFS" \
+	"$unmountcmd $datasets"
+
+function setup_all
+{
+	typeset fs
+
+	for fs in $multifs ; do
+		setup_filesystem "$DISKS" "$TESTPOOL" \
+			"$fs" \
+			"${TEST_BASE_DIR%%/}/testroot$$/$TESTPOOL/$fs"
+	done
+	return 0
+}
+
+function cleanup_all
+{
+	typeset fs
+
+	cleanup_filesystem "$TESTPOOL" "$TESTFS1"
+	log_must $ZFS set mountpoint=$TESTDIR $TESTPOOL/$TESTFS
+
+	[[ -d ${TEST_BASE_DIR%%/}/testroot$$ ]] && \
+		$RM -rf ${TEST_BASE_DIR%%/}/testroot$$
+
+	return 0
+}
+
+function verify_all
+{
+	typeset fs
+
+	for fs in $multifs ; do
+		log_must mounted $TESTPOOL/$fs
+	done
+	return 0
+}
+
+log_assert "Badly-formed 'zfs $unmountcmd' with inapplicable scenarios " \
+	"should return an error."
+log_onexit cleanup_all
+
+log_must setup_all
+
+typeset -i i=0
+while (( i < ${#args[*]} )); do
+	log_mustnot $ZFS ${args[i]}
+	((i = i + 1))
+done
+
+log_must verify_all
+
+log_pass "Badly formed 'zfs $unmountcmd' with inapplicable scenarios " \
+	"fail as expected."
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/usr/src/test/zfs-tests/tests/functional/cli_root/zfs_unmount/zfs_unmount_008_neg.ksh	Wed Dec 05 22:04:50 2012 -0500
@@ -0,0 +1,139 @@
+#!/bin/ksh -p
+#
+# CDDL HEADER START
+#
+# The contents of this file are subject to the terms of the
+# Common Development and Distribution License (the "License").
+# You may not use this file except in compliance with the License.
+#
+# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
+# or http://www.opensolaris.org/os/licensing.
+# See the License for the specific language governing permissions
+# and limitations under the License.
+#
+# When distributing Covered Code, include this CDDL HEADER in each
+# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
+# If applicable, add the following below this CDDL HEADER, with the
+# fields enclosed by brackets "[]" replaced with your own identifying
+# information: Portions Copyright [yyyy] [name of copyright owner]
+#
+# CDDL HEADER END
+#
+
+#
+# Copyright 2007 Sun Microsystems, Inc.  All rights reserved.
+# Use is subject to license terms.
+#
+
+. $STF_SUITE/include/libtest.shlib
+
+#
+# DESCRIPTION:
+# Verify that zfs unmount should fail with bad parameters or scenarios:
+#	1. bad option;
+#	2. too many arguments;
+#	3. null arguments;
+#	4. invalid datasets;
+#	5. invalid mountpoint;
+#	6. already unmounted zfs filesystem;
+#	7. legacy mounted zfs filesystem
+#
+# STRATEGY:
+# 1. Make an array of bad parameters
+# 2. Use zfs unmount to unmount the filesystem
+# 3. Verify that zfs unmount returns error
+#
+
+verify_runnable "both"
+
+function cleanup
+{
+	for ds in $vol $fs1; do
+		if datasetexists $ds; then
+			log_must $ZFS destroy -f $ds
+		fi
+	done
+
+	if snapexists $snap; then
+		log_must $ZFS destroy $snap
+	fi
+
+	if [[ -e /tmp/$file ]]; then
+		$RM -f /tmp/$file
+	fi
+	if [[ -d /tmp/$dir ]]; then
+		$RM -rf /tmp/$dir
+	fi
+
+}
+
+log_assert "zfs unmount fails with bad parameters or scenarios"
+log_onexit cleanup
+
+fs=$TESTPOOL/$TESTFS
+vol=$TESTPOOL/vol.$$
+snap=$TESTPOOL/$TESTFS@snap.$$
+set -A badargs "A" "-A" "F" "-F" "-" "-x" "-?"
+
+if ! ismounted $fs; then
+	log_must $ZFS mount $fs
+fi
+
+log_must $ZFS snapshot $snap
+if is_global_zone; then
+	log_must $ZFS create -V 10m $vol
+else
+	vol=""
+fi
+
+# Testing bad options
+for arg in ${badargs[@]}; do
+	log_mustnot eval "$ZFS unmount $arg $fs >/dev/null 2>&1"
+done
+
+
+#Testing invalid datasets
+for ds in $snap $vol "blah"; do
+	for opt in "" "-f"; do
+		log_mustnot eval "$ZFS unmount $opt $ds >/dev/null 2>&1"
+	done
+done
+
+#Testing invalid mountpoint
+dir=foodir.$$
+file=foo.$$
+fs1=$TESTPOOL/fs.$$
+$MKDIR /tmp/$dir
+$TOUCH /tmp/$file
+log_must $ZFS create -o mountpoint=/tmp/$dir $fs1
+curpath=`$DIRNAME $0`
+cd /tmp
+for mpt in "./$dir" "./$file" "/tmp"; do
+	for opt in "" "-f"; do
+		log_mustnot eval "$ZFS unmount $opt $mpt >/dev/null 2>&1"
+	done
+done
+cd $curpath
+
+#Testing null argument and too many arguments
+for opt in "" "-f"; do
+	log_mustnot eval "$ZFS unmount $opt >/dev/null 2>&1"
+	log_mustnot eval "$ZFS unmount $opt $fs $fs1 >/dev/null 2>&1"
+done
+
+#Testing already unmounted filesystem
+log_must $ZFS unmount $fs1
+for opt in "" "-f"; do
+	log_mustnot eval "$ZFS unmount $opt $fs1 >/dev/null 2>&1"
+	log_mustnot eval "$ZFS unmount /tmp/$dir >/dev/null 2>&1"
+done
+
+#Testing legacy mounted filesystem
+log_must $ZFS set mountpoint=legacy $fs1
+log_must $MOUNT -F zfs $fs1 /tmp/$dir
+for opt in "" "-f"; do
+	log_mustnot eval "$ZFS unmount $opt $fs1 >/dev/null 2>&1"
+done
+$UMOUNT /tmp/$dir
+
+log_pass "zfs unmount fails with bad parameters or scenarios as expected."
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/usr/src/test/zfs-tests/tests/functional/cli_root/zfs_unmount/zfs_unmount_009_pos.ksh	Wed Dec 05 22:04:50 2012 -0500
@@ -0,0 +1,123 @@
+#!/bin/ksh -p
+#
+# CDDL HEADER START
+#
+# The contents of this file are subject to the terms of the
+# Common Development and Distribution License (the "License").
+# You may not use this file except in compliance with the License.
+#
+# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
+# or http://www.opensolaris.org/os/licensing.
+# See the License for the specific language governing permissions
+# and limitations under the License.
+#
+# When distributing Covered Code, include this CDDL HEADER in each
+# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
+# If applicable, add the following below this CDDL 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.
+#
+
+. $STF_SUITE/include/libtest.shlib
+
+#
+# DESCRIPTION:
+# Verify that zfs unmount and destroy in a snapshot directory will not cause error.
+#
+# STRATEGY:
+# 1. Create a file in a zfs filesystem, snapshot it and change directory to snapshot directory
+# 2. Verify that 'zfs unmount -a'  will fail and 'zfs unmount -fa' will succeed
+# 3. Verify 'ls' and 'cd /' will succeed
+# 4. 'zfs mount -a' and change directory to snapshot directory again
+# 5. Verify that zfs destroy snapshot will succeed
+# 6. Verify 'ls' and 'cd /' will succeed
+# 7. Create zfs filesystem, create a file, snapshot it and change to snapshot directory
+# 8. Verify that zpool destroy the pool will succeed
+# 9. Verify 'ls' 'cd /' 'zpool list' and etc will succeed
+#
+
+verify_runnable "both"
+
+function cleanup
+{
+	DISK=${DISKS%% *}
+
+	for fs in $TESTPOOL/$TESTFS $TESTPOOL ; do
+		typeset snap=$fs@$TESTSNAP
+		if snapexists $snap; then
+			log_must $ZFS destroy $snap
+		fi
+	done
+
+	if ! poolexists $TESTPOOL && is_global_zone; then
+		log_must $ZPOOL create $TESTPOOL $DISK
+	fi
+
+	if ! datasetexists $TESTPOOL/$TESTFS; then
+		log_must $ZFS create $TESTPOOL/$TESTFS
+		log_must $ZFS set mountpoint=$TESTDIR $TESTPOOL/$TESTFS
+	fi
+}
+
+function restore_dataset
+{
+	if ! datasetexists $TESTPOOL/$TESTFS ; then
+		log_must $ZFS create $TESTPOOL/$TESTFS
+		log_must $ZFS set mountpoint=$TESTDIR $TESTPOOL/$TESTFS
+		log_must cd $TESTDIR
+		$ECHO hello > world
+		log_must $ZFS snapshot $TESTPOOL/$TESTFS@$TESTSNAP
+		log_must cd .zfs/snapshot/$TESTSNAP
+	fi
+}
+
+
+log_assert "zfs fource unmount and destroy in snapshot directory will not cause error."
+log_onexit cleanup
+
+for fs in $TESTPOOL/$TESTFS $TESTPOOL ; do
+	typeset snap=$fs@$TESTSNAP
+	typeset mtpt=$(get_prop mountpoint $fs)
+
+	log_must cd $mtpt
+	$ECHO hello > world
+	log_must $ZFS snapshot $snap
+	log_must cd .zfs/snapshot/$TESTSNAP
+
+	log_mustnot $ZFS unmount -a
+	log_must $ZFS unmount -fa
+	log_mustnot $LS
+	log_must cd /
+
+	log_must $ZFS mount -a
+	log_must cd $mtpt
+	log_must cd .zfs/snapshot/$TESTSNAP
+
+	if is_global_zone || [[ $fs != $TESTPOOL ]] ; then
+		log_must $ZFS destroy -rf $fs
+		log_mustnot $LS
+		log_must cd /
+	fi
+
+	restore_dataset
+done
+
+if is_global_zone ; then
+	log_must $ZPOOL destroy -f $TESTPOOL
+	log_mustnot $LS
+	log_must cd /
+fi
+
+log_must eval $ZFS list > /dev/null 2>&1
+log_must eval $ZPOOL list > /dev/null 2>&1
+log_must eval $ZPOOL status > /dev/null 2>&1
+$ZPOOL iostat > /dev/null 2>&1
+
+log_pass "zfs fource unmount and destroy in snapshot directory will not cause error."
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/usr/src/test/zfs-tests/tests/functional/cli_root/zfs_unmount/zfs_unmount_all_001_pos.ksh	Wed Dec 05 22:04:50 2012 -0500
@@ -0,0 +1,195 @@
+#!/bin/ksh -p
+#
+# CDDL HEADER START
+#
+# The contents of this file are subject to the terms of the
+# Common Development and Distribution License (the "License").
+# You may not use this file except in compliance with the License.
+#
+# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
+# or http://www.opensolaris.org/os/licensing.
+# See the License for the specific language governing permissions
+# and limitations under the License.
+#
+# When distributing Covered Code, include this CDDL HEADER in each
+# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
+# If applicable, add the following below this CDDL HEADER, with the
+# fields enclosed by brackets "[]" replaced with your own identifying
+# information: Portions Copyright [yyyy] [name of copyright owner]
+#
+# CDDL HEADER END
+#
+
+#
+# Copyright 2007 Sun Microsystems, Inc.  All rights reserved.
+# Use is subject to license terms.
+#
+
+. $STF_SUITE/tests/functional/cli_root/zfs_mount/zfs_mount.kshlib
+. $STF_SUITE/tests/functional/cli_root/zfs_unmount/zfs_unmount.kshlib
+
+#
+# DESCRIPTION:
+#       Verify that 'zfs unmount -a[f]' succeeds as root.
+#
+# STRATEGY:
+#       1. Create a group of pools with specified vdev.
+#       2. Create zfs filesystems within the given pools.
+#       3. Mount all the filesystems.
+#       4. Verify that 'zfs unmount -a[f]' command succeed,
+#	   and all available ZFS filesystems are unmounted.
+#	5. Verify that 'zfs mount' is identical with 'df -F zfs'
+#
+
+verify_runnable "both"
+
+set -A fs "$TESTFS" "$TESTFS1"
+set -A ctr "" "$TESTCTR" "$TESTCTR1" "$TESTCTR/$TESTCTR1"
+set -A vol "$TESTVOL" "$TESTVOL1"
+
+function setup_all
+{
+	typeset -i i=0
+	typeset -i j=0
+	typeset path
+
+	while (( i < ${#ctr[*]} )); do
+
+		path=${TEST_BASE_DIR%%/}/testroot$$/$TESTPOOL
+		if [[ -n ${ctr[i]} ]]; then
+			path=$path/${ctr[i]}
+
+			setup_filesystem "$DISKS" "$TESTPOOL" \
+				"${ctr[i]}" "$path" \
+				"ctr"
+		fi
+
+		if is_global_zone ; then
+			j=0
+			while (( j < ${#vol[*]} )); do
+				setup_filesystem "$DISKS" "$TESTPOOL" \
+				"${ctr[i]}/${vol[j]}" \
+					"$path/${vol[j]}" \
+					"vol"
+				((j = j + 1))
+			done
+		fi
+		j=0
+		while (( j < ${#fs[*]} )); do
+			setup_filesystem "$DISKS" "$TESTPOOL" \
+				"${ctr[i]}/${fs[j]}" \
+				"$path/${fs[j]}"
+			((j = j + 1))
+		done
+
+		((i = i + 1))
+	done
+
+	return 0
+}
+
+function cleanup_all
+{
+	typeset -i i=0
+	typeset -i j=0
+
+	((i = ${#ctr[*]} - 1))
+
+	while (( i >= 0 )); do
+		if is_global_zone ; then
+			j=0
+			while (( j < ${#vol[*]} )); do
+				cleanup_filesystem "$TESTPOOL" \
+					"${ctr[i]}/${vol[j]}"
+				((j = j + 1))
+			done
+		fi
+
+		j=0
+		while (( j < ${#fs[*]} )); do
+			cleanup_filesystem "$TESTPOOL" \
+				"${ctr[i]}/${fs[j]}"
+			((j = j + 1))
+		done
+
+		[[ -n ${ctr[i]} ]] && \
+			cleanup_filesystem "$TESTPOOL" "${ctr[i]}"
+
+		((i = i - 1))
+	done
+
+	[[ -d ${TEST_BASE_DIR%%/}/testroot$$ ]] && \
+		$RM -rf ${TEST_BASE_DIR%%/}/testroot$$
+}
+
+function verify_all
+{
+	typeset -i i=0
+	typeset -i j=0
+	typeset path
+
+	while (( i < ${#ctr[*]} )); do
+
+		path=$TESTPOOL
+		[[ -n ${ctr[i]} ]] && \
+			path=$path/${ctr[i]}
+
+		if is_global_zone ; then
+			j=0
+			while (( j < ${#vol[*]} )); do
+				log_must unmounted "$path/${vol[j]}"
+				((j = j + 1))
+			done
+		fi
+
+		j=0
+		while (( j < ${#fs[*]} )); do
+			log_must unmounted "$path/${fs[j]}"
+			((j = j + 1))
+		done
+
+		log_must unmounted "$path"
+
+		((i = i + 1))
+	done
+
+	return 0
+}
+
+
+log_assert "Verify that 'zfs $unmountall' succeeds as root, " \
+	"and all available ZFS filesystems are unmounted."
+
+log_onexit cleanup_all
+
+log_must setup_all
+
+typeset opt
+for opt in "-a" "-fa"; do
+	export __ZFS_POOL_RESTRICT="$TESTPOOL"
+	log_must $ZFS $mountall
+	unset __ZFS_POOL_RESTRICT
+
+	if [[ $opt == "-fa" ]]; then
+		mntpnt=$(get_prop mountpoint ${TESTPOOL}/${TESTCTR}/${TESTFS})
+		cd $mntpnt
+		log_mustnot $ZFS unmount -a
+	fi
+
+	export __ZFS_POOL_RESTRICT="$TESTPOOL"
+	log_must $ZFS unmount $opt
+	unset __ZFS_POOL_RESTRICT
+
+	if [[ $opt == "-fa" ]]; then
+		cd  /tmp
+	fi
+
+	log_must verify_all
+	log_note "Verify that 'zfs $mountcmd' will display " \
+	"all ZFS filesystems currently mounted."
+	log_must verify_mount_display
+
+done
+
+log_pass "'zfs mount -[f]a' succeeds as root, " \
+	"and all available ZFS filesystems are unmounted."
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/usr/src/test/zfs-tests/tests/functional/cli_root/zfs_unshare/Makefile	Wed Dec 05 22:04:50 2012 -0500
@@ -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) 2012 by Delphix. All rights reserved.
+#
+
+include $(SRC)/Makefile.master
+
+ROOTOPTPKG = $(ROOT)/opt/zfs-tests
+TESTDIR = $(ROOTOPTPKG)/tests/functional/cli_root/zfs_unshare
+
+PROGS = cleanup \
+	setup \
+	zfs_unshare_001_pos \
+	zfs_unshare_002_pos \
+	zfs_unshare_003_pos \
+	zfs_unshare_004_neg \
+	zfs_unshare_005_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	Thu Jan 01 00:00:00 1970 +0000
+++ b/usr/src/test/zfs-tests/tests/functional/cli_root/zfs_unshare/cleanup.ksh	Wed Dec 05 22:04:50 2012 -0500
@@ -0,0 +1,30 @@
+#!/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.
+#
+
+. $STF_SUITE/include/libtest.shlib
+
+default_cleanup
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/usr/src/test/zfs-tests/tests/functional/cli_root/zfs_unshare/setup.ksh	Wed Dec 05 22:04:50 2012 -0500
@@ -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.
+#
+
+. $STF_SUITE/include/libtest.shlib
+
+# Make sure NFS server is running before testing.
+setup_nfs_server
+
+DISK=${DISKS%% *}
+default_container_volume_setup $DISK
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/usr/src/test/zfs-tests/tests/functional/cli_root/zfs_unshare/zfs_unshare_001_pos.ksh	Wed Dec 05 22:04:50 2012 -0500
@@ -0,0 +1,173 @@
+#!/bin/ksh -p
+#
+# CDDL HEADER START
+#
+# The contents of this file are subject to the terms of the
+# Common Development and Distribution License (the "License").
+# You may not use this file except in compliance with the License.
+#
+# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
+# or http://www.opensolaris.org/os/licensing.
+# See the License for the specific language governing permissions
+# and limitations under the License.
+#
+# When distributing Covered Code, include this CDDL HEADER in each
+# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
+# If applicable, add the following below this CDDL HEADER, with the
+# fields enclosed by brackets "[]" replaced with your own identifying
+# information: Portions Copyright [yyyy] [name of copyright owner]
+#
+# CDDL HEADER END
+#
+
+#
+# Copyright 2007 Sun Microsystems, Inc.  All rights reserved.
+# Use is subject to license terms.
+#
+
+. $STF_SUITE/include/libtest.shlib
+
+#
+# DESCRIPTION:
+# Verify that 'zfs unshare <filesystem|mountpoint>' unshares a given shared
+# filesystem.
+#
+# STRATEGY:
+# 1. Share filesystems
+# 2. Invoke 'zfs unshare <filesystem|mountpoint>' to unshare zfs file system
+# 3. Verify that the file system is unshared
+# 4. Verify that unsharing an unshared file system fails
+# 5. Verify that "zfs unshare -a" succeeds to unshare all zfs file systems.
+#
+
+verify_runnable "global"
+
+function cleanup
+{
+	typeset -i i=0
+	while (( i < ${#mntp_fs[*]} )); do
+		log_must $ZFS set sharenfs=off ${mntp_fs[((i+1))]}
+
+		((i = i + 2))
+	done
+
+	if mounted $TESTPOOL/$TESTCLONE; then
+		log_must $ZFS unmount $TESTDIR2
+	fi
+
+	[[ -d $TESTDIR2 ]] && \
+		log_must $RM -rf $TESTDIR2
+
+	if datasetexists "$TESTPOOL/$TESTCLONE"; then
+		log_must $ZFS destroy -f $TESTPOOL/$TESTCLONE
+	fi
+
+	if snapexists "$TESTPOOL/$TESTFS2@snapshot"; then
+		log_must $ZFS destroy -f $TESTPOOL/$TESTFS2@snapshot
+	fi
+
+	if datasetexists "$TESTPOOL/$TESTFS2"; then
+		log_must $ZFS destroy -f $TESTPOOL/$TESTFS2
+	fi
+}
+
+#
+# Main test routine.
+#
+# Given a mountpoint and file system this routine will attempt
+# unshare the filesystem via <filesystem|mountpoint> argument
+# and then verify it has been unshared.
+#
+function test_unshare # <mntp> <filesystem>
+{
+        typeset mntp=$1
+        typeset filesystem=$2
+	typeset prop_value
+
+	prop_value=$(get_prop "sharenfs" $filesystem)
+
+	if [[ $prop_value == "off" ]]; then
+		not_shared $mntp ||
+			log_must $UNSHARE -F nfs $mntp
+		log_must $ZFS set sharenfs=on $filesystem
+		is_shared $mntp || \
+			log_fail "'$ZFS set sharenfs=on' fails to make" \
+				"file system $filesystem shared."
+	fi
+
+	is_shared $mntp || log_must $ZFS share $filesystem
+
+        #
+	# Verify 'zfs unshare <filesystem>' works as well.
+	#
+	log_must $ZFS unshare $filesystem
+	not_shared $mntp || log_fail "'zfs unshare <filesystem>' fails"
+
+	log_must $ZFS share $filesystem
+
+	log_must $ZFS unshare $mntp
+	not_shared $mntp || log_fail "'zfs unshare <mountpoint>' fails"
+
+        log_note "Unsharing an unshared file system fails."
+        log_mustnot $ZFS unshare $filesystem
+	log_mustnot $ZFS unshare $mntp
+}
+
+set -A mntp_fs \
+    "$TESTDIR" "$TESTPOOL/$TESTFS" \
+    "$TESTDIR1" "$TESTPOOL/$TESTCTR/$TESTFS1" \
+    "$TESTDIR2" "$TESTPOOL/$TESTCLONE"
+
+log_assert "Verify that 'zfs unshare [-a] <filesystem|mountpoint>' succeeds as root."
+log_onexit cleanup
+
+log_must $ZFS create $TESTPOOL/$TESTFS2
+log_must $ZFS snapshot $TESTPOOL/$TESTFS2@snapshot
+log_must $ZFS clone $TESTPOOL/$TESTFS2@snapshot $TESTPOOL/$TESTCLONE
+log_must $ZFS set mountpoint=$TESTDIR2 $TESTPOOL/$TESTCLONE
+
+#
+# Invoke 'test_unshare' routine to test 'zfs unshare <filesystem|mountpoint>'.
+#
+typeset -i i=0
+while (( i < ${#mntp_fs[*]} )); do
+	test_unshare ${mntp_fs[i]} ${mntp_fs[((i + 1 ))]}
+
+	((i = i + 2))
+done
+
+log_note "Verify '$ZFS unshare -a' succeds as root."
+
+i=0
+typeset sharenfs_val
+while (( i < ${#mntp_fs[*]} )); do
+	sharenfs_val=$(get_prop "sharenfs" ${mntp_fs[((i+1))]})
+	if [[ $sharenfs_val == "on" ]]; then
+		not_shared ${mntp_fs[i]} && \
+			log_must $ZFS share ${mntp_fs[((i+1))]}
+	else
+		log_must $ZFS set sharenfs=on ${mntp_fs[((i+1))]}
+		is_shared ${mntp_fs[i]} || \
+			log_fail "'$ZFS set sharenfs=on' fails to share filesystem."
+	fi
+
+        ((i = i + 2))
+done
+
+#
+# test 'zfs unshare -a '
+#
+log_must $ZFS unshare -a
+
+#
+# verify all shared filesystems become unshared
+#
+i=0
+while (( i < ${#mntp_fs[*]} )); do
+        not_shared ${mntp_fs[i]} || \
+                log_fail "'$ZFS unshare -a' fails to unshare all shared zfs filesystems."
+
+        ((i = i + 2))
+done
+
+log_pass "'$ZFS unshare [-a] <filesystem|mountpoint>' succeeds as root."
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/usr/src/test/zfs-tests/tests/functional/cli_root/zfs_unshare/zfs_unshare_002_pos.ksh	Wed Dec 05 22:04:50 2012 -0500
@@ -0,0 +1,177 @@
+#!/bin/ksh -p
+#
+# CDDL HEADER START
+#
+# The contents of this file are subject to the terms of the
+# Common Development and Distribution License (the "License").
+# You may not use this file except in compliance with the License.
+#
+# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
+# or http://www.opensolaris.org/os/licensing.
+# See the License for the specific language governing permissions
+# and limitations under the License.
+#
+# When distributing Covered Code, include this CDDL HEADER in each
+# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
+# If applicable, add the following below this CDDL HEADER, with the
+# fields enclosed by brackets "[]" replaced with your own identifying
+# information: Portions Copyright [yyyy] [name of copyright owner]
+#
+# CDDL HEADER END
+#
+
+#
+# Copyright 2007 Sun Microsystems, Inc.  All rights reserved.
+# Use is subject to license terms.
+#
+
+. $STF_SUITE/include/libtest.shlib
+
+#
+# DESCRIPTION:
+# Verify that 'zfs unshare [-a] <filesystem|mountpoint>' is aware of legacy share.
+#
+# STRATEGY:
+# 1. Set 'zfs set sharenfs=off'
+# 2. Use 'share' to share given filesystem
+# 3. Verify that 'zfs unshare <filesystem|mountpoint>' is aware of legacy share
+# 4. Verify that 'zfs unshare -a' is aware of legacy share.
+#
+
+verify_runnable "global"
+
+function cleanup
+{
+	typeset -i i=0
+	while (( i < ${#mntp_fs[*]} )); do
+		is_shared ${mntp_fs[i]} && \
+			log_must $UNSHARE -F nfs ${mntp_fs[i]}
+
+		((i = i + 2))
+	done
+
+	if mounted $TESTPOOL/$TESTCLONE; then
+		log_must $ZFS unmount $TESTDIR2
+	fi
+
+	[[ -d $TESTDIR2 ]] && \
+		log_must $RM -rf $TESTDIR2
+
+	if datasetexists "$TESTPOOL/$TESTCLONE"; then
+		log_must $ZFS destroy -f $TESTPOOL/$TESTCLONE
+	fi
+
+	if snapexists "$TESTPOOL/$TESTFS2@snapshot"; then
+		log_must $ZFS destroy -f $TESTPOOL/$TESTFS2@snapshot
+	fi
+
+	if datasetexists "$TESTPOOL/$TESTFS2"; then
+		log_must $ZFS destroy -f $TESTPOOL/$TESTFS2
+	fi
+}
+
+#
+# Main test routine.
+#
+# Given a mountpoint and file system this routine will attempt
+# to verify 'zfs unshare' is aware of legacy share.
+#
+function test_legacy_unshare # <mntp> <filesystem>
+{
+        typeset mntp=$1
+        typeset filesystem=$2
+
+	log_must $ZFS set sharenfs=off $filesystem
+	not_shared $mntp || \
+	    log_fail "'zfs set sharenfs=off' fails to make ZFS " \
+	    "filesystem $filesystem unshared."
+
+	log_must $SHARE -F nfs $mntp
+	is_shared $mntp || \
+	    log_fail "'share' command fails to share ZFS file system."
+	#
+	# Verify 'zfs unshare <filesystem>' is aware of legacy share.
+	#
+	log_mustnot $ZFS unshare $filesystem
+	is_shared $mntp || \
+	    log_fail "'zfs unshare <filesystem>' fails to be aware" \
+	    "of legacy share."
+
+	#
+	# Verify 'zfs unshare <filesystem>' is aware of legacy share.
+	#
+	log_mustnot $ZFS unshare $mntp
+	is_shared $mntp || \
+	    log_fail "'zfs unshare <mountpoint>' fails to be aware" \
+	    "of legacy share."
+}
+
+
+set -A mntp_fs \
+    "$TESTDIR" "$TESTPOOL/$TESTFS" \
+    "$TESTDIR1" "$TESTPOOL/$TESTCTR/$TESTFS1" \
+    "$TESTDIR2" "$TESTPOOL/$TESTCLONE"
+
+log_assert "Verify that 'zfs unshare [-a]' is aware of legacy share."
+log_onexit cleanup
+
+log_must $ZFS create $TESTPOOL/$TESTFS2
+log_must $ZFS snapshot $TESTPOOL/$TESTFS2@snapshot
+log_must $ZFS clone $TESTPOOL/$TESTFS2@snapshot $TESTPOOL/$TESTCLONE
+log_must $ZFS set mountpoint=$TESTDIR2 $TESTPOOL/$TESTCLONE
+
+#
+# Invoke 'test_legacy_unshare' routine to verify.
+#
+typeset -i i=0
+while (( i < ${#mntp_fs[*]} )); do
+	test_legacy_unshare ${mntp_fs[i]} ${mntp_fs[((i + 1 ))]}
+
+	((i = i + 2))
+done
+
+
+log_note "Verify '$ZFS unshare -a' is aware of legacy share."
+
+#
+# set the 'sharenfs' property to 'off' for each filesystem
+#
+i=0
+while (( i < ${#mntp_fs[*]} )); do
+        log_must $ZFS set sharenfs=off ${mntp_fs[((i + 1))]}
+        not_shared ${mntp_fs[i]} || \
+                log_fail "'$ZFS set sharenfs=off' unshares file system failed."
+
+        ((i = i + 2))
+done
+
+#
+# Share each of the file systems via legacy share.
+#
+i=0
+while (( i < ${#mntp_fs[*]} )); do
+        $SHARE -F nfs ${mntp_fs[i]}
+        is_shared ${mntp_fs[i]} || \
+                log_fail "'$SHARE' shares ZFS filesystem failed."
+
+        ((i = i + 2))
+done
+
+#
+# Verify that 'zfs unshare -a' is aware of legacy share
+#
+log_must $ZFS unshare -a
+
+#
+# verify ZFS filesystems are still shared
+#
+i=0
+while (( i < ${#mntp_fs[*]} )); do
+        is_shared ${mntp_fs[i]} || \
+            log_fail "'$ZFS  unshare -a' fails to be aware of legacy share."
+
+        ((i = i + 2))
+done
+
+log_pass "'$ZFS unshare [-a]' succeeds to be aware of legacy share."
+
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/usr/src/test/zfs-tests/tests/functional/cli_root/zfs_unshare/zfs_unshare_003_pos.ksh	Wed Dec 05 22:04:50 2012 -0500
@@ -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.
+#
+
+. $STF_SUITE/include/libtest.shlib
+
+#
+# DESCRIPTION:
+# Verify that a file system and its dependant are unshared when turn off sharenfs
+# property.
+#
+# STRATEGY:
+# 1. Create a file system
+# 2. Set the sharenfs property on the file system
+# 3. Create a snapshot
+# 4. Verify that both are shared
+# 5. Turn off the sharenfs property
+# 6. Verify that both are unshared.
+#
+
+verify_runnable "global"
+
+function cleanup
+{
+	if snapexists $TESTPOOL/$TESTFS@snapshot; then
+		log_must $ZFS destroy $TESTPOOL/$TESTFS@snapshot
+	fi
+
+	log_must $ZFS set sharenfs=off $TESTPOOL/$TESTFS
+}
+
+#
+# Main test routine.
+#
+# Given a mountpoint and file system this routine will attempt
+# unshare the mountpoint and then verify a snapshot of the mounpoint
+# is also unshared.
+#
+function test_snap_unshare # <mntp> <filesystem>
+{
+        typeset mntp=$1
+        typeset filesystem=$2
+	typeset prop_value
+
+	prop_value=$(get_prop "sharenfs" $filesystem)
+
+	if [[ $prop_value == "off" ]]; then
+		is_shared $mntp || $UNSHARE -F nfs $mntp
+		log_must $ZFS set sharenfs=on $filesystem
+	fi
+
+	log_must $ZFS set sharenfs=off $filesystem
+
+	not_shared $mntp || \
+		log_fail "File system $filesystem is shared (set sharenfs)."
+
+	not_shared $mntp@snapshot || \
+	    log_fail "Snapshot $mntpt@snapshot is shared (set sharenfs)."
+}
+
+log_assert "Verify that a file system and its dependant are unshared."
+log_onexit cleanup
+
+log_must $ZFS snapshot $TESTPOOL/$TESTFS@snapshot
+test_snap_unshare $TESTDIR $TESTPOOL/$TESTFS
+
+log_pass "A file system and its dependant are both unshared as expected."
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/usr/src/test/zfs-tests/tests/functional/cli_root/zfs_unshare/zfs_unshare_004_neg.ksh	Wed Dec 05 22:04:50 2012 -0500
@@ -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) 2012 by Delphix. All rights reserved.
+#
+
+. $STF_SUITE/include/libtest.shlib
+
+#
+# DESCRIPTION:
+# Verify that "zfs unshare" issue error message with badly formed parameter.
+#
+# STRATEGY:
+# 1. Define badly formed parameters
+# 2. Invoke 'zfs unshare'
+# 3. Verify that unshare fails and issue error message.
+#
+
+verify_runnable "global"
+
+export NONEXISTFSNAME="nonexistfs50charslong_0123456789012345678901234567"
+export NONEXISTMOUNTPOINT="/nonexistmountpoint_0123456789"
+
+set -A opts "" "$TESTPOOL/$NONEXISTFSNAME" "$NONEEXISTMOUNTPOINT" "-?" "-1" \
+		"-a blah" "$TESTPOOL/$TESTFS $TESTPOOL/$TESTFS1" \
+		"-f $TESTPOOL/$TESTFS $TESTPOOL/$TESTFS1" \
+		"$TESTPOOL/$TESTFS $TESTDIR" "-f $TESTPOOL/$TESTFS $TESTDIR" \
+		"${TESTDIR#/}" "-f ${TESTDIR#/}"
+
+log_assert "Verify that '$ZFS unshare' issue error message with badly formed parameter."
+
+shareval=$(get_prop sharenfs $TESTPOOL/$TESTFS)
+if [[ $shareval == off ]]; then
+	log_must $ZFS set sharenfs=on $TESTPOOL/$TESTFS
+fi
+
+typeset -i i=0
+while [[ $i -lt ${#args[*]} ]]; do
+        log_mustnot $ZFS unshare ${args[i]}
+
+        ((i = i + 1))
+done
+
+#Testing that unsharing unshared filesystem fails.
+mpt=$(get_prop mountpoint $TESTPOOL/$TESTFS)
+log_must $ZFS unshare $TESTPOOL/$TESTFS
+for opt in "" "-f"; do
+	log_mustnot eval "$ZFS unshare $opt $TESTPOOL/$TESTFS >/dev/null 2>&1"
+	log_mustnot eval "$ZFS unshare $opt $mpt >/dev/null 2>&1"
+done
+
+#Testing zfs unshare fails with legacy share set
+log_must $ZFS set sharenfs=off $TESTPOOL/$TESTFS
+for opt in "" "-f"; do
+	log_mustnot eval "$ZFS unshare $opt $TESTPOOL/$TESTFS >/dev/null 2>&1"
+	log_mustnot eval "$ZFS unshare $opt $mpt >/dev/null 2>&1"
+done
+
+log_pass "'$ZFS unshare' fails as expected with badly-formed parameters."
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/usr/src/test/zfs-tests/tests/functional/cli_root/zfs_unshare/zfs_unshare_005_neg.ksh	Wed Dec 05 22:04:50 2012 -0500
@@ -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.
+#
+
+. $STF_SUITE/include/libtest.shlib
+
+#
+# DESCRIPTION:
+# Verify that unsharing a dataset and mountpoint other than filesystem fails.
+#
+# STRATEGY:
+# 1. Create a volume, dataset other than a ZFS file system
+# 2. Verify that the datasets other than file system are not support by 'zfs unshare'.
+#
+
+verify_runnable "both"
+
+set -A datasets \
+	"$TESTPOOL" "$ZFSROOT/$TESTPOOL" \
+	"$TESTPOOL/$TESTCTR" "$ZFSROOT/$TESTPOOL/$TESTCTR" \
+	"$TESTPOOL/$TESTVOL" "/dev/zvol/dsk/$TESTPOOL/$TESTVOL"
+
+log_assert "Verify that unsharing a dataset other than filesystem fails."
+
+typeset -i i=0
+while (( i < ${#datasets[*]} ))
+do
+	log_mustnot $ZFS unshare ${datasets[i]}
+
+	((i = i + 1))
+done
+
+log_pass "Unsharing datasets other than filesystem failed as expected."
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/usr/src/test/zfs-tests/tests/functional/cli_root/zfs_upgrade/Makefile	Wed Dec 05 22:04:50 2012 -0500
@@ -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) 2012 by Delphix. All rights reserved.
+#
+
+include $(SRC)/Makefile.master
+
+ROOTOPTPKG = $(ROOT)/opt/zfs-tests
+TESTDIR = $(ROOTOPTPKG)/tests/functional/cli_root/zfs_upgrade
+
+PROGS = cleanup \
+	setup \
+	zfs_upgrade_001_pos \
+	zfs_upgrade_002_pos \
+	zfs_upgrade_003_pos \
+	zfs_upgrade_004_pos \
+	zfs_upgrade_005_pos \
+	zfs_upgrade_006_neg \
+	zfs_upgrade_007_neg
+
+FILES = zfs_upgrade.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	Thu Jan 01 00:00:00 1970 +0000
+++ b/usr/src/test/zfs-tests/tests/functional/cli_root/zfs_upgrade/cleanup.ksh	Wed Dec 05 22:04:50 2012 -0500
@@ -0,0 +1,33 @@
+#!/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.
+#
+#
+
+. $STF_SUITE/include/libtest.shlib
+
+verify_runnable "both"
+
+default_cleanup
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/usr/src/test/zfs-tests/tests/functional/cli_root/zfs_upgrade/setup.ksh	Wed Dec 05 22:04:50 2012 -0500
@@ -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.
+#
+#
+
+. $STF_SUITE/include/libtest.shlib
+
+verify_runnable "both"
+
+# This should have been set by the .cfg script - verify it's set to something
+# (we check that something later on)
+if [ -z "$ZFS_VERSION" ]
+then
+   log_unresolved "Unable to determine ZFS Filesystem version of this machine"
+else
+   log_note "This machine is running ZFS Filesystem version $ZFS_VERSION"
+fi
+
+default_setup $DISKS
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/usr/src/test/zfs-tests/tests/functional/cli_root/zfs_upgrade/zfs_upgrade.kshlib	Wed Dec 05 22:04:50 2012 -0500
@@ -0,0 +1,179 @@
+#
+# CDDL HEADER START
+#
+# The contents of this file are subject to the terms of the
+# Common Development and Distribution License (the "License").
+# You may not use this file except in compliance with the License.
+#
+# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
+# or http://www.opensolaris.org/os/licensing.
+# See the License for the specific language governing permissions
+# and limitations under the License.
+#
+# When distributing Covered Code, include this CDDL HEADER in each
+# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
+# If applicable, add the following below this CDDL 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.
+#
+
+. $STF_SUITE/include/libtest.shlib
+
+#
+# For zfs create.
+#
+set -A zpl_create_versions 3 4  5
+set -A spa_create_versions 9 15 24
+
+#
+# For zfs upgrade
+#
+set -A zpl_upgrade_versions 3 4  5
+set -A spa_upgrade_versions 9 15 24
+
+function default_setup_datasets #rootfs
+{
+	typeset rootfs=$1
+	typeset pool=${rootfs%%/*}
+	typeset -i vp=$(get_pool_prop version $pool)
+	typeset -i version
+	typeset -i m
+	typeset -i spa_version
+	typeset -i zpl_version
+
+	for version in $ZFS_ALL_VERSIONS ; do
+		typeset verfs
+		eval verfs=\$ZFS_VERSION_$version
+		typeset current_fs=$rootfs/$verfs
+		typeset current_snap=${current_fs}@snap
+		typeset current_clone=$rootfs/clone$verfs
+
+		(( m=0 ))
+		(( spa_version=0 ))
+		while (( m < ${#zpl_create_versions[@]} )); do
+			(( zpl_version=${zpl_create_versions[m]} ))
+			if (( version == zpl_version )); then
+				(( spa_version=${spa_create_versions[m]} ))
+				break
+			fi
+			(( m+=1 ))
+		done
+		if (( spa_version != 0 )) && (( vp < spa_version )); then
+			log_mustnot $ZFS create -o version=${version} ${current_fs}
+			continue
+		fi
+		log_must $ZFS create -o version=${version} ${current_fs}
+		log_must $ZFS snapshot ${current_snap}
+		log_must $ZFS clone ${current_snap} ${current_clone}
+
+		for subversion in $ZFS_ALL_VERSIONS ; do
+			typeset subverfs
+			eval subverfs=\$ZFS_VERSION_$subversion
+
+			(( m=0 ))
+			(( spa_version=0 ))
+			while (( m < ${#zpl_create_versions[@]} )); do
+				(( zpl_version=${zpl_create_versions[m]} ))
+				if (( subversion == zpl_version )); then
+					(( spa_version=${spa_create_versions[m]} ))
+					break
+				fi
+				(( m+=1 ))
+			done
+			if (( spa_version != 0 )) && (( vp < spa_version )); then
+				log_mustnot $ZFS create -o \
+				version=${subversion} ${current_fs}/$subverfs
+			else
+				log_must $ZFS create -o \
+				version=${subversion} ${current_fs}/$subverfs
+			fi
+		done
+	done
+}
+
+function default_cleanup_datasets #rootfs
+{
+	typeset rootfs=$1
+
+	if datasetexists $rootfs ; then
+		log_must $ZFS destroy -Rf $rootfs
+	fi
+
+	if datasetnonexists $rootfs ; then
+		log_must $ZFS create $rootfs
+	fi
+}
+
+function default_check_zfs_upgrade #rootfs
+{
+	typeset rootfs=$1
+	typeset pool=${rootfs%%/*}
+	typeset -i vp=$(get_pool_prop version $pool)
+	typeset -i m
+	typeset -i spa_version
+	typeset -i zpl_version
+	typeset newv
+	typeset -i df_ret
+
+	$DF -F zfs / > /dev/null 2>&1
+	df_ret=$?
+
+	for newv in "" $ZFS_VERSION; do
+		default_setup_datasets $rootfs
+		if [[ -n $newv ]]; then
+			opt="-V $newv"
+		else
+			newv=$ZFS_VERSION
+		fi
+
+		(( m=0 ))
+		(( spa_version=0 ))
+		while (( m < ${#zpl_upgrade_versions[@]} )); do
+			(( zpl_version=${zpl_upgrade_versions[m]} ))
+			if (( newv == zpl_version )); then
+				(( spa_version=${spa_upgrade_versions[m]} ))
+				break
+			fi
+			(( m+=1 ))
+		done
+
+		if (( df_ret != 0 )); then
+			if (( spa_version != 0 )) && (( vp < spa_version )); then
+				log_mustnot eval '$ZFS upgrade $opt -a > /dev/null 2>&1'
+				log_must eval '$ZPOOL upgrade $pool > /dev/null 2>&1'
+				vp=$(get_pool_prop version $pool)
+			fi
+
+			log_must eval '$ZFS upgrade $opt -a > /dev/null 2>&1'
+
+			for fs in $($ZFS list -rH -t filesystem -o name $rootfs) ; do
+				log_must check_fs_version $fs $newv
+			done
+		fi
+
+		default_cleanup_datasets $rootfs
+	done
+}
+
+function check_fs_version #filesystem version
+{
+	typeset fs=$1
+	typeset -i version=${2:-$ZFS_VERSION}
+
+	if [[ -z $fs ]]; then
+		log_fail "No filesystem specified."
+	fi
+
+	typeset -i curv=$(get_prop version $fs)
+	if (( curv != version )); then
+		return 1
+	fi
+	return 0
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/usr/src/test/zfs-tests/tests/functional/cli_root/zfs_upgrade/zfs_upgrade_001_pos.ksh	Wed Dec 05 22:04:50 2012 -0500
@@ -0,0 +1,136 @@
+#!/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.
+#
+#
+. $STF_SUITE/include/libtest.shlib
+. $STF_SUITE/tests/functional/cli_root/zfs_upgrade/zfs_upgrade.kshlib
+
+#
+# DESCRIPTION:
+#	Executing 'zfs upgrade' command succeeds, it should report
+#	the current system version and list all old-version filesystems.
+#	If no old-version filesystems be founded, it prints out
+#	"All filesystems are formatted with the current version."
+#
+# STRATEGY:
+# 1. Prepare a set of datasets which contain old-version and current version.
+# 2. Execute 'zfs upgrade', verify return 0, and it prints out
+#	the current system version and list all old-version filesystems.
+# 3. Remove all old-version filesystems, then execute 'zfs upgrade' again,
+#	verify return 0, and get the expected message.
+#
+
+verify_runnable "both"
+
+function cleanup
+{
+	if datasetexists $rootfs ; then
+		log_must $ZFS destroy -Rf $rootfs
+	fi
+	log_must $ZFS create $rootfs
+
+	for file in $output $oldoutput ; do
+		if [[ -f $file ]]; then
+			log_must $RM -f $file
+		fi
+	done
+}
+
+log_assert "Executing 'zfs upgrade' command succeeds."
+log_onexit cleanup
+
+rootfs=$TESTPOOL/$TESTFS
+typeset output=/tmp/zfs-versions.$$
+typeset oldoutput=/tmp/zfs-versions-old.$$
+typeset expect_str1="This system is currently running ZFS filesystem version"
+typeset expect_str2="All filesystems are formatted with the current version"
+typeset expect_str3="The following filesystems are out of date, and can be upgraded"
+typeset -i COUNT OLDCOUNT
+
+$ZFS upgrade | $NAWK '$1 ~ "^[0-9]+$" {print $2}'> $oldoutput
+OLDCOUNT=$( $WC -l $oldoutput | $AWK '{print $1}' )
+
+old_datasets=""
+for version in $ZFS_ALL_VERSIONS ; do
+	typeset verfs
+	eval verfs=\$ZFS_VERSION_$version
+	typeset current_fs=$rootfs/$verfs
+	typeset current_snap=${current_fs}@snap
+	typeset current_clone=$rootfs/clone$verfs
+	log_must $ZFS create -o version=${version} ${current_fs}
+	log_must $ZFS snapshot ${current_snap}
+	log_must $ZFS clone ${current_snap} ${current_clone}
+
+	if (( version != $ZFS_VERSION )); then
+		old_datasets="$old_datasets ${current_fs} ${current_clone}"
+	fi
+done
+
+if is_global_zone; then
+	log_must $ZFS create -V 100m $rootfs/$TESTVOL
+fi
+
+log_must eval '$ZFS upgrade > $output 2>&1'
+
+# we also check that the usage message contains at least a description
+# of the current ZFS version.
+log_must eval '$GREP "${expect_str1} $ZFS_VERSION" $output > /dev/null 2>&1'
+$ZFS upgrade | $NAWK '$1 ~ "^[0-9]+$" {print $2}'> $output
+COUNT=$( $WC -l $output | $AWK '{print $1}' )
+
+typeset -i i=0
+for fs in ${old_datasets}; do
+	log_must $GREP "^$fs$" $output
+	(( i = i + 1 ))
+done
+
+if (( i != COUNT - OLDCOUNT )); then
+	$CAT $output
+	log_fail "More old-version filesystems print out than expect."
+fi
+
+for fs in $old_datasets ; do
+	if datasetexists $fs ; then
+		log_must $ZFS destroy -Rf $fs
+	fi
+done
+
+log_must eval '$ZFS upgrade > $output 2>&1'
+log_must eval '$GREP "${expect_str1} $ZFS_VERSION" $output > /dev/null 2>&1'
+if (( OLDCOUNT == 0 )); then
+	log_must eval '$GREP "${expect_str2}" $output > /dev/null 2>&1'
+else
+	log_must eval '$GREP "${expect_str3}" $output > /dev/null 2>&1'
+fi
+$ZFS upgrade | $NAWK '$1 ~ "^[0-9]+$" {print $2}'> $output
+COUNT=$( $WC -l $output | $AWK '{print $1}' )
+
+if (( COUNT != OLDCOUNT )); then
+	$CAT $output
+	log_fail "Unexpect old-version filesystems print out."
+fi
+
+log_pass "Executing 'zfs upgrade' command succeeds."
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/usr/src/test/zfs-tests/tests/functional/cli_root/zfs_upgrade/zfs_upgrade_002_pos.ksh	Wed Dec 05 22:04:50 2012 -0500
@@ -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.
+#
+#
+. $STF_SUITE/include/libtest.shlib
+. $STF_SUITE/tests/functional/cli_root/zfs_upgrade/zfs_upgrade.kshlib
+
+#
+# DESCRIPTION:
+#	Executing 'zfs upgrade -v ' command succeeds, it should
+#	show the info of available versions.
+#
+# STRATEGY:
+# 1. Execute 'zfs upgrade -v', verify return value is 0.
+# 2, Verify all the available versions info are printed out.
+#
+
+verify_runnable "both"
+
+function cleanup
+{
+	if [[ -f $output ]]; then
+		log_must $RM -f $output
+	fi
+}
+
+log_assert "Executing 'zfs upgrade -v' command succeeds."
+log_onexit cleanup
+
+typeset output=/tmp/zfs-versions.$$
+typeset expect_str1="Initial ZFS filesystem version"
+typeset expect_str2="Enhanced directory entries"
+
+log_must eval '$ZFS upgrade -v > /dev/null 2>&1'
+
+$ZFS upgrade -v | $NAWK '$1 ~ "^[0-9]+$" {print $0}'> $output
+log_must eval '$GREP "${expect_str1}" $output > /dev/null 2>&1'
+log_must eval '$GREP "${expect_str2}" $output > /dev/null 2>&1'
+
+log_pass "Executing 'zfs upgrade -v' command succeeds."
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/usr/src/test/zfs-tests/tests/functional/cli_root/zfs_upgrade/zfs_upgrade_003_pos.ksh	Wed Dec 05 22:04:50 2012 -0500
@@ -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 2009 Sun Microsystems, Inc.  All rights reserved.
+# Use is subject to license terms.
+#
+#
+. $STF_SUITE/include/libtest.shlib
+. $STF_SUITE/tests/functional/cli_root/zfs_upgrade/zfs_upgrade.kshlib
+
+#
+# DESCRIPTION:
+#	Executing 'zfs upgrade [-V version] filesystem' command succeeds,
+#	it could upgrade a filesystem to specific version or current version.
+#
+# STRATEGY:
+# 1. Prepare a set of datasets which contain old-version and current version.
+# 2. Execute 'zfs upgrade [-V version] filesystem', verify return 0,
+# 3. Verify the filesystem be updated as expected.
+#
+
+verify_runnable "both"
+
+function cleanup
+{
+	if datasetexists $rootfs ; then
+		log_must $ZFS destroy -Rf $rootfs
+	fi
+	log_must $ZFS create $rootfs
+}
+
+function setup_datasets
+{
+	datasets=""
+	for version in $ZFS_ALL_VERSIONS ; do
+		typeset verfs
+		eval verfs=\$ZFS_VERSION_$version
+		typeset current_fs=$rootfs/$verfs
+		typeset current_snap=${current_fs}@snap
+		typeset current_clone=$rootfs/clone$verfs
+		log_must $ZFS create -o version=${version} ${current_fs}
+		log_must $ZFS snapshot ${current_snap}
+		log_must $ZFS clone ${current_snap} ${current_clone}
+		datasets="$datasets ${current_fs} ${current_clone}"
+	done
+}
+
+log_assert "Executing 'zfs upgrade [-V version] filesystem' command succeeds."
+log_onexit cleanup
+
+rootfs=$TESTPOOL/$TESTFS
+typeset datasets
+
+typeset newv
+for newv in "" "current" $ZFS_ALL_VERSIONS; do
+	setup_datasets
+	for fs in $datasets ; do
+		typeset -i oldv=$(get_prop version $fs)
+
+		if [[ -n $newv ]]; then
+			opt="-V $newv"
+			if [[ $newv == current ]]; then
+				newv=$ZFS_VERSION
+			fi
+		else
+			newv=$ZFS_VERSION
+		fi
+
+		if (( newv >= oldv )); then
+			log_must eval '$ZFS upgrade $opt $fs > /dev/null 2>&1'
+			log_must check_fs_version $fs $newv
+		else
+			log_mustnot eval '$ZFS upgrade $opt $fs > /dev/null 2>&1'
+			log_must check_fs_version $fs $oldv
+		fi
+	done
+	cleanup
+done
+
+log_pass "Executing 'zfs upgrade [-V version] filesystem' command succeeds."
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/usr/src/test/zfs-tests/tests/functional/cli_root/zfs_upgrade/zfs_upgrade_004_pos.ksh	Wed Dec 05 22:04:50 2012 -0500
@@ -0,0 +1,104 @@
+#!/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.
+#
+#
+. $STF_SUITE/include/libtest.shlib
+. $STF_SUITE/tests/functional/cli_root/zfs_upgrade/zfs_upgrade.kshlib
+
+#
+# DESCRIPTION:
+#	Executing 'zfs upgrade -r [-V version] filesystem' command succeeds,
+#	it upgrade filesystem recursively to specific or current version.
+#
+# STRATEGY:
+# 1. Prepare a set of datasets which contain old-version and current version.
+# 2. Execute 'zfs upgrade -r [-V version] filesystem', verify return 0,
+# 3. Verify the filesystem be updated recursively as expected.
+#
+
+verify_runnable "both"
+
+function cleanup
+{
+	if datasetexists $rootfs ; then
+		log_must $ZFS destroy -Rf $rootfs
+	fi
+	log_must $ZFS create $rootfs
+}
+
+function setup_datasets
+{
+	datasets=""
+	for version in $ZFS_ALL_VERSIONS ; do
+		typeset verfs
+		eval verfs=\$ZFS_VERSION_$version
+		typeset current_fs=$rootfs/$verfs
+		typeset current_snap=${current_fs}@snap
+		typeset current_clone=$rootfs/clone$verfs
+		log_must $ZFS create -o version=${version} ${current_fs}
+		log_must $ZFS snapshot ${current_snap}
+		log_must $ZFS clone ${current_snap} ${current_clone}
+
+		for subversion in $ZFS_ALL_VERSIONS ; do
+			typeset subverfs
+			eval subverfs=\$ZFS_VERSION_$subversion
+			log_must $ZFS create -o version=${subversion} \
+				${current_fs}/$subverfs
+		done
+		datasets="$datasets ${current_fs}"
+	done
+}
+
+log_assert "Executing 'zfs upgrade -r [-V version] filesystem' command succeeds."
+log_onexit cleanup
+
+rootfs=$TESTPOOL/$TESTFS
+
+typeset datasets
+
+typeset newv
+for newv in "" "current" $ZFS_VERSION; do
+	setup_datasets
+	for topfs in $datasets ; do
+		if [[ -n $newv ]]; then
+			opt="-V $newv"
+			if [[ $newv == current ]]; then
+				newv=$ZFS_VERSION
+			fi
+		else
+			newv=$ZFS_VERSION
+		fi
+
+		log_must eval '$ZFS upgrade -r $opt $topfs > /dev/null 2>&1'
+
+		for fs in $($ZFS list -rH -t filesystem -o name $topfs) ; do
+			log_must check_fs_version $fs $newv
+		done
+	done
+	cleanup
+done
+
+log_pass "Executing 'zfs upgrade -r [-V version] filesystem' command succeeds."
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/usr/src/test/zfs-tests/tests/functional/cli_root/zfs_upgrade/zfs_upgrade_005_pos.ksh	Wed Dec 05 22:04:50 2012 -0500
@@ -0,0 +1,104 @@
+#!/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.
+#
+#
+. $STF_SUITE/include/libtest.shlib
+. $STF_SUITE/tests/functional/cli_root/zfs_upgrade/zfs_upgrade.kshlib
+
+#
+# DESCRIPTION:
+#	Executing 'zfs upgrade [-V version] -a' command succeeds,
+#	it upgrade all filesystems to specific or current version.
+#
+# STRATEGY:
+# 1. Prepare a set of datasets which contain old-version and current version.
+# 2. Execute 'zfs upgrade [-V version] -a', verify return 0,
+# 3. Verify all the filesystems be updated as expected.
+#
+
+verify_runnable "both"
+
+function cleanup
+{
+	if datasetexists $rootfs ; then
+		log_must $ZFS destroy -Rf $rootfs
+	fi
+	log_must $ZFS create $rootfs
+}
+
+function setup_datasets
+{
+	datasets=""
+	for version in $ZFS_ALL_VERSIONS ; do
+		typeset verfs
+		eval verfs=\$ZFS_VERSION_$version
+		typeset current_fs=$rootfs/$verfs
+		typeset current_snap=${current_fs}@snap
+		typeset current_clone=$rootfs/clone$verfs
+		log_must $ZFS create -o version=${version} ${current_fs}
+		log_must $ZFS snapshot ${current_snap}
+		log_must $ZFS clone ${current_snap} ${current_clone}
+
+		for subversion in $ZFS_ALL_VERSIONS ; do
+			typeset subverfs
+			eval subverfs=\$ZFS_VERSION_$subversion
+			log_must $ZFS create -o version=${subversion} \
+				${current_fs}/$subverfs
+		done
+		datasets="$datasets ${current_fs}"
+	done
+}
+
+log_assert "Executing 'zfs upgrade [-V version] -a' command succeeds."
+log_onexit cleanup
+
+rootfs=$TESTPOOL/$TESTFS
+
+typeset datasets
+
+typeset newv
+for newv in "" "current" $ZFS_VERSION; do
+	setup_datasets
+	if [[ -n $newv ]]; then
+		opt="-V $newv"
+		if [[ $newv == current ]]; then
+			newv=$ZFS_VERSION
+		fi
+	else
+		newv=$ZFS_VERSION
+	fi
+
+	export __ZFS_POOL_RESTRICT="$TESTPOOL"
+	log_must $ZFS upgrade $opt -a
+	unset __ZFS_POOL_RESTRICT
+
+	for fs in $($ZFS list -rH -t filesystem -o name $rootfs) ; do
+		log_must check_fs_version $fs $newv
+	done
+	cleanup
+done
+
+log_pass "Executing 'zfs upgrade [-V version] -a' command succeeds."
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/usr/src/test/zfs-tests/tests/functional/cli_root/zfs_upgrade/zfs_upgrade_006_neg.ksh	Wed Dec 05 22:04:50 2012 -0500
@@ -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 2007 Sun Microsystems, Inc.  All rights reserved.
+# Use is subject to license terms.
+#
+
+. $STF_SUITE/include/libtest.shlib
+. $STF_SUITE/tests/functional/cli_root/zfs_upgrade/zfs_upgrade.kshlib
+
+#
+# DESCRIPTION:
+# Verify that invalid upgrade parameters and options are caught.
+#
+# STRATEGY:
+# 1. Create a ZFS file system.
+# 2. For each option in the list, try 'zfs upgrade'.
+# 3. Verify that the operation fails as expected.
+#
+
+verify_runnable "both"
+
+set -A args "" "-?" "-A" "-R" "-b" "-c" "-d" "--invalid" \
+    "-V" "-V $TESTPOOL/$TESTFS" "-V $TESTPOOL $TESTPOOL/$TESTFS"
+
+log_assert "Badly-formed 'zfs upgrade' should return an error."
+
+typeset -i i=1
+while (( i < ${#args[*]} )); do
+	log_mustnot $ZFS upgrade ${args[i]}
+	((i = i + 1))
+done
+
+log_pass "Badly-formed 'zfs upgrade' fail as expected."
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/usr/src/test/zfs-tests/tests/functional/cli_root/zfs_upgrade/zfs_upgrade_007_neg.ksh	Wed Dec 05 22:04:50 2012 -0500
@@ -0,0 +1,55 @@
+#!/bin/ksh -p
+#
+# CDDL HEADER START
+#
+# The contents of this file are subject to the terms of the
+# Common Development and Distribution License (the "License").
+# You may not use this file except in compliance with the License.
+#
+# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
+# or http://www.opensolaris.org/os/licensing.
+# See the License for the specific language governing permissions
+# and limitations under the License.
+#
+# When distributing Covered Code, include this CDDL HEADER in each
+# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
+# If applicable, add the following below this CDDL HEADER, with the
+# fields enclosed by brackets "[]" replaced with your own identifying
+# information: Portions Copyright [yyyy] [name of copyright owner]
+#
+# CDDL HEADER END
+#
+
+#
+# Copyright 2007 Sun Microsystems, Inc.  All rights reserved.
+# Use is subject to license terms.
+#
+
+. $STF_SUITE/include/libtest.shlib
+. $STF_SUITE/tests/functional/cli_root/zfs_upgrade/zfs_upgrade.kshlib
+
+#
+# DESCRIPTION:
+# Verify that version should only by '1' '2' or current version,
+# non-digit input are invalid.
+#
+# STRATEGY:
+# 1. For each invalid value of version in the list, try 'zfs upgrade -V version'.
+# 2. Verify that the operation fails as expected.
+#
+
+verify_runnable "both"
+
+set -A args \
+	"0" "0.000" "0.5" "-1.234" "-1" "1234b" "5678x"
+
+log_assert "Set invalid value or non-digit version should fail as expected."
+
+typeset -i i=0
+while (( i < ${#args[*]} ))
+do
+	log_mustnot $ZFS upgrade -V ${args[i]} $TESTPOOL/$TESTFS
+	((i = i + 1))
+done
+
+log_pass "Set invalid value or non-digit version fail as expected."
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/usr/src/test/zfs-tests/tests/functional/cli_root/zpool/Makefile	Wed Dec 05 22:04:50 2012 -0500
@@ -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) 2012 by Delphix. All rights reserved.
+#
+
+include $(SRC)/Makefile.master
+
+ROOTOPTPKG = $(ROOT)/opt/zfs-tests
+TESTDIR = $(ROOTOPTPKG)/tests/functional/cli_root/zpool
+
+PROGS = cleanup \
+	setup \
+	zpool_001_neg \
+	zpool_002_pos \
+	zpool_003_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	Thu Jan 01 00:00:00 1970 +0000
+++ b/usr/src/test/zfs-tests/tests/functional/cli_root/zpool/cleanup.ksh	Wed Dec 05 22:04:50 2012 -0500
@@ -0,0 +1,30 @@
+#!/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.
+#
+
+. $STF_SUITE/include/libtest.shlib
+
+default_cleanup
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/usr/src/test/zfs-tests/tests/functional/cli_root/zpool/setup.ksh	Wed Dec 05 22:04:50 2012 -0500
@@ -0,0 +1,32 @@
+#!/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.
+#
+
+. $STF_SUITE/include/libtest.shlib
+
+DISK=${DISKS%% *}
+
+default_setup $DISK
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/usr/src/test/zfs-tests/tests/functional/cli_root/zpool/zpool_001_neg.ksh	Wed Dec 05 22:04:50 2012 -0500
@@ -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.
+#
+. $STF_SUITE/include/libtest.shlib
+
+#
+# DESCRIPTION:
+# A badly formed sub-command passed to zpool(1) should
+# return an error.
+#
+# STRATEGY:
+# 1. Create an array containg each zpool sub-command name.
+# 2. For each element, execute the sub-command.
+# 3. Verify it returns an error.
+#
+
+verify_runnable "both"
+
+
+set -A args "" "create" "add" "destroy" "import fakepool" \
+    "export fakepool" "create fakepool" "add fakepool" \
+    "create mirror" "create raidz" "create raidz1" \
+    "create mirror fakepool" "create raidz fakepool" \
+    "create raidz1 fakepool" "create raidz2 fakepool" \
+    "create fakepool mirror" "create fakepool raidz" \
+    "create fakepool raidz1" "create fakepool raidz2" \
+    "add fakepool mirror" "add fakepool raidz" \
+    "add fakepool raidz1" "add fakepool raidz2" \
+    "add mirror fakepool" "add raidz fakepool" \
+    "add raidz1 fakepool" "add raidz2 fakepool" \
+    "setvprop" "blah blah" "-%" "--" "--?" "-*" "-="
+
+log_assert "Execute zpool sub-command without proper parameters."
+
+typeset -i i=0
+while [[ $i -lt ${#args[*]} ]]; do
+	log_mustnot $ZPOOL ${args[i]}
+
+	((i = i + 1))
+done
+
+log_pass "Badly formed zpool sub-commands fail as expected."
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/usr/src/test/zfs-tests/tests/functional/cli_root/zpool/zpool_002_pos.ksh	Wed Dec 05 22:04:50 2012 -0500
@@ -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.
+#
+. $STF_SUITE/include/libtest.shlib
+
+#
+# DESCRIPTION:
+# With ZFS_ABORT set, all zpool commands should be able to abort and generate a core file.
+#
+# STRATEGY:
+# 1. Create an array of zpool command
+# 2. Execute each command in the array
+# 3. Verify the command aborts and generate a core file
+#
+
+verify_runnable "global"
+
+function cleanup
+{
+	unset ZFS_ABORT
+
+	if [[ -d $corepath ]]; then
+		$RM -rf $corepath
+	fi
+	if poolexists $pool; then
+		log_must $ZPOOL destroy -f $pool
+	fi
+}
+
+log_assert "With ZFS_ABORT set, all zpool commands can abort and generate a core file."
+log_onexit cleanup
+
+#preparation work for testing
+corepath=$TESTDIR/core
+if [[ -d $corepath ]]; then
+	$RM -rf $corepath
+fi
+$MKDIR $corepath
+
+pool=pool.$$
+vdev1=$TESTDIR/file1
+vdev2=$TESTDIR/file2
+vdev3=$TESTDIR/file3
+for vdev in $vdev1 $vdev2 $vdev3; do
+	$MKFILE 64m $vdev
+done
+
+set -A cmds "create $pool mirror $vdev1 $vdev2" "list $pool" "iostat $pool" \
+	"status $pool" "upgrade $pool" "get delegation $pool" "set delegation=off $pool" \
+	"export $pool" "import -d $TESTDIR $pool" "offline $pool $vdev1" \
+	"online $pool $vdev1" "clear $pool" "detach $pool $vdev2" \
+	"attach $pool $vdev1 $vdev2" "replace $pool $vdev2 $vdev3" \
+	"scrub $pool" "destroy -f $pool"
+
+set -A badparams "" "create" "destroy" "add" "remove" "list *" "iostat" "status" \
+		"online" "offline" "clear" "attach" "detach" "replace" "scrub" \
+		"import" "export" "upgrade" "history -?" "get" "set"
+
+$COREADM -p ${corepath}/core.%f
+export ZFS_ABORT=yes
+
+for subcmd in "${cmds[@]}" "${badparams[@]}"; do
+	$ZPOOL $subcmd >/dev/null 2>&1
+	corefile=${corepath}/core.zpool
+	if [[ ! -e $corefile ]]; then
+		log_fail "$ZPOOL $subcmd cannot generate core file  with ZFS_ABORT set."
+	fi
+	$RM -f $corefile
+done
+
+log_pass "With ZFS_ABORT set, zpool command can abort and generate core file as expected."
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/usr/src/test/zfs-tests/tests/functional/cli_root/zpool/zpool_003_pos.ksh	Wed Dec 05 22:04:50 2012 -0500
@@ -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) 2012 by Delphix. All rights reserved.
+#
+
+. $STF_SUITE/include/libtest.shlib
+
+#
+# DESCRIPTION:
+#	Verify debugging features of zpool such as ABORT and freeze/unfreeze
+#	should run successfully.
+#
+# STRATEGY:
+# 1. Create an array containg each zpool options.
+# 2. For each element, execute the zpool command.
+# 3. Verify it run successfully.
+#
+
+verify_runnable "both"
+
+log_assert "Debugging features of zpool should succeed."
+
+log_must $ZPOOL -? > /dev/null 2>&1
+
+if is_global_zone ; then
+	log_must $ZPOOL freeze $TESTPOOL
+else
+	log_mustnot $ZPOOL freeze $TESTPOOL
+	log_mustnot $ZPOOL freeze ${TESTPOOL%%/*}
+fi
+
+log_mustnot $ZPOOL freeze fakepool
+
+# Remove corefile possibly left by previous failing run of this test.
+[[ -f core ]] && log_must rm -f core
+
+ZFS_ABORT=1; export ZFS_ABORT
+$ZPOOL > /dev/null 2>&1
+unset ZFS_ABORT
+
+[[ -f core ]] || log_fail "$ZPOOL did not dump core by request."
+[[ -f core ]] && log_must rm -f core
+
+log_pass "Debugging features of zpool succeed."
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/usr/src/test/zfs-tests/tests/functional/cli_root/zpool_add/Makefile	Wed Dec 05 22:04:50 2012 -0500
@@ -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) 2012 by Delphix. All rights reserved.
+#
+
+include $(SRC)/Makefile.master
+
+ROOTOPTPKG = $(ROOT)/opt/zfs-tests
+TESTDIR = $(ROOTOPTPKG)/tests/functional/cli_root/zpool_add
+
+PROGS = cleanup \
+	setup \
+	zpool_add_001_pos \
+	zpool_add_002_pos \
+	zpool_add_003_pos \
+	zpool_add_004_pos \
+	zpool_add_005_pos \
+	zpool_add_006_pos \
+	zpool_add_007_neg \
+	zpool_add_008_neg \
+	zpool_add_009_neg
+
+FILES = zpool_add.cfg \
+	zpool_add.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	Thu Jan 01 00:00:00 1970 +0000
+++ b/usr/src/test/zfs-tests/tests/functional/cli_root/zpool_add/cleanup.ksh	Wed Dec 05 22:04:50 2012 -0500
@@ -0,0 +1,37 @@
+#!/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) 2012 by Delphix. All rights reserved.
+#
+
+. $STF_SUITE/include/libtest.shlib
+. $STF_SUITE/tests/functional/cli_root/zpool_add/zpool_add.kshlib
+
+cleanup_devices $DISKS
+
+log_pass
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/usr/src/test/zfs-tests/tests/functional/cli_root/zpool_add/setup.ksh	Wed Dec 05 22:04:50 2012 -0500
@@ -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 2009 Sun Microsystems, Inc.  All rights reserved.
+# Use is subject to license terms.
+#
+
+#
+# Copyright (c) 2012 by Delphix. All rights reserved.
+#
+
+. $STF_SUITE/include/libtest.shlib
+. $STF_SUITE/tests/functional/cli_root/zpool_add/zpool_add.kshlib
+
+verify_runnable "global"
+
+if ! $(is_physical_device $DISKS) ; then
+	log_unsupported "This directory cannot be run on raw files."
+fi
+
+if [[ -n $DISK ]]; then
+	#
+        # Use 'zpool create' to clean up the infomation in
+        # in the given disk to avoid slice overlapping.
+        #
+	cleanup_devices $DISK
+
+        partition_disk $SIZE $DISK 7
+else
+	for disk in `$ECHO $DISKSARRAY`; do
+		cleanup_devices $disk
+		partition_disk $SIZE $disk 7
+	done
+fi
+
+log_pass
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/usr/src/test/zfs-tests/tests/functional/cli_root/zpool_add/zpool_add.cfg	Wed Dec 05 22:04:50 2012 -0500
@@ -0,0 +1,100 @@
+#
+# CDDL HEADER START
+#
+# The contents of this file are subject to the terms of the
+# Common Development and Distribution License (the "License").
+# You may not use this file except in compliance with the License.
+#
+# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
+# or http://www.opensolaris.org/os/licensing.
+# See the License for the specific language governing permissions
+# and limitations under the License.
+#
+# When distributing Covered Code, include this CDDL HEADER in each
+# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
+# If applicable, add the following below this CDDL 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.
+#
+
+export DISK_ARRAY_NUM=0
+export DISK_ARRAY_LIMIT=4
+export DISKSARRAY=""
+
+#
+# Variables for zpool_add_006
+#
+export STF_TIMEOUT=2400
+export VDEVS_NUM=300
+export FILE_SIZE=100 #100mb
+
+function set_disks
+{
+        set -A disk_array $(find_disks $DISKS)
+
+        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 ))
+                        (( i>$DISK_ARRAY_LIMIT )) && break
+                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 FILESIZE="100m"
+export FILESIZE1="150m"
+export SIZE="150m"
+export SIZE1="250m"
+export SLICE0=0
+export SLICE1=1
+export SLICE2=2
+export SLICE3=3
+export SLICE4=4
+export SLICE5=5
+export SLICE6=6
+export SLICE7=7
+
+export FILEDISK=filedisk.zpool_add
+export FILEDISK0=filedisk0.zpool_add
+export FILEDISK1=filedisk1.zpool_add
+export FILEDISK2=filedisk2.zpool_add
+export FILEDISK3=filedisk3.zpool_add
+
+export VOLSIZE=64mb
+
+export BYND_MAX_NAME="byondmaxnamelength\
+012345678901234567890123456789\
+012345678901234567890123456789\
+012345678901234567890123456789\
+012345678901234567890123456789\
+012345678901234567890123456789\
+012345678901234567890123456789\
+012345678901234567890123456789\
+012345678901234567890123456789"
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/usr/src/test/zfs-tests/tests/functional/cli_root/zpool_add/zpool_add.kshlib	Wed Dec 05 22:04:50 2012 -0500
@@ -0,0 +1,147 @@
+#
+# CDDL HEADER START
+#
+# The contents of this file are subject to the terms of the
+# Common Development and Distribution License (the "License").
+# You may not use this file except in compliance with the License.
+#
+# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
+# or http://www.opensolaris.org/os/licensing.
+# See the License for the specific language governing permissions
+# and limitations under the License.
+#
+# When distributing Covered Code, include this CDDL HEADER in each
+# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
+# If applicable, add the following below this CDDL HEADER, with the
+# fields enclosed by brackets "[]" replaced with your own identifying
+# information: Portions Copyright [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.
+#
+
+. $STF_SUITE/include/libtest.shlib
+. $STF_SUITE/tests/functional/cli_root/zpool_add/zpool_add.cfg
+
+#
+# check if the <pool> contains <vdev> ...
+#
+# $1 pool
+# $2..n <vdev> ...
+#
+# Return 0 if <vdev> are contained in the <pool>; 1 if not used; 2 if pool
+# name is missing
+#
+function iscontained
+{
+	typeset pool=$1
+	typeset vdev
+
+        if [[ -z $pool ]]; then
+                log_note "Missing pool name."
+                return 2
+        fi
+
+	shift
+
+	for vdev in $@; do
+
+# remove /dev/dsk in vdev if there is
+		$ECHO $vdev | $GREP "^/dev/dsk" >/dev/null 2>&1
+		(( $? == 0 )) && \
+			vdev=${vdev##*/}
+
+		$ZPOOL status "$pool" | $AWK '$1 == vdevname {exit 1}' \
+			vdevname=$vdev >/dev/null 2>&1
+		(( $? != 1 )) && \
+			return 1
+	done
+
+	return 0;
+
+}
+
+#
+# Find the storage device in /etc/vfstab
+#
+function find_vfstab_dev
+{
+	typeset vfstab="/etc/vfstab"
+	typeset tmpfile="/tmp/vfstab.tmp"
+	typeset vfstabdev
+	typeset vfstabdevs=""
+	typeset line
+
+	$CAT $vfstab | $GREP "^/dev/dsk" >$tmpfile
+	while read -r line
+	do
+		vfstabdev=`$ECHO "$line" | $AWK '{print $1}'`
+		vfstabdev=${vfstabdev%%:}
+		vfstabdevs="$vfstabdev $vfstabdevs"
+	done <$tmpfile
+
+	$RM -f $tmpfile
+	$ECHO $vfstabdevs
+}
+
+#
+# Find the storage device in /etc/mnttab
+#
+function find_mnttab_dev
+{
+	typeset mnttab="/etc/mnttab"
+	typeset tmpfile="/tmp/mnttab.tmp"
+	typeset mnttabdev
+	typeset mnttabdevs=""
+	typeset line
+
+	$CAT $mnttab | $GREP "^/dev/dsk" >$tmpfile
+	while read -r line
+	do
+		mnttabdev=`$ECHO "$line" | $AWK '{print $1}'`
+		mnttabdev=${mnttabdev%%:}
+		mnttabdevs="$mnttabdev $mnttabdevs"
+	done <$tmpfile
+
+	$RM -f $tmpfile
+	$ECHO $mnttabdevs
+}
+
+#
+# Save the systme current dump device configuration
+#
+function save_dump_dev
+{
+
+	typeset dumpdev
+	typeset fnd="Dump device"
+
+	dumpdev=`$DUMPADM | $GREP "$fnd" | $CUT -f2 -d : | \
+		$AWK '{print $1}'`
+	$ECHO $dumpdev
+}
+
+#
+# Common cleanup routine for partitions used in testing
+#
+function partition_cleanup
+{
+
+        if [[ -n $DISK ]]; then
+                partition_disk $SIZE $DISK 7
+        else
+                typeset disk=""
+                for disk in $DISK0 $DISK1; do
+                        partition_disk $SIZE $disk 7
+                done
+        fi
+
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/usr/src/test/zfs-tests/tests/functional/cli_root/zpool_add/zpool_add_001_pos.ksh	Wed Dec 05 22:04:50 2012 -0500
@@ -0,0 +1,123 @@
+#!/bin/ksh -p
+#
+# CDDL HEADER START
+#
+# The contents of this file are subject to the terms of the
+# Common Development and Distribution License (the "License").
+# You may not use this file except in compliance with the License.
+#
+# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
+# or http://www.opensolaris.org/os/licensing.
+# See the License for the specific language governing permissions
+# and limitations under the License.
+#
+# When distributing Covered Code, include this CDDL HEADER in each
+# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
+# If applicable, add the following below this CDDL 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.
+#
+. $STF_SUITE/include/libtest.shlib
+. $STF_SUITE/tests/functional/cli_root/zpool_add/zpool_add.kshlib
+
+#
+# DESCRIPTION:
+#	'zpool add <pool> <vdev> ...' can successfully add the specified
+# devices to the given pool
+#
+# STRATEGY:
+#	1. Create a storage pool
+#	2. Add spare devices to the pool
+#	3. Verify the devices are added to the pool successfully
+#
+
+verify_runnable "global"
+
+function cleanup
+{
+	poolexists $TESTPOOL && \
+		destroy_pool $TESTPOOL
+
+	partition_cleanup
+}
+
+log_assert "'zpool add <pool> <vdev> ...' can add devices to the pool."
+
+log_onexit cleanup
+
+set -A keywords "" "mirror" "raidz" "raidz1" "spare"
+
+case $DISK_ARRAY_NUM in
+0|1)
+        pooldevs="${disk}s${SLICE0} \
+                  /dev/dsk/${disk}s${SLICE0} \
+                  \"${disk}s${SLICE0} ${disk}s${SLICE1}\""
+        mirrordevs="\"/dev/dsk/${disk}s${SLICE0} ${disk}s${SLICE1}\""
+        raidzdevs="\"/dev/dsk/${disk}s${SLICE0} ${disk}s${SLICE1}\""
+
+        ;;
+2|*)
+        pooldevs="${DISK0}s${SLICE0}\
+                 \"/dev/dsk/${DISK0}s${SLICE0} ${DISK1}s${SLICE0}\" \
+                 \"${DISK0}s${SLICE0} ${DISK0}s${SLICE1} ${DISK1}s${SLICE1}\"\
+                 \"${DISK0}s${SLICE0} ${DISK1}s${SLICE0} ${DISK0}s${SLICE1}\
+                   ${DISK1}s${SLICE1}\""
+        mirrordevs="\"/dev/dsk/${DISK0}s${SLICE0} ${DISK1}s${SLICE0}\""
+        raidzdevs="\"/dev/dsk/${DISK0}s${SLICE0} ${DISK1}s${SLICE0}\""
+
+        ;;
+esac
+
+typeset -i i=0
+typeset vdev
+eval set -A poolarray $pooldevs
+eval set -A mirrorarray $mirrordevs
+eval set -A raidzarray $raidzdevs
+
+while (( $i < ${#keywords[*]} )); do
+        case ${keywords[i]} in
+        ""|spare)
+		for vdev in "${poolarray[@]}"; do
+			create_pool "$TESTPOOL" "${disk}s${SLICE6}"
+			log_must poolexists "$TESTPOOL"
+			log_must $ZPOOL add -f "$TESTPOOL" ${keywords[i]} $vdev
+			log_must iscontained "$TESTPOOL" "$vdev"
+			destroy_pool "$TESTPOOL"
+		done
+
+		;;
+        mirror)
+		for vdev in "${mirrorarray[@]}"; do
+			create_pool "$TESTPOOL" "${keywords[i]}" \
+				"${disk}s${SLICE4}" "${disk}s${SLICE5}"
+			log_must poolexists "$TESTPOOL"
+			log_must $ZPOOL add "$TESTPOOL" ${keywords[i]} $vdev
+			log_must iscontained "$TESTPOOL" "$vdev"
+			destroy_pool "$TESTPOOL"
+		done
+
+		;;
+        raidz|raidz1)
+		for vdev in "${raidzarray[@]}"; do
+			create_pool "$TESTPOOL" "${keywords[i]}" \
+				"${disk}s${SLICE4}" "${disk}s${SLICE5}"
+			log_must poolexists "$TESTPOOL"
+			log_must $ZPOOL add "$TESTPOOL" ${keywords[i]} $vdev
+			log_must iscontained "$TESTPOOL" "$vdev"
+			destroy_pool "$TESTPOOL"
+		done
+
+		;;
+        esac
+
+        (( i = i+1 ))
+done
+
+log_pass "'zpool add <pool> <vdev> ...' executes successfully"
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/usr/src/test/zfs-tests/tests/functional/cli_root/zpool_add/zpool_add_002_pos.ksh	Wed Dec 05 22:04:50 2012 -0500
@@ -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.
+#
+. $STF_SUITE/include/libtest.shlib
+. $STF_SUITE/tests/functional/cli_root/zpool_add/zpool_add.kshlib
+
+#
+# DESCRIPTION:
+#	'zpool add -f <pool> <vdev> ...' can successfully add the specified
+# devices to given pool in some cases.
+#
+# STRATEGY:
+#	1. Create a mirrored pool
+#	2. Without -f option to add 1-way device the mirrored pool will fail
+#	3. Use -f to override the errors to add 1-way device to the mirrored
+#	pool
+#	4. Verify the device is added successfully
+#
+
+verify_runnable "global"
+
+function cleanup
+{
+        poolexists $TESTPOOL && \
+                destroy_pool $TESTPOOL
+
+	partition_cleanup
+}
+
+log_assert "'zpool add -f <pool> <vdev> ...' can successfully add" \
+	"devices to the pool in some cases."
+
+log_onexit cleanup
+
+create_pool "$TESTPOOL" mirror "${disk}s${SLICE0}" "${disk}s${SLICE1}"
+log_must poolexists "$TESTPOOL"
+
+log_mustnot $ZPOOL add "$TESTPOOL" ${disk}s${SLICE3}
+log_mustnot iscontained "$TESTPOOL" "${disk}s${SLICE3}"
+
+log_must $ZPOOL add -f "$TESTPOOL" ${disk}s${SLICE3}
+log_must iscontained "$TESTPOOL" "${disk}s${SLICE3}"
+
+log_pass "'zpool add -f <pool> <vdev> ...' executes successfully."
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/usr/src/test/zfs-tests/tests/functional/cli_root/zpool_add/zpool_add_003_pos.ksh	Wed Dec 05 22:04:50 2012 -0500
@@ -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.
+#
+. $STF_SUITE/include/libtest.shlib
+. $STF_SUITE/tests/functional/cli_root/zpool_add/zpool_add.kshlib
+
+#
+# DESCRIPTION:
+#	'zpool add -n <pool> <vdev> ...' can display the configuration without
+# adding the specified devices to given pool
+#
+# STRATEGY:
+#	1. Create a storage pool
+#	2. Use -n to add a device to the pool
+#	3. Verify the device is not added actually
+#
+
+verify_runnable "global"
+
+function cleanup
+{
+        poolexists $TESTPOOL && \
+                destroy_pool $TESTPOOL
+
+	partition_cleanup
+
+	[[ -e $tmpfile ]] && \
+		log_must $RM -f $tmpfile
+}
+
+log_assert "'zpool add -n <pool> <vdev> ...' can display the configuration" \
+	"without actually adding devices to the pool."
+
+log_onexit cleanup
+
+tmpfile="/var/tmp/zpool_add_003.tmp$$"
+
+create_pool "$TESTPOOL" "${disk}s${SLICE0}"
+log_must poolexists "$TESTPOOL"
+
+$ZPOOL add -n "$TESTPOOL" ${disk}s${SLICE1} > $tmpfile
+
+log_mustnot iscontained "$TESTPOOL" "${disk}s${SLICE1}"
+
+str="would update '$TESTPOOL' to the following configuration:"
+$CAT $tmpfile | $GREP "$str" >/dev/null 2>&1
+(( $? != 0 )) && \
+	 log_fail "'zpool add -n <pool> <vdev> ...' is executed as unexpected"
+
+log_pass "'zpool add -n <pool> <vdev> ...'executes successfully."
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/usr/src/test/zfs-tests/tests/functional/cli_root/zpool_add/zpool_add_004_pos.ksh	Wed Dec 05 22:04:50 2012 -0500
@@ -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.
+#
+. $STF_SUITE/include/libtest.shlib
+. $STF_SUITE/tests/functional/cli_root/zpool_add/zpool_add.kshlib
+
+#
+# DESCRIPTION:
+#	'zpool add <pool> <vdev> ...' can successfully add a zfs volume
+# to the given pool
+#
+# STRATEGY:
+#	1. Create a storage pool and a zfs volume
+#	2. Add the volume to the pool
+#	3. Verify the devices are added to the pool successfully
+#
+
+verify_runnable "global"
+
+function cleanup
+{
+	poolexists $TESTPOOL && \
+		destroy_pool "$TESTPOOL"
+
+	datasetexists $TESTPOOL1/$TESTVOL && \
+		log_must $ZFS destroy -f $TESTPOOL1/$TESTVOL
+	poolexists $TESTPOOL1 && \
+		destroy_pool "$TESTPOOL1"
+
+	partition_cleanup
+
+}
+
+log_assert "'zpool add <pool> <vdev> ...' can add zfs volume to the pool."
+
+log_onexit cleanup
+
+create_pool "$TESTPOOL" "${disk}s${SLICE0}"
+log_must poolexists "$TESTPOOL"
+
+create_pool "$TESTPOOL1" "${disk}s${SLICE1}"
+log_must poolexists "$TESTPOOL1"
+log_must $ZFS create -V $VOLSIZE $TESTPOOL1/$TESTVOL
+
+log_must $ZPOOL add "$TESTPOOL" /dev/zvol/dsk/$TESTPOOL1/$TESTVOL
+
+log_must iscontained "$TESTPOOL" "/dev/zvol/dsk/$TESTPOOL1/$TESTVOL"
+
+log_pass "'zpool add <pool> <vdev> ...' adds zfs volume to the pool successfully"
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/usr/src/test/zfs-tests/tests/functional/cli_root/zpool_add/zpool_add_005_pos.ksh	Wed Dec 05 22:04:50 2012 -0500
@@ -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 2009 Sun Microsystems, Inc.  All rights reserved.
+# Use is subject to license terms.
+#
+. $STF_SUITE/include/libtest.shlib
+. $STF_SUITE/tests/functional/cli_root/zpool_add/zpool_add.kshlib
+
+#
+# DESCRIPTION:
+#       'zpool add' should return fail if
+#	1. vdev is part of an active pool
+#	2. vdev is currently mounted
+#	3. vdev is in /etc/vfstab
+#	3. vdev is specified as the dedicated dump device
+#
+# STRATEGY:
+#	1. Create case scenarios
+#	2. For each scenario, try to add the device to the pool
+#	3. Verify the add operation get failed
+#
+
+verify_runnable "global"
+
+function cleanup
+{
+	poolexists "$TESTPOOL" && \
+		destroy_pool "$TESTPOOL"
+	poolexists "$TESTPOOL1" && \
+		destroy_pool "$TESTPOOL1"
+
+	if [[ -n $saved_dump_dev ]]; then
+		log_must eval "$DUMPADM -u -d $saved_dump_dev > /dev/null"
+	fi
+
+	partition_cleanup
+}
+
+log_assert "'zpool add' should fail with inapplicable scenarios."
+
+log_onexit cleanup
+
+mnttab_dev=$(find_mnttab_dev)
+vfstab_dev=$(find_vfstab_dev)
+saved_dump_dev=$(save_dump_dev)
+dump_dev=${disk}s${SLICE3}
+
+create_pool "$TESTPOOL" "${disk}s${SLICE0}"
+log_must poolexists "$TESTPOOL"
+
+create_pool "$TESTPOOL1" "${disk}s${SLICE1}"
+log_must poolexists "$TESTPOOL1"
+log_mustnot $ZPOOL add -f "$TESTPOOL" ${disk}s${SLICE1}
+
+log_mustnot $ZPOOL add -f "$TESTPOOL" $mnttab_dev
+
+log_mustnot $ZPOOL add -f "$TESTPOOL" $vfstab_dev
+
+log_must $ECHO "y" | $NEWFS /dev/dsk/$dump_dev > /dev/null 2>&1
+log_must $DUMPADM -u -d /dev/dsk/$dump_dev > /dev/null
+log_mustnot $ZPOOL add -f "$TESTPOOL" $dump_dev
+
+log_pass "'zpool add' should fail with inapplicable scenarios."
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/usr/src/test/zfs-tests/tests/functional/cli_root/zpool_add/zpool_add_006_pos.ksh	Wed Dec 05 22:04:50 2012 -0500
@@ -0,0 +1,153 @@
+#!/bin/ksh -p
+#
+# CDDL HEADER START
+#
+# The contents of this file are subject to the terms of the
+# Common Development and Distribution License (the "License").
+# You may not use this file except in compliance with the License.
+#
+# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
+# or http://www.opensolaris.org/os/licensing.
+# See the License for the specific language governing permissions
+# and limitations under the License.
+#
+# When distributing Covered Code, include this CDDL HEADER in each
+# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
+# If applicable, add the following below this CDDL 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.
+#
+. $STF_SUITE/include/libtest.shlib
+. $STF_SUITE/tests/functional/cli_root/zpool_add/zpool_add.kshlib
+
+#
+# DESCRIPTION:
+# 'zpool add [-f]' can add large numbers of file-in-zfs-filesystem-based vdevs
+# to the specified pool without any errors.
+#
+# STRATEGY:
+# 1. Create assigned number of files in ZFS filesystem as vdevs and use the first
+# file to create a pool
+# 2. Add other vdevs to the pool should get success
+# 3  Fill in the filesystem and create a partially written file
+# as vdev
+# 4. Add the new file into the pool should be failed.
+#
+
+verify_runnable "global"
+
+function cleanup
+{
+	poolexists $TESTPOOL1 && \
+		destroy_pool $TESTPOOL1
+
+	datasetexists $TESTPOOL/$TESTFS && \
+		log_must $ZFS destroy -f $TESTPOOL/$TESTFS
+	poolexists $TESTPOOL && \
+		destroy_pool $TESTPOOL
+
+	if [[ -d $TESTDIR ]]; then
+		log_must $RM -rf $TESTDIR
+	fi
+
+	partition_cleanup
+}
+
+
+#
+# Create a pool and fs on the assigned disk, and dynamically create large
+# numbers of files as vdevs.(the default value is <VDEVS_NUM>)
+# the first file will be used to create a pool for other vdevs to be added into
+#
+
+function setup_vdevs #<disk>
+{
+	typeset disk=$1
+	typeset -l count=0
+	typeset -l largest_num=0
+	typeset -l slicesize=0
+	typeset vdev=""
+
+
+	#
+	# Get disk size for zfs filesystem
+	#
+	create_pool foo $disk
+	log_must $ZFS create foo/fs
+	typeset -l fs_size=$(get_prop "available" foo/fs)
+	destroy_pool foo
+
+	#64m is the minmum size for pool
+	(( largest_num = fs_size / (1024 * 1024 * 64) ))
+	if (( largest_num < $VDEVS_NUM )); then
+		# minus $largest_num/40 to leave 2.5% space for metadata.
+		(( vdevs_num=largest_num - largest_num/40 ))
+		file_size=64
+		vdev=$disk
+	else
+		vdevs_num=$VDEVS_NUM
+		file_size=$((fs_size / (1024 * 1024 * \
+		    (vdevs_num + vdevs_num / 40))))
+		if (( file_size > FILE_SIZE )); then
+			file_size=$FILE_SIZE
+		fi
+		# plus $vdevs_num/40 to provide enough space for metadata.
+		(( slice_size = file_size * (vdevs_num + vdevs_num/40) ))
+		set_partition 0 "" ${slice_size}m $disk
+		vdev=${disk}s0
+        fi
+
+	create_pool $TESTPOOL $vdev
+	[[ -d $TESTDIR ]] && \
+		log_must $RM -rf $TESTDIR
+        log_must $MKDIR -p $TESTDIR
+        log_must $ZFS create $TESTPOOL/$TESTFS
+        log_must $ZFS set mountpoint=$TESTDIR $TESTPOOL/$TESTFS
+
+	# Create a pool first using the first file, and make subsequent files
+	# ready as vdevs to add to the pool
+
+	log_must $MKFILE ${file_size}m ${TESTDIR}/file.$count
+	create_pool "$TESTPOOL1" "${TESTDIR}/file.$count"
+	log_must poolexists "$TESTPOOL1"
+
+	while (( count < vdevs_num )); do # minus 1 to avoid space non-enough
+		(( count = count + 1 ))
+		log_must $MKFILE ${file_size}m ${TESTDIR}/file.$count
+		vdevs_list="$vdevs_list ${TESTDIR}/file.$count"
+	done
+}
+
+log_assert " 'zpool add [-f]' can add large numbers of vdevs to the specified" \
+	   " pool without any errors."
+log_onexit cleanup
+
+if [[ $DISK_ARRAY_NUM == 0 ]]; then
+        disk=$DISK
+else
+        disk=$DISK0
+fi
+
+vdevs_list=""
+vdevs_num=$VDEVS_NUM
+file_size=$FILE_SIZE
+
+setup_vdevs $disk
+log_must $ZPOOL add -f "$TESTPOOL1" $vdevs_list
+log_must iscontained "$TESTPOOL1" "$vdevs_list"
+
+(( file_size = file_size * (vdevs_num/40 + 1 ) ))
+log_mustnot $MKFILE ${file_size}m ${TESTDIR}/broken_file
+
+log_mustnot $ZPOOL add -f "$TESTPOOL1" ${TESTDIR}/broken_file
+log_mustnot iscontained "$TESTPOOL1" "${TESTDIR}/broken_file"
+
+log_pass "'zpool successfully add [-f]' can add large numbers of vdevs to the" \
+	 "specified pool without any errors."
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/usr/src/test/zfs-tests/tests/functional/cli_root/zpool_add/zpool_add_007_neg.ksh	Wed Dec 05 22:04:50 2012 -0500
@@ -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 2009 Sun Microsystems, Inc.  All rights reserved.
+# Use is subject to license terms.
+#
+. $STF_SUITE/include/libtest.shlib
+. $STF_SUITE/tests/functional/cli_root/zpool_add/zpool_add.kshlib
+
+#
+# DESCRIPTION:
+#       'zpool add' should return an error with badly-formed parameters,
+#
+# STRATEGY:
+#	1. Create an array of parameters
+#	2. For each parameter in the array, execute 'zpool add'
+#	3. Verify an error is returned.
+#
+
+verify_runnable "global"
+
+function cleanup
+{
+	poolexists "$TESTPOOL" && \
+		destroy_pool "$TESTPOOL"
+
+	partition_cleanup
+}
+
+log_assert "'zpool add' should return an error with badly-formed parameters."
+
+log_onexit cleanup
+
+set -A args "" "-f" "-n" "-?" "-nf" "-fn" "-f -n" "--f" "-blah" \
+	"-? $TESTPOOL ${disk}s${SLICE1}"
+
+create_pool "$TESTPOOL" "${disk}s${SLICE0}"
+log_must poolexists "$TESTPOOL"
+
+typeset -i i=0
+while (( $i < ${#args[*]} )); do
+	log_mustnot $ZPOOL add ${args[i]}
+	((i = i + 1))
+done
+
+log_pass "'zpool add' badly formed parameters fail as expected."
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/usr/src/test/zfs-tests/tests/functional/cli_root/zpool_add/zpool_add_008_neg.ksh	Wed Dec 05 22:04:50 2012 -0500
@@ -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.
+#
+. $STF_SUITE/include/libtest.shlib
+. $STF_SUITE/tests/functional/cli_root/zpool_add/zpool_add.kshlib
+
+#
+# DESCRIPTION:
+#       'zpool add' should return an error with nonexistent pools or vdevs
+#
+# STRATEGY:
+#	1. Create an array of parameters which contains nonexistent pools/vdevs
+#	2. For each parameter in the array, execute 'zpool add'
+#	3. Verify an error is returned
+#
+
+verify_runnable "global"
+
+function cleanup
+{
+
+        poolexists "$TESTPOOL" && \
+                destroy_pool "$TESTPOOL"
+
+	partition_cleanup
+}
+
+log_assert "'zpool add' should return an error with nonexistent pools and vdevs"
+
+log_onexit cleanup
+
+set -A args "" "-f nonexistent_pool ${disk}s${SLICE1}" \
+	"-f $TESTPOOL nonexistent_vdev"
+
+create_pool "$TESTPOOL" "${disk}s${SLICE0}"
+log_must poolexists "$TESTPOOL"
+
+typeset -i i=0
+while (( $i < ${#args[*]} )); do
+	log_mustnot $ZPOOL add ${args[i]}
+	((i = i + 1))
+done
+
+log_pass "'zpool add' with nonexistent pools and vdevs fail as expected."
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/usr/src/test/zfs-tests/tests/functional/cli_root/zpool_add/zpool_add_009_neg.ksh	Wed Dec 05 22:04:50 2012 -0500
@@ -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.
+#
+. $STF_SUITE/include/libtest.shlib
+. $STF_SUITE/tests/functional/cli_root/zpool_add/zpool_add.kshlib
+
+#
+# DESCRIPTION:
+#       'zpool add' should return fail if vdevs are the same or vdev is
+# contained in the given pool
+#
+# STRATEGY:
+#	1. Create a storage pool
+#	2. Add the two same devices to pool A
+#	3. Add the device in pool A to pool A again
+#
+
+verify_runnable "global"
+
+function cleanup
+{
+
+        poolexists "$TESTPOOL" && \
+                destroy_pool "$TESTPOOL"
+
+	partition_cleanup
+
+}
+
+log_assert "'zpool add' should fail if vdevs are the same or vdev is " \
+	"contained in the given pool."
+
+log_onexit cleanup
+
+create_pool "$TESTPOOL" "${disk}s${SLICE0}"
+log_must poolexists "$TESTPOOL"
+
+log_mustnot $ZPOOL add -f "$TESTPOOL" ${disk}s${SLICE1} ${disk}s${SLICE1}
+log_mustnot $ZPOOL add -f "$TESTPOOL" ${disk}s${SLICE0}
+
+log_pass "'zpool add' get fail as expected if vdevs are the same or vdev is " \
+	"contained in the given pool."
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/usr/src/test/zfs-tests/tests/functional/cli_root/zpool_attach/Makefile	Wed Dec 05 22:04:50 2012 -0500
@@ -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) 2012 by Delphix. All rights reserved.
+#
+
+include $(SRC)/Makefile.master
+
+ROOTOPTPKG = $(ROOT)/opt/zfs-tests
+TESTDIR = $(ROOTOPTPKG)/tests/functional/cli_root/zpool_attach
+
+PROGS = cleanup \
+	setup \
+	zpool_attach_001_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	Thu Jan 01 00:00:00 1970 +0000
+++ b/usr/src/test/zfs-tests/tests/functional/cli_root/zpool_attach/cleanup.ksh	Wed Dec 05 22:04:50 2012 -0500
@@ -0,0 +1,32 @@
+#!/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.
+#
+
+. $STF_SUITE/include/libtest.shlib
+
+verify_runnable "global"
+
+default_cleanup
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/usr/src/test/zfs-tests/tests/functional/cli_root/zpool_attach/setup.ksh	Wed Dec 05 22:04:50 2012 -0500
@@ -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 2009 Sun Microsystems, Inc.  All rights reserved.
+# Use is subject to license terms.
+#
+
+. $STF_SUITE/include/libtest.shlib
+
+verify_runnable "global"
+verify_disk_count "$DISKS" 2
+
+DISK=${DISKS%% *}
+
+default_mirror_setup $DISKS
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/usr/src/test/zfs-tests/tests/functional/cli_root/zpool_attach/zpool_attach_001_neg.ksh	Wed Dec 05 22:04:50 2012 -0500
@@ -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.
+#
+. $STF_SUITE/include/libtest.shlib
+
+#
+# DESCRIPTION:
+# Executing 'zpool attach' command with bad options fails.
+#
+# STRATEGY:
+# 1. Create an array of badly formed 'zpool attach' options.
+# 2. Execute each element of the array.
+# 3. Verify an error code is returned.
+#
+
+verify_runnable "global"
+
+DISKLIST=$(get_disklist $TESTPOOL)
+
+set -A args "" "-f" "-?" "-z fakepool" "-f fakepool" "-ev fakepool" "fakepool" \
+	"$TESTPOOL" "-t $TESTPOOL/$TESTFS" "-t $TESTPOOL/$TESTFS $DISKLIST" \
+	"$TESTPOOL/$TESTCTR" "-t $TESTPOOL/$TESTCTR/$TESTFS1" \
+	"$TESTPOOL/$TESTCTR $DISKLIST" "-t $TESTPOOL/$TESTVOL" \
+	"$TESTPOOL/$TESTCTR/$TESTFS1 $DISKLIST" \
+	"$TESTPOOL/$TESTVOL $DISKLIST" \
+	"$DISKLIST" \
+	"fakepool fakedevice" "fakepool fakedevice fakenewdevice" \
+	"$TESTPOOL fakedevice" "$TESTPOOL $DISKLIST" \
+	"$TESTPOOL fakedevice fakenewdevice fakenewdevice" \
+        "-f $TESTPOOL" "-f $TESTPOOL/$TESTFS" "-f $TESTPOOL/$TESTFS $DISKLIST" \
+        "-f $TESTPOOL/$TESTCTR" "-f $TESTPOOL/$TESTCTR/$TESTFS1" \
+        "-f $TESTPOOL/$TESTCTR $DISKLIST" "-f $TESTPOOL/$TESTVOL" \
+        "-f $TESTPOOL/$TESTCTR/$TESTFS1 $DISKLIST" \
+        "-f $TESTPOOL/$TESTVOL $DISKLIST" \
+        "-f $DISKLIST" \
+	"-f fakepool fakedevice" "-f fakepool fakedevice fakenewdevice" \
+	"-f $TESTPOOL fakedevice fakenewdevice fakenewdevice" \
+	"-f $TESTPOOL fakedevice" "-f $TESTPOOL $DISKLIST"
+
+log_assert "Executing 'zpool attach' with bad options fails"
+
+if [[ -z $DISKLIST ]]; then
+	log_fail "DISKLIST is empty."
+fi
+
+typeset -i i=0
+
+while [[ $i -lt ${#args[*]} ]]; do
+
+	log_mustnot $ZPOOL attach ${args[$i]}
+
+	(( i = i + 1 ))
+done
+
+log_pass "'zpool attach' command with bad options failed as expected."
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/usr/src/test/zfs-tests/tests/functional/cli_root/zpool_clear/Makefile	Wed Dec 05 22:04:50 2012 -0500
@@ -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) 2012 by Delphix. All rights reserved.
+#
+
+include $(SRC)/Makefile.master
+
+ROOTOPTPKG = $(ROOT)/opt/zfs-tests
+TESTDIR = $(ROOTOPTPKG)/tests/functional/cli_root/zpool_clear
+
+PROGS = cleanup \
+	setup \
+	zpool_clear_001_pos \
+	zpool_clear_002_neg \
+	zpool_clear_003_neg
+
+FILES = zpool_clear.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	Thu Jan 01 00:00:00 1970 +0000
+++ b/usr/src/test/zfs-tests/tests/functional/cli_root/zpool_clear/cleanup.ksh	Wed Dec 05 22:04:50 2012 -0500
@@ -0,0 +1,30 @@
+#!/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.
+#
+
+. $STF_SUITE/include/libtest.shlib
+
+default_cleanup
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/usr/src/test/zfs-tests/tests/functional/cli_root/zpool_clear/setup.ksh	Wed Dec 05 22:04:50 2012 -0500
@@ -0,0 +1,32 @@
+#!/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.
+#
+
+. $STF_SUITE/include/libtest.shlib
+
+DISK=${DISKS%% *}
+
+default_setup $DISK
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/usr/src/test/zfs-tests/tests/functional/cli_root/zpool_clear/zpool_clear.cfg	Wed Dec 05 22:04:50 2012 -0500
@@ -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) 2012 by Delphix. All rights reserved.
+#
+
+export FILESIZE=100m
+export BLOCKSZ=$(( 1024 * 1024 ))
+export NUM_WRITES=40
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/usr/src/test/zfs-tests/tests/functional/cli_root/zpool_clear/zpool_clear_001_pos.ksh	Wed Dec 05 22:04:50 2012 -0500
@@ -0,0 +1,217 @@
+#!/bin/ksh -p
+#
+# CDDL HEADER START
+#
+# The contents of this file are subject to the terms of the
+# Common Development and Distribution License (the "License").
+# You may not use this file except in compliance with the License.
+#
+# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
+# or http://www.opensolaris.org/os/licensing.
+# See the License for the specific language governing permissions
+# and limitations under the License.
+#
+# When distributing Covered Code, include this CDDL HEADER in each
+# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
+# If applicable, add the following below this CDDL HEADER, with the
+# fields enclosed by brackets "[]" replaced with your own identifying
+# information: Portions Copyright [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.
+#
+
+. $STF_SUITE/include/libtest.shlib
+. $STF_SUITE/tests/functional/cli_root/zpool_clear/zpool_clear.cfg
+
+#
+# DESCRIPTION:
+# Verify 'zpool clear' can clear pool errors.
+#
+# STRATEGY:
+# 1. Create various configuration pools
+# 2. Make errors to pool
+# 3. Use zpool clear to clear errors
+# 4. Verify the errors has been cleared.
+#
+
+verify_runnable "global"
+
+function cleanup
+{
+        poolexists $TESTPOOL1 && \
+                log_must $ZPOOL destroy -f $TESTPOOL1
+
+        for file in `$LS $TESTDIR/file.*`; do
+		log_must $RM -f $file
+        done
+}
+
+
+log_assert "Verify 'zpool clear' can clear errors of a storage pool."
+log_onexit cleanup
+
+#make raw files to create various configuration pools
+typeset -i i=0
+while (( i < 3 )); do
+	log_must $MKFILE $FILESIZE $TESTDIR/file.$i
+
+	(( i = i + 1 ))
+done
+
+fbase=$TESTDIR/file
+set -A poolconf "mirror $fbase.0 $fbase.1 $fbase.2" \
+                "raidz1 $fbase.0 $fbase.1 $fbase.2" \
+                "raidz2 $fbase.0 $fbase.1 $fbase.2"
+
+function check_err # <pool> [<vdev>]
+{
+	typeset pool=$1
+	shift
+	if (( $# > 0 )); then
+		typeset	checkvdev=$1
+	else
+		typeset checkvdev=""
+	fi
+	typeset -i errnum=0
+	typeset c_read=0
+	typeset c_write=0
+	typeset c_cksum=0
+	typeset tmpfile=/var/tmp/file.$$
+	typeset healthstr="pool '$pool' is healthy"
+	typeset output="`$ZPOOL status -x $pool`"
+
+	[[ "$output" ==  "$healthstr" ]] && return $errnum
+
+	$ZPOOL status -x $pool | $GREP -v "^$" | $GREP -v "pool:" \
+			| $GREP -v "state:" | $GREP -v "config:" \
+			| $GREP -v "errors:" > $tmpfile
+	typeset line
+	typeset -i fetchbegin=1
+	while read line; do
+		if (( $fetchbegin != 0 )); then
+                        $ECHO $line | $GREP "NAME" >/dev/null 2>&1
+                        (( $? == 0 )) && (( fetchbegin = 0 ))
+                         continue
+                fi
+
+		if [[ -n $checkvdev ]]; then
+			$ECHO $line | $GREP $checkvdev >/dev/null 2>&1
+			(( $? != 0 )) && continue
+			c_read=`$ECHO $line | $AWK '{print $3}'`
+			c_write=`$ECHO $line | $AWK '{print $4}'`
+			c_cksum=`$ECHO $line | $AWK '{print $5}'`
+			if [ $c_read != 0 ] || [ $c_write != 0 ] || \
+			    [ $c_cksum != 0 ]
+			then
+				(( errnum = errnum + 1 ))
+			fi
+			break
+		fi
+
+		c_read=`$ECHO $line | $AWK '{print $3}'`
+		c_write=`$ECHO $line | $AWK '{print $4}'`
+		c_cksum=`$ECHO $line | $AWK '{print $5}'`
+		if [ $c_read != 0 ] || [ $c_write != 0 ] || \
+		    [ $c_cksum != 0 ]
+		then
+			(( errnum = errnum + 1 ))
+		fi
+	done <$tmpfile
+
+	return $errnum
+}
+
+function do_testing #<clear type> <vdevs>
+{
+	typeset FS=$TESTPOOL1/fs
+	typeset file=/$FS/f
+	typeset type=$1
+	shift
+	typeset vdev="$@"
+
+	log_must $ZPOOL create -f $TESTPOOL1 $vdev
+	log_must $ZFS create $FS
+	#
+	# Fully fill up the zfs filesystem in order to make data block errors
+	# zfs filesystem
+	#
+	typeset -i ret=0
+	typeset -i i=0
+	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_fail "$FILE_WRITE fails to fully fill up the $FS."
+
+	#
+	#Make errors to the testing pool by overwrite the vdev device with
+	#/usr/bin/dd command. We donot want to have a full overwrite. That
+	#may cause the system panic. So, we should skip the vdev label space.
+	#
+	(( i = $RANDOM % 3 ))
+	typeset -i wcount=0
+	typeset -i size
+	case $FILESIZE in
+		*g|*G)
+			(( size = ${FILESIZE%%[g|G]} ))
+			(( wcount = size*1024*1024 - 512 ))
+			;;
+		*m|*M)
+			(( size = ${FILESIZE%%[m|M]} ))
+			(( wcount = size*1024 - 512 ))
+			;;
+		*k|*K)
+			(( size = ${FILESIZE%%[k|K]} ))
+			(( wcount = size - 512 ))
+			;;
+		*)
+			(( wcount = FILESIZE/1024 - 512 ))
+			;;
+	esac
+	$DD if=/dev/zero of=$fbase.$i seek=512 bs=1024 count=$wcount conv=notrunc \
+			> /dev/null 2>&1
+	log_must $SYNC
+	log_must $ZPOOL scrub $TESTPOOL1
+	# Wait for the completion of scrub operation
+	while is_pool_scrubbing $TESTPOOL1; do
+		$SLEEP 1
+	done
+
+	check_err $TESTPOOL1 && \
+		log_fail "No error generated."
+	if [[ $type == "device" ]]; then
+		log_must $ZPOOL clear $TESTPOOL1 $fbase.$i
+		! check_err $TESTPOOL1 $fbase.$i && \
+		    log_fail "'zpool clear' fails to clear error for $fbase.$i device."
+	fi
+
+	if [[ $type == "pool" ]]; then
+		log_must $ZPOOL clear $TESTPOOL1
+		! check_err $TESTPOOL1 && \
+		    log_fail "'zpool clear' fails to clear error for pool $TESTPOOL1."
+	fi
+
+	log_must $ZPOOL destroy $TESTPOOL1
+}
+
+log_note "'zpool clear' clears leaf-device error."
+for devconf in "${poolconf[@]}"; do
+	do_testing "device" $devconf
+done
+log_note "'zpool clear' clears top-level pool error."
+for devconf in "${poolconf[@]}"; do
+	do_testing "pool" $devconf
+done
+
+log_pass "'zpool clear' clears pool errors as expected."
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/usr/src/test/zfs-tests/tests/functional/cli_root/zpool_clear/zpool_clear_002_neg.ksh	Wed Dec 05 22:04:50 2012 -0500
@@ -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) 2012 by Delphix. All rights reserved.
+#
+
+. $STF_SUITE/include/libtest.shlib
+. $STF_SUITE/tests/functional/cli_root/zpool_clear/zpool_clear.cfg
+
+#
+# DESCRIPTION:
+# A badly formed parameter passed to 'zpool clear' should
+# return an error.
+#
+# STRATEGY:
+# 1. Create an array containing bad 'zpool clear' parameters.
+# 2. For each element, execute the sub-command.
+# 3. Verify it returns an error.
+#
+
+verify_runnable "global"
+
+function cleanup
+{
+	poolexists $TESTPOOL1 && \
+		log_must $ZPOOL destroy -f $TESTPOOL1
+	[[ -e $file ]] && \
+		log_must $RM -f $file
+}
+
+log_assert "Execute 'zpool clear' using invalid parameters."
+log_onexit cleanup
+
+# Create another pool for negative testing, which clears pool error
+# with vdev device not in the pool vdev devices.
+file=$TESTDIR/file.$$
+log_must $MKFILE $FILESIZE $file
+log_must $ZPOOL create $TESTPOOL1 $file
+
+set -A args "" "-?" "--%" "-1234567" "0.0001" "0.7644" "-0.7644" \
+		"blah" "blah $DISK" "$TESTPOOL c0txdx" "$TESTPOOL $file" \
+		"$TESTPOOL c0txdx blah" "$TESTPOOL $file blah"
+
+typeset -i i=0
+while (( i < ${#args[*]} )); do
+	log_mustnot $ZPOOL clear ${args[i]}
+
+	((i = i + 1))
+done
+
+log_pass "Invalid parameters to 'zpool clear' fail as expected."
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/usr/src/test/zfs-tests/tests/functional/cli_root/zpool_clear/zpool_clear_003_neg.ksh	Wed Dec 05 22:04:50 2012 -0500
@@ -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) 2012 by Delphix. All rights reserved.
+#
+
+. $STF_SUITE/include/libtest.shlib
+. $STF_SUITE/tests/functional/cli_root/zpool_clear/zpool_clear.cfg
+
+#
+# DESCRIPTION:
+# Verify 'zpool clear' cannot used to spare device.
+#
+# STRATEGY:
+# 1. Create a spare pool.
+# 2. Try to clear the spare device
+# 3. Verify it returns an error.
+#
+
+verify_runnable "global"
+
+function cleanup
+{
+        poolexists $TESTPOOL1 && \
+                log_must $ZPOOL destroy -f $TESTPOOL1
+
+        for file in `$LS $TESTDIR/file.*`; do
+		log_must $RM -f $file
+        done
+}
+
+
+log_assert "Verify 'zpool clear' cannot clear error for spare device."
+log_onexit cleanup
+
+#make raw files to create a spare pool
+typeset -i i=0
+while (( i < 5 )); do
+	log_must $MKFILE $FILESIZE $TESTDIR/file.$i
+
+	(( i = i + 1 ))
+done
+log_must $ZPOOL create $TESTPOOL1 raidz $TESTDIR/file.1 $TESTDIR/file.2 \
+	$TESTDIR/file.3 spare $TESTDIR/file.4
+
+log_mustnot $ZPOOL clear $TESTPOOL1 $TESTDIR/file.4
+
+log_pass "'zpool clear' works on spare device failed as expected."
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/usr/src/test/zfs-tests/tests/functional/cli_root/zpool_create/Makefile	Wed Dec 05 22:04:50 2012 -0500
@@ -0,0 +1,70 @@
+#
+# 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) 2012 by Delphix. All rights reserved.
+#
+
+include $(SRC)/Makefile.master
+
+ROOTOPTPKG = $(ROOT)/opt/zfs-tests
+TESTDIR = $(ROOTOPTPKG)/tests/functional/cli_root/zpool_create
+
+PROGS = cleanup \
+	setup \
+	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
+
+FILES = zpool_create.cfg \
+	zpool_create.shlib
+
+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	Thu Jan 01 00:00:00 1970 +0000
+++ b/usr/src/test/zfs-tests/tests/functional/cli_root/zpool_create/cleanup.ksh	Wed Dec 05 22:04:50 2012 -0500
@@ -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) 2012 by Delphix. All rights reserved.
+#
+
+. $STF_SUITE/include/libtest.shlib
+. $STF_SUITE/tests/functional/cli_root/zpool_create/zpool_create.shlib
+
+clean_blockfile "$TESTDIR $TESTDIR0 $TESTDIR1"
+
+cleanup_devices $DISKS
+
+log_pass
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/usr/src/test/zfs-tests/tests/functional/cli_root/zpool_create/setup.ksh	Wed Dec 05 22:04:50 2012 -0500
@@ -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 2009 Sun Microsystems, Inc.  All rights reserved.
+# Use is subject to license terms.
+#
+
+#
+# Copyright (c) 2012 by Delphix. All rights reserved.
+#
+
+. $STF_SUITE/include/libtest.shlib
+. $STF_SUITE/tests/functional/cli_root/zpool_create/zpool_create.shlib
+
+verify_runnable "global"
+
+if ! $(is_physical_device $DISKS) ; then
+	log_unsupported "This directory cannot be run on raw files."
+fi
+
+if [[ -n $DISK ]]; then
+	#
+        # Use 'zpool create' to clean up the infomation in
+        # in the given disk to avoid slice overlapping.
+        #
+	cleanup_devices $DISK
+
+        partition_disk $SIZE $DISK 7
+else
+	for disk in `$ECHO $DISKSARRAY`; do
+		cleanup_devices $disk
+
+		partition_disk $SIZE $disk 7
+	done
+fi
+
+log_pass
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/usr/src/test/zfs-tests/tests/functional/cli_root/zpool_create/zpool_create.cfg	Wed Dec 05 22:04:50 2012 -0500
@@ -0,0 +1,102 @@
+#
+# CDDL HEADER START
+#
+# The contents of this file are subject to the terms of the
+# Common Development and Distribution License (the "License").
+# You may not use this file except in compliance with the License.
+#
+# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
+# or http://www.opensolaris.org/os/licensing.
+# See the License for the specific language governing permissions
+# and limitations under the License.
+#
+# When distributing Covered Code, include this CDDL HEADER in each
+# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
+# If applicable, add the following below this CDDL 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.
+#
+
+. $STF_SUITE/include/libtest.shlib
+
+export DISK_ARRAY_NUM=0
+export DISK_ARRAY_LIMIT=4
+export DISKSARRAY=""
+
+#
+# Variables for zpool_create_005
+#
+export VDEVS_NUM=300
+export FILE_SIZE=100 #100mb
+export MD_OVERHEAD=10 # 10%
+export POOL_MINSIZE=64  # the minimum size(64m) to create a storage pool
+
+function set_disks
+{
+        typeset -a disk_array=($(find_disks $DISKS))
+
+	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 ))
+			(( i>$DISK_ARRAY_LIMIT )) && break
+		done
+		export DISK_ARRAY_NUM=$i
+		export DISKSARRAY
+	fi
+}
+
+set_disks
+
+export FILESIZE="100m"
+export FILESIZE1="150m"
+export SIZE="200m"
+export SIZE1="250m"
+export SLICE0=0
+export SLICE1=1
+export SLICE2=2
+export SLICE3=3
+export SLICE4=4
+export SLICE5=5
+export SLICE6=6
+export SLICE7=7
+
+export FILEDISK=filedisk_create
+export FILEDISK0=filedisk0_create
+export FILEDISK1=filedisk1_create
+export FILEDISK2=filedisk2_create
+export FILEDISK3=filedisk3_create
+
+export BYND_MAX_NAME="byondmaxnamelength\
+012345678901234567890123456789\
+012345678901234567890123456789\
+012345678901234567890123456789\
+012345678901234567890123456789\
+012345678901234567890123456789\
+012345678901234567890123456789\
+012345678901234567890123456789\
+012345678901234567890123456789"
+
+export TOOSMALL="toosmall"
+
+export TESTPOOL4=testpool4.create
+export TESTPOOL5=testpool5.create
+export TESTPOOL6=testpool6.create
+
+export CPATH="/var/tmp/cachefile.create"
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/usr/src/test/zfs-tests/tests/functional/cli_root/zpool_create/zpool_create.shlib	Wed Dec 05 22:04:50 2012 -0500
@@ -0,0 +1,142 @@
+#
+# CDDL HEADER START
+#
+# The contents of this file are subject to the terms of the
+# Common Development and Distribution License (the "License").
+# You may not use this file except in compliance with the License.
+#
+# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
+# or http://www.opensolaris.org/os/licensing.
+# See the License for the specific language governing permissions
+# and limitations under the License.
+#
+# When distributing Covered Code, include this CDDL HEADER in each
+# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
+# If applicable, add the following below this CDDL 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) 2012 by Delphix. All rights reserved.
+#
+
+. $STF_SUITE/include/libtest.shlib
+. $STF_SUITE/tests/functional/cli_root/zpool_create/zpool_create.cfg
+
+#
+# Given a pool vdevs list, create the pool,verify the created pool,
+# and destroy the pool
+# $1, pool name
+# $2, pool type, mirror, raidz, or none
+# $3, vdevs list
+#
+function create_pool_test
+{
+	typeset pool=$1
+	typeset keywd=$2
+	typeset vdevs
+	eval "typeset -a diskarray=($3)"
+
+	for vdevs in "${diskarray[@]}";do
+		create_pool $pool $keywd $vdevs
+		log_must poolexists $pool
+		destroy_pool $pool
+	done
+}
+
+#
+# Create a ufs file system and make a file within the file
+# system for storage pool vdev
+# $1, file size
+# $2, file name
+# $3, disk name to create ufs file system
+#
+function create_blockfile
+{
+	typeset size=$1
+	typeset file=$2
+	typeset disk=$3
+	typeset dir=`$DIRNAME $file`
+
+	if [[ -d $dir ]]; then
+		ismounted $dir ufs
+		(( $? == 0 )) && \
+			log_must $UMOUNT -f $dir
+	else
+		log_must $MKDIR -p $dir
+	fi
+
+	$ECHO "y" | $NEWFS /dev/rdsk/$disk >/dev/null 2>&1
+	(( $? != 0 )) &&
+		log_fail "Create ufs file system fail."
+
+        log_must $MOUNT /dev/dsk/$disk $dir
+        log_must $MKFILE $size $file
+}
+
+#
+# Umount the ufs filesystem and remove the mountpoint
+# $1, the mount point
+#
+function clean_blockfile
+{
+	typeset dirs=$1
+
+	for dir in $dirs; do
+		if [[ -d $dir ]]; then
+			if ismounted $dir ufs; then
+				typeset dev=$($DF -lhF ufs | $GREP "$dir" | \
+					$AWK '{print $1}')
+				log_must $UMOUNT -f $dir
+				create_pool ${TESTPOOL}.tmp $dev
+				destroy_pool ${TESTPOOL}.tmp
+			fi
+			log_must $RM -rf $dir
+		fi
+	done
+}
+
+#
+# Find the storage device in /etc/vfstab
+#
+function find_vfstab_dev
+{
+	typeset vfstab="/etc/vfstab"
+	typeset tmpfile="/tmp/vfstab.tmp"
+	typeset vfstabdev
+	typeset vfstabdevs=""
+	typeset line
+
+	$CAT $vfstab | $GREP "^/dev/dsk" >$tmpfile
+	while read -r line
+	do
+		vfstabdev=`$ECHO "$line" | $AWK '{print $1}'`
+		vfstabdev=${vfstabdev%%:}
+		vfstabdevs="$vfstabdev $vfstabdevs"
+	done <$tmpfile
+
+	$RM -f $tmpfile
+	$ECHO $vfstabdevs
+}
+
+#
+# Save the systme current dump device configuration
+#
+function save_dump_dev
+{
+
+	typeset dumpdev
+	typeset fnd="Dump device"
+
+	dumpdev=`$DUMPADM | $GREP "$fnd" | $CUT -f2 -d : | \
+		$AWK '{print $1}'`
+	$ECHO $dumpdev
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/usr/src/test/zfs-tests/tests/functional/cli_root/zpool_create/zpool_create_001_pos.ksh	Wed Dec 05 22:04:50 2012 -0500
@@ -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) 2012 by Delphix. All rights reserved.
+#
+
+. $STF_SUITE/include/libtest.shlib
+. $STF_SUITE/tests/functional/cli_root/zpool_create/zpool_create.shlib
+
+#
+# DESCRIPTION:
+# 'zpool create <pool> <vspec> ...' can successfully create a
+# new pool with a name in ZFS namespace.
+#
+# STRATEGY:
+# 1. Create storage pools with a name in ZFS namespace with different
+# vdev specs.
+# 2. Verify the pool created successfully
+#
+
+verify_runnable "global"
+
+function cleanup
+{
+	poolexists $TESTPOOL && destroy_pool $TESTPOOL
+
+	clean_blockfile "$TESTDIR0 $TESTDIR1"
+
+	if [[ -n $DISK ]]; then
+		partition_disk $SIZE $DISK 7
+	else
+		typeset disk=""
+		for disk in $DISK0 $DISK1; do
+			partition_disk $SIZE $disk 7
+		done
+	fi
+}
+
+log_assert "'zpool create <pool> <vspec> ...' can successfully create" \
+	"a new pool with a name in ZFS namespace."
+
+log_onexit cleanup
+
+set -A keywords "" "mirror" "raidz" "raidz1"
+
+case $DISK_ARRAY_NUM in
+0|1)
+	typeset disk=""
+	if (( $DISK_ARRAY_NUM == 0 )); then
+		disk=$DISK
+	else
+		disk=$DISK0
+	fi
+	create_blockfile $FILESIZE $TESTDIR0/$FILEDISK0 ${disk}s${SLICE5}
+        create_blockfile $FILESIZE $TESTDIR1/$FILEDISK1 ${disk}s${SLICE6}
+
+	pooldevs="${disk}s${SLICE0} \
+                  /dev/dsk/${disk}s${SLICE0} \
+                  \"${disk}s${SLICE0} ${disk}s${SLICE1}\" \
+                  $TESTDIR0/$FILEDISK0"
+	raidzdevs="\"/dev/dsk/${disk}s${SLICE0} ${disk}s${SLICE1}\" \
+                   \"${disk}s${SLICE0} ${disk}s${SLICE1} ${disk}s${SLICE3}\" \
+                   \"${disk}s${SLICE0} ${disk}s${SLICE1} ${disk}s${SLICE3} \
+                     ${disk}s${SLICE4}\"\
+                   \"$TESTDIR0/$FILEDISK0 $TESTDIR1/$FILEDISK1\""
+	mirrordevs=$raidzdevs
+	;;
+2|*)
+	create_blockfile $FILESIZE $TESTDIR0/$FILEDISK0 ${DISK0}s${SLICE5}
+        create_blockfile $FILESIZE $TESTDIR1/$FILEDISK1 ${DISK1}s${SLICE5}
+
+	pooldevs="${DISK0}s${SLICE0}\
+                 \"/dev/dsk/${DISK0}s${SLICE0} ${DISK1}s${SLICE0}\" \
+                 \"${DISK0}s${SLICE0} ${DISK0}s${SLICE1} ${DISK1}s${SLICE1}\"\
+                 \"${DISK0}s${SLICE0} ${DISK1}s${SLICE0} ${DISK0}s${SLICE1}\
+                   ${DISK1}s${SLICE1}\" \
+                 \"$TESTDIR0/$FILEDISK0 $TESTDIR1/$FILEDISK1\""
+	raidzdevs="\"/dev/dsk/${DISK0}s${SLICE0} ${DISK1}s${SLICE0}\" \
+                 \"${DISK0}s${SLICE0} ${DISK0}s${SLICE1} ${DISK1}s${SLICE1}\"\
+                 \"${DISK0}s${SLICE0} ${DISK1}s${SLICE0} ${DISK0}s${SLICE1}\
+                   ${DISK1}s${SLICE1}\" \
+                 \"$TESTDIR0/$FILEDISK0 $TESTDIR1/$FILEDISK1\""
+	mirrordevs=$raidzdevs
+	;;
+esac
+
+typeset -i i=0
+while (( $i < ${#keywords[*]} )); do
+	case ${keywords[i]} in
+	"")
+		create_pool_test "$TESTPOOL" "${keywords[i]}" "$pooldevs";;
+	mirror)
+		create_pool_test "$TESTPOOL" "${keywords[i]}" "$mirrordevs";;
+	raidz|raidz1)
+		create_pool_test "$TESTPOOL" "${keywords[i]}" "$raidzdevs" ;;
+	esac
+	(( i = i+1 ))
+done
+
+log_pass "'zpool create <pool> <vspec> ...' success."
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/usr/src/test/zfs-tests/tests/functional/cli_root/zpool_create/zpool_create_002_pos.ksh	Wed Dec 05 22:04:50 2012 -0500
@@ -0,0 +1,122 @@
+#!/bin/ksh -p
+#
+# CDDL HEADER START
+#
+# The contents of this file are subject to the terms of the
+# Common Development and Distribution License (the "License").
+# You may not use this file except in compliance with the License.
+#
+# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
+# or http://www.opensolaris.org/os/licensing.
+# See the License for the specific language governing permissions
+# and limitations under the License.
+#
+# When distributing Covered Code, include this CDDL HEADER in each
+# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
+# If applicable, add the following below this CDDL 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) 2012 by Delphix. All rights reserved.
+#
+
+. $STF_SUITE/include/libtest.shlib
+. $STF_SUITE/tests/functional/cli_root/zpool_create/zpool_create.shlib
+
+#
+# DESCRIPTION:
+# 'zpool create -f <pool> <vspec> ...' can successfully create a
+# new pool in some cases.
+#
+# STRATEGY:
+# 1. Prepare the scenarios for '-f' option
+# 2. Use -f to override the devices to create new pools
+# 3. Verify the pool created successfully
+#
+
+verify_runnable "global"
+
+function cleanup
+{
+	for pool in $TESTPOOL $TESTPOOL1 $TESTPOOL2 $TESTPOOL3 $TESTPOOL4 \
+		$TESTPOOL5 $TESTPOOL6
+	do
+		poolexists $pool && destroy_pool $pool
+	done
+
+	clean_blockfile "$TESTDIR0 $TESTDIR1"
+
+	for file in /var/tmp/$FILEDISK0 /var/tmp/$FILEDISK1 /var/tmp/$FILEDISK2
+	do
+		if [[ -e $file ]]; then
+			$RM -rf $file
+		fi
+	done
+
+	partition_disk $SIZE $disk 6
+}
+
+log_onexit cleanup
+
+log_assert "'zpool create -f <pool> <vspec> ...' can successfully create" \
+	"a new pool in some cases."
+
+if [[ -n $DISK ]]; then
+	disk=$DISK
+else
+	disk=$DISK0
+fi
+create_pool "$TESTPOOL" "${disk}s${SLICE0}"
+log_must $ECHO "y" | $NEWFS /dev/rdsk/${disk}s${SLICE1} >/dev/null 2>&1
+create_blockfile $FILESIZE $TESTDIR0/$FILEDISK0 ${disk}s${SLICE4}
+create_blockfile $FILESIZE1 $TESTDIR1/$FILEDISK1 ${disk}s${SLICE5}
+log_must $MKFILE $SIZE /var/tmp/$FILEDISK0
+log_must $MKFILE $SIZE /var/tmp/$FILEDISK1
+log_must $MKFILE $SIZE /var/tmp/$FILEDISK2
+
+log_must $ZPOOL export $TESTPOOL
+log_note "'zpool create' without '-f' will fail " \
+	"while device is belong to an exported pool."
+log_mustnot $ZPOOL create "$TESTPOOL1" "${disk}s${SLICE0}"
+create_pool "$TESTPOOL1" "${disk}s${SLICE0}"
+log_must poolexists $TESTPOOL1
+
+log_note "'zpool create' without '-f' will fail " \
+	"while device is using by an ufs filesystem."
+log_mustnot $ZPOOL create "$TESTPOOL2" "${disk}s${SLICE1}"
+create_pool "$TESTPOOL2" "${disk}s${SLICE1}"
+log_must poolexists $TESTPOOL2
+
+log_note "'zpool create' mirror without '-f' will fail " \
+	"while devices have different size."
+log_mustnot $ZPOOL create "$TESTPOOL3" "mirror" $TESTDIR0/$FILEDISK0 $TESTDIR1/$FILEDISK1
+create_pool "$TESTPOOL3" "mirror" $TESTDIR0/$FILEDISK0 $TESTDIR1/$FILEDISK1
+log_must poolexists $TESTPOOL3
+
+log_note "'zpool create' mirror without '-f' will fail " \
+	"while devices are of different types."
+log_mustnot $ZPOOL create "$TESTPOOL4" "mirror" /var/tmp/$FILEDISK0 \
+	${disk}s${SLICE3}
+create_pool "$TESTPOOL4" "mirror" /var/tmp/$FILEDISK0 ${disk}s${SLICE3}
+log_must poolexists $TESTPOOL4
+
+log_note "'zpool create' without '-f' will fail " \
+	"while device is part of potentially active pool."
+create_pool "$TESTPOOL5"  "mirror" /var/tmp/$FILEDISK1 \
+	/var/tmp/$FILEDISK2
+log_must $ZPOOL offline $TESTPOOL5 /var/tmp/$FILEDISK2
+log_must $ZPOOL export $TESTPOOL5
+log_mustnot $ZPOOL create "$TESTPOOL6" /var/tmp/$FILEDISK2
+create_pool $TESTPOOL6 /var/tmp/$FILEDISK2
+log_must poolexists $TESTPOOL6
+
+log_pass "'zpool create -f <pool> <vspec> ...' success."
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/usr/src/test/zfs-tests/tests/functional/cli_root/zpool_create/zpool_create_003_pos.ksh	Wed Dec 05 22:04:50 2012 -0500
@@ -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 2007 Sun Microsystems, Inc.  All rights reserved.
+# Use is subject to license terms.
+#
+
+#
+# Copyright (c) 2012 by Delphix. All rights reserved.
+#
+
+. $STF_SUITE/include/libtest.shlib
+. $STF_SUITE/tests/functional/cli_root/zpool_create/zpool_create.shlib
+
+#
+# DESCRIPTION:
+# 'zpool create -n <pool> <vspec> ...' can display the configuration without
+# actually creating the pool.
+#
+# STRATEGY:
+# 1. Create storage pool with -n option
+# 2. Verify the pool has not been actually created
+#
+
+verify_runnable "global"
+
+function cleanup
+{
+	[[ -e $tmpfile ]] && log_must $RM -f $tmpfile
+}
+
+tmpfile="/var/tmp/zpool_create_003.tmp$$"
+
+log_assert "'zpool create -n <pool> <vspec> ...' can display the configureation" \
+        "without actually creating the pool."
+
+log_onexit cleanup
+
+if [[ -n $DISK ]]; then
+        disk=$DISK
+else
+        disk=$DISK0
+fi
+
+#
+# Make sure disk is clean before we use it
+#
+create_pool $TESTPOOL ${disk}s${SLICE0} > $tmpfile
+destroy_pool $TESTPOOL
+
+$ZPOOL create -n  $TESTPOOL ${disk}s${SLICE0} > $tmpfile
+
+poolexists $TESTPOOL && \
+        log_fail "'zpool create -n <pool> <vspec> ...' fail."
+
+str="would create '$TESTPOOL' with the following layout:"
+$CAT $tmpfile | $GREP "$str" >/dev/null 2>&1
+(( $? != 0 )) && \
+        log_fail "'zpool create -n <pool> <vspec>...' is executed as unexpected."
+
+log_pass "'zpool create -n <pool> <vspec>...' success."
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/usr/src/test/zfs-tests/tests/functional/cli_root/zpool_create/zpool_create_004_pos.ksh	Wed Dec 05 22:04:50 2012 -0500
@@ -0,0 +1,181 @@
+#!/usr/bin/ksh
+#
+# CDDL HEADER START
+#
+# The contents of this file are subject to the terms of the
+# Common Development and Distribution License (the "License").
+# You may not use this file except in compliance with the License.
+#
+# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
+# or http://www.opensolaris.org/os/licensing.
+# See the License for the specific language governing permissions
+# and limitations under the License.
+#
+# When distributing Covered Code, include this CDDL HEADER in each
+# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
+# If applicable, add the following below this CDDL 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.
+#
+
+. $STF_SUITE/tests/functional/cli_root/zpool_create/zpool_create.shlib
+
+#
+# DESCRIPTION:
+# 'zpool create [-f]' can create a storage pool with large number of
+# file-in-zfs-filesystem-based vdevs without any errors.
+#
+# STRATEGY:
+# 1. Create assigned number of files in ZFS filesystem as vdevs
+# 2. Creating a new pool based on the vdevs should get success
+# 3. Fill in the filesystem and create a partially writen file as vdev
+# 4. Add the new file into vdevs list and create a pool
+# 5. Creating a storage pool with the new vdevs list should be failed.
+#
+
+verify_runnable "global"
+
+function cleanup
+{
+	typeset pool=""
+
+	for pool in foo $TESTPOOL2 $TESTPOOL1; do
+		poolexists $pool && \
+			destroy_pool $pool
+	done
+
+	if datasetexists $TESTPOOL/$TESTFS; then
+		log_must $ZFS destroy -f $TESTPOOL/$TESTFS
+	fi
+
+	if poolexists $TESTPOOL; then
+		destroy_pool $TESTPOOL
+	fi
+
+	if [[ -d $TESTDIR ]]; then
+		log_must $RM -rf $TESTDIR
+	fi
+
+	partition_disk $SIZE $disk 6
+}
+
+#
+# Create a pool and fs on the assigned disk, and dynamically create large
+# numbers of files as vdevs.(the default value is <VDEVS_NUM>)
+#
+
+function setup_vdevs #<disk>
+{
+	typeset disk=$1
+	typeset -l largest_num=0
+	typeset -l slice_size=0
+	typeset vdev=""
+
+
+	#
+	# Get disk size for zfs filesystem
+	#
+	create_pool foo $disk
+	log_must $ZFS create foo/fs
+	typeset -l fs_size=$(get_prop "available" foo/fs)
+	destroy_pool foo
+
+	(( largest_num = fs_size / (1024 * 1024 * ${POOL_MINSIZE}) ))
+	if (( largest_num < $VDEVS_NUM )); then
+		#minus $largest_num/$MD_OVERHEAD to leave space for metadata
+		(( vdevs_num=largest_num - largest_num/$MD_OVERHEAD ))
+		file_size=$POOL_MINSIZE
+		vdev=$disk
+	else
+		vdevs_num=$VDEVS_NUM
+		(( file_size = fs_size / \
+		 (1024 * 1024 * (vdevs_num + vdevs_num/$MD_OVERHEAD)) ))
+		if (( file_size > FILE_SIZE )); then
+			# If file_size too large, the time cost will increase so
+                        # we limit the file_size to $FILE_SIZE, and thus the
+			# total time spent on creating file can be controlled
+			# within the timeout.
+			file_size=$FILE_SIZE
+		fi
+		# Add $vdevs_num/$MD_OVERHEAD to provide enough space for
+		# metadata
+		(( slice_size = file_size * (vdevs_num + \
+		    vdevs_num/$MD_OVERHEAD) ))
+		set_partition 0 "" ${slice_size}m $disk
+		vdev=${disk}s0
+        fi
+
+	create_pool $TESTPOOL $vdev
+	[[ -d $TESTDIR ]] && \
+		log_must $RM -rf $TESTDIR
+        log_must $MKDIR -p $TESTDIR
+        log_must $ZFS create $TESTPOOL/$TESTFS
+        log_must $ZFS set mountpoint=$TESTDIR $TESTPOOL/$TESTFS
+
+	typeset -l count=0
+	typeset PIDLIST=""
+	while (( count < vdevs_num )); do
+		$MKFILE ${file_size}m ${TESTDIR}/file.$count &
+		PIDLIST="$PIDLIST $!"
+		vdevs_list="$vdevs_list ${TESTDIR}/file.$count"
+		(( count = count + 1 ))
+	done
+
+	# wait all mkfiles to finish
+        wait $PIDLIST
+        if (( $? != 0 )); then
+                log_fail "create vdevs failed."
+        fi
+
+        return 0
+}
+
+log_assert " 'zpool create [-f]' can create a storage pool with large " \
+    "numbers of vdevs without any errors."
+log_onexit cleanup
+
+if [[ -n $DISK ]]; then
+        disk=$DISK
+else
+        disk=$DISK0
+fi
+
+log_note "Create storage pool with number of $VDEVS_NUM file vdevs should " \
+    "succeed."
+vdevs_list=""
+vdevs_num=$VDEVS_NUM
+file_size=$FILE_SIZE
+
+setup_vdevs $disk
+create_pool $TESTPOOL1 $vdevs_list
+
+if poolexists $TESTPOOL1; then
+	destroy_pool $TESTPOOL1
+else
+	log_fail " Creating pool with large numbers of file-vdevs fail."
+fi
+
+log_note "Creating storage pool with partially written file as vdev should " \
+    "fail."
+
+left_space=$(get_prop "available" $TESTPOOL/$TESTFS)
+# Count the broken file size. make sure it should be greater than $left_space
+# so, here, we plus a number -- $file_size, this number can be any other number.
+(( file_size = left_space / (1024 * 1024) + file_size ))
+log_mustnot $MKFILE ${file_size}m ${TESTDIR}/broken_file
+vdevs_list="$vdevs_list ${TESTDIR}/broken_file"
+
+log_mustnot $ZPOOL create -f $TESTPOOL2 $vdevs_list
+
+log_pass "'zpool create [-f]' with $vdevs_num vdevs success."
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/usr/src/test/zfs-tests/tests/functional/cli_root/zpool_create/zpool_create_005_pos.ksh	Wed Dec 05 22:04:50 2012 -0500
@@ -0,0 +1,126 @@
+#!/bin/ksh -p
+#
+# CDDL HEADER START
+#
+# The contents of this file are subject to the terms of the
+# Common Development and Distribution License (the "License").
+# You may not use this file except in compliance with the License.
+#
+# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
+# or http://www.opensolaris.org/os/licensing.
+# See the License for the specific language governing permissions
+# and limitations under the License.
+#
+# When distributing Covered Code, include this CDDL HEADER in each
+# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
+# If applicable, add the following below this CDDL 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.
+#
+
+. $STF_SUITE/include/libtest.shlib
+. $STF_SUITE/tests/functional/cli_root/zpool_create/zpool_create.shlib
+
+#
+# DESCRIPTION:
+# 'zpool create [-R root][-m mountpoint] <pool> <vdev> ...' can create an
+#  alternate root pool or a new pool mounted at the specified mountpoint.
+#
+# STRATEGY:
+# 1. Create a pool with '-m' option
+# 2. Verify the pool is mounted at the specified mountpoint
+#
+
+verify_runnable "global"
+
+function cleanup
+{
+	poolexists $TESTPOOL && \
+		log_must $ZPOOL destroy -f $TESTPOOL
+
+	for dir in $TESTDIR $TESTDIR1; do
+		[[ -d $dir ]] && $RM -rf $dir
+	done
+}
+
+log_assert "'zpool create [-R root][-m mountpoint] <pool> <vdev> ...' can create" \
+	"an alternate pool or a new pool mounted at the specified mountpoint."
+log_onexit cleanup
+
+set -A pooltype "" "mirror" "raidz" "raidz1" "raidz2"
+
+#
+# cleanup the pools created in previous case if zpool_create_004_pos timedout
+#
+for pool in $TESTPOOL2 $TESTPOOL1 $TESTPOOL; do
+	if poolexists $pool; then
+		destroy_pool $pool
+	fi
+done
+
+#prepare raw file for file disk
+[[ -d $TESTDIR ]] && $RM -rf $TESTDIR
+log_must $MKDIR -p $TESTDIR
+typeset -i i=1
+while (( i < 4 )); do
+	log_must $MKFILE $FILESIZE $TESTDIR/file.$i
+
+	(( i = i + 1 ))
+done
+
+#Remove the directory with name as pool name if it exists
+[[ -d /$TESTPOOL ]] && $RM -rf /$TESTPOOL
+file=$TESTDIR/file
+
+for opt in "-R $TESTDIR1" "-m $TESTDIR1" \
+	"-R $TESTDIR1 -m $TESTDIR1" "-m $TESTDIR1 -R $TESTDIR1"
+do
+	i=0
+	while (( i < ${#pooltype[*]} )); do
+		#Remove the testing pool and its mount directory
+		poolexists $TESTPOOL && \
+			log_must $ZPOOL destroy -f $TESTPOOL
+		[[ -d $TESTDIR1 ]] && $RM -rf $TESTDIR1
+		log_must $ZPOOL create $opt $TESTPOOL ${pooltype[i]} \
+			$file.1 $file.2 $file.3
+		! poolexists $TESTPOOL && \
+			log_fail "Createing pool with $opt fails."
+		mpt=`$ZFS mount | $EGREP "^$TESTPOOL[^/]" | $AWK '{print $2}'`
+		(( ${#mpt} == 0 )) && \
+			log_fail "$TESTPOOL created with $opt is not mounted."
+		mpt_val=$(get_prop "mountpoint" $TESTPOOL)
+		[[ "$mpt" != "$mpt_val" ]] && \
+			log_fail "The value of mountpoint property is different\
+				from the output of zfs mount"
+		if [[ "$opt" == "-R $TESTDIR1" ]] || [[ "$opt" == "-m $TESTDIR1" ]];
+		then
+			[[ ! -d $TESTDIR1 ]] && \
+				log_fail "$TESTDIR1 is not created auotmatically."
+			[[ "$mpt" != "$TESTDIR1" ]] && \
+				log_fail "$TESTPOOL is not mounted on $TESTDIR1."
+		else
+			[[ ! -d ${TESTDIR1}$TESTDIR1 ]] && \
+				log_fail "${TESTDIR1}$TESTDIR1 is not created automatically."
+			[[ "$mpt" != "${TESTDIR1}$TESTDIR1" ]] && \
+				log_fail "$TESTPOOL is not mounted on ${TESTDIR1}$TESTDIR1."
+		fi
+		[[ -d /$TESTPOOL ]] && \
+			log_fail "The default mountpoint /$TESTPOOL is created" \
+				"while with $opt option."
+
+		(( i = i + 1 ))
+	done
+done
+
+log_pass "'zpool create [-R root][-m mountpoint] <pool> <vdev> ...' works as expected."
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/usr/src/test/zfs-tests/tests/functional/cli_root/zpool_create/zpool_create_006_pos.ksh	Wed Dec 05 22:04:50 2012 -0500
@@ -0,0 +1,123 @@
+#!/bin/ksh -p
+#
+# CDDL HEADER START
+#
+# The contents of this file are subject to the terms of the
+# Common Development and Distribution License (the "License").
+# You may not use this file except in compliance with the License.
+#
+# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
+# or http://www.opensolaris.org/os/licensing.
+# See the License for the specific language governing permissions
+# and limitations under the License.
+#
+# When distributing Covered Code, include this CDDL HEADER in each
+# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
+# If applicable, add the following below this CDDL 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.
+#
+
+. $STF_SUITE/include/libtest.shlib
+
+#
+# DESCRIPTION:
+#	Verify zpool create succeed with multiple keywords combination.
+#
+# STRATEGY:
+#	1. Create base filesystem to hold virtual disk files.
+#	2. Create several files >= 64M.
+#	3. Verify 'zpool create' succeed with valid keywords combination.
+#
+
+verify_runnable "global"
+
+function cleanup
+{
+	datasetexists $TESTPOOL1 && destroy_pool $TESTPOOL1
+	datasetexists $TESTPOOL && destroy_pool $TESTPOOL
+}
+
+
+log_assert "Verify 'zpool create' succeed with keywords combination."
+log_onexit cleanup
+
+create_pool $TESTPOOL $DISKS
+mntpnt=$(get_prop mountpoint $TESTPOOL)
+
+typeset -i i=0
+while ((i < 10)); do
+	log_must $MKFILE 64M $mntpnt/vdev$i
+
+	eval vdev$i=$mntpnt/vdev$i
+	((i += 1))
+done
+
+set -A valid_args \
+	"mirror $vdev0 $vdev1 $vdev2 mirror $vdev3 $vdev4 $vdev5" \
+	"mirror $vdev0 $vdev1 mirror $vdev2 $vdev3 mirror $vdev4 $vdev5" \
+	"mirror $vdev0 $vdev1 $vdev2 mirror $vdev3 $vdev4 $vdev5 \
+		spare $vdev6" \
+	"mirror $vdev0 $vdev1 mirror $vdev2 $vdev3 mirror $vdev4 $vdev5 \
+		spare $vdev6 $vdev7" \
+	"mirror $vdev0 $vdev1 spare $vdev2 mirror $vdev3 $vdev4" \
+	"raidz $vdev0 $vdev1 $vdev2 raidz1 $vdev3 $vdev4 $vdev5" \
+	"raidz $vdev0 $vdev1 raidz1 $vdev2 $vdev3 raidz $vdev4 $vdev5" \
+	"raidz $vdev0 $vdev1 $vdev2 raidz1 $vdev3 $vdev4 $vdev5 \
+		spare $vdev6" \
+	"raidz $vdev0 $vdev1 raidz1 $vdev2 $vdev3 raidz $vdev4 $vdev5 \
+		spare $vdev6 $vdev7" \
+	"raidz $vdev0 $vdev1 spare $vdev2 raidz $vdev3 $vdev4" \
+	"raidz2 $vdev0 $vdev1 $vdev2 raidz2 $vdev3 $vdev4 $vdev5" \
+	"raidz2 $vdev0 $vdev1 $vdev2 raidz2 $vdev3 $vdev4 $vdev5 \
+		raidz2 $vdev6 $vdev7 $vdev8" \
+	"raidz2 $vdev0 $vdev1 $vdev2 raidz2 $vdev3 $vdev4 $vdev5 \
+		spare $vdev6" \
+	"raidz2 $vdev0 $vdev1 $vdev2 raidz2 $vdev3 $vdev4 $vdev5 \
+		raidz2 $vdev6 $vdev7 $vdev8 spare $vdev9" \
+	"raidz2 $vdev0 $vdev1 $vdev2 spare $vdev3 raidz2 $vdev4 $vdev5 $vdev6"
+
+set -A forced_args \
+	"$vdev0 raidz $vdev1 $vdev2 raidz1 $vdev3 $vdev4 $vdev5" \
+	"$vdev0 raidz2 $vdev1 $vdev2 $vdev3 raidz2 $vdev4 $vdev5 $vdev6" \
+	"$vdev0 mirror $vdev1 $vdev2 mirror $vdev3 $vdev4" \
+	"$vdev0 mirror $vdev1 $vdev2 raidz $vdev3 $vdev4 \
+		raidz2 $vdev5 $vdev6 $vdev7 spare $vdev8" \
+	"$vdev0 mirror $vdev1 $vdev2 spare $vdev3 raidz $vdev4 $vdev5" \
+	"raidz $vdev0 $vdev1 raidz2 $vdev2 $vdev3 $vdev4" \
+	"raidz $vdev0 $vdev1 raidz2 $vdev2 $vdev3 $vdev4 spare $vdev5" \
+	"raidz $vdev0 $vdev1 spare $vdev2 raidz2 $vdev3 $vdev4 $vdev5" \
+	"mirror $vdev0 $vdev1 raidz $vdev2 $vdev3 raidz2 $vdev4 $vdev5 $vdev6" \
+	"mirror $vdev0 $vdev1 raidz $vdev2 $vdev3 \
+		raidz2 $vdev4 $vdev5 $vdev6 spare $vdev7" \
+	"mirror $vdev0 $vdev1 raidz $vdev2 $vdev3 \
+		spare $vdev4 raidz2 $vdev5 $vdev6 $vdev7" \
+	"spare $vdev0 $vdev1 $vdev2 mirror $vdev3 $vdev4 raidz $vdev5 $vdev6"
+
+i=0
+while ((i < ${#valid_args[@]})); do
+	log_must $ZPOOL create $TESTPOOL1 ${valid_args[$i]}
+	$SYNC; $SYNC
+	log_must $ZPOOL destroy -f $TESTPOOL1
+
+	((i += 1))
+done
+
+i=0
+while ((i < ${#forced_args[@]})); do
+	log_mustnot $ZPOOL create $TESTPOOL1 ${forced_args[$i]}
+	log_must $ZPOOL create -f $TESTPOOL1 ${forced_args[$i]}
+	$SYNC; $SYNC
+	log_must $ZPOOL destroy -f $TESTPOOL1
+
+	((i += 1))
+done
+
+log_pass "'zpool create' succeed with keywords combination."
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/usr/src/test/zfs-tests/tests/functional/cli_root/zpool_create/zpool_create_007_neg.ksh	Wed Dec 05 22:04:50 2012 -0500
@@ -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 2008 Sun Microsystems, Inc.  All rights reserved.
+# Use is subject to license terms.
+#
+
+#
+# Copyright (c) 2012 by Delphix. All rights reserved.
+#
+
+. $STF_SUITE/include/libtest.shlib
+. $STF_SUITE/tests/functional/cli_root/zpool_create/zpool_create.shlib
+
+#
+# DESCRIPTION:
+# 'zpool create' should return an error with badly formed parameters.
+#
+# STRATEGY:
+# 1. Create an array of parameters
+# 2. For each parameter in the array, execute 'zpool create'
+# 3. Verify an error is returned.
+#
+
+verify_runnable "global"
+
+if [[ -n $DISK ]]; then
+	disk=$DISK
+else
+	disk=$DISK0
+fi
+
+set -A args  "" "-?" "-n" "-f" "-nf" "-fn" "-f -n" "--f" "-e" "-s" \
+	"-m" "-R" "-m -R" "-Rm" "-mR" "-m $TESTDIR $TESTPOOL" \
+	"-R $TESTDIR $TESTPOOL" "-m nodir $TESTPOOL $disk" \
+	"-R nodir $TESTPOOL $disk" "-m nodir -R nodir $TESTPOOL $disk" \
+	"-R nodir -m nodir $TESTPOOL $disk" "-R $TESTDIR -m nodir $TESTPOOL $disk" \
+	"-R nodir -m $TESTDIR $TESTPOOL $disk" \
+	"-blah" "$TESTPOOL" "$TESTPOOL blah" "$TESTPOOL c?t0d0" \
+	"$TESTPOOL c0txd0" "$TESTPOOL c0t0dx" "$TESTPOOL cxtxdx" \
+	"$TESTPOOL mirror" "$TESTPOOL raidz" "$TESTPOOL mirror raidz" \
+	"$TESTPOOL raidz1" "$TESTPOOL mirror raidz1" \
+	"$TESTPOOL mirror c?t?d?" "$TESTPOOL mirror $disk c0t1d?" \
+	"$TESTPOOL RAIDZ ${disk}s${SLICE0} ${disk}s${SLICE1}" \
+	"$TESTPOOL ${disk}s${SLICE0} log ${disk}s${SLICE1} \
+	log ${disk}s${SLICE3}" \
+	"$TESTPOOL ${disk}s${SLICE0} spare ${disk}s${SLICE1} \
+	spare ${disk}s${SLICE3}" \
+	"$TESTPOOL RAIDZ1 ${disk}s${SLICE0} ${disk}s${SLICE1}" \
+	"$TESTPOOL MIRROR $disk" "$TESTPOOL raidz $disk" \
+	"$TESTPOOL raidz1 $disk" \
+	"1tank $disk" "1234 $disk" "?tank $disk" \
+	"tan%k $disk" "ta@# $disk" "tan+k $disk" \
+	"$BYND_MAX_NAME $disk"
+
+log_assert "'zpool create' should return an error with badly-formed parameters."
+log_onexit default_cleanup_noexit
+
+typeset -i i=0
+while [[ $i -lt ${#args[*]} ]]; do
+	log_mustnot $ZPOOL create ${args[i]}
+	((i = i + 1))
+done
+
+log_pass "'zpool create' with badly formed parameters failed as expected."
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/usr/src/test/zfs-tests/tests/functional/cli_root/zpool_create/zpool_create_008_pos.ksh	Wed Dec 05 22:04:50 2012 -0500
@@ -0,0 +1,148 @@
+#!/bin/ksh -p
+#
+# CDDL HEADER START
+#
+# The contents of this file are subject to the terms of the
+# Common Development and Distribution License (the "License").
+# You may not use this file except in compliance with the License.
+#
+# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
+# or http://www.opensolaris.org/os/licensing.
+# See the License for the specific language governing permissions
+# and limitations under the License.
+#
+# When distributing Covered Code, include this CDDL HEADER in each
+# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
+# If applicable, add the following below this CDDL 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) 2012 by Delphix. All rights reserved.
+#
+
+. $STF_SUITE/include/libtest.shlib
+. $STF_SUITE/tests/functional/cli_root/zpool_create/zpool_create.shlib
+
+#
+# DESCRIPTION:
+# 'zpool create' have to use '-f' scenarios
+#
+# STRATEGY:
+# 1. Prepare the scenarios
+# 2. Create pool without '-f' and verify it fails
+# 3. Create pool with '-f' and verify it succeeds
+#
+
+verify_runnable "global"
+
+function cleanup
+{
+	if [[ $exported_pool == true ]]; then
+		if [[ $force_pool == true ]]; then
+			log_must $ZPOOL create -f $TESTPOOL ${disk}s${SLICE0}
+		else
+			log_must $ZPOOL import $TESTPOOL
+		fi
+	fi
+
+	if poolexists $TESTPOOL ; then
+                destroy_pool $TESTPOOL
+	fi
+
+	if poolexists $TESTPOOL1 ; then
+                destroy_pool $TESTPOOL1
+	fi
+
+	#
+	# recover it back to EFI label
+	#
+	create_pool $TESTPOOL $disk
+	destroy_pool $TESTPOOL
+
+        partition_disk $SIZE $disk 6
+}
+
+#
+# create overlap slice 0 and 1 on $disk
+#
+function create_overlap_slice
+{
+        typeset format_file=/var/tmp/format_overlap.$$
+        typeset disk=$1
+
+        $ECHO "partition" >$format_file
+        $ECHO "0" >> $format_file
+        $ECHO "" >> $format_file
+        $ECHO "" >> $format_file
+        $ECHO "0" >> $format_file
+        $ECHO "200m" >> $format_file
+        $ECHO "1" >> $format_file
+        $ECHO "" >> $format_file
+        $ECHO "" >> $format_file
+        $ECHO "0" >> $format_file
+        $ECHO "400m" >> $format_file
+        $ECHO "label" >> $format_file
+        $ECHO "" >> $format_file
+        $ECHO "q" >> $format_file
+        $ECHO "q" >> $format_file
+
+        $FORMAT -e -s -d $disk -f $format_file
+	typeset -i ret=$?
+        $RM -fr $format_file
+
+	if (( ret != 0 )); then
+                log_fail "unable to create overlap slice."
+        fi
+
+        return 0
+}
+
+log_assert "'zpool create' have to use '-f' scenarios"
+log_onexit cleanup
+
+typeset exported_pool=false
+typeset force_pool=false
+
+if [[ -n $DISK ]]; then
+        disk=$DISK
+else
+        disk=$DISK0
+fi
+
+# overlapped slices as vdev need -f to create pool
+
+# Make the disk is EFI labeled first via pool creation
+create_pool $TESTPOOL $disk
+destroy_pool $TESTPOOL
+
+# Make the disk is VTOC labeled since only VTOC label supports overlap
+log_must labelvtoc $disk
+log_must create_overlap_slice $disk
+
+log_mustnot $ZPOOL create $TESTPOOL ${disk}s${SLICE0}
+log_must $ZPOOL create -f $TESTPOOL ${disk}s${SLICE0}
+destroy_pool $TESTPOOL
+
+# exported device to be as spare vdev need -f to create pool
+
+log_must $ZPOOL create -f $TESTPOOL $disk
+destroy_pool $TESTPOOL
+log_must partition_disk $SIZE $disk 6
+create_pool $TESTPOOL ${disk}s${SLICE0} ${disk}s${SLICE1}
+log_must $ZPOOL export $TESTPOOL
+exported_pool=true
+log_mustnot $ZPOOL create $TESTPOOL1 ${disk}s${SLICE3} spare ${disk}s${SLICE1}
+create_pool $TESTPOOL1 ${disk}s${SLICE3} spare ${disk}s${SLICE1}
+force_pool=true
+destroy_pool $TESTPOOL1
+
+log_pass "'zpool create' have to use '-f' scenarios"
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/usr/src/test/zfs-tests/tests/functional/cli_root/zpool_create/zpool_create_009_neg.ksh	Wed Dec 05 22:04:50 2012 -0500
@@ -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) 2012 by Delphix. All rights reserved.
+#
+
+. $STF_SUITE/include/libtest.shlib
+. $STF_SUITE/tests/functional/cli_root/zpool_create/zpool_create.shlib
+
+#
+# DESCRIPTION:
+#	Create a pool with same devices twice or create two pools with same
+#	devices, 'zpool create' should failed.
+#
+# STRATEGY:
+#	1. Loop to create the following three kinds of pools.
+#		- Regular pool
+#		- Mirror
+#		- Raidz
+#	2. Create two pools but using the same disks, expect failed.
+#	3. Create one pool but using the same disks twice, expect failed.
+#
+
+verify_runnable "global"
+
+function cleanup
+{
+	typeset dtst
+	typeset disk
+
+	for dtst in $TESTPOOL $TESTPOOL1; do
+		poolexists $dtst && destroy_pool $dtst
+	done
+
+	for disk in $DISKS; do
+		partition_disk $SIZE $disk 6
+	done
+}
+
+log_assert "Create a pool with same devices twice or create two pools with " \
+	"same devices, 'zpool create' should fail."
+log_onexit cleanup
+
+typeset opt
+for opt in "" "mirror" "raidz" "raidz1"; do
+	typeset disk="$DISKS"
+	(( ${#opt} == 0 )) && disk=${DISKS%% *}
+
+	typeset -i count=$(get_word_count $disk)
+	if (( count < 2  && ${#opt} != 0 )) ; then
+		continue
+	fi
+
+	# Create two pools but using the same disks.
+	create_pool $TESTPOOL $opt $disk
+	log_mustnot $ZPOOL create -f $TESTPOOL1 $opt $disk
+	destroy_pool $TESTPOOL
+
+	# Create two pools and part of the devices were overlapped
+	create_pool $TESTPOOL $opt $disk
+	log_mustnot $ZPOOL create -f $TESTPOOL1 $opt ${DISKS% *}
+	destroy_pool $TESTPOOL
+
+	# Create one pool but using the same disks twice.
+	log_mustnot $ZPOOL create -f $TESTPOOL $opt $disk $disk
+done
+
+log_pass "Using overlapping or in-use disks to create a new pool fails as expected."
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/usr/src/test/zfs-tests/tests/functional/cli_root/zpool_create/zpool_create_010_neg.ksh	Wed Dec 05 22:04:50 2012 -0500
@@ -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) 2012 by Delphix. All rights reserved.
+#
+
+. $STF_SUITE/include/libtest.shlib
+. $STF_SUITE/tests/functional/cli_root/zpool_create/zpool_create.shlib
+
+#
+# DESCRIPTION:
+# 'zpool create' should return an error with VDEVsof size  <64mb
+#
+# STRATEGY:
+# 1. Create an array of parameters
+# 2. For each parameter in the array, execute 'zpool create'
+# 3. Verify an error is returned.
+#
+
+log_assert "'zpool create' should return an error with VDEVs <64mb"
+
+verify_runnable "global"
+
+function cleanup
+{
+        poolexists $TOOSMALL && destroy_pool $TOOSMALL
+        poolexists $TESTPOOL1 && destroy_pool $TESTPOOL1
+
+        poolexists $TESTPOOL && destroy_pool $TESTPOOL
+
+	[[ -d $TESTDIR ]] && $RM -rf $TESTDIR
+
+	partition_disk $SIZE $disk 6
+}
+log_onexit cleanup
+
+if [[ -n $DISK ]]; then
+        disk=$DISK
+else
+        disk=$DISK0
+fi
+
+create_pool $TESTPOOL $disk
+log_must $ZFS create $TESTPOOL/$TESTFS
+log_must $ZFS set mountpoint=$TESTDIR $TESTPOOL/$TESTFS
+
+for files in $TESTDIR/file1 $TESTDIR/file2
+do
+	log_must $MKFILE 63m $files
+done
+
+set -A args \
+	"$TOOSMALL $TESTDIR/file1" "$TESTPOOL1 $TESTDIR/file1 $TESTDIR/file2" \
+        "$TOOSMALL mirror $TESTDIR/file1 $TESTDIR/file2" \
+	"$TOOSMALL raidz $TESTDIR/file1 $TESTDIR/file2"
+
+typeset -i i=0
+while [[ $i -lt ${#args[*]} ]]; do
+	log_mustnot $ZPOOL create ${args[i]}
+	((i = i + 1))
+done
+
+log_pass "'zpool create' with badly formed parameters failed as expected."
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/usr/src/test/zfs-tests/tests/functional/cli_root/zpool_create/zpool_create_011_neg.ksh	Wed Dec 05 22:04:50 2012 -0500
@@ -0,0 +1,129 @@
+#!/bin/ksh -p
+#
+# CDDL HEADER START
+#
+# The contents of this file are subject to the terms of the
+# Common Development and Distribution License (the "License").
+# You may not use this file except in compliance with the License.
+#
+# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
+# or http://www.opensolaris.org/os/licensing.
+# See the License for the specific language governing permissions
+# and limitations under the License.
+#
+# When distributing Covered Code, include this CDDL HEADER in each
+# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
+# If applicable, add the following below this CDDL 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.
+#
+
+. $STF_SUITE/include/libtest.shlib
+. $STF_SUITE/tests/functional/cli_root/zpool_create/zpool_create.shlib
+
+#
+# DESCRIPTION:
+# 'zpool create' will fail in the following cases:
+# existent pool; device is part of an active pool; nested virtual devices;
+# differently sized devices without -f option; device being currently
+# mounted; devices in /etc/vfstab; specified as the dedicated dump device.
+#
+# STRATEGY:
+# 1. Create case scenarios
+# 2. For each scenario, try to create a new pool with the virtual devices
+# 3. Verify the creation is failed.
+#
+
+verify_runnable "global"
+
+function cleanup
+{
+        for pool in $TESTPOOL $TESTPOOL1
+        do
+                destroy_pool $pool
+        done
+
+	if [[ -n $saved_dump_dev ]]; then
+		log_must $DUMPADM -u -d $saved_dump_dev
+	fi
+
+        partition_disk $SIZE $disk 6
+}
+
+log_assert "'zpool create' should be failed with inapplicable scenarios."
+log_onexit cleanup
+
+if [[ -n $DISK ]]; then
+        disk=$DISK
+else
+        disk=$DISK0
+fi
+pooldev1=${disk}s${SLICE0}
+pooldev2=${disk}s${SLICE1}
+mirror1="${disk}s${SLICE1} ${disk}s${SLICE3}"
+mirror2="${disk}s${SLICE4} ${disk}s${SLICE5}"
+raidz1=$mirror1
+raidz2=$mirror2
+diff_size_dev="${disk}s${SLICE6} ${disk}s${SLICE7}"
+vfstab_dev=$(find_vfstab_dev)
+specified_dump_dev=${disk}s${SLICE0}
+saved_dump_dev=$(save_dump_dev)
+
+cyl=$(get_endslice $disk $SLICE6)
+set_partition $SLICE7 "$cyl" $SIZE1 $disk
+create_pool "$TESTPOOL" "$pooldev1"
+
+#
+# Set up the testing scenarios parameters
+#
+set -A arg "$TESTPOOL $pooldev2" \
+        "$TESTPOOL1 $pooldev1" \
+        "$TESTPOOL1 $TESTDIR0/$FILEDISK0" \
+        "$TESTPOOL1 mirror mirror $mirror1 mirror $mirror2" \
+        "$TESTPOOL1 raidz raidz $raidz1 raidz $raidz2" \
+        "$TESTPOOL1 raidz1 raidz1 $raidz1 raidz1 $raidz2" \
+        "$TESTPOOL1 mirror raidz $raidz1 raidz $raidz2" \
+        "$TESTPOOL1 mirror raidz1 $raidz1 raidz1 $raidz2" \
+        "$TESTPOOL1 raidz mirror $mirror1 mirror $mirror2" \
+        "$TESTPOOL1 raidz1 mirror $mirror1 mirror $mirror2" \
+        "$TESTPOOL1 mirror $diff_size_dev" \
+        "$TESTPOOL1 raidz $diff_size_dev" \
+        "$TESTPOOL1 raidz1 $diff_size_dev" \
+	"$TESTPOOL1 mirror $mirror1 spare $mirror2 spare $diff_size_dev" \
+        "$TESTPOOL1 $vfstab_dev" \
+        "$TESTPOOL1 ${disk}s10" \
+	"$TESTPOOL1 spare $pooldev2"
+
+typeset -i i=0
+while (( i < ${#arg[*]} )); do
+        log_mustnot $ZPOOL create ${arg[i]}
+        (( i = i+1 ))
+done
+
+# now destroy the pool to be polite
+log_must $ZPOOL destroy -f $TESTPOOL
+
+# create/destroy a pool as a simple way to set the partitioning
+# back to something normal so we can use this $disk as a dump device
+log_must $ZPOOL create -f $TESTPOOL3 $disk
+log_must $ZPOOL destroy -f $TESTPOOL3
+
+log_must $DUMPADM -d /dev/dsk/$specified_dump_dev
+log_mustnot $ZPOOL create -f $TESTPOOL1 "$specified_dump_dev"
+
+# Also check to see that in-use checking prevents us from creating
+# a zpool from just the first slice on the disk.
+log_mustnot $ZPOOL create -f $TESTPOOL1 ${specified_dump_dev}s0
+
+log_pass "'zpool create' is failed as expected with inapplicable scenarios."
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/usr/src/test/zfs-tests/tests/functional/cli_root/zpool_create/zpool_create_012_neg.ksh	Wed Dec 05 22:04:50 2012 -0500
@@ -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.
+#
+
+. $STF_SUITE/include/libtest.shlib
+
+#
+#
+# DESCRIPTION:
+# 'zpool create' will fail with formal disk slice in swap
+#
+#
+# STRATEGY:
+# 1. Get all the disk devices in swap
+# 2. For each device, try to create a new pool with this device
+# 3. Verify the creation is failed.
+#
+
+verify_runnable "global"
+
+function cleanup
+{
+	if poolexists $TESTPOOL; then
+		destroy_pool $TESTPOOL
+	fi
+
+}
+typeset swap_disks=`$SWAP -l | $GREP "c[0-9].*d[0-9].*s[0-9]" | \
+            $AWK '{print $1}'`
+
+log_assert "'zpool create' should fail with disk slice in swap."
+log_onexit cleanup
+
+for sdisk in $swap_disks; do
+	for opt in "-n" "" "-f"; do
+		log_mustnot $ZPOOL create $opt $TESTPOOL $sdisk
+	done
+done
+
+log_pass "'zpool create' passed as expected with inapplicable scenario."
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/usr/src/test/zfs-tests/tests/functional/cli_root/zpool_create/zpool_create_013_neg.ksh	Wed Dec 05 22:04:50 2012 -0500
@@ -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) 2012 by Delphix. All rights reserved.
+#
+
+. $STF_SUITE/include/libtest.shlib
+. $STF_SUITE/tests/functional/cli_root/zpool_create/zpool_create.shlib
+
+#
+#
+# DESCRIPTION:
+# 'zpool create' will fail with metadevice in swap
+#
+# STRATEGY:
+# 1. Create a one way strip metadevice
+# 2. Try to create a new pool with metadevice in swap
+# 3. Verify the creation is failed.
+#
+
+verify_runnable "global"
+
+function cleanup
+{
+	# cleanup SVM
+	$METASTAT $md_name > /dev/null 2>&1
+	if [[ $? -eq 0 ]]; then
+		$SWAP -l | $GREP /dev/md/dsk/$md_name > /dev/null 2>&1
+		if [[ $? -eq 0 ]]; then
+			$SWAP -d /dev/md/dsk/$md_name
+		fi
+		$METACLEAR $md_name
+	fi
+
+	$METADB | $GREP $mddb_dev > /dev/null 2>&1
+	if [[ $? -eq 0 ]]; then
+		$METADB -df /dev/dsk/$mddb_dev
+	fi
+
+	if poolexists $TESTPOOL; then
+		destroy_pool $TESTPOOL
+	fi
+
+}
+
+if [[ -n $DISK ]]; then
+        disk=$DISK
+else
+        disk=$DISK0
+fi
+
+typeset mddb_dev=${disk}s${SLICE0}
+typeset md_dev=${disk}s${SLICE1}
+typeset md_name=d0
+typeset MD_DSK=/dev/md/dsk/d0
+
+log_assert "'zpool create' should fail with metadevice in swap."
+log_onexit cleanup
+
+#
+# use metadevice in swap to create pool, which should fail.
+#
+$METADB | $GREP $mddb_dev > /dev/null 2>&1
+if [[ $? -ne 0 ]]; then
+	log_must $METADB -af $mddb_dev
+fi
+
+$METASTAT $md_name > /dev/null 2>&1
+if [[ $? -eq 0 ]]; then
+	$METACLEAR $md_name
+fi
+
+log_must $METAINIT $md_name 1 1 $md_dev
+log_must $SWAP -a $MD_DSK
+for opt in "-n" "" "-f"; do
+	log_mustnot $ZPOOL create $opt $TESTPOOL $MD_DSK
+done
+
+log_pass "'zpool create' passed as expected with inapplicable scenario."
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/usr/src/test/zfs-tests/tests/functional/cli_root/zpool_create/zpool_create_014_neg.ksh	Wed Dec 05 22:04:50 2012 -0500
@@ -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) 2012 by Delphix. All rights reserved.
+#
+
+. $STF_SUITE/include/libtest.shlib
+. $STF_SUITE/tests/functional/cli_root/zpool_create/zpool_create.shlib
+
+#
+#
+# DESCRIPTION:
+# 'zpool create' will fail with ordinary file in swap
+#
+# STRATEGY:
+# 1. Create a regular file on top of UFS-zvol filesystem
+# 2. Try to create a new pool with regular file in swap
+# 3. Verify the creation is failed.
+#
+
+verify_runnable "global"
+
+function cleanup
+{
+	if datasetexists $vol_name; then
+		$SWAP -l | $GREP $TMP_FILE > /dev/null 2>&1
+		if [[ $? -eq 0 ]]; then
+			log_must $SWAP -d $TMP_FILE
+		fi
+		$RM -f $TMP_FILE
+		log_must $UMOUNT $mntp
+		$ZFS destroy $vol_name
+	fi
+
+	if poolexists $TESTPOOL; then
+		destroy_pool $TESTPOOL
+	fi
+}
+
+log_assert "'zpool create' should fail with regular file in swap."
+log_onexit cleanup
+
+if [[ -n $DISK ]]; then
+        disk=$DISK
+else
+        disk=$DISK0
+fi
+
+typeset pool_dev=${disk}s${SLICE0}
+typeset vol_name=$TESTPOOL/$TESTVOL
+typeset mntp=/mnt
+typeset TMP_FILE=$mntp/tmpfile.$$
+
+create_pool $TESTPOOL $pool_dev
+log_must $ZFS create -V 100m $vol_name
+log_must $ECHO "y" | $NEWFS /dev/zvol/dsk/$vol_name > /dev/null 2>&1
+log_must $MOUNT /dev/zvol/dsk/$vol_name $mntp
+
+log_must $MKFILE 50m $TMP_FILE
+log_must $SWAP -a $TMP_FILE
+
+for opt in "-n" "" "-f"; do
+	log_mustnot $ZPOOL create $opt $TESTPOOL $TMP_FILE
+done
+
+log_pass "'zpool create' passed as expected with inapplicable scenario."
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/usr/src/test/zfs-tests/tests/functional/cli_root/zpool_create/zpool_create_015_neg.ksh	Wed Dec 05 22:04:50 2012 -0500
@@ -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) 2012 by Delphix. All rights reserved.
+#
+
+. $STF_SUITE/include/libtest.shlib
+. $STF_SUITE/tests/functional/cli_root/zpool_create/zpool_create.shlib
+
+#
+#
+# DESCRIPTION:
+# 'zpool create' will fail with zfs vol device in swap
+#
+#
+# STRATEGY:
+# 1. Create a zpool
+# 2. Create a zfs vol on zpool
+# 3. Add this zfs vol device to swap
+# 4. Try to create a new pool with devices in swap
+# 5. Verify the creation is failed.
+#
+
+verify_runnable "global"
+
+function cleanup
+{
+	# cleanup zfs pool and dataset
+	if datasetexists $vol_name; then
+		$SWAP -l | $GREP /dev/zvol/dsk/$vol_name > /dev/null 2>&1
+		if [[ $? -eq 0 ]]; then
+			$SWAP -d /dev/zvol/dsk/${vol_name}
+		fi
+	fi
+
+	for pool in $TESTPOOL1 $TESTPOOL; do
+		if poolexists $pool; then
+			destroy_pool $pool
+		fi
+	done
+
+}
+
+if [[ -n $DISK ]]; then
+        disk=$DISK
+else
+        disk=$DISK0
+fi
+
+typeset pool_dev=${disk}s${SLICE0}
+typeset vol_name=$TESTPOOL/$TESTVOL
+
+log_assert "'zpool create' should fail with zfs vol device in swap."
+log_onexit cleanup
+
+#
+# use zfs vol device in swap to create pool which should fail.
+#
+create_pool $TESTPOOL $pool_dev
+log_must $ZFS create -V 100m $vol_name
+log_must $SWAP -a /dev/zvol/dsk/$vol_name
+for opt in "-n" "" "-f"; do
+	log_mustnot $ZPOOL create $opt $TESTPOOL1 /dev/zvol/dsk/${vol_name}
+done
+
+# cleanup
+log_must $SWAP -d /dev/zvol/dsk/${vol_name}
+log_must $ZFS destroy $vol_name
+log_must $ZPOOL destroy $TESTPOOL
+
+log_pass "'zpool create' passed as expected with inapplicable scenario."
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/usr/src/test/zfs-tests/tests/functional/cli_root/zpool_create/zpool_create_016_pos.ksh	Wed Dec 05 22:04:50 2012 -0500
@@ -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) 2012 by Delphix. All rights reserved.
+#
+
+. $STF_SUITE/include/libtest.shlib
+. $STF_SUITE/tests/functional/cli_root/zpool_create/zpool_create.shlib
+
+#
+#
+# DESCRIPTION:
+# 'zpool create' will success with no device in swap
+#
+#
+# STRATEGY:
+# 1. delete all devices in the swap
+# 2. create a zpool
+# 3. Verify the creation is successed.
+#
+
+verify_runnable "global"
+
+function cleanup
+{
+	if poolexists $TESTPOOL; then
+		destroy_pool $TESTPOOL
+	fi
+
+	#recover swap devices
+	FSTAB=/tmp/fstab_$$
+	$RM -f $FSTAB
+	for sdisk in $swap_disks; do
+		$ECHO "$sdisk	-	-	swap	-	no	-" >> $FSTAB
+	done
+	if [ -e $FSTAB ]
+	then
+		log_must $SWAPADD $FSTAB
+	fi
+	$RM -f $FSTAB
+	if [ $dump_device != "none" ]
+	then
+		log_must $DUMPADM -u -d $dump_device
+	fi
+}
+
+if [[ -n $DISK ]]; then
+	disk=$DISK
+else
+	disk=$DISK0
+fi
+typeset pool_dev=${disk}s${SLICE0}
+typeset swap_disks=$($SWAP -l | $GREP -v "swapfile" | $AWK '{print $1}')
+typeset dump_device=$($DUMPADM | $GREP "Dump device" | $AWK '{print $3}')
+
+log_assert "'zpool create' should success with no device in swap."
+log_onexit cleanup
+
+for sdisk in $swap_disks; do
+	log_note "Executing: swap -d $sdisk"
+	$SWAP -d $sdisk >/dev/null 2>&1;
+	if [[ $? != 0 ]]; then
+		log_untested "Unable to delete swap device $sdisk because of" \
+				"insufficient RAM"
+	fi
+done
+
+log_must $ZPOOL create $TESTPOOL $pool_dev
+log_must $ZPOOL destroy $TESTPOOL
+
+log_pass "'zpool create' passed as expected with applicable scenario."
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/usr/src/test/zfs-tests/tests/functional/cli_root/zpool_create/zpool_create_017_neg.ksh	Wed Dec 05 22:04:50 2012 -0500
@@ -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) 2012 by Delphix. All rights reserved.
+#
+
+. $STF_SUITE/include/libtest.shlib
+. $STF_SUITE/tests/functional/cli_root/zpool_create/zpool_create.shlib
+
+#
+#
+# DESCRIPTION:
+# 'zpool create' will fail with mountpoint exists and is not empty.
+#
+#
+# STRATEGY:
+# 1. Prepare the mountpoint put some stuff into it.
+# 2. Verify 'zpool create' over that mountpoint fails.
+#
+
+verify_runnable "global"
+
+function cleanup
+{
+	if poolexists $TESTPOOL; then
+		destroy_pool $TESTPOOL
+	fi
+
+	if [[ -d $TESTDIR ]]; then
+		log_must $RM -rf $TESTDIR
+	fi
+}
+
+if [[ -n $DISK ]]; then
+        disk=$DISK
+else
+        disk=$DISK0
+fi
+
+typeset pool_dev=${disk}s${SLICE0}
+
+log_assert "'zpool create' should fail with mountpoint exists and not empty."
+log_onexit cleanup
+
+if [[ ! -d $TESTDIR ]]; then
+	log_must $MKDIR -p $TESTDIR
+fi
+
+typeset -i i=0
+
+while (( i < 2 )); do
+	log_must $RM -rf $TESTDIR/*
+	if (( i == 0 )); then
+		log_must $MKDIR $TESTDIR/testdir
+	else
+		log_must $TOUCH $TESTDIR/testfile
+	fi
+
+	log_mustnot $ZPOOL create -m $TESTDIR -f $TESTPOOL $pool_dev
+	log_mustnot poolexists $TESTPOOL
+
+	(( i = i + 1 ))
+done
+
+log_pass "'zpool create' fail as expected with mountpoint exists and not empty."
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/usr/src/test/zfs-tests/tests/functional/cli_root/zpool_create/zpool_create_018_pos.ksh	Wed Dec 05 22:04:50 2012 -0500
@@ -0,0 +1,104 @@
+#!/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) 2012 by Delphix. All rights reserved.
+#
+
+. $STF_SUITE/include/libtest.shlib
+. $STF_SUITE/tests/functional/cli_root/zpool_create/zpool_create.shlib
+
+#
+# DESCRIPTION:
+#
+# zpool create can create pools with specified properties
+#
+# STRATEGY:
+# 1. Create a pool with all editable properties
+# 2. Verify those properties are set
+# 3. Create a pool with two properties set
+# 4. Verify both properties are set correctly
+#
+
+function cleanup
+{
+	poolexists $TESTPOOL && destroy_pool $TESTPOOL
+	[[ -f $CPATH ]] && log_must $RM $CPATH
+}
+
+log_onexit cleanup
+log_assert "zpool create can create pools with specified properties"
+
+if [[ -n $DISK ]]; then
+	disk=$DISK
+else
+	disk=$DISK0
+fi
+
+#
+# we don't include "root" property in this list, as it requires both "cachefile"
+# and "root" to be set at the same time. A test for this is included in
+# ../../root.
+#
+typeset props=("autoreplace" "delegation" "cachefile" "version" "autoexpand")
+typeset vals=("off" "off" "$CPATH" "3" "on")
+
+typeset -i i=0;
+while [ $i -lt "${#props[@]}" ]
+do
+	log_must $ZPOOL create -o ${props[$i]}=${vals[$i]} $TESTPOOL $disk
+	RESULT=$(get_pool_prop ${props[$i]} $TESTPOOL)
+	if [[ $RESULT != ${vals[$i]} ]]
+	then
+		$ZPOOL get all $TESTPOOL
+		log_fail "Pool was created without setting the ${props[$i]} " \
+		    "property"
+	fi
+	log_must $ZPOOL destroy $TESTPOOL
+	((i = i + 1))
+done
+
+# Destroy our pool
+poolexists $TESTPOOL && destroy_pool $TESTPOOL
+
+# pick two properties, and verify we can create with those as well
+log_must $ZPOOL create -o delegation=off -o cachefile=$CPATH $TESTPOOL $disk
+RESULT=$(get_pool_prop delegation $TESTPOOL)
+if [[ $RESULT != off ]]
+then
+	$ZPOOL get all $TESTPOOL
+	log_fail "Pool created without the delegation prop."
+fi
+
+RESULT=$(get_pool_prop cachefile $TESTPOOL)
+if [[ $RESULT != $CPATH ]]
+then
+	$ZPOOL get all $TESTPOOL
+	log_fail "Pool created without the cachefile prop."
+fi
+
+log_pass "zpool create can create pools with specified properties"
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/usr/src/test/zfs-tests/tests/functional/cli_root/zpool_create/zpool_create_019_pos.ksh	Wed Dec 05 22:04:50 2012 -0500
@@ -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.
+#
+
+. $STF_SUITE/include/libtest.shlib
+
+#
+# DESCRIPTION:
+#
+# zpool create cannot create pools specifying readonly properties
+#
+# STRATEGY:
+# 1. Attempt to create a pool, specifying each readonly property in turn
+# 2. Verify the pool was not created
+#
+
+function cleanup
+{
+	if poolexists $TESTPOOL ; then
+                destroy_pool $TESTPOOL
+        fi
+}
+
+log_onexit cleanup
+
+log_assert "zpool create cannot create pools specifying readonly properties"
+
+if [[ -n $DISK ]]; then
+	disk=$DISK
+else
+	disk=$DISK0
+fi
+
+set -A props "available" "capacity" "guid"  "health"  "size" "used"
+set -A vals  "100"       "10"       "12345" "HEALTHY" "10"   "10"
+
+typeset -i i=0;
+while [ $i -lt "${#props[@]}" ]
+do
+        # try to set each property in the prop list with it's corresponding val
+        log_mustnot $ZPOOL create -o ${props[$i]}=${vals[$i]} $TESTPOOL $disk
+	if poolexists $TESTPOOL
+	then
+		log_fail "$TESTPOOL was created when setting ${props[$i]}!"
+	fi
+        i=$(( $i + 1))
+done
+
+log_pass "zpool create cannot create pools specifying readonly properties"
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/usr/src/test/zfs-tests/tests/functional/cli_root/zpool_create/zpool_create_020_pos.ksh	Wed Dec 05 22:04:50 2012 -0500
@@ -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) 2012 by Delphix. All rights reserved.
+#
+
+. $STF_SUITE/include/libtest.shlib
+. $STF_SUITE/tests/functional/cli_root/zpool_create/zpool_create.cfg
+
+#
+# DESCRIPTION:
+#
+# zpool create -R works as expected
+#
+# STRATEGY:
+# 1. Create a -R altroot pool
+# 2. Verify the pool is mounted at the correct location
+# 3. Verify that cachefile=none for the pool
+# 4. Verify that root=<mountpoint> for the pool
+# 5. Verify that no reference to the pool is found in /etc/zfs/zpool.cache
+
+function cleanup
+{
+	if poolexists $TESTPOOL ; then
+                destroy_pool $TESTPOOL
+        fi
+	if [ -d ${TESTPOOL}.root ]
+	then
+		log_must $RMDIR ${TESTPOOL}.root
+	fi
+}
+
+log_onexit cleanup
+
+log_assert "zpool create -R works as expected"
+
+if [[ -n $DISK ]]; then
+	disk=$DISK
+else
+	disk=$DISK0
+fi
+
+log_must $MKDIR /${TESTPOOL}.root
+log_must $ZPOOL create -R /${TESTPOOL}.root $TESTPOOL $disk
+if [ ! -d /${TESTPOOL}.root ]
+then
+	log_fail "Mountpoint was not create when using zpool with -R flag!"
+fi
+
+FS=$($ZFS list $TESTPOOL)
+if [ -z "$FS" ]
+then
+	log_fail "Mounted filesystem at /${TESTPOOL}.root isn't ZFS!"
+fi
+
+log_must $ZPOOL get all $TESTPOOL
+$ZPOOL get all $TESTPOOL > /tmp/values.$$
+
+# check for the cachefile property, verifying that it's set to 'none'
+$GREP "$TESTPOOL[ ]*cachefile[ ]*none" /tmp/values.$$ > /dev/null 2>&1
+if [ $? -ne 0 ]
+then
+	log_fail "zpool property \'cachefile\' was not set to \'none\'."
+fi
+
+# check that the root = /mountpoint property is set correctly
+$GREP "$TESTPOOL[ ]*altroot[ ]*/${TESTPOOL}.root" /tmp/values.$$ > /dev/null 2>&1
+if [ $? -ne 0 ]
+then
+	log_fail "zpool property root was not found in pool output."
+fi
+
+$RM /tmp/values.$$
+
+# finally, check that the pool has no reference in /etc/zfs/zpool.cache
+if [[ -f /etc/zfs/zpool.cache ]] ; then
+	REF=$($STRINGS /etc/zfs/zpool.cache | $GREP ${TESTPOOL})
+	if [ ! -z "$REF" ]
+	then
+		$STRINGS /etc/zfs/zpool.cache
+		log_fail "/etc/zfs/zpool.cache appears to have a reference to $TESTPOOL"
+	fi
+fi
+
+
+log_pass "zpool create -R works as expected"
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/usr/src/test/zfs-tests/tests/functional/cli_root/zpool_create/zpool_create_021_pos.ksh	Wed Dec 05 22:04:50 2012 -0500
@@ -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 2009 Sun Microsystems, Inc.  All rights reserved.
+# Use is subject to license terms.
+#
+
+#
+# Copyright (c) 2012 by Delphix. All rights reserved.
+#
+
+. $STF_SUITE/include/libtest.shlib
+. $STF_SUITE/tests/functional/cli_root/zfs_create/zfs_create_common.kshlib
+
+#
+# DESCRIPTION:
+# 'zpool create -O property=value pool' can successfully create a pool
+# with correct filesystem property set.
+#
+# STRATEGY:
+# 1. Create a storage pool with -O option
+# 2. Verify the pool created successfully
+# 3. Verify the filesystem property is correctly set
+#
+
+verify_runnable "global"
+
+function cleanup
+{
+	datasetexists $TESTPOOL && destroy_pool $TESTPOOL
+}
+
+log_onexit cleanup
+
+log_assert "'zpool create -O property=value pool' can successfully create a pool \
+		with correct filesystem property set."
+
+set -A RW_FS_PROP "quota=512M" \
+		  "reservation=512M" \
+		  "recordsize=64K" \
+		  "mountpoint=/tmp/mnt$$" \
+		  "checksum=fletcher2" \
+		  "compression=lzjb" \
+		  "atime=off" \
+		  "devices=off" \
+		  "exec=off" \
+		  "setuid=off" \
+		  "readonly=on" \
+		  "snapdir=visible" \
+		  "aclmode=discard" \
+		  "aclinherit=discard" \
+		  "canmount=off" \
+		  "sharenfs=on" \
+		  "zoned=on"
+
+typeset -i i=0
+while (( $i < ${#RW_FS_PROP[*]} )); do
+	log_must $ZPOOL create -O ${RW_FS_PROP[$i]} -f $TESTPOOL $DISKS
+	datasetexists $TESTPOOL || \
+		log_fail "zpool create $TESTPOOL fail."
+	propertycheck $TESTPOOL ${RW_FS_PROP[i]} || \
+		log_fail "${RW_FS_PROP[i]} is failed to set."
+	log_must $ZPOOL destroy $TESTPOOL
+	(( i = i + 1 ))
+done
+
+log_pass "'zpool create -O property=value pool' can successfully create a pool \
+		with correct filesystem property set."
+
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/usr/src/test/zfs-tests/tests/functional/cli_root/zpool_create/zpool_create_022_pos.ksh	Wed Dec 05 22:04:50 2012 -0500
@@ -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) 2012 by Delphix. All rights reserved.
+#
+
+. $STF_SUITE/include/libtest.shlib
+. $STF_SUITE/tests/functional/cli_root/zfs_create/zfs_create_common.kshlib
+
+#
+# DESCRIPTION:
+# 'zpool create -O property=value pool' can successfully create a pool
+# with multiple filesystem properties set.
+#
+# STRATEGY:
+# 1. Create a storage pool with multiple -O options
+# 2. Verify the pool created successfully
+# 3. Verify the properties are correctly set
+#
+
+verify_runnable "global"
+
+function cleanup
+{
+	datasetexists $TESTPOOL && log_must $ZPOOL destroy $TESTPOOL
+}
+
+log_onexit cleanup
+
+log_assert "'zpool create -O property=value pool' can successfully create a pool \
+		with multiple filesystem properties set."
+
+set -A RW_FS_PROP "quota=512M" \
+		  "reservation=512M" \
+		  "recordsize=64K" \
+		  "mountpoint=/tmp/mnt$$" \
+		  "checksum=fletcher2" \
+		  "compression=lzjb" \
+		  "atime=off" \
+		  "devices=off" \
+		  "exec=off" \
+		  "setuid=off" \
+		  "readonly=on" \
+		  "snapdir=visible" \
+		  "aclmode=discard" \
+		  "aclinherit=discard" \
+		  "canmount=off" \
+		  "sharenfs=on"
+
+typeset -i i=0
+typeset opts=""
+
+while (( $i < ${#RW_FS_PROP[*]} )); do
+	opts="$opts -O ${RW_FS_PROP[$i]}"
+	(( i = i + 1 ))
+done
+
+log_must $ZPOOL create $opts -f $TESTPOOL $DISKS
+datasetexists $TESTPOOL || log_fail "zpool create $TESTPOOL fail."
+
+i=0
+while (( $i < ${#RW_FS_PROP[*]} )); do
+	propertycheck $TESTPOOL ${RW_FS_PROP[i]} || \
+			log_fail "${RW_FS_PROP[i]} is failed to set."
+	(( i = i + 1 ))
+done
+
+log_pass "'zpool create -O property=value pool' can successfully create a pool \
+		with multiple filesystem properties set."
+
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/usr/src/test/zfs-tests/tests/functional/cli_root/zpool_create/zpool_create_023_neg.ksh	Wed Dec 05 22:04:50 2012 -0500
@@ -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 2009 Sun Microsystems, Inc.  All rights reserved.
+# Use is subject to license terms.
+#
+
+. $STF_SUITE/include/libtest.shlib
+
+#
+# DESCRIPTION:
+# 'zpool create -O' should return an error with badly formed parameters.
+#
+# STRATEGY:
+# 1. Create an array of parameters with '-O'
+# 2. For each parameter in the array, execute 'zpool create -O'
+# 3. Verify an error is returned.
+#
+
+verify_runnable "global"
+
+function cleanup
+{
+	datasetexists $TESTPOOL && log_must $ZPOOL destroy $TESTPOOL
+}
+
+log_onexit cleanup
+
+set -A args "QuOta=none" "quota=non" "quota=abcd" "quota=0" "quota=" \
+    "ResErVaTi0n=none" "reserV=none" "reservation=abcd" "reserv=" \
+    "recorDSize=64k" "recordsize=256K" "recordsize=256" \
+    "recsize=" "recsize=zero" "recordsize=0" \
+    "mountPoint=/tmp/tmpfile$$" "mountpoint=non0" "mountpoint=" \
+    "mountpoint=LEGACY" "mounpoint=none" \
+    "sharenfs=ON" "ShareNFS=off" "sharenfs=sss" \
+    "checkSUM=on" "checksum=SHA256" "chsum=off" "checksum=aaa" \
+    "compression=of" "ComPression=lzjb" "compress=ON" "compress=a" \
+    "atime=ON" "ATime=off" "atime=bbb" \
+    "deviCes=on" "devices=OFF" "devices=aaa" \
+    "exec=ON" "EXec=off" "exec=aaa" \
+    "readonly=ON" "reADOnly=off" "rdonly=OFF" "rdonly=aaa" \
+    "zoned=ON" "ZoNed=off" "zoned=aaa" \
+    "snapdIR=hidden" "snapdir=VISible" "snapdir=aaa" \
+    "aclmode=DIScard" "aclmODE=groupmask" "aclmode=aaa" \
+    "aclinherit=deny" "aclinHerit=secure" "aclinherit=aaa" \
+    "type=volume" "type=snapshot" "type=filesystem" \
+    "creation=aaa" "used=10K" "available=10K" \
+    "referenced=10K" "compressratio=1.00x" \
+    "version=0" "version=1.234" "version=10K" "version=-1" \
+    "version=aaa" "version=999"
+
+log_assert "'zpool create -O' should return an error with badly formed parameters."
+
+typeset -i i=0
+while (( $i < ${#args[*]} )); do
+	log_mustnot $ZPOOL create -O ${args[i]} -f $TESTPOOL $DISKS
+	((i = i + 1))
+done
+
+log_pass "'zpool create -O' should return an error with badly formed parameters."
+
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/usr/src/test/zfs-tests/tests/functional/cli_root/zpool_create/zpool_create_features_001_pos.ksh	Wed Dec 05 22:04:50 2012 -0500
@@ -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 (c) 2012 by Delphix. All rights reserved.
+#
+
+. $STF_SUITE/include/libtest.shlib
+
+################################################################################
+#
+#  Newly created pools should have all features enabled.
+#  Specifying a feature to be enabled with '-o' should be a no-op.
+#
+#  1. Create a new pool.
+#  2. Verify that every feature@ property is in the 'enabled' or 'active' state
+#  3. Destroy the pool and create a new pool with
+#     '-o feature@async_destroy=enabled'
+#  4. Verify again.
+#
+################################################################################
+
+verify_runnable "global"
+
+function cleanup
+{
+	datasetexists $TESTPOOL && log_must $ZPOOL destroy $TESTPOOL
+}
+
+function check_features
+{
+	for state in $($ZPOOL get all $TESTPOOL | \
+	    $AWK '$2 ~ /feature@/ { print $3 }'); do
+		if [[ "$state" != "enabled" && "$state" != "active" ]]; then
+			log_fail "some features are not enabled on new pool"
+	        fi
+	done
+}
+
+log_onexit cleanup
+
+log_assert "'zpool create' creates pools with all features enabled"
+
+log_must $ZPOOL create -f $TESTPOOL $DISKS
+check_features
+log_must $ZPOOL destroy -f $TESTPOOL
+
+log_must $ZPOOL create -f -o feature@async_destroy=enabled $TESTPOOL $DISKS
+check_features
+
+log_pass "'zpool create' creates pools with all features enabled"
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/usr/src/test/zfs-tests/tests/functional/cli_root/zpool_create/zpool_create_features_002_pos.ksh	Wed Dec 05 22:04:50 2012 -0500
@@ -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 (c) 2012 by Delphix. All rights reserved.
+#
+
+. $STF_SUITE/include/libtest.shlib
+
+################################################################################
+#
+#  When using the '-d' option or specifying '-o version=X' new pools should
+#  have all features disabled.
+#
+#  1. Create a new pool with '-d'.
+#  2. Verify that every feature@ property is in the 'disabled' state
+#  3. Destroy pool and re-create with -o version=28
+#  4. Verify again.
+#
+################################################################################
+
+verify_runnable "global"
+
+function cleanup
+{
+	datasetexists $TESTPOOL && log_must $ZPOOL destroy $TESTPOOL
+}
+
+function check_features
+{
+	for prop in $($ZPOOL get all $TESTPOOL | $AWK '$2 ~ /feature@/ { print $2 }'); do
+		state=$($ZPOOL list -Ho "$prop" $TESTPOOL)
+                if [[ "$state" != "disabled" ]]; then
+			log_fail "$prop is enabled on new pool"
+	        fi
+	done
+}
+
+log_onexit cleanup
+
+log_assert "'zpool create -d' creates pools with all features disabled"
+
+log_must $ZPOOL create -f -d $TESTPOOL $DISKS
+check_features
+log_must $ZPOOL destroy -f $TESTPOOL
+
+log_must $ZPOOL create -f -o version=28 $TESTPOOL $DISKS
+check_features
+
+log_pass
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/usr/src/test/zfs-tests/tests/functional/cli_root/zpool_create/zpool_create_features_003_pos.ksh	Wed Dec 05 22:04:50 2012 -0500
@@ -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 (c) 2012 by Delphix. All rights reserved.
+#
+
+. $STF_SUITE/include/libtest.shlib
+
+################################################################################
+#
+#  When using the '-d' option with '-o feature@XXX=enabled' only the specified
+#  feature is enabled.
+#
+#  1. Create a new pool with '-d' and '-o feature@async_destroy=enabled'.
+#     async_destroy does not depend on anything so it should be the only
+#     feature that gets enabled.
+#  2. Verify that every feature@ property except feature@async_destroy is in
+#     the 'disabled' state
+#
+################################################################################
+
+verify_runnable "global"
+
+function cleanup
+{
+	datasetexists $TESTPOOL && log_must $ZPOOL destroy $TESTPOOL
+}
+
+log_onexit cleanup
+
+log_assert "'zpool create -d -o feature@async_destroy=enabled' only " \
+    "enables async_destroy"
+
+log_must $ZPOOL create -f -d -o feature@async_destroy=enabled $TESTPOOL $DISKS
+
+state=$($ZPOOL list -Ho feature@async_destroy $TESTPOOL)
+if [[ "$state" != "enabled" ]]; then
+	log_fail "async_destroy has state $state"
+fi
+
+for prop in $($ZPOOL get all $TESTPOOL | $AWK '$2 ~ /feature@/ { print $2 }'); do
+	state=$($ZPOOL list -Ho "$prop" $TESTPOOL)
+	if [[ "$prop" != "feature@async_destroy" \
+	    && "$state" != "disabled" ]]; then
+		log_fail "$prop is enabled on new pool"
+        fi
+done
+
+log_pass
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/usr/src/test/zfs-tests/tests/functional/cli_root/zpool_create/zpool_create_features_004_neg.ksh	Wed Dec 05 22:04:50 2012 -0500
@@ -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 (c) 2012 by Delphix. All rights reserved.
+#
+
+. $STF_SUITE/include/libtest.shlib
+
+################################################################################
+#
+#  Specifying invalid features/states should cause the create to fail.
+#
+#  1. Try to create the pool with a variety of invalid feature flags options.
+#  2. Verify no pool was created.
+#
+################################################################################
+
+verify_runnable "global"
+
+properties="feature@async_destroy=disabled " \
+    "feature@async_destroy=active " \
+    "feature@xxx_fake_xxx=enabled " \
+    "unsupported@some_feature=inactive " \
+    "unsupported@some_feature=readonly "
+
+function cleanup
+{
+	datasetexists $TESTPOOL && log_must $ZPOOL destroy $TESTPOOL
+}
+
+log_assert "'zpool create with invalid features fails"
+log_onexit cleanup
+
+for prop in $properties; do
+	log_mustnot $ZPOOL create -f -o "$prop" $TESTPOOL $DISKS
+	log_mustnot datasetexists $TESTPOOL
+done
+
+log_pass
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/usr/src/test/zfs-tests/tests/functional/cli_root/zpool_destroy/Makefile	Wed Dec 05 22:04:50 2012 -0500
@@ -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) 2012 by Delphix. All rights reserved.
+#
+
+include $(SRC)/Makefile.master
+
+ROOTOPTPKG = $(ROOT)/opt/zfs-tests
+TESTDIR = $(ROOTOPTPKG)/tests/functional/cli_root/zpool_destroy
+
+PROGS = zpool_destroy_001_pos \
+	zpool_destroy_002_pos \
+	zpool_destroy_003_neg
+
+FILES = zpool_destroy.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	Thu Jan 01 00:00:00 1970 +0000
+++ b/usr/src/test/zfs-tests/tests/functional/cli_root/zpool_destroy/zpool_destroy.cfg	Wed Dec 05 22:04:50 2012 -0500
@@ -0,0 +1,34 @@
+#
+# CDDL HEADER START
+#
+# The contents of this file are subject to the terms of the
+# Common Development and Distribution License (the "License").
+# You may not use this file except in compliance with the License.
+#
+# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
+# or http://www.opensolaris.org/os/licensing.
+# See the License for the specific language governing permissions
+# and limitations under the License.
+#
+# When distributing Covered Code, include this CDDL HEADER in each
+# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
+# If applicable, add the following below this CDDL HEADER, with the
+# fields enclosed by brackets "[]" replaced with your own identifying
+# information: Portions Copyright [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.
+#
+
+export DISK=${DISKS%% *}
+export SLICE0=0
+export SLICE1=1
+export SLICE_SIZE=500m
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/usr/src/test/zfs-tests/tests/functional/cli_root/zpool_destroy/zpool_destroy_001_pos.ksh	Wed Dec 05 22:04:50 2012 -0500
@@ -0,0 +1,87 @@
+#!/bin/ksh -p
+#
+# CDDL HEADER START
+#
+# The contents of this file are subject to the terms of the
+# Common Development and Distribution License (the "License").
+# You may not use this file except in compliance with the License.
+#
+# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
+# or http://www.opensolaris.org/os/licensing.
+# See the License for the specific language governing permissions
+# and limitations under the License.
+#
+# When distributing Covered Code, include this CDDL HEADER in each
+# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
+# If applicable, add the following below this CDDL 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) 2012 by Delphix. All rights reserved.
+#
+
+. $STF_SUITE/include/libtest.shlib
+. $STF_SUITE/tests/functional/cli_root/zpool_destroy/zpool_destroy.cfg
+
+
+#
+# DESCRIPTION:
+#	'zpool destroy <pool>' can successfully destroy the specified pool.
+#
+# STRATEGY:
+#	1. Create a storage pool
+#	2. Destroy the pool
+#	3. Verify the is destroyed successfully
+#
+
+verify_runnable "global"
+
+function cleanup
+{
+	poolexists $TESTPOOL2 && destroy_pool $TESTPOOL2
+	datasetexists $TESTPOOL1/$TESTVOL && \
+		log_must $ZFS destroy -f $TESTPOOL1/$TESTVOL
+
+	typeset pool
+	for pool in $TESTPOOL1 $TESTPOOL; do
+		poolexists $pool && destroy_pool $pool
+	done
+
+	zero_partitions $DISK
+}
+
+set -A datasets "$TESTPOOL" "$TESTPOOL2"
+
+if ! $(is_physical_device $DISKS) ; then
+	log_unsupported "This case cannot be run on raw files."
+fi
+
+log_assert "'zpool destroy <pool>' can destroy a specified pool."
+
+log_onexit cleanup
+
+partition_disk $SLICE_SIZE $DISK 2
+
+create_pool "$TESTPOOL" "${DISK}s${SLICE0}"
+create_pool "$TESTPOOL1" "${DISK}s${SLICE1}"
+log_must $ZFS create -s -V $VOLSIZE $TESTPOOL1/$TESTVOL
+create_pool "$TESTPOOL2" "/dev/zvol/dsk/$TESTPOOL1/$TESTVOL"
+
+typeset -i i=0
+while (( i < ${#datasets[*]} )); do
+	log_must poolexists "${datasets[i]}"
+	log_must $ZPOOL destroy "${datasets[i]}"
+	log_mustnot poolexists "${datasets[i]}"
+	((i = i + 1))
+done
+
+log_pass "'zpool destroy <pool>' executes successfully"
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/usr/src/test/zfs-tests/tests/functional/cli_root/zpool_destroy/zpool_destroy_002_pos.ksh	Wed Dec 05 22:04:50 2012 -0500
@@ -0,0 +1,117 @@
+#!/bin/ksh -p
+#
+# CDDL HEADER START
+#
+# The contents of this file are subject to the terms of the
+# Common Development and Distribution License (the "License").
+# You may not use this file except in compliance with the License.
+#
+# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
+# or http://www.opensolaris.org/os/licensing.
+# See the License for the specific language governing permissions
+# and limitations under the License.
+#
+# When distributing Covered Code, include this CDDL HEADER in each
+# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
+# If applicable, add the following below this CDDL 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) 2012 by Delphix. All rights reserved.
+#
+
+. $STF_SUITE/include/libtest.shlib
+. $STF_SUITE/tests/functional/cli_root/zpool_destroy/zpool_destroy.cfg
+
+#
+# DESCRIPTION:
+#	'zpool destroy -f <pool>' can forcely destroy the specified pool.
+#
+# STRATEGY:
+#	1. Create a storage pool
+#	2. Create some datasets within the pool
+#	3. Change directory to any mountpoint of these datasets,
+#	   Verify 'zpool destroy' without '-f' will fail.
+#	4. 'zpool destroy -f' the pool
+#	5. Verify the pool is destroyed successfully
+#
+
+verify_runnable "global"
+
+function cleanup
+{
+	[[ -n $cwd ]] && log_must cd $cwd
+
+	if [[ -d $TESTDIR ]]; then
+		ismounted $TESTDIR
+		((  $? == 0 )) && \
+			log_must $UNMOUNT $TESTDIR
+		log_must $RM -rf $TESTDIR
+	fi
+
+	typeset -i i=0
+	while (( $i < ${#datasets[*]} )); do
+		datasetexists ${datasets[i]} && \
+			log_must $ZFS destroy ${datasets[i]}
+		(( i = i + 1 ))
+	done
+
+	poolexists $TESTPOOL && destroy_pool $TESTPOOL
+}
+
+set -A datasets "$TESTPOOL/$TESTFS" "$TESTPOOL/$TESTCTR/$TESTFS1" \
+	"$TESTPOOL/$TESTCTR" "$TESTPOOL/$TESTVOL" \
+
+log_assert "'zpool destroy -f <pool>' can forcely destroy the specified pool"
+
+log_onexit cleanup
+
+typeset cwd=""
+
+create_pool "$TESTPOOL" "$DISK"
+log_must $ZFS create $TESTPOOL/$TESTFS
+log_must $MKDIR -p $TESTDIR
+log_must $ZFS set mountpoint=$TESTDIR $TESTPOOL/$TESTFS
+log_must $ZFS create $TESTPOOL/$TESTCTR
+log_must $ZFS create $TESTPOOL/$TESTCTR/$TESTFS1
+log_must $ZFS create -V $VOLSIZE $TESTPOOL/$TESTVOL
+
+typeset -i i=0
+while (( $i < ${#datasets[*]} )); do
+	datasetexists "${datasets[i]}" || \
+		log_fail "Create datasets fail."
+	((i = i + 1))
+done
+
+cwd=$PWD
+log_note "'zpool destroy' without '-f' will fail " \
+	"while pool is busy."
+
+for dir in $TESTDIR /$TESTPOOL/$TESTCTR /$TESTPOOL/$TESTCTR/$TESTFS1 ; do
+	log_must cd $dir
+	log_mustnot $ZPOOL destroy $TESTPOOL
+
+	# Need mount here, otherwise some dataset may be unmounted.
+	log_must $ZFS mount -a
+
+	i=0
+	while (( i < ${#datasets[*]} )); do
+		datasetexists "${datasets[i]}" || \
+			log_fail "Dataset ${datasets[i]} removed unexpected."
+		((i = i + 1))
+	done
+done
+
+destroy_pool $TESTPOOL
+log_mustnot poolexists "$TESTPOOL"
+
+log_pass "'zpool destroy -f <pool>' success."
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/usr/src/test/zfs-tests/tests/functional/cli_root/zpool_destroy/zpool_destroy_003_neg.ksh	Wed Dec 05 22:04:50 2012 -0500
@@ -0,0 +1,52 @@
+#!/bin/ksh -p
+#
+# CDDL HEADER START
+#
+# The contents of this file are subject to the terms of the
+# Common Development and Distribution License (the "License").
+# You may not use this file except in compliance with the License.
+#
+# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
+# or http://www.opensolaris.org/os/licensing.
+# See the License for the specific language governing permissions
+# and limitations under the License.
+#
+# When distributing Covered Code, include this CDDL HEADER in each
+# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
+# If applicable, add the following below this CDDL HEADER, with the
+# fields enclosed by brackets "[]" replaced with your own identifying
+# information: Portions Copyright [yyyy] [name of copyright owner]
+#
+# CDDL HEADER END
+#
+
+#
+# Copyright 2007 Sun Microsystems, Inc.  All rights reserved.
+# Use is subject to license terms.
+#
+. $STF_SUITE/include/libtest.shlib
+
+#
+# DESCRIPTION:
+#       'zpool destroy' should return an error with badly formed parameters,
+#
+# STRATEGY:
+#	1. Create an array of parameters
+#	2. For each parameter in the array, execute 'zpool destroy'
+#	3. Verify an error is returned.
+#
+
+verify_runnable "global"
+
+set -A args "" "-f" "-? $TESTPOOL" "nonexistent_pool" \
+	"$TESTPOOL abcd" "abcd $TESTPOOL"
+
+log_assert "'zpool destroy' should return an error with badly-formed parameters."
+
+typeset -i i=0
+while (( $i < ${#args[*]} )); do
+	log_mustnot $ZPOOL destroy ${args[i]}
+	((i = i + 1))
+done
+
+log_pass "'zpool destroy' badly formed parameters fail as expected."
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/usr/src/test/zfs-tests/tests/functional/cli_root/zpool_detach/Makefile	Wed Dec 05 22:04:50 2012 -0500
@@ -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) 2012 by Delphix. All rights reserved.
+#
+
+include $(SRC)/Makefile.master
+
+ROOTOPTPKG = $(ROOT)/opt/zfs-tests
+TESTDIR = $(ROOTOPTPKG)/tests/functional/cli_root/zpool_detach
+
+PROGS = cleanup \
+	setup \
+	zpool_detach_001_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	Thu Jan 01 00:00:00 1970 +0000
+++ b/usr/src/test/zfs-tests/tests/functional/cli_root/zpool_detach/cleanup.ksh	Wed Dec 05 22:04:50 2012 -0500
@@ -0,0 +1,32 @@
+#!/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.
+#
+
+. $STF_SUITE/include/libtest.shlib
+
+verify_runnable "global"
+
+default_cleanup
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/usr/src/test/zfs-tests/tests/functional/cli_root/zpool_detach/setup.ksh	Wed Dec 05 22:04:50 2012 -0500
@@ -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 2009 Sun Microsystems, Inc.  All rights reserved.
+# Use is subject to license terms.
+#
+
+. $STF_SUITE/include/libtest.shlib
+
+verify_runnable "global"
+verify_disk_count "$DISKS" 2
+
+DISK=${DISKS%% *}
+
+default_mirror_setup $DISKS
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/usr/src/test/zfs-tests/tests/functional/cli_root/zpool_detach/zpool_detach_001_neg.ksh	Wed Dec 05 22:04:50 2012 -0500
@@ -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.
+#
+. $STF_SUITE/include/libtest.shlib
+
+#
+# DESCRIPTION:
+# Executing 'zpool detach' command with bad options fails.
+#
+# STRATEGY:
+# 1. Create an array of badly formed 'zpool detach' options.
+# 2. Execute each element of the array.
+# 3. Verify an error code is returned.
+#
+
+verify_runnable "global"
+
+DISKLIST=$(get_disklist $TESTPOOL)
+
+set -A args "" "-?" "-t fakepool" "-f fakepool" "-ev fakepool" "fakepool" \
+	"$TESTPOOL" "$TESTPOOL/$TESTFS" "$TESTPOOL/$TESTFS $DISKLIST" \
+	"$TESTPOOL/$TESTCTR" "$TESTPOOL/$TESTCTR/$TESTFS1" \
+	"$TESTPOOL/$TESTCTR $DISKLIST" "$TESTPOOL/$TESTVOL" \
+	"$TESTPOOL/$TESTCTR/$TESTFS1 $DISKLIST" "$TESTPOOL/$TESTVOL $DISKLIST" \
+	"$DISKLIST"
+
+log_assert "Executing 'zpool detach' with bad options fails"
+
+if [[ -z $DISKLIST ]]; then
+	log_fail "DISKLIST is empty."
+fi
+
+typeset -i i=0
+
+while [[ $i -lt ${#args[*]} ]]; do
+
+	log_mustnot $ZPOOL detach ${args[$i]}
+
+	(( i = i + 1 ))
+done
+
+log_pass "'zpool detach' command with bad options failed as expected."
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/usr/src/test/zfs-tests/tests/functional/cli_root/zpool_expand/Makefile	Wed Dec 05 22:04:50 2012 -0500
@@ -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) 2012 by Delphix. All rights reserved.
+#
+
+include $(SRC)/Makefile.master
+
+ROOTOPTPKG = $(ROOT)/opt/zfs-tests
+TESTDIR = $(ROOTOPTPKG)/tests/functional/cli_root/zpool_expand
+
+PROGS = cleanup \
+	setup \
+	zpool_expand_001_pos \
+	zpool_expand_002_pos \
+	zpool_expand_003_neg
+
+FILES = zpool_expand.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	Thu Jan 01 00:00:00 1970 +0000
+++ b/usr/src/test/zfs-tests/tests/functional/cli_root/zpool_expand/cleanup.ksh	Wed Dec 05 22:04:50 2012 -0500
@@ -0,0 +1,32 @@
+#!/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.
+#
+
+. $STF_SUITE/include/libtest.shlib
+
+verify_runnable "global"
+
+default_cleanup
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/usr/src/test/zfs-tests/tests/functional/cli_root/zpool_expand/setup.ksh	Wed Dec 05 22:04:50 2012 -0500
@@ -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.
+#
+
+. $STF_SUITE/include/libtest.shlib
+
+verify_runnable "global"
+
+DISK=${DISKS%% *}
+
+default_setup $DISK
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/usr/src/test/zfs-tests/tests/functional/cli_root/zpool_expand/zpool_expand.cfg	Wed Dec 05 22:04:50 2012 -0500
@@ -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 2009 Sun Microsystems, Inc.  All rights reserved.
+# Use is subject to license terms.
+#
+
+#
+# Copyright (c) 2012 by Delphix. All rights reserved.
+#
+
+
+export org_size=1g
+export exp_size=2g
+
+export VFS=$TESTPOOL/$TESTFS
+
+export EX_1GB=1073741824
+export EX_3GB=3221225472
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/usr/src/test/zfs-tests/tests/functional/cli_root/zpool_expand/zpool_expand_001_pos.ksh	Wed Dec 05 22:04:50 2012 -0500
@@ -0,0 +1,146 @@
+#! /bin/ksh -p
+#
+# CDDL HEADER START
+#
+# The contents of this file are subject to the terms of the
+# Common Development and Distribution License (the "License").
+# You may not use this file except in compliance with the License.
+#
+# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
+# or http://www.opensolaris.org/os/licensing.
+# See the License for the specific language governing permissions
+# and limitations under the License.
+#
+# When distributing Covered Code, include this CDDL HEADER in each
+# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
+# If applicable, add the following below this CDDL 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) 2012 by Delphix. All rights reserved.
+#
+
+. $STF_SUITE/include/libtest.shlib
+. $STF_SUITE/tests/functional/cli_root/zpool_expand/zpool_expand.cfg
+
+#
+# DESCRIPTION:
+# Once zpool set autoexpand=on poolname, zpool can autoexpand by
+# Dynamic LUN Expansion
+#
+#
+# STRATEGY:
+# 1) Create a pool
+# 2) Create volume on top of the pool
+# 3) Create pool by using the zvols and set autoexpand=on
+# 4) Expand the vol size by 'zfs set volsize'
+# 5) Check that the pool size was expanded
+#
+
+verify_runnable "global"
+
+function cleanup
+{
+	if poolexists $TESTPOOL1; then
+		log_must $ZPOOL destroy $TESTPOOL1
+	fi
+
+	for i in 1 2 3; do
+		if datasetexists $VFS/vol$i; then
+			log_must $ZFS destroy $VFS/vol$i
+		fi
+	done
+}
+
+log_onexit cleanup
+
+log_assert "zpool can be autoexpanded after set autoexpand=on on LUN expansion"
+
+for i in 1 2 3; do
+	log_must $ZFS create -V $org_size $VFS/vol$i
+done
+
+for type in " " mirror raidz raidz2; do
+
+	log_must $ZPOOL create -o autoexpand=on $TESTPOOL1 $type \
+	    /dev/zvol/dsk/$VFS/vol1  /dev/zvol/dsk/$VFS/vol2 \
+	    /dev/zvol/dsk/$VFS/vol3
+
+	typeset autoexp=$(get_pool_prop autoexpand $TESTPOOL1)
+	if [[ $autoexp != "on" ]]; then
+		log_fail "zpool $TESTPOOL1 autoexpand should on but is $autoexp"
+	fi
+
+	typeset prev_size=$(get_pool_prop size $TESTPOOL1)
+	typeset zfs_prev_size=$($ZFS get -p avail $TESTPOOL1 | $TAIL -1 | \
+	    $AWK '{print $3}')
+
+	for i in 1 2 3; do
+		log_must $ZFS set volsize=$exp_size $VFS/vol$i
+	done
+
+	$SYNC
+	$SLEEP 10
+	$SYNC
+
+	typeset expand_size=$(get_pool_prop size $TESTPOOL1)
+	typeset zfs_expand_size=$($ZFS get -p avail $TESTPOOL1 | $TAIL -1 | \
+	    $AWK '{print $3}')
+
+	log_note "$TESTPOOL1 $type has previous size: $prev_size and " \
+	    "expanded size: $expand_size"
+	# compare available pool size from zfs
+	if [[ $zfs_expand_size > $zfs_prev_size ]]; then
+	# check for zpool history for the pool size expansion
+		if [[ $type == " " ]]; then
+			typeset	size_addition=$($ZPOOL history -il $TESTPOOL1 |\
+			    $GREP "pool '$TESTPOOL1' size:" | \
+			    $GREP "vdev online" | \
+			    $GREP "(+${EX_1GB}" | wc -l)
+
+			if [[ $size_addition -ne $i ]]; then
+				log_fail "pool $TESTPOOL1 is not autoexpand " \
+				    "after LUN expansion"
+			fi
+		elif [[ $type == "mirror" ]]; then
+			$ZPOOL history -il $TESTPOOL1 | \
+			    $GREP "pool '$TESTPOOL1' size:" | \
+			    $GREP "vdev online" | \
+			    $GREP "(+${EX_1GB})" >/dev/null 2>&1
+
+			if [[ $? -ne 0 ]] ; then
+				log_fail "pool $TESTPOOL1 is not autoexpand " \
+				    "after LUN expansion"
+			fi
+		else
+			$ZPOOL history -il $TESTPOOL1 | \
+			    $GREP "pool '$TESTPOOL1' size:" | \
+			    $GREP "vdev online" | \
+			    $GREP "(+${EX_3GB})" >/dev/null 2>&1
+
+			if [[ $? -ne 0 ]]; then
+				log_fail "pool $TESTPOOL is not autoexpand " \
+				    "after LUN expansion"
+			fi
+		fi
+	else
+		log_fail "pool $TESTPOOL1 is not autoexpanded after LUN " \
+		    "expansion"
+	fi
+
+	log_must $ZPOOL destroy $TESTPOOL1
+	for i in 1 2 3; do
+		log_must $ZFS set volsize=$org_size $VFS/vol$i
+	done
+
+done
+log_pass "zpool can be autoexpanded after set autoexpand=on on LUN expansion"
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/usr/src/test/zfs-tests/tests/functional/cli_root/zpool_expand/zpool_expand_002_pos.ksh	Wed Dec 05 22:04:50 2012 -0500
@@ -0,0 +1,148 @@
+#! /bin/ksh -p
+#
+# CDDL HEADER START
+#
+# The contents of this file are subject to the terms of the
+# Common Development and Distribution License (the "License").
+# You may not use this file except in compliance with the License.
+#
+# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
+# or http://www.opensolaris.org/os/licensing.
+# See the License for the specific language governing permissions
+# and limitations under the License.
+#
+# When distributing Covered Code, include this CDDL HEADER in each
+# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
+# If applicable, add the following below this CDDL 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) 2012 by Delphix. All rights reserved.
+#
+
+. $STF_SUITE/include/libtest.shlib
+. $STF_SUITE/tests/functional/cli_root/zpool_expand/zpool_expand.cfg
+
+#
+# DESCRIPTION:
+# After zpool online -e poolname zvol vdevs, zpool can autoexpand by
+# Dynamic LUN Expansion
+#
+#
+# STRATEGY:
+# 1) Create a pool
+# 2) Create volume on top of the pool
+# 3) Create pool by using the zvols
+# 4) Expand the vol size by zfs set volsize
+# 5  Use zpool online -e to online the zvol vdevs
+# 6) Check that the pool size was expaned
+#
+
+verify_runnable "global"
+
+function cleanup
+{
+        if poolexists $TESTPOOL1; then
+                log_must $ZPOOL destroy $TESTPOOL1
+        fi
+
+	for i in 1 2 3; do
+		if datasetexists $VFS/vol$i; then
+			log_must $ZFS destroy $VFS/vol$i
+		fi
+	done
+}
+
+log_onexit cleanup
+
+log_assert "zpool can expand after zpool online -e zvol vdevs on LUN expansion"
+
+for i in 1 2 3; do
+	log_must $ZFS create -V $org_size $VFS/vol$i
+done
+
+for type in " " mirror raidz raidz2; do
+	log_must $ZPOOL create $TESTPOOL1 $type /dev/zvol/dsk/$VFS/vol1 \
+	    /dev/zvol/dsk/$VFS/vol2 /dev/zvol/dsk/$VFS/vol3
+
+	typeset autoexp=$(get_pool_prop autoexpand $TESTPOOL1)
+
+	if [[ $autoexp != "off" ]]; then
+		log_fail "zpool $TESTPOOL1 autoexpand should off but is " \
+		    "$autoexp"
+	fi
+	typeset prev_size=$(get_pool_prop size $TESTPOOL1)
+	typeset zfs_prev_size=$($ZFS get -p avail $TESTPOOL1 | $TAIL -1 | \
+	    $AWK '{print $3}')
+
+	for i in 1 2 3; do
+		log_must $ZFS set volsize=$exp_size $VFS/vol$i
+	done
+
+	for i in 1 2 3; do
+		log_must $ZPOOL online -e $TESTPOOL1 /dev/zvol/dsk/$VFS/vol$i
+	done
+
+	$SYNC
+	$SLEEP 10
+	$SYNC
+
+	typeset expand_size=$(get_pool_prop size $TESTPOOL1)
+	typeset zfs_expand_size=$($ZFS get -p avail $TESTPOOL1 | $TAIL -1 | \
+	    $AWK '{print $3}')
+	log_note "$TESTPOOL1 $type has previous size: $prev_size and " \
+	    "expanded size: $expand_size"
+
+	# compare available pool size from zfs
+	if [[ $zfs_expand_size > $zfs_prev_size ]]; then
+	# check for zpool history for the pool size expansion
+		if [[ $type == " " ]]; then
+			typeset	size_addition=$($ZPOOL history -il $TESTPOOL1 \
+			    | $GREP "pool '$TESTPOOL1' size:" | \
+			    $GREP "vdev online" | \
+			    $GREP "(+${EX_1GB}" | wc -l)
+
+			if [[ $size_addition -ne $i ]]; then
+				log_fail "pool $TESTPOOL1 is not autoexpand " \
+				    "after LUN expansion"
+			fi
+		elif [[ $type == "mirror" ]]; then
+			$ZPOOL history -il $TESTPOOL1 | \
+			    $GREP "pool '$TESTPOOL1' size:" | \
+			    $GREP "vdev online" | \
+			    $GREP "(+${EX_1GB})" >/dev/null 2>&1
+
+			if [[ $? -ne 0 ]]; then
+				log_fail "pool $TESTPOOL1 is not autoexpand " \
+				    "after LUN expansion"
+			fi
+		else
+			$ZPOOL history -il $TESTPOOL1 | \
+			    $GREP "pool '$TESTPOOL1' size:" | \
+			    $GREP "vdev online" | \
+			    $GREP "(+${EX_3GB})" >/dev/null 2>&1
+
+			if [[ $? -ne 0 ]] ; then
+				log_fail "pool $TESTPOOL1 is not autoexpand " \
+				    "after LUN expansion"
+			fi
+		fi
+	else
+		log_fail "pool $TESTPOOL1 is not autoexpanded after LUN " \
+		    "expansion"
+	fi
+	log_must $ZPOOL destroy $TESTPOOL1
+	for i in 1 2 3; do
+		log_must $ZFS set volsize=$org_size $VFS/vol$i
+	done
+done
+log_pass "zpool can expand after zpool online -e zvol vdevs on LUN expansion"
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/usr/src/test/zfs-tests/tests/functional/cli_root/zpool_expand/zpool_expand_003_neg.ksh	Wed Dec 05 22:04:50 2012 -0500
@@ -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 2009 Sun Microsystems, Inc.  All rights reserved.
+# Use is subject to license terms.
+#
+
+#
+# Copyright (c) 2012 by Delphix. All rights reserved.
+#
+
+. $STF_SUITE/include/libtest.shlib
+. $STF_SUITE/tests/functional/cli_root/zpool_expand/zpool_expand.cfg
+
+#
+# Description:
+# Once set zpool autoexpand=off, zpool can *NOT* autoexpand by
+# Dynamic LUN Expansion
+#
+#
+# STRATEGY:
+# 1) Create a pool
+# 2) Create volumes on top of the pool
+# 3) Create pool by using the zvols and set autoexpand=off
+# 4) Expand the vol size by zfs set volsize
+# 5) Check that the pool size is not changed
+#
+
+verify_runnable "global"
+
+function cleanup
+{
+        if poolexists $TESTPOOL1; then
+                log_must $ZPOOL destroy $TESTPOOL1
+        fi
+
+	for i in 1 2 3; do
+		if datasetexists $VFS/vol$i; then
+			log_must $ZFS destroy $VFS/vol$i
+		fi
+	done
+}
+
+log_onexit cleanup
+
+log_assert "zpool can not expand if set autoexpand=off after LUN expansion"
+
+for i  in 1 2 3; do
+	log_must $ZFS create -V $org_size $VFS/vol$i
+done
+
+for type in " " mirror raidz raidz2; do
+	log_must $ZPOOL create $TESTPOOL1 $type /dev/zvol/dsk/$VFS/vol1 \
+	    /dev/zvol/dsk/$VFS/vol2 /dev/zvol/dsk/$VFS/vol3
+
+	typeset autoexp=$(get_pool_prop autoexpand $TESTPOOL1)
+	if [[ $autoexp != "off" ]]; then
+		log_fail "zpool $TESTPOOL1 autoexpand should off but is " \
+		    "$autoexp"
+	fi
+
+	typeset prev_size=$(get_pool_prop size $TESTPOOL1)
+
+	for i in 1 2 3; do
+		log_must $ZFS set volsize=$exp_size $VFS/vol$i
+	done
+
+	$SYNC
+	$SLEEP 10
+	$SYNC
+
+	# check for zpool history for the pool size expansion
+	$ZPOOL history -il $TESTPOOL1 | $GREP "pool '$TESTPOOL1' size:" | \
+	    $GREP "vdev online" >/dev/null 2>&1
+
+	if [[ $? -eq 0 ]]; then
+		log_fail "pool $TESTPOOL1 is not autoexpand after LUN " \
+		    "expansion"
+	fi
+
+	typeset expand_size=$(get_pool_prop size $TESTPOOL1)
+
+	if [[ "$prev_size" != "$expand_size" ]]; then
+		log_fail "pool $TESTPOOL1 size changed after LUN expansion"
+	fi
+
+	log_must $ZPOOL destroy $TESTPOOL1
+
+	for i in 1 2 3; do
+		log_must $ZFS set volsize=$org_size $VFS/vol$i
+	done
+
+done
+
+log_pass "zpool can not expand if set autoexpand=off after LUN expansion"
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/usr/src/test/zfs-tests/tests/functional/cli_root/zpool_export/Makefile	Wed Dec 05 22:04:50 2012 -0500
@@ -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) 2012 by Delphix. All rights reserved.
+#
+
+include $(SRC)/Makefile.master
+
+ROOTOPTPKG = $(ROOT)/opt/zfs-tests
+TESTDIR = $(ROOTOPTPKG)/tests/functional/cli_root/zpool_export
+
+PROGS = cleanup \
+	setup \
+	zpool_export_001_pos \
+	zpool_export_002_pos \
+	zpool_export_003_neg \
+	zpool_export_004_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	Thu Jan 01 00:00:00 1970 +0000
+++ b/usr/src/test/zfs-tests/tests/functional/cli_root/zpool_export/cleanup.ksh	Wed Dec 05 22:04:50 2012 -0500
@@ -0,0 +1,30 @@
+#!/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.
+#
+
+. $STF_SUITE/include/libtest.shlib
+
+default_cleanup
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/usr/src/test/zfs-tests/tests/functional/cli_root/zpool_export/setup.ksh	Wed Dec 05 22:04:50 2012 -0500
@@ -0,0 +1,32 @@
+#!/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.
+#
+
+. $STF_SUITE/include/libtest.shlib
+
+DISK=${DISKS%% *}
+
+default_setup $DISK
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/usr/src/test/zfs-tests/tests/functional/cli_root/zpool_export/zpool_export_001_pos.ksh	Wed Dec 05 22:04:50 2012 -0500
@@ -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.
+#
+. $STF_SUITE/include/libtest.shlib
+
+#
+# DESCRIPTION:
+# Exported pools should no longer be visible from 'zpool list'.
+# Therefore, we export an existing pool and verify it cannot
+# be accessed.
+#
+# STRATEGY:
+# 1. Unmount the test directory.
+# 2. Export the pool.
+# 3. Verify the pool is no longer present in the list output.
+#
+
+verify_runnable "global"
+
+function cleanup
+{
+	typeset dir=$(get_device_dir $DISKS)
+
+	datasetexists "$TESTPOOL/$TESTFS" || \
+		log_must $ZPOOL import -d $dir $TESTPOOL
+
+	ismounted "$TESTPOOL/$TESTFS"
+	(( $? != 0 )) && \
+	    log_must $ZFS mount $TESTPOOL/$TESTFS
+}
+
+log_onexit cleanup
+
+log_assert "Verify a pool can be exported."
+
+log_must $ZFS umount $TESTDIR
+log_must $ZPOOL export $TESTPOOL
+
+poolexists $TESTPOOL && \
+        log_fail "$TESTPOOL unexpectedly found in 'zpool list' output."
+
+log_pass "Successfully exported a ZPOOL."
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/usr/src/test/zfs-tests/tests/functional/cli_root/zpool_export/zpool_export_002_pos.ksh	Wed Dec 05 22:04:50 2012 -0500
@@ -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.
+#
+. $STF_SUITE/include/libtest.shlib
+
+#
+# DESCRIPTION:
+# The 'zpool export' command must fail when a pool is
+# busy i.e. mounted.
+#
+# STRATEGY:
+# 1. Try and export the default pool when mounted and busy.
+# 2. Verify an error is returned.
+#
+
+verify_runnable "global"
+
+function cleanup
+{
+	typeset dir=$(get_device_dir $DISKS)
+	cd $olddir || \
+	    log_fail "Couldn't cd back to $olddir"
+
+	datasetexists "$TESTPOOL/$TESTFS" || \
+	    log_must $ZPOOL import -d $dir $TESTPOOL
+
+	ismounted "$TESTPOOL/$TESTFS"
+	(( $? != 0 )) && \
+	    log_must $ZFS mount $TESTPOOL/$TESTFS
+
+	[[ -e $TESTDIR/$TESTFILE0 ]] && \
+	    log_must $RM -rf $TESTDIR/$TESTFILE0
+}
+
+olddir=$PWD
+
+log_onexit cleanup
+
+log_assert "Verify a busy ZPOOL cannot be exported."
+
+ismounted "$TESTPOOL/$TESTFS"
+(( $? != 0 )) && \
+    log_fail "$TESTDIR not mounted. Unable to continue."
+
+cd $TESTDIR || \
+    log_fail "Couldn't cd to $TESTDIR"
+
+log_mustnot $ZPOOL export $TESTPOOL
+
+poolexists $TESTPOOL || \
+	log_fail "$TESTPOOL not found in 'zpool list' output."
+
+log_pass "Unable to export a busy ZPOOL as expected."
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/usr/src/test/zfs-tests/tests/functional/cli_root/zpool_export/zpool_export_003_neg.ksh	Wed Dec 05 22:04:50 2012 -0500
@@ -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.
+#
+. $STF_SUITE/include/libtest.shlib
+
+#
+# DESCRIPTION:
+#       'zpool export' should return an error with badly formed parameters,
+#
+# STRATEGY:
+#	1. Create an array of parameters
+#	2. For each parameter in the array, execute 'zpool export'
+#	3. Verify an error is returned.
+#
+
+verify_runnable "global"
+
+function cleanup
+{
+	typeset dir=$(get_device_dir $DISKS)
+	datasetexists "$TESTPOOL/$TESTFS" || \
+		log_must $ZPOOL import -d $dir $TESTPOOL
+
+	ismounted "$TESTPOOL/$TESTFS"
+	(( $? != 0 )) && \
+	    log_must $ZFS mount $TESTPOOL/$TESTFS
+}
+
+log_onexit cleanup
+
+set -A args "" "-f" "-? $TESTPOOL" "-QWERTYUIO $TESTPOOL"
+
+log_assert "'zpool export' should return an error with badly-formed parameters."
+
+typeset -i i=0
+while (( $i < ${#args[*]} )); do
+	log_mustnot $ZPOOL export ${args[i]}
+	((i = i + 1))
+done
+
+log_pass "'zpool export' badly formed parameters fail as expected."
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/usr/src/test/zfs-tests/tests/functional/cli_root/zpool_export/zpool_export_004_pos.ksh	Wed Dec 05 22:04:50 2012 -0500
@@ -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.
+#
+
+. $STF_SUITE/include/libtest.shlib
+
+#
+# DESCRIPTION:
+#	Verify zpool export succeed or fail with spare.
+#
+# STRATEGY:
+#	1. Create two mirror pools with same spare.
+#	2. Verify zpool export one pool succeed.
+#	3. Import the pool.
+#	4. Replace one device with the spare and detach it in one pool.
+#	5. Verify zpool export the pool succeed.
+#	6. Import the pool.
+#	7. Replace one device with the spare in one pool.
+#	8. Verify zpool export the pool fail.
+#	9. Verify zpool export the pool with "-f" succeed.
+#	10. Import the pool.
+#
+
+verify_runnable "global"
+
+function cleanup
+{
+	mntpnt=$(get_prop mountpoint $TESTPOOL)
+        datasetexists $TESTPOOL1 || log_must $ZPOOL import -d $mntpnt $TESTPOOL1
+	datasetexists $TESTPOOL1 && destroy_pool $TESTPOOL1
+	datasetexists $TESTPOOL2 && destroy_pool $TESTPOOL2
+	typeset -i i=0
+	while ((i < 5)); do
+		if [[ -e $mntpnt/vdev$i ]]; then
+			log_must $RM -f $mntpnt/vdev$i
+		fi
+		((i += 1))
+	done
+}
+
+
+log_assert "Verify zpool export succeed or fail with spare."
+log_onexit cleanup
+
+mntpnt=$(get_prop mountpoint $TESTPOOL)
+
+typeset -i i=0
+while ((i < 5)); do
+	log_must $MKFILE 64M $mntpnt/vdev$i
+	eval vdev$i=$mntpnt/vdev$i
+	((i += 1))
+done
+
+log_must $ZPOOL create $TESTPOOL1 mirror $vdev0 $vdev1 spare $vdev4
+log_must $ZPOOL create $TESTPOOL2 mirror $vdev2 $vdev3 spare $vdev4
+
+log_must $ZPOOL export $TESTPOOL1
+log_must $ZPOOL import -d $mntpnt $TESTPOOL1
+
+log_must $ZPOOL replace $TESTPOOL1 $vdev0 $vdev4
+log_must $ZPOOL detach $TESTPOOL1 $vdev4
+log_must $ZPOOL export $TESTPOOL1
+log_must $ZPOOL import -d $mntpnt $TESTPOOL1
+
+log_must $ZPOOL replace $TESTPOOL1 $vdev0 $vdev4
+log_mustnot $ZPOOL export $TESTPOOL1
+
+log_must $ZPOOL export -f $TESTPOOL1
+log_must $ZPOOL import -d $mntpnt  $TESTPOOL1
+
+log_pass "Verify zpool export succeed or fail with spare."
+
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/usr/src/test/zfs-tests/tests/functional/cli_root/zpool_get/Makefile	Wed Dec 05 22:04:50 2012 -0500
@@ -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) 2012 by Delphix. All rights reserved.
+#
+
+include $(SRC)/Makefile.master
+
+ROOTOPTPKG = $(ROOT)/opt/zfs-tests
+TESTDIR = $(ROOTOPTPKG)/tests/functional/cli_root/zpool_get
+
+PROGS = cleanup \
+	setup \
+	zpool_get_001_pos \
+	zpool_get_002_pos \
+	zpool_get_003_pos \
+	zpool_get_004_neg
+
+FILES = zpool_get.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	Thu Jan 01 00:00:00 1970 +0000
+++ b/usr/src/test/zfs-tests/tests/functional/cli_root/zpool_get/cleanup.ksh	Wed Dec 05 22:04:50 2012 -0500
@@ -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) 2012 by Delphix. All rights reserved.
+#
+
+. $STF_SUITE/include/libtest.shlib
+
+verify_runnable "both"
+
+default_cleanup
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/usr/src/test/zfs-tests/tests/functional/cli_root/zpool_get/setup.ksh	Wed Dec 05 22:04:50 2012 -0500
@@ -0,0 +1,37 @@
+#!/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.
+#
+
+. $STF_SUITE/include/libtest.shlib
+verify_runnable "both"
+
+DISK=${DISKS%% *}
+
+default_setup $DISK
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/usr/src/test/zfs-tests/tests/functional/cli_root/zpool_get/zpool_get.cfg	Wed Dec 05 22:04:50 2012 -0500
@@ -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 2009 Sun Microsystems, Inc.  All rights reserved.
+# Use is subject to license terms.
+#
+
+#
+# Copyright (c) 2012 by Delphix. All rights reserved.
+#
+
+# Set the expected properties of zpool
+typeset -a properties=("size" "capacity" "altroot" "health" "guid" "version"
+    "bootfs" "delegation" "autoreplace" "cachefile" "dedupditto" "dedupratio"
+    "free" "allocated" "readonly" "comment" "expandsize" "freeing" "failmode"
+    "listsnapshots" "autoexpand" "feature@async_destroy" "feature@empty_bpobj")
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/usr/src/test/zfs-tests/tests/functional/cli_root/zpool_get/zpool_get_001_pos.ksh	Wed Dec 05 22:04:50 2012 -0500
@@ -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 2008 Sun Microsystems, Inc.  All rights reserved.
+# Use is subject to license terms.
+#
+
+. $STF_SUITE/include/libtest.shlib
+
+#
+# DESCRIPTION:
+#
+# Zpool get usage message is displayed when called with no arguments
+#
+# STRATEGY:
+#	1. Run zpool get
+#	2. Check that exit status is set to 2
+#	3. Check usage message contains text "usage"
+#
+
+log_assert "Zpool get usage message is displayed when called with no arguments."
+
+$ZPOOL get > /dev/null 2>&1
+RET=$?
+if [ $RET != 2 ]
+then
+	log_fail "\"zpool get\" exit status $RET should be equal to 2."
+fi
+
+OUTPUT=$($ZPOOL get 2>&1 | $GREP -i usage)
+RET=$?
+if [ $RET != 0 ]
+then
+	log_fail "Usage message for zpool get did not contain the word 'usage'."
+fi
+
+log_pass "Zpool get usage message is displayed when called with no arguments."
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/usr/src/test/zfs-tests/tests/functional/cli_root/zpool_get/zpool_get_002_pos.ksh	Wed Dec 05 22:04:50 2012 -0500
@@ -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.
+#
+
+. $STF_SUITE/include/libtest.shlib
+. $STF_SUITE/tests/functional/cli_root/zpool_get/zpool_get.cfg
+
+#
+# DESCRIPTION:
+#
+# zpool get all works as expected
+#
+# STRATEGY:
+#
+# 1. Using zpool get, retrieve all default values
+# 2. Verify that the header is printed
+# 3. Verify that we can see all the properties we expect to see
+# 4. Verify that the total output contains just those properties + header.
+#
+# Test for those properties are expected to check whether their
+# default values are sane, or whether they can be changed with zpool set.
+#
+
+log_assert "Zpool get all works as expected"
+
+typeset -i i=0;
+
+if ! is_global_zone ; then
+	TESTPOOL=${TESTPOOL%%/*}
+fi
+
+log_must $ZPOOL get all $TESTPOOL
+$ZPOOL get all $TESTPOOL > /tmp/values.$$
+
+log_note "Checking zpool get all output for a header."
+$GREP ^"NAME " /tmp/values.$$ > /dev/null 2>&1
+if [ $? -ne 0 ]
+then
+	log_fail "The header was not printed from zpool get all"
+fi
+
+
+while [ $i -lt "${#properties[@]}" ]
+do
+	log_note "Checking for ${properties[$i]} property"
+	$GREP "$TESTPOOL *${properties[$i]}" /tmp/values.$$ > /dev/null 2>&1
+	if [ $? -ne 0 ]
+	then
+		log_fail "zpool property ${properties[$i]} was not found\
+ in pool output."
+	fi
+	i=$(( $i + 1 ))
+done
+
+# increment the counter to include the header line
+i=$(( $i + 1 ))
+
+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."
+fi
+
+
+
+$RM /tmp/values.$$
+log_pass "Zpool get all works as expected"
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/usr/src/test/zfs-tests/tests/functional/cli_root/zpool_get/zpool_get_003_pos.ksh	Wed Dec 05 22:04:50 2012 -0500
@@ -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.
+#
+
+. $STF_SUITE/include/libtest.shlib
+. $STF_SUITE/tests/functional/cli_root/zpool_get/zpool_get.cfg
+
+#
+# DESCRIPTION:
+#
+# Zpool get returns values for all known properties
+#
+# STRATEGY:
+# 1. For all properties, verify zpool get retrieves a value
+#
+
+log_assert "Zpool get returns values for all known properties"
+
+if ! is_global_zone ; then
+	TESTPOOL=${TESTPOOL%%/*}
+fi
+
+typeset -i i=0;
+
+while [ $i -lt "${#properties[@]}" ]
+do
+	log_note "Checking for ${properties[$i]} property"
+	log_must eval "$ZPOOL get ${properties[$i]} $TESTPOOL > /tmp/value.$$"
+	$GREP "${properties[$i]}" /tmp/value.$$ > /dev/null 2>&1
+	if [ $? -ne 0 ]
+	then
+		log_fail "${properties[$i]} not seen in output"
+	fi
+	$GREP "^NAME " /tmp/value.$$ > /dev/null 2>&1
+	# only need to check this once.
+	if [ $i -eq 0 ] && [ $? -ne 0 ]
+	then
+		log_fail "Header not seen in zpool get output"
+	fi
+	i=$(( $i + 1 ))
+done
+
+$RM /tmp/value.$$
+log_pass "Zpool get returns values for all known properties"
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/usr/src/test/zfs-tests/tests/functional/cli_root/zpool_get/zpool_get_004_neg.ksh	Wed Dec 05 22:04:50 2012 -0500
@@ -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 2008 Sun Microsystems, Inc.  All rights reserved.
+# Use is subject to license terms.
+#
+
+. $STF_SUITE/include/libtest.shlib
+
+#
+# DESCRIPTION:
+#
+# Malformed zpool get commands are rejected
+#
+# STRATEGY:
+#
+# 1. Run several different "zpool get" commands that should fail.
+#
+
+log_assert "Malformed zpool get commands are rejected"
+
+if ! is_global_zone ; then
+	TESTPOOL=${TESTPOOL%%/*}
+fi
+
+set -A arguments "$TESTPOOL $TESTPOOL" "$TESTPOOL rubbish" "-v $TESTPOOL" \
+		"nosuchproperty $TESTPOOL" "--$TESTPOOL" "all all" \
+		"type $TESTPOOL" "usage: $TESTPOOL" "bootfs $TESTPOOL@" \
+		"bootfs,bootfs $TESTPOOL" "name $TESTPOOL" "t%d%s" \
+		"bootfs,delegation $TESTPOOL" "delegation $TESTPOOL@"
+
+for arg in $arguments
+do
+	log_mustnot $ZPOOL get $arg
+done
+
+log_pass "Malformed zpool get commands are rejected"
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/usr/src/test/zfs-tests/tests/functional/cli_root/zpool_history/Makefile	Wed Dec 05 22:04:50 2012 -0500
@@ -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) 2012 by Delphix. All rights reserved.
+#
+
+include $(SRC)/Makefile.master
+
+ROOTOPTPKG = $(ROOT)/opt/zfs-tests
+TESTDIR = $(ROOTOPTPKG)/tests/functional/cli_root/zpool_history
+
+PROGS = cleanup \
+	setup \
+	zpool_history_001_neg \
+	zpool_history_002_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	Thu Jan 01 00:00:00 1970 +0000
+++ b/usr/src/test/zfs-tests/tests/functional/cli_root/zpool_history/cleanup.ksh	Wed Dec 05 22:04:50 2012 -0500
@@ -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) 2012 by Delphix. All rights reserved.
+#
+
+. $STF_SUITE/include/libtest.shlib
+
+default_cleanup
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/usr/src/test/zfs-tests/tests/functional/cli_root/zpool_history/setup.ksh	Wed Dec 05 22:04:50 2012 -0500
@@ -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) 2012 by Delphix. All rights reserved.
+#
+
+. $STF_SUITE/include/libtest.shlib
+
+DISK=${DISKS%% *}
+default_container_volume_setup $DISK
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/usr/src/test/zfs-tests/tests/functional/cli_root/zpool_history/zpool_history_001_neg.ksh	Wed Dec 05 22:04:50 2012 -0500
@@ -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.
+#
+
+. $STF_SUITE/include/libtest.shlib
+
+#
+# DESCRIPTION:
+#	Verify 'zpool history' can deal with non-existent pools and garbage
+#	to the command.
+#
+# STRATEGY:
+#	1. Create pool, volume & snap
+#	2. Verify 'zpool history' can cope with incorret arguments.
+#
+
+verify_runnable "global"
+
+snap=$TESTPOOL/$TESTFS@snap
+clone=$TESTPOOL/clone
+
+set -A neg_opt "$TESTPOOL/$TESTCTR" "$TESTPOOL/$TESTVOL" "-t $TESTPOOL" \
+	"-v $TESTPOOL" "$snap" "$clone" "nonexist" "TESTPOOL"
+
+function cleanup
+{
+	datasetexists $clone && log_must $ZFS destroy $clone
+	datasetexists $snap && log_must $ZFS destroy $snap
+}
+
+log_assert "Verify 'zpool history' can deal with non-existent pools and " \
+	"garbage to the command."
+log_onexit cleanup
+
+log_must $ZFS snapshot $snap
+log_must $ZFS clone $snap $clone
+
+for opt in "${neg_opt[@]}"; do
+	log_mustnot eval "$ZPOOL history $opt > /dev/null"
+done
+
+log_pass "'zpool history' command line negation test passed."
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/usr/src/test/zfs-tests/tests/functional/cli_root/zpool_history/zpool_history_002_pos.ksh	Wed Dec 05 22:04:50 2012 -0500
@@ -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 2007 Sun Microsystems, Inc.  All rights reserved.
+# Use is subject to license terms.
+#
+
+#
+# Copyright (c) 2012 by Delphix. All rights reserved.
+#
+
+. $STF_SUITE/include/libtest.shlib
+
+#
+# DESCRIPTION:
+#	Verify zpool history can handle options [-il] correctly.
+#
+# STRATEGY:
+#	1. Create varied combinations of option -i & -l.
+#	2. Verify 'zpool history' can cope with these combination correctly.
+#
+
+verify_runnable "global"
+
+log_assert "Verify zpool history can handle options [-il] correctly."
+
+options="-i -l -il -li -lil -ili -lli -iill -liil"
+
+for opt in $options; do
+	log_must eval "$ZPOOL history $opt $TESTPOOL > /dev/null 2>&1"
+done
+
+log_pass "Verify zpool history can handle options [-il] passed."
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/usr/src/test/zfs-tests/tests/functional/cli_root/zpool_import/Makefile	Wed Dec 05 22:04:50 2012 -0500
@@ -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) 2012 by Delphix. All rights reserved.
+#
+
+include $(SRC)/Makefile.master
+
+ROOTOPTPKG = $(ROOT)/opt/zfs-tests
+TESTDIR = $(ROOTOPTPKG)/tests/functional/cli_root/zpool_import
+
+PROGS = cleanup \
+	setup \
+	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 \
+	zpool_import_rename_001_pos
+
+FILES = zpool_import.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)
+
+SUBDIRS = blockfiles
+
+include $(SRC)/test/Makefile.com
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/usr/src/test/zfs-tests/tests/functional/cli_root/zpool_import/blockfiles/Makefile	Wed Dec 05 22:04:50 2012 -0500
@@ -0,0 +1,36 @@
+#
+# 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) 2012 by Delphix. All rights reserved.
+#
+
+include $(SRC)/Makefile.master
+
+ROOTOPTPKG = $(ROOT)/opt/zfs-tests
+BLOCKFILESDIR = $(ROOTOPTPKG)/tests/functional/cli_root/zpool_import/blockfiles
+
+FILES = unclean_export.dat.bz2
+
+CMDS = $(FILES:%=$(BLOCKFILESDIR)/%)
+$(CMDS) := FILEMODE = 0444
+
+all lint clean clobber:
+
+install: $(CMDS)
+
+$(CMDS): $(BLOCKFILESDIR)
+
+$(BLOCKFILESDIR):
+	$(INS.dir)
+
+$(BLOCKFILESDIR)/%: %
+	$(INS.file)
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/usr/src/test/zfs-tests/tests/functional/cli_root/zpool_import/blockfiles/README	Wed Dec 05 22:04:50 2012 -0500
@@ -0,0 +1,29 @@
+#
+# CDDL HEADER START
+#
+# The contents of this file are subject to the terms of the
+# Common Development and Distribution License (the "License").
+# You may not use this file except in compliance with the License.
+#
+# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
+# or http://www.opensolaris.org/os/licensing.
+# See the License for the specific language governing permissions
+# and limitations under the License.
+#
+# When distributing Covered Code, include this CDDL HEADER in each
+# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
+# If applicable, add the following below this CDDL HEADER, with the
+# fields enclosed by brackets "[]" replaced with your own identifying
+# information: Portions Copyright [yyyy] [name of copyright owner]
+#
+# CDDL HEADER END
+#
+
+#
+# Copyright (c) 2012 by Delphix. All rights reserved.
+#
+
+Unless otherwise noted, all files in this distribution are released
+under the Common Development and Distribution License (CDDL).
+
+This directory contains compressed blockfiles for zpool import testing.
Binary file usr/src/test/zfs-tests/tests/functional/cli_root/zpool_import/blockfiles/unclean_export.dat.bz2 has changed
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/usr/src/test/zfs-tests/tests/functional/cli_root/zpool_import/cleanup.ksh	Wed Dec 05 22:04:50 2012 -0500
@@ -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) 2012 by Delphix. All rights reserved.
+#
+
+. $STF_SUITE/include/libtest.shlib
+. $STF_SUITE/tests/functional/cli_root/zpool_import/zpool_import.cfg
+
+verify_runnable "global"
+
+for pool in "$TESTPOOL" "$TESTPOOL1"; do
+	datasetexists $pool/$TESTFS && \
+		log_must $ZFS destroy -Rf $pool/$TESTFS
+	destroy_pool "$pool"
+done
+
+ismounted $DEVICE_DIR ufs
+(( $? == 0 )) && log_must $UMOUNT -f $DEVICE_DIR
+
+for dir in "$TESTDIR" "$TESTDIR1" "$DEVICE_DIR" ; do
+	[[ -d $dir ]] && \
+		log_must $RM -rf $dir
+done
+
+# recreate and destroy a zpool over the disks to restore the partitions to
+# normal
+case $DISK_COUNT in
+0|1)
+	log_note "No disk devices to restore"
+	;;
+*)
+	log_must cleanup_devices $ZFS_DISK1
+	log_must cleanup_devices $ZFS_DISK2
+	;;
+esac
+
+log_pass
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/usr/src/test/zfs-tests/tests/functional/cli_root/zpool_import/setup.ksh	Wed Dec 05 22:04:50 2012 -0500
@@ -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) 2012 by Delphix. All rights reserved.
+#
+
+. $STF_SUITE/include/libtest.shlib
+. $STF_SUITE/tests/functional/cli_root/zpool_import/zpool_import.cfg
+
+verify_runnable "global"
+verify_disk_count "$DISKS" 2
+
+DISK=${DISKS%% *}
+
+for dev in $ZFS_DISK1 $ZFS_DISK2 ; do
+	log_must cleanup_devices $dev
+done
+
+typeset -i i=0
+while (( i <= $GROUP_NUM )); do
+	if (( i == 2 )); then
+		(( i = i + 1 ))
+		continue
+	fi
+	log_must set_partition $i "$cyl" $SLICE_SIZE $ZFS_DISK1
+	cyl=$(get_endslice $ZFS_DISK1 $i)
+	(( i = i + 1 ))
+done
+
+create_pool "$TESTPOOL" "$ZFSSIDE_DISK1"
+
+if [[ -d $TESTDIR ]]; then
+	$RM -rf $TESTDIR  || log_unresolved Could not remove $TESTDIR
+	$MKDIR -p $TESTDIR || log_unresolved Could not create $TESTDIR
+fi
+
+log_must $ZFS create $TESTPOOL/$TESTFS
+log_must $ZFS set mountpoint=$TESTDIR $TESTPOOL/$TESTFS
+
+$ECHO "y" | $NEWFS -v /dev/rdsk/$ZFSSIDE_DISK2 >/dev/null 2>&1
+(( $? != 0 )) &&
+	log_untested "Unable to setup a UFS file system"
+
+[[ ! -d $DEVICE_DIR ]] && \
+	log_must $MKDIR -p $DEVICE_DIR
+
+log_must $MOUNT /dev/dsk/$ZFSSIDE_DISK2 $DEVICE_DIR
+
+i=0
+while (( i < $MAX_NUM )); do
+	log_must $MKFILE $FILE_SIZE ${DEVICE_DIR}/${DEVICE_FILE}$i
+	(( i = i + 1 ))
+done
+
+log_pass
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/usr/src/test/zfs-tests/tests/functional/cli_root/zpool_import/zpool_import.cfg	Wed Dec 05 22:04:50 2012 -0500
@@ -0,0 +1,85 @@
+#
+# CDDL HEADER START
+#
+# The contents of this file are subject to the terms of the
+# Common Development and Distribution License (the "License").
+# You may not use this file except in compliance with the License.
+#
+# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
+# or http://www.opensolaris.org/os/licensing.
+# See the License for the specific language governing permissions
+# and limitations under the License.
+#
+# When distributing Covered Code, include this CDDL HEADER in each
+# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
+# If applicable, add the following below this CDDL 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.
+#
+
+. $STF_SUITE/include/libtest.shlib
+
+typeset -a disk_array=($(find_disks $DISKS))
+case "${#disk_array[*]}" in
+0)
+	#
+	# on stf_configure, disk_freelist returns empty.
+	#
+	DISK_COUNT=0
+	;;
+1)
+	# We need to repartition the single disk to two slices.
+	DISK_COUNT=1
+	ZFS_DISK1=${disk_array[0]}
+	ZFSSIDE_DISK1=${ZFS_DISK1}s0
+	ZFS_DISK2=${disk_array[0]}
+	ZFSSIDE_DISK2=${ZFS_DISK2}s1
+	;;
+*)
+	# We need to repartition the single disk to two slices.
+	DISK_COUNT=2
+	ZFS_DISK1=${disk_array[0]}
+	ZFSSIDE_DISK1=${ZFS_DISK1}s0
+	ZFS_DISK2=${disk_array[1]}
+	ZFSSIDE_DISK2=${ZFS_DISK2}s0
+	;;
+esac
+
+export DISK_COUNT ZFS_DISK1 ZFSSIDE_DISK1 ZFS_DISK2 ZFSSIDE_DISK2
+
+export FS_SIZE=2gb
+export FILE_SIZE=64m
+export SLICE_SIZE=128m
+export MAX_NUM=5
+export GROUP_NUM=3
+export DEVICE_DIR=/dev_import-test
+export BACKUP_DEVICE_DIR=/bakdev_import-test
+export DEVICE_FILE=disk
+export DEVICE_ARCHIVE=archive_import-test
+export MYTESTFILE=$STF_SUITE/include/libtest.shlib
+
+typeset -i num=0
+while (( num < $GROUP_NUM )); do
+	DEVICE_FILES="$DEVICE_FILES ${DEVICE_DIR}/${DEVICE_FILE}$num"
+	(( num = num + 1 ))
+done
+export DEVICE_FILES
+
+export VDEV0=$DEVICE_DIR/${DEVICE_FILE}0
+export VDEV1=$DEVICE_DIR/${DEVICE_FILE}1
+export VDEV2=$DEVICE_DIR/${DEVICE_FILE}2
+export VDEV3=$DEVICE_DIR/${DEVICE_FILE}3
+export VDEV4=$DEVICE_DIR/${DEVICE_FILE}4
+
+export ALTER_ROOT=/alter_import-test
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/usr/src/test/zfs-tests/tests/functional/cli_root/zpool_import/zpool_import_001_pos.ksh	Wed Dec 05 22:04:50 2012 -0500
@@ -0,0 +1,138 @@
+#!/bin/ksh -p
+#
+# CDDL HEADER START
+#
+# The contents of this file are subject to the terms of the
+# Common Development and Distribution License (the "License").
+# You may not use this file except in compliance with the License.
+#
+# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
+# or http://www.opensolaris.org/os/licensing.
+# See the License for the specific language governing permissions
+# and limitations under the License.
+#
+# When distributing Covered Code, include this CDDL HEADER in each
+# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
+# If applicable, add the following below this CDDL HEADER, with the
+# fields enclosed by brackets "[]" replaced with your own identifying
+# information: Portions Copyright [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.
+#
+
+. $STF_SUITE/include/libtest.shlib
+. $STF_SUITE/tests/functional/cli_root/zfs_mount/zfs_mount.kshlib
+. $STF_SUITE/tests/functional/cli_root/zpool_import/zpool_import.cfg
+
+#
+# DESCRIPTION:
+# Once a pool has been exported, it should be recreated after a
+# successful import. Verify that is true.
+#
+# STRATEGY:
+#	1. Populate the default test directory and unmount it.
+#	2. Export the default test pool.
+#	3. Import it using the various combinations.
+#		- Regular import
+#		- Alternate Root Specified
+#	   Try to import it by name or guid randomly.
+#	4. Verify it shows up under 'zpool list'.
+#	5. Verify it can be mounted again and contains a file.
+#
+
+verify_runnable "global"
+
+set -A pools "$TESTPOOL" "$TESTPOOL1"
+set -A devs "" "-d $DEVICE_DIR"
+set -A options "" "-R $ALTER_ROOT"
+set -A mtpts "$TESTDIR" "$TESTDIR1"
+
+
+function cleanup
+{
+	typeset -i i=0
+
+	while (( i < ${#pools[*]} )); do
+		poolexists ${pools[i]} && \
+			log_must $ZPOOL export ${pools[i]}
+
+		datasetexists "${pools[i]}/$TESTFS" || \
+			log_must $ZPOOL import ${devs[i]} ${pools[i]}
+
+		ismounted "${pools[i]}/$TESTFS" || \
+			log_must $ZFS mount ${pools[i]}/$TESTFS
+
+		[[ -e ${mtpts[i]}/$TESTFILE0 ]] && \
+			log_must $RM -rf ${mtpts[i]}/$TESTFILE0
+
+		((i = i + 1))
+	done
+
+	cleanup_filesystem $TESTPOOL1 $TESTFS
+
+        destroy_pool $TESTPOOL1
+
+	[[ -d $ALTER_ROOT ]] && \
+		log_must $RM -rf $ALTER_ROOT
+}
+
+log_onexit cleanup
+
+log_assert "Verify that an exported pool can be imported."
+
+setup_filesystem "$DEVICE_FILES" $TESTPOOL1 $TESTFS $TESTDIR1
+
+checksum1=$($SUM $MYTESTFILE | $AWK '{print $1}')
+
+typeset -i i=0
+typeset -i j=0
+typeset basedir
+
+while (( i < ${#pools[*]} )); do
+	guid=$(get_config ${pools[i]} pool_guid)
+	log_must $CP $MYTESTFILE ${mtpts[i]}/$TESTFILE0
+
+	log_must $ZFS umount ${mtpts[i]}
+
+	j=0
+	while (( j <  ${#options[*]} )); do
+		log_must $ZPOOL export ${pools[i]}
+
+		typeset target=${pools[i]}
+		if (( RANDOM % 2 == 0 )) ; then
+			target=$guid
+			log_note "Import by guid."
+		fi
+		log_must $ZPOOL import ${devs[i]} ${options[j]} $target
+
+		log_must poolexists ${pools[i]}
+
+		log_must ismounted ${pools[i]}/$TESTFS
+
+		basedir=${mtpts[i]}
+		[[ -n ${options[j]} ]] && \
+			basedir=$ALTER_ROOT/${mtpts[i]}
+
+		[[ ! -e $basedir/$TESTFILE0 ]] && \
+			log_fail "$basedir/$TESTFILE0 missing after import."
+
+		checksum2=$($SUM $basedir/$TESTFILE0 | $AWK '{print $1}')
+		[[ "$checksum1" != "$checksum2" ]] && \
+			log_fail "Checksums differ ($checksum1 != $checksum2)"
+
+		((j = j + 1))
+	done
+
+	((i = i + 1))
+done
+
+log_pass "Successfully imported a ZPOOL"
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/usr/src/test/zfs-tests/tests/functional/cli_root/zpool_import/zpool_import_002_pos.ksh	Wed Dec 05 22:04:50 2012 -0500
@@ -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 2007 Sun Microsystems, Inc.  All rights reserved.
+# Use is subject to license terms.
+#
+
+#
+# Copyright (c) 2012 by Delphix. All rights reserved.
+#
+
+. $STF_SUITE/include/libtest.shlib
+. $STF_SUITE/tests/functional/cli_root/zfs_mount/zfs_mount.kshlib
+. $STF_SUITE/tests/functional/cli_root/zpool_import/zpool_import.cfg
+
+#
+# DESCRIPTION:
+# Verify that an exported pool cannot be imported
+# more than once.
+#
+# STRATEGY:
+#	1. Populate the default test directory and unmount it.
+#	2. Export the default test pool.
+#	3. Import it using the various combinations.
+#		- Regular import
+#		- Alternate Root Specified
+#	4. Verify it shows up under 'zpool list'.
+#	5. Verify it contains a file.
+#	6. Attempt to import it for a second time. Verify this fails.
+#
+
+verify_runnable "global"
+
+set -A pools "$TESTPOOL" "$TESTPOOL1"
+set -A devs "" "-d $DEVICE_DIR"
+set -A options "" "-R $ALTER_ROOT"
+set -A mtpts "$TESTDIR" "$TESTDIR1"
+
+
+function cleanup
+{
+	typeset -i i=0
+	while (( i < ${#pools[*]} )); do
+		poolexists ${pools[i]} && \
+			log_must $ZPOOL export ${pools[i]}
+
+		datasetexists "${pools[i]}/$TESTFS" || \
+			log_must $ZPOOL import ${devs[i]} ${pools[i]}
+
+		ismounted "${pools[i]}/$TESTFS" || \
+			log_must $ZFS mount ${pools[i]}/$TESTFS
+
+		[[ -e ${mtpts[i]}/$TESTFILE0 ]] && \
+			log_must $RM -rf ${mtpts[i]}/$TESTFILE0
+
+		((i = i + 1))
+	done
+
+	cleanup_filesystem $TESTPOOL1 $TESTFS
+
+	destroy_pool $TESTPOOL1
+
+	[[ -d $ALTER_ROOT ]] && \
+		log_must $RM -rf $ALTER_ROOT
+}
+
+log_onexit cleanup
+
+log_assert "Verify that an exported pool cannot be imported more than once."
+
+setup_filesystem "$DEVICE_FILES" $TESTPOOL1 $TESTFS $TESTDIR1
+
+checksum1=$($SUM $MYTESTFILE | $AWK '{print $1}')
+
+typeset -i i=0
+typeset -i j=0
+typeset basedir
+
+while (( i < ${#pools[*]} )); do
+	guid=$(get_config ${pools[i]} pool_guid)
+
+	log_must $CP $MYTESTFILE ${mtpts[i]}/$TESTFILE0
+
+	log_must $ZFS umount ${mtpts[i]}
+
+	j=0
+	while (( j <  ${#options[*]} )); do
+		log_must $ZPOOL export ${pools[i]}
+
+		typeset target=${pools[i]}
+		if (( RANDOM % 2 == 0 )) ; then
+			target=$guid
+			log_note "Import by guid."
+		fi
+
+		log_must $ZPOOL import ${devs[i]} ${options[j]} $target
+
+		log_must poolexists ${pools[i]}
+
+		log_must ismounted ${pools[i]}/$TESTFS
+
+		basedir=${mtpts[i]}
+		[[ -n ${options[j]} ]] && \
+			basedir=$ALTER_ROOT/${mtpts[i]}
+
+		[[ ! -e $basedir/$TESTFILE0 ]] && \
+			log_fail "$basedir/$TESTFILE0 missing after import."
+
+		checksum2=$($SUM $basedir/$TESTFILE0 | $AWK '{print $1}')
+		[[ "$checksum1" != "$checksum2" ]] && \
+			log_fail "Checksums differ ($checksum1 != $checksum2)"
+
+		log_mustnot $ZPOOL import ${devs[i]} $target
+
+		((j = j + 1))
+	done
+
+	((i = i + 1))
+
+done
+
+log_pass "Unable to import the same pool twice as expected."
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/usr/src/test/zfs-tests/tests/functional/cli_root/zpool_import/zpool_import_003_pos.ksh	Wed Dec 05 22:04:50 2012 -0500
@@ -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) 2012 by Delphix. All rights reserved.
+#
+
+. $STF_SUITE/include/libtest.shlib
+. $STF_SUITE/tests/functional/cli_root/zpool_import/zpool_import.cfg
+
+#
+# DESCRIPTION:
+#	Destroyed pools are not listed unless with -D option is specified.
+#
+# STRATEGY:
+#	1. Create test pool A.
+#	2. Destroy pool A.
+#	3. Verify only 'import -D' can list pool A.
+#
+
+verify_runnable "global"
+
+function cleanup
+{
+	destroy_pool $TESTPOOL1
+
+	log_must $RM $VDEV0 $VDEV1
+	log_must $MKFILE $FILE_SIZE $VDEV0 $VDEV1
+}
+
+log_assert "Destroyed pools are not listed unless with -D option is specified."
+log_onexit cleanup
+
+log_must $ZPOOL create $TESTPOOL1 $VDEV0 $VDEV1
+log_must $ZPOOL destroy $TESTPOOL1
+
+#
+# 'pool:' is the keywords of 'zpool import -D' output.
+#
+log_mustnot eval "$ZPOOL import -d $DEVICE_DIR | $GREP pool:"
+log_must eval "$ZPOOL import -d $DEVICE_DIR -D | $GREP pool:"
+
+log_pass "Destroyed pool only can be listed with -D option."
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/usr/src/test/zfs-tests/tests/functional/cli_root/zpool_import/zpool_import_004_pos.ksh	Wed Dec 05 22:04:50 2012 -0500
@@ -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) 2012 by Delphix. All rights reserved.
+#
+
+. $STF_SUITE/include/libtest.shlib
+. $STF_SUITE/tests/functional/cli_root/zpool_import/zpool_import.cfg
+
+#
+# DESCRIPTION:
+#	Destroyed pools devices was moved to another directory, it still can be
+#	imported correctly.
+#
+# STRATEGY:
+#	1. Create test pool A with several devices.
+#	2. Destroy pool A.
+#	3. Move devices to another directory.
+#	4. Verify 'zpool import -D' succeed.
+#
+
+verify_runnable "global"
+
+function cleanup
+{
+	destroy_pool $TESTPOOL1
+
+	log_must $RM -rf $DEVICE_DIR/*
+	typeset i=0
+	while (( i < $MAX_NUM )); do
+		log_must $MKFILE $FILE_SIZE ${DEVICE_DIR}/${DEVICE_FILE}$i
+		((i += 1))
+	done
+}
+
+log_assert "Destroyed pools devices was moved to another directory," \
+	"it still can be imported correctly."
+log_onexit cleanup
+
+log_must $ZPOOL create $TESTPOOL1 $VDEV0 $VDEV1 $VDEV2
+typeset guid=$(get_config $TESTPOOL1 pool_guid)
+typeset target=$TESTPOOL1
+if (( RANDOM % 2 == 0 )) ; then
+	target=$guid
+	log_note "Import by guid."
+fi
+log_must $ZPOOL destroy $TESTPOOL1
+
+log_note "Devices was moved to different directories."
+log_must $MKDIR $DEVICE_DIR/newdir1 $DEVICE_DIR/newdir2
+log_must $MV $VDEV1 $DEVICE_DIR/newdir1
+log_must $MV $VDEV2 $DEVICE_DIR/newdir2
+log_must $ZPOOL import -d $DEVICE_DIR/newdir1 -d $DEVICE_DIR/newdir2 \
+	-d $DEVICE_DIR -D -f $target
+log_must $ZPOOL destroy -f $TESTPOOL1
+
+log_note "Devices was moved to same directory."
+log_must $MV $VDEV0 $DEVICE_DIR/newdir2
+log_must $MV $DEVICE_DIR/newdir1/* $DEVICE_DIR/newdir2
+log_must $ZPOOL import -d $DEVICE_DIR/newdir2 -D -f $target
+log_must $ZPOOL destroy -f $TESTPOOL1
+
+log_pass "Destroyed pools devices was moved, 'zpool import -D' passed."
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/usr/src/test/zfs-tests/tests/functional/cli_root/zpool_import/zpool_import_005_pos.ksh	Wed Dec 05 22:04:50 2012 -0500
@@ -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) 2012 by Delphix. All rights reserved.
+#
+
+. $STF_SUITE/include/libtest.shlib
+. $STF_SUITE/tests/functional/cli_root/zpool_import/zpool_import.cfg
+
+#
+# DESCRIPTION:
+#	Destroyed pools devices was renamed, it still can be imported correctly.
+#
+# STRATEGY:
+#	1. Create test pool A with several devices.
+#	2. Destroy pool A and rename devices name.
+#	3. Verify 'zpool import -D' succeed.
+#
+
+verify_runnable "global"
+
+function cleanup
+{
+	destroy_pool $TESTPOOL1
+
+	log_must $RM -rf $DEVICE_DIR/*
+	typeset i=0
+	while (( i < $MAX_NUM )); do
+		log_must $MKFILE $FILE_SIZE ${DEVICE_DIR}/${DEVICE_FILE}$i
+		((i += 1))
+	done
+}
+
+log_assert "Destroyed pools devices was renamed, it still can be imported " \
+	"correctly."
+log_onexit cleanup
+
+log_must $ZPOOL create $TESTPOOL1 $VDEV0 $VDEV1 $VDEV2
+typeset guid=$(get_config $TESTPOOL1 pool_guid)
+typeset target=$TESTPOOL1
+if (( RANDOM % 2 == 0 )) ; then
+	target=$guid
+	log_note "Import by guid."
+fi
+log_must $ZPOOL destroy $TESTPOOL1
+
+log_note "Part of devices was renamed in the same directory."
+log_must $MV $VDEV0 $DEVICE_DIR/vdev0-new
+log_must $ZPOOL import -d $DEVICE_DIR -D -f $target
+log_must $ZPOOL destroy -f $TESTPOOL1
+
+log_note "All of devices was rename to different directories."
+log_must $MKDIR $DEVICE_DIR/newdir1 $DEVICE_DIR/newdir2
+log_must $MV $VDEV1 $DEVICE_DIR/newdir1/vdev1-new
+log_must $MV $VDEV2 $DEVICE_DIR/newdir2/vdev2-new
+log_must $ZPOOL import -d $DEVICE_DIR/newdir1 -d $DEVICE_DIR/newdir2 \
+	-d $DEVICE_DIR -D -f $target
+log_must $ZPOOL destroy -f $TESTPOOL1
+
+log_pass "Destroyed pools devices was renamed, 'zpool import -D' passed."
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/usr/src/test/zfs-tests/tests/functional/cli_root/zpool_import/zpool_import_006_pos.ksh	Wed Dec 05 22:04:50 2012 -0500
@@ -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) 2012 by Delphix. All rights reserved.
+#
+
+. $STF_SUITE/include/libtest.shlib
+. $STF_SUITE/tests/functional/cli_root/zpool_import/zpool_import.cfg
+
+#
+# DESCRIPTION:
+#	For mirror, N-1 destroyed pools devices was removed or used by other
+#	pool, it still can be imported correctly.
+#
+# STRATEGY:
+#	1. Create mirror with N disks.
+#	2. Destroy this mirror.
+#	3. Create another pool with N-1 disks which was used by this mirror.
+#	4. Verify import mirror can succeed.
+#
+
+verify_runnable "global"
+
+function cleanup
+{
+	destroy_pool $TESTPOOL2
+	destroy_pool $TESTPOOL1
+
+	log_must $RM -rf $DEVICE_DIR/*
+	typeset i=0
+	while (( i < $MAX_NUM )); do
+		log_must $MKFILE $FILE_SIZE ${DEVICE_DIR}/${DEVICE_FILE}$i
+		((i += 1))
+	done
+}
+
+log_assert "For mirror, N-1 destroyed pools devices was removed or used " \
+	"by other pool, it still can be imported correctly."
+log_onexit cleanup
+
+log_must $ZPOOL create $TESTPOOL1 mirror $VDEV0 $VDEV1 $VDEV2
+typeset guid=$(get_config $TESTPOOL1 pool_guid)
+typeset target=$TESTPOOL1
+if (( RANDOM % 2 == 0 )) ; then
+	target=$guid
+	log_note "Import by guid."
+fi
+log_must $ZPOOL destroy $TESTPOOL1
+
+log_must $ZPOOL create $TESTPOOL2 $VDEV0 $VDEV2
+log_must $ZPOOL import -d $DEVICE_DIR -D -f $target
+log_must $ZPOOL destroy $TESTPOOL1
+
+log_must $ZPOOL destroy $TESTPOOL2
+log_must $RM -rf $VDEV2
+log_must $ZPOOL import -d $DEVICE_DIR -D -f $target
+
+log_pass "zpool import -D mirror passed."
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/usr/src/test/zfs-tests/tests/functional/cli_root/zpool_import/zpool_import_007_pos.ksh	Wed Dec 05 22:04:50 2012 -0500
@@ -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) 2012 by Delphix. All rights reserved.
+#
+
+. $STF_SUITE/include/libtest.shlib
+. $STF_SUITE/tests/functional/cli_root/zpool_import/zpool_import.cfg
+
+#
+# DESCRIPTION:
+#	For raidz, one destroyed pools devices was removed or used by other
+#	pool, it still can be imported correctly.
+#
+# STRATEGY:
+#	1. Create a raidz pool A with N disks.
+#	2. Destroy this pool A.
+#	3. Create another pool B with 1 disk which was used by pool A.
+#	4. Verify import this raidz pool can succeed.
+#
+
+verify_runnable "global"
+
+function cleanup
+{
+	destroy_pool $TESTPOOL2
+	destroy_pool $TESTPOOL1
+
+	log_must $RM -rf $DEVICE_DIR/*
+	typeset i=0
+	while (( i < $MAX_NUM )); do
+		log_must $MKFILE $FILE_SIZE ${DEVICE_DIR}/${DEVICE_FILE}$i
+		((i += 1))
+	done
+}
+
+log_assert "For raidz, one destroyed pools devices was removed or used by " \
+	"other pool, it still can be imported correctly."
+log_onexit cleanup
+
+log_must $ZPOOL create $TESTPOOL1 raidz $VDEV0 $VDEV1 $VDEV2 $VDIV3
+typeset guid=$(get_config $TESTPOOL1 pool_guid)
+typeset target=$TESTPOOL1
+if (( RANDOM % 2 == 0 )) ; then
+	target=$guid
+	log_note "Import by guid."
+fi
+log_must $ZPOOL destroy $TESTPOOL1
+
+log_must $ZPOOL create $TESTPOOL2 $VDEV0
+log_must $ZPOOL import -d $DEVICE_DIR -D -f $target
+log_must $ZPOOL destroy $TESTPOOL1
+
+log_must $ZPOOL destroy $TESTPOOL2
+log_must $RM -rf $VDEV0
+log_must $ZPOOL import -d $DEVICE_DIR -D -f $target
+log_must $ZPOOL destroy $TESTPOOL1
+
+log_note "For raidz, two destroyed pool's devices were used, import failed."
+log_must $MKFILE $FILE_SIZE $VDEV0
+log_must $ZPOOL create $TESTPOOL2 $VDEV0 $VDEV1
+log_mustnot $ZPOOL import -d $DEVICE_DIR -D -f $target
+log_must $ZPOOL destroy $TESTPOOL2
+
+log_pass "zpool import -D raidz passed."
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/usr/src/test/zfs-tests/tests/functional/cli_root/zpool_import/zpool_import_008_pos.ksh	Wed Dec 05 22:04:50 2012 -0500
@@ -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) 2012 by Delphix. All rights reserved.
+#
+
+. $STF_SUITE/include/libtest.shlib
+. $STF_SUITE/tests/functional/cli_root/zpool_import/zpool_import.cfg
+
+#
+# DESCRIPTION:
+#	For raidz2, two destroyed pool's devices were removed or used by other
+#	pool, it still can be imported correctly.
+#
+# STRATEGY:
+#	1. Create a raidz2 pool A with N disks.
+#	2. Destroy this pool A.
+#	3. Create another pool B with two disks which were used by pool A.
+#	4. Verify import this raidz2 pool can succeed.
+#
+
+verify_runnable "global"
+
+function cleanup
+{
+	destroy_pool $TESTPOOL2
+	destroy_pool $TESTPOOL1
+
+	log_must $RM -rf $DEVICE_DIR/*
+	typeset i=0
+	while (( i < $MAX_NUM )); do
+		log_must $MKFILE $FILE_SIZE ${DEVICE_DIR}/${DEVICE_FILE}$i
+		((i += 1))
+	done
+}
+
+log_assert "For raidz2, two destroyed pools devices was removed or used by " \
+	"other pool, it still can be imported correctly."
+log_onexit cleanup
+
+log_must $ZPOOL create $TESTPOOL1 raidz2 $VDEV0 $VDEV1 $VDEV2 $VDIV3
+typeset guid=$(get_config $TESTPOOL1 pool_guid)
+typeset target=$TESTPOOL1
+if (( RANDOM % 2 == 0 )) ; then
+	target=$guid
+	log_note "Import by guid."
+fi
+log_must $ZPOOL destroy $TESTPOOL1
+
+log_must $ZPOOL create $TESTPOOL2 $VDEV0 $VDEV1
+log_must $ZPOOL import -d $DEVICE_DIR -D -f $target
+log_must $ZPOOL destroy $TESTPOOL1
+
+log_must $ZPOOL destroy $TESTPOOL2
+log_must $RM -rf $VDEV0 $VDEV1
+log_must $ZPOOL import -d $DEVICE_DIR -D -f $target
+log_must $ZPOOL destroy $TESTPOOL1
+
+log_note "For raidz2, more than two destroyed pool's devices were used, " \
+	"import failed."
+log_must $MKFILE $FILE_SIZE $VDEV0 $VDEV1
+log_must $ZPOOL create $TESTPOOL2 $VDEV0 $VDEV1 $VDEV2
+log_mustnot $ZPOOL import -d $DEVICE_DIR -D -f $target
+log_must $ZPOOL destroy $TESTPOOL2
+
+log_pass "zpool import -D raidz2 passed."
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/usr/src/test/zfs-tests/tests/functional/cli_root/zpool_import/zpool_import_009_neg.ksh	Wed Dec 05 22:04:50 2012 -0500
@@ -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) 2012 by Delphix. All rights reserved.
+#
+
+. $STF_SUITE/include/libtest.shlib
+. $STF_SUITE/tests/functional/cli_root/zfs_mount/zfs_mount.kshlib
+. $STF_SUITE/tests/functional/cli_root/zpool_import/zpool_import.cfg
+
+# DESCRIPTION:
+#	Try each 'zpool import' with inapplicable scenarios to make sure
+#	it returns an error. include:
+#		* A non-existent pool name is given
+#		* '-d', but no device directory specified
+#		* '-R', but no alter root directory specified
+#		* '-a', but a pool name specified either
+#		* more than 2 pool names is given
+#		* The new pool name specified already exists
+#		* Contain invalid characters not allowed in the ZFS namespace
+#
+# 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 "blah" "-d" "-R" "-a $TESTPOOL" \
+	"$TESTPOOL ${TESTPOOL}-new ${TESTPOOL}-new" \
+	"$TESTPOOL $TESTPOOL1" \
+	"$TESTPOOL ${TESTPOOL1}*" "$TESTPOOL ${TESTPOOL1}?"
+
+set -A pools "$TESTPOOL" "$TESTPOOL1"
+set -A devs "" "-d $DEVICE_DIR"
+
+function cleanup
+{
+	typeset -i i=0
+	typeset -i j=0
+
+	while (( i < ${#pools[*]} )); do
+
+		poolexists ${pools[i]} && \
+			log_must $ZPOOL export ${pools[i]}
+
+		datasetexists "${pools[i]}/$TESTFS" || \
+			log_must $ZPOOL import ${devs[i]} ${pools[i]}
+
+		ismounted "${pools[i]}/$TESTFS" || \
+			log_must $ZFS mount ${pools[i]}/$TESTFS
+
+		((i = i + 1))
+	done
+
+	cleanup_filesystem $TESTPOOL1 $TESTFS
+
+        destroy_pool $TESTPOOL1
+}
+
+log_onexit cleanup
+
+log_assert "Badly-formed 'zpool import' with inapplicable scenarios " \
+	"should return an error."
+
+setup_filesystem "$DEVICE_FILES" $TESTPOOL1 $TESTFS $TESTDIR1
+
+log_must $ZPOOL export $TESTPOOL
+
+typeset -i i=0
+while (( i < ${#args[*]} )); do
+	log_mustnot $ZPOOL import ${args[i]}
+	((i = i + 1))
+done
+
+log_pass "Badly formed 'zpool import' with inapplicable scenarios " \
+	"fail as expected."
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/usr/src/test/zfs-tests/tests/functional/cli_root/zpool_import/zpool_import_010_pos.ksh	Wed Dec 05 22:04:50 2012 -0500
@@ -0,0 +1,92 @@
+#!/bin/ksh -p
+#
+# CDDL HEADER START
+#
+# The contents of this file are subject to the terms of the
+# Common Development and Distribution License (the "License").
+# You may not use this file except in compliance with the License.
+#
+# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
+# or http://www.opensolaris.org/os/licensing.
+# See the License for the specific language governing permissions
+# and limitations under the License.
+#
+# When distributing Covered Code, include this CDDL HEADER in each
+# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
+# If applicable, add the following below this CDDL HEADER, with the
+# fields enclosed by brackets "[]" replaced with your own identifying
+# information: Portions Copyright [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.
+#
+
+. $STF_SUITE/include/libtest.shlib
+. $STF_SUITE/tests/functional/cli_root/zpool_import/zpool_import.cfg
+
+#
+# DESCRIPTION:
+#	'zpool -D -a' can import all the specified directories destroyed pools.
+#
+# STRATEGY:
+#	1. Create a 5 ways mirror pool A with dev0/1/2/3/4, then destroy it.
+#	2. Create a stripe pool B with dev1. Then destroy it.
+#	3. Create a raidz2 pool C with dev2/3/4. Then destroy it.
+#	4. Create a raidz pool D with dev3/4. Then destroy it.
+#	5. Create a stripe pool E with dev4. Then destroy it.
+#	6. Verify 'zpool import -D -a' recover all the pools.
+#
+
+verify_runnable "global"
+
+function cleanup
+{
+	typeset dt
+	for dt in $poolE $poolD $poolC $poolB $poolA; do
+		destroy_pool $dt
+	done
+
+	log_must $RM -rf $DEVICE_DIR/*
+	typeset i=0
+	while (( i < $MAX_NUM )); do
+		log_must $MKFILE $FILE_SIZE ${DEVICE_DIR}/${DEVICE_FILE}$i
+		((i += 1))
+	done
+}
+
+log_assert "'zpool -D -a' can import all the specified directories " \
+	"destroyed pools."
+log_onexit cleanup
+
+poolA=poolA.$$; poolB=poolB.$$; poolC=poolC.$$; poolD=poolD.$$; poolE=poolE.$$
+
+log_must $ZPOOL create $poolA mirror $VDEV0 $VDEV1 $VDEV2 $VDEV3 $VDEV4
+log_must $ZPOOL destroy $poolA
+
+log_must $ZPOOL create $poolB $VDEV1
+log_must $ZPOOL destroy $poolB
+
+log_must $ZPOOL create $poolC raidz2 $VDEV2 $VDEV3 $VDEV4
+log_must $ZPOOL destroy $poolC
+
+log_must $ZPOOL create $poolD raidz $VDEV3 $VDEV4
+log_must $ZPOOL destroy $poolD
+
+log_must $ZPOOL create $poolE $VDEV4
+log_must $ZPOOL destroy $poolE
+
+log_must $ZPOOL import -d $DEVICE_DIR -D -f -a
+
+for dt in $poolA $poolB $poolC $poolD $poolE; do
+	log_must datasetexists $dt
+done
+
+log_pass "'zpool -D -a' test passed."
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/usr/src/test/zfs-tests/tests/functional/cli_root/zpool_import/zpool_import_011_neg.ksh	Wed Dec 05 22:04:50 2012 -0500
@@ -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 2007 Sun Microsystems, Inc.  All rights reserved.
+# Use is subject to license terms.
+#
+
+#
+# Copyright (c) 2012 by Delphix. All rights reserved.
+#
+
+. $STF_SUITE/include/libtest.shlib
+. $STF_SUITE/tests/functional/cli_root/zpool_import/zpool_import.cfg
+
+#
+# DESCRIPTION:
+#	For strip pool, any destroyed pool devices was demaged, zpool import -D
+#	will failed.
+#
+# STRATEGY:
+#	1. Create strip pool A with three devices.
+#	2. Destroy this pool B.
+#	3. Create pool B with one of devices in step 1.
+#	4. Verify 'import -D' pool A will failed whenever pool B was destroyed
+#	   or not.
+#
+
+verify_runnable "global"
+
+function cleanup
+{
+	destroy_pool $TESTPOOL1
+	destroy_pool $TESTPOOL2
+
+	#
+	# Recreate virtual devices to avoid destroyed pool information on files.
+	#
+	log_must $RM -rf $VDEV0 $VDEV1 $VDEV2
+	log_must $MKFILE $FILE_SIZE $VDEV0 $VDEV1 $VDEV2
+}
+
+log_assert "For strip pool, any destroyed pool devices was demaged," \
+	"zpool import -D will failed."
+log_onexit cleanup
+
+log_must $ZPOOL create $TESTPOOL1 $VDEV0 $VDEV1 $VDEV2
+typeset guid=$(get_config $TESTPOOL1 pool_guid)
+typeset target=$TESTPOOL1
+if (( RANDOM % 2 == 0 )) ; then
+	target=$guid
+	log_note "Import by guid."
+fi
+log_must $ZPOOL destroy $TESTPOOL1
+log_must $ZPOOL create $TESTPOOL2 $VDEV2
+
+log_mustnot $ZPOOL import -d $DEVICE_DIR -D -f $target
+
+log_must $ZPOOL destroy $TESTPOOL2
+log_mustnot $ZPOOL import -d $DEVICE_DIR -D -f $target
+
+log_pass "Any strip pool devices damaged, pool can't be import passed."
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/usr/src/test/zfs-tests/tests/functional/cli_root/zpool_import/zpool_import_012_pos.ksh	Wed Dec 05 22:04:50 2012 -0500
@@ -0,0 +1,209 @@
+#!/bin/ksh -p
+#
+# CDDL HEADER START
+#
+# The contents of this file are subject to the terms of the
+# Common Development and Distribution License (the "License").
+# You may not use this file except in compliance with the License.
+#
+# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
+# or http://www.opensolaris.org/os/licensing.
+# See the License for the specific language governing permissions
+# and limitations under the License.
+#
+# When distributing Covered Code, include this CDDL HEADER in each
+# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
+# If applicable, add the following below this CDDL 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) 2012 by Delphix. All rights reserved.
+#
+
+. $STF_SUITE/include/libtest.shlib
+. $STF_SUITE/tests/functional/cli_root/zfs_mount/zfs_mount.kshlib
+. $STF_SUITE/tests/functional/cli_root/zpool_import/zpool_import.cfg
+
+#
+# DESCRIPTION:
+# Once a pool has been exported, it should be recreated after a
+# successful import, all the sub-filesystems within it should all be restored,
+# include mount & share status. Verify that is true.
+#
+# STRATEGY:
+#	1. Create the test pool and hierarchical filesystems.
+#	2. Export the test pool, or destroy the test pool,
+#		depend on testing import [-Df].
+#	3. Import it using the various combinations.
+#		- Regular import
+#		- Alternate Root Specified
+#	4. Verify the mount & share status is restored.
+#
+
+verify_runnable "global"
+
+set -A pools "$TESTPOOL" "$TESTPOOL1"
+set -A devs "" "-d $DEVICE_DIR"
+set -A options "" "-R $ALTER_ROOT"
+set -A mtpts "$TESTDIR" "$TESTDIR1"
+
+
+function cleanup
+{
+	typeset -i i=0
+
+	while ((i < ${#pools[*]})); do
+		if poolexists ${pools[i]}; then
+			log_must $ZPOOL export ${pools[i]}
+			log_note "Try to import ${devs[i]} ${pools[i]}"
+			$ZPOOL import ${devs[i]} ${pools[i]}
+		else
+			log_note "Try to import $option ${devs[i]} ${pools[i]}"
+			$ZPOOL import $option ${devs[i]} ${pools[i]}
+		fi
+
+		if poolexists ${pools[i]}; then
+			is_shared ${pools[i]} && \
+			    log_must $ZFS set sharenfs=off ${pools[i]}
+
+			ismounted "${pools[i]}/$TESTFS" || \
+			    log_must $ZFS mount ${pools[i]}/$TESTFS
+		fi
+
+		((i = i + 1))
+	done
+
+	destroy_pool $TESTPOOL1
+
+	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
+
+	[[ -d $ALTER_ROOT ]] && \
+		log_must $RM -rf $ALTER_ROOT
+}
+
+log_onexit cleanup
+
+log_assert "Verify all mount & share status of sub-filesystems within a pool \
+	can be restored after import [-Df]."
+
+setup_filesystem "$DEVICE_FILES" $TESTPOOL1 $TESTFS $TESTDIR1
+# create a heirarchy of filesystem
+for pool in ${pools[@]} ; do
+	log_must $ZFS create $pool/$TESTFS/$TESTCTR
+	log_must $ZFS create $pool/$TESTFS/$TESTCTR/$TESTCTR1
+	log_must $ZFS set canmount=off $pool/$TESTFS/$TESTCTR
+	log_must $ZFS set canmount=off $pool/$TESTFS/$TESTCTR/$TESTCTR1
+	log_must $ZFS create $pool/$TESTFS/$TESTCTR/$TESTFS1
+	log_must $ZFS create $pool/$TESTFS/$TESTCTR/$TESTCTR1/$TESTFS1
+	log_must $ZFS create $pool/$TESTFS/$TESTFS1
+	log_must $ZFS snapshot $pool/$TESTFS/$TESTFS1@snap
+	log_must $ZFS clone $pool/$TESTFS/$TESTFS1@snap $pool/$TESTCLONE1
+done
+
+typeset mount_fs="$TESTFS $TESTFS/$TESTFS1 $TESTCLONE1 \
+		$TESTFS/$TESTCTR/$TESTFS1 $TESTFS/$TESTCTR/$TESTCTR1/$TESTFS1"
+typeset nomount_fs="$TESTFS/$TESTCTR $TESTFS/$TESTCTR/$TESTCTR1"
+
+typeset -i i=0
+typeset -i j=0
+typeset -i nfs_share_bit=0
+typeset -i guid_bit=0
+typeset basedir
+
+for option in "" "-Df"; do
+	i=0
+	while ((i < ${#pools[*]})); do
+		pool=${pools[i]}
+		guid=$(get_pool_prop guid $pool)
+		j=0
+		while ((j < ${#options[*]})); do
+			# set sharenfs property off/on
+			nfs_share_bit=0
+			while ((nfs_share_bit <= 1)); do
+				typeset f_share=""
+				typeset nfs_flag="sharenfs=off"
+				if ((nfs_share_bit == 1)); then
+					log_note "Set sharenfs=on $pool"
+					log_must $ZFS set sharenfs=on $pool
+					log_must is_shared $pool
+					f_share="true"
+					nfs_flag="sharenfs=on"
+				fi
+				# for every off/on nfs bit import guid/pool_name
+				guid_bit=0
+				while ((guid_bit <= 1)); do
+					typeset guid_flag="pool name"
+					if [[ -z $option ]]; then
+						log_must $ZPOOL export $pool
+					else
+						log_must $ZPOOL destroy $pool
+					fi
+
+					typeset target=$pool
+					if ((guid_bit == 1)); then
+						log_note "Import by guid."
+						if [[ -z $guid ]]; then
+							log_fail "guid should "\
+							    "not be empty!"
+						else
+							target=$guid
+							guid_flag="$guid"
+						fi
+					fi
+					log_note "Import with $nfs_flag and " \
+					    "$guid_flag"
+					$ZPOOL import $option ${devs[i]} \
+					    ${options[j]} $target
+					#import by GUID if import by pool name fails
+					if [[ $? != 0 ]]; then
+						log_note "Possible pool name" \
+						    "duplicates. Try GUID import"
+						target=$guid
+						log_must $ZPOOL import $option \
+						    ${devs[i]} ${options[j]} \
+						    $target
+					fi
+					log_must poolexists $pool
+
+					for fs in $mount_fs; do
+						log_must ismounted $pool/$fs
+						[[ -n $f_share ]] && \
+						    log_must is_shared $pool/$fs
+					done
+
+					for fs in $nomount_fs; do
+						log_mustnot ismounted $pool/$fs
+						log_mustnot is_shared $pool/$fs
+					done
+					((guid_bit = guid_bit + 1))
+				done
+				# reset nfsshare=off
+				if [[ -n $f_share ]]; then
+					log_must $ZFS set sharenfs=off $pool
+					log_mustnot is_shared $pool
+				fi
+				((nfs_share_bit = nfs_share_bit + 1))
+			done
+
+			((j = j + 1))
+		done
+
+		((i = i + 1))
+	done
+done
+
+log_pass "All mount & share status of sub-filesystems within a pool \
+	can be restored after import [-Df]."
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/usr/src/test/zfs-tests/tests/functional/cli_root/zpool_import/zpool_import_013_neg.ksh	Wed Dec 05 22:04:50 2012 -0500
@@ -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) 2012 by Delphix. All rights reserved.
+#
+
+. $STF_SUITE/include/libtest.shlib
+. $STF_SUITE/tests/functional/cli_root/zpool_import/zpool_import.cfg
+
+#
+# DESCRIPTION:
+#	For pool may be in use from other system,
+#	'zpool import' will prompt the warning and fails.
+#
+# STRATEGY:
+#	1. Prepare rawfile that are created from other system.
+#	2. Verify 'zpool import' will fail.
+#	3. Verify 'zpool import -f' succeed.
+#
+
+verify_runnable "global"
+
+POOL_NAME=unclean_export
+POOL_FILE=unclean_export.dat
+
+function uncompress_pool
+{
+
+	log_note "Creating pool from $POOL_FILE"
+	log_must $BZCAT \
+	    $STF_SUITE/tests/functional/cli_root/zpool_import/blockfiles/$POOL_FILE.bz2 \
+	    > /$TESTPOOL/$POOL_FILE
+	return 0
+}
+
+function cleanup
+{
+	poolexists $POOL_NAME && log_must $ZPOOL destroy $POOL_NAME
+	[[ -e /$TESTPOOL/$POOL_FILE ]] && $RM /$TESTPOOL/$POOL_FILE
+	return 0
+}
+
+log_assert "'zpool import' fails for pool that was not cleanly exported"
+log_onexit cleanup
+
+uncompress_pool
+log_mustnot $ZPOOL import -d /$TESTPOOL $POOL_NAME
+log_must $ZPOOL import -d /$TESTPOOL -f $POOL_NAME
+
+log_pass "'zpool import' fails for pool that was not cleanly exported"
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/usr/src/test/zfs-tests/tests/functional/cli_root/zpool_import/zpool_import_all_001_pos.ksh	Wed Dec 05 22:04:50 2012 -0500
@@ -0,0 +1,223 @@
+#!/bin/ksh -p
+#
+# CDDL HEADER START
+#
+# The contents of this file are subject to the terms of the
+# Common Development and Distribution License (the "License").
+# You may not use this file except in compliance with the License.
+#
+# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
+# or http://www.opensolaris.org/os/licensing.
+# See the License for the specific language governing permissions
+# and limitations under the License.
+#
+# When distributing Covered Code, include this CDDL HEADER in each
+# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
+# If applicable, add the following below this CDDL 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.
+#
+
+. $STF_SUITE/include/libtest.shlib
+. $STF_SUITE/tests/functional/cli_root/zfs_mount/zfs_mount.kshlib
+. $STF_SUITE/tests/functional/cli_root/zpool_import/zpool_import.cfg
+
+#
+# DESCRIPTION:
+# Verify that 'zpool import -a' succeeds as root.
+#
+# STRATEGY:
+# 1. Create a group of pools with specified vdev.
+# 2. Create zfs filesystems within the given pools.
+# 3. Export the pools.
+# 4. Verify that import command succeed.
+#
+
+verify_runnable "global"
+
+set -A options "" "-R $ALTER_ROOT"
+
+typeset -i number=0
+typeset -i id=0
+typeset -i i=0
+typeset checksum1
+typeset unwantedpool
+
+function setup_single_disk #disk #pool #fs #mtpt
+{
+	typeset disk=$1
+	typeset pool=$2
+	typeset fs=${3##/}
+	typeset mtpt=$4
+
+	setup_filesystem "$disk" "$pool" "$fs" "$mtpt"
+
+	log_must $CP $MYTESTFILE $mtpt/$TESTFILE0
+
+	log_must $ZPOOL export $pool
+
+	[[ -d $mtpt ]] && \
+		$RM -rf $mtpt
+}
+
+function cleanup_all
+{
+	typeset -i id=0
+
+	#
+	# Try import individually if 'import -a' failed.
+	#
+	for pool in `$ZPOOL import | $GREP "pool:" | $AWK '{print $2}'`; do
+		$ZPOOL import -f $pool
+	done
+
+	for pool in `$ZPOOL import -d $DEVICE_DIR | $GREP "pool:" | $AWK '{print $2}'`; do
+		log_must $ZPOOL import -d $DEVICE_DIR -f $pool
+	done
+
+	while (( id < number )); do
+		if ! poolexists ${TESTPOOL}-$id ; then
+			(( id = id + 1 ))
+			continue
+		fi
+
+		if (( id == 0 )); then
+			log_must $ZPOOL export ${TESTPOOL}-$id
+
+			[[ -d /${TESTPOOL}-$id ]] && \
+				log_must $RM -rf /${TESTPOOL}-$id
+
+			log_must $ZPOOL import -f ${TESTPOOL}-$id $TESTPOOL
+
+			[[ -e $TESTDIR/$TESTFILE0 ]] && \
+				log_must $RM -rf $TESTDIR/$TESTFILE0
+		else
+			cleanup_filesystem "${TESTPOOL}-$id" $TESTFS
+
+			destroy_pool ${TESTPOOL}-$id
+		fi
+
+		(( id = id + 1 ))
+        done
+
+	[[ -d $ALTER_ROOT ]] && \
+		$RM -rf $ALTER_ROOT
+}
+
+function checksum_all #alter_root
+{
+	typeset alter_root=$1
+	typeset -i id=0
+	typeset file
+	typeset checksum2
+
+	while (( id < number )); do
+		if (( id == 2 )); then
+			(( id = id + 1 ))
+			continue
+		fi
+
+		if (( id == 0 )); then
+			file=${alter_root}/$TESTDIR/$TESTFILE0
+		else
+			file=${alter_root}/$TESTDIR.$id/$TESTFILE0
+		fi
+		[[ ! -e $file ]] && \
+			log_fail "$file missing after import."
+
+		checksum2=$($SUM $file | $AWK '{print $1}')
+		[[ "$checksum1" != "$checksum2" ]] && \
+			log_fail "Checksums differ ($checksum1 != $checksum2)"
+
+		(( id = id + 1 ))
+	done
+
+	return 0
+}
+
+
+log_assert "Verify that 'zpool import -a' succeeds as root."
+
+log_onexit cleanup_all
+
+checksum1=$($SUM $MYTESTFILE | $AWK '{print $1}')
+
+log_must $ZPOOL export $TESTPOOL
+log_must $ZPOOL import $TESTPOOL ${TESTPOOL}-0
+log_must $CP $MYTESTFILE $TESTDIR/$TESTFILE0
+log_must $ZPOOL export ${TESTPOOL}-0
+[[ -d /${TESTPOOL}-0 ]] && \
+	log_must $RM -rf /${TESTPOOL}-0
+
+#
+# setup exported pools on normal devices
+#
+number=1
+while (( number <= $GROUP_NUM )); do
+	if (( number == 2)); then
+		(( number = number + 1 ))
+		continue
+	fi
+
+	setup_single_disk "${ZFS_DISK1}s${number}" \
+		"${TESTPOOL}-$number" \
+		"$TESTFS" \
+		"$TESTDIR.$number"
+
+	(( number = number + 1 ))
+done
+
+#
+# setup exported pools on raw files
+#
+for disk in $DEVICE_FILES
+do
+
+	setup_single_disk "$disk" \
+		"${TESTPOOL}-$number" \
+		"$TESTFS" \
+		"$TESTDIR.$number"
+
+	(( number = number + 1 ))
+done
+
+while (( i < ${#options[*]} )); do
+
+	log_must $ZPOOL import -d /dev/dsk -d $DEVICE_DIR ${options[i]} -a -f
+
+	# destroy unintentional imported pools
+	typeset exclude=`eval $ECHO \"'(${KEEP})'\"`
+	for unwantedpool in $($ZPOOL list -H -o name \
+	     | $EGREP -v "$exclude" | $GREP -v $TESTPOOL); do
+		log_must $ZPOOL export $unwantedpool
+	done
+
+	if [[ -n ${options[i]} ]]; then
+		checksum_all $ALTER_ROOT
+	else
+		checksum_all
+	fi
+
+	id=0
+	while (( id < number )); do
+		if poolexists ${TESTPOOL}-$id ; then
+			log_must $ZPOOL export ${TESTPOOL}-$id
+		fi
+		(( id = id + 1 ))
+	done
+
+	(( i = i + 1 ))
+done
+
+log_pass "'zpool import -a' succeeds as root."
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/usr/src/test/zfs-tests/tests/functional/cli_root/zpool_import/zpool_import_features_001_pos.ksh	Wed Dec 05 22:04:50 2012 -0500
@@ -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 (c) 2012 by Delphix. All rights reserved.
+#
+
+. $STF_SUITE/include/libtest.shlib
+. $STF_SUITE/tests/functional/cli_root/zpool_import/zpool_import.cfg
+
+#################################################################################
+#
+#  Pool can be imported with inactive unsupported features.
+#
+#  1. Create new pool.
+#  2. Export and inject unsuppored features with zhack.
+#  3. Import pool normally with no problems.
+#  4. Verify that unsupported@ properties exist for the unsupported features.
+#
+################################################################################
+
+verify_runnable "global"
+
+features="com.test:xxx_unsup0 com.test:xxx_unsup1 com.test:xxx_unsup2"
+
+function cleanup
+{
+	poolexists $TESTPOOL1 && destroy_pool $TESTPOOL1
+
+	log_must $RM $VDEV0
+	log_must $MKFILE $FILE_SIZE $VDEV0
+}
+
+log_assert "Pool with inactive unsupported features can be imported."
+log_onexit cleanup
+
+log_must $ZPOOL create $TESTPOOL1 $VDEV0
+log_must $ZPOOL export $TESTPOOL1
+
+for feature in $features; do
+	log_must $ZHACK -d $DEVICE_DIR feature enable $TESTPOOL1 $feature
+done
+
+log_must $ZPOOL import -d $DEVICE_DIR $TESTPOOL1
+for feature in $features; do
+	state=$($ZPOOL list -Ho unsupported@$feature $TESTPOOL1)
+        if [[ "$state" != "inactive" ]]; then
+		log_fail "unsupported@$feature is '$state'"
+        fi
+done
+
+log_pass
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/usr/src/test/zfs-tests/tests/functional/cli_root/zpool_import/zpool_import_features_002_neg.ksh	Wed Dec 05 22:04:50 2012 -0500
@@ -0,0 +1,87 @@
+#!/bin/ksh -p
+#
+# CDDL HEADER START
+#
+# The contents of this file are subject to the terms of the
+# Common Development and Distribution License (the "License").
+# You may not use this file except in compliance with the License.
+#
+# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
+# or http://www.opensolaris.org/os/licensing.
+# See the License for the specific language governing permissions
+# and limitations under the License.
+#
+# When distributing Covered Code, include this CDDL HEADER in each
+# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
+# If applicable, add the following below this CDDL HEADER, with the
+# fields enclosed by brackets "[]" replaced with your own identifying
+# information: Portions Copyright [yyyy] [name of copyright owner]
+#
+# CDDL HEADER END
+#
+
+#
+# Copyright (c) 2012 by Delphix. All rights reserved.
+#
+
+. $STF_SUITE/include/libtest.shlib
+. $STF_SUITE/tests/functional/cli_root/zpool_import/zpool_import.cfg
+
+#################################################################################
+#
+#  Pool cannot be opened with active unsupported features. Error message should
+#  list active unsupported features.
+#
+#  1. Create new pool.
+#  2. Export and inject unsuppored features with zhack, make some of them active.
+#  3. Try to import pool, error should only list active features. It should
+#     not say anything about being able to import the pool in readonly mode.
+#
+################################################################################
+
+verify_runnable "global"
+
+enabled_features="com.test:xxx_unsup1 com.test:xxx_unsup3"
+active_features="com.test:xxx_unsup0 com.test:xxx_unsup2"
+
+function cleanup
+{
+	poolexists $TESTPOOL1 && destroy_pool $TESTPOOL1
+
+	log_must $RM $VDEV0
+	log_must $MKFILE $FILE_SIZE $VDEV0
+}
+
+log_assert "Pool with active unsupported features cannot be imported."
+log_onexit cleanup
+
+log_must $ZPOOL create $TESTPOOL1 $VDEV0
+log_must $ZPOOL export $TESTPOOL1
+
+for feature in $enabled_features $active_features; do
+	log_must $ZHACK -d $DEVICE_DIR feature enable $TESTPOOL1 $feature
+done
+
+for feature in $active_features; do
+	log_must $ZHACK -d $DEVICE_DIR feature ref $TESTPOOL1 $feature
+done
+
+log_mustnot $ZPOOL import -d $DEVICE_DIR $TESTPOOL1
+
+# error message should not mention "readonly"
+log_mustnot eval "$ZPOOL import -d $DEVICE_DIR $TESTPOOL1 | $GREP readonly"
+log_mustnot poolexists $TESTPOOL1
+
+for feature in $active_features; do
+	log_must eval "$ZPOOL import -d $DEVICE_DIR $TESTPOOL1 \
+	    | $GREP $feature"
+	log_mustnot poolexists $TESTPOOL1
+done
+
+for feature in $enabled_features; do
+	log_mustnot eval "$ZPOOL import -d $DEVICE_DIR $TESTPOOL1 \
+	    | $GREP $feature"
+	log_mustnot poolexists $TESTPOOL1
+done
+
+log_pass
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/usr/src/test/zfs-tests/tests/functional/cli_root/zpool_import/zpool_import_features_003_pos.ksh	Wed Dec 05 22:04:50 2012 -0500
@@ -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 (c) 2012 by Delphix. All rights reserved.
+#
+
+. $STF_SUITE/include/libtest.shlib
+. $STF_SUITE/tests/functional/cli_root/zpool_import/zpool_import.cfg
+
+#################################################################################
+#
+#  Pool can be imported with active read-only compatible features. If a feature
+#  is read-only compatible but also inactive its property status should be
+#  "inactive" rather than "readonly".
+#
+#  1. Create new pool.
+#  2. Export and inject variety of unsupported features.
+#  3. Try to import read-write, this should fail. The error should only list
+#     the active read-only compatible feature and mention "readonly=on".
+#  4. Import the pool in read-only mode.
+#  5. Verify values of unsupported@ properties.
+#
+################################################################################
+
+verify_runnable "global"
+
+enabled_features="com.test:xxx_unsup0 com.test:xxx_unsup2"
+active_features="com.test:xxx_unsup1 com.test:xxx_unsup3"
+
+function cleanup
+{
+	poolexists $TESTPOOL1 && destroy_pool $TESTPOOL1
+
+	log_must $RM $VDEV0
+	log_must $MKFILE $FILE_SIZE $VDEV0
+}
+
+log_assert "Pool with active read-only compatible features can be imported."
+log_onexit cleanup
+
+log_must $ZPOOL create $TESTPOOL1 $VDEV0
+log_must $ZPOOL export $TESTPOOL1
+
+for feature in $enabled_features $active_features; do
+	log_must $ZHACK -d $DEVICE_DIR feature enable -r $TESTPOOL1 $feature
+done
+
+for feature in $active_features; do
+	log_must $ZHACK -d $DEVICE_DIR feature ref $TESTPOOL1 $feature
+done
+
+log_mustnot $ZPOOL import -d $DEVICE_DIR $TESTPOOL1
+
+# error message should mention "readonly"
+log_must eval "$ZPOOL import -d $DEVICE_DIR $TESTPOOL1 | $GREP readonly"
+log_mustnot poolexists $TESTPOOL1
+
+for feature in $enabled_features; do
+	log_mustnot eval "$ZPOOL import -d $DEVICE_DIR $TESTPOOL1 \
+	    | $GREP $feature"
+	log_mustnot poolexists $TESTPOOL1
+done
+
+for feature in $active_features; do
+	log_must eval "$ZPOOL import -d $DEVICE_DIR $TESTPOOL1 \
+	    | $GREP $feature"
+	log_mustnot poolexists $TESTPOOL1
+done
+
+log_must $ZPOOL import -o readonly=on -d $DEVICE_DIR $TESTPOOL1
+
+for feature in $enabled_features; do
+	state=$($ZPOOL list -Ho unsupported@$feature $TESTPOOL1)
+        if [[ "$state" != "inactive" ]]; then
+		log_fail "unsupported@$feature is '$state'"
+        fi
+done
+
+for feature in $active_features; do
+	state=$($ZPOOL list -Ho unsupported@$feature $TESTPOOL1)
+        if [[ "$state" != "readonly" ]]; then
+		log_fail "unsupported@$feature is '$state'"
+        fi
+done
+
+log_pass
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/usr/src/test/zfs-tests/tests/functional/cli_root/zpool_import/zpool_import_missing_001_pos.ksh	Wed Dec 05 22:04:50 2012 -0500
@@ -0,0 +1,203 @@
+#!/bin/ksh -p
+#
+# CDDL HEADER START
+#
+# The contents of this file are subject to the terms of the
+# Common Development and Distribution License (the "License").
+# You may not use this file except in compliance with the License.
+#
+# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
+# or http://www.opensolaris.org/os/licensing.
+# See the License for the specific language governing permissions
+# and limitations under the License.
+#
+# When distributing Covered Code, include this CDDL HEADER in each
+# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
+# If applicable, add the following below this CDDL HEADER, with the
+# fields enclosed by brackets "[]" replaced with your own identifying
+# information: Portions Copyright [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.
+#
+
+. $STF_SUITE/include/libtest.shlib
+. $STF_SUITE/tests/functional/cli_root/zfs_mount/zfs_mount.kshlib
+. $STF_SUITE/tests/functional/cli_root/zpool_import/zpool_import.cfg
+
+#
+# DESCRIPTION:
+#	Once a pool has been exported, and one or more devices are
+#	damaged or missing (d/m), import should handle this kind of situation
+#	as described:
+#		- Regular, report error while any number of devices failing.
+#		- Mirror could withstand (N-1) devices failing
+#		  before data integrity is compromised
+#		- Raidz could withstand one devices failing
+#		  before data integrity is compromised
+#	Verify those are true.
+#
+# STRATEGY:
+#	1. Create test pool upon device files using the various combinations.
+#		- Regular pool
+#		- Mirror
+#		- Raidz
+#	2. Create necessary filesystem and test files.
+#	3. Export the test pool.
+#	4. Remove one or more devices
+#	5. Verify 'zpool import' will handle d/m device successfully.
+#	   Using the various combinations.
+#		- Regular import
+#		- Alternate Root Specified
+#	   It should be succeed with single d/m device upon 'raidz' & 'mirror',
+#	   but failed against 'regular' or more d/m devices.
+#	6. If import succeed, verify following is true:
+#		- The pool shows up under 'zpool list'.
+#		- The pool's health should be DEGRADED.
+#		- It contains the correct test file
+#
+
+verify_runnable "global"
+
+set -A vdevs "" "mirror" "raidz"
+set -A options "" "-R $ALTER_ROOT"
+
+function cleanup
+{
+	# recover the vdevs
+	recreate_files
+
+	[[ -d $ALTER_ROOT ]] && \
+		log_must $RM -rf $ALTER_ROOT
+}
+
+function recreate_files
+{
+	if poolexists "$TESTPOOL1" ; then
+		cleanup_filesystem $TESTPOOL1 $TESTFS
+		destroy_pool $TESTPOOL1
+	fi
+
+	log_must $RM -rf $DEVICE_DIR/*
+	typeset i=0
+	while (( i < $MAX_NUM )); do
+		log_must $MKFILE $FILE_SIZE ${DEVICE_DIR}/${DEVICE_FILE}$i
+		((i += 1))
+	done
+}
+
+log_onexit cleanup
+
+log_assert "Verify that import could handle damaged or missing device."
+
+CWD=$PWD
+cd $DEVICE_DIR || log_fail "Unable change directory to $DEVICE_DIR"
+
+checksum1=$($SUM $MYTESTFILE | $AWK '{print $1}')
+
+typeset -i i=0
+typeset -i j=0
+typeset -i count=0
+typeset basedir backup
+
+while (( i < ${#vdevs[*]} )); do
+
+	setup_filesystem "$DEVICE_FILES" \
+		$TESTPOOL1 $TESTFS $TESTDIR1 \
+		"" ${vdevs[i]}
+
+	backup=""
+
+	guid=$(get_config $TESTPOOL1 pool_guid)
+	log_must $CP $MYTESTFILE $TESTDIR1/$TESTFILE0
+
+	log_must $ZFS umount $TESTDIR1
+
+	j=0
+	while (( j <  ${#options[*]} )); do
+
+		count=0
+		action=log_must
+
+		#
+		# Restore all device files.
+		#
+		[[ -n $backup ]] && \
+			log_must $TAR xf $DEVICE_DIR/$DEVICE_ARCHIVE
+
+		for device in $DEVICE_FILES ; do
+			log_must $RM -f $device
+
+			poolexists $TESTPOOL1 && \
+				log_must $ZPOOL export $TESTPOOL1
+
+			#
+			# Backup all device files while filesystem prepared.
+			#
+			if [[ -z $backup ]]; then
+				log_must $TAR cf $DEVICE_DIR/$DEVICE_ARCHIVE \
+					${DEVICE_FILE}*
+				backup="true"
+			fi
+
+			(( count = count + 1 ))
+
+			case "${vdevs[i]}" in
+				'mirror') (( count == $GROUP_NUM )) && \
+						action=log_mustnot
+					;;
+				'raidz')  (( count > 1 )) && \
+						action=log_mustnot
+					;;
+				'')  action=log_mustnot
+					;;
+			esac
+
+			typeset target=$TESTPOOL1
+			if (( RANDOM % 2 == 0 )) ; then
+				target=$guid
+				log_note "Import by guid."
+			fi
+			$action $ZPOOL import \
+				-d $DEVICE_DIR ${options[j]} $target
+
+			[[ $action == "log_mustnot" ]] && continue
+
+			log_must poolexists $TESTPOOL1
+
+			health=$($ZPOOL list -H -o health $TESTPOOL1)
+
+			[[ $health == "DEGRADED" ]] || \
+				log_fail "$TESTPOOL1: Incorrect health($health)"
+			log_must ismounted $TESTPOOL1/$TESTFS
+
+			basedir=$TESTDIR1
+			[[ -n ${options[j]} ]] && \
+				basedir=$ALTER_ROOT/$TESTDIR1
+
+			[[ ! -e $basedir/$TESTFILE0 ]] && \
+				log_fail "$basedir/$TESTFILE0 missing after import."
+
+			checksum2=$($SUM $basedir/$TESTFILE0 | $AWK '{print $1}')
+			[[ "$checksum1" != "$checksum2" ]] && \
+				log_fail "Checksums differ ($checksum1 != $checksum2)"
+
+		done
+
+		((j = j + 1))
+	done
+
+	recreate_files
+
+	((i = i + 1))
+done
+
+log_pass "Import could handle damaged or missing device."
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/usr/src/test/zfs-tests/tests/functional/cli_root/zpool_import/zpool_import_missing_002_pos.ksh	Wed Dec 05 22:04:50 2012 -0500
@@ -0,0 +1,197 @@
+#!/bin/ksh -p
+#
+# CDDL HEADER START
+#
+# The contents of this file are subject to the terms of the
+# Common Development and Distribution License (the "License").
+# You may not use this file except in compliance with the License.
+#
+# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
+# or http://www.opensolaris.org/os/licensing.
+# See the License for the specific language governing permissions
+# and limitations under the License.
+#
+# When distributing Covered Code, include this CDDL HEADER in each
+# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
+# If applicable, add the following below this CDDL HEADER, with the
+# fields enclosed by brackets "[]" replaced with your own identifying
+# information: Portions Copyright [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.
+#
+
+. $STF_SUITE/include/libtest.shlib
+. $STF_SUITE/tests/functional/cli_root/zfs_mount/zfs_mount.kshlib
+. $STF_SUITE/tests/functional/cli_root/zpool_import/zpool_import.cfg
+
+#
+# DESCRIPTION:
+#	Once a pool has been exported, and one or more devices are
+#	move to other place, import should handle this kind of situation
+#	as described:
+#		- Regular, report error while any number of devices failing.
+#		- Mirror could withstand (N-1) devices failing
+#		  before data integrity is compromised
+#		- Raidz could withstand one devices failing
+#		  before data integrity is compromised
+#	Verify that is true.
+#
+# STRATEGY:
+#	1. Create test pool upon device files using the various combinations.
+#		- Regular pool
+#		- Mirror
+#		- Raidz
+#	2. Create necessary filesystem and test files.
+#	3. Export the test pool.
+#	4. Move one or more device files to other directory
+#	5. Verify 'zpool import -d' with the new directory
+#	   will handle moved files successfullly.
+#	   Using the various combinations.
+#		- Regular import
+#		- Alternate Root Specified
+#
+
+verify_runnable "global"
+
+set -A vdevs "" "mirror" "raidz"
+set -A options "" "-R $ALTER_ROOT"
+
+function cleanup
+{
+	cd $DEVICE_DIR || log_fail "Unable change directory to $DEVICE_DIR"
+	[[ -e $DEVICE_DIR/$DEVICE_ARCHIVE ]] && \
+		log_must $TAR xf $DEVICE_DIR/$DEVICE_ARCHIVE
+
+	poolexists $TESTPOOL1 || \
+		log_must $ZPOOL import -d $DEVICE_DIR $TESTPOOL1
+
+	cleanup_filesystem $TESTPOOL1 $TESTFS
+
+	destroy_pool $TESTPOOL1
+}
+
+function cleanup_all
+{
+	cleanup
+
+	# recover dev files
+	typeset i=0
+	while (( i < $MAX_NUM )); do
+		typeset dev_file=${DEVICE_DIR}/${DEVICE_FILE}$i
+		if [[ ! -e ${dev_file} ]]; then
+			log_must $MKFILE $FILE_SIZE ${dev_file}
+		fi
+		((i += 1))
+	done
+
+	log_must $RM -f $DEVICE_DIR/$DEVICE_ARCHIVE
+	cd $CWD || log_fail "Unable change directory to $CWD"
+
+	[[ -d $ALTER_ROOT ]] && \
+		log_must $RM -rf $ALTER_ROOT
+
+	[[ -d $BACKUP_DEVICE_DIR ]] && \
+		log_must $RM -rf $BACKUP_DEVICE_DIR
+}
+
+log_onexit cleanup_all
+
+log_assert "Verify that import could handle moving device."
+
+CWD=$PWD
+
+[[ ! -d $BACKUP_DEVICE_DIR ]] &&
+	log_must $MKDIR -p $BACKUP_DEVICE_DIR
+
+cd $DEVICE_DIR || log_fail "Unable change directory to $DEVICE_DIR"
+
+typeset -i i=0
+typeset -i j=0
+typeset -i count=0
+typeset basedir backup
+typeset action
+
+while (( i < ${#vdevs[*]} )); do
+
+	(( i != 0 )) && \
+		log_must $TAR xf $DEVICE_DIR/$DEVICE_ARCHIVE
+
+	setup_filesystem "$DEVICE_FILES" \
+		$TESTPOOL1 $TESTFS $TESTDIR1 \
+		"" ${vdevs[i]}
+
+	guid=$(get_config $TESTPOOL1 pool_guid)
+	backup=""
+
+	log_must $CP $MYTESTFILE $TESTDIR1/$TESTFILE0
+
+	log_must $ZFS umount $TESTDIR1
+
+	j=0
+	while (( j <  ${#options[*]} )); do
+
+		count=0
+
+		#
+		# Restore all device files.
+		#
+		[[ -n $backup ]] && \
+			log_must $TAR xf $DEVICE_DIR/$DEVICE_ARCHIVE
+
+		log_must $RM -f $BACKUP_DEVICE_DIR/*
+
+		for device in $DEVICE_FILES ; do
+
+			poolexists $TESTPOOL1 && \
+				log_must $ZPOOL export $TESTPOOL1
+
+			#
+			# Backup all device files while filesystem prepared.
+			#
+			if [[ -z $backup ]] ; then
+				log_must $TAR cf $DEVICE_DIR/$DEVICE_ARCHIVE ${DEVICE_FILE}*
+				backup="true"
+			fi
+
+			log_must $MV $device $BACKUP_DEVICE_DIR
+
+			(( count = count + 1 ))
+
+			action=log_mustnot
+			case "${vdevs[i]}" in
+				'mirror') (( count < $GROUP_NUM )) && \
+					action=log_must
+					;;
+				'raidz')  (( count == 1 )) && \
+					action=log_must
+					;;
+			esac
+
+			typeset target=$TESTPOOL1
+			if (( RANDOM % 2 == 0 )) ; then
+				target=$guid
+				log_note "Import by guid."
+			fi
+			$action $ZPOOL import \
+				-d $DEVICE_DIR ${options[j]} $target
+
+		done
+
+		((j = j + 1))
+	done
+
+	cleanup
+
+	((i = i + 1))
+done
+
+log_pass "Import could handle moving device."
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/usr/src/test/zfs-tests/tests/functional/cli_root/zpool_import/zpool_import_missing_003_pos.ksh	Wed Dec 05 22:04:50 2012 -0500
@@ -0,0 +1,232 @@
+#!/bin/ksh -p
+#
+# CDDL HEADER START
+#
+# The contents of this file are subject to the terms of the
+# Common Development and Distribution License (the "License").
+# You may not use this file except in compliance with the License.
+#
+# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
+# or http://www.opensolaris.org/os/licensing.
+# See the License for the specific language governing permissions
+# and limitations under the License.
+#
+# When distributing Covered Code, include this CDDL HEADER in each
+# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
+# If applicable, add the following below this CDDL HEADER, with the
+# fields enclosed by brackets "[]" replaced with your own identifying
+# information: Portions Copyright [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.
+#
+
+. $STF_SUITE/include/libtest.shlib
+. $STF_SUITE/tests/functional/cli_root/zfs_mount/zfs_mount.kshlib
+. $STF_SUITE/tests/functional/cli_root/zpool_import/zpool_import.cfg
+
+#
+# DESCRIPTION:
+#	Once a pool has been exported, but one or more devices are
+#	overlapped with other exported pool, import should handle
+#	this kind of situation properly.
+#
+# STRATEGY:
+#	1. Repeat 1-3, create two test pools upon device files separately.
+#	   These two pools should have one or more devices are overlapped.
+#	   using the various combinations.
+#		- Regular pool
+#		- Mirror
+#		- Raidz
+#	2. Create necessary filesystem and test files.
+#	3. Export the test pool.
+#	4. Verify 'zpool import -d' with these two pools will have results
+#	   as described:
+#		- Regular, report error while any number of devices failing.
+#		- Mirror could withstand (N-1) devices failing
+#		  before data integrity is compromised
+#		- Raidz could withstand one devices failing
+#		  before data integrity is compromised
+#
+
+verify_runnable "global"
+
+set -A vdevs "" "mirror" "raidz"
+
+function verify
+{
+	typeset pool=$1
+	typeset fs=$2
+	typeset mtpt=$3
+	typeset health=$4
+	typeset file=$5
+	typeset checksum1=$6
+
+	typeset myhealth
+	typeset mymtpt
+	typeset checksum2
+
+	log_must poolexists $pool
+
+	myhealth=$($ZPOOL list -H -o health $pool)
+
+	[[ $myhealth == $health ]] || \
+		log_fail "$pool: Incorrect health ($myhealth), " \
+			"expected ($health)."
+
+	log_must ismounted $pool/$fs
+
+	mymtpt=$(get_prop mountpoint $pool/$fs)
+	[[ $mymtpt == $mtpt ]] || \
+		log_fail "$pool/$fs: Incorrect mountpoint ($mymtpt), " \
+			"expected ($mtpt)."
+
+	[[ ! -e $mtpt/$file ]] && \
+		log_fail "$mtpt/$file missing after import."
+
+	checksum2=$($SUM $mymtpt/$file | $AWK '{print $1}')
+	[[ "$checksum1" != "$checksum2" ]] && \
+		log_fail "Checksums differ ($checksum1 != $checksum2)"
+
+	return 0
+
+}
+
+function cleanup
+{
+	cd $DEVICE_DIR || log_fail "Unable change directory to $DEVICE_DIR"
+
+	for pool in $TESTPOOL1 $TESTPOOL2; do
+		if poolexists "$pool" ; then
+			cleanup_filesystem $pool $TESTFS
+			destroy_pool $pool
+		fi
+	done
+
+	[[ -e $DEVICE_DIR/$DEVICE_ARCHIVE ]] && \
+		log_must $TAR xf $DEVICE_DIR/$DEVICE_ARCHIVE
+}
+
+function cleanup_all
+{
+	cleanup
+
+	# recover dev files
+	typeset i=0
+	while (( i < $MAX_NUM )); do
+		typeset file=${DEVICE_DIR}/${DEVICE_FILE}$i
+		if  [[ -e $file ]]; then
+			log_must $RM $file
+		fi
+		log_must $MKFILE $FILE_SIZE $file
+		((i += 1))
+	done
+
+	log_must $RM -f $DEVICE_DIR/$DEVICE_ARCHIVE
+	cd $CWD || log_fail "Unable change directory to $CWD"
+
+}
+
+log_onexit cleanup_all
+
+log_assert "Verify that import could handle device overlapped."
+
+CWD=$PWD
+
+cd $DEVICE_DIR || log_fail "Unable change directory to $DEVICE_DIR"
+log_must $TAR cf $DEVICE_DIR/$DEVICE_ARCHIVE ${DEVICE_FILE}*
+
+checksum1=$($SUM $MYTESTFILE | $AWK '{print $1}')
+
+typeset -i i=0
+typeset -i j=0
+typeset -i count=0
+typeset -i num=0
+typeset vdev1=""
+typeset vdev2=""
+typeset action
+
+while (( num < $GROUP_NUM )); do
+	vdev1="$vdev1 ${DEVICE_DIR}/${DEVICE_FILE}$num"
+	(( num = num + 1 ))
+done
+
+while (( i < ${#vdevs[*]} )); do
+	j=0
+	while (( j < ${#vdevs[*]} )); do
+
+		(( j != 0 )) && \
+			log_must $TAR xf $DEVICE_DIR/$DEVICE_ARCHIVE
+
+		typeset -i overlap=1
+		typeset -i begin
+		typeset -i end
+
+		while (( overlap <= $GROUP_NUM )); do
+			vdev2=""
+			(( begin = $GROUP_NUM - overlap ))
+			(( end = 2 * $GROUP_NUM - overlap - 1 ))
+			(( num = begin ))
+			while (( num <= end )); do
+				vdev2="$vdev2 ${DEVICE_DIR}/${DEVICE_FILE}$num"
+				(( num = num + 1 ))
+			done
+
+			setup_filesystem "$vdev1" $TESTPOOL1 $TESTFS $TESTDIR1 \
+				"" ${vdevs[i]}
+			log_must $CP $MYTESTFILE $TESTDIR1/$TESTFILE0
+			log_must $ZFS umount $TESTDIR1
+			poolexists $TESTPOOL1 && \
+				log_must $ZPOOL export $TESTPOOL1
+
+			setup_filesystem "$vdev2" $TESTPOOL2 $TESTFS $TESTDIR2 \
+				"" ${vdevs[j]}
+			log_must $CP $MYTESTFILE $TESTDIR2/$TESTFILE0
+			log_must $ZFS umount $TESTDIR2
+			poolexists $TESTPOOL2 && \
+				log_must $ZPOOL export $TESTPOOL2
+
+			action=log_must
+			case "${vdevs[i]}" in
+				'mirror') (( overlap == $GROUP_NUM )) && \
+					action=log_mustnot
+					;;
+				'raidz')  (( overlap > 1 )) && \
+					action=log_mustnot
+					;;
+				'')  action=log_mustnot
+					;;
+			esac
+
+			$action $ZPOOL import -d $DEVICE_DIR $TESTPOOL1
+			log_must $ZPOOL import -d $DEVICE_DIR $TESTPOOL2
+
+			if [[ $action == log_must ]]; then
+				verify "$TESTPOOL1" "$TESTFS" "$TESTDIR1" \
+					"DEGRADED" "$TESTFILE0" "$checksum1"
+			fi
+
+			verify "$TESTPOOL2" "$TESTFS" "$TESTDIR2" \
+				"ONLINE" "$TESTFILE0" "$checksum1"
+
+			cleanup
+
+			(( overlap = overlap + 1 ))
+
+		done
+
+		((j = j + 1))
+	done
+
+	((i = i + 1))
+done
+
+log_pass "Import could handle device overlapped."
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/usr/src/test/zfs-tests/tests/functional/cli_root/zpool_import/zpool_import_rename_001_pos.ksh	Wed Dec 05 22:04:50 2012 -0500
@@ -0,0 +1,162 @@
+#!/bin/ksh -p
+#
+# CDDL HEADER START
+#
+# The contents of this file are subject to the terms of the
+# Common Development and Distribution License (the "License").
+# You may not use this file except in compliance with the License.
+#
+# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
+# or http://www.opensolaris.org/os/licensing.
+# See the License for the specific language governing permissions
+# and limitations under the License.
+#
+# When distributing Covered Code, include this CDDL HEADER in each
+# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
+# If applicable, add the following below this CDDL HEADER, with the
+# fields enclosed by brackets "[]" replaced with your own identifying
+# information: Portions Copyright [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.
+#
+
+. $STF_SUITE/include/libtest.shlib
+. $STF_SUITE/tests/functional/cli_root/zfs_mount/zfs_mount.kshlib
+. $STF_SUITE/tests/functional/cli_root/zpool_import/zpool_import.cfg
+
+#
+# DESCRIPTION:
+# An exported pool can be imported under a different name. Hence
+# we test that a previously exported pool can be renamed.
+#
+# STRATEGY:
+#	1. Copy a file into the default test directory.
+#	2. Umount the default directory.
+#	3. Export the pool.
+#	4. Import the pool using the name ${TESTPOOL}-new,
+#	   and using the various combinations.
+#               - Regular import
+#               - Alternate Root Specified
+#	5. Verify it exists in the 'zpool list' output.
+#	6. Verify the default file system is mounted and that the file
+#	   from step (1) is present.
+#
+
+verify_runnable "global"
+
+set -A pools "$TESTPOOL" "$TESTPOOL1"
+set -A devs "" "-d $DEVICE_DIR"
+set -A options "" "-R $ALTER_ROOT"
+set -A mtpts "$TESTDIR" "$TESTDIR1"
+
+
+function cleanup
+{
+	typeset -i i=0
+	while (( i < ${#pools[*]} )); do
+		if poolexists "${pools[i]}-new" ; then
+			log_must $ZPOOL export "${pools[i]}-new"
+
+			[[ -d /${pools[i]}-new ]] && \
+				log_must $RM -rf /${pools[i]}-new
+
+			log_must $ZPOOL import ${devs[i]} \
+				"${pools[i]}-new" ${pools[i]}
+		fi
+
+		datasetexists "${pools[i]}" || \
+			log_must $ZPOOL import ${devs[i]} ${pools[i]}
+
+		ismounted "${pools[i]}/$TESTFS" || \
+			log_must $ZFS mount ${pools[i]}/$TESTFS
+
+		[[ -e ${mtpts[i]}/$TESTFILE0 ]] && \
+			log_must $RM -rf ${mtpts[i]}/$TESTFILE0
+
+		((i = i + 1))
+
+	done
+
+	cleanup_filesystem $TESTPOOL1 $TESTFS $TESTDIR1
+
+	destroy_pool $TESTPOOL1
+
+	[[ -d $ALTER_ROOT ]] && \
+		log_must $RM -rf $ALTER_ROOT
+}
+
+log_onexit cleanup
+
+log_assert "Verify that an imported pool can be renamed."
+
+setup_filesystem "$DEVICE_FILES" $TESTPOOL1 $TESTFS $TESTDIR1
+checksum1=$($SUM $MYTESTFILE | $AWK '{print $1}')
+
+typeset -i i=0
+typeset -i j=0
+typeset basedir
+
+while (( i < ${#pools[*]} )); do
+	guid=$(get_config ${pools[i]} pool_guid)
+	log_must $CP $MYTESTFILE ${mtpts[i]}/$TESTFILE0
+
+	log_must $ZFS umount ${mtpts[i]}
+
+	j=0
+	while (( j <  ${#options[*]} )); do
+		log_must $ZPOOL export ${pools[i]}
+
+		[[ -d /${pools[i]} ]] && \
+			log_must $RM -rf /${pools[i]}
+
+		typeset target=${pools[i]}
+		if (( RANDOM % 2 == 0 )) ; then
+			target=$guid
+			log_note "Import by guid."
+		fi
+
+		log_must $ZPOOL import ${devs[i]} ${options[j]} \
+			$target ${pools[i]}-new
+
+		log_must poolexists "${pools[i]}-new"
+
+		log_must ismounted ${pools[i]}-new/$TESTFS
+
+		basedir=${mtpts[i]}
+		[[ -n ${options[j]} ]] && \
+			basedir=$ALTER_ROOT/${mtpts[i]}
+
+		[[ ! -e $basedir/$TESTFILE0 ]] && \
+			log_fail "$basedir/$TESTFILE0 missing after import."
+
+		checksum2=$($SUM $basedir/$TESTFILE0 | $AWK '{print $1}')
+		[[ "$checksum1" != "$checksum2" ]] && \
+			log_fail "Checksums differ ($checksum1 != $checksum2)"
+
+		log_must $ZPOOL export "${pools[i]}-new"
+
+		[[ -d /${pools[i]}-new ]] && \
+			log_must $RM -rf /${pools[i]}-new
+
+		target=${pools[i]}-new
+		if (( RANDOM % 2 == 0 )) ; then
+			target=$guid
+		fi
+		log_must $ZPOOL import ${devs[i]} $target ${pools[i]}
+
+		((j = j + 1))
+	done
+
+	((i = i + 1))
+done
+
+log_pass "Successfully imported and renamed a ZPOOL"
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/usr/src/test/zfs-tests/tests/functional/cli_root/zpool_offline/Makefile	Wed Dec 05 22:04:50 2012 -0500
@@ -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) 2012 by Delphix. All rights reserved.
+#
+
+include $(SRC)/Makefile.master
+
+ROOTOPTPKG = $(ROOT)/opt/zfs-tests
+TESTDIR = $(ROOTOPTPKG)/tests/functional/cli_root/zpool_offline
+
+PROGS = cleanup \
+	setup \
+	zpool_offline_001_pos \
+	zpool_offline_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	Thu Jan 01 00:00:00 1970 +0000
+++ b/usr/src/test/zfs-tests/tests/functional/cli_root/zpool_offline/cleanup.ksh	Wed Dec 05 22:04:50 2012 -0500
@@ -0,0 +1,32 @@
+#!/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.
+#
+
+. $STF_SUITE/include/libtest.shlib
+
+verify_runnable "global"
+
+default_cleanup
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/usr/src/test/zfs-tests/tests/functional/cli_root/zpool_offline/setup.ksh	Wed Dec 05 22:04:50 2012 -0500
@@ -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 2009 Sun Microsystems, Inc.  All rights reserved.
+# Use is subject to license terms.
+#
+
+. $STF_SUITE/include/libtest.shlib
+
+verify_runnable "global"
+verify_disk_count "$DISKS" 2
+
+DISK=${DISKS%% *}
+
+default_mirror_setup $DISKS
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/usr/src/test/zfs-tests/tests/functional/cli_root/zpool_offline/zpool_offline_001_pos.ksh	Wed Dec 05 22:04:50 2012 -0500
@@ -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 2009 Sun Microsystems, Inc.  All rights reserved.
+# Use is subject to license terms.
+#
+. $STF_SUITE/include/libtest.shlib
+
+#
+# DESCRIPTION:
+# Executing 'zpool offline' with valid parameters succeeds.
+#
+# STRATEGY:
+# 1. Create an array of correctly formed 'zpool offline' options
+# 2. Execute each element of the array.
+# 3. Verify use of each option is successful.
+#
+
+verify_runnable "global"
+
+DISKLIST=$(get_disklist $TESTPOOL)
+set -A disks $DISKLIST
+typeset -i num=${#disks[*]}
+
+set -A args "" "-t"
+
+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
+}
+
+log_assert "Executing 'zpool offline' with correct options succeeds"
+
+log_onexit cleanup
+
+if [[ -z $DISKLIST ]]; then
+	log_fail "DISKLIST is empty."
+fi
+
+typeset -i i=0
+typeset -i j=1
+
+for disk in $DISKLIST; do
+	i=0
+	while [[ $i -lt ${#args[*]} ]]; do
+		if (( j < num )) ; then
+			log_must $ZPOOL offline ${args[$i]} $TESTPOOL $disk
+			check_state $TESTPOOL $disk "offline"
+			if [[ $? != 0 ]]; then
+				log_fail "$disk of $TESTPOOL did not match offline state"
+			fi
+		else
+			log_mustnot $ZPOOL offline ${args[$i]} $TESTPOOL $disk
+			check_state $TESTPOOL $disk "online"
+			if [[ $? != 0 ]]; then
+				log_fail "$disk of $TESTPOOL did not match online state"
+			fi
+		fi
+
+		(( i = i + 1 ))
+	done
+	(( j = j + 1 ))
+done
+
+log_note "Issuing repeated 'zpool offline' commands succeeds."
+
+typeset -i iters=20
+typeset -i index=0
+
+for disk in $DISKLIST; do
+        i=0
+        while [[ $i -lt $iters ]]; do
+		index=`expr $RANDOM % ${#args[*]}`
+                log_must $ZPOOL offline ${args[$index]} $TESTPOOL $disk
+                check_state $TESTPOOL $disk "offline"
+                if [[ $? != 0 ]]; then
+                        log_fail "$disk of $TESTPOOL is not offline."
+                fi
+
+                (( i = i + 1 ))
+        done
+
+	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
+
+log_pass "'zpool offline' with correct options succeeded"
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/usr/src/test/zfs-tests/tests/functional/cli_root/zpool_offline/zpool_offline_002_neg.ksh	Wed Dec 05 22:04:50 2012 -0500
@@ -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.
+#
+. $STF_SUITE/include/libtest.shlib
+
+#
+# DESCRIPTION:
+# Executing 'zpool offline' command with bad options fails.
+#
+# STRATEGY:
+# 1. Create an array of badly formed 'zpool offline' options.
+# 2. Execute each element of the array.
+# 3. Verify an error code is returned.
+#
+
+verify_runnable "global"
+
+DISKLIST=$(get_disklist $TESTPOOL)
+
+set -A args "" "-?" "-t fakepool" "-f fakepool" "-ev fakepool" "fakepool" \
+	"-t $TESTPOOL" "-t $TESTPOOL/$TESTFS" "-t $TESTPOOL/$TESTFS $DISKLIST" \
+	"-t $TESTPOOL/$TESTCTR" "-t $TESTPOOL/$TESTCTR/$TESTFS1" \
+	"-t $TESTPOOL/$TESTCTR $DISKLIST" "-t $TESTPOOL/$TESTVOL" \
+	"-t $TESTPOOL/$TESTCTR/$TESTFS1 $DISKLIST" \
+	"-t $TESTPOOL/$TESTVOL $DISKLIST" \
+	"-t $DISKLIST" \
+        "-f $TESTPOOL" "-f $TESTPOOL/$TESTFS" "-f $TESTPOOL/$TESTFS $DISKLIST" \
+        "-f $TESTPOOL/$TESTCTR" "-f $TESTPOOL/$TESTCTR/$TESTFS1" \
+        "-f $TESTPOOL/$TESTCTR $DISKLIST" "-f $TESTPOOL/$TESTVOL" \
+        "-f $TESTPOOL/$TESTCTR/$TESTFS1 $DISKLIST" \
+        "-f $TESTPOOL/$TESTVOL $DISKLIST" \
+        "-f $DISKLIST" \
+        "-ft $TESTPOOL" "-ft $TESTPOOL/$TESTFS" \
+	"-ft $TESTPOOL/$TESTFS $DISKLIST" \
+        "-ft $TESTPOOL/$TESTCTR" "-ft $TESTPOOL/$TESTCTR/$TESTFS1" \
+        "-ft $TESTPOOL/$TESTCTR $DISKLIST" "-ft $TESTPOOL/$TESTVOL" \
+        "-ft $TESTPOOL/$TESTCTR/$TESTFS1 $DISKLIST" \
+        "-ft $TESTPOOL/$TESTVOL $DISKLIST" \
+        "-ft $DISKLIST" \
+        "-tf $TESTPOOL" "-tf $TESTPOOL/$TESTFS" \
+	"-tf $TESTPOOL/$TESTFS $DISKLIST" \
+        "-tf $TESTPOOL/$TESTCTR" "-tf $TESTPOOL/$TESTCTR/$TESTFS1" \
+        "-tf $TESTPOOL/$TESTCTR $DISKLIST" "-tf $TESTPOOL/$TESTVOL" \
+        "-tf $TESTPOOL/$TESTCTR/$TESTFS1 $DISKLIST" \
+        "-tf $TESTPOOL/$TESTVOL $DISKLIST" \
+        "-tf $DISKLIST" \
+	"$TESTPOOL" "$TESTPOOL/$TESTFS" "$TESTPOOL/$TESTFS $DISKLIST" \
+	"$TESTPOOL/$TESTCTR" "$TESTPOOL/$TESTCTR/$TESTFS1" \
+	"$TESTPOOL/$TESTCTR $DISKLIST" "$TESTPOOL/$TESTVOL" \
+	"$TESTPOOL/$TESTCTR/$TESTFS1 $DISKLIST" "$TESTPOOL/$TESTVOL $DISKLIST" \
+	"$DISKLIST"
+
+log_assert "Executing 'zpool offline' with bad options fails"
+
+if [[ -z $DISKLIST ]]; then
+	log_fail "DISKLIST is empty."
+fi
+
+typeset -i i=0
+
+while [[ $i -lt ${#args[*]} ]]; do
+
+	log_mustnot $ZPOOL offline ${args[$i]}
+
+	(( i = i + 1 ))
+done
+
+log_pass "'zpool offline' command with bad options failed as expected."
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/usr/src/test/zfs-tests/tests/functional/cli_root/zpool_online/Makefile	Wed Dec 05 22:04:50 2012 -0500
@@ -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) 2012 by Delphix. All rights reserved.
+#
+
+include $(SRC)/Makefile.master
+
+ROOTOPTPKG = $(ROOT)/opt/zfs-tests
+TESTDIR = $(ROOTOPTPKG)/tests/functional/cli_root/zpool_online
+
+PROGS = cleanup \
+	setup \
+	zpool_online_001_pos \
+	zpool_online_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	Thu Jan 01 00:00:00 1970 +0000
+++ b/usr/src/test/zfs-tests/tests/functional/cli_root/zpool_online/cleanup.ksh	Wed Dec 05 22:04:50 2012 -0500
@@ -0,0 +1,32 @@
+#!/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.
+#
+
+. $STF_SUITE/include/libtest.shlib
+
+verify_runnable "global"
+
+default_cleanup
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/usr/src/test/zfs-tests/tests/functional/cli_root/zpool_online/setup.ksh	Wed Dec 05 22:04:50 2012 -0500
@@ -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 2009 Sun Microsystems, Inc.  All rights reserved.
+# Use is subject to license terms.
+#
+
+. $STF_SUITE/include/libtest.shlib
+
+verify_runnable "global"
+verify_disk_count "$DISKS" 2
+
+DISK=${DISKS%% *}
+
+default_mirror_setup $DISKS
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/usr/src/test/zfs-tests/tests/functional/cli_root/zpool_online/zpool_online_001_pos.ksh	Wed Dec 05 22:04:50 2012 -0500
@@ -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 2007 Sun Microsystems, Inc.  All rights reserved.
+# Use is subject to license terms.
+#
+. $STF_SUITE/include/libtest.shlib
+
+#
+# DESCRIPTION:
+# Executing 'zpool online' with valid parameters succeeds.
+#
+# STRATEGY:
+# 1. Create an array of correctly formed 'zpool online' options
+# 2. Execute each element of the array.
+# 3. Verify use of each option is successful.
+#
+
+verify_runnable "global"
+
+DISKLIST=$(get_disklist $TESTPOOL)
+
+set -A args ""
+
+function cleanup
+{
+	#
+	# Ensure we don't leave disks in temporary online state (-t)
+	#
+	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
+}
+
+log_assert "Executing 'zpool online' with correct options succeeds"
+
+log_onexit cleanup
+
+if [[ -z $DISKLIST ]]; then
+	log_fail "DISKLIST is empty."
+fi
+
+typeset -i i=0
+
+for disk in $DISKLIST; do
+	i=0
+	while [[ $i -lt ${#args[*]} ]]; do
+		log_must $ZPOOL offline $TESTPOOL $disk
+		check_state $TESTPOOL $disk "offline"
+		if [[ $? != 0 ]]; then
+			log_fail "$disk of $TESTPOOL did not match offline state"
+		fi
+
+		log_must $ZPOOL online ${args[$i]} $TESTPOOL $disk
+		check_state $TESTPOOL $disk "online"
+		if [[ $? != 0 ]]; then
+			log_fail "$disk of $TESTPOOL did not match online state"
+		fi
+
+		(( i = i + 1 ))
+	done
+done
+
+log_note "Issuing repeated 'zpool online' commands succeeds."
+
+typeset -i iters=20
+typeset -i index=0
+
+for disk in $DISKLIST; do
+        i=0
+        while [[ $i -lt $iters ]]; do
+		index=`expr $RANDOM % ${#args[*]}`
+                log_must $ZPOOL online ${args[$index]} $TESTPOOL $disk
+                check_state $TESTPOOL $disk "online"
+                if [[ $? != 0 ]]; then
+                        log_fail "$disk of $TESTPOOL did not match online state"
+                fi
+
+                (( i = i + 1 ))
+        done
+done
+
+log_pass "'zpool online' with correct options succeeded"
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/usr/src/test/zfs-tests/tests/functional/cli_root/zpool_online/zpool_online_002_neg.ksh	Wed Dec 05 22:04:50 2012 -0500
@@ -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.
+#
+. $STF_SUITE/include/libtest.shlib
+
+#
+# DESCRIPTION:
+# Executing 'zpool online' command with bad options fails.
+#
+# STRATEGY:
+# 1. Create an array of badly formed 'zpool online' options.
+# 2. Execute each element of the array.
+# 3. Verify an error code is returned.
+#
+verify_runnable "global"
+
+DISKLIST=$(get_disklist $TESTPOOL)
+
+set -A args "" "-?" "-e fakepool" "-v fakepool" "-ev fakepool" "-ve fakepool" \
+	"-t $TESTPOOL" "-t $TESTPOOL/$TESTFS" "-t $TESTPOOL/$TESTFS $DISKLIST" \
+	"-t $TESTPOOL/$TESTCTR" "-t $TESTPOOL/$TESTCTR/$TESTFS1" \
+	"-t $TESTPOOL/$TESTCTR $DISKLIST" "-t $TESTPOOL/$TESTVOL" \
+	"-t $TESTPOOL/$TESTCTR/$TESTFS1 $DISKLIST" \
+	"-t $TESTPOOL/$TESTVOL $DISKLIST" \
+	"-t $DISKLIST" \
+	"$TESTPOOL" "$TESTPOOL/$TESTFS" "$TESTPOOL/$TESTFS $DISKLIST" \
+	"$TESTPOOL/$TESTCTR" "$TESTPOOL/$TESTCTR/$TESTFS1" \
+	"$TESTPOOL/$TESTCTR $DISKLIST" "$TESTPOOL/$TESTVOL" \
+	"$TESTPOOL/$TESTCTR/$TESTFS1 $DISKLIST" "$TESTPOOL/$TESTVOL $DISKLIST" \
+	"$DISKLIST"
+
+log_assert "Executing 'zpool online' with bad options fails"
+
+if [[ -z $DISKLIST ]]; then
+        log_fail "DISKLIST is empty."
+fi
+
+typeset -i i=0
+
+while [[ $i -lt ${#args[*]} ]]; do
+
+	log_mustnot $ZPOOL online ${args[$i]}
+
+	(( i = i + 1 ))
+done
+
+log_pass "'zpool online' command with bad options failed as expected."
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/usr/src/test/zfs-tests/tests/functional/cli_root/zpool_remove/Makefile	Wed Dec 05 22:04:50 2012 -0500
@@ -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) 2012 by Delphix. All rights reserved.
+#
+
+include $(SRC)/Makefile.master
+
+ROOTOPTPKG = $(ROOT)/opt/zfs-tests
+TESTDIR = $(ROOTOPTPKG)/tests/functional/cli_root/zpool_remove
+
+PROGS = cleanup \
+	setup \
+	zpool_remove_001_neg \
+	zpool_remove_002_pos \
+	zpool_remove_003_pos
+
+FILES = zpool_remove.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	Thu Jan 01 00:00:00 1970 +0000
+++ b/usr/src/test/zfs-tests/tests/functional/cli_root/zpool_remove/cleanup.ksh	Wed Dec 05 22:04:50 2012 -0500
@@ -0,0 +1,32 @@
+#!/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.
+#
+
+. $STF_SUITE/include/libtest.shlib
+
+cleanup_devices $DISKS
+
+log_pass
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/usr/src/test/zfs-tests/tests/functional/cli_root/zpool_remove/setup.ksh	Wed Dec 05 22:04:50 2012 -0500
@@ -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) 2012 by Delphix. All rights reserved.
+#
+
+. $STF_SUITE/include/libtest.shlib
+. $STF_SUITE/tests/functional/cli_root/zpool_remove/zpool_remove.cfg
+
+verify_runnable "global"
+
+if ! $(is_physical_device $DISKS) ; then
+	log_unsupported "This directory cannot be run on raw files."
+fi
+
+partition_disk $SIZE $DISK 6
+
+log_pass
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/usr/src/test/zfs-tests/tests/functional/cli_root/zpool_remove/zpool_remove.cfg	Wed Dec 05 22:04:50 2012 -0500
@@ -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) 2012 by Delphix. All rights reserved.
+#
+
+export DISK=${DISKS%% *}
+export SIZE="200m"
+export SLICE0=0
+export SLICE1=1
+export SLICE2=2
+export SLICE3=3
+export SLICE4=4
+export SLICE5=5
+export SLICE6=6
+export SLICE7=7
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/usr/src/test/zfs-tests/tests/functional/cli_root/zpool_remove/zpool_remove_001_neg.ksh	Wed Dec 05 22:04:50 2012 -0500
@@ -0,0 +1,96 @@
+#!/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.
+#
+
+. $STF_SUITE/include/libtest.shlib
+. $STF_SUITE/tests/functional/cli_root/zpool_remove/zpool_remove.cfg
+
+#
+# DESCRIPTION:
+# Verify that 'zpool can not remove device except inactive hot spares from pool'
+#
+# STRATEGY:
+# 1. Create all kinds of pool (strip, mirror, raidz, hotspare)
+# 2. Try to remove device from the pool
+# 3. Verify that the remove failed.
+#
+
+typeset disk=${DISK}
+typeset vdev_devs="${disk}s${SLICE0}"
+typeset mirror_devs="${disk}s${SLICE0} ${disk}s${SLICE1}"
+typeset raidz_devs=${mirror_devs}
+typeset raidz1_devs=${mirror_devs}
+typeset raidz2_devs="${mirror_devs} ${disk}s${SLICE3}"
+typeset spare_devs1="${disk}s${SLICE0}"
+typeset spare_devs2="${disk}s${SLICE1}"
+
+function check_remove
+{
+        typeset pool=$1
+        typeset devs="$2"
+        typeset dev
+
+        for dev in $devs; do
+                log_mustnot $ZPOOL remove $dev
+        done
+
+        destroy_pool $pool
+
+}
+
+function cleanup
+{
+        if poolexists $TESTPOOL; then
+                destroy_pool $TESTPOOL
+        fi
+}
+
+set -A create_args "$vdev_devs" "mirror $mirror_devs"  \
+		"raidz $raidz_devs" "raidz $raidz1_devs" \
+		"raidz2 $raidz2_devs" \
+		"$spare_devs1 spare $spare_devs2"
+
+set -A verify_disks "$vdev_devs" "$mirror_devs" "$raidz_devs" \
+		"$raidz1_devs" "$raidz2_devs" "$spare_devs1"
+
+
+log_assert "Check zpool remove <pool> <device> can not remove " \
+	"active device from pool"
+
+log_onexit cleanup
+
+typeset -i i=0
+while [[ $i -lt ${#create_args[*]} ]]; do
+	log_must $ZPOOL create $TESTPOOL ${create_args[i]}
+	check_remove $TESTPOOL "${verify_disks[i]}"
+	(( i = i + 1))
+done
+
+log_pass "'zpool remove <pool> <device> fail as expected .'"
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/usr/src/test/zfs-tests/tests/functional/cli_root/zpool_remove/zpool_remove_002_pos.ksh	Wed Dec 05 22:04:50 2012 -0500
@@ -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 2007 Sun Microsystems, Inc.  All rights reserved.
+# Use is subject to license terms.
+#
+
+#
+# Copyright (c) 2012 by Delphix. All rights reserved.
+#
+
+. $STF_SUITE/include/libtest.shlib
+. $STF_SUITE/tests/functional/cli_root/zpool_remove/zpool_remove.cfg
+
+#
+# DESCRIPTION:
+# Verify that 'zpool can only remove inactive hot spare devices from pool'
+#
+# STRATEGY:
+# 1. Create a hotspare pool
+# 2. Try to remove the inactive hotspare device from the pool
+# 3. Verify that the remove succeed.
+#
+
+function cleanup
+{
+	if poolexists $TESTPOOL; then
+		destroy_pool $TESTPOOL
+	fi
+}
+
+log_onexit cleanup
+typeset disk=${DISK}
+
+typeset spare_devs1="${disk}s${SLICE0}"
+typeset spare_devs2="${disk}s${SLICE1}"
+
+log_assert "zpool remove can only remove inactive hotspare device from pool"
+
+log_note "check hotspare device which is created by zpool create"
+log_must $ZPOOL create $TESTPOOL $spare_devs1 spare $spare_devs2
+log_must $ZPOOL remove $TESTPOOL $spare_devs2
+
+log_note "check hotspare device which is created by zpool add"
+log_must $ZPOOL add $TESTPOOL spare $spare_devs2
+log_must $ZPOOL remove $TESTPOOL $spare_devs2
+log_must $ZPOOL destroy $TESTPOOL
+
+log_pass "zpool remove can only remove inactive hotspare device from pool"
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/usr/src/test/zfs-tests/tests/functional/cli_root/zpool_remove/zpool_remove_003_pos.ksh	Wed Dec 05 22:04:50 2012 -0500
@@ -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) 2012 by Delphix. All rights reserved.
+#
+
+. $STF_SUITE/include/libtest.shlib
+. $STF_SUITE/tests/functional/cli_root/zpool_remove/zpool_remove.cfg
+
+#
+# DESCRIPTION:
+# Verify that 'zpool can remove hotspare devices from pool when it state
+#              switch from active to inactive'
+#
+# STRATEGY:
+# 1. Create a hotspare pool
+# 2. Try to replace the inactive hotspare device to active device in the pool
+# 3. Try to detach active (spare) device to make it inactive
+# 3. Verify that the zpool remove succeed.
+#
+
+function cleanup
+{
+	if poolexists $TESTPOOL; then
+		destroy_pool $TESTPOOL
+	fi
+}
+
+log_onexit cleanup
+typeset disk=${DISK}
+
+typeset spare_devs1="${disk}s${SLICE0}"
+typeset spare_devs2="${disk}s${SLICE1}"
+typeset spare_devs3="${disk}s${SLICE3}"
+typeset spare_devs4="${disk}s${SLICE4}"
+
+log_assert "zpool remove can remove hotspare device which state go though" \
+	" active to inactive in pool"
+
+log_note "Check spare device which state go through active to inactive"
+log_must $ZPOOL create $TESTPOOL $spare_devs1 $spare_devs2 spare \
+                 $spare_devs3 $spare_devs4
+log_must $ZPOOL replace $TESTPOOL $spare_devs2 $spare_devs3
+log_mustnot $ZPOOL remove $TESTPOOL $spare_devs3
+log_must $ZPOOL detach $TESTPOOL $spare_devs3
+log_must $ZPOOL remove $TESTPOOL $spare_devs3
+
+log_pass "'zpool remove device passed as expected.'"
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/usr/src/test/zfs-tests/tests/functional/cli_root/zpool_replace/Makefile	Wed Dec 05 22:04:50 2012 -0500
@@ -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) 2012 by Delphix. All rights reserved.
+#
+
+include $(SRC)/Makefile.master
+
+ROOTOPTPKG = $(ROOT)/opt/zfs-tests
+TESTDIR = $(ROOTOPTPKG)/tests/functional/cli_root/zpool_replace
+
+PROGS = cleanup \
+	setup \
+	zpool_replace_001_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	Thu Jan 01 00:00:00 1970 +0000
+++ b/usr/src/test/zfs-tests/tests/functional/cli_root/zpool_replace/cleanup.ksh	Wed Dec 05 22:04:50 2012 -0500
@@ -0,0 +1,32 @@
+#!/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.
+#
+
+. $STF_SUITE/include/libtest.shlib
+
+verify_runnable "global"
+
+default_cleanup
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/usr/src/test/zfs-tests/tests/functional/cli_root/zpool_replace/setup.ksh	Wed Dec 05 22:04:50 2012 -0500
@@ -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 2009 Sun Microsystems, Inc.  All rights reserved.
+# Use is subject to license terms.
+#
+
+. $STF_SUITE/include/libtest.shlib
+
+verify_runnable "global"
+verify_disk_count "$DISKS" 2
+
+DISK=${DISKS%% *}
+
+default_mirror_setup $DISKS
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/usr/src/test/zfs-tests/tests/functional/cli_root/zpool_replace/zpool_replace_001_neg.ksh	Wed Dec 05 22:04:50 2012 -0500
@@ -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.
+#
+. $STF_SUITE/include/libtest.shlib
+
+#
+# DESCRIPTION:
+# Executing 'zpool replace' command with bad options fails.
+#
+# STRATEGY:
+# 1. Create an array of badly formed 'zpool replace' options.
+# 2. Execute each element of the array.
+# 3. Verify an error code is returned.
+#
+
+verify_runnable "global"
+
+DISKLIST=$(get_disklist $TESTPOOL)
+
+set -A args "" "-f" "-?" "-z fakepool" "-f fakepool" "-ev fakepool" "fakepool" \
+        "$TESTPOOL" "-t $TESTPOOL/$TESTFS" "-t $TESTPOOL/$TESTFS $DISKLIST" \
+        "$TESTPOOL/$TESTCTR" "-t $TESTPOOL/$TESTCTR/$TESTFS1" \
+        "$TESTPOOL/$TESTCTR $DISKLIST" "-t $TESTPOOL/$TESTVOL" \
+        "$TESTPOOL/$TESTCTR/$TESTFS1 $DISKLIST" \
+        "$TESTPOOL/$TESTVOL $DISKLIST" \
+        "$DISKLIST" \
+        "fakepool fakedevice" "fakepool fakedevice fakenewdevice" \
+        "$TESTPOOL fakedevice" "$TESTPOOL $DISKLIST" \
+	"$TESTPOOL fakedevice fakenewdevice fakenewdevice" \
+        "-f $TESTPOOL" "-f $TESTPOOL/$TESTFS" "-f $TESTPOOL/$TESTFS $DISKLIST" \
+        "-f $TESTPOOL/$TESTCTR" "-f $TESTPOOL/$TESTCTR/$TESTFS1" \
+        "-f $TESTPOOL/$TESTCTR $DISKLIST" "-f $TESTPOOL/$TESTVOL" \
+        "-f $TESTPOOL/$TESTCTR/$TESTFS1 $DISKLIST" \
+        "-f $TESTPOOL/$TESTVOL $DISKLIST" \
+        "-f $DISKLIST" \
+        "-f fakepool fakedevice" "-f fakepool fakedevice fakenewdevice" \
+	"-f $TESTPOOL fakedevice fakenewdevice fakenewdevice" \
+        "-f $TESTPOOL fakedevice" "-f $TESTPOOL $DISKLIST"
+
+log_assert "Executing 'zpool replace' with bad options fails"
+
+if [[ -z $DISKLIST ]]; then
+	log_fail "DISKLIST is empty."
+fi
+
+typeset -i i=0
+
+while [[ $i -lt ${#args[*]} ]]; do
+
+	log_mustnot $ZPOOL replace ${args[$i]}
+
+	(( i = i + 1 ))
+done
+
+log_pass "'zpool replace' command with bad options failed as expected."
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/usr/src/test/zfs-tests/tests/functional/cli_root/zpool_scrub/Makefile	Wed Dec 05 22:04:50 2012 -0500
@@ -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) 2012 by Delphix. All rights reserved.
+#
+
+include $(SRC)/Makefile.master
+
+ROOTOPTPKG = $(ROOT)/opt/zfs-tests
+TESTDIR = $(ROOTOPTPKG)/tests/functional/cli_root/zpool_scrub
+
+PROGS = cleanup \
+	setup \
+	zpool_scrub_001_neg \
+	zpool_scrub_002_pos \
+	zpool_scrub_003_pos \
+	zpool_scrub_004_pos \
+	zpool_scrub_005_pos
+
+FILES = zpool_scrub.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	Thu Jan 01 00:00:00 1970 +0000
+++ b/usr/src/test/zfs-tests/tests/functional/cli_root/zpool_scrub/cleanup.ksh	Wed Dec 05 22:04:50 2012 -0500
@@ -0,0 +1,32 @@
+#!/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.
+#
+
+. $STF_SUITE/include/libtest.shlib
+
+verify_runnable "global"
+
+destroy_mirrors
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/usr/src/test/zfs-tests/tests/functional/cli_root/zpool_scrub/setup.ksh	Wed Dec 05 22:04:50 2012 -0500
@@ -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) 2012 by Delphix. All rights reserved.
+#
+
+. $STF_SUITE/include/libtest.shlib
+. $STF_SUITE/tests/functional/cli_root/zpool_scrub/zpool_scrub.cfg
+
+verify_runnable "global"
+verify_disk_count "$DISKS" 2
+
+default_mirror_setup_noexit $DISK1 $DISK2
+
+mntpnt=$(get_prop mountpoint $TESTPOOL)
+typeset -i i=0
+while ((i < 10)); do
+	log_must $MKFILE 500M $mntpnt/bigfile.$i
+	((i += 1))
+done
+
+log_pass
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/usr/src/test/zfs-tests/tests/functional/cli_root/zpool_scrub/zpool_scrub.cfg	Wed Dec 05 22:04:50 2012 -0500
@@ -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 2007 Sun Microsystems, Inc.  All rights reserved.
+# Use is subject to license terms.
+#
+
+#
+# Copyright (c) 2012 by Delphix. All rights reserved.
+#
+
+export DISK1=$($ECHO $DISKS | $AWK '{print $1}')
+export DISK2=$($ECHO $DISKS | $AWK '{print $2}')
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/usr/src/test/zfs-tests/tests/functional/cli_root/zpool_scrub/zpool_scrub_001_neg.ksh	Wed Dec 05 22:04:50 2012 -0500
@@ -0,0 +1,58 @@
+#!/bin/ksh -p
+#
+# CDDL HEADER START
+#
+# The contents of this file are subject to the terms of the
+# Common Development and Distribution License (the "License").
+# You may not use this file except in compliance with the License.
+#
+# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
+# or http://www.opensolaris.org/os/licensing.
+# See the License for the specific language governing permissions
+# and limitations under the License.
+#
+# When distributing Covered Code, include this CDDL HEADER in each
+# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
+# If applicable, add the following below this CDDL HEADER, with the
+# fields enclosed by brackets "[]" replaced with your own identifying
+# information: Portions Copyright [yyyy] [name of copyright owner]
+#
+# CDDL HEADER END
+#
+
+#
+# Copyright 2007 Sun Microsystems, Inc.  All rights reserved.
+# Use is subject to license terms.
+#
+. $STF_SUITE/include/libtest.shlib
+
+#
+# DESCRIPTION:
+# A badly formed parameter passed to 'zpool scrub' should
+# return an error.
+#
+# STRATEGY:
+# 1. Create an array containing bad 'zpool scrub' parameters.
+# 2. For each element, execute the sub-command.
+# 3. Verify it returns an error.
+#
+
+verify_runnable "global"
+
+set -A args "" "-?" "blah blah" "-%" "--?" "-*" "-=" \
+    "-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" "-W" "-Z"
+
+
+log_assert "Execute 'zpool scrub' using invalid parameters."
+
+typeset -i i=0
+while [[ $i -lt ${#args[*]} ]]; do
+	log_mustnot $ZPOOL scrub ${args[i]}
+
+	((i = i + 1))
+done
+
+log_pass "Badly formed 'zpool scrub' parameters fail as expected."
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/usr/src/test/zfs-tests/tests/functional/cli_root/zpool_scrub/zpool_scrub_002_pos.ksh	Wed Dec 05 22:04:50 2012 -0500
@@ -0,0 +1,48 @@
+#!/bin/ksh -p
+#
+# CDDL HEADER START
+#
+# The contents of this file are subject to the terms of the
+# Common Development and Distribution License (the "License").
+# You may not use this file except in compliance with the License.
+#
+# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
+# or http://www.opensolaris.org/os/licensing.
+# See the License for the specific language governing permissions
+# and limitations under the License.
+#
+# When distributing Covered Code, include this CDDL HEADER in each
+# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
+# If applicable, add the following below this CDDL HEADER, with the
+# fields enclosed by brackets "[]" replaced with your own identifying
+# information: Portions Copyright [yyyy] [name of copyright owner]
+#
+# CDDL HEADER END
+#
+
+#
+# Copyright 2007 Sun Microsystems, Inc.  All rights reserved.
+# Use is subject to license terms.
+#
+
+. $STF_SUITE/include/libtest.shlib
+
+#
+# DESCRIPTION:
+#	Verify scrub -s works correctly.
+#
+# STRATEGY:
+#	1. Create pool and fill with hundreds data.
+#	2. zpool scrub the pool
+#	3. Verify zpool scrub -s succeed when the system is scrubbing.
+#
+
+verify_runnable "global"
+
+log_assert "Verify scrub -s works correctly."
+
+log_must $ZPOOL scrub $TESTPOOL
+log_must $ZPOOL scrub -s $TESTPOOL
+log_must is_pool_scrub_stopped $TESTPOOL
+
+log_pass "Verify scrub -s works correctly."
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/usr/src/test/zfs-tests/tests/functional/cli_root/zpool_scrub/zpool_scrub_003_pos.ksh	Wed Dec 05 22:04:50 2012 -0500
@@ -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.
+#
+
+. $STF_SUITE/include/libtest.shlib
+
+#
+# DESCRIPTION:
+#	scrub command terminates the existing scrub process and starts
+#	a new scrub.
+#
+# STRATEGY:
+#	1. Setup a pool and fill with data
+#	2. Kick off a scrub
+#	3. Check the completed percent and invoke another scrub
+#	4. Check the percent again, verify a new scrub started.
+#
+
+verify_runnable "global"
+
+function get_scrub_percent
+{
+	typeset -i percent
+	percent=$($ZPOOL status $TESTPOOL | $GREP "^ scrub" | \
+	    $AWK '{print $7}' | $AWK -F. '{print $1}')
+	if is_pool_scrubbed $TESTPOOL ; then
+		percent=100
+	fi
+	$ECHO $percent
+}
+
+log_assert "scrub command terminates the existing scrub process and starts" \
+	"a new scrub."
+
+log_must $ZPOOL scrub $TESTPOOL
+typeset -i PERCENT=30 percent=0
+while ((percent < PERCENT)) ; do
+	percent=$(get_scrub_percent)
+done
+
+log_must $ZPOOL scrub $TESTPOOL
+percent=$(get_scrub_percent)
+if ((percent > PERCENT)); then
+	log_fail "zpool scrub don't stop existing scrubbing process."
+fi
+
+log_pass "scrub command terminates the existing scrub process and starts" \
+	"a new scrub."
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/usr/src/test/zfs-tests/tests/functional/cli_root/zpool_scrub/zpool_scrub_004_pos.ksh	Wed Dec 05 22:04:50 2012 -0500
@@ -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) 2012 by Delphix. All rights reserved.
+#
+
+. $STF_SUITE/include/libtest.shlib
+. $STF_SUITE/tests/functional/cli_root/zpool_scrub/zpool_scrub.cfg
+
+#
+# DESCRIPTION:
+#	Resilver prevent scrub from starting until the resilver completes
+#
+# STRATEGY:
+#	1. Setup a mirror pool and filled with data.
+#	2. Detach one of devices
+#	3. Verify scrub failed until the resilver completed
+#
+
+verify_runnable "global"
+
+log_assert "Resilver prevent scrub from starting until the resilver completes"
+
+log_must $ZPOOL detach $TESTPOOL $DISK2
+log_must $ZPOOL attach $TESTPOOL $DISK1 $DISK2
+log_must is_pool_resilvering $TESTPOOL
+log_mustnot $ZPOOL scrub $TESTPOOL
+
+# Allow the resilver to finish, or it will interfere with the next test.
+while ! is_pool_resilvered $TESTPOOL; do
+	$SLEEP 1
+done
+
+log_pass "Resilver prevent scrub from starting until the resilver completes"
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/usr/src/test/zfs-tests/tests/functional/cli_root/zpool_scrub/zpool_scrub_005_pos.ksh	Wed Dec 05 22:04:50 2012 -0500
@@ -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) 2012 by Delphix. All rights reserved.
+#
+
+. $STF_SUITE/include/libtest.shlib
+. $STF_SUITE/tests/functional/cli_root/zpool_scrub/zpool_scrub.cfg
+
+#
+# DESCRIPTION:
+#	When scrubbing, detach device should not break system.
+#
+# STRATEGY:
+#	1. Setup filesys with data.
+#	2. Detaching and attaching the device when scrubbing.
+#	3. Try it twice, verify both of them work fine.
+#
+
+verify_runnable "global"
+
+log_assert "When scrubbing, detach device should not break system."
+
+log_must $ZPOOL scrub $TESTPOOL
+log_must $ZPOOL detach $TESTPOOL $DISK2
+log_must $ZPOOL attach $TESTPOOL $DISK1 $DISK2
+
+while ! is_pool_resilvered $TESTPOOL; do
+	$SLEEP 1
+done
+
+log_must $ZPOOL scrub $TESTPOOL
+log_must $ZPOOL detach $TESTPOOL $DISK1
+log_must $ZPOOL attach $TESTPOOL $DISK2 $DISK1
+
+log_pass "When scrubbing, detach device should not break system."
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/usr/src/test/zfs-tests/tests/functional/cli_root/zpool_set/Makefile	Wed Dec 05 22:04:50 2012 -0500
@@ -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) 2012 by Delphix. All rights reserved.
+#
+
+include $(SRC)/Makefile.master
+
+ROOTOPTPKG = $(ROOT)/opt/zfs-tests
+TESTDIR = $(ROOTOPTPKG)/tests/functional/cli_root/zpool_set
+
+PROGS = zpool_set_001_pos \
+	zpool_set_002_neg \
+	zpool_set_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	Thu Jan 01 00:00:00 1970 +0000
+++ b/usr/src/test/zfs-tests/tests/functional/cli_root/zpool_set/zpool_set_001_pos.ksh	Wed Dec 05 22:04:50 2012 -0500
@@ -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.
+#
+
+. $STF_SUITE/include/libtest.shlib
+#
+# DESCRIPTION:
+#
+# Zpool set usage message is displayed when called with no arguments
+#
+# STRATEGY:
+#	1. Run zpool set
+#	2. Check that exit status is set to 2
+#	3. Check usage message contains text "usage"
+#
+#
+
+log_assert "zpool set usage message is displayed when called with no arguments"
+
+$ZPOOL set > /dev/null 2>&1
+RET=$?
+if [ $RET != 2 ]
+then
+	log_fail "\"zpool set\" exit status $RET should be equal to 2."
+fi
+
+OUTPUT=$($ZPOOL set 2>&1 | $GREP -i usage)
+if [ $? != 0 ]
+then
+	log_fail "Usage message for zpool set did not contain the word 'usage'."
+fi
+
+log_pass "zpool set usage message is displayed when called with no arguments"
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/usr/src/test/zfs-tests/tests/functional/cli_root/zpool_set/zpool_set_002_neg.ksh	Wed Dec 05 22:04:50 2012 -0500
@@ -0,0 +1,119 @@
+#!/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.
+#
+
+. $STF_SUITE/include/libtest.shlib
+
+#
+# DESCRIPTION:
+#
+# Malformed zpool set commands are rejected
+#
+# STRATEGY:
+#	1. Create an array of many different malformed zfs set arguments
+#	2. Run zpool set for each arg checking each will exit with status code 1
+#
+#
+
+verify_runnable "global"
+
+# note to self - need to make sure there isn't a pool called bootfs
+# before running this test...
+function cleanup {
+
+	$ZPOOL destroy bootfs
+	$RM /tmp/zpool_set_002.$$.dat
+}
+
+log_assert "Malformed zpool set commands are rejected"
+
+if poolexists bootfs
+then
+	log_unsupported "Unable to run test on a machine with a pool called \
+ bootfs"
+fi
+
+log_onexit cleanup
+
+# build up an array of bad arguments.
+set -A arguments "rubbish " \
+		"foo@bar= " \
+		"@@@= +pool " \
+		"zpool bootfs " \
+		"bootfs " \
+		"bootfs +" \
+		"bootfs=bootfs/123 " \
+		"bootfs=bootfs@val " \
+		"Bootfs=bootfs " \
+		"- " \
+		"== " \
+		"set " \
+		"@@ " \
+		"12345 " \
+		"€にほんご " \
+		"/ " \
+		"bootfs=bootfs /" \
+		"bootfs=a%d%s "
+
+
+# here, we build up a large string.
+# a word to the ksh-wary, ${#array[@]} gives you the
+# total number of entries in an array, so array[${#array[@]}]
+# will index the last entry+1, ksh arrays start at index 0.
+COUNT=0
+while [ $COUNT -le 1025 ]
+do
+	bigname="${bigname}o"
+	COUNT=$(( $COUNT + 1 ))
+done
+
+# add an argument of maximum length property name
+arguments[${#arguments[@]}]="$bigname=value"
+
+# add an argument of maximum length property value
+arguments[${#arguments[@]}]="bootfs=$bigname"
+
+# Create a pool called bootfs (so-called, so as to trip any clashes between
+# property name, and pool name)
+# Also create a filesystem in this pool
+log_must $MKFILE 64m /tmp/zpool_set_002.$$.dat
+log_must $ZPOOL create bootfs /tmp/zpool_set_002.$$.dat
+log_must $ZFS create bootfs/root
+
+typeset -i i=0;
+while [ $i -lt "${#arguments[@]}" ]
+do
+	log_mustnot eval "$ZPOOL set ${arguments[$i]} > /dev/null 2>&1"
+
+	# now also try with a valid pool in the argument list
+	log_mustnot eval "$ZPOOL set ${arguments[$i]}bootfs > /dev/null 2>&1"
+
+	# now also try with two valid pools in the argument list
+	log_mustnot eval "$ZPOOL set ${arguments[$i]}bootfs bootfs > /dev/null"
+	i=$(( $i + 1))
+done
+
+log_pass "Malformed zpool set commands are rejected"
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/usr/src/test/zfs-tests/tests/functional/cli_root/zpool_set/zpool_set_003_neg.ksh	Wed Dec 05 22:04:50 2012 -0500
@@ -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 2007 Sun Microsystems, Inc.  All rights reserved.
+# Use is subject to license terms.
+#
+
+#
+# Copyright (c) 2012 by Delphix. All rights reserved.
+#
+
+. $STF_SUITE/include/libtest.shlib
+
+#
+# DESCRIPTION:
+#
+# zpool set cannot set a readonly property
+#
+# STRATEGY:
+# 1. Create a pool
+# 2. Verify that we can't set readonly properties on that pool
+#
+
+verify_runnable "global"
+
+function cleanup
+{
+        $ZPOOL destroy $TESTPOOL
+        $RM /tmp/zpool_set_003.$$.dat
+}
+
+set -A props "available" "capacity" "guid"  "health"  "size" "used"
+set -A vals  "100"       "10"       "12345" "HEALTHY" "10"   "10"
+
+log_onexit cleanup
+
+log_assert "zpool set cannot set a readonly property"
+
+log_must $MKFILE 64m /tmp/zpool_set_003.$$.dat
+log_must $ZPOOL create $TESTPOOL /tmp/zpool_set_003.$$.dat
+
+typeset -i i=0;
+while [ $i -lt "${#props[@]}" ]
+do
+	# try to set each property in the prop list with it's corresponding val
+        log_mustnot eval "$ZPOOL set ${props[$i]}=${vals[$i]} $TESTPOOL \
+ > /dev/null 2>&1"
+        i=$(( $i + 1))
+done
+
+log_pass "zpool set cannot set a readonly property"
+
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/usr/src/test/zfs-tests/tests/functional/cli_root/zpool_status/Makefile	Wed Dec 05 22:04:50 2012 -0500
@@ -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) 2012 by Delphix. All rights reserved.
+#
+
+include $(SRC)/Makefile.master
+
+ROOTOPTPKG = $(ROOT)/opt/zfs-tests
+TESTDIR = $(ROOTOPTPKG)/tests/functional/cli_root/zpool_status
+
+PROGS = cleanup \
+	setup \
+	zpool_status_001_pos \
+	zpool_status_002_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	Thu Jan 01 00:00:00 1970 +0000
+++ b/usr/src/test/zfs-tests/tests/functional/cli_root/zpool_status/cleanup.ksh	Wed Dec 05 22:04:50 2012 -0500
@@ -0,0 +1,30 @@
+#!/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.
+#
+
+. $STF_SUITE/include/libtest.shlib
+
+default_cleanup
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/usr/src/test/zfs-tests/tests/functional/cli_root/zpool_status/setup.ksh	Wed Dec 05 22:04:50 2012 -0500
@@ -0,0 +1,32 @@
+#!/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.
+#
+
+. $STF_SUITE/include/libtest.shlib
+
+DISK=${DISKS%% *}
+
+default_setup $DISK
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/usr/src/test/zfs-tests/tests/functional/cli_root/zpool_status/zpool_status_001_pos.ksh	Wed Dec 05 22:04:50 2012 -0500
@@ -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 2007 Sun Microsystems, Inc.  All rights reserved.
+# Use is subject to license terms.
+#
+. $STF_SUITE/include/libtest.shlib
+
+#
+# DESCRIPTION:
+# Executing 'zpool status' command with bad options fails.
+#
+# STRATEGY:
+# 1. Create an array of badly formed 'zpool status' options
+# 2. Execute each element of the array.
+# 3. Verify an error code is returned.
+#
+
+verify_runnable "both"
+
+
+set -A args "" "-?" "-x fakepool" "-v fakepool" "-xv fakepool" "-vx fakepool" \
+	"-x $TESTPOOL/$TESTFS" "-v $TESTPOOL/$TESTFS" "-xv $TESTPOOL/$TESTFS" \
+	"-vx $TESTPOOL/$TESTFS"
+
+log_assert "Executing 'zpool status' with bad options fails"
+
+typeset -i i=1
+
+while [[ $i -lt ${#args[*]} ]]; do
+
+	log_mustnot $ZPOOL status ${args[$i]}
+
+	(( i = i + 1 ))
+done
+
+log_pass "'zpool status' command with bad options failed as expected."
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/usr/src/test/zfs-tests/tests/functional/cli_root/zpool_status/zpool_status_002_pos.ksh	Wed Dec 05 22:04:50 2012 -0500
@@ -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.
+#
+. $STF_SUITE/include/libtest.shlib
+
+#
+# DESCRIPTION:
+# Executing 'zpool status' with correct options succeeds
+#
+# STRATEGY:
+# 1. Create an array of correctly formed 'zpool status' options
+# 2. Execute each element of the array.
+# 3. Verify use of each option is successful.
+#
+
+verify_runnable "both"
+
+typeset testpool
+if is_global_zone; then
+	testpool=$TESTPOOL
+else
+	testpool=${TESTPOOL%%/*}
+fi
+
+set -A args "" "-x" "-v" "-x $testpool" "-v $testpool" "-xv $testpool" \
+	"-vx $testpool"
+
+log_assert "Executing 'zpool status' with correct options succeeds"
+
+typeset -i i=0
+
+while [[ $i -lt ${#args[*]} ]]; do
+
+	log_must $ZPOOL status ${args[$i]}
+
+	(( i = i + 1 ))
+done
+
+log_pass "'zpool status' with correct options succeeded"
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/usr/src/test/zfs-tests/tests/functional/cli_root/zpool_upgrade/Makefile	Wed Dec 05 22:04:50 2012 -0500
@@ -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) 2012 by Delphix. All rights reserved.
+#
+
+include $(SRC)/Makefile.master
+
+ROOTOPTPKG = $(ROOT)/opt/zfs-tests
+TESTDIR = $(ROOTOPTPKG)/tests/functional/cli_root/zpool_upgrade
+
+PROGS = cleanup \
+	setup \
+	zpool_upgrade_001_pos \
+	zpool_upgrade_002_pos \
+	zpool_upgrade_003_pos \
+	zpool_upgrade_004_pos \
+	zpool_upgrade_005_neg \
+	zpool_upgrade_006_neg \
+	zpool_upgrade_007_pos \
+	zpool_upgrade_008_pos \
+	zpool_upgrade_009_neg
+
+FILES = zpool_upgrade.cfg \
+	zpool_upgrade.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)
+
+SUBDIRS = blockfiles
+
+include $(SRC)/test/Makefile.com
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/usr/src/test/zfs-tests/tests/functional/cli_root/zpool_upgrade/blockfiles/Makefile	Wed Dec 05 22:04:50 2012 -0500
@@ -0,0 +1,87 @@
+#
+# 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) 2012 by Delphix. All rights reserved.
+#
+
+include $(SRC)/Makefile.master
+
+ROOTOPTPKG = $(ROOT)/opt/zfs-tests
+BLOCKFILESDIR = $(ROOTOPTPKG)/tests/functional/cli_root/zpool_upgrade/blockfiles
+
+FILES = zfs-broken-mirror1.dat.bz2 \
+	zfs-broken-mirror2.dat.bz2 \
+	zfs-pool-v1.dat.bz2 \
+	zfs-pool-v10.dat.bz2 \
+	zfs-pool-v11.dat.bz2 \
+	zfs-pool-v12.dat.bz2 \
+	zfs-pool-v13.dat.bz2 \
+	zfs-pool-v14.dat.bz2 \
+	zfs-pool-v15.dat.bz2 \
+	zfs-pool-v1mirror1.dat.bz2 \
+	zfs-pool-v1mirror2.dat.bz2 \
+	zfs-pool-v1mirror3.dat.bz2 \
+	zfs-pool-v1raidz1.dat.bz2 \
+	zfs-pool-v1raidz2.dat.bz2 \
+	zfs-pool-v1raidz3.dat.bz2 \
+	zfs-pool-v1stripe1.dat.bz2 \
+	zfs-pool-v1stripe2.dat.bz2 \
+	zfs-pool-v1stripe3.dat.bz2 \
+	zfs-pool-v2.dat.bz2 \
+	zfs-pool-v2mirror1.dat.bz2 \
+	zfs-pool-v2mirror2.dat.bz2 \
+	zfs-pool-v2mirror3.dat.bz2 \
+	zfs-pool-v2raidz1.dat.bz2 \
+	zfs-pool-v2raidz2.dat.bz2 \
+	zfs-pool-v2raidz3.dat.bz2 \
+	zfs-pool-v2stripe1.dat.bz2 \
+	zfs-pool-v2stripe2.dat.bz2 \
+	zfs-pool-v2stripe3.dat.bz2 \
+	zfs-pool-v3.dat.bz2 \
+	zfs-pool-v3hotspare1.dat.bz2 \
+	zfs-pool-v3hotspare2.dat.bz2 \
+	zfs-pool-v3hotspare3.dat.bz2 \
+	zfs-pool-v3mirror1.dat.bz2 \
+	zfs-pool-v3mirror2.dat.bz2 \
+	zfs-pool-v3mirror3.dat.bz2 \
+	zfs-pool-v3raidz1.dat.bz2 \
+	zfs-pool-v3raidz2.dat.bz2 \
+	zfs-pool-v3raidz21.dat.bz2 \
+	zfs-pool-v3raidz22.dat.bz2 \
+	zfs-pool-v3raidz23.dat.bz2 \
+	zfs-pool-v3raidz3.dat.bz2 \
+	zfs-pool-v3stripe1.dat.bz2 \
+	zfs-pool-v3stripe2.dat.bz2 \
+	zfs-pool-v3stripe3.dat.bz2 \
+	zfs-pool-v4.dat.bz2 \
+	zfs-pool-v5.dat.bz2 \
+	zfs-pool-v6.dat.bz2 \
+	zfs-pool-v7.dat.bz2 \
+	zfs-pool-v8.dat.bz2 \
+	zfs-pool-v9.dat.bz2 \
+	zfs-pool-v999.dat.bz2 \
+	zfs-pool-vBROKEN.dat.bz2
+
+CMDS = $(FILES:%=$(BLOCKFILESDIR)/%)
+$(CMDS) := FILEMODE = 0444
+
+all lint clean clobber:
+
+install: $(CMDS)
+
+$(CMDS): $(BLOCKFILESDIR)
+
+$(BLOCKFILESDIR):
+	$(INS.dir)
+
+$(BLOCKFILESDIR)/%: %
+	$(INS.file)
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/usr/src/test/zfs-tests/tests/functional/cli_root/zpool_upgrade/blockfiles/README	Wed Dec 05 22:04:50 2012 -0500
@@ -0,0 +1,30 @@
+#
+# CDDL HEADER START
+#
+# The contents of this file are subject to the terms of the
+# Common Development and Distribution License (the "License").
+# You may not use this file except in compliance with the License.
+#
+# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
+# or http://www.opensolaris.org/os/licensing.
+# See the License for the specific language governing permissions
+# and limitations under the License.
+#
+# When distributing Covered Code, include this CDDL HEADER in each
+# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
+# If applicable, add the following below this CDDL HEADER, with the
+# fields enclosed by brackets "[]" replaced with your own identifying
+# information: Portions Copyright [yyyy] [name of copyright owner]
+#
+# CDDL HEADER END
+#
+
+#
+# Copyright 2007 Sun Microsystems, Inc.  All rights reserved.
+# Use is subject to license terms.
+#
+
+Unless otherwise noted, all files in this distribution are released
+under the Common Development and Distribution License (CDDL).
+
+This directory contains compressed blockfiles for zpool upgrade testing.
Binary file usr/src/test/zfs-tests/tests/functional/cli_root/zpool_upgrade/blockfiles/zfs-broken-mirror1.dat.bz2 has changed
Binary file usr/src/test/zfs-tests/tests/functional/cli_root/zpool_upgrade/blockfiles/zfs-broken-mirror2.dat.bz2 has changed
Binary file usr/src/test/zfs-tests/tests/functional/cli_root/zpool_upgrade/blockfiles/zfs-pool-v1.dat.bz2 has changed
Binary file usr/src/test/zfs-tests/tests/functional/cli_root/zpool_upgrade/blockfiles/zfs-pool-v10.dat.bz2 has changed
Binary file usr/src/test/zfs-tests/tests/functional/cli_root/zpool_upgrade/blockfiles/zfs-pool-v11.dat.bz2 has changed
Binary file usr/src/test/zfs-tests/tests/functional/cli_root/zpool_upgrade/blockfiles/zfs-pool-v12.dat.bz2 has changed
Binary file usr/src/test/zfs-tests/tests/functional/cli_root/zpool_upgrade/blockfiles/zfs-pool-v13.dat.bz2 has changed
Binary file usr/src/test/zfs-tests/tests/functional/cli_root/zpool_upgrade/blockfiles/zfs-pool-v14.dat.bz2 has changed
Binary file usr/src/test/zfs-tests/tests/functional/cli_root/zpool_upgrade/blockfiles/zfs-pool-v15.dat.bz2 has changed
Binary file usr/src/test/zfs-tests/tests/functional/cli_root/zpool_upgrade/blockfiles/zfs-pool-v1mirror1.dat.bz2 has changed
Binary file usr/src/test/zfs-tests/tests/functional/cli_root/zpool_upgrade/blockfiles/zfs-pool-v1mirror2.dat.bz2 has changed
Binary file usr/src/test/zfs-tests/tests/functional/cli_root/zpool_upgrade/blockfiles/zfs-pool-v1mirror3.dat.bz2 has changed
Binary file usr/src/test/zfs-tests/tests/functional/cli_root/zpool_upgrade/blockfiles/zfs-pool-v1raidz1.dat.bz2 has changed
Binary file usr/src/test/zfs-tests/tests/functional/cli_root/zpool_upgrade/blockfiles/zfs-pool-v1raidz2.dat.bz2 has changed
Binary file usr/src/test/zfs-tests/tests/functional/cli_root/zpool_upgrade/blockfiles/zfs-pool-v1raidz3.dat.bz2 has changed
Binary file usr/src/test/zfs-tests/tests/functional/cli_root/zpool_upgrade/blockfiles/zfs-pool-v1stripe1.dat.bz2 has changed
Binary file usr/src/test/zfs-tests/tests/functional/cli_root/zpool_upgrade/blockfiles/zfs-pool-v1stripe2.dat.bz2 has changed
Binary file usr/src/test/zfs-tests/tests/functional/cli_root/zpool_upgrade/blockfiles/zfs-pool-v1stripe3.dat.bz2 has changed
Binary file usr/src/test/zfs-tests/tests/functional/cli_root/zpool_upgrade/blockfiles/zfs-pool-v2.dat.bz2 has changed
Binary file usr/src/test/zfs-tests/tests/functional/cli_root/zpool_upgrade/blockfiles/zfs-pool-v2mirror1.dat.bz2 has changed
Binary file usr/src/test/zfs-tests/tests/functional/cli_root/zpool_upgrade/blockfiles/zfs-pool-v2mirror2.dat.bz2 has changed
Binary file usr/src/test/zfs-tests/tests/functional/cli_root/zpool_upgrade/blockfiles/zfs-pool-v2mirror3.dat.bz2 has changed
Binary file usr/src/test/zfs-tests/tests/functional/cli_root/zpool_upgrade/blockfiles/zfs-pool-v2raidz1.dat.bz2 has changed
Binary file usr/src/test/zfs-tests/tests/functional/cli_root/zpool_upgrade/blockfiles/zfs-pool-v2raidz2.dat.bz2 has changed
Binary file usr/src/test/zfs-tests/tests/functional/cli_root/zpool_upgrade/blockfiles/zfs-pool-v2raidz3.dat.bz2 has changed
Binary file usr/src/test/zfs-tests/tests/functional/cli_root/zpool_upgrade/blockfiles/zfs-pool-v2stripe1.dat.bz2 has changed
Binary file usr/src/test/zfs-tests/tests/functional/cli_root/zpool_upgrade/blockfiles/zfs-pool-v2stripe2.dat.bz2 has changed
Binary file usr/src/test/zfs-tests/tests/functional/cli_root/zpool_upgrade/blockfiles/zfs-pool-v2stripe3.dat.bz2 has changed
Binary file usr/src/test/zfs-tests/tests/functional/cli_root/zpool_upgrade/blockfiles/zfs-pool-v3.dat.bz2 has changed
Binary file usr/src/test/zfs-tests/tests/functional/cli_root/zpool_upgrade/blockfiles/zfs-pool-v3hotspare1.dat.bz2 has changed
Binary file usr/src/test/zfs-tests/tests/functional/cli_root/zpool_upgrade/blockfiles/zfs-pool-v3hotspare2.dat.bz2 has changed
Binary file usr/src/test/zfs-tests/tests/functional/cli_root/zpool_upgrade/blockfiles/zfs-pool-v3hotspare3.dat.bz2 has changed
Binary file usr/src/test/zfs-tests/tests/functional/cli_root/zpool_upgrade/blockfiles/zfs-pool-v3mirror1.dat.bz2 has changed
Binary file usr/src/test/zfs-tests/tests/functional/cli_root/zpool_upgrade/blockfiles/zfs-pool-v3mirror2.dat.bz2 has changed
Binary file usr/src/test/zfs-tests/tests/functional/cli_root/zpool_upgrade/blockfiles/zfs-pool-v3mirror3.dat.bz2 has changed
Binary file usr/src/test/zfs-tests/tests/functional/cli_root/zpool_upgrade/blockfiles/zfs-pool-v3raidz1.dat.bz2 has changed
Binary file usr/src/test/zfs-tests/tests/functional/cli_root/zpool_upgrade/blockfiles/zfs-pool-v3raidz2.dat.bz2 has changed
Binary file usr/src/test/zfs-tests/tests/functional/cli_root/zpool_upgrade/blockfiles/zfs-pool-v3raidz21.dat.bz2 has changed
Binary file usr/src/test/zfs-tests/tests/functional/cli_root/zpool_upgrade/blockfiles/zfs-pool-v3raidz22.dat.bz2 has changed
Binary file usr/src/test/zfs-tests/tests/functional/cli_root/zpool_upgrade/blockfiles/zfs-pool-v3raidz23.dat.bz2 has changed
Binary file usr/src/test/zfs-tests/tests/functional/cli_root/zpool_upgrade/blockfiles/zfs-pool-v3raidz3.dat.bz2 has changed
Binary file usr/src/test/zfs-tests/tests/functional/cli_root/zpool_upgrade/blockfiles/zfs-pool-v3stripe1.dat.bz2 has changed
Binary file usr/src/test/zfs-tests/tests/functional/cli_root/zpool_upgrade/blockfiles/zfs-pool-v3stripe2.dat.bz2 has changed
Binary file usr/src/test/zfs-tests/tests/functional/cli_root/zpool_upgrade/blockfiles/zfs-pool-v3stripe3.dat.bz2 has changed
Binary file usr/src/test/zfs-tests/tests/functional/cli_root/zpool_upgrade/blockfiles/zfs-pool-v4.dat.bz2 has changed
Binary file usr/src/test/zfs-tests/tests/functional/cli_root/zpool_upgrade/blockfiles/zfs-pool-v5.dat.bz2 has changed
Binary file usr/src/test/zfs-tests/tests/functional/cli_root/zpool_upgrade/blockfiles/zfs-pool-v6.dat.bz2 has changed
Binary file usr/src/test/zfs-tests/tests/functional/cli_root/zpool_upgrade/blockfiles/zfs-pool-v7.dat.bz2 has changed
Binary file usr/src/test/zfs-tests/tests/functional/cli_root/zpool_upgrade/blockfiles/zfs-pool-v8.dat.bz2 has changed
Binary file usr/src/test/zfs-tests/tests/functional/cli_root/zpool_upgrade/blockfiles/zfs-pool-v9.dat.bz2 has changed
Binary file usr/src/test/zfs-tests/tests/functional/cli_root/zpool_upgrade/blockfiles/zfs-pool-v999.dat.bz2 has changed
Binary file usr/src/test/zfs-tests/tests/functional/cli_root/zpool_upgrade/blockfiles/zfs-pool-vBROKEN.dat.bz2 has changed
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/usr/src/test/zfs-tests/tests/functional/cli_root/zpool_upgrade/cleanup.ksh	Wed Dec 05 22:04:50 2012 -0500
@@ -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) 2012 by Delphix. All rights reserved.
+#
+
+. $STF_SUITE/include/libtest.shlib
+. $STF_SUITE/tests/functional/cli_root/zpool_upgrade/zpool_upgrade.kshlib
+
+function destroy_upgraded_pools {
+	for config in $CONFIGS; do
+		POOL_NAME=$(eval $ECHO \$ZPOOL_VERSION_${VERSION}_NAME)
+		POOL_FILES=$(eval $ECHO \$ZPOOL_VERSION_${VERSION}_FILES)
+		poolexists $POOL_NAME && log_must $ZPOOL destroy -f $POOL_NAME
+	done
+}
+
+destroy_upgraded_pools
+
+default_cleanup
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/usr/src/test/zfs-tests/tests/functional/cli_root/zpool_upgrade/setup.ksh	Wed Dec 05 22:04:50 2012 -0500
@@ -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 2009 Sun Microsystems, Inc.  All rights reserved.
+# Use is subject to license terms.
+#
+
+#
+# Copyright (c) 2012 by Delphix. All rights reserved.
+#
+
+. $STF_SUITE/include/libtest.shlib
+
+verify_runnable "global"
+verify_disk_count "$DISKS" 2
+
+# give us a pool to play in
+default_mirror_setup $DISKS
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/usr/src/test/zfs-tests/tests/functional/cli_root/zpool_upgrade/zpool_upgrade.cfg	Wed Dec 05 22:04:50 2012 -0500
@@ -0,0 +1,165 @@
+#
+# CDDL HEADER START
+#
+# The contents of this file are subject to the terms of the
+# Common Development and Distribution License (the "License").
+# You may not use this file except in compliance with the License.
+#
+# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
+# or http://www.opensolaris.org/os/licensing.
+# See the License for the specific language governing permissions
+# and limitations under the License.
+#
+# When distributing Covered Code, include this CDDL HEADER in each
+# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
+# If applicable, add the following below this CDDL 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) 2012 by Delphix. All rights reserved.
+#
+
+. $STF_SUITE/include/libtest.shlib
+
+# The following variable names describe files, stored as gzip compressed files
+# in the test directory which can be used to construct a pool of a given
+# version. The variable names are important, in that the construction
+# ZPOOL_VERSION_$var_FILES describes the files the pool is made from, and
+# ZPOOL_VERSION_$var_NAME describes the pool name.
+
+# Version 1 pools
+export ZPOOL_VERSION_1_FILES="zfs-pool-v1.dat"
+export ZPOOL_VERSION_1_NAME="v1-pool"
+# v1 stripe
+export ZPOOL_VERSION_1stripe_FILES="zfs-pool-v1stripe1.dat \
+zfs-pool-v1stripe2.dat  zfs-pool-v1stripe3.dat"
+export ZPOOL_VERSION_1stripe_NAME="pool-v1stripe"
+# v1 raidz
+export ZPOOL_VERSION_1raidz_FILES="zfs-pool-v1raidz1.dat zfs-pool-v1raidz2.dat \
+zfs-pool-v1raidz3.dat"
+export ZPOOL_VERSION_1raidz_NAME="pool-v1raidz"
+# v1 mirror
+export ZPOOL_VERSION_1mirror_FILES="zfs-pool-v1mirror1.dat \
+zfs-pool-v1mirror2.dat zfs-pool-v1mirror3.dat"
+export ZPOOL_VERSION_1mirror_NAME="pool-v1mirror"
+
+
+# Version 2 pools
+export ZPOOL_VERSION_2_FILES="zfs-pool-v2.dat"
+export ZPOOL_VERSION_2_NAME="v2-pool"
+# v2 stripe
+export ZPOOL_VERSION_2stripe_FILES="zfs-pool-v2stripe1.dat \
+zfs-pool-v2stripe2.dat  zfs-pool-v2stripe3.dat"
+export ZPOOL_VERSION_2stripe_NAME="pool-v2stripe"
+# v2 raidz
+export ZPOOL_VERSION_2raidz_FILES="zfs-pool-v2raidz1.dat zfs-pool-v2raidz2.dat \
+zfs-pool-v2raidz3.dat"
+export ZPOOL_VERSION_2raidz_NAME="pool-v2raidz"
+# v2 mirror
+export ZPOOL_VERSION_2mirror_FILES="zfs-pool-v2mirror1.dat \
+zfs-pool-v2mirror2.dat zfs-pool-v2mirror3.dat"
+export ZPOOL_VERSION_2mirror_NAME="pool-v2mirror"
+
+
+# This is a v3 pool
+export ZPOOL_VERSION_3_FILES="zfs-pool-v3.dat"
+export ZPOOL_VERSION_3_NAME="v3-pool"
+# v3 stripe
+export ZPOOL_VERSION_3stripe_FILES="zfs-pool-v3stripe1.dat \
+zfs-pool-v3stripe2.dat  zfs-pool-v3stripe3.dat"
+export ZPOOL_VERSION_3stripe_NAME="pool-v3stripe"
+# v3 raidz
+export ZPOOL_VERSION_3raidz_FILES="zfs-pool-v3raidz1.dat zfs-pool-v3raidz2.dat \
+zfs-pool-v3raidz3.dat"
+export ZPOOL_VERSION_3raidz_NAME="pool-v3raidz"
+# v3 mirror
+export ZPOOL_VERSION_3mirror_FILES="zfs-pool-v3mirror1.dat \
+zfs-pool-v3mirror2.dat zfs-pool-v3mirror3.dat"
+export ZPOOL_VERSION_3mirror_NAME="pool-v3mirror"
+# v3 raidz2
+export ZPOOL_VERSION_3dblraidz_FILES="zfs-pool-v3raidz21.dat \
+zfs-pool-v3raidz22.dat zfs-pool-v3raidz23.dat"
+export ZPOOL_VERSION_3dblraidz_NAME="pool-v3raidz2"
+# v3 hotspares
+export ZPOOL_VERSION_3hotspare_FILES="zfs-pool-v3hotspare1.dat \
+zfs-pool-v3hotspare2.dat zfs-pool-v3hotspare3.dat"
+export ZPOOL_VERSION_3hotspare_NAME="pool-v3hotspare"
+
+# v4 pool
+export ZPOOL_VERSION_4_FILES="zfs-pool-v4.dat"
+export ZPOOL_VERSION_4_NAME="v4-pool"
+
+# v5 pool
+export ZPOOL_VERSION_5_FILES="zfs-pool-v5.dat"
+export ZPOOL_VERSION_5_NAME="v5-pool"
+
+# v6 pool
+export ZPOOL_VERSION_6_FILES="zfs-pool-v6.dat"
+export ZPOOL_VERSION_6_NAME="v6-pool"
+
+# v7 pool
+export ZPOOL_VERSION_7_FILES="zfs-pool-v7.dat"
+export ZPOOL_VERSION_7_NAME="v7-pool"
+
+# v8 pool
+export ZPOOL_VERSION_8_FILES="zfs-pool-v8.dat"
+export ZPOOL_VERSION_8_NAME="v8-pool"
+
+# v9 pool
+export ZPOOL_VERSION_9_FILES="zfs-pool-v9.dat"
+export ZPOOL_VERSION_9_NAME="v9-pool"
+
+# v10 pool
+export ZPOOL_VERSION_10_FILES="zfs-pool-v10.dat"
+export ZPOOL_VERSION_10_NAME="v10-pool"
+
+# v11 pool
+export ZPOOL_VERSION_11_FILES="zfs-pool-v11.dat"
+export ZPOOL_VERSION_11_NAME="v11-pool"
+
+# v12 pool
+export ZPOOL_VERSION_12_FILES="zfs-pool-v12.dat"
+export ZPOOL_VERSION_12_NAME="v12-pool"
+
+# v13 pool
+export ZPOOL_VERSION_13_FILES="zfs-pool-v13.dat"
+export ZPOOL_VERSION_13_NAME="v13-pool"
+
+# v14 pool
+export ZPOOL_VERSION_14_FILES="zfs-pool-v14.dat"
+export ZPOOL_VERSION_14_NAME="v14-pool"
+
+# v15 pool
+export ZPOOL_VERSION_15_FILES="zfs-pool-v15.dat"
+export ZPOOL_VERSION_15_NAME="v15-pool"
+
+# This pool is a v2 pool, with device problems on one side of the mirror
+# so that the pool appears as DEGRADED
+export ZPOOL_VERSION_2brokenmirror_FILES="zfs-broken-mirror1.dat \
+zfs-broken-mirror2.dat"
+export ZPOOL_VERSION_2brokenmirror_NAME="zfs-broken-mirror"
+
+
+# This pool is a v999 pool (an unknown version) which can be used to check
+# whether upgrade, import or other tests that should fail against unknown
+# pool versions should fail. It should not be listed in the CONFIGS
+# variable below, as these are pool versions that can be imported and upgraded
+export ZPOOL_VERSION_9999_FILES="zfs-pool-v999.dat"
+export ZPOOL_VERSION_9999_NAME="v999-pool"
+
+
+# This is a list of pool configurations we should be able to upgrade from,
+# each entry should have corresponding ZPOOL_VERSION_*_FILES and
+# ZPOOL_VERSION_*_NAME variables defined above.
+export CONFIGS="1 1stripe 1raidz 1mirror \
+2 2stripe 2raidz 2mirror 2brokenmirror \
+3 3stripe 3raidz 3mirror 3dblraidz 3hotspare 4 5 6 7 8 9 10 11 12 13 14 15"
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/usr/src/test/zfs-tests/tests/functional/cli_root/zpool_upgrade/zpool_upgrade.kshlib	Wed Dec 05 22:04:50 2012 -0500
@@ -0,0 +1,162 @@
+#
+# CDDL HEADER START
+#
+# The contents of this file are subject to the terms of the
+# Common Development and Distribution License (the "License").
+# You may not use this file except in compliance with the License.
+#
+# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
+# or http://www.opensolaris.org/os/licensing.
+# See the License for the specific language governing permissions
+# and limitations under the License.
+#
+# When distributing Covered Code, include this CDDL HEADER in each
+# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
+# If applicable, add the following below this CDDL 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.
+#
+
+. $STF_SUITE/include/libtest.shlib
+. $STF_SUITE/tests/functional/cli_root/zpool_upgrade/zpool_upgrade.cfg
+
+# This part of the test suite relies on variables being setup in the
+# zpool_upgrade.cfg script. Those variables give us details about which
+# files make up the pool, and what the pool name is.
+
+
+# A function to import a pool from files we have stored in the test suite
+# We import the pool, and create some random data in the pool.
+# $1 a version number we can use to get information about the pool
+function create_old_pool
+{
+	VERSION=$1
+	POOL_FILES=$(eval $ECHO \$ZPOOL_VERSION_${VERSION}_FILES)
+	POOL_NAME=$(eval $ECHO \$ZPOOL_VERSION_${VERSION}_NAME)
+
+	log_note "Creating $POOL_NAME from $POOL_FILES"
+	for pool_file in $POOL_FILES; do
+		log_must $BZCAT \
+		    $STF_SUITE/tests/functional/cli_root/zpool_upgrade/blockfiles/$pool_file.bz2 \
+		    >/$TESTPOOL/$pool_file
+	done
+	log_must $ZPOOL import -d /$TESTPOOL $POOL_NAME
+
+	# Now put some random contents into the pool.
+	COUNT=0
+	while [ $COUNT -lt 1024 ]; do
+		$DD if=/dev/urandom of=/$POOL_NAME/random.$COUNT \
+		count=1 bs=1024 > /dev/null 2>&1
+		COUNT=$(( $COUNT + 1 ))
+	done
+}
+
+
+# A function to check the contents of a pool, upgrade it to the current version
+# and then verify that the data is consistent after upgrading. Note that we're
+# not using "zpool status -x" to see if the pool is healthy, as it's possible
+# to also upgrade faulted, or degraded pools.
+# $1 a version number we can use to get information about the pool
+function check_upgrade {
+	VERSION=$1
+	POOL_FILES=$(eval $ECHO \$ZPOOL_VERSION_${VERSION}_FILES)
+	POOL_NAME=$(eval $ECHO \$ZPOOL_VERSION_${VERSION}_NAME)
+
+	log_note "Checking if we can upgrade from ZFS version ${VERSION}."
+	PRE_UPGRADE_CHECKSUM=$(check_pool $POOL_NAME pre )
+	log_must $ZPOOL upgrade $POOL_NAME > /dev/null
+	POST_UPGRADE_CHECKSUM=$(check_pool $POOL_NAME post )
+
+	log_note "Checking that there are no differences between checksum output"
+	log_must $DIFF $PRE_UPGRADE_CHECKSUM $POST_UPGRADE_CHECKSUM
+	$RM $PRE_UPGRADE_CHECKSUM $POST_UPGRADE_CHECKSUM
+}
+
+# A function to destroy an upgraded pool, plus the files it was based on.
+# $1 a version number we can use to get information about the pool
+function destroy_upgraded_pool {
+	VERSION=$1
+	POOL_FILES=$(eval $ECHO \$ZPOOL_VERSION_${VERSION}_FILES)
+	POOL_NAME=$(eval $ECHO \$ZPOOL_VERSION_${VERSION}_NAME)
+
+	if poolexists $POOL_NAME; then
+		log_must $ZPOOL destroy $POOL_NAME
+	fi
+	for file in $POOL_FILES; do
+		if [ -e /$TESTPOOL/$file ]; then
+			$RM /$TESTPOOL/$file
+		fi
+	done
+}
+
+# This function does a basic sanity check on the pool by computing the
+# checksums of all files in the pool, echoing the name of the file containing
+# the checksum results.
+# $1 the name of the pool
+# $2 a flag we can use to determine when this check is being performed
+#    (ie. pre or post pool-upgrade)
+function check_pool { # pool state
+	POOL=$1
+	STATE=$2
+	$FIND /$POOL -type f -exec $CKSUM {} + > \
+		/$TESTPOOL/pool-checksums.$POOL.$STATE
+	echo /$TESTPOOL/pool-checksums.$POOL.$STATE
+}
+
+# This function simply checks that a pool has a particular version number
+# as reported by zdb and zpool upgrade -v
+# $1 the name of the pool
+# $2 the version of the pool we expect to see
+function check_poolversion { # pool version
+
+	POOL=$1
+	VERSION=$2
+
+	# check version using zdb
+	ACTUAL=$($ZDB -C $POOL | $SED -n 's/version: \(.*\)$/\1/p')
+
+	if [ $ACTUAL != $VERSION ]
+	then
+		log_fail "$POOL not upgraded, ver. $ACTUAL, expected $VERSION"
+	fi
+
+	# check version using zpool upgrade
+	ACTUAL=$($ZPOOL upgrade | $GREP $POOL$ | \
+	 $AWK '{print $1}' | $SED -e 's/ //g')
+	if [ $ACTUAL != $VERSION ]
+	then
+		log_fail "$POOL reported version $ACTUAL, expected $VERSION"
+	fi
+}
+
+# A simple function to get a random number between two bounds
+# probably not the most efficient for large ranges, but it's okay.
+# Note since we're using $RANDOM, 32767 is the largest number we
+# can accept as the upper bound.
+# $1 lower bound
+# $2 upper bound
+function random { # min max
+
+	typeset MIN=$1
+	typeset MAX=$2
+	typeset RAND=0
+
+	while [ $RAND -lt $MIN ]
+	do
+		RAND=$(( $RANDOM % $MAX + 1))
+	done
+
+	echo $RAND
+}
+
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/usr/src/test/zfs-tests/tests/functional/cli_root/zpool_upgrade/zpool_upgrade_001_pos.ksh	Wed Dec 05 22:04:50 2012 -0500
@@ -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 2008 Sun Microsystems, Inc.  All rights reserved.
+# Use is subject to license terms.
+#
+
+#
+# Copyright (c) 2012 by Delphix. All rights reserved.
+#
+
+. $STF_SUITE/include/libtest.shlib
+. $STF_SUITE/tests/functional/cli_root/zpool_upgrade/zpool_upgrade.cfg
+
+#
+# DESCRIPTION:
+# Executing 'zpool upgrade -v' command succeeds, prints a description of legacy
+# versions, and mentions feature flags.
+#
+# STRATEGY:
+# 1. Execute the command
+# 2. Verify a 0 exit status
+# 3. Grep for version descriptions and 'feature flags'
+#
+
+verify_runnable "global"
+
+log_assert "Executing 'zpool upgrade -v' command succeeds."
+
+log_must $ZPOOL upgrade -v
+
+# We also check that the usage message contains a description of legacy
+# versions and a note about feature flags.
+
+log_must eval "$ZPOOL upgrade -v | $HEAD -1 | $GREP 'feature flags'"
+
+$ZPOOL upgrade -v > /tmp/zpool-versions.$$
+
+#
+# Current output for 'zpool upgrade -v' has different indent space
+# for single and double digit version number. For example,
+#  9   refquota and refreservation properties
+#  10  Cache devices
+#
+for version in {1..28}; do
+	log_note "Checking for a description of pool version $version."
+	log_must eval "$AWK '/^ $version / { print $1 }' /tmp/zpool-versions.$$ | $GREP $version"
+done
+$RM /tmp/zpool-versions.$$
+
+log_pass "Executing 'zpool upgrade -v' command succeeds."
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/usr/src/test/zfs-tests/tests/functional/cli_root/zpool_upgrade/zpool_upgrade_002_pos.ksh	Wed Dec 05 22:04:50 2012 -0500
@@ -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 2008 Sun Microsystems, Inc.  All rights reserved.
+# Use is subject to license terms.
+#
+#
+
+. $STF_SUITE/include/libtest.shlib
+. $STF_SUITE/tests/functional/cli_root/zpool_upgrade/zpool_upgrade.kshlib
+
+#
+# DESCRIPTION:
+# import pools of all versions - zpool upgrade on each pools works
+#
+# STRATEGY:
+# 1. Execute the command with several invalid options
+# 2. Verify a 0 exit status for each
+#
+
+verify_runnable "global"
+
+function cleanup
+{
+	destroy_upgraded_pool $config
+}
+
+log_assert "Import pools of all versions - zpool upgrade on each pools works"
+log_onexit cleanup
+
+# $CONFIGS gets set in the .cfg script
+for config in $CONFIGS
+do
+    create_old_pool $config
+    check_upgrade $config
+    destroy_upgraded_pool $config
+done
+
+log_pass "Import pools of all versions - zpool upgrade on each pools works"
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/usr/src/test/zfs-tests/tests/functional/cli_root/zpool_upgrade/zpool_upgrade_003_pos.ksh	Wed Dec 05 22:04:50 2012 -0500
@@ -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 2008 Sun Microsystems, Inc.  All rights reserved.
+# Use is subject to license terms.
+#
+#
+
+. $STF_SUITE/include/libtest.shlib
+. $STF_SUITE/tests/functional/cli_root/zpool_upgrade/zpool_upgrade.kshlib
+
+#
+# DESCRIPTION:
+# Upgrading a pool that has already been upgraded succeeds.
+#
+# STRATEGY:
+# 1. Upgrade a pool, then try to upgrade it again
+# 2. Verify a 0 exit status
+#
+
+verify_runnable "global"
+
+function cleanup
+{
+	destroy_upgraded_pool 1
+}
+
+log_assert "Upgrading a pool that has already been upgraded succeeds."
+log_onexit cleanup
+
+# we just create a version 1 pool here
+create_old_pool 1
+check_upgrade 1
+check_upgrade 1
+destroy_upgraded_pool 1
+
+log_pass "Upgrading a pool that has already been upgraded succeeds."
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/usr/src/test/zfs-tests/tests/functional/cli_root/zpool_upgrade/zpool_upgrade_004_pos.ksh	Wed Dec 05 22:04:50 2012 -0500
@@ -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 2009 Sun Microsystems, Inc.  All rights reserved.
+# Use is subject to license terms.
+#
+
+#
+# Copyright (c) 2012 by Delphix. All rights reserved.
+#
+
+. $STF_SUITE/include/libtest.shlib
+. $STF_SUITE/tests/functional/cli_root/zpool_upgrade/zpool_upgrade.kshlib
+
+#
+# DESCRIPTION:
+# zpool upgrade -a works
+#
+# STRATEGY:
+# 1. Create all upgradable pools for this system, then upgrade -a
+# 2. Verify a 0 exit status
+#
+
+verify_runnable "global"
+
+function cleanup
+{
+	for config in $CONFIGS ; do
+		destroy_upgraded_pool $config
+	done
+}
+
+log_assert "zpool upgrade -a works"
+log_onexit cleanup
+
+TEST_POOLS=
+# Now build all of our pools
+for config in $CONFIGS
+do
+	POOL_NAME=$(eval $ECHO \$ZPOOL_VERSION_${config}_NAME)
+
+	TEST_POOLS="$TEST_POOLS $POOL_NAME"
+	create_old_pool $config
+	# a side effect of the check_pool here, is that we get a checksum written
+	# called /$TESTPOOL/pool-checksums.$POOL.pre
+	check_pool $POOL_NAME pre > /dev/null
+done
+
+# upgrade them all at once
+export __ZFS_POOL_RESTRICT="$TEST_POOLS"
+log_must $ZPOOL upgrade -a
+unset __ZFS_POOL_RESTRICT
+
+# verify their contents then destroy them
+for config in $CONFIGS
+do
+	POOL_NAME=$(eval $ECHO \$ZPOOL_VERSION_${config}_NAME)
+
+	check_pool $POOL_NAME post > /dev/null
+
+	# a side effect of the check_pool here, is that we get a checksum written
+	# called /$TESTPOOL/pool-checksums.$POOL_NAME.post
+	log_must $DIFF /$TESTPOOL/pool-checksums.$POOL_NAME.pre \
+		/$TESTPOOL/pool-checksums.$POOL_NAME.post
+
+	$RM /$TESTPOOL/pool-checksums.$POOL_NAME.pre /$TESTPOOL/pool-checksums.$POOL_NAME.post
+	destroy_upgraded_pool $config
+done
+
+log_pass "zpool upgrade -a works"
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/usr/src/test/zfs-tests/tests/functional/cli_root/zpool_upgrade/zpool_upgrade_005_neg.ksh	Wed Dec 05 22:04:50 2012 -0500
@@ -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 2007 Sun Microsystems, Inc.  All rights reserved.
+# Use is subject to license terms.
+#
+
+#
+# Copyright (c) 2012 by Delphix. All rights reserved.
+#
+
+. $STF_SUITE/include/libtest.shlib
+. $STF_SUITE/tests/functional/cli_root/zpool_upgrade/zpool_upgrade.cfg
+
+#
+# DESCRIPTION:
+# Variations of upgrade -v print usage message, return with non-zero status
+#
+# STRATEGY:
+# 1. Execute the command with several invalid options
+# 2. Verify a 0 exit status for each
+#
+
+verify_runnable "global"
+
+set -A args "/tmp" "-?" "-va" "-v fakepool" "-a fakepool"
+
+log_assert "Variations of upgrade -v print usage message, \
+ return with non-zero status"
+
+typeset -i i=0
+
+while [[ $i -lt ${#args[*]} ]]; do
+
+        log_mustnot $ZPOOL upgrade ${args[$i]} > /dev/null
+
+        (( i = i + 1 ))
+done
+
+log_pass "Variations of upgrade -v print usage message, \
+ return with non-zero status"
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/usr/src/test/zfs-tests/tests/functional/cli_root/zpool_upgrade/zpool_upgrade_006_neg.ksh	Wed Dec 05 22:04:50 2012 -0500
@@ -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) 2012 by Delphix. All rights reserved.
+#
+
+. $STF_SUITE/include/libtest.shlib
+. $STF_SUITE/tests/functional/cli_root/zpool_upgrade/zpool_upgrade.cfg
+
+#
+# DESCRIPTION:
+# Attempting to upgrade a non-existent pool will return an error
+#
+# STRATEGY:
+# 1. Verify a pool doesn't exist, then try to upgrade it
+# 2. Verify a 0 exit status
+#
+
+log_assert "Attempting to upgrade a non-existent pool will return an error"
+NO_POOL=notapool
+FOUND=""
+
+while [ -z "$FOUND" ]
+do
+   $ZPOOL list $NO_POOL 2>&1 > /dev/null
+   if [ $? -ne 0 ]
+   then
+      FOUND="true"
+      log_mustnot $ZPOOL upgrade $NO_POOL
+   else
+      NO_POOL="${NO_POOL}x"
+   fi
+done
+
+log_pass "Attempting to upgrade a non-existent pool will return an error"
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/usr/src/test/zfs-tests/tests/functional/cli_root/zpool_upgrade/zpool_upgrade_007_pos.ksh	Wed Dec 05 22:04:50 2012 -0500
@@ -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 2008 Sun Microsystems, Inc.  All rights reserved.
+# Use is subject to license terms.
+#
+
+#
+# Copyright (c) 2012 by Delphix. All rights reserved.
+#
+
+. $STF_SUITE/include/libtest.shlib
+. $STF_SUITE/tests/functional/cli_root/zpool_upgrade/zpool_upgrade.kshlib
+. $STF_SUITE/tests/functional/cli_root/zfs_upgrade/zfs_upgrade.kshlib
+
+#
+# DESCRIPTION:
+# import pools of all versions - verify the following operation not break.
+#	* zfs create -o version=<vers> <filesystem>
+#	* zfs upgrade [-V vers] <filesystem>
+#	* zfs set version=<vers> <filesystem>
+#
+# STRATEGY:
+# 1. Import pools of all versions
+# 2. Setup a test enviorment over the old pools.
+# 3. Verify the commands related to 'zfs upgrade' succeed as expected.
+#
+
+verify_runnable "global"
+
+function cleanup
+{
+	destroy_upgraded_pool $config
+}
+
+log_assert "Import pools of all versions - 'zfs upgrade' on each pools works"
+log_onexit cleanup
+
+# $CONFIGS gets set in the .cfg script
+for config in $CONFIGS
+do
+	create_old_pool $config
+	POOL_NAME=$(eval $ECHO \$ZPOOL_VERSION_${config}_NAME)
+
+	default_check_zfs_upgrade $pool
+	destroy_upgraded_pool $config
+done
+
+log_pass "Import pools of all versions - 'zfs upgrade' on each pools works"
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/usr/src/test/zfs-tests/tests/functional/cli_root/zpool_upgrade/zpool_upgrade_008_pos.ksh	Wed Dec 05 22:04:50 2012 -0500
@@ -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) 2012 by Delphix. All rights reserved.
+#
+
+. $STF_SUITE/include/libtest.shlib
+. $STF_SUITE/tests/functional/cli_root/zpool_upgrade/zpool_upgrade.kshlib
+
+#
+# DESCRIPTION:
+#
+# Zpool upgrade should be able to upgrade pools to a given version using -V
+#
+# STRATEGY:
+# 1. For all versions pools that can be upgraded on a given OS version
+#    (latest pool version - 1)
+# 2. Pick a version that's a random number, greater than the version
+#    we're running.
+# 3. Attempt to upgrade that pool to the given version
+# 4. Check the pool was upgraded correctly.
+#
+
+verify_runnable "global"
+
+function cleanup
+{
+	destroy_upgraded_pool $config
+}
+
+log_assert \
+ "Zpool upgrade should be able to upgrade pools to a given version using -V"
+
+log_onexit cleanup
+
+# We're just using the single disk version of the pool, which should be
+# enough to determine if upgrade works correctly. Also set a MAX_VER
+# variable, which specifies the highest version that we should expect
+# a zpool upgrade operation to succeed from. (latest version - 1)
+CONFIGS="1 2 3 4 5 6 7 8 9 10 11 12 13 14 15"
+MAX_VER=15
+
+for config in $CONFIGS
+do
+        create_old_pool $config
+	pool=$(eval $ECHO \$ZPOOL_VERSION_${config}_NAME)
+	NEXT=$(random $config $MAX_VER)
+	log_must $ZPOOL upgrade -V $NEXT $pool
+        check_poolversion $pool $NEXT
+        destroy_upgraded_pool $config
+done
+
+log_pass "zpool upgrade should be able to upgrade pools to a given version " \
+    "using -V"
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/usr/src/test/zfs-tests/tests/functional/cli_root/zpool_upgrade/zpool_upgrade_009_neg.ksh	Wed Dec 05 22:04:50 2012 -0500
@@ -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) 2012 by Delphix. All rights reserved.
+#
+
+. $STF_SUITE/include/libtest.shlib
+. $STF_SUITE/tests/functional/cli_root/zpool_upgrade/zpool_upgrade.kshlib
+
+#
+# DESCRIPTION:
+#
+# Zpool upgrade -V shouldn't be able to upgrade a pool to an unknown version
+#
+# STRATEGY:
+# 1. Take an existing pool
+# 2. Attempt to upgrade it to an unknown version
+# 3. Verify that the upgrade failed, and the pool version was still the original
+#
+
+verify_runnable "global"
+
+function cleanup
+{
+	destroy_upgraded_pool $config
+}
+
+log_assert \
+"Zpool upgrade -V shouldn't be able to upgrade a pool to an unknown version"
+
+# Create a version 2 pool
+typeset -i config=2
+create_old_pool $config
+pool=$(eval $ECHO \$ZPOOL_VERSION_${config}_NAME)
+
+# Attempt to upgrade it
+log_mustnot $ZPOOL upgrade -V 999 $pool
+log_mustnot $ZPOOL upgrade -V 999
+
+# Verify we're still on the old version
+check_poolversion $pool $config
+destroy_upgraded_pool $config
+
+log_pass \
+ "Zpool upgrade -V shouldn't be able to upgrade a pool to an unknown version"
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/usr/src/test/zfs-tests/tests/functional/nopwrite/Makefile	Wed Dec 05 22:04:50 2012 -0500
@@ -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) 2012 by Delphix. All rights reserved.
+#
+
+include $(SRC)/Makefile.master
+
+ROOTOPTPKG = $(ROOT)/opt/zfs-tests
+TESTDIR = $(ROOTOPTPKG)/tests/functional/nopwrite
+
+PROGS = cleanup \
+	nopwrite.shlib \
+	nopwrite_copies \
+	nopwrite_mtime \
+	nopwrite_negative \
+	nopwrite_promoted_clone \
+	nopwrite_recsize \
+	nopwrite_sync \
+	nopwrite_varying_compression \
+	nopwrite_volume \
+	setup
+
+CMDS = $(PROGS:%=$(TESTDIR)/%)
+$(CMDS) := FILEMODE = 0555
+
+all lint clean clobber:
+
+install: $(CMDS)
+
+$(CMDS): $(TESTDIR)
+
+$(TESTDIR):
+	$(INS.dir)
+
+$(TESTDIR)/%.shlib: %.shlib
+	$(INS.file)
+
+$(TESTDIR)/%: %.ksh
+	$(INS.rename)
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/usr/src/test/zfs-tests/tests/functional/nopwrite/cleanup.ksh	Wed Dec 05 22:04:50 2012 -0500
@@ -0,0 +1,20 @@
+#!/usr/bin/ksh
+
+#
+# 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) 2012 by Delphix. All rights reserved.
+#
+
+. ${STF_SUITE}/include/libtest.shlib
+
+default_cleanup
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/usr/src/test/zfs-tests/tests/functional/nopwrite/nopwrite.shlib	Wed Dec 05 22:04:50 2012 -0500
@@ -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) 2012 by Delphix. All rights reserved.
+#
+
+. $STF_SUITE/include/math.shlib
+
+export TESTVOL="testvol.nopwrite"
+export VOLSIZE="256M"
+export MEGS="64"
+
+function verify_nopwrite
+{
+	typeset origin=$1
+	typeset snap=$2
+	typeset clone=$3
+	typeset low=1
+	typeset high=99
+
+	$SYNC
+	for i in origin snap clone; do
+		for j in used refer usedbychildren written; do
+			typeset ${i}_$j=$(get_prop $j $(eval echo \$$i))
+		done
+	done
+
+	#
+	# If we are dealing with a volume, deduct the refreserv from the used
+	# value to prevent real failures from being masked by the unexpected
+	# extra space. Also, volumes use more space for metadata, so adjust the
+	# percentages to be more forgiving.
+	#
+	if [[ "$(get_prop type $origin)" = "volume" ]]; then
+		typeset rr=$(get_prop refreserv $origin)
+		((origin_used -= rr ))
+		low=2
+		high=98
+	fi
+
+	# These values should differ greatly with nopwrite.
+	within_percent $origin_used $clone_used $low && return 1
+	within_percent $origin_refer $origin_usedbychildren $low && return 1
+	within_percent $snap_written $clone_written $low && return 1
+
+	# These values should be nearly the same with nopwrite.
+	within_percent $origin_used $clone_refer $high || return 1
+	within_percent $origin_used $snap_refer $high || return 1
+
+	#
+	# The comparisons below should pass regardless of nopwrite. They're
+	# here for sanity.
+	#
+	typeset deadlist=$($ZDB -Pddd $clone | $AWK '/Deadlist:/ {print $2}')
+	within_percent $deadlist $clone_written $high || return 1
+	within_percent $snap_refer $snap_written $high || return 1
+
+	return 0
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/usr/src/test/zfs-tests/tests/functional/nopwrite/nopwrite_copies.ksh	Wed Dec 05 22:04:50 2012 -0500
@@ -0,0 +1,71 @@
+#!/usr/bin/ksh
+
+#
+# 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) 2012 by Delphix. All rights reserved.
+#
+
+. $STF_SUITE/include/libtest.shlib
+. $STF_SUITE/tests/functional/nopwrite/nopwrite.shlib
+
+#
+# Description:
+# Verify that nopwrite is not enabled if the copies property changes
+#
+# Strategy:
+# 1. Create a clone with copies set higher than the origin fs
+# 2. Verify that nopwrite is in use.
+# 3. Repeat with the number of copies decreased.
+#
+
+verify_runnable "global"
+origin="$TESTPOOL/$TESTFS"
+log_onexit cleanup
+
+function cleanup
+{
+	datasetexists $origin && log_must $ZFS destroy -R $origin
+	log_must $ZFS create -o mountpoint=$TESTDIR $origin
+}
+
+log_assert "nopwrite requires copies property to remain constant"
+
+# Verify nopwrite is disabled with increased redundancy
+log_must $ZFS set compress=on $origin
+log_must $ZFS set checksum=sha256 $origin
+$DD if=/dev/urandom of=$TESTDIR/file bs=1024k count=$MEGS conv=notrunc \
+    >/dev/null 2>&1 || log_fail "dd into $TESTDIR/file failed."
+$ZFS snapshot $origin@a || log_fail "zfs snap failed"
+log_must $ZFS clone $origin@a $origin/clone
+$ZFS set copies=3 $origin/clone
+$DD if=/$TESTDIR/file of=/$TESTDIR/clone/file bs=1024k count=$MEGS \
+    conv=notrunc >/dev/null 2>&1 || log_fail "dd failed."
+log_mustnot verify_nopwrite $origin $origin@a $origin/clone
+
+# Verify nopwrite is disabled with decreased redundancy
+$ZFS destroy -R $origin || log_fail "Couldn't destroy $origin"
+$ZFS create -o mountpoint=$TESTDIR $origin || \
+    log_fail "Couldn't recreate $origin"
+log_must $ZFS set compress=on $origin
+log_must $ZFS set copies=3 $origin
+log_must $ZFS set checksum=sha256 $origin
+$DD if=/dev/urandom of=$TESTDIR/file bs=1024k count=$MEGS conv=notrunc \
+    >/dev/null 2>&1 || log_fail "dd into $TESTDIR/file failed."
+$ZFS snapshot $origin@a || log_fail "zfs snap failed"
+log_must $ZFS clone $origin@a $origin/clone
+$ZFS set copies=1 $origin/clone
+$DD if=/$TESTDIR/file of=/$TESTDIR/clone/file bs=1024k count=$MEGS \
+    conv=notrunc >/dev/null 2>&1 || log_fail "dd failed."
+log_mustnot verify_nopwrite $origin $origin@a $origin/clone
+
+log_pass "nopwrite requires copies property to remain constant"
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/usr/src/test/zfs-tests/tests/functional/nopwrite/nopwrite_mtime.ksh	Wed Dec 05 22:04:50 2012 -0500
@@ -0,0 +1,65 @@
+#!/usr/bin/ksh
+
+#
+# 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) 2012 by Delphix. All rights reserved.
+#
+
+. $STF_SUITE/include/libtest.shlib
+. $STF_SUITE/tests/functional/nopwrite/nopwrite.shlib
+
+#
+# Description:
+# Verify that nopwrite still updates file metadata correctly
+#
+# Strategy:
+# 1. Create a clone with nopwrite enabled.
+# 2. Write to the file in that clone and verify the mtime and ctime change,
+# but the atime does not.
+#
+
+verify_runnable "global"
+origin="$TESTPOOL/$TESTFS"
+log_onexit cleanup
+
+function cleanup
+{
+	datasetexists $origin && log_must $ZFS destroy -R $origin
+	log_must $ZFS create -o mountpoint=$TESTDIR $origin
+}
+
+log_assert "nopwrite updates file metadata correctly"
+
+log_must $ZFS set compress=on $origin
+log_must $ZFS set checksum=sha256 $origin
+$DD if=/dev/urandom of=$TESTDIR/file bs=1024k count=$MEGS conv=notrunc \
+    >/dev/null 2>&1 || log_fail "dd into $TESTDIR/file failed."
+$ZFS snapshot $origin@a || log_fail "zfs snap failed"
+log_must $ZFS clone $origin@a $origin/clone
+
+o_atime=$($LS -E% all $TESTDIR/clone/file | $AWK '/atime/ {print $4}')
+o_ctime=$($LS -E% all $TESTDIR/clone/file | $AWK '/ctime/ {print $4}')
+o_mtime=$($LS -E% all $TESTDIR/clone/file | $AWK '/mtime/ {print $4}')
+$DD if=/$TESTDIR/file of=/$TESTDIR/clone/file bs=1024k count=$MEGS \
+    conv=notrunc >/dev/null 2>&1 || log_fail "dd failed."
+atime=$($LS -E% all $TESTDIR/clone/file | $AWK '/atime/ {print $4}')
+ctime=$($LS -E% all $TESTDIR/clone/file | $AWK '/ctime/ {print $4}')
+mtime=$($LS -E% all $TESTDIR/clone/file | $AWK '/mtime/ {print $4}')
+
+[[ $o_atime = $atime ]] || log_fail "atime changed: $o_atime $atime"
+[[ $o_ctime = $ctime ]] && log_fail "ctime unchanged: $o_ctime $ctime"
+[[ $o_mtime = $mtime ]] && log_fail "mtime unchanged: $o_mtime $mtime"
+
+log_must verify_nopwrite $origin $origin@a $origin/clone
+
+log_pass "nopwrite updates file metadata correctly"
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/usr/src/test/zfs-tests/tests/functional/nopwrite/nopwrite_negative.ksh	Wed Dec 05 22:04:50 2012 -0500
@@ -0,0 +1,90 @@
+#!/usr/bin/ksh
+
+#
+# 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) 2012 by Delphix. All rights reserved.
+#
+
+. $STF_SUITE/include/libtest.shlib
+. $STF_SUITE/tests/functional/nopwrite/nopwrite.shlib
+
+#
+# Description:
+# Verify that duplicate writes to a clone are accounted as new data if the
+# prerequisites for nopwrite are not met.
+#
+# Scenarios:
+# 1. The file in the origin ds is written without compression or sha256.
+# 2. The file in the origin ds is written before sha256 checksum is turned on.
+# 3. The clone does not have compression.
+# 4. The clone does not have the appropriate checksum.
+#
+
+verify_runnable "global"
+origin="$TESTPOOL/$TESTFS"
+log_onexit cleanup
+
+function cleanup
+{
+	datasetexists $origin && log_must $ZFS destroy -R $origin
+	log_must $ZFS create -o mountpoint=$TESTDIR $origin
+}
+
+log_assert "nopwrite isn't enabled without the prerequisites"
+
+# Data written into origin fs without compression or sha256
+$DD if=/dev/urandom of=$TESTDIR/file bs=1024k count=$MEGS conv=notrunc \
+    >/dev/null 2>&1 || log_fail "dd of $TESTDIR/file failed."
+$ZFS snapshot $origin@a || log_fail "zfs snap failed"
+log_must $ZFS clone -o compress=on $origin@a $origin/clone
+log_must $ZFS set checksum=sha256 $origin/clone
+$DD if=/$TESTDIR/file of=/$TESTDIR/clone/file bs=1024k count=$MEGS \
+    conv=notrunc >/dev/null 2>&1 || log_fail "dd failed."
+log_mustnot verify_nopwrite $origin $origin@a $origin/clone
+$ZFS destroy -R $origin@a || log_fail "zfs destroy failed"
+log_must $RM -f $TESTDIR/file
+
+# Data written to origin fs before checksum enabled
+log_must $ZFS set compress=on $origin
+$DD if=/dev/urandom of=$TESTDIR/file bs=1024k count=$MEGS conv=notrunc \
+    >/dev/null 2>&1 || log_fail "dd into $TESTDIR/file failed."
+log_must $ZFS set checksum=sha256 $origin
+$ZFS snapshot $origin@a || log_fail "zfs snap failed"
+log_must $ZFS clone $origin@a $origin/clone
+$DD if=/$TESTDIR/file of=/$TESTDIR/clone/file bs=1024k count=$MEGS \
+    conv=notrunc >/dev/null 2>&1 || log_fail "dd failed."
+log_mustnot verify_nopwrite $origin $origin@a $origin/clone
+$ZFS destroy -R $origin@a || log_fail "zfs destroy failed"
+log_must $RM -f $TESTDIR/file
+
+# Clone with compression=off
+$DD if=/dev/urandom of=$TESTDIR/file bs=1024k count=$MEGS conv=notrunc \
+    >/dev/null 2>&1 || log_fail "dd into $TESTDIR/file failed."
+$ZFS snapshot $origin@a || log_fail "zfs snap failed"
+log_must $ZFS clone -o compress=off $origin@a $origin/clone
+$DD if=/$TESTDIR/file of=/$TESTDIR/clone/file bs=1024k count=$MEGS \
+    conv=notrunc >/dev/null 2>&1 || log_fail "dd failed."
+log_mustnot verify_nopwrite $origin $origin@a $origin/clone
+$ZFS destroy -R $origin@a || log_fail "zfs destroy failed"
+log_must $RM -f $TESTDIR/file
+
+# Clone with fletcher4, rather than sha256
+$DD if=/dev/urandom of=$TESTDIR/file bs=1024k count=$MEGS conv=notrunc \
+    >/dev/null 2>&1 || log_fail "dd into $TESTDIR/file failed."
+$ZFS snapshot $origin@a || log_fail "zfs snap failed"
+log_must $ZFS clone -o checksum=fletcher4 $origin@a $origin/clone
+$DD if=/$TESTDIR/file of=/$TESTDIR/clone/file bs=1024k count=$MEGS \
+    conv=notrunc >/dev/null 2>&1 || log_fail "dd failed."
+log_mustnot verify_nopwrite $origin $origin@a $origin/clone
+
+log_pass "nopwrite isn't enabled without the prerequisites"
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/usr/src/test/zfs-tests/tests/functional/nopwrite/nopwrite_promoted_clone.ksh	Wed Dec 05 22:04:50 2012 -0500
@@ -0,0 +1,58 @@
+#!/usr/bin/ksh
+
+#
+# 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) 2012 by Delphix. All rights reserved.
+#
+
+. $STF_SUITE/include/libtest.shlib
+. $STF_SUITE/tests/functional/nopwrite/nopwrite.shlib
+
+#
+# Description:
+# Verify that nopwrite still works for a dataset that becomes a clone via
+# promotion.
+#
+# Strategy:
+# 1. Create a clone suitable for nopwrite.
+# 2. Disable compression and checksum on the clone, and promote it.
+# 3. Overwrite the file in the clone (former origin fs) and verify it
+# consumes no additional space.
+#
+
+verify_runnable "global"
+origin="$TESTPOOL/$TESTFS"
+log_onexit cleanup
+
+function cleanup
+{
+	datasetexists $origin && log_must $ZFS destroy -R $TESTPOOL/clone
+	log_must $ZFS create -o mountpoint=$TESTDIR $origin
+}
+
+log_assert "nopwrite works on a dataset that becomes a clone via promotion."
+
+log_must $ZFS set compress=on $origin
+log_must $ZFS set checksum=sha256 $origin
+$DD if=/dev/urandom of=$TESTDIR/file bs=1024k count=$MEGS conv=notrunc \
+    >/dev/null 2>&1 || log_fail "dd into $TESTDIR/file failed."
+$ZFS snapshot $origin@a || log_fail "zfs snap failed"
+log_must $ZFS clone $origin@a $TESTPOOL/clone
+log_must $ZFS set compress=off $TESTPOOL/clone
+log_must $ZFS set checksum=off $TESTPOOL/clone
+log_must $ZFS promote $TESTPOOL/clone
+$DD if=/$TESTPOOL/clone/file of=/$TESTDIR/file bs=1024k count=$MEGS \
+    conv=notrunc >/dev/null 2>&1 || log_fail "dd failed."
+log_must verify_nopwrite $TESTPOOL/clone $TESTPOOL/clone@a $origin
+
+log_pass "nopwrite works on a dataset that becomes a clone via promotion."
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/usr/src/test/zfs-tests/tests/functional/nopwrite/nopwrite_recsize.ksh	Wed Dec 05 22:04:50 2012 -0500
@@ -0,0 +1,57 @@
+#!/usr/bin/ksh
+
+#
+# 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) 2012 by Delphix. All rights reserved.
+#
+
+. $STF_SUITE/include/libtest.shlib
+. $STF_SUITE/tests/functional/nopwrite/nopwrite.shlib
+
+#
+# Description:
+# Verify that nopwrite works regardless of recsize property setting.
+#
+# Strategy:
+# 1. Create an origin fs that's suitable to make nopwrite clones.
+# 2. For each possible recsize, create a clone that inherits the compress and
+# checksum, and verify overwriting the origin file consumes no new space.
+#
+
+verify_runnable "global"
+origin="$TESTPOOL/$TESTFS"
+log_onexit cleanup
+
+function cleanup
+{
+	datasetexists $origin && log_must $ZFS destroy -R $origin
+	log_must $ZFS create -o mountpoint=$TESTDIR $origin
+}
+
+log_assert "nopwrite updates file metadata correctly"
+
+log_must $ZFS set compress=on $origin
+log_must $ZFS set checksum=sha256 $origin
+$DD if=/dev/urandom of=$TESTDIR/file bs=1024k count=$MEGS conv=notrunc \
+    >/dev/null 2>&1 || log_fail "dd into $TESTDIR/file failed."
+$ZFS snapshot $origin@a || log_fail "zfs snap failed"
+log_must $ZFS clone $origin@a $origin/clone
+
+for rs in 512 1024 2048 4096 8192 16384 32768 65536 131072 ; do
+	log_must $ZFS set recsize=$rs $origin/clone
+	$DD if=/$TESTDIR/file of=/$TESTDIR/clone/file bs=1024k count=$MEGS \
+	    conv=notrunc >/tmp/null 2>&1 || log_fail "dd failed."
+	log_must verify_nopwrite $origin $origin@a $origin/clone
+done
+
+log_pass "nopwrite updates file metadata correctly"
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/usr/src/test/zfs-tests/tests/functional/nopwrite/nopwrite_sync.ksh	Wed Dec 05 22:04:50 2012 -0500
@@ -0,0 +1,55 @@
+#!/usr/bin/ksh
+
+#
+# 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) 2012 by Delphix. All rights reserved.
+#
+
+. $STF_SUITE/include/libtest.shlib
+. $STF_SUITE/tests/functional/nopwrite/nopwrite.shlib
+
+#
+# Description:
+# Verify that nopwrite works for sync writes
+#
+# Strategy:
+# 1. Create an origin fs with compression and sha256.
+# 2. Clone origin such that it inherits the properies.
+# 3. Use dd with the sync flag to test the sync write path.
+#
+
+verify_runnable "global"
+origin="$TESTPOOL/$TESTFS"
+log_onexit cleanup
+
+function cleanup
+{
+	datasetexists $origin && log_must $ZFS destroy -R $origin
+	log_must $ZFS create -o mountpoint=$TESTDIR $origin
+}
+
+log_assert "nopwrite works for sync writes"
+
+log_must $ZFS set compress=on $origin
+log_must $ZFS set checksum=sha256 $origin
+$GNUDD if=/dev/urandom of=$TESTDIR/file bs=1024k count=$MEGS oflag=sync \
+    conv=notrunc >/dev/null 2>&1 || log_fail "dd into $TESTDIR/file failed."
+$ZFS snapshot $origin@a || log_fail "zfs snap failed"
+log_must $ZFS clone $origin@a $origin/clone
+
+$GNUDD if=/$TESTDIR/file of=/$TESTDIR/clone/file bs=1024k count=$MEGS \
+    oflag=sync conv=notrunc >/dev/null 2>&1 || log_fail "dd failed."
+
+log_must verify_nopwrite $origin $origin@a $origin/clone
+
+log_pass "nopwrite works for sync writes"
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/usr/src/test/zfs-tests/tests/functional/nopwrite/nopwrite_varying_compression.ksh	Wed Dec 05 22:04:50 2012 -0500
@@ -0,0 +1,64 @@
+#!/usr/bin/ksh
+
+#
+# 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) 2012 by Delphix. All rights reserved.
+#
+
+. $STF_SUITE/include/libtest.shlib
+. $STF_SUITE/include/properties.shlib
+. $STF_SUITE/tests/functional/nopwrite/nopwrite.shlib
+
+#
+# Description:
+# Verify that if the checksum on the origin and clone is sha256, any compression
+# algorithm enables nopwrite.
+#
+# Strategy:
+# 1. Create an origin dataset with compression and sha256 checksum.
+# 2. Write a 64M file into the origin dataset.
+# 3. For each of 4 randomly chosen compression types:
+# 3a. Create a snap and clone (inheriting the checksum property) of the origin.
+# 3b. Apply the compression property to the clone.
+# 3c. Write the same 64M of data into the file that exists in the clone.
+# 3d. Verify that no new space was consumed.
+#
+
+verify_runnable "global"
+origin="$TESTPOOL/$TESTFS"
+log_onexit cleanup
+
+function cleanup
+{
+	datasetexists $origin && log_must $ZFS destroy -R $origin
+	log_must $ZFS create -o mountpoint=$TESTDIR $origin
+}
+
+log_assert "nopwrite works with sha256 and any compression algorithm"
+
+log_must $ZFS set compress=on $origin
+log_must $ZFS set checksum=sha256 $origin
+$DD if=/dev/urandom of=$TESTDIR/file bs=1024k count=$MEGS conv=notrunc \
+    >/dev/null 2>&1 || log_fail "initial dd failed."
+
+# Verify nop_write for 4 random compression algorithms
+for i in $(get_rand_compress 4); do
+	$ZFS snapshot $origin@a || log_fail "zfs snap failed"
+	log_must $ZFS clone -o compress=$i $origin@a $origin/clone
+	$DD if=/$TESTDIR/file of=/$TESTDIR/clone/file bs=1024k count=$MEGS \
+	    conv=notrunc >/dev/null 2>&1 || log_fail "dd failed."
+	log_must verify_nopwrite $origin $origin@a $origin/clone
+	$ZFS destroy -R $origin@a || log_fail "zfs destroy failed"
+done
+
+log_pass "nopwrite works with sha256 and any compression algorithm"
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/usr/src/test/zfs-tests/tests/functional/nopwrite/nopwrite_volume.ksh	Wed Dec 05 22:04:50 2012 -0500
@@ -0,0 +1,58 @@
+#!/usr/bin/ksh
+
+#
+# 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) 2012 by Delphix. All rights reserved.
+#
+
+. $STF_SUITE/include/libtest.shlib
+. $STF_SUITE/tests/functional/nopwrite/nopwrite.shlib
+
+#
+# Description:
+# Verify that nopwrite cannot be enabled on volumes
+#
+# Strategy:
+# 1. Create a clone of a volume that fits the criteria for nopwrite.
+# 2. Overwrite the same blocks from the origin vol and verify that
+# new space is consumed.
+#
+
+verify_runnable "global"
+origin="$TESTPOOL/$TESTVOL"
+clone="$TESTPOOL/clone"
+vol="/dev/zvol/rdsk/$origin"
+volclone="/dev/zvol/rdsk/$clone"
+log_onexit cleanup
+
+function cleanup
+{
+	datasetexists $origin && log_must $ZFS destroy -R $origin
+	# No need to recreate the volume as no other tests expect it.
+}
+
+log_assert "nopwrite works on volumes"
+
+log_must $ZFS set compress=on $origin
+log_must $ZFS set checksum=sha256 $origin
+$DD if=/dev/urandom of=$vol bs=8192 count=4096 conv=notrunc >/dev/null \
+    2>&1 || log_fail "dd into $orgin failed."
+$ZFS snapshot $origin@a || log_fail "zfs snap failed"
+log_must $ZFS clone $origin@a $clone
+log_must $ZFS set compress=on $clone
+log_must $ZFS set checksum=sha256 $clone
+$DD if=$vol of=$volclone bs=8192 count=4096 conv=notrunc >/dev/null 2>&1 || \
+    log_fail "dd into $clone failed."
+log_must verify_nopwrite $origin $origin@a $clone
+
+log_pass "nopwrite works on volumes"
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/usr/src/test/zfs-tests/tests/functional/nopwrite/setup.ksh	Wed Dec 05 22:04:50 2012 -0500
@@ -0,0 +1,23 @@
+#!/usr/bin/ksh
+
+#
+# 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) 2012 by Delphix. All rights reserved.
+#
+
+. ${STF_SUITE}/include/libtest.shlib
+. ${STF_SUITE}/tests/functional/nopwrite/nopwrite.shlib
+
+disk=${DISKS%% *}
+
+default_volume_setup $disk
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/usr/src/test/zfs-tests/tests/functional/truncate/Makefile	Wed Dec 05 22:04:50 2012 -0500
@@ -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) 2012 by Delphix. All rights reserved.
+#
+
+include $(SRC)/Makefile.master
+
+ROOTOPTPKG = $(ROOT)/opt/zfs-tests
+TESTDIR = $(ROOTOPTPKG)/tests/functional/truncate
+
+PROGS = cleanup \
+	setup \
+	truncate.cfg \
+	truncate_001_pos \
+	truncate_002_pos
+
+CMDS = $(PROGS:%=$(TESTDIR)/%)
+$(CMDS) := FILEMODE = 0555
+
+all lint clean clobber:
+
+install: $(CMDS)
+
+$(CMDS): $(TESTDIR)
+
+$(TESTDIR):
+	$(INS.dir)
+
+$(TESTDIR)/%.cfg: %.cfg
+	$(INS.file)
+
+$(TESTDIR)/%: %.ksh
+	$(INS.rename)
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/usr/src/test/zfs-tests/tests/functional/truncate/cleanup.ksh	Wed Dec 05 22:04:50 2012 -0500
@@ -0,0 +1,30 @@
+#!/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.
+#
+
+. ${STF_SUITE}/include/libtest.shlib
+
+default_cleanup
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/usr/src/test/zfs-tests/tests/functional/truncate/setup.ksh	Wed Dec 05 22:04:50 2012 -0500
@@ -0,0 +1,32 @@
+#!/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.
+#
+
+. ${STF_SUITE}/include/libtest.shlib
+
+disk=${DISKS%% *}
+
+default_setup $disk
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/usr/src/test/zfs-tests/tests/functional/truncate/truncate.cfg	Wed Dec 05 22:04:50 2012 -0500
@@ -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.
+#
+
+export TESTFILE=testfile.$$
+export TRUNC_FILESIZE=${TRUNC_FILESIZE-"67108864"} # 64 Mb
+export TRUNC_BLKSIZE=${TRUNC_BLKSIZE-"512"}
+export TRUNC_SEED=${TRUNC_SEED-""}
+export TRUNC_FILEOFFSET=${TRUNC_FILEOFFSET-""}
+export TRUNC_COUNT=${TRUNC_COUNT-"16384"}	   # FILESIZE/BLKSIZE/8
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/usr/src/test/zfs-tests/tests/functional/truncate/truncate_001_pos.ksh	Wed Dec 05 22:04:50 2012 -0500
@@ -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.
+#
+
+. $STF_SUITE/tests/functional/truncate/truncate.cfg
+. $STF_SUITE/include/libtest.shlib
+
+#
+# DESCRIPTION:
+# Tests file truncation within ZFS.
+#
+# STRATEGY:
+# 1. Open file
+# 2. Write random blocks in random places
+# 3. Truncate the file
+# 4. Repeat steps 2 and 3 lots of times
+# 5. Close the file.
+#
+
+verify_runnable "global"
+
+function cleanup
+{
+	[[ -e $TESTDIR ]] && log_must $RM -rf $TESTDIR/*
+}
+
+log_assert "Ensure file with random blocks is truncated properly"
+
+options=""
+options_display="default options"
+
+log_onexit cleanup
+
+[[ -n "$TRUNC_FILESIZE" ]] && options=" $options -f $TRUNC_FILESIZE "
+
+[[ -n "$TRUNC_BLKSIZE" ]] && options="$options -b $TRUNC_BLKSIZE "
+
+[[ -n "$TRUNC_COUNT" ]] && options="$options -c $TRUNC_COUNT "
+
+[[ -n "$TRUNC_SEED" ]] && options="$options -s $TRUNC_SEED "
+
+[[ -n "$TRUNC_FILEOFFSET" ]] && options="$options -o $TRUNC_FILEOFFSET "
+
+[[ -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 truncated properly."
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/usr/src/test/zfs-tests/tests/functional/truncate/truncate_002_pos.ksh	Wed Dec 05 22:04:50 2012 -0500
@@ -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.
+#
+
+. $STF_SUITE/tests/functional/truncate/truncate.cfg
+. $STF_SUITE/include/libtest.shlib
+
+#
+# DESCRIPTION:
+# Tests file truncation within ZFS while a sync operation is in progress.
+#
+# STRATEGY:
+# 1. Copy a file to ZFS filesystem
+# 2. Copy /dev/null to same file on ZFS filesystem
+# 3. Execute a sync command
+#
+
+verify_runnable "both"
+
+function cleanup
+{
+	[[ -e $TESTDIR ]] && log_must $RM -rf $TESTDIR/*
+	[[ -f $srcfile ]] && $RM -f $srcfile
+}
+
+log_assert "Ensure zeroed file gets written correctly during a sync operation"
+
+srcfile="/tmp/cosmo.$$"
+log_must $DD if=/dev/urandom of=$srcfile bs=1024k count=1
+
+log_onexit cleanup
+log_must $CP $srcfile $TESTDIR/$TESTFILE
+log_must $CP /dev/null $TESTDIR/$TESTFILE
+log_must $SYNC
+if [[ -s $TESTDIR/$TESTFILE ]]; then
+	log_note "$($LS -l $TESTDIR/$TESTFILE)"
+	log_fail "testfile not truncated"
+fi
+
+log_pass "Successful truncation while a sync operation is in progress."
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/usr/src/test/zfs-tests/tests/stress/Makefile	Wed Dec 05 22:04:50 2012 -0500
@@ -0,0 +1,20 @@
+#
+# 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) 2012 by Delphix. All rights reserved.
+#
+
+.PARALLEL: $(SUBDIRS)
+
+SUBDIRS =
+
+include $(SRC)/test/Makefile.com