]> git.proxmox.com Git - mirror_zfs.git/commitdiff
Add the ZFS Test Suite
authorBrian Behlendorf <behlendorf1@llnl.gov>
Wed, 1 Jul 2015 22:23:09 +0000 (15:23 -0700)
committerBrian Behlendorf <behlendorf1@llnl.gov>
Wed, 16 Mar 2016 20:46:16 +0000 (13:46 -0700)
Add the ZFS Test Suite and test-runner framework from illumos.
This is a continuation of the work done by Turbo Fredriksson to
port the ZFS Test Suite to Linux.  While this work was originally
conceived as a stand alone project integrating it directly with
the ZoL source tree has several advantages:

  * Allows the ZFS Test Suite to be packaged in zfs-test package.
    * Facilitates easy integration with the CI testing.
    * Users can locally run the ZFS Test Suite to validate ZFS.
      This testing should ONLY be done on a dedicated test system
      because the ZFS Test Suite in its current form is destructive.
  * Allows the ZFS Test Suite to be run directly in the ZoL source
    tree enabled developers to iterate quickly during development.
  * Developers can easily add/modify tests in the framework as
    features are added or functionality is changed.  The tests
    will then always be in sync with the implementation.

Full documentation for how to run the ZFS Test Suite is available
in the tests/README.md file.

Warning: This test suite is designed to be run on a dedicated test
system.  It will make modifications to the system including, but
not limited to, the following.

  * Adding new users
  * Adding new groups
  * Modifying the following /proc files:
    * /proc/sys/kernel/core_pattern
    * /proc/sys/kernel/core_uses_pid
  * Creating directories under /

Notes:
  * Not all of the test cases are expected to pass and by default
    these test cases are disabled.  The failures are primarily due
    to assumption made for illumos which are invalid under Linux.
  * When updating these test cases it should be done in as generic
    a way as possible so the patch can be submitted back upstream.
    Most existing library functions have been updated to be Linux
    aware, and the following functions and variables have been added.
    * Functions:
      * is_linux          - Used to wrap a Linux specific section.
      * block_device_wait - Waits for block devices to be added to /dev/.
    * Variables:            Linux          Illumos
      * ZVOL_DEVDIR         "/dev/zvol"    "/dev/zvol/dsk"
      * ZVOL_RDEVDIR        "/dev/zvol"    "/dev/zvol/rdsk"
      * DEV_DSKDIR          "/dev"         "/dev/dsk"
      * DEV_RDSKDIR         "/dev"         "/dev/rdsk"
      * NEWFS_DEFAULT_FS    "ext2"         "ufs"
  * Many of the disabled test cases fail because 'zfs/zpool destroy'
    returns EBUSY.  This is largely causes by the asynchronous nature
    of device handling on Linux and is expected, the impacted test
    cases will need to be updated to handle this.
  * There are several test cases which have been disabled because
    they can trigger a deadlock.  A primary example of this is to
    recursively create zpools within zpools.  These tests have been
    disabled until the root issue can be addressed.
  * Illumos specific utilities such as (mkfile) should be added to
    the tests/zfs-tests/cmd/ directory.  Custom programs required by
    the test scripts can also be added here.
  * SELinux should be either is permissive mode or disabled when
    running the tests.  The test cases should be updated to conform
    to a standard policy.
  * Redundant test functionality has been removed (zfault.sh).
  * Existing test scripts (zconfig.sh) should be migrated to use
    the framework for consistency and ease of testing.
  * The DISKS environment variable currently only supports loopback
    devices because of how the ZFS Test Suite expects partitions to
    be named (p1, p2, etc).  Support must be added to generate the
    correct partition name based on the device location and name.
  * The ZFS Test Suite is part of the illumos code base at:
    https://github.com/illumos/illumos-gate/tree/master/usr/src/test

Original-patch-by: Turbo Fredriksson <turbo@bayour.com>
Signed-off-by: Brian Behlendorf <behlendorf1@llnl.gov>
Signed-off-by: Olaf Faaland <faaland1@llnl.gov>
Closes #6
Closes #1534

1243 files changed:
Makefile.am
TEST
config/user-commands.m4 [new file with mode: 0644]
config/user-libattr.m4 [new file with mode: 0644]
config/user.m4
config/zfs-build.m4
configure.ac
include/libzfs.h
lib/libzfs/libzfs_util.c
rpm/generic/zfs.spec.in
scripts/Makefile.am
scripts/common.sh.in
scripts/zfault.sh [deleted file]
scripts/zfs-tests.sh [new file with mode: 0755]
tests/Makefile.am [new file with mode: 0644]
tests/README.md [new file with mode: 0644]
tests/runfiles/Makefile.am [new file with mode: 0644]
tests/runfiles/linux.run [new file with mode: 0644]
tests/test-runner/Makefile.am [new file with mode: 0644]
tests/test-runner/cmd/Makefile.am [new file with mode: 0644]
tests/test-runner/cmd/test-runner.py [new file with mode: 0755]
tests/test-runner/include/Makefile.am [new file with mode: 0644]
tests/test-runner/include/logapi.shlib [new file with mode: 0644]
tests/test-runner/include/stf.shlib [new file with mode: 0644]
tests/test-runner/man/Makefile.am [new file with mode: 0644]
tests/test-runner/man/test-runner.1 [new file with mode: 0644]
tests/zfs-tests/Makefile.am [new file with mode: 0644]
tests/zfs-tests/cmd/Makefile.am [new file with mode: 0644]
tests/zfs-tests/cmd/chg_usr_exec/.gitignore [new file with mode: 0644]
tests/zfs-tests/cmd/chg_usr_exec/Makefile.am [new file with mode: 0644]
tests/zfs-tests/cmd/chg_usr_exec/chg_usr_exec.c [new file with mode: 0644]
tests/zfs-tests/cmd/devname2devid/.gitignore [new file with mode: 0644]
tests/zfs-tests/cmd/devname2devid/Makefile.am [new file with mode: 0644]
tests/zfs-tests/cmd/devname2devid/devname2devid.c [new file with mode: 0644]
tests/zfs-tests/cmd/dir_rd_update/.gitignore [new file with mode: 0644]
tests/zfs-tests/cmd/dir_rd_update/Makefile.am [new file with mode: 0644]
tests/zfs-tests/cmd/dir_rd_update/dir_rd_update.c [new file with mode: 0644]
tests/zfs-tests/cmd/file_check/.gitignore [new file with mode: 0644]
tests/zfs-tests/cmd/file_check/Makefile.am [new file with mode: 0644]
tests/zfs-tests/cmd/file_check/file_check.c [new file with mode: 0644]
tests/zfs-tests/cmd/file_common.h [new file with mode: 0644]
tests/zfs-tests/cmd/file_trunc/.gitignore [new file with mode: 0644]
tests/zfs-tests/cmd/file_trunc/Makefile.am [new file with mode: 0644]
tests/zfs-tests/cmd/file_trunc/file_trunc.c [new file with mode: 0644]
tests/zfs-tests/cmd/file_write/.gitignore [new file with mode: 0644]
tests/zfs-tests/cmd/file_write/Makefile.am [new file with mode: 0644]
tests/zfs-tests/cmd/file_write/file_write.c [new file with mode: 0644]
tests/zfs-tests/cmd/largest_file/.gitignore [new file with mode: 0644]
tests/zfs-tests/cmd/largest_file/Makefile.am [new file with mode: 0644]
tests/zfs-tests/cmd/largest_file/largest_file.c [new file with mode: 0644]
tests/zfs-tests/cmd/mkbusy/.gitignore [new file with mode: 0644]
tests/zfs-tests/cmd/mkbusy/Makefile.am [new file with mode: 0644]
tests/zfs-tests/cmd/mkbusy/mkbusy.c [new file with mode: 0644]
tests/zfs-tests/cmd/mkfile/.gitignore [new file with mode: 0644]
tests/zfs-tests/cmd/mkfile/Makefile.am [new file with mode: 0644]
tests/zfs-tests/cmd/mkfile/mkfile.c [new file with mode: 0644]
tests/zfs-tests/cmd/mkfiles/.gitignore [new file with mode: 0644]
tests/zfs-tests/cmd/mkfiles/Makefile.am [new file with mode: 0644]
tests/zfs-tests/cmd/mkfiles/mkfiles.c [new file with mode: 0644]
tests/zfs-tests/cmd/mktree/.gitignore [new file with mode: 0644]
tests/zfs-tests/cmd/mktree/Makefile.am [new file with mode: 0644]
tests/zfs-tests/cmd/mktree/mktree.c [new file with mode: 0644]
tests/zfs-tests/cmd/mmap_exec/.gitignore [new file with mode: 0644]
tests/zfs-tests/cmd/mmap_exec/Makefile.am [new file with mode: 0644]
tests/zfs-tests/cmd/mmap_exec/mmap_exec.c [new file with mode: 0644]
tests/zfs-tests/cmd/mmapwrite/.gitignore [new file with mode: 0644]
tests/zfs-tests/cmd/mmapwrite/Makefile.am [new file with mode: 0644]
tests/zfs-tests/cmd/mmapwrite/mmapwrite.c [new file with mode: 0644]
tests/zfs-tests/cmd/randfree_file/.gitignore [new file with mode: 0644]
tests/zfs-tests/cmd/randfree_file/Makefile.am [new file with mode: 0644]
tests/zfs-tests/cmd/randfree_file/randfree_file.c [new file with mode: 0644]
tests/zfs-tests/cmd/readmmap/.gitignore [new file with mode: 0644]
tests/zfs-tests/cmd/readmmap/Makefile.am [new file with mode: 0644]
tests/zfs-tests/cmd/readmmap/readmmap.c [new file with mode: 0644]
tests/zfs-tests/cmd/rename_dir/.gitignore [new file with mode: 0644]
tests/zfs-tests/cmd/rename_dir/Makefile.am [new file with mode: 0644]
tests/zfs-tests/cmd/rename_dir/rename_dir.c [new file with mode: 0644]
tests/zfs-tests/cmd/rm_lnkcnt_zero_file/.gitignore [new file with mode: 0644]
tests/zfs-tests/cmd/rm_lnkcnt_zero_file/Makefile.am [new file with mode: 0644]
tests/zfs-tests/cmd/rm_lnkcnt_zero_file/rm_lnkcnt_zero_file.c [new file with mode: 0644]
tests/zfs-tests/cmd/threadsappend/.gitignore [new file with mode: 0644]
tests/zfs-tests/cmd/threadsappend/Makefile.am [new file with mode: 0644]
tests/zfs-tests/cmd/threadsappend/threadsappend.c [new file with mode: 0644]
tests/zfs-tests/cmd/xattrtest/.gitignore [new file with mode: 0644]
tests/zfs-tests/cmd/xattrtest/Makefile.am [new file with mode: 0644]
tests/zfs-tests/cmd/xattrtest/xattrtest.c [new file with mode: 0644]
tests/zfs-tests/include/.gitignore [new file with mode: 0644]
tests/zfs-tests/include/Makefile.am [new file with mode: 0644]
tests/zfs-tests/include/commands.cfg.in [new file with mode: 0644]
tests/zfs-tests/include/default.cfg.in [new file with mode: 0644]
tests/zfs-tests/include/libtest.shlib [new file with mode: 0644]
tests/zfs-tests/include/math.shlib [new file with mode: 0644]
tests/zfs-tests/include/properties.shlib [new file with mode: 0644]
tests/zfs-tests/include/zfs_commands.cfg [new symlink]
tests/zfs-tests/tests/Makefile.am [new file with mode: 0644]
tests/zfs-tests/tests/functional/Makefile.am [new file with mode: 0644]
tests/zfs-tests/tests/functional/acl/Makefile.am [new file with mode: 0644]
tests/zfs-tests/tests/functional/acl/acl.cfg [new file with mode: 0644]
tests/zfs-tests/tests/functional/acl/acl_common.kshlib [new file with mode: 0644]
tests/zfs-tests/tests/functional/acl/posix/Makefile.am [new file with mode: 0644]
tests/zfs-tests/tests/functional/acl/posix/cleanup.ksh [new file with mode: 0755]
tests/zfs-tests/tests/functional/acl/posix/posix_001_pos.ksh [new file with mode: 0755]
tests/zfs-tests/tests/functional/acl/posix/posix_002_pos.ksh [new file with mode: 0755]
tests/zfs-tests/tests/functional/acl/posix/setup.ksh [new file with mode: 0755]
tests/zfs-tests/tests/functional/atime/Makefile.am [new file with mode: 0644]
tests/zfs-tests/tests/functional/atime/atime.cfg [new file with mode: 0644]
tests/zfs-tests/tests/functional/atime/atime_001_pos.ksh [new file with mode: 0755]
tests/zfs-tests/tests/functional/atime/atime_002_neg.ksh [new file with mode: 0755]
tests/zfs-tests/tests/functional/atime/atime_common.kshlib [new file with mode: 0644]
tests/zfs-tests/tests/functional/atime/cleanup.ksh [new file with mode: 0755]
tests/zfs-tests/tests/functional/atime/setup.ksh [new file with mode: 0755]
tests/zfs-tests/tests/functional/bootfs/Makefile.am [new file with mode: 0644]
tests/zfs-tests/tests/functional/bootfs/bootfs_001_pos.ksh [new file with mode: 0755]
tests/zfs-tests/tests/functional/bootfs/bootfs_002_neg.ksh [new file with mode: 0755]
tests/zfs-tests/tests/functional/bootfs/bootfs_003_pos.ksh [new file with mode: 0755]
tests/zfs-tests/tests/functional/bootfs/bootfs_004_neg.ksh [new file with mode: 0755]
tests/zfs-tests/tests/functional/bootfs/bootfs_005_neg.ksh [new file with mode: 0755]
tests/zfs-tests/tests/functional/bootfs/bootfs_006_pos.ksh [new file with mode: 0755]
tests/zfs-tests/tests/functional/bootfs/bootfs_007_neg.ksh [new file with mode: 0755]
tests/zfs-tests/tests/functional/bootfs/bootfs_007_pos.ksh [new file with mode: 0644]
tests/zfs-tests/tests/functional/bootfs/bootfs_008_neg.ksh [new file with mode: 0755]
tests/zfs-tests/tests/functional/bootfs/cleanup.ksh [new file with mode: 0755]
tests/zfs-tests/tests/functional/bootfs/setup.ksh [new file with mode: 0755]
tests/zfs-tests/tests/functional/cache/Makefile.am [new file with mode: 0644]
tests/zfs-tests/tests/functional/cache/cache.cfg [new file with mode: 0644]
tests/zfs-tests/tests/functional/cache/cache.kshlib [new file with mode: 0644]
tests/zfs-tests/tests/functional/cache/cache_001_pos.ksh [new file with mode: 0755]
tests/zfs-tests/tests/functional/cache/cache_002_pos.ksh [new file with mode: 0755]
tests/zfs-tests/tests/functional/cache/cache_003_pos.ksh [new file with mode: 0755]
tests/zfs-tests/tests/functional/cache/cache_004_neg.ksh [new file with mode: 0755]
tests/zfs-tests/tests/functional/cache/cache_005_neg.ksh [new file with mode: 0755]
tests/zfs-tests/tests/functional/cache/cache_006_pos.ksh [new file with mode: 0755]
tests/zfs-tests/tests/functional/cache/cache_007_neg.ksh [new file with mode: 0755]
tests/zfs-tests/tests/functional/cache/cache_008_neg.ksh [new file with mode: 0755]
tests/zfs-tests/tests/functional/cache/cache_009_pos.ksh [new file with mode: 0755]
tests/zfs-tests/tests/functional/cache/cache_010_neg.ksh [new file with mode: 0755]
tests/zfs-tests/tests/functional/cache/cache_011_pos.ksh [new file with mode: 0755]
tests/zfs-tests/tests/functional/cache/cleanup.ksh [new file with mode: 0755]
tests/zfs-tests/tests/functional/cache/setup.ksh [new file with mode: 0755]
tests/zfs-tests/tests/functional/cachefile/Makefile.am [new file with mode: 0644]
tests/zfs-tests/tests/functional/cachefile/cachefile.cfg [new file with mode: 0644]
tests/zfs-tests/tests/functional/cachefile/cachefile.kshlib [new file with mode: 0644]
tests/zfs-tests/tests/functional/cachefile/cachefile_001_pos.ksh [new file with mode: 0755]
tests/zfs-tests/tests/functional/cachefile/cachefile_002_pos.ksh [new file with mode: 0755]
tests/zfs-tests/tests/functional/cachefile/cachefile_003_pos.ksh [new file with mode: 0755]
tests/zfs-tests/tests/functional/cachefile/cachefile_004_pos.ksh [new file with mode: 0755]
tests/zfs-tests/tests/functional/casenorm/Makefile.am [new file with mode: 0644]
tests/zfs-tests/tests/functional/casenorm/case_all_values.ksh [new file with mode: 0755]
tests/zfs-tests/tests/functional/casenorm/casenorm.cfg [new file with mode: 0644]
tests/zfs-tests/tests/functional/casenorm/casenorm.kshlib [new file with mode: 0755]
tests/zfs-tests/tests/functional/casenorm/cleanup.ksh [new file with mode: 0755]
tests/zfs-tests/tests/functional/casenorm/insensitive_formd_delete.ksh [new file with mode: 0755]
tests/zfs-tests/tests/functional/casenorm/insensitive_formd_lookup.ksh [new file with mode: 0755]
tests/zfs-tests/tests/functional/casenorm/insensitive_none_delete.ksh [new file with mode: 0755]
tests/zfs-tests/tests/functional/casenorm/insensitive_none_lookup.ksh [new file with mode: 0755]
tests/zfs-tests/tests/functional/casenorm/mixed_formd_delete.ksh [new file with mode: 0755]
tests/zfs-tests/tests/functional/casenorm/mixed_formd_lookup.ksh [new file with mode: 0755]
tests/zfs-tests/tests/functional/casenorm/mixed_formd_lookup_ci.ksh [new file with mode: 0755]
tests/zfs-tests/tests/functional/casenorm/mixed_none_delete.ksh [new file with mode: 0755]
tests/zfs-tests/tests/functional/casenorm/mixed_none_lookup.ksh [new file with mode: 0755]
tests/zfs-tests/tests/functional/casenorm/mixed_none_lookup_ci.ksh [new file with mode: 0755]
tests/zfs-tests/tests/functional/casenorm/norm_all_values.ksh [new file with mode: 0755]
tests/zfs-tests/tests/functional/casenorm/sensitive_formd_delete.ksh [new file with mode: 0755]
tests/zfs-tests/tests/functional/casenorm/sensitive_formd_lookup.ksh [new file with mode: 0755]
tests/zfs-tests/tests/functional/casenorm/sensitive_none_delete.ksh [new file with mode: 0755]
tests/zfs-tests/tests/functional/casenorm/sensitive_none_lookup.ksh [new file with mode: 0755]
tests/zfs-tests/tests/functional/casenorm/setup.ksh [new file with mode: 0755]
tests/zfs-tests/tests/functional/clean_mirror/Makefile.am [new file with mode: 0644]
tests/zfs-tests/tests/functional/clean_mirror/clean_mirror_001_pos.ksh [new file with mode: 0755]
tests/zfs-tests/tests/functional/clean_mirror/clean_mirror_002_pos.ksh [new file with mode: 0755]
tests/zfs-tests/tests/functional/clean_mirror/clean_mirror_003_pos.ksh [new file with mode: 0755]
tests/zfs-tests/tests/functional/clean_mirror/clean_mirror_004_pos.ksh [new file with mode: 0755]
tests/zfs-tests/tests/functional/clean_mirror/clean_mirror_common.kshlib [new file with mode: 0644]
tests/zfs-tests/tests/functional/clean_mirror/cleanup.ksh [new file with mode: 0755]
tests/zfs-tests/tests/functional/clean_mirror/default.cfg [new file with mode: 0644]
tests/zfs-tests/tests/functional/clean_mirror/setup.ksh [new file with mode: 0755]
tests/zfs-tests/tests/functional/cli_root/Makefile.am [new file with mode: 0644]
tests/zfs-tests/tests/functional/cli_root/cli_common.kshlib [new file with mode: 0644]
tests/zfs-tests/tests/functional/cli_root/zdb/Makefile.am [new file with mode: 0644]
tests/zfs-tests/tests/functional/cli_root/zdb/zdb_001_neg.ksh [new file with mode: 0755]
tests/zfs-tests/tests/functional/cli_root/zfs/Makefile.am [new file with mode: 0644]
tests/zfs-tests/tests/functional/cli_root/zfs/cleanup.ksh [new file with mode: 0755]
tests/zfs-tests/tests/functional/cli_root/zfs/setup.ksh [new file with mode: 0755]
tests/zfs-tests/tests/functional/cli_root/zfs/zfs_001_neg.ksh [new file with mode: 0755]
tests/zfs-tests/tests/functional/cli_root/zfs/zfs_002_pos.ksh [new file with mode: 0755]
tests/zfs-tests/tests/functional/cli_root/zfs/zfs_003_neg.ksh [new file with mode: 0755]
tests/zfs-tests/tests/functional/cli_root/zfs_clone/Makefile.am [new file with mode: 0644]
tests/zfs-tests/tests/functional/cli_root/zfs_clone/cleanup.ksh [new file with mode: 0755]
tests/zfs-tests/tests/functional/cli_root/zfs_clone/setup.ksh [new file with mode: 0755]
tests/zfs-tests/tests/functional/cli_root/zfs_clone/zfs_clone_001_neg.ksh [new file with mode: 0755]
tests/zfs-tests/tests/functional/cli_root/zfs_clone/zfs_clone_002_pos.ksh [new file with mode: 0755]
tests/zfs-tests/tests/functional/cli_root/zfs_clone/zfs_clone_003_pos.ksh [new file with mode: 0755]
tests/zfs-tests/tests/functional/cli_root/zfs_clone/zfs_clone_004_pos.ksh [new file with mode: 0755]
tests/zfs-tests/tests/functional/cli_root/zfs_clone/zfs_clone_005_pos.ksh [new file with mode: 0755]
tests/zfs-tests/tests/functional/cli_root/zfs_clone/zfs_clone_006_pos.ksh [new file with mode: 0755]
tests/zfs-tests/tests/functional/cli_root/zfs_clone/zfs_clone_007_pos.ksh [new file with mode: 0755]
tests/zfs-tests/tests/functional/cli_root/zfs_clone/zfs_clone_008_neg.ksh [new file with mode: 0755]
tests/zfs-tests/tests/functional/cli_root/zfs_clone/zfs_clone_009_neg.ksh [new file with mode: 0755]
tests/zfs-tests/tests/functional/cli_root/zfs_clone/zfs_clone_010_pos.ksh [new file with mode: 0755]
tests/zfs-tests/tests/functional/cli_root/zfs_copies/Makefile.am [new file with mode: 0644]
tests/zfs-tests/tests/functional/cli_root/zfs_copies/cleanup.ksh [new file with mode: 0755]
tests/zfs-tests/tests/functional/cli_root/zfs_copies/setup.ksh [new file with mode: 0755]
tests/zfs-tests/tests/functional/cli_root/zfs_copies/zfs_copies.cfg [new file with mode: 0644]
tests/zfs-tests/tests/functional/cli_root/zfs_copies/zfs_copies.kshlib [new file with mode: 0644]
tests/zfs-tests/tests/functional/cli_root/zfs_copies/zfs_copies_001_pos.ksh [new file with mode: 0755]
tests/zfs-tests/tests/functional/cli_root/zfs_copies/zfs_copies_002_pos.ksh [new file with mode: 0755]
tests/zfs-tests/tests/functional/cli_root/zfs_copies/zfs_copies_003_pos.ksh [new file with mode: 0755]
tests/zfs-tests/tests/functional/cli_root/zfs_copies/zfs_copies_004_neg.ksh [new file with mode: 0755]
tests/zfs-tests/tests/functional/cli_root/zfs_copies/zfs_copies_005_neg.ksh [new file with mode: 0755]
tests/zfs-tests/tests/functional/cli_root/zfs_copies/zfs_copies_006_pos.ksh [new file with mode: 0755]
tests/zfs-tests/tests/functional/cli_root/zfs_create/Makefile.am [new file with mode: 0644]
tests/zfs-tests/tests/functional/cli_root/zfs_create/cleanup.ksh [new file with mode: 0755]
tests/zfs-tests/tests/functional/cli_root/zfs_create/properties.kshlib [new file with mode: 0644]
tests/zfs-tests/tests/functional/cli_root/zfs_create/setup.ksh [new file with mode: 0755]
tests/zfs-tests/tests/functional/cli_root/zfs_create/zfs_create.cfg [new file with mode: 0644]
tests/zfs-tests/tests/functional/cli_root/zfs_create/zfs_create_001_pos.ksh [new file with mode: 0755]
tests/zfs-tests/tests/functional/cli_root/zfs_create/zfs_create_002_pos.ksh [new file with mode: 0755]
tests/zfs-tests/tests/functional/cli_root/zfs_create/zfs_create_003_pos.ksh [new file with mode: 0755]
tests/zfs-tests/tests/functional/cli_root/zfs_create/zfs_create_004_pos.ksh [new file with mode: 0755]
tests/zfs-tests/tests/functional/cli_root/zfs_create/zfs_create_005_pos.ksh [new file with mode: 0755]
tests/zfs-tests/tests/functional/cli_root/zfs_create/zfs_create_006_pos.ksh [new file with mode: 0755]
tests/zfs-tests/tests/functional/cli_root/zfs_create/zfs_create_007_pos.ksh [new file with mode: 0755]
tests/zfs-tests/tests/functional/cli_root/zfs_create/zfs_create_008_neg.ksh [new file with mode: 0755]
tests/zfs-tests/tests/functional/cli_root/zfs_create/zfs_create_009_neg.ksh [new file with mode: 0755]
tests/zfs-tests/tests/functional/cli_root/zfs_create/zfs_create_010_neg.ksh [new file with mode: 0755]
tests/zfs-tests/tests/functional/cli_root/zfs_create/zfs_create_011_pos.ksh [new file with mode: 0755]
tests/zfs-tests/tests/functional/cli_root/zfs_create/zfs_create_012_pos.ksh [new file with mode: 0755]
tests/zfs-tests/tests/functional/cli_root/zfs_create/zfs_create_013_pos.ksh [new file with mode: 0755]
tests/zfs-tests/tests/functional/cli_root/zfs_create/zfs_create_common.kshlib [new file with mode: 0644]
tests/zfs-tests/tests/functional/cli_root/zfs_destroy/Makefile.am [new file with mode: 0644]
tests/zfs-tests/tests/functional/cli_root/zfs_destroy/cleanup.ksh [new file with mode: 0755]
tests/zfs-tests/tests/functional/cli_root/zfs_destroy/setup.ksh [new file with mode: 0755]
tests/zfs-tests/tests/functional/cli_root/zfs_destroy/zfs_destroy.cfg [new file with mode: 0644]
tests/zfs-tests/tests/functional/cli_root/zfs_destroy/zfs_destroy_001_pos.ksh [new file with mode: 0755]
tests/zfs-tests/tests/functional/cli_root/zfs_destroy/zfs_destroy_002_pos.ksh [new file with mode: 0755]
tests/zfs-tests/tests/functional/cli_root/zfs_destroy/zfs_destroy_003_pos.ksh [new file with mode: 0755]
tests/zfs-tests/tests/functional/cli_root/zfs_destroy/zfs_destroy_004_pos.ksh [new file with mode: 0755]
tests/zfs-tests/tests/functional/cli_root/zfs_destroy/zfs_destroy_005_neg.ksh [new file with mode: 0755]
tests/zfs-tests/tests/functional/cli_root/zfs_destroy/zfs_destroy_006_neg.ksh [new file with mode: 0755]
tests/zfs-tests/tests/functional/cli_root/zfs_destroy/zfs_destroy_007_neg.ksh [new file with mode: 0755]
tests/zfs-tests/tests/functional/cli_root/zfs_destroy/zfs_destroy_008_pos.ksh [new file with mode: 0755]
tests/zfs-tests/tests/functional/cli_root/zfs_destroy/zfs_destroy_009_pos.ksh [new file with mode: 0755]
tests/zfs-tests/tests/functional/cli_root/zfs_destroy/zfs_destroy_010_pos.ksh [new file with mode: 0755]
tests/zfs-tests/tests/functional/cli_root/zfs_destroy/zfs_destroy_011_pos.ksh [new file with mode: 0755]
tests/zfs-tests/tests/functional/cli_root/zfs_destroy/zfs_destroy_012_pos.ksh [new file with mode: 0755]
tests/zfs-tests/tests/functional/cli_root/zfs_destroy/zfs_destroy_013_neg.ksh [new file with mode: 0755]
tests/zfs-tests/tests/functional/cli_root/zfs_destroy/zfs_destroy_014_pos.ksh [new file with mode: 0755]
tests/zfs-tests/tests/functional/cli_root/zfs_destroy/zfs_destroy_015_pos.ksh [new file with mode: 0755]
tests/zfs-tests/tests/functional/cli_root/zfs_destroy/zfs_destroy_016_pos.ksh [new file with mode: 0755]
tests/zfs-tests/tests/functional/cli_root/zfs_destroy/zfs_destroy_common.kshlib [new file with mode: 0644]
tests/zfs-tests/tests/functional/cli_root/zfs_get/Makefile.am [new file with mode: 0644]
tests/zfs-tests/tests/functional/cli_root/zfs_get/cleanup.ksh [new file with mode: 0755]
tests/zfs-tests/tests/functional/cli_root/zfs_get/setup.ksh [new file with mode: 0755]
tests/zfs-tests/tests/functional/cli_root/zfs_get/zfs_get_001_pos.ksh [new file with mode: 0755]
tests/zfs-tests/tests/functional/cli_root/zfs_get/zfs_get_002_pos.ksh [new file with mode: 0755]
tests/zfs-tests/tests/functional/cli_root/zfs_get/zfs_get_003_pos.ksh [new file with mode: 0755]
tests/zfs-tests/tests/functional/cli_root/zfs_get/zfs_get_004_pos.ksh [new file with mode: 0755]
tests/zfs-tests/tests/functional/cli_root/zfs_get/zfs_get_005_neg.ksh [new file with mode: 0755]
tests/zfs-tests/tests/functional/cli_root/zfs_get/zfs_get_006_neg.ksh [new file with mode: 0755]
tests/zfs-tests/tests/functional/cli_root/zfs_get/zfs_get_007_neg.ksh [new file with mode: 0755]
tests/zfs-tests/tests/functional/cli_root/zfs_get/zfs_get_008_pos.ksh [new file with mode: 0755]
tests/zfs-tests/tests/functional/cli_root/zfs_get/zfs_get_009_pos.ksh [new file with mode: 0755]
tests/zfs-tests/tests/functional/cli_root/zfs_get/zfs_get_010_neg.ksh [new file with mode: 0755]
tests/zfs-tests/tests/functional/cli_root/zfs_get/zfs_get_common.kshlib [new file with mode: 0644]
tests/zfs-tests/tests/functional/cli_root/zfs_get/zfs_get_list_d.kshlib [new file with mode: 0644]
tests/zfs-tests/tests/functional/cli_root/zfs_inherit/Makefile.am [new file with mode: 0644]
tests/zfs-tests/tests/functional/cli_root/zfs_inherit/cleanup.ksh [new file with mode: 0755]
tests/zfs-tests/tests/functional/cli_root/zfs_inherit/setup.ksh [new file with mode: 0755]
tests/zfs-tests/tests/functional/cli_root/zfs_inherit/zfs_inherit_001_neg.ksh [new file with mode: 0755]
tests/zfs-tests/tests/functional/cli_root/zfs_inherit/zfs_inherit_002_neg.ksh [new file with mode: 0755]
tests/zfs-tests/tests/functional/cli_root/zfs_inherit/zfs_inherit_003_pos.ksh [new file with mode: 0755]
tests/zfs-tests/tests/functional/cli_root/zfs_mount/Makefile.am [new file with mode: 0644]
tests/zfs-tests/tests/functional/cli_root/zfs_mount/cleanup.ksh [new file with mode: 0755]
tests/zfs-tests/tests/functional/cli_root/zfs_mount/setup.ksh [new file with mode: 0755]
tests/zfs-tests/tests/functional/cli_root/zfs_mount/zfs_mount.cfg [new file with mode: 0644]
tests/zfs-tests/tests/functional/cli_root/zfs_mount/zfs_mount.kshlib [new file with mode: 0644]
tests/zfs-tests/tests/functional/cli_root/zfs_mount/zfs_mount_001_pos.ksh [new file with mode: 0755]
tests/zfs-tests/tests/functional/cli_root/zfs_mount/zfs_mount_002_pos.ksh [new file with mode: 0755]
tests/zfs-tests/tests/functional/cli_root/zfs_mount/zfs_mount_003_pos.ksh [new file with mode: 0755]
tests/zfs-tests/tests/functional/cli_root/zfs_mount/zfs_mount_004_pos.ksh [new file with mode: 0755]
tests/zfs-tests/tests/functional/cli_root/zfs_mount/zfs_mount_005_pos.ksh [new file with mode: 0755]
tests/zfs-tests/tests/functional/cli_root/zfs_mount/zfs_mount_006_pos.ksh [new file with mode: 0755]
tests/zfs-tests/tests/functional/cli_root/zfs_mount/zfs_mount_007_pos.ksh [new file with mode: 0755]
tests/zfs-tests/tests/functional/cli_root/zfs_mount/zfs_mount_008_pos.ksh [new file with mode: 0755]
tests/zfs-tests/tests/functional/cli_root/zfs_mount/zfs_mount_009_neg.ksh [new file with mode: 0755]
tests/zfs-tests/tests/functional/cli_root/zfs_mount/zfs_mount_010_neg.ksh [new file with mode: 0755]
tests/zfs-tests/tests/functional/cli_root/zfs_mount/zfs_mount_011_neg.ksh [new file with mode: 0755]
tests/zfs-tests/tests/functional/cli_root/zfs_mount/zfs_mount_all_001_pos.ksh [new file with mode: 0755]
tests/zfs-tests/tests/functional/cli_root/zfs_promote/Makefile.am [new file with mode: 0644]
tests/zfs-tests/tests/functional/cli_root/zfs_promote/cleanup.ksh [new file with mode: 0755]
tests/zfs-tests/tests/functional/cli_root/zfs_promote/setup.ksh [new file with mode: 0755]
tests/zfs-tests/tests/functional/cli_root/zfs_promote/zfs_promote.cfg [new file with mode: 0644]
tests/zfs-tests/tests/functional/cli_root/zfs_promote/zfs_promote_001_pos.ksh [new file with mode: 0755]
tests/zfs-tests/tests/functional/cli_root/zfs_promote/zfs_promote_002_pos.ksh [new file with mode: 0755]
tests/zfs-tests/tests/functional/cli_root/zfs_promote/zfs_promote_003_pos.ksh [new file with mode: 0755]
tests/zfs-tests/tests/functional/cli_root/zfs_promote/zfs_promote_004_pos.ksh [new file with mode: 0755]
tests/zfs-tests/tests/functional/cli_root/zfs_promote/zfs_promote_005_pos.ksh [new file with mode: 0755]
tests/zfs-tests/tests/functional/cli_root/zfs_promote/zfs_promote_006_neg.ksh [new file with mode: 0755]
tests/zfs-tests/tests/functional/cli_root/zfs_promote/zfs_promote_007_neg.ksh [new file with mode: 0755]
tests/zfs-tests/tests/functional/cli_root/zfs_promote/zfs_promote_008_pos.ksh [new file with mode: 0755]
tests/zfs-tests/tests/functional/cli_root/zfs_property/Makefile.am [new file with mode: 0644]
tests/zfs-tests/tests/functional/cli_root/zfs_property/cleanup.ksh [new file with mode: 0755]
tests/zfs-tests/tests/functional/cli_root/zfs_property/setup.ksh [new file with mode: 0755]
tests/zfs-tests/tests/functional/cli_root/zfs_property/zfs_written_property_001_pos.ksh [new file with mode: 0755]
tests/zfs-tests/tests/functional/cli_root/zfs_receive/Makefile.am [new file with mode: 0644]
tests/zfs-tests/tests/functional/cli_root/zfs_receive/cleanup.ksh [new file with mode: 0755]
tests/zfs-tests/tests/functional/cli_root/zfs_receive/setup.ksh [new file with mode: 0755]
tests/zfs-tests/tests/functional/cli_root/zfs_receive/zfs_receive_001_pos.ksh [new file with mode: 0755]
tests/zfs-tests/tests/functional/cli_root/zfs_receive/zfs_receive_002_pos.ksh [new file with mode: 0755]
tests/zfs-tests/tests/functional/cli_root/zfs_receive/zfs_receive_003_pos.ksh [new file with mode: 0755]
tests/zfs-tests/tests/functional/cli_root/zfs_receive/zfs_receive_004_neg.ksh [new file with mode: 0755]
tests/zfs-tests/tests/functional/cli_root/zfs_receive/zfs_receive_005_neg.ksh [new file with mode: 0755]
tests/zfs-tests/tests/functional/cli_root/zfs_receive/zfs_receive_006_pos.ksh [new file with mode: 0755]
tests/zfs-tests/tests/functional/cli_root/zfs_receive/zfs_receive_007_neg.ksh [new file with mode: 0755]
tests/zfs-tests/tests/functional/cli_root/zfs_receive/zfs_receive_008_pos.ksh [new file with mode: 0755]
tests/zfs-tests/tests/functional/cli_root/zfs_receive/zfs_receive_009_neg.ksh [new file with mode: 0755]
tests/zfs-tests/tests/functional/cli_root/zfs_receive/zfs_receive_010_pos.ksh [new file with mode: 0755]
tests/zfs-tests/tests/functional/cli_root/zfs_receive/zfs_receive_011_pos.ksh [new file with mode: 0755]
tests/zfs-tests/tests/functional/cli_root/zfs_receive/zfs_receive_012_pos.ksh [new file with mode: 0755]
tests/zfs-tests/tests/functional/cli_root/zfs_rename/Makefile.am [new file with mode: 0644]
tests/zfs-tests/tests/functional/cli_root/zfs_rename/cleanup.ksh [new file with mode: 0755]
tests/zfs-tests/tests/functional/cli_root/zfs_rename/setup.ksh [new file with mode: 0755]
tests/zfs-tests/tests/functional/cli_root/zfs_rename/zfs_rename.cfg [new file with mode: 0644]
tests/zfs-tests/tests/functional/cli_root/zfs_rename/zfs_rename.kshlib [new file with mode: 0644]
tests/zfs-tests/tests/functional/cli_root/zfs_rename/zfs_rename_001_pos.ksh [new file with mode: 0755]
tests/zfs-tests/tests/functional/cli_root/zfs_rename/zfs_rename_002_pos.ksh [new file with mode: 0755]
tests/zfs-tests/tests/functional/cli_root/zfs_rename/zfs_rename_003_pos.ksh [new file with mode: 0755]
tests/zfs-tests/tests/functional/cli_root/zfs_rename/zfs_rename_004_neg.ksh [new file with mode: 0755]
tests/zfs-tests/tests/functional/cli_root/zfs_rename/zfs_rename_005_neg.ksh [new file with mode: 0755]
tests/zfs-tests/tests/functional/cli_root/zfs_rename/zfs_rename_006_pos.ksh [new file with mode: 0755]
tests/zfs-tests/tests/functional/cli_root/zfs_rename/zfs_rename_007_pos.ksh [new file with mode: 0755]
tests/zfs-tests/tests/functional/cli_root/zfs_rename/zfs_rename_008_pos.ksh [new file with mode: 0755]
tests/zfs-tests/tests/functional/cli_root/zfs_rename/zfs_rename_009_neg.ksh [new file with mode: 0755]
tests/zfs-tests/tests/functional/cli_root/zfs_rename/zfs_rename_010_neg.ksh [new file with mode: 0755]
tests/zfs-tests/tests/functional/cli_root/zfs_rename/zfs_rename_011_pos.ksh [new file with mode: 0755]
tests/zfs-tests/tests/functional/cli_root/zfs_rename/zfs_rename_012_neg.ksh [new file with mode: 0755]
tests/zfs-tests/tests/functional/cli_root/zfs_rename/zfs_rename_013_pos.ksh [new file with mode: 0755]
tests/zfs-tests/tests/functional/cli_root/zfs_reservation/Makefile.am [new file with mode: 0644]
tests/zfs-tests/tests/functional/cli_root/zfs_reservation/cleanup.ksh [new file with mode: 0755]
tests/zfs-tests/tests/functional/cli_root/zfs_reservation/setup.ksh [new file with mode: 0755]
tests/zfs-tests/tests/functional/cli_root/zfs_reservation/zfs_reservation_001_pos.ksh [new file with mode: 0755]
tests/zfs-tests/tests/functional/cli_root/zfs_reservation/zfs_reservation_002_pos.ksh [new file with mode: 0755]
tests/zfs-tests/tests/functional/cli_root/zfs_rollback/Makefile.am [new file with mode: 0644]
tests/zfs-tests/tests/functional/cli_root/zfs_rollback/cleanup.ksh [new file with mode: 0755]
tests/zfs-tests/tests/functional/cli_root/zfs_rollback/setup.ksh [new file with mode: 0755]
tests/zfs-tests/tests/functional/cli_root/zfs_rollback/zfs_rollback.cfg [new file with mode: 0644]
tests/zfs-tests/tests/functional/cli_root/zfs_rollback/zfs_rollback_001_pos.ksh [new file with mode: 0755]
tests/zfs-tests/tests/functional/cli_root/zfs_rollback/zfs_rollback_002_pos.ksh [new file with mode: 0755]
tests/zfs-tests/tests/functional/cli_root/zfs_rollback/zfs_rollback_003_neg.ksh [new file with mode: 0755]
tests/zfs-tests/tests/functional/cli_root/zfs_rollback/zfs_rollback_004_neg.ksh [new file with mode: 0755]
tests/zfs-tests/tests/functional/cli_root/zfs_rollback/zfs_rollback_common.kshlib [new file with mode: 0644]
tests/zfs-tests/tests/functional/cli_root/zfs_send/Makefile.am [new file with mode: 0644]
tests/zfs-tests/tests/functional/cli_root/zfs_send/cleanup.ksh [new file with mode: 0755]
tests/zfs-tests/tests/functional/cli_root/zfs_send/setup.ksh [new file with mode: 0755]
tests/zfs-tests/tests/functional/cli_root/zfs_send/zfs_send.cfg [new file with mode: 0644]
tests/zfs-tests/tests/functional/cli_root/zfs_send/zfs_send_001_pos.ksh [new file with mode: 0755]
tests/zfs-tests/tests/functional/cli_root/zfs_send/zfs_send_002_pos.ksh [new file with mode: 0755]
tests/zfs-tests/tests/functional/cli_root/zfs_send/zfs_send_003_pos.ksh [new file with mode: 0755]
tests/zfs-tests/tests/functional/cli_root/zfs_send/zfs_send_004_neg.ksh [new file with mode: 0755]
tests/zfs-tests/tests/functional/cli_root/zfs_send/zfs_send_005_pos.ksh [new file with mode: 0755]
tests/zfs-tests/tests/functional/cli_root/zfs_send/zfs_send_006_pos.ksh [new file with mode: 0755]
tests/zfs-tests/tests/functional/cli_root/zfs_send/zfs_send_007_pos.ksh [new file with mode: 0755]
tests/zfs-tests/tests/functional/cli_root/zfs_set/Makefile.am [new file with mode: 0644]
tests/zfs-tests/tests/functional/cli_root/zfs_set/cache_001_pos.ksh [new file with mode: 0755]
tests/zfs-tests/tests/functional/cli_root/zfs_set/cache_002_neg.ksh [new file with mode: 0755]
tests/zfs-tests/tests/functional/cli_root/zfs_set/canmount_001_pos.ksh [new file with mode: 0755]
tests/zfs-tests/tests/functional/cli_root/zfs_set/canmount_002_pos.ksh [new file with mode: 0755]
tests/zfs-tests/tests/functional/cli_root/zfs_set/canmount_003_pos.ksh [new file with mode: 0755]
tests/zfs-tests/tests/functional/cli_root/zfs_set/canmount_004_pos.ksh [new file with mode: 0755]
tests/zfs-tests/tests/functional/cli_root/zfs_set/checksum_001_pos.ksh [new file with mode: 0755]
tests/zfs-tests/tests/functional/cli_root/zfs_set/cleanup.ksh [new file with mode: 0755]
tests/zfs-tests/tests/functional/cli_root/zfs_set/compression_001_pos.ksh [new file with mode: 0755]
tests/zfs-tests/tests/functional/cli_root/zfs_set/mountpoint_001_pos.ksh [new file with mode: 0755]
tests/zfs-tests/tests/functional/cli_root/zfs_set/mountpoint_002_pos.ksh [new file with mode: 0755]
tests/zfs-tests/tests/functional/cli_root/zfs_set/mountpoint_003_pos.ksh [new file with mode: 0755]
tests/zfs-tests/tests/functional/cli_root/zfs_set/onoffs_001_pos.ksh [new file with mode: 0755]
tests/zfs-tests/tests/functional/cli_root/zfs_set/property_alias_001_pos.ksh [new file with mode: 0755]
tests/zfs-tests/tests/functional/cli_root/zfs_set/readonly_001_pos.ksh [new file with mode: 0755]
tests/zfs-tests/tests/functional/cli_root/zfs_set/reservation_001_neg.ksh [new file with mode: 0755]
tests/zfs-tests/tests/functional/cli_root/zfs_set/ro_props_001_pos.ksh [new file with mode: 0755]
tests/zfs-tests/tests/functional/cli_root/zfs_set/setup.ksh [new file with mode: 0755]
tests/zfs-tests/tests/functional/cli_root/zfs_set/share_mount_001_neg.ksh [new file with mode: 0755]
tests/zfs-tests/tests/functional/cli_root/zfs_set/snapdir_001_pos.ksh [new file with mode: 0755]
tests/zfs-tests/tests/functional/cli_root/zfs_set/user_property_001_pos.ksh [new file with mode: 0755]
tests/zfs-tests/tests/functional/cli_root/zfs_set/user_property_002_pos.ksh [new file with mode: 0755]
tests/zfs-tests/tests/functional/cli_root/zfs_set/user_property_003_neg.ksh [new file with mode: 0755]
tests/zfs-tests/tests/functional/cli_root/zfs_set/user_property_004_pos.ksh [new file with mode: 0755]
tests/zfs-tests/tests/functional/cli_root/zfs_set/version_001_neg.ksh [new file with mode: 0755]
tests/zfs-tests/tests/functional/cli_root/zfs_set/zfs_set_001_neg.ksh [new file with mode: 0755]
tests/zfs-tests/tests/functional/cli_root/zfs_set/zfs_set_002_neg.ksh [new file with mode: 0755]
tests/zfs-tests/tests/functional/cli_root/zfs_set/zfs_set_003_neg.ksh [new file with mode: 0755]
tests/zfs-tests/tests/functional/cli_root/zfs_set/zfs_set_common.kshlib [new file with mode: 0644]
tests/zfs-tests/tests/functional/cli_root/zfs_share/Makefile.am [new file with mode: 0644]
tests/zfs-tests/tests/functional/cli_root/zfs_share/cleanup.ksh [new file with mode: 0755]
tests/zfs-tests/tests/functional/cli_root/zfs_share/setup.ksh [new file with mode: 0755]
tests/zfs-tests/tests/functional/cli_root/zfs_share/zfs_share.cfg [new file with mode: 0644]
tests/zfs-tests/tests/functional/cli_root/zfs_share/zfs_share_001_pos.ksh [new file with mode: 0755]
tests/zfs-tests/tests/functional/cli_root/zfs_share/zfs_share_002_pos.ksh [new file with mode: 0755]
tests/zfs-tests/tests/functional/cli_root/zfs_share/zfs_share_003_pos.ksh [new file with mode: 0755]
tests/zfs-tests/tests/functional/cli_root/zfs_share/zfs_share_004_pos.ksh [new file with mode: 0755]
tests/zfs-tests/tests/functional/cli_root/zfs_share/zfs_share_005_pos.ksh [new file with mode: 0755]
tests/zfs-tests/tests/functional/cli_root/zfs_share/zfs_share_006_pos.ksh [new file with mode: 0755]
tests/zfs-tests/tests/functional/cli_root/zfs_share/zfs_share_007_neg.ksh [new file with mode: 0755]
tests/zfs-tests/tests/functional/cli_root/zfs_share/zfs_share_008_neg.ksh [new file with mode: 0755]
tests/zfs-tests/tests/functional/cli_root/zfs_share/zfs_share_009_neg.ksh [new file with mode: 0755]
tests/zfs-tests/tests/functional/cli_root/zfs_share/zfs_share_010_neg.ksh [new file with mode: 0755]
tests/zfs-tests/tests/functional/cli_root/zfs_share/zfs_share_011_pos.ksh [new file with mode: 0755]
tests/zfs-tests/tests/functional/cli_root/zfs_snapshot/Makefile.am [new file with mode: 0644]
tests/zfs-tests/tests/functional/cli_root/zfs_snapshot/cleanup.ksh [new file with mode: 0755]
tests/zfs-tests/tests/functional/cli_root/zfs_snapshot/setup.ksh [new file with mode: 0755]
tests/zfs-tests/tests/functional/cli_root/zfs_snapshot/zfs_snapshot.cfg [new file with mode: 0644]
tests/zfs-tests/tests/functional/cli_root/zfs_snapshot/zfs_snapshot_001_neg.ksh [new file with mode: 0755]
tests/zfs-tests/tests/functional/cli_root/zfs_snapshot/zfs_snapshot_002_neg.ksh [new file with mode: 0755]
tests/zfs-tests/tests/functional/cli_root/zfs_snapshot/zfs_snapshot_003_neg.ksh [new file with mode: 0755]
tests/zfs-tests/tests/functional/cli_root/zfs_snapshot/zfs_snapshot_004_neg.ksh [new file with mode: 0755]
tests/zfs-tests/tests/functional/cli_root/zfs_snapshot/zfs_snapshot_005_neg.ksh [new file with mode: 0755]
tests/zfs-tests/tests/functional/cli_root/zfs_snapshot/zfs_snapshot_006_pos.ksh [new file with mode: 0755]
tests/zfs-tests/tests/functional/cli_root/zfs_snapshot/zfs_snapshot_007_neg.ksh [new file with mode: 0755]
tests/zfs-tests/tests/functional/cli_root/zfs_snapshot/zfs_snapshot_008_neg.ksh [new file with mode: 0755]
tests/zfs-tests/tests/functional/cli_root/zfs_snapshot/zfs_snapshot_009_pos.ksh [new file with mode: 0755]
tests/zfs-tests/tests/functional/cli_root/zfs_unmount/Makefile.am [new file with mode: 0644]
tests/zfs-tests/tests/functional/cli_root/zfs_unmount/cleanup.ksh [new file with mode: 0755]
tests/zfs-tests/tests/functional/cli_root/zfs_unmount/setup.ksh [new file with mode: 0755]
tests/zfs-tests/tests/functional/cli_root/zfs_unmount/zfs_unmount.cfg [new file with mode: 0644]
tests/zfs-tests/tests/functional/cli_root/zfs_unmount/zfs_unmount.kshlib [new file with mode: 0644]
tests/zfs-tests/tests/functional/cli_root/zfs_unmount/zfs_unmount_001_pos.ksh [new file with mode: 0755]
tests/zfs-tests/tests/functional/cli_root/zfs_unmount/zfs_unmount_002_pos.ksh [new file with mode: 0755]
tests/zfs-tests/tests/functional/cli_root/zfs_unmount/zfs_unmount_003_pos.ksh [new file with mode: 0755]
tests/zfs-tests/tests/functional/cli_root/zfs_unmount/zfs_unmount_004_pos.ksh [new file with mode: 0755]
tests/zfs-tests/tests/functional/cli_root/zfs_unmount/zfs_unmount_005_pos.ksh [new file with mode: 0755]
tests/zfs-tests/tests/functional/cli_root/zfs_unmount/zfs_unmount_006_pos.ksh [new file with mode: 0755]
tests/zfs-tests/tests/functional/cli_root/zfs_unmount/zfs_unmount_007_neg.ksh [new file with mode: 0755]
tests/zfs-tests/tests/functional/cli_root/zfs_unmount/zfs_unmount_008_neg.ksh [new file with mode: 0755]
tests/zfs-tests/tests/functional/cli_root/zfs_unmount/zfs_unmount_009_pos.ksh [new file with mode: 0755]
tests/zfs-tests/tests/functional/cli_root/zfs_unmount/zfs_unmount_all_001_pos.ksh [new file with mode: 0755]
tests/zfs-tests/tests/functional/cli_root/zfs_unshare/Makefile.am [new file with mode: 0644]
tests/zfs-tests/tests/functional/cli_root/zfs_unshare/cleanup.ksh [new file with mode: 0755]
tests/zfs-tests/tests/functional/cli_root/zfs_unshare/setup.ksh [new file with mode: 0755]
tests/zfs-tests/tests/functional/cli_root/zfs_unshare/zfs_unshare_001_pos.ksh [new file with mode: 0755]
tests/zfs-tests/tests/functional/cli_root/zfs_unshare/zfs_unshare_002_pos.ksh [new file with mode: 0755]
tests/zfs-tests/tests/functional/cli_root/zfs_unshare/zfs_unshare_003_pos.ksh [new file with mode: 0755]
tests/zfs-tests/tests/functional/cli_root/zfs_unshare/zfs_unshare_004_neg.ksh [new file with mode: 0755]
tests/zfs-tests/tests/functional/cli_root/zfs_unshare/zfs_unshare_005_neg.ksh [new file with mode: 0755]
tests/zfs-tests/tests/functional/cli_root/zfs_upgrade/Makefile.am [new file with mode: 0644]
tests/zfs-tests/tests/functional/cli_root/zfs_upgrade/cleanup.ksh [new file with mode: 0755]
tests/zfs-tests/tests/functional/cli_root/zfs_upgrade/setup.ksh [new file with mode: 0755]
tests/zfs-tests/tests/functional/cli_root/zfs_upgrade/zfs_upgrade.kshlib [new file with mode: 0644]
tests/zfs-tests/tests/functional/cli_root/zfs_upgrade/zfs_upgrade_001_pos.ksh [new file with mode: 0755]
tests/zfs-tests/tests/functional/cli_root/zfs_upgrade/zfs_upgrade_002_pos.ksh [new file with mode: 0755]
tests/zfs-tests/tests/functional/cli_root/zfs_upgrade/zfs_upgrade_003_pos.ksh [new file with mode: 0755]
tests/zfs-tests/tests/functional/cli_root/zfs_upgrade/zfs_upgrade_004_pos.ksh [new file with mode: 0755]
tests/zfs-tests/tests/functional/cli_root/zfs_upgrade/zfs_upgrade_005_pos.ksh [new file with mode: 0755]
tests/zfs-tests/tests/functional/cli_root/zfs_upgrade/zfs_upgrade_006_neg.ksh [new file with mode: 0755]
tests/zfs-tests/tests/functional/cli_root/zfs_upgrade/zfs_upgrade_007_neg.ksh [new file with mode: 0755]
tests/zfs-tests/tests/functional/cli_root/zpool/Makefile.am [new file with mode: 0644]
tests/zfs-tests/tests/functional/cli_root/zpool/cleanup.ksh [new file with mode: 0755]
tests/zfs-tests/tests/functional/cli_root/zpool/setup.ksh [new file with mode: 0755]
tests/zfs-tests/tests/functional/cli_root/zpool/zpool_001_neg.ksh [new file with mode: 0755]
tests/zfs-tests/tests/functional/cli_root/zpool/zpool_002_pos.ksh [new file with mode: 0755]
tests/zfs-tests/tests/functional/cli_root/zpool/zpool_003_pos.ksh [new file with mode: 0755]
tests/zfs-tests/tests/functional/cli_root/zpool_add/Makefile.am [new file with mode: 0644]
tests/zfs-tests/tests/functional/cli_root/zpool_add/cleanup.ksh [new file with mode: 0755]
tests/zfs-tests/tests/functional/cli_root/zpool_add/setup.ksh [new file with mode: 0755]
tests/zfs-tests/tests/functional/cli_root/zpool_add/zpool_add.cfg [new file with mode: 0644]
tests/zfs-tests/tests/functional/cli_root/zpool_add/zpool_add.kshlib [new file with mode: 0644]
tests/zfs-tests/tests/functional/cli_root/zpool_add/zpool_add_001_pos.ksh [new file with mode: 0755]
tests/zfs-tests/tests/functional/cli_root/zpool_add/zpool_add_002_pos.ksh [new file with mode: 0755]
tests/zfs-tests/tests/functional/cli_root/zpool_add/zpool_add_003_pos.ksh [new file with mode: 0755]
tests/zfs-tests/tests/functional/cli_root/zpool_add/zpool_add_004_pos.ksh [new file with mode: 0755]
tests/zfs-tests/tests/functional/cli_root/zpool_add/zpool_add_005_pos.ksh [new file with mode: 0755]
tests/zfs-tests/tests/functional/cli_root/zpool_add/zpool_add_006_pos.ksh [new file with mode: 0755]
tests/zfs-tests/tests/functional/cli_root/zpool_add/zpool_add_007_neg.ksh [new file with mode: 0755]
tests/zfs-tests/tests/functional/cli_root/zpool_add/zpool_add_008_neg.ksh [new file with mode: 0755]
tests/zfs-tests/tests/functional/cli_root/zpool_add/zpool_add_009_neg.ksh [new file with mode: 0755]
tests/zfs-tests/tests/functional/cli_root/zpool_attach/Makefile.am [new file with mode: 0644]
tests/zfs-tests/tests/functional/cli_root/zpool_attach/cleanup.ksh [new file with mode: 0755]
tests/zfs-tests/tests/functional/cli_root/zpool_attach/setup.ksh [new file with mode: 0755]
tests/zfs-tests/tests/functional/cli_root/zpool_attach/zpool_attach_001_neg.ksh [new file with mode: 0755]
tests/zfs-tests/tests/functional/cli_root/zpool_clear/Makefile.am [new file with mode: 0644]
tests/zfs-tests/tests/functional/cli_root/zpool_clear/cleanup.ksh [new file with mode: 0755]
tests/zfs-tests/tests/functional/cli_root/zpool_clear/setup.ksh [new file with mode: 0755]
tests/zfs-tests/tests/functional/cli_root/zpool_clear/zpool_clear.cfg [new file with mode: 0644]
tests/zfs-tests/tests/functional/cli_root/zpool_clear/zpool_clear_001_pos.ksh [new file with mode: 0755]
tests/zfs-tests/tests/functional/cli_root/zpool_clear/zpool_clear_002_neg.ksh [new file with mode: 0755]
tests/zfs-tests/tests/functional/cli_root/zpool_clear/zpool_clear_003_neg.ksh [new file with mode: 0755]
tests/zfs-tests/tests/functional/cli_root/zpool_create/Makefile.am [new file with mode: 0644]
tests/zfs-tests/tests/functional/cli_root/zpool_create/cleanup.ksh [new file with mode: 0755]
tests/zfs-tests/tests/functional/cli_root/zpool_create/setup.ksh [new file with mode: 0755]
tests/zfs-tests/tests/functional/cli_root/zpool_create/zpool_create.cfg [new file with mode: 0644]
tests/zfs-tests/tests/functional/cli_root/zpool_create/zpool_create.shlib [new file with mode: 0644]
tests/zfs-tests/tests/functional/cli_root/zpool_create/zpool_create_001_pos.ksh [new file with mode: 0755]
tests/zfs-tests/tests/functional/cli_root/zpool_create/zpool_create_002_pos.ksh [new file with mode: 0755]
tests/zfs-tests/tests/functional/cli_root/zpool_create/zpool_create_003_pos.ksh [new file with mode: 0755]
tests/zfs-tests/tests/functional/cli_root/zpool_create/zpool_create_004_pos.ksh [new file with mode: 0755]
tests/zfs-tests/tests/functional/cli_root/zpool_create/zpool_create_005_pos.ksh [new file with mode: 0755]
tests/zfs-tests/tests/functional/cli_root/zpool_create/zpool_create_006_pos.ksh [new file with mode: 0755]
tests/zfs-tests/tests/functional/cli_root/zpool_create/zpool_create_007_neg.ksh [new file with mode: 0755]
tests/zfs-tests/tests/functional/cli_root/zpool_create/zpool_create_008_pos.ksh [new file with mode: 0755]
tests/zfs-tests/tests/functional/cli_root/zpool_create/zpool_create_009_neg.ksh [new file with mode: 0755]
tests/zfs-tests/tests/functional/cli_root/zpool_create/zpool_create_010_neg.ksh [new file with mode: 0755]
tests/zfs-tests/tests/functional/cli_root/zpool_create/zpool_create_011_neg.ksh [new file with mode: 0755]
tests/zfs-tests/tests/functional/cli_root/zpool_create/zpool_create_012_neg.ksh [new file with mode: 0755]
tests/zfs-tests/tests/functional/cli_root/zpool_create/zpool_create_014_neg.ksh [new file with mode: 0755]
tests/zfs-tests/tests/functional/cli_root/zpool_create/zpool_create_015_neg.ksh [new file with mode: 0755]
tests/zfs-tests/tests/functional/cli_root/zpool_create/zpool_create_016_pos.ksh [new file with mode: 0755]
tests/zfs-tests/tests/functional/cli_root/zpool_create/zpool_create_017_neg.ksh [new file with mode: 0755]
tests/zfs-tests/tests/functional/cli_root/zpool_create/zpool_create_018_pos.ksh [new file with mode: 0755]
tests/zfs-tests/tests/functional/cli_root/zpool_create/zpool_create_019_pos.ksh [new file with mode: 0755]
tests/zfs-tests/tests/functional/cli_root/zpool_create/zpool_create_020_pos.ksh [new file with mode: 0755]
tests/zfs-tests/tests/functional/cli_root/zpool_create/zpool_create_021_pos.ksh [new file with mode: 0755]
tests/zfs-tests/tests/functional/cli_root/zpool_create/zpool_create_022_pos.ksh [new file with mode: 0755]
tests/zfs-tests/tests/functional/cli_root/zpool_create/zpool_create_023_neg.ksh [new file with mode: 0755]
tests/zfs-tests/tests/functional/cli_root/zpool_create/zpool_create_features_001_pos.ksh [new file with mode: 0755]
tests/zfs-tests/tests/functional/cli_root/zpool_create/zpool_create_features_002_pos.ksh [new file with mode: 0755]
tests/zfs-tests/tests/functional/cli_root/zpool_create/zpool_create_features_003_pos.ksh [new file with mode: 0755]
tests/zfs-tests/tests/functional/cli_root/zpool_create/zpool_create_features_004_neg.ksh [new file with mode: 0755]
tests/zfs-tests/tests/functional/cli_root/zpool_destroy/Makefile.am [new file with mode: 0644]
tests/zfs-tests/tests/functional/cli_root/zpool_destroy/zpool_destroy.cfg [new file with mode: 0644]
tests/zfs-tests/tests/functional/cli_root/zpool_destroy/zpool_destroy_001_pos.ksh [new file with mode: 0755]
tests/zfs-tests/tests/functional/cli_root/zpool_destroy/zpool_destroy_002_pos.ksh [new file with mode: 0755]
tests/zfs-tests/tests/functional/cli_root/zpool_destroy/zpool_destroy_003_neg.ksh [new file with mode: 0755]
tests/zfs-tests/tests/functional/cli_root/zpool_detach/Makefile.am [new file with mode: 0644]
tests/zfs-tests/tests/functional/cli_root/zpool_detach/cleanup.ksh [new file with mode: 0755]
tests/zfs-tests/tests/functional/cli_root/zpool_detach/setup.ksh [new file with mode: 0755]
tests/zfs-tests/tests/functional/cli_root/zpool_detach/zpool_detach_001_neg.ksh [new file with mode: 0755]
tests/zfs-tests/tests/functional/cli_root/zpool_expand/Makefile.am [new file with mode: 0644]
tests/zfs-tests/tests/functional/cli_root/zpool_expand/cleanup.ksh [new file with mode: 0755]
tests/zfs-tests/tests/functional/cli_root/zpool_expand/setup.ksh [new file with mode: 0755]
tests/zfs-tests/tests/functional/cli_root/zpool_expand/zpool_expand.cfg [new file with mode: 0644]
tests/zfs-tests/tests/functional/cli_root/zpool_expand/zpool_expand_001_pos.ksh [new file with mode: 0755]
tests/zfs-tests/tests/functional/cli_root/zpool_expand/zpool_expand_002_pos.ksh [new file with mode: 0755]
tests/zfs-tests/tests/functional/cli_root/zpool_expand/zpool_expand_003_neg.ksh [new file with mode: 0755]
tests/zfs-tests/tests/functional/cli_root/zpool_export/Makefile.am [new file with mode: 0644]
tests/zfs-tests/tests/functional/cli_root/zpool_export/cleanup.ksh [new file with mode: 0755]
tests/zfs-tests/tests/functional/cli_root/zpool_export/setup.ksh [new file with mode: 0755]
tests/zfs-tests/tests/functional/cli_root/zpool_export/zpool_export_001_pos.ksh [new file with mode: 0755]
tests/zfs-tests/tests/functional/cli_root/zpool_export/zpool_export_002_pos.ksh [new file with mode: 0755]
tests/zfs-tests/tests/functional/cli_root/zpool_export/zpool_export_003_neg.ksh [new file with mode: 0755]
tests/zfs-tests/tests/functional/cli_root/zpool_export/zpool_export_004_pos.ksh [new file with mode: 0755]
tests/zfs-tests/tests/functional/cli_root/zpool_get/Makefile.am [new file with mode: 0644]
tests/zfs-tests/tests/functional/cli_root/zpool_get/cleanup.ksh [new file with mode: 0755]
tests/zfs-tests/tests/functional/cli_root/zpool_get/setup.ksh [new file with mode: 0755]
tests/zfs-tests/tests/functional/cli_root/zpool_get/zpool_get.cfg [new file with mode: 0644]
tests/zfs-tests/tests/functional/cli_root/zpool_get/zpool_get_001_pos.ksh [new file with mode: 0755]
tests/zfs-tests/tests/functional/cli_root/zpool_get/zpool_get_002_pos.ksh [new file with mode: 0755]
tests/zfs-tests/tests/functional/cli_root/zpool_get/zpool_get_003_pos.ksh [new file with mode: 0755]
tests/zfs-tests/tests/functional/cli_root/zpool_get/zpool_get_004_neg.ksh [new file with mode: 0755]
tests/zfs-tests/tests/functional/cli_root/zpool_history/Makefile.am [new file with mode: 0644]
tests/zfs-tests/tests/functional/cli_root/zpool_history/cleanup.ksh [new file with mode: 0755]
tests/zfs-tests/tests/functional/cli_root/zpool_history/setup.ksh [new file with mode: 0755]
tests/zfs-tests/tests/functional/cli_root/zpool_history/zpool_history_001_neg.ksh [new file with mode: 0755]
tests/zfs-tests/tests/functional/cli_root/zpool_history/zpool_history_002_pos.ksh [new file with mode: 0755]
tests/zfs-tests/tests/functional/cli_root/zpool_import/Makefile.am [new file with mode: 0644]
tests/zfs-tests/tests/functional/cli_root/zpool_import/cleanup.ksh [new file with mode: 0755]
tests/zfs-tests/tests/functional/cli_root/zpool_import/setup.ksh [new file with mode: 0755]
tests/zfs-tests/tests/functional/cli_root/zpool_import/unclean_export.dat.bz2 [new file with mode: 0644]
tests/zfs-tests/tests/functional/cli_root/zpool_import/zpool_import.cfg [new file with mode: 0644]
tests/zfs-tests/tests/functional/cli_root/zpool_import/zpool_import_001_pos.ksh [new file with mode: 0755]
tests/zfs-tests/tests/functional/cli_root/zpool_import/zpool_import_002_pos.ksh [new file with mode: 0755]
tests/zfs-tests/tests/functional/cli_root/zpool_import/zpool_import_003_pos.ksh [new file with mode: 0755]
tests/zfs-tests/tests/functional/cli_root/zpool_import/zpool_import_004_pos.ksh [new file with mode: 0755]
tests/zfs-tests/tests/functional/cli_root/zpool_import/zpool_import_005_pos.ksh [new file with mode: 0755]
tests/zfs-tests/tests/functional/cli_root/zpool_import/zpool_import_006_pos.ksh [new file with mode: 0755]
tests/zfs-tests/tests/functional/cli_root/zpool_import/zpool_import_007_pos.ksh [new file with mode: 0755]
tests/zfs-tests/tests/functional/cli_root/zpool_import/zpool_import_008_pos.ksh [new file with mode: 0755]
tests/zfs-tests/tests/functional/cli_root/zpool_import/zpool_import_009_neg.ksh [new file with mode: 0755]
tests/zfs-tests/tests/functional/cli_root/zpool_import/zpool_import_010_pos.ksh [new file with mode: 0755]
tests/zfs-tests/tests/functional/cli_root/zpool_import/zpool_import_011_neg.ksh [new file with mode: 0755]
tests/zfs-tests/tests/functional/cli_root/zpool_import/zpool_import_012_pos.ksh [new file with mode: 0755]
tests/zfs-tests/tests/functional/cli_root/zpool_import/zpool_import_013_neg.ksh [new file with mode: 0755]
tests/zfs-tests/tests/functional/cli_root/zpool_import/zpool_import_all_001_pos.ksh [new file with mode: 0755]
tests/zfs-tests/tests/functional/cli_root/zpool_import/zpool_import_features_001_pos.ksh [new file with mode: 0755]
tests/zfs-tests/tests/functional/cli_root/zpool_import/zpool_import_features_002_neg.ksh [new file with mode: 0755]
tests/zfs-tests/tests/functional/cli_root/zpool_import/zpool_import_features_003_pos.ksh [new file with mode: 0755]
tests/zfs-tests/tests/functional/cli_root/zpool_import/zpool_import_missing_001_pos.ksh [new file with mode: 0755]
tests/zfs-tests/tests/functional/cli_root/zpool_import/zpool_import_missing_002_pos.ksh [new file with mode: 0755]
tests/zfs-tests/tests/functional/cli_root/zpool_import/zpool_import_missing_003_pos.ksh [new file with mode: 0755]
tests/zfs-tests/tests/functional/cli_root/zpool_import/zpool_import_rename_001_pos.ksh [new file with mode: 0755]
tests/zfs-tests/tests/functional/cli_root/zpool_offline/Makefile.am [new file with mode: 0644]
tests/zfs-tests/tests/functional/cli_root/zpool_offline/cleanup.ksh [new file with mode: 0755]
tests/zfs-tests/tests/functional/cli_root/zpool_offline/setup.ksh [new file with mode: 0755]
tests/zfs-tests/tests/functional/cli_root/zpool_offline/zpool_offline_001_pos.ksh [new file with mode: 0755]
tests/zfs-tests/tests/functional/cli_root/zpool_offline/zpool_offline_002_neg.ksh [new file with mode: 0755]
tests/zfs-tests/tests/functional/cli_root/zpool_online/Makefile.am [new file with mode: 0644]
tests/zfs-tests/tests/functional/cli_root/zpool_online/cleanup.ksh [new file with mode: 0755]
tests/zfs-tests/tests/functional/cli_root/zpool_online/setup.ksh [new file with mode: 0755]
tests/zfs-tests/tests/functional/cli_root/zpool_online/zpool_online_001_pos.ksh [new file with mode: 0755]
tests/zfs-tests/tests/functional/cli_root/zpool_online/zpool_online_002_neg.ksh [new file with mode: 0755]
tests/zfs-tests/tests/functional/cli_root/zpool_remove/Makefile.am [new file with mode: 0644]
tests/zfs-tests/tests/functional/cli_root/zpool_remove/cleanup.ksh [new file with mode: 0755]
tests/zfs-tests/tests/functional/cli_root/zpool_remove/setup.ksh [new file with mode: 0755]
tests/zfs-tests/tests/functional/cli_root/zpool_remove/zpool_remove.cfg [new file with mode: 0644]
tests/zfs-tests/tests/functional/cli_root/zpool_remove/zpool_remove_001_neg.ksh [new file with mode: 0755]
tests/zfs-tests/tests/functional/cli_root/zpool_remove/zpool_remove_002_pos.ksh [new file with mode: 0755]
tests/zfs-tests/tests/functional/cli_root/zpool_remove/zpool_remove_003_pos.ksh [new file with mode: 0755]
tests/zfs-tests/tests/functional/cli_root/zpool_replace/Makefile.am [new file with mode: 0644]
tests/zfs-tests/tests/functional/cli_root/zpool_replace/cleanup.ksh [new file with mode: 0755]
tests/zfs-tests/tests/functional/cli_root/zpool_replace/setup.ksh [new file with mode: 0755]
tests/zfs-tests/tests/functional/cli_root/zpool_replace/zpool_replace_001_neg.ksh [new file with mode: 0755]
tests/zfs-tests/tests/functional/cli_root/zpool_scrub/Makefile.am [new file with mode: 0644]
tests/zfs-tests/tests/functional/cli_root/zpool_scrub/cleanup.ksh [new file with mode: 0755]
tests/zfs-tests/tests/functional/cli_root/zpool_scrub/setup.ksh [new file with mode: 0755]
tests/zfs-tests/tests/functional/cli_root/zpool_scrub/zpool_scrub.cfg [new file with mode: 0644]
tests/zfs-tests/tests/functional/cli_root/zpool_scrub/zpool_scrub_001_neg.ksh [new file with mode: 0755]
tests/zfs-tests/tests/functional/cli_root/zpool_scrub/zpool_scrub_002_pos.ksh [new file with mode: 0755]
tests/zfs-tests/tests/functional/cli_root/zpool_scrub/zpool_scrub_003_pos.ksh [new file with mode: 0755]
tests/zfs-tests/tests/functional/cli_root/zpool_scrub/zpool_scrub_004_pos.ksh [new file with mode: 0755]
tests/zfs-tests/tests/functional/cli_root/zpool_scrub/zpool_scrub_005_pos.ksh [new file with mode: 0755]
tests/zfs-tests/tests/functional/cli_root/zpool_set/Makefile.am [new file with mode: 0644]
tests/zfs-tests/tests/functional/cli_root/zpool_set/zpool_set_001_pos.ksh [new file with mode: 0755]
tests/zfs-tests/tests/functional/cli_root/zpool_set/zpool_set_002_neg.ksh [new file with mode: 0755]
tests/zfs-tests/tests/functional/cli_root/zpool_set/zpool_set_003_neg.ksh [new file with mode: 0755]
tests/zfs-tests/tests/functional/cli_root/zpool_status/Makefile.am [new file with mode: 0644]
tests/zfs-tests/tests/functional/cli_root/zpool_status/cleanup.ksh [new file with mode: 0755]
tests/zfs-tests/tests/functional/cli_root/zpool_status/setup.ksh [new file with mode: 0755]
tests/zfs-tests/tests/functional/cli_root/zpool_status/zpool_status_001_pos.ksh [new file with mode: 0755]
tests/zfs-tests/tests/functional/cli_root/zpool_status/zpool_status_002_pos.ksh [new file with mode: 0755]
tests/zfs-tests/tests/functional/cli_root/zpool_upgrade/Makefile.am [new file with mode: 0644]
tests/zfs-tests/tests/functional/cli_root/zpool_upgrade/cleanup.ksh [new file with mode: 0755]
tests/zfs-tests/tests/functional/cli_root/zpool_upgrade/setup.ksh [new file with mode: 0755]
tests/zfs-tests/tests/functional/cli_root/zpool_upgrade/zfs-broken-mirror1.dat.bz2 [new file with mode: 0644]
tests/zfs-tests/tests/functional/cli_root/zpool_upgrade/zfs-broken-mirror2.dat.bz2 [new file with mode: 0644]
tests/zfs-tests/tests/functional/cli_root/zpool_upgrade/zfs-pool-v1.dat.bz2 [new file with mode: 0644]
tests/zfs-tests/tests/functional/cli_root/zpool_upgrade/zfs-pool-v10.dat.bz2 [new file with mode: 0644]
tests/zfs-tests/tests/functional/cli_root/zpool_upgrade/zfs-pool-v11.dat.bz2 [new file with mode: 0644]
tests/zfs-tests/tests/functional/cli_root/zpool_upgrade/zfs-pool-v12.dat.bz2 [new file with mode: 0644]
tests/zfs-tests/tests/functional/cli_root/zpool_upgrade/zfs-pool-v13.dat.bz2 [new file with mode: 0644]
tests/zfs-tests/tests/functional/cli_root/zpool_upgrade/zfs-pool-v14.dat.bz2 [new file with mode: 0644]
tests/zfs-tests/tests/functional/cli_root/zpool_upgrade/zfs-pool-v15.dat.bz2 [new file with mode: 0644]
tests/zfs-tests/tests/functional/cli_root/zpool_upgrade/zfs-pool-v1mirror1.dat.bz2 [new file with mode: 0644]
tests/zfs-tests/tests/functional/cli_root/zpool_upgrade/zfs-pool-v1mirror2.dat.bz2 [new file with mode: 0644]
tests/zfs-tests/tests/functional/cli_root/zpool_upgrade/zfs-pool-v1mirror3.dat.bz2 [new file with mode: 0644]
tests/zfs-tests/tests/functional/cli_root/zpool_upgrade/zfs-pool-v1raidz1.dat.bz2 [new file with mode: 0644]
tests/zfs-tests/tests/functional/cli_root/zpool_upgrade/zfs-pool-v1raidz2.dat.bz2 [new file with mode: 0644]
tests/zfs-tests/tests/functional/cli_root/zpool_upgrade/zfs-pool-v1raidz3.dat.bz2 [new file with mode: 0644]
tests/zfs-tests/tests/functional/cli_root/zpool_upgrade/zfs-pool-v1stripe1.dat.bz2 [new file with mode: 0644]
tests/zfs-tests/tests/functional/cli_root/zpool_upgrade/zfs-pool-v1stripe2.dat.bz2 [new file with mode: 0644]
tests/zfs-tests/tests/functional/cli_root/zpool_upgrade/zfs-pool-v1stripe3.dat.bz2 [new file with mode: 0644]
tests/zfs-tests/tests/functional/cli_root/zpool_upgrade/zfs-pool-v2.dat.bz2 [new file with mode: 0644]
tests/zfs-tests/tests/functional/cli_root/zpool_upgrade/zfs-pool-v2mirror1.dat.bz2 [new file with mode: 0644]
tests/zfs-tests/tests/functional/cli_root/zpool_upgrade/zfs-pool-v2mirror2.dat.bz2 [new file with mode: 0644]
tests/zfs-tests/tests/functional/cli_root/zpool_upgrade/zfs-pool-v2mirror3.dat.bz2 [new file with mode: 0644]
tests/zfs-tests/tests/functional/cli_root/zpool_upgrade/zfs-pool-v2raidz1.dat.bz2 [new file with mode: 0644]
tests/zfs-tests/tests/functional/cli_root/zpool_upgrade/zfs-pool-v2raidz2.dat.bz2 [new file with mode: 0644]
tests/zfs-tests/tests/functional/cli_root/zpool_upgrade/zfs-pool-v2raidz3.dat.bz2 [new file with mode: 0644]
tests/zfs-tests/tests/functional/cli_root/zpool_upgrade/zfs-pool-v2stripe1.dat.bz2 [new file with mode: 0644]
tests/zfs-tests/tests/functional/cli_root/zpool_upgrade/zfs-pool-v2stripe2.dat.bz2 [new file with mode: 0644]
tests/zfs-tests/tests/functional/cli_root/zpool_upgrade/zfs-pool-v2stripe3.dat.bz2 [new file with mode: 0644]
tests/zfs-tests/tests/functional/cli_root/zpool_upgrade/zfs-pool-v3.dat.bz2 [new file with mode: 0644]
tests/zfs-tests/tests/functional/cli_root/zpool_upgrade/zfs-pool-v3hotspare1.dat.bz2 [new file with mode: 0644]
tests/zfs-tests/tests/functional/cli_root/zpool_upgrade/zfs-pool-v3hotspare2.dat.bz2 [new file with mode: 0644]
tests/zfs-tests/tests/functional/cli_root/zpool_upgrade/zfs-pool-v3hotspare3.dat.bz2 [new file with mode: 0644]
tests/zfs-tests/tests/functional/cli_root/zpool_upgrade/zfs-pool-v3mirror1.dat.bz2 [new file with mode: 0644]
tests/zfs-tests/tests/functional/cli_root/zpool_upgrade/zfs-pool-v3mirror2.dat.bz2 [new file with mode: 0644]
tests/zfs-tests/tests/functional/cli_root/zpool_upgrade/zfs-pool-v3mirror3.dat.bz2 [new file with mode: 0644]
tests/zfs-tests/tests/functional/cli_root/zpool_upgrade/zfs-pool-v3raidz1.dat.bz2 [new file with mode: 0644]
tests/zfs-tests/tests/functional/cli_root/zpool_upgrade/zfs-pool-v3raidz2.dat.bz2 [new file with mode: 0644]
tests/zfs-tests/tests/functional/cli_root/zpool_upgrade/zfs-pool-v3raidz21.dat.bz2 [new file with mode: 0644]
tests/zfs-tests/tests/functional/cli_root/zpool_upgrade/zfs-pool-v3raidz22.dat.bz2 [new file with mode: 0644]
tests/zfs-tests/tests/functional/cli_root/zpool_upgrade/zfs-pool-v3raidz23.dat.bz2 [new file with mode: 0644]
tests/zfs-tests/tests/functional/cli_root/zpool_upgrade/zfs-pool-v3raidz3.dat.bz2 [new file with mode: 0644]
tests/zfs-tests/tests/functional/cli_root/zpool_upgrade/zfs-pool-v3stripe1.dat.bz2 [new file with mode: 0644]
tests/zfs-tests/tests/functional/cli_root/zpool_upgrade/zfs-pool-v3stripe2.dat.bz2 [new file with mode: 0644]
tests/zfs-tests/tests/functional/cli_root/zpool_upgrade/zfs-pool-v3stripe3.dat.bz2 [new file with mode: 0644]
tests/zfs-tests/tests/functional/cli_root/zpool_upgrade/zfs-pool-v4.dat.bz2 [new file with mode: 0644]
tests/zfs-tests/tests/functional/cli_root/zpool_upgrade/zfs-pool-v5.dat.bz2 [new file with mode: 0644]
tests/zfs-tests/tests/functional/cli_root/zpool_upgrade/zfs-pool-v6.dat.bz2 [new file with mode: 0644]
tests/zfs-tests/tests/functional/cli_root/zpool_upgrade/zfs-pool-v7.dat.bz2 [new file with mode: 0644]
tests/zfs-tests/tests/functional/cli_root/zpool_upgrade/zfs-pool-v8.dat.bz2 [new file with mode: 0644]
tests/zfs-tests/tests/functional/cli_root/zpool_upgrade/zfs-pool-v9.dat.bz2 [new file with mode: 0644]
tests/zfs-tests/tests/functional/cli_root/zpool_upgrade/zfs-pool-v999.dat.bz2 [new file with mode: 0644]
tests/zfs-tests/tests/functional/cli_root/zpool_upgrade/zfs-pool-vBROKEN.dat.bz2 [new file with mode: 0644]
tests/zfs-tests/tests/functional/cli_root/zpool_upgrade/zpool_upgrade.cfg [new file with mode: 0644]
tests/zfs-tests/tests/functional/cli_root/zpool_upgrade/zpool_upgrade.kshlib [new file with mode: 0644]
tests/zfs-tests/tests/functional/cli_root/zpool_upgrade/zpool_upgrade_001_pos.ksh [new file with mode: 0755]
tests/zfs-tests/tests/functional/cli_root/zpool_upgrade/zpool_upgrade_002_pos.ksh [new file with mode: 0755]
tests/zfs-tests/tests/functional/cli_root/zpool_upgrade/zpool_upgrade_003_pos.ksh [new file with mode: 0755]
tests/zfs-tests/tests/functional/cli_root/zpool_upgrade/zpool_upgrade_004_pos.ksh [new file with mode: 0755]
tests/zfs-tests/tests/functional/cli_root/zpool_upgrade/zpool_upgrade_005_neg.ksh [new file with mode: 0755]
tests/zfs-tests/tests/functional/cli_root/zpool_upgrade/zpool_upgrade_006_neg.ksh [new file with mode: 0755]
tests/zfs-tests/tests/functional/cli_root/zpool_upgrade/zpool_upgrade_007_pos.ksh [new file with mode: 0755]
tests/zfs-tests/tests/functional/cli_root/zpool_upgrade/zpool_upgrade_008_pos.ksh [new file with mode: 0755]
tests/zfs-tests/tests/functional/cli_root/zpool_upgrade/zpool_upgrade_009_neg.ksh [new file with mode: 0755]
tests/zfs-tests/tests/functional/cli_user/Makefile.am [new file with mode: 0644]
tests/zfs-tests/tests/functional/cli_user/misc/Makefile.am [new file with mode: 0644]
tests/zfs-tests/tests/functional/cli_user/misc/cleanup.ksh [new file with mode: 0755]
tests/zfs-tests/tests/functional/cli_user/misc/misc.cfg [new file with mode: 0644]
tests/zfs-tests/tests/functional/cli_user/misc/setup.ksh [new file with mode: 0755]
tests/zfs-tests/tests/functional/cli_user/misc/zdb_001_neg.ksh [new file with mode: 0755]
tests/zfs-tests/tests/functional/cli_user/misc/zfs_001_neg.ksh [new file with mode: 0755]
tests/zfs-tests/tests/functional/cli_user/misc/zfs_allow_001_neg.ksh [new file with mode: 0755]
tests/zfs-tests/tests/functional/cli_user/misc/zfs_clone_001_neg.ksh [new file with mode: 0755]
tests/zfs-tests/tests/functional/cli_user/misc/zfs_create_001_neg.ksh [new file with mode: 0755]
tests/zfs-tests/tests/functional/cli_user/misc/zfs_destroy_001_neg.ksh [new file with mode: 0755]
tests/zfs-tests/tests/functional/cli_user/misc/zfs_get_001_neg.ksh [new file with mode: 0755]
tests/zfs-tests/tests/functional/cli_user/misc/zfs_inherit_001_neg.ksh [new file with mode: 0755]
tests/zfs-tests/tests/functional/cli_user/misc/zfs_mount_001_neg.ksh [new file with mode: 0755]
tests/zfs-tests/tests/functional/cli_user/misc/zfs_promote_001_neg.ksh [new file with mode: 0755]
tests/zfs-tests/tests/functional/cli_user/misc/zfs_receive_001_neg.ksh [new file with mode: 0755]
tests/zfs-tests/tests/functional/cli_user/misc/zfs_rename_001_neg.ksh [new file with mode: 0755]
tests/zfs-tests/tests/functional/cli_user/misc/zfs_rollback_001_neg.ksh [new file with mode: 0755]
tests/zfs-tests/tests/functional/cli_user/misc/zfs_send_001_neg.ksh [new file with mode: 0755]
tests/zfs-tests/tests/functional/cli_user/misc/zfs_set_001_neg.ksh [new file with mode: 0755]
tests/zfs-tests/tests/functional/cli_user/misc/zfs_share_001_neg.ksh [new file with mode: 0755]
tests/zfs-tests/tests/functional/cli_user/misc/zfs_snapshot_001_neg.ksh [new file with mode: 0755]
tests/zfs-tests/tests/functional/cli_user/misc/zfs_unallow_001_neg.ksh [new file with mode: 0755]
tests/zfs-tests/tests/functional/cli_user/misc/zfs_unmount_001_neg.ksh [new file with mode: 0755]
tests/zfs-tests/tests/functional/cli_user/misc/zfs_unshare_001_neg.ksh [new file with mode: 0755]
tests/zfs-tests/tests/functional/cli_user/misc/zfs_upgrade_001_neg.ksh [new file with mode: 0755]
tests/zfs-tests/tests/functional/cli_user/misc/zpool_001_neg.ksh [new file with mode: 0755]
tests/zfs-tests/tests/functional/cli_user/misc/zpool_add_001_neg.ksh [new file with mode: 0755]
tests/zfs-tests/tests/functional/cli_user/misc/zpool_attach_001_neg.ksh [new file with mode: 0755]
tests/zfs-tests/tests/functional/cli_user/misc/zpool_clear_001_neg.ksh [new file with mode: 0755]
tests/zfs-tests/tests/functional/cli_user/misc/zpool_create_001_neg.ksh [new file with mode: 0755]
tests/zfs-tests/tests/functional/cli_user/misc/zpool_destroy_001_neg.ksh [new file with mode: 0755]
tests/zfs-tests/tests/functional/cli_user/misc/zpool_detach_001_neg.ksh [new file with mode: 0755]
tests/zfs-tests/tests/functional/cli_user/misc/zpool_export_001_neg.ksh [new file with mode: 0755]
tests/zfs-tests/tests/functional/cli_user/misc/zpool_get_001_neg.ksh [new file with mode: 0755]
tests/zfs-tests/tests/functional/cli_user/misc/zpool_history_001_neg.ksh [new file with mode: 0755]
tests/zfs-tests/tests/functional/cli_user/misc/zpool_import_001_neg.ksh [new file with mode: 0755]
tests/zfs-tests/tests/functional/cli_user/misc/zpool_import_002_neg.ksh [new file with mode: 0755]
tests/zfs-tests/tests/functional/cli_user/misc/zpool_offline_001_neg.ksh [new file with mode: 0755]
tests/zfs-tests/tests/functional/cli_user/misc/zpool_online_001_neg.ksh [new file with mode: 0755]
tests/zfs-tests/tests/functional/cli_user/misc/zpool_remove_001_neg.ksh [new file with mode: 0755]
tests/zfs-tests/tests/functional/cli_user/misc/zpool_replace_001_neg.ksh [new file with mode: 0755]
tests/zfs-tests/tests/functional/cli_user/misc/zpool_scrub_001_neg.ksh [new file with mode: 0755]
tests/zfs-tests/tests/functional/cli_user/misc/zpool_set_001_neg.ksh [new file with mode: 0755]
tests/zfs-tests/tests/functional/cli_user/misc/zpool_status_001_neg.ksh [new file with mode: 0755]
tests/zfs-tests/tests/functional/cli_user/misc/zpool_upgrade_001_neg.ksh [new file with mode: 0755]
tests/zfs-tests/tests/functional/cli_user/zfs_list/Makefile.am [new file with mode: 0644]
tests/zfs-tests/tests/functional/cli_user/zfs_list/cleanup.ksh [new file with mode: 0755]
tests/zfs-tests/tests/functional/cli_user/zfs_list/setup.ksh [new file with mode: 0755]
tests/zfs-tests/tests/functional/cli_user/zfs_list/zfs_list.cfg [new file with mode: 0644]
tests/zfs-tests/tests/functional/cli_user/zfs_list/zfs_list.kshlib [new file with mode: 0644]
tests/zfs-tests/tests/functional/cli_user/zfs_list/zfs_list_001_pos.ksh [new file with mode: 0755]
tests/zfs-tests/tests/functional/cli_user/zfs_list/zfs_list_002_pos.ksh [new file with mode: 0755]
tests/zfs-tests/tests/functional/cli_user/zfs_list/zfs_list_003_pos.ksh [new file with mode: 0755]
tests/zfs-tests/tests/functional/cli_user/zfs_list/zfs_list_004_neg.ksh [new file with mode: 0755]
tests/zfs-tests/tests/functional/cli_user/zfs_list/zfs_list_007_pos.ksh [new file with mode: 0755]
tests/zfs-tests/tests/functional/cli_user/zfs_list/zfs_list_008_neg.ksh [new file with mode: 0755]
tests/zfs-tests/tests/functional/cli_user/zpool_iostat/Makefile.am [new file with mode: 0644]
tests/zfs-tests/tests/functional/cli_user/zpool_iostat/cleanup.ksh [new file with mode: 0755]
tests/zfs-tests/tests/functional/cli_user/zpool_iostat/setup.ksh [new file with mode: 0755]
tests/zfs-tests/tests/functional/cli_user/zpool_iostat/zpool_iostat_001_neg.ksh [new file with mode: 0755]
tests/zfs-tests/tests/functional/cli_user/zpool_iostat/zpool_iostat_002_pos.ksh [new file with mode: 0755]
tests/zfs-tests/tests/functional/cli_user/zpool_iostat/zpool_iostat_003_neg.ksh [new file with mode: 0755]
tests/zfs-tests/tests/functional/cli_user/zpool_list/Makefile.am [new file with mode: 0644]
tests/zfs-tests/tests/functional/cli_user/zpool_list/cleanup.ksh [new file with mode: 0755]
tests/zfs-tests/tests/functional/cli_user/zpool_list/setup.ksh [new file with mode: 0755]
tests/zfs-tests/tests/functional/cli_user/zpool_list/zpool_list_001_pos.ksh [new file with mode: 0755]
tests/zfs-tests/tests/functional/cli_user/zpool_list/zpool_list_002_neg.ksh [new file with mode: 0755]
tests/zfs-tests/tests/functional/compression/Makefile.am [new file with mode: 0644]
tests/zfs-tests/tests/functional/compression/cleanup.ksh [new file with mode: 0755]
tests/zfs-tests/tests/functional/compression/compress.cfg [new file with mode: 0644]
tests/zfs-tests/tests/functional/compression/compress_001_pos.ksh [new file with mode: 0755]
tests/zfs-tests/tests/functional/compression/compress_002_pos.ksh [new file with mode: 0755]
tests/zfs-tests/tests/functional/compression/compress_003_pos.ksh [new file with mode: 0755]
tests/zfs-tests/tests/functional/compression/compress_004_pos.ksh [new file with mode: 0755]
tests/zfs-tests/tests/functional/compression/setup.ksh [new file with mode: 0755]
tests/zfs-tests/tests/functional/ctime/.gitignore [new file with mode: 0644]
tests/zfs-tests/tests/functional/ctime/Makefile.am [new file with mode: 0644]
tests/zfs-tests/tests/functional/ctime/cleanup.ksh [new file with mode: 0755]
tests/zfs-tests/tests/functional/ctime/ctime_001_pos.c [new file with mode: 0644]
tests/zfs-tests/tests/functional/ctime/setup.ksh [new file with mode: 0755]
tests/zfs-tests/tests/functional/delegate/Makefile.am [new file with mode: 0644]
tests/zfs-tests/tests/functional/delegate/cleanup.ksh [new file with mode: 0755]
tests/zfs-tests/tests/functional/delegate/delegate.cfg [new file with mode: 0644]
tests/zfs-tests/tests/functional/delegate/delegate_common.kshlib [new file with mode: 0644]
tests/zfs-tests/tests/functional/delegate/setup.ksh [new file with mode: 0755]
tests/zfs-tests/tests/functional/delegate/zfs_allow_001_pos.ksh [new file with mode: 0755]
tests/zfs-tests/tests/functional/delegate/zfs_allow_002_pos.ksh [new file with mode: 0755]
tests/zfs-tests/tests/functional/delegate/zfs_allow_003_pos.ksh [new file with mode: 0755]
tests/zfs-tests/tests/functional/delegate/zfs_allow_004_pos.ksh [new file with mode: 0755]
tests/zfs-tests/tests/functional/delegate/zfs_allow_005_pos.ksh [new file with mode: 0755]
tests/zfs-tests/tests/functional/delegate/zfs_allow_006_pos.ksh [new file with mode: 0755]
tests/zfs-tests/tests/functional/delegate/zfs_allow_007_pos.ksh [new file with mode: 0755]
tests/zfs-tests/tests/functional/delegate/zfs_allow_008_pos.ksh [new file with mode: 0755]
tests/zfs-tests/tests/functional/delegate/zfs_allow_009_neg.ksh [new file with mode: 0755]
tests/zfs-tests/tests/functional/delegate/zfs_allow_010_pos.ksh [new file with mode: 0755]
tests/zfs-tests/tests/functional/delegate/zfs_allow_011_neg.ksh [new file with mode: 0755]
tests/zfs-tests/tests/functional/delegate/zfs_allow_012_neg.ksh [new file with mode: 0755]
tests/zfs-tests/tests/functional/delegate/zfs_unallow_001_pos.ksh [new file with mode: 0755]
tests/zfs-tests/tests/functional/delegate/zfs_unallow_002_pos.ksh [new file with mode: 0755]
tests/zfs-tests/tests/functional/delegate/zfs_unallow_003_pos.ksh [new file with mode: 0755]
tests/zfs-tests/tests/functional/delegate/zfs_unallow_004_pos.ksh [new file with mode: 0755]
tests/zfs-tests/tests/functional/delegate/zfs_unallow_005_pos.ksh [new file with mode: 0755]
tests/zfs-tests/tests/functional/delegate/zfs_unallow_006_pos.ksh [new file with mode: 0755]
tests/zfs-tests/tests/functional/delegate/zfs_unallow_007_neg.ksh [new file with mode: 0755]
tests/zfs-tests/tests/functional/delegate/zfs_unallow_008_neg.ksh [new file with mode: 0755]
tests/zfs-tests/tests/functional/devices/Makefile.am [new file with mode: 0644]
tests/zfs-tests/tests/functional/devices/cleanup.ksh [new file with mode: 0755]
tests/zfs-tests/tests/functional/devices/devices.cfg [new file with mode: 0644]
tests/zfs-tests/tests/functional/devices/devices_001_pos.ksh [new file with mode: 0755]
tests/zfs-tests/tests/functional/devices/devices_002_neg.ksh [new file with mode: 0755]
tests/zfs-tests/tests/functional/devices/devices_003_pos.ksh [new file with mode: 0755]
tests/zfs-tests/tests/functional/devices/devices_common.kshlib [new file with mode: 0644]
tests/zfs-tests/tests/functional/devices/setup.ksh [new file with mode: 0755]
tests/zfs-tests/tests/functional/exec/.gitignore [new file with mode: 0644]
tests/zfs-tests/tests/functional/exec/Makefile.am [new file with mode: 0644]
tests/zfs-tests/tests/functional/exec/cleanup.ksh [new file with mode: 0755]
tests/zfs-tests/tests/functional/exec/exec_001_pos.ksh [new file with mode: 0755]
tests/zfs-tests/tests/functional/exec/exec_002_neg.ksh [new file with mode: 0755]
tests/zfs-tests/tests/functional/exec/setup.ksh [new file with mode: 0755]
tests/zfs-tests/tests/functional/features/Makefile.am [new file with mode: 0644]
tests/zfs-tests/tests/functional/features/async_destroy/Makefile.am [new file with mode: 0644]
tests/zfs-tests/tests/functional/features/async_destroy/async_destroy_001_pos.ksh [new file with mode: 0755]
tests/zfs-tests/tests/functional/features/async_destroy/cleanup.ksh [new file with mode: 0755]
tests/zfs-tests/tests/functional/features/async_destroy/setup.ksh [new file with mode: 0755]
tests/zfs-tests/tests/functional/grow_pool/Makefile.am [new file with mode: 0644]
tests/zfs-tests/tests/functional/grow_pool/grow_pool.cfg [new file with mode: 0644]
tests/zfs-tests/tests/functional/grow_pool/grow_pool_001_pos.ksh [new file with mode: 0755]
tests/zfs-tests/tests/functional/grow_replicas/Makefile.am [new file with mode: 0644]
tests/zfs-tests/tests/functional/grow_replicas/grow_replicas.cfg [new file with mode: 0644]
tests/zfs-tests/tests/functional/grow_replicas/grow_replicas_001_pos.ksh [new file with mode: 0755]
tests/zfs-tests/tests/functional/history/Makefile.am [new file with mode: 0644]
tests/zfs-tests/tests/functional/history/cleanup.ksh [new file with mode: 0755]
tests/zfs-tests/tests/functional/history/history.cfg [new file with mode: 0644]
tests/zfs-tests/tests/functional/history/history_001_pos.ksh [new file with mode: 0755]
tests/zfs-tests/tests/functional/history/history_002_pos.ksh [new file with mode: 0755]
tests/zfs-tests/tests/functional/history/history_003_pos.ksh [new file with mode: 0755]
tests/zfs-tests/tests/functional/history/history_004_pos.ksh [new file with mode: 0755]
tests/zfs-tests/tests/functional/history/history_005_neg.ksh [new file with mode: 0755]
tests/zfs-tests/tests/functional/history/history_006_neg.ksh [new file with mode: 0755]
tests/zfs-tests/tests/functional/history/history_007_pos.ksh [new file with mode: 0755]
tests/zfs-tests/tests/functional/history/history_008_pos.ksh [new file with mode: 0755]
tests/zfs-tests/tests/functional/history/history_009_pos.ksh [new file with mode: 0755]
tests/zfs-tests/tests/functional/history/history_010_pos.ksh [new file with mode: 0755]
tests/zfs-tests/tests/functional/history/history_common.kshlib [new file with mode: 0644]
tests/zfs-tests/tests/functional/history/i386.migratedpool.DAT.Z [new file with mode: 0644]
tests/zfs-tests/tests/functional/history/i386.orig_history.txt [new file with mode: 0644]
tests/zfs-tests/tests/functional/history/setup.ksh [new file with mode: 0755]
tests/zfs-tests/tests/functional/history/sparc.migratedpool.DAT.Z [new file with mode: 0644]
tests/zfs-tests/tests/functional/history/sparc.orig_history.txt [new file with mode: 0644]
tests/zfs-tests/tests/functional/history/zfs-pool-v4.dat.Z [new file with mode: 0644]
tests/zfs-tests/tests/functional/inheritance/Makefile.am [new file with mode: 0644]
tests/zfs-tests/tests/functional/inheritance/README.config [new file with mode: 0644]
tests/zfs-tests/tests/functional/inheritance/README.state [new file with mode: 0644]
tests/zfs-tests/tests/functional/inheritance/cleanup.ksh [new file with mode: 0755]
tests/zfs-tests/tests/functional/inheritance/config001.cfg [new file with mode: 0644]
tests/zfs-tests/tests/functional/inheritance/config002.cfg [new file with mode: 0644]
tests/zfs-tests/tests/functional/inheritance/config003.cfg [new file with mode: 0644]
tests/zfs-tests/tests/functional/inheritance/config004.cfg [new file with mode: 0644]
tests/zfs-tests/tests/functional/inheritance/config005.cfg [new file with mode: 0644]
tests/zfs-tests/tests/functional/inheritance/config006.cfg [new file with mode: 0644]
tests/zfs-tests/tests/functional/inheritance/config007.cfg [new file with mode: 0644]
tests/zfs-tests/tests/functional/inheritance/config008.cfg [new file with mode: 0644]
tests/zfs-tests/tests/functional/inheritance/config009.cfg [new file with mode: 0644]
tests/zfs-tests/tests/functional/inheritance/config010.cfg [new file with mode: 0644]
tests/zfs-tests/tests/functional/inheritance/config011.cfg [new file with mode: 0644]
tests/zfs-tests/tests/functional/inheritance/config012.cfg [new file with mode: 0644]
tests/zfs-tests/tests/functional/inheritance/config013.cfg [new file with mode: 0644]
tests/zfs-tests/tests/functional/inheritance/config014.cfg [new file with mode: 0644]
tests/zfs-tests/tests/functional/inheritance/config015.cfg [new file with mode: 0644]
tests/zfs-tests/tests/functional/inheritance/config016.cfg [new file with mode: 0644]
tests/zfs-tests/tests/functional/inheritance/config017.cfg [new file with mode: 0644]
tests/zfs-tests/tests/functional/inheritance/config018.cfg [new file with mode: 0644]
tests/zfs-tests/tests/functional/inheritance/config019.cfg [new file with mode: 0644]
tests/zfs-tests/tests/functional/inheritance/config020.cfg [new file with mode: 0644]
tests/zfs-tests/tests/functional/inheritance/config021.cfg [new file with mode: 0644]
tests/zfs-tests/tests/functional/inheritance/config022.cfg [new file with mode: 0644]
tests/zfs-tests/tests/functional/inheritance/config023.cfg [new file with mode: 0644]
tests/zfs-tests/tests/functional/inheritance/config024.cfg [new file with mode: 0644]
tests/zfs-tests/tests/functional/inheritance/inherit.kshlib [new file with mode: 0644]
tests/zfs-tests/tests/functional/inheritance/inherit_001_pos.ksh [new file with mode: 0755]
tests/zfs-tests/tests/functional/inheritance/state001.cfg [new file with mode: 0644]
tests/zfs-tests/tests/functional/inheritance/state002.cfg [new file with mode: 0644]
tests/zfs-tests/tests/functional/inheritance/state003.cfg [new file with mode: 0644]
tests/zfs-tests/tests/functional/inheritance/state004.cfg [new file with mode: 0644]
tests/zfs-tests/tests/functional/inheritance/state005.cfg [new file with mode: 0644]
tests/zfs-tests/tests/functional/inheritance/state006.cfg [new file with mode: 0644]
tests/zfs-tests/tests/functional/inheritance/state007.cfg [new file with mode: 0644]
tests/zfs-tests/tests/functional/inheritance/state008.cfg [new file with mode: 0644]
tests/zfs-tests/tests/functional/inheritance/state009.cfg [new file with mode: 0644]
tests/zfs-tests/tests/functional/inheritance/state010.cfg [new file with mode: 0644]
tests/zfs-tests/tests/functional/inheritance/state011.cfg [new file with mode: 0644]
tests/zfs-tests/tests/functional/inheritance/state012.cfg [new file with mode: 0644]
tests/zfs-tests/tests/functional/inheritance/state013.cfg [new file with mode: 0644]
tests/zfs-tests/tests/functional/inheritance/state014.cfg [new file with mode: 0644]
tests/zfs-tests/tests/functional/inheritance/state015.cfg [new file with mode: 0644]
tests/zfs-tests/tests/functional/inheritance/state016.cfg [new file with mode: 0644]
tests/zfs-tests/tests/functional/inheritance/state017.cfg [new file with mode: 0644]
tests/zfs-tests/tests/functional/inheritance/state018.cfg [new file with mode: 0644]
tests/zfs-tests/tests/functional/inheritance/state019.cfg [new file with mode: 0644]
tests/zfs-tests/tests/functional/inheritance/state020.cfg [new file with mode: 0644]
tests/zfs-tests/tests/functional/inheritance/state021.cfg [new file with mode: 0644]
tests/zfs-tests/tests/functional/inheritance/state022.cfg [new file with mode: 0644]
tests/zfs-tests/tests/functional/inheritance/state023.cfg [new file with mode: 0644]
tests/zfs-tests/tests/functional/inheritance/state024.cfg [new file with mode: 0644]
tests/zfs-tests/tests/functional/inuse/Makefile.am [new file with mode: 0644]
tests/zfs-tests/tests/functional/inuse/inuse.cfg [new file with mode: 0644]
tests/zfs-tests/tests/functional/inuse/inuse_001_pos.ksh [new file with mode: 0755]
tests/zfs-tests/tests/functional/inuse/inuse_003_pos.ksh [new file with mode: 0755]
tests/zfs-tests/tests/functional/inuse/inuse_004_pos.ksh [new file with mode: 0755]
tests/zfs-tests/tests/functional/inuse/inuse_005_pos.ksh [new file with mode: 0755]
tests/zfs-tests/tests/functional/inuse/inuse_006_pos.ksh [new file with mode: 0755]
tests/zfs-tests/tests/functional/inuse/inuse_007_pos.ksh [new file with mode: 0755]
tests/zfs-tests/tests/functional/inuse/inuse_008_pos.ksh [new file with mode: 0755]
tests/zfs-tests/tests/functional/inuse/inuse_009_pos.ksh [new file with mode: 0755]
tests/zfs-tests/tests/functional/inuse/setup.ksh [new file with mode: 0755]
tests/zfs-tests/tests/functional/large_files/Makefile.am [new file with mode: 0644]
tests/zfs-tests/tests/functional/large_files/cleanup.ksh [new file with mode: 0755]
tests/zfs-tests/tests/functional/large_files/large_files_001_pos.ksh [new file with mode: 0755]
tests/zfs-tests/tests/functional/large_files/setup.ksh [new file with mode: 0755]
tests/zfs-tests/tests/functional/largest_pool/Makefile.am [new file with mode: 0644]
tests/zfs-tests/tests/functional/largest_pool/largest_pool.cfg [new file with mode: 0644]
tests/zfs-tests/tests/functional/largest_pool/largest_pool_001_pos.ksh [new file with mode: 0755]
tests/zfs-tests/tests/functional/link_count/Makefile.am [new file with mode: 0644]
tests/zfs-tests/tests/functional/link_count/cleanup.ksh [new file with mode: 0755]
tests/zfs-tests/tests/functional/link_count/link_count_001.ksh [new file with mode: 0755]
tests/zfs-tests/tests/functional/link_count/setup.ksh [new file with mode: 0755]
tests/zfs-tests/tests/functional/migration/Makefile.am [new file with mode: 0644]
tests/zfs-tests/tests/functional/migration/cleanup.ksh [new file with mode: 0755]
tests/zfs-tests/tests/functional/migration/migration.cfg [new file with mode: 0644]
tests/zfs-tests/tests/functional/migration/migration.kshlib [new file with mode: 0644]
tests/zfs-tests/tests/functional/migration/migration_001_pos.ksh [new file with mode: 0755]
tests/zfs-tests/tests/functional/migration/migration_002_pos.ksh [new file with mode: 0755]
tests/zfs-tests/tests/functional/migration/migration_003_pos.ksh [new file with mode: 0755]
tests/zfs-tests/tests/functional/migration/migration_004_pos.ksh [new file with mode: 0755]
tests/zfs-tests/tests/functional/migration/migration_005_pos.ksh [new file with mode: 0755]
tests/zfs-tests/tests/functional/migration/migration_006_pos.ksh [new file with mode: 0755]
tests/zfs-tests/tests/functional/migration/migration_007_pos.ksh [new file with mode: 0755]
tests/zfs-tests/tests/functional/migration/migration_008_pos.ksh [new file with mode: 0755]
tests/zfs-tests/tests/functional/migration/migration_009_pos.ksh [new file with mode: 0755]
tests/zfs-tests/tests/functional/migration/migration_010_pos.ksh [new file with mode: 0755]
tests/zfs-tests/tests/functional/migration/migration_011_pos.ksh [new file with mode: 0755]
tests/zfs-tests/tests/functional/migration/migration_012_pos.ksh [new file with mode: 0755]
tests/zfs-tests/tests/functional/migration/setup.ksh [new file with mode: 0755]
tests/zfs-tests/tests/functional/mmap/Makefile.am [new file with mode: 0644]
tests/zfs-tests/tests/functional/mmap/cleanup.ksh [new file with mode: 0755]
tests/zfs-tests/tests/functional/mmap/mmap_read_001_pos.ksh [new file with mode: 0755]
tests/zfs-tests/tests/functional/mmap/mmap_write_001_pos.ksh [new file with mode: 0755]
tests/zfs-tests/tests/functional/mmap/setup.ksh [new file with mode: 0755]
tests/zfs-tests/tests/functional/mount/Makefile.am [new file with mode: 0644]
tests/zfs-tests/tests/functional/mount/cleanup.ksh [new file with mode: 0755]
tests/zfs-tests/tests/functional/mount/setup.ksh [new file with mode: 0755]
tests/zfs-tests/tests/functional/mount/umount_001.ksh [new file with mode: 0755]
tests/zfs-tests/tests/functional/mount/umountall_001.ksh [new file with mode: 0755]
tests/zfs-tests/tests/functional/mv_files/Makefile.am [new file with mode: 0644]
tests/zfs-tests/tests/functional/mv_files/cleanup.ksh [new file with mode: 0755]
tests/zfs-tests/tests/functional/mv_files/mv_files.cfg [new file with mode: 0644]
tests/zfs-tests/tests/functional/mv_files/mv_files_001_pos.ksh [new file with mode: 0755]
tests/zfs-tests/tests/functional/mv_files/mv_files_002_pos.ksh [new file with mode: 0755]
tests/zfs-tests/tests/functional/mv_files/mv_files_common.kshlib [new file with mode: 0644]
tests/zfs-tests/tests/functional/mv_files/setup.ksh [new file with mode: 0755]
tests/zfs-tests/tests/functional/nestedfs/Makefile.am [new file with mode: 0644]
tests/zfs-tests/tests/functional/nestedfs/cleanup.ksh [new file with mode: 0755]
tests/zfs-tests/tests/functional/nestedfs/nestedfs_001_pos.ksh [new file with mode: 0755]
tests/zfs-tests/tests/functional/nestedfs/setup.ksh [new file with mode: 0755]
tests/zfs-tests/tests/functional/no_space/Makefile.am [new file with mode: 0644]
tests/zfs-tests/tests/functional/no_space/cleanup.ksh [new file with mode: 0755]
tests/zfs-tests/tests/functional/no_space/enospc.cfg [new file with mode: 0644]
tests/zfs-tests/tests/functional/no_space/enospc_001_pos.ksh [new file with mode: 0755]
tests/zfs-tests/tests/functional/no_space/enospc_002_pos.ksh [new file with mode: 0644]
tests/zfs-tests/tests/functional/no_space/setup.ksh [new file with mode: 0755]
tests/zfs-tests/tests/functional/nopwrite/Makefile.am [new file with mode: 0644]
tests/zfs-tests/tests/functional/nopwrite/cleanup.ksh [new file with mode: 0755]
tests/zfs-tests/tests/functional/nopwrite/nopwrite.shlib [new file with mode: 0644]
tests/zfs-tests/tests/functional/nopwrite/nopwrite_copies.ksh [new file with mode: 0755]
tests/zfs-tests/tests/functional/nopwrite/nopwrite_mtime.ksh [new file with mode: 0755]
tests/zfs-tests/tests/functional/nopwrite/nopwrite_negative.ksh [new file with mode: 0755]
tests/zfs-tests/tests/functional/nopwrite/nopwrite_promoted_clone.ksh [new file with mode: 0755]
tests/zfs-tests/tests/functional/nopwrite/nopwrite_recsize.ksh [new file with mode: 0755]
tests/zfs-tests/tests/functional/nopwrite/nopwrite_sync.ksh [new file with mode: 0755]
tests/zfs-tests/tests/functional/nopwrite/nopwrite_varying_compression.ksh [new file with mode: 0755]
tests/zfs-tests/tests/functional/nopwrite/nopwrite_volume.ksh [new file with mode: 0755]
tests/zfs-tests/tests/functional/nopwrite/setup.ksh [new file with mode: 0755]
tests/zfs-tests/tests/functional/online_offline/Makefile.am [new file with mode: 0644]
tests/zfs-tests/tests/functional/online_offline/cleanup.ksh [new file with mode: 0755]
tests/zfs-tests/tests/functional/online_offline/online_offline.cfg [new file with mode: 0644]
tests/zfs-tests/tests/functional/online_offline/online_offline_001_pos.ksh [new file with mode: 0755]
tests/zfs-tests/tests/functional/online_offline/online_offline_002_neg.ksh [new file with mode: 0755]
tests/zfs-tests/tests/functional/online_offline/online_offline_003_neg.ksh [new file with mode: 0755]
tests/zfs-tests/tests/functional/online_offline/setup.ksh [new file with mode: 0755]
tests/zfs-tests/tests/functional/pool_names/Makefile.am [new file with mode: 0644]
tests/zfs-tests/tests/functional/pool_names/pool_names_001_pos.ksh [new file with mode: 0755]
tests/zfs-tests/tests/functional/pool_names/pool_names_002_neg.ksh [new file with mode: 0755]
tests/zfs-tests/tests/functional/poolversion/Makefile.am [new file with mode: 0644]
tests/zfs-tests/tests/functional/poolversion/cleanup.ksh [new file with mode: 0755]
tests/zfs-tests/tests/functional/poolversion/poolversion_001_pos.ksh [new file with mode: 0755]
tests/zfs-tests/tests/functional/poolversion/poolversion_002_pos.ksh [new file with mode: 0755]
tests/zfs-tests/tests/functional/poolversion/setup.ksh [new file with mode: 0755]
tests/zfs-tests/tests/functional/privilege/Makefile.am [new file with mode: 0644]
tests/zfs-tests/tests/functional/privilege/cleanup.ksh [new file with mode: 0755]
tests/zfs-tests/tests/functional/privilege/privilege_001_pos.ksh [new file with mode: 0755]
tests/zfs-tests/tests/functional/privilege/privilege_002_pos.ksh [new file with mode: 0755]
tests/zfs-tests/tests/functional/privilege/setup.ksh [new file with mode: 0755]
tests/zfs-tests/tests/functional/quota/Makefile.am [new file with mode: 0644]
tests/zfs-tests/tests/functional/quota/cleanup.ksh [new file with mode: 0755]
tests/zfs-tests/tests/functional/quota/quota.cfg [new file with mode: 0644]
tests/zfs-tests/tests/functional/quota/quota.kshlib [new file with mode: 0644]
tests/zfs-tests/tests/functional/quota/quota_001_pos.ksh [new file with mode: 0755]
tests/zfs-tests/tests/functional/quota/quota_002_pos.ksh [new file with mode: 0755]
tests/zfs-tests/tests/functional/quota/quota_003_pos.ksh [new file with mode: 0755]
tests/zfs-tests/tests/functional/quota/quota_004_pos.ksh [new file with mode: 0755]
tests/zfs-tests/tests/functional/quota/quota_005_pos.ksh [new file with mode: 0755]
tests/zfs-tests/tests/functional/quota/quota_006_neg.ksh [new file with mode: 0755]
tests/zfs-tests/tests/functional/quota/setup.ksh [new file with mode: 0755]
tests/zfs-tests/tests/functional/redundancy/Makefile.am [new file with mode: 0644]
tests/zfs-tests/tests/functional/redundancy/cleanup.ksh [new file with mode: 0755]
tests/zfs-tests/tests/functional/redundancy/redundancy.cfg [new file with mode: 0644]
tests/zfs-tests/tests/functional/redundancy/redundancy.kshlib [new file with mode: 0644]
tests/zfs-tests/tests/functional/redundancy/redundancy_001_pos.ksh [new file with mode: 0755]
tests/zfs-tests/tests/functional/redundancy/redundancy_002_pos.ksh [new file with mode: 0755]
tests/zfs-tests/tests/functional/redundancy/redundancy_003_pos.ksh [new file with mode: 0755]
tests/zfs-tests/tests/functional/redundancy/redundancy_004_neg.ksh [new file with mode: 0755]
tests/zfs-tests/tests/functional/redundancy/setup.ksh [new file with mode: 0755]
tests/zfs-tests/tests/functional/refquota/Makefile.am [new file with mode: 0644]
tests/zfs-tests/tests/functional/refquota/cleanup.ksh [new file with mode: 0755]
tests/zfs-tests/tests/functional/refquota/refquota_001_pos.ksh [new file with mode: 0755]
tests/zfs-tests/tests/functional/refquota/refquota_002_pos.ksh [new file with mode: 0755]
tests/zfs-tests/tests/functional/refquota/refquota_003_pos.ksh [new file with mode: 0755]
tests/zfs-tests/tests/functional/refquota/refquota_004_pos.ksh [new file with mode: 0755]
tests/zfs-tests/tests/functional/refquota/refquota_005_pos.ksh [new file with mode: 0755]
tests/zfs-tests/tests/functional/refquota/refquota_006_neg.ksh [new file with mode: 0755]
tests/zfs-tests/tests/functional/refquota/setup.ksh [new file with mode: 0755]
tests/zfs-tests/tests/functional/refreserv/Makefile.am [new file with mode: 0644]
tests/zfs-tests/tests/functional/refreserv/cleanup.ksh [new file with mode: 0755]
tests/zfs-tests/tests/functional/refreserv/refreserv.cfg [new file with mode: 0644]
tests/zfs-tests/tests/functional/refreserv/refreserv_001_pos.ksh [new file with mode: 0755]
tests/zfs-tests/tests/functional/refreserv/refreserv_002_pos.ksh [new file with mode: 0755]
tests/zfs-tests/tests/functional/refreserv/refreserv_003_pos.ksh [new file with mode: 0755]
tests/zfs-tests/tests/functional/refreserv/refreserv_004_pos.ksh [new file with mode: 0755]
tests/zfs-tests/tests/functional/refreserv/refreserv_005_pos.ksh [new file with mode: 0755]
tests/zfs-tests/tests/functional/refreserv/setup.ksh [new file with mode: 0755]
tests/zfs-tests/tests/functional/rename_dirs/Makefile.am [new file with mode: 0644]
tests/zfs-tests/tests/functional/rename_dirs/cleanup.ksh [new file with mode: 0755]
tests/zfs-tests/tests/functional/rename_dirs/rename_dirs_001_pos.ksh [new file with mode: 0755]
tests/zfs-tests/tests/functional/rename_dirs/setup.ksh [new file with mode: 0755]
tests/zfs-tests/tests/functional/replacement/Makefile.am [new file with mode: 0644]
tests/zfs-tests/tests/functional/replacement/cleanup.ksh [new file with mode: 0755]
tests/zfs-tests/tests/functional/replacement/replacement.cfg [new file with mode: 0644]
tests/zfs-tests/tests/functional/replacement/replacement_001_pos.ksh [new file with mode: 0755]
tests/zfs-tests/tests/functional/replacement/replacement_002_pos.ksh [new file with mode: 0755]
tests/zfs-tests/tests/functional/replacement/replacement_003_pos.ksh [new file with mode: 0755]
tests/zfs-tests/tests/functional/replacement/setup.ksh [new file with mode: 0755]
tests/zfs-tests/tests/functional/reservation/Makefile.am [new file with mode: 0644]
tests/zfs-tests/tests/functional/reservation/cleanup.ksh [new file with mode: 0755]
tests/zfs-tests/tests/functional/reservation/reservation.cfg [new file with mode: 0644]
tests/zfs-tests/tests/functional/reservation/reservation.shlib [new file with mode: 0644]
tests/zfs-tests/tests/functional/reservation/reservation_001_pos.sh [new file with mode: 0755]
tests/zfs-tests/tests/functional/reservation/reservation_002_pos.sh [new file with mode: 0755]
tests/zfs-tests/tests/functional/reservation/reservation_003_pos.sh [new file with mode: 0755]
tests/zfs-tests/tests/functional/reservation/reservation_004_pos.sh [new file with mode: 0755]
tests/zfs-tests/tests/functional/reservation/reservation_005_pos.sh [new file with mode: 0755]
tests/zfs-tests/tests/functional/reservation/reservation_006_pos.sh [new file with mode: 0755]
tests/zfs-tests/tests/functional/reservation/reservation_007_pos.sh [new file with mode: 0755]
tests/zfs-tests/tests/functional/reservation/reservation_008_pos.sh [new file with mode: 0755]
tests/zfs-tests/tests/functional/reservation/reservation_009_pos.sh [new file with mode: 0755]
tests/zfs-tests/tests/functional/reservation/reservation_010_pos.sh [new file with mode: 0755]
tests/zfs-tests/tests/functional/reservation/reservation_011_pos.sh [new file with mode: 0755]
tests/zfs-tests/tests/functional/reservation/reservation_012_pos.sh [new file with mode: 0755]
tests/zfs-tests/tests/functional/reservation/reservation_013_pos.sh [new file with mode: 0755]
tests/zfs-tests/tests/functional/reservation/reservation_014_pos.sh [new file with mode: 0755]
tests/zfs-tests/tests/functional/reservation/reservation_015_pos.sh [new file with mode: 0755]
tests/zfs-tests/tests/functional/reservation/reservation_016_pos.sh [new file with mode: 0755]
tests/zfs-tests/tests/functional/reservation/reservation_017_pos.sh [new file with mode: 0755]
tests/zfs-tests/tests/functional/reservation/reservation_018_pos.sh [new file with mode: 0755]
tests/zfs-tests/tests/functional/reservation/setup.ksh [new file with mode: 0755]
tests/zfs-tests/tests/functional/rootpool/Makefile.am [new file with mode: 0644]
tests/zfs-tests/tests/functional/rootpool/cleanup.ksh [new file with mode: 0755]
tests/zfs-tests/tests/functional/rootpool/rootpool_002_neg.ksh [new file with mode: 0755]
tests/zfs-tests/tests/functional/rootpool/rootpool_003_neg.ksh [new file with mode: 0755]
tests/zfs-tests/tests/functional/rootpool/rootpool_007_neg.ksh [new file with mode: 0755]
tests/zfs-tests/tests/functional/rootpool/setup.ksh [new file with mode: 0755]
tests/zfs-tests/tests/functional/rsend/Makefile.am [new file with mode: 0644]
tests/zfs-tests/tests/functional/rsend/cleanup.ksh [new file with mode: 0755]
tests/zfs-tests/tests/functional/rsend/rsend.cfg [new file with mode: 0644]
tests/zfs-tests/tests/functional/rsend/rsend.kshlib [new file with mode: 0644]
tests/zfs-tests/tests/functional/rsend/rsend_001_pos.ksh [new file with mode: 0755]
tests/zfs-tests/tests/functional/rsend/rsend_002_pos.ksh [new file with mode: 0755]
tests/zfs-tests/tests/functional/rsend/rsend_003_pos.ksh [new file with mode: 0755]
tests/zfs-tests/tests/functional/rsend/rsend_004_pos.ksh [new file with mode: 0755]
tests/zfs-tests/tests/functional/rsend/rsend_005_pos.ksh [new file with mode: 0755]
tests/zfs-tests/tests/functional/rsend/rsend_006_pos.ksh [new file with mode: 0755]
tests/zfs-tests/tests/functional/rsend/rsend_007_pos.ksh [new file with mode: 0755]
tests/zfs-tests/tests/functional/rsend/rsend_008_pos.ksh [new file with mode: 0755]
tests/zfs-tests/tests/functional/rsend/rsend_009_pos.ksh [new file with mode: 0755]
tests/zfs-tests/tests/functional/rsend/rsend_010_pos.ksh [new file with mode: 0755]
tests/zfs-tests/tests/functional/rsend/rsend_011_pos.ksh [new file with mode: 0755]
tests/zfs-tests/tests/functional/rsend/rsend_012_pos.ksh [new file with mode: 0755]
tests/zfs-tests/tests/functional/rsend/rsend_013_pos.ksh [new file with mode: 0755]
tests/zfs-tests/tests/functional/rsend/rsend_014_pos.ksh [new file with mode: 0644]
tests/zfs-tests/tests/functional/rsend/rsend_019_pos.ksh [new file with mode: 0644]
tests/zfs-tests/tests/functional/rsend/rsend_020_pos.ksh [new file with mode: 0644]
tests/zfs-tests/tests/functional/rsend/rsend_021_pos.ksh [new file with mode: 0644]
tests/zfs-tests/tests/functional/rsend/rsend_022_pos.ksh [new file with mode: 0644]
tests/zfs-tests/tests/functional/rsend/rsend_024_pos.ksh [new file with mode: 0644]
tests/zfs-tests/tests/functional/rsend/setup.ksh [new file with mode: 0755]
tests/zfs-tests/tests/functional/scrub_mirror/Makefile.am [new file with mode: 0644]
tests/zfs-tests/tests/functional/scrub_mirror/cleanup.ksh [new file with mode: 0755]
tests/zfs-tests/tests/functional/scrub_mirror/default.cfg [new file with mode: 0644]
tests/zfs-tests/tests/functional/scrub_mirror/scrub_mirror_001_pos.ksh [new file with mode: 0755]
tests/zfs-tests/tests/functional/scrub_mirror/scrub_mirror_002_pos.ksh [new file with mode: 0755]
tests/zfs-tests/tests/functional/scrub_mirror/scrub_mirror_003_pos.ksh [new file with mode: 0755]
tests/zfs-tests/tests/functional/scrub_mirror/scrub_mirror_004_pos.ksh [new file with mode: 0755]
tests/zfs-tests/tests/functional/scrub_mirror/scrub_mirror_common.kshlib [new file with mode: 0644]
tests/zfs-tests/tests/functional/scrub_mirror/setup.ksh [new file with mode: 0755]
tests/zfs-tests/tests/functional/slog/Makefile.am [new file with mode: 0644]
tests/zfs-tests/tests/functional/slog/cleanup.ksh [new file with mode: 0755]
tests/zfs-tests/tests/functional/slog/setup.ksh [new file with mode: 0755]
tests/zfs-tests/tests/functional/slog/slog.cfg [new file with mode: 0644]
tests/zfs-tests/tests/functional/slog/slog.kshlib [new file with mode: 0644]
tests/zfs-tests/tests/functional/slog/slog_001_pos.ksh [new file with mode: 0755]
tests/zfs-tests/tests/functional/slog/slog_002_pos.ksh [new file with mode: 0755]
tests/zfs-tests/tests/functional/slog/slog_003_pos.ksh [new file with mode: 0755]
tests/zfs-tests/tests/functional/slog/slog_004_pos.ksh [new file with mode: 0755]
tests/zfs-tests/tests/functional/slog/slog_005_pos.ksh [new file with mode: 0755]
tests/zfs-tests/tests/functional/slog/slog_006_pos.ksh [new file with mode: 0755]
tests/zfs-tests/tests/functional/slog/slog_007_pos.ksh [new file with mode: 0755]
tests/zfs-tests/tests/functional/slog/slog_008_neg.ksh [new file with mode: 0755]
tests/zfs-tests/tests/functional/slog/slog_009_neg.ksh [new file with mode: 0755]
tests/zfs-tests/tests/functional/slog/slog_010_neg.ksh [new file with mode: 0755]
tests/zfs-tests/tests/functional/slog/slog_011_neg.ksh [new file with mode: 0755]
tests/zfs-tests/tests/functional/slog/slog_012_neg.ksh [new file with mode: 0755]
tests/zfs-tests/tests/functional/slog/slog_013_pos.ksh [new file with mode: 0755]
tests/zfs-tests/tests/functional/slog/slog_014_pos.ksh [new file with mode: 0755]
tests/zfs-tests/tests/functional/snapshot/Makefile.am [new file with mode: 0644]
tests/zfs-tests/tests/functional/snapshot/cleanup.ksh [new file with mode: 0755]
tests/zfs-tests/tests/functional/snapshot/clone_001_pos.ksh [new file with mode: 0755]
tests/zfs-tests/tests/functional/snapshot/rollback_001_pos.ksh [new file with mode: 0755]
tests/zfs-tests/tests/functional/snapshot/rollback_002_pos.ksh [new file with mode: 0755]
tests/zfs-tests/tests/functional/snapshot/rollback_003_pos.ksh [new file with mode: 0755]
tests/zfs-tests/tests/functional/snapshot/setup.ksh [new file with mode: 0755]
tests/zfs-tests/tests/functional/snapshot/snapshot.cfg [new file with mode: 0644]
tests/zfs-tests/tests/functional/snapshot/snapshot_001_pos.ksh [new file with mode: 0755]
tests/zfs-tests/tests/functional/snapshot/snapshot_002_pos.ksh [new file with mode: 0755]
tests/zfs-tests/tests/functional/snapshot/snapshot_003_pos.ksh [new file with mode: 0755]
tests/zfs-tests/tests/functional/snapshot/snapshot_004_pos.ksh [new file with mode: 0755]
tests/zfs-tests/tests/functional/snapshot/snapshot_005_pos.ksh [new file with mode: 0755]
tests/zfs-tests/tests/functional/snapshot/snapshot_006_pos.ksh [new file with mode: 0755]
tests/zfs-tests/tests/functional/snapshot/snapshot_007_pos.ksh [new file with mode: 0755]
tests/zfs-tests/tests/functional/snapshot/snapshot_008_pos.ksh [new file with mode: 0755]
tests/zfs-tests/tests/functional/snapshot/snapshot_009_pos.ksh [new file with mode: 0755]
tests/zfs-tests/tests/functional/snapshot/snapshot_010_pos.ksh [new file with mode: 0755]
tests/zfs-tests/tests/functional/snapshot/snapshot_011_pos.ksh [new file with mode: 0755]
tests/zfs-tests/tests/functional/snapshot/snapshot_012_pos.ksh [new file with mode: 0755]
tests/zfs-tests/tests/functional/snapshot/snapshot_013_pos.ksh [new file with mode: 0755]
tests/zfs-tests/tests/functional/snapshot/snapshot_014_pos.ksh [new file with mode: 0755]
tests/zfs-tests/tests/functional/snapshot/snapshot_015_pos.ksh [new file with mode: 0755]
tests/zfs-tests/tests/functional/snapshot/snapshot_016_pos.ksh [new file with mode: 0755]
tests/zfs-tests/tests/functional/snapshot/snapshot_017_pos.ksh [new file with mode: 0755]
tests/zfs-tests/tests/functional/snapused/Makefile.am [new file with mode: 0644]
tests/zfs-tests/tests/functional/snapused/cleanup.ksh [new file with mode: 0755]
tests/zfs-tests/tests/functional/snapused/setup.ksh [new file with mode: 0755]
tests/zfs-tests/tests/functional/snapused/snapused.kshlib [new file with mode: 0644]
tests/zfs-tests/tests/functional/snapused/snapused_001_pos.ksh [new file with mode: 0755]
tests/zfs-tests/tests/functional/snapused/snapused_002_pos.ksh [new file with mode: 0755]
tests/zfs-tests/tests/functional/snapused/snapused_003_pos.ksh [new file with mode: 0755]
tests/zfs-tests/tests/functional/snapused/snapused_004_pos.ksh [new file with mode: 0755]
tests/zfs-tests/tests/functional/snapused/snapused_005_pos.ksh [new file with mode: 0755]
tests/zfs-tests/tests/functional/sparse/Makefile.am [new file with mode: 0644]
tests/zfs-tests/tests/functional/sparse/cleanup.ksh [new file with mode: 0755]
tests/zfs-tests/tests/functional/sparse/setup.ksh [new file with mode: 0755]
tests/zfs-tests/tests/functional/sparse/sparse.cfg [new file with mode: 0644]
tests/zfs-tests/tests/functional/sparse/sparse_001_pos.ksh [new file with mode: 0755]
tests/zfs-tests/tests/functional/threadsappend/.gitignore [new file with mode: 0644]
tests/zfs-tests/tests/functional/threadsappend/Makefile.am [new file with mode: 0644]
tests/zfs-tests/tests/functional/threadsappend/cleanup.ksh [new file with mode: 0755]
tests/zfs-tests/tests/functional/threadsappend/setup.ksh [new file with mode: 0755]
tests/zfs-tests/tests/functional/threadsappend/threadsappend_001_pos.ksh [new file with mode: 0755]
tests/zfs-tests/tests/functional/truncate/Makefile.am [new file with mode: 0644]
tests/zfs-tests/tests/functional/truncate/cleanup.ksh [new file with mode: 0755]
tests/zfs-tests/tests/functional/truncate/setup.ksh [new file with mode: 0755]
tests/zfs-tests/tests/functional/truncate/truncate.cfg [new file with mode: 0644]
tests/zfs-tests/tests/functional/truncate/truncate_001_pos.ksh [new file with mode: 0755]
tests/zfs-tests/tests/functional/truncate/truncate_002_pos.ksh [new file with mode: 0755]
tests/zfs-tests/tests/functional/userquota/Makefile.am [new file with mode: 0644]
tests/zfs-tests/tests/functional/userquota/cleanup.ksh [new file with mode: 0755]
tests/zfs-tests/tests/functional/userquota/groupspace_001_pos.ksh [new file with mode: 0755]
tests/zfs-tests/tests/functional/userquota/groupspace_002_pos.ksh [new file with mode: 0755]
tests/zfs-tests/tests/functional/userquota/setup.ksh [new file with mode: 0755]
tests/zfs-tests/tests/functional/userquota/userquota.cfg [new file with mode: 0644]
tests/zfs-tests/tests/functional/userquota/userquota_001_pos.ksh [new file with mode: 0755]
tests/zfs-tests/tests/functional/userquota/userquota_002_pos.ksh [new file with mode: 0755]
tests/zfs-tests/tests/functional/userquota/userquota_003_pos.ksh [new file with mode: 0755]
tests/zfs-tests/tests/functional/userquota/userquota_004_pos.ksh [new file with mode: 0755]
tests/zfs-tests/tests/functional/userquota/userquota_005_neg.ksh [new file with mode: 0755]
tests/zfs-tests/tests/functional/userquota/userquota_006_pos.ksh [new file with mode: 0755]
tests/zfs-tests/tests/functional/userquota/userquota_007_pos.ksh [new file with mode: 0755]
tests/zfs-tests/tests/functional/userquota/userquota_008_pos.ksh [new file with mode: 0755]
tests/zfs-tests/tests/functional/userquota/userquota_009_pos.ksh [new file with mode: 0755]
tests/zfs-tests/tests/functional/userquota/userquota_010_pos.ksh [new file with mode: 0755]
tests/zfs-tests/tests/functional/userquota/userquota_011_pos.ksh [new file with mode: 0755]
tests/zfs-tests/tests/functional/userquota/userquota_012_neg.ksh [new file with mode: 0755]
tests/zfs-tests/tests/functional/userquota/userquota_common.kshlib [new file with mode: 0644]
tests/zfs-tests/tests/functional/userquota/userspace_001_pos.ksh [new file with mode: 0755]
tests/zfs-tests/tests/functional/userquota/userspace_002_pos.ksh [new file with mode: 0755]
tests/zfs-tests/tests/functional/write_dirs/Makefile.am [new file with mode: 0644]
tests/zfs-tests/tests/functional/write_dirs/cleanup.ksh [new file with mode: 0755]
tests/zfs-tests/tests/functional/write_dirs/setup.ksh [new file with mode: 0755]
tests/zfs-tests/tests/functional/write_dirs/write_dirs_001_pos.ksh [new file with mode: 0755]
tests/zfs-tests/tests/functional/write_dirs/write_dirs_002_pos.ksh [new file with mode: 0755]
tests/zfs-tests/tests/functional/xattr/Makefile.am [new file with mode: 0644]
tests/zfs-tests/tests/functional/xattr/cleanup.ksh [new file with mode: 0755]
tests/zfs-tests/tests/functional/xattr/setup.ksh [new file with mode: 0755]
tests/zfs-tests/tests/functional/xattr/xattr_001_pos.ksh [new file with mode: 0755]
tests/zfs-tests/tests/functional/xattr/xattr_002_neg.ksh [new file with mode: 0755]
tests/zfs-tests/tests/functional/xattr/xattr_003_neg.ksh [new file with mode: 0755]
tests/zfs-tests/tests/functional/xattr/xattr_004_pos.ksh [new file with mode: 0755]
tests/zfs-tests/tests/functional/xattr/xattr_005_pos.ksh [new file with mode: 0755]
tests/zfs-tests/tests/functional/xattr/xattr_006_pos.ksh [new file with mode: 0755]
tests/zfs-tests/tests/functional/xattr/xattr_007_neg.ksh [new file with mode: 0755]
tests/zfs-tests/tests/functional/xattr/xattr_008_pos.ksh [new file with mode: 0755]
tests/zfs-tests/tests/functional/xattr/xattr_009_neg.ksh [new file with mode: 0755]
tests/zfs-tests/tests/functional/xattr/xattr_010_neg.ksh [new file with mode: 0755]
tests/zfs-tests/tests/functional/xattr/xattr_011_pos.ksh [new file with mode: 0755]
tests/zfs-tests/tests/functional/xattr/xattr_012_pos.ksh [new file with mode: 0755]
tests/zfs-tests/tests/functional/xattr/xattr_013_pos.ksh [new file with mode: 0755]
tests/zfs-tests/tests/functional/xattr/xattr_common.kshlib [new file with mode: 0644]
tests/zfs-tests/tests/functional/zvol/Makefile.am [new file with mode: 0644]
tests/zfs-tests/tests/functional/zvol/zvol.cfg [new file with mode: 0644]
tests/zfs-tests/tests/functional/zvol/zvol_ENOSPC/Makefile.am [new file with mode: 0644]
tests/zfs-tests/tests/functional/zvol/zvol_ENOSPC/cleanup.ksh [new file with mode: 0755]
tests/zfs-tests/tests/functional/zvol/zvol_ENOSPC/setup.ksh [new file with mode: 0755]
tests/zfs-tests/tests/functional/zvol/zvol_ENOSPC/zvol_ENOSPC_001_pos.ksh [new file with mode: 0755]
tests/zfs-tests/tests/functional/zvol/zvol_cli/Makefile.am [new file with mode: 0644]
tests/zfs-tests/tests/functional/zvol/zvol_cli/cleanup.ksh [new file with mode: 0755]
tests/zfs-tests/tests/functional/zvol/zvol_cli/setup.ksh [new file with mode: 0755]
tests/zfs-tests/tests/functional/zvol/zvol_cli/zvol_cli_001_pos.ksh [new file with mode: 0755]
tests/zfs-tests/tests/functional/zvol/zvol_cli/zvol_cli_002_pos.ksh [new file with mode: 0755]
tests/zfs-tests/tests/functional/zvol/zvol_cli/zvol_cli_003_neg.ksh [new file with mode: 0755]
tests/zfs-tests/tests/functional/zvol/zvol_common.shlib [new file with mode: 0644]
tests/zfs-tests/tests/functional/zvol/zvol_misc/Makefile.am [new file with mode: 0644]
tests/zfs-tests/tests/functional/zvol/zvol_misc/cleanup.ksh [new file with mode: 0755]
tests/zfs-tests/tests/functional/zvol/zvol_misc/setup.ksh [new file with mode: 0755]
tests/zfs-tests/tests/functional/zvol/zvol_misc/zvol_misc_001_neg.ksh [new file with mode: 0755]
tests/zfs-tests/tests/functional/zvol/zvol_misc/zvol_misc_002_pos.ksh [new file with mode: 0755]
tests/zfs-tests/tests/functional/zvol/zvol_misc/zvol_misc_003_neg.ksh [new file with mode: 0755]
tests/zfs-tests/tests/functional/zvol/zvol_misc/zvol_misc_004_pos.ksh [new file with mode: 0755]
tests/zfs-tests/tests/functional/zvol/zvol_misc/zvol_misc_005_neg.ksh [new file with mode: 0755]
tests/zfs-tests/tests/functional/zvol/zvol_misc/zvol_misc_006_pos.ksh [new file with mode: 0755]
tests/zfs-tests/tests/functional/zvol/zvol_swap/Makefile.am [new file with mode: 0644]
tests/zfs-tests/tests/functional/zvol/zvol_swap/cleanup.ksh [new file with mode: 0755]
tests/zfs-tests/tests/functional/zvol/zvol_swap/setup.ksh [new file with mode: 0755]
tests/zfs-tests/tests/functional/zvol/zvol_swap/zvol_swap.cfg [new file with mode: 0644]
tests/zfs-tests/tests/functional/zvol/zvol_swap/zvol_swap_001_pos.ksh [new file with mode: 0755]
tests/zfs-tests/tests/functional/zvol/zvol_swap/zvol_swap_002_pos.ksh [new file with mode: 0755]
tests/zfs-tests/tests/functional/zvol/zvol_swap/zvol_swap_003_pos.ksh [new file with mode: 0755]
tests/zfs-tests/tests/functional/zvol/zvol_swap/zvol_swap_004_pos.ksh [new file with mode: 0755]
tests/zfs-tests/tests/functional/zvol/zvol_swap/zvol_swap_005_pos.ksh [new file with mode: 0755]
tests/zfs-tests/tests/functional/zvol/zvol_swap/zvol_swap_006_pos.ksh [new file with mode: 0755]
tests/zfs-tests/tests/stress/Makefile.am [new file with mode: 0644]
zfs-script-config.sh.in

index f8abb5f2c6e52984c211511bc84571450cc7d373..ca8c8a0aa1c85de5df93c411c09b776c923a8ed4 100644 (file)
@@ -6,7 +6,7 @@ include config/tgz.am
 
 SUBDIRS = include rpm
 if CONFIG_USER
-SUBDIRS += udev etc man scripts lib cmd contrib
+SUBDIRS += udev etc man scripts tests lib cmd contrib
 endif
 if CONFIG_KERNEL
 SUBDIRS += module
diff --git a/TEST b/TEST
index dd599d119abad8af07780737793650a219e414d5..1cdbde8aa2e53a223feeee9cf7f2e20dd888f39d 100644 (file)
--- a/TEST
+++ b/TEST
@@ -37,6 +37,12 @@ TEST_ZCONFIG_OPTIONS="-c -s10"
 #TEST_XFSTESTS_VDEV="/var/tmp/vdev"
 #TEST_XFSTESTS_OPTIONS=""
 
+### zfs-tests.sh
+#TEST_ZFSTESTS_SKIP="yes"
+#TEST_ZFSTESTS_DISKS="vdb vdc vdd"
+#TEST_ZFSTESTS_DISKSIZE="8G"
+#TEST_ZFSTESTS_RUNFILE="linux.run"
+
 ### filebench
 #TEST_FILEBENCH_SKIP="yes"
 #TEST_FILEBENCH_URL="http://build.zfsonlinux.org/"
diff --git a/config/user-commands.m4 b/config/user-commands.m4
new file mode 100644 (file)
index 0000000..655b992
--- /dev/null
@@ -0,0 +1,171 @@
+dnl #
+dnl # Commands common to multiple platforms.  They generally behave
+dnl # in the same way and take similar options.
+dnl #
+AC_DEFUN([ZFS_AC_CONFIG_USER_COMMANDS_COMMON], [
+       AC_PATH_TOOL(AWK, awk, "")
+       AC_PATH_TOOL(BASENAME, basename, "")
+       AC_PATH_TOOL(BC, bc, "")
+       AC_PATH_TOOL(BUNZIP2, bunzip2, "")
+       AC_PATH_TOOL(BZCAT, bzcat, "")
+       AC_PATH_TOOL(CAT, cat, "")
+       AC_PATH_TOOL(CD, cd, "cd")              dnl # Builtin in bash
+       AC_PATH_TOOL(CHGRP, chgrp, "")
+       AC_PATH_TOOL(CHMOD, chmod, "")
+       AC_PATH_TOOL(CHOWN, chown, "")
+       AC_PATH_TOOL(CKSUM, cksum, "")
+       AC_PATH_TOOL(CMP, cmp, "")
+       AC_PATH_TOOL(CP, cp, "")
+       AC_PATH_TOOL(CPIO, cpio, "")
+       AC_PATH_TOOL(CUT, cut, "")
+       AC_PATH_TOOL(DATE, date, "")
+       AC_PATH_TOOL(DD, dd, "")
+       AC_PATH_TOOL(DF, df, "")
+       AC_PATH_TOOL(DIFF, diff, "")
+       AC_PATH_TOOL(DIRNAME, dirname, "")
+       AC_PATH_TOOL(DU, du, "")
+       AC_PATH_TOOL(ECHO, echo, "")
+       AC_PATH_TOOL(EGREP, egrep, "")
+       AC_PATH_TOOL(FDISK, fdisk, "")
+       AC_PATH_TOOL(FGREP, fgrep, "")
+       AC_PATH_TOOL(FILE, file, "")
+       AC_PATH_TOOL(FIND, find, "")
+       AC_PATH_TOOL(FSCK, fsck, "")
+       AC_PATH_TOOL(GNUDD, dd, "")
+       AC_PATH_TOOL(GETCONF, getconf, "")
+       AC_PATH_TOOL(GETENT, getent, "")
+       AC_PATH_TOOL(GREP, grep, "")
+       dnl # Due to permissions unpriviledged users may not detect group*.
+       AC_PATH_TOOL(GROUPADD, groupadd, "/usr/sbin/groupadd")
+       AC_PATH_TOOL(GROUPDEL, groupdel, "/usr/sbin/groupdel")
+       AC_PATH_TOOL(GROUPMOD, groupmod, "/usr/sbin/groupmod")
+       AC_PATH_TOOL(HEAD, head, "")
+       AC_PATH_TOOL(HOSTNAME, hostname, "")
+       AC_PATH_TOOL(ID, id, "")
+       AC_PATH_TOOL(KILL, kill, "")
+       AC_PATH_TOOL(KSH, ksh, "")
+       AC_PATH_TOOL(LOGNAME, logname, "")
+       AC_PATH_TOOL(LS, ls, "")
+       AC_PATH_TOOL(MD5SUM, md5sum, "")
+       AC_PATH_TOOL(MKDIR, mkdir, "")
+       AC_PATH_TOOL(MKNOD, mknod, "")
+       AC_PATH_TOOL(MKTEMP, mktemp, "")
+       AC_PATH_TOOL(MODINFO, modinfo, "")
+       AC_PATH_TOOL(MOUNT, mount, "")
+       AC_PATH_TOOL(MV, mv, "")
+       AC_PATH_TOOL(NAWK, nawk, "")
+       AC_PATH_TOOL(PGREP, pgrep, "")
+       AC_PATH_TOOL(PING, ping, "")
+       AC_PATH_TOOL(PKILL, pkill, "")
+       AC_PATH_TOOL(PRINTF, printf, "")
+       AC_PATH_TOOL(PS, ps, "")
+       AC_PATH_TOOL(PYTHON, python, "")
+       AC_PATH_TOOL(REBOOT, reboot, "")
+       AC_PATH_TOOL(RMDIR, rmdir, "")
+       AC_PATH_TOOL(RSH, rsh, "")
+       AC_PATH_TOOL(SED, sed, "")
+       AC_PATH_TOOL(SHUF, shuf, "")
+       AC_PATH_TOOL(SLEEP, sleep, "")
+       AC_PATH_TOOL(SORT, sort, "")
+       AC_PATH_TOOL(STRINGS, strings, "")
+       AC_PATH_TOOL(SU, su, "")
+       AC_PATH_TOOL(SUM, sum, "")
+       AC_PATH_TOOL(SYNC, sync, "")
+       AC_PATH_TOOL(TAIL, tail, "")
+       AC_PATH_TOOL(TAR, tar, "")
+       AC_PATH_TOOL(TOUCH, touch, "")
+       AC_PATH_TOOL(TR, tr, "")
+       AC_PATH_TOOL(TRUE, true, "")
+       AC_PATH_TOOL(UMASK, umask, "")
+       AC_PATH_TOOL(UMOUNT, umount, "")
+       AC_PATH_TOOL(UNAME, uname, "")
+       AC_PATH_TOOL(UNIQ, uniq, "")
+       dnl # Due to permissions unpriviledged users may not detect user*.
+       AC_PATH_TOOL(USERADD, useradd, "/usr/sbin/useradd")
+       AC_PATH_TOOL(USERDEL, userdel, "/usr/sbin/userdel")
+       AC_PATH_TOOL(USERMOD, usermod, "/usr/sbin/usermod")
+       AC_PATH_TOOL(WAIT, wait, "wait") dnl # Builtin in bash
+       AC_PATH_TOOL(WC, wc, "")
+])
+
+dnl #
+dnl # Linux commands, used withing 'is_linux' blocks of test scripts.
+dnl # These commands may take different command line arguments.
+dnl #
+AC_DEFUN([ZFS_AC_CONFIG_USER_COMMANDS_LINUX], [
+       AC_PATH_TOOL(BLOCKDEV, blockdev, "")
+       AC_PATH_TOOL(COMPRESS, gzip, "")
+       AC_PATH_TOOL(FORMAT, parted, "")
+       AC_PATH_TOOL(LOCKFS, lsof, "")
+       AC_PATH_TOOL(MODUNLOAD, rmmod, "")
+       AC_PATH_TOOL(NEWFS, mke2fs, "")
+       AC_PATH_TOOL(PFEXEC, sudo, "")
+       AC_PATH_TOOL(SHARE, exportfs, "")
+       AC_PATH_TOOL(SWAP, swapon, "")
+       AC_PATH_TOOL(SWAPADD, swapon, "")
+       AC_PATH_TOOL(TRUNCATE, truncate, "")
+       AC_PATH_TOOL(UDEVADM, udevadm, "")
+       AC_PATH_TOOL(UFSDUMP, dump, "")
+       AC_PATH_TOOL(UFSRESTORE, restore, "")
+       AC_PATH_TOOL(UNCOMPRESS, gunzip, "")
+       AC_PATH_TOOL(UNSHARE, exportfs, "")
+       AC_PATH_TOOL(GETFACL, getfacl, "")
+       AC_PATH_TOOL(SETFACL, setfacl, "")
+       AC_PATH_TOOL(CHACL, chacl, "")
+       AC_PATH_TOOL(NPROC, nproc, "")
+
+       PAGESIZE=$($GETCONF PAGESIZE)
+       AC_SUBST(PAGESIZE)
+
+       MNTTAB=/etc/mtab
+       AC_SUBST(MNTTAB)
+])
+
+dnl #
+dnl # BSD style commands, these have been kept in case at some point
+dnl # we want to build these packages on a BSD style systems.  Otherwise
+dnl # they are unused and should be treated as such.
+dnl #
+AC_DEFUN([ZFS_AC_CONFIG_USER_COMMANDS_BSD], [
+       AC_PATH_TOOL(COMPRESS, compress, "")
+       AC_PATH_TOOL(COREADM, coreadm, "")
+       AC_PATH_TOOL(DIRCMP, dircmp, "")
+       AC_PATH_TOOL(DUMPADM, dumpadm, "")
+       AC_PATH_TOOL(FORMAT, format, "")
+       AC_PATH_TOOL(GETMAJOR, getmajor, "")
+       AC_PATH_TOOL(ISAINFO, isainfo, "")
+       AC_PATH_TOOL(KSTAT, kstat, "")
+       AC_PATH_TOOL(LOCKFS, lockfs, "")
+       AC_PATH_TOOL(LOFIADM, lofiadm, "")
+       AC_PATH_TOOL(MODUNLOAD, modunload, "")
+       AC_PATH_TOOL(NEWFS, newfs, "")
+       AC_PATH_TOOL(PAGESIZE, pagesize, "")
+       AC_PATH_TOOL(PFEXEC, pfexec, "")
+       AC_PATH_TOOL(PKGINFO, pkginfo, "")
+       AC_PATH_TOOL(PRTVTOC, prtvtoc, "")
+       AC_PATH_TOOL(PSRINFO, psrinfo, "")
+       AC_PATH_TOOL(SHARE, share, "")
+       AC_PATH_TOOL(SVCADM, svcadm, "")
+       AC_PATH_TOOL(SVCS, svcs, "")
+       AC_PATH_TOOL(SWAP, swap, "")
+       AC_PATH_TOOL(SWAPADD, swapadd, "")
+       AC_PATH_TOOL(UFSDUMP, ufsdump, "")
+       AC_PATH_TOOL(UFSRESTORE, ufsrestore, "")
+       AC_PATH_TOOL(UMOUNTALL, umountall, "")
+       AC_PATH_TOOL(UNCOMPRESS, uncompress, "")
+       AC_PATH_TOOL(UNSHARE, unshare, "")
+       AC_PATH_TOOL(ZONEADM, zoneadm, "")
+       AC_PATH_TOOL(ZONECFG, zonecfg, "")
+       AC_PATH_TOOL(ZONENAME, zonename, "")
+])
+
+AC_DEFUN([ZFS_AC_CONFIG_USER_COMMANDS], [
+       ZFS_AC_CONFIG_USER_COMMANDS_COMMON
+
+       OS=$($UNAME -o)
+       AS_IF([test "$OS" == "GNU/Linux"], [
+               ZFS_AC_CONFIG_USER_COMMANDS_LINUX
+       ], [
+               ZFS_AC_CONFIG_USER_COMMANDS_BSD
+       ])
+])
diff --git a/config/user-libattr.m4 b/config/user-libattr.m4
new file mode 100644 (file)
index 0000000..3298fd4
--- /dev/null
@@ -0,0 +1,12 @@
+dnl #
+dnl # Check for libattr
+dnl #
+AC_DEFUN([ZFS_AC_CONFIG_USER_LIBATTR], [
+       LIBATTR=
+
+       AC_CHECK_HEADER([attr/xattr.h], [], [AC_MSG_FAILURE([
+       *** attr/xattr.h missing, libattr-devel package required])])
+
+       AC_SUBST([LIBATTR], ["-lattr"])
+       AC_DEFINE([HAVE_LIBATTR], 1, [Define if you have libattr])
+])
index 7f79420825645423613a3de472a73534522466c8..69d103c1058ad3d54e8bd571ebc29f92a63056c7 100644 (file)
@@ -11,9 +11,24 @@ AC_DEFUN([ZFS_AC_CONFIG_USER], [
        ZFS_AC_CONFIG_USER_ZLIB
        ZFS_AC_CONFIG_USER_LIBUUID
        ZFS_AC_CONFIG_USER_LIBBLKID
+       ZFS_AC_CONFIG_USER_LIBATTR
        ZFS_AC_CONFIG_USER_FRAME_LARGER_THAN
        ZFS_AC_CONFIG_USER_RUNSTATEDIR
-dnl #
-dnl #  Checks for library functions
+
+       ZFS_AC_CONFIG_USER_COMMANDS
+       ZFS_AC_TEST_FRAMEWORK
+
        AC_CHECK_FUNCS([mlockall])
 ])
+
+dnl #
+dnl # Setup the environment for the ZFS Test Suite.  Currently only
+dnl # Linux sytle systems are supported but this infrastructure can
+dnl # be extended to support other platforms if needed.
+dnl #
+AC_DEFUN([ZFS_AC_TEST_FRAMEWORK], [
+       ZONENAME="echo global"
+       AC_SUBST(ZONENAME)
+
+       AC_SUBST(RM)
+])
index 9d3f0a6f5bbc16f84bf951382506ddc72ec4d740..41431e10a7dba6fde4923cfbe940eb81479c721f 100644 (file)
@@ -89,8 +89,8 @@ AC_DEFUN([ZFS_AC_CONFIG], [
        case "$ZFS_CONFIG" in
                kernel) ZFS_AC_CONFIG_KERNEL ;;
                user)   ZFS_AC_CONFIG_USER   ;;
-               all)    ZFS_AC_CONFIG_KERNEL
-                       ZFS_AC_CONFIG_USER   ;;
+               all)    ZFS_AC_CONFIG_USER
+                       ZFS_AC_CONFIG_KERNEL ;;
                srpm)                        ;;
                *)
                AC_MSG_RESULT([Error!])
index 9907857e2e12844f78a26a61433f19a5827c2a3c..41cd00758119d2a8ae7032c25896314ed61a6622 100644 (file)
@@ -56,7 +56,7 @@ ZFS_AC_CONFIG
 ZFS_AC_DEBUG
 ZFS_AC_DEBUG_DMU_TX
 
-AC_CONFIG_FILES([ 
+AC_CONFIG_FILES([
        Makefile
        udev/Makefile
        udev/rules.d/Makefile
@@ -134,6 +134,145 @@ AC_CONFIG_FILES([
        scripts/zpios-test/Makefile
        scripts/zpool-config/Makefile
        scripts/common.sh
+       tests/Makefile
+       tests/test-runner/Makefile
+       tests/test-runner/cmd/Makefile
+       tests/test-runner/include/Makefile
+       tests/test-runner/man/Makefile
+       tests/runfiles/Makefile
+       tests/zfs-tests/Makefile
+       tests/zfs-tests/cmd/Makefile
+       tests/zfs-tests/cmd/chg_usr_exec/Makefile
+       tests/zfs-tests/cmd/devname2devid/Makefile
+       tests/zfs-tests/cmd/dir_rd_update/Makefile
+       tests/zfs-tests/cmd/file_check/Makefile
+       tests/zfs-tests/cmd/file_trunc/Makefile
+       tests/zfs-tests/cmd/file_write/Makefile
+       tests/zfs-tests/cmd/largest_file/Makefile
+       tests/zfs-tests/cmd/mkbusy/Makefile
+       tests/zfs-tests/cmd/mkfile/Makefile
+       tests/zfs-tests/cmd/mkfiles/Makefile
+       tests/zfs-tests/cmd/mktree/Makefile
+       tests/zfs-tests/cmd/mmap_exec/Makefile
+       tests/zfs-tests/cmd/mmapwrite/Makefile
+       tests/zfs-tests/cmd/randfree_file/Makefile
+       tests/zfs-tests/cmd/readmmap/Makefile
+       tests/zfs-tests/cmd/rename_dir/Makefile
+       tests/zfs-tests/cmd/rm_lnkcnt_zero_file/Makefile
+       tests/zfs-tests/cmd/threadsappend/Makefile
+       tests/zfs-tests/cmd/xattrtest/Makefile
+       tests/zfs-tests/include/Makefile
+       tests/zfs-tests/include/commands.cfg
+       tests/zfs-tests/include/default.cfg
+       tests/zfs-tests/tests/Makefile
+       tests/zfs-tests/tests/functional/Makefile
+       tests/zfs-tests/tests/functional/acl/Makefile
+       tests/zfs-tests/tests/functional/acl/posix/Makefile
+       tests/zfs-tests/tests/functional/atime/Makefile
+       tests/zfs-tests/tests/functional/bootfs/Makefile
+       tests/zfs-tests/tests/functional/cache/Makefile
+       tests/zfs-tests/tests/functional/cachefile/Makefile
+       tests/zfs-tests/tests/functional/casenorm/Makefile
+       tests/zfs-tests/tests/functional/clean_mirror/Makefile
+       tests/zfs-tests/tests/functional/cli_root/Makefile
+       tests/zfs-tests/tests/functional/cli_root/zdb/Makefile
+       tests/zfs-tests/tests/functional/cli_root/zfs_clone/Makefile
+       tests/zfs-tests/tests/functional/cli_root/zfs_copies/Makefile
+       tests/zfs-tests/tests/functional/cli_root/zfs_create/Makefile
+       tests/zfs-tests/tests/functional/cli_root/zfs_destroy/Makefile
+       tests/zfs-tests/tests/functional/cli_root/zfs_get/Makefile
+       tests/zfs-tests/tests/functional/cli_root/zfs_inherit/Makefile
+       tests/zfs-tests/tests/functional/cli_root/zfs/Makefile
+       tests/zfs-tests/tests/functional/cli_root/zfs_mount/Makefile
+       tests/zfs-tests/tests/functional/cli_root/zfs_promote/Makefile
+       tests/zfs-tests/tests/functional/cli_root/zfs_property/Makefile
+       tests/zfs-tests/tests/functional/cli_root/zfs_receive/Makefile
+       tests/zfs-tests/tests/functional/cli_root/zfs_rename/Makefile
+       tests/zfs-tests/tests/functional/cli_root/zfs_reservation/Makefile
+       tests/zfs-tests/tests/functional/cli_root/zfs_rollback/Makefile
+       tests/zfs-tests/tests/functional/cli_root/zfs_send/Makefile
+       tests/zfs-tests/tests/functional/cli_root/zfs_set/Makefile
+       tests/zfs-tests/tests/functional/cli_root/zfs_share/Makefile
+       tests/zfs-tests/tests/functional/cli_root/zfs_snapshot/Makefile
+       tests/zfs-tests/tests/functional/cli_root/zfs_unmount/Makefile
+       tests/zfs-tests/tests/functional/cli_root/zfs_unshare/Makefile
+       tests/zfs-tests/tests/functional/cli_root/zfs_upgrade/Makefile
+       tests/zfs-tests/tests/functional/cli_root/zpool_add/Makefile
+       tests/zfs-tests/tests/functional/cli_root/zpool_attach/Makefile
+       tests/zfs-tests/tests/functional/cli_root/zpool_clear/Makefile
+       tests/zfs-tests/tests/functional/cli_root/zpool_create/Makefile
+       tests/zfs-tests/tests/functional/cli_root/zpool_destroy/Makefile
+       tests/zfs-tests/tests/functional/cli_root/zpool_detach/Makefile
+       tests/zfs-tests/tests/functional/cli_root/zpool_expand/Makefile
+       tests/zfs-tests/tests/functional/cli_root/zpool_export/Makefile
+       tests/zfs-tests/tests/functional/cli_root/zpool_get/Makefile
+       tests/zfs-tests/tests/functional/cli_root/zpool_history/Makefile
+       tests/zfs-tests/tests/functional/cli_root/zpool_import/Makefile
+       tests/zfs-tests/tests/functional/cli_root/zpool/Makefile
+       tests/zfs-tests/tests/functional/cli_root/zpool_offline/Makefile
+       tests/zfs-tests/tests/functional/cli_root/zpool_online/Makefile
+       tests/zfs-tests/tests/functional/cli_root/zpool_remove/Makefile
+       tests/zfs-tests/tests/functional/cli_root/zpool_replace/Makefile
+       tests/zfs-tests/tests/functional/cli_root/zpool_scrub/Makefile
+       tests/zfs-tests/tests/functional/cli_root/zpool_set/Makefile
+       tests/zfs-tests/tests/functional/cli_root/zpool_status/Makefile
+       tests/zfs-tests/tests/functional/cli_root/zpool_upgrade/Makefile
+       tests/zfs-tests/tests/functional/cli_user/Makefile
+       tests/zfs-tests/tests/functional/cli_user/misc/Makefile
+       tests/zfs-tests/tests/functional/cli_user/zfs_list/Makefile
+       tests/zfs-tests/tests/functional/cli_user/zpool_iostat/Makefile
+       tests/zfs-tests/tests/functional/cli_user/zpool_list/Makefile
+       tests/zfs-tests/tests/functional/compression/Makefile
+       tests/zfs-tests/tests/functional/ctime/Makefile
+       tests/zfs-tests/tests/functional/delegate/Makefile
+       tests/zfs-tests/tests/functional/devices/Makefile
+       tests/zfs-tests/tests/functional/exec/Makefile
+       tests/zfs-tests/tests/functional/features/async_destroy/Makefile
+       tests/zfs-tests/tests/functional/features/Makefile
+       tests/zfs-tests/tests/functional/grow_pool/Makefile
+       tests/zfs-tests/tests/functional/grow_replicas/Makefile
+       tests/zfs-tests/tests/functional/history/Makefile
+       tests/zfs-tests/tests/functional/inheritance/Makefile
+       tests/zfs-tests/tests/functional/inuse/Makefile
+       tests/zfs-tests/tests/functional/large_files/Makefile
+       tests/zfs-tests/tests/functional/largest_pool/Makefile
+       tests/zfs-tests/tests/functional/link_count/Makefile
+       tests/zfs-tests/tests/functional/migration/Makefile
+       tests/zfs-tests/tests/functional/mmap/Makefile
+       tests/zfs-tests/tests/functional/mount/Makefile
+       tests/zfs-tests/tests/functional/mv_files/Makefile
+       tests/zfs-tests/tests/functional/nestedfs/Makefile
+       tests/zfs-tests/tests/functional/no_space/Makefile
+       tests/zfs-tests/tests/functional/nopwrite/Makefile
+       tests/zfs-tests/tests/functional/online_offline/Makefile
+       tests/zfs-tests/tests/functional/pool_names/Makefile
+       tests/zfs-tests/tests/functional/poolversion/Makefile
+       tests/zfs-tests/tests/functional/privilege/Makefile
+       tests/zfs-tests/tests/functional/quota/Makefile
+       tests/zfs-tests/tests/functional/redundancy/Makefile
+       tests/zfs-tests/tests/functional/refquota/Makefile
+       tests/zfs-tests/tests/functional/refreserv/Makefile
+       tests/zfs-tests/tests/functional/rename_dirs/Makefile
+       tests/zfs-tests/tests/functional/replacement/Makefile
+       tests/zfs-tests/tests/functional/reservation/Makefile
+       tests/zfs-tests/tests/functional/rootpool/Makefile
+       tests/zfs-tests/tests/functional/rsend/Makefile
+       tests/zfs-tests/tests/functional/scrub_mirror/Makefile
+       tests/zfs-tests/tests/functional/slog/Makefile
+       tests/zfs-tests/tests/functional/snapshot/Makefile
+       tests/zfs-tests/tests/functional/snapused/Makefile
+       tests/zfs-tests/tests/functional/sparse/Makefile
+       tests/zfs-tests/tests/functional/threadsappend/Makefile
+       tests/zfs-tests/tests/functional/truncate/Makefile
+       tests/zfs-tests/tests/functional/userquota/Makefile
+       tests/zfs-tests/tests/functional/write_dirs/Makefile
+       tests/zfs-tests/tests/functional/xattr/Makefile
+       tests/zfs-tests/tests/functional/zvol/Makefile
+       tests/zfs-tests/tests/functional/zvol/zvol_cli/Makefile
+       tests/zfs-tests/tests/functional/zvol/zvol_ENOSPC/Makefile
+       tests/zfs-tests/tests/functional/zvol/zvol_misc/Makefile
+       tests/zfs-tests/tests/functional/zvol/zvol_swap/Makefile
+       tests/zfs-tests/tests/stress/Makefile
        rpm/Makefile
        rpm/redhat/Makefile
        rpm/redhat/zfs.spec
index 33c87b441359706d31dcc9c2c08f69afdeae2f7a..07a5906c248ad3f23ab29d2e737ef00e2d1fb3b8 100644 (file)
@@ -58,6 +58,7 @@ extern "C" {
  */
 #define        DISK_ROOT               "/dev"
 #define        UDISK_ROOT              "/dev/disk"
+#define        ZVOL_ROOT               "/dev/zvol"
 
 /*
  * Default wait time for a device name to be created.
index 65b04c59ac9609d36c0d6f418206173010a0ff47..57c2ac85386a13bcc53e1c20fc8285c949d70e28 100644 (file)
@@ -908,7 +908,8 @@ zfs_append_partition(char *path, size_t max_len)
 {
        int len = strlen(path);
 
-       if (strncmp(path, UDISK_ROOT, strlen(UDISK_ROOT)) == 0) {
+       if ((strncmp(path, UDISK_ROOT, strlen(UDISK_ROOT)) == 0) ||
+           (strncmp(path, ZVOL_ROOT, strlen(ZVOL_ROOT)) == 0)) {
                if (len + 6 >= max_len)
                        return (-1);
 
index cadc08c8ae90945f9e5a0e4da54682631f0fdec5..cc8d02b6de78c09c4dfe97ddb10df7926068e4fe 100644 (file)
@@ -171,6 +171,7 @@ Requires:       parted
 Requires:       lsscsi
 Requires:       mdadm
 Requires:       bc
+Requires:       ksh
 
 %description test
 This package contains test infrastructure and support scripts for
index 26f9207e4a41c57fcdb21f0dbb87ccd2597a41fd..32d8911c36265a07cc4e8633353ae75a9131c438 100644 (file)
@@ -6,52 +6,12 @@ pkgdatadir = $(datadir)/@PACKAGE@
 dist_pkgdata_SCRIPTS = \
        $(top_builddir)/scripts/common.sh \
        $(top_srcdir)/scripts/zconfig.sh \
-       $(top_srcdir)/scripts/zfault.sh \
        $(top_srcdir)/scripts/ziltest.sh \
        $(top_srcdir)/scripts/zimport.sh \
        $(top_srcdir)/scripts/zfs.sh \
+       $(top_srcdir)/scripts/zfs-tests.sh \
        $(top_srcdir)/scripts/zpool-create.sh \
        $(top_srcdir)/scripts/zpios.sh \
        $(top_srcdir)/scripts/zpios-sanity.sh \
        $(top_srcdir)/scripts/zpios-survey.sh \
        $(top_srcdir)/scripts/smb.sh
-
-ZFS=$(top_builddir)/scripts/zfs.sh
-ZCONFIG=$(top_builddir)/scripts/zconfig.sh
-ZFAULT=$(top_builddir)/scripts/zfault.sh
-ZIMPORT=$(top_builddir)/scripts/zimport.sh
-ZTEST=$(top_builddir)/cmd/ztest/ztest
-ZPIOS_SANITY=$(top_builddir)/scripts/zpios-sanity.sh
-
-check:
-       @$(ZFS) -u
-       @echo
-       @echo -n "===================================="
-       @echo -n " ZTEST "
-       @echo    "===================================="
-       @echo
-       @$(ZFS)
-       @$(ZTEST) -V
-       @$(ZFS) -u
-       @echo
-       @echo
-       @echo -n "==================================="
-       @echo -n " ZCONFIG "
-       @echo    "==================================="
-       @echo
-       @$(ZCONFIG) -c
-       @echo
-       @echo -n "==================================="
-       @echo -n " ZFAULT "
-       @echo    "==================================="
-       @echo
-       @$(ZFAULT) -c
-       @echo
-       @echo -n "===================================="
-       @echo -n " ZPIOS "
-       @echo    "===================================="
-       @echo
-       @$(ZFS)
-       @$(ZPIOS_SANITY)
-       @$(ZFS) -u
-       @echo
index 2fac2a9191c2df00b4b506bd4aa5c9d0366cd041..f6c6d93fe6bb4e1ebdc8b13e1bedc8bc4e97166d 100644 (file)
@@ -45,10 +45,13 @@ DEVDIR=${DEVDIR:-/dev/disk/by-vdev}
 ZPOOLDIR=${ZPOOLDIR:-${pkgdatadir}/zpool-config}
 ZPIOSDIR=${ZPIOSDIR:-${pkgdatadir}/zpios-test}
 ZPIOSPROFILEDIR=${ZPIOSPROFILEDIR:-${pkgdatadir}/zpios-profile}
+TESTSDIR=${TESTSDIR:-${pkgdatadir}/zfs-tests}
+RUNFILEDIR=${RUNFILEDIR:-${pkgdatadir}/runfiles}
 
 ZDB=${ZDB:-${sbindir}/zdb}
 ZFS=${ZFS:-${sbindir}/zfs}
 ZINJECT=${ZINJECT:-${sbindir}/zinject}
+ZHACK=${ZHACK:-${sbindir}/zhack}
 ZPOOL=${ZPOOL:-${sbindir}/zpool}
 ZTEST=${ZTEST:-${sbindir}/ztest}
 ZPIOS=${ZPIOS:-${sbindir}/zpios}
@@ -58,6 +61,9 @@ ZFS_SH=${ZFS_SH:-${pkgdatadir}/zfs.sh}
 ZPOOL_CREATE_SH=${ZPOOL_CREATE_SH:-${pkgdatadir}/zpool-create.sh}
 ZPIOS_SH=${ZPIOS_SH:-${pkgdatadir}/zpios.sh}
 ZPIOS_SURVEY_SH=${ZPIOS_SURVEY_SH:-${pkgdatadir}/zpios-survey.sh}
+TEST_RUNNER=${TEST_RUNNER:-${pkgdatadir}/test-runner/bin/test-runner.py}
+STF_TOOLS=${STF_TOOLS:-${pkgdatadir}/test-runner}
+STF_SUITE=${STF_SUITE:-${pkgdatadir}/zfs-tests}
 
 LDMOD=${LDMOD:-/sbin/modprobe}
 LSMOD=${LSMOD:-/sbin/lsmod}
@@ -65,6 +71,7 @@ RMMOD=${RMMOD:-/sbin/rmmod}
 INFOMOD=${INFOMOD:-/sbin/modinfo}
 LOSETUP=${LOSETUP:-/sbin/losetup}
 MDADM=${MDADM:-/sbin/mdadm}
+DMSETUP=${DMSETUP:-/sbin/dmsetup}
 PARTED=${PARTED:-/sbin/parted}
 BLOCKDEV=${BLOCKDEV:-/sbin/blockdev}
 LSSCSI=${LSSCSI:-/usr/bin/lsscsi}
@@ -297,7 +304,7 @@ check_loop_utils() {
 # the minor as long as it's less than /sys/module/loop/parameters/max_loop.
 #
 unused_loop_device() {
-       local DEVICE=`${LOSETUP} -f`
+       local DEVICE=$(${LOSETUP} -f)
        local MAX_LOOP_PATH="/sys/module/loop/parameters/max_loop"
        local MAX_LOOP;
 
@@ -359,7 +366,7 @@ destroy_loop_devices() {
        local LODEVICES="$1"
 
        msg "Destroying ${LODEVICES}"
-        ${LOSETUP} -d ${LODEVICES} || \
+       ${LOSETUP} -d ${LODEVICES} || \
                die "Error $? destroying ${FILE} -> ${DEVICE} loopback"
 
        rm -f ${FILES}
diff --git a/scripts/zfault.sh b/scripts/zfault.sh
deleted file mode 100755 (executable)
index a5f1f3c..0000000
+++ /dev/null
@@ -1,955 +0,0 @@
-#!/bin/bash
-#
-# ZPOOL fault verification test script.
-#
-# The current suite of fault tests should not be thought of an exhaustive
-# list of failure modes.  Rather it is simply an starting point which trys
-# to cover the bulk the of the 'easy' and hopefully common, failure modes.
-#
-# Additional tests should be added but the current suite as new interesting
-# failures modes are observed.  Additional failure modes I'd like to see
-# tests for include, but are not limited too:
-#
-#      * Slow but successful IO.
-#      * SCSI sense codes generated as zevents.
-#      * 4k sectors
-#      * noise
-#      * medium error
-#      * recovered error
-#
-# The current infrastructure using the 'mdadm' faulty device and the
-# 'scsi_debug' simulated scsi devices.  The idea is to inject the error
-# below the zfs stack to validate all the error paths.  More targeted
-# failure testing should be added using the 'zinject' command line util.
-#
-# Requires the following packages:
-# * mdadm
-# * lsscsi
-# * sg3-utils
-#
-
-basedir="$(dirname $0)"
-
-SCRIPT_COMMON=common.sh
-if [ -f "${basedir}/${SCRIPT_COMMON}" ]; then
-. "${basedir}/${SCRIPT_COMMON}"
-else
-echo "Missing helper script ${SCRIPT_COMMON}" && exit 1
-fi
-
-PROG=zfault.sh
-
-usage() {
-cat << EOF
-USAGE:
-$0 [hvcts]
-
-DESCRIPTION:
-       ZPOOL fault verification tests
-
-OPTIONS:
-       -h      Show this message
-       -v      Verbose
-       -c      Cleanup md+lo+file devices at start
-       -t <#>  Run listed tests
-       -s <#>  Skip listed tests
-
-EOF
-}
-
-while getopts 'hvct:s:?' OPTION; do
-       case $OPTION in
-       h)
-               usage
-               exit 1
-               ;;
-       v)
-               VERBOSE=1
-               ;;
-       c)
-               CLEANUP=1
-               ;;
-       t)
-               TESTS_RUN=($OPTARG)
-               ;;
-       s)
-               TESTS_SKIP=($OPTARG)
-               ;;
-       ?)
-               usage
-               exit
-               ;;
-       esac
-done
-
-if [ $(id -u) != 0 ]; then
-       die "Must run as root"
-fi
-
-# Initialize the test suite
-init
-
-# Perform pre-cleanup is requested
-if [ ${CLEANUP} ]; then
-       ${ZFS_SH} -u
-       cleanup_md_devices
-       cleanup_loop_devices
-       rm -f /tmp/zpool.cache.*
-fi
-
-# Check if we need to skip all md based tests.
-MD_PARTITIONABLE=0
-check_md_partitionable && MD_PARTITIONABLE=1
-if [ ${MD_PARTITIONABLE} -eq 0 ]; then
-       echo "Skipping tests 1-7 which require partitionable md devices"
-fi
-
-# Check if we need to skip all the scsi_debug tests.
-SCSI_DEBUG=0
-${INFOMOD} scsi_debug &>/dev/null && SCSI_DEBUG=1
-if [ ${SCSI_DEBUG} -eq 0 ]; then
-       echo "Skipping tests 8-9 which require the scsi_debug module"
-fi
-
-if [ ${MD_PARTITIONABLE} -eq 0 ] || [ ${SCSI_DEBUG} -eq 0 ]; then
-       echo
-fi
-
-printf "%40s%s\t%s\t%s\t%s\t%s\n" "" "raid0" "raid10" "raidz" "raidz2" "raidz3"
-
-pass_nonewline() {
-       echo -n -e "${COLOR_GREEN}Pass${COLOR_RESET}\t"
-}
-
-skip_nonewline() {
-       echo -n -e "${COLOR_BROWN}Skip${COLOR_RESET}\t"
-}
-
-nth_zpool_vdev() {
-       local POOL_NAME=$1
-       local DEVICE_TYPE=$2
-       local DEVICE_NTH=$3
-
-       ${ZPOOL} status ${POOL_NAME} | grep ${DEVICE_TYPE} ${TMP_STATUS} |   \
-               head -n${DEVICE_NTH} | tail -n1 | ${AWK} "{ print \$1 }"
-}
-
-vdev_status() {
-       local POOL_NAME=$1
-       local VDEV_NAME=$2
-
-       ${ZPOOL} status ${POOL_NAME} | ${AWK} "/${VDEV_NAME}/ { print \$2 }"
-}
-
-# Required format is x.yz[KMGTP]
-expand_numeric_suffix() {
-       local VALUE=$1
-
-       VALUE=`echo "${VALUE/%K/*1000}"`
-       VALUE=`echo "${VALUE/%M/*1000000}"`
-       VALUE=`echo "${VALUE/%G/*1000000000}"`
-       VALUE=`echo "${VALUE/%T/*1000000000000}"`
-       VALUE=`echo "${VALUE/%P/*1000000000000000}"`
-       VALUE=`echo "${VALUE}" | bc | cut -d'.' -f1`
-
-       echo "${VALUE}"
-}
-
-vdev_read_errors() {
-       local POOL_NAME=$1
-       local VDEV_NAME=$2
-       local VDEV_ERRORS=`${ZPOOL} status ${POOL_NAME} |
-               ${AWK} "/${VDEV_NAME}/ { print \\$3 }"`
-
-       expand_numeric_suffix ${VDEV_ERRORS}
-}
-
-vdev_write_errors() {
-       local POOL_NAME=$1
-       local VDEV_NAME=$2
-       local VDEV_ERRORS=`${ZPOOL} status ${POOL_NAME} |
-               ${AWK} "/${VDEV_NAME}/ { print \\$4 }"`
-
-       expand_numeric_suffix ${VDEV_ERRORS}
-}
-
-vdev_cksum_errors() {
-       local POOL_NAME=$1
-       local VDEV_NAME=$2
-       local VDEV_ERRORS=`${ZPOOL} status ${POOL_NAME} |
-               ${AWK} "/${VDEV_NAME}/ { print \\$5 }"`
-
-       expand_numeric_suffix ${VDEV_ERRORS}
-}
-
-zpool_state() {
-       local POOL_NAME=$1
-
-       ${ZPOOL} status ${POOL_NAME} | ${AWK} "/state/ { print \$2; exit }"
-}
-
-zpool_event() {
-       local EVENT_NAME=$1
-       local EVENT_KEY=$2
-
-       SCRIPT1="BEGIN {RS=\"\"; FS=\"\n\"} /${EVENT_NAME}/ { print \$0; exit }"
-       SCRIPT2="BEGIN {FS=\"=\"} /${EVENT_KEY}/ { print \$2; exit }"
-
-       ${ZPOOL} events -vH | ${AWK} "${SCRIPT1}" | ${AWK} "${SCRIPT2}"
-}
-
-zpool_scan_errors() {
-       local POOL_NAME=$1
-
-       ${ZPOOL} status ${POOL_NAME} | ${AWK} "/scan: scrub/ { print \$8 }"
-       ${ZPOOL} status ${POOL_NAME} | ${AWK} "/scan: resilver/ { print \$7 }"
-}
-
-pattern_create() {
-       local PATTERN_BLOCK_SIZE=$1
-       local PATTERN_BLOCK_COUNT=$2
-       local PATTERN_NAME=`mktemp -p /tmp zpool.pattern.XXXXXXXX`
-
-       echo ${PATTERN_NAME}
-       dd if=/dev/urandom of=${PATTERN_NAME} bs=${PATTERN_BLOCK_SIZE}   \
-               count=${PATTERN_BLOCK_COUNT} &>/dev/null
-       return $?
-}
-
-pattern_write() {
-       local PATTERN_NAME=$1
-       local PATTERN_BLOCK_SIZE=$2
-       local PATTERN_BLOCK_COUNT=$3
-       local DEVICE_NAME=$4
-
-       dd if=${PATTERN_NAME} of=${DEVICE_NAME} bs=${PATTERN_BLOCK_SIZE} \
-               count=${PATTERN_BLOCK_COUNT} oflag=direct &>/dev/null
-       return $?
-}
-
-pattern_write_bg() {
-       local PATTERN_NAME=$1
-       local PATTERN_BLOCK_SIZE=$2
-       local PATTERN_BLOCK_COUNT=$3
-       local DEVICE_NAME=$4
-
-       dd if=${PATTERN_NAME} of=${DEVICE_NAME} bs=${PATTERN_BLOCK_SIZE} \
-               count=${PATTERN_BLOCK_COUNT} oflag=direct &>/dev/null &
-       return $?
-}
-
-pattern_verify() {
-       local PATTERN_NAME=$1
-       local PATTERN_BLOCK_SIZE=$2
-       local PATTERN_BLOCK_COUNT=$3
-       local DEVICE_NAME=$4
-       local DEVICE_FILE=`mktemp -p /tmp zpool.pattern.XXXXXXXX`
-
-       dd if=${DEVICE_NAME} of=${DEVICE_FILE} bs=${PATTERN_BLOCK_SIZE} \
-               count=${PATTERN_BLOCK_COUNT} iflag=direct &>/dev/null
-       cmp -s ${PATTERN_NAME} ${DEVICE_FILE}
-       RC=$?
-       rm -f ${DEVICE_FILE}
-
-       return ${RC}
-}
-
-pattern_remove() {
-       local PATTERN_NAME=$1
-
-       rm -f ${PATTERN_NAME}
-       return $?
-}
-
-fault_set_md() {
-       local VDEV_FAULTY=$1
-       local FAULT_TYPE=$2
-
-       ${MDADM} /dev/${VDEV_FAULTY} --grow --level=faulty \
-               --layout=${FAULT_TYPE} >/dev/null
-       return $?
-}
-
-fault_clear_md() {
-       local VDEV_FAULTY=$1
-
-       # Clear all failure injection.
-       ${MDADM} /dev/${VDEV_FAULTY} --grow --level=faulty \
-               --layout=clear >/dev/null || return $?
-       ${MDADM} /dev/${VDEV_FAULTY} --grow --level=faulty \
-               --layout=flush >/dev/null || return $?
-       return $?
-}
-
-fault_set_sd() {
-       local OPTS=$1
-       local NTH=$2
-
-       echo ${OPTS} >/sys/bus/pseudo/drivers/scsi_debug/opts
-       echo ${NTH}  >/sys/bus/pseudo/drivers/scsi_debug/every_nth
-}
-
-fault_clear_sd() {
-       echo 0 >/sys/bus/pseudo/drivers/scsi_debug/every_nth
-       echo 0 >/sys/bus/pseudo/drivers/scsi_debug/opts
-}
-
-test_setup() {
-       local POOL_NAME=$1
-       local POOL_CONFIG=$2
-       local ZVOL_NAME=$3
-       local TMP_CACHE=$4
-
-       ${ZFS_SH} zfs="spa_config_path=${TMP_CACHE}" || fail 1
-       ${ZPOOL_CREATE_SH} -p ${POOL_NAME} -c ${POOL_CONFIG} || fail 2
-       ${ZFS} create -V 64M ${POOL_NAME}/${ZVOL_NAME} || fail 3
-
-       # Trigger udev and re-read the partition table to ensure all of
-       # this IO is out of the way before we begin injecting failures.
-       udev_trigger || fail 4
-       ${BLOCKDEV} --rereadpt /dev/${POOL_NAME}/${ZVOL_NAME} || fail 5
-}
-
-test_cleanup() {
-       local POOL_NAME=$1
-       local POOL_CONFIG=$2
-       local ZVOL_NAME=$3
-       local TMP_CACHE=$4
-
-       ${ZFS} destroy ${POOL_NAME}/${ZVOL_NAME} || fail 101
-       ${ZPOOL_CREATE_SH} -p ${POOL_NAME} -c ${POOL_CONFIG} -d || fail 102
-       ${ZFS_SH} -u || fail 103
-       rm -f ${TMP_CACHE} || fail 104
-}
-
-test_write_soft() {
-       local POOL_NAME=$1
-       local POOL_CONFIG=$2
-       local POOL_REDUNDANT=$3
-       local ZVOL_NAME="zvol"
-       local ZVOL_DEVICE="/dev/${POOL_NAME}/${ZVOL_NAME}"
-
-       if [ ${MD_PARTITIONABLE} -eq 0 ]; then
-               skip_nonewline
-               return
-       fi
-
-       local TMP_CACHE=`mktemp -p /tmp zpool.cache.XXXXXXXX`
-       test_setup ${POOL_NAME} ${POOL_CONFIG} ${ZVOL_NAME} ${TMP_CACHE}
-
-       # Set soft write failure for first vdev device.
-       local VDEV_FAULTY=`nth_zpool_vdev ${POOL_NAME} md 1`
-       fault_set_md ${VDEV_FAULTY} write-transient
-
-       # The application must not observe an error.
-       local TMP_PATTERN=`pattern_create 1M 8` || fail 11
-       pattern_write ${TMP_PATTERN} 1M 8 ${ZVOL_DEVICE} || fail 12
-       fault_clear_md ${VDEV_FAULTY}
-
-       # Soft errors will not be logged to 'zpool status'
-       local WRITE_ERRORS=`vdev_write_errors ${POOL_NAME} ${VDEV_FAULTY}`
-       test ${WRITE_ERRORS} -eq 0 || fail 13
-
-       # Soft errors will still generate an EIO (5) event.
-       test `zpool_event "zfs.io" "zio_err"` = "0x5" || fail 14
-
-       # Verify the known pattern.
-       pattern_verify ${TMP_PATTERN} 1M 8 ${ZVOL_DEVICE} || fail 15
-       pattern_remove ${TMP_PATTERN} || fail 16
-
-       test_cleanup ${POOL_NAME} ${POOL_CONFIG} ${ZVOL_NAME} ${TMP_CACHE}
-       pass_nonewline
-}
-
-# Soft write error.
-test_1() {
-       test_write_soft tank lo-faulty-raid0  0
-       test_write_soft tank lo-faulty-raid10 1
-       test_write_soft tank lo-faulty-raidz  1
-       test_write_soft tank lo-faulty-raidz2 1
-       test_write_soft tank lo-faulty-raidz3 1
-       echo
-}
-run_test 1 "soft write error"
-
-test_write_hard() {
-       local POOL_NAME=$1
-       local POOL_CONFIG=$2
-       local POOL_REDUNDANT=$3
-       local ZVOL_NAME="zvol"
-       local ZVOL_DEVICE="/dev/${POOL_NAME}/${ZVOL_NAME}"
-
-       if [ ${MD_PARTITIONABLE} -eq 0 ]; then
-               skip_nonewline
-               return
-       fi
-
-       local TMP_CACHE=`mktemp -p /tmp zpool.cache.XXXXXXXX`
-       test_setup ${POOL_NAME} ${POOL_CONFIG} ${ZVOL_NAME} ${TMP_CACHE}
-
-       # Set hard write failure for first vdev device.
-       local VDEV_FAULTY=`nth_zpool_vdev ${POOL_NAME} md 1`
-       fault_set_md ${VDEV_FAULTY} write-persistent
-
-       # The application must not observe an error.
-       local TMP_PATTERN=`pattern_create 1M 8` || fail 11
-       pattern_write ${TMP_PATTERN} 1M 8 ${ZVOL_DEVICE} || fail 12
-       fault_clear_md ${VDEV_FAULTY}
-
-       local WRITE_ERRORS=`vdev_write_errors ${POOL_NAME} ${VDEV_FAULTY}`
-       if [ ${POOL_REDUNDANT} -eq 1 ]; then
-               # For redundant configurations hard errors will not be
-               # logged to 'zpool status' but will generate EIO events.
-               test ${WRITE_ERRORS} -eq 0 || fail 21
-               test `zpool_event "zfs.io" "zio_err"` = "0x5" || fail 22
-       else
-               # For non-redundant configurations hard errors will be
-               # logged to 'zpool status' and generate EIO events.  They
-               # will also trigger a scrub of the impacted sectors.
-               sleep 10
-               test ${WRITE_ERRORS} -gt 0 || fail 31
-               test `zpool_event "zfs.io" "zio_err"` = "0x5" || fail 32
-               test `zpool_event "zfs.resilver.start" "ena"` != "" || fail 33
-               test `zpool_event "zfs.resilver.finish" "ena"` != "" || fail 34
-               test `zpool_scan_errors ${POOL_NAME}` -eq 0 || fail 35
-       fi
-
-       # Verify the known pattern.
-       pattern_verify ${TMP_PATTERN} 1M 8 ${ZVOL_DEVICE} || fail 41
-       pattern_remove ${TMP_PATTERN} || fail 42
-
-       test_cleanup ${POOL_NAME} ${POOL_CONFIG} ${ZVOL_NAME} ${TMP_CACHE}
-       pass_nonewline
-}
-
-# Hard write error.
-test_2() {
-       test_write_hard tank lo-faulty-raid0  0
-       test_write_hard tank lo-faulty-raid10 1
-       test_write_hard tank lo-faulty-raidz  1
-       test_write_hard tank lo-faulty-raidz2 1
-       test_write_hard tank lo-faulty-raidz3 1
-       echo
-}
-run_test 2 "hard write error"
-
-test_write_all() {
-       local POOL_NAME=$1
-       local POOL_CONFIG=$2
-       local POOL_REDUNDANT=$3
-       local ZVOL_NAME="zvol"
-       local ZVOL_DEVICE="/dev/${POOL_NAME}/${ZVOL_NAME}"
-
-       if [ ${MD_PARTITIONABLE} -eq 0 ]; then
-               skip_nonewline
-               return
-       fi
-
-       local TMP_CACHE=`mktemp -p /tmp zpool.cache.XXXXXXXX`
-       test_setup ${POOL_NAME} ${POOL_CONFIG} ${ZVOL_NAME} ${TMP_CACHE}
-
-       # Set all write failures for first vdev device.
-       local VDEV_FAULTY=`nth_zpool_vdev ${POOL_NAME} md 1`
-       fault_set_md ${VDEV_FAULTY} write-all
-
-       local TMP_PATTERN=`pattern_create 1M 8` || fail 11
-       if [ ${POOL_REDUNDANT} -eq 1 ]; then
-               # The application must not observe an error.
-               pattern_write ${TMP_PATTERN} 1M 8 ${ZVOL_DEVICE} || fail 12
-       else
-               # The application is expected to hang in the background until
-               # the faulty device is repaired and 'zpool clear' is run.
-               pattern_write_bg ${TMP_PATTERN} 1M 8 ${ZVOL_DEVICE} || fail 13
-               sleep 10
-       fi
-       fault_clear_md ${VDEV_FAULTY}
-
-       local WRITE_ERRORS=`vdev_write_errors ${POOL_NAME} ${VDEV_FAULTY}`
-       local VDEV_STATUS=`vdev_status ${POOL_NAME} ${VDEV_FAULTY}`
-       local POOL_STATE=`zpool_state ${POOL_NAME}`
-       # For all configurations write errors are logged to 'zpool status',
-       # and EIO events are generated.  However, only a redundant config
-       # will cause the vdev to be FAULTED and pool DEGRADED.  In a non-
-       # redundant config the IO will hang until 'zpool clear' is run.
-       test ${WRITE_ERRORS} -gt 0 || fail 14
-       test `zpool_event "zfs.io" "zio_err"` = "0x5" || fail 15
-
-       if [ ${POOL_REDUNDANT} -eq 1 ]; then
-               test "${VDEV_STATUS}" = "FAULTED" || fail 21
-               test "${POOL_STATE}" = "DEGRADED" || fail 22
-       else
-               BLOCKED=`ps a | grep "${ZVOL_DEVICE}" | grep -c -v "grep"`
-               ${ZPOOL} clear  ${POOL_NAME} || fail 31
-               test ${BLOCKED} -eq 1 || fail 32
-               wait
-       fi
-
-       # Verify the known pattern.
-       pattern_verify ${TMP_PATTERN} 1M 8 ${ZVOL_DEVICE} || fail 41
-       pattern_remove ${TMP_PATTERN} || fail 42
-
-       test_cleanup ${POOL_NAME} ${POOL_CONFIG} ${ZVOL_NAME} ${TMP_CACHE}
-       pass_nonewline
-}
-
-# All write errors.
-test_3() {
-       test_write_all tank lo-faulty-raid0  0
-       test_write_all tank lo-faulty-raid10 1
-       test_write_all tank lo-faulty-raidz  1
-       test_write_all tank lo-faulty-raidz2 1
-       test_write_all tank lo-faulty-raidz3 1
-       echo
-}
-run_test 3 "all write errors"
-
-test_read_soft() {
-       local POOL_NAME=$1
-       local POOL_CONFIG=$2
-       local POOL_REDUNDANT=$3
-       local ZVOL_NAME="zvol"
-       local ZVOL_DEVICE="/dev/${POOL_NAME}/${ZVOL_NAME}"
-       local READ_ERRORS=0
-
-       if [ ${MD_PARTITIONABLE} -eq 0 ]; then
-               skip_nonewline
-               return
-       fi
-
-       local TMP_CACHE=`mktemp -p /tmp zpool.cache.XXXXXXXX`
-       test_setup ${POOL_NAME} ${POOL_CONFIG} ${ZVOL_NAME} ${TMP_CACHE}
-
-       # Create a pattern to be verified during a read error.
-       local TMP_PATTERN=`pattern_create 1M 8` || fail 11
-       pattern_write ${TMP_PATTERN} 1M 8 ${ZVOL_DEVICE} || fail 12
-
-       # Set soft read failure for all the vdevs to ensure we hit it.
-       for (( i=1; i<=4; i++ )); do
-               fault_set_md `nth_zpool_vdev ${POOL_NAME} md $i` read-transient
-       done
-
-       pattern_verify ${TMP_PATTERN} 1M 8 ${ZVOL_DEVICE} || fail 13
-       pattern_remove ${TMP_PATTERN} || fail 14
-
-       # Clear all failure injection and sum read errors.
-       for (( i=1; i<=4; i++ )); do
-               local VDEV_FAULTY=`nth_zpool_vdev ${POOL_NAME} md $i`
-               local VDEV_ERRORS=`vdev_read_errors ${POOL_NAME} ${VDEV_FAULTY}`
-               let READ_ERRORS=${READ_ERRORS}+${VDEV_ERRORS}
-               fault_clear_md ${VDEV_FAULTY}
-       done
-
-       # Soft errors will not be logged to 'zpool status'.
-       test ${READ_ERRORS} -eq 0 || fail 15
-
-       # Soft errors will still generate an EIO (5) event.
-       test `zpool_event "zfs.io" "zio_err"` = "0x5" || fail 16
-
-       test_cleanup ${POOL_NAME} ${POOL_CONFIG} ${ZVOL_NAME} ${TMP_CACHE}
-       pass_nonewline
-}
-
-# Soft read error.
-test_4() {
-       test_read_soft tank lo-faulty-raid0  0
-       test_read_soft tank lo-faulty-raid10 1
-       test_read_soft tank lo-faulty-raidz  1
-       test_read_soft tank lo-faulty-raidz2 1
-       test_read_soft tank lo-faulty-raidz3 1
-       echo
-}
-run_test 4 "soft read error"
-
-test_read_hard() {
-       local POOL_NAME=$1
-       local POOL_CONFIG=$2
-       local POOL_REDUNDANT=$3
-       local ZVOL_NAME="zvol"
-       local ZVOL_DEVICE="/dev/${POOL_NAME}/${ZVOL_NAME}"
-       local READ_ERRORS=0
-
-       if [ ${MD_PARTITIONABLE} -eq 0 ]; then
-               skip_nonewline
-               return
-       fi
-
-       local TMP_CACHE=`mktemp -p /tmp zpool.cache.XXXXXXXX`
-       test_setup ${POOL_NAME} ${POOL_CONFIG} ${ZVOL_NAME} ${TMP_CACHE}
-
-       # Create a pattern to be verified during a read error.
-       local TMP_PATTERN=`pattern_create 1M 8` || fail 11
-       pattern_write ${TMP_PATTERN} 1M 8 ${ZVOL_DEVICE} || fail 12
-
-       # Set hard read failure for the fourth vdev.
-       local VDEV_FAULTY=`nth_zpool_vdev ${POOL_NAME} md 4`
-       fault_set_md ${VDEV_FAULTY} read-persistent
-
-       # For a redundant pool there must be no IO error, for a non-redundant
-       # pool we expect permanent damage and an IO error during verify, unless
-       # we get exceptionally lucky and have just damaged redundant metadata.
-       if [ ${POOL_REDUNDANT} -eq 1 ]; then
-               pattern_verify ${TMP_PATTERN} 1M 8 ${ZVOL_DEVICE} || fail 21
-               local READ_ERRORS=`vdev_read_errors ${POOL_NAME} ${VDEV_FAULTY}`
-               test ${READ_ERRORS} -eq 0 || fail 22
-       else
-               pattern_verify ${TMP_PATTERN} 1M 8 ${ZVOL_DEVICE}
-               ${ZPOOL} scrub ${POOL_NAME} || fail 32
-               local READ_ERRORS=`vdev_read_errors ${POOL_NAME} ${VDEV_FAULTY}`
-               test ${READ_ERRORS} -gt 0 || fail 33
-               ${ZPOOL} status -v ${POOL_NAME} |     \
-                       grep -A8 "Permanent errors" | \
-                       grep -q "${POOL_NAME}" || fail 34
-       fi
-       pattern_remove ${TMP_PATTERN} || fail 41
-
-       # Clear all failure injection and sum read errors.
-       fault_clear_md ${VDEV_FAULTY}
-
-       # Hard errors will generate an EIO (5) event.
-       test `zpool_event "zfs.io" "zio_err"` = "0x5" || fail 42
-
-       test_cleanup ${POOL_NAME} ${POOL_CONFIG} ${ZVOL_NAME} ${TMP_CACHE}
-       pass_nonewline
-}
-
-# Hard read error.
-test_5() {
-       test_read_hard tank lo-faulty-raid0  0
-       test_read_hard tank lo-faulty-raid10 1
-       test_read_hard tank lo-faulty-raidz  1
-       test_read_hard tank lo-faulty-raidz2 1
-       test_read_hard tank lo-faulty-raidz3 1
-       echo
-}
-run_test 5 "hard read error"
-
-# Fixable read error.
-test_read_fixable() {
-       local POOL_NAME=$1
-       local POOL_CONFIG=$2
-       local POOL_REDUNDANT=$3
-       local ZVOL_NAME="zvol"
-       local ZVOL_DEVICE="/dev/${POOL_NAME}/${ZVOL_NAME}"
-       local READ_ERRORS=0
-
-       if [ ${MD_PARTITIONABLE} -eq 0 ]; then
-               skip_nonewline
-               return
-       fi
-
-       local TMP_CACHE=`mktemp -p /tmp zpool.cache.XXXXXXXX`
-       test_setup ${POOL_NAME} ${POOL_CONFIG} ${ZVOL_NAME} ${TMP_CACHE}
-
-       # Create a pattern to be verified during a read error.
-       local TMP_PATTERN=`pattern_create 1M 8` || fail 11
-       pattern_write ${TMP_PATTERN} 1M 8 ${ZVOL_DEVICE} || fail 12
-
-       # Set hard read failure for the fourth vdev.
-       local VDEV_FAULTY=`nth_zpool_vdev ${POOL_NAME} md 4`
-       fault_set_md ${VDEV_FAULTY} read-fixable
-
-       # For a redundant pool there must be no IO error, for a non-redundant
-       # pool we expect permanent damage and an IO error during verify, unless
-       # we get exceptionally lucky and have just damaged redundant metadata.
-       if [ ${POOL_REDUNDANT} -eq 1 ]; then
-               pattern_verify ${TMP_PATTERN} 1M 8 ${ZVOL_DEVICE} || fail 21
-               local READ_ERRORS=`vdev_read_errors ${POOL_NAME} ${VDEV_FAULTY}`
-               test ${READ_ERRORS} -eq 0 || fail 22
-       else
-               pattern_verify ${TMP_PATTERN} 1M 8 ${ZVOL_DEVICE}
-               ${ZPOOL} scrub ${POOL_NAME} || fail 32
-               local READ_ERRORS=`vdev_read_errors ${POOL_NAME} ${VDEV_FAULTY}`
-               test ${READ_ERRORS} -gt 0 || fail 33
-               ${ZPOOL} status -v ${POOL_NAME} |     \
-                       grep -A8 "Permanent errors" | \
-                       grep -q "${POOL_NAME}" || fail 34
-       fi
-       pattern_remove ${TMP_PATTERN} || fail 41
-
-       # Clear all failure injection and sum read errors.
-       fault_clear_md ${VDEV_FAULTY}
-
-       # Hard errors will generate an EIO (5) event.
-       test `zpool_event "zfs.io" "zio_err"` = "0x5" || fail 42
-
-       test_cleanup ${POOL_NAME} ${POOL_CONFIG} ${ZVOL_NAME} ${TMP_CACHE}
-       pass_nonewline
-}
-
-# Read errors fixable with a write.
-test_6() {
-       test_read_fixable tank lo-faulty-raid0  0
-       test_read_fixable tank lo-faulty-raid10 1
-       test_read_fixable tank lo-faulty-raidz  1
-       test_read_fixable tank lo-faulty-raidz2 1
-       test_read_fixable tank lo-faulty-raidz3 1
-       echo
-}
-run_test 6 "fixable read error"
-
-test_cksum() {
-       local POOL_NAME=$1
-       local POOL_CONFIG=$2
-       local POOL_REDUNDANT=$3
-       local VDEV_DAMAGE="$4"
-       local ZVOL_NAME="zvol"
-       local ZVOL_DEVICE="/dev/${POOL_NAME}/${ZVOL_NAME}"
-
-       if [ ${MD_PARTITIONABLE} -eq 0 ]; then
-               skip_nonewline
-               return
-       fi
-
-       local TMP_CACHE=`mktemp -p /tmp zpool.cache.XXXXXXXX`
-       test_setup ${POOL_NAME} ${POOL_CONFIG} ${ZVOL_NAME} ${TMP_CACHE}
-
-       # Create a pattern to be verified.
-       local TMP_PATTERN=`pattern_create 1M 8` || fail 11
-       pattern_write ${TMP_PATTERN} 1M 8 ${ZVOL_DEVICE} || fail 12
-
-       # Verify the pattern and that no vdev has cksum errors.
-       pattern_verify ${TMP_PATTERN} 1M 8 ${ZVOL_DEVICE} || fail 13
-       for (( i=1; i<4; i++ )); do
-               VDEV_FAULTY=`nth_zpool_vdev ${POOL_NAME} md ${i}`
-               CKSUM_ERRORS=`vdev_cksum_errors ${POOL_NAME} ${VDEV_FAULTY}`
-               test ${CKSUM_ERRORS} -eq 0 || fail 14
-       done
-
-       # Corrupt the bulk of a vdev with random garbage, we damage as many
-       # vdevs as we have levels of redundancy.  For example for a raidz3
-       # configuration we can trash 3 vdevs and still expect correct data.
-       # This improves the odds that we read one of the damaged vdevs.
-       for VDEV in ${VDEV_DAMAGE}; do
-               VDEV_FAULTY=`nth_zpool_vdev ${POOL_NAME} md $VDEV`
-               pattern_write /dev/urandom 1M 64 /dev/${VDEV_FAULTY}p1
-       done
-
-       # Verify the pattern is still correct.  For non-redundant pools
-       # expect failure and for redundant pools success due to resilvering.
-       if [ ${POOL_REDUNDANT} -eq 1 ]; then
-               pattern_verify ${TMP_PATTERN} 1M 8 ${ZVOL_DEVICE} || fail 16
-       else
-               pattern_verify ${TMP_PATTERN} 1M 8 ${ZVOL_DEVICE} && fail 17
-       fi
-
-       CKSUM_ERRORS=`vdev_cksum_errors ${POOL_NAME} ${VDEV_FAULTY}`
-       test ${CKSUM_ERRORS} -gt 0 || fail 18
-       STATUS=`vdev_status ${POOL_NAME} ${VDEV_FAULTY}`
-       test "${STATUS}" = "ONLINE" || fail 19
-
-       # The checksum errors must be logged as an event.
-       local CKSUM_ERRORS=`zpool_event "zfs.checksum" "zio_err"`
-       test ${CKSUM_ERRORS} = "0x34" || test ${CKSUM_ERRORS} = "0x0" || fail 20
-
-       # Verify permant errors for non-redundant pools, and for redundant
-       # pools trigger a scrub and check that all checksums have been fixed.
-       if [ ${POOL_REDUNDANT} -eq 1 ]; then
-               # Scrub the checksum errors and clear the faults.
-               ${ZPOOL} scrub ${POOL_NAME} || fail 21
-               sleep 3
-               ${ZPOOL} clear ${POOL_NAME} || fail 22
-
-               # Re-verify the pattern for fixed checksums.
-               pattern_verify ${TMP_PATTERN} 1M 8 ${ZVOL_DEVICE} || fail 23
-               CKSUM_ERRORS=`vdev_cksum_errors ${POOL_NAME} ${VDEV_FAULTY}`
-               test ${CKSUM_ERRORS} -eq 0 || fail 24
-
-               # Re-verify the entire pool for fixed checksums.
-               ${ZPOOL} scrub ${POOL_NAME} || fail 25
-               CKSUM_ERRORS=`vdev_cksum_errors ${POOL_NAME} ${VDEV_FAULTY}`
-               test ${CKSUM_ERRORS} -eq 0 || fail 26
-       else
-               ${ZPOOL} status -v ${POOL_NAME} |     \
-                       grep -A8 "Permanent errors" | \
-                       grep -q "${POOL_NAME}/${ZVOL_NAME}" || fail 31
-               ${ZPOOL} clear ${POOL_NAME} || fail 32
-       fi
-       pattern_remove ${TMP_PATTERN} || fail 41
-
-       test_cleanup ${POOL_NAME} ${POOL_CONFIG} ${ZVOL_NAME} ${TMP_CACHE}
-       pass_nonewline
-}
-
-# Silent data corruption
-test_7() {
-       test_cksum tank lo-faulty-raid0  0 "1"
-       test_cksum tank lo-faulty-raid10 1 "1 3"
-       test_cksum tank lo-faulty-raidz  1 "4"
-       test_cksum tank lo-faulty-raidz2 1 "3 4"
-       test_cksum tank lo-faulty-raidz3 1 "2 3 4"
-       echo
-}
-run_test 7 "silent data corruption"
-
-# Soft write timeout at the scsi device layer.
-test_write_timeout_soft() {
-       local POOL_NAME=$1
-       local POOL_CONFIG=$2
-       local POOL_REDUNDANT=$3
-       local POOL_NTH=$4
-       local ZVOL_NAME="zvol"
-       local ZVOL_DEVICE="/dev/${POOL_NAME}/${ZVOL_NAME}"
-
-       if [ ${SCSI_DEBUG} -eq 0 ]; then
-               skip_nonewline
-               return
-       fi
-
-       local TMP_CACHE=`mktemp -p /tmp zpool.cache.XXXXXXXX`
-       test_setup ${POOL_NAME} ${POOL_CONFIG} ${ZVOL_NAME} ${TMP_CACHE}
-
-       # Set timeout(0x4) for every nth command.
-       fault_set_sd  4 ${POOL_NTH}
-
-       # The application must not observe an error.
-       local TMP_PATTERN=`pattern_create 1M 8` || fail 11
-       pattern_write ${TMP_PATTERN} 1M 8 ${ZVOL_DEVICE} || fail 12
-       fault_clear_sd
-
-       # Intermittent write timeouts even with FAILFAST set may not cause
-       # an EIO (5) event.  This is because how FAILFAST is handled depends
-       # a log on the low level driver and the exact nature of the failure.
-       # We will however see a 'zfs.delay' event logged due to the timeout.
-       VDEV_DELAY=`zpool_event "zfs.delay" "zio_delay"`
-       test `printf "%d" ${VDEV_DELAY}` -ge 30000 || fail 13
-
-       # Verify the known pattern.
-       pattern_verify ${TMP_PATTERN} 1M 8 ${ZVOL_DEVICE} || fail 14
-       pattern_remove ${TMP_PATTERN} || fail 15
-
-       test_cleanup ${POOL_NAME} ${POOL_CONFIG} ${ZVOL_NAME} ${TMP_CACHE}
-       pass_nonewline
-}
-
-test_8() {
-       test_write_timeout_soft tank scsi_debug-raid0  0 50
-       test_write_timeout_soft tank scsi_debug-raid10 1 100
-       test_write_timeout_soft tank scsi_debug-raidz  1 75
-       test_write_timeout_soft tank scsi_debug-raidz2 1 150
-       test_write_timeout_soft tank scsi_debug-raidz3 1 300
-       echo
-}
-run_test 8 "soft write timeout"
-
-# Persistent write timeout at the scsi device layer.
-test_write_timeout_hard() {
-       local POOL_NAME=$1
-       local POOL_CONFIG=$2
-       local POOL_REDUNDANT=$3
-       local POOL_NTH=$4
-       local ZVOL_NAME="zvol"
-       local ZVOL_DEVICE="/dev/${POOL_NAME}/${ZVOL_NAME}"
-       local RESCAN=1
-
-       if [ ${SCSI_DEBUG} -eq 0 ]; then
-               skip_nonewline
-               return
-       fi
-
-       local TMP_CACHE=`mktemp -p /tmp zpool.cache.XXXXXXXX`
-       test_setup ${POOL_NAME} ${POOL_CONFIG} ${ZVOL_NAME} ${TMP_CACHE}
-
-       local TMP_PATTERN1=`pattern_create 1M 8`
-       local TMP_PATTERN2=`pattern_create 1M 8`
-       local TMP_PATTERN3=`pattern_create 1M 8`
-
-       # Create three partitions each one gets a unique pattern.  The first
-       # pattern is written before the failure, the second pattern during
-       # the failure, and the third pattern while the vdev is degraded.
-       # All three patterns are verified while the vdev is degraded and
-       # then again once it is brought back online.
-       ${PARTED} -s ${ZVOL_DEVICE} mklabel gpt || fail 11
-       ${PARTED} -s ${ZVOL_DEVICE} mkpart primary 1M 16M || fail 12
-       ${PARTED} -s ${ZVOL_DEVICE} mkpart primary 16M 32M || fail 13
-       ${PARTED} -s ${ZVOL_DEVICE} mkpart primary 32M 48M || fail 14
-
-       wait_udev ${ZVOL_DEVICE}1 30
-       wait_udev ${ZVOL_DEVICE}2 30
-       wait_udev ${ZVOL_DEVICE}3 30
-
-       # Before the failure.
-       pattern_write ${TMP_PATTERN1} 1M 8 ${ZVOL_DEVICE}1 || fail 15
-
-       # Get the faulty vdev name.
-       local VDEV_FAULTY=`nth_zpool_vdev ${POOL_NAME} sd 1`
-
-       # Set timeout(0x4) for every nth command.
-       fault_set_sd  4 ${POOL_NTH}
-
-       # During the failure.
-       pattern_write ${TMP_PATTERN2} 1M 8 ${ZVOL_DEVICE}2 || fail 21
-
-       # Expect write errors to be logged to 'zpool status'
-       local WRITE_ERRORS=`vdev_write_errors ${POOL_NAME} ${VDEV_FAULTY}`
-       test ${WRITE_ERRORS} -gt 0 || fail 22
-
-       local VDEV_STATUS=`vdev_status ${POOL_NAME} ${VDEV_FAULTY}`
-       test "${VDEV_STATUS}" = "UNAVAIL" || fail 23
-
-       # Clear the error and remove it from /dev/.
-       fault_clear_sd
-       rm -f /dev/${VDEV_FAULTY}[0-9]
-
-       # Verify the first two patterns and write out the third.
-       pattern_write ${TMP_PATTERN3} 1M 8 ${ZVOL_DEVICE}3 || fail 31
-       pattern_verify ${TMP_PATTERN1} 1M 8 ${ZVOL_DEVICE}1 || fail 32
-       pattern_verify ${TMP_PATTERN2} 1M 8 ${ZVOL_DEVICE}2 || fail 33
-       pattern_verify ${TMP_PATTERN3} 1M 8 ${ZVOL_DEVICE}3 || fail 34
-
-       # Bring the device back online by rescanning for it.  It must appear
-       # in lsscsi and be available to dd before allowing ZFS to bring it
-       # online.  This is not required but provides additional sanity.
-       while [ ${RESCAN} -eq 1 ]; do
-               scsi_rescan
-               wait_udev /dev/${VDEV_FAULTY} 30
-
-               if [ `${LSSCSI} | grep -c "/dev/${VDEV_FAULTY}"` -eq 0 ]; then
-                       continue
-               fi
-
-               dd if=/dev/${VDEV_FAULTY} of=/dev/null bs=8M count=1 &>/dev/null
-               if [ $? -ne 0 ]; then
-                       continue
-               fi
-
-               RESCAN=0
-       done
-
-       # Bring the device back online.  We expect it to be automatically
-       # resilvered without error and we should see minimally the zfs.io,
-       # zfs.statechange (VDEV_STATE_HEALTHY (0x7)), and zfs.resilver.*
-       # events posted.
-       ${ZPOOL} online ${POOL_NAME} ${VDEV_FAULTY} || fail 51
-       sleep 3
-       test `zpool_event "zfs.io" "zio_err"` = "0x5" || fail 52
-       test `zpool_event "zfs.statechange" "vdev_state"` = "0x7" || fail 53
-       test `zpool_event "zfs.resilver.start" "ena"` != "" || fail 54
-       test `zpool_event "zfs.resilver.finish" "ena"` != "" || fail 55
-       test `zpool_scan_errors ${POOL_NAME}` -eq 0 || fail 56
-
-       local VDEV_STATUS=`vdev_status ${POOL_NAME} ${VDEV_FAULTY}`
-       test "${VDEV_STATUS}" = "ONLINE" || fail 57
-
-       # Verify the known pattern.
-       pattern_verify ${TMP_PATTERN1} 1M 8 ${ZVOL_DEVICE}1 || fail 61
-       pattern_verify ${TMP_PATTERN2} 1M 8 ${ZVOL_DEVICE}2 || fail 62
-       pattern_verify ${TMP_PATTERN3} 1M 8 ${ZVOL_DEVICE}3 || fail 63
-       pattern_remove ${TMP_PATTERN1} || fail 64
-       pattern_remove ${TMP_PATTERN2} || fail 65
-       pattern_remove ${TMP_PATTERN3} || fail 66
-
-       test_cleanup ${POOL_NAME} ${POOL_CONFIG} ${ZVOL_NAME} ${TMP_CACHE}
-       pass_nonewline
-}
-
-test_9() {
-       skip_nonewline # Skip non-redundant config
-       test_write_timeout_hard tank scsi_debug-raid10 1 -50
-       test_write_timeout_hard tank scsi_debug-raidz  1 -50
-       test_write_timeout_hard tank scsi_debug-raidz2 1 -50
-       test_write_timeout_hard tank scsi_debug-raidz3 1 -50
-       echo
-}
-run_test 9 "hard write timeout"
-
-exit 0
diff --git a/scripts/zfs-tests.sh b/scripts/zfs-tests.sh
new file mode 100755 (executable)
index 0000000..0c8a56c
--- /dev/null
@@ -0,0 +1,343 @@
+#!/bin/bash
+#
+# CDDL HEADER START
+#
+# The contents of this file are subject to the terms of the
+# Common Development and Distribution License, Version 1.0 only
+# (the "License").  You may not use this file except in compliance
+# with the License.
+#
+# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
+# or http://www.opensolaris.org/os/licensing.
+# See the License for the specific language governing permissions
+# and limitations under the License.
+#
+# When distributing Covered Code, include this CDDL HEADER in each
+# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
+# If applicable, add the following below this CDDL HEADER, with the
+# fields enclosed by brackets "[]" replaced with your own identifying
+# information: Portions Copyright [yyyy] [name of copyright owner]
+#
+# CDDL HEADER END
+#
+basedir="$(dirname $0)"
+
+SCRIPT_COMMON=common.sh
+if [ -f "${basedir}/${SCRIPT_COMMON}" ]; then
+. "${basedir}/${SCRIPT_COMMON}"
+else
+echo "Missing helper script ${SCRIPT_COMMON}" && exit 1
+fi
+
+. $STF_SUITE/include/default.cfg
+
+PROG=zfs-tests.sh
+SUDO=/usr/bin/sudo
+SETENFORCE=/usr/sbin/setenforce
+VERBOSE=
+QUIET=
+CLEANUP=1
+CLEANUPALL=0
+LOOPBACK=1
+FILESIZE="2G"
+RUNFILE=${RUNFILE:-"linux.run"}
+FILEDIR=${FILEDIR:-/var/tmp}
+DISKS=${DISKS:-""}
+
+#
+# Attempt to remove loopback devices and files which where created earlier
+# by this script to run the test framework.  The '-k' option may be passed
+# to the script to suppress cleanup for debugging purposes.
+#
+cleanup() {
+       if [ $CLEANUP -eq 0 ]; then
+               return 0
+       fi
+
+       if [ $LOOPBACK -eq 1 ]; then
+               for TEST_LOOPBACK in ${LOOPBACKS}; do
+                       LOOP_DEV=$(basename $TEST_LOOPBACK)
+                       DM_DEV=$(${SUDO} ${DMSETUP} ls 2>/dev/null | \
+                           grep ${LOOP_DEV} | cut -f1)
+
+                       if [ -n "$DM_DEV" ]; then
+                               ${SUDO} ${DMSETUP} remove ${DM_DEV} ||
+                                   echo "Failed to remove: ${DM_DEV}"
+                       fi
+
+                       if [ -n "${TEST_LOOPBACK}" ]; then
+                               ${SUDO} ${LOSETUP} -d ${TEST_LOOPBACK} ||
+                                   echo "Failed to remove: ${TEST_LOOPBACK}"
+                       fi
+               done
+       fi
+
+       for TEST_FILE in ${FILES}; do
+               rm -f ${TEST_FILE} &>/dev/null
+       done
+}
+trap cleanup EXIT
+
+#
+# Attempt to remove all testpools (testpool.XXX), unopened dm devices,
+# loopback devices, and files.  This is a useful way to cleanup a previous
+# test run failure which has left the system in an unknown state.  This can
+# be dangerous and should only be used in a dedicated test environment.
+#
+cleanup_all() {
+       local TEST_POOLS=$(${SUDO} ${ZPOOL} list -H -o name | grep testpool)
+       local TEST_LOOPBACKS=$(${SUDO} ${LOSETUP} -a|grep file-vdev|cut -f1 -d:)
+       local TEST_FILES=$(ls /var/tmp/file-vdev* 2>/dev/null)
+
+       msg
+       msg "--- Cleanup ---"
+       msg "Removing pool(s):     $(echo ${TEST_POOLS} | tr '\n' ' ')"
+       for TEST_POOL in $TEST_POOLS; do
+               ${SUDO} ${ZPOOL} destroy ${TEST_POOL}
+       done
+
+       msg "Removing dm(s):       $(${SUDO} ${DMSETUP} ls |
+           grep loop | tr '\n' ' ')"
+       ${SUDO} ${DMSETUP} remove_all
+
+       msg "Removing loopback(s): $(echo ${TEST_LOOPBACKS} | tr '\n' ' ')"
+       for TEST_LOOPBACK in $TEST_LOOPBACKS; do
+               ${SUDO} ${LOSETUP} -d ${TEST_LOOPBACK}
+       done
+
+       msg "Removing files(s):    $(echo ${TEST_FILES} | tr '\n' ' ')"
+       for TEST_FILE in $TEST_FILES; do
+               ${SUDO} rm -f ${TEST_FILE}
+       done
+}
+
+#
+# Log a failure message, cleanup, and return an error.
+#
+fail() {
+        echo -e "${PROG}: $1" >&2
+       cleanup
+       exit 1
+}
+
+#
+# Takes a name as the only arguments and looks for the following variations
+# on that name.  If one is found it is returned.
+#
+# $RUNFILEDIR/<name>
+# $RUNFILEDIR/<name>.run
+# <name>
+# <name>.run
+#
+find_runfile() {
+       local NAME=$1
+       local RESULT=""
+
+       if [ -f "$RUNFILEDIR/$NAME" ]; then
+               RESULT="$RUNFILEDIR/$NAME"
+       elif [ -f "$RUNFILEDIR/$NAME.run" ]; then
+               RESULT="$RUNFILEDIR/$NAME.run"
+       elif [ -f "$NAME" ]; then
+               RESULT="$NAME"
+       elif [ -f "$NAME.run" ]; then
+               RESULT="$NAME.run"
+       fi
+
+       echo "$RESULT"
+}
+
+#
+# Output a useful usage message.
+#
+usage() {
+cat << EOF
+USAGE:
+$0 [hvqxkf] [-s SIZE] [-r RUNFILE]
+
+DESCRIPTION:
+       ZFS Test Suite launch script
+
+OPTIONS:
+       -h          Show this message
+       -v          Verbose zfs-tests.sh output
+       -q          Quiet test-runner output
+       -x          Remove all testpools, dm, lo, and files (unsafe)
+       -k          Disable cleanup after test failure
+       -f          Use files only, disables block device tests
+       -d DIR      Use DIR for files and loopback devices
+       -s SIZE     Use vdevs of SIZE (default: 4G)
+       -r RUNFILE  Run tests in RUNFILE (default: linux.run)
+
+EXAMPLES:
+# Run the default (linux) suite of tests and output the configuration used.
+$0 -v
+
+# Run a smaller suite of tests designed to run more quickly.
+$0 -r linux-fast
+
+# Cleanup a previous run of the test suite prior to testing, run the
+# default (linux) suite of tests and perform no cleanup on exit.
+$0 -c
+
+EOF
+}
+
+while getopts 'hvqxkfd:s:r:?' OPTION; do
+       case $OPTION in
+       h)
+               usage
+               exit 1
+               ;;
+       v)
+               VERBOSE=1
+               ;;
+       q)
+               QUIET="-q"
+               ;;
+       x)
+               CLEANUPALL=1
+               ;;
+       k)
+               CLEANUP=0
+               ;;
+       f)
+               LOOPBACK=0
+               ;;
+       d)
+               FILEDIR="$OPTARG"
+               ;;
+       s)
+               FILESIZE="$OPTARG"
+               ;;
+       r)
+               RUNFILE="$OPTARG"
+               ;;
+       ?)
+               usage
+               exit
+               ;;
+       esac
+done
+
+shift $((OPTIND-1))
+
+FILES=${FILES:-"$FILEDIR/file-vdev0 $FILEDIR/file-vdev1 $FILEDIR/file-vdev2"}
+LOOPBACKS=${LOOPBACKS:-""}
+
+#
+# Attempt to locate the runfile describing the test workload.
+#
+if [ -n "$RUNFILE" ]; then
+       SAVED_RUNFILE="$RUNFILE"
+       RUNFILE=$(find_runfile "$RUNFILE")
+       [ -z "$RUNFILE" ] && fail "Cannot find runfile: $SAVED_RUNFILE"
+fi
+
+if [ ! -r "$RUNFILE" ]; then
+       fail "Cannot read runfile: $RUNFILE"
+fi
+
+#
+# This script should not be run as root.  Instead the test user, which may
+# be a normal user account, needs to be configured such that it can
+# run commands via sudo passwordlessly.
+#
+if [ $(id -u) = "0" ]; then
+       fail "This script must not be run as root."
+fi
+
+if [ $(sudo whoami) != "root" ]; then
+       fail "Passwordless sudo access required."
+fi
+
+#
+# Verify the ZFS module stack if loaded.
+#
+${SUDO} ${ZFS_SH} &>/dev/null
+
+#
+# Attempt to cleanup all previous state for a new test run.
+#
+if [ $CLEANUPALL -ne 0 ]; then
+       cleanup_all
+fi
+
+#
+# By default preserve any existing pools
+#
+if [ -z "${KEEP}" ]; then
+       KEEP=$(${SUDO} ${ZPOOL} list -H -o name)
+       if [ -z "${KEEP}" ]; then
+               KEEP="rpool"
+       fi
+fi
+
+msg
+msg "--- Configuration ---"
+msg "Runfile:         $RUNFILE"
+msg "STF_TOOLS:       $STF_TOOLS"
+msg "STF_SUITE:       $STF_SUITE"
+
+#
+# No DISKS have been provided so a basic file or loopback based devices
+# must be created for the test suite to use.
+#
+if [ -z "${DISKS}" ]; then
+       #
+       # Create sparse files for the test suite.  These may be used
+       # directory or have loopback devices layered on them.
+       #
+       for TEST_FILE in ${FILES}; do
+               [ -f "$TEST_FILE" ] && fail "Failed file exists: ${TEST_FILE}"
+               truncate -s ${FILESIZE} ${TEST_FILE} ||
+                   fail "Failed creating: ${TEST_FILE} ($?)"
+               DISKS="$DISKS$TEST_FILE "
+       done
+
+       #
+       # If requested setup loopback devices backed by the sparse files.
+       #
+       if [ $LOOPBACK -eq 1 ]; then
+               DISKS=""
+               check_loop_utils
+
+               for TEST_FILE in ${FILES}; do
+                       TEST_LOOPBACK=$(${SUDO} ${LOSETUP} -f)
+                       ${SUDO} ${LOSETUP} ${TEST_LOOPBACK} ${TEST_FILE} ||
+                           fail "Failed: ${TEST_FILE} -> ${TEST_LOOPBACK}"
+                       LOOPBACKS="${LOOPBACKS}${TEST_LOOPBACK} "
+                       DISKS="$DISKS$(basename $TEST_LOOPBACK) "
+               done
+       fi
+fi
+
+NUM_DISKS=$(echo ${DISKS} | $AWK '{print NF}')
+[ $NUM_DISKS -lt 3 ] && fail "Not enough disks ($NUM_DISKS/3 minimum)"
+
+#
+# Disable SELinux until the ZFS Test Suite has been updated accordingly.
+#
+if [ -x ${SETENFORCE} ]; then
+       ${SUDO} ${SETENFORCE} permissive &>/dev/null
+fi
+
+msg "FILEDIR:         $FILEDIR"
+msg "FILES:           $FILES"
+msg "LOOPBACKS:       $LOOPBACKS"
+msg "DISKS:           $DISKS"
+msg "NUM_DISKS:       $NUM_DISKS"
+msg "FILESIZE:        $FILESIZE"
+msg "Keep pool(s):    $KEEP"
+msg ""
+
+export STF_TOOLS
+export STF_SUITE
+export DISKS
+export KEEP
+
+msg "${TEST_RUNNER} ${QUIET} -c ${RUNFILE} -i ${STF_SUITE}"
+${TEST_RUNNER} ${QUIET} -c ${RUNFILE} -i ${STF_SUITE}
+RESULT=$?
+echo
+
+exit ${RESULT}
diff --git a/tests/Makefile.am b/tests/Makefile.am
new file mode 100644 (file)
index 0000000..28d6e95
--- /dev/null
@@ -0,0 +1 @@
+SUBDIRS = runfiles test-runner zfs-tests
diff --git a/tests/README.md b/tests/README.md
new file mode 100644 (file)
index 0000000..18bdd05
--- /dev/null
@@ -0,0 +1,133 @@
+# ZFS Test Suite README
+
+1) Building and installing the ZFS Test Suite
+
+The ZFS Test Suite runs under the test-runner framework.  This framework
+is built along side the standard ZFS utilities and is included as part of
+zfs-test package.  The zfs-test package can be built from source as follows:
+
+    $ ./configure
+    $ make pkg-utils
+
+The resulting packages can be installed using the rpm or dpkg command as
+appropriate for your distributions.  Alternately, if you have installed
+ZFS from a distributions repository (not from source) the zfs-test package
+may be provided for your distribution.
+
+    - Installed from source
+    $ rpm -ivh ./zfs-test*.rpm, or
+    $ dpkg -i ./zfs-test*.deb,
+
+    - Installed from package repository
+    $ yum install zfs-test
+    $ apt-get install zfs-test
+
+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='vdb vdc vdd'.  By default
+      the zfs-tests.sh sciprt will construct three loopback devices to
+      be used for testing: DISKS='loop0 loop1 loop2'.
+  * A non-root user with a full set of basic privileges and the ability
+    to sudo(8) 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. All pools detected at the start of testing are
+    added automatically.
+  * The ZFS Test Suite will add users and groups to test machine to
+    verify functionality.  Therefore it is strongly advised that a
+    dedicated test machine, which can be a VM, be used for testing.
+
+Once the pre-requisites are satisfied simply run the zfs-tests.sh script:
+
+    $ /usr/share/zfs/zfs-tests.sh
+
+Alternately, the zfs-tests.sh script can be run from the source tree to allow
+developers to rapidly validate their work.  In this mode the ZFS utilities and
+modules from the source tree will be used (rather than those installed on the
+system).  In order to avoid certain types of failures you will need to ensure
+the ZFS udev rules are installed.  This can be done manually or by ensuring
+some version of ZFS is installed on the system.
+
+    $ ./scripts/zfs-tests.sh
+
+The following zfs-tests.sh options are supported:
+
+    -v          Verbose zfs-tests.sh output When specified additional
+                information describing the test environment will be logged
+                prior to invoking test-runner.  This includes the runfile
+                being used, the DISKS targeted, pools to keep, etc.
+
+    -q          Quiet test-runner output.  When specified it is passed to
+                test-runner(1) which causes output to be written to the
+                console only for tests that do not pass and the results
+                summary.
+
+    -x          Remove all testpools, dm, lo, and files (unsafe).  When
+                specified the script will attempt to remove any leftover
+                configuration from a previous test run.  This includes
+                destroying any pools named testpool, unused DM devices,
+                and loopback devices backed by file-vdevs.  This operation
+                can be DANGEROUS because it is possible that the script
+                will mistakenly remove a resource not related to the testing.
+
+    -k          Disable cleanup after test failure.  When specified the
+                zfs-tests.sh script will not perform any additional cleanup
+                when test-runner exists.  This is useful when the results of
+                a specific test need to be preserved for further analysis.
+
+    -f          Use sparse files directly instread of loopback devices for
+                the testing.  When running in this mode certain tests will
+                be skipped which depend on real block devices.
+
+    -d DIR      Create sparse files for vdevs in the DIR directory.  By
+                default these files are created under /var/tmp/.
+
+    -s SIZE     Use vdevs of SIZE (default: 2G)
+
+    -r RUNFILE  Run tests in RUNFILE (default: linux.run)
+
+
+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 test-runner(1), and
+the files that zfs-tests.sh uses are available for reference under
+/usr/share/zfs/runfiles. To specify a custom runfile, use the -r option:
+
+    $ /usr/share/zfs/zfs-tests.sh -r 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 logged in
+the form /var/tmp/test_results/[ISO 8601 date].  A normal test run launched
+with the `zfs-tests.sh` wrapper script will look something like this:
+
+$ /usr/share/zfs/zfs-tests.sh -v -d /mnt
+
+--- Configuration ---
+Runfile:         /usr/share/zfs/runfiles/linux.run
+STF_TOOLS:       /usr/share/zfs/test-runner
+STF_SUITE:       /usr/share/zfs/zfs-tests
+FILEDIR:         /mnt
+FILES:           /mnt/file-vdev0 /mnt/file-vdev1 /mnt/file-vdev2
+LOOPBACKS:       /dev/loop0 /dev/loop1 /dev/loop2 
+DISKS:           loop0 loop1 loop2 
+NUM_DISKS:       3
+FILESIZE:        2G
+Keep pool(s):    rpool
+
+/usr/share/zfs/test-runner/bin/test-runner.py  -c \
+  /usr/share/zfs/runfiles/linux.run -i /usr/share/zfs/zfs-tests
+Test: .../tests/functional/acl/posix/setup (run as root) [00:00] [PASS]
+...470 additional tests...
+Test: .../tests/functional/zvol/zvol_cli/cleanup (run as root) [00:00] [PASS]
+
+Results Summary
+PASS    472
+
+Running Time:  00:45:09
+Percent passed:        100.0%
+Log directory: /var/tmp/test_results/20160316T181651
diff --git a/tests/runfiles/Makefile.am b/tests/runfiles/Makefile.am
new file mode 100644 (file)
index 0000000..cddfb2e
--- /dev/null
@@ -0,0 +1,2 @@
+pkgdatadir = $(datadir)/@PACKAGE@/runfiles
+dist_pkgdata_SCRIPTS = *.run
diff --git a/tests/runfiles/linux.run b/tests/runfiles/linux.run
new file mode 100644 (file)
index 0000000..56e80b8
--- /dev/null
@@ -0,0 +1,647 @@
+#
+# 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.
+#
+
+[DEFAULT]
+pre = setup
+quiet = False
+pre_user = root
+user = root
+timeout = 600
+post_user = root
+post = cleanup
+outputdir = /var/tmp/test_results
+
+# DISABLED:
+# posix_001_pos - needs investigation
+[tests/functional/acl/posix]
+tests = ['posix_002_pos']
+
+[tests/functional/atime]
+tests = ['atime_001_pos', 'atime_002_neg']
+
+# DISABLED:
+# bootfs_006_pos - needs investigation
+# bootfs_008_neg - needs investigation
+[tests/functional/bootfs]
+tests = ['bootfs_001_pos', 'bootfs_002_neg', 'bootfs_003_pos',
+    'bootfs_004_neg', 'bootfs_005_neg', 'bootfs_007_neg']
+
+# DISABLED:
+# cache_001_pos - needs investigation
+# cache_010_neg - needs investigation
+[tests/functional/cache]
+tests = ['cache_002_pos', 'cache_003_pos', 'cache_004_neg',
+    'cache_005_neg', 'cache_006_pos', 'cache_007_neg', 'cache_008_neg',
+    'cache_009_pos', 'cache_011_pos']
+
+# DISABLED: needs investigation
+#[tests/functional/cachefile]
+#tests = ['cachefile_001_pos', 'cachefile_002_pos', 'cachefile_003_pos',
+#    'cachefile_004_pos']
+#pre =
+#post =
+
+# DISABLED: needs investigation
+# 'sensitive_none_lookup', 'sensitive_none_delete',
+# 'sensitive_formd_lookup', 'sensitive_formd_delete',
+# 'insensitive_none_lookup', 'insensitive_none_delete',
+# 'insensitive_formd_lookup', 'insensitive_formd_delete',
+# 'mixed_none_lookup', 'mixed_none_lookup_ci', 'mixed_none_delete',
+# 'mixed_formd_lookup', 'mixed_formd_lookup_ci', 'mixed_formd_delete']
+[tests/functional/casenorm]
+tests = ['case_all_values', 'norm_all_values']
+
+[tests/functional/clean_mirror]
+tests = [ 'clean_mirror_001_pos', 'clean_mirror_002_pos',
+    'clean_mirror_003_pos', 'clean_mirror_004_pos']
+
+[tests/functional/cli_root/zdb]
+tests = ['zdb_001_neg']
+pre =
+post =
+
+[tests/functional/cli_root/zfs]
+tests = ['zfs_001_neg', 'zfs_002_pos', 'zfs_003_neg']
+
+# DISABLED:
+# zfs_clone_005_pos - busy unmount
+# zfs_clone_010_pos - needs investigation
+[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_006_pos',
+    'zfs_clone_007_pos', 'zfs_clone_008_neg', 'zfs_clone_009_neg']
+
+# DISABLED:
+# zfs_copies_002_pos - needs investigation
+# zfs_copies_003_pos - zpool on zvol
+# zfs_copies_005_neg - nested pools
+[tests/functional/cli_root/zfs_copies]
+tests = ['zfs_copies_001_pos', 'zfs_copies_004_neg', 'zfs_copies_006_pos']
+
+# DISABLED:
+# zfs_create_006_pos - needs investigation
+# zfs_create_003_pos - needs investigation
+[tests/functional/cli_root/zfs_create]
+tests = ['zfs_create_001_pos', 'zfs_create_002_pos',
+    'zfs_create_004_pos', 'zfs_create_005_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']
+
+# DISABLED:
+# zfs_destroy_001_pos - busy mountpoint behavior
+# zfs_destroy_004_pos - busy mountpoint behavior
+# zfs_destroy_005_neg - busy mountpoint behavior
+# zfs_destroy_008_pos - busy mountpoint behavior
+# zfs_destroy_009_pos - busy mountpoint behavior
+# zfs_destroy_010_pos - busy mountpoint behavior
+# zfs_destroy_011_pos - busy mountpoint behavior
+# zfs_destroy_012_pos - busy mountpoint behavior
+# zfs_destroy_013_neg - busy mountpoint behavior
+[tests/functional/cli_root/zfs_destroy]
+tests = ['zfs_destroy_002_pos', 'zfs_destroy_003_pos', 'zfs_destroy_006_neg',
+    'zfs_destroy_007_neg', 'zfs_destroy_014_pos', 'zfs_destroy_015_pos',
+    'zfs_destroy_016_pos']
+
+# DISABLED:
+# zfs_get_004_pos - nested pools
+# zfs_get_006_neg - needs investigation
+[tests/functional/cli_root/zfs_get]
+tests = ['zfs_get_001_pos', 'zfs_get_002_pos', 'zfs_get_003_pos',
+    'zfs_get_005_neg', 'zfs_get_007_neg', 'zfs_get_008_pos',
+    'zfs_get_009_pos', 'zfs_get_010_neg']
+
+[tests/functional/cli_root/zfs_inherit]
+tests = ['zfs_inherit_001_neg', 'zfs_inherit_002_neg', 'zfs_inherit_003_pos']
+
+# DISABLED:
+# zfs_mount_005_pos - needs investigation
+# zfs_mount_006_pos - needs investigation
+# zfs_mount_007_pos - needs investigation
+# zfs_mount_009_neg - needs investigation
+# zfs_mount_010_neg - needs investigation
+# zfs_mount_all_001_pos - needs investigation
+[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_008_pos',
+    'zfs_mount_011_neg']
+
+[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']
+
+# DISABLED:
+# zfs_written_property_001_pos - sync(1) does not force txg under Linux
+[tests/functional/cli_root/zfs_property]
+tests = []
+
+# DISABLED:
+# zfs_receive_003_pos - needs investigation
+# zfs_receive_010_pos - needs investigation
+# zfs_receive_011_pos - needs investigation
+# zfs_receive_012_pos - needs investigation
+[tests/functional/cli_root/zfs_receive]
+tests = ['zfs_receive_001_pos', 'zfs_receive_002_pos', 'zfs_receive_005_neg',
+    'zfs_receive_006_pos', 'zfs_receive_007_neg', 'zfs_receive_008_pos',
+    'zfs_receive_009_neg']
+
+# DISABLED:
+# zfs_rename_002_pos - needs investigation
+# zfs_rename_005_neg - nested pools
+# zfs_rename_006_pos - needs investigation
+# zfs_rename_007_pos - needs investigation
+[tests/functional/cli_root/zfs_rename]
+tests = ['zfs_rename_001_pos', 'zfs_rename_003_pos',
+    'zfs_rename_004_neg', 'zfs_rename_008_pos', 'zfs_rename_009_neg',
+    'zfs_rename_010_neg', 'zfs_rename_011_pos', 'zfs_rename_012_neg',
+    'zfs_rename_013_pos']
+
+[tests/functional/cli_root/zfs_reservation]
+tests = ['zfs_reservation_001_pos', 'zfs_reservation_002_pos']
+
+# DISABLED:
+# zfs_rollback_001_pos - busy mountpoint behavior
+# zfs_rollback_002_pos - busy mountpoint behavior
+[tests/functional/cli_root/zfs_rollback]
+tests = ['zfs_rollback_003_neg', 'zfs_rollback_004_neg']
+
+# DISABLED:
+# zfs_send_007_pos - needs investigation
+[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']
+
+# DISABLED:
+# mountpoint_003_pos - needs investigation
+# ro_props_001_pos - needs investigation
+# onoffs_001_pos - needs investigation
+# property_alias_001_pos - needs investigation
+# readonly_001_pos - needs investigation
+# user_property_002_pos - needs investigation
+[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', 'reservation_001_neg',
+    'share_mount_001_neg', 'snapdir_001_pos',
+    'user_property_001_pos', 'user_property_003_neg',
+    'user_property_004_pos', 'version_001_neg', 'zfs_set_001_neg',
+    'zfs_set_002_neg', 'zfs_set_003_neg']
+
+# DISABLED: Tests need to be updated for Linux share behavior
+#[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']
+
+# DISABLED:
+# zfs_snapshot_008_neg - nested pools
+[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_009_pos']
+
+# DISABLED:
+# zfs_unmount_005_pos - needs investigation
+# zfs_unmount_009_pos - needs investigation
+# zfs_unmount_all_001_pos - needs investigation
+[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_006_pos',
+    'zfs_unmount_007_neg', 'zfs_unmount_008_neg']
+
+# DISABLED: Tests need to be updated for Linux unshare behavior
+#[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']
+
+[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']
+
+[tests/functional/cli_root/zpool]
+tests = ['zpool_001_neg', 'zpool_002_pos', 'zpool_003_pos']
+
+# DISABLED:
+# zpool_add_005_pos - no 'dumpadm' command.
+# zpool_add_006_pos - nested pools
+[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_007_neg', 'zpool_add_008_neg', 'zpool_add_009_neg']
+
+[tests/functional/cli_root/zpool_attach]
+tests = ['zpool_attach_001_neg']
+
+[tests/functional/cli_root/zpool_clear]
+tests = ['zpool_clear_001_pos', 'zpool_clear_002_neg', 'zpool_clear_003_neg']
+
+# DISABLED:
+# zpool_create_001_pos - needs investigation
+# zpool_create_002_pos - needs investigation
+# zpool_create_004_pos - needs investigation
+# zpool_create_006_pos - nested pools
+# zpool_create_008_pos - uses VTOC labels (?) and 'overlapping slices'
+# zpool_create_011_neg - tries to access /etc/vfstab etc
+# zpool_create_012_neg - swap devices
+# zpool_create_014_neg - swap devices
+# zpool_create_015_neg - swap devices
+# zpool_create_016_pos - no dumadm command.
+# zpool_create_020_pos - needs investigation
+[tests/functional/cli_root/zpool_create]
+tests = [
+    'zpool_create_003_pos', 'zpool_create_005_pos', 'zpool_create_007_neg', 
+    'zpool_create_009_neg', 'zpool_create_010_neg', 'zpool_create_017_neg',
+    'zpool_create_018_pos', 'zpool_create_019_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']
+
+# DISABLED:
+# zpool_destroy_001_pos - failure should be investigated
+# zpool_destroy_002_pos - update for Linux fource unmount behavior
+[tests/functional/cli_root/zpool_destroy]
+tests = [
+    'zpool_destroy_003_neg']
+pre =
+post =
+
+[tests/functional/cli_root/zpool_detach]
+tests = ['zpool_detach_001_neg']
+
+# DISABLED: Requires full FMA support in ZED
+#[tests/functional/cli_root/zpool_expand]
+#tests = ['zpool_expand_001_pos', 'zpool_expand_002_pos',
+#    'zpool_expand_003_neg']
+
+# DISABLED:
+# zpool_export_004_pos - nested pools
+[tests/functional/cli_root/zpool_export]
+tests = ['zpool_export_001_pos', 'zpool_export_002_pos',
+    'zpool_export_003_neg']
+
+[tests/functional/cli_root/zpool_get]
+tests = ['zpool_get_001_pos', 'zpool_get_002_pos', 'zpool_get_003_pos',
+    'zpool_get_004_neg']
+
+[tests/functional/cli_root/zpool_history]
+tests = ['zpool_history_001_neg', 'zpool_history_002_pos']
+
+# DISABLED:
+# zpool_import_012_pos - sharenfs issue
+# zpool_import_all_001_pos - partition issue
+# zpool_import_features_001_pos - zhack issue
+# zpool_import_features_002_neg - zhack issue
+# zpool_import_features_003_pos - zhack issue
+# zpool_import_missing_001_pos - zhack_issue
+# zpool_import_missing_002_pos - zhack_issue
+# zpool_import_missing_003_pos - zhack_issue
+# zpool_import_rename_001_pos - hack issue
+[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_013_neg']
+
+[tests/functional/cli_root/zpool_offline]
+tests = ['zpool_offline_001_pos', 'zpool_offline_002_neg']
+
+[tests/functional/cli_root/zpool_online]
+tests = ['zpool_online_001_pos', 'zpool_online_002_neg']
+
+# DISABLED:
+# zpool_remove_003_pos - needs investigation
+[tests/functional/cli_root/zpool_remove]
+tests = ['zpool_remove_001_neg', 'zpool_remove_002_pos']
+
+[tests/functional/cli_root/zpool_replace]
+tests = ['zpool_replace_001_neg']
+
+# DISABLED:
+# zpool_scrub_004_pos - needs investigation
+# zpool_scrub_005_pos - needs investigation
+[tests/functional/cli_root/zpool_scrub]
+tests = ['zpool_scrub_001_neg', 'zpool_scrub_002_pos', 'zpool_scrub_003_pos']
+
+[tests/functional/cli_root/zpool_set]
+tests = ['zpool_set_001_pos', 'zpool_set_002_neg', 'zpool_set_003_neg']
+pre =
+post =
+
+[tests/functional/cli_root/zpool_status]
+tests = ['zpool_status_001_pos', 'zpool_status_002_pos']
+
+# DISABLED: ENOSPC failure
+#[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']
+
+# DISABLED: nested pools
+#[tests/functional/cli_user/misc]
+#tests = ['zdb_001_neg', 'zfs_001_neg', 'zfs_allow_001_neg',
+#    'zfs_clone_001_neg', 'zfs_create_001_neg', 'zfs_destroy_001_neg',
+#    'zfs_get_001_neg', 'zfs_inherit_001_neg', 'zfs_mount_001_neg',
+#    'zfs_promote_001_neg', 'zfs_receive_001_neg', 'zfs_rename_001_neg',
+#    'zfs_rollback_001_neg', 'zfs_send_001_neg', 'zfs_set_001_neg',
+#    'zfs_share_001_neg', 'zfs_snapshot_001_neg', 'zfs_unallow_001_neg',
+#    'zfs_unmount_001_neg', 'zfs_unshare_001_neg', 'zfs_upgrade_001_neg',
+#    'zpool_001_neg', 'zpool_add_001_neg', 'zpool_attach_001_neg',
+#    'zpool_clear_001_neg', 'zpool_create_001_neg', 'zpool_destroy_001_neg',
+#    'zpool_detach_001_neg', 'zpool_export_001_neg', 'zpool_get_001_neg',
+#    'zpool_history_001_neg', 'zpool_import_001_neg', 'zpool_import_002_neg',
+#    'zpool_offline_001_neg', 'zpool_online_001_neg', 'zpool_remove_001_neg',
+#    'zpool_replace_001_neg', 'zpool_scrub_001_neg', 'zpool_set_001_neg',
+#    'zpool_status_001_neg', 'zpool_upgrade_001_neg']
+#user = zfs-tests
+
+[tests/functional/cli_user/zfs_list]
+tests = ['zfs_list_001_pos', 'zfs_list_002_pos', 'zfs_list_003_pos',
+    'zfs_list_004_neg', 'zfs_list_007_pos', 'zfs_list_008_neg']
+
+[tests/functional/cli_user/zpool_iostat]
+tests = ['zpool_iostat_001_neg', 'zpool_iostat_002_pos',
+    'zpool_iostat_003_neg']
+
+[tests/functional/cli_user/zpool_list]
+tests = ['zpool_list_001_pos', 'zpool_list_002_neg']
+
+[tests/functional/compression]
+tests = ['compress_001_pos', 'compress_002_pos', 'compress_003_pos',
+    'compress_004_pos']
+
+[tests/functional/ctime]
+tests = ['ctime_001_pos' ]
+
+# DISABLED: Linux does not yet support delegations.
+#[tests/functional/delegate]
+#tests = ['zfs_allow_001_pos', 'zfs_allow_002_pos',
+#    'zfs_allow_004_pos', 'zfs_allow_005_pos', 'zfs_allow_006_pos',
+#    'zfs_allow_007_pos', 'zfs_allow_008_pos', 'zfs_allow_009_neg',
+#    'zfs_allow_010_pos', 'zfs_allow_011_neg', 'zfs_allow_012_neg',
+#    'zfs_unallow_001_pos', 'zfs_unallow_002_pos', 'zfs_unallow_003_pos',
+#    'zfs_unallow_004_pos', 'zfs_unallow_005_pos', 'zfs_unallow_006_pos',
+#    'zfs_unallow_007_neg', 'zfs_unallow_008_neg']
+
+# DISABLED:
+# devices_001_pos - needs investigation
+# devices_002_neg - needs investigation
+[tests/functional/devices]
+tests = ['devices_003_pos']
+
+# DISABLED:
+# exec_002_neg - needs investigation
+[tests/functional/exec]
+tests = ['exec_001_pos']
+
+[tests/functional/features/async_destroy]
+tests = ['async_destroy_001_pos']
+
+# DISABLED: needs investigation
+#[tests/functional/grow_pool]
+#tests = ['grow_pool_001_pos']
+#pre =
+#post =
+
+# DISABLED: needs investigation
+#[tests/functional/grow_replicas]
+#tests = ['grow_replicas_001_pos']
+#pre =
+#post =
+
+# DISABLED:
+# history_001_pos - export commands missing from history
+# history_003_pos - nested pool
+# history_006_neg - needs investigation
+# history_007_pos - needs investigation
+# history_008_pos - needs investigation
+# history_010_pos - needs investigation
+[tests/functional/history]
+tests = ['history_002_pos', 'history_004_pos', 'history_005_neg',
+    'history_009_pos']
+
+[tests/functional/inheritance]
+tests = ['inherit_001_pos']
+pre =
+
+# DISABLED:
+# inuse_001_pos, inuse_007_pos - no dumpadm command
+# inuse_005_pos - partition issue
+# inuse_006_pos - partition issue
+# inuse_008_pos - partition issue
+# inuse_009_pos - partition issue
+[tests/functional/inuse]
+tests = ['inuse_004_pos']
+post =
+
+# DISABLED: needs investigation
+#[tests/functional/large_files]
+#tests = ['large_files_001_pos']
+
+# DISABLED: needs investigation
+#[tests/functional/largest_pool]
+#tests = ['largest_pool_001_pos']
+#pre =
+#post =
+
+# DISABLED: needs investigation
+#[tests/functional/link_count]
+#tests = ['link_count_001']
+
+[tests/functional/migration]
+tests = ['migration_001_pos', 'migration_002_pos', 'migration_003_pos',
+    'migration_004_pos', 'migration_005_pos', 'migration_006_pos',
+    'migration_007_pos', 'migration_008_pos', 'migration_009_pos',
+    'migration_010_pos', 'migration_011_pos', 'migration_012_pos']
+
+# DISABLED:
+# mmap_write_001_pos: needs investigation
+[tests/functional/mmap]
+tests = ['mmap_read_001_pos']
+
+# DISABLED:
+# umountall_001 - Doesn't make sence in Linux - no umountall command.
+[tests/functional/mount]
+tests = ['umount_001']
+
+[tests/functional/mv_files]
+tests = ['mv_files_001_pos', 'mv_files_002_pos']
+
+[tests/functional/nestedfs]
+tests = ['nestedfs_001_pos']
+
+[tests/functional/no_space]
+tests = ['enospc_001_pos']
+
+# DISABLED: needs investigation (CentOS 7 only)
+#[tests/functional/nopwrite]
+#tests = ['nopwrite_copies', 'nopwrite_mtime', 'nopwrite_negative',
+#    'nopwrite_promoted_clone', 'nopwrite_recsize', 'nopwrite_sync',
+#    'nopwrite_volume', 'nopwrite_varying_compression']
+
+# DISABLED: needs investigation
+#[tests/functional/online_offline]
+#tests = ['online_offline_001_pos', 'online_offline_002_neg',
+#    'online_offline_003_neg']
+
+[tests/functional/pool_names]
+tests = ['pool_names_001_pos', 'pool_names_002_neg']
+pre =
+post =
+
+[tests/functional/poolversion]
+tests = ['poolversion_001_pos', 'poolversion_002_pos']
+
+# DISABLED: Doesn't make sense on Linux - no pfexec command or 'RBAC profile'
+#[tests/functional/privilege]
+#tests = ['privilege_001_pos', 'privilege_002_pos']
+
+# DISABLED:
+# quota_002_pos - size is less than current used or reserved space 
+# quota_004_pos - size is less than current used or reserved space
+# quota_005_pos - size is less than current used or reserved space
+[tests/functional/quota]
+tests = ['quota_001_pos', 'quota_003_pos', 'quota_006_neg']
+
+[tests/functional/redundancy]
+tests = ['redundancy_001_pos', 'redundancy_002_pos', 'redundancy_003_pos']
+
+# DISABLED:
+# refquota_002_pos - size is less than current used or reserved space
+# refquota_004_pos - needs investigation
+[tests/functional/refquota]
+tests = ['refquota_001_pos', 'refquota_003_pos',
+    'refquota_005_pos', 'refquota_006_neg']
+
+# DISABLED:
+# refreserv_004_pos - needs investigation
+[tests/functional/refreserv]
+tests = ['refreserv_001_pos', 'refreserv_002_pos', 'refreserv_003_pos',
+    'refreserv_005_pos']
+
+# DISABLED: nested pool
+#[tests/functional/rename_dirs]
+#tests = ['rename_dirs_001_pos']
+
+# DISABLED: nested pool
+#[tests/functional/replacement]
+#tests = ['replacement_001_pos', 'replacement_002_pos']
+
+# DISABLED:
+# reservation_012_pos - needs investigation
+# reservation_015_pos - needs investigation
+# reservation_016_pos - needs investigation
+[tests/functional/reservation]
+tests = ['reservation_001_pos', 'reservation_002_pos', 'reservation_003_pos',
+    'reservation_004_pos', 'reservation_005_pos', 'reservation_006_pos',
+    'reservation_007_pos', 'reservation_008_pos', 'reservation_009_pos',
+    'reservation_010_pos', 'reservation_011_pos',
+    'reservation_013_pos', 'reservation_014_pos',
+    'reservation_017_pos', 'reservation_018_pos']
+
+# DISABLED: Root pools must be handled differently under Linux
+#[tests/functional/rootpool]
+#tests = ['rootpool_002_neg', 'rootpool_003_neg', 'rootpool_007_neg']
+
+# DISABLED: Hangs on I/O for unclear reason.
+#[tests/functional/rsend]
+#tests = ['rsend_002_pos', 'rsend_003_pos', 'rsend_004_pos',
+#    'rsend_005_pos', 'rsend_006_pos', 'rsend_007_pos', 'rsend_008_pos',
+#    'rsend_009_pos', 'rsend_010_pos', 'rsend_011_pos', 'rsend_012_pos',
+#    'rsend_013_pos']
+
+[tests/functional/scrub_mirror]
+tests = ['scrub_mirror_001_pos', 'scrub_mirror_002_pos',
+    'scrub_mirror_003_pos', 'scrub_mirror_004_pos']
+
+# DISABLED: Scripts need to be updated.
+# slog_012_neg - needs investigation
+# slog_013_pos - Linux doesn't have a 'lofiadm' command.
+# slog_014_pos - needs investigation
+[tests/functional/slog]
+tests = ['slog_001_pos', 'slog_002_pos', 'slog_003_pos', 'slog_004_pos',
+    'slog_005_pos', 'slog_006_pos', 'slog_007_pos', 'slog_008_neg',
+    'slog_009_neg', 'slog_010_neg', 'slog_011_neg']
+
+# DISABLED:
+# rollback_003_pos - Hangs in unmount and spins.
+# snapshot_013_pos - Hangs on I/O for unclear reason.
+# snapshot_016_pos - .zfs mv/rmdir/mkdir disabled by default.
+#[tests/functional/snapshot]
+#tests = ['clone_001_pos', 'rollback_001_pos', 'rollback_002_pos',
+#    'snapshot_001_pos', 'snapshot_002_pos',
+#    'snapshot_003_pos', 'snapshot_004_pos', 'snapshot_005_pos',
+#    'snapshot_006_pos', 'snapshot_007_pos', 'snapshot_008_pos',
+#    'snapshot_009_pos', 'snapshot_010_pos', 'snapshot_011_pos',
+#    'snapshot_012_pos', 'snapshot_014_pos',
+#    'snapshot_015_pos', 'snapshot_017_pos']
+[tests/functional/snapused]
+tests = ['snapused_001_pos', 'snapused_002_pos', 'snapused_003_pos',
+    'snapused_004_pos', 'snapused_005_pos']
+
+[tests/functional/sparse]
+tests = ['sparse_001_pos']
+
+# DISABLED: needs investigation
+#[tests/functional/threadsappend]
+#tests = ['threadsappend_001_pos']
+
+[tests/functional/truncate]
+tests = ['truncate_001_pos', 'truncate_002_pos']
+
+# DISABLED:
+# groupspace_001_pos
+# groupspace_002_pos
+# userquota_001_pos
+# userquota_004_pos
+# userquota_007_pos
+# userquota_010_pos
+# userspace_001_pos
+# userspace_002_pos
+[tests/functional/userquota]
+tests = [
+    'userquota_002_pos', 'userquota_003_pos',
+    'userquota_005_neg', 'userquota_006_pos',
+    'userquota_008_pos', 'userquota_009_pos',
+    'userquota_011_pos', 'userquota_012_neg']
+
+# DISABLED:
+# write_dirs_002_pos - needs investigation
+[tests/functional/write_dirs]
+tests = ['write_dirs_001_pos']
+
+# DISABLED: No 'runat' command, replace the Linux equivilant and add xattrtest
+#[tests/functional/xattr]
+#tests = ['xattr_001_pos', 'xattr_002_neg', 'xattr_003_neg', 'xattr_004_pos',
+#    'xattr_005_pos', 'xattr_006_pos', 'xattr_007_neg', 'xattr_008_pos',
+#    'xattr_009_neg', 'xattr_010_neg', 'xattr_011_pos', 'xattr_012_pos',
+#    'xattr_013_pos']
+
+[tests/functional/zvol/zvol_ENOSPC]
+tests = ['zvol_ENOSPC_001_pos']
+
+[tests/functional/zvol/zvol_cli]
+tests = ['zvol_cli_001_pos', 'zvol_cli_002_pos', 'zvol_cli_003_neg']
+
+# DISABLED: requires dumpadm
+#[tests/functional/zvol/zvol_misc]
+#tests = ['zvol_misc_001_neg', 'zvol_misc_002_pos', 'zvol_misc_003_neg',
+#    'zvol_misc_004_pos', 'zvol_misc_005_neg', 'zvol_misc_006_pos']
+
+# DISABLED: requires updated for Linux
+#[tests/functional/zvol/zvol_swap]
+#tests = ['zvol_swap_001_pos', 'zvol_swap_002_pos', 'zvol_swap_003_pos',
+#    'zvol_swap_004_pos', 'zvol_swap_005_pos', 'zvol_swap_006_pos']
diff --git a/tests/test-runner/Makefile.am b/tests/test-runner/Makefile.am
new file mode 100644 (file)
index 0000000..6a0d9ec
--- /dev/null
@@ -0,0 +1 @@
+SUBDIRS = cmd include man
diff --git a/tests/test-runner/cmd/Makefile.am b/tests/test-runner/cmd/Makefile.am
new file mode 100644 (file)
index 0000000..223622d
--- /dev/null
@@ -0,0 +1,3 @@
+pkgdatadir = $(datadir)/@PACKAGE@/test-runner/bin
+dist_pkgdata_SCRIPTS = \
+       test-runner.py
diff --git a/tests/test-runner/cmd/test-runner.py b/tests/test-runner/cmd/test-runner.py
new file mode 100755 (executable)
index 0000000..dd6a3c7
--- /dev/null
@@ -0,0 +1,862 @@
+#!/usr/bin/python
+
+#
+# This file and its contents are supplied under the terms of the
+# Common Development and Distribution License ("CDDL"), version 1.0.
+# You may only use this file in accordance with the terms of version
+# 1.0 of the CDDL.
+#
+# A full copy of the text of the CDDL should have accompanied this
+# source.  A copy of the CDDL is also available via the Internet at
+# http://www.illumos.org/license/CDDL.
+#
+
+#
+# Copyright (c) 2013 by Delphix. All rights reserved.
+#
+
+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'
+TESTDIR = '/usr/share/zfs/'
+KILL = 'kill'
+TRUE = 'true'
+SUDO = '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 4:
+            self.result = 'SKIP'
+            Result.runresults['SKIP'] += 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
+
+        if not os.path.isfile(cmd):
+            if os.path.isfile(cmd+'.ksh') and os.access(cmd+'.ksh', os.X_OK):
+                cmd += '.ksh'
+            if os.path.isfile(cmd+'.sh') and os.access(cmd+'.sh', os.X_OK):
+                cmd += '.sh'
+
+        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
+
+        logname = getpwuid(os.getuid()).pw_name
+        user = ' (run as %s)' % (self.user if len(self.user) else logname)
+        msga = 'Test: %s%s ' % (self.pathname, user)
+        msgb = '[%s] [%s]' % (self.result.runtime, self.result.result)
+        pad = ' ' * (80 - (len(msga) + len(msgb)))
+
+        # 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):
+                if os.path.isdir(section):
+                    pathname = section
+                elif os.path.isdir(os.path.join(options.testdir, section)):
+                    pathname = os.path.join(options.testdir, section)
+                else:
+                    pathname = section
+
+                testgroup = TestGroup(os.path.abspath(pathname))
+                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)) or \
+            (os.path.isfile(pathname+'.ksh') and os.access(pathname+'.ksh', os.X_OK)) or \
+            (os.path.isfile(pathname+'.sh') and os.access(pathname+'.sh', 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 passwordless 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', 'testdir']
+
+    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('-i', action='callback', callback=options_cb,
+                      default=TESTDIR, dest='testdir', type='string',
+                      metavar='testdir', help='Specify a test 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:])
diff --git a/tests/test-runner/include/Makefile.am b/tests/test-runner/include/Makefile.am
new file mode 100644 (file)
index 0000000..d071dd4
--- /dev/null
@@ -0,0 +1,4 @@
+pkgdatadir = $(datadir)/@PACKAGE@/test-runner/include
+dist_pkgdata_SCRIPTS = \
+       logapi.shlib \
+       stf.shlib
diff --git a/tests/test-runner/include/logapi.shlib b/tests/test-runner/include/logapi.shlib
new file mode 100644 (file)
index 0000000..6fd4ab3
--- /dev/null
@@ -0,0 +1,385 @@
+#!/bin/ksh -p
+#
+# CDDL HEADER START
+#
+# The contents of this file are subject to the terms of the
+# Common Development and Distribution License (the "License").
+# You may not use this file except in compliance with the License.
+#
+# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
+# or http://www.opensolaris.org/os/licensing.
+# See the License for the specific language governing permissions
+# and limitations under the License.
+#
+# When distributing Covered Code, include this CDDL HEADER in each
+# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
+# If applicable, add the following below this CDDL HEADER, with the
+# fields enclosed by brackets "[]" replaced with your own identifying
+# information: Portions Copyright [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="$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 | $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 | $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="$CAT $logfile"
+
+       if (( $status != 0 )) ; then
+               print -u2 $($out)
+               _printerror "$@" "exited $status"
+       else
+               $out | $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
+                       $CAT $logfile
+               fi
+               $RM -f $logfile
+               logfile="$logfile.$$"
+        done
+}
diff --git a/tests/test-runner/include/stf.shlib b/tests/test-runner/include/stf.shlib
new file mode 100644 (file)
index 0000000..ea879a8
--- /dev/null
@@ -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" )
diff --git a/tests/test-runner/man/Makefile.am b/tests/test-runner/man/Makefile.am
new file mode 100644 (file)
index 0000000..a7017f5
--- /dev/null
@@ -0,0 +1,4 @@
+dist_man_MANS = test-runner.1
+
+install-data-local:
+       $(INSTALL) -d -m 0755 "$(DESTDIR)$(mandir)/man1"
diff --git a/tests/test-runner/man/test-runner.1 b/tests/test-runner/man/test-runner.1
new file mode 100644 (file)
index 0000000..31cd412
--- /dev/null
@@ -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)
diff --git a/tests/zfs-tests/Makefile.am b/tests/zfs-tests/Makefile.am
new file mode 100644 (file)
index 0000000..8617034
--- /dev/null
@@ -0,0 +1 @@
+SUBDIRS = cmd include tests
diff --git a/tests/zfs-tests/cmd/Makefile.am b/tests/zfs-tests/cmd/Makefile.am
new file mode 100644 (file)
index 0000000..f55ff8c
--- /dev/null
@@ -0,0 +1,22 @@
+EXTRA_DIST = file_common.h
+
+SUBDIRS = \
+       chg_usr_exec \
+       devname2devid \
+       dir_rd_update \
+       file_check \
+       file_trunc \
+       file_write \
+       largest_file \
+       mkbusy \
+       mkfile \
+       mkfiles \
+       mktree \
+       mmap_exec \
+       mmapwrite \
+       randfree_file \
+       readmmap \
+       rename_dir \
+       rm_lnkcnt_zero_file \
+       threadsappend \
+       xattrtest
diff --git a/tests/zfs-tests/cmd/chg_usr_exec/.gitignore b/tests/zfs-tests/cmd/chg_usr_exec/.gitignore
new file mode 100644 (file)
index 0000000..a8b44df
--- /dev/null
@@ -0,0 +1 @@
+/chg_usr_exec
diff --git a/tests/zfs-tests/cmd/chg_usr_exec/Makefile.am b/tests/zfs-tests/cmd/chg_usr_exec/Makefile.am
new file mode 100644 (file)
index 0000000..6f2968f
--- /dev/null
@@ -0,0 +1,6 @@
+include $(top_srcdir)/config/Rules.am
+
+pkgexecdir = $(datadir)/@PACKAGE@/zfs-tests/bin
+
+pkgexec_PROGRAMS = chg_usr_exec
+chg_usr_exec_SOURCES = chg_usr_exec.c
diff --git a/tests/zfs-tests/cmd/chg_usr_exec/chg_usr_exec.c b/tests/zfs-tests/cmd/chg_usr_exec/chg_usr_exec.c
new file mode 100644 (file)
index 0000000..1fa9e88
--- /dev/null
@@ -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>
+
+#define        EXECSHELL       "/bin/sh"
+
+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(EXECSHELL, "sh",  "-c", cmds, (char *)NULL) != 0) {
+               perror("execl: " EXECSHELL);
+               return (errno);
+       }
+
+       return (0);
+}
diff --git a/tests/zfs-tests/cmd/devname2devid/.gitignore b/tests/zfs-tests/cmd/devname2devid/.gitignore
new file mode 100644 (file)
index 0000000..fa9fb6c
--- /dev/null
@@ -0,0 +1 @@
+/devname2devid
diff --git a/tests/zfs-tests/cmd/devname2devid/Makefile.am b/tests/zfs-tests/cmd/devname2devid/Makefile.am
new file mode 100644 (file)
index 0000000..2eb03e9
--- /dev/null
@@ -0,0 +1,7 @@
+include $(top_srcdir)/config/Rules.am
+
+pkgdatadir = $(datadir)/@PACKAGE@/zfs-tests/bin
+
+# DISABLED: Not supported under Linux
+# pkgdata_PROGRAMS = devname2devid
+# devname2devid_SOURCES = devname2devid.c
diff --git a/tests/zfs-tests/cmd/devname2devid/devname2devid.c b/tests/zfs-tests/cmd/devname2devid/devname2devid.c
new file mode 100644 (file)
index 0000000..fd32874
--- /dev/null
@@ -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);
+}
diff --git a/tests/zfs-tests/cmd/dir_rd_update/.gitignore b/tests/zfs-tests/cmd/dir_rd_update/.gitignore
new file mode 100644 (file)
index 0000000..ec9a15f
--- /dev/null
@@ -0,0 +1 @@
+/dir_rd_update
diff --git a/tests/zfs-tests/cmd/dir_rd_update/Makefile.am b/tests/zfs-tests/cmd/dir_rd_update/Makefile.am
new file mode 100644 (file)
index 0000000..27cc9e9
--- /dev/null
@@ -0,0 +1,6 @@
+include $(top_srcdir)/config/Rules.am
+
+pkgexecdir = $(datadir)/@PACKAGE@/zfs-tests/bin
+
+pkgexec_PROGRAMS = dir_rd_update
+dir_rd_update_SOURCES = dir_rd_update.c
diff --git a/tests/zfs-tests/cmd/dir_rd_update/dir_rd_update.c b/tests/zfs-tests/cmd/dir_rd_update/dir_rd_update.c
new file mode 100644 (file)
index 0000000..bca365c
--- /dev/null
@@ -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);
+}
diff --git a/tests/zfs-tests/cmd/file_check/.gitignore b/tests/zfs-tests/cmd/file_check/.gitignore
new file mode 100644 (file)
index 0000000..24fe113
--- /dev/null
@@ -0,0 +1 @@
+/file_check
diff --git a/tests/zfs-tests/cmd/file_check/Makefile.am b/tests/zfs-tests/cmd/file_check/Makefile.am
new file mode 100644 (file)
index 0000000..13027ef
--- /dev/null
@@ -0,0 +1,6 @@
+include $(top_srcdir)/config/Rules.am
+
+pkgexecdir = $(datadir)/@PACKAGE@/zfs-tests/bin
+
+pkgexec_PROGRAMS = file_check
+file_check_SOURCES = file_check.c
diff --git a/tests/zfs-tests/cmd/file_check/file_check.c b/tests/zfs-tests/cmd/file_check/file_check.c
new file mode 100644 (file)
index 0000000..5df0ea7
--- /dev/null
@@ -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;
+       unsigned char   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);
+}
diff --git a/tests/zfs-tests/cmd/file_common.h b/tests/zfs-tests/cmd/file_common.h
new file mode 100644 (file)
index 0000000..759889e
--- /dev/null
@@ -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 */
diff --git a/tests/zfs-tests/cmd/file_trunc/.gitignore b/tests/zfs-tests/cmd/file_trunc/.gitignore
new file mode 100644 (file)
index 0000000..90b149f
--- /dev/null
@@ -0,0 +1 @@
+/file_trunc
diff --git a/tests/zfs-tests/cmd/file_trunc/Makefile.am b/tests/zfs-tests/cmd/file_trunc/Makefile.am
new file mode 100644 (file)
index 0000000..0455eb4
--- /dev/null
@@ -0,0 +1,6 @@
+include $(top_srcdir)/config/Rules.am
+
+pkgexecdir = $(datadir)/@PACKAGE@/zfs-tests/bin
+
+pkgexec_PROGRAMS = file_trunc
+file_trunc_SOURCES = file_trunc.c
diff --git a/tests/zfs-tests/cmd/file_trunc/file_trunc.c b/tests/zfs-tests/cmd/file_trunc/file_trunc.c
new file mode 100644 (file)
index 0000000..38e36c9
--- /dev/null
@@ -0,0 +1,244 @@
+/*
+ * CDDL HEADER START
+ *
+ * The contents of this file are subject to the terms of the
+ * Common Development and Distribution License (the "License").
+ * You may not use this file except in compliance with the License.
+ *
+ * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
+ * or http://www.opensolaris.org/os/licensing.
+ * See the License for the specific language governing permissions
+ * and limitations under the License.
+ *
+ * When distributing Covered Code, include this CDDL HEADER in each
+ * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
+ * If applicable, add the following below this CDDL HEADER, with the
+ * fields enclosed by brackets "[]" replaced with your own identifying
+ * information: Portions Copyright [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>
+#include <time.h>
+#include <inttypes.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);
+       }
+
+       strcpy(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 %" PRId64 "\n", (offset + roffset));
+               if (rflag) {
+                       (void) fprintf(stderr,
+                           "Read back from offset %" PRId64 "\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 %" PRId64 "\n",
+                   (offset + roffset));
+       }
+}
diff --git a/tests/zfs-tests/cmd/file_write/.gitignore b/tests/zfs-tests/cmd/file_write/.gitignore
new file mode 100644 (file)
index 0000000..9f691d5
--- /dev/null
@@ -0,0 +1 @@
+/file_write
diff --git a/tests/zfs-tests/cmd/file_write/Makefile.am b/tests/zfs-tests/cmd/file_write/Makefile.am
new file mode 100644 (file)
index 0000000..6089571
--- /dev/null
@@ -0,0 +1,6 @@
+include $(top_srcdir)/config/Rules.am
+
+pkgexecdir = $(datadir)/@PACKAGE@/zfs-tests/bin
+
+pkgexec_PROGRAMS = file_write
+file_write_SOURCES = file_write.c
diff --git a/tests/zfs-tests/cmd/file_write/file_write.c b/tests/zfs-tests/cmd/file_write/file_write.c
new file mode 100644 (file)
index 0000000..43fd96a
--- /dev/null
@@ -0,0 +1,229 @@
+/*
+ * CDDL HEADER START
+ *
+ * The contents of this file are subject to the terms of the
+ * Common Development and Distribution License (the "License").
+ * You may not use this file except in compliance with the License.
+ *
+ * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
+ * or http://www.opensolaris.org/os/licensing.
+ * See the License for the specific language governing permissions
+ * and limitations under the License.
+ *
+ * When distributing Covered Code, include this CDDL HEADER in each
+ * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
+ * If applicable, add the following below this CDDL HEADER, with the
+ * fields enclosed by brackets "[]" replaced with your own identifying
+ * information: 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>
+#include <string.h>
+#include <inttypes.h>
+#include <sys/types.h>
+#include <unistd.h>
+
+typedef unsigned char  uchar_t;
+typedef long long      longlong_t;
+typedef longlong_t     offset_t;
+
+static unsigned char bigbuffer[BIGBUFFERSIZE];
+
+/*
+ * Writes (or appends) a given value to a file repeatedly.
+ * See header file for defaults.
+ */
+
+static void usage(char *);
+
+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;
+       char            *prog = argv[0];
+       /*
+        * 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(prog);
+                               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(prog);
+
+       /*
+        * 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(prog);
+       }
+
+       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 = lseek64(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 = %"
+                           PRId64 ", " "error: %s[%d]\n",
+                           (long)n, good_writes,
+                           strerror(errno),
+                           errno);
+                       exit(errno);
+               }
+               good_writes++;
+       }
+
+       if (verbose) {
+               (void) printf("Success: good_writes = %" PRId64 "(%"
+                   PRId64 ")\n", good_writes, (good_writes * block_size));
+       }
+
+       return (0);
+}
+
+static void
+usage(char *prog)
+{
+       (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", prog, DATA_RANGE);
+
+       exit(1);
+}
diff --git a/tests/zfs-tests/cmd/largest_file/.gitignore b/tests/zfs-tests/cmd/largest_file/.gitignore
new file mode 100644 (file)
index 0000000..f8f480d
--- /dev/null
@@ -0,0 +1 @@
+/largest_file
diff --git a/tests/zfs-tests/cmd/largest_file/Makefile.am b/tests/zfs-tests/cmd/largest_file/Makefile.am
new file mode 100644 (file)
index 0000000..a3e4e93
--- /dev/null
@@ -0,0 +1,6 @@
+include $(top_srcdir)/config/Rules.am
+
+pkgexecdir = $(datadir)/@PACKAGE@/zfs-tests/bin
+
+pkgexec_PROGRAMS = largest_file
+largest_file_SOURCES = largest_file.c
diff --git a/tests/zfs-tests/cmd/largest_file/largest_file.c b/tests/zfs-tests/cmd/largest_file/largest_file.c
new file mode 100644 (file)
index 0000000..1cf7529
--- /dev/null
@@ -0,0 +1,140 @@
+/*
+ * CDDL HEADER START
+ *
+ * The contents of this file are subject to the terms of the
+ * Common Development and Distribution License (the "License").
+ * You may not use this file except in compliance with the License.
+ *
+ * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
+ * or http://www.opensolaris.org/os/licensing.
+ * See the License for the specific language governing permissions
+ * and limitations under the License.
+ *
+ * When distributing Covered Code, include this CDDL HEADER in each
+ * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
+ * If applicable, add the following below this CDDL HEADER, with the
+ * fields enclosed by brackets "[]" replaced with your own identifying
+ * information: Portions Copyright [yyyy] [name of copyright owner]
+ *
+ * CDDL HEADER END
+ */
+
+/*
+ * Copyright 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>
+#include <string.h>
+#include <sys/types.h>
+#include <unistd.h>
+
+typedef long long      offset_t;
+#define        MAXOFFSET_T     LLONG_MAX
+
+/*
+ * --------------------------------------------------------------
+ *
+ *     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 = lseek64(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 = lseek64(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");
+}
diff --git a/tests/zfs-tests/cmd/mkbusy/.gitignore b/tests/zfs-tests/cmd/mkbusy/.gitignore
new file mode 100644 (file)
index 0000000..18d099c
--- /dev/null
@@ -0,0 +1 @@
+/mkbusy
diff --git a/tests/zfs-tests/cmd/mkbusy/Makefile.am b/tests/zfs-tests/cmd/mkbusy/Makefile.am
new file mode 100644 (file)
index 0000000..abae69d
--- /dev/null
@@ -0,0 +1,6 @@
+include $(top_srcdir)/config/Rules.am
+
+pkgexecdir = $(datadir)/@PACKAGE@/zfs-tests/bin
+
+pkgexec_PROGRAMS = mkbusy
+mkbusy_SOURCES = mkbusy.c
diff --git a/tests/zfs-tests/cmd/mkbusy/mkbusy.c b/tests/zfs-tests/cmd/mkbusy/mkbusy.c
new file mode 100644 (file)
index 0000000..1e45674
--- /dev/null
@@ -0,0 +1,183 @@
+/*
+ * 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>
+#include <string.h>
+
+typedef enum boolean { B_FALSE, B_TRUE } boolean_t;
+
+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", (long)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);
+}
diff --git a/tests/zfs-tests/cmd/mkfile/.gitignore b/tests/zfs-tests/cmd/mkfile/.gitignore
new file mode 100644 (file)
index 0000000..93e9a8a
--- /dev/null
@@ -0,0 +1 @@
+/mkfile
diff --git a/tests/zfs-tests/cmd/mkfile/Makefile.am b/tests/zfs-tests/cmd/mkfile/Makefile.am
new file mode 100644 (file)
index 0000000..016c671
--- /dev/null
@@ -0,0 +1,6 @@
+include $(top_srcdir)/config/Rules.am
+
+pkgexecdir = $(datadir)/@PACKAGE@/zfs-tests/bin
+
+pkgexec_PROGRAMS = mkfile
+mkfile_SOURCES = mkfile.c
diff --git a/tests/zfs-tests/cmd/mkfile/mkfile.c b/tests/zfs-tests/cmd/mkfile/mkfile.c
new file mode 100644 (file)
index 0000000..4e0be93
--- /dev/null
@@ -0,0 +1,275 @@
+/*
+ * CDDL HEADER START
+ *
+ * The contents of this file are subject to the terms of the
+ * Common Development and Distribution License, Version 1.0 only
+ * (the "License").  You may not use this file except in compliance
+ * with the License.
+ *
+ * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
+ * or http://www.opensolaris.org/os/licensing.
+ * See the License for the specific language governing permissions
+ * and limitations under the License.
+ *
+ * When distributing Covered Code, include this CDDL HEADER in each
+ * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
+ * If applicable, add the following below this CDDL HEADER, with the
+ * fields enclosed by brackets "[]" replaced with your own identifying
+ * information: Portions Copyright [yyyy] [name of copyright owner]
+ *
+ * CDDL HEADER END
+ */
+
+/*
+ * Copyright 2005 Sun Microsystems, Inc.  All rights reserved.
+ * Use is subject to license terms.
+ */
+
+#include <stdio.h>
+#include <ctype.h>
+#include <unistd.h>
+#include <sys/stat.h>
+#include <fcntl.h>
+#include <stdlib.h>
+#include <string.h>
+#include <libintl.h>
+#include <errno.h>
+
+#define        MIN(a, b)       ((a) < (b) ? (a) : (b))
+
+#define        BLOCK_SIZE      512             /* bytes */
+#define        KILOBYTE        1024
+#define        MEGABYTE        (KILOBYTE * KILOBYTE)
+#define        GIGABYTE        (KILOBYTE * MEGABYTE)
+
+#define        FILE_MODE       (S_ISVTX + S_IRUSR + S_IWUSR)
+
+typedef long long      offset_t;
+
+static void usage(void);
+
+int
+main(int argc, char **argv)
+{
+       char    *opts;
+       off_t   size;
+       size_t  len;
+       size_t  mult = 1;
+       char    *buf = NULL;
+       size_t  bufsz = 0;
+       int     errors = 0;
+       int     i;
+       int     verbose = 0;    /* option variable */
+       int     nobytes = 0;    /* option variable */
+       int     saverr;
+
+       if (argc == 1)
+               usage();
+
+       while (argv[1] && argv[1][0] == '-') {
+               opts = &argv[1][0];
+               while (*(++opts)) {
+                       switch (*opts) {
+                       case 'v':
+                               verbose++;
+                               break;
+                       case 'n':
+                               nobytes++;
+                               break;
+                       default:
+                               usage();
+                       }
+               }
+               argc--;
+               argv++;
+       }
+       if (argc < 3)
+               usage();
+
+       len = strlen(argv[1]);
+       if (len && isalpha(argv[1][len-1])) {
+               switch (argv[1][len-1]) {
+               case 'k':
+               case 'K':
+                       mult = KILOBYTE;
+                       break;
+               case 'b':
+               case 'B':
+                       mult = BLOCK_SIZE;
+                       break;
+               case 'm':
+               case 'M':
+                       mult = MEGABYTE;
+                       break;
+               case 'g':
+               case 'G':
+                       mult = GIGABYTE;
+                       break;
+               default:
+                       (void) fprintf(stderr,
+                           gettext("unknown size %s\n"), argv[1]);
+                       usage();
+               }
+
+               for (i = 0; i <= (len-2); i++) {
+                       if (!isdigit(argv[1][i])) {
+                               (void) fprintf(stderr,
+                                   gettext("unknown size %s\n"), argv[1]);
+                               usage();
+                       }
+               }
+               argv[1][len-1] = '\0';
+       }
+       size = ((off_t)atoll(argv[1]) * (off_t)mult);
+
+       argv++;
+       argc--;
+
+       while (argc > 1) {
+               int fd;
+
+               if (verbose)
+                       (void) fprintf(stdout, gettext("%s %lld bytes\n"),
+                           argv[1], (offset_t)size);
+               fd = open(argv[1], O_CREAT|O_TRUNC|O_RDWR, FILE_MODE);
+               if (fd < 0) {
+                       saverr = errno;
+                       (void) fprintf(stderr,
+                           gettext("Could not open %s: %s\n"),
+                           argv[1], strerror(saverr));
+                       errors++;
+                       argv++;
+                       argc--;
+                       continue;
+               }
+               if (lseek(fd, (off_t)size-1, SEEK_SET) < 0) {
+                       saverr = errno;
+                       (void) fprintf(stderr, gettext(
+                           "Could not seek to offset %ld in %s: %s\n"),
+                           (unsigned long)size-1, argv[1], strerror(saverr));
+                       (void) close(fd);
+                       errors++;
+                       argv++;
+                       argc--;
+                       continue;
+               } else if (write(fd, "", 1) != 1) {
+                       saverr = errno;
+                       (void) fprintf(stderr, gettext(
+                           "Could not set length of %s: %s\n"),
+                           argv[1], strerror(saverr));
+                       (void) close(fd);
+                       errors++;
+                       argv++;
+                       argc--;
+                       continue;
+               }
+
+               if (!nobytes) {
+                       off_t written = 0;
+                       struct stat64 st;
+
+                       if (lseek(fd, (off_t)0, SEEK_SET) < 0) {
+                               saverr = errno;
+                               (void) fprintf(stderr, gettext(
+                                   "Could not seek to beginning of %s: %s\n"),
+                                   argv[1], strerror(saverr));
+                               (void) close(fd);
+                               errors++;
+                               argv++;
+                               argc--;
+                               continue;
+                       }
+                       if (fstat64(fd, &st) < 0) {
+                               saverr = errno;
+                               (void) fprintf(stderr, gettext(
+                                   "Could not fstat64 %s: %s\n"),
+                                   argv[1], strerror(saverr));
+                               (void) close(fd);
+                               errors++;
+                               argv++;
+                               argc--;
+                               continue;
+                       }
+                       if (bufsz != st.st_blksize) {
+                               if (buf)
+                                       free(buf);
+                               bufsz = (size_t)st.st_blksize;
+                               buf = calloc(bufsz, 1);
+                               if (buf == NULL) {
+                                       (void) fprintf(stderr, gettext(
+                                           "Could not allocate buffer of"
+                                           " size %d\n"), (int)bufsz);
+                                       (void) close(fd);
+                                       bufsz = 0;
+                                       errors++;
+                                       argv++;
+                                       argc--;
+                                       continue;
+                               }
+                       }
+                       while (written < size) {
+                               ssize_t result;
+                               size_t bytes = (size_t)MIN(bufsz, size-written);
+
+                               if ((result = write(fd, buf, bytes)) !=
+                                   (ssize_t)bytes) {
+                                       saverr = errno;
+                                       if (result < 0)
+                                           result = 0;
+                                       written += result;
+                                       (void) fprintf(stderr, gettext(
+                           "%s: initialized %lu of %lu bytes: %s\n"),
+                                           argv[1], (unsigned long)written,
+                                           (unsigned long)size,
+                                           strerror(saverr));
+                                       errors++;
+                                       break;
+                               }
+                               written += bytes;
+                       }
+
+                       /*
+                        * A write(2) call in the above loop failed so
+                        * close out this file and go on (error was
+                        * already incremented when the write(2) failed).
+                        */
+                       if (written < size) {
+                               (void) close(fd);
+                               argv++;
+                               argc--;
+                               continue;
+                       }
+               }
+               if (close(fd) < 0) {
+                       saverr = errno;
+                       (void) fprintf(stderr, gettext(
+                           "Error encountered when closing %s: %s\n"),
+                           argv[1], strerror(saverr));
+                       errors++;
+                       argv++;
+                       argc--;
+                       continue;
+               }
+
+               /*
+                * Only set the modes (including the sticky bit) if we
+                * had no problems.  It is not an error for the chmod(2)
+                * to fail, but do issue a warning.
+                */
+               if (chmod(argv[1], FILE_MODE) < 0)
+                       (void) fprintf(stderr, gettext(
+                           "warning: couldn't set mode to %#o\n"), FILE_MODE);
+
+               argv++;
+               argc--;
+       }
+       return (errors);
+}
+
+static void usage()
+{
+       (void) fprintf(stderr, gettext(
+               "Usage: mkfile [-nv] <size>[g|k|b|m] <name1> [<name2>] ...\n"));
+       exit(1);
+       /* NOTREACHED */
+}
diff --git a/tests/zfs-tests/cmd/mkfiles/.gitignore b/tests/zfs-tests/cmd/mkfiles/.gitignore
new file mode 100644 (file)
index 0000000..cee4858
--- /dev/null
@@ -0,0 +1 @@
+/mkfiles
diff --git a/tests/zfs-tests/cmd/mkfiles/Makefile.am b/tests/zfs-tests/cmd/mkfiles/Makefile.am
new file mode 100644 (file)
index 0000000..54c2159
--- /dev/null
@@ -0,0 +1,6 @@
+include $(top_srcdir)/config/Rules.am
+
+pkgexecdir = $(datadir)/@PACKAGE@/zfs-tests/bin
+
+pkgexec_PROGRAMS = mkfiles
+mkfiles_SOURCES = mkfiles.c
diff --git a/tests/zfs-tests/cmd/mkfiles/mkfiles.c b/tests/zfs-tests/cmd/mkfiles/mkfiles.c
new file mode 100644 (file)
index 0000000..418fb9d
--- /dev/null
@@ -0,0 +1,65 @@
+/*
+ * 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) 2016 by Delphix. All rights reserved.
+ */
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <fcntl.h>
+#include <string.h>
+#include <errno.h>
+#include <unistd.h>
+#include <sys/param.h>
+
+#define        MAX_INT_LENGTH 10
+
+static void
+usage(char *msg, int exit_value)
+{
+       (void) fprintf(stderr, "mkfiles basename max_file [min_file]\n");
+       (void) fprintf(stderr, "%s\n", msg);
+       exit(exit_value);
+}
+
+int
+main(int argc, char **argv)
+{
+       unsigned int numfiles = 0;
+       unsigned int first_file = 0;
+       unsigned int i;
+       char buf[MAXPATHLEN];
+
+       if (argc < 3 || argc > 4)
+               usage("Invalid number of arguments", -1);
+
+       if (sscanf(argv[2], "%u", &numfiles) != 1)
+               usage("Invalid maximum file", -2);
+
+       if (argc == 4 && sscanf(argv[3], "%u", &first_file) != 1)
+               usage("Invalid first file", -3);
+
+       if (numfiles < first_file)
+               usage("First file larger than last file", -3);
+
+       for (i = first_file; i <= numfiles; i++) {
+               int fd;
+               (void) snprintf(buf, MAXPATHLEN, "%s%u", argv[1], i);
+               if ((fd = open(buf, O_CREAT | O_EXCL, O_RDWR)) == -1) {
+                       (void) fprintf(stderr, "Failed to create %s %s\n", buf,
+                           strerror(errno));
+                       return (-4);
+               }
+               (void) close(fd);
+       }
+       return (0);
+}
diff --git a/tests/zfs-tests/cmd/mktree/.gitignore b/tests/zfs-tests/cmd/mktree/.gitignore
new file mode 100644 (file)
index 0000000..588bc6d
--- /dev/null
@@ -0,0 +1 @@
+/mktree
diff --git a/tests/zfs-tests/cmd/mktree/Makefile.am b/tests/zfs-tests/cmd/mktree/Makefile.am
new file mode 100644 (file)
index 0000000..88c74ae
--- /dev/null
@@ -0,0 +1,6 @@
+include $(top_srcdir)/config/Rules.am
+
+pkgexecdir = $(datadir)/@PACKAGE@/zfs-tests/bin
+
+pkgexec_PROGRAMS = mktree
+mktree_SOURCES = mktree.c
diff --git a/tests/zfs-tests/cmd/mktree/mktree.c b/tests/zfs-tests/cmd/mktree/mktree.c
new file mode 100644 (file)
index 0000000..8f9b385
--- /dev/null
@@ -0,0 +1,183 @@
+/*
+ * CDDL HEADER START
+ *
+ * The contents of this file are subject to the terms of the
+ * Common Development and Distribution License (the "License").
+ * You may not use this file except in compliance with the License.
+ *
+ * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
+ * or http://www.opensolaris.org/os/licensing.
+ * See the License for the specific language governing permissions
+ * and limitations under the License.
+ *
+ * When distributing Covered Code, include this CDDL HEADER in each
+ * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
+ * If applicable, add the following below this CDDL HEADER, with the
+ * fields enclosed by brackets "[]" replaced with your own identifying
+ * information: 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 <attr/xattr.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'
+
+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 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 (fsetxattr(fd, "xattr", pbuf, 1024, 0) < 0) {
+               (void) fprintf(stderr, "fsetxattr(fd, \"xattr\", pbuf, "
+                   "1024, 0) failed.\n[%d]: %s.\n", errno, strerror(errno));
+               exit(errno);
+       }
+
+       (void) close(fd);
+       free(pbuf);
+}
diff --git a/tests/zfs-tests/cmd/mmap_exec/.gitignore b/tests/zfs-tests/cmd/mmap_exec/.gitignore
new file mode 100644 (file)
index 0000000..63a68bb
--- /dev/null
@@ -0,0 +1 @@
+/mmap_exec
diff --git a/tests/zfs-tests/cmd/mmap_exec/Makefile.am b/tests/zfs-tests/cmd/mmap_exec/Makefile.am
new file mode 100644 (file)
index 0000000..ab9f81b
--- /dev/null
@@ -0,0 +1,6 @@
+include $(top_srcdir)/config/Rules.am
+
+pkgexecdir = $(datadir)/@PACKAGE@/zfs-tests/bin
+
+pkgexec_PROGRAMS = mmap_exec
+mmap_exec_SOURCES = mmap_exec.c
diff --git a/tests/zfs-tests/cmd/mmap_exec/mmap_exec.c b/tests/zfs-tests/cmd/mmap_exec/mmap_exec.c
new file mode 100644 (file)
index 0000000..6a48a9c
--- /dev/null
@@ -0,0 +1,69 @@
+/*
+ * CDDL HEADER START
+ *
+ * The contents of this file are subject to the terms of the
+ * Common Development and Distribution License (the "License").
+ * You may not use this file except in compliance with the License.
+ *
+ * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
+ * or http://www.opensolaris.org/os/licensing.
+ * See the License for the specific language governing permissions
+ * and limitations under the License.
+ *
+ * When distributing Covered Code, include this CDDL HEADER in each
+ * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
+ * If applicable, add the following below this CDDL HEADER, with the
+ * fields enclosed by brackets "[]" replaced with your own identifying
+ * information: Portions Copyright [yyyy] [name of copyright owner]
+ *
+ * CDDL HEADER END
+ */
+
+/*
+ * Copyright 2007 Sun Microsystems, Inc.  All rights reserved.
+ * Use is subject to license terms.
+ */
+
+/*
+ * Copyright (c) 2013 by Delphix. All rights reserved.
+ */
+
+#include <stdio.h>
+#include <sys/stat.h>
+#include <fcntl.h>
+#include <sys/types.h>
+#include <sys/mman.h>
+#include <errno.h>
+
+int
+main(int argc, char *argv[])
+{
+       int fd;
+       struct stat statbuf;
+
+       if (argc != 2) {
+               (void) printf("Error: missing binary name.\n");
+               (void) printf("Usage:\n\t%s <binary name>\n",
+                   argv[0]);
+               return (1);
+       }
+
+       errno = 0;
+
+       if ((fd = open(argv[1], O_RDONLY)) < 0) {
+               perror("open");
+               return (errno);
+       }
+       if (fstat(fd, &statbuf) < 0) {
+               perror("fstat");
+               return (errno);
+       }
+
+       if (mmap(0, statbuf.st_size,
+           PROT_EXEC, MAP_SHARED, fd, 0) == MAP_FAILED) {
+               perror("mmap");
+               return (errno);
+       }
+
+       return (0);
+}
diff --git a/tests/zfs-tests/cmd/mmapwrite/.gitignore b/tests/zfs-tests/cmd/mmapwrite/.gitignore
new file mode 100644 (file)
index 0000000..4e7043b
--- /dev/null
@@ -0,0 +1 @@
+/mmapwrite
diff --git a/tests/zfs-tests/cmd/mmapwrite/Makefile.am b/tests/zfs-tests/cmd/mmapwrite/Makefile.am
new file mode 100644 (file)
index 0000000..b21b9e7
--- /dev/null
@@ -0,0 +1,7 @@
+include $(top_srcdir)/config/Rules.am
+
+pkgexecdir = $(datadir)/@PACKAGE@/zfs-tests/bin
+
+pkgexec_PROGRAMS = mmapwrite
+mmapwrite_SOURCES = mmapwrite.c
+mmapwrite_LDADD = -lpthread
diff --git a/tests/zfs-tests/cmd/mmapwrite/mmapwrite.c b/tests/zfs-tests/cmd/mmapwrite/mmapwrite.c
new file mode 100644 (file)
index 0000000..2eca124
--- /dev/null
@@ -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.
+ */
+
+#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];
+       pthread_t tid;
+
+       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);
+       }
+
+       (void) pthread_setconcurrency(2);
+       if (pthread_create(&tid, NULL, mapper, &fd) != 0) {
+               perror("pthread_create");
+               exit(1);
+       }
+       for (;;) {
+               if (write(fd, buf, sizeof (buf)) == -1) {
+                       perror("write");
+                       exit(1);
+               }
+       }
+
+       /* NOTREACHED */
+       return (0);
+}
diff --git a/tests/zfs-tests/cmd/randfree_file/.gitignore b/tests/zfs-tests/cmd/randfree_file/.gitignore
new file mode 100644 (file)
index 0000000..0f5b394
--- /dev/null
@@ -0,0 +1 @@
+/randfree_file
diff --git a/tests/zfs-tests/cmd/randfree_file/Makefile.am b/tests/zfs-tests/cmd/randfree_file/Makefile.am
new file mode 100644 (file)
index 0000000..6306e0e
--- /dev/null
@@ -0,0 +1,6 @@
+include $(top_srcdir)/config/Rules.am
+
+pkgexecdir = $(datadir)/@PACKAGE@/zfs-tests/bin
+
+pkgexec_PROGRAMS = randfree_file
+randfree_file_SOURCES = randfree_file.c
diff --git a/tests/zfs-tests/cmd/randfree_file/randfree_file.c b/tests/zfs-tests/cmd/randfree_file/randfree_file.c
new file mode 100644 (file)
index 0000000..8e7487c
--- /dev/null
@@ -0,0 +1,105 @@
+/*
+ * CDDL HEADER START
+ *
+ * The contents of this file are subject to the terms of the
+ * Common Development and Distribution License (the "License").
+ * You may not use this file except in compliance with the License.
+ *
+ * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
+ * or http://www.opensolaris.org/os/licensing.
+ * See the License for the specific language governing permissions
+ * and limitations under the License.
+ *
+ * When distributing Covered Code, include this CDDL HEADER in each
+ * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
+ * If applicable, add the following below this CDDL HEADER, with the
+ * fields enclosed by brackets "[]" replaced with your own identifying
+ * information: Portions Copyright [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/types.h>
+#include <unistd.h>
+#include <fcntl.h>
+#include <linux/falloc.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;
+       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);
+       }
+
+       if (fallocate(fd, FALLOC_FL_PUNCH_HOLE | FALLOC_FL_KEEP_SIZE,
+           start_off, off_len) < 0) {
+               perror("fallocate");
+               return (1);
+       }
+
+       free(buf);
+       return (0);
+}
diff --git a/tests/zfs-tests/cmd/readmmap/.gitignore b/tests/zfs-tests/cmd/readmmap/.gitignore
new file mode 100644 (file)
index 0000000..3799193
--- /dev/null
@@ -0,0 +1 @@
+/readmmap
diff --git a/tests/zfs-tests/cmd/readmmap/Makefile.am b/tests/zfs-tests/cmd/readmmap/Makefile.am
new file mode 100644 (file)
index 0000000..9b735c2
--- /dev/null
@@ -0,0 +1,6 @@
+include $(top_srcdir)/config/Rules.am
+
+pkgexecdir = $(datadir)/@PACKAGE@/zfs-tests/bin
+
+pkgexec_PROGRAMS = readmmap
+readmmap_SOURCES = readmmap.c
diff --git a/tests/zfs-tests/cmd/readmmap/readmmap.c b/tests/zfs-tests/cmd/readmmap/readmmap.c
new file mode 100644 (file)
index 0000000..e21c2c8
--- /dev/null
@@ -0,0 +1,138 @@
+/*
+ * CDDL HEADER START
+ *
+ * The contents of this file are subject to the terms of the
+ * Common Development and Distribution License (the "License").
+ * You may not use this file except in compliance with the License.
+ *
+ * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
+ * or http://www.opensolaris.org/os/licensing.
+ * See the License for the specific language governing permissions
+ * and limitations under the License.
+ *
+ * When distributing Covered Code, include this CDDL HEADER in each
+ * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
+ * If applicable, add the following below this CDDL HEADER, with the
+ * fields enclosed by brackets "[]" replaced with your own identifying
+ * information: 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>
+#include <time.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 != %zd\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 != %zd\n", bytes, size);
+               retval = 1;
+               goto end;
+       }
+
+       if (buf[idx] != 1) {
+               (void) printf(
+                   "bad data from read!  got buf[%zd]=%d, expected 1\n",
+                   idx, buf[idx]);
+               retval = 1;
+               goto end;
+       }
+
+       (void) printf("good data from read: buf[%zd]=1\n", idx);
+end:
+       if (fd != -1) {
+               (void) close(fd);
+       }
+       if (buf != NULL) {
+               free(buf);
+       }
+
+       return (retval);
+}
diff --git a/tests/zfs-tests/cmd/rename_dir/.gitignore b/tests/zfs-tests/cmd/rename_dir/.gitignore
new file mode 100644 (file)
index 0000000..39a0cb2
--- /dev/null
@@ -0,0 +1 @@
+/rename_dir
diff --git a/tests/zfs-tests/cmd/rename_dir/Makefile.am b/tests/zfs-tests/cmd/rename_dir/Makefile.am
new file mode 100644 (file)
index 0000000..21971cd
--- /dev/null
@@ -0,0 +1,6 @@
+include $(top_srcdir)/config/Rules.am
+
+pkgexecdir = $(datadir)/@PACKAGE@/zfs-tests/bin
+
+pkgexec_PROGRAMS = rename_dir
+rename_dir_SOURCES = rename_dir.c
diff --git a/tests/zfs-tests/cmd/rename_dir/rename_dir.c b/tests/zfs-tests/cmd/rename_dir/rename_dir.c
new file mode 100644 (file)
index 0000000..5f80f72
--- /dev/null
@@ -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 argc, char *argvp[])
+{
+       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);
+}
diff --git a/tests/zfs-tests/cmd/rm_lnkcnt_zero_file/.gitignore b/tests/zfs-tests/cmd/rm_lnkcnt_zero_file/.gitignore
new file mode 100644 (file)
index 0000000..fc6323f
--- /dev/null
@@ -0,0 +1 @@
+/rm_lnkcnt_zero_file
diff --git a/tests/zfs-tests/cmd/rm_lnkcnt_zero_file/Makefile.am b/tests/zfs-tests/cmd/rm_lnkcnt_zero_file/Makefile.am
new file mode 100644 (file)
index 0000000..90fc8d0
--- /dev/null
@@ -0,0 +1,7 @@
+include $(top_srcdir)/config/Rules.am
+
+pkgexecdir = $(datadir)/@PACKAGE@/zfs-tests/bin
+
+pkgexec_PROGRAMS = rm_lnkcnt_zero_file
+rm_lnkcnt_zero_file_SOURCES = rm_lnkcnt_zero_file.c
+rm_lnkcnt_zero_file_LDADD = -lpthread
diff --git a/tests/zfs-tests/cmd/rm_lnkcnt_zero_file/rm_lnkcnt_zero_file.c b/tests/zfs-tests/cmd/rm_lnkcnt_zero_file/rm_lnkcnt_zero_file.c
new file mode 100644 (file)
index 0000000..ee85a20
--- /dev/null
@@ -0,0 +1,155 @@
+/*
+ * CDDL HEADER START
+ *
+ * The contents of this file are subject to the terms of the
+ * Common Development and Distribution License (the "License").
+ * You may not use this file except in compliance with the License.
+ *
+ * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
+ * or http://www.opensolaris.org/os/licensing.
+ * See the License for the specific language governing permissions
+ * and limitations under the License.
+ *
+ * When distributing Covered Code, include this CDDL HEADER in each
+ * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
+ * If applicable, add the following below this CDDL HEADER, with the
+ * fields enclosed by brackets "[]" replaced with your own identifying
+ * information: Portions Copyright [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 <string.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(void)
+{
+       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;
+       int ret;
+
+       while (TRUE) {
+               (void) close (*fd);
+               *fd = open(filebase, O_APPEND | O_RDWR | O_CREAT, 0644);
+               if (*fd < 0)
+                       perror("refreshing file");
+               ret = write(*fd, "test\n", 5);
+               if (ret != 5)
+                       perror("writing file");
+       }
+
+       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) pthread_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);
+}
diff --git a/tests/zfs-tests/cmd/threadsappend/.gitignore b/tests/zfs-tests/cmd/threadsappend/.gitignore
new file mode 100644 (file)
index 0000000..4c8c8cd
--- /dev/null
@@ -0,0 +1 @@
+/threadsappend
diff --git a/tests/zfs-tests/cmd/threadsappend/Makefile.am b/tests/zfs-tests/cmd/threadsappend/Makefile.am
new file mode 100644 (file)
index 0000000..f030b42
--- /dev/null
@@ -0,0 +1,7 @@
+include $(top_srcdir)/config/Rules.am
+
+pkgexecdir = $(datadir)/@PACKAGE@/zfs-tests/bin
+
+pkgexec_PROGRAMS = threadsappend
+threadsappend_SOURCES = threadsappend.c
+threadsappend_LDADD = -lpthread
diff --git a/tests/zfs-tests/cmd/threadsappend/threadsappend.c b/tests/zfs-tests/cmd/threadsappend/threadsappend.c
new file mode 100644 (file)
index 0000000..25710a3
--- /dev/null
@@ -0,0 +1,135 @@
+/*
+ * CDDL HEADER START
+ *
+ * The contents of this file are subject to the terms of the
+ * Common Development and Distribution License (the "License").
+ * You may not use this file except in compliance with the License.
+ *
+ * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
+ * or http://www.opensolaris.org/os/licensing.
+ * See the License for the specific language governing permissions
+ * and limitations under the License.
+ *
+ * When distributing Covered Code, include this CDDL HEADER in each
+ * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
+ * If applicable, add the following below this CDDL HEADER, with the
+ * fields enclosed by brackets "[]" replaced with your own identifying
+ * information: Portions Copyright [yyyy] [name of copyright owner]
+ *
+ * CDDL HEADER END
+ */
+
+/*
+ * Copyright 2007 Sun Microsystems, Inc.  All rights reserved.
+ * Use is subject to license terms.
+ */
+
+/*
+ * Copyright (c) 2013 by Delphix. All rights reserved.
+ */
+
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <fcntl.h>
+#include <pthread.h>
+#include <string.h>
+#include <stdio.h>
+#include <unistd.h>
+#include <stdlib.h>
+#include <errno.h>
+
+/*
+ * The size of the output file, "go.out", should be 80*8192*2 = 1310720
+ *
+ * $ cd /tmp; go; ls -l go.out
+ * done.
+ * -rwxr-xr-x  1 jdm   staff   1310720 Apr 13 19:45 go.out
+ * $ cd /zfs; go; ls -l go.out
+ * done.
+ * -rwxr-xr-x  1 jdm   staff   663552 Apr 13 19:45 go.out
+ *
+ * The file on zfs is short as it does not appear that zfs is making the
+ * implicit seek to EOF and the actual write atomic. From the SUSv3
+ * interface spec, behavior is undefined if concurrent writes are performed
+ * from multi-processes to a single file. So I don't know if this is a
+ * standards violation, but I cannot find any such disclaimers in our
+ * man pages. This issue came up at a customer site in another context, and
+ * the suggestion was to open the file with O_APPEND, but that wouldn't
+ * help with zfs(see 4977529). Also see bug# 5031301.
+ */
+
+static int outfd = 0;
+
+static void *
+go(void *data)
+{
+       int ret, i = 0, n = *(int *)data;
+       char buf[8192] = {0};
+       (void) memset(buf, n, sizeof (buf));
+
+       for (i = 0; i < 80; i++) {
+               ret = write(outfd, buf, sizeof (buf));
+               if (ret != sizeof (buf))
+                       perror("write");
+       }
+       return (NULL);
+}
+
+static void
+usage(void)
+{
+       (void) fprintf(stderr,
+           "usage: zfs_threadsappend <file name>\n");
+       exit(1);
+}
+
+int
+main(int argc, char **argv)
+{
+       pthread_t tid;
+       int     ret = 0;
+       long    ncpus = 0;
+       int     i;
+
+       if (argc != 2) {
+               usage();
+       }
+
+       ncpus = sysconf(_SC_NPROCESSORS_ONLN);
+       if (ncpus < 0) {
+               (void) fprintf(stderr,
+                   "Invalid return from sysconf(_SC_NPROCESSORS_ONLN)"
+                   " : errno (decimal)=%d\n", errno);
+               exit(1);
+       }
+       if (ncpus < 2) {
+               (void) fprintf(stderr,
+                   "Must execute this binary on a multi-processor system\n");
+               exit(1);
+       }
+
+       outfd = open(argv[optind++], O_RDWR|O_CREAT|O_APPEND|O_TRUNC, 0777);
+       if (outfd == -1) {
+               (void) fprintf(stderr,
+                   "zfs_threadsappend: "
+                   "open(%s, O_RDWR|O_CREAT|O_APPEND|O_TRUNC, 0777)"
+                   " failed\n", argv[optind]);
+               perror("open");
+               exit(1);
+       }
+
+       for (i = 0; i < 2; i++) {
+               ret = pthread_create(&tid, NULL, go, (void *)&i);
+               if (ret != 0) {
+                       (void) fprintf(stderr,
+                           "zfs_threadsappend: thr_create(#%d) "
+                           "failed error=%d\n", i+1, ret);
+                       exit(1);
+               }
+       }
+
+       while (pthread_join(tid, NULL) == 0)
+               continue;
+
+       return (0);
+}
diff --git a/tests/zfs-tests/cmd/xattrtest/.gitignore b/tests/zfs-tests/cmd/xattrtest/.gitignore
new file mode 100644 (file)
index 0000000..7d21283
--- /dev/null
@@ -0,0 +1 @@
+/xattrtest
diff --git a/tests/zfs-tests/cmd/xattrtest/Makefile.am b/tests/zfs-tests/cmd/xattrtest/Makefile.am
new file mode 100644 (file)
index 0000000..7398ae6
--- /dev/null
@@ -0,0 +1,6 @@
+include $(top_srcdir)/config/Rules.am
+
+pkgexecdir = $(datadir)/@PACKAGE@/zfs-tests/bin
+
+pkgexec_PROGRAMS = xattrtest
+xattrtest_SOURCES = xattrtest.c
diff --git a/tests/zfs-tests/cmd/xattrtest/xattrtest.c b/tests/zfs-tests/cmd/xattrtest/xattrtest.c
new file mode 100644 (file)
index 0000000..22f798d
--- /dev/null
@@ -0,0 +1,641 @@
+/*
+ * CDDL HEADER START
+ *
+ * The contents of this file are subject to the terms of the
+ * Common Development and Distribution License (the "License").
+ * You may not use this file except in compliance with the License.
+ *
+ * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
+ * or http://www.opensolaris.org/os/licensing.
+ * See the License for the specific language governing permissions
+ * and limitations under the License.
+ *
+ * When distributing Covered Code, include this CDDL HEADER in each
+ * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
+ * If applicable, add the following below this CDDL HEADER, with the
+ * fields enclosed by brackets "[]" replaced with your own identifying
+ * information: Portions Copyright [yyyy] [name of copyright owner]
+ *
+ * CDDL HEADER END
+ */
+
+/*
+ * Copyright 2016 Lawrence Livermore National Security, LLC.
+ */
+
+/*
+ * An extended attribute (xattr) correctness test.  This program creates
+ * N files and sets M attrs on them of size S.  Optionally is will verify
+ * a pattern stored in the xattr.
+ */
+#include <stdlib.h>
+#include <stddef.h>
+#include <stdio.h>
+#include <string.h>
+#include <errno.h>
+#include <getopt.h>
+#include <fcntl.h>
+#include <time.h>
+#include <unistd.h>
+#include <attr/xattr.h>
+#include <sys/types.h>
+#include <sys/wait.h>
+#include <sys/stat.h>
+#include <sys/time.h>
+#include <linux/limits.h>
+
+extern char *program_invocation_short_name;
+
+#define        ERROR(fmt, ...)                                                 \
+       fprintf(stderr, "%s: %s:%d: %s: " fmt "\n",                     \
+               program_invocation_short_name, __FILE__, __LINE__,      \
+               __func__, ## __VA_ARGS__);
+
+static const char shortopts[] = "hvycdn:f:x:s:p:t:e:rRk";
+static const struct option longopts[] = {
+       { "help",               no_argument,            0,      'h' },
+       { "verbose",            no_argument,            0,      'v' },
+       { "verify",             no_argument,            0,      'y' },
+       { "nth",                required_argument,      0,      'n' },
+       { "files",              required_argument,      0,      'f' },
+       { "xattrs",             required_argument,      0,      'x' },
+       { "size",               required_argument,      0,      's' },
+       { "path",               required_argument,      0,      'p' },
+       { "synccaches",         no_argument,            0,      'c' },
+       { "dropcaches",         no_argument,            0,      'd' },
+       { "script",             required_argument,      0,      't' },
+       { "seed",               required_argument,      0,      'e' },
+       { "random",             no_argument,            0,      'r' },
+       { "randomvalue",        no_argument,            0,      'R' },
+       { "keep",               no_argument,            0,      'k' },
+       { 0,                    0,                      0,      0   }
+};
+
+static int verbose = 0;
+static int verify = 0;
+static int synccaches = 0;
+static int dropcaches = 0;
+static int nth = 0;
+static int files = 1000;
+static int xattrs = 1;
+static int size  = 1;
+static int size_is_random = 0;
+static int value_is_random = 0;
+static int keep_files = 0;
+static char path[PATH_MAX] = "/tmp/xattrtest";
+static char script[PATH_MAX] = "/bin/true";
+
+static int
+usage(int argc, char **argv) {
+       fprintf(stderr,
+       "usage: %s [-hvycdrRk] [-n <nth>] [-f <files>] [-x <xattrs>]\n"
+       "       [-s <bytes>] [-p <path>] [-t <script> ]\n", argv[0]);
+       fprintf(stderr,
+       "  --help        -h           This help\n"
+       "  --verbose     -v           Increase verbosity\n"
+       "  --verify      -y           Verify xattr contents\n"
+       "  --nth         -n <nth>     Print every nth file\n"
+       "  --files       -f <files>   Set xattrs on N files\n"
+       "  --xattrs      -x <xattrs>  Set N xattrs on each file\n"
+       "  --size        -s <bytes>   Set N bytes per xattr\n"
+       "  --path        -p <path>    Path to files\n"
+       "  --synccaches  -c           Sync caches between phases\n"
+       "  --dropcaches  -d           Drop caches between phases\n"
+       "  --script      -t <script>  Exec script between phases\n"
+       "  --seed        -e <seed>    Random seed value\n"
+       "  --random      -r           Randomly sized xattrs [16-size]\n"
+       "  --randomvalue -R           Random xattr values\n"
+       "  --keep        -k           Don't unlink files\n\n");
+
+       return (0);
+}
+
+static int
+parse_args(int argc, char **argv)
+{
+       long seed = time(NULL);
+       int c;
+       int rc;
+
+       while ((c = getopt_long(argc, argv, shortopts, longopts, NULL)) != -1) {
+               switch (c) {
+               case 'h':
+                       return (usage(argc, argv));
+               case 'v':
+                       verbose++;
+                       break;
+               case 'y':
+                       verify = 1;
+                       if (value_is_random != 0) {
+                               fprintf(stderr,
+                                   "Error: -y and -R are incompatible.\n");
+                               rc = 1;
+                       }
+                       break;
+               case 'n':
+                       nth = strtol(optarg, NULL, 0);
+                       break;
+               case 'f':
+                       files = strtol(optarg, NULL, 0);
+                       break;
+               case 'x':
+                       xattrs = strtol(optarg, NULL, 0);
+                       break;
+               case 's':
+                       size = strtol(optarg, NULL, 0);
+                       if (size > XATTR_SIZE_MAX) {
+                               fprintf(stderr, "Error: the size may not be "
+                                   "greater than %d\n", XATTR_SIZE_MAX);
+                               rc = 1;
+                       }
+                       break;
+               case 'p':
+                       strncpy(path, optarg, PATH_MAX);
+                       break;
+               case 'c':
+                       synccaches = 1;
+                       break;
+               case 'd':
+                       dropcaches = 1;
+                       break;
+               case 't':
+                       strncpy(script, optarg, PATH_MAX);
+                       break;
+               case 'e':
+                       seed = strtol(optarg, NULL, 0);
+                       break;
+               case 'r':
+                       size_is_random = 1;
+                       break;
+               case 'R':
+                       value_is_random = 1;
+                       if (verify != 0) {
+                               fprintf(stderr,
+                                   "Error: -y and -R are incompatible.\n");
+                               rc = 1;
+                       }
+                       break;
+               case 'k':
+                       keep_files = 1;
+                       break;
+               default:
+                       rc = 1;
+                       break;
+               }
+       }
+
+       if (rc != 0)
+               return (rc);
+
+       srandom(seed);
+
+       if (verbose) {
+               fprintf(stdout, "verbose:          %d\n", verbose);
+               fprintf(stdout, "verify:           %d\n", verify);
+               fprintf(stdout, "nth:              %d\n", nth);
+               fprintf(stdout, "files:            %d\n", files);
+               fprintf(stdout, "xattrs:           %d\n", xattrs);
+               fprintf(stdout, "size:             %d\n", size);
+               fprintf(stdout, "path:             %s\n", path);
+               fprintf(stdout, "synccaches:       %d\n", synccaches);
+               fprintf(stdout, "dropcaches:       %d\n", dropcaches);
+               fprintf(stdout, "script:           %s\n", script);
+               fprintf(stdout, "seed:             %ld\n", seed);
+               fprintf(stdout, "random size:      %d\n", size_is_random);
+               fprintf(stdout, "random value:     %d\n", value_is_random);
+               fprintf(stdout, "keep:             %d\n", keep_files);
+               fprintf(stdout, "%s", "\n");
+       }
+
+       return (rc);
+}
+
+static int
+drop_caches(void)
+{
+       char file[] = "/proc/sys/vm/drop_caches";
+       int fd, rc;
+
+       fd = open(file, O_WRONLY);
+       if (fd == -1) {
+               ERROR("Error %d: open(\"%s\", O_WRONLY)\n", errno, file);
+               return (errno);
+       }
+
+       rc = write(fd, "3", 1);
+       if ((rc == -1) || (rc != 1)) {
+               ERROR("Error %d: write(%d, \"3\", 1)\n", errno, fd);
+               return (errno);
+       }
+
+       rc = close(fd);
+       if (rc == -1) {
+               ERROR("Error %d: close(%d)\n", errno, fd);
+               return (errno);
+       }
+
+       return (0);
+}
+
+static int
+run_process(const char *path, char *argv[])
+{
+       pid_t pid;
+       int rc, devnull_fd;
+
+       pid = vfork();
+       if (pid == 0) {
+               devnull_fd = open("/dev/null", O_WRONLY);
+
+               if (devnull_fd < 0)
+                       _exit(-1);
+
+               (void) dup2(devnull_fd, STDOUT_FILENO);
+               (void) dup2(devnull_fd, STDERR_FILENO);
+               close(devnull_fd);
+
+               (void) execvp(path, argv);
+               _exit(-1);
+       } else if (pid > 0) {
+               int status;
+
+               while ((rc = waitpid(pid, &status, 0)) == -1 && errno == EINTR);
+
+               if (rc < 0 || !WIFEXITED(status))
+                       return (-1);
+
+               return (WEXITSTATUS(status));
+       }
+
+       return (-1);
+}
+
+static int
+post_hook(char *phase)
+{
+       char *argv[3] = { script, phase, (char *)0 };
+       int rc;
+
+       if (synccaches)
+               sync();
+
+       if (dropcaches) {
+               rc = drop_caches();
+               if (rc)
+                       return (rc);
+       }
+
+       rc = run_process(script, argv);
+       if (rc)
+               return (rc);
+
+       return (0);
+}
+
+#define        USEC_PER_SEC    1000000
+
+static void
+timeval_normalize(struct timeval *tv, time_t sec, suseconds_t usec)
+{
+       while (usec >= USEC_PER_SEC) {
+               usec -= USEC_PER_SEC;
+               sec++;
+       }
+
+       while (usec < 0) {
+               usec += USEC_PER_SEC;
+               sec--;
+       }
+
+       tv->tv_sec = sec;
+       tv->tv_usec = usec;
+}
+
+static void
+timeval_sub(struct timeval *delta, struct timeval *tv1, struct timeval *tv2)
+{
+       timeval_normalize(delta,
+           tv1->tv_sec - tv2->tv_sec,
+           tv1->tv_usec - tv2->tv_usec);
+}
+
+static int
+create_files(void)
+{
+       int i, rc;
+       char *file = NULL;
+       struct timeval start, stop, delta;
+
+       file = malloc(PATH_MAX);
+       if (file == NULL) {
+               rc = ENOMEM;
+               ERROR("Error %d: malloc(%d) bytes for file name\n",
+                       rc, PATH_MAX);
+               goto out;
+       }
+
+       (void) gettimeofday(&start, NULL);
+
+       for (i = 1; i <= files; i++) {
+               (void) sprintf(file, "%s/file-%d", path, i);
+
+               if (nth && ((i % nth) == 0))
+                       fprintf(stdout, "create: %s\n", file);
+
+               rc = unlink(file);
+               if ((rc == -1) && (errno != ENOENT)) {
+                       ERROR("Error %d: unlink(%s)\n", errno, file);
+                       rc = errno;
+                       goto out;
+               }
+
+               rc = open(file, O_CREAT, 0644);
+               if (rc == -1) {
+                       ERROR("Error %d: open(%s, O_CREATE, 0644)\n",
+                               errno, file);
+                       rc = errno;
+                       goto out;
+               }
+
+               rc = close(rc);
+               if (rc == -1) {
+                       ERROR("Error %d: close(%d)\n", errno, rc);
+                       rc = errno;
+                       goto out;
+               }
+       }
+
+       (void) gettimeofday(&stop, NULL);
+       timeval_sub(&delta, &stop, &start);
+       fprintf(stdout, "create:   %d.%d seconds\n",
+           (int)delta.tv_sec, (int)delta.tv_usec);
+
+       rc = post_hook("post");
+out:
+       if (file)
+               free(file);
+
+       return (rc);
+}
+
+static int
+get_random_bytes(char *buf, size_t bytes)
+{
+       int rand;
+       ssize_t bytes_read = 0;
+
+       rand = open("/dev/urandom", O_RDONLY);
+
+       if (rand < 0)
+               return (rand);
+
+       while (bytes_read < bytes) {
+               ssize_t rc = read(rand, buf + bytes_read, bytes - bytes_read);
+               if (rc < 0)
+                       break;
+               bytes_read += rc;
+       }
+
+       (void) close(rand);
+
+       return (bytes_read);
+}
+
+static int
+setxattrs(void)
+{
+       int i, j, rnd_size = size, shift, rc = 0;
+       char name[XATTR_NAME_MAX];
+       char *value = NULL;
+       char *file = NULL;
+       struct timeval start, stop, delta;
+
+       value = malloc(XATTR_SIZE_MAX);
+       if (value == NULL) {
+               rc = ENOMEM;
+               ERROR("Error %d: malloc(%d) bytes for xattr value\n",
+                       rc, XATTR_SIZE_MAX);
+               goto out;
+       }
+
+       file = malloc(PATH_MAX);
+       if (file == NULL) {
+               rc = ENOMEM;
+               ERROR("Error %d: malloc(%d) bytes for file name\n",
+                       rc, PATH_MAX);
+               goto out;
+       }
+
+       (void) gettimeofday(&start, NULL);
+
+       for (i = 1; i <= files; i++) {
+               (void) sprintf(file, "%s/file-%d", path, i);
+
+               if (nth && ((i % nth) == 0))
+                       fprintf(stdout, "setxattr: %s\n", file);
+
+               for (j = 1; j <= xattrs; j++) {
+                       if (size_is_random)
+                               rnd_size = (random() % (size - 16)) + 16;
+
+                       (void) sprintf(name, "user.%d", j);
+                       if (value_is_random) {
+                               rc = get_random_bytes(value, rnd_size);
+                               if (rc < rnd_size) {
+                                       ERROR("Error %d: get_random_bytes() "
+                                           "wanted %d got %d\n", errno,
+                                           rnd_size, rc);
+                                       goto out;
+                               }
+                       } else {
+                               shift = sprintf(value, "size=%d ", rnd_size);
+                               memset(value + shift, 'x', XATTR_SIZE_MAX -
+                                   shift);
+                       }
+
+                       rc = lsetxattr(file, name, value, rnd_size, 0);
+                       if (rc == -1) {
+                               ERROR("Error %d: lsetxattr(%s, %s, ..., %d)\n",
+                                   errno, file, name, rnd_size);
+                               goto out;
+                       }
+               }
+       }
+
+       (void) gettimeofday(&stop, NULL);
+       timeval_sub(&delta, &stop, &start);
+       fprintf(stdout, "setxattr: %d.%d seconds\n",
+           (int)delta.tv_sec, (int)delta.tv_usec);
+
+       rc = post_hook("post");
+out:
+       if (file)
+               free(file);
+
+       if (value)
+               free(value);
+
+       return (rc);
+}
+
+static int
+getxattrs(void)
+{
+       int i, j, rnd_size, shift, rc = 0;
+       char name[XATTR_NAME_MAX];
+       char *verify_value = NULL;
+       char *value = NULL;
+       char *file = NULL;
+       struct timeval start, stop, delta;
+
+       verify_value = malloc(XATTR_SIZE_MAX);
+       if (verify_value == NULL) {
+               rc = ENOMEM;
+               ERROR("Error %d: malloc(%d) bytes for xattr verify\n",
+                       rc, XATTR_SIZE_MAX);
+               goto out;
+       }
+
+       value = malloc(XATTR_SIZE_MAX);
+       if (value == NULL) {
+               rc = ENOMEM;
+               ERROR("Error %d: malloc(%d) bytes for xattr value\n",
+                       rc, XATTR_SIZE_MAX);
+               goto out;
+       }
+
+       file = malloc(PATH_MAX);
+       if (file == NULL) {
+               rc = ENOMEM;
+               ERROR("Error %d: malloc(%d) bytes for file name\n",
+                       rc, PATH_MAX);
+               goto out;
+       }
+
+       (void) gettimeofday(&start, NULL);
+
+       for (i = 1; i <= files; i++) {
+               (void) sprintf(file, "%s/file-%d", path, i);
+
+               if (nth && ((i % nth) == 0))
+                       fprintf(stdout, "getxattr: %s\n", file);
+
+               for (j = 1; j <= xattrs; j++) {
+                       (void) sprintf(name, "user.%d", j);
+
+                       rc = lgetxattr(file, name, value, XATTR_SIZE_MAX);
+                       if (rc == -1) {
+                               ERROR("Error %d: lgetxattr(%s, %s, ..., %d)\n",
+                                   errno, file, name, XATTR_SIZE_MAX);
+                               goto out;
+                       }
+
+                       if (verify) {
+                               sscanf(value, "size=%d [a-z]", &rnd_size);
+                               shift = sprintf(verify_value, "size=%d ",
+                                   rnd_size);
+                               memset(verify_value + shift, 'x',
+                                   XATTR_SIZE_MAX - shift);
+
+                               if (rnd_size != rc ||
+                                   memcmp(verify_value, value, rnd_size)) {
+                                       ERROR("Error %d: verify failed\n "
+                                           "verify: %s\nvalue:  %s\n",
+                                           EINVAL, verify_value, value);
+                                       goto out;
+                               }
+                       }
+               }
+       }
+
+       (void) gettimeofday(&stop, NULL);
+       timeval_sub(&delta, &stop, &start);
+       fprintf(stdout, "getxattr: %d.%d seconds\n",
+           (int)delta.tv_sec, (int)delta.tv_usec);
+
+       rc = post_hook("post");
+out:
+       if (file)
+               free(file);
+
+       if (value)
+               free(value);
+
+       if (verify_value)
+               free(verify_value);
+
+       return (rc);
+}
+
+static int
+unlink_files(void)
+{
+       int i, rc;
+       char *file = NULL;
+       struct timeval start, stop, delta;
+
+       file = malloc(PATH_MAX);
+       if (file == NULL) {
+               rc = ENOMEM;
+               ERROR("Error %d: malloc(%d) bytes for file name\n",
+                   rc, PATH_MAX);
+               goto out;
+       }
+
+       (void) gettimeofday(&start, NULL);
+
+       for (i = 1; i <= files; i++) {
+               (void) sprintf(file, "%s/file-%d", path, i);
+
+               if (nth && ((i % nth) == 0))
+                       fprintf(stdout, "unlink: %s\n", file);
+
+               rc = unlink(file);
+               if ((rc == -1) && (errno != ENOENT)) {
+                       ERROR("Error %d: unlink(%s)\n", errno, file);
+                       return (errno);
+               }
+       }
+
+       (void) gettimeofday(&stop, NULL);
+       timeval_sub(&delta, &stop, &start);
+       fprintf(stdout, "unlink:   %d.%d seconds\n",
+           (int)delta.tv_sec, (int)delta.tv_usec);
+
+       rc = post_hook("post");
+out:
+       if (file)
+               free(file);
+
+       return (rc);
+}
+
+int
+main(int argc, char **argv)
+{
+       int rc;
+
+       rc = parse_args(argc, argv);
+       if (rc)
+               return (rc);
+
+       rc = create_files();
+       if (rc)
+               return (rc);
+
+       rc = setxattrs();
+       if (rc)
+               return (rc);
+
+       rc = getxattrs();
+       if (rc)
+               return (rc);
+
+       if (!keep_files) {
+               rc = unlink_files();
+               if (rc)
+                       return (rc);
+       }
+
+       return (0);
+}
diff --git a/tests/zfs-tests/include/.gitignore b/tests/zfs-tests/include/.gitignore
new file mode 100644 (file)
index 0000000..5de1b82
--- /dev/null
@@ -0,0 +1,2 @@
+/commands.cfg
+/default.cfg
diff --git a/tests/zfs-tests/include/Makefile.am b/tests/zfs-tests/include/Makefile.am
new file mode 100644 (file)
index 0000000..d9e6f47
--- /dev/null
@@ -0,0 +1,10 @@
+pkgdatadir = $(datadir)/@PACKAGE@/zfs-tests/include
+dist_pkgdata_SCRIPTS = \
+       commands.cfg \
+       default.cfg \
+       libtest.shlib \
+       math.shlib \
+       properties.shlib
+
+EXTRA_DIST = \
+       zfs_commands.cfg
diff --git a/tests/zfs-tests/include/commands.cfg.in b/tests/zfs-tests/include/commands.cfg.in
new file mode 100644 (file)
index 0000000..823ee96
--- /dev/null
@@ -0,0 +1,119 @@
+export AWK="@AWK@"
+export BLOCKDEV="@BLOCKDEV@"
+export BASENAME="@BASENAME@"
+export BC="@BC@"
+export BUNZIP2="@BUNZIP2@"
+export BZCAT="@BZCAT@"
+export CAT="@CAT@"
+export CD="@CD@"
+export CHACL="@CHACL@"
+export CHGRP="@CHGRP@"
+export CHMOD="@CHMOD@"
+export CHOWN="@CHOWN@"
+export CKSUM="@CKSUM@"
+export CMP="@CMP@"
+export COMPRESS="@COMPRESS@"
+export COREADM="@COREADM@"
+export CP="@CP@"
+export CPIO="@CPIO@"
+export CUT="@CUT@"
+export DATE="@DATE@"
+export DD="@DD@"
+export DF="@DF@"
+export DIFF="@DIFF@"
+export DIRCMP="@DIRCMP@"
+export DIRNAME="@DIRNAME@"
+export DU="@DU@"
+export DUMPADM="@DUMPADM@"
+export ECHO="@ECHO@"
+export EGREP="@EGREP@"
+export FDISK="@FDISK@"
+export FGREP="@FGREP@"
+export FILE="@FILE@"
+export FIND="@FIND@"
+export FORMAT="@FORMAT@"
+export FSCK="@FSCK@"
+export GETENT="@GETENT@"
+export GETFACL="@GETFACL@"
+export GETMAJOR="@GETMAJOR@"
+export GNUDD="@GNUDD@"
+export GREP="@GREP@"
+export GROUPADD="@GROUPADD@"
+export GROUPDEL="@GROUPDEL@"
+export GROUPMOD="@GROUPMOD@"
+export HEAD="@HEAD@"
+export HOSTNAME="@HOSTNAME@"
+export ID="@ID@"
+export ISAINFO="@ISAINFO@"
+export KILL="@KILL@"
+export KSH="@KSH@"
+export KSTAT="@KSTAT@"
+export LOCKFS="@LOCKFS@"
+export LOFIADM="@LOFIADM@"
+export LOGNAME="@LOGNAME@"
+export LS="@LS@"
+export MD5SUM="@MD5SUM@"
+export MKDIR="@MKDIR@"
+export MKNOD="@MKNOD@"
+export MKTEMP="@MKTEMP@"
+export MNTTAB="@MNTTAB@"
+export MODINFO="@MODINFO@"
+export MODUNLOAD="@MODUNLOAD@"
+export MOUNT="@MOUNT@"
+export MV="@MV@"
+export NAWK="@AWK@"
+export NEWFS="@NEWFS@"
+export NPROC="@NPROC@"
+export PAGESIZE="@PAGESIZE@"
+export PFEXEC="@PFEXEC@"
+export PGREP="@PGREP@"
+export PING="@PING@"
+export PKGINFO="@PKGINFO@"
+export PKILL="@PKILL@"
+export PRINTF="@PRINTF@"
+export PRTVTOC="@PRTVTOC@"
+export PS="@PS@"
+export PSRINFO="@PSRINFO@"
+export PYTHON="@PYTHON@"
+export REBOOT="@REBOOT@"
+export RM="@RM@"
+export RMDIR="@RMDIR@"
+export RSH="@RSH@"
+export SED="@SED@"
+export SETFACL="@SETFACL@"
+export SHARE="@SHARE@"
+export SHUF="@SHUF@"
+export SLEEP="@SLEEP@"
+export SORT="@SORT@"
+export STRINGS="@STRINGS@"
+export SU="@SU@"
+export SUM="@SUM@"
+export SVCADM="@SVCADM@"
+export SVCS="@SVCS@"
+export SWAP="@SWAP@"
+export SWAPADD="@SWAPADD@"
+export SYNC="@SYNC@"
+export TAIL="@TAIL@"
+export TAR="@TAR@"
+export TOUCH="@TOUCH@"
+export TR="@TR@"
+export TRUE="@TRUE@"
+export TRUNCATE="@TRUNCATE@"
+export UDEVADM="@UDEVADM@"
+export UFSDUMP="@UFSDUMP@"
+export UFSRESTORE="@UFSRESTORE@"
+export UMASK="@UMASK@"
+export UMOUNT="@UMOUNT@"
+export UMOUNTALL="@UMOUNTALL@"
+export UNAME="@UNAME@"
+export UNCOMPRESS="@UNCOMPRESS@"
+export UNIQ="@UNIQ@"
+export UNSHARE="@UNSHARE@"
+export USERADD="@USERADD@"
+export USERDEL="@USERDEL@"
+export USERMOD="@USERMOD@"
+export WAIT="@WAIT@"
+export WC="@WC@"
+export ZONEADM="@ZONEADM@"
+export ZONECFG="@ZONECFG@"
+export ZONENAME="@ZONENAME@"
diff --git a/tests/zfs-tests/include/default.cfg.in b/tests/zfs-tests/include/default.cfg.in
new file mode 100644 (file)
index 0000000..2711c70
--- /dev/null
@@ -0,0 +1,200 @@
+#
+# CDDL HEADER START
+#
+# The contents of this file are subject to the terms of the
+# Common Development and Distribution License (the "License").
+# You may not use this file except in compliance with the License.
+#
+# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
+# or http://www.opensolaris.org/os/licensing.
+# See the License for the specific language governing permissions
+# and limitations under the License.
+#
+# When distributing Covered Code, include this CDDL HEADER in each
+# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
+# If applicable, add the following below this CDDL 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) 2016 by Delphix. All rights reserved.
+#
+
+. $STF_SUITE/include/commands.cfg
+. $STF_SUITE/include/libtest.shlib
+
+# Optionally override the installed ZFS commands to run in-tree
+if [[ -f "$STF_SUITE/include/zfs_commands.cfg" ]]; then
+       . $STF_SUITE/include/zfs_commands.cfg
+fi
+
+# 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"
+
+# Common paths
+bindir=@bindir@
+sbindir=@sbindir@
+helperdir=@datarootdir@/@PACKAGE@/zfs-tests/bin
+
+# ZFS Commands
+ZDB=${ZDB:-${sbindir}/zdb}
+ZFS=${ZFS:-${sbindir}/zfs}
+ZHACK=${ZHACK:-${sbindir}/zhack}
+ZINJECT=${ZINJECT:-${sbindir}/zinject}
+ZPOOL=${ZPOOL:-${sbindir}/zpool}
+ZTEST=${ZTEST:-${sbindir}/ztest}
+ZPIOS=${ZPIOS:-${sbindir}/zpios}
+
+# Test Suite Specific Commands
+export CHG_USR_EXEC=${CHG_USR_EXEC:-${helperdir}/chg_usr_exec}
+export DEVNAME2DEVID=${DEVNAME2DEVID:-${helperdir}/devname2devid}
+export DIR_RD_UPDATE=${DIR_RD_UPDATE:-${helperdir}/dir_rd_update}
+export FILE_CHECK=${FILE_CHECK:-${helperdir}/file_check}
+export FILE_TRUNC=${FILE_TRUNC:-${helperdir}/file_trunc}
+export FILE_WRITE=${FILE_WRITE:-${helperdir}/file_write}
+export LARGEST_FILE=${LARGEST_FILE:-${helperdir}/largest_file}
+export MKBUSY=${MKBUSY:-${helperdir}/mkbusy}
+export MKFILE=${MKFILE:-${helperdir}/mkfile}
+export MKFILES=${MKFILES:-${helperdir}/mkfiles}
+export MKTREE=${MKTREE:-${helperdir}/mktree}
+export MMAP_EXEC=${MMAP_EXEC:-${helperdir}/mmap_exec}
+export MMAPWRITE=${MMAPWRITE:-${helperdir}/mmapwrite}
+export RANDFREE_FILE=${RANDFREE_FILE:-${helperdir}/randfree_file}
+export READMMAP=${READMMAP:-${helperdir}/readmmap}
+export RENAME_DIR=${RENAME_DIR:-${helperdir}/rename_dir}
+export RM_LNKCNT_ZERO_FILE=${RM_LNKCNT_ZERO_FILE:-${helperdir}/rm_lnkcnt_zero_file}
+export THREADSAPPEND=${THREADSAPPEND:-${helperdir}/threadsappend}
+export XATTRTEST=${XATTRTEST:-${helpdir}/xattrtest}
+
+# 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="/var/tmp"
+
+# 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
+
+#
+# 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
+
+if is_linux; then
+       unpack_opts="--sparse -xf"
+       pack_opts="--sparse -cf"
+       verbose=" -v"
+       unpack_preserve=" -xpf"
+       pack_preserve=" -cpf"
+
+       ZVOL_DEVDIR="/dev/zvol"
+       ZVOL_RDEVDIR="/dev/zvol"
+       DEV_DSKDIR="/dev"
+       DEV_RDSKDIR="/dev"
+
+       NEWFS_DEFAULT_FS="ext2"
+else
+       unpack_opts="xv"
+       pack_opts="cf"
+       verbose="v"
+       unpack_preserve="xpf"
+       pack_preserve="cpf"
+
+       ZVOL_DEVDIR="/dev/zvol/dsk"
+       ZVOL_RDEVDIR="/dev/zvol/rdsk"
+       DEV_DSKDIR="/dev/dsk"
+       DEV_RDSKDIR="/dev/rdsk"
+
+       NEWFS_DEFAULT_FS="ufs"
+fi
+export unpack_opts pack_opts verbose unpack_preserve pack_preserve \
+       ZVOL_DEVDIR ZVOL_RDEVDIR NEWFS_DEFAULT_FS DEV_DSKDIR DEV_RDSKDIR
diff --git a/tests/zfs-tests/include/libtest.shlib b/tests/zfs-tests/include/libtest.shlib
new file mode 100644 (file)
index 0000000..10ef5a9
--- /dev/null
@@ -0,0 +1,2648 @@
+#!/bin/ksh -p
+#
+# CDDL HEADER START
+#
+# The contents of this file are subject to the terms of the
+# Common Development and Distribution License (the "License").
+# You may not use this file except in compliance with the License.
+#
+# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
+# or http://www.opensolaris.org/os/licensing.
+# See the License for the specific language governing permissions
+# and limitations under the License.
+#
+# When distributing Covered Code, include this CDDL HEADER in each
+# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
+# If applicable, add the following below this CDDL 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, 2015 by Delphix. All rights reserved.
+#
+
+. ${STF_TOOLS}/include/logapi.shlib
+
+ZDB=${ZDB:-/sbin/zdb}
+ZFS=${ZFS:-/sbin/zfs}
+ZINJECT=${ZINJECT:-/sbin/zinject}
+ZHACK=${ZHACK:-/sbin/zhack}
+ZPOOL=${ZPOOL:-/sbin/zpool}
+ZTEST=${ZTEST:-/sbin/ztest}
+
+# Determine if this is a Linux test system
+#
+# Return 0 if platform Linux, 1 if otherwise
+
+function is_linux
+{
+       if [[ $($UNAME -o) == "GNU/Linux" ]]; then
+               return 0
+       else
+               return 1
+       fi
+}
+
+# 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
+               ;;
+               ext2)
+                       out=$($DF -t $fstype $1 2>/dev/null)
+                       return $?
+               ;;
+               zvol)
+                       if [[ -L "$ZVOL_DEVDIR/$1" ]]; then
+                               link=$(readlink -f $ZVOL_DEVDIR/$1)
+                               [[ -n "$link" ]] && \
+                                       $MOUNT | $GREP -q "^$link" && \
+                                               return 0
+                       fi
+               ;;
+       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
+                       block_device_wait
+               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
+               [[ -z "$KEEP" ]] && KEEP="rpool"
+               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
+
+       if is_linux; then
+               log_must $FORMAT $DEV_DSKDIR/$diskname -s -- mklabel gpt
+       else
+               for i in 0 1 3 4 5 6 7
+               do
+                       set_partition $i "" 0mb $diskname
+               done
+       fi
+}
+
+#
+# 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
+#
+# NOTE: This entire interface is problematic for the Linux parted utilty
+# which requires the end of the partition to be specified.  It would be
+# best to retire this interface and replace it with something more flexible.
+# At the moment a best effort is made.
+#
+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."
+
+       if is_linux; then
+               typeset size_mb=${size%%[mMgG]}
+
+               size_mb=${size_mb%%[mMgG][bB]}
+               if [[ ${size:1:1} == 'g' ]]; then
+                       ((size_mb = size_mb * 1024))
+               fi
+
+               # Create GPT partition table when setting slice 0 or
+               # when the device doesn't already contain a GPT label.
+               $FORMAT $DEV_DSKDIR/$disk -s -- print 1 >/dev/null
+               typeset ret_val=$?
+               if [[ $slicenum -eq 0 || $ret_val -ne 0 ]]; then
+                       log_must $FORMAT $DEV_DSKDIR/$disk -s -- mklabel gpt
+               fi
+
+               # When no start is given align on the first cylinder.
+               if [[ -z "$start" ]]; then
+                       start=1
+               fi
+
+               # Determine the cylinder size for the device and using
+               # that calculate the end offset in cylinders.
+               typeset -i cly_size_kb=0
+               cly_size_kb=$($FORMAT -m $DEV_DSKDIR/$disk -s -- \
+                       unit cyl print | $HEAD -3 | $TAIL -1 | \
+                       $AWK -F '[:k.]' '{print $4}')
+               ((end = (size_mb * 1024 / cly_size_kb) + start))
+
+               log_must $FORMAT $DEV_DSKDIR/$disk -s -- \
+                   mkpart part$slicenum ${start}cyl ${end}cyl
+
+               $BLOCKDEV --rereadpt $DEV_DSKDIR/$disk 2>/dev/null
+               block_device_wait
+       else
+               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
+       fi
+       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
+
+       if is_linux; then
+               endcyl=$($FORMAT -s $DEV_DSKDIR/$disk -- unit cyl print | \
+                       $GREP "part${slice}" | \
+                       $AWK '{print $3}' | \
+                       $SED 's,cyl,,')
+               ((endcyl = (endcyl + 1)))
+       else
+               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))
+       fi
+
+       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 ! is_linux; then
+                       if ((i == 2)); then
+                               ((i = i + 1))
+                               continue
+                       fi
+               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 is_linux; then
+               log_unsupported "Currently unsupported by the test framework"
+               return 1
+       fi
+
+       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
+
+       if is_linux; then
+               log_unsupported "Currently unsupported by the test framework"
+               return 1
+       fi
+
+       is_shared $fs
+       if (($? == 0)); then
+               return 1
+       fi
+
+       return 0
+}
+
+#
+# Helper function to unshare a mountpoint.
+#
+function unshare_fs #fs
+{
+       typeset fs=$1
+
+       if is_linux; then
+               log_unsupported "Currently unsupported by the test framework"
+               return 1
+       fi
+
+       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
+
+       if is_linux; then
+               log_unsupported "Currently unsupported by the test framework"
+               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")
+
+                       # At times, syseventd activity can cause attempts to
+                       # destroy a pool to fail with EBUSY. We retry a few
+                       # times allowing failures before requiring the destroy
+                       # to succeed.
+                       typeset -i wait_time=10 ret=1 count=0
+                       must=""
+                       while [[ $ret -ne 0 ]]; do
+                               $must $ZPOOL destroy -f $pool
+                               ret=$?
+                               [[ $ret -eq 0 ]] && break
+                               log_note "zpool destroy failed with $ret"
+                               [[ count++ -ge 7 ]] && must=log_must
+                               $SLEEP $wait_time
+                       done
+
+                       [[ -d $mtpt ]] && \
+                               log_must $RM -rf $mtpt
+               else
+                       log_note "Pool does 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
+       block_device_wait
+
+       #
+       # 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=$ZVOL_DEVDIR/$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=$ZVOL_RDEVDIR/$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_DSKDIR/}
+       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
+}
+
+# /**
+#  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_DSKDIR/}
+       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_DSKDIR/}
+       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_DSKDIR/}
+       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 /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 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
+{
+       # Trust provided list, no attempt is made to locate unused devices.
+       if is_linux; then
+               $ECHO "$@"
+               return
+       fi
+
+
+       sfi=/tmp/swaplist.$$
+       dmpi=/tmp/dumpdev.$$
+       max_finddisksnum=${MAX_FINDDISKSNUM:-6}
+
+       $SWAP -l > $sfi
+       $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 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 $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_DSKDIR/${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, a larger value is selected for
+       # Linux because for many distributions 1000 and under are reserved.
+       if is_linux; then
+               typeset -i gid=1500
+
+               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
+                               9) ((gid += 1)) ;;
+                               *) return 1 ;;
+                       esac
+               done
+       else
+               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
+       fi
+}
+
+#
+# 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
+
+       if is_linux; then
+               $GETENT group $grp > /dev/null 2>&1
+               typeset -i ret=$?
+               case $ret in
+                       # Group does not exist.
+                       2) return 0 ;;
+                       # Name already exists as a group name
+                       0) log_must $GROUPDEL $grp ;;
+                       *) return 1 ;;
+               esac
+       else
+               $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
+       fi
+
+       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 "$ZVOL_DEVDIR/$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 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
+       block_device_wait
+
+       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_DSKDIR/}
+       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 is_linux; then
+               log_note "Currently unsupported by the test framework"
+               return 1
+       fi
+
+       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_DSKDIR}
+       device=${device#$DEV_RDSKDIR}
+
+       if is_linux; then
+               [[ -b "$DEV_DSKDIR/$device" ]] && \
+               [[ -f /sys/module/loop/parameters/max_part ]]
+               return $?
+       else
+               $ECHO $device | $EGREP "^c[0-F]+([td][0-F]+)+$" > /dev/null 2>&1
+               return $?
+       fi
+}
+
+#
+# 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
+               if [[ -b "$DEV_DSKDIR/$device" ]]; then
+                       device="$DEV_DSKDIR"
+               fi
+               $ECHO $device
+       else
+               $ECHO "$DEV_DSKDIR"
+       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
+}
+
+# Utility function to determine if a system has multiple cpus.
+function is_mp
+{
+       if is_linux; then
+               (($($NPROC) > 1))
+       else
+               (($($PSRINFO | $WC -l) > 1))
+       fi
+
+       return $?
+}
+
+function get_cpu_freq
+{
+       if is_linux; then
+               lscpu | $AWK '/CPU MHz/ { print $3 }'
+       else
+               $PSRINFO -v 0 | $AWK '/processor operates at/ {print $6}'
+       fi
+}
+
+# Run the given command as the user provided.
+function user_run
+{
+       typeset user=$1
+       shift
+
+       eval \$SU \$user -c \"$@\" > /tmp/out 2>/tmp/err
+       return $?
+}
+
+#
+# Check if the pool contains the specified vdevs
+#
+# $1 pool
+# $2..n <vdev> ...
+#
+# Return 0 if the vdevs are contained in the pool, 1 if any of the specified
+# vdevs is not in the pool, and 2 if pool name is missing.
+#
+function vdevs_in_pool
+{
+       typeset pool=$1
+       typeset vdev
+
+       if [[ -z $pool ]]; then
+               log_note "Missing pool name."
+               return 2
+       fi
+
+       shift
+
+       typeset tmpfile=$($MKTEMP)
+       $ZPOOL list -Hv "$pool" >$tmpfile
+       for vdev in $@; do
+               $GREP -w ${vdev##*/} $tmpfile >/dev/null 2>&1
+               [[ $? -ne 0 ]] && return 1
+       done
+
+       $RM -f $tmpfile
+
+       return 0;
+}
+
+#
+# Wait for newly created block devices to have their minors created.
+#
+function block_device_wait
+{
+       if is_linux; then
+               $UDEVADM trigger
+               $UDEVADM settle
+       fi
+}
diff --git a/tests/zfs-tests/include/math.shlib b/tests/zfs-tests/include/math.shlib
new file mode 100644 (file)
index 0000000..38479d3
--- /dev/null
@@ -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
+}
diff --git a/tests/zfs-tests/include/properties.shlib b/tests/zfs-tests/include/properties.shlib
new file mode 100644 (file)
index 0000000..bb0b4ff
--- /dev/null
@@ -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
+}
diff --git a/tests/zfs-tests/include/zfs_commands.cfg b/tests/zfs-tests/include/zfs_commands.cfg
new file mode 120000 (symlink)
index 0000000..222b038
--- /dev/null
@@ -0,0 +1 @@
+../../../zfs-script-config.sh
\ No newline at end of file
diff --git a/tests/zfs-tests/tests/Makefile.am b/tests/zfs-tests/tests/Makefile.am
new file mode 100644 (file)
index 0000000..e1a1c6b
--- /dev/null
@@ -0,0 +1 @@
+SUBDIRS = functional stress
diff --git a/tests/zfs-tests/tests/functional/Makefile.am b/tests/zfs-tests/tests/functional/Makefile.am
new file mode 100644 (file)
index 0000000..aff3d28
--- /dev/null
@@ -0,0 +1,55 @@
+SUBDIRS = \
+       acl \
+       atime \
+       bootfs \
+       cache \
+       cachefile \
+       casenorm \
+       clean_mirror \
+       cli_root \
+       cli_user \
+       compression \
+       ctime \
+       delegate \
+       devices \
+       exec \
+       features \
+       grow_pool \
+       grow_replicas \
+       history \
+       inheritance \
+       inuse \
+       large_files \
+       largest_pool \
+       link_count \
+       migration \
+       mmap \
+       mount \
+       mv_files \
+       nestedfs \
+       no_space \
+       nopwrite \
+       online_offline \
+       pool_names \
+       poolversion \
+       privilege \
+       quota \
+       redundancy \
+       refquota \
+       refreserv \
+       rename_dirs \
+       replacement \
+       reservation \
+       rootpool \
+       rsend \
+       scrub_mirror \
+       slog \
+       snapshot \
+       snapused \
+       sparse \
+       threadsappend \
+       truncate \
+       userquota \
+       write_dirs \
+       xattr \
+       zvol
diff --git a/tests/zfs-tests/tests/functional/acl/Makefile.am b/tests/zfs-tests/tests/functional/acl/Makefile.am
new file mode 100644 (file)
index 0000000..6a02583
--- /dev/null
@@ -0,0 +1,6 @@
+pkgdatadir = $(datadir)/@PACKAGE@/zfs-tests/tests/functional/acl
+dist_pkgdata_SCRIPTS = \
+       acl.cfg \
+       acl_common.kshlib
+
+SUBDIRS = posix
diff --git a/tests/zfs-tests/tests/functional/acl/acl.cfg b/tests/zfs-tests/tests/functional/acl/acl.cfg
new file mode 100644 (file)
index 0000000..fbebe38
--- /dev/null
@@ -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 'zfstest'
+export ZFS_ACL_ADMIN=zfstest
+
+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
diff --git a/tests/zfs-tests/tests/functional/acl/acl_common.kshlib b/tests/zfs-tests/tests/functional/acl/acl_common.kshlib
new file mode 100644 (file)
index 0000000..1ebc1cd
--- /dev/null
@@ -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
+}
diff --git a/tests/zfs-tests/tests/functional/acl/posix/Makefile.am b/tests/zfs-tests/tests/functional/acl/posix/Makefile.am
new file mode 100644 (file)
index 0000000..475cdca
--- /dev/null
@@ -0,0 +1,6 @@
+pkgdatadir = $(datadir)/@PACKAGE@/zfs-tests/tests/functional/acl/posix
+dist_pkgdata_SCRIPTS = \
+       cleanup.ksh \
+       setup.ksh \
+       posix_001_pos.ksh \
+       posix_002_pos.ksh
diff --git a/tests/zfs-tests/tests/functional/acl/posix/cleanup.ksh b/tests/zfs-tests/tests/functional/acl/posix/cleanup.ksh
new file mode 100755 (executable)
index 0000000..bb58a8c
--- /dev/null
@@ -0,0 +1,33 @@
+#!/bin/ksh -p
+#
+# CDDL HEADER START
+#
+# The contents of this file are subject to the terms of the
+# Common Development and Distribution License (the "License").
+# You may not use this file except in compliance with the License.
+#
+# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
+# or http://www.opensolaris.org/os/licensing.
+# See the License for the specific language governing permissions
+# and limitations under the License.
+#
+# When distributing Covered Code, include this CDDL HEADER in each
+# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
+# If applicable, add the following below this CDDL HEADER, with the
+# fields enclosed by brackets "[]" replaced with your own identifying
+# information: 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
+
+default_cleanup
diff --git a/tests/zfs-tests/tests/functional/acl/posix/posix_001_pos.ksh b/tests/zfs-tests/tests/functional/acl/posix/posix_001_pos.ksh
new file mode 100755 (executable)
index 0000000..25c250f
--- /dev/null
@@ -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 2008 Sun Microsystems, Inc.  All rights reserved.
+# Use is subject to license terms.
+#
+
+. $STF_SUITE/include/libtest.shlib
+
+#
+# Copyright (c) 2012 by Delphix. All rights reserved.
+#
+
+#
+# DESCRIPTION:
+#      Verify that user can access file/directory if acltype=posixacl.
+#
+# STRATEGY:
+#      1. Test access to file (mode=rw-)
+#         a. Can modify file
+#         b. Can't create new file
+#         b. Can't execute file
+#
+
+verify_runnable "both"
+log_assert "Verify acltype=posixacl works on file"
+
+# Test access to FILE
+log_note "Testing access to FILE"
+log_must $TOUCH $TESTDIR/file.0
+log_must $SETFACL -m g:zfsgrp:rw $TESTDIR/file.0
+$GETFACL $TESTDIR/file.0 2> /dev/null | $EGREP -q "^group:zfsgrp:rw-$"
+if [ "$?" -eq "0" ]; then
+       # Should be able to write to file
+       log_must $SU staff1 -c "$ECHO \"$ECHO test > /dev/null\" > $TESTDIR/file.0"
+
+       # Should NOT be able to create new file
+       log_mustnot $SU staff1 -c "$TOUCH $TESTDIR/file.1"
+
+       # Root should be able to run file, but not user
+       chmod +x $TESTDIR/file.0
+       log_must $TESTDIR/file.0
+       log_mustnot $SU staff1 -c $TESTDIR/file.0
+
+       log_pass "POSIX ACL mode works on files"
+else
+       log_fail "Group 'zfsgrp' does not have 'rw' as specified"
+fi
diff --git a/tests/zfs-tests/tests/functional/acl/posix/posix_002_pos.ksh b/tests/zfs-tests/tests/functional/acl/posix/posix_002_pos.ksh
new file mode 100755 (executable)
index 0000000..fcd0114
--- /dev/null
@@ -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 2008 Sun Microsystems, Inc.  All rights reserved.
+# Use is subject to license terms.
+#
+
+. $STF_SUITE/include/libtest.shlib
+
+#
+# Copyright (c) 2012 by Delphix. All rights reserved.
+#
+
+#
+# DESCRIPTION:
+#      Verify that user can access file/directory if acltype=posixacl.
+#
+# STRATEGY:
+#      1. Test access to directory (mode=-wx)
+#         a. Can create file in dir
+#         b. Can't list directory
+#
+
+verify_runnable "both"
+log_assert "Verify acltype=posixacl works on directory"
+
+# Test access to DIRECTORY
+log_note "Testing access to DIRECTORY"
+log_must $MKDIR $TESTDIR/dir.0
+log_must $SETFACL -m g:zfsgrp:wx $TESTDIR/dir.0
+$GETFACL $TESTDIR/dir.0 2> /dev/null | $EGREP -q "^group:zfsgrp:-wx$"
+if [ "$?" -eq "0" ]; then
+       # Should be able to create file in directory
+       log_must $SU staff1 -c "$TOUCH $TESTDIR/dir.0/file.0"
+
+       # Should NOT be able to list files in directory
+       log_mustnot $SU staff1 -c "$LS -l $TESTDIR/dir.0"
+
+       log_pass "POSIX ACL mode works on directories"
+else
+       log_fail "Group 'zfsgrp' does not have 'rwx' as specified"
+fi
diff --git a/tests/zfs-tests/tests/functional/acl/posix/setup.ksh b/tests/zfs-tests/tests/functional/acl/posix/setup.ksh
new file mode 100755 (executable)
index 0000000..dc17f7c
--- /dev/null
@@ -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
+. $STF_SUITE/tests/functional/acl/acl_common.kshlib
+
+log_must $GETFACL --version
+log_must $SETFACL --version
+
+cleanup_user_group
+
+# Create staff group and add user to it
+log_must add_group $ZFS_ACL_STAFF_GROUP
+log_must add_user $ZFS_ACL_STAFF_GROUP $ZFS_ACL_STAFF1
+
+DISK=${DISKS%% *}
+default_setup_noexit $DISK
+log_must $CHMOD 777 $TESTDIR
+
+# Use POSIX ACLs on filesystem
+log_must $ZFS set acltype=posixacl $TESTPOOL/$TESTFS
+log_must $ZFS set xattr=sa $TESTPOOL/$TESTFS
+
+log_pass
diff --git a/tests/zfs-tests/tests/functional/atime/Makefile.am b/tests/zfs-tests/tests/functional/atime/Makefile.am
new file mode 100644 (file)
index 0000000..ff268e3
--- /dev/null
@@ -0,0 +1,8 @@
+pkgdatadir = $(datadir)/@PACKAGE@/zfs-tests/tests/functional/atime
+dist_pkgdata_SCRIPTS = \
+       atime.cfg \
+       atime_common.kshlib \
+       cleanup.ksh \
+       setup.ksh \
+       atime_001_pos.ksh \
+       atime_002_neg.ksh
diff --git a/tests/zfs-tests/tests/functional/atime/atime.cfg b/tests/zfs-tests/tests/functional/atime/atime.cfg
new file mode 100644 (file)
index 0000000..c1532eb
--- /dev/null
@@ -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
diff --git a/tests/zfs-tests/tests/functional/atime/atime_001_pos.ksh b/tests/zfs-tests/tests/functional/atime/atime_001_pos.ksh
new file mode 100755 (executable)
index 0000000..891e221
--- /dev/null
@@ -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."
diff --git a/tests/zfs-tests/tests/functional/atime/atime_002_neg.ksh b/tests/zfs-tests/tests/functional/atime/atime_002_neg.ksh
new file mode 100755 (executable)
index 0000000..06a35cc
--- /dev/null
@@ -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."
diff --git a/tests/zfs-tests/tests/functional/atime/atime_common.kshlib b/tests/zfs-tests/tests/functional/atime/atime_common.kshlib
new file mode 100644 (file)
index 0000000..c2f90eb
--- /dev/null
@@ -0,0 +1,78 @@
+#
+# CDDL HEADER START
+#
+# The contents of this file are subject to the terms of the
+# Common Development and Distribution License (the "License").
+# You may not use this file except in compliance with the License.
+#
+# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
+# or http://www.opensolaris.org/os/licensing.
+# See the License for the specific language governing permissions
+# and limitations under the License.
+#
+# When distributing Covered Code, include this CDDL HEADER in each
+# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
+# If applicable, add the following below this CDDL HEADER, with the
+# fields enclosed by brackets "[]" replaced with your own identifying
+# information: Portions Copyright [yyyy] [name of copyright owner]
+#
+# CDDL HEADER END
+#
+
+#
+# Copyright 2007 Sun Microsystems, Inc.  All rights reserved.
+# Use is subject to license terms.
+#
+
+. $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
+
+       if is_linux; then
+               typeset before=$(stat -c %X $filename)
+               sleep 2
+       else
+               typeset before=$($LS -Eu $filename | $AWK '{print $7}')
+       fi
+
+       log_must $CAT $filename
+
+       if is_linux; then
+               typeset after=$(stat -c %X $filename)
+       else
+               typeset after=$($LS -Eu $filename | $AWK '{print $7}')
+       fi
+
+       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
+}
diff --git a/tests/zfs-tests/tests/functional/atime/cleanup.ksh b/tests/zfs-tests/tests/functional/atime/cleanup.ksh
new file mode 100755 (executable)
index 0000000..79cd6e9
--- /dev/null
@@ -0,0 +1,30 @@
+#!/bin/ksh -p
+#
+# CDDL HEADER START
+#
+# The contents of this file are subject to the terms of the
+# Common Development and Distribution License (the "License").
+# You may not use this file except in compliance with the License.
+#
+# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
+# or http://www.opensolaris.org/os/licensing.
+# See the License for the specific language governing permissions
+# and limitations under the License.
+#
+# When distributing Covered Code, include this CDDL HEADER in each
+# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
+# If applicable, add the following below this CDDL HEADER, with the
+# fields enclosed by brackets "[]" replaced with your own identifying
+# information: 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
diff --git a/tests/zfs-tests/tests/functional/atime/setup.ksh b/tests/zfs-tests/tests/functional/atime/setup.ksh
new file mode 100755 (executable)
index 0000000..0c5d38f
--- /dev/null
@@ -0,0 +1,31 @@
+#!/bin/ksh -p
+#
+# CDDL HEADER START
+#
+# The contents of this file are subject to the terms of the
+# Common Development and Distribution License (the "License").
+# You may not use this file except in compliance with the License.
+#
+# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
+# or http://www.opensolaris.org/os/licensing.
+# See the License for the specific language governing permissions
+# and limitations under the License.
+#
+# When distributing Covered Code, include this CDDL HEADER in each
+# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
+# If applicable, add the following below this CDDL HEADER, with the
+# fields enclosed by brackets "[]" replaced with your own identifying
+# information: 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
diff --git a/tests/zfs-tests/tests/functional/bootfs/Makefile.am b/tests/zfs-tests/tests/functional/bootfs/Makefile.am
new file mode 100644 (file)
index 0000000..901c039
--- /dev/null
@@ -0,0 +1,12 @@
+pkgdatadir = $(datadir)/@PACKAGE@/zfs-tests/tests/functional/bootfs
+dist_pkgdata_SCRIPTS = \
+       cleanup.ksh \
+       setup.ksh \
+       bootfs_001_pos.ksh \
+       bootfs_002_neg.ksh \
+       bootfs_003_pos.ksh \
+       bootfs_004_neg.ksh \
+       bootfs_005_neg.ksh \
+       bootfs_006_pos.ksh \
+       bootfs_007_neg.ksh \
+       bootfs_008_neg.ksh
diff --git a/tests/zfs-tests/tests/functional/bootfs/bootfs_001_pos.ksh b/tests/zfs-tests/tests/functional/bootfs/bootfs_001_pos.ksh
new file mode 100755 (executable)
index 0000000..ad416a5
--- /dev/null
@@ -0,0 +1,78 @@
+#!/bin/ksh -p
+#
+# CDDL HEADER START
+#
+# The contents of this file are subject to the terms of the
+# Common Development and Distribution License (the "License").
+# You may not use this file except in compliance with the License.
+#
+# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
+# or http://www.opensolaris.org/os/licensing.
+# See the License for the specific language governing permissions
+# and limitations under the License.
+#
+# When distributing Covered Code, include this CDDL HEADER in each
+# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
+# If applicable, add the following below this CDDL HEADER, with the
+# fields enclosed by brackets "[]" replaced with your own identifying
+# information: Portions Copyright [yyyy] [name of copyright owner]
+#
+# CDDL HEADER END
+#
+
+#
+# Copyright 2009 Sun Microsystems, Inc.  All rights reserved.
+# Use is subject to license terms.
+#
+# Copyright 2015 Nexenta Systems, Inc.
+#
+
+. $STF_SUITE/include/libtest.shlib
+
+#
+# DESCRIPTION:
+#
+# Valid datasets and snapshots are accepted as bootfs property values
+#
+# STRATEGY:
+# 1. Create a set of datasets and snapshots 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=$TESTDIR/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/$TESTFS@snap $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"
diff --git a/tests/zfs-tests/tests/functional/bootfs/bootfs_002_neg.ksh b/tests/zfs-tests/tests/functional/bootfs/bootfs_002_neg.ksh
new file mode 100755 (executable)
index 0000000..cd61b92
--- /dev/null
@@ -0,0 +1,78 @@
+#!/bin/ksh -p
+#
+# CDDL HEADER START
+#
+# The contents of this file are subject to the terms of the
+# Common Development and Distribution License (the "License").
+# You may not use this file except in compliance with the License.
+#
+# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
+# or http://www.opensolaris.org/os/licensing.
+# See the License for the specific language governing permissions
+# and limitations under the License.
+#
+# When distributing Covered Code, include this CDDL HEADER in each
+# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
+# If applicable, add the following below this CDDL HEADER, with the
+# fields enclosed by brackets "[]" replaced with your own identifying
+# information: Portions Copyright [yyyy] [name of copyright owner]
+#
+# CDDL HEADER END
+#
+
+#
+# Copyright 2009 Sun Microsystems, Inc.  All rights reserved.
+# Use is subject to license terms.
+#
+# Copyright 2015 Nexenta Systems, Inc.
+#
+
+. $STF_SUITE/include/libtest.shlib
+
+#
+# DESCRIPTION:
+#
+# Invalid datasets are rejected as boot property values
+#
+# STRATEGY:
+#
+# 1. Create a zvol 
+# 2. Verify that we can't set the bootfs to that dataset
+#
+
+verify_runnable "global"
+
+function cleanup {
+       if datasetexists $TESTPOOL/vol
+       then
+               log_must $ZFS destroy $TESTPOOL/vol
+       fi
+       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 "Invalid datasets are rejected as boot property values"
+log_onexit cleanup
+
+typeset VDEV=$TESTDIR/bootfs_002_neg_a.$$.dat
+
+log_must $MKFILE 400m $VDEV
+create_pool "$TESTPOOL" "$VDEV"
+log_must $ZFS create -V 10m $TESTPOOL/vol
+block_device_wait
+
+log_mustnot $ZPOOL set bootfs=$TESTPOOL/vol $TESTPOOL
+
+log_pass "Invalid datasets are rejected as boot property values"
diff --git a/tests/zfs-tests/tests/functional/bootfs/bootfs_003_pos.ksh b/tests/zfs-tests/tests/functional/bootfs/bootfs_003_pos.ksh
new file mode 100755 (executable)
index 0000000..f3cf1c9
--- /dev/null
@@ -0,0 +1,82 @@
+#!/bin/ksh -p
+#
+# CDDL HEADER START
+#
+# The contents of this file are subject to the terms of the
+# Common Development and Distribution License (the "License").
+# You may not use this file except in compliance with the License.
+#
+# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
+# or http://www.opensolaris.org/os/licensing.
+# See the License for the specific language governing permissions
+# and limitations under the License.
+#
+# When distributing Covered Code, include this CDDL HEADER in each
+# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
+# If applicable, add the following below this CDDL HEADER, with the
+# fields enclosed by brackets "[]" replaced with your own identifying
+# information: Portions Copyright [yyyy] [name of copyright owner]
+#
+# CDDL HEADER END
+#
+
+#
+# Copyright 2008 Sun Microsystems, Inc.  All rights reserved.
+# Use is subject to license terms.
+#
+
+. $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 $TESTDIR/bootfs_003.$$.dat
+
+typeset -i i=0;
+
+while [ $i -lt "${#pools[@]}" ]
+do
+       POOL=${pools[$i]}
+       log_must $ZPOOL create $POOL $TESTDIR/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"
diff --git a/tests/zfs-tests/tests/functional/bootfs/bootfs_004_neg.ksh b/tests/zfs-tests/tests/functional/bootfs/bootfs_004_neg.ksh
new file mode 100755 (executable)
index 0000000..62bbb3d
--- /dev/null
@@ -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:
+#
+# 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 $TESTDIR/bootfs_004.$$.dat
+
+typeset -i i=0;
+
+while [ $i -lt "${#pools[@]}" ]
+do
+       POOL=${pools[$i]}/$TESTFS
+       log_mustnot $ZPOOL create $POOL $TESTDIR/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"
diff --git a/tests/zfs-tests/tests/functional/bootfs/bootfs_005_neg.ksh b/tests/zfs-tests/tests/functional/bootfs/bootfs_005_neg.ksh
new file mode 100755 (executable)
index 0000000..3928cdd
--- /dev/null
@@ -0,0 +1,79 @@
+#!/bin/ksh -p
+#
+# CDDL HEADER START
+#
+# The contents of this file are subject to the terms of the
+# Common Development and Distribution License (the "License").
+# You may not use this file except in compliance with the License.
+#
+# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
+# or http://www.opensolaris.org/os/licensing.
+# See the License for the specific language governing permissions
+# and limitations under the License.
+#
+# When distributing Covered Code, include this CDDL HEADER in each
+# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
+# If applicable, add the following below this CDDL HEADER, with the
+# fields enclosed by brackets "[]" replaced with your own identifying
+# information: Portions Copyright [yyyy] [name of copyright owner]
+#
+# CDDL HEADER END
+#
+
+#
+# Copyright 2008 Sun Microsystems, Inc.  All rights reserved.
+# Use is subject to license terms.
+#
+
+. $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"
diff --git a/tests/zfs-tests/tests/functional/bootfs/bootfs_006_pos.ksh b/tests/zfs-tests/tests/functional/bootfs/bootfs_006_pos.ksh
new file mode 100755 (executable)
index 0000000..fc3ca14
--- /dev/null
@@ -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 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=$TESTDIR/bootfs_006_pos_a.$$.dat
+VDEV2=$TESTDIR/bootfs_006_pos_b.$$.dat
+VDEV3=$TESTDIR/bootfs_006_pos_c.$$.dat
+VDEV4=$TESTDIR/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"
diff --git a/tests/zfs-tests/tests/functional/bootfs/bootfs_007_neg.ksh b/tests/zfs-tests/tests/functional/bootfs/bootfs_007_neg.ksh
new file mode 100755 (executable)
index 0000000..6f6bb40
--- /dev/null
@@ -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
+
+#
+# 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
+
+if is_linux; then
+       log_must $ZPOOL set bootfs=$EFI_BOOTFS $TESTPOOL
+else
+       log_mustnot $ZPOOL set bootfs=$EFI_BOOTFS $TESTPOOL
+fi
+
+log_pass $assert_mesg
diff --git a/tests/zfs-tests/tests/functional/bootfs/bootfs_007_pos.ksh b/tests/zfs-tests/tests/functional/bootfs/bootfs_007_pos.ksh
new file mode 100644 (file)
index 0000000..56235f3
--- /dev/null
@@ -0,0 +1,65 @@
+#!/bin/ksh -p
+#
+# CDDL HEADER START
+#
+# The contents of this file are subject to the terms of the
+# Common Development and Distribution License (the "License").
+# You may not use this file except in compliance with the License.
+#
+# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
+# or http://www.opensolaris.org/os/licensing.
+# See the License for the specific language governing permissions
+# and limitations under the License.
+#
+# When distributing Covered Code, include this CDDL HEADER in each
+# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
+# If applicable, add the following below this CDDL HEADER, with the
+# fields enclosed by brackets "[]" replaced with your own identifying
+# information: Portions Copyright [yyyy] [name of copyright owner]
+#
+# CDDL HEADER END
+#
+
+#
+# Copyright 2009 Sun Microsystems, Inc.  All rights reserved.
+# Use is subject to license terms.
+#
+# Copyright 2015 Nexenta Systems, Inc.
+#
+
+. $STF_SUITE/include/libtest.shlib
+
+#
+# DESCRIPTION:
+#
+# Setting bootfs on a pool which was configured with the whole disk
+# (i.e. EFI) works.
+#
+# STRATEGY:
+# 1. create a pool with a whole disk
+# 2. create a filesystem on this pool
+# 3. verify we can 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 works"
+
+log_assert $assert_mesg
+create_pool "$TESTPOOL" "$DISK"
+log_must $ZFS create $EFI_BOOTFS
+
+log_must $ZPOOL set bootfs=$EFI_BOOTFS $TESTPOOL
+
+log_pass $assert_mesg
diff --git a/tests/zfs-tests/tests/functional/bootfs/bootfs_008_neg.ksh b/tests/zfs-tests/tests/functional/bootfs/bootfs_008_neg.ksh
new file mode 100755 (executable)
index 0000000..1bf9bda
--- /dev/null
@@ -0,0 +1,78 @@
+#!/bin/ksh -p
+#
+# CDDL HEADER START
+#
+# The contents of this file are subject to the terms of the
+# Common Development and Distribution License (the "License").
+# You may not use this file except in compliance with the License.
+#
+# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
+# or http://www.opensolaris.org/os/licensing.
+# See the License for the specific language governing permissions
+# and limitations under the License.
+#
+# When distributing Covered Code, include this CDDL HEADER in each
+# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
+# If applicable, add the following below this CDDL HEADER, with the
+# fields enclosed by brackets "[]" replaced with your own identifying
+# information: Portions Copyright [yyyy] [name of copyright owner]
+#
+# CDDL HEADER END
+#
+
+#
+# Copyright 2009 Sun Microsystems, Inc.  All rights reserved.
+# Use is subject to license terms.
+#
+
+. $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=$TESTDIR/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
diff --git a/tests/zfs-tests/tests/functional/bootfs/cleanup.ksh b/tests/zfs-tests/tests/functional/bootfs/cleanup.ksh
new file mode 100755 (executable)
index 0000000..f481a70
--- /dev/null
@@ -0,0 +1,34 @@
+#! /bin/ksh -p
+#
+# CDDL HEADER START
+#
+# The contents of this file are subject to the terms of the
+# Common Development and Distribution License (the "License").
+# You may not use this file except in compliance with the License.
+#
+# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
+# or http://www.opensolaris.org/os/licensing.
+# See the License for the specific language governing permissions
+# and limitations under the License.
+#
+# When distributing Covered Code, include this CDDL HEADER in each
+# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
+# If applicable, add the following below this CDDL 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) 2015 by Lawrence Livermore National Security, LLC
+# All rights reserved.
+#
+
+. $STF_SUITE/include/libtest.shlib
+
+verify_runnable "global"
+
+[[ -e $TESTDIR ]] && $RM -rf $TESTDIR
+
+log_pass
diff --git a/tests/zfs-tests/tests/functional/bootfs/setup.ksh b/tests/zfs-tests/tests/functional/bootfs/setup.ksh
new file mode 100755 (executable)
index 0000000..694a805
--- /dev/null
@@ -0,0 +1,34 @@
+#! /bin/ksh -p
+#
+# CDDL HEADER START
+#
+# The contents of this file are subject to the terms of the
+# Common Development and Distribution License (the "License").
+# You may not use this file except in compliance with the License.
+#
+# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
+# or http://www.opensolaris.org/os/licensing.
+# See the License for the specific language governing permissions
+# and limitations under the License.
+#
+# When distributing Covered Code, include this CDDL HEADER in each
+# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
+# If applicable, add the following below this CDDL 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) 2015 by Lawrence Livermore National Security, LLC.
+# All rights reserved.
+#
+
+. $STF_SUITE/include/libtest.shlib
+
+verify_runnable "global"
+
+log_must $MKDIR $TESTDIR
+
+log_pass
diff --git a/tests/zfs-tests/tests/functional/cache/Makefile.am b/tests/zfs-tests/tests/functional/cache/Makefile.am
new file mode 100644 (file)
index 0000000..f1aaf72
--- /dev/null
@@ -0,0 +1,17 @@
+pkgdatadir = $(datadir)/@PACKAGE@/zfs-tests/tests/functional/cache
+dist_pkgdata_SCRIPTS = \
+       cache.cfg \
+       cache.kshlib \
+       cleanup.ksh \
+       setup.ksh \
+       cache_001_pos.ksh \
+       cache_002_pos.ksh \
+       cache_003_pos.ksh \
+       cache_004_neg.ksh \
+       cache_005_neg.ksh \
+       cache_006_pos.ksh \
+       cache_007_neg.ksh \
+       cache_008_neg.ksh \
+       cache_009_pos.ksh \
+       cache_010_neg.ksh \
+       cache_011_pos.ksh
diff --git a/tests/zfs-tests/tests/functional/cache/cache.cfg b/tests/zfs-tests/tests/functional/cache/cache.cfg
new file mode 100644 (file)
index 0000000..f8a795d
--- /dev/null
@@ -0,0 +1,70 @@
+#
+# CDDL HEADER START
+#
+# The contents of this file are subject to the terms of the
+# Common Development and Distribution License (the "License").
+# You may not use this file except in compliance with the License.
+#
+# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
+# or http://www.opensolaris.org/os/licensing.
+# See the License for the specific language governing permissions
+# and limitations under the License.
+#
+# When distributing Covered Code, include this CDDL HEADER in each
+# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
+# If applicable, add the following below this CDDL HEADER, with the
+# fields enclosed by brackets "[]" replaced with your own identifying
+# information: Portions Copyright [yyyy] [name of copyright owner]
+#
+# CDDL HEADER END
+#
+
+#
+# Copyright 2009 Sun Microsystems, Inc.  All rights reserved.
+# Use is subject to license terms.
+#
+
+#
+# Copyright (c) 2013 by Delphix. All rights reserved.
+#
+
+. $STF_SUITE/include/libtest.shlib
+
+function set_disks
+{
+       set -A disk_array $(find_disks $DISKS)
+
+       typeset -i DISK_ARRAY_NUM=0
+
+       if (( ${#disk_array[*]} <= 1 )); then
+               export DISK=${DISKS%% *}
+       else
+               export DISK=""
+               typeset -i i=0
+               while (( i < ${#disk_array[*]} )); do
+                       export DISK${i}="${disk_array[$i]}"
+                       DISKSARRAY="$DISKSARRAY ${disk_array[$i]}"
+                       (( i = i + 1 ))
+               done
+               export DISK_ARRAY_NUM=$i
+               export DISKSARRAY
+       fi
+
+       if (( $DISK_ARRAY_NUM == 0 )); then
+               export disk=$DISK
+       else
+               export disk=$DISK0
+       fi
+}
+
+set_disks
+
+export SIZE=64M
+
+export VDIR=$TESTDIR/disk.cache
+export VDIR2=$TESTDIR/disk2.cache
+
+export VDEV="$VDIR/a $VDIR/b $VDIR/c"
+export LDEV="$DISK0"
+export VDEV2="$VDIR2/a $VDIR2/b $VDIR2/c"
+export LDEV2="$DISK1"
diff --git a/tests/zfs-tests/tests/functional/cache/cache.kshlib b/tests/zfs-tests/tests/functional/cache/cache.kshlib
new file mode 100644 (file)
index 0000000..6cdeef7
--- /dev/null
@@ -0,0 +1,160 @@
+#
+# CDDL HEADER START
+#
+# The contents of this file are subject to the terms of the
+# Common Development and Distribution License (the "License").
+# You may not use this file except in compliance with the License.
+#
+# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
+# or http://www.opensolaris.org/os/licensing.
+# See the License for the specific language governing permissions
+# and limitations under the License.
+#
+# When distributing Covered Code, include this CDDL HEADER in each
+# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
+# If applicable, add the following below this CDDL HEADER, with the
+# fields enclosed by brackets "[]" replaced with your own identifying
+# information: Portions Copyright [yyyy] [name of copyright owner]
+#
+# CDDL HEADER END
+#
+
+#
+# Copyright 2009 Sun Microsystems, Inc.  All rights reserved.
+# Use is subject to license terms.
+#
+
+#
+# Copyright (c) 2013 by Delphix. All rights reserved.
+#
+
+. $STF_SUITE/include/libtest.shlib
+
+function cleanup
+{
+       if datasetexists $TESTPOOL ; then
+               log_must $ZPOOL destroy -f $TESTPOOL
+       fi
+       if datasetexists $TESTPOOL2 ; then
+               log_must $ZPOOL destroy -f $TESTPOOL2
+       fi
+}
+
+#
+# Try zpool status/iostat for given pool
+#
+# $1 pool
+#
+function display_status
+{
+       typeset pool=$1
+
+       typeset -i ret=0
+       $ZPOOL status -xv $pool > /dev/null 2>&1
+       ret=$?
+
+       $ZPOOL iostat > /dev/null 2>&1
+       ((ret |= $?))
+
+       typeset mntpnt=$(get_prop mountpoint $pool)
+       $DD if=/dev/random of=$mntpnt/testfile.$$ &
+       typeset pid=$!
+
+       $ZPOOL iostat -v 1 3 > /dev/null
+       ((ret |= $?))
+
+       kill -9 $pid
+
+       return $ret
+}
+
+#
+# Verify the given cache device have correct type and status
+#
+# $1 pool name
+# $2 device name
+# $3 device status
+# $4 device type
+#
+function verify_cache_device
+{
+       typeset pool=$1
+       typeset device=$2
+       typeset status=$3
+       typeset type=$4
+
+       if [[ -z $pool || -z $device || -z $status ]]; then
+               log_fail "Usage: verify_cache_device <pool> <device> " \
+                       "<status> [type]"
+       fi
+
+       if [[ $WRAPPER == *"smi"* ]]; then
+               $ECHO $device | $EGREP "^c[0-F]+([td][0-F]+)+$" > /dev/null 2>&1
+               if (( $? == 0 )); then
+                       device=${device}s2
+               fi
+       fi
+
+       #
+       # Get all the cache devices and status table like below
+       #
+       # mirror:/disks/d ONLINE mirror:/disks/e ONLINE stripe:/disks/f ONLINE
+       #
+       set -A dev_stat_tab $($ZPOOL status -v $pool | $NAWK 'BEGIN {start=0} \
+                               /\tcache/ {start=1}
+                               /\tmirror/ || /\tspares/ || /^$/ {start=0}
+                               (start==1) && /\t  (\/|[a-zA-Z])/ \
+                                       {print "stripe:" $1 " " $2}
+                               (start==1) && /\t    (\/|[a-zA-Z])/ \
+                                       {print "mirror:" $1 " " $2}
+                               # When hotspare is replacing
+                               (start==1) && /\t      (\/|[a-zA-Z])/ \
+                                       {print "mirror:" $1 " " $2}'
+                            )
+
+       typeset -i i=0
+       typeset find=0
+       while (( i < ${#dev_stat_tab[@]} )); do
+               typeset dev=${dev_stat_tab[$i]}
+               typeset stat=${dev_stat_tab[((i+1))]}
+
+               case $dev in
+                       stripe:$device)
+                               if [[ "$type" == 'mirror' ]]; then
+                                       log_note "Unexpected type: mirror"
+                                       return 1
+                               else
+                                       if [[ $stat != $status ]]; then
+                                               log_note "Status($stat) " \
+                                                       "!= Expected stat($status)"
+                                               return 1
+                                       fi
+                                       return 0
+                               fi
+                               ;;
+                       mirror:$device)
+                               if [[ -z "$type" || $type == 'stripe' ]]; then
+                                       log_note "Unexpected type: stripe"
+                                       return 1
+                               else
+                                       if [[ $stat != $status ]]; then
+                                               log_note "Status($stat) " \
+                                                       "!= Expected stat($status)"
+                                               return 1
+                                       fi
+                                       return 0
+                               fi
+                               ;;
+               esac
+               ((i += 2))
+       done
+
+       log_note "Can not find device: $device"
+       return 1
+}
+
+function verify_cache_support
+{
+       $ZPOOL upgrade -v | $GREP "Cache devices" > /dev/null 2>&1
+       return $?
+}
diff --git a/tests/zfs-tests/tests/functional/cache/cache_001_pos.ksh b/tests/zfs-tests/tests/functional/cache/cache_001_pos.ksh
new file mode 100755 (executable)
index 0000000..7b4f560
--- /dev/null
@@ -0,0 +1,65 @@
+#!/bin/ksh -p
+#
+# CDDL HEADER START
+#
+# The contents of this file are subject to the terms of the
+# Common Development and Distribution License (the "License").
+# You may not use this file except in compliance with the License.
+#
+# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
+# or http://www.opensolaris.org/os/licensing.
+# See the License for the specific language governing permissions
+# and limitations under the License.
+#
+# When distributing Covered Code, include this CDDL HEADER in each
+# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
+# If applicable, add the following below this CDDL HEADER, with the
+# fields enclosed by brackets "[]" replaced with your own identifying
+# information: Portions Copyright [yyyy] [name of copyright owner]
+#
+# CDDL HEADER END
+#
+
+#
+# Copyright 2008 Sun Microsystems, Inc.  All rights reserved.
+# Use is subject to license terms.
+#
+
+#
+# Copyright (c) 2013 by Delphix. All rights reserved.
+#
+
+. $STF_SUITE/tests/functional/cache/cache.cfg
+. $STF_SUITE/tests/functional/cache/cache.kshlib
+
+#
+# DESCRIPTION:
+#      Creating a pool with a cache device succeeds.
+#
+# STRATEGY:
+#      1. Create pool with separated cache devices.
+#      2. Display pool status
+#      3. Destroy and loop to create pool with different configuration.
+#
+
+verify_runnable "global"
+
+log_assert "Creating a pool with a cache device succeeds."
+log_onexit cleanup
+
+for type in "" "mirror" "raidz" "raidz2"
+do
+       log_must $ZPOOL create $TESTPOOL $type $VDEV \
+               cache $LDEV
+       log_must display_status $TESTPOOL
+
+       ldev=$(random_get $LDEV)
+       log_must verify_cache_device $TESTPOOL $ldev 'ONLINE'
+
+       log_must $ZPOOL remove $TESTPOOL $ldev
+       log_must check_vdev_state $TESTPOOL $ldev ""
+
+       log_must $ZPOOL destroy -f $TESTPOOL
+done
+
+log_pass "Creating a pool with a cache device succeeds."
diff --git a/tests/zfs-tests/tests/functional/cache/cache_002_pos.ksh b/tests/zfs-tests/tests/functional/cache/cache_002_pos.ksh
new file mode 100755 (executable)
index 0000000..5c2c34e
--- /dev/null
@@ -0,0 +1,65 @@
+#!/bin/ksh -p
+#
+# CDDL HEADER START
+#
+# The contents of this file are subject to the terms of the
+# Common Development and Distribution License (the "License").
+# You may not use this file except in compliance with the License.
+#
+# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
+# or http://www.opensolaris.org/os/licensing.
+# See the License for the specific language governing permissions
+# and limitations under the License.
+#
+# When distributing Covered Code, include this CDDL HEADER in each
+# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
+# If applicable, add the following below this CDDL HEADER, with the
+# fields enclosed by brackets "[]" replaced with your own identifying
+# information: Portions Copyright [yyyy] [name of copyright owner]
+#
+# CDDL HEADER END
+#
+
+#
+# Copyright 2008 Sun Microsystems, Inc.  All rights reserved.
+# Use is subject to license terms.
+#
+
+#
+# Copyright (c) 2013 by Delphix. All rights reserved.
+#
+
+. $STF_SUITE/tests/functional/cache/cache.cfg
+. $STF_SUITE/tests/functional/cache/cache.kshlib
+
+#
+# DESCRIPTION:
+#      Adding a cache device to normal pool works.
+#
+# STRATEGY:
+#      1. Create pool
+#      2. Add cache devices with different configuration
+#      3. Display pool status
+#      4. Destroy and loop to create pool with different configuration.
+#
+
+verify_runnable "global"
+
+log_assert "Adding a cache device to normal pool works."
+log_onexit cleanup
+
+for type in "" "mirror" "raidz" "raidz2"
+do
+       log_must $ZPOOL create $TESTPOOL $type $VDEV
+       log_must $ZPOOL add $TESTPOOL cache $LDEV
+       log_must display_status $TESTPOOL
+       typeset ldev=$(random_get $LDEV)
+       log_must verify_cache_device $TESTPOOL $ldev 'ONLINE'
+
+       log_must $ZPOOL remove $TESTPOOL $ldev
+       log_must check_vdev_state $TESTPOOL $ldev ""
+
+       log_must $ZPOOL destroy -f $TESTPOOL
+done
+
+log_pass "Adding a cache device to normal pool works."
diff --git a/tests/zfs-tests/tests/functional/cache/cache_003_pos.ksh b/tests/zfs-tests/tests/functional/cache/cache_003_pos.ksh
new file mode 100755 (executable)
index 0000000..73b5d34
--- /dev/null
@@ -0,0 +1,69 @@
+#!/bin/ksh -p
+#
+# CDDL HEADER START
+#
+# The contents of this file are subject to the terms of the
+# Common Development and Distribution License (the "License").
+# You may not use this file except in compliance with the License.
+#
+# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
+# or http://www.opensolaris.org/os/licensing.
+# See the License for the specific language governing permissions
+# and limitations under the License.
+#
+# When distributing Covered Code, include this CDDL HEADER in each
+# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
+# If applicable, add the following below this CDDL HEADER, with the
+# fields enclosed by brackets "[]" replaced with your own identifying
+# information: Portions Copyright [yyyy] [name of copyright owner]
+#
+# CDDL HEADER END
+#
+
+#
+# Copyright 2009 Sun Microsystems, Inc.  All rights reserved.
+# Use is subject to license terms.
+#
+
+#
+# Copyright (c) 2013 by Delphix. All rights reserved.
+#
+
+. $STF_SUITE/tests/functional/cache/cache.cfg
+. $STF_SUITE/tests/functional/cache/cache.kshlib
+
+#
+# DESCRIPTION:
+#      Adding an extra cache device works
+#
+# STRATEGY:
+#      1. Create pool with separated cache devices.
+#      2. Add an extra cache devices
+#      3. Display pool status
+#      4. Destroy and loop to create pool with different configuration.
+#
+
+verify_runnable "global"
+verify_disk_count "$LDEV2"
+
+log_assert "Adding an extra cache device works."
+log_onexit cleanup
+
+for type in "" "mirror" "raidz" "raidz2"
+do
+       log_must $ZPOOL create $TESTPOOL $type $VDEV \
+               cache $LDEV
+       log_must $ZPOOL add $TESTPOOL \
+               cache $LDEV2
+
+       log_must display_status $TESTPOOL
+       ldev=$(random_get $LDEV2)
+       log_must verify_cache_device $TESTPOOL $ldev 'ONLINE'
+
+       log_must $ZPOOL remove $TESTPOOL $ldev
+       log_must check_vdev_state $TESTPOOL $ldev ""
+
+       log_must $ZPOOL destroy -f $TESTPOOL
+done
+
+log_pass "Adding an extra cache device works."
diff --git a/tests/zfs-tests/tests/functional/cache/cache_004_neg.ksh b/tests/zfs-tests/tests/functional/cache/cache_004_neg.ksh
new file mode 100755 (executable)
index 0000000..e71d4d0
--- /dev/null
@@ -0,0 +1,64 @@
+#!/bin/ksh -p
+#
+# CDDL HEADER START
+#
+# The contents of this file are subject to the terms of the
+# Common Development and Distribution License (the "License").
+# You may not use this file except in compliance with the License.
+#
+# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
+# or http://www.opensolaris.org/os/licensing.
+# See the License for the specific language governing permissions
+# and limitations under the License.
+#
+# When distributing Covered Code, include this CDDL HEADER in each
+# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
+# If applicable, add the following below this CDDL HEADER, with the
+# fields enclosed by brackets "[]" replaced with your own identifying
+# information: Portions Copyright [yyyy] [name of copyright owner]
+#
+# CDDL HEADER END
+#
+
+#
+# Copyright 2009 Sun Microsystems, Inc.  All rights reserved.
+# Use is subject to license terms.
+#
+
+#
+# Copyright (c) 2013 by Delphix. All rights reserved.
+#
+
+. $STF_SUITE/tests/functional/cache/cache.cfg
+. $STF_SUITE/tests/functional/cache/cache.kshlib
+
+#
+# DESCRIPTION:
+#      Attaching a cache device fails.
+#
+# STRATEGY:
+#      1. Create pool with separated cache devices.
+#      2. Attaching a cache device for existing cache device
+#      3. Verify the operation fails
+#
+
+verify_runnable "global"
+verify_disk_count "$LDEV2"
+
+log_assert "Attaching a cache device fails for an existing cache device."
+log_onexit cleanup
+
+for type in "" "mirror" "raidz" "raidz2"
+do
+       log_must $ZPOOL create $TESTPOOL $type $VDEV \
+               cache $LDEV
+
+       ldev=$(random_get $LDEV)
+       typeset ldev2=$(random_get $LDEV2)
+       log_mustnot $ZPOOL attach $TESTPOOL $ldev $ldev2
+       log_must check_vdev_state $TESTPOOL $ldev2 ""
+
+       log_must $ZPOOL destroy -f $TESTPOOL
+done
+
+log_pass "Attaching a cache device fails for an existing cache device."
diff --git a/tests/zfs-tests/tests/functional/cache/cache_005_neg.ksh b/tests/zfs-tests/tests/functional/cache/cache_005_neg.ksh
new file mode 100755 (executable)
index 0000000..6f61326
--- /dev/null
@@ -0,0 +1,65 @@
+#!/bin/ksh -p
+#
+# CDDL HEADER START
+#
+# The contents of this file are subject to the terms of the
+# Common Development and Distribution License (the "License").
+# You may not use this file except in compliance with the License.
+#
+# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
+# or http://www.opensolaris.org/os/licensing.
+# See the License for the specific language governing permissions
+# and limitations under the License.
+#
+# When distributing Covered Code, include this CDDL HEADER in each
+# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
+# If applicable, add the following below this CDDL HEADER, with the
+# fields enclosed by brackets "[]" replaced with your own identifying
+# information: Portions Copyright [yyyy] [name of copyright owner]
+#
+# CDDL HEADER END
+#
+
+#
+# Copyright 2009 Sun Microsystems, Inc.  All rights reserved.
+# Use is subject to license terms.
+#
+
+#
+# Copyright (c) 2013 by Delphix. All rights reserved.
+#
+
+. $STF_SUITE/tests/functional/cache/cache.cfg
+. $STF_SUITE/tests/functional/cache/cache.kshlib
+
+#
+# DESCRIPTION:
+#      Replacing a cache device fails.
+#
+# STRATEGY:
+#      1. Create pool with cache devices.
+#      2. Replacing one cache device
+#      3. Verify replace fails
+#      4. Destroy and loop to create pool with different configuration.
+#
+
+verify_runnable "global"
+verify_disk_count "$LDEV2"
+
+log_assert "Replacing a cache device fails."
+log_onexit cleanup
+
+for type in "" "mirror" "raidz" "raidz2"
+do
+       log_must $ZPOOL create $TESTPOOL $type $VDEV \
+               cache $LDEV
+       sdev=$(random_get $LDEV)
+       tdev=$(random_get $LDEV2)
+       log_mustnot $ZPOOL replace $TESTPOOL $sdev $tdev
+       log_must verify_cache_device $TESTPOOL $sdev 'ONLINE'
+       log_must check_vdev_state $TESTPOOL $tdev ""
+
+       log_must $ZPOOL destroy -f $TESTPOOL
+done
+
+log_pass "Replacing a cache device fails."
diff --git a/tests/zfs-tests/tests/functional/cache/cache_006_pos.ksh b/tests/zfs-tests/tests/functional/cache/cache_006_pos.ksh
new file mode 100755 (executable)
index 0000000..1ced5ab
--- /dev/null
@@ -0,0 +1,85 @@
+#!/bin/ksh -p
+#
+# CDDL HEADER START
+#
+# The contents of this file are subject to the terms of the
+# Common Development and Distribution License (the "License").
+# You may not use this file except in compliance with the License.
+#
+# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
+# or http://www.opensolaris.org/os/licensing.
+# See the License for the specific language governing permissions
+# and limitations under the License.
+#
+# When distributing Covered Code, include this CDDL HEADER in each
+# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
+# If applicable, add the following below this CDDL HEADER, with the
+# fields enclosed by brackets "[]" replaced with your own identifying
+# information: Portions Copyright [yyyy] [name of copyright owner]
+#
+# CDDL HEADER END
+#
+
+#
+# Copyright 2009 Sun Microsystems, Inc.  All rights reserved.
+# Use is subject to license terms.
+#
+
+#
+# Copyright (c) 2013 by Delphix. All rights reserved.
+#
+
+. $STF_SUITE/tests/functional/cache/cache.cfg
+. $STF_SUITE/tests/functional/cache/cache.kshlib
+
+#
+# DESCRIPTION:
+#      Exporting and importing pool with cache devices passes.
+#
+# STRATEGY:
+#      1. Create pool with cache devices.
+#      2. Export and import the pool
+#      3. Display pool status
+#      4. Destroy and import the pool again
+#      5. Display pool status
+#      6. Destroy and loop to create pool with different configuration.
+#
+
+verify_runnable "global"
+verify_disk_count "$LDEV2"
+
+log_assert "Exporting and importing pool with cache devices passes."
+log_onexit cleanup
+
+for type in "" "mirror" "raidz" "raidz2"
+do
+       log_must $ZPOOL create $TESTPOOL $type $VDEV \
+               cache $LDEV $LDEV2
+       ldev=$(random_get $LDEV $LDEV2)
+       log_must verify_cache_device \
+               $TESTPOOL $ldev 'ONLINE'
+
+       #
+       # Nomal export/import operating
+       #
+       log_must $ZPOOL export $TESTPOOL
+       log_must $ZPOOL import -d $VDIR $TESTPOOL
+       log_must display_status $TESTPOOL
+       ldev=$(random_get $LDEV $LDEV2)
+       log_must verify_cache_device \
+               $TESTPOOL $ldev 'ONLINE'
+
+       #
+       # Destroy the pool and import again
+       #
+       log_must $ZPOOL destroy $TESTPOOL
+       log_must $ZPOOL import -Df -d $VDIR $TESTPOOL
+       log_must display_status $TESTPOOL
+       ldev=$(random_get $LDEV $LDEV2)
+       log_must verify_cache_device \
+               $TESTPOOL $ldev 'ONLINE'
+
+       log_must $ZPOOL destroy -f $TESTPOOL
+done
+
+log_pass "Exporting and importing pool with cache devices passes."
diff --git a/tests/zfs-tests/tests/functional/cache/cache_007_neg.ksh b/tests/zfs-tests/tests/functional/cache/cache_007_neg.ksh
new file mode 100755 (executable)
index 0000000..3f204ef
--- /dev/null
@@ -0,0 +1,63 @@
+#!/bin/ksh -p
+#
+# CDDL HEADER START
+#
+# The contents of this file are subject to the terms of the
+# Common Development and Distribution License (the "License").
+# You may not use this file except in compliance with the License.
+#
+# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
+# or http://www.opensolaris.org/os/licensing.
+# See the License for the specific language governing permissions
+# and limitations under the License.
+#
+# When distributing Covered Code, include this CDDL HEADER in each
+# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
+# If applicable, add the following below this CDDL HEADER, with the
+# fields enclosed by brackets "[]" replaced with your own identifying
+# information: Portions Copyright [yyyy] [name of copyright owner]
+#
+# CDDL HEADER END
+#
+
+#
+# Copyright 2009 Sun Microsystems, Inc.  All rights reserved.
+# Use is subject to license terms.
+#
+
+#
+# Copyright (c) 2013 by Delphix. All rights reserved.
+#
+
+. $STF_SUITE/tests/functional/cache/cache.cfg
+. $STF_SUITE/tests/functional/cache/cache.kshlib
+
+#
+# DESCRIPTION:
+#      A mirror/raidz/raidz2 cache is not supported.
+#
+# STRATEGY:
+#      1. Try to create pool with unsupported type
+#      2. Verify failed to create pool.
+#
+
+verify_runnable "global"
+verify_disk_count "$LDEV2"
+
+log_assert "A mirror/raidz/raidz2 cache is not supported."
+log_onexit cleanup
+
+for type in "" "mirror" "raidz" "raidz2"
+do
+       for cachetype in "mirror" "raidz" "raidz1" "raidz2"
+       do
+               log_mustnot $ZPOOL create $TESTPOOL $type $VDEV \
+                       cache $cachetype $LDEV $LDEV2
+               ldev=$(random_get $LDEV $LDEV2)
+               log_mustnot verify_cache_device \
+                       $TESTPOOL $ldev 'ONLINE' $cachetype
+               log_must datasetnonexists $TESTPOOL
+       done
+done
+
+log_pass "A mirror/raidz/raidz2 cache is not supported."
diff --git a/tests/zfs-tests/tests/functional/cache/cache_008_neg.ksh b/tests/zfs-tests/tests/functional/cache/cache_008_neg.ksh
new file mode 100755 (executable)
index 0000000..c251c5a
--- /dev/null
@@ -0,0 +1,67 @@
+#!/bin/ksh -p
+#
+# CDDL HEADER START
+#
+# The contents of this file are subject to the terms of the
+# Common Development and Distribution License (the "License").
+# You may not use this file except in compliance with the License.
+#
+# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
+# or http://www.opensolaris.org/os/licensing.
+# See the License for the specific language governing permissions
+# and limitations under the License.
+#
+# When distributing Covered Code, include this CDDL HEADER in each
+# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
+# If applicable, add the following below this CDDL HEADER, with the
+# fields enclosed by brackets "[]" replaced with your own identifying
+# information: Portions Copyright [yyyy] [name of copyright owner]
+#
+# CDDL HEADER END
+#
+
+#
+# Copyright 2009 Sun Microsystems, Inc.  All rights reserved.
+# Use is subject to license terms.
+#
+
+#
+# Copyright (c) 2013 by Delphix. All rights reserved.
+#
+
+. $STF_SUITE/tests/functional/cache/cache.cfg
+. $STF_SUITE/tests/functional/cache/cache.kshlib
+
+#
+# DESCRIPTION:
+#      A mirror/raidz/raidz2 cache can not be added to existed pool.
+#
+# STRATEGY:
+#      1. Create pool with or without cache.
+#      2. Add a mirror/raidz/raidz2 cache to this pool.
+#      3. Verify failed to add.
+#
+
+verify_runnable "global"
+verify_disk_count "$LDEV2"
+
+log_assert "A raidz/raidz2 cache can not be added to existed pool."
+log_onexit cleanup
+
+for type in "" "mirror" "raidz" "raidz2"
+do
+       for cachetype in "mirror" "raidz" "raidz1" "raidz2"
+       do
+               log_must $ZPOOL create $TESTPOOL $type $VDEV \
+                       cache $LDEV
+
+               log_mustnot $ZPOOL add $TESTPOOL cache $cachetype $LDEV2
+               ldev=$(random_get $LDEV2)
+               log_mustnot verify_cache_device \
+                       $TESTPOOL $ldev 'ONLINE' $cachetype
+
+               log_must $ZPOOL destroy $TESTPOOL
+       done
+done
+
+log_pass "A mirror/raidz/raidz2 cache can not be added to existed pool."
diff --git a/tests/zfs-tests/tests/functional/cache/cache_009_pos.ksh b/tests/zfs-tests/tests/functional/cache/cache_009_pos.ksh
new file mode 100755 (executable)
index 0000000..f4c5f50
--- /dev/null
@@ -0,0 +1,69 @@
+#!/bin/ksh -p
+#
+# CDDL HEADER START
+#
+# The contents of this file are subject to the terms of the
+# Common Development and Distribution License (the "License").
+# You may not use this file except in compliance with the License.
+#
+# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
+# or http://www.opensolaris.org/os/licensing.
+# See the License for the specific language governing permissions
+# and limitations under the License.
+#
+# When distributing Covered Code, include this CDDL HEADER in each
+# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
+# If applicable, add the following below this CDDL HEADER, with the
+# fields enclosed by brackets "[]" replaced with your own identifying
+# information: Portions Copyright [yyyy] [name of copyright owner]
+#
+# CDDL HEADER END
+#
+
+#
+# Copyright 2009 Sun Microsystems, Inc.  All rights reserved.
+# Use is subject to license terms.
+#
+
+#
+# Copyright (c) 2013 by Delphix. All rights reserved.
+#
+
+. $STF_SUITE/tests/functional/cache/cache.cfg
+. $STF_SUITE/tests/functional/cache/cache.kshlib
+
+#
+# DESCRIPTION:
+#      Offline and online a cache device succeed.
+#
+# STRATEGY:
+#      1. Create pool with mirror cache devices.
+#      2. Offine and online a cache device
+#      3. Display pool status
+#      4. Destroy and loop to create pool with different configuration.
+#
+
+verify_runnable "global"
+verify_disk_count "$LDEV2"
+
+log_assert "Offline and online a cache device succeed."
+log_onexit cleanup
+
+for type in "" "mirror" "raidz" "raidz2"
+do
+       log_must $ZPOOL create $TESTPOOL $type $VDEV \
+               cache $LDEV $LDEV2
+
+       ldev=$(random_get $LDEV $LDEV2)
+       log_must $ZPOOL offline $TESTPOOL $ldev
+       log_must display_status $TESTPOOL
+       log_must verify_cache_device $TESTPOOL $ldev 'OFFLINE' ''
+
+       log_must $ZPOOL online $TESTPOOL $ldev
+       log_must display_status $TESTPOOL
+       log_must verify_cache_device $TESTPOOL $ldev 'ONLINE' ''
+
+       log_must $ZPOOL destroy -f $TESTPOOL
+done
+
+log_pass "Offline and online a cache device succeed."
diff --git a/tests/zfs-tests/tests/functional/cache/cache_010_neg.ksh b/tests/zfs-tests/tests/functional/cache/cache_010_neg.ksh
new file mode 100755 (executable)
index 0000000..7aca708
--- /dev/null
@@ -0,0 +1,90 @@
+#!/bin/ksh -p
+#
+# CDDL HEADER START
+#
+# The contents of this file are subject to the terms of the
+# Common Development and Distribution License (the "License").
+# You may not use this file except in compliance with the License.
+#
+# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
+# or http://www.opensolaris.org/os/licensing.
+# See the License for the specific language governing permissions
+# and limitations under the License.
+#
+# When distributing Covered Code, include this CDDL HEADER in each
+# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
+# If applicable, add the following below this CDDL HEADER, with the
+# fields enclosed by brackets "[]" replaced with your own identifying
+# information: Portions Copyright [yyyy] [name of copyright owner]
+#
+# CDDL HEADER END
+#
+
+#
+# Copyright 2008 Sun Microsystems, Inc.  All rights reserved.
+# Use is subject to license terms.
+#
+
+#
+# Copyright (c) 2013 by Delphix. All rights reserved.
+#
+
+. $STF_SUITE/tests/functional/cache/cache.cfg
+. $STF_SUITE/tests/functional/cache/cache.kshlib
+
+#
+# DESCRIPTION:
+#      Verify cache device must be a block device.
+#
+# STRATEGY:
+#      1. Create a pool
+#      2. Add different object as cache
+#      3. Verify character devices and files fail
+#
+
+verify_runnable "global"
+
+function cleanup_testenv
+{
+       cleanup
+       if [[ -n $lofidev ]]; then
+               log_must $LOFIADM -d $lofidev
+       fi
+}
+
+log_assert "Cache device can only be block devices."
+log_onexit cleanup_testenv
+
+TESTVOL=testvol1$$
+dsk1=${DISKS%% *}
+log_must $ZPOOL create $TESTPOOL ${DISKS#$dsk1}
+
+if is_linux; then
+       SLICE="p1"
+else
+       SLICE="s0"
+fi
+
+# Add nomal ${DEV_RDSKDIR} device
+log_mustnot $ZPOOL add $TESTPOOL cache ${DEV_RDSKDIR}/${dsk1}${SLICE}
+#log_must verify_cache_device $TESTPOOL $dsk1 'ONLINE'
+
+# Add nomal file
+log_mustnot $ZPOOL add $TESTPOOL cache $VDEV2
+
+# Add /dev/rlofi device
+lofidev=${VDEV2%% *}
+log_must $LOFIADM -a $lofidev
+lofidev=$($LOFIADM $lofidev)
+log_mustnot $ZPOOL add $TESTPOOL cache "/dev/rlofi/${lofidev#/dev/lofi/}"
+if [[ -n $lofidev ]]; then
+       log_must $LOFIADM -d $lofidev
+       lofidev=""
+fi
+
+# Add ${ZVOL_RDEVDIR} device
+log_must $ZPOOL create $TESTPOOL2 $VDEV2
+log_must $ZFS create -V $SIZE $TESTPOOL2/$TESTVOL
+log_mustnot $ZPOOL add $TESTPOOL cache ${ZVOL_RDEVDIR}/$TESTPOOL2/$TESTVOL
+
+log_pass "Cache device can only be block devices."
diff --git a/tests/zfs-tests/tests/functional/cache/cache_011_pos.ksh b/tests/zfs-tests/tests/functional/cache/cache_011_pos.ksh
new file mode 100755 (executable)
index 0000000..5f9e6db
--- /dev/null
@@ -0,0 +1,68 @@
+#!/bin/ksh -p
+#
+# CDDL HEADER START
+#
+# The contents of this file are subject to the terms of the
+# Common Development and Distribution License (the "License").
+# You may not use this file except in compliance with the License.
+#
+# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
+# or http://www.opensolaris.org/os/licensing.
+# See the License for the specific language governing permissions
+# and limitations under the License.
+#
+# When distributing Covered Code, include this CDDL HEADER in each
+# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
+# If applicable, add the following below this CDDL HEADER, with the
+# fields enclosed by brackets "[]" replaced with your own identifying
+# information: Portions Copyright [yyyy] [name of copyright owner]
+#
+# CDDL HEADER END
+#
+
+#
+# Copyright 2009 Sun Microsystems, Inc.  All rights reserved.
+# Use is subject to license terms.
+#
+
+#
+# Copyright (c) 2013 by Delphix. All rights reserved.
+#
+
+. $STF_SUITE/tests/functional/cache/cache.cfg
+. $STF_SUITE/tests/functional/cache/cache.kshlib
+
+#
+# DESCRIPTION:
+#      Remove cache device from pool with spare device should succeed.
+#
+# STRATEGY:
+#      1. Create pool with cache devices and spare devices
+#      2. Remove cache device from the pool
+#      3. The upper action should succeed
+#
+
+verify_runnable "global"
+verify_disk_count "$LDEV2"
+
+function cleanup {
+       if datasetexists $TESTPOOL ; then
+               log_must $ZPOOL destroy -f $TESTPOOL
+       fi
+}
+
+log_assert "Remove cache device from pool with spare device should succeed"
+log_onexit cleanup
+
+for type in "" "mirror" "raidz" "raidz2"
+do
+       log_must $ZPOOL create $TESTPOOL $type $VDEV \
+               cache $LDEV spare $LDEV2
+
+       log_must $ZPOOL remove $TESTPOOL $LDEV
+       log_must display_status $TESTPOOL
+
+       log_must $ZPOOL destroy -f $TESTPOOL
+done
+
+log_pass "Remove cache device from pool with spare device should succeed"
diff --git a/tests/zfs-tests/tests/functional/cache/cleanup.ksh b/tests/zfs-tests/tests/functional/cache/cleanup.ksh
new file mode 100755 (executable)
index 0000000..ea57d0d
--- /dev/null
@@ -0,0 +1,46 @@
+#!/bin/ksh -p
+#
+# CDDL HEADER START
+#
+# The contents of this file are subject to the terms of the
+# Common Development and Distribution License (the "License").
+# You may not use this file except in compliance with the License.
+#
+# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
+# or http://www.opensolaris.org/os/licensing.
+# See the License for the specific language governing permissions
+# and limitations under the License.
+#
+# When distributing Covered Code, include this CDDL HEADER in each
+# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
+# If applicable, add the following below this CDDL HEADER, with the
+# fields enclosed by brackets "[]" replaced with your own identifying
+# information: Portions Copyright [yyyy] [name of copyright owner]
+#
+# CDDL HEADER END
+#
+
+#
+# Copyright 2008 Sun Microsystems, Inc.  All rights reserved.
+# Use is subject to license terms.
+#
+
+#
+# Copyright (c) 2013 by Delphix. All rights reserved.
+#
+
+. $STF_SUITE/tests/functional/cache/cache.cfg
+. $STF_SUITE/tests/functional/cache/cache.kshlib
+
+verify_runnable "global"
+
+if datasetexists $TESTPOOL ; then
+       log_must $ZPOOL destroy -f $TESTPOOL
+fi
+if datasetexists $TESTPOOL2 ; then
+       log_must $ZPOOL destroy -f $TESTPOOL2
+fi
+
+log_must $RM -rf $VDIR $VDIR2
+
+log_pass
diff --git a/tests/zfs-tests/tests/functional/cache/setup.ksh b/tests/zfs-tests/tests/functional/cache/setup.ksh
new file mode 100755 (executable)
index 0000000..832dfe9
--- /dev/null
@@ -0,0 +1,45 @@
+#!/bin/ksh -p
+#
+# CDDL HEADER START
+#
+# The contents of this file are subject to the terms of the
+# Common Development and Distribution License (the "License").
+# You may not use this file except in compliance with the License.
+#
+# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
+# or http://www.opensolaris.org/os/licensing.
+# See the License for the specific language governing permissions
+# and limitations under the License.
+#
+# When distributing Covered Code, include this CDDL HEADER in each
+# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
+# If applicable, add the following below this CDDL HEADER, with the
+# fields enclosed by brackets "[]" replaced with your own identifying
+# information: Portions Copyright [yyyy] [name of copyright owner]
+#
+# CDDL HEADER END
+#
+
+#
+# Copyright 2009 Sun Microsystems, Inc.  All rights reserved.
+# Use is subject to license terms.
+#
+
+#
+# Copyright (c) 2013 by Delphix. All rights reserved.
+#
+
+. $STF_SUITE/tests/functional/cache/cache.cfg
+. $STF_SUITE/tests/functional/cache/cache.kshlib
+
+verify_runnable "global"
+
+if ! $(is_physical_device $LDEV) ; then
+       log_unsupported "Only physical disk could be cache device"
+fi
+
+log_must $RM -rf $VDIR $VDIR2
+log_must $MKDIR -p $VDIR $VDIR2
+log_must $MKFILE $SIZE $VDEV $VDEV2
+
+log_pass
diff --git a/tests/zfs-tests/tests/functional/cachefile/Makefile.am b/tests/zfs-tests/tests/functional/cachefile/Makefile.am
new file mode 100644 (file)
index 0000000..4252c70
--- /dev/null
@@ -0,0 +1,8 @@
+pkgdatadir = $(datadir)/@PACKAGE@/zfs-tests/tests/functional/cachefile
+dist_pkgdata_SCRIPTS = \
+       cachefile.cfg \
+       cachefile.kshlib \
+       cachefile_001_pos.ksh \
+       cachefile_002_pos.ksh \
+       cachefile_003_pos.ksh \
+       cachefile_004_pos.ksh
diff --git a/tests/zfs-tests/tests/functional/cachefile/cachefile.cfg b/tests/zfs-tests/tests/functional/cachefile/cachefile.cfg
new file mode 100644 (file)
index 0000000..1379198
--- /dev/null
@@ -0,0 +1,33 @@
+#
+# CDDL HEADER START
+#
+# The contents of this file are subject to the terms of the
+# Common Development and Distribution License (the "License").
+# You may not use this file except in compliance with the License.
+#
+# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
+# or http://www.opensolaris.org/os/licensing.
+# See the License for the specific language governing permissions
+# and limitations under the License.
+#
+# When distributing Covered Code, include this CDDL HEADER in each
+# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
+# If applicable, add the following below this CDDL HEADER, with the
+# fields enclosed by brackets "[]" replaced with your own identifying
+# information: Portions Copyright [yyyy] [name of copyright owner]
+#
+# CDDL HEADER END
+#
+
+#
+# Copyright 2008 Sun Microsystems, Inc.  All rights reserved.
+# Use is subject to license terms.
+#
+
+#
+# Copyright (c) 2013 by Delphix. All rights reserved.
+#
+
+export CPATH="/etc/zfs/zpool.cache"
+export CPATH1=/var/tmp/cachefile.$$
+export CPATH2=$TEST_BASE_DIR/cachefile.$$
diff --git a/tests/zfs-tests/tests/functional/cachefile/cachefile.kshlib b/tests/zfs-tests/tests/functional/cachefile/cachefile.kshlib
new file mode 100644 (file)
index 0000000..27a36af
--- /dev/null
@@ -0,0 +1,47 @@
+#!/bin/ksh -p
+#
+# CDDL HEADER START
+#
+# The contents of this file are subject to the terms of the
+# Common Development and Distribution License (the "License").
+# You may not use this file except in compliance with the License.
+#
+# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
+# or http://www.opensolaris.org/os/licensing.
+# See the License for the specific language governing permissions
+# and limitations under the License.
+#
+# When distributing Covered Code, include this CDDL HEADER in each
+# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
+# If applicable, add the following below this CDDL HEADER, with the
+# fields enclosed by brackets "[]" replaced with your own identifying
+# information: Portions Copyright [yyyy] [name of copyright owner]
+#
+# CDDL HEADER END
+#
+
+#
+# Copyright 2008 Sun Microsystems, Inc.  All rights reserved.
+# Use is subject to license terms.
+#
+
+#
+# Copyright (c) 2013 by Delphix. All rights reserved.
+#
+
+#
+# A function to determine if a given pool name has an entry in cachefile
+# returns 1 if the pool is not in the cache, 0 otherwise.
+function pool_in_cache {
+
+       # checking for the pool name in the strings output of
+       # the given cachefile, default is /etc/zfs/zpool.cache
+       typeset cachefile=${2:-$CPATH}
+
+       RESULT=$($STRINGS $cachefile | $GREP -w $1)
+       if [ -z "$RESULT" ]
+       then
+               return 1
+       fi
+       return 0
+}
diff --git a/tests/zfs-tests/tests/functional/cachefile/cachefile_001_pos.ksh b/tests/zfs-tests/tests/functional/cachefile/cachefile_001_pos.ksh
new file mode 100755 (executable)
index 0000000..0023807
--- /dev/null
@@ -0,0 +1,94 @@
+#!/bin/ksh -p
+#
+# CDDL HEADER START
+#
+# The contents of this file are subject to the terms of the
+# Common Development and Distribution License (the "License").
+# You may not use this file except in compliance with the License.
+#
+# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
+# or http://www.opensolaris.org/os/licensing.
+# See the License for the specific language governing permissions
+# and limitations under the License.
+#
+# When distributing Covered Code, include this CDDL HEADER in each
+# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
+# If applicable, add the following below this CDDL HEADER, with the
+# fields enclosed by brackets "[]" replaced with your own identifying
+# information: Portions Copyright [yyyy] [name of copyright owner]
+#
+# CDDL HEADER END
+#
+
+#
+# Copyright 2008 Sun Microsystems, Inc.  All rights reserved.
+# Use is subject to license terms.
+#
+
+#
+# Copyright (c) 2013 by Delphix. All rights reserved.
+#
+
+. $STF_SUITE/include/libtest.shlib
+. $STF_SUITE/tests/functional/cachefile/cachefile.cfg
+. $STF_SUITE/tests/functional/cachefile/cachefile.kshlib
+
+#
+# DESCRIPTION:
+#
+# Creating a pool with "cachefile" set doesn't update zpool.cache
+#
+# STRATEGY:
+# 1. Create a pool with the cachefile property set
+# 2. Verify that the pool doesn't have an entry in zpool.cache
+# 3. Verify the cachefile property is set
+# 4. Create a pool without the cachefile property
+# 5. Verify the cachefile property isn't set
+# 6. Verify that zpool.cache contains an entry for the pool
+#
+
+function cleanup
+{
+       typeset file
+
+       if poolexists $TESTPOOL ; then
+                destroy_pool $TESTPOOL
+        fi
+       for file in $CPATH1 $CPATH2 ; do
+               if [[ -f $file ]] ; then
+                       log_must $RM $file
+               fi
+       done
+}
+
+verify_runnable "global"
+
+log_assert "Creating a pool with \"cachefile\" set doesn't update zpool.cache"
+log_onexit cleanup
+
+set -A opts "none" "false" "none" \
+       "$CPATH" "true" "-" \
+       "$CPATH1" "true" "$CPATH1" \
+       "$CPATH2" "true" "$CPATH2"
+
+typeset -i i=0
+
+while (( i < ${#opts[*]} )); do
+       log_must $ZPOOL create -o cachefile=${opts[i]} $TESTPOOL $DISKS
+       case ${opts[((i+1))]} in
+               false) log_mustnot pool_in_cache $TESTPOOL
+                       ;;
+               true) log_must pool_in_cache $TESTPOOL ${opts[i]}
+                       ;;
+       esac
+
+       PROP=$(get_pool_prop cachefile $TESTPOOL)
+       if [[ $PROP != ${opts[((i+2))]} ]]; then
+               log_fail "cachefile property not set as expected. " \
+                       "Expect: ${opts[((i+2))]}, Current: $PROP"
+       fi
+       log_must $ZPOOL destroy $TESTPOOL
+       (( i = i + 3 ))
+done
+
+log_pass "Creating a pool with \"cachefile\" set doesn't update zpool.cache"
diff --git a/tests/zfs-tests/tests/functional/cachefile/cachefile_002_pos.ksh b/tests/zfs-tests/tests/functional/cachefile/cachefile_002_pos.ksh
new file mode 100755 (executable)
index 0000000..1680e66
--- /dev/null
@@ -0,0 +1,82 @@
+#!/bin/ksh -p
+#
+# CDDL HEADER START
+#
+# The contents of this file are subject to the terms of the
+# Common Development and Distribution License (the "License").
+# You may not use this file except in compliance with the License.
+#
+# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
+# or http://www.opensolaris.org/os/licensing.
+# See the License for the specific language governing permissions
+# and limitations under the License.
+#
+# When distributing Covered Code, include this CDDL HEADER in each
+# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
+# If applicable, add the following below this CDDL HEADER, with the
+# fields enclosed by brackets "[]" replaced with your own identifying
+# information: Portions Copyright [yyyy] [name of copyright owner]
+#
+# CDDL HEADER END
+#
+
+#
+# Copyright 2009 Sun Microsystems, Inc.  All rights reserved.
+# Use is subject to license terms.
+#
+
+#
+# Copyright (c) 2013 by Delphix. All rights reserved.
+#
+
+. $STF_SUITE/include/libtest.shlib
+. $STF_SUITE/tests/functional/cachefile/cachefile.cfg
+. $STF_SUITE/tests/functional/cachefile/cachefile.kshlib
+
+#
+# DESCRIPTION:
+#
+# Importing a pool with "cachefile" set doesn't update zpool.cache
+#
+# STRATEGY:
+# 1. Create a pool with the cachefile property set
+# 2. Verify the pool doesn't have an entry in zpool.cache
+# 3. Export the pool
+# 4. Import the pool
+# 5. Verify the pool does have an entry in zpool.cache
+# 6. Export the pool
+# 7. Import the pool -o cachefile=<cachefile>
+# 8. Verify the pool doesn't have an entry in zpool.cache
+#
+
+function cleanup
+{
+       if poolexists $TESTPOOL ; then
+                destroy_pool $TESTPOOL
+        fi
+}
+
+verify_runnable "global"
+
+log_assert "Importing a pool with \"cachefile\" set doesn't update zpool.cache"
+log_onexit cleanup
+
+log_must $ZPOOL create -o cachefile=none $TESTPOOL $DISKS
+typeset DEVICEDIR=$(get_device_dir $DISKS)
+log_mustnot pool_in_cache $TESTPOOL
+
+log_must $ZPOOL export $TESTPOOL
+log_must $ZPOOL import -d $DEVICEDIR $TESTPOOL
+log_must pool_in_cache $TESTPOOL
+
+log_must $ZPOOL export $TESTPOOL
+log_must $ZPOOL import -o cachefile=none -d $DEVICEDIR $TESTPOOL
+log_mustnot pool_in_cache $TESTPOOL
+
+log_must $ZPOOL export $TESTPOOL
+log_must $ZPOOL import -o cachefile=$CPATH -d $DEVICEDIR $TESTPOOL
+log_must pool_in_cache $TESTPOOL
+
+log_must $ZPOOL destroy $TESTPOOL
+
+log_pass "Importing a pool with \"cachefile\" set doesn't update zpool.cache"
diff --git a/tests/zfs-tests/tests/functional/cachefile/cachefile_003_pos.ksh b/tests/zfs-tests/tests/functional/cachefile/cachefile_003_pos.ksh
new file mode 100755 (executable)
index 0000000..d79a1a7
--- /dev/null
@@ -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 2008 Sun Microsystems, Inc.  All rights reserved.
+# Use is subject to license terms.
+#
+
+#
+# Copyright (c) 2013 by Delphix. All rights reserved.
+#
+
+. $STF_SUITE/include/libtest.shlib
+. $STF_SUITE/tests/functional/cachefile/cachefile.cfg
+. $STF_SUITE/tests/functional/cachefile/cachefile.kshlib
+
+#
+# DESCRIPTION:
+#
+# Setting altroot=<path> and cachefile=$CPATH for zpool create is succeed
+#
+# STRATEGY:
+# 1. Attempt to create a pool with -o altroot=<path> -o cachefile=<value>
+# 2. Verify the command succeed
+#
+#
+
+TESTDIR=/altdir.$$
+
+function cleanup
+{
+       typeset file
+
+       if poolexists $TESTPOOL ; then
+               destroy_pool $TESTPOOL
+       fi
+
+        for file in $CPATH1 $CPATH2 ; do
+                if [[ -f $file ]] ; then
+                        log_must $RM $file
+                fi
+        done
+
+       if [ -d $TESTDIR ]
+       then
+               $RMDIR $TESTDIR
+       fi
+}
+
+verify_runnable "global"
+
+log_assert "Setting altroot=path and cachefile=$CPATH for zpool create succeed."
+log_onexit cleanup
+
+typeset -i i=0
+
+set -A opts "none" "none" \
+       "$CPATH" "-" \
+       "$CPATH1" "$CPATH1" \
+       "$CPATH2" "$CPATH2"
+
+
+while (( i < ${#opts[*]} )); do
+       log_must $ZPOOL create -o altroot=$TESTDIR -o cachefile=${opts[i]} \
+               $TESTPOOL $DISKS
+       if [[ ${opts[i]} != none ]]; then
+               log_must pool_in_cache $TESTPOOL ${opts[i]}
+       else
+               log_mustnot pool_in_cache $TESTPOOL
+       fi
+
+       PROP=$(get_pool_prop cachefile $TESTPOOL)
+       if [[ $PROP != ${opts[((i+1))]} ]]; then
+               log_fail "cachefile property not set as expected. " \
+                       "Expect: ${opts[((i+1))]}, Current: $PROP"
+       fi
+       log_must $ZPOOL destroy $TESTPOOL
+       (( i = i + 2 ))
+done
+
+log_pass "Setting altroot=path and cachefile=$CPATH for zpool create succeed."
diff --git a/tests/zfs-tests/tests/functional/cachefile/cachefile_004_pos.ksh b/tests/zfs-tests/tests/functional/cachefile/cachefile_004_pos.ksh
new file mode 100755 (executable)
index 0000000..98adfd0
--- /dev/null
@@ -0,0 +1,124 @@
+#!/bin/ksh -p
+#
+# CDDL HEADER START
+#
+# The contents of this file are subject to the terms of the
+# Common Development and Distribution License (the "License").
+# You may not use this file except in compliance with the License.
+#
+# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
+# or http://www.opensolaris.org/os/licensing.
+# See the License for the specific language governing permissions
+# and limitations under the License.
+#
+# When distributing Covered Code, include this CDDL HEADER in each
+# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
+# If applicable, add the following below this CDDL HEADER, with the
+# fields enclosed by brackets "[]" replaced with your own identifying
+# information: Portions Copyright [yyyy] [name of copyright owner]
+#
+# CDDL HEADER END
+#
+
+#
+# Copyright 2009 Sun Microsystems, Inc.  All rights reserved.
+# Use is subject to license terms.
+#
+
+#
+# Copyright (c) 2013 by Delphix. All rights reserved.
+#
+
+. $STF_SUITE/include/libtest.shlib
+. $STF_SUITE/tests/functional/cachefile/cachefile.cfg
+. $STF_SUITE/tests/functional/cachefile/cachefile.kshlib
+
+#
+# DESCRIPTION:
+#      Verify set, export and destroy when cachefile is set on pool.
+#
+# STRATEGY:
+#      1. Create two pools with one same cahcefile1.
+#      2. Set cachefile of the two pools to another same cachefile2.
+#      3. Verify cachefile1 not exist.
+#      4. Export the two pools.
+#      5. Verify cachefile2 not exist.
+#      6. Import the two pools and set cachefile to cachefile2.
+#      7. Destroy the two pools.
+#      8. Verify cachefile2 not exist.
+#
+
+verify_runnable "global"
+
+function cleanup
+{
+       poolexists $TESTPOOL1 && destroy_pool $TESTPOOL1
+       poolexists $TESTPOOL2 && destroy_pool $TESTPOOL2
+
+       mntpnt=$(get_prop mountpoint $TESTPOOL)
+       typeset -i i=0
+       while ((i < 2)); do
+               if [[ -e $mntpnt/vdev$i ]]; then
+                       log_must $RM -f $mntpnt/vdev$i
+               fi
+               ((i += 1))
+       done
+
+       if poolexists $TESTPOOL ; then
+               destroy_pool $TESTPOOL
+       fi
+
+       for file in $CPATH1 $CPATH2 ; do
+               if [[ -f $file ]] ; then
+                       log_must $RM $file
+               fi
+       done
+}
+
+
+log_assert "Verify set, export and destroy when cachefile is set on pool."
+log_onexit cleanup
+
+log_must $ZPOOL create $TESTPOOL $DISKS
+
+mntpnt=$(get_prop mountpoint $TESTPOOL)
+typeset -i i=0
+while ((i < 2)); do
+       log_must $MKFILE 64M $mntpnt/vdev$i
+       eval vdev$i=$mntpnt/vdev$i
+       ((i += 1))
+done
+
+log_must $ZPOOL create -o cachefile=$CPATH1 $TESTPOOL1 $vdev0
+log_must pool_in_cache $TESTPOOL1 $CPATH1
+log_must $ZPOOL create -o cachefile=$CPATH1 $TESTPOOL2 $vdev1
+log_must pool_in_cache $TESTPOOL2 $CPATH1
+
+log_must $ZPOOL set cachefile=$CPATH2 $TESTPOOL1
+log_must pool_in_cache $TESTPOOL1 $CPATH2
+log_must $ZPOOL set cachefile=$CPATH2 $TESTPOOL2
+log_must pool_in_cache $TESTPOOL2 $CPATH2
+if [[ -f $CPATH1 ]]; then
+       log_fail "Verify set when cachefile is set on pool."
+fi
+
+log_must $ZPOOL export $TESTPOOL1
+log_must $ZPOOL export $TESTPOOL2
+if [[ -f $CPATH2 ]]; then
+       log_fail "Verify export when cachefile is set on pool."
+fi
+
+log_must $ZPOOL import -d $mntpnt $TESTPOOL1
+log_must $ZPOOL set cachefile=$CPATH2 $TESTPOOL1
+log_must pool_in_cache $TESTPOOL1 $CPATH2
+log_must $ZPOOL import -d $mntpnt $TESTPOOL2
+log_must $ZPOOL set cachefile=$CPATH2 $TESTPOOL2
+log_must pool_in_cache $TESTPOOL2 $CPATH2
+
+log_must $ZPOOL destroy $TESTPOOL1
+log_must $ZPOOL destroy $TESTPOOL2
+if [[ -f $CPATH2 ]]; then
+       log_fail "Verify destroy when cachefile is set on pool."
+fi
+
+log_pass "Verify set, export and destroy when cachefile is set on pool."
diff --git a/tests/zfs-tests/tests/functional/casenorm/Makefile.am b/tests/zfs-tests/tests/functional/casenorm/Makefile.am
new file mode 100644 (file)
index 0000000..00a19c7
--- /dev/null
@@ -0,0 +1,22 @@
+pkgdatadir = $(datadir)/@PACKAGE@/zfs-tests/tests/functional/casenorm
+dist_pkgdata_SCRIPTS = \
+       setup.ksh \
+       cleanup.ksh \
+       case_all_values.ksh \
+       casenorm.cfg \
+       casenorm.kshlib \
+       insensitive_formd_delete.ksh \
+       insensitive_formd_lookup.ksh \
+       insensitive_none_delete.ksh \
+       insensitive_none_lookup.ksh \
+       mixed_formd_delete.ksh \
+       mixed_formd_lookup_ci.ksh \
+       mixed_formd_lookup.ksh \
+       mixed_none_delete.ksh \
+       mixed_none_lookup_ci.ksh \
+       mixed_none_lookup.ksh \
+       norm_all_values.ksh \
+       sensitive_formd_delete.ksh \
+       sensitive_formd_lookup.ksh \
+       sensitive_none_delete.ksh \
+       sensitive_none_lookup.ksh
diff --git a/tests/zfs-tests/tests/functional/casenorm/case_all_values.ksh b/tests/zfs-tests/tests/functional/casenorm/case_all_values.ksh
new file mode 100755 (executable)
index 0000000..af23e9d
--- /dev/null
@@ -0,0 +1,42 @@
+#!/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 2015 Nexenta Systems, Inc.  All rights reserved.
+#
+
+. $STF_SUITE/tests/functional/casenorm/casenorm.kshlib
+
+# DESCRIPTION:
+# Check that we can create FS with any supported casesensitivity value.
+#
+# STRATEGY:
+# For all suported casesensitivity values:
+# 1. Create FS with given casesensitivity value.
+
+verify_runnable "global"
+
+function cleanup
+{
+       destroy_testfs
+}
+
+log_onexit cleanup
+log_assert "Can create FS with any supported casesensitivity value"
+
+for caseval in sensitive insensitive mixed; do
+       create_testfs "-o casesensitivity=$caseval"
+       destroy_testfs
+done
+
+log_pass "Can create FS with any supported casesensitivity value"
diff --git a/tests/zfs-tests/tests/functional/casenorm/casenorm.cfg b/tests/zfs-tests/tests/functional/casenorm/casenorm.cfg
new file mode 100644 (file)
index 0000000..ffad2fb
--- /dev/null
@@ -0,0 +1,27 @@
+#
+# This file and its contents are supplied under the terms of the
+# Common Development and Distribution License ("CDDL"), version 1.0.
+# You may only use this file in accordance with the terms of version
+# 1.0 of the CDDL.
+#
+# A full copy of the text of the CDDL should have accompanied this
+# source.  A copy of the CDDL is also available via the Internet at
+# http://www.illumos.org/license/CDDL.
+#
+
+#
+# Copyright 2015 Nexenta Systems, Inc.  All rights reserved.
+#
+
+NAME_C_ORIG=$($ECHO 'F\0303\0257L\0303\0253N\0303\0204m\0303\0253')
+NAME_C_UPPER=$($ECHO 'F\0303\0217L\0303\0213N\0303\0204M\0303\0213')
+NAME_C_LOWER=$($ECHO 'f\0303\0257l\0303\0253n\0303\0244m\0303\0253')
+NAME_D_ORIG=$($ECHO 'Fi\0314\0210Le\0314\0210NA\0314\0210me\0314\0210')
+NAME_D_UPPER=$($ECHO 'FI\0314\0210LE\0314\0210NA\0314\0210ME\0314\0210')
+NAME_D_LOWER=$($ECHO 'fi\0314\0210le\0314\0210na\0314\0210me\0314\0210')
+NAMES_ORIG="$NAME_C_ORIG $NAME_D_ORIG"
+NAMES_UPPER="$NAME_C_UPPER $NAME_D_UPPER"
+NAMES_LOWER="$NAME_C_LOWER $NAME_D_LOWER"
+NAMES_C="$NAME_C_ORIG $NAME_C_UPPER $NAME_C_LOWER"
+NAMES_D="$NAME_D_ORIG $NAME_D_UPPER $NAME_D_LOWER"
+NAMES_ALL="$NAMES_C $NAMES_D"
diff --git a/tests/zfs-tests/tests/functional/casenorm/casenorm.kshlib b/tests/zfs-tests/tests/functional/casenorm/casenorm.kshlib
new file mode 100755 (executable)
index 0000000..ff1206f
--- /dev/null
@@ -0,0 +1,119 @@
+#
+# 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 2015 Nexenta Systems, Inc.  All rights reserved.
+#
+
+. $STF_SUITE/include/libtest.shlib
+. $STF_SUITE/tests/functional/casenorm/casenorm.cfg
+
+function create_testfs
+{
+       typeset opts=$1
+
+       $RM -rf $TESTDIR || log_unresolved Could not remove $TESTDIR
+       $MKDIR -p $TESTDIR || log_unresolved Could not create $TESTDIR
+
+       log_must $ZFS create $opts $TESTPOOL/$TESTFS
+       log_must $ZFS set mountpoint=$TESTDIR $TESTPOOL/$TESTFS
+}
+
+function destroy_testfs
+{
+       if datasetexists $TESTPOOL/$TESTFS ; then
+               log_must $ZFS destroy -f $TESTPOOL/$TESTFS
+               $RM -rf $TESTDIR || log_unresolved Could not remove $TESTDIR
+       fi
+}
+
+function create_file
+{
+       typeset name=$TESTDIR/$1
+
+       $ECHO $name > $name
+}
+
+function delete_file
+{
+       typeset name=$TESTDIR/$1
+
+       $RM $name >/dev/null 2>&1
+
+       if [[ $? -ne 0 ]] ; then
+               return 1
+       fi
+
+       if [[ -f $name ]] ; then
+               return 2
+       fi
+}
+
+function lookup_file
+{
+       typeset name=$1
+
+       $ZLOOK -l $TESTDIR $name >/dev/null 2>&1
+}
+
+function lookup_file_ci
+{
+       typeset name=$1
+
+       $ZLOOK -il $TESTDIR $name >/dev/null 2>&1
+}
+
+function lookup_any
+{
+       for name in $NAMES_ALL ; do
+               lookup_file $name
+               if [[ $? -eq 0 ]] ; then
+                       return 0
+               fi
+       done
+
+       return 1
+}
+
+function switch_norm
+{
+       typeset norm=$(get_norm $1)
+
+       if [[ $norm == "C" ]] ; then
+               print "D"
+       else
+               print "C"
+       fi
+}
+
+function get_norm
+{
+       if [[ "${NAMES_C#*$1}" != "${NAMES_C}" ]] ; then
+               print "C"
+       elif [[ "${NAMES_D#*$1}" != "${NAMES_D}" ]] ; then
+               print "D"
+       else
+               return 1
+       fi
+}
+
+function get_case
+{
+       if [[ ${NAMES_UPPER#*$1} != ${NAMES_UPPER} ]] ; then
+               print "UPPER"
+       elif [[ ${NAMES_LOWER#*$1} != ${NAMES_LOWER} ]] ; then
+               print "LOWER"
+       elif [[ ${NAMES_ORIG#*$1} != ${NAMES_ORIG} ]] ; then
+               print "ORIG"
+       else
+               return 1
+       fi
+}
diff --git a/tests/zfs-tests/tests/functional/casenorm/cleanup.ksh b/tests/zfs-tests/tests/functional/casenorm/cleanup.ksh
new file mode 100755 (executable)
index 0000000..98af72d
--- /dev/null
@@ -0,0 +1,20 @@
+#!/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 2015 Nexenta Systems, Inc.  All rights reserved.
+#
+
+. $STF_SUITE/include/libtest.shlib
+
+default_cleanup
diff --git a/tests/zfs-tests/tests/functional/casenorm/insensitive_formd_delete.ksh b/tests/zfs-tests/tests/functional/casenorm/insensitive_formd_delete.ksh
new file mode 100755 (executable)
index 0000000..00caea9
--- /dev/null
@@ -0,0 +1,53 @@
+#!/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 2015 Nexenta Systems, Inc.  All rights reserved.
+#
+
+. $STF_SUITE/tests/functional/casenorm/casenorm.kshlib
+
+# DESCRIPTION:
+# For the filesystem with casesensitivity=insensitive, normalization=formD,
+# check that file can be deleted using any name form.
+#
+# STRATEGY:
+# For each c/n name form:
+# 1. Create file with given c/n name form.
+# 2. Check that deleting file using other c/n name forms succeeds.
+# 3. Check that file isn't accessible by any c/n name form.
+
+verify_runnable "global"
+
+function cleanup
+{
+       destroy_testfs
+}
+
+log_onexit cleanup
+log_assert "CI-UN FS: delete succeeds using any name form"
+
+# Can delete using any case/normalization form
+create_testfs "-o casesensitivity=insensitive -o normalization=formD"
+
+for name1 in $NAMES_ALL ; do
+       for name2 in $NAMES_ALL ; do
+               log_must create_file $name1
+               log_must delete_file $name2
+               log_mustnot lookup_any
+       done
+done
+
+destroy_testfs
+
+log_pass "CI-UN FS: delete succeeds using any name form"
diff --git a/tests/zfs-tests/tests/functional/casenorm/insensitive_formd_lookup.ksh b/tests/zfs-tests/tests/functional/casenorm/insensitive_formd_lookup.ksh
new file mode 100755 (executable)
index 0000000..d284313
--- /dev/null
@@ -0,0 +1,51 @@
+#!/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 2015 Nexenta Systems, Inc.  All rights reserved.
+#
+
+. $STF_SUITE/tests/functional/casenorm/casenorm.kshlib
+
+# DESCRIPTION:
+# For the filesystem with casesensitivity=insensitive, normalization=formD,
+# check that lookup succeds using any name form.
+#
+# STRATEGY:
+# For each c/n name form:
+# 1. Create file with given c/n name form.
+# 2. Check that lookup succeeds for any other c/n name form.
+
+verify_runnable "global"
+
+function cleanup
+{
+       destroy_testfs
+}
+
+log_onexit cleanup
+log_assert "CI-UN FS: lookup succeeds using any name form"
+
+create_testfs "-o casesensitivity=insensitive -o normalization=formD"
+
+for name1 in $NAMES_ALL ; do
+       log_must create_file $name1
+       for name2 in $NAMES_ALL ; do
+               log_must lookup_file $name2
+       done
+       delete_file $name1
+done
+
+destroy_testfs
+
+log_pass "CI-UN FS: lookup succeeds using any name form"
diff --git a/tests/zfs-tests/tests/functional/casenorm/insensitive_none_delete.ksh b/tests/zfs-tests/tests/functional/casenorm/insensitive_none_delete.ksh
new file mode 100755 (executable)
index 0000000..51f6a3c
--- /dev/null
@@ -0,0 +1,71 @@
+#!/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 2015 Nexenta Systems, Inc.  All rights reserved.
+#
+
+. $STF_SUITE/tests/functional/casenorm/casenorm.kshlib
+
+# DESCRIPTION:
+# For the filesystem with casesensitivity=insensitive, normalization=none,
+# check that delete succeeds if (norm=same).
+#
+# STRATEGY:
+# For each c/n name form:
+# 1. Create file with given c/n name form.
+# 2. Check that delete succeeds if (norm=same).
+# 3. Check that file is no longer accessible using any name form.
+# 4. Check that delete fails if (norm=other).
+
+verify_runnable "global"
+
+function cleanup
+{
+       destroy_testfs
+}
+
+log_onexit cleanup
+log_assert "CI-not-UN FS: delete succeeds if (norm=same)"
+
+create_testfs "-o casesensitivity=insensitive -o normalization=none"
+
+for name1 in $NAMES_C ; do
+       for name2 in $NAMES_C ; do
+               log_must create_file $name1
+               log_must delete_file $name2
+               log_mustnot lookup_any
+       done
+       for name2 in $NAMES_D ; do
+               log_must create_file $name1
+               log_mustnot delete_file $name2
+               delete_file $name1
+       done
+done
+
+for name1 in $NAMES_D ; do
+       for name2 in $NAMES_D ; do
+               log_must create_file $name1
+               log_must delete_file $name2
+               log_mustnot lookup_any
+       done
+       for name2 in $NAMES_C ; do
+               log_must create_file $name1
+               log_mustnot delete_file $name2
+               delete_file $name1
+       done
+done
+
+destroy_testfs
+
+log_pass "CI-not-UN FS: delete succeeds if (norm=same)"
diff --git a/tests/zfs-tests/tests/functional/casenorm/insensitive_none_lookup.ksh b/tests/zfs-tests/tests/functional/casenorm/insensitive_none_lookup.ksh
new file mode 100755 (executable)
index 0000000..12b7951
--- /dev/null
@@ -0,0 +1,66 @@
+#!/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 2015 Nexenta Systems, Inc.  All rights reserved.
+#
+
+. $STF_SUITE/tests/functional/casenorm/casenorm.kshlib
+
+# DESCRIPTION:
+# For the filesystem with casesensitivity=insensitive, normalization=none,
+# check that lookup succeeds only if (norm=same)
+#
+# STRATEGY:
+# For each c/n name form:
+# 1. Create file with given c/n name form.
+# 2. Check that lookup succeeds if (norm=same).
+# 3. Check that lookup fails if (norm=other).
+
+verify_runnable "global"
+
+function cleanup
+{
+       destroy_testfs
+}
+
+log_onexit cleanup
+log_assert "CI-not-UN FS: lookup succeeds only if (norm=same)"
+
+create_testfs "-o casesensitivity=insensitive -o normalization=none"
+
+for name1 in $NAMES_C ; do
+       log_must create_file $name1
+       for name2 in $NAMES_C ; do
+               log_must lookup_file $name2
+       done
+       for name2 in $NAMES_D; do
+               log_mustnot lookup_file $name2
+       done
+       delete_file $name1
+done
+
+for name1 in $NAMES_D ; do
+       log_must create_file $name1
+       for name2 in $NAMES_D ; do
+               log_must lookup_file $name2
+       done
+       for name2 in $NAMES_C; do
+               log_mustnot lookup_file $name2
+       done
+       delete_file $name1
+done
+
+destroy_testfs
+
+log_pass "CI-not-UN FS: lookup succeeds only if (norm=same)"
diff --git a/tests/zfs-tests/tests/functional/casenorm/mixed_formd_delete.ksh b/tests/zfs-tests/tests/functional/casenorm/mixed_formd_delete.ksh
new file mode 100755 (executable)
index 0000000..451acbb
--- /dev/null
@@ -0,0 +1,59 @@
+#!/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 2015 Nexenta Systems, Inc.  All rights reserved.
+#
+
+. $STF_SUITE/tests/functional/casenorm/casenorm.kshlib
+
+# DESCRIPTION:
+# For the filesystem with casesensitivity=mixed, normalization=formD,
+# check that delete succeeds if (case=same).
+#
+# STRATEGY:
+# For each c/n name form:
+# 1. Create file with given c/n name form.
+# 2. Check that delete succeeds if (case=same).
+# 3. Check that file is no longer accessible using any name form.
+# 4. Check that delete fails for all other name forms other than original.
+
+verify_runnable "global"
+
+function cleanup
+{
+       destroy_testfs
+}
+
+log_onexit cleanup
+log_assert "CM-UN FS: delete succeeds if (case=same)"
+
+create_testfs "-o casesensitivity=mixed -o normalization=formD"
+
+for name1 in $NAMES_ALL; do
+       typeset -n namen=NAME_$(switch_norm $name1)_$(get_case $name1)
+       for name2 in $NAMES_ALL; do
+               log_must create_file $name1
+               if [[ $name2 == $namen || $name2 == $name1 ]]; then
+                       log_must delete_file $name2
+                       log_mustnot lookup_any
+               else
+                       log_mustnot delete_file $name2
+               fi
+               delete_file $name1
+       done
+done
+
+destroy_testfs
+
+log_pass "CM-UN FS: delete succeeds if (case=same)"
diff --git a/tests/zfs-tests/tests/functional/casenorm/mixed_formd_lookup.ksh b/tests/zfs-tests/tests/functional/casenorm/mixed_formd_lookup.ksh
new file mode 100755 (executable)
index 0000000..105415d
--- /dev/null
@@ -0,0 +1,56 @@
+#!/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 2015 Nexenta Systems, Inc.  All rights reserved.
+#
+
+. $STF_SUITE/tests/functional/casenorm/casenorm.kshlib
+
+# DESCRIPTION:
+# For the filesystem with casesensitivity=mixed, normalization=formD,
+# check that lookup succeeds only if (case=same).
+#
+# STRATEGY:
+# For each c/n name form:
+# 1. Create file with given c/n name form.
+# 2. Check that lookup succeeds if (case=same).
+# 3. Check that lookup fails if (case=other).
+
+verify_runnable "global"
+
+function cleanup
+{
+       destroy_testfs
+}
+
+log_onexit cleanup
+log_assert "CM-UN FS: lookup succeeds if (case=same)"
+
+create_testfs "-o casesensitivity=mixed -o normalization=formD"
+
+for name1 in $NAMES_ALL; do
+       log_must create_file $name1
+       for name2 in $NAMES_ALL; do
+               if [[ $(get_case $name2) == $(get_case $name1) ]]; then
+                       log_must lookup_file $name2
+               else
+                       log_mustnot lookup_file $name2
+               fi
+       done
+       delete_file $name1
+done
+
+destroy_testfs
+
+log_pass "CM-UN FS: lookup succeeds if (case=same)"
diff --git a/tests/zfs-tests/tests/functional/casenorm/mixed_formd_lookup_ci.ksh b/tests/zfs-tests/tests/functional/casenorm/mixed_formd_lookup_ci.ksh
new file mode 100755 (executable)
index 0000000..50827ff
--- /dev/null
@@ -0,0 +1,51 @@
+#!/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 2015 Nexenta Systems, Inc.  All rights reserved.
+#
+
+. $STF_SUITE/tests/functional/casenorm/casenorm.kshlib
+
+# DESCRIPTION:
+# For the filesystem with casesensitivity=insensitive, normalization=formD,
+# check that CI lookup succeeds using any name form.
+#
+# STRATEGY:
+# For each c/n name form:
+# 1. Create file with given c/n name form.
+# 2. Check that CI lookup succeeds for any c/n name form.
+
+verify_runnable "global"
+
+function cleanup
+{
+       destroy_testfs
+}
+
+log_onexit cleanup
+log_assert "CM-UN FS: CI lookup succeeds using any name form"
+
+create_testfs "-o casesensitivity=mixed -o normalization=formD"
+
+for name1 in $NAMES_ALL ; do
+       log_must create_file $name1
+       for name2 in $NAMES_ALL ; do
+               log_must lookup_file_ci $name2
+       done
+       delete_file $name1
+done
+
+destroy_testfs
+
+log_pass "CM-UN FS: CI lookup succeeds using any name form"
diff --git a/tests/zfs-tests/tests/functional/casenorm/mixed_none_delete.ksh b/tests/zfs-tests/tests/functional/casenorm/mixed_none_delete.ksh
new file mode 100755 (executable)
index 0000000..708fea8
--- /dev/null
@@ -0,0 +1,56 @@
+#!/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 2015 Nexenta Systems, Inc.  All rights reserved.
+#
+
+. $STF_SUITE/tests/functional/casenorm/casenorm.kshlib
+
+# DESCRIPTION:
+# For the filesystem with casesensitivity=mixed, normalization=none,
+# check that delete succeeds only if (case=same and norm=same).
+#
+# STRATEGY:
+# For each c/n name form:
+# 1. Create file in given c/n name form.
+# 2. Check that delete fails for all other name forms.
+# 3. Check that delete succeeds if (case=same and norm=same).
+# 4. Check that file is no longer accessible by any name form.
+
+verify_runnable "global"
+
+function cleanup
+{
+       destroy_testfs
+}
+
+log_onexit cleanup
+log_assert "CM-not-UN FS: delete succeeds only if using exact name form"
+
+create_testfs "-o casesensitivity=mixed -o normalization=none"
+
+for name1 in $NAMES_ALL ; do
+       log_must create_file $name1
+       for name2 in $NAMES_ALL ; do
+               if [[ $name2 != $name1 ]] ; then
+                       log_mustnot delete_file $name2
+               fi
+       done
+       delete_file $name1
+       log_mustnot lookup_any
+done
+
+destroy_testfs
+
+log_pass "CM-not-UN FS: delete succeeds only if using exact name form"
diff --git a/tests/zfs-tests/tests/functional/casenorm/mixed_none_lookup.ksh b/tests/zfs-tests/tests/functional/casenorm/mixed_none_lookup.ksh
new file mode 100755 (executable)
index 0000000..12d8495
--- /dev/null
@@ -0,0 +1,53 @@
+#!/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 2015 Nexenta Systems, Inc.  All rights reserved.
+#
+
+. $STF_SUITE/tests/functional/casenorm/casenorm.kshlib
+
+# DESCRIPTION:
+# For the filesystem with casesensitivity=mixed, normalization=none,
+# check that lookup succeeds only if (case=same and norm=same).
+#
+# STRATEGY:
+# For each c/n name form:
+# 1. Create file with given c/n name form.
+# 2. Check that lookup fails for all other c/n name forms.
+
+verify_runnable "global"
+
+function cleanup
+{
+       destroy_testfs
+}
+
+log_onexit cleanup
+log_assert "CM-not-UN FS: lookup succeeds only if using exact name form"
+
+create_testfs "-o casesensitivity=mixed -o normalization=none"
+
+for name1 in $NAMES_ALL; do
+       for name2 in $NAMES_ALL; do
+               log_must create_file $name1
+               if [[ $name2 != $name1 ]]; then
+                       log_mustnot lookup_file $name2
+               fi
+               delete_file $name1
+       done
+done
+
+destroy_testfs
+
+log_pass "CM-not-UN FS: lookup succeeds only if using exact name form"
diff --git a/tests/zfs-tests/tests/functional/casenorm/mixed_none_lookup_ci.ksh b/tests/zfs-tests/tests/functional/casenorm/mixed_none_lookup_ci.ksh
new file mode 100755 (executable)
index 0000000..c798ec7
--- /dev/null
@@ -0,0 +1,66 @@
+#!/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 2015 Nexenta Systems, Inc.  All rights reserved.
+#
+
+. $STF_SUITE/tests/functional/casenorm/casenorm.kshlib
+
+# DESCRIPTION:
+# For the filesystem with casesensitivity=mixed, normalization=none,
+# check that CI lookup succeeds only if (norm=same).
+#
+# STRATEGY:
+# For each c/n name form:
+# 1. Create file with given c/n name form.
+# 2. Check that CI lookup succeeds if (norm=same).
+# 3. Check that CI lookup fails if (norm=other).
+
+verify_runnable "global"
+
+function cleanup
+{
+       destroy_testfs
+}
+
+log_onexit cleanup
+log_assert "CM-not-UN FS: CI lookup succeeds only if (norm=same)"
+
+create_testfs "-o casesensitivity=mixed -o normalization=none"
+
+for name1 in $NAMES_C ; do
+       log_must create_file $name1
+       for name2 in $NAMES_C ; do
+               log_must lookup_file_ci $name2
+       done
+       for name2 in $NAMES_D; do
+               log_mustnot lookup_file_ci $name2
+       done
+       delete_file $name1
+done
+
+for name1 in $NAMES_D ; do
+       log_must create_file $name1
+       for name2 in $NAMES_D ; do
+               log_must lookup_file_ci $name2
+       done
+       for name2 in $NAMES_C; do
+               log_mustnot lookup_file_ci $name2
+       done
+       delete_file $name1
+done
+
+destroy_testfs
+
+log_pass "CM-not-UN FS: CI lookup succeeds only if (norm=same)"
diff --git a/tests/zfs-tests/tests/functional/casenorm/norm_all_values.ksh b/tests/zfs-tests/tests/functional/casenorm/norm_all_values.ksh
new file mode 100755 (executable)
index 0000000..90e625c
--- /dev/null
@@ -0,0 +1,57 @@
+#!/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 2015 Nexenta Systems, Inc.  All rights reserved.
+#
+
+. $STF_SUITE/tests/functional/casenorm/casenorm.kshlib
+
+# DESCRIPTION:
+# Check that we can create FS with all supported normalization forms.
+#
+# STRATEGY:
+# 1. Create FS with all supported normalization forms.
+# 2. Check that utf8only is set on except for normalization=none.
+# 3. Check that it's not possible to create FS with utf8only=off
+#    and normalization other than none.
+
+verify_runnable "global"
+
+function cleanup
+{
+       destroy_testfs
+}
+
+log_onexit cleanup
+log_assert "Can create FS with all supported normalization forms"
+
+for form in none formC formD formKC formKD; do
+       create_testfs "-o normalization=$form"
+       if [[ $form != "none" ]] ; then
+               utf8only=$($ZFS get -H -o value utf8only $TESTPOOL/$TESTFS)
+               if [[ $utf8only != "on" ]]; then
+                       log_fail "Turning on normalization didn't set " \
+                           "utf8only to on"
+               fi
+       fi
+       destroy_testfs
+done
+
+for form in formC formD formKC formKD; do
+       log_mustnot $ZFS create -o utf8only=off -o normalization=$form \
+           $TESTPOOL/$TESTFS
+       destroy_testfs
+done
+
+log_pass "Can create FS with all supported normalization forms"
diff --git a/tests/zfs-tests/tests/functional/casenorm/sensitive_formd_delete.ksh b/tests/zfs-tests/tests/functional/casenorm/sensitive_formd_delete.ksh
new file mode 100755 (executable)
index 0000000..285bd4e
--- /dev/null
@@ -0,0 +1,59 @@
+#!/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 2015 Nexenta Systems, Inc.  All rights reserved.
+#
+
+. $STF_SUITE/tests/functional/casenorm/casenorm.kshlib
+
+# DESCRIPTION:
+# For the filesystem with casesensitivity=sensitive, normalization=formD,
+# check that delete succeeds if (case=same).
+#
+# STRATEGY:
+# For each c/n name form:
+# 1. Create file with given c/n name form.
+# 2. Check that delete succeeds if (case=same).
+# 3. Check that file is no longer accessible using any name form.
+# 4. Check that delete fails for all other name forms.
+
+verify_runnable "global"
+
+function cleanup
+{
+       destroy_testfs
+}
+
+log_onexit cleanup
+log_assert "CS-UN FS: delete succeeds if (case=same)"
+
+create_testfs "-o casesensitivity=sensitive -o normalization=formD"
+
+for name1 in $NAMES_ALL ; do
+       typeset -n namen=NAME_$(switch_norm $name1)_$(get_case $name1)
+       for name2 in $NAMES_ALL ; do
+               log_must create_file $name1
+               if [[ $name2 == $namen || $name2 == $name1 ]] ; then
+                       log_must delete_file $name2
+                       log_mustnot lookup_any
+               else
+                       log_mustnot delete_file $name2
+               fi
+               delete_file $name1
+       done
+done
+
+destroy_testfs
+
+log_pass "CS-UN FS: delete succeeds if (case=same)"
diff --git a/tests/zfs-tests/tests/functional/casenorm/sensitive_formd_lookup.ksh b/tests/zfs-tests/tests/functional/casenorm/sensitive_formd_lookup.ksh
new file mode 100755 (executable)
index 0000000..d00c7b5
--- /dev/null
@@ -0,0 +1,56 @@
+#!/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 2015 Nexenta Systems, Inc.  All rights reserved.
+#
+
+. $STF_SUITE/tests/functional/casenorm/casenorm.kshlib
+
+# DESCRIPTION:
+# For the filesystem with casesensitivity=sensitive, normalization=formD,
+# check that lookup only if (case=same).
+#
+# STRATEGY:
+# For each c/n name form:
+# 1. Create file with given c/n name form.
+# 2. Check that lookup succeeds if (case=same).
+# 3. Check that lookup fails if (case=other).
+
+verify_runnable "global"
+
+function cleanup
+{
+       destroy_testfs
+}
+
+log_onexit cleanup
+log_assert "CS-UN FS: lookup succeeds if (case=same)"
+
+create_testfs "-o casesensitivity=sensitive -o normalization=formD"
+
+for name1 in $NAMES_ALL; do
+       log_must create_file $name1
+       for name2 in $NAMES_ALL; do
+               if [[ $(get_case $name2) == $(get_case $name1) ]]; then
+                       log_must lookup_file $name2
+               else
+                       log_mustnot lookup_file $name2
+               fi
+       done
+       delete_file $name1
+done
+
+destroy_testfs
+
+log_pass "CS-UN FS: lookup succeeds if (case=same)"
diff --git a/tests/zfs-tests/tests/functional/casenorm/sensitive_none_delete.ksh b/tests/zfs-tests/tests/functional/casenorm/sensitive_none_delete.ksh
new file mode 100755 (executable)
index 0000000..addebcd
--- /dev/null
@@ -0,0 +1,56 @@
+#!/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 2015 Nexenta Systems, Inc.  All rights reserved.
+#
+
+. $STF_SUITE/tests/functional/casenorm/casenorm.kshlib
+
+# DESCRIPTION:
+# For the filesystem with casesensitivity=sensitive, normalization=none,
+# check that delete succeeds only if (case=same and norm=same).
+#
+# STRATEGY:
+# For each c/n name form:
+# 1. Create file in given c/n name form.
+# 2. Check that delete fails for all other name forms.
+# 3. Check that delete succeeds if (case=same and norm=same).
+# 4. Check that file is no longer accessible by any name form.
+
+verify_runnable "global"
+
+function cleanup
+{
+       destroy_testfs
+}
+
+log_onexit cleanup
+log_assert "CS-not-UN FS: delete succeeds only if using exact name form"
+
+create_testfs "-o casesensitivity=sensitive -o normalization=none"
+
+for name1 in $NAMES_ALL ; do
+       log_must create_file $name1
+       for name2 in $NAMES_ALL ; do
+               if [[ $name2 != $name1 ]] ; then
+                       log_mustnot delete_file $name2
+               fi
+       done
+       delete_file $name1
+       log_mustnot lookup_any
+done
+
+destroy_testfs
+
+log_pass "CS-not-UN FS: delete succeeds only if using exact name form"
diff --git a/tests/zfs-tests/tests/functional/casenorm/sensitive_none_lookup.ksh b/tests/zfs-tests/tests/functional/casenorm/sensitive_none_lookup.ksh
new file mode 100755 (executable)
index 0000000..b945d81
--- /dev/null
@@ -0,0 +1,53 @@
+#!/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 2015 Nexenta Systems, Inc.  All rights reserved.
+#
+
+. $STF_SUITE/tests/functional/casenorm/casenorm.kshlib
+
+# DESCRIPTION:
+# For the filesystem with casesensitivity=sensitive, normalization=none,
+# check that lookup succeeds only if (case=same and norm=same).
+#
+# STRATEGY:
+# For each c/n name form:
+# 1. Create file with given c/n name form.
+# 2. Check that lookup fails for all other c/n name forms.
+
+verify_runnable "global"
+
+function cleanup
+{
+       destroy_testfs
+}
+
+log_onexit cleanup
+log_assert "CS-not-UN FS: lookup succeeds only if using exact name form"
+
+create_testfs "-o casesensitivity=sensitive -o normalization=none"
+
+for name1 in $NAMES_ALL; do
+       for name2 in $NAMES_ALL; do
+               log_must create_file $name1
+               if [[ $name2 != $name1 ]]; then
+                       log_mustnot lookup_file $name2
+               fi
+               delete_file $name1
+       done
+done
+
+destroy_testfs
+
+log_pass "CS-not-UN FS: lookup succeeds only if using exact name form"
diff --git a/tests/zfs-tests/tests/functional/casenorm/setup.ksh b/tests/zfs-tests/tests/functional/casenorm/setup.ksh
new file mode 100755 (executable)
index 0000000..b6c8498
--- /dev/null
@@ -0,0 +1,23 @@
+#!/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 2015 Nexenta Systems, Inc.  All rights reserved.
+#
+
+. $STF_SUITE/include/libtest.shlib
+
+verify_runnable "global"
+DISK=${DISKS%% *}
+log_must $ZPOOL create $TESTPOOL $DISK
+log_pass
diff --git a/tests/zfs-tests/tests/functional/clean_mirror/Makefile.am b/tests/zfs-tests/tests/functional/clean_mirror/Makefile.am
new file mode 100644 (file)
index 0000000..2e37147
--- /dev/null
@@ -0,0 +1,10 @@
+pkgdatadir = $(datadir)/@PACKAGE@/zfs-tests/tests/functional/clean_mirror
+dist_pkgdata_SCRIPTS = \
+       clean_mirror_common.kshlib \
+       default.cfg \
+        cleanup.ksh \
+       setup.ksh \
+       clean_mirror_001_pos.ksh \
+       clean_mirror_002_pos.ksh \
+       clean_mirror_003_pos.ksh \
+       clean_mirror_004_pos.ksh
diff --git a/tests/zfs-tests/tests/functional/clean_mirror/clean_mirror_001_pos.ksh b/tests/zfs-tests/tests/functional/clean_mirror/clean_mirror_001_pos.ksh
new file mode 100755 (executable)
index 0000000..8dd337a
--- /dev/null
@@ -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) 2013 by Delphix. All rights reserved.
+#
+
+. $STF_SUITE/include/libtest.shlib
+. $STF_SUITE/tests/functional/clean_mirror/clean_mirror_common.kshlib
+
+#
+# DESCRIPTION:
+# The primary side of a zpool mirror can be zeroed without causing damage
+# to the data in the pool
+#
+# STRATEGY:
+# 1) Write several files to the ZFS filesystem mirror
+# 2) dd from /dev/zero over the primary side of the mirror
+# 3) verify that all the file contents are unchanged on the file system
+#
+
+verify_runnable "global"
+
+log_assert "The primary side of a zpool mirror may be completely wiped" \
+       "without affecting the content of the pool"
+
+overwrite_verify_mirror $SIDE_PRIMARY /dev/zero
+
+log_pass "The overwrite had no effect on the data"
diff --git a/tests/zfs-tests/tests/functional/clean_mirror/clean_mirror_002_pos.ksh b/tests/zfs-tests/tests/functional/clean_mirror/clean_mirror_002_pos.ksh
new file mode 100755 (executable)
index 0000000..a156368
--- /dev/null
@@ -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) 2013 by Delphix. All rights reserved.
+#
+
+. $STF_SUITE/include/libtest.shlib
+. $STF_SUITE/tests/functional/clean_mirror/clean_mirror_common.kshlib
+
+#
+# DESCRIPTION:
+# The secondary side of a zpool mirror can be zeroed without causing damage
+# to the data in the pool
+#
+# STRATEGY:
+# 1) Write several files to the ZFS filesystem in the mirrored pool
+# 2) dd from /dev/zero over the secondary side of the mirror
+# 3) verify that all the file contents are unchanged on the file system
+#
+
+verify_runnable "global"
+
+log_assert "The primary side of a zpool mirror may be completely wiped" \
+       "without affecting the content of the pool"
+
+overwrite_verify_mirror $SIDE_SECONDARY /dev/zero
+
+log_pass "The overwrite had no effect on the data"
diff --git a/tests/zfs-tests/tests/functional/clean_mirror/clean_mirror_003_pos.ksh b/tests/zfs-tests/tests/functional/clean_mirror/clean_mirror_003_pos.ksh
new file mode 100755 (executable)
index 0000000..144dcf1
--- /dev/null
@@ -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) 2013 by Delphix. All rights reserved.
+#
+
+. $STF_SUITE/include/libtest.shlib
+. $STF_SUITE/tests/functional/clean_mirror/clean_mirror_common.kshlib
+
+#
+# DESCRIPTION:
+# The primary side of a zpool mirror can be mangled without causing damage
+# to the data in the pool
+#
+# STRATEGY:
+# 1) Write several files to the ZFS filesystem mirror
+# 2) dd from /dev/urandom over the primary side of the mirror
+# 3) verify that all the file contents are unchanged on the file system
+#
+
+verify_runnable "global"
+
+log_assert "The primary side of a zpool mirror may be completely mangled" \
+       "without affecting the content of the pool"
+
+overwrite_verify_mirror $SIDE_PRIMARY /dev/urandom
+
+log_pass "The overwrite did not have any effect on the data"
diff --git a/tests/zfs-tests/tests/functional/clean_mirror/clean_mirror_004_pos.ksh b/tests/zfs-tests/tests/functional/clean_mirror/clean_mirror_004_pos.ksh
new file mode 100755 (executable)
index 0000000..ce1aac5
--- /dev/null
@@ -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) 2013 by Delphix. All rights reserved.
+#
+
+. $STF_SUITE/include/libtest.shlib
+. $STF_SUITE/tests/functional/clean_mirror/clean_mirror_common.kshlib
+
+#
+# DESCRIPTION:
+# The secondary side of a zpool mirror can be mangled without causing damage
+# to the data in the pool
+#
+# STRATEGY:
+# 1) Write several files to the ZFS filesystem in the mirrored pool
+# 2) dd from /dev/urandom over the secondary side of the mirror
+# 3) verify that all the file contents are unchanged on the file system
+#
+
+verify_runnable "global"
+
+log_assert "The primary side of a zpool mirror may be completely mangled" \
+       "without affecting the content of the pool"
+
+overwrite_verify_mirror $SIDE_SECONDARY /dev/urandom
+
+log_pass "The overwrite had no effect on the data"
diff --git a/tests/zfs-tests/tests/functional/clean_mirror/clean_mirror_common.kshlib b/tests/zfs-tests/tests/functional/clean_mirror/clean_mirror_common.kshlib
new file mode 100644 (file)
index 0000000..1f234ce
--- /dev/null
@@ -0,0 +1,78 @@
+#
+# CDDL HEADER START
+#
+# The contents of this file are subject to the terms of the
+# Common Development and Distribution License (the "License").
+# You may not use this file except in compliance with the License.
+#
+# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
+# or http://www.opensolaris.org/os/licensing.
+# See the License for the specific language governing permissions
+# and limitations under the License.
+#
+# When distributing Covered Code, include this CDDL HEADER in each
+# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
+# If applicable, add the following below this CDDL HEADER, with the
+# fields enclosed by brackets "[]" replaced with your own identifying
+# information: Portions Copyright [yyyy] [name of copyright owner]
+#
+# CDDL HEADER END
+#
+
+#
+# Copyright 2007 Sun Microsystems, Inc.  All rights reserved.
+# Use is subject to license terms.
+#
+
+#
+# Copyright (c) 2013 by Delphix. All rights reserved.
+#
+
+. $STF_SUITE/tests/functional/clean_mirror/default.cfg
+
+# Most of the code related to the clearing of mirrors is duplicated in all
+# the test cases below this directory, barring a few minor changes
+# involving the device to be affected and the 'object' to use to mangle
+# the contents of the mirror.
+# This code is sourced into each of these test cases.
+
+function overwrite_verify_mirror
+{
+       typeset AFFECTED_DEVICE=$1
+       typeset OVERWRITING_DEVICE=$2
+
+       typeset atfile=0
+       set -A files
+       set -A cksums
+       set -A newcksums
+
+       while (( atfile < FILE_COUNT )); do
+               files[$atfile]=$TESTDIR/file.$atfile
+               log_must $FILE_WRITE -o create -f $TESTDIR/file.$atfile \
+                       -b $FILE_SIZE -c 1
+               cksums[$atfile]=$($CKSUM ${files[$atfile]})
+               (( atfile = atfile + 1 ))
+       done
+
+       # dd the primary side of the mirror
+       log_must $DD if=$OVERWRITING_DEVICE of=$AFFECTED_DEVICE \
+               seek=8 bs=$DD_BLOCK count=$(( DD_COUNT - 128 )) conv=notrunc
+
+       atfile=0
+
+       typeset -i failedcount=0
+       while (( atfile < FILE_COUNT )); do
+               files[$atfile]=$TESTDIR/file.$atfile
+               newcksum=$($CKSUM ${files[$atfile]})
+               if [[ $newcksum != ${cksums[$atfile]} ]]; then
+                       (( failedcount = failedcount + 1 ))
+               fi
+               $RM -f ${files[$atfile]}
+               (( atfile = atfile + 1 ))
+       done
+
+       if (( $failedcount > 0 )); then
+               log_fail "of the $FILE_COUNT files $failedcount did not " \
+                   "have the same checksum before and after."
+       fi
+}
diff --git a/tests/zfs-tests/tests/functional/clean_mirror/cleanup.ksh b/tests/zfs-tests/tests/functional/clean_mirror/cleanup.ksh
new file mode 100755 (executable)
index 0000000..e09fb59
--- /dev/null
@@ -0,0 +1,49 @@
+#! /bin/ksh -p
+#
+# CDDL HEADER START
+#
+# The contents of this file are subject to the terms of the
+# Common Development and Distribution License (the "License").
+# You may not use this file except in compliance with the License.
+#
+# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
+# or http://www.opensolaris.org/os/licensing.
+# See the License for the specific language governing permissions
+# and limitations under the License.
+#
+# When distributing Covered Code, include this CDDL HEADER in each
+# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
+# If applicable, add the following below this CDDL HEADER, with the
+# fields enclosed by brackets "[]" replaced with your own identifying
+# information: Portions Copyright [yyyy] [name of copyright owner]
+#
+# CDDL HEADER END
+#
+
+#
+# Copyright 2007 Sun Microsystems, Inc.  All rights reserved.
+# Use is subject to license terms.
+#
+
+#
+# Copyright (c) 2013 by Delphix. All rights reserved.
+#
+
+. $STF_SUITE/tests/functional/clean_mirror/default.cfg
+. $STF_SUITE/include/libtest.shlib
+
+verify_runnable "global"
+
+$DF -F zfs -h | $GREP "$TESTFS " >/dev/null
+[[ $? == 0 ]] && log_must $ZFS umount -f $TESTDIR
+destroy_pool $TESTPOOL
+
+# recreate and destroy a zpool over the disks to restore the partitions to
+# normal
+if [[ -n $SINGLE_DISK ]]; then
+       log_must cleanup_devices $MIRROR_PRIMARY
+else
+       log_must cleanup_devices $MIRROR_PRIMARY $MIRROR_SECONDARY
+fi
+
+log_pass
diff --git a/tests/zfs-tests/tests/functional/clean_mirror/default.cfg b/tests/zfs-tests/tests/functional/clean_mirror/default.cfg
new file mode 100644 (file)
index 0000000..35cd141
--- /dev/null
@@ -0,0 +1,72 @@
+#
+# CDDL HEADER START
+#
+# The contents of this file are subject to the terms of the
+# Common Development and Distribution License (the "License").
+# You may not use this file except in compliance with the License.
+#
+# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
+# or http://www.opensolaris.org/os/licensing.
+# See the License for the specific language governing permissions
+# and limitations under the License.
+#
+# When distributing Covered Code, include this CDDL HEADER in each
+# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
+# If applicable, add the following below this CDDL HEADER, with the
+# fields enclosed by brackets "[]" replaced with your own identifying
+# information: Portions Copyright [yyyy] [name of copyright owner]
+#
+# CDDL HEADER END
+#
+
+#
+# Copyright 2008 Sun Microsystems, Inc.  All rights reserved.
+# Use is subject to license terms.
+#
+
+#
+# Copyright (c) 2013 by Delphix. All rights reserved.
+#
+
+. $STF_SUITE/include/libtest.shlib
+
+typeset -i NUMBER_OF_DISKS=0
+for i in $DISKS; do
+       [[ -n $MIRROR_PRIMARY ]] && MIRROR_SECONDARY=$i
+       [[ -z $MIRROR_PRIMARY ]] && MIRROR_PRIMARY=$i
+done
+
+if [[ -z $MIRROR_SECONDARY ]]; then
+       # We need to repartition the single disk to two slices
+       SINGLE_DISK=$MIRROR_PRIMARY
+       MIRROR_SECONDARY=$MIRROR_PRIMARY
+       SIDE_PRIMARY_PART=0
+       SIDE_SECONDARY_PART=1
+
+       if is_linux; then
+               SIDE_PRIMARY=${SINGLE_DISK}p1
+               SIDE_SECONDARY=${SINGLE_DISK}p2
+       else
+               SIDE_PRIMARY=${SINGLE_DISK}s${SIDE_PRIMARY_PART}
+               SIDE_SECONDARY=${SINGLE_DISK}s${SIDE_SECONDARY_PART}
+       fi
+else
+       SIDE_PRIMARY_PART=0
+       SIDE_SECONDARY_PART=0
+       if is_linux; then
+               SIDE_PRIMARY=${MIRROR_PRIMARY}p1
+               SIDE_SECONDARY=${MIRROR_SECONDARY}p1
+       else
+               SIDE_PRIMARY=${MIRROR_PRIMARY}s${SIDE_PRIMARY_PART}
+               SIDE_SECONDARY=${MIRROR_SECONDARY}s${SIDE_SECONDARY_PART}
+       fi
+fi
+
+export MIRROR_PRIMARY MIRROR_SECONDARY SINGLE_DISK SIDE_PRIMARY SIDE_SECONDARY
+
+export FILE_COUNT=10
+export FILE_SIZE=$(( 1024 * 1024 ))
+export MIRROR_MEGS=100
+export MIRROR_SIZE=${MIRROR_MEGS}m # default mirror size
+export DD_BLOCK=$(( 64 * 1024 ))
+export DD_COUNT=$(( MIRROR_MEGS * 1024 * 1024 / DD_BLOCK ))
diff --git a/tests/zfs-tests/tests/functional/clean_mirror/setup.ksh b/tests/zfs-tests/tests/functional/clean_mirror/setup.ksh
new file mode 100755 (executable)
index 0000000..6ea2f1e
--- /dev/null
@@ -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 2009 Sun Microsystems, Inc.  All rights reserved.
+# Use is subject to license terms.
+#
+
+#
+# Copyright (c) 2013 by Delphix. All rights reserved.
+#
+
+. $STF_SUITE/tests/functional/clean_mirror/default.cfg
+. $STF_SUITE/include/libtest.shlib
+
+verify_runnable "global"
+
+if ! $(is_physical_device $DISKS) ; then
+       log_unsupported "This directory cannot be run on raw files."
+fi
+
+if [[ -n $SINGLE_DISK ]]; then
+       log_note "Partitioning a single disk ($SINGLE_DISK)"
+else
+       log_note "Partitioning disks ($MIRROR_PRIMARY $MIRROR_SECONDARY)"
+fi
+
+log_must set_partition $SIDE_PRIMARY_PART "" $MIRROR_SIZE $MIRROR_PRIMARY
+log_must set_partition $SIDE_SECONDARY_PART "" $MIRROR_SIZE $MIRROR_SECONDARY
+
+default_mirror_setup $SIDE_PRIMARY $SIDE_SECONDARY
+
+log_pass
diff --git a/tests/zfs-tests/tests/functional/cli_root/Makefile.am b/tests/zfs-tests/tests/functional/cli_root/Makefile.am
new file mode 100644 (file)
index 0000000..5dc72de
--- /dev/null
@@ -0,0 +1,47 @@
+pkgdatadir = $(datadir)/@PACKAGE@/zfs-tests/tests/functional/cli_root
+dist_pkgdata_SCRIPTS = \
+       cli_common.kshlib
+
+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
diff --git a/tests/zfs-tests/tests/functional/cli_root/cli_common.kshlib b/tests/zfs-tests/tests/functional/cli_root/cli_common.kshlib
new file mode 100644 (file)
index 0000000..06e794e
--- /dev/null
@@ -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
+}
diff --git a/tests/zfs-tests/tests/functional/cli_root/zdb/Makefile.am b/tests/zfs-tests/tests/functional/cli_root/zdb/Makefile.am
new file mode 100644 (file)
index 0000000..05711c2
--- /dev/null
@@ -0,0 +1,3 @@
+pkgdatadir = $(datadir)/@PACKAGE@/zfs-tests/tests/functional/cli_root/zdb
+dist_pkgdata_SCRIPTS = \
+       zdb_001_neg.ksh
diff --git a/tests/zfs-tests/tests/functional/cli_root/zdb/zdb_001_neg.ksh b/tests/zfs-tests/tests/functional/cli_root/zdb/zdb_001_neg.ksh
new file mode 100755 (executable)
index 0000000..9ef8e1a
--- /dev/null
@@ -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" "-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."
diff --git a/tests/zfs-tests/tests/functional/cli_root/zfs/Makefile.am b/tests/zfs-tests/tests/functional/cli_root/zfs/Makefile.am
new file mode 100644 (file)
index 0000000..8b0ee27
--- /dev/null
@@ -0,0 +1,7 @@
+pkgdatadir = $(datadir)/@PACKAGE@/zfs-tests/tests/functional/cli_root/zfs
+dist_pkgdata_SCRIPTS = \
+       setup.ksh \
+       cleanup.ksh \
+       zfs_001_neg.ksh \
+       zfs_002_pos.ksh \
+       zfs_003_neg.ksh
diff --git a/tests/zfs-tests/tests/functional/cli_root/zfs/cleanup.ksh b/tests/zfs-tests/tests/functional/cli_root/zfs/cleanup.ksh
new file mode 100755 (executable)
index 0000000..79cd6e9
--- /dev/null
@@ -0,0 +1,30 @@
+#!/bin/ksh -p
+#
+# CDDL HEADER START
+#
+# The contents of this file are subject to the terms of the
+# Common Development and Distribution License (the "License").
+# You may not use this file except in compliance with the License.
+#
+# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
+# or http://www.opensolaris.org/os/licensing.
+# See the License for the specific language governing permissions
+# and limitations under the License.
+#
+# When distributing Covered Code, include this CDDL HEADER in each
+# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
+# If applicable, add the following below this CDDL HEADER, with the
+# fields enclosed by brackets "[]" replaced with your own identifying
+# information: 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
diff --git a/tests/zfs-tests/tests/functional/cli_root/zfs/setup.ksh b/tests/zfs-tests/tests/functional/cli_root/zfs/setup.ksh
new file mode 100755 (executable)
index 0000000..6a9af3b
--- /dev/null
@@ -0,0 +1,32 @@
+#!/bin/ksh -p
+#
+# CDDL HEADER START
+#
+# The contents of this file are subject to the terms of the
+# Common Development and Distribution License (the "License").
+# You may not use this file except in compliance with the License.
+#
+# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
+# or http://www.opensolaris.org/os/licensing.
+# See the License for the specific language governing permissions
+# and limitations under the License.
+#
+# When distributing Covered Code, include this CDDL HEADER in each
+# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
+# If applicable, add the following below this CDDL HEADER, with the
+# fields enclosed by brackets "[]" replaced with your own identifying
+# information: 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
diff --git a/tests/zfs-tests/tests/functional/cli_root/zfs/zfs_001_neg.ksh b/tests/zfs-tests/tests/functional/cli_root/zfs/zfs_001_neg.ksh
new file mode 100755 (executable)
index 0000000..bfcc864
--- /dev/null
@@ -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."
diff --git a/tests/zfs-tests/tests/functional/cli_root/zfs/zfs_002_pos.ksh b/tests/zfs-tests/tests/functional/cli_root/zfs/zfs_002_pos.ksh
new file mode 100755 (executable)
index 0000000..473bc65
--- /dev/null
@@ -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 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")
+
+if is_linux; then
+       ulimit -c unlimited
+       echo "$corepath/core.zfs" >/proc/sys/kernel/core_pattern
+       echo 0 >/proc/sys/kernel/core_uses_pid
+else
+       log_must $COREADM -p ${corepath}/core.%f
+fi
+
+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."
diff --git a/tests/zfs-tests/tests/functional/cli_root/zfs/zfs_003_neg.ksh b/tests/zfs-tests/tests/functional/cli_root/zfs/zfs_003_neg.ksh
new file mode 100755 (executable)
index 0000000..d094d1a
--- /dev/null
@@ -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:
+# 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
+
+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."
diff --git a/tests/zfs-tests/tests/functional/cli_root/zfs_clone/Makefile.am b/tests/zfs-tests/tests/functional/cli_root/zfs_clone/Makefile.am
new file mode 100644 (file)
index 0000000..7c7728c
--- /dev/null
@@ -0,0 +1,14 @@
+pkgdatadir = $(datadir)/@PACKAGE@/zfs-tests/tests/functional/cli_root/zfs_clone
+dist_pkgdata_SCRIPTS = \
+       setup.ksh \
+       cleanup.ksh \
+       zfs_clone_001_neg.ksh \
+       zfs_clone_002_pos.ksh \
+       zfs_clone_003_pos.ksh \
+       zfs_clone_004_pos.ksh \
+       zfs_clone_005_pos.ksh \
+       zfs_clone_006_pos.ksh \
+       zfs_clone_007_pos.ksh \
+       zfs_clone_008_neg.ksh \
+       zfs_clone_009_neg.ksh \
+       zfs_clone_010_pos.ksh
diff --git a/tests/zfs-tests/tests/functional/cli_root/zfs_clone/cleanup.ksh b/tests/zfs-tests/tests/functional/cli_root/zfs_clone/cleanup.ksh
new file mode 100755 (executable)
index 0000000..d247991
--- /dev/null
@@ -0,0 +1,30 @@
+#!/bin/ksh -p
+#
+# CDDL HEADER START
+#
+# The contents of this file are subject to the terms of the
+# Common Development and Distribution License (the "License").
+# You may not use this file except in compliance with the License.
+#
+# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
+# or http://www.opensolaris.org/os/licensing.
+# See the License for the specific language governing permissions
+# and limitations under the License.
+#
+# When distributing Covered Code, include this CDDL HEADER in each
+# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
+# If applicable, add the following below this CDDL HEADER, with the
+# fields enclosed by brackets "[]" replaced with your own identifying
+# information: 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
diff --git a/tests/zfs-tests/tests/functional/cli_root/zfs_clone/setup.ksh b/tests/zfs-tests/tests/functional/cli_root/zfs_clone/setup.ksh
new file mode 100755 (executable)
index 0000000..985554f
--- /dev/null
@@ -0,0 +1,36 @@
+#!/bin/ksh -p
+#
+# CDDL HEADER START
+#
+# The contents of this file are subject to the terms of the
+# Common Development and Distribution License (the "License").
+# You may not use this file except in compliance with the License.
+#
+# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
+# or http://www.opensolaris.org/os/licensing.
+# See the License for the specific language governing permissions
+# and limitations under the License.
+#
+# When distributing Covered Code, include this CDDL HEADER in each
+# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
+# If applicable, add the following below this CDDL HEADER, with the
+# fields enclosed by brackets "[]" replaced with your own identifying
+# information: Portions Copyright [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}
diff --git a/tests/zfs-tests/tests/functional/cli_root/zfs_clone/zfs_clone_001_neg.ksh b/tests/zfs-tests/tests/functional/cli_root/zfs_clone/zfs_clone_001_neg.ksh
new file mode 100755 (executable)
index 0000000..e98b0d8
--- /dev/null
@@ -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 2009 Sun Microsystems, Inc.  All rights reserved.
+# Use is subject to license terms.
+#
+
+#
+# Copyright (c) 2012, 2015 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.
+#               * Invalid record sizes.
+#
+# 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" \
+        "-o recordsize=2M $SNAPFS1 $target1" \
+        "-o recordsize=128B $SNAPFS1 $target1"
+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."
diff --git a/tests/zfs-tests/tests/functional/cli_root/zfs_clone/zfs_clone_002_pos.ksh b/tests/zfs-tests/tests/functional/cli_root/zfs_clone/zfs_clone_002_pos.ksh
new file mode 100755 (executable)
index 0000000..1b376eb
--- /dev/null
@@ -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."
diff --git a/tests/zfs-tests/tests/functional/cli_root/zfs_clone/zfs_clone_003_pos.ksh b/tests/zfs-tests/tests/functional/cli_root/zfs_clone/zfs_clone_003_pos.ksh
new file mode 100755 (executable)
index 0000000..103f2d3
--- /dev/null
@@ -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."
diff --git a/tests/zfs-tests/tests/functional/cli_root/zfs_clone/zfs_clone_004_pos.ksh b/tests/zfs-tests/tests/functional/cli_root/zfs_clone/zfs_clone_004_pos.ksh
new file mode 100755 (executable)
index 0000000..03bf7d7
--- /dev/null
@@ -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."
diff --git a/tests/zfs-tests/tests/functional/cli_root/zfs_clone/zfs_clone_005_pos.ksh b/tests/zfs-tests/tests/functional/cli_root/zfs_clone/zfs_clone_005_pos.ksh
new file mode 100755 (executable)
index 0000000..776dfd5
--- /dev/null
@@ -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."
diff --git a/tests/zfs-tests/tests/functional/cli_root/zfs_clone/zfs_clone_006_pos.ksh b/tests/zfs-tests/tests/functional/cli_root/zfs_clone/zfs_clone_006_pos.ksh
new file mode 100755 (executable)
index 0000000..84f55c8
--- /dev/null
@@ -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."
diff --git a/tests/zfs-tests/tests/functional/cli_root/zfs_clone/zfs_clone_007_pos.ksh b/tests/zfs-tests/tests/functional/cli_root/zfs_clone/zfs_clone_007_pos.ksh
new file mode 100755 (executable)
index 0000000..370a98f
--- /dev/null
@@ -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."
diff --git a/tests/zfs-tests/tests/functional/cli_root/zfs_clone/zfs_clone_008_neg.ksh b/tests/zfs-tests/tests/functional/cli_root/zfs_clone/zfs_clone_008_neg.ksh
new file mode 100755 (executable)
index 0000000..d54c87d
--- /dev/null
@@ -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."
diff --git a/tests/zfs-tests/tests/functional/cli_root/zfs_clone/zfs_clone_009_neg.ksh b/tests/zfs-tests/tests/functional/cli_root/zfs_clone/zfs_clone_009_neg.ksh
new file mode 100755 (executable)
index 0000000..286cbf8
--- /dev/null
@@ -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."
diff --git a/tests/zfs-tests/tests/functional/cli_root/zfs_clone/zfs_clone_010_pos.ksh b/tests/zfs-tests/tests/functional/cli_root/zfs_clone/zfs_clone_010_pos.ksh
new file mode 100755 (executable)
index 0000000..8f405a0
--- /dev/null
@@ -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."
diff --git a/tests/zfs-tests/tests/functional/cli_root/zfs_copies/Makefile.am b/tests/zfs-tests/tests/functional/cli_root/zfs_copies/Makefile.am
new file mode 100644 (file)
index 0000000..732126d
--- /dev/null
@@ -0,0 +1,12 @@
+pkgdatadir = $(datadir)/@PACKAGE@/zfs-tests/tests/functional/cli_root/zfs_copies
+dist_pkgdata_SCRIPTS = \
+       zfs_copies.cfg \
+       zfs_copies.kshlib \
+       setup.ksh \
+       cleanup.ksh \
+       zfs_copies_001_pos.ksh \
+       zfs_copies_002_pos.ksh \
+       zfs_copies_003_pos.ksh \
+       zfs_copies_004_neg.ksh \
+       zfs_copies_005_neg.ksh \
+       zfs_copies_006_pos.ksh
diff --git a/tests/zfs-tests/tests/functional/cli_root/zfs_copies/cleanup.ksh b/tests/zfs-tests/tests/functional/cli_root/zfs_copies/cleanup.ksh
new file mode 100755 (executable)
index 0000000..39b52a8
--- /dev/null
@@ -0,0 +1,44 @@
+#!/bin/ksh -p
+#
+# CDDL HEADER START
+#
+# The contents of this file are subject to the terms of the
+# Common Development and Distribution License (the "License").
+# You may not use this file except in compliance with the License.
+#
+# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
+# or http://www.opensolaris.org/os/licensing.
+# See the License for the specific language governing permissions
+# and limitations under the License.
+#
+# When distributing Covered Code, include this CDDL HEADER in each
+# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
+# If applicable, add the following below this CDDL 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|ext2 fs if there is timedout in the ufs|ext2 test
+#
+
+if ismounted $FS_MNTPOINT $NEWFS_DEFAULT_FS ; then
+       log_must $UMOUNT -f $FS_MNTPOINT
+       $RM -fr $FS_MNTPOINT
+fi
+
+default_cleanup
diff --git a/tests/zfs-tests/tests/functional/cli_root/zfs_copies/setup.ksh b/tests/zfs-tests/tests/functional/cli_root/zfs_copies/setup.ksh
new file mode 100755 (executable)
index 0000000..d4cf209
--- /dev/null
@@ -0,0 +1,31 @@
+#!/bin/ksh -p
+#
+# CDDL HEADER START
+#
+# The contents of this file are subject to the terms of the
+# Common Development and Distribution License (the "License").
+# You may not use this file except in compliance with the License.
+#
+# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
+# or http://www.opensolaris.org/os/licensing.
+# See the License for the specific language governing permissions
+# and limitations under the License.
+#
+# When distributing Covered Code, include this CDDL HEADER in each
+# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
+# If applicable, add the following below this CDDL 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
diff --git a/tests/zfs-tests/tests/functional/cli_root/zfs_copies/zfs_copies.cfg b/tests/zfs-tests/tests/functional/cli_root/zfs_copies/zfs_copies.cfg
new file mode 100644 (file)
index 0000000..eb85e65
--- /dev/null
@@ -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 FS_MNTPOINT=/testdir_nfs_mntpoint
diff --git a/tests/zfs-tests/tests/functional/cli_root/zfs_copies/zfs_copies.kshlib b/tests/zfs-tests/tests/functional/cli_root/zfs_copies/zfs_copies.kshlib
new file mode 100644 (file)
index 0000000..68cfb92
--- /dev/null
@@ -0,0 +1,151 @@
+#
+# CDDL HEADER START
+#
+# The contents of this file are subject to the terms of the
+# Common Development and Distribution License (the "License").
+# You may not use this file except in compliance with the License.
+#
+# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
+# or http://www.opensolaris.org/os/licensing.
+# See the License for the specific language governing permissions
+# and limitations under the License.
+#
+# When distributing Covered Code, include this CDDL HEADER in each
+# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
+# If applicable, add the following below this CDDL 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=$ZVOL_DEVDIR/$TESTPOOL/$TESTVOL1
+       vol_r_path=$ZVOL_RDEVDIR/$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
+       elif [[ $type == "ext2" ]]; then
+               log_must $ECHO y | $NEWFS $vol_r_path >/dev/null 2>&1
+               log_must $MOUNT -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
+       elif [[ $type == "ext2" ]]; 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
+       elif [[ $type == "ext2" ]]; then
+               $UMOUNT $mntp
+       else
+               log_must $ZPOOL destroy $TESTPOOL1
+       fi
+
+       log_must $ZFS destroy $vol
+}
diff --git a/tests/zfs-tests/tests/functional/cli_root/zfs_copies/zfs_copies_001_pos.ksh b/tests/zfs-tests/tests/functional/cli_root/zfs_copies/zfs_copies_001_pos.ksh
new file mode 100755 (executable)
index 0000000..f484e05
--- /dev/null
@@ -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. "
diff --git a/tests/zfs-tests/tests/functional/cli_root/zfs_copies/zfs_copies_002_pos.ksh b/tests/zfs-tests/tests/functional/cli_root/zfs_copies/zfs_copies_002_pos.ksh
new file mode 100755 (executable)
index 0000000..46fe0f5
--- /dev/null
@@ -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. "
diff --git a/tests/zfs-tests/tests/functional/cli_root/zfs_copies/zfs_copies_003_pos.ksh b/tests/zfs-tests/tests/functional/cli_root/zfs_copies/zfs_copies_003_pos.ksh
new file mode 100755 (executable)
index 0000000..4b67e69
--- /dev/null
@@ -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. "
diff --git a/tests/zfs-tests/tests/functional/cli_root/zfs_copies/zfs_copies_004_neg.ksh b/tests/zfs-tests/tests/functional/cli_root/zfs_copies/zfs_copies_004_neg.ksh
new file mode 100755 (executable)
index 0000000..132e2b0
--- /dev/null
@@ -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"
diff --git a/tests/zfs-tests/tests/functional/cli_root/zfs_copies/zfs_copies_005_neg.ksh b/tests/zfs-tests/tests/functional/cli_root/zfs_copies/zfs_copies_005_neg.ksh
new file mode 100755 (executable)
index 0000000..a10ca59
--- /dev/null
@@ -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. "
diff --git a/tests/zfs-tests/tests/functional/cli_root/zfs_copies/zfs_copies_006_pos.ksh b/tests/zfs-tests/tests/functional/cli_root/zfs_copies/zfs_copies_006_pos.ksh
new file mode 100755 (executable)
index 0000000..40a8328
--- /dev/null
@@ -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 $NEWFS_DEFAULT_FS ; 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=$FS_MNTPOINT
+vol=$TESTPOOL/$TESTVOL1
+
+if [[ ! -d $mntp ]]; then
+       $MKDIR -p $mntp
+fi
+
+for val in 1 2 3; do
+       do_vol_test $NEWFS_DEFAULT_FS $val $mntp
+done
+
+log_pass "The volume space used by multiple copies is charged correctly as expected. "
diff --git a/tests/zfs-tests/tests/functional/cli_root/zfs_create/Makefile.am b/tests/zfs-tests/tests/functional/cli_root/zfs_create/Makefile.am
new file mode 100644 (file)
index 0000000..10d6b66
--- /dev/null
@@ -0,0 +1,20 @@
+pkgdatadir = $(datadir)/@PACKAGE@/zfs-tests/tests/functional/cli_root/zfs_create
+dist_pkgdata_SCRIPTS = \
+       properties.kshlib \
+       zfs_create_common.kshlib \
+       zfs_create.cfg \
+       setup.ksh \
+       cleanup.ksh \
+       zfs_create_001_pos.ksh \
+       zfs_create_002_pos.ksh \
+       zfs_create_003_pos.ksh \
+       zfs_create_004_pos.ksh \
+       zfs_create_005_pos.ksh \
+       zfs_create_006_pos.ksh \
+       zfs_create_007_pos.ksh \
+       zfs_create_008_neg.ksh \
+       zfs_create_009_neg.ksh \
+       zfs_create_010_neg.ksh \
+       zfs_create_011_pos.ksh \
+       zfs_create_012_pos.ksh \
+       zfs_create_013_pos.ksh
diff --git a/tests/zfs-tests/tests/functional/cli_root/zfs_create/cleanup.ksh b/tests/zfs-tests/tests/functional/cli_root/zfs_create/cleanup.ksh
new file mode 100755 (executable)
index 0000000..79cd6e9
--- /dev/null
@@ -0,0 +1,30 @@
+#!/bin/ksh -p
+#
+# CDDL HEADER START
+#
+# The contents of this file are subject to the terms of the
+# Common Development and Distribution License (the "License").
+# You may not use this file except in compliance with the License.
+#
+# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
+# or http://www.opensolaris.org/os/licensing.
+# See the License for the specific language governing permissions
+# and limitations under the License.
+#
+# When distributing Covered Code, include this CDDL HEADER in each
+# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
+# If applicable, add the following below this CDDL HEADER, with the
+# fields enclosed by brackets "[]" replaced with your own identifying
+# information: 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
diff --git a/tests/zfs-tests/tests/functional/cli_root/zfs_create/properties.kshlib b/tests/zfs-tests/tests/functional/cli_root/zfs_create/properties.kshlib
new file mode 100644 (file)
index 0000000..cf35686
--- /dev/null
@@ -0,0 +1,69 @@
+#
+# CDDL HEADER START
+#
+# The contents of this file are subject to the terms of the
+# Common Development and Distribution License (the "License").
+# You may not use this file except in compliance with the License.
+#
+# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
+# or http://www.opensolaris.org/os/licensing.
+# See the License for the specific language governing permissions
+# and limitations under the License.
+#
+# When distributing Covered Code, include this CDDL HEADER in each
+# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
+# If applicable, add the following below this CDDL 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, 2015 by Delphix. All rights reserved.
+#
+
+set -A RW_FS_PROP "quota=512M" \
+                 "reservation=512M" \
+                 "recordsize=256K" \
+                 "mountpoint=/tmp/mnt$$" \
+                 "checksum=fletcher2" \
+                 "compression=lzjb" \
+                 "atime=off" \
+                 "devices=off" \
+                 "exec=off" \
+                 "setuid=off" \
+                 "readonly=on" \
+                 "snapdir=visible" \
+                 "canmount=off" \
+                 "local:department=123"
+
+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$$" \
+                    "atime=off" \
+                    "devices=off" \
+                    "exec=off" \
+                    "setuid=off" \
+                    "zoned=on" \
+                    "snapdir=visible" \
+                   "canmount=off" \
+                   "version=1"
+
+set -A VOL_ONLY_PROP "volblocksize=16K" "volsize=512M"
diff --git a/tests/zfs-tests/tests/functional/cli_root/zfs_create/setup.ksh b/tests/zfs-tests/tests/functional/cli_root/zfs_create/setup.ksh
new file mode 100755 (executable)
index 0000000..6a9af3b
--- /dev/null
@@ -0,0 +1,32 @@
+#!/bin/ksh -p
+#
+# CDDL HEADER START
+#
+# The contents of this file are subject to the terms of the
+# Common Development and Distribution License (the "License").
+# You may not use this file except in compliance with the License.
+#
+# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
+# or http://www.opensolaris.org/os/licensing.
+# See the License for the specific language governing permissions
+# and limitations under the License.
+#
+# When distributing Covered Code, include this CDDL HEADER in each
+# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
+# If applicable, add the following below this CDDL HEADER, with the
+# fields enclosed by brackets "[]" replaced with your own identifying
+# information: 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
diff --git a/tests/zfs-tests/tests/functional/cli_root/zfs_create/zfs_create.cfg b/tests/zfs-tests/tests/functional/cli_root/zfs_create/zfs_create.cfg
new file mode 100644 (file)
index 0000000..c97e44d
--- /dev/null
@@ -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"
diff --git a/tests/zfs-tests/tests/functional/cli_root/zfs_create/zfs_create_001_pos.ksh b/tests/zfs-tests/tests/functional/cli_root/zfs_create/zfs_create_001_pos.ksh
new file mode 100755 (executable)
index 0000000..63cf619
--- /dev/null
@@ -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."
diff --git a/tests/zfs-tests/tests/functional/cli_root/zfs_create/zfs_create_002_pos.ksh b/tests/zfs-tests/tests/functional/cli_root/zfs_create/zfs_create_002_pos.ksh
new file mode 100755 (executable)
index 0000000..bb06646
--- /dev/null
@@ -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."
diff --git a/tests/zfs-tests/tests/functional/cli_root/zfs_create/zfs_create_003_pos.ksh b/tests/zfs-tests/tests/functional/cli_root/zfs_create/zfs_create_003_pos.ksh
new file mode 100755 (executable)
index 0000000..bffe8cd
--- /dev/null
@@ -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."
diff --git a/tests/zfs-tests/tests/functional/cli_root/zfs_create/zfs_create_004_pos.ksh b/tests/zfs-tests/tests/functional/cli_root/zfs_create/zfs_create_004_pos.ksh
new file mode 100755 (executable)
index 0000000..5d2a21a
--- /dev/null
@@ -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."
diff --git a/tests/zfs-tests/tests/functional/cli_root/zfs_create/zfs_create_005_pos.ksh b/tests/zfs-tests/tests/functional/cli_root/zfs_create/zfs_create_005_pos.ksh
new file mode 100755 (executable)
index 0000000..ce84a5c
--- /dev/null
@@ -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."
diff --git a/tests/zfs-tests/tests/functional/cli_root/zfs_create/zfs_create_006_pos.ksh b/tests/zfs-tests/tests/functional/cli_root/zfs_create/zfs_create_006_pos.ksh
new file mode 100755 (executable)
index 0000000..e47b064
--- /dev/null
@@ -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."
diff --git a/tests/zfs-tests/tests/functional/cli_root/zfs_create/zfs_create_007_pos.ksh b/tests/zfs-tests/tests/functional/cli_root/zfs_create/zfs_create_007_pos.ksh
new file mode 100755 (executable)
index 0000000..a34b46d
--- /dev/null
@@ -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, 2015 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/$TESTVOL && \
+                log_must $ZFS destroy -f $TESTPOOL/$TESTVOL
+       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."
diff --git a/tests/zfs-tests/tests/functional/cli_root/zfs_create/zfs_create_008_neg.ksh b/tests/zfs-tests/tests/functional/cli_root/zfs_create/zfs_create_008_neg.ksh
new file mode 100755 (executable)
index 0000000..27b5f9c
--- /dev/null
@@ -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, 2015 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=2048K" "-o recordsize=2M" \
+    "-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."
diff --git a/tests/zfs-tests/tests/functional/cli_root/zfs_create/zfs_create_009_neg.ksh b/tests/zfs-tests/tests/functional/cli_root/zfs_create/zfs_create_009_neg.ksh
new file mode 100755 (executable)
index 0000000..1144191
--- /dev/null
@@ -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."
diff --git a/tests/zfs-tests/tests/functional/cli_root/zfs_create/zfs_create_010_neg.ksh b/tests/zfs-tests/tests/functional/cli_root/zfs_create/zfs_create_010_neg.ksh
new file mode 100755 (executable)
index 0000000..1f10b9c
--- /dev/null
@@ -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"
+
+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."
diff --git a/tests/zfs-tests/tests/functional/cli_root/zfs_create/zfs_create_011_pos.ksh b/tests/zfs-tests/tests/functional/cli_root/zfs_create/zfs_create_011_pos.ksh
new file mode 100755 (executable)
index 0000000..ba2e55f
--- /dev/null
@@ -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."
diff --git a/tests/zfs-tests/tests/functional/cli_root/zfs_create/zfs_create_012_pos.ksh b/tests/zfs-tests/tests/functional/cli_root/zfs_create/zfs_create_012_pos.ksh
new file mode 100755 (executable)
index 0000000..fe50460
--- /dev/null
@@ -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."
diff --git a/tests/zfs-tests/tests/functional/cli_root/zfs_create/zfs_create_013_pos.ksh b/tests/zfs-tests/tests/functional/cli_root/zfs_create/zfs_create_013_pos.ksh
new file mode 100755 (executable)
index 0000000..460ee8f
--- /dev/null
@@ -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."
diff --git a/tests/zfs-tests/tests/functional/cli_root/zfs_create/zfs_create_common.kshlib b/tests/zfs-tests/tests/functional/cli_root/zfs_create/zfs_create_common.kshlib
new file mode 100644 (file)
index 0000000..bbc1273
--- /dev/null
@@ -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
+}
diff --git a/tests/zfs-tests/tests/functional/cli_root/zfs_destroy/Makefile.am b/tests/zfs-tests/tests/functional/cli_root/zfs_destroy/Makefile.am
new file mode 100644 (file)
index 0000000..5a4bd70
--- /dev/null
@@ -0,0 +1,22 @@
+pkgdatadir = $(datadir)/@PACKAGE@/zfs-tests/tests/functional/cli_root/zfs_destroy
+dist_pkgdata_SCRIPTS = \
+       zfs_destroy_common.kshlib \
+       zfs_destroy.cfg \
+       setup.ksh \
+       cleanup.ksh \
+       zfs_destroy_001_pos.ksh \
+       zfs_destroy_002_pos.ksh \
+       zfs_destroy_003_pos.ksh \
+       zfs_destroy_004_pos.ksh \
+       zfs_destroy_005_neg.ksh \
+       zfs_destroy_006_neg.ksh \
+       zfs_destroy_007_neg.ksh \
+       zfs_destroy_008_pos.ksh \
+       zfs_destroy_009_pos.ksh \
+       zfs_destroy_010_pos.ksh \
+       zfs_destroy_011_pos.ksh \
+       zfs_destroy_012_pos.ksh \
+       zfs_destroy_013_neg.ksh \
+       zfs_destroy_014_pos.ksh \
+       zfs_destroy_015_pos.ksh \
+       zfs_destroy_016_pos.ksh
diff --git a/tests/zfs-tests/tests/functional/cli_root/zfs_destroy/cleanup.ksh b/tests/zfs-tests/tests/functional/cli_root/zfs_destroy/cleanup.ksh
new file mode 100755 (executable)
index 0000000..90c0ac7
--- /dev/null
@@ -0,0 +1,32 @@
+#!/bin/ksh -p
+#
+# CDDL HEADER START
+#
+# The contents of this file are subject to the terms of the
+# Common Development and Distribution License (the "License").
+# You may not use this file except in compliance with the License.
+#
+# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
+# or http://www.opensolaris.org/os/licensing.
+# See the License for the specific language governing permissions
+# and limitations under the License.
+#
+# When distributing Covered Code, include this CDDL HEADER in each
+# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
+# If applicable, add the following below this CDDL HEADER, with the
+# fields enclosed by brackets "[]" replaced with your own identifying
+# information: 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
diff --git a/tests/zfs-tests/tests/functional/cli_root/zfs_destroy/setup.ksh b/tests/zfs-tests/tests/functional/cli_root/zfs_destroy/setup.ksh
new file mode 100755 (executable)
index 0000000..6a9af3b
--- /dev/null
@@ -0,0 +1,32 @@
+#!/bin/ksh -p
+#
+# CDDL HEADER START
+#
+# The contents of this file are subject to the terms of the
+# Common Development and Distribution License (the "License").
+# You may not use this file except in compliance with the License.
+#
+# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
+# or http://www.opensolaris.org/os/licensing.
+# See the License for the specific language governing permissions
+# and limitations under the License.
+#
+# When distributing Covered Code, include this CDDL HEADER in each
+# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
+# If applicable, add the following below this CDDL HEADER, with the
+# fields enclosed by brackets "[]" replaced with your own identifying
+# information: 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
diff --git a/tests/zfs-tests/tests/functional/cli_root/zfs_destroy/zfs_destroy.cfg b/tests/zfs-tests/tests/functional/cli_root/zfs_destroy/zfs_destroy.cfg
new file mode 100644 (file)
index 0000000..a62739b
--- /dev/null
@@ -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
diff --git a/tests/zfs-tests/tests/functional/cli_root/zfs_destroy/zfs_destroy_001_pos.ksh b/tests/zfs-tests/tests/functional/cli_root/zfs_destroy/zfs_destroy_001_pos.ksh
new file mode 100755 (executable)
index 0000000..4aef51e
--- /dev/null
@@ -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."
diff --git a/tests/zfs-tests/tests/functional/cli_root/zfs_destroy/zfs_destroy_002_pos.ksh b/tests/zfs-tests/tests/functional/cli_root/zfs_destroy/zfs_destroy_002_pos.ksh
new file mode 100755 (executable)
index 0000000..5e27ce1
--- /dev/null
@@ -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."
diff --git a/tests/zfs-tests/tests/functional/cli_root/zfs_destroy/zfs_destroy_003_pos.ksh b/tests/zfs-tests/tests/functional/cli_root/zfs_destroy/zfs_destroy_003_pos.ksh
new file mode 100755 (executable)
index 0000000..a18c0d6
--- /dev/null
@@ -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."
diff --git a/tests/zfs-tests/tests/functional/cli_root/zfs_destroy/zfs_destroy_004_pos.ksh b/tests/zfs-tests/tests/functional/cli_root/zfs_destroy/zfs_destroy_004_pos.ksh
new file mode 100755 (executable)
index 0000000..6919bdf
--- /dev/null
@@ -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."
diff --git a/tests/zfs-tests/tests/functional/cli_root/zfs_destroy/zfs_destroy_005_neg.ksh b/tests/zfs-tests/tests/functional/cli_root/zfs_destroy/zfs_destroy_005_neg.ksh
new file mode 100755 (executable)
index 0000000..baf182a
--- /dev/null
@@ -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."
diff --git a/tests/zfs-tests/tests/functional/cli_root/zfs_destroy/zfs_destroy_006_neg.ksh b/tests/zfs-tests/tests/functional/cli_root/zfs_destroy/zfs_destroy_006_neg.ksh
new file mode 100755 (executable)
index 0000000..7e383c2
--- /dev/null
@@ -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."
diff --git a/tests/zfs-tests/tests/functional/cli_root/zfs_destroy/zfs_destroy_007_neg.ksh b/tests/zfs-tests/tests/functional/cli_root/zfs_destroy/zfs_destroy_007_neg.ksh
new file mode 100755 (executable)
index 0000000..72272a5
--- /dev/null
@@ -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."
diff --git a/tests/zfs-tests/tests/functional/cli_root/zfs_destroy/zfs_destroy_008_pos.ksh b/tests/zfs-tests/tests/functional/cli_root/zfs_destroy/zfs_destroy_008_pos.ksh
new file mode 100755 (executable)
index 0000000..b9a866a
--- /dev/null
@@ -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"
diff --git a/tests/zfs-tests/tests/functional/cli_root/zfs_destroy/zfs_destroy_009_pos.ksh b/tests/zfs-tests/tests/functional/cli_root/zfs_destroy/zfs_destroy_009_pos.ksh
new file mode 100755 (executable)
index 0000000..b602a3e
--- /dev/null
@@ -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"
diff --git a/tests/zfs-tests/tests/functional/cli_root/zfs_destroy/zfs_destroy_010_pos.ksh b/tests/zfs-tests/tests/functional/cli_root/zfs_destroy/zfs_destroy_010_pos.ksh
new file mode 100755 (executable)
index 0000000..150d0b3
--- /dev/null
@@ -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"
diff --git a/tests/zfs-tests/tests/functional/cli_root/zfs_destroy/zfs_destroy_011_pos.ksh b/tests/zfs-tests/tests/functional/cli_root/zfs_destroy/zfs_destroy_011_pos.ksh
new file mode 100755 (executable)
index 0000000..6039202
--- /dev/null
@@ -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"
diff --git a/tests/zfs-tests/tests/functional/cli_root/zfs_destroy/zfs_destroy_012_pos.ksh b/tests/zfs-tests/tests/functional/cli_root/zfs_destroy/zfs_destroy_012_pos.ksh
new file mode 100755 (executable)
index 0000000..076e905
--- /dev/null
@@ -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"
diff --git a/tests/zfs-tests/tests/functional/cli_root/zfs_destroy/zfs_destroy_013_neg.ksh b/tests/zfs-tests/tests/functional/cli_root/zfs_destroy/zfs_destroy_013_neg.ksh
new file mode 100755 (executable)
index 0000000..198573d
--- /dev/null
@@ -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"
diff --git a/tests/zfs-tests/tests/functional/cli_root/zfs_destroy/zfs_destroy_014_pos.ksh b/tests/zfs-tests/tests/functional/cli_root/zfs_destroy/zfs_destroy_014_pos.ksh
new file mode 100755 (executable)
index 0000000..5625785
--- /dev/null
@@ -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."
diff --git a/tests/zfs-tests/tests/functional/cli_root/zfs_destroy/zfs_destroy_015_pos.ksh b/tests/zfs-tests/tests/functional/cli_root/zfs_destroy/zfs_destroy_015_pos.ksh
new file mode 100755 (executable)
index 0000000..579e747
--- /dev/null
@@ -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"
diff --git a/tests/zfs-tests/tests/functional/cli_root/zfs_destroy/zfs_destroy_016_pos.ksh b/tests/zfs-tests/tests/functional/cli_root/zfs_destroy/zfs_destroy_016_pos.ksh
new file mode 100755 (executable)
index 0000000..0942bac
--- /dev/null
@@ -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"
diff --git a/tests/zfs-tests/tests/functional/cli_root/zfs_destroy/zfs_destroy_common.kshlib b/tests/zfs-tests/tests/functional/cli_root/zfs_destroy/zfs_destroy_common.kshlib
new file mode 100644 (file)
index 0000000..ba3c9d4
--- /dev/null
@@ -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/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
+               block_device_wait
+
+               $ECHO "y" | $NEWFS $ZVOL_DEVDIR/$VOL > /dev/null 2>&1
+               if (( $? == 0 )); then
+                       log_note "SUCCESS: $NEWFS $ZVOL_DEVDIR/$VOL>/dev/null"
+               else
+                       log_fail "$NEWFS $ZVOL_DEVDIR/$VOL > /dev/null"
+               fi
+
+               if [[ ! -d $TESTDIR1 ]]; then
+                       log_must $MKDIR $TESTDIR1
+               fi
+               log_must $MOUNT $ZVOL_DEVDIR/$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
+}
diff --git a/tests/zfs-tests/tests/functional/cli_root/zfs_get/Makefile.am b/tests/zfs-tests/tests/functional/cli_root/zfs_get/Makefile.am
new file mode 100644 (file)
index 0000000..880a845
--- /dev/null
@@ -0,0 +1,16 @@
+pkgdatadir = $(datadir)/@PACKAGE@/zfs-tests/tests/functional/cli_root/zfs_get
+dist_pkgdata_SCRIPTS = \
+       zfs_get_common.kshlib \
+       zfs_get_list_d.kshlib \
+       setup.ksh \
+       cleanup.ksh \
+       zfs_get_001_pos.ksh \
+       zfs_get_002_pos.ksh \
+       zfs_get_003_pos.ksh \
+       zfs_get_004_pos.ksh \
+       zfs_get_005_neg.ksh \
+       zfs_get_006_neg.ksh \
+       zfs_get_007_neg.ksh \
+       zfs_get_008_pos.ksh \
+       zfs_get_009_pos.ksh \
+       zfs_get_010_neg.ksh
diff --git a/tests/zfs-tests/tests/functional/cli_root/zfs_get/cleanup.ksh b/tests/zfs-tests/tests/functional/cli_root/zfs_get/cleanup.ksh
new file mode 100755 (executable)
index 0000000..79cd6e9
--- /dev/null
@@ -0,0 +1,30 @@
+#!/bin/ksh -p
+#
+# CDDL HEADER START
+#
+# The contents of this file are subject to the terms of the
+# Common Development and Distribution License (the "License").
+# You may not use this file except in compliance with the License.
+#
+# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
+# or http://www.opensolaris.org/os/licensing.
+# See the License for the specific language governing permissions
+# and limitations under the License.
+#
+# When distributing Covered Code, include this CDDL HEADER in each
+# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
+# If applicable, add the following below this CDDL HEADER, with the
+# fields enclosed by brackets "[]" replaced with your own identifying
+# information: 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
diff --git a/tests/zfs-tests/tests/functional/cli_root/zfs_get/setup.ksh b/tests/zfs-tests/tests/functional/cli_root/zfs_get/setup.ksh
new file mode 100755 (executable)
index 0000000..9692385
--- /dev/null
@@ -0,0 +1,32 @@
+#!/bin/ksh -p
+#
+# CDDL HEADER START
+#
+# The contents of this file are subject to the terms of the
+# Common Development and Distribution License (the "License").
+# You may not use this file except in compliance with the License.
+#
+# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
+# or http://www.opensolaris.org/os/licensing.
+# See the License for the specific language governing permissions
+# and limitations under the License.
+#
+# When distributing Covered Code, include this CDDL HEADER in each
+# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
+# If applicable, add the following below this CDDL HEADER, with the
+# fields enclosed by brackets "[]" replaced with your own identifying
+# information: 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
diff --git a/tests/zfs-tests/tests/functional/cli_root/zfs_get/zfs_get_001_pos.ksh b/tests/zfs-tests/tests/functional/cli_root/zfs_get/zfs_get_001_pos.ksh
new file mode 100755 (executable)
index 0000000..dbac854
--- /dev/null
@@ -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 acltype 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."
diff --git a/tests/zfs-tests/tests/functional/cli_root/zfs_get/zfs_get_002_pos.ksh b/tests/zfs-tests/tests/functional/cli_root/zfs_get/zfs_get_002_pos.ksh
new file mode 100755 (executable)
index 0000000..d425a26
--- /dev/null
@@ -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 acltype 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."
diff --git a/tests/zfs-tests/tests/functional/cli_root/zfs_get/zfs_get_003_pos.ksh b/tests/zfs-tests/tests/functional/cli_root/zfs_get/zfs_get_003_pos.ksh
new file mode 100755 (executable)
index 0000000..77a58e1
--- /dev/null
@@ -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."
diff --git a/tests/zfs-tests/tests/functional/cli_root/zfs_get/zfs_get_004_pos.ksh b/tests/zfs-tests/tests/functional/cli_root/zfs_get/zfs_get_004_pos.ksh
new file mode 100755 (executable)
index 0000000..1dce6e9
--- /dev/null
@@ -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."
diff --git a/tests/zfs-tests/tests/functional/cli_root/zfs_get/zfs_get_005_neg.ksh b/tests/zfs-tests/tests/functional/cli_root/zfs_get/zfs_get_005_neg.ksh
new file mode 100755 (executable)
index 0000000..c77f769
--- /dev/null
@@ -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 acltype \
+    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."
diff --git a/tests/zfs-tests/tests/functional/cli_root/zfs_get/zfs_get_006_neg.ksh b/tests/zfs-tests/tests/functional/cli_root/zfs_get/zfs_get_006_neg.ksh
new file mode 100755 (executable)
index 0000000..58b0826
--- /dev/null
@@ -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."
diff --git a/tests/zfs-tests/tests/functional/cli_root/zfs_get/zfs_get_007_neg.ksh b/tests/zfs-tests/tests/functional/cli_root/zfs_get/zfs_get_007_neg.ksh
new file mode 100755 (executable)
index 0000000..850c1ca
--- /dev/null
@@ -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."
diff --git a/tests/zfs-tests/tests/functional/cli_root/zfs_get/zfs_get_008_pos.ksh b/tests/zfs-tests/tests/functional/cli_root/zfs_get/zfs_get_008_pos.ksh
new file mode 100755 (executable)
index 0000000..af1b568
--- /dev/null
@@ -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 \
+       acltype 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"
+
diff --git a/tests/zfs-tests/tests/functional/cli_root/zfs_get/zfs_get_009_pos.ksh b/tests/zfs-tests/tests/functional/cli_root/zfs_get/zfs_get_009_pos.ksh
new file mode 100755 (executable)
index 0000000..11eadaa
--- /dev/null
@@ -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 acltype 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."
+
diff --git a/tests/zfs-tests/tests/functional/cli_root/zfs_get/zfs_get_010_neg.ksh b/tests/zfs-tests/tests/functional/cli_root/zfs_get/zfs_get_010_neg.ksh
new file mode 100755 (executable)
index 0000000..e8c3607
--- /dev/null
@@ -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>'"
+
+
diff --git a/tests/zfs-tests/tests/functional/cli_root/zfs_get/zfs_get_common.kshlib b/tests/zfs-tests/tests/functional/cli_root/zfs_get/zfs_get_common.kshlib
new file mode 100644 (file)
index 0000000..b1978cb
--- /dev/null
@@ -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
+}
diff --git a/tests/zfs-tests/tests/functional/cli_root/zfs_get/zfs_get_list_d.kshlib b/tests/zfs-tests/tests/functional/cli_root/zfs_get/zfs_get_list_d.kshlib
new file mode 100644 (file)
index 0000000..874cfa3
--- /dev/null
@@ -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
+}
+
+
diff --git a/tests/zfs-tests/tests/functional/cli_root/zfs_inherit/Makefile.am b/tests/zfs-tests/tests/functional/cli_root/zfs_inherit/Makefile.am
new file mode 100644 (file)
index 0000000..104ee06
--- /dev/null
@@ -0,0 +1,7 @@
+pkgdatadir = $(datadir)/@PACKAGE@/zfs-tests/tests/functional/cli_root/zfs_inherit
+dist_pkgdata_SCRIPTS = \
+       cleanup.ksh \
+       setup.ksh \
+       zfs_inherit_001_neg.ksh \
+       zfs_inherit_002_neg.ksh \
+       zfs_inherit_003_pos.ksh
diff --git a/tests/zfs-tests/tests/functional/cli_root/zfs_inherit/cleanup.ksh b/tests/zfs-tests/tests/functional/cli_root/zfs_inherit/cleanup.ksh
new file mode 100755 (executable)
index 0000000..79cd6e9
--- /dev/null
@@ -0,0 +1,30 @@
+#!/bin/ksh -p
+#
+# CDDL HEADER START
+#
+# The contents of this file are subject to the terms of the
+# Common Development and Distribution License (the "License").
+# You may not use this file except in compliance with the License.
+#
+# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
+# or http://www.opensolaris.org/os/licensing.
+# See the License for the specific language governing permissions
+# and limitations under the License.
+#
+# When distributing Covered Code, include this CDDL HEADER in each
+# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
+# If applicable, add the following below this CDDL HEADER, with the
+# fields enclosed by brackets "[]" replaced with your own identifying
+# information: 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
diff --git a/tests/zfs-tests/tests/functional/cli_root/zfs_inherit/setup.ksh b/tests/zfs-tests/tests/functional/cli_root/zfs_inherit/setup.ksh
new file mode 100755 (executable)
index 0000000..9692385
--- /dev/null
@@ -0,0 +1,32 @@
+#!/bin/ksh -p
+#
+# CDDL HEADER START
+#
+# The contents of this file are subject to the terms of the
+# Common Development and Distribution License (the "License").
+# You may not use this file except in compliance with the License.
+#
+# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
+# or http://www.opensolaris.org/os/licensing.
+# See the License for the specific language governing permissions
+# and limitations under the License.
+#
+# When distributing Covered Code, include this CDDL HEADER in each
+# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
+# If applicable, add the following below this CDDL HEADER, with the
+# fields enclosed by brackets "[]" replaced with your own identifying
+# information: 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
diff --git a/tests/zfs-tests/tests/functional/cli_root/zfs_inherit/zfs_inherit_001_neg.ksh b/tests/zfs-tests/tests/functional/cli_root/zfs_inherit/zfs_inherit_001_neg.ksh
new file mode 100755 (executable)
index 0000000..891e0e9
--- /dev/null
@@ -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."
diff --git a/tests/zfs-tests/tests/functional/cli_root/zfs_inherit/zfs_inherit_002_neg.ksh b/tests/zfs-tests/tests/functional/cli_root/zfs_inherit/zfs_inherit_002_neg.ksh
new file mode 100755 (executable)
index 0000000..3fefa31
--- /dev/null
@@ -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 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 "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."
diff --git a/tests/zfs-tests/tests/functional/cli_root/zfs_inherit/zfs_inherit_003_pos.ksh b/tests/zfs-tests/tests/functional/cli_root/zfs_inherit/zfs_inherit_003_pos.ksh
new file mode 100755 (executable)
index 0000000..b2f09db
--- /dev/null
@@ -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."
diff --git a/tests/zfs-tests/tests/functional/cli_root/zfs_mount/Makefile.am b/tests/zfs-tests/tests/functional/cli_root/zfs_mount/Makefile.am
new file mode 100644 (file)
index 0000000..c6ae99c
--- /dev/null
@@ -0,0 +1,18 @@
+pkgdatadir = $(datadir)/@PACKAGE@/zfs-tests/tests/functional/cli_root/zfs_mount
+dist_pkgdata_SCRIPTS = \
+       zfs_mount.cfg \
+       zfs_mount.kshlib \
+       setup.ksh \
+       cleanup.ksh \
+       zfs_mount_001_pos.ksh \
+       zfs_mount_002_pos.ksh \
+       zfs_mount_003_pos.ksh \
+       zfs_mount_004_pos.ksh  \
+       zfs_mount_005_pos.ksh \
+       zfs_mount_006_pos.ksh \
+       zfs_mount_007_pos.ksh \
+       zfs_mount_008_pos.ksh \
+       zfs_mount_009_neg.ksh \
+       zfs_mount_010_neg.ksh \
+       zfs_mount_011_neg.ksh \
+       zfs_mount_all_001_pos.ksh
diff --git a/tests/zfs-tests/tests/functional/cli_root/zfs_mount/cleanup.ksh b/tests/zfs-tests/tests/functional/cli_root/zfs_mount/cleanup.ksh
new file mode 100755 (executable)
index 0000000..79cd6e9
--- /dev/null
@@ -0,0 +1,30 @@
+#!/bin/ksh -p
+#
+# CDDL HEADER START
+#
+# The contents of this file are subject to the terms of the
+# Common Development and Distribution License (the "License").
+# You may not use this file except in compliance with the License.
+#
+# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
+# or http://www.opensolaris.org/os/licensing.
+# See the License for the specific language governing permissions
+# and limitations under the License.
+#
+# When distributing Covered Code, include this CDDL HEADER in each
+# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
+# If applicable, add the following below this CDDL HEADER, with the
+# fields enclosed by brackets "[]" replaced with your own identifying
+# information: 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
diff --git a/tests/zfs-tests/tests/functional/cli_root/zfs_mount/setup.ksh b/tests/zfs-tests/tests/functional/cli_root/zfs_mount/setup.ksh
new file mode 100755 (executable)
index 0000000..6a9af3b
--- /dev/null
@@ -0,0 +1,32 @@
+#!/bin/ksh -p
+#
+# CDDL HEADER START
+#
+# The contents of this file are subject to the terms of the
+# Common Development and Distribution License (the "License").
+# You may not use this file except in compliance with the License.
+#
+# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
+# or http://www.opensolaris.org/os/licensing.
+# See the License for the specific language governing permissions
+# and limitations under the License.
+#
+# When distributing Covered Code, include this CDDL HEADER in each
+# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
+# If applicable, add the following below this CDDL HEADER, with the
+# fields enclosed by brackets "[]" replaced with your own identifying
+# information: 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
diff --git a/tests/zfs-tests/tests/functional/cli_root/zfs_mount/zfs_mount.cfg b/tests/zfs-tests/tests/functional/cli_root/zfs_mount/zfs_mount.cfg
new file mode 100644 (file)
index 0000000..c8e4689
--- /dev/null
@@ -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"
diff --git a/tests/zfs-tests/tests/functional/cli_root/zfs_mount/zfs_mount.kshlib b/tests/zfs-tests/tests/functional/cli_root/zfs_mount/zfs_mount.kshlib
new file mode 100644 (file)
index 0000000..2f6194e
--- /dev/null
@@ -0,0 +1,132 @@
+#
+# CDDL HEADER START
+#
+# The contents of this file are subject to the terms of the
+# Common Development and Distribution License (the "License").
+# You may not use this file except in compliance with the License.
+#
+# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
+# or http://www.opensolaris.org/os/licensing.
+# See the License for the specific language governing permissions
+# and limitations under the License.
+#
+# When distributing Covered Code, include this CDDL HEADER in each
+# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
+# If applicable, add the following below this CDDL HEADER, with the
+# fields enclosed by brackets "[]" replaced with your own identifying
+# information: Portions Copyright [yyyy] [name of copyright owner]
+#
+# CDDL HEADER END
+#
+
+#
+# Copyright 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
+                       block_device_wait
+                       ;;
+               *)      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
+}
diff --git a/tests/zfs-tests/tests/functional/cli_root/zfs_mount/zfs_mount_001_pos.ksh b/tests/zfs-tests/tests/functional/cli_root/zfs_mount/zfs_mount_001_pos.ksh
new file mode 100755 (executable)
index 0000000..b474dc8
--- /dev/null
@@ -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."
diff --git a/tests/zfs-tests/tests/functional/cli_root/zfs_mount/zfs_mount_002_pos.ksh b/tests/zfs-tests/tests/functional/cli_root/zfs_mount/zfs_mount_002_pos.ksh
new file mode 100755 (executable)
index 0000000..8b39306
--- /dev/null
@@ -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."
diff --git a/tests/zfs-tests/tests/functional/cli_root/zfs_mount/zfs_mount_003_pos.ksh b/tests/zfs-tests/tests/functional/cli_root/zfs_mount/zfs_mount_003_pos.ksh
new file mode 100755 (executable)
index 0000000..2dd14da
--- /dev/null
@@ -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."
diff --git a/tests/zfs-tests/tests/functional/cli_root/zfs_mount/zfs_mount_004_pos.ksh b/tests/zfs-tests/tests/functional/cli_root/zfs_mount/zfs_mount_004_pos.ksh
new file mode 100755 (executable)
index 0000000..524aed1
--- /dev/null
@@ -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."
diff --git a/tests/zfs-tests/tests/functional/cli_root/zfs_mount/zfs_mount_005_pos.ksh b/tests/zfs-tests/tests/functional/cli_root/zfs_mount/zfs_mount_005_pos.ksh
new file mode 100755 (executable)
index 0000000..1e56104
--- /dev/null
@@ -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."
diff --git a/tests/zfs-tests/tests/functional/cli_root/zfs_mount/zfs_mount_006_pos.ksh b/tests/zfs-tests/tests/functional/cli_root/zfs_mount/zfs_mount_006_pos.ksh
new file mode 100755 (executable)
index 0000000..f8b4021
--- /dev/null
@@ -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."
diff --git a/tests/zfs-tests/tests/functional/cli_root/zfs_mount/zfs_mount_007_pos.ksh b/tests/zfs-tests/tests/functional/cli_root/zfs_mount/zfs_mount_007_pos.ksh
new file mode 100755 (executable)
index 0000000..577de09
--- /dev/null
@@ -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."
diff --git a/tests/zfs-tests/tests/functional/cli_root/zfs_mount/zfs_mount_008_pos.ksh b/tests/zfs-tests/tests/functional/cli_root/zfs_mount/zfs_mount_008_pos.ksh
new file mode 100755 (executable)
index 0000000..a273272
--- /dev/null
@@ -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."
diff --git a/tests/zfs-tests/tests/functional/cli_root/zfs_mount/zfs_mount_009_neg.ksh b/tests/zfs-tests/tests/functional/cli_root/zfs_mount/zfs_mount_009_neg.ksh
new file mode 100755 (executable)
index 0000000..c6a372a
--- /dev/null
@@ -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."
diff --git a/tests/zfs-tests/tests/functional/cli_root/zfs_mount/zfs_mount_010_neg.ksh b/tests/zfs-tests/tests/functional/cli_root/zfs_mount/zfs_mount_010_neg.ksh
new file mode 100755 (executable)
index 0000000..f4cb321
--- /dev/null
@@ -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."
diff --git a/tests/zfs-tests/tests/functional/cli_root/zfs_mount/zfs_mount_011_neg.ksh b/tests/zfs-tests/tests/functional/cli_root/zfs_mount/zfs_mount_011_neg.ksh
new file mode 100755 (executable)
index 0000000..97fc4b3
--- /dev/null
@@ -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."
diff --git a/tests/zfs-tests/tests/functional/cli_root/zfs_mount/zfs_mount_all_001_pos.ksh b/tests/zfs-tests/tests/functional/cli_root/zfs_mount/zfs_mount_all_001_pos.ksh
new file mode 100755 (executable)
index 0000000..8973558
--- /dev/null
@@ -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."
diff --git a/tests/zfs-tests/tests/functional/cli_root/zfs_promote/Makefile.am b/tests/zfs-tests/tests/functional/cli_root/zfs_promote/Makefile.am
new file mode 100644 (file)
index 0000000..fa0eae7
--- /dev/null
@@ -0,0 +1,13 @@
+pkgdatadir = $(datadir)/@PACKAGE@/zfs-tests/tests/functional/cli_root/zfs_promote
+dist_pkgdata_SCRIPTS = \
+       zfs_promote.cfg \
+       setup.ksh \
+       cleanup.ksh \
+       zfs_promote_001_pos.ksh \
+       zfs_promote_002_pos.ksh \
+       zfs_promote_003_pos.ksh \
+       zfs_promote_004_pos.ksh \
+       zfs_promote_005_pos.ksh \
+       zfs_promote_006_neg.ksh \
+       zfs_promote_007_neg.ksh \
+       zfs_promote_008_pos.ksh
diff --git a/tests/zfs-tests/tests/functional/cli_root/zfs_promote/cleanup.ksh b/tests/zfs-tests/tests/functional/cli_root/zfs_promote/cleanup.ksh
new file mode 100755 (executable)
index 0000000..79cd6e9
--- /dev/null
@@ -0,0 +1,30 @@
+#!/bin/ksh -p
+#
+# CDDL HEADER START
+#
+# The contents of this file are subject to the terms of the
+# Common Development and Distribution License (the "License").
+# You may not use this file except in compliance with the License.
+#
+# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
+# or http://www.opensolaris.org/os/licensing.
+# See the License for the specific language governing permissions
+# and limitations under the License.
+#
+# When distributing Covered Code, include this CDDL HEADER in each
+# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
+# If applicable, add the following below this CDDL HEADER, with the
+# fields enclosed by brackets "[]" replaced with your own identifying
+# information: 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
diff --git a/tests/zfs-tests/tests/functional/cli_root/zfs_promote/setup.ksh b/tests/zfs-tests/tests/functional/cli_root/zfs_promote/setup.ksh
new file mode 100755 (executable)
index 0000000..3e2e2ce
--- /dev/null
@@ -0,0 +1,32 @@
+#!/bin/ksh -p
+#
+# CDDL HEADER START
+#
+# The contents of this file are subject to the terms of the
+# Common Development and Distribution License (the "License").
+# You may not use this file except in compliance with the License.
+#
+# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
+# or http://www.opensolaris.org/os/licensing.
+# See the License for the specific language governing permissions
+# and limitations under the License.
+#
+# When distributing Covered Code, include this CDDL HEADER in each
+# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
+# If applicable, add the following below this CDDL HEADER, with the
+# fields enclosed by brackets "[]" replaced with your own identifying
+# information: 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}
diff --git a/tests/zfs-tests/tests/functional/cli_root/zfs_promote/zfs_promote.cfg b/tests/zfs-tests/tests/functional/cli_root/zfs_promote/zfs_promote.cfg
new file mode 100644 (file)
index 0000000..6407328
--- /dev/null
@@ -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
+
+
diff --git a/tests/zfs-tests/tests/functional/cli_root/zfs_promote/zfs_promote_001_pos.ksh b/tests/zfs-tests/tests/functional/cli_root/zfs_promote/zfs_promote_001_pos.ksh
new file mode 100755 (executable)
index 0000000..2c2b9a5
--- /dev/null
@@ -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."
+
diff --git a/tests/zfs-tests/tests/functional/cli_root/zfs_promote/zfs_promote_002_pos.ksh b/tests/zfs-tests/tests/functional/cli_root/zfs_promote/zfs_promote_002_pos.ksh
new file mode 100755 (executable)
index 0000000..b6ff94b
--- /dev/null
@@ -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."
+
diff --git a/tests/zfs-tests/tests/functional/cli_root/zfs_promote/zfs_promote_003_pos.ksh b/tests/zfs-tests/tests/functional/cli_root/zfs_promote/zfs_promote_003_pos.ksh
new file mode 100755 (executable)
index 0000000..44a6aa9
--- /dev/null
@@ -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."
+
diff --git a/tests/zfs-tests/tests/functional/cli_root/zfs_promote/zfs_promote_004_pos.ksh b/tests/zfs-tests/tests/functional/cli_root/zfs_promote/zfs_promote_004_pos.ksh
new file mode 100755 (executable)
index 0000000..a90da8e
--- /dev/null
@@ -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."
+
diff --git a/tests/zfs-tests/tests/functional/cli_root/zfs_promote/zfs_promote_005_pos.ksh b/tests/zfs-tests/tests/functional/cli_root/zfs_promote/zfs_promote_005_pos.ksh
new file mode 100755 (executable)
index 0000000..e505951
--- /dev/null
@@ -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."
diff --git a/tests/zfs-tests/tests/functional/cli_root/zfs_promote/zfs_promote_006_neg.ksh b/tests/zfs-tests/tests/functional/cli_root/zfs_promote/zfs_promote_006_neg.ksh
new file mode 100755 (executable)
index 0000000..9c1fb3e
--- /dev/null
@@ -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."
diff --git a/tests/zfs-tests/tests/functional/cli_root/zfs_promote/zfs_promote_007_neg.ksh b/tests/zfs-tests/tests/functional/cli_root/zfs_promote/zfs_promote_007_neg.ksh
new file mode 100755 (executable)
index 0000000..83a5231
--- /dev/null
@@ -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."
+
diff --git a/tests/zfs-tests/tests/functional/cli_root/zfs_promote/zfs_promote_008_pos.ksh b/tests/zfs-tests/tests/functional/cli_root/zfs_promote/zfs_promote_008_pos.ksh
new file mode 100755 (executable)
index 0000000..e4e6aa6
--- /dev/null
@@ -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."
+
diff --git a/tests/zfs-tests/tests/functional/cli_root/zfs_property/Makefile.am b/tests/zfs-tests/tests/functional/cli_root/zfs_property/Makefile.am
new file mode 100644 (file)
index 0000000..d8a5687
--- /dev/null
@@ -0,0 +1,5 @@
+pkgdatadir = $(datadir)/@PACKAGE@/zfs-tests/tests/functional/cli_root/zfs_property
+dist_pkgdata_SCRIPTS = \
+       setup.ksh \
+       cleanup.ksh \
+       zfs_written_property_001_pos.ksh
diff --git a/tests/zfs-tests/tests/functional/cli_root/zfs_property/cleanup.ksh b/tests/zfs-tests/tests/functional/cli_root/zfs_property/cleanup.ksh
new file mode 100755 (executable)
index 0000000..e499813
--- /dev/null
@@ -0,0 +1,34 @@
+#!/bin/ksh -p
+#
+# CDDL HEADER START
+#
+# The contents of this file are subject to the terms of the
+# Common Development and Distribution License (the "License").
+# You may not use this file except in compliance with the License.
+#
+# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
+# or http://www.opensolaris.org/os/licensing.
+# See the License for the specific language governing permissions
+# and limitations under the License.
+#
+# When distributing Covered Code, include this CDDL HEADER in each
+# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
+# If applicable, add the following below this CDDL HEADER, with the
+# fields enclosed by brackets "[]" replaced with your own identifying
+# information: Portions Copyright [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
diff --git a/tests/zfs-tests/tests/functional/cli_root/zfs_property/setup.ksh b/tests/zfs-tests/tests/functional/cli_root/zfs_property/setup.ksh
new file mode 100755 (executable)
index 0000000..746a050
--- /dev/null
@@ -0,0 +1,36 @@
+#!/bin/ksh -p
+#
+# CDDL HEADER START
+#
+# The contents of this file are subject to the terms of the
+# Common Development and Distribution License (the "License").
+# You may not use this file except in compliance with the License.
+#
+# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
+# or http://www.opensolaris.org/os/licensing.
+# See the License for the specific language governing permissions
+# and limitations under the License.
+#
+# When distributing Covered Code, include this CDDL HEADER in each
+# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
+# If applicable, add the following below this CDDL HEADER, with the
+# fields enclosed by brackets "[]" replaced with your own identifying
+# information: Portions Copyright [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
diff --git a/tests/zfs-tests/tests/functional/cli_root/zfs_property/zfs_written_property_001_pos.ksh b/tests/zfs-tests/tests/functional/cli_root/zfs_property/zfs_written_property_001_pos.ksh
new file mode 100755 (executable)
index 0000000..ad96879
--- /dev/null
@@ -0,0 +1,236 @@
+#!/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
+       log_must $SLEEP 10
+       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
+log_must $SLEEP 10
+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
+log_must $SLEEP 10
+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
+log_must $SLEEP 10
+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
+       log_must $SLEEP 10
+       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
+       log_must $SLEEP 10
+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"
diff --git a/tests/zfs-tests/tests/functional/cli_root/zfs_receive/Makefile.am b/tests/zfs-tests/tests/functional/cli_root/zfs_receive/Makefile.am
new file mode 100644 (file)
index 0000000..533acc6
--- /dev/null
@@ -0,0 +1,13 @@
+pkgdatadir = $(datadir)/@PACKAGE@/zfs-tests/tests/functional/cli_root/zfs_receive
+dist_pkgdata_SCRIPTS = \
+       setup.ksh \
+       cleanup.ksh \
+       zfs_receive_001_pos.ksh \
+       zfs_receive_002_pos.ksh \
+       zfs_receive_003_pos.ksh \
+       zfs_receive_004_neg.ksh \
+       zfs_receive_005_neg.ksh \
+       zfs_receive_006_pos.ksh \
+       zfs_receive_007_neg.ksh \
+       zfs_receive_008_pos.ksh \
+       zfs_receive_009_neg.ksh
diff --git a/tests/zfs-tests/tests/functional/cli_root/zfs_receive/cleanup.ksh b/tests/zfs-tests/tests/functional/cli_root/zfs_receive/cleanup.ksh
new file mode 100755 (executable)
index 0000000..cec69d4
--- /dev/null
@@ -0,0 +1,33 @@
+#!/bin/ksh -p
+#
+# CDDL HEADER START
+#
+# The contents of this file are subject to the terms of the
+# Common Development and Distribution License (the "License").
+# You may not use this file except in compliance with the License.
+#
+# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
+# or http://www.opensolaris.org/os/licensing.
+# See the License for the specific language governing permissions
+# and limitations under the License.
+#
+# When distributing Covered Code, include this CDDL HEADER in each
+# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
+# If applicable, add the following below this CDDL 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
diff --git a/tests/zfs-tests/tests/functional/cli_root/zfs_receive/setup.ksh b/tests/zfs-tests/tests/functional/cli_root/zfs_receive/setup.ksh
new file mode 100755 (executable)
index 0000000..aee38d2
--- /dev/null
@@ -0,0 +1,35 @@
+#!/bin/ksh -p
+#
+# CDDL HEADER START
+#
+# The contents of this file are subject to the terms of the
+# Common Development and Distribution License (the "License").
+# You may not use this file except in compliance with the License.
+#
+# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
+# or http://www.opensolaris.org/os/licensing.
+# See the License for the specific language governing permissions
+# and limitations under the License.
+#
+# When distributing Covered Code, include this CDDL HEADER in each
+# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
+# If applicable, add the following below this CDDL HEADER, with the
+# fields enclosed by brackets "[]" replaced with your own identifying
+# information: 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
diff --git a/tests/zfs-tests/tests/functional/cli_root/zfs_receive/zfs_receive_001_pos.ksh b/tests/zfs-tests/tests/functional/cli_root/zfs_receive/zfs_receive_001_pos.ksh
new file mode 100755 (executable)
index 0000000..288372a
--- /dev/null
@@ -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."
diff --git a/tests/zfs-tests/tests/functional/cli_root/zfs_receive/zfs_receive_002_pos.ksh b/tests/zfs-tests/tests/functional/cli_root/zfs_receive/zfs_receive_002_pos.ksh
new file mode 100755 (executable)
index 0000000..27f9ae2
--- /dev/null
@@ -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."
diff --git a/tests/zfs-tests/tests/functional/cli_root/zfs_receive/zfs_receive_003_pos.ksh b/tests/zfs-tests/tests/functional/cli_root/zfs_receive/zfs_receive_003_pos.ksh
new file mode 100755 (executable)
index 0000000..e7d4bf4
--- /dev/null
@@ -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."
diff --git a/tests/zfs-tests/tests/functional/cli_root/zfs_receive/zfs_receive_004_neg.ksh b/tests/zfs-tests/tests/functional/cli_root/zfs_receive/zfs_receive_004_neg.ksh
new file mode 100755 (executable)
index 0000000..7f1c053
--- /dev/null
@@ -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."
diff --git a/tests/zfs-tests/tests/functional/cli_root/zfs_receive/zfs_receive_005_neg.ksh b/tests/zfs-tests/tests/functional/cli_root/zfs_receive/zfs_receive_005_neg.ksh
new file mode 100755 (executable)
index 0000000..86bd944
--- /dev/null
@@ -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."
diff --git a/tests/zfs-tests/tests/functional/cli_root/zfs_receive/zfs_receive_006_pos.ksh b/tests/zfs-tests/tests/functional/cli_root/zfs_receive/zfs_receive_006_pos.ksh
new file mode 100755 (executable)
index 0000000..8f973b1
--- /dev/null
@@ -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."
diff --git a/tests/zfs-tests/tests/functional/cli_root/zfs_receive/zfs_receive_007_neg.ksh b/tests/zfs-tests/tests/functional/cli_root/zfs_receive/zfs_receive_007_neg.ksh
new file mode 100755 (executable)
index 0000000..b2f6dc6
--- /dev/null
@@ -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"
diff --git a/tests/zfs-tests/tests/functional/cli_root/zfs_receive/zfs_receive_008_pos.ksh b/tests/zfs-tests/tests/functional/cli_root/zfs_receive/zfs_receive_008_pos.ksh
new file mode 100755 (executable)
index 0000000..6d9081e
--- /dev/null
@@ -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."
diff --git a/tests/zfs-tests/tests/functional/cli_root/zfs_receive/zfs_receive_009_neg.ksh b/tests/zfs-tests/tests/functional/cli_root/zfs_receive/zfs_receive_009_neg.ksh
new file mode 100755 (executable)
index 0000000..8d4b89b
--- /dev/null
@@ -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."
diff --git a/tests/zfs-tests/tests/functional/cli_root/zfs_receive/zfs_receive_010_pos.ksh b/tests/zfs-tests/tests/functional/cli_root/zfs_receive/zfs_receive_010_pos.ksh
new file mode 100755 (executable)
index 0000000..b1fbff2
--- /dev/null
@@ -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 (c) 2015 by Delphix. All rights reserved.
+#
+
+. $STF_SUITE/include/libtest.shlib
+
+#
+# DESCRIPTION:
+# Test that receiving a full send as a clone works correctly.
+#
+# STRATEGY:
+# 1. Create pool and filesystems.
+# 2. Send filesystem, receive as clone of itself.
+# 3. Verify that nop-write saves space.
+# 4. Send filesystem, receive as clone of other filesystem.
+# 5. Verify that contents are correct.
+# 6. Repeat steps 4 and 5 with filesystems swapped.
+#
+
+verify_runnable "both"
+
+fs=$TESTPOOL/$TESTFS/base/fs
+fs2=$TESTPOOL/$TESTFS/base/fs2
+rfs=$TESTPOOL/$TESTFS/base/rfs
+
+function make_object
+{
+       local objnum=$1
+       local mntpnt=$2
+       local type=$3
+       if [[ $type == "file" ]]; then
+               $DD if=/dev/urandom of=${mntpnt}/f$objnum bs=512 count=16
+       elif [[ $type == "hole1" ]]; then
+               $DD if=/dev/urandom of=${mntpnt}/fh$objnum bs=512 count=5 stride=4
+       elif [[ $type == "hole2" ]]; then
+               $DD if=/dev/urandom of=${mntpnt}/fh$objnum bs=512 count=4 stride=5
+       elif [[ $type == "directory" ]]; then
+               $MKDIR ${mntpnt}/d$objnum
+       elif [[ $type == "missing" ]]; then
+               $TOUCH ${mntpnt}/h$objnum
+       fi
+}
+
+function create_pair
+{
+       local objnum=$1
+       local mntpnt1=$2
+       local mntpnt2=$3
+       local type1=$4
+       local type2=$5
+       make_object $objnum $mntpnt1 $type1
+       make_object $objnum $mntpnt2 $type2
+}
+
+function cleanup
+{
+       $ZFS destroy -Rf $TESTPOOL/$TESTFS/base
+       rm /tmp/zr010p*
+}
+
+log_assert "zfs receive of full send as clone should work"
+log_onexit cleanup
+log_must $ZFS create -o checksum=sha256 -o compression=gzip -o recordsize=512 \
+       $TESTPOOL/$TESTFS/base
+
+log_must $ZFS create $fs
+log_must $ZFS create $fs2
+mntpnt=$(get_prop mountpoint $fs)
+mntpnt2=$(get_prop mountpoint $fs2)
+
+#
+# Now, we create the two filesystems.  By creating objects with
+# different types and the same object number in each filesystem, we
+# create a situation where, when you receive the full send of each as
+# a clone of the other, we will test to ensure that the code correctly
+# handles receiving all object types onto all other object types.
+#
+
+# Receive a file onto a file (and vice versa).
+create_pair 8 $mntpnt $mntpnt2 "file" "file"
+
+# Receive a file onto a file with holes (and vice versa).
+create_pair 9 $mntpnt $mntpnt2 "file" "hole1"
+
+# Receive a file onto a directory (and vice versa).
+create_pair 10 $mntpnt $mntpnt2 "file" "directory"
+
+# Receive a file onto a missing object (and vice versa).
+create_pair 11 $mntpnt $mntpnt2 "file" "missing"
+
+# Receive a file with holes onto a file with holes (and vice versa).
+create_pair 12 $mntpnt $mntpnt2 "hole1" "hole2"
+
+# Receive a file with holes onto a directory (and vice versa).
+create_pair 13 $mntpnt $mntpnt2 "hole1" "directory"
+
+# Receive a file with holes onto a missing object (and vice versa).
+create_pair 14 $mntpnt $mntpnt2 "hole1" "missing"
+
+# Receive a directory onto a directory (and vice versa).
+create_pair 15 $mntpnt $mntpnt2 "directory" "directory"
+
+# Receive a directory onto a missing object (and vice versa).
+create_pair 16 $mntpnt $mntpnt2 "directory" "missing"
+
+# Receive a missing object onto a missing object (and vice versa).
+create_pair 17 $mntpnt $mntpnt2 "missing" "missing"
+
+# Receive a file with a different record size onto a file (and vice versa).
+log_must $ZFS set recordsize=128k $fs
+$DD if=/dev/urandom of=$mntpnt/f18 bs=128k count=64
+$TOUCH $mntpnt2/f18
+
+# Remove objects that are intended to be missing.
+$RM $mntpnt/h17
+$RM $mntpnt2/h*
+
+# Add empty objects to $fs to exercise dmu_traverse code
+for i in `seq 1 100`; do
+       log_must touch $mntpnt/uf$i
+done
+
+log_must $ZFS snapshot $fs@s1
+log_must $ZFS snapshot $fs2@s1
+
+log_must $ZFS send $fs@s1 > /tmp/zr010p
+log_must $ZFS send $fs2@s1 > /tmp/zr010p2
+
+
+#
+# Test that, when we receive a full send as a clone of itself,
+# nop-write saves us all the space used by data blocks.
+#
+cat /tmp/zr010p | log_must $ZFS receive -o origin=$fs@s1 $rfs
+size=$(get_prop used $rfs)
+size2=$(get_prop used $fs)
+if [[ $size -ge $(($size2 / 10)) ]] then
+        log_fail "nop-write failure; expected usage less than "\
+               "$(($size2 / 10)), but is using $size"
+fi
+log_must $ZFS destroy -fr $rfs
+
+# Correctness testing: receive each full send as a clone of the other fiesystem.
+cat /tmp/zr010p | log_must $ZFS receive -o origin=$fs2@s1 $rfs
+mntpnt_old=$(get_prop mountpoint $fs)
+mntpnt_new=$(get_prop mountpoint $rfs)
+log_must $DIFF -r $mntpnt_old $mntpnt_new
+log_must $ZFS destroy -r $rfs
+
+cat /tmp/zr010p2 | log_must $ZFS receive -o origin=$fs@s1 $rfs
+mntpnt_old=$(get_prop mountpoint $fs2)
+mntpnt_new=$(get_prop mountpoint $rfs)
+log_must $DIFF -r $mntpnt_old $mntpnt_new
+
+log_pass "zfs receive of full send as clone works"
diff --git a/tests/zfs-tests/tests/functional/cli_root/zfs_receive/zfs_receive_011_pos.ksh b/tests/zfs-tests/tests/functional/cli_root/zfs_receive/zfs_receive_011_pos.ksh
new file mode 100755 (executable)
index 0000000..b905a87
--- /dev/null
@@ -0,0 +1,84 @@
+#!/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 2015, OmniTI Computer Consulting, Inc. All rights reserved.
+#
+
+. $STF_SUITE/include/libtest.shlib
+
+#
+# DESCRIPTION:
+#      refquota should be sent-and-received, but it should not interfere with
+#      the receipt of intermediate snapshots that may have preceded the
+#      final snapshot, where the refquota should hold.
+#
+# STRATEGY:
+#      1. Create a filesystem.
+#      2. Create two equal-sized large files.
+#      3. Snapshot the filesystem.
+#      4. Remove one of the two large files.
+#      5. Create a refquota larger than one file, but smaller than both.
+#      6. Snapshot the filesystem again.
+#      7. Send a replication stream of the second snapshot to a new filesystem.
+#
+#
+
+verify_runnable "both"
+
+typeset streamfile=/var/tmp/streamfile.$$
+
+function cleanup
+{
+       log_must $RM $streamfile
+       log_must $ZFS destroy -rf $TESTPOOL/$TESTFS1
+       log_must $ZFS destroy -rf $TESTPOOL/$TESTFS2
+}
+
+log_assert "refquota is properly sent-and-received, regardless of any " \
+       "intermediate snapshots sent by a replication stream."
+log_onexit cleanup
+
+orig=$TESTPOOL/$TESTFS1
+dest=$TESTPOOL/$TESTFS2
+#      1. Create a filesystem.
+log_must $ZFS create $orig
+origdir=$(get_prop mountpoint $orig)
+
+#      2. Create two equal-sized large files.
+log_must $MKFILE 5M $origdir/file1
+log_must $MKFILE 5M $origdir/file2
+log_must $SYNC
+
+#      3. Snapshot the filesystem.
+log_must $ZFS snapshot $orig@1
+
+#      4. Remove one of the two large files.
+log_must $RM $origdir/file2
+log_must $SYNC
+
+#      5. Create a refquota larger than one file, but smaller than both.
+log_must $ZFS set refquota=8M $orig
+
+#      6. Snapshot the filesystem again.
+log_must $ZFS snapshot $orig@2
+
+#      7. Send a replication stream of the second snapshot to a new filesystem.
+log_must eval "$ZFS send -R $orig@2 > $streamfile"
+log_must eval "$ZFS recv $dest < $streamfile"
+
+log_pass "refquota is properly sent-and-received, regardless of any " \
+       "intermediate snapshots sent by a replication stream."
diff --git a/tests/zfs-tests/tests/functional/cli_root/zfs_receive/zfs_receive_012_pos.ksh b/tests/zfs-tests/tests/functional/cli_root/zfs_receive/zfs_receive_012_pos.ksh
new file mode 100755 (executable)
index 0000000..af9f91e
--- /dev/null
@@ -0,0 +1,83 @@
+#!/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 2016, OmniTI Computer Consulting, Inc. All rights reserved.
+#
+
+. $STF_SUITE/include/libtest.shlib
+
+#
+# DESCRIPTION:
+#      refquota, like regular quota, is loosely enforced.  A dataset
+#      can exceed its refquota by one transaction.  This loose enforcement
+#      used to cause problems upon receiving a datastream where its
+#      refquota is slightly exceeded.  This test confirms that we can
+#      successfully receive a slightly over refquota stream.
+#
+# STRATEGY:
+#      1. Create a filesystem.
+#      2. Set a refquota.
+#      3. Snapshot the filesystem.
+#      4. Send a replication stream to a new filesystem.
+#      5. On the original filesystem, fill it up to its quota.
+#      6. Snapshot the original filesystem again.
+#      7. Send an incremental stream to the same new filesystem.
+#
+
+verify_runnable "both"
+
+typeset streamfile=/var/tmp/streamfile.$$
+
+function cleanup
+{
+       log_must $RM $streamfile
+       log_must $ZFS destroy -rf $TESTPOOL/$TESTFS1
+       log_must $ZFS destroy -rf $TESTPOOL/$TESTFS2
+}
+
+log_assert "The allowable slight refquota overage is properly sent-and-" \
+       "received."
+log_onexit cleanup
+
+orig=$TESTPOOL/$TESTFS1
+dest=$TESTPOOL/$TESTFS2
+
+#      1. Create a filesystem.
+log_must $ZFS create $orig
+origdir=$(get_prop mountpoint $orig)
+
+#      2. Set a refquota.
+log_must $ZFS set refquota=50M $orig
+
+#      3. Snapshot the filesystem.
+log_must $ZFS snapshot $orig@1
+
+#      4. Send a replication stream to a new filesystem.
+log_must eval "$ZFS send -R $orig@1 > $streamfile"
+log_must eval "$ZFS recv $dest < $streamfile"
+
+#      5. On the original filesystem, fill it up to its quota.
+cat < /dev/urandom > $origdir/fill-it-up
+
+#      6. Snapshot the original filesystem again.
+log_must $ZFS snapshot $orig@2
+
+#      7. Send an incremental stream to the same new filesystem.
+log_must eval "$ZFS send -I 1 -R $orig@2 > $streamfile"
+log_must eval "$ZFS recv $dest < $streamfile"
+
+log_pass "Verified receiving a slightly-over-refquota stream succeeds."
diff --git a/tests/zfs-tests/tests/functional/cli_root/zfs_rename/Makefile.am b/tests/zfs-tests/tests/functional/cli_root/zfs_rename/Makefile.am
new file mode 100644 (file)
index 0000000..fec9560
--- /dev/null
@@ -0,0 +1,19 @@
+pkgdatadir = $(datadir)/@PACKAGE@/zfs-tests/tests/functional/cli_root/zfs_rename
+dist_pkgdata_SCRIPTS = \
+       zfs_rename.cfg \
+       zfs_rename.kshlib \
+       setup.ksh \
+       cleanup.ksh \
+       zfs_rename_001_pos.ksh \
+       zfs_rename_002_pos.ksh \
+       zfs_rename_003_pos.ksh \
+       zfs_rename_004_neg.ksh \
+       zfs_rename_005_neg.ksh \
+       zfs_rename_006_pos.ksh \
+       zfs_rename_007_pos.ksh \
+       zfs_rename_008_pos.ksh \
+       zfs_rename_009_neg.ksh \
+       zfs_rename_010_neg.ksh \
+       zfs_rename_011_pos.ksh \
+       zfs_rename_012_neg.ksh \
+       zfs_rename_013_pos.ksh
diff --git a/tests/zfs-tests/tests/functional/cli_root/zfs_rename/cleanup.ksh b/tests/zfs-tests/tests/functional/cli_root/zfs_rename/cleanup.ksh
new file mode 100755 (executable)
index 0000000..9316154
--- /dev/null
@@ -0,0 +1,39 @@
+#!/bin/ksh -p
+#
+# CDDL HEADER START
+#
+# The contents of this file are subject to the terms of the
+# Common Development and Distribution License (the "License").
+# You may not use this file except in compliance with the License.
+#
+# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
+# or http://www.opensolaris.org/os/licensing.
+# See the License for the specific language governing permissions
+# and limitations under the License.
+#
+# When distributing Covered Code, include this CDDL HEADER in each
+# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
+# If applicable, add the following below this CDDL HEADER, with the
+# fields enclosed by brackets "[]" replaced with your own identifying
+# information: 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
diff --git a/tests/zfs-tests/tests/functional/cli_root/zfs_rename/setup.ksh b/tests/zfs-tests/tests/functional/cli_root/zfs_rename/setup.ksh
new file mode 100755 (executable)
index 0000000..dee3af8
--- /dev/null
@@ -0,0 +1,49 @@
+#!/bin/ksh -p
+#
+# CDDL HEADER START
+#
+# The contents of this file are subject to the terms of the
+# Common Development and Distribution License (the "License").
+# You may not use this file except in compliance with the License.
+#
+# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
+# or http://www.opensolaris.org/os/licensing.
+# See the License for the specific language governing permissions
+# and limitations under the License.
+#
+# When distributing Covered Code, include this CDDL HEADER in each
+# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
+# If applicable, add the following below this CDDL HEADER, with the
+# fields enclosed by brackets "[]" replaced with your own identifying
+# information: Portions Copyright [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
diff --git a/tests/zfs-tests/tests/functional/cli_root/zfs_rename/zfs_rename.cfg b/tests/zfs-tests/tests/functional/cli_root/zfs_rename/zfs_rename.cfg
new file mode 100644 (file)
index 0000000..8c33b58
--- /dev/null
@@ -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=$ZVOL_RDEVDIR/$TESTPOOL/$TESTVOL
+export VOLDATA=$TESTDIR2/voldata.rename
diff --git a/tests/zfs-tests/tests/functional/cli_root/zfs_rename/zfs_rename.kshlib b/tests/zfs-tests/tests/functional/cli_root/zfs_rename/zfs_rename.kshlib
new file mode 100644 (file)
index 0000000..e363607
--- /dev/null
@@ -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 $?
+}
+
diff --git a/tests/zfs-tests/tests/functional/cli_root/zfs_rename/zfs_rename_001_pos.ksh b/tests/zfs-tests/tests/functional/cli_root/zfs_rename/zfs_rename_001_pos.ksh
new file mode 100755 (executable)
index 0000000..dc178c4
--- /dev/null
@@ -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."
diff --git a/tests/zfs-tests/tests/functional/cli_root/zfs_rename/zfs_rename_002_pos.ksh b/tests/zfs-tests/tests/functional/cli_root/zfs_rename/zfs_rename_002_pos.ksh
new file mode 100755 (executable)
index 0000000..6646df5
--- /dev/null
@@ -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."
diff --git a/tests/zfs-tests/tests/functional/cli_root/zfs_rename/zfs_rename_003_pos.ksh b/tests/zfs-tests/tests/functional/cli_root/zfs_rename/zfs_rename_003_pos.ksh
new file mode 100755 (executable)
index 0000000..9660641
--- /dev/null
@@ -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."
diff --git a/tests/zfs-tests/tests/functional/cli_root/zfs_rename/zfs_rename_004_neg.ksh b/tests/zfs-tests/tests/functional/cli_root/zfs_rename/zfs_rename_004_neg.ksh
new file mode 100755 (executable)
index 0000000..19f8a80
--- /dev/null
@@ -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."
diff --git a/tests/zfs-tests/tests/functional/cli_root/zfs_rename/zfs_rename_005_neg.ksh b/tests/zfs-tests/tests/functional/cli_root/zfs_rename/zfs_rename_005_neg.ksh
new file mode 100755 (executable)
index 0000000..6010af1
--- /dev/null
@@ -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."
diff --git a/tests/zfs-tests/tests/functional/cli_root/zfs_rename/zfs_rename_006_pos.ksh b/tests/zfs-tests/tests/functional/cli_root/zfs_rename/zfs_rename_006_pos.ksh
new file mode 100755 (executable)
index 0000000..5f6cdd5
--- /dev/null
@@ -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."
diff --git a/tests/zfs-tests/tests/functional/cli_root/zfs_rename/zfs_rename_007_pos.ksh b/tests/zfs-tests/tests/functional/cli_root/zfs_rename/zfs_rename_007_pos.ksh
new file mode 100755 (executable)
index 0000000..425422f
--- /dev/null
@@ -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=$ZVOL_DEVDIR/$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/urandom 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."
diff --git a/tests/zfs-tests/tests/functional/cli_root/zfs_rename/zfs_rename_008_pos.ksh b/tests/zfs-tests/tests/functional/cli_root/zfs_rename/zfs_rename_008_pos.ksh
new file mode 100755 (executable)
index 0000000..2552acc
--- /dev/null
@@ -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."
diff --git a/tests/zfs-tests/tests/functional/cli_root/zfs_rename/zfs_rename_009_neg.ksh b/tests/zfs-tests/tests/functional/cli_root/zfs_rename/zfs_rename_009_neg.ksh
new file mode 100755 (executable)
index 0000000..16d306d
--- /dev/null
@@ -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."
diff --git a/tests/zfs-tests/tests/functional/cli_root/zfs_rename/zfs_rename_010_neg.ksh b/tests/zfs-tests/tests/functional/cli_root/zfs_rename/zfs_rename_010_neg.ksh
new file mode 100755 (executable)
index 0000000..2b96662
--- /dev/null
@@ -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."
diff --git a/tests/zfs-tests/tests/functional/cli_root/zfs_rename/zfs_rename_011_pos.ksh b/tests/zfs-tests/tests/functional/cli_root/zfs_rename/zfs_rename_011_pos.ksh
new file mode 100755 (executable)
index 0000000..e453e83
--- /dev/null
@@ -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"
diff --git a/tests/zfs-tests/tests/functional/cli_root/zfs_rename/zfs_rename_012_neg.ksh b/tests/zfs-tests/tests/functional/cli_root/zfs_rename/zfs_rename_012_neg.ksh
new file mode 100755 (executable)
index 0000000..495f663
--- /dev/null
@@ -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."
diff --git a/tests/zfs-tests/tests/functional/cli_root/zfs_rename/zfs_rename_013_pos.ksh b/tests/zfs-tests/tests/functional/cli_root/zfs_rename/zfs_rename_013_pos.ksh
new file mode 100755 (executable)
index 0000000..3189be5
--- /dev/null
@@ -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."
+
diff --git a/tests/zfs-tests/tests/functional/cli_root/zfs_reservation/Makefile.am b/tests/zfs-tests/tests/functional/cli_root/zfs_reservation/Makefile.am
new file mode 100644 (file)
index 0000000..5b7b758
--- /dev/null
@@ -0,0 +1,6 @@
+pkgdatadir = $(datadir)/@PACKAGE@/zfs-tests/tests/functional/cli_root/zfs_reservation
+dist_pkgdata_SCRIPTS = \
+       setup.ksh \
+       cleanup.ksh \
+       zfs_reservation_001_pos.ksh \
+       zfs_reservation_002_pos.ksh
diff --git a/tests/zfs-tests/tests/functional/cli_root/zfs_reservation/cleanup.ksh b/tests/zfs-tests/tests/functional/cli_root/zfs_reservation/cleanup.ksh
new file mode 100755 (executable)
index 0000000..79cd6e9
--- /dev/null
@@ -0,0 +1,30 @@
+#!/bin/ksh -p
+#
+# CDDL HEADER START
+#
+# The contents of this file are subject to the terms of the
+# Common Development and Distribution License (the "License").
+# You may not use this file except in compliance with the License.
+#
+# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
+# or http://www.opensolaris.org/os/licensing.
+# See the License for the specific language governing permissions
+# and limitations under the License.
+#
+# When distributing Covered Code, include this CDDL HEADER in each
+# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
+# If applicable, add the following below this CDDL HEADER, with the
+# fields enclosed by brackets "[]" replaced with your own identifying
+# information: 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
diff --git a/tests/zfs-tests/tests/functional/cli_root/zfs_reservation/setup.ksh b/tests/zfs-tests/tests/functional/cli_root/zfs_reservation/setup.ksh
new file mode 100755 (executable)
index 0000000..6a9af3b
--- /dev/null
@@ -0,0 +1,32 @@
+#!/bin/ksh -p
+#
+# CDDL HEADER START
+#
+# The contents of this file are subject to the terms of the
+# Common Development and Distribution License (the "License").
+# You may not use this file except in compliance with the License.
+#
+# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
+# or http://www.opensolaris.org/os/licensing.
+# See the License for the specific language governing permissions
+# and limitations under the License.
+#
+# When distributing Covered Code, include this CDDL HEADER in each
+# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
+# If applicable, add the following below this CDDL HEADER, with the
+# fields enclosed by brackets "[]" replaced with your own identifying
+# information: 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
diff --git a/tests/zfs-tests/tests/functional/cli_root/zfs_reservation/zfs_reservation_001_pos.ksh b/tests/zfs-tests/tests/functional/cli_root/zfs_reservation/zfs_reservation_001_pos.ksh
new file mode 100755 (executable)
index 0000000..d3a6a00
--- /dev/null
@@ -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"
diff --git a/tests/zfs-tests/tests/functional/cli_root/zfs_reservation/zfs_reservation_002_pos.ksh b/tests/zfs-tests/tests/functional/cli_root/zfs_reservation/zfs_reservation_002_pos.ksh
new file mode 100755 (executable)
index 0000000..d308f75
--- /dev/null
@@ -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'"
diff --git a/tests/zfs-tests/tests/functional/cli_root/zfs_rollback/Makefile.am b/tests/zfs-tests/tests/functional/cli_root/zfs_rollback/Makefile.am
new file mode 100644 (file)
index 0000000..857959b
--- /dev/null
@@ -0,0 +1,10 @@
+pkgdatadir = $(datadir)/@PACKAGE@/zfs-tests/tests/functional/cli_root/zfs_rollback
+dist_pkgdata_SCRIPTS = \
+       zfs_rollback.cfg \
+       zfs_rollback_common.kshlib \
+       setup.ksh \
+       cleanup.ksh \
+       zfs_rollback_001_pos.ksh \
+       zfs_rollback_002_pos.ksh \
+       zfs_rollback_003_neg.ksh \
+       zfs_rollback_004_neg.ksh
diff --git a/tests/zfs-tests/tests/functional/cli_root/zfs_rollback/cleanup.ksh b/tests/zfs-tests/tests/functional/cli_root/zfs_rollback/cleanup.ksh
new file mode 100755 (executable)
index 0000000..707e8f1
--- /dev/null
@@ -0,0 +1,32 @@
+#!/bin/ksh -p
+#
+# CDDL HEADER START
+#
+# The contents of this file are subject to the terms of the
+# Common Development and Distribution License (the "License").
+# You may not use this file except in compliance with the License.
+#
+# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
+# or http://www.opensolaris.org/os/licensing.
+# See the License for the specific language governing permissions
+# and limitations under the License.
+#
+# When distributing Covered Code, include this CDDL HEADER in each
+# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
+# If applicable, add the following below this CDDL HEADER, with the
+# fields enclosed by brackets "[]" replaced with your own identifying
+# information: 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
diff --git a/tests/zfs-tests/tests/functional/cli_root/zfs_rollback/setup.ksh b/tests/zfs-tests/tests/functional/cli_root/zfs_rollback/setup.ksh
new file mode 100755 (executable)
index 0000000..d3341b1
--- /dev/null
@@ -0,0 +1,31 @@
+#!/bin/ksh -p
+#
+# CDDL HEADER START
+#
+# The contents of this file are subject to the terms of the
+# Common Development and Distribution License (the "License").
+# You may not use this file except in compliance with the License.
+#
+# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
+# or http://www.opensolaris.org/os/licensing.
+# See the License for the specific language governing permissions
+# and limitations under the License.
+#
+# When distributing Covered Code, include this CDDL HEADER in each
+# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
+# If applicable, add the following below this CDDL HEADER, with the
+# fields enclosed by brackets "[]" replaced with your own identifying
+# information: 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
diff --git a/tests/zfs-tests/tests/functional/cli_root/zfs_rollback/zfs_rollback.cfg b/tests/zfs-tests/tests/functional/cli_root/zfs_rollback/zfs_rollback.cfg
new file mode 100644 (file)
index 0000000..d6c8934
--- /dev/null
@@ -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
diff --git a/tests/zfs-tests/tests/functional/cli_root/zfs_rollback/zfs_rollback_001_pos.ksh b/tests/zfs-tests/tests/functional/cli_root/zfs_rollback/zfs_rollback_001_pos.ksh
new file mode 100755 (executable)
index 0000000..1697f62
--- /dev/null
@@ -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 "$ZVOL_DEVDIR/$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 \
+                               $ZVOL_DEVDIR/$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."
diff --git a/tests/zfs-tests/tests/functional/cli_root/zfs_rollback/zfs_rollback_002_pos.ksh b/tests/zfs-tests/tests/functional/cli_root/zfs_rollback/zfs_rollback_002_pos.ksh
new file mode 100755 (executable)
index 0000000..8da6589
--- /dev/null
@@ -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."
diff --git a/tests/zfs-tests/tests/functional/cli_root/zfs_rollback/zfs_rollback_003_neg.ksh b/tests/zfs-tests/tests/functional/cli_root/zfs_rollback/zfs_rollback_003_neg.ksh
new file mode 100755 (executable)
index 0000000..1115ea6
--- /dev/null
@@ -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."
diff --git a/tests/zfs-tests/tests/functional/cli_root/zfs_rollback/zfs_rollback_004_neg.ksh b/tests/zfs-tests/tests/functional/cli_root/zfs_rollback/zfs_rollback_004_neg.ksh
new file mode 100755 (executable)
index 0000000..a0aab07
--- /dev/null
@@ -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."
diff --git a/tests/zfs-tests/tests/functional/cli_root/zfs_rollback/zfs_rollback_common.kshlib b/tests/zfs-tests/tests/functional/cli_root/zfs_rollback/zfs_rollback_common.kshlib
new file mode 100644 (file)
index 0000000..f9b9301
--- /dev/null
@@ -0,0 +1,308 @@
+#
+# CDDL HEADER START
+#
+# The contents of this file are subject to the terms of the
+# Common Development and Distribution License (the "License").
+# You may not use this file except in compliance with the License.
+#
+# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
+# or http://www.opensolaris.org/os/licensing.
+# See the License for the specific language governing permissions
+# and limitations under the License.
+#
+# When distributing Covered Code, include this CDDL HEADER in each
+# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
+# If applicable, add the following below this CDDL 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
+               block_device_wait
+       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|ext2 file system
+               # was mounted.
+               #
+               log_must eval "$ECHO "y" | \
+                       $NEWFS -v $ZVOL_DEVDIR/$VOL > /dev/null 2>&1"
+
+               [[ ! -d $TESTDIR1 ]] && log_must $MKDIR $TESTDIR1
+
+               # Make sure the ufs|ext2 filesystem hasn't been mounted,
+               # then mount the new ufs|ext2 filesystem.
+               if ! ismounted "$ZVOL_DEVDIR/$VOL" $NEWFS_DEFAULT_FS; then
+                       log_must $MOUNT \
+                               $ZVOL_DEVDIR/$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
+                               if is_linux; then
+                                       log_must $SYNC
+                               else
+                                       #
+                                       # using 'lockfs -f' to flush the writes
+                                       # to disk before taking a snapshot.
+                                       #
+                                       if [[ $dtst == $VOL ]]; then
+                                               log_must $LOCKFS -f $TESTDIR1
+                                       fi
+                               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##*/}
+
+       if ismounted $TESTDIR1 $NEWFS_DEFAULT_FS; 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 $NEWFS_DEFAULT_FS
+       fi
+       $DD if=/dev/urandom of=$dir/$TESTFILE1 &
+       log_must $SLEEP 3
+}
diff --git a/tests/zfs-tests/tests/functional/cli_root/zfs_send/Makefile.am b/tests/zfs-tests/tests/functional/cli_root/zfs_send/Makefile.am
new file mode 100644 (file)
index 0000000..13faeab
--- /dev/null
@@ -0,0 +1,12 @@
+pkgdatadir = $(datadir)/@PACKAGE@/zfs-tests/tests/functional/cli_root/zfs_send
+dist_pkgdata_SCRIPTS = \
+       zfs_send.cfg \
+       setup.ksh \
+       cleanup.ksh \
+       zfs_send_001_pos.ksh \
+       zfs_send_002_pos.ksh \
+       zfs_send_003_pos.ksh \
+       zfs_send_004_neg.ksh \
+       zfs_send_005_pos.ksh \
+       zfs_send_006_pos.ksh \
+       zfs_send_007_pos.ksh
diff --git a/tests/zfs-tests/tests/functional/cli_root/zfs_send/cleanup.ksh b/tests/zfs-tests/tests/functional/cli_root/zfs_send/cleanup.ksh
new file mode 100755 (executable)
index 0000000..cec69d4
--- /dev/null
@@ -0,0 +1,33 @@
+#!/bin/ksh -p
+#
+# CDDL HEADER START
+#
+# The contents of this file are subject to the terms of the
+# Common Development and Distribution License (the "License").
+# You may not use this file except in compliance with the License.
+#
+# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
+# or http://www.opensolaris.org/os/licensing.
+# See the License for the specific language governing permissions
+# and limitations under the License.
+#
+# When distributing Covered Code, include this CDDL HEADER in each
+# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
+# If applicable, add the following below this CDDL 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
diff --git a/tests/zfs-tests/tests/functional/cli_root/zfs_send/setup.ksh b/tests/zfs-tests/tests/functional/cli_root/zfs_send/setup.ksh
new file mode 100755 (executable)
index 0000000..6a9af3b
--- /dev/null
@@ -0,0 +1,32 @@
+#!/bin/ksh -p
+#
+# CDDL HEADER START
+#
+# The contents of this file are subject to the terms of the
+# Common Development and Distribution License (the "License").
+# You may not use this file except in compliance with the License.
+#
+# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
+# or http://www.opensolaris.org/os/licensing.
+# See the License for the specific language governing permissions
+# and limitations under the License.
+#
+# When distributing Covered Code, include this CDDL HEADER in each
+# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
+# If applicable, add the following below this CDDL HEADER, with the
+# fields enclosed by brackets "[]" replaced with your own identifying
+# information: 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
diff --git a/tests/zfs-tests/tests/functional/cli_root/zfs_send/zfs_send.cfg b/tests/zfs-tests/tests/functional/cli_root/zfs_send/zfs_send.cfg
new file mode 100644 (file)
index 0000000..bbc4d3a
--- /dev/null
@@ -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
diff --git a/tests/zfs-tests/tests/functional/cli_root/zfs_send/zfs_send_001_pos.ksh b/tests/zfs-tests/tests/functional/cli_root/zfs_send/zfs_send_001_pos.ksh
new file mode 100755 (executable)
index 0000000..0f3ae61
--- /dev/null
@@ -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."
diff --git a/tests/zfs-tests/tests/functional/cli_root/zfs_send/zfs_send_002_pos.ksh b/tests/zfs-tests/tests/functional/cli_root/zfs_send/zfs_send_002_pos.ksh
new file mode 100755 (executable)
index 0000000..b542bf9
--- /dev/null
@@ -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."
diff --git a/tests/zfs-tests/tests/functional/cli_root/zfs_send/zfs_send_003_pos.ksh b/tests/zfs-tests/tests/functional/cli_root/zfs_send/zfs_send_003_pos.ksh
new file mode 100755 (executable)
index 0000000..749f074
--- /dev/null
@@ -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."
diff --git a/tests/zfs-tests/tests/functional/cli_root/zfs_send/zfs_send_004_neg.ksh b/tests/zfs-tests/tests/functional/cli_root/zfs_send/zfs_send_004_neg.ksh
new file mode 100755 (executable)
index 0000000..4f0bf2b
--- /dev/null
@@ -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."
diff --git a/tests/zfs-tests/tests/functional/cli_root/zfs_send/zfs_send_005_pos.ksh b/tests/zfs-tests/tests/functional/cli_root/zfs_send/zfs_send_005_pos.ksh
new file mode 100755 (executable)
index 0000000..ffabfe1
--- /dev/null
@@ -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"
diff --git a/tests/zfs-tests/tests/functional/cli_root/zfs_send/zfs_send_006_pos.ksh b/tests/zfs-tests/tests/functional/cli_root/zfs_send/zfs_send_006_pos.ksh
new file mode 100755 (executable)
index 0000000..7580c6d
--- /dev/null
@@ -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."
diff --git a/tests/zfs-tests/tests/functional/cli_root/zfs_send/zfs_send_007_pos.ksh b/tests/zfs-tests/tests/functional/cli_root/zfs_send/zfs_send_007_pos.ksh
new file mode 100755 (executable)
index 0000000..13ae4f0
--- /dev/null
@@ -0,0 +1,99 @@
+#!/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) 2015, 2016 by Delphix. All rights reserved.
+#
+
+. $STF_SUITE/include/libtest.shlib
+#
+# DESCRIPTION:
+#      Verify 'zfs send' drills holes appropriately when files are replaced
+#
+# STRATEGY:
+#      1. Create dataset
+#      2. Write block 0 in a bunch of files
+#      3. Snapshot the dataset
+#      4. Remove all the files and rewrite some files with just block 1
+#      5. Snapshot the dataset
+#      6. Send both snapshots and receive them locally
+#      7. diff the received dataset and the old datasets.
+#      8. Repeat steps 1-7 above with pool that never had hole birth enabled.
+#
+
+verify_runnable "both"
+
+function cleanup
+{
+       $ZFS destroy -rf $TESTPOOL/fs
+       $ZFS destroy -rf $TESTPOOL/recvfs
+       $RM $streamfile
+       $RM $vdev
+       $ZPOOL destroy testpool
+}
+
+
+log_assert "Verify that 'zfs send' drills appropriate holes"
+log_onexit cleanup
+streamfile=$(mktemp /var/tmp/file.XXXXXX)
+vdev=$(mktemp /var/tmp/file.XXXXXX)
+
+
+test_pool ()
+{
+       POOL=$1
+       log_must $ZFS create -o recordsize=512 $POOL/fs
+       mntpnt=$(get_prop mountpoint "$POOL/fs")
+       log_must $DD if=/dev/urandom of=${mntpnt}/file bs=512 count=1 2>/dev/null
+       first_object=$(ls -i $mntpnt | awk '{print $1}')
+       log_must $ZFS snapshot $POOL/fs@a
+       while true; do
+               log_must $FIND $mntpnt -delete
+               sync
+               log_must $MKFILES "$mntpnt/" 4000
+               FILE=$(ls -i $mntpnt | awk \
+                       '{if ($1 == '$first_object') {print $2}}')
+               if [[ -n "$FILE" ]]; then
+                       break
+               fi
+       done
+       $DD if=/dev/urandom of=${mntpnt}/$FILE bs=512 count=1 seek=1 2>/dev/null
+
+       log_must $ZFS snapshot $POOL/fs@b
+
+       log_must eval "$ZFS send $POOL/fs@a > $streamfile"
+       $CAT $streamfile | log_must $ZFS receive $POOL/recvfs
+
+       log_must eval "$ZFS send -i @a $POOL/fs@b > $streamfile"
+       $CAT $streamfile | log_must $ZFS receive $POOL/recvfs
+
+       recv_mntpnt=$(get_prop mountpoint "$POOL/recvfs")
+       log_must $DIFF -r $mntpnt $recv_mntpnt
+       log_must $ZFS destroy -rf $POOL/fs
+       log_must $ZFS destroy -rf $POOL/recvfs
+}
+
+test_pool $TESTPOOL
+log_must $TRUNCATE --size=1G $vdev
+log_must $ZPOOL create -o version=1 testpool $vdev
+test_pool testpool
+log_must $ZPOOL destroy testpool
+log_must $ZPOOL create -d testpool $vdev
+test_pool testpool
+log_must $ZPOOL destroy testpool
+
+
+log_pass "'zfs send' drills appropriate holes"
diff --git a/tests/zfs-tests/tests/functional/cli_root/zfs_set/Makefile.am b/tests/zfs-tests/tests/functional/cli_root/zfs_set/Makefile.am
new file mode 100644 (file)
index 0000000..f47ff10
--- /dev/null
@@ -0,0 +1,31 @@
+pkgdatadir = $(datadir)/@PACKAGE@/zfs-tests/tests/functional/cli_root/zfs_set
+dist_pkgdata_SCRIPTS = \
+       zfs_set_common.kshlib \
+       setup.ksh \
+       cleanup.ksh \
+       cache_001_pos.ksh \
+       cache_002_neg.ksh \
+       canmount_001_pos.ksh \
+       canmount_002_pos.ksh \
+       canmount_003_pos.ksh \
+       canmount_004_pos.ksh \
+       checksum_001_pos.ksh \
+       compression_001_pos.ksh \
+       mountpoint_001_pos.ksh \
+       mountpoint_002_pos.ksh \
+       mountpoint_003_pos.ksh \
+       onoffs_001_pos.ksh \
+       property_alias_001_pos.ksh \
+       readonly_001_pos.ksh \
+       reservation_001_neg.ksh \
+       ro_props_001_pos.ksh \
+       share_mount_001_neg.ksh \
+       snapdir_001_pos.ksh \
+       user_property_001_pos.ksh \
+       user_property_002_pos.ksh \
+       user_property_003_neg.ksh \
+       user_property_004_pos.ksh \
+       version_001_neg.ksh \
+       zfs_set_001_neg.ksh \
+       zfs_set_002_neg.ksh \
+       zfs_set_003_neg.ksh
diff --git a/tests/zfs-tests/tests/functional/cli_root/zfs_set/cache_001_pos.ksh b/tests/zfs-tests/tests/functional/cli_root/zfs_set/cache_001_pos.ksh
new file mode 100755 (executable)
index 0000000..bffc47f
--- /dev/null
@@ -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."
diff --git a/tests/zfs-tests/tests/functional/cli_root/zfs_set/cache_002_neg.ksh b/tests/zfs-tests/tests/functional/cli_root/zfs_set/cache_002_neg.ksh
new file mode 100755 (executable)
index 0000000..653f31a
--- /dev/null
@@ -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."
diff --git a/tests/zfs-tests/tests/functional/cli_root/zfs_set/canmount_001_pos.ksh b/tests/zfs-tests/tests/functional/cli_root/zfs_set/canmount_001_pos.ksh
new file mode 100755 (executable)
index 0000000..de219c4
--- /dev/null
@@ -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."
diff --git a/tests/zfs-tests/tests/functional/cli_root/zfs_set/canmount_002_pos.ksh b/tests/zfs-tests/tests/functional/cli_root/zfs_set/canmount_002_pos.ksh
new file mode 100755 (executable)
index 0000000..447a9e8
--- /dev/null
@@ -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."
diff --git a/tests/zfs-tests/tests/functional/cli_root/zfs_set/canmount_003_pos.ksh b/tests/zfs-tests/tests/functional/cli_root/zfs_set/canmount_003_pos.ksh
new file mode 100755 (executable)
index 0000000..886b120
--- /dev/null
@@ -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."
diff --git a/tests/zfs-tests/tests/functional/cli_root/zfs_set/canmount_004_pos.ksh b/tests/zfs-tests/tests/functional/cli_root/zfs_set/canmount_004_pos.ksh
new file mode 100755 (executable)
index 0000000..bc8e279
--- /dev/null
@@ -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."
+
diff --git a/tests/zfs-tests/tests/functional/cli_root/zfs_set/checksum_001_pos.ksh b/tests/zfs-tests/tests/functional/cli_root/zfs_set/checksum_001_pos.ksh
new file mode 100755 (executable)
index 0000000..edc7a3f
--- /dev/null
@@ -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."
diff --git a/tests/zfs-tests/tests/functional/cli_root/zfs_set/cleanup.ksh b/tests/zfs-tests/tests/functional/cli_root/zfs_set/cleanup.ksh
new file mode 100755 (executable)
index 0000000..fad025c
--- /dev/null
@@ -0,0 +1,30 @@
+#!/bin/ksh -p
+#
+# CDDL HEADER START
+#
+# The contents of this file are subject to the terms of the
+# Common Development and Distribution License (the "License").
+# You may not use this file except in compliance with the License.
+#
+# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
+# or http://www.opensolaris.org/os/licensing.
+# See the License for the specific language governing permissions
+# and limitations under the License.
+#
+# When distributing Covered Code, include this CDDL HEADER in each
+# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
+# If applicable, add the following below this CDDL 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
diff --git a/tests/zfs-tests/tests/functional/cli_root/zfs_set/compression_001_pos.ksh b/tests/zfs-tests/tests/functional/cli_root/zfs_set/compression_001_pos.ksh
new file mode 100755 (executable)
index 0000000..f7d06ea
--- /dev/null
@@ -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."
diff --git a/tests/zfs-tests/tests/functional/cli_root/zfs_set/mountpoint_001_pos.ksh b/tests/zfs-tests/tests/functional/cli_root/zfs_set/mountpoint_001_pos.ksh
new file mode 100755 (executable)
index 0000000..eaf9a62
--- /dev/null
@@ -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."
diff --git a/tests/zfs-tests/tests/functional/cli_root/zfs_set/mountpoint_002_pos.ksh b/tests/zfs-tests/tests/functional/cli_root/zfs_set/mountpoint_002_pos.ksh
new file mode 100755 (executable)
index 0000000..d827fbe
--- /dev/null
@@ -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."
diff --git a/tests/zfs-tests/tests/functional/cli_root/zfs_set/mountpoint_003_pos.ksh b/tests/zfs-tests/tests/functional/cli_root/zfs_set/mountpoint_003_pos.ksh
new file mode 100755 (executable)
index 0000000..ce427c1
--- /dev/null
@@ -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.
+#
+
+. $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
+#
+if is_linux; then
+       set -A args \
+       "dev"           "/dev/"         "nodev"         "/nodev/"       \
+       "exec"          "/exec/"        "noexec"        "/noexec/"      \
+       "mand"          "/mand/"        "nomand"        "/nomand/"      \
+       "ro"            "read only"     "rw"            "read/write"    \
+       "suid"          "/suid/"        "nosuid"        "/nosuid/"      \
+       "xattr"         "/xattr/"       "noxattr"       "/noxattr/"     \
+       "atime"         "/atime/"       "noatime"       "/noatime/"
+else
+       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/"
+fi
+
+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
+       if is_linux; then
+               log_must $MOUNT -t zfs -o ${args[$i]} $testfs $tmpmnt
+       else
+               log_must $MOUNT -F zfs -o ${args[$i]} $testfs $tmpmnt
+       fi
+       msg=$($MOUNT | $GREP "^$tmpmnt ")
+
+       if ! is_linux; then
+               # In LZ, a user with all zone privileges can never "devices"
+               if ! is_global_zone && [[ ${args[$i]} == devices ]] ; then
+                       args[((i+1))]="/nodevices/"
+               fi
+       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."
diff --git a/tests/zfs-tests/tests/functional/cli_root/zfs_set/onoffs_001_pos.ksh b/tests/zfs-tests/tests/functional/cli_root/zfs_set/onoffs_001_pos.ksh
new file mode 100755 (executable)
index 0000000..41ff4b7
--- /dev/null
@@ -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."
diff --git a/tests/zfs-tests/tests/functional/cli_root/zfs_set/property_alias_001_pos.ksh b/tests/zfs-tests/tests/functional/cli_root/zfs_set/property_alias_001_pos.ksh
new file mode 100755 (executable)
index 0000000..d2f8cee
--- /dev/null
@@ -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."
diff --git a/tests/zfs-tests/tests/functional/cli_root/zfs_set/readonly_001_pos.ksh b/tests/zfs-tests/tests/functional/cli_root/zfs_set/readonly_001_pos.ksh
new file mode 100755 (executable)
index 0000000..a4c04a8
--- /dev/null
@@ -0,0 +1,160 @@
+#!/bin/ksh -p
+#
+# CDDL HEADER START
+#
+# The contents of this file are subject to the terms of the
+# Common Development and Distribution License (the "License").
+# You may not use this file except in compliance with the License.
+#
+# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
+# or http://www.opensolaris.org/os/licensing.
+# See the License for the specific language governing permissions
+# and limitations under the License.
+#
+# When distributing Covered Code, include this CDDL HEADER in each
+# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
+# If applicable, add the following below this CDDL HEADER, with the
+# fields enclosed by brackets "[]" replaced with your own identifying
+# information: Portions Copyright [yyyy] [name of copyright owner]
+#
+# CDDL HEADER END
+#
+
+#
+# Copyright 2009 Sun Microsystems, Inc.  All rights reserved.
+# Use is subject to license terms.
+#
+
+#
+# Copyright (c) 2014 by Delphix. All rights reserved.
+#
+
+. $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 does 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 eval "$ECHO 'y' | $RM $mtpt/$TESTFILE0"
+                       $expect $RMDIR $mtpt/$TESTDIR0
+
+                       if [[ $expect == "log_must" ]] ; then
+                               log_must eval "$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 \
+                           ${ZVOL_DEVDIR}/$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 "
+       all_datasets+="$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."
diff --git a/tests/zfs-tests/tests/functional/cli_root/zfs_set/reservation_001_neg.ksh b/tests/zfs-tests/tests/functional/cli_root/zfs_set/reservation_001_neg.ksh
new file mode 100755 (executable)
index 0000000..511a506
--- /dev/null
@@ -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"
diff --git a/tests/zfs-tests/tests/functional/cli_root/zfs_set/ro_props_001_pos.ksh b/tests/zfs-tests/tests/functional/cli_root/zfs_set/ro_props_001_pos.ksh
new file mode 100755 (executable)
index 0000000..c9a7391
--- /dev/null
@@ -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."
diff --git a/tests/zfs-tests/tests/functional/cli_root/zfs_set/setup.ksh b/tests/zfs-tests/tests/functional/cli_root/zfs_set/setup.ksh
new file mode 100755 (executable)
index 0000000..312638d
--- /dev/null
@@ -0,0 +1,31 @@
+#!/bin/ksh -p
+#
+# CDDL HEADER START
+#
+# The contents of this file are subject to the terms of the
+# Common Development and Distribution License (the "License").
+# You may not use this file except in compliance with the License.
+#
+# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
+# or http://www.opensolaris.org/os/licensing.
+# See the License for the specific language governing permissions
+# and limitations under the License.
+#
+# When distributing Covered Code, include this CDDL HEADER in each
+# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
+# If applicable, add the following below this CDDL HEADER, with the
+# fields enclosed by brackets "[]" replaced with your own identifying
+# information: 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
diff --git a/tests/zfs-tests/tests/functional/cli_root/zfs_set/share_mount_001_neg.ksh b/tests/zfs-tests/tests/functional/cli_root/zfs_set/share_mount_001_neg.ksh
new file mode 100755 (executable)
index 0000000..05c8b63
--- /dev/null
@@ -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."
diff --git a/tests/zfs-tests/tests/functional/cli_root/zfs_set/snapdir_001_pos.ksh b/tests/zfs-tests/tests/functional/cli_root/zfs_set/snapdir_001_pos.ksh
new file mode 100755 (executable)
index 0000000..9abd0ec
--- /dev/null
@@ -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."
diff --git a/tests/zfs-tests/tests/functional/cli_root/zfs_set/user_property_001_pos.ksh b/tests/zfs-tests/tests/functional/cli_root/zfs_set/user_property_001_pos.ksh
new file mode 100755 (executable)
index 0000000..be8c88c
--- /dev/null
@@ -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."
diff --git a/tests/zfs-tests/tests/functional/cli_root/zfs_set/user_property_002_pos.ksh b/tests/zfs-tests/tests/functional/cli_root/zfs_set/user_property_002_pos.ksh
new file mode 100755 (executable)
index 0000000..24fecfb
--- /dev/null
@@ -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."
diff --git a/tests/zfs-tests/tests/functional/cli_root/zfs_set/user_property_003_neg.ksh b/tests/zfs-tests/tests/functional/cli_root/zfs_set/user_property_003_neg.ksh
new file mode 100755 (executable)
index 0000000..4c1c1bc
--- /dev/null
@@ -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."
diff --git a/tests/zfs-tests/tests/functional/cli_root/zfs_set/user_property_004_pos.ksh b/tests/zfs-tests/tests/functional/cli_root/zfs_set/user_property_004_pos.ksh
new file mode 100755 (executable)
index 0000000..1bce7a7
--- /dev/null
@@ -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."
diff --git a/tests/zfs-tests/tests/functional/cli_root/zfs_set/version_001_neg.ksh b/tests/zfs-tests/tests/functional/cli_root/zfs_set/version_001_neg.ksh
new file mode 100755 (executable)
index 0000000..40a541a
--- /dev/null
@@ -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"
diff --git a/tests/zfs-tests/tests/functional/cli_root/zfs_set/zfs_set_001_neg.ksh b/tests/zfs-tests/tests/functional/cli_root/zfs_set/zfs_set_001_neg.ksh
new file mode 100755 (executable)
index 0000000..4d8982c
--- /dev/null
@@ -0,0 +1,82 @@
+#!/bin/ksh -p
+#
+# CDDL HEADER START
+#
+# The contents of this file are subject to the terms of the
+# Common Development and Distribution License (the "License").
+# You may not use this file except in compliance with the License.
+#
+# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
+# or http://www.opensolaris.org/os/licensing.
+# See the License for the specific language governing permissions
+# and limitations under the License.
+#
+# When distributing Covered Code, include this CDDL HEADER in each
+# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
+# If applicable, add the following below this CDDL HEADER, with the
+# fields enclosed by brackets "[]" replaced with your own identifying
+# information: Portions Copyright [yyyy] [name of copyright owner]
+#
+# CDDL HEADER END
+#
+
+#
+# Copyright 2007 Sun Microsystems, Inc.  All rights reserved.
+# Use is subject to license terms.
+#
+
+#
+# Copyright (c) 2015 by Delphix. All rights reserved.
+#
+
+. $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, recordsize, 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
+        # Additional recordsize
+        set_n_check_prop "recordsize" "2048K" "${dataset[i]}" false
+        set_n_check_prop "recordsize" "128B" "${dataset[i]}" false
+       (( i += 1 ))
+done
+
+log_pass "Setting invalid value to mountpoint, checksum, compression, atime, " \
+       "readonly, setuid, zoned or canmount on file system or volume pass."
diff --git a/tests/zfs-tests/tests/functional/cli_root/zfs_set/zfs_set_002_neg.ksh b/tests/zfs-tests/tests/functional/cli_root/zfs_set/zfs_set_002_neg.ksh
new file mode 100755 (executable)
index 0000000..619a1ee
--- /dev/null
@@ -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."
diff --git a/tests/zfs-tests/tests/functional/cli_root/zfs_set/zfs_set_003_neg.ksh b/tests/zfs-tests/tests/functional/cli_root/zfs_set/zfs_set_003_neg.ksh
new file mode 100755 (executable)
index 0000000..13260f1
--- /dev/null
@@ -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."
diff --git a/tests/zfs-tests/tests/functional/cli_root/zfs_set/zfs_set_common.kshlib b/tests/zfs-tests/tests/functional/cli_root/zfs_set/zfs_set_common.kshlib
new file mode 100644 (file)
index 0000000..5c4363b
--- /dev/null
@@ -0,0 +1,267 @@
+#
+# CDDL HEADER START
+#
+# The contents of this file are subject to the terms of the
+# Common Development and Distribution License (the "License").
+# You may not use this file except in compliance with the License.
+#
+# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
+# or http://www.opensolaris.org/os/licensing.
+# See the License for the specific language governing permissions
+# and limitations under the License.
+#
+# When distributing Covered Code, include this CDDL HEADER in each
+# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
+# If applicable, add the following below this CDDL HEADER, with the
+# fields enclosed by brackets "[]" replaced with your own identifying
+# information: Portions Copyright [yyyy] [name of copyright owner]
+#
+# CDDL HEADER END
+#
+
+#
+# Copyright 2009 Sun Microsystems, Inc.  All rights reserved.
+# Use is subject to license terms.
+#
+
+#
+# Copyright (c) 2014 by Delphix. All rights reserved.
+#
+
+. $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[@]}
+
+       # No consumers want an empty string.
+       ((len == 0)) && len=3
+
+       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"
+}
diff --git a/tests/zfs-tests/tests/functional/cli_root/zfs_share/Makefile.am b/tests/zfs-tests/tests/functional/cli_root/zfs_share/Makefile.am
new file mode 100644 (file)
index 0000000..926531b
--- /dev/null
@@ -0,0 +1,16 @@
+pkgdatadir = $(datadir)/@PACKAGE@/zfs-tests/tests/functional/cli_root/zfs_share
+dist_pkgdata_SCRIPTS = \
+       zfs_share.cfg \
+       setup.ksh \
+       cleanup.ksh \
+       zfs_share_001_pos.ksh \
+       zfs_share_002_pos.ksh \
+       zfs_share_003_pos.ksh \
+       zfs_share_004_pos.ksh \
+       zfs_share_005_pos.ksh \
+       zfs_share_006_pos.ksh \
+       zfs_share_007_neg.ksh \
+       zfs_share_008_neg.ksh \
+       zfs_share_009_neg.ksh \
+       zfs_share_010_neg.ksh \
+       zfs_share_011_pos.ksh
diff --git a/tests/zfs-tests/tests/functional/cli_root/zfs_share/cleanup.ksh b/tests/zfs-tests/tests/functional/cli_root/zfs_share/cleanup.ksh
new file mode 100755 (executable)
index 0000000..79cd6e9
--- /dev/null
@@ -0,0 +1,30 @@
+#!/bin/ksh -p
+#
+# CDDL HEADER START
+#
+# The contents of this file are subject to the terms of the
+# Common Development and Distribution License (the "License").
+# You may not use this file except in compliance with the License.
+#
+# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
+# or http://www.opensolaris.org/os/licensing.
+# See the License for the specific language governing permissions
+# and limitations under the License.
+#
+# When distributing Covered Code, include this CDDL HEADER in each
+# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
+# If applicable, add the following below this CDDL HEADER, with the
+# fields enclosed by brackets "[]" replaced with your own identifying
+# information: 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
diff --git a/tests/zfs-tests/tests/functional/cli_root/zfs_share/setup.ksh b/tests/zfs-tests/tests/functional/cli_root/zfs_share/setup.ksh
new file mode 100755 (executable)
index 0000000..9cfd997
--- /dev/null
@@ -0,0 +1,34 @@
+#!/bin/ksh -p
+#
+# CDDL HEADER START
+#
+# The contents of this file are subject to the terms of the
+# Common Development and Distribution License (the "License").
+# You may not use this file except in compliance with the License.
+#
+# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
+# or http://www.opensolaris.org/os/licensing.
+# See the License for the specific language governing permissions
+# and limitations under the License.
+#
+# When distributing Covered Code, include this CDDL HEADER in each
+# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
+# If applicable, add the following below this CDDL HEADER, with the
+# fields enclosed by brackets "[]" replaced with your own identifying
+# information: 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
diff --git a/tests/zfs-tests/tests/functional/cli_root/zfs_share/zfs_share.cfg b/tests/zfs-tests/tests/functional/cli_root/zfs_share/zfs_share.cfg
new file mode 100644 (file)
index 0000000..5c31c8f
--- /dev/null
@@ -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"
diff --git a/tests/zfs-tests/tests/functional/cli_root/zfs_share/zfs_share_001_pos.ksh b/tests/zfs-tests/tests/functional/cli_root/zfs_share/zfs_share_001_pos.ksh
new file mode 100755 (executable)
index 0000000..084b18d
--- /dev/null
@@ -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."
diff --git a/tests/zfs-tests/tests/functional/cli_root/zfs_share/zfs_share_002_pos.ksh b/tests/zfs-tests/tests/functional/cli_root/zfs_share/zfs_share_002_pos.ksh
new file mode 100755 (executable)
index 0000000..4005bf0
--- /dev/null
@@ -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."
diff --git a/tests/zfs-tests/tests/functional/cli_root/zfs_share/zfs_share_003_pos.ksh b/tests/zfs-tests/tests/functional/cli_root/zfs_share/zfs_share_003_pos.ksh
new file mode 100755 (executable)
index 0000000..e4ab8c6
--- /dev/null
@@ -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."
diff --git a/tests/zfs-tests/tests/functional/cli_root/zfs_share/zfs_share_004_pos.ksh b/tests/zfs-tests/tests/functional/cli_root/zfs_share/zfs_share_004_pos.ksh
new file mode 100755 (executable)
index 0000000..04cf72e
--- /dev/null
@@ -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."
diff --git a/tests/zfs-tests/tests/functional/cli_root/zfs_share/zfs_share_005_pos.ksh b/tests/zfs-tests/tests/functional/cli_root/zfs_share/zfs_share_005_pos.ksh
new file mode 100755 (executable)
index 0000000..eed0eaa
--- /dev/null
@@ -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."
diff --git a/tests/zfs-tests/tests/functional/cli_root/zfs_share/zfs_share_006_pos.ksh b/tests/zfs-tests/tests/functional/cli_root/zfs_share/zfs_share_006_pos.ksh
new file mode 100755 (executable)
index 0000000..2088489
--- /dev/null
@@ -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."
diff --git a/tests/zfs-tests/tests/functional/cli_root/zfs_share/zfs_share_007_neg.ksh b/tests/zfs-tests/tests/functional/cli_root/zfs_share/zfs_share_007_neg.ksh
new file mode 100755 (executable)
index 0000000..ace4e43
--- /dev/null
@@ -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."
diff --git a/tests/zfs-tests/tests/functional/cli_root/zfs_share/zfs_share_008_neg.ksh b/tests/zfs-tests/tests/functional/cli_root/zfs_share/zfs_share_008_neg.ksh
new file mode 100755 (executable)
index 0000000..a945ddd
--- /dev/null
@@ -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."
diff --git a/tests/zfs-tests/tests/functional/cli_root/zfs_share/zfs_share_009_neg.ksh b/tests/zfs-tests/tests/functional/cli_root/zfs_share/zfs_share_009_neg.ksh
new file mode 100755 (executable)
index 0000000..6b4f303
--- /dev/null
@@ -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."
diff --git a/tests/zfs-tests/tests/functional/cli_root/zfs_share/zfs_share_010_neg.ksh b/tests/zfs-tests/tests/functional/cli_root/zfs_share/zfs_share_010_neg.ksh
new file mode 100755 (executable)
index 0000000..a56761e
--- /dev/null
@@ -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."
diff --git a/tests/zfs-tests/tests/functional/cli_root/zfs_share/zfs_share_011_pos.ksh b/tests/zfs-tests/tests/functional/cli_root/zfs_share/zfs_share_011_pos.ksh
new file mode 100755 (executable)
index 0000000..8f519b3
--- /dev/null
@@ -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"
diff --git a/tests/zfs-tests/tests/functional/cli_root/zfs_snapshot/Makefile.am b/tests/zfs-tests/tests/functional/cli_root/zfs_snapshot/Makefile.am
new file mode 100644 (file)
index 0000000..fd1db07
--- /dev/null
@@ -0,0 +1,14 @@
+pkgdatadir = $(datadir)/@PACKAGE@/zfs-tests/tests/functional/cli_root/zfs_snapshot
+dist_pkgdata_SCRIPTS = \
+       zfs_snapshot.cfg \
+       setup.ksh \
+       cleanup.ksh \
+       zfs_snapshot_001_neg.ksh \
+       zfs_snapshot_002_neg.ksh \
+       zfs_snapshot_003_neg.ksh \
+       zfs_snapshot_004_neg.ksh \
+       zfs_snapshot_005_neg.ksh \
+       zfs_snapshot_006_pos.ksh \
+       zfs_snapshot_007_neg.ksh \
+       zfs_snapshot_008_neg.ksh \
+       zfs_snapshot_009_pos.ksh
diff --git a/tests/zfs-tests/tests/functional/cli_root/zfs_snapshot/cleanup.ksh b/tests/zfs-tests/tests/functional/cli_root/zfs_snapshot/cleanup.ksh
new file mode 100755 (executable)
index 0000000..d247991
--- /dev/null
@@ -0,0 +1,30 @@
+#!/bin/ksh -p
+#
+# CDDL HEADER START
+#
+# The contents of this file are subject to the terms of the
+# Common Development and Distribution License (the "License").
+# You may not use this file except in compliance with the License.
+#
+# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
+# or http://www.opensolaris.org/os/licensing.
+# See the License for the specific language governing permissions
+# and limitations under the License.
+#
+# When distributing Covered Code, include this CDDL HEADER in each
+# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
+# If applicable, add the following below this CDDL HEADER, with the
+# fields enclosed by brackets "[]" replaced with your own identifying
+# information: 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
diff --git a/tests/zfs-tests/tests/functional/cli_root/zfs_snapshot/setup.ksh b/tests/zfs-tests/tests/functional/cli_root/zfs_snapshot/setup.ksh
new file mode 100755 (executable)
index 0000000..b3f2b02
--- /dev/null
@@ -0,0 +1,32 @@
+#!/bin/ksh -p
+#
+# CDDL HEADER START
+#
+# The contents of this file are subject to the terms of the
+# Common Development and Distribution License (the "License").
+# You may not use this file except in compliance with the License.
+#
+# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
+# or http://www.opensolaris.org/os/licensing.
+# See the License for the specific language governing permissions
+# and limitations under the License.
+#
+# When distributing Covered Code, include this CDDL HEADER in each
+# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
+# If applicable, add the following below this CDDL HEADER, with the
+# fields enclosed by brackets "[]" replaced with your own identifying
+# information: 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}
diff --git a/tests/zfs-tests/tests/functional/cli_root/zfs_snapshot/zfs_snapshot.cfg b/tests/zfs-tests/tests/functional/cli_root/zfs_snapshot/zfs_snapshot.cfg
new file mode 100644 (file)
index 0000000..fb22367
--- /dev/null
@@ -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"
diff --git a/tests/zfs-tests/tests/functional/cli_root/zfs_snapshot/zfs_snapshot_001_neg.ksh b/tests/zfs-tests/tests/functional/cli_root/zfs_snapshot/zfs_snapshot_001_neg.ksh
new file mode 100755 (executable)
index 0000000..860dd6c
--- /dev/null
@@ -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."
diff --git a/tests/zfs-tests/tests/functional/cli_root/zfs_snapshot/zfs_snapshot_002_neg.ksh b/tests/zfs-tests/tests/functional/cli_root/zfs_snapshot/zfs_snapshot_002_neg.ksh
new file mode 100755 (executable)
index 0000000..907d0dd
--- /dev/null
@@ -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."
diff --git a/tests/zfs-tests/tests/functional/cli_root/zfs_snapshot/zfs_snapshot_003_neg.ksh b/tests/zfs-tests/tests/functional/cli_root/zfs_snapshot/zfs_snapshot_003_neg.ksh
new file mode 100755 (executable)
index 0000000..e424b9b
--- /dev/null
@@ -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."
diff --git a/tests/zfs-tests/tests/functional/cli_root/zfs_snapshot/zfs_snapshot_004_neg.ksh b/tests/zfs-tests/tests/functional/cli_root/zfs_snapshot/zfs_snapshot_004_neg.ksh
new file mode 100755 (executable)
index 0000000..319e5c4
--- /dev/null
@@ -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."
diff --git a/tests/zfs-tests/tests/functional/cli_root/zfs_snapshot/zfs_snapshot_005_neg.ksh b/tests/zfs-tests/tests/functional/cli_root/zfs_snapshot/zfs_snapshot_005_neg.ksh
new file mode 100755 (executable)
index 0000000..8794cba
--- /dev/null
@@ -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."
diff --git a/tests/zfs-tests/tests/functional/cli_root/zfs_snapshot/zfs_snapshot_006_pos.ksh b/tests/zfs-tests/tests/functional/cli_root/zfs_snapshot/zfs_snapshot_006_pos.ksh
new file mode 100755 (executable)
index 0000000..6d5f03c
--- /dev/null
@@ -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'."
diff --git a/tests/zfs-tests/tests/functional/cli_root/zfs_snapshot/zfs_snapshot_007_neg.ksh b/tests/zfs-tests/tests/functional/cli_root/zfs_snapshot/zfs_snapshot_007_neg.ksh
new file mode 100755 (executable)
index 0000000..1a80e4f
--- /dev/null
@@ -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."
diff --git a/tests/zfs-tests/tests/functional/cli_root/zfs_snapshot/zfs_snapshot_008_neg.ksh b/tests/zfs-tests/tests/functional/cli_root/zfs_snapshot/zfs_snapshot_008_neg.ksh
new file mode 100755 (executable)
index 0000000..153a016
--- /dev/null
@@ -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."
diff --git a/tests/zfs-tests/tests/functional/cli_root/zfs_snapshot/zfs_snapshot_009_pos.ksh b/tests/zfs-tests/tests/functional/cli_root/zfs_snapshot/zfs_snapshot_009_pos.ksh
new file mode 100755 (executable)
index 0000000..318c3ad
--- /dev/null
@@ -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/*.bz2
+
+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"
diff --git a/tests/zfs-tests/tests/functional/cli_root/zfs_unmount/Makefile.am b/tests/zfs-tests/tests/functional/cli_root/zfs_unmount/Makefile.am
new file mode 100644 (file)
index 0000000..57a7808
--- /dev/null
@@ -0,0 +1,16 @@
+pkgdatadir = $(datadir)/@PACKAGE@/zfs-tests/tests/functional/cli_root/zfs_unmount
+dist_pkgdata_SCRIPTS = \
+       zfs_unmount.cfg \
+       zfs_unmount.kshlib \
+       setup.ksh \
+       cleanup.ksh \
+       zfs_unmount_001_pos.ksh \
+       zfs_unmount_002_pos.ksh \
+       zfs_unmount_003_pos.ksh \
+       zfs_unmount_004_pos.ksh \
+       zfs_unmount_005_pos.ksh \
+       zfs_unmount_006_pos.ksh \
+       zfs_unmount_007_neg.ksh \
+       zfs_unmount_008_neg.ksh \
+       zfs_unmount_009_pos.ksh \
+       zfs_unmount_all_001_pos.ksh
diff --git a/tests/zfs-tests/tests/functional/cli_root/zfs_unmount/cleanup.ksh b/tests/zfs-tests/tests/functional/cli_root/zfs_unmount/cleanup.ksh
new file mode 100755 (executable)
index 0000000..79cd6e9
--- /dev/null
@@ -0,0 +1,30 @@
+#!/bin/ksh -p
+#
+# CDDL HEADER START
+#
+# The contents of this file are subject to the terms of the
+# Common Development and Distribution License (the "License").
+# You may not use this file except in compliance with the License.
+#
+# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
+# or http://www.opensolaris.org/os/licensing.
+# See the License for the specific language governing permissions
+# and limitations under the License.
+#
+# When distributing Covered Code, include this CDDL HEADER in each
+# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
+# If applicable, add the following below this CDDL HEADER, with the
+# fields enclosed by brackets "[]" replaced with your own identifying
+# information: 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
diff --git a/tests/zfs-tests/tests/functional/cli_root/zfs_unmount/setup.ksh b/tests/zfs-tests/tests/functional/cli_root/zfs_unmount/setup.ksh
new file mode 100755 (executable)
index 0000000..6a9af3b
--- /dev/null
@@ -0,0 +1,32 @@
+#!/bin/ksh -p
+#
+# CDDL HEADER START
+#
+# The contents of this file are subject to the terms of the
+# Common Development and Distribution License (the "License").
+# You may not use this file except in compliance with the License.
+#
+# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
+# or http://www.opensolaris.org/os/licensing.
+# See the License for the specific language governing permissions
+# and limitations under the License.
+#
+# When distributing Covered Code, include this CDDL HEADER in each
+# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
+# If applicable, add the following below this CDDL HEADER, with the
+# fields enclosed by brackets "[]" replaced with your own identifying
+# information: 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
diff --git a/tests/zfs-tests/tests/functional/cli_root/zfs_unmount/zfs_unmount.cfg b/tests/zfs-tests/tests/functional/cli_root/zfs_unmount/zfs_unmount.cfg
new file mode 100644 (file)
index 0000000..c8e4689
--- /dev/null
@@ -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"
diff --git a/tests/zfs-tests/tests/functional/cli_root/zfs_unmount/zfs_unmount.kshlib b/tests/zfs-tests/tests/functional/cli_root/zfs_unmount/zfs_unmount.kshlib
new file mode 100644 (file)
index 0000000..9c9cb71
--- /dev/null
@@ -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
+}
diff --git a/tests/zfs-tests/tests/functional/cli_root/zfs_unmount/zfs_unmount_001_pos.ksh b/tests/zfs-tests/tests/functional/cli_root/zfs_unmount/zfs_unmount_001_pos.ksh
new file mode 100755 (executable)
index 0000000..924e6ac
--- /dev/null
@@ -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."
diff --git a/tests/zfs-tests/tests/functional/cli_root/zfs_unmount/zfs_unmount_002_pos.ksh b/tests/zfs-tests/tests/functional/cli_root/zfs_unmount/zfs_unmount_002_pos.ksh
new file mode 100755 (executable)
index 0000000..1b0e621
--- /dev/null
@@ -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."
diff --git a/tests/zfs-tests/tests/functional/cli_root/zfs_unmount/zfs_unmount_003_pos.ksh b/tests/zfs-tests/tests/functional/cli_root/zfs_unmount/zfs_unmount_003_pos.ksh
new file mode 100755 (executable)
index 0000000..8f1b949
--- /dev/null
@@ -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."
diff --git a/tests/zfs-tests/tests/functional/cli_root/zfs_unmount/zfs_unmount_004_pos.ksh b/tests/zfs-tests/tests/functional/cli_root/zfs_unmount/zfs_unmount_004_pos.ksh
new file mode 100755 (executable)
index 0000000..8f3def6
--- /dev/null
@@ -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."
diff --git a/tests/zfs-tests/tests/functional/cli_root/zfs_unmount/zfs_unmount_005_pos.ksh b/tests/zfs-tests/tests/functional/cli_root/zfs_unmount/zfs_unmount_005_pos.ksh
new file mode 100755 (executable)
index 0000000..ac2de65
--- /dev/null
@@ -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."
diff --git a/tests/zfs-tests/tests/functional/cli_root/zfs_unmount/zfs_unmount_006_pos.ksh b/tests/zfs-tests/tests/functional/cli_root/zfs_unmount/zfs_unmount_006_pos.ksh
new file mode 100755 (executable)
index 0000000..3e2ac07
--- /dev/null
@@ -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."
diff --git a/tests/zfs-tests/tests/functional/cli_root/zfs_unmount/zfs_unmount_007_neg.ksh b/tests/zfs-tests/tests/functional/cli_root/zfs_unmount/zfs_unmount_007_neg.ksh
new file mode 100755 (executable)
index 0000000..c1000e8
--- /dev/null
@@ -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."
diff --git a/tests/zfs-tests/tests/functional/cli_root/zfs_unmount/zfs_unmount_008_neg.ksh b/tests/zfs-tests/tests/functional/cli_root/zfs_unmount/zfs_unmount_008_neg.ksh
new file mode 100755 (executable)
index 0000000..04a7e56
--- /dev/null
@@ -0,0 +1,143 @@
+#!/bin/ksh -p
+#
+# CDDL HEADER START
+#
+# The contents of this file are subject to the terms of the
+# Common Development and Distribution License (the "License").
+# You may not use this file except in compliance with the License.
+#
+# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
+# or http://www.opensolaris.org/os/licensing.
+# See the License for the specific language governing permissions
+# and limitations under the License.
+#
+# When distributing Covered Code, include this CDDL HEADER in each
+# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
+# If applicable, add the following below this CDDL HEADER, with the
+# fields enclosed by brackets "[]" replaced with your own identifying
+# information: 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
+if is_linux; then
+       log_must $MOUNT -t zfs $fs1 /tmp/$dir
+else
+       log_must $MOUNT -F zfs $fs1 /tmp/$dir
+fi
+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."
diff --git a/tests/zfs-tests/tests/functional/cli_root/zfs_unmount/zfs_unmount_009_pos.ksh b/tests/zfs-tests/tests/functional/cli_root/zfs_unmount/zfs_unmount_009_pos.ksh
new file mode 100755 (executable)
index 0000000..79c6fda
--- /dev/null
@@ -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."
diff --git a/tests/zfs-tests/tests/functional/cli_root/zfs_unmount/zfs_unmount_all_001_pos.ksh b/tests/zfs-tests/tests/functional/cli_root/zfs_unmount/zfs_unmount_all_001_pos.ksh
new file mode 100755 (executable)
index 0000000..454293f
--- /dev/null
@@ -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."
diff --git a/tests/zfs-tests/tests/functional/cli_root/zfs_unshare/Makefile.am b/tests/zfs-tests/tests/functional/cli_root/zfs_unshare/Makefile.am
new file mode 100644 (file)
index 0000000..c454697
--- /dev/null
@@ -0,0 +1,9 @@
+pkgdatadir = $(datadir)/@PACKAGE@/zfs-tests/tests/functional/cli_root/zfs_unshare
+dist_pkgdata_SCRIPTS = \
+       setup.ksh \
+       cleanup.ksh \
+       zfs_unshare_001_pos.ksh \
+       zfs_unshare_002_pos.ksh \
+       zfs_unshare_003_pos.ksh \
+       zfs_unshare_004_neg.ksh \
+       zfs_unshare_005_neg.ksh
diff --git a/tests/zfs-tests/tests/functional/cli_root/zfs_unshare/cleanup.ksh b/tests/zfs-tests/tests/functional/cli_root/zfs_unshare/cleanup.ksh
new file mode 100755 (executable)
index 0000000..79cd6e9
--- /dev/null
@@ -0,0 +1,30 @@
+#!/bin/ksh -p
+#
+# CDDL HEADER START
+#
+# The contents of this file are subject to the terms of the
+# Common Development and Distribution License (the "License").
+# You may not use this file except in compliance with the License.
+#
+# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
+# or http://www.opensolaris.org/os/licensing.
+# See the License for the specific language governing permissions
+# and limitations under the License.
+#
+# When distributing Covered Code, include this CDDL HEADER in each
+# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
+# If applicable, add the following below this CDDL HEADER, with the
+# fields enclosed by brackets "[]" replaced with your own identifying
+# information: 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
diff --git a/tests/zfs-tests/tests/functional/cli_root/zfs_unshare/setup.ksh b/tests/zfs-tests/tests/functional/cli_root/zfs_unshare/setup.ksh
new file mode 100755 (executable)
index 0000000..9cfd997
--- /dev/null
@@ -0,0 +1,34 @@
+#!/bin/ksh -p
+#
+# CDDL HEADER START
+#
+# The contents of this file are subject to the terms of the
+# Common Development and Distribution License (the "License").
+# You may not use this file except in compliance with the License.
+#
+# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
+# or http://www.opensolaris.org/os/licensing.
+# See the License for the specific language governing permissions
+# and limitations under the License.
+#
+# When distributing Covered Code, include this CDDL HEADER in each
+# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
+# If applicable, add the following below this CDDL HEADER, with the
+# fields enclosed by brackets "[]" replaced with your own identifying
+# information: 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
diff --git a/tests/zfs-tests/tests/functional/cli_root/zfs_unshare/zfs_unshare_001_pos.ksh b/tests/zfs-tests/tests/functional/cli_root/zfs_unshare/zfs_unshare_001_pos.ksh
new file mode 100755 (executable)
index 0000000..033865b
--- /dev/null
@@ -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."
diff --git a/tests/zfs-tests/tests/functional/cli_root/zfs_unshare/zfs_unshare_002_pos.ksh b/tests/zfs-tests/tests/functional/cli_root/zfs_unshare/zfs_unshare_002_pos.ksh
new file mode 100755 (executable)
index 0000000..ea1d079
--- /dev/null
@@ -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."
+
diff --git a/tests/zfs-tests/tests/functional/cli_root/zfs_unshare/zfs_unshare_003_pos.ksh b/tests/zfs-tests/tests/functional/cli_root/zfs_unshare/zfs_unshare_003_pos.ksh
new file mode 100755 (executable)
index 0000000..74cc41d
--- /dev/null
@@ -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."
diff --git a/tests/zfs-tests/tests/functional/cli_root/zfs_unshare/zfs_unshare_004_neg.ksh b/tests/zfs-tests/tests/functional/cli_root/zfs_unshare/zfs_unshare_004_neg.ksh
new file mode 100755 (executable)
index 0000000..29c5fb9
--- /dev/null
@@ -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."
diff --git a/tests/zfs-tests/tests/functional/cli_root/zfs_unshare/zfs_unshare_005_neg.ksh b/tests/zfs-tests/tests/functional/cli_root/zfs_unshare/zfs_unshare_005_neg.ksh
new file mode 100755 (executable)
index 0000000..fb582b9
--- /dev/null
@@ -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" "${ZVOL_DEVDIR}/$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."
diff --git a/tests/zfs-tests/tests/functional/cli_root/zfs_upgrade/Makefile.am b/tests/zfs-tests/tests/functional/cli_root/zfs_upgrade/Makefile.am
new file mode 100644 (file)
index 0000000..cd7a452
--- /dev/null
@@ -0,0 +1,12 @@
+pkgdatadir = $(datadir)/@PACKAGE@/zfs-tests/tests/functional/cli_root/zfs_upgrade
+dist_pkgdata_SCRIPTS = \
+       zfs_upgrade.kshlib \
+       setup.ksh \
+       cleanup.ksh \
+       zfs_upgrade_001_pos.ksh \
+       zfs_upgrade_002_pos.ksh \
+       zfs_upgrade_003_pos.ksh \
+       zfs_upgrade_004_pos.ksh \
+       zfs_upgrade_005_pos.ksh \
+       zfs_upgrade_006_neg.ksh \
+       zfs_upgrade_007_neg.ksh
diff --git a/tests/zfs-tests/tests/functional/cli_root/zfs_upgrade/cleanup.ksh b/tests/zfs-tests/tests/functional/cli_root/zfs_upgrade/cleanup.ksh
new file mode 100755 (executable)
index 0000000..e2d0604
--- /dev/null
@@ -0,0 +1,33 @@
+#!/bin/ksh -p
+#
+# CDDL HEADER START
+#
+# The contents of this file are subject to the terms of the
+# Common Development and Distribution License (the "License").
+# You may not use this file except in compliance with the License.
+#
+# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
+# or http://www.opensolaris.org/os/licensing.
+# See the License for the specific language governing permissions
+# and limitations under the License.
+#
+# When distributing Covered Code, include this CDDL HEADER in each
+# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
+# If applicable, add the following below this CDDL HEADER, with the
+# fields enclosed by brackets "[]" replaced with your own identifying
+# information: 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
diff --git a/tests/zfs-tests/tests/functional/cli_root/zfs_upgrade/setup.ksh b/tests/zfs-tests/tests/functional/cli_root/zfs_upgrade/setup.ksh
new file mode 100755 (executable)
index 0000000..4c1348a
--- /dev/null
@@ -0,0 +1,42 @@
+#!/bin/ksh -p
+#
+# CDDL HEADER START
+#
+# The contents of this file are subject to the terms of the
+# Common Development and Distribution License (the "License").
+# You may not use this file except in compliance with the License.
+#
+# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
+# or http://www.opensolaris.org/os/licensing.
+# See the License for the specific language governing permissions
+# and limitations under the License.
+#
+# When distributing Covered Code, include this CDDL HEADER in each
+# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
+# If applicable, add the following below this CDDL HEADER, with the
+# fields enclosed by brackets "[]" replaced with your own identifying
+# information: 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
diff --git a/tests/zfs-tests/tests/functional/cli_root/zfs_upgrade/zfs_upgrade.kshlib b/tests/zfs-tests/tests/functional/cli_root/zfs_upgrade/zfs_upgrade.kshlib
new file mode 100644 (file)
index 0000000..b622c94
--- /dev/null
@@ -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
+}
diff --git a/tests/zfs-tests/tests/functional/cli_root/zfs_upgrade/zfs_upgrade_001_pos.ksh b/tests/zfs-tests/tests/functional/cli_root/zfs_upgrade/zfs_upgrade_001_pos.ksh
new file mode 100755 (executable)
index 0000000..32e76ff
--- /dev/null
@@ -0,0 +1,136 @@
+#!/bin/ksh -p
+#
+# CDDL HEADER START
+#
+# The contents of this file are subject to the terms of the
+# Common Development and Distribution License (the "License").
+# You may not use this file except in compliance with the License.
+#
+# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
+# or http://www.opensolaris.org/os/licensing.
+# See the License for the specific language governing permissions
+# and limitations under the License.
+#
+# When distributing Covered Code, include this CDDL HEADER in each
+# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
+# If applicable, add the following below this CDDL 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."
diff --git a/tests/zfs-tests/tests/functional/cli_root/zfs_upgrade/zfs_upgrade_002_pos.ksh b/tests/zfs-tests/tests/functional/cli_root/zfs_upgrade/zfs_upgrade_002_pos.ksh
new file mode 100755 (executable)
index 0000000..2de2ed3
--- /dev/null
@@ -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_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."
diff --git a/tests/zfs-tests/tests/functional/cli_root/zfs_upgrade/zfs_upgrade_003_pos.ksh b/tests/zfs-tests/tests/functional/cli_root/zfs_upgrade/zfs_upgrade_003_pos.ksh
new file mode 100755 (executable)
index 0000000..24fac02
--- /dev/null
@@ -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 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."
diff --git a/tests/zfs-tests/tests/functional/cli_root/zfs_upgrade/zfs_upgrade_004_pos.ksh b/tests/zfs-tests/tests/functional/cli_root/zfs_upgrade/zfs_upgrade_004_pos.ksh
new file mode 100755 (executable)
index 0000000..47cff6e
--- /dev/null
@@ -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 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."
diff --git a/tests/zfs-tests/tests/functional/cli_root/zfs_upgrade/zfs_upgrade_005_pos.ksh b/tests/zfs-tests/tests/functional/cli_root/zfs_upgrade/zfs_upgrade_005_pos.ksh
new file mode 100755 (executable)
index 0000000..764727c
--- /dev/null
@@ -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 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."
diff --git a/tests/zfs-tests/tests/functional/cli_root/zfs_upgrade/zfs_upgrade_006_neg.ksh b/tests/zfs-tests/tests/functional/cli_root/zfs_upgrade/zfs_upgrade_006_neg.ksh
new file mode 100755 (executable)
index 0000000..6cd3bb4
--- /dev/null
@@ -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."
diff --git a/tests/zfs-tests/tests/functional/cli_root/zfs_upgrade/zfs_upgrade_007_neg.ksh b/tests/zfs-tests/tests/functional/cli_root/zfs_upgrade/zfs_upgrade_007_neg.ksh
new file mode 100755 (executable)
index 0000000..cdc7e41
--- /dev/null
@@ -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."
diff --git a/tests/zfs-tests/tests/functional/cli_root/zpool/Makefile.am b/tests/zfs-tests/tests/functional/cli_root/zpool/Makefile.am
new file mode 100644 (file)
index 0000000..2d0046c
--- /dev/null
@@ -0,0 +1,7 @@
+pkgdatadir = $(datadir)/@PACKAGE@/zfs-tests/tests/functional/cli_root/zpool
+dist_pkgdata_SCRIPTS = \
+       setup.ksh \
+       cleanup.ksh \
+       zpool_001_neg.ksh \
+       zpool_002_pos.ksh \
+       zpool_003_pos.ksh
diff --git a/tests/zfs-tests/tests/functional/cli_root/zpool/cleanup.ksh b/tests/zfs-tests/tests/functional/cli_root/zpool/cleanup.ksh
new file mode 100755 (executable)
index 0000000..79cd6e9
--- /dev/null
@@ -0,0 +1,30 @@
+#!/bin/ksh -p
+#
+# CDDL HEADER START
+#
+# The contents of this file are subject to the terms of the
+# Common Development and Distribution License (the "License").
+# You may not use this file except in compliance with the License.
+#
+# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
+# or http://www.opensolaris.org/os/licensing.
+# See the License for the specific language governing permissions
+# and limitations under the License.
+#
+# When distributing Covered Code, include this CDDL HEADER in each
+# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
+# If applicable, add the following below this CDDL HEADER, with the
+# fields enclosed by brackets "[]" replaced with your own identifying
+# information: 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
diff --git a/tests/zfs-tests/tests/functional/cli_root/zpool/setup.ksh b/tests/zfs-tests/tests/functional/cli_root/zpool/setup.ksh
new file mode 100755 (executable)
index 0000000..6a9af3b
--- /dev/null
@@ -0,0 +1,32 @@
+#!/bin/ksh -p
+#
+# CDDL HEADER START
+#
+# The contents of this file are subject to the terms of the
+# Common Development and Distribution License (the "License").
+# You may not use this file except in compliance with the License.
+#
+# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
+# or http://www.opensolaris.org/os/licensing.
+# See the License for the specific language governing permissions
+# and limitations under the License.
+#
+# When distributing Covered Code, include this CDDL HEADER in each
+# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
+# If applicable, add the following below this CDDL HEADER, with the
+# fields enclosed by brackets "[]" replaced with your own identifying
+# information: 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
diff --git a/tests/zfs-tests/tests/functional/cli_root/zpool/zpool_001_neg.ksh b/tests/zfs-tests/tests/functional/cli_root/zpool/zpool_001_neg.ksh
new file mode 100755 (executable)
index 0000000..7b37644
--- /dev/null
@@ -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."
diff --git a/tests/zfs-tests/tests/functional/cli_root/zpool/zpool_002_pos.ksh b/tests/zfs-tests/tests/functional/cli_root/zpool/zpool_002_pos.ksh
new file mode 100755 (executable)
index 0000000..d4265af
--- /dev/null
@@ -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 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"
+
+if is_linux; then
+       ulimit -c unlimited
+       echo "$corepath/core.zpool" >/proc/sys/kernel/core_pattern
+       echo 0 >/proc/sys/kernel/core_uses_pid
+else
+       $COREADM -p ${corepath}/core.%f
+fi
+
+export ZFS_ABORT=yes
+
+for subcmd in "${cmds[@]}" "${badparams[@]}"; do
+       corefile=${corepath}/core.zpool
+       $ZPOOL $subcmd >/dev/null 2>&1
+       ls -l $corepath >>/tmp/CORE
+       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."
diff --git a/tests/zfs-tests/tests/functional/cli_root/zpool/zpool_003_pos.ksh b/tests/zfs-tests/tests/functional/cli_root/zpool/zpool_003_pos.ksh
new file mode 100755 (executable)
index 0000000..7012eaf
--- /dev/null
@@ -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
+
+#
+# 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
+
+if is_linux; then
+        ulimit -c unlimited
+        echo "core" >/proc/sys/kernel/core_pattern
+        echo 0 >/proc/sys/kernel/core_uses_pid
+fi
+
+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."
diff --git a/tests/zfs-tests/tests/functional/cli_root/zpool_add/Makefile.am b/tests/zfs-tests/tests/functional/cli_root/zpool_add/Makefile.am
new file mode 100644 (file)
index 0000000..fef9343
--- /dev/null
@@ -0,0 +1,15 @@
+pkgdatadir = $(datadir)/@PACKAGE@/zfs-tests/tests/functional/cli_root/zpool_add
+dist_pkgdata_SCRIPTS = \
+       zpool_add.cfg \
+       zpool_add.kshlib \
+       setup.ksh \
+       cleanup.ksh \
+       zpool_add_001_pos.ksh \
+       zpool_add_002_pos.ksh \
+       zpool_add_003_pos.ksh \
+       zpool_add_004_pos.ksh \
+       zpool_add_005_pos.ksh \
+       zpool_add_006_pos.ksh \
+       zpool_add_007_neg.ksh \
+       zpool_add_008_neg.ksh \
+       zpool_add_009_neg.ksh
diff --git a/tests/zfs-tests/tests/functional/cli_root/zpool_add/cleanup.ksh b/tests/zfs-tests/tests/functional/cli_root/zpool_add/cleanup.ksh
new file mode 100755 (executable)
index 0000000..b4916f9
--- /dev/null
@@ -0,0 +1,37 @@
+#!/bin/ksh -p
+#
+# CDDL HEADER START
+#
+# The contents of this file are subject to the terms of the
+# Common Development and Distribution License (the "License").
+# You may not use this file except in compliance with the License.
+#
+# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
+# or http://www.opensolaris.org/os/licensing.
+# See the License for the specific language governing permissions
+# and limitations under the License.
+#
+# When distributing Covered Code, include this CDDL HEADER in each
+# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
+# If applicable, add the following below this CDDL HEADER, with the
+# fields enclosed by brackets "[]" replaced with your own identifying
+# information: Portions Copyright [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
diff --git a/tests/zfs-tests/tests/functional/cli_root/zpool_add/setup.ksh b/tests/zfs-tests/tests/functional/cli_root/zpool_add/setup.ksh
new file mode 100755 (executable)
index 0000000..f35dedd
--- /dev/null
@@ -0,0 +1,56 @@
+#!/bin/ksh -p
+#
+# CDDL HEADER START
+#
+# The contents of this file are subject to the terms of the
+# Common Development and Distribution License (the "License").
+# You may not use this file except in compliance with the License.
+#
+# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
+# or http://www.opensolaris.org/os/licensing.
+# See the License for the specific language governing permissions
+# and limitations under the License.
+#
+# When distributing Covered Code, include this CDDL HEADER in each
+# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
+# If applicable, add the following below this CDDL HEADER, with the
+# fields enclosed by brackets "[]" replaced with your own identifying
+# information: Portions Copyright [yyyy] [name of copyright owner]
+#
+# CDDL HEADER END
+#
+
+#
+# Copyright 2009 Sun Microsystems, Inc.  All rights reserved.
+# Use is subject to license terms.
+#
+
+#
+# Copyright (c) 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
diff --git a/tests/zfs-tests/tests/functional/cli_root/zpool_add/zpool_add.cfg b/tests/zfs-tests/tests/functional/cli_root/zpool_add/zpool_add.cfg
new file mode 100644 (file)
index 0000000..c18c6aa
--- /dev/null
@@ -0,0 +1,92 @@
+#
+# CDDL HEADER START
+#
+# The contents of this file are subject to the terms of the
+# Common Development and Distribution License (the "License").
+# You may not use this file except in compliance with the License.
+#
+# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
+# or http://www.opensolaris.org/os/licensing.
+# See the License for the specific language governing permissions
+# and limitations under the License.
+#
+# When distributing Covered Code, include this CDDL HEADER in each
+# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
+# If applicable, add the following below this CDDL 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, 2014 by Delphix. All rights reserved.
+#
+
+export DISK_ARRAY_NUM=0
+export DISK_ARRAY_LIMIT=4
+export DISKSARRAY=""
+
+#
+# Variables for zpool_add_006
+#
+export VDEVS_NUM=32
+
+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"
+
+if is_linux; then
+       export SLICE_PREFIX="p"
+       export SLICE0=1
+       export SLICE1=2
+       export SLICE3=4
+       export SLICE4=5
+       export SLICE5=6
+       export SLICE6=7
+else
+       export SLICE_PREFIX="s"
+       export SLICE0=0
+       export SLICE1=1
+       export SLICE3=3
+       export SLICE4=4
+       export SLICE5=5
+       export SLICE6=6
+fi
+
+export VOLSIZE=84m
diff --git a/tests/zfs-tests/tests/functional/cli_root/zpool_add/zpool_add.kshlib b/tests/zfs-tests/tests/functional/cli_root/zpool_add/zpool_add.kshlib
new file mode 100644 (file)
index 0000000..71d3027
--- /dev/null
@@ -0,0 +1,109 @@
+#
+# CDDL HEADER START
+#
+# The contents of this file are subject to the terms of the
+# Common Development and Distribution License (the "License").
+# You may not use this file except in compliance with the License.
+#
+# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
+# or http://www.opensolaris.org/os/licensing.
+# See the License for the specific language governing permissions
+# and limitations under the License.
+#
+# When distributing Covered Code, include this CDDL HEADER in each
+# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
+# If applicable, add the following below this CDDL HEADER, with the
+# fields enclosed by brackets "[]" replaced with your own identifying
+# information: Portions Copyright [yyyy] [name of copyright owner]
+#
+# CDDL HEADER END
+#
+
+#
+# Copyright 2007 Sun Microsystems, Inc.  All rights reserved.
+# Use is subject to license terms.
+#
+
+#
+# Copyright (c) 2012, 2014 by Delphix. All rights reserved.
+#
+
+. $STF_SUITE/include/libtest.shlib
+. $STF_SUITE/tests/functional/cli_root/zpool_add/zpool_add.cfg
+
+#
+# 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_DSKDIR}" >$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_DSKDIR}" >$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
+
+}
diff --git a/tests/zfs-tests/tests/functional/cli_root/zpool_add/zpool_add_001_pos.ksh b/tests/zfs-tests/tests/functional/cli_root/zpool_add/zpool_add_001_pos.ksh
new file mode 100755 (executable)
index 0000000..1f179fd
--- /dev/null
@@ -0,0 +1,142 @@
+#!/bin/ksh -p
+#
+# CDDL HEADER START
+#
+# The contents of this file are subject to the terms of the
+# Common Development and Distribution License (the "License").
+# You may not use this file except in compliance with the License.
+#
+# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
+# or http://www.opensolaris.org/os/licensing.
+# See the License for the specific language governing permissions
+# and limitations under the License.
+#
+# When distributing Covered Code, include this CDDL HEADER in each
+# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
+# If applicable, add the following below this CDDL HEADER, with the
+# fields enclosed by brackets "[]" replaced with your own identifying
+# information: Portions Copyright [yyyy] [name of copyright owner]
+#
+# CDDL HEADER END
+#
+
+#
+# Copyright 2009 Sun Microsystems, Inc.  All rights reserved.
+# Use is subject to license terms.
+#
+
+#
+# Copyright (c) 2014 by Delphix. All rights reserved.
+#
+
+. $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}${SLICE_PREFIX}${SLICE0} \
+               ${DEV_DSKDIR}/${disk}${SLICE_PREFIX}${SLICE0} \
+               \"${disk}${SLICE_PREFIX}${SLICE0} \
+               ${disk}${SLICE_PREFIX}${SLICE1}\""
+       mirrordevs="\"${DEV_DSKDIR}/${disk}${SLICE_PREFIX}${SLICE0} \
+               ${disk}${SLICE_PREFIX}${SLICE1}\""
+       raidzdevs="\"${DEV_DSKDIR}/${disk}${SLICE_PREFIX}${SLICE0} \
+               ${disk}${SLICE_PREFIX}${SLICE1}\""
+
+       ;;
+2|*)
+       pooldevs="${DISK0}${SLICE_PREFIX}${SLICE0} \
+               \"${DEV_DSKDIR}/${DISK0}${SLICE_PREFIX}${SLICE0} \
+               ${DISK1}${SLICE_PREFIX}${SLICE0}\" \
+               \"${DISK0}${SLICE_PREFIX}${SLICE0} \
+               ${DISK0}${SLICE_PREFIX}${SLICE1} \
+               ${DISK1}${SLICE_PREFIX}${SLICE1}\"\
+               \"${DISK0}${SLICE_PREFIX}${SLICE0} \
+               ${DISK1}${SLICE_PREFIX}${SLICE0} \
+               ${DISK0}${SLICE_PREFIX}${SLICE1}\
+               ${DISK1}${SLICE_PREFIX}${SLICE1}\""
+       mirrordevs="\"${DEV_DSKDIR}/${DISK0}${SLICE_PREFIX}${SLICE0} \
+               ${DISK1}${SLICE_PREFIX}${SLICE0}\""
+       raidzdevs="\"${DEV_DSKDIR}/${DISK0}${SLICE_PREFIX}${SLICE0} \
+               ${DISK1}${SLICE_PREFIX}${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
+       echo "I=$i keyword=${keywords[i]}" >>/tmp/LOG
+
+        case ${keywords[i]} in
+        ""|spare)
+               for vdev in "${poolarray[@]}"; do
+                       create_pool "$TESTPOOL" "${disk}${SLICE_PREFIX}${SLICE6}"
+                       log_must poolexists "$TESTPOOL"
+                       log_must $ZPOOL add -f "$TESTPOOL" ${keywords[i]} $vdev
+                       log_must vdevs_in_pool "$TESTPOOL" "$vdev"
+                       destroy_pool "$TESTPOOL"
+               done
+
+               ;;
+        mirror)
+               for vdev in "${mirrorarray[@]}"; do
+                       create_pool "$TESTPOOL" "${keywords[i]}" \
+                               "${disk}${SLICE_PREFIX}${SLICE4}" \
+                               "${disk}${SLICE_PREFIX}${SLICE5}"
+                       log_must poolexists "$TESTPOOL"
+                       log_must $ZPOOL add "$TESTPOOL" ${keywords[i]} $vdev
+                       log_must vdevs_in_pool "$TESTPOOL" "$vdev"
+                       destroy_pool "$TESTPOOL"
+               done
+
+               ;;
+        raidz|raidz1)
+               for vdev in "${raidzarray[@]}"; do
+                       create_pool "$TESTPOOL" "${keywords[i]}" \
+                               "${disk}${SLICE_PREFIX}${SLICE4}" \
+                               "${disk}${SLICE_PREFIX}${SLICE5}"
+                       log_must poolexists "$TESTPOOL"
+                       log_must $ZPOOL add "$TESTPOOL" ${keywords[i]} $vdev
+                       log_must vdevs_in_pool "$TESTPOOL" "$vdev"
+                       destroy_pool "$TESTPOOL"
+               done
+
+               ;;
+        esac
+
+        (( i = i+1 ))
+done
+
+log_pass "'zpool add <pool> <vdev> ...' executes successfully"
diff --git a/tests/zfs-tests/tests/functional/cli_root/zpool_add/zpool_add_002_pos.ksh b/tests/zfs-tests/tests/functional/cli_root/zpool_add/zpool_add_002_pos.ksh
new file mode 100755 (executable)
index 0000000..a76bc9e
--- /dev/null
@@ -0,0 +1,72 @@
+#!/bin/ksh -p
+#
+# CDDL HEADER START
+#
+# The contents of this file are subject to the terms of the
+# Common Development and Distribution License (the "License").
+# You may not use this file except in compliance with the License.
+#
+# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
+# or http://www.opensolaris.org/os/licensing.
+# See the License for the specific language governing permissions
+# and limitations under the License.
+#
+# When distributing Covered Code, include this CDDL HEADER in each
+# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
+# If applicable, add the following below this CDDL HEADER, with the
+# fields enclosed by brackets "[]" replaced with your own identifying
+# information: Portions Copyright [yyyy] [name of copyright owner]
+#
+# CDDL HEADER END
+#
+
+#
+# Copyright 2009 Sun Microsystems, Inc.  All rights reserved.
+# Use is subject to license terms.
+#
+
+#
+# Copyright (c) 2014 by Delphix. All rights reserved.
+#
+. $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}${SLICE_PREFIX}${SLICE0}" \
+       "${disk}${SLICE_PREFIX}${SLICE1}"
+log_must poolexists "$TESTPOOL"
+
+log_mustnot $ZPOOL add "$TESTPOOL" ${disk}${SLICE_PREFIX}${SLICE3}
+log_mustnot vdevs_in_pool "$TESTPOOL" "${disk}${SLICE_PREFIX}${SLICE3}"
+
+log_must $ZPOOL add -f "$TESTPOOL" ${disk}${SLICE_PREFIX}${SLICE3}
+log_must vdevs_in_pool "$TESTPOOL" "${disk}${SLICE_PREFIX}${SLICE3}"
+
+log_pass "'zpool add -f <pool> <vdev> ...' executes successfully."
diff --git a/tests/zfs-tests/tests/functional/cli_root/zpool_add/zpool_add_003_pos.ksh b/tests/zfs-tests/tests/functional/cli_root/zpool_add/zpool_add_003_pos.ksh
new file mode 100755 (executable)
index 0000000..a422e51
--- /dev/null
@@ -0,0 +1,78 @@
+#!/bin/ksh -p
+#
+# CDDL HEADER START
+#
+# The contents of this file are subject to the terms of the
+# Common Development and Distribution License (the "License").
+# You may not use this file except in compliance with the License.
+#
+# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
+# or http://www.opensolaris.org/os/licensing.
+# See the License for the specific language governing permissions
+# and limitations under the License.
+#
+# When distributing Covered Code, include this CDDL HEADER in each
+# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
+# If applicable, add the following below this CDDL HEADER, with the
+# fields enclosed by brackets "[]" replaced with your own identifying
+# information: Portions Copyright [yyyy] [name of copyright owner]
+#
+# CDDL HEADER END
+#
+
+#
+# Copyright 2009 Sun Microsystems, Inc.  All rights reserved.
+# Use is subject to license terms.
+#
+
+#
+# Copyright (c) 2014 by Delphix. All rights reserved.
+#
+
+. $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}${SLICE_PREFIX}${SLICE0}"
+log_must poolexists "$TESTPOOL"
+
+$ZPOOL add -n "$TESTPOOL" ${disk}${SLICE_PREFIX}${SLICE1} > $tmpfile
+
+log_mustnot vdevs_in_pool "$TESTPOOL" "${disk}${SLICE_PREFIX}${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."
diff --git a/tests/zfs-tests/tests/functional/cli_root/zpool_add/zpool_add_004_pos.ksh b/tests/zfs-tests/tests/functional/cli_root/zpool_add/zpool_add_004_pos.ksh
new file mode 100755 (executable)
index 0000000..a893c31
--- /dev/null
@@ -0,0 +1,78 @@
+#!/bin/ksh -p
+#
+# CDDL HEADER START
+#
+# The contents of this file are subject to the terms of the
+# Common Development and Distribution License (the "License").
+# You may not use this file except in compliance with the License.
+#
+# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
+# or http://www.opensolaris.org/os/licensing.
+# See the License for the specific language governing permissions
+# and limitations under the License.
+#
+# When distributing Covered Code, include this CDDL HEADER in each
+# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
+# If applicable, add the following below this CDDL HEADER, with the
+# fields enclosed by brackets "[]" replaced with your own identifying
+# information: Portions Copyright [yyyy] [name of copyright owner]
+#
+# CDDL HEADER END
+#
+
+#
+# Copyright 2009 Sun Microsystems, Inc.  All rights reserved.
+# Use is subject to license terms.
+#
+
+#
+# Copyright (c) 2014 by Delphix. All rights reserved.
+#
+
+. $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}${SLICE_PREFIX}${SLICE0}"
+log_must poolexists "$TESTPOOL"
+
+create_pool "$TESTPOOL1" "${disk}${SLICE_PREFIX}${SLICE1}"
+log_must poolexists "$TESTPOOL1"
+log_must $ZFS create -V $VOLSIZE $TESTPOOL1/$TESTVOL
+block_device_wait
+
+log_must $ZPOOL add "$TESTPOOL" $ZVOL_DEVDIR/$TESTPOOL1/$TESTVOL
+
+log_must vdevs_in_pool "$TESTPOOL" "$ZVOL_DEVDIR/$TESTPOOL1/$TESTVOL"
+
+log_pass "'zpool add <pool> <vdev> ...' adds zfs volume to the pool successfully"
diff --git a/tests/zfs-tests/tests/functional/cli_root/zpool_add/zpool_add_005_pos.ksh b/tests/zfs-tests/tests/functional/cli_root/zpool_add/zpool_add_005_pos.ksh
new file mode 100755 (executable)
index 0000000..4cfc904
--- /dev/null
@@ -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}${SLICE_PREFIX}${SLICE3}
+
+create_pool "$TESTPOOL" "${disk}${SLICE_PREFIX}${SLICE0}"
+log_must poolexists "$TESTPOOL"
+
+create_pool "$TESTPOOL1" "${disk}${SLICE_PREFIX}${SLICE1}"
+log_must poolexists "$TESTPOOL1"
+log_mustnot $ZPOOL add -f "$TESTPOOL" ${disk}${SLICE_PREFIX}${SLICE1}
+
+log_mustnot $ZPOOL add -f "$TESTPOOL" $mnttab_dev
+
+log_mustnot $ZPOOL add -f "$TESTPOOL" $vfstab_dev
+
+log_must $ECHO "y" | $NEWFS ${DEV_DSKDIR}/$dump_dev > /dev/null 2>&1
+log_must $DUMPADM -u -d ${DEV_DSKDIR}/$dump_dev > /dev/null
+log_mustnot $ZPOOL add -f "$TESTPOOL" $dump_dev
+
+log_pass "'zpool add' should fail with inapplicable scenarios."
diff --git a/tests/zfs-tests/tests/functional/cli_root/zpool_add/zpool_add_006_pos.ksh b/tests/zfs-tests/tests/functional/cli_root/zpool_add/zpool_add_006_pos.ksh
new file mode 100755 (executable)
index 0000000..c60814d
--- /dev/null
@@ -0,0 +1,78 @@
+#!/bin/ksh -p
+#
+# CDDL HEADER START
+#
+# The contents of this file are subject to the terms of the
+# Common Development and Distribution License (the "License").
+# You may not use this file except in compliance with the License.
+#
+# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
+# or http://www.opensolaris.org/os/licensing.
+# See the License for the specific language governing permissions
+# and limitations under the License.
+#
+# When distributing Covered Code, include this CDDL HEADER in each
+# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
+# If applicable, add the following below this CDDL HEADER, with the
+# fields enclosed by brackets "[]" replaced with your own identifying
+# information: Portions Copyright [yyyy] [name of copyright owner]
+#
+# CDDL HEADER END
+#
+
+#
+# Copyright 2009 Sun Microsystems, Inc.  All rights reserved.
+# Use is subject to license terms.
+#
+
+#
+# Copyright (c) 2014 by Delphix. All rights reserved.
+#
+
+. $STF_SUITE/include/libtest.shlib
+. $STF_SUITE/tests/functional/cli_root/zpool_add/zpool_add.kshlib
+
+#
+# DESCRIPTION:
+# Adding a large number of file based vdevs to a zpool works.
+#
+# STRATEGY:
+# 1. Create a file based pool.
+# 2. Add 32 file based vdevs to it.
+# 3. Attempt to add a file based vdev that's too small; verify failure.
+#
+
+verify_runnable "global"
+
+function cleanup
+{
+       poolexists $TESTPOOL1 && \
+               destroy_pool $TESTPOOL1
+
+       poolexists $TESTPOOL && \
+               destroy_pool $TESTPOOL
+
+       [[ -d $TESTDIR ]] && log_must $RM -rf $TESTDIR
+       partition_cleanup
+}
+
+log_assert "Adding a large number of file based vdevs to a zpool works."
+log_onexit cleanup
+
+create_pool $TESTPOOL ${DISKS%% *}
+log_must $ZFS create -o mountpoint=$TESTDIR $TESTPOOL/$TESTFS
+log_must $MKFILE 64m $TESTDIR/file.00
+create_pool "$TESTPOOL1" "$TESTDIR/file.00"
+
+vdevs_list=$($ECHO $TESTDIR/file.{01..32})
+log_must $MKFILE 64m $vdevs_list
+
+log_must $ZPOOL add -f "$TESTPOOL1" $vdevs_list
+log_must vdevs_in_pool "$TESTPOOL1" "$vdevs_list"
+
+# Attempt to add a file based vdev that's too small.
+log_must $MKFILE 32m $TESTDIR/broken_file
+log_mustnot $ZPOOL add -f "$TESTPOOL1" ${TESTDIR}/broken_file
+log_mustnot vdevs_in_pool "$TESTPOOL1" "${TESTDIR}/broken_file"
+
+log_pass "Adding a large number of file based vdevs to a zpool works."
diff --git a/tests/zfs-tests/tests/functional/cli_root/zpool_add/zpool_add_007_neg.ksh b/tests/zfs-tests/tests/functional/cli_root/zpool_add/zpool_add_007_neg.ksh
new file mode 100755 (executable)
index 0000000..25225fc
--- /dev/null
@@ -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}${SLICE_PREFIX}${SLICE1}"
+
+create_pool "$TESTPOOL" "${disk}${SLICE_PREFIX}${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."
diff --git a/tests/zfs-tests/tests/functional/cli_root/zpool_add/zpool_add_008_neg.ksh b/tests/zfs-tests/tests/functional/cli_root/zpool_add/zpool_add_008_neg.ksh
new file mode 100755 (executable)
index 0000000..ffb5910
--- /dev/null
@@ -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}${SLICE_PREFIX}${SLICE1}" \
+       "-f $TESTPOOL nonexistent_vdev"
+
+create_pool "$TESTPOOL" "${disk}${SLICE_PREFIX}${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."
diff --git a/tests/zfs-tests/tests/functional/cli_root/zpool_add/zpool_add_009_neg.ksh b/tests/zfs-tests/tests/functional/cli_root/zpool_add/zpool_add_009_neg.ksh
new file mode 100755 (executable)
index 0000000..f547883
--- /dev/null
@@ -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 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}${SLICE_PREFIX}${SLICE0}"
+log_must poolexists "$TESTPOOL"
+
+log_mustnot $ZPOOL add -f "$TESTPOOL" ${disk}${SLICE_PREFIX}${SLICE1} \
+       ${disk}${SLICE_PREFIX}${SLICE1}
+log_mustnot $ZPOOL add -f "$TESTPOOL" ${disk}${SLICE_PREFIX}${SLICE0}
+
+log_pass "'zpool add' get fail as expected if vdevs are the same or vdev is " \
+       "contained in the given pool."
diff --git a/tests/zfs-tests/tests/functional/cli_root/zpool_attach/Makefile.am b/tests/zfs-tests/tests/functional/cli_root/zpool_attach/Makefile.am
new file mode 100644 (file)
index 0000000..f642108
--- /dev/null
@@ -0,0 +1,5 @@
+pkgdatadir = $(datadir)/@PACKAGE@/zfs-tests/tests/functional/cli_root/zpool_attach
+dist_pkgdata_SCRIPTS = \
+       setup.ksh \
+       cleanup.ksh \
+       zpool_attach_001_neg.ksh
diff --git a/tests/zfs-tests/tests/functional/cli_root/zpool_attach/cleanup.ksh b/tests/zfs-tests/tests/functional/cli_root/zpool_attach/cleanup.ksh
new file mode 100755 (executable)
index 0000000..89c1462
--- /dev/null
@@ -0,0 +1,32 @@
+#!/bin/ksh -p
+#
+# CDDL HEADER START
+#
+# The contents of this file are subject to the terms of the
+# Common Development and Distribution License (the "License").
+# You may not use this file except in compliance with the License.
+#
+# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
+# or http://www.opensolaris.org/os/licensing.
+# See the License for the specific language governing permissions
+# and limitations under the License.
+#
+# When distributing Covered Code, include this CDDL HEADER in each
+# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
+# If applicable, add the following below this CDDL HEADER, with the
+# fields enclosed by brackets "[]" replaced with your own identifying
+# information: 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
diff --git a/tests/zfs-tests/tests/functional/cli_root/zpool_attach/setup.ksh b/tests/zfs-tests/tests/functional/cli_root/zpool_attach/setup.ksh
new file mode 100755 (executable)
index 0000000..2229f87
--- /dev/null
@@ -0,0 +1,35 @@
+#!/bin/ksh -p
+#
+# CDDL HEADER START
+#
+# The contents of this file are subject to the terms of the
+# Common Development and Distribution License (the "License").
+# You may not use this file except in compliance with the License.
+#
+# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
+# or http://www.opensolaris.org/os/licensing.
+# See the License for the specific language governing permissions
+# and limitations under the License.
+#
+# When distributing Covered Code, include this CDDL HEADER in each
+# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
+# If applicable, add the following below this CDDL 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
diff --git a/tests/zfs-tests/tests/functional/cli_root/zpool_attach/zpool_attach_001_neg.ksh b/tests/zfs-tests/tests/functional/cli_root/zpool_attach/zpool_attach_001_neg.ksh
new file mode 100755 (executable)
index 0000000..df53b12
--- /dev/null
@@ -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."
diff --git a/tests/zfs-tests/tests/functional/cli_root/zpool_clear/Makefile.am b/tests/zfs-tests/tests/functional/cli_root/zpool_clear/Makefile.am
new file mode 100644 (file)
index 0000000..1d9a719
--- /dev/null
@@ -0,0 +1,8 @@
+pkgdatadir = $(datadir)/@PACKAGE@/zfs-tests/tests/functional/cli_root/zpool_clear
+dist_pkgdata_SCRIPTS = \
+       zpool_clear.cfg \
+       setup.ksh \
+       cleanup.ksh \
+       zpool_clear_001_pos.ksh \
+       zpool_clear_002_neg.ksh \
+       zpool_clear_003_neg.ksh
diff --git a/tests/zfs-tests/tests/functional/cli_root/zpool_clear/cleanup.ksh b/tests/zfs-tests/tests/functional/cli_root/zpool_clear/cleanup.ksh
new file mode 100755 (executable)
index 0000000..79cd6e9
--- /dev/null
@@ -0,0 +1,30 @@
+#!/bin/ksh -p
+#
+# CDDL HEADER START
+#
+# The contents of this file are subject to the terms of the
+# Common Development and Distribution License (the "License").
+# You may not use this file except in compliance with the License.
+#
+# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
+# or http://www.opensolaris.org/os/licensing.
+# See the License for the specific language governing permissions
+# and limitations under the License.
+#
+# When distributing Covered Code, include this CDDL HEADER in each
+# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
+# If applicable, add the following below this CDDL HEADER, with the
+# fields enclosed by brackets "[]" replaced with your own identifying
+# information: 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
diff --git a/tests/zfs-tests/tests/functional/cli_root/zpool_clear/setup.ksh b/tests/zfs-tests/tests/functional/cli_root/zpool_clear/setup.ksh
new file mode 100755 (executable)
index 0000000..6a9af3b
--- /dev/null
@@ -0,0 +1,32 @@
+#!/bin/ksh -p
+#
+# CDDL HEADER START
+#
+# The contents of this file are subject to the terms of the
+# Common Development and Distribution License (the "License").
+# You may not use this file except in compliance with the License.
+#
+# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
+# or http://www.opensolaris.org/os/licensing.
+# See the License for the specific language governing permissions
+# and limitations under the License.
+#
+# When distributing Covered Code, include this CDDL HEADER in each
+# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
+# If applicable, add the following below this CDDL HEADER, with the
+# fields enclosed by brackets "[]" replaced with your own identifying
+# information: 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
diff --git a/tests/zfs-tests/tests/functional/cli_root/zpool_clear/zpool_clear.cfg b/tests/zfs-tests/tests/functional/cli_root/zpool_clear/zpool_clear.cfg
new file mode 100644 (file)
index 0000000..097a43b
--- /dev/null
@@ -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
diff --git a/tests/zfs-tests/tests/functional/cli_root/zpool_clear/zpool_clear_001_pos.ksh b/tests/zfs-tests/tests/functional/cli_root/zpool_clear/zpool_clear_001_pos.ksh
new file mode 100755 (executable)
index 0000000..b2a2ed5
--- /dev/null
@@ -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."
diff --git a/tests/zfs-tests/tests/functional/cli_root/zpool_clear/zpool_clear_002_neg.ksh b/tests/zfs-tests/tests/functional/cli_root/zpool_clear/zpool_clear_002_neg.ksh
new file mode 100755 (executable)
index 0000000..35c2b64
--- /dev/null
@@ -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."
diff --git a/tests/zfs-tests/tests/functional/cli_root/zpool_clear/zpool_clear_003_neg.ksh b/tests/zfs-tests/tests/functional/cli_root/zpool_clear/zpool_clear_003_neg.ksh
new file mode 100755 (executable)
index 0000000..241ac03
--- /dev/null
@@ -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."
diff --git a/tests/zfs-tests/tests/functional/cli_root/zpool_create/Makefile.am b/tests/zfs-tests/tests/functional/cli_root/zpool_create/Makefile.am
new file mode 100644 (file)
index 0000000..0530dec
--- /dev/null
@@ -0,0 +1,32 @@
+pkgdatadir = $(datadir)/@PACKAGE@/zfs-tests/tests/functional/cli_root/zpool_create
+dist_pkgdata_SCRIPTS = \
+       zpool_create.cfg \
+       zpool_create.shlib \
+       setup.ksh \
+       cleanup.ksh \
+       zpool_create_001_pos.ksh \
+       zpool_create_002_pos.ksh \
+       zpool_create_003_pos.ksh \
+       zpool_create_004_pos.ksh \
+       zpool_create_005_pos.ksh \
+       zpool_create_006_pos.ksh \
+       zpool_create_007_neg.ksh \
+       zpool_create_008_pos.ksh \
+       zpool_create_009_neg.ksh \
+       zpool_create_010_neg.ksh \
+       zpool_create_011_neg.ksh \
+       zpool_create_012_neg.ksh \
+       zpool_create_014_neg.ksh \
+       zpool_create_015_neg.ksh \
+       zpool_create_016_pos.ksh \
+       zpool_create_017_neg.ksh \
+       zpool_create_018_pos.ksh \
+       zpool_create_019_pos.ksh \
+       zpool_create_020_pos.ksh \
+       zpool_create_021_pos.ksh \
+       zpool_create_022_pos.ksh \
+       zpool_create_023_neg.ksh \
+       zpool_create_features_001_pos.ksh \
+       zpool_create_features_002_pos.ksh \
+       zpool_create_features_003_pos.ksh \
+       zpool_create_features_004_neg.ksh
diff --git a/tests/zfs-tests/tests/functional/cli_root/zpool_create/cleanup.ksh b/tests/zfs-tests/tests/functional/cli_root/zpool_create/cleanup.ksh
new file mode 100755 (executable)
index 0000000..d3134a7
--- /dev/null
@@ -0,0 +1,39 @@
+#!/bin/ksh -p
+#
+# CDDL HEADER START
+#
+# The contents of this file are subject to the terms of the
+# Common Development and Distribution License (the "License").
+# You may not use this file except in compliance with the License.
+#
+# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
+# or http://www.opensolaris.org/os/licensing.
+# See the License for the specific language governing permissions
+# and limitations under the License.
+#
+# When distributing Covered Code, include this CDDL HEADER in each
+# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
+# If applicable, add the following below this CDDL HEADER, with the
+# fields enclosed by brackets "[]" replaced with your own identifying
+# information: Portions Copyright [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
diff --git a/tests/zfs-tests/tests/functional/cli_root/zpool_create/setup.ksh b/tests/zfs-tests/tests/functional/cli_root/zpool_create/setup.ksh
new file mode 100755 (executable)
index 0000000..409d5d0
--- /dev/null
@@ -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 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
diff --git a/tests/zfs-tests/tests/functional/cli_root/zpool_create/zpool_create.cfg b/tests/zfs-tests/tests/functional/cli_root/zpool_create/zpool_create.cfg
new file mode 100644 (file)
index 0000000..d39b987
--- /dev/null
@@ -0,0 +1,109 @@
+#
+# CDDL HEADER START
+#
+# The contents of this file are subject to the terms of the
+# Common Development and Distribution License (the "License").
+# You may not use this file except in compliance with the License.
+#
+# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
+# or http://www.opensolaris.org/os/licensing.
+# See the License for the specific language governing permissions
+# and limitations under the License.
+#
+# When distributing Covered Code, include this CDDL HEADER in each
+# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
+# If applicable, add the following below this CDDL HEADER, with the
+# fields enclosed by brackets "[]" replaced with your own identifying
+# information: Portions Copyright [yyyy] [name of copyright owner]
+#
+# CDDL HEADER END
+#
+
+#
+# Copyright 2008 Sun Microsystems, Inc.  All rights reserved.
+# Use is subject to license terms.
+#
+
+#
+# Copyright (c) 2012, 2014 by Delphix. All rights reserved.
+#
+
+. $STF_SUITE/include/libtest.shlib
+
+export DISK_ARRAY_NUM=0
+export DISK_ARRAY_LIMIT=4
+export DISKSARRAY=""
+export VDEVS_NUM=32
+
+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"
+
+if is_linux; then
+       export SLICE_PREFIX="p"
+       export SLICE0=1
+       export SLICE1=2
+       export SLICE2=3
+       export SLICE3=4
+       export SLICE4=5
+       export SLICE5=6
+       export SLICE6=7
+       export SLICE7=8
+else
+       export SLICE_PREFIX="s"
+       export SLICE0=0
+       export SLICE1=1
+       export SLICE2=2
+       export SLICE3=3
+       export SLICE4=4
+       export SLICE5=5
+       export SLICE6=6
+       export SLICE7=7
+fi
+
+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"
diff --git a/tests/zfs-tests/tests/functional/cli_root/zpool_create/zpool_create.shlib b/tests/zfs-tests/tests/functional/cli_root/zpool_create/zpool_create.shlib
new file mode 100644 (file)
index 0000000..ff104f2
--- /dev/null
@@ -0,0 +1,154 @@
+#
+# CDDL HEADER START
+#
+# The contents of this file are subject to the terms of the
+# Common Development and Distribution License (the "License").
+# You may not use this file except in compliance with the License.
+#
+# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
+# or http://www.opensolaris.org/os/licensing.
+# See the License for the specific language governing permissions
+# and limitations under the License.
+#
+# When distributing Covered Code, include this CDDL HEADER in each
+# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
+# If applicable, add the following below this CDDL 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|ext2 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|ext2 file system
+#
+function create_blockfile
+{
+       typeset size=$1
+       typeset file=$2
+       typeset disk=$3
+       typeset dir=`$DIRNAME $file`
+
+       if [[ -d $dir ]]; then
+               ismounted $dir $NEWFS_DEFAULT_FS
+               (( $? == 0 )) && \
+                       log_must $UMOUNT -f $dir
+       else
+               log_must $MKDIR -p $dir
+       fi
+
+       $ECHO "y" | $NEWFS ${DEV_RDSKDIR}/$disk >/dev/null 2>&1
+       (( $? != 0 )) &&
+               log_fail "Create file system fail."
+
+        log_must $MOUNT ${DEV_DSKDIR}/$disk $dir
+        log_must $MKFILE $size $file
+}
+
+#
+# Umount the ext2|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 is_linux; then
+                               if ismounted $dir ext2; then
+                                       typeset dev=$($DF -lht ext2 | \
+                                               $GREP "$dir" | \
+                                               $AWK '{print $1}')
+                                       log_must $UMOUNT -f $dir
+                                       create_pool ${TESTPOOL}.tmp $dev
+                                       destroy_pool ${TESTPOOL}.tmp
+                               fi
+                       else
+                               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
+                       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_DSKDIR}" >$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
+}
diff --git a/tests/zfs-tests/tests/functional/cli_root/zpool_create/zpool_create_001_pos.ksh b/tests/zfs-tests/tests/functional/cli_root/zpool_create/zpool_create_001_pos.ksh
new file mode 100755 (executable)
index 0000000..824c6dc
--- /dev/null
@@ -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 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}${SLICE_PREFIX}${SLICE5}
+       create_blockfile $FILESIZE $TESTDIR1/$FILEDISK1 \
+               ${disk}${SLICE_PREFIX}${SLICE6}
+
+       pooldevs="${disk}${SLICE_PREFIX}${SLICE0} \
+               ${DEV_DSKDIR}/${disk}${SLICE_PREFIX}${SLICE0} \
+               \"${disk}${SLICE_PREFIX}${SLICE0} \
+               ${disk}${SLICE_PREFIX}${SLICE1}\" \
+                  $TESTDIR0/$FILEDISK0"
+       raidzdevs="\"${DEV_DSKDIR}/${disk}${SLICE_PREFIX}${SLICE0} \
+               ${disk}${SLICE_PREFIX}${SLICE1}\" \
+               \"${disk}${SLICE_PREFIX}${SLICE0} \
+               ${disk}${SLICE_PREFIX}${SLICE1} \
+               ${disk}${SLICE_PREFIX}${SLICE3}\" \
+               \"${disk}${SLICE_PREFIX}${SLICE0} \
+               ${disk}${SLICE_PREFIX}${SLICE1} \
+               ${disk}${SLICE_PREFIX}${SLICE3} \
+               ${disk}${SLICE_PREFIX}${SLICE4}\"\
+               \"$TESTDIR0/$FILEDISK0 $TESTDIR1/$FILEDISK1\""
+       mirrordevs=$raidzdevs
+       ;;
+2|*)
+       create_blockfile $FILESIZE $TESTDIR0/$FILEDISK0 \
+               ${DISK0}${SLICE_PREFIX}${SLICE5}
+        create_blockfile $FILESIZE $TESTDIR1/$FILEDISK1 \
+               ${DISK1}${SLICE_PREFIX}${SLICE5}
+
+       pooldevs="${DISK0}${SLICE_PREFIX}${SLICE0} \
+               \"${DEV_DSKDIR}/${DISK0}${SLICE_PREFIX}${SLICE0} \
+               ${DISK1}${SLICE_PREFIX}${SLICE0}\" \
+               \"${DISK0}${SLICE_PREFIX}${SLICE0} \
+               ${DISK0}${SLICE_PREFIX}${SLICE1} \
+               ${DISK1}${SLICE_PREFIX}${SLICE1}\"\
+               \"${DISK0}${SLICE_PREFIX}${SLICE0} \
+               ${DISK1}${SLICE_PREFIX}${SLICE0} \
+               ${DISK0}${SLICE_PREFIX}${SLICE1}\
+               ${DISK1}${SLICE_PREFIX}${SLICE1}\" \
+               \"$TESTDIR0/$FILEDISK0 $TESTDIR1/$FILEDISK1\""
+       raidzdevs="\"${DEV_DSKDIR}/${DISK0}${SLICE_PREFIX}${SLICE0} \
+               ${DISK1}${SLICE_PREFIX}${SLICE0}\" \
+               \"${DISK0}${SLICE_PREFIX}${SLICE0} \
+               ${DISK0}${SLICE_PREFIX}${SLICE1} \
+               ${DISK1}${SLICE_PREFIX}${SLICE1}\" \
+               \"${DISK0}${SLICE_PREFIX}${SLICE0} \
+               ${DISK1}${SLICE_PREFIX}${SLICE0} \
+               ${DISK0}${SLICE_PREFIX}${SLICE1} \
+               ${DISK1}${SLICE_PREFIX}${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."
diff --git a/tests/zfs-tests/tests/functional/cli_root/zpool_create/zpool_create_002_pos.ksh b/tests/zfs-tests/tests/functional/cli_root/zpool_create/zpool_create_002_pos.ksh
new file mode 100755 (executable)
index 0000000..bba3d94
--- /dev/null
@@ -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 -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}${SLICE_PREFIX}${SLICE0}"
+log_must $ECHO "y" | $NEWFS \
+       ${DEV_RDSKDIR}/${disk}${SLICE_PREFIX}${SLICE1} >/dev/null 2>&1
+create_blockfile $FILESIZE $TESTDIR0/$FILEDISK0 ${disk}${SLICE_PREFIX}${SLICE4}
+create_blockfile $FILESIZE1 $TESTDIR1/$FILEDISK1 ${disk}${SLICE_PREFIX}${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}${SLICE_PREFIX}${SLICE0}"
+create_pool "$TESTPOOL1" "${disk}${SLICE_PREFIX}${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}${SLICE_PREFIX}${SLICE1}"
+create_pool "$TESTPOOL2" "${disk}${SLICE_PREFIX}${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}${SLICE_PREFIX}${SLICE3}
+create_pool "$TESTPOOL4" "mirror" \
+       /var/tmp/$FILEDISK0 ${disk}${SLICE_PREFIX}${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."
diff --git a/tests/zfs-tests/tests/functional/cli_root/zpool_create/zpool_create_003_pos.ksh b/tests/zfs-tests/tests/functional/cli_root/zpool_create/zpool_create_003_pos.ksh
new file mode 100755 (executable)
index 0000000..008828b
--- /dev/null
@@ -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}${SLICE_PREFIX}${SLICE0} > $tmpfile
+destroy_pool $TESTPOOL
+
+$ZPOOL create -n  $TESTPOOL ${disk}${SLICE_PREFIX}${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."
diff --git a/tests/zfs-tests/tests/functional/cli_root/zpool_create/zpool_create_004_pos.ksh b/tests/zfs-tests/tests/functional/cli_root/zpool_create/zpool_create_004_pos.ksh
new file mode 100755 (executable)
index 0000000..b5a3709
--- /dev/null
@@ -0,0 +1,80 @@
+#!/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, 2014 by Delphix. All rights reserved.
+#
+
+. $STF_SUITE/tests/functional/cli_root/zpool_create/zpool_create.shlib
+
+#
+# DESCRIPTION:
+# Create a storage pool with many file based vdevs.
+#
+# STRATEGY:
+# 1. Create assigned number of files in ZFS filesystem as vdevs.
+# 2. Creating a new pool based on the vdevs should work.
+# 3. Creating a pool with a file based vdev that is too small should fail.
+#
+
+verify_runnable "global"
+
+function cleanup
+{
+       typeset pool=""
+
+       poolexists $TESTPOOL1 && destroy_pool $TESTPOOL1
+       poolexists $TESTPOOL && destroy_pool $TESTPOOL
+
+       [[ -d $TESTDIR ]] && log_must $RM -rf $TESTDIR
+       partition_disk $SIZE $disk 6
+}
+
+log_assert "Storage pools with $VDEVS_NUM file based vdevs can be created."
+log_onexit cleanup
+
+disk=${DISKS%% *}
+create_pool $TESTPOOL $disk
+log_must $ZFS create -o mountpoint=$TESTDIR $TESTPOOL/$TESTFS
+
+vdevs_list=$($ECHO $TESTDIR/file.{01..32})
+log_must $MKFILE 64m $vdevs_list
+
+create_pool "$TESTPOOL1" $vdevs_list
+log_must vdevs_in_pool "$TESTPOOL1" "$vdevs_list"
+
+if poolexists $TESTPOOL1; then
+       destroy_pool $TESTPOOL1
+else
+       log_fail "Creating pool with large numbers of file-vdevs failed."
+fi
+
+log_must $MKFILE 32m $TESTDIR/broken_file
+vdevs_list="$vdevs_list ${TESTDIR}/broken_file"
+log_mustnot $ZPOOL create -f $TESTPOOL1 $vdevs_list
+
+log_pass "Storage pools with many file based vdevs can be created."
diff --git a/tests/zfs-tests/tests/functional/cli_root/zpool_create/zpool_create_005_pos.ksh b/tests/zfs-tests/tests/functional/cli_root/zpool_create/zpool_create_005_pos.ksh
new file mode 100755 (executable)
index 0000000..c2f3789
--- /dev/null
@@ -0,0 +1,130 @@
+#!/bin/ksh -p
+#
+# CDDL HEADER START
+#
+# The contents of this file are subject to the terms of the
+# Common Development and Distribution License (the "License").
+# You may not use this file except in compliance with the License.
+#
+# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
+# or http://www.opensolaris.org/os/licensing.
+# See the License for the specific language governing permissions
+# and limitations under the License.
+#
+# When distributing Covered Code, include this CDDL HEADER in each
+# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
+# If applicable, add the following below this CDDL 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" == "-m $TESTDIR1" ]]; then
+                       [[ ! -d $TESTDIR1 ]] && \
+                               log_fail "$TESTDIR1 is not created auotmatically."
+                       [[ "$mpt" != "$TESTDIR1" ]] && \
+                               log_fail "$TESTPOOL is not mounted on $TESTDIR1."
+               elif [[ "$opt" == "-R $TESTDIR1" ]]; then
+                       [[ ! -d $TESTDIR1/$TESTPOOL ]] && \
+                               log_fail "$TESTDIR1/$TESTPOOL is not created auotmatically."
+                       [[ "$mpt" != "$TESTDIR1/$TESTPOOL" ]] && \
+                               log_fail "$TESTPOOL is not mounted on $TESTDIR1/$TESTPOOL."
+               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."
diff --git a/tests/zfs-tests/tests/functional/cli_root/zpool_create/zpool_create_006_pos.ksh b/tests/zfs-tests/tests/functional/cli_root/zpool_create/zpool_create_006_pos.ksh
new file mode 100755 (executable)
index 0000000..70dcadc
--- /dev/null
@@ -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."
diff --git a/tests/zfs-tests/tests/functional/cli_root/zpool_create/zpool_create_007_neg.ksh b/tests/zfs-tests/tests/functional/cli_root/zpool_create/zpool_create_007_neg.ksh
new file mode 100755 (executable)
index 0000000..3211b0b
--- /dev/null
@@ -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 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}${SLICE_PREFIX}${SLICE0} \
+       ${disk}${SLICE_PREFIX}${SLICE1}" \
+       "$TESTPOOL ${disk}${SLICE_PREFIX}${SLICE0} \
+       log ${disk}${SLICE_PREFIX}${SLICE1} \
+       log ${disk}${SLICE_PREFIX}${SLICE3}" \
+       "$TESTPOOL ${disk}${SLICE_PREFIX}${SLICE0} \
+       spare ${disk}${SLICE_PREFIX}${SLICE1} \
+       spare ${disk}${SLICE_PREFIX}${SLICE3}" \
+       "$TESTPOOL RAIDZ1 ${disk}${SLICE_PREFIX}${SLICE0} \
+       ${disk}${SLICE_PREFIX}${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."
diff --git a/tests/zfs-tests/tests/functional/cli_root/zpool_create/zpool_create_008_pos.ksh b/tests/zfs-tests/tests/functional/cli_root/zpool_create/zpool_create_008_pos.ksh
new file mode 100755 (executable)
index 0000000..27506a6
--- /dev/null
@@ -0,0 +1,152 @@
+#!/bin/ksh -p
+#
+# CDDL HEADER START
+#
+# The contents of this file are subject to the terms of the
+# Common Development and Distribution License (the "License").
+# You may not use this file except in compliance with the License.
+#
+# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
+# or http://www.opensolaris.org/os/licensing.
+# See the License for the specific language governing permissions
+# and limitations under the License.
+#
+# When distributing Covered Code, include this CDDL HEADER in each
+# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
+# If applicable, add the following below this CDDL 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}${SLICE_PREFIX}${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}${SLICE_PREFIX}${SLICE0}
+log_must $ZPOOL create -f $TESTPOOL ${disk}${SLICE_PREFIX}${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}${SLICE_PREFIX}${SLICE0} \
+       ${disk}${SLICE_PREFIX}${SLICE1}
+log_must $ZPOOL export $TESTPOOL
+exported_pool=true
+log_mustnot $ZPOOL create $TESTPOOL1 ${disk}${SLICE_PREFIX}${SLICE3} \
+       spare ${disk}${SLICE_PREFIX}${SLICE1}
+create_pool $TESTPOOL1 ${disk}${SLICE_PREFIX}${SLICE3} \
+       spare ${disk}${SLICE_PREFIX}${SLICE1}
+force_pool=true
+destroy_pool $TESTPOOL1
+
+log_pass "'zpool create' have to use '-f' scenarios"
diff --git a/tests/zfs-tests/tests/functional/cli_root/zpool_create/zpool_create_009_neg.ksh b/tests/zfs-tests/tests/functional/cli_root/zpool_create/zpool_create_009_neg.ksh
new file mode 100755 (executable)
index 0000000..089c475
--- /dev/null
@@ -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."
diff --git a/tests/zfs-tests/tests/functional/cli_root/zpool_create/zpool_create_010_neg.ksh b/tests/zfs-tests/tests/functional/cli_root/zpool_create/zpool_create_010_neg.ksh
new file mode 100755 (executable)
index 0000000..7b555de
--- /dev/null
@@ -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."
diff --git a/tests/zfs-tests/tests/functional/cli_root/zpool_create/zpool_create_011_neg.ksh b/tests/zfs-tests/tests/functional/cli_root/zpool_create/zpool_create_011_neg.ksh
new file mode 100755 (executable)
index 0000000..6d8b26c
--- /dev/null
@@ -0,0 +1,130 @@
+#!/bin/ksh -p
+#
+# CDDL HEADER START
+#
+# The contents of this file are subject to the terms of the
+# Common Development and Distribution License (the "License").
+# You may not use this file except in compliance with the License.
+#
+# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
+# or http://www.opensolaris.org/os/licensing.
+# See the License for the specific language governing permissions
+# and limitations under the License.
+#
+# When distributing Covered Code, include this CDDL HEADER in each
+# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
+# If applicable, add the following below this CDDL 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}${SLICE_PREFIX}${SLICE0}
+pooldev2=${disk}${SLICE_PREFIX}${SLICE1}
+mirror1="${disk}${SLICE_PREFIX}${SLICE1} ${disk}${SLICE_PREFIX}${SLICE3}"
+mirror2="${disk}${SLICE_PREFIX}${SLICE4} ${disk}${SLICE_PREFIX}${SLICE5}"
+raidz1=$mirror1
+raidz2=$mirror2
+diff_size_dev="${disk}${SLICE_PREFIX}${SLICE6} ${disk}${SLICE_PREFIX}${SLICE7}"
+vfstab_dev=$(find_vfstab_dev)
+specified_dump_dev=${disk}${SLICE_PREFIX}${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_DSKDIR}/$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}${SLICE_PREFIX}${SLICE0}
+
+log_pass "'zpool create' is failed as expected with inapplicable scenarios."
diff --git a/tests/zfs-tests/tests/functional/cli_root/zpool_create/zpool_create_012_neg.ksh b/tests/zfs-tests/tests/functional/cli_root/zpool_create/zpool_create_012_neg.ksh
new file mode 100755 (executable)
index 0000000..f3e438f
--- /dev/null
@@ -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."
diff --git a/tests/zfs-tests/tests/functional/cli_root/zpool_create/zpool_create_014_neg.ksh b/tests/zfs-tests/tests/functional/cli_root/zpool_create/zpool_create_014_neg.ksh
new file mode 100755 (executable)
index 0000000..ccc5b09
--- /dev/null
@@ -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}${SLICE_PREFIX}${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 ${ZVOL_DEVDIR}/$vol_name > /dev/null 2>&1
+log_must $MOUNT ${ZVOL_DEVDIR}/$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."
diff --git a/tests/zfs-tests/tests/functional/cli_root/zpool_create/zpool_create_015_neg.ksh b/tests/zfs-tests/tests/functional/cli_root/zpool_create/zpool_create_015_neg.ksh
new file mode 100755 (executable)
index 0000000..c866c4d
--- /dev/null
@@ -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 ${ZVOL_DEVDIR}/$vol_name > /dev/null 2>&1
+               if [[ $? -eq 0 ]]; then
+                       $SWAP -d ${ZVOL_DEVDIR}/${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}${SLICE_PREFIX}${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 ${ZVOl_DEVDIR}/$vol_name
+for opt in "-n" "" "-f"; do
+       log_mustnot $ZPOOL create $opt $TESTPOOL1 ${ZVOL_DEVDIR}/${vol_name}
+done
+
+# cleanup
+log_must $SWAP -d ${ZVOL_DEVDIR}/${vol_name}
+log_must $ZFS destroy $vol_name
+log_must $ZPOOL destroy $TESTPOOL
+
+log_pass "'zpool create' passed as expected with inapplicable scenario."
diff --git a/tests/zfs-tests/tests/functional/cli_root/zpool_create/zpool_create_016_pos.ksh b/tests/zfs-tests/tests/functional/cli_root/zpool_create/zpool_create_016_pos.ksh
new file mode 100755 (executable)
index 0000000..be8fb6f
--- /dev/null
@@ -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}${SLICE_PREFIX}${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."
diff --git a/tests/zfs-tests/tests/functional/cli_root/zpool_create/zpool_create_017_neg.ksh b/tests/zfs-tests/tests/functional/cli_root/zpool_create/zpool_create_017_neg.ksh
new file mode 100755 (executable)
index 0000000..14cbf98
--- /dev/null
@@ -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}${SLICE_PREFIX}${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."
diff --git a/tests/zfs-tests/tests/functional/cli_root/zpool_create/zpool_create_018_pos.ksh b/tests/zfs-tests/tests/functional/cli_root/zpool_create/zpool_create_018_pos.ksh
new file mode 100755 (executable)
index 0000000..a42edff
--- /dev/null
@@ -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 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"
diff --git a/tests/zfs-tests/tests/functional/cli_root/zpool_create/zpool_create_019_pos.ksh b/tests/zfs-tests/tests/functional/cli_root/zpool_create/zpool_create_019_pos.ksh
new file mode 100755 (executable)
index 0000000..277b91e
--- /dev/null
@@ -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
+
+#
+# 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"
diff --git a/tests/zfs-tests/tests/functional/cli_root/zpool_create/zpool_create_020_pos.ksh b/tests/zfs-tests/tests/functional/cli_root/zpool_create/zpool_create_020_pos.ksh
new file mode 100755 (executable)
index 0000000..2ab2f50
--- /dev/null
@@ -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/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"
diff --git a/tests/zfs-tests/tests/functional/cli_root/zpool_create/zpool_create_021_pos.ksh b/tests/zfs-tests/tests/functional/cli_root/zpool_create/zpool_create_021_pos.ksh
new file mode 100755 (executable)
index 0000000..c488441
--- /dev/null
@@ -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 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" \
+                 "acltype=posixacl" \
+                 "aclinherit=discard" \
+                 "canmount=off" \
+                 "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."
+
diff --git a/tests/zfs-tests/tests/functional/cli_root/zpool_create/zpool_create_022_pos.ksh b/tests/zfs-tests/tests/functional/cli_root/zpool_create/zpool_create_022_pos.ksh
new file mode 100755 (executable)
index 0000000..9cc78a1
--- /dev/null
@@ -0,0 +1,94 @@
+#!/bin/ksh -p
+#
+# CDDL HEADER START
+#
+# The contents of this file are subject to the terms of the
+# Common Development and Distribution License (the "License").
+# You may not use this file except in compliance with the License.
+#
+# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
+# or http://www.opensolaris.org/os/licensing.
+# See the License for the specific language governing permissions
+# and limitations under the License.
+#
+# When distributing Covered Code, include this CDDL HEADER in each
+# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
+# If applicable, add the following below this CDDL HEADER, with the
+# fields enclosed by brackets "[]" replaced with your own identifying
+# information: Portions Copyright [yyyy] [name of copyright owner]
+#
+# CDDL HEADER END
+#
+
+#
+# Copyright 2009 Sun Microsystems, Inc.  All rights reserved.
+# Use is subject to license terms.
+#
+
+#
+# Copyright (c) 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" \
+                 "acltype=posixacl" \
+                 "aclinherit=discard" \
+                 "canmount=off"
+
+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."
+
diff --git a/tests/zfs-tests/tests/functional/cli_root/zpool_create/zpool_create_023_neg.ksh b/tests/zfs-tests/tests/functional/cli_root/zpool_create/zpool_create_023_neg.ksh
new file mode 100755 (executable)
index 0000000..3b0f674
--- /dev/null
@@ -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) 2015 by Delphix. All rights reserved.
+#
+
+. $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=2M" "recordsize=2048K" \
+    "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" \
+    "acltype=DIScard" "acltYPE=groupmask" "acltype=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."
+
diff --git a/tests/zfs-tests/tests/functional/cli_root/zpool_create/zpool_create_features_001_pos.ksh b/tests/zfs-tests/tests/functional/cli_root/zpool_create/zpool_create_features_001_pos.ksh
new file mode 100755 (executable)
index 0000000..296a7b4
--- /dev/null
@@ -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"
diff --git a/tests/zfs-tests/tests/functional/cli_root/zpool_create/zpool_create_features_002_pos.ksh b/tests/zfs-tests/tests/functional/cli_root/zpool_create/zpool_create_features_002_pos.ksh
new file mode 100755 (executable)
index 0000000..ce24b38
--- /dev/null
@@ -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
diff --git a/tests/zfs-tests/tests/functional/cli_root/zpool_create/zpool_create_features_003_pos.ksh b/tests/zfs-tests/tests/functional/cli_root/zpool_create/zpool_create_features_003_pos.ksh
new file mode 100755 (executable)
index 0000000..936a1cd
--- /dev/null
@@ -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
diff --git a/tests/zfs-tests/tests/functional/cli_root/zpool_create/zpool_create_features_004_neg.ksh b/tests/zfs-tests/tests/functional/cli_root/zpool_create/zpool_create_features_004_neg.ksh
new file mode 100755 (executable)
index 0000000..2d3ffc8
--- /dev/null
@@ -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 (c) 2012 by Delphix. All rights reserved.
+#
+
+. $STF_SUITE/include/libtest.shlib
+
+################################################################################
+#
+#  Specifying invalid feature names/states should cause the create to fail.
+#
+#  1. Try to create the pool with a variety of invalid feature names/states.
+#  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 feature names/states 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
diff --git a/tests/zfs-tests/tests/functional/cli_root/zpool_destroy/Makefile.am b/tests/zfs-tests/tests/functional/cli_root/zpool_destroy/Makefile.am
new file mode 100644 (file)
index 0000000..5130bcc
--- /dev/null
@@ -0,0 +1,6 @@
+pkgdatadir = $(datadir)/@PACKAGE@/zfs-tests/tests/functional/cli_root/zpool_destroy
+dist_pkgdata_SCRIPTS = \
+       zpool_destroy.cfg \
+       zpool_destroy_001_pos.ksh \
+       zpool_destroy_002_pos.ksh \
+       zpool_destroy_003_neg.ksh
diff --git a/tests/zfs-tests/tests/functional/cli_root/zpool_destroy/zpool_destroy.cfg b/tests/zfs-tests/tests/functional/cli_root/zpool_destroy/zpool_destroy.cfg
new file mode 100644 (file)
index 0000000..63051e2
--- /dev/null
@@ -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 DISK=${DISKS%% *}
+
+if is_linux; then
+       export SLICE_PREFIX="p"
+       export SLICE0=1
+       export SLICE1=2
+else
+       export SLICE_PREFIX="s"
+       export SLICE0=0
+       export SLICE1=1
+
+fi
+export SLICE_SIZE=500m
diff --git a/tests/zfs-tests/tests/functional/cli_root/zpool_destroy/zpool_destroy_001_pos.ksh b/tests/zfs-tests/tests/functional/cli_root/zpool_destroy/zpool_destroy_001_pos.ksh
new file mode 100755 (executable)
index 0000000..d87d7fc
--- /dev/null
@@ -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}${SLICE_PREFIX}${SLICE0}"
+create_pool "$TESTPOOL1" "${DISK}${SLICE_PREFIX}${SLICE1}"
+log_must $ZFS create -s -V $VOLSIZE $TESTPOOL1/$TESTVOL
+create_pool "$TESTPOOL2" "${ZVOL_DEVDIR}/$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"
diff --git a/tests/zfs-tests/tests/functional/cli_root/zpool_destroy/zpool_destroy_002_pos.ksh b/tests/zfs-tests/tests/functional/cli_root/zpool_destroy/zpool_destroy_002_pos.ksh
new file mode 100755 (executable)
index 0000000..682e9c0
--- /dev/null
@@ -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."
diff --git a/tests/zfs-tests/tests/functional/cli_root/zpool_destroy/zpool_destroy_003_neg.ksh b/tests/zfs-tests/tests/functional/cli_root/zpool_destroy/zpool_destroy_003_neg.ksh
new file mode 100755 (executable)
index 0000000..fb104f1
--- /dev/null
@@ -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."
diff --git a/tests/zfs-tests/tests/functional/cli_root/zpool_detach/Makefile.am b/tests/zfs-tests/tests/functional/cli_root/zpool_detach/Makefile.am
new file mode 100644 (file)
index 0000000..b22018c
--- /dev/null
@@ -0,0 +1,5 @@
+pkgdatadir = $(datadir)/@PACKAGE@/zfs-tests/tests/functional/cli_root/zpool_detach
+dist_pkgdata_SCRIPTS = \
+       setup.ksh \
+       cleanup.ksh \
+       zpool_detach_001_neg.ksh
diff --git a/tests/zfs-tests/tests/functional/cli_root/zpool_detach/cleanup.ksh b/tests/zfs-tests/tests/functional/cli_root/zpool_detach/cleanup.ksh
new file mode 100755 (executable)
index 0000000..89c1462
--- /dev/null
@@ -0,0 +1,32 @@
+#!/bin/ksh -p
+#
+# CDDL HEADER START
+#
+# The contents of this file are subject to the terms of the
+# Common Development and Distribution License (the "License").
+# You may not use this file except in compliance with the License.
+#
+# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
+# or http://www.opensolaris.org/os/licensing.
+# See the License for the specific language governing permissions
+# and limitations under the License.
+#
+# When distributing Covered Code, include this CDDL HEADER in each
+# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
+# If applicable, add the following below this CDDL HEADER, with the
+# fields enclosed by brackets "[]" replaced with your own identifying
+# information: 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
diff --git a/tests/zfs-tests/tests/functional/cli_root/zpool_detach/setup.ksh b/tests/zfs-tests/tests/functional/cli_root/zpool_detach/setup.ksh
new file mode 100755 (executable)
index 0000000..2229f87
--- /dev/null
@@ -0,0 +1,35 @@
+#!/bin/ksh -p
+#
+# CDDL HEADER START
+#
+# The contents of this file are subject to the terms of the
+# Common Development and Distribution License (the "License").
+# You may not use this file except in compliance with the License.
+#
+# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
+# or http://www.opensolaris.org/os/licensing.
+# See the License for the specific language governing permissions
+# and limitations under the License.
+#
+# When distributing Covered Code, include this CDDL HEADER in each
+# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
+# If applicable, add the following below this CDDL 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
diff --git a/tests/zfs-tests/tests/functional/cli_root/zpool_detach/zpool_detach_001_neg.ksh b/tests/zfs-tests/tests/functional/cli_root/zpool_detach/zpool_detach_001_neg.ksh
new file mode 100755 (executable)
index 0000000..848ce8c
--- /dev/null
@@ -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."
diff --git a/tests/zfs-tests/tests/functional/cli_root/zpool_expand/Makefile.am b/tests/zfs-tests/tests/functional/cli_root/zpool_expand/Makefile.am
new file mode 100644 (file)
index 0000000..dc90f9f
--- /dev/null
@@ -0,0 +1,8 @@
+pkgdatadir = $(datadir)/@PACKAGE@/zfs-tests/tests/functional/cli_root/zpool_expand
+dist_pkgdata_SCRIPTS = \
+       zpool_expand.cfg \
+       setup.ksh \
+       cleanup.ksh \
+       zpool_expand_001_pos.ksh \
+       zpool_expand_002_pos.ksh \
+       zpool_expand_003_neg.ksh
diff --git a/tests/zfs-tests/tests/functional/cli_root/zpool_expand/cleanup.ksh b/tests/zfs-tests/tests/functional/cli_root/zpool_expand/cleanup.ksh
new file mode 100755 (executable)
index 0000000..d00826b
--- /dev/null
@@ -0,0 +1,32 @@
+#!/bin/ksh -p
+#
+# CDDL HEADER START
+#
+# The contents of this file are subject to the terms of the
+# Common Development and Distribution License (the "License").
+# You may not use this file except in compliance with the License.
+#
+# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
+# or http://www.opensolaris.org/os/licensing.
+# See the License for the specific language governing permissions
+# and limitations under the License.
+#
+# When distributing Covered Code, include this CDDL HEADER in each
+# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
+# If applicable, add the following below this CDDL 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
diff --git a/tests/zfs-tests/tests/functional/cli_root/zpool_expand/setup.ksh b/tests/zfs-tests/tests/functional/cli_root/zpool_expand/setup.ksh
new file mode 100755 (executable)
index 0000000..2069e97
--- /dev/null
@@ -0,0 +1,34 @@
+#!/bin/ksh -p
+#
+# CDDL HEADER START
+#
+# The contents of this file are subject to the terms of the
+# Common Development and Distribution License (the "License").
+# You may not use this file except in compliance with the License.
+#
+# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
+# or http://www.opensolaris.org/os/licensing.
+# See the License for the specific language governing permissions
+# and limitations under the License.
+#
+# When distributing Covered Code, include this CDDL HEADER in each
+# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
+# If applicable, add the following below this CDDL 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
diff --git a/tests/zfs-tests/tests/functional/cli_root/zpool_expand/zpool_expand.cfg b/tests/zfs-tests/tests/functional/cli_root/zpool_expand/zpool_expand.cfg
new file mode 100644 (file)
index 0000000..16df1d9
--- /dev/null
@@ -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
diff --git a/tests/zfs-tests/tests/functional/cli_root/zpool_expand/zpool_expand_001_pos.ksh b/tests/zfs-tests/tests/functional/cli_root/zpool_expand/zpool_expand_001_pos.ksh
new file mode 100755 (executable)
index 0000000..a063b08
--- /dev/null
@@ -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 \
+           ${ZVOL_DEVDIR}/$VFS/vol1  ${ZVOL_DEVDIR}/$VFS/vol2 \
+           ${ZVOL_DEVDIR}/$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"
diff --git a/tests/zfs-tests/tests/functional/cli_root/zpool_expand/zpool_expand_002_pos.ksh b/tests/zfs-tests/tests/functional/cli_root/zpool_expand/zpool_expand_002_pos.ksh
new file mode 100755 (executable)
index 0000000..d7ce33d
--- /dev/null
@@ -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 ${ZVOL_DEVDIR}/$VFS/vol1 \
+           ${ZVOL_DEVDIR}/$VFS/vol2 ${ZVOL_DEVDIR}/$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 ${ZVOL_DEVDIR}/$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"
diff --git a/tests/zfs-tests/tests/functional/cli_root/zpool_expand/zpool_expand_003_neg.ksh b/tests/zfs-tests/tests/functional/cli_root/zpool_expand/zpool_expand_003_neg.ksh
new file mode 100755 (executable)
index 0000000..36e8d49
--- /dev/null
@@ -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 ${ZVOL_DEVDIR}/$VFS/vol1 \
+           ${ZVOL_DEVDIR}/$VFS/vol2 ${ZVOL_DEVDIR}/$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"
diff --git a/tests/zfs-tests/tests/functional/cli_root/zpool_export/Makefile.am b/tests/zfs-tests/tests/functional/cli_root/zpool_export/Makefile.am
new file mode 100644 (file)
index 0000000..a1d97eb
--- /dev/null
@@ -0,0 +1,8 @@
+pkgdatadir = $(datadir)/@PACKAGE@/zfs-tests/tests/functional/cli_root/zpool_export
+dist_pkgdata_SCRIPTS = \
+       setup.ksh \
+       cleanup.ksh \
+       zpool_export_001_pos.ksh \
+       zpool_export_002_pos.ksh \
+       zpool_export_003_neg.ksh \
+       zpool_export_004_pos.ksh
diff --git a/tests/zfs-tests/tests/functional/cli_root/zpool_export/cleanup.ksh b/tests/zfs-tests/tests/functional/cli_root/zpool_export/cleanup.ksh
new file mode 100755 (executable)
index 0000000..79cd6e9
--- /dev/null
@@ -0,0 +1,30 @@
+#!/bin/ksh -p
+#
+# CDDL HEADER START
+#
+# The contents of this file are subject to the terms of the
+# Common Development and Distribution License (the "License").
+# You may not use this file except in compliance with the License.
+#
+# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
+# or http://www.opensolaris.org/os/licensing.
+# See the License for the specific language governing permissions
+# and limitations under the License.
+#
+# When distributing Covered Code, include this CDDL HEADER in each
+# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
+# If applicable, add the following below this CDDL HEADER, with the
+# fields enclosed by brackets "[]" replaced with your own identifying
+# information: 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
diff --git a/tests/zfs-tests/tests/functional/cli_root/zpool_export/setup.ksh b/tests/zfs-tests/tests/functional/cli_root/zpool_export/setup.ksh
new file mode 100755 (executable)
index 0000000..9ce5226
--- /dev/null
@@ -0,0 +1,36 @@
+#!/bin/ksh -p
+#
+# CDDL HEADER START
+#
+# The contents of this file are subject to the terms of the
+# Common Development and Distribution License (the "License").
+# You may not use this file except in compliance with the License.
+#
+# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
+# or http://www.opensolaris.org/os/licensing.
+# See the License for the specific language governing permissions
+# and limitations under the License.
+#
+# When distributing Covered Code, include this CDDL HEADER in each
+# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
+# If applicable, add the following below this CDDL HEADER, with the
+# fields enclosed by brackets "[]" replaced with your own identifying
+# information: 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_physical_device $DISK) ; then
+       log_unsupported "Only partitionable physical disks can be used"
+fi
+
+default_setup $DISK
diff --git a/tests/zfs-tests/tests/functional/cli_root/zpool_export/zpool_export_001_pos.ksh b/tests/zfs-tests/tests/functional/cli_root/zpool_export/zpool_export_001_pos.ksh
new file mode 100755 (executable)
index 0000000..6f404ce
--- /dev/null
@@ -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."
diff --git a/tests/zfs-tests/tests/functional/cli_root/zpool_export/zpool_export_002_pos.ksh b/tests/zfs-tests/tests/functional/cli_root/zpool_export/zpool_export_002_pos.ksh
new file mode 100755 (executable)
index 0000000..ee1895e
--- /dev/null
@@ -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."
diff --git a/tests/zfs-tests/tests/functional/cli_root/zpool_export/zpool_export_003_neg.ksh b/tests/zfs-tests/tests/functional/cli_root/zpool_export/zpool_export_003_neg.ksh
new file mode 100755 (executable)
index 0000000..c3d6c63
--- /dev/null
@@ -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."
diff --git a/tests/zfs-tests/tests/functional/cli_root/zpool_export/zpool_export_004_pos.ksh b/tests/zfs-tests/tests/functional/cli_root/zpool_export/zpool_export_004_pos.ksh
new file mode 100755 (executable)
index 0000000..91f2968
--- /dev/null
@@ -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."
+
diff --git a/tests/zfs-tests/tests/functional/cli_root/zpool_get/Makefile.am b/tests/zfs-tests/tests/functional/cli_root/zpool_get/Makefile.am
new file mode 100644 (file)
index 0000000..bc42ee4
--- /dev/null
@@ -0,0 +1,9 @@
+pkgdatadir = $(datadir)/@PACKAGE@/zfs-tests/tests/functional/cli_root/zpool_get
+dist_pkgdata_SCRIPTS = \
+       zpool_get.cfg \
+       setup.ksh \
+       cleanup.ksh \
+       zpool_get_001_pos.ksh \
+       zpool_get_002_pos.ksh \
+       zpool_get_003_pos.ksh \
+       zpool_get_004_neg.ksh
diff --git a/tests/zfs-tests/tests/functional/cli_root/zpool_get/cleanup.ksh b/tests/zfs-tests/tests/functional/cli_root/zpool_get/cleanup.ksh
new file mode 100755 (executable)
index 0000000..6c992b5
--- /dev/null
@@ -0,0 +1,36 @@
+#!/bin/ksh -p
+#
+# CDDL HEADER START
+#
+# The contents of this file are subject to the terms of the
+# Common Development and Distribution License (the "License").
+# You may not use this file except in compliance with the License.
+#
+# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
+# or http://www.opensolaris.org/os/licensing.
+# See the License for the specific language governing permissions
+# and limitations under the License.
+#
+# When distributing Covered Code, include this CDDL HEADER in each
+# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
+# If applicable, add the following below this CDDL 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
diff --git a/tests/zfs-tests/tests/functional/cli_root/zpool_get/setup.ksh b/tests/zfs-tests/tests/functional/cli_root/zpool_get/setup.ksh
new file mode 100755 (executable)
index 0000000..063ad74
--- /dev/null
@@ -0,0 +1,37 @@
+#!/bin/ksh -p
+#
+# CDDL HEADER START
+#
+# The contents of this file are subject to the terms of the
+# Common Development and Distribution License (the "License").
+# You may not use this file except in compliance with the License.
+#
+# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
+# or http://www.opensolaris.org/os/licensing.
+# See the License for the specific language governing permissions
+# and limitations under the License.
+#
+# When distributing Covered Code, include this CDDL HEADER in each
+# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
+# If applicable, add the following below this CDDL 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
diff --git a/tests/zfs-tests/tests/functional/cli_root/zpool_get/zpool_get.cfg b/tests/zfs-tests/tests/functional/cli_root/zpool_get/zpool_get.cfg
new file mode 100644 (file)
index 0000000..d1d89f1
--- /dev/null
@@ -0,0 +1,49 @@
+#
+# CDDL HEADER START
+#
+# The contents of this file are subject to the terms of the
+# Common Development and Distribution License (the "License").
+# You may not use this file except in compliance with the License.
+#
+# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
+# or http://www.opensolaris.org/os/licensing.
+# See the License for the specific language governing permissions
+# and limitations under the License.
+#
+# When distributing Covered Code, include this CDDL HEADER in each
+# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
+# If applicable, add the following below this CDDL HEADER, with the
+# fields enclosed by brackets "[]" replaced with your own identifying
+# information: Portions Copyright [yyyy] [name of copyright owner]
+#
+# CDDL HEADER END
+#
+
+#
+# Copyright 2009 Sun Microsystems, Inc.  All rights reserved.
+# Use is subject to license terms.
+#
+
+#
+# Copyright (c) 2013 by Delphix. All rights reserved.
+#
+
+# Set the expected properties of zpool
+if is_linux; then
+typeset -a properties=("size" "capacity" "altroot" "health" "guid" "version"
+    "bootfs" "delegation" "autoreplace" "cachefile" "dedupditto" "dedupratio"
+    "free" "allocated" "readonly" "comment" "expandsize" "freeing" "failmode"
+    "listsnapshots" "autoexpand" "fragmentation" "leaked" "ashift"
+    "feature@async_destroy" "feature@empty_bpobj" "feature@lz4_compress"
+    "feature@large_blocks" "feature@filesystem_limits"
+    "feature@spacemap_histogram" "feature@enabled_txg" "feature@hole_birth"
+    "feature@extensible_dataset" "feature@bookmarks" "feature@embedded_data")
+else
+typeset -a properties=("size" "capacity" "altroot" "health" "guid" "version"
+    "bootfs" ""leaked" delegation" "autoreplace" "cachefile" "dedupditto" "dedupratio"
+    "free" "allocated" "readonly" "comment" "expandsize" "freeing" "failmode"
+    "listsnapshots" "autoexpand" "feature@async_destroy" "feature@empty_bpobj"
+    "feature@lz4_compress" "feature@multi_vdev_crash_dump"
+    "feature@spacemap_histogram" "feature@enabled_txg" "feature@hole_birth"
+    "feature@extensible_dataset" "feature@bookmarks")
+fi
diff --git a/tests/zfs-tests/tests/functional/cli_root/zpool_get/zpool_get_001_pos.ksh b/tests/zfs-tests/tests/functional/cli_root/zpool_get/zpool_get_001_pos.ksh
new file mode 100755 (executable)
index 0000000..dbf3042
--- /dev/null
@@ -0,0 +1,57 @@
+#!/bin/ksh -p
+#
+# CDDL HEADER START
+#
+# The contents of this file are subject to the terms of the
+# Common Development and Distribution License (the "License").
+# You may not use this file except in compliance with the License.
+#
+# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
+# or http://www.opensolaris.org/os/licensing.
+# See the License for the specific language governing permissions
+# and limitations under the License.
+#
+# When distributing Covered Code, include this CDDL HEADER in each
+# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
+# If applicable, add the following below this CDDL HEADER, with the
+# fields enclosed by brackets "[]" replaced with your own identifying
+# information: Portions Copyright [yyyy] [name of copyright owner]
+#
+# CDDL HEADER END
+#
+
+#
+# Copyright 2008 Sun Microsystems, Inc.  All rights reserved.
+# Use is subject to license terms.
+#
+
+. $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."
diff --git a/tests/zfs-tests/tests/functional/cli_root/zpool_get/zpool_get_002_pos.ksh b/tests/zfs-tests/tests/functional/cli_root/zpool_get/zpool_get_002_pos.ksh
new file mode 100755 (executable)
index 0000000..346811e
--- /dev/null
@@ -0,0 +1,94 @@
+#!/bin/ksh -p
+#
+# CDDL HEADER START
+#
+# The contents of this file are subject to the terms of the
+# Common Development and Distribution License (the "License").
+# You may not use this file except in compliance with the License.
+#
+# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
+# or http://www.opensolaris.org/os/licensing.
+# See the License for the specific language governing permissions
+# and limitations under the License.
+#
+# When distributing Covered Code, include this CDDL HEADER in each
+# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
+# If applicable, add the following below this CDDL HEADER, with the
+# fields enclosed by brackets "[]" replaced with your own identifying
+# information: Portions Copyright [yyyy] [name of copyright owner]
+#
+# CDDL HEADER END
+#
+
+#
+# Copyright 2008 Sun Microsystems, Inc.  All rights reserved.
+# Use is subject to license terms.
+#
+
+#
+# Copyright (c) 2013 by Delphix. All rights reserved.
+#
+
+. $STF_SUITE/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 "Found zpool features not in the zpool_get test config $i/$COUNT."
+fi
+
+
+
+$RM /tmp/values.$$
+log_pass "Zpool get all works as expected"
diff --git a/tests/zfs-tests/tests/functional/cli_root/zpool_get/zpool_get_003_pos.ksh b/tests/zfs-tests/tests/functional/cli_root/zpool_get/zpool_get_003_pos.ksh
new file mode 100755 (executable)
index 0000000..a816b6b
--- /dev/null
@@ -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 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"
diff --git a/tests/zfs-tests/tests/functional/cli_root/zpool_get/zpool_get_004_neg.ksh b/tests/zfs-tests/tests/functional/cli_root/zpool_get/zpool_get_004_neg.ksh
new file mode 100755 (executable)
index 0000000..c4729d8
--- /dev/null
@@ -0,0 +1,57 @@
+#!/bin/ksh -p
+#
+# CDDL HEADER START
+#
+# The contents of this file are subject to the terms of the
+# Common Development and Distribution License (the "License").
+# You may not use this file except in compliance with the License.
+#
+# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
+# or http://www.opensolaris.org/os/licensing.
+# See the License for the specific language governing permissions
+# and limitations under the License.
+#
+# When distributing Covered Code, include this CDDL HEADER in each
+# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
+# If applicable, add the following below this CDDL HEADER, with the
+# fields enclosed by brackets "[]" replaced with your own identifying
+# information: Portions Copyright [yyyy] [name of copyright owner]
+#
+# CDDL HEADER END
+#
+
+#
+# Copyright 2008 Sun Microsystems, Inc.  All rights reserved.
+# Use is subject to license terms.
+#
+
+. $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"
diff --git a/tests/zfs-tests/tests/functional/cli_root/zpool_history/Makefile.am b/tests/zfs-tests/tests/functional/cli_root/zpool_history/Makefile.am
new file mode 100644 (file)
index 0000000..8755f8f
--- /dev/null
@@ -0,0 +1,6 @@
+pkgdatadir = $(datadir)/@PACKAGE@/zfs-tests/tests/functional/cli_root/zpool_history
+dist_pkgdata_SCRIPTS = \
+       setup.ksh \
+       cleanup.ksh \
+       zpool_history_001_neg.ksh \
+       zpool_history_002_pos.ksh
diff --git a/tests/zfs-tests/tests/functional/cli_root/zpool_history/cleanup.ksh b/tests/zfs-tests/tests/functional/cli_root/zpool_history/cleanup.ksh
new file mode 100755 (executable)
index 0000000..e499813
--- /dev/null
@@ -0,0 +1,34 @@
+#!/bin/ksh -p
+#
+# CDDL HEADER START
+#
+# The contents of this file are subject to the terms of the
+# Common Development and Distribution License (the "License").
+# You may not use this file except in compliance with the License.
+#
+# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
+# or http://www.opensolaris.org/os/licensing.
+# See the License for the specific language governing permissions
+# and limitations under the License.
+#
+# When distributing Covered Code, include this CDDL HEADER in each
+# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
+# If applicable, add the following below this CDDL HEADER, with the
+# fields enclosed by brackets "[]" replaced with your own identifying
+# information: Portions Copyright [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
diff --git a/tests/zfs-tests/tests/functional/cli_root/zpool_history/setup.ksh b/tests/zfs-tests/tests/functional/cli_root/zpool_history/setup.ksh
new file mode 100755 (executable)
index 0000000..b2a852a
--- /dev/null
@@ -0,0 +1,35 @@
+#!/bin/ksh -p
+#
+# CDDL HEADER START
+#
+# The contents of this file are subject to the terms of the
+# Common Development and Distribution License (the "License").
+# You may not use this file except in compliance with the License.
+#
+# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
+# or http://www.opensolaris.org/os/licensing.
+# See the License for the specific language governing permissions
+# and limitations under the License.
+#
+# When distributing Covered Code, include this CDDL HEADER in each
+# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
+# If applicable, add the following below this CDDL HEADER, with the
+# fields enclosed by brackets "[]" replaced with your own identifying
+# information: Portions Copyright [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
diff --git a/tests/zfs-tests/tests/functional/cli_root/zpool_history/zpool_history_001_neg.ksh b/tests/zfs-tests/tests/functional/cli_root/zpool_history/zpool_history_001_neg.ksh
new file mode 100755 (executable)
index 0000000..a722fe7
--- /dev/null
@@ -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."
diff --git a/tests/zfs-tests/tests/functional/cli_root/zpool_history/zpool_history_002_pos.ksh b/tests/zfs-tests/tests/functional/cli_root/zpool_history/zpool_history_002_pos.ksh
new file mode 100755 (executable)
index 0000000..bd5bf19
--- /dev/null
@@ -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."
diff --git a/tests/zfs-tests/tests/functional/cli_root/zpool_import/Makefile.am b/tests/zfs-tests/tests/functional/cli_root/zpool_import/Makefile.am
new file mode 100644 (file)
index 0000000..bdc631a
--- /dev/null
@@ -0,0 +1,32 @@
+pkgdatadir = $(datadir)/@PACKAGE@/zfs-tests/tests/functional/cli_root/zpool_import
+dist_pkgdata_SCRIPTS = \
+       zpool_import.cfg \
+       setup.ksh \
+       cleanup.ksh \
+       zpool_import_001_pos.ksh \
+       zpool_import_002_pos.ksh \
+       zpool_import_003_pos.ksh \
+       zpool_import_004_pos.ksh \
+       zpool_import_005_pos.ksh \
+       zpool_import_006_pos.ksh \
+       zpool_import_007_pos.ksh \
+       zpool_import_008_pos.ksh \
+       zpool_import_009_neg.ksh \
+       zpool_import_010_pos.ksh \
+       zpool_import_011_neg.ksh \
+       zpool_import_012_pos.ksh \
+       zpool_import_013_neg.ksh \
+       zpool_import_all_001_pos.ksh \
+       zpool_import_features_001_pos.ksh \
+       zpool_import_features_002_neg.ksh \
+       zpool_import_features_003_pos.ksh \
+       zpool_import_missing_001_pos.ksh \
+       zpool_import_missing_002_pos.ksh \
+       zpool_import_missing_003_pos.ksh \
+       zpool_import_rename_001_pos.ksh
+
+BLOCKFILES = \
+       unclean_export.dat.bz2
+
+dist_pkgdata_DATA = $(BLOCKFILES)
+EXTRA_DIST = $(BLOCKFILES)
diff --git a/tests/zfs-tests/tests/functional/cli_root/zpool_import/cleanup.ksh b/tests/zfs-tests/tests/functional/cli_root/zpool_import/cleanup.ksh
new file mode 100755 (executable)
index 0000000..03830c4
--- /dev/null
@@ -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 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 $NEWFS_DEFAULT_FS
+(( $? == 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
diff --git a/tests/zfs-tests/tests/functional/cli_root/zpool_import/setup.ksh b/tests/zfs-tests/tests/functional/cli_root/zpool_import/setup.ksh
new file mode 100755 (executable)
index 0000000..f765da0
--- /dev/null
@@ -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_import/zpool_import.cfg
+
+verify_runnable "global"
+verify_disk_count "$DISKS" 2
+
+if ! $(is_physical_device $ZFS_DISK1) ; then
+       log_unsupported "Only partitionable physical disks can be used"
+fi
+
+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 ! is_linux; then
+               if (( i == 2 )); then
+                       (( i = i + 1 ))
+                       continue
+               fi
+       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
+
+log_must set_partition 0 "" $FS_SIZE $ZFS_DISK2
+$ECHO "y" | $NEWFS -v $DEV_RDSKDIR/$ZFSSIDE_DISK2 >/dev/null 2>&1
+(( $? != 0 )) &&
+       log_untested "Unable to setup a $NEWFS_DEFAULT_FS file system"
+
+[[ ! -d $DEVICE_DIR ]] && \
+       log_must $MKDIR -p $DEVICE_DIR
+
+log_must $MOUNT $DEV_DSKDIR/$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
diff --git a/tests/zfs-tests/tests/functional/cli_root/zpool_import/unclean_export.dat.bz2 b/tests/zfs-tests/tests/functional/cli_root/zpool_import/unclean_export.dat.bz2
new file mode 100644 (file)
index 0000000..a7e042b
Binary files /dev/null and b/tests/zfs-tests/tests/functional/cli_root/zpool_import/unclean_export.dat.bz2 differ
diff --git a/tests/zfs-tests/tests/functional/cli_root/zpool_import/zpool_import.cfg b/tests/zfs-tests/tests/functional/cli_root/zpool_import/zpool_import.cfg
new file mode 100644 (file)
index 0000000..5f1638c
--- /dev/null
@@ -0,0 +1,101 @@
+#
+# CDDL HEADER START
+#
+# The contents of this file are subject to the terms of the
+# Common Development and Distribution License (the "License").
+# You may not use this file except in compliance with the License.
+#
+# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
+# or http://www.opensolaris.org/os/licensing.
+# See the License for the specific language governing permissions
+# and limitations under the License.
+#
+# When distributing Covered Code, include this CDDL HEADER in each
+# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
+# If applicable, add the following below this CDDL 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.
+       if is_linux; then
+               DISK_COUNT=1
+               ZFS_DISK1=${disk_array[0]}
+               ZFSSIDE_DISK1=${ZFS_DISK1}p1
+               ZFS_DISK2=${disk_array[0]}
+               ZFSSIDE_DISK2=${ZFS_DISK2}p2
+       else
+               DISK_COUNT=1
+               ZFS_DISK1=${disk_array[0]}
+               ZFSSIDE_DISK1=${ZFS_DISK1}s0
+               ZFS_DISK2=${disk_array[0]}
+               ZFSSIDE_DISK2=${ZFS_DISK2}s1
+       fi
+       ;;
+*)
+       # We need to repartition the single disk to two slices.
+       if is_linux; then
+               DISK_COUNT=2
+               ZFS_DISK1=${disk_array[0]}
+               ZFSSIDE_DISK1=${ZFS_DISK1}p1
+               ZFS_DISK2=${disk_array[1]}
+               ZFSSIDE_DISK2=${ZFS_DISK2}p1
+       else
+               DISK_COUNT=2
+               ZFS_DISK1=${disk_array[0]}
+               ZFSSIDE_DISK1=${ZFS_DISK1}s0
+               ZFS_DISK2=${disk_array[1]}
+               ZFSSIDE_DISK2=${ZFS_DISK2}s0
+       fi
+       ;;
+esac
+
+export DISK_COUNT ZFS_DISK1 ZFSSIDE_DISK1 ZFS_DISK2 ZFSSIDE_DISK2
+
+export FS_SIZE=1g
+export FILE_SIZE=64m
+export SLICE_SIZE=128m
+export MAX_NUM=5
+export GROUP_NUM=3
+export DEVICE_DIR=$TEST_BASE_DIR/dev_import-test
+export BACKUP_DEVICE_DIR=$TEST_BASE_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
diff --git a/tests/zfs-tests/tests/functional/cli_root/zpool_import/zpool_import_001_pos.ksh b/tests/zfs-tests/tests/functional/cli_root/zpool_import/zpool_import_001_pos.ksh
new file mode 100755 (executable)
index 0000000..3562b04
--- /dev/null
@@ -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"
diff --git a/tests/zfs-tests/tests/functional/cli_root/zpool_import/zpool_import_002_pos.ksh b/tests/zfs-tests/tests/functional/cli_root/zpool_import/zpool_import_002_pos.ksh
new file mode 100755 (executable)
index 0000000..73f24a4
--- /dev/null
@@ -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."
diff --git a/tests/zfs-tests/tests/functional/cli_root/zpool_import/zpool_import_003_pos.ksh b/tests/zfs-tests/tests/functional/cli_root/zpool_import/zpool_import_003_pos.ksh
new file mode 100755 (executable)
index 0000000..26ed492
--- /dev/null
@@ -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."
diff --git a/tests/zfs-tests/tests/functional/cli_root/zpool_import/zpool_import_004_pos.ksh b/tests/zfs-tests/tests/functional/cli_root/zpool_import/zpool_import_004_pos.ksh
new file mode 100755 (executable)
index 0000000..f584200
--- /dev/null
@@ -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."
diff --git a/tests/zfs-tests/tests/functional/cli_root/zpool_import/zpool_import_005_pos.ksh b/tests/zfs-tests/tests/functional/cli_root/zpool_import/zpool_import_005_pos.ksh
new file mode 100755 (executable)
index 0000000..12bd14d
--- /dev/null
@@ -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."
diff --git a/tests/zfs-tests/tests/functional/cli_root/zpool_import/zpool_import_006_pos.ksh b/tests/zfs-tests/tests/functional/cli_root/zpool_import/zpool_import_006_pos.ksh
new file mode 100755 (executable)
index 0000000..b35e3cc
--- /dev/null
@@ -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."
diff --git a/tests/zfs-tests/tests/functional/cli_root/zpool_import/zpool_import_007_pos.ksh b/tests/zfs-tests/tests/functional/cli_root/zpool_import/zpool_import_007_pos.ksh
new file mode 100755 (executable)
index 0000000..ec7a867
--- /dev/null
@@ -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."
diff --git a/tests/zfs-tests/tests/functional/cli_root/zpool_import/zpool_import_008_pos.ksh b/tests/zfs-tests/tests/functional/cli_root/zpool_import/zpool_import_008_pos.ksh
new file mode 100755 (executable)
index 0000000..45d76b3
--- /dev/null
@@ -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."
diff --git a/tests/zfs-tests/tests/functional/cli_root/zpool_import/zpool_import_009_neg.ksh b/tests/zfs-tests/tests/functional/cli_root/zpool_import/zpool_import_009_neg.ksh
new file mode 100755 (executable)
index 0000000..a572ba0
--- /dev/null
@@ -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."
diff --git a/tests/zfs-tests/tests/functional/cli_root/zpool_import/zpool_import_010_pos.ksh b/tests/zfs-tests/tests/functional/cli_root/zpool_import/zpool_import_010_pos.ksh
new file mode 100755 (executable)
index 0000000..23d7f91
--- /dev/null
@@ -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."
diff --git a/tests/zfs-tests/tests/functional/cli_root/zpool_import/zpool_import_011_neg.ksh b/tests/zfs-tests/tests/functional/cli_root/zpool_import/zpool_import_011_neg.ksh
new file mode 100755 (executable)
index 0000000..fbc6e6d
--- /dev/null
@@ -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."
diff --git a/tests/zfs-tests/tests/functional/cli_root/zpool_import/zpool_import_012_pos.ksh b/tests/zfs-tests/tests/functional/cli_root/zpool_import/zpool_import_012_pos.ksh
new file mode 100755 (executable)
index 0000000..b4453b8
--- /dev/null
@@ -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]."
diff --git a/tests/zfs-tests/tests/functional/cli_root/zpool_import/zpool_import_013_neg.ksh b/tests/zfs-tests/tests/functional/cli_root/zpool_import/zpool_import_013_neg.ksh
new file mode 100755 (executable)
index 0000000..f81738c
--- /dev/null
@@ -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/$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"
diff --git a/tests/zfs-tests/tests/functional/cli_root/zpool_import/zpool_import_all_001_pos.ksh b/tests/zfs-tests/tests/functional/cli_root/zpool_import/zpool_import_all_001_pos.ksh
new file mode 100755 (executable)
index 0000000..6b83935
--- /dev/null
@@ -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_DSKDIR} -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."
diff --git a/tests/zfs-tests/tests/functional/cli_root/zpool_import/zpool_import_features_001_pos.ksh b/tests/zfs-tests/tests/functional/cli_root/zpool_import/zpool_import_features_001_pos.ksh
new file mode 100755 (executable)
index 0000000..ea71acf
--- /dev/null
@@ -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
diff --git a/tests/zfs-tests/tests/functional/cli_root/zpool_import/zpool_import_features_002_neg.ksh b/tests/zfs-tests/tests/functional/cli_root/zpool_import/zpool_import_features_002_neg.ksh
new file mode 100755 (executable)
index 0000000..26b99f0
--- /dev/null
@@ -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
diff --git a/tests/zfs-tests/tests/functional/cli_root/zpool_import/zpool_import_features_003_pos.ksh b/tests/zfs-tests/tests/functional/cli_root/zpool_import/zpool_import_features_003_pos.ksh
new file mode 100755 (executable)
index 0000000..3f0ea63
--- /dev/null
@@ -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
diff --git a/tests/zfs-tests/tests/functional/cli_root/zpool_import/zpool_import_missing_001_pos.ksh b/tests/zfs-tests/tests/functional/cli_root/zpool_import/zpool_import_missing_001_pos.ksh
new file mode 100755 (executable)
index 0000000..d044759
--- /dev/null
@@ -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."
diff --git a/tests/zfs-tests/tests/functional/cli_root/zpool_import/zpool_import_missing_002_pos.ksh b/tests/zfs-tests/tests/functional/cli_root/zpool_import/zpool_import_missing_002_pos.ksh
new file mode 100755 (executable)
index 0000000..36fbe44
--- /dev/null
@@ -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."
diff --git a/tests/zfs-tests/tests/functional/cli_root/zpool_import/zpool_import_missing_003_pos.ksh b/tests/zfs-tests/tests/functional/cli_root/zpool_import/zpool_import_missing_003_pos.ksh
new file mode 100755 (executable)
index 0000000..7f2d4f4
--- /dev/null
@@ -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."
diff --git a/tests/zfs-tests/tests/functional/cli_root/zpool_import/zpool_import_rename_001_pos.ksh b/tests/zfs-tests/tests/functional/cli_root/zpool_import/zpool_import_rename_001_pos.ksh
new file mode 100755 (executable)
index 0000000..60ccc0d
--- /dev/null
@@ -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"
diff --git a/tests/zfs-tests/tests/functional/cli_root/zpool_offline/Makefile.am b/tests/zfs-tests/tests/functional/cli_root/zpool_offline/Makefile.am
new file mode 100644 (file)
index 0000000..6bb5fbf
--- /dev/null
@@ -0,0 +1,6 @@
+pkgdatadir = $(datadir)/@PACKAGE@/zfs-tests/tests/functional/cli_root/zpool_offline
+dist_pkgdata_SCRIPTS = \
+       setup.ksh \
+       cleanup.ksh \
+       zpool_offline_001_pos.ksh \
+       zpool_offline_002_neg.ksh
diff --git a/tests/zfs-tests/tests/functional/cli_root/zpool_offline/cleanup.ksh b/tests/zfs-tests/tests/functional/cli_root/zpool_offline/cleanup.ksh
new file mode 100755 (executable)
index 0000000..89c1462
--- /dev/null
@@ -0,0 +1,32 @@
+#!/bin/ksh -p
+#
+# CDDL HEADER START
+#
+# The contents of this file are subject to the terms of the
+# Common Development and Distribution License (the "License").
+# You may not use this file except in compliance with the License.
+#
+# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
+# or http://www.opensolaris.org/os/licensing.
+# See the License for the specific language governing permissions
+# and limitations under the License.
+#
+# When distributing Covered Code, include this CDDL HEADER in each
+# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
+# If applicable, add the following below this CDDL HEADER, with the
+# fields enclosed by brackets "[]" replaced with your own identifying
+# information: 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
diff --git a/tests/zfs-tests/tests/functional/cli_root/zpool_offline/setup.ksh b/tests/zfs-tests/tests/functional/cli_root/zpool_offline/setup.ksh
new file mode 100755 (executable)
index 0000000..2229f87
--- /dev/null
@@ -0,0 +1,35 @@
+#!/bin/ksh -p
+#
+# CDDL HEADER START
+#
+# The contents of this file are subject to the terms of the
+# Common Development and Distribution License (the "License").
+# You may not use this file except in compliance with the License.
+#
+# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
+# or http://www.opensolaris.org/os/licensing.
+# See the License for the specific language governing permissions
+# and limitations under the License.
+#
+# When distributing Covered Code, include this CDDL HEADER in each
+# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
+# If applicable, add the following below this CDDL 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
diff --git a/tests/zfs-tests/tests/functional/cli_root/zpool_offline/zpool_offline_001_pos.ksh b/tests/zfs-tests/tests/functional/cli_root/zpool_offline/zpool_offline_001_pos.ksh
new file mode 100755 (executable)
index 0000000..ddd6574
--- /dev/null
@@ -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"
diff --git a/tests/zfs-tests/tests/functional/cli_root/zpool_offline/zpool_offline_002_neg.ksh b/tests/zfs-tests/tests/functional/cli_root/zpool_offline/zpool_offline_002_neg.ksh
new file mode 100755 (executable)
index 0000000..9834d07
--- /dev/null
@@ -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."
diff --git a/tests/zfs-tests/tests/functional/cli_root/zpool_online/Makefile.am b/tests/zfs-tests/tests/functional/cli_root/zpool_online/Makefile.am
new file mode 100644 (file)
index 0000000..12681e3
--- /dev/null
@@ -0,0 +1,6 @@
+pkgdatadir = $(datadir)/@PACKAGE@/zfs-tests/tests/functional/cli_root/zpool_online
+dist_pkgdata_SCRIPTS = \
+       setup.ksh \
+       cleanup.ksh \
+       zpool_online_001_pos.ksh \
+       zpool_online_002_neg.ksh
diff --git a/tests/zfs-tests/tests/functional/cli_root/zpool_online/cleanup.ksh b/tests/zfs-tests/tests/functional/cli_root/zpool_online/cleanup.ksh
new file mode 100755 (executable)
index 0000000..89c1462
--- /dev/null
@@ -0,0 +1,32 @@
+#!/bin/ksh -p
+#
+# CDDL HEADER START
+#
+# The contents of this file are subject to the terms of the
+# Common Development and Distribution License (the "License").
+# You may not use this file except in compliance with the License.
+#
+# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
+# or http://www.opensolaris.org/os/licensing.
+# See the License for the specific language governing permissions
+# and limitations under the License.
+#
+# When distributing Covered Code, include this CDDL HEADER in each
+# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
+# If applicable, add the following below this CDDL HEADER, with the
+# fields enclosed by brackets "[]" replaced with your own identifying
+# information: 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
diff --git a/tests/zfs-tests/tests/functional/cli_root/zpool_online/setup.ksh b/tests/zfs-tests/tests/functional/cli_root/zpool_online/setup.ksh
new file mode 100755 (executable)
index 0000000..2229f87
--- /dev/null
@@ -0,0 +1,35 @@
+#!/bin/ksh -p
+#
+# CDDL HEADER START
+#
+# The contents of this file are subject to the terms of the
+# Common Development and Distribution License (the "License").
+# You may not use this file except in compliance with the License.
+#
+# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
+# or http://www.opensolaris.org/os/licensing.
+# See the License for the specific language governing permissions
+# and limitations under the License.
+#
+# When distributing Covered Code, include this CDDL HEADER in each
+# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
+# If applicable, add the following below this CDDL 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
diff --git a/tests/zfs-tests/tests/functional/cli_root/zpool_online/zpool_online_001_pos.ksh b/tests/zfs-tests/tests/functional/cli_root/zpool_online/zpool_online_001_pos.ksh
new file mode 100755 (executable)
index 0000000..f1ed6a0
--- /dev/null
@@ -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"
diff --git a/tests/zfs-tests/tests/functional/cli_root/zpool_online/zpool_online_002_neg.ksh b/tests/zfs-tests/tests/functional/cli_root/zpool_online/zpool_online_002_neg.ksh
new file mode 100755 (executable)
index 0000000..307d196
--- /dev/null
@@ -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."
diff --git a/tests/zfs-tests/tests/functional/cli_root/zpool_remove/Makefile.am b/tests/zfs-tests/tests/functional/cli_root/zpool_remove/Makefile.am
new file mode 100644 (file)
index 0000000..9890265
--- /dev/null
@@ -0,0 +1,8 @@
+pkgdatadir = $(datadir)/@PACKAGE@/zfs-tests/tests/functional/cli_root/zpool_remove
+dist_pkgdata_SCRIPTS = \
+       zpool_remove.cfg \
+       setup.ksh \
+       cleanup.ksh \
+       zpool_remove_001_neg.ksh \
+       zpool_remove_002_pos.ksh \
+       zpool_remove_003_pos.ksh
diff --git a/tests/zfs-tests/tests/functional/cli_root/zpool_remove/cleanup.ksh b/tests/zfs-tests/tests/functional/cli_root/zpool_remove/cleanup.ksh
new file mode 100755 (executable)
index 0000000..4cc6b3b
--- /dev/null
@@ -0,0 +1,32 @@
+#!/bin/ksh -p
+#
+# CDDL HEADER START
+#
+# The contents of this file are subject to the terms of the
+# Common Development and Distribution License (the "License").
+# You may not use this file except in compliance with the License.
+#
+# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
+# or http://www.opensolaris.org/os/licensing.
+# See the License for the specific language governing permissions
+# and limitations under the License.
+#
+# When distributing Covered Code, include this CDDL HEADER in each
+# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
+# If applicable, add the following below this CDDL HEADER, with the
+# fields enclosed by brackets "[]" replaced with your own identifying
+# information: 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
diff --git a/tests/zfs-tests/tests/functional/cli_root/zpool_remove/setup.ksh b/tests/zfs-tests/tests/functional/cli_root/zpool_remove/setup.ksh
new file mode 100755 (executable)
index 0000000..f3e3606
--- /dev/null
@@ -0,0 +1,43 @@
+#!/bin/ksh -p
+#
+# CDDL HEADER START
+#
+# The contents of this file are subject to the terms of the
+# Common Development and Distribution License (the "License").
+# You may not use this file except in compliance with the License.
+#
+# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
+# or http://www.opensolaris.org/os/licensing.
+# See the License for the specific language governing permissions
+# and limitations under the License.
+#
+# When distributing Covered Code, include this CDDL HEADER in each
+# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
+# If applicable, add the following below this CDDL 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
diff --git a/tests/zfs-tests/tests/functional/cli_root/zpool_remove/zpool_remove.cfg b/tests/zfs-tests/tests/functional/cli_root/zpool_remove/zpool_remove.cfg
new file mode 100644 (file)
index 0000000..c611efd
--- /dev/null
@@ -0,0 +1,54 @@
+#
+# CDDL HEADER START
+#
+# The contents of this file are subject to the terms of the
+# Common Development and Distribution License (the "License").
+# You may not use this file except in compliance with the License.
+#
+# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
+# or http://www.opensolaris.org/os/licensing.
+# See the License for the specific language governing permissions
+# and limitations under the License.
+#
+# When distributing Covered Code, include this CDDL HEADER in each
+# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
+# If applicable, add the following below this CDDL HEADER, with the
+# fields enclosed by brackets "[]" replaced with your own identifying
+# information: Portions Copyright [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"
+
+if is_linux; then
+       export SLICE_PREFIX="p"
+       export SLICE0=1
+       export SLICE1=2
+       export SLICE2=3
+       export SLICE3=4
+       export SLICE4=5
+       export SLICE5=6
+       export SLICE6=7
+       export SLICE7=8
+else
+       export SLICE_PREFIX="s"
+       export SLICE0=0
+       export SLICE1=1
+       export SLICE2=2
+       export SLICE3=3
+       export SLICE4=4
+       export SLICE5=5
+       export SLICE6=6
+       export SLICE7=7
+fi
diff --git a/tests/zfs-tests/tests/functional/cli_root/zpool_remove/zpool_remove_001_neg.ksh b/tests/zfs-tests/tests/functional/cli_root/zpool_remove/zpool_remove_001_neg.ksh
new file mode 100755 (executable)
index 0000000..495d803
--- /dev/null
@@ -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_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}${SLICE_PREFIX}${SLICE0}"
+typeset mirror_devs="${disk}${SLICE_PREFIX}${SLICE0} ${disk}${SLICE_PREFIX}${SLICE1}"
+typeset raidz_devs=${mirror_devs}
+typeset raidz1_devs=${mirror_devs}
+typeset raidz2_devs="${mirror_devs} ${disk}${SLICE_PREFIX}${SLICE3}"
+typeset spare_devs1="${disk}${SLICE_PREFIX}${SLICE0}"
+typeset spare_devs2="${disk}${SLICE_PREFIX}${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 .'"
diff --git a/tests/zfs-tests/tests/functional/cli_root/zpool_remove/zpool_remove_002_pos.ksh b/tests/zfs-tests/tests/functional/cli_root/zpool_remove/zpool_remove_002_pos.ksh
new file mode 100755 (executable)
index 0000000..c4ef652
--- /dev/null
@@ -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/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}${SLICE_PREFIX}${SLICE0}"
+typeset spare_devs2="${disk}${SLICE_PREFIX}${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"
diff --git a/tests/zfs-tests/tests/functional/cli_root/zpool_remove/zpool_remove_003_pos.ksh b/tests/zfs-tests/tests/functional/cli_root/zpool_remove/zpool_remove_003_pos.ksh
new file mode 100755 (executable)
index 0000000..cb2d56e
--- /dev/null
@@ -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
+. $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}${SLICE_PREFIX}${SLICE0}"
+typeset spare_devs2="${disk}${SLICE_PREFIX}${SLICE1}"
+typeset spare_devs3="${disk}${SLICE_PREFIX}${SLICE3}"
+typeset spare_devs4="${disk}${SLICE_PREFIX}${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.'"
diff --git a/tests/zfs-tests/tests/functional/cli_root/zpool_replace/Makefile.am b/tests/zfs-tests/tests/functional/cli_root/zpool_replace/Makefile.am
new file mode 100644 (file)
index 0000000..ce1b630
--- /dev/null
@@ -0,0 +1,5 @@
+pkgdatadir = $(datadir)/@PACKAGE@/zfs-tests/tests/functional/cli_root/zpool_replace
+dist_pkgdata_SCRIPTS = \
+       setup.ksh \
+       cleanup.ksh \
+       zpool_replace_001_neg.ksh
diff --git a/tests/zfs-tests/tests/functional/cli_root/zpool_replace/cleanup.ksh b/tests/zfs-tests/tests/functional/cli_root/zpool_replace/cleanup.ksh
new file mode 100755 (executable)
index 0000000..89c1462
--- /dev/null
@@ -0,0 +1,32 @@
+#!/bin/ksh -p
+#
+# CDDL HEADER START
+#
+# The contents of this file are subject to the terms of the
+# Common Development and Distribution License (the "License").
+# You may not use this file except in compliance with the License.
+#
+# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
+# or http://www.opensolaris.org/os/licensing.
+# See the License for the specific language governing permissions
+# and limitations under the License.
+#
+# When distributing Covered Code, include this CDDL HEADER in each
+# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
+# If applicable, add the following below this CDDL HEADER, with the
+# fields enclosed by brackets "[]" replaced with your own identifying
+# information: 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
diff --git a/tests/zfs-tests/tests/functional/cli_root/zpool_replace/setup.ksh b/tests/zfs-tests/tests/functional/cli_root/zpool_replace/setup.ksh
new file mode 100755 (executable)
index 0000000..2229f87
--- /dev/null
@@ -0,0 +1,35 @@
+#!/bin/ksh -p
+#
+# CDDL HEADER START
+#
+# The contents of this file are subject to the terms of the
+# Common Development and Distribution License (the "License").
+# You may not use this file except in compliance with the License.
+#
+# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
+# or http://www.opensolaris.org/os/licensing.
+# See the License for the specific language governing permissions
+# and limitations under the License.
+#
+# When distributing Covered Code, include this CDDL HEADER in each
+# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
+# If applicable, add the following below this CDDL 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
diff --git a/tests/zfs-tests/tests/functional/cli_root/zpool_replace/zpool_replace_001_neg.ksh b/tests/zfs-tests/tests/functional/cli_root/zpool_replace/zpool_replace_001_neg.ksh
new file mode 100755 (executable)
index 0000000..8533877
--- /dev/null
@@ -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."
diff --git a/tests/zfs-tests/tests/functional/cli_root/zpool_scrub/Makefile.am b/tests/zfs-tests/tests/functional/cli_root/zpool_scrub/Makefile.am
new file mode 100644 (file)
index 0000000..ee6a839
--- /dev/null
@@ -0,0 +1,10 @@
+pkgdatadir = $(datadir)/@PACKAGE@/zfs-tests/tests/functional/cli_root/zpool_scrub
+dist_pkgdata_SCRIPTS = \
+       zpool_scrub.cfg \
+       setup.ksh \
+       cleanup.ksh \
+       zpool_scrub_001_neg.ksh \
+       zpool_scrub_002_pos.ksh \
+       zpool_scrub_003_pos.ksh \
+       zpool_scrub_004_pos.ksh \
+       zpool_scrub_005_pos.ksh
diff --git a/tests/zfs-tests/tests/functional/cli_root/zpool_scrub/cleanup.ksh b/tests/zfs-tests/tests/functional/cli_root/zpool_scrub/cleanup.ksh
new file mode 100755 (executable)
index 0000000..74396de
--- /dev/null
@@ -0,0 +1,32 @@
+#!/bin/ksh -p
+#
+# CDDL HEADER START
+#
+# The contents of this file are subject to the terms of the
+# Common Development and Distribution License (the "License").
+# You may not use this file except in compliance with the License.
+#
+# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
+# or http://www.opensolaris.org/os/licensing.
+# See the License for the specific language governing permissions
+# and limitations under the License.
+#
+# When distributing Covered Code, include this CDDL HEADER in each
+# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
+# If applicable, add the following below this CDDL HEADER, with the
+# fields enclosed by brackets "[]" replaced with your own identifying
+# information: 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
diff --git a/tests/zfs-tests/tests/functional/cli_root/zpool_scrub/setup.ksh b/tests/zfs-tests/tests/functional/cli_root/zpool_scrub/setup.ksh
new file mode 100755 (executable)
index 0000000..af078e2
--- /dev/null
@@ -0,0 +1,47 @@
+#!/bin/ksh -p
+#
+# CDDL HEADER START
+#
+# The contents of this file are subject to the terms of the
+# Common Development and Distribution License (the "License").
+# You may not use this file except in compliance with the License.
+#
+# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
+# or http://www.opensolaris.org/os/licensing.
+# See the License for the specific language governing permissions
+# and limitations under the License.
+#
+# When distributing Covered Code, include this CDDL HEADER in each
+# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
+# If applicable, add the following below this CDDL 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 $DD if=/dev/urandom of=$mntpnt/bigfile.$i bs=1024k count=100
+       ((i += 1))
+done
+
+log_pass
diff --git a/tests/zfs-tests/tests/functional/cli_root/zpool_scrub/zpool_scrub.cfg b/tests/zfs-tests/tests/functional/cli_root/zpool_scrub/zpool_scrub.cfg
new file mode 100644 (file)
index 0000000..36b4c0e
--- /dev/null
@@ -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}')
diff --git a/tests/zfs-tests/tests/functional/cli_root/zpool_scrub/zpool_scrub_001_neg.ksh b/tests/zfs-tests/tests/functional/cli_root/zpool_scrub/zpool_scrub_001_neg.ksh
new file mode 100755 (executable)
index 0000000..c3214c1
--- /dev/null
@@ -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."
diff --git a/tests/zfs-tests/tests/functional/cli_root/zpool_scrub/zpool_scrub_002_pos.ksh b/tests/zfs-tests/tests/functional/cli_root/zpool_scrub/zpool_scrub_002_pos.ksh
new file mode 100755 (executable)
index 0000000..000b4f0
--- /dev/null
@@ -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."
diff --git a/tests/zfs-tests/tests/functional/cli_root/zpool_scrub/zpool_scrub_003_pos.ksh b/tests/zfs-tests/tests/functional/cli_root/zpool_scrub/zpool_scrub_003_pos.ksh
new file mode 100755 (executable)
index 0000000..4f5019d
--- /dev/null
@@ -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."
diff --git a/tests/zfs-tests/tests/functional/cli_root/zpool_scrub/zpool_scrub_004_pos.ksh b/tests/zfs-tests/tests/functional/cli_root/zpool_scrub/zpool_scrub_004_pos.ksh
new file mode 100755 (executable)
index 0000000..f457646
--- /dev/null
@@ -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"
diff --git a/tests/zfs-tests/tests/functional/cli_root/zpool_scrub/zpool_scrub_005_pos.ksh b/tests/zfs-tests/tests/functional/cli_root/zpool_scrub/zpool_scrub_005_pos.ksh
new file mode 100755 (executable)
index 0000000..39e43fd
--- /dev/null
@@ -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."
diff --git a/tests/zfs-tests/tests/functional/cli_root/zpool_set/Makefile.am b/tests/zfs-tests/tests/functional/cli_root/zpool_set/Makefile.am
new file mode 100644 (file)
index 0000000..185d4b1
--- /dev/null
@@ -0,0 +1,5 @@
+pkgdatadir = $(datadir)/@PACKAGE@/zfs-tests/tests/functional/cli_root/zpool_set
+dist_pkgdata_SCRIPTS = \
+       zpool_set_001_pos.ksh \
+       zpool_set_002_neg.ksh \
+       zpool_set_003_neg.ksh
diff --git a/tests/zfs-tests/tests/functional/cli_root/zpool_set/zpool_set_001_pos.ksh b/tests/zfs-tests/tests/functional/cli_root/zpool_set/zpool_set_001_pos.ksh
new file mode 100755 (executable)
index 0000000..570e1ba
--- /dev/null
@@ -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:
+#
+# 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"
diff --git a/tests/zfs-tests/tests/functional/cli_root/zpool_set/zpool_set_002_neg.ksh b/tests/zfs-tests/tests/functional/cli_root/zpool_set/zpool_set_002_neg.ksh
new file mode 100755 (executable)
index 0000000..4f8e548
--- /dev/null
@@ -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
+
+#
+# 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"
diff --git a/tests/zfs-tests/tests/functional/cli_root/zpool_set/zpool_set_003_neg.ksh b/tests/zfs-tests/tests/functional/cli_root/zpool_set/zpool_set_003_neg.ksh
new file mode 100755 (executable)
index 0000000..614939b
--- /dev/null
@@ -0,0 +1,72 @@
+#!/bin/ksh -p
+#
+# CDDL HEADER START
+#
+# The contents of this file are subject to the terms of the
+# Common Development and Distribution License (the "License").
+# You may not use this file except in compliance with the License.
+#
+# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
+# or http://www.opensolaris.org/os/licensing.
+# See the License for the specific language governing permissions
+# and limitations under the License.
+#
+# When distributing Covered Code, include this CDDL HEADER in each
+# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
+# If applicable, add the following below this CDDL HEADER, with the
+# fields enclosed by brackets "[]" replaced with your own identifying
+# information: Portions Copyright [yyyy] [name of copyright owner]
+#
+# CDDL HEADER END
+#
+
+#
+# Copyright 2007 Sun Microsystems, Inc.  All rights reserved.
+# Use is subject to license terms.
+#
+
+#
+# Copyright (c) 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"
+
diff --git a/tests/zfs-tests/tests/functional/cli_root/zpool_status/Makefile.am b/tests/zfs-tests/tests/functional/cli_root/zpool_status/Makefile.am
new file mode 100644 (file)
index 0000000..beb59e3
--- /dev/null
@@ -0,0 +1,6 @@
+pkgdatadir = $(datadir)/@PACKAGE@/zfs-tests/tests/functional/cli_root/zpool_status
+dist_pkgdata_SCRIPTS = \
+       setup.ksh \
+       cleanup.ksh \
+       zpool_status_001_pos.ksh \
+       zpool_status_002_pos.ksh
diff --git a/tests/zfs-tests/tests/functional/cli_root/zpool_status/cleanup.ksh b/tests/zfs-tests/tests/functional/cli_root/zpool_status/cleanup.ksh
new file mode 100755 (executable)
index 0000000..79cd6e9
--- /dev/null
@@ -0,0 +1,30 @@
+#!/bin/ksh -p
+#
+# CDDL HEADER START
+#
+# The contents of this file are subject to the terms of the
+# Common Development and Distribution License (the "License").
+# You may not use this file except in compliance with the License.
+#
+# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
+# or http://www.opensolaris.org/os/licensing.
+# See the License for the specific language governing permissions
+# and limitations under the License.
+#
+# When distributing Covered Code, include this CDDL HEADER in each
+# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
+# If applicable, add the following below this CDDL HEADER, with the
+# fields enclosed by brackets "[]" replaced with your own identifying
+# information: 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
diff --git a/tests/zfs-tests/tests/functional/cli_root/zpool_status/setup.ksh b/tests/zfs-tests/tests/functional/cli_root/zpool_status/setup.ksh
new file mode 100755 (executable)
index 0000000..6a9af3b
--- /dev/null
@@ -0,0 +1,32 @@
+#!/bin/ksh -p
+#
+# CDDL HEADER START
+#
+# The contents of this file are subject to the terms of the
+# Common Development and Distribution License (the "License").
+# You may not use this file except in compliance with the License.
+#
+# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
+# or http://www.opensolaris.org/os/licensing.
+# See the License for the specific language governing permissions
+# and limitations under the License.
+#
+# When distributing Covered Code, include this CDDL HEADER in each
+# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
+# If applicable, add the following below this CDDL HEADER, with the
+# fields enclosed by brackets "[]" replaced with your own identifying
+# information: 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
diff --git a/tests/zfs-tests/tests/functional/cli_root/zpool_status/zpool_status_001_pos.ksh b/tests/zfs-tests/tests/functional/cli_root/zpool_status/zpool_status_001_pos.ksh
new file mode 100755 (executable)
index 0000000..d582e55
--- /dev/null
@@ -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."
diff --git a/tests/zfs-tests/tests/functional/cli_root/zpool_status/zpool_status_002_pos.ksh b/tests/zfs-tests/tests/functional/cli_root/zpool_status/zpool_status_002_pos.ksh
new file mode 100755 (executable)
index 0000000..5ae84a8
--- /dev/null
@@ -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"
diff --git a/tests/zfs-tests/tests/functional/cli_root/zpool_upgrade/Makefile.am b/tests/zfs-tests/tests/functional/cli_root/zpool_upgrade/Makefile.am
new file mode 100644 (file)
index 0000000..71cdb29
--- /dev/null
@@ -0,0 +1,72 @@
+pkgdatadir = $(datadir)/@PACKAGE@/zfs-tests/tests/functional/cli_root/zpool_upgrade
+dist_pkgdata_SCRIPTS = \
+       zpool_upgrade.cfg \
+       zpool_upgrade.kshlib \
+       setup.ksh \
+       cleanup.ksh \
+       zpool_upgrade_001_pos.ksh \
+       zpool_upgrade_002_pos.ksh \
+       zpool_upgrade_003_pos.ksh \
+       zpool_upgrade_004_pos.ksh \
+       zpool_upgrade_005_neg.ksh \
+       zpool_upgrade_006_neg.ksh \
+       zpool_upgrade_007_pos.ksh \
+       zpool_upgrade_008_pos.ksh \
+       zpool_upgrade_009_neg.ksh
+
+BLOCKFILES = \
+       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
+
+dist_pkgdata_DATA = $(BLOCKFILES)
+EXTRA_DIST = $(BLOCKFILES)
diff --git a/tests/zfs-tests/tests/functional/cli_root/zpool_upgrade/cleanup.ksh b/tests/zfs-tests/tests/functional/cli_root/zpool_upgrade/cleanup.ksh
new file mode 100755 (executable)
index 0000000..1fab530
--- /dev/null
@@ -0,0 +1,39 @@
+#!/bin/ksh -p
+#
+# CDDL HEADER START
+#
+# The contents of this file are subject to the terms of the
+# Common Development and Distribution License (the "License").
+# You may not use this file except in compliance with the License.
+#
+# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
+# or http://www.opensolaris.org/os/licensing.
+# See the License for the specific language governing permissions
+# and limitations under the License.
+#
+# When distributing Covered Code, include this CDDL HEADER in each
+# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
+# If applicable, add the following below this CDDL HEADER, with the
+# fields enclosed by brackets "[]" replaced with your own identifying
+# information: Portions Copyright [yyyy] [name of copyright owner]
+#
+# CDDL HEADER END
+#
+
+#
+# Copyright 2007 Sun Microsystems, Inc.  All rights reserved.
+# Use is subject to license terms.
+#
+
+#
+# Copyright (c) 2012 by Delphix. All rights reserved.
+# Copyright 2015 Nexenta Systems, Inc.  All rights reserved.
+#
+
+. $STF_SUITE/tests/functional/cli_root/zpool_upgrade/zpool_upgrade.kshlib
+
+for config in $CONFIGS; do
+       destroy_upgraded_pool $config
+done
+
+default_cleanup
diff --git a/tests/zfs-tests/tests/functional/cli_root/zpool_upgrade/setup.ksh b/tests/zfs-tests/tests/functional/cli_root/zpool_upgrade/setup.ksh
new file mode 100755 (executable)
index 0000000..1b75c94
--- /dev/null
@@ -0,0 +1,38 @@
+#!/bin/ksh -p
+#
+# CDDL HEADER START
+#
+# The contents of this file are subject to the terms of the
+# Common Development and Distribution License (the "License").
+# You may not use this file except in compliance with the License.
+#
+# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
+# or http://www.opensolaris.org/os/licensing.
+# See the License for the specific language governing permissions
+# and limitations under the License.
+#
+# When distributing Covered Code, include this CDDL HEADER in each
+# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
+# If applicable, add the following below this CDDL 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
diff --git a/tests/zfs-tests/tests/functional/cli_root/zpool_upgrade/zfs-broken-mirror1.dat.bz2 b/tests/zfs-tests/tests/functional/cli_root/zpool_upgrade/zfs-broken-mirror1.dat.bz2
new file mode 100644 (file)
index 0000000..7ec82b7
Binary files /dev/null and b/tests/zfs-tests/tests/functional/cli_root/zpool_upgrade/zfs-broken-mirror1.dat.bz2 differ
diff --git a/tests/zfs-tests/tests/functional/cli_root/zpool_upgrade/zfs-broken-mirror2.dat.bz2 b/tests/zfs-tests/tests/functional/cli_root/zpool_upgrade/zfs-broken-mirror2.dat.bz2
new file mode 100644 (file)
index 0000000..00ef2bc
Binary files /dev/null and b/tests/zfs-tests/tests/functional/cli_root/zpool_upgrade/zfs-broken-mirror2.dat.bz2 differ
diff --git a/tests/zfs-tests/tests/functional/cli_root/zpool_upgrade/zfs-pool-v1.dat.bz2 b/tests/zfs-tests/tests/functional/cli_root/zpool_upgrade/zfs-pool-v1.dat.bz2
new file mode 100644 (file)
index 0000000..9c8a157
Binary files /dev/null and b/tests/zfs-tests/tests/functional/cli_root/zpool_upgrade/zfs-pool-v1.dat.bz2 differ
diff --git a/tests/zfs-tests/tests/functional/cli_root/zpool_upgrade/zfs-pool-v10.dat.bz2 b/tests/zfs-tests/tests/functional/cli_root/zpool_upgrade/zfs-pool-v10.dat.bz2
new file mode 100644 (file)
index 0000000..5caf41c
Binary files /dev/null and b/tests/zfs-tests/tests/functional/cli_root/zpool_upgrade/zfs-pool-v10.dat.bz2 differ
diff --git a/tests/zfs-tests/tests/functional/cli_root/zpool_upgrade/zfs-pool-v11.dat.bz2 b/tests/zfs-tests/tests/functional/cli_root/zpool_upgrade/zfs-pool-v11.dat.bz2
new file mode 100644 (file)
index 0000000..4af228e
Binary files /dev/null and b/tests/zfs-tests/tests/functional/cli_root/zpool_upgrade/zfs-pool-v11.dat.bz2 differ
diff --git a/tests/zfs-tests/tests/functional/cli_root/zpool_upgrade/zfs-pool-v12.dat.bz2 b/tests/zfs-tests/tests/functional/cli_root/zpool_upgrade/zfs-pool-v12.dat.bz2
new file mode 100644 (file)
index 0000000..a116e9d
Binary files /dev/null and b/tests/zfs-tests/tests/functional/cli_root/zpool_upgrade/zfs-pool-v12.dat.bz2 differ
diff --git a/tests/zfs-tests/tests/functional/cli_root/zpool_upgrade/zfs-pool-v13.dat.bz2 b/tests/zfs-tests/tests/functional/cli_root/zpool_upgrade/zfs-pool-v13.dat.bz2
new file mode 100644 (file)
index 0000000..3fab226
Binary files /dev/null and b/tests/zfs-tests/tests/functional/cli_root/zpool_upgrade/zfs-pool-v13.dat.bz2 differ
diff --git a/tests/zfs-tests/tests/functional/cli_root/zpool_upgrade/zfs-pool-v14.dat.bz2 b/tests/zfs-tests/tests/functional/cli_root/zpool_upgrade/zfs-pool-v14.dat.bz2
new file mode 100644 (file)
index 0000000..e8443c3
Binary files /dev/null and b/tests/zfs-tests/tests/functional/cli_root/zpool_upgrade/zfs-pool-v14.dat.bz2 differ
diff --git a/tests/zfs-tests/tests/functional/cli_root/zpool_upgrade/zfs-pool-v15.dat.bz2 b/tests/zfs-tests/tests/functional/cli_root/zpool_upgrade/zfs-pool-v15.dat.bz2
new file mode 100644 (file)
index 0000000..0887ae8
Binary files /dev/null and b/tests/zfs-tests/tests/functional/cli_root/zpool_upgrade/zfs-pool-v15.dat.bz2 differ
diff --git a/tests/zfs-tests/tests/functional/cli_root/zpool_upgrade/zfs-pool-v1mirror1.dat.bz2 b/tests/zfs-tests/tests/functional/cli_root/zpool_upgrade/zfs-pool-v1mirror1.dat.bz2
new file mode 100644 (file)
index 0000000..ed42283
Binary files /dev/null and b/tests/zfs-tests/tests/functional/cli_root/zpool_upgrade/zfs-pool-v1mirror1.dat.bz2 differ
diff --git a/tests/zfs-tests/tests/functional/cli_root/zpool_upgrade/zfs-pool-v1mirror2.dat.bz2 b/tests/zfs-tests/tests/functional/cli_root/zpool_upgrade/zfs-pool-v1mirror2.dat.bz2
new file mode 100644 (file)
index 0000000..4e72f1a
Binary files /dev/null and b/tests/zfs-tests/tests/functional/cli_root/zpool_upgrade/zfs-pool-v1mirror2.dat.bz2 differ
diff --git a/tests/zfs-tests/tests/functional/cli_root/zpool_upgrade/zfs-pool-v1mirror3.dat.bz2 b/tests/zfs-tests/tests/functional/cli_root/zpool_upgrade/zfs-pool-v1mirror3.dat.bz2
new file mode 100644 (file)
index 0000000..006c96d
Binary files /dev/null and b/tests/zfs-tests/tests/functional/cli_root/zpool_upgrade/zfs-pool-v1mirror3.dat.bz2 differ
diff --git a/tests/zfs-tests/tests/functional/cli_root/zpool_upgrade/zfs-pool-v1raidz1.dat.bz2 b/tests/zfs-tests/tests/functional/cli_root/zpool_upgrade/zfs-pool-v1raidz1.dat.bz2
new file mode 100644 (file)
index 0000000..3c3531c
Binary files /dev/null and b/tests/zfs-tests/tests/functional/cli_root/zpool_upgrade/zfs-pool-v1raidz1.dat.bz2 differ
diff --git a/tests/zfs-tests/tests/functional/cli_root/zpool_upgrade/zfs-pool-v1raidz2.dat.bz2 b/tests/zfs-tests/tests/functional/cli_root/zpool_upgrade/zfs-pool-v1raidz2.dat.bz2
new file mode 100644 (file)
index 0000000..99a0768
Binary files /dev/null and b/tests/zfs-tests/tests/functional/cli_root/zpool_upgrade/zfs-pool-v1raidz2.dat.bz2 differ
diff --git a/tests/zfs-tests/tests/functional/cli_root/zpool_upgrade/zfs-pool-v1raidz3.dat.bz2 b/tests/zfs-tests/tests/functional/cli_root/zpool_upgrade/zfs-pool-v1raidz3.dat.bz2
new file mode 100644 (file)
index 0000000..0fd057e
Binary files /dev/null and b/tests/zfs-tests/tests/functional/cli_root/zpool_upgrade/zfs-pool-v1raidz3.dat.bz2 differ
diff --git a/tests/zfs-tests/tests/functional/cli_root/zpool_upgrade/zfs-pool-v1stripe1.dat.bz2 b/tests/zfs-tests/tests/functional/cli_root/zpool_upgrade/zfs-pool-v1stripe1.dat.bz2
new file mode 100644 (file)
index 0000000..41f63f6
Binary files /dev/null and b/tests/zfs-tests/tests/functional/cli_root/zpool_upgrade/zfs-pool-v1stripe1.dat.bz2 differ
diff --git a/tests/zfs-tests/tests/functional/cli_root/zpool_upgrade/zfs-pool-v1stripe2.dat.bz2 b/tests/zfs-tests/tests/functional/cli_root/zpool_upgrade/zfs-pool-v1stripe2.dat.bz2
new file mode 100644 (file)
index 0000000..cc9eab1
Binary files /dev/null and b/tests/zfs-tests/tests/functional/cli_root/zpool_upgrade/zfs-pool-v1stripe2.dat.bz2 differ
diff --git a/tests/zfs-tests/tests/functional/cli_root/zpool_upgrade/zfs-pool-v1stripe3.dat.bz2 b/tests/zfs-tests/tests/functional/cli_root/zpool_upgrade/zfs-pool-v1stripe3.dat.bz2
new file mode 100644 (file)
index 0000000..866bd96
Binary files /dev/null and b/tests/zfs-tests/tests/functional/cli_root/zpool_upgrade/zfs-pool-v1stripe3.dat.bz2 differ
diff --git a/tests/zfs-tests/tests/functional/cli_root/zpool_upgrade/zfs-pool-v2.dat.bz2 b/tests/zfs-tests/tests/functional/cli_root/zpool_upgrade/zfs-pool-v2.dat.bz2
new file mode 100644 (file)
index 0000000..184e3c3
Binary files /dev/null and b/tests/zfs-tests/tests/functional/cli_root/zpool_upgrade/zfs-pool-v2.dat.bz2 differ
diff --git a/tests/zfs-tests/tests/functional/cli_root/zpool_upgrade/zfs-pool-v2mirror1.dat.bz2 b/tests/zfs-tests/tests/functional/cli_root/zpool_upgrade/zfs-pool-v2mirror1.dat.bz2
new file mode 100644 (file)
index 0000000..7466e7e
Binary files /dev/null and b/tests/zfs-tests/tests/functional/cli_root/zpool_upgrade/zfs-pool-v2mirror1.dat.bz2 differ
diff --git a/tests/zfs-tests/tests/functional/cli_root/zpool_upgrade/zfs-pool-v2mirror2.dat.bz2 b/tests/zfs-tests/tests/functional/cli_root/zpool_upgrade/zfs-pool-v2mirror2.dat.bz2
new file mode 100644 (file)
index 0000000..de66b53
Binary files /dev/null and b/tests/zfs-tests/tests/functional/cli_root/zpool_upgrade/zfs-pool-v2mirror2.dat.bz2 differ
diff --git a/tests/zfs-tests/tests/functional/cli_root/zpool_upgrade/zfs-pool-v2mirror3.dat.bz2 b/tests/zfs-tests/tests/functional/cli_root/zpool_upgrade/zfs-pool-v2mirror3.dat.bz2
new file mode 100644 (file)
index 0000000..4c3504b
Binary files /dev/null and b/tests/zfs-tests/tests/functional/cli_root/zpool_upgrade/zfs-pool-v2mirror3.dat.bz2 differ
diff --git a/tests/zfs-tests/tests/functional/cli_root/zpool_upgrade/zfs-pool-v2raidz1.dat.bz2 b/tests/zfs-tests/tests/functional/cli_root/zpool_upgrade/zfs-pool-v2raidz1.dat.bz2
new file mode 100644 (file)
index 0000000..e008ae0
Binary files /dev/null and b/tests/zfs-tests/tests/functional/cli_root/zpool_upgrade/zfs-pool-v2raidz1.dat.bz2 differ
diff --git a/tests/zfs-tests/tests/functional/cli_root/zpool_upgrade/zfs-pool-v2raidz2.dat.bz2 b/tests/zfs-tests/tests/functional/cli_root/zpool_upgrade/zfs-pool-v2raidz2.dat.bz2
new file mode 100644 (file)
index 0000000..bf7f6b1
Binary files /dev/null and b/tests/zfs-tests/tests/functional/cli_root/zpool_upgrade/zfs-pool-v2raidz2.dat.bz2 differ
diff --git a/tests/zfs-tests/tests/functional/cli_root/zpool_upgrade/zfs-pool-v2raidz3.dat.bz2 b/tests/zfs-tests/tests/functional/cli_root/zpool_upgrade/zfs-pool-v2raidz3.dat.bz2
new file mode 100644 (file)
index 0000000..f7b7012
Binary files /dev/null and b/tests/zfs-tests/tests/functional/cli_root/zpool_upgrade/zfs-pool-v2raidz3.dat.bz2 differ
diff --git a/tests/zfs-tests/tests/functional/cli_root/zpool_upgrade/zfs-pool-v2stripe1.dat.bz2 b/tests/zfs-tests/tests/functional/cli_root/zpool_upgrade/zfs-pool-v2stripe1.dat.bz2
new file mode 100644 (file)
index 0000000..16a7bb8
Binary files /dev/null and b/tests/zfs-tests/tests/functional/cli_root/zpool_upgrade/zfs-pool-v2stripe1.dat.bz2 differ
diff --git a/tests/zfs-tests/tests/functional/cli_root/zpool_upgrade/zfs-pool-v2stripe2.dat.bz2 b/tests/zfs-tests/tests/functional/cli_root/zpool_upgrade/zfs-pool-v2stripe2.dat.bz2
new file mode 100644 (file)
index 0000000..8f7287e
Binary files /dev/null and b/tests/zfs-tests/tests/functional/cli_root/zpool_upgrade/zfs-pool-v2stripe2.dat.bz2 differ
diff --git a/tests/zfs-tests/tests/functional/cli_root/zpool_upgrade/zfs-pool-v2stripe3.dat.bz2 b/tests/zfs-tests/tests/functional/cli_root/zpool_upgrade/zfs-pool-v2stripe3.dat.bz2
new file mode 100644 (file)
index 0000000..9fccd05
Binary files /dev/null and b/tests/zfs-tests/tests/functional/cli_root/zpool_upgrade/zfs-pool-v2stripe3.dat.bz2 differ
diff --git a/tests/zfs-tests/tests/functional/cli_root/zpool_upgrade/zfs-pool-v3.dat.bz2 b/tests/zfs-tests/tests/functional/cli_root/zpool_upgrade/zfs-pool-v3.dat.bz2
new file mode 100644 (file)
index 0000000..fc122d8
Binary files /dev/null and b/tests/zfs-tests/tests/functional/cli_root/zpool_upgrade/zfs-pool-v3.dat.bz2 differ
diff --git a/tests/zfs-tests/tests/functional/cli_root/zpool_upgrade/zfs-pool-v3hotspare1.dat.bz2 b/tests/zfs-tests/tests/functional/cli_root/zpool_upgrade/zfs-pool-v3hotspare1.dat.bz2
new file mode 100644 (file)
index 0000000..d5c7e3c
Binary files /dev/null and b/tests/zfs-tests/tests/functional/cli_root/zpool_upgrade/zfs-pool-v3hotspare1.dat.bz2 differ
diff --git a/tests/zfs-tests/tests/functional/cli_root/zpool_upgrade/zfs-pool-v3hotspare2.dat.bz2 b/tests/zfs-tests/tests/functional/cli_root/zpool_upgrade/zfs-pool-v3hotspare2.dat.bz2
new file mode 100644 (file)
index 0000000..47b4d6a
Binary files /dev/null and b/tests/zfs-tests/tests/functional/cli_root/zpool_upgrade/zfs-pool-v3hotspare2.dat.bz2 differ
diff --git a/tests/zfs-tests/tests/functional/cli_root/zpool_upgrade/zfs-pool-v3hotspare3.dat.bz2 b/tests/zfs-tests/tests/functional/cli_root/zpool_upgrade/zfs-pool-v3hotspare3.dat.bz2
new file mode 100644 (file)
index 0000000..cb253c3
Binary files /dev/null and b/tests/zfs-tests/tests/functional/cli_root/zpool_upgrade/zfs-pool-v3hotspare3.dat.bz2 differ
diff --git a/tests/zfs-tests/tests/functional/cli_root/zpool_upgrade/zfs-pool-v3mirror1.dat.bz2 b/tests/zfs-tests/tests/functional/cli_root/zpool_upgrade/zfs-pool-v3mirror1.dat.bz2
new file mode 100644 (file)
index 0000000..e8ab50c
Binary files /dev/null and b/tests/zfs-tests/tests/functional/cli_root/zpool_upgrade/zfs-pool-v3mirror1.dat.bz2 differ
diff --git a/tests/zfs-tests/tests/functional/cli_root/zpool_upgrade/zfs-pool-v3mirror2.dat.bz2 b/tests/zfs-tests/tests/functional/cli_root/zpool_upgrade/zfs-pool-v3mirror2.dat.bz2
new file mode 100644 (file)
index 0000000..769e0f8
Binary files /dev/null and b/tests/zfs-tests/tests/functional/cli_root/zpool_upgrade/zfs-pool-v3mirror2.dat.bz2 differ
diff --git a/tests/zfs-tests/tests/functional/cli_root/zpool_upgrade/zfs-pool-v3mirror3.dat.bz2 b/tests/zfs-tests/tests/functional/cli_root/zpool_upgrade/zfs-pool-v3mirror3.dat.bz2
new file mode 100644 (file)
index 0000000..e7e5a89
Binary files /dev/null and b/tests/zfs-tests/tests/functional/cli_root/zpool_upgrade/zfs-pool-v3mirror3.dat.bz2 differ
diff --git a/tests/zfs-tests/tests/functional/cli_root/zpool_upgrade/zfs-pool-v3raidz1.dat.bz2 b/tests/zfs-tests/tests/functional/cli_root/zpool_upgrade/zfs-pool-v3raidz1.dat.bz2
new file mode 100644 (file)
index 0000000..6d43f74
Binary files /dev/null and b/tests/zfs-tests/tests/functional/cli_root/zpool_upgrade/zfs-pool-v3raidz1.dat.bz2 differ
diff --git a/tests/zfs-tests/tests/functional/cli_root/zpool_upgrade/zfs-pool-v3raidz2.dat.bz2 b/tests/zfs-tests/tests/functional/cli_root/zpool_upgrade/zfs-pool-v3raidz2.dat.bz2
new file mode 100644 (file)
index 0000000..6ab1059
Binary files /dev/null and b/tests/zfs-tests/tests/functional/cli_root/zpool_upgrade/zfs-pool-v3raidz2.dat.bz2 differ
diff --git a/tests/zfs-tests/tests/functional/cli_root/zpool_upgrade/zfs-pool-v3raidz21.dat.bz2 b/tests/zfs-tests/tests/functional/cli_root/zpool_upgrade/zfs-pool-v3raidz21.dat.bz2
new file mode 100644 (file)
index 0000000..dcc537f
Binary files /dev/null and b/tests/zfs-tests/tests/functional/cli_root/zpool_upgrade/zfs-pool-v3raidz21.dat.bz2 differ
diff --git a/tests/zfs-tests/tests/functional/cli_root/zpool_upgrade/zfs-pool-v3raidz22.dat.bz2 b/tests/zfs-tests/tests/functional/cli_root/zpool_upgrade/zfs-pool-v3raidz22.dat.bz2
new file mode 100644 (file)
index 0000000..3cd92b1
Binary files /dev/null and b/tests/zfs-tests/tests/functional/cli_root/zpool_upgrade/zfs-pool-v3raidz22.dat.bz2 differ
diff --git a/tests/zfs-tests/tests/functional/cli_root/zpool_upgrade/zfs-pool-v3raidz23.dat.bz2 b/tests/zfs-tests/tests/functional/cli_root/zpool_upgrade/zfs-pool-v3raidz23.dat.bz2
new file mode 100644 (file)
index 0000000..e3c5f41
Binary files /dev/null and b/tests/zfs-tests/tests/functional/cli_root/zpool_upgrade/zfs-pool-v3raidz23.dat.bz2 differ
diff --git a/tests/zfs-tests/tests/functional/cli_root/zpool_upgrade/zfs-pool-v3raidz3.dat.bz2 b/tests/zfs-tests/tests/functional/cli_root/zpool_upgrade/zfs-pool-v3raidz3.dat.bz2
new file mode 100644 (file)
index 0000000..2109fda
Binary files /dev/null and b/tests/zfs-tests/tests/functional/cli_root/zpool_upgrade/zfs-pool-v3raidz3.dat.bz2 differ
diff --git a/tests/zfs-tests/tests/functional/cli_root/zpool_upgrade/zfs-pool-v3stripe1.dat.bz2 b/tests/zfs-tests/tests/functional/cli_root/zpool_upgrade/zfs-pool-v3stripe1.dat.bz2
new file mode 100644 (file)
index 0000000..4e6afe2
Binary files /dev/null and b/tests/zfs-tests/tests/functional/cli_root/zpool_upgrade/zfs-pool-v3stripe1.dat.bz2 differ
diff --git a/tests/zfs-tests/tests/functional/cli_root/zpool_upgrade/zfs-pool-v3stripe2.dat.bz2 b/tests/zfs-tests/tests/functional/cli_root/zpool_upgrade/zfs-pool-v3stripe2.dat.bz2
new file mode 100644 (file)
index 0000000..6e755dd
Binary files /dev/null and b/tests/zfs-tests/tests/functional/cli_root/zpool_upgrade/zfs-pool-v3stripe2.dat.bz2 differ
diff --git a/tests/zfs-tests/tests/functional/cli_root/zpool_upgrade/zfs-pool-v3stripe3.dat.bz2 b/tests/zfs-tests/tests/functional/cli_root/zpool_upgrade/zfs-pool-v3stripe3.dat.bz2
new file mode 100644 (file)
index 0000000..9cf396a
Binary files /dev/null and b/tests/zfs-tests/tests/functional/cli_root/zpool_upgrade/zfs-pool-v3stripe3.dat.bz2 differ
diff --git a/tests/zfs-tests/tests/functional/cli_root/zpool_upgrade/zfs-pool-v4.dat.bz2 b/tests/zfs-tests/tests/functional/cli_root/zpool_upgrade/zfs-pool-v4.dat.bz2
new file mode 100644 (file)
index 0000000..b1c00e1
Binary files /dev/null and b/tests/zfs-tests/tests/functional/cli_root/zpool_upgrade/zfs-pool-v4.dat.bz2 differ
diff --git a/tests/zfs-tests/tests/functional/cli_root/zpool_upgrade/zfs-pool-v5.dat.bz2 b/tests/zfs-tests/tests/functional/cli_root/zpool_upgrade/zfs-pool-v5.dat.bz2
new file mode 100644 (file)
index 0000000..9c6cb0c
Binary files /dev/null and b/tests/zfs-tests/tests/functional/cli_root/zpool_upgrade/zfs-pool-v5.dat.bz2 differ
diff --git a/tests/zfs-tests/tests/functional/cli_root/zpool_upgrade/zfs-pool-v6.dat.bz2 b/tests/zfs-tests/tests/functional/cli_root/zpool_upgrade/zfs-pool-v6.dat.bz2
new file mode 100644 (file)
index 0000000..1eb1fea
Binary files /dev/null and b/tests/zfs-tests/tests/functional/cli_root/zpool_upgrade/zfs-pool-v6.dat.bz2 differ
diff --git a/tests/zfs-tests/tests/functional/cli_root/zpool_upgrade/zfs-pool-v7.dat.bz2 b/tests/zfs-tests/tests/functional/cli_root/zpool_upgrade/zfs-pool-v7.dat.bz2
new file mode 100644 (file)
index 0000000..04c6cac
Binary files /dev/null and b/tests/zfs-tests/tests/functional/cli_root/zpool_upgrade/zfs-pool-v7.dat.bz2 differ
diff --git a/tests/zfs-tests/tests/functional/cli_root/zpool_upgrade/zfs-pool-v8.dat.bz2 b/tests/zfs-tests/tests/functional/cli_root/zpool_upgrade/zfs-pool-v8.dat.bz2
new file mode 100644 (file)
index 0000000..8f1e663
Binary files /dev/null and b/tests/zfs-tests/tests/functional/cli_root/zpool_upgrade/zfs-pool-v8.dat.bz2 differ
diff --git a/tests/zfs-tests/tests/functional/cli_root/zpool_upgrade/zfs-pool-v9.dat.bz2 b/tests/zfs-tests/tests/functional/cli_root/zpool_upgrade/zfs-pool-v9.dat.bz2
new file mode 100644 (file)
index 0000000..94528d3
Binary files /dev/null and b/tests/zfs-tests/tests/functional/cli_root/zpool_upgrade/zfs-pool-v9.dat.bz2 differ
diff --git a/tests/zfs-tests/tests/functional/cli_root/zpool_upgrade/zfs-pool-v999.dat.bz2 b/tests/zfs-tests/tests/functional/cli_root/zpool_upgrade/zfs-pool-v999.dat.bz2
new file mode 100644 (file)
index 0000000..7ca57a2
Binary files /dev/null and b/tests/zfs-tests/tests/functional/cli_root/zpool_upgrade/zfs-pool-v999.dat.bz2 differ
diff --git a/tests/zfs-tests/tests/functional/cli_root/zpool_upgrade/zfs-pool-vBROKEN.dat.bz2 b/tests/zfs-tests/tests/functional/cli_root/zpool_upgrade/zfs-pool-vBROKEN.dat.bz2
new file mode 100644 (file)
index 0000000..6595f4a
Binary files /dev/null and b/tests/zfs-tests/tests/functional/cli_root/zpool_upgrade/zfs-pool-vBROKEN.dat.bz2 differ
diff --git a/tests/zfs-tests/tests/functional/cli_root/zpool_upgrade/zpool_upgrade.cfg b/tests/zfs-tests/tests/functional/cli_root/zpool_upgrade/zpool_upgrade.cfg
new file mode 100644 (file)
index 0000000..993fafc
--- /dev/null
@@ -0,0 +1,161 @@
+#
+# CDDL HEADER START
+#
+# The contents of this file are subject to the terms of the
+# Common Development and Distribution License (the "License").
+# You may not use this file except in compliance with the License.
+#
+# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
+# or http://www.opensolaris.org/os/licensing.
+# See the License for the specific language governing permissions
+# and limitations under the License.
+#
+# When distributing Covered Code, include this CDDL HEADER in each
+# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
+# If applicable, add the following below this CDDL 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.
+# Copyright 2015 Nexenta Systems, Inc.  All rights reserved.
+#
+
+# 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.
+
+# v1 pools
+ZPOOL_VERSION_1_FILES="zfs-pool-v1.dat"
+ZPOOL_VERSION_1_NAME="v1-pool"
+# v1 stripe
+ZPOOL_VERSION_1stripe_FILES="zfs-pool-v1stripe1.dat \
+zfs-pool-v1stripe2.dat  zfs-pool-v1stripe3.dat"
+ZPOOL_VERSION_1stripe_NAME="pool-v1stripe"
+# v1 raidz
+ZPOOL_VERSION_1raidz_FILES="zfs-pool-v1raidz1.dat zfs-pool-v1raidz2.dat \
+zfs-pool-v1raidz3.dat"
+ZPOOL_VERSION_1raidz_NAME="pool-v1raidz"
+# v1 mirror
+ZPOOL_VERSION_1mirror_FILES="zfs-pool-v1mirror1.dat zfs-pool-v1mirror2.dat \
+zfs-pool-v1mirror3.dat"
+ZPOOL_VERSION_1mirror_NAME="pool-v1mirror"
+
+# v2 pools
+ZPOOL_VERSION_2_FILES="zfs-pool-v2.dat"
+ZPOOL_VERSION_2_NAME="v2-pool"
+# v2 stripe
+ZPOOL_VERSION_2stripe_FILES="zfs-pool-v2stripe1.dat zfs-pool-v2stripe2.dat \
+zfs-pool-v2stripe3.dat"
+ZPOOL_VERSION_2stripe_NAME="pool-v2stripe"
+# v2 raidz
+ZPOOL_VERSION_2raidz_FILES="zfs-pool-v2raidz1.dat zfs-pool-v2raidz2.dat \
+zfs-pool-v2raidz3.dat"
+ZPOOL_VERSION_2raidz_NAME="pool-v2raidz"
+# v2 mirror
+ZPOOL_VERSION_2mirror_FILES="zfs-pool-v2mirror1.dat zfs-pool-v2mirror2.dat \
+zfs-pool-v2mirror3.dat"
+ZPOOL_VERSION_2mirror_NAME="pool-v2mirror"
+
+# v3 pools
+ZPOOL_VERSION_3_FILES="zfs-pool-v3.dat"
+ZPOOL_VERSION_3_NAME="v3-pool"
+# v3 stripe
+ZPOOL_VERSION_3stripe_FILES="zfs-pool-v3stripe1.dat zfs-pool-v3stripe2.dat \
+zfs-pool-v3stripe3.dat"
+ZPOOL_VERSION_3stripe_NAME="pool-v3stripe"
+# v3 raidz
+ZPOOL_VERSION_3raidz_FILES="zfs-pool-v3raidz1.dat zfs-pool-v3raidz2.dat \
+zfs-pool-v3raidz3.dat"
+ZPOOL_VERSION_3raidz_NAME="pool-v3raidz"
+# v3 mirror
+ZPOOL_VERSION_3mirror_FILES="zfs-pool-v3mirror1.dat zfs-pool-v3mirror2.dat \
+zfs-pool-v3mirror3.dat"
+ZPOOL_VERSION_3mirror_NAME="pool-v3mirror"
+# v3 raidz2
+ZPOOL_VERSION_3dblraidz_FILES="zfs-pool-v3raidz21.dat zfs-pool-v3raidz22.dat \
+zfs-pool-v3raidz23.dat"
+ZPOOL_VERSION_3dblraidz_NAME="pool-v3raidz2"
+# v3 hotspares
+ZPOOL_VERSION_3hotspare_FILES="zfs-pool-v3hotspare1.dat \
+zfs-pool-v3hotspare2.dat zfs-pool-v3hotspare3.dat"
+ZPOOL_VERSION_3hotspare_NAME="pool-v3hotspare"
+
+# v4 pool
+ZPOOL_VERSION_4_FILES="zfs-pool-v4.dat"
+ZPOOL_VERSION_4_NAME="v4-pool"
+
+# v5 pool
+ZPOOL_VERSION_5_FILES="zfs-pool-v5.dat"
+ZPOOL_VERSION_5_NAME="v5-pool"
+
+# v6 pool
+ZPOOL_VERSION_6_FILES="zfs-pool-v6.dat"
+ZPOOL_VERSION_6_NAME="v6-pool"
+
+# v7 pool
+ZPOOL_VERSION_7_FILES="zfs-pool-v7.dat"
+ZPOOL_VERSION_7_NAME="v7-pool"
+
+# v8 pool
+ZPOOL_VERSION_8_FILES="zfs-pool-v8.dat"
+ZPOOL_VERSION_8_NAME="v8-pool"
+
+# v9 pool
+ZPOOL_VERSION_9_FILES="zfs-pool-v9.dat"
+ZPOOL_VERSION_9_NAME="v9-pool"
+
+# v10 pool
+ZPOOL_VERSION_10_FILES="zfs-pool-v10.dat"
+ZPOOL_VERSION_10_NAME="v10-pool"
+
+# v11 pool
+ZPOOL_VERSION_11_FILES="zfs-pool-v11.dat"
+ZPOOL_VERSION_11_NAME="v11-pool"
+
+# v12 pool
+ZPOOL_VERSION_12_FILES="zfs-pool-v12.dat"
+ZPOOL_VERSION_12_NAME="v12-pool"
+
+# v13 pool
+ZPOOL_VERSION_13_FILES="zfs-pool-v13.dat"
+ZPOOL_VERSION_13_NAME="v13-pool"
+
+# v14 pool
+ZPOOL_VERSION_14_FILES="zfs-pool-v14.dat"
+ZPOOL_VERSION_14_NAME="v14-pool"
+
+# v15 pool
+ZPOOL_VERSION_15_FILES="zfs-pool-v15.dat"
+ZPOOL_VERSION_15_NAME="v15-pool"
+
+# v2 pool, with device problems on one side of the mirror
+# so that the pool appears as DEGRADED
+ZPOOL_VERSION_2brokenmirror_FILES="zfs-broken-mirror1.dat \
+zfs-broken-mirror2.dat"
+ZPOOL_VERSION_2brokenmirror_NAME="zfs-broken-mirror"
+
+# v999 pool (an unknown version) which can be used to check whether upgrade,
+# import or other tests that should fail against unknown pool version.
+# It should not be listed in the CONFIGS variable below, as these are pool
+# versions that can be imported and upgraded.
+ZPOOL_VERSION_9999_FILES="zfs-pool-v999.dat"
+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.
+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"
diff --git a/tests/zfs-tests/tests/functional/cli_root/zpool_upgrade/zpool_upgrade.kshlib b/tests/zfs-tests/tests/functional/cli_root/zpool_upgrade/zpool_upgrade.kshlib
new file mode 100644 (file)
index 0000000..d2d0eaf
--- /dev/null
@@ -0,0 +1,160 @@
+#
+# CDDL HEADER START
+#
+# The contents of this file are subject to the terms of the
+# Common Development and Distribution License (the "License").
+# You may not use this file except in compliance with the License.
+#
+# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
+# or http://www.opensolaris.org/os/licensing.
+# See the License for the specific language governing permissions
+# and limitations under the License.
+#
+# When distributing Covered Code, include this CDDL HEADER in each
+# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
+# If applicable, add the following below this CDDL HEADER, with the
+# fields enclosed by brackets "[]" replaced with your own identifying
+# information: Portions Copyright [yyyy] [name of copyright owner]
+#
+# CDDL HEADER END
+#
+
+#
+# Copyright 2008 Sun Microsystems, Inc.  All rights reserved.
+# Use is subject to license terms.
+#
+
+#
+# Copyright (c) 2012 by Delphix. All rights reserved.
+# Copyright 2015 Nexenta Systems, Inc.  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
+{
+       typeset vers=$1
+       typeset -n pool_files=ZPOOL_VERSION_${vers}_FILES
+       typeset -n pool_name=ZPOOL_VERSION_${vers}_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/$pool_file.bz2 \
+                   >/$TESTPOOL/$pool_file
+       done
+       log_must $ZPOOL import -d /$TESTPOOL $pool_name
+
+       # Put some random contents into the pool
+       for i in {1..1024} ; do
+               $DD if=/dev/urandom of=/$pool_name/random.$i \
+                   count=1 bs=1024 > /dev/null 2>&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
+{
+       typeset vers=$1
+       typeset -n pool_files=ZPOOL_VERSION_${vers}_FILES
+       typeset -n pool_name=ZPOOL_VERSION_${vers}_NAME
+       typeset pre_upgrade_checksum
+       typeset post_upgrade_checksum
+
+       log_note "Checking if we can upgrade from ZFS version $vers"
+       pre_upgrade_checksum=$(check_pool $pool_name pre)
+       log_must $ZPOOL upgrade $pool_name
+       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
+{
+       typeset vers=$1
+       typeset -n pool_files=ZPOOL_VERSION_${vers}_FILES
+       typeset -n pool_name=ZPOOL_VERSION_${vers}_NAME
+
+       if poolexists $pool_name; then
+               log_must $ZPOOL destroy $pool_name
+       fi
+       for file in $pool_files; do
+               $RM -f /$TESTPOOL/$file
+       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
+{
+       typeset pool=$1
+       typeset flag=$2
+       $FIND /$pool -type f -exec $CKSUM {} + > \
+               /$TESTPOOL/pool-checksums.$pool.$flag
+       echo /$TESTPOOL/pool-checksums.$pool.$flag
+}
+
+# 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
+{
+       typeset pool=$1
+       typeset vers=$2
+       typeset actual
+
+       # check version using zdb
+       actual=$($ZDB -C $pool | $SED -n 's/^.*version: \(.*\)$/\1/p')
+       if [[ $actual != $vers ]] ; then
+               log_fail "$pool: zdb reported version $actual, expected $vers"
+       fi
+
+       # check version using zpool upgrade
+       actual=$($ZPOOL upgrade | $GREP $pool$ | \
+           $AWK '{print $1}' | $SED -e 's/ //g')
+       if [[ $actual != $vers ]] ; then
+               log_fail "$pool: zpool reported version $actual, expected $vers"
+       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
+{
+       typeset min=$1
+       typeset max=$2
+       typeset rand=0
+
+       while [[ $rand -lt $min ]] ; do
+               rand=$(( $RANDOM % $max + 1))
+       done
+
+       echo $rand
+}
diff --git a/tests/zfs-tests/tests/functional/cli_root/zpool_upgrade/zpool_upgrade_001_pos.ksh b/tests/zfs-tests/tests/functional/cli_root/zpool_upgrade/zpool_upgrade_001_pos.ksh
new file mode 100755 (executable)
index 0000000..f32d1ca
--- /dev/null
@@ -0,0 +1,71 @@
+#!/bin/ksh -p
+#
+# CDDL HEADER START
+#
+# The contents of this file are subject to the terms of the
+# Common Development and Distribution License (the "License").
+# You may not use this file except in compliance with the License.
+#
+# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
+# or http://www.opensolaris.org/os/licensing.
+# See the License for the specific language governing permissions
+# and limitations under the License.
+#
+# When distributing Covered Code, include this CDDL HEADER in each
+# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
+# If applicable, add the following below this CDDL HEADER, with the
+# fields enclosed by brackets "[]" replaced with your own identifying
+# information: Portions Copyright [yyyy] [name of copyright owner]
+#
+# CDDL HEADER END
+#
+
+#
+# Copyright 2008 Sun Microsystems, Inc.  All rights reserved.
+# Use is subject to license terms.
+#
+
+#
+# Copyright (c) 2012 by Delphix. All rights reserved.
+# Copyright 2015 Nexenta Systems, Inc.  All rights reserved.
+#
+
+. $STF_SUITE/tests/functional/cli_root/zpool_upgrade/zpool_upgrade.kshlib
+
+#
+# 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"
diff --git a/tests/zfs-tests/tests/functional/cli_root/zpool_upgrade/zpool_upgrade_002_pos.ksh b/tests/zfs-tests/tests/functional/cli_root/zpool_upgrade/zpool_upgrade_002_pos.ksh
new file mode 100755 (executable)
index 0000000..16ab149
--- /dev/null
@@ -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 2008 Sun Microsystems, Inc.  All rights reserved.
+# Use is subject to license terms.
+#
+
+#
+# Copyright 2015 Nexenta Systems, Inc.  All rights reserved.
+#
+
+. $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 pool works"
+log_onexit cleanup
+
+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 pool works"
diff --git a/tests/zfs-tests/tests/functional/cli_root/zpool_upgrade/zpool_upgrade_003_pos.ksh b/tests/zfs-tests/tests/functional/cli_root/zpool_upgrade/zpool_upgrade_003_pos.ksh
new file mode 100755 (executable)
index 0000000..0ac3470
--- /dev/null
@@ -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 2008 Sun Microsystems, Inc.  All rights reserved.
+# Use is subject to license terms.
+#
+
+#
+# Copyright 2015 Nexenta Systems, Inc.  All rights reserved.
+#
+
+. $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
+
+# Create a version 1 pool
+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"
diff --git a/tests/zfs-tests/tests/functional/cli_root/zpool_upgrade/zpool_upgrade_004_pos.ksh b/tests/zfs-tests/tests/functional/cli_root/zpool_upgrade/zpool_upgrade_004_pos.ksh
new file mode 100755 (executable)
index 0000000..ba3cdd0
--- /dev/null
@@ -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.
+#
+
+#
+# Copyright (c) 2012 by Delphix. All rights reserved.
+# Copyright 2015 Nexenta Systems, Inc.  All rights reserved.
+#
+
+. $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
+       typeset -n pool_name=ZPOOL_VERSION_${config}_NAME
+
+       TEST_POOLS="$TEST_POOLS $pool_name"
+       create_old_pool $config
+       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
+       typeset -n pool_name=ZPOOL_VERSION_${config}_NAME
+
+       check_pool $pool_name post > /dev/null
+       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"
diff --git a/tests/zfs-tests/tests/functional/cli_root/zpool_upgrade/zpool_upgrade_005_neg.ksh b/tests/zfs-tests/tests/functional/cli_root/zpool_upgrade/zpool_upgrade_005_neg.ksh
new file mode 100755 (executable)
index 0000000..d32ae3e
--- /dev/null
@@ -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.
+#
+
+#
+# Copyright (c) 2012 by Delphix. All rights reserved.
+# Copyright 2015 Nexenta Systems, Inc.  All rights reserved.
+#
+
+. $STF_SUITE/tests/functional/cli_root/zpool_upgrade/zpool_upgrade.kshlib
+
+#
+# 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"
+
+log_assert "Variations of upgrade -v print usage message," \
+    "return with non-zero status"
+
+for arg in "/tmp" "-?" "-va" "-v fakepool" "-a fakepool" ; do
+        log_mustnot $ZPOOL upgrade $arg
+done
+
+log_pass "Variations of upgrade -v print usage message," \
+    "return with non-zero status"
diff --git a/tests/zfs-tests/tests/functional/cli_root/zpool_upgrade/zpool_upgrade_006_neg.ksh b/tests/zfs-tests/tests/functional/cli_root/zpool_upgrade/zpool_upgrade_006_neg.ksh
new file mode 100755 (executable)
index 0000000..a66ac6c
--- /dev/null
@@ -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.
+#
+
+#
+# Copyright (c) 2012 by Delphix. All rights reserved.
+# Copyright 2015 Nexenta Systems, Inc.  All rights reserved.
+#
+
+. $STF_SUITE/tests/functional/cli_root/zpool_upgrade/zpool_upgrade.kshlib
+
+#
+# DESCRIPTION:
+# Attempting to upgrade a non-existent pool will return an error
+#
+# STRATEGY:
+# 1. Compose non-existent pool name, try to upgrade it
+# 2. Verify non-zero exit status
+#
+
+log_assert "Attempting to upgrade a non-existent pool will return an error"
+
+NO_POOL=notapool
+
+while true ; do
+       if poolexists $NO_POOL ; then
+               NO_POOL="${NO_POOL}x"
+       else
+               log_mustnot $ZPOOL upgrade $NO_POOL
+               break
+       fi
+done
+
+log_pass "Attempting to upgrade a non-existent pool will return an error"
diff --git a/tests/zfs-tests/tests/functional/cli_root/zpool_upgrade/zpool_upgrade_007_pos.ksh b/tests/zfs-tests/tests/functional/cli_root/zpool_upgrade/zpool_upgrade_007_pos.ksh
new file mode 100755 (executable)
index 0000000..346d3da
--- /dev/null
@@ -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 2008 Sun Microsystems, Inc.  All rights reserved.
+# Use is subject to license terms.
+#
+
+#
+# Copyright (c) 2012 by Delphix. All rights reserved.
+# Copyright 2015 Nexenta Systems, Inc.  All rights reserved.
+#
+
+. $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 pool works"
+log_onexit cleanup
+
+# $CONFIGS gets set in the .cfg script
+for config in $CONFIGS; do
+       typeset -n pool_name=ZPOOL_VERSION_${config}_NAME
+
+       create_old_pool $config
+       default_check_zfs_upgrade $pool_name
+       destroy_upgraded_pool $config
+done
+
+log_pass "Import pools of all versions - 'zfs upgrade' on each pool works"
diff --git a/tests/zfs-tests/tests/functional/cli_root/zpool_upgrade/zpool_upgrade_008_pos.ksh b/tests/zfs-tests/tests/functional/cli_root/zpool_upgrade/zpool_upgrade_008_pos.ksh
new file mode 100755 (executable)
index 0000000..0809f95
--- /dev/null
@@ -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 2009 Sun Microsystems, Inc.  All rights reserved.
+# Use is subject to license terms.
+#
+
+#
+# Copyright (c) 2012 by Delphix. All rights reserved.
+# Copyright 2015 Nexenta Systems, Inc.  All rights reserved.
+#
+
+. $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 $ver_old
+}
+
+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.
+VERSIONS="1 2 3 4 5 6 7 8 9 10 11 12 13 14 15"
+MAX_VER=15
+
+for ver_old in $VERSIONS; do
+       typeset -n pool_name=ZPOOL_VERSION_${ver_old}_NAME
+       typeset ver_new=$(random $ver_old $MAX_VER)
+
+       create_old_pool $ver_old
+       log_must $ZPOOL upgrade -V $ver_new $pool_name > /dev/null
+       check_poolversion $pool_name $ver_new
+       destroy_upgraded_pool $ver_old
+done
+
+log_pass "zpool upgrade should be able to upgrade pools to a given version" \
+    "using -V"
diff --git a/tests/zfs-tests/tests/functional/cli_root/zpool_upgrade/zpool_upgrade_009_neg.ksh b/tests/zfs-tests/tests/functional/cli_root/zpool_upgrade/zpool_upgrade_009_neg.ksh
new file mode 100755 (executable)
index 0000000..dce9268
--- /dev/null
@@ -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.
+#
+
+#
+# Copyright (c) 2012 by Delphix. All rights reserved.
+# Copyright 2015 Nexenta Systems, Inc.  All rights reserved.
+#
+
+. $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" \
+    "unknown version"
+
+typeset -i config=2
+typeset -n pool_name=ZPOOL_VERSION_${config}_NAME
+
+create_old_pool $config
+log_mustnot $ZPOOL upgrade -V 999 $pool_name
+log_mustnot $ZPOOL upgrade -V 999
+check_poolversion $pool_name $config
+destroy_upgraded_pool $config
+
+log_pass "zpool upgrade -V shouldn't be able to upgrade a pool to" \
+    "unknown version"
diff --git a/tests/zfs-tests/tests/functional/cli_user/Makefile.am b/tests/zfs-tests/tests/functional/cli_user/Makefile.am
new file mode 100644 (file)
index 0000000..f1ff32e
--- /dev/null
@@ -0,0 +1,5 @@
+SUBDIRS = \
+       misc \
+       zfs_list \
+       zpool_iostat \
+       zpool_list
diff --git a/tests/zfs-tests/tests/functional/cli_user/misc/Makefile.am b/tests/zfs-tests/tests/functional/cli_user/misc/Makefile.am
new file mode 100644 (file)
index 0000000..dad922c
--- /dev/null
@@ -0,0 +1,46 @@
+pkgdatadir = $(datadir)/@PACKAGE@/zfs-tests/tests/functional/cli_user/misc
+dist_pkgdata_SCRIPTS = \
+       misc.cfg \
+       setup.ksh \
+       cleanup.ksh \
+       zdb_001_neg.ksh \
+       zfs_001_neg.ksh \
+       zfs_allow_001_neg.ksh \
+       zfs_clone_001_neg.ksh \
+       zfs_create_001_neg.ksh \
+       zfs_destroy_001_neg.ksh \
+       zfs_get_001_neg.ksh \
+       zfs_inherit_001_neg.ksh \
+       zfs_mount_001_neg.ksh \
+       zfs_promote_001_neg.ksh \
+       zfs_receive_001_neg.ksh \
+       zfs_rename_001_neg.ksh \
+       zfs_rollback_001_neg.ksh \
+       zfs_send_001_neg.ksh \
+       zfs_set_001_neg.ksh \
+       zfs_share_001_neg.ksh \
+       zfs_snapshot_001_neg.ksh \
+       zfs_unallow_001_neg.ksh \
+       zfs_unmount_001_neg.ksh \
+       zfs_unshare_001_neg.ksh \
+       zfs_upgrade_001_neg.ksh \
+       zpool_001_neg.ksh \
+       zpool_add_001_neg.ksh \
+       zpool_attach_001_neg.ksh \
+       zpool_clear_001_neg.ksh \
+       zpool_create_001_neg.ksh \
+       zpool_destroy_001_neg.ksh \
+       zpool_detach_001_neg.ksh \
+       zpool_export_001_neg.ksh \
+       zpool_get_001_neg.ksh \
+       zpool_history_001_neg.ksh \
+       zpool_import_001_neg.ksh \
+       zpool_import_002_neg.ksh \
+       zpool_offline_001_neg.ksh \
+       zpool_online_001_neg.ksh \
+       zpool_remove_001_neg.ksh \
+       zpool_replace_001_neg.ksh \
+       zpool_scrub_001_neg.ksh \
+       zpool_set_001_neg.ksh \
+       zpool_status_001_neg.ksh \
+       zpool_upgrade_001_neg.ksh
diff --git a/tests/zfs-tests/tests/functional/cli_user/misc/cleanup.ksh b/tests/zfs-tests/tests/functional/cli_user/misc/cleanup.ksh
new file mode 100755 (executable)
index 0000000..77090ba
--- /dev/null
@@ -0,0 +1,50 @@
+#!/bin/ksh -p
+#
+# CDDL HEADER START
+#
+# The contents of this file are subject to the terms of the
+# Common Development and Distribution License (the "License").
+# You may not use this file except in compliance with the License.
+#
+# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
+# or http://www.opensolaris.org/os/licensing.
+# See the License for the specific language governing permissions
+# and limitations under the License.
+#
+# When distributing Covered Code, include this CDDL HEADER in each
+# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
+# If applicable, add the following below this CDDL HEADER, with the
+# fields enclosed by brackets "[]" replaced with your own identifying
+# information: Portions Copyright [yyyy] [name of copyright owner]
+#
+# CDDL HEADER END
+#
+
+#
+# Copyright 2008 Sun Microsystems, Inc.  All rights reserved.
+# Use is subject to license terms.
+#
+
+#
+# Copyright (c) 2013 by Delphix. All rights reserved.
+#
+
+. $STF_SUITE/tests/functional/cli_user/misc/misc.cfg
+. $STF_SUITE/include/libtest.shlib
+
+if poolexists $TESTPOOL.virt
+then
+       log_must $ZPOOL destroy $TESTPOOL.virt
+fi
+
+if poolexists v1-pool
+then
+       log_must $ZPOOL destroy v1-pool
+fi
+
+if [[ -f /tmp/zfstest_datastream.dat ]]
+then
+       log_must $RM -f /tmp/zfstest_datastream.dat
+fi
+
+default_cleanup
diff --git a/tests/zfs-tests/tests/functional/cli_user/misc/misc.cfg b/tests/zfs-tests/tests/functional/cli_user/misc/misc.cfg
new file mode 100644 (file)
index 0000000..55d38e8
--- /dev/null
@@ -0,0 +1,71 @@
+#
+# CDDL HEADER START
+#
+# The contents of this file are subject to the terms of the
+# Common Development and Distribution License (the "License").
+# You may not use this file except in compliance with the License.
+#
+# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
+# or http://www.opensolaris.org/os/licensing.
+# See the License for the specific language governing permissions
+# and limitations under the License.
+#
+# When distributing Covered Code, include this CDDL HEADER in each
+# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
+# If applicable, add the following below this CDDL HEADER, with the
+# fields enclosed by brackets "[]" replaced with your own identifying
+# information: Portions Copyright [yyyy] [name of copyright owner]
+#
+# CDDL HEADER END
+#
+
+#
+# Copyright 2007 Sun Microsystems, Inc.  All rights reserved.
+# Use is subject to license terms.
+#
+
+#
+# Copyright (c) 2013 by Delphix. All rights reserved.
+#
+
+# these are the set of setable ZFS properties
+PROP_NAMES="\
+       aclinherit      aclmode         atime            \
+       checksum        compression                     devices \
+       exec            mountpoint      quota           readonly \
+       recordsize      reservation     setuid          sharenfs \
+       snapdir"
+
+# these are a set of values we apply, for use when testing the
+# zfs get/set subcommands - ordered as per the list above so we
+# can iterate over both sets in an array
+PROP_VALS="\
+       secure          discard         on               \
+       fletcher2       on                              on \
+       on              legacy          none            on \
+       128k            none            on              on \
+       visible"
+
+# these are an alternate set of property values
+PROP_ALTVALS="\
+       noallow         groupmask       off              \
+       fletcher4       lzjb                            off \
+       off             /tmp/zfstest    100m            off \
+       512             10m             off             off \
+       hidden"
+
+
+
+# additional properties to worry about: canmount copies xattr zoned version
+
+POOL_PROPS="\
+       failmode        autoreplace"
+
+POOL_VALS="\
+       continue        on"
+
+POOL_ALTVALS="\
+       panic           off"
+
+export TESTSNAP=testsnap-misc
+export TESTCLCT=testclct-misc
diff --git a/tests/zfs-tests/tests/functional/cli_user/misc/setup.ksh b/tests/zfs-tests/tests/functional/cli_user/misc/setup.ksh
new file mode 100755 (executable)
index 0000000..e651acb
--- /dev/null
@@ -0,0 +1,161 @@
+#!/bin/ksh -p
+#
+# CDDL HEADER START
+#
+# The contents of this file are subject to the terms of the
+# Common Development and Distribution License (the "License").
+# You may not use this file except in compliance with the License.
+#
+# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
+# or http://www.opensolaris.org/os/licensing.
+# See the License for the specific language governing permissions
+# and limitations under the License.
+#
+# When distributing Covered Code, include this CDDL HEADER in each
+# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
+# If applicable, add the following below this CDDL HEADER, with the
+# fields enclosed by brackets "[]" replaced with your own identifying
+# information: Portions Copyright [yyyy] [name of copyright owner]
+#
+# CDDL HEADER END
+#
+
+#
+# Copyright 2008 Sun Microsystems, Inc.  All rights reserved.
+# Use is subject to license terms.
+#
+
+#
+# Copyright (c) 2013 by Delphix. All rights reserved.
+#
+
+. $STF_SUITE/tests/functional/cli_user/misc/misc.cfg
+. $STF_SUITE/include/libtest.shlib
+
+# This setup script is moderately complex, as it creates scenarios for all
+# of the tests included in this directory. Usually we'd want each test case
+# to setup/teardown it's own configuration, but this would be time consuming
+# given the nature of these tests. However, as a side-effect, one test
+# leaving the system in an unknown state could impact other test cases.
+
+
+DISK=${DISKS%% *}
+VOLSIZE=150m
+TESTVOL=testvol
+
+# Create a default setup that includes a volume
+default_setup_noexit "$DISK" "" "volume"
+
+#
+# The rest of this setup script creates a ZFS filesystem configuration
+# that is used to test the rest of the zfs subcommands in this directory.
+#
+
+# create a snapshot and a clone to test clone promote
+log_must $ZFS snapshot $TESTPOOL/$TESTFS@snap
+log_must $ZFS clone $TESTPOOL/$TESTFS@snap $TESTPOOL/$TESTFS/clone
+# create a file in the filesystem that isn't in the above snapshot
+$TOUCH /$TESTDIR/file.txt
+
+
+# create a non-default property and a child we can use to test inherit
+log_must $ZFS create $TESTPOOL/$TESTFS/$TESTFS2
+log_must $ZFS set snapdir=hidden $TESTPOOL/$TESTFS
+
+
+# create an unmounted filesystem to test unmount
+log_must $ZFS create $TESTPOOL/$TESTFS/$TESTFS2.unmounted
+log_must $ZFS unmount $TESTPOOL/$TESTFS/$TESTFS2.unmounted
+
+
+# send our snapshot to a known file in /tmp
+$ZFS send $TESTPOOL/$TESTFS@snap > /tmp/zfstest_datastream.dat
+if [ ! -s /tmp/zfstest_datastream.dat ]
+then
+       log_fail "ZFS send datafile was not created!"
+fi
+log_must $CHMOD 644 /tmp/zfstest_datastream.dat
+
+
+# create a filesystem that has particular properties to test set/get
+log_must $ZFS create -o version=1 $TESTPOOL/$TESTFS/prop
+set -A props $PROP_NAMES
+set -A prop_vals $PROP_VALS
+typeset -i i=0
+
+while [[ $i -lt ${#props[*]} ]]
+do
+       prop_name=${props[$i]}
+       prop_val=${prop_vals[$i]}
+       log_must $ZFS set $prop_name=$prop_val $TESTPOOL/$TESTFS/prop
+       i=$(( $i + 1 ))
+done
+
+# create a filesystem we don't mind renaming
+log_must $ZFS create $TESTPOOL/$TESTFS/renameme
+
+
+if is_global_zone
+then
+       # create a filesystem we can share
+       log_must $ZFS create $TESTPOOL/$TESTFS/unshared
+       log_must $ZFS set sharenfs=off $TESTPOOL/$TESTFS/unshared
+
+       # create a filesystem that we can unshare
+       log_must $ZFS create $TESTPOOL/$TESTFS/shared
+       log_must $ZFS set sharenfs=on $TESTPOOL/$TESTFS/shared
+fi
+
+
+log_must $ZFS create -o version=1 $TESTPOOL/$TESTFS/version1
+log_must $ZFS create -o version=1 $TESTPOOL/$TESTFS/allowed
+log_must $ZFS allow everyone create $TESTPOOL/$TESTFS/allowed
+
+if is_global_zone
+then
+
+       # Now create several virtual disks to test zpool with
+
+       $MKFILE 100m /$TESTDIR/disk1.dat
+       $MKFILE 100m /$TESTDIR/disk2.dat
+       $MKFILE 100m /$TESTDIR/disk3.dat
+       $MKFILE 100m /$TESTDIR/disk-additional.dat
+       $MKFILE 100m /$TESTDIR/disk-export.dat
+       $MKFILE 100m /$TESTDIR/disk-offline.dat
+       $MKFILE 100m /$TESTDIR/disk-spare1.dat
+       $MKFILE 100m /$TESTDIR/disk-spare2.dat
+
+       # and create a pool we can perform attach remove replace,
+       # etc. operations with
+       log_must $ZPOOL create $TESTPOOL.virt mirror /$TESTDIR/disk1.dat \
+       /$TESTDIR/disk2.dat /$TESTDIR/disk3.dat /$TESTDIR/disk-offline.dat \
+       spare /$TESTDIR/disk-spare1.dat
+
+
+       # Offline one of the disks to test online
+       log_must $ZPOOL offline $TESTPOOL.virt /$TESTDIR/disk-offline.dat
+
+
+       # create an exported pool to test import
+       log_must $ZPOOL create $TESTPOOL.exported /$TESTDIR/disk-export.dat
+       log_must $ZPOOL export $TESTPOOL.exported
+
+       set -A props $POOL_PROPS
+       set -A prop_vals $POOL_VALS
+       typeset -i i=0
+
+       while [[ $i -lt ${#props[*]} ]]
+       do
+               prop_name=${props[$i]}
+               prop_val=${prop_vals[$i]}
+               log_must $ZPOOL set $prop_name=$prop_val $TESTPOOL
+               i=$(( $i + 1 ))
+       done
+
+       # copy a v1 pool from cli_root
+       $CP $STF_SUITE/tests/functional/cli_root/zpool_upgrade/blockfiles/zfs-pool-v1.dat.bz2 \
+           /$TESTDIR
+       log_must $BUNZIP2 /$TESTDIR/zfs-pool-v1.dat.bz2
+       log_must $ZPOOL import -d /$TESTDIR v1-pool
+fi
+log_pass
diff --git a/tests/zfs-tests/tests/functional/cli_user/misc/zdb_001_neg.ksh b/tests/zfs-tests/tests/functional/cli_user/misc/zdb_001_neg.ksh
new file mode 100755 (executable)
index 0000000..876f1e0
--- /dev/null
@@ -0,0 +1,82 @@
+#!/bin/ksh -p
+#
+# CDDL HEADER START
+#
+# The contents of this file are subject to the terms of the
+# Common Development and Distribution License (the "License").
+# You may not use this file except in compliance with the License.
+#
+# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
+# or http://www.opensolaris.org/os/licensing.
+# See the License for the specific language governing permissions
+# and limitations under the License.
+#
+# When distributing Covered Code, include this CDDL HEADER in each
+# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
+# If applicable, add the following below this CDDL HEADER, with the
+# fields enclosed by brackets "[]" replaced with your own identifying
+# information: Portions Copyright [yyyy] [name of copyright owner]
+#
+# CDDL HEADER END
+#
+
+#
+# Copyright 2007 Sun Microsystems, Inc.  All rights reserved.
+# Use is subject to license terms.
+#
+
+#
+# Copyright (c) 2013 by Delphix. All rights reserved.
+#
+
+. $STF_SUITE/tests/functional/cli_user/misc/misc.cfg
+. $STF_SUITE/include/libtest.shlib
+
+#
+# DESCRIPTION:
+#
+# zdb can't run as a user on datasets, but can run without arguments
+#
+# STRATEGY:
+# 1. Run zdb as a user, it should print information
+# 2. Run zdb as a user on different datasets, it should fail
+#
+
+function check_zdb
+{
+       $@ > /tmp/zdb.$$
+       $GREP "Dataset mos" /tmp/zdb.$$
+       if [ $? -eq 0 ]
+       then
+               log_fail "$@ exited 0 when run as a non root user!"
+       fi
+       $RM /tmp/zdb.$$
+}
+
+
+function cleanup
+{
+       if [ -e /tmp/zdb_001_neg.$$.txt ]
+       then
+               $RM /tmp/zdb_001_neg.$$.txt
+       fi
+
+}
+
+verify_runnable "global"
+
+log_assert "zdb can't run as a user on datasets, but can run without arguments"
+log_onexit cleanup
+
+log_must eval "$ZDB > /tmp/zdb_001_neg.$$.txt"
+# verify the output looks okay
+log_must $GREP pool_guid /tmp/zdb_001_neg.$$.txt
+log_must $RM /tmp/zdb_001_neg.$$.txt
+
+# we shouldn't able to run it on any dataset
+check_zdb $ZDB $TESTPOOL
+check_zdb $ZDB $TESTPOOL/$TESTFS
+check_zdb $ZDB $TESTPOOL/$TESTFS@snap
+check_zdb $ZDB $TESTPOOL/$TESTFS.clone
+
+log_pass "zdb can't run as a user on datasets, but can run without arguments"
diff --git a/tests/zfs-tests/tests/functional/cli_user/misc/zfs_001_neg.ksh b/tests/zfs-tests/tests/functional/cli_user/misc/zfs_001_neg.ksh
new file mode 100755 (executable)
index 0000000..5edf735
--- /dev/null
@@ -0,0 +1,59 @@
+#!/bin/ksh -p
+#
+# CDDL HEADER START
+#
+# The contents of this file are subject to the terms of the
+# Common Development and Distribution License (the "License").
+# You may not use this file except in compliance with the License.
+#
+# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
+# or http://www.opensolaris.org/os/licensing.
+# See the License for the specific language governing permissions
+# and limitations under the License.
+#
+# When distributing Covered Code, include this CDDL HEADER in each
+# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
+# If applicable, add the following below this CDDL HEADER, with the
+# fields enclosed by brackets "[]" replaced with your own identifying
+# information: Portions Copyright [yyyy] [name of copyright owner]
+#
+# CDDL HEADER END
+#
+
+#
+# Copyright 2007 Sun Microsystems, Inc.  All rights reserved.
+# Use is subject to license terms.
+#
+
+#
+# Copyright (c) 2013 by Delphix. All rights reserved.
+#
+
+. $STF_SUITE/tests/functional/cli_user/misc/misc.cfg
+. $STF_SUITE/include/libtest.shlib
+
+#
+# DESCRIPTION:
+#
+# zfs shows a usage message when run as a user
+#
+# STRATEGY:
+# 1. Run zfs as a user
+# 2. Verify it produces a usage message
+#
+
+function cleanup
+{
+       if [ -e /tmp/zfs_001_neg.$$.txt ]
+       then
+               $RM /tmp/zfs_001_neg.$$.txt
+       fi
+}
+
+log_onexit cleanup
+log_assert "zfs shows a usage message when run as a user"
+
+eval "$ZFS > /tmp/zfs_001_neg.$$.txt 2>&1"
+log_must $GREP "usage: zfs command args" /tmp/zfs_001_neg.$$.txt
+
+log_pass "zfs shows a usage message when run as a user"
diff --git a/tests/zfs-tests/tests/functional/cli_user/misc/zfs_allow_001_neg.ksh b/tests/zfs-tests/tests/functional/cli_user/misc/zfs_allow_001_neg.ksh
new file mode 100755 (executable)
index 0000000..0fb22e0
--- /dev/null
@@ -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 2008 Sun Microsystems, Inc.  All rights reserved.
+# Use is subject to license terms.
+#
+
+#
+# Copyright (c) 2013 by Delphix. All rights reserved.
+#
+
+. $STF_SUITE/tests/functional/cli_user/misc/misc.cfg
+. $STF_SUITE/include/libtest.shlib
+
+#
+# DESCRIPTION:
+#
+# zfs allow returns an error when run as a user
+#
+# STRATEGY:
+#
+# 1. Verify that trying to show allows works as a user
+# 2. Verify that trying to set allows fails as a user
+#
+#
+
+# check to see if we have zfs allow
+$ZFS 2>&1 | $GREP "allow" > /dev/null
+if (($? != 0)) then
+       log_unsupported "ZFS allow not supported on this machine."
+fi
+
+log_assert "zfs allow returns an error when run as a user"
+
+log_must $ZFS allow $TESTPOOL/$TESTFS
+log_mustnot $ZFS allow $($LOGNAME) create $TESTPOOL/$TESTFS
+
+# now verify that the above command actually did nothing by
+# checking for any allow output. ( if no allows are granted,
+# nothing should be output )
+OUTPUT=$($ZFS allow $TESTPOOL/$TESTFS | $GREP "Local+Descendent" )
+if [ -n "$OUTPUT" ]
+then
+       log_fail "zfs allow permissions were granted on $TESTPOOL/$TESTFS"
+fi
+
+log_pass "zfs allow returns an error when run as a user"
diff --git a/tests/zfs-tests/tests/functional/cli_user/misc/zfs_clone_001_neg.ksh b/tests/zfs-tests/tests/functional/cli_user/misc/zfs_clone_001_neg.ksh
new file mode 100755 (executable)
index 0000000..406f913
--- /dev/null
@@ -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.
+#
+
+#
+# Copyright (c) 2013 by Delphix. All rights reserved.
+#
+
+. $STF_SUITE/tests/functional/cli_user/misc/misc.cfg
+. $STF_SUITE/include/libtest.shlib
+
+#
+# DESCRIPTION:
+#
+# zfs clone returns an error when run as a user
+#
+# STRATEGY:
+#
+# 1. Verify that we're unable to clone snapshots as a user
+#
+#
+
+log_assert "zfs clone returns an error when run as a user"
+log_mustnot $ZFS clone $TESTPOOL/$TESTFS@snap $TESTPOOL/$TESTFS.myclone
+
+# check to see that the above command really did nothing
+if datasetexists $TESTPOOL/$TESTFS.myclone
+then
+       log_fail "Dataset $TESTPOOL/$TESTFS.myclone should not exist!"
+fi
+log_pass "zfs clone returns an error when run as a user"
diff --git a/tests/zfs-tests/tests/functional/cli_user/misc/zfs_create_001_neg.ksh b/tests/zfs-tests/tests/functional/cli_user/misc/zfs_create_001_neg.ksh
new file mode 100755 (executable)
index 0000000..579771e
--- /dev/null
@@ -0,0 +1,61 @@
+#!/bin/ksh -p
+#
+# CDDL HEADER START
+#
+# The contents of this file are subject to the terms of the
+# Common Development and Distribution License (the "License").
+# You may not use this file except in compliance with the License.
+#
+# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
+# or http://www.opensolaris.org/os/licensing.
+# See the License for the specific language governing permissions
+# and limitations under the License.
+#
+# When distributing Covered Code, include this CDDL HEADER in each
+# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
+# If applicable, add the following below this CDDL HEADER, with the
+# fields enclosed by brackets "[]" replaced with your own identifying
+# information: Portions Copyright [yyyy] [name of copyright owner]
+#
+# CDDL HEADER END
+#
+
+#
+# Copyright 2007 Sun Microsystems, Inc.  All rights reserved.
+# Use is subject to license terms.
+#
+
+#
+# Copyright (c) 2013 by Delphix. All rights reserved.
+#
+
+. $STF_SUITE/tests/functional/cli_user/misc/misc.cfg
+. $STF_SUITE/include/libtest.shlib
+
+#
+# DESCRIPTION:
+# Executing various badly formed 'zfs create' should fail.
+#
+# STRATEGY:
+# 1. Create an array of badly formed sub-commands.
+# 2. Execute each element of the array.
+# 3. Verify an error code is returned.
+#
+
+verify_runnable "both"
+
+
+set -A args  "" "create $TESTPOOL/$TESTFS" \
+    "create $TESTPOOL/$TESTFS@$TESTSNAP" \
+    "create $TESTPOOL/$TESTCLCT/$TESTFS" \
+    "create $TESTFS/$TESTPOOL/$TESTCLCT"
+
+log_assert "Verify zfs create without parameters fails."
+
+typeset -i i=0
+while [[ $i -lt ${#args[*]} ]]; do
+       log_mustnot $ZFS ${args[i]}
+       ((i = i + 1))
+done
+
+log_pass "The sub-command 'create' fails as non-root."
diff --git a/tests/zfs-tests/tests/functional/cli_user/misc/zfs_destroy_001_neg.ksh b/tests/zfs-tests/tests/functional/cli_user/misc/zfs_destroy_001_neg.ksh
new file mode 100755 (executable)
index 0000000..d7a23ac
--- /dev/null
@@ -0,0 +1,67 @@
+#!/bin/ksh -p
+#
+# CDDL HEADER START
+#
+# The contents of this file are subject to the terms of the
+# Common Development and Distribution License (the "License").
+# You may not use this file except in compliance with the License.
+#
+# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
+# or http://www.opensolaris.org/os/licensing.
+# See the License for the specific language governing permissions
+# and limitations under the License.
+#
+# When distributing Covered Code, include this CDDL HEADER in each
+# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
+# If applicable, add the following below this CDDL HEADER, with the
+# fields enclosed by brackets "[]" replaced with your own identifying
+# information: Portions Copyright [yyyy] [name of copyright owner]
+#
+# CDDL HEADER END
+#
+
+#
+# Copyright 2007 Sun Microsystems, Inc.  All rights reserved.
+# Use is subject to license terms.
+#
+
+#
+# Copyright (c) 2013 by Delphix. All rights reserved.
+#
+
+. $STF_SUITE/tests/functional/cli_user/misc/misc.cfg
+. $STF_SUITE/include/libtest.shlib
+
+#
+# DESCRIPTION:
+# Verify that 'zfs destroy' fails as non-root.
+#
+# STRATEGY:
+# 1. Create an array of options.
+# 2. Execute each element of the array.
+# 3. Verify an error code is returned.
+#
+
+verify_runnable "both"
+
+
+set -A args "destroy" "destroy $TESTPOOL/$TESTFS" \
+    "destroy -f" "destroy -f $TESTPOOL/$TESTFS" \
+    "destroy -r" "destroy -r $TESTPOOL/$TESTFS" \
+    "destroy -rf $TESTPOOL/$TESTFS" \
+    "destroy -fr $TESTPOOL/$TESTFS" \
+    "destroy $TESTPOOL/$TESTFS@$TESTSNAP" \
+    "destroy -f $TESTPOOL/$TESTFS@$TESTSNAP" \
+    "destroy -r $TESTPOOL/$TESTFS@$TESTSNAP" \
+    "destroy -rf $TESTPOOL/$TESTFS@$TESTSNAP" \
+    "destroy -fr $TESTPOOL/$TESTFS@$TESTSNAP"
+
+log_assert "zfs destroy [-f|-r] [fs|snap]"
+
+typeset -i i=0
+while [[ $i -lt ${#args[*]} ]]; do
+       log_mustnot $ZFS ${args[i]}
+       ((i = i + 1))
+done
+
+log_pass "The sub-command 'destroy' fails as non-root."
diff --git a/tests/zfs-tests/tests/functional/cli_user/misc/zfs_get_001_neg.ksh b/tests/zfs-tests/tests/functional/cli_user/misc/zfs_get_001_neg.ksh
new file mode 100755 (executable)
index 0000000..70b4681
--- /dev/null
@@ -0,0 +1,65 @@
+#!/bin/ksh -p
+#
+# CDDL HEADER START
+#
+# The contents of this file are subject to the terms of the
+# Common Development and Distribution License (the "License").
+# You may not use this file except in compliance with the License.
+#
+# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
+# or http://www.opensolaris.org/os/licensing.
+# See the License for the specific language governing permissions
+# and limitations under the License.
+#
+# When distributing Covered Code, include this CDDL HEADER in each
+# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
+# If applicable, add the following below this CDDL HEADER, with the
+# fields enclosed by brackets "[]" replaced with your own identifying
+# information: Portions Copyright [yyyy] [name of copyright owner]
+#
+# CDDL HEADER END
+#
+
+#
+# Copyright 2007 Sun Microsystems, Inc.  All rights reserved.
+# Use is subject to license terms.
+#
+
+#
+# Copyright (c) 2013 by Delphix. All rights reserved.
+#
+
+. $STF_SUITE/tests/functional/cli_user/misc/misc.cfg
+. $STF_SUITE/include/libtest.shlib
+
+#
+# DESCRIPTION:
+#
+# zfs get works when run as a user
+#
+# STRATEGY:
+# 1. Run zfs get with an array of different arguments
+# 2. Verify for each property, we get the value that's expected
+#
+#
+
+log_assert "zfs get works when run as a user"
+
+typeset -i i=0
+
+set -A props $PROP_NAMES
+set -A prop_vals $PROP_VALS
+
+while [[ $i -lt ${#args[*]} ]]
+do
+       PROP=${props[$i]}
+       EXPECTED=${prop_vals[$i]}
+       ACTUAL=$( $ZFS get $PROP -o value -H snapdir $TESTPOOl/$TESTFS/prop )
+       if [ "$ACTUAL" != "$EXPECTED" ]
+       then
+               log_fail "Property $PROP value was $ACTUAL, expected $EXPECTED"
+       fi
+        i=$(( $i + 1 ))
+done
+
+log_pass "zfs get works when run as a user"
diff --git a/tests/zfs-tests/tests/functional/cli_user/misc/zfs_inherit_001_neg.ksh b/tests/zfs-tests/tests/functional/cli_user/misc/zfs_inherit_001_neg.ksh
new file mode 100755 (executable)
index 0000000..d68cec6
--- /dev/null
@@ -0,0 +1,56 @@
+#!/bin/ksh -p
+#
+# CDDL HEADER START
+#
+# The contents of this file are subject to the terms of the
+# Common Development and Distribution License (the "License").
+# You may not use this file except in compliance with the License.
+#
+# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
+# or http://www.opensolaris.org/os/licensing.
+# See the License for the specific language governing permissions
+# and limitations under the License.
+#
+# When distributing Covered Code, include this CDDL HEADER in each
+# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
+# If applicable, add the following below this CDDL HEADER, with the
+# fields enclosed by brackets "[]" replaced with your own identifying
+# information: Portions Copyright [yyyy] [name of copyright owner]
+#
+# CDDL HEADER END
+#
+
+#
+# Copyright 2007 Sun Microsystems, Inc.  All rights reserved.
+# Use is subject to license terms.
+#
+
+#
+# Copyright (c) 2013 by Delphix. All rights reserved.
+#
+
+. $STF_SUITE/tests/functional/cli_user/misc/misc.cfg
+. $STF_SUITE/include/libtest.shlib
+
+#
+# DESCRIPTION:
+#
+# zfs inherit returns an error when run as a user
+#
+# STRATEGY:
+#
+# 1. Verify that we can't inherit a property when running as a user
+#
+#
+
+log_assert "zfs inherit returns an error when run as a user"
+log_mustnot $ZFS inherit snapdir $TESTPOOL/$TESTFS/$TESTFS2
+
+# check to see that the above command really did nothing
+PROP=$($ZFS get snapdir $TESTPOOL/$TESTFS)
+if [ "$PROP" = "visible" ]
+then
+       log_fail "snapdir property inherited from the $TESTPOOL/$TESTFS!"
+fi
+
+log_pass "zfs inherit returns an error when run as a user"
diff --git a/tests/zfs-tests/tests/functional/cli_user/misc/zfs_mount_001_neg.ksh b/tests/zfs-tests/tests/functional/cli_user/misc/zfs_mount_001_neg.ksh
new file mode 100755 (executable)
index 0000000..ecf3562
--- /dev/null
@@ -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.
+#
+
+#
+# Copyright (c) 2013 by Delphix. All rights reserved.
+#
+
+. $STF_SUITE/tests/functional/cli_user/misc/misc.cfg
+. $STF_SUITE/include/libtest.shlib
+
+#
+# DESCRIPTION:
+#
+# zfs mount returns an error when run as a user
+#
+# STRATEGY:
+#
+# 1. Verify that we can't mount the unmounted filesystem created in setup
+#
+#
+
+log_assert "zfs mount returns an error when run as a user"
+
+log_mustnot $ZFS mount $TESTPOOL/$TESTFS/$TESTFS2.unmounted
+
+# now verify that the above command didn't do anything
+MOUNTED=$($MOUNT | $GREP $TESTPOOL/$TESTFS/$TESTFS2.unmounted)
+if [ -n "$MOUNTED" ]
+then
+       log_fail "Filesystem $TESTPOOL/$TESTFS/$TESTFS2.unmounted was mounted!"
+fi
+
+log_pass "zfs mount returns an error when run as a user"
diff --git a/tests/zfs-tests/tests/functional/cli_user/misc/zfs_promote_001_neg.ksh b/tests/zfs-tests/tests/functional/cli_user/misc/zfs_promote_001_neg.ksh
new file mode 100755 (executable)
index 0000000..579ee93
--- /dev/null
@@ -0,0 +1,56 @@
+#!/bin/ksh -p
+#
+# CDDL HEADER START
+#
+# The contents of this file are subject to the terms of the
+# Common Development and Distribution License (the "License").
+# You may not use this file except in compliance with the License.
+#
+# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
+# or http://www.opensolaris.org/os/licensing.
+# See the License for the specific language governing permissions
+# and limitations under the License.
+#
+# When distributing Covered Code, include this CDDL HEADER in each
+# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
+# If applicable, add the following below this CDDL HEADER, with the
+# fields enclosed by brackets "[]" replaced with your own identifying
+# information: Portions Copyright [yyyy] [name of copyright owner]
+#
+# CDDL HEADER END
+#
+
+#
+# Copyright 2007 Sun Microsystems, Inc.  All rights reserved.
+# Use is subject to license terms.
+#
+
+#
+# Copyright (c) 2013 by Delphix. All rights reserved.
+#
+
+. $STF_SUITE/tests/functional/cli_user/misc/misc.cfg
+. $STF_SUITE/include/libtest.shlib
+
+#
+# DESCRIPTION:
+#
+# zfs promote returns an error when run as a user
+#
+# STRATEGY:
+#
+# 1. Verify we don't have permissions to promote a clone
+#
+#
+
+log_assert "zfs promote returns an error when run as a user"
+
+log_mustnot $ZFS promote $TESTPOOL/$TESTFS/clone
+
+# Now verify that the above command didn't do anything
+if datasetexists $TESTPOOL/$TESTFS/clone@snap
+then
+       log_fail "Clone $TESTPOOl/$TESTFS/clone was actually promoted!"
+fi
+
+log_pass "zfs promote returns an error when run as a user"
diff --git a/tests/zfs-tests/tests/functional/cli_user/misc/zfs_receive_001_neg.ksh b/tests/zfs-tests/tests/functional/cli_user/misc/zfs_receive_001_neg.ksh
new file mode 100755 (executable)
index 0000000..7ea4a47
--- /dev/null
@@ -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.
+#
+
+#
+# Copyright (c) 2013 by Delphix. All rights reserved.
+#
+
+. $STF_SUITE/tests/functional/cli_user/misc/misc.cfg
+. $STF_SUITE/include/libtest.shlib
+
+#
+# DESCRIPTION:
+#
+# zfs receive returns an error when run as a user
+#
+# STRATEGY:
+#
+# 1. Attempt to receive a datastream as a user
+# 2. Verify that the dataset wasn't created
+#
+
+log_assert "zfs receive returns an error when run as a user"
+
+log_mustnot eval "$ZFS receive -d $TESTPOOL/$TESTFS/$TESTFS2 \
+ < /tmp/zfstest_datastream.dat"
+
+# verify that command actually did nothing
+
+if datasetexists $TESTPOOL/$TESTFS/$TESTFS2/$TESTFS
+then
+       log_fail "$TESTPOOL/$TESTFS/$TESTFS2/$TESTFS was received!"
+fi
+
+log_pass "zfs receive returns an error when run as a user"
diff --git a/tests/zfs-tests/tests/functional/cli_user/misc/zfs_rename_001_neg.ksh b/tests/zfs-tests/tests/functional/cli_user/misc/zfs_rename_001_neg.ksh
new file mode 100755 (executable)
index 0000000..20b017f
--- /dev/null
@@ -0,0 +1,56 @@
+#!/bin/ksh -p
+#
+# CDDL HEADER START
+#
+# The contents of this file are subject to the terms of the
+# Common Development and Distribution License (the "License").
+# You may not use this file except in compliance with the License.
+#
+# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
+# or http://www.opensolaris.org/os/licensing.
+# See the License for the specific language governing permissions
+# and limitations under the License.
+#
+# When distributing Covered Code, include this CDDL HEADER in each
+# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
+# If applicable, add the following below this CDDL HEADER, with the
+# fields enclosed by brackets "[]" replaced with your own identifying
+# information: Portions Copyright [yyyy] [name of copyright owner]
+#
+# CDDL HEADER END
+#
+
+#
+# Copyright 2007 Sun Microsystems, Inc.  All rights reserved.
+# Use is subject to license terms.
+#
+
+#
+# Copyright (c) 2013 by Delphix. All rights reserved.
+#
+
+. $STF_SUITE/tests/functional/cli_user/misc/misc.cfg
+. $STF_SUITE/include/libtest.shlib
+
+#
+# DESCRIPTION:
+#
+# zfs rename returns an error when run as a user
+#
+# STRATEGY:
+# 1. Attempt to rename a dataset
+# 2. Verify that the renamed dataset does not exist.
+#
+#
+
+log_assert "zfs rename returns an error when run as a user"
+
+log_mustnot $ZFS rename $TESTPOOL/$TESTFS/renameme $TESTPOOL/$TESTFS/renameme1
+
+# now verify the above command didn't actually do anything
+if datasetexists $TESTPOOL/$TESTFS/renameme1
+then
+       log_fail "The dataset $TESTPOOL/$TESTFS/renameme was renamed!"
+fi
+
+log_pass "zfs rename returns an error when run as a user"
diff --git a/tests/zfs-tests/tests/functional/cli_user/misc/zfs_rollback_001_neg.ksh b/tests/zfs-tests/tests/functional/cli_user/misc/zfs_rollback_001_neg.ksh
new file mode 100755 (executable)
index 0000000..ecc95c1
--- /dev/null
@@ -0,0 +1,60 @@
+#!/bin/ksh -p
+#
+# CDDL HEADER START
+#
+# The contents of this file are subject to the terms of the
+# Common Development and Distribution License (the "License").
+# You may not use this file except in compliance with the License.
+#
+# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
+# or http://www.opensolaris.org/os/licensing.
+# See the License for the specific language governing permissions
+# and limitations under the License.
+#
+# When distributing Covered Code, include this CDDL HEADER in each
+# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
+# If applicable, add the following below this CDDL HEADER, with the
+# fields enclosed by brackets "[]" replaced with your own identifying
+# information: Portions Copyright [yyyy] [name of copyright owner]
+#
+# CDDL HEADER END
+#
+
+#
+# Copyright 2007 Sun Microsystems, Inc.  All rights reserved.
+# Use is subject to license terms.
+#
+
+#
+# Copyright (c) 2013 by Delphix. All rights reserved.
+#
+
+. $STF_SUITE/tests/functional/cli_user/misc/misc.cfg
+. $STF_SUITE/include/libtest.shlib
+
+#
+# DESCRIPTION:
+#
+# zfs rollback returns an error when run as a user
+#
+# STRATEGY:
+# 1. Attempt to rollback a snapshot
+# 2. Verify that a file which doesn't exist in the snapshot still exists
+#    (showing the snapshot rollback failed)
+#
+#
+
+log_assert "zfs rollback returns an error when run as a user"
+
+log_mustnot $ZFS rollback $TESTPOOL/$TESTFS@snap
+
+# now verify the above command didn't actually do anything
+
+# in the above filesystem there's a file that should not exist once
+# the snapshot is rolled back - we check for it
+if [ ! -e /$TESTDIR/file.txt ]
+then
+       log_fail "Rollback of snapshot $TESTPOOL/$TESTFS@snap succeeded!"
+fi
+
+log_pass "zfs rollback returns an error when run as a user"
diff --git a/tests/zfs-tests/tests/functional/cli_user/misc/zfs_send_001_neg.ksh b/tests/zfs-tests/tests/functional/cli_user/misc/zfs_send_001_neg.ksh
new file mode 100755 (executable)
index 0000000..0b92ed3
--- /dev/null
@@ -0,0 +1,67 @@
+#!/bin/ksh -p
+#
+# CDDL HEADER START
+#
+# The contents of this file are subject to the terms of the
+# Common Development and Distribution License (the "License").
+# You may not use this file except in compliance with the License.
+#
+# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
+# or http://www.opensolaris.org/os/licensing.
+# See the License for the specific language governing permissions
+# and limitations under the License.
+#
+# When distributing Covered Code, include this CDDL HEADER in each
+# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
+# If applicable, add the following below this CDDL HEADER, with the
+# fields enclosed by brackets "[]" replaced with your own identifying
+# information: Portions Copyright [yyyy] [name of copyright owner]
+#
+# CDDL HEADER END
+#
+
+#
+# Copyright 2007 Sun Microsystems, Inc.  All rights reserved.
+# Use is subject to license terms.
+#
+
+#
+# Copyright (c) 2013 by Delphix. All rights reserved.
+#
+
+. $STF_SUITE/tests/functional/cli_user/misc/misc.cfg
+. $STF_SUITE/include/libtest.shlib
+
+#
+# DESCRIPTION:
+#
+# zfs send returns an error when run as a user
+#
+# STRATEGY:
+# 1. Attempt to send a dataset to a file
+# 2. Verify the file created has zero-size
+#
+#
+
+function cleanup
+{
+       if [ -e /tmp/zfstest_datastream.$$ ]
+       then
+               log_must $RM /tmp/zfstest_datastream.$$
+       fi
+}
+
+log_assert "zfs send returns an error when run as a user"
+log_onexit cleanup
+
+log_mustnot eval "$ZFS send $TESTPOOL/$TESTFS@snap > /tmp/zfstest_datastream.$$"
+
+# Now check that the above command actually did nothing
+
+# We should have a non-zero-length file in /tmp
+if [ -s /tmp/zfstest_datastream.$$ ]
+then
+       log_fail "A zfs send file was created in /tmp/zfstest_datastream.$$ !"
+fi
+
+log_pass "zfs send returns an error when run as a user"
diff --git a/tests/zfs-tests/tests/functional/cli_user/misc/zfs_set_001_neg.ksh b/tests/zfs-tests/tests/functional/cli_user/misc/zfs_set_001_neg.ksh
new file mode 100755 (executable)
index 0000000..1f1a8bd
--- /dev/null
@@ -0,0 +1,70 @@
+#!/bin/ksh -p
+#
+# CDDL HEADER START
+#
+# The contents of this file are subject to the terms of the
+# Common Development and Distribution License (the "License").
+# You may not use this file except in compliance with the License.
+#
+# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
+# or http://www.opensolaris.org/os/licensing.
+# See the License for the specific language governing permissions
+# and limitations under the License.
+#
+# When distributing Covered Code, include this CDDL HEADER in each
+# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
+# If applicable, add the following below this CDDL HEADER, with the
+# fields enclosed by brackets "[]" replaced with your own identifying
+# information: Portions Copyright [yyyy] [name of copyright owner]
+#
+# CDDL HEADER END
+#
+
+#
+# Copyright 2007 Sun Microsystems, Inc.  All rights reserved.
+# Use is subject to license terms.
+#
+
+#
+# Copyright (c) 2013 by Delphix. All rights reserved.
+#
+
+. $STF_SUITE/tests/functional/cli_user/misc/misc.cfg
+. $STF_SUITE/include/libtest.shlib
+
+#
+# DESCRIPTION:
+#
+# zfs set returns an error when run as a user
+#
+# STRATEGY:
+# 1. Attempt to set an array of properties on a dataset
+# 2. Verify that those properties were not set and retain their original values.
+#
+#
+
+log_assert "zfs set returns an error when run as a user"
+
+typeset -i i=0
+
+set -A props $PROP_NAMES
+set -A prop_vals $PROP_VALS
+set -A prop_new $PROP_ALTVALS
+
+while [[ $i -lt ${#args[*]} ]]
+do
+       PROP=${props[$i]}
+       EXPECTED=${prop_vals[$i]}
+       NEW=${prop_new[$i]}
+       log_mustnot $ZFS set $PROP=$NEW $TESTPOOL/$TESTFS/prop
+
+       # Now verify that the above command did nothing
+       ACTUAL=$($ZFS get $PROP -o value -H snapdir $TESTPOOl/$TESTFS/prop )
+       if [ "$ACTUAL" != "$EXPECTED" ]
+       then
+               log_fail "Property $PROP was set to $ACTUAL, expected $EXPECTED"
+       fi
+        i=$(( $i + 1 ))
+done
+
+log_pass "zfs set returns an error when run as a user"
diff --git a/tests/zfs-tests/tests/functional/cli_user/misc/zfs_share_001_neg.ksh b/tests/zfs-tests/tests/functional/cli_user/misc/zfs_share_001_neg.ksh
new file mode 100755 (executable)
index 0000000..0f45f50
--- /dev/null
@@ -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 2008 Sun Microsystems, Inc.  All rights reserved.
+# Use is subject to license terms.
+#
+
+#
+# Copyright (c) 2013 by Delphix. All rights reserved.
+#
+
+. $STF_SUITE/tests/functional/cli_user/misc/misc.cfg
+. $STF_SUITE/include/libtest.shlib
+
+#
+# DESCRIPTION:
+#
+# zfs share returns an error when run as a user
+#
+# STRATEGY:
+# 1. Attempt to share a dataset
+# 2. Verify the dataset was not shared.
+#
+#
+
+verify_runnable "global"
+
+log_assert "zfs share returns an error when run as a user"
+
+if is_shared $TESTDIR/unshared
+then
+       log_fail "$TESTPOOL/$TESTFS/unshared was incorrectly shared initially!"
+fi
+
+log_mustnot $ZFS share $TESTPOOL/$TESTFS/unshared
+
+# Now verify that the above command didn't actually do anything
+if is_shared $TESTDIR/unshared
+then
+       log_fail "$TESTPOOL/$TESTFS/unshared was actually shared!"
+fi
+
+log_pass "zfs share returns an error when run as a user"
diff --git a/tests/zfs-tests/tests/functional/cli_user/misc/zfs_snapshot_001_neg.ksh b/tests/zfs-tests/tests/functional/cli_user/misc/zfs_snapshot_001_neg.ksh
new file mode 100755 (executable)
index 0000000..f473c5e
--- /dev/null
@@ -0,0 +1,56 @@
+#!/bin/ksh -p
+#
+# CDDL HEADER START
+#
+# The contents of this file are subject to the terms of the
+# Common Development and Distribution License (the "License").
+# You may not use this file except in compliance with the License.
+#
+# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
+# or http://www.opensolaris.org/os/licensing.
+# See the License for the specific language governing permissions
+# and limitations under the License.
+#
+# When distributing Covered Code, include this CDDL HEADER in each
+# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
+# If applicable, add the following below this CDDL HEADER, with the
+# fields enclosed by brackets "[]" replaced with your own identifying
+# information: Portions Copyright [yyyy] [name of copyright owner]
+#
+# CDDL HEADER END
+#
+
+#
+# Copyright 2007 Sun Microsystems, Inc.  All rights reserved.
+# Use is subject to license terms.
+#
+
+#
+# Copyright (c) 2013 by Delphix. All rights reserved.
+#
+
+. $STF_SUITE/tests/functional/cli_user/misc/misc.cfg
+. $STF_SUITE/include/libtest.shlib
+
+#
+# DESCRIPTION:
+#
+# zfs snapshot returns an error when run as a user
+#
+# STRATEGY:
+# 1. Attempt to snapshot a dataset
+# 2. Verify the snapshot wasn't taken
+#
+#
+
+log_assert "zfs snapshot returns an error when run as a user"
+
+log_mustnot $ZFS snapshot $TESTPOOL/$TESTFS@usersnap1
+
+# Now verify that the above command didn't actually do anything
+if datasetexists $TESTPOOL/$TESTFS@usersnap1
+then
+       log_fail "Snapshot $TESTPOOL/$TESTFS@usersnap1 was taken !"
+fi
+
+log_pass "zfs snapshot returns an error when run as a user"
diff --git a/tests/zfs-tests/tests/functional/cli_user/misc/zfs_unallow_001_neg.ksh b/tests/zfs-tests/tests/functional/cli_user/misc/zfs_unallow_001_neg.ksh
new file mode 100755 (executable)
index 0000000..84dc938
--- /dev/null
@@ -0,0 +1,64 @@
+#!/bin/ksh -p
+#
+# CDDL HEADER START
+#
+# The contents of this file are subject to the terms of the
+# Common Development and Distribution License (the "License").
+# You may not use this file except in compliance with the License.
+#
+# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
+# or http://www.opensolaris.org/os/licensing.
+# See the License for the specific language governing permissions
+# and limitations under the License.
+#
+# When distributing Covered Code, include this CDDL HEADER in each
+# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
+# If applicable, add the following below this CDDL HEADER, with the
+# fields enclosed by brackets "[]" replaced with your own identifying
+# information: Portions Copyright [yyyy] [name of copyright owner]
+#
+# CDDL HEADER END
+#
+
+#
+# Copyright 2008 Sun Microsystems, Inc.  All rights reserved.
+# Use is subject to license terms.
+#
+
+#
+# Copyright (c) 2013 by Delphix. All rights reserved.
+#
+
+. $STF_SUITE/tests/functional/cli_user/misc/misc.cfg
+. $STF_SUITE/include/libtest.shlib
+
+#
+# DESCRIPTION:
+#
+# zfs unallow returns an error when run as a user
+#
+# STRATEGY:
+# 1. Attempt to unallow a set of permissions
+# 2. Verify the unallow wasn't performed
+#
+#
+
+# check to see if we have zfs unallow
+$ZFS 2>&1 | $GREP "unallow" > /dev/null
+if (($? != 0)) then
+        log_unsupported "ZFS unallow not supported on this machine."
+fi
+
+log_assert "zfs unallow returns an error when run as a user"
+
+log_mustnot $ZFS unallow everyone $TESTPOOL/$TESTFS/allowed
+
+# now check with zfs allow to see if the permissions are still there
+OUTPUT=$($ZFS allow $TESTPOOL/$TESTFS/allowed | $GREP "Local+Descendent" )
+if [ -z "$OUTPUT" ]
+then
+       log_fail "Error - create permissions were unallowed on \
+       $TESTPOOL/$TESTFS/allowed"
+fi
+
+log_pass "zfs unallow returns an error when run as a user"
diff --git a/tests/zfs-tests/tests/functional/cli_user/misc/zfs_unmount_001_neg.ksh b/tests/zfs-tests/tests/functional/cli_user/misc/zfs_unmount_001_neg.ksh
new file mode 100755 (executable)
index 0000000..22a3d75
--- /dev/null
@@ -0,0 +1,65 @@
+#!/bin/ksh -p
+#
+# CDDL HEADER START
+#
+# The contents of this file are subject to the terms of the
+# Common Development and Distribution License (the "License").
+# You may not use this file except in compliance with the License.
+#
+# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
+# or http://www.opensolaris.org/os/licensing.
+# See the License for the specific language governing permissions
+# and limitations under the License.
+#
+# When distributing Covered Code, include this CDDL HEADER in each
+# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
+# If applicable, add the following below this CDDL HEADER, with the
+# fields enclosed by brackets "[]" replaced with your own identifying
+# information: Portions Copyright [yyyy] [name of copyright owner]
+#
+# CDDL HEADER END
+#
+
+#
+# Copyright 2007 Sun Microsystems, Inc.  All rights reserved.
+# Use is subject to license terms.
+#
+
+#
+# Copyright (c) 2013 by Delphix. All rights reserved.
+#
+
+. $STF_SUITE/tests/functional/cli_user/misc/misc.cfg
+. $STF_SUITE/include/libtest.shlib
+
+#
+# DESCRIPTION:
+# Verify that 'zfs umount' and its variants fail as non-root.
+#
+# STRATEGY:
+# 1. Create an array of options.
+# 2. Execute each element of the array.
+# 3. Verify that the commands fail with an error code.
+#
+
+verify_runnable "both"
+
+set -A args "umount" "umount -f" "unmount" "unmount -f" \
+    "umount $TESTPOOL/$TESTFS" "umount -f $TESTPOOL/$TESTFS" \
+    "unmount $TESTPOOL/$TESTFS" "unmount -f $TESTPOOL/$TESTFS" \
+    "umount $TESTPOOL/$TESTFS@$TESTSNAP" \
+    "umount -f $TESTPOOL/$TESTFS@$TESTSNAP" \
+    "unmount $TESTPOOL/$TESTFS@$TESTSNAP" \
+    "unmount -f $TESTPOOL/$TESTFS@$TESTSNAP" \
+    "umount $TESTDIR" "umount -f $TESTDIR" \
+    "unmount $TESTDIR" "unmount -f $TESTDIR"
+
+log_assert "zfs u[n]mount [-f] [mountpoint|fs|snap]"
+
+typeset -i i=0
+while [[ $i -lt ${#args[*]} ]]; do
+       log_mustnot $ZFS ${args[i]}
+       ((i = i + 1))
+done
+
+log_pass "The sub-command 'u[n]mount' fails as non-root."
diff --git a/tests/zfs-tests/tests/functional/cli_user/misc/zfs_unshare_001_neg.ksh b/tests/zfs-tests/tests/functional/cli_user/misc/zfs_unshare_001_neg.ksh
new file mode 100755 (executable)
index 0000000..069279c
--- /dev/null
@@ -0,0 +1,64 @@
+#!/bin/ksh -p
+#
+# CDDL HEADER START
+#
+# The contents of this file are subject to the terms of the
+# Common Development and Distribution License (the "License").
+# You may not use this file except in compliance with the License.
+#
+# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
+# or http://www.opensolaris.org/os/licensing.
+# See the License for the specific language governing permissions
+# and limitations under the License.
+#
+# When distributing Covered Code, include this CDDL HEADER in each
+# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
+# If applicable, add the following below this CDDL HEADER, with the
+# fields enclosed by brackets "[]" replaced with your own identifying
+# information: Portions Copyright [yyyy] [name of copyright owner]
+#
+# CDDL HEADER END
+#
+
+#
+# Copyright 2008 Sun Microsystems, Inc.  All rights reserved.
+# Use is subject to license terms.
+#
+
+#
+# Copyright (c) 2013 by Delphix. All rights reserved.
+#
+
+. $STF_SUITE/tests/functional/cli_user/misc/misc.cfg
+. $STF_SUITE/include/libtest.shlib
+
+#
+# DESCRIPTION:
+#
+# zfs unshare returns an error when run as a user
+#
+# STRATEGY:
+# 1. Attempt to unshare a shared dataset
+# 2. Verify the dataset is still shared
+#
+#
+
+verify_runnable "global"
+
+log_assert "zfs unshare returns an error when run as a user"
+
+#  verify that the filesystem was shared initially
+if not_shared $TESTDIR/shared
+then
+       log_fail "$TESTPOOL/$TESTFS/shared was not shared initially at all!"
+fi
+
+log_mustnot $ZFS unshare $TESTPOOL/$TESTFS/shared
+
+# now verify that the above command didn't do anything
+if not_shared $TESTDIR/shared
+then
+       log_fail "$TESTPOOL/$TESTFS/shared was actually unshared!"
+fi
+
+log_pass "zfs unshare returns an error when run as a user"
diff --git a/tests/zfs-tests/tests/functional/cli_user/misc/zfs_upgrade_001_neg.ksh b/tests/zfs-tests/tests/functional/cli_user/misc/zfs_upgrade_001_neg.ksh
new file mode 100755 (executable)
index 0000000..0053871
--- /dev/null
@@ -0,0 +1,67 @@
+#!/bin/ksh -p
+#
+# CDDL HEADER START
+#
+# The contents of this file are subject to the terms of the
+# Common Development and Distribution License (the "License").
+# You may not use this file except in compliance with the License.
+#
+# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
+# or http://www.opensolaris.org/os/licensing.
+# See the License for the specific language governing permissions
+# and limitations under the License.
+#
+# When distributing Covered Code, include this CDDL HEADER in each
+# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
+# If applicable, add the following below this CDDL HEADER, with the
+# fields enclosed by brackets "[]" replaced with your own identifying
+# information: Portions Copyright [yyyy] [name of copyright owner]
+#
+# CDDL HEADER END
+#
+
+#
+# Copyright 2007 Sun Microsystems, Inc.  All rights reserved.
+# Use is subject to license terms.
+#
+
+#
+# Copyright (c) 2013 by Delphix. All rights reserved.
+#
+
+. $STF_SUITE/tests/functional/cli_user/misc/misc.cfg
+. $STF_SUITE/include/libtest.shlib
+
+#
+# DESCRIPTION:
+#
+# zfs upgrade returns an error when run as a user
+#
+# STRATEGY:
+# 1. Attempt to upgrade a version1 dataset
+# 2. Verify the dataset wasn't upgraded
+#
+#
+
+# check to see if we have upgrade capability
+$ZFS upgrade > /dev/null 2>&1
+HAS_UPGRADE=$?
+if [ $HAS_UPGRADE -ne 0 ]
+then
+       log_unsupported "Zfs upgrade not supported"
+fi
+
+log_assert "zfs upgrade returns an error when run as a user"
+
+
+log_mustnot $ZFS upgrade $TESTPOOL/$TESTFS/version1
+
+# now check to see the above command didn't do anything
+VERSION=$($ZFS upgrade $TESTPOOL/$TESTFS/version1 2>&1 \
+        | $GREP "already at this version")
+if [ -n "$VERSION" ]
+then
+       log_fail "A filesystem was upgraded!"
+fi
+
+log_pass "zfs upgrade returns an error when run as a user"
diff --git a/tests/zfs-tests/tests/functional/cli_user/misc/zpool_001_neg.ksh b/tests/zfs-tests/tests/functional/cli_user/misc/zpool_001_neg.ksh
new file mode 100755 (executable)
index 0000000..447fc97
--- /dev/null
@@ -0,0 +1,60 @@
+#!/bin/ksh -p
+#
+# CDDL HEADER START
+#
+# The contents of this file are subject to the terms of the
+# Common Development and Distribution License (the "License").
+# You may not use this file except in compliance with the License.
+#
+# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
+# or http://www.opensolaris.org/os/licensing.
+# See the License for the specific language governing permissions
+# and limitations under the License.
+#
+# When distributing Covered Code, include this CDDL HEADER in each
+# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
+# If applicable, add the following below this CDDL HEADER, with the
+# fields enclosed by brackets "[]" replaced with your own identifying
+# information: Portions Copyright [yyyy] [name of copyright owner]
+#
+# CDDL HEADER END
+#
+
+#
+# Copyright 2007 Sun Microsystems, Inc.  All rights reserved.
+# Use is subject to license terms.
+#
+
+#
+# Copyright (c) 2013 by Delphix. All rights reserved.
+#
+
+. $STF_SUITE/tests/functional/cli_user/misc/misc.cfg
+. $STF_SUITE/include/libtest.shlib
+
+#
+# DESCRIPTION:
+#
+# zpool shows a usage message when run as a user
+#
+# STRATEGY:
+# 1. Run the zpool command
+# 2. Verify that a usage message is produced
+#
+#
+
+function cleanup
+{
+       if [ -e /tmp/zpool_001_neg.$$.txt ]
+       then
+               $RM /tmp/zpool_001_neg.$$.txt
+       fi
+}
+
+log_onexit cleanup
+log_assert "zpool shows a usage message when run as a user"
+
+eval "$ZPOOL > /tmp/zpool_001_neg.$$.txt 2>&1"
+log_must $GREP "usage: zpool command args" /tmp/zpool_001_neg.$$.txt
+
+log_pass "zpool shows a usage message when run as a user"
diff --git a/tests/zfs-tests/tests/functional/cli_user/misc/zpool_add_001_neg.ksh b/tests/zfs-tests/tests/functional/cli_user/misc/zpool_add_001_neg.ksh
new file mode 100755 (executable)
index 0000000..d02dd0b
--- /dev/null
@@ -0,0 +1,69 @@
+#!/bin/ksh -p
+
+# CDDL HEADER START
+#
+# The contents of this file are subject to the terms of the
+# Common Development and Distribution License (the "License").
+# You may not use this file except in compliance with the License.
+#
+# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
+# or http://www.opensolaris.org/os/licensing.
+# See the License for the specific language governing permissions
+# and limitations under the License.
+#
+# When distributing Covered Code, include this CDDL HEADER in each
+# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
+# If applicable, add the following below this CDDL HEADER, with the
+# fields enclosed by brackets "[]" replaced with your own identifying
+# information: Portions Copyright [yyyy] [name of copyright owner]
+#
+# CDDL HEADER END
+#
+
+#
+# Copyright 2009 Sun Microsystems, Inc.  All rights reserved.
+# Use is subject to license terms.
+#
+
+#
+# Copyright (c) 2013 by Delphix. All rights reserved.
+#
+
+. $STF_SUITE/tests/functional/cli_user/misc/misc.cfg
+. $STF_SUITE/include/libtest.shlib
+
+#
+# DESCRIPTION:
+# Verify that 'zpool add' fails as non-root.
+#
+# STRATEGY:
+# 1. Create an array of options.
+# 2. Execute each element of the array.
+# 3. Verify that an error is returned.
+#
+
+verify_runnable "global"
+
+ADD_DISK="${DISKS%% }"
+ADD_DISK="${ADD_DISK##* }"
+
+[[ -z $ADD_DISK ]] && \
+        log_fail "No spare disks available."
+
+set -A args "add" "add -f" "add -n" \
+    "add $TESTPOOL" "add -f $TESTPOOL" "add -n $TESTPOOL" \
+    "add -fn $TESTPOOL" "add -nf $TESTPOOL" \
+    "add $TESTPOOL $ADD_DISK" "add -f $TESTPOOL $ADD_DISK" \
+    "add -n $TESTPOOL $ADD_DISK" \
+    "add -fn $TESTPOOL $ADD_DISK" \
+    "add -nf $TESTPOOL $ADD_DISK" \
+
+log_assert "zpool add [-fn] pool_name vdev"
+
+typeset -i i=0
+while [[ $i -lt ${#args[*]} ]]; do
+       log_mustnot $ZPOOL ${args[i]}
+       ((i = i + 1))
+done
+
+log_pass "The sub-command 'add' and its options fail as non-root."
diff --git a/tests/zfs-tests/tests/functional/cli_user/misc/zpool_attach_001_neg.ksh b/tests/zfs-tests/tests/functional/cli_user/misc/zpool_attach_001_neg.ksh
new file mode 100755 (executable)
index 0000000..59254ea
--- /dev/null
@@ -0,0 +1,67 @@
+#!/bin/ksh -p
+#
+# CDDL HEADER START
+#
+# The contents of this file are subject to the terms of the
+# Common Development and Distribution License (the "License").
+# You may not use this file except in compliance with the License.
+#
+# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
+# or http://www.opensolaris.org/os/licensing.
+# See the License for the specific language governing permissions
+# and limitations under the License.
+#
+# When distributing Covered Code, include this CDDL HEADER in each
+# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
+# If applicable, add the following below this CDDL HEADER, with the
+# fields enclosed by brackets "[]" replaced with your own identifying
+# information: Portions Copyright [yyyy] [name of copyright owner]
+#
+# CDDL HEADER END
+#
+
+#
+# Copyright 2007 Sun Microsystems, Inc.  All rights reserved.
+# Use is subject to license terms.
+#
+
+#
+# Copyright (c) 2013 by Delphix. All rights reserved.
+#
+
+. $STF_SUITE/tests/functional/cli_user/misc/misc.cfg
+. $STF_SUITE/include/libtest.shlib
+
+#
+# DESCRIPTION:
+#
+# zpool attach returns an error when run as a user
+#
+# STRATEGY:
+# 1. Attempt to attach a disk to a pool
+# 2.Verify that the attach failed
+#
+#
+
+function check_for_attach
+{
+       RESULT=$($ZPOOL status -v $TESTPOOL.virt | $GREP disk-additional.dat)
+       if [ -n "$RESULT" ]
+       then
+               log_fail "A disk was attached to the pool!"
+       fi
+}
+
+verify_runnable "global"
+
+log_assert "zpool attach returns an error when run as a user"
+
+log_mustnot $ZPOOL attach $TESTPOOL.virt /$TESTDIR/disk1.dat \
+       /$TESTDIR/disk-additional.dat
+check_for_attach
+
+log_mustnot $ZPOOL attach -f $TESTPOOL.virt /$TESTDIR/disk1.dat \
+        /$TESTDIR/disk-additional.dat
+check_for_attach
+
+log_pass "zpool attach returns an error when run as a user"
diff --git a/tests/zfs-tests/tests/functional/cli_user/misc/zpool_clear_001_neg.ksh b/tests/zfs-tests/tests/functional/cli_user/misc/zpool_clear_001_neg.ksh
new file mode 100755 (executable)
index 0000000..0a6bb8c
--- /dev/null
@@ -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.
+#
+
+#
+# Copyright (c) 2013 by Delphix. All rights reserved.
+#
+
+. $STF_SUITE/tests/functional/cli_user/misc/misc.cfg
+. $STF_SUITE/include/libtest.shlib
+
+#
+# DESCRIPTION:
+#
+# zpool clear returns an error when run as a user
+#
+# STRATEGY:
+#
+# 1. Attempt to clear errors on a zpool
+# 2. Verify that the command fails
+#
+
+verify_runnable "global"
+
+log_assert "zpool clear returns an error when run as a user"
+
+log_mustnot $ZPOOL clear $TESTPOOL
+
+log_pass "zpool clear returns an error when run as a user"
diff --git a/tests/zfs-tests/tests/functional/cli_user/misc/zpool_create_001_neg.ksh b/tests/zfs-tests/tests/functional/cli_user/misc/zpool_create_001_neg.ksh
new file mode 100755 (executable)
index 0000000..f77df30
--- /dev/null
@@ -0,0 +1,69 @@
+#!/bin/ksh -p
+#
+# CDDL HEADER START
+#
+# The contents of this file are subject to the terms of the
+# Common Development and Distribution License (the "License").
+# You may not use this file except in compliance with the License.
+#
+# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
+# or http://www.opensolaris.org/os/licensing.
+# See the License for the specific language governing permissions
+# and limitations under the License.
+#
+# When distributing Covered Code, include this CDDL HEADER in each
+# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
+# If applicable, add the following below this CDDL HEADER, with the
+# fields enclosed by brackets "[]" replaced with your own identifying
+# information: Portions Copyright [yyyy] [name of copyright owner]
+#
+# CDDL HEADER END
+#
+
+#
+# Copyright 2009 Sun Microsystems, Inc.  All rights reserved.
+# Use is subject to license terms.
+#
+
+#
+# Copyright (c) 2013 by Delphix. All rights reserved.
+#
+
+. $STF_SUITE/tests/functional/cli_user/misc/misc.cfg
+. $STF_SUITE/include/libtest.shlib
+
+#
+# DESCRIPTION:
+# Verify that 'zpool create' fails as a non-root user.
+#
+# STRATEGY:
+# 1. Create an array of options.
+# 2. Execute each element of the array.
+# 3. Verify that an error is returned.
+#
+
+verify_runnable "global"
+
+ADD_DISK="${DISKS%% }"
+ADD_DISK="${ADD_DISK##* }"
+
+[[ -z $ADD_DISK ]] && \
+        log_fail "No spare disks available."
+
+set -A args "create" "create -f" "create -n" \
+    "create $TESTPOOL" "create -f $TESTPOOL" "create -n $TESTPOOL" \
+    "create -fn $TESTPOOL" "create -nf $TESTPOOL" \
+    "create $TESTPOOL $ADD_DISK" "create -f $TESTPOOL $ADD_DISK" \
+    "create -n $TESTPOOL $ADD_DISK" \
+    "create -fn $TESTPOOL $ADD_DISK" \
+    "create -nf $TESTPOOL $ADD_DISK"
+
+log_assert "zpool create [-fn] pool_name vdev"
+
+typeset -i i=0
+while [[ $i -lt ${#args[*]} ]]; do
+       log_mustnot $ZPOOL ${args[i]}
+       ((i = i + 1))
+done
+
+log_pass "The sub-command 'create' and its options fail as non-root."
diff --git a/tests/zfs-tests/tests/functional/cli_user/misc/zpool_destroy_001_neg.ksh b/tests/zfs-tests/tests/functional/cli_user/misc/zpool_destroy_001_neg.ksh
new file mode 100755 (executable)
index 0000000..8d28f70
--- /dev/null
@@ -0,0 +1,59 @@
+#!/bin/ksh -p
+#
+# CDDL HEADER START
+#
+# The contents of this file are subject to the terms of the
+# Common Development and Distribution License (the "License").
+# You may not use this file except in compliance with the License.
+#
+# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
+# or http://www.opensolaris.org/os/licensing.
+# See the License for the specific language governing permissions
+# and limitations under the License.
+#
+# When distributing Covered Code, include this CDDL HEADER in each
+# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
+# If applicable, add the following below this CDDL HEADER, with the
+# fields enclosed by brackets "[]" replaced with your own identifying
+# information: Portions Copyright [yyyy] [name of copyright owner]
+#
+# CDDL HEADER END
+#
+
+#
+# Copyright 2007 Sun Microsystems, Inc.  All rights reserved.
+# Use is subject to license terms.
+#
+
+#
+# Copyright (c) 2013 by Delphix. All rights reserved.
+#
+
+. $STF_SUITE/tests/functional/cli_user/misc/misc.cfg
+. $STF_SUITE/include/libtest.shlib
+
+#
+# DESCRIPTION:
+# Verify that 'zpool destroy' fails as non-root.
+#
+# STRATEGY:
+# 1. Create an array of options.
+# 2. Execute each element of the array.
+# 3. Verify an error is returned.
+#
+
+verify_runnable "global"
+
+set -A args "destroy" "destroy -f" \
+    "destroy $TESTPOOL" "destroy -f $TESTPOOL" \
+    "destroy $TESTPOOL $TESTPOOL"
+
+log_assert "zpool destroy [-f] [pool_name ...]"
+
+typeset -i i=0
+while [[ $i -lt ${#args[*]} ]]; do
+       log_mustnot $ZPOOL ${args[i]}
+       ((i = i + 1))
+done
+
+log_pass "The sub-command 'destroy' and its options fail as non-root."
diff --git a/tests/zfs-tests/tests/functional/cli_user/misc/zpool_detach_001_neg.ksh b/tests/zfs-tests/tests/functional/cli_user/misc/zpool_detach_001_neg.ksh
new file mode 100755 (executable)
index 0000000..849308d
--- /dev/null
@@ -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.
+#
+
+#
+# Copyright (c) 2013 by Delphix. All rights reserved.
+#
+
+. $STF_SUITE/tests/functional/cli_user/misc/misc.cfg
+. $STF_SUITE/include/libtest.shlib
+
+#
+# DESCRIPTION:
+#
+# zpool detach returns an error when run as a user
+#
+# STRATEGY:
+#
+# 1. Attempt to detach a device from a pool
+# 2. Verify the command fails
+#
+
+verify_runnable "global"
+
+log_assert "zpool detach returns an error when run as a user"
+
+log_mustnot $ZPOOL detach $TESTPOOL.virt /$TESTDIR/disk1.dat
+
+RESULT=$($ZPOOL status -v $TESTPOOL.virt | $GREP disk1.dat)
+if [ -z "$RESULT" ]
+then
+       log_fail "A disk was detached from the pool!"
+fi
+
+log_pass "zpool detach returns an error when run as a user"
diff --git a/tests/zfs-tests/tests/functional/cli_user/misc/zpool_export_001_neg.ksh b/tests/zfs-tests/tests/functional/cli_user/misc/zpool_export_001_neg.ksh
new file mode 100755 (executable)
index 0000000..6d44be7
--- /dev/null
@@ -0,0 +1,65 @@
+#!/bin/ksh -p
+#
+# CDDL HEADER START
+#
+# The contents of this file are subject to the terms of the
+# Common Development and Distribution License (the "License").
+# You may not use this file except in compliance with the License.
+#
+# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
+# or http://www.opensolaris.org/os/licensing.
+# See the License for the specific language governing permissions
+# and limitations under the License.
+#
+# When distributing Covered Code, include this CDDL HEADER in each
+# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
+# If applicable, add the following below this CDDL HEADER, with the
+# fields enclosed by brackets "[]" replaced with your own identifying
+# information: Portions Copyright [yyyy] [name of copyright owner]
+#
+# CDDL HEADER END
+#
+
+#
+# Copyright 2007 Sun Microsystems, Inc.  All rights reserved.
+# Use is subject to license terms.
+#
+
+#
+# Copyright (c) 2013 by Delphix. All rights reserved.
+#
+
+. $STF_SUITE/tests/functional/cli_user/misc/misc.cfg
+. $STF_SUITE/include/libtest.shlib
+
+#
+# DESCRIPTION:
+#
+# zpool export returns an error when run as a user
+#
+# STRATEGY:
+# 1. Attempt to export a pool
+# 2. Verify the command fails
+#
+
+function check_for_export
+{
+       RESULT=$($ZPOOL list | $GREP $TESTPOOL.virt )
+       if [ -z "$RESULT" ]
+       then
+               log_fail "A pool was exported!"
+       fi
+
+}
+
+verify_runnable "global"
+
+log_assert "zpool export returns an error when run as a user"
+
+log_mustnot $ZPOOL export $TESTPOOL.virt
+check_for_export
+
+log_mustnot $ZPOOL export -f $TESTPOOL.virt
+check_for_export
+
+log_pass "zpool export returns an error when run as a user"
diff --git a/tests/zfs-tests/tests/functional/cli_user/misc/zpool_get_001_neg.ksh b/tests/zfs-tests/tests/functional/cli_user/misc/zpool_get_001_neg.ksh
new file mode 100755 (executable)
index 0000000..6965a58
--- /dev/null
@@ -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 2008 Sun Microsystems, Inc.  All rights reserved.
+# Use is subject to license terms.
+#
+
+#
+# Copyright (c) 2013 by Delphix. All rights reserved.
+#
+
+. $STF_SUITE/tests/functional/cli_user/misc/misc.cfg
+. $STF_SUITE/include/libtest.shlib
+
+#
+# DESCRIPTION:
+#
+# zpool get works when run as a user
+#
+# STRATEGY:
+#
+# 1. For each property, get that property
+# 2. Verify the property was the same as that set in setup
+#
+
+verify_runnable "global"
+
+log_assert "zpool get works when run as a user"
+
+set -A props $POOL_PROPS
+set -A prop_vals $POOL_VALS
+
+while [[ $i -lt ${#args[*]} ]]
+do
+       PROP=${props[$i]}
+       EXPECTED=${prop_vals[$i]}
+       ACTUAL=$( $ZPOOL get $PROP $TESTPOOL | $GREP $PROP | $AWK '{print $1}' )
+       if [ "$ACTUAL" != "$EXPECTED" ]
+       then
+               log_fail "Property $PROP value was $ACTUAL, expected $EXPECTED"
+       fi
+        i=$(( $i + 1 ))
+done
+
+log_must $ZPOOL get all $TESTPOOL
+
+log_pass "zpool get works when run as a user"
diff --git a/tests/zfs-tests/tests/functional/cli_user/misc/zpool_history_001_neg.ksh b/tests/zfs-tests/tests/functional/cli_user/misc/zpool_history_001_neg.ksh
new file mode 100755 (executable)
index 0000000..b29d083
--- /dev/null
@@ -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.
+#
+
+#
+# Copyright (c) 2013 by Delphix. All rights reserved.
+#
+
+. $STF_SUITE/tests/functional/cli_user/misc/misc.cfg
+. $STF_SUITE/include/libtest.shlib
+
+#
+# DESCRIPTION:
+#
+# zpool history works when run as a user
+#
+# STRATEGY:
+# 1. Attempt to get history on a test pool
+# 2. Verify the command fails
+#
+
+verify_runnable "global"
+
+log_assert "zpool history returns an error when run as a user"
+
+log_mustnot $ZPOOL history
+log_mustnot $ZPOOL history $TESTPOOL
+log_mustnot $ZPOOL history -i $TESTPOOL
+log_mustnot $ZPOOL history -l $TESTPOOL
+log_mustnot $ZPOOL history -il $TESTPOOL
+
+log_assert "zpool history returns an error when run as a user"
diff --git a/tests/zfs-tests/tests/functional/cli_user/misc/zpool_import_001_neg.ksh b/tests/zfs-tests/tests/functional/cli_user/misc/zpool_import_001_neg.ksh
new file mode 100755 (executable)
index 0000000..c73c12f
--- /dev/null
@@ -0,0 +1,66 @@
+#!/bin/ksh -p
+#
+# CDDL HEADER START
+#
+# The contents of this file are subject to the terms of the
+# Common Development and Distribution License (the "License").
+# You may not use this file except in compliance with the License.
+#
+# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
+# or http://www.opensolaris.org/os/licensing.
+# See the License for the specific language governing permissions
+# and limitations under the License.
+#
+# When distributing Covered Code, include this CDDL HEADER in each
+# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
+# If applicable, add the following below this CDDL HEADER, with the
+# fields enclosed by brackets "[]" replaced with your own identifying
+# information: Portions Copyright [yyyy] [name of copyright owner]
+#
+# CDDL HEADER END
+#
+
+#
+# Copyright 2007 Sun Microsystems, Inc.  All rights reserved.
+# Use is subject to license terms.
+#
+
+#
+# Copyright (c) 2013 by Delphix. All rights reserved.
+#
+
+. $STF_SUITE/tests/functional/cli_user/misc/misc.cfg
+. $STF_SUITE/include/libtest.shlib
+
+#
+# DESCRIPTION:
+#
+# zpool import returns an error when run as a user
+#
+# STRATEGY:
+# 1. Attempt to import an exported pool
+# 2. Verify the command fails
+#
+#
+
+function check_for_import
+{
+       RESULT=$($ZPOOL list -H -o name | $GREP $TESTPOOL.exported)
+       if [ -n "$RESULT" ]
+       then
+               log_fail "Pool $TESTPOOL.export was successfully imported!"
+       fi
+}
+
+verify_runnable "global"
+
+log_assert "zpool import returns an error when run as a user"
+log_mustnot $ZPOOL import
+
+log_mustnot $ZPOOL import -a
+check_for_import
+
+log_mustnot $ZPOOL import -d /$TESTDIR $TESTPOOL.exported
+check_for_import
+
+log_pass "zpool import returns an error when run as a user"
diff --git a/tests/zfs-tests/tests/functional/cli_user/misc/zpool_import_002_neg.ksh b/tests/zfs-tests/tests/functional/cli_user/misc/zpool_import_002_neg.ksh
new file mode 100755 (executable)
index 0000000..011cd1c
--- /dev/null
@@ -0,0 +1,64 @@
+#!/bin/ksh -p
+#
+# CDDL HEADER START
+#
+# The contents of this file are subject to the terms of the
+# Common Development and Distribution License (the "License").
+# You may not use this file except in compliance with the License.
+#
+# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
+# or http://www.opensolaris.org/os/licensing.
+# See the License for the specific language governing permissions
+# and limitations under the License.
+#
+# When distributing Covered Code, include this CDDL HEADER in each
+# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
+# If applicable, add the following below this CDDL HEADER, with the
+# fields enclosed by brackets "[]" replaced with your own identifying
+# information: Portions Copyright [yyyy] [name of copyright owner]
+#
+# CDDL HEADER END
+#
+
+#
+# Copyright 2007 Sun Microsystems, Inc.  All rights reserved.
+# Use is subject to license terms.
+#
+
+#
+# Copyright (c) 2013 by Delphix. All rights reserved.
+#
+
+. $STF_SUITE/tests/functional/cli_user/misc/misc.cfg
+. $STF_SUITE/include/libtest.shlib
+
+#
+# DESCRIPTION:
+# Executing 'zpool import' as regular user should denied.
+#
+# STRATEGY:
+# 1. Create an array of options try to detect exported/destroyed pools.
+# 2. Execute 'zpool import' with each element of the array by regular user.
+# 3. Verify an error code is returned.
+#
+
+verify_runnable "both"
+
+typeset testpool
+if is_global_zone ; then
+        testpool=$TESTPOOL.exported
+else
+        testpool=${TESTPOOL%%/*}
+fi
+
+set -A args "" "-D" "-Df" "-f" "-f $TESTPOOL" "-Df $TESTPOOL" "-a"
+
+log_assert "Executing 'zpool import' by regular user fails"
+
+typeset -i i=0
+while [[ $i -lt ${#args[*]} ]]; do
+       log_mustnot $ZPOOL import ${args[i]}
+       ((i = i + 1))
+done
+
+log_pass "Executing 'zpool import' by regular user fails as expected."
diff --git a/tests/zfs-tests/tests/functional/cli_user/misc/zpool_offline_001_neg.ksh b/tests/zfs-tests/tests/functional/cli_user/misc/zpool_offline_001_neg.ksh
new file mode 100755 (executable)
index 0000000..6fa03c4
--- /dev/null
@@ -0,0 +1,66 @@
+#!/bin/ksh -p
+#
+# CDDL HEADER START
+#
+# The contents of this file are subject to the terms of the
+# Common Development and Distribution License (the "License").
+# You may not use this file except in compliance with the License.
+#
+# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
+# or http://www.opensolaris.org/os/licensing.
+# See the License for the specific language governing permissions
+# and limitations under the License.
+#
+# When distributing Covered Code, include this CDDL HEADER in each
+# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
+# If applicable, add the following below this CDDL HEADER, with the
+# fields enclosed by brackets "[]" replaced with your own identifying
+# information: Portions Copyright [yyyy] [name of copyright owner]
+#
+# CDDL HEADER END
+#
+
+#
+# Copyright 2007 Sun Microsystems, Inc.  All rights reserved.
+# Use is subject to license terms.
+#
+
+#
+# Copyright (c) 2013 by Delphix. All rights reserved.
+#
+
+. $STF_SUITE/tests/functional/cli_user/misc/misc.cfg
+. $STF_SUITE/include/libtest.shlib
+
+#
+# DESCRIPTION:
+#
+# zpool offline returns an error when run as a user
+#
+# STRATEGY:
+# 1. Attempt to offline a device in a pool
+# 2. Verify that the command fails
+#
+#
+
+function check_for_offline
+{
+       RESULT=$($ZPOOL status -v $TESTPOOL.virt | $GREP disk-1.dat \
+                | $GREP OFFLINE )
+       if [ -n "$RESULT" ]
+       then
+               log_fail "A disk was taken offline!"
+       fi
+}
+
+verify_runnable "global"
+
+log_assert "zpool offline returns an error when run as a user"
+
+log_mustnot $ZPOOL offline $TESTPOOL.virt /$TESTDIR/disk-1.dat
+check_for_offline
+
+log_mustnot $ZPOOL offline -t $TESTPOOL.virt /$TESTDIR/disk-1.dat
+check_for_offline
+
+log_pass "zpool offline returns an error when run as a user"
diff --git a/tests/zfs-tests/tests/functional/cli_user/misc/zpool_online_001_neg.ksh b/tests/zfs-tests/tests/functional/cli_user/misc/zpool_online_001_neg.ksh
new file mode 100755 (executable)
index 0000000..db886eb
--- /dev/null
@@ -0,0 +1,66 @@
+#!/bin/ksh -p
+#
+# CDDL HEADER START
+#
+# The contents of this file are subject to the terms of the
+# Common Development and Distribution License (the "License").
+# You may not use this file except in compliance with the License.
+#
+# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
+# or http://www.opensolaris.org/os/licensing.
+# See the License for the specific language governing permissions
+# and limitations under the License.
+#
+# When distributing Covered Code, include this CDDL HEADER in each
+# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
+# If applicable, add the following below this CDDL HEADER, with the
+# fields enclosed by brackets "[]" replaced with your own identifying
+# information: Portions Copyright [yyyy] [name of copyright owner]
+#
+# CDDL HEADER END
+#
+
+#
+# Copyright 2007 Sun Microsystems, Inc.  All rights reserved.
+# Use is subject to license terms.
+#
+
+#
+# Copyright (c) 2013 by Delphix. All rights reserved.
+#
+
+. $STF_SUITE/tests/functional/cli_user/misc/misc.cfg
+. $STF_SUITE/include/libtest.shlib
+
+#
+# DESCRIPTION:
+#
+# zpool online returns an error when run as a user
+#
+# STRATEGY:
+# 1. Attempt to online a device in a pool
+# 2. Verify the command fails
+#
+#
+
+function check_for_online
+{
+       RESULT=$($ZPOOL status -v $TESTPOOL.virt | $GREP disk-offline.dat \
+                | $GREP ONLINE )
+       if [ -n "$RESULT" ]
+       then
+               log_fail "A disk was brough online!"
+       fi
+}
+
+verify_runnable "global"
+
+log_assert "zpool online returns an error when run as a user"
+
+log_mustnot $ZPOOL online $TESTPOOL.virt /$TESTDIR/disk-offline.dat
+check_for_online
+
+log_mustnot $ZPOOL online -t $TESTPOOL.virt /$TESTDIR/disk-offline.dat
+check_for_online
+
+log_pass "zpool online returns an error when run as a user"
diff --git a/tests/zfs-tests/tests/functional/cli_user/misc/zpool_remove_001_neg.ksh b/tests/zfs-tests/tests/functional/cli_user/misc/zpool_remove_001_neg.ksh
new file mode 100755 (executable)
index 0000000..7e93bc0
--- /dev/null
@@ -0,0 +1,59 @@
+#!/bin/ksh -p
+#
+# CDDL HEADER START
+#
+# The contents of this file are subject to the terms of the
+# Common Development and Distribution License (the "License").
+# You may not use this file except in compliance with the License.
+#
+# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
+# or http://www.opensolaris.org/os/licensing.
+# See the License for the specific language governing permissions
+# and limitations under the License.
+#
+# When distributing Covered Code, include this CDDL HEADER in each
+# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
+# If applicable, add the following below this CDDL HEADER, with the
+# fields enclosed by brackets "[]" replaced with your own identifying
+# information: Portions Copyright [yyyy] [name of copyright owner]
+#
+# CDDL HEADER END
+#
+
+#
+# Copyright 2007 Sun Microsystems, Inc.  All rights reserved.
+# Use is subject to license terms.
+#
+
+#
+# Copyright (c) 2013 by Delphix. All rights reserved.
+#
+
+. $STF_SUITE/tests/functional/cli_user/misc/misc.cfg
+. $STF_SUITE/include/libtest.shlib
+
+#
+# DESCRIPTION:
+#
+# zpool remove returns an error when run as a user
+#
+# STRATEGY:
+# 1. Attempt to remove a device from a pool
+# 2. Verify the command fails
+#
+#
+
+verify_runnable "global"
+
+log_assert "zpool remove returns an error when run as a user"
+
+log_mustnot $ZPOOL remove $TESTPOOL.virt /$TESTDIR/disk-spare1.dat
+
+RESULT=$($ZPOOL status -v $TESTPOOL.virt | $GREP disk-spare1.dat)
+if [ -z "$RESULT" ]
+then
+       log_fail "A disk was removed from the pool!"
+fi
+
+
+log_pass "zpool remove returns an error when run as a user"
diff --git a/tests/zfs-tests/tests/functional/cli_user/misc/zpool_replace_001_neg.ksh b/tests/zfs-tests/tests/functional/cli_user/misc/zpool_replace_001_neg.ksh
new file mode 100755 (executable)
index 0000000..12576bf
--- /dev/null
@@ -0,0 +1,68 @@
+#!/bin/ksh -p
+#
+# CDDL HEADER START
+#
+# The contents of this file are subject to the terms of the
+# Common Development and Distribution License (the "License").
+# You may not use this file except in compliance with the License.
+#
+# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
+# or http://www.opensolaris.org/os/licensing.
+# See the License for the specific language governing permissions
+# and limitations under the License.
+#
+# When distributing Covered Code, include this CDDL HEADER in each
+# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
+# If applicable, add the following below this CDDL HEADER, with the
+# fields enclosed by brackets "[]" replaced with your own identifying
+# information: Portions Copyright [yyyy] [name of copyright owner]
+#
+# CDDL HEADER END
+#
+
+#
+# Copyright 2007 Sun Microsystems, Inc.  All rights reserved.
+# Use is subject to license terms.
+#
+
+#
+# Copyright (c) 2013 by Delphix. All rights reserved.
+#
+
+. $STF_SUITE/tests/functional/cli_user/misc/misc.cfg
+. $STF_SUITE/include/libtest.shlib
+
+#
+# DESCRIPTION:
+#
+# zpool replace returns an error when run as a user
+#
+# STRATEGY:
+# 1. Attempt to replace a device in a pool
+# 2. Verify the command fails
+#
+#
+
+function check_for_replace
+{
+       $SLEEP 10
+       RESULT=$($ZPOOL status -v $TESTPOOL.virt | $GREP disk-additional.dat)
+       if [ -n "$RESULT" ]
+       then
+               log_fail "A disk was replaced in the pool!"
+       fi
+}
+
+verify_runnable "global"
+
+log_assert "zpool replace returns an error when run as a user"
+
+log_mustnot $ZPOOL replace $TESTPOOL.virt /$TESTDIR/disk-1.dat \
+        /$TESTDIR/disk-additional.dat
+check_for_replace
+
+log_mustnot $ZPOOL replace -f $TESTPOOL.virt /$TESTDIR/disk-1.dat \
+ /$TESTDIR/disk-additional.dat
+check_for_replace
+
+log_pass "zpool replace returns an error when run as a user"
diff --git a/tests/zfs-tests/tests/functional/cli_user/misc/zpool_scrub_001_neg.ksh b/tests/zfs-tests/tests/functional/cli_user/misc/zpool_scrub_001_neg.ksh
new file mode 100755 (executable)
index 0000000..abbdcd6
--- /dev/null
@@ -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) 2013 by Delphix. All rights reserved.
+#
+
+. $STF_SUITE/tests/functional/cli_user/misc/misc.cfg
+. $STF_SUITE/include/libtest.shlib
+
+#
+# DESCRIPTION:
+#
+# zpool scrub returns an error when run as a user
+#
+# STRATEGY:
+# 1. Attempt to start a scrub on a pool
+# 2. Verify the command fails
+#
+#
+
+verify_runnable "global"
+
+log_assert "zpool scrub returns an error when run as a user"
+
+log_mustnot $ZPOOL scrub $TESTPOOL
+log_mustnot $ZPOOL scrub -s $TESTPOOL
+
+log_pass "zpool scrub returns an error when run as a user"
diff --git a/tests/zfs-tests/tests/functional/cli_user/misc/zpool_set_001_neg.ksh b/tests/zfs-tests/tests/functional/cli_user/misc/zpool_set_001_neg.ksh
new file mode 100755 (executable)
index 0000000..e353d2d
--- /dev/null
@@ -0,0 +1,71 @@
+#!/bin/ksh -p
+#
+# CDDL HEADER START
+#
+# The contents of this file are subject to the terms of the
+# Common Development and Distribution License (the "License").
+# You may not use this file except in compliance with the License.
+#
+# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
+# or http://www.opensolaris.org/os/licensing.
+# See the License for the specific language governing permissions
+# and limitations under the License.
+#
+# When distributing Covered Code, include this CDDL HEADER in each
+# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
+# If applicable, add the following below this CDDL HEADER, with the
+# fields enclosed by brackets "[]" replaced with your own identifying
+# information: Portions Copyright [yyyy] [name of copyright owner]
+#
+# CDDL HEADER END
+#
+
+#
+# Copyright 2007 Sun Microsystems, Inc.  All rights reserved.
+# Use is subject to license terms.
+#
+
+#
+# Copyright (c) 2013 by Delphix. All rights reserved.
+#
+
+. $STF_SUITE/tests/functional/cli_user/misc/misc.cfg
+. $STF_SUITE/include/libtest.shlib
+
+#
+# DESCRIPTION:
+#
+# zpool set returns an error when run as a user
+#
+# STRATEGY:
+# 1. Attempt to set some properties on a pool
+# 2. Verify the command fails
+#
+#
+
+verify_runnable "global"
+
+log_assert "zpool set returns an error when run as a user"
+
+set -A props $POOL_NAMES
+set -A prop_vals $POOL_VALS
+set -A prop_new $POOL_ALTVALS
+
+while [[ $i -lt ${#args[*]} ]]
+do
+       PROP=${props[$i]}
+       EXPECTED=${prop_vals[$i]}
+       NEW=${prop_new[$i]}
+       log_mustnot $POOL set $PROP=$NEW $TESTPOOL
+
+       # Now verify that the above command did nothing
+       ACTUAL=$( $ZPOOL get $PROP $TESTPOOL | $GREP $PROP | $AWK '{print $1}' )
+       if [ "$ACTUAL" != "$EXPECTED" ]
+       then
+               log_fail "Property $PROP was set to $ACTUAL, expected $EXPECTED"
+       fi
+        i=$(( $i + 1 ))
+done
+
+
+log_pass "zpool set returns an error when run as a user"
diff --git a/tests/zfs-tests/tests/functional/cli_user/misc/zpool_status_001_neg.ksh b/tests/zfs-tests/tests/functional/cli_user/misc/zpool_status_001_neg.ksh
new file mode 100755 (executable)
index 0000000..54806b5
--- /dev/null
@@ -0,0 +1,76 @@
+#!/bin/ksh -p
+#
+# CDDL HEADER START
+#
+# The contents of this file are subject to the terms of the
+# Common Development and Distribution License (the "License").
+# You may not use this file except in compliance with the License.
+#
+# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
+# or http://www.opensolaris.org/os/licensing.
+# See the License for the specific language governing permissions
+# and limitations under the License.
+#
+# When distributing Covered Code, include this CDDL HEADER in each
+# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
+# If applicable, add the following below this CDDL HEADER, with the
+# fields enclosed by brackets "[]" replaced with your own identifying
+# information: Portions Copyright [yyyy] [name of copyright owner]
+#
+# CDDL HEADER END
+#
+
+#
+# Copyright 2007 Sun Microsystems, Inc.  All rights reserved.
+# Use is subject to license terms.
+#
+
+#
+# Copyright (c) 2013 by Delphix. All rights reserved.
+#
+
+. $STF_SUITE/tests/functional/cli_user/misc/misc.cfg
+. $STF_SUITE/include/libtest.shlib
+
+#
+# DESCRIPTION:
+#
+# zpool status works when run as a user
+#
+# STRATEGY:
+#
+# 1. Run zpool status as a user
+# 2. Verify we get output
+#
+
+function check_pool_status
+{
+       RESULT=$($GREP "pool:" /tmp/pool-status.$$)
+       if [ -z "$RESULT" ]
+       then
+               log_fail "No pool: string found in zpool status output!"
+       fi
+       $RM /tmp/pool-status.$$
+}
+
+verify_runnable "global"
+
+log_assert "zpool status works when run as a user"
+
+log_must eval "$ZPOOL status > /tmp/pool-status.$$"
+check_pool_status
+
+log_must eval "$ZPOOL status -v > /tmp/pool-status.$$"
+check_pool_status
+
+log_must eval "$ZPOOL status $TESTPOOL> /tmp/pool-status.$$"
+check_pool_status
+
+log_must eval "$ZPOOL status -v $TESTPOOL > /tmp/pool-status.$$"
+check_pool_status
+
+# $TESTPOOL.virt has an offline device, so -x will show it
+log_must eval "$ZPOOL status -x $TESTPOOL.virt > /tmp/pool-status.$$"
+check_pool_status
+
+log_pass "zpool status works when run as a user"
diff --git a/tests/zfs-tests/tests/functional/cli_user/misc/zpool_upgrade_001_neg.ksh b/tests/zfs-tests/tests/functional/cli_user/misc/zpool_upgrade_001_neg.ksh
new file mode 100755 (executable)
index 0000000..2dc02b7
--- /dev/null
@@ -0,0 +1,65 @@
+#!/bin/ksh -p
+#
+# CDDL HEADER START
+#
+# The contents of this file are subject to the terms of the
+# Common Development and Distribution License (the "License").
+# You may not use this file except in compliance with the License.
+#
+# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
+# or http://www.opensolaris.org/os/licensing.
+# See the License for the specific language governing permissions
+# and limitations under the License.
+#
+# When distributing Covered Code, include this CDDL HEADER in each
+# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
+# If applicable, add the following below this CDDL HEADER, with the
+# fields enclosed by brackets "[]" replaced with your own identifying
+# information: Portions Copyright [yyyy] [name of copyright owner]
+#
+# CDDL HEADER END
+#
+
+#
+# Copyright 2007 Sun Microsystems, Inc.  All rights reserved.
+# Use is subject to license terms.
+#
+
+#
+# Copyright (c) 2013 by Delphix. All rights reserved.
+#
+
+. $STF_SUITE/tests/functional/cli_user/misc/misc.cfg
+. $STF_SUITE/include/libtest.shlib
+
+#
+# DESCRIPTION:
+#
+# zpool upgrade returns an error when run as a user
+#
+# STRATEGY:
+#
+# 1. Attempt to upgrade a pool
+# 2. Verify the command fails
+#
+
+verify_runnable "global"
+
+log_assert "zpool upgrade returns an error when run as a user"
+
+log_onexit cleanup
+# zpool upgrade returns 0 when it can't do anything
+log_must $ZPOOL upgrade $TESTPOOL.virt
+
+# Now try to upgrade our version 1 pool
+log_mustnot $ZPOOL upgrade v1-pool
+
+# if the pool has been upgraded, then v1-pool won't be listed in the output
+# of zpool upgrade anymore
+RESULT=$($ZPOOL upgrade | $GREP v1-pool)
+if [ -z "$RESULT" ]
+then
+       log_fail "A pool was upgraded successfully!"
+fi
+
+log_pass "zpool upgrade returns an error when run as a user"
diff --git a/tests/zfs-tests/tests/functional/cli_user/zfs_list/Makefile.am b/tests/zfs-tests/tests/functional/cli_user/zfs_list/Makefile.am
new file mode 100644 (file)
index 0000000..34390af
--- /dev/null
@@ -0,0 +1,12 @@
+pkgdatadir = $(datadir)/@PACKAGE@/zfs-tests/tests/functional/cli_user/zfs_list
+dist_pkgdata_SCRIPTS = \
+       zfs_list.cfg \
+       zfs_list.kshlib \
+       setup.ksh \
+       cleanup.ksh \
+       zfs_list_001_pos.ksh \
+       zfs_list_002_pos.ksh \
+       zfs_list_003_pos.ksh \
+       zfs_list_004_neg.ksh \
+       zfs_list_007_pos.ksh \
+       zfs_list_008_neg.ksh
diff --git a/tests/zfs-tests/tests/functional/cli_user/zfs_list/cleanup.ksh b/tests/zfs-tests/tests/functional/cli_user/zfs_list/cleanup.ksh
new file mode 100755 (executable)
index 0000000..115e00c
--- /dev/null
@@ -0,0 +1,36 @@
+#!/bin/ksh -p
+#
+# CDDL HEADER START
+#
+# The contents of this file are subject to the terms of the
+# Common Development and Distribution License (the "License").
+# You may not use this file except in compliance with the License.
+#
+# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
+# or http://www.opensolaris.org/os/licensing.
+# See the License for the specific language governing permissions
+# and limitations under the License.
+#
+# When distributing Covered Code, include this CDDL HEADER in each
+# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
+# If applicable, add the following below this CDDL HEADER, with the
+# fields enclosed by brackets "[]" replaced with your own identifying
+# information: Portions Copyright [yyyy] [name of copyright owner]
+#
+# CDDL HEADER END
+#
+
+#
+# Copyright 2009 Sun Microsystems, Inc.  All rights reserved.
+# Use is subject to license terms.
+#
+
+#
+# Copyright (c) 2013 by Delphix. All rights reserved.
+#
+
+. $STF_SUITE/include/libtest.shlib
+. $STF_SUITE/tests/functional/cli_root/zfs_get/zfs_get_list_d.kshlib
+
+depth_fs_cleanup
+default_cleanup
diff --git a/tests/zfs-tests/tests/functional/cli_user/zfs_list/setup.ksh b/tests/zfs-tests/tests/functional/cli_user/zfs_list/setup.ksh
new file mode 100755 (executable)
index 0000000..66bcc06
--- /dev/null
@@ -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 2009 Sun Microsystems, Inc.  All rights reserved.
+# Use is subject to license terms.
+#
+
+#
+# Copyright (c) 2013 by Delphix. All rights reserved.
+#
+
+. $STF_SUITE/include/libtest.shlib
+. $STF_SUITE/tests/functional/cli_root/zfs_get/zfs_get_list_d.kshlib
+. $STF_SUITE/tests/functional/cli_user/zfs_list/zfs_list.cfg
+
+DISK=${DISKS%% *}
+
+default_setup_noexit $DISK
+
+# create datasets and set checksum options
+set -A cksumarray $CKSUMOPTS
+typeset -i index=0
+for dataset in $DATASETS
+do
+       log_must $ZFS create $TESTPOOL/$TESTFS/$dataset
+       $SLEEP 1
+        log_must $ZFS snapshot $TESTPOOL/$TESTFS/${dataset}@snap
+
+       $SLEEP 1
+       if is_global_zone ; then
+               log_must $ZFS create -V 64M $TESTPOOL/$TESTFS/${dataset}-vol
+               $SLEEP 1
+               log_must $ZFS snapshot $TESTPOOL/$TESTFS/${dataset}-vol@snap
+       fi
+
+       # sleep to ensure that the datasets have different creation dates
+       $SLEEP 1
+       log_must $ZFS set checksum=${cksumarray[$index]} \
+               $TESTPOOL/$TESTFS/$dataset
+       if datasetexists $TESTPOOL/$TESTFS/${dataset}-vol; then
+               log_must $ZFS set checksum=${cksumarray[$index]} \
+                       $TESTPOOL/$TESTFS/${dataset}-vol
+       fi
+
+        index=$((index + 1))
+done
+
+depth_fs_setup
+
+log_pass
diff --git a/tests/zfs-tests/tests/functional/cli_user/zfs_list/zfs_list.cfg b/tests/zfs-tests/tests/functional/cli_user/zfs_list/zfs_list.cfg
new file mode 100644 (file)
index 0000000..59f367c
--- /dev/null
@@ -0,0 +1,35 @@
+#
+# CDDL HEADER START
+#
+# The contents of this file are subject to the terms of the
+# Common Development and Distribution License (the "License").
+# You may not use this file except in compliance with the License.
+#
+# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
+# or http://www.opensolaris.org/os/licensing.
+# See the License for the specific language governing permissions
+# and limitations under the License.
+#
+# When distributing Covered Code, include this CDDL HEADER in each
+# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
+# If applicable, add the following below this CDDL HEADER, with the
+# fields enclosed by brackets "[]" replaced with your own identifying
+# information: Portions Copyright [yyyy] [name of copyright owner]
+#
+# CDDL HEADER END
+#
+
+#
+# Copyright 2007 Sun Microsystems, Inc.  All rights reserved.
+# Use is subject to license terms.
+#
+
+#
+# Copyright (c) 2013 by Delphix. All rights reserved.
+#
+
+# Datasets (in order of creation date) and which checksum options
+# we want to set for each dataset.
+# These are used by various zfs list tests
+export DATASETS="Apple Banana Carrot Orange apple banana carrot"
+export CKSUMOPTS="on sha256 sha256 sha256 fletcher4 off fletcher2"
diff --git a/tests/zfs-tests/tests/functional/cli_user/zfs_list/zfs_list.kshlib b/tests/zfs-tests/tests/functional/cli_user/zfs_list/zfs_list.kshlib
new file mode 100644 (file)
index 0000000..e64739d
--- /dev/null
@@ -0,0 +1,118 @@
+#
+# CDDL HEADER START
+#
+# The contents of this file are subject to the terms of the
+# Common Development and Distribution License (the "License").
+# You may not use this file except in compliance with the License.
+#
+# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
+# or http://www.opensolaris.org/os/licensing.
+# See the License for the specific language governing permissions
+# and limitations under the License.
+#
+# When distributing Covered Code, include this CDDL HEADER in each
+# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
+# If applicable, add the following below this CDDL HEADER, with the
+# fields enclosed by brackets "[]" replaced with your own identifying
+# information: Portions Copyright [yyyy] [name of copyright owner]
+#
+# CDDL HEADER END
+#
+
+#
+# Copyright 2008 Sun Microsystems, Inc.  All rights reserved.
+# Use is subject to license terms.
+#
+
+#
+# Copyright (c) 2013 by Delphix. All rights reserved.
+#
+
+. $STF_SUITE/include/libtest.shlib
+
+#
+# A function that verifies sort order. It takes as input
+# a command, which gets executed. We then iterate over the results
+# comparing that the sort order passed in via the list
+#
+function verify_sort { # command list name
+
+       # now verify we've sorted by creation date:
+       typeset CMD=$1
+       typeset list=$2
+       typeset name=$3
+
+       typeset -i RET=0
+       typeset -i index=1
+
+       # run the command to verify that it works
+       log_must eval "$CMD > /dev/null"
+
+       # Now check the sort order
+       for dataset in $( $CMD )
+       do
+               ACTUAL=$(basename $dataset)
+               if [ "$dataset" != "$TESTPOOL/$TESTFS" ]
+               then
+                       EXPECTED=$($ECHO $list | $AWK "{print \$$index}")
+                       if [ "$ACTUAL" != "$EXPECTED" ]
+                       then
+                               log_note "WARNING:" \
+                                       "'$ACTUAL' does not equal '$EXPECTED'"
+                               log_fail "ERROR: Sort by $name fails."
+                       fi
+
+                       ((index = index + 1))
+               fi
+       done
+
+       # finally check to see if we have the expected number of elements
+       if [ $index -ne $($ECHO $list | $AWK '{print split($0,arr)+1}') ]
+       then
+               log_fail "Warning: " \
+                       "unexpected number of filesystems found in list output!"
+       fi
+}
+
+# A function that verifies reverse sort order. It takes as input
+# a command, which gets executed. We then iterate over the results
+# comparing that the sort order passed in via the list
+#
+function verify_reverse_sort { # command list name
+
+       typeset CMD=$1
+       typeset list=$2
+       typeset name=$3
+
+       # set our index to the be number of elements in the list
+       typeset -i index=$($ECHO $list | $AWK '{print split($0,arr)}')
+
+       log_note "Checking reverse sort by '$name'," \
+               "expecting the reverse of '$list'"
+       log_must eval "$CMD > /dev/null"
+
+       for dataset in $( $CMD )
+       do
+               ACTUAL=$(basename $dataset)
+               if [ "$dataset" != "$TESTPOOL/$TESTFS" ]
+               then
+                       EXPECTED=$($ECHO $list | $AWK "{print \$$index}")
+                       if [ "$ACTUAL" != "$EXPECTED" ]
+                       then
+                               log_note "Warning:" \
+                                       "'$ACTUAL' does not equal to" \
+                                       "the reverse of '$EXPECTED'"
+                               log_fail "ERROR: Reverse sort by '$name' fails."
+                       fi
+
+                       ((index = index - 1))
+               fi
+       done
+
+       # finally check to see if we have the expected number of elements
+       if [ $index -ne 0 ]
+       then
+               log_fail "Warning: " \
+                       "unexpected number of filesystems found in list output!"
+       fi
+}
diff --git a/tests/zfs-tests/tests/functional/cli_user/zfs_list/zfs_list_001_pos.ksh b/tests/zfs-tests/tests/functional/cli_user/zfs_list/zfs_list_001_pos.ksh
new file mode 100755 (executable)
index 0000000..b0af4eb
--- /dev/null
@@ -0,0 +1,116 @@
+#!/bin/ksh -p
+#
+# CDDL HEADER START
+#
+# The contents of this file are subject to the terms of the
+# Common Development and Distribution License (the "License").
+# You may not use this file except in compliance with the License.
+#
+# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
+# or http://www.opensolaris.org/os/licensing.
+# See the License for the specific language governing permissions
+# and limitations under the License.
+#
+# When distributing Covered Code, include this CDDL HEADER in each
+# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
+# If applicable, add the following below this CDDL HEADER, with the
+# fields enclosed by brackets "[]" replaced with your own identifying
+# information: Portions Copyright [yyyy] [name of copyright owner]
+#
+# CDDL HEADER END
+#
+
+#
+# Copyright 2009 Sun Microsystems, Inc.  All rights reserved.
+# Use is subject to license terms.
+#
+
+#
+# Copyright (c) 2013 by Delphix. All rights reserved.
+#
+
+. $STF_SUITE/include/libtest.shlib
+. $STF_SUITE/tests/functional/cli_root/zfs_get/zfs_get_list_d.kshlib
+
+#
+# DESCRIPTION:
+# Executing well-formed 'zfs list' commands should return success.
+#
+# STRATEGY:
+# 1. Create an array of valid options.
+# 2. Execute each element in the array.
+# 3. Verify success is returned.
+#
+
+verify_runnable "both"
+
+set -A args "list" "list -r" "list -H" \
+        "list $TESTPOOL/$TESTFS" \
+        "list -r $TESTPOOL/$TESTFS" "list -H $TESTPOOL/$TESTFS" \
+        "list -rH $TESTPOOL/$TESTFS" "list -Hr $TESTPOOL/$TESTFS" \
+        "list -o name $TESTPOOL/$TESTFS" "list -r -o name $TESTPOOL/$TESTFS" \
+        "list -H -o name $TESTPOOL/$TESTFS" "list -rH -o name $TESTPOOL/$TESTFS" \
+        "list -Hr -o name $TESTPOOL/$TESTFS"
+
+set -A d_args " " "-r" "-H" \
+        "$TESTPOOL/$TESTFS" \
+        "-r $TESTPOOL/$TESTFS" "-H $TESTPOOL/$TESTFS" \
+        "-rH $TESTPOOL/$TESTFS" "-Hr $TESTPOOL/$TESTFS" \
+        "-o name $TESTPOOL/$TESTFS" "-r -o name $TESTPOOL/$TESTFS" \
+        "-H -o name $TESTPOOL/$TESTFS" "-rH -o name $TESTPOOL/$TESTFS" \
+        "-Hr -o name $TESTPOOL/$TESTFS"
+
+typeset -i m=${#args[*]}
+typeset -i n=0
+typeset -i k=0
+while (( n<${#depth_options[*]} ));
+do
+       (( k=0 ))
+       while (( k<${#d_args[*]} ));
+       do
+               args[$m]="list"" -${depth_options[$n]}"" ${d_args[$k]}"
+               (( k+=1 ))
+               (( m+=1 ))
+       done
+       (( n+=1 ))
+done
+
+set -A pathargs "list -r $TESTDIR" "list -H $TESTDIR" \
+       "list -r ./../$TESTDIR" "list -H ./../$TESTDIR"
+
+set -A d_pathargs " $TESTDIR" "-r $TESTDIR" "-H $TESTDIR" \
+       "-r ./../$TESTDIR" "-H ./../$TESTDIR"
+
+(( m=${#pathargs[*]} ))
+(( n=0 ))
+(( k=0 ))
+while (( n<${#depth_options[*]} ));
+do
+       (( k=0 ))
+       while (( k<${#d_pathargs[*]} ));
+       do
+               pathargs[$m]="list"" -${depth_options[$n]}"" ${d_pathargs[$k]}"
+               (( k+=1 ))
+               (( m+=1 ))
+       done
+       (( n+=1 ))
+done
+
+log_assert "Verify 'zfs list [-rH] [-o property[,prop]*] [fs|clct|vol]'."
+
+typeset -i i=0
+while [[ $i -lt ${#args[*]} ]]; do
+       log_must eval "$ZFS ${args[i]} > /dev/null"
+       ((i = i + 1))
+done
+
+# Verify 'zfs list <path>' will succeed on absolute or relative path.
+
+cd /tmp
+typeset -i i=0
+while [[ $i -lt ${#pathargs[*]} ]]; do
+       log_must eval "$ZFS ${pathargs[i]} > /dev/null"
+       ((i = i + 1))
+done
+
+log_pass "The sub-command 'list' succeeds as non-root."
diff --git a/tests/zfs-tests/tests/functional/cli_user/zfs_list/zfs_list_002_pos.ksh b/tests/zfs-tests/tests/functional/cli_user/zfs_list/zfs_list_002_pos.ksh
new file mode 100755 (executable)
index 0000000..3d546ec
--- /dev/null
@@ -0,0 +1,176 @@
+#!/bin/ksh -p
+#
+# CDDL HEADER START
+#
+# The contents of this file are subject to the terms of the
+# Common Development and Distribution License (the "License").
+# You may not use this file except in compliance with the License.
+#
+# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
+# or http://www.opensolaris.org/os/licensing.
+# See the License for the specific language governing permissions
+# and limitations under the License.
+#
+# When distributing Covered Code, include this CDDL HEADER in each
+# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
+# If applicable, add the following below this CDDL HEADER, with the
+# fields enclosed by brackets "[]" replaced with your own identifying
+# information: Portions Copyright [yyyy] [name of copyright owner]
+#
+# CDDL HEADER END
+#
+
+#
+# Copyright 2008 Sun Microsystems, Inc.  All rights reserved.
+# Use is subject to license terms.
+#
+
+#
+# Copyright (c) 2013 by Delphix. All rights reserved.
+#
+
+. $STF_SUITE/tests/functional/cli_user/zfs_list/zfs_list.kshlib
+
+#
+# DESCRIPTION:
+# The sort functionality in 'zfs list' works as expected.
+#
+# STRATEGY:
+# 1. Using several zfs datasets with names, creation dates, checksum options
+# 2. Sort the datasets by name, checksum options, creation date.
+# 3. Verify that the datasets are sorted correctly.
+#
+
+verify_runnable "both"
+
+# datasets ordered by name
+fs_name="Apple Banana Carrot Orange apple banana carrot"
+vol_name="Apple-vol Banana-vol Carrot-vol Orange-vol apple-vol"
+vol_name="$vol_name banana-vol carrot-vol"
+if is_global_zone ; then
+       snap_name="Apple-vol@snap Apple@snap Banana-vol@snap Banana@snap"
+       snap_name="$snap_name Carrot-vol@snap Carrot@snap Orange-vol@snap Orange@snap"
+       snap_name="$snap_name apple-vol@snap apple@snap banana-vol@snap banana@snap"
+       snap_name="$snap_name carrot-vol@snap carrot@snap"
+else
+       snap_name="Apple@snap Banana@snap"
+       snap_name="$snap_name Carrot@snap Orange@snap"
+       snap_name="$snap_name apple@snap banana@snap"
+       snap_name="$snap_name carrot@snap"
+fi
+
+fs_creation=$fs_name
+vol_creation=$vol_name
+if is_global_zone ; then
+       snap_creation="Apple@snap Apple-vol@snap Banana@snap Banana-vol@snap"
+       snap_creation="$snap_creation Carrot@snap Carrot-vol@snap Orange@snap Orange-vol@snap"
+       snap_creation="$snap_creation apple@snap apple-vol@snap banana@snap banana-vol@snap"
+       snap_creation="$snap_creation carrot@snap carrot-vol@snap"
+else
+       snap_creation="Apple@snap Banana@snap"
+       snap_creation="$snap_creation Carrot@snap Orange@snap"
+       snap_creation="$snap_creation apple@snap banana@snap"
+       snap_creation="$snap_creation carrot@snap"
+fi
+
+#
+# datsets ordered by checksum options (note, Orange, Carrot & Banana have the
+# same checksum options, so ZFS should revert to sorting them alphabetically by
+# name)
+#
+fs_cksum="carrot apple banana Apple Banana Carrot Orange"
+vol_cksum="carrot-vol apple-vol banana-vol Apple-vol Banana-vol"
+vol_cksum="$vol_cksum Carrot-vol Orange-vol"
+snap_cksum=$snap_creation
+
+fs_rev_cksum="carrot apple banana Apple Orange Carrot Banana"
+vol_rev_cksum="carrot-vol apple-vol banana-vol Apple-vol Orange-vol"
+vol_rev_cksum="$vol_rev_cksum Carrot-vol Banana-vol"
+
+log_assert "The sort functionality in 'zfs list' works as expected."
+
+#
+# we must be in the C locale here, as running in other locales
+# will make zfs use that locale's sort order.
+#
+LC_ALL=C; export LC_ALL
+
+# sort by creation
+verify_sort \
+       "$ZFS list -H -r -o name -s creation -t filesystem $TESTPOOL/$TESTFS" \
+       "$fs_creation" "creation date"
+if is_global_zone ; then
+       verify_sort \
+       "$ZFS list -H -r -o name -s creation -t volume $TESTPOOL/$TESTFS" \
+       "$vol_creation" "creation date"
+fi
+verify_sort \
+       "$ZFS list -H -r -o name -s creation -t snapshot $TESTPOOL/$TESTFS" \
+       "$snap_creation" "creation date"
+
+# sort by checksum
+verify_sort \
+       "$ZFS list -H -r -o name -s checksum -t filesystem $TESTPOOL/$TESTFS" \
+       "$fs_cksum" "checksum"
+if is_global_zone ; then
+       verify_sort \
+       "$ZFS list -H -r -o name -s checksum -t volume $TESTPOOL/$TESTFS" \
+       "$vol_cksum" "checksum"
+fi
+verify_sort \
+       "$ZFS list -H -r -o name -s checksum -t snapshot $TESTPOOL/$TESTFS" \
+       "$snap_cksum" "checksum"
+verify_sort \
+       "$ZFS list -H -r -o name -S checksum -t snapshot $TESTPOOL/$TESTFS" \
+       "$snap_cksum" "checksum"
+
+# sort by name
+verify_sort \
+       "$ZFS list -H -r -o name -s name -t filesystem $TESTPOOL/$TESTFS" \
+       "$fs_name" "name"
+if is_global_zone ; then
+       verify_sort \
+       "$ZFS list -H -r -o name -s name -t volume $TESTPOOL/$TESTFS" \
+       "$vol_name" "name"
+fi
+verify_sort \
+       "$ZFS list -H -r -o name -s name -t snapshot $TESTPOOL/$TESTFS" \
+       "$snap_name" "name"
+
+# reverse sort by creation
+verify_reverse_sort \
+       "$ZFS list -H -r -o name -S creation -t filesystem $TESTPOOL/$TESTFS" \
+       "$fs_creation" "creation date"
+if is_global_zone ; then
+       verify_reverse_sort \
+       "$ZFS list -H -r -o name -S creation -t volume $TESTPOOL/$TESTFS" \
+       "$vol_creation" "creation date"
+fi
+verify_reverse_sort \
+       "$ZFS list -H -r -o name -S creation -t snapshot $TESTPOOL/$TESTFS" \
+       "$snap_creation" "creation date"
+
+# reverse sort by checksum
+verify_reverse_sort \
+       "$ZFS list -H -r -o name -S checksum -t filesystem $TESTPOOL/$TESTFS" \
+       "$fs_rev_cksum" "checksum"
+if is_global_zone ; then
+       verify_reverse_sort \
+       "$ZFS list -H -r -o name -S checksum -t volume $TESTPOOL/$TESTFS" \
+       "$vol_rev_cksum" "checksum"
+fi
+
+# reverse sort by name
+verify_reverse_sort \
+       "$ZFS list -H -r -o name -S name -t filesystem $TESTPOOL/$TESTFS"\
+       "$fs_name" "name"
+if is_global_zone ; then
+       verify_reverse_sort \
+       "$ZFS list -H -r -o name -S name -t volume $TESTPOOL/$TESTFS"\
+       "$vol_name" "name"
+fi
+verify_reverse_sort \
+       "$ZFS list -H -r -o name -S name -t snapshot $TESTPOOL/$TESTFS"\
+       "$snap_name" "name"
+
+log_pass "The sort functionality in 'zfs list' works as expected."
diff --git a/tests/zfs-tests/tests/functional/cli_user/zfs_list/zfs_list_003_pos.ksh b/tests/zfs-tests/tests/functional/cli_user/zfs_list/zfs_list_003_pos.ksh
new file mode 100755 (executable)
index 0000000..f685456
--- /dev/null
@@ -0,0 +1,76 @@
+#!/bin/ksh -p
+#
+# CDDL HEADER START
+#
+# The contents of this file are subject to the terms of the
+# Common Development and Distribution License (the "License").
+# You may not use this file except in compliance with the License.
+#
+# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
+# or http://www.opensolaris.org/os/licensing.
+# See the License for the specific language governing permissions
+# and limitations under the License.
+#
+# When distributing Covered Code, include this CDDL HEADER in each
+# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
+# If applicable, add the following below this CDDL HEADER, with the
+# fields enclosed by brackets "[]" replaced with your own identifying
+# information: Portions Copyright [yyyy] [name of copyright owner]
+#
+# CDDL HEADER END
+#
+
+#
+# Copyright 2007 Sun Microsystems, Inc.  All rights reserved.
+# Use is subject to license terms.
+#
+
+#
+# Copyright (c) 2013 by Delphix. All rights reserved.
+#
+
+. $STF_SUITE/include/libtest.shlib
+
+#
+# DESCRIPTION:
+#      Verify 'zfs list -r' could recursively display any children
+#      of the dataset.
+#
+# STRATEGY:
+# 1. Prepare a set of datasets by hierarchy.
+# 2. Execute 'zfs list -r' at the top of these datasets.
+# 3. Verify all child datasets are all be shown.
+#
+
+function cleanup
+{
+       if [[ -f $tmpfile ]]; then
+               $RM -f $tmpfile
+       fi
+}
+
+verify_runnable "both"
+log_onexit cleanup
+
+log_assert "Verify 'zfs list -r' could display any children recursively."
+
+tmpfile=/var/tmp/zfslist.out.$$
+children="$TESTPOOL/$TESTFS"
+
+for fs in $DATASETS ; do
+       children="$children $TESTPOOL/$TESTFS/$fs"
+done
+
+cd /tmp
+
+for path in $TESTPOOL/$TESTFS $TESTDIR ./../$TESTDIR ; do
+       $ZFS list -rH -o name $path > $tmpfile
+       for fs in $children ; do
+               $GREP "^${fs}$" $tmpfile > /dev/null 2>&1
+               if (( $? != 0 )); then
+                       log_fail "$fs not shown in the output list."
+               fi
+       done
+done
+
+log_pass "'zfs list -r' could display any children recursively."
diff --git a/tests/zfs-tests/tests/functional/cli_user/zfs_list/zfs_list_004_neg.ksh b/tests/zfs-tests/tests/functional/cli_user/zfs_list/zfs_list_004_neg.ksh
new file mode 100755 (executable)
index 0000000..13d6233
--- /dev/null
@@ -0,0 +1,63 @@
+#!/bin/ksh -p
+#
+# CDDL HEADER START
+#
+# The contents of this file are subject to the terms of the
+# Common Development and Distribution License (the "License").
+# You may not use this file except in compliance with the License.
+#
+# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
+# or http://www.opensolaris.org/os/licensing.
+# See the License for the specific language governing permissions
+# and limitations under the License.
+#
+# When distributing Covered Code, include this CDDL HEADER in each
+# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
+# If applicable, add the following below this CDDL HEADER, with the
+# fields enclosed by brackets "[]" replaced with your own identifying
+# information: Portions Copyright [yyyy] [name of copyright owner]
+#
+# CDDL HEADER END
+#
+
+#
+# Copyright 2007 Sun Microsystems, Inc.  All rights reserved.
+# Use is subject to license terms.
+#
+
+#
+# Copyright (c) 2013 by Delphix. All rights reserved.
+#
+
+. $STF_SUITE/include/libtest.shlib
+
+#
+# DESCRIPTION:
+#      Verify 'zfs list [-r]' should fail while
+#              * the given dataset does not exist
+#              * the given path does not exist.
+#              * the given path does not belong to zfs.
+#
+# STRATEGY:
+# 1. Create an array of invalid options.
+# 2. Execute each element in the array.
+# 3. Verify failure is returned.
+#
+
+verify_runnable "both"
+
+log_assert "Verify 'zfs list [-r]' should fail while the given " \
+       "dataset/path does not exist or not belong to zfs."
+
+paths="$TESTPOOL/NONEXISTFS $TESTPOOL/$TESTFS/NONEXISTFS \
+       /$TESTDIR/NONEXISTFS /devices /tmp ./../devices ./../tmp"
+
+cd /tmp
+
+for fs in $paths ; do
+       log_mustnot $ZFS list $fs
+       log_mustnot $ZFS list -r $fs
+done
+
+log_pass "'zfs list [-r]' fails while the given dataset/path does not exist " \
+       "or not belong to zfs."
diff --git a/tests/zfs-tests/tests/functional/cli_user/zfs_list/zfs_list_007_pos.ksh b/tests/zfs-tests/tests/functional/cli_user/zfs_list/zfs_list_007_pos.ksh
new file mode 100755 (executable)
index 0000000..984bc77
--- /dev/null
@@ -0,0 +1,91 @@
+#!/bin/ksh -p
+#
+# CDDL HEADER START
+#
+# The contents of this file are subject to the terms of the
+# Common Development and Distribution License (the "License").
+# You may not use this file except in compliance with the License.
+#
+# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
+# or http://www.opensolaris.org/os/licensing.
+# See the License for the specific language governing permissions
+# and limitations under the License.
+#
+# When distributing Covered Code, include this CDDL HEADER in each
+# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
+# If applicable, add the following below this CDDL HEADER, with the
+# fields enclosed by brackets "[]" replaced with your own identifying
+# information: Portions Copyright [yyyy] [name of copyright owner]
+#
+# CDDL HEADER END
+#
+
+#
+# Copyright 2009 Sun Microsystems, Inc.  All rights reserved.
+# Use is subject to license terms.
+#
+
+#
+# Copyright (c) 2013 by Delphix. All rights reserved.
+#
+
+. $STF_SUITE/tests/functional/cli_root/zfs_get/zfs_get_list_d.kshlib
+
+#
+# DESCRIPTION:
+#      'zfs list -d <n>' should get expected output.
+#
+# STRATEGY:
+#      1. 'zfs list -d <n>' to get the output.
+#      2. 'zfs list -r|egrep' to get the expected output.
+#      3. Compare the two outputs, they shoud be same.
+#
+
+verify_runnable "both"
+
+set -A fs_type "all" "filesystem" "snapshot"
+if is_global_zone ; then
+       set -A fs_type ${fs_type[*]} "volume"
+fi
+
+function cleanup
+{
+       log_must $RM -f $DEPTH_OUTPUT
+       log_must $RM -f $EXPECT_OUTPUT
+}
+
+log_onexit cleanup
+log_assert "'zfs list -d <n>' should get expected output."
+
+mntpnt=/var/tmp
+DEPTH_OUTPUT="$mntpnt/depth_output"
+EXPECT_OUTPUT="$mntpnt/expect_output"
+typeset -i old_val=0
+typeset -i j=0
+typeset -i fs=0
+typeset eg_opt="$DEPTH_FS"$
+for dp in ${depth_array[@]}; do
+       (( j=old_val+1 ))
+       while (( j<=dp && j<=MAX_DEPTH )); do
+               eg_opt="$eg_opt""|depth""$j"$
+               (( j+=1 ))
+       done
+       (( fs=0 ))
+       while (( fs<${#fs_type[*]} )); do
+               if [[ "$dp" == "0" ]] && \
+                 [[ "${fs_type[$fs]}" == "volume" || "${fs_type[$fs]}" == "snapshot" ]]; then
+                       log_must eval "$ZFS list -H -d $dp -o name -t ${fs_type[$fs]} $DEPTH_FS > $DEPTH_OUTPUT"
+                       [[ -s "$DEPTH_OUTPUT" ]] && \
+                               log_fail "$DEPTH_OUTPUT should be null."
+                       log_mustnot $ZFS list -rH -o name -t ${fs_type[$fs]} $DEPTH_FS | $EGREP -e '$eg_opt'
+               else
+                       log_must eval "$ZFS list -H -d $dp -o name -t ${fs_type[$fs]} $DEPTH_FS > $DEPTH_OUTPUT"
+                       log_must eval "$ZFS list -rH -o name -t ${fs_type[$fs]} $DEPTH_FS | $EGREP -e '$eg_opt' > $EXPECT_OUTPUT"
+                       log_must $DIFF $DEPTH_OUTPUT $EXPECT_OUTPUT
+               fi
+               (( fs+=1 ))
+       done
+       (( old_val=dp ))
+done
+
+log_pass "'zfs list -d <n>' should get expected output."
diff --git a/tests/zfs-tests/tests/functional/cli_user/zfs_list/zfs_list_008_neg.ksh b/tests/zfs-tests/tests/functional/cli_user/zfs_list/zfs_list_008_neg.ksh
new file mode 100755 (executable)
index 0000000..74c0b8b
--- /dev/null
@@ -0,0 +1,56 @@
+#!/bin/ksh -p
+#
+# CDDL HEADER START
+#
+# The contents of this file are subject to the terms of the
+# Common Development and Distribution License (the "License").
+# You may not use this file except in compliance with the License.
+#
+# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
+# or http://www.opensolaris.org/os/licensing.
+# See the License for the specific language governing permissions
+# and limitations under the License.
+#
+# When distributing Covered Code, include this CDDL HEADER in each
+# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
+# If applicable, add the following below this CDDL HEADER, with the
+# fields enclosed by brackets "[]" replaced with your own identifying
+# information: Portions Copyright [yyyy] [name of copyright owner]
+#
+# CDDL HEADER END
+#
+
+#
+# Copyright 2009 Sun Microsystems, Inc.  All rights reserved.
+# Use is subject to license terms.
+#
+
+#
+# Copyright (c) 2013 by Delphix. All rights reserved.
+#
+
+. $STF_SUITE/tests/functional/cli_root/zfs_get/zfs_get_list_d.kshlib
+
+#
+# DESCRIPTION:
+# A negative depth or a non numeric depth should fail in 'zfs list -d <n>'
+#
+# STRATEGY:
+# 1. Run zfs list -d with negative depth or non numeric depth
+# 2. Verify that zfs list returns error
+#
+
+verify_runnable "both"
+
+log_assert "A negative depth or a non numeric depth should fail in 'zfs list -d <n>'"
+
+set -A  badargs "a" "AB" "aBc" "2A" "a2b" "aB2" "-1" "-32" "-999"
+
+typeset -i i=0
+while (( i < ${#badargs[*]} ))
+do
+       log_mustnot eval "$ZFS list -d ${badargs[i]} $DEPTH_FS >/dev/null 2>&1"
+       (( i = i + 1 ))
+done
+
+log_pass "A negative depth or a non numeric depth should fail in 'zfs list -d <n>'"
diff --git a/tests/zfs-tests/tests/functional/cli_user/zpool_iostat/Makefile.am b/tests/zfs-tests/tests/functional/cli_user/zpool_iostat/Makefile.am
new file mode 100644 (file)
index 0000000..2c292b9
--- /dev/null
@@ -0,0 +1,7 @@
+pkgdatadir = $(datadir)/@PACKAGE@/zfs-tests/tests/functional/cli_user/zpool_iostat
+dist_pkgdata_SCRIPTS = \
+       setup.ksh \
+       cleanup.ksh \
+       zpool_iostat_001_neg.ksh \
+       zpool_iostat_002_pos.ksh \
+       zpool_iostat_003_neg.ksh
diff --git a/tests/zfs-tests/tests/functional/cli_user/zpool_iostat/cleanup.ksh b/tests/zfs-tests/tests/functional/cli_user/zpool_iostat/cleanup.ksh
new file mode 100755 (executable)
index 0000000..3166bd6
--- /dev/null
@@ -0,0 +1,34 @@
+#!/bin/ksh -p
+#
+# CDDL HEADER START
+#
+# The contents of this file are subject to the terms of the
+# Common Development and Distribution License (the "License").
+# You may not use this file except in compliance with the License.
+#
+# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
+# or http://www.opensolaris.org/os/licensing.
+# See the License for the specific language governing permissions
+# and limitations under the License.
+#
+# When distributing Covered Code, include this CDDL HEADER in each
+# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
+# If applicable, add the following below this CDDL HEADER, with the
+# fields enclosed by brackets "[]" replaced with your own identifying
+# information: Portions Copyright [yyyy] [name of copyright owner]
+#
+# CDDL HEADER END
+#
+
+#
+# Copyright 2007 Sun Microsystems, Inc.  All rights reserved.
+# Use is subject to license terms.
+#
+
+#
+# Copyright (c) 2013 by Delphix. All rights reserved.
+#
+
+. $STF_SUITE/include/libtest.shlib
+
+default_cleanup
diff --git a/tests/zfs-tests/tests/functional/cli_user/zpool_iostat/setup.ksh b/tests/zfs-tests/tests/functional/cli_user/zpool_iostat/setup.ksh
new file mode 100755 (executable)
index 0000000..d275e06
--- /dev/null
@@ -0,0 +1,36 @@
+#!/bin/ksh -p
+#
+# CDDL HEADER START
+#
+# The contents of this file are subject to the terms of the
+# Common Development and Distribution License (the "License").
+# You may not use this file except in compliance with the License.
+#
+# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
+# or http://www.opensolaris.org/os/licensing.
+# See the License for the specific language governing permissions
+# and limitations under the License.
+#
+# When distributing Covered Code, include this CDDL HEADER in each
+# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
+# If applicable, add the following below this CDDL HEADER, with the
+# fields enclosed by brackets "[]" replaced with your own identifying
+# information: Portions Copyright [yyyy] [name of copyright owner]
+#
+# CDDL HEADER END
+#
+
+#
+# Copyright 2007 Sun Microsystems, Inc.  All rights reserved.
+# Use is subject to license terms.
+#
+
+#
+# Copyright (c) 2013 by Delphix. All rights reserved.
+#
+
+. $STF_SUITE/include/libtest.shlib
+
+DISK=${DISKS%% *}
+
+default_setup $DISK
diff --git a/tests/zfs-tests/tests/functional/cli_user/zpool_iostat/zpool_iostat_001_neg.ksh b/tests/zfs-tests/tests/functional/cli_user/zpool_iostat/zpool_iostat_001_neg.ksh
new file mode 100755 (executable)
index 0000000..a1fac98
--- /dev/null
@@ -0,0 +1,63 @@
+#!/bin/ksh -p
+#
+# CDDL HEADER START
+#
+# The contents of this file are subject to the terms of the
+# Common Development and Distribution License (the "License").
+# You may not use this file except in compliance with the License.
+#
+# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
+# or http://www.opensolaris.org/os/licensing.
+# See the License for the specific language governing permissions
+# and limitations under the License.
+#
+# When distributing Covered Code, include this CDDL HEADER in each
+# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
+# If applicable, add the following below this CDDL HEADER, with the
+# fields enclosed by brackets "[]" replaced with your own identifying
+# information: Portions Copyright [yyyy] [name of copyright owner]
+#
+# CDDL HEADER END
+#
+
+#
+# Copyright 2007 Sun Microsystems, Inc.  All rights reserved.
+# Use is subject to license terms.
+#
+
+#
+# Copyright (c) 2013 by Delphix. All rights reserved.
+#
+
+. $STF_SUITE/include/libtest.shlib
+
+#
+# DESCRIPTION:
+# Verify that 'zpool iostat' can be executed as non-root.
+#
+# STRATEGY:
+# 1. Create an array of options.
+# 2. Execute each element of the array.
+# 3. Verify that a success is returned.
+#
+
+verify_runnable "both"
+
+typeset testpool
+if is_global_zone ; then
+       testpool=$TESTPOOL
+else
+       testpool=${TESTPOOL%%/*}
+fi
+
+set -A args "iostat" "iostat $testpool"
+
+log_assert "zpool iostat [pool_name ...] [interval]"
+
+typeset -i i=0
+while [[ $i -lt ${#args[*]} ]]; do
+       log_must $ZPOOL ${args[i]}
+       ((i = i + 1))
+done
+
+log_pass "The sub-command 'iostat' succeeds as non-root."
diff --git a/tests/zfs-tests/tests/functional/cli_user/zpool_iostat/zpool_iostat_002_pos.ksh b/tests/zfs-tests/tests/functional/cli_user/zpool_iostat/zpool_iostat_002_pos.ksh
new file mode 100755 (executable)
index 0000000..37062ca
--- /dev/null
@@ -0,0 +1,71 @@
+#!/bin/ksh -p
+#
+# CDDL HEADER START
+#
+# The contents of this file are subject to the terms of the
+# Common Development and Distribution License (the "License").
+# You may not use this file except in compliance with the License.
+#
+# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
+# or http://www.opensolaris.org/os/licensing.
+# See the License for the specific language governing permissions
+# and limitations under the License.
+#
+# When distributing Covered Code, include this CDDL HEADER in each
+# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
+# If applicable, add the following below this CDDL HEADER, with the
+# fields enclosed by brackets "[]" replaced with your own identifying
+# information: Portions Copyright [yyyy] [name of copyright owner]
+#
+# CDDL HEADER END
+#
+
+#
+# Copyright 2008 Sun Microsystems, Inc.  All rights reserved.
+# Use is subject to license terms.
+#
+
+#
+# Copyright (c) 2013 by Delphix. All rights reserved.
+#
+
+. $STF_SUITE/include/libtest.shlib
+
+#
+# DESCRIPTION:
+# Verify that 'zpool iostat [interval [count]' can be executed as non-root.
+#
+# STRATEGY:
+# 1. Set the interval to 1 and count to 4.
+# 2. Sleep for 4 seconds.
+# 3. Verify that the output has 4 records.
+#
+
+verify_runnable "both"
+
+typeset tmpfile=/var/tmp/zfsiostat.out.$$
+typeset -i stat_count=0
+
+function cleanup
+{
+       if [[ -f $tmpfile ]]; then
+               $RM -f $tmpfile
+       fi
+}
+
+log_onexit cleanup
+log_assert "zpool iostat [pool_name ...] [interval] [count]"
+
+if ! is_global_zone ; then
+       TESTPOOL=${TESTPOOL%%/*}
+fi
+
+$ZPOOL iostat $TESTPOOL 1 4 > $tmpfile 2>&1 &
+sleep 4
+stat_count=$($GREP $TESTPOOL $tmpfile | $WC -l)
+
+if [[ $stat_count -ne 4 ]]; then
+       log_fail "zpool iostat [pool_name] [interval] [count] failed"
+fi
+
+log_pass "zpool iostat [pool_name ...] [interval] [count] passed"
diff --git a/tests/zfs-tests/tests/functional/cli_user/zpool_iostat/zpool_iostat_003_neg.ksh b/tests/zfs-tests/tests/functional/cli_user/zpool_iostat/zpool_iostat_003_neg.ksh
new file mode 100755 (executable)
index 0000000..d73f5d5
--- /dev/null
@@ -0,0 +1,65 @@
+#!/bin/ksh -p
+#
+# CDDL HEADER START
+#
+# The contents of this file are subject to the terms of the
+# Common Development and Distribution License (the "License").
+# You may not use this file except in compliance with the License.
+#
+# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
+# or http://www.opensolaris.org/os/licensing.
+# See the License for the specific language governing permissions
+# and limitations under the License.
+#
+# When distributing Covered Code, include this CDDL HEADER in each
+# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
+# If applicable, add the following below this CDDL HEADER, with the
+# fields enclosed by brackets "[]" replaced with your own identifying
+# information: Portions Copyright [yyyy] [name of copyright owner]
+#
+# CDDL HEADER END
+#
+
+#
+# Copyright 2007 Sun Microsystems, Inc.  All rights reserved.
+# Use is subject to license terms.
+#
+
+#
+# Copyright (c) 2013 by Delphix. All rights reserved.
+#
+
+. $STF_SUITE/include/libtest.shlib
+
+#
+# DESCRIPTION:
+# Executing 'zpool iostat' command with bad options fails.
+#
+# STRATEGY:
+# 1. Create an array of badly formed 'zpool iostat' options.
+# 2. Execute each element of the array.
+# 3. Verify an error code is returned.
+#
+
+verify_runnable "both"
+
+typeset testpool
+if is_global_zone ; then
+        testpool=$TESTPOOL
+else
+        testpool=${TESTPOOL%%/*}
+fi
+
+set -A args "" "-?" "-f" "nonexistpool" "$TESTPOOL/$TESTFS" \
+       "$testpool 1.23" "$testpool 0" "$testpool -1" "$testpool 1 0" \
+       "$testpool 0 0"
+
+log_assert "Executing 'zpool iostat' with bad options fails"
+
+typeset -i i=1
+while [[ $i -lt ${#args[*]} ]]; do
+       log_mustnot $ZPOOL iostat ${args[i]}
+       ((i = i + 1))
+done
+
+log_pass "Executing 'zpool iostat' with bad options fails"
diff --git a/tests/zfs-tests/tests/functional/cli_user/zpool_list/Makefile.am b/tests/zfs-tests/tests/functional/cli_user/zpool_list/Makefile.am
new file mode 100644 (file)
index 0000000..de8cb36
--- /dev/null
@@ -0,0 +1,6 @@
+pkgdatadir = $(datadir)/@PACKAGE@/zfs-tests/tests/functional/cli_user/zpool_list
+dist_pkgdata_SCRIPTS = \
+       setup.ksh \
+       cleanup.ksh \
+       zpool_list_001_pos.ksh \
+       zpool_list_002_neg.ksh
diff --git a/tests/zfs-tests/tests/functional/cli_user/zpool_list/cleanup.ksh b/tests/zfs-tests/tests/functional/cli_user/zpool_list/cleanup.ksh
new file mode 100755 (executable)
index 0000000..3166bd6
--- /dev/null
@@ -0,0 +1,34 @@
+#!/bin/ksh -p
+#
+# CDDL HEADER START
+#
+# The contents of this file are subject to the terms of the
+# Common Development and Distribution License (the "License").
+# You may not use this file except in compliance with the License.
+#
+# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
+# or http://www.opensolaris.org/os/licensing.
+# See the License for the specific language governing permissions
+# and limitations under the License.
+#
+# When distributing Covered Code, include this CDDL HEADER in each
+# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
+# If applicable, add the following below this CDDL HEADER, with the
+# fields enclosed by brackets "[]" replaced with your own identifying
+# information: Portions Copyright [yyyy] [name of copyright owner]
+#
+# CDDL HEADER END
+#
+
+#
+# Copyright 2007 Sun Microsystems, Inc.  All rights reserved.
+# Use is subject to license terms.
+#
+
+#
+# Copyright (c) 2013 by Delphix. All rights reserved.
+#
+
+. $STF_SUITE/include/libtest.shlib
+
+default_cleanup
diff --git a/tests/zfs-tests/tests/functional/cli_user/zpool_list/setup.ksh b/tests/zfs-tests/tests/functional/cli_user/zpool_list/setup.ksh
new file mode 100755 (executable)
index 0000000..d275e06
--- /dev/null
@@ -0,0 +1,36 @@
+#!/bin/ksh -p
+#
+# CDDL HEADER START
+#
+# The contents of this file are subject to the terms of the
+# Common Development and Distribution License (the "License").
+# You may not use this file except in compliance with the License.
+#
+# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
+# or http://www.opensolaris.org/os/licensing.
+# See the License for the specific language governing permissions
+# and limitations under the License.
+#
+# When distributing Covered Code, include this CDDL HEADER in each
+# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
+# If applicable, add the following below this CDDL HEADER, with the
+# fields enclosed by brackets "[]" replaced with your own identifying
+# information: Portions Copyright [yyyy] [name of copyright owner]
+#
+# CDDL HEADER END
+#
+
+#
+# Copyright 2007 Sun Microsystems, Inc.  All rights reserved.
+# Use is subject to license terms.
+#
+
+#
+# Copyright (c) 2013 by Delphix. All rights reserved.
+#
+
+. $STF_SUITE/include/libtest.shlib
+
+DISK=${DISKS%% *}
+
+default_setup $DISK
diff --git a/tests/zfs-tests/tests/functional/cli_user/zpool_list/zpool_list_001_pos.ksh b/tests/zfs-tests/tests/functional/cli_user/zpool_list/zpool_list_001_pos.ksh
new file mode 100755 (executable)
index 0000000..4de8867
--- /dev/null
@@ -0,0 +1,64 @@
+#!/bin/ksh -p
+#
+# CDDL HEADER START
+#
+# The contents of this file are subject to the terms of the
+# Common Development and Distribution License (the "License").
+# You may not use this file except in compliance with the License.
+#
+# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
+# or http://www.opensolaris.org/os/licensing.
+# See the License for the specific language governing permissions
+# and limitations under the License.
+#
+# When distributing Covered Code, include this CDDL HEADER in each
+# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
+# If applicable, add the following below this CDDL HEADER, with the
+# fields enclosed by brackets "[]" replaced with your own identifying
+# information: Portions Copyright [yyyy] [name of copyright owner]
+#
+# CDDL HEADER END
+#
+
+#
+# Copyright 2008 Sun Microsystems, Inc.  All rights reserved.
+# Use is subject to license terms.
+#
+
+#
+# Copyright (c) 2013 by Delphix. All rights reserved.
+#
+
+. $STF_SUITE/include/libtest.shlib
+
+#
+# DESCRIPTION:
+# Verify that 'zpool list' succeeds as non-root.
+#
+# STRATEGY:
+# 1. Create an array of options.
+# 2. Execute each element of the array.
+# 3. Verify the command succeeds.
+#
+
+verify_runnable "both"
+
+if ! is_global_zone; then
+       TESTPOOL=${TESTPOOL%%/*}
+fi
+
+set -A args "list $TESTPOOL" "list -H $TESTPOOL" "list" "list -H" \
+    "list -H -o name $TESTPOOL" "list -o name $TESTPOOL" \
+    "list -o name,size,capacity,health,altroot $TESTPOOL" \
+    "list -H -o name,size,capacity,health,altroot $TESTPOOL"
+
+log_assert "zpool list [-H] [-o filed[,filed]*] [<pool_name> ...]"
+
+typeset -i i=0
+while [[ $i -lt ${#args[*]} ]]; do
+       log_must $ZPOOL ${args[i]}
+
+       ((i = i + 1))
+done
+
+log_pass "The sub-command 'list' succeeds as non-root."
diff --git a/tests/zfs-tests/tests/functional/cli_user/zpool_list/zpool_list_002_neg.ksh b/tests/zfs-tests/tests/functional/cli_user/zpool_list/zpool_list_002_neg.ksh
new file mode 100755 (executable)
index 0000000..469437a
--- /dev/null
@@ -0,0 +1,57 @@
+#!/bin/ksh -p
+#
+# CDDL HEADER START
+#
+# The contents of this file are subject to the terms of the
+# Common Development and Distribution License (the "License").
+# You may not use this file except in compliance with the License.
+#
+# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
+# or http://www.opensolaris.org/os/licensing.
+# See the License for the specific language governing permissions
+# and limitations under the License.
+#
+# When distributing Covered Code, include this CDDL HEADER in each
+# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
+# If applicable, add the following below this CDDL HEADER, with the
+# fields enclosed by brackets "[]" replaced with your own identifying
+# information: Portions Copyright [yyyy] [name of copyright owner]
+#
+# CDDL HEADER END
+#
+
+#
+# Copyright 2008 Sun Microsystems, Inc.  All rights reserved.
+# Use is subject to license terms.
+#
+
+#
+# Copyright (c) 2013 by Delphix. All rights reserved.
+#
+
+. $STF_SUITE/include/libtest.shlib
+
+#
+# DESCRIPTION:
+# Executing 'zpool list' command with bad options fails.
+#
+# STRATEGY:
+# 1. Create an array of badly formed 'zpool list' options.
+# 2. Execute each element of the array.
+# 3. Verify an error code is returned.
+#
+
+verify_runnable "both"
+
+set -A args "" "-?" "-f" "-o" \
+       "-o fakeproperty" "-o name,size,fakeproperty"
+
+log_assert "Executing 'zpool list' with bad options fails"
+
+typeset -i i=1
+while [[ $i -lt ${#args[*]} ]]; do
+       log_mustnot $ZPOOL list ${args[i]}
+       ((i = i + 1))
+done
+
+log_pass "Executing 'zpool list' with bad options fails"
diff --git a/tests/zfs-tests/tests/functional/compression/Makefile.am b/tests/zfs-tests/tests/functional/compression/Makefile.am
new file mode 100644 (file)
index 0000000..d11b0a7
--- /dev/null
@@ -0,0 +1,9 @@
+pkgdatadir = $(datadir)/@PACKAGE@/zfs-tests/tests/functional/compression
+dist_pkgdata_SCRIPTS = \
+       compress.cfg \
+       cleanup.ksh \
+       setup.ksh \
+       compress_001_pos.ksh \
+       compress_002_pos.ksh \
+       compress_003_pos.ksh \
+       compress_004_pos.ksh
diff --git a/tests/zfs-tests/tests/functional/compression/cleanup.ksh b/tests/zfs-tests/tests/functional/compression/cleanup.ksh
new file mode 100755 (executable)
index 0000000..0573003
--- /dev/null
@@ -0,0 +1,34 @@
+#!/bin/ksh -p
+#
+# CDDL HEADER START
+#
+# The contents of this file are subject to the terms of the
+# Common Development and Distribution License (the "License").
+# You may not use this file except in compliance with the License.
+#
+# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
+# or http://www.opensolaris.org/os/licensing.
+# See the License for the specific language governing permissions
+# and limitations under the License.
+#
+# When distributing Covered Code, include this CDDL HEADER in each
+# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
+# If applicable, add the following below this CDDL HEADER, with the
+# fields enclosed by brackets "[]" replaced with your own identifying
+# information: Portions Copyright [yyyy] [name of copyright owner]
+#
+# CDDL HEADER END
+#
+
+#
+# Copyright 2007 Sun Microsystems, Inc.  All rights reserved.
+# Use is subject to license terms.
+#
+
+#
+# Copyright (c) 2013 by Delphix. All rights reserved.
+#
+
+. ${STF_SUITE}/include/libtest.shlib
+
+default_container_cleanup
diff --git a/tests/zfs-tests/tests/functional/compression/compress.cfg b/tests/zfs-tests/tests/functional/compression/compress.cfg
new file mode 100644 (file)
index 0000000..b237306
--- /dev/null
@@ -0,0 +1,33 @@
+#
+# CDDL HEADER START
+#
+# The contents of this file are subject to the terms of the
+# Common Development and Distribution License (the "License").
+# You may not use this file except in compliance with the License.
+#
+# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
+# or http://www.opensolaris.org/os/licensing.
+# See the License for the specific language governing permissions
+# and limitations under the License.
+#
+# When distributing Covered Code, include this CDDL HEADER in each
+# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
+# If applicable, add the following below this CDDL HEADER, with the
+# fields enclosed by brackets "[]" replaced with your own identifying
+# information: Portions Copyright [yyyy] [name of copyright owner]
+#
+# CDDL HEADER END
+#
+
+#
+# Copyright 2008 Sun Microsystems, Inc.  All rights reserved.
+# Use is subject to license terms.
+#
+
+#
+# Copyright (c) 2013 by Delphix. All rights reserved.
+#
+
+export BLOCKSZ=8192
+export NUM_WRITES=16384
+export DATA=13
diff --git a/tests/zfs-tests/tests/functional/compression/compress_001_pos.ksh b/tests/zfs-tests/tests/functional/compression/compress_001_pos.ksh
new file mode 100755 (executable)
index 0000000..ce2c26b
--- /dev/null
@@ -0,0 +1,74 @@
+#!/bin/ksh -p
+#
+# CDDL HEADER START
+#
+# The contents of this file are subject to the terms of the
+# Common Development and Distribution License (the "License").
+# You may not use this file except in compliance with the License.
+#
+# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
+# or http://www.opensolaris.org/os/licensing.
+# See the License for the specific language governing permissions
+# and limitations under the License.
+#
+# When distributing Covered Code, include this CDDL HEADER in each
+# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
+# If applicable, add the following below this CDDL HEADER, with the
+# fields enclosed by brackets "[]" replaced with your own identifying
+# information: Portions Copyright [yyyy] [name of copyright owner]
+#
+# CDDL HEADER END
+#
+
+#
+# Copyright 2007 Sun Microsystems, Inc.  All rights reserved.
+# Use is subject to license terms.
+#
+
+#
+# Copyright (c) 2013 by Delphix. All rights reserved.
+#
+
+. $STF_SUITE/include/libtest.shlib
+. $STF_SUITE/tests/functional/compression/compress.cfg
+
+#
+# DESCRIPTION:
+# Create two files of exactly the same size. One with compression
+# and one without. Ensure the compressed file is smaller.
+#
+# STRATEGY:
+# Use "zfs set" to turn on compression and create files before
+# and after the set call. The compressed file should be smaller.
+#
+
+verify_runnable "both"
+
+typeset OP=create
+
+log_assert "Ensure that compressed files are smaller."
+
+log_note "Ensure compression is off"
+log_must $ZFS set compression=off $TESTPOOL/$TESTFS
+
+log_note "Writing file without compression..."
+log_must $FILE_WRITE -o $OP -f $TESTDIR/$TESTFILE0 -b $BLOCKSZ \
+    -c $NUM_WRITES -d $DATA
+
+log_note "Add compression property to the dataset and write another file"
+log_must $ZFS set compression=on $TESTPOOL/$TESTFS
+
+log_must $FILE_WRITE -o $OP -f $TESTDIR/$TESTFILE1 -b $BLOCKSZ \
+    -c $NUM_WRITES -d $DATA
+
+$SLEEP 60
+
+FILE0_BLKS=`$DU -k $TESTDIR/$TESTFILE0 | $AWK '{ print $1}'`
+FILE1_BLKS=`$DU -k $TESTDIR/$TESTFILE1 | $AWK '{ print $1}'`
+
+if [[ $FILE0_BLKS -le $FILE1_BLKS ]]; then
+       log_fail "$TESTFILE0 is smaller than $TESTFILE1" \
+                       "($FILE0_BLKS <= $FILE1_BLKS)"
+fi
+
+log_pass "$TESTFILE0 is bigger than $TESTFILE1 ($FILE0_BLKS > $FILE1_BLKS)"
diff --git a/tests/zfs-tests/tests/functional/compression/compress_002_pos.ksh b/tests/zfs-tests/tests/functional/compression/compress_002_pos.ksh
new file mode 100755 (executable)
index 0000000..88e1556
--- /dev/null
@@ -0,0 +1,76 @@
+#!/bin/ksh -p
+#
+# CDDL HEADER START
+#
+# The contents of this file are subject to the terms of the
+# Common Development and Distribution License (the "License").
+# You may not use this file except in compliance with the License.
+#
+# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
+# or http://www.opensolaris.org/os/licensing.
+# See the License for the specific language governing permissions
+# and limitations under the License.
+#
+# When distributing Covered Code, include this CDDL HEADER in each
+# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
+# If applicable, add the following below this CDDL HEADER, with the
+# fields enclosed by brackets "[]" replaced with your own identifying
+# information: Portions Copyright [yyyy] [name of copyright owner]
+#
+# CDDL HEADER END
+#
+
+#
+# Copyright 2007 Sun Microsystems, Inc.  All rights reserved.
+# Use is subject to license terms.
+#
+
+#
+# Copyright (c) 2013 by Delphix. All rights reserved.
+#
+
+. $STF_SUITE/include/libtest.shlib
+. $STF_SUITE/tests/functional/compression/compress.cfg
+
+#
+# DESCRIPTION:
+# Create two files of exactly the same size. One with compression
+# and one without. Ensure the compressed file is smaller.
+#
+# NOTE: This test uses a dataset rather than a simple file system.
+#
+# STRATEGY:
+# Create a dataset, turn on compression and create files before
+# and after the property change. The compressed file should be smaller.
+#
+
+verify_runnable "both"
+
+typeset OP=create
+
+log_assert "Ensure that compressed files in a dataset are smaller."
+
+log_note "Ensure compression is off"
+log_must $ZFS set compression=off $TESTPOOL/$TESTCTR
+
+log_note "Writing file without compression..."
+log_must $FILE_WRITE -o $OP -f $TESTDIR1/$TESTFILE0 -b $BLOCKSZ \
+    -c $NUM_WRITES -d $DATA
+
+log_note "Add compression property to the dataset and write another file"
+log_must $ZFS set compression=on $TESTPOOL/$TESTCTR
+
+log_must $FILE_WRITE -o $OP -f $TESTDIR1/$TESTFILE1 -b $BLOCKSZ \
+    -c $NUM_WRITES -d $DATA
+
+$SLEEP 60
+
+FILE0_BLKS=`$DU -k $TESTDIR1/$TESTFILE0 | $AWK '{ print $1}'`
+FILE1_BLKS=`$DU -k $TESTDIR1/$TESTFILE1 | $AWK '{ print $1}'`
+
+if [[ $FILE0_BLKS -le $FILE1_BLKS ]]; then
+       log_fail "$TESTFILE0 is smaller than $TESTFILE1" \
+                       "($FILE0_BLKS <= $FILE1_BLKS)"
+fi
+
+log_pass "$TESTFILE0 is bigger than $TESTFILE1 ($FILE0_BLKS > $FILE1_BLKS)"
diff --git a/tests/zfs-tests/tests/functional/compression/compress_003_pos.ksh b/tests/zfs-tests/tests/functional/compression/compress_003_pos.ksh
new file mode 100755 (executable)
index 0000000..c995b53
--- /dev/null
@@ -0,0 +1,96 @@
+#!/bin/ksh -p
+#
+# CDDL HEADER START
+#
+# The contents of this file are subject to the terms of the
+# Common Development and Distribution License (the "License").
+# You may not use this file except in compliance with the License.
+#
+# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
+# or http://www.opensolaris.org/os/licensing.
+# See the License for the specific language governing permissions
+# and limitations under the License.
+#
+# When distributing Covered Code, include this CDDL HEADER in each
+# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
+# If applicable, add the following below this CDDL HEADER, with the
+# fields enclosed by brackets "[]" replaced with your own identifying
+# information: Portions Copyright [yyyy] [name of copyright owner]
+#
+# CDDL HEADER END
+#
+
+#
+# Copyright 2007 Sun Microsystems, Inc.  All rights reserved.
+# Use is subject to license terms.
+#
+
+#
+# Copyright (c) 2013 by Delphix. All rights reserved.
+#
+
+. $STF_SUITE/include/libtest.shlib
+
+#
+# DESCRIPTION:
+# With 'compression' or 'compress'  set, changing filesystem blocksize cannot
+# cause system panic
+#
+# STRATEGY:
+#      1. Set 'compression' or "compress" to on
+#      2. Set different blocksize with ZFS filesystem
+#      3. Use 'mkfile' create single block and multi-block files
+#      4. Verify the system continued work
+#
+
+verify_runnable "both"
+
+function cleanup
+{
+       $RM -f $TESTDIR/*
+}
+
+log_assert "Changing blocksize doesn't casue system panic with compression settings"
+log_onexit cleanup
+
+fs=$TESTPOOL/$TESTFS
+single_blk_file=$TESTDIR/singleblkfile.$$
+multi_blk_file=$TESTDIR/multiblkfile.$$
+typeset -i blksize=512
+typeset -i fsize=0
+typeset -i offset=0
+
+for propname in "compression" "compress"
+do
+       for value in $(get_compress_opts zfs_compress)
+       do
+               log_must $ZFS set $propname=$value $fs
+               if [[ $value == "gzip-6" ]]; then
+                       value="gzip"
+               fi
+               real_val=$(get_prop $propname $fs)
+               [[ $real_val != $value ]] && \
+                       log_fail "Set property $propname=$value failed."
+
+               (( blksize = 512 ))
+               while (( blksize <= 131072 )); do
+                       log_must $ZFS set recordsize=$blksize $fs
+                       (( offset = $RANDOM ))
+                       if (( offset > blksize )); then
+                               (( offset = offset % blksize ))
+                       fi
+                       if (( (offset % 2) == 0 )); then
+                               #keep offset as non-power-of-2
+                               (( offset = offset + 1 ))
+                       fi
+                       (( fsize = offset ))
+                       log_must $MKFILE $fsize $single_blk_file
+                       (( fsize = blksize + offset ))
+                       log_must $MKFILE $fsize $multi_blk_file
+
+                       (( blksize = blksize * 2 ))
+               done
+       done
+done
+
+log_pass "The system works as expected while changing blocksize with compression settings"
diff --git a/tests/zfs-tests/tests/functional/compression/compress_004_pos.ksh b/tests/zfs-tests/tests/functional/compression/compress_004_pos.ksh
new file mode 100755 (executable)
index 0000000..8b9054e
--- /dev/null
@@ -0,0 +1,141 @@
+#!/bin/ksh -p
+#
+# CDDL HEADER START
+#
+# The contents of this file are subject to the terms of the
+# Common Development and Distribution License (the "License").
+# You may not use this file except in compliance with the License.
+#
+# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
+# or http://www.opensolaris.org/os/licensing.
+# See the License for the specific language governing permissions
+# and limitations under the License.
+#
+# When distributing Covered Code, include this CDDL HEADER in each
+# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
+# If applicable, add the following below this CDDL HEADER, with the
+# fields enclosed by brackets "[]" replaced with your own identifying
+# information: Portions Copyright [yyyy] [name of copyright owner]
+#
+# CDDL HEADER END
+#
+
+#
+# Copyright 2007 Sun Microsystems, Inc.  All rights reserved.
+# Use is subject to license terms.
+#
+
+#
+# Copyright (c) 2013 by Delphix. All rights reserved.
+#
+
+. $STF_SUITE/include/libtest.shlib
+
+#
+# DESCRIPTION:
+# With 'compression' set, a file with non-power-of-2 blocksize storage space
+# can be freed as will normally.
+#
+# STRATEGY:
+#      1. Set 'compression' or 'compress' to on or lzjb
+#      2. Set different recordsize with ZFS filesystem
+#      3. Repeatedly using 'randfree_file' to create a file and then free its
+#         storage space with different range, the system should work normally.
+#
+
+verify_runnable "both"
+
+function cleanup
+{
+       $RM -f $TESTDIR/*
+}
+
+function create_free_testing #<file size> <file>
+{
+       typeset -i fsz=$1
+       typeset file=$2
+       typeset -i start=0
+       typeset -i len=0
+       typeset -i dist=0
+
+       for start in 0 `expr $RANDOM % $fsz`
+       do
+               (( dist = fsz - start ))
+               for len in `expr $RANDOM % $dist` $dist \
+                       `expr $start + $dist`; do
+
+                       # Zero length results in EINVAL for fallocate(2).
+                       if is_linux; then
+                               if (( len == 0 )); then
+                                       continue
+                               fi
+                       fi
+
+                       log_must $RANDFREE_FILE -l fsz -s $start \
+                               -n $len $file
+                       [[ -e $file ]] && \
+                               log_must $RM -f $file
+               done
+       done
+}
+
+
+log_assert "Creating non-power-of-2 blocksize file and freeing the file \
+       storage space at will should work normally with compression setting"
+log_onexit cleanup
+
+fs=$TESTPOOL/$TESTFS
+single_blk_file=$TESTDIR/singleblkfile.$$
+multi_blk_file=$TESTDIR/multiblkfile.$$
+typeset -i blksize=512
+typeset -i fsize=0
+typeset -i avail=0
+typeset -i blknum=0
+
+for propname in "compression" "compress"
+do
+       for value in $(get_compress_opts zfs_compress)
+       do
+               log_must $ZFS set compression=$value $fs
+               real_val=$(get_prop $propname $fs)
+               if [[ $value == "gzip-6" ]]; then
+                       value="gzip"
+               fi
+               [[ $real_val != $value ]] && \
+                       log_fail "Set property $propname=$value failed."
+
+               (( blksize = 512 ))
+               while (( blksize <= 131072 )); do
+                       log_must $ZFS set recordsize=$blksize $fs
+
+                       # doing single block testing
+                       (( fsize = $RANDOM ))
+                       if (( fsize > blksize )); then
+                               (( fsize = fsize % blksize ))
+                       fi
+                       if (( (fsize % 2) == 0 )); then
+                               #make sure fsize is non-power-of-2
+                               (( fsize = fsize + 1 ))
+                       fi
+                       create_free_testing $fsize $single_blk_file
+
+                       # doing multiple blocks testing
+                       avail=$(get_prop available $fs)
+                       (( blknum = avail / blksize ))
+                       # we just test <10 multi-blocks to limit testing time
+                       (( blknum = blknum % 9 ))
+                       while (( blknum < 2 )); do
+                               (( blknum = blknum + $RANDOM % 9 ))
+                       done
+                       if (( (blknum % 2) == 0 )); then
+                               (( blknum = blknum + 1 )) # keep blknum as odd
+                       fi
+                       (( fsize = blknum * blksize ))
+                       create_free_testing $fsize $multi_blk_file
+
+                       (( blksize = blksize * 2 ))
+               done
+       done
+done
+
+log_pass "Creating and freeing non-power-of-2 blocksize file work as expected."
diff --git a/tests/zfs-tests/tests/functional/compression/setup.ksh b/tests/zfs-tests/tests/functional/compression/setup.ksh
new file mode 100755 (executable)
index 0000000..677cb12
--- /dev/null
@@ -0,0 +1,36 @@
+#!/bin/ksh -p
+#
+# CDDL HEADER START
+#
+# The contents of this file are subject to the terms of the
+# Common Development and Distribution License (the "License").
+# You may not use this file except in compliance with the License.
+#
+# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
+# or http://www.opensolaris.org/os/licensing.
+# See the License for the specific language governing permissions
+# and limitations under the License.
+#
+# When distributing Covered Code, include this CDDL HEADER in each
+# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
+# If applicable, add the following below this CDDL HEADER, with the
+# fields enclosed by brackets "[]" replaced with your own identifying
+# information: Portions Copyright [yyyy] [name of copyright owner]
+#
+# CDDL HEADER END
+#
+
+#
+# Copyright 2007 Sun Microsystems, Inc.  All rights reserved.
+# Use is subject to license terms.
+#
+
+#
+# Copyright (c) 2013 by Delphix. All rights reserved.
+#
+
+. $STF_SUITE/include/libtest.shlib
+
+DISK=${DISKS%% *}
+
+default_container_setup $DISK
diff --git a/tests/zfs-tests/tests/functional/ctime/.gitignore b/tests/zfs-tests/tests/functional/ctime/.gitignore
new file mode 100644 (file)
index 0000000..ead826c
--- /dev/null
@@ -0,0 +1 @@
+/ctime_001_pos
diff --git a/tests/zfs-tests/tests/functional/ctime/Makefile.am b/tests/zfs-tests/tests/functional/ctime/Makefile.am
new file mode 100644 (file)
index 0000000..1c7c26d
--- /dev/null
@@ -0,0 +1,12 @@
+include $(top_srcdir)/config/Rules.am
+
+pkgdatadir = $(datadir)/@PACKAGE@/zfs-tests/tests/functional/ctime
+
+dist_pkgdata_SCRIPTS = \
+       cleanup.ksh \
+       setup.ksh
+
+pkgexecdir = $(datadir)/@PACKAGE@/zfs-tests/tests/functional/ctime
+
+pkgexec_PROGRAMS = ctime_001_pos
+ctime_001_pos_SOURCES = ctime_001_pos.c
diff --git a/tests/zfs-tests/tests/functional/ctime/cleanup.ksh b/tests/zfs-tests/tests/functional/ctime/cleanup.ksh
new file mode 100755 (executable)
index 0000000..3166bd6
--- /dev/null
@@ -0,0 +1,34 @@
+#!/bin/ksh -p
+#
+# CDDL HEADER START
+#
+# The contents of this file are subject to the terms of the
+# Common Development and Distribution License (the "License").
+# You may not use this file except in compliance with the License.
+#
+# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
+# or http://www.opensolaris.org/os/licensing.
+# See the License for the specific language governing permissions
+# and limitations under the License.
+#
+# When distributing Covered Code, include this CDDL HEADER in each
+# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
+# If applicable, add the following below this CDDL HEADER, with the
+# fields enclosed by brackets "[]" replaced with your own identifying
+# information: Portions Copyright [yyyy] [name of copyright owner]
+#
+# CDDL HEADER END
+#
+
+#
+# Copyright 2007 Sun Microsystems, Inc.  All rights reserved.
+# Use is subject to license terms.
+#
+
+#
+# Copyright (c) 2013 by Delphix. All rights reserved.
+#
+
+. $STF_SUITE/include/libtest.shlib
+
+default_cleanup
diff --git a/tests/zfs-tests/tests/functional/ctime/ctime_001_pos.c b/tests/zfs-tests/tests/functional/ctime/ctime_001_pos.c
new file mode 100644 (file)
index 0000000..0c0615f
--- /dev/null
@@ -0,0 +1,347 @@
+/*
+ * CDDL HEADER START
+ *
+ * The contents of this file are subject to the terms of the
+ * Common Development and Distribution License (the "License").
+ * You may not use this file except in compliance with the License.
+ *
+ * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
+ * or http://www.opensolaris.org/os/licensing.
+ * See the License for the specific language governing permissions
+ * and limitations under the License.
+ *
+ * When distributing Covered Code, include this CDDL HEADER in each
+ * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
+ * If applicable, add the following below this CDDL HEADER, with the
+ * fields enclosed by brackets "[]" replaced with your own identifying
+ * information: Portions Copyright [yyyy] [name of copyright owner]
+ *
+ * CDDL HEADER END
+ */
+
+/*
+ * Copyright 2007 Sun Microsystems, Inc.  All rights reserved.
+ * Use is subject to license terms.
+ */
+
+/*
+ * Copyright (c) 2013 by Delphix. All rights reserved.
+ */
+
+
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <utime.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <unistd.h>
+#include <strings.h>
+#include <errno.h>
+#include <fcntl.h>
+#include <libgen.h>
+#include <string.h>
+
+#define        ST_ATIME 0
+#define        ST_CTIME 1
+#define        ST_MTIME 2
+
+#define        ALL_MODE (mode_t)(S_IRWXU|S_IRWXG|S_IRWXO)
+
+typedef struct timetest {
+       int     type;
+       char    *name;
+       int     (*func)(const char *pfile);
+} timetest_t;
+
+static char tfile[BUFSIZ] = { 0 };
+
+/*
+ * DESCRIPTION:
+ *     Verify time will be changed correctly after each operation.
+ *
+ * STRATEGY:
+ *     1. Define time test array.
+ *     2. Loop through each item in this array.
+ *     3. Verify the time is changed after each operation.
+ *
+ */
+
+static int
+get_file_time(const char *pfile, int what, time_t *ptr)
+{
+       struct stat stat_buf;
+
+       if (pfile == NULL || ptr == NULL) {
+               return (-1);
+       }
+
+       if (stat(pfile, &stat_buf) == -1) {
+               return (-1);
+       }
+
+       switch (what) {
+               case ST_ATIME:
+                       *ptr = stat_buf.st_atime;
+                       return (0);
+               case ST_CTIME:
+                       *ptr = stat_buf.st_ctime;
+                       return (0);
+               case ST_MTIME:
+                       *ptr = stat_buf.st_mtime;
+                       return (0);
+               default:
+                       return (-1);
+       }
+}
+
+static int
+do_read(const char *pfile)
+{
+       int fd, ret = 0;
+       char buf[BUFSIZ] = { 0 };
+
+       if (pfile == NULL) {
+               return (-1);
+       }
+
+       if ((fd = open(pfile, O_RDONLY, ALL_MODE)) == -1) {
+               return (-1);
+       }
+       if (read(fd, buf, sizeof (buf)) == -1) {
+               (void) fprintf(stderr, "read(%d, buf, %zd) failed with errno "
+                   "%d\n", fd, sizeof (buf), errno);
+               return (1);
+       }
+       (void) close(fd);
+
+       return (ret);
+}
+
+static int
+do_write(const char *pfile)
+{
+       int fd, ret = 0;
+       char buf[BUFSIZ] = "call function do_write()";
+
+       if (pfile == NULL) {
+               return (-1);
+       }
+
+       if ((fd = open(pfile, O_WRONLY, ALL_MODE)) == -1) {
+               return (-1);
+       }
+       if (write(fd, buf, strlen(buf)) == -1) {
+               (void) fprintf(stderr, "write(%d, buf, %d) failed with errno "
+                   "%d\n", fd, (int)strlen(buf), errno);
+               return (1);
+       }
+       (void) close(fd);
+
+       return (ret);
+}
+
+static int
+do_link(const char *pfile)
+{
+       int ret = 0;
+       char link_file[BUFSIZ] = { 0 };
+       char *dname;
+
+       if (pfile == NULL) {
+               return (-1);
+       }
+
+       /*
+        * Figure out source file directory name, and create
+        * the link file in the same directory.
+        */
+       dname = dirname((char *)pfile);
+       (void) snprintf(link_file, BUFSIZ, "%s/%s", dname, "link_file");
+
+       if (link(pfile, link_file) == -1) {
+               (void) fprintf(stderr, "link(%s, %s) failed with errno %d\n",
+                   pfile, link_file, errno);
+               return (1);
+       }
+
+       (void) unlink(link_file);
+
+       return (ret);
+}
+
+static int
+do_creat(const char *pfile)
+{
+       int fd, ret = 0;
+
+       if (pfile == NULL) {
+               return (-1);
+       }
+
+       if ((fd = creat(pfile, ALL_MODE)) == -1) {
+               (void) fprintf(stderr, "creat(%s, ALL_MODE) failed with errno "
+                   "%d\n", pfile, errno);
+               return (1);
+       }
+       (void) close(fd);
+
+       return (ret);
+}
+
+static int
+do_utime(const char *pfile)
+{
+       int ret = 0;
+
+       if (pfile == NULL) {
+               return (-1);
+       }
+
+       /*
+        * Times of the file are set to the current time
+        */
+       if (utime(pfile, NULL) == -1) {
+               (void) fprintf(stderr, "utime(%s, NULL) failed with errno "
+                   "%d\n", pfile, errno);
+               return (1);
+       }
+
+       return (ret);
+}
+
+static int
+do_chmod(const char *pfile)
+{
+       int ret = 0;
+
+       if (pfile == NULL) {
+               return (-1);
+       }
+
+       if (chmod(pfile, ALL_MODE) == -1) {
+               (void) fprintf(stderr, "chmod(%s, ALL_MODE) failed with "
+                   "errno %d\n", pfile, errno);
+               return (1);
+       }
+
+       return (ret);
+}
+
+static int
+do_chown(const char *pfile)
+{
+       int ret = 0;
+
+       if (pfile == NULL) {
+               return (-1);
+       }
+
+       if (chown(pfile, getuid(), getgid()) == -1) {
+               (void) fprintf(stderr, "chown(%s, %d, %d) failed with errno "
+                   "%d\n", pfile, (int)getuid(), (int)getgid(), errno);
+               return (1);
+       }
+
+       return (ret);
+}
+
+static void
+cleanup(void)
+{
+       if ((strlen(tfile) != 0) && (access(tfile, F_OK) == 0)) {
+               (void) unlink(tfile);
+       }
+}
+
+static timetest_t timetest_table[] = {
+       { ST_ATIME,     "st_atime",     do_read         },
+       { ST_ATIME,     "st_atime",     do_utime        },
+       { ST_MTIME,     "st_mtime",     do_creat        },
+       { ST_MTIME,     "st_mtime",     do_write        },
+       { ST_MTIME,     "st_mtime",     do_utime        },
+       { ST_CTIME,     "st_ctime",     do_creat        },
+       { ST_CTIME,     "st_ctime",     do_write        },
+       { ST_CTIME,     "st_ctime",     do_chmod        },
+       { ST_CTIME,     "st_ctime",     do_chown        },
+       { ST_CTIME,     "st_ctime",     do_link         },
+       { ST_CTIME,     "st_ctime",     do_utime        },
+};
+
+#define        NCOMMAND (sizeof (timetest_table) / sizeof (timetest_table[0]))
+
+/* ARGSUSED */
+int
+main(int argc, char *argv[])
+{
+       int i, ret, fd;
+       char *penv[] = {"TESTDIR", "TESTFILE0"};
+
+       (void) fprintf(stdout, "Verify [acm]time is modified appropriately.\n");
+       (void) atexit(cleanup);
+
+       /*
+        * Get the environment variable values.
+        */
+       for (i = 0; i < sizeof (penv) / sizeof (char *); i++) {
+               if ((penv[i] = getenv(penv[i])) == NULL) {
+                       (void) fprintf(stderr, "getenv(penv[%d])\n", i);
+                       return (1);
+               }
+       }
+       (void) snprintf(tfile, sizeof (tfile), "%s/%s", penv[0], penv[1]);
+
+       /*
+        * If the test file is exists, remove it first.
+        */
+       if (access(tfile, F_OK) == 0) {
+               (void) unlink(tfile);
+       }
+       ret = 0;
+       if ((fd = open(tfile, O_WRONLY | O_CREAT | O_TRUNC, ALL_MODE)) == -1) {
+               (void) fprintf(stderr, "open(%s) failed: %d\n", tfile, errno);
+               return (1);
+       }
+       (void) close(fd);
+
+       for (i = 0; i < NCOMMAND; i++) {
+               time_t t1, t2;
+
+               /*
+                * Get original time before operating.
+                */
+               ret = get_file_time(tfile, timetest_table[i].type, &t1);
+               if (ret != 0) {
+                       (void) fprintf(stderr, "get_file_time(%s %d) = %d\n",
+                           tfile, timetest_table[i].type, ret);
+                       return (1);
+               }
+
+               /*
+                * Sleep 2 seconds, then invoke command on given file
+                */
+               (void) sleep(2);
+               timetest_table[i].func(tfile);
+
+               /*
+                * Get time after operating.
+                */
+               ret = get_file_time(tfile, timetest_table[i].type, &t2);
+               if (ret != 0) {
+                       (void) fprintf(stderr, "get_file_time(%s %d) = %d\n",
+                           tfile, timetest_table[i].type, ret);
+                       return (1);
+               }
+
+               if (t1 == t2) {
+                       (void) fprintf(stderr, "%s: t1(%ld) == t2(%ld)\n",
+                           timetest_table[i].name, (long)t1, (long)t2);
+                       return (1);
+               } else {
+                       (void) fprintf(stderr, "%s: t1(%ld) != t2(%ld)\n",
+                           timetest_table[i].name, (long)t1, (long)t2);
+               }
+       }
+
+       (void) fprintf(stdout, "PASS\n");
+       return (0);
+}
diff --git a/tests/zfs-tests/tests/functional/ctime/setup.ksh b/tests/zfs-tests/tests/functional/ctime/setup.ksh
new file mode 100755 (executable)
index 0000000..fc5cec3
--- /dev/null
@@ -0,0 +1,35 @@
+#!/bin/ksh -p
+#
+# CDDL HEADER START
+#
+# The contents of this file are subject to the terms of the
+# Common Development and Distribution License (the "License").
+# You may not use this file except in compliance with the License.
+#
+# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
+# or http://www.opensolaris.org/os/licensing.
+# See the License for the specific language governing permissions
+# and limitations under the License.
+#
+# When distributing Covered Code, include this CDDL HEADER in each
+# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
+# If applicable, add the following below this CDDL HEADER, with the
+# fields enclosed by brackets "[]" replaced with your own identifying
+# information: Portions Copyright [yyyy] [name of copyright owner]
+#
+# CDDL HEADER END
+#
+
+#
+# Copyright 2007 Sun Microsystems, Inc.  All rights reserved.
+# Use is subject to license terms.
+#
+
+#
+# Copyright (c) 2013 by Delphix. All rights reserved.
+#
+
+. $STF_SUITE/include/libtest.shlib
+
+DISK=${DISKS%% *}
+default_setup $DISK
diff --git a/tests/zfs-tests/tests/functional/delegate/Makefile.am b/tests/zfs-tests/tests/functional/delegate/Makefile.am
new file mode 100644 (file)
index 0000000..6ccd65d
--- /dev/null
@@ -0,0 +1,26 @@
+pkgdatadir = $(datadir)/@PACKAGE@/zfs-tests/tests/functional/delegate
+dist_pkgdata_SCRIPTS = \
+       delegate.cfg \
+       delegate_common.kshlib \
+       cleanup.ksh \
+       setup.ksh \
+       zfs_allow_001_pos.ksh \
+       zfs_allow_002_pos.ksh \
+       zfs_allow_003_pos.ksh \
+       zfs_allow_004_pos.ksh \
+       zfs_allow_005_pos.ksh \
+       zfs_allow_006_pos.ksh \
+       zfs_allow_007_pos.ksh \
+       zfs_allow_008_pos.ksh \
+       zfs_allow_009_neg.ksh \
+       zfs_allow_010_pos.ksh \
+       zfs_allow_011_neg.ksh \
+       zfs_allow_012_neg.ksh \
+       zfs_unallow_001_pos.ksh \
+       zfs_unallow_002_pos.ksh \
+       zfs_unallow_003_pos.ksh \
+       zfs_unallow_004_pos.ksh \
+       zfs_unallow_005_pos.ksh \
+       zfs_unallow_006_pos.ksh \
+       zfs_unallow_007_neg.ksh \
+       zfs_unallow_008_neg.ksh
diff --git a/tests/zfs-tests/tests/functional/delegate/cleanup.ksh b/tests/zfs-tests/tests/functional/delegate/cleanup.ksh
new file mode 100755 (executable)
index 0000000..c0a3e34
--- /dev/null
@@ -0,0 +1,44 @@
+#!/bin/ksh -p
+#
+# CDDL HEADER START
+#
+# The contents of this file are subject to the terms of the
+# Common Development and Distribution License (the "License").
+# You may not use this file except in compliance with the License.
+#
+# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
+# or http://www.opensolaris.org/os/licensing.
+# See the License for the specific language governing permissions
+# and limitations under the License.
+#
+# When distributing Covered Code, include this CDDL HEADER in each
+# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
+# If applicable, add the following below this CDDL HEADER, with the
+# fields enclosed by brackets "[]" replaced with your own identifying
+# information: Portions Copyright [yyyy] [name of copyright owner]
+#
+# CDDL HEADER END
+#
+
+#
+# Copyright 2007 Sun Microsystems, Inc.  All rights reserved.
+# Use is subject to license terms.
+#
+
+#
+# Copyright (c) 2013 by Delphix. All rights reserved.
+#
+
+. $STF_SUITE/tests/functional/delegate/delegate_common.kshlib
+
+cleanup_user_group
+
+# restore the state of svc:/network/nis/client:default
+if [[ -e $NISSTAFILE ]]; then
+       log_must $SVCADM enable svc:/network/nis/client:default
+       log_must $RM -f $NISSTAFILE
+fi
+
+default_cleanup
+
+log_pass
diff --git a/tests/zfs-tests/tests/functional/delegate/delegate.cfg b/tests/zfs-tests/tests/functional/delegate/delegate.cfg
new file mode 100644 (file)
index 0000000..57ec0a5
--- /dev/null
@@ -0,0 +1,59 @@
+#
+# CDDL HEADER START
+#
+# The contents of this file are subject to the terms of the
+# Common Development and Distribution License (the "License").
+# You may not use this file except in compliance with the License.
+#
+# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
+# or http://www.opensolaris.org/os/licensing.
+# See the License for the specific language governing permissions
+# and limitations under the License.
+#
+# When distributing Covered Code, include this CDDL HEADER in each
+# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
+# If applicable, add the following below this CDDL HEADER, with the
+# fields enclosed by brackets "[]" replaced with your own identifying
+# information: Portions Copyright [yyyy] [name of copyright owner]
+#
+# CDDL HEADER END
+#
+
+#
+# Copyright 2008 Sun Microsystems, Inc.  All rights reserved.
+# Use is subject to license terms.
+#
+
+#
+# Copyright (c) 2013 by Delphix. All rights reserved.
+#
+
+export NISSTAFILE=/var/tmp/nis_state
+
+export STAFF_GROUP=zfsgrp
+export STAFF1=staff1
+export STAFF2=staff2
+
+export OTHER_GROUP=othergrp
+export OTHER1=other1
+export OTHER2=other2
+
+export EVERYONE="$STAFF1 $STAFF2 $OTHER1 $OTHER2"
+
+export LOCAL_SET="snapshot"
+export LOCAL_DESC_SET="readonly,checksum"
+export DESC_SET="compression"
+
+export TESTVOL=testvol.delegate
+export VOLSIZE=150m
+
+export ROOT_TESTVOL=$TESTPOOL/$TESTVOL
+export ROOT_TESTFS=$TESTPOOL/$TESTFS
+export SUBFS=$ROOT_TESTFS/SUBFS
+export SUBFS2=$ROOT_TESTFS/SUBFS2
+
+DATASETS="$ROOT_TESTFS"
+if is_global_zone ; then
+       DATASETS=$DATASETS
+fi
+export DATASETS
diff --git a/tests/zfs-tests/tests/functional/delegate/delegate_common.kshlib b/tests/zfs-tests/tests/functional/delegate/delegate_common.kshlib
new file mode 100644 (file)
index 0000000..d4b7733
--- /dev/null
@@ -0,0 +1,1679 @@
+#
+# CDDL HEADER START
+#
+# The contents of this file are subject to the terms of the
+# Common Development and Distribution License (the "License").
+# You may not use this file except in compliance with the License.
+#
+# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
+# or http://www.opensolaris.org/os/licensing.
+# See the License for the specific language governing permissions
+# and limitations under the License.
+#
+# When distributing Covered Code, include this CDDL HEADER in each
+# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
+# If applicable, add the following below this CDDL HEADER, with the
+# fields enclosed by brackets "[]" replaced with your own identifying
+# information: Portions Copyright [yyyy] [name of copyright owner]
+#
+# CDDL HEADER END
+#
+
+#
+# Copyright 2008 Sun Microsystems, Inc.  All rights reserved.
+# Use is subject to license terms.
+#
+
+#
+# Copyright (c) 2013 by Delphix. All rights reserved.
+# Copyright 2016 Nexenta Systems, Inc.
+#
+
+. $STF_SUITE/include/libtest.shlib
+. $STF_SUITE/tests/functional/delegate/delegate.cfg
+
+#
+# Cleanup exist user/group.
+#
+function cleanup_user_group
+{
+       typeset i
+       for i in $STAFF1 $STAFF2 $OTHER1 $OTHER2 ; do
+               del_user $i
+       done
+       for i in $STAFF_GROUP $OTHER_GROUP ; do
+               del_group $i
+       done
+
+       return 0
+}
+
+#
+# Restore test file system to the original status.
+#
+function restore_root_datasets
+{
+       if datasetexists $ROOT_TESTFS ; then
+               log_must $ZFS destroy -Rf $ROOT_TESTFS
+       fi
+       log_must $ZFS create $ROOT_TESTFS
+
+       if is_global_zone ; then
+               if datasetexists $ROOT_TESTVOL ; then
+                       log_must $ZFS destroy -Rf $ROOT_TESTVOL
+               fi
+               log_must $ZFS create -V $VOLSIZE $ROOT_TESTVOL
+       fi
+
+       return 0
+}
+
+#
+# Verify the specified user have permission on the dataset
+#
+# $1 dataset
+# $2 permissions which are separated by comma(,)
+# $3-n users
+#
+function verify_perm
+{
+       typeset dtst=$1
+       typeset permissions=$2
+       shift 2
+
+       if [[ -z $@ || -z $permissions || -z $dtst ]]; then
+               return 1
+       fi
+
+       typeset type=$(get_prop type $dtst)
+       permissions=$($ECHO $permissions | $TR -s "," " ")
+
+       typeset user
+       for user in $@; do
+               typeset perm
+               for perm in $permissions; do
+                       typeset -i ret=1
+                       if [[ $type == "filesystem" ]]; then
+                               check_fs_perm $user $perm $dtst
+                               ret=$?
+                       elif [[ $type == "volume" ]]; then
+                               check_vol_perm $user $perm $dtst
+                               ret=$?
+                       fi
+
+                       if ((ret != 0)) ; then
+                               log_note "Fail: $user should have $perm " \
+                                       "on $dtst"
+                               return 1
+                       fi
+               done
+       done
+
+       return 0
+}
+
+#
+# Verify the specified user have no permission on the dataset
+#
+# $1 dataset
+# $2 permissions which are separated by comma(,)
+# $3-n users
+#
+function verify_noperm
+{
+       typeset dtst=$1
+       typeset permissions=$2
+       shift 2
+
+       if [[ -z $@ || -z $permissions || -z $dtst ]]; then
+               return 1
+       fi
+
+       typeset type=$(get_prop type $dtst)
+       permissions=$($ECHO $permissions | $TR -s "," " ")
+
+       typeset user
+       for user in $@; do
+               typeset perm
+               for perm in $permissions; do
+                       typeset -i ret=1
+                       if [[ $type == "filesystem" ]]; then
+                               check_fs_perm $user $perm $dtst
+                               ret=$?
+                       elif [[ $type == "volume" ]]; then
+                               check_vol_perm $user $perm $dtst
+                               ret=$?
+                       fi
+
+                       if ((ret == 0)) ; then
+                               log_note "Fail: $user should not have $perm " \
+                                       "on $dtst"
+                               return 1
+                       fi
+               done
+       done
+
+       return 0
+}
+
+function common_perm
+{
+       typeset user=$1
+       typeset perm=$2
+       typeset dtst=$3
+
+       typeset -i ret=1
+       case $perm in
+               send)
+                       verify_send $user $perm $dtst
+                       ret=$?
+                       ;;
+               allow)
+                       verify_allow $user $perm $dtst
+                       ret=$?
+                       ;;
+               userprop)
+                       verify_userprop $user $perm $dtst
+                       ret=$?
+                       ;;
+               compression|checksum|readonly)
+                       verify_ccr $user $perm $dtst
+                       ret=$?
+                       ;;
+               copies)
+                       verify_copies $user $perm $dtst
+                       ret=$?
+                       ;;
+               reservation)
+                       verify_reservation $user $perm $dtst
+                       ret=$?
+                       ;;
+               *)
+                       ret=1
+                       ;;
+       esac
+
+       return $ret
+}
+
+function check_fs_perm
+{
+       typeset user=$1
+       typeset perm=$2
+       typeset fs=$3
+
+       typeset -i ret=1
+       case $perm in
+               create)
+                       verify_fs_create $user $perm $fs
+                       ret=$?
+                       ;;
+               destroy)
+                       verify_fs_destroy $user $perm $fs
+                       ret=$?
+                       ;;
+               snapshot)
+                       verify_fs_snapshot $user $perm $fs
+                       ret=$?
+                       ;;
+               rollback)
+                       verify_fs_rollback $user $perm $fs
+                       ret=$?
+                       ;;
+               clone)
+                       verify_fs_clone $user $perm $fs
+                       ret=$?
+                       ;;
+               rename)
+                       verify_fs_rename $user $perm $fs
+                       ret=$?
+                       ;;
+               mount)
+                       verify_fs_mount $user $perm $fs
+                       ret=$?
+                       ;;
+               share)
+                       verify_fs_share $user $perm $fs
+                       ret=$?
+                       ;;
+               mountpoint)
+                       verify_fs_mountpoint $user $perm $fs
+                       ret=$?
+                       ;;
+               promote)
+                       verify_fs_promote $user $perm $fs
+                       ret=$?
+                       ;;
+               canmount)
+                       verify_fs_canmount $user $perm $fs
+                       ret=$?
+                       ;;
+               recordsize)
+                       verify_fs_recordsize $user $perm $fs
+                       ret=$?
+                       ;;
+               quota)
+                       verify_fs_quota $user $perm $fs
+                       ret=$?
+                       ;;
+               aclmode)
+                       verify_fs_aclmode $user $perm $fs
+                       ret=$?
+                       ;;
+               aclinherit)
+                       verify_fs_aclinherit $user $perm $fs
+                       ret=$?
+                       ;;
+               snapdir)
+                       verify_fs_snapdir $user $perm $fs
+                       ret=$?
+                       ;;
+               atime|exec|devices|setuid|xattr)
+                       verify_fs_aedsx $user $perm $fs
+                       ret=$?
+                       ;;
+               zoned)
+                       verify_fs_zoned $user $perm $fs
+                       ret=$?
+                       ;;
+               sharenfs)
+                       verify_fs_sharenfs $user $perm $fs
+                       ret=$?
+                       ;;
+               receive)
+                       verify_fs_receive $user $perm $fs
+                       ret=$?
+                       ;;
+               *)
+                       common_perm $user $perm $fs
+                       ret=$?
+                       ;;
+       esac
+
+       return $ret
+}
+
+function check_vol_perm
+{
+       typeset user=$1
+       typeset perm=$2
+       typeset vol=$3
+
+       typeset -i ret=1
+       case $perm in
+               destroy)
+                       verify_vol_destroy $user $perm $vol
+                       ret=$?
+                       ;;
+               snapshot)
+                       verify_vol_snapshot $user $perm $vol
+                       ret=$?
+                       ;;
+               rollback)
+                       verify_vol_rollback $user $perm $vol
+                       ret=$?
+                       ;;
+               clone)
+                       verify_vol_clone $user $perm $vol
+                       ret=$?
+                       ;;
+               rename)
+                       verify_vol_rename $user $perm $vol
+                       ret=$?
+                       ;;
+               promote)
+                       verify_vol_promote $user $perm $vol
+                       ret=$?
+                       ;;
+               volsize)
+                       verify_vol_volsize $user $perm $vol
+                       ret=$?
+                       ;;
+               *)
+                       common_perm $user $perm $vol
+                       ret=$?
+                       ;;
+       esac
+
+       return $ret
+}
+
+function setup_unallow_testenv
+{
+       log_must restore_root_datasets
+
+       log_must $ZFS create $SUBFS
+
+       for dtst in $DATASETS ; do
+               log_must $ZFS allow -l $STAFF1 $LOCAL_SET $dtst
+               log_must $ZFS allow -d $STAFF2 $DESC_SET  $dtst
+               log_must $ZFS allow $OTHER1 $LOCAL_DESC_SET $dtst
+               log_must $ZFS allow $OTHER2 $LOCAL_DESC_SET $dtst
+
+               log_must verify_perm $dtst $LOCAL_SET $STAFF1
+               log_must verify_perm $dtst $LOCAL_DESC_SET $OTHER1
+               log_must verify_perm $dtst $LOCAL_DESC_SET $OTHER2
+               if [[ $dtst == $ROOT_TESTFS ]]; then
+                       log_must verify_perm $SUBFS $DESC_SET $STAFF2
+                       log_must verify_perm $SUBFS $LOCAL_DESC_SET $OTHER1
+                       log_must verify_perm $SUBFS $LOCAL_DESC_SET $OTHER2
+               fi
+       done
+
+       return 0
+}
+
+#
+# Verify permission send for specified user on the dataset
+# $1 user
+# $2 permission
+# $3 dataset
+#
+function verify_send
+{
+       typeset user=$1
+       typeset perm=$2
+       typeset dtst=$3
+
+       typeset oldval
+       typeset stamp=${perm}.${user}.$($DATE +'%F-%H%M%S')
+       typeset snap=$dtst@snap.$stamp
+
+       typeset -i ret=1
+
+       log_must $ZFS snapshot $snap
+       typeset bak_user=/tmp/bak.$user.$stamp
+       typeset bak_root=/tmp/bak.root.$stamp
+
+       user_run $user eval "$ZFS send $snap > $bak_user"
+       log_must eval "$ZFS send $snap > $bak_root"
+
+       if [[ $(checksum $bak_user) == $(checksum $bak_root) ]]; then
+               ret=0
+       fi
+
+       $RM -rf $bak_user > /dev/null
+       $RM -rf $bak_root > /dev/null
+
+       return $ret
+}
+
+function verify_fs_receive
+{
+       typeset user=$1
+       typeset perm=$2
+       typeset fs=$3
+
+       typeset dtst
+       typeset stamp=${perm}.${user}.$($DATE +'%F-%H%M%S')
+       typeset newfs=$fs/newfs.$stamp
+       typeset newvol=$fs/newvol.$stamp
+       typeset bak_user=/tmp/bak.$user.$stamp
+       typeset bak_root=/tmp/bak.root.$stamp
+
+       log_must $ZFS create $newfs
+       typeset datasets="$newfs"
+       if is_global_zone ; then
+               log_must $ZFS create -V $VOLSIZE $newvol
+               datasets="$newfs $newvol"
+       fi
+
+       for dtst in $datasets ; do
+
+               typeset dtstsnap=$dtst@snap.$stamp
+               log_must $ZFS snapshot $dtstsnap
+
+               log_must eval "$ZFS send $dtstsnap > $bak_root"
+               log_must $ZFS destroy -rf $dtst
+
+               user_run $user eval "$ZFS receive $dtst < $bak_root"
+               if datasetexists $dtstsnap ; then
+                       return 1
+               fi
+
+               log_must $ZFS allow $user create $fs
+               user_run $user eval "$ZFS receive $dtst < $bak_root"
+               log_must $ZFS unallow $user create $fs
+               if datasetexists $dtstsnap ; then
+                       return 1
+               fi
+
+               log_must $ZFS allow $user mount $fs
+               user_run $user eval "$ZFS receive $dtst < $bak_root"
+               log_must $ZFS unallow $user mount $fs
+               if datasetexists $dtstsnap ; then
+                       return 1
+               fi
+
+               log_must $ZFS allow $user mount,create $fs
+               user_run $user eval "$ZFS receive $dtst < $bak_root"
+               log_must $ZFS unallow $user mount,create $fs
+               if ! datasetexists $dtstsnap ; then
+                       return 1
+               fi
+
+               # check the data integrity
+               log_must eval "$ZFS send $dtstsnap > $bak_user"
+               log_must $ZFS destroy -rf $dtst
+               log_must eval "$ZFS receive $dtst < $bak_root"
+               log_must eval "$ZFS send $dtstsnap > $bak_root"
+               log_must $ZFS destroy -rf $dtst
+               if [[ $(checksum $bak_user) != $(checksum $bak_root) ]]; then
+                       return 1
+               fi
+
+               $RM -rf $bak_user > /dev/null
+               $RM -rf $bak_root > /dev/null
+
+       done
+
+       return 0
+}
+
+function verify_userprop
+{
+       typeset user=$1
+       typeset perm=$2
+       typeset dtst=$3
+
+       typeset stamp=${perm}.${user}.$($DATE +'%F-%H%M%S')
+
+       user_run $user $ZFS set "$user:ts=$stamp" $dtst
+       if [[ $stamp != $(get_prop "$user:ts" $dtst) ]]; then
+               return 1
+       fi
+
+       return 0
+}
+
+function verify_ccr
+{
+       typeset user=$1
+       typeset perm=$2
+       typeset dtst=$3
+
+       typeset oldval
+
+       set -A modes "on" "off"
+       oldval=$(get_prop $perm $dtst)
+       if [[ $oldval == "on" ]]; then
+               n=1
+       elif [[ $oldval == "off" ]]; then
+               n=0
+       fi
+       log_note "$user $ZFS set $perm=${modes[$n]} $dtst"
+       user_run $user $ZFS set $perm=${modes[$n]} $dtst
+       if [[ ${modes[$n]} != $(get_prop $perm $dtst) ]]; then
+               return 1
+       fi
+
+       return 0
+}
+
+function verify_copies
+{
+       typeset user=$1
+       typeset perm=$2
+       typeset dtst=$3
+
+       typeset oldval
+
+       set -A modes 1 2 3
+       oldval=$(get_prop $perm $dtst)
+       if [[ $oldval -eq 1 ]]; then
+               n=1
+       elif [[ $oldval -eq 2 ]]; then
+               n=2
+       elif [[ $oldval -eq 3 ]]; then
+               n=0
+       fi
+       log_note "$user $ZFS set $perm=${modes[$n]} $dtst"
+       user_run $user $ZFS set $perm=${modes[$n]} $dtst
+       if [[ ${modes[$n]} != $(get_prop $perm $dtst) ]]; then
+               return 1
+       fi
+
+       return 0
+}
+
+function verify_reservation
+{
+       typeset user=$1
+       typeset perm=$2
+       typeset dtst=$3
+
+       typeset value32m=$(( 1024 * 1024 * 32 ))
+       typeset oldval=$(get_prop reservation $dtst)
+       user_run $user $ZFS set reservation=$value32m $dtst
+       if [[ $value32m != $(get_prop reservation $dtst) ]]; then
+               log_must $ZFS set reservation=$oldval $dtst
+               return 1
+       fi
+
+       log_must $ZFS set reservation=$oldval $dtst
+       return 0
+}
+
+function verify_fs_create
+{
+       typeset user=$1
+       typeset perm=$2
+       typeset fs=$3
+
+       typeset stamp=${perm}.${user}.$($DATE +'%F-%H%M%S')
+       typeset newfs=$fs/nfs.$stamp
+       typeset newvol=$fs/nvol.$stamp
+
+       user_run $user $ZFS create $newfs
+       if datasetexists $newfs ; then
+               return 1
+       fi
+
+       log_must $ZFS allow $user mount $fs
+       user_run $user $ZFS create $newfs
+       log_must $ZFS unallow $user mount $fs
+       if ! datasetexists $newfs ; then
+               return 1
+       fi
+
+       log_must $ZFS destroy $newfs
+
+       if is_global_zone ; then
+               # mount permission is required for sparse volume
+               user_run $user $ZFS create -V 150m -s $newvol
+               if datasetexists $newvol ; then
+                       return 1
+               fi
+
+               log_must $ZFS allow $user mount $fs
+               user_run $user $ZFS create -V 150m -s $newvol
+               log_must $ZFS unallow $user mount $fs
+               if ! datasetexists $newvol ; then
+                       return 1
+               fi
+               log_must $ZFS destroy $newvol
+
+               # mount and reserveration permission are
+               # required for normal volume
+               user_run $user $ZFS create -V 150m $newvol
+               if datasetexists $newvol ; then
+                       return 1
+               fi
+
+               log_must $ZFS allow $user mount $fs
+               user_run $user $ZFS create -V 150m $newvol
+               log_must $ZFS unallow $user mount $fs
+               if datasetexists $newvol ; then
+                       return 1
+               fi
+
+               log_must $ZFS allow $user reservation $fs
+               user_run $user $ZFS create -V 150m $newvol
+               log_must $ZFS unallow $user reservation $fs
+               if datasetexists $newvol ; then
+                       return 1
+               fi
+
+               log_must $ZFS allow $user refreservation $fs
+               user_run $user $ZFS create -V 150m $newvol
+               log_must $ZFS unallow $user refreservation $fs
+               if datasetexists $newvol ; then
+                       return 1
+               fi
+
+               log_must $ZFS allow $user mount $fs
+               log_must $ZFS allow $user reservation $fs
+               log_must $ZFS allow $user refreservation $fs
+               user_run $user $ZFS create -V 150m $newvol
+               log_must $ZFS unallow $user mount $fs
+               log_must $ZFS unallow $user reservation $fs
+               log_must $ZFS unallow $user refreservation $fs
+               if ! datasetexists $newvol ; then
+                       return 1
+               fi
+               log_must $ZFS destroy $newvol
+       fi
+
+       return 0
+}
+
+function verify_fs_destroy
+{
+       typeset user=$1
+       typeset perm=$2
+       typeset fs=$3
+
+       if ! ismounted $fs ; then
+               user_run $user $ZFS destroy $fs
+               if datasetexists $fs ; then
+                       return 1
+               fi
+       fi
+
+       if ismounted $fs ; then
+               user_run $user $ZFS destroy $fs
+               if ! datasetexists $fs ; then
+                       return 1
+               fi
+
+               # mount permission is required
+               log_must $ZFS allow $user mount $fs
+               user_run $user $ZFS destroy $fs
+               if datasetexists $fs ; then
+                       return 1
+               fi
+       fi
+
+       return 0
+}
+
+# Verify that given the correct delegation, a regular user can:
+#      Take a snapshot of an unmounted dataset
+#      Take a snapshot of an mounted dataset
+#      Create a snapshot by making a directory in the .zfs/snapshot directory
+function verify_fs_snapshot
+{
+       typeset user=$1
+       typeset perm=$2
+       typeset fs=$3
+
+       typeset stamp=${perm}.${user}.$($DATE +'%F-%H%M%S')
+       typeset snap=$fs@snap.$stamp
+       typeset mntpt=$(get_prop mountpoint $fs)
+
+       if [[ "yes" == $(get_prop mounted $fs) ]]; then
+               log_must $ZFS umount $fs
+       fi
+
+       user_run $user $ZFS snapshot $snap
+       if ! datasetexists $snap ; then
+               return 1
+       fi
+       log_must $ZFS destroy $snap
+
+       if [[ "no" == $(get_prop mounted $fs) ]]; then
+               log_must $ZFS mount $fs
+       fi
+
+       user_run $user $ZFS snapshot $snap
+       if ! datasetexists $snap ; then
+               return 1
+       fi
+       log_must $ZFS destroy $snap
+
+       typeset snapdir=${mntpt}/.zfs/snapshot/snap.$stamp
+       user_run $user $MKDIR $snapdir
+       if ! datasetexists $snap ; then
+               return 1
+       fi
+       log_must $ZFS destroy $snap
+
+       return 0
+}
+
+function verify_fs_rollback
+{
+       typeset user=$1
+       typeset perm=$2
+       typeset fs=$3
+
+       typeset oldval
+       typeset stamp=${perm}.${user}.$($DATE +'%F-%H%M%S')
+       typeset snap=$fs@snap.$stamp
+       typeset mntpt=$(get_prop mountpoint $fs)
+
+       oldval=$(datasetcksum $fs)
+       log_must $ZFS snapshot $snap
+
+       if ! ismounted $fs; then
+               log_must $ZFS mount $fs
+       fi
+       log_must $TOUCH $mntpt/testfile.$stamp
+
+       user_run $user $ZFS rollback -R $snap
+       if is_global_zone ; then
+               if [[ $oldval != $(datasetcksum $fs) ]]; then
+                       return 1
+               fi
+       else
+               # datasetcksum can not be used in local zone
+               if [[ -e $mntpt/testfile.$stamp ]]; then
+                       return 1
+               fi
+       fi
+
+       return 0
+}
+
+function verify_fs_clone
+{
+       typeset user=$1
+       typeset perm=$2
+       typeset fs=$3
+
+       typeset stamp=${perm}.${user}.$($DATE +'%F-%H%M%S')
+        typeset basefs=${fs%/*}
+       typeset snap=$fs@snap.$stamp
+       typeset clone=$basefs/cfs.$stamp
+
+       log_must $ZFS snapshot $snap
+       user_run $user $ZFS clone $snap $clone
+       if datasetexists $clone ; then
+               return 1
+       fi
+
+       log_must $ZFS allow $user create $basefs
+       user_run $user $ZFS clone $snap $clone
+       log_must $ZFS unallow $user create $basefs
+       if datasetexists $clone ; then
+               return 1
+       fi
+
+       log_must $ZFS allow $user mount $basefs
+       user_run $user $ZFS clone $snap $clone
+       log_must $ZFS unallow $user mount $basefs
+       if datasetexists $clone ; then
+               return 1
+       fi
+
+       log_must $ZFS allow $user mount $basefs
+       log_must $ZFS allow $user create $basefs
+       user_run $user $ZFS clone $snap $clone
+       log_must $ZFS unallow $user create $basefs
+       log_must $ZFS unallow $user mount $basefs
+       if ! datasetexists $clone ; then
+               return 1
+       fi
+
+       log_must $ZFS destroy -R $snap
+
+       return 0
+}
+
+function verify_fs_rename
+{
+       typeset user=$1
+       typeset perm=$2
+       typeset fs=$3
+
+       typeset stamp=${perm}.${user}.$($DATE +'%F-%H%M%S')
+        typeset basefs=${fs%/*}
+       typeset snap=$fs@snap.$stamp
+       typeset renamefs=$basefs/nfs.$stamp
+
+       if ! ismounted $fs; then
+               log_must $ZFS mount $fs
+       fi
+
+       # case 1
+       user_run $user $ZFS rename $fs $renamefs
+       if datasetexists $renamefs ; then
+               return 1
+       fi
+
+       # case 2
+       log_must $ZFS allow $user create $basefs
+       user_run $user $ZFS rename $fs $renamefs
+       log_must $ZFS unallow $user create $basefs
+       if datasetexists $renamefs ; then
+               return 1
+       fi
+
+       # case 3
+       log_must $ZFS allow $user mount $basefs
+       user_run $user $ZFS rename $fs $renamefs
+       log_must $ZFS unallow $user mount $basefs
+       if datasetexists $renamefs ; then
+               return 1
+       fi
+
+       # case 4
+       log_must $ZFS allow $user mount $fs
+       user_run $user $ZFS rename $fs $renamefs
+       if datasetexists $renamefs ; then
+               log_must $ZFS unallow $user mount $renamefs
+               return 1
+       fi
+       log_must $ZFS unallow $user mount $fs
+
+       # case 5
+       log_must $ZFS allow $user create $basefs
+       log_must $ZFS allow $user mount $fs
+       user_run $user $ZFS rename $fs $renamefs
+       log_must $ZFS unallow $user create $basefs
+       if datasetexists $renamefs ; then
+               log_must $ZFS unallow $user mount $renamefs
+               return 1
+       fi
+       log_must $ZFS unallow $user mount $fs
+
+       # case 6
+       log_must $ZFS allow $user mount $basefs
+       log_must $ZFS allow $user mount $fs
+       user_run $user $ZFS rename $fs $renamefs
+       log_must $ZFS unallow $user mount $basefs
+       if datasetexists $renamefs ; then
+               log_must $ZFS unallow $user mount $renamefs
+               return 1
+       fi
+       log_must $ZFS unallow $user mount $fs
+
+       # case 7
+       log_must $ZFS allow $user create $basefs
+       log_must $ZFS allow $user mount $basefs
+       user_run $user $ZFS rename $fs $renamefs
+       log_must $ZFS unallow $user mount $basefs
+       log_must $ZFS unallow $user create $basefs
+       if ! datasetexists $renamefs ; then
+               return 1
+       fi
+
+       log_must $ZFS rename $renamefs $fs
+
+       return 0
+}
+
+function verify_fs_mount
+{
+       typeset user=$1
+       typeset perm=$2
+       typeset fs=$3
+
+       typeset stamp=${perm}.${user}.$($DATE +'%F-%H%M%S')
+       typeset mntpt=$(get_prop mountpoint $fs)
+       typeset newmntpt=/tmp/mnt.$stamp
+
+       if ismounted $fs ; then
+               user_run $user $ZFS unmount $fs
+               if ismounted $fs ; then
+                       return 1
+               fi
+       fi
+
+       if ! ismounted $fs ; then
+               log_must $ZFS set mountpoint=$newmntpt $fs
+               log_must $RM -rf $newmntpt
+               log_must $MKDIR $newmntpt
+
+               user_run $user $ZFS mount $fs
+               if ismounted $fs ; then
+                       return 1
+               fi
+
+               # mountpoint's owner must be the user
+               log_must $CHOWN $user $newmntpt
+               user_run $user $ZFS mount $fs
+               if ! ismounted $fs ; then
+                       return 1
+               fi
+               log_must $ZFS umount $fs
+               log_must $RM -rf $newmntpt
+               log_must $ZFS set mountpoint=$mntpt $fs
+       fi
+
+       return 0
+}
+
+function verify_fs_share
+{
+       typeset user=$1
+       typeset perm=$2
+       typeset fs=$3
+       typeset -i ret=0
+
+       $SVCADM enable -rs nfs/server
+       typeset stat=$($SVCS -H -o STA nfs/server:default)
+       if [[ $stat != "ON" ]]; then
+               log_fail "Could not enable nfs/server"
+       fi
+
+       log_must $ZFS set sharenfs=on $fs
+       $ZFS unshare $fs
+
+       user_run $user $ZFS share $fs
+       if ! is_shared $fs; then
+               ret=1
+       fi
+
+       $ZFS unshare $fs
+       log_must $ZFS set sharenfs=off $fs
+
+       return $ret
+}
+
+function verify_fs_mountpoint
+{
+       typeset user=$1
+       typeset perm=$2
+       typeset fs=$3
+
+       typeset stamp=${perm}.${user}.$($DATE +'%F-%H%M%S')
+       typeset mntpt=$(get_prop mountpoint $fs)
+       typeset newmntpt=/tmp/mnt.$stamp
+
+       if ! ismounted $fs ; then
+               user_run $user $ZFS set mountpoint=$newmntpt $fs
+               if [[ $newmntpt != \
+                       $(get_prop mountpoint $fs) ]] ; then
+                       return 1
+               fi
+               log_must $ZFS set mountpoint=$mntpt $fs
+       fi
+
+       if ismounted $fs ; then
+               user_run $user $ZFS set mountpoint=$newmntpt $fs
+               if [[ $mntpt != $(get_prop mountpoint $fs) ]]; then
+                       return 1
+               fi
+
+               # require mount permission when fs is mounted
+               log_must $ZFS allow $user mount $fs
+               user_run $user $ZFS set mountpoint=$newmntpt $fs
+               log_must $ZFS unallow $user mount $fs
+               if [[ $newmntpt != \
+                       $(get_prop mountpoint $fs) ]] ; then
+                       return 1
+               fi
+               log_must $ZFS set mountpoint=$mntpt $fs
+       fi
+
+       return 0
+}
+
+function verify_fs_promote
+{
+       typeset user=$1
+       typeset perm=$2
+       typeset fs=$3
+
+       typeset stamp=${perm}.${user}.$($DATE +'%F-%H%M%S')
+        typeset basefs=${fs%/*}
+       typeset snap=$fs@snap.$stamp
+       typeset clone=$basefs/cfs.$stamp
+
+       log_must $ZFS snapshot $snap
+       log_must $ZFS clone $snap $clone
+       log_must $ZFS promote $clone
+
+       typeset fs_orig=$(get_prop origin $fs)
+       typeset clone_orig=$(get_prop origin $clone)
+
+       user_run $user $ZFS promote $fs
+       # promote should fail if original fs does not have
+       # promote permission
+       if [[ $fs_orig != $(get_prop origin $fs) || \
+               $clone_orig != $(get_prop origin $clone) ]]; then
+               return 1
+       fi
+
+       log_must $ZFS allow $user promote $clone
+       user_run $user $ZFS promote $fs
+       log_must $ZFS unallow $user promote $clone
+       if [[ $fs_orig != $(get_prop origin $fs) || \
+               $clone_orig != $(get_prop origin $clone) ]]; then
+               return 1
+       fi
+
+       log_must $ZFS allow $user mount $fs
+       user_run $user $ZFS promote $fs
+       log_must $ZFS unallow $user mount $fs
+       if [[ $fs_orig != $(get_prop origin $fs) || \
+               $clone_orig != $(get_prop origin $clone) ]]; then
+               return 1
+       fi
+
+       log_must $ZFS allow $user mount $fs
+       log_must $ZFS allow $user promote $clone
+       user_run $user $ZFS promote $fs
+       log_must $ZFS unallow $user promote $clone
+       log_must $ZFS unallow $user mount $fs
+       if [[ $snap != $(get_prop origin $clone) || \
+               $clone_orig != $(get_prop origin $fs) ]]; then
+               return 1
+       fi
+
+       return 0
+}
+
+function verify_fs_canmount
+{
+       typeset user=$1
+       typeset perm=$2
+       typeset fs=$3
+
+       typeset oldval
+       typeset stamp=${perm}.${user}.$($DATE +'%F-%H%M%S')
+
+       if ! ismounted $fs ; then
+               set -A modes "on" "off"
+               oldval=$(get_prop $perm $fs)
+               if [[ $oldval == "on" ]]; then
+                       n=1
+               elif [[ $oldval == "off" ]]; then
+                       n=0
+               fi
+               log_note "$user $ZFS set $perm=${modes[$n]} $fs"
+               user_run $user $ZFS set $perm=${modes[$n]} $fs
+               if [[ ${modes[$n]} != $(get_prop $perm $fs) ]]; then
+                       return 1
+               fi
+       fi
+
+
+       # fs is mounted
+       if ismounted $fs ; then
+               # property value does not change if
+               # no mount permission
+               set -A modes "on" "off"
+               oldval=$(get_prop $perm $fs)
+               if [[ $oldval == "on" ]]; then
+                       n=1
+               elif [[ $oldval == "off" ]]; then
+                       n=0
+               fi
+               log_note "$user $ZFS set $perm=${modes[$n]} $fs"
+               log_must $ZFS allow $user mount $fs
+               user_run $user $ZFS set $perm=${modes[$n]} $fs
+               log_must $ZFS unallow $user mount $fs
+               if [[ ${modes[$n]} != $(get_prop $perm $fs) ]]; then
+                       return 1
+               fi
+       fi
+
+       return 0
+}
+
+function verify_fs_recordsize
+{
+       typeset user=$1
+       typeset perm=$2
+       typeset fs=$3
+
+       typeset value8k=$(( 1024 * 8 ))
+       user_run $user $ZFS set recordsize=$value8k $fs
+       if [[ $value8k != $(get_prop recordsize $fs) ]]; then
+               return 1
+       fi
+
+       return 0
+}
+
+function verify_fs_quota
+{
+       typeset user=$1
+       typeset perm=$2
+       typeset fs=$3
+
+       typeset value32m=$(( 1024 * 1024 * 32 ))
+       user_run $user $ZFS set quota=$value32m $fs
+       if [[ $value32m != $(get_prop quota $fs) ]]; then
+               return 1
+       fi
+
+       return 0
+}
+
+function verify_fs_aclmode
+{
+       typeset user=$1
+       typeset perm=$2
+       typeset fs=$3
+
+       typeset oldval
+       set -A modes "discard" "groupmask" "passthrough"
+       oldval=$(get_prop $perm $fs)
+       if [[ $oldval == "discard" ]]; then
+               n=1
+       elif [[ $oldval == "groupmask" ]]; then
+               n=2
+       elif [[ $oldval == "passthrough" ]]; then
+               n=0
+       fi
+       log_note "$user $ZFS set aclmode=${modes[$n]} $fs"
+       user_run $user $ZFS set aclmode=${modes[$n]} $fs
+       if [[ ${modes[$n]} != $(get_prop aclmode $fs) ]]; then
+               return 1
+       fi
+
+       return 0
+}
+
+function verify_fs_aclinherit
+{
+       typeset user=$1
+       typeset perm=$2
+       typeset fs=$3
+
+       #
+       # PSARC/2008/231 change the default value of aclinherit to "restricted"
+       # but still keep the old interface of "secure"
+       #
+
+       typeset oldval
+       set -A modes "discard" "noallow" "secure" "passthrough"
+       oldval=$(get_prop $perm $fs)
+       if [[ $oldval == "discard" ]]; then
+               n=1
+       elif [[ $oldval == "noallow" ]]; then
+               n=2
+       elif [[ $oldval == "secure" || $oldval == "restricted" ]]; then
+               n=3
+       elif [[ $oldval == "passthrough" ]]; then
+               n=0
+       fi
+       log_note "$user $ZFS set aclinherit=${modes[$n]} $fs"
+       user_run $user $ZFS set aclinherit=${modes[$n]} $fs
+
+       typeset newval=$(get_prop aclinherit $fs)
+       if [[ ${modes[$n]} == "secure" && $newval == "restricted" ]]; then
+               return 0
+       elif [[ ${modes[$n]} != $(get_prop aclinherit $fs) ]]; then
+               return 1
+       fi
+
+       return 0
+}
+
+function verify_fs_snapdir
+{
+       typeset user=$1
+       typeset perm=$2
+       typeset fs=$3
+
+       typeset oldval
+       set -A modes "visible" "hidden"
+       oldval=$(get_prop $perm $fs)
+       if [[ $oldval == "visible" ]]; then
+               n=1
+       elif [[ $oldval == "hidden" ]]; then
+               n=0
+       fi
+       log_note "$user $ZFS set snapdir=${modes[$n]} $fs"
+       user_run $user $ZFS set snapdir=${modes[$n]} $fs
+       if [[ ${modes[$n]} != $(get_prop snapdir $fs) ]]; then
+               return 1
+       fi
+
+       return 0
+}
+
+function verify_fs_aedsx
+{
+       typeset user=$1
+       typeset perm=$2
+       typeset fs=$3
+
+       typeset oldval
+       set -A modes "on" "off"
+       oldval=$(get_prop $perm $fs)
+       if [[ $oldval == "on" ]]; then
+               n=1
+       elif [[ $oldval == "off" ]]; then
+               n=0
+       fi
+       log_note "$user $ZFS set $perm=${modes[$n]} $fs"
+       user_run $user $ZFS set $perm=${modes[$n]} $fs
+       if [[ ${modes[$n]} != $(get_prop $perm $fs) ]]; then
+               return 1
+       fi
+
+       return 0
+}
+
+function verify_fs_zoned
+{
+       typeset user=$1
+       typeset perm=$2
+       typeset fs=$3
+
+       typeset oldval
+       set -A modes "on" "off"
+       oldval=$(get_prop $perm $fs)
+       if [[ $oldval == "on" ]]; then
+               n=1
+       elif [[ $oldval == "off" ]]; then
+               n=0
+       fi
+       log_note "$user $ZFS set $perm=${modes[$n]} $fs"
+       if is_global_zone ; then
+               if ! ismounted $fs ; then
+                       user_run $user $ZFS set \
+                               $perm=${modes[$n]} $fs
+                       if [[ ${modes[$n]} != \
+                               $(get_prop $perm $fs) ]]; then
+                               return 1
+                       fi
+                       if [[ $n -eq 0 ]]; then
+                               log_mustnot $ZFS mount $fs
+                       else
+                               log_must $ZFS mount $fs
+                       fi
+               fi
+
+               if ismounted $fs; then
+                       # n always is 1 in this case
+                       user_run $user $ZFS set \
+                               $perm=${modes[$n]} $fs
+                       if [[ $oldval != \
+                               $(get_prop $perm $fs) ]]; then
+                               return 1
+                       fi
+
+                       # mount permission is needed
+                       # to make zoned=on
+                       log_must $ZFS allow $user mount $fs
+                       user_run $user $ZFS set \
+                               $perm=${modes[$n]} $fs
+                       log_must $ZFS unallow $user mount $fs
+                       if [[ ${modes[$n]} != \
+                               $(get_prop $perm $fs) ]]; then
+                               return 1
+                       fi
+               fi
+       fi
+
+       if ! is_global_zone; then
+               user_run $user $ZFS set $perm=${modes[$n]} $fs
+               if [[ $oldval != $(get_prop $perm $fs) ]]; then
+                       return 1
+               fi
+       fi
+
+       return 0
+}
+
+function verify_fs_sharenfs
+{
+       typeset user=$1
+       typeset perm=$2
+       typeset fs=$3
+       typeset nmode omode
+
+       omode=$(get_prop $perm $fs)
+       if [[ $omode == "off" ]]; then
+               nmode="on"
+       else
+               nmode="off"
+       fi
+
+       log_note "$user $ZFS set $perm=$nmode $fs"
+       user_run $user $ZFS set $perm=$nmode $fs
+       if [[ $(get_prop $perm $fs) != $nmode ]]; then
+               return 1
+       fi
+
+       log_note "$user $ZFS set $perm=$omode $fs"
+       user_run $user $ZFS set $perm=$omode $fs
+       if [[ $(get_prop $perm $fs) != $omode ]]; then
+               return 1
+       fi
+
+       return 0
+}
+
+function verify_vol_destroy
+{
+       typeset user=$1
+       typeset perm=$2
+       typeset vol=$3
+
+       user_run $user $ZFS destroy $vol
+       if ! datasetexists $vol ; then
+               return 1
+       fi
+
+       # mount permission is required
+       log_must $ZFS allow $user mount $vol
+       user_run $user $ZFS destroy $vol
+       if datasetexists $vol ; then
+               return 1
+       fi
+
+       return 0
+}
+
+function verify_vol_snapshot
+{
+       typeset user=$1
+       typeset perm=$2
+       typeset vol=$3
+
+       typeset stamp=${perm}.${user}.$($DATE +'%F-%H%M%S')
+        typeset basevol=${vol%/*}
+       typeset snap=$vol@snap.$stamp
+
+       user_run $user $ZFS snapshot $snap
+       if datasetexists $snap ; then
+               return 1
+       fi
+
+       log_must $ZFS allow $user mount $vol
+       user_run $user $ZFS snapshot $snap
+       log_must $ZFS unallow $user mount $vol
+       if ! datasetexists $snap ; then
+               return 1
+       fi
+
+       return 0
+}
+
+function verify_vol_rollback
+{
+       typeset user=$1
+       typeset perm=$2
+       typeset vol=$3
+
+       typeset stamp=${perm}.${user}.$($DATE +'%F-%H%M%S')
+        typeset basevol=${vol%/*}
+       typeset snap=$vol@snap.$stamp
+
+       typeset oldval
+       log_must $ZFS snapshot $snap
+       oldval=$(datasetcksum $vol)
+
+       log_must $DD if=/dev/urandom of=$ZVOL_RDEVDIR/$vol \
+               bs=512 count=1
+
+       user_run $user $ZFS rollback -R $snap
+       $SLEEP 10
+       if [[ $oldval == $(datasetcksum $vol) ]]; then
+               return 1
+       fi
+
+       # rollback on volume has to be with mount permission
+       log_must $ZFS allow $user mount $vol
+       user_run $user $ZFS rollback -R $snap
+       $SLEEP 10
+       log_must $ZFS unallow $user mount $vol
+       if [[ $oldval != $(datasetcksum $vol) ]]; then
+               return 1
+       fi
+
+       return 0
+}
+
+function verify_vol_clone
+{
+       typeset user=$1
+       typeset perm=$2
+       typeset vol=$3
+
+       typeset stamp=${perm}.${user}.$($DATE +'%F-%H%M%S')
+        typeset basevol=${vol%/*}
+       typeset snap=$vol@snap.$stamp
+       typeset clone=$basevol/cvol.$stamp
+
+       log_must $ZFS snapshot $snap
+
+       user_run $user $ZFS clone $snap $clone
+       if datasetexists $clone ; then
+               return 1
+       fi
+
+       log_must $ZFS allow $user create $basevol
+       user_run $user $ZFS clone $snap $clone
+       log_must $ZFS unallow $user create $basevol
+       if datasetexists $clone ; then
+               return 1
+       fi
+
+       log_must $ZFS allow $user mount $basevol
+       user_run $user $ZFS clone $snap $clone
+       log_must $ZFS unallow $user mount $basevol
+       if datasetexists $clone ; then
+               return 1
+       fi
+
+       # require create permission on parent and
+       # mount permission on itself as well
+       log_must $ZFS allow $user mount $basevol
+       log_must $ZFS allow $user create $basevol
+       user_run $user $ZFS clone $snap $clone
+       log_must $ZFS unallow $user create $basevol
+       log_must $ZFS unallow $user mount $basevol
+       if ! datasetexists $clone ; then
+               return 1
+       fi
+
+       return 0
+}
+
+function verify_vol_rename
+{
+       typeset user=$1
+       typeset perm=$2
+       typeset vol=$3
+
+       typeset stamp=${perm}.${user}.$($DATE +'%F-%H%M%S')
+        typeset basevol=${vol%/*}
+       typeset snap=$vol@snap.$stamp
+       typeset clone=$basevol/cvol.$stamp
+       typeset renamevol=$basevol/nvol.$stamp
+
+       user_run $user $ZFS rename $vol $renamevol
+       if datasetexists $renamevol ; then
+               return 1
+       fi
+
+       log_must $ZFS allow $user create $basevol
+       user_run $user $ZFS rename $vol $renamevol
+       log_must $ZFS unallow $user create $basevol
+       if datasetexists $renamevol ; then
+               return 1
+       fi
+
+       log_must $ZFS allow $user mount $basevol
+       user_run $user $ZFS rename $vol $renamevol
+       log_must $ZFS unallow $user mount $basevol
+       if datasetexists $renamevol ; then
+               return 1
+       fi
+
+       # require both create permission on parent and
+       # mount permission on parent as well
+       log_must $ZFS allow $user mount $basevol
+       log_must $ZFS allow $user create $basevol
+       user_run $user $ZFS rename $vol $renamevol
+       log_must $ZFS unallow $user mount $basevol
+       log_must $ZFS unallow $user create $basevol
+       if ! datasetexists $renamevol ; then
+               return 1
+       fi
+
+       log_must $ZFS rename $renamevol $vol
+
+       return 0
+}
+
+function verify_vol_promote
+{
+       typeset user=$1
+       typeset perm=$2
+       typeset vol=$3
+
+       typeset stamp=${perm}.${user}.$($DATE +'%F-%H%M%S')
+        typeset basevol=${vol%/*}
+       typeset snap=$vol@snap.$stamp
+       typeset clone=$basevol/cvol.$stamp
+
+       log_must $ZFS snapshot $snap
+       log_must $ZFS clone $snap $clone
+       log_must $ZFS promote $clone
+
+       typeset vol_orig=$(get_prop origin $vol)
+       typeset clone_orig=$(get_prop origin $clone)
+
+       # promote should fail if $vol and $clone
+       # miss either mount or promote permission
+       # case 1
+       user_run $user $ZFS promote $vol
+       if [[ $vol_orig != $(get_prop origin $vol) || \
+               $clone_orig != $(get_prop origin $clone) ]];
+       then
+               return 1
+       fi
+
+       # promote should fail if $vol and $clone
+       # miss either mount or promote permission
+       # case 2
+       log_must $ZFS allow $user promote $clone
+       user_run $user $ZFS promote $vol
+       log_must $ZFS unallow $user promote $clone
+       if [[ $vol_orig != $(get_prop origin $vol) || \
+               $clone_orig != $(get_prop origin $clone) ]];
+       then
+               return 1
+       fi
+
+       # promote should fail if $vol and $clone
+       # miss either mount or promote permission
+       # case 3
+       log_must $ZFS allow $user mount $vol
+       user_run $user $ZFS promote $vol
+       log_must $ZFS unallow $user mount $vol
+       if [[ $vol_orig != $(get_prop origin $vol) || \
+               $clone_orig != $(get_prop origin $clone) ]];
+       then
+               return 1
+       fi
+
+       # promote should fail if $vol and $clone
+       # miss either mount or promote permission
+       # case 4
+       log_must $ZFS allow $user mount $clone
+       user_run $user $ZFS promote $vol
+       log_must $ZFS unallow $user mount $clone
+       if [[ $vol_orig != $(get_prop origin $vol) || \
+               $clone_orig != $(get_prop origin $clone) ]];
+       then
+               return 1
+       fi
+
+       # promote should fail if $vol and $clone
+       # miss either mount or promote permission
+       # case 5
+       log_must $ZFS allow $user promote $clone
+       log_must $ZFS allow $user mount $vol
+       user_run $user $ZFS promote $vol
+       log_must $ZFS unallow $user promote $clone
+       log_must $ZFS unallow $user mount $vol
+       if [[ $vol_orig != $(get_prop origin $vol) || \
+               $clone_orig != $(get_prop origin $clone) ]];
+       then
+               return 1
+       fi
+
+       # promote should fail if $vol and $clone
+       # miss either mount or promote permission
+       # case 6
+       log_must $ZFS allow $user promote $clone
+       log_must $ZFS allow $user mount $clone
+       user_run $user $ZFS promote $vol
+       log_must $ZFS unallow $user promote $clone
+       log_must $ZFS unallow $user mount $vol
+       if [[ $vol_orig != $(get_prop origin $vol) || \
+               $clone_orig != $(get_prop origin $clone) ]];
+       then
+               return 1
+       fi
+
+       # promote should fail if $vol and $clone
+       # miss either mount or promote permission
+       # case 7
+       log_must $ZFS allow $user mount $vol
+       log_must $ZFS allow $user mount $clone
+       user_run $user $ZFS promote $vol
+       log_must $ZFS unallow $user mount $vol
+       log_must $ZFS unallow $user mount $clone
+       if [[ $vol_orig != $(get_prop origin $vol) || \
+               $clone_orig != $(get_prop origin $clone) ]];
+       then
+               return 1
+       fi
+
+       # promote only succeeds when $vol and $clone
+       # have both mount and promote permission
+       # case 8
+       log_must $ZFS allow $user promote $clone
+       log_must $ZFS allow $user mount $vol
+       log_must $ZFS allow $user mount $clone
+       user_run $user $ZFS promote $vol
+       log_must $ZFS unallow $user promote $clone
+       log_must $ZFS unallow $user mount $vol
+       log_must $ZFS unallow $user mount $clone
+       if [[ $snap != $(get_prop origin $clone) || \
+               $clone_orig != $(get_prop origin $vol) ]]; then
+               return 1
+       fi
+
+       return 0
+}
+
+function verify_vol_volsize
+{
+       typeset user=$1
+       typeset perm=$2
+       typeset vol=$3
+
+       typeset oldval
+       oldval=$(get_prop volsize $vol)
+       (( newval = oldval * 2 ))
+
+       reserv_size=$(get_prop refreservation $vol)
+
+       if [[ "0" == $reserv_size ]]; then
+               # sparse volume
+               user_run $user $ZFS set volsize=$newval $vol
+               if [[ $oldval == $(get_prop volsize $vol) ]];
+               then
+                       return 1
+               fi
+
+       else
+               # normal volume, reservation permission
+               # is required
+               user_run $user $ZFS set volsize=$newval $vol
+               if [[ $newval == $(get_prop volsize $vol) ]];
+               then
+                       return 1
+               fi
+
+               log_must $ZFS allow $user reservation $vol
+               log_must $ZFS allow $user refreservation $vol
+               user_run $user $ZFS set volsize=$newval $vol
+               log_must $ZFS unallow $user reservation $vol
+               log_must $ZFS unallow $user refreservation $vol
+               if [[ $oldval == $(get_prop volsize $vol) ]];
+               then
+                       return 1
+               fi
+       fi
+
+       return 0
+}
+
+function verify_allow
+{
+       typeset user=$1
+       typeset perm=$2
+       typeset dtst=$3
+
+       typeset -i ret
+
+       user_run $user $ZFS allow $user allow $dtst
+       ret=$?
+       if [[ $ret -eq 0 ]]; then
+               return 1
+       fi
+
+       log_must $ZFS allow $user copies $dtst
+       user_run $user $ZFS allow $user copies $dtst
+       ret=$?
+       log_must $ZFS unallow $user copies $dtst
+       if [[ $ret -eq 1 ]]; then
+               return 1
+       fi
+
+       return 0
+
+}
diff --git a/tests/zfs-tests/tests/functional/delegate/setup.ksh b/tests/zfs-tests/tests/functional/delegate/setup.ksh
new file mode 100755 (executable)
index 0000000..0e4a9ec
--- /dev/null
@@ -0,0 +1,59 @@
+#!/bin/ksh -p
+#
+# CDDL HEADER START
+#
+# The contents of this file are subject to the terms of the
+# Common Development and Distribution License (the "License").
+# You may not use this file except in compliance with the License.
+#
+# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
+# or http://www.opensolaris.org/os/licensing.
+# See the License for the specific language governing permissions
+# and limitations under the License.
+#
+# When distributing Covered Code, include this CDDL HEADER in each
+# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
+# If applicable, add the following below this CDDL HEADER, with the
+# fields enclosed by brackets "[]" replaced with your own identifying
+# information: Portions Copyright [yyyy] [name of copyright owner]
+#
+# CDDL HEADER END
+#
+
+#
+# Copyright 2007 Sun Microsystems, Inc.  All rights reserved.
+# Use is subject to license terms.
+#
+
+#
+# Copyright (c) 2013 by Delphix. All rights reserved.
+#
+
+. $STF_SUITE/tests/functional/delegate/delegate_common.kshlib
+
+# check svc:/network/nis/client:default state
+# disable it if the state is ON
+# and the state will be restored during cleanup.ksh
+log_must $RM -f $NISSTAFILE
+if [[ "ON" == $($SVCS -H -o sta svc:/network/nis/client:default) ]]; then
+       log_must $SVCADM disable -t svc:/network/nis/client:default
+       log_must $TOUCH $NISSTAFILE
+fi
+
+cleanup_user_group
+
+# Create staff group and add two user to it
+log_must add_group $STAFF_GROUP
+log_must add_user $STAFF_GROUP $STAFF1
+log_must add_user $STAFF_GROUP $STAFF2
+
+# Create other group and add two user to it
+log_must add_group $OTHER_GROUP
+log_must add_user $OTHER_GROUP $OTHER1
+log_must add_user $OTHER_GROUP $OTHER2
+
+DISK=${DISKS%% *}
+default_volume_setup $DISK
+log_must $CHMOD 777 $TESTDIR
+
+log_pass
diff --git a/tests/zfs-tests/tests/functional/delegate/zfs_allow_001_pos.ksh b/tests/zfs-tests/tests/functional/delegate/zfs_allow_001_pos.ksh
new file mode 100755 (executable)
index 0000000..32b1a88
--- /dev/null
@@ -0,0 +1,98 @@
+#!/bin/ksh -p
+#
+# CDDL HEADER START
+#
+# The contents of this file are subject to the terms of the
+# Common Development and Distribution License (the "License").
+# You may not use this file except in compliance with the License.
+#
+# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
+# or http://www.opensolaris.org/os/licensing.
+# See the License for the specific language governing permissions
+# and limitations under the License.
+#
+# When distributing Covered Code, include this CDDL HEADER in each
+# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
+# If applicable, add the following below this CDDL HEADER, with the
+# fields enclosed by brackets "[]" replaced with your own identifying
+# information: Portions Copyright [yyyy] [name of copyright owner]
+#
+# CDDL HEADER END
+#
+
+#
+# Copyright 2008 Sun Microsystems, Inc.  All rights reserved.
+# Use is subject to license terms.
+#
+
+#
+# Copyright (c) 2013 by Delphix. All rights reserved.
+#
+
+. $STF_SUITE/tests/functional/delegate/delegate_common.kshlib
+
+#
+# DESCRIPTION:
+#      "everyone" is interpreted as the keyword "everyone" whatever the same
+#      name user or group is existing.
+#
+# STRATEGY:
+#      1. Create user 'everyone'.
+#      2. Verify 'everyone' is interpreted as keywords.
+#      3. Create group 'everyone'.
+#      4. Verify 'everyone' is interpreted as keywords.
+#
+
+verify_runnable "both"
+
+function cleanup
+{
+       if [[ $user_added == "TRUE" ]] ; then
+               del_user everyone
+       fi
+       if [[ $group_added == "TRUE" ]] ; then
+               del_group everyone
+       fi
+
+       restore_root_datasets
+}
+
+log_assert "everyone' is interpreted as a keyword even if a user " \
+       "or group named 'everyone' exists."
+log_onexit cleanup
+
+eval set -A dataset $DATASETS
+typeset perms="snapshot,reservation,compression,checksum,send,userprop"
+
+log_note "Create a user called 'everyone'."
+if ! $ID everyone > /dev/null 2>&1; then
+       user_added="TRUE"
+       log_must $USERADD everyone
+fi
+for dtst in $DATASETS ; do
+       log_must $ZFS allow everyone $perms $dtst
+       log_must verify_perm $dtst $perms $EVERYONE "everyone"
+done
+log_must restore_root_datasets
+if [[ $user_added == "TRUE" ]]; then
+       log_must $USERDEL everyone
+fi
+
+log_note "Created a group called 'everyone'."
+if ! $CAT /etc/group | $AWK -F: '{print $1}' | \
+       $GREP -w 'everyone' > /dev/null 2>&1
+then
+       group_added="TRUE"
+       log_must $GROUPADD everyone
+fi
+
+for dtst in $DATASETS ; do
+       log_must $ZFS allow everyone $perms $dtst
+       log_must verify_perm $dtst $perms $EVERYONE
+done
+log_must restore_root_datasets
+if [[ $group_added == "TRUE" ]]; then
+       log_must $GROUPDEL everyone
+fi
+
+log_pass "everyone is always interpreted as keyword passed."
diff --git a/tests/zfs-tests/tests/functional/delegate/zfs_allow_002_pos.ksh b/tests/zfs-tests/tests/functional/delegate/zfs_allow_002_pos.ksh
new file mode 100755 (executable)
index 0000000..2da435e
--- /dev/null
@@ -0,0 +1,79 @@
+#!/bin/ksh -p
+#
+# CDDL HEADER START
+#
+# The contents of this file are subject to the terms of the
+# Common Development and Distribution License (the "License").
+# You may not use this file except in compliance with the License.
+#
+# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
+# or http://www.opensolaris.org/os/licensing.
+# See the License for the specific language governing permissions
+# and limitations under the License.
+#
+# When distributing Covered Code, include this CDDL HEADER in each
+# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
+# If applicable, add the following below this CDDL HEADER, with the
+# fields enclosed by brackets "[]" replaced with your own identifying
+# information: Portions Copyright [yyyy] [name of copyright owner]
+#
+# CDDL HEADER END
+#
+
+#
+# Copyright 2008 Sun Microsystems, Inc.  All rights reserved.
+# Use is subject to license terms.
+#
+
+#
+# Copyright (c) 2013 by Delphix. All rights reserved.
+#
+
+. $STF_SUITE/tests/functional/delegate/delegate_common.kshlib
+
+#
+# DESCRIPTION:
+# <user|group> argument is interpreted as a user if possible, then as a group as
+# possible.
+#
+# STRATEGY:
+#      1. Create user $STAFF_GROUP
+#      2. Delegate permissions to $STAFF_GROUP
+#      3. Verify user $STAFF_GROUP has the permissions.
+#      4. Delete user $STAFF_GROUP and allow the permission to $STAFF_GROUP
+#      5. Verify $STAFF_GROUP is interpreted as group.
+#
+
+verify_runnable "both"
+
+function cleanup
+{
+       if $ID $STAFF_GROUP > /dev/null 2>&1; then
+               log_must del_user $STAFF_GROUP
+       fi
+
+       restore_root_datasets
+}
+
+log_assert "<user|group> is interpreted as user if possible, then as group."
+log_onexit cleanup
+
+eval set -A dataset $DATASETS
+typeset perms="snapshot,reservation,compression,checksum,send,userprop"
+
+log_must $USERADD $STAFF_GROUP
+for dtst in $DATASETS ; do
+       log_must $ZFS allow $STAFF_GROUP $perms $dtst
+       log_must verify_perm $dtst $perms $STAFF_GROUP
+       log_must verify_noperm $dtst $perms $STAFF1 $STAFF2
+done
+
+log_must restore_root_datasets
+
+log_must del_user $STAFF_GROUP
+for dtst in $datasets ; do
+       log_must $ZFS allow $STAFF_GROUP $perms $dtst
+       log_must verify_perm $dtst $perms $STAFF1 $STAFF2
+done
+
+log_pass "<user|group> is interpreted as user if possible, then as group passed."
diff --git a/tests/zfs-tests/tests/functional/delegate/zfs_allow_003_pos.ksh b/tests/zfs-tests/tests/functional/delegate/zfs_allow_003_pos.ksh
new file mode 100755 (executable)
index 0000000..21cf4a0
--- /dev/null
@@ -0,0 +1,93 @@
+#!/bin/ksh -p
+#
+# CDDL HEADER START
+#
+# The contents of this file are subject to the terms of the
+# Common Development and Distribution License (the "License").
+# You may not use this file except in compliance with the License.
+#
+# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
+# or http://www.opensolaris.org/os/licensing.
+# See the License for the specific language governing permissions
+# and limitations under the License.
+#
+# When distributing Covered Code, include this CDDL HEADER in each
+# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
+# If applicable, add the following below this CDDL HEADER, with the
+# fields enclosed by brackets "[]" replaced with your own identifying
+# information: Portions Copyright [yyyy] [name of copyright owner]
+#
+# CDDL HEADER END
+#
+
+#
+# Copyright 2009 Sun Microsystems, Inc.  All rights reserved.
+# Use is subject to license terms.
+#
+
+#
+# Copyright (c) 2013 by Delphix. All rights reserved.
+#
+
+. $STF_SUITE/tests/functional/delegate/delegate_common.kshlib
+
+#
+# DESCRIPTION:
+#      Verify option '-l' only allow permission to the dataset itself.
+#
+# STRATEGY:
+#      1. Create descendent datasets of $ROOT_TESTFS
+#      2. Select user, group and everyone and set local permission separately.
+#      3. Set locally permissions to $ROOT_TESTFS or $ROOT_TESTVOL.
+#      4. Verify the permissions are only allow on $ROOT_TESTFS or
+#         $ROOT_TESTVOL.
+#
+
+verify_runnable "both"
+
+log_assert "Verify option '-l' only allow permission to the dataset itself."
+log_onexit restore_root_datasets
+
+childfs=$ROOT_TESTFS/childfs
+
+eval set -A dataset $DATASETS
+typeset perms="snapshot,reservation,compression,checksum,userprop"
+
+log_must $ZFS create $childfs
+
+for dtst in $DATASETS ; do
+       log_must $ZFS allow -l $STAFF1 $perms $dtst
+       log_must verify_perm $dtst $perms $STAFF1
+       if [[ $dtst == $ROOT_TESTFS ]] ; then
+               log_must verify_noperm $childfs $perms \
+                       $STAFF1 $STAFF2 $OTHER1 $OTHER2
+       fi
+done
+
+log_must restore_root_datasets
+
+log_must $ZFS create $childfs
+for dtst in $DATASETS ; do
+       log_must $ZFS allow -l -g $STAFF_GROUP $perms $dtst
+       log_must verify_perm $dtst $perms $STAFF1 $STAFF2
+       if [[ $dtst == $ROOT_TESTFS ]] ; then
+               log_must verify_noperm $childfs $perms \
+                       $STAFF1 $STAFF2 $OTHER1 $OTHER2
+       fi
+done
+
+log_must restore_root_datasets
+
+log_must $ZFS create $childfs
+for dtst in $DATASETS ; do
+       log_must $ZFS allow -l -e $perms $dtst
+       log_must verify_perm $dtst $perms $STAFF1 $STAFF2 $OTHER1 $OTHER2
+       if [[ $dtst == $ROOT_TESTFS ]] ; then
+               log_must verify_noperm $childfs $perms \
+                       $STAFF1 $STAFF2 $OTHER1 $OTHER2
+       fi
+done
+
+log_must restore_root_datasets
+
+log_pass "Verify option '-l' only allow permission to the dataset itself pass."
diff --git a/tests/zfs-tests/tests/functional/delegate/zfs_allow_004_pos.ksh b/tests/zfs-tests/tests/functional/delegate/zfs_allow_004_pos.ksh
new file mode 100755 (executable)
index 0000000..c1cdb3c
--- /dev/null
@@ -0,0 +1,96 @@
+#!/bin/ksh -p
+#
+# CDDL HEADER START
+#
+# The contents of this file are subject to the terms of the
+# Common Development and Distribution License (the "License").
+# You may not use this file except in compliance with the License.
+#
+# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
+# or http://www.opensolaris.org/os/licensing.
+# See the License for the specific language governing permissions
+# and limitations under the License.
+#
+# When distributing Covered Code, include this CDDL HEADER in each
+# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
+# If applicable, add the following below this CDDL HEADER, with the
+# fields enclosed by brackets "[]" replaced with your own identifying
+# information: Portions Copyright [yyyy] [name of copyright owner]
+#
+# CDDL HEADER END
+#
+
+#
+# Copyright 2009 Sun Microsystems, Inc.  All rights reserved.
+# Use is subject to license terms.
+#
+
+#
+# Copyright (c) 2013 by Delphix. All rights reserved.
+#
+
+. $STF_SUITE/tests/functional/delegate/delegate_common.kshlib
+
+#
+# DESCRIPTION:
+#      Verify option '-d' allow permission to the descendent datasets, and not
+#      for this dataset itself.
+#
+# STRATEGY:
+#      1. Create descendent datasets of $ROOT_TESTFS
+#      2. Select user, group and everyone and set descendent permission
+#         separately.
+#      3. Set descendent permissions to $ROOT_TESTFS or $ROOT_TESTVOL.
+#      4. Verify those permissions are allowed to $ROOT_TESTFS's
+#         descendent dataset.
+#      5. Verify the permissions are not allowed to $ROOT_TESTFS or
+#         $ROOT_TESTVOL.
+#
+
+verify_runnable "both"
+
+log_assert "Verify option '-d' allow permission to the descendent datasets."
+log_onexit restore_root_datasets
+
+childfs=$ROOT_TESTFS/childfs
+
+eval set -A dataset $DATASETS
+typeset perms="snapshot,reservation,compression,checksum,userprop"
+
+# Verify option '-d' only affect sub-datasets
+log_must $ZFS create $childfs
+for dtst in $DATASETS ; do
+       log_must $ZFS allow -d $STAFF1 $perms $dtst
+       log_must verify_noperm $dtst $perms $STAFF1
+       if [[ $dtst == $ROOT_TESTFS ]]; then
+               log_must verify_perm $childfs $perms $STAFF1
+       fi
+done
+
+log_must restore_root_datasets
+
+# Verify option '-d + -g' affect group in sub-datasets.
+log_must $ZFS create $childfs
+for dtst in $DATASETS ; do
+       log_must $ZFS allow -d -g $STAFF_GROUP $perms $dtst
+       log_must verify_noperm $dtst $perms $STAFF2
+       if [[ $dtst == $ROOT_TESTFS ]]; then
+               log_must verify_perm $childfs $perms $STAFF2
+       fi
+done
+
+log_must restore_root_datasets
+
+# Verify option '-d + -e' affect everyone in sub-datasets.
+log_must $ZFS create $childfs
+for dtst in $DATASETS ; do
+       log_must $ZFS allow -d -e $perms $dtst
+       log_must verify_noperm $dtst $perms $OTHER1 $OTHER2
+       if [[ $dtst == $ROOT_TESTFS ]]; then
+               log_must verify_perm $childfs $perms $OTHER1 $OTHER2
+       fi
+done
+
+log_must restore_root_datasets
+
+log_pass "Verify option '-d' allow permission to the descendent datasets pass."
diff --git a/tests/zfs-tests/tests/functional/delegate/zfs_allow_005_pos.ksh b/tests/zfs-tests/tests/functional/delegate/zfs_allow_005_pos.ksh
new file mode 100755 (executable)
index 0000000..9342643
--- /dev/null
@@ -0,0 +1,78 @@
+#!/bin/ksh -p
+#
+# CDDL HEADER START
+#
+# The contents of this file are subject to the terms of the
+# Common Development and Distribution License (the "License").
+# You may not use this file except in compliance with the License.
+#
+# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
+# or http://www.opensolaris.org/os/licensing.
+# See the License for the specific language governing permissions
+# and limitations under the License.
+#
+# When distributing Covered Code, include this CDDL HEADER in each
+# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
+# If applicable, add the following below this CDDL HEADER, with the
+# fields enclosed by brackets "[]" replaced with your own identifying
+# information: Portions Copyright [yyyy] [name of copyright owner]
+#
+# CDDL HEADER END
+#
+
+#
+# Copyright 2009 Sun Microsystems, Inc.  All rights reserved.
+# Use is subject to license terms.
+#
+
+#
+# Copyright (c) 2013 by Delphix. All rights reserved.
+#
+
+. $STF_SUITE/tests/functional/delegate/delegate_common.kshlib
+
+#
+# DESCRIPTION:
+#      Verify option '-c' will be granted locally to the creator on any
+#      newly-created descendent file systems.
+#
+# STRATEGY:
+#      1. Allow create permissions to everyone on $ROOT_TESTFS locally.
+#      2. Allow '-c' create to $ROOT_TESTFS.
+#      3. chmod 777 the mountpoint of $ROOT_TESTFS
+#      4. Verify only creator can create descendent dataset on
+#         $ROOT_TESTFS/$user.
+#
+
+verify_runnable "both"
+
+log_assert "Verify option '-c' will be granted locally to the creator."
+log_onexit restore_root_datasets
+
+eval set -A dataset $DATASETS
+typeset perms="snapshot,reservation,compression,checksum,userprop"
+
+log_must $ZFS allow -l everyone create,mount $ROOT_TESTFS
+log_must $ZFS allow -c $perms $ROOT_TESTFS
+
+mntpnt=$(get_prop mountpoint $ROOT_TESTFS)
+log_must $CHMOD 777 $mntpnt
+
+for user in $EVERYONE; do
+       childfs=$ROOT_TESTFS/$user
+
+       user_run $user $ZFS create $childfs
+
+       for other in $EVERYONE; do
+               #
+               # Verify only the creator has the $perm time permissions.
+               #
+               if [[ $other == $user ]]; then
+                       log_must verify_perm $childfs $perms $user
+               else
+                       log_must verify_noperm $childfs $perms $other
+               fi
+       done
+done
+
+log_pass "Verify option '-c' will be granted locally to the creator passed."
diff --git a/tests/zfs-tests/tests/functional/delegate/zfs_allow_006_pos.ksh b/tests/zfs-tests/tests/functional/delegate/zfs_allow_006_pos.ksh
new file mode 100755 (executable)
index 0000000..e8cdf25
--- /dev/null
@@ -0,0 +1,72 @@
+#!/bin/ksh -p
+#
+# CDDL HEADER START
+#
+# The contents of this file are subject to the terms of the
+# Common Development and Distribution License (the "License").
+# You may not use this file except in compliance with the License.
+#
+# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
+# or http://www.opensolaris.org/os/licensing.
+# See the License for the specific language governing permissions
+# and limitations under the License.
+#
+# When distributing Covered Code, include this CDDL HEADER in each
+# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
+# If applicable, add the following below this CDDL HEADER, with the
+# fields enclosed by brackets "[]" replaced with your own identifying
+# information: Portions Copyright [yyyy] [name of copyright owner]
+#
+# CDDL HEADER END
+#
+
+#
+# Copyright 2008 Sun Microsystems, Inc.  All rights reserved.
+# Use is subject to license terms.
+#
+
+#
+# Copyright (c) 2013 by Delphix. All rights reserved.
+#
+
+. $STF_SUITE/tests/functional/delegate/delegate_common.kshlib
+
+#
+# DESCRIPTION:
+#      Changing permissions in a set will change what is allowed wherever the
+#      set is used.
+#
+# STRATEGY:
+#      1. Set create as set @basic.
+#      2. Allow set @basic to $STAFF1 on $ROOT_TESTFS or $ROOT_TESTVOL
+#      3. Verify $STAFF1 has create permissions.
+#      4. Reset snapshot,allow to $basic
+#      5. Verify now $STAFF1 have create,allow,destroy permissions.
+#
+
+verify_runnable "both"
+
+log_assert "Changing permissions in a set will change what is allowed " \
+       "wherever the set is used."
+log_onexit restore_root_datasets
+
+fs1=$ROOT_TESTFS/fs1; fs2=$ROOT_TESTFS/fs2
+log_must $ZFS create $fs1
+log_must $ZFS create $fs2
+
+eval set -A dataset $DATASETS
+perms1="snapshot,checksum,reservation"
+
+for dtst in $DATASETS $fs1 $fs2; do
+       log_must $ZFS allow -s @basic $perms1 $dtst
+       log_must $ZFS allow $STAFF1 @basic $dtst
+       log_must verify_perm $dtst $perms1 $STAFF1
+done
+
+perms2="send,compression,userprop"
+for dtst in $DATASETS $fs1 $fs2; do
+       log_must $ZFS allow -s @basic $perms2 $dtst
+       log_must verify_perm $dtst ${perms1},${perms2} $STAFF1
+done
+
+log_pass "Changing permissions in a set will change what is allowed passed."
diff --git a/tests/zfs-tests/tests/functional/delegate/zfs_allow_007_pos.ksh b/tests/zfs-tests/tests/functional/delegate/zfs_allow_007_pos.ksh
new file mode 100755 (executable)
index 0000000..5305deb
--- /dev/null
@@ -0,0 +1,103 @@
+#!/bin/ksh -p
+#
+# CDDL HEADER START
+#
+# The contents of this file are subject to the terms of the
+# Common Development and Distribution License (the "License").
+# You may not use this file except in compliance with the License.
+#
+# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
+# or http://www.opensolaris.org/os/licensing.
+# See the License for the specific language governing permissions
+# and limitations under the License.
+#
+# When distributing Covered Code, include this CDDL HEADER in each
+# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
+# If applicable, add the following below this CDDL HEADER, with the
+# fields enclosed by brackets "[]" replaced with your own identifying
+# information: Portions Copyright [yyyy] [name of copyright owner]
+#
+# CDDL HEADER END
+#
+
+#
+# Copyright 2008 Sun Microsystems, Inc.  All rights reserved.
+# Use is subject to license terms.
+#
+
+#
+# Copyright (c) 2013 by Delphix. All rights reserved.
+#
+
+. $STF_SUITE/tests/functional/delegate/delegate_common.kshlib
+
+#
+# DESCRIPTION:
+#      Verify the permissions set will be masked on its descendent
+#      datasets by same name set.
+#
+# STRATEGY:
+#      1. Create $ROOT_TESTFS/childfs
+#      2. Set permission $perms1 to @set on $ROOT_TESTFS
+#      3. Reset permission $perms2 to @set on $ROOT_TESTFS/childfs
+#      4. Allow @set to $STAFF1 on $ROOT_TESTFS/childfs
+#      5. Verify $perms2 is delegated on $ROOT_TESTFS/childfs and its
+#         descendent.
+#      6. Allow @set to $STAFF1 on $ROOT_TESTFS
+#      7. Verify $perms1 is not appended to $STAFF1 on $ROOT_TESTFS/childfs and
+#         its descendent since it is masked
+#
+
+verify_runnable "both"
+
+log_assert "Verify permission set can be masked on descendent dataset."
+log_onexit restore_root_datasets
+
+typeset perms1="snapshot,reservation,compression"
+eval set -A dataset $DATASETS
+typeset perms2="checksum,send,userprop"
+
+#
+# Define three level filesystems
+#
+childfs=$ROOT_TESTFS/childfs
+grandchild=$childfs/grandchild
+log_must $ZFS create $childfs
+log_must $ZFS create $grandchild
+
+#
+# Setting different permissions to the same set on two level.
+# But only assign the user at one level.
+#
+log_must $ZFS allow -s @set $perms1 $ROOT_TESTFS
+log_must $ZFS allow -s @set $perms2 $childfs
+log_must $ZFS allow $STAFF1 @set $childfs
+
+#
+# Verify only perms2 is valid to user on the level which he was assigned.
+#
+log_must verify_noperm $ROOT_TESTFS $perms1 $STAFF1
+for fs in $childfs $grandchild ; do
+       log_must verify_noperm $fs $perms1 $STAFF1
+       log_must verify_perm $fs $perms2 $STAFF1
+done
+
+#
+# Delegate @set to STAFF1 on ROOT_TESTFS, verify $perms1 will not be appended
+# to its descendent datasets since it is masked
+#
+log_must $ZFS allow $STAFF1 @set $ROOT_TESTFS
+log_must verify_perm $ROOT_TESTFS $perms1 $STAFF1
+for fs in $childfs $grandchild ; do
+       log_must verify_noperm $fs $perms1 $STAFF1
+       log_must verify_perm $fs $perms2 $STAFF1
+done
+
+# Remove the mask, $perms1 will be allowed to its descendent datasets
+log_must $ZFS unallow -s @set $childfs
+for fs in $childfs $grandchild ; do
+       log_must verify_noperm $fs $perms2 $STAFF1
+       log_must verify_perm $fs $perms1 $STAFF1
+done
+
+log_pass "Verify permission set can be masked on descendent dataset pass."
diff --git a/tests/zfs-tests/tests/functional/delegate/zfs_allow_008_pos.ksh b/tests/zfs-tests/tests/functional/delegate/zfs_allow_008_pos.ksh
new file mode 100755 (executable)
index 0000000..fb02b9a
--- /dev/null
@@ -0,0 +1,78 @@
+#!/bin/ksh -p
+#
+# CDDL HEADER START
+#
+# The contents of this file are subject to the terms of the
+# Common Development and Distribution License (the "License").
+# You may not use this file except in compliance with the License.
+#
+# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
+# or http://www.opensolaris.org/os/licensing.
+# See the License for the specific language governing permissions
+# and limitations under the License.
+#
+# When distributing Covered Code, include this CDDL HEADER in each
+# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
+# If applicable, add the following below this CDDL HEADER, with the
+# fields enclosed by brackets "[]" replaced with your own identifying
+# information: Portions Copyright [yyyy] [name of copyright owner]
+#
+# CDDL HEADER END
+#
+
+#
+# Copyright 2007 Sun Microsystems, Inc.  All rights reserved.
+# Use is subject to license terms.
+#
+
+#
+# Copyright (c) 2013 by Delphix. All rights reserved.
+#
+
+. $STF_SUITE/tests/functional/delegate/delegate_common.kshlib
+
+#
+# DESCRIPTION:
+#      non-root user can allow any permissions which he is holding to
+#      other else user when it get 'allow' permission.
+#
+# STRATEGY:
+#      1. Set two set permissions to two datasets locally.
+#      2. Verify the non-root user can allow permission if he has allow
+#         permission.
+#
+
+verify_runnable "both"
+
+log_assert "Verify non-root user can allow permissions."
+log_onexit restore_root_datasets
+
+perms1="snapshot,reservation"
+perms2="send,compression,checksum,userprop"
+childfs=$ROOT_TESTFS/childfs
+
+log_must $ZFS create $childfs
+
+for dtst in $DATASETS ; do
+       # Delegate local permission to $STAFF1
+       log_must $ZFS allow -l $STAFF1 $perms1 $dtst
+       log_must $ZFS allow -l $STAFF1 allow $dtst
+
+       if [[ $dtst == $ROOT_TESTFS ]]; then
+               log_must $ZFS allow -l $STAFF1 $perms2 $childfs
+               # $perms1 is local permission in $ROOT_TESTFS
+               log_mustnot user_run $STAFF1 $ZFS allow $OTHER1 $perms1 $childfs
+               log_must verify_noperm $childfs $perms1 $OTHER1
+       fi
+
+       # Verify 'allow' give non-privilege user delegated permission.
+       log_must user_run $STAFF1 $ZFS allow -l $OTHER1 $perms1 $dtst
+       log_must verify_perm $dtst $perms1 $OTHER1
+
+       # $perms2 was not allow to $STAFF1, so he have no permission to
+       # delegate permission to other else.
+       log_mustnot user_run $STAFF1 $ZFS allow $OTHER1 $perms2 $dtst
+       log_must verify_noperm $dtst $perms2 $OTHER1
+done
+
+log_pass "Verify non-root user can allow permissions passed."
diff --git a/tests/zfs-tests/tests/functional/delegate/zfs_allow_009_neg.ksh b/tests/zfs-tests/tests/functional/delegate/zfs_allow_009_neg.ksh
new file mode 100755 (executable)
index 0000000..4da1653
--- /dev/null
@@ -0,0 +1,64 @@
+#!/bin/ksh -p
+#
+# CDDL HEADER START
+#
+# The contents of this file are subject to the terms of the
+# Common Development and Distribution License (the "License").
+# You may not use this file except in compliance with the License.
+#
+# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
+# or http://www.opensolaris.org/os/licensing.
+# See the License for the specific language governing permissions
+# and limitations under the License.
+#
+# When distributing Covered Code, include this CDDL HEADER in each
+# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
+# If applicable, add the following below this CDDL HEADER, with the
+# fields enclosed by brackets "[]" replaced with your own identifying
+# information: Portions Copyright [yyyy] [name of copyright owner]
+#
+# CDDL HEADER END
+#
+
+#
+# Copyright 2007 Sun Microsystems, Inc.  All rights reserved.
+# Use is subject to license terms.
+#
+
+#
+# Copyright (c) 2013 by Delphix. All rights reserved.
+#
+
+. $STF_SUITE/tests/functional/delegate/delegate_common.kshlib
+
+#
+# DESCRIPTION:
+#      zfs allow can deal with invalid arguments.(Invalid options or combination)
+#
+# STRATEGY:
+#      1. Verify invalid argumets will cause error.
+#      2. Verify non-optional argument was missing will cause error.
+#      3. Verify invalid options cause error.
+#
+
+verify_runnable "both"
+
+log_assert "Verify invalid arguments are handled correctly."
+log_onexit restore_root_datasets
+
+# Permission sets are limited to 64 characters in length.
+longset="set123456789012345678901234567890123456789012345678901234567890123"
+for dtst in $DATASETS ; do
+       log_mustnot eval "$ZFS allow -s @$longset $dtst"
+       # Create non-existent permission set
+       typeset timestamp=$($DATE +'%F-%R:%S')
+       log_mustnot $ZFS allow -s @non-existent $dtst
+       log_mustnot $ZFS allow $STAFF "atime,created,mounted" $dtst
+       log_mustnot $ZFS allow $dtst $TESTPOOL
+       log_mustnot $ZFS allow -c $dtst
+       log_mustnot $ZFS allow -u $STAFF1 $dtst
+       log_mustnot $ZFS allow -u $STAFF1 -g $STAFF_GROUP "create,destroy" $dtst
+       log_mustnot $ZFS allow -u $STAFF1 -e "mountpoint" $dtst
+done
+
+log_pass "Invalid arguments are handled correctly."
diff --git a/tests/zfs-tests/tests/functional/delegate/zfs_allow_010_pos.ksh b/tests/zfs-tests/tests/functional/delegate/zfs_allow_010_pos.ksh
new file mode 100755 (executable)
index 0000000..397b1a5
--- /dev/null
@@ -0,0 +1,113 @@
+#!/bin/ksh -p
+#
+# CDDL HEADER START
+#
+# The contents of this file are subject to the terms of the
+# Common Development and Distribution License (the "License").
+# You may not use this file except in compliance with the License.
+#
+# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
+# or http://www.opensolaris.org/os/licensing.
+# See the License for the specific language governing permissions
+# and limitations under the License.
+#
+# When distributing Covered Code, include this CDDL HEADER in each
+# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
+# If applicable, add the following below this CDDL HEADER, with the
+# fields enclosed by brackets "[]" replaced with your own identifying
+# information: Portions Copyright [yyyy] [name of copyright owner]
+#
+# CDDL HEADER END
+#
+
+#
+# Copyright 2007 Sun Microsystems, Inc.  All rights reserved.
+# Use is subject to license terms.
+#
+
+#
+# Copyright (c) 2013 by Delphix. All rights reserved.
+#
+
+. $STF_SUITE/tests/functional/delegate/delegate_common.kshlib
+
+#
+# DESCRIPTION:
+#      Scan the following permissions one by one to verify privileged user
+#      has correct permission delegation in datasets.
+#
+# STRATEGY:
+#      1. Delegate all the permission one by one to user on dataset.
+#      2. Verify privileged user has correct permission without any other
+#         permissions allowed.
+#
+
+verify_runnable "both"
+
+log_assert "Verify privileged user has correct permissions once which was "\
+       "delegated to him in datasets"
+log_onexit restore_root_datasets
+
+#
+#                              Results in      Results in
+#              Permission      Filesystem      Volume
+#
+set -A perms   create          true            false   \
+               snapshot        true            true    \
+               mount           true            false   \
+               send            true            true    \
+               allow           true            true    \
+               quota           true            false   \
+               reservation     true            true    \
+               recordsize      true            false   \
+               mountpoint      true            false   \
+               checksum        true            true    \
+               compression     true            true    \
+               canmount        true            false   \
+               atime           true            false   \
+               devices         true            false   \
+               exec            true            false   \
+               volsize         false           true    \
+               setuid          true            false   \
+               readonly        true            true    \
+               snapdir         true            false   \
+               userprop        true            true    \
+               aclmode         true            false   \
+               aclinherit      true            false   \
+               rollback        true            true    \
+               clone           true            true    \
+               rename          true            true    \
+               promote         true            true    \
+               zoned           true            false   \
+               xattr           true            false   \
+               receive         true            false   \
+               destroy         true            true
+if is_global_zone; then
+       typeset -i n=${#perms[@]}
+       perms[((n))]="sharenfs"; perms[((n+1))]="true"; perms[((n+2))]="false"
+       perms[((n+3))]="share"; perms[((n+4))]="true"; perms[((n+5))]="false"
+fi
+
+for dtst in $DATASETS; do
+       typeset -i k=1
+       typeset type=$(get_prop type $dtst)
+       [[ $type == "volume" ]] && k=2
+
+       typeset -i i=0
+       while (( i < ${#perms[@]} )); do
+               log_must $ZFS allow $STAFF1 ${perms[$i]} $dtst
+
+               if [[ ${perms[((i+k))]} == "true" ]]; then
+                       log_must verify_perm $dtst ${perms[$i]} $STAFF1
+               else
+                       log_must verify_noperm $dtst ${perms[$i]} $STAFF1
+               fi
+
+               log_must restore_root_datasets
+
+               ((i += 3))
+       done
+done
+
+log_pass "Verify privileged user has correct permissions " \
+       "in datasets passed."
diff --git a/tests/zfs-tests/tests/functional/delegate/zfs_allow_011_neg.ksh b/tests/zfs-tests/tests/functional/delegate/zfs_allow_011_neg.ksh
new file mode 100755 (executable)
index 0000000..60031c9
--- /dev/null
@@ -0,0 +1,68 @@
+#!/bin/ksh -p
+#
+# CDDL HEADER START
+#
+# The contents of this file are subject to the terms of the
+# Common Development and Distribution License (the "License").
+# You may not use this file except in compliance with the License.
+#
+# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
+# or http://www.opensolaris.org/os/licensing.
+# See the License for the specific language governing permissions
+# and limitations under the License.
+#
+# When distributing Covered Code, include this CDDL HEADER in each
+# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
+# If applicable, add the following below this CDDL HEADER, with the
+# fields enclosed by brackets "[]" replaced with your own identifying
+# information: Portions Copyright [yyyy] [name of copyright owner]
+#
+# CDDL HEADER END
+#
+
+#
+# Copyright 2007 Sun Microsystems, Inc.  All rights reserved.
+# Use is subject to license terms.
+#
+
+#
+# Copyright (c) 2013 by Delphix. All rights reserved.
+#
+
+. $STF_SUITE/tests/functional/delegate/delegate_common.kshlib
+
+#
+# DESCRIPTION:
+#      Verify zpool subcmds and system readonly properties can't be delegated.
+#
+# STRATEGY:
+#      1. Loop all the zpool subcmds and readonly properties, except permission
+#         'create' & 'destroy'.
+#      2. Verify those subcmd or properties can't be delegated.
+#
+
+verify_runnable "both"
+
+log_assert "Verify zpool subcmds and system readonly properties can't be " \
+       "delegated."
+log_onexit restore_root_datasets
+
+set -A invalid_perms   \
+       add             remove          list            iostat          \
+       status          offline         online          clear           \
+       attach          detach          replace         scrub           \
+       export          import          upgrade                         \
+       type            creation        used            available       \
+       referenced      compressratio   mounted
+
+for dtst in $DATASETS ; do
+       typeset -i i=0
+
+       while ((i < ${#invalid_perms[@]})); do
+               log_mustnot $ZFS allow $STAFF1 ${invalid_perms[$i]} $dtst
+
+               ((i += 1))
+       done
+done
+
+log_pass "Verify zpool subcmds and system readonly properties passed."
diff --git a/tests/zfs-tests/tests/functional/delegate/zfs_allow_012_neg.ksh b/tests/zfs-tests/tests/functional/delegate/zfs_allow_012_neg.ksh
new file mode 100755 (executable)
index 0000000..c33c29b
--- /dev/null
@@ -0,0 +1,79 @@
+#!/bin/ksh -p
+#
+# CDDL HEADER START
+#
+# The contents of this file are subject to the terms of the
+# Common Development and Distribution License (the "License").
+# You may not use this file except in compliance with the License.
+#
+# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
+# or http://www.opensolaris.org/os/licensing.
+# See the License for the specific language governing permissions
+# and limitations under the License.
+#
+# When distributing Covered Code, include this CDDL HEADER in each
+# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
+# If applicable, add the following below this CDDL HEADER, with the
+# fields enclosed by brackets "[]" replaced with your own identifying
+# information: Portions Copyright [yyyy] [name of copyright owner]
+#
+# CDDL HEADER END
+#
+
+#
+# Copyright 2007 Sun Microsystems, Inc.  All rights reserved.
+# Use is subject to license terms.
+#
+
+#
+# Copyright (c) 2013 by Delphix. All rights reserved.
+#
+
+. $STF_SUITE/tests/functional/delegate/delegate_common.kshlib
+
+#
+# DESCRIPTION:
+#      Scan all permissions one by one to verify privileged user
+#      can not use permissions properly when delegation property is set off
+#
+# STRATEGY:
+#      1. Delegate all the permission one by one to user on dataset.
+#      2. Verify privileged user can not use permissions properly when
+#      delegation property is off
+#
+
+verify_runnable "global"
+
+function cleanup
+{
+       log_must $ZPOOL set delegation=on $TESTPOOL
+       log_must restore_root_datasets
+}
+
+log_assert "Verify privileged user can not use permissions properly when " \
+       "delegation property is set off"
+log_onexit cleanup
+
+
+set -A perms   create snapshot mount send allow quota reservation \
+               recordsize mountpoint checksum compression canmount atime \
+               devices exec volsize setuid readonly snapdir userprop \
+               aclmode aclinherit rollback clone rename promote \
+               zoned xattr receive destroy sharenfs share
+
+log_must $ZPOOL set delegation=off $TESTPOOL
+
+for dtst in $DATASETS; do
+       typeset -i i=0
+       while (( i < ${#perms[@]} )); do
+
+               log_must $ZFS allow $STAFF1 ${perms[$i]} $dtst
+               log_must verify_noperm $dtst ${perms[$i]} $STAFF1
+
+               log_must restore_root_datasets
+               ((i += 1))
+       done
+done
+
+log_pass "Verify privileged user can not use permissions properly when " \
+       "delegation property is set off"
diff --git a/tests/zfs-tests/tests/functional/delegate/zfs_unallow_001_pos.ksh b/tests/zfs-tests/tests/functional/delegate/zfs_unallow_001_pos.ksh
new file mode 100755 (executable)
index 0000000..a2c34de
--- /dev/null
@@ -0,0 +1,65 @@
+#!/bin/ksh -p
+#
+# CDDL HEADER START
+#
+# The contents of this file are subject to the terms of the
+# Common Development and Distribution License (the "License").
+# You may not use this file except in compliance with the License.
+#
+# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
+# or http://www.opensolaris.org/os/licensing.
+# See the License for the specific language governing permissions
+# and limitations under the License.
+#
+# When distributing Covered Code, include this CDDL HEADER in each
+# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
+# If applicable, add the following below this CDDL HEADER, with the
+# fields enclosed by brackets "[]" replaced with your own identifying
+# information: Portions Copyright [yyyy] [name of copyright owner]
+#
+# CDDL HEADER END
+#
+
+#
+# Copyright 2007 Sun Microsystems, Inc.  All rights reserved.
+# Use is subject to license terms.
+#
+
+#
+# Copyright (c) 2013 by Delphix. All rights reserved.
+#
+
+. $STF_SUITE/tests/functional/delegate/delegate_common.kshlib
+
+#
+# DESCRIPTION:
+#      Verify '-l' only removed the local permissions.
+#
+# STRATEGY:
+#      1. Set up unallow test model.
+#      2. Implement unallow -l to $ROOT_TESTFS or $TESTVOL
+#      3. Verify '-l' only remove the local permissions.
+#
+
+verify_runnable "both"
+
+log_assert "Verify '-l' only removed the local permissions."
+log_onexit restore_root_datasets
+
+log_must setup_unallow_testenv
+
+for dtst in $DATASETS ; do
+       log_must $ZFS unallow -l $STAFF1 $dtst
+       log_must verify_noperm $dtst $LOCAL_SET $STAFF1
+
+       log_must $ZFS unallow -l $OTHER1 $dtst
+       log_must verify_noperm $dtst $LOCAL_DESC_SET $OTHER1
+
+       log_must verify_perm $dtst $LOCAL_DESC_SET $OTHER2
+       if [[ $dtst == $ROOT_TESTFS ]]; then
+               log_must verify_perm $SUBFS $LOCAL_DESC_SET $OTHER1 $OTHER2
+               log_must verify_perm $SUBFS $DESC_SET $STAFF2
+       fi
+done
+
+log_pass "Verify '-l' only removed the local permissions passed."
diff --git a/tests/zfs-tests/tests/functional/delegate/zfs_unallow_002_pos.ksh b/tests/zfs-tests/tests/functional/delegate/zfs_unallow_002_pos.ksh
new file mode 100755 (executable)
index 0000000..c48df76
--- /dev/null
@@ -0,0 +1,61 @@
+#!/bin/ksh -p
+#
+# CDDL HEADER START
+#
+# The contents of this file are subject to the terms of the
+# Common Development and Distribution License (the "License").
+# You may not use this file except in compliance with the License.
+#
+# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
+# or http://www.opensolaris.org/os/licensing.
+# See the License for the specific language governing permissions
+# and limitations under the License.
+#
+# When distributing Covered Code, include this CDDL HEADER in each
+# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
+# If applicable, add the following below this CDDL HEADER, with the
+# fields enclosed by brackets "[]" replaced with your own identifying
+# information: Portions Copyright [yyyy] [name of copyright owner]
+#
+# CDDL HEADER END
+#
+
+#
+# Copyright 2007 Sun Microsystems, Inc.  All rights reserved.
+# Use is subject to license terms.
+#
+
+#
+# Copyright (c) 2013 by Delphix. All rights reserved.
+#
+
+. $STF_SUITE/tests/functional/delegate/delegate_common.kshlib
+
+#
+# DESCRIPTION:
+#      Verify '-d' only remove the permissions on descendent filesystem.
+#
+# STRATEGY:
+#      1. Set up unallow test model.
+#      2. Implement unallow -d to $ROOT_TESTFS
+#      3. Verify '-d' only remove the permissions on descendent filesystem.
+#
+
+verify_runnable "both"
+
+log_assert "Verify '-d' only removed the descendent permissions."
+log_onexit restore_root_datasets
+
+log_must setup_unallow_testenv
+
+log_must $ZFS unallow -d $STAFF2 $ROOT_TESTFS
+log_must verify_noperm $SUBFS $DESC_SET $STAFF2
+
+log_must $ZFS unallow -d $OTHER1 $ROOT_TESTFS
+log_must verify_noperm $SUBFS $LOCAL_DESC_SET $OTHER1
+log_must verify_perm $ROOT_TESTFS $LOCAL_DESC_SET $OTHER1
+
+log_must verify_perm $ROOT_TESTFS $LOCAL_DESC_SET $OTHER2
+log_must verify_perm $SUBFS $LOCAL_DESC_SET $OTHER2
+
+log_pass "Verify '-d' only removed the descendent permissions passed"
diff --git a/tests/zfs-tests/tests/functional/delegate/zfs_unallow_003_pos.ksh b/tests/zfs-tests/tests/functional/delegate/zfs_unallow_003_pos.ksh
new file mode 100755 (executable)
index 0000000..57dff54
--- /dev/null
@@ -0,0 +1,71 @@
+#!/bin/ksh -p
+#
+# CDDL HEADER START
+#
+# The contents of this file are subject to the terms of the
+# Common Development and Distribution License (the "License").
+# You may not use this file except in compliance with the License.
+#
+# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
+# or http://www.opensolaris.org/os/licensing.
+# See the License for the specific language governing permissions
+# and limitations under the License.
+#
+# When distributing Covered Code, include this CDDL HEADER in each
+# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
+# If applicable, add the following below this CDDL HEADER, with the
+# fields enclosed by brackets "[]" replaced with your own identifying
+# information: Portions Copyright [yyyy] [name of copyright owner]
+#
+# CDDL HEADER END
+#
+
+#
+# Copyright 2007 Sun Microsystems, Inc.  All rights reserved.
+# Use is subject to license terms.
+#
+
+#
+# Copyright (c) 2013 by Delphix. All rights reserved.
+#
+
+. $STF_SUITE/tests/functional/delegate/delegate_common.kshlib
+
+#
+# DESCRIPTION:
+#      Verify options '-r' or '-l' + '-d' will unallow permission to this
+#      dataset and the descendent datasets.
+#
+# STRATEGY:
+#      1. Set up unallow test model.
+#      2. Implement unallow -l -d to $ROOT_TESTFS or $ROOT_TESTVOL without
+#         options.
+#      3. Verify '-l' + '-d' will unallow local + descendent permission.
+#      4. Verify '-r' will unallow local + descendent permission.
+#
+
+verify_runnable "both"
+
+log_assert "Verify options '-r' and '-l'+'-d' will unallow permission to " \
+       "this dataset and the descendent datasets."
+log_onexit restore_root_datasets
+
+log_must setup_unallow_testenv
+
+for dtst in $DATASETS ; do
+       log_must $ZFS unallow $STAFF1 $dtst
+       log_must $ZFS unallow -l -d $STAFF2 $dtst
+       log_must verify_noperm $dtst $LOCAL_SET $STAFF1
+       if [[ $dtst == $ROOT_TESTFS ]]; then
+               log_must verify_noperm $SUBFS $DESC_SET $STAFF2
+       fi
+
+       log_must $ZFS unallow -l -d $OTHER1 $dtst
+       log_must $ZFS unallow -r $OTHER2 $dtst
+       log_must verify_noperm $dtst $LOCAL_DESC_SET $OTHER1 $OTHER2
+       if [[ $dtst == $ROOT_TESTFS ]]; then
+               log_must verify_noperm $SUBFS $LOCAL_DESC_SET $OTHER1 $OTHER2
+       fi
+done
+
+log_pass "Verify options '-r' and '-l'+'-d' function passed."
diff --git a/tests/zfs-tests/tests/functional/delegate/zfs_unallow_004_pos.ksh b/tests/zfs-tests/tests/functional/delegate/zfs_unallow_004_pos.ksh
new file mode 100755 (executable)
index 0000000..0c55551
--- /dev/null
@@ -0,0 +1,59 @@
+#!/bin/ksh -p
+#
+# CDDL HEADER START
+#
+# The contents of this file are subject to the terms of the
+# Common Development and Distribution License (the "License").
+# You may not use this file except in compliance with the License.
+#
+# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
+# or http://www.opensolaris.org/os/licensing.
+# See the License for the specific language governing permissions
+# and limitations under the License.
+#
+# When distributing Covered Code, include this CDDL HEADER in each
+# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
+# If applicable, add the following below this CDDL HEADER, with the
+# fields enclosed by brackets "[]" replaced with your own identifying
+# information: Portions Copyright [yyyy] [name of copyright owner]
+#
+# CDDL HEADER END
+#
+
+#
+# Copyright 2007 Sun Microsystems, Inc.  All rights reserved.
+# Use is subject to license terms.
+#
+
+#
+# Copyright (c) 2013 by Delphix. All rights reserved.
+#
+
+. $STF_SUITE/tests/functional/delegate/delegate_common.kshlib
+
+#
+# DESCRIPTION:
+#      Verify '-s' will remove permissions from the named set.
+#
+# STRATEGY:
+#      1. Set @basic set to $ROOT_TESTFS or $ROOT_TESTVOL and allow @basic
+#         to $STAFF1
+#      2. Verify $STAFF1 have @basic permissions.
+#      3. Verify '-s' will remove permission from the named set.
+#
+
+verify_runnable "both"
+
+log_assert "Verify '-s' will remove permissions from the named set."
+log_onexit restore_root_datasets
+
+for dtst in $DATASETS ; do
+       log_must $ZFS allow -s @basic $LOCAL_DESC_SET $dtst
+       log_must $ZFS allow -u $STAFF1 @basic $dtst
+
+       log_must verify_perm $dtst $LOCAL_DESC_SET $STAFF1
+       log_must $ZFS unallow -s @basic $LOCAL_DESC_SET $dtst
+       log_must verify_noperm $dtst $LOCAL_DESC_SET $STAFF1
+done
+
+log_pass "Verify '-s' will remove permissions from the named set passed."
diff --git a/tests/zfs-tests/tests/functional/delegate/zfs_unallow_005_pos.ksh b/tests/zfs-tests/tests/functional/delegate/zfs_unallow_005_pos.ksh
new file mode 100755 (executable)
index 0000000..a723e8f
--- /dev/null
@@ -0,0 +1,73 @@
+#!/bin/ksh -p
+#
+# CDDL HEADER START
+#
+# The contents of this file are subject to the terms of the
+# Common Development and Distribution License (the "License").
+# You may not use this file except in compliance with the License.
+#
+# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
+# or http://www.opensolaris.org/os/licensing.
+# See the License for the specific language governing permissions
+# and limitations under the License.
+#
+# When distributing Covered Code, include this CDDL HEADER in each
+# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
+# If applicable, add the following below this CDDL HEADER, with the
+# fields enclosed by brackets "[]" replaced with your own identifying
+# information: Portions Copyright [yyyy] [name of copyright owner]
+#
+# CDDL HEADER END
+#
+
+#
+# Copyright 2007 Sun Microsystems, Inc.  All rights reserved.
+# Use is subject to license terms.
+#
+
+#
+# Copyright (c) 2013 by Delphix. All rights reserved.
+#
+
+. $STF_SUITE/tests/functional/delegate/delegate_common.kshlib
+
+#
+# DESCRIPTION:
+#      Verify option '-c' will remove the created permission set.
+#
+# STRATEGY:
+#      1. Set created time set to $ROOT_TESTFS.
+#      2. Allow permission create to $STAFF1 on $ROOT_TESTFS.
+#      3. Create $SUBFS and verify $STAFF1 have created time permissions.
+#      4. Verify $STAFF1 has created time permission.
+#      5. Unallow created time permission with option '-c'.
+#      6. Created $SUBFS and verify $STAFF1 have not created time permissions.
+#
+
+verify_runnable "both"
+
+log_assert "Verify option '-c' will remove the created permission set."
+log_onexit restore_root_datasets
+
+log_must $ZFS allow -c $LOCAL_SET $ROOT_TESTFS
+log_must $ZFS allow -l $STAFF1 create,mount $ROOT_TESTFS
+
+# Create $SUBFS and verify $SUBFS has created time permissions.
+user_run $STAFF1 $ZFS create $SUBFS
+if ! datasetexists $SUBFS ; then
+       log_fail "ERROR: ($STAFF1): $ZFS create $SUBFS"
+fi
+log_must verify_perm $SUBFS $LOCAL_SET $STAFF1
+
+#
+# After unallow -c, create $SUBFS2 and verify $SUBFS2 has not created time
+# permissions any more.
+#
+log_must $ZFS unallow -c $LOCAL_SET $ROOT_TESTFS
+user_run $STAFF1 $ZFS create $SUBFS2
+if ! datasetexists $SUBFS2 ; then
+       log_fail "ERROR: ($STAFF1): $ZFS create $SUBFS2"
+fi
+log_must verify_noperm $SUBFS2 $LOCAL_SET $STAFF1
+
+log_pass "Verify option '-c' will remove the created permission set passed."
diff --git a/tests/zfs-tests/tests/functional/delegate/zfs_unallow_006_pos.ksh b/tests/zfs-tests/tests/functional/delegate/zfs_unallow_006_pos.ksh
new file mode 100755 (executable)
index 0000000..af9ea49
--- /dev/null
@@ -0,0 +1,71 @@
+#!/bin/ksh -p
+#
+# CDDL HEADER START
+#
+# The contents of this file are subject to the terms of the
+# Common Development and Distribution License (the "License").
+# You may not use this file except in compliance with the License.
+#
+# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
+# or http://www.opensolaris.org/os/licensing.
+# See the License for the specific language governing permissions
+# and limitations under the License.
+#
+# When distributing Covered Code, include this CDDL HEADER in each
+# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
+# If applicable, add the following below this CDDL HEADER, with the
+# fields enclosed by brackets "[]" replaced with your own identifying
+# information: Portions Copyright [yyyy] [name of copyright owner]
+#
+# CDDL HEADER END
+#
+
+#
+# Copyright 2007 Sun Microsystems, Inc.  All rights reserved.
+# Use is subject to license terms.
+#
+
+#
+# Copyright (c) 2013 by Delphix. All rights reserved.
+#
+
+. $STF_SUITE/tests/functional/delegate/delegate_common.kshlib
+
+#
+# DESCRIPTION:
+#      Verify option '-u', '-g' and '-e' only removed the specified type
+#      permissions set.
+#
+# STRATEGY:
+#      1. Allow '-u' '-g' & '-e' to $STAFF1 on ROOT_TESTFS or $ROOT_TESTVOL.
+#      2. Unallow '-u' '-g' & '-e' on $ROOT_TESTFS or $ROOT_TESTVOL separately.
+#      3. Verify permissions on $ROOT_TESTFS or $ROOT_TESTVOL separately.
+#
+
+verify_runnable "both"
+
+log_assert "Verify option '-u', '-g' and '-e' only removed the specified type "\
+       "permissions set."
+log_onexit restore_root_datasets
+
+for dtst in $DATASETS ; do
+       log_must $ZFS allow -u $STAFF1 $LOCAL_DESC_SET $dtst
+       log_must $ZFS allow -g $STAFF_GROUP $LOCAL_DESC_SET $dtst
+       log_must $ZFS allow -e $LOCAL_DESC_SET $dtst
+
+       log_must verify_perm $dtst $LOCAL_DESC_SET \
+               $STAFF1 $STAFF2 $OTHER1 $OTHER2
+
+       log_must $ZFS unallow -e $dtst
+       log_must verify_perm $dtst $LOCAL_DESC_SET $STAFF1 $STAFF2
+       log_must verify_noperm $dtst $LOCAL_DESC_SET $OTHER1 $OTHER2
+
+       log_must $ZFS unallow -g $STAFF_GROUP $dtst
+       log_must verify_perm $dtst $LOCAL_DESC_SET $STAFF1
+       log_must verify_noperm $dtst $LOCAL_DESC_SET $STAFF2
+
+       log_must $ZFS unallow -u $STAFF1 $dtst
+       log_must verify_noperm $dtst $LOCAL_DESC_SET $STAFF1
+done
+
+log_pass "Verify option '-u', '-g' and '-e' passed."
diff --git a/tests/zfs-tests/tests/functional/delegate/zfs_unallow_007_neg.ksh b/tests/zfs-tests/tests/functional/delegate/zfs_unallow_007_neg.ksh
new file mode 100755 (executable)
index 0000000..e9bd3bf
--- /dev/null
@@ -0,0 +1,64 @@
+#!/bin/ksh -p
+#
+# CDDL HEADER START
+#
+# The contents of this file are subject to the terms of the
+# Common Development and Distribution License (the "License").
+# You may not use this file except in compliance with the License.
+#
+# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
+# or http://www.opensolaris.org/os/licensing.
+# See the License for the specific language governing permissions
+# and limitations under the License.
+#
+# When distributing Covered Code, include this CDDL HEADER in each
+# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
+# If applicable, add the following below this CDDL HEADER, with the
+# fields enclosed by brackets "[]" replaced with your own identifying
+# information: Portions Copyright [yyyy] [name of copyright owner]
+#
+# CDDL HEADER END
+#
+
+#
+# Copyright 2007 Sun Microsystems, Inc.  All rights reserved.
+# Use is subject to license terms.
+#
+
+#
+# Copyright (c) 2013 by Delphix. All rights reserved.
+#
+
+. $STF_SUITE/tests/functional/delegate/delegate_common.kshlib
+
+#
+# DESCRIPTION:
+#      zfs unallow will not remove those permissions which inherited from
+#      its parent filesystem.
+#
+# STRATEGY:
+#      1. Assign perm1 to $ROOT_TESTFS
+#      2. Create $SUBFS and assign perm2 to it.
+#      3. Verify unallow can not affect perm1 on $SUBFS
+#
+
+verify_runnable "both"
+
+log_assert "zfs unallow won't remove those permissions which inherited from " \
+       "its parent dataset."
+log_onexit restore_root_datasets
+
+perm1="atime,devices"; perm2="compression,checksum"
+log_must $ZFS create $SUBFS
+log_must $ZFS allow $STAFF1 $perm1 $ROOT_TESTFS
+log_must $ZFS allow $STAFF1 $perm2 $SUBFS
+
+log_must verify_perm $SUBFS ${perm1},${perm2} $STAFF1
+#
+# Athrough unallow the permissions which don't exists on the specific dataset
+# return 0, the inherited permissions can't be removed in fact.
+#
+log_must $ZFS unallow -u $STAFF1 $perm1 $SUBFS
+log_must verify_perm $SUBFS ${perm1},${perm2} $STAFF1
+
+log_pass "Verify zfs unallow won't remove inherited permissions passed."
diff --git a/tests/zfs-tests/tests/functional/delegate/zfs_unallow_008_neg.ksh b/tests/zfs-tests/tests/functional/delegate/zfs_unallow_008_neg.ksh
new file mode 100755 (executable)
index 0000000..7cd824c
--- /dev/null
@@ -0,0 +1,75 @@
+#!/bin/ksh -p
+#
+# CDDL HEADER START
+#
+# The contents of this file are subject to the terms of the
+# Common Development and Distribution License (the "License").
+# You may not use this file except in compliance with the License.
+#
+# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
+# or http://www.opensolaris.org/os/licensing.
+# See the License for the specific language governing permissions
+# and limitations under the License.
+#
+# When distributing Covered Code, include this CDDL HEADER in each
+# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
+# If applicable, add the following below this CDDL HEADER, with the
+# fields enclosed by brackets "[]" replaced with your own identifying
+# information: Portions Copyright [yyyy] [name of copyright owner]
+#
+# CDDL HEADER END
+#
+
+#
+# Copyright 2007 Sun Microsystems, Inc.  All rights reserved.
+# Use is subject to license terms.
+#
+
+#
+# Copyright (c) 2013 by Delphix. All rights reserved.
+#
+
+. $STF_SUITE/tests/functional/delegate/delegate_common.kshlib
+
+#
+# DESCRIPTION:
+#      zfs unallow can handle invalid arguments.
+#
+# STRATEGY:
+#      1. Set up basic test environment.
+#      2. Verify zfs unallow handle invalid arguments correctly.
+#
+
+verify_runnable "both"
+
+log_assert "zfs unallow can handle invalid arguments."
+log_onexit restore_root_datasets
+
+function neg_test
+{
+       log_mustnot eval "$@ >/dev/null 2>&1"
+}
+
+# Options that cause this test to fail:
+# "-r"
+set -A badopts "everyone -e" "everyone -u $STAFF1" "everyone everyone" \
+       "-c -l" "-c -d" "-c -e" "-c -s" "-u -e" "-s -e" "-s -l -d" \
+       "-s @non-exist-set -l" "-s @non-existen-set -d" \
+       "-s @non-existen-set -e" "-r -u $STAFF1 $STAFF1" \
+       "-u $STAFF1 -g $STAFF_GROUP" "-u $STAFF1 -e"
+
+log_must setup_unallow_testenv
+
+for dtst in $DATASETS ; do
+       log_must $ZFS allow -c create $dtst
+
+       typeset -i i=0
+       while ((i < ${#badopts[@]})); do
+               neg_test $ZFS unallow ${badopts[$i]} $dtst
+               ((i += 1))
+       done
+
+       # Causes test failure: neg_test user_run $STAFF1 $ZFS unallow $dtst
+done
+
+log_pass "zfs unallow can handle invalid arguments passed."
diff --git a/tests/zfs-tests/tests/functional/devices/Makefile.am b/tests/zfs-tests/tests/functional/devices/Makefile.am
new file mode 100644 (file)
index 0000000..ebbfa9a
--- /dev/null
@@ -0,0 +1,9 @@
+pkgdatadir = $(datadir)/@PACKAGE@/zfs-tests/tests/functional/devices
+dist_pkgdata_SCRIPTS = \
+       devices.cfg \
+       devices_common.kshlib \
+       cleanup.ksh \
+       setup.ksh \
+       devices_001_pos.ksh \
+       devices_002_neg.ksh \
+       devices_003_pos.ksh
diff --git a/tests/zfs-tests/tests/functional/devices/cleanup.ksh b/tests/zfs-tests/tests/functional/devices/cleanup.ksh
new file mode 100755 (executable)
index 0000000..3166bd6
--- /dev/null
@@ -0,0 +1,34 @@
+#!/bin/ksh -p
+#
+# CDDL HEADER START
+#
+# The contents of this file are subject to the terms of the
+# Common Development and Distribution License (the "License").
+# You may not use this file except in compliance with the License.
+#
+# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
+# or http://www.opensolaris.org/os/licensing.
+# See the License for the specific language governing permissions
+# and limitations under the License.
+#
+# When distributing Covered Code, include this CDDL HEADER in each
+# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
+# If applicable, add the following below this CDDL HEADER, with the
+# fields enclosed by brackets "[]" replaced with your own identifying
+# information: Portions Copyright [yyyy] [name of copyright owner]
+#
+# CDDL HEADER END
+#
+
+#
+# Copyright 2007 Sun Microsystems, Inc.  All rights reserved.
+# Use is subject to license terms.
+#
+
+#
+# Copyright (c) 2013 by Delphix. All rights reserved.
+#
+
+. $STF_SUITE/include/libtest.shlib
+
+default_cleanup
diff --git a/tests/zfs-tests/tests/functional/devices/devices.cfg b/tests/zfs-tests/tests/functional/devices/devices.cfg
new file mode 100644 (file)
index 0000000..ba3c36a
--- /dev/null
@@ -0,0 +1,32 @@
+#
+# CDDL HEADER START
+#
+# The contents of this file are subject to the terms of the
+# Common Development and Distribution License (the "License").
+# You may not use this file except in compliance with the License.
+#
+# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
+# or http://www.opensolaris.org/os/licensing.
+# See the License for the specific language governing permissions
+# and limitations under the License.
+#
+# When distributing Covered Code, include this CDDL HEADER in each
+# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
+# If applicable, add the following below this CDDL HEADER, with the
+# fields enclosed by brackets "[]" replaced with your own identifying
+# information: Portions Copyright [yyyy] [name of copyright owner]
+#
+# CDDL HEADER END
+#
+
+#
+# Copyright 2008 Sun Microsystems, Inc.  All rights reserved.
+# Use is subject to license terms.
+#
+
+#
+# Copyright (c) 2013 by Delphix. All rights reserved.
+#
+
+export TESTFILE1=testfile1$$
+export TESTFILE2=testfile2$$
diff --git a/tests/zfs-tests/tests/functional/devices/devices_001_pos.ksh b/tests/zfs-tests/tests/functional/devices/devices_001_pos.ksh
new file mode 100755 (executable)
index 0000000..acea6e2
--- /dev/null
@@ -0,0 +1,66 @@
+#!/bin/ksh -p
+#
+# CDDL HEADER START
+#
+# The contents of this file are subject to the terms of the
+# Common Development and Distribution License (the "License").
+# You may not use this file except in compliance with the License.
+#
+# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
+# or http://www.opensolaris.org/os/licensing.
+# See the License for the specific language governing permissions
+# and limitations under the License.
+#
+# When distributing Covered Code, include this CDDL HEADER in each
+# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
+# If applicable, add the following below this CDDL HEADER, with the
+# fields enclosed by brackets "[]" replaced with your own identifying
+# information: Portions Copyright [yyyy] [name of copyright owner]
+#
+# CDDL HEADER END
+#
+
+#
+# Copyright 2007 Sun Microsystems, Inc.  All rights reserved.
+# Use is subject to license terms.
+#
+
+#
+# Copyright (c) 2013 by Delphix. All rights reserved.
+#
+
+. $STF_SUITE/include/libtest.shlib
+. $STF_SUITE/tests/functional/devices/devices.cfg
+. $STF_SUITE/tests/functional/devices/devices_common.kshlib
+
+#
+# DESCRIPTION:
+# When set property devices=on on file system, devices files can be used in
+# this file system.
+#
+# STRATEGY:
+# 1. Create pool and file system.
+# 2. Set devices=on on this file system.
+# 3. Separately create block device file and character file.
+# 4. Separately read from those two device files.
+# 5. Check the return value, and make sure it succeeds.
+#
+
+verify_runnable "global"
+
+log_assert "Setting devices=on on file system, the devices files in this file" \
+       "system can be used."
+log_onexit cleanup
+
+log_must $ZFS set devices=on $TESTPOOL/$TESTFS
+
+#
+# Separately create block device file and character device file, then try to
+# open them and make sure it succeed.
+#
+create_dev_file b $TESTDIR/$TESTFILE1
+log_must $DD if=$TESTDIR/$TESTFILE1 of=$TESTDIR/$TESTFILE1.out count=1
+create_dev_file c $TESTDIR/$TESTFILE2
+log_must $DD if=$TESTDIR/$TESTFILE2 of=$TESTDIR/$TESTFILE2.out count=1
+
+log_pass "Setting devices=on on file system and testing it pass."
diff --git a/tests/zfs-tests/tests/functional/devices/devices_002_neg.ksh b/tests/zfs-tests/tests/functional/devices/devices_002_neg.ksh
new file mode 100755 (executable)
index 0000000..8a1f828
--- /dev/null
@@ -0,0 +1,66 @@
+#!/bin/ksh -p
+#
+# CDDL HEADER START
+#
+# The contents of this file are subject to the terms of the
+# Common Development and Distribution License (the "License").
+# You may not use this file except in compliance with the License.
+#
+# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
+# or http://www.opensolaris.org/os/licensing.
+# See the License for the specific language governing permissions
+# and limitations under the License.
+#
+# When distributing Covered Code, include this CDDL HEADER in each
+# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
+# If applicable, add the following below this CDDL HEADER, with the
+# fields enclosed by brackets "[]" replaced with your own identifying
+# information: Portions Copyright [yyyy] [name of copyright owner]
+#
+# CDDL HEADER END
+#
+
+#
+# Copyright 2007 Sun Microsystems, Inc.  All rights reserved.
+# Use is subject to license terms.
+#
+
+#
+# Copyright (c) 2013 by Delphix. All rights reserved.
+#
+
+. $STF_SUITE/include/libtest.shlib
+. $STF_SUITE/tests/functional/devices/devices.cfg
+. $STF_SUITE/tests/functional/devices/devices_common.kshlib
+
+#
+# DESCRIPTION:
+# When set property devices=off on file system, device files cannot be used
+# in this file system.
+#
+# STRATEGY:
+# 1. Create pool and file system.
+# 2. Set devices=off on this file system.
+# 3. Separately create block device file and character file.
+# 4. Separately read from those two device files.
+# 5. Check the return value, and make sure it failed.
+#
+
+verify_runnable "global"
+
+log_assert "Setting devices=off on file system, the devices files in this file"\
+       "system can not be used."
+log_onexit cleanup
+
+log_must $ZFS set devices=off $TESTPOOL/$TESTFS
+
+#
+# Separately create block device file and character device file, then try to
+# open them and make sure it failed.
+#
+create_dev_file b $TESTDIR/$TESTFILE1
+log_mustnot $DD if=$TESTDIR/$TESTFILE1 of=$TESTDIR/$TESTFILE1.out count=1
+create_dev_file c $TESTDIR/$TESTFILE2
+log_mustnot $DD if=$TESTDIR/$TESTFILE2 of=$TESTDIR/$TESTFILE2.out count=1
+
+log_pass "Setting devices=off on file system and testing it pass."
diff --git a/tests/zfs-tests/tests/functional/devices/devices_003_pos.ksh b/tests/zfs-tests/tests/functional/devices/devices_003_pos.ksh
new file mode 100755 (executable)
index 0000000..837478c
--- /dev/null
@@ -0,0 +1,49 @@
+#!/bin/ksh -p
+#
+# CDDL HEADER START
+#
+# The contents of this file are subject to the terms of the
+# Common Development and Distribution License (the "License").
+# You may not use this file except in compliance with the License.
+#
+# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
+# or http://www.opensolaris.org/os/licensing.
+# See the License for the specific language governing permissions
+# and limitations under the License.
+#
+# When distributing Covered Code, include this CDDL HEADER in each
+# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
+# If applicable, add the following below this CDDL HEADER, with the
+# fields enclosed by brackets "[]" replaced with your own identifying
+# information: Portions Copyright [yyyy] [name of copyright owner]
+#
+# CDDL HEADER END
+#
+
+#
+# Copyright 2007 Sun Microsystems, Inc.  All rights reserved.
+# Use is subject to license terms.
+#
+
+#
+# Copyright (c) 2013 by Delphix. All rights reserved.
+#
+
+. $STF_SUITE/include/libtest.shlib
+
+#
+# DESCRIPTION:
+#
+# Writing random data into /dev/zfs should do no harm.
+#
+# STRATEGY:
+# 1. Write some random data into /dev/zfs
+# 2. Verify that this should fail.
+#
+#
+
+log_assert "Writing random data into /dev/zfs should do no harm."
+
+log_mustnot $DD if=/dev/urandom of=/dev/zfs count=1024
+
+log_pass "Writing random data into /dev/zfs should do no harm."
diff --git a/tests/zfs-tests/tests/functional/devices/devices_common.kshlib b/tests/zfs-tests/tests/functional/devices/devices_common.kshlib
new file mode 100644 (file)
index 0000000..597ca94
--- /dev/null
@@ -0,0 +1,126 @@
+#
+# CDDL HEADER START
+#
+# The contents of this file are subject to the terms of the
+# Common Development and Distribution License (the "License").
+# You may not use this file except in compliance with the License.
+#
+# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
+# or http://www.opensolaris.org/os/licensing.
+# See the License for the specific language governing permissions
+# and limitations under the License.
+#
+# When distributing Covered Code, include this CDDL HEADER in each
+# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
+# If applicable, add the following below this CDDL HEADER, with the
+# fields enclosed by brackets "[]" replaced with your own identifying
+# information: Portions Copyright [yyyy] [name of copyright owner]
+#
+# CDDL HEADER END
+#
+
+#
+# Copyright 2007 Sun Microsystems, Inc.  All rights reserved.
+# Use is subject to license terms.
+#
+
+#
+# Copyright (c) 2013 by Delphix. All rights reserved.
+#
+
+. $STF_SUITE/tests/functional/devices/devices.cfg
+. $STF_SUITE/include/libtest.shlib
+
+#
+# Create block file or charactor file according to parameter.
+#
+# $1 device file type
+# $2 file name
+#
+function create_dev_file
+{
+       typeset filetype=$1
+       typeset filename=$2
+
+       case $filetype in
+               b)
+                       if is_linux; then
+                               devtype=$($DF -T / | $AWK '{print $2}')
+                       else
+                               devtype=$($DF -n / | $AWK '{print $3}')
+                       fi
+                       case $devtype in
+                               zfs)
+                                       rootpool=$($DF / | \
+                                               $AWK '{print $2}')
+                                       rootpool=${rootpool#\(}
+                                       rootpool=${rootpool%%/*}
+
+                                       devstr=$(get_disklist $rootpool)
+                                       devstr=$($ECHO "$devstr" | \
+                                               $AWK '{print $1}')
+                                       [[ -z $devstr ]] && \
+                                               log_fail "Can not get block device file."
+                                       devstr=$DEV_DSKDIR/${devstr}
+                                       ;;
+                               ufs)
+                       #
+                       # Get the existing block device file in current system.
+                       # And bring out the first one.
+                       #
+                                       devstr=$($DF -lhF ufs | \
+                                               $GREP "^${DEV_DSKDIR}" | \
+                                               $AWK '{print $1}')
+                                       devstr=$($ECHO "$devstr" | \
+                                               $AWK '{print $1}')
+                                       [[ -z $devstr ]] && \
+                                               log_fail "Can not get block device file."
+                                       ;;
+                               ext2)
+                                       # TODO: Linux version
+                                       ;;
+                               *)
+                                       log_unsupported "Unsupported fstype " \
+                                               "for / ($devtype)," \
+                                               "only ufs|zfs is supported."
+                                       ;;
+                       esac
+
+                       #
+                       # Get the device file information. i.e:
+                       # $DEV_DSKDIR/c0t0d0s0:      block special (28/768)
+                       #
+                       devstr=$($FILE $devstr)
+
+                       #
+                       # Bring out major and minor number.
+                       #
+                       major=${devstr##*\(}
+                       major=${major%%/*}
+                       minor=${devstr##*/}
+                       minor=${minor%\)}
+
+                       log_must $MKNOD $filename b $major $minor
+                       ;;
+               c)
+                       #
+                       # Create device file '/dev/null'
+                       #
+                       log_must $MKNOD $filename c $($GETMAJOR mm) 2
+                       ;;
+               *)
+                       log_fail "'$filetype' is wrong."
+                       ;;
+       esac
+
+       return 0
+}
+
+function cleanup
+{
+       log_must $ZFS set devices=on $TESTPOOL/$TESTFS
+       log_must $RM -f $TESTDIR/$TESTFILE1
+       log_must $RM -f $TESTDIR/$TESTFILE2
+       log_must $RM -f $TESTDIR/$TESTFILE1.out
+       log_must $RM -f $TESTDIR/$TESTFILE2.out
+}
diff --git a/tests/zfs-tests/tests/functional/devices/setup.ksh b/tests/zfs-tests/tests/functional/devices/setup.ksh
new file mode 100755 (executable)
index 0000000..fc5cec3
--- /dev/null
@@ -0,0 +1,35 @@
+#!/bin/ksh -p
+#
+# CDDL HEADER START
+#
+# The contents of this file are subject to the terms of the
+# Common Development and Distribution License (the "License").
+# You may not use this file except in compliance with the License.
+#
+# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
+# or http://www.opensolaris.org/os/licensing.
+# See the License for the specific language governing permissions
+# and limitations under the License.
+#
+# When distributing Covered Code, include this CDDL HEADER in each
+# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
+# If applicable, add the following below this CDDL HEADER, with the
+# fields enclosed by brackets "[]" replaced with your own identifying
+# information: Portions Copyright [yyyy] [name of copyright owner]
+#
+# CDDL HEADER END
+#
+
+#
+# Copyright 2007 Sun Microsystems, Inc.  All rights reserved.
+# Use is subject to license terms.
+#
+
+#
+# Copyright (c) 2013 by Delphix. All rights reserved.
+#
+
+. $STF_SUITE/include/libtest.shlib
+
+DISK=${DISKS%% *}
+default_setup $DISK
diff --git a/tests/zfs-tests/tests/functional/exec/.gitignore b/tests/zfs-tests/tests/functional/exec/.gitignore
new file mode 100644 (file)
index 0000000..63a68bb
--- /dev/null
@@ -0,0 +1 @@
+/mmap_exec
diff --git a/tests/zfs-tests/tests/functional/exec/Makefile.am b/tests/zfs-tests/tests/functional/exec/Makefile.am
new file mode 100644 (file)
index 0000000..524bf27
--- /dev/null
@@ -0,0 +1,9 @@
+include $(top_srcdir)/config/Rules.am
+
+pkgdatadir = $(datadir)/@PACKAGE@/zfs-tests/tests/functional/exec
+
+dist_pkgdata_SCRIPTS = \
+       cleanup.ksh \
+       setup.ksh \
+       exec_001_pos.ksh \
+       exec_002_neg.ksh
diff --git a/tests/zfs-tests/tests/functional/exec/cleanup.ksh b/tests/zfs-tests/tests/functional/exec/cleanup.ksh
new file mode 100755 (executable)
index 0000000..3166bd6
--- /dev/null
@@ -0,0 +1,34 @@
+#!/bin/ksh -p
+#
+# CDDL HEADER START
+#
+# The contents of this file are subject to the terms of the
+# Common Development and Distribution License (the "License").
+# You may not use this file except in compliance with the License.
+#
+# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
+# or http://www.opensolaris.org/os/licensing.
+# See the License for the specific language governing permissions
+# and limitations under the License.
+#
+# When distributing Covered Code, include this CDDL HEADER in each
+# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
+# If applicable, add the following below this CDDL HEADER, with the
+# fields enclosed by brackets "[]" replaced with your own identifying
+# information: Portions Copyright [yyyy] [name of copyright owner]
+#
+# CDDL HEADER END
+#
+
+#
+# Copyright 2007 Sun Microsystems, Inc.  All rights reserved.
+# Use is subject to license terms.
+#
+
+#
+# Copyright (c) 2013 by Delphix. All rights reserved.
+#
+
+. $STF_SUITE/include/libtest.shlib
+
+default_cleanup
diff --git a/tests/zfs-tests/tests/functional/exec/exec_001_pos.ksh b/tests/zfs-tests/tests/functional/exec/exec_001_pos.ksh
new file mode 100755 (executable)
index 0000000..f6e44d2
--- /dev/null
@@ -0,0 +1,63 @@
+#!/bin/ksh -p
+#
+# CDDL HEADER START
+#
+# The contents of this file are subject to the terms of the
+# Common Development and Distribution License (the "License").
+# You may not use this file except in compliance with the License.
+#
+# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
+# or http://www.opensolaris.org/os/licensing.
+# See the License for the specific language governing permissions
+# and limitations under the License.
+#
+# When distributing Covered Code, include this CDDL HEADER in each
+# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
+# If applicable, add the following below this CDDL HEADER, with the
+# fields enclosed by brackets "[]" replaced with your own identifying
+# information: Portions Copyright [yyyy] [name of copyright owner]
+#
+# CDDL HEADER END
+#
+
+#
+# Copyright 2007 Sun Microsystems, Inc.  All rights reserved.
+# Use is subject to license terms.
+#
+
+#
+# Copyright (c) 2013 by Delphix. All rights reserved.
+#
+
+. $STF_SUITE/include/libtest.shlib
+
+#
+# DESCRIPTION:
+# When set property exec=on on a filesystem, processes can be executed from
+# this filesystem.
+#
+# STRATEGY:
+# 1. Create pool and file system.
+# 2. Copy '/usr/bin/ls' to the ZFS file system.
+# 3. Setting exec=on on this file system.
+# 4. Make sure '/usr/bin/ls' can work in this ZFS file system.
+# 5. Make sure mmap which is using the PROT_EXEC calls succeed.
+#
+
+verify_runnable "both"
+
+function cleanup
+{
+       log_must $RM $TESTDIR/myls
+}
+
+log_assert "Setting exec=on on a filesystem, processes can be executed from " \
+       "this file system."
+log_onexit cleanup
+
+log_must $CP $LS $TESTDIR/myls
+log_must $ZFS set exec=on $TESTPOOL/$TESTFS
+log_must $TESTDIR/myls
+log_must $MMAP_EXEC $TESTDIR/myls
+
+log_pass "Setting exec=on on filesystem testing passed."
diff --git a/tests/zfs-tests/tests/functional/exec/exec_002_neg.ksh b/tests/zfs-tests/tests/functional/exec/exec_002_neg.ksh
new file mode 100755 (executable)
index 0000000..34a7f6c
--- /dev/null
@@ -0,0 +1,84 @@
+#!/bin/ksh -p
+#
+# CDDL HEADER START
+#
+# The contents of this file are subject to the terms of the
+# Common Development and Distribution License (the "License").
+# You may not use this file except in compliance with the License.
+#
+# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
+# or http://www.opensolaris.org/os/licensing.
+# See the License for the specific language governing permissions
+# and limitations under the License.
+#
+# When distributing Covered Code, include this CDDL HEADER in each
+# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
+# If applicable, add the following below this CDDL HEADER, with the
+# fields enclosed by brackets "[]" replaced with your own identifying
+# information: Portions Copyright [yyyy] [name of copyright owner]
+#
+# CDDL HEADER END
+#
+
+#
+# Copyright 2007 Sun Microsystems, Inc.  All rights reserved.
+# Use is subject to license terms.
+#
+
+#
+# Copyright (c) 2013 by Delphix. All rights reserved.
+#
+
+. $STF_SUITE/include/libtest.shlib
+
+#
+# DESCRIPTION:
+# When set property exec=off on a filesystem, processes can not be executed from
+# this filesystem.
+#
+# STRATEGY:
+# 1. Create pool and file system.
+# 2. Copy '/usr/bin/ls' to the ZFS file system.
+# 3. Setting exec=off on this file system.
+# 4. Make sure '/usr/bin/ls' can not work in this ZFS file system.
+# 5. Make sure mmap which is using the PROT_EXEC calls failed.
+#
+
+verify_runnable "both"
+
+function cleanup
+{
+       log_must $RM $TESTDIR/myls
+}
+
+#
+# Execute and check if the return value is equal to expected.
+#
+# $1 expected value
+# $2..$n executed item
+#
+function exec_n_check
+{
+       typeset expect_value=$1
+
+       shift
+       $@
+       ret=$?
+       if [[ $ret != $expect_value ]]; then
+               log_fail "Unexpected return code: '$ret'"
+       fi
+
+       return 0
+}
+
+log_assert "Setting exec=off on a filesystem, processes can not be executed " \
+       "from this file system."
+log_onexit cleanup
+
+log_must $CP $LS $TESTDIR/myls
+log_must $ZFS set exec=off $TESTPOOL/$TESTFS
+
+log_must exec_n_check 126 $TESTDIR/myls
+log_must exec_n_check 13 $MMAP_EXEC $TESTDIR/myls
+
+log_pass "Setting exec=off on filesystem testing passed."
diff --git a/tests/zfs-tests/tests/functional/exec/setup.ksh b/tests/zfs-tests/tests/functional/exec/setup.ksh
new file mode 100755 (executable)
index 0000000..fc5cec3
--- /dev/null
@@ -0,0 +1,35 @@
+#!/bin/ksh -p
+#
+# CDDL HEADER START
+#
+# The contents of this file are subject to the terms of the
+# Common Development and Distribution License (the "License").
+# You may not use this file except in compliance with the License.
+#
+# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
+# or http://www.opensolaris.org/os/licensing.
+# See the License for the specific language governing permissions
+# and limitations under the License.
+#
+# When distributing Covered Code, include this CDDL HEADER in each
+# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
+# If applicable, add the following below this CDDL HEADER, with the
+# fields enclosed by brackets "[]" replaced with your own identifying
+# information: Portions Copyright [yyyy] [name of copyright owner]
+#
+# CDDL HEADER END
+#
+
+#
+# Copyright 2007 Sun Microsystems, Inc.  All rights reserved.
+# Use is subject to license terms.
+#
+
+#
+# Copyright (c) 2013 by Delphix. All rights reserved.
+#
+
+. $STF_SUITE/include/libtest.shlib
+
+DISK=${DISKS%% *}
+default_setup $DISK
diff --git a/tests/zfs-tests/tests/functional/features/Makefile.am b/tests/zfs-tests/tests/functional/features/Makefile.am
new file mode 100644 (file)
index 0000000..4c6142a
--- /dev/null
@@ -0,0 +1 @@
+SUBDIRS = async_destroy
diff --git a/tests/zfs-tests/tests/functional/features/async_destroy/Makefile.am b/tests/zfs-tests/tests/functional/features/async_destroy/Makefile.am
new file mode 100644 (file)
index 0000000..4c77787
--- /dev/null
@@ -0,0 +1,5 @@
+pkgdatadir = $(datadir)/@PACKAGE@/zfs-tests/tests/functional/features/async_destroy
+dist_pkgdata_SCRIPTS = \
+       cleanup.ksh \
+       setup.ksh \
+       async_destroy_001_pos.ksh
diff --git a/tests/zfs-tests/tests/functional/features/async_destroy/async_destroy_001_pos.ksh b/tests/zfs-tests/tests/functional/features/async_destroy/async_destroy_001_pos.ksh
new file mode 100755 (executable)
index 0000000..130c8f2
--- /dev/null
@@ -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) 2013, 2014 by Delphix. All rights reserved.
+#
+
+. $STF_SUITE/include/libtest.shlib
+
+#
+# DESCRIPTION:
+# Exercise the traversal suspend/resume code in async_destroy by
+# destroying a file system that has more blocks than we can free
+# in a single txg.
+#
+# STRATEGY:
+# 1. Create a file system
+# 2. Set recordsize to 512 to create the maximum number of blocks
+# 3. Set compression to off to force zero-ed blocks to be written
+# 4. dd a lot of data from /dev/zero to the file system
+# 5. Destroy the file system
+# 6. Wait for the freeing property to go to 0
+# 7. Use zdb to check for leaked blocks
+#
+
+TEST_FS=$TESTPOOL/async_destroy
+
+verify_runnable "both"
+
+function cleanup
+{
+       datasetexists $TEST_FS && log_must $ZFS destroy $TEST_FS
+}
+
+log_onexit cleanup
+log_assert "async_destroy can suspend and resume traversal"
+
+log_must $ZFS create -o recordsize=512 -o compression=off $TEST_FS
+
+# Fill with 1G
+log_must $DD bs=1024k count=1024 if=/dev/zero of=/$TEST_FS/file
+
+log_must $ZFS destroy $TEST_FS
+
+#
+# We monitor the freeing property, to verify we can see blocks being
+# freed while the suspend/resume code is exerciesd.
+#
+t0=$SECONDS
+count=0
+while [[ $((SECONDS - t0)) -lt 10 ]]; do
+       [[ "0" != "$($ZPOOL list -Ho freeing $TESTPOOL)" ]] && ((count++))
+       [[ $count -gt 1 ]] && break
+       $SLEEP 1
+done
+
+[[ $count -eq 0 ]] && log_fail "Freeing property remained empty"
+
+# Wait for everything to be freed.
+while [[ "0" != "$($ZPOOL list -Ho freeing $TESTPOOL)" ]]; do
+       [[ $((SECONDS - t0)) -gt 180 ]] && \
+           log_fail "Timed out waiting for freeing to drop to zero"
+done
+
+# Check for leaked blocks.
+log_must $ZDB -b $TESTPOOL
+
+log_pass "async_destroy can suspend and resume traversal"
diff --git a/tests/zfs-tests/tests/functional/features/async_destroy/cleanup.ksh b/tests/zfs-tests/tests/functional/features/async_destroy/cleanup.ksh
new file mode 100755 (executable)
index 0000000..3166bd6
--- /dev/null
@@ -0,0 +1,34 @@
+#!/bin/ksh -p
+#
+# CDDL HEADER START
+#
+# The contents of this file are subject to the terms of the
+# Common Development and Distribution License (the "License").
+# You may not use this file except in compliance with the License.
+#
+# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
+# or http://www.opensolaris.org/os/licensing.
+# See the License for the specific language governing permissions
+# and limitations under the License.
+#
+# When distributing Covered Code, include this CDDL HEADER in each
+# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
+# If applicable, add the following below this CDDL HEADER, with the
+# fields enclosed by brackets "[]" replaced with your own identifying
+# information: Portions Copyright [yyyy] [name of copyright owner]
+#
+# CDDL HEADER END
+#
+
+#
+# Copyright 2007 Sun Microsystems, Inc.  All rights reserved.
+# Use is subject to license terms.
+#
+
+#
+# Copyright (c) 2013 by Delphix. All rights reserved.
+#
+
+. $STF_SUITE/include/libtest.shlib
+
+default_cleanup
diff --git a/tests/zfs-tests/tests/functional/features/async_destroy/setup.ksh b/tests/zfs-tests/tests/functional/features/async_destroy/setup.ksh
new file mode 100755 (executable)
index 0000000..d275e06
--- /dev/null
@@ -0,0 +1,36 @@
+#!/bin/ksh -p
+#
+# CDDL HEADER START
+#
+# The contents of this file are subject to the terms of the
+# Common Development and Distribution License (the "License").
+# You may not use this file except in compliance with the License.
+#
+# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
+# or http://www.opensolaris.org/os/licensing.
+# See the License for the specific language governing permissions
+# and limitations under the License.
+#
+# When distributing Covered Code, include this CDDL HEADER in each
+# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
+# If applicable, add the following below this CDDL HEADER, with the
+# fields enclosed by brackets "[]" replaced with your own identifying
+# information: Portions Copyright [yyyy] [name of copyright owner]
+#
+# CDDL HEADER END
+#
+
+#
+# Copyright 2007 Sun Microsystems, Inc.  All rights reserved.
+# Use is subject to license terms.
+#
+
+#
+# Copyright (c) 2013 by Delphix. All rights reserved.
+#
+
+. $STF_SUITE/include/libtest.shlib
+
+DISK=${DISKS%% *}
+
+default_setup $DISK
diff --git a/tests/zfs-tests/tests/functional/grow_pool/Makefile.am b/tests/zfs-tests/tests/functional/grow_pool/Makefile.am
new file mode 100644 (file)
index 0000000..4fc98ff
--- /dev/null
@@ -0,0 +1,4 @@
+pkgdatadir = $(datadir)/@PACKAGE@/zfs-tests/tests/functional/grow_pool
+dist_pkgdata_SCRIPTS = \
+       grow_pool.cfg \
+       grow_pool_001_pos.ksh
diff --git a/tests/zfs-tests/tests/functional/grow_pool/grow_pool.cfg b/tests/zfs-tests/tests/functional/grow_pool/grow_pool.cfg
new file mode 100644 (file)
index 0000000..c2689e8
--- /dev/null
@@ -0,0 +1,72 @@
+#
+# CDDL HEADER START
+#
+# The contents of this file are subject to the terms of the
+# Common Development and Distribution License (the "License").
+# You may not use this file except in compliance with the License.
+#
+# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
+# or http://www.opensolaris.org/os/licensing.
+# See the License for the specific language governing permissions
+# and limitations under the License.
+#
+# When distributing Covered Code, include this CDDL HEADER in each
+# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
+# If applicable, add the following below this CDDL HEADER, with the
+# fields enclosed by brackets "[]" replaced with your own identifying
+# information: Portions Copyright [yyyy] [name of copyright owner]
+#
+# CDDL HEADER END
+#
+
+#
+# Copyright 2008 Sun Microsystems, Inc.  All rights reserved.
+# Use is subject to license terms.
+#
+
+#
+# Copyright (c) 2013 by Delphix. All rights reserved.
+#
+
+. $STF_SUITE/include/libtest.shlib
+
+function set_disks
+{
+       set -A disk_array $(find_disks $DISKS)
+       typeset -i i=0
+       typeset -i limit=2
+       while  (( i < limit )); do
+               if [[ -n ${disk_array[$i]} ]]; then
+                       export DISK${i}="${disk_array[$i]}"
+               else
+                       export DISK=${DISKS%% *}
+                       return
+               fi
+               ((i = i + 1))
+       done
+       export DISK=""
+}
+
+export BLOCK_SIZE=8192
+set_disks
+#
+# Do not make SIZE too large as the three slices may exceed
+# the size of the disk, and also slow down the test
+# which involves filling until ENOSPC
+#
+export SIZE="100mb"
+export SMALL_WRITE_COUNT=100
+export TESTFILE1=file$$.1
+export WRITE_COUNT=65536000
+
+if is_linux; then
+       export SLICE_PREFIX="p"
+       export SLICE=1
+       export SLICE0=1
+       export SLICE1=2
+else
+       export SLICE_PREFIX="s"
+       export SLICE=0
+       export SLICE0=0
+       export SLICE1=1
+fi
diff --git a/tests/zfs-tests/tests/functional/grow_pool/grow_pool_001_pos.ksh b/tests/zfs-tests/tests/functional/grow_pool/grow_pool_001_pos.ksh
new file mode 100755 (executable)
index 0000000..ac3e09b
--- /dev/null
@@ -0,0 +1,74 @@
+#! /bin/ksh -p
+#
+# CDDL HEADER START
+#
+# The contents of this file are subject to the terms of the
+# Common Development and Distribution License (the "License").
+# You may not use this file except in compliance with the License.
+#
+# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
+# or http://www.opensolaris.org/os/licensing.
+# See the License for the specific language governing permissions
+# and limitations under the License.
+#
+# When distributing Covered Code, include this CDDL HEADER in each
+# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
+# If applicable, add the following below this CDDL HEADER, with the
+# fields enclosed by brackets "[]" replaced with your own identifying
+# information: Portions Copyright [yyyy] [name of copyright owner]
+#
+# CDDL HEADER END
+#
+
+#
+# Copyright 2007 Sun Microsystems, Inc.  All rights reserved.
+# Use is subject to license terms.
+#
+
+#
+# Copyright (c) 2013 by Delphix. All rights reserved.
+#
+
+. $STF_SUITE/include/libtest.shlib
+. $STF_SUITE/tests/functional/grow_pool/grow_pool.cfg
+
+#
+# DESCRIPTION:
+# A ZFS file system is limited by the amount of disk space
+# available to the pool. Growing the pool by adding a disk
+# increases the amount of space.
+#
+# STRATEGY:
+# 1) Fill a ZFS filesystem until ENOSPC by creating a large file
+# 2) Grow the pool by adding a disk
+# 3) Verify that more data can now be written to the file system
+#
+
+verify_runnable "global"
+
+log_assert "A zpool may be increased in capacity by adding a disk"
+
+log_must $ZFS set compression=off $TESTPOOL/$TESTFS
+$FILE_WRITE -o create -f $TESTDIR/$TESTFILE1 \
+       -b $BLOCK_SIZE -c $WRITE_COUNT -d 0
+typeset -i zret=$?
+readonly ENOSPC=28
+if [[ $zret -ne $ENOSPC ]]; then
+       log_fail "file_write completed w/o ENOSPC, aborting!!!"
+fi
+
+if [[ ! -s $TESTDIR/$TESTFILE1 ]]; then
+       log_fail "$TESTDIR/$TESTFILE1 was not created"
+fi
+
+if [[ -n $DISK ]]; then
+       log_must $ZPOOL add $TESTPOOL $DISK"s"$SLICE1
+else
+       log_must $ZPOOL add $TESTPOOL $DISK1
+fi
+
+log_must $FILE_WRITE -o append -f $TESTDIR/$TESTFILE1 \
+       -b $BLOCK_SIZE -c $SMALL_WRITE_COUNT -d 0
+
+log_must $ZFS inherit compression $TESTPOOL/$TESTFS
+log_pass "TESTPOOL successfully grown"
diff --git a/tests/zfs-tests/tests/functional/grow_replicas/Makefile.am b/tests/zfs-tests/tests/functional/grow_replicas/Makefile.am
new file mode 100644 (file)
index 0000000..7fdcd95
--- /dev/null
@@ -0,0 +1,4 @@
+pkgdatadir = $(datadir)/@PACKAGE@/zfs-tests/tests/functional/grow_replicas
+dist_pkgdata_SCRIPTS = \
+       grow_replicas.cfg \
+       grow_replicas_001_pos.ksh
diff --git a/tests/zfs-tests/tests/functional/grow_replicas/grow_replicas.cfg b/tests/zfs-tests/tests/functional/grow_replicas/grow_replicas.cfg
new file mode 100644 (file)
index 0000000..7b599cf
--- /dev/null
@@ -0,0 +1,78 @@
+#
+# CDDL HEADER START
+#
+# The contents of this file are subject to the terms of the
+# Common Development and Distribution License (the "License").
+# You may not use this file except in compliance with the License.
+#
+# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
+# or http://www.opensolaris.org/os/licensing.
+# See the License for the specific language governing permissions
+# and limitations under the License.
+#
+# When distributing Covered Code, include this CDDL HEADER in each
+# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
+# If applicable, add the following below this CDDL HEADER, with the
+# fields enclosed by brackets "[]" replaced with your own identifying
+# information: Portions Copyright [yyyy] [name of copyright owner]
+#
+# CDDL HEADER END
+#
+
+#
+# Copyright 2008 Sun Microsystems, Inc.  All rights reserved.
+# Use is subject to license terms.
+#
+
+#
+# Copyright (c) 2013 by Delphix. All rights reserved.
+# Copyright 2016 Nexenta Systems, Inc.
+#
+
+. $STF_SUITE/include/libtest.shlib
+
+function set_disks
+{
+       set -A disk_array $(find_disks $DISKS)
+       typeset -i i=0
+       typeset -i limit=4
+       while  (( i < limit )); do
+               if [[ -n ${disk_array[$i]} ]]; then
+                       export DISK${i}="${disk_array[$i]}"
+               else
+                       export DISK=${DISKS%% *}
+                       return
+               fi
+               ((i = i + 1))
+       done
+       export DISK=""
+}
+
+export BLOCK_SIZE=8192
+set_disks
+
+# Do not make SIZE too large as the three slices may exceed
+# the size of the disk, and also slow down the test
+# which involves filling until ENOSPC.
+export SIZE="100mb"
+export SMALL_WRITE_COUNT=100
+export TESTFILE1=file$$.1
+export WRITE_COUNT=65536000
+
+if is_linux; then
+       export SLICES="0 1 2 3 4"
+       export SLICE_PREFIX="p"
+       export SLICE0=1
+       export SLICE1=2
+       export SLICE2=3
+       export SLICE3=4
+       export SLICE4=5
+else
+       export SLICES="0 1 3 4"
+       export SLICE_PREFIX="s"
+       export SLICE0=0
+       export SLICE1=1
+       export SLICE2=2
+       export SLICE3=3
+       export SLICE4=4
+fi
diff --git a/tests/zfs-tests/tests/functional/grow_replicas/grow_replicas_001_pos.ksh b/tests/zfs-tests/tests/functional/grow_replicas/grow_replicas_001_pos.ksh
new file mode 100755 (executable)
index 0000000..aaf3e53
--- /dev/null
@@ -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 2008 Sun Microsystems, Inc.  All rights reserved.
+# Use is subject to license terms.
+#
+
+#
+# Copyright (c) 2013 by Delphix. All rights reserved.
+# Copyright 2016 Nexenta Systems, Inc.
+#
+
+. $STF_SUITE/tests/functional/grow_replicas/grow_replicas.cfg
+
+# DESCRIPTION:
+# A ZFS filesystem is limited by the amount of disk space
+# available to the pool. Growing the pool by adding a disk
+# increases the amount of space.
+#
+# STRATEGY:
+# 1. Fill the filesystem on mirror/raidz pool by writing a file until ENOSPC.
+# 2. Grow the mirror/raidz pool by adding another mirror/raidz vdev.
+# 3. Verify that more data can now be written to the filesystem.
+
+verify_runnable "global"
+
+if ! is_physical_device $DISKS; then
+       log_unsupported "This test case cannot be run on raw files"
+fi
+
+function cleanup
+{
+       datasetexists $TESTPOOL && log_must destroy_pool $TESTPOOL
+       [[ -d $TESTDIR ]] && log_must $RM -rf $TESTDIR
+}
+
+log_assert "mirror/raidz pool may be increased in capacity by adding a disk"
+
+log_onexit cleanup
+
+readonly ENOSPC=28
+
+for pooltype in "mirror" "raidz"; do
+       log_note "Creating pool type: $pooltype"
+
+       if [[ -n $DISK ]]; then
+               log_note "No spare disks available. Using slices on $DISK"
+               for slice in $SLICES; do
+                       log_must set_partition $slice "$cyl" $SIZE $DISK
+                       cyl=$(get_endslice $DISK $slice)
+               done
+               create_pool $TESTPOOL $pooltype \
+                       ${DISK}${SLICE_PREFIX}${SLICE0} \
+                       ${DISK}${SLICE_PREFIX}${SLICE1}
+       else
+               log_must set_partition 0 "" $SIZE $DISK0
+               log_must set_partition 0 "" $SIZE $DISK1
+               create_pool $TESTPOOL $pooltype \
+                       ${DISK0}${SLICE_PREFIX}${SLICE0} \
+                       ${DISK1}${SLICE_PREFIX}${SLICE0}
+       fi
+
+       [[ -d $TESTDIR ]] && log_must $RM -rf $TESTDIR
+       log_must $ZFS create $TESTPOOL/$TESTFS
+       log_must $ZFS set mountpoint=$TESTDIR $TESTPOOL/$TESTFS
+
+       log_must $ZFS set compression=off $TESTPOOL/$TESTFS
+       $FILE_WRITE -o create -f $TESTDIR/$TESTFILE1 \
+            -b $BLOCK_SIZE -c $WRITE_COUNT -d 0
+
+       [[ $? -ne $ENOSPC ]] && \
+           log_fail "file_write completed w/o ENOSPC"
+
+       [[ ! -s $TESTDIR/$TESTFILE1 ]] && \
+           log_fail "$TESTDIR/$TESTFILE1 was not created"
+
+       # $DISK will be set if we're using slices on one disk
+       if [[ -n $DISK ]]; then
+               log_must $ZPOOL add $TESTPOOL $pooltype ${DISK}s3 ${DISK}s4
+       else
+               [[ -z $DISK2 || -z $DISK3 ]] && 
+                   log_unsupported "No spare disks available"
+               log_must $ZPOOL add $TESTPOOL $pooltype \
+                       ${DISK2}${SLICE_PREFIX}${SLICE0} \
+                       ${DISK3}${SLICE_PREFIX}${SLICE0}
+       fi
+
+       log_must $FILE_WRITE -o append -f $TESTDIR/$TESTFILE1 \
+           -b $BLOCK_SIZE -c $SMALL_WRITE_COUNT -d 0
+
+       log_must destroy_pool $TESTPOOL
+done
+
+log_pass "mirror/raidz pool successfully grown"
diff --git a/tests/zfs-tests/tests/functional/history/Makefile.am b/tests/zfs-tests/tests/functional/history/Makefile.am
new file mode 100644 (file)
index 0000000..b96c6e6
--- /dev/null
@@ -0,0 +1,24 @@
+pkgdatadir = $(datadir)/@PACKAGE@/zfs-tests/tests/functional/history
+dist_pkgdata_SCRIPTS = \
+       history.cfg \
+       history_common.kshlib \
+       cleanup.ksh \
+       setup.ksh \
+       history_001_pos.ksh \
+       history_002_pos.ksh \
+       history_003_pos.ksh \
+       history_004_pos.ksh \
+       history_005_neg.ksh \
+       history_006_neg.ksh \
+       history_007_pos.ksh \
+       history_008_pos.ksh \
+       history_009_pos.ksh \
+       history_010_pos.ksh
+
+
+EXTRA_DIST = \
+       i386.migratedpool.DAT.Z \
+       i386.orig_history.txt \
+       sparc.migratedpool.DAT.Z \
+       sparc.orig_history.txt \
+       zfs-pool-v4.dat.Z
diff --git a/tests/zfs-tests/tests/functional/history/cleanup.ksh b/tests/zfs-tests/tests/functional/history/cleanup.ksh
new file mode 100755 (executable)
index 0000000..a09846a
--- /dev/null
@@ -0,0 +1,38 @@
+#!/bin/ksh -p
+#
+# CDDL HEADER START
+#
+# The contents of this file are subject to the terms of the
+# Common Development and Distribution License (the "License").
+# You may not use this file except in compliance with the License.
+#
+# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
+# or http://www.opensolaris.org/os/licensing.
+# See the License for the specific language governing permissions
+# and limitations under the License.
+#
+# When distributing Covered Code, include this CDDL HEADER in each
+# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
+# If applicable, add the following below this CDDL HEADER, with the
+# fields enclosed by brackets "[]" replaced with your own identifying
+# information: Portions Copyright [yyyy] [name of copyright owner]
+#
+# CDDL HEADER END
+#
+
+#
+# Copyright 2007 Sun Microsystems, Inc.  All rights reserved.
+# Use is subject to license terms.
+#
+
+#
+# Copyright (c) 2013 by Delphix. All rights reserved.
+#
+
+. $STF_SUITE/include/libtest.shlib
+
+[[ -f $OLD_HISTORY ]] && $RM -f $OLD_HISTORY
+[[ -f $TMP_HISTORY ]] && $RM -f $TMP_HISTORY
+[[ -f $NEW_HISTORY ]] && $RM -f $NEW_HISTORY
+
+default_cleanup
diff --git a/tests/zfs-tests/tests/functional/history/history.cfg b/tests/zfs-tests/tests/functional/history/history.cfg
new file mode 100644 (file)
index 0000000..e1ed76e
--- /dev/null
@@ -0,0 +1,45 @@
+#
+# CDDL HEADER START
+#
+# The contents of this file are subject to the terms of the
+# Common Development and Distribution License (the "License").
+# You may not use this file except in compliance with the License.
+#
+# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
+# or http://www.opensolaris.org/os/licensing.
+# See the License for the specific language governing permissions
+# and limitations under the License.
+#
+# When distributing Covered Code, include this CDDL HEADER in each
+# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
+# If applicable, add the following below this CDDL HEADER, with the
+# fields enclosed by brackets "[]" replaced with your own identifying
+# information: Portions Copyright [yyyy] [name of copyright owner]
+#
+# CDDL HEADER END
+#
+
+#
+# Copyright 2008 Sun Microsystems, Inc.  All rights reserved.
+# Use is subject to license terms.
+#
+
+#
+# Copyright (c) 2013 by Delphix. All rights reserved.
+#
+
+export ZFSROOT=
+
+export MPOOL=mpool.$$
+
+export OLD_HISTORY=/tmp/old_history.$$
+export TMP_HISTORY=/tmp/tmp_history.$$
+export NEW_HISTORY=/tmp/new_history.$$
+
+export MIGRATEDPOOLNAME=${MIGRATEDPOOLNAME:-history_pool}
+export TIMEZONE=${TIMEZONE:-US/Mountain}
+
+export HIST_USER="huser"
+export HIST_GROUP="hgroup"
+
+export TESTVOL=testvol.$$
diff --git a/tests/zfs-tests/tests/functional/history/history_001_pos.ksh b/tests/zfs-tests/tests/functional/history/history_001_pos.ksh
new file mode 100755 (executable)
index 0000000..e5a5c83
--- /dev/null
@@ -0,0 +1,111 @@
+#!/bin/ksh -p
+#
+# CDDL HEADER START
+#
+# The contents of this file are subject to the terms of the
+# Common Development and Distribution License (the "License").
+# You may not use this file except in compliance with the License.
+#
+# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
+# or http://www.opensolaris.org/os/licensing.
+# See the License for the specific language governing permissions
+# and limitations under the License.
+#
+# When distributing Covered Code, include this CDDL HEADER in each
+# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
+# If applicable, add the following below this CDDL HEADER, with the
+# fields enclosed by brackets "[]" replaced with your own identifying
+# information: Portions Copyright [yyyy] [name of copyright owner]
+#
+# CDDL HEADER END
+#
+
+#
+# Copyright 2007 Sun Microsystems, Inc.  All rights reserved.
+# Use is subject to license terms.
+
+#
+# Copyright (c) 2013 by Delphix. All rights reserved.
+#
+
+. $STF_SUITE/tests/functional/history/history_common.kshlib
+
+#
+# DESCRIPTION:
+#      Create a scenario to verify the following zpool subcommands are logged.
+#      create, destroy, add, remove, offline, online, attach, detach, replace,
+#      scrub, export, import, clear, upgrade.
+#
+# STRATEGY:
+#      1. Create three virtual disk files and create a mirror.
+#      2. Run and verify pool commands, with special casing for destroy/export.
+#      3. Import a pool and upgrade it, verifying 'upgrade' was logged.
+#
+
+verify_runnable "global"
+
+function cleanup
+{
+       destroy_pool $MPOOL
+       destroy_pool $upgrade_pool
+
+       [[ -d $import_dir ]] && $RM -rf $import_dir
+       for file in $VDEV1 $VDEV2 $VDEV3 $VDEV4; do
+               [[ -f $file ]] && $RM -f $file
+       done
+}
+
+log_assert "Verify zpool sub-commands which modify state are logged."
+log_onexit cleanup
+
+mntpnt=$(get_prop mountpoint $TESTPOOL)
+(( $? != 0)) && log_fail "get_prop($TESTPOOL mountpoint)"
+VDEV1=$mntpnt/vdev1; VDEV2=$mntpnt/vdev2;
+VDEV3=$mntpnt/vdev3; VDEV4=$mntpnt/vdev4;
+
+log_must $MKFILE 64m $VDEV1 $VDEV2 $VDEV3
+log_must $MKFILE 100m $VDEV4
+
+run_and_verify -p "$MPOOL" "$ZPOOL create $MPOOL mirror $VDEV1 $VDEV2"
+run_and_verify -p "$MPOOL" "$ZPOOL add -f $MPOOL spare $VDEV3"
+run_and_verify -p "$MPOOL" "$ZPOOL remove $MPOOL $VDEV3"
+run_and_verify -p "$MPOOL" "$ZPOOL offline $MPOOL $VDEV1"
+run_and_verify -p "$MPOOL" "$ZPOOL online $MPOOL $VDEV1"
+run_and_verify -p "$MPOOL" "$ZPOOL attach $MPOOL $VDEV1 $VDEV4"
+run_and_verify -p "$MPOOL" "$ZPOOL detach $MPOOL $VDEV4"
+run_and_verify -p "$MPOOL" "$ZPOOL replace -f $MPOOL $VDEV1 $VDEV4"
+run_and_verify -p "$MPOOL" "$ZPOOL scrub $MPOOL"
+run_and_verify -p "$MPOOL" "$ZPOOL clear $MPOOL"
+
+# For export and destroy, mimic the behavior of run_and_verify using two
+# commands since the history will be unavailable until the pool is imported
+# again.
+commands=("$ZPOOL export $MPOOL" "$ZPOOL import -d $mntpnt $MPOOL"
+    "$ZPOOL destroy $MPOOL" "$ZPOOL import -D -f -d $mntpnt $MPOOL")
+for i in 0 2; do
+       cmd1="${commands[$i]}"
+       cmd2="${commands[(($i + 1 ))]}"
+
+       $ZPOOL history $MPOOL > $OLD_HISTORY 2>/dev/null
+       log_must $cmd1
+       log_must $cmd2
+       $ZPOOL history $MPOOL > $TMP_HISTORY 2>/dev/null
+       $DIFF $OLD_HISTORY $TMP_HISTORY | $GREP "^> " | $SED 's/^> //g' > \
+           $NEW_HISTORY
+       $GREP "$($ECHO "$cmd1" | $SED 's/\/usr\/sbin\///g')" $NEW_HISTORY \
+           >/dev/null 2>&1 || log_fail "Didn't find \"$cmd1\" in pool history"
+       $GREP "$($ECHO "$cmd2" | $SED 's/\/usr\/sbin\///g')" $NEW_HISTORY \
+           >/dev/null 2>&1 || log_fail "Didn't find \"$cmd2\" in pool history"
+done
+
+run_and_verify -p "$MPOOL" "$ZPOOL split $MPOOL ${MPOOL}_split"
+
+import_dir=/var/tmp/import_dir.$$
+log_must $MKDIR $import_dir
+log_must $CP $STF_SUITE/tests/functional/history/zfs-pool-v4.dat.Z $import_dir
+log_must $UNCOMPRESS $import_dir/zfs-pool-v4.dat.Z
+upgrade_pool=$($ZPOOL import -d $import_dir | $GREP "pool:" | $AWK '{print $2}')
+log_must $ZPOOL import -d $import_dir $upgrade_pool
+run_and_verify -p "$upgrade_pool" "$ZPOOL upgrade $upgrade_pool"
+
+log_pass "zpool sub-commands which modify state are logged passed. "
diff --git a/tests/zfs-tests/tests/functional/history/history_002_pos.ksh b/tests/zfs-tests/tests/functional/history/history_002_pos.ksh
new file mode 100755 (executable)
index 0000000..06edc67
--- /dev/null
@@ -0,0 +1,169 @@
+#!/bin/ksh -p
+#
+# CDDL HEADER START
+#
+# The contents of this file are subject to the terms of the
+# Common Development and Distribution License (the "License").
+# You may not use this file except in compliance with the License.
+#
+# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
+# or http://www.opensolaris.org/os/licensing.
+# See the License for the specific language governing permissions
+# and limitations under the License.
+#
+# When distributing Covered Code, include this CDDL HEADER in each
+# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
+# If applicable, add the following below this CDDL HEADER, with the
+# fields enclosed by brackets "[]" replaced with your own identifying
+# information: Portions Copyright [yyyy] [name of copyright owner]
+#
+# CDDL HEADER END
+#
+
+#
+# Copyright 2009 Sun Microsystems, Inc.  All rights reserved.
+# Use is subject to license terms.
+
+#
+# Copyright (c) 2013 by Delphix. All rights reserved.
+#
+
+. $STF_SUITE/tests/functional/history/history_common.kshlib
+
+#
+# DESCRIPTION:
+#      Create a  scenario to verify the following zfs subcommands are logged.
+#      create, destroy, clone, rename, snapshot, rollback, set, inherit,
+#      receive, promote, hold and release.
+#
+# STRATEGY:
+#      1. Verify that all the zfs commands listed (barring send) produce an
+#         entry in the pool history.
+#
+
+verify_runnable "global"
+
+function cleanup
+{
+
+       [[ -f $tmpfile ]] && $RM -f $tmpfile
+       [[ -f $tmpfile2 ]] && $RM -f $tmpfile2
+       for dataset in $fs $newfs $fsclone $vol $newvol $volclone; do
+               datasetexists $dataset && $ZFS destroy -Rf $dataset
+       done
+       $RM -rf /history.$$
+}
+
+log_assert "Verify zfs sub-commands which modify state are logged."
+log_onexit cleanup
+
+fs=$TESTPOOL/$TESTFS1; newfs=$TESTPOOL/newfs; fsclone=$TESTPOOL/clone
+vol=$TESTPOOL/$TESTVOL ; newvol=$TESTPOOL/newvol; volclone=$TESTPOOL/volclone
+fssnap=$fs@fssnap; fssnap2=$fs@fssnap2
+volsnap=$vol@volsnap; volsnap2=$vol@volsnap2
+tmpfile=/tmp/tmpfile.$$ ; tmpfile2=/tmp/tmpfile2.$$
+
+if is_linux; then
+#      property        value           property        value
+#
+props=(
+       quota           64M             recordsize      512
+       reservation     32M             reservation     none
+       mountpoint      /history.$$     mountpoint      legacy
+       mountpoint      none            compression     lz4
+       compression     on              compression     off
+       compression     lzjb            acltype         noacl
+       acltype         posixacl        xattr           sa
+       atime           on              atime           off
+       devices         on              devices         off
+       exec            on              exec            off
+       setuid          on              setuid          off
+       readonly        on              readonly        off
+       zoned           on              zoned           off
+       snapdir         hidden          snapdir         visible
+       aclinherit      discard         aclinherit      noallow
+       aclinherit      secure          aclinherit      passthrough
+       canmount        off             canmount        on
+       xattr           on              xattr           off
+       compression     gzip            compression     gzip-$((RANDOM%9 + 1))
+       copies          $((RANDOM%3 + 1))
+)
+else
+#      property        value           property        value
+#
+props=(
+       quota           64M             recordsize      512
+       reservation     32M             reservation     none
+       mountpoint      /history.$$     mountpoint      legacy
+       mountpoint      none            sharenfs        on
+       sharenfs        off
+       compression     on              compression     off
+       compression     lzjb            aclmode         discard
+       aclmode         groupmask       aclmode         passthrough
+       atime           on              atime           off
+       devices         on              devices         off
+       exec            on              exec            off
+       setuid          on              setuid          off
+       readonly        on              readonly        off
+       zoned           on              zoned           off
+       snapdir         hidden          snapdir         visible
+       aclinherit      discard         aclinherit      noallow
+       aclinherit      secure          aclinherit      passthrough
+       canmount        off             canmount        on
+       xattr           on              xattr           off
+       compression     gzip            compression     gzip-$((RANDOM%9 + 1))
+       copies          $((RANDOM%3 + 1))
+)
+fi
+
+run_and_verify "$ZFS create $fs"
+# Set all the property for filesystem
+typeset -i i=0
+while ((i < ${#props[@]})) ; do
+       run_and_verify "$ZFS set ${props[$i]}=${props[((i+1))]} $fs"
+
+       # quota, reservation, canmount can not be inherited.
+       #
+       if [[ ${props[$i]} != "quota" && ${props[$i]} != "reservation" && \
+           ${props[$i]} != "canmount" ]];
+       then
+               run_and_verify "$ZFS inherit ${props[$i]} $fs"
+       fi
+
+       ((i += 2))
+done
+
+run_and_verify "$ZFS create -V 64M $vol"
+run_and_verify "$ZFS set volsize=32M $vol"
+run_and_verify "$ZFS snapshot $fssnap"
+run_and_verify "$ZFS hold tag $fssnap"
+run_and_verify "$ZFS release tag $fssnap"
+run_and_verify "$ZFS snapshot $volsnap"
+run_and_verify "$ZFS snapshot $fssnap2"
+run_and_verify "$ZFS snapshot $volsnap2"
+
+# Send isn't logged...
+log_must $ZFS send -i $fssnap $fssnap2 > $tmpfile
+log_must $ZFS send -i $volsnap $volsnap2 > $tmpfile2
+# Verify that's true
+$ZPOOL history $TESTPOOL | $GREP 'zfs send' >/dev/null 2>&1 && \
+    log_fail "'zfs send' found in history of \"$TESTPOOL\""
+
+run_and_verify "$ZFS destroy $fssnap2"
+run_and_verify "$ZFS destroy $volsnap2"
+run_and_verify "$ZFS receive $fs < $tmpfile"
+run_and_verify "$ZFS receive $vol < $tmpfile2"
+run_and_verify "$ZFS rollback -r $fssnap"
+run_and_verify "$ZFS rollback -r $volsnap"
+run_and_verify "$ZFS clone $fssnap $fsclone"
+run_and_verify "$ZFS clone $volsnap $volclone"
+run_and_verify "$ZFS rename $fs $newfs"
+run_and_verify "$ZFS rename $vol $newvol"
+run_and_verify "$ZFS promote $fsclone"
+run_and_verify "$ZFS promote $volclone"
+run_and_verify "$ZFS destroy $newfs"
+run_and_verify "$ZFS destroy $newvol"
+run_and_verify "$ZFS destroy -rf $fsclone"
+run_and_verify "$ZFS destroy -rf $volclone"
+
+log_pass "zfs sub-commands which modify state are logged passed."
diff --git a/tests/zfs-tests/tests/functional/history/history_003_pos.ksh b/tests/zfs-tests/tests/functional/history/history_003_pos.ksh
new file mode 100755 (executable)
index 0000000..224ee15
--- /dev/null
@@ -0,0 +1,103 @@
+#!/bin/ksh -p
+#
+# CDDL HEADER START
+#
+# The contents of this file are subject to the terms of the
+# Common Development and Distribution License (the "License").
+# You may not use this file except in compliance with the License.
+#
+# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
+# or http://www.opensolaris.org/os/licensing.
+# See the License for the specific language governing permissions
+# and limitations under the License.
+#
+# When distributing Covered Code, include this CDDL HEADER in each
+# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
+# If applicable, add the following below this CDDL HEADER, with the
+# fields enclosed by brackets "[]" replaced with your own identifying
+# information: Portions Copyright [yyyy] [name of copyright owner]
+#
+# CDDL HEADER END
+#
+
+#
+# Copyright 2007 Sun Microsystems, Inc.  All rights reserved.
+# Use is subject to license terms.
+#
+
+#
+# Copyright (c) 2013 by Delphix. All rights reserved.
+#
+
+. $STF_SUITE/include/libtest.shlib
+
+#
+# DESCRIPTION:
+#      zpool history will truncate on small pools, leaving pool creation intact
+#
+# STRATEGY:
+#      1. Create two 100M virtual disk files.
+#      2. Create test pool using the two virtual files.
+#      3. Loop 100 times to set and remove compression to test dataset.
+#      4. Make sure 'zpool history' output is truncated
+#      5. Verify that the initial pool creation is preserved.
+#
+
+verify_runnable "global"
+
+function cleanup
+{
+       datasetexists $spool && log_must $ZPOOL destroy $spool
+       [[ -f $VDEV0 ]] && log_must $RM -f $VDEV0
+       [[ -f $VDEV1 ]] && log_must $RM -f $VDEV1
+       [[ -f $TMPFILE ]] && log_must $RM -f $TMPFILE
+}
+
+log_assert "zpool history limitation test."
+log_onexit cleanup
+
+mntpnt=$(get_prop mountpoint $TESTPOOL)
+(( $? != 0 )) && log_fail "get_prop mountpoint $TESTPOOL"
+
+VDEV0=$mntpnt/vdev0; VDEV1=$mntpnt/vdev1
+log_must $MKFILE 100m $VDEV0 $VDEV1
+
+spool=smallpool.$$; sfs=smallfs.$$
+log_must $ZPOOL create $spool $VDEV0 $VDEV1
+log_must $ZFS create $spool/$sfs
+
+typeset -i orig_count=$($ZPOOL history $spool | $WC -l)
+typeset orig_md5=$($ZPOOL history $spool | $HEAD -2 | $MD5SUM | \
+    $AWK '{print $1}')
+
+typeset -i i=0
+while ((i < 100)); do
+       $ZFS set compression=off $spool/$sfs
+       $ZFS set compression=on $spool/$sfs
+       $ZFS set compression=off $spool/$sfs
+       $ZFS set compression=on $spool/$sfs
+       $ZFS set compression=off $spool/$sfs
+
+       ((i += 1))
+done
+
+TMPFILE=/tmp/spool.$$
+$ZPOOL history $spool >$TMPFILE
+typeset -i entry_count=$($WC -l $TMPFILE | $AWK '{print $1}')
+typeset final_md5=$($HEAD -2 $TMPFILE | $MD5SUM | $AWK '{print $1}')
+
+$GREP 'zpool create' $TMPFILE >/dev/null 2>&1 ||
+    log_fail "'zpool create' was not found in pool history"
+
+$GREP 'zfs create' $TMPFILE >/dev/null 2>&1 &&
+    log_fail "'zfs create' was found in pool history"
+
+$GREP 'zfs set compress' $TMPFILE >/dev/null 2>&1 ||
+    log_fail "'zfs set compress' was found in pool history"
+
+# Verify that the creation of the pool was preserved in the history.
+if [[ $orig_md5 != $final_md5 ]]; then
+       log_fail "zpool creation history was not preserved."
+fi
+
+log_pass "zpool history limitation test passed."
diff --git a/tests/zfs-tests/tests/functional/history/history_004_pos.ksh b/tests/zfs-tests/tests/functional/history/history_004_pos.ksh
new file mode 100755 (executable)
index 0000000..e29173f
--- /dev/null
@@ -0,0 +1,100 @@
+#!/bin/ksh -p
+#
+# CDDL HEADER START
+#
+# The contents of this file are subject to the terms of the
+# Common Development and Distribution License (the "License").
+# You may not use this file except in compliance with the License.
+#
+# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
+# or http://www.opensolaris.org/os/licensing.
+# See the License for the specific language governing permissions
+# and limitations under the License.
+#
+# When distributing Covered Code, include this CDDL HEADER in each
+# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
+# If applicable, add the following below this CDDL HEADER, with the
+# fields enclosed by brackets "[]" replaced with your own identifying
+# information: Portions Copyright [yyyy] [name of copyright owner]
+#
+# CDDL HEADER END
+#
+
+#
+# Copyright 2007 Sun Microsystems, Inc.  All rights reserved.
+# Use is subject to license terms.
+#
+
+#
+# Copyright (c) 2013 by Delphix. All rights reserved.
+#
+
+. $STF_SUITE/include/libtest.shlib
+
+#
+# DESCRIPTION:
+#      'zpool history' can cope with simultaneous commands.
+#
+# STRATEGY:
+#      1. Create test pool and test fs.
+#      2. Loop 100 times, set properties to test fs simultaneously.
+#      3. Wait for all the command execution complete.
+#      4. Make sure all the commands was logged by 'zpool history'.
+#
+
+verify_runnable "global"
+
+log_assert "'zpool history' can cope with simultaneous commands."
+
+typeset -i orig_count=$($ZPOOL history $spool | $WC -l | $AWK '{print $1}')
+
+typeset -i i=0
+while ((i < 10)); do
+       $ZFS set compression=off $TESTPOOL/$TESTFS &
+       $ZFS set atime=off $TESTPOOL/$TESTFS &
+       $ZFS create $TESTPOOL/$TESTFS1 &
+       $ZFS create $TESTPOOL/$TESTFS2 &
+       $ZFS create $TESTPOOL/$TESTFS3 &
+
+       wait
+
+       $ZFS snapshot $TESTPOOL/$TESTFS1@snap &
+       $ZFS snapshot $TESTPOOL/$TESTFS2@snap &
+       $ZFS snapshot $TESTPOOL/$TESTFS3@snap &
+
+       wait
+
+       $ZFS clone $TESTPOOL/$TESTFS1@snap $TESTPOOL/clone1 &
+       $ZFS clone $TESTPOOL/$TESTFS2@snap $TESTPOOL/clone2 &
+       $ZFS clone $TESTPOOL/$TESTFS3@snap $TESTPOOL/clone3 &
+
+       wait
+
+       $ZFS promote $TESTPOOL/clone1 &
+       $ZFS promote $TESTPOOL/clone2 &
+       $ZFS promote $TESTPOOL/clone3 &
+
+       wait
+
+       $ZFS destroy $TESTPOOL/$TESTFS1 &
+       $ZFS destroy $TESTPOOL/$TESTFS2 &
+       $ZFS destroy $TESTPOOL/$TESTFS3 &
+
+       wait
+
+       $ZFS destroy -Rf $TESTPOOL/clone1 &
+       $ZFS destroy -Rf $TESTPOOL/clone2 &
+       $ZFS destroy -Rf $TESTPOOL/clone3 &
+
+       wait
+       ((i += 1))
+done
+
+typeset -i entry_count=$($ZPOOL history $spool | $WC -l | $AWK '{print $1}')
+
+if ((entry_count - orig_count != 200)); then
+       log_fail "The entries count error: entry_count=$entry_count " \
+                "orig_count = $orig_count"
+fi
+
+log_pass "'zpool history' can cope with simultaneous commands."
diff --git a/tests/zfs-tests/tests/functional/history/history_005_neg.ksh b/tests/zfs-tests/tests/functional/history/history_005_neg.ksh
new file mode 100755 (executable)
index 0000000..7a3ac27
--- /dev/null
@@ -0,0 +1,65 @@
+#!/bin/ksh -p
+#
+# CDDL HEADER START
+#
+# The contents of this file are subject to the terms of the
+# Common Development and Distribution License (the "License").
+# You may not use this file except in compliance with the License.
+#
+# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
+# or http://www.opensolaris.org/os/licensing.
+# See the License for the specific language governing permissions
+# and limitations under the License.
+#
+# When distributing Covered Code, include this CDDL HEADER in each
+# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
+# If applicable, add the following below this CDDL HEADER, with the
+# fields enclosed by brackets "[]" replaced with your own identifying
+# information: Portions Copyright [yyyy] [name of copyright owner]
+#
+# CDDL HEADER END
+#
+
+#
+# Copyright 2007 Sun Microsystems, Inc.  All rights reserved.
+# Use is subject to license terms.
+#
+
+#
+# Copyright (c) 2013 by Delphix. All rights reserved.
+#
+
+. $STF_SUITE/include/libtest.shlib
+. $STF_SUITE/tests/functional/history/history_common.kshlib
+
+#
+# DESCRIPTION:
+#      Verify the following zpool subcommands are not logged.
+#              zpool get
+#              zpool history
+#              zpool list
+#              zpool status
+#              zpool iostat
+#
+# STRATEGY:
+#      1. Create a test pool.
+#      2. Separately invoke zpool list|status|iostat
+#      3. Verify they was not recored in pool history.
+#
+
+verify_runnable "global"
+
+log_assert "Verify 'zpool get|history|list|status|iostat' will not be logged."
+
+# Save initial TESTPOOL history
+log_must eval "$ZPOOL history $TESTPOOL >$OLD_HISTORY"
+
+log_must $ZPOOL get all $TESTPOOL >/dev/null
+log_must $ZPOOL list $TESTPOOL >/dev/null
+log_must $ZPOOL status $TESTPOOL >/dev/null
+log_must $ZPOOL iostat $TESTPOOL >/dev/null
+
+log_must eval "$ZPOOL history $TESTPOOL >$NEW_HISTORY"
+log_must $DIFF $OLD_HISTORY $NEW_HISTORY
+
+log_pass "Verify 'zpool get|history|list|status|iostat' will not be logged."
diff --git a/tests/zfs-tests/tests/functional/history/history_006_neg.ksh b/tests/zfs-tests/tests/functional/history/history_006_neg.ksh
new file mode 100755 (executable)
index 0000000..d1ed414
--- /dev/null
@@ -0,0 +1,88 @@
+#!/bin/ksh -p
+#
+# CDDL HEADER START
+#
+# The contents of this file are subject to the terms of the
+# Common Development and Distribution License (the "License").
+# You may not use this file except in compliance with the License.
+#
+# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
+# or http://www.opensolaris.org/os/licensing.
+# See the License for the specific language governing permissions
+# and limitations under the License.
+#
+# When distributing Covered Code, include this CDDL HEADER in each
+# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
+# If applicable, add the following below this CDDL HEADER, with the
+# fields enclosed by brackets "[]" replaced with your own identifying
+# information: Portions Copyright [yyyy] [name of copyright owner]
+#
+# CDDL HEADER END
+#
+
+#
+# Copyright 2007 Sun Microsystems, Inc.  All rights reserved.
+# Use is subject to license terms.
+#
+
+#
+# Copyright (c) 2013 by Delphix. All rights reserved.
+#
+
+. $STF_SUITE/tests/functional/history/history_common.kshlib
+. $STF_SUITE/include/libtest.shlib
+
+#
+# DESCRIPTION:
+#      Verify the following zfs subcommands are not logged.
+#      list, get, holds, mount, unmount, share, unshare, send
+#
+# STRATEGY:
+#      1. Create a test pool.
+#      2. Separately invoke zfs list|get|holds|mount|unmount|share|unshare|send
+#      3. Verify they were not recored in pool history.
+#
+
+verify_runnable "global"
+
+function cleanup
+{
+       if datasetexists $fs ; then
+               log_must $ZFS destroy -rf $fs
+       fi
+       log_must $ZFS create $fs
+}
+
+log_assert "Verify 'zfs list|get|holds|mount|unmount|share|unshare|send' " \
+    "will not be logged."
+log_onexit cleanup
+
+# Create initial test environment
+fs=$TESTPOOL/$TESTFS; snap1=$fs@snap1; snap2=$fs@snap2
+if ! is_linux; then
+       log_must $ZFS set sharenfs=on $fs
+fi
+log_must $ZFS snapshot $snap1
+log_must $ZFS hold tag $snap1
+log_must $ZFS snapshot $snap2
+
+# Save initial TESTPOOL history
+log_must eval "$ZPOOL history $TESTPOOL > $OLD_HISTORY"
+
+log_must $ZFS list $fs > /dev/null
+log_must $ZFS get mountpoint $fs > /dev/null
+log_must $ZFS unmount $fs
+log_must $ZFS mount $fs
+if ! is_linux; then
+       log_must $ZFS share $fs
+       log_must $ZFS unshare $fs
+fi
+log_must $ZFS send -i $snap1 $snap2 > /dev/null
+log_must $ZFS holds $snap1
+
+log_must eval "$ZPOOL history $TESTPOOL > $NEW_HISTORY"
+log_must $DIFF $OLD_HISTORY $NEW_HISTORY
+
+log_must $ZFS release tag $snap1
+
+log_pass "Verify 'zfs list|get|mount|unmount|share|unshare|send' passed."
diff --git a/tests/zfs-tests/tests/functional/history/history_007_pos.ksh b/tests/zfs-tests/tests/functional/history/history_007_pos.ksh
new file mode 100755 (executable)
index 0000000..66d2191
--- /dev/null
@@ -0,0 +1,112 @@
+#!/bin/ksh -p
+#
+# CDDL HEADER START
+#
+# The contents of this file are subject to the terms of the
+# Common Development and Distribution License (the "License").
+# You may not use this file except in compliance with the License.
+#
+# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
+# or http://www.opensolaris.org/os/licensing.
+# See the License for the specific language governing permissions
+# and limitations under the License.
+#
+# When distributing Covered Code, include this CDDL HEADER in each
+# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
+# If applicable, add the following below this CDDL HEADER, with the
+# fields enclosed by brackets "[]" replaced with your own identifying
+# information: Portions Copyright [yyyy] [name of copyright owner]
+#
+# CDDL HEADER END
+#
+
+#
+# Copyright 2007 Sun Microsystems, Inc.  All rights reserved.
+# Use is subject to license terms.
+#
+
+#
+# Copyright (c) 2013 by Delphix. All rights reserved.
+#
+
+. $STF_SUITE/include/libtest.shlib
+. $STF_SUITE/tests/functional/history/history_common.kshlib
+
+#
+# DESCRIPTION:
+#      Verify command history moves with pool while pool being migrated
+#
+# STRATEGY:
+#      1. Import uniform platform and cross platform pools
+#      2. Contract the command history of the imported pool
+#      3. Compare imported history log with the previous log.
+#
+
+verify_runnable "global"
+
+function cleanup
+{
+       poolexists $migratedpoolname &&  \
+               log_must $ZPOOL destroy -f $migratedpoolname
+
+       [[ -d $import_dir ]] && $RM -rf $import_dir
+}
+
+log_assert "Verify command history moves with migrated pool."
+log_onexit cleanup
+
+tst_dir=$STF_SUITE/tests/functional/history
+import_dir=$TESTDIR/importdir.$$
+migrated_cmds_f=$import_dir/migrated_history.$$
+migratedpoolname=$MIGRATEDPOOLNAME
+typeset -i RET=1
+typeset -i linenum=0
+
+[[ ! -d $import_dir ]] && log_must $MKDIR $import_dir
+
+# We test the migrations on both uniform platform and cross platform
+for arch in "i386" "sparc"; do
+       log_must $CP $tst_dir/${arch}.orig_history.txt $import_dir
+       orig_cmds_f=$import_dir/${arch}.orig_history.txt
+       # remove blank line
+       orig_cmds_f1=$import_dir/${arch}.orig_history_1.txt
+       $CAT $orig_cmds_f | $GREP -v "^$" > $orig_cmds_f1
+
+       log_must $CP $tst_dir/${arch}.migratedpool.DAT.Z $import_dir
+       log_must $UNCOMPRESS $import_dir/${arch}.migratedpool.DAT.Z
+
+       # destroy the pool with same name, so that import operation succeeds.
+       poolexists $migratedpoolname && \
+           log_must $ZPOOL destroy -f $migratedpoolname
+
+       log_must $ZPOOL import -d $import_dir $migratedpoolname
+       TZ=$TIMEZONE $ZPOOL history $migratedpoolname | $GREP -v "^$" \
+           >$migrated_cmds_f
+       RET=$?
+       (( $RET != 0 )) && log_fail "$ZPOOL histroy $migratedpoolname fails."
+
+       # The migrated history file should differ with original history file on
+       # two commands -- 'export' and 'import', which are included in migrated
+       # history file but not in original history file. so, check the two
+       # commands firstly in migrated history file and then delete them, and
+       # then compare this filtered file with the original history file. They
+       # should be identical at this time.
+       for subcmd in "export" "import"; do
+               $GREP "$subcmd" $migrated_cmds_f >/dev/null 2>&1
+               RET=$?
+               (( $RET != 0 )) && log_fail "zpool $subcmd is not logged for" \
+                   "the imported pool $migratedpoolname."
+       done
+
+       tmpfile=$import_dir/cmds_tmp.$$
+       linenum=`$CAT $migrated_cmds_f | $WC -l`
+       (( linenum = linenum - 2 ))
+       $HEAD -n $linenum $migrated_cmds_f > $tmpfile
+       log_must $DIFF $tmpfile $orig_cmds_f1
+
+       # cleanup for next loop testing
+       log_must $ZPOOL destroy -f $migratedpoolname
+       log_must $RM -f `$LS $import_dir`
+done
+
+log_pass "Verify command history moves with migrated pool."
diff --git a/tests/zfs-tests/tests/functional/history/history_008_pos.ksh b/tests/zfs-tests/tests/functional/history/history_008_pos.ksh
new file mode 100755 (executable)
index 0000000..56df293
--- /dev/null
@@ -0,0 +1,74 @@
+#!/bin/ksh -p
+#
+# CDDL HEADER START
+#
+# The contents of this file are subject to the terms of the
+# Common Development and Distribution License (the "License").
+# You may not use this file except in compliance with the License.
+#
+# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
+# or http://www.opensolaris.org/os/licensing.
+# See the License for the specific language governing permissions
+# and limitations under the License.
+#
+# When distributing Covered Code, include this CDDL HEADER in each
+# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
+# If applicable, add the following below this CDDL HEADER, with the
+# fields enclosed by brackets "[]" replaced with your own identifying
+# information: Portions Copyright [yyyy] [name of copyright owner]
+#
+# CDDL HEADER END
+#
+
+#
+# Copyright 2009 Sun Microsystems, Inc.  All rights reserved.
+# Use is subject to license terms.
+#
+
+#
+# Copyright (c) 2013 by Delphix. All rights reserved.
+#
+
+. $STF_SUITE/tests/functional/history/history_common.kshlib
+
+#
+# DESCRIPTION:
+#      Pool history records all recursive operations.
+#
+# STRATEGY:
+#      1. Create a filesystem and several sub-filesystems in it.
+#      2. Make a recursive snapshot.
+#      3. Verify pool history records all the recursive operations.
+#      4. Do the same verification for hold, release, inherit, rollback and
+#         destroy.
+#
+
+verify_runnable "global"
+
+function cleanup
+{
+       if datasetexists $root_testfs; then
+               log_must $ZFS destroy -rf $root_testfs
+       fi
+       log_must $ZFS create $root_testfs
+}
+
+log_assert "Pool history records all recursive operations."
+log_onexit cleanup
+
+root_testfs=$TESTPOOL/$TESTFS
+fs1=$root_testfs/fs1; fs2=$root_testfs/fs2; fs3=$root_testfs/fs3
+for fs in $fs1 $fs2 $fs3; do
+       log_must $ZFS create $fs
+done
+
+run_and_verify "$ZFS snapshot -r $root_testfs@snap" "-i"
+run_and_verify "$ZFS hold -r tag $root_testfs@snap" "-i"
+run_and_verify "$ZFS release -r tag $root_testfs@snap" "-i"
+log_must $ZFS snapshot $root_testfs@snap2
+log_must $ZFS snapshot $root_testfs@snap3
+run_and_verify "$ZFS rollback -r $root_testfs@snap" "-i"
+run_and_verify "$ZFS inherit -r mountpoint $root_testfs" "-i"
+run_and_verify "$ZFS destroy -r $root_testfs" "-i"
+
+log_pass "Pool history records all recursive operations."
diff --git a/tests/zfs-tests/tests/functional/history/history_009_pos.ksh b/tests/zfs-tests/tests/functional/history/history_009_pos.ksh
new file mode 100755 (executable)
index 0000000..8a10d16
--- /dev/null
@@ -0,0 +1,114 @@
+#!/bin/ksh -p
+#
+# CDDL HEADER START
+#
+# The contents of this file are subject to the terms of the
+# Common Development and Distribution License (the "License").
+# You may not use this file except in compliance with the License.
+#
+# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
+# or http://www.opensolaris.org/os/licensing.
+# See the License for the specific language governing permissions
+# and limitations under the License.
+#
+# When distributing Covered Code, include this CDDL HEADER in each
+# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
+# If applicable, add the following below this CDDL HEADER, with the
+# fields enclosed by brackets "[]" replaced with your own identifying
+# information: Portions Copyright [yyyy] [name of copyright owner]
+#
+# CDDL HEADER END
+#
+
+#
+# Copyright 2009 Sun Microsystems, Inc.  All rights reserved.
+# Use is subject to license terms.
+#
+
+#
+# Copyright (c) 2013 by Delphix. All rights reserved.
+#
+
+. $STF_SUITE/tests/functional/history/history_common.kshlib
+
+#
+# DESCRIPTION:
+#      Verify the delegation internal history are correctly.
+#
+# STRATEGY:
+#      1. Create test group and user.
+#      2. Define permission sets and verify the internal history correctly.
+#      3. Separately verify the internal history above is correct.
+#
+
+verify_runnable "global"
+
+function cleanup
+{
+       del_user $HIST_USER
+       del_group $HIST_GROUP
+}
+
+log_assert "Verify delegated commands are logged in the pool history."
+log_onexit cleanup
+
+testfs=$TESTPOOL/$TESTFS
+# Create history test group and user and get user id and group id
+add_group $HIST_GROUP
+add_user $HIST_GROUP $HIST_USER
+
+#      subcmd          allow_options
+array=(        "allow"         "-s @basic snapshot"
+       "allow"         "-s @set @basic"
+       "allow"         "-c create"
+       "unallow"       "-c create"
+       "allow"         "-c @set"
+       "unallow"       "-c @set"
+       "allow"         "-l -u $HIST_USER snapshot"
+       "allow"         "-u $HIST_USER snapshot"
+       "unallow"       "-u $HIST_USER snapshot"
+       "allow"         "-l -u $HIST_USER @set"
+       "allow"         "-u $HIST_USER @set"
+       "unallow"       "-u $HIST_USER @set"
+       "allow"         "-d -u $HIST_USER snapshot"
+       "allow"         "-u $HIST_USER snapshot"
+       "unallow"       "-u $HIST_USER snapshot"
+       "allow"         "-d -u $HIST_USER @set"
+       "allow"         "-u $HIST_USER @set"
+       "unallow"       "-u $HIST_USER @set"
+       "allow"         "-l -g $HIST_GROUP snapshot"
+       "allow"         "-g $HIST_GROUP snapshot"
+       "unallow"       "-g $HIST_GROUP snapshot"
+       "allow"         "-l -g $HIST_GROUP @set"
+       "allow"         "-g $HIST_GROUP @set"
+       "unallow"       "-g $HIST_GROUP @set"
+       "allow"         "-d -g $HIST_GROUP snapshot"
+       "allow"         "-g $HIST_GROUP snapshot"
+       "unallow"       "-g $HIST_GROUP snapshot"
+       "allow"         "-d -g $HIST_GROUP @set"
+       "allow"         "-g $HIST_GROUP @set"
+       "unallow"       "-g $HIST_GROUP @set"
+       "allow"         "-l -e snapshot"
+       "allow"         "-e snapshot"
+       "unallow"       "-e snapshot"
+       "allow"         "-l -e @set"
+       "allow"         "-e @set"
+       "unallow"       "-e @set"
+       "allow"         "-d -e snapshot"
+       "allow"         "-e snapshot"
+       "unallow"       "-e snapshot"
+       "allow"         "-d -e @set"
+       "allow"         "-e @set"
+       "unallow"       "-e @set"
+)
+
+typeset -i i=0
+while ((i < ${#array[@]})); do
+       subcmd=${array[$i]}
+       options=${array[((i + 1))]}
+
+       run_and_verify "$ZFS $subcmd $options $testfs" "-i"
+       ((i += 2))
+done
+
+log_pass "Verify delegated commands are logged in the pool history."
diff --git a/tests/zfs-tests/tests/functional/history/history_010_pos.ksh b/tests/zfs-tests/tests/functional/history/history_010_pos.ksh
new file mode 100755 (executable)
index 0000000..4c146d8
--- /dev/null
@@ -0,0 +1,76 @@
+#!/bin/ksh -p
+#
+# CDDL HEADER START
+#
+# The contents of this file are subject to the terms of the
+# Common Development and Distribution License (the "License").
+# You may not use this file except in compliance with the License.
+#
+# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
+# or http://www.opensolaris.org/os/licensing.
+# See the License for the specific language governing permissions
+# and limitations under the License.
+#
+# When distributing Covered Code, include this CDDL HEADER in each
+# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
+# If applicable, add the following below this CDDL HEADER, with the
+# fields enclosed by brackets "[]" replaced with your own identifying
+# information: Portions Copyright [yyyy] [name of copyright owner]
+#
+# CDDL HEADER END
+#
+
+#
+# Copyright 2009 Sun Microsystems, Inc.  All rights reserved.
+# Use is subject to license terms.
+#
+
+#
+# Copyright (c) 2013 by Delphix. All rights reserved.
+#
+
+. $STF_SUITE/tests/functional/history/history_common.kshlib
+
+#
+# DESCRIPTION:
+#      Verify internal long history information are correct.
+#
+# STRATEGY:
+#      1. Create non-root test user and group.
+#      2. Do some zfs operations as a root and non-root user.
+#      3. Verify the long history information is correct.
+#
+
+verify_runnable "global"
+
+function cleanup
+{
+       del_user $HIST_USER
+       del_group $HIST_GROUP
+       datasetexists $root_testfs && log_must $ZFS destroy -rf $root_testfs
+}
+
+log_assert "Verify internal long history information are correct."
+log_onexit cleanup
+
+root_testfs=$TESTPOOL/$TESTFS1
+
+# Create history test group and user and get user id and group id
+add_group $HIST_GROUP
+add_user $HIST_GROUP $HIST_USER
+
+run_and_verify "$ZFS create $root_testfs" "-l"
+run_and_verify "$ZFS allow $HIST_GROUP snapshot,mount $root_testfs" "-l"
+run_and_verify "$ZFS allow $HIST_USER destroy,mount $root_testfs" "-l"
+run_and_verify "$ZFS allow $HIST_USER reservation $root_testfs" "-l"
+run_and_verify "$ZFS allow $HIST_USER allow $root_testfs" "-l"
+run_and_verify -u "$HIST_USER" "$ZFS snapshot $root_testfs@snap" "-l"
+run_and_verify -u "$HIST_USER" "$ZFS destroy $root_testfs@snap" "-l"
+run_and_verify -u "$HIST_USER" "$ZFS set reservation=64M $root_testfs" "-l"
+run_and_verify -u "$HIST_USER" \
+    "$ZFS allow $HIST_USER reservation $root_testfs" "-l"
+run_and_verify "$ZFS unallow $HIST_USER create $root_testfs" "-l"
+run_and_verify "$ZFS unallow $HIST_GROUP snapshot $root_testfs" "-l"
+run_and_verify "$ZFS destroy -r $root_testfs" "-l"
+
+log_pass "Verify internal long history information pass."
diff --git a/tests/zfs-tests/tests/functional/history/history_common.kshlib b/tests/zfs-tests/tests/functional/history/history_common.kshlib
new file mode 100644 (file)
index 0000000..e1f1d06
--- /dev/null
@@ -0,0 +1,416 @@
+#
+# CDDL HEADER START
+#
+# The contents of this file are subject to the terms of the
+# Common Development and Distribution License (the "License").
+# You may not use this file except in compliance with the License.
+#
+# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
+# or http://www.opensolaris.org/os/licensing.
+# See the License for the specific language governing permissions
+# and limitations under the License.
+#
+# When distributing Covered Code, include this CDDL HEADER in each
+# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
+# If applicable, add the following below this CDDL HEADER, with the
+# fields enclosed by brackets "[]" replaced with your own identifying
+# information: Portions Copyright [yyyy] [name of copyright owner]
+#
+# CDDL HEADER END
+#
+
+#
+# Copyright 2007 Sun Microsystems, Inc.  All rights reserved.
+# Use is subject to license terms.
+#
+
+#
+# Copyright (c) 2013 by Delphix. All rights reserved.
+#
+
+. $STF_SUITE/include/libtest.shlib
+. $STF_SUITE/tests/functional/history/history.cfg
+
+function run_and_verify
+{
+       typeset user pool
+       while getopts "p:u:" opt; do
+               case $opt in
+               p)
+                       pool=$OPTARG
+                       ;;
+               u)
+                       user=$OPTARG
+                       ;;
+               esac
+       done
+       shift $(($OPTIND - 1))
+
+       pool=${pool:-$TESTPOOL}
+       user=${user:-"root"}
+       fullcmd="$1"
+       flags="$2"
+
+       if is_linux; then
+               histcmd=$($ECHO $fullcmd | $SED 's/^.*\/\(zpool .*\).*$/\1/')
+               histcmd=$($ECHO $histcmd | $SED 's/^.*\/\(zfs .*\).*$/\1/')
+       else
+               histcmd=$($ECHO $fullcmd | $SED 's/\/usr\/sbin\///g')
+       fi
+
+       cmd=$($ECHO $histcmd | $AWK '{print $1}')
+       subcmd=$($ECHO $histcmd | $AWK '{print $2}')
+
+       # If we aren't running zpool or zfs, something is wrong
+       [[ $cmd == "zpool" || $cmd == "zfs" ]] || \
+           log_fail "run_and_verify called with \"$cmd ($fullcmd)\""
+
+       # If this is a 'zfs receive' truncate the stdin redirect
+       [[ $subcmd == "receive" || $subcmd == "recv" ]] && \
+           histcmd=${histcmd%% <*}
+
+       # Run the command as the specified user, and find the new history.
+       $ZPOOL history $flags $pool > $OLD_HISTORY 2>/dev/null
+       if [[ $user == "root" ]]; then
+               log_must eval "$fullcmd"
+       else
+               log_must $SU $user -c "eval $fullcmd"
+       fi
+       $ZPOOL history $flags $pool > $TMP_HISTORY 2>/dev/null
+       $DIFF $OLD_HISTORY $TMP_HISTORY | $GREP "^> " | $SED 's/^> //g' \
+           > $NEW_HISTORY
+
+       # Verify what's common to every case, regardless of zpool history flags.
+       $GREP "$histcmd" $NEW_HISTORY >/dev/null 2>&1 || \
+           log_fail "Didn't find \"$histcmd\" in pool history"
+
+       # If 'zpool history' was called without any flags, then we're done.
+       [[ -z $flags ]] && return
+
+       # Verify the new history in cases that are more interesting because
+       # additional information is logged with -i or -l.
+
+       [[ $flags =~ "i" ]] && log_must verify_$subcmd "$histcmd" "$subcmd" \
+           "$flags"
+       [[ $flags =~ "l" ]] && log_must verify_long "$histcmd" "$user" "$flags"
+}
+
+function verify_long
+{
+       typeset cmd=$1
+       typeset user=$2
+       typeset flags=$3
+
+       [[ $flags =~ "l" ]] || return 1
+
+       typeset uid=$($ID -u $user)
+       typeset hname=$($HOSTNAME)
+       if ! is_global_zone; then
+               hname=$hname:$($ZONENAME)
+       fi
+
+       $GREP "$cmd \[user $uid ($user) on $hname\]" $NEW_HISTORY >/dev/null \
+           2>&1
+       if [[ $? != 0 ]]; then
+               log_note "Couldn't find long information for \"$cmd\""
+               return 1
+       fi
+
+       return 0
+}
+
+function verify_hold
+{
+       typeset cmd=$1
+       typeset subcmd=$2
+       typeset flags=$3
+
+       [[ $flags =~ "i" ]] || return 1
+
+       typeset tag=$($ECHO $cmd | $AWK '{print $4}')
+       typeset fullname=${cmd##* }
+       typeset dsname=${fullname%%@*}
+       typeset snapname=${fullname##*@}
+
+       # This works whether or not the hold was recursive
+       for ds in $($ZFS list -r -Ho name -t snapshot $dsname | \
+           $GREP "@$snapname"); do
+               $GREP "$subcmd $ds ([0-9]*) tag=$tag" $NEW_HISTORY \
+                   >/dev/null 2>&1
+               if [[ $? != 0 ]]; then
+                       log_note "Didn't find hold on $ds with $tag"
+                       return 1
+               fi
+       done
+
+       return 0
+}
+
+function verify_release
+{
+       # hold and release formats only differ by the subcommand name, so
+       # simply reuse the hold function.
+       verify_hold "$1" "release" "$3"
+}
+
+function verify_rollback
+{
+       typeset cmd=$1
+       typeset flags=$3
+
+       [[ $flags =~ "i" ]] || return 1
+
+       typeset fullname=${cmd##* }
+       typeset dsname=${fullname%%@*}
+       typeset parent_fs=${dsname##*/}
+       typeset rb_fs=${dsname}/%rollback
+       typeset snapname=${fullname##*@}
+
+       $GREP "clone swap $rb_fs ([0-9]*) parent=$parent_fs" $NEW_HISTORY \
+           >/dev/null 2>&1
+       if [[ $? != 0 ]]; then
+               log_note "Didn't find rollback clone swap in pool history"
+               return 1
+       fi
+
+       $GREP "destroy $rb_fs" $NEW_HISTORY >/dev/null 2>&1
+       if [[ $? != 0 ]]; then
+               log_note "Didn't find rollback destroy in pool history"
+               return 1
+       fi
+
+       return 0
+}
+
+function verify_inherit
+{
+       typeset cmd=$1
+       typeset flags=$3
+
+       [[ $flags =~ "i" ]] || return 1
+
+       typeset dsname=${cmd##* }
+       typeset prop=${cmd% *}
+       prop=${prop##* }
+
+       # This works whether or not the inherit was recursive
+       for ds in $($ZFS list -r -Ho name -t filesystem $dsname); do
+               $GREP "$subcmd $ds ([0-9]*) ${prop}=" $NEW_HISTORY >/dev/null \
+                   2>&1
+               if [[ $? != 0 ]]; then
+                       log_note "Didn't find inherit history for $ds"
+                       return 1
+               fi
+       done
+
+       return 0
+}
+
+function verify_allow
+{
+       typeset cmd=$1
+       typeset subcmd=$2
+       typeset flags=$3
+
+       [[ $flags =~ "i" ]] || return 1
+       [[ $subcmd == "allow" ]] && subcmd="update"
+       [[ $subcmd == "unallow" ]] && subcmd="remove"
+       typeset is_set lflag dflag dsname gname gid uname uid opt str code tmp
+
+       #
+       # Here, we determine three things:
+       # - Whether we're operating on a set or an indivdual permission (which
+       #   dictates the case of the first character in the code)
+       # - The name of the dataset we're operating on.
+       # - Whether the operation applies locally or to descendent datasets (or
+       #   both)
+       #
+       $ECHO $cmd  | $AWK '{i = NF - 1; print $i}' | $GREP '@' >/dev/null \
+           2>&1 && is_set=1
+       dsname=${cmd##* }
+       [[ $cmd =~ "-l " ]] && lflag=1
+       [[ $cmd =~ "-d " ]] && dflag=1
+       if [[ -z $lflag && -z $dflag ]]; then
+               lflag=1
+               dflag=1
+       fi
+
+       #
+       # For each of the five cases below, the operation is essentially the
+       # same. First, use the command passed in to determine what the code at
+       # the end of the pool history will be. The specifics of the code are
+       # described in a block comment at the top of dsl_deleg.c. Once that's
+       # been assembled, check for its presence in the history, and return
+       # success or failure accordingly.
+       #
+       if [[ $cmd =~ "-s " ]]; then
+               str="s-\$@"
+               [[ -n $is_set ]] && str="S-\$@"
+               tmp=${cmd#*@}
+               code="$str${tmp% *}"
+               $GREP "permission $subcmd $dsname ([0-9]*) $code" \
+                   $NEW_HISTORY >/dev/null 2>&1
+               if [[ $? != 0 ]]; then
+                        log_note "Couldn't find $code in $NEW_HISTORY"
+                        return 1
+                fi
+       elif [[ $cmd =~ "-c " ]]; then
+               str="c-\$"
+               [[ -n $is_set ]] && str="C-\$"
+               tmp=${cmd#*-c}
+               code="$str${tmp% *}"
+               $GREP "permission $subcmd $dsname ([0-9]*) $code" \
+                   $NEW_HISTORY >/dev/null 2>&1
+               if [ $? != 0 ]]; then
+                        log_note "Couldn't find $code in $NEW_HISTORY"
+                        return 1
+               fi
+       elif [[ $cmd =~ "-u " ]]; then
+               str="u"
+               [[ -n $is_set ]] && str="U"
+               tmp=${cmd##*-u }
+               opt=$($ECHO $tmp | $AWK '{print $2}')
+               uid=$($ID -u ${tmp%% *})
+               if [[ -n $lflag ]]; then
+                       code="${str}l\$$uid $opt"
+                       $GREP "permission $subcmd $dsname ([0-9]*) $code" \
+                           $NEW_HISTORY >/dev/null 2>&1
+                       if [ $? != 0 ]]; then
+                                log_note "Couldn't find $code in $NEW_HISTORY"
+                                return 1
+                       fi
+               fi
+               if [[ -n $dflag ]]; then
+                       code="${str}d\$$uid $opt"
+                       $GREP "permission $subcmd $dsname ([0-9]*) $code" \
+                           $NEW_HISTORY >/dev/null 2>&1
+                       if [ $? != 0 ]]; then
+                                log_note "Couldn't find $code in $NEW_HISTORY"
+                                return 1
+                       fi
+               fi
+       elif [[ $cmd =~ "-g " ]]; then
+               str="g"
+               [[ -n $is_set ]] && str="G"
+               tmp=${cmd##*-g }
+               opt=$($ECHO $tmp | $AWK '{print $2}')
+               gid=$($AWK -F: "/^${tmp%% *}:/ {print \$3}" /etc/group)
+               if [[ -n $lflag ]]; then
+                       code="${str}l\$$gid $opt"
+                       $GREP "permission $subcmd $dsname ([0-9]*) $code" \
+                           $NEW_HISTORY >/dev/null 2>&1
+                       if [ $? != 0 ]]; then
+                                log_note "Couldn't find $code in $NEW_HISTORY"
+                                return 1
+                       fi
+               fi
+               if [[ -n $dflag ]]; then
+                       code="${str}d\$$gid $opt"
+                       $GREP "permission $subcmd $dsname ([0-9]*) $code" \
+                           $NEW_HISTORY >/dev/null 2>&1
+                       if [ $? != 0 ]]; then
+                                log_note "Couldn't find $code in $NEW_HISTORY"
+                                return 1
+                       fi
+               fi
+       elif [[ $cmd =~ "-e " ]]; then
+               str="e"
+               [[ -n $is_set ]] && str="E"
+               opt=${cmd##*-e }
+               opt=${opt%% *}
+               if [[ -n $lflag ]]; then
+                       code="${str}l\$ $opt"
+                       $GREP "permission $subcmd $dsname ([0-9]*) $code" \
+                           $NEW_HISTORY >/dev/null 2>&1
+                       if [ $? != 0 ]]; then
+                                log_note "Couldn't find $code in $NEW_HISTORY"
+                                return 1
+                       fi
+               fi
+               if [[ -n $dflag ]]; then
+                       code="${str}d\$ $opt"
+                       $GREP "permission $subcmd $dsname ([0-9]*) $code" \
+                           $NEW_HISTORY >/dev/null 2>&1
+                       if [ $? != 0 ]]; then
+                                log_note "Couldn't find $code in $NEW_HISTORY"
+                                return 1
+                       fi
+               fi
+       else
+               log_note "Can't parse command \"$cmd\""
+               return 1
+       fi
+
+       return 0
+}
+
+function verify_unallow
+{
+       #
+       # The unallow and allow history have the same format, except the former
+       # logs "permission removed" and the latter "permission updated" so
+       # simply reuse the allow function.
+       #
+       verify_allow "$1" "unallow" "$3"
+}
+
+function verify_destroy
+{
+       typeset cmd=$1
+       typeset flags=$3
+
+       # This function doesn't currently verifiy the zpool command.
+       [[ ${cmd%% *} == "zfs" ]] || return 1
+       [[ $flags =~ "i" ]] || return 1
+
+       typeset dsname=${cmd##* }
+       [[ $dsname =~ "@" ]] && typeset is_snap=1
+
+       if [[ -n $is_snap ]]; then
+               $GREP "ioctl destroy_snaps" $NEW_HISTORY >/dev/null 2>&1
+               if [[ $? != 0 ]]; then
+                       log_note "Didn't find ioctl while destroying $dsname"
+                       return 1
+               fi
+       fi
+
+       # This should be present for datasets and snapshots alike
+       $GREP "destroy $dsname" $NEW_HISTORY >/dev/null 2>&1
+       if [[ $? != 0 ]]; then
+               log_note "Didn't find \"destroy\" for $dsname"
+               return 1
+       fi
+
+       return 0
+}
+
+function verify_snapshot
+{
+       typeset cmd=$1
+       typeset flags=$3
+
+       [[ $flags =~ "i" ]] || return 1
+
+       typeset fullname=${cmd##* }
+       typeset dsname=${fullname%%@*}
+       typeset snapname=${fullname##*@}
+
+       $GREP "\[txg:[0-9]*\] $subcmd $fullname ([0-9]*)" $NEW_HISTORY \
+           >/dev/null 2>&1
+       if [[ $? != 0 ]]; then
+               log_note "Didn't find snapshot command for $fullname"
+               return 1
+       fi
+
+       # This works whether or not the snapshot was recursive
+       for ds in $($ZFS list -r -Ho name -t snapshot $dsname | \
+           $GREP "@$snapname"); do
+               $GREP "^[ ]* $ds$" $NEW_HISTORY >/dev/null 2>&1
+               if [[ $? != 0 ]]; then
+                       log_note "Didn't find \"ioctl snapshot\" for $ds"
+                       return 1
+               fi
+       done
+
+       return 0
+}
diff --git a/tests/zfs-tests/tests/functional/history/i386.migratedpool.DAT.Z b/tests/zfs-tests/tests/functional/history/i386.migratedpool.DAT.Z
new file mode 100644 (file)
index 0000000..21cd7fc
Binary files /dev/null and b/tests/zfs-tests/tests/functional/history/i386.migratedpool.DAT.Z differ
diff --git a/tests/zfs-tests/tests/functional/history/i386.orig_history.txt b/tests/zfs-tests/tests/functional/history/i386.orig_history.txt
new file mode 100644 (file)
index 0000000..148b825
--- /dev/null
@@ -0,0 +1,12 @@
+History for 'history_pool':
+2006-10-20.13:18:37 zpool create history_pool /var/tmp/i386.migratedpool.DAT
+2006-10-20.13:18:37 zfs create history_pool/fs
+2006-10-20.13:18:37 zfs set compression=on history_pool/fs
+2006-10-20.13:18:37 zfs set checksum=on history_pool
+2006-10-20.13:18:37 zfs snapshot history_pool/fs@snap
+2006-10-20.13:18:37 zfs clone history_pool/fs@snap history_pool/clone
+2006-10-20.13:18:37 zfs promote history_pool/clone
+2006-10-20.13:18:37 zfs promote history_pool/fs
+2006-10-20.13:18:37 zfs destroy -r -R history_pool/fs
+2006-10-20.13:18:37 zpool export history_pool
+2007-04-05.00:05:38 zpool upgrade history_pool
diff --git a/tests/zfs-tests/tests/functional/history/setup.ksh b/tests/zfs-tests/tests/functional/history/setup.ksh
new file mode 100755 (executable)
index 0000000..fc5cec3
--- /dev/null
@@ -0,0 +1,35 @@
+#!/bin/ksh -p
+#
+# CDDL HEADER START
+#
+# The contents of this file are subject to the terms of the
+# Common Development and Distribution License (the "License").
+# You may not use this file except in compliance with the License.
+#
+# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
+# or http://www.opensolaris.org/os/licensing.
+# See the License for the specific language governing permissions
+# and limitations under the License.
+#
+# When distributing Covered Code, include this CDDL HEADER in each
+# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
+# If applicable, add the following below this CDDL HEADER, with the
+# fields enclosed by brackets "[]" replaced with your own identifying
+# information: Portions Copyright [yyyy] [name of copyright owner]
+#
+# CDDL HEADER END
+#
+
+#
+# Copyright 2007 Sun Microsystems, Inc.  All rights reserved.
+# Use is subject to license terms.
+#
+
+#
+# Copyright (c) 2013 by Delphix. All rights reserved.
+#
+
+. $STF_SUITE/include/libtest.shlib
+
+DISK=${DISKS%% *}
+default_setup $DISK
diff --git a/tests/zfs-tests/tests/functional/history/sparc.migratedpool.DAT.Z b/tests/zfs-tests/tests/functional/history/sparc.migratedpool.DAT.Z
new file mode 100644 (file)
index 0000000..47a61ff
Binary files /dev/null and b/tests/zfs-tests/tests/functional/history/sparc.migratedpool.DAT.Z differ
diff --git a/tests/zfs-tests/tests/functional/history/sparc.orig_history.txt b/tests/zfs-tests/tests/functional/history/sparc.orig_history.txt
new file mode 100644 (file)
index 0000000..2d0e342
--- /dev/null
@@ -0,0 +1,12 @@
+History for 'history_pool':
+2006-10-27.03:13:47 zpool create history_pool /var/tmp/sparc.migratedpool.DAT
+2006-10-27.03:13:48 zfs create history_pool/fs
+2006-10-27.03:13:48 zfs set compression=on history_pool/fs
+2006-10-27.03:13:48 zfs set checksum=on history_pool
+2006-10-27.03:13:48 zfs snapshot history_pool/fs@snap
+2006-10-27.03:13:48 zfs clone history_pool/fs@snap history_pool/clone
+2006-10-27.03:13:49 zfs promote history_pool/clone
+2006-10-27.03:13:49 zfs promote history_pool/fs
+2006-10-27.03:13:49 zfs destroy -r -R history_pool/fs
+2006-10-27.03:13:49 zpool export history_pool
+2007-04-05.00:41:55 zpool upgrade history_pool
diff --git a/tests/zfs-tests/tests/functional/history/zfs-pool-v4.dat.Z b/tests/zfs-tests/tests/functional/history/zfs-pool-v4.dat.Z
new file mode 100644 (file)
index 0000000..bc32472
Binary files /dev/null and b/tests/zfs-tests/tests/functional/history/zfs-pool-v4.dat.Z differ
diff --git a/tests/zfs-tests/tests/functional/inheritance/Makefile.am b/tests/zfs-tests/tests/functional/inheritance/Makefile.am
new file mode 100644 (file)
index 0000000..d07e2b1
--- /dev/null
@@ -0,0 +1,53 @@
+pkgdatadir = $(datadir)/@PACKAGE@/zfs-tests/tests/functional/inheritance
+dist_pkgdata_SCRIPTS = \
+       inherit.kshlib \
+       cleanup.ksh \
+       inherit_001_pos.ksh \
+       config001.cfg \
+       config002.cfg \
+       config003.cfg \
+       config004.cfg \
+       config005.cfg \
+       config006.cfg \
+       config007.cfg \
+       config008.cfg \
+       config009.cfg \
+       config010.cfg \
+       config011.cfg \
+       config012.cfg \
+       config013.cfg \
+       config014.cfg \
+       config015.cfg \
+       config016.cfg \
+       config017.cfg \
+       config018.cfg \
+       config019.cfg \
+       config020.cfg \
+       config021.cfg \
+       config022.cfg \
+       config023.cfg \
+       config024.cfg \
+       state001.cfg \
+       state002.cfg \
+       state003.cfg \
+       state004.cfg \
+       state005.cfg \
+       state006.cfg \
+       state007.cfg \
+       state008.cfg \
+       state009.cfg \
+       state010.cfg \
+       state011.cfg \
+       state012.cfg \
+       state013.cfg \
+       state014.cfg \
+       state015.cfg \
+       state016.cfg \
+       state017.cfg \
+       state018.cfg \
+       state019.cfg \
+       state020.cfg \
+       state021.cfg \
+       state022.cfg \
+       state023.cfg \
+       state024.cfg
diff --git a/tests/zfs-tests/tests/functional/inheritance/README.config b/tests/zfs-tests/tests/functional/inheritance/README.config
new file mode 100644 (file)
index 0000000..6e04a3f
--- /dev/null
@@ -0,0 +1,67 @@
+#
+# CDDL HEADER START
+#
+# The contents of this file are subject to the terms of the
+# Common Development and Distribution License (the "License").
+# You may not use this file except in compliance with the License.
+#
+# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
+# or http://www.opensolaris.org/os/licensing.
+# See the License for the specific language governing permissions
+# and limitations under the License.
+#
+# When distributing Covered Code, include this CDDL HEADER in each
+# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
+# If applicable, add the following below this CDDL HEADER, with the
+# fields enclosed by brackets "[]" replaced with your own identifying
+# information: Portions Copyright [yyyy] [name of copyright owner]
+#
+# CDDL HEADER END
+#
+
+#
+# Copyright 2007 Sun Microsystems, Inc.  All rights reserved.
+# Use is subject to license terms.
+#
+# The configX.cfg files describe both the dataset hierarchy to
+# be created but also the initial source values for the datasets
+# properties, i.e. whether they should be left with their default values
+# or set locally.
+#
+# Format for this file is as follows:
+#      <dataset name>  <dataset type>  <inital property setting>
+#
+# <dataset name> - must be the full dataset name
+#
+# <dataset type> - recognised types are POOL, CTR and FS
+#
+#
+# <initial property setting> - can have one of the following
+# values:
+#
+#      default         property values are left unchanged
+#
+#      local           property values are set locally
+#
+#        -             property values are left unchanged (has the
+#                      same effect as 'default' but is used to indicate
+#                      that the property 'source' field may be 'inherited
+#                      from..' depending on the actions further up the
+#                      dataset hierarchy.
+#
+#
+# The configuration below creates a three tier dataset layout, consisting
+# of a pool, container and filesystem.
+#
+# The top tier pool's properties being set locally, and the two
+# lower tier properties each inheriting their values from the next tier
+# up.
+#
+
+#
+# Copyright (c) 2013 by Delphix. All rights reserved.
+#
+
+TESTPOOL                        POOL    local
+TESTPOOL/TESTCTR                CTR     -
+TESTPOOL/TESTCTR/TESTFS1        FS      -
diff --git a/tests/zfs-tests/tests/functional/inheritance/README.state b/tests/zfs-tests/tests/functional/inheritance/README.state
new file mode 100644 (file)
index 0000000..c1d3cc0
--- /dev/null
@@ -0,0 +1,109 @@
+#
+# CDDL HEADER START
+#
+# The contents of this file are subject to the terms of the
+# Common Development and Distribution License (the "License").
+# You may not use this file except in compliance with the License.
+#
+# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
+# or http://www.opensolaris.org/os/licensing.
+# See the License for the specific language governing permissions
+# and limitations under the License.
+#
+# When distributing Covered Code, include this CDDL HEADER in each
+# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
+# If applicable, add the following below this CDDL HEADER, with the
+# fields enclosed by brackets "[]" replaced with your own identifying
+# information: Portions Copyright [yyyy] [name of copyright owner]
+#
+# CDDL HEADER END
+#
+
+#
+# Copyright 2007 Sun Microsystems, Inc.  All rights reserved.
+# Use is subject to license terms.
+#
+#
+# For every configX.cfg file there must be a corresponding stateX.cfg
+# file. The state file both drives the operations to be performed on the
+# dataset hierarchy which has been specified by the corresponding
+# configX.cfg file, and also specifies the expected state of the
+# properties after the operation has been completed.
+#
+# The format of the file is:
+#       <target dataset>:<command>
+#       <property source before command>        <property src after command>
+#       <property source before command>        <property src after command>
+#       ....                                    ....
+#       ....                                    ....
+#
+# <target dataset> - dataset upon which the <command> is to be executed. Can
+#                    be any of the datasets specified in the corresponding
+#                    configX.cfg file. If no command is to be executed
+#                    then must be set to '-'
+#
+#
+# <command>        - command to be executed upon the specified dataset.
+#                    Currently the only supported commands are 'inherit'
+#                    or 'inherit -r'. If no command is to be executed,
+#                    then must be set to '-'.
+#
+# <property src before command>
+#                  - the 'source' (as reported in 'zfs get') for the
+#                    the properties before <command> is executed. This
+#                    can be 'default', 'local' or the name of a dataset
+#                    from which the property is inherited. (The code
+#                    automatically adds in the 'inherited from..' part
+#                    of the string when doing the check.
+#
+#                    This field is for informational purposes only, to
+#                    aid the user in seeing how the changes trickle down
+#                    the data hierarchy.
+#
+# <property src after command>
+#                  - the expected value of the 'source' field after the
+#                    <command> has been executed on the <target dataset>.
+#                    As above can be 'default', 'local', or the dataset
+#                    from which the property is inherited.
+#
+# Two important things to note:
+# 1) there must be a <property src..> line corresponding to each dataset
+#    line specified in the configX.cfg file.
+#
+#
+# 2) There can be as many <command>/<property src> blocks as desired, but
+#    there must be at least one, and the effect of each block is cumulative
+#    (i.e. the properties are not reset back to their default values between
+#    each block. If that is desired then each block must be placed in its
+#    own state file with its own corresponding configX.cfg file).
+#
+#
+# Below are two sample <command>/<property src> blocks.
+#
+# The first simply verifies that the properties on the top level dataset
+# were set locally, and that the middle and bottom datasets properties
+# were inherited from the top level pool (called TESTPOOL). Note the '-:-'
+# which means that no command is to be executed, but simply that the
+# properties settings are to be verified.
+#
+
+#
+# Copyright (c) 2013 by Delphix. All rights reserved.
+#
+
+-:-
+#
+local                           local
+TESTPOOL                        TESTPOOL
+TESTPOOL                        TESTPOOL
+#
+#
+# The block below describes the expected state of the properties after
+# an 'inherit -r' command has been run on the top level pool (called
+# TESTPOOL).
+#
+TESTPOOL:inherit -r
+#
+local                          default
+TESTPOOL                       default
+TESTPOOL                       default
diff --git a/tests/zfs-tests/tests/functional/inheritance/cleanup.ksh b/tests/zfs-tests/tests/functional/inheritance/cleanup.ksh
new file mode 100755 (executable)
index 0000000..3c631a2
--- /dev/null
@@ -0,0 +1,35 @@
+#!/bin/ksh -p
+#
+# CDDL HEADER START
+#
+# The contents of this file are subject to the terms of the
+# Common Development and Distribution License (the "License").
+# You may not use this file except in compliance with the License.
+#
+# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
+# or http://www.opensolaris.org/os/licensing.
+# See the License for the specific language governing permissions
+# and limitations under the License.
+#
+# When distributing Covered Code, include this CDDL HEADER in each
+# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
+# If applicable, add the following below this CDDL HEADER, with the
+# fields enclosed by brackets "[]" replaced with your own identifying
+# information: Portions Copyright [yyyy] [name of copyright owner]
+#
+# CDDL HEADER END
+#
+
+#
+# Copyright 2007 Sun Microsystems, Inc.  All rights reserved.
+# Use is subject to license terms.
+#
+
+#
+# Copyright (c) 2013 by Delphix. All rights reserved.
+#
+
+. ${STF_SUITE}/include/libtest.shlib
+
+$RM -rf $TESTDIR.*
+default_cleanup
diff --git a/tests/zfs-tests/tests/functional/inheritance/config001.cfg b/tests/zfs-tests/tests/functional/inheritance/config001.cfg
new file mode 100644 (file)
index 0000000..23616cb
--- /dev/null
@@ -0,0 +1,33 @@
+#
+# CDDL HEADER START
+#
+# The contents of this file are subject to the terms of the
+# Common Development and Distribution License (the "License").
+# You may not use this file except in compliance with the License.
+#
+# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
+# or http://www.opensolaris.org/os/licensing.
+# See the License for the specific language governing permissions
+# and limitations under the License.
+#
+# When distributing Covered Code, include this CDDL HEADER in each
+# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
+# If applicable, add the following below this CDDL HEADER, with the
+# fields enclosed by brackets "[]" replaced with your own identifying
+# information: Portions Copyright [yyyy] [name of copyright owner]
+#
+# CDDL HEADER END
+#
+
+#
+# Copyright 2007 Sun Microsystems, Inc.  All rights reserved.
+# Use is subject to license terms.
+#
+
+#
+# Copyright (c) 2013 by Delphix. All rights reserved.
+#
+
+TESTPOOL                        POOL    local
+TESTPOOL/TESTCTR                CTR     -
+TESTPOOL/TESTCTR/TESTFS1        FS      -
diff --git a/tests/zfs-tests/tests/functional/inheritance/config002.cfg b/tests/zfs-tests/tests/functional/inheritance/config002.cfg
new file mode 100644 (file)
index 0000000..3129411
--- /dev/null
@@ -0,0 +1,33 @@
+#
+# CDDL HEADER START
+#
+# The contents of this file are subject to the terms of the
+# Common Development and Distribution License (the "License").
+# You may not use this file except in compliance with the License.
+#
+# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
+# or http://www.opensolaris.org/os/licensing.
+# See the License for the specific language governing permissions
+# and limitations under the License.
+#
+# When distributing Covered Code, include this CDDL HEADER in each
+# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
+# If applicable, add the following below this CDDL HEADER, with the
+# fields enclosed by brackets "[]" replaced with your own identifying
+# information: Portions Copyright [yyyy] [name of copyright owner]
+#
+# CDDL HEADER END
+#
+
+#
+# Copyright 2007 Sun Microsystems, Inc.  All rights reserved.
+# Use is subject to license terms.
+#
+
+#
+# Copyright (c) 2013 by Delphix. All rights reserved.
+#
+
+TESTPOOL                        POOL    default
+TESTPOOL/TESTCTR                CTR     local
+TESTPOOL/TESTCTR/TESTFS1        FS      -
diff --git a/tests/zfs-tests/tests/functional/inheritance/config003.cfg b/tests/zfs-tests/tests/functional/inheritance/config003.cfg
new file mode 100644 (file)
index 0000000..57a73b9
--- /dev/null
@@ -0,0 +1,33 @@
+#
+# CDDL HEADER START
+#
+# The contents of this file are subject to the terms of the
+# Common Development and Distribution License (the "License").
+# You may not use this file except in compliance with the License.
+#
+# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
+# or http://www.opensolaris.org/os/licensing.
+# See the License for the specific language governing permissions
+# and limitations under the License.
+#
+# When distributing Covered Code, include this CDDL HEADER in each
+# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
+# If applicable, add the following below this CDDL HEADER, with the
+# fields enclosed by brackets "[]" replaced with your own identifying
+# information: Portions Copyright [yyyy] [name of copyright owner]
+#
+# CDDL HEADER END
+#
+
+#
+# Copyright 2007 Sun Microsystems, Inc.  All rights reserved.
+# Use is subject to license terms.
+#
+
+#
+# Copyright (c) 2013 by Delphix. All rights reserved.
+#
+
+TESTPOOL                        POOL    default
+TESTPOOL/TESTCTR                CTR     default
+TESTPOOL/TESTCTR/TESTFS1        FS      local
diff --git a/tests/zfs-tests/tests/functional/inheritance/config004.cfg b/tests/zfs-tests/tests/functional/inheritance/config004.cfg
new file mode 100644 (file)
index 0000000..1052526
--- /dev/null
@@ -0,0 +1,33 @@
+#
+# CDDL HEADER START
+#
+# The contents of this file are subject to the terms of the
+# Common Development and Distribution License (the "License").
+# You may not use this file except in compliance with the License.
+#
+# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
+# or http://www.opensolaris.org/os/licensing.
+# See the License for the specific language governing permissions
+# and limitations under the License.
+#
+# When distributing Covered Code, include this CDDL HEADER in each
+# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
+# If applicable, add the following below this CDDL HEADER, with the
+# fields enclosed by brackets "[]" replaced with your own identifying
+# information: Portions Copyright [yyyy] [name of copyright owner]
+#
+# CDDL HEADER END
+#
+
+#
+# Copyright 2007 Sun Microsystems, Inc.  All rights reserved.
+# Use is subject to license terms.
+#
+
+#
+# Copyright (c) 2013 by Delphix. All rights reserved.
+#
+
+TESTPOOL                        POOL    default
+TESTPOOL/TESTCTR                CTR     local
+TESTPOOL/TESTCTR/TESTFS1        FS      local
diff --git a/tests/zfs-tests/tests/functional/inheritance/config005.cfg b/tests/zfs-tests/tests/functional/inheritance/config005.cfg
new file mode 100644 (file)
index 0000000..d15beb2
--- /dev/null
@@ -0,0 +1,33 @@
+#
+# CDDL HEADER START
+#
+# The contents of this file are subject to the terms of the
+# Common Development and Distribution License (the "License").
+# You may not use this file except in compliance with the License.
+#
+# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
+# or http://www.opensolaris.org/os/licensing.
+# See the License for the specific language governing permissions
+# and limitations under the License.
+#
+# When distributing Covered Code, include this CDDL HEADER in each
+# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
+# If applicable, add the following below this CDDL HEADER, with the
+# fields enclosed by brackets "[]" replaced with your own identifying
+# information: Portions Copyright [yyyy] [name of copyright owner]
+#
+# CDDL HEADER END
+#
+
+#
+# Copyright 2007 Sun Microsystems, Inc.  All rights reserved.
+# Use is subject to license terms.
+#
+
+#
+# Copyright (c) 2013 by Delphix. All rights reserved.
+#
+
+TESTPOOL                        POOL    local
+TESTPOOL/TESTCTR                CTR     local
+TESTPOOL/TESTCTR/TESTFS1        FS      -
diff --git a/tests/zfs-tests/tests/functional/inheritance/config006.cfg b/tests/zfs-tests/tests/functional/inheritance/config006.cfg
new file mode 100644 (file)
index 0000000..a059d17
--- /dev/null
@@ -0,0 +1,33 @@
+#
+# CDDL HEADER START
+#
+# The contents of this file are subject to the terms of the
+# Common Development and Distribution License (the "License").
+# You may not use this file except in compliance with the License.
+#
+# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
+# or http://www.opensolaris.org/os/licensing.
+# See the License for the specific language governing permissions
+# and limitations under the License.
+#
+# When distributing Covered Code, include this CDDL HEADER in each
+# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
+# If applicable, add the following below this CDDL HEADER, with the
+# fields enclosed by brackets "[]" replaced with your own identifying
+# information: Portions Copyright [yyyy] [name of copyright owner]
+#
+# CDDL HEADER END
+#
+
+#
+# Copyright 2007 Sun Microsystems, Inc.  All rights reserved.
+# Use is subject to license terms.
+#
+
+#
+# Copyright (c) 2013 by Delphix. All rights reserved.
+#
+
+TESTPOOL                        POOL    local
+TESTPOOL/TESTCTR                CTR     -
+TESTPOOL/TESTCTR/TESTFS1        FS      local
diff --git a/tests/zfs-tests/tests/functional/inheritance/config007.cfg b/tests/zfs-tests/tests/functional/inheritance/config007.cfg
new file mode 100644 (file)
index 0000000..b416c9f
--- /dev/null
@@ -0,0 +1,33 @@
+#
+# CDDL HEADER START
+#
+# The contents of this file are subject to the terms of the
+# Common Development and Distribution License (the "License").
+# You may not use this file except in compliance with the License.
+#
+# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
+# or http://www.opensolaris.org/os/licensing.
+# See the License for the specific language governing permissions
+# and limitations under the License.
+#
+# When distributing Covered Code, include this CDDL HEADER in each
+# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
+# If applicable, add the following below this CDDL HEADER, with the
+# fields enclosed by brackets "[]" replaced with your own identifying
+# information: Portions Copyright [yyyy] [name of copyright owner]
+#
+# CDDL HEADER END
+#
+
+#
+# Copyright 2007 Sun Microsystems, Inc.  All rights reserved.
+# Use is subject to license terms.
+#
+
+#
+# Copyright (c) 2013 by Delphix. All rights reserved.
+#
+
+TESTPOOL                        POOL    local
+TESTPOOL/TESTCTR                CTR     local
+TESTPOOL/TESTCTR/TESTFS1        FS      local
diff --git a/tests/zfs-tests/tests/functional/inheritance/config008.cfg b/tests/zfs-tests/tests/functional/inheritance/config008.cfg
new file mode 100644 (file)
index 0000000..4f7e7b0
--- /dev/null
@@ -0,0 +1,33 @@
+#
+# CDDL HEADER START
+#
+# The contents of this file are subject to the terms of the
+# Common Development and Distribution License (the "License").
+# You may not use this file except in compliance with the License.
+#
+# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
+# or http://www.opensolaris.org/os/licensing.
+# See the License for the specific language governing permissions
+# and limitations under the License.
+#
+# When distributing Covered Code, include this CDDL HEADER in each
+# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
+# If applicable, add the following below this CDDL HEADER, with the
+# fields enclosed by brackets "[]" replaced with your own identifying
+# information: Portions Copyright [yyyy] [name of copyright owner]
+#
+# CDDL HEADER END
+#
+
+#
+# Copyright 2007 Sun Microsystems, Inc.  All rights reserved.
+# Use is subject to license terms.
+#
+
+#
+# Copyright (c) 2013 by Delphix. All rights reserved.
+#
+
+TESTPOOL                        POOL    default
+TESTPOOL/TESTCTR                CTR     default
+TESTPOOL/TESTCTR/TESTFS1        FS      default
diff --git a/tests/zfs-tests/tests/functional/inheritance/config009.cfg b/tests/zfs-tests/tests/functional/inheritance/config009.cfg
new file mode 100644 (file)
index 0000000..4f7e7b0
--- /dev/null
@@ -0,0 +1,33 @@
+#
+# CDDL HEADER START
+#
+# The contents of this file are subject to the terms of the
+# Common Development and Distribution License (the "License").
+# You may not use this file except in compliance with the License.
+#
+# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
+# or http://www.opensolaris.org/os/licensing.
+# See the License for the specific language governing permissions
+# and limitations under the License.
+#
+# When distributing Covered Code, include this CDDL HEADER in each
+# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
+# If applicable, add the following below this CDDL HEADER, with the
+# fields enclosed by brackets "[]" replaced with your own identifying
+# information: Portions Copyright [yyyy] [name of copyright owner]
+#
+# CDDL HEADER END
+#
+
+#
+# Copyright 2007 Sun Microsystems, Inc.  All rights reserved.
+# Use is subject to license terms.
+#
+
+#
+# Copyright (c) 2013 by Delphix. All rights reserved.
+#
+
+TESTPOOL                        POOL    default
+TESTPOOL/TESTCTR                CTR     default
+TESTPOOL/TESTCTR/TESTFS1        FS      default
diff --git a/tests/zfs-tests/tests/functional/inheritance/config010.cfg b/tests/zfs-tests/tests/functional/inheritance/config010.cfg
new file mode 100644 (file)
index 0000000..4f7e7b0
--- /dev/null
@@ -0,0 +1,33 @@
+#
+# CDDL HEADER START
+#
+# The contents of this file are subject to the terms of the
+# Common Development and Distribution License (the "License").
+# You may not use this file except in compliance with the License.
+#
+# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
+# or http://www.opensolaris.org/os/licensing.
+# See the License for the specific language governing permissions
+# and limitations under the License.
+#
+# When distributing Covered Code, include this CDDL HEADER in each
+# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
+# If applicable, add the following below this CDDL HEADER, with the
+# fields enclosed by brackets "[]" replaced with your own identifying
+# information: Portions Copyright [yyyy] [name of copyright owner]
+#
+# CDDL HEADER END
+#
+
+#
+# Copyright 2007 Sun Microsystems, Inc.  All rights reserved.
+# Use is subject to license terms.
+#
+
+#
+# Copyright (c) 2013 by Delphix. All rights reserved.
+#
+
+TESTPOOL                        POOL    default
+TESTPOOL/TESTCTR                CTR     default
+TESTPOOL/TESTCTR/TESTFS1        FS      default
diff --git a/tests/zfs-tests/tests/functional/inheritance/config011.cfg b/tests/zfs-tests/tests/functional/inheritance/config011.cfg
new file mode 100644 (file)
index 0000000..57a73b9
--- /dev/null
@@ -0,0 +1,33 @@
+#
+# CDDL HEADER START
+#
+# The contents of this file are subject to the terms of the
+# Common Development and Distribution License (the "License").
+# You may not use this file except in compliance with the License.
+#
+# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
+# or http://www.opensolaris.org/os/licensing.
+# See the License for the specific language governing permissions
+# and limitations under the License.
+#
+# When distributing Covered Code, include this CDDL HEADER in each
+# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
+# If applicable, add the following below this CDDL HEADER, with the
+# fields enclosed by brackets "[]" replaced with your own identifying
+# information: Portions Copyright [yyyy] [name of copyright owner]
+#
+# CDDL HEADER END
+#
+
+#
+# Copyright 2007 Sun Microsystems, Inc.  All rights reserved.
+# Use is subject to license terms.
+#
+
+#
+# Copyright (c) 2013 by Delphix. All rights reserved.
+#
+
+TESTPOOL                        POOL    default
+TESTPOOL/TESTCTR                CTR     default
+TESTPOOL/TESTCTR/TESTFS1        FS      local
diff --git a/tests/zfs-tests/tests/functional/inheritance/config012.cfg b/tests/zfs-tests/tests/functional/inheritance/config012.cfg
new file mode 100644 (file)
index 0000000..57a73b9
--- /dev/null
@@ -0,0 +1,33 @@
+#
+# CDDL HEADER START
+#
+# The contents of this file are subject to the terms of the
+# Common Development and Distribution License (the "License").
+# You may not use this file except in compliance with the License.
+#
+# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
+# or http://www.opensolaris.org/os/licensing.
+# See the License for the specific language governing permissions
+# and limitations under the License.
+#
+# When distributing Covered Code, include this CDDL HEADER in each
+# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
+# If applicable, add the following below this CDDL HEADER, with the
+# fields enclosed by brackets "[]" replaced with your own identifying
+# information: Portions Copyright [yyyy] [name of copyright owner]
+#
+# CDDL HEADER END
+#
+
+#
+# Copyright 2007 Sun Microsystems, Inc.  All rights reserved.
+# Use is subject to license terms.
+#
+
+#
+# Copyright (c) 2013 by Delphix. All rights reserved.
+#
+
+TESTPOOL                        POOL    default
+TESTPOOL/TESTCTR                CTR     default
+TESTPOOL/TESTCTR/TESTFS1        FS      local
diff --git a/tests/zfs-tests/tests/functional/inheritance/config013.cfg b/tests/zfs-tests/tests/functional/inheritance/config013.cfg
new file mode 100644 (file)
index 0000000..1052526
--- /dev/null
@@ -0,0 +1,33 @@
+#
+# CDDL HEADER START
+#
+# The contents of this file are subject to the terms of the
+# Common Development and Distribution License (the "License").
+# You may not use this file except in compliance with the License.
+#
+# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
+# or http://www.opensolaris.org/os/licensing.
+# See the License for the specific language governing permissions
+# and limitations under the License.
+#
+# When distributing Covered Code, include this CDDL HEADER in each
+# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
+# If applicable, add the following below this CDDL HEADER, with the
+# fields enclosed by brackets "[]" replaced with your own identifying
+# information: Portions Copyright [yyyy] [name of copyright owner]
+#
+# CDDL HEADER END
+#
+
+#
+# Copyright 2007 Sun Microsystems, Inc.  All rights reserved.
+# Use is subject to license terms.
+#
+
+#
+# Copyright (c) 2013 by Delphix. All rights reserved.
+#
+
+TESTPOOL                        POOL    default
+TESTPOOL/TESTCTR                CTR     local
+TESTPOOL/TESTCTR/TESTFS1        FS      local
diff --git a/tests/zfs-tests/tests/functional/inheritance/config014.cfg b/tests/zfs-tests/tests/functional/inheritance/config014.cfg
new file mode 100644 (file)
index 0000000..1052526
--- /dev/null
@@ -0,0 +1,33 @@
+#
+# CDDL HEADER START
+#
+# The contents of this file are subject to the terms of the
+# Common Development and Distribution License (the "License").
+# You may not use this file except in compliance with the License.
+#
+# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
+# or http://www.opensolaris.org/os/licensing.
+# See the License for the specific language governing permissions
+# and limitations under the License.
+#
+# When distributing Covered Code, include this CDDL HEADER in each
+# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
+# If applicable, add the following below this CDDL HEADER, with the
+# fields enclosed by brackets "[]" replaced with your own identifying
+# information: Portions Copyright [yyyy] [name of copyright owner]
+#
+# CDDL HEADER END
+#
+
+#
+# Copyright 2007 Sun Microsystems, Inc.  All rights reserved.
+# Use is subject to license terms.
+#
+
+#
+# Copyright (c) 2013 by Delphix. All rights reserved.
+#
+
+TESTPOOL                        POOL    default
+TESTPOOL/TESTCTR                CTR     local
+TESTPOOL/TESTCTR/TESTFS1        FS      local
diff --git a/tests/zfs-tests/tests/functional/inheritance/config015.cfg b/tests/zfs-tests/tests/functional/inheritance/config015.cfg
new file mode 100644 (file)
index 0000000..3129411
--- /dev/null
@@ -0,0 +1,33 @@
+#
+# CDDL HEADER START
+#
+# The contents of this file are subject to the terms of the
+# Common Development and Distribution License (the "License").
+# You may not use this file except in compliance with the License.
+#
+# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
+# or http://www.opensolaris.org/os/licensing.
+# See the License for the specific language governing permissions
+# and limitations under the License.
+#
+# When distributing Covered Code, include this CDDL HEADER in each
+# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
+# If applicable, add the following below this CDDL HEADER, with the
+# fields enclosed by brackets "[]" replaced with your own identifying
+# information: Portions Copyright [yyyy] [name of copyright owner]
+#
+# CDDL HEADER END
+#
+
+#
+# Copyright 2007 Sun Microsystems, Inc.  All rights reserved.
+# Use is subject to license terms.
+#
+
+#
+# Copyright (c) 2013 by Delphix. All rights reserved.
+#
+
+TESTPOOL                        POOL    default
+TESTPOOL/TESTCTR                CTR     local
+TESTPOOL/TESTCTR/TESTFS1        FS      -
diff --git a/tests/zfs-tests/tests/functional/inheritance/config016.cfg b/tests/zfs-tests/tests/functional/inheritance/config016.cfg
new file mode 100644 (file)
index 0000000..3129411
--- /dev/null
@@ -0,0 +1,33 @@
+#
+# CDDL HEADER START
+#
+# The contents of this file are subject to the terms of the
+# Common Development and Distribution License (the "License").
+# You may not use this file except in compliance with the License.
+#
+# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
+# or http://www.opensolaris.org/os/licensing.
+# See the License for the specific language governing permissions
+# and limitations under the License.
+#
+# When distributing Covered Code, include this CDDL HEADER in each
+# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
+# If applicable, add the following below this CDDL HEADER, with the
+# fields enclosed by brackets "[]" replaced with your own identifying
+# information: Portions Copyright [yyyy] [name of copyright owner]
+#
+# CDDL HEADER END
+#
+
+#
+# Copyright 2007 Sun Microsystems, Inc.  All rights reserved.
+# Use is subject to license terms.
+#
+
+#
+# Copyright (c) 2013 by Delphix. All rights reserved.
+#
+
+TESTPOOL                        POOL    default
+TESTPOOL/TESTCTR                CTR     local
+TESTPOOL/TESTCTR/TESTFS1        FS      -
diff --git a/tests/zfs-tests/tests/functional/inheritance/config017.cfg b/tests/zfs-tests/tests/functional/inheritance/config017.cfg
new file mode 100644 (file)
index 0000000..d15beb2
--- /dev/null
@@ -0,0 +1,33 @@
+#
+# CDDL HEADER START
+#
+# The contents of this file are subject to the terms of the
+# Common Development and Distribution License (the "License").
+# You may not use this file except in compliance with the License.
+#
+# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
+# or http://www.opensolaris.org/os/licensing.
+# See the License for the specific language governing permissions
+# and limitations under the License.
+#
+# When distributing Covered Code, include this CDDL HEADER in each
+# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
+# If applicable, add the following below this CDDL HEADER, with the
+# fields enclosed by brackets "[]" replaced with your own identifying
+# information: Portions Copyright [yyyy] [name of copyright owner]
+#
+# CDDL HEADER END
+#
+
+#
+# Copyright 2007 Sun Microsystems, Inc.  All rights reserved.
+# Use is subject to license terms.
+#
+
+#
+# Copyright (c) 2013 by Delphix. All rights reserved.
+#
+
+TESTPOOL                        POOL    local
+TESTPOOL/TESTCTR                CTR     local
+TESTPOOL/TESTCTR/TESTFS1        FS      -
diff --git a/tests/zfs-tests/tests/functional/inheritance/config018.cfg b/tests/zfs-tests/tests/functional/inheritance/config018.cfg
new file mode 100644 (file)
index 0000000..d15beb2
--- /dev/null
@@ -0,0 +1,33 @@
+#
+# CDDL HEADER START
+#
+# The contents of this file are subject to the terms of the
+# Common Development and Distribution License (the "License").
+# You may not use this file except in compliance with the License.
+#
+# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
+# or http://www.opensolaris.org/os/licensing.
+# See the License for the specific language governing permissions
+# and limitations under the License.
+#
+# When distributing Covered Code, include this CDDL HEADER in each
+# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
+# If applicable, add the following below this CDDL HEADER, with the
+# fields enclosed by brackets "[]" replaced with your own identifying
+# information: Portions Copyright [yyyy] [name of copyright owner]
+#
+# CDDL HEADER END
+#
+
+#
+# Copyright 2007 Sun Microsystems, Inc.  All rights reserved.
+# Use is subject to license terms.
+#
+
+#
+# Copyright (c) 2013 by Delphix. All rights reserved.
+#
+
+TESTPOOL                        POOL    local
+TESTPOOL/TESTCTR                CTR     local
+TESTPOOL/TESTCTR/TESTFS1        FS      -
diff --git a/tests/zfs-tests/tests/functional/inheritance/config019.cfg b/tests/zfs-tests/tests/functional/inheritance/config019.cfg
new file mode 100644 (file)
index 0000000..23616cb
--- /dev/null
@@ -0,0 +1,33 @@
+#
+# CDDL HEADER START
+#
+# The contents of this file are subject to the terms of the
+# Common Development and Distribution License (the "License").
+# You may not use this file except in compliance with the License.
+#
+# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
+# or http://www.opensolaris.org/os/licensing.
+# See the License for the specific language governing permissions
+# and limitations under the License.
+#
+# When distributing Covered Code, include this CDDL HEADER in each
+# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
+# If applicable, add the following below this CDDL HEADER, with the
+# fields enclosed by brackets "[]" replaced with your own identifying
+# information: Portions Copyright [yyyy] [name of copyright owner]
+#
+# CDDL HEADER END
+#
+
+#
+# Copyright 2007 Sun Microsystems, Inc.  All rights reserved.
+# Use is subject to license terms.
+#
+
+#
+# Copyright (c) 2013 by Delphix. All rights reserved.
+#
+
+TESTPOOL                        POOL    local
+TESTPOOL/TESTCTR                CTR     -
+TESTPOOL/TESTCTR/TESTFS1        FS      -
diff --git a/tests/zfs-tests/tests/functional/inheritance/config020.cfg b/tests/zfs-tests/tests/functional/inheritance/config020.cfg
new file mode 100644 (file)
index 0000000..23616cb
--- /dev/null
@@ -0,0 +1,33 @@
+#
+# CDDL HEADER START
+#
+# The contents of this file are subject to the terms of the
+# Common Development and Distribution License (the "License").
+# You may not use this file except in compliance with the License.
+#
+# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
+# or http://www.opensolaris.org/os/licensing.
+# See the License for the specific language governing permissions
+# and limitations under the License.
+#
+# When distributing Covered Code, include this CDDL HEADER in each
+# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
+# If applicable, add the following below this CDDL HEADER, with the
+# fields enclosed by brackets "[]" replaced with your own identifying
+# information: Portions Copyright [yyyy] [name of copyright owner]
+#
+# CDDL HEADER END
+#
+
+#
+# Copyright 2007 Sun Microsystems, Inc.  All rights reserved.
+# Use is subject to license terms.
+#
+
+#
+# Copyright (c) 2013 by Delphix. All rights reserved.
+#
+
+TESTPOOL                        POOL    local
+TESTPOOL/TESTCTR                CTR     -
+TESTPOOL/TESTCTR/TESTFS1        FS      -
diff --git a/tests/zfs-tests/tests/functional/inheritance/config021.cfg b/tests/zfs-tests/tests/functional/inheritance/config021.cfg
new file mode 100644 (file)
index 0000000..a059d17
--- /dev/null
@@ -0,0 +1,33 @@
+#
+# CDDL HEADER START
+#
+# The contents of this file are subject to the terms of the
+# Common Development and Distribution License (the "License").
+# You may not use this file except in compliance with the License.
+#
+# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
+# or http://www.opensolaris.org/os/licensing.
+# See the License for the specific language governing permissions
+# and limitations under the License.
+#
+# When distributing Covered Code, include this CDDL HEADER in each
+# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
+# If applicable, add the following below this CDDL HEADER, with the
+# fields enclosed by brackets "[]" replaced with your own identifying
+# information: Portions Copyright [yyyy] [name of copyright owner]
+#
+# CDDL HEADER END
+#
+
+#
+# Copyright 2007 Sun Microsystems, Inc.  All rights reserved.
+# Use is subject to license terms.
+#
+
+#
+# Copyright (c) 2013 by Delphix. All rights reserved.
+#
+
+TESTPOOL                        POOL    local
+TESTPOOL/TESTCTR                CTR     -
+TESTPOOL/TESTCTR/TESTFS1        FS      local
diff --git a/tests/zfs-tests/tests/functional/inheritance/config022.cfg b/tests/zfs-tests/tests/functional/inheritance/config022.cfg
new file mode 100644 (file)
index 0000000..a059d17
--- /dev/null
@@ -0,0 +1,33 @@
+#
+# CDDL HEADER START
+#
+# The contents of this file are subject to the terms of the
+# Common Development and Distribution License (the "License").
+# You may not use this file except in compliance with the License.
+#
+# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
+# or http://www.opensolaris.org/os/licensing.
+# See the License for the specific language governing permissions
+# and limitations under the License.
+#
+# When distributing Covered Code, include this CDDL HEADER in each
+# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
+# If applicable, add the following below this CDDL HEADER, with the
+# fields enclosed by brackets "[]" replaced with your own identifying
+# information: Portions Copyright [yyyy] [name of copyright owner]
+#
+# CDDL HEADER END
+#
+
+#
+# Copyright 2007 Sun Microsystems, Inc.  All rights reserved.
+# Use is subject to license terms.
+#
+
+#
+# Copyright (c) 2013 by Delphix. All rights reserved.
+#
+
+TESTPOOL                        POOL    local
+TESTPOOL/TESTCTR                CTR     -
+TESTPOOL/TESTCTR/TESTFS1        FS      local
diff --git a/tests/zfs-tests/tests/functional/inheritance/config023.cfg b/tests/zfs-tests/tests/functional/inheritance/config023.cfg
new file mode 100644 (file)
index 0000000..b416c9f
--- /dev/null
@@ -0,0 +1,33 @@
+#
+# CDDL HEADER START
+#
+# The contents of this file are subject to the terms of the
+# Common Development and Distribution License (the "License").
+# You may not use this file except in compliance with the License.
+#
+# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
+# or http://www.opensolaris.org/os/licensing.
+# See the License for the specific language governing permissions
+# and limitations under the License.
+#
+# When distributing Covered Code, include this CDDL HEADER in each
+# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
+# If applicable, add the following below this CDDL HEADER, with the
+# fields enclosed by brackets "[]" replaced with your own identifying
+# information: Portions Copyright [yyyy] [name of copyright owner]
+#
+# CDDL HEADER END
+#
+
+#
+# Copyright 2007 Sun Microsystems, Inc.  All rights reserved.
+# Use is subject to license terms.
+#
+
+#
+# Copyright (c) 2013 by Delphix. All rights reserved.
+#
+
+TESTPOOL                        POOL    local
+TESTPOOL/TESTCTR                CTR     local
+TESTPOOL/TESTCTR/TESTFS1        FS      local
diff --git a/tests/zfs-tests/tests/functional/inheritance/config024.cfg b/tests/zfs-tests/tests/functional/inheritance/config024.cfg
new file mode 100644 (file)
index 0000000..b416c9f
--- /dev/null
@@ -0,0 +1,33 @@
+#
+# CDDL HEADER START
+#
+# The contents of this file are subject to the terms of the
+# Common Development and Distribution License (the "License").
+# You may not use this file except in compliance with the License.
+#
+# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
+# or http://www.opensolaris.org/os/licensing.
+# See the License for the specific language governing permissions
+# and limitations under the License.
+#
+# When distributing Covered Code, include this CDDL HEADER in each
+# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
+# If applicable, add the following below this CDDL HEADER, with the
+# fields enclosed by brackets "[]" replaced with your own identifying
+# information: Portions Copyright [yyyy] [name of copyright owner]
+#
+# CDDL HEADER END
+#
+
+#
+# Copyright 2007 Sun Microsystems, Inc.  All rights reserved.
+# Use is subject to license terms.
+#
+
+#
+# Copyright (c) 2013 by Delphix. All rights reserved.
+#
+
+TESTPOOL                        POOL    local
+TESTPOOL/TESTCTR                CTR     local
+TESTPOOL/TESTCTR/TESTFS1        FS      local
diff --git a/tests/zfs-tests/tests/functional/inheritance/inherit.kshlib b/tests/zfs-tests/tests/functional/inheritance/inherit.kshlib
new file mode 100644 (file)
index 0000000..cee0cfd
--- /dev/null
@@ -0,0 +1,114 @@
+#
+# CDDL HEADER START
+#
+# The contents of this file are subject to the terms of the
+# Common Development and Distribution License (the "License").
+# You may not use this file except in compliance with the License.
+#
+# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
+# or http://www.opensolaris.org/os/licensing.
+# See the License for the specific language governing permissions
+# and limitations under the License.
+#
+# When distributing Covered Code, include this CDDL HEADER in each
+# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
+# If applicable, add the following below this CDDL HEADER, with the
+# fields enclosed by brackets "[]" replaced with your own identifying
+# information: Portions Copyright [yyyy] [name of copyright owner]
+#
+# CDDL HEADER END
+#
+
+#
+# Copyright 2009 Sun Microsystems, Inc.  All rights reserved.
+# Use is subject to license terms.
+#
+
+#
+# Copyright (c) 2013 by Delphix. All rights reserved.
+#
+
+#
+# Simple function to get the source of the specified property.
+# If unable to get the property then exits.
+#
+function get_prop_src # property dataset
+{
+        typeset prop_val
+        typeset prop=$1
+        typeset dataset=$2
+
+       prop_val=`$ZFS get -H -o source $prop $dataset`
+
+        if [[ $? -ne 0 ]]; then
+                log_fail "Unable to determine the source of $prop " \
+                        "property for dataset $dataset"
+        else
+                echo $prop_val
+        fi
+}
+
+#
+# Function to check the 'source' of a property. The source can
+# either be "default", "local", or "inherited from <parent dataset>".
+#
+# The 'expected src' argument must be either "default", "local", or
+# a dataset name.
+#
+# Returns 0 on success, 1 on failure.
+#
+function verify_prop_src # child_dataset property expected_src
+{
+        typeset target=$1
+        typeset prop=$2
+        typeset expected=$3
+
+        prop_src=`get_prop_src $prop $target`
+
+       #
+       # Rather than just checking if $prop_src == $expected
+       # we first determine what value $expected should have.
+       # This allows us to catch the case where a property
+       # has a source of "local" but we expected it to be
+       # "default"
+       #
+       if [[ $expected == "default" ]]; then
+               if [[ $prop_src != $expected ]]; then
+                       log_note "Property $prop of $target has source"\
+                               " $prop_src rather than $expected"
+                       return 1
+               fi
+       elif [[ $expected == "local" ]]; then
+               if [[ $prop_src != $expected ]]; then
+                       log_note "Property $prop of $target has source"\
+                               " $prop_src rather than $expected"
+                       return 1
+               fi
+       elif [[ $prop_src != "inherited from $expected" ]]; then
+               log_note "Property $prop of $expected has source $prop_src"\
+                       " rather than 'inherited from $expected'"
+                return 1
+       fi
+
+       return 0
+}
+
+#
+# Simple function to set a property to a
+# specified value and verify it has changed
+# correctly.
+#
+function set_n_verify_prop #property value dataset
+{
+       typeset prop=$1
+       typeset prop_val=$2
+       typeset dataset=$3
+
+       $ZFS set $prop=$prop_val $dataset
+       check_val=`get_prop $prop $dataset`
+
+       if [[ $check_val != $prop_val ]]; then
+               log_fail "Property $prop of $dataset has value $check_val"\
+                       " rather than $prop_val"
+       fi
+}
diff --git a/tests/zfs-tests/tests/functional/inheritance/inherit_001_pos.ksh b/tests/zfs-tests/tests/functional/inheritance/inherit_001_pos.ksh
new file mode 100755 (executable)
index 0000000..6677d11
--- /dev/null
@@ -0,0 +1,456 @@
+#! /bin/ksh -p
+#
+# CDDL HEADER START
+#
+# The contents of this file are subject to the terms of the
+# Common Development and Distribution License (the "License").
+# You may not use this file except in compliance with the License.
+#
+# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
+# or http://www.opensolaris.org/os/licensing.
+# See the License for the specific language governing permissions
+# and limitations under the License.
+#
+# When distributing Covered Code, include this CDDL HEADER in each
+# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
+# If applicable, add the following below this CDDL HEADER, with the
+# fields enclosed by brackets "[]" replaced with your own identifying
+# information: Portions Copyright [yyyy] [name of copyright owner]
+#
+# CDDL HEADER END
+#
+
+#
+# Copyright 2009 Sun Microsystems, Inc.  All rights reserved.
+# Use is subject to license terms.
+
+#
+# Copyright (c) 2013 by Delphix. All rights reserved.
+#
+
+. $STF_SUITE/include/libtest.shlib
+. $STF_SUITE/tests/functional/inheritance/inherit.kshlib
+
+#
+# DESCRIPTION:
+# Test that properties are correctly inherited using 'zfs set',
+# 'zfs inherit' and 'zfs inherit -r'.
+#
+# STRATEGY:
+# 1) Read a configX.cfg file and create the specified datasets
+# 2) Read a stateX.cfg file and execute the commands within it
+# and verify that the properties have the correct values
+# 3) Repeat steps 1-2 for each configX and stateX files found.
+#
+
+verify_runnable "global"
+
+log_assert "Test properties are inherited correctly"
+
+#
+# Simple function to create specified datasets.
+#
+function create_dataset { #name type disks
+       typeset dataset=$1
+       typeset type=$2
+       typeset disks=$3
+
+       if [[ $type == "POOL" ]]; then
+               create_pool "$dataset" "$disks"
+       elif [[ $type == "CTR" ]]; then
+               log_must $ZFS create $dataset
+               log_must $ZFS set canmount=off $dataset
+       elif [[ $type == "FS" ]]; then
+               log_must $ZFS create $dataset
+       else
+               log_fail "Unrecognised type $type"
+       fi
+
+       list="$list $dataset"
+}
+
+#
+# Function to walk through all the properties in a
+# dataset, setting them to a 'local' value if required.
+#
+function init_props { #dataset init_code
+       typeset dataset=$1
+       typeset init_code=$2
+       typeset dir=$3
+
+       typeset -i i=0
+
+       #
+       # Though the effect of '-' and 'default' is the same we
+       # call them out via a log_note to aid in debugging the
+       # config files
+       #
+       if [[ $init_code == "-" ]]; then
+               log_note "Leaving properties for $dataset unchanged."
+               [[ $def_recordsize == 0 ]] && \
+                   update_recordsize $dataset $init_code
+               return;
+       elif [[ $init_code == "default" ]]; then
+               log_note "Leaving properties for $dataset at default values."
+               [[ $def_recordsize == 0 ]] && \
+                   update_recordsize $dataset $init_code
+               return;
+       elif [[ $init_code == "local" ]]; then
+               log_note "Setting properties for $dataset to local values."
+               while (( i <  ${#prop[*]} )); do
+                       if [[ ${prop[i]} == "recordsize" ]]; then
+                               update_recordsize $dataset $init_code
+                       else
+                               if [[ ${prop[i]} == "mountpoint" ]]; then
+                                       set_n_verify_prop ${prop[i]} \
+                                           ${local_val[((i/2))]}.$dir $dataset
+                               else
+                                       set_n_verify_prop ${prop[i]} \
+                                           ${local_val[((i/2))]} $dataset
+                               fi
+                       fi
+
+                       ((i = i + 2))
+               done
+       else
+               log_fail "Unrecognised init code $init_code"
+       fi
+}
+
+#
+# We enter this function either to update the recordsize value
+# in the default array, or to update the local value array.
+#
+function update_recordsize { #dataset init_code
+       typeset dataset=$1
+       typeset init_code=$2
+       typeset idx=0
+       typeset record_val
+
+       #
+       # First need to find where the recordsize property is
+       # located in the arrays
+       #
+       while (( idx <  ${#prop[*]} )); do
+               [[ ${prop[idx]} == "recordsize" ]] && break
+
+               ((idx = idx + 2))
+       done
+
+       ((idx = idx / 2))
+       record_val=`get_prop recordsize $dataset`
+       if [[ $init_code == "-" || $init_code == "default" ]]; then
+               def_val[idx]=$record_val
+               def_recordsize=1
+       elif [[ $init_code == "local" ]]; then
+               log_must $ZFS set recordsize=$record_val $dataset
+               local_val[idx]=$record_val
+       fi
+}
+
+#
+# The mountpoint property is slightly different from other properties and
+# so is handled here. For all other properties if they are set to a specific
+# value at a higher level in the data hierarchy (i.e. checksum=on) then that
+# value propogates down the hierarchy unchanged, with the source field being
+# set to 'inherited from <higher dataset>'.
+#
+# The mountpoint property is different in that while the value propogates
+# down the hierarchy, the value at each level is determined by a combination
+# of the top-level value and the current level in the hierarchy.
+#
+# For example consider the case where we have a pool (called pool1), containing
+# a dataset (ctr) which in turn contains a filesystem (fs). If we set the
+# mountpoint of the pool to '/mnt2' then the mountpoints for the dataset and
+# filesystem are '/mnt2/ctr' and /mnt2/ctr/fs' respectively, with the 'source'
+# field being set to 'inherited from pool1'.
+#
+# So at the filesystem level to calculate what our mountpoint property should
+# be set to we walk back up the hierarchy sampling the mountpoint property at
+# each level and forming up the expected mountpoint value piece by piece until
+# we reach the level specified in the 'source' field, which in this example is
+# the top-level pool.
+#
+function get_mntpt_val #dataset src index
+{
+       typeset dataset=$1
+       typeset src=$2
+       typeset idx=$3
+       typeset new_path=""
+       typeset dset
+       typeset mntpt=""
+
+       if [[ $src == "local" ]]; then
+               # Extract mount points specific to datasets
+               if [[ $dataset == "TESTPOOL" ]]; then
+                       mntpt=${local_val[idx]}.1
+               elif [[ $dataset == "TESTPOOL/TESTCTR" ]]; then
+                       mntpt=${local_val[idx]}.2
+               else
+                       mntpt=${local_val[idx]}.3
+               fi
+       elif [[ $src == "default" ]]; then
+               mntpt="/$dataset"
+       else
+               # Walk back up the hierarchy building up the
+               # expected mountpoint property value.
+               obj_name=${dataset##*/}
+
+               while [[ $src != $dataset ]]; do
+                       dset=${dataset%/*}
+
+                       mnt_val=`get_prop mountpoint $dset`
+
+                       mod_prop_val=${mnt_val##*/}
+                       new_path="/"$mod_prop_val$new_path
+                       dataset=$dset
+               done
+
+               mntpt=$new_path"/"$obj_name
+       fi
+       echo $mntpt
+}
+
+#
+# Simple function to verify that a property has the
+# expected value.
+#
+function verify_prop_val #property dataset src index
+{
+       typeset prop=$1
+       typeset dataset=$2
+       typeset src=$3
+       typeset idx=$4
+       typeset new_path=""
+       typeset dset
+       typeset exp_val
+       typeset prop_val
+
+       prop_val=`get_prop $prop $dataset`
+
+       # mountpoint property is handled as a special case
+       if [[ $prop == "mountpoint" ]]; then
+               exp_val=`get_mntpt_val $dataset $src $idx`
+       else
+               if [[ $src == "local" ]]; then
+                       exp_val=${local_val[idx]}
+               elif [[ $src == "default" ]]; then
+                       exp_val=${def_val[idx]}
+               else
+                       #
+                       # We are inheriting the value from somewhere
+                       # up the hierarchy.
+                       #
+                       exp_val=`get_prop $prop $src`
+               fi
+       fi
+
+       if [[ $prop_val != $exp_val ]]; then
+               # After putback PSARC/2008/231 Apr,09,2008,
+               # the default value of aclinherit has changed to be
+               # 'restricted' instead of 'secure',
+               # but the old interface of 'secure' still exist
+
+               if [[ $prop != "aclinherit" || \
+                   $exp_val != "secure" || \
+                   $prop_val != "restricted" ]]; then
+
+                       log_fail "$prop of $dataset is [$prop_val] rather "\
+                           "than [$exp_val]"
+               fi
+       fi
+}
+
+#
+# Function to read the configX.cfg files and create the specified
+# dataset hierarchy
+#
+function scan_config { #config-file
+       typeset config_file=$1
+
+       DISK=${DISKS%% *}
+
+       list=""
+       typeset -i mount_dir=1
+
+       grep "^[^#]" $config_file | {
+               while read name type init ; do
+                       create_dataset $name $type $DISK
+                       init_props $name $init $mount_dir
+                       ((mount_dir = mount_dir + 1))
+               done
+       }
+}
+
+#
+# Function to check an exit flag, calling log_fail if that exit flag
+# is non-zero. Can be used from code that runs in a tight loop, which
+# would otherwise result in a lot of journal output.
+#
+function check_failure { # int status, error message to use
+
+       typeset -i exit_flag=$1
+       error_message=$2
+
+       if [[ $exit_flag -ne 0 ]]; then
+               log_fail "$error_message"
+       fi
+}
+
+
+#
+# Main function. Executes the commands specified in the stateX.cfg
+# files and then verifies that all the properties have the correct
+# values and 'source' fields.
+#
+function scan_state { #state-file
+       typeset state_file=$1
+       typeset -i i=0
+       typeset -i j=0
+
+       log_note "Reading state from $state_file"
+
+       while ((i <  ${#prop[*]})); do
+               grep "^[^#]" $state_file | {
+                       while IFS=: read target op; do
+                               #
+                               # The user can if they wish specify that no
+                               # operation be performed (by specifying '-'
+                               # rather than a command). This is not as
+                               # useless as it sounds as it allows us to
+                               # verify that the dataset hierarchy has been
+                               # set up correctly as specified in the
+                               # configX.cfg file (which includes 'set'ting
+                               # properties at a higher level and checking
+                               # that they propogate down to the lower levels.
+                               #
+                               # Note in a few places here, we use
+                               # check_failure, rather than log_must - this
+                               # substantially reduces journal output.
+                               #
+                               if [[ $op == "-" ]]; then
+                                       log_note "No operation specified"
+                               else
+                                       export __ZFS_POOL_RESTRICT="$TESTPOOL"
+                                       log_must $ZFS unmount -a
+                                       unset __ZFS_POOL_RESTRICT
+
+                                       for p in ${prop[i]} ${prop[((i+1))]}; do
+                                               $ZFS $op $p $target
+                                               ret=$?
+                                               check_failure $ret "$ZFS $op $p \
+                                                   $target"
+                                       done
+                               fi
+                               for check_obj in $list; do
+                                       read init_src final_src
+
+                                       for p in ${prop[i]} ${prop[((i+1))]}; do
+                                       # check_failure to keep journal small
+                                               verify_prop_src $check_obj $p \
+                                                   $final_src
+                                               ret=$?
+                                               check_failure $ret "verify" \
+                                                   "_prop_src $check_obj $p" \
+                                                   "$final_src"
+
+                                       # Again, to keep journal size down.
+                                               verify_prop_val $p $check_obj \
+                                                   $final_src $j
+                                               ret=$?
+                                               check_failure $ret "verify" \
+                                                   "_prop_val $check_obj $p" \
+                                                   "$final_src"
+                                       done
+                               done
+                       done
+               }
+               ((i = i + 2))
+               ((j = j + 1))
+       done
+}
+
+#
+# Note except for the mountpoint default value (which is handled in
+# the routine itself), each property specified in the 'prop' array
+# above must have a corresponding entry in the two arrays below.
+#
+if is_linux; then
+       set -A prop "checksum" "" \
+               "compression" "compress" \
+               "atime" "" \
+               "devices" "" \
+               "exec" "" \
+               "setuid" "" \
+               "recordsize" "recsize" \
+               "snapdir" "" \
+               "acltype"
+
+       set -A def_val "on" "off" "on" "on" "on" \
+               "on" "" \
+               "hidden" "off"
+
+       set -A local_val "off" "on" "off" "off" "off" \
+               "off" "" \
+               "visible" "off"
+else
+       set -A prop "checksum" "" \
+               "compression" "compress" \
+               "atime" "" \
+               "devices" "" \
+               "exec" "" \
+               "setuid" "" \
+               "sharenfs", "" \
+               "recordsize" "recsize" \
+               "mountpoint" "" \
+               "snapdir" "" \
+               "aclmode", "" \
+               "aclinherit" "" \
+               "readonly" "rdonly"
+
+       set -A def_val "on" "off" "on" "on" "on" \
+               "on" "off" "" \
+               "" "hidden" "discard" "secure" \
+               "off"
+
+       set -A local_val "off" "on" "off" "off" "off" \
+               "off" "on" "" \
+               "$TESTDIR" "visible" "groupmask" "discard" \
+               "off"
+fi
+
+
+#
+# Global flag indicating whether the default record size had been
+# read.
+#
+typeset def_recordsize=0
+
+set -A config_files $(ls $STF_SUITE/tests/functional/inheritance/config*[1-9]*.cfg)
+set -A state_files $(ls $STF_SUITE/tests/functional/inheritance/state*.cfg)
+
+#
+# Global list of datasets created.
+#
+list=""
+
+typeset -i k=0
+
+if [[ ${#config_files[*]} != ${#state_files[*]} ]]; then
+       log_fail "Must have the same number of config files " \
+           " (${#config_files[*]}) and state files ${#state_files[*]}"
+fi
+
+while ((k < ${#config_files[*]})); do
+       default_cleanup_noexit
+       def_recordsize=0
+
+       log_note "Testing configuration ${config_files[k]}"
+
+       scan_config ${config_files[k]}
+       scan_state ${state_files[k]}
+
+       ((k = k + 1))
+done
+
+log_pass "Properties correctly inherited as expected"
diff --git a/tests/zfs-tests/tests/functional/inheritance/state001.cfg b/tests/zfs-tests/tests/functional/inheritance/state001.cfg
new file mode 100644 (file)
index 0000000..68e4379
--- /dev/null
@@ -0,0 +1,44 @@
+#
+# CDDL HEADER START
+#
+# The contents of this file are subject to the terms of the
+# Common Development and Distribution License (the "License").
+# You may not use this file except in compliance with the License.
+#
+# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
+# or http://www.opensolaris.org/os/licensing.
+# See the License for the specific language governing permissions
+# and limitations under the License.
+#
+# When distributing Covered Code, include this CDDL HEADER in each
+# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
+# If applicable, add the following below this CDDL HEADER, with the
+# fields enclosed by brackets "[]" replaced with your own identifying
+# information: Portions Copyright [yyyy] [name of copyright owner]
+#
+# CDDL HEADER END
+#
+
+#
+# Copyright 2007 Sun Microsystems, Inc.  All rights reserved.
+# Use is subject to license terms.
+#
+
+#
+# Copyright (c) 2013 by Delphix. All rights reserved.
+#
+
+# *** ASSERTION DESCRIPTION ***
+#
+# No command is actually run (hence '-:-') but rather this state file is
+# used to verify that the property that was set on the top level pool
+# via the 'local' keyword (in the config1.cfg file) has correctly
+# propogated down the hierarchy.
+#
+# *** ASSERTION DESCRIPTION ***
+#
+-:-
+#
+local                           local
+TESTPOOL                        TESTPOOL
+TESTPOOL                        TESTPOOL
diff --git a/tests/zfs-tests/tests/functional/inheritance/state002.cfg b/tests/zfs-tests/tests/functional/inheritance/state002.cfg
new file mode 100644 (file)
index 0000000..c3b9b15
--- /dev/null
@@ -0,0 +1,45 @@
+#
+# CDDL HEADER START
+#
+# The contents of this file are subject to the terms of the
+# Common Development and Distribution License (the "License").
+# You may not use this file except in compliance with the License.
+#
+# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
+# or http://www.opensolaris.org/os/licensing.
+# See the License for the specific language governing permissions
+# and limitations under the License.
+#
+# When distributing Covered Code, include this CDDL HEADER in each
+# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
+# If applicable, add the following below this CDDL HEADER, with the
+# fields enclosed by brackets "[]" replaced with your own identifying
+# information: Portions Copyright [yyyy] [name of copyright owner]
+#
+# CDDL HEADER END
+#
+
+#
+# Copyright 2007 Sun Microsystems, Inc.  All rights reserved.
+# Use is subject to license terms.
+#
+
+#
+# Copyright (c) 2013 by Delphix. All rights reserved.
+#
+
+# *** ASSERTION DESCRIPTION ***
+#
+# No command is actually run (hence '-:-') but rather this state file is
+# used to verify that the property that was set on the middle level
+# dataset via the 'local' keyword (in the configX.cfg file) has
+# correctly propogated down the hierarchy to the filesystem underneath,
+# while leaving the top level pools properties unchanged.
+#
+# *** ASSERTION DESCRIPTION ***
+#
+-:-
+#
+default                                default
+local                           local
+TESTPOOL/TESTCTR               TESTPOOL/TESTCTR
diff --git a/tests/zfs-tests/tests/functional/inheritance/state003.cfg b/tests/zfs-tests/tests/functional/inheritance/state003.cfg
new file mode 100644 (file)
index 0000000..5780065
--- /dev/null
@@ -0,0 +1,43 @@
+#
+# CDDL HEADER START
+#
+# The contents of this file are subject to the terms of the
+# Common Development and Distribution License (the "License").
+# You may not use this file except in compliance with the License.
+#
+# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
+# or http://www.opensolaris.org/os/licensing.
+# See the License for the specific language governing permissions
+# and limitations under the License.
+#
+# When distributing Covered Code, include this CDDL HEADER in each
+# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
+# If applicable, add the following below this CDDL HEADER, with the
+# fields enclosed by brackets "[]" replaced with your own identifying
+# information: Portions Copyright [yyyy] [name of copyright owner]
+#
+# CDDL HEADER END
+#
+
+#
+# Copyright 2007 Sun Microsystems, Inc.  All rights reserved.
+# Use is subject to license terms.
+#
+
+#
+# Copyright (c) 2013 by Delphix. All rights reserved.
+#
+
+# *** ASSERTION DESCRIPTION ***
+#
+# No command is actually run (hence '-:-') but rather this state file is
+# used to verify that setting the filesystem's properties does not affect
+# the properties of datasets above it in the hierarchy.
+#
+# *** ASSERTION DESCRIPTION ***
+#
+-:-
+#
+default                                default
+default                                default
+local                           local
diff --git a/tests/zfs-tests/tests/functional/inheritance/state004.cfg b/tests/zfs-tests/tests/functional/inheritance/state004.cfg
new file mode 100644 (file)
index 0000000..e62979a
--- /dev/null
@@ -0,0 +1,44 @@
+#
+# CDDL HEADER START
+#
+# The contents of this file are subject to the terms of the
+# Common Development and Distribution License (the "License").
+# You may not use this file except in compliance with the License.
+#
+# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
+# or http://www.opensolaris.org/os/licensing.
+# See the License for the specific language governing permissions
+# and limitations under the License.
+#
+# When distributing Covered Code, include this CDDL HEADER in each
+# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
+# If applicable, add the following below this CDDL HEADER, with the
+# fields enclosed by brackets "[]" replaced with your own identifying
+# information: Portions Copyright [yyyy] [name of copyright owner]
+#
+# CDDL HEADER END
+#
+
+#
+# Copyright 2007 Sun Microsystems, Inc.  All rights reserved.
+# Use is subject to license terms.
+#
+
+#
+# Copyright (c) 2013 by Delphix. All rights reserved.
+#
+
+# *** ASSERTION DESCRIPTION ***
+#
+# No command is actually run (hence '-:-') but rather this state file is
+# used to verify that setting a property on a middle level dataset does
+# not prevent us from setting a property on the bottom level filesystem,
+# and that neither affects the top level pools properties.
+#
+# *** ASSERTION DESCRIPTION ***
+#
+-:-
+#
+default                                default
+local                           local
+local                           local
diff --git a/tests/zfs-tests/tests/functional/inheritance/state005.cfg b/tests/zfs-tests/tests/functional/inheritance/state005.cfg
new file mode 100644 (file)
index 0000000..097459f
--- /dev/null
@@ -0,0 +1,45 @@
+#
+# CDDL HEADER START
+#
+# The contents of this file are subject to the terms of the
+# Common Development and Distribution License (the "License").
+# You may not use this file except in compliance with the License.
+#
+# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
+# or http://www.opensolaris.org/os/licensing.
+# See the License for the specific language governing permissions
+# and limitations under the License.
+#
+# When distributing Covered Code, include this CDDL HEADER in each
+# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
+# If applicable, add the following below this CDDL HEADER, with the
+# fields enclosed by brackets "[]" replaced with your own identifying
+# information: Portions Copyright [yyyy] [name of copyright owner]
+#
+# CDDL HEADER END
+#
+
+#
+# Copyright 2007 Sun Microsystems, Inc.  All rights reserved.
+# Use is subject to license terms.
+#
+
+#
+# Copyright (c) 2013 by Delphix. All rights reserved.
+#
+
+# *** ASSERTION DESCRIPTION ***
+#
+# No command is actually run (hence '-:-') but rather this state file is
+# used to verify that when we set a property on a top level pool, followed
+# by a middle level dataset, that the bottom level filesystem inherits
+# the property from the middle level dataset, and not from the top level
+# pool.
+#
+# *** ASSERTION DESCRIPTION ***
+#
+-:-
+#
+local                           local
+local                           local
+TESTPOOL/TESTCTR               TESTPOOL/TESTCTR
diff --git a/tests/zfs-tests/tests/functional/inheritance/state006.cfg b/tests/zfs-tests/tests/functional/inheritance/state006.cfg
new file mode 100644 (file)
index 0000000..9863b29
--- /dev/null
@@ -0,0 +1,47 @@
+#
+# CDDL HEADER START
+#
+# The contents of this file are subject to the terms of the
+# Common Development and Distribution License (the "License").
+# You may not use this file except in compliance with the License.
+#
+# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
+# or http://www.opensolaris.org/os/licensing.
+# See the License for the specific language governing permissions
+# and limitations under the License.
+#
+# When distributing Covered Code, include this CDDL HEADER in each
+# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
+# If applicable, add the following below this CDDL HEADER, with the
+# fields enclosed by brackets "[]" replaced with your own identifying
+# information: Portions Copyright [yyyy] [name of copyright owner]
+#
+# CDDL HEADER END
+#
+
+#
+# Copyright 2007 Sun Microsystems, Inc.  All rights reserved.
+# Use is subject to license terms.
+#
+
+#
+# Copyright (c) 2013 by Delphix. All rights reserved.
+#
+
+# *** ASSERTION DESCRIPTION ***
+#
+# No command is actually run (hence '-:-') but rather this state file is
+# used to verify that when we set a property on a top level pool, followed
+# by a bottom level filesystem, that the middle level dataset inherits
+# the property from the top level pool, and not from the bottom level
+# filesystem.
+#
+# *** ASSERTION DESCRIPTION ***
+#
+-:-
+#
+# <prop src before cmd>                <prop src after cmd>
+#
+local                           local
+TESTPOOL                       TESTPOOL
+local                           local
diff --git a/tests/zfs-tests/tests/functional/inheritance/state007.cfg b/tests/zfs-tests/tests/functional/inheritance/state007.cfg
new file mode 100644 (file)
index 0000000..731ec95
--- /dev/null
@@ -0,0 +1,45 @@
+#
+# CDDL HEADER START
+#
+# The contents of this file are subject to the terms of the
+# Common Development and Distribution License (the "License").
+# You may not use this file except in compliance with the License.
+#
+# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
+# or http://www.opensolaris.org/os/licensing.
+# See the License for the specific language governing permissions
+# and limitations under the License.
+#
+# When distributing Covered Code, include this CDDL HEADER in each
+# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
+# If applicable, add the following below this CDDL HEADER, with the
+# fields enclosed by brackets "[]" replaced with your own identifying
+# information: Portions Copyright [yyyy] [name of copyright owner]
+#
+# CDDL HEADER END
+#
+
+#
+# Copyright 2007 Sun Microsystems, Inc.  All rights reserved.
+# Use is subject to license terms.
+#
+
+#
+# Copyright (c) 2013 by Delphix. All rights reserved.
+#
+
+# *** ASSERTION DESCRIPTION ***
+#
+# No command is actually run (hence '-:-') but rather this state file is
+# used to verify that when we can set properties on each level of the
+# hierarchy independently.
+#
+# *** ASSERTION DESCRIPTION ***
+#
+-:-
+#
+# <prop src before cmd>         <prop src after cmd>
+#
+local                           local
+local                           local
+local                           local
diff --git a/tests/zfs-tests/tests/functional/inheritance/state008.cfg b/tests/zfs-tests/tests/functional/inheritance/state008.cfg
new file mode 100644 (file)
index 0000000..7385c98
--- /dev/null
@@ -0,0 +1,44 @@
+#
+# CDDL HEADER START
+#
+# The contents of this file are subject to the terms of the
+# Common Development and Distribution License (the "License").
+# You may not use this file except in compliance with the License.
+#
+# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
+# or http://www.opensolaris.org/os/licensing.
+# See the License for the specific language governing permissions
+# and limitations under the License.
+#
+# When distributing Covered Code, include this CDDL HEADER in each
+# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
+# If applicable, add the following below this CDDL HEADER, with the
+# fields enclosed by brackets "[]" replaced with your own identifying
+# information: Portions Copyright [yyyy] [name of copyright owner]
+#
+# CDDL HEADER END
+#
+
+#
+# Copyright 2007 Sun Microsystems, Inc.  All rights reserved.
+# Use is subject to license terms.
+#
+
+#
+# Copyright (c) 2013 by Delphix. All rights reserved.
+#
+
+# *** ASSERTION DESCRIPTION ***
+#
+# No command is actually run (hence '-:-') but rather this state file is
+# used to verify that when we create a dataset hierarchy that the
+# properties of each dataset have their default values.
+#
+# *** ASSERTION DESCRIPTION ***
+#
+-:-
+#
+# <prop src before cmd>         <prop src after cmd>
+default                                default
+default                                default
+default                                default
diff --git a/tests/zfs-tests/tests/functional/inheritance/state009.cfg b/tests/zfs-tests/tests/functional/inheritance/state009.cfg
new file mode 100644 (file)
index 0000000..3fb2841
--- /dev/null
@@ -0,0 +1,57 @@
+#
+# CDDL HEADER START
+#
+# The contents of this file are subject to the terms of the
+# Common Development and Distribution License (the "License").
+# You may not use this file except in compliance with the License.
+#
+# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
+# or http://www.opensolaris.org/os/licensing.
+# See the License for the specific language governing permissions
+# and limitations under the License.
+#
+# When distributing Covered Code, include this CDDL HEADER in each
+# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
+# If applicable, add the following below this CDDL HEADER, with the
+# fields enclosed by brackets "[]" replaced with your own identifying
+# information: Portions Copyright [yyyy] [name of copyright owner]
+#
+# CDDL HEADER END
+#
+
+#
+# Copyright 2007 Sun Microsystems, Inc.  All rights reserved.
+# Use is subject to license terms.
+#
+
+#
+# Copyright (c) 2013 by Delphix. All rights reserved.
+#
+
+# *** ASSERTION DESCRIPTION ***
+#
+# Verify that executing 'zfs inherit' at different levels of a
+# data hierarchy where the properties of each dataset have their
+# default values leaves the values unchanged.
+#
+# *** ASSERTION DESCRIPTION ***
+#
+#
+TESTPOOL:inherit
+#
+default                                default
+default                                default
+default                                default
+#
+TESTPOOL/TESTCTR:inherit
+#
+default                                default
+default                                default
+default                                default
+#
+TESTPOOL/TESTCTR/TESTFS1:inherit
+#
+default                                default
+default                                default
+default                                default
+#
diff --git a/tests/zfs-tests/tests/functional/inheritance/state010.cfg b/tests/zfs-tests/tests/functional/inheritance/state010.cfg
new file mode 100644 (file)
index 0000000..4c51e80
--- /dev/null
@@ -0,0 +1,56 @@
+#
+# CDDL HEADER START
+#
+# The contents of this file are subject to the terms of the
+# Common Development and Distribution License (the "License").
+# You may not use this file except in compliance with the License.
+#
+# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
+# or http://www.opensolaris.org/os/licensing.
+# See the License for the specific language governing permissions
+# and limitations under the License.
+#
+# When distributing Covered Code, include this CDDL HEADER in each
+# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
+# If applicable, add the following below this CDDL HEADER, with the
+# fields enclosed by brackets "[]" replaced with your own identifying
+# information: Portions Copyright [yyyy] [name of copyright owner]
+#
+# CDDL HEADER END
+#
+
+#
+# Copyright 2007 Sun Microsystems, Inc.  All rights reserved.
+# Use is subject to license terms.
+#
+
+#
+# Copyright (c) 2013 by Delphix. All rights reserved.
+#
+
+# *** ASSERTION DESCRIPTION ***
+#
+# Verify that executing 'zfs inherit -r' at different levels of a
+# data hierarchy where the properties of each dataset have their
+# default values leaves the values unchanged.
+#
+# *** ASSERTION DESCRIPTION ***
+#
+TESTPOOL:inherit -r
+#
+default                                default
+default                                default
+default                                default
+#
+TESTPOOL/TESTCTR:inherit -r
+#
+default                                default
+default                                default
+default                                default
+#
+TESTPOOL/TESTCTR/TESTFS1:inherit -r
+#
+default                                default
+default                                default
+default                                default
+#
diff --git a/tests/zfs-tests/tests/functional/inheritance/state011.cfg b/tests/zfs-tests/tests/functional/inheritance/state011.cfg
new file mode 100644 (file)
index 0000000..f6e791e
--- /dev/null
@@ -0,0 +1,58 @@
+#
+# CDDL HEADER START
+#
+# The contents of this file are subject to the terms of the
+# Common Development and Distribution License (the "License").
+# You may not use this file except in compliance with the License.
+#
+# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
+# or http://www.opensolaris.org/os/licensing.
+# See the License for the specific language governing permissions
+# and limitations under the License.
+#
+# When distributing Covered Code, include this CDDL HEADER in each
+# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
+# If applicable, add the following below this CDDL HEADER, with the
+# fields enclosed by brackets "[]" replaced with your own identifying
+# information: Portions Copyright [yyyy] [name of copyright owner]
+#
+# CDDL HEADER END
+#
+
+#
+# Copyright 2007 Sun Microsystems, Inc.  All rights reserved.
+# Use is subject to license terms.
+#
+
+#
+# Copyright (c) 2013 by Delphix. All rights reserved.
+#
+
+# *** ASSERTION DESCRIPTION ***
+#
+# Verify that running 'zfs inherit' at each level of the data hierarchy
+# when the bottom filesystem level properties have been set locally has
+# no effect except at the bottom level where the property values are
+# inherited from the middle level dataset.
+#
+# *** ASSERTION DESCRIPTION ***
+#
+#
+TESTPOOL:inherit
+#
+default                                default
+default                                default
+local                          local
+#
+TESTPOOL/TESTCTR:inherit
+#
+default                                default
+default                                default
+local                          local
+#
+TESTPOOL/TESTCTR/TESTFS1:inherit
+#
+default                                default
+default                                default
+local                          default
+#
diff --git a/tests/zfs-tests/tests/functional/inheritance/state012.cfg b/tests/zfs-tests/tests/functional/inheritance/state012.cfg
new file mode 100644 (file)
index 0000000..6f3f389
--- /dev/null
@@ -0,0 +1,62 @@
+#
+# CDDL HEADER START
+#
+# The contents of this file are subject to the terms of the
+# Common Development and Distribution License (the "License").
+# You may not use this file except in compliance with the License.
+#
+# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
+# or http://www.opensolaris.org/os/licensing.
+# See the License for the specific language governing permissions
+# and limitations under the License.
+#
+# When distributing Covered Code, include this CDDL HEADER in each
+# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
+# If applicable, add the following below this CDDL HEADER, with the
+# fields enclosed by brackets "[]" replaced with your own identifying
+# information: Portions Copyright [yyyy] [name of copyright owner]
+#
+# CDDL HEADER END
+#
+
+#
+# Copyright 2007 Sun Microsystems, Inc.  All rights reserved.
+# Use is subject to license terms.
+#
+
+#
+# Copyright (c) 2013 by Delphix. All rights reserved.
+#
+
+# *** ASSERTION DESCRIPTION ***
+#
+# Verify that running 'zfs inherit -r' at each level of the data hierarchy
+# when the bottom filesystem level properties have been set locally results
+# in the top level property values being propogated down the data
+# hierarchy.
+#
+# Executing inherit -r at the middle level and bottom levels after
+# running it at the top level is somewhat redundant as the top level value
+# should propogate down the entire data hierarchy. Done for completeness
+# sake.
+#
+# *** ASSERTION DESCRIPTION ***
+#
+TESTPOOL:inherit -r
+#
+default                                default
+default                                default
+local                          default
+#
+TESTPOOL/TESTCTR:inherit -r
+#
+default                                default
+default                                default
+default                                default
+#
+TESTPOOL/TESTCTR/TESTFS1:inherit -r
+#
+default                                default
+default                                default
+default                                default
+#
diff --git a/tests/zfs-tests/tests/functional/inheritance/state013.cfg b/tests/zfs-tests/tests/functional/inheritance/state013.cfg
new file mode 100644 (file)
index 0000000..ae59192
--- /dev/null
@@ -0,0 +1,56 @@
+#
+# CDDL HEADER START
+#
+# The contents of this file are subject to the terms of the
+# Common Development and Distribution License (the "License").
+# You may not use this file except in compliance with the License.
+#
+# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
+# or http://www.opensolaris.org/os/licensing.
+# See the License for the specific language governing permissions
+# and limitations under the License.
+#
+# When distributing Covered Code, include this CDDL HEADER in each
+# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
+# If applicable, add the following below this CDDL HEADER, with the
+# fields enclosed by brackets "[]" replaced with your own identifying
+# information: Portions Copyright [yyyy] [name of copyright owner]
+#
+# CDDL HEADER END
+#
+
+#
+# Copyright 2007 Sun Microsystems, Inc.  All rights reserved.
+# Use is subject to license terms.
+#
+
+#
+# Copyright (c) 2013 by Delphix. All rights reserved.
+#
+
+# *** ASSERTION DESCRIPTION ***
+#
+# Verify that executing 'zfs inherit' on each level when the middle
+# and bottom levels properties are set locally results in the middle and
+# bottom levels inheriting values from the next level up in the hierarchy.
+#
+# *** ASSERTION DESCRIPTION ***
+#
+TESTPOOL:inherit
+#
+default                                default
+local                          local
+local                          local
+#
+TESTPOOL/TESTCTR:inherit
+#
+default                                default
+local                          default
+local                          local
+#
+TESTPOOL/TESTCTR/TESTFS1:inherit
+#
+default                                default
+default                                default
+local                          default
+#
diff --git a/tests/zfs-tests/tests/functional/inheritance/state014.cfg b/tests/zfs-tests/tests/functional/inheritance/state014.cfg
new file mode 100644 (file)
index 0000000..3322123
--- /dev/null
@@ -0,0 +1,62 @@
+#
+# CDDL HEADER START
+#
+# The contents of this file are subject to the terms of the
+# Common Development and Distribution License (the "License").
+# You may not use this file except in compliance with the License.
+#
+# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
+# or http://www.opensolaris.org/os/licensing.
+# See the License for the specific language governing permissions
+# and limitations under the License.
+#
+# When distributing Covered Code, include this CDDL HEADER in each
+# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
+# If applicable, add the following below this CDDL HEADER, with the
+# fields enclosed by brackets "[]" replaced with your own identifying
+# information: Portions Copyright [yyyy] [name of copyright owner]
+#
+# CDDL HEADER END
+#
+
+#
+# Copyright 2007 Sun Microsystems, Inc.  All rights reserved.
+# Use is subject to license terms.
+#
+
+#
+# Copyright (c) 2013 by Delphix. All rights reserved.
+#
+
+# *** ASSERTION DESCRIPTION ***
+#
+# Verify that running 'zfs inherit -r' at each level of the data hierarchy
+# when the bottom and middle level properties have been set locally results
+# in the top level property values being propogated down the data
+# hierarchy.
+#
+# Note : executing inherit -r at the middle level and bottom levels after
+# running it at the top level is somewhat redundant as the top level value
+# should propogate down the entire data hierarchy. Done for completeness
+# sake.
+#
+# *** ASSERTION DESCRIPTION ***
+#
+TESTPOOL:inherit -r
+#
+default                                default
+local                          default
+local                          default
+#
+TESTPOOL/TESTCTR:inherit -r
+#
+default                                default
+default                                default
+default                                default
+#
+TESTPOOL/TESTCTR/TESTFS1:inherit -r
+#
+default                                default
+default                                default
+default                                default
+#
diff --git a/tests/zfs-tests/tests/functional/inheritance/state015.cfg b/tests/zfs-tests/tests/functional/inheritance/state015.cfg
new file mode 100644 (file)
index 0000000..bab7bc2
--- /dev/null
@@ -0,0 +1,66 @@
+#
+# CDDL HEADER START
+#
+# The contents of this file are subject to the terms of the
+# Common Development and Distribution License (the "License").
+# You may not use this file except in compliance with the License.
+#
+# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
+# or http://www.opensolaris.org/os/licensing.
+# See the License for the specific language governing permissions
+# and limitations under the License.
+#
+# When distributing Covered Code, include this CDDL HEADER in each
+# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
+# If applicable, add the following below this CDDL HEADER, with the
+# fields enclosed by brackets "[]" replaced with your own identifying
+# information: Portions Copyright [yyyy] [name of copyright owner]
+#
+# CDDL HEADER END
+#
+
+#
+# Copyright 2007 Sun Microsystems, Inc.  All rights reserved.
+# Use is subject to license terms.
+#
+
+#
+# Copyright (c) 2013 by Delphix. All rights reserved.
+#
+
+# *** ASSERTION DESCRIPTION ***
+#
+# Verify that executing 'zfs inherit' at the top level in the hierarchy
+# when the middle level properties are set locally, and the bottom
+# level has inherited its value from the middle level, results in no change
+# to the top level properties.
+#
+# Executing 'zfs inherit' at the middle level results in the middle level
+# inheriting its value from the top level, and passing the values down to
+# the bottom level.
+#
+# Executing 'zfs inherit' at the bottom level is somewhat redundant but
+# is done for completness sake.
+#
+# *** ASSERTION DESCRIPTION ***
+#
+#
+TESTPOOL:inherit
+#
+default                         default
+local                           local
+TESTPOOL/TESTCTR                TESTPOOL/TESTCTR
+#
+#
+TESTPOOL/TESTCTR:inherit
+#
+default                         default
+local                           default
+TESTPOOL/TESTCTR                default
+#
+#
+TESTPOOL/TESTCTR/TESTFS1:inherit
+#
+default                         default
+default                         default
+default                         default
diff --git a/tests/zfs-tests/tests/functional/inheritance/state016.cfg b/tests/zfs-tests/tests/functional/inheritance/state016.cfg
new file mode 100644 (file)
index 0000000..50601c6
--- /dev/null
@@ -0,0 +1,62 @@
+#
+# CDDL HEADER START
+#
+# The contents of this file are subject to the terms of the
+# Common Development and Distribution License (the "License").
+# You may not use this file except in compliance with the License.
+#
+# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
+# or http://www.opensolaris.org/os/licensing.
+# See the License for the specific language governing permissions
+# and limitations under the License.
+#
+# When distributing Covered Code, include this CDDL HEADER in each
+# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
+# If applicable, add the following below this CDDL HEADER, with the
+# fields enclosed by brackets "[]" replaced with your own identifying
+# information: Portions Copyright [yyyy] [name of copyright owner]
+#
+# CDDL HEADER END
+#
+
+#
+# Copyright 2007 Sun Microsystems, Inc.  All rights reserved.
+# Use is subject to license terms.
+#
+
+#
+# Copyright (c) 2013 by Delphix. All rights reserved.
+#
+
+# *** ASSERTION DESCRIPTION ***
+#
+# Verify that executing 'zfs inherit -r' at the top level in the hierarchy
+# when the middle level properties are set locally, and the bottom
+# level has inherited its value from the middle level, results in no change
+# to the top level properties and the middle and bottom properties changing
+# to the top level (default) values.
+#
+# Executing 'zfs inherit -r' at the bottom and middle levels after executing
+# at the top level is somewhat redundant but ss done for completness sake.
+#
+# *** ASSERTION DESCRIPTION ***
+#
+#
+TESTPOOL:inherit -r
+#
+default                                default
+local                          default
+TESTPOOL                       default
+#
+TESTPOOL/TESTCTR:inherit -r
+#
+default                                default
+default                                default
+default                                default
+#
+TESTPOOL/TESTCTR/TESTFS1:inherit -r
+#
+default                                default
+default                                default
+default                                default
+#
diff --git a/tests/zfs-tests/tests/functional/inheritance/state017.cfg b/tests/zfs-tests/tests/functional/inheritance/state017.cfg
new file mode 100644 (file)
index 0000000..a4a127d
--- /dev/null
@@ -0,0 +1,67 @@
+#
+# CDDL HEADER START
+#
+# The contents of this file are subject to the terms of the
+# Common Development and Distribution License (the "License").
+# You may not use this file except in compliance with the License.
+#
+# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
+# or http://www.opensolaris.org/os/licensing.
+# See the License for the specific language governing permissions
+# and limitations under the License.
+#
+# When distributing Covered Code, include this CDDL HEADER in each
+# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
+# If applicable, add the following below this CDDL HEADER, with the
+# fields enclosed by brackets "[]" replaced with your own identifying
+# information: Portions Copyright [yyyy] [name of copyright owner]
+#
+# CDDL HEADER END
+#
+
+#
+# Copyright 2007 Sun Microsystems, Inc.  All rights reserved.
+# Use is subject to license terms.
+#
+
+#
+# Copyright (c) 2013 by Delphix. All rights reserved.
+#
+
+# *** ASSERTION DESCRIPTION ***
+#
+# Verify that executing 'zfs inherit' at the top level in the hierarchy
+# when the top level and middle level datasets properties are set locally,
+# and the bottom level has inherited its properties from the middle
+# level, results in the top level properties reverting back to their
+# default values.
+#
+# Executing 'zfs inherit' at the middle level results in the middle level
+# inheriting its value from the top level (which is now default), and passing
+# the values down to the bottom level.
+#
+# Executing 'zfs inherit' at the bottom level is somewhat redundant but
+# is done for completness sake.
+#
+# *** ASSERTION DESCRIPTION ***
+#
+#
+TESTPOOL:inherit
+#
+local                           default
+local                           local
+TESTPOOL/TESTCTR                TESTPOOL/TESTCTR
+#
+#
+TESTPOOL/TESTCTR:inherit
+#
+default                         default
+local                           default
+TESTPOOL/TESTCTR                default
+#
+#
+TESTPOOL/TESTCTR/TESTFS1:inherit
+#
+default                         default
+default                         default
+default                         default
diff --git a/tests/zfs-tests/tests/functional/inheritance/state018.cfg b/tests/zfs-tests/tests/functional/inheritance/state018.cfg
new file mode 100644 (file)
index 0000000..b76bbac
--- /dev/null
@@ -0,0 +1,64 @@
+#
+# CDDL HEADER START
+#
+# The contents of this file are subject to the terms of the
+# Common Development and Distribution License (the "License").
+# You may not use this file except in compliance with the License.
+#
+# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
+# or http://www.opensolaris.org/os/licensing.
+# See the License for the specific language governing permissions
+# and limitations under the License.
+#
+# When distributing Covered Code, include this CDDL HEADER in each
+# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
+# If applicable, add the following below this CDDL HEADER, with the
+# fields enclosed by brackets "[]" replaced with your own identifying
+# information: Portions Copyright [yyyy] [name of copyright owner]
+#
+# CDDL HEADER END
+#
+
+#
+# Copyright 2007 Sun Microsystems, Inc.  All rights reserved.
+# Use is subject to license terms.
+#
+
+#
+# Copyright (c) 2013 by Delphix. All rights reserved.
+#
+
+# *** ASSERTION DESCRIPTION ***
+#
+# Verify that executing 'zfs inherit -r' at the top level in the hierarchy
+# when the top level and middle level datasets properties are set locally,
+# and the bottom level has inherited its properties from the middle
+# level, results in the top level properties reverting back to their
+# default values and being propogated down to the other datasets in the
+# hierarchy.
+#
+# Executing 'zfs inherit -r' at the middle and bottom levels after executing
+# it at the top level is somewhat redundant but is done for completness sake.
+#
+# *** ASSERTION DESCRIPTION ***
+#
+#
+TESTPOOL:inherit -r
+#
+local                          default
+local                          default
+TESTPOOL/TESTCTR               default
+#
+#
+TESTPOOL/TESTCTR:inherit -r
+#
+default                                default
+default                                default
+default                                default
+#
+#
+TESTPOOL/TESTCTR/TESTFS1:inherit
+#
+default                                default
+default                                default
+default                                default
diff --git a/tests/zfs-tests/tests/functional/inheritance/state019.cfg b/tests/zfs-tests/tests/functional/inheritance/state019.cfg
new file mode 100644 (file)
index 0000000..652d3b1
--- /dev/null
@@ -0,0 +1,63 @@
+#
+# CDDL HEADER START
+#
+# The contents of this file are subject to the terms of the
+# Common Development and Distribution License (the "License").
+# You may not use this file except in compliance with the License.
+#
+# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
+# or http://www.opensolaris.org/os/licensing.
+# See the License for the specific language governing permissions
+# and limitations under the License.
+#
+# When distributing Covered Code, include this CDDL HEADER in each
+# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
+# If applicable, add the following below this CDDL HEADER, with the
+# fields enclosed by brackets "[]" replaced with your own identifying
+# information: Portions Copyright [yyyy] [name of copyright owner]
+#
+# CDDL HEADER END
+#
+
+#
+# Copyright 2007 Sun Microsystems, Inc.  All rights reserved.
+# Use is subject to license terms.
+#
+
+#
+# Copyright (c) 2013 by Delphix. All rights reserved.
+#
+
+# *** ASSERTION DESCRIPTION ***
+#
+# Verify that executing 'zfs inherit' at the top level in the hierarchy
+# when the top level properties are set locally and the middle and bottom
+# datasets have inherited from the top level, results in the top level
+# properties reverting back to their default values, the middle and bottom
+# levels inheriting the changed values.
+#
+# Executing 'zfs inherit' at the middle and bottom levels is somewhat
+# redundant but is done for completness sake.
+#
+# *** ASSERTION DESCRIPTION ***
+#
+TESTPOOL:inherit
+#
+local                          default
+TESTPOOL                       default
+TESTPOOL                       default
+#
+#
+TESTPOOL/TESTCTR:inherit
+#
+default                                default
+default                                default
+default                                default
+#
+#
+TESTPOOL/TESTCTR/TESTFS1:inherit
+#
+default                                default
+default                                default
+default                                default
+#
diff --git a/tests/zfs-tests/tests/functional/inheritance/state020.cfg b/tests/zfs-tests/tests/functional/inheritance/state020.cfg
new file mode 100644 (file)
index 0000000..fc869f8
--- /dev/null
@@ -0,0 +1,64 @@
+#
+# CDDL HEADER START
+#
+# The contents of this file are subject to the terms of the
+# Common Development and Distribution License (the "License").
+# You may not use this file except in compliance with the License.
+#
+# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
+# or http://www.opensolaris.org/os/licensing.
+# See the License for the specific language governing permissions
+# and limitations under the License.
+#
+# When distributing Covered Code, include this CDDL HEADER in each
+# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
+# If applicable, add the following below this CDDL HEADER, with the
+# fields enclosed by brackets "[]" replaced with your own identifying
+# information: Portions Copyright [yyyy] [name of copyright owner]
+#
+# CDDL HEADER END
+#
+
+#
+# Copyright 2007 Sun Microsystems, Inc.  All rights reserved.
+# Use is subject to license terms.
+#
+
+#
+# Copyright (c) 2013 by Delphix. All rights reserved.
+#
+
+# *** ASSERTION DESCRIPTION ***
+#
+# Verify that executing 'zfs inherit -r' at the top level in the hierarchy
+# when the top level properties are set locally and the middle and bottom
+# datasets have inherited from the top level, results in the top level
+# properties reverting back to their default values, the middle and bottom
+# levels inheriting the changed values.
+#
+# Executing 'zfs inherit -r' at the middle and bottom levels is somewhat
+# redundant but is done for completness sake.
+#
+# *** ASSERTION DESCRIPTION ***
+#
+#
+TESTPOOL:inherit -r
+#
+local                          default
+TESTPOOL                       default
+TESTPOOL                       default
+#
+#
+TESTPOOL/TESTCTR:inherit -r
+#
+default                                default
+default                                default
+default                                default
+#
+#
+TESTPOOL/TESTCTR/TESTFS1:inherit -r
+#
+default                                default
+default                                default
+default                                default
+#
diff --git a/tests/zfs-tests/tests/functional/inheritance/state021.cfg b/tests/zfs-tests/tests/functional/inheritance/state021.cfg
new file mode 100644 (file)
index 0000000..f61472e
--- /dev/null
@@ -0,0 +1,64 @@
+#
+# CDDL HEADER START
+#
+# The contents of this file are subject to the terms of the
+# Common Development and Distribution License (the "License").
+# You may not use this file except in compliance with the License.
+#
+# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
+# or http://www.opensolaris.org/os/licensing.
+# See the License for the specific language governing permissions
+# and limitations under the License.
+#
+# When distributing Covered Code, include this CDDL HEADER in each
+# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
+# If applicable, add the following below this CDDL HEADER, with the
+# fields enclosed by brackets "[]" replaced with your own identifying
+# information: Portions Copyright [yyyy] [name of copyright owner]
+#
+# CDDL HEADER END
+#
+
+#
+# Copyright 2007 Sun Microsystems, Inc.  All rights reserved.
+# Use is subject to license terms.
+#
+
+#
+# Copyright (c) 2013 by Delphix. All rights reserved.
+#
+
+# *** ASSERTION DESCRIPTION ***
+#
+# Verify that executing 'zfs inherit' at the top level in the hierarchy
+# when the top level and bottom level properties are set locally and the
+# middle dataset has inherited from the top level, results in the top level
+# properties reverting back to their default values, and the middle level
+# inheriting the new top level value.
+#
+# Executing 'zfs inherit' at the bottom level results in it inheriting
+# the middle level values.
+#
+# *** ASSERTION DESCRIPTION ***
+#
+#
+TESTPOOL:inherit
+#
+local                          default
+TESTPOOL                       default
+local                          local
+#
+#
+TESTPOOL/TESTCTR:inherit
+#
+default                                default
+default                                default
+local                          local
+#
+#
+TESTPOOL/TESTCTR/TESTFS1:inherit
+#
+default                                default
+default                                default
+local                          default
+#
diff --git a/tests/zfs-tests/tests/functional/inheritance/state022.cfg b/tests/zfs-tests/tests/functional/inheritance/state022.cfg
new file mode 100644 (file)
index 0000000..a00f3bb
--- /dev/null
@@ -0,0 +1,63 @@
+#
+# CDDL HEADER START
+#
+# The contents of this file are subject to the terms of the
+# Common Development and Distribution License (the "License").
+# You may not use this file except in compliance with the License.
+#
+# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
+# or http://www.opensolaris.org/os/licensing.
+# See the License for the specific language governing permissions
+# and limitations under the License.
+#
+# When distributing Covered Code, include this CDDL HEADER in each
+# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
+# If applicable, add the following below this CDDL HEADER, with the
+# fields enclosed by brackets "[]" replaced with your own identifying
+# information: Portions Copyright [yyyy] [name of copyright owner]
+#
+# CDDL HEADER END
+#
+
+#
+# Copyright 2007 Sun Microsystems, Inc.  All rights reserved.
+# Use is subject to license terms.
+#
+
+#
+# Copyright (c) 2013 by Delphix. All rights reserved.
+#
+
+# *** ASSERTION DESCRIPTION ***
+#
+# Verify that executing 'zfs inherit -r' at the top level in the hierarchy
+# when the top level and bottom level properties are set locally and the
+# middle dataset has inherited from the top level, results in the top level
+# properties reverting back to their default values, the middle and bottom
+# levels inheriting the changed values.
+#
+# Executing 'zfs inherit -r' at the middle and bottom levels is somewhat
+# redundant but is done for completness sake.
+#
+# *** ASSERTION DESCRIPTION ***
+#
+TESTPOOL:inherit -r
+#
+local                          default
+TESTPOOL                       default
+local                          default
+#
+#
+TESTPOOL/TESTCTR:inherit -r
+#
+default                                default
+default                                default
+default                                default
+#
+#
+TESTPOOL/TESTCTR/TESTFS1:inherit -r
+#
+default                                default
+default                                default
+default                                default
+#
diff --git a/tests/zfs-tests/tests/functional/inheritance/state023.cfg b/tests/zfs-tests/tests/functional/inheritance/state023.cfg
new file mode 100644 (file)
index 0000000..8219a2a
--- /dev/null
@@ -0,0 +1,65 @@
+#
+# CDDL HEADER START
+#
+# The contents of this file are subject to the terms of the
+# Common Development and Distribution License (the "License").
+# You may not use this file except in compliance with the License.
+#
+# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
+# or http://www.opensolaris.org/os/licensing.
+# See the License for the specific language governing permissions
+# and limitations under the License.
+#
+# When distributing Covered Code, include this CDDL HEADER in each
+# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
+# If applicable, add the following below this CDDL HEADER, with the
+# fields enclosed by brackets "[]" replaced with your own identifying
+# information: Portions Copyright [yyyy] [name of copyright owner]
+#
+# CDDL HEADER END
+#
+
+#
+# Copyright 2007 Sun Microsystems, Inc.  All rights reserved.
+# Use is subject to license terms.
+#
+
+#
+# Copyright (c) 2013 by Delphix. All rights reserved.
+#
+
+# *** ASSERTION DESCRIPTION ***
+#
+# Verify that executing 'zfs inherit' at the top level in the hierarchy
+# when each levels properties are set locally, results in the top level
+# properties reverting back to their default values.
+#
+# Executing 'zfs inherit' at the middle level results in it inheriting
+# the top levels (now default) values
+#
+# Executing 'zfs inherit' at the bottom level results in it inheriting
+# the middle levels (now default) values
+#
+# *** ASSERTION DESCRIPTION ***
+#
+#
+TESTPOOL:inherit
+#
+local                          default
+local                          local
+local                          local
+#
+#
+TESTPOOL/TESTCTR:inherit
+#
+default                                default
+local                          default
+local                          local
+#
+#
+TESTPOOL/TESTCTR/TESTFS1:inherit
+#
+default                                default
+default                                default
+local                          default
+#
diff --git a/tests/zfs-tests/tests/functional/inheritance/state024.cfg b/tests/zfs-tests/tests/functional/inheritance/state024.cfg
new file mode 100644 (file)
index 0000000..22d605c
--- /dev/null
@@ -0,0 +1,63 @@
+#
+# CDDL HEADER START
+#
+# The contents of this file are subject to the terms of the
+# Common Development and Distribution License (the "License").
+# You may not use this file except in compliance with the License.
+#
+# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
+# or http://www.opensolaris.org/os/licensing.
+# See the License for the specific language governing permissions
+# and limitations under the License.
+#
+# When distributing Covered Code, include this CDDL HEADER in each
+# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
+# If applicable, add the following below this CDDL HEADER, with the
+# fields enclosed by brackets "[]" replaced with your own identifying
+# information: Portions Copyright [yyyy] [name of copyright owner]
+#
+# CDDL HEADER END
+#
+
+#
+# Copyright 2007 Sun Microsystems, Inc.  All rights reserved.
+# Use is subject to license terms.
+#
+
+#
+# Copyright (c) 2013 by Delphix. All rights reserved.
+#
+
+# *** ASSERTION DESCRIPTION ***
+#
+# Verify that executing 'zfs inherit -r' at the top level in the hierarchy
+# when each levels properties are set locally, results in the top level
+# properties reverting back to their default values, and the changed
+# values being propogated down the hierarchy.
+#
+# Executing 'zfs inherit -r' at the middle and bottom levels after doing so
+# at the top level is somewhat redundant but is done for completeness.
+#
+# *** ASSERTION DESCRIPTION ***
+#
+#
+TESTPOOL:inherit -r
+#
+local                          default
+local                          default
+local                          default
+#
+#
+TESTPOOL/TESTCTR:inherit
+#
+default                                default
+default                                default
+default                                default
+#
+#
+TESTPOOL/TESTCTR/TESTFS1:inherit
+#
+default                                default
+default                                default
+default                                default
+#
diff --git a/tests/zfs-tests/tests/functional/inuse/Makefile.am b/tests/zfs-tests/tests/functional/inuse/Makefile.am
new file mode 100644 (file)
index 0000000..efc00ea
--- /dev/null
@@ -0,0 +1,12 @@
+pkgdatadir = $(datadir)/@PACKAGE@/zfs-tests/tests/functional/inuse
+dist_pkgdata_SCRIPTS = \
+       inuse.cfg \
+       setup.ksh \
+       inuse_001_pos.ksh \
+       inuse_003_pos.ksh \
+       inuse_004_pos.ksh \
+       inuse_005_pos.ksh \
+       inuse_006_pos.ksh \
+       inuse_007_pos.ksh \
+       inuse_008_pos.ksh \
+       inuse_009_pos.ksh
diff --git a/tests/zfs-tests/tests/functional/inuse/inuse.cfg b/tests/zfs-tests/tests/functional/inuse/inuse.cfg
new file mode 100644 (file)
index 0000000..1666cdb
--- /dev/null
@@ -0,0 +1,135 @@
+#
+# CDDL HEADER START
+#
+# The contents of this file are subject to the terms of the
+# Common Development and Distribution License (the "License").
+# You may not use this file except in compliance with the License.
+#
+# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
+# or http://www.opensolaris.org/os/licensing.
+# See the License for the specific language governing permissions
+# and limitations under the License.
+#
+# When distributing Covered Code, include this CDDL HEADER in each
+# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
+# If applicable, add the following below this CDDL HEADER, with the
+# fields enclosed by brackets "[]" replaced with your own identifying
+# information: Portions Copyright [yyyy] [name of copyright owner]
+#
+# CDDL HEADER END
+#
+
+#
+# Copyright 2009 Sun Microsystems, Inc.  All rights reserved.
+# Use is subject to license terms.
+#
+
+#
+# Copyright (c) 2013 by Delphix. All rights reserved.
+#
+
+. $STF_SUITE/include/libtest.shlib
+
+if is_linux; then
+       export SLICE_PREFIX="p"
+       export SLICE0=1
+       export SLICE1=2
+else
+       export SLICE_PREFIX="s"
+       export SLICE0=0
+       export SLICE1=1
+fi
+
+verify_disk_count "$DISKS" 2
+set -A disk_array $(find_disks $DISKS)
+case "${#disk_array[@]}" in
+2)
+       FS_DISK0=${disk_array[0]}
+       FS_DISK1=${disk_array[1]}
+       FS_DISK2=${disk_array[0]}
+       FS_DISK3=${disk_array[1]}
+       FS_SIDE0=${FS_DISK0}${SLICE_PREFIX}${SLICE0}
+       FS_SIDE1=${FS_DISK0}${SLICE_PREFIX}${SLICE1}
+       FS_SIDE2=${FS_DISK1}${SLICE_PREFIX}${SLICE0}
+       FS_SIDE3=${FS_DISK1}${SLICE_PREFIX}${SLICE1}
+       disk0="${DEV_DSKDIR}/$FS_SIDE0"
+       disk1="${DEV_DSKDIR}/$FS_SIDE1"
+       disk2="${DEV_DSKDIR}/$FS_SIDE2"
+       disk3="${DEV_DSKDIR}/$FS_SIDE3"
+       disktargets="$disk0 $disk2"
+       rawdisk0="${DEV_RDSKDIR}/$FS_SIDE0"
+       rawdisk1="${DEV_RDSKDIR}/$FS_SIDE1"
+       rawdisk2="${DEV_RDSKDIR}/$FS_SIDE2"
+       rawdisk3="${DEV_RDSKDIR}/$FS_SIDE3"
+       rawtargets="$rawdisk0 $rawdisk2"
+       vdisks="$FS_DISK0"
+       sdisks="$FS_DISK1"
+       vslices="$FS_SIDE0 $FS_SIDE1 $FS_SIDE2"
+       sslices="$FS_SIDE3"
+       ;;
+3)
+       FS_DISK0=${disk_array[0]}
+       FS_DISK1=${disk_array[1]}
+       FS_DISK2=${disk_array[2]}
+       FS_DISK3=${disk_array[0]}
+       FS_SIDE0=${FS_DISK0}${SLICE_PREFIX}${SLICE0}
+       FS_SIDE1=${FS_DISK0}${SLICE_PREFIX}${SLICE1}
+       FS_SIDE2=${FS_DISK1}${SLICE_PREFIX}${SLICE0}
+       FS_SIDE3=${FS_DISK2}${SLICE_PREFIX}${SLICE0}
+       disk0="${DEV_DSKDIR}/$FS_SIDE0"
+       disk1="${DEV_DSKDIR}/$FS_SIDE1"
+       disk2="${DEV_DSKDIR}/$FS_SIDE2"
+       disk3="${DEV_DSKDIR}/$FS_SIDE3"
+       disktargets="$disk0 $disk2 $disk3"
+       rawdisk0="${DEV_RDSKDIR}/$FS_SIDE0"
+       rawdisk1="${DEV_RDSKDIR}/$FS_SIDE1"
+       rawdisk2="${DEV_RDSKDIR}/$FS_SIDE2"
+       rawdisk3="${DEV_RDSKDIR}/$FS_SIDE3"
+       rawtargets="$rawdisk0 $rawdisk2 $rawdisk3"
+       vdisks="$FS_DISK0 $FS_DISK1"
+       sdisks="$FS_DISK2"
+       vslices="$FS_SIDE0 $FS_SIDE2 $FS_SIDE3"
+       sslices="$FS_SIDE1"
+       ;;
+*)
+       FS_DISK0=${disk_array[0]}
+       FS_DISK1=${disk_array[1]}
+       FS_DISK2=${disk_array[2]}
+       FS_DISK3=${disk_array[3]}
+       FS_SIDE0=${FS_DISK0}${SLICE_PREFIX}${SLICE0}
+       FS_SIDE1=${FS_DISK1}${SLICE_PREFIX}${SLICE0}
+       FS_SIDE2=${FS_DISK2}${SLICE_PREFIX}${SLICE0}
+       FS_SIDE3=${FS_DISK3}${SLICE_PREFIX}${SLICE0}
+       disk0="${DEV_DSKDIR}/$FS_SIDE0"
+       disk1="${DEV_DSKDIR}/$FS_SIDE1"
+       disk2="${DEV_DSKDIR}/$FS_SIDE2"
+       disk3="${DEV_DSKDIR}/$FS_SIDE3"
+       disktargets="$disk0 $disk1 $disk2 $disk3"
+       rawdisk0="${DEV_RDSKDIR}/$FS_SIDE0"
+       rawdisk1="${DEV_RDSKDIR}/$FS_SIDE1"
+       rawdisk2="${DEV_RDSKDIR}/$FS_SIDE2"
+       rawdisk3="${DEV_RDSKDIR}/$FS_SIDE3"
+       rawtargets="$rawdisk0 $rawdisk1 $rawdisk2 $rawdisk3"
+       vdisks="$FS_DISK0 $FS_DISK1 $FS_DISK2"
+       sdisks="$FS_DISK3"
+       vslices="$FS_SIDE0 $FS_SIDE1 $FS_SIDE2"
+       sslices="$FS_SIDE3"
+       ;;
+esac
+
+export FS_DISK0 FS_DISK1 FS_DISK2 FS_DISK3 SINGLE_DISK
+export FS_SIDE0 FS_SIDE1 FS_SIDE2 FS_SIDE3
+export disk0 disk1 disk2 disk3 disktargets
+export rawdisk0 rawdisk1 rawdisk2 rawdisk3 rawtargets
+export vdisks sdisks vslices sslices
+
+export UFSMP=$TESTDIR/testinuseufsdump
+export FS_SIZE=1g
+export PREVDUMPDEV=""
+export PIDUFSDUMP=""
+export PIDUFSRESTORE=""
+# size of block to be written to test file - currently 1mb
+export BLOCK_SIZE=$(( 1024 * 1024 ))
+# number of blocks to write == size of file
+export BLOCK_COUNT=100
+export STF_TIMEOUT=1200                        # 20 minutes max.
diff --git a/tests/zfs-tests/tests/functional/inuse/inuse_001_pos.ksh b/tests/zfs-tests/tests/functional/inuse/inuse_001_pos.ksh
new file mode 100755 (executable)
index 0000000..1feb681
--- /dev/null
@@ -0,0 +1,90 @@
+#!/bin/ksh -p
+#
+# CDDL HEADER START
+#
+# The contents of this file are subject to the terms of the
+# Common Development and Distribution License (the "License").
+# You may not use this file except in compliance with the License.
+#
+# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
+# or http://www.opensolaris.org/os/licensing.
+# See the License for the specific language governing permissions
+# and limitations under the License.
+#
+# When distributing Covered Code, include this CDDL HEADER in each
+# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
+# If applicable, add the following below this CDDL HEADER, with the
+# fields enclosed by brackets "[]" replaced with your own identifying
+# information: Portions Copyright [yyyy] [name of copyright owner]
+#
+# CDDL HEADER END
+#
+
+#
+# Copyright 2008 Sun Microsystems, Inc.  All rights reserved.
+# Use is subject to license terms.
+#
+
+#
+# Copyright (c) 2013 by Delphix. All rights reserved.
+#
+
+. $STF_SUITE/include/libtest.shlib
+. $STF_SUITE/tests/functional/inuse/inuse.cfg
+
+#
+# DESCRIPTION:
+# ZFS will not interfere with devices that are in use by dumpadm.
+#
+# STRATEGY:
+# 1. Create crash dump device using 'dumpadm'
+# 2. Try to create a ZFS pool using the 'dumpadm' crash dump device.
+#
+
+verify_runnable "global"
+
+function cleanup
+{
+       #
+       # Remove dump device.
+       #
+       if [[ -n $PREVDUMPDEV ]]; then
+               log_must $DUMPADM -u -d $PREVDUMPDEV > /dev/null
+       fi
+
+       destroy_pool $TESTPOOL
+}
+
+log_assert "Ensure ZFS cannot use a device designated as a dump device"
+
+log_onexit cleanup
+
+typeset dumpdev=""
+typeset diskslice=""
+
+PREVDUMPDEV=`$DUMPADM | $GREP "Dump device" | $AWK '{print $3}'`
+
+log_note "Zero $FS_DISK0 and place free space in to slice 0"
+log_must cleanup_devices $FS_DISK0
+
+if [[ $WRAPPER == *"smi"* ]]; then
+       diskslice="${DEV_DSKDIR}/${FS_DISK0}${SLICE_PREFIX}${SLICE2}"
+else
+       diskslice="${DEV_DSKDIR}/${FS_DISK0}${SLICE_PREFIX}${SLICE0}"
+fi
+
+log_note "Configuring $diskslice as dump device"
+log_must $DUMPADM -d $diskslice > /dev/null
+
+log_note "Confirm that dump device has been setup"
+dumpdev=`$DUMPADM | $GREP "Dump device" | $AWK '{print $3}'`
+[[ -z "$dumpdev" ]] && log_untested "No dump device has been configured"
+
+[[ "$dumpdev" != "$diskslice" ]] && \
+    log_untested "Dump device has not been been configured to $diskslice"
+
+log_note "Attempt to zpool the dump device"
+log_mustnot $ZPOOL create $TESTPOOL "$diskslice"
+log_mustnot poolexists $TESTPOOL
+
+log_pass "Unable to zpool a device in use by dumpadm"
diff --git a/tests/zfs-tests/tests/functional/inuse/inuse_003_pos.ksh b/tests/zfs-tests/tests/functional/inuse/inuse_003_pos.ksh
new file mode 100755 (executable)
index 0000000..81bf0b4
--- /dev/null
@@ -0,0 +1,185 @@
+#!/bin/ksh -p
+#
+# CDDL HEADER START
+#
+# The contents of this file are subject to the terms of the
+# Common Development and Distribution License (the "License").
+# You may not use this file except in compliance with the License.
+#
+# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
+# or http://www.opensolaris.org/os/licensing.
+# See the License for the specific language governing permissions
+# and limitations under the License.
+#
+# When distributing Covered Code, include this CDDL HEADER in each
+# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
+# If applicable, add the following below this CDDL HEADER, with the
+# fields enclosed by brackets "[]" replaced with your own identifying
+# information: Portions Copyright [yyyy] [name of copyright owner]
+#
+# CDDL HEADER END
+#
+
+#
+# Copyright 2008 Sun Microsystems, Inc.  All rights reserved.
+# Use is subject to license terms.
+#
+
+#
+# Copyright (c) 2012 by Delphix. All rights reserved.
+#
+
+#
+# Copyright (c) 2013 by Delphix. All rights reserved.
+#
+
+. $STF_SUITE/include/libtest.shlib
+. $STF_SUITE/tests/functional/inuse/inuse.cfg
+
+#
+# DESCRIPTION:
+# ZFS will not interfere with devices that are in use by ufsdump or
+# ufsrestore.
+#
+# STRATEGY:
+# 1. newfs a disk
+# 2. mount the disk
+# 3. create files and dirs on disk
+# 4. umount the disk
+# 5. ufsdump this disk to a backup disk
+# 6. Try to create a ZFS pool with same disk (also as a spare device)
+# 7. ufsrestore the disk from backup
+# 8. try to create a zpool during the ufsrestore
+#
+
+verify_runnable "global"
+
+function cleanup
+{
+       poolexists $TESTPOOL1 && destroy_pool $TESTPOOL1
+
+       poolexists $TESTPOOL2 && destroy_pool $TESTPOOL2
+
+       log_note "Kill off ufsdump process if still running"
+       $KILL -0 $PIDUFSDUMP > /dev/null 2>&1 && \
+           log_must $KILL -9 $PIDUFSDUMP  > /dev/null 2>&1
+       #
+       # Note: It would appear that ufsdump spawns a number of processes
+       # which are not killed when the $PIDUFSDUMP is whacked.  So best bet
+       # is to find the rest of the them and deal with them individually.
+       #
+       for all in `$PGREP ufsdump`
+       do
+               $KILL -9 $all > /dev/null 2>&1
+       done
+
+       log_note "Kill off ufsrestore process if still running"
+       $KILL -0 $PIDUFSRESTORE > /dev/null 2>&1 && \
+           log_must $KILL -9 $PIDUFSRESTORE  > /dev/null 2>&1
+
+       ismounted $UFSMP ufs && log_must $UMOUNT $UFSMP
+
+       $RM -rf $UFSMP
+       $RM -rf $TESTDIR
+
+       #
+       # Tidy up the disks we used.
+       #
+       log_must cleanup_devices $vdisks $sdisks
+}
+
+log_assert "Ensure ZFS does not interfere with devices that are in use by " \
+    "ufsdump or ufsrestore"
+
+log_onexit cleanup
+
+typeset bigdir="${UFSMP}/bigdirectory"
+typeset restored_files="${UFSMP}/restored_files"
+typeset -i dirnum=0
+typeset -i filenum=0
+typeset cwd=""
+
+for num in 0 1 2; do
+       eval typeset slice=\${FS_SIDE$num}
+       disk=${slice%${SLICE_PREFIX}*}
+       slice=${slice##*${SLICE_PREFIX}}
+       if [[ $WRAPPER == *"smi"* && $disk == ${saved_disk} ]]; then
+               cyl=$(get_endslice $disk ${saved_slice})
+               log_must set_partition $slice "$cyl" $FS_SIZE $disk
+       else
+               log_must set_partition $slice "" $FS_SIZE $disk
+       fi
+       saved_disk=$disk
+       saved_slice=$slice
+done
+
+log_note "Make a ufs filesystem on source $rawdisk1"
+$ECHO "y" | $NEWFS -v $rawdisk1 > /dev/null 2>&1
+(($? != 0)) && log_untested "Unable to create ufs filesystem on $rawdisk1"
+
+log_must $MKDIR -p $UFSMP
+
+log_note "mount source $disk1 on $UFSMP"
+log_must $MOUNT $disk1 $UFSMP
+
+log_note "Now create some directories and files to be ufsdump'ed"
+while (($dirnum <= 2)); do
+       log_must $MKDIR $bigdir${dirnum}
+       while (( $filenum <= 2 )); do
+               $FILE_WRITE -o create -f $bigdir${dirnum}/file${filenum} \
+                   -b $BLOCK_SIZE -c $BLOCK_COUNT
+               if [[ $? -ne 0 ]]; then
+                       if [[ $dirnum -lt 3 ]]; then
+                               log_fail "$FILE_WRITE only wrote" \
+                                   "<(( $dirnum * 3 + $filenum ))>" \
+                                   "files, this is not enough"
+                       fi
+               fi
+               ((filenum = filenum + 1))
+       done
+       filenum=0
+       ((dirnum = dirnum + 1))
+done
+
+log_must $UMOUNT $UFSMP
+
+log_note "Start ufsdump in the background"
+log_note "$UFSDUMP 0bf 512 $rawdisk0 $disk1"
+$UFSDUMP 0bf 512 $rawdisk0 $disk1 &
+PIDUFSDUMP=$!
+
+log_note "Attempt to zpool the source device in use by ufsdump"
+log_mustnot $ZPOOL create $TESTPOOL1 "$disk1"
+log_mustnot poolexists $TESTPOOL1
+
+log_note "Attempt to take the source device in use by ufsdump as spare device"
+log_mustnot $ZPOOL create $TESTPOOL1 "$FS_SIDE2" spare "$disk1"
+log_mustnot poolexists $TESTPOOL1
+
+wait $PIDUFSDUMP
+typeset -i retval=$?
+(($retval != 0)) && log_fail "$UFSDUMP failed with error code $ret_val"
+
+log_must $MOUNT $disk1 $UFSMP
+
+log_must $RM -rf $UFSMP/*
+log_must $MKDIR $restored_files
+
+cwd=$PWD
+log_must cd $restored_files
+log_note "Start ufsrestore in the background from the target device"
+log_note "$UFSRESTORE rbf 512 $rawdisk0"
+$UFSRESTORE rbf 512 $rawdisk0 &
+PIDUFSRESTORE=$!
+log_must cd $cwd
+
+log_note "Attempt to zpool the restored device in use by ufsrestore"
+log_mustnot $ZPOOL create -f $TESTPOOL2 "$disk1"
+log_mustnot poolexists $TESTPOOL2
+
+log_note "Attempt to take the restored device in use by ufsrestore as spare" \
+    "device"
+log_mustnot $ZPOOL create -f $TESTPOOL2 "$FS_SIDE2" spare "$disk1"
+log_mustnot poolexists $TESTPOOL2
+
+log_pass "Unable to zpool over a device in use by ufsdump or ufsrestore"
diff --git a/tests/zfs-tests/tests/functional/inuse/inuse_004_pos.ksh b/tests/zfs-tests/tests/functional/inuse/inuse_004_pos.ksh
new file mode 100755 (executable)
index 0000000..5dfbd7a
--- /dev/null
@@ -0,0 +1,94 @@
+#!/bin/ksh -p
+#
+# CDDL HEADER START
+#
+# The contents of this file are subject to the terms of the
+# Common Development and Distribution License (the "License").
+# You may not use this file except in compliance with the License.
+#
+# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
+# or http://www.opensolaris.org/os/licensing.
+# See the License for the specific language governing permissions
+# and limitations under the License.
+#
+# When distributing Covered Code, include this CDDL HEADER in each
+# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
+# If applicable, add the following below this CDDL HEADER, with the
+# fields enclosed by brackets "[]" replaced with your own identifying
+# information: Portions Copyright [yyyy] [name of copyright owner]
+#
+# CDDL HEADER END
+#
+
+#
+# Copyright 2009 Sun Microsystems, Inc.  All rights reserved.
+# Use is subject to license terms.
+#
+
+#
+# Copyright (c) 2013 by Delphix. All rights reserved.
+#
+
+. $STF_SUITE/include/libtest.shlib
+. $STF_SUITE/tests/functional/inuse/inuse.cfg
+
+#
+# DESCRIPTION:
+# format will disallow modification of a mounted zfs disk partition or a spare
+# device
+#
+# STRATEGY:
+# 1. Create a ZFS filesystem
+# 2. Add a spare device to the ZFS pool
+# 3. Attempt to format the disk and the spare device.
+#
+
+verify_runnable "global"
+
+function cleanup
+{
+       #
+       # Essentailly this is the default_cleanup rountine but I cannot get it
+       # to work correctly.  So its reproduced below.  Still need to full
+       # understand why default_cleanup does not work correctly from here.
+       #
+        log_must $ZFS umount $TESTPOOL/$TESTFS
+
+        $RM -rf $TESTDIR || \
+            log_unresolved Could not remove $TESTDIR
+
+       log_must $ZFS destroy $TESTPOOL/$TESTFS
+       destroy_pool $TESTPOOL
+}
+#
+# Currently, if a ZFS disk gets formatted things go horribly wrong, hence the
+# mini_format function.  If the modify option is reached, then we know format
+# would happily continue - best to not go further.
+#
+function mini_format
+{
+        typeset disk=$1
+
+       typeset format_file=/var/tmp/format_in.$$.1
+       $ECHO "partition" > $format_file
+       $ECHO "modify" >> $format_file
+
+       $FORMAT -e -s -d $disk -f $format_file
+       typeset -i retval=$?
+       $RM -rf $format_file
+       return $retval
+}
+
+log_assert "format will disallow modification of a mounted zfs disk partition"\
+ " or a spare device"
+
+log_onexit cleanup
+log_must default_setup_noexit $FS_DISK0
+log_must $ZPOOL add $TESTPOOL spare $FS_DISK1
+
+log_note "Attempt to format a ZFS disk"
+log_mustnot mini_format $FS_DISK0
+log_note "Attempt to format a ZFS spare device"
+log_mustnot mini_format $FS_DISK1
+
+log_pass "Unable to format a disk in use by ZFS"
diff --git a/tests/zfs-tests/tests/functional/inuse/inuse_005_pos.ksh b/tests/zfs-tests/tests/functional/inuse/inuse_005_pos.ksh
new file mode 100755 (executable)
index 0000000..dadb191
--- /dev/null
@@ -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) 2013 by Delphix. All rights reserved.
+#
+
+. $STF_SUITE/include/libtest.shlib
+. $STF_SUITE/tests/functional/inuse/inuse.cfg
+
+#
+# DESCRIPTION:
+# newfs will not interfere with devices and spare devices that are in use
+# by active pool.
+#
+# STRATEGY:
+# 1. Create a regular|mirror|raidz|raidz2 pool with the given disk
+# 2. Try to newfs against the disk, verify it fails as expect.
+#
+
+verify_runnable "global"
+
+function cleanup
+{
+       poolexists $TESTPOOL1 && destroy_pool $TESTPOOL1
+
+       #
+       # Tidy up the disks we used.
+       #
+       cleanup_devices $vdisks $sdisks
+}
+
+function verify_assertion #slices
+{
+       typeset targets=$1
+
+       for t in $targets; do
+               $ECHO "y" | $NEWFS -v $t > /dev/null 2>&1
+               (( $? !=0 )) || \
+                       log_fail "newfs over active pool " \
+                       "unexpected return code of 0"
+       done
+
+       return 0
+}
+
+log_assert "Verify newfs over active pool fails."
+
+log_onexit cleanup
+
+set -A vdevs "" "mirror" "raidz" "raidz1" "raidz2"
+
+typeset -i i=0
+
+while (( i < ${#vdevs[*]} )); do
+
+       for num in 0 1 2 3 ; do
+               eval typeset slice=\${FS_SIDE$num}
+               disk=${slice%${SLICE_PREFIX}*}
+               slice=${slice##*${SLICE_PREFIX}}
+               if [[ $WRAPPER == *"smi"* && \
+                       $disk == ${saved_disk} ]]; then
+                       cyl=$(get_endslice $disk ${saved_slice})
+                       log_must set_partition $slice "$cyl" $FS_SIZE $disk
+               else
+                       log_must set_partition $slice "" $FS_SIZE $disk
+               fi
+               saved_disk=$disk
+               saved_slice=$slice
+       done
+
+       if [[ -n $SINGLE_DISK && -n ${vdevs[i]} ]]; then
+               (( i = i + 1 ))
+               continue
+       fi
+
+       create_pool $TESTPOOL1 ${vdevs[i]} $vslices spare $sslices
+       verify_assertion "$rawtargets"
+       destroy_pool $TESTPOOL1
+
+       if [[ ( $FS_DISK0 == $FS_DISK2 ) && -n ${vdevs[i]} ]]; then
+               (( i = i + 1 ))
+               continue
+       fi
+
+       if [[ ( $FS_DISK0 == $FS_DISK3 ) && ( ${vdevs[i]} == "raidz2" ) ]]; then
+               (( i = i + 1 ))
+               continue
+       fi
+
+       create_pool $TESTPOOL1 ${vdevs[i]} $vdisks spare $sdisks
+       verify_assertion "$rawtargets"
+       destroy_pool $TESTPOOL1
+
+       (( i = i + 1 ))
+done
+
+log_pass "Newfs over active pool fails."
diff --git a/tests/zfs-tests/tests/functional/inuse/inuse_006_pos.ksh b/tests/zfs-tests/tests/functional/inuse/inuse_006_pos.ksh
new file mode 100755 (executable)
index 0000000..d79e318
--- /dev/null
@@ -0,0 +1,125 @@
+#!/bin/ksh -p
+#
+# CDDL HEADER START
+#
+# The contents of this file are subject to the terms of the
+# Common Development and Distribution License (the "License").
+# You may not use this file except in compliance with the License.
+#
+# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
+# or http://www.opensolaris.org/os/licensing.
+# See the License for the specific language governing permissions
+# and limitations under the License.
+#
+# When distributing Covered Code, include this CDDL HEADER in each
+# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
+# If applicable, add the following below this CDDL HEADER, with the
+# fields enclosed by brackets "[]" replaced with your own identifying
+# information: Portions Copyright [yyyy] [name of copyright owner]
+#
+# CDDL HEADER END
+#
+
+#
+# Copyright 2009 Sun Microsystems, Inc.  All rights reserved.
+# Use is subject to license terms.
+#
+
+#
+# Copyright (c) 2013 by Delphix. All rights reserved.
+#
+
+. $STF_SUITE/include/libtest.shlib
+. $STF_SUITE/tests/functional/inuse/inuse.cfg
+
+#
+# DESCRIPTION:
+# dumpadm will not interfere with devices and spare devices that are in use
+# by active pool.
+#
+# STRATEGY:
+# 1. Create a regular|mirror|raidz|raidz2 pool with the given disk
+# 2. Try to dumpadm against the disk, verify it fails as expect.
+#
+
+verify_runnable "global"
+
+function cleanup
+{
+       if [[ -n $PREVDUMPDEV ]]; then
+               log_must $DUMPADM -u -d $PREVDUMPDEV
+       fi
+
+       poolexists $TESTPOOL1 && destroy_pool $TESTPOOL1
+
+       #
+       # Tidy up the disks we used.
+       #
+       cleanup_devices $vdisks $sdisks
+}
+
+function verify_assertion #slices
+{
+       typeset targets=$1
+
+       for t in $targets; do
+               log_mustnot $DUMPADM -d $t
+       done
+
+        return 0
+}
+
+log_assert "Verify dumpadm over active pool fails."
+
+log_onexit cleanup
+
+set -A vdevs "" "mirror" "raidz" "raidz1" "raidz2"
+
+typeset -i i=0
+
+PREVDUMPDEV=`$DUMPADM | $GREP "Dump device" | $AWK '{print $3}'`
+
+while (( i < ${#vdevs[*]} )); do
+
+       for num in 0 1 2 3 ; do
+               eval typeset slice=\${FS_SIDE$num}
+               disk=${slice%${SLICE_PREFIX}*}
+               slice=${slice##*${SLICE_PREFIX}}
+               if [[ $WRAPPER == *"smi"* && \
+                       $disk == ${saved_disk} ]]; then
+                       cyl=$(get_endslice $disk ${saved_slice})
+                       log_must set_partition $slice "$cyl" $FS_SIZE $disk
+               else
+                       log_must set_partition $slice "" $FS_SIZE $disk
+               fi
+               saved_disk=$disk
+               saved_slice=$slice
+       done
+
+       if [[ -n $SINGLE_DISK && -n ${vdevs[i]} ]]; then
+               (( i = i + 1 ))
+               continue
+       fi
+
+       create_pool $TESTPOOL1 ${vdevs[i]} $vslices spare $sslices
+       verify_assertion "$disktargets"
+       destroy_pool $TESTPOOL1
+
+       if [[ ( $FS_DISK0 == $FS_DISK2 ) && -n ${vdevs[i]} ]]; then
+               (( i = i + 1 ))
+               continue
+       fi
+
+       if [[ ( $FS_DISK0 == $FS_DISK3 ) && ( ${vdevs[i]} == "raidz2" ) ]]; then
+               (( i = i + 1 ))
+               continue
+       fi
+
+       create_pool $TESTPOOL1 ${vdevs[i]} $vdisks spare $sdisks
+       verify_assertion "$disktargets"
+       destroy_pool $TESTPOOL1
+
+       (( i = i + 1 ))
+done
+
+log_pass "Dumpadm over active pool fails."
diff --git a/tests/zfs-tests/tests/functional/inuse/inuse_007_pos.ksh b/tests/zfs-tests/tests/functional/inuse/inuse_007_pos.ksh
new file mode 100755 (executable)
index 0000000..cb50689
--- /dev/null
@@ -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 2009 Sun Microsystems, Inc.  All rights reserved.
+# Use is subject to license terms.
+#
+
+#
+# Copyright (c) 2013 by Delphix. All rights reserved.
+#
+
+. $STF_SUITE/include/libtest.shlib
+. $STF_SUITE/tests/functional/inuse/inuse.cfg
+
+#
+# DESCRIPTION:
+# dumpadm will interfere with devices and spare devices that are in use
+# by exported pool.
+#
+# STRATEGY:
+# 1. Create a regular|mirror|raidz|raidz2 pool with the given disk
+# 2. Export the pool
+# 3. Try to dumpadm against the disk, verify it succeeds as expect.
+#
+
+verify_runnable "global"
+
+function cleanup
+{
+       if [[ -n $PREVDUMPDEV ]]; then
+               log_must $DUMPADM -u -d $PREVDUMPDEV
+       fi
+
+       poolexists $TESTPOOL1 || $ZPOOL import $TESTPOOL1 >/dev/null 2>&1
+
+       poolexists $TESTPOOL1 && destroy_pool $TESTPOOL1
+
+       #
+       # Tidy up the disks we used.
+       #
+       cleanup_devices $vdisks $sdisks
+}
+
+function verify_assertion #slices
+{
+       typeset targets=$1
+
+       for t in $targets; do
+               log_must $DUMPADM -u -d $t
+
+               log_must $DUMPADM -u -d $PREVDUMPDEV
+       done
+
+       return 0
+}
+
+log_assert "Verify dumpadm over exported pool succeed."
+
+log_onexit cleanup
+
+set -A vdevs "" "mirror" "raidz" "raidz1" "raidz2"
+
+typeset -i i=0
+
+PREVDUMPDEV=`$DUMPADM | $GREP "Dump device" | $AWK '{print $3}'`
+
+while (( i < ${#vdevs[*]} )); do
+
+       for num in 0 1 2 3 ; do
+               eval typeset slice=\${FS_SIDE$num}
+               disk=${slice%${SLICE_PREFIX}*}
+               slice=${slice##*${SLICE_PREFIX}}
+               if [[ $WRAPPER == *"smi"* && \
+                       $disk == ${saved_disk} ]]; then
+                       cyl=$(get_endslice $disk ${saved_slice})
+                       log_must set_partition $slice "$cyl" $FS_SIZE $disk
+               else
+                       log_must set_partition $slice "" $FS_SIZE $disk
+               fi
+               saved_disk=$disk
+               saved_slice=$slice
+       done
+
+       if [[ -n $SINGLE_DISK && -n ${vdevs[i]} ]]; then
+               (( i = i + 1 ))
+               continue
+       fi
+
+       create_pool $TESTPOOL1 ${vdevs[i]} $vslices spare $sslices
+       log_must $ZPOOL export $TESTPOOL1
+       verify_assertion "$disktargets"
+       log_must $ZPOOL import $TESTPOOL1
+       destroy_pool $TESTPOOL1
+
+       if [[ ( $FS_DISK0 == $FS_DISK2 ) && -n ${vdevs[i]} ]]; then
+               (( i = i + 1 ))
+               continue
+       fi
+
+       if [[ ( $FS_DISK0 == $FS_DISK3 ) && ( ${vdevs[i]} == "raidz2" ) ]]; then
+               (( i = i + 1 ))
+               continue
+       fi
+
+       create_pool $TESTPOOL1 ${vdevs[i]} $vdisks spare $sdisks
+       log_must $ZPOOL export $TESTPOOL1
+       verify_assertion "$disktargets"
+       log_must $ZPOOL import $TESTPOOL1
+       destroy_pool $TESTPOOL1
+
+       (( i = i + 1 ))
+done
+
+log_pass "Dumpadm over exported pool succeed."
diff --git a/tests/zfs-tests/tests/functional/inuse/inuse_008_pos.ksh b/tests/zfs-tests/tests/functional/inuse/inuse_008_pos.ksh
new file mode 100755 (executable)
index 0000000..80dad47
--- /dev/null
@@ -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) 2013 by Delphix. All rights reserved.
+#
+
+. $STF_SUITE/include/libtest.shlib
+. $STF_SUITE/tests/functional/inuse/inuse.cfg
+
+#
+# DESCRIPTION:
+# Newfs will interfere with devices and spare devices that are in use
+# by exported pool.
+#
+# STRATEGY:
+# 1. Create a regular|mirror|raidz|raidz2 pool with the given disk
+# 2. Export the pool
+# 3. Try to newfs against the disk, verify it succeeds as expect.
+#
+
+verify_runnable "global"
+
+function cleanup
+{
+       poolexists $TESTPOOL1 || $ZPOOL import $TESTPOOL1 >/dev/null 2>&1
+
+       poolexists $TESTPOOL1 && destroy_pool $TESTPOOL1
+
+       #
+       # Tidy up the disks we used.
+       #
+       cleanup_devices $vdisks $sdisks
+}
+
+function verify_assertion #slices
+{
+       typeset targets=$1
+
+       for t in $targets; do
+               $ECHO "y" | $NEWFS -v $t > /dev/null 2>&1
+               (( $? !=0 )) && \
+                       log_fail "newfs over exported pool " \
+                               "failes unexpected."
+       done
+
+       return 0
+}
+
+log_assert "Verify newfs over exported pool succeed."
+
+log_onexit cleanup
+
+set -A vdevs "" "mirror" "raidz" "raidz1" "raidz2"
+
+typeset -i i=0
+
+for num in 0 1 2 3 ; do
+       eval typeset slice=\${FS_SIDE$num}
+       disk=${slice%${SLICE_PREFIX}*}
+       slice=${slice##*${SLICE_PREFIX}}
+       if [[ $WRAPPER == *"smi"* && \
+               $disk == ${saved_disk} ]]; then
+               cyl=$(get_endslice $disk ${saved_slice})
+               log_must set_partition $slice "$cyl" $FS_SIZE $disk
+       else
+               log_must set_partition $slice "" $FS_SIZE $disk
+       fi
+       saved_disk=$disk
+       saved_slice=$slice
+done
+
+while (( i < ${#vdevs[*]} )); do
+       if [[ -n $SINGLE_DISK && -n ${vdevs[i]} ]]; then
+               (( i = i + 1 ))
+               continue
+       fi
+
+       create_pool $TESTPOOL1 ${vdevs[i]} $vslices spare $sslices
+       log_must $ZPOOL export $TESTPOOL1
+       verify_assertion "$rawtargets"
+       cleanup_devices $vslices $sslices
+
+       (( i = i + 1 ))
+done
+
+log_pass "Newfs over exported pool succeed."
diff --git a/tests/zfs-tests/tests/functional/inuse/inuse_009_pos.ksh b/tests/zfs-tests/tests/functional/inuse/inuse_009_pos.ksh
new file mode 100755 (executable)
index 0000000..a5b1fe2
--- /dev/null
@@ -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) 2013 by Delphix. All rights reserved.
+#
+
+. $STF_SUITE/include/libtest.shlib
+. $STF_SUITE/tests/functional/inuse/inuse.cfg
+
+#
+# DESCRIPTION:
+# format command will interfere with devices and spare devices that are in use
+# by exported pool.
+#
+# STRATEGY:
+# 1. Create a regular|mirror|raidz|raidz2 pool with the given disk
+# 2. Export the pool
+# 3. Try to format against the disk, verify it succeeds as expect.
+#
+
+verify_runnable "global"
+
+function cleanup
+{
+       poolexists $TESTPOOL1 || $ZPOOL import $TESTPOOL1 >/dev/null 2>&1
+
+       poolexists $TESTPOOL1 && destroy_pool $TESTPOOL1
+
+       #
+       # Tidy up the disks we used.
+       #
+       cleanup_devices $vdisks $sdisks
+}
+
+function verify_assertion #disks
+{
+       typeset targets=$1
+
+       for t in $targets; do
+               log_must set_partition 0 "" 0mb $t
+       done
+
+       return 0
+}
+
+log_assert "Verify format over exported pool succeed."
+
+log_onexit cleanup
+
+set -A vdevs "" "mirror" "raidz" "raidz1" "raidz2"
+
+typeset -i i=0
+
+while (( i < ${#vdevs[*]} )); do
+
+       for num in 0 1 2 3 ; do
+               eval typeset slice=\${FS_SIDE$num}
+               disk=${slice%${SLICE_PREFIX}*}
+               slice=${slice##*${SLICE_PREFIX}}
+               if [[ $WRAPPER == *"smi"* && \
+                       $disk == ${saved_disk} ]]; then
+                       cyl=$(get_endslice $disk ${saved_slice})
+                       log_must set_partition $slice "$cyl" $FS_SIZE $disk
+               else
+                       log_must set_partition $slice "" $FS_SIZE $disk
+               fi
+               saved_disk=$disk
+               saved_slice=$slice
+       done
+
+       if [[ -n $SINGLE_DISK && -n ${vdevs[i]} ]]; then
+               (( i = i + 1 ))
+               continue
+       fi
+
+       create_pool $TESTPOOL1 ${vdevs[i]} $vslices spare $sslices
+       log_must $ZPOOL export $TESTPOOL1
+       verify_assertion "$vdisks $sdisks"
+
+       if [[ ( $FS_DISK0 == $FS_DISK2 ) && -n ${vdevs[i]} ]]; then
+               (( i = i + 1 ))
+               continue
+       fi
+
+       if [[ ( $FS_DISK0 == $FS_DISK3 ) && ( ${vdevs[i]} == "raidz2" ) ]]; then
+               (( i = i + 1 ))
+               continue
+       fi
+
+       create_pool $TESTPOOL1 ${vdevs[i]} $vdisks spare $sdisks
+       log_must $ZPOOL export $TESTPOOL1
+       verify_assertion "$vdisks $sdisks"
+
+       (( i = i + 1 ))
+done
+
+log_pass "Format over exported pool succeed."
diff --git a/tests/zfs-tests/tests/functional/inuse/setup.ksh b/tests/zfs-tests/tests/functional/inuse/setup.ksh
new file mode 100755 (executable)
index 0000000..962a0c9
--- /dev/null
@@ -0,0 +1,36 @@
+#!/bin/ksh -p
+#
+# CDDL HEADER START
+#
+# The contents of this file are subject to the terms of the
+# Common Development and Distribution License (the "License").
+# You may not use this file except in compliance with the License.
+#
+# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
+# or http://www.opensolaris.org/os/licensing.
+# See the License for the specific language governing permissions
+# and limitations under the License.
+#
+# When distributing Covered Code, include this CDDL HEADER in each
+# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
+# If applicable, add the following below this CDDL HEADER, with the
+# fields enclosed by brackets "[]" replaced with your own identifying
+# information: Portions Copyright [yyyy] [name of copyright owner]
+#
+# CDDL HEADER END
+#
+
+#
+# Copyright 2008 Sun Microsystems, Inc.  All rights reserved.
+# Use is subject to license terms.
+#
+
+#
+# Copyright (c) 2013 by Delphix. All rights reserved.
+#
+
+. $STF_SUITE/include/libtest.shlib
+
+verify_runnable "global"
+
+log_pass
diff --git a/tests/zfs-tests/tests/functional/large_files/Makefile.am b/tests/zfs-tests/tests/functional/large_files/Makefile.am
new file mode 100644 (file)
index 0000000..d78ea47
--- /dev/null
@@ -0,0 +1,5 @@
+pkgdatadir = $(datadir)/@PACKAGE@/zfs-tests/tests/functional/large_files
+dist_pkgdata_SCRIPTS = \
+       setup.ksh \
+       cleanup.ksh \
+       large_files_001_pos.ksh
diff --git a/tests/zfs-tests/tests/functional/large_files/cleanup.ksh b/tests/zfs-tests/tests/functional/large_files/cleanup.ksh
new file mode 100755 (executable)
index 0000000..3166bd6
--- /dev/null
@@ -0,0 +1,34 @@
+#!/bin/ksh -p
+#
+# CDDL HEADER START
+#
+# The contents of this file are subject to the terms of the
+# Common Development and Distribution License (the "License").
+# You may not use this file except in compliance with the License.
+#
+# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
+# or http://www.opensolaris.org/os/licensing.
+# See the License for the specific language governing permissions
+# and limitations under the License.
+#
+# When distributing Covered Code, include this CDDL HEADER in each
+# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
+# If applicable, add the following below this CDDL HEADER, with the
+# fields enclosed by brackets "[]" replaced with your own identifying
+# information: Portions Copyright [yyyy] [name of copyright owner]
+#
+# CDDL HEADER END
+#
+
+#
+# Copyright 2007 Sun Microsystems, Inc.  All rights reserved.
+# Use is subject to license terms.
+#
+
+#
+# Copyright (c) 2013 by Delphix. All rights reserved.
+#
+
+. $STF_SUITE/include/libtest.shlib
+
+default_cleanup
diff --git a/tests/zfs-tests/tests/functional/large_files/large_files_001_pos.ksh b/tests/zfs-tests/tests/functional/large_files/large_files_001_pos.ksh
new file mode 100755 (executable)
index 0000000..b973d6e
--- /dev/null
@@ -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) 2013 by Delphix. All rights reserved.
+#
+
+. $STF_SUITE/include/libtest.shlib
+
+#
+# DESCRIPTION:
+# Write a file to the allowable ZFS fs size.
+#
+# STRATEGY:
+# 1. largest_file will write to a file and increase its size
+# to the maximum allowable.
+# 2. The last byte of the file should be accessbile without error.
+# 3. Writing beyond the maximum file size generates an 'errno' of
+# EFBIG.
+#
+
+verify_runnable "both"
+
+log_assert "Write a file to the allowable ZFS fs size."
+
+log_note "Invoke 'largest_file' with $TESTDIR/bigfile"
+log_must $LARGEST_FILE $TESTDIR/bigfile
+
+log_pass "Successfully created a file to the maximum allowable size."
diff --git a/tests/zfs-tests/tests/functional/large_files/setup.ksh b/tests/zfs-tests/tests/functional/large_files/setup.ksh
new file mode 100755 (executable)
index 0000000..3a45ec8
--- /dev/null
@@ -0,0 +1,36 @@
+#!/bin/ksh -p
+#
+# CDDL HEADER START
+#
+# The contents of this file are subject to the terms of the
+# Common Development and Distribution License (the "License").
+# You may not use this file except in compliance with the License.
+#
+# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
+# or http://www.opensolaris.org/os/licensing.
+# See the License for the specific language governing permissions
+# and limitations under the License.
+#
+# When distributing Covered Code, include this CDDL HEADER in each
+# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
+# If applicable, add the following below this CDDL HEADER, with the
+# fields enclosed by brackets "[]" replaced with your own identifying
+# information: Portions Copyright [yyyy] [name of copyright owner]
+#
+# CDDL HEADER END
+#
+
+#
+# Copyright 2007 Sun Microsystems, Inc.  All rights reserved.
+# Use is subject to license terms.
+#
+
+#
+# Copyright (c) 2013 by Delphix. All rights reserved.
+#
+
+. $STF_SUITE/include/libtest.shlib
+
+disk=${DISKS%% *}
+
+default_setup $disk
diff --git a/tests/zfs-tests/tests/functional/largest_pool/Makefile.am b/tests/zfs-tests/tests/functional/largest_pool/Makefile.am
new file mode 100644 (file)
index 0000000..474a15a
--- /dev/null
@@ -0,0 +1,4 @@
+pkgdatadir = $(datadir)/@PACKAGE@/zfs-tests/tests/functional/largest_pool
+dist_pkgdata_SCRIPTS = \
+       largest_pool.cfg \
+       largest_pool_001_pos.ksh
diff --git a/tests/zfs-tests/tests/functional/largest_pool/largest_pool.cfg b/tests/zfs-tests/tests/functional/largest_pool/largest_pool.cfg
new file mode 100644 (file)
index 0000000..bcb93d4
--- /dev/null
@@ -0,0 +1,43 @@
+#
+# CDDL HEADER START
+#
+# The contents of this file are subject to the terms of the
+# Common Development and Distribution License (the "License").
+# You may not use this file except in compliance with the License.
+#
+# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
+# or http://www.opensolaris.org/os/licensing.
+# See the License for the specific language governing permissions
+# and limitations under the License.
+#
+# When distributing Covered Code, include this CDDL HEADER in each
+# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
+# If applicable, add the following below this CDDL HEADER, with the
+# fields enclosed by brackets "[]" replaced with your own identifying
+# information: Portions Copyright [yyyy] [name of copyright owner]
+#
+# CDDL HEADER END
+#
+
+#
+# Copyright 2008 Sun Microsystems, Inc.  All rights reserved.
+# Use is subject to license terms.
+#
+
+#
+# Copyright (c) 2013 by Delphix. All rights reserved.
+#
+
+export TESTVOL=testvol$$
+export VOL_PATH=${ZVOL_DEVDIR}/${TESTPOOL2}/$TESTVOL
+export VOLSIZES=${VOLSIZES-"2pb 5pb 10pb 2eb 5eb 8eb 9eb"}
+
+# There're 3 different prompt messages while create
+# a volume that great than 1TB on 32-bit
+#       - volume size exceeds limit for this system. (happy gate)
+#       - max volume size is 1TB on 32-bit systems (s10u2)
+#       - value is too large (old)
+
+export VOL_LIMIT_KEYWORD1="1TB on 32-bit"
+export VOL_LIMIT_KEYWORD2="value is too large"
+export VOL_LIMIT_KEYWORD3="volume size exceeds limit"
diff --git a/tests/zfs-tests/tests/functional/largest_pool/largest_pool_001_pos.ksh b/tests/zfs-tests/tests/functional/largest_pool/largest_pool_001_pos.ksh
new file mode 100755 (executable)
index 0000000..8ca4d9d
--- /dev/null
@@ -0,0 +1,160 @@
+#!/bin/ksh -p
+#
+# CDDL HEADER START
+#
+# The contents of this file are subject to the terms of the
+# Common Development and Distribution License (the "License").
+# You may not use this file except in compliance with the License.
+#
+# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
+# or http://www.opensolaris.org/os/licensing.
+# See the License for the specific language governing permissions
+# and limitations under the License.
+#
+# When distributing Covered Code, include this CDDL HEADER in each
+# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
+# If applicable, add the following below this CDDL HEADER, with the
+# fields enclosed by brackets "[]" replaced with your own identifying
+# information: Portions Copyright [yyyy] [name of copyright owner]
+#
+# CDDL HEADER END
+#
+
+#
+# Copyright 2009 Sun Microsystems, Inc.  All rights reserved.
+# Use is subject to license terms.
+#
+
+#
+# Copyright (c) 2013 by Delphix. All rights reserved.
+#
+
+. $STF_SUITE/include/libtest.shlib
+. $STF_SUITE/tests/functional/largest_pool/largest_pool.cfg
+
+# DESCRIPTION:
+#      The largest pool can be created and a dataset in that
+#      pool can be created and mounted.
+#
+# STRATEGY:
+#      create a pool which will contain a volume device.
+#      create a volume device of desired sizes.
+#      create the largest pool allowed using the volume vdev.
+#      create and mount a dataset in the largest pool.
+#      create some files in the zfs file system.
+#      do some zpool list commands and parse the output.
+
+verify_runnable "global"
+
+#
+# Parse the results of zpool & zfs creation with specified size
+#
+# $1: volume size
+#
+# return value:
+# 0 -> success
+# 1 -> failure
+#
+function parse_expected_output
+{
+       UNITS=`$ECHO $1 | $SED -e 's/^\([0-9].*\)\([a-z].\)/\2/'`
+       case "$UNITS" in
+               'mb') CHKUNIT="M" ;;
+               'gb') CHKUNIT="G" ;;
+               'tb') CHKUNIT="T" ;;
+               'pb') CHKUNIT="P" ;;
+               'eb') CHKUNIT="E" ;;
+               *) CHKUNIT="M" ;;
+       esac
+
+       log_note "Detect zpool $TESTPOOL in this test machine."
+       log_must eval "$ZPOOL list $TESTPOOL > /tmp/j.$$"
+       log_must eval "$GREP $TESTPOOL /tmp/j.$$ | \
+               $AWK '{print $2}' | $GREP $CHKUNIT"
+
+       log_note "Detect the file system in this test machine."
+       log_must eval "$DF -F zfs -h > /tmp/j.$$"
+       log_must eval "$GREP $TESTPOOL /tmp/j.$$ | \
+               $AWK '{print $2}' | $GREP $CHKUNIT"
+
+       return 0
+}
+
+#
+# Check and destroy zfs, volume & zpool remove the temporary files
+#
+function cleanup
+{
+       log_note "Start cleanup the zfs and pool"
+
+       if datasetexists $TESTPOOL/$TESTFS ; then
+               if ismounted $TESTPOOL/$TESTFS ; then
+                       log_must $ZFS unmount $TESTPOOL/$TESTFS
+               fi
+               log_must $ZFS destroy $TESTPOOL/$TESTFS
+       fi
+
+       destroy_pool $TESTPOOL
+
+       datasetexists $TESTPOOL2/$TESTVOL && \
+               log_must $ZFS destroy $TESTPOOL2/$TESTVOL
+
+       destroy_pool $TESTPOOL2
+
+       $RM -f /tmp/j.* > /dev/null
+}
+
+log_assert "The largest pool can be created and a dataset in that" \
+       "pool can be created and mounted."
+
+# Set trigger. When the test case exit, cleanup is executed.
+log_onexit cleanup
+
+# -----------------------------------------------------------------------
+# volume sizes with unit designations.
+#
+# Note: specifying the number '1' as size will not give the correct
+# units for 'df'.  It must be greater than one.
+# -----------------------------------------------------------------------
+typeset str
+typeset -i ret
+for volsize in $VOLSIZES; do
+       log_note "Create a pool which will contain a volume device"
+       create_pool $TESTPOOL2 "$DISKS"
+
+       log_note "Create a volume device of desired sizes: $volsize"
+       str=$($ZFS create -sV $volsize $TESTPOOL2/$TESTVOL 2>&1)
+       ret=$?
+       if (( ret != 0 )); then
+               if [[ $($ISAINFO -b) == 32 && \
+                       $str == *${VOL_LIMIT_KEYWORD1}* || \
+                       $str == *${VOL_LIMIT_KEYWORD2}* || \
+                       $str == *${VOL_LIMIT_KEYWORD3}* ]]
+               then
+                       log_unsupported \
+                               "Max volume size is 1TB on 32-bit systems."
+               else
+                       log_fail "$ZFS create -sV $volsize $TESTPOOL2/$TESTVOL"
+               fi
+       fi
+
+       log_note "Create the largest pool allowed using the volume vdev"
+       create_pool $TESTPOOL "$VOL_PATH"
+
+       log_note "Create a zfs file system in the largest pool"
+       log_must $ZFS create $TESTPOOL/$TESTFS
+
+       log_note "Parse the execution result"
+       parse_expected_output $volsize
+
+       log_note "unmount this zfs file system $TESTPOOL/$TESTFS"
+       log_must $ZFS unmount $TESTPOOL/$TESTFS
+
+       log_note "Destroy zfs, volume & zpool"
+       log_must $ZFS destroy $TESTPOOL/$TESTFS
+       destroy_pool $TESTPOOL
+       log_must $ZFS destroy $TESTPOOL2/$TESTVOL
+       destroy_pool $TESTPOOL2
+done
+
+log_pass "Dateset can be created, mounted & destroy in largest pool succeeded."
diff --git a/tests/zfs-tests/tests/functional/link_count/Makefile.am b/tests/zfs-tests/tests/functional/link_count/Makefile.am
new file mode 100644 (file)
index 0000000..669f3c1
--- /dev/null
@@ -0,0 +1,5 @@
+pkgdatadir = $(datadir)/@PACKAGE@/zfs-tests/tests/functional/link_count
+dist_pkgdata_SCRIPTS = \
+       cleanup.ksh \
+       setup.ksh \
+       link_count_001.ksh
diff --git a/tests/zfs-tests/tests/functional/link_count/cleanup.ksh b/tests/zfs-tests/tests/functional/link_count/cleanup.ksh
new file mode 100755 (executable)
index 0000000..3166bd6
--- /dev/null
@@ -0,0 +1,34 @@
+#!/bin/ksh -p
+#
+# CDDL HEADER START
+#
+# The contents of this file are subject to the terms of the
+# Common Development and Distribution License (the "License").
+# You may not use this file except in compliance with the License.
+#
+# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
+# or http://www.opensolaris.org/os/licensing.
+# See the License for the specific language governing permissions
+# and limitations under the License.
+#
+# When distributing Covered Code, include this CDDL HEADER in each
+# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
+# If applicable, add the following below this CDDL HEADER, with the
+# fields enclosed by brackets "[]" replaced with your own identifying
+# information: Portions Copyright [yyyy] [name of copyright owner]
+#
+# CDDL HEADER END
+#
+
+#
+# Copyright 2007 Sun Microsystems, Inc.  All rights reserved.
+# Use is subject to license terms.
+#
+
+#
+# Copyright (c) 2013 by Delphix. All rights reserved.
+#
+
+. $STF_SUITE/include/libtest.shlib
+
+default_cleanup
diff --git a/tests/zfs-tests/tests/functional/link_count/link_count_001.ksh b/tests/zfs-tests/tests/functional/link_count/link_count_001.ksh
new file mode 100755 (executable)
index 0000000..53e89ae
--- /dev/null
@@ -0,0 +1,89 @@
+#!/bin/ksh -p
+#
+# CDDL HEADER START
+#
+# The contents of this file are subject to the terms of the
+# Common Development and Distribution License (the "License").
+# You may not use this file except in compliance with the License.
+#
+# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
+# or http://www.opensolaris.org/os/licensing.
+# See the License for the specific language governing permissions
+# and limitations under the License.
+#
+# When distributing Covered Code, include this CDDL HEADER in each
+# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
+# If applicable, add the following below this CDDL HEADER, with the
+# fields enclosed by brackets "[]" replaced with your own identifying
+# information: Portions Copyright [yyyy] [name of copyright owner]
+#
+# CDDL HEADER END
+#
+
+#
+# Copyright 2007 Sun Microsystems, Inc.  All rights reserved.
+# Use is subject to license terms.
+#
+
+#
+# Copyright (c) 2013 by Delphix. All rights reserved.
+#
+
+. $STF_SUITE/include/libtest.shlib
+
+#
+# DESCRIPTION:
+# Verify file link count is zero on zfs
+#
+# STRATEGY:
+# 1. Make sure this test executes on multi-processes system
+# 2. Make zero size files and remove them in the background
+# 3. Call the binary
+# 4. Make sure the files can be removed successfully
+#
+
+verify_runnable "both"
+
+log_assert "Verify file link count is zero on zfs"
+
+export ITERS=10
+export NUMFILES=10000
+
+# Detect and make sure this test must be executed on a multi-process system
+is_mp || log_fail "This test requires a multi-processor system."
+
+log_must $MKDIR -p ${TESTDIR}/tmp
+
+typeset -i i=0
+while [ $i -lt $NUMFILES ]; do
+        (( i = i + 1 ))
+        $TOUCH ${TESTDIR}/tmp/x$i > /dev/null 2>&1
+done
+
+sleep 3
+
+$RM -f ${TESTDIR}/tmp/x* >/dev/null 2>&1
+
+$RM_LNKCNT_ZERO_FILE ${TESTDIR}/tmp/test$$ > /dev/null 2>&1 &
+PID=$!
+log_note "$RM_LNKCNT_ZERO_FILE ${TESTDIR}/tmp/test$$ pid: $PID"
+
+i=0
+while [ $i -lt $ITERS ]; do
+       if ! $PGREP $RM_LNKCNT_ZERO_FILE > /dev/null ; then
+               log_note "$RM_LNKCNT_ZERO_FILE completes"
+               break
+       fi
+       log_must $SLEEP 10
+       (( i = i + 1 ))
+done
+
+if $PGREP $RM_LNKCNT_ZERO_FILE > /dev/null; then
+       log_must $KILL -TERM $PID
+       log_fail "file link count is zero"
+fi
+
+log_must $KILL -TERM $PID
+log_must $RM -f ${TESTDIR}/tmp/test$$*
+
+log_pass "Verify file link count is zero on zfs"
diff --git a/tests/zfs-tests/tests/functional/link_count/setup.ksh b/tests/zfs-tests/tests/functional/link_count/setup.ksh
new file mode 100755 (executable)
index 0000000..d275e06
--- /dev/null
@@ -0,0 +1,36 @@
+#!/bin/ksh -p
+#
+# CDDL HEADER START
+#
+# The contents of this file are subject to the terms of the
+# Common Development and Distribution License (the "License").
+# You may not use this file except in compliance with the License.
+#
+# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
+# or http://www.opensolaris.org/os/licensing.
+# See the License for the specific language governing permissions
+# and limitations under the License.
+#
+# When distributing Covered Code, include this CDDL HEADER in each
+# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
+# If applicable, add the following below this CDDL HEADER, with the
+# fields enclosed by brackets "[]" replaced with your own identifying
+# information: Portions Copyright [yyyy] [name of copyright owner]
+#
+# CDDL HEADER END
+#
+
+#
+# Copyright 2007 Sun Microsystems, Inc.  All rights reserved.
+# Use is subject to license terms.
+#
+
+#
+# Copyright (c) 2013 by Delphix. All rights reserved.
+#
+
+. $STF_SUITE/include/libtest.shlib
+
+DISK=${DISKS%% *}
+
+default_setup $DISK
diff --git a/tests/zfs-tests/tests/functional/migration/Makefile.am b/tests/zfs-tests/tests/functional/migration/Makefile.am
new file mode 100644 (file)
index 0000000..53fb30b
--- /dev/null
@@ -0,0 +1,18 @@
+pkgdatadir = $(datadir)/@PACKAGE@/zfs-tests/tests/functional/migration
+dist_pkgdata_SCRIPTS = \
+       migration.cfg \
+       migration.kshlib \
+       setup.ksh \
+       cleanup.ksh \
+       migration_001_pos.ksh \
+       migration_002_pos.ksh \
+       migration_003_pos.ksh \
+       migration_004_pos.ksh \
+       migration_005_pos.ksh \
+       migration_006_pos.ksh \
+       migration_007_pos.ksh \
+       migration_008_pos.ksh \
+       migration_009_pos.ksh \
+       migration_010_pos.ksh \
+       migration_011_pos.ksh \
+       migration_012_pos.ksh
diff --git a/tests/zfs-tests/tests/functional/migration/cleanup.ksh b/tests/zfs-tests/tests/functional/migration/cleanup.ksh
new file mode 100755 (executable)
index 0000000..1b146a7
--- /dev/null
@@ -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 2008 Sun Microsystems, Inc.  All rights reserved.
+# Use is subject to license terms.
+#
+
+#
+# Copyright (c) 2013 by Delphix. All rights reserved.
+#
+
+. $STF_SUITE/include/libtest.shlib
+. $STF_SUITE/tests/functional/migration/migration.cfg
+
+verify_runnable "global"
+
+ismounted $NONZFS_TESTDIR $NEWFS_DEFAULT_FS
+(( $? == 0 )) && log_must $UMOUNT -f $NONZFS_TESTDIR
+
+ismounted $TESTPOOL/$TESTFS
+[[ $? == 0 ]] && log_must $ZFS umount -f $TESTDIR
+destroy_pool $TESTPOOL
+
+# recreate and destroy a zpool over the disks to restore the partitions to
+# normal
+case $DISK_COUNT in
+0)
+       log_note "No disk devices to restore"
+       ;;
+1)
+       log_must cleanup_devices $ZFS_DISK
+       ;;
+*)
+       log_must cleanup_devices $ZFS_DISK $NONZFS_DISK
+       ;;
+esac
+
+log_pass
diff --git a/tests/zfs-tests/tests/functional/migration/migration.cfg b/tests/zfs-tests/tests/functional/migration/migration.cfg
new file mode 100644 (file)
index 0000000..ddae25d
--- /dev/null
@@ -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 2008 Sun Microsystems, Inc.  All rights reserved.
+# Use is subject to license terms.
+#
+
+#
+# Copyright (c) 2013 by Delphix. All rights reserved.
+#
+
+. $STF_SUITE/include/libtest.shlib
+
+set -A disk_array $(find_disks $DISKS)
+case "${#disk_array[*]}" in
+0)
+       DISK_COUNT=0
+       ;;
+1)
+       # We need to repartition the single disk to two slices.
+       DISK_COUNT=1
+       ZFS_DISK=${disk_array[0]}
+       SINGLE_DISK=$ZFS_DISK
+       NONZFS_DISK=$ZFS_DISK
+       if is_linux; then
+               ZFSSIDE_DISK=${SINGLE_DISK}p1
+               NONZFSSIDE_DISK=${SINGLE_DISK}p2
+       else
+               ZFSSIDE_DISK=${SINGLE_DISK}s0
+               NONZFSSIDE_DISK=${SINGLE_DISK}s1
+       fi
+       ;;
+*)
+       # In this case there are at least enough disks to use.
+       DISK_COUNT=2
+       ZFS_DISK=${disk_array[0]}
+       NONZFS_DISK=${disk_array[1]}
+       if is_linux; then
+               ZFSSIDE_DISK=${ZFS_DISK}p1
+               NONZFSSIDE_DISK=${NONZFS_DISK}p1
+       else
+               ZFSSIDE_DISK=${ZFS_DISK}s0
+               NONZFSSIDE_DISK=${NONZFS_DISK}s0
+       fi
+       ;;
+esac
+
+export DISK_COUNT ZFS_DISK NONZFS_DISK SINGLE_DISK ZFSSIDE_DISK NONZFSSIDE_DISK
+
+export TESTFILE=/etc/passwd
+export NONZFS_TESTDIR=$TESTDIR/nonzfstestdir
+tmp=`$SUM $TESTFILE`
+export SUMA=`$ECHO $tmp | $AWK '{print $1}'`
+export SUMB=`$ECHO $tmp | $AWK '{print $2}'`
+export FS_SIZE=1g
+export BNAME=`$BASENAME $TESTFILE`
+export DNAME=`$DIRNAME $TESTFILE`
diff --git a/tests/zfs-tests/tests/functional/migration/migration.kshlib b/tests/zfs-tests/tests/functional/migration/migration.kshlib
new file mode 100644 (file)
index 0000000..e0799af
--- /dev/null
@@ -0,0 +1,153 @@
+#
+# CDDL HEADER START
+#
+# The contents of this file are subject to the terms of the
+# Common Development and Distribution License (the "License").
+# You may not use this file except in compliance with the License.
+#
+# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
+# or http://www.opensolaris.org/os/licensing.
+# See the License for the specific language governing permissions
+# and limitations under the License.
+#
+# When distributing Covered Code, include this CDDL HEADER in each
+# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
+# If applicable, add the following below this CDDL HEADER, with the
+# fields enclosed by brackets "[]" replaced with your own identifying
+# information: Portions Copyright [yyyy] [name of copyright owner]
+#
+# CDDL HEADER END
+#
+
+#
+# Copyright 2007 Sun Microsystems, Inc.  All rights reserved.
+# Use is subject to license terms.
+#
+
+#
+# Copyright (c) 2013 by Delphix. All rights reserved.
+#
+
+. $STF_SUITE/tests/functional/migration/migration.cfg
+
+#
+# This function creates the test archive for migration.
+#
+# Usage:
+# prepare srcdir cmd
+#
+# Return value: 0 on success
+#              1 on failure
+#
+# Where:
+#      srcdir: is the directory where the testfile is
+#      cmd:    is the command to be executed.
+#              E.g.
+#              $TAR cf $TESTDIR/tar$$.tar
+#
+function prepare #srcdir cmd
+{
+       typeset srcdir=$1
+       typeset cmd=$2
+       typeset -i retval=0
+
+       cwd=$PWD
+       cd $srcdir
+       (( $? != 0 )) && return 1
+
+       $cmd
+       (( $? != 0 )) && return 1
+
+       cd $cwd
+       (( $? != 0 )) && return 1
+
+       return 0
+}
+
+#
+# This function executes a passed in command and then determines the chksum
+# of the resulting file.  The chksum components are checked against the ones
+# passed in to determine if they are equal.  If they are equal, 0 is returned
+# otherwise 1 is returned.
+#
+# Usage:
+# migrate destdir oldsuma oldsumb command_to_execute
+#
+# Return value: 0 on success
+#              1 on failure
+#
+# Where:
+#      destdir: is the directory where the command is to be executed on
+#      oldsuma: is the first part of the values returned by sum
+#      oldsumb: is the second part of the values returned by sum
+#      cmd: is the command to be executed;
+#              E.g.
+#              "$TAR xf $TESTDIR/tar$$.tar"
+#
+function migrate #destdir oldsuma oldsumb cmd
+{
+       typeset destdir=$1
+       typeset oldsuma=$2
+       typeset oldsumb=$3
+       typeset cmd=$4
+       typeset -i retval=0
+
+       cwd=$PWD
+       cd $destdir
+       (( $? != 0 )) && return 1
+
+       $cmd
+       (( $? != 0 )) && return 1
+
+       sumy=`$SUM ./$BNAME`
+       suma=`$ECHO $sumy | $AWK '{print $1}'`
+       sumb=`$ECHO $sumy | $AWK '{print $2}'`
+
+       if (( $oldsuma != $suma )); then
+               log_note "$SUM values are not the same"
+               retval=1
+       fi
+
+       if (( $oldsumb != $sumb )); then
+               log_note "$SUM values are not the same"
+               retval=1
+       fi
+
+       cd $cwd
+       (( $? != 0 )) && return 1
+       return $retval
+}
+
+function migrate_cpio
+{
+       typeset destdir=$1
+       typeset archive=$2
+       typeset oldsuma=$3
+       typeset oldsumb=$4
+       typeset -i retval=0
+
+       cwd=$PWD
+       cd $destdir
+       (( $? != 0 )) && return 1
+
+       $CPIO -iv < $archive
+       (( $? != 0 )) && return 1
+
+       sumy=`$SUM ./$BNAME`
+       suma=`$ECHO $sumy | $AWK '{print $1}'`
+       sumb=`$ECHO $sumy | $AWK '{print $2}'`
+
+       if (( $oldsuma != $suma )); then
+               log_note "$SUM values are not the same"
+               retval=1
+       fi
+
+       if (( $oldsumb != $sumb )); then
+               log_note "$SUM values are not the same"
+               retval=1
+       fi
+
+       cd $cwd
+       (( $? != 0 )) && return 1
+       return $retval
+}
diff --git a/tests/zfs-tests/tests/functional/migration/migration_001_pos.ksh b/tests/zfs-tests/tests/functional/migration/migration_001_pos.ksh
new file mode 100755 (executable)
index 0000000..5286461
--- /dev/null
@@ -0,0 +1,66 @@
+#!/bin/ksh -p
+#
+# CDDL HEADER START
+#
+# The contents of this file are subject to the terms of the
+# Common Development and Distribution License (the "License").
+# You may not use this file except in compliance with the License.
+#
+# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
+# or http://www.opensolaris.org/os/licensing.
+# See the License for the specific language governing permissions
+# and limitations under the License.
+#
+# When distributing Covered Code, include this CDDL HEADER in each
+# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
+# If applicable, add the following below this CDDL HEADER, with the
+# fields enclosed by brackets "[]" replaced with your own identifying
+# information: Portions Copyright [yyyy] [name of copyright owner]
+#
+# CDDL HEADER END
+#
+
+#
+# Copyright 2007 Sun Microsystems, Inc.  All rights reserved.
+# Use is subject to license terms.
+#
+
+#
+# Copyright (c) 2013 by Delphix. All rights reserved.
+#
+
+. $STF_SUITE/include/libtest.shlib
+. $STF_SUITE/tests/functional/migration/migration.kshlib
+
+#
+# DESCRIPTION:
+# Migrating test file from ZFS fs to ZFS fs using tar.
+#
+# STRATEGY:
+# 1. Calculate chksum of testfile
+# 2. Tar up test file and place on a ZFS filesystem
+# 3. Extract tar contents to a ZFS file system
+# 4. Calculate chksum of extracted file
+# 5. Compare old and new chksums.
+#
+
+verify_runnable "both"
+
+function cleanup
+{
+       $RM -rf $TESTDIR/tar$$.tar
+       $RM -rf $TESTDIR/$BNAME
+}
+
+log_assert "Migrating test file from ZFS fs to ZFS fs using tar"
+
+log_onexit cleanup
+
+prepare $DNAME "$TAR cf $TESTDIR/tar$$.tar $BNAME"
+(( $? != 0 )) && log_fail "Unable to create src archive"
+
+migrate $TESTDIR $SUMA $SUMB "$TAR xf $TESTDIR/tar$$.tar"
+(( $? != 0 )) && log_fail "Uable to successfully migrate test file from" \
+    "ZFS fs to ZFS fs"
+
+log_pass "Successully migrated test file from ZFS fs to ZFS fs".
diff --git a/tests/zfs-tests/tests/functional/migration/migration_002_pos.ksh b/tests/zfs-tests/tests/functional/migration/migration_002_pos.ksh
new file mode 100755 (executable)
index 0000000..54fbc04
--- /dev/null
@@ -0,0 +1,66 @@
+#!/bin/ksh -p
+#
+# CDDL HEADER START
+#
+# The contents of this file are subject to the terms of the
+# Common Development and Distribution License (the "License").
+# You may not use this file except in compliance with the License.
+#
+# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
+# or http://www.opensolaris.org/os/licensing.
+# See the License for the specific language governing permissions
+# and limitations under the License.
+#
+# When distributing Covered Code, include this CDDL HEADER in each
+# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
+# If applicable, add the following below this CDDL HEADER, with the
+# fields enclosed by brackets "[]" replaced with your own identifying
+# information: Portions Copyright [yyyy] [name of copyright owner]
+#
+# CDDL HEADER END
+#
+
+#
+# Copyright 2007 Sun Microsystems, Inc.  All rights reserved.
+# Use is subject to license terms.
+#
+
+#
+# Copyright (c) 2013 by Delphix. All rights reserved.
+#
+
+. $STF_SUITE/include/libtest.shlib
+. $STF_SUITE/tests/functional/migration/migration.kshlib
+
+#
+# DESCRIPTION:
+# Migrating test file from ZFS fs to UFS fs using tar.
+#
+# STRATEGY:
+# 1. Calculate chksum of testfile
+# 2. Tar up test file and place on a ZFS filesystem
+# 3. Extract tar contents to a UFS file system
+# 4. Calculate chksum of extracted file
+# 5. Compare old and new chksums.
+#
+
+verify_runnable "both"
+
+function cleanup
+{
+       $RM -rf $TESTDIR/tar$$.tar
+       $RM -rf $NONZFS_TESTDIR/$BNAME
+}
+
+log_assert "Migrating test file from ZFS fs to UFS fs using tar"
+
+log_onexit cleanup
+
+prepare $DNAME "$TAR cf $TESTDIR/tar$$.tar $BNAME"
+(( $? != 0 )) && log_fail "Unable to create src archive"
+
+migrate $NONZFS_TESTDIR $SUMA $SUMB "$TAR xf $TESTDIR/tar$$.tar"
+(( $? != 0 )) && log_fail "Uable to successfully migrate test file from" \
+    "ZFS fs to UFS fs"
+
+log_pass "Successully migrated test file from ZFS fs to UFS fs".
diff --git a/tests/zfs-tests/tests/functional/migration/migration_003_pos.ksh b/tests/zfs-tests/tests/functional/migration/migration_003_pos.ksh
new file mode 100755 (executable)
index 0000000..c8d67c1
--- /dev/null
@@ -0,0 +1,66 @@
+#!/bin/ksh -p
+#
+# CDDL HEADER START
+#
+# The contents of this file are subject to the terms of the
+# Common Development and Distribution License (the "License").
+# You may not use this file except in compliance with the License.
+#
+# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
+# or http://www.opensolaris.org/os/licensing.
+# See the License for the specific language governing permissions
+# and limitations under the License.
+#
+# When distributing Covered Code, include this CDDL HEADER in each
+# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
+# If applicable, add the following below this CDDL HEADER, with the
+# fields enclosed by brackets "[]" replaced with your own identifying
+# information: Portions Copyright [yyyy] [name of copyright owner]
+#
+# CDDL HEADER END
+#
+
+#
+# Copyright 2007 Sun Microsystems, Inc.  All rights reserved.
+# Use is subject to license terms.
+#
+
+#
+# Copyright (c) 2013 by Delphix. All rights reserved.
+#
+
+. $STF_SUITE/include/libtest.shlib
+. $STF_SUITE/tests/functional/migration/migration.kshlib
+
+#
+# DESCRIPTION:
+# Migrating test file from UFS fs to ZFS fs using tar.
+#
+# STRATEGY:
+# 1. Calculate chksum of testfile
+# 2. Tar up test file and place on a UFS filesystem
+# 3. Extract tar contents to a ZFS file system
+# 4. Calculate chksum of extracted file
+# 5. Compare old and new chksums.
+#
+
+verify_runnable "both"
+
+function cleanup
+{
+       $RM -rf $NONZFS_TESTDIR/tar$$.tar
+       $RM -rf $TESTDIR/$BNAME
+}
+
+log_assert "Migrating test file from UFS fs to ZFS fs using tar"
+
+log_onexit cleanup
+
+prepare $DNAME "$TAR cf $NONZFS_TESTDIR/tar$$.tar $BNAME"
+(( $? != 0 )) && log_fail "Unable to create src archive"
+
+migrate $TESTDIR $SUMA $SUMB "$TAR xvf $NONZFS_TESTDIR/tar$$.tar"
+(( $? != 0 )) && log_fail "Uable to successfully migrate test file from" \
+    "UFS fs to ZFS fs"
+
+log_pass "Successully migrated test file from UFS fs to ZFS fs".
diff --git a/tests/zfs-tests/tests/functional/migration/migration_004_pos.ksh b/tests/zfs-tests/tests/functional/migration/migration_004_pos.ksh
new file mode 100755 (executable)
index 0000000..98689e1
--- /dev/null
@@ -0,0 +1,73 @@
+#!/bin/ksh -p
+#
+# CDDL HEADER START
+#
+# The contents of this file are subject to the terms of the
+# Common Development and Distribution License (the "License").
+# You may not use this file except in compliance with the License.
+#
+# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
+# or http://www.opensolaris.org/os/licensing.
+# See the License for the specific language governing permissions
+# and limitations under the License.
+#
+# When distributing Covered Code, include this CDDL HEADER in each
+# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
+# If applicable, add the following below this CDDL HEADER, with the
+# fields enclosed by brackets "[]" replaced with your own identifying
+# information: Portions Copyright [yyyy] [name of copyright owner]
+#
+# CDDL HEADER END
+#
+
+#
+# Copyright 2007 Sun Microsystems, Inc.  All rights reserved.
+# Use is subject to license terms.
+#
+
+#
+# Copyright (c) 2013 by Delphix. All rights reserved.
+#
+
+. $STF_SUITE/include/libtest.shlib
+. $STF_SUITE/tests/functional/migration/migration.kshlib
+
+#
+# DESCRIPTION:
+# Migrating test file from ZFS fs to ZFS fs using cpio
+#
+# STRATEGY:
+# 1. Calculate chksum of testfile
+# 2. Cpio up test file and place on a ZFS filesystem
+# 3. Extract cpio contents to a ZFS file system
+# 4. Calculate chksum of extracted file
+# 5. Compare old and new chksums.
+#
+
+verify_runnable "both"
+
+function cleanup
+{
+       $RM -rf $TESTDIR/cpio$$.cpio
+       $RM -rf $TESTDIR/$BNAME
+}
+
+log_assert "Migrating test file from ZFS fs to ZFS fs using cpio"
+
+log_onexit cleanup
+
+cwd=$PWD
+cd $DNAME
+(( $? != 0 )) && log_untested "Could not change directory to $DNAME"
+
+$LS $BNAME | $CPIO -oc > $TESTDIR/cpio$$.cpio
+(( $? != 0 )) && log_failED "Unable to create cpio archive"
+
+cd $cwd
+(( $? != 0 )) && log_untested "Could not change directory to $cwd"
+
+migrate_cpio $TESTDIR "$TESTDIR/cpio$$.cpio" $SUMA $SUMB
+(( $? != 0 )) && log_fail "Uable to successfully migrate test file from" \
+    "ZFS fs to ZFS fs"
+
+log_pass "Successully migrated test file from ZFS fs to ZFS fs".
diff --git a/tests/zfs-tests/tests/functional/migration/migration_005_pos.ksh b/tests/zfs-tests/tests/functional/migration/migration_005_pos.ksh
new file mode 100755 (executable)
index 0000000..288b125
--- /dev/null
@@ -0,0 +1,73 @@
+#!/bin/ksh -p
+#
+# CDDL HEADER START
+#
+# The contents of this file are subject to the terms of the
+# Common Development and Distribution License (the "License").
+# You may not use this file except in compliance with the License.
+#
+# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
+# or http://www.opensolaris.org/os/licensing.
+# See the License for the specific language governing permissions
+# and limitations under the License.
+#
+# When distributing Covered Code, include this CDDL HEADER in each
+# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
+# If applicable, add the following below this CDDL HEADER, with the
+# fields enclosed by brackets "[]" replaced with your own identifying
+# information: Portions Copyright [yyyy] [name of copyright owner]
+#
+# CDDL HEADER END
+#
+
+#
+# Copyright 2007 Sun Microsystems, Inc.  All rights reserved.
+# Use is subject to license terms.
+#
+
+#
+# Copyright (c) 2013 by Delphix. All rights reserved.
+#
+
+. $STF_SUITE/include/libtest.shlib
+. $STF_SUITE/tests/functional/migration/migration.kshlib
+
+#
+# DESCRIPTION:
+# Migrating test file from ZFS fs to UFS fs using cpio
+#
+# STRATEGY:
+# 1. Calculate chksum of testfile
+# 2. Cpio up test file and place on a ZFS filesystem
+# 3. Extract cpio contents to a UFS file system
+# 4. Calculate chksum of extracted file
+# 5. Compare old and new chksums.
+#
+
+verify_runnable "both"
+
+function cleanup
+{
+       $RM -rf $TESTDIR/cpio$$.cpio
+       $RM -rf $NONZFS_TESTDIR/$BNAME
+}
+
+log_assert "Migrating test file from ZFS fs to uFS fs using cpio"
+
+log_onexit cleanup
+
+cwd=$PWD
+cd $DNAME
+(( $? != 0 )) && log_untested "Could not change directory to $DNAME"
+
+$LS $BNAME | $CPIO -oc > $TESTDIR/cpio$$.cpio
+(( $? != 0 )) && log_failED "Unable to create cpio archive"
+
+cd $cwd
+(( $? != 0 )) && log_untested "Could not change directory to $cwd"
+
+migrate_cpio $NONZFS_TESTDIR "$TESTDIR/cpio$$.cpio" $SUMA $SUMB
+(( $? != 0 )) && log_fail "Uable to successfully migrate test file from" \
+    "ZFS fs to UFS fs"
+
+log_pass "Successully migrated test file from ZFS fs to UFS fs".
diff --git a/tests/zfs-tests/tests/functional/migration/migration_006_pos.ksh b/tests/zfs-tests/tests/functional/migration/migration_006_pos.ksh
new file mode 100755 (executable)
index 0000000..97e7a01
--- /dev/null
@@ -0,0 +1,73 @@
+#!/bin/ksh -p
+#
+# CDDL HEADER START
+#
+# The contents of this file are subject to the terms of the
+# Common Development and Distribution License (the "License").
+# You may not use this file except in compliance with the License.
+#
+# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
+# or http://www.opensolaris.org/os/licensing.
+# See the License for the specific language governing permissions
+# and limitations under the License.
+#
+# When distributing Covered Code, include this CDDL HEADER in each
+# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
+# If applicable, add the following below this CDDL HEADER, with the
+# fields enclosed by brackets "[]" replaced with your own identifying
+# information: Portions Copyright [yyyy] [name of copyright owner]
+#
+# CDDL HEADER END
+#
+
+#
+# Copyright 2007 Sun Microsystems, Inc.  All rights reserved.
+# Use is subject to license terms.
+#
+
+#
+# Copyright (c) 2013 by Delphix. All rights reserved.
+#
+
+. $STF_SUITE/include/libtest.shlib
+. $STF_SUITE/tests/functional/migration/migration.kshlib
+
+#
+# DESCRIPTION:
+# Migrating test file from UFS fs to ZFS fs using cpio
+#
+# STRATEGY:
+# 1. Calculate chksum of testfile
+# 2. Cpio up test file and place on a UFS filesystem
+# 3. Extract cpio contents to a ZFS file system
+# 4. Calculate chksum of extracted file
+# 5. Compare old and new chksums.
+#
+
+verify_runnable "both"
+
+function cleanup
+{
+       $RM -rf $NONZFS_TESTDIR/cpio$$.cpio
+       $RM -rf $TESTDIR/$BNAME
+}
+
+log_assert "Migrating test file from UFS fs to ZFS fs using cpio"
+
+log_onexit cleanup
+
+cwd=$PWD
+cd $DNAME
+(( $? != 0 )) && log_untested "Could not change directory to $DNAME"
+
+$LS $BNAME | $CPIO -oc > $NONZFS_TESTDIR/cpio$$.cpio
+(( $? != 0 )) && log_failED "Unable to create cpio archive"
+
+cd $cwd
+(( $? != 0 )) && log_untested "Could not change directory to $cwd"
+
+migrate_cpio $TESTDIR "$NONZFS_TESTDIR/cpio$$.cpio" $SUMA $SUMB
+(( $? != 0 )) && log_fail "Uable to successfully migrate test file from" \
+    "ZFS fs to ZFS fs"
+
+log_pass "Successully migrated test file from UFS fs to ZFS fs".
diff --git a/tests/zfs-tests/tests/functional/migration/migration_007_pos.ksh b/tests/zfs-tests/tests/functional/migration/migration_007_pos.ksh
new file mode 100755 (executable)
index 0000000..ee0927b
--- /dev/null
@@ -0,0 +1,66 @@
+#!/bin/ksh -p
+#
+# CDDL HEADER START
+#
+# The contents of this file are subject to the terms of the
+# Common Development and Distribution License (the "License").
+# You may not use this file except in compliance with the License.
+#
+# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
+# or http://www.opensolaris.org/os/licensing.
+# See the License for the specific language governing permissions
+# and limitations under the License.
+#
+# When distributing Covered Code, include this CDDL HEADER in each
+# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
+# If applicable, add the following below this CDDL HEADER, with the
+# fields enclosed by brackets "[]" replaced with your own identifying
+# information: Portions Copyright [yyyy] [name of copyright owner]
+#
+# CDDL HEADER END
+#
+
+#
+# Copyright 2007 Sun Microsystems, Inc.  All rights reserved.
+# Use is subject to license terms.
+#
+
+#
+# Copyright (c) 2013 by Delphix. All rights reserved.
+#
+
+. $STF_SUITE/include/libtest.shlib
+. $STF_SUITE/tests/functional/migration/migration.kshlib
+
+#
+# DESCRIPTION:
+# Migrating test file from ZFS fs to ZFS fs using dd.
+#
+# STRATEGY:
+# 1. Calculate chksum of testfile
+# 2. Dd up test file and place on a ZFS filesystem
+# 3. Extract dd contents to a ZFS file system
+# 4. Calculate chksum of extracted file
+# 5. Compare old and new chksums.
+#
+
+verify_runnable "both"
+
+function cleanup
+{
+       $RM -rf $TESTDIR/dd$$.dd
+       $RM -rf $TESTDIR/$BNAME
+}
+
+log_assert "Migrating test file from ZFS fs to ZFS fs using dd"
+
+log_onexit cleanup
+
+prepare $DNAME "$DD if=$BNAME obs=128k of=$TESTDIR/dd$$.dd"
+(( $? != 0 )) && log_fail "Unable to create src archive"
+
+migrate $TESTDIR $SUMA $SUMB "$DD if=$TESTDIR/dd$$.dd obs=128k of=$BNAME"
+(( $? != 0 )) && log_fail "Uable to successfully migrate test file from" \
+    "ZFS fs to ZFS fs"
+
+log_pass "Successully migrated test file from ZFS fs to ZFS fs".
diff --git a/tests/zfs-tests/tests/functional/migration/migration_008_pos.ksh b/tests/zfs-tests/tests/functional/migration/migration_008_pos.ksh
new file mode 100755 (executable)
index 0000000..92d2a45
--- /dev/null
@@ -0,0 +1,66 @@
+#!/bin/ksh -p
+#
+# CDDL HEADER START
+#
+# The contents of this file are subject to the terms of the
+# Common Development and Distribution License (the "License").
+# You may not use this file except in compliance with the License.
+#
+# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
+# or http://www.opensolaris.org/os/licensing.
+# See the License for the specific language governing permissions
+# and limitations under the License.
+#
+# When distributing Covered Code, include this CDDL HEADER in each
+# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
+# If applicable, add the following below this CDDL HEADER, with the
+# fields enclosed by brackets "[]" replaced with your own identifying
+# information: Portions Copyright [yyyy] [name of copyright owner]
+#
+# CDDL HEADER END
+#
+
+#
+# Copyright 2007 Sun Microsystems, Inc.  All rights reserved.
+# Use is subject to license terms.
+#
+
+#
+# Copyright (c) 2013 by Delphix. All rights reserved.
+#
+
+. $STF_SUITE/include/libtest.shlib
+. $STF_SUITE/tests/functional/migration/migration.kshlib
+
+#
+# DESCRIPTION:
+# Migrating test file from ZFS fs to UFS fs using dd.
+#
+# STRATEGY:
+# 1. Calculate chksum of testfile
+# 2. Dd up test file and place on a ZFS filesystem
+# 3. Extract dd contents to a UFS file system
+# 4. Calculate chksum of extracted file
+# 5. Compare old and new chksums.
+#
+
+verify_runnable "both"
+
+function cleanup
+{
+       $RM -rf $TESTDIR/dd$$.dd
+       $RM -rf $NONZFS_TESTDIR/$BNAME
+}
+
+log_assert "Migrating test file from ZFS fs to UFS fs using dd"
+
+log_onexit cleanup
+
+prepare $DNAME "$DD if=$BNAME obs=128k of=$TESTDIR/dd$$.dd"
+(( $? != 0 )) && log_fail "Unable to create src archive"
+
+migrate $NONZFS_TESTDIR $SUMA $SUMB "$DD if=$TESTDIR/dd$$.dd obs=128k of=$BNAME"
+(( $? != 0 )) && log_fail "Uable to successfully migrate test file from" \
+    "ZFS fs to ZFS fs"
+
+log_pass "Successully migrated test file from ZFS fs to UFS fs".
diff --git a/tests/zfs-tests/tests/functional/migration/migration_009_pos.ksh b/tests/zfs-tests/tests/functional/migration/migration_009_pos.ksh
new file mode 100755 (executable)
index 0000000..317eefd
--- /dev/null
@@ -0,0 +1,66 @@
+#!/bin/ksh -p
+#
+# CDDL HEADER START
+#
+# The contents of this file are subject to the terms of the
+# Common Development and Distribution License (the "License").
+# You may not use this file except in compliance with the License.
+#
+# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
+# or http://www.opensolaris.org/os/licensing.
+# See the License for the specific language governing permissions
+# and limitations under the License.
+#
+# When distributing Covered Code, include this CDDL HEADER in each
+# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
+# If applicable, add the following below this CDDL HEADER, with the
+# fields enclosed by brackets "[]" replaced with your own identifying
+# information: Portions Copyright [yyyy] [name of copyright owner]
+#
+# CDDL HEADER END
+#
+
+#
+# Copyright 2007 Sun Microsystems, Inc.  All rights reserved.
+# Use is subject to license terms.
+#
+
+#
+# Copyright (c) 2013 by Delphix. All rights reserved.
+#
+
+. $STF_SUITE/include/libtest.shlib
+. $STF_SUITE/tests/functional/migration/migration.kshlib
+
+#
+# DESCRIPTION:
+# Migrating test file from UFS fs to ZFS fs using dd.
+#
+# STRATEGY:
+# 1. Calculate chksum of testfile
+# 2. Dd up test file and place on a UFS filesystem
+# 3. Extract dd contents to a ZFS file system
+# 4. Calculate chksum of extracted file
+# 5. Compare old and new chksums.
+#
+
+verify_runnable "both"
+
+function cleanup
+{
+       $RM -rf $TESTDIR/dd$$.dd
+       $RM -rf $NONZFS_TESTDIR/$BNAME
+}
+
+log_assert "Migrating test file from UFS fs to ZFS fs using dd"
+
+log_onexit cleanup
+
+prepare $DNAME "$DD if=$BNAME obs=128k of=$NONZFS_TESTDIR/dd$$.dd"
+(( $? != 0 )) && log_fail "Unable to create src archive"
+
+migrate $TESTDIR $SUMA $SUMB "$DD if=$NONZFS_TESTDIR/dd$$.dd obs=128k of=$BNAME"
+(( $? != 0 )) && log_fail "Uable to successfully migrate test file from" \
+    "ZFS fs to ZFS fs"
+
+log_pass "Successully migrated test file from UFS fs to ZFS fs".
diff --git a/tests/zfs-tests/tests/functional/migration/migration_010_pos.ksh b/tests/zfs-tests/tests/functional/migration/migration_010_pos.ksh
new file mode 100755 (executable)
index 0000000..462bfb1
--- /dev/null
@@ -0,0 +1,66 @@
+#!/bin/ksh -p
+#
+# CDDL HEADER START
+#
+# The contents of this file are subject to the terms of the
+# Common Development and Distribution License (the "License").
+# You may not use this file except in compliance with the License.
+#
+# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
+# or http://www.opensolaris.org/os/licensing.
+# See the License for the specific language governing permissions
+# and limitations under the License.
+#
+# When distributing Covered Code, include this CDDL HEADER in each
+# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
+# If applicable, add the following below this CDDL HEADER, with the
+# fields enclosed by brackets "[]" replaced with your own identifying
+# information: Portions Copyright [yyyy] [name of copyright owner]
+#
+# CDDL HEADER END
+#
+
+#
+# Copyright 2007 Sun Microsystems, Inc.  All rights reserved.
+# Use is subject to license terms.
+#
+
+#
+# Copyright (c) 2013 by Delphix. All rights reserved.
+#
+
+. $STF_SUITE/include/libtest.shlib
+. $STF_SUITE/tests/functional/migration/migration.kshlib
+
+#
+# DESCRIPTION:
+# Migrating test file from ZFS fs to ZFS fs using cp
+#
+# STRATEGY:
+# 1. Calculate chksum of testfile
+# 2. CP up test file and place on a ZFS filesystem
+# 3. Extract cp contents to a ZFS file system
+# 4. Calculate chksum of extracted file
+# 5. Compare old and new chksums.
+#
+
+verify_runnable "both"
+
+function cleanup
+{
+       $RM -rf $TESTDIR/cp$$.cp
+       $RM -rf $TESTDIR/$BNAME
+}
+
+log_assert "Migrating test file from ZFS fs to ZFS fs using cp"
+
+log_onexit cleanup
+
+prepare $DNAME "$CP $BNAME $TESTDIR/cp$$.cp"
+(( $? != 0 )) && log_fail "Unable to create src archive"
+
+migrate $TESTDIR $SUMA $SUMB "$CP $TESTDIR/cp$$.cp $BNAME"
+(( $? != 0 )) && log_fail "Uable to successfully migrate test file from" \
+    "ZFS fs to ZFS fs"
+
+log_pass "Successully migrated test file from ZFS fs to ZFS fs".
diff --git a/tests/zfs-tests/tests/functional/migration/migration_011_pos.ksh b/tests/zfs-tests/tests/functional/migration/migration_011_pos.ksh
new file mode 100755 (executable)
index 0000000..2fcd291
--- /dev/null
@@ -0,0 +1,66 @@
+#!/bin/ksh -p
+#
+# CDDL HEADER START
+#
+# The contents of this file are subject to the terms of the
+# Common Development and Distribution License (the "License").
+# You may not use this file except in compliance with the License.
+#
+# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
+# or http://www.opensolaris.org/os/licensing.
+# See the License for the specific language governing permissions
+# and limitations under the License.
+#
+# When distributing Covered Code, include this CDDL HEADER in each
+# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
+# If applicable, add the following below this CDDL HEADER, with the
+# fields enclosed by brackets "[]" replaced with your own identifying
+# information: Portions Copyright [yyyy] [name of copyright owner]
+#
+# CDDL HEADER END
+#
+
+#
+# Copyright 2007 Sun Microsystems, Inc.  All rights reserved.
+# Use is subject to license terms.
+#
+
+#
+# Copyright (c) 2013 by Delphix. All rights reserved.
+#
+
+. $STF_SUITE/include/libtest.shlib
+. $STF_SUITE/tests/functional/migration/migration.kshlib
+
+#
+# DESCRIPTION:
+# Migrating test file from ZFS fs to UFS fs using cp
+#
+# STRATEGY:
+# 1. Calculate chksum of testfile
+# 2. CP up test file and place on a ZFS filesystem
+# 3. Extract cp contents to a UFS file system
+# 4. Calculate chksum of extracted file
+# 5. Compare old and new chksums.
+#
+
+verify_runnable "both"
+
+function cleanup
+{
+       $RM -rf $NONZFS_TESTDIR/cp$$.cp
+       $RM -rf $TESTDIR/$BNAME
+}
+
+log_assert "Migrating test file from ZFS fs to UFS fs using cp"
+
+log_onexit cleanup
+
+prepare $DNAME "$CP $BNAME $TESTDIR/cp$$.cp"
+(( $? != 0 )) && log_fail "Unable to create src archive"
+
+migrate $NONZFS_TESTDIR $SUMA $SUMB "$CP $TESTDIR/cp$$.cp $BNAME"
+(( $? != 0 )) && log_fail "Uable to successfully migrate test file from" \
+    "ZFS fs to UFS fs"
+
+log_pass "Successully migrated test file from ZFS fs to UFS fs".
diff --git a/tests/zfs-tests/tests/functional/migration/migration_012_pos.ksh b/tests/zfs-tests/tests/functional/migration/migration_012_pos.ksh
new file mode 100755 (executable)
index 0000000..427467e
--- /dev/null
@@ -0,0 +1,66 @@
+#!/bin/ksh -p
+#
+# CDDL HEADER START
+#
+# The contents of this file are subject to the terms of the
+# Common Development and Distribution License (the "License").
+# You may not use this file except in compliance with the License.
+#
+# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
+# or http://www.opensolaris.org/os/licensing.
+# See the License for the specific language governing permissions
+# and limitations under the License.
+#
+# When distributing Covered Code, include this CDDL HEADER in each
+# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
+# If applicable, add the following below this CDDL HEADER, with the
+# fields enclosed by brackets "[]" replaced with your own identifying
+# information: Portions Copyright [yyyy] [name of copyright owner]
+#
+# CDDL HEADER END
+#
+
+#
+# Copyright 2007 Sun Microsystems, Inc.  All rights reserved.
+# Use is subject to license terms.
+#
+
+#
+# Copyright (c) 2013 by Delphix. All rights reserved.
+#
+
+. $STF_SUITE/include/libtest.shlib
+. $STF_SUITE/tests/functional/migration/migration.kshlib
+
+#
+# DESCRIPTION:
+# Migrating test file from UFS fs to ZFS fs using cp
+#
+# STRATEGY:
+# 1. Calculate chksum of testfile
+# 2. CP up test file and place on a UFS filesystem
+# 3. Extract cp contents to a ZFS file system
+# 4. Calculate chksum of extracted file
+# 5. Compare old and new chksums.
+#
+
+verify_runnable "both"
+
+function cleanup
+{
+       $RM -rf $TESTDIR/cp$$.cp
+       $RM -rf $NONZFS_TESTDIR/$BNAME
+}
+
+log_assert "Migrating test file from UFS fs to ZFS fs using cp"
+
+log_onexit cleanup
+
+prepare $DNAME "$CP $BNAME $NONZFS_TESTDIR/cp$$.cp"
+(( $? != 0 )) && log_fail "Unable to create src archive"
+
+migrate $TESTDIR $SUMA $SUMB "$CP $NONZFS_TESTDIR/cp$$.cp $BNAME"
+(( $? != 0 )) && log_fail "Uable to successfully migrate test file from" \
+    "UFS fs to ZFS fs"
+
+log_pass "Successully migrated test file from UFS fs to ZFS fs".
diff --git a/tests/zfs-tests/tests/functional/migration/setup.ksh b/tests/zfs-tests/tests/functional/migration/setup.ksh
new file mode 100755 (executable)
index 0000000..18be625
--- /dev/null
@@ -0,0 +1,73 @@
+#!/bin/ksh -p
+#
+# CDDL HEADER START
+#
+# The contents of this file are subject to the terms of the
+# Common Development and Distribution License (the "License").
+# You may not use this file except in compliance with the License.
+#
+# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
+# or http://www.opensolaris.org/os/licensing.
+# See the License for the specific language governing permissions
+# and limitations under the License.
+#
+# When distributing Covered Code, include this CDDL HEADER in each
+# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
+# If applicable, add the following below this CDDL HEADER, with the
+# fields enclosed by brackets "[]" replaced with your own identifying
+# information: Portions Copyright [yyyy] [name of copyright owner]
+#
+# CDDL HEADER END
+#
+
+#
+# Copyright 2009 Sun Microsystems, Inc.  All rights reserved.
+# Use is subject to license terms.
+#
+
+#
+# Copyright (c) 2013 by Delphix. All rights reserved.
+#
+
+. $STF_SUITE/include/libtest.shlib
+. $STF_SUITE/tests/functional/migration/migration.cfg
+
+verify_runnable "global"
+
+if ! $(is_physical_device $ZFS_DISK) ; then
+       log_unsupported "Only partitionable physical disks can be used"
+fi
+
+case $DISK_COUNT in
+0)
+       log_untested "Need at least 1 disk device for test"
+       ;;
+1)
+       log_note "Partitioning a single disk ($SINGLE_DISK)"
+       ;;
+*)
+       log_note "Partitioning disks ($ZFS_DISK $NONZFS_DISK)"
+       ;;
+esac
+
+set_partition ${ZFSSIDE_DISK##*s} "" $FS_SIZE $ZFS_DISK
+set_partition ${NONZFSSIDE_DISK##*s} "" $FS_SIZE $NONZFS_DISK
+
+create_pool $TESTPOOL "$ZFSSIDE_DISK"
+
+$RM -rf $TESTDIR  || log_unresolved Could not remove $TESTDIR
+$MKDIR -p $TESTDIR || log_unresolved Could not create $TESTDIR
+
+log_must $ZFS create $TESTPOOL/$TESTFS
+log_must $ZFS set mountpoint=$TESTDIR $TESTPOOL/$TESTFS
+
+$RM -rf $NONZFS_TESTDIR  || log_unresolved Could not remove $NONZFS_TESTDIR
+$MKDIR -p $NONZFS_TESTDIR || log_unresolved Could not create $NONZFS_TESTDIR
+
+$ECHO "y" | $NEWFS -v ${DEV_RDSKDIR}/$NONZFSSIDE_DISK
+(( $? != 0 )) &&
+       log_untested "Unable to setup a UFS file system"
+
+log_must $MOUNT ${DEV_DSKDIR}/$NONZFSSIDE_DISK $NONZFS_TESTDIR
+
+log_pass
diff --git a/tests/zfs-tests/tests/functional/mmap/Makefile.am b/tests/zfs-tests/tests/functional/mmap/Makefile.am
new file mode 100644 (file)
index 0000000..a635b3d
--- /dev/null
@@ -0,0 +1,6 @@
+pkgdatadir = $(datadir)/@PACKAGE@/zfs-tests/tests/functional/mmap
+dist_pkgdata_SCRIPTS = \
+       setup.ksh \
+       cleanup.ksh \
+       mmap_read_001_pos.ksh \
+       mmap_write_001_pos.ksh
diff --git a/tests/zfs-tests/tests/functional/mmap/cleanup.ksh b/tests/zfs-tests/tests/functional/mmap/cleanup.ksh
new file mode 100755 (executable)
index 0000000..3166bd6
--- /dev/null
@@ -0,0 +1,34 @@
+#!/bin/ksh -p
+#
+# CDDL HEADER START
+#
+# The contents of this file are subject to the terms of the
+# Common Development and Distribution License (the "License").
+# You may not use this file except in compliance with the License.
+#
+# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
+# or http://www.opensolaris.org/os/licensing.
+# See the License for the specific language governing permissions
+# and limitations under the License.
+#
+# When distributing Covered Code, include this CDDL HEADER in each
+# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
+# If applicable, add the following below this CDDL HEADER, with the
+# fields enclosed by brackets "[]" replaced with your own identifying
+# information: Portions Copyright [yyyy] [name of copyright owner]
+#
+# CDDL HEADER END
+#
+
+#
+# Copyright 2007 Sun Microsystems, Inc.  All rights reserved.
+# Use is subject to license terms.
+#
+
+#
+# Copyright (c) 2013 by Delphix. All rights reserved.
+#
+
+. $STF_SUITE/include/libtest.shlib
+
+default_cleanup
diff --git a/tests/zfs-tests/tests/functional/mmap/mmap_read_001_pos.ksh b/tests/zfs-tests/tests/functional/mmap/mmap_read_001_pos.ksh
new file mode 100755 (executable)
index 0000000..0b3ddb6
--- /dev/null
@@ -0,0 +1,56 @@
+#!/bin/ksh -p
+#
+# CDDL HEADER START
+#
+# The contents of this file are subject to the terms of the
+# Common Development and Distribution License (the "License").
+# You may not use this file except in compliance with the License.
+#
+# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
+# or http://www.opensolaris.org/os/licensing.
+# See the License for the specific language governing permissions
+# and limitations under the License.
+#
+# When distributing Covered Code, include this CDDL HEADER in each
+# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
+# If applicable, add the following below this CDDL HEADER, with the
+# fields enclosed by brackets "[]" replaced with your own identifying
+# information: Portions Copyright [yyyy] [name of copyright owner]
+#
+# CDDL HEADER END
+#
+
+#
+# Copyright 2009 Sun Microsystems, Inc.  All rights reserved.
+# Use is subject to license terms.
+#
+
+#
+# Copyright (c) 2013 by Delphix. All rights reserved.
+#
+
+. $STF_SUITE/include/libtest.shlib
+
+#
+# DESCRIPTION:
+# read()s from mmap()'ed file contain correct data.
+#
+# STRATEGY:
+# 1. Create a pool & dataset
+# 2. Call readmmap binary
+# 3. unmount this file system
+# 4. Verify the integrity of this pool & dateset
+#
+
+verify_runnable "global"
+
+log_assert "read()s from mmap()'ed file contain correct data."
+
+log_must $CHMOD 777 $TESTDIR
+log_must $READMMAP $TESTDIR/test-read-file
+log_must $ZFS unmount $TESTPOOL/$TESTFS
+
+typeset dir=$(get_device_dir $DISKS)
+verify_filesys "$TESTPOOL" "$TESTPOOL/$TESTFS" "$dir"
+
+log_pass "read(2) calls from a mmap(2)'ed file succeeded."
diff --git a/tests/zfs-tests/tests/functional/mmap/mmap_write_001_pos.ksh b/tests/zfs-tests/tests/functional/mmap/mmap_write_001_pos.ksh
new file mode 100755 (executable)
index 0000000..6bede53
--- /dev/null
@@ -0,0 +1,62 @@
+#!/bin/ksh -p
+#
+# CDDL HEADER START
+#
+# The contents of this file are subject to the terms of the
+# Common Development and Distribution License (the "License").
+# You may not use this file except in compliance with the License.
+#
+# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
+# or http://www.opensolaris.org/os/licensing.
+# See the License for the specific language governing permissions
+# and limitations under the License.
+#
+# When distributing Covered Code, include this CDDL HEADER in each
+# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
+# If applicable, add the following below this CDDL HEADER, with the
+# fields enclosed by brackets "[]" replaced with your own identifying
+# information: Portions Copyright [yyyy] [name of copyright owner]
+#
+# CDDL HEADER END
+#
+
+#
+# Copyright 2007 Sun Microsystems, Inc.  All rights reserved.
+# Use is subject to license terms.
+#
+
+#
+# Copyright (c) 2013 by Delphix. All rights reserved.
+#
+
+. $STF_SUITE/include/libtest.shlib
+
+#
+# DESCRIPTION:
+# Writing to a file and mmaping that file at the
+# same time does not result in a deadlock.
+#
+# STRATEGY:
+# 1. Make sure this test executes on multi-processes system.
+# 2. Call mmapwrite binary.
+# 3. wait 30s and make sure the test file existed.
+#
+
+verify_runnable "both"
+
+log_assert "write()s to a file and mmap() that file at the same time does not "\
+       "result in a deadlock."
+
+# Detect and make sure this test must be executed on a multi-process system
+is_mp || log_fail "This test requires a multi-processor system."
+
+log_must $CHMOD 777 $TESTDIR
+$MMAPWRITE $TESTDIR/test-write-file &
+PID_MMAPWRITE=$!
+log_note "$MMAPWRITE $TESTDIR/test-write-file pid: $PID_MMAPWRITE"
+log_must $SLEEP 30
+
+log_must $KILL -9 $PID_MMAPWRITE
+log_must $LS -l $TESTDIR/test-write-file
+
+log_pass "write(2) a mmap(2)'ing file succeeded."
diff --git a/tests/zfs-tests/tests/functional/mmap/setup.ksh b/tests/zfs-tests/tests/functional/mmap/setup.ksh
new file mode 100755 (executable)
index 0000000..d275e06
--- /dev/null
@@ -0,0 +1,36 @@
+#!/bin/ksh -p
+#
+# CDDL HEADER START
+#
+# The contents of this file are subject to the terms of the
+# Common Development and Distribution License (the "License").
+# You may not use this file except in compliance with the License.
+#
+# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
+# or http://www.opensolaris.org/os/licensing.
+# See the License for the specific language governing permissions
+# and limitations under the License.
+#
+# When distributing Covered Code, include this CDDL HEADER in each
+# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
+# If applicable, add the following below this CDDL HEADER, with the
+# fields enclosed by brackets "[]" replaced with your own identifying
+# information: Portions Copyright [yyyy] [name of copyright owner]
+#
+# CDDL HEADER END
+#
+
+#
+# Copyright 2007 Sun Microsystems, Inc.  All rights reserved.
+# Use is subject to license terms.
+#
+
+#
+# Copyright (c) 2013 by Delphix. All rights reserved.
+#
+
+. $STF_SUITE/include/libtest.shlib
+
+DISK=${DISKS%% *}
+
+default_setup $DISK
diff --git a/tests/zfs-tests/tests/functional/mount/Makefile.am b/tests/zfs-tests/tests/functional/mount/Makefile.am
new file mode 100644 (file)
index 0000000..9898e05
--- /dev/null
@@ -0,0 +1,6 @@
+pkgdatadir = $(datadir)/@PACKAGE@/zfs-tests/tests/functional/mount
+dist_pkgdata_SCRIPTS = \
+       setup.ksh \
+       cleanup.ksh \
+       umount_001.ksh \
+       umountall_001.ksh
diff --git a/tests/zfs-tests/tests/functional/mount/cleanup.ksh b/tests/zfs-tests/tests/functional/mount/cleanup.ksh
new file mode 100755 (executable)
index 0000000..36ff7c0
--- /dev/null
@@ -0,0 +1,38 @@
+#!/bin/ksh -p
+#
+# CDDL HEADER START
+#
+# The contents of this file are subject to the terms of the
+# Common Development and Distribution License (the "License").
+# You may not use this file except in compliance with the License.
+#
+# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
+# or http://www.opensolaris.org/os/licensing.
+# See the License for the specific language governing permissions
+# and limitations under the License.
+#
+# When distributing Covered Code, include this CDDL HEADER in each
+# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
+# If applicable, add the following below this CDDL HEADER, with the
+# fields enclosed by brackets "[]" replaced with your own identifying
+# information: Portions Copyright [yyyy] [name of copyright owner]
+#
+# CDDL HEADER END
+#
+
+#
+# Copyright 2007 Sun Microsystems, Inc.  All rights reserved.
+# Use is subject to license terms.
+#
+
+#
+# Copyright (c) 2013 by Delphix. All rights reserved.
+#
+
+. $STF_SUITE/include/libtest.shlib
+
+log_must destroy_pool $TESTPOOL
+
+for dir in $TESTDIRS; do
+       $RM -rf $dir
+done
diff --git a/tests/zfs-tests/tests/functional/mount/setup.ksh b/tests/zfs-tests/tests/functional/mount/setup.ksh
new file mode 100755 (executable)
index 0000000..7255e7d
--- /dev/null
@@ -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 2009 Sun Microsystems, Inc.  All rights reserved.
+# Use is subject to license terms.
+#
+
+#
+# Copyright (c) 2013 by Delphix. All rights reserved.
+#
+
+. $STF_SUITE/include/libtest.shlib
+
+DISK=${DISKS%% *}
+create_pool $TESTPOOL "$DISK"
+
+for i in 1 2 3; do
+       dir=$TESTDIR.$i
+       fs=$TESTPOOL/$TESTFS.$i
+
+       log_must $ZFS create $fs
+       log_must $MKDIR -p $dir
+       log_must $ZFS set mountpoint=$dir $fs
+
+       log_must mounted $fs
+done
+
+log_pass
diff --git a/tests/zfs-tests/tests/functional/mount/umount_001.ksh b/tests/zfs-tests/tests/functional/mount/umount_001.ksh
new file mode 100755 (executable)
index 0000000..55b46ff
--- /dev/null
@@ -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.
+#
+
+#
+# Copyright (c) 2013 by Delphix. All rights reserved.
+#
+
+. $STF_SUITE/include/libtest.shlib
+
+#
+# DESCRIPTION:
+# zfs mount and unmount commands should mount and unmount existing
+# file systems.
+#
+# STRATEGY:
+# 1. Call zfs mount command
+# 2. Make sure the file systems were mounted
+# 3. Call zfs unmount command
+# 4. Make sure the file systems were unmounted
+#
+
+for fs in 1 2 3; do
+       log_must mounted $TESTDIR.$fs
+       log_must $ZFS umount $TESTPOOL/$TESTFS.$fs
+       log_must unmounted $TESTDIR.$fs
+       log_must $ZFS mount $TESTPOOL/$TESTFS.$fs
+       log_must mounted $TESTDIR.$fs
+done
+
+log_pass "All file systems are unmounted"
diff --git a/tests/zfs-tests/tests/functional/mount/umountall_001.ksh b/tests/zfs-tests/tests/functional/mount/umountall_001.ksh
new file mode 100755 (executable)
index 0000000..6b07542
--- /dev/null
@@ -0,0 +1,59 @@
+#!/bin/ksh -p
+
+#
+# This file and its contents are supplied under the terms of the
+# Common Development and Distribution License ("CDDL"), version 1.0.
+# You may only use this file in accordance with the terms of version
+# 1.0 of the CDDL.
+#
+# A full copy of the text of the CDDL should have accompanied this
+# source.  A copy of the CDDL is also available via the Internet at
+# http://www.illumos.org/license/CDDL.
+#
+
+#
+# Copyright (c) 2013 by Delphix. All rights reserved.
+#
+
+. $STF_SUITE/include/libtest.shlib
+
+#
+# DESCRIPTION:
+# There are myriad problems associated with trying to test umountall in a way
+# that works reliable across different systems. Some filesystems won't unmount
+# because they're busy. Some won't remount because they were legacy mounts in
+# the first place. etc...
+# Make a best approximation by calling umountall with the -n option, and verify
+# that the list of things it would try to unmout makes sense.
+#
+# STRATEGY:
+# 1. Make a list of file systems umountall is known to ignore.
+# 2. Append all ZFS file systems on this system.
+# 3. Run umountall -n and verify the file systems it reports are in the list.
+#
+
+log_must $ZFS mount -a
+for fs in 1 2 3 ; do
+       log_must mounted $TESTPOOL/$TESTFS.$fs
+done
+
+# This is the list we check the output of umountall -n against. We seed it
+# with these values because umountall will ignore them, and they're possible
+# (though most are improbable) ZFS filesystem mountpoints.
+zfs_list="/ /lib /sbin /tmp /usr /var /var/adm /var/run"
+
+# Append our ZFS filesystems to the list, not worrying about duplicates.
+for fs in $($MOUNT -p | $AWK '{if ($4 == "zfs") print $3}'); do
+       zfs_list="$zfs_list $fs"
+done
+
+fs=''
+for fs in $($UMOUNTALL -n -F zfs 2>&1 | $AWK '{print $2}'); do
+       for i in $zfs_list; do
+               [[ $fs = $i ]] && continue 2
+       done
+       log_fail "umountall -n -F zfs tried to unmount $fs"
+done
+[[ -n $fs ]] || log_fail "umountall -n -F zfs produced no output"
+
+log_pass "All ZFS file systems would have been unmounted"
diff --git a/tests/zfs-tests/tests/functional/mv_files/Makefile.am b/tests/zfs-tests/tests/functional/mv_files/Makefile.am
new file mode 100644 (file)
index 0000000..574af15
--- /dev/null
@@ -0,0 +1,8 @@
+pkgdatadir = $(datadir)/@PACKAGE@/zfs-tests/tests/functional/mv_files
+dist_pkgdata_SCRIPTS = \
+       mv_files.cfg \
+       mv_files_common.kshlib \
+       setup.ksh \
+       cleanup.ksh \
+       mv_files_001_pos.ksh \
+       mv_files_002_pos.ksh
diff --git a/tests/zfs-tests/tests/functional/mv_files/cleanup.ksh b/tests/zfs-tests/tests/functional/mv_files/cleanup.ksh
new file mode 100755 (executable)
index 0000000..ecec91f
--- /dev/null
@@ -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.
+#
+
+#
+# Copyright (c) 2013 by Delphix. All rights reserved.
+#
+
+. $STF_SUITE/include/libtest.shlib
+. $STF_SUITE/tests/functional/mv_files/mv_files_common.kshlib
+
+verify_runnable "global"
+
+[[ -f /var/tmp/exitsZero.ksh ]] && \
+       log_must $RM -f /var/tmp/exitsZero.ksh
+[[ -f /var/tmp/testbackgprocs.ksh ]] && \
+       log_must $RM -f /var/tmp/testbackgprocs.ksh
+
+ismounted $TESTPOOL/$TESTFS_TGT
+(( $? == 0 )) && log_must $ZFS umount $TESTPOOL/$TESTFS_TGT
+log_must $ZFS destroy $TESTPOOL/$TESTFS_TGT
+
+[[ -d $TESTDIR_TGT ]] && log_must $RM -rf $TESTDIR_TGT
+
+default_cleanup
diff --git a/tests/zfs-tests/tests/functional/mv_files/mv_files.cfg b/tests/zfs-tests/tests/functional/mv_files/mv_files.cfg
new file mode 100644 (file)
index 0000000..6c81862
--- /dev/null
@@ -0,0 +1,43 @@
+#
+# CDDL HEADER START
+#
+# The contents of this file are subject to the terms of the
+# Common Development and Distribution License (the "License").
+# You may not use this file except in compliance with the License.
+#
+# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
+# or http://www.opensolaris.org/os/licensing.
+# See the License for the specific language governing permissions
+# and limitations under the License.
+#
+# When distributing Covered Code, include this CDDL HEADER in each
+# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
+# If applicable, add the following below this CDDL HEADER, with the
+# fields enclosed by brackets "[]" replaced with your own identifying
+# information: Portions Copyright [yyyy] [name of copyright owner]
+#
+# CDDL HEADER END
+#
+
+#
+# Copyright 2008 Sun Microsystems, Inc.  All rights reserved.
+# Use is subject to license terms.
+#
+
+#
+# Copyright (c) 2013 by Delphix. All rights reserved.
+#
+
+export DISK=${DISKS%% *}
+
+export TESTFILE=testfile
+
+export TESTDIR_TGT=${TEST_BASE_DIR%%/}/testdir_tgt
+export TESTFS_TGT=testzfs_tgt
+export OLDDIR=$TESTDIR/olddir
+export NEWDIR_IN_FS=$TESTDIR/newdir
+export NEWDIR_ACROSS_FS=$TESTDIR_TGT/newdir
+
+export MVNUMFILES=2000 # <number of files to start>
+export MVNUMINCR=1000  # <number of files to be increased to>
+export GANGPIDS=50     # <number of limit for parallel background running process>
diff --git a/tests/zfs-tests/tests/functional/mv_files/mv_files_001_pos.ksh b/tests/zfs-tests/tests/functional/mv_files/mv_files_001_pos.ksh
new file mode 100755 (executable)
index 0000000..834ee3b
--- /dev/null
@@ -0,0 +1,69 @@
+#! /bin/ksh -p
+#
+# CDDL HEADER START
+#
+# The contents of this file are subject to the terms of the
+# Common Development and Distribution License (the "License").
+# You may not use this file except in compliance with the License.
+#
+# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
+# or http://www.opensolaris.org/os/licensing.
+# See the License for the specific language governing permissions
+# and limitations under the License.
+#
+# When distributing Covered Code, include this CDDL HEADER in each
+# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
+# If applicable, add the following below this CDDL HEADER, with the
+# fields enclosed by brackets "[]" replaced with your own identifying
+# information: Portions Copyright [yyyy] [name of copyright owner]
+#
+# CDDL HEADER END
+#
+
+#
+# Copyright 2007 Sun Microsystems, Inc.  All rights reserved.
+# Use is subject to license terms.
+#
+
+#
+# Copyright (c) 2013 by Delphix. All rights reserved.
+#
+
+. $STF_SUITE/include/libtest.shlib
+. $STF_SUITE/tests/functional/mv_files/mv_files_common.kshlib
+
+#
+# DESCRIPTION:
+# Doing a 'mv' of a large amount of files between two directories
+# within a zfs filesystem works without errors.
+#
+# STRATEGY:
+#
+# 1. create a pool and a zfs filesystem
+# 2. create two directories within the filesystem
+# 3. create a large number of files within a directory
+# 4. Move files from one directory to another and back again
+# 5. validate file number
+# 6. increase the number of files to $MVNUMFILES + $MVNUMINCR
+# 7. repeat steps 3,4,5,6 above
+# 8. verify the data integrity
+#
+
+verify_runnable "global"
+
+function cleanup
+{
+       PIDS=""
+       $RM -f $OLDDIR/* >/dev/null 2>&1
+       $RM -f $NEWDIR_IN_FS/* >/dev/null 2>&1
+}
+
+log_assert "Doing a 'mv' of a large amount of files within a zfs filesystem" \
+           "works without errors."
+
+log_onexit cleanup
+
+mv_test $OLDDIR $NEWDIR_IN_FS
+(($? != 0 )) &&  log_fail "'mv' test failed to complete."
+
+log_pass
diff --git a/tests/zfs-tests/tests/functional/mv_files/mv_files_002_pos.ksh b/tests/zfs-tests/tests/functional/mv_files/mv_files_002_pos.ksh
new file mode 100755 (executable)
index 0000000..f80447f
--- /dev/null
@@ -0,0 +1,71 @@
+#! /bin/ksh -p
+#
+# CDDL HEADER START
+#
+# The contents of this file are subject to the terms of the
+# Common Development and Distribution License (the "License").
+# You may not use this file except in compliance with the License.
+#
+# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
+# or http://www.opensolaris.org/os/licensing.
+# See the License for the specific language governing permissions
+# and limitations under the License.
+#
+# When distributing Covered Code, include this CDDL HEADER in each
+# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
+# If applicable, add the following below this CDDL HEADER, with the
+# fields enclosed by brackets "[]" replaced with your own identifying
+# information: Portions Copyright [yyyy] [name of copyright owner]
+#
+# CDDL HEADER END
+#
+
+#
+# Copyright 2007 Sun Microsystems, Inc.  All rights reserved.
+# Use is subject to license terms.
+#
+
+#
+# Copyright (c) 2013 by Delphix. All rights reserved.
+#
+
+. $STF_SUITE/include/libtest.shlib
+. $STF_SUITE/tests/functional/mv_files/mv_files_common.kshlib
+
+#
+# DESCRIPTION:
+# Doing a 'mv' of a large amount of files between two directories across
+# two zfs filesystems works without errors.
+#
+# STRATEGY:
+#
+# 1. create a pool and two zfs filesystems
+# 2. create a directory in each filesystem
+# 3. create a large number of files in a directory of a filesystem
+# 4. Move files from the directory to another directory in another
+# filesystem and back again
+# 5. validate file number
+# 6. increase the number of files to $MVNUMFILES + $MVNUMINCR
+# 7. repeat steps 3,4,5,6 above
+# 8. verify the data integrity
+#
+
+verify_runnable "global"
+
+function cleanup
+{
+       PIDS=""
+       $RM -f $OLDDIR/* >/dev/null 2>&1
+       $RM -f $NEWDIR_ACROSS_FS/* >/dev/null 2>&1
+}
+
+log_assert "Doing a 'mv' of a large amount of files across two zfs filesystems" \
+           "works without errors."
+
+log_onexit cleanup
+
+mv_test $OLDDIR $NEWDIR_ACROSS_FS
+(($? != 0 )) && \
+        log_fail "'mv' test failed to complete."
+
+log_pass
diff --git a/tests/zfs-tests/tests/functional/mv_files/mv_files_common.kshlib b/tests/zfs-tests/tests/functional/mv_files/mv_files_common.kshlib
new file mode 100644 (file)
index 0000000..32190d8
--- /dev/null
@@ -0,0 +1,217 @@
+#
+# CDDL HEADER START
+#
+# The contents of this file are subject to the terms of the
+# Common Development and Distribution License (the "License").
+# You may not use this file except in compliance with the License.
+#
+# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
+# or http://www.opensolaris.org/os/licensing.
+# See the License for the specific language governing permissions
+# and limitations under the License.
+#
+# When distributing Covered Code, include this CDDL HEADER in each
+# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
+# If applicable, add the following below this CDDL HEADER, with the
+# fields enclosed by brackets "[]" replaced with your own identifying
+# information: Portions Copyright [yyyy] [name of copyright owner]
+#
+# CDDL HEADER END
+#
+
+#
+# Copyright 2009 Sun Microsystems, Inc.  All rights reserved.
+# Use is subject to license terms.
+#
+
+#
+# Copyright (c) 2013 by Delphix. All rights reserved.
+#
+
+. $STF_SUITE/tests/functional/mv_files/mv_files.cfg
+
+#
+# Determine whether this version of the ksh being
+# executed has a bug where the limit of background
+# processes of 25.
+#
+function check_bg_procs_limit_num
+{
+$ECHO "#!/bin/ksh" > /var/tmp/exitsZero.ksh
+$ECHO  "exit 0" >> /var/tmp/exitsZero.ksh
+$CHMOD 777 /var/tmp/exitsZero.ksh
+
+$CAT <<EOF > /var/tmp/testbackgprocs.ksh
+#!/bin/ksh
+#
+# exitsZero.ksh is a one line script
+# that exit with status of "0"
+#
+
+PIDS=""
+typeset -i i=1
+while [ \$i -le 50 ]
+do
+       /var/tmp/exitsZero.ksh &
+        PIDS="\$PIDS \$!"
+        (( i = i + 1 ))
+done
+
+\$SLEEP 1
+
+for pid in \$PIDS
+do
+       \$WAIT \$pid
+        (( \$? == 127 )) && exit 1
+done
+exit 0
+EOF
+
+$KSH /var/tmp/testbackgprocs.ksh
+if [[ $? -eq 1 ]]; then
+#
+# Current ksh being executed has a limit
+# of 25 background processes.
+#
+       return 1
+else
+        return 0
+fi
+}
+
+function init_setup
+{
+
+       typeset disklist=$1
+
+        create_pool $TESTPOOL "$disklist"
+
+       if ! is_global_zone ; then
+               reexport_pool
+       fi
+
+        $RM -rf $TESTDIR  || log_unresolved Could not remove $TESTDIR
+        $MKDIR -p $TESTDIR || log_unresolved Could not create $TESTDIR
+
+        $RM -rf $TESTDIR_TGT  || log_unresolved Could not remove $TESTDIR_TGT
+        $MKDIR -p $TESTDIR_TGT || log_unresolved Could not create $TESTDIR_TGT
+
+        log_must $ZFS create $TESTPOOL/$TESTFS
+        log_must $ZFS set mountpoint=$TESTDIR $TESTPOOL/$TESTFS
+
+        log_must $ZFS create $TESTPOOL/$TESTFS_TGT
+        log_must $ZFS set mountpoint=$TESTDIR_TGT $TESTPOOL/$TESTFS_TGT
+
+        $MKDIR -p $OLDDIR || log_unresolved Could not create $OLDDIR
+        $MKDIR -p $NEWDIR_IN_FS || log_unresolved Could not create $NEWDIR_IN_FS
+        $MKDIR -p $NEWDIR_ACROSS_FS || log_unresolved Could not create $NEWDIR_ACROSS_FS
+
+}
+
+function wait_pid
+{
+       for pid in $1
+       do
+               $PS -e | $GREP $pid >/dev/null 2>&1
+               (( $? == 0 )) && $WAIT $pid
+        done
+}
+
+
+#
+# Generate given number files in a
+# directory of zfs file system
+# $1 - the directory holds the generated files
+# $2 - number of to-be-generated files
+#
+
+function generate_files
+{
+       typeset -i count
+        typeset -i proc_num=0
+
+       if (( $2 == $MVNUMFILES )); then
+               count=1
+       else
+               count=$MVNUMFILES+1
+       fi
+
+        while (( count <= $2 ))
+        do
+                $CP /etc/passwd $1/file_$count \
+                         > /dev/null 2>&1 &
+
+                PIDS="$PIDS $!"
+
+                proc_num=`$ECHO $PIDS | $WC -w`
+                if (( proc_num >= GANGPIDS )); then
+                        wait_pid "$PIDS"
+                        proc_num=0
+                        PIDS=""
+                fi
+
+               (( count = count + 1 ))
+        done
+
+}
+
+#
+# Move given number files from one directory to
+# another directory in parallel
+# $1 - source directory
+# $2 - target directory
+#
+function mv_files
+{
+
+        $FIND $1 -type f -print | xargs -i \
+                $MV {} $2 > /dev/null 2>&1
+}
+
+#
+# Count the files number after moving, and
+# compare it with the original number
+# $1 - directory that to be operated
+# $2 - original files number
+#
+function count_files
+{
+        typeset -i file_num
+        file_num=`$FIND $1  -type f -print | \
+                wc -l`
+        (( file_num != $2 )) && \
+                log_fail "The file number of target directory"\
+                        "$2 is not equal to that of the source "\
+                        "directory $1"
+
+}
+
+#
+# Running the 'mv' test
+# $1 - old directory
+# $2 - new directory
+#
+function mv_test
+{
+        typeset old=$1
+        typeset new=$2
+
+        typeset -i inc_num=$(( MVNUMFILES + MVNUMINCR ))
+        typeset -i num=0
+
+        for num in $MVNUMFILES $inc_num
+        do
+                generate_files $old $num
+
+                mv_files $old $new
+                count_files $new $num
+
+                mv_files $new $old
+                count_files $old $num
+        done
+
+       typeset dir=$(get_device_dir $DISKS)
+        verify_filesys "$TESTPOOL" "$TESTPOOL/$TESTFS" "$dir"
+
+        return 0
+}
diff --git a/tests/zfs-tests/tests/functional/mv_files/setup.ksh b/tests/zfs-tests/tests/functional/mv_files/setup.ksh
new file mode 100755 (executable)
index 0000000..e4e97b1
--- /dev/null
@@ -0,0 +1,47 @@
+#!/bin/ksh -p
+#
+# CDDL HEADER START
+#
+# The contents of this file are subject to the terms of the
+# Common Development and Distribution License (the "License").
+# You may not use this file except in compliance with the License.
+#
+# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
+# or http://www.opensolaris.org/os/licensing.
+# See the License for the specific language governing permissions
+# and limitations under the License.
+#
+# When distributing Covered Code, include this CDDL HEADER in each
+# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
+# If applicable, add the following below this CDDL HEADER, with the
+# fields enclosed by brackets "[]" replaced with your own identifying
+# information: Portions Copyright [yyyy] [name of copyright owner]
+#
+# CDDL HEADER END
+#
+
+#
+# Copyright 2007 Sun Microsystems, Inc.  All rights reserved.
+# Use is subject to license terms.
+#
+
+#
+# Copyright (c) 2013 by Delphix. All rights reserved.
+#
+
+. $STF_SUITE/include/libtest.shlib
+. $STF_SUITE/tests/functional/mv_files/mv_files_common.kshlib
+
+verify_runnable "global"
+
+check_bg_procs_limit_num
+if [[ $? -ne 0 ]]; then
+       log_note "ksh background process limit number is 25"
+       export GANGPIDS=25
+fi
+
+export PIDS=""
+
+init_setup $DISK
+
+log_pass
diff --git a/tests/zfs-tests/tests/functional/nestedfs/Makefile.am b/tests/zfs-tests/tests/functional/nestedfs/Makefile.am
new file mode 100644 (file)
index 0000000..6a5ecf2
--- /dev/null
@@ -0,0 +1,5 @@
+pkgdatadir = $(datadir)/@PACKAGE@/zfs-tests/tests/functional/nestedfs
+dist_pkgdata_SCRIPTS = \
+       setup.ksh \
+       cleanup.ksh \
+       nestedfs_001_pos.ksh
diff --git a/tests/zfs-tests/tests/functional/nestedfs/cleanup.ksh b/tests/zfs-tests/tests/functional/nestedfs/cleanup.ksh
new file mode 100755 (executable)
index 0000000..c4c3691
--- /dev/null
@@ -0,0 +1,34 @@
+#!/bin/ksh -p
+#
+# CDDL HEADER START
+#
+# The contents of this file are subject to the terms of the
+# Common Development and Distribution License (the "License").
+# You may not use this file except in compliance with the License.
+#
+# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
+# or http://www.opensolaris.org/os/licensing.
+# See the License for the specific language governing permissions
+# and limitations under the License.
+#
+# When distributing Covered Code, include this CDDL HEADER in each
+# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
+# If applicable, add the following below this CDDL HEADER, with the
+# fields enclosed by brackets "[]" replaced with your own identifying
+# information: Portions Copyright [yyyy] [name of copyright owner]
+#
+# CDDL HEADER END
+#
+
+#
+# Copyright 2007 Sun Microsystems, Inc.  All rights reserved.
+# Use is subject to license terms.
+#
+
+#
+# Copyright (c) 2013 by Delphix. All rights reserved.
+#
+
+. $STF_SUITE/include/libtest.shlib
+
+default_container_cleanup
diff --git a/tests/zfs-tests/tests/functional/nestedfs/nestedfs_001_pos.ksh b/tests/zfs-tests/tests/functional/nestedfs/nestedfs_001_pos.ksh
new file mode 100755 (executable)
index 0000000..b27dd6e
--- /dev/null
@@ -0,0 +1,59 @@
+#!/bin/ksh -p
+#
+# CDDL HEADER START
+#
+# The contents of this file are subject to the terms of the
+# Common Development and Distribution License (the "License").
+# You may not use this file except in compliance with the License.
+#
+# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
+# or http://www.opensolaris.org/os/licensing.
+# See the License for the specific language governing permissions
+# and limitations under the License.
+#
+# When distributing Covered Code, include this CDDL HEADER in each
+# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
+# If applicable, add the following below this CDDL HEADER, with the
+# fields enclosed by brackets "[]" replaced with your own identifying
+# information: Portions Copyright [yyyy] [name of copyright owner]
+#
+# CDDL HEADER END
+#
+
+#
+# Copyright 2007 Sun Microsystems, Inc.  All rights reserved.
+# Use is subject to license terms.
+#
+
+#
+# Copyright (c) 2013 by Delphix. All rights reserved.
+#
+
+. $STF_SUITE/include/libtest.shlib
+
+#
+# DESCRIPTION:
+# Given a pool create a nested file system and a ZFS file system
+# in the nested file system. Populate the file system.
+#
+# As a sub-assertion, the test verifies that a nested file system with
+# a mounted file system cannot be destroyed.
+#
+# STRATEGY:
+# 1. Create a file in the new mountpoint
+# 2. Unmount the new mountpoint
+# 3. Show a nested file system with file systems cannot be destroyed
+#
+
+verify_runnable "both"
+
+log_assert "Verify a nested file system can be created/destroyed."
+
+log_must $FILE_WRITE -o create -f $TESTDIR1/file -b 8192 -c 600 -d 0
+log_must $ZFS unmount $TESTDIR1
+
+log_note "Verify that a nested file system with a mounted file system "\
+    "cannot be destroyed."
+log_mustnot $ZFS destroy $TESTPOOL/$TESTCTR
+
+log_pass "A nested file system was successfully populated."
diff --git a/tests/zfs-tests/tests/functional/nestedfs/setup.ksh b/tests/zfs-tests/tests/functional/nestedfs/setup.ksh
new file mode 100755 (executable)
index 0000000..677cb12
--- /dev/null
@@ -0,0 +1,36 @@
+#!/bin/ksh -p
+#
+# CDDL HEADER START
+#
+# The contents of this file are subject to the terms of the
+# Common Development and Distribution License (the "License").
+# You may not use this file except in compliance with the License.
+#
+# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
+# or http://www.opensolaris.org/os/licensing.
+# See the License for the specific language governing permissions
+# and limitations under the License.
+#
+# When distributing Covered Code, include this CDDL HEADER in each
+# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
+# If applicable, add the following below this CDDL HEADER, with the
+# fields enclosed by brackets "[]" replaced with your own identifying
+# information: Portions Copyright [yyyy] [name of copyright owner]
+#
+# CDDL HEADER END
+#
+
+#
+# Copyright 2007 Sun Microsystems, Inc.  All rights reserved.
+# Use is subject to license terms.
+#
+
+#
+# Copyright (c) 2013 by Delphix. All rights reserved.
+#
+
+. $STF_SUITE/include/libtest.shlib
+
+DISK=${DISKS%% *}
+
+default_container_setup $DISK
diff --git a/tests/zfs-tests/tests/functional/no_space/Makefile.am b/tests/zfs-tests/tests/functional/no_space/Makefile.am
new file mode 100644 (file)
index 0000000..19a5313
--- /dev/null
@@ -0,0 +1,7 @@
+pkgdatadir = $(datadir)/@PACKAGE@/zfs-tests/tests/functional/no_space
+dist_pkgdata_SCRIPTS = \
+       enospc.cfg \
+       setup.ksh \
+       cleanup.ksh \
+       enospc_001_pos.ksh \
+       enospc_002_pos.ksh
diff --git a/tests/zfs-tests/tests/functional/no_space/cleanup.ksh b/tests/zfs-tests/tests/functional/no_space/cleanup.ksh
new file mode 100755 (executable)
index 0000000..1ed7ee1
--- /dev/null
@@ -0,0 +1,49 @@
+#!/bin/ksh -p
+#
+# CDDL HEADER START
+#
+# The contents of this file are subject to the terms of the
+# Common Development and Distribution License (the "License").
+# You may not use this file except in compliance with the License.
+#
+# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
+# or http://www.opensolaris.org/os/licensing.
+# See the License for the specific language governing permissions
+# and limitations under the License.
+#
+# When distributing Covered Code, include this CDDL HEADER in each
+# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
+# If applicable, add the following below this CDDL HEADER, with the
+# fields enclosed by brackets "[]" replaced with your own identifying
+# information: Portions Copyright [yyyy] [name of copyright owner]
+#
+# CDDL HEADER END
+#
+
+#
+# Copyright 2009 Sun Microsystems, Inc.  All rights reserved.
+# Use is subject to license terms.
+#
+#
+# Copyright (c) 2013 by Delphix. All rights reserved.
+#
+
+. $STF_SUITE/include/libtest.shlib
+. $STF_SUITE/tests/functional/no_space/enospc.cfg
+
+verify_runnable "global"
+
+DISK=${DISKS%% *}
+
+ismounted "$TESTPOOL/$TESTFS"
+(( $? == 0 )) && \
+        log_must $ZFS umount $TESTDIR
+
+destroy_pool $TESTPOOL
+#
+# Remove 100mb partition.
+#
+create_pool dummy$$ "$DISK"
+destroy_pool dummy$$
+
+log_pass
diff --git a/tests/zfs-tests/tests/functional/no_space/enospc.cfg b/tests/zfs-tests/tests/functional/no_space/enospc.cfg
new file mode 100644 (file)
index 0000000..692482a
--- /dev/null
@@ -0,0 +1,38 @@
+#
+# CDDL HEADER START
+#
+# The contents of this file are subject to the terms of the
+# Common Development and Distribution License (the "License").
+# You may not use this file except in compliance with the License.
+#
+# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
+# or http://www.opensolaris.org/os/licensing.
+# See the License for the specific language governing permissions
+# and limitations under the License.
+#
+# When distributing Covered Code, include this CDDL HEADER in each
+# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
+# If applicable, add the following below this CDDL HEADER, with the
+# fields enclosed by brackets "[]" replaced with your own identifying
+# information: Portions Copyright [yyyy] [name of copyright owner]
+#
+# CDDL HEADER END
+#
+
+#
+# Copyright 2008 Sun Microsystems, Inc.  All rights reserved.
+# Use is subject to license terms.
+#
+
+#
+# Copyright (c) 2013 by Delphix. All rights reserved.
+#
+
+export TESTFILE0=testfile0.$$
+export TESTFILE1=testfile1.$$
+
+export SIZE=100mb
+export ENOSPC=28
+export BLOCKSZ=8192
+export NUM_WRITES=65536
+export DATA=0
diff --git a/tests/zfs-tests/tests/functional/no_space/enospc_001_pos.ksh b/tests/zfs-tests/tests/functional/no_space/enospc_001_pos.ksh
new file mode 100755 (executable)
index 0000000..7b20eb7
--- /dev/null
@@ -0,0 +1,76 @@
+#!/bin/ksh -p
+#
+# CDDL HEADER START
+#
+# The contents of this file are subject to the terms of the
+# Common Development and Distribution License (the "License").
+# You may not use this file except in compliance with the License.
+#
+# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
+# or http://www.opensolaris.org/os/licensing.
+# See the License for the specific language governing permissions
+# and limitations under the License.
+#
+# When distributing Covered Code, include this CDDL HEADER in each
+# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
+# If applicable, add the following below this CDDL HEADER, with the
+# fields enclosed by brackets "[]" replaced with your own identifying
+# information: Portions Copyright [yyyy] [name of copyright owner]
+#
+# CDDL HEADER END
+#
+
+#
+# Copyright 2007 Sun Microsystems, Inc.  All rights reserved.
+# Use is subject to license terms.
+#
+#
+# Copyright (c) 2013, 2014 by Delphix. All rights reserved.
+#
+
+. $STF_SUITE/include/libtest.shlib
+. $STF_SUITE/tests/functional/no_space/enospc.cfg
+
+#
+# DESCRIPTION:
+# ENOSPC is returned on an attempt to write a second file
+# to a file system after a first file was written that terminated
+# with ENOSPC on a cleanly initialized file system.
+#
+# STRATEGY:
+# 1. Write a file until the file system is full.
+# 2. Ensure that ENOSPC is returned.
+# 3. Write a second file while the file system remains full.
+# 4. Verify the return code is ENOSPC.
+#
+
+verify_runnable "both"
+
+function cleanup
+{
+       rm -f $TESTDIR/$TESTFILE0
+       rm -f $TESTDIR/$TESTFILE1
+}
+
+log_onexit cleanup
+
+log_assert "ENOSPC is returned when file system is full."
+log_must $ZFS set compression=off $TESTPOOL/$TESTFS
+
+log_note "Writing file: $TESTFILE0 until ENOSPC."
+$FILE_WRITE -o create -f $TESTDIR/$TESTFILE0 -b $BLOCKSZ \
+    -c $NUM_WRITES -d $DATA
+ret=$?
+
+(( $ret != $ENOSPC )) && \
+    log_fail "$TESTFILE0 returned: $ret rather than ENOSPC."
+
+log_note "Write another file: $TESTFILE1 but expect ENOSPC."
+$FILE_WRITE -o create -f $TESTDIR/$TESTFILE1 -b $BLOCKSZ \
+    -c $NUM_WRITES -d $DATA
+ret=$?
+
+(( $ret != $ENOSPC )) && \
+    log_fail "$TESTFILE1 returned: $ret rather than ENOSPC."
+
+log_pass "ENOSPC returned as expected."
diff --git a/tests/zfs-tests/tests/functional/no_space/enospc_002_pos.ksh b/tests/zfs-tests/tests/functional/no_space/enospc_002_pos.ksh
new file mode 100644 (file)
index 0000000..25d88d7
--- /dev/null
@@ -0,0 +1,74 @@
+#!/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) 2014 by Delphix. All rights reserved.
+#
+
+. $STF_SUITE/include/libtest.shlib
+. $STF_SUITE/tests/functional/no_space/enospc.cfg
+
+#
+# DESCRIPTION:
+# After filling a filesystem, certain zfs commands are allowed.
+#
+
+verify_runnable "both"
+
+log_assert "ENOSPC is returned when file system is full."
+sync
+log_must $ZFS set compression=off $TESTPOOL/$TESTFS
+log_must $ZFS snapshot $TESTPOOL/$TESTFS@snap
+
+log_note "Writing file: $TESTFILE0 until ENOSPC."
+$FILE_WRITE -o create -f $TESTDIR/$TESTFILE0 -b $BLOCKSZ \
+    -c $NUM_WRITES -d $DATA
+ret=$?
+
+(( $ret != $ENOSPC )) && \
+    log_fail "$TESTFILE0 returned: $ret rather than ENOSPC."
+
+log_mustnot_expect space $ZFS create $TESTPOOL/$TESTFS/subfs
+log_mustnot_expect space $ZFS clone $TESTPOOL/$TESTFS@snap $TESTPOOL/clone
+log_mustnot_expect space $ZFS snapshot $TESTPOOL/$TESTFS@snap2
+log_mustnot_expect space $ZFS bookmark \
+    $TESTPOOL/$TESTFS@snap $TESTPOOL/$TESTFS#bookmark
+
+log_must $ZFS send $TESTPOOL/$TESTFS@snap >/tmp/stream.$$
+log_mustnot_expect space $ZFS receive $TESTPOOL/$TESTFS/recvd </tmp/stream.$$
+log_must rm /tmp/stream.$$
+
+log_must $ZFS rename $TESTPOOL/$TESTFS@snap $TESTPOOL/$TESTFS@snap_newname
+log_must $ZFS rename $TESTPOOL/$TESTFS@snap_newname $TESTPOOL/$TESTFS@snap
+log_must $ZFS rename $TESTPOOL/$TESTFS $TESTPOOL/${TESTFS}_newname
+log_must $ZFS rename $TESTPOOL/${TESTFS}_newname $TESTPOOL/$TESTFS
+log_must $ZFS allow staff snapshot $TESTPOOL/$TESTFS
+log_must $ZFS unallow staff snapshot $TESTPOOL/$TESTFS
+log_must $ZFS set user:prop=value $TESTPOOL/$TESTFS
+log_must $ZFS set quota=1EB $TESTPOOL/$TESTFS
+log_must $ZFS set quota=none $TESTPOOL/$TESTFS
+log_must $ZFS set reservation=1KB $TESTPOOL/$TESTFS
+log_must $ZFS set reservation=none $TESTPOOL/$TESTFS
+log_must $ZPOOL scrub $TESTPOOL
+$ZPOOL scrub -s $TESTPOOL
+log_must $ZPOOL set comment="Use the force, Luke." $TESTPOOL
+log_must $ZPOOL set comment="" $TESTPOOL
+
+# destructive tests must come last
+log_must $ZFS rollback $TESTPOOL/$TESTFS@snap
+log_must $ZFS destroy $TESTPOOL/$TESTFS@snap
+
+log_pass "ENOSPC returned as expected."
diff --git a/tests/zfs-tests/tests/functional/no_space/setup.ksh b/tests/zfs-tests/tests/functional/no_space/setup.ksh
new file mode 100755 (executable)
index 0000000..5bd8918
--- /dev/null
@@ -0,0 +1,49 @@
+#!/bin/ksh -p
+#
+# CDDL HEADER START
+#
+# The contents of this file are subject to the terms of the
+# Common Development and Distribution License (the "License").
+# You may not use this file except in compliance with the License.
+#
+# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
+# or http://www.opensolaris.org/os/licensing.
+# See the License for the specific language governing permissions
+# and limitations under the License.
+#
+# When distributing Covered Code, include this CDDL HEADER in each
+# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
+# If applicable, add the following below this CDDL HEADER, with the
+# fields enclosed by brackets "[]" replaced with your own identifying
+# information: Portions Copyright [yyyy] [name of copyright owner]
+#
+# CDDL HEADER END
+#
+
+#
+# Copyright 2009 Sun Microsystems, Inc.  All rights reserved.
+# Use is subject to license terms.
+#
+
+#
+# Copyright (c) 2013 by Delphix. All rights reserved.
+#
+
+. $STF_SUITE/include/libtest.shlib
+. $STF_SUITE/tests/functional/no_space/enospc.cfg
+
+verify_runnable "global"
+
+if ! $(is_physical_device $DISKS) ; then
+       log_unsupported "This directory cannot be run on raw files."
+fi
+
+DISK=${DISKS%% *}
+
+log_must set_partition 0 "" $SIZE $DISK
+
+if is_linux; then
+       default_setup $DISK"p1"
+else
+       default_setup $DISK"s0"
+fi
diff --git a/tests/zfs-tests/tests/functional/nopwrite/Makefile.am b/tests/zfs-tests/tests/functional/nopwrite/Makefile.am
new file mode 100644 (file)
index 0000000..c7c90e3
--- /dev/null
@@ -0,0 +1,13 @@
+pkgdatadir = $(datadir)/@PACKAGE@/zfs-tests/tests/functional/nopwrite
+dist_pkgdata_SCRIPTS = \
+       setup.ksh \
+       cleanup.ksh \
+       nopwrite.shlib \
+       nopwrite_copies.ksh \
+       nopwrite_mtime.ksh \
+       nopwrite_negative.ksh \
+       nopwrite_promoted_clone.ksh \
+       nopwrite_recsize.ksh \
+       nopwrite_sync.ksh \
+       nopwrite_varying_compression.ksh \
+       nopwrite_volume.ksh
diff --git a/tests/zfs-tests/tests/functional/nopwrite/cleanup.ksh b/tests/zfs-tests/tests/functional/nopwrite/cleanup.ksh
new file mode 100755 (executable)
index 0000000..2d7b69a
--- /dev/null
@@ -0,0 +1,20 @@
+#!/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
diff --git a/tests/zfs-tests/tests/functional/nopwrite/nopwrite.shlib b/tests/zfs-tests/tests/functional/nopwrite/nopwrite.shlib
new file mode 100644 (file)
index 0000000..a03bc54
--- /dev/null
@@ -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
+}
diff --git a/tests/zfs-tests/tests/functional/nopwrite/nopwrite_copies.ksh b/tests/zfs-tests/tests/functional/nopwrite/nopwrite_copies.ksh
new file mode 100755 (executable)
index 0000000..94a846a
--- /dev/null
@@ -0,0 +1,71 @@
+#!/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"
diff --git a/tests/zfs-tests/tests/functional/nopwrite/nopwrite_mtime.ksh b/tests/zfs-tests/tests/functional/nopwrite/nopwrite_mtime.ksh
new file mode 100755 (executable)
index 0000000..23d4be2
--- /dev/null
@@ -0,0 +1,81 @@
+#!/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
+
+if is_linux; then
+       o_atime=$(stat -c %X $TESTDIR/clone/file)
+       o_ctime=$(stat -c %Z $TESTDIR/clone/file)
+       o_mtime=$(stat -c %Y $TESTDIR/clone/file)
+else
+       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}')
+fi
+
+$SLEEP 1
+$DD if=/$TESTDIR/file of=/$TESTDIR/clone/file bs=1024k count=$MEGS \
+    conv=notrunc >/dev/null 2>&1 || log_fail "dd failed."
+$SLEEP 1
+
+if is_linux; then
+       atime=$(stat -c %X $TESTDIR/clone/file)
+       ctime=$(stat -c %Z $TESTDIR/clone/file)
+       mtime=$(stat -c %Y $TESTDIR/clone/file)
+else
+       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}')
+fi
+
+[[ $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"
diff --git a/tests/zfs-tests/tests/functional/nopwrite/nopwrite_negative.ksh b/tests/zfs-tests/tests/functional/nopwrite/nopwrite_negative.ksh
new file mode 100755 (executable)
index 0000000..921d17f
--- /dev/null
@@ -0,0 +1,90 @@
+#!/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"
diff --git a/tests/zfs-tests/tests/functional/nopwrite/nopwrite_promoted_clone.ksh b/tests/zfs-tests/tests/functional/nopwrite/nopwrite_promoted_clone.ksh
new file mode 100755 (executable)
index 0000000..7a21aa5
--- /dev/null
@@ -0,0 +1,58 @@
+#!/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."
diff --git a/tests/zfs-tests/tests/functional/nopwrite/nopwrite_recsize.ksh b/tests/zfs-tests/tests/functional/nopwrite/nopwrite_recsize.ksh
new file mode 100755 (executable)
index 0000000..a3c272c
--- /dev/null
@@ -0,0 +1,57 @@
+#!/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"
diff --git a/tests/zfs-tests/tests/functional/nopwrite/nopwrite_sync.ksh b/tests/zfs-tests/tests/functional/nopwrite/nopwrite_sync.ksh
new file mode 100755 (executable)
index 0000000..d6cc66f
--- /dev/null
@@ -0,0 +1,55 @@
+#!/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"
diff --git a/tests/zfs-tests/tests/functional/nopwrite/nopwrite_varying_compression.ksh b/tests/zfs-tests/tests/functional/nopwrite/nopwrite_varying_compression.ksh
new file mode 100755 (executable)
index 0000000..12450f8
--- /dev/null
@@ -0,0 +1,64 @@
+#!/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"
diff --git a/tests/zfs-tests/tests/functional/nopwrite/nopwrite_volume.ksh b/tests/zfs-tests/tests/functional/nopwrite/nopwrite_volume.ksh
new file mode 100755 (executable)
index 0000000..28c1dfa
--- /dev/null
@@ -0,0 +1,58 @@
+#!/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="${ZVOL_RDEVDIR}/$origin"
+volclone="${ZVOL_RDEVDIR}/$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"
diff --git a/tests/zfs-tests/tests/functional/nopwrite/setup.ksh b/tests/zfs-tests/tests/functional/nopwrite/setup.ksh
new file mode 100755 (executable)
index 0000000..17c68a6
--- /dev/null
@@ -0,0 +1,23 @@
+#!/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
diff --git a/tests/zfs-tests/tests/functional/online_offline/Makefile.am b/tests/zfs-tests/tests/functional/online_offline/Makefile.am
new file mode 100644 (file)
index 0000000..9562ba5
--- /dev/null
@@ -0,0 +1,8 @@
+pkgdatadir = $(datadir)/@PACKAGE@/zfs-tests/tests/functional/online_offline
+dist_pkgdata_SCRIPTS = \
+       online_offline.cfg \
+       setup.ksh \
+       cleanup.ksh \
+       online_offline_001_pos.ksh \
+       online_offline_002_neg.ksh \
+       online_offline_003_neg.ksh
diff --git a/tests/zfs-tests/tests/functional/online_offline/cleanup.ksh b/tests/zfs-tests/tests/functional/online_offline/cleanup.ksh
new file mode 100755 (executable)
index 0000000..b81a372
--- /dev/null
@@ -0,0 +1,36 @@
+#!/bin/ksh -p
+#
+# CDDL HEADER START
+#
+# The contents of this file are subject to the terms of the
+# Common Development and Distribution License (the "License").
+# You may not use this file except in compliance with the License.
+#
+# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
+# or http://www.opensolaris.org/os/licensing.
+# See the License for the specific language governing permissions
+# and limitations under the License.
+#
+# When distributing Covered Code, include this CDDL HEADER in each
+# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
+# If applicable, add the following below this CDDL HEADER, with the
+# fields enclosed by brackets "[]" replaced with your own identifying
+# information: Portions Copyright [yyyy] [name of copyright owner]
+#
+# CDDL HEADER END
+#
+
+#
+# Copyright 2007 Sun Microsystems, Inc.  All rights reserved.
+# Use is subject to license terms.
+#
+
+#
+# Copyright (c) 2013 by Delphix. All rights reserved.
+#
+
+. $STF_SUITE/include/libtest.shlib
+
+verify_runnable "global"
+
+default_cleanup
diff --git a/tests/zfs-tests/tests/functional/online_offline/online_offline.cfg b/tests/zfs-tests/tests/functional/online_offline/online_offline.cfg
new file mode 100644 (file)
index 0000000..e68e836
--- /dev/null
@@ -0,0 +1,38 @@
+#
+# CDDL HEADER START
+#
+# The contents of this file are subject to the terms of the
+# Common Development and Distribution License (the "License").
+# You may not use this file except in compliance with the License.
+#
+# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
+# or http://www.opensolaris.org/os/licensing.
+# See the License for the specific language governing permissions
+# and limitations under the License.
+#
+# When distributing Covered Code, include this CDDL HEADER in each
+# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
+# If applicable, add the following below this CDDL HEADER, with the
+# fields enclosed by brackets "[]" replaced with your own identifying
+# information: Portions Copyright [yyyy] [name of copyright owner]
+#
+# CDDL HEADER END
+#
+
+#
+# Copyright 2008 Sun Microsystems, Inc.  All rights reserved.
+# Use is subject to license terms.
+#
+
+#
+# Copyright (c) 2013 by Delphix. All rights reserved.
+#
+
+export TESTFILE=testfile.$$
+export TESTFILE1=testfile1.$$
+export HOLES_FILESIZE=${HOLES_FILESIZE-"67108864"} # 64 Mb
+export HOLES_BLKSIZE=${HOLES_BLKSIZE-"512"}
+export HOLES_SEED=${HOLES_SEED-""}
+export HOLES_FILEOFFSET=${HOLES_FILEOFFSET-""}
+export HOLES_COUNT=${HOLES_COUNT-"16384"}         # FILESIZE/BLKSIZE/8
+export STF_TIMEOUT=3600
diff --git a/tests/zfs-tests/tests/functional/online_offline/online_offline_001_pos.ksh b/tests/zfs-tests/tests/functional/online_offline/online_offline_001_pos.ksh
new file mode 100755 (executable)
index 0000000..d98ef7f
--- /dev/null
@@ -0,0 +1,94 @@
+#!/bin/ksh -p
+#
+# CDDL HEADER START
+#
+# The contents of this file are subject to the terms of the
+# Common Development and Distribution License (the "License").
+# You may not use this file except in compliance with the License.
+#
+# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
+# or http://www.opensolaris.org/os/licensing.
+# See the License for the specific language governing permissions
+# and limitations under the License.
+#
+# When distributing Covered Code, include this CDDL HEADER in each
+# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
+# If applicable, add the following below this CDDL HEADER, with the
+# fields enclosed by brackets "[]" replaced with your own identifying
+# information: Portions Copyright [yyyy] [name of copyright owner]
+#
+# CDDL HEADER END
+#
+
+#
+# Copyright 2009 Sun Microsystems, Inc.  All rights reserved.
+# Use is subject to license terms.
+#
+
+#
+# Copyright (c) 2013, 2014 by Delphix. All rights reserved.
+#
+
+. $STF_SUITE/include/libtest.shlib
+
+#
+# DESCRIPTION:
+# Turning a disk offline and back online during I/O completes.
+#
+# STRATEGY:
+# 1. Create a mirror and start some random I/O
+# 2. For each disk in the mirror, set it offline and online
+# 3. Verify the integrity of the file system and the resilvering.
+#
+
+verify_runnable "global"
+log_onexit cleanup
+
+DISKLIST=$(get_disklist $TESTPOOL)
+
+function cleanup
+{
+       #
+       # Ensure we don't leave disks in the offline state
+       #
+       for disk in $DISKLIST; do
+               log_must $ZPOOL online $TESTPOOL $disk
+               check_state $TESTPOOL $disk "online"
+               if [[ $? != 0 ]]; then
+                       log_fail "Unable to online $disk"
+               fi
+
+       done
+
+       $KILL $killpid >/dev/null 2>&1
+       [[ -e $TESTDIR ]] && log_must $RM -rf $TESTDIR/*
+}
+
+log_assert "Turning a disk offline and back online during I/O completes."
+
+$FILE_TRUNC -f $((64 * 1024 * 1024)) -b 8192 -c 0 -r $TESTDIR/$TESTFILE1 &
+typeset killpid="$! "
+
+for disk in $DISKLIST; do
+        for i in 'do_offline' 'do_offline_while_already_offline'; do
+               log_must $ZPOOL offline $TESTPOOL $disk
+               check_state $TESTPOOL $disk "offline"
+                if [[ $? != 0 ]]; then
+                        log_fail "$disk of $TESTPOOL is not offline."
+                fi
+        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_must $KILL $killpid
+$SYNC
+
+typeset dir=$(get_device_dir $DISKS)
+verify_filesys "$TESTPOOL" "$TESTPOOL/$TESTFS" "$dir"
+
+log_pass
diff --git a/tests/zfs-tests/tests/functional/online_offline/online_offline_002_neg.ksh b/tests/zfs-tests/tests/functional/online_offline/online_offline_002_neg.ksh
new file mode 100755 (executable)
index 0000000..12c191a
--- /dev/null
@@ -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 2009 Sun Microsystems, Inc.  All rights reserved.
+# Use is subject to license terms.
+#
+
+#
+# Copyright (c) 2013, 2014 by Delphix. All rights reserved.
+#
+
+. $STF_SUITE/include/libtest.shlib
+
+#
+# DESCRIPTION:
+# Turning disks in a pool offline should fail when there is no longer
+# sufficient redundancy.
+#
+# STRATEGY:
+# 1. Start some random I/O on the mirror or raidz.
+# 2. Verify that we can offline as many disks as the redundancy level
+# will support, but not more.
+# 3. Verify the integrity of the file system and the resilvering.
+#
+
+verify_runnable "global"
+
+DISKLIST=$(get_disklist $TESTPOOL)
+
+function cleanup
+{
+       #
+       # Ensure we don't leave disks in the offline state
+       #
+       for disk in $DISKLIST; do
+               log_must $ZPOOL online $TESTPOOL $disk
+               check_state $TESTPOOL $disk "online"
+               if [[ $? != 0 ]]; then
+                       log_fail "Unable to online $disk"
+               fi
+
+       done
+
+       $KILL $killpid >/dev/null 2>&1
+       [[ -e $TESTDIR ]] && log_must $RM -rf $TESTDIR/*
+}
+
+log_assert "Turning both disks offline should fail."
+
+log_onexit cleanup
+
+$FILE_TRUNC -f $((64 * 1024 * 1024)) -b 8192 -c 0 -r $TESTDIR/$TESTFILE1 &
+typeset killpid="$! "
+
+disks=($DISKLIST)
+
+#
+# The setup script will give us either a mirror or a raidz. The former can have
+# all but one vdev offlined, whereas with raidz there can be only one.
+#
+pooltype='mirror'
+$ZPOOL list -v $TESTPOOL | $GREP raidz >/dev/null 2>&1 && pooltype='raidz'
+
+typeset -i i=0
+while [[ $i -lt ${#disks[*]} ]]; do
+       typeset -i j=0
+       if [[ $pooltype = 'mirror' ]]; then
+               # Hold one disk online, verify the others can be offlined.
+               log_must $ZPOOL online $TESTPOOL ${disks[$i]}
+               check_state $TESTPOOL ${disks[$i]} "online" || \
+                   log_fail "Failed to set ${disks[$i]} online"
+               while [[ $j -lt ${#disks[*]} ]]; do
+                       if [[ $j -eq $i ]]; then
+                               ((j++))
+                               continue
+                       fi
+                       log_must $ZPOOL offline $TESTPOOL ${disks[$j]}
+                       check_state $TESTPOOL ${disks[$j]} "offline" || \
+                           log_fail "Failed to set ${disks[$j]} offline"
+                       ((j++))
+               done
+       elif [[ $pooltype = 'raidz' ]]; then
+               # Hold one disk offline, verify the others can't be offlined.
+               log_must $ZPOOL offline $TESTPOOL ${disks[$i]}
+               check_state $TESTPOOL ${disks[$i]} "offline" || \
+                   log_fail "Failed to set ${disks[$i]} offline"
+               while [[ $j -lt ${#disks[*]} ]]; do
+                       if [[ $j -eq $i ]]; then
+                               ((j++))
+                               continue
+                       fi
+                       log_mustnot $ZPOOL offline $TESTPOOL ${disks[$j]}
+                       check_state $TESTPOOL ${disks[$j]} "online" || \
+                           log_fail "Failed to set ${disks[$j]} online"
+                       check_state $TESTPOOL ${disks[$i]} "offline" || \
+                           log_fail "Failed to set ${disks[$i]} offline"
+                       ((j++))
+               done
+               log_must $ZPOOL online $TESTPOOL ${disks[$i]}
+               check_state $TESTPOOL ${disks[$i]} "online" || \
+                   log_fail "Failed to set ${disks[$i]} online"
+       fi
+       ((i++))
+done
+
+log_must $KILL $killpid
+$SYNC
+
+typeset dir=$(get_device_dir $DISKS)
+verify_filesys "$TESTPOOL" "$TESTPOOL/$TESTFS" "$dir"
+
+log_pass
diff --git a/tests/zfs-tests/tests/functional/online_offline/online_offline_003_neg.ksh b/tests/zfs-tests/tests/functional/online_offline/online_offline_003_neg.ksh
new file mode 100755 (executable)
index 0000000..a9d0c33
--- /dev/null
@@ -0,0 +1,81 @@
+#!/bin/ksh -p
+#
+# CDDL HEADER START
+#
+# The contents of this file are subject to the terms of the
+# Common Development and Distribution License (the "License").
+# You may not use this file except in compliance with the License.
+#
+# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
+# or http://www.opensolaris.org/os/licensing.
+# See the License for the specific language governing permissions
+# and limitations under the License.
+#
+# When distributing Covered Code, include this CDDL HEADER in each
+# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
+# If applicable, add the following below this CDDL HEADER, with the
+# fields enclosed by brackets "[]" replaced with your own identifying
+# information: Portions Copyright [yyyy] [name of copyright owner]
+#
+# CDDL HEADER END
+#
+
+#
+# Copyright 2008 Sun Microsystems, Inc.  All rights reserved.
+# Use is subject to license terms.
+#
+
+#
+# Copyright (c) 2013, 2014 by Delphix. All rights reserved.
+#
+
+. $STF_SUITE/include/libtest.shlib
+
+#
+# DESCRIPTION:
+# Offlining disks in a non-redundant pool should fail.
+#
+# STRATEGY:
+# 1. Create a multidisk stripe and start some random I/O
+# 2. zpool offline should fail on each disk.
+#
+
+verify_runnable "global"
+
+function cleanup
+{
+       if poolexists $TESTPOOL1; then
+               destroy_pool $TESTPOOL1
+       fi
+
+       $KILL $killpid >/dev/null 2>&1
+       [[ -e $TESTDIR ]] && log_must $RM -rf $TESTDIR/*
+}
+
+log_assert "Offlining disks in a non-redundant pool should fail."
+
+log_onexit cleanup
+
+specials_list=""
+for i in 0 1 2; do
+       $MKFILE 64m $TESTDIR/$TESTFILE1.$i
+       specials_list="$specials_list $TESTDIR/$TESTFILE1.$i"
+done
+disk=($specials_list)
+
+create_pool $TESTPOOL1 $specials_list
+log_must $ZFS create $TESTPOOL1/$TESTFS1
+log_must $ZFS set mountpoint=$TESTDIR1 $TESTPOOL1/$TESTFS1
+
+$FILE_TRUNC -f $((64 * 1024 * 1024)) -b 8192 -c 0 -r $TESTDIR/$TESTFILE1 &
+typeset killpid="$! "
+
+for i in 0 1 2; do
+       log_mustnot $ZPOOL offline $TESTPOOL1 ${disk[$i]}
+       check_state $TESTPOOL1 ${disk[$i]} "online"
+done
+
+log_must $KILL $killpid
+$SYNC
+
+log_pass
diff --git a/tests/zfs-tests/tests/functional/online_offline/setup.ksh b/tests/zfs-tests/tests/functional/online_offline/setup.ksh
new file mode 100755 (executable)
index 0000000..4132392
--- /dev/null
@@ -0,0 +1,47 @@
+#!/bin/ksh -p
+#
+# CDDL HEADER START
+#
+# The contents of this file are subject to the terms of the
+# Common Development and Distribution License (the "License").
+# You may not use this file except in compliance with the License.
+#
+# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
+# or http://www.opensolaris.org/os/licensing.
+# See the License for the specific language governing permissions
+# and limitations under the License.
+#
+# When distributing Covered Code, include this CDDL HEADER in each
+# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
+# If applicable, add the following below this CDDL HEADER, with the
+# fields enclosed by brackets "[]" replaced with your own identifying
+# information: Portions Copyright [yyyy] [name of copyright owner]
+#
+# CDDL HEADER END
+#
+
+#
+# Copyright 2009 Sun Microsystems, Inc.  All rights reserved.
+# Use is subject to license terms.
+#
+
+#
+# Copyright (c) 2013 by Delphix. All rights reserved.
+#
+
+. $STF_SUITE/include/libtest.shlib
+
+verify_runnable "global"
+verify_disk_count "$DISKS" 2
+
+index=`expr $RANDOM % 2`
+case $index in
+0)     log_note "Pool Type: Mirror"
+       default_mirror_setup $DISKS
+       ;;
+1)     log_note "Pool Type: RAID-Z"
+       default_raidz_setup $DISKS
+       ;;
+esac
+
+log_pass
diff --git a/tests/zfs-tests/tests/functional/pool_names/Makefile.am b/tests/zfs-tests/tests/functional/pool_names/Makefile.am
new file mode 100644 (file)
index 0000000..cd87486
--- /dev/null
@@ -0,0 +1,4 @@
+pkgdatadir = $(datadir)/@PACKAGE@/zfs-tests/tests/functional/pool_names
+dist_pkgdata_SCRIPTS = \
+       pool_names_001_pos.ksh \
+       pool_names_002_neg.ksh
diff --git a/tests/zfs-tests/tests/functional/pool_names/pool_names_001_pos.ksh b/tests/zfs-tests/tests/functional/pool_names/pool_names_001_pos.ksh
new file mode 100755 (executable)
index 0000000..ad10740
--- /dev/null
@@ -0,0 +1,115 @@
+#!/bin/ksh -p
+#
+# CDDL HEADER START
+#
+# The contents of this file are subject to the terms of the
+# Common Development and Distribution License (the "License").
+# You may not use this file except in compliance with the License.
+#
+# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
+# or http://www.opensolaris.org/os/licensing.
+# See the License for the specific language governing permissions
+# and limitations under the License.
+#
+# When distributing Covered Code, include this CDDL HEADER in each
+# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
+# If applicable, add the following below this CDDL HEADER, with the
+# fields enclosed by brackets "[]" replaced with your own identifying
+# information: Portions Copyright [yyyy] [name of copyright owner]
+#
+# CDDL HEADER END
+#
+
+#
+# Copyright 2007 Sun Microsystems, Inc.  All rights reserved.
+# Use is subject to license terms.
+#
+
+#
+# Copyright (c) 2013 by Delphix. All rights reserved.
+#
+
+. $STF_SUITE/include/libtest.shlib
+
+#
+# DESCRIPTION:
+#
+# Test that a set of valid names can be used to create pools. Further
+# verify that the created pools can be destroyed.
+#
+# STRATEGY:
+# 1) For each valid character in the character set, try to create
+# and destroy the pool.
+# 2) Given a list of valid pool names, try to create and destroy
+# pools with the given names.
+#
+
+verify_runnable "global"
+
+log_assert "Ensure that pool names can use the ASCII subset of UTF-8"
+
+function cleanup
+{
+       if [[ -n $name ]] && poolexists $name ; then
+               log_must $ZPOOL destroy $name
+       fi
+
+       if [[ -d $TESTDIR ]]; then
+               log_must $RM -rf $TESTDIR
+       fi
+
+}
+
+log_onexit cleanup
+
+DISK=${DISKS%% *}
+if [[ ! -e $TESTDIR ]]; then
+       log_must $MKDIR $TESTDIR
+fi
+
+log_note "Ensure letters of the alphabet are allowable"
+
+typeset name=""
+
+for name in A B C D E F G H I J K L M \
+    N O P Q R S T U V W X Y Z \
+    a b c d e f g h i j k l m \
+    n o p q r s t u v w x y z
+do
+       log_must $ZPOOL create -m $TESTDIR $name $DISK
+       if ! poolexists $name; then
+               log_fail "Could not create a pool called '$name'"
+       fi
+
+       log_must $ZPOOL destroy $name
+done
+
+log_note "Ensure a variety of unusual names passes"
+
+name=""
+
+for name in "a.............................." "a_" "a-" "a:" \
+    "a." "a123456" "bc0t0d0" "m1rr0r_p00l" "ra1dz_p00l" \
+    "araidz2" "C0t2d0" "cc0t0" "raid2:-_." "mirr_:-." \
+    "m1rr0r-p00l" "ra1dz-p00l" "spar3_p00l" \
+    "spar3-p00l" "hiddenmirrorpool" "hiddenraidzpool" \
+    "hiddensparepool"
+do
+       log_must $ZPOOL create -m $TESTDIR $name $DISK
+       if ! poolexists $name; then
+               log_fail "Could not create a pool called '$name'"
+       fi
+
+       #
+       # Since the naming convention applies to datasets too,
+       # create datasets with the same names as above.
+       #
+       log_must $ZFS create $name/$name
+       log_must $ZFS snapshot $name/$name@$name
+       log_must $ZFS clone $name/$name@$name $name/clone_$name
+       log_must $ZFS create -V 150m $name/$name/$name
+
+       log_must $ZPOOL destroy $name
+done
+
+log_pass "Valid pool names were accepted correctly."
diff --git a/tests/zfs-tests/tests/functional/pool_names/pool_names_002_neg.ksh b/tests/zfs-tests/tests/functional/pool_names/pool_names_002_neg.ksh
new file mode 100755 (executable)
index 0000000..d54fddf
--- /dev/null
@@ -0,0 +1,131 @@
+#!/bin/ksh -p
+#
+# CDDL HEADER START
+#
+# The contents of this file are subject to the terms of the
+# Common Development and Distribution License (the "License").
+# You may not use this file except in compliance with the License.
+#
+# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
+# or http://www.opensolaris.org/os/licensing.
+# See the License for the specific language governing permissions
+# and limitations under the License.
+#
+# When distributing Covered Code, include this CDDL HEADER in each
+# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
+# If applicable, add the following below this CDDL HEADER, with the
+# fields enclosed by brackets "[]" replaced with your own identifying
+# information: Portions Copyright [yyyy] [name of copyright owner]
+#
+# CDDL HEADER END
+#
+
+#
+# Copyright 2008 Sun Microsystems, Inc.  All rights reserved.
+# Use is subject to license terms.
+#
+
+#
+# Copyright (c) 2013 by Delphix. All rights reserved.
+#
+
+. $STF_SUITE/include/libtest.shlib
+
+#
+# DESCRIPTION:
+#
+# Ensure that a set of invalid names cannot be used to create pools.
+#
+# STRATEGY:
+# 1) For each invalid character in the character set, try to create
+# and destroy the pool. Verify it fails.
+# 2) Given a list of invalid pool names, ensure the pools are not
+# created.
+#
+
+verify_runnable "global"
+
+log_assert "Ensure that a set of invalid names cannot be used to create pools."
+
+# Global variable use to cleanup failures.
+POOLNAME=""
+
+function cleanup
+{
+       if poolexists $POOLNAME; then
+               log_must $ZPOOL destroy $POOLNAME
+       fi
+
+       if [[ -d $TESTDIR ]]; then
+               log_must $RM -rf $TESTDIR
+       fi
+}
+
+log_onexit cleanup
+
+typeset exclude=`eval $ECHO \"'(${KEEP})'\"`
+for pool in $($ZPOOL list -H -o name | \
+       $EGREP -v "$exclude" | \
+       $GREP -v "$TESTPOOL" | \
+       $EGREP -v "$NO_POOLS"); do
+       log_must $ZPOOL destroy $pool
+done
+
+DISK=${DISKS%% *}
+if [[ ! -e $TESTDIR ]]; then
+        log_must $MKDIR $TESTDIR
+fi
+
+log_note "Ensure invalid characters fail"
+for POOLNAME in "!" "\"" "#" "$" "%" "&" "'" "(" ")" \
+    "\*" "+" "," "-" "\." "/" "\\" \
+    0 1 2 3 4 5 6 7 8 9 \
+    ":" ";" "<" "=" ">" "\?" "@" \
+    "[" "]" "^" "_" "\`" "{" "|" "}" "~"
+do
+       log_mustnot $ZPOOL create -m $TESTDIR $POOLNAME $DISK
+        if poolexists $POOLNAME; then
+                log_fail "Unexpectedly created pool: '$POOLNAME'"
+        fi
+
+       log_mustnot $ZPOOL destroy $POOLNAME
+done
+
+log_note "Check that invalid octal values fail"
+for oct in "\000" "\001" "\002" "\003" "\004" "\005" "\006" "\007" \
+    "\010" "\011" "\012" "\013" "\014" "\015" "\017" \
+    "\020" "\021" "\022" "\023" "\024" "\025" "\026" "\027" \
+    "\030" "\031" "\032" "\033" "\034" "\035" "\036" "\037" \
+    "\040" "\177"
+do
+       POOLNAME=`eval "echo x | tr 'x' '$oct'"`
+       log_mustnot $ZPOOL create -m $TESTDIR $POOLNAME $DISK
+        if poolexists $POOLNAME; then
+                log_fail "Unexpectedly created pool: '$POOLNAME'"
+        fi
+
+       log_mustnot $ZPOOL destroy $POOLNAME
+done
+
+log_note "Verify invalid pool names fail"
+set -A POOLNAME "c0t0d0s0" "c0t0d0" "c0t0d19" "c0t50000E0108D279d0" \
+    "mirror" "raidz" ",," ",,,,,,,,,,,,,,,,,,,,,,,,," \
+    "2222222222222222222" "mirror_pool" "raidz_pool" \
+    "mirror-pool" "raidz-pool" "spare" "spare_pool" \
+    "spare-pool" "raidz1-" "raidz2:" ":aaa" "-bbb" "_ccc" ".ddd"
+if verify_slog_support ; then
+       POOLNAME[${#POOLNAME[@]}]='log'
+fi
+typeset -i i=0
+while ((i < ${#POOLNAME[@]})); do
+       log_mustnot $ZPOOL create -m $TESTDIR ${POOLNAME[$i]} $DISK
+        if poolexists ${POOLNAME[$i]}; then
+                log_fail "Unexpectedly created pool: '${POOLNAME[$i]}'"
+        fi
+
+       log_mustnot $ZPOOL destroy ${POOLNAME[$i]}
+
+       ((i += 1))
+done
+
+log_pass "Invalid names and characters were caught correctly"
diff --git a/tests/zfs-tests/tests/functional/poolversion/Makefile.am b/tests/zfs-tests/tests/functional/poolversion/Makefile.am
new file mode 100644 (file)
index 0000000..51c2046
--- /dev/null
@@ -0,0 +1,6 @@
+pkgdatadir = $(datadir)/@PACKAGE@/zfs-tests/tests/functional/poolversion
+dist_pkgdata_SCRIPTS = \
+       setup.ksh \
+       cleanup.ksh \
+       poolversion_001_pos.ksh \
+       poolversion_002_pos.ksh
diff --git a/tests/zfs-tests/tests/functional/poolversion/cleanup.ksh b/tests/zfs-tests/tests/functional/poolversion/cleanup.ksh
new file mode 100755 (executable)
index 0000000..6555a0d
--- /dev/null
@@ -0,0 +1,42 @@
+#!/bin/ksh -p
+#
+# CDDL HEADER START
+#
+# The contents of this file are subject to the terms of the
+# Common Development and Distribution License (the "License").
+# You may not use this file except in compliance with the License.
+#
+# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
+# or http://www.opensolaris.org/os/licensing.
+# See the License for the specific language governing permissions
+# and limitations under the License.
+#
+# When distributing Covered Code, include this CDDL HEADER in each
+# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
+# If applicable, add the following below this CDDL HEADER, with the
+# fields enclosed by brackets "[]" replaced with your own identifying
+# information: Portions Copyright [yyyy] [name of copyright owner]
+#
+# CDDL HEADER END
+#
+
+#
+# Copyright 2007 Sun Microsystems, Inc.  All rights reserved.
+# Use is subject to license terms.
+#
+
+#
+# Copyright (c) 2013 by Delphix. All rights reserved.
+#
+
+. $STF_SUITE/include/libtest.shlib
+
+verify_runnable "global"
+
+log_must $ZPOOL destroy $TESTPOOL
+log_must $ZPOOL destroy $TESTPOOL2
+
+log_must $RM /tmp/zpool_version_1.dat
+log_must $RM /tmp/zpool2_version_1.dat
+
+default_cleanup
diff --git a/tests/zfs-tests/tests/functional/poolversion/poolversion_001_pos.ksh b/tests/zfs-tests/tests/functional/poolversion/poolversion_001_pos.ksh
new file mode 100755 (executable)
index 0000000..6622213
--- /dev/null
@@ -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 2009 Sun Microsystems, Inc.  All rights reserved.
+# Use is subject to license terms.
+#
+
+#
+# Copyright (c) 2013 by Delphix. All rights reserved.
+#
+
+. $STF_SUITE/include/libtest.shlib
+
+#
+# DESCRIPTION:
+#
+# zpool set version can upgrade a pool
+#
+# STRATEGY:
+# 1. Taking a version 1 pool
+# 2. For all known versions, set the version of the pool using zpool set
+# 3. Verify that pools version
+#
+
+verify_runnable "global"
+log_assert "zpool set version can upgrade a pool"
+for version in 1 2 3 4 5 6 7 8
+do
+       log_must $ZPOOL set version=$version $TESTPOOL
+       ACTUAL=$($ZPOOL get version $TESTPOOL | $GREP version \
+               | $AWK '{print $3}')
+       if [ "$ACTUAL" != "$version" ]
+       then
+               log_fail "v. $ACTUAL set for $TESTPOOL, expected v. $version!"
+       fi
+done
+
+log_pass "zpool set version can upgrade a pool"
diff --git a/tests/zfs-tests/tests/functional/poolversion/poolversion_002_pos.ksh b/tests/zfs-tests/tests/functional/poolversion/poolversion_002_pos.ksh
new file mode 100755 (executable)
index 0000000..9c51a88
--- /dev/null
@@ -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 2009 Sun Microsystems, Inc.  All rights reserved.
+# Use is subject to license terms.
+#
+
+#
+# Copyright (c) 2013 by Delphix. All rights reserved.
+#
+
+. $STF_SUITE/include/libtest.shlib
+
+#
+# DESCRIPTION:
+#
+# zpool set version can only increment pool version
+#
+# STRATEGY:
+# 1. Set a version 1 pool to be a version 6 pool
+# 2. Verify it's set to version 6
+# 3. Attempt to set prior versions
+# 4. Verify it's still set to version 6
+#
+
+verify_runnable "global"
+log_assert "zpool set version can only increment pool version"
+
+log_must $ZPOOL set version=6 $TESTPOOL2
+# verify it's actually that version - by checking the version property
+# and also by trying to set bootfs (which should fail if it is not version 6)
+
+VERSION=$($ZPOOL get version $TESTPOOL2| $GREP version | $AWK '{print $3}')
+if [ "$VERSION" != "6" ]
+then
+       log_fail "Version $VERSION set for $TESTPOOL2 expected version 6!"
+fi
+log_must $ZPOOL set bootfs=$TESTPOOL2 $TESTPOOL2
+
+# now verify we can't downgrade the version
+log_mustnot $ZPOOL set version=5 $TESTPOOL2
+log_mustnot $ZPOOL set version=-1 $TESTPOOL2
+
+# verify the version is still 6
+VERSION=$($ZPOOL get version $TESTPOOL2 | $GREP version | $AWK '{print $3}')
+if [ "$VERSION" != "6" ]
+then
+       log_fail "Version $VERSION set for $TESTPOOL2, expected version 6!"
+fi
+
+log_pass "zpool set version can only increment pool version"
diff --git a/tests/zfs-tests/tests/functional/poolversion/setup.ksh b/tests/zfs-tests/tests/functional/poolversion/setup.ksh
new file mode 100755 (executable)
index 0000000..cfe14a0
--- /dev/null
@@ -0,0 +1,45 @@
+#!/bin/ksh -p
+#
+# CDDL HEADER START
+#
+# The contents of this file are subject to the terms of the
+# Common Development and Distribution License (the "License").
+# You may not use this file except in compliance with the License.
+#
+# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
+# or http://www.opensolaris.org/os/licensing.
+# See the License for the specific language governing permissions
+# and limitations under the License.
+#
+# When distributing Covered Code, include this CDDL HEADER in each
+# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
+# If applicable, add the following below this CDDL HEADER, with the
+# fields enclosed by brackets "[]" replaced with your own identifying
+# information: Portions Copyright [yyyy] [name of copyright owner]
+#
+# CDDL HEADER END
+#
+
+#
+# Copyright 2007 Sun Microsystems, Inc.  All rights reserved.
+# Use is subject to license terms.
+#
+
+#
+# Copyright (c) 2013 by Delphix. All rights reserved.
+#
+
+. $STF_SUITE/include/libtest.shlib
+
+verify_runnable "global"
+
+# create a version 1 pool
+log_must $MKFILE 64m /tmp/zpool_version_1.dat
+log_must $ZPOOL create -o version=1 $TESTPOOL /tmp/zpool_version_1.dat
+
+
+# create another version 1 pool
+log_must $MKFILE 64m /tmp/zpool2_version_1.dat
+log_must $ZPOOL create -o version=1 $TESTPOOL2 /tmp/zpool2_version_1.dat
+
+log_pass
diff --git a/tests/zfs-tests/tests/functional/privilege/Makefile.am b/tests/zfs-tests/tests/functional/privilege/Makefile.am
new file mode 100644 (file)
index 0000000..ef26a75
--- /dev/null
@@ -0,0 +1,6 @@
+pkgdatadir = $(datadir)/@PACKAGE@/zfs-tests/tests/functional/privilege
+dist_pkgdata_SCRIPTS = \
+       setup.ksh \
+       cleanup.ksh \
+       privilege_001_pos.ksh \
+       privilege_002_pos.ksh
diff --git a/tests/zfs-tests/tests/functional/privilege/cleanup.ksh b/tests/zfs-tests/tests/functional/privilege/cleanup.ksh
new file mode 100755 (executable)
index 0000000..ee50ad4
--- /dev/null
@@ -0,0 +1,49 @@
+#!/bin/ksh -p
+#
+# CDDL HEADER START
+#
+# The contents of this file are subject to the terms of the
+# Common Development and Distribution License (the "License").
+# You may not use this file except in compliance with the License.
+#
+# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
+# or http://www.opensolaris.org/os/licensing.
+# See the License for the specific language governing permissions
+# and limitations under the License.
+#
+# When distributing Covered Code, include this CDDL HEADER in each
+# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
+# If applicable, add the following below this CDDL HEADER, with the
+# fields enclosed by brackets "[]" replaced with your own identifying
+# information: Portions Copyright [yyyy] [name of copyright owner]
+#
+# CDDL HEADER END
+#
+
+#
+# Copyright 2007 Sun Microsystems, Inc.  All rights reserved.
+# Use is subject to license terms.
+#
+
+#
+# Copyright (c) 2013 by Delphix. All rights reserved.
+#
+
+. $STF_SUITE/include/libtest.shlib
+
+verify_runnable "global"
+
+ZFS_USER=$($CAT /tmp/zfs-privs-test-user.txt)
+USES_NIS=$($CAT /tmp/zfs-privs-test-nis.txt)
+
+if [ "${USES_NIS}" == "true" ]
+then
+    $SVCADM enable svc:/network/nis/client:default
+fi
+
+$USERDEL $ZFS_USER
+[[ -d /export/home/$ZFS_USER ]] && $RM -rf /export/home/$ZFS_USER
+$RM /tmp/zfs-privs-test-nis.txt
+$RM /tmp/zfs-privs-test-user.txt
+
+default_cleanup
diff --git a/tests/zfs-tests/tests/functional/privilege/privilege_001_pos.ksh b/tests/zfs-tests/tests/functional/privilege/privilege_001_pos.ksh
new file mode 100755 (executable)
index 0000000..5beabad
--- /dev/null
@@ -0,0 +1,91 @@
+#!/bin/ksh -p
+#
+# CDDL HEADER START
+#
+# The contents of this file are subject to the terms of the
+# Common Development and Distribution License (the "License").
+# You may not use this file except in compliance with the License.
+#
+# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
+# or http://www.opensolaris.org/os/licensing.
+# See the License for the specific language governing permissions
+# and limitations under the License.
+#
+# When distributing Covered Code, include this CDDL HEADER in each
+# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
+# If applicable, add the following below this CDDL HEADER, with the
+# fields enclosed by brackets "[]" replaced with your own identifying
+# information: Portions Copyright [yyyy] [name of copyright owner]
+#
+# CDDL HEADER END
+#
+
+#
+# Copyright 2007 Sun Microsystems, Inc.  All rights reserved.
+# Use is subject to license terms.
+#
+
+#
+# Copyright (c) 2013 by Delphix. All rights reserved.
+#
+
+. $STF_SUITE/include/libtest.shlib
+
+#
+# DESCRIPTION:
+#
+# The RBAC profile "ZFS Storage Management" works
+#
+# STRATEGY:
+#      (create)
+#      1. As a normal user, try to create a pool - which should fail.
+#       2. Assign "ZFS Storage Management" profile, try to create pool again,
+#         which should succeed.
+#
+#      (works well with other ZFS profile tests)
+#      3. Attempt to create a ZFS filesystem, which should fail.
+#      4. Add the "ZFS File System Management" profile, attempt to create a FS
+#         which should succeed.
+#
+#      (destroy)
+#       5. Remove the FS profile, then attempt to destroy the pool, which
+#         should succeed.
+#      6. Remove the Storage profile, then attempt to recreate the pool, which
+#         should fail.
+#
+
+# We can only run this in the global zone
+verify_runnable "global"
+
+log_assert "The RBAC profile \"ZFS Storage Management\" works"
+
+ZFS_USER=$($CAT /tmp/zfs-privs-test-user.txt)
+
+# the user shouldn't be able to do anything initially
+log_mustnot $SU $ZFS_USER -c "$ZPOOL create $TESTPOOL $DISKS"
+log_mustnot $SU $ZFS_USER -c "$PFEXEC $ZPOOL create $TESTPOOL $DISKS"
+
+# the first time we assign the profile, we insist it should work
+log_must $USERMOD -P "ZFS Storage Management" $ZFS_USER
+log_must $SU $ZFS_USER -c "$PFEXEC $ZPOOL create -f $TESTPOOL $DISKS"
+
+# ensure the user can't create a filesystem with this profile
+log_mustnot $SU $ZFS_USER -c "$ZFS create $TESTPOOL/fs"
+
+# add ZFS File System Management profile, and try to create a fs
+log_must $USERMOD -P "ZFS File System Management" $ZFS_USER
+log_must $SU $ZFS_USER -c "$PFEXEC $ZFS create $TESTPOOL/fs"
+
+# revoke File System Management profile
+$USERMOD -P, $ZFS_USER
+$USERMOD -P "ZFS Storage Management" $ZFS_USER
+
+# ensure the user can destroy pools
+log_mustnot $SU $ZFS_USER -c "$ZPOOL destroy $TESTPOOL"
+log_must $SU $ZFS_USER -c "$PFEXEC $ZPOOL destroy $TESTPOOL"
+
+# revoke Storage Management profile
+$USERMOD -P, $ZFS_USER
+log_mustnot $SU $ZFS_USER -c "$PFEXEC $ZPOOL create -f $TESTPOOL $DISKS"
+
+log_pass "The RBAC profile \"ZFS Storage Management\" works"
diff --git a/tests/zfs-tests/tests/functional/privilege/privilege_002_pos.ksh b/tests/zfs-tests/tests/functional/privilege/privilege_002_pos.ksh
new file mode 100755 (executable)
index 0000000..7935985
--- /dev/null
@@ -0,0 +1,101 @@
+#!/bin/ksh -p
+#
+# CDDL HEADER START
+#
+# The contents of this file are subject to the terms of the
+# Common Development and Distribution License (the "License").
+# You may not use this file except in compliance with the License.
+#
+# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
+# or http://www.opensolaris.org/os/licensing.
+# See the License for the specific language governing permissions
+# and limitations under the License.
+#
+# When distributing Covered Code, include this CDDL HEADER in each
+# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
+# If applicable, add the following below this CDDL HEADER, with the
+# fields enclosed by brackets "[]" replaced with your own identifying
+# information: Portions Copyright [yyyy] [name of copyright owner]
+#
+# CDDL HEADER END
+#
+
+#
+# Copyright 2007 Sun Microsystems, Inc.  All rights reserved.
+# Use is subject to license terms.
+#
+
+#
+# Copyright (c) 2013 by Delphix. All rights reserved.
+#
+
+. $STF_SUITE/include/libtest.shlib
+
+#
+# DESCRIPTION:
+#
+# The RBAC profile "ZFS File System Management" works
+#
+# STRATEGY:
+#
+#      The following actions are taken, both using profile execution (pfexec)
+#      and without profile execution - we make sure that the latter should
+#      always fail.
+#
+#      (create)
+#      1. As a normal user, try to create a filesystem - which should fail.
+#       2. Assign "ZFS File System Management" profile, try to create fs again,
+#         which should succeed.
+#
+#      (pools)
+#      3. Ensure a user with this profile can't perform pool administration
+#         by attempting to destroy a pool.
+#
+#      (destroy)
+#       5. Remove the FS profile, then attempt to destroy the fs, which
+#         should fail.
+#      6. Assign the FS profile, then attempt to destroy the fs, which
+#         should succeed.
+#
+
+verify_runnable "both"
+
+log_assert "The RBAC profile \"ZFS File System Management\" works"
+
+ZFS_USER=$($CAT /tmp/zfs-privs-test-user.txt)
+
+# Set a $DATASET where we can create child files systems
+if is_global_zone; then
+       log_must $ZPOOL create -f $TESTPOOL $DISKS
+       DATASET=$TESTPOOL
+else
+       DATASET=zonepool/zonectr0
+fi
+
+# A user shouldn't be able to create filesystems
+log_mustnot $SU $ZFS_USER -c "$ZFS create $DATASET/zfsprivfs"
+
+# Insist this invocation of usermod works
+log_must $USERMOD -P "ZFS File System Management" $ZFS_USER
+
+# Now try to create file systems as the user
+log_mustnot $SU $ZFS_USER -c "$ZFS create $DATASET/zfsprivfs"
+log_must $SU $ZFS_USER -c "$PFEXEC $ZFS create $DATASET/zfsprivfs"
+
+# Ensure the user can't do anything to pools in this state:
+log_mustnot $SU $ZFS_USER -c "$ZPOOL destroy $DATASET"
+log_mustnot $SU $ZFS_USER -c "$PFEXEC $ZPOOL destroy $DATASET"
+
+# revoke File System Management profile
+$USERMOD -P, $ZFS_USER
+
+# Ensure the user can't create more filesystems
+log_mustnot $SU $ZFS_USER -c "$ZFS create $DATASET/zfsprivfs2"
+log_mustnot $SU $ZFS_USER -c "$PFEXEC $ZFS create $DATASET/zfsprivfs2"
+
+# assign the profile again and destroy the fs.
+$USERMOD -P "ZFS File System Management" $ZFS_USER
+log_must $SU $ZFS_USER -c "$PFEXEC $ZFS destroy $DATASET/zfsprivfs"
+$USERMOD -P, $ZFS_USER
+
+log_pass "The RBAC profile \"ZFS File System Management\" works"
diff --git a/tests/zfs-tests/tests/functional/privilege/setup.ksh b/tests/zfs-tests/tests/functional/privilege/setup.ksh
new file mode 100755 (executable)
index 0000000..0f53b8c
--- /dev/null
@@ -0,0 +1,67 @@
+#!/bin/ksh -p
+#
+# CDDL HEADER START
+#
+# The contents of this file are subject to the terms of the
+# Common Development and Distribution License (the "License").
+# You may not use this file except in compliance with the License.
+#
+# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
+# or http://www.opensolaris.org/os/licensing.
+# See the License for the specific language governing permissions
+# and limitations under the License.
+#
+# When distributing Covered Code, include this CDDL HEADER in each
+# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
+# If applicable, add the following below this CDDL HEADER, with the
+# fields enclosed by brackets "[]" replaced with your own identifying
+# information: Portions Copyright [yyyy] [name of copyright owner]
+#
+# CDDL HEADER END
+#
+
+#
+# Copyright 2007 Sun Microsystems, Inc.  All rights reserved.
+# Use is subject to license terms.
+#
+
+#
+# Copyright (c) 2013 by Delphix. All rights reserved.
+#
+
+. $STF_SUITE/include/libtest.shlib
+
+ZFS_USER=zfsrbac
+USES_NIS=false
+
+# if we're running NIS, turn it off until we clean up
+# (it can cause useradd to take a long time, hitting our TIMEOUT)
+$SVCS svc:/network/nis/client:default | $GREP online > /dev/null
+if [ $? -eq 0 ]
+then
+  $SVCADM disable svc:/network/nis/client:default
+  USES_NIS=true
+fi
+
+
+# create a unique user that we can use to run the tests,
+# making sure not to clobber any existing users.
+FOUND=""
+while [ -z "${FOUND}" ]
+do
+  USER_EXISTS=$( grep $ZFS_USER /etc/passwd )
+  if [ ! -z "${USER_EXISTS}" ]
+  then
+      ZFS_USER="${ZFS_USER}x"
+  else
+      FOUND="true"
+  fi
+done
+
+log_must $MKDIR -p /export/home/$ZFS_USER
+log_must $USERADD -c "ZFS Privileges Test User" -d /export/home/$ZFS_USER $ZFS_USER
+
+echo $ZFS_USER > /tmp/zfs-privs-test-user.txt
+echo $USES_NIS > /tmp/zfs-privs-test-nis.txt
+
+log_pass
diff --git a/tests/zfs-tests/tests/functional/quota/Makefile.am b/tests/zfs-tests/tests/functional/quota/Makefile.am
new file mode 100644 (file)
index 0000000..6318684
--- /dev/null
@@ -0,0 +1,12 @@
+pkgdatadir = $(datadir)/@PACKAGE@/zfs-tests/tests/functional/quota
+dist_pkgdata_SCRIPTS = \
+       quota.cfg \
+       quota.kshlib \
+       setup.ksh \
+       cleanup.ksh \
+       quota_001_pos.ksh \
+       quota_002_pos.ksh \
+       quota_003_pos.ksh \
+       quota_004_pos.ksh \
+       quota_005_pos.ksh \
+       quota_006_neg.ksh
diff --git a/tests/zfs-tests/tests/functional/quota/cleanup.ksh b/tests/zfs-tests/tests/functional/quota/cleanup.ksh
new file mode 100755 (executable)
index 0000000..c4c3691
--- /dev/null
@@ -0,0 +1,34 @@
+#!/bin/ksh -p
+#
+# CDDL HEADER START
+#
+# The contents of this file are subject to the terms of the
+# Common Development and Distribution License (the "License").
+# You may not use this file except in compliance with the License.
+#
+# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
+# or http://www.opensolaris.org/os/licensing.
+# See the License for the specific language governing permissions
+# and limitations under the License.
+#
+# When distributing Covered Code, include this CDDL HEADER in each
+# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
+# If applicable, add the following below this CDDL HEADER, with the
+# fields enclosed by brackets "[]" replaced with your own identifying
+# information: Portions Copyright [yyyy] [name of copyright owner]
+#
+# CDDL HEADER END
+#
+
+#
+# Copyright 2007 Sun Microsystems, Inc.  All rights reserved.
+# Use is subject to license terms.
+#
+
+#
+# Copyright (c) 2013 by Delphix. All rights reserved.
+#
+
+. $STF_SUITE/include/libtest.shlib
+
+default_container_cleanup
diff --git a/tests/zfs-tests/tests/functional/quota/quota.cfg b/tests/zfs-tests/tests/functional/quota/quota.cfg
new file mode 100644 (file)
index 0000000..5b19f40
--- /dev/null
@@ -0,0 +1,35 @@
+#
+# CDDL HEADER START
+#
+# The contents of this file are subject to the terms of the
+# Common Development and Distribution License (the "License").
+# You may not use this file except in compliance with the License.
+#
+# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
+# or http://www.opensolaris.org/os/licensing.
+# See the License for the specific language governing permissions
+# and limitations under the License.
+#
+# When distributing Covered Code, include this CDDL HEADER in each
+# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
+# If applicable, add the following below this CDDL HEADER, with the
+# fields enclosed by brackets "[]" replaced with your own identifying
+# information: Portions Copyright [yyyy] [name of copyright owner]
+#
+# CDDL HEADER END
+#
+
+#
+# Copyright 2008 Sun Microsystems, Inc.  All rights reserved.
+# Use is subject to license terms.
+#
+
+#
+# Copyright (c) 2013 by Delphix. All rights reserved.
+#
+
+export BLOCK_SIZE=8192
+export QUOTA_VALUE=10000000
+export TESTFILE1=file1
+export TESTFILE2=file2
+export TOLERANCE=131071
diff --git a/tests/zfs-tests/tests/functional/quota/quota.kshlib b/tests/zfs-tests/tests/functional/quota/quota.kshlib
new file mode 100644 (file)
index 0000000..7ca111a
--- /dev/null
@@ -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.
+#
+
+#
+# Copyright (c) 2013 by Delphix. All rights reserved.
+#
+
+. $STF_SUITE/tests/functional/quota/quota.cfg
+
+# BLOCK_SIZE, QUOTA_VALUE and TOLERANCE set in quota.cfg
+if is_linux; then
+       readonly EDQUOT=122
+else
+       readonly EDQUOT=49
+fi
+
+#
+# Function to fill the quota of a zfs filesystem
+#
+# $1 - The File system or container to fill.
+# $2 - The mountpoint to use.
+#
+function fill_quota
+{
+       typeset FILESYSTEM="$1"
+       typeset MNTPT="$2"
+
+       log_must $ZFS set quota=$QUOTA_VALUE $FILESYSTEM
+
+       typeset -i write_size=0
+       (( write_size = 2 * QUOTA_VALUE ))
+
+       typeset -i zret=0
+       $FILE_WRITE -o create -f $MNTPT/$TESTFILE1 -b $BLOCK_SIZE \
+                -c $write_size -d 0
+       zret=$?
+        [[ $zret -ne EDQUOT ]] && \
+            log_fail "Returned error code: $zret. Expected: $EDQUOT."
+
+       typeset -i file_size=`$LS -ls $MNTPT/$TESTFILE1 | $AWK '{ print $1 }'`
+       typeset -i limit=0
+       (( file_size = file_size * 512 ))
+       (( limit = QUOTA_VALUE + TOLERANCE ))
+       (( file_size > limit )) && \
+           log_fail "File was created larger than the quota value, aborting!!!"
+       return 0
+}
+
+#
+# Function attempts to write another file in a ZFS filesystem
+# that has already filled its quota
+#
+function exceed_quota
+{
+       typeset FILESYSTEM="$1"
+       typeset MNTPT="$2"
+
+       log_must fill_quota $FILESYSTEM $MNTPT
+       typeset -i write_size=0
+        (( write_size = 2 * QUOTA_VALUE ))
+       typeset -i zret=0
+       #
+       # Writing a file without API to access return code
+       #
+       log_note "Creating a file in a FS that has already exceeded its quota"
+       $FILE_WRITE -o create -f $MNTPT/$TESTFILE2 \
+               -b $BLOCK_SIZE -c $write_size -d 0
+       zret=$?
+       [[ $zret -ne EDQUOT ]] && \
+           log_fail "Returned error code: $zret. Expected: EDQUOT."
+       return 0
+}
diff --git a/tests/zfs-tests/tests/functional/quota/quota_001_pos.ksh b/tests/zfs-tests/tests/functional/quota/quota_001_pos.ksh
new file mode 100755 (executable)
index 0000000..6c5cf36
--- /dev/null
@@ -0,0 +1,76 @@
+#! /bin/ksh -p
+#
+# CDDL HEADER START
+#
+# The contents of this file are subject to the terms of the
+# Common Development and Distribution License (the "License").
+# You may not use this file except in compliance with the License.
+#
+# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
+# or http://www.opensolaris.org/os/licensing.
+# See the License for the specific language governing permissions
+# and limitations under the License.
+#
+# When distributing Covered Code, include this CDDL HEADER in each
+# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
+# If applicable, add the following below this CDDL HEADER, with the
+# fields enclosed by brackets "[]" replaced with your own identifying
+# information: Portions Copyright [yyyy] [name of copyright owner]
+#
+# CDDL HEADER END
+#
+
+#
+# Copyright 2007 Sun Microsystems, Inc.  All rights reserved.
+# Use is subject to license terms.
+#
+
+#
+# Copyright (c) 2013 by Delphix. All rights reserved.
+#
+
+. $STF_SUITE/include/libtest.shlib
+. $STF_SUITE/tests/functional/quota/quota.kshlib
+
+#
+# DESCRIPTION:
+#
+# A ZFS file system quota limits the amount of pool space
+# available to a file system. Apply a quota and verify
+# that no more file creates are permitted.
+#
+# STRATEGY:
+# 1) Apply quota to ZFS file system
+# 2) Create a file which is larger than the set quota
+# 3) Verify that the resulting file size is less than the quota limit
+#
+
+verify_runnable "both"
+
+log_assert "Verify that file size is limited by the file system quota"
+
+#
+# cleanup to be used internally as otherwise quota assertions cannot be
+# run independently or out of order
+#
+function cleanup
+{
+       [[ -e $TESTDIR/$TESTFILE1 ]] && \
+           log_must $RM $TESTDIR/$TESTFILE1
+       #
+       # Need to allow time for space to be released back to
+       # pool, otherwise next test will fail trying to set a
+       # quota which is less than the space used.
+       #
+       sleep 5
+}
+
+log_onexit cleanup
+
+#
+# Sets the quota value and attempts to fill it with a file
+# twice the size of the quota
+#
+log_must fill_quota $TESTPOOL/$TESTFS $TESTDIR
+
+log_pass "File size limited by quota"
diff --git a/tests/zfs-tests/tests/functional/quota/quota_002_pos.ksh b/tests/zfs-tests/tests/functional/quota/quota_002_pos.ksh
new file mode 100755 (executable)
index 0000000..3b8ba66
--- /dev/null
@@ -0,0 +1,73 @@
+#! /bin/ksh -p
+#
+# CDDL HEADER START
+#
+# The contents of this file are subject to the terms of the
+# Common Development and Distribution License (the "License").
+# You may not use this file except in compliance with the License.
+#
+# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
+# or http://www.opensolaris.org/os/licensing.
+# See the License for the specific language governing permissions
+# and limitations under the License.
+#
+# When distributing Covered Code, include this CDDL HEADER in each
+# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
+# If applicable, add the following below this CDDL HEADER, with the
+# fields enclosed by brackets "[]" replaced with your own identifying
+# information: Portions Copyright [yyyy] [name of copyright owner]
+#
+# CDDL HEADER END
+#
+
+#
+# Copyright 2007 Sun Microsystems, Inc.  All rights reserved.
+# Use is subject to license terms.
+#
+
+#
+# Copyright (c) 2013 by Delphix. All rights reserved.
+#
+
+. $STF_SUITE/include/libtest.shlib
+. $STF_SUITE/tests/functional/quota/quota.kshlib
+
+#
+# DESCRIPTION:
+# A zfs file system quota limits the amount of pool space
+# available to a given ZFS file system. Once exceeded, it is impossible
+# to write any more files to the file system.
+#
+# STRATEGY:
+# 1) Apply quota to the ZFS file system
+# 2) Exceed the quota
+# 3) Attempt to write another file
+# 4) Verify the attempt fails with error code 49 (EDQUOTA)
+#
+#
+
+verify_runnable "both"
+
+log_assert "Verify that a file write cannot exceed the file system quota"
+
+#
+# cleanup to be used internally as otherwise quota assertions cannot be
+# run independently or out of order
+#
+function cleanup
+{
+        [[ -e $TESTDIR/$TESTFILE1 ]] && \
+            log_must $RM $TESTDIR/$TESTFILE1
+
+       [[ -e $TESTDIR/$TESTFILE2 ]] && \
+            log_must $RM $TESTDIR/$TESTFILE2
+}
+
+log_onexit cleanup
+
+#
+# Fills the quota & attempts to write another file
+#
+log_must exceed_quota $TESTPOOL/$TESTFS $TESTDIR
+
+log_pass "Could not write file. Quota limit enforced as expected"
diff --git a/tests/zfs-tests/tests/functional/quota/quota_003_pos.ksh b/tests/zfs-tests/tests/functional/quota/quota_003_pos.ksh
new file mode 100755 (executable)
index 0000000..afcc4a1
--- /dev/null
@@ -0,0 +1,79 @@
+#! /bin/ksh -p
+#
+# CDDL HEADER START
+#
+# The contents of this file are subject to the terms of the
+# Common Development and Distribution License (the "License").
+# You may not use this file except in compliance with the License.
+#
+# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
+# or http://www.opensolaris.org/os/licensing.
+# See the License for the specific language governing permissions
+# and limitations under the License.
+#
+# When distributing Covered Code, include this CDDL HEADER in each
+# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
+# If applicable, add the following below this CDDL HEADER, with the
+# fields enclosed by brackets "[]" replaced with your own identifying
+# information: Portions Copyright [yyyy] [name of copyright owner]
+#
+# CDDL HEADER END
+#
+
+#
+# Copyright 2007 Sun Microsystems, Inc.  All rights reserved.
+# Use is subject to license terms.
+#
+
+#
+# Copyright (c) 2013 by Delphix. All rights reserved.
+#
+
+. $STF_SUITE/include/libtest.shlib
+. $STF_SUITE/tests/functional/quota/quota.kshlib
+
+#
+# DESCRIPTION:
+# A ZFS file system quota limits the amount of pool space
+# available to a file system dataset. Apply a quota and verify
+# that no more file creates are permitted.
+#
+# NOTE: THis test applies to a dataset rather than a file system.
+#
+# STRATEGY:
+# 1) Apply quota to ZFS file system dataset
+# 2) Create a file which is larger than the set quota
+# 3) Verify that the resulting file size is less than the quota limit
+#
+
+verify_runnable "both"
+
+log_assert "Verify that file size is limited by the file system quota" \
+    "(dataset version)"
+
+#
+# cleanup to be used internally as otherwise quota assertions cannot be
+# run independently or out of order
+#
+function cleanup
+{
+       [[ -e $TESTDIR1/$TESTFILE1 ]] && \
+           log_must $RM $TESTDIR1/$TESTFILE1
+
+       #
+        # Need to allow time for space to be released back to
+        # pool, otherwise next test will fail trying to set a
+        # quota which is less than the space used.
+        #
+        sleep 5
+}
+
+log_onexit cleanup
+
+#
+# Sets the quota value and attempts to fill it with a file
+# twice the size of the quota
+#
+log_must fill_quota $TESTPOOL/$TESTCTR/$TESTFS1 $TESTDIR1
+
+log_pass "File size limited by quota"
diff --git a/tests/zfs-tests/tests/functional/quota/quota_004_pos.ksh b/tests/zfs-tests/tests/functional/quota/quota_004_pos.ksh
new file mode 100755 (executable)
index 0000000..def8b2b
--- /dev/null
@@ -0,0 +1,74 @@
+#! /bin/ksh -p
+#
+# CDDL HEADER START
+#
+# The contents of this file are subject to the terms of the
+# Common Development and Distribution License (the "License").
+# You may not use this file except in compliance with the License.
+#
+# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
+# or http://www.opensolaris.org/os/licensing.
+# See the License for the specific language governing permissions
+# and limitations under the License.
+#
+# When distributing Covered Code, include this CDDL HEADER in each
+# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
+# If applicable, add the following below this CDDL HEADER, with the
+# fields enclosed by brackets "[]" replaced with your own identifying
+# information: Portions Copyright [yyyy] [name of copyright owner]
+#
+# CDDL HEADER END
+#
+
+#
+# Copyright 2007 Sun Microsystems, Inc.  All rights reserved.
+# Use is subject to license terms.
+#
+
+#
+# Copyright (c) 2013 by Delphix. All rights reserved.
+#
+
+. $STF_SUITE/include/libtest.shlib
+. $STF_SUITE/tests/functional/quota/quota.kshlib
+
+#
+# DESCRIPTION:
+# A zfs file system quota limits the amount of pool space
+# available to a given ZFS file system dataset. Once exceeded, it
+# is impossible to write any more files to the file system.
+#
+# STRATEGY:
+# 1) Apply quota to the ZFS file system dataset
+# 2) Exceed the quota
+# 3) Attempt to write another file
+# 4) Verify the attempt fails with error code 49 (EDQUOTA)
+#
+#
+
+verify_runnable "both"
+
+log_assert "Verify that a file write cannot exceed the file system quota" \
+    "(dataset version)"
+
+#
+# cleanup to be used internally as otherwise quota assertions cannot be
+# run independently or out of order
+#
+function cleanup
+{
+        [[ -e $TESTDIR1/$TESTFILE1 ]] && \
+            log_must $RM $TESTDIR1/$TESTFILE1
+
+       [[ -e $TESTDIR1/$TESTFILE2 ]] && \
+            log_must $RM $TESTDIR1/$TESTFILE2
+}
+
+log_onexit cleanup
+
+#
+# Fills the quota & attempts to write another file
+#
+log_must exceed_quota $TESTPOOL/$TESTCTR/$TESTFS1 $TESTDIR1
+
+log_pass "Could not write file. Quota limit enforced as expected"
diff --git a/tests/zfs-tests/tests/functional/quota/quota_005_pos.ksh b/tests/zfs-tests/tests/functional/quota/quota_005_pos.ksh
new file mode 100755 (executable)
index 0000000..55bddb5
--- /dev/null
@@ -0,0 +1,76 @@
+#! /bin/ksh -p
+#
+# CDDL HEADER START
+#
+# The contents of this file are subject to the terms of the
+# Common Development and Distribution License (the "License").
+# You may not use this file except in compliance with the License.
+#
+# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
+# or http://www.opensolaris.org/os/licensing.
+# See the License for the specific language governing permissions
+# and limitations under the License.
+#
+# When distributing Covered Code, include this CDDL HEADER in each
+# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
+# If applicable, add the following below this CDDL HEADER, with the
+# fields enclosed by brackets "[]" replaced with your own identifying
+# information: Portions Copyright [yyyy] [name of copyright owner]
+#
+# CDDL HEADER END
+#
+
+#
+# Copyright 2007 Sun Microsystems, Inc.  All rights reserved.
+# Use is subject to license terms.
+#
+
+#
+# Copyright (c) 2013 by Delphix. All rights reserved.
+#
+
+. $STF_SUITE/include/libtest.shlib
+. $STF_SUITE/tests/functional/quota/quota.kshlib
+
+#
+# DESCRIPTION:
+#
+# Verify that quota doesn't inherit its value from parent.
+#
+# STRATEGY:
+# 1) Set quota for parents
+# 2) Create a filesystem tree
+# 3) Verify that the 'quota' for descendent doesnot inherit the value.
+#
+###############################################################################
+
+verify_runnable "both"
+
+function cleanup
+{
+       datasetexists $fs_child && \
+               log_must $ZFS destroy $fs_child
+
+       log_must $ZFS set quota=$quota_val $fs
+}
+
+log_onexit cleanup
+
+log_assert "Verify that quota doesnot inherit its value from parent."
+log_onexit cleanup
+
+fs=$TESTPOOL/$TESTFS
+fs_child=$TESTPOOL/$TESTFS/$TESTFS
+
+space_avail=$(get_prop available $fs)
+quota_val=$(get_prop quota $fs)
+typeset -i quotasize=$space_avail
+((quotasize = quotasize * 2 ))
+log_must $ZFS set quota=$quotasize $fs
+
+log_must $ZFS create $fs_child
+quota_space=$(get_prop quota $fs_child)
+[[ $quota_space == $quotasize ]] && \
+       log_fail "The quota of child dataset inherits its value from parent."
+
+log_pass "quota doesnot inherit its value from parent as expected."
diff --git a/tests/zfs-tests/tests/functional/quota/quota_006_neg.ksh b/tests/zfs-tests/tests/functional/quota/quota_006_neg.ksh
new file mode 100755 (executable)
index 0000000..a22520c
--- /dev/null
@@ -0,0 +1,71 @@
+#! /bin/ksh -p
+#
+# CDDL HEADER START
+#
+# The contents of this file are subject to the terms of the
+# Common Development and Distribution License (the "License").
+# You may not use this file except in compliance with the License.
+#
+# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
+# or http://www.opensolaris.org/os/licensing.
+# See the License for the specific language governing permissions
+# and limitations under the License.
+#
+# When distributing Covered Code, include this CDDL HEADER in each
+# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
+# If applicable, add the following below this CDDL HEADER, with the
+# fields enclosed by brackets "[]" replaced with your own identifying
+# information: Portions Copyright [yyyy] [name of copyright owner]
+#
+# CDDL HEADER END
+#
+
+#
+# Copyright 2007 Sun Microsystems, Inc.  All rights reserved.
+# Use is subject to license terms.
+#
+
+#
+# Copyright (c) 2013 by Delphix. All rights reserved.
+#
+
+. $STF_SUITE/include/libtest.shlib
+. $STF_SUITE/tests/functional/quota/quota.kshlib
+
+#
+# DESCRIPTION:
+#
+# Can't set a quota to less than currently being used by the dataset.
+#
+# STRATEGY:
+# 1) Create a filesystem
+# 2) Set a quota on the filesystem that is lower than the space
+#      currently in use.
+# 3) Verify that the attempt fails.
+#
+
+verify_runnable "both"
+
+log_assert "Verify cannot set quota lower than the space currently in use"
+
+function cleanup
+{
+       log_must $ZFS set quota=none $TESTPOOL/$TESTFS
+}
+
+log_onexit cleanup
+
+typeset -i quota_integer_size=0
+typeset invalid_size="123! @456 7#89 0\$ abc123% 123%s 12%s3 %c123 123%d %x123 12%p3 \
+       ^def456 789&ghi"
+typeset -i space_used=`get_prop used $TESTPOOL/$TESTFS`
+(( quota_integer_size = space_used  - 1 ))
+quota_fp_size=${quota_integer_size}.123
+
+for size in 0 -1 $quota_integer_size -$quota_integer_size $quota_fp_size -$quota_fp_size \
+       $invalid_size ; do
+       log_mustnot $ZFS set quota=$size $TESTPOOL/$TESTFS
+done
+log_must $ZFS set quota=$space_used $TESTPOOL/$TESTFS
+
+log_pass "As expected cannot set quota lower than space currently in use"
diff --git a/tests/zfs-tests/tests/functional/quota/setup.ksh b/tests/zfs-tests/tests/functional/quota/setup.ksh
new file mode 100755 (executable)
index 0000000..677cb12
--- /dev/null
@@ -0,0 +1,36 @@
+#!/bin/ksh -p
+#
+# CDDL HEADER START
+#
+# The contents of this file are subject to the terms of the
+# Common Development and Distribution License (the "License").
+# You may not use this file except in compliance with the License.
+#
+# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
+# or http://www.opensolaris.org/os/licensing.
+# See the License for the specific language governing permissions
+# and limitations under the License.
+#
+# When distributing Covered Code, include this CDDL HEADER in each
+# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
+# If applicable, add the following below this CDDL HEADER, with the
+# fields enclosed by brackets "[]" replaced with your own identifying
+# information: Portions Copyright [yyyy] [name of copyright owner]
+#
+# CDDL HEADER END
+#
+
+#
+# Copyright 2007 Sun Microsystems, Inc.  All rights reserved.
+# Use is subject to license terms.
+#
+
+#
+# Copyright (c) 2013 by Delphix. All rights reserved.
+#
+
+. $STF_SUITE/include/libtest.shlib
+
+DISK=${DISKS%% *}
+
+default_container_setup $DISK
diff --git a/tests/zfs-tests/tests/functional/redundancy/Makefile.am b/tests/zfs-tests/tests/functional/redundancy/Makefile.am
new file mode 100644 (file)
index 0000000..ef7dd91
--- /dev/null
@@ -0,0 +1,10 @@
+pkgdatadir = $(datadir)/@PACKAGE@/zfs-tests/tests/functional/redundancy
+dist_pkgdata_SCRIPTS = \
+       redundancy.cfg \
+       redundancy.kshlib \
+       setup.ksh \
+       cleanup.ksh \
+       redundancy_001_pos.ksh \
+       redundancy_002_pos.ksh \
+       redundancy_003_pos.ksh \
+       redundancy_004_neg.ksh
diff --git a/tests/zfs-tests/tests/functional/redundancy/cleanup.ksh b/tests/zfs-tests/tests/functional/redundancy/cleanup.ksh
new file mode 100755 (executable)
index 0000000..ba8d980
--- /dev/null
@@ -0,0 +1,38 @@
+#!/bin/ksh -p
+#
+# CDDL HEADER START
+#
+# The contents of this file are subject to the terms of the
+# Common Development and Distribution License (the "License").
+# You may not use this file except in compliance with the License.
+#
+# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
+# or http://www.opensolaris.org/os/licensing.
+# See the License for the specific language governing permissions
+# and limitations under the License.
+#
+# When distributing Covered Code, include this CDDL HEADER in each
+# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
+# If applicable, add the following below this CDDL HEADER, with the
+# fields enclosed by brackets "[]" replaced with your own identifying
+# information: Portions Copyright [yyyy] [name of copyright owner]
+#
+# CDDL HEADER END
+#
+
+#
+# Copyright 2008 Sun Microsystems, Inc.  All rights reserved.
+# Use is subject to license terms.
+#
+
+#
+# Copyright (c) 2013 by Delphix. All rights reserved.
+#
+
+. $STF_SUITE/tests/functional/redundancy/redundancy.kshlib
+
+verify_runnable "global"
+
+cleanup
+
+log_pass
diff --git a/tests/zfs-tests/tests/functional/redundancy/redundancy.cfg b/tests/zfs-tests/tests/functional/redundancy/redundancy.cfg
new file mode 100644 (file)
index 0000000..079ff8b
--- /dev/null
@@ -0,0 +1,40 @@
+#
+# CDDL HEADER START
+#
+# The contents of this file are subject to the terms of the
+# Common Development and Distribution License (the "License").
+# You may not use this file except in compliance with the License.
+#
+# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
+# or http://www.opensolaris.org/os/licensing.
+# See the License for the specific language governing permissions
+# and limitations under the License.
+#
+# When distributing Covered Code, include this CDDL HEADER in each
+# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
+# If applicable, add the following below this CDDL HEADER, with the
+# fields enclosed by brackets "[]" replaced with your own identifying
+# information: Portions Copyright [yyyy] [name of copyright owner]
+#
+# CDDL HEADER END
+#
+
+#
+# Copyright 2008 Sun Microsystems, Inc.  All rights reserved.
+# Use is subject to license terms.
+#
+
+#
+# Copyright (c) 2013 by Delphix. All rights reserved.
+#
+
+export BASEDIR=/var/tmp/basedir.$$
+export TESTFILE=testfile.$$
+
+export PRE_RECORD_FILE=$BASEDIR/pre-record-file.$$
+export PST_RECORD_FILE=$BASEDIR/pst-record-file.$$
+
+export DEV_SIZE=64M
+
+export BLOCKSZ=$(( 1024 * 1024 ))
+export NUM_WRITES=40
diff --git a/tests/zfs-tests/tests/functional/redundancy/redundancy.kshlib b/tests/zfs-tests/tests/functional/redundancy/redundancy.kshlib
new file mode 100644 (file)
index 0000000..cb82717
--- /dev/null
@@ -0,0 +1,365 @@
+#
+# CDDL HEADER START
+#
+# The contents of this file are subject to the terms of the
+# Common Development and Distribution License (the "License").
+# You may not use this file except in compliance with the License.
+#
+# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
+# or http://www.opensolaris.org/os/licensing.
+# See the License for the specific language governing permissions
+# and limitations under the License.
+#
+# When distributing Covered Code, include this CDDL HEADER in each
+# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
+# If applicable, add the following below this CDDL HEADER, with the
+# fields enclosed by brackets "[]" replaced with your own identifying
+# information: Portions Copyright [yyyy] [name of copyright owner]
+#
+# CDDL HEADER END
+#
+
+#
+# Copyright 2009 Sun Microsystems, Inc.  All rights reserved.
+# Use is subject to license terms.
+#
+
+#
+# Copyright (c) 2013 by Delphix. All rights reserved.
+#
+
+. $STF_SUITE/include/libtest.shlib
+. $STF_SUITE/tests/functional/redundancy/redundancy.cfg
+
+function cleanup
+{
+       if poolexists $TESTPOOL; then
+               destroy_pool $TESTPOOL
+       fi
+       typeset dir
+       for dir in $TESTDIR $BASEDIR; do
+               if [[ -d $dir ]]; then
+                       log_must $RM -rf $dir
+               fi
+       done
+}
+
+#
+# Get random number between min and max number.
+#
+# $1 Minimal value
+# $2 Maximal value
+#
+function random
+{
+       typeset -i min=$1
+       typeset -i max=$2
+       typeset -i value
+
+       while true; do
+               ((value = RANDOM % (max + 1)))
+               if ((value >= min)); then
+                       break
+               fi
+       done
+
+       $ECHO $value
+}
+
+#
+# Record the directories construction and checksum all the files which reside
+# within the specified pool
+#
+# $1 The specified pool
+# $2 The file which save the record.
+#
+function record_data
+{
+       typeset pool=$1
+       typeset recordfile=$2
+
+       [[ -z $pool ]] && log_fail "No specified pool."
+       [[ -f $recordfile ]] && log_must $RM -f $recordfile
+
+       typeset mntpnt
+       mntpnt=$(get_prop mountpoint $pool)
+       log_must eval "$DU -a $mntpnt > $recordfile 2>&1"
+       #
+       # When the data was damaged, checksum is failing and return 1
+       # So, will not use log_must
+       #
+       $FIND $mntpnt -type f -exec $CKSUM {} + >> $recordfile 2>&1
+}
+
+#
+# Create test pool and fill with files and directories.
+#
+# $1 pool name
+# $2 pool type
+# $3 virtual devices number
+#
+function setup_test_env
+{
+       typeset pool=$1
+       typeset keyword=$2
+       typeset -i vdev_cnt=$3
+       typeset vdevs
+
+       typeset -i i=0
+       while (( i < vdev_cnt )); do
+               vdevs="$vdevs $BASEDIR/vdev$i"
+               ((i += 1))
+       done
+
+       if [[ ! -d $BASEDIR ]]; then
+               log_must $MKDIR $BASEDIR
+       fi
+
+       if poolexists $pool ; then
+               destroy_pool $pool
+       fi
+
+       log_must $MKFILE $DEV_SIZE $vdevs
+
+       log_must $ZPOOL create -m $TESTDIR $pool $keyword $vdevs
+
+       log_note "Filling up the filesystem ..."
+       typeset -i ret=0
+       typeset -i i=0
+       typeset file=$TESTDIR/file
+       while $TRUE ; do
+               $FILE_WRITE -o create -f $file.$i \
+                       -b $BLOCKSZ -c $NUM_WRITES
+               ret=$?
+               (( $ret != 0 )) && break
+               (( i = i + 1 ))
+       done
+       (($ret != 28 )) && log_note "$FILE_WRITE return value($ret) is unexpected."
+
+       record_data $TESTPOOL $PRE_RECORD_FILE
+}
+
+#
+# Check pool status is healthy
+#
+# $1 pool
+#
+function is_healthy
+{
+       typeset pool=$1
+
+       typeset healthy_output="pool '$pool' is healthy"
+       typeset real_output=$($ZPOOL status -x $pool)
+
+       if [[ "$real_output" == "$healthy_output" ]]; then
+               return 0
+       else
+               typeset -i ret
+               $ZPOOL status -x $pool | $GREP "state:" | \
+                       $GREP "FAULTED" >/dev/null 2>&1
+               ret=$?
+               (( $ret == 0 )) && return 1
+               typeset l_scan
+               typeset errnum
+               l_scan=$($ZPOOL status -x $pool | $GREP "scan:")
+               l_scan=${l_scan##*"with"}
+               errnum=$($ECHO $l_scan | $AWK '{print $1}')
+
+               return $errnum
+       fi
+}
+
+#
+# Check pool data is valid
+#
+# $1 pool
+#
+function is_data_valid
+{
+       typeset pool=$1
+
+       record_data $pool $PST_RECORD_FILE
+       if ! $DIFF $PRE_RECORD_FILE $PST_RECORD_FILE > /dev/null 2>&1; then
+               return 1
+       fi
+
+       return 0
+}
+
+#
+# Get the specified count devices name
+#
+# $1 pool name
+# $2 devices count
+#
+function get_vdevs #pool cnt
+{
+       typeset pool=$1
+       typeset -i cnt=$2
+
+       typeset all_devs=$($ZPOOL iostat -v $pool | $AWK '{print $1}'| \
+               $EGREP -v "^pool$|^capacity$|^mirror$|^raidz1$|^raidz2$|---" | \
+               $EGREP -v "/old$|^$pool$")
+       typeset -i i=0
+       typeset vdevs
+       while ((i < cnt)); do
+               typeset dev=$($ECHO $all_devs | $AWK '{print $1}')
+               eval all_devs=\${all_devs##*$dev}
+
+               vdevs="$dev $vdevs"
+               ((i += 1))
+       done
+
+       $ECHO "$vdevs"
+}
+
+#
+# Synchronize all the data in pool
+#
+# $1 pool name
+#
+function sync_pool #pool
+{
+       typeset pool=$1
+
+       log_must $SYNC
+       log_must $SLEEP 2
+       # Flush all the pool data.
+       typeset -i ret
+       $ZPOOL scrub $pool >/dev/null 2>&1
+       ret=$?
+       (( $ret != 0 )) && \
+               log_fail "$ZPOOL scrub $pool failed."
+
+       while ! is_pool_scrubbed $pool; do
+               if is_pool_resilvered $pool ; then
+                       log_fail "$pool should not be resilver completed."
+               fi
+               log_must $SLEEP 2
+       done
+}
+
+#
+# Create and replace the same name virtual device files
+#
+# $1 pool name
+# $2-n virtual device files
+#
+function replace_missing_devs
+{
+       typeset pool=$1
+       shift
+
+       typeset vdev
+       for vdev in $@; do
+               log_must $MKFILE $DEV_SIZE $vdev
+               log_must $ZPOOL replace -f $pool $vdev $vdev
+               while true; do
+                       if ! is_pool_resilvered $pool ; then
+                               log_must $SLEEP 2
+                       else
+                               break
+                       fi
+               done
+       done
+}
+
+#
+# Damage the pool's virtual device files.
+#
+# $1 pool name
+# $2 Failing devices count
+# $3 damage vdevs method, if not null, we keep
+#    the label for the vdevs
+#
+function damage_devs
+{
+       typeset pool=$1
+       typeset -i cnt=$2
+       typeset label="$3"
+       typeset vdevs
+       typeset -i bs_count
+
+       vdevs=$(get_vdevs $pool $cnt)
+       if [[ -n $label ]]; then
+               typeset dev
+               for dev in $vdevs; do
+                       bs_count=$($LS -l $dev | $AWK '{print $5}')
+                       (( bs_count = bs_count/1024 - 512 ))
+                       $DD if=/dev/zero of=$dev seek=512 bs=1024 \
+                               count=$bs_count conv=notrunc >/dev/null 2>&1
+               done
+       else
+               log_must $MKFILE $DEV_SIZE $vdevs
+       fi
+
+       sync_pool $pool
+}
+
+#
+# Clear errors in the pool caused by data corruptions
+#
+# $1 pool name
+#
+function clear_errors
+{
+       typeset pool=$1
+
+       log_must $ZPOOL clear $pool
+
+       if ! is_healthy $pool ; then
+               log_note "$pool should be healthy."
+               return 1
+       fi
+       if ! is_data_valid $pool ; then
+               log_note "Data should be valid in $pool."
+               return 1
+       fi
+
+       return 0
+}
+
+#
+# Remove the specified pool's virtual device files
+#
+# $1 Pool name
+# $2 Missing devices count
+#
+function remove_devs
+{
+       typeset pool=$1
+       typeset -i cnt=$2
+       typeset vdevs
+
+       vdevs=$(get_vdevs $pool $cnt)
+       log_must $RM -f $vdevs
+
+       sync_pool $pool
+}
+
+#
+# Recover the bad or missing device files in the pool
+#
+# $1 Pool name
+# $2 Missing devices count
+#
+function recover_bad_missing_devs
+{
+       typeset pool=$1
+       typeset -i cnt=$2
+       typeset vdevs
+
+       vdevs=$(get_vdevs $pool $cnt)
+       replace_missing_devs $pool $vdevs
+
+       if ! is_healthy $pool ; then
+               log_note "$pool should be healthy."
+               return 1
+       fi
+       if ! is_data_valid $pool ; then
+               log_note "Data should be valid in $pool."
+               return 1
+       fi
+
+       return 0
+}
diff --git a/tests/zfs-tests/tests/functional/redundancy/redundancy_001_pos.ksh b/tests/zfs-tests/tests/functional/redundancy/redundancy_001_pos.ksh
new file mode 100755 (executable)
index 0000000..e25a48b
--- /dev/null
@@ -0,0 +1,76 @@
+#!/bin/ksh -p
+#
+# CDDL HEADER START
+#
+# The contents of this file are subject to the terms of the
+# Common Development and Distribution License (the "License").
+# You may not use this file except in compliance with the License.
+#
+# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
+# or http://www.opensolaris.org/os/licensing.
+# See the License for the specific language governing permissions
+# and limitations under the License.
+#
+# When distributing Covered Code, include this CDDL HEADER in each
+# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
+# If applicable, add the following below this CDDL HEADER, with the
+# fields enclosed by brackets "[]" replaced with your own identifying
+# information: Portions Copyright [yyyy] [name of copyright owner]
+#
+# CDDL HEADER END
+#
+
+#
+# Copyright 2007 Sun Microsystems, Inc.  All rights reserved.
+# Use is subject to license terms.
+#
+
+#
+# Copyright (c) 2013 by Delphix. All rights reserved.
+#
+
+. $STF_SUITE/tests/functional/redundancy/redundancy.kshlib
+
+#
+# DESCRIPTION:
+#      A raidz pool can withstand at most 1 device failing or missing.
+#
+# STRATEGY:
+#      1. Create N(>2,<5) virtual disk files.
+#      2. Create raidz pool based on the virtual disk files.
+#      3. Fill the filesystem with directories and files.
+#      4. Record all the files and directories checksum information.
+#      5. Damaged one of the virtual disk file.
+#      6. Verify the data is correct to prove raidz can withstand 1 devicd is
+#         failing.
+#
+
+verify_runnable "global"
+
+log_assert "Verify raidz pool can withstand one device is failing."
+log_onexit cleanup
+
+typeset -i cnt=$(random 2 5)
+setup_test_env $TESTPOOL raidz $cnt
+
+#
+# Inject data corruption error for raidz pool
+#
+damage_devs $TESTPOOL 1 "label"
+log_must is_data_valid $TESTPOOL
+log_must clear_errors $TESTPOOL
+
+#
+# Inject bad device error for raidz pool
+#
+damage_devs $TESTPOOL 1
+log_must is_data_valid $TESTPOOL
+log_must recover_bad_missing_devs $TESTPOOL 1
+
+#
+# Inject missing device error for raidz pool
+#
+remove_devs $TESTPOOL 1
+log_must is_data_valid $TESTPOOL
+
+log_pass "Raidz pool can withstand one devices is failing passed."
diff --git a/tests/zfs-tests/tests/functional/redundancy/redundancy_002_pos.ksh b/tests/zfs-tests/tests/functional/redundancy/redundancy_002_pos.ksh
new file mode 100755 (executable)
index 0000000..b16687d
--- /dev/null
@@ -0,0 +1,83 @@
+#!/bin/ksh -p
+#
+# CDDL HEADER START
+#
+# The contents of this file are subject to the terms of the
+# Common Development and Distribution License (the "License").
+# You may not use this file except in compliance with the License.
+#
+# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
+# or http://www.opensolaris.org/os/licensing.
+# See the License for the specific language governing permissions
+# and limitations under the License.
+#
+# When distributing Covered Code, include this CDDL HEADER in each
+# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
+# If applicable, add the following below this CDDL HEADER, with the
+# fields enclosed by brackets "[]" replaced with your own identifying
+# information: Portions Copyright [yyyy] [name of copyright owner]
+#
+# CDDL HEADER END
+#
+
+#
+# Copyright 2007 Sun Microsystems, Inc.  All rights reserved.
+# Use is subject to license terms.
+#
+
+#
+# Copyright (c) 2013 by Delphix. All rights reserved.
+#
+
+. $STF_SUITE/tests/functional/redundancy/redundancy.kshlib
+
+#
+# DESCRIPTION:
+#      A raidz2 pool can withstand 2 devices are failing or missing.
+#
+# STRATEGY:
+#      1. Create N(>3,<5) virtual disk files.
+#      2. Create raidz2 pool based on the virtual disk files.
+#      3. Fill the filesystem with directories and files.
+#      4. Record all the files and directories checksum information.
+#      5. Damaged at most two of the virtual disk files.
+#      6. Verify the data is correct to prove raidz2 can withstand 2 devices
+#         are failing.
+#
+
+verify_runnable "global"
+
+log_assert "Verify raidz2 pool can withstand two devices are failing."
+log_onexit cleanup
+
+typeset -i cnt=$(random 3 5)
+setup_test_env $TESTPOOL raidz2 $cnt
+
+#
+# Inject data corruption errors for raidz2 pool
+#
+for i in 1 2; do
+       damage_devs $TESTPOOL $i "label"
+       log_must is_data_valid $TESTPOOL
+       log_must clear_errors $TESTPOOL
+done
+
+#
+# Inject bad devices errors for raidz2 pool
+#
+for i in 1 2; do
+       damage_devs $TESTPOOL $i
+       log_must is_data_valid $TESTPOOL
+       log_must recover_bad_missing_devs $TESTPOOL $i
+done
+
+#
+# Inject missing device errors for raidz2 pool
+#
+for i in 1 2; do
+       remove_devs $TESTPOOL $i
+       log_must is_data_valid $TESTPOOL
+       log_must recover_bad_missing_devs $TESTPOOL $i
+done
+
+log_pass "Raidz2 pool can withstand two devices are failing passed."
diff --git a/tests/zfs-tests/tests/functional/redundancy/redundancy_003_pos.ksh b/tests/zfs-tests/tests/functional/redundancy/redundancy_003_pos.ksh
new file mode 100755 (executable)
index 0000000..a1ca2cb
--- /dev/null
@@ -0,0 +1,93 @@
+#!/bin/ksh -p
+#
+# CDDL HEADER START
+#
+# The contents of this file are subject to the terms of the
+# Common Development and Distribution License (the "License").
+# You may not use this file except in compliance with the License.
+#
+# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
+# or http://www.opensolaris.org/os/licensing.
+# See the License for the specific language governing permissions
+# and limitations under the License.
+#
+# When distributing Covered Code, include this CDDL HEADER in each
+# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
+# If applicable, add the following below this CDDL HEADER, with the
+# fields enclosed by brackets "[]" replaced with your own identifying
+# information: Portions Copyright [yyyy] [name of copyright owner]
+#
+# CDDL HEADER END
+#
+
+#
+# Copyright 2007 Sun Microsystems, Inc.  All rights reserved.
+# Use is subject to license terms.
+#
+
+#
+# Copyright (c) 2013 by Delphix. All rights reserved.
+#
+
+. $STF_SUITE/tests/functional/redundancy/redundancy.kshlib
+
+#
+# DESCRIPTION:
+#      A mirrored pool can withstand N-1 device are failing or missing.
+#
+# STRATEGY:
+#      1. Create N(>2,<5) virtual disk files.
+#      2. Create mirror pool based on the virtual disk files.
+#      3. Fill the filesystem with directories and files.
+#      4. Record all the files and directories checksum information.
+#      5. Damaged at most N-1 of the virtual disk files.
+#      6. Verify the data are correct to prove mirror can withstand N-1 devices
+#         are failing.
+#
+
+verify_runnable "global"
+
+log_assert "Verify mirrored pool can withstand N-1 devices are failing or missing."
+log_onexit cleanup
+
+typeset -i cnt=$(random 2 5)
+setup_test_env $TESTPOOL mirror $cnt
+
+typeset -i i=1
+
+#
+# Inject data corruption errors for mirrored pool
+#
+while (( i < cnt )); do
+       damage_devs $TESTPOOL $i "label"
+       log_must is_data_valid $TESTPOOL
+       log_must clear_errors $TESTPOOL
+
+       (( i +=1 ))
+done
+
+#
+# Inject  bad devices errors for mirrored pool
+#
+i=1
+while (( i < cnt )); do
+        damage_devs $TESTPOOL $i
+        log_must is_data_valid $TESTPOOL
+       log_must recover_bad_missing_devs $TESTPOOL $i
+
+       (( i +=1 ))
+done
+
+#
+# Inject missing device errors for mirrored pool
+#
+i=1
+while (( i < cnt )); do
+        remove_devs $TESTPOOL $i
+        log_must is_data_valid $TESTPOOL
+       log_must recover_bad_missing_devs $TESTPOOL $i
+
+       (( i +=1 ))
+done
+
+log_pass "Mirrored pool can withstand N-1 devices failing as expected."
diff --git a/tests/zfs-tests/tests/functional/redundancy/redundancy_004_neg.ksh b/tests/zfs-tests/tests/functional/redundancy/redundancy_004_neg.ksh
new file mode 100755 (executable)
index 0000000..0d40c57
--- /dev/null
@@ -0,0 +1,66 @@
+#!/bin/ksh -p
+#
+# CDDL HEADER START
+#
+# The contents of this file are subject to the terms of the
+# Common Development and Distribution License (the "License").
+# You may not use this file except in compliance with the License.
+#
+# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
+# or http://www.opensolaris.org/os/licensing.
+# See the License for the specific language governing permissions
+# and limitations under the License.
+#
+# When distributing Covered Code, include this CDDL HEADER in each
+# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
+# If applicable, add the following below this CDDL HEADER, with the
+# fields enclosed by brackets "[]" replaced with your own identifying
+# information: Portions Copyright [yyyy] [name of copyright owner]
+#
+# CDDL HEADER END
+#
+
+#
+# Copyright 2007 Sun Microsystems, Inc.  All rights reserved.
+# Use is subject to license terms.
+#
+
+#
+# Copyright (c) 2013 by Delphix. All rights reserved.
+#
+
+. $STF_SUITE/tests/functional/redundancy/redundancy.kshlib
+
+#
+# DESCRIPTION:
+#      Striped pool have no data redundancy. Any device errors will
+#      cause data corruption.
+#
+# STRATEGY:
+#      1. Create N virtual disk file.
+#      2. Create stripe pool based on the virtual disk files.
+#      3. Fill the filesystem with directories and files.
+#      4. Record all the files and directories checksum information.
+#      5. Damage one of the virtual disk file.
+#      6. Verify the data is error.
+#
+
+verify_runnable "global"
+
+log_assert "Verify striped pool have no data redundancy."
+log_onexit cleanup
+
+typeset -i cnt=$(random 2 5)
+setup_test_env $TESTPOOL "" $cnt
+
+damage_devs $TESTPOOL 1 "keep_label"
+log_must $ZPOOL clear $TESTPOOL
+
+# Wait for the scrub intiated by the clear to wrap, or is_healthy will be wrong.
+while ! is_pool_scrubbed $TESTPOOL; do
+       sync
+done
+
+log_mustnot is_healthy $TESTPOOL
+
+log_pass "Striped pool has no data redundancy as expected."
diff --git a/tests/zfs-tests/tests/functional/redundancy/setup.ksh b/tests/zfs-tests/tests/functional/redundancy/setup.ksh
new file mode 100755 (executable)
index 0000000..e2c04fe
--- /dev/null
@@ -0,0 +1,36 @@
+#!/bin/ksh -p
+#
+# CDDL HEADER START
+#
+# The contents of this file are subject to the terms of the
+# Common Development and Distribution License (the "License").
+# You may not use this file except in compliance with the License.
+#
+# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
+# or http://www.opensolaris.org/os/licensing.
+# See the License for the specific language governing permissions
+# and limitations under the License.
+#
+# When distributing Covered Code, include this CDDL HEADER in each
+# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
+# If applicable, add the following below this CDDL HEADER, with the
+# fields enclosed by brackets "[]" replaced with your own identifying
+# information: Portions Copyright [yyyy] [name of copyright owner]
+#
+# CDDL HEADER END
+#
+
+#
+# Copyright 2007 Sun Microsystems, Inc.  All rights reserved.
+# Use is subject to license terms.
+#
+
+#
+# Copyright (c) 2013 by Delphix. All rights reserved.
+#
+
+. $STF_SUITE/include/libtest.shlib
+
+verify_runnable "global"
+
+log_pass
diff --git a/tests/zfs-tests/tests/functional/refquota/Makefile.am b/tests/zfs-tests/tests/functional/refquota/Makefile.am
new file mode 100644 (file)
index 0000000..5f7c7b6
--- /dev/null
@@ -0,0 +1,10 @@
+pkgdatadir = $(datadir)/@PACKAGE@/zfs-tests/tests/functional/refquota
+dist_pkgdata_SCRIPTS = \
+       setup.ksh \
+       cleanup.ksh \
+       refquota_001_pos.ksh \
+       refquota_002_pos.ksh \
+       refquota_003_pos.ksh \
+       refquota_004_pos.ksh \
+       refquota_005_pos.ksh \
+       refquota_006_neg.ksh
diff --git a/tests/zfs-tests/tests/functional/refquota/cleanup.ksh b/tests/zfs-tests/tests/functional/refquota/cleanup.ksh
new file mode 100755 (executable)
index 0000000..ea139ae
--- /dev/null
@@ -0,0 +1,35 @@
+#!/bin/ksh -p
+#
+# CDDL HEADER START
+#
+# The contents of this file are subject to the terms of the
+# Common Development and Distribution License (the "License").
+# You may not use this file except in compliance with the License.
+#
+# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
+# or http://www.opensolaris.org/os/licensing.
+# See the License for the specific language governing permissions
+# and limitations under the License.
+#
+# When distributing Covered Code, include this CDDL HEADER in each
+# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
+# If applicable, add the following below this CDDL HEADER, with the
+# fields enclosed by brackets "[]" replaced with your own identifying
+# information: Portions Copyright [yyyy] [name of copyright owner]
+#
+# CDDL HEADER END
+#
+
+#
+# Copyright 2008 Sun Microsystems, Inc.  All rights reserved.
+# Use is subject to license terms.
+#
+
+#
+# Copyright (c) 2013 by Delphix. All rights reserved.
+#
+
+. $STF_SUITE/include/libtest.shlib
+
+verify_runnable "both"
+default_cleanup
diff --git a/tests/zfs-tests/tests/functional/refquota/refquota_001_pos.ksh b/tests/zfs-tests/tests/functional/refquota/refquota_001_pos.ksh
new file mode 100755 (executable)
index 0000000..9f974d8
--- /dev/null
@@ -0,0 +1,77 @@
+#!/bin/ksh -p
+#
+# CDDL HEADER START
+#
+# The contents of this file are subject to the terms of the
+# Common Development and Distribution License (the "License").
+# You may not use this file except in compliance with the License.
+#
+# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
+# or http://www.opensolaris.org/os/licensing.
+# See the License for the specific language governing permissions
+# and limitations under the License.
+#
+# When distributing Covered Code, include this CDDL HEADER in each
+# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
+# If applicable, add the following below this CDDL HEADER, with the
+# fields enclosed by brackets "[]" replaced with your own identifying
+# information: Portions Copyright [yyyy] [name of copyright owner]
+#
+# CDDL HEADER END
+#
+
+#
+# Copyright 2008 Sun Microsystems, Inc.  All rights reserved.
+# Use is subject to license terms.
+#
+
+#
+# Copyright (c) 2013 by Delphix. All rights reserved.
+#
+
+. $STF_SUITE/include/libtest.shlib
+
+#
+# DESCRIPTION:
+#      refquota limits the amount of space a dataset can consume, but does
+#      not include space used by descendents.
+#
+# STRATEGY:
+#      1. Setting refquota in given filesystem
+#      2. Create descendent filesystem
+#      3. Verify refquota limits the amount of space a dataset can consume
+#      4. Verify the limit does not impact descendents
+#
+
+verify_runnable "both"
+
+function cleanup
+{
+       log_must $ZFS destroy -rf $TESTPOOL/$TESTFS
+       log_must $ZFS create $TESTPOOL/$TESTFS
+       log_must $ZFS set mountpoint=$TESTDIR $TESTPOOL/$TESTFS
+}
+
+log_assert "refquota limits the amount of space a dataset can consume, " \
+       "but does not include space used by descendents."
+log_onexit cleanup
+
+fs=$TESTPOOL/$TESTFS
+sub=$fs/sub
+log_must $ZFS create $sub
+
+log_must $ZFS set refquota=10M $fs
+mntpnt=$(get_prop mountpoint $fs)
+
+log_mustnot $MKFILE 11M $mntpnt/file
+log_must $MKFILE 9M $mntpnt/file
+log_must $ZFS snapshot $fs@snap
+log_mustnot $MKFILE 2M $mntpnt/file2
+
+mntpnt=$(get_prop mountpoint $sub)
+log_must $MKFILE 10M $mntpnt/file
+log_must $ZFS snapshot $sub@snap
+log_must $MKFILE 10 $mntpnt/file2
+
+log_pass "refquota limits the amount of space a dataset can consume, " \
+       "but does not include space used by descendents."
diff --git a/tests/zfs-tests/tests/functional/refquota/refquota_002_pos.ksh b/tests/zfs-tests/tests/functional/refquota/refquota_002_pos.ksh
new file mode 100755 (executable)
index 0000000..7ee5967
--- /dev/null
@@ -0,0 +1,90 @@
+#!/bin/ksh -p
+#
+# CDDL HEADER START
+#
+# The contents of this file are subject to the terms of the
+# Common Development and Distribution License (the "License").
+# You may not use this file except in compliance with the License.
+#
+# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
+# or http://www.opensolaris.org/os/licensing.
+# See the License for the specific language governing permissions
+# and limitations under the License.
+#
+# When distributing Covered Code, include this CDDL HEADER in each
+# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
+# If applicable, add the following below this CDDL HEADER, with the
+# fields enclosed by brackets "[]" replaced with your own identifying
+# information: Portions Copyright [yyyy] [name of copyright owner]
+#
+# CDDL HEADER END
+#
+
+#
+# Copyright 2008 Sun Microsystems, Inc.  All rights reserved.
+# Use is subject to license terms.
+#
+
+#
+# Copyright (c) 2013 by Delphix. All rights reserved.
+#
+
+. $STF_SUITE/include/libtest.shlib
+
+#
+# DESCRIPTION:
+#      Quotas are enforced using the minimum of the two properties:
+#      quota & refquota
+#
+# STRATEGY:
+#      1. Set value for quota and refquota. Quota less than refquota.
+#      2. Creating file which should be limited by quota.
+#      3. Switch the value of quota and refquota.
+#      4. Verify file should be limited by refquota.
+#
+
+verify_runnable "both"
+
+function cleanup
+{
+       log_must $ZFS destroy -rf $TESTPOOL/$TESTFS
+       log_must $ZFS create $TESTPOOL/$TESTFS
+       log_must $ZFS set mountpoint=$TESTDIR $TESTPOOL/$TESTFS
+}
+
+log_assert "Quotas are enforced using the minimum of the two properties"
+log_onexit cleanup
+
+TESTFILE='testfile'
+fs=$TESTPOOL/$TESTFS
+log_must $ZFS set quota=15M $fs
+log_must $ZFS set refquota=25M $fs
+
+mntpnt=$(get_prop mountpoint $fs)
+log_mustnot $MKFILE 20M $mntpnt/$TESTFILE
+typeset -i used quota
+used=$(get_prop used $fs)
+quota=$(get_prop quota $fs)
+((used = used / (1024 * 1024)))
+((quota = quota / (1024 * 1024)))
+if [[ $used -ne $quota ]]; then
+       log_fail "ERROR: $used -ne $quota Quotas are not limited by quota"
+fi
+
+#
+# Switch the value of them and try again
+#
+log_must $RM $mntpnt/$TESTFILE
+log_must $ZFS set quota=25M $fs
+log_must $ZFS set refquota=15M $fs
+
+log_mustnot $MKFILE 20M $mntpnt/$TESTFILE
+used=$(get_prop used $fs)
+refquota=$(get_prop refquota $fs)
+((used = used / (1024 * 1024)))
+((refquota = refquota / (1024 * 1024)))
+if [[ $used -ne $refquota ]]; then
+       log_fail "ERROR: $used -ne $refquota Quotas are not limited by refquota"
+fi
+
+log_pass "Quotas are enforced using the minimum of the two properties"
diff --git a/tests/zfs-tests/tests/functional/refquota/refquota_003_pos.ksh b/tests/zfs-tests/tests/functional/refquota/refquota_003_pos.ksh
new file mode 100755 (executable)
index 0000000..8026e7d
--- /dev/null
@@ -0,0 +1,83 @@
+#!/bin/ksh -p
+#
+# CDDL HEADER START
+#
+# The contents of this file are subject to the terms of the
+# Common Development and Distribution License (the "License").
+# You may not use this file except in compliance with the License.
+#
+# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
+# or http://www.opensolaris.org/os/licensing.
+# See the License for the specific language governing permissions
+# and limitations under the License.
+#
+# When distributing Covered Code, include this CDDL HEADER in each
+# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
+# If applicable, add the following below this CDDL HEADER, with the
+# fields enclosed by brackets "[]" replaced with your own identifying
+# information: Portions Copyright [yyyy] [name of copyright owner]
+#
+# CDDL HEADER END
+#
+
+#
+# Copyright 2008 Sun Microsystems, Inc.  All rights reserved.
+# Use is subject to license terms.
+#
+
+#
+# Copyright (c) 2013 by Delphix. All rights reserved.
+#
+
+. $STF_SUITE/include/libtest.shlib
+
+#
+# DESCRIPTION:
+#      Sub-filesystem quotas are not enforced by property 'refquota'
+#
+# STRATEGY:
+#      1. Setting quota and refquota for parent. refquota < quota
+#      2. Verify sub-filesystem will not be limited by refquota
+#      3. Verify sub-filesystem will only be limited by quota
+#
+
+verify_runnable "both"
+
+function cleanup
+{
+       log_must $ZFS destroy -rf $TESTPOOL/$TESTFS
+       log_must $ZFS create $TESTPOOL/$TESTFS
+       log_must $ZFS set mountpoint=$TESTDIR $TESTPOOL/$TESTFS
+}
+
+log_assert "Sub-filesystem quotas are not enforced by property 'refquota'"
+log_onexit cleanup
+
+TESTFILE='testfile'
+fs=$TESTPOOL/$TESTFS
+log_must $ZFS set quota=25M $fs
+log_must $ZFS set refquota=10M $fs
+log_must $ZFS create $fs/subfs
+
+mntpnt=$(get_prop mountpoint $fs/subfs)
+log_must $MKFILE 20M $mntpnt/$TESTFILE
+
+typeset -i used quota refquota
+used=$(get_prop used $fs)
+refquota=$(get_prop refquota $fs)
+((used = used / (1024 * 1024)))
+((refquota = refquota / (1024 * 1024)))
+if [[ $used -lt $refquota ]]; then
+       log_fail "ERROR: $used < $refquota subfs quotas are limited by refquota"
+fi
+
+log_mustnot $MKFILE 20M $mntpnt/$TESTFILE.2
+used=$(get_prop used $fs)
+quota=$(get_prop quota $fs)
+((used = used / (1024 * 1024)))
+((quota = quota / (1024 * 1024)))
+if [[ $used -gt $quota ]]; then
+       log_fail "ERROR: $used > $quota subfs quotas aren't limited by quota"
+fi
+
+log_pass "Sub-filesystem quotas are not enforced by property 'refquota'"
diff --git a/tests/zfs-tests/tests/functional/refquota/refquota_004_pos.ksh b/tests/zfs-tests/tests/functional/refquota/refquota_004_pos.ksh
new file mode 100755 (executable)
index 0000000..2d7902e
--- /dev/null
@@ -0,0 +1,76 @@
+#!/bin/ksh -p
+#
+# CDDL HEADER START
+#
+# The contents of this file are subject to the terms of the
+# Common Development and Distribution License (the "License").
+# You may not use this file except in compliance with the License.
+#
+# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
+# or http://www.opensolaris.org/os/licensing.
+# See the License for the specific language governing permissions
+# and limitations under the License.
+#
+# When distributing Covered Code, include this CDDL HEADER in each
+# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
+# If applicable, add the following below this CDDL HEADER, with the
+# fields enclosed by brackets "[]" replaced with your own identifying
+# information: Portions Copyright [yyyy] [name of copyright owner]
+#
+# CDDL HEADER END
+#
+
+#
+# Copyright 2008 Sun Microsystems, Inc.  All rights reserved.
+# Use is subject to license terms.
+#
+
+#
+# Copyright (c) 2013 by Delphix. All rights reserved.
+#
+
+. $STF_SUITE/include/libtest.shlib
+
+#
+# DESCRIPTION:
+#      refquotas are not limited by snapshots.
+#
+# STRATEGY:
+#      1. Setting refquota < quota
+#      2. Create file in filesytem, take snapshot and remove the file
+#      3. Verify snapshot will not consume refquota
+#
+
+verify_runnable "both"
+
+function cleanup
+{
+       log_must $ZFS destroy -rf $TESTPOOL/$TESTFS
+       log_must $ZFS create $TESTPOOL/$TESTFS
+       log_must $ZFS set mountpoint=$TESTDIR $TESTPOOL/$TESTFS
+}
+
+log_assert "refquotas are not limited by snapshots."
+log_onexit cleanup
+
+TESTFILE='testfile'
+fs=$TESTPOOL/$TESTFS
+log_must $ZFS set quota=25M $fs
+log_must $ZFS set refquota=15M $fs
+
+mntpnt=$(get_prop mountpoint $fs)
+typeset -i i=0
+while ((i < 3)); do
+       log_must $MKFILE 7M $mntpnt/$TESTFILE.$i
+       log_must $ZFS snapshot $fs@snap.$i
+       log_must $RM $mntpnt/$TESTFILE.$i
+
+       ((i += 1))
+done
+
+#
+# Verify out of the limitation of 'quota'
+#
+log_mustnot $MKFILE 7M $mntpnt/$TESTFILE
+
+log_pass "refquotas are not limited by snapshots."
diff --git a/tests/zfs-tests/tests/functional/refquota/refquota_005_pos.ksh b/tests/zfs-tests/tests/functional/refquota/refquota_005_pos.ksh
new file mode 100755 (executable)
index 0000000..5e6ad12
--- /dev/null
@@ -0,0 +1,77 @@
+#!/bin/ksh -p
+#
+# CDDL HEADER START
+#
+# The contents of this file are subject to the terms of the
+# Common Development and Distribution License (the "License").
+# You may not use this file except in compliance with the License.
+#
+# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
+# or http://www.opensolaris.org/os/licensing.
+# See the License for the specific language governing permissions
+# and limitations under the License.
+#
+# When distributing Covered Code, include this CDDL HEADER in each
+# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
+# If applicable, add the following below this CDDL HEADER, with the
+# fields enclosed by brackets "[]" replaced with your own identifying
+# information: Portions Copyright [yyyy] [name of copyright owner]
+#
+# CDDL HEADER END
+#
+
+#
+# Copyright 2008 Sun Microsystems, Inc.  All rights reserved.
+# Use is subject to license terms.
+#
+
+#
+# Copyright (c) 2013 by Delphix. All rights reserved.
+#
+
+. $STF_SUITE/include/libtest.shlib
+
+#
+# DESCRIPTION:
+#      refquotas are not limited by sub-filesystem snapshots.
+#
+# STRATEGY:
+#      1. Setting refquota < quota for parent
+#      2. Create file in sub-filesytem, take snapshot and remove the file
+#      3. Verify sub-filesystem snapshot will not consume refquota
+#
+
+verify_runnable "both"
+
+function cleanup
+{
+       log_must $ZFS destroy -rf $TESTPOOL/$TESTFS
+       log_must $ZFS create $TESTPOOL/$TESTFS
+       log_must $ZFS set mountpoint=$TESTDIR $TESTPOOL/$TESTFS
+}
+
+log_assert "refquotas are not limited by sub-filesystem snapshots."
+log_onexit cleanup
+
+TESTFILE='testfile'
+fs=$TESTPOOL/$TESTFS
+log_must $ZFS set quota=25M $fs
+log_must $ZFS set refquota=15M $fs
+log_must $ZFS create $fs/subfs
+
+mntpnt=$(get_prop mountpoint $fs/subfs)
+typeset -i i=0
+while ((i < 3)); do
+       log_must $MKFILE 7M $mntpnt/$TESTFILE.$i
+       log_must $ZFS snapshot $fs/subfs@snap.$i
+       log_must $RM $mntpnt/$TESTFILE.$i
+
+       ((i += 1))
+done
+
+#
+# Verify out of the limitation of 'quota'
+#
+log_mustnot $MKFILE 7M $mntpnt/$TESTFILE
+
+log_pass "refquotas are not limited by sub-filesystem snapshots"
diff --git a/tests/zfs-tests/tests/functional/refquota/refquota_006_neg.ksh b/tests/zfs-tests/tests/functional/refquota/refquota_006_neg.ksh
new file mode 100755 (executable)
index 0000000..18b0a4f
--- /dev/null
@@ -0,0 +1,70 @@
+#!/bin/ksh -p
+#
+# CDDL HEADER START
+#
+# The contents of this file are subject to the terms of the
+# Common Development and Distribution License (the "License").
+# You may not use this file except in compliance with the License.
+#
+# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
+# or http://www.opensolaris.org/os/licensing.
+# See the License for the specific language governing permissions
+# and limitations under the License.
+#
+# When distributing Covered Code, include this CDDL HEADER in each
+# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
+# If applicable, add the following below this CDDL HEADER, with the
+# fields enclosed by brackets "[]" replaced with your own identifying
+# information: Portions Copyright [yyyy] [name of copyright owner]
+#
+# CDDL HEADER END
+#
+
+#
+# Copyright 2008 Sun Microsystems, Inc.  All rights reserved.
+# Use is subject to license terms.
+#
+
+#
+# Copyright (c) 2013 by Delphix. All rights reserved.
+#
+
+. $STF_SUITE/include/libtest.shlib
+
+#
+# DESCRIPTION:
+#      'zfs set refquota/refreserv' can handle incorrect arguments correctly.
+#
+# STRATEGY:
+#      1. Setup incorrect arguments arrays.
+#      2. Set the bad argument to refquota.
+#      3. Verify zfs can handle it correctly.
+#
+
+verify_runnable "both"
+
+function cleanup
+{
+       log_must $ZFS set refquota=none $TESTPOOL/$TESTFS
+       log_must $ZFS set refreserv=none $TESTPOOL/$TESTFS
+}
+
+log_assert "'zfs set refquota' can handle incorrect arguments correctly."
+log_onexit cleanup
+
+set -A badopt  \
+       "None"          "-1"            "1TT"           "%5"            \
+       "123!"          "@456"          "7#89"          "0\$"           \
+       "abc123%"       "123%s"         "12%s3"         "%c123"         \
+       "123%d"         "%x123"         "12%p3"         "^def456"       \
+       "\0"            "x0"
+
+typeset -i i=0
+while ((i < ${#badopt[@]})); do
+       log_mustnot $ZFS set refquota=${badopt[$i]} $TESTPOOL/$TESTFS
+       log_mustnot $ZFS set refreserv=${badopt[$i]} $TESTPOOL/$TESTFS
+
+       ((i += 1))
+done
+
+log_pass "'zfs set refquota' can handle incorrect arguments correctly."
diff --git a/tests/zfs-tests/tests/functional/refquota/setup.ksh b/tests/zfs-tests/tests/functional/refquota/setup.ksh
new file mode 100755 (executable)
index 0000000..a34453b
--- /dev/null
@@ -0,0 +1,36 @@
+#!/bin/ksh -p
+#
+# CDDL HEADER START
+#
+# The contents of this file are subject to the terms of the
+# Common Development and Distribution License (the "License").
+# You may not use this file except in compliance with the License.
+#
+# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
+# or http://www.opensolaris.org/os/licensing.
+# See the License for the specific language governing permissions
+# and limitations under the License.
+#
+# When distributing Covered Code, include this CDDL HEADER in each
+# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
+# If applicable, add the following below this CDDL HEADER, with the
+# fields enclosed by brackets "[]" replaced with your own identifying
+# information: Portions Copyright [yyyy] [name of copyright owner]
+#
+# CDDL HEADER END
+#
+
+#
+# Copyright 2008 Sun Microsystems, Inc.  All rights reserved.
+# Use is subject to license terms.
+#
+
+#
+# Copyright (c) 2013 by Delphix. All rights reserved.
+#
+
+. $STF_SUITE/include/libtest.shlib
+
+verify_runnable "both"
+DISK=${DISKS%% *}
+default_setup $DISK
diff --git a/tests/zfs-tests/tests/functional/refreserv/Makefile.am b/tests/zfs-tests/tests/functional/refreserv/Makefile.am
new file mode 100644 (file)
index 0000000..41c88a6
--- /dev/null
@@ -0,0 +1,10 @@
+pkgdatadir = $(datadir)/@PACKAGE@/zfs-tests/tests/functional/refreserv
+dist_pkgdata_SCRIPTS = \
+       refreserv.cfg \
+       setup.ksh \
+       cleanup.ksh \
+       refreserv_001_pos.ksh \
+       refreserv_002_pos.ksh \
+       refreserv_003_pos.ksh \
+       refreserv_004_pos.ksh \
+       refreserv_005_pos.ksh
diff --git a/tests/zfs-tests/tests/functional/refreserv/cleanup.ksh b/tests/zfs-tests/tests/functional/refreserv/cleanup.ksh
new file mode 100755 (executable)
index 0000000..ea139ae
--- /dev/null
@@ -0,0 +1,35 @@
+#!/bin/ksh -p
+#
+# CDDL HEADER START
+#
+# The contents of this file are subject to the terms of the
+# Common Development and Distribution License (the "License").
+# You may not use this file except in compliance with the License.
+#
+# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
+# or http://www.opensolaris.org/os/licensing.
+# See the License for the specific language governing permissions
+# and limitations under the License.
+#
+# When distributing Covered Code, include this CDDL HEADER in each
+# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
+# If applicable, add the following below this CDDL HEADER, with the
+# fields enclosed by brackets "[]" replaced with your own identifying
+# information: Portions Copyright [yyyy] [name of copyright owner]
+#
+# CDDL HEADER END
+#
+
+#
+# Copyright 2008 Sun Microsystems, Inc.  All rights reserved.
+# Use is subject to license terms.
+#
+
+#
+# Copyright (c) 2013 by Delphix. All rights reserved.
+#
+
+. $STF_SUITE/include/libtest.shlib
+
+verify_runnable "both"
+default_cleanup
diff --git a/tests/zfs-tests/tests/functional/refreserv/refreserv.cfg b/tests/zfs-tests/tests/functional/refreserv/refreserv.cfg
new file mode 100644 (file)
index 0000000..8c892db
--- /dev/null
@@ -0,0 +1,31 @@
+#
+# CDDL HEADER START
+#
+# The contents of this file are subject to the terms of the
+# Common Development and Distribution License (the "License").
+# You may not use this file except in compliance with the License.
+#
+# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
+# or http://www.opensolaris.org/os/licensing.
+# See the License for the specific language governing permissions
+# and limitations under the License.
+#
+# When distributing Covered Code, include this CDDL HEADER in each
+# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
+# If applicable, add the following below this CDDL HEADER, with the
+# fields enclosed by brackets "[]" replaced with your own identifying
+# information: Portions Copyright [yyyy] [name of copyright owner]
+#
+# CDDL HEADER END
+#
+
+#
+# Copyright 2008 Sun Microsystems, Inc.  All rights reserved.
+# Use is subject to license terms.
+#
+
+#
+# Copyright (c) 2013 by Delphix. All rights reserved.
+#
+
+export TESTFILE=testfile
diff --git a/tests/zfs-tests/tests/functional/refreserv/refreserv_001_pos.ksh b/tests/zfs-tests/tests/functional/refreserv/refreserv_001_pos.ksh
new file mode 100755 (executable)
index 0000000..f0f45ac
--- /dev/null
@@ -0,0 +1,75 @@
+#!/bin/ksh -p
+#
+# CDDL HEADER START
+#
+# The contents of this file are subject to the terms of the
+# Common Development and Distribution License (the "License").
+# You may not use this file except in compliance with the License.
+#
+# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
+# or http://www.opensolaris.org/os/licensing.
+# See the License for the specific language governing permissions
+# and limitations under the License.
+#
+# When distributing Covered Code, include this CDDL HEADER in each
+# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
+# If applicable, add the following below this CDDL HEADER, with the
+# fields enclosed by brackets "[]" replaced with your own identifying
+# information: Portions Copyright [yyyy] [name of copyright owner]
+#
+# CDDL HEADER END
+#
+
+#
+# Copyright 2008 Sun Microsystems, Inc.  All rights reserved.
+# Use is subject to license terms.
+#
+
+#
+# Copyright (c) 2013 by Delphix. All rights reserved.
+#
+
+. $STF_SUITE/include/libtest.shlib
+. $STF_SUITE/tests/functional/refreserv/refreserv.cfg
+
+#
+# DESCRIPTION:
+#      Reservations are enforced using the maximum of 'reserv' and 'refreserv'
+#
+# STRATEGY:
+#      1. Setting quota for parent filesystem.
+#      2. Setting reservation and refreservation for sub-filesystem.
+#      3. Verify the sub-fs reservation are enforced by the maximum of 'reserv'
+#         and 'refreserv'.
+#
+
+verify_runnable "both"
+
+function cleanup
+{
+       log_must $ZFS destroy -rf $TESTPOOL/$TESTFS
+       log_must $ZFS create $TESTPOOL/$TESTFS
+       log_must $ZFS set mountpoint=$TESTDIR $TESTPOOL/$TESTFS
+}
+
+log_assert "Reservations are enforced using the maximum of " \
+       "'reserv' and 'refreserv'"
+log_onexit cleanup
+
+fs=$TESTPOOL/$TESTFS ; subfs=$fs/subfs
+log_must $ZFS create $subfs
+log_must $ZFS set quota=25M $fs
+
+log_must $ZFS set reserv=10M $subfs
+log_must $ZFS set refreserv=20M $subfs
+mntpnt=$(get_prop mountpoint $fs)
+log_mustnot $MKFILE 15M $mntpnt/$TESTFILE
+
+log_must $RM -f $mntpnt/$TESTFILE
+
+log_must $ZFS set reserv=20M $subfs
+log_must $ZFS set refreserv=10M $subfs
+log_mustnot $MKFILE 15M $mntpnt/$TESTFILE
+
+log_pass "Reservations are enforced using the maximum of " \
+       "'reserv' and 'refreserv'"
diff --git a/tests/zfs-tests/tests/functional/refreserv/refreserv_002_pos.ksh b/tests/zfs-tests/tests/functional/refreserv/refreserv_002_pos.ksh
new file mode 100755 (executable)
index 0000000..7a39a8d
--- /dev/null
@@ -0,0 +1,114 @@
+#!/bin/ksh -p
+#
+# CDDL HEADER START
+#
+# The contents of this file are subject to the terms of the
+# Common Development and Distribution License (the "License").
+# You may not use this file except in compliance with the License.
+#
+# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
+# or http://www.opensolaris.org/os/licensing.
+# See the License for the specific language governing permissions
+# and limitations under the License.
+#
+# When distributing Covered Code, include this CDDL HEADER in each
+# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
+# If applicable, add the following below this CDDL HEADER, with the
+# fields enclosed by brackets "[]" replaced with your own identifying
+# information: Portions Copyright [yyyy] [name of copyright owner]
+#
+# CDDL HEADER END
+#
+
+#
+# Copyright 2009 Sun Microsystems, Inc.  All rights reserved.
+# Use is subject to license terms.
+#
+
+#
+# Copyright (c) 2013 by Delphix. All rights reserved.
+#
+
+. $STF_SUITE/include/libtest.shlib
+. $STF_SUITE/tests/functional/refreserv/refreserv.cfg
+
+#
+# DESCRIPTION:
+#      Setting full size as refreservation, verify no snapshot can be created.
+#
+# STRATEGY:
+#      1. Setting full size as refreservation on pool
+#      2. Verify no snapshot can be created on this pool
+#      3. Setting full size as refreservation on filesystem
+#      4. Verify no snapshot can be created on it and its subfs
+#
+
+verify_runnable "both"
+
+function cleanup
+{
+       if is_global_zone ; then
+               log_must $ZFS set refreservation=none $TESTPOOL
+
+               if datasetexists $TESTPOOL@snap ; then
+                       log_must $ZFS destroy -f $TESTPOOL@snap
+               fi
+       fi
+       log_must $ZFS destroy -rf $TESTPOOL/$TESTFS
+       log_must $ZFS create $TESTPOOL/$TESTFS
+       log_must $ZFS set mountpoint=$TESTDIR $TESTPOOL/$TESTFS
+}
+
+# This function iteratively increases refreserv to its highest possible
+# value. Simply setting refreserv == quota can allow enough writes to
+# complete that the test fails.
+function max_refreserv
+{
+       typeset ds=$1
+       typeset -i incsize=131072
+       typeset -i rr=$(get_prop available $ds)
+
+       log_must $ZFS set refreserv=$rr $ds
+       while :; do
+               $ZFS set refreserv=$((rr + incsize)) $ds >/dev/null 2>&1
+               if [[ $? == 0 ]]; then
+                       ((rr += incsize))
+                       continue
+               else
+                       ((incsize /= 2))
+                       ((incsize == 0)) && break
+               fi
+       done
+}
+
+
+log_assert "Setting full size as refreservation, verify no snapshot " \
+       "can be created."
+log_onexit cleanup
+
+log_must $ZFS create $TESTPOOL/$TESTFS/subfs
+
+typeset datasets
+if is_global_zone; then
+       datasets="$TESTPOOL $TESTPOOL/$TESTFS $TESTPOOL/$TESTFS/subfs"
+else
+       datasets="$TESTPOOL/$TESTFS $TESTPOOL/$TESTFS/subfs"
+fi
+
+for ds in $datasets; do
+       #
+       # Verify refreservation on dataset
+       #
+       log_must $ZFS set quota=25M $ds
+       max_refreserv $ds
+       log_mustnot $ZFS snapshot $ds@snap
+       if datasetexists $ds@snap ; then
+               log_fail "ERROR: $ds@snap should not exists."
+       fi
+
+       log_must $ZFS set quota=none $ds
+       log_must $ZFS set refreservation=none $ds
+done
+
+log_pass "Setting full size as refreservation, verify no snapshot " \
+       "can be created."
diff --git a/tests/zfs-tests/tests/functional/refreserv/refreserv_003_pos.ksh b/tests/zfs-tests/tests/functional/refreserv/refreserv_003_pos.ksh
new file mode 100755 (executable)
index 0000000..1738291
--- /dev/null
@@ -0,0 +1,77 @@
+#!/bin/ksh -p
+#
+# CDDL HEADER START
+#
+# The contents of this file are subject to the terms of the
+# Common Development and Distribution License (the "License").
+# You may not use this file except in compliance with the License.
+#
+# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
+# or http://www.opensolaris.org/os/licensing.
+# See the License for the specific language governing permissions
+# and limitations under the License.
+#
+# When distributing Covered Code, include this CDDL HEADER in each
+# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
+# If applicable, add the following below this CDDL HEADER, with the
+# fields enclosed by brackets "[]" replaced with your own identifying
+# information: Portions Copyright [yyyy] [name of copyright owner]
+#
+# CDDL HEADER END
+#
+
+#
+# Copyright 2008 Sun Microsystems, Inc.  All rights reserved.
+# Use is subject to license terms.
+#
+
+#
+# Copyright (c) 2013 by Delphix. All rights reserved.
+#
+
+. $STF_SUITE/include/libtest.shlib
+. $STF_SUITE/tests/functional/refreserv/refreserv.cfg
+
+#
+# DESCRIPTION:
+#      Verify a snapshot will only be allowed if there is enough free pool
+#      space outside of this refreservation.
+#
+# STRATEGY:
+#      1. Setting quota and refservation
+#      2. Verify snapshot can be created, when used =< quota - refreserv
+#      3. Verify failed to create snapshot, when used > quota - refreserv
+#
+
+verify_runnable "both"
+
+function cleanup
+{
+       log_must $ZFS destroy -rf $TESTPOOL/$TESTFS
+       log_must $ZFS create $TESTPOOL/$TESTFS
+       log_must $ZFS set mountpoint=$TESTDIR $TESTPOOL/$TESTFS
+}
+
+log_assert "Verify a snapshot will only be allowed if there is enough " \
+       "free space outside of this refreservation."
+log_onexit cleanup
+
+fs=$TESTPOOL/$TESTFS
+log_must $ZFS set quota=25M $fs
+log_must $ZFS set refreservation=10M $fs
+
+mntpnt=$(get_prop mountpoint $fs)
+log_must $MKFILE 7M $mntpnt/$TESTFILE
+log_must $ZFS snapshot $fs@snap
+
+log_must $MKFILE 7M $mntpnt/$TESTFILE.2
+log_must $ZFS snapshot $fs@snap2
+
+log_must $MKFILE 7M $mntpnt/$TESTFILE.3
+log_mustnot $ZFS snapshot $fs@snap3
+if datasetexists $fs@snap3 ; then
+       log_fail "ERROR: $fs@snap3 should not exists."
+fi
+
+log_pass "Verify a snapshot will only be allowed if there is enough " \
+       "free space outside of this refreservation."
diff --git a/tests/zfs-tests/tests/functional/refreserv/refreserv_004_pos.ksh b/tests/zfs-tests/tests/functional/refreserv/refreserv_004_pos.ksh
new file mode 100755 (executable)
index 0000000..8238573
--- /dev/null
@@ -0,0 +1,90 @@
+#!/bin/ksh -p
+#
+# CDDL HEADER START
+#
+# The contents of this file are subject to the terms of the
+# Common Development and Distribution License (the "License").
+# You may not use this file except in compliance with the License.
+#
+# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
+# or http://www.opensolaris.org/os/licensing.
+# See the License for the specific language governing permissions
+# and limitations under the License.
+#
+# When distributing Covered Code, include this CDDL HEADER in each
+# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
+# If applicable, add the following below this CDDL HEADER, with the
+# fields enclosed by brackets "[]" replaced with your own identifying
+# information: Portions Copyright [yyyy] [name of copyright owner]
+#
+# CDDL HEADER END
+#
+
+#
+# Copyright 2009 Sun Microsystems, Inc.  All rights reserved.
+# Use is subject to license terms.
+#
+
+#
+# Copyright (c) 2013 by Delphix. All rights reserved.
+#
+
+. $STF_SUITE/include/libtest.shlib
+. $STF_SUITE/tests/functional/refreserv/refreserv.cfg
+
+#
+# DESCRIPTION:
+#      Verify refreservation is limited by available space.
+#
+# STRATEGY:
+#      1. Setting quota and refreservation on parent filesystem.
+#      2. Get available space on sub-filesystem.
+#      3. Verify refreservation is limited by available on it.
+#
+
+verify_runnable "both"
+
+function cleanup
+{
+       if is_global_zone ; then
+               log_must $ZFS set refreservation=none $TESTPOOL
+       fi
+       log_must $ZFS destroy -rf $TESTPOOL/$TESTFS
+       log_must $ZFS create $TESTPOOL/$TESTFS
+       log_must $ZFS set mountpoint=$TESTDIR $TESTPOOL/$TESTFS
+}
+
+log_assert "Verify refreservation is limited by available space."
+log_onexit cleanup
+
+pool=$TESTPOOL ; fs=$pool/$TESTFS ; subfs=$fs/subfs
+log_must $ZFS create $subfs
+
+typeset datasets
+if is_global_zone; then
+        datasets="$pool $fs"
+else
+        datasets="$fs"
+fi
+
+for ds in $datasets; do
+       log_must $ZFS set quota=25M $ds
+       log_must $ZFS set refreservation=15M $ds
+
+       typeset -i avail
+       avail=$(get_prop avail $subfs)
+       log_must $ZFS set refreservation=$avail $subfs
+       typeset mntpnt
+       mntpnt=$(get_prop mountpoint $subfs)
+       log_must $MKFILE $avail $mntpnt/$TESTFILE
+
+       typeset -i exceed
+       ((exceed = avail + 1))
+       log_mustnot $ZFS set refreservation=$exceed $subfs
+       log_mustnot $MKFILE $avail $mntpnt/$TESTFILE
+
+       log_must $ZFS set quota=none $ds
+       log_must $ZFS set reservation=15M $ds
+done
+
+log_pass "Verify refreservation is limited by available space."
diff --git a/tests/zfs-tests/tests/functional/refreserv/refreserv_005_pos.ksh b/tests/zfs-tests/tests/functional/refreserv/refreserv_005_pos.ksh
new file mode 100755 (executable)
index 0000000..5a3adbb
--- /dev/null
@@ -0,0 +1,71 @@
+#!/bin/ksh -p
+#
+# CDDL HEADER START
+#
+# The contents of this file are subject to the terms of the
+# Common Development and Distribution License (the "License").
+# You may not use this file except in compliance with the License.
+#
+# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
+# or http://www.opensolaris.org/os/licensing.
+# See the License for the specific language governing permissions
+# and limitations under the License.
+#
+# When distributing Covered Code, include this CDDL HEADER in each
+# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
+# If applicable, add the following below this CDDL HEADER, with the
+# fields enclosed by brackets "[]" replaced with your own identifying
+# information: Portions Copyright [yyyy] [name of copyright owner]
+#
+# CDDL HEADER END
+#
+
+#
+# Copyright 2008 Sun Microsystems, Inc.  All rights reserved.
+# Use is subject to license terms.
+#
+
+#
+# Copyright (c) 2013 by Delphix. All rights reserved.
+#
+
+. $STF_SUITE/include/libtest.shlib
+
+#
+# DESCRIPTION:
+#      Volume refreservation is limited by volsize
+#
+# STRATEGY:
+#      1. Create volume on filesystem
+#      2. Setting quota for parenet filesytem
+#      3. Verify volume refreservation is only limited by volsize
+#      4. Verify volume refreservation can be changed when volsize changed
+#
+
+verify_runnable "global"
+
+function cleanup
+{
+       log_must $ZFS destroy -rf $TESTPOOL/$TESTFS
+       log_must $ZFS create $TESTPOOL/$TESTFS
+       log_must $ZFS set mountpoint=$TESTDIR $TESTPOOL/$TESTFS
+}
+
+log_assert "Volume refreservation is limited by volsize"
+log_onexit cleanup
+
+fs=$TESTPOOL/$TESTFS; vol=$fs/vol
+log_must $ZFS create -V 10M $vol
+
+# Verify the parent filesystem does not affect volume
+log_must $ZFS set quota=25M $fs
+log_must $ZFS set refreservation=10M $vol
+avail=$(get_prop mountpoint $vol)
+log_mustnot $ZFS set refreservation=$avail $vol
+
+# Verify it is affected by volsize
+log_must $ZFS set volsize=15M $vol
+log_must $ZFS set refreservation=15M $vol
+log_mustnot $ZFS set refreservation=16M $vol
+
+log_pass "Volume refreservation is limited by volsize"
diff --git a/tests/zfs-tests/tests/functional/refreserv/setup.ksh b/tests/zfs-tests/tests/functional/refreserv/setup.ksh
new file mode 100755 (executable)
index 0000000..a34453b
--- /dev/null
@@ -0,0 +1,36 @@
+#!/bin/ksh -p
+#
+# CDDL HEADER START
+#
+# The contents of this file are subject to the terms of the
+# Common Development and Distribution License (the "License").
+# You may not use this file except in compliance with the License.
+#
+# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
+# or http://www.opensolaris.org/os/licensing.
+# See the License for the specific language governing permissions
+# and limitations under the License.
+#
+# When distributing Covered Code, include this CDDL HEADER in each
+# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
+# If applicable, add the following below this CDDL HEADER, with the
+# fields enclosed by brackets "[]" replaced with your own identifying
+# information: Portions Copyright [yyyy] [name of copyright owner]
+#
+# CDDL HEADER END
+#
+
+#
+# Copyright 2008 Sun Microsystems, Inc.  All rights reserved.
+# Use is subject to license terms.
+#
+
+#
+# Copyright (c) 2013 by Delphix. All rights reserved.
+#
+
+. $STF_SUITE/include/libtest.shlib
+
+verify_runnable "both"
+DISK=${DISKS%% *}
+default_setup $DISK
diff --git a/tests/zfs-tests/tests/functional/rename_dirs/Makefile.am b/tests/zfs-tests/tests/functional/rename_dirs/Makefile.am
new file mode 100644 (file)
index 0000000..029daf1
--- /dev/null
@@ -0,0 +1,5 @@
+pkgdatadir = $(datadir)/@PACKAGE@/zfs-tests/tests/functional/rename_dirs
+dist_pkgdata_SCRIPTS = \
+       setup.ksh \
+       cleanup.ksh \
+       rename_dirs_001_pos.ksh
diff --git a/tests/zfs-tests/tests/functional/rename_dirs/cleanup.ksh b/tests/zfs-tests/tests/functional/rename_dirs/cleanup.ksh
new file mode 100755 (executable)
index 0000000..3166bd6
--- /dev/null
@@ -0,0 +1,34 @@
+#!/bin/ksh -p
+#
+# CDDL HEADER START
+#
+# The contents of this file are subject to the terms of the
+# Common Development and Distribution License (the "License").
+# You may not use this file except in compliance with the License.
+#
+# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
+# or http://www.opensolaris.org/os/licensing.
+# See the License for the specific language governing permissions
+# and limitations under the License.
+#
+# When distributing Covered Code, include this CDDL HEADER in each
+# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
+# If applicable, add the following below this CDDL HEADER, with the
+# fields enclosed by brackets "[]" replaced with your own identifying
+# information: Portions Copyright [yyyy] [name of copyright owner]
+#
+# CDDL HEADER END
+#
+
+#
+# Copyright 2007 Sun Microsystems, Inc.  All rights reserved.
+# Use is subject to license terms.
+#
+
+#
+# Copyright (c) 2013 by Delphix. All rights reserved.
+#
+
+. $STF_SUITE/include/libtest.shlib
+
+default_cleanup
diff --git a/tests/zfs-tests/tests/functional/rename_dirs/rename_dirs_001_pos.ksh b/tests/zfs-tests/tests/functional/rename_dirs/rename_dirs_001_pos.ksh
new file mode 100755 (executable)
index 0000000..f84a2b6
--- /dev/null
@@ -0,0 +1,71 @@
+#!/bin/ksh -p
+#
+# CDDL HEADER START
+#
+# The contents of this file are subject to the terms of the
+# Common Development and Distribution License (the "License").
+# You may not use this file except in compliance with the License.
+#
+# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
+# or http://www.opensolaris.org/os/licensing.
+# See the License for the specific language governing permissions
+# and limitations under the License.
+#
+# When distributing Covered Code, include this CDDL HEADER in each
+# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
+# If applicable, add the following below this CDDL HEADER, with the
+# fields enclosed by brackets "[]" replaced with your own identifying
+# information: Portions Copyright [yyyy] [name of copyright owner]
+#
+# CDDL HEADER END
+#
+
+#
+# Copyright 2007 Sun Microsystems, Inc.  All rights reserved.
+# Use is subject to license terms.
+#
+
+#
+# Copyright (c) 2013 by Delphix. All rights reserved.
+#
+
+. $STF_SUITE/include/libtest.shlib
+
+#
+# DESCRIPTION:
+# Create two directory trees in ZFS filesystem, and concurently rename
+# directory across the two trees. ZFS should be able to handle the race
+# situation.
+#
+# STRATEGY:
+# 1. Create a ZFS filesystem
+# 2. Make two directory tree in the zfs file system
+# 3. Continually rename directory from one tree to another tree in two process
+# 4. After the specified time duration, the system should not be panic.
+#
+
+verify_runnable "both"
+
+function cleanup
+{
+       log_must $RM -rf $TESTDIR/*
+}
+
+log_assert "ZFS can handle race directory rename operation."
+
+log_onexit cleanup
+
+$CD $TESTDIR
+$MKDIR -p 1/2/3/4/5 a/b/c/d/e
+
+$RENAME_DIRS &
+
+$SLEEP 500
+typeset -i retval=1
+$PGREP $RENAME_DIRS >/dev/null 2>&1
+retval=$?
+if (( $retval == 0 )); then
+       $PKILL -9 $RENAME_DIRS >/dev/null 2>&1
+fi
+
+log_pass "ZFS handle race directory rename operation as expected."
diff --git a/tests/zfs-tests/tests/functional/rename_dirs/setup.ksh b/tests/zfs-tests/tests/functional/rename_dirs/setup.ksh
new file mode 100755 (executable)
index 0000000..fc5cec3
--- /dev/null
@@ -0,0 +1,35 @@
+#!/bin/ksh -p
+#
+# CDDL HEADER START
+#
+# The contents of this file are subject to the terms of the
+# Common Development and Distribution License (the "License").
+# You may not use this file except in compliance with the License.
+#
+# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
+# or http://www.opensolaris.org/os/licensing.
+# See the License for the specific language governing permissions
+# and limitations under the License.
+#
+# When distributing Covered Code, include this CDDL HEADER in each
+# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
+# If applicable, add the following below this CDDL HEADER, with the
+# fields enclosed by brackets "[]" replaced with your own identifying
+# information: Portions Copyright [yyyy] [name of copyright owner]
+#
+# CDDL HEADER END
+#
+
+#
+# Copyright 2007 Sun Microsystems, Inc.  All rights reserved.
+# Use is subject to license terms.
+#
+
+#
+# Copyright (c) 2013 by Delphix. All rights reserved.
+#
+
+. $STF_SUITE/include/libtest.shlib
+
+DISK=${DISKS%% *}
+default_setup $DISK
diff --git a/tests/zfs-tests/tests/functional/replacement/Makefile.am b/tests/zfs-tests/tests/functional/replacement/Makefile.am
new file mode 100644 (file)
index 0000000..ff3a7df
--- /dev/null
@@ -0,0 +1,8 @@
+pkgdatadir = $(datadir)/@PACKAGE@/zfs-tests/tests/functional/replacement
+dist_pkgdata_SCRIPTS = \
+       replacement.cfg \
+       setup.ksh \
+       cleanup.ksh \
+       replacement_001_pos.ksh \
+       replacement_002_pos.ksh \
+       replacement_003_pos.ksh
diff --git a/tests/zfs-tests/tests/functional/replacement/cleanup.ksh b/tests/zfs-tests/tests/functional/replacement/cleanup.ksh
new file mode 100755 (executable)
index 0000000..b81a372
--- /dev/null
@@ -0,0 +1,36 @@
+#!/bin/ksh -p
+#
+# CDDL HEADER START
+#
+# The contents of this file are subject to the terms of the
+# Common Development and Distribution License (the "License").
+# You may not use this file except in compliance with the License.
+#
+# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
+# or http://www.opensolaris.org/os/licensing.
+# See the License for the specific language governing permissions
+# and limitations under the License.
+#
+# When distributing Covered Code, include this CDDL HEADER in each
+# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
+# If applicable, add the following below this CDDL HEADER, with the
+# fields enclosed by brackets "[]" replaced with your own identifying
+# information: Portions Copyright [yyyy] [name of copyright owner]
+#
+# CDDL HEADER END
+#
+
+#
+# Copyright 2007 Sun Microsystems, Inc.  All rights reserved.
+# Use is subject to license terms.
+#
+
+#
+# Copyright (c) 2013 by Delphix. All rights reserved.
+#
+
+. $STF_SUITE/include/libtest.shlib
+
+verify_runnable "global"
+
+default_cleanup
diff --git a/tests/zfs-tests/tests/functional/replacement/replacement.cfg b/tests/zfs-tests/tests/functional/replacement/replacement.cfg
new file mode 100644 (file)
index 0000000..b2ba1b8
--- /dev/null
@@ -0,0 +1,38 @@
+#
+# CDDL HEADER START
+#
+# The contents of this file are subject to the terms of the
+# Common Development and Distribution License (the "License").
+# You may not use this file except in compliance with the License.
+#
+# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
+# or http://www.opensolaris.org/os/licensing.
+# See the License for the specific language governing permissions
+# and limitations under the License.
+#
+# When distributing Covered Code, include this CDDL HEADER in each
+# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
+# If applicable, add the following below this CDDL HEADER, with the
+# fields enclosed by brackets "[]" replaced with your own identifying
+# information: Portions Copyright [yyyy] [name of copyright owner]
+#
+# CDDL HEADER END
+#
+
+#
+# Copyright 2008 Sun Microsystems, Inc.  All rights reserved.
+# Use is subject to license terms.
+#
+
+#
+# Copyright (c) 2013 by Delphix. All rights reserved.
+#
+
+export TESTFILE=testfile
+export TESTFILE1=testfile1
+export HOLES_FILESIZE=${HOLES_FILESIZE-"67108864"} # 64 Mb
+export HOLES_BLKSIZE=${HOLES_BLKSIZE-"512"}
+export HOLES_SEED=${HOLES_SEED-""}
+export HOLES_FILEOFFSET=${HOLES_FILEOFFSET-""}
+export HOLES_COUNT=${HOLES_COUNT-"16384"}         # FILESIZE/BLKSIZE/8
+export REPLACEFILE="sparedisk"
diff --git a/tests/zfs-tests/tests/functional/replacement/replacement_001_pos.ksh b/tests/zfs-tests/tests/functional/replacement/replacement_001_pos.ksh
new file mode 100755 (executable)
index 0000000..1d66ff7
--- /dev/null
@@ -0,0 +1,160 @@
+#!/bin/ksh -p
+#
+# CDDL HEADER START
+#
+# The contents of this file are subject to the terms of the
+# Common Development and Distribution License (the "License").
+# You may not use this file except in compliance with the License.
+#
+# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
+# or http://www.opensolaris.org/os/licensing.
+# See the License for the specific language governing permissions
+# and limitations under the License.
+#
+# When distributing Covered Code, include this CDDL HEADER in each
+# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
+# If applicable, add the following below this CDDL HEADER, with the
+# fields enclosed by brackets "[]" replaced with your own identifying
+# information: Portions Copyright [yyyy] [name of copyright owner]
+#
+# CDDL HEADER END
+#
+
+#
+# Copyright 2008 Sun Microsystems, Inc.  All rights reserved.
+# Use is subject to license terms.
+#
+
+#
+# Copyright (c) 2013 by Delphix. All rights reserved.
+#
+
+. $STF_SUITE/include/libtest.shlib
+. $STF_SUITE/tests/functional/replacement/replacement.cfg
+
+#
+# DESCRIPTION:
+#      Replacing disks during I/O should pass for supported pools.
+#
+# STRATEGY:
+#      1. Create multidisk pools (stripe/mirror/raidz) and
+#         start some random I/O
+#      2. Replace a disk in the pool with anbother disk.
+#      3. Verify the integrity of the file system and the resilvering.
+#
+
+verify_runnable "global"
+
+function cleanup
+{
+       if [[ -n "$child_pids" ]]; then
+               for wait_pid in $child_pids
+               do
+                       $KILL $wait_pid
+               done
+       fi
+
+       if poolexists $TESTPOOL1; then
+               destroy_pool $TESTPOOL1
+       fi
+
+       [[ -e $TESTDIR ]] && log_must $RM -rf $TESTDIR/*
+}
+
+log_assert "Replacing a disk during I/O completes."
+
+options=""
+options_display="default options"
+
+log_onexit cleanup
+
+[[ -n "$HOLES_FILESIZE" ]] && options=" $options -f $HOLES_FILESIZE "
+
+[[ -n "$HOLES_BLKSIZE" ]] && options="$options -b $HOLES_BLKSIZE "
+
+[[ -n "$HOLES_COUNT" ]] && options="$options -c $HOLES_COUNT "
+
+[[ -n "$HOLES_SEED" ]] && options="$options -s $HOLES_SEED "
+
+[[ -n "$HOLES_FILEOFFSET" ]] && options="$options -o $HOLES_FILEOFFSET "
+
+options="$options -r "
+
+[[ -n "$options" ]] && options_display=$options
+
+child_pids=""
+
+function replace_test
+{
+       typeset -i iters=2
+       typeset -i index=0
+       typeset opt=$1
+       typeset disk1=$2
+       typeset disk2=$3
+
+       typeset i=0
+       while [[ $i -lt $iters ]]; do
+               log_note "Invoking $FILE_TRUNC with: $options_display"
+               $FILE_TRUNC $options $TESTDIR/$TESTFILE.$i &
+               typeset pid=$!
+
+               $SLEEP 1
+               if ! $PS -p $pid > /dev/null 2>&1; then
+                       log_fail "$FILE_TRUNC $options $TESTDIR/$TESTFILE.$i"
+               fi
+
+               child_pids="$child_pids $pid"
+               ((i = i + 1))
+       done
+
+       log_must $ZPOOL replace $opt $TESTPOOL1 $disk1 $disk2
+
+       $SLEEP 10
+
+       for wait_pid in $child_pids
+       do
+               $KILL $wait_pid
+       done
+       child_pids=""
+
+        log_must $ZPOOL export $TESTPOOL1
+        log_must $ZPOOL import -d $TESTDIR $TESTPOOL1
+        log_must $ZFS umount $TESTPOOL1/$TESTFS1
+        log_must $ZDB -cdui $TESTPOOL1/$TESTFS1
+        log_must $ZFS mount $TESTPOOL1/$TESTFS1
+
+}
+
+specials_list=""
+i=0
+while [[ $i != 2 ]]; do
+        $MKFILE 100m $TESTDIR/$TESTFILE1.$i
+        specials_list="$specials_list $TESTDIR/$TESTFILE1.$i"
+
+        ((i = i + 1))
+done
+
+#
+# Create a replacement disk special file.
+#
+$MKFILE 100m $TESTDIR/$REPLACEFILE
+
+for type in "" "raidz" "raidz1" "mirror"; do
+       for op in "" "-f"; do
+               create_pool $TESTPOOL1 $type $specials_list
+               log_must $ZFS create $TESTPOOL1/$TESTFS1
+               log_must $ZFS set mountpoint=$TESTDIR1 $TESTPOOL1/$TESTFS1
+
+               replace_test "$opt" $TESTDIR/$TESTFILE1.1 $TESTDIR/$REPLACEFILE
+
+               $ZPOOL iostat -v $TESTPOOL1 | grep "$TESTDIR/$REPLACEFILE"
+               if [[ $? -ne 0 ]]; then
+                       log_fail "$REPLACEFILE is not present."
+               fi
+
+               destroy_pool $TESTPOOL1
+               log_must $RM -rf /$TESTPOOL1
+       done
+done
+
+log_pass
diff --git a/tests/zfs-tests/tests/functional/replacement/replacement_002_pos.ksh b/tests/zfs-tests/tests/functional/replacement/replacement_002_pos.ksh
new file mode 100755 (executable)
index 0000000..3790396
--- /dev/null
@@ -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 2008 Sun Microsystems, Inc.  All rights reserved.
+# Use is subject to license terms.
+#
+
+#
+# Copyright (c) 2013 by Delphix. All rights reserved.
+#
+
+. $STF_SUITE/include/libtest.shlib
+. $STF_SUITE/tests/functional/replacement/replacement.cfg
+
+#
+# DESCRIPTION:
+#      Attaching disks during I/O should pass for supported pools.
+#
+# STRATEGY:
+#      1. Create multidisk pools (stripe/mirror/raidz) and
+#         start some random I/O
+#      2. Attach a disk to the pool.
+#      3. Verify the integrity of the file system and the resilvering.
+#
+
+verify_runnable "global"
+
+function cleanup
+{
+       if [[ -n "$child_pids" ]]; then
+               for wait_pid in $child_pids
+               do
+                       $KILL $wait_pid
+               done
+       fi
+
+       if poolexists $TESTPOOL1; then
+               destroy_pool $TESTPOOL1
+       fi
+
+       [[ -e $TESTDIR ]] && log_must $RM -rf $TESTDIR/*
+}
+
+log_assert "Replacing a disk during I/O completes."
+
+options=""
+options_display="default options"
+
+log_onexit cleanup
+
+[[ -n "$HOLES_FILESIZE" ]] && options=" $options -f $HOLES_FILESIZE "
+
+[[ -n "$HOLES_BLKSIZE" ]] && options="$options -b $HOLES_BLKSIZE "
+
+[[ -n "$HOLES_COUNT" ]] && options="$options -c $HOLES_COUNT "
+
+[[ -n "$HOLES_SEED" ]] && options="$options -s $HOLES_SEED "
+
+[[ -n "$HOLES_FILEOFFSET" ]] && options="$options -o $HOLES_FILEOFFSET "
+
+options="$options -r "
+
+[[ -n "$options" ]] && options_display=$options
+
+child_pids=""
+
+function attach_test
+{
+       typeset -i iters=2
+       typeset -i index=0
+       typeset opt=$1
+       typeset disk1=$2
+       typeset disk2=$3
+
+       typeset i=0
+       while [[ $i -lt $iters ]]; do
+               log_note "Invoking $FILE_TRUNC with: $options_display"
+               $FILE_TRUNC $options $TESTDIR/$TESTFILE.$i &
+               typeset pid=$!
+
+               $SLEEP 1
+               if ! $PS -p $pid > /dev/null 2>&1; then
+                       log_fail "$FILE_TRUNC $options $TESTDIR/$TESTFILE.$i"
+               fi
+
+               child_pids="$child_pids $pid"
+               ((i = i + 1))
+       done
+
+       log_must $ZPOOL attach $opt $TESTPOOL1 $disk1 $disk2
+
+       $SLEEP 10
+
+       for wait_pid in $child_pids
+       do
+               $KILL $wait_pid
+       done
+       child_pids=""
+
+        log_must $ZPOOL export $TESTPOOL1
+        log_must $ZPOOL import -d $TESTDIR $TESTPOOL1
+        log_must $ZFS umount $TESTPOOL1/$TESTFS1
+        log_must $ZDB -cdui $TESTPOOL1/$TESTFS1
+        log_must $ZFS mount $TESTPOOL1/$TESTFS1
+
+}
+
+specials_list=""
+i=0
+while [[ $i != 2 ]]; do
+       $MKFILE 100m $TESTDIR/$TESTFILE1.$i
+       specials_list="$specials_list $TESTDIR/$TESTFILE1.$i"
+
+       ((i = i + 1))
+done
+
+#
+# Create a replacement disk special file.
+#
+$MKFILE 100m $TESTDIR/$REPLACEFILE
+
+for op in "" "-f"; do
+       create_pool $TESTPOOL1 mirror $specials_list
+       log_must $ZFS create $TESTPOOL1/$TESTFS1
+       log_must $ZFS set mountpoint=$TESTDIR1 $TESTPOOL1/$TESTFS1
+
+       attach_test "$opt" $TESTDIR/$TESTFILE1.1 $TESTDIR/$REPLACEFILE
+
+       $ZPOOL iostat -v $TESTPOOL1 | grep "$TESTDIR/$REPLACEFILE"
+       if [[ $? -ne 0 ]]; then
+               log_fail "$REPLACEFILE is not present."
+       fi
+
+       destroy_pool $TESTPOOL1
+done
+
+log_note "Verify 'zpool attach' fails with non-mirrors."
+
+for type in "" "raidz" "raidz1"; do
+       for op in "" "-f"; do
+               create_pool $TESTPOOL1 $type $specials_list
+               log_must $ZFS create $TESTPOOL1/$TESTFS1
+               log_must $ZFS set mountpoint=$TESTDIR1 $TESTPOOL1/$TESTFS1
+
+               log_mustnot $ZPOOL attach "$opt" $TESTDIR/$TESTFILE1.1 \
+                   $TESTDIR/$REPLACEFILE
+
+               $ZPOOL iostat -v $TESTPOOL1 | grep "$TESTDIR/$REPLACEFILE"
+               if [[ $? -eq 0 ]]; then
+                       log_fail "$REPLACEFILE should not be present."
+               fi
+
+               destroy_pool $TESTPOOL1
+       done
+done
+
+log_pass
diff --git a/tests/zfs-tests/tests/functional/replacement/replacement_003_pos.ksh b/tests/zfs-tests/tests/functional/replacement/replacement_003_pos.ksh
new file mode 100755 (executable)
index 0000000..3553264
--- /dev/null
@@ -0,0 +1,164 @@
+#!/bin/ksh -p
+#
+# CDDL HEADER START
+#
+# The contents of this file are subject to the terms of the
+# Common Development and Distribution License (the "License").
+# You may not use this file except in compliance with the License.
+#
+# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
+# or http://www.opensolaris.org/os/licensing.
+# See the License for the specific language governing permissions
+# and limitations under the License.
+#
+# When distributing Covered Code, include this CDDL HEADER in each
+# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
+# If applicable, add the following below this CDDL HEADER, with the
+# fields enclosed by brackets "[]" replaced with your own identifying
+# information: Portions Copyright [yyyy] [name of copyright owner]
+#
+# CDDL HEADER END
+#
+
+#
+# Copyright 2008 Sun Microsystems, Inc.  All rights reserved.
+# Use is subject to license terms.
+#
+
+#
+# Copyright (c) 2013 by Delphix. All rights reserved.
+#
+
+. $STF_SUITE/include/libtest.shlib
+. $STF_SUITE/tests/functional/replacement/replacement.cfg
+
+#
+# DESCRIPTION:
+#      Detaching disks during I/O should pass for supported pools.
+#
+# STRATEGY:
+#      1. Create multidisk pools (stripe/mirror/raidz) and
+#         start some random I/O
+#      2. Detach a disk from the pool.
+#      3. Verify the integrity of the file system and the resilvering.
+#
+
+verify_runnable "global"
+
+function cleanup
+{
+       if [[ -n "$child_pids" ]]; then
+               for wait_pid in $child_pids
+               do
+                       $KILL $wait_pid
+               done
+       fi
+
+       if poolexists $TESTPOOL1; then
+               destroy_pool $TESTPOOL1
+       fi
+
+       [[ -e $TESTDIR ]] && log_must $RM -rf $TESTDIR/*
+}
+
+log_assert "Replacing a disk during I/O completes."
+
+options=""
+options_display="default options"
+
+log_onexit cleanup
+
+[[ -n "$HOLES_FILESIZE" ]] && options=" $options -f $HOLES_FILESIZE "
+
+[[ -n "$HOLES_BLKSIZE" ]] && options="$options -b $HOLES_BLKSIZE "
+
+[[ -n "$HOLES_COUNT" ]] && options="$options -c $HOLES_COUNT "
+
+[[ -n "$HOLES_SEED" ]] && options="$options -s $HOLES_SEED "
+
+[[ -n "$HOLES_FILEOFFSET" ]] && options="$options -o $HOLES_FILEOFFSET "
+
+ptions="$options -r "
+
+[[ -n "$options" ]] && options_display=$options
+
+child_pids=""
+
+function detach_test
+{
+       typeset -i iters=2
+       typeset -i index=0
+       typeset disk1=$1
+
+       typeset i=0
+       while [[ $i -lt $iters ]]; do
+               log_note "Invoking $FILE_TRUNC with: $options_display"
+               $FILE_TRUNC $options $TESTDIR/$TESTFILE.$i &
+               typeset pid=$!
+
+               $SLEEP 1
+               if ! $PS -p $pid > /dev/null 2>&1; then
+                       log_fail "$FILE_TRUNC $options $TESTDIR/$TESTFILE.$i"
+               fi
+
+               child_pids="$child_pids $pid"
+               ((i = i + 1))
+       done
+
+       log_must $ZPOOL detach $TESTPOOL1 $disk1
+
+       $SLEEP 10
+
+       for wait_pid in $child_pids
+       do
+               $KILL $wait_pid
+       done
+       child_pids=""
+
+        log_must $ZPOOL export $TESTPOOL1
+        log_must $ZPOOL import -d $TESTDIR $TESTPOOL1
+        log_must $ZFS umount $TESTPOOL1/$TESTFS1
+        log_must $ZDB -cdui $TESTPOOL1/$TESTFS1
+        log_must $ZFS mount $TESTPOOL1/$TESTFS1
+}
+
+specials_list=""
+i=0
+while [[ $i != 2 ]]; do
+       $MKFILE 100m $TESTDIR/$TESTFILE1.$i
+       specials_list="$specials_list $TESTDIR/$TESTFILE1.$i"
+
+       ((i = i + 1))
+done
+
+create_pool $TESTPOOL1 mirror $specials_list
+log_must $ZFS create $TESTPOOL1/$TESTFS1
+log_must $ZFS set mountpoint=$TESTDIR1 $TESTPOOL1/$TESTFS1
+
+detach_test $TESTDIR/$TESTFILE1.1
+
+$ZPOOL iostat -v $TESTPOOL1 | grep "$TESTDIR/$TESTFILE1.1"
+if [[ $? -eq 0 ]]; then
+       log_fail "$TESTFILE1.1 should no longer be present."
+fi
+
+destroy_pool $TESTPOOL1
+
+log_note "Verify 'zpool detach' fails with non-mirrors."
+
+for type in "" "raidz" "raidz1" ; do
+       create_pool $TESTPOOL1 $type $specials_list
+       log_must $ZFS create $TESTPOOL1/$TESTFS1
+       log_must $ZFS set mountpoint=$TESTDIR1 $TESTPOOL1/$TESTFS1
+
+       log_mustnot $ZPOOL detach $TESTDIR/$TESTFILE1.1
+
+       $ZPOOL iostat -v $TESTPOOL1 | grep "$TESTDIR/$TESTFILE1.1"
+       if [[ $? -ne 0 ]]; then
+               log_fail "$TESTFILE1.1 is not present."
+       fi
+
+       destroy_pool $TESTPOOL1
+done
+
+log_pass
diff --git a/tests/zfs-tests/tests/functional/replacement/setup.ksh b/tests/zfs-tests/tests/functional/replacement/setup.ksh
new file mode 100755 (executable)
index 0000000..4132392
--- /dev/null
@@ -0,0 +1,47 @@
+#!/bin/ksh -p
+#
+# CDDL HEADER START
+#
+# The contents of this file are subject to the terms of the
+# Common Development and Distribution License (the "License").
+# You may not use this file except in compliance with the License.
+#
+# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
+# or http://www.opensolaris.org/os/licensing.
+# See the License for the specific language governing permissions
+# and limitations under the License.
+#
+# When distributing Covered Code, include this CDDL HEADER in each
+# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
+# If applicable, add the following below this CDDL HEADER, with the
+# fields enclosed by brackets "[]" replaced with your own identifying
+# information: Portions Copyright [yyyy] [name of copyright owner]
+#
+# CDDL HEADER END
+#
+
+#
+# Copyright 2009 Sun Microsystems, Inc.  All rights reserved.
+# Use is subject to license terms.
+#
+
+#
+# Copyright (c) 2013 by Delphix. All rights reserved.
+#
+
+. $STF_SUITE/include/libtest.shlib
+
+verify_runnable "global"
+verify_disk_count "$DISKS" 2
+
+index=`expr $RANDOM % 2`
+case $index in
+0)     log_note "Pool Type: Mirror"
+       default_mirror_setup $DISKS
+       ;;
+1)     log_note "Pool Type: RAID-Z"
+       default_raidz_setup $DISKS
+       ;;
+esac
+
+log_pass
diff --git a/tests/zfs-tests/tests/functional/reservation/Makefile.am b/tests/zfs-tests/tests/functional/reservation/Makefile.am
new file mode 100644 (file)
index 0000000..c346ca3
--- /dev/null
@@ -0,0 +1,24 @@
+pkgdatadir = $(datadir)/@PACKAGE@/zfs-tests/tests/functional/reservation
+dist_pkgdata_SCRIPTS = \
+       reservation.cfg \
+       reservation.shlib \
+       setup.ksh \
+       cleanup.ksh \
+       reservation_001_pos.sh \
+       reservation_002_pos.sh \
+       reservation_003_pos.sh \
+       reservation_004_pos.sh \
+       reservation_005_pos.sh \
+       reservation_006_pos.sh \
+       reservation_007_pos.sh \
+       reservation_008_pos.sh \
+       reservation_009_pos.sh \
+       reservation_010_pos.sh \
+       reservation_011_pos.sh \
+       reservation_012_pos.sh \
+       reservation_013_pos.sh \
+       reservation_014_pos.sh \
+       reservation_015_pos.sh \
+       reservation_016_pos.sh \
+       reservation_017_pos.sh \
+       reservation_018_pos.sh
diff --git a/tests/zfs-tests/tests/functional/reservation/cleanup.ksh b/tests/zfs-tests/tests/functional/reservation/cleanup.ksh
new file mode 100755 (executable)
index 0000000..3166bd6
--- /dev/null
@@ -0,0 +1,34 @@
+#!/bin/ksh -p
+#
+# CDDL HEADER START
+#
+# The contents of this file are subject to the terms of the
+# Common Development and Distribution License (the "License").
+# You may not use this file except in compliance with the License.
+#
+# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
+# or http://www.opensolaris.org/os/licensing.
+# See the License for the specific language governing permissions
+# and limitations under the License.
+#
+# When distributing Covered Code, include this CDDL HEADER in each
+# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
+# If applicable, add the following below this CDDL HEADER, with the
+# fields enclosed by brackets "[]" replaced with your own identifying
+# information: Portions Copyright [yyyy] [name of copyright owner]
+#
+# CDDL HEADER END
+#
+
+#
+# Copyright 2007 Sun Microsystems, Inc.  All rights reserved.
+# Use is subject to license terms.
+#
+
+#
+# Copyright (c) 2013 by Delphix. All rights reserved.
+#
+
+. $STF_SUITE/include/libtest.shlib
+
+default_cleanup
diff --git a/tests/zfs-tests/tests/functional/reservation/reservation.cfg b/tests/zfs-tests/tests/functional/reservation/reservation.cfg
new file mode 100644 (file)
index 0000000..c12ad07
--- /dev/null
@@ -0,0 +1,44 @@
+#
+# CDDL HEADER START
+#
+# The contents of this file are subject to the terms of the
+# Common Development and Distribution License (the "License").
+# You may not use this file except in compliance with the License.
+#
+# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
+# or http://www.opensolaris.org/os/licensing.
+# See the License for the specific language governing permissions
+# and limitations under the License.
+#
+# When distributing Covered Code, include this CDDL HEADER in each
+# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
+# If applicable, add the following below this CDDL HEADER, with the
+# fields enclosed by brackets "[]" replaced with your own identifying
+# information: Portions Copyright [yyyy] [name of copyright owner]
+#
+# CDDL HEADER END
+#
+
+#
+# Copyright 2008 Sun Microsystems, Inc.  All rights reserved.
+# Use is subject to license terms.
+#
+
+#
+# Copyright (c) 2013 by Delphix. All rights reserved.
+#
+
+export RESV_DELTA=5242880
+export RESV_TOLERANCE=5242880  # Acceptable limit (5MB) for diff in space stats
+export RESV_SIZE=52428800      # Default reservation size (50MB)
+export RESV_FREE_SPACE=52428800        # Amount of space (50MB) to leave free in a pool
+export RESV_NUM_FS=10          # Number of filesystems to create
+export RESV_ITER=10            # Number of iterations
+
+export BLOCK_SIZE=1048576
+export ENOSPC=28
+
+export TESTVOL=testvol$$
+export TESTVOL2=testvol2-$$
+export TESTFILE1=file1.$$
+export TESTFILE2=file2.$$
diff --git a/tests/zfs-tests/tests/functional/reservation/reservation.shlib b/tests/zfs-tests/tests/functional/reservation/reservation.shlib
new file mode 100644 (file)
index 0000000..e58e198
--- /dev/null
@@ -0,0 +1,201 @@
+#
+# CDDL HEADER START
+#
+# The contents of this file are subject to the terms of the
+# Common Development and Distribution License (the "License").
+# You may not use this file except in compliance with the License.
+#
+# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
+# or http://www.opensolaris.org/os/licensing.
+# See the License for the specific language governing permissions
+# and limitations under the License.
+#
+# When distributing Covered Code, include this CDDL HEADER in each
+# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
+# If applicable, add the following below this CDDL HEADER, with the
+# fields enclosed by brackets "[]" replaced with your own identifying
+# information: Portions Copyright [yyyy] [name of copyright owner]
+#
+# CDDL HEADER END
+#
+
+#
+# Copyright 2009 Sun Microsystems, Inc.  All rights reserved.
+# Use is subject to license terms.
+#
+
+#
+# Copyright (c) 2013 by Delphix. All rights reserved.
+#
+
+. $STF_SUITE/tests/functional/reservation/reservation.cfg
+
+#
+# Function to set the reservation property of a dataset to
+# 'none' and verify that it is correctly set using both the
+# "normal" 'zfs get reservation' and the '-p' option which
+# gives a numerical value.
+#
+function zero_reservation
+{
+       typeset resv_val
+       dataset=$1
+
+       log_must $ZFS set reservation=none $dataset
+
+       resv_val=`$ZFS get -H reservation $dataset | awk '{print $3}'`
+       if [[ $? -ne 0 ]]; then
+               log_fail "Unable to get reservation prop on $dataset"
+       elif [[ $resv_val != "none" ]]; then
+               log_fail "Reservation not 'none' ($resv_val) as expected"
+       fi
+
+
+       resv_val=`$ZFS get -pH reservation $dataset | awk '{print $3}'`
+       if [[ $? -ne 0 ]]; then
+               log_fail "Unable to get reservation prop on $dataset"
+       elif [[ $resv_val -ne 0 ]]; then
+               log_fail "Reservation not 0 ($resv_val) as expected"
+       fi
+
+       return 0
+}
+
+#
+# Utility function to see if two values are within a certain specified
+# limit of each other. Used primarily to check that a dataset's parent
+# is correctly accounting for space used/available. Need this function as
+# currently there is some slop in the way space is accounted (i.e. can't
+# do a direct comparison).
+#
+function within_limits
+{
+       typeset -l valA=$1
+       typeset -l valB=$2
+       typeset -l delta=$3
+
+       if ((valA <= valB)); then
+               if (((valB - valA) <= delta)); then
+                       return 0
+               fi
+       elif ((valB <= valA)); then
+               if (((valA - valB) <= delta)); then
+                       return 0
+               fi
+       fi
+
+       return 1
+}
+
+#
+# Function to create and mount multiple filesystems. The filesystem
+# will be named according to the name specified with a suffix value
+# taken from the loop counter.
+#
+function create_multiple_fs # num_fs base_fs_name base_mnt_name
+{
+       typeset -i iter=0
+       typeset -i count=$1
+       typeset FS_NAME=$2
+       typeset MNT_NAME=$3
+
+       while  (($iter < $count)); do
+               log_must $ZFS create ${FS_NAME}$iter
+               log_must $ZFS set mountpoint=${MNT_NAME}$iter ${FS_NAME}$iter
+               ((iter = iter + 1))
+       done
+}
+
+#
+# This function compute the largest volume size which is multiple of volume
+# block size (default 8K) and not greater than the largest expected volsize.
+#
+# $1 The largest expected volume size.
+# $2 The volume block size
+#
+function floor_volsize #<largest_volsize> [volblksize]
+{
+       typeset -l largest_volsize=$1
+       typeset -l volblksize=${2:-8192}
+
+       if ((largest_volsize < volblksize)); then
+               log_fail "The largest_volsize must be greater than volblksize."
+       fi
+       typeset -l real_volsize
+       typeset -l n
+
+       ((n = largest_volsize / volblksize))
+       ((largest_volsize = volblksize * n))
+
+       print $largest_volsize
+}
+
+#
+# This function is a copy of a function by the same name in libzfs_dataset.c
+# Its purpose is to reserve additional space for volume metadata so volumes
+# don't unexpectedly run out of room.
+#
+# Note: This function can be used to do an estimate for a volume that has not
+# yet been created. In this case, $vol is not a volume, but rather a pool in
+# which a volume is going to be created. In this case, use default properties.
+#
+function volsize_to_reservation
+{
+       typeset vol=$1
+       typeset -i volsize=$2
+
+       typeset -i DN_MAX_INDBLKSHIFT=14
+       typeset -i SPA_BLKPTRSHIFT=7
+       typeset -i SPA_DVAS_PER_BP=3
+
+       typeset -i DNODES_PER_LEVEL_SHIFT=$((DN_MAX_INDBLKSHIFT - \
+           SPA_BLKPTRSHIFT))
+       typeset -i DNODES_PER_LEVEL=$((1 << $DNODES_PER_LEVEL_SHIFT))
+
+       if ds_is_volume $vol; then
+               typeset -i ncopies=$(get_prop copies $vol)
+               typeset -i volblocksize=$(get_prop volblocksize $vol)
+       else
+               typeset -i ncopies=1
+               typeset -i volblocksize=8192
+       fi
+       typeset -i nblocks=$((volsize / volblocksize))
+
+       typeset -i numdb=7
+       while ((nblocks > 1)); do
+               ((nblocks += DNODES_PER_LEVEL - 1))
+               ((nblocks /= DNODES_PER_LEVEL))
+               ((numdb += nblocks))
+       done
+
+       ((numdb *= SPA_DVAS_PER_BP < ncopies + 1 ? SPA_DVAS_PER_BP : \
+           ncopies + 1))
+       ((volsize *= ncopies))
+       ((numdb *= 1 << DN_MAX_INDBLKSHIFT))
+       ((volsize += numdb))
+       echo $volsize
+}
+
+#
+# This function takes a pool name as an argument, and returns the largest (give
+# or take some slop) -V value that can be used to create a volume in that pool.
+# This is necessary because during volume creation, a reservation is created
+# that will be larger than the value specified with -V, and potentially larger
+# than the available space in the pool. See volsize_to_reservation().
+#
+function largest_volsize_from_pool
+{
+       typeset pool=$1
+       typeset -i poolsize=$(get_prop available $pool)
+       typeset -i volsize=$poolsize
+       typeset -i nvolsize
+
+       while :; do
+               # knock 50M off the volsize each time through
+               ((volsize -= 50 * 1024 * 1024))
+               nvolsize=$(volsize_to_reservation $pool $volsize)
+               nvolsize=$(floor_volsize $nvolsize)
+               ((nvolsize < poolsize)) && break
+       done
+       echo $volsize
+}
diff --git a/tests/zfs-tests/tests/functional/reservation/reservation_001_pos.sh b/tests/zfs-tests/tests/functional/reservation/reservation_001_pos.sh
new file mode 100755 (executable)
index 0000000..cef3187
--- /dev/null
@@ -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 2008 Sun Microsystems, Inc.  All rights reserved.
+# Use is subject to license terms.
+#
+
+#
+# Copyright (c) 2013 by Delphix. All rights reserved.
+#
+
+. $STF_SUITE/include/libtest.shlib
+. $STF_SUITE/tests/functional/reservation/reservation.shlib
+
+#
+# DESCRIPTION:
+#
+# ZFS allows reservations to be set on filesystems and volumes, provided
+# the reservation is less than the space available in the pool.
+#
+# STRATEGY:
+# 1) Create a regular and sparse volume
+#   (filesystem already created by default_setup)
+# 2) Get the space available in the pool
+# 3) Set a reservation on the filesystem less than the space available.
+# 4) Verify that the 'reservation' property for the filesystem has
+#    the correct value.
+# 5) Reset the reservation to 'none'
+# 6) Repeat steps 2-5 for both volume types
+#
+
+verify_runnable "both"
+
+function cleanup
+{
+       for obj in $OBJ_LIST; do
+               datasetexists $obj && log_must $ZFS destroy -f $obj
+       done
+}
+
+log_onexit cleanup
+
+log_assert "Verify that to set a reservation on a filesystem or volume must " \
+    "use value smaller than space available property of pool"
+
+space_avail=`get_prop available $TESTPOOL`
+
+if ! is_global_zone ; then
+       OBJ_LIST=""
+else
+       OBJ_LIST="$TESTPOOL/$TESTVOL $TESTPOOL/$TESTVOL2"
+
+       ((vol_set_size = space_avail / 4))
+       vol_set_size=$(floor_volsize $vol_set_size)
+       ((sparse_vol_set_size = space_avail * 4))
+       sparse_vol_set_size=$(floor_volsize $sparse_vol_set_size)
+
+       #
+       # Note that when creating a regular volume we are implicitly
+       # setting a reservation upon it (i.e. the size of the volume)
+       # which we reset back to zero initially.
+       #
+       log_must $ZFS create -V $vol_set_size $TESTPOOL/$TESTVOL
+       log_must $ZFS set reservation=none $TESTPOOL/$TESTVOL
+       log_must $ZFS set refreservation=none $TESTPOOL/$TESTVOL
+       log_must $ZFS create -s -V $sparse_vol_set_size $TESTPOOL/$TESTVOL2
+fi
+
+
+for obj in $TESTPOOL/$TESTFS $OBJ_LIST; do
+
+       space_avail=`get_prop available $TESTPOOL`
+       resv_size_set=`expr $space_avail - $RESV_DELTA`
+
+       #
+       # For a regular (non-sparse) volume the upper limit
+       # for reservations is not determined by the space
+       # available in the pool but rather by the size of
+       # the volume itself.
+       #
+       [[ $obj == $TESTPOOL/$TESTVOL ]] && \
+           ((resv_size_set = vol_set_size - RESV_DELTA))
+
+       log_must $ZFS set reservation=$resv_size_set $obj
+
+       resv_size_get=`get_prop reservation $obj`
+       if [[ $resv_size_set != $resv_size_get ]]; then
+               log_fail "Reservation not the expected value " \
+                   "($resv_size_set != $resv_size_get)"
+       fi
+
+       log_must zero_reservation $obj
+
+       new_space_avail=`get_prop available $obj`
+
+       #
+       # Due to the way space is consumed and released by metadata we
+       # can't do an exact check here, but we do do a basic sanity
+       # check.
+       #
+       log_must within_limits $space_avail $new_space_avail $RESV_TOLERANCE
+done
+
+log_pass "Successfully set reservation on filesystem and volume"
diff --git a/tests/zfs-tests/tests/functional/reservation/reservation_002_pos.sh b/tests/zfs-tests/tests/functional/reservation/reservation_002_pos.sh
new file mode 100755 (executable)
index 0000000..fdf4ce3
--- /dev/null
@@ -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.
+#
+
+#
+# Copyright (c) 2013 by Delphix. All rights reserved.
+#
+
+. $STF_SUITE/include/libtest.shlib
+. $STF_SUITE/tests/functional/reservation/reservation.shlib
+
+#
+# DESCRIPTION:
+#
+# Reservation values cannot exceed the amount of space available
+# in the pool. Verify that attempting to set a reservation greater
+# than this value fails.
+#
+# STRATEGY:
+# 1) Create a filesystem, regular and sparse volume
+# 2) Get the space available in the pool
+# 3) Attempt to set a reservation greater than the available space
+# on the filesystem and verify it fails.
+# 4) Verify that the reservation is still set to 'none' (or 0) on
+# the filesystem.
+# 5) Repeat 3-4 for regular and sparse volume
+#
+
+verify_runnable "both"
+
+function cleanup
+{
+       for obj in $OBJ_LIST; do
+               datasetexists $obj && log_must $ZFS destroy -f $obj
+       done
+
+       log_must zero_reservation $TESTPOOL/$TESTFS
+}
+
+log_onexit cleanup
+
+log_assert "Reservation values cannot exceed the amount of space" \
+       " available in the pool"
+
+space_avail=`get_prop available $TESTPOOL`
+
+if ! is_global_zone ; then
+       OBJ_LIST=""
+else
+       OBJ_LIST="$TESTPOOL/$TESTVOL $TESTPOOL/$TESTVOL2"
+
+       ((vol_set_size = space_avail / 4))
+       vol_set_size=$(floor_volsize $vol_set_size)
+       ((sparse_vol_set_size = space_avail * 4))
+       sparse_vol_set_size=$(floor_volsize $sparse_vol_set_size)
+
+       log_must $ZFS create -V $vol_set_size $TESTPOOL/$TESTVOL
+       log_must $ZFS set reservation=none $TESTPOOL/$TESTVOL
+       log_must $ZFS create -s -V $sparse_vol_set_size $TESTPOOL/$TESTVOL2
+fi
+
+for obj in $TESTPOOL/$TESTFS $OBJ_LIST ; do
+
+       space_avail=`get_prop available $TESTPOOL`
+       resv_size_set=`expr $space_avail + $RESV_DELTA`
+
+       #
+       # For regular (non-sparse) volumes the upper limit is determined
+       # not by the space available in the pool but rather by the size
+       # of the volume itself.
+       #
+       [[ $obj == $TESTPOOL/$TESTVOL ]] && \
+           ((resv_size_set = vol_set_size + RESV_DELTA))
+
+       log_must zero_reservation $obj
+       log_mustnot $ZFS set reservation=$resv_size_set $obj
+
+       resv_size_get=`get_prop reservation $obj`
+
+       if (($resv_size_get != 0)); then
+               log_fail "Reservation value non-zero ($resv_size_get)"
+       fi
+done
+
+log_pass "Attempting to set too large reservation failed as expected"
diff --git a/tests/zfs-tests/tests/functional/reservation/reservation_003_pos.sh b/tests/zfs-tests/tests/functional/reservation/reservation_003_pos.sh
new file mode 100755 (executable)
index 0000000..81096e8
--- /dev/null
@@ -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 2009 Sun Microsystems, Inc.  All rights reserved.
+# Use is subject to license terms.
+#
+
+#
+# Copyright (c) 2013 by Delphix. All rights reserved.
+#
+
+. $STF_SUITE/include/libtest.shlib
+. $STF_SUITE/tests/functional/reservation/reservation.shlib
+
+#
+# DESCRIPTION:
+#
+# Verify that it's possible to set a reservation on a filesystem,
+# or volume multiple times, without resetting the reservation
+# to none.
+#
+# STRATEGY:
+# 1) Create a regular volume and a sparse volume
+# 2) Get the space available in the pool
+# 3) Set a reservation on the filesystem less than the space available.
+# 4) Verify that the 'reservation' property for the filesystem has
+# the correct value.
+# 5) Repeat 2-4 for different reservation values
+# 6) Repeat 3-5 for regular and sparse volume
+#
+
+verify_runnable "both"
+
+log_assert "Verify it is possible to set reservations multiple times " \
+       "on a filesystem regular and sparse volume"
+
+function cleanup
+{
+       log_must zero_reservation $TESTPOOL/$TESTFS
+
+       for obj in $OBJ_LIST; do
+       datasetexists $obj && log_must $ZFS destroy -f $obj
+       done
+}
+
+log_onexit cleanup
+
+
+#
+# Set a reservation $RESV_ITER times on a dataset and verify that
+# the reservation is correctly set each time.
+#
+function multiple_resv { #dataset
+       typeset -i i=0
+
+       dataset=$1
+
+       log_must zero_reservation $dataset
+       space_avail=`get_prop available $TESTPOOL`
+
+       ((resv_size = (space_avail - RESV_DELTA) / RESV_ITER))
+
+       #
+       # For regular (non-sparse) volumes the upper limit is determined
+       # not by the space available in the pool but rather by the size
+       # of the volume itself.
+       #
+       [[ $obj == $TESTPOOL/$TESTVOL ]] && \
+           ((resv_size = (vol_set_size - RESV_DELTA) / RESV_ITER))
+
+       resv_size_set=$resv_size
+
+       while (($i < $RESV_ITER)); do
+
+               ((i = i + 1))
+
+               ((resv_size_set = resv_size * i))
+
+               log_must $ZFS set reservation=$resv_size_set $dataset
+
+               resv_size_get=`get_prop reservation $dataset`
+               if [[ $resv_size_set != $resv_size_get ]]; then
+                       log_fail "Reservation not the expected value " \
+                           "($resv_size_set != $resv_size_get)"
+               fi
+       done
+
+       log_must zero_reservation $dataset
+}
+
+space_avail=`get_prop available $TESTPOOL`
+
+if ! is_global_zone ; then
+       OBJ_LIST=""
+else
+       OBJ_LIST="$TESTPOOL/$TESTVOL $TESTPOOL/$TESTVOL2"
+
+       ((vol_set_size = space_avail / 4))
+       vol_set_size=$(floor_volsize $vol_set_size)
+       ((sparse_vol_set_size = space_avail * 4))
+       sparse_vol_set_size=$(floor_volsize $sparse_vol_set_size)
+
+
+       log_must $ZFS create -V $vol_set_size $TESTPOOL/$TESTVOL
+       log_must $ZFS set reservation=none $TESTPOOL/$TESTVOL
+       log_must $ZFS create -s -V $sparse_vol_set_size $TESTPOOL/$TESTVOL2
+fi
+
+for obj in $TESTPOOL/$TESTFS $OBJ_LIST ; do
+       multiple_resv $obj
+done
+
+log_pass "Multiple reservations successfully set on filesystem" \
+    " and both volume types"
diff --git a/tests/zfs-tests/tests/functional/reservation/reservation_004_pos.sh b/tests/zfs-tests/tests/functional/reservation/reservation_004_pos.sh
new file mode 100755 (executable)
index 0000000..3734002
--- /dev/null
@@ -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 2008 Sun Microsystems, Inc.  All rights reserved.
+# Use is subject to license terms.
+#
+
+#
+# Copyright (c) 2013 by Delphix. All rights reserved.
+#
+
+. $STF_SUITE/include/libtest.shlib
+. $STF_SUITE/tests/functional/reservation/reservation.shlib
+
+#
+# DESCRIPTION:
+#
+# When a dataset which has a reservation set on it is destroyed,
+# the space consumed or reserved by that dataset should be released
+# back into the pool.
+#
+# STRATEGY:
+# 1) Create a filesystem, regular and sparse volume
+# 2) Get the space used and available in the pool
+# 3) Set a reservation on the filesystem less than the space available.
+# 4) Verify that the 'reservation' property for the filesystem has
+# the correct value.
+# 5) Destroy the filesystem without resetting the reservation value.
+# 6) Verify that the space used and available totals for the pool have
+# changed by the expected amounts (within tolerances).
+# 7) Repeat steps 3-6 for a regular volume and sparse volume
+#
+
+verify_runnable "both"
+
+function cleanup {
+
+       for obj in $OBJ_LIST; do
+               datasetexists $obj && log_must $ZFS destroy -f $obj
+       done
+}
+
+log_assert "Verify space released when a dataset with reservation is destroyed"
+
+log_onexit cleanup
+
+log_must $ZFS create $TESTPOOL/$TESTFS2
+
+space_avail=`get_prop available $TESTPOOL`
+
+if ! is_global_zone ; then
+       OBJ_LIST="$TESTPOOL/$TESTFS2"
+else
+       OBJ_LIST="$TESTPOOL/$TESTFS2 \
+               $TESTPOOL/$TESTVOL $TESTPOOL/$TESTVOL2"
+
+       ((vol_set_size = space_avail / 4))
+       vol_set_size=$(floor_volsize $vol_set_size)
+       ((sparse_vol_set_size = space_avail * 4))
+       sparse_vol_set_size=$(floor_volsize $sparse_vol_set_size)
+
+       log_must $ZFS create -V $vol_set_size $TESTPOOL/$TESTVOL
+       log_must $ZFS set refreservation=none $TESTPOOL/$TESTVOL
+       log_must $ZFS set reservation=none $TESTPOOL/$TESTVOL
+       log_must $ZFS create -s -V $sparse_vol_set_size $TESTPOOL/$TESTVOL2
+fi
+
+# re-calculate space available.
+space_avail=`get_prop available $TESTPOOL`
+
+# Calculate a large but valid reservation value.
+resv_size_set=`expr $space_avail - $RESV_DELTA`
+
+for obj in $OBJ_LIST ; do
+
+       space_avail=`get_prop available $TESTPOOL`
+       space_used=`get_prop used $TESTPOOL`
+
+       #
+       # For regular (non-sparse) volumes the upper limit is determined
+       # not by the space available in the pool but rather by the size
+       # of the volume itself.
+       #
+       [[ $obj == $TESTPOOL/$TESTVOL ]] && \
+           ((resv_size_set = vol_set_size - RESV_DELTA))
+
+       log_must $ZFS set reservation=$resv_size_set $obj
+
+       resv_size_get=`get_prop reservation $obj`
+       if [[ $resv_size_set != $resv_size_get ]]; then
+               log_fail "Reservation not the expected value " \
+               "($resv_size_set != $resv_size_get)"
+       fi
+
+       log_must $ZFS destroy -f $obj
+
+       new_space_avail=`get_prop available $TESTPOOL`
+       new_space_used=`get_prop used $TESTPOOL`
+
+       log_must within_limits $space_used $new_space_used $RESV_TOLERANCE
+       log_must within_limits $space_avail $new_space_avail $RESV_TOLERANCE
+done
+
+log_pass "Space correctly released when dataset is destroyed"
diff --git a/tests/zfs-tests/tests/functional/reservation/reservation_005_pos.sh b/tests/zfs-tests/tests/functional/reservation/reservation_005_pos.sh
new file mode 100755 (executable)
index 0000000..19b07fe
--- /dev/null
@@ -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.
+#
+
+#
+# Copyright (c) 2013 by Delphix. All rights reserved.
+#
+
+. $STF_SUITE/include/libtest.shlib
+. $STF_SUITE/tests/functional/reservation/reservation.shlib
+
+#
+# DESCRIPTION:
+#
+# When a reservation property of a filesystem, regular volume
+# or sparse volume is set to 'none' the space previously consumed by the
+# reservation should be released back to the pool
+#
+# STRATEGY:
+# 1) Create a filesystem, regular volume and sparse volume
+# 2) Get the space used and available in the pool
+# 3) Set a reservation on the filesystem less than the space available.
+# 4) Verify that the 'reservation' property for the filesystem has
+# the correct value.
+# 5) Reset the reservation value back to zero (or 'none')
+# 6) Verify that the space used and available totals for the pool have
+# changed by the expected amounts (within tolerances).
+# 7) Repeat steps 3-6 for a regular volume, sparse volume
+#
+
+verify_runnable "both"
+
+log_assert "Verify space released when reservation on a dataset is set "\
+       "to 'none'"
+
+function cleanup
+{
+       for obj in $OBJ_LIST; do
+               datasetexists $obj && log_must $ZFS destroy -f $obj
+       done
+}
+
+log_onexit cleanup
+
+space_avail=`get_prop available $TESTPOOL`
+
+if ! is_global_zone ; then
+       OBJ_LIST=""
+else
+       OBJ_LIST="$TESTPOOL/$TESTVOL $TESTPOOL/$TESTVOL2"
+       ((vol_set_size = space_avail / 4))
+       vol_set_size=$(floor_volsize $vol_set_size)
+       ((sparse_vol_set_size = space_avail * 4))
+       sparse_vol_set_size=$(floor_volsize $sparse_vol_set_size)
+
+
+       log_must $ZFS create -V $vol_set_size $TESTPOOL/$TESTVOL
+       log_must $ZFS set reservation=none $TESTPOOL/$TESTVOL
+       log_must $ZFS create -s -V $sparse_vol_set_size $TESTPOOL/$TESTVOL2
+fi
+
+space_avail=`get_prop available $TESTPOOL`
+space_used=`get_prop used $TESTPOOL`
+
+# Calculate a large but valid reservation value.
+resv_size_set=`expr $space_avail - $RESV_DELTA`
+
+for obj in $TESTPOOL/$TESTFS $OBJ_LIST ; do
+
+       #
+       # For regular (non-sparse) volumes the upper limit is determined
+       # not by the space available in the pool but rather by the size
+       # of the volume itself.
+       #
+       [[ $obj == $TESTPOOL/$TESTVOL ]] && \
+           ((resv_size_set = vol_set_size - RESV_DELTA))
+
+       log_must $ZFS set reservation=$resv_size_set $obj
+
+       resv_size_get=`get_prop reservation $obj`
+       if [[ $resv_size_set != $resv_size_get ]]; then
+               log_fail "Reservation not the expected value "\
+                       "($resv_size_set != $resv_size_get)"
+       fi
+
+       log_must $ZFS set reservation=none $obj
+
+       new_space_avail=`get_prop available $TESTPOOL`
+       new_space_used=`get_prop used $TESTPOOL`
+
+       log_must within_limits $space_used $new_space_used $RESV_TOLERANCE
+       log_must within_limits $space_avail $new_space_avail $RESV_TOLERANCE
+done
+
+log_pass "Space correctly released when dataset reservation set to 'none'"
diff --git a/tests/zfs-tests/tests/functional/reservation/reservation_006_pos.sh b/tests/zfs-tests/tests/functional/reservation/reservation_006_pos.sh
new file mode 100755 (executable)
index 0000000..87359aa
--- /dev/null
@@ -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.
+#
+
+#
+# Copyright (c) 2013 by Delphix. All rights reserved.
+#
+
+. $STF_SUITE/include/libtest.shlib
+. $STF_SUITE/tests/functional/reservation/reservation.shlib
+
+#
+# DESCRIPTION:
+#
+# Reservations (if successfully set) guarantee a minimum amount of space
+# for a dataset. Unlike quotas however there should be no restrictions
+# on accessing space outside of the limits of the reservation (if the
+# space is available in the pool). Verify that in a filesystem with a
+# reservation set that its possible to create files both within the
+# reserved space and also outside.
+#
+# STRATEGY:
+# 1) Create a filesystem
+# 2) Get the space used and available in the pool
+# 3) Set a reservation on the filesystem
+# 4) Verify can write a file that is bigger than the reserved space
+#
+# i.e. we start writing within the reserved region and then continue
+# for 20MB outside it.
+#
+
+verify_runnable "both"
+
+function cleanup
+{
+       [[ -e $TESTDIR/$TESTFILE1 ]] && log_must $RM -rf $TESTDIR/$TESTFILE1
+       log_must $ZFS set reservation=none $TESTPOOL/$TESTFS
+}
+
+log_onexit cleanup
+
+log_assert "Verify can create files both inside and outside reserved areas"
+
+space_used=`get_prop used $TESTPOOL`
+
+log_must $ZFS set reservation=$RESV_SIZE $TESTPOOL/$TESTFS
+
+#
+# Calculate how many writes of BLOCK_SIZE it would take to fill
+# up RESV_SIZE + 20971520 (20 MB).
+#
+fill_size=`expr $RESV_SIZE + 20971520`
+write_count=`expr $fill_size / $BLOCK_SIZE`
+
+log_must $FILE_WRITE -o create -f $TESTDIR/$TESTFILE1 -b $BLOCK_SIZE \
+    -c $write_count -d 0
+
+log_pass "Able to create files inside and outside reserved area"
diff --git a/tests/zfs-tests/tests/functional/reservation/reservation_007_pos.sh b/tests/zfs-tests/tests/functional/reservation/reservation_007_pos.sh
new file mode 100755 (executable)
index 0000000..0765f2b
--- /dev/null
@@ -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) 2013 by Delphix. All rights reserved.
+#
+
+. $STF_SUITE/include/libtest.shlib
+. $STF_SUITE/tests/functional/reservation/reservation.shlib
+
+#
+# DESCRIPTION:
+#
+# Setting a reservation on dataset should have no effect on any other
+# dataset at the same level in the hierarchy beyond using up available
+# space in the pool.
+#
+# STRATEGY:
+# 1) Create a filesystem
+# 2) Set a reservation on the filesystem
+# 3) Create another filesystem at the same level
+# 4) Set a reservation on the second filesystem
+# 5) Destroy both the filesystems
+# 6) Verify space accounted for correctly
+#
+
+verify_runnable "both"
+
+log_assert "Verify reservations on data sets doesn't affect other data sets " \
+    "at same level except for consuming space from common pool"
+
+function cleanup
+{
+       datasetexists $TESTPOOL/$TESTFS2 && \
+           log_must $ZFS destroy -f $TESTPOOL/$TESTFS2
+
+       datasetexists $TESTPOOL/$TESTFS1 && \
+           log_must $ZFS destroy -f $TESTPOOL/$TESTFS1
+}
+
+log_onexit cleanup
+
+space_avail=`get_prop available $TESTPOOL`
+space_used=`get_prop used $TESTPOOL`
+
+resv_size_set=`expr $space_avail / 3`
+
+#
+# Function which creates two datasets, sets reservations on them,
+# then destroys them and ensures that space is correctly accounted
+# for.
+#
+# Any special arguments for create are passed in via the args
+# paramater.
+#
+function create_resv_destroy { # args1 dataset1 args2 dataset2
+
+       args1=$1
+       dataset1=$2
+       args2=$3
+       dataset2=$4
+
+       log_must $ZFS create $args1 $dataset1
+
+       log_must $ZFS set reservation=$RESV_SIZE $dataset1
+
+       avail_aft_dset1=`get_prop available $TESTPOOL`
+       used_aft_dset1=`get_prop used $TESTPOOL`
+
+       log_must $ZFS create $args2 $dataset2
+
+       log_must $ZFS set reservation=$RESV_SIZE $dataset2
+
+       #
+       # After destroying the second dataset the space used and
+       # available totals should revert back to the values they
+       # had after creating the first dataset.
+       #
+       log_must $ZFS destroy -f $dataset2
+
+       avail_dest_dset2=`get_prop available $TESTPOOL`
+       used_dest_dset2=`get_prop used $TESTPOOL`
+
+       log_must within_limits $avail_aft_dset1 $avail_dest_dset2 $RESV_TOLERANCE
+       log_must within_limits $used_aft_dset1 $used_dest_dset2 $RESV_TOLERANCE
+
+
+       # After destroying the first dataset the space used and
+       # space available totals should revert back to the values
+       # they had when the pool was first created.
+       log_must $ZFS destroy -f $dataset1
+
+       avail_dest_dset1=`get_prop available $TESTPOOL`
+       used_dest_dset1=`get_prop used $TESTPOOL`
+
+       log_must within_limits $avail_dest_dset1 $space_avail $RESV_TOLERANCE
+       log_must within_limits $used_dest_dset1 $space_used $RESV_TOLERANCE
+}
+
+create_resv_destroy "" $TESTPOOL/$TESTFS1 ""  $TESTPOOL/$TESTFS2
+create_resv_destroy "" $TESTPOOL/$TESTFS2 "" $TESTPOOL/$TESTFS1
+
+log_pass "Verify reservations on data sets doesn't affect other data sets at" \
+       " same level except for consuming space from common pool"
diff --git a/tests/zfs-tests/tests/functional/reservation/reservation_008_pos.sh b/tests/zfs-tests/tests/functional/reservation/reservation_008_pos.sh
new file mode 100755 (executable)
index 0000000..5753d99
--- /dev/null
@@ -0,0 +1,124 @@
+#!/bin/ksh -p
+#
+# CDDL HEADER START
+#
+# The contents of this file are subject to the terms of the
+# Common Development and Distribution License (the "License").
+# You may not use this file except in compliance with the License.
+#
+# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
+# or http://www.opensolaris.org/os/licensing.
+# See the License for the specific language governing permissions
+# and limitations under the License.
+#
+# When distributing Covered Code, include this CDDL HEADER in each
+# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
+# If applicable, add the following below this CDDL HEADER, with the
+# fields enclosed by brackets "[]" replaced with your own identifying
+# information: Portions Copyright [yyyy] [name of copyright owner]
+#
+# CDDL HEADER END
+#
+
+#
+# Copyright 2009 Sun Microsystems, Inc.  All rights reserved.
+# Use is subject to license terms.
+#
+
+#
+# Copyright (c) 2013 by Delphix. All rights reserved.
+#
+
+. $STF_SUITE/include/libtest.shlib
+. $STF_SUITE/tests/functional/reservation/reservation.shlib
+
+#
+# DESCRIPTION:
+#
+# Setting a reservation reserves a defined minimum amount of space for
+# a dataset, and prevents other datasets using that space. Verify that
+# reducing the reservation on a filesystem allows other datasets in
+# the pool to use that space.
+#
+# STRATEGY:
+# 1) Create multiple filesystems
+# 2) Set reservations on all bar one of the filesystems
+# 3) Fill up the one non-reserved filesystem
+# 4) Reduce one of the reservations and verify can write more
+# data into the non-reserved filesystem
+#
+
+verify_runnable "both"
+
+log_assert "Verify reducing reservation allows other datasets to use space"
+
+function cleanup
+{
+       typeset -i loop=0
+       while (($loop < $RESV_NUM_FS)); do
+               datasetexists $TESTPOOL/${TESTFS}$loop && \
+                   log_must $ZFS destroy -f $TESTPOOL/${TESTFS}$loop
+
+               [[ -d ${TESTDIR}$loop ]] && log_must $RM -r ${TESTDIR}$loop
+
+               ((loop = loop + 1))
+       done
+}
+
+log_onexit cleanup
+
+log_must create_multiple_fs $RESV_NUM_FS $TESTPOOL/$TESTFS $TESTDIR
+
+space_avail=`get_prop available $TESTPOOL`
+space_used=`get_prop used $TESTPOOL`
+
+#
+# To make sure this test doesn't take too long to execute on
+# large pools, we calculate a reservation setting which when
+# applied to all bar one of the filesystems (RESV_NUM_FS-1) will
+# ensure we have RESV_FREE_SPACE left free in the pool, which we will
+# be able to quickly fill.
+#
+resv_space_avail=`expr $space_avail - $RESV_FREE_SPACE`
+num_resv_fs=`expr $RESV_NUM_FS - 1` # Number of FS to which resv will be applied
+resv_size_set=`expr $resv_space_avail / $num_resv_fs`
+
+#
+# We set the reservations now, rather than when we created the filesystems
+# to allow us to take into account space used by the filsystem metadata
+#
+# Note we don't set a reservation on the first filesystem we created,
+# hence num=1 rather than zero below.
+#
+typeset -i num=1
+while (($num < $RESV_NUM_FS)); do
+       log_must $ZFS set reservation=$resv_size_set $TESTPOOL/$TESTFS$num
+       ((num = num + 1))
+done
+
+space_avail_still=`get_prop available $TESTPOOL`
+
+fill_size=`expr $space_avail_still + $RESV_TOLERANCE`
+write_count=`expr $fill_size / $BLOCK_SIZE`
+
+# Now fill up the first filesystem (which doesn't have a reservation set
+# and thus will use up whatever free space is left in the pool).
+num=0
+log_note "Writing to $TESTDIR$num/$TESTFILE1"
+
+$FILE_WRITE -o create -f $TESTDIR$num/$TESTFILE1 -b $BLOCK_SIZE \
+    -c $write_count -d 0
+ret=$?
+if (($ret != $ENOSPC)); then
+       log_fail "Did not get ENOSPC as expected (got $ret)."
+fi
+
+# Remove the reservation on one of the other filesystems and verify
+# can write more data to the original non-reservation filesystem.
+num=1
+log_must $ZFS set reservation=none $TESTPOOL/${TESTFS}$num
+num=0
+log_must $FILE_WRITE -o create -f ${TESTDIR}$num/$TESTFILE2 -b $PAGESIZE \
+    -c 1000 -d 0
+
+log_pass "reducing reservation allows other datasets to use space"
diff --git a/tests/zfs-tests/tests/functional/reservation/reservation_009_pos.sh b/tests/zfs-tests/tests/functional/reservation/reservation_009_pos.sh
new file mode 100755 (executable)
index 0000000..67c6524
--- /dev/null
@@ -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 2009 Sun Microsystems, Inc.  All rights reserved.
+# Use is subject to license terms.
+#
+
+#
+# Copyright (c) 2013 by Delphix. All rights reserved.
+#
+
+. $STF_SUITE/include/libtest.shlib
+. $STF_SUITE/tests/functional/reservation/reservation.shlib
+
+#
+# DESCRIPTION:
+#
+# In pool with a full filesystem and another filesystem with a reservation
+# setting the reservation on the second filesystem to 'none' should allow more
+# data to be written to the first filesystem.
+#
+#
+# STRATEGY:
+# 1) Create a filesystem as a dataset
+# 2) Create a filesystem at the same level
+# 3) Set a reservation on the dataset filesystem
+# 4) Fill up the filesystem
+# 5) Set the reservation on the dataset filesystem to 'none'
+# 6) Verify we can write more data to the first filesystem
+#
+
+verify_runnable "both"
+
+log_assert "Setting top level dataset reservation to 'none' allows more data "
+    "to be written to top level filesystem"
+
+function cleanup
+{
+       log_must $RM -rf $TESTDIR/$TESTFILE1
+       log_must $RM -rf $TESTDIR/$TESTFILE2
+       log_must $ZFS destroy -f $TESTPOOL/$TESTFS1
+}
+
+log_onexit cleanup
+
+log_must $ZFS create $TESTPOOL/$TESTFS1
+
+space_avail=`get_prop available $TESTPOOL`
+
+#
+# To make sure this test doesn't take too long to execute on
+# large pools, we calculate a reservation setting which when
+# applied to the dataset will ensure we have RESV_FREE_SPACE
+# left free in the pool which we can quickly fill.
+#
+((resv_size_set = space_avail - RESV_FREE_SPACE))
+
+log_must $ZFS set reservation=$resv_size_set $TESTPOOL/$TESTFS1
+
+space_avail_still=`get_prop available $TESTPOOL`
+
+fill_size=`expr $space_avail_still + $RESV_TOLERANCE`
+write_count=`expr $fill_size / $BLOCK_SIZE`
+
+# Now fill up the filesystem (which doesn't have a reservation set
+# and thus will use up whatever free space is left in the pool).
+$FILE_WRITE -o create -f $TESTDIR/$TESTFILE1 -b $BLOCK_SIZE \
+        -c $write_count -d 0
+ret=$?
+if (($ret != $ENOSPC)); then
+       log_fail "Did not get ENOSPC as expected (got $ret)."
+fi
+
+log_must $ZFS set reservation=none $TESTPOOL/$TESTFS1
+
+log_must $FILE_WRITE -o create -f $TESTDIR/$TESTFILE2 -b $PAGESIZE \
+    -c 1000 -d 0
+
+log_pass "Setting top level dataset reservation to 'none' allows more " \
+    "data to be written to the top level filesystem"
diff --git a/tests/zfs-tests/tests/functional/reservation/reservation_010_pos.sh b/tests/zfs-tests/tests/functional/reservation/reservation_010_pos.sh
new file mode 100755 (executable)
index 0000000..23e78bd
--- /dev/null
@@ -0,0 +1,101 @@
+#!/bin/ksh -p
+#
+# CDDL HEADER START
+#
+# The contents of this file are subject to the terms of the
+# Common Development and Distribution License (the "License").
+# You may not use this file except in compliance with the License.
+#
+# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
+# or http://www.opensolaris.org/os/licensing.
+# See the License for the specific language governing permissions
+# and limitations under the License.
+#
+# When distributing Covered Code, include this CDDL HEADER in each
+# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
+# If applicable, add the following below this CDDL HEADER, with the
+# fields enclosed by brackets "[]" replaced with your own identifying
+# information: Portions Copyright [yyyy] [name of copyright owner]
+#
+# CDDL HEADER END
+#
+
+#
+# Copyright 2007 Sun Microsystems, Inc.  All rights reserved.
+# Use is subject to license terms.
+#
+
+#
+# Copyright (c) 2013 by Delphix. All rights reserved.
+#
+
+. $STF_SUITE/include/libtest.shlib
+. $STF_SUITE/tests/functional/reservation/reservation.shlib
+
+#
+# DESCRIPTION:
+#
+# In pool with a full filesystem and a filesystem with a reservation
+# destroying another filesystem should allow more data to be written to
+# the full filesystem
+#
+#
+# STRATEGY:
+# 1) Create a filesystem as dataset
+# 2) Create a filesystem at the same level
+# 3) Set a reservation on the dataset filesystem
+# 4) Fill up the second filesystem
+# 5) Destroy the dataset filesystem
+# 6) Verify can write more data to the full filesystem
+#
+
+verify_runnable "both"
+
+log_assert "Destroying top level filesystem with reservation allows more " \
+    "data to be written to another top level filesystem"
+
+function cleanup
+{
+       datasetexists $TESTPOOL/$TESTFS1 && \
+           log_must $ZFS destroy $TESTPOOL/$TESTFS1
+
+       [[ -e $TESTDIR/$TESTFILE1 ]] && log_must $RM -rf $TESTDIR/$TESTFILE1
+       [[ -e $TESTDIR/$TESTFILE2 ]] && log_must $RM -rf $TESTDIR/$TESTFILE2
+}
+
+log_onexit cleanup
+
+log_must $ZFS create $TESTPOOL/$TESTFS1
+
+space_avail=`get_prop available $TESTPOOL`
+
+#
+# To make sure this test doesn't take too long to execute on
+# large pools, we calculate a reservation setting which when
+# applied to the dataset filesystem  will ensure we have
+# RESV_FREE_SPACE left free in the pool.
+#
+((resv_size_set = space_avail - RESV_FREE_SPACE))
+
+log_must $ZFS set reservation=$resv_size_set $TESTPOOL/$TESTFS1
+
+space_avail_still=`get_prop available $TESTPOOL`
+
+fill_size=`expr $space_avail_still + $RESV_TOLERANCE`
+write_count=`expr $fill_size / $BLOCK_SIZE`
+
+# Now fill up the filesystem (which doesn't have a reservation set
+# and thus will use up whatever free space is left in the pool).
+$FILE_WRITE -o create -f $TESTDIR/$TESTFILE1 -b $BLOCK_SIZE -c $write_count -d 0
+ret=$?
+if (($ret != $ENOSPC)); then
+       log_fail "Did not get ENOSPC as expected (got $ret)."
+fi
+
+log_must $ZFS destroy -f $TESTPOOL/$TESTFS1
+
+log_must $FILE_WRITE -o create -f $TESTDIR/$TESTFILE2 -b $PAGESIZE \
+    -c 1000 -d 0
+
+log_pass "Destroying top level filesystem with reservation allows more data " \
+    "to be written to another top level filesystem"
diff --git a/tests/zfs-tests/tests/functional/reservation/reservation_011_pos.sh b/tests/zfs-tests/tests/functional/reservation/reservation_011_pos.sh
new file mode 100755 (executable)
index 0000000..1260e04
--- /dev/null
@@ -0,0 +1,75 @@
+#!/bin/ksh -p
+#
+# CDDL HEADER START
+#
+# The contents of this file are subject to the terms of the
+# Common Development and Distribution License (the "License").
+# You may not use this file except in compliance with the License.
+#
+# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
+# or http://www.opensolaris.org/os/licensing.
+# See the License for the specific language governing permissions
+# and limitations under the License.
+#
+# When distributing Covered Code, include this CDDL HEADER in each
+# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
+# If applicable, add the following below this CDDL HEADER, with the
+# fields enclosed by brackets "[]" replaced with your own identifying
+# information: Portions Copyright [yyyy] [name of copyright owner]
+#
+# CDDL HEADER END
+#
+
+#
+# Copyright 2007 Sun Microsystems, Inc.  All rights reserved.
+# Use is subject to license terms.
+#
+
+#
+# Copyright (c) 2013 by Delphix. All rights reserved.
+#
+
+. $STF_SUITE/include/libtest.shlib
+. $STF_SUITE/tests/functional/reservation/reservation.shlib
+
+#
+# DESCRIPTION:
+#
+# ZFS has two mechanisms dealing with space for datasets, namely
+# reservations and quotas. Setting one should not affect the other,
+# provided the values are legal (i.e. enough space in pool etc).
+#
+# STRATEGY:
+# 1) Create one filesystem
+# 2) Get the current quota setting
+# 3) Set a reservation
+# 4) Verify that the quota value remains unchanged
+#
+
+verify_runnable "both"
+
+log_assert "Verify reservation settings do not affect quota settings"
+
+function cleanup
+{
+       log_must zero_reservation $TESTPOOL/$TESTFS
+}
+
+log_onexit cleanup
+
+space_avail=`get_prop available $TESTPOOL`
+
+((resv_size_set = (space_avail - RESV_DELTA) / 2))
+
+fs_quota=`$ZFS get quota $TESTPOOL/$TESTFS`
+
+log_must $ZFS set reservation=$resv_size_set $TESTPOOL/$TESTFS
+
+new_fs_quota=`$ZFS get quota $TESTPOOL/$TESTFS`
+
+if [[ $fs_quota != $new_fs_quota ]]; then
+       log_fail "Quota value on $TESTFS has changed " \
+           "($fs_quota != $new_fs_quota)"
+fi
+
+log_pass "Quota settings unaffected by reservation settings"
diff --git a/tests/zfs-tests/tests/functional/reservation/reservation_012_pos.sh b/tests/zfs-tests/tests/functional/reservation/reservation_012_pos.sh
new file mode 100755 (executable)
index 0000000..cc412a0
--- /dev/null
@@ -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 2009 Sun Microsystems, Inc.  All rights reserved.
+# Use is subject to license terms.
+#
+
+#
+# Copyright (c) 2013 by Delphix. All rights reserved.
+#
+
+. $STF_SUITE/include/libtest.shlib
+. $STF_SUITE/tests/functional/reservation/reservation.shlib
+
+#
+# DESCRIPTION:
+#
+# A reservation guarantees a certain amount of space for a dataset.
+# Nothing else which happens in the same pool should affect that
+# space, i.e. even if the rest of the pool fills up the reserved
+# space should still be accessible.
+#
+# STRATEGY:
+# 1) Create 2 filesystems
+# 2) Set a reservation on one filesystem
+# 3) Fill up the other filesystem (which does not have a reservation
+# set) until all space is consumed
+# 4) Verify can still write to the filesystem which has a reservation
+#
+
+verify_runnable "both"
+
+log_assert "Verify reservations protect space"
+
+function cleanup
+{
+       log_must $ZFS destroy -f $TESTPOOL/$TESTFS2
+       log_must zero_reservation $TESTPOOL/$TESTFS
+
+       [[ -e $TESTDIR/$TESTFILE2 ]] && log_must $RM -rf $TESTDIR/$TESTFILE2
+       [[ -d $TESTDIR2 ]] && log_must $RM -rf $TESTDIR2
+}
+
+log_onexit cleanup
+
+log_must $ZFS create $TESTPOOL/$TESTFS2
+log_must $ZFS set mountpoint=$TESTDIR2 $TESTPOOL/$TESTFS2
+
+space_avail=`get_prop available $TESTPOOL`
+
+((resv_size_set = space_avail - RESV_FREE_SPACE))
+
+log_must $ZFS set reservation=$resv_size_set $TESTPOOL/$TESTFS
+
+((write_count = (RESV_FREE_SPACE + RESV_TOLERANCE) / BLOCK_SIZE))
+
+$FILE_WRITE -o create -f $TESTDIR2/$TESTFILE1 -b $BLOCK_SIZE -c $write_count \
+    -d 0
+ret=$?
+if [[ $ret != $ENOSPC ]]; then
+       log_fail "Did not get ENOSPC (got $ret) for non-reserved filesystem"
+fi
+
+((write_count = (RESV_FREE_SPACE - RESV_TOLERANCE) / BLOCK_SIZE))
+log_must $FILE_WRITE -o create -f $TESTDIR/$TESTFILE2 -b $BLOCK_SIZE -c \
+    $write_count -d 0
+
+log_pass "Reserved space preserved correctly"
diff --git a/tests/zfs-tests/tests/functional/reservation/reservation_013_pos.sh b/tests/zfs-tests/tests/functional/reservation/reservation_013_pos.sh
new file mode 100755 (executable)
index 0000000..3ddd9cc
--- /dev/null
@@ -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.
+#
+
+#
+# Copyright (c) 2013 by Delphix. All rights reserved.
+#
+
+. $STF_SUITE/include/libtest.shlib
+. $STF_SUITE/tests/functional/reservation/reservation.shlib
+
+#
+# DESCRIPTION:
+#
+# Reservation properties on data objects should be preserved when the
+# pool within which they are contained is exported and then re-imported.
+#
+#
+# STRATEGY:
+# 1) Create a filesystem as dataset
+# 2) Create another filesystem at the same level
+# 3) Create a regular volume at the same level
+# 4) Create a sparse volume at the same level
+# 5) Create a filesystem within the dataset filesystem
+# 6) Set reservations on all filesystems
+# 7) Export the pool
+# 8) Re-import the pool
+# 9) Verify that the reservation settings are correct
+#
+
+verify_runnable "global"
+
+log_assert "Reservation properties preserved across exports and imports"
+
+function cleanup
+{
+       for obj in $OBJ_LIST; do
+                datasetexists $obj && log_must $ZFS destroy -f $obj
+        done
+
+       log_must zero_reservation $TESTPOOL/$TESTFS
+}
+log_onexit cleanup
+
+OBJ_LIST="$TESTPOOL/$TESTFS1/$TESTFS2 $TESTPOOL/$TESTFS1 $TESTPOOL/$TESTVOL \
+    $TESTPOOL/$TESTVOL2"
+
+log_must $ZFS create $TESTPOOL/$TESTFS1
+log_must $ZFS create $TESTPOOL/$TESTFS1/$TESTFS2
+
+space_avail=$(get_prop available $TESTPOOL)
+[[ $? -ne 0 ]] && \
+    log_fail "Unable to get space available property for $TESTPOOL"
+
+((resv_set = space_avail / 5))
+resv_set=$(floor_volsize $resv_set)
+((sparse_vol_set_size = space_avail * 5))
+sparse_vol_set_size=$(floor_volsize $sparse_vol_set_size)
+
+# When initially created, a regular volume's reservation property is set
+# equal to its size (unlike a sparse volume), so we don't need to set it
+# explictly later on
+log_must $ZFS create -V $resv_set $TESTPOOL/$TESTVOL
+log_must $ZFS create -s -V $sparse_vol_set_size $TESTPOOL/$TESTVOL2
+
+log_must $ZFS set reservation=$resv_set $TESTPOOL/$TESTFS
+log_must $ZFS set reservation=$resv_set $TESTPOOL/$TESTFS1
+log_must $ZFS set reservation=$resv_set $TESTPOOL/$TESTFS1/$TESTFS2
+log_must $ZFS set reservation=$resv_set $TESTPOOL/$TESTVOL2
+
+log_must $ZPOOL export $TESTPOOL
+log_must $ZPOOL import $TESTPOOL
+
+for obj in $TESTPOOL/$TESTFS $OBJ_LIST; do
+
+       if [[ $obj == $TESTPOOL/$TESTVOL ]]; then
+               expected=$(volsize_to_reservation $obj $resv_set)
+               found=$(get_prop refreservation $obj)
+       else
+               expected=$resv_set
+               found=$(get_prop reservation $obj)
+       fi
+
+       [[ $found != $expected ]] && \
+           log_fail "Reservation property for $obj incorrect. Expected " \
+           "$expected but got $found."
+done
+
+log_pass "Reservation properties preserved across exports and imports"
diff --git a/tests/zfs-tests/tests/functional/reservation/reservation_014_pos.sh b/tests/zfs-tests/tests/functional/reservation/reservation_014_pos.sh
new file mode 100755 (executable)
index 0000000..dbc6889
--- /dev/null
@@ -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) 2013 by Delphix. All rights reserved.
+#
+
+. $STF_SUITE/include/libtest.shlib
+. $STF_SUITE/tests/functional/reservation/reservation.shlib
+
+#
+# DESCRIPTION:
+#
+# A reservation cannot exceed the quota on a dataset
+#
+# STRATEGY:
+# 1) Create a filesystem and volume
+# 2) Set a quota on the filesystem
+# 3) Attempt to set a reservation larger than the quota. Verify
+# that the attempt fails.
+# 4) Repeat 2-3 for volume
+#
+
+verify_runnable "both"
+
+log_assert "Verify cannot set reservation larger than quota"
+
+function cleanup
+{
+       #
+       # Note we don't destroy $TESTFS as it's used by other tests
+       for obj in $OBJ_LIST ; do
+               datasetexists $obj && log_must $ZFS destroy -f $obj
+       done
+
+       log_must zero_reservation $TESTPOOL/$TESTFS
+}
+log_onexit cleanup
+
+space_avail=`get_prop available $TESTPOOL`
+
+if ! is_global_zone ; then
+       OBJ_LIST=""
+else
+       OBJ_LIST="$TESTPOOL/$TESTVOL $TESTPOOL/$TESTVOL2"
+
+        ((vol_set_size = space_avail / 4))
+       vol_set_size=$(floor_volsize $vol_set_size)
+       ((sparse_vol_set_size = space_avail * 4))
+       sparse_vol_set_size=$(floor_volsize $sparse_vol_set_size)
+
+       log_must $ZFS create -V $vol_set_size $TESTPOOL/$TESTVOL
+       log_must $ZFS create -s -V $sparse_vol_set_size $TESTPOOL/$TESTVOL2
+fi
+
+for obj in $TESTPOOL/$TESTFS $OBJ_LIST ; do
+
+       space_avail=`get_prop available $TESTPOOL`
+       ((quota_set_size = space_avail / 3))
+
+       #
+       # A regular (non-sparse) volume's size is effectively
+       # its quota so only need to explicitly set quotas for
+       # filesystems and datasets.
+       #
+       # A volumes size is effectively its quota. The maximum
+       # reservation value that can be set on a volume is
+       # determined by the size of the volume or the amount of
+       # space in the pool, whichever is smaller.
+       #
+       if [[ $obj == $TESTPOOL/$TESTFS ]]; then
+               log_must $ZFS set quota=$quota_set_size $obj
+               ((resv_set_size = quota_set_size + RESV_SIZE))
+
+       elif [[ $obj == $TESTPOOL/$TESTVOL2 ]] ; then
+
+               ((resv_set_size = sparse_vol_set_size + RESV_SIZE))
+
+       elif [[ $obj == $TESTPOOL/$TESTVOL ]] ; then
+
+               ((resv_set_size = vol_set_size + RESV_SIZE))
+       fi
+
+       orig_quota=`get_prop quota $obj`
+
+       log_mustnot $ZFS set reservation=$resv_set_size $obj
+       new_quota=`get_prop quota $obj`
+
+       if [[ $orig_quota != $new_quota ]]; then
+               log_fail "Quota value changed from $orig_quota " \
+                               "to $new_quota"
+       fi
+
+       if [[ $obj == $TESTPOOL/$TESTFS ]]; then
+               log_must $ZFS set quota=none $obj
+       fi
+done
+
+log_pass "As expected cannot set reservation larger than quota"
diff --git a/tests/zfs-tests/tests/functional/reservation/reservation_015_pos.sh b/tests/zfs-tests/tests/functional/reservation/reservation_015_pos.sh
new file mode 100755 (executable)
index 0000000..c8779a4
--- /dev/null
@@ -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 2009 Sun Microsystems, Inc.  All rights reserved.
+# Use is subject to license terms.
+#
+
+#
+# Copyright (c) 2013 by Delphix. All rights reserved.
+#
+
+. $STF_SUITE/include/libtest.shlib
+. $STF_SUITE/tests/functional/reservation/reservation.shlib
+
+#
+# DESCRIPTION:
+#
+# In pool with a full filesystem and a regular volume with an implicit
+# reservation, setting the reservation on the volume to 'none' should allow
+# more data to be written to the filesystem.
+#
+#
+# STRATEGY:
+# 1) Create a regular non-sparse volume (which implicitly sets the reservation
+#    property to a value equal to the volume size)
+# 2) Create a filesystem at the same level
+# 3) Fill up the filesystem
+# 4) Set the reservation on the volume to 'none'
+# 5) Verify can write more data to the filesystem
+#
+
+verify_runnable "global"
+
+log_assert "Setting volume reservation to 'none' allows more data to be " \
+    "written to top level filesystem"
+
+function cleanup
+{
+       datasetexists $TESTPOOL/$TESTVOL && \
+       log_must $ZFS destroy $TESTPOOL/$TESTVOL
+
+       [[ -e $TESTDIR/$TESTFILE1 ]] && log_must $RM -rf $TESTDIR/$TESTFILE1
+       [[ -e $TESTDIR/$TESTFILE2 ]] && log_must $RM -rf $TESTDIR/$TESTFILE2
+}
+log_onexit cleanup
+
+space_avail=$(largest_volsize_from_pool $TESTPOOL)
+
+#
+# To make sure this test doesn't take too long to execute on
+# large pools, we calculate a volume size which when applied
+# to the volume will ensure we have RESV_FREE_SPACE
+# left free in the pool which we can quickly fill.
+#
+((resv_size_set = space_avail - RESV_FREE_SPACE))
+resv_size_set=$(floor_volsize $resv_size_set)
+
+log_must $ZFS create -V $resv_size_set $TESTPOOL/$TESTVOL
+
+space_avail_still=`get_prop available $TESTPOOL`
+
+fill_size=$((space_avail_still + $RESV_TOLERANCE))
+write_count=$((fill_size / BLOCK_SIZE))
+
+# Now fill up the filesystem (which doesn't have a reservation set
+# and thus will use up whatever free space is left in the pool).
+$FILE_WRITE -o create -f $TESTDIR/$TESTFILE1 -b $BLOCK_SIZE -c $write_count -d 0
+ret=$?
+if (($ret != $ENOSPC)); then
+       log_fail "Did not get ENOSPC as expected (got $ret)."
+fi
+
+log_must $ZFS set refreservation=none $TESTPOOL/$TESTVOL
+
+log_must $FILE_WRITE -o create -f $TESTDIR/$TESTFILE2 -b $PAGESIZE \
+    -c 1000 -d 0
+
+log_pass "Setting top level volume reservation to 'none' allows more " \
+    "data to be written to the top level filesystem"
diff --git a/tests/zfs-tests/tests/functional/reservation/reservation_016_pos.sh b/tests/zfs-tests/tests/functional/reservation/reservation_016_pos.sh
new file mode 100755 (executable)
index 0000000..04c0165
--- /dev/null
@@ -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) 2013 by Delphix. All rights reserved.
+#
+
+. $STF_SUITE/include/libtest.shlib
+. $STF_SUITE/tests/functional/reservation/reservation.shlib
+
+#
+# DESCRIPTION:
+#
+# In pool with a full filesystem and a regular volume (with implicit
+# reservation) destroying the volume should allow more data to be written
+# to the filesystem
+#
+#
+# STRATEGY:
+# 1) Create a regular (non-sparse) volume
+# 2) Create a filesystem at the same level
+# 3) Fill up the filesystem
+# 4) Destroy the volume
+# 5) Verify can write more data to the filesystem
+#
+
+verify_runnable "global"
+
+log_assert "Destroying a regular volume with reservation allows more data to" \
+    " be written to top level filesystem"
+
+function cleanup
+{
+       datasetexists $TESTPOOL/$TESTVOL && \
+           log_must $ZFS destroy $TESTPOOL/$TESTVOL
+
+       [[ -e $TESTDIR/$TESTFILE1 ]] && log_must $RM -rf $TESTDIR/$TESTFILE1
+       [[ -e $TESTDIR/$TESTFILE2 ]] && log_must $RM -rf $TESTDIR/$TESTFILE2
+}
+log_onexit cleanup
+
+space_avail=$(largest_volsize_from_pool $TESTPOOL)
+
+#
+# To make sure this test doesn't take too long to execute on
+# large pools, we calculate a volume size which will ensure we
+# have RESV_FREE_SPACE left free in the pool.
+#
+((vol_set_size = space_avail - RESV_FREE_SPACE))
+vol_set_size=$(floor_volsize $vol_set_size)
+
+# Creating a regular volume implicitly sets its reservation
+# property to the same value.
+log_must $ZFS create -V $vol_set_size $TESTPOOL/$TESTVOL
+
+space_avail_still=$(get_prop available $TESTPOOL)
+fill_size=$((space_avail_still + $RESV_TOLERANCE))
+write_count=$((fill_size / BLOCK_SIZE))
+
+# Now fill up the filesystem (which doesn't have a reservation set
+# and thus will use up whatever free space is left in the pool).
+$FILE_WRITE -o create -f $TESTDIR/$TESTFILE1 -b $BLOCK_SIZE -c $write_count -d 0
+ret=$?
+if (($ret != $ENOSPC)); then
+       log_fail "Did not get ENOSPC as expected (got $ret)."
+fi
+
+log_must $ZFS destroy -f $TESTPOOL/$TESTVOL
+
+log_must $FILE_WRITE -o create -f $TESTDIR/$TESTFILE2 -b $PAGESIZE \
+    -c 1000 -d 0
+
+log_pass "Destroying volume with reservation allows more data to be written " \
+    "to top level filesystem"
diff --git a/tests/zfs-tests/tests/functional/reservation/reservation_017_pos.sh b/tests/zfs-tests/tests/functional/reservation/reservation_017_pos.sh
new file mode 100755 (executable)
index 0000000..b0a5f45
--- /dev/null
@@ -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 2009 Sun Microsystems, Inc.  All rights reserved.
+# Use is subject to license terms.
+#
+
+#
+# Copyright (c) 2013 by Delphix. All rights reserved.
+#
+
+. $STF_SUITE/include/libtest.shlib
+. $STF_SUITE/tests/functional/reservation/reservation.shlib
+
+#
+# DESCRIPTION:
+#
+# For a sparse volume changes to the volsize are not reflected in the
+# reservation.
+#
+# STRATEGY:
+# 1) Create a regular and sparse volume
+# 2) Get the space available in the pool
+# 3) Set reservation with various sizes on the regular and sparse volumes
+# 4) Verify that the 'reservation' property for the regular volume has
+#    the correct value.
+# 5) Verify that the 'reservation' property for the sparse volume is set to
+#    'none'
+#
+
+verify_runnable "global"
+
+function cleanup
+{
+       typeset vol
+
+       for vol in $regvol $sparsevol; do
+               datasetexists $vol &&  log_must $ZFS destroy $vol
+       done
+}
+log_onexit cleanup
+
+log_assert "Verify that the volsize changes of sparse volumes are not " \
+    "reflected in the reservation."
+log_onexit cleanup
+
+# Create a regular and sparse volume for testing.
+regvol=$TESTPOOL/$TESTVOL
+sparsevol=$TESTPOOL/$TESTVOL2
+log_must $ZFS create -V 64M $regvol
+log_must $ZFS create -s -V 64M $sparsevol
+
+typeset -i vsize=$(get_prop available $TESTPOOL)
+typeset -i iterate=10
+typeset -i regreserv
+typeset -i sparsereserv
+typeset -i volblocksize=$(get_prop volblocksize $regvol)
+typeset -i blknum=0
+typeset -i randomblknum
+((blknum = vsize / volblocksize))
+
+while ((iterate > 1)); do
+       ((randomblknum = 1 + RANDOM % blknum))
+       # Make sure volsize is a multiple of volume block size
+       ((vsize = randomblknum * volblocksize))
+       log_must $ZFS set volsize=$vsize $regvol
+       log_must $ZFS set volsize=$vsize $sparsevol
+       vsize=$(volsize_to_reservation $regvol $vsize)
+       regreserv=$(get_prop refreservation $regvol)
+       sparsereserv=$(get_prop reservation $sparsevol)
+       ((sparsereserv == vsize)) && \
+               log_fail "volsize changes of sparse volume is reflected in " \
+                   "reservation (expected $vsize, got $sparsereserv)."
+       ((regreserv != vsize)) && \
+               log_fail "volsize changes of regular volume is not reflected " \
+                   "in reservation (expected $vsize, got $regreserv)."
+       ((iterate = iterate - 1))
+done
+
+log_pass "The volsize changes of sparse volumes are not reflected in the " \
+    "reservation"
diff --git a/tests/zfs-tests/tests/functional/reservation/reservation_018_pos.sh b/tests/zfs-tests/tests/functional/reservation/reservation_018_pos.sh
new file mode 100755 (executable)
index 0000000..9236fd0
--- /dev/null
@@ -0,0 +1,72 @@
+#!/bin/ksh -p
+#
+# CDDL HEADER START
+#
+# The contents of this file are subject to the terms of the
+# Common Development and Distribution License (the "License").
+# You may not use this file except in compliance with the License.
+#
+# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
+# or http://www.opensolaris.org/os/licensing.
+# See the License for the specific language governing permissions
+# and limitations under the License.
+#
+# When distributing Covered Code, include this CDDL HEADER in each
+# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
+# If applicable, add the following below this CDDL HEADER, with the
+# fields enclosed by brackets "[]" replaced with your own identifying
+# information: Portions Copyright [yyyy] [name of copyright owner]
+#
+# CDDL HEADER END
+#
+
+#
+# Copyright 2009 Sun Microsystems, Inc.  All rights reserved.
+# Use is subject to license terms.
+#
+
+#
+# Copyright (c) 2013 by Delphix. All rights reserved.
+#
+
+. $STF_SUITE/include/libtest.shlib
+. $STF_SUITE/tests/functional/reservation/reservation.shlib
+
+#
+# DESCRIPTION:
+#
+# Verify that reservation doesn't inherit its value from parent.
+#
+# STRATEGY:
+# 1) Create a filesystem tree
+# 2) Set reservation for parents
+# 3) Verify that the 'reservation' for descendent doesnot inherit the value.
+#
+
+verify_runnable "both"
+
+function cleanup
+{
+       datasetexists $fs_child && log_must $ZFS destroy $fs_child
+       log_must $ZFS set reservation=$reserv_val $fs
+}
+
+log_onexit cleanup
+
+log_assert "Verify that reservation doesnot inherit its value from parent."
+
+fs=$TESTPOOL/$TESTFS
+fs_child=$TESTPOOL/$TESTFS/$TESTFS
+
+space_avail=$(get_prop available $fs)
+reserv_val=$(get_prop reservation $fs)
+typeset -l reservsize=$space_avail
+((reservsize = reservsize / 2))
+log_must $ZFS set reservation=$reservsize $fs
+
+log_must $ZFS create $fs_child
+rsv_space=$(get_prop reservation $fs_child)
+[[ $rsv_space == $reservsize ]] && \
+    log_fail "The reservation of child dataset inherits its value from parent."
+
+log_pass "reservation doesnot inherit its value from parent as expected."
diff --git a/tests/zfs-tests/tests/functional/reservation/setup.ksh b/tests/zfs-tests/tests/functional/reservation/setup.ksh
new file mode 100755 (executable)
index 0000000..c390347
--- /dev/null
@@ -0,0 +1,35 @@
+#!/bin/ksh -p
+#
+# CDDL HEADER START
+#
+# The contents of this file are subject to the terms of the
+# Common Development and Distribution License (the "License").
+# You may not use this file except in compliance with the License.
+#
+# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
+# or http://www.opensolaris.org/os/licensing.
+# See the License for the specific language governing permissions
+# and limitations under the License.
+#
+# When distributing Covered Code, include this CDDL HEADER in each
+# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
+# If applicable, add the following below this CDDL HEADER, with the
+# fields enclosed by brackets "[]" replaced with your own identifying
+# information: Portions Copyright [yyyy] [name of copyright owner]
+#
+# CDDL HEADER END
+#
+
+#
+# Copyright 2007 Sun Microsystems, Inc.  All rights reserved.
+# Use is subject to license terms.
+#
+
+#
+# Copyright (c) 2013 by Delphix. All rights reserved.
+#
+
+. $STF_SUITE/include/libtest.shlib
+
+default_setup_noexit ${DISKS%% *}
+log_pass
diff --git a/tests/zfs-tests/tests/functional/rootpool/Makefile.am b/tests/zfs-tests/tests/functional/rootpool/Makefile.am
new file mode 100644 (file)
index 0000000..9800fa0
--- /dev/null
@@ -0,0 +1,7 @@
+pkgdatadir = $(datadir)/@PACKAGE@/zfs-tests/tests/functional/rootpool
+dist_pkgdata_SCRIPTS = \
+       setup.ksh \
+       cleanup.ksh \
+       rootpool_002_neg.ksh \
+       rootpool_003_neg.ksh \
+       rootpool_007_neg.ksh
diff --git a/tests/zfs-tests/tests/functional/rootpool/cleanup.ksh b/tests/zfs-tests/tests/functional/rootpool/cleanup.ksh
new file mode 100755 (executable)
index 0000000..8f04325
--- /dev/null
@@ -0,0 +1,36 @@
+#!/bin/ksh -p
+#
+# CDDL HEADER START
+#
+# The contents of this file are subject to the terms of the
+# Common Development and Distribution License (the "License").
+# You may not use this file except in compliance with the License.
+#
+# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
+# or http://www.opensolaris.org/os/licensing.
+# See the License for the specific language governing permissions
+# and limitations under the License.
+#
+# When distributing Covered Code, include this CDDL HEADER in each
+# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
+# If applicable, add the following below this CDDL HEADER, with the
+# fields enclosed by brackets "[]" replaced with your own identifying
+# information: Portions Copyright [yyyy] [name of copyright owner]
+#
+# CDDL HEADER END
+#
+
+#
+# Copyright 2008 Sun Microsystems, Inc.  All rights reserved.
+# Use is subject to license terms.
+#
+
+#
+# Copyright (c) 2013 by Delphix. All rights reserved.
+#
+
+. $STF_SUITE/include/libtest.shlib
+
+verify_runnable "global"
+
+default_cleanup
diff --git a/tests/zfs-tests/tests/functional/rootpool/rootpool_002_neg.ksh b/tests/zfs-tests/tests/functional/rootpool/rootpool_002_neg.ksh
new file mode 100755 (executable)
index 0000000..1c66669
--- /dev/null
@@ -0,0 +1,68 @@
+#!/bin/ksh -p
+#
+# CDDL HEADER START
+#
+# The contents of this file are subject to the terms of the
+# Common Development and Distribution License (the "License").
+# You may not use this file except in compliance with the License.
+#
+# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
+# or http://www.opensolaris.org/os/licensing.
+# See the License for the specific language governing permissions
+# and limitations under the License.
+#
+# When distributing Covered Code, include this CDDL HEADER in each
+# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
+# If applicable, add the following below this CDDL HEADER, with the
+# fields enclosed by brackets "[]" replaced with your own identifying
+# information: Portions Copyright [yyyy] [name of copyright owner]
+#
+# CDDL HEADER END
+#
+
+#
+# Copyright 2009 Sun Microsystems, Inc.  All rights reserved.
+# Use is subject to license terms.
+#
+
+#
+# Copyright (c) 2013 by Delphix. All rights reserved.
+#
+
+. $STF_SUITE/include/libtest.shlib
+
+#
+# DESCRIPTION:
+#
+# the zfs rootpool can not be destroyed
+#
+# STRATEGY:
+# 1) check if the current system is installed as zfs root
+# 2) get the rootpool
+# 3) try to destroy the rootpool, which should fail.
+# 4) try to destroy the rootpool filesystem, which should fail.
+#
+
+verify_runnable "global"
+log_assert "zpool/zfs destory <rootpool> should return error"
+
+typeset rootpool=$(get_rootpool)
+typeset tmpfile="/tmp/mounted-datasets.$$"
+
+# Collect the currently mounted ZFS filesystems, so that we can repair any
+# damage done by the attempted pool destroy. The destroy itself should fail, but
+# some filesystems can become unmounted in the process, and aren't automatically
+# remounted.
+$MOUNT -p | $AWK '{if ($4 == "zfs") print $1" "$3}' > $tmpfile
+
+log_mustnot $ZPOOL destroy $rootpool
+
+# Remount any filesystems that the destroy attempt unmounted.
+while read ds mntpt; do
+       mounted $ds || log_must $MOUNT -Fzfs $ds $mntpt
+done < $tmpfile
+$RM -f $tmpfile
+
+log_mustnot $ZFS destroy $rootpool
+
+log_pass "rootpool can not be destroyed"
diff --git a/tests/zfs-tests/tests/functional/rootpool/rootpool_003_neg.ksh b/tests/zfs-tests/tests/functional/rootpool/rootpool_003_neg.ksh
new file mode 100755 (executable)
index 0000000..469e7ad
--- /dev/null
@@ -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.
+#
+
+#
+# Copyright (c) 2013 by Delphix. All rights reserved.
+#
+
+. $STF_SUITE/include/libtest.shlib
+
+#
+# DESCRIPTION:
+#
+#  system related filesystems can not be renamed or destroyed
+#
+# STRATEGY:
+#
+# 1) check if the current system is installed as zfs rootfs
+# 2) get the rootfs
+# 3) try to rename the rootfs to some newfs, which should fail.
+# 4) try to destroy the rootfs, which should fail.
+# 5) try to destroy the rootfs with -f which should fail
+# 6) try to destroy the rootfs with -fR which should fail
+#
+
+verify_runnable "global"
+log_assert "system related filesytems can not be renamed or destroyed"
+
+typeset rootpool=$(get_rootpool)
+typeset rootfs=$(get_rootfs)
+
+log_mustnot $ZFS rename $rootfs $rootpool/newfs
+log_mustnot $ZFS rename -f $rootfs $rootpool/newfs
+
+log_mustnot $ZFS destroy $rootfs
+log_mustnot $ZFS destroy -f $rootfs
+
+log_pass "system related filesystems can not be renamed or destroyed"
diff --git a/tests/zfs-tests/tests/functional/rootpool/rootpool_007_neg.ksh b/tests/zfs-tests/tests/functional/rootpool/rootpool_007_neg.ksh
new file mode 100755 (executable)
index 0000000..4f715d5
--- /dev/null
@@ -0,0 +1,70 @@
+#!/bin/ksh -p
+#
+# CDDL HEADER START
+#
+# The contents of this file are subject to the terms of the
+# Common Development and Distribution License (the "License").
+# You may not use this file except in compliance with the License.
+#
+# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
+# or http://www.opensolaris.org/os/licensing.
+# See the License for the specific language governing permissions
+# and limitations under the License.
+#
+# When distributing Covered Code, include this CDDL HEADER in each
+# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
+# If applicable, add the following below this CDDL HEADER, with the
+# fields enclosed by brackets "[]" replaced with your own identifying
+# information: Portions Copyright [yyyy] [name of copyright owner]
+#
+# CDDL HEADER END
+#
+
+#
+# Copyright 2008 Sun Microsystems, Inc.  All rights reserved.
+# Use is subject to license terms.
+#
+
+#
+# Copyright (c) 2013 by Delphix. All rights reserved.
+#
+
+. $STF_SUITE/include/libtest.shlib
+
+#
+# DESCRIPTION:
+#
+# the zfs rootfilesystem's compression property can not set to gzip[1-9]
+#
+# STRATEGY:
+# 1) check if the current system is installed as zfs root
+# 2) get the rootfs
+# 3) set the rootfs's compression to gzip 1-9 which should fail.
+#
+
+verify_runnable "global"
+
+function cleanup {
+       log_must $ZFS set compression=$orig_compress $rootfs
+}
+
+log_onexit cleanup
+log_assert $assert_msg
+
+typeset rootpool=$(get_rootpool)
+typeset rootfs=$(get_pool_prop bootfs $rootpool)
+typeset orig_compress=$(get_prop compression $rootfs)
+
+typeset assert_msg="the zfs rootfs's compression property can not set to \
+                  gzip and gzip[1-9]"
+
+set -A gtype "gzip" "gzip-1" "gzip-2" "gzip-3" "gzip-4" "gzip-5" \
+            "gzip-6" "gzip-7" "gzip-8" "gzip-9"
+
+typeset -i i=0
+while (( i < ${#gtype[@]} )); do
+       log_mustnot $ZFS set compression=${gtype[i]} $rootfs
+       (( i += 1 ))
+done
+
+log_pass $assert_msg
diff --git a/tests/zfs-tests/tests/functional/rootpool/setup.ksh b/tests/zfs-tests/tests/functional/rootpool/setup.ksh
new file mode 100755 (executable)
index 0000000..a5baac5
--- /dev/null
@@ -0,0 +1,34 @@
+#!/bin/ksh -p
+#
+# CDDL HEADER START
+#
+# The contents of this file are subject to the terms of the
+# Common Development and Distribution License (the "License").
+# You may not use this file except in compliance with the License.
+#
+# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
+# or http://www.opensolaris.org/os/licensing.
+# See the License for the specific language governing permissions
+# and limitations under the License.
+#
+# When distributing Covered Code, include this CDDL HEADER in each
+# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
+# If applicable, add the following below this CDDL HEADER, with the
+# fields enclosed by brackets "[]" replaced with your own identifying
+# information: Portions Copyright [yyyy] [name of copyright owner]
+#
+# CDDL HEADER END
+#
+
+#
+# Copyright 2008 Sun Microsystems, Inc.  All rights reserved.
+# Use is subject to license terms.
+#
+
+#
+# Copyright (c) 2013 by Delphix. All rights reserved.
+#
+
+. $STF_SUITE/include/libtest.shlib
+
+verify_runnable "global"
diff --git a/tests/zfs-tests/tests/functional/rsend/Makefile.am b/tests/zfs-tests/tests/functional/rsend/Makefile.am
new file mode 100644 (file)
index 0000000..6be0000
--- /dev/null
@@ -0,0 +1,25 @@
+pkgdatadir = $(datadir)/@PACKAGE@/zfs-tests/tests/functional/rsend
+dist_pkgdata_SCRIPTS = \
+       rsend.cfg \
+       rsend.kshlib \
+       setup.ksh \
+       cleanup.ksh \
+       rsend_001_pos.ksh \
+       rsend_002_pos.ksh \
+       rsend_003_pos.ksh \
+       rsend_004_pos.ksh \
+       rsend_005_pos.ksh \
+       rsend_006_pos.ksh \
+       rsend_007_pos.ksh \
+       rsend_008_pos.ksh \
+       rsend_009_pos.ksh \
+       rsend_010_pos.ksh \
+       rsend_011_pos.ksh \
+       rsend_012_pos.ksh \
+       rsend_013_pos.ksh \
+       rsend_014_pos.ksh \
+       rsend_019_pos.ksh \
+       rsend_020_pos.ksh \
+       rsend_021_pos.ksh \
+       rsend_022_pos.ksh \
+       rsend_024_pos.ksh
diff --git a/tests/zfs-tests/tests/functional/rsend/cleanup.ksh b/tests/zfs-tests/tests/functional/rsend/cleanup.ksh
new file mode 100755 (executable)
index 0000000..6787660
--- /dev/null
@@ -0,0 +1,45 @@
+#!/bin/ksh -p
+#
+# CDDL HEADER START
+#
+# The contents of this file are subject to the terms of the
+# Common Development and Distribution License (the "License").
+# You may not use this file except in compliance with the License.
+#
+# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
+# or http://www.opensolaris.org/os/licensing.
+# See the License for the specific language governing permissions
+# and limitations under the License.
+#
+# When distributing Covered Code, include this CDDL HEADER in each
+# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
+# If applicable, add the following below this CDDL HEADER, with the
+# fields enclosed by brackets "[]" replaced with your own identifying
+# information: Portions Copyright [yyyy] [name of copyright owner]
+#
+# CDDL HEADER END
+#
+
+#
+# Copyright 2009 Sun Microsystems, Inc.  All rights reserved.
+# Use is subject to license terms.
+#
+
+#
+# Copyright (c) 2013, 2014 by Delphix. All rights reserved.
+#
+
+. $STF_SUITE/tests/functional/rsend/rsend.kshlib
+
+verify_runnable "both"
+
+if is_global_zone ; then
+       destroy_pool $POOL
+       destroy_pool $POOL2
+else
+       cleanup_pool $POOL
+       cleanup_pool $POOL2
+fi
+log_must $RM -rf $BACKDIR $TESTDIR
+
+log_pass
diff --git a/tests/zfs-tests/tests/functional/rsend/rsend.cfg b/tests/zfs-tests/tests/functional/rsend/rsend.cfg
new file mode 100644 (file)
index 0000000..2430407
--- /dev/null
@@ -0,0 +1,37 @@
+#
+# CDDL HEADER START
+#
+# The contents of this file are subject to the terms of the
+# Common Development and Distribution License (the "License").
+# You may not use this file except in compliance with the License.
+#
+# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
+# or http://www.opensolaris.org/os/licensing.
+# See the License for the specific language governing permissions
+# and limitations under the License.
+#
+# When distributing Covered Code, include this CDDL HEADER in each
+# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
+# If applicable, add the following below this CDDL HEADER, with the
+# fields enclosed by brackets "[]" replaced with your own identifying
+# information: Portions Copyright [yyyy] [name of copyright owner]
+#
+# CDDL HEADER END
+#
+
+#
+# Copyright 2008 Sun Microsystems, Inc.  All rights reserved.
+#
+
+#
+# Copyright (c) 2013 by Delphix. All rights reserved.
+#
+
+export BACKDIR=${TEST_BASE_DIR%%/}/backdir-rsend
+
+export DISK1=$($ECHO $DISKS | $AWK '{print $1}')
+export DISK2=$($ECHO $DISKS | $AWK '{print $2}')
+
+export POOL=$TESTPOOL
+export POOL2=$TESTPOOL1
+export FS=$TESTFS
diff --git a/tests/zfs-tests/tests/functional/rsend/rsend.kshlib b/tests/zfs-tests/tests/functional/rsend/rsend.kshlib
new file mode 100644 (file)
index 0000000..46f96fa
--- /dev/null
@@ -0,0 +1,551 @@
+#
+# CDDL HEADER START
+#
+# The contents of this file are subject to the terms of the
+# Common Development and Distribution License (the "License").
+# You may not use this file except in compliance with the License.
+#
+# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
+# or http://www.opensolaris.org/os/licensing.
+# See the License for the specific language governing permissions
+# and limitations under the License.
+#
+# When distributing Covered Code, include this CDDL HEADER in each
+# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
+# If applicable, add the following below this CDDL HEADER, with the
+# fields enclosed by brackets "[]" replaced with your own identifying
+# information: Portions Copyright [yyyy] [name of copyright owner]
+#
+# CDDL HEADER END
+#
+
+#
+# Copyright 2009 Sun Microsystems, Inc.  All rights reserved.
+# Use is subject to license terms.
+#
+
+#
+# Copyright (c) 2013, 2015 by Delphix. All rights reserved.
+#
+
+. $STF_SUITE/include/libtest.shlib
+. $STF_SUITE/tests/functional/rsend/rsend.cfg
+
+#
+# Set up test model which includes various datasets
+#
+#               @final
+#               @snapB
+#               @init
+#               |
+#   ______ pclone
+#  |      /
+#  |@psnap
+#  ||                         @final
+#  ||@final       @final      @snapC
+#  ||@snapC       @snapC      @snapB
+#  ||@snapA       @snapB      @snapA
+#  ||@init        @init       @init
+#  |||            |           |
+# $pool -------- $FS ------- fs1 ------- fs2
+#    \             \\_____     \          |
+#     vol           vol   \____ \         @fsnap
+#      |              |        \ \              \
+#      @init          @vsnap   |  ------------ fclone
+#      @snapA         @init \  |                    |
+#      @final         @snapB \ |                    @init
+#                     @snapC  vclone                @snapA
+#                     @final       |                @final
+#                                 @init
+#                                 @snapC
+#                                 @final
+#
+# $1 pool name
+#
+function setup_test_model
+{
+       typeset pool=$1
+
+       log_must $ZFS create -p $pool/$FS/fs1/fs2
+
+       log_must $ZFS snapshot $pool@psnap
+       log_must $ZFS clone $pool@psnap $pool/pclone
+
+       if is_global_zone ; then
+               log_must $ZFS create -V 16M $pool/vol
+               log_must $ZFS create -V 16M $pool/$FS/vol
+
+               log_must $ZFS snapshot $pool/$FS/vol@vsnap
+               log_must $ZFS clone $pool/$FS/vol@vsnap $pool/$FS/vclone
+       fi
+
+       log_must snapshot_tree $pool/$FS/fs1/fs2@fsnap
+       log_must $ZFS clone $pool/$FS/fs1/fs2@fsnap $pool/$FS/fs1/fclone
+       log_must $ZFS snapshot -r $pool@init
+
+       log_must snapshot_tree $pool@snapA
+       log_must snapshot_tree $pool@snapC
+       log_must snapshot_tree $pool/pclone@snapB
+       log_must snapshot_tree $pool/$FS@snapB
+       log_must snapshot_tree $pool/$FS@snapC
+       log_must snapshot_tree $pool/$FS/fs1@snapA
+       log_must snapshot_tree $pool/$FS/fs1@snapB
+       log_must snapshot_tree $pool/$FS/fs1@snapC
+       log_must snapshot_tree $pool/$FS/fs1/fclone@snapA
+
+       if is_global_zone ; then
+               log_must $ZFS snapshot $pool/vol@snapA
+               log_must $ZFS snapshot $pool/$FS/vol@snapB
+               log_must $ZFS snapshot $pool/$FS/vol@snapC
+               log_must $ZFS snapshot $pool/$FS/vclone@snapC
+       fi
+
+       log_must $ZFS snapshot -r $pool@final
+
+       return 0
+}
+
+#
+# Cleanup the BACKDIR and given pool content and all the sub datasets
+#
+# $1 pool name
+#
+function cleanup_pool
+{
+       typeset pool=$1
+       log_must $RM -rf $BACKDIR/*
+
+       if is_global_zone ; then
+               log_must $ZFS destroy -Rf $pool
+       else
+               typeset list=$($ZFS list -H -r -t filesystem,snapshot,volume -o name $pool)
+               for ds in $list ; do
+                       if [[ $ds != $pool ]] ; then
+                               if datasetexists $ds ; then
+                                       log_must $ZFS destroy -Rf $ds
+                               fi
+                       fi
+               done
+       fi
+
+       typeset mntpnt=$(get_prop mountpoint $pool)
+       if ! ismounted $pool ; then
+               # Make sure mountpoint directory is empty
+               if [[ -d $mntpnt ]]; then
+                       log_must $RM -rf $mntpnt/*
+               fi
+
+               log_must $ZFS mount $pool
+       fi
+       if [[ -d $mntpnt ]]; then
+               log_must $RM -rf $mntpnt/*
+       fi
+
+       return 0
+}
+
+#
+# Detect if the given two filesystems have same sub-datasets
+#
+# $1 source filesystem
+# $2 destination filesystem
+#
+function cmp_ds_subs
+{
+       typeset src_fs=$1
+       typeset dst_fs=$2
+
+       $ZFS list -r -H -t filesystem,snapshot,volume -o name $src_fs > $BACKDIR/src1
+       $ZFS list -r -H -t filesystem,snapshot,volume -o name $dst_fs > $BACKDIR/dst1
+
+       eval $SED -e 's:^$src_fs:PREFIX:g' < $BACKDIR/src1 > $BACKDIR/src
+       eval $SED -e 's:^$dst_fs:PREFIX:g' < $BACKDIR/dst1 > $BACKDIR/dst
+
+       $DIFF $BACKDIR/src $BACKDIR/dst
+       typeset -i ret=$?
+
+       $RM -f $BACKDIR/src $BACKDIR/dst $BACKDIR/src1 $BACKDIR/dst1
+
+       return $ret
+}
+
+#
+# Compare all the directores and files in two filesystems
+#
+# $1 source filesystem
+# $2 destination filesystem
+#
+function cmp_ds_cont
+{
+       typeset src_fs=$1
+       typeset dst_fs=$2
+
+       typeset srcdir dstdir
+       srcdir=$(get_prop mountpoint $src_fs)
+       dstdir=$(get_prop mountpoint $dst_fs)
+
+       $DIFF -r $srcdir $dstdir > /dev/null 2>&1
+       echo $?
+}
+
+#
+# Compare the given two dataset properties
+#
+# $1 dataset 1
+# $2 dataset 2
+#
+function cmp_ds_prop
+{
+       typeset dtst1=$1
+       typeset dtst2=$2
+
+       for item in "type" "origin" "volblocksize" "aclinherit" "aclmode" \
+           "atime" "canmount" "checksum" "compression" "copies" "devices" \
+           "exec" "quota" "readonly" "recordsize" "reservation" "setuid" \
+           "sharenfs" "snapdir" "version" "volsize" "xattr" "zoned" \
+           "mountpoint";
+       do
+               $ZFS get -H -o property,value,source $item $dtst1 >> \
+                   $BACKDIR/dtst1
+               $ZFS get -H -o property,value,source $item $dtst2 >> \
+                   $BACKDIR/dtst2
+       done
+
+       eval $SED -e 's:$dtst1:PREFIX:g' < $BACKDIR/dtst1 > $BACKDIR/dtst1
+       eval $SED -e 's:$dtst2:PREFIX:g' < $BACKDIR/dtst2 > $BACKDIR/dtst2
+
+       $DIFF $BACKDIR/dtst1 $BACKDIR/dtst2
+       typeset -i ret=$?
+
+       $RM -f $BACKDIR/dtst1 $BACKDIR/dtst2
+
+       return $ret
+
+}
+
+#
+# Random create directories and files
+#
+# $1 directory
+#
+function random_tree
+{
+       typeset dir=$1
+
+       if [[ -d $dir ]]; then
+               $RM -rf $dir
+       fi
+       $MKDIR -p $dir
+       typeset -i ret=$?
+
+       typeset -i nl nd nf
+       ((nl = RANDOM % 6 + 1))
+       ((nd = RANDOM % 3 ))
+       ((nf = RANDOM % 5 ))
+       $MKTREE -b $dir -l $nl -d $nd -f $nf
+       ((ret |= $?))
+
+       return $ret
+}
+
+#
+# Put data in filesystem and take snapshot
+#
+# $1 snapshot name
+#
+function snapshot_tree
+{
+       typeset snap=$1
+       typeset ds=${snap%%@*}
+       typeset type=$(get_prop "type" $ds)
+
+       typeset -i ret=0
+       if [[ $type == "filesystem" ]]; then
+               typeset mntpnt=$(get_prop mountpoint $ds)
+               ((ret |= $?))
+
+               if ((ret == 0)) ; then
+                       eval random_tree $mntpnt/${snap##$ds}
+                       ((ret |= $?))
+               fi
+       fi
+
+       if ((ret == 0)) ; then
+               $ZFS snapshot $snap
+               ((ret |= $?))
+       fi
+
+       return $ret
+}
+
+#
+# Destroy the given snapshot and stuff
+#
+# $1 snapshot
+#
+function destroy_tree
+{
+       typeset -i ret=0
+       typeset snap
+       for snap in "$@" ; do
+               $ZFS destroy $snap
+               ret=$?
+
+               typeset ds=${snap%%@*}
+               typeset type=$(get_prop "type" $ds)
+               if [[ $type == "filesystem" ]]; then
+                       typeset mntpnt=$(get_prop mountpoint $ds)
+                       ((ret |= $?))
+
+                       if ((ret != 0)); then
+                               $RM -r $mntpnt/$snap
+                               ((ret |= $?))
+                       fi
+               fi
+
+               if ((ret != 0)); then
+                       return $ret
+               fi
+       done
+
+       return 0
+}
+
+#
+# Get all the sub-datasets of give dataset with specific suffix
+#
+# $1 Given dataset
+# $2 Suffix
+#
+function getds_with_suffix
+{
+       typeset ds=$1
+       typeset suffix=$2
+
+       typeset list=$($ZFS list -r -H -t filesystem,snapshot,volume -o name $ds \
+           | $GREP "$suffix$")
+
+       $ECHO $list
+}
+
+#
+# Output inherited properties whitch is edited for file system
+#
+function fs_inherit_prop
+{
+       typeset fs_prop
+       if is_global_zone ; then
+               fs_prop=$($ZFS inherit 2>&1 | \
+                   $AWK '$2=="YES" && $3=="YES" {print $1}')
+               if ! is_te_enabled ; then
+                       fs_prop=$(echo $fs_prop | $GREP -v "mlslabel")
+               fi
+       else
+               fs_prop=$($ZFS inherit 2>&1 | \
+                   $AWK '$2=="YES" && $3=="YES" {print $1}'|
+                   $EGREP -v "devices|mlslabel|sharenfs|sharesmb|zoned")
+       fi
+
+       $ECHO $fs_prop
+}
+
+#
+# Output inherited properties for volume
+#
+function vol_inherit_prop
+{
+       $ECHO "checksum readonly"
+}
+
+#
+# Get the destination dataset to compare
+#
+function get_dst_ds
+{
+       typeset srcfs=$1
+       typeset dstfs=$2
+
+       #
+       # If the srcfs is not pool
+       #
+       if ! $ZPOOL list $srcfs > /dev/null 2>&1 ; then
+               eval dstfs="$dstfs/${srcfs#*/}"
+       fi
+
+       $ECHO $dstfs
+}
+
+#
+# Make test files
+#
+# $1 Number of files to create
+# $2 Maximum file size
+# $3 File ID offset
+# $4 File system to create the files on
+#
+function mk_files
+{
+       nfiles=$1
+       maxsize=$2
+       file_id_offset=$3
+       fs=$4
+
+       for ((i=0; i<$nfiles; i=i+1)); do
+               $DD if=/dev/urandom \
+                   of=/$fs/file-$maxsize-$((i+$file_id_offset)) \
+                   bs=$(($RANDOM * $RANDOM % $maxsize)) \
+                   count=1 >/dev/null 2>&1 || log_fail \
+                   "Failed to create /$fs/file-$maxsize-$((i+$file_id_offset))"
+       done
+       $ECHO Created $nfiles files of random sizes up to $maxsize bytes
+}
+
+#
+# Remove test files
+#
+# $1 Number of files to remove
+# $2 Maximum file size
+# $3 File ID offset
+# $4 File system to remove the files from
+#
+function rm_files
+{
+       nfiles=$1
+       maxsize=$2
+       file_id_offset=$3
+       fs=$4
+
+       for ((i=0; i<$nfiles; i=i+1)); do
+               $RM -f /$fs/file-$maxsize-$((i+$file_id_offset))
+       done
+       $ECHO Removed $nfiles files of random sizes up to $maxsize bytes
+}
+
+#
+# Mess up file contents
+#
+# $1 The file path
+#
+function mess_file
+{
+       file=$1
+
+       filesize=$($STAT -c '%s' $file)
+       offset=$(($RANDOM * $RANDOM % $filesize))
+       if (($RANDOM % 7 <= 1)); then
+               #
+               # We corrupt 2 bytes to minimize the chance that we
+               # write the same value that's already there.
+               #
+               log_must eval "$DD if=/dev/urandom of=$file conv=notrunc " \
+                   "bs=1 count=2 oseek=$offset >/dev/null 2>&1"
+       else
+               log_must $TRUNCATE -s $offset $file
+       fi
+}
+
+#
+# Diff the send/receive filesystems
+#
+# $1 The sent filesystem
+# $2 The received filesystem
+#
+function file_check
+{
+       sendfs=$1
+       recvfs=$2
+
+       if [[ -d /$recvfs/.zfs/snapshot/a && -d \
+           /$sendfs/.zfs/snapshot/a ]]; then
+               $DIFF -r /$recvfs/.zfs/snapshot/a /$sendfs/.zfs/snapshot/a
+               [[ $? -eq 0 ]] || log_fail "Differences found in snap a"
+       fi
+       if [[ -d /$recvfs/.zfs/snapshot/b && -d \
+           /$sendfs/.zfs/snapshot/b ]]; then
+               $DIFF -r /$recvfs/.zfs/snapshot/b /$sendfs/.zfs/snapshot/b
+               [[ $? -eq 0 ]] || log_fail "Differences found in snap b"
+       fi
+}
+
+#
+# Resume test helper
+#
+# $1 The ZFS send command
+# $2 The filesystem where the streams are sent
+# $3 The receive filesystem
+#
+function resume_test
+{
+       sendcmd=$1
+       streamfs=$2
+       recvfs=$3
+
+       stream_num=1
+       log_must eval "$sendcmd >/$streamfs/$stream_num"
+
+       for ((i=0; i<2; i=i+1)); do
+               mess_file /$streamfs/$stream_num
+               log_mustnot $ZFS recv -sv $recvfs </$streamfs/$stream_num
+               stream_num=$((stream_num+1))
+
+               token=$($ZFS get -Hp -o value receive_resume_token $recvfs)
+               log_must eval "$ZFS send -v -t $token >/$streamfs/$stream_num"
+               [[ -f /$streamfs/$stream_num ]] || \
+                   log_fail "NO FILE /$streamfs/$stream_num"
+       done
+       log_must $ZFS recv -sv $recvfs </$streamfs/$stream_num
+}
+
+#
+# Setup filesystems for the resumable send/receive tests
+#
+# $1 The pool to set up with the "send" filesystems
+# $2 The pool for receive
+#
+function test_fs_setup
+{
+       sendpool=$1
+       recvpool=$2
+
+       sendfs=$sendpool/sendfs
+       recvfs=$recvpool/recvfs
+       streamfs=$sendpool/stream
+
+       if datasetexists $recvfs; then
+               log_must $ZFS destroy -r $recvfs
+       fi
+       if datasetexists $sendfs; then
+               log_must $ZFS destroy -r $sendfs
+       fi
+       if $($ZFS create -o compress=lz4 $sendfs); then
+               mk_files 1000 256 0 $sendfs &
+               mk_files 1000 131072 0 $sendfs &
+               mk_files 100 1048576 0 $sendfs &
+               mk_files 10 10485760 0 $sendfs &
+               mk_files 1 104857600 0 $sendfs &
+               log_must $WAIT
+               log_must $ZFS snapshot $sendfs@a
+
+               rm_files 200 256 0 $sendfs &
+               rm_files 200 131072 0 $sendfs &
+               rm_files 20 1048576 0 $sendfs &
+               rm_files 2 10485760 0 $sendfs &
+               log_must $WAIT
+
+               mk_files 400 256 0 $sendfs &
+               mk_files 400 131072 0 $sendfs &
+               mk_files 40 1048576 0 $sendfs &
+               mk_files 4 10485760 0 $sendfs &
+               log_must $WAIT
+
+               log_must $ZFS snapshot $sendfs@b
+               log_must eval "$ZFS send -v $sendfs@a >/$sendpool/initial.zsend"
+               log_must eval "$ZFS send -v -i @a $sendfs@b " \
+                   ">/$sendpool/incremental.zsend"
+       fi
+
+       if datasetexists $streamfs; then
+               log_must $ZFS destroy -r $streamfs
+       fi
+       log_must $ZFS create -o compress=lz4 $sendpool/stream
+}
diff --git a/tests/zfs-tests/tests/functional/rsend/rsend_001_pos.ksh b/tests/zfs-tests/tests/functional/rsend/rsend_001_pos.ksh
new file mode 100755 (executable)
index 0000000..6087dd3
--- /dev/null
@@ -0,0 +1,73 @@
+#!/bin/ksh -p
+#
+# CDDL HEADER START
+#
+# The contents of this file are subject to the terms of the
+# Common Development and Distribution License (the "License").
+# You may not use this file except in compliance with the License.
+#
+# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
+# or http://www.opensolaris.org/os/licensing.
+# See the License for the specific language governing permissions
+# and limitations under the License.
+#
+# When distributing Covered Code, include this CDDL HEADER in each
+# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
+# If applicable, add the following below this CDDL HEADER, with the
+# fields enclosed by brackets "[]" replaced with your own identifying
+# information: Portions Copyright [yyyy] [name of copyright owner]
+#
+# CDDL HEADER END
+#
+
+#
+# Copyright 2008 Sun Microsystems, Inc.  All rights reserved.
+# Use is subject to license terms.
+#
+
+#
+# Copyright (c) 2013 by Delphix. All rights reserved.
+#
+
+. $STF_SUITE/tests/functional/rsend/rsend.kshlib
+
+#
+# DESCRIPTION:
+#      zfs send -R send replication stream up to the named snap.
+#
+# STRATEGY:
+#      1. Back up all the data from POOL/FS
+#      2. Verify all the datasets and data can be recovered in POOL2
+#      3. Back up all the data from root filesystem POOL2
+#      4. Verify all the data can be recovered, too
+#
+
+verify_runnable "both"
+
+log_assert "zfs send -R send replication stream up to the named snap."
+log_onexit cleanup_pool $POOL2
+
+#
+# Verify the entire pool and sub-ds can be backup and restored.
+#
+log_must eval "$ZFS send -R $POOL@final > $BACKDIR/pool-final-R"
+log_must eval "$ZFS receive -d -F $POOL2 < $BACKDIR/pool-final-R"
+
+dstds=$(get_dst_ds $POOL $POOL2)
+log_must cmp_ds_subs $POOL $dstds
+log_must cmp_ds_cont $POOL $dstds
+
+# Cleanup POOL2
+log_must cleanup_pool $POOL2
+
+#
+# Verify all the filesystem and sub-fs can be backup and restored.
+#
+log_must eval "$ZFS send -R $POOL/$FS@final > $BACKDIR/fs-final-R"
+log_must eval "$ZFS receive -d $POOL2 < $BACKDIR/fs-final-R"
+
+dstds=$(get_dst_ds $POOL/$FS $POOL2)
+log_must cmp_ds_subs $POOL/$FS $dstds
+log_must cmp_ds_cont $POOL/$FS $dstds
+
+log_pass "zfs send -R send replication stream up to the named snap."
diff --git a/tests/zfs-tests/tests/functional/rsend/rsend_002_pos.ksh b/tests/zfs-tests/tests/functional/rsend/rsend_002_pos.ksh
new file mode 100755 (executable)
index 0000000..9a495d3
--- /dev/null
@@ -0,0 +1,93 @@
+#!/bin/ksh -p
+#
+# CDDL HEADER START
+#
+# The contents of this file are subject to the terms of the
+# Common Development and Distribution License (the "License").
+# You may not use this file except in compliance with the License.
+#
+# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
+# or http://www.opensolaris.org/os/licensing.
+# See the License for the specific language governing permissions
+# and limitations under the License.
+#
+# When distributing Covered Code, include this CDDL HEADER in each
+# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
+# If applicable, add the following below this CDDL HEADER, with the
+# fields enclosed by brackets "[]" replaced with your own identifying
+# information: Portions Copyright [yyyy] [name of copyright owner]
+#
+# CDDL HEADER END
+#
+
+#
+# Copyright 2008 Sun Microsystems, Inc.  All rights reserved.
+# Use is subject to license terms.
+#
+
+#
+# Copyright (c) 2013 by Delphix. All rights reserved.
+#
+
+. $STF_SUITE/tests/functional/rsend/rsend.kshlib
+
+#
+# DESCRIPTION:
+#      zfs send -I sends all incrementals from fs@init to fs@final.
+#
+# STRATEGY:
+#      1. Create several snapshots in pool2
+#      2. Send -I @snapA @final
+#      3. Destroy all the snapshot except @snapA
+#      4. Make sure all the snapshots and content are recovered
+#
+
+verify_runnable "both"
+
+log_assert "zfs send -I sends all incrementals from fs@init to fs@final."
+log_onexit cleanup_pool $POOL2
+
+#
+# Duplicate POOL2
+#
+log_must eval "$ZFS send -R $POOL@final > $BACKDIR/pool-R"
+log_must eval "$ZFS receive -d -F $POOL2 < $BACKDIR/pool-R"
+
+if is_global_zone ; then
+       #
+       # Verify send -I will backup all the incrementals in pool
+       #
+       log_must eval "$ZFS send -I $POOL2@init $POOL2@final > " \
+               "$BACKDIR/pool-init-final-I"
+       log_must destroy_tree $POOL2@final $POOL2@snapC $POOL2@snapA
+       log_must eval "$ZFS receive -d -F $POOL2 < $BACKDIR/pool-init-final-I"
+       log_must cmp_ds_subs $POOL $POOL2
+       log_must cmp_ds_cont $POOL $POOL2
+fi
+
+dstds=$(get_dst_ds $POOL $POOL2)
+
+#
+# Verify send -I will backup all the incrementals in filesystem
+#
+log_must eval "$ZFS send -I @init $dstds/$FS@final > $BACKDIR/fs-init-final-I"
+log_must destroy_tree $dstds/$FS@final $dstds/$FS@snapC $dstds/$FS@snapB
+log_must eval "$ZFS receive -d -F $dstds < $BACKDIR/fs-init-final-I"
+log_must cmp_ds_subs $POOL $dstds
+log_must cmp_ds_cont $POOL $dstds
+
+if is_global_zone ; then
+       #
+       # Verify send -I will backup all the incrementals in volume
+       #
+       dataset=$POOL2/$FS/vol
+       log_must eval "$ZFS send -I @vsnap $dataset@final > " \
+               "$BACKDIR/vol-vsnap-final-I"
+       log_must destroy_tree $dataset@final $dataset@snapC  \
+               $dataset@snapB $dataset@init
+       log_must eval "$ZFS receive -d -F $POOL2 < $BACKDIR/vol-vsnap-final-I"
+       log_must cmp_ds_subs $POOL $POOL2
+       log_must cmp_ds_cont $POOL $POOL2
+fi
+
+log_pass "zfs send -I sends all incrementals from fs@init to fs@final."
diff --git a/tests/zfs-tests/tests/functional/rsend/rsend_003_pos.ksh b/tests/zfs-tests/tests/functional/rsend/rsend_003_pos.ksh
new file mode 100755 (executable)
index 0000000..85d789d
--- /dev/null
@@ -0,0 +1,95 @@
+#!/bin/ksh -p
+#
+# CDDL HEADER START
+#
+# The contents of this file are subject to the terms of the
+# Common Development and Distribution License (the "License").
+# You may not use this file except in compliance with the License.
+#
+# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
+# or http://www.opensolaris.org/os/licensing.
+# See the License for the specific language governing permissions
+# and limitations under the License.
+#
+# When distributing Covered Code, include this CDDL HEADER in each
+# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
+# If applicable, add the following below this CDDL HEADER, with the
+# fields enclosed by brackets "[]" replaced with your own identifying
+# information: Portions Copyright [yyyy] [name of copyright owner]
+#
+# CDDL HEADER END
+#
+
+#
+# Copyright 2008 Sun Microsystems, Inc.  All rights reserved.
+# Use is subject to license terms.
+#
+
+#
+# Copyright (c) 2013 by Delphix. All rights reserved.
+#
+
+. $STF_SUITE/tests/functional/rsend/rsend.kshlib
+
+#
+# DESCRIPTION:
+#      zfs send -I dataset@init to clone@snap can create a clone
+#
+# STRATEGY:
+#      1. Setup test model
+#      2. send -I pool@init to clone@snap
+#      3. Verify the clone and snapshot can be recovered via receive
+#      4. Verify the similar operating in filesystem and volume
+#
+
+verify_runnable "both"
+
+log_assert "zfs send -I send all incrementals from dataset@init to clone@snap"
+log_onexit cleanup_pool $POOL2
+
+#
+# Duplicate POOL2
+#
+log_must eval "$ZFS send -R $POOL@final > $BACKDIR/pool-R"
+log_must eval "$ZFS receive -d -F $POOL2 < $BACKDIR/pool-R"
+
+if is_global_zone ; then
+       #
+       # Verify send -I backup all incrementals from pool
+       #
+       log_must eval "$ZFS send -I $POOL2@psnap $POOL2/pclone@final > " \
+               "$BACKDIR/pool-clone-I"
+       log_must $ZFS destroy -rf $POOL2/pclone
+       log_must eval "$ZFS receive -d -F $POOL2 < $BACKDIR/pool-clone-I"
+       log_must cmp_ds_subs $POOL $POOL2
+       log_must cmp_ds_cont $POOL $POOL2
+fi
+
+dstds=$(get_dst_ds $POOL $POOL2)
+
+#
+# Verify send -I backup all incrementals from filesystem
+#
+ds=$dstds/$FS/fs1
+log_must eval "$ZFS send -I $ds/fs2@fsnap $ds/fclone@final > " \
+       "$BACKDIR/fs-clone-I"
+log_must $ZFS destroy -rf $ds/fclone
+log_must eval "$ZFS receive -F $ds/fclone < $BACKDIR/fs-clone-I"
+
+log_must cmp_ds_subs $POOL $dstds
+log_must cmp_ds_cont $POOL $dstds
+
+if is_global_zone ; then
+       #
+       # Verify send -I backup all incrementals from volume
+       #
+       ds=$POOL2/$FS
+       log_must eval "$ZFS send -I $ds/vol@vsnap $ds/vclone@final > " \
+               "$BACKDIR/vol-clone-I"
+       log_must $ZFS destroy -rf $ds/vclone
+       log_must eval "$ZFS receive -d -F $POOL2 < $BACKDIR/vol-clone-I"
+       log_must cmp_ds_subs $POOL $POOL2
+       log_must cmp_ds_cont $POOL $POOL2
+fi
+
+log_pass "zfs send -I send all incrementals from dataset@init to clone@snap"
diff --git a/tests/zfs-tests/tests/functional/rsend/rsend_004_pos.ksh b/tests/zfs-tests/tests/functional/rsend/rsend_004_pos.ksh
new file mode 100755 (executable)
index 0000000..18cdac3
--- /dev/null
@@ -0,0 +1,120 @@
+#!/bin/ksh -p
+#
+# CDDL HEADER START
+#
+# The contents of this file are subject to the terms of the
+# Common Development and Distribution License (the "License").
+# You may not use this file except in compliance with the License.
+#
+# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
+# or http://www.opensolaris.org/os/licensing.
+# See the License for the specific language governing permissions
+# and limitations under the License.
+#
+# When distributing Covered Code, include this CDDL HEADER in each
+# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
+# If applicable, add the following below this CDDL HEADER, with the
+# fields enclosed by brackets "[]" replaced with your own identifying
+# information: Portions Copyright [yyyy] [name of copyright owner]
+#
+# CDDL HEADER END
+#
+
+#
+# Copyright 2008 Sun Microsystems, Inc.  All rights reserved.
+# Use is subject to license terms.
+#
+
+#
+# Copyright (c) 2013 by Delphix. All rights reserved.
+#
+
+. $STF_SUITE/tests/functional/rsend/rsend.kshlib
+
+#
+# DESCRIPTION:
+#      zfs send -R -i send incremental from fs@init to fs@final.
+#
+# STRATEGY:
+#      1. Create a set of snapshots and fill with data.
+#      2. Create sub filesystems.
+#      3. Create final snapshot
+#      4. Verify zfs send -R -i will backup all the datasets which has
+#         snapshot suffix @final
+#
+
+verify_runnable "both"
+
+log_assert "zfs send -R -i send incremental from fs@init to fs@final."
+log_onexit cleanup_pool $POOL2
+
+#
+# Duplicate POOL2 for testing
+#
+log_must eval "$ZFS send -R $POOL@final > $BACKDIR/pool-final-R"
+log_must eval "$ZFS receive -d -F $POOL2 < $BACKDIR/pool-final-R"
+
+if is_global_zone ; then
+       #
+       # Testing send -R -i backup from pool
+       #
+       srclist=$(getds_with_suffix $POOL2 @final)
+       interlist="$srclist $(getds_with_suffix $POOL2 @snapC)"
+       interlist="$interlist $(getds_with_suffix $POOL2 @snapB)"
+       interlist="$interlist $(getds_with_suffix $POOL2 @snapA)"
+
+       log_must eval "$ZFS send -R -i @init $POOL2@final > " \
+               "$BACKDIR/pool-init-final-iR"
+       log_must destroy_tree $interlist
+       log_must eval "$ZFS receive -d -F $POOL2 < $BACKDIR/pool-init-final-iR"
+
+       # Get current datasets with suffix @final
+       dstlist=$(getds_with_suffix $POOL2 @final)
+       if [[ $srclist != $dstlist ]]; then
+               log_fail "Unexpected: srclist($srclist) != dstlist($dstlist)"
+       fi
+       log_must cmp_ds_cont $POOL $POOL2
+fi
+
+dstds=$(get_dst_ds $POOL $POOL2)
+#
+# Testing send -R -i backup from filesystem
+#
+log_must eval "$ZFS send -R -i @init $dstds/$FS@final > " \
+       "$BACKDIR/fs-init-final-iR"
+
+srclist=$(getds_with_suffix $dstds/$FS @final)
+interlist="$srclist $(getds_with_suffix $dstds/$FS @snapC)"
+interlist="$interlist $(getds_with_suffix $dstds/$FS @snapB)"
+interlist="$interlist $(getds_with_suffix $dstds/$FS @snapA)"
+log_must destroy_tree $interlist
+if is_global_zone ; then
+       log_must eval "$ZFS receive -d -F $POOL2 < $BACKDIR/fs-init-final-iR"
+else
+       $ZFS receive -F -d $dstds/$FS < $BACKDIR/fs-init-final-iR
+fi
+
+dstlist=$(getds_with_suffix $dstds/$FS @final)
+if [[ $srclist != $dstlist ]]; then
+       log_fail "Unexpected: srclist($srclist) != dstlist($dstlist)"
+fi
+log_must cmp_ds_cont $POOL $POOL2
+
+if is_global_zone ; then
+       #
+       # Testing send -R -i backup from volume
+       #
+       srclist=$(getds_with_suffix $POOL2/$FS/vol @final)
+       log_must eval "$ZFS send -R -i @init $POOL2/$FS/vol@final > " \
+               "$BACKDIR/vol-init-final-iR"
+       log_must destroy_tree $srclist
+       log_must eval "$ZFS receive -d $POOL2 < $BACKDIR/vol-init-final-iR"
+
+       dstlist=$(getds_with_suffix $POOL2/$FS/vol @final)
+       if [[ $srclist != $dstlist ]]; then
+               log_fail "Unexpected: srclist($srclist) != dstlist($dstlist)"
+       fi
+       log_must cmp_ds_cont $POOL $POOL2
+fi
+
+log_pass "zfs send -R -i send incremental from fs@init to fs@final."
diff --git a/tests/zfs-tests/tests/functional/rsend/rsend_005_pos.ksh b/tests/zfs-tests/tests/functional/rsend/rsend_005_pos.ksh
new file mode 100755 (executable)
index 0000000..154072d
--- /dev/null
@@ -0,0 +1,104 @@
+#!/bin/ksh -p
+#
+# CDDL HEADER START
+#
+# The contents of this file are subject to the terms of the
+# Common Development and Distribution License (the "License").
+# You may not use this file except in compliance with the License.
+#
+# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
+# or http://www.opensolaris.org/os/licensing.
+# See the License for the specific language governing permissions
+# and limitations under the License.
+#
+# When distributing Covered Code, include this CDDL HEADER in each
+# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
+# If applicable, add the following below this CDDL HEADER, with the
+# fields enclosed by brackets "[]" replaced with your own identifying
+# information: Portions Copyright [yyyy] [name of copyright owner]
+#
+# CDDL HEADER END
+#
+
+#
+# Copyright 2008 Sun Microsystems, Inc.  All rights reserved.
+# Use is subject to license terms.
+#
+
+#
+# Copyright (c) 2013 by Delphix. All rights reserved.
+#
+
+. $STF_SUITE/tests/functional/rsend/rsend.kshlib
+
+#
+# DESCRIPTION:
+#      zfs send -R -I send all the incremental between fs@init with fs@final
+#
+# STRATEGY:
+#      1. Setup test model
+#      2. Send -R -I @init @final on pool
+#      3. Destroy all the snapshots which is later than @init
+#      4. Verify receive can restore all the snapshots and data
+#      5. Do the same test on filesystem and volume
+#
+
+verify_runnable "both"
+
+log_assert "zfs send -R -I send all the incremental between @init with @final"
+log_onexit cleanup_pool $POOL2
+
+#
+# Duplicate POOL2 for testing
+#
+log_must eval "$ZFS send -R $POOL@final > $BACKDIR/pool-final-R"
+log_must eval "$ZFS receive -d -F $POOL2 < $BACKDIR/pool-final-R"
+
+if is_global_zone ; then
+       #
+       # Testing send -R -I from pool
+       #
+       log_must eval "$ZFS send -R -I @init $POOL2@final > " \
+               "$BACKDIR/pool-init-final-IR"
+       list=$(getds_with_suffix $POOL2 @snapA)
+       list="$list $(getds_with_suffix $POOL2 @snapB)"
+       list="$list $(getds_with_suffix $POOL2 @snapC)"
+       list="$list $(getds_with_suffix $POOL2 @final)"
+       log_must destroy_tree $list
+       log_must eval "$ZFS receive -d -F $POOL2 < $BACKDIR/pool-init-final-IR"
+       log_must cmp_ds_cont $POOL $POOL2
+fi
+
+dstds=$(get_dst_ds $POOL $POOL2)
+#
+# Testing send -R -I from filesystem
+#
+log_must eval "$ZFS send -R -I @init $dstds/$FS@final > " \
+       "$BACKDIR/fs-init-final-IR"
+list=$(getds_with_suffix $dstds/$FS @snapA)
+list="$list $(getds_with_suffix $dstds/$FS @snapB)"
+list="$list $(getds_with_suffix $dstds/$FS @snapC)"
+list="$list $(getds_with_suffix $dstds/$FS @final)"
+log_must destroy_tree $list
+if is_global_zone ; then
+       log_must eval "$ZFS receive -d -F $dstds < $BACKDIR/fs-init-final-IR"
+else
+       $ZFS receive -d -F $dstds < $BACKDIR/fs-init-final-IR
+fi
+log_must cmp_ds_subs $POOL $dstds
+log_must cmp_ds_cont $POOL $dstds
+
+if is_global_zone ; then
+       #
+       # Testing send -I -R for volume
+       #
+       vol=$POOL2/$FS/vol
+       log_must eval "$ZFS send -R -I @init $vol@final > " \
+               "$BACKDIR/vol-init-final-IR"
+       log_must destroy_tree $vol@snapB $vol@snapC $vol@final
+       log_must eval "$ZFS receive -d -F $POOL2 < $BACKDIR/vol-init-final-IR"
+       log_must cmp_ds_subs $POOL $POOL2
+       log_must cmp_ds_cont $POOL $POOL2
+fi
+
+log_pass "zfs send -R -I send all the incremental between @init with @final"
diff --git a/tests/zfs-tests/tests/functional/rsend/rsend_006_pos.ksh b/tests/zfs-tests/tests/functional/rsend/rsend_006_pos.ksh
new file mode 100755 (executable)
index 0000000..78f3d26
--- /dev/null
@@ -0,0 +1,82 @@
+#!/bin/ksh -p
+#
+# CDDL HEADER START
+#
+# The contents of this file are subject to the terms of the
+# Common Development and Distribution License (the "License").
+# You may not use this file except in compliance with the License.
+#
+# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
+# or http://www.opensolaris.org/os/licensing.
+# See the License for the specific language governing permissions
+# and limitations under the License.
+#
+# When distributing Covered Code, include this CDDL HEADER in each
+# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
+# If applicable, add the following below this CDDL HEADER, with the
+# fields enclosed by brackets "[]" replaced with your own identifying
+# information: Portions Copyright [yyyy] [name of copyright owner]
+#
+# CDDL HEADER END
+#
+
+#
+# Copyright 2008 Sun Microsystems, Inc.  All rights reserved.
+# Use is subject to license terms.
+#
+
+#
+# Copyright (c) 2013 by Delphix. All rights reserved.
+#
+
+. $STF_SUITE/tests/functional/rsend/rsend.kshlib
+
+#
+# DESCRIPTION:
+#      Rename snapshot name will not change the dependent order.
+#
+# STRATEGY:
+#      1. Set up a set of datasets.
+#      2. Rename part of snapshots.
+#      3. Send -R all the POOL
+#      4. Verify snapshot name will not change the dependent order.
+#
+
+verify_runnable "both"
+
+#              Source                  Target
+#
+set -A snaps   "$POOL@init"            "$POOL@snap0"   \
+               "$POOL@snapA"           "$POOL@snap1"   \
+               "$POOL@snapC"           "$POOL@snap2"   \
+               "$POOL@final"           "$POOL@init"
+
+function cleanup
+{
+       log_must cleanup_pool $POOL
+       log_must cleanup_pool $POOL2
+
+       log_must setup_test_model $POOL
+}
+
+log_assert "Rename snapshot name will not change the dependent order."
+log_onexit cleanup
+
+typeset -i i=0
+while ((i < ${#snaps[@]})); do
+       log_must $ZFS rename -r ${snaps[$i]} ${snaps[((i+1))]}
+
+       ((i += 2))
+done
+
+#
+# Duplicate POOL2 for testing
+#
+log_must eval "$ZFS send -R $POOL@init > $BACKDIR/pool-final-R"
+log_must eval "$ZFS receive -d -F $POOL2 < $BACKDIR/pool-final-R"
+
+dstds=$(get_dst_ds $POOL $POOL2)
+log_must cmp_ds_subs $POOL $dstds
+log_must cmp_ds_cont $POOL $dstds
+
+log_pass "Rename snapshot name will not change the dependent order."
diff --git a/tests/zfs-tests/tests/functional/rsend/rsend_007_pos.ksh b/tests/zfs-tests/tests/functional/rsend/rsend_007_pos.ksh
new file mode 100755 (executable)
index 0000000..b057953
--- /dev/null
@@ -0,0 +1,99 @@
+#!/bin/ksh -p
+#
+# CDDL HEADER START
+#
+# The contents of this file are subject to the terms of the
+# Common Development and Distribution License (the "License").
+# You may not use this file except in compliance with the License.
+#
+# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
+# or http://www.opensolaris.org/os/licensing.
+# See the License for the specific language governing permissions
+# and limitations under the License.
+#
+# When distributing Covered Code, include this CDDL HEADER in each
+# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
+# If applicable, add the following below this CDDL HEADER, with the
+# fields enclosed by brackets "[]" replaced with your own identifying
+# information: Portions Copyright [yyyy] [name of copyright owner]
+#
+# CDDL HEADER END
+#
+
+#
+# Copyright 2008 Sun Microsystems, Inc.  All rights reserved.
+# Use is subject to license terms.
+#
+
+#
+# Copyright (c) 2013 by Delphix. All rights reserved.
+#
+
+. $STF_SUITE/tests/functional/rsend/rsend.kshlib
+
+#
+# DESCRIPTION:
+#      Rename parent filesystem name will not change the dependent order.
+#
+# STRATEGY:
+#      1. Separately rename pool clone, filesystem and volume name.
+#      2. Send -R all the POOL
+#      3. Verify renamed dataset will not change the snapshot dependent order.
+#
+
+verify_runnable "both"
+
+set -A         dtst \
+       "$POOL/pclone"          "$POOL/$FS/pclone"      \
+       "$POOL/$FS/fs1/fs2"     "$POOL/fs2"
+if is_global_zone ; then
+       typeset -i n=${#dtst[@]}
+       dtst[((n))]="$POOL/vol";        dtst[((n+1))]="$POOL/$FS/fs1/vol"
+fi
+
+function cleanup
+{
+       log_must cleanup_pool $POOL
+       log_must cleanup_pool $POOL2
+
+       log_must setup_test_model $POOL
+}
+
+log_assert "Rename parent filesystem name will not change the dependent order."
+log_onexit cleanup
+
+typeset -i i=0
+while ((i < ${#dtst[@]})); do
+       log_must $ZFS rename ${dtst[$i]} ${dtst[((i+1))]}
+
+       ((i += 2))
+done
+
+#
+# Verify zfs send -R should succeed
+#
+log_must eval "$ZFS send -R $POOL@final > $BACKDIR/pool-final-R"
+log_must eval "$ZFS receive -d -F $POOL2 < $BACKDIR/pool-final-R"
+dstds=$(get_dst_ds $POOL $POOL2)
+log_must cmp_ds_subs $POOL $dstds
+log_must cmp_ds_cont $POOL $dstds
+
+#
+# Verify zfs send -R -I should succeed
+#
+log_must eval "$ZFS send -R -I @init $dstds@final > " \
+        "$BACKDIR/pool-init-final-IR"
+list=$(getds_with_suffix $dstds @snapA)
+list="$list $(getds_with_suffix $dstds @snapB)"
+list="$list $(getds_with_suffix $dstds @snapC)"
+list="$list $(getds_with_suffix $dstds @final)"
+log_must destroy_tree $list
+if is_global_zone ; then
+       log_must eval "$ZFS receive -d -F $dstds < $BACKDIR/pool-init-final-IR"
+else
+       $ZFS receive -d -F $dstds < $BACKDIR/pool-init-final-IR
+fi
+log_must cmp_ds_subs $POOL $dstds
+log_must cmp_ds_cont $POOL $dstds
+
+log_pass "Rename parent filesystem name will not change the dependent order."
diff --git a/tests/zfs-tests/tests/functional/rsend/rsend_008_pos.ksh b/tests/zfs-tests/tests/functional/rsend/rsend_008_pos.ksh
new file mode 100755 (executable)
index 0000000..de5543e
--- /dev/null
@@ -0,0 +1,128 @@
+#!/bin/ksh -p
+#
+# CDDL HEADER START
+#
+# The contents of this file are subject to the terms of the
+# Common Development and Distribution License (the "License").
+# You may not use this file except in compliance with the License.
+#
+# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
+# or http://www.opensolaris.org/os/licensing.
+# See the License for the specific language governing permissions
+# and limitations under the License.
+#
+# When distributing Covered Code, include this CDDL HEADER in each
+# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
+# If applicable, add the following below this CDDL HEADER, with the
+# fields enclosed by brackets "[]" replaced with your own identifying
+# information: Portions Copyright [yyyy] [name of copyright owner]
+#
+# CDDL HEADER END
+#
+
+#
+# Copyright 2009 Sun Microsystems, Inc.  All rights reserved.
+# Use is subject to license terms.
+#
+
+#
+# Copyright (c) 2013 by Delphix. All rights reserved.
+#
+
+. $STF_SUITE/tests/functional/rsend/rsend.kshlib
+
+#
+# DESCRIPTION:
+#      Changes made by 'zfs promote' can be properly received.
+#
+# STRATEGY:
+#      1. Seperatly promote pool clone, filesystem clone and volume clone.
+#      2. Recursively backup all the POOL and restore in POOL2
+#      3. Verify all the datesets and property be properly received.
+#
+
+verify_runnable "both"
+
+#              Origin                  Clone
+#
+set -A dtst    "$POOL"                 "$POOL/pclone"          \
+               "$POOL/$FS/fs1/fs2"     "$POOL/$FS/fs1/fclone"
+if is_global_zone ; then
+       typeset -i n=${#dtst[@]}
+       dtst[((n))]="$POOL/$FS/vol";    dtst[((n+1))]="$POOL/$FS/vclone"
+fi
+
+function cleanup
+{
+       typeset origin
+       typeset -i i=0
+       while ((i < ${#dtst[@]})); do
+               origin=$(get_prop origin ${dtst[$i]})
+
+               if [[ $origin != "-" ]]; then
+                       log_must $ZFS promote ${dtst[$i]}
+               fi
+
+               ((i += 2))
+       done
+
+       origin=$(get_prop origin $POOL2)
+       if [[ $origin != "-" ]]; then
+               log_must $ZFS promote $POOL2
+       fi
+       log_must cleanup_pool $POOL2
+}
+
+log_assert "Changes made by 'zfs promote' can be properly received."
+log_onexit cleanup
+
+typeset -i i=0
+while ((i < ${#dtst[@]})); do
+       log_must $ZFS promote ${dtst[((i+1))]}
+
+       ((i += 2))
+done
+
+#
+# Verify zfs send -R should succeed
+#
+log_must eval "$ZFS send -R $POOL@final > $BACKDIR/pool-final-R"
+log_must eval "$ZFS receive -d -F $POOL2 < $BACKDIR/pool-final-R"
+
+dstds=$(get_dst_ds $POOL $POOL2)
+#
+# Define all the POOL/POOL2 datasets pair
+#
+set -A pair    "$POOL"                 "$dstds"                \
+               "$POOL/$FS"             "$dstds/$FS"            \
+               "$POOL/$FS/fs1"         "$dstds/$FS/fs1"        \
+               "$POOL/$FS/fs1/fs2"     "$dstds/$FS/fs1/fs2"    \
+               "$POOL/pclone"          "$dstds/pclone"         \
+               "$POOL/$FS/fs1/fclone"  "$dstds/$FS/fs1/fclone"
+
+if is_global_zone ; then
+       typeset -i n=${#pair[@]}
+       pair[((n))]="$POOL/vol";        pair[((n+1))]="$dstds/vol"
+       pair[((n+2))]="$POOL/$FS/vol"   pair[((n+3))]="$dstds/$FS/vol"
+fi
+
+#
+# Verify all the sub-datasets can be properly received.
+#
+log_must cmp_ds_subs $POOL $dstds
+typeset -i i=0
+while ((i < ${#pair[@]})); do
+       log_must cmp_ds_cont ${pair[$i]} ${pair[((i+1))]}
+       log_must cmp_ds_prop ${pair[$i]} ${pair[((i+1))]}
+
+       ((i += 2))
+done
+
+# Verify the original filesystem can be promoted
+log_must $ZFS promote $dstds
+if is_global_zone ; then
+       log_must $ZFS promote $dstds/$FS/vol
+fi
+log_must $ZFS promote $dstds/$FS/fs1/fs2
+
+log_pass "Changes made by 'zfs promote' can be properly received."
diff --git a/tests/zfs-tests/tests/functional/rsend/rsend_009_pos.ksh b/tests/zfs-tests/tests/functional/rsend/rsend_009_pos.ksh
new file mode 100755 (executable)
index 0000000..0e6fcf1
--- /dev/null
@@ -0,0 +1,94 @@
+#!/bin/ksh -p
+#
+# CDDL HEADER START
+#
+# The contents of this file are subject to the terms of the
+# Common Development and Distribution License (the "License").
+# You may not use this file except in compliance with the License.
+#
+# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
+# or http://www.opensolaris.org/os/licensing.
+# See the License for the specific language governing permissions
+# and limitations under the License.
+#
+# When distributing Covered Code, include this CDDL HEADER in each
+# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
+# If applicable, add the following below this CDDL HEADER, with the
+# fields enclosed by brackets "[]" replaced with your own identifying
+# information: Portions Copyright [yyyy] [name of copyright owner]
+#
+# CDDL HEADER END
+#
+
+#
+# Copyright 2008 Sun Microsystems, Inc.  All rights reserved.
+# Use is subject to license terms.
+#
+
+#
+# Copyright (c) 2013 by Delphix. All rights reserved.
+#
+
+. $STF_SUITE/tests/functional/rsend/rsend.kshlib
+
+#
+# DESCRIPTION:
+#      zfs receive can handle out of space correctly.
+#
+# STRATEGY:
+#      1. Create two pools, one is big and another is small.
+#      2. Fill the big pool with data.
+#      3. Take snapshot and backup the whole pool.
+#      4. Receive this stream in small pool.
+#      5. Verify zfs receive can handle the out of space error correctly.
+#
+
+verify_runnable "global"
+
+function cleanup
+{
+       if datasetexists bpool ; then
+               log_must $ZPOOL destroy -f bpool
+       fi
+       if datasetexists spool ; then
+               log_must $ZPOOL destroy -f spool
+       fi
+}
+
+log_assert "Verify zfs receive can handle out of space correctly."
+log_onexit cleanup
+
+log_must $MKFILE 100M $TESTDIR/bfile
+log_must $MKFILE 64M  $TESTDIR/sfile
+log_must $ZPOOL create bpool $TESTDIR/bfile
+log_must $ZPOOL create spool $TESTDIR/sfile
+
+#
+# Test out of space on sub-filesystem
+#
+log_must $ZFS create bpool/fs
+mntpnt=$(get_prop mountpoint bpool/fs)
+log_must $MKFILE 30M $mntpnt/file
+
+log_must $ZFS snapshot bpool/fs@snap
+log_must eval "$ZFS send -R bpool/fs@snap > $BACKDIR/fs-R"
+log_mustnot eval "$ZFS receive -d -F spool < $BACKDIR/fs-R"
+
+log_must datasetnonexists spool/fs
+log_must ismounted spool
+
+#
+# Test out of space on top filesystem
+#
+mntpnt2=$(get_prop mountpoint bpool)
+log_must $MV $mntpnt/file $mntpnt2
+log_must $ZFS destroy -rf bpool/fs
+
+log_must $ZFS snapshot bpool@snap
+log_must eval "$ZFS send -R bpool@snap > $BACKDIR/bpool-R"
+log_mustnot eval "$ZFS receive -d -F spool < $BACKDIR/bpool-R"
+
+log_must datasetnonexists spool/fs
+log_must ismounted spool
+
+log_pass "zfs receive can handle out of space correctly."
diff --git a/tests/zfs-tests/tests/functional/rsend/rsend_010_pos.ksh b/tests/zfs-tests/tests/functional/rsend/rsend_010_pos.ksh
new file mode 100755 (executable)
index 0000000..503a8c2
--- /dev/null
@@ -0,0 +1,77 @@
+#!/bin/ksh -p
+#
+# CDDL HEADER START
+#
+# The contents of this file are subject to the terms of the
+# Common Development and Distribution License (the "License").
+# You may not use this file except in compliance with the License.
+#
+# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
+# or http://www.opensolaris.org/os/licensing.
+# See the License for the specific language governing permissions
+# and limitations under the License.
+#
+# When distributing Covered Code, include this CDDL HEADER in each
+# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
+# If applicable, add the following below this CDDL HEADER, with the
+# fields enclosed by brackets "[]" replaced with your own identifying
+# information: Portions Copyright [yyyy] [name of copyright owner]
+#
+# CDDL HEADER END
+#
+
+#
+# Copyright 2008 Sun Microsystems, Inc.  All rights reserved.
+# Use is subject to license terms.
+#
+
+#
+# Copyright (c) 2013 by Delphix. All rights reserved.
+#
+
+. $STF_SUITE/tests/functional/rsend/rsend.kshlib
+
+#
+# DESCRIPTION:
+#      ZFS can handle stream with multiple identical (same GUID) snapshots
+#
+# STRATEGY:
+#      1. Recursively backup snapshot
+#      2. Restore it to the given filesystem
+#      3. Resend the snapshot again
+#      4. Verify this stream can be restore to this filesystem again
+#
+
+verify_runnable "both"
+
+log_assert "ZFS can handle stream with multiple identical (same GUID) snapshots"
+log_onexit cleanup_pool $POOL2
+
+log_must $ZFS create $POOL2/$FS
+log_must $ZFS snapshot $POOL2/$FS@snap
+
+#
+# First round restore the stream
+#
+log_must eval "$ZFS send -R $POOL2/$FS@snap > $BACKDIR/fs-R"
+log_must eval "$ZFS receive -d -F $POOL2/$FS < $BACKDIR/fs-R"
+
+#
+# In order to avoid 'zfs send -R' failed, create snapshot for
+# all the sub-systems
+#
+list=$($ZFS list -r -H -o name -t filesystem $POOL2/$FS)
+for item in $list ; do
+       if datasetnonexists $item@snap ; then
+               log_must $ZFS snapshot $item@snap
+       fi
+done
+
+#
+# Second round restore the stream
+#
+log_must eval "$ZFS send -R $POOL2/$FS@snap > $BACKDIR/fs-R"
+dstds=$(get_dst_ds $POOL2/$FS $POOL2/$FS)
+log_must eval "$ZFS receive -d -F $dstds < $BACKDIR/fs-R"
+
+log_pass "ZFS can handle stream with multiple identical (same GUID) snapshots"
diff --git a/tests/zfs-tests/tests/functional/rsend/rsend_011_pos.ksh b/tests/zfs-tests/tests/functional/rsend/rsend_011_pos.ksh
new file mode 100755 (executable)
index 0000000..d771a83
--- /dev/null
@@ -0,0 +1,125 @@
+#!/bin/ksh -p
+#
+# CDDL HEADER START
+#
+# The contents of this file are subject to the terms of the
+# Common Development and Distribution License (the "License").
+# You may not use this file except in compliance with the License.
+#
+# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
+# or http://www.opensolaris.org/os/licensing.
+# See the License for the specific language governing permissions
+# and limitations under the License.
+#
+# When distributing Covered Code, include this CDDL HEADER in each
+# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
+# If applicable, add the following below this CDDL HEADER, with the
+# fields enclosed by brackets "[]" replaced with your own identifying
+# information: Portions Copyright [yyyy] [name of copyright owner]
+#
+# CDDL HEADER END
+#
+
+#
+# Copyright 2009 Sun Microsystems, Inc.  All rights reserved.
+# Use is subject to license terms.
+#
+
+#
+# Copyright (c) 2013 by Delphix. All rights reserved.
+#
+
+. $STF_SUITE/tests/functional/rsend/rsend.kshlib
+
+#
+# DESCRIPTION:
+#      Changes made by 'zfs inherit' can be properly received.
+#
+# STRATEGY:
+#      1. Inherit property for filesystem and volume
+#      2. Send and restore them in the target pool
+#      3. Verify all the datasets can be properly backup and receive
+#
+
+verify_runnable "both"
+
+function cleanup
+{
+       export __ZFS_POOL_RESTRICT="$POOL $POOL2"
+       log_must $ZFS unmount -a
+       unset __ZFS_POOL_RESTRICT
+       log_must cleanup_pool $POOL
+       log_must cleanup_pool $POOL2
+
+       log_must setup_test_model $POOL
+}
+
+log_assert "Verify changes made by 'zfs inherit' can be properly received."
+log_onexit cleanup
+
+#
+# Setting all the $FS properties as local value,
+#
+for prop in $(fs_inherit_prop); do
+       value=$(get_prop $prop $POOL/$FS)
+       log_must $ZFS set $prop=$value $POOL/$FS
+done
+
+#
+# Inherit propertes in sub-datasets
+#
+for ds in "$POOL/$FS/fs1" "$POOL/$FS/fs1/fs2" "$POOL/$FS/fs1/fclone" ; do
+       for prop in $(fs_inherit_prop) ; do
+               $ZFS inherit $prop $ds
+               if (($? !=0 )); then
+                       log_fail "$ZFS inherit $prop $ds"
+               fi
+       done
+done
+if is_global_zone ; then
+       for prop in $(vol_inherit_prop) ; do
+               $ZFS inherit $prop $POOL/$FS/vol
+               if (($? !=0 )); then
+                       log_fail "$ZFS inherit $prop $POOL/$FS/vol"
+               fi
+       done
+fi
+
+#
+# Verify datasets can be backup and restore correctly
+# Unmount $POOL/$FS to avoid two fs mount in the same mountpoint
+#
+log_must eval "$ZFS send -R $POOL@final > $BACKDIR/pool-R"
+log_must $ZFS unmount -f $POOL/$FS
+log_must eval "$ZFS receive -d -F $POOL2 < $BACKDIR/pool-R"
+
+dstds=$(get_dst_ds $POOL $POOL2)
+#
+# Define all the POOL/POOL2 datasets pair
+#
+set -A pair    "$POOL"                 "$dstds"                \
+               "$POOL/$FS"             "$dstds/$FS"            \
+               "$POOL/$FS/fs1"         "$dstds/$FS/fs1"        \
+               "$POOL/$FS/fs1/fs2"     "$dstds/$FS/fs1/fs2"    \
+               "$POOL/pclone"          "$dstds/pclone"         \
+               "$POOL/$FS/fs1/fclone"  "$dstds/$FS/fs1/fclone"
+
+if is_global_zone ; then
+       typeset -i n=${#pair[@]}
+       pair[((n))]="$POOL/vol";        pair[((n+1))]="$dstds/vol"
+       pair[((n+2))]="$POOL/$FS/vol"   pair[((n+3))]="$dstds/$FS/vol"
+fi
+
+#
+# Verify all the sub-datasets can be properly received.
+#
+log_must cmp_ds_subs $POOL $dstds
+typeset -i i=0
+while ((i < ${#pair[@]})); do
+       log_must cmp_ds_cont ${pair[$i]} ${pair[((i+1))]}
+       log_must cmp_ds_prop ${pair[$i]} ${pair[((i+1))]}
+
+       ((i += 2))
+done
+
+log_pass "Changes made by 'zfs inherit' can be properly received."
diff --git a/tests/zfs-tests/tests/functional/rsend/rsend_012_pos.ksh b/tests/zfs-tests/tests/functional/rsend/rsend_012_pos.ksh
new file mode 100755 (executable)
index 0000000..4a590fa
--- /dev/null
@@ -0,0 +1,201 @@
+#!/bin/ksh -p
+#
+# CDDL HEADER START
+#
+# The contents of this file are subject to the terms of the
+# Common Development and Distribution License (the "License").
+# You may not use this file except in compliance with the License.
+#
+# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
+# or http://www.opensolaris.org/os/licensing.
+# See the License for the specific language governing permissions
+# and limitations under the License.
+#
+# When distributing Covered Code, include this CDDL HEADER in each
+# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
+# If applicable, add the following below this CDDL HEADER, with the
+# fields enclosed by brackets "[]" replaced with your own identifying
+# information: Portions Copyright [yyyy] [name of copyright owner]
+#
+# CDDL HEADER END
+#
+
+#
+# Copyright 2009 Sun Microsystems, Inc.  All rights reserved.
+# Use is subject to license terms.
+#
+
+#
+# Copyright (c) 2013 by Delphix. All rights reserved.
+#
+
+. $STF_SUITE/tests/functional/rsend/rsend.kshlib
+
+#
+# DESCRIPTION:
+#      zfs send -R will backup all the filesystem properties correctly.
+#
+# STRATEGY:
+#      1. Setting properties for all the filesystem and volumes randomly
+#      2. Backup all the data from POOL by send -R
+#      3. Restore all the data in POOL2
+#      4. Verify all the perperties in two pools are same
+#
+
+verify_runnable "global"
+
+function rand_set_prop
+{
+       typeset dtst=$1
+       typeset prop=$2
+       shift 2
+       typeset value=$(random_get $@)
+
+       log_must eval "$ZFS set $prop='$value' $dtst"
+}
+
+function edited_prop
+{
+       typeset behaviour=$1
+       typeset ds=$2
+       typeset backfile=$TESTDIR/edited_prop_$ds
+
+       case $behaviour in
+               "get")
+                       typeset props=$($ZFS inherit 2>&1 | \
+                               $AWK '$2=="YES" {print $1}' | \
+                               $EGREP -v "^vol|\.\.\.$")
+                       for item in $props ; do
+                               if [[ $item == "mlslabel" ]] && \
+                                       ! is_te_enabled ; then
+                                       continue
+                               fi
+                               $ZFS get -H -o property,value $item $ds >> \
+                                       $backfile
+                               if (($? != 0)); then
+                                       log_fail "zfs get -H -o property,value"\
+                                               "$item $ds > $backfile"
+                               fi
+                       done
+                       ;;
+               "set")
+                       if [[ ! -f $backfile ]] ; then
+                               log_fail "$ds need backup properties firstly."
+                       fi
+
+                       typeset prop value
+                       while read prop value ; do
+                               eval $ZFS set $prop='$value' $ds
+                               if (($? != 0)); then
+                                       log_fail "$ZFS set $prop=$value $ds"
+                               fi
+                       done < $backfile
+                       ;;
+               *)
+                       log_fail "Unrecognized behaviour: $behaviour"
+       esac
+}
+
+function cleanup
+{
+       log_must cleanup_pool $POOL
+       log_must cleanup_pool $POOL2
+
+       log_must edited_prop "set" $POOL
+       log_must edited_prop "set" $POOL2
+
+       typeset prop
+       for prop in $(fs_inherit_prop) ; do
+               log_must $ZFS inherit $prop $POOL
+               log_must $ZFS inherit $prop $POOL2
+       done
+
+       #if is_shared $POOL; then
+       #       log_must $ZFS set sharenfs=off $POOL
+       #fi
+       log_must setup_test_model $POOL
+
+       if [[ -d $TESTDIR ]]; then
+               log_must $RM -rf $TESTDIR/*
+       fi
+}
+
+log_assert "Verify zfs send -R will backup all the filesystem properties " \
+       "correctly."
+log_onexit cleanup
+
+log_must edited_prop "get" $POOL
+log_must edited_prop "get" $POOL2
+
+for fs in "$POOL" "$POOL/pclone" "$POOL/$FS" "$POOL/$FS/fs1" \
+       "$POOL/$FS/fs1/fs2" "$POOL/$FS/fs1/fclone" ; do
+       rand_set_prop $fs aclinherit "discard" "noallow" "secure" "passthrough"
+       rand_set_prop $fs checksum "on" "off" "fletcher2" "fletcher4" "sha256"
+       rand_set_prop $fs aclmode "discard" "groupmask" "passthrough"
+       rand_set_prop $fs atime "on" "off"
+       rand_set_prop $fs checksum "on" "off" "fletcher2" "fletcher4" "sha256"
+       rand_set_prop $fs compression "on" "off" "lzjb" "gzip" \
+               "gzip-1" "gzip-2" "gzip-3" "gzip-4" "gzip-5" "gzip-6"   \
+               "gzip-7" "gzip-8" "gzip-9"
+       rand_set_prop $fs copies "1" "2" "3"
+       rand_set_prop $fs devices "on" "off"
+       rand_set_prop $fs exec "on" "off"
+       rand_set_prop $fs quota "512M" "1024M"
+       rand_set_prop $fs recordsize "512" "2K" "8K" "32K" "128K"
+       rand_set_prop $fs setuid "on" "off"
+       rand_set_prop $fs snapdir "hidden" "visible"
+       rand_set_prop $fs xattr "on" "off"
+       rand_set_prop $fs user:prop "aaa" "bbb" "23421" "()-+?"
+done
+
+for vol in "$POOL/vol" "$POOL/$FS/vol" ; do
+       rand_set_prop $vol checksum "on" "off" "fletcher2" "fletcher4" "sha256"
+       rand_set_prop $vol compression "on" "off" "lzjb" "gzip" \
+               "gzip-1" "gzip-2" "gzip-3" "gzip-4" "gzip-5" "gzip-6"   \
+               "gzip-7" "gzip-8" "gzip-9"
+       rand_set_prop $vol readonly "on" "off"
+       rand_set_prop $vol copies "1" "2" "3"
+       rand_set_prop $vol user:prop "aaa" "bbb" "23421" "()-+?"
+done
+
+
+# Verify inherited property can be received
+rand_set_prop $POOL sharenfs "on" "off" "rw"
+
+#
+# Duplicate POOL2 for testing
+#
+log_must eval "$ZFS send -R $POOL@final > $BACKDIR/pool-final-R"
+log_must eval "$ZFS receive -d -F $POOL2 < $BACKDIR/pool-final-R"
+
+#
+# Define all the POOL/POOL2 datasets pair
+#
+set -A pair    "$POOL"                 "$POOL2"                \
+               "$POOL/$FS"             "$POOL2/$FS"            \
+               "$POOL/$FS/fs1"         "$POOL2/$FS/fs1"        \
+               "$POOL/$FS/fs1/fs2"     "$POOL2/$FS/fs1/fs2"    \
+               "$POOL/pclone"          "$POOL2/pclone"         \
+               "$POOL/$FS/fs1/fclone"  "$POOL2/$FS/fs1/fclone" \
+               "$POOL/vol"             "$POOL2/vol"            \
+               "$POOL/$FS/vol"         "$POOL2/$FS/vol"
+
+typeset -i i=0
+while ((i < ${#pair[@]})); do
+       log_must cmp_ds_prop ${pair[$i]} ${pair[((i+1))]}
+
+       ((i += 2))
+done
+
+
+$ZPOOL upgrade -v | $GREP "Snapshot properties" > /dev/null 2>&1
+if (( $? == 0 )) ; then
+       i=0
+       while ((i < ${#pair[@]})); do
+               log_must cmp_ds_prop ${pair[$i]}@final ${pair[((i+1))]}@final
+               ((i += 2))
+       done
+fi
+
+log_pass "Verify zfs send -R will backup all the filesystem properties " \
+       "correctly."
diff --git a/tests/zfs-tests/tests/functional/rsend/rsend_013_pos.ksh b/tests/zfs-tests/tests/functional/rsend/rsend_013_pos.ksh
new file mode 100755 (executable)
index 0000000..fefcfa7
--- /dev/null
@@ -0,0 +1,86 @@
+#!/bin/ksh -p
+#
+# CDDL HEADER START
+#
+# The contents of this file are subject to the terms of the
+# Common Development and Distribution License (the "License").
+# You may not use this file except in compliance with the License.
+#
+# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
+# or http://www.opensolaris.org/os/licensing.
+# See the License for the specific language governing permissions
+# and limitations under the License.
+#
+# When distributing Covered Code, include this CDDL HEADER in each
+# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
+# If applicable, add the following below this CDDL HEADER, with the
+# fields enclosed by brackets "[]" replaced with your own identifying
+# information: Portions Copyright [yyyy] [name of copyright owner]
+#
+# CDDL HEADER END
+#
+
+#
+# Copyright 2009 Sun Microsystems, Inc.  All rights reserved.
+# Use is subject to license terms.
+#
+
+#
+# Copyright (c) 2013 by Delphix. All rights reserved.
+#
+
+. $STF_SUITE/tests/functional/rsend/rsend.kshlib
+
+#
+# DESCRIPTION:
+#      zfs receive -dF with incremental stream will destroy all the
+#      dataset that not exist on the sender side.
+#
+# STRATEGY:
+#      1. Setup test model
+#      2. Send -R @final on pool
+#      3. Destroy some dataset within the @final, and create @destroy
+#      4. Send -R -I @final @destroy on pool
+#      5. Verify receive -dF will destroy all the dataset that not exist
+#         on the sender side.
+#
+
+verify_runnable "both"
+
+function cleanup
+{
+       cleanup_pool $POOL2
+       cleanup_pool $POOL
+       log_must setup_test_model $POOL
+}
+
+log_assert "zfs receive -dF will destroy all the dataset that not exist" \
+       "on the sender side"
+log_onexit cleanup
+
+cleanup
+
+#
+# Duplicate POOL2 for testing
+#
+log_must eval "$ZFS send -R $POOL@final > $BACKDIR/pool-final-R"
+log_must eval "$ZFS receive -dF $POOL2 < $BACKDIR/pool-final-R"
+
+log_must $ZFS destroy -Rf $POOL/$FS
+log_must $ZFS destroy -Rf $POOL/pclone
+
+if is_global_zone ; then
+       log_must $ZFS destroy -Rf $POOL/vol
+fi
+log_must $ZFS snapshot -r $POOL@destroy
+
+log_must eval "$ZFS send -R -I @final $POOL@destroy > " \
+       "$BACKDIR/pool-final-destroy-IR"
+log_must eval "$ZFS receive -dF $POOL2 < $BACKDIR/pool-final-destroy-IR"
+
+dstds=$(get_dst_ds $POOL $POOL2)
+log_must cmp_ds_subs $POOL $dstds
+log_must cmp_ds_cont $POOL $dstds
+
+log_pass "zfs receive -dF will destroy all the dataset that not exist" \
+       "on the sender side"
diff --git a/tests/zfs-tests/tests/functional/rsend/rsend_014_pos.ksh b/tests/zfs-tests/tests/functional/rsend/rsend_014_pos.ksh
new file mode 100644 (file)
index 0000000..b6cbb1c
--- /dev/null
@@ -0,0 +1,56 @@
+#!/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) 2014 by Delphix. All rights reserved.
+#
+
+. $STF_SUITE/include/libtest.shlib
+. $STF_SUITE/tests/functional/rsend/rsend.kshlib
+
+#
+# Description:
+# Verify that a pool imported readonly can be sent and received.
+#
+# Strategy:
+# 1. Make the source pool readonly, and receive it into pool2.
+# 2. Reset pool2, and repeat the send from a non-root fs of the source pool.
+# 3. Make the source pool read-write again.
+#
+
+verify_runnable "both"
+
+log_assert "zfs send will work on filesystems and volumes in a read-only pool."
+log_onexit cleanup_pool $POOL2
+
+log_must eval "$ZPOOL export $POOL"
+log_must eval "$ZPOOL import -o readonly=on $POOL"
+log_must eval "$ZFS send -R $POOL@final > $BACKDIR/pool-final-R"
+log_must eval "$ZFS receive -d -F $POOL2 < $BACKDIR/pool-final-R"
+
+dstds=$(get_dst_ds $POOL $POOL2)
+log_must cmp_ds_subs $POOL $dstds
+log_must cmp_ds_cont $POOL $dstds
+
+log_must cleanup_pool $POOL2
+
+log_must eval "$ZFS send -R $POOL/$FS@final > $BACKDIR/fs-final-R"
+log_must eval "$ZFS receive -d $POOL2 < $BACKDIR/fs-final-R"
+log_must eval "$ZPOOL export $POOL"
+log_must eval "$ZPOOL import $POOL"
+
+dstds=$(get_dst_ds $POOL/$FS $POOL2)
+log_must cmp_ds_subs $POOL/$FS $dstds
+log_must cmp_ds_cont $POOL/$FS $dstds
+
+log_pass "zfs send will work on filesystems and volumes in a read-only pool."
diff --git a/tests/zfs-tests/tests/functional/rsend/rsend_019_pos.ksh b/tests/zfs-tests/tests/functional/rsend/rsend_019_pos.ksh
new file mode 100644 (file)
index 0000000..26f475e
--- /dev/null
@@ -0,0 +1,51 @@
+#!/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) 2014 by Delphix. All rights reserved.
+#
+
+. $STF_SUITE/include/libtest.shlib
+. $STF_SUITE/tests/functional/rsend/rsend.kshlib
+
+#
+# Description:
+# Verify resumability of a full and incremental ZFS send/receive in the
+# presence of a corrupted stream.
+#
+# Strategy:
+# 1. Start a full ZFS send, redirect output to a file
+# 2. Mess up the contents of the stream state file on disk
+# 3. Try ZFS receive, which should fail with a checksum mismatch error
+# 4. ZFS send to the stream state file again using the receive_resume_token
+# 5. ZFS receieve and verify the receive completes successfully
+# 6. Repeat steps on an incremental ZFS send
+#
+
+verify_runnable "both"
+
+log_assert "Verify resumability of a full and incremental ZFS send/receive " \
+    "in the presence of a corrupted stream"
+log_onexit cleanup_pool $POOL2
+
+sendfs=$POOL/sendfs
+recvfs=$POOL2/recvfs
+streamfs=$POOL/stream
+
+test_fs_setup $POOL $POOL2
+resume_test "$ZFS send -v $sendfs@a" $streamfs $recvfs
+resume_test "$ZFS send -v -i @a $sendfs@b" $streamfs $recvfs
+file_check $sendfs $recvfs
+
+log_pass "Verify resumability of a full and incremental ZFS send/receive " \
+    "in the presence of a corrupted stream"
diff --git a/tests/zfs-tests/tests/functional/rsend/rsend_020_pos.ksh b/tests/zfs-tests/tests/functional/rsend/rsend_020_pos.ksh
new file mode 100644 (file)
index 0000000..43cf345
--- /dev/null
@@ -0,0 +1,49 @@
+#!/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) 2014 by Delphix. All rights reserved.
+#
+
+. $STF_SUITE/include/libtest.shlib
+. $STF_SUITE/tests/functional/rsend/rsend.kshlib
+
+#
+# Description:
+# Verify resumability of a full ZFS send/receive with the -D (dedup) flag in
+# the presence of a corrupted stream.
+#
+# Strategy:
+# 1. Start a full ZFS send with the -D flag (dedup), redirect output to a file
+# 2. Mess up the contents of the stream state file on disk
+# 3. Try ZFS receive, which should fail with a checksum mismatch error
+# 4. ZFS send to the stream state file again using the receive_resume_token
+# 5. ZFS receieve and verify the receive completes successfully
+#
+
+verify_runnable "both"
+
+log_assert "Verify resumability of full ZFS send/receive with the -D " \
+    "(dedup) flag"
+log_onexit cleanup_pool $POOL2
+
+sendfs=$POOL/sendfs
+recvfs=$POOL2/recvfs
+streamfs=$POOL/stream
+
+test_fs_setup $POOL $POOL2
+resume_test "$ZFS send -D -v $sendfs@a" $streamfs $recvfs
+file_check $sendfs $recvfs
+
+log_pass "Verify resumability of full ZFS send/receive with the -D " \
+    "(dedup) flag"
diff --git a/tests/zfs-tests/tests/functional/rsend/rsend_021_pos.ksh b/tests/zfs-tests/tests/functional/rsend/rsend_021_pos.ksh
new file mode 100644 (file)
index 0000000..3790121
--- /dev/null
@@ -0,0 +1,52 @@
+#!/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) 2014 by Delphix. All rights reserved.
+#
+
+. $STF_SUITE/include/libtest.shlib
+. $STF_SUITE/tests/functional/rsend/rsend.kshlib
+
+#
+# Description:
+# Verify resumability of a full and incremental ZFS send/receive with the
+# -e (embedded) flag in the presence of a corrupted stream.
+#
+# Strategy:
+# 1. Start a full ZFS send with the -e flag (embedded), redirect output to
+#    a file
+# 2. Mess up the contents of the stream state file on disk
+# 3. Try ZFS receive, which should fail with a checksum mismatch error
+# 4. ZFS send to the stream state file again using the receive_resume_token
+# 5. ZFS receieve and verify the receive completes successfully
+# 6. Repeat steps on an incremental ZFS send
+#
+
+verify_runnable "both"
+
+log_assert "Verify resumability of a full and incremental ZFS send/receive " \
+    "with the -e (embedded) flag"
+log_onexit cleanup_pool $POOL2
+
+sendfs=$POOL/sendfs
+recvfs=$POOL2/recvfs
+streamfs=$POOL/stream
+
+test_fs_setup $POOL $POOL2
+resume_test "$ZFS send -v -e $sendfs@a" $streamfs $recvfs
+resume_test "$ZFS send -v -e -i @a $sendfs@b" $streamfs $recvfs
+file_check $sendfs $recvfs
+
+log_pass "Verify resumability of a full and incremental ZFS send/receive " \
+    "with the -e (embedded) flag"
diff --git a/tests/zfs-tests/tests/functional/rsend/rsend_022_pos.ksh b/tests/zfs-tests/tests/functional/rsend/rsend_022_pos.ksh
new file mode 100644 (file)
index 0000000..fd06b06
--- /dev/null
@@ -0,0 +1,60 @@
+#!/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) 2014 by Delphix. All rights reserved.
+#
+
+. $STF_SUITE/include/libtest.shlib
+. $STF_SUITE/tests/functional/rsend/rsend.kshlib
+
+#
+# Description:
+# Verify resumability of an incremental ZFS send/receive with ZFS bookmarks in
+# the presence of a corrupted stream.
+#
+# Strategy:
+# 1. Bookmark a ZFS snapshot
+# 2. Destroy the ZFS sanpshot
+# 3. Destroy the filesystem for the receive
+# 4. Verify receive of the full send stream
+# 5. Start an incremental ZFS send of the ZFS bookmark, redirect output to a
+#    file
+# 6. Mess up the contents of the stream state file on disk
+# 7. Try ZFS receive, which should fail with a checksum mismatch error
+# 8. ZFS send to the stream state file again using the receive_resume_token
+# 9. ZFS receieve and verify the receive completes successfully
+#
+
+verify_runnable "both"
+
+log_assert "Verify resumability of an incremental ZFS send/receive with ZFS " \
+    "bookmarks"
+log_onexit cleanup_pool $POOL2
+
+sendfs=$POOL/sendfs
+recvfs=$POOL2/recvfs
+streamfs=$POOL/stream
+
+test_fs_setup $POOL $POOL2
+log_must $ZFS bookmark $sendfs@a $sendfs#bm_a
+log_must $ZFS destroy $sendfs@a
+log_must $ZFS receive -v $recvfs </$POOL/initial.zsend
+resume_test "$ZFS send -i \#bm_a $sendfs@b" $streamfs $recvfs
+log_must $ZFS destroy -r -f $sendfs
+log_must $ZFS receive -v $sendfs </$POOL/initial.zsend
+log_must $ZFS receive -v $sendfs </$POOL/incremental.zsend
+file_check $sendfs $recvfs
+
+log_pass "Verify resumability of an incremental ZFS send/receive with ZFS " \
+    "bookmarks"
diff --git a/tests/zfs-tests/tests/functional/rsend/rsend_024_pos.ksh b/tests/zfs-tests/tests/functional/rsend/rsend_024_pos.ksh
new file mode 100644 (file)
index 0000000..2f8f3f7
--- /dev/null
@@ -0,0 +1,52 @@
+#!/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) 2014 by Delphix. All rights reserved.
+#
+
+. $STF_SUITE/include/libtest.shlib
+. $STF_SUITE/tests/functional/rsend/rsend.kshlib
+
+#
+# Description:
+# Verify resumability of a full ZFS send/receive with the source filesystem
+# unmounted.
+#
+# Strategy:
+# 1. Destroy the filesystem for the receive
+# 2. Unmount the source filsesystem
+# 3. Start a full ZFS send, redirect output to a file
+# 4. Mess up the contents of the stream state file on disk
+# 5. Try ZFS receive, which should fail with a checksum mismatch error
+# 6. ZFS send to the stream state file again using the receive_resume_token
+# 7. ZFS receieve and verify the receive completes successfully
+#
+
+verify_runnable "both"
+
+log_assert "Verify resumability of a full ZFS send/receive with the source " \
+    "filesystem unmounted"
+log_onexit cleanup_pool $POOL2
+
+sendfs=$POOL/sendfs
+recvfs=$POOL2/recvfs
+streamfs=$POOL/stream
+
+test_fs_setup $POOL $POOL2
+log_must $ZFS unmount $sendfs
+resume_test "$ZFS send $sendfs" $streamfs $recvfs
+file_check $sendfs $recvfs
+
+log_pass "Verify resumability of a full ZFS send/receive with the source " \
+    "filesystem unmounted"
diff --git a/tests/zfs-tests/tests/functional/rsend/setup.ksh b/tests/zfs-tests/tests/functional/rsend/setup.ksh
new file mode 100755 (executable)
index 0000000..8423adf
--- /dev/null
@@ -0,0 +1,45 @@
+#!/bin/ksh -p
+#
+# CDDL HEADER START
+#
+# The contents of this file are subject to the terms of the
+# Common Development and Distribution License (the "License").
+# You may not use this file except in compliance with the License.
+#
+# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
+# or http://www.opensolaris.org/os/licensing.
+# See the License for the specific language governing permissions
+# and limitations under the License.
+#
+# When distributing Covered Code, include this CDDL HEADER in each
+# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
+# If applicable, add the following below this CDDL HEADER, with the
+# fields enclosed by brackets "[]" replaced with your own identifying
+# information: Portions Copyright [yyyy] [name of copyright owner]
+#
+# CDDL HEADER END
+#
+
+#
+# Copyright 2009 Sun Microsystems, Inc.  All rights reserved.
+# Use is subject to license terms.
+#
+
+#
+# Copyright (c) 2013, 2014 by Delphix. All rights reserved.
+#
+
+. $STF_SUITE/tests/functional/rsend/rsend.kshlib
+
+verify_runnable "both"
+verify_disk_count "$DISKS" 2
+
+if is_global_zone ; then
+       log_must $ZPOOL create $POOL $DISK1
+       log_must $ZPOOL create $POOL2 $DISK2
+fi
+log_must $MKDIR $BACKDIR $TESTDIR
+
+log_must setup_test_model $POOL
+
+log_pass
diff --git a/tests/zfs-tests/tests/functional/scrub_mirror/Makefile.am b/tests/zfs-tests/tests/functional/scrub_mirror/Makefile.am
new file mode 100644 (file)
index 0000000..a14d32d
--- /dev/null
@@ -0,0 +1,10 @@
+pkgdatadir = $(datadir)/@PACKAGE@/zfs-tests/tests/functional/scrub_mirror
+dist_pkgdata_SCRIPTS = \
+       default.cfg \
+       scrub_mirror_common.kshlib \
+       setup.ksh \
+       cleanup.ksh \
+       scrub_mirror_001_pos.ksh \
+       scrub_mirror_002_pos.ksh \
+       scrub_mirror_003_pos.ksh \
+       scrub_mirror_004_pos.ksh
diff --git a/tests/zfs-tests/tests/functional/scrub_mirror/cleanup.ksh b/tests/zfs-tests/tests/functional/scrub_mirror/cleanup.ksh
new file mode 100755 (executable)
index 0000000..da628bc
--- /dev/null
@@ -0,0 +1,50 @@
+#!/bin/ksh -p
+#
+# CDDL HEADER START
+#
+# The contents of this file are subject to the terms of the
+# Common Development and Distribution License (the "License").
+# You may not use this file except in compliance with the License.
+#
+# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
+# or http://www.opensolaris.org/os/licensing.
+# See the License for the specific language governing permissions
+# and limitations under the License.
+#
+# When distributing Covered Code, include this CDDL HEADER in each
+# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
+# If applicable, add the following below this CDDL HEADER, with the
+# fields enclosed by brackets "[]" replaced with your own identifying
+# information: Portions Copyright [yyyy] [name of copyright owner]
+#
+# CDDL HEADER END
+#
+
+#
+# Copyright 2007 Sun Microsystems, Inc.  All rights reserved.
+# Use is subject to license terms.
+#
+
+#
+# Copyright (c) 2013 by Delphix. All rights reserved.
+#
+
+. $STF_SUITE/include/libtest.shlib
+. $STF_SUITE/tests/functional/scrub_mirror/default.cfg
+
+
+verify_runnable "global"
+
+$DF -F zfs -h | $GREP "$TESTFS " >/dev/null
+[[ $? == 0 ]] && log_must $ZFS umount -f $TESTDIR
+destroy_pool $TESTPOOL
+
+# recreate and destroy a zpool over the disks to restore the partitions to
+# normal
+if [[ -n $SINGLE_DISK ]]; then
+       log_must cleanup_devices $MIRROR_PRIMARY
+else
+       log_must cleanup_devices $MIRROR_PRIMARY $MIRROR_SECONDARY
+fi
+
+log_pass
diff --git a/tests/zfs-tests/tests/functional/scrub_mirror/default.cfg b/tests/zfs-tests/tests/functional/scrub_mirror/default.cfg
new file mode 100644 (file)
index 0000000..461212b
--- /dev/null
@@ -0,0 +1,70 @@
+#
+# CDDL HEADER START
+#
+# The contents of this file are subject to the terms of the
+# Common Development and Distribution License (the "License").
+# You may not use this file except in compliance with the License.
+#
+# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
+# or http://www.opensolaris.org/os/licensing.
+# See the License for the specific language governing permissions
+# and limitations under the License.
+#
+# When distributing Covered Code, include this CDDL HEADER in each
+# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
+# If applicable, add the following below this CDDL HEADER, with the
+# fields enclosed by brackets "[]" replaced with your own identifying
+# information: Portions Copyright [yyyy] [name of copyright owner]
+#
+# CDDL HEADER END
+#
+
+#
+# Copyright 2008 Sun Microsystems, Inc.  All rights reserved.
+# Use is subject to license terms.
+#
+
+#
+# Copyright (c) 2013 by Delphix. All rights reserved.
+#
+
+typeset -i NUMBER_OF_DISKS=0
+for i in $DISKS; do
+       [[ -n $MIRROR_PRIMARY ]] && MIRROR_SECONDARY=$i
+       [[ -z $MIRROR_PRIMARY ]] && MIRROR_PRIMARY=$i
+done
+
+if [[ -z $MIRROR_SECONDARY ]]; then
+       # We need to repartition the single disk to two slices
+       SINGLE_DISK=$MIRROR_PRIMARY
+       MIRROR_SECONDARY=$MIRROR_PRIMARY
+       SIDE_PRIMARY_PART=0
+       SIDE_SECONDARY_PART=1
+       if is_linux; then
+               SIDE_PRIMARY=${SINGLE_DISK}p1
+               SIDE_SECONDARY=${SINGLE_DISK}p2
+       else
+               SIDE_PRIMARY=${SINGLE_DISK}s${SIDE_PRIMARY_PART}
+               SIDE_SECONDARY=${SINGLE_DISK}s${SIDE_SECONDARY_PART}
+       fi
+else
+       SIDE_PRIMARY_PART=0
+       SIDE_SECONDARY_PART=0
+       if is_linux; then
+               SIDE_PRIMARY=${MIRROR_PRIMARY}p1
+               SIDE_SECONDARY=${MIRROR_SECONDARY}p1
+       else
+               SIDE_PRIMARY=${MIRROR_PRIMARY}s${SIDE_PRIMARY_PART}
+               SIDE_SECONDARY=${MIRROR_SECONDARY}s${SIDE_SECONDARY_PART}
+       fi
+fi
+
+
+export MIRROR_PRIMARY MIRROR_SECONDARY SINGLE_DISK SIDE_PRIMARY SIDE_SECONDARY
+
+export FILE_COUNT=10
+export FILE_SIZE=$(( 1024 * 1024 ))
+export MIRROR_MEGS=100
+export MIRROR_SIZE=${MIRROR_MEGS}m # default mirror size
+export DD_BLOCK=$(( 64 * 1024 ))
+export DD_COUNT=$(( MIRROR_MEGS * 1024 * 1024 / DD_BLOCK ))
diff --git a/tests/zfs-tests/tests/functional/scrub_mirror/scrub_mirror_001_pos.ksh b/tests/zfs-tests/tests/functional/scrub_mirror/scrub_mirror_001_pos.ksh
new file mode 100755 (executable)
index 0000000..841d8ab
--- /dev/null
@@ -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) 2013 by Delphix. All rights reserved.
+#
+
+. $STF_SUITE/include/libtest.shlib
+. $STF_SUITE/tests/functional/scrub_mirror/scrub_mirror_common.kshlib
+
+#
+# DESCRIPTION:
+# The primary side of a zpool mirror can be zeroed without causing damage
+# to the data in the pool
+#
+# STRATEGY:
+# 1) Write several files to the ZFS filesystem mirror
+# 2) dd from /dev/zero over the primary side of the mirror
+# 3) verify that all the file contents are unchanged on the file system
+#
+
+verify_runnable "global"
+
+log_assert "The primary side of a zpool mirror may be completely wiped" \
+       "without affecting the content of the pool"
+
+overwrite_verify_mirror $TESTPOOL $SIDE_PRIMARY /dev/zero
+
+log_pass "The overwrite had no effect on the data"
diff --git a/tests/zfs-tests/tests/functional/scrub_mirror/scrub_mirror_002_pos.ksh b/tests/zfs-tests/tests/functional/scrub_mirror/scrub_mirror_002_pos.ksh
new file mode 100755 (executable)
index 0000000..92cabd6
--- /dev/null
@@ -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) 2013 by Delphix. All rights reserved.
+#
+
+. $STF_SUITE/include/libtest.shlib
+. $STF_SUITE/tests/functional/scrub_mirror/scrub_mirror_common.kshlib
+
+#
+# DESCRIPTION:
+# The secondary side of a zpool mirror can be zeroed without causing damage
+# to the data in the pool
+#
+# STRATEGY:
+# 1) Write several files to the ZFS filesystem in the mirrored pool
+# 2) dd from /dev/zero over the secondary side of the mirror
+# 3) verify that all the file contents are unchanged on the file system
+#
+
+verify_runnable "global"
+
+log_assert "The primary side of a zpool mirror may be completely wiped" \
+       "without affecting the content of the pool"
+
+overwrite_verify_mirror $TESTPOOL $SIDE_SECONDARY /dev/zero
+
+log_pass "The overwrite had no effect on the data"
diff --git a/tests/zfs-tests/tests/functional/scrub_mirror/scrub_mirror_003_pos.ksh b/tests/zfs-tests/tests/functional/scrub_mirror/scrub_mirror_003_pos.ksh
new file mode 100755 (executable)
index 0000000..ecb4229
--- /dev/null
@@ -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) 2013 by Delphix. All rights reserved.
+#
+
+. $STF_SUITE/include/libtest.shlib
+. $STF_SUITE/tests/functional/scrub_mirror/scrub_mirror_common.kshlib
+
+#
+# DESCRIPTION:
+# The primary side of a zpool mirror can be mangled causing without damage
+# to the data in the pool
+#
+# STRATEGY:
+# 1) Write several files to the ZFS filesystem mirror
+# 2) dd from /dev/urandom over the primary side of the mirror
+# 3) verify that all the file contents are unchanged on the file system
+#
+
+verify_runnable "global"
+
+log_assert "The primary side of a zpool mirror may be completely mangled" \
+       "without affecting the content of the pool"
+
+overwrite_verify_mirror $TESTPOOL $SIDE_PRIMARY /dev/urandom
+
+log_pass "The overwrite did not have any effect on the data"
diff --git a/tests/zfs-tests/tests/functional/scrub_mirror/scrub_mirror_004_pos.ksh b/tests/zfs-tests/tests/functional/scrub_mirror/scrub_mirror_004_pos.ksh
new file mode 100755 (executable)
index 0000000..b863380
--- /dev/null
@@ -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) 2013 by Delphix. All rights reserved.
+#
+
+. $STF_SUITE/include/libtest.shlib
+. $STF_SUITE/tests/functional/scrub_mirror/scrub_mirror_common.kshlib
+
+#
+# DESCRIPTION:
+# The secondary side of a zpool mirror can be mangled causing without damage
+# to the data in the pool
+#
+# STRATEGY:
+# 1) Write several files to the ZFS filesystem in the mirrored pool
+# 2) dd from /dev/urandom over the secondary side of the mirror
+# 3) verify that all the file contents are unchanged on the file system
+#
+
+verify_runnable "global"
+
+log_assert "The primary side of a zpool mirror may be completely mangled" \
+       "without affecting the content of the pool"
+
+overwrite_verify_mirror $TESTPOOL $SIDE_SECONDARY /dev/urandom
+
+log_pass "The overwrite had no effect on the data"
diff --git a/tests/zfs-tests/tests/functional/scrub_mirror/scrub_mirror_common.kshlib b/tests/zfs-tests/tests/functional/scrub_mirror/scrub_mirror_common.kshlib
new file mode 100644 (file)
index 0000000..08450dc
--- /dev/null
@@ -0,0 +1,78 @@
+#
+# CDDL HEADER START
+#
+# The contents of this file are subject to the terms of the
+# Common Development and Distribution License (the "License").
+# You may not use this file except in compliance with the License.
+#
+# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
+# or http://www.opensolaris.org/os/licensing.
+# See the License for the specific language governing permissions
+# and limitations under the License.
+#
+# When distributing Covered Code, include this CDDL HEADER in each
+# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
+# If applicable, add the following below this CDDL HEADER, with the
+# fields enclosed by brackets "[]" replaced with your own identifying
+# information: Portions Copyright [yyyy] [name of copyright owner]
+#
+# CDDL HEADER END
+#
+
+#
+# Copyright 2007 Sun Microsystems, Inc.  All rights reserved.
+# Use is subject to license terms.
+#
+
+#
+# Copyright (c) 2013 by Delphix. All rights reserved.
+#
+. $STF_SUITE/tests/functional/scrub_mirror/default.cfg
+
+function overwrite_verify_mirror
+{
+       typeset POOL=$1
+       typeset AFFECTED_DEVICE=$2
+       typeset OVERWRITING_DEVICE=$3
+
+       typeset atfile=0
+       set -A files
+       set -A cksums
+       set -A newcksums
+
+       while (( atfile < FILE_COUNT )); do
+               files[$atfile]=$TESTDIR/file.$atfile
+               log_must $FILE_WRITE -o create -f $TESTDIR/file.$atfile \
+                       -b $FILE_SIZE -c 1
+               cksums[$atfile]=$($CKSUM ${files[$atfile]})
+               (( atfile = atfile + 1 ))
+       done
+
+       # dd the affected side of the mirror
+       log_must $DD if=$OVERWRITING_DEVICE of=${DEV_DSKDIR}/$AFFECTED_DEVICE \
+               seek=8 bs=$DD_BLOCK count=$(( DD_COUNT - 128 )) conv=notrunc
+
+       log_must $ZPOOL scrub $POOL
+
+       while is_pool_scrubbing $POOL; do
+               $SLEEP 2
+       done
+
+       atfile=0
+
+       typeset -i failedcount=0
+       while (( atfile < FILE_COUNT )); do
+               files[$atfile]=$TESTDIR/file.$atfile
+               newcksum=$($CKSUM ${files[$atfile]})
+               if [[ $newcksum != ${cksums[$atfile]} ]]; then
+                       (( failedcount = failedcount + 1 ))
+               fi
+               $RM -f ${files[$atfile]}
+               (( atfile = atfile + 1 ))
+       done
+
+       if (( $failedcount > 0 )); then
+               log_fail "of the $FILE_COUNT files $failedcount did not " \
+                   "have the same checksum before and after."
+       fi
+}
diff --git a/tests/zfs-tests/tests/functional/scrub_mirror/setup.ksh b/tests/zfs-tests/tests/functional/scrub_mirror/setup.ksh
new file mode 100755 (executable)
index 0000000..97a70d8
--- /dev/null
@@ -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 2009 Sun Microsystems, Inc.  All rights reserved.
+# Use is subject to license terms.
+#
+
+#
+# Copyright (c) 2013 by Delphix. All rights reserved.
+#
+
+. $STF_SUITE/include/libtest.shlib
+. $STF_SUITE/tests/functional/scrub_mirror/default.cfg
+
+verify_runnable "global"
+
+if ! $(is_physical_device $DISKS) ; then
+       log_unsupported "This directory cannot be run on raw files."
+fi
+
+if [[ -n $SINGLE_DISK ]]; then
+       log_note "Partitioning a single disk ($SINGLE_DISK)"
+else
+       log_note "Partitioning disks ($MIRROR_PRIMARY $MIRROR_SECONDARY)"
+fi
+log_must set_partition $SIDE_PRIMARY_PART "" $MIRROR_SIZE $MIRROR_PRIMARY
+log_must set_partition $SIDE_SECONDARY_PART "" $MIRROR_SIZE $MIRROR_SECONDARY
+
+default_mirror_setup $SIDE_PRIMARY $SIDE_SECONDARY
+
+log_pass
diff --git a/tests/zfs-tests/tests/functional/slog/Makefile.am b/tests/zfs-tests/tests/functional/slog/Makefile.am
new file mode 100644 (file)
index 0000000..c370472
--- /dev/null
@@ -0,0 +1,20 @@
+pkgdatadir = $(datadir)/@PACKAGE@/zfs-tests/tests/functional/slog
+dist_pkgdata_SCRIPTS = \
+       slog.cfg \
+       slog.kshlib \
+       setup.ksh \
+       cleanup.ksh \
+       slog_001_pos.ksh \
+       slog_002_pos.ksh \
+       slog_003_pos.ksh \
+       slog_004_pos.ksh \
+       slog_005_pos.ksh \
+       slog_006_pos.ksh \
+       slog_007_pos.ksh \
+       slog_008_neg.ksh \
+       slog_009_neg.ksh \
+       slog_010_neg.ksh \
+       slog_011_neg.ksh \
+       slog_012_neg.ksh \
+       slog_013_pos.ksh \
+       slog_014_pos.ksh
diff --git a/tests/zfs-tests/tests/functional/slog/cleanup.ksh b/tests/zfs-tests/tests/functional/slog/cleanup.ksh
new file mode 100755 (executable)
index 0000000..039135c
--- /dev/null
@@ -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.
+#
+
+#
+# Copyright (c) 2013 by Delphix. All rights reserved.
+#
+
+. $STF_SUITE/include/libtest.shlib
+. $STF_SUITE/tests/functional/slog/slog.cfg
+
+verify_runnable "global"
+
+if ! verify_slog_support ; then
+       log_unsupported "This system doesn't support separate intent logs"
+fi
+
+if datasetexists $TESTPOOL ; then
+       log_must $ZPOOL destroy -f $TESTPOOL
+fi
+if datasetexists $TESTPOOL2 ; then
+       log_must $ZPOOL destroy -f $TESTPOOL2
+fi
+if [[ -d $VDIR ]]; then
+       log_must $RM -rf $VDIR
+fi
+if [[ -d $VDIR2 ]]; then
+       log_must $RM -rf $VDIR2
+fi
+
+log_pass
diff --git a/tests/zfs-tests/tests/functional/slog/setup.ksh b/tests/zfs-tests/tests/functional/slog/setup.ksh
new file mode 100755 (executable)
index 0000000..28c07c9
--- /dev/null
@@ -0,0 +1,50 @@
+#!/bin/ksh -p
+#
+# CDDL HEADER START
+#
+# The contents of this file are subject to the terms of the
+# Common Development and Distribution License (the "License").
+# You may not use this file except in compliance with the License.
+#
+# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
+# or http://www.opensolaris.org/os/licensing.
+# See the License for the specific language governing permissions
+# and limitations under the License.
+#
+# When distributing Covered Code, include this CDDL HEADER in each
+# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
+# If applicable, add the following below this CDDL HEADER, with the
+# fields enclosed by brackets "[]" replaced with your own identifying
+# information: Portions Copyright [yyyy] [name of copyright owner]
+#
+# CDDL HEADER END
+#
+
+#
+# Copyright 2007 Sun Microsystems, Inc.  All rights reserved.
+# Use is subject to license terms.
+#
+
+#
+# Copyright (c) 2013 by Delphix. All rights reserved.
+#
+
+. $STF_SUITE/include/libtest.shlib
+. $STF_SUITE/tests/functional/slog/slog.cfg
+
+verify_runnable "global"
+
+if ! verify_slog_support ; then
+       log_unsupported "This system doesn't support separate intent logs"
+fi
+
+if [[ -d $VDEV ]]; then
+       log_must $RM -rf $VDIR
+fi
+if [[ -d $VDEV2 ]]; then
+       log_must $RM -rf $VDIR2
+fi
+log_must $MKDIR -p $VDIR $VDIR2
+log_must $MKFILE $SIZE $VDEV $SDEV $LDEV $VDEV2 $SDEV2 $LDEV2
+
+log_pass
diff --git a/tests/zfs-tests/tests/functional/slog/slog.cfg b/tests/zfs-tests/tests/functional/slog/slog.cfg
new file mode 100644 (file)
index 0000000..28cce1a
--- /dev/null
@@ -0,0 +1,41 @@
+#
+# CDDL HEADER START
+#
+# The contents of this file are subject to the terms of the
+# Common Development and Distribution License (the "License").
+# You may not use this file except in compliance with the License.
+#
+# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
+# or http://www.opensolaris.org/os/licensing.
+# See the License for the specific language governing permissions
+# and limitations under the License.
+#
+# When distributing Covered Code, include this CDDL HEADER in each
+# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
+# If applicable, add the following below this CDDL HEADER, with the
+# fields enclosed by brackets "[]" replaced with your own identifying
+# information: Portions Copyright [yyyy] [name of copyright owner]
+#
+# CDDL HEADER END
+#
+
+#
+# Copyright 2007 Sun Microsystems, Inc.  All rights reserved.
+# Use is subject to license terms.
+#
+
+#
+# Copyright (c) 2013 by Delphix. All rights reserved.
+#
+
+export SIZE=64M
+
+export VDIR=/disk-slog
+export VDIR2=/disk2-slog
+
+export VDEV="$VDIR/a $VDIR/b $VDIR/c"
+export SDEV="$VDIR/d"
+export LDEV="$VDIR/e $VDIR/f"
+export VDEV2="$VDIR2/a $VDIR2/b $VDIR2/c"
+export SDEV2="$VDIR2/d"
+export LDEV2="$VDIR2/e $VDIR2/f"
diff --git a/tests/zfs-tests/tests/functional/slog/slog.kshlib b/tests/zfs-tests/tests/functional/slog/slog.kshlib
new file mode 100644 (file)
index 0000000..124bfe6
--- /dev/null
@@ -0,0 +1,157 @@
+#
+# CDDL HEADER START
+#
+# The contents of this file are subject to the terms of the
+# Common Development and Distribution License (the "License").
+# You may not use this file except in compliance with the License.
+#
+# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
+# or http://www.opensolaris.org/os/licensing.
+# See the License for the specific language governing permissions
+# and limitations under the License.
+#
+# When distributing Covered Code, include this CDDL HEADER in each
+# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
+# If applicable, add the following below this CDDL HEADER, with the
+# fields enclosed by brackets "[]" replaced with your own identifying
+# information: Portions Copyright [yyyy] [name of copyright owner]
+#
+# CDDL HEADER END
+#
+
+#
+# Copyright 2008 Sun Microsystems, Inc.  All rights reserved.
+# Use is subject to license terms.
+#
+
+#
+# Copyright (c) 2013 by Delphix. All rights reserved.
+#
+
+. $STF_SUITE/include/libtest.shlib
+. $STF_SUITE/tests/functional/slog/slog.cfg
+
+function cleanup
+{
+       if datasetexists $TESTPOOL ; then
+               log_must $ZPOOL destroy -f $TESTPOOL
+       fi
+       if datasetexists $TESTPOOL2 ; then
+               log_must $ZPOOL destroy -f $TESTPOOL2
+       fi
+}
+
+#
+# Try zpool status/iostat for given pool
+#
+# $1 pool
+#
+function display_status
+{
+       typeset pool=$1
+
+       typeset -i ret=0
+       $ZPOOL status -xv $pool > /dev/null 2>&1
+       ret=$?
+
+       $ZPOOL iostat > /dev/null 2>&1
+       ((ret |= $?))
+
+       typeset mntpnt=$(get_prop mountpoint $pool)
+       $DD if=/dev/random of=$mntpnt/testfile.$$ &
+       typeset pid=$!
+
+       $ZPOOL iostat -v 1 3 > /dev/null
+       ((ret |= $?))
+
+       kill -9 $pid
+
+       return $ret
+}
+
+#
+# Verify the give slog device have correct type and status
+#
+# $1 pool name
+# $2 device name
+# $3 device status
+# $4 device type
+#
+function verify_slog_device
+{
+       typeset pool=$1
+       typeset device=$2
+       typeset status=$3
+       typeset type=$4
+
+       if [[ -z $pool || -z $device || -z $status ]]; then
+               log_fail "Usage: verify_slog_device <pool> <device> " \
+                       "<status> [type]"
+       fi
+
+       if [[ $WRAPPER == *"smi"* ]]; then
+               $ECHO $device | $EGREP "^c[0-F]+([td][0-F]+)+$" > /dev/null 2>&1
+               if (( $? == 0 )); then
+                       device=${device}s2
+               fi
+       fi
+
+       #
+       # Get all the slog devices and status table like below
+       #
+       # mirror:/disks/d ONLINE mirror:/disks/e ONLINE stripe:/disks/f ONLINE
+       #
+       set -A dev_stat_tab $($ZPOOL status -v $pool | $NAWK 'BEGIN {start=0} \
+                               /\tlogs/ {start=1}
+                               /\tmirror/ || /\tspares/ || /^$/ {start=0}
+                               (start==1) && /\t  (\/|[a-zA-Z])/ \
+                                       {print "stripe:" $1 " " $2}
+                               (start==1) && /\t    (\/|[a-zA-Z])/ \
+                                       {print "mirror:" $1 " " $2}
+                               # When hotspare is replacing
+                               (start==1) && /\t      (\/|[a-zA-Z])/ \
+                                       {print "mirror:" $1 " " $2}'
+                            )
+
+       typeset -i i=0
+       typeset find=0
+       while (( i < ${#dev_stat_tab[@]} )); do
+               typeset dev=${dev_stat_tab[$i]}
+               typeset stat=${dev_stat_tab[((i+1))]}
+
+               case $dev in
+                       stripe:$device)
+                               if [[ "$type" == 'mirror' ]]; then
+                                       log_note "Unexpected type: mirror"
+                                       return 1
+                               else
+                                       if [[ $stat != $status ]]; then
+                                               log_note "Status($stat) " \
+                                                       "!= Expected stat($status)"
+                                               return 1
+                                       fi
+                                       return 0
+                               fi
+                               ;;
+                       mirror:$device)
+                               if [[ -z "$type" || $type == 'stripe' ]]; then
+                                       log_note "Unexpected type: stripe"
+                                       return 1
+                               else
+                                       if [[ $stat != $status ]]; then
+                                               log_note "Status($stat) " \
+                                                       "!= Expected stat($status)"
+                                               return 1
+                                       fi
+                                       return 0
+                               fi
+                               ;;
+               esac
+
+               ((i += 2))
+       done
+
+       log_note "Can not find device: $device"
+
+       return 1
+}
diff --git a/tests/zfs-tests/tests/functional/slog/slog_001_pos.ksh b/tests/zfs-tests/tests/functional/slog/slog_001_pos.ksh
new file mode 100755 (executable)
index 0000000..c6adaa4
--- /dev/null
@@ -0,0 +1,68 @@
+#!/bin/ksh -p
+#
+# CDDL HEADER START
+#
+# The contents of this file are subject to the terms of the
+# Common Development and Distribution License (the "License").
+# You may not use this file except in compliance with the License.
+#
+# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
+# or http://www.opensolaris.org/os/licensing.
+# See the License for the specific language governing permissions
+# and limitations under the License.
+#
+# When distributing Covered Code, include this CDDL HEADER in each
+# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
+# If applicable, add the following below this CDDL HEADER, with the
+# fields enclosed by brackets "[]" replaced with your own identifying
+# information: Portions Copyright [yyyy] [name of copyright owner]
+#
+# CDDL HEADER END
+#
+
+#
+# Copyright 2007 Sun Microsystems, Inc.  All rights reserved.
+# Use is subject to license terms.
+#
+
+#
+# Copyright (c) 2013 by Delphix. All rights reserved.
+#
+
+. $STF_SUITE/tests/functional/slog/slog.kshlib
+
+#
+# DESCRIPTION:
+#      Creating a pool with a log device succeeds.
+#
+# STRATEGY:
+#      1. Create pool with separated log devices.
+#      2. Display pool status
+#      3. Destroy and loop to create pool with different configuration.
+#
+
+verify_runnable "global"
+
+log_assert "Creating a pool with a log device succeeds."
+log_onexit cleanup
+
+for type in "" "mirror" "raidz" "raidz2"
+do
+       for spare in "" "spare"
+       do
+               for logtype in "" "mirror"
+               do
+                       log_must $ZPOOL create $TESTPOOL $type $VDEV \
+                               $spare $SDEV log $logtype $LDEV
+                       log_must display_status $TESTPOOL
+
+                       ldev=$(random_get $LDEV)
+                       log_must verify_slog_device \
+                               $TESTPOOL $ldev 'ONLINE' $logtype
+
+                       log_must $ZPOOL destroy -f $TESTPOOL
+               done
+       done
+done
+
+log_pass "Creating a pool with a log device succeeds."
diff --git a/tests/zfs-tests/tests/functional/slog/slog_002_pos.ksh b/tests/zfs-tests/tests/functional/slog/slog_002_pos.ksh
new file mode 100755 (executable)
index 0000000..9062772
--- /dev/null
@@ -0,0 +1,67 @@
+#!/bin/ksh -p
+#
+# CDDL HEADER START
+#
+# The contents of this file are subject to the terms of the
+# Common Development and Distribution License (the "License").
+# You may not use this file except in compliance with the License.
+#
+# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
+# or http://www.opensolaris.org/os/licensing.
+# See the License for the specific language governing permissions
+# and limitations under the License.
+#
+# When distributing Covered Code, include this CDDL HEADER in each
+# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
+# If applicable, add the following below this CDDL HEADER, with the
+# fields enclosed by brackets "[]" replaced with your own identifying
+# information: Portions Copyright [yyyy] [name of copyright owner]
+#
+# CDDL HEADER END
+#
+
+#
+# Copyright 2007 Sun Microsystems, Inc.  All rights reserved.
+# Use is subject to license terms.
+#
+
+#
+# Copyright (c) 2013 by Delphix. All rights reserved.
+#
+
+. $STF_SUITE/tests/functional/slog/slog.kshlib
+
+#
+# DESCRIPTION:
+#      Adding a log device to normal pool works.
+#
+# STRATEGY:
+#      1. Create pool
+#      2. Add log devices with different configuration
+#      3. Display pool status
+#      4. Destroy and loop to create pool with different configuration.
+#
+
+verify_runnable "global"
+
+log_assert "Adding a log device to normal pool works."
+log_onexit cleanup
+
+for type in "" "mirror" "raidz" "raidz2"
+do
+       for spare in "" "spare"
+       do
+               for logtype in "" "mirror"
+               do
+                       log_must $ZPOOL create $TESTPOOL $type $VDEV $spare $SDEV
+                       log_must $ZPOOL add $TESTPOOL log $logtype $LDEV
+                       log_must display_status $TESTPOOL
+                       typeset ldev=$(random_get $LDEV)
+                       log_must verify_slog_device \
+                               $TESTPOOL $ldev 'ONLINE' $logtype
+                       log_must $ZPOOL destroy -f $TESTPOOL
+               done
+       done
+done
+
+log_pass "Adding a log device to normal pool works."
diff --git a/tests/zfs-tests/tests/functional/slog/slog_003_pos.ksh b/tests/zfs-tests/tests/functional/slog/slog_003_pos.ksh
new file mode 100755 (executable)
index 0000000..5a28066
--- /dev/null
@@ -0,0 +1,74 @@
+#!/bin/ksh -p
+#
+# CDDL HEADER START
+#
+# The contents of this file are subject to the terms of the
+# Common Development and Distribution License (the "License").
+# You may not use this file except in compliance with the License.
+#
+# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
+# or http://www.opensolaris.org/os/licensing.
+# See the License for the specific language governing permissions
+# and limitations under the License.
+#
+# When distributing Covered Code, include this CDDL HEADER in each
+# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
+# If applicable, add the following below this CDDL HEADER, with the
+# fields enclosed by brackets "[]" replaced with your own identifying
+# information: Portions Copyright [yyyy] [name of copyright owner]
+#
+# CDDL HEADER END
+#
+
+#
+# Copyright 2007 Sun Microsystems, Inc.  All rights reserved.
+# Use is subject to license terms.
+#
+
+#
+# Copyright (c) 2013 by Delphix. All rights reserved.
+#
+
+. $STF_SUITE/tests/functional/slog/slog.kshlib
+
+#
+# DESCRIPTION:
+#      Adding an extra log device works
+#
+# STRATEGY:
+#      1. Create pool with separated log devices.
+#      2. Add an extra log devices
+#      3. Display pool status
+#      4. Destroy and loop to create pool with different configuration.
+#
+
+verify_runnable "global"
+
+log_assert "Adding an extra log device works."
+log_onexit cleanup
+
+for type in "" "mirror" "raidz" "raidz2"
+do
+       for spare in "" "spare"
+       do
+               for logtype in "" "mirror"
+               do
+                       for newtype in "" "mirror"
+                       do
+                               log_must $ZPOOL create $TESTPOOL $type $VDEV \
+                                       $spare $SDEV log $logtype $LDEV
+                               log_must $ZPOOL add $TESTPOOL \
+                                       log $newtype $LDEV2
+
+                               log_must display_status $TESTPOOL
+                               ldev=$(random_get $LDEV2)
+                               log_must verify_slog_device \
+                                       $TESTPOOL $ldev 'ONLINE' $newtype
+
+                               log_must $ZPOOL destroy -f $TESTPOOL
+                       done
+               done
+       done
+done
+
+log_pass "Adding an extra log device works."
diff --git a/tests/zfs-tests/tests/functional/slog/slog_004_pos.ksh b/tests/zfs-tests/tests/functional/slog/slog_004_pos.ksh
new file mode 100755 (executable)
index 0000000..83806d0
--- /dev/null
@@ -0,0 +1,73 @@
+#!/bin/ksh -p
+#
+# CDDL HEADER START
+#
+# The contents of this file are subject to the terms of the
+# Common Development and Distribution License (the "License").
+# You may not use this file except in compliance with the License.
+#
+# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
+# or http://www.opensolaris.org/os/licensing.
+# See the License for the specific language governing permissions
+# and limitations under the License.
+#
+# When distributing Covered Code, include this CDDL HEADER in each
+# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
+# If applicable, add the following below this CDDL HEADER, with the
+# fields enclosed by brackets "[]" replaced with your own identifying
+# information: Portions Copyright [yyyy] [name of copyright owner]
+#
+# CDDL HEADER END
+#
+
+#
+# Copyright 2007 Sun Microsystems, Inc.  All rights reserved.
+# Use is subject to license terms.
+#
+
+#
+# Copyright (c) 2013 by Delphix. All rights reserved.
+#
+
+. $STF_SUITE/tests/functional/slog/slog.kshlib
+
+#
+# DESCRIPTION:
+#      Attaching a log device passes.
+#
+# STRATEGY:
+#      1. Create pool with separated log devices.
+#      2. Attaching a log device for existing log device
+#      3. Display pool status
+#      4. Destroy and loop to create pool with different configuration.
+#
+
+verify_runnable "global"
+
+log_assert "Attaching a log device passes."
+log_onexit cleanup
+
+for type in "" "mirror" "raidz" "raidz2"
+do
+       for spare in "" "spare"
+       do
+               for logtype in "" "mirror"
+               do
+                       log_must $ZPOOL create $TESTPOOL $type $VDEV \
+                               $spare $SDEV log $logtype $LDEV
+
+                       ldev=$(random_get $LDEV)
+                       typeset ldev2=$(random_get $LDEV2)
+                       log_must $ZPOOL attach $TESTPOOL $ldev $ldev2
+                       log_must display_status $TESTPOOL
+                       log_must verify_slog_device \
+                               $TESTPOOL $ldev 'ONLINE' 'mirror'
+                       log_must verify_slog_device \
+                               $TESTPOOL $ldev2 'ONLINE' 'mirror'
+
+                       log_must $ZPOOL destroy -f $TESTPOOL
+               done
+       done
+done
+
+log_pass "Attaching a log device passes."
diff --git a/tests/zfs-tests/tests/functional/slog/slog_005_pos.ksh b/tests/zfs-tests/tests/functional/slog/slog_005_pos.ksh
new file mode 100755 (executable)
index 0000000..f40fc5a
--- /dev/null
@@ -0,0 +1,65 @@
+#!/bin/ksh -p
+#
+# CDDL HEADER START
+#
+# The contents of this file are subject to the terms of the
+# Common Development and Distribution License (the "License").
+# You may not use this file except in compliance with the License.
+#
+# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
+# or http://www.opensolaris.org/os/licensing.
+# See the License for the specific language governing permissions
+# and limitations under the License.
+#
+# When distributing Covered Code, include this CDDL HEADER in each
+# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
+# If applicable, add the following below this CDDL HEADER, with the
+# fields enclosed by brackets "[]" replaced with your own identifying
+# information: Portions Copyright [yyyy] [name of copyright owner]
+#
+# CDDL HEADER END
+#
+
+#
+# Copyright 2007 Sun Microsystems, Inc.  All rights reserved.
+# Use is subject to license terms.
+#
+
+#
+# Copyright (c) 2013 by Delphix. All rights reserved.
+#
+
+. $STF_SUITE/tests/functional/slog/slog.kshlib
+
+#
+# DESCRIPTION:
+#      Detaching a log device passes.
+#
+# STRATEGY:
+#      1. Create pool with mirror log devices.
+#      2. Detaching a log device
+#      3. Display pool status
+#      4. Destroy and loop to create pool with different configuration.
+#
+
+verify_runnable "global"
+
+log_assert "Detaching a log device passes."
+log_onexit cleanup
+
+for type in "" "mirror" "raidz" "raidz2"
+do
+       for spare in "" "spare"
+       do
+               log_must $ZPOOL create $TESTPOOL $type $VDEV $spare $SDEV \
+                       log mirror $LDEV mirror $LDEV2
+               ldev=$(random_get $LDEV $LDEV2)
+               log_must $ZPOOL detach $TESTPOOL $ldev
+               log_must display_status $TESTPOOL
+               log_mustnot verify_slog_device $TESTPOOL $ldev 'ONLINE' 'mirror'
+
+               log_must $ZPOOL destroy -f $TESTPOOL
+       done
+done
+
+log_pass "Detaching a log device passes."
diff --git a/tests/zfs-tests/tests/functional/slog/slog_006_pos.ksh b/tests/zfs-tests/tests/functional/slog/slog_006_pos.ksh
new file mode 100755 (executable)
index 0000000..b93f64a
--- /dev/null
@@ -0,0 +1,72 @@
+#!/bin/ksh -p
+#
+# CDDL HEADER START
+#
+# The contents of this file are subject to the terms of the
+# Common Development and Distribution License (the "License").
+# You may not use this file except in compliance with the License.
+#
+# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
+# or http://www.opensolaris.org/os/licensing.
+# See the License for the specific language governing permissions
+# and limitations under the License.
+#
+# When distributing Covered Code, include this CDDL HEADER in each
+# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
+# If applicable, add the following below this CDDL HEADER, with the
+# fields enclosed by brackets "[]" replaced with your own identifying
+# information: Portions Copyright [yyyy] [name of copyright owner]
+#
+# CDDL HEADER END
+#
+
+#
+# Copyright 2007 Sun Microsystems, Inc.  All rights reserved.
+# Use is subject to license terms.
+#
+
+#
+# Copyright (c) 2013 by Delphix. All rights reserved.
+#
+
+. $STF_SUITE/tests/functional/slog/slog.kshlib
+
+#
+# DESCRIPTION:
+#      Replacing a log device passes.
+#
+# STRATEGY:
+#      1. Create pool with log devices.
+#      2. Replacing one log device
+#      3. Display pool status
+#      4. Destroy and loop to create pool with different configuration.
+#
+
+verify_runnable "global"
+
+log_assert "Replacing a log device passes."
+log_onexit cleanup
+
+for type in "" "mirror" "raidz" "raidz2"
+do
+       for spare in "" "spare"
+       do
+               for logtype in "" "mirror"
+               do
+                       log_must $ZPOOL create $TESTPOOL $type $VDEV \
+                               $spare $SDEV log $logtype $LDEV
+                       sdev=$(random_get $LDEV)
+                       tdev=$(random_get $LDEV2)
+                       log_must $ZPOOL replace $TESTPOOL $sdev $tdev
+                       log_must display_status $TESTPOOL
+                       # sleep 15 to make sure replacement completely.
+                       log_must $SLEEP 15
+                       log_must verify_slog_device \
+                               $TESTPOOL $tdev 'ONLINE' $logtype
+
+                       log_must $ZPOOL destroy -f $TESTPOOL
+               done
+       done
+done
+
+log_pass "Replacing a log device passes."
diff --git a/tests/zfs-tests/tests/functional/slog/slog_007_pos.ksh b/tests/zfs-tests/tests/functional/slog/slog_007_pos.ksh
new file mode 100755 (executable)
index 0000000..c643301
--- /dev/null
@@ -0,0 +1,93 @@
+#!/bin/ksh -p
+#
+# CDDL HEADER START
+#
+# The contents of this file are subject to the terms of the
+# Common Development and Distribution License (the "License").
+# You may not use this file except in compliance with the License.
+#
+# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
+# or http://www.opensolaris.org/os/licensing.
+# See the License for the specific language governing permissions
+# and limitations under the License.
+#
+# When distributing Covered Code, include this CDDL HEADER in each
+# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
+# If applicable, add the following below this CDDL HEADER, with the
+# fields enclosed by brackets "[]" replaced with your own identifying
+# information: Portions Copyright [yyyy] [name of copyright owner]
+#
+# CDDL HEADER END
+#
+
+#
+# Copyright 2007 Sun Microsystems, Inc.  All rights reserved.
+# Use is subject to license terms.
+#
+
+#
+# Copyright (c) 2013 by Delphix. All rights reserved.
+#
+
+. $STF_SUITE/tests/functional/slog/slog.kshlib
+
+#
+# DESCRIPTION:
+#      Exporting and importing pool with log devices passes.
+#
+# STRATEGY:
+#      1. Create pool with log devices.
+#      2. Export and import the pool
+#      3. Display pool status
+#      4. Destroy and import the pool again
+#      5. Display pool status
+#      6. Destroy and loop to create pool with different configuration.
+#
+
+verify_runnable "global"
+
+log_assert "Exporting and importing pool with log devices passes."
+log_onexit cleanup
+
+for type in "" "mirror" "raidz" "raidz2"
+do
+       for spare in "" "spare"
+       do
+               for logtype in "" "mirror"
+               do
+                       #
+                       # Create pool which devices resider in different
+                       # directory
+                       #
+                       log_must $ZPOOL create $TESTPOOL $type $VDEV \
+                               $spare $SDEV log $logtype $LDEV $LDEV2
+                       ldev=$(random_get $LDEV $LDEV2)
+                       log_must verify_slog_device \
+                               $TESTPOOL $ldev 'ONLINE' $logtype
+
+                       #
+                       # Nomal export/import operating
+                       #
+                       log_must $ZPOOL export $TESTPOOL
+                       log_must $ZPOOL import -d $VDIR -d $VDIR2 $TESTPOOL
+                       log_must display_status $TESTPOOL
+                       ldev=$(random_get $LDEV $LDEV2)
+                       log_must verify_slog_device \
+                               $TESTPOOL $ldev 'ONLINE' $logtype
+
+                       #
+                       # Destroy the pool and import again
+                       #
+                       log_must $ZPOOL destroy $TESTPOOL
+                       log_must $ZPOOL import -Df -d $VDIR -d $VDIR2 $TESTPOOL
+                       log_must display_status $TESTPOOL
+                       ldev=$(random_get $LDEV $LDEV2)
+                       log_must verify_slog_device \
+                               $TESTPOOL $ldev 'ONLINE' $logtype
+
+                       log_must $ZPOOL destroy -f $TESTPOOL
+               done
+       done
+done
+
+log_pass "Exporting and importing pool with log devices passes."
diff --git a/tests/zfs-tests/tests/functional/slog/slog_008_neg.ksh b/tests/zfs-tests/tests/functional/slog/slog_008_neg.ksh
new file mode 100755 (executable)
index 0000000..b924356
--- /dev/null
@@ -0,0 +1,64 @@
+#!/bin/ksh -p
+#
+# CDDL HEADER START
+#
+# The contents of this file are subject to the terms of the
+# Common Development and Distribution License (the "License").
+# You may not use this file except in compliance with the License.
+#
+# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
+# or http://www.opensolaris.org/os/licensing.
+# See the License for the specific language governing permissions
+# and limitations under the License.
+#
+# When distributing Covered Code, include this CDDL HEADER in each
+# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
+# If applicable, add the following below this CDDL HEADER, with the
+# fields enclosed by brackets "[]" replaced with your own identifying
+# information: Portions Copyright [yyyy] [name of copyright owner]
+#
+# CDDL HEADER END
+#
+
+#
+# Copyright 2007 Sun Microsystems, Inc.  All rights reserved.
+# Use is subject to license terms.
+#
+
+#
+# Copyright (c) 2013 by Delphix. All rights reserved.
+#
+
+. $STF_SUITE/tests/functional/slog/slog.kshlib
+
+#
+# DESCRIPTION:
+#      A raidz/raidz2 log is not supported.
+#
+# STRATEGY:
+#      1. Try to create pool with unsupported type
+#      2. Verify failed to create pool.
+#
+
+verify_runnable "global"
+
+log_assert "A raidz/raidz2 log is not supported."
+log_onexit cleanup
+
+for type in "" "mirror" "raidz" "raidz2"
+do
+       for spare in "" "spare"
+       do
+               for logtype in "raidz" "raidz1" "raidz2"
+               do
+                       log_mustnot $ZPOOL create $TESTPOOL $type $VDEV \
+                               $spare $SDEV log $logtype $LDEV $LDEV2
+                       ldev=$(random_get $LDEV $LDEV2)
+                       log_mustnot verify_slog_device \
+                               $TESTPOOL $ldev 'ONLINE' $logtype
+                       log_must datasetnonexists $TESTPOOL
+               done
+       done
+done
+
+log_pass "A raidz/raidz2 log is not supported."
diff --git a/tests/zfs-tests/tests/functional/slog/slog_009_neg.ksh b/tests/zfs-tests/tests/functional/slog/slog_009_neg.ksh
new file mode 100755 (executable)
index 0000000..9b195bd
--- /dev/null
@@ -0,0 +1,69 @@
+#!/bin/ksh -p
+#
+# CDDL HEADER START
+#
+# The contents of this file are subject to the terms of the
+# Common Development and Distribution License (the "License").
+# You may not use this file except in compliance with the License.
+#
+# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
+# or http://www.opensolaris.org/os/licensing.
+# See the License for the specific language governing permissions
+# and limitations under the License.
+#
+# When distributing Covered Code, include this CDDL HEADER in each
+# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
+# If applicable, add the following below this CDDL HEADER, with the
+# fields enclosed by brackets "[]" replaced with your own identifying
+# information: Portions Copyright [yyyy] [name of copyright owner]
+#
+# CDDL HEADER END
+#
+
+#
+# Copyright 2007 Sun Microsystems, Inc.  All rights reserved.
+# Use is subject to license terms.
+#
+
+#
+# Copyright (c) 2013 by Delphix. All rights reserved.
+#
+
+. $STF_SUITE/tests/functional/slog/slog.kshlib
+
+#
+# DESCRIPTION:
+#      A raidz/raidz2 log can not be added to existed pool.
+#
+# STRATEGY:
+#      1. Create pool with or without log.
+#      2. Add a raidz/raidz2 log to this pool.
+#      3. Verify failed to add.
+#
+
+verify_runnable "global"
+
+log_assert "A raidz/raidz2 log can not be added to existed pool."
+log_onexit cleanup
+
+for type in "" "mirror" "raidz" "raidz2"
+do
+       for spare in "" "spare"
+       do
+               for logtype in "raidz" "raidz1" "raidz2"
+               do
+                       log=$(random_get_with_non "log")
+                       log_must $ZPOOL create $TESTPOOL $type $VDEV \
+                               $spare $SDEV $log $LDEV
+
+                       log_mustnot $ZPOOL add $TESTPOOL log $logtype $LDEV2
+                       ldev=$(random_get $LDEV2)
+                       log_mustnot verify_slog_device \
+                               $TESTPOOL $ldev 'ONLINE' $logtype
+
+                       log_must $ZPOOL destroy $TESTPOOL
+               done
+       done
+done
+
+log_pass "A raidz/raidz2 log can not be added to existed pool."
diff --git a/tests/zfs-tests/tests/functional/slog/slog_010_neg.ksh b/tests/zfs-tests/tests/functional/slog/slog_010_neg.ksh
new file mode 100755 (executable)
index 0000000..a5e79f0
--- /dev/null
@@ -0,0 +1,64 @@
+#!/bin/ksh -p
+#
+# CDDL HEADER START
+#
+# The contents of this file are subject to the terms of the
+# Common Development and Distribution License (the "License").
+# You may not use this file except in compliance with the License.
+#
+# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
+# or http://www.opensolaris.org/os/licensing.
+# See the License for the specific language governing permissions
+# and limitations under the License.
+#
+# When distributing Covered Code, include this CDDL HEADER in each
+# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
+# If applicable, add the following below this CDDL HEADER, with the
+# fields enclosed by brackets "[]" replaced with your own identifying
+# information: Portions Copyright [yyyy] [name of copyright owner]
+#
+# CDDL HEADER END
+#
+
+#
+# Copyright 2007 Sun Microsystems, Inc.  All rights reserved.
+# Use is subject to license terms.
+#
+
+#
+# Copyright (c) 2013 by Delphix. All rights reserved.
+#
+
+. $STF_SUITE/tests/functional/slog/slog.kshlib
+
+#
+# DESCRIPTION:
+#      Slog device can not be replaced with spare device
+#
+# STRATEGY:
+#      1. Create a pool with hotspare and log devices.
+#      2. Verify slog device can not be replaced with hotspare device.
+#      3. Create pool2 with hotspare
+#      4. Verify slog device can not be replaced with hotspare device in pool2.
+#
+
+verify_runnable "global"
+
+log_assert "Slog device can not be replaced with spare device."
+log_onexit cleanup
+
+log_must $ZPOOL create $TESTPOOL $VDEV spare $SDEV log $LDEV
+sdev=$(random_get $SDEV)
+ldev=$(random_get $LDEV)
+log_mustnot $ZPOOL replace $TESTPOOL $ldev $sdev
+log_mustnot verify_slog_device $TESTPOOL $sdev 'ONLINE'
+log_must verify_slog_device $TESTPOOL $ldev 'ONLINE'
+
+log_must $ZPOOL create $TESTPOOL2 $VDEV2 spare $SDEV2
+sdev2=$(random_get $SDEV2)
+log_mustnot $ZPOOL replace $TESTPOOL $ldev $sdev2
+log_mustnot $ZPOOL replace -f $TESTPOOL $ldev $sdev2
+log_mustnot verify_slog_device $TESTPOOL $sdev2 'ONLINE'
+log_must verify_slog_device $TESTPOOL $ldev 'ONLINE'
+
+log_pass "Slog device can not be replaced with spare device."
diff --git a/tests/zfs-tests/tests/functional/slog/slog_011_neg.ksh b/tests/zfs-tests/tests/functional/slog/slog_011_neg.ksh
new file mode 100755 (executable)
index 0000000..d2fd334
--- /dev/null
@@ -0,0 +1,70 @@
+#!/bin/ksh -p
+#
+# CDDL HEADER START
+#
+# The contents of this file are subject to the terms of the
+# Common Development and Distribution License (the "License").
+# You may not use this file except in compliance with the License.
+#
+# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
+# or http://www.opensolaris.org/os/licensing.
+# See the License for the specific language governing permissions
+# and limitations under the License.
+#
+# When distributing Covered Code, include this CDDL HEADER in each
+# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
+# If applicable, add the following below this CDDL HEADER, with the
+# fields enclosed by brackets "[]" replaced with your own identifying
+# information: Portions Copyright [yyyy] [name of copyright owner]
+#
+# CDDL HEADER END
+#
+
+#
+# Copyright 2007 Sun Microsystems, Inc.  All rights reserved.
+# Use is subject to license terms.
+#
+
+#
+# Copyright (c) 2013 by Delphix. All rights reserved.
+#
+
+. $STF_SUITE/tests/functional/slog/slog.kshlib
+
+#
+# DESCRIPTION:
+#      Offline and online a log device passes.
+#
+# STRATEGY:
+#      1. Create pool with mirror log devices.
+#      2. Offine and online a log device
+#      3. Display pool status
+#      4. Destroy and loop to create pool with different configuration.
+#
+
+verify_runnable "global"
+
+log_assert "Offline and online a log device passes."
+log_onexit cleanup
+
+for type in "" "mirror" "raidz" "raidz2"
+do
+       for spare in "" "spare"
+       do
+               log_must $ZPOOL create $TESTPOOL $type $VDEV $spare $SDEV \
+                       log mirror $LDEV mirror $LDEV2
+
+               ldev=$(random_get $LDEV $LDEV2)
+               log_must $ZPOOL offline $TESTPOOL $ldev
+               log_must display_status $TESTPOOL
+               log_must verify_slog_device $TESTPOOL $ldev 'OFFLINE' 'mirror'
+
+               log_must $ZPOOL online $TESTPOOL $ldev
+               log_must display_status $TESTPOOL
+               log_must verify_slog_device $TESTPOOL $ldev 'ONLINE' 'mirror'
+
+               log_must $ZPOOL destroy -f $TESTPOOL
+       done
+done
+
+log_pass "Offline and online a log device passes."
diff --git a/tests/zfs-tests/tests/functional/slog/slog_012_neg.ksh b/tests/zfs-tests/tests/functional/slog/slog_012_neg.ksh
new file mode 100755 (executable)
index 0000000..76cbf15
--- /dev/null
@@ -0,0 +1,73 @@
+#!/bin/ksh -p
+#
+# CDDL HEADER START
+#
+# The contents of this file are subject to the terms of the
+# Common Development and Distribution License (the "License").
+# You may not use this file except in compliance with the License.
+#
+# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
+# or http://www.opensolaris.org/os/licensing.
+# See the License for the specific language governing permissions
+# and limitations under the License.
+#
+# When distributing Covered Code, include this CDDL HEADER in each
+# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
+# If applicable, add the following below this CDDL HEADER, with the
+# fields enclosed by brackets "[]" replaced with your own identifying
+# information: Portions Copyright [yyyy] [name of copyright owner]
+#
+# CDDL HEADER END
+#
+
+#
+# Copyright 2007 Sun Microsystems, Inc.  All rights reserved.
+# Use is subject to license terms.
+#
+
+#
+# Copyright (c) 2013 by Delphix. All rights reserved.
+#
+
+. $STF_SUITE/tests/functional/slog/slog.kshlib
+
+#
+# DESCRIPTION:
+#      Pool can survive when one of mirror log device get corrupted
+#
+# STRATEGY:
+#      1. Create pool with mirror slog devices
+#      2. Make corrupted on one disk
+#      3. Verify the pool is fine
+#
+
+verify_runnable "global"
+
+log_assert "Pool can survive when one of mirror log device get corrupted."
+log_onexit cleanup
+
+for type in "" "mirror" "raidz" "raidz2"
+do
+       for spare in "" "spare"
+       do
+               log_must $ZPOOL create $TESTPOOL $type $VDEV $spare $SDEV \
+                       log mirror $LDEV
+
+               mntpnt=$(get_prop mountpoint $TESTPOOL)
+               #
+               # Create file in pool to trigger writting in slog devices
+               #
+               log_must $DD if=/dev/urandom of=$mntpnt/testfile.$$ count=100
+
+               ldev=$(random_get $LDEV)
+               log_must $MKFILE $SIZE $ldev
+               log_must $ZPOOL scrub $TESTPOOL
+
+               log_must display_status $TESTPOOL
+               log_must verify_slog_device $TESTPOOL $ldev 'UNAVAIL' 'mirror'
+
+               log_must $ZPOOL destroy -f $TESTPOOL
+       done
+done
+
+log_pass "Pool can survive when one of mirror log device get corrupted."
diff --git a/tests/zfs-tests/tests/functional/slog/slog_013_pos.ksh b/tests/zfs-tests/tests/functional/slog/slog_013_pos.ksh
new file mode 100755 (executable)
index 0000000..b2a16b0
--- /dev/null
@@ -0,0 +1,94 @@
+#!/bin/ksh -p
+#
+# CDDL HEADER START
+#
+# The contents of this file are subject to the terms of the
+# Common Development and Distribution License (the "License").
+# You may not use this file except in compliance with the License.
+#
+# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
+# or http://www.opensolaris.org/os/licensing.
+# See the License for the specific language governing permissions
+# and limitations under the License.
+#
+# When distributing Covered Code, include this CDDL HEADER in each
+# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
+# If applicable, add the following below this CDDL HEADER, with the
+# fields enclosed by brackets "[]" replaced with your own identifying
+# information: Portions Copyright [yyyy] [name of copyright owner]
+#
+# CDDL HEADER END
+#
+
+#
+# Copyright 2009 Sun Microsystems, Inc.  All rights reserved.
+# Use is subject to license terms.
+#
+
+#
+# Copyright (c) 2013 by Delphix. All rights reserved.
+#
+
+. $STF_SUITE/tests/functional/slog/slog.kshlib
+
+#
+# DESCRIPTION:
+#      Verify slog device can be disk, file, lofi device or any device that
+#      presents a block interface.
+#
+# STRATEGY:
+#      1. Create a pool
+#      2. Loop to add different object as slog
+#      3. Verify it passes
+#
+
+verify_runnable "global"
+
+function cleanup_testenv
+{
+       cleanup
+       if datasetexists $TESTPOOL2 ; then
+               log_must $ZPOOL destroy -f $TESTPOOL2
+       fi
+       if [[ -n $lofidev ]]; then
+               $LOFIADM -d $lofidev
+       fi
+}
+
+log_assert "Verify slog device can be disk, file, lofi device or any device " \
+       "that presents a block interface."
+verify_disk_count "$DISKS" 2
+log_onexit cleanup_testenv
+
+dsk1=${DISKS%% *}
+log_must $ZPOOL create $TESTPOOL ${DISKS#$dsk1}
+
+# Add nomal disk
+log_must $ZPOOL add $TESTPOOL log $dsk1
+log_must verify_slog_device $TESTPOOL $dsk1 'ONLINE'
+# Add nomal file
+log_must $ZPOOL add $TESTPOOL log $LDEV
+ldev=$(random_get $LDEV)
+log_must verify_slog_device $TESTPOOL $ldev 'ONLINE'
+
+# Add lofi device
+lofidev=${LDEV2%% *}
+log_must $LOFIADM -a $lofidev
+lofidev=$($LOFIADM $lofidev)
+log_must $ZPOOL add $TESTPOOL log $lofidev
+log_must verify_slog_device $TESTPOOL $lofidev 'ONLINE'
+
+log_pass "Verify slog device can be disk, file, lofi device or any device " \
+       "that presents a block interface."
+
+# Temp disable fore bug 6569095
+# Add file which reside in the itself
+mntpnt=$(get_prop mountpoint $TESTPOOL)
+log_must $MKFILE 100M $mntpnt/vdev
+log_must $ZPOOL add $TESTPOOL $mntpnt/vdev
+
+# Temp disable fore bug 6569072
+# Add ZFS volume
+vol=$TESTPOOL/vol
+log_must $ZPOOL create -V 64M $vol
+log_must $ZPOOL add $TESTPOOL ${ZVOL_DEVDIR}/$vol
diff --git a/tests/zfs-tests/tests/functional/slog/slog_014_pos.ksh b/tests/zfs-tests/tests/functional/slog/slog_014_pos.ksh
new file mode 100755 (executable)
index 0000000..5f69b19
--- /dev/null
@@ -0,0 +1,85 @@
+#!/bin/ksh -p
+#
+# CDDL HEADER START
+#
+# The contents of this file are subject to the terms of the
+# Common Development and Distribution License (the "License").
+# You may not use this file except in compliance with the License.
+#
+# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
+# or http://www.opensolaris.org/os/licensing.
+# See the License for the specific language governing permissions
+# and limitations under the License.
+#
+# When distributing Covered Code, include this CDDL HEADER in each
+# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
+# If applicable, add the following below this CDDL HEADER, with the
+# fields enclosed by brackets "[]" replaced with your own identifying
+# information: Portions Copyright [yyyy] [name of copyright owner]
+#
+# CDDL HEADER END
+#
+
+#
+# Copyright 2009 Sun Microsystems, Inc.  All rights reserved.
+# Use is subject to license terms.
+#
+
+#
+# Copyright (c) 2013 by Delphix. All rights reserved.
+#
+
+. $STF_SUITE/tests/functional/slog/slog.kshlib
+
+#
+# DESCRIPTION:
+#      log device can survive when one of pool device get corrupted
+#
+# STRATEGY:
+#      1. Create pool with slog devices
+#      2. Corrupt the data on one disk.
+#      3. Verify the log is fine
+#
+
+verify_runnable "global"
+
+log_assert "log device can survive when one of the pool device get corrupted."
+
+for type in "mirror" "raidz" "raidz2"
+do
+       for spare in "" "spare"
+       do
+               log_must $ZPOOL create $TESTPOOL $type $VDEV $spare $SDEV \
+                       log $LDEV
+
+               # Corrupt a pool device to make the pool DEGRADED
+               $DD if=/dev/urandom of=/$TESTPOOL/filler bs=1024k count=50
+               # The oseek value below is to skip past the vdev label.
+               if is_linux; then
+                       log_must $DD if=/dev/urandom of=$VDIR/a bs=1024k \
+                          seek=4 conv=notrunc count=50
+               else
+                       log_must $DD if=/dev/urandom of=$VDIR/a bs=1024k \
+                          oseek=4 conv=notrunc count=50
+               fi
+               log_must $ZPOOL scrub $TESTPOOL
+               log_must display_status $TESTPOOL
+               log_must $ZPOOL status $TESTPOOL 2>&1 >/dev/null
+
+               $ZPOOL status -v $TESTPOOL | \
+                       $GREP "state: DEGRADED" 2>&1 >/dev/null
+               if (( $? != 0 )); then
+                       log_fail "pool $TESTPOOL status should be DEGRADED"
+               fi
+
+               $ZPOOL status -v $TESTPOOL | $GREP logs | \
+                       $GREP "DEGRADED" 2>&1 >/dev/null
+               if (( $? == 0 )); then
+                       log_fail "log device should display correct status"
+               fi
+
+               log_must $ZPOOL destroy -f $TESTPOOL
+       done
+done
+
+log_pass "log device can survive when one of the pool device get corrupted."
diff --git a/tests/zfs-tests/tests/functional/snapshot/Makefile.am b/tests/zfs-tests/tests/functional/snapshot/Makefile.am
new file mode 100644 (file)
index 0000000..091434d
--- /dev/null
@@ -0,0 +1,26 @@
+pkgdatadir = $(datadir)/@PACKAGE@/zfs-tests/tests/functional/snapshot
+dist_pkgdata_SCRIPTS = \
+       snapshot.cfg \
+       setup.ksh \
+       cleanup.ksh \
+       clone_001_pos.ksh \
+       rollback_001_pos.ksh \
+       rollback_002_pos.ksh \
+       rollback_003_pos.ksh \
+       snapshot_001_pos.ksh \
+       snapshot_002_pos.ksh \
+       snapshot_003_pos.ksh \
+       snapshot_004_pos.ksh \
+       snapshot_005_pos.ksh \
+       snapshot_006_pos.ksh \
+       snapshot_007_pos.ksh \
+       snapshot_008_pos.ksh \
+       snapshot_009_pos.ksh \
+       snapshot_010_pos.ksh \
+       snapshot_011_pos.ksh \
+       snapshot_012_pos.ksh \
+       snapshot_013_pos.ksh \
+       snapshot_014_pos.ksh \
+       snapshot_015_pos.ksh \
+       snapshot_016_pos.ksh \
+       snapshot_017_pos.ksh
diff --git a/tests/zfs-tests/tests/functional/snapshot/cleanup.ksh b/tests/zfs-tests/tests/functional/snapshot/cleanup.ksh
new file mode 100755 (executable)
index 0000000..c4c3691
--- /dev/null
@@ -0,0 +1,34 @@
+#!/bin/ksh -p
+#
+# CDDL HEADER START
+#
+# The contents of this file are subject to the terms of the
+# Common Development and Distribution License (the "License").
+# You may not use this file except in compliance with the License.
+#
+# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
+# or http://www.opensolaris.org/os/licensing.
+# See the License for the specific language governing permissions
+# and limitations under the License.
+#
+# When distributing Covered Code, include this CDDL HEADER in each
+# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
+# If applicable, add the following below this CDDL HEADER, with the
+# fields enclosed by brackets "[]" replaced with your own identifying
+# information: Portions Copyright [yyyy] [name of copyright owner]
+#
+# CDDL HEADER END
+#
+
+#
+# Copyright 2007 Sun Microsystems, Inc.  All rights reserved.
+# Use is subject to license terms.
+#
+
+#
+# Copyright (c) 2013 by Delphix. All rights reserved.
+#
+
+. $STF_SUITE/include/libtest.shlib
+
+default_container_cleanup
diff --git a/tests/zfs-tests/tests/functional/snapshot/clone_001_pos.ksh b/tests/zfs-tests/tests/functional/snapshot/clone_001_pos.ksh
new file mode 100755 (executable)
index 0000000..9833087
--- /dev/null
@@ -0,0 +1,161 @@
+#! /bin/ksh -p
+#
+# CDDL HEADER START
+#
+# The contents of this file are subject to the terms of the
+# Common Development and Distribution License (the "License").
+# You may not use this file except in compliance with the License.
+#
+# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
+# or http://www.opensolaris.org/os/licensing.
+# See the License for the specific language governing permissions
+# and limitations under the License.
+#
+# When distributing Covered Code, include this CDDL HEADER in each
+# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
+# If applicable, add the following below this CDDL HEADER, with the
+# fields enclosed by brackets "[]" replaced with your own identifying
+# information: Portions Copyright [yyyy] [name of copyright owner]
+#
+# CDDL HEADER END
+#
+
+#
+# Copyright 2009 Sun Microsystems, Inc.  All rights reserved.
+# Use is subject to license terms.
+#
+
+#
+# Copyright (c) 2013 by Delphix. All rights reserved.
+#
+
+. $STF_SUITE/include/libtest.shlib
+. $STF_SUITE/tests/functional/snapshot/snapshot.cfg
+
+#
+# DESCRIPTION:
+#      Create a snapshot from regular filesystem, volume,
+#      or filesystem upon volume, Build a clone file system
+#      from the snapshot and verify new files can be written.
+#
+# STRATEGY:
+#      1. Create snapshot use 3 combination:
+#              - Regular filesystem
+#              - Regular volume
+#              - Filesystem upon volume
+#      2. Clone a new file system from the snapshot
+#      3. Verify the cloned file system is writable
+#
+
+verify_runnable "both"
+
+# Setup array, 4 elements as a group, refer to:
+# i+0: name of a snapshot
+# i+1: mountpoint of the snapshot
+# i+2: clone created from the snapshot
+# i+3: mountpoint of the clone
+
+set -A args "$SNAPFS" "$SNAPDIR" "$TESTPOOL/$TESTCLONE" "$TESTDIR.0" \
+       "$SNAPFS1" "$SNAPDIR3" "$TESTPOOL/$TESTCLONE1" "" \
+       "$SNAPFS2" "$SNAPDIR2" "$TESTPOOL1/$TESTCLONE2" "$TESTDIR.2"
+
+function setup_all
+{
+       create_pool $TESTPOOL1 ${ZVOL_DEVDIR}/$TESTPOOL/$TESTVOL
+       log_must $ZFS create $TESTPOOL1/$TESTFS
+       log_must $ZFS set mountpoint=$TESTDIR2 $TESTPOOL1/$TESTFS
+
+       return 0
+}
+
+function cleanup_all
+{
+       typeset -i i=0
+
+       i=0
+       while (( i < ${#args[*]} )); do
+               snapexists ${args[i]} && \
+                       log_must $ZFS destroy -Rf ${args[i]}
+
+               [[ -d ${args[i+3]} ]] && \
+                       log_must $RM -rf ${args[i+3]}
+
+               [[ -d ${args[i+1]} ]] && \
+                       log_must $RM -rf ${args[i+1]}
+
+               (( i = i + 4 ))
+       done
+
+       datasetexists $TESTPOOL1/$TESTFS  && \
+               log_must $ZFS destroy -f $TESTPOOL1/$TESTFS
+
+       destroy_pool $TESTPOOL1
+
+       [[ -d $TESTDIR2 ]] && \
+               log_must $RM -rf $TESTDIR2
+
+       return 0
+}
+
+log_assert "Verify a cloned file system is writable."
+
+log_onexit cleanup_all
+
+setup_all
+
+[[ -n $TESTDIR ]] && \
+    log_must $RM -rf $TESTDIR/* > /dev/null 2>&1
+
+typeset -i COUNT=10
+typeset -i i=0
+
+for mtpt in $TESTDIR $TESTDIR2 ; do
+       log_note "Populate the $mtpt directory (prior to snapshot)"
+       typeset -i j=1
+       while [[ $j -le $COUNT ]]; do
+               log_must $FILE_WRITE -o create -f $mtpt/before_file$j \
+                       -b $BLOCKSZ -c $NUM_WRITES -d $j
+
+               (( j = j + 1 ))
+       done
+done
+
+while (( i < ${#args[*]} )); do
+       #
+       # Take a snapshot of the test file system.
+       #
+       log_must $ZFS snapshot ${args[i]}
+
+       #
+       # Clone a new file system from the snapshot
+       #
+       log_must $ZFS clone ${args[i]} ${args[i+2]}
+       if [[ -n ${args[i+3]} ]] ; then
+               log_must $ZFS set mountpoint=${args[i+3]} ${args[i+2]}
+
+               FILE_COUNT=`$LS -Al ${args[i+3]} | $GREP -v "total" \
+                   | $GREP -v "\.zfs" | wc -l`
+               if [[ $FILE_COUNT -ne $COUNT ]]; then
+                       $LS -Al ${args[i+3]}
+                       log_fail "AFTER: ${args[i+3]} contains $FILE_COUNT files(s)."
+               fi
+
+               log_note "Verify the ${args[i+3]} directory is writable"
+               j=1
+               while [[ $j -le $COUNT ]]; do
+                       log_must $FILE_WRITE -o create -f ${args[i+3]}/after_file$j \
+                       -b $BLOCKSZ -c $NUM_WRITES -d $j
+                       (( j = j + 1 ))
+               done
+
+               FILE_COUNT=`$LS -Al ${args[i+3]}/after* | $GREP -v "total" | wc -l`
+               if [[ $FILE_COUNT -ne $COUNT ]]; then
+                       $LS -Al ${args[i+3]}
+                       log_fail "${args[i+3]} contains $FILE_COUNT after* files(s)."
+               fi
+       fi
+
+       (( i = i + 4 ))
+done
+
+log_pass "The clone file system is writable."
diff --git a/tests/zfs-tests/tests/functional/snapshot/rollback_001_pos.ksh b/tests/zfs-tests/tests/functional/snapshot/rollback_001_pos.ksh
new file mode 100755 (executable)
index 0000000..e5df02d
--- /dev/null
@@ -0,0 +1,115 @@
+#! /bin/ksh -p
+#
+# CDDL HEADER START
+#
+# The contents of this file are subject to the terms of the
+# Common Development and Distribution License (the "License").
+# You may not use this file except in compliance with the License.
+#
+# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
+# or http://www.opensolaris.org/os/licensing.
+# See the License for the specific language governing permissions
+# and limitations under the License.
+#
+# When distributing Covered Code, include this CDDL HEADER in each
+# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
+# If applicable, add the following below this CDDL HEADER, with the
+# fields enclosed by brackets "[]" replaced with your own identifying
+# information: Portions Copyright [yyyy] [name of copyright owner]
+#
+# CDDL HEADER END
+#
+
+#
+# Copyright 2007 Sun Microsystems, Inc.  All rights reserved.
+# Use is subject to license terms.
+#
+
+#
+# Copyright (c) 2013 by Delphix. All rights reserved.
+#
+
+. $STF_SUITE/include/libtest.shlib
+. $STF_SUITE/tests/functional/snapshot/snapshot.cfg
+
+#
+# DESCRIPTION:
+# Populate a file system and take a snapshot. Add some more files to the
+# file system and rollback to the last snapshot. Verify no post snapshot
+# file exist.
+#
+# STRATEGY:
+# 1. Empty a file system
+# 2. Populate the file system
+# 3. Take a snapshot of the file system
+# 4. Add new files to the file system
+# 5. Perform a rollback
+# 6. Verify the snapshot and file system agree
+#
+
+verify_runnable "both"
+
+function cleanup
+{
+       snapexists $SNAPFS
+       [[ $? -eq 0 ]] && \
+               log_must $ZFS destroy $SNAPFS
+
+       [[ -e $TESTDIR ]] && \
+               log_must $RM -rf $TESTDIR/* > /dev/null 2>&1
+}
+
+log_assert "Verify that a rollback to a previous snapshot succeeds."
+
+log_onexit cleanup
+
+[[ -n $TESTDIR ]] && \
+    log_must $RM -rf $TESTDIR/* > /dev/null 2>&1
+
+typeset -i COUNT=10
+
+log_note "Populate the $TESTDIR directory (prior to snapshot)"
+typeset -i i=1
+while [[ $i -le $COUNT ]]; do
+       log_must $FILE_WRITE -o create -f $TESTDIR/before_file$i \
+          -b $BLOCKSZ -c $NUM_WRITES -d $i
+
+       (( i = i + 1 ))
+done
+
+log_must $ZFS snapshot $SNAPFS
+
+FILE_COUNT=`$LS -Al $SNAPDIR | $GREP -v "total" | wc -l`
+if [[ $FILE_COUNT -ne $COUNT ]]; then
+        $LS -Al $SNAPDIR
+        log_fail "AFTER: $SNAPFS contains $FILE_COUNT files(s)."
+fi
+
+log_note "Populate the $TESTDIR directory (post snapshot)"
+typeset -i i=1
+while [[ $i -le $COUNT ]]; do
+        log_must $FILE_WRITE -o create -f $TESTDIR/after_file$i \
+           -b $BLOCKSZ -c $NUM_WRITES -d $i
+
+        (( i = i + 1 ))
+done
+
+#
+# Now rollback to latest snapshot
+#
+log_must $ZFS rollback $SNAPFS
+
+FILE_COUNT=`$LS -Al $TESTDIR/after* 2> /dev/null | $GREP -v "total" | wc -l`
+if [[ $FILE_COUNT -ne 0 ]]; then
+        $LS -Al $TESTDIR
+        log_fail "$TESTDIR contains $FILE_COUNT after* files(s)."
+fi
+
+FILE_COUNT=`$LS -Al $TESTDIR/before* 2> /dev/null \
+    | $GREP -v "total" | wc -l`
+if [[ $FILE_COUNT -ne $COUNT ]]; then
+       $LS -Al $TESTDIR
+       log_fail "$TESTDIR contains $FILE_COUNT before* files(s)."
+fi
+
+log_pass "The rollback operation succeeded."
diff --git a/tests/zfs-tests/tests/functional/snapshot/rollback_002_pos.ksh b/tests/zfs-tests/tests/functional/snapshot/rollback_002_pos.ksh
new file mode 100755 (executable)
index 0000000..76b8c84
--- /dev/null
@@ -0,0 +1,133 @@
+#! /bin/ksh -p
+#
+# CDDL HEADER START
+#
+# The contents of this file are subject to the terms of the
+# Common Development and Distribution License (the "License").
+# You may not use this file except in compliance with the License.
+#
+# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
+# or http://www.opensolaris.org/os/licensing.
+# See the License for the specific language governing permissions
+# and limitations under the License.
+#
+# When distributing Covered Code, include this CDDL HEADER in each
+# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
+# If applicable, add the following below this CDDL HEADER, with the
+# fields enclosed by brackets "[]" replaced with your own identifying
+# information: Portions Copyright [yyyy] [name of copyright owner]
+#
+# CDDL HEADER END
+#
+
+#
+# Copyright 2007 Sun Microsystems, Inc.  All rights reserved.
+# Use is subject to license terms.
+#
+
+#
+# Copyright (c) 2013 by Delphix. All rights reserved.
+#
+
+. $STF_SUITE/include/libtest.shlib
+. $STF_SUITE/tests/functional/snapshot/snapshot.cfg
+
+#
+# DESCRIPTION:
+# Verify that rollbacks are with respect to the latest snapshot.
+#
+# STRATEGY:
+# 1. Empty a file system
+# 2. Populate the file system
+# 3. Take a snapshot of the file system
+# 4. Add new files to the file system
+# 5. Take a snapshot
+# 6. Remove the original files
+# 7. Perform a rollback
+# 8. Verify the latest snapshot and file system agree
+#
+
+verify_runnable "both"
+
+function cleanup
+{
+       snapexists $SNAPFS.1
+       [[ $? -eq 0 ]] && \
+               log_must $ZFS destroy $SNAPFS.1
+
+       snapexists $SNAPFS
+       [[ $? -eq 0 ]] && \
+               log_must $ZFS destroy $SNAPFS
+
+       [[ -e $TESTDIR ]] && \
+               log_must $RM -rf $TESTDIR/* > /dev/null 2>&1
+}
+
+log_assert "Verify rollback is with respect to latest snapshot."
+
+log_onexit cleanup
+
+[[ -n $TESTDIR ]] && \
+    log_must $RM -rf $TESTDIR/* > /dev/null 2>&1
+
+typeset -i COUNT=10
+
+log_note "Populate the $TESTDIR directory (prior to first snapshot)"
+typeset -i i=1
+while [[ $i -le $COUNT ]]; do
+       log_must $FILE_WRITE -o create -f $TESTDIR/original_file$i \
+          -b $BLOCKSZ -c $NUM_WRITES -d $i
+
+       (( i = i + 1 ))
+done
+
+log_must $ZFS snapshot $SNAPFS
+
+FILE_COUNT=`$LS -Al $SNAPDIR | $GREP -v "total" | wc -l`
+if [[ $FILE_COUNT -ne $COUNT ]]; then
+        $LS -Al $SNAPDIR
+        log_fail "AFTER: $SNAPFS contains $FILE_COUNT files(s)."
+fi
+
+log_note "Populate the $TESTDIR directory (prior to second snapshot)"
+typeset -i i=1
+while [[ $i -le $COUNT ]]; do
+        log_must $FILE_WRITE -o create -f $TESTDIR/afterfirst_file$i \
+           -b $BLOCKSZ -c $NUM_WRITES -d $i
+
+        (( i = i + 1 ))
+done
+
+log_must $ZFS snapshot $SNAPFS.1
+
+log_note "Populate the $TESTDIR directory (Post second snapshot)"
+typeset -i i=1
+while [[ $i -le $COUNT ]]; do
+        log_must $FILE_WRITE -o create -f $TESTDIR/aftersecond_file$i \
+           -b $BLOCKSZ -c $NUM_WRITES -d $i
+
+        (( i = i + 1 ))
+done
+
+[[ -n $TESTDIR ]] && \
+    log_must $RM -rf $TESTDIR/original_file* > /dev/null 2>&1
+
+#
+# Now rollback to latest snapshot
+#
+log_must $ZFS rollback $SNAPFS.1
+
+FILE_COUNT=`$LS -Al $TESTDIR/aftersecond* 2> /dev/null \
+    | $GREP -v "total" | wc -l`
+if [[ $FILE_COUNT -ne 0 ]]; then
+        $LS -Al $TESTDIR
+        log_fail "$TESTDIR contains $FILE_COUNT aftersecond* files(s)."
+fi
+
+FILE_COUNT=`$LS -Al $TESTDIR/original* $TESTDIR/afterfirst*| $GREP -v "total" | wc -l`
+if [[ $FILE_COUNT -ne 20 ]]; then
+        $LS -Al $TESTDIR
+        log_fail "$TESTDIR contains $FILE_COUNT original* files(s)."
+fi
+
+log_pass "The rollback to the latest snapshot succeeded."
diff --git a/tests/zfs-tests/tests/functional/snapshot/rollback_003_pos.ksh b/tests/zfs-tests/tests/functional/snapshot/rollback_003_pos.ksh
new file mode 100755 (executable)
index 0000000..4c9ef68
--- /dev/null
@@ -0,0 +1,106 @@
+#! /bin/ksh -p
+#
+# CDDL HEADER START
+#
+# The contents of this file are subject to the terms of the
+# Common Development and Distribution License (the "License").
+# You may not use this file except in compliance with the License.
+#
+# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
+# or http://www.opensolaris.org/os/licensing.
+# See the License for the specific language governing permissions
+# and limitations under the License.
+#
+# When distributing Covered Code, include this CDDL HEADER in each
+# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
+# If applicable, add the following below this CDDL HEADER, with the
+# fields enclosed by brackets "[]" replaced with your own identifying
+# information: Portions Copyright [yyyy] [name of copyright owner]
+#
+# CDDL HEADER END
+#
+
+#
+# Copyright 2009 Sun Microsystems, Inc.  All rights reserved.
+# Use is subject to license terms.
+#
+
+#
+# Copyright (c) 2013 by Delphix. All rights reserved.
+#
+
+. $STF_SUITE/include/libtest.shlib
+. $STF_SUITE/tests/functional/cli_root/zfs_rollback/zfs_rollback_common.kshlib
+. $STF_SUITE/tests/functional/snapshot/snapshot.cfg
+
+
+#
+# DESCRIPTION:
+# Verify that rollbacks succeed when there are nested file systems.
+#
+# STRATEGY:
+# 1) Snapshot an empty file system and rollback
+# 2) Create a file in the file system
+# 3) Rollback the file system to empty
+# 4) Create a nested file system with the same name as the file created in (2)
+# 5) Verify a rollback succeeds
+#
+
+verify_runnable "both"
+
+function cleanup
+{
+       typeset snap=""
+       typeset fs=""
+
+       export __ZFS_POOL_RESTRICT="$TESTPOOL"
+       log_must $ZFS mount -a
+       unset __ZFS_POOL_RESTRICT
+
+       for snap in "$SNAPPOOL.1" "$SNAPPOOL"
+       do
+               snapexists $snap
+               [[ $? -eq 0 ]] && \
+                       log_must $ZFS destroy $snap
+       done
+
+       for fs in "$TESTPOOL/$TESTFILE/$TESTFILE.1" "$TESTPOOL/$TESTFILE"
+       do
+               datasetexists $fs
+               [[ $? -eq 0 ]] && \
+                       log_must $ZFS destroy -r $fs
+       done
+
+       [[ -e /$TESTPOOL ]] && \
+               log_must $RM -rf $TESTPOOL/*
+}
+
+log_assert "Verify rollback succeeds when there are nested file systems."
+
+log_onexit cleanup
+
+log_must $ZFS snapshot $SNAPPOOL
+log_must $ZFS rollback $SNAPPOOL
+log_mustnot $ZFS snapshot $SNAPPOOL
+
+log_must $TOUCH /$TESTPOOL/$TESTFILE
+
+log_must $ZFS rollback $SNAPPOOL
+log_must $ZFS create $TESTPOOL/$TESTFILE
+
+log_must $ZFS rollback $SNAPPOOL
+
+log_note "Verify rollback of multiple nested file systems succeeds."
+log_must $ZFS snapshot $TESTPOOL/$TESTFILE@$TESTSNAP
+log_must $ZFS snapshot $SNAPPOOL.1
+
+export __ZFS_POOL_RESTRICT="$TESTPOOL"
+log_must $ZFS unmount -a
+log_must $ZFS mount -a
+unset __ZFS_POOL_RESTRICT
+
+log_must $TOUCH /$TESTPOOL/$TESTFILE/$TESTFILE.1
+
+log_must $ZFS rollback $SNAPPOOL.1
+
+log_pass "Rollbacks succeed when nested file systems are present."
diff --git a/tests/zfs-tests/tests/functional/snapshot/setup.ksh b/tests/zfs-tests/tests/functional/snapshot/setup.ksh
new file mode 100755 (executable)
index 0000000..d8733f3
--- /dev/null
@@ -0,0 +1,36 @@
+#!/bin/ksh -p
+#
+# CDDL HEADER START
+#
+# The contents of this file are subject to the terms of the
+# Common Development and Distribution License (the "License").
+# You may not use this file except in compliance with the License.
+#
+# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
+# or http://www.opensolaris.org/os/licensing.
+# See the License for the specific language governing permissions
+# and limitations under the License.
+#
+# When distributing Covered Code, include this CDDL HEADER in each
+# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
+# If applicable, add the following below this CDDL HEADER, with the
+# fields enclosed by brackets "[]" replaced with your own identifying
+# information: Portions Copyright [yyyy] [name of copyright owner]
+#
+# CDDL HEADER END
+#
+
+#
+# Copyright 2007 Sun Microsystems, Inc.  All rights reserved.
+# Use is subject to license terms.
+#
+
+#
+# Copyright (c) 2013 by Delphix. All rights reserved.
+#
+
+. $STF_SUITE/include/libtest.shlib
+
+DISK=${DISKS%% *}
+
+default_container_volume_setup ${DISK}
diff --git a/tests/zfs-tests/tests/functional/snapshot/snapshot.cfg b/tests/zfs-tests/tests/functional/snapshot/snapshot.cfg
new file mode 100644 (file)
index 0000000..fa31645
--- /dev/null
@@ -0,0 +1,53 @@
+#
+# CDDL HEADER START
+#
+# The contents of this file are subject to the terms of the
+# Common Development and Distribution License (the "License").
+# You may not use this file except in compliance with the License.
+#
+# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
+# or http://www.opensolaris.org/os/licensing.
+# See the License for the specific language governing permissions
+# and limitations under the License.
+#
+# When distributing Covered Code, include this CDDL HEADER in each
+# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
+# If applicable, add the following below this CDDL HEADER, with the
+# fields enclosed by brackets "[]" replaced with your own identifying
+# information: Portions Copyright [yyyy] [name of copyright owner]
+#
+# CDDL HEADER END
+#
+
+#
+# Copyright 2008 Sun Microsystems, Inc.  All rights reserved.
+# Use is subject to license terms.
+#
+
+#
+# Copyright (c) 2013 by Delphix. All rights reserved.
+#
+
+. $STF_SUITE/include/libtest.shlib
+
+export TESTFILE=testfile-snapshot
+export SNAPROOT=".zfs/snapshot"
+
+export SNAPPOOL="$TESTPOOL@$TESTSNAP"
+export SNAPFS="$TESTPOOL/$TESTFS@$TESTSNAP"
+export SNAPFS1="$TESTPOOL/$TESTVOL@$TESTSNAP"
+export SNAPFS2="$TESTPOOL1/$TESTFS@$TESTSNAP"
+export SNAPCTR="$TESTPOOL/$TESTCTR/$TESTFS1@$TESTSNAP"
+export SNAPDIR="$TESTDIR/$SNAPROOT/$TESTSNAP"
+export SNAPDIR1="$TESTDIR1/$SNAPROOT/$TESTSNAP"
+export SNAPDIR2="$TESTDIR2/$SNAPROOT/$TESTSNAP"
+export SNAPDIR3="/$SNAPFS1"
+
+export VOLSIZE=1gb
+export BLOCKSZ=8192
+export NUM_WRITES=20
+export DATA=0
+export LIMIT=524288 # tolerance measured in bytes, 512K
+export FSQUOTA=500m
+export FILESIZE=400m
+export FILESIZE1=200m
diff --git a/tests/zfs-tests/tests/functional/snapshot/snapshot_001_pos.ksh b/tests/zfs-tests/tests/functional/snapshot/snapshot_001_pos.ksh
new file mode 100755 (executable)
index 0000000..832ca1e
--- /dev/null
@@ -0,0 +1,91 @@
+#! /bin/ksh -p
+#
+# CDDL HEADER START
+#
+# The contents of this file are subject to the terms of the
+# Common Development and Distribution License (the "License").
+# You may not use this file except in compliance with the License.
+#
+# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
+# or http://www.opensolaris.org/os/licensing.
+# See the License for the specific language governing permissions
+# and limitations under the License.
+#
+# When distributing Covered Code, include this CDDL HEADER in each
+# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
+# If applicable, add the following below this CDDL HEADER, with the
+# fields enclosed by brackets "[]" replaced with your own identifying
+# information: Portions Copyright [yyyy] [name of copyright owner]
+#
+# CDDL HEADER END
+#
+
+#
+# Copyright 2007 Sun Microsystems, Inc.  All rights reserved.
+# Use is subject to license terms.
+#
+
+#
+# Copyright (c) 2013 by Delphix. All rights reserved.
+#
+
+. $STF_SUITE/include/libtest.shlib
+. $STF_SUITE/tests/functional/snapshot/snapshot.cfg
+
+#
+# DESCRIPTION:
+# A zfs file system snapshot is identical to
+# the originally snapshot'd file system, after the file
+# system has been changed. Uses 'sum -r'.
+#
+# STRATEGY:
+# 1. Create a file in the zfs file system
+# 2. Checksum the file for later comparison
+# 3. Create a snapshot of the dataset
+# 4. Append to the original file
+# 5. Verify the snapshot and file agree
+#
+
+verify_runnable "both"
+
+function cleanup
+{
+       snapexists $SNAPFS
+       if [[ $? -eq 0 ]]; then
+               log_must $ZFS destroy $SNAPFS
+       fi
+
+       if [[ -e $SNAPDIR ]]; then
+               log_must $RM -rf $SNAPDIR > /dev/null 2>&1
+       fi
+
+       if [[ -e $TESTDIR ]]; then
+               log_must $RM -rf $TESTDIR/* > /dev/null 2>&1
+       fi
+}
+
+log_assert "Verify a file system snapshot is identical to original."
+
+log_onexit cleanup
+
+log_note "Create a file in the zfs filesystem..."
+log_must $FILE_WRITE -o create -f $TESTDIR/$TESTFILE -b $BLOCKSZ \
+    -c $NUM_WRITES -d $DATA
+
+log_note "Sum the file, save for later comparison..."
+FILE_SUM=`$SUM -r $TESTDIR/$TESTFILE | $AWK  '{ print $1 }'`
+log_note "FILE_SUM = $FILE_SUM"
+
+log_note "Create a snapshot and mount it..."
+log_must $ZFS snapshot $SNAPFS
+
+log_note "Append to the original file..."
+log_must $FILE_WRITE -o append -f $TESTDIR/$TESTFILE -b $BLOCKSZ \
+    -c $NUM_WRITES -d $DATA
+
+SNAP_FILE_SUM=`$SUM -r $SNAPDIR/$TESTFILE | $AWK '{ print $1 }'`
+if [[ $SNAP_FILE_SUM -ne $FILE_SUM ]]; then
+       log_fail "Sums do not match, aborting!! ($SNAP_FILE_SUM != $FILE_SUM)"
+fi
+
+log_pass "Both Sums match. ($SNAP_FILE_SUM == $FILE_SUM)"
diff --git a/tests/zfs-tests/tests/functional/snapshot/snapshot_002_pos.ksh b/tests/zfs-tests/tests/functional/snapshot/snapshot_002_pos.ksh
new file mode 100755 (executable)
index 0000000..040f3ac
--- /dev/null
@@ -0,0 +1,134 @@
+#! /bin/ksh -p
+#
+# CDDL HEADER START
+#
+# The contents of this file are subject to the terms of the
+# Common Development and Distribution License (the "License").
+# You may not use this file except in compliance with the License.
+#
+# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
+# or http://www.opensolaris.org/os/licensing.
+# See the License for the specific language governing permissions
+# and limitations under the License.
+#
+# When distributing Covered Code, include this CDDL HEADER in each
+# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
+# If applicable, add the following below this CDDL HEADER, with the
+# fields enclosed by brackets "[]" replaced with your own identifying
+# information: Portions Copyright [yyyy] [name of copyright owner]
+#
+# CDDL HEADER END
+#
+
+#
+# Copyright 2007 Sun Microsystems, Inc.  All rights reserved.
+# Use is subject to license terms.
+#
+
+#
+# Copyright (c) 2013 by Delphix. All rights reserved.
+#
+
+. $STF_SUITE/include/libtest.shlib
+. $STF_SUITE/tests/functional/snapshot/snapshot.cfg
+
+#
+# DESCRIPTION:
+# An archive of a zfs file system and an archive of its snapshot
+# is identical even though the original file system has
+# changed sinced the snapshot was taken.
+#
+# STRATEGY:
+# 1) Create files in all of the zfs file systems
+# 2) Create a tarball of the file system
+# 3) Create a snapshot of the dataset
+# 4) Remove all the files in the original file system
+# 5) Create a tarball of the snapshot
+# 6) Extract each tarball and compare directory structures
+#
+
+verify_runnable "both"
+
+function cleanup
+{
+       if [[ -d $CWD ]]; then
+               cd $CWD || log_fail "Could not cd $CWD"
+       fi
+
+        snapexists $SNAPFS
+        if [[ $? -eq 0 ]]; then
+                log_must $ZFS destroy $SNAPFS
+        fi
+
+        if [[ -e $SNAPDIR ]]; then
+                log_must $RM -rf $SNAPDIR > /dev/null 2>&1
+        fi
+
+        if [[ -e $TESTDIR ]]; then
+                log_must $RM -rf $TESTDIR/* > /dev/null 2>&1
+        fi
+
+       if [[ -e /tmp/zfs_snapshot2.$$ ]]; then
+               log_must $RM -rf /tmp/zfs_snapshot2.$$ > /dev/null 2>&1
+       fi
+
+}
+
+log_assert "Verify an archive of a file system is identical to " \
+    "an archive of its snapshot."
+
+log_onexit cleanup
+
+typeset -i COUNT=21
+typeset OP=create
+
+[[ -n $TESTDIR ]] && \
+    $RM -rf $TESTDIR/* > /dev/null 2>&1
+
+log_note "Create files in the zfs filesystem..."
+
+typeset i=1
+while [ $i -lt $COUNT ]; do
+       log_must $FILE_WRITE -o $OP -f $TESTDIR/file$i \
+           -b $BLOCKSZ -c $NUM_WRITES -d $DATA
+
+       (( i = i + 1 ))
+done
+
+log_note "Create a tarball from $TESTDIR contents..."
+CWD=$PWD
+cd $TESTDIR || log_fail "Could not cd $TESTDIR"
+log_must $TAR cf $TESTDIR/tarball.original.tar file*
+cd $CWD || log_fail "Could not cd $CWD"
+
+log_note "Create a snapshot and mount it..."
+log_must $ZFS snapshot $SNAPFS
+
+log_note "Remove all of the original files..."
+log_must $RM -f $TESTDIR/file* > /dev/null 2>&1
+
+log_note "Create tarball of snapshot..."
+CWD=$PWD
+cd $SNAPDIR || log_fail "Could not cd $SNAPDIR"
+log_must $TAR cf $TESTDIR/tarball.snapshot.tar file*
+cd $CWD || log_fail "Could not cd $CWD"
+
+log_must $MKDIR $TESTDIR/original
+log_must $MKDIR $TESTDIR/snapshot
+
+CWD=$PWD
+cd $TESTDIR/original || log_fail "Could not cd $TESTDIR/original"
+log_must $TAR xf $TESTDIR/tarball.original.tar
+
+cd $TESTDIR/snapshot || log_fail "Could not cd $TESTDIR/snapshot"
+log_must $TAR xf $TESTDIR/tarball.snapshot.tar
+
+cd $CWD || log_fail "Could not cd $CWD"
+
+$DIRCMP $TESTDIR/original $TESTDIR/snapshot > /tmp/zfs_snapshot2.$$
+$GREP different /tmp/zfs_snapshot2.$$ >/dev/null 2>&1
+if [[ $? -ne 1 ]]; then
+       log_fail "Directory structures differ."
+fi
+
+log_pass "Directory structures match."
diff --git a/tests/zfs-tests/tests/functional/snapshot/snapshot_003_pos.ksh b/tests/zfs-tests/tests/functional/snapshot/snapshot_003_pos.ksh
new file mode 100755 (executable)
index 0000000..f30629f
--- /dev/null
@@ -0,0 +1,103 @@
+#! /bin/ksh -p
+#
+# CDDL HEADER START
+#
+# The contents of this file are subject to the terms of the
+# Common Development and Distribution License (the "License").
+# You may not use this file except in compliance with the License.
+#
+# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
+# or http://www.opensolaris.org/os/licensing.
+# See the License for the specific language governing permissions
+# and limitations under the License.
+#
+# When distributing Covered Code, include this CDDL HEADER in each
+# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
+# If applicable, add the following below this CDDL HEADER, with the
+# fields enclosed by brackets "[]" replaced with your own identifying
+# information: Portions Copyright [yyyy] [name of copyright owner]
+#
+# CDDL HEADER END
+#
+
+#
+# Copyright 2007 Sun Microsystems, Inc.  All rights reserved.
+# Use is subject to license terms.
+#
+
+#
+# Copyright (c) 2013 by Delphix. All rights reserved.
+#
+
+. $STF_SUITE/include/libtest.shlib
+. $STF_SUITE/tests/functional/snapshot/snapshot.cfg
+
+#
+# DESCRIPTION:
+# Verify that many snapshots can be made on a zfs file system.
+#
+# STRATEGY:
+# 1) Create a files in the zfs file system
+# 2) Create a snapshot of the dataset
+# 3) Remove all the files from the original file system
+# 4) Verify consistency of each snapshot directory
+#
+
+verify_runnable "both"
+
+function cleanup
+{
+       typeset -i i=1
+       while [ $i -lt $COUNT ]; do
+               snapexists $SNAPFS.$i
+               if [[ $? -eq 0 ]]; then
+                       log_must $ZFS destroy $SNAPFS.$i
+               fi
+
+               if [[ -e $SNAPDIR.$i ]]; then
+                       log_must $RM -rf $SNAPDIR.$i > /dev/null 2>&1
+               fi
+
+               (( i = i + 1 ))
+       done
+
+       if [[ -e $TESTDIR ]]; then
+               log_must $RM -rf $TESTDIR/* > /dev/null 2>&1
+       fi
+}
+
+log_assert "Verify many snapshots of a file system can be taken."
+
+log_onexit cleanup
+
+[[ -n $TESTDIR ]] && \
+    log_must $RM -rf $TESTDIR/* > /dev/null 2>&1
+
+typeset -i COUNT=10
+
+log_note "Create some files in the $TESTDIR directory..."
+typeset -i i=1
+while [[ $i -lt $COUNT ]]; do
+       log_must $FILE_WRITE -o create -f $TESTDIR/file$i \
+          -b $BLOCKSZ -c $NUM_WRITES -d $i
+       log_must $ZFS snapshot $SNAPFS.$i
+
+       (( i = i + 1 ))
+done
+
+log_note "Remove all of the original files"
+[[ -n $TESTDIR ]] && \
+    log_must $RM -rf $TESTDIR/file* > /dev/null 2>&1
+
+i=1
+while [[ $i -lt $COUNT ]]; do
+       FILECOUNT=`$LS $SNAPDIR.$i/file* | wc -l`
+       typeset j=1
+       while [ $j -lt $FILECOUNT ]; do
+               log_must $FILE_CHECK $SNAPDIR.$i/file$j $j
+               (( j = j + 1 ))
+       done
+       (( i = i + 1 ))
+done
+
+log_pass "All files are consistent"
diff --git a/tests/zfs-tests/tests/functional/snapshot/snapshot_004_pos.ksh b/tests/zfs-tests/tests/functional/snapshot/snapshot_004_pos.ksh
new file mode 100755 (executable)
index 0000000..e104007
--- /dev/null
@@ -0,0 +1,90 @@
+#! /bin/ksh -p
+#
+# CDDL HEADER START
+#
+# The contents of this file are subject to the terms of the
+# Common Development and Distribution License (the "License").
+# You may not use this file except in compliance with the License.
+#
+# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
+# or http://www.opensolaris.org/os/licensing.
+# See the License for the specific language governing permissions
+# and limitations under the License.
+#
+# When distributing Covered Code, include this CDDL HEADER in each
+# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
+# If applicable, add the following below this CDDL HEADER, with the
+# fields enclosed by brackets "[]" replaced with your own identifying
+# information: Portions Copyright [yyyy] [name of copyright owner]
+#
+# CDDL HEADER END
+#
+
+#
+# Copyright 2007 Sun Microsystems, Inc.  All rights reserved.
+# Use is subject to license terms.
+#
+
+#
+# Copyright (c) 2013 by Delphix. All rights reserved.
+#
+
+. $STF_SUITE/include/libtest.shlib
+. $STF_SUITE/tests/functional/snapshot/snapshot.cfg
+
+#
+# DESCRIPTION:
+# Create a null snapshot i.e. a snapshot created before file system
+# activity is empty.
+#
+# STRATEGY:
+# 1. Empty a file system
+# 2. Take a snapshot of the empty file system.
+# 3. Populate the file system
+# 4. Verify the snapshot is still empty
+#
+
+verify_runnable "both"
+
+function cleanup
+{
+       snapexists $SNAPFS
+       [[ $? -eq 0 ]] && \
+               log_must $ZFS destroy $SNAPFS
+
+       [[ -e $TESTDIR ]] && \
+               log_must $RM -rf $TESTDIR/* > /dev/null 2>&1
+}
+
+log_assert "Verify that a snapshot of an empty file system remains empty."
+
+log_onexit cleanup
+
+[[ -n $TESTDIR ]] && \
+    log_must $RM -rf $TESTDIR/* > /dev/null 2>&1
+
+log_must $ZFS snapshot $SNAPFS
+FILE_COUNT=`$LS -Al $SNAPDIR | $GREP -v "total 0" | wc -l`
+if [[ $FILE_COUNT -ne 0 ]]; then
+       $LS $SNAPDIR
+       log_fail "BEFORE: $SNAPDIR contains $FILE_COUNT files(s)."
+fi
+
+typeset -i COUNT=10
+
+log_note "Populate the $TESTDIR directory"
+typeset -i i=1
+while [[ $i -lt $COUNT ]]; do
+       log_must $FILE_WRITE -o create -f $TESTDIR/file$i \
+          -b $BLOCKSZ -c $NUM_WRITES -d $i
+
+       (( i = i + 1 ))
+done
+
+FILE_COUNT=`$LS -Al $SNAPDIR | $GREP -v "total 0" | wc -l`
+if [[ $FILE_COUNT -ne 0 ]]; then
+        $LS $SNAPDIR
+        log_fail "AFTER: $SNAPDIR contains $FILE_COUNT files(s)."
+fi
+
+log_pass "The NULL snapshot remains empty."
diff --git a/tests/zfs-tests/tests/functional/snapshot/snapshot_005_pos.ksh b/tests/zfs-tests/tests/functional/snapshot/snapshot_005_pos.ksh
new file mode 100755 (executable)
index 0000000..8c73639
--- /dev/null
@@ -0,0 +1,90 @@
+#! /bin/ksh -p
+#
+# CDDL HEADER START
+#
+# The contents of this file are subject to the terms of the
+# Common Development and Distribution License (the "License").
+# You may not use this file except in compliance with the License.
+#
+# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
+# or http://www.opensolaris.org/os/licensing.
+# See the License for the specific language governing permissions
+# and limitations under the License.
+#
+# When distributing Covered Code, include this CDDL HEADER in each
+# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
+# If applicable, add the following below this CDDL HEADER, with the
+# fields enclosed by brackets "[]" replaced with your own identifying
+# information: Portions Copyright [yyyy] [name of copyright owner]
+#
+# CDDL HEADER END
+#
+
+#
+# Copyright 2007 Sun Microsystems, Inc.  All rights reserved.
+# Use is subject to license terms.
+#
+
+#
+# Copyright (c) 2013 by Delphix. All rights reserved.
+#
+
+. $STF_SUITE/include/libtest.shlib
+. $STF_SUITE/tests/functional/snapshot/snapshot.cfg
+
+#
+# DESCRIPTION:
+# to the originally snapshot'd file system, after the file
+# system has been changed. Uses 'sum -r'.
+#
+# STRATEGY:
+# 1) Create a file in the zfs dataset
+# 2) Sum the file for later comparison
+# 3) Create a snapshot of the dataset
+# 4) Append to the original file
+# 5) Verify both checksums match
+#
+
+verify_runnable "both"
+
+function cleanup
+{
+       snapexists $SNAPCTR
+       if [[ $? -eq 0 ]]; then
+               log_must $ZFS destroy $SNAPCTR
+       fi
+
+       if [[ -e $SNAPDIR1 ]]; then
+               log_must $RM -rf $SNAPDIR1 > /dev/null 2>&1
+       fi
+
+       if [[ -e $TESTDIR ]]; then
+               log_must $RM -rf $TESTDIR/* > /dev/null 2>&1
+       fi
+}
+
+log_assert "Verify that a snapshot of a dataset is identical to " \
+    "the original dataset."
+log_onexit cleanup
+
+log_note "Create a file in the zfs filesystem..."
+log_must $FILE_WRITE -o create -f $TESTDIR1/$TESTFILE -b $BLOCKSZ \
+    -c $NUM_WRITES -d $DATA
+
+log_note "Sum the file, save for later comparison..."
+FILE_SUM=`$SUM -r $TESTDIR1/$TESTFILE | $AWK  '{ print $1 }'`
+log_note "FILE_SUM = $FILE_SUM"
+
+log_note "Create a snapshot and mount it..."
+log_must $ZFS snapshot $SNAPCTR
+
+log_note "Append to the original file..."
+log_must $FILE_WRITE -o append -f $TESTDIR1/$TESTFILE -b $BLOCKSZ \
+    -c $NUM_WRITES -d $DATA
+
+SNAP_FILE_SUM=`$SUM -r $SNAPDIR1/$TESTFILE | $AWK '{ print $1 }'`
+if [[ $SNAP_FILE_SUM -ne $FILE_SUM ]]; then
+       log_fail "Sums do not match, aborting!! ($SNAP_FILE_SUM != $FILE_SUM)"
+fi
+
+log_pass "Both Sums match. ($SNAP_FILE_SUM == $FILE_SUM)"
diff --git a/tests/zfs-tests/tests/functional/snapshot/snapshot_006_pos.ksh b/tests/zfs-tests/tests/functional/snapshot/snapshot_006_pos.ksh
new file mode 100755 (executable)
index 0000000..cc2c6ed
--- /dev/null
@@ -0,0 +1,132 @@
+#! /bin/ksh -p
+#
+# CDDL HEADER START
+#
+# The contents of this file are subject to the terms of the
+# Common Development and Distribution License (the "License").
+# You may not use this file except in compliance with the License.
+#
+# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
+# or http://www.opensolaris.org/os/licensing.
+# See the License for the specific language governing permissions
+# and limitations under the License.
+#
+# When distributing Covered Code, include this CDDL HEADER in each
+# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
+# If applicable, add the following below this CDDL HEADER, with the
+# fields enclosed by brackets "[]" replaced with your own identifying
+# information: Portions Copyright [yyyy] [name of copyright owner]
+#
+# CDDL HEADER END
+#
+
+#
+# Copyright 2007 Sun Microsystems, Inc.  All rights reserved.
+# Use is subject to license terms.
+#
+
+#
+# Copyright (c) 2013 by Delphix. All rights reserved.
+#
+
+. $STF_SUITE/include/libtest.shlib
+. $STF_SUITE/tests/functional/snapshot/snapshot.cfg
+
+#
+# DESCRIPTION:
+# An archive of a zfs dataset and an archive of its snapshot
+# changed sinced the snapshot was taken.
+#
+# STRATEGY:
+# 1) Create some files in a ZFS dataset
+# 2) Create a tarball of the dataset
+# 3) Create a snapshot of the dataset
+# 4) Remove all the files in the original dataset
+# 5) Create a tarball of the snapshot
+# 6) Extract each tarball and compare directory structures
+#
+
+verify_runnable "both"
+
+function cleanup
+{
+       if [[ -d $CWD ]]; then
+               cd $CWD || log_fail "Could not cd $CWD"
+       fi
+
+        snapexists $SNAPCTR
+        if [[ $? -eq 0 ]]; then
+                log_must $ZFS destroy $SNAPCTR
+        fi
+
+        if [[ -e $SNAPDIR1 ]]; then
+                log_must $RM -rf $SNAPDIR1 > /dev/null 2>&1
+        fi
+
+        if [[ -e $TESTDIR1 ]]; then
+                log_must $RM -rf $TESTDIR1/* > /dev/null 2>&1
+        fi
+
+       if [[ -e /tmp/zfs_snapshot2.$$ ]]; then
+               log_must $RM -rf /tmp/zfs_snapshot2.$$ > /dev/null 2>&1
+       fi
+
+}
+
+log_assert "Verify that an archive of a dataset is identical to " \
+   "an archive of the dataset's snapshot."
+
+log_onexit cleanup
+
+typeset -i COUNT=21
+typeset OP=create
+
+[[ -n $TESTDIR1 ]] && $RM -rf $TESTDIR1/* > /dev/null 2>&1
+
+log_note "Create files in the zfs dataset ..."
+
+typeset i=1
+while [ $i -lt $COUNT ]; do
+       log_must $FILE_WRITE -o $OP -f $TESTDIR1/file$i \
+           -b $BLOCKSZ -c $NUM_WRITES -d $DATA
+
+       (( i = i + 1 ))
+done
+
+log_note "Create a tarball from $TESTDIR1 contents..."
+CWD=$PWD
+cd $TESTDIR1 || log_fail "Could not cd $TESTDIR1"
+log_must $TAR cf $TESTDIR1/tarball.original.tar file*
+cd $CWD || log_fail "Could not cd $CWD"
+
+log_note "Create a snapshot and mount it..."
+log_must $ZFS snapshot $SNAPCTR
+
+log_note "Remove all of the original files..."
+log_must $RM -f $TESTDIR1/file* > /dev/null 2>&1
+
+log_note "Create tarball of snapshot..."
+CWD=$PWD
+cd $SNAPDIR1 || log_fail "Could not cd $SNAPDIR1"
+log_must $TAR cf $TESTDIR1/tarball.snapshot.tar file*
+cd $CWD || log_fail "Could not cd $CWD"
+
+log_must $MKDIR $TESTDIR1/original
+log_must $MKDIR $TESTDIR1/snapshot
+
+CWD=$PWD
+cd $TESTDIR1/original || log_fail "Could not cd $TESTDIR1/original"
+log_must $TAR xf $TESTDIR1/tarball.original.tar
+
+cd $TESTDIR1/snapshot || log_fail "Could not cd $TESTDIR1/snapshot"
+log_must $TAR xf $TESTDIR1/tarball.snapshot.tar
+
+cd $CWD || log_fail "Could not cd $CWD"
+
+$DIRCMP $TESTDIR1/original $TESTDIR1/snapshot > /tmp/zfs_snapshot2.$$
+$GREP different /tmp/zfs_snapshot2.$$ >/dev/null 2>&1
+if [[ $? -ne 1 ]]; then
+       log_fail "Directory structures differ."
+fi
+
+log_pass "Directory structures match."
diff --git a/tests/zfs-tests/tests/functional/snapshot/snapshot_007_pos.ksh b/tests/zfs-tests/tests/functional/snapshot/snapshot_007_pos.ksh
new file mode 100755 (executable)
index 0000000..5ee9f5d
--- /dev/null
@@ -0,0 +1,107 @@
+#! /bin/ksh -p
+#
+# CDDL HEADER START
+#
+# The contents of this file are subject to the terms of the
+# Common Development and Distribution License (the "License").
+# You may not use this file except in compliance with the License.
+#
+# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
+# or http://www.opensolaris.org/os/licensing.
+# See the License for the specific language governing permissions
+# and limitations under the License.
+#
+# When distributing Covered Code, include this CDDL HEADER in each
+# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
+# If applicable, add the following below this CDDL HEADER, with the
+# fields enclosed by brackets "[]" replaced with your own identifying
+# information: Portions Copyright [yyyy] [name of copyright owner]
+#
+# CDDL HEADER END
+#
+
+#
+# Copyright 2007 Sun Microsystems, Inc.  All rights reserved.
+# Use is subject to license terms.
+#
+
+#
+# Copyright (c) 2013 by Delphix. All rights reserved.
+#
+
+. $STF_SUITE/include/libtest.shlib
+. $STF_SUITE/tests/functional/snapshot/snapshot.cfg
+
+#
+# DESCRIPTION:
+# Verify that many snapshots can be made on a zfs dataset.
+#
+# STRATEGY:
+# 1) Create a file in the zfs dataset
+# 2) Create a snapshot of the dataset
+# 3) Remove all the files from the original dataset
+# 4) For each snapshot directory verify consistency
+#
+
+verify_runnable "both"
+
+function cleanup
+{
+       typeset -i i=1
+       while [ $i -lt $COUNT ]; do
+               snapexists $SNAPCTR.$i
+               if [[ $? -eq 0 ]]; then
+                       log_must $ZFS destroy $SNAPCTR.$i
+               fi
+
+               if [[ -e $SNAPDIR.$i ]]; then
+                       log_must $RM -rf $SNAPDIR1.$i > /dev/null 2>&1
+               fi
+
+               (( i = i + 1 ))
+       done
+
+       if [[ -e $SNAPDIR1 ]]; then
+               log_must $RM -rf $SNAPDIR1 > /dev/null 2>&1
+       fi
+
+       if [[ -e $TESTDIR ]]; then
+               log_must $RM -rf $TESTDIR/* > /dev/null 2>&1
+       fi
+}
+
+log_assert "Verify that many snapshots can be made on a zfs dataset."
+
+log_onexit cleanup
+
+[[ -n $TESTDIR ]] && \
+    log_must $RM -rf $TESTDIR/* > /dev/null 2>&1
+
+typeset -i COUNT=10
+
+log_note "Create some files in the $TESTDIR directory..."
+typeset -i i=1
+while [[ $i -lt $COUNT ]]; do
+       log_must $FILE_WRITE -o create -f $TESTDIR1/file$i \
+          -b $BLOCKSZ -c $NUM_WRITES -d $i
+       log_must $ZFS snapshot $SNAPCTR.$i
+
+       (( i = i + 1 ))
+done
+
+log_note "Remove all of the original files"
+[[ -n $TESTDIR ]] && \
+    log_must $RM -rf $TESTDIR1/file* > /dev/null 2>&1
+
+i=1
+while [[ $i -lt $COUNT ]]; do
+       FILECOUNT=`$LS $SNAPDIR1.$i/file* | wc -l`
+       typeset j=1
+       while [ $j -lt $FILECOUNT ]; do
+               log_must $FILE_CHECK $SNAPDIR1.$i/file$j $j
+               (( j = j + 1 ))
+       done
+       (( i = i + 1 ))
+done
+
+log_pass "All files are consistent"
diff --git a/tests/zfs-tests/tests/functional/snapshot/snapshot_008_pos.ksh b/tests/zfs-tests/tests/functional/snapshot/snapshot_008_pos.ksh
new file mode 100755 (executable)
index 0000000..3610491
--- /dev/null
@@ -0,0 +1,100 @@
+#! /bin/ksh -p
+#
+# CDDL HEADER START
+#
+# The contents of this file are subject to the terms of the
+# Common Development and Distribution License (the "License").
+# You may not use this file except in compliance with the License.
+#
+# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
+# or http://www.opensolaris.org/os/licensing.
+# See the License for the specific language governing permissions
+# and limitations under the License.
+#
+# When distributing Covered Code, include this CDDL HEADER in each
+# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
+# If applicable, add the following below this CDDL HEADER, with the
+# fields enclosed by brackets "[]" replaced with your own identifying
+# information: Portions Copyright [yyyy] [name of copyright owner]
+#
+# CDDL HEADER END
+#
+
+#
+# Copyright 2007 Sun Microsystems, Inc.  All rights reserved.
+# Use is subject to license terms.
+#
+
+#
+# Copyright (c) 2013 by Delphix. All rights reserved.
+#
+
+. $STF_SUITE/include/libtest.shlib
+. $STF_SUITE/tests/functional/snapshot/snapshot.cfg
+
+#
+# DESCRIPTION:
+# Verify that destroying snapshots returns space to the pool.
+#
+# STRATEGY:
+# 1. Create a file system and populate it while snapshotting.
+# 2. Destroy the snapshots and remove the files.
+# 3. Verify the space returns to the pool.
+#
+
+verify_runnable "both"
+
+function cleanup
+{
+       typeset -i i=1
+       while [[ $i -lt $COUNT ]]; do
+               snapexists $SNAPFS.$i
+               [[ $? -eq 0 ]] && \
+                       log_must $ZFS destroy $SNAPFS.$i
+
+               (( i = i + 1 ))
+       done
+
+       [[ -e $TESTDIR ]] && \
+               log_must $RM -rf $TESTDIR/* > /dev/null 2>&1
+}
+
+log_assert "Verify that destroying snapshots returns space to the pool."
+
+log_onexit cleanup
+
+[[ -n $TESTDIR ]] && \
+    log_must $RM -rf $TESTDIR/* > /dev/null 2>&1
+
+typeset -i COUNT=10
+
+orig_size=`get_prop available $TESTPOOL`
+
+log_note "Populate the $TESTDIR directory"
+typeset -i i=1
+while [[ $i -lt $COUNT ]]; do
+       log_must $FILE_WRITE -o create -f $TESTDIR/file$i \
+          -b $BLOCKSZ -c $NUM_WRITES -d $i
+
+       log_must $ZFS snapshot $SNAPFS.$i
+       (( i = i + 1 ))
+done
+
+typeset -i i=1
+while [[ $i -lt $COUNT ]]; do
+       log_must rm -rf $TESTDIR/file$i > /dev/null 2>&1
+       log_must $ZFS destroy $SNAPFS.$i
+
+       (( i = i + 1 ))
+done
+
+new_size=`get_prop available $TESTPOOL`
+
+typeset -i tolerance=0
+
+(( tolerance = new_size - orig_size))
+if (( tolerance > LIMIT )); then
+        log_fail "Space not freed. ($orig_size != $new_size)"
+fi
+
+log_pass "After destroying snapshots, the space is returned to the pool."
diff --git a/tests/zfs-tests/tests/functional/snapshot/snapshot_009_pos.ksh b/tests/zfs-tests/tests/functional/snapshot/snapshot_009_pos.ksh
new file mode 100755 (executable)
index 0000000..dfc75d8
--- /dev/null
@@ -0,0 +1,119 @@
+#! /bin/ksh -p
+#
+# CDDL HEADER START
+#
+# The contents of this file are subject to the terms of the
+# Common Development and Distribution License (the "License").
+# You may not use this file except in compliance with the License.
+#
+# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
+# or http://www.opensolaris.org/os/licensing.
+# See the License for the specific language governing permissions
+# and limitations under the License.
+#
+# When distributing Covered Code, include this CDDL HEADER in each
+# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
+# If applicable, add the following below this CDDL HEADER, with the
+# fields enclosed by brackets "[]" replaced with your own identifying
+# information: Portions Copyright [yyyy] [name of copyright owner]
+#
+# CDDL HEADER END
+#
+
+#
+# Copyright 2007 Sun Microsystems, Inc.  All rights reserved.
+# Use is subject to license terms.
+#
+
+#
+# Copyright (c) 2013 by Delphix. All rights reserved.
+#
+
+. $STF_SUITE/include/libtest.shlib
+. $STF_SUITE/tests/functional/snapshot/snapshot.cfg
+
+#
+# DESCRIPTION:
+#      Verify 'snapshot -r' and 'destroy -r' can correctly create and destroy
+#      snapshot tree respectively.
+#
+# STRATEGY:
+# 1. Use the snapshot -r to create snapshot for top level pool
+# 2. Verify the children snapshots are created correctly.
+# 3. Use destroy -r to destroy the top level snapshot
+# 4. Verify that all children snapshots are destroyed too.
+#
+
+verify_runnable "both"
+
+function cleanup
+{
+       typeset ds
+       typeset snap
+
+       for ds in $ctr/$TESTVOL1 $ctr/$TESTCLONE; do
+               datasetexists $ds && \
+                       log_must $ZFS destroy -f $ds
+       done
+
+       for snap in $ctr/$TESTFS1@$TESTSNAP1 \
+               $snappool $snapvol $snapctr $snapctrvol \
+               $snapctrclone $snapctrfs
+       do
+               snapexists $snap && \
+                       log_must $ZFS destroy -rf $snap
+       done
+
+}
+
+log_assert "Verify snapshot -r can correctly create a snapshot tree."
+log_onexit cleanup
+
+ctr=$TESTPOOL/$TESTCTR
+ctrfs=$ctr/$TESTFS1
+ctrclone=$ctr/$TESTCLONE
+ctrvol=$ctr/$TESTVOL1
+snappool=$SNAPPOOL
+snapfs=$SNAPFS
+snapctr=$ctr@$TESTSNAP
+snapvol=$SNAPFS1
+snapctrvol=$ctrvol@$TESTSNAP
+snapctrclone=$ctrclone@$TESTSNAP
+snapctrfs=$SNAPCTR
+
+#preparation for testing
+log_must $ZFS snapshot $ctrfs@$TESTSNAP1
+log_must $ZFS clone $ctrfs@$TESTSNAP1 $ctrclone
+if is_global_zone; then
+       log_must $ZFS create -V $VOLSIZE $ctrvol
+else
+       log_must $ZFS create $ctrvol
+fi
+
+log_must $ZFS snapshot -r $snappool
+
+#verify the snapshot -r results
+for snap in $snappool $snapfs $snapvol $snapctr $snapctrvol \
+               $snapctrclone $snapctrfs
+do
+       ! snapexists $snap && \
+               log_fail "The snapshot $snap is not created via -r option."
+done
+
+log_note "Verify that destroy -r can destroy the snapshot tree."
+
+log_must $ZFS destroy -r $snappool
+for snap in $snappool $snapfs $snapvol $snapctr $snapctrvol \
+               $snapctrclone $snapctrfs
+do
+       snapexists $snap && \
+               log_fail "The snapshot $snap is not destroyed correctly."
+done
+
+log_note "Verify that the snapshot with different name should \
+               be not destroyed."
+! snapexists $ctrfs@$TESTSNAP1 && \
+       log_fail "destroy -r incorrectly destroys the snapshot \
+               $ctrfs@$TESTSNAP1."
+
+log_pass  "snapshot|destroy -r with snapshot tree works as expected."
diff --git a/tests/zfs-tests/tests/functional/snapshot/snapshot_010_pos.ksh b/tests/zfs-tests/tests/functional/snapshot/snapshot_010_pos.ksh
new file mode 100755 (executable)
index 0000000..cb9ff88
--- /dev/null
@@ -0,0 +1,101 @@
+#! /bin/ksh -p
+#
+# CDDL HEADER START
+#
+# The contents of this file are subject to the terms of the
+# Common Development and Distribution License (the "License").
+# You may not use this file except in compliance with the License.
+#
+# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
+# or http://www.opensolaris.org/os/licensing.
+# See the License for the specific language governing permissions
+# and limitations under the License.
+#
+# When distributing Covered Code, include this CDDL HEADER in each
+# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
+# If applicable, add the following below this CDDL HEADER, with the
+# fields enclosed by brackets "[]" replaced with your own identifying
+# information: Portions Copyright [yyyy] [name of copyright owner]
+#
+# CDDL HEADER END
+#
+
+#
+# Copyright 2007 Sun Microsystems, Inc.  All rights reserved.
+# Use is subject to license terms.
+#
+
+#
+# Copyright (c) 2013 by Delphix. All rights reserved.
+#
+
+. $STF_SUITE/include/libtest.shlib
+. $STF_SUITE/tests/functional/snapshot/snapshot.cfg
+
+#
+# DESCRIPTION:
+#      Verify 'destroy -r' can correctly destroy a snapshot tree at any point.
+#
+# STRATEGY:
+# 1. Use the snapshot -r to create snapshot for top level pool
+# 2. Select a middle point of the snapshot tree, use destroy -r to destroy all
+#      snapshots beneath the point.
+# 3. Verify the destroy results.
+#
+
+verify_runnable "both"
+
+function cleanup
+{
+       typeset snap
+
+       datasetexists $ctrvol && \
+               log_must $ZFS destroy -f $ctrvol
+
+       for snap in $ctrfs@$TESTSNAP1 \
+               $snappool $snapvol $snapctr $snapctrvol \
+               $snapctrclone $snapctrfs
+       do
+               snapexists $snap && \
+                       log_must $ZFS destroy -rf $snap
+       done
+
+}
+
+log_assert "Verify 'destroy -r' can correctly destroy a snapshot subtree at any point."
+log_onexit cleanup
+
+ctr=$TESTPOOL/$TESTCTR
+ctrfs=$ctr/$TESTFS1
+ctrvol=$ctr/$TESTVOL1
+snappool=$SNAPPOOL
+snapfs=$SNAPFS
+snapctr=$ctr@$TESTSNAP
+snapvol=$SNAPFS1
+snapctrvol=$ctr/$TESTVOL1@$TESTSNAP
+snapctrclone=$ctr/$TESTCLONE@$TESTSNAP
+snapctrfs=$SNAPCTR
+
+#preparation for testing
+log_must $ZFS snapshot $ctrfs@$TESTSNAP1
+if is_global_zone; then
+       log_must $ZFS create -V $VOLSIZE $ctrvol
+else
+       log_must $ZFS create $ctrvol
+fi
+
+log_must $ZFS snapshot -r $snappool
+
+#select the $TESTCTR as destroy point, $TESTCTR is a child of $TESTPOOL
+log_must $ZFS destroy -r $snapctr
+for snap in $snapctr $snapctrvol $snapctrclone $snapctrfs; do
+       snapexists $snap && \
+               log_fail "The snapshot $snap is not destroyed correctly."
+done
+
+for snap in $snappool $snapfs $snapvol $ctrfs@$TESTSNAP1;do
+       ! snapexists $snap && \
+               log_fail "The snapshot $snap should be not destroyed."
+done
+
+log_pass  "'destroy -r' destroys snapshot subtree as expected."
diff --git a/tests/zfs-tests/tests/functional/snapshot/snapshot_011_pos.ksh b/tests/zfs-tests/tests/functional/snapshot/snapshot_011_pos.ksh
new file mode 100755 (executable)
index 0000000..9774035
--- /dev/null
@@ -0,0 +1,113 @@
+#! /bin/ksh -p
+#
+# CDDL HEADER START
+#
+# The contents of this file are subject to the terms of the
+# Common Development and Distribution License (the "License").
+# You may not use this file except in compliance with the License.
+#
+# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
+# or http://www.opensolaris.org/os/licensing.
+# See the License for the specific language governing permissions
+# and limitations under the License.
+#
+# When distributing Covered Code, include this CDDL HEADER in each
+# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
+# If applicable, add the following below this CDDL HEADER, with the
+# fields enclosed by brackets "[]" replaced with your own identifying
+# information: Portions Copyright [yyyy] [name of copyright owner]
+#
+# CDDL HEADER END
+#
+
+#
+# Copyright 2007 Sun Microsystems, Inc.  All rights reserved.
+# Use is subject to license terms.
+#
+
+#
+# Copyright (c) 2013 by Delphix. All rights reserved.
+#
+
+. $STF_SUITE/include/libtest.shlib
+. $STF_SUITE/tests/functional/snapshot/snapshot.cfg
+
+#
+# DESCRIPTION:
+#      use 'snapshot -r' to create a snapshot tree, add some files to one child
+#      filesystem, rollback the child filesystem snapshot, verify that the child
+#      filesystem gets back to the status while taking the snapshot.
+#
+# STRATEGY:
+#      1. Add some files to a target child filesystem
+#      2. snapshot -r the parent filesystem
+#      3. Add some other files to the target child filesystem
+#      4. rollback the child filesystem snapshot
+#      5. verify that the child filesystem get back to the status while being
+#         snapshot'd
+#
+
+verify_runnable "both"
+
+function cleanup
+{
+       snapexists $SNAPPOOL && \
+               log_must $ZFS destroy -r $SNAPPOOL
+
+       [[ -e $TESTDIR ]] && \
+               log_must $RM -rf $TESTDIR/* > /dev/null 2>&1
+}
+
+log_assert "Verify that rollback to a snapshot created by snapshot -r succeeds."
+log_onexit cleanup
+
+[[ -n $TESTDIR ]] && \
+    log_must $RM -rf $TESTDIR/* > /dev/null 2>&1
+
+typeset -i COUNT=10
+
+log_note "Populate the $TESTDIR directory (prior to snapshot)"
+typeset -i i=0
+while (( i < COUNT )); do
+       log_must $FILE_WRITE -o create -f $TESTDIR/before_file$i \
+          -b $BLOCKSZ -c $NUM_WRITES -d $i
+
+       (( i = i + 1 ))
+done
+
+log_must $ZFS snapshot -r $SNAPPOOL
+
+FILE_COUNT=`$LS -Al $SNAPDIR | $GREP -v "total" | wc -l`
+if (( FILE_COUNT != COUNT )); then
+        $LS -Al $SNAPDIR
+        log_fail "AFTER: $SNAPFS contains $FILE_COUNT files(s)."
+fi
+
+log_note "Populate the $TESTDIR directory (post snapshot)"
+typeset -i i=0
+while (( i < COUNT )); do
+        log_must $FILE_WRITE -o create -f $TESTDIR/after_file$i \
+           -b $BLOCKSZ -c $NUM_WRITES -d $i
+
+        (( i = i + 1 ))
+done
+
+#
+# Now rollback to latest snapshot
+#
+log_must $ZFS rollback $SNAPFS
+
+FILE_COUNT=`$LS -Al $TESTDIR/after* 2> /dev/null | $GREP -v "total" | wc -l`
+if (( FILE_COUNT != 0 )); then
+        $LS -Al $TESTDIR
+        log_fail "$TESTDIR contains $FILE_COUNT after* files(s)."
+fi
+
+FILE_COUNT=`$LS -Al $TESTDIR/before* 2> /dev/null \
+    | $GREP -v "total" | wc -l`
+if (( FILE_COUNT != $COUNT )); then
+       $LS -Al $TESTDIR
+       log_fail "$TESTDIR contains $FILE_COUNT before* files(s)."
+fi
+
+log_pass "Rollback with child snapshot works as expected."
diff --git a/tests/zfs-tests/tests/functional/snapshot/snapshot_012_pos.ksh b/tests/zfs-tests/tests/functional/snapshot/snapshot_012_pos.ksh
new file mode 100755 (executable)
index 0000000..6f75861
--- /dev/null
@@ -0,0 +1,104 @@
+#! /bin/ksh -p
+#
+# CDDL HEADER START
+#
+# The contents of this file are subject to the terms of the
+# Common Development and Distribution License (the "License").
+# You may not use this file except in compliance with the License.
+#
+# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
+# or http://www.opensolaris.org/os/licensing.
+# See the License for the specific language governing permissions
+# and limitations under the License.
+#
+# When distributing Covered Code, include this CDDL HEADER in each
+# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
+# If applicable, add the following below this CDDL HEADER, with the
+# fields enclosed by brackets "[]" replaced with your own identifying
+# information: Portions Copyright [yyyy] [name of copyright owner]
+#
+# CDDL HEADER END
+#
+
+#
+# Copyright 2008 Sun Microsystems, Inc.  All rights reserved.
+# Use is subject to license terms.
+#
+
+#
+# Copyright (c) 2013 by Delphix. All rights reserved.
+#
+
+. $STF_SUITE/include/libtest.shlib
+. $STF_SUITE/tests/functional/snapshot/snapshot.cfg
+
+#
+# DESCRIPTION:
+#      Verify 'snapshot -r' can create snapshot for promoted clone, and vice
+#      versa, a clone filesystem from the snapshot created by 'snapshot -r'
+#      can be correctly promoted.
+#
+# STRATEGY:
+#      1. Create a dataset tree
+#      2. snapshot a filesystem and clone the snapshot
+#      3. promote the clone
+#      4. snapshot -r the dataset tree
+#      5. verify that the snapshot of cloned filesystem is created correctly
+#      6. clone a snapshot from the snapshot tree
+#      7. promote the clone
+#      8. verify that the clone is promoted correctly.
+#
+
+verify_runnable "both"
+
+function cleanup
+{
+       if datasetexists $clone1; then
+               log_must $ZFS promote $ctrfs
+               log_must $ZFS destroy $clone1
+       fi
+
+       snapexists $snapctr && \
+               log_must $ZFS destroy -r $snapctr
+
+       if snapexists $clone@$TESTSNAP1; then
+               log_must $ZFS promote $ctrfs
+               log_must $ZFS destroy -rR $ctrfs@$TESTSNAP1
+       fi
+}
+
+log_assert "Verify that 'snapshot -r' can work with 'zfs promote'."
+log_onexit cleanup
+
+ctr=$TESTPOOL/$TESTCTR
+ctrfs=$ctr/$TESTFS1
+clone=$ctr/$TESTCLONE
+clone1=$ctr/$TESTCLONE1
+snappool=$SNAPPOOL
+snapfs=$SNAPFS
+snapctr=$ctr@$TESTSNAP
+snapctrclone=$clone@$TESTSNAP
+snapctrclone1=$clone1@$TESTSNAP
+snapctrfs=$SNAPCTR
+
+#preparation for testing
+log_must $ZFS snapshot $ctrfs@$TESTSNAP1
+log_must $ZFS clone $ctrfs@$TESTSNAP1 $clone
+log_must $ZFS promote $clone
+
+log_must $ZFS snapshot -r $snapctr
+
+! snapexists $snapctrclone && \
+       log_fail "'snapshot -r' fails to create $snapctrclone for $ctr/$TESTCLONE."
+
+log_must $ZFS clone $snapctrfs $clone1
+log_must $ZFS promote $clone1
+
+#verify the origin value is correct.
+orig_value=$(get_prop origin $ctrfs)
+if ! snapexists $snapctrclone1 || [[ "$orig_value" != "$snapctrclone1" ]]; then
+       log_fail "'zfs promote' fails to promote $clone which is cloned from \
+               $snapctrfs."
+fi
+
+log_pass "'snapshot -r' can work with 'zfs promote' as expected."
diff --git a/tests/zfs-tests/tests/functional/snapshot/snapshot_013_pos.ksh b/tests/zfs-tests/tests/functional/snapshot/snapshot_013_pos.ksh
new file mode 100755 (executable)
index 0000000..65315ee
--- /dev/null
@@ -0,0 +1,99 @@
+#! /bin/ksh -p
+#
+# CDDL HEADER START
+#
+# The contents of this file are subject to the terms of the
+# Common Development and Distribution License (the "License").
+# You may not use this file except in compliance with the License.
+#
+# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
+# or http://www.opensolaris.org/os/licensing.
+# See the License for the specific language governing permissions
+# and limitations under the License.
+#
+# When distributing Covered Code, include this CDDL HEADER in each
+# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
+# If applicable, add the following below this CDDL HEADER, with the
+# fields enclosed by brackets "[]" replaced with your own identifying
+# information: Portions Copyright [yyyy] [name of copyright owner]
+#
+# CDDL HEADER END
+#
+
+#
+# Copyright 2007 Sun Microsystems, Inc.  All rights reserved.
+# Use is subject to license terms.
+#
+
+#
+# Copyright (c) 2013 by Delphix. All rights reserved.
+#
+
+. $STF_SUITE/include/libtest.shlib
+. $STF_SUITE/tests/functional/snapshot/snapshot.cfg
+
+#
+# DESCRIPTION:
+#      verify that the snapshots created by 'snapshot -r' can be used for
+#      zfs send/recv
+#
+# STRATEGY:
+#      1. create a dataset tree and populate a filesystem
+#      2. snapshot -r the dataset tree
+#      3. select one snapshot used  for zfs send/recv
+#      4. verify the data integrity after zfs send/recv
+#
+
+verify_runnable "both"
+
+function cleanup
+{
+       datasetexists $ctrfs && \
+               $ZFS destroy -r $ctrfs
+
+       snapexists $snappool && \
+               log_must $ZFS destroy -r $snappool
+
+       [[ -e $TESTDIR ]] && \
+               log_must $RM -rf $TESTDIR/* > /dev/null 2>&1
+}
+
+log_assert "Verify snapshots from 'snapshot -r' can be used for zfs send/recv"
+log_onexit cleanup
+
+ctr=$TESTPOOL/$TESTCTR
+ctrfs=$ctr/$TESTFS
+snappool=$SNAPPOOL
+snapfs=$SNAPFS
+snapctr=$ctr@$TESTSNAP
+snapctrfs=$ctrfs@$TESTSNAP
+fsdir=/$ctrfs
+snapdir=$fsdir/.zfs/snapshot/$TESTSNAP
+
+[[ -n $TESTDIR ]] && \
+    log_must $RM -rf $TESTDIR/* > /dev/null 2>&1
+
+typeset -i COUNT=10
+
+log_note "Populate the $TESTDIR directory (prior to snapshot)"
+typeset -i i=0
+while (( i < COUNT )); do
+       log_must $FILE_WRITE -o create -f $TESTDIR/file$i \
+          -b $BLOCKSZ -c $NUM_WRITES -d $i
+
+       (( i = i + 1 ))
+done
+
+log_must $ZFS snapshot -r $snappool
+
+$ZFS send $snapfs | $ZFS receive $ctrfs >/dev/null 2>&1
+if ! datasetexists $ctrfs || ! snapexists $snapctrfs; then
+       log_fail "zfs send/receive fails with snapshot $snapfs."
+fi
+
+for dir in $fsdir $snapdir; do
+       FILE_COUNT=`$LS -Al $dir | $GREP -v "total" | wc -l`
+       (( FILE_COUNT != COUNT )) && log_fail "Got $FILE_COUNT expected $COUNT"
+done
+
+log_pass "'zfs send/receive' works as expected with snapshots from 'snapshot -r'"
diff --git a/tests/zfs-tests/tests/functional/snapshot/snapshot_014_pos.ksh b/tests/zfs-tests/tests/functional/snapshot/snapshot_014_pos.ksh
new file mode 100755 (executable)
index 0000000..39a8ff3
--- /dev/null
@@ -0,0 +1,78 @@
+#! /bin/ksh -p
+#
+# CDDL HEADER START
+#
+# The contents of this file are subject to the terms of the
+# Common Development and Distribution License (the "License").
+# You may not use this file except in compliance with the License.
+#
+# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
+# or http://www.opensolaris.org/os/licensing.
+# See the License for the specific language governing permissions
+# and limitations under the License.
+#
+# When distributing Covered Code, include this CDDL HEADER in each
+# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
+# If applicable, add the following below this CDDL HEADER, with the
+# fields enclosed by brackets "[]" replaced with your own identifying
+# information: Portions Copyright [yyyy] [name of copyright owner]
+#
+# CDDL HEADER END
+#
+
+#
+# Copyright 2007 Sun Microsystems, Inc.  All rights reserved.
+# Use is subject to license terms.
+#
+
+#
+# Copyright (c) 2013 by Delphix. All rights reserved.
+#
+
+. $STF_SUITE/include/libtest.shlib
+. $STF_SUITE/tests/functional/snapshot/snapshot.cfg
+
+#
+# DESCRIPTION:
+#      verify that creating/destroying snapshots do things clean
+#
+# STRATEGY:
+#      1. create a dataset and set a quota with 500m
+#      2. create file of size 400m on the dataset
+#      3. take a snapshot and destroy it
+#      4. then create file to use all spaces in the dataset
+#      5. verify removing the first file should succeed
+#
+
+verify_runnable "both"
+
+function cleanup
+{
+       [[ -e $TESTDIR1 ]] && \
+               log_must $RM -rf $TESTDIR1/* > /dev/null 2>&1
+
+       snapexists $SNAPCTR && \
+               log_must $ZFS destroy $SNAPCTR
+
+       datasetexists $TESTPOOL/$TESTCTR/$TESTFS1 && \
+               log_must $ZFS set quota=none $TESTPOOL/$TESTCTR/$TESTFS1
+
+}
+
+log_assert "Verify creating/destroying snapshots do things clean"
+log_onexit cleanup
+
+log_must $ZFS set quota=$FSQUOTA $TESTPOOL/$TESTCTR/$TESTFS1
+log_must $MKFILE $FILESIZE $TESTDIR1/$TESTFILE
+
+log_must $ZFS snapshot $SNAPCTR
+log_must $ZFS destroy $SNAPCTR
+
+log_note "Make the quota of filesystem is reached"
+log_mustnot $MKFILE $FILESIZE1 $TESTDIR1/$TESTFILE1
+
+log_note "Verify removing the first file should succeed after the snapshot is \
+       removed"
+log_must $RM $TESTDIR1/$TESTFILE
+
+log_pass "Verify creating/destroying snapshots do things clean"
diff --git a/tests/zfs-tests/tests/functional/snapshot/snapshot_015_pos.ksh b/tests/zfs-tests/tests/functional/snapshot/snapshot_015_pos.ksh
new file mode 100755 (executable)
index 0000000..cf819dd
--- /dev/null
@@ -0,0 +1,121 @@
+#!/bin/ksh -p
+#
+# CDDL HEADER START
+#
+# The contents of this file are subject to the terms of the
+# Common Development and Distribution License (the "License").
+# You may not use this file except in compliance with the License.
+#
+# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
+# or http://www.opensolaris.org/os/licensing.
+# See the License for the specific language governing permissions
+# and limitations under the License.
+#
+# When distributing Covered Code, include this CDDL HEADER in each
+# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
+# If applicable, add the following below this CDDL HEADER, with the
+# fields enclosed by brackets "[]" replaced with your own identifying
+# information: Portions Copyright [yyyy] [name of copyright owner]
+#
+# CDDL HEADER END
+#
+
+#
+# Copyright 2009 Sun Microsystems, Inc.  All rights reserved.
+# Use is subject to license terms.
+#
+
+
+#
+# Copyright (c) 2013 by Delphix. All rights reserved.
+#
+
+. $STF_SUITE/include/libtest.shlib
+. $STF_SUITE/tests/functional/snapshot/snapshot.cfg
+. $STF_SUITE/tests/functional/cli_root/zfs_rollback/zfs_rollback_common.kshlib
+
+#
+# DESCRIPTION:
+#      Verify snapshot can be created or destroy via mkdir or rm
+#      in .zfs/snapshot.
+#
+# STRATEGY:
+#      1. Verify make directories only successfully in .zfs/snapshot.
+#      2. Verify snapshot can be created and destroy via mkdir and remove
+#      directories in .zfs/snapshot.
+#      3. Verify rollback to previous snapshot can succeed.
+#      4. Verify remove directory in snapdir can destroy snapshot.
+#
+
+verify_runnable "both"
+
+function cleanup
+{
+       typeset -i i=0
+       while ((i < snap_cnt)); do
+               typeset snap=$fs@snap.$i
+               datasetexists $snap && log_must $ZFS destroy -f $snap
+
+               ((i += 1))
+       done
+}
+
+$ZFS 2>&1 | $GREP "allow" > /dev/null
+(($? != 0)) && log_unsupported
+
+log_assert "Verify snapshot can be created via mkdir in .zfs/snapshot."
+log_onexit cleanup
+
+fs=$TESTPOOL/$TESTFS
+# Verify all the other directories are readonly.
+mntpnt=$(get_prop mountpoint $fs)
+snapdir=$mntpnt/.zfs
+set -A ro_dirs "$snapdir" "$snapdir/snap" "$snapdir/snapshot"
+for dir in ${ro_dirs[@]}; do
+       if [[ -d $dir ]]; then
+               log_mustnot $RM -rf $dir
+               log_mustnot $TOUCH $dir/testfile
+       else
+               log_mustnot $MKDIR $dir
+       fi
+done
+
+# Verify snapshot can be created via mkdir in .zfs/snapshot
+typeset -i snap_cnt=5
+typeset -i cnt=0
+while ((cnt < snap_cnt)); do
+       testfile=$mntpnt/testfile.$cnt
+       log_must $MKFILE 1M $testfile
+       log_must $MKDIR $snapdir/snapshot/snap.$cnt
+       if ! datasetexists $fs@snap.$cnt ; then
+               log_fail "ERROR: $fs@snap.$cnt should exists."
+       fi
+
+       ((cnt += 1))
+done
+
+# Verify rollback to previous snapshot succeed.
+((cnt = RANDOM % snap_cnt))
+log_must $ZFS rollback -r $fs@snap.$cnt
+
+typeset -i i=0
+while ((i < snap_cnt)); do
+       testfile=$mntpnt/testfile.$i
+       if ((i <= cnt)); then
+               if [[ ! -f $testfile ]]; then
+                       log_fail "ERROR: $testfile should exists."
+               fi
+       else
+               if [[ -f $testfile ]]; then
+                       log_fail "ERROR: $testfile should not exists."
+               fi
+       fi
+
+       ((i += 1))
+done
+
+# Verify remove directory in snapdir can destroy snapshot.
+log_must $RMDIR $snapdir/snapshot/snap.$cnt
+log_mustnot datasetexists $fs@snap.$cnt
+
+log_pass "Verify snapshot can be created via mkdir in .zfs/snapshot passed."
diff --git a/tests/zfs-tests/tests/functional/snapshot/snapshot_016_pos.ksh b/tests/zfs-tests/tests/functional/snapshot/snapshot_016_pos.ksh
new file mode 100755 (executable)
index 0000000..9d957c7
--- /dev/null
@@ -0,0 +1,101 @@
+#!/bin/ksh -p
+#
+# CDDL HEADER START
+#
+# The contents of this file are subject to the terms of the
+# Common Development and Distribution License (the "License").
+# You may not use this file except in compliance with the License.
+#
+# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
+# or http://www.opensolaris.org/os/licensing.
+# See the License for the specific language governing permissions
+# and limitations under the License.
+#
+# When distributing Covered Code, include this CDDL HEADER in each
+# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
+# If applicable, add the following below this CDDL HEADER, with the
+# fields enclosed by brackets "[]" replaced with your own identifying
+# information: Portions Copyright [yyyy] [name of copyright owner]
+#
+# CDDL HEADER END
+#
+
+#
+# Copyright 2008 Sun Microsystems, Inc.  All rights reserved.
+# Use is subject to license terms.
+#
+
+
+#
+# Copyright (c) 2013 by Delphix. All rights reserved.
+#
+
+. $STF_SUITE/include/libtest.shlib
+. $STF_SUITE/tests/functional/snapshot/snapshot.cfg
+
+#
+# DESCRIPTION:
+#      Verify renamed snapshots via mv can be destroyed
+#
+# STRATEGY:
+#      1. Create snapshot
+#      2. Rename the snapshot via mv command
+#      2. Verify destroying the renamed snapshot via 'zfs destroy' succeeds
+#
+
+verify_runnable "both"
+
+function cleanup
+{
+       datasetexists $SNAPFS && \
+               log_must $ZFS destroy -Rf $SNAPFS
+       datasetexists $TESTPOOL/$TESTFS@snap_a && \
+               log_must $ZFS destroy -Rf $TESTPOOL/$TESTFS@snap_a
+       datasetexists $TESTPOOL/$TESTCLONE@snap_a && \
+               log_must $ZFS destroy -Rf $TESTPOOL/$TESTCLONE@snap_a
+
+       datasetexists $TESTPOOL/$TESTCLONE && \
+               log_must $ZFS destroy $TESTPOOL/$TESTCLONE
+       datasetexists $TESTPOOL/$TESTFS && \
+               log_must $ZFS destroy $TESTPOOL/$TESTFS
+
+       log_must $ZFS create $TESTPOOL/$TESTFS
+       log_must $ZFS set mountpoint=$TESTDIR $TESTPOOL/$TESTFS
+}
+
+log_assert "Verify renamed snapshots via mv can be destroyed."
+log_onexit cleanup
+
+# scenario 1
+
+log_must $ZFS snapshot $SNAPFS
+log_must $MV $TESTDIR/$SNAPROOT/$TESTSNAP $TESTDIR/$SNAPROOT/snap_a
+
+datasetexists $TESTPOOL/$TESTFS@snap_a || \
+       log_fail "rename snapshot via mv in .zfs/snapshot fails."
+log_must $ZFS destroy $TESTPOOL/$TESTFS@snap_a
+
+# scenario 2
+
+log_must $ZFS snapshot $SNAPFS
+log_must $ZFS clone $SNAPFS $TESTPOOL/$TESTCLONE
+log_must $MV $TESTDIR/$SNAPROOT/$TESTSNAP $TESTDIR/$SNAPROOT/snap_a
+
+datasetexists $TESTPOOL/$TESTFS@snap_a || \
+        log_fail "rename snapshot via mv in .zfs/snapshot fails."
+log_must $ZFS promote $TESTPOOL/$TESTCLONE
+# promote back to $TESTPOOL/$TESTFS for scenario 3
+log_must $ZFS promote $TESTPOOL/$TESTFS
+log_must $ZFS destroy $TESTPOOL/$TESTCLONE
+log_must $ZFS destroy $TESTPOOL/$TESTFS@snap_a
+
+# scenario 3
+
+log_must $ZFS snapshot $SNAPFS
+log_must $ZFS clone $SNAPFS $TESTPOOL/$TESTCLONE
+log_must $ZFS rename $SNAPFS $TESTPOOL/$TESTFS@snap_a
+log_must $ZFS promote $TESTPOOL/$TESTCLONE
+log_must $ZFS destroy $TESTPOOL/$TESTFS
+log_must $ZFS destroy $TESTPOOL/$TESTCLONE@snap_a
+
+log_pass "Verify renamed snapshots via mv can be destroyed."
diff --git a/tests/zfs-tests/tests/functional/snapshot/snapshot_017_pos.ksh b/tests/zfs-tests/tests/functional/snapshot/snapshot_017_pos.ksh
new file mode 100755 (executable)
index 0000000..89d89ff
--- /dev/null
@@ -0,0 +1,202 @@
+#!/bin/ksh -p
+#
+# CDDL HEADER START
+#
+# The contents of this file are subject to the terms of the
+# Common Development and Distribution License (the "License").
+# You may not use this file except in compliance with the License.
+#
+# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
+# or http://www.opensolaris.org/os/licensing.
+# See the License for the specific language governing permissions
+# and limitations under the License.
+#
+# When distributing Covered Code, include this CDDL HEADER in each
+# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
+# If applicable, add the following below this CDDL HEADER, with the
+# fields enclosed by brackets "[]" replaced with your own identifying
+# information: Portions Copyright [yyyy] [name of copyright owner]
+#
+# CDDL HEADER END
+#
+
+#
+# Copyright 2008 Sun Microsystems, Inc.  All rights reserved.
+# Use is subject to license terms.
+#
+
+
+#
+# Copyright (c) 2013 by Delphix. All rights reserved.
+#
+
+. $STF_SUITE/include/libtest.shlib
+. $STF_SUITE/tests/functional/snapshot/snapshot.cfg
+
+#
+# DESCRIPTION:
+#
+# Directory structure of snapshots reflects filesystem structure.
+#
+# STRATEGY:
+#
+# This test makes sure that the directory structure of snapshots is
+# a proper reflection of the filesystem the snapshot was taken of.
+#
+# 1. Create a simple directory structure of files and directories
+# 2. Take a snapshot of the filesystem
+# 3. Modify original filesystem
+# 4. Walk down the snapshot directory structure verifying it
+#    checking with both absolute and relative paths
+#
+
+verify_runnable "both"
+
+function cleanup
+{
+       cd $SAVED_DIR
+
+       if datasetexists $TESTPOOL/$TESTFS ; then
+               log_must $ZFS destroy -Rf $TESTPOOL/$TESTFS
+       fi
+
+       log_must $ZFS create $TESTPOOL/$TESTFS
+       log_must $ZFS set mountpoint=$TESTDIR $TESTPOOL/$TESTFS
+}
+
+function verify_structure {
+
+       # check absolute paths
+       DIR=$PWD
+       verify_file $DIR/file1
+       verify_file $DIR/file2
+       verify_file $DIR/dir1/file3
+       verify_file $DIR/dir1/file4
+       verify_file $DIR/dir1/dir2/file5
+       verify_file $DIR/dir1/dir2/file6
+
+       verify_no_file $DIR/file99
+
+       # check relative paths
+       verify_file ./file1
+       verify_file ./file2
+       verify_file ./dir1/file3
+       verify_file ./dir1/file4
+       verify_file ./dir1/dir2/file5
+       verify_file ./dir1/dir2/file6
+
+       cd dir1
+       verify_file ../file1
+       verify_file ../file2
+       verify_file ./file3
+       verify_file ./file4
+
+       verify_no_file ../file99
+
+       cd dir2
+       verify_file ./file5
+       verify_file ./file6
+       verify_file ../file3
+       verify_file ../file4
+       verify_no_file ../file99
+
+       verify_file ../../file1
+       verify_file ../../file2
+       verify_no_file ../../file99
+}
+
+function verify_file {
+       if [ ! -e $1 ]
+       then
+               log_note "Working dir is $PWD"
+               log_fail "File $1 does not exist!"
+       fi
+}
+
+function verify_no_file {
+       if [ -e $1 ]
+       then
+               log_note "Working dir is $PWD"
+               log_fail "File $1 exists when it should not!"
+       fi
+}
+
+function verify_dir {
+       if [ ! -d $1 ]
+       then
+               log_note "Working dir is $PWD"
+               log_fail "Directory $1 does not exist!"
+       fi
+}
+
+log_assert "Directory structure of snapshots reflects filesystem structure."
+log_onexit cleanup
+
+SAVED_DIR=$PWD
+
+#
+# Create a directory structure with the following files
+#
+# ./file1
+# ./file2
+# ./dir1/file3
+# ./dir1/file4
+# ./dir1/dir2/file5
+# ./dir1/dir2/file6
+
+cd $TESTDIR
+$MKFILE 10m file1
+$MKFILE 20m file2
+$MKDIR dir1
+cd dir1
+$MKFILE 10m file3
+$MKFILE 20m file4
+$MKDIR dir2
+cd dir2
+$MKFILE 10m file5
+$MKFILE 20m file6
+
+# Now walk the directory structure verifying it
+cd $TESTDIR
+verify_structure
+
+# Take snapshots
+log_must $ZFS snapshot $TESTPOOL/$TESTFS@snap_a
+log_must $ZFS snapshot $TESTPOOL/$TESTFS@snap_b
+
+# Change the filesystem structure by renaming files in the original structure
+# The snapshot file structure should not change
+cd $TESTDIR
+log_must $MV file2 file99
+cd dir1
+log_must $MV file4 file99
+cd dir2
+log_must $MV file6 file99
+
+# verify the top level snapshot directories
+verify_dir $TESTDIR/.zfs
+verify_dir $TESTDIR/.zfs/snapshot
+verify_dir $TESTDIR/.zfs/snapshot/snap_a
+verify_dir $TESTDIR/.zfs/snapshot/snap_b
+
+cd $TESTDIR/.zfs/snapshot/snap_a
+verify_structure
+
+cd $TESTDIR/.zfs/snapshot/snap_b
+verify_structure
+
+cd $TESTDIR/.zfs
+verify_dir snapshot
+cd $TESTDIR/.zfs/snapshot
+verify_dir snap_a
+verify_dir snap_b
+
+cd snap_a
+verify_dir ../snap_a
+verify_dir ../snap_b
+
+cd ..
+verify_dir snap_a
+verify_dir snap_b
+
+log_pass "Directory structure of snapshots reflects filesystem structure."
diff --git a/tests/zfs-tests/tests/functional/snapused/Makefile.am b/tests/zfs-tests/tests/functional/snapused/Makefile.am
new file mode 100644 (file)
index 0000000..f19320a
--- /dev/null
@@ -0,0 +1,10 @@
+pkgdatadir = $(datadir)/@PACKAGE@/zfs-tests/tests/functional/snapused
+dist_pkgdata_SCRIPTS = \
+       snapused.kshlib \
+       setup.ksh \
+       cleanup.ksh \
+       snapused_001_pos.ksh \
+       snapused_002_pos.ksh \
+       snapused_003_pos.ksh \
+       snapused_004_pos.ksh \
+       snapused_005_pos.ksh
diff --git a/tests/zfs-tests/tests/functional/snapused/cleanup.ksh b/tests/zfs-tests/tests/functional/snapused/cleanup.ksh
new file mode 100755 (executable)
index 0000000..2f536ca
--- /dev/null
@@ -0,0 +1,34 @@
+#!/bin/ksh -p
+#
+# CDDL HEADER START
+#
+# The contents of this file are subject to the terms of the
+# Common Development and Distribution License (the "License").
+# You may not use this file except in compliance with the License.
+#
+# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
+# or http://www.opensolaris.org/os/licensing.
+# See the License for the specific language governing permissions
+# and limitations under the License.
+#
+# When distributing Covered Code, include this CDDL HEADER in each
+# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
+# If applicable, add the following below this CDDL HEADER, with the
+# fields enclosed by brackets "[]" replaced with your own identifying
+# information: Portions Copyright [yyyy] [name of copyright owner]
+#
+# CDDL HEADER END
+#
+
+#
+# Copyright 2009 Sun Microsystems, Inc.  All rights reserved.
+# Use is subject to license terms.
+#
+
+#
+# Copyright (c) 2013 by Delphix. All rights reserved.
+#
+
+. $STF_SUITE/include/libtest.shlib
+
+default_cleanup
diff --git a/tests/zfs-tests/tests/functional/snapused/setup.ksh b/tests/zfs-tests/tests/functional/snapused/setup.ksh
new file mode 100755 (executable)
index 0000000..dfe8696
--- /dev/null
@@ -0,0 +1,36 @@
+#!/bin/ksh -p
+#
+# CDDL HEADER START
+#
+# The contents of this file are subject to the terms of the
+# Common Development and Distribution License (the "License").
+# You may not use this file except in compliance with the License.
+#
+# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
+# or http://www.opensolaris.org/os/licensing.
+# See the License for the specific language governing permissions
+# and limitations under the License.
+#
+# When distributing Covered Code, include this CDDL HEADER in each
+# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
+# If applicable, add the following below this CDDL HEADER, with the
+# fields enclosed by brackets "[]" replaced with your own identifying
+# information: Portions Copyright [yyyy] [name of copyright owner]
+#
+# CDDL HEADER END
+#
+
+#
+# Copyright 2009 Sun Microsystems, Inc.  All rights reserved.
+# Use is subject to license terms.
+#
+
+#
+# Copyright (c) 2013 by Delphix. All rights reserved.
+#
+
+. $STF_SUITE/include/libtest.shlib
+
+DISK=${DISKS%% *}
+
+default_setup $DISK
diff --git a/tests/zfs-tests/tests/functional/snapused/snapused.kshlib b/tests/zfs-tests/tests/functional/snapused/snapused.kshlib
new file mode 100644 (file)
index 0000000..5e3a765
--- /dev/null
@@ -0,0 +1,185 @@
+#
+# CDDL HEADER START
+#
+# The contents of this file are subject to the terms of the
+# Common Development and Distribution License (the "License").
+# You may not use this file except in compliance with the License.
+#
+# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
+# or http://www.opensolaris.org/os/licensing.
+# See the License for the specific language governing permissions
+# and limitations under the License.
+#
+# When distributing Covered Code, include this CDDL HEADER in each
+# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
+# If applicable, add the following below this CDDL HEADER, with the
+# fields enclosed by brackets "[]" replaced with your own identifying
+# information: Portions Copyright [yyyy] [name of copyright owner]
+#
+# CDDL HEADER END
+#
+
+#
+# Copyright 2009 Sun Microsystems, Inc.  All rights reserved.
+# Use is subject to license terms.
+#
+
+#
+# Copyright (c) 2013 by Delphix. All rights reserved.
+#
+
+. $STF_SUITE/include/libtest.shlib
+
+export USEDTEST=$TESTPOOL/$TESTFS/usedtest-snapused
+
+function _check_used # dataset
+{
+        typeset dataset=$1
+
+       if [[ "$(get_prop type $dataset)" == "snapshot" ]]; then
+               return
+       fi
+
+       used=$(get_prop used $dataset)
+       usedbychildren=$(get_prop usedbychildren $dataset)
+       usedbydataset=$(get_prop usedbydataset $dataset)
+       usedbyrefreservation=$(get_prop usedbyrefreservation $dataset)
+       usedbysnapshots=$(get_prop usedbysnapshots $dataset)
+       ((used_sum = usedbychildren + usedbydataset + \
+               usedbyrefreservation + usedbysnapshots))
+       if ((used != used_sum)); then
+               log_fail "$dataset: used($used) is not the sum($used_sum) of usedby*"
+       fi
+}
+
+function check_used # dataset
+{
+       typeset dataset=$1
+       for child in $($ZFS list -rH -t filesystem,volume -o name $dataset)
+       do
+               _check_used $child
+       done
+}
+
+function check_usedbychildren # dataset
+{
+       typeset dataset=$1
+       typeset -i usedbychildren_sum=0
+       typeset -i parent_usedbychildren=0
+       for child in $($ZFS list -rH -t filesystem,volume -o name $dataset)
+       do
+               if [[ "$(get_prop type $child)" == "snapshot" ]]; then
+                       continue
+               fi
+
+               # parent
+               if [[ "$child" == "$dataset" ]]; then
+                       parent_usedbychildren=$(get_prop usedbychildren $child)
+               else #child
+                       reservation=$(get_prop reservation $child)
+                       used=$(get_prop used $child)
+                       if ((reservation > used)); then
+                               ((usedbychildren_sum += reservation))
+                       else
+                               ((usedbychildren_sum += used))
+                       fi
+               fi
+       done
+
+        if ((parent_usedbychildren != usedbychildren_sum)); then
+                log_fail "$dataset: usedbychildren($parent_usedbychildren) is not the sum($usedbychildren_sum) of used by children"
+        fi
+}
+
+function _check_usedbydataset # dataset
+{
+        typeset dataset=$1
+       if [[ "$(get_prop type $dataset)" == "snapshot" ]]; then
+               return
+       fi
+
+       usedbydataset=$(get_prop usedbydataset $dataset)
+       referenced=$(get_prop referenced $dataset)
+
+       is_cloned=$(get_prop is:cloned $dataset)
+
+       if [[ "$is_cloned" == "yes" ]]; then
+               if ((usedbydataset > referenced)); then
+                       log_fail "$dataset(cloned): usedbydataset($usedbydataset) is more than referenced($referenced)"
+               fi
+       else
+               #
+               # if non-clones, should usedbydataset == referenced
+               #
+               if ((usedbydataset != referenced)); then
+                       log_fail "$dataset: usedbydataset($usedbydataset) is not equal to referenced($referenced)"
+               fi
+       fi
+}
+
+function check_usedbydataset # dataset
+{
+       typeset dataset=$1
+       for child in $($ZFS list -rH -t filesystem,volume -o name $dataset)
+       do
+               _check_usedbydataset $child
+       done
+}
+
+function _check_usedbyrefreservation # dataset
+{
+        typeset dataset=$1
+       if [[ "$(get_prop type $dataset)" == "snapshot" ]]; then
+               return
+       fi
+
+       usedbyrefreservation=$(get_prop usedbyrefreservation $dataset)
+       referenced=$(get_prop referenced $dataset)
+       refreservation=$(get_prop refreservation $dataset)
+       ((diff_ref = refreservation - referenced))
+       if ((usedbyrefreservation > refreservation || \
+               usedbyrefreservation < diff_ref)); then
+               log_fail "$dataset: usedbyrefreservation($usedbyrefreservation) checking is not ok"
+       fi
+}
+
+function check_usedbyrefreservation # dataset
+{
+       typeset dataset=$1
+       for child in $($ZFS list -rH -t filesystem,volume -o name $dataset)
+       do
+               _check_usedbyrefreservation $child
+       done
+}
+
+function check_usedbysnapshots # dataset
+{
+       typeset dataset=$1
+       typeset -i usedbysnapshots_sum=0
+       typeset -i parent_usedbysnapshots=0
+       for child in $($ZFS list -rH -t filesystem,volume,snapshot -o name $dataset)
+       do
+               # parent
+               if [[ "$child" == "$dataset" ]]; then
+                       parent_usedbysnapshots=$(get_prop usedbysnapshots $child)
+                       continue
+               fi
+
+               if [[ "$(get_prop type $child)" != "snapshot" ]]; then
+                       continue
+               fi
+
+               if [[ "$child" != "$dataset@"* ]]; then
+                       continue
+               fi
+
+               # snapshot
+               used=$(get_prop used $child)
+               ((usedbysnapshots_sum += used))
+       done
+
+        if ((parent_usedbysnapshots < usedbysnapshots_sum)); then
+                log_fail "$dataset: usedbysnapshots($parent_usedbysnapshots) is not more than or equal to" \
+                               "the sum($usedbysnapshots_sum) of used of snapshots"
+        fi
+}
diff --git a/tests/zfs-tests/tests/functional/snapused/snapused_001_pos.ksh b/tests/zfs-tests/tests/functional/snapused/snapused_001_pos.ksh
new file mode 100755 (executable)
index 0000000..3182ded
--- /dev/null
@@ -0,0 +1,91 @@
+#!/bin/ksh -p
+#
+# CDDL HEADER START
+#
+# The contents of this file are subject to the terms of the
+# Common Development and Distribution License (the "License").
+# You may not use this file except in compliance with the License.
+#
+# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
+# or http://www.opensolaris.org/os/licensing.
+# See the License for the specific language governing permissions
+# and limitations under the License.
+#
+# When distributing Covered Code, include this CDDL HEADER in each
+# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
+# If applicable, add the following below this CDDL HEADER, with the
+# fields enclosed by brackets "[]" replaced with your own identifying
+# information: Portions Copyright [yyyy] [name of copyright owner]
+#
+# CDDL HEADER END
+#
+
+#
+# Copyright 2009 Sun Microsystems, Inc.  All rights reserved.
+# Use is subject to license terms.
+#
+
+#
+# Copyright (c) 2013 by Delphix. All rights reserved.
+#
+
+. $STF_SUITE/include/libtest.shlib
+. $STF_SUITE/tests/functional/snapused/snapused.kshlib
+
+#
+# DESCRIPTION:
+#      Verify used is correct.
+#
+# STRATEGY:
+#      1. Create a filesystem.
+#      2. Set refreservation of the filesystem.
+#      3. Make file in the filesystem.
+#      4. Create sub filesystem and make file in it.
+#      5. Create volume under it.
+#      6. Snapshot it.
+#      7. Check used=usedbychildren+usedbydataset+
+#              usedbyrefreservation+usedbysnapshots.
+#
+
+verify_runnable "both"
+
+function cleanup
+{
+       log_must $ZFS destroy -rR $USEDTEST
+}
+
+log_assert "Verify used is correct."
+log_onexit cleanup
+
+log_must $ZFS create $USEDTEST
+check_used $USEDTEST
+
+typeset -i i=0
+typeset -i r_size=0
+mntpnt=$(get_prop mountpoint $USEDTEST)
+while ((i < 5)); do
+       ((r_size=(i+1)*16))
+
+       #usedbyrefreservation
+       log_must $ZFS set refreservation="$r_size"M $USEDTEST
+
+       #usedbydataset
+       log_must $MKFILE 16M $mntpnt/file$i
+
+       #usedbychildren
+       log_must $ZFS create $USEDTEST/fs$i
+       log_must $MKFILE 16M $mntpnt/fs$i/file$i
+
+       if is_global_zone; then
+               log_must $ZFS create -V 16M $USEDTEST/vol$i
+       fi
+
+       #usedbysnapshots
+       log_must $ZFS snapshot -r $USEDTEST@snap$i
+
+       check_used $USEDTEST
+
+        ((i = i + 1))
+done
+
+log_pass "Verify used is correct."
diff --git a/tests/zfs-tests/tests/functional/snapused/snapused_002_pos.ksh b/tests/zfs-tests/tests/functional/snapused/snapused_002_pos.ksh
new file mode 100755 (executable)
index 0000000..db6ac3d
--- /dev/null
@@ -0,0 +1,82 @@
+#!/bin/ksh -p
+#
+# CDDL HEADER START
+#
+# The contents of this file are subject to the terms of the
+# Common Development and Distribution License (the "License").
+# You may not use this file except in compliance with the License.
+#
+# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
+# or http://www.opensolaris.org/os/licensing.
+# See the License for the specific language governing permissions
+# and limitations under the License.
+#
+# When distributing Covered Code, include this CDDL HEADER in each
+# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
+# If applicable, add the following below this CDDL HEADER, with the
+# fields enclosed by brackets "[]" replaced with your own identifying
+# information: Portions Copyright [yyyy] [name of copyright owner]
+#
+# CDDL HEADER END
+#
+
+#
+# Copyright 2009 Sun Microsystems, Inc.  All rights reserved.
+# Use is subject to license terms.
+#
+
+#
+# Copyright (c) 2013 by Delphix. All rights reserved.
+#
+
+. $STF_SUITE/include/libtest.shlib
+. $STF_SUITE/tests/functional/snapused/snapused.kshlib
+
+#
+# DESCRIPTION:
+#      Verify usedbychildren is correct.
+#
+# STRATEGY:
+#      1. Create a filesystem.
+#      2. Create sub filesystem and make file in it.
+#      3. Set reservation of the sub filesystem.
+#      4. Create volume under it.
+#      5. Snapshot it.
+#      6. Check usedbychildren is correct.
+#
+
+verify_runnable "both"
+
+function cleanup
+{
+       log_must $ZFS destroy -rR $USEDTEST
+}
+
+log_assert "Verify usedbychildren is correct."
+log_onexit cleanup
+
+log_must $ZFS create $USEDTEST
+check_usedbychildren $USEDTEST
+
+typeset -i i=0
+typeset -i r_size=0
+mntpnt=$(get_prop mountpoint $USEDTEST)
+while ((i < 5)); do
+       ((r_size=(i+1)*16))
+
+       log_must $ZFS create $USEDTEST/fs$i
+       log_must $ZFS set reservation="$r_size"M $USEDTEST/fs$i
+       log_must $MKFILE 48M $mntpnt/fs$i/file$i
+
+       if is_global_zone; then
+               log_must $ZFS create -V 32M $USEDTEST/vol$i
+       fi
+
+       log_must $ZFS snapshot -r $USEDTEST@snap$i
+
+       check_usedbychildren $USEDTEST
+
+        ((i = i + 1))
+done
+
+log_pass "Verify usedbychildren is correct."
diff --git a/tests/zfs-tests/tests/functional/snapused/snapused_003_pos.ksh b/tests/zfs-tests/tests/functional/snapused/snapused_003_pos.ksh
new file mode 100755 (executable)
index 0000000..9dee1f3
--- /dev/null
@@ -0,0 +1,82 @@
+#!/bin/ksh -p
+#
+# CDDL HEADER START
+#
+# The contents of this file are subject to the terms of the
+# Common Development and Distribution License (the "License").
+# You may not use this file except in compliance with the License.
+#
+# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
+# or http://www.opensolaris.org/os/licensing.
+# See the License for the specific language governing permissions
+# and limitations under the License.
+#
+# When distributing Covered Code, include this CDDL HEADER in each
+# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
+# If applicable, add the following below this CDDL HEADER, with the
+# fields enclosed by brackets "[]" replaced with your own identifying
+# information: Portions Copyright [yyyy] [name of copyright owner]
+#
+# CDDL HEADER END
+#
+
+#
+# Copyright 2009 Sun Microsystems, Inc.  All rights reserved.
+# Use is subject to license terms.
+#
+
+#
+# Copyright (c) 2013 by Delphix. All rights reserved.
+#
+
+. $STF_SUITE/include/libtest.shlib
+. $STF_SUITE/tests/functional/snapused/snapused.kshlib
+
+#
+# DESCRIPTION:
+#      Verify usedbydataset is correct.
+#
+# STRATEGY:
+#      1. Create a filesystem.
+#      2. Make file in the filesystem.
+#      3. Snapshot it.
+#      4. Clone it and make file in the cloned filesystem.
+#      5. Check usedbydataset is correct.
+#
+
+verify_runnable "both"
+
+function cleanup
+{
+       log_must $ZFS destroy -rR $USEDTEST
+}
+
+log_assert "Verify usedbydataset is correct."
+log_onexit cleanup
+
+log_must $ZFS create $USEDTEST
+check_usedbydataset $USEDTEST
+
+typeset -i i=0
+typeset -i r_size=0
+mntpnt=$(get_prop mountpoint $USEDTEST)
+while ((i < 5)); do
+       ((r_size=(i+1)*16))
+
+       log_must $MKFILE 16M $mntpnt/file$i
+       log_must $MKFILE "$r_size"M $mntpnt/file_var$i
+       log_must $ZFS snapshot -r $USEDTEST@snap$i
+
+       log_must $ZFS clone $USEDTEST@snap$i $USEDTEST/cln$i
+       log_must $ZFS set is:cloned=yes $USEDTEST/cln$i
+
+       mntpnt_cln=$(get_prop mountpoint $USEDTEST/cln$i)
+       log_must $MKFILE 16M $mntpnt_cln/file_cln$i
+       log_must $MKFILE "$r_size"M $mntpnt_cln/file_cln_var$i
+
+       check_usedbydataset $USEDTEST
+
+        ((i = i + 1))
+done
+
+log_pass "Verify usedbydataset is correct."
diff --git a/tests/zfs-tests/tests/functional/snapused/snapused_004_pos.ksh b/tests/zfs-tests/tests/functional/snapused/snapused_004_pos.ksh
new file mode 100755 (executable)
index 0000000..2cc4cad
--- /dev/null
@@ -0,0 +1,95 @@
+#!/bin/ksh -p
+#
+# CDDL HEADER START
+#
+# The contents of this file are subject to the terms of the
+# Common Development and Distribution License (the "License").
+# You may not use this file except in compliance with the License.
+#
+# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
+# or http://www.opensolaris.org/os/licensing.
+# See the License for the specific language governing permissions
+# and limitations under the License.
+#
+# When distributing Covered Code, include this CDDL HEADER in each
+# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
+# If applicable, add the following below this CDDL HEADER, with the
+# fields enclosed by brackets "[]" replaced with your own identifying
+# information: Portions Copyright [yyyy] [name of copyright owner]
+#
+# CDDL HEADER END
+#
+
+#
+# Copyright 2009 Sun Microsystems, Inc.  All rights reserved.
+# Use is subject to license terms.
+#
+
+#
+# Copyright (c) 2013 by Delphix. All rights reserved.
+#
+
+. $STF_SUITE/include/libtest.shlib
+. $STF_SUITE/tests/functional/snapused/snapused.kshlib
+
+#
+# DESCRIPTION:
+#      Verify usedbyrefreservation is correct.
+#
+# STRATEGY:
+#      1. Create a filesystem.
+#      2. Set refreservation of the filesystem.
+#      3. Make file in the filesystem.
+#      4. Create sub filesystem and make file in it.
+#      5. Set refreservation of the sub filesystem.
+#      6. Create volume under it.
+#      7. Snapshot it.
+#      8. Clone it and set refreservation of the cloned filesystem.
+#      9. Makefile the cloned filesystem.
+#      10. Check usedbyrefreservation is correct.
+#
+
+verify_runnable "both"
+
+function cleanup
+{
+       log_must $ZFS destroy -rR $USEDTEST
+}
+
+log_assert "Verify usedbyrefreservation is correct."
+log_onexit cleanup
+
+log_must $ZFS create $USEDTEST
+check_usedbyrefreservation $USEDTEST
+
+typeset -i i=0
+typeset -i r_size=0
+mntpnt=$(get_prop mountpoint $USEDTEST)
+while ((i < 5)); do
+       ((r_size=(i+1)*16))
+       log_must $ZFS set refreservation="$r_size"M $USEDTEST
+
+       log_must $MKFILE 16M $mntpnt/file$i
+
+       log_must $ZFS create $USEDTEST/fs$i
+       log_must $ZFS set refreservation="$r_size"M $USEDTEST/fs$i
+       log_must $MKFILE 16M $mntpnt/fs$i/file$i
+
+       if is_global_zone; then
+               log_must $ZFS create -V 16M $USEDTEST/vol$i
+       fi
+
+       log_must $ZFS snapshot -r $USEDTEST@snap$i
+
+       log_must $ZFS clone $USEDTEST@snap$i $USEDTEST/cln$i
+
+       mntpnt_cln=$(get_prop mountpoint $USEDTEST/cln$i)
+       log_must $ZFS set refreservation="$r_size"M $USEDTEST/cln$i
+       log_must $MKFILE 16M $mntpnt_cln/file_cln$i
+
+       check_usedbyrefreservation $USEDTEST
+
+        ((i = i + 1))
+done
+
+log_pass "Verify usedbyrefreservation is correct."
diff --git a/tests/zfs-tests/tests/functional/snapused/snapused_005_pos.ksh b/tests/zfs-tests/tests/functional/snapused/snapused_005_pos.ksh
new file mode 100755 (executable)
index 0000000..f4099c8
--- /dev/null
@@ -0,0 +1,73 @@
+#!/bin/ksh -p
+#
+# CDDL HEADER START
+#
+# The contents of this file are subject to the terms of the
+# Common Development and Distribution License (the "License").
+# You may not use this file except in compliance with the License.
+#
+# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
+# or http://www.opensolaris.org/os/licensing.
+# See the License for the specific language governing permissions
+# and limitations under the License.
+#
+# When distributing Covered Code, include this CDDL HEADER in each
+# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
+# If applicable, add the following below this CDDL HEADER, with the
+# fields enclosed by brackets "[]" replaced with your own identifying
+# information: Portions Copyright [yyyy] [name of copyright owner]
+#
+# CDDL HEADER END
+#
+
+#
+# Copyright 2009 Sun Microsystems, Inc.  All rights reserved.
+# Use is subject to license terms.
+#
+
+#
+# Copyright (c) 2013 by Delphix. All rights reserved.
+#
+
+. $STF_SUITE/include/libtest.shlib
+. $STF_SUITE/tests/functional/snapused/snapused.kshlib
+
+#
+# DESCRIPTION:
+#      Verify usedbysnapshots is correct.
+#
+# STRATEGY:
+#      1. Create a filesystem.
+#      2. Make file in the filesystem.
+#      3. Snapshot it.
+#      4. Check check_usedbysnapshots is correct.
+#
+
+verify_runnable "both"
+
+function cleanup
+{
+       log_must $ZFS destroy -rR $USEDTEST
+}
+
+log_assert "Verify usedbysnapshots is correct."
+log_onexit cleanup
+
+log_must $ZFS create $USEDTEST
+check_usedbysnapshots $USEDTEST
+
+typeset -i i=0
+typeset -i r_size=0
+mntpnt=$(get_prop mountpoint $USEDTEST)
+while ((i < 5)); do
+       ((r_size=(i+1)*16))
+
+       log_must $MKFILE "$r_size"M $mntpnt/file$i
+
+       log_must $ZFS snapshot $USEDTEST@snap$i
+       check_usedbysnapshots $USEDTEST
+
+        ((i = i + 1))
+done
+
+log_pass "Verify usedbysnapshots is correct."
diff --git a/tests/zfs-tests/tests/functional/sparse/Makefile.am b/tests/zfs-tests/tests/functional/sparse/Makefile.am
new file mode 100644 (file)
index 0000000..33256b9
--- /dev/null
@@ -0,0 +1,6 @@
+pkgdatadir = $(datadir)/@PACKAGE@/zfs-tests/tests/functional/sparse
+dist_pkgdata_SCRIPTS = \
+       sparse.cfg \
+       setup.ksh \
+       cleanup.ksh \
+       sparse_001_pos.ksh
diff --git a/tests/zfs-tests/tests/functional/sparse/cleanup.ksh b/tests/zfs-tests/tests/functional/sparse/cleanup.ksh
new file mode 100755 (executable)
index 0000000..3166bd6
--- /dev/null
@@ -0,0 +1,34 @@
+#!/bin/ksh -p
+#
+# CDDL HEADER START
+#
+# The contents of this file are subject to the terms of the
+# Common Development and Distribution License (the "License").
+# You may not use this file except in compliance with the License.
+#
+# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
+# or http://www.opensolaris.org/os/licensing.
+# See the License for the specific language governing permissions
+# and limitations under the License.
+#
+# When distributing Covered Code, include this CDDL HEADER in each
+# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
+# If applicable, add the following below this CDDL HEADER, with the
+# fields enclosed by brackets "[]" replaced with your own identifying
+# information: Portions Copyright [yyyy] [name of copyright owner]
+#
+# CDDL HEADER END
+#
+
+#
+# Copyright 2007 Sun Microsystems, Inc.  All rights reserved.
+# Use is subject to license terms.
+#
+
+#
+# Copyright (c) 2013 by Delphix. All rights reserved.
+#
+
+. $STF_SUITE/include/libtest.shlib
+
+default_cleanup
diff --git a/tests/zfs-tests/tests/functional/sparse/setup.ksh b/tests/zfs-tests/tests/functional/sparse/setup.ksh
new file mode 100755 (executable)
index 0000000..3a45ec8
--- /dev/null
@@ -0,0 +1,36 @@
+#!/bin/ksh -p
+#
+# CDDL HEADER START
+#
+# The contents of this file are subject to the terms of the
+# Common Development and Distribution License (the "License").
+# You may not use this file except in compliance with the License.
+#
+# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
+# or http://www.opensolaris.org/os/licensing.
+# See the License for the specific language governing permissions
+# and limitations under the License.
+#
+# When distributing Covered Code, include this CDDL HEADER in each
+# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
+# If applicable, add the following below this CDDL HEADER, with the
+# fields enclosed by brackets "[]" replaced with your own identifying
+# information: Portions Copyright [yyyy] [name of copyright owner]
+#
+# CDDL HEADER END
+#
+
+#
+# Copyright 2007 Sun Microsystems, Inc.  All rights reserved.
+# Use is subject to license terms.
+#
+
+#
+# Copyright (c) 2013 by Delphix. All rights reserved.
+#
+
+. $STF_SUITE/include/libtest.shlib
+
+disk=${DISKS%% *}
+
+default_setup $disk
diff --git a/tests/zfs-tests/tests/functional/sparse/sparse.cfg b/tests/zfs-tests/tests/functional/sparse/sparse.cfg
new file mode 100644 (file)
index 0000000..ba969ee
--- /dev/null
@@ -0,0 +1,37 @@
+#
+# CDDL HEADER START
+#
+# The contents of this file are subject to the terms of the
+# Common Development and Distribution License (the "License").
+# You may not use this file except in compliance with the License.
+#
+# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
+# or http://www.opensolaris.org/os/licensing.
+# See the License for the specific language governing permissions
+# and limitations under the License.
+#
+# When distributing Covered Code, include this CDDL HEADER in each
+# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
+# If applicable, add the following below this CDDL HEADER, with the
+# fields enclosed by brackets "[]" replaced with your own identifying
+# information: Portions Copyright [yyyy] [name of copyright owner]
+#
+# CDDL HEADER END
+#
+
+#
+# Copyright 2008 Sun Microsystems, Inc.  All rights reserved.
+# Use is subject to license terms.
+#
+
+#
+# Copyright (c) 2013 by Delphix. All rights reserved.
+#
+
+export TESTFILE=testfile.sparse
+export HOLES_FILESIZE=${HOLES_FILESIZE-"67108864"} # 64 Mb
+export HOLES_BLKSIZE=${HOLES_BLKSIZE-"512"}
+export HOLES_SEED=${HOLES_SEED-""}
+export HOLES_FILEOFFSET=${HOLES_FILEOFFSET-""}
+export HOLES_COUNT=${HOLES_COUNT-"16384"}         # FILESIZE/BLKSIZE/8
+export STF_TIMEOUT=3600
diff --git a/tests/zfs-tests/tests/functional/sparse/sparse_001_pos.ksh b/tests/zfs-tests/tests/functional/sparse/sparse_001_pos.ksh
new file mode 100755 (executable)
index 0000000..f5d7546
--- /dev/null
@@ -0,0 +1,80 @@
+#!/bin/ksh -p
+#
+# CDDL HEADER START
+#
+# The contents of this file are subject to the terms of the
+# Common Development and Distribution License (the "License").
+# You may not use this file except in compliance with the License.
+#
+# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
+# or http://www.opensolaris.org/os/licensing.
+# See the License for the specific language governing permissions
+# and limitations under the License.
+#
+# When distributing Covered Code, include this CDDL HEADER in each
+# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
+# If applicable, add the following below this CDDL HEADER, with the
+# fields enclosed by brackets "[]" replaced with your own identifying
+# information: Portions Copyright [yyyy] [name of copyright owner]
+#
+# CDDL HEADER END
+#
+
+#
+# Copyright 2009 Sun Microsystems, Inc.  All rights reserved.
+# Use is subject to license terms.
+#
+
+#
+# Copyright (c) 2013 by Delphix. All rights reserved.
+#
+
+. $STF_SUITE/include/libtest.shlib
+. $STF_SUITE/tests/functional/sparse/sparse.cfg
+
+#
+# DESCRIPTION:
+# Holes in ZFS files work correctly.
+#
+# STRATEGY:
+# 1. Open file
+# 2. Write random blocks in random places
+# 3. Read each block back to check for correctness.
+# 4. Repeat steps 2 and 3 lots of times
+#
+
+verify_runnable "global"
+
+function cleanup
+{
+       [[ -e $TESTDIR ]] && log_must $RM -rf $TESTDIR/*
+}
+
+log_assert "Ensure random blocks are read back correctly"
+
+options=""
+options_display="default options"
+
+log_onexit cleanup
+
+[[ -n "$HOLES_FILESIZE" ]] && options=" $options -f $HOLES_FILESIZE "
+
+[[ -n "$HOLES_BLKSIZE" ]] && options="$options -b $HOLES_BLKSIZE "
+
+[[ -n "$HOLES_COUNT" ]] && options="$options -c $HOLES_COUNT "
+
+[[ -n "$HOLES_SEED" ]] && options="$options -s $HOLES_SEED "
+
+[[ -n "$HOLES_FILEOFFSET" ]] && options="$options -o $HOLES_FILEOFFSET "
+
+options="$options -r "
+
+[[ -n "$options" ]] && options_display=$options
+
+log_note "Invoking $FILE_TRUNC with: $options_display"
+log_must $FILE_TRUNC $options $TESTDIR/$TESTFILE
+
+typeset dir=$(get_device_dir $DISKS)
+verify_filesys "$TESTPOOL" "$TESTPOOL/$TESTFS" "$dir"
+
+log_pass "Random blocks have been read back correctly."
diff --git a/tests/zfs-tests/tests/functional/threadsappend/.gitignore b/tests/zfs-tests/tests/functional/threadsappend/.gitignore
new file mode 100644 (file)
index 0000000..4c8c8cd
--- /dev/null
@@ -0,0 +1 @@
+/threadsappend
diff --git a/tests/zfs-tests/tests/functional/threadsappend/Makefile.am b/tests/zfs-tests/tests/functional/threadsappend/Makefile.am
new file mode 100644 (file)
index 0000000..80f7788
--- /dev/null
@@ -0,0 +1,8 @@
+include $(top_srcdir)/config/Rules.am
+
+pkgdatadir = $(datadir)/@PACKAGE@/zfs-tests/tests/functional/threadsappend
+
+dist_pkgdata_SCRIPTS = \
+       cleanup.ksh \
+       setup.ksh \
+       threadsappend_001_pos.ksh
diff --git a/tests/zfs-tests/tests/functional/threadsappend/cleanup.ksh b/tests/zfs-tests/tests/functional/threadsappend/cleanup.ksh
new file mode 100755 (executable)
index 0000000..3166bd6
--- /dev/null
@@ -0,0 +1,34 @@
+#!/bin/ksh -p
+#
+# CDDL HEADER START
+#
+# The contents of this file are subject to the terms of the
+# Common Development and Distribution License (the "License").
+# You may not use this file except in compliance with the License.
+#
+# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
+# or http://www.opensolaris.org/os/licensing.
+# See the License for the specific language governing permissions
+# and limitations under the License.
+#
+# When distributing Covered Code, include this CDDL HEADER in each
+# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
+# If applicable, add the following below this CDDL HEADER, with the
+# fields enclosed by brackets "[]" replaced with your own identifying
+# information: Portions Copyright [yyyy] [name of copyright owner]
+#
+# CDDL HEADER END
+#
+
+#
+# Copyright 2007 Sun Microsystems, Inc.  All rights reserved.
+# Use is subject to license terms.
+#
+
+#
+# Copyright (c) 2013 by Delphix. All rights reserved.
+#
+
+. $STF_SUITE/include/libtest.shlib
+
+default_cleanup
diff --git a/tests/zfs-tests/tests/functional/threadsappend/setup.ksh b/tests/zfs-tests/tests/functional/threadsappend/setup.ksh
new file mode 100755 (executable)
index 0000000..4fc55cd
--- /dev/null
@@ -0,0 +1,36 @@
+#!/bin/ksh -p
+#
+# CDDL HEADER START
+#
+# The contents of this file are subject to the terms of the
+# Common Development and Distribution License (the "License").
+# You may not use this file except in compliance with the License.
+#
+# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
+# or http://www.opensolaris.org/os/licensing.
+# See the License for the specific language governing permissions
+# and limitations under the License.
+#
+# When distributing Covered Code, include this CDDL HEADER in each
+# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
+# If applicable, add the following below this CDDL HEADER, with the
+# fields enclosed by brackets "[]" replaced with your own identifying
+# information: Portions Copyright [yyyy] [name of copyright owner]
+#
+# CDDL HEADER END
+#
+
+#
+# Copyright 2007 Sun Microsystems, Inc.  All rights reserved.
+# Use is subject to license terms.
+#
+
+#
+# Copyright (c) 2013 by Delphix. All rights reserved.
+#
+
+. $STF_SUITE/include/libtest.shlib
+
+DISK=${DISKS%% *}
+
+default_setup ${DISK}
diff --git a/tests/zfs-tests/tests/functional/threadsappend/threadsappend_001_pos.ksh b/tests/zfs-tests/tests/functional/threadsappend/threadsappend_001_pos.ksh
new file mode 100755 (executable)
index 0000000..3c445a5
--- /dev/null
@@ -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.
+#
+
+#
+# Copyright (c) 2013 by Delphix. All rights reserved.
+#
+
+. $STF_SUITE/include/libtest.shlib
+
+#
+# DESCRIPTION:
+#
+# Ensure multiple threads performing write appends to the same ZFS
+# file succeed.
+#
+# STRATEGY:
+#      1) Verify this is a multi-processor system
+#      2) Create multiple threads with each appending to a file
+#       3) Verify that the resulting file is the expected size
+#
+
+verify_runnable "both"
+
+log_assert "Ensure multiple threads performing write appends to the same" \
+       "ZFS file succeed"
+
+#
+# $FILE_SIZE is hardcoded into threadsappend.c and is the expected
+# size of the file after all the threads have appended to it
+#
+typeset -i FILE_SIZE=1310720
+TESTFILE='testfile-threadsappend'
+
+#
+# This test should be run on a multi-processor system because otherwise the FS
+# will not be concurrently used by the threads
+#
+if ! is_mp; then
+       log_fail "This test should be executed on a multi-processor system."
+fi
+
+#
+# zfs_threadsappend tries to append to $TESTFILE using threads
+# so that the resulting file is $FILE_SIZE bytes in size
+#
+log_must $THREADSAPPEND ${TESTDIR}/${TESTFILE}
+
+#
+# Check the size of the resulting file
+#
+SIZE=`$LS -l ${TESTDIR}/${TESTFILE} | $AWK '{print $5}'`
+if [[ $SIZE -ne $FILE_SIZE ]]; then
+       log_fail "'The length of ${TESTDIR}/${TESTFILE}' doesnt equal 1310720."
+fi
+
+log_pass "Multiple thread appends succeeded. File size as expected"
diff --git a/tests/zfs-tests/tests/functional/truncate/Makefile.am b/tests/zfs-tests/tests/functional/truncate/Makefile.am
new file mode 100644 (file)
index 0000000..16cadf2
--- /dev/null
@@ -0,0 +1,7 @@
+pkgdatadir = $(datadir)/@PACKAGE@/zfs-tests/tests/functional/truncate
+dist_pkgdata_SCRIPTS = \
+       setup.ksh \
+       cleanup.ksh \
+       truncate.cfg \
+       truncate_001_pos.ksh \
+       truncate_002_pos.ksh
diff --git a/tests/zfs-tests/tests/functional/truncate/cleanup.ksh b/tests/zfs-tests/tests/functional/truncate/cleanup.ksh
new file mode 100755 (executable)
index 0000000..9756c0f
--- /dev/null
@@ -0,0 +1,30 @@
+#!/bin/ksh -p
+#
+# CDDL HEADER START
+#
+# The contents of this file are subject to the terms of the
+# Common Development and Distribution License (the "License").
+# You may not use this file except in compliance with the License.
+#
+# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
+# or http://www.opensolaris.org/os/licensing.
+# See the License for the specific language governing permissions
+# and limitations under the License.
+#
+# When distributing Covered Code, include this CDDL HEADER in each
+# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
+# If applicable, add the following below this CDDL HEADER, with the
+# fields enclosed by brackets "[]" replaced with your own identifying
+# information: 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
diff --git a/tests/zfs-tests/tests/functional/truncate/setup.ksh b/tests/zfs-tests/tests/functional/truncate/setup.ksh
new file mode 100755 (executable)
index 0000000..863492d
--- /dev/null
@@ -0,0 +1,32 @@
+#!/bin/ksh -p
+#
+# CDDL HEADER START
+#
+# The contents of this file are subject to the terms of the
+# Common Development and Distribution License (the "License").
+# You may not use this file except in compliance with the License.
+#
+# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
+# or http://www.opensolaris.org/os/licensing.
+# See the License for the specific language governing permissions
+# and limitations under the License.
+#
+# When distributing Covered Code, include this CDDL HEADER in each
+# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
+# If applicable, add the following below this CDDL HEADER, with the
+# fields enclosed by brackets "[]" replaced with your own identifying
+# information: 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
diff --git a/tests/zfs-tests/tests/functional/truncate/truncate.cfg b/tests/zfs-tests/tests/functional/truncate/truncate.cfg
new file mode 100644 (file)
index 0000000..703ff50
--- /dev/null
@@ -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
diff --git a/tests/zfs-tests/tests/functional/truncate/truncate_001_pos.ksh b/tests/zfs-tests/tests/functional/truncate/truncate_001_pos.ksh
new file mode 100755 (executable)
index 0000000..a6b379a
--- /dev/null
@@ -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.
+#
+
+. $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."
diff --git a/tests/zfs-tests/tests/functional/truncate/truncate_002_pos.ksh b/tests/zfs-tests/tests/functional/truncate/truncate_002_pos.ksh
new file mode 100755 (executable)
index 0000000..fe9584a
--- /dev/null
@@ -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/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."
diff --git a/tests/zfs-tests/tests/functional/userquota/Makefile.am b/tests/zfs-tests/tests/functional/userquota/Makefile.am
new file mode 100644 (file)
index 0000000..b726599
--- /dev/null
@@ -0,0 +1,22 @@
+pkgdatadir = $(datadir)/@PACKAGE@/zfs-tests/tests/functional/userquota
+dist_pkgdata_SCRIPTS = \
+       userquota.cfg \
+       userquota_common.kshlib \
+       setup.ksh \
+       cleanup.ksh \
+       groupspace_001_pos.ksh \
+       groupspace_002_pos.ksh \
+       userquota_001_pos.ksh \
+       userquota_002_pos.ksh \
+       userquota_003_pos.ksh \
+       userquota_004_pos.ksh \
+       userquota_005_neg.ksh \
+       userquota_006_pos.ksh \
+       userquota_007_pos.ksh \
+       userquota_008_pos.ksh \
+       userquota_009_pos.ksh \
+       userquota_010_pos.ksh \
+       userquota_011_pos.ksh \
+       userquota_012_neg.ksh \
+       userspace_001_pos.ksh \
+       userspace_002_pos.ksh
diff --git a/tests/zfs-tests/tests/functional/userquota/cleanup.ksh b/tests/zfs-tests/tests/functional/userquota/cleanup.ksh
new file mode 100755 (executable)
index 0000000..5931acb
--- /dev/null
@@ -0,0 +1,41 @@
+#!/bin/ksh -p
+#
+# CDDL HEADER START
+#
+# The contents of this file are subject to the terms of the
+# Common Development and Distribution License (the "License").
+# You may not use this file except in compliance with the License.
+#
+# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
+# or http://www.opensolaris.org/os/licensing.
+# See the License for the specific language governing permissions
+# and limitations under the License.
+#
+# When distributing Covered Code, include this CDDL HEADER in each
+# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
+# If applicable, add the following below this CDDL HEADER, with the
+# fields enclosed by brackets "[]" replaced with your own identifying
+# information: Portions Copyright [yyyy] [name of copyright owner]
+#
+# CDDL HEADER END
+#
+
+#
+# Copyright 2009 Sun Microsystems, Inc.  All rights reserved.
+# Use is subject to license terms.
+#
+
+#
+# Copyright (c) 2013 by Delphix. All rights reserved.
+#
+
+. $STF_SUITE/include/libtest.shlib
+. $STF_SUITE/tests/functional/userquota/userquota_common.kshlib
+
+log_must cleanup_quota
+log_must clean_user_group
+
+typeset mntp=$(get_prop mountpoint $QFS)
+log_must $CHMOD 0755 $mntp
+
+default_cleanup
diff --git a/tests/zfs-tests/tests/functional/userquota/groupspace_001_pos.ksh b/tests/zfs-tests/tests/functional/userquota/groupspace_001_pos.ksh
new file mode 100755 (executable)
index 0000000..800285e
--- /dev/null
@@ -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 2009 Sun Microsystems, Inc.  All rights reserved.
+# Use is subject to license terms.
+#
+
+#
+# Copyright (c) 2013 by Delphix. All rights reserved.
+#
+
+. $STF_SUITE/include/libtest.shlib
+. $STF_SUITE/tests/functional/userquota/userquota_common.kshlib
+
+#
+# DESCRIPTION:
+#       Check the zfs groupspace with all parameters
+#
+#
+# STRATEGY:
+#       1. set zfs groupquota to a fs
+#       2. write some data to the fs with specified user and group
+#      3. use zfs groupspace with all possible parameters to check the result
+#
+
+function cleanup
+{
+       if datasetexists $snap_fs; then
+               log_must $ZFS destroy $snap_fs
+       fi
+
+       log_must cleanup_quota
+}
+
+log_onexit cleanup
+
+log_assert "Check the zfs groupspace with all possible parameters"
+
+set -A params -- "-n" "-H" "-p" "-o type,name,used,quota" \
+    "-o name,used,quota" "-o used,quota" "-o used" "-o quota" "-s type" \
+    "-s name" "-s used" "-s quota" "-S type" "-S name" "-S used" "-S quota" \
+    "-t posixuser" "-t posixgroup" "-t all" "-i" "-t smbuser" "-t smbgroup"
+
+typeset snap_fs=$QFS@snap
+
+log_must $ZFS set groupquota@$QGROUP=500m $QFS
+mkmount_writable $QFS
+log_must user_run $QUSER1 $MKFILE 50m $QFILE
+
+$SYNC
+
+log_must $ZFS snapshot $snap_fs
+
+for param in "${params[@]}"; do
+       log_must eval "$ZFS groupspace $param $QFS >/dev/null 2>&1"
+       log_must eval "$ZFS groupspace $param $snap_fs >/dev/null 2>&1"
+done
+
+log_pass "Check the zfs groupspace with all possible parameters"
diff --git a/tests/zfs-tests/tests/functional/userquota/groupspace_002_pos.ksh b/tests/zfs-tests/tests/functional/userquota/groupspace_002_pos.ksh
new file mode 100755 (executable)
index 0000000..92d8dd9
--- /dev/null
@@ -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 2009 Sun Microsystems, Inc.  All rights reserved.
+# Use is subject to license terms.
+#
+
+#
+# Copyright (c) 2013 by Delphix. All rights reserved.
+#
+
+. $STF_SUITE/include/libtest.shlib
+. $STF_SUITE/tests/functional/userquota/userquota_common.kshlib
+
+#
+# DESCRIPTION:
+#       Check the user used and groupspace size in zfs groupspace
+#
+#
+# STRATEGY:
+#       1. set zfs groupquota to a fs
+#       2. write some data to the fs with specified user and size
+#      3. use zfs groupspace to check the used size and quota size
+#
+
+function cleanup
+{
+       if datasetexists $snapfs; then
+               log_must $ZFS destroy $snapfs
+       fi
+       log_must cleanup_quota
+}
+
+log_onexit cleanup
+
+log_assert "Check the zfs groupspace used and quota"
+
+log_must $ZFS set groupquota@$QGROUP=500m $QFS
+mkmount_writable $QFS
+log_must user_run $QUSER1 $MKFILE 100m $QFILE
+
+$SYNC
+
+typeset snapfs=$QFS@snap
+
+log_must $ZFS snapshot $snapfs
+
+log_must eval "$ZFS groupspace $QFS >/dev/null 2>&1"
+log_must eval "$ZFS groupspace $snapfs >/dev/null 2>&1"
+
+for fs in "$QFS" "$snapfs"; do
+       log_note "check the quota size in zfs groupspace $fs"
+       log_must eval "$ZFS groupspace $fs | $GREP $QGROUP | $GREP 500M"
+
+       log_note "check the user used size in zfs groupspace $fs"
+       log_must eval "$ZFS groupspace $fs | $GREP $QGROUP | $GREP 100M"
+done
+
+log_pass "Check the zfs groupspace used and quota pass as expect"
diff --git a/tests/zfs-tests/tests/functional/userquota/setup.ksh b/tests/zfs-tests/tests/functional/userquota/setup.ksh
new file mode 100755 (executable)
index 0000000..1c27075
--- /dev/null
@@ -0,0 +1,44 @@
+#!/bin/ksh -p
+#
+# CDDL HEADER START
+#
+# The contents of this file are subject to the terms of the
+# Common Development and Distribution License (the "License").
+# You may not use this file except in compliance with the License.
+#
+# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
+# or http://www.opensolaris.org/os/licensing.
+# See the License for the specific language governing permissions
+# and limitations under the License.
+#
+# When distributing Covered Code, include this CDDL HEADER in each
+# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
+# If applicable, add the following below this CDDL HEADER, with the
+# fields enclosed by brackets "[]" replaced with your own identifying
+# information: Portions Copyright [yyyy] [name of copyright owner]
+#
+# CDDL HEADER END
+#
+
+#
+# Copyright 2009 Sun Microsystems, Inc.  All rights reserved.
+# Use is subject to license terms.
+#
+
+#
+# Copyright (c) 2013 by Delphix. All rights reserved.
+#
+
+. $STF_SUITE/include/libtest.shlib
+. $STF_SUITE/tests/functional/userquota/userquota_common.kshlib
+
+verify_runnable "both"
+
+log_must clean_user_group
+
+log_must add_group $QGROUP
+log_must add_user $QGROUP $QUSER1
+log_must add_user $QGROUP $QUSER2
+
+DISK=${DISKS%% *}
+default_setup $DISK
diff --git a/tests/zfs-tests/tests/functional/userquota/userquota.cfg b/tests/zfs-tests/tests/functional/userquota/userquota.cfg
new file mode 100644 (file)
index 0000000..893428d
--- /dev/null
@@ -0,0 +1,46 @@
+#
+# CDDL HEADER START
+#
+# The contents of this file are subject to the terms of the
+# Common Development and Distribution License (the "License").
+# You may not use this file except in compliance with the License.
+#
+# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
+# or http://www.opensolaris.org/os/licensing.
+# See the License for the specific language governing permissions
+# and limitations under the License.
+#
+# When distributing Covered Code, include this CDDL HEADER in each
+# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
+# If applicable, add the following below this CDDL HEADER, with the
+# fields enclosed by brackets "[]" replaced with your own identifying
+# information: Portions Copyright [yyyy] [name of copyright owner]
+#
+# CDDL HEADER END
+#
+
+#
+# Copyright 2009 Sun Microsystems, Inc.  All rights reserved.
+# Use is subject to license terms.
+#
+
+#
+# Copyright (c) 2013 by Delphix. All rights reserved.
+#
+
+export QUSER1=quser1
+export QUSER2=quser2
+
+export QGROUP=qgroup
+export QGROUP1=qgroup1
+export QGROUP1=qgroup2
+
+export UQUOTA_SIZE=1000000
+export GQUOTA_SIZE=4000000
+
+export QFS=$TESTPOOL/$TESTFS
+export QFILE=$TESTDIR/qf
+export OFILE=$TESTDIR/of
+
+export SNAP_QUOTA=100m
+export TEST_QUOTA=88888
diff --git a/tests/zfs-tests/tests/functional/userquota/userquota_001_pos.ksh b/tests/zfs-tests/tests/functional/userquota/userquota_001_pos.ksh
new file mode 100755 (executable)
index 0000000..b134a76
--- /dev/null
@@ -0,0 +1,74 @@
+#!/bin/ksh -p
+#
+# CDDL HEADER START
+#
+# The contents of this file are subject to the terms of the
+# Common Development and Distribution License (the "License").
+# You may not use this file except in compliance with the License.
+#
+# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
+# or http://www.opensolaris.org/os/licensing.
+# See the License for the specific language governing permissions
+# and limitations under the License.
+#
+# When distributing Covered Code, include this CDDL HEADER in each
+# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
+# If applicable, add the following below this CDDL HEADER, with the
+# fields enclosed by brackets "[]" replaced with your own identifying
+# information: Portions Copyright [yyyy] [name of copyright owner]
+#
+# CDDL HEADER END
+#
+
+#
+# Copyright 2009 Sun Microsystems, Inc.  All rights reserved.
+# Use is subject to license terms.
+#
+
+#
+# Copyright (c) 2013 by Delphix. All rights reserved.
+#
+. $STF_SUITE/include/libtest.shlib
+. $STF_SUITE/tests/functional/userquota/userquota_common.kshlib
+
+#
+#
+# DESCRIPTION:
+#       Check the basic function of the userquota and groupquota
+#
+#
+# STRATEGY:
+#       1. Set userquota and overwrite the quota size
+#       2. The write operation should fail with Disc quota exceeded
+#       3. Set groupquota and overwrite the quota size
+#       4. The write operation should fail with Disc quota exceeded
+#
+#
+
+function cleanup
+{
+       cleanup_quota
+}
+
+log_onexit cleanup
+
+log_assert "If write operation overwrite {user|group}quota size, it will fail"
+
+mkmount_writable $QFS
+log_note "Check the userquota@$QUSER1"
+log_must $ZFS set userquota@$QUSER1=$UQUOTA_SIZE $QFS
+log_must user_run $QUSER1 $MKFILE $UQUOTA_SIZE $QFILE
+$SYNC
+log_mustnot user_run $QUSER1 $MKFILE 1 $OFILE
+cleanup_quota
+
+log_note "Check the groupquota@$QGROUP"
+log_must $ZFS set groupquota@$QGROUP=$GQUOTA_SIZE $QFS
+mkmount_writable $QFS
+log_must user_run $QUSER1 $MKFILE $GQUOTA_SIZE $QFILE
+$SYNC
+log_mustnot user_run $QUSER1 $MKFILE 1 $OFILE
+
+cleanup_quota
+
+log_pass "Write operation overwrite {user|group}quota size, it as expect"
diff --git a/tests/zfs-tests/tests/functional/userquota/userquota_002_pos.ksh b/tests/zfs-tests/tests/functional/userquota/userquota_002_pos.ksh
new file mode 100755 (executable)
index 0000000..aa52c1d
--- /dev/null
@@ -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) 2013 by Delphix. All rights reserved.
+#
+
+. $STF_SUITE/include/libtest.shlib
+. $STF_SUITE/tests/functional/userquota/userquota_common.kshlib
+
+#
+# DESCRIPTION:
+#       the userquota and groupquota can be set during zpool or zfs creation"
+#
+#
+# STRATEGY:
+#       1. Set userquota and groupquota via "zpool -O or zfs create -o"
+#
+
+verify_runnable "global"
+
+function cleanup
+{
+       if poolexists $TESTPOOL1; then
+               log_must $ZPOOL destroy $TESTPOOL1
+       fi
+
+       if [[ -f $pool_vdev ]]; then
+               $RM -f $pool_vdev
+       fi
+}
+
+log_onexit cleanup
+
+log_assert \
+       "the userquota and groupquota can be set during zpool,zfs creation"
+
+typeset pool_vdev=/var/tmp/pool_dev.$$
+
+log_must $MKFILE 500m $pool_vdev
+
+if poolexists $TESTPOOL1; then
+       $ZPOOL destroy $TESTPOOL1
+fi
+
+log_must $ZPOOL create -O userquota@$QUSER1=$UQUOTA_SIZE \
+       -O groupquota@$QGROUP=$GQUOTA_SIZE $TESTPOOL1 $pool_vdev
+
+log_must eval "$ZFS list -r -o userquota@$QUSER1,groupquota@$QGROUP \
+       $TESTPOOL1 > /dev/null 2>&1"
+
+log_must check_quota "userquota@$QUSER1" $TESTPOOL1 "$UQUOTA_SIZE"
+log_must check_quota "groupquota@$QGROUP" $TESTPOOL1 "$GQUOTA_SIZE"
+
+log_must $ZFS create -o userquota@$QUSER1=$UQUOTA_SIZE \
+       -o groupquota@$QGROUP=$GQUOTA_SIZE $TESTPOOL1/fs
+
+log_must eval "$ZFS list -r -o userquota@$QUSER1,groupquota@$QGROUP \
+       $TESTPOOL1 > /dev/null 2>&1"
+
+log_must check_quota "userquota@$QUSER1" $TESTPOOL1/fs "$UQUOTA_SIZE"
+log_must check_quota "groupquota@$QGROUP" $TESTPOOL1/fs "$GQUOTA_SIZE"
+
+log_pass \
+       "the userquota and groupquota can be set during zpool,zfs creation"
diff --git a/tests/zfs-tests/tests/functional/userquota/userquota_003_pos.ksh b/tests/zfs-tests/tests/functional/userquota/userquota_003_pos.ksh
new file mode 100755 (executable)
index 0000000..40903db
--- /dev/null
@@ -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.
+#
+
+#
+# Copyright (c) 2013 by Delphix. All rights reserved.
+#
+
+. $STF_SUITE/include/libtest.shlib
+. $STF_SUITE/tests/functional/userquota/userquota_common.kshlib
+
+#
+# DESCRIPTION:
+#       Check the basic function of set/get userquota and groupquota on fs
+#
+#
+# STRATEGY:
+#       1. Set userquota on fs and check the zfs get
+#       2. Set groupquota on fs and check the zfs get
+#
+
+function cleanup
+{
+       cleanup_quota
+}
+
+log_onexit cleanup
+
+log_assert "Check the basic function of set/get userquota and groupquota on fs"
+
+log_note "Check the set|get userquota@$QUSER1 and groupquota@QGROUP"
+log_must $ZFS set userquota@$QUSER1=$UQUOTA_SIZE $QFS
+log_must check_quota "userquota@$QUSER1" $QFS "$UQUOTA_SIZE"
+
+log_must $ZFS set groupquota@$QGROUP=$GQUOTA_SIZE $QFS
+log_must check_quota "groupquota@$QGROUP" $QFS "$GQUOTA_SIZE"
+
+log_pass "Check the basic function of set/get userquota on fs passed as expect"
diff --git a/tests/zfs-tests/tests/functional/userquota/userquota_004_pos.ksh b/tests/zfs-tests/tests/functional/userquota/userquota_004_pos.ksh
new file mode 100755 (executable)
index 0000000..6bdcf1c
--- /dev/null
@@ -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.
+#
+
+#
+# Copyright (c) 2013 by Delphix. All rights reserved.
+#
+
+. $STF_SUITE/include/libtest.shlib
+. $STF_SUITE/tests/functional/userquota/userquota_common.kshlib
+
+#
+# DESCRIPTION:
+#       Check the basic function user|group used
+#
+#
+# STRATEGY:
+#       1. Write some data to fs by normal user and check the user|group used
+#
+
+function cleanup
+{
+       cleanup_quota
+}
+
+log_onexit cleanup
+
+log_assert "Check the basic function of {user|group} used"
+
+typeset user_used=$(get_value "userused@$QUSER1" $QFS)
+typeset group_used=$(get_value "groupused@$QGROUP" $QFS)
+
+if [[ $user_used != 0 ]]; then
+       log_fail "FAIL: userused is $user_used, should be 0"
+fi
+if [[ $group_used != 0 ]]; then
+       log_fail "FAIL: groupused is $group_used, should be 0"
+fi
+
+mkmount_writable $QFS
+log_must user_run $QUSER1 $MKFILE 100m $QFILE
+$SYNC
+
+user_used=$(get_value "userused@$QUSER1" $QFS)
+group_used=$(get_value "groupused@$QGROUP" $QFS)
+
+if [[ $user_used != "100M" ]]; then
+       log_note "user $QUSER1 used is $user_used"
+       log_fail "userused for user $QUSER1 expected to be 50.0M, not $user_used"
+fi
+
+if [[ $user_used != $group_used ]]; then
+       log_note "user $QUSER1 used is $user_used"
+       log_note "group $QGROUP used is $group_used"
+       log_fail "FAIL: userused should equal to groupused"
+fi
+
+log_pass "Check the basic function of {user|group}used pass as expect"
diff --git a/tests/zfs-tests/tests/functional/userquota/userquota_005_neg.ksh b/tests/zfs-tests/tests/functional/userquota/userquota_005_neg.ksh
new file mode 100755 (executable)
index 0000000..1b405fb
--- /dev/null
@@ -0,0 +1,94 @@
+#!/bin/ksh -p
+#
+# CDDL HEADER START
+#
+# The contents of this file are subject to the terms of the
+# Common Development and Distribution License (the "License").
+# You may not use this file except in compliance with the License.
+#
+# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
+# or http://www.opensolaris.org/os/licensing.
+# See the License for the specific language governing permissions
+# and limitations under the License.
+#
+# When distributing Covered Code, include this CDDL HEADER in each
+# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
+# If applicable, add the following below this CDDL HEADER, with the
+# fields enclosed by brackets "[]" replaced with your own identifying
+# information: Portions Copyright [yyyy] [name of copyright owner]
+#
+# CDDL HEADER END
+#
+
+#
+# Copyright 2009 Sun Microsystems, Inc.  All rights reserved.
+# Use is subject to license terms.
+#
+
+#
+# Copyright (c) 2013 by Delphix. All rights reserved.
+#
+
+. $STF_SUITE/include/libtest.shlib
+. $STF_SUITE/tests/functional/userquota/userquota_common.kshlib
+
+#
+# DESCRIPTION:
+#       Check the invalid parameter of zfs set user|group quota
+#
+#
+# STRATEGY:
+#       1. check the invalid zfs set user|group quota to fs
+#       1. check the valid zfs set user|group quota to snapshots
+#
+
+function cleanup
+{
+       if datasetexists $snap_fs; then
+               log_must $ZFS destroy $snap_fs
+       fi
+
+       log_must cleanup_quota
+}
+
+log_onexit cleanup
+
+log_assert "Check the invalid parameter of zfs set user|group quota"
+typeset snap_fs=$QFS@snap
+
+log_must $ZFS snapshot $snap_fs
+
+set -A no_users "mms1234" "ss@#" "root-122"
+for user in "${no_users[@]}"; do
+       log_mustnot $ID $user
+       log_mustnot $ZFS set userquota@$user=100m $QFS
+done
+
+log_note "can set all numberic id even that id is not existed"
+log_must $ZFS set userquota@12345678=100m $QFS
+log_mustnot $ZFS set userquota@12345678=100m $snap_fs
+
+set -A sizes "100mfsd" "m0.12m" "GGM" "-1234-m" "123m-m"
+
+for size in "${sizes[@]}"; do
+       log_note "can not set user quota with invalid size parameter"
+       log_mustnot $ZFS set userquota@root=$size $QFS
+done
+
+log_note "can not set user quota to snapshot $snap_fs"
+log_mustnot $ZFS set userquota@root=100m $snap_fs
+
+
+set -A no_groups "aidsf@dfsd@" "123223-dsfds#sdfsd" "mss_#ss" "@@@@"
+for group in "${no_groups[@]}"; do
+       log_mustnot eval "$GREP $group /etc/group"
+       log_mustnot $ZFS set groupquota@$group=100m $QFS
+done
+
+log_note "can not set group quota with invalid size parameter"
+log_mustnot $ZFS set groupquota@root=100msfsd $QFS
+
+log_note "can not set group quota to snapshot $snap_fs"
+log_mustnot $ZFS set groupquota@root=100m $snap_fs
+
+log_pass "Check the invalid parameter of zfs set user|group quota pas as expect"
diff --git a/tests/zfs-tests/tests/functional/userquota/userquota_006_pos.ksh b/tests/zfs-tests/tests/functional/userquota/userquota_006_pos.ksh
new file mode 100755 (executable)
index 0000000..92b4f83
--- /dev/null
@@ -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) 2013 by Delphix. All rights reserved.
+#
+
+. $STF_SUITE/include/libtest.shlib
+. $STF_SUITE/tests/functional/userquota/userquota_common.kshlib
+
+#
+# DESCRIPTION:
+#       Check the invalid parameter of zfs get user|group quota
+#
+#
+# STRATEGY:
+#       1. check the invalid zfs get user|group quota to fs
+#       2. check the valid zfs get user|group quota to snapshots
+#
+
+function cleanup
+{
+       if datasetexists $snap_fs; then
+               log_must $ZFS destroy $snap_fs
+       fi
+
+       log_must cleanup_quota
+}
+
+log_onexit cleanup
+
+log_assert "Check the invalid parameter of zfs get user|group quota"
+typeset snap_fs=$QFS@snap
+
+log_must $ZFS snapshot $snap_fs
+
+set -A no_users "mms1234" "ss@#" "root-122" "1234"
+for user in "${no_users[@]}"; do
+       log_mustnot eval "$ID $user >/dev/null 2>&1"
+       log_must eval "$ZFS get userquota@$user $QFS >/dev/null 2>&1"
+       log_must eval "$ZFS get userquota@$user $snap_fs >/dev/null 2>&1"
+done
+
+set -A no_groups "aidsf@dfsd@" "123223-dsfds#sdfsd" "mss_#ss" "1234"
+for group in "${no_groups[@]}"; do
+       log_mustnot eval "$GROUPDEL $group > /dev/null 2>&1"
+       log_must eval "$ZFS get groupquota@$group $QFS >/dev/null 2>&1"
+       log_must eval "$ZFS get groupquota@$group $snap_fs >/dev/null 2>&1"
+done
+
+log_pass "Check the invalid parameter of zfs get user|group quota pass as expect"
diff --git a/tests/zfs-tests/tests/functional/userquota/userquota_007_pos.ksh b/tests/zfs-tests/tests/functional/userquota/userquota_007_pos.ksh
new file mode 100755 (executable)
index 0000000..ec9158d
--- /dev/null
@@ -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) 2013 by Delphix. All rights reserved.
+#
+
+. $STF_SUITE/include/libtest.shlib
+. $STF_SUITE/tests/functional/userquota/userquota_common.kshlib
+
+#
+# DESCRIPTION:
+#
+#      userquota/groupquota can be set beyond the fs quota
+#      userquota/groupquota can be set at a smaller size than its current usage.
+#
+# STRATEGY:
+#       1. set quota to a fs and set a larger size of userquota and groupquota
+#       2. write some data to the fs and set a smaller userquota and groupquota
+#
+
+function cleanup
+{
+       log_must cleanup_quota
+       log_must $ZFS set quota=none $QFS
+}
+
+log_onexit cleanup
+
+log_assert "Check set user|group quota to larger than the quota size of a fs"
+
+log_must $ZFS set quota=200m $QFS
+log_must $ZFS set userquota@$QUSER1=500m $QFS
+log_must $ZFS set groupquota@$QGROUP=600m $QFS
+
+log_must $ZFS get userquota@$QUSER1 $QFS
+log_must $ZFS get groupquota@$QGROUP $QFS
+
+log_note "write some data to the $QFS"
+mkmount_writable $QFS
+log_must user_run $QUSER1 $MKFILE 100m $QFILE
+$SYNC
+
+log_note "set user|group quota at a smaller size than it current usage"
+log_must $ZFS set userquota@$QUSER1=90m $QFS
+log_must $ZFS set groupquota@$QGROUP=90m $QFS
+
+log_must $ZFS get userquota@$QUSER1 $QFS
+log_must $ZFS get groupquota@$QGROUP $QFS
+
+log_pass "set user|group quota to larger than quota size of a fs pass as expect"
diff --git a/tests/zfs-tests/tests/functional/userquota/userquota_008_pos.ksh b/tests/zfs-tests/tests/functional/userquota/userquota_008_pos.ksh
new file mode 100755 (executable)
index 0000000..23ea117
--- /dev/null
@@ -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 2009 Sun Microsystems, Inc.  All rights reserved.
+# Use is subject to license terms.
+#
+
+#
+# Copyright (c) 2013 by Delphix. All rights reserved.
+#
+
+. $STF_SUITE/include/libtest.shlib
+. $STF_SUITE/tests/functional/userquota/userquota_common.kshlib
+
+#
+# DESCRIPTION:
+#
+#      zfs get all <fs> does not print out userquota/groupquota
+#
+# STRATEGY:
+#       1. set userquota and groupquota to a fs
+#       2. check zfs get all fs
+#
+
+function cleanup
+{
+       log_must cleanup_quota
+}
+
+log_onexit cleanup
+
+log_assert "Check zfs get all will not print out user|group quota"
+
+log_must $ZFS set userquota@$QUSER1=50m $QFS
+log_must $ZFS set groupquota@$QGROUP=100m $QFS
+
+log_mustnot $ZFS get all $QFS | $GREP userquota
+log_mustnot $ZFS get all $QFS | $GREP groupquota
+
+log_pass "zfs get all will not print out user|group quota"
diff --git a/tests/zfs-tests/tests/functional/userquota/userquota_009_pos.ksh b/tests/zfs-tests/tests/functional/userquota/userquota_009_pos.ksh
new file mode 100755 (executable)
index 0000000..18c0de8
--- /dev/null
@@ -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.
+#
+
+#
+# Copyright (c) 2013 by Delphix. All rights reserved.
+#
+
+. $STF_SUITE/include/libtest.shlib
+. $STF_SUITE/tests/functional/userquota/userquota_common.kshlib
+
+#
+# DESCRIPTION:
+#       Check user|group quota to snapshot that:
+#      1) can not set user|group quota to snapshot directly
+#      2) snapshot can inherit the parent fs's user|groupquota
+#      3) the user|group quota will not change even the parent fs's quota changed.
+#
+#
+# STRATEGY:
+#       1. create a snapshot of a fs
+#       2. set the user|group quota to snapshot and expect fail
+#      3. set user|group quota to fs and check the snapshot
+#      4. re-set user|group quota to fs and check the snapshot's value
+#
+
+function cleanup
+{
+       if datasetexists $snap_fs; then
+               log_must $ZFS destroy $snap_fs
+       fi
+
+       log_must cleanup_quota
+}
+
+log_onexit cleanup
+
+log_assert "Check the snapshot's user|group quota"
+typeset snap_fs=$QFS@snap
+
+
+log_must $ZFS set userquota@$QUSER1=$UQUOTA_SIZE $QFS
+log_must check_quota "userquota@$QUSER1" $QFS "$UQUOTA_SIZE"
+
+log_must $ZFS set groupquota@$QGROUP=$GQUOTA_SIZE $QFS
+log_must check_quota "groupquota@$QGROUP" $QFS "$GQUOTA_SIZE"
+
+log_must $ZFS snapshot $snap_fs
+
+log_note "check the snapshot $snap_fs user|group quota"
+log_must check_quota "userquota@$QUSER1" $snap_fs "$UQUOTA_SIZE"
+log_must check_quota "groupquota@$QGROUP" $snap_fs "$GQUOTA_SIZE"
+
+log_note  "set userquota and groupquota to $snap_fs which will fail"
+log_mustnot $ZFS set userquota@$QUSER1=$SNAP_QUOTA $snap_fs
+log_mustnot $ZFS set groupquota@$QGROUP=$SNAP_QUOTA $snap_fs
+
+log_note "change the parent's userquota and groupquota"
+log_must $ZFS set userquota@$QUSER1=$TEST_QUOTA $QFS
+log_must $ZFS set groupquota@$QGROUP=$TEST_QUOTA $QFS
+
+log_must check_quota "userquota@$QUSER1" $QFS $TEST_QUOTA
+log_must check_quota "groupquota@$QGROUP" $QFS $TEST_QUOTA
+
+log_note "check the snapshot $snap_fs userquota and groupquota"
+log_must check_quota "userquota@$QUSER1" $snap_fs "$UQUOTA_SIZE"
+log_must check_quota "groupquota@$QGROUP" $snap_fs "$GQUOTA_SIZE"
+
+log_pass "Check the snapshot's user|group quota pass as expect"
diff --git a/tests/zfs-tests/tests/functional/userquota/userquota_010_pos.ksh b/tests/zfs-tests/tests/functional/userquota/userquota_010_pos.ksh
new file mode 100755 (executable)
index 0000000..b926058
--- /dev/null
@@ -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) 2013 by Delphix. All rights reserved.
+#
+
+. $STF_SUITE/include/libtest.shlib
+. $STF_SUITE/tests/functional/userquota/userquota_common.kshlib
+
+#
+# DESCRIPTION:
+#       Check userquota and groupquota be overwrited at same time
+#
+#
+# STRATEGY:
+#       1. Set userquota and groupquota to a fs
+#       2. write to exceed the userquota size to check the result
+#       3. write to exceed the groupquota size to check the result
+#
+
+function cleanup
+{
+       cleanup_quota
+}
+
+log_onexit cleanup
+
+log_assert "overwrite any of the {user|group}quota size, it will fail"
+
+log_note "overwrite to $QFS to make it exceed userquota"
+log_must $ZFS set userquota@$QUSER1=$UQUOTA_SIZE $QFS
+log_must $ZFS set groupquota@$QGROUP=$GQUOTA_SIZE $QFS
+
+mkmount_writable $QFS
+log_must user_run $QUSER1 $MKFILE $UQUOTA_SIZE $QFILE
+$SYNC
+
+log_must eval "$ZFS get -p userused@$QUSER1 $QFS >/dev/null 2>&1"
+log_must eval "$ZFS get -p groupused@$GROUPUSED $QFS >/dev/null 2>&1"
+
+log_mustnot user_run $QUSER1 $MKFILE 1 $OFILE
+
+log_must $RM -f $QFILE
+
+log_note "overwrite to $QFS to make it exceed userquota"
+log_mustnot user_run $QUSER1 $MKFILE $GQUOTA_SIZE $QFILE
+
+log_must eval "$ZFS get -p userused@$QUSER1 $QFS >/dev/null 2>&1"
+log_must eval "$ZFS get -p groupused@$GROUPUSED $QFS >/dev/null 2>&1"
+
+log_pass "overwrite any of the {user|group}quota size, it fail as expect"
diff --git a/tests/zfs-tests/tests/functional/userquota/userquota_011_pos.ksh b/tests/zfs-tests/tests/functional/userquota/userquota_011_pos.ksh
new file mode 100755 (executable)
index 0000000..7e04377
--- /dev/null
@@ -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 2009 Sun Microsystems, Inc.  All rights reserved.
+# Use is subject to license terms.
+#
+
+#
+# Copyright (c) 2013 by Delphix. All rights reserved.
+#
+
+. $STF_SUITE/include/libtest.shlib
+. $STF_SUITE/tests/functional/userquota/userquota_common.kshlib
+
+#
+# DESCRIPTION:
+#       the userquota and groupquota will not change during zfs actions, such as
+#      snapshot,clone,rename,upgrade,send,receive.
+#
+#
+# STRATEGY:
+#       1. Create a pool, and create fs with preset user,group quota
+#       2. Check set user|group quota via zfs snapshot|clone|list -o
+#       3. Check the user|group quota can not change during zfs rename|upgrade|promote
+#       4. Check the user|group quota can not change during zfs clone
+#       5. Check the user|group quota can not change during zfs send/receive
+#
+
+function cleanup
+{
+       for ds in $TESTPOOL/fs $TESTPOOL/fs-rename $TESTPOOL/fs-clone; do
+               if datasetexists $ds; then
+                       log_must $ZFS destroy -rRf $ds
+               fi
+       done
+}
+
+log_onexit cleanup
+
+log_assert \
+       "the userquota and groupquota can't change during zfs actions"
+
+cleanup
+
+log_must $ZFS create -o userquota@$QUSER1=$UQUOTA_SIZE \
+       -o groupquota@$QGROUP=$GQUOTA_SIZE $TESTPOOL/fs
+
+log_must $ZFS snapshot $TESTPOOL/fs@snap
+log_must eval "$ZFS list -r -o userquota@$QUSER1,groupquota@$QGROUP \
+       $TESTPOOL >/dev/null 2>&1"
+
+log_must check_quota "userquota@$QUSER1" $TESTPOOL/fs@snap "$UQUOTA_SIZE"
+log_must check_quota "groupquota@$QGROUP" $TESTPOOL/fs@snap "$GQUOTA_SIZE"
+
+
+log_note "clone fs gets its parent's userquota/groupquota initially"
+log_must $ZFS clone  -o userquota@$QUSER1=$UQUOTA_SIZE \
+               -o groupquota@$QGROUP=$GQUOTA_SIZE \
+               $TESTPOOL/fs@snap $TESTPOOL/fs-clone
+
+log_must eval "$ZFS list -r -o userquota@$QUSER1,groupquota@$QGROUP \
+       $TESTPOOL >/dev/null 2>&1"
+
+log_must check_quota "userquota@$QUSER1" $TESTPOOL/fs-clone "$UQUOTA_SIZE"
+log_must check_quota "groupquota@$QGROUP" $TESTPOOL/fs-clone "$GQUOTA_SIZE"
+
+log_must eval "$ZFS list -o userquota@$QUSER1,groupquota@$QGROUP \
+       $TESTPOOL/fs-clone >/dev/null 2>&1"
+
+log_note "zfs promote can not change the previously set user|group quota"
+log_must $ZFS promote $TESTPOOL/fs-clone
+
+log_must eval "$ZFS list -r -o userquota@$QUSER1,groupquota@$QGROUP \
+       $TESTPOOL >/dev/null 2>&1"
+
+log_must check_quota "userquota@$QUSER1" $TESTPOOL/fs-clone "$UQUOTA_SIZE"
+log_must check_quota "groupquota@$QGROUP" $TESTPOOL/fs-clone "$GQUOTA_SIZE"
+
+log_note "zfs send receive can not change the previously set user|group quota"
+log_must $ZFS send $TESTPOOL/fs-clone@snap | $ZFS receive $TESTPOOL/fs-rev
+
+log_must eval "$ZFS list -r -o userquota@$QUSER1,groupquota@$QGROUP \
+       $TESTPOOL >/dev/null 2>&1"
+
+log_must check_quota "userquota@$QUSER1" $TESTPOOL/fs-rev "$UQUOTA_SIZE"
+log_must check_quota "groupquota@$QGROUP" $TESTPOOL/fs-rev "$GQUOTA_SIZE"
+
+log_note "zfs rename can not change the previously set user|group quota"
+log_must $ZFS rename $TESTPOOL/fs-rev $TESTPOOL/fs-rename
+
+log_must eval "$ZFS list -r -o userquota@$QUSER1,groupquota@$QGROUP \
+       $TESTPOOL  >/dev/null 2>&1"
+
+log_must check_quota "userquota@$QUSER1" $TESTPOOL/fs-rename "$UQUOTA_SIZE"
+log_must check_quota "groupquota@$QGROUP" $TESTPOOL/fs-rename "$GQUOTA_SIZE"
+
+log_note "zfs upgrade can not change the previously set user|group quota"
+log_must $ZFS upgrade $TESTPOOL/fs-rename
+
+log_must eval "$ZFS list -r -o userquota@$QUSER1,groupquota@$QGROUP \
+       $TESTPOOL >/dev/null 2>&1"
+
+log_must check_quota "userquota@$QUSER1" $TESTPOOL/fs-rename "$UQUOTA_SIZE"
+log_must check_quota "groupquota@$QGROUP" $TESTPOOL/fs-rename "$GQUOTA_SIZE"
+
+log_pass \
+       "the userquota and groupquota can't change during zfs actions"
diff --git a/tests/zfs-tests/tests/functional/userquota/userquota_012_neg.ksh b/tests/zfs-tests/tests/functional/userquota/userquota_012_neg.ksh
new file mode 100755 (executable)
index 0000000..c1d790b
--- /dev/null
@@ -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.
+#
+
+#
+# Copyright (c) 2013 by Delphix. All rights reserved.
+#
+
+. $STF_SUITE/include/libtest.shlib
+. $STF_SUITE/tests/functional/userquota/userquota_common.kshlib
+
+#
+# DESCRIPTION:
+#       userquota and groupquota can not be set against snapshot
+#
+#
+# STRATEGY:
+#       1. Set userquota on snap and check the zfs get
+#       2. Set groupquota on snap and check the zfs get
+#
+
+function cleanup
+{
+       cleanup_quota
+
+       if datasetexists $snap_fs; then
+               log_must $ZFS destroy $snap_fs
+       fi
+}
+
+log_onexit cleanup
+
+typeset snap_fs=$QFS@snap
+log_assert "Check  set userquota and groupquota on snapshot"
+
+log_note "Check can not set user|group quuota on snapshot"
+log_must $ZFS snapshot $snap_fs
+
+log_mustnot $ZFS set userquota@$QUSER1=$UQUOTA_SIZE $snap_fs
+
+log_mustnot $ZFS set groupquota@$QGROUP=$GQUOTA_SIZE $snap_fs
+
+log_pass "Check  set userquota and groupquota on snapshot"
diff --git a/tests/zfs-tests/tests/functional/userquota/userquota_common.kshlib b/tests/zfs-tests/tests/functional/userquota/userquota_common.kshlib
new file mode 100644 (file)
index 0000000..7719196
--- /dev/null
@@ -0,0 +1,120 @@
+#
+# CDDL HEADER START
+#
+# The contents of this file are subject to the terms of the
+# Common Development and Distribution License (the "License").
+# You may not use this file except in compliance with the License.
+#
+# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
+# or http://www.opensolaris.org/os/licensing.
+# See the License for the specific language governing permissions
+# and limitations under the License.
+#
+# When distributing Covered Code, include this CDDL HEADER in each
+# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
+# If applicable, add the following below this CDDL HEADER, with the
+# fields enclosed by brackets "[]" replaced with your own identifying
+# information: Portions Copyright [yyyy] [name of copyright owner]
+#
+# CDDL HEADER END
+#
+
+#
+# Copyright 2009 Sun Microsystems, Inc.  All rights reserved.
+# Use is subject to license terms.
+#
+
+#
+# Copyright (c) 2013 by Delphix. All rights reserved.
+#
+
+. $STF_SUITE/include/libtest.shlib
+. $STF_SUITE/tests/functional/userquota/userquota.cfg
+
+#
+# reset the userquota and groupquota and delete temporary files
+#
+function cleanup_quota
+{
+       if datasetexists $QFS; then
+               log_must $ZFS set userquota@$QUSER1=none $QFS
+               log_must $ZFS set userquota@$QUSER2=none $QFS
+               log_must $ZFS set groupquota@$QGROUP=none $QFS
+               recovery_writable $QFS
+       fi
+
+       [[ -f $QFILE ]] && log_must $RM -f $QFILE
+       [[ -f $OFILE ]] && log_must $RM -f $OFILE
+       $SYNC
+
+        return 0
+}
+
+#
+# delete user and group that created during the test
+#
+function clean_user_group
+{
+       for usr in $QUSER1 $QUSER2; do
+               log_must del_user $usr
+       done
+
+       log_must del_group $QGROUP
+
+       return 0
+}
+
+#
+#  make the $QFS's mountpoint writable for all users
+#
+function mkmount_writable
+{
+       typeset fs=$1
+       typeset mntp=$(get_prop mountpoint $fs)
+       log_must $CHMOD 0777 $mntp
+}
+
+#
+# recovery the directory permission for $QFS
+#
+function recovery_writable
+{
+       typeset fs=$1
+       typeset mntp=$(get_prop mountpoint $fs)
+       log_must $CHMOD 0755 $mntp
+}
+
+#
+# check the quota value of a specific FS
+#
+function check_quota
+{
+       typeset fs=$2
+       typeset prop=$1
+       typeset expected=$3
+       typeset value=$(get_prop $prop $fs)
+
+       if (($value != $expected)); then
+               return 1
+       fi
+}
+
+#
+# zfs get prop, which return raw value not -p value.
+#
+function get_value # property dataset
+{
+        typeset prop_val
+        typeset prop=$1
+        typeset dataset=$2
+
+        prop_val=$($ZFS get -H -o value $prop $dataset 2>/dev/null)
+        if [[ $? -ne 0 ]]; then
+                log_note "Unable to get $prop property for dataset " \
+                "$dataset"
+                return 1
+        fi
+
+        $ECHO $prop_val
+        return 0
+}
diff --git a/tests/zfs-tests/tests/functional/userquota/userspace_001_pos.ksh b/tests/zfs-tests/tests/functional/userquota/userspace_001_pos.ksh
new file mode 100755 (executable)
index 0000000..c336ad2
--- /dev/null
@@ -0,0 +1,78 @@
+#!/bin/ksh -p
+#
+# CDDL HEADER START
+#
+# The contents of this file are subject to the terms of the
+# Common Development and Distribution License (the "License").
+# You may not use this file except in compliance with the License.
+#
+# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
+# or http://www.opensolaris.org/os/licensing.
+# See the License for the specific language governing permissions
+# and limitations under the License.
+#
+# When distributing Covered Code, include this CDDL HEADER in each
+# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
+# If applicable, add the following below this CDDL HEADER, with the
+# fields enclosed by brackets "[]" replaced with your own identifying
+# information: Portions Copyright [yyyy] [name of copyright owner]
+#
+# CDDL HEADER END
+#
+
+#
+# Copyright 2009 Sun Microsystems, Inc.  All rights reserved.
+# Use is subject to license terms.
+#
+
+#
+# Copyright (c) 2013 by Delphix. All rights reserved.
+#
+
+. $STF_SUITE/include/libtest.shlib
+. $STF_SUITE/tests/functional/userquota/userquota_common.kshlib
+
+#
+# DESCRIPTION:
+#       Check the zfs userspace with all parameters
+#
+#
+# STRATEGY:
+#       1. set zfs userspace to a fs
+#       2. write some data to the fs with specified user
+#      3. use zfs userspace with all possible parameters to check the result
+#
+
+function cleanup
+{
+       if datasetexists $snap_fs; then
+               log_must $ZFS destroy $snap_fs
+       fi
+
+       log_must cleanup_quota
+}
+
+log_onexit cleanup
+
+log_assert "Check the zfs userspace with all possible parameters"
+
+set -A params -- "-n" "-H" "-p" "-o type,name,used,quota" \
+    "-o name,used,quota" "-o used,quota" "-o used" "-o quota" "-s type" \
+    "-s name" "-s used" "-s quota" "-S type" "-S name" "-S used" "-S quota" \
+    "-t posixuser" "-t posixgroup" "-t all" "-i" "-tsmbuser" "-t smbgroup"
+
+typeset snap_fs=$QFS@snap
+
+log_must $ZFS set userquota@$QUSER1=100m $QFS
+mkmount_writable $QFS
+log_must user_run $QUSER1 $MKFILE 50m $QFILE
+$SYNC
+
+log_must $ZFS snapshot $snap_fs
+
+for param in "${params[@]}"; do
+       log_must eval "$ZFS userspace $param $QFS >/dev/null 2>&1"
+       log_must eval "$ZFS userspace $param $snap_fs >/dev/null 2>&1"
+done
+
+log_pass "zfs userspace with all possible parameters pass as expect"
diff --git a/tests/zfs-tests/tests/functional/userquota/userspace_002_pos.ksh b/tests/zfs-tests/tests/functional/userquota/userspace_002_pos.ksh
new file mode 100755 (executable)
index 0000000..b29052d
--- /dev/null
@@ -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.
+#
+
+#
+# Copyright (c) 2013 by Delphix. All rights reserved.
+#
+
+. $STF_SUITE/include/libtest.shlib
+. $STF_SUITE/tests/functional/userquota/userquota_common.kshlib
+
+#
+# DESCRIPTION:
+#       Check the user used size and quota in zfs userspace
+#
+#
+# STRATEGY:
+#       1. set zfs userquota to a fs
+#       2. write some data to the fs with specified user and size
+#      3. use zfs userspace to check the used size and quota size
+#
+
+function cleanup
+{
+       if datasetexists $snapfs; then
+               log_must $ZFS destroy $snapfs
+       fi
+
+       log_must cleanup_quota
+}
+
+log_onexit cleanup
+
+log_assert "Check the zfs userspace used and quota"
+
+log_must $ZFS set userquota@$QUSER1=100m $QFS
+
+mkmount_writable $QFS
+
+log_must user_run $QUSER1 $MKFILE 50m $QFILE
+$SYNC
+
+typeset snapfs=$QFS@snap
+
+log_must $ZFS snapshot $snapfs
+
+log_must eval "$ZFS userspace $QFS >/dev/null 2>&1"
+log_must eval "$ZFS userspace $snapfs >/dev/null 2>&1"
+
+for fs in "$QFS" "$snapfs"; do
+       log_note "check the quota size in zfs userspace $fs"
+       log_must eval "$ZFS userspace $fs | $GREP $QUSER1 | $GREP 100M"
+
+       log_note "check the user used size in zfs userspace $fs"
+       log_must eval "$ZFS userspace $fs | $GREP $QUSER1 | $GREP 50.0M"
+done
+
+log_pass "Check the zfs userspace used and quota"
diff --git a/tests/zfs-tests/tests/functional/write_dirs/Makefile.am b/tests/zfs-tests/tests/functional/write_dirs/Makefile.am
new file mode 100644 (file)
index 0000000..9bdc46b
--- /dev/null
@@ -0,0 +1,6 @@
+pkgdatadir = $(datadir)/@PACKAGE@/zfs-tests/tests/functional/write_dirs
+dist_pkgdata_SCRIPTS = \
+       setup.ksh \
+       cleanup.ksh \
+       write_dirs_001_pos.ksh \
+       write_dirs_002_pos.ksh
diff --git a/tests/zfs-tests/tests/functional/write_dirs/cleanup.ksh b/tests/zfs-tests/tests/functional/write_dirs/cleanup.ksh
new file mode 100755 (executable)
index 0000000..3166bd6
--- /dev/null
@@ -0,0 +1,34 @@
+#!/bin/ksh -p
+#
+# CDDL HEADER START
+#
+# The contents of this file are subject to the terms of the
+# Common Development and Distribution License (the "License").
+# You may not use this file except in compliance with the License.
+#
+# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
+# or http://www.opensolaris.org/os/licensing.
+# See the License for the specific language governing permissions
+# and limitations under the License.
+#
+# When distributing Covered Code, include this CDDL HEADER in each
+# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
+# If applicable, add the following below this CDDL HEADER, with the
+# fields enclosed by brackets "[]" replaced with your own identifying
+# information: Portions Copyright [yyyy] [name of copyright owner]
+#
+# CDDL HEADER END
+#
+
+#
+# Copyright 2007 Sun Microsystems, Inc.  All rights reserved.
+# Use is subject to license terms.
+#
+
+#
+# Copyright (c) 2013 by Delphix. All rights reserved.
+#
+
+. $STF_SUITE/include/libtest.shlib
+
+default_cleanup
diff --git a/tests/zfs-tests/tests/functional/write_dirs/setup.ksh b/tests/zfs-tests/tests/functional/write_dirs/setup.ksh
new file mode 100755 (executable)
index 0000000..14f60c9
--- /dev/null
@@ -0,0 +1,54 @@
+#!/bin/ksh -p
+#
+# CDDL HEADER START
+#
+# The contents of this file are subject to the terms of the
+# Common Development and Distribution License (the "License").
+# You may not use this file except in compliance with the License.
+#
+# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
+# or http://www.opensolaris.org/os/licensing.
+# See the License for the specific language governing permissions
+# and limitations under the License.
+#
+# When distributing Covered Code, include this CDDL HEADER in each
+# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
+# If applicable, add the following below this CDDL HEADER, with the
+# fields enclosed by brackets "[]" replaced with your own identifying
+# information: Portions Copyright [yyyy] [name of copyright owner]
+#
+# CDDL HEADER END
+#
+
+#
+# Copyright 2009 Sun Microsystems, Inc.  All rights reserved.
+# Use is subject to license terms.
+#
+
+#
+# Copyright (c) 2013 by Delphix. All rights reserved.
+#
+
+. $STF_SUITE/include/libtest.shlib
+
+verify_runnable "global"
+
+export SIZE="1gb"
+
+if is_linux; then
+       export SLICE_PREFIX="p"
+       export SLICE=1
+else
+       export SLICE_PREFIX="s"
+       export SLICE=0
+fi
+
+if ! $(is_physical_device $DISKS) ; then
+       log_unsupported "This directory cannot be run on raw files."
+fi
+
+DISK=${DISKS%% *}
+
+log_must set_partition $SLICE "" $SIZE $DISK
+
+default_setup "${DISK}${SLICE_PREFIX}${SLICE}"
diff --git a/tests/zfs-tests/tests/functional/write_dirs/write_dirs_001_pos.ksh b/tests/zfs-tests/tests/functional/write_dirs/write_dirs_001_pos.ksh
new file mode 100755 (executable)
index 0000000..dc5854b
--- /dev/null
@@ -0,0 +1,76 @@
+#!/bin/ksh -p
+#
+# CDDL HEADER START
+#
+# The contents of this file are subject to the terms of the
+# Common Development and Distribution License (the "License").
+# You may not use this file except in compliance with the License.
+#
+# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
+# or http://www.opensolaris.org/os/licensing.
+# See the License for the specific language governing permissions
+# and limitations under the License.
+#
+# When distributing Covered Code, include this CDDL HEADER in each
+# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
+# If applicable, add the following below this CDDL HEADER, with the
+# fields enclosed by brackets "[]" replaced with your own identifying
+# information: Portions Copyright [yyyy] [name of copyright owner]
+#
+# CDDL HEADER END
+#
+
+#
+# Copyright 2007 Sun Microsystems, Inc.  All rights reserved.
+# Use is subject to license terms.
+#
+
+#
+# Copyright (c) 2013 by Delphix. All rights reserved.
+#
+
+. $STF_SUITE/include/libtest.shlib
+
+#
+# DESCRIPTION:
+# Create as many directories with 50 big files each until the file system
+# is full. The zfs file system should be stable and works well.
+#
+# STRATEGY:
+# 1. Create a pool & dateset
+# 2. Make directories in the zfs file system
+# 3. Create 50 big files in each directories
+# 4. Test case exit when the disk is full.
+#
+
+verify_runnable "both"
+
+function cleanup
+{
+       for file in `$FIND $TESTDIR -type f`; do
+               $CAT /dev/null > $file
+       done
+       log_must $SYNC
+       log_must $RM -rf $TESTDIR/*
+}
+
+typeset -i retval=0
+log_assert "Creating directories with 50 big files in each, until file system "\
+       "is full."
+
+log_onexit cleanup
+
+typeset -i bytes=8192
+typeset -i num_writes=300000
+typeset -i dirnum=50
+typeset -i filenum=50
+
+fill_fs "" $dirnum $filenum $bytes $num_writes
+retval=$?
+if (( retval == 28 )); then
+       log_note "No space left on device."
+elif (( retval != 0 )); then
+       log_fail "Unexpected exit: $retval"
+fi
+
+log_pass "Write big files in a directory succeeded."
diff --git a/tests/zfs-tests/tests/functional/write_dirs/write_dirs_002_pos.ksh b/tests/zfs-tests/tests/functional/write_dirs/write_dirs_002_pos.ksh
new file mode 100755 (executable)
index 0000000..bc4aff0
--- /dev/null
@@ -0,0 +1,77 @@
+#!/bin/ksh -p
+#
+# CDDL HEADER START
+#
+# The contents of this file are subject to the terms of the
+# Common Development and Distribution License (the "License").
+# You may not use this file except in compliance with the License.
+#
+# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
+# or http://www.opensolaris.org/os/licensing.
+# See the License for the specific language governing permissions
+# and limitations under the License.
+#
+# When distributing Covered Code, include this CDDL HEADER in each
+# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
+# If applicable, add the following below this CDDL HEADER, with the
+# fields enclosed by brackets "[]" replaced with your own identifying
+# information: Portions Copyright [yyyy] [name of copyright owner]
+#
+# CDDL HEADER END
+#
+
+#
+# Copyright 2007 Sun Microsystems, Inc.  All rights reserved.
+# Use is subject to license terms.
+#
+
+#
+# Copyright (c) 2013 by Delphix. All rights reserved.
+#
+
+. $STF_SUITE/include/libtest.shlib
+
+#
+# DESCRIPTION:
+# Create as many directories with 5000 files each until the file system
+# is full. The zfs file system should be work well and stable.
+#
+# STRATEGY:
+# 1. Create a pool & dateset
+# 2. Make directories in the zfs file system
+# 3. Create 5000 files in each directories
+# 4. Test case exit when the disk is full
+#
+
+verify_runnable "both"
+
+function cleanup
+{
+       for file in `$FIND $TESTDIR -type f`; do
+               $CAT /dev/null > $file
+       done
+       log_must $SYNC
+       log_must $RM -rf $TESTDIR/*
+}
+
+typeset -i retval=0
+
+log_assert "Creating directories with 5000 files in each, until file system " \
+       "is full."
+
+log_onexit cleanup
+
+typeset -i bytes=8192
+typeset -i num_writes=20
+typeset -i dirnum=50
+typeset -i filenum=5000
+
+fill_fs "" $dirnum $filenum $bytes $num_writes
+retval=$?
+if (( retval == 28 )); then
+       log_note "No space left on device."
+elif (( retval != 0 )); then
+       log_fail "Unexpected exit: $retval"
+fi
+
+log_pass "Create many files in a directory succeeded."
diff --git a/tests/zfs-tests/tests/functional/xattr/Makefile.am b/tests/zfs-tests/tests/functional/xattr/Makefile.am
new file mode 100644 (file)
index 0000000..ac2cb54
--- /dev/null
@@ -0,0 +1,18 @@
+pkgdatadir = $(datadir)/@PACKAGE@/zfs-tests/tests/functional/xattr
+dist_pkgdata_SCRIPTS = \
+       xattr_common.kshlib \
+       setup.ksh \
+       cleanup.ksh \
+       xattr_001_pos.ksh \
+       xattr_002_neg.ksh \
+       xattr_003_neg.ksh \
+       xattr_004_pos.ksh \
+       xattr_005_pos.ksh \
+       xattr_006_pos.ksh \
+       xattr_007_neg.ksh \
+       xattr_008_pos.ksh \
+       xattr_009_neg.ksh \
+       xattr_010_neg.ksh \
+       xattr_011_pos.ksh \
+       xattr_012_pos.ksh \
+       xattr_013_pos.ksh 
diff --git a/tests/zfs-tests/tests/functional/xattr/cleanup.ksh b/tests/zfs-tests/tests/functional/xattr/cleanup.ksh
new file mode 100755 (executable)
index 0000000..b52c07d
--- /dev/null
@@ -0,0 +1,45 @@
+#!/bin/ksh -p
+#
+# CDDL HEADER START
+#
+# The contents of this file are subject to the terms of the
+# Common Development and Distribution License (the "License").
+# You may not use this file except in compliance with the License.
+#
+# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
+# or http://www.opensolaris.org/os/licensing.
+# See the License for the specific language governing permissions
+# and limitations under the License.
+#
+# When distributing Covered Code, include this CDDL HEADER in each
+# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
+# If applicable, add the following below this CDDL HEADER, with the
+# fields enclosed by brackets "[]" replaced with your own identifying
+# information: Portions Copyright [yyyy] [name of copyright owner]
+#
+# CDDL HEADER END
+#
+# Copyright 2007 Sun Microsystems, Inc.  All rights reserved.
+# Use is subject to license terms.
+#
+
+#
+# Copyright (c) 2013 by Delphix. All rights reserved.
+#
+
+. $STF_SUITE/include/libtest.shlib
+
+ZFS_USER=$($CAT /tmp/zfs-xattr-test-user.txt)
+$RM /tmp/zfs-xattr-test-user.txt
+
+USES_NIS=$($CAT /tmp/zfs-xattr-test-nis.txt)
+$RM /tmp/zfs-xattr-test-nis.txt
+
+del_user $ZFS_USER
+
+if [ "${USES_NIS}" == "true" ]
+then
+    $SVCADM enable svc:/network/nis/client:default
+fi
+
+default_cleanup
diff --git a/tests/zfs-tests/tests/functional/xattr/setup.ksh b/tests/zfs-tests/tests/functional/xattr/setup.ksh
new file mode 100755 (executable)
index 0000000..d359eb0
--- /dev/null
@@ -0,0 +1,64 @@
+#!/bin/ksh -p
+#
+# CDDL HEADER START
+#
+# The contents of this file are subject to the terms of the
+# Common Development and Distribution License (the "License").
+# You may not use this file except in compliance with the License.
+#
+# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
+# or http://www.opensolaris.org/os/licensing.
+# See the License for the specific language governing permissions
+# and limitations under the License.
+#
+# When distributing Covered Code, include this CDDL HEADER in each
+# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
+# If applicable, add the following below this CDDL HEADER, with the
+# fields enclosed by brackets "[]" replaced with your own identifying
+# information: Portions Copyright [yyyy] [name of copyright owner]
+#
+# CDDL HEADER END
+#
+# Copyright 2007 Sun Microsystems, Inc.  All rights reserved.
+# Use is subject to license terms.
+#
+
+#
+# Copyright (c) 2013 by Delphix. All rights reserved.
+#
+
+. $STF_SUITE/include/libtest.shlib
+
+# if we're running NIS, turn it off until we clean up
+# (it can cause useradd to take a long time, hitting our TIMEOUT)
+USES_NIS=FALSE
+$SVCS svc:/network/nis/client:default | $GREP online > /dev/null
+if [ $? -eq 0 ]
+then
+       $SVCADM disable -t svc:/network/nis/client:default
+       USES_NIS=true
+fi
+
+# Make sure we use a brand new user for this
+ZFS_USER=zxtr
+ZFS_GROUP=staff
+while [ -z "${FOUND}" ]
+do
+       COUNT=0
+       USER_EXISTS=$( $GREP $ZFS_USER /etc/passwd )
+       if [ ! -z "${USER_EXISTS}" ]
+       then
+               ZFS_USER="${ZFS_USER}${COUNT}"
+               COUNT=$(( $COUNT + 1 ))
+       else
+               FOUND="true"
+       fi
+done
+
+log_must add_user $ZFS_GROUP $ZFS_USER
+
+$ECHO $ZFS_USER > /tmp/zfs-xattr-test-user.txt
+$ECHO $USES_NIS > /tmp/zfs-xattr-test-nis.txt
+
+DISK=${DISKS%% *}
+default_setup $DISK
diff --git a/tests/zfs-tests/tests/functional/xattr/xattr_001_pos.ksh b/tests/zfs-tests/tests/functional/xattr/xattr_001_pos.ksh
new file mode 100755 (executable)
index 0000000..1bc7e5c
--- /dev/null
@@ -0,0 +1,63 @@
+#!/bin/ksh -p
+#
+# CDDL HEADER START
+#
+# The contents of this file are subject to the terms of the
+# Common Development and Distribution License (the "License").
+# You may not use this file except in compliance with the License.
+#
+# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
+# or http://www.opensolaris.org/os/licensing.
+# See the License for the specific language governing permissions
+# and limitations under the License.
+#
+# When distributing Covered Code, include this CDDL HEADER in each
+# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
+# If applicable, add the following below this CDDL HEADER, with the
+# fields enclosed by brackets "[]" replaced with your own identifying
+# information: Portions Copyright [yyyy] [name of copyright owner]
+#
+# CDDL HEADER END
+#
+# Copyright 2007 Sun Microsystems, Inc.  All rights reserved.
+# Use is subject to license terms.
+#
+
+#
+# Copyright (c) 2013 by Delphix. All rights reserved.
+#
+
+. $STF_SUITE/include/libtest.shlib
+. $STF_SUITE/tests/functional/xattr/xattr_common.kshlib
+
+#
+# DESCRIPTION:
+#
+# Creating, reading and writing xattrs on ZFS filesystems works as expected
+#
+# STRATEGY:
+#      1. Create an xattr on a ZFS-based file using runat
+#      2. Read an empty xattr directory
+#       3. Write the xattr using runat and cat
+#      3. Read the xattr using runat
+#      4. Delete the xattr
+#      5. List the xattr namespace successfully, checking for deletion
+#
+
+function cleanup {
+
+       if [ -f $TESTDIR/myfile.$$ ]
+       then
+               log_must $RM $TESTDIR/myfile.$$
+       fi
+}
+
+log_assert "Create/read/write/append of xattrs works"
+log_onexit cleanup
+
+log_must $TOUCH $TESTDIR/myfile.$$
+create_xattr $TESTDIR/myfile.$$ passwd /etc/passwd
+verify_write_xattr $TESTDIR/myfile.$$ passwd
+delete_xattr $TESTDIR/myfile.$$ passwd
+
+log_pass "Create/read/write of xattrs works"
diff --git a/tests/zfs-tests/tests/functional/xattr/xattr_002_neg.ksh b/tests/zfs-tests/tests/functional/xattr/xattr_002_neg.ksh
new file mode 100755 (executable)
index 0000000..cd57b35
--- /dev/null
@@ -0,0 +1,56 @@
+#!/bin/ksh -p
+#
+# CDDL HEADER START
+#
+# The contents of this file are subject to the terms of the
+# Common Development and Distribution License (the "License").
+# You may not use this file except in compliance with the License.
+#
+# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
+# or http://www.opensolaris.org/os/licensing.
+# See the License for the specific language governing permissions
+# and limitations under the License.
+#
+# When distributing Covered Code, include this CDDL HEADER in each
+# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
+# If applicable, add the following below this CDDL HEADER, with the
+# fields enclosed by brackets "[]" replaced with your own identifying
+# information: Portions Copyright [yyyy] [name of copyright owner]
+#
+# CDDL HEADER END
+#
+# Copyright 2007 Sun Microsystems, Inc.  All rights reserved.
+# Use is subject to license terms.
+#
+
+#
+# Copyright (c) 2013 by Delphix. All rights reserved.
+#
+
+. $STF_SUITE/include/libtest.shlib
+. $STF_SUITE/tests/functional/xattr/xattr_common.kshlib
+
+#
+# DESCRIPTION:
+#
+# Trying to read a non-existent xattr should fail.
+#
+# STRATEGY:
+#      1. Create a file
+#       2. Try to read a non-existent xattr, check that an error is returned.
+#
+
+function cleanup {
+
+       log_must $RM $TESTDIR/myfile.$$
+
+}
+
+log_assert "A read of a non-existent xattr fails"
+log_onexit cleanup
+
+# create a file
+log_must $TOUCH $TESTDIR/myfile.$$
+log_mustnot eval "$CAT $TESTDIR/myfile.$$ not-here.txt > /dev/null 2>&1"
+
+log_pass "A read of a non-existent xattr fails"
diff --git a/tests/zfs-tests/tests/functional/xattr/xattr_003_neg.ksh b/tests/zfs-tests/tests/functional/xattr/xattr_003_neg.ksh
new file mode 100755 (executable)
index 0000000..90d7860
--- /dev/null
@@ -0,0 +1,62 @@
+#!/bin/ksh -p
+#
+# CDDL HEADER START
+#
+# The contents of this file are subject to the terms of the
+# Common Development and Distribution License (the "License").
+# You may not use this file except in compliance with the License.
+#
+# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
+# or http://www.opensolaris.org/os/licensing.
+# See the License for the specific language governing permissions
+# and limitations under the License.
+#
+# When distributing Covered Code, include this CDDL HEADER in each
+# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
+# If applicable, add the following below this CDDL HEADER, with the
+# fields enclosed by brackets "[]" replaced with your own identifying
+# information: Portions Copyright [yyyy] [name of copyright owner]
+#
+# CDDL HEADER END
+#
+# Copyright 2007 Sun Microsystems, Inc.  All rights reserved.
+# Use is subject to license terms.
+#
+
+#
+# Copyright (c) 2013 by Delphix. All rights reserved.
+#
+
+. $STF_SUITE/include/libtest.shlib
+. $STF_SUITE/tests/functional/xattr/xattr_common.kshlib
+
+#
+# DESCRIPTION:
+#
+# Attempting to read an xattr on a file for which we have no permissions
+# should fail.
+#
+# STRATEGY:
+#      1. Create a file, and set an with an xattr
+#       2. Set the octal file permissions to 000 on the file.
+#      3. Check that we're unable to read the xattr as a non-root user
+#      4. Check that we're unable to write an xattr as a non-root user
+#
+
+function cleanup {
+
+       log_must $RM $TESTDIR/myfile.$$
+
+}
+
+log_assert "read/write xattr on a file with no permissions fails"
+log_onexit cleanup
+
+log_must $TOUCH $TESTDIR/myfile.$$
+create_xattr $TESTDIR/myfile.$$ passwd /etc/passwd
+
+log_must $CHMOD 000 $TESTDIR/myfile.$$
+log_mustnot $SU $ZFS_USER -c "$RUNAT $TESTDIR/myfile.$$ $CAT passwd"
+log_mustnot $SU $ZFS_USER -c "$RUNAT $TESTDIR/myfile.$$ $CP /etc/passwd ."
+
+log_pass "read/write xattr on a file with no permissions fails"
diff --git a/tests/zfs-tests/tests/functional/xattr/xattr_004_pos.ksh b/tests/zfs-tests/tests/functional/xattr/xattr_004_pos.ksh
new file mode 100755 (executable)
index 0000000..f0f301f
--- /dev/null
@@ -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.
+#
+
+#
+# Copyright (c) 2013 by Delphix. All rights reserved.
+#
+
+. $STF_SUITE/include/libtest.shlib
+. $STF_SUITE/tests/functional/xattr/xattr_common.kshlib
+
+#
+# DESCRIPTION:
+#
+# Creating files on ufs|ext2 and tmpfs, and copying those files to ZFS with
+# appropriate cp flags, the xattrs will still be readable.
+#
+# STRATEGY:
+#      1. Create files in ufs|ext2 and tmpfs with xattrs
+#       2. Copy those files to zfs
+#      3. Ensure the xattrs can be read and written
+#      4. Do the same in reverse.
+#
+
+# we need to be able to create zvols to hold our test
+# ufs|ext2 filesystem.
+verify_runnable "global"
+
+# Make sure we clean up properly
+function cleanup {
+
+       if [ $( ismounted /tmp/$NEWFS_DEFAULT_FS.$$ $NEWFS_DEFAULT_FS ) ]
+       then
+               log_must $UMOUNT /tmp/$NEWFS_DEFAULT_FS.$$
+               log_must $RM -rf /tmp/$NEWFS_DEFAULT_FS.$$
+       fi
+}
+
+log_assert "Files from $NEWFS_DEFAULT_FS,tmpfs with xattrs copied to zfs retain xattr info."
+log_onexit cleanup
+
+# Create a UFS|EXT2 file system that we can work in
+log_must $ZFS create -V128m $TESTPOOL/$TESTFS/zvol
+block_device_wait
+log_must eval "$ECHO y | $NEWFS $ZVOL_DEVDIR/$TESTPOOL/$TESTFS/zvol > /dev/null 2>&1"
+
+log_must $MKDIR /tmp/$NEWFS_DEFAULT_FS.$$
+log_must $MOUNT $ZVOL_DEVDIR/$TESTPOOL/$TESTFS/zvol /tmp/$NEWFS_DEFAULT_FS.$$
+
+# Create files in ufs|ext2 and tmpfs, and set some xattrs on them.
+log_must $TOUCH /tmp/$NEWFS_DEFAULT_FS.$$/$NEWFS_DEFAULT_FS-file.$$
+log_must $TOUCH /tmp/tmpfs-file.$$
+
+log_must $RUNAT /tmp/$NEWFS_DEFAULT_FS.$$/$NEWFS_DEFAULT_FS-file.$$ $CP /etc/passwd .
+log_must $RUNAT /tmp/tmpfs-file.$$ $CP /etc/group .
+
+# copy those files to ZFS
+log_must $CP -@ /tmp/$NEWFS_DEFAULT_FS.$$/$NEWFS_DEFAULT_FS-file.$$ $TESTDIR
+log_must $CP -@ /tmp/tmpfs-file.$$ $TESTDIR
+
+# ensure the xattr information has been copied correctly
+log_must $RUNAT $TESTDIR/$NEWFS_DEFAULT_FS-file.$$ $DIFF passwd /etc/passwd
+log_must $RUNAT $TESTDIR/tmpfs-file.$$ $DIFF group /etc/group
+
+log_must $UMOUNT /tmp/$NEWFS_DEFAULT_FS.$$
+log_pass "Files from $NEWFS_DEFAULT_FS,tmpfs with xattrs copied to zfs retain xattr info."
diff --git a/tests/zfs-tests/tests/functional/xattr/xattr_005_pos.ksh b/tests/zfs-tests/tests/functional/xattr/xattr_005_pos.ksh
new file mode 100755 (executable)
index 0000000..f7be58e
--- /dev/null
@@ -0,0 +1,78 @@
+#!/bin/ksh -p
+#
+# CDDL HEADER START
+#
+# The contents of this file are subject to the terms of the
+# Common Development and Distribution License (the "License").
+# You may not use this file except in compliance with the License.
+#
+# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
+# or http://www.opensolaris.org/os/licensing.
+# See the License for the specific language governing permissions
+# and limitations under the License.
+#
+# When distributing Covered Code, include this CDDL HEADER in each
+# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
+# If applicable, add the following below this CDDL HEADER, with the
+# fields enclosed by brackets "[]" replaced with your own identifying
+# information: Portions Copyright [yyyy] [name of copyright owner]
+#
+# CDDL HEADER END
+#
+# Copyright 2007 Sun Microsystems, Inc.  All rights reserved.
+# Use is subject to license terms.
+#
+
+#
+# Copyright (c) 2013 by Delphix. All rights reserved.
+#
+
+. $STF_SUITE/include/libtest.shlib
+. $STF_SUITE/tests/functional/xattr/xattr_common.kshlib
+
+#
+# DESCRIPTION:
+# read/write/create/delete xattr on a clone filesystem
+#
+#
+# STRATEGY:
+#      1. Create an xattr on a filesystem
+#      2. Snapshot the filesystem and clone it
+#       3. Verify the xattr can still be read, written, deleted
+#      4. Verify we can create new xattrs on new files created on the clone
+#
+
+function cleanup {
+
+       log_must $ZFS destroy $TESTPOOL/$TESTFS/clone
+       log_must $ZFS destroy $TESTPOOL/$TESTFS@snapshot1
+       log_must $RM $TESTDIR/myfile.$$
+}
+
+log_assert "read/write/create/delete xattr on a clone filesystem"
+log_onexit cleanup
+
+# create a file, and an xattr on it
+log_must $TOUCH $TESTDIR/myfile.$$
+create_xattr $TESTDIR/myfile.$$ passwd /etc/passwd
+
+# snapshot & clone the filesystem
+log_must $ZFS snapshot $TESTPOOL/$TESTFS@snapshot1
+log_must $ZFS clone $TESTPOOL/$TESTFS@snapshot1 $TESTPOOL/$TESTFS/clone
+log_must $ZFS set mountpoint=$TESTDIR/clone $TESTPOOL/$TESTFS/clone
+
+# check for the xattrs on the clone
+verify_xattr $TESTDIR/clone/myfile.$$ passwd /etc/passwd
+
+# check we can create xattrs on the clone
+create_xattr $TESTDIR/clone/myfile.$$ foo /etc/passwd
+delete_xattr $TESTDIR/clone/myfile.$$ foo
+
+# delete the original dataset xattr
+delete_xattr $TESTDIR/myfile.$$ passwd
+
+# verify it's still there on the clone
+verify_xattr $TESTDIR/clone/myfile.$$ passwd /etc/passwd
+delete_xattr $TESTDIR/clone/myfile.$$ passwd
+
+log_pass "read/write/create/delete xattr on a clone filesystem"
diff --git a/tests/zfs-tests/tests/functional/xattr/xattr_006_pos.ksh b/tests/zfs-tests/tests/functional/xattr/xattr_006_pos.ksh
new file mode 100755 (executable)
index 0000000..24915fd
--- /dev/null
@@ -0,0 +1,63 @@
+#!/bin/ksh -p
+#
+# CDDL HEADER START
+#
+# The contents of this file are subject to the terms of the
+# Common Development and Distribution License (the "License").
+# You may not use this file except in compliance with the License.
+#
+# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
+# or http://www.opensolaris.org/os/licensing.
+# See the License for the specific language governing permissions
+# and limitations under the License.
+#
+# When distributing Covered Code, include this CDDL HEADER in each
+# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
+# If applicable, add the following below this CDDL HEADER, with the
+# fields enclosed by brackets "[]" replaced with your own identifying
+# information: Portions Copyright [yyyy] [name of copyright owner]
+#
+# CDDL HEADER END
+#
+# Copyright 2007 Sun Microsystems, Inc.  All rights reserved.
+# Use is subject to license terms.
+#
+
+#
+# Copyright (c) 2013 by Delphix. All rights reserved.
+#
+
+. $STF_SUITE/include/libtest.shlib
+. $STF_SUITE/tests/functional/xattr/xattr_common.kshlib
+
+#
+# DESCRIPTION:
+# Xattrs present on a file in a snapshot should be visible.
+#
+# STRATEGY:
+#      1. Create a file and give it an xattr
+#       2. Take a snapshot of the filesystem
+#      3. Verify that we can take a snapshot of it.
+#
+
+function cleanup {
+
+       log_must $ZFS destroy $TESTPOOL/$TESTFS@snap
+       log_must $RM $TESTDIR/myfile.$$
+
+}
+
+log_assert "read xattr on a snapshot"
+log_onexit cleanup
+
+# create a file, and an xattr on it
+log_must $TOUCH $TESTDIR/myfile.$$
+create_xattr $TESTDIR/myfile.$$ passwd /etc/passwd
+
+# snapshot the filesystem
+log_must $ZFS snapshot $TESTPOOL/$TESTFS@snap
+
+# check for the xattr on the snapshot
+verify_xattr $TESTDIR/.zfs/snapshot/snap/myfile.$$ passwd /etc/passwd
+
+log_pass "read xattr on a snapshot"
diff --git a/tests/zfs-tests/tests/functional/xattr/xattr_007_neg.ksh b/tests/zfs-tests/tests/functional/xattr/xattr_007_neg.ksh
new file mode 100755 (executable)
index 0000000..bef6020
--- /dev/null
@@ -0,0 +1,81 @@
+#!/bin/ksh -p
+#
+# CDDL HEADER START
+#
+# The contents of this file are subject to the terms of the
+# Common Development and Distribution License (the "License").
+# You may not use this file except in compliance with the License.
+#
+# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
+# or http://www.opensolaris.org/os/licensing.
+# See the License for the specific language governing permissions
+# and limitations under the License.
+#
+# When distributing Covered Code, include this CDDL HEADER in each
+# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
+# If applicable, add the following below this CDDL HEADER, with the
+# fields enclosed by brackets "[]" replaced with your own identifying
+# information: Portions Copyright [yyyy] [name of copyright owner]
+#
+# CDDL HEADER END
+#
+# Copyright 2008 Sun Microsystems, Inc.  All rights reserved.
+# Use is subject to license terms.
+#
+
+#
+# Copyright (c) 2013 by Delphix. All rights reserved.
+#
+
+. $STF_SUITE/include/libtest.shlib
+. $STF_SUITE/tests/functional/xattr/xattr_common.kshlib
+
+#
+# DESCRIPTION:
+# Creating and writing xattrs on files in snapshot directories fails. Also,
+# we shouldn't be able to list the xattrs of files in snapshots who didn't have
+# xattrs when the snapshot was created (the xattr namespace wouldn't have been
+# created yet, and snapshots are read-only) See fsattr(5) for more details.
+#
+# STRATEGY:
+#      1. Create a file and add an xattr to it.
+#      2. Create another file, but don't add an xattr to it.
+#       3. Snapshot the filesystem
+#      4. Verify we're unable to alter the xattr on the first file
+#      5. Verify we're unable to list the xattrs on the second file
+#
+
+function cleanup {
+       log_must $ZFS destroy $TESTPOOL/$TESTFS@snap
+       log_must $RM $TESTDIR/myfile2.$$
+       log_must $RM $TESTDIR/myfile.$$
+       log_must $RM /tmp/output.$$
+       [[ -e /tmp/expected_output.$$ ]]  && log_must $RM  \
+       /tmp/expected_output.$$
+
+}
+
+log_assert "create/write xattr on a snapshot fails"
+log_onexit cleanup
+
+# create a file, and an xattr on it
+log_must $TOUCH $TESTDIR/myfile.$$
+create_xattr $TESTDIR/myfile.$$ passwd /etc/passwd
+
+# create another file that doesn't have an xattr
+log_must $TOUCH $TESTDIR/myfile2.$$
+
+# snapshot the filesystem
+log_must $ZFS snapshot $TESTPOOL/$TESTFS@snap
+
+# we shouldn't be able to alter the first file's xattr
+log_mustnot eval " $RUNAT $TESTDIR/.zfs/snapshot/snap/myfile.$$ \
+    $CP /etc/passwd .  >/tmp/output.$$  2>&1"
+log_must $GREP  -i  Read-only  /tmp/output.$$
+
+log_must eval "$RUNAT $TESTDIR/.zfs/snapshot/snap/myfile2.$$  \
+    $LS >/tmp/output.$$  2>&1"
+create_expected_output  /tmp/expected_output.$$ SUNWattr_ro SUNWattr_rw
+log_must $DIFF /tmp/output.$$ /tmp/expected_output.$$
+
+log_pass "create/write xattr on a snapshot fails"
diff --git a/tests/zfs-tests/tests/functional/xattr/xattr_008_pos.ksh b/tests/zfs-tests/tests/functional/xattr/xattr_008_pos.ksh
new file mode 100755 (executable)
index 0000000..40cc4a0
--- /dev/null
@@ -0,0 +1,80 @@
+#!/bin/ksh -p
+#
+# CDDL HEADER START
+#
+# The contents of this file are subject to the terms of the
+# Common Development and Distribution License (the "License").
+# You may not use this file except in compliance with the License.
+#
+# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
+# or http://www.opensolaris.org/os/licensing.
+# See the License for the specific language governing permissions
+# and limitations under the License.
+#
+# When distributing Covered Code, include this CDDL HEADER in each
+# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
+# If applicable, add the following below this CDDL HEADER, with the
+# fields enclosed by brackets "[]" replaced with your own identifying
+# information: Portions Copyright [yyyy] [name of copyright owner]
+#
+# CDDL HEADER END
+#
+# Copyright 2008 Sun Microsystems, Inc.  All rights reserved.
+# Use is subject to license terms.
+#
+
+#
+# Copyright (c) 2013 by Delphix. All rights reserved.
+#
+
+. $STF_SUITE/include/libtest.shlib
+. $STF_SUITE/tests/functional/xattr/xattr_common.kshlib
+
+#
+# DESCRIPTION:
+# We verify that the special . and .. dirs work as expected for xattrs.
+#
+# STRATEGY:
+#      1. Create a file and an xattr on that file
+#      2. List the . directory, verifying the output
+#      3. Verify we're unable to list the ../ directory
+#
+
+function cleanup {
+       typeset file
+
+       for file in /tmp/output.$$ /tmp/expected-output.$$ \
+               $TESTDIR/myfile.$$ ; do
+               log_must $RM -f $file
+       done
+}
+
+log_assert "special . and .. dirs work as expected for xattrs"
+log_onexit cleanup
+
+# create a file, and an xattr on it
+log_must $TOUCH $TESTDIR/myfile.$$
+create_xattr $TESTDIR/myfile.$$ passwd /etc/passwd
+
+# listing the directory .
+log_must eval "$RUNAT $TESTDIR/myfile.$$ $LS  . > /tmp/output.$$"
+create_expected_output  /tmp/expected-output.$$  \
+    SUNWattr_ro  SUNWattr_rw  passwd
+log_must $DIFF /tmp/output.$$ /tmp/expected-output.$$
+# list the directory . long form
+log_must eval "$RUNAT $TESTDIR/myfile.$$ $LS -a . > /tmp/output.$$"
+create_expected_output  /tmp/expected-output.$$ . ..  \
+    SUNWattr_ro  SUNWattr_rw  passwd
+log_must $DIFF /tmp/output.$$ /tmp/expected-output.$$
+
+# list the directory .. expecting one file
+OUTPUT=$($RUNAT $TESTDIR/myfile.$$ $LS ..)
+if [ "$OUTPUT" != ".." ]
+then
+       log_fail "Listing the .. directory doesn't show \"..\" as expected."
+fi
+
+# verify we can't list ../
+log_mustnot eval "$RUNAT $TESTDIR/myfile.$$ $LS ../ > /dev/null 2>&1"
+
+log_pass "special . and .. dirs work as expected for xattrs"
diff --git a/tests/zfs-tests/tests/functional/xattr/xattr_009_neg.ksh b/tests/zfs-tests/tests/functional/xattr/xattr_009_neg.ksh
new file mode 100755 (executable)
index 0000000..40b3617
--- /dev/null
@@ -0,0 +1,62 @@
+#!/bin/ksh -p
+#
+# CDDL HEADER START
+#
+# The contents of this file are subject to the terms of the
+# Common Development and Distribution License (the "License").
+# You may not use this file except in compliance with the License.
+#
+# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
+# or http://www.opensolaris.org/os/licensing.
+# See the License for the specific language governing permissions
+# and limitations under the License.
+#
+# When distributing Covered Code, include this CDDL HEADER in each
+# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
+# If applicable, add the following below this CDDL HEADER, with the
+# fields enclosed by brackets "[]" replaced with your own identifying
+# information: Portions Copyright [yyyy] [name of copyright owner]
+#
+# CDDL HEADER END
+#
+# Copyright 2007 Sun Microsystems, Inc.  All rights reserved.
+# Use is subject to license terms.
+#
+
+#
+# Copyright (c) 2013 by Delphix. All rights reserved.
+#
+
+. $STF_SUITE/include/libtest.shlib
+. $STF_SUITE/tests/functional/xattr/xattr_common.kshlib
+
+#
+# DESCRIPTION:
+# links between xattr and normal file namespace fail
+#
+# STRATEGY:
+#      1. Create a file and add an xattr to it (to ensure the namespace exists)
+#       2. Verify we're unable to create a symbolic link
+#      3. Verify we're unable to create a hard link
+#
+
+function cleanup {
+
+       log_must $RM $TESTDIR/myfile.$$
+
+}
+
+log_assert "links between xattr and normal file namespace fail"
+log_onexit cleanup
+
+# create a file, and an xattr on it
+log_must $TOUCH $TESTDIR/myfile.$$
+create_xattr $TESTDIR/myfile.$$ passwd /etc/passwd
+
+# Try to create a soft link from the xattr namespace to the default namespace
+log_mustnot $RUNAT $TESTDIR/myfile.$$ $LN -s /etc/passwd foo
+
+# Try to create a hard link from the xattr namespace to the default namespace
+log_mustnot $RUNAT $TESTDIR/myfile.$$ $LN /etc/passwd foo
+
+log_pass "links between xattr and normal file namespace fail"
diff --git a/tests/zfs-tests/tests/functional/xattr/xattr_010_neg.ksh b/tests/zfs-tests/tests/functional/xattr/xattr_010_neg.ksh
new file mode 100755 (executable)
index 0000000..e3e23a4
--- /dev/null
@@ -0,0 +1,66 @@
+#!/bin/ksh -p
+#
+# CDDL HEADER START
+#
+# The contents of this file are subject to the terms of the
+# Common Development and Distribution License (the "License").
+# You may not use this file except in compliance with the License.
+#
+# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
+# or http://www.opensolaris.org/os/licensing.
+# See the License for the specific language governing permissions
+# and limitations under the License.
+#
+# When distributing Covered Code, include this CDDL HEADER in each
+# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
+# If applicable, add the following below this CDDL HEADER, with the
+# fields enclosed by brackets "[]" replaced with your own identifying
+# information: Portions Copyright [yyyy] [name of copyright owner]
+#
+# CDDL HEADER END
+#
+# Copyright 2007 Sun Microsystems, Inc.  All rights reserved.
+# Use is subject to license terms.
+#
+
+#
+# Copyright (c) 2013 by Delphix. All rights reserved.
+#
+
+. $STF_SUITE/include/libtest.shlib
+. $STF_SUITE/tests/functional/xattr/xattr_common.kshlib
+
+#
+# DESCRIPTION:
+# Verify that mkdir and various mknods fail inside the xattr namespace
+#
+# STRATEGY:
+#      1. Create a file and add an xattr to it (to ensure the namespace exists)
+#       2. Verify that mkdir fails inside the xattr namespace
+#      3. Verify that various mknods fails inside the xattr namespace
+#
+#
+
+function cleanup {
+
+       log_must $RM $TESTDIR/myfile.$$
+}
+
+log_assert "mkdir, mknod fail"
+log_onexit cleanup
+
+# create a file, and an xattr on it
+log_must $TOUCH $TESTDIR/myfile.$$
+create_xattr $TESTDIR/myfile.$$ passwd /etc/passwd
+
+# Try to create directory in the xattr namespace
+log_mustnot $RUNAT $TESTDIR/myfile.$$ $MKDIR foo
+
+# Try to create a range of different filetypes in the xattr namespace
+log_mustnot $RUNAT $TESTDIR/myfile.$$ $MKNOD block b 888 888
+
+log_mustnot $RUNAT $TESTDIR/myfile.$$ $MKNOD char c
+
+log_mustnot $RUNAT $TESTDIR/myfile.$$ $MKNOD fifo p
+
+log_pass "mkdir, mknod fail"
diff --git a/tests/zfs-tests/tests/functional/xattr/xattr_011_pos.ksh b/tests/zfs-tests/tests/functional/xattr/xattr_011_pos.ksh
new file mode 100755 (executable)
index 0000000..e3a8d26
--- /dev/null
@@ -0,0 +1,193 @@
+#!/bin/ksh -p
+#
+# CDDL HEADER START
+#
+# The contents of this file are subject to the terms of the
+# Common Development and Distribution License (the "License").
+# You may not use this file except in compliance with the License.
+#
+# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
+# or http://www.opensolaris.org/os/licensing.
+# See the License for the specific language governing permissions
+# and limitations under the License.
+#
+# When distributing Covered Code, include this CDDL HEADER in each
+# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
+# If applicable, add the following below this CDDL HEADER, with the
+# fields enclosed by brackets "[]" replaced with your own identifying
+# information: Portions Copyright [yyyy] [name of copyright owner]
+#
+# CDDL HEADER END
+#
+# Copyright 2007 Sun Microsystems, Inc.  All rights reserved.
+# Use is subject to license terms.
+#
+
+#
+# Copyright (c) 2012 by Delphix. All rights reserved.
+#
+
+#
+# Copyright (c) 2013 by Delphix. All rights reserved.
+#
+
+. $STF_SUITE/include/libtest.shlib
+. $STF_SUITE/tests/functional/xattr/xattr_common.kshlib
+
+#
+# DESCRIPTION:
+#
+# Basic applications work with xattrs: cpio cp find mv pax tar
+#
+# STRATEGY:
+#      1. For each application
+#       2. Create an xattr and archive/move/copy/find files with xattr support
+#      3. Also check that when appropriate flag is not used, the xattr
+#         doesn't get copied
+#
+
+function cleanup {
+
+       log_must $RM $TESTDIR/myfile.$$
+}
+
+log_assert "Basic applications work with xattrs: cpio cp find mv pax tar"
+log_onexit cleanup
+
+# Create a file, and set an xattr on it. This file is used in several of the
+# test scenarios below.
+log_must $TOUCH $TESTDIR/myfile.$$
+create_xattr $TESTDIR/myfile.$$ passwd /etc/passwd
+
+
+# For the archive applications below (tar, cpio, pax)
+# we create two archives, one with xattrs, one without
+# and try various cpio options extracting the archives
+# with and without xattr support, checking for correct behaviour
+
+
+log_note "Checking cpio"
+log_must $TOUCH $TESTDIR/cpio.$$
+create_xattr $TESTDIR/cpio.$$ passwd /etc/passwd
+$ECHO $TESTDIR/cpio.$$ | $CPIO -o@ > /tmp/xattr.$$.cpio
+$ECHO $TESTDIR/cpio.$$ | $CPIO -o > /tmp/noxattr.$$.cpio
+
+# we should have no xattr here
+log_must $CPIO -iu < /tmp/xattr.$$.cpio
+log_mustnot eval "$RUNAT $TESTDIR/cpio.$$ $CAT passwd > /dev/null 2>&1"
+
+# we should have an xattr here
+log_must $CPIO -iu@ < /tmp/xattr.$$.cpio
+log_must eval "$RUNAT $TESTDIR/cpio.$$ $CAT passwd > /dev/null 2>&1"
+
+# we should have no xattr here
+log_must $CPIO -iu < /tmp/noxattr.$$.cpio
+log_mustnot eval "$RUNAT $TESTDIR/cpio.$$ $CAT passwd > /dev/null 2>&1"
+
+# we should have no xattr here
+log_must $CPIO -iu@ < /tmp/noxattr.$$.cpio
+log_mustnot eval "$RUNAT $TESTDIR/cpio.$$ $CAT passwd > /dev/null 2>&1"
+log_must $RM $TESTDIR/cpio.$$ /tmp/xattr.$$.cpio /tmp/noxattr.$$.cpio
+
+
+
+log_note "Checking cp"
+# check that with the right flag, the xattr is preserved
+log_must $CP -@ $TESTDIR/myfile.$$ $TESTDIR/myfile2.$$
+compare_xattrs $TESTDIR/myfile.$$ $TESTDIR/myfile2.$$ passwd
+log_must $RM $TESTDIR/myfile2.$$
+
+# without the right flag, there should be no xattr
+log_must $CP $TESTDIR/myfile.$$ $TESTDIR/myfile2.$$
+log_mustnot eval "$RUNAT $TESTDIR/myfile2.$$ $LS passwd > /dev/null 2>&1"
+log_must $RM $TESTDIR/myfile2.$$
+
+
+
+log_note "Checking find"
+# create a file without xattrs, and check that find -xattr only finds
+# our test file that has an xattr.
+log_must $MKDIR $TESTDIR/noxattrs
+log_must $TOUCH $TESTDIR/noxattrs/no-xattr
+
+$FIND $TESTDIR -xattr | $GREP myfile.$$
+[[ $? -ne 0 ]] && \
+       log_fail "find -xattr didn't find our file that had an xattr."
+$FIND $TESTDIR -xattr | $GREP no-xattr
+[[ $? -eq 0 ]] && \
+       log_fail "find -xattr found a file that didn't have an xattr."
+log_must $RM -rf $TESTDIR/noxattrs
+
+
+
+log_note "Checking mv"
+# mv doesn't have any flags to preserve/ommit xattrs - they're
+# always moved.
+log_must $TOUCH $TESTDIR/mvfile.$$
+create_xattr $TESTDIR/mvfile.$$ passwd /etc/passwd
+log_must $MV $TESTDIR/mvfile.$$ $TESTDIR/mvfile2.$$
+verify_xattr $TESTDIR/mvfile2.$$ passwd /etc/passwd
+log_must $RM $TESTDIR/mvfile2.$$
+
+
+log_note "Checking pax"
+log_must $TOUCH $TESTDIR/pax.$$
+create_xattr $TESTDIR/pax.$$ passwd /etc/passwd
+log_must $PAX -w -f $TESTDIR/noxattr.pax $TESTDIR/pax.$$
+log_must $PAX -w@ -f $TESTDIR/xattr.pax $TESTDIR/pax.$$
+log_must $RM $TESTDIR/pax.$$
+
+# we should have no xattr here
+log_must $PAX -r -f $TESTDIR/noxattr.pax
+log_mustnot eval "$RUNAT $TESTDIR/pax.$$ $CAT passwd > /dev/null 2>&1"
+log_must $RM $TESTDIR/pax.$$
+
+# we should have no xattr here
+log_must $PAX -r@ -f $TESTDIR/noxattr.pax
+log_mustnot eval "$RUNAT $TESTDIR/pax.$$ $CAT passwd > /dev/null 2>&1"
+log_must $RM $TESTDIR/pax.$$
+
+
+# we should have an xattr here
+log_must $PAX -r@ -f $TESTDIR/xattr.pax
+verify_xattr $TESTDIR/pax.$$ passwd /etc/passwd
+log_must $RM $TESTDIR/pax.$$
+
+# we should have no xattr here
+log_must $PAX -r -f $TESTDIR/xattr.pax $TESTDIR
+log_mustnot eval "$RUNAT $TESTDIR/pax.$$ $CAT passwd > /dev/null 2>&1"
+log_must $RM $TESTDIR/pax.$$ $TESTDIR/noxattr.pax $TESTDIR/xattr.pax
+
+
+log_note "Checking tar"
+log_must $TOUCH $TESTDIR/tar.$$
+create_xattr $TESTDIR/tar.$$ passwd /etc/passwd
+
+log_must cd $TESTDIR
+
+log_must $TAR cf noxattr.tar tar.$$
+log_must $TAR c@f xattr.tar tar.$$
+log_must $RM $TESTDIR/tar.$$
+
+# we should have no xattr here
+log_must $TAR xf xattr.tar
+log_mustnot eval "$RUNAT $TESTDIR/tar.$$ $CAT passwd > /dev/null 2>&1"
+log_must $RM $TESTDIR/tar.$$
+
+# we should have an xattr here
+log_must $TAR x@f xattr.tar
+verify_xattr tar.$$ passwd /etc/passwd
+log_must $RM $TESTDIR/tar.$$
+
+# we should have no xattr here
+log_must $TAR xf $TESTDIR/noxattr.tar
+log_mustnot eval "$RUNAT $TESTDIR/tar.$$ $CAT passwd > /dev/null 2>&1"
+log_must $RM $TESTDIR/tar.$$
+
+# we should have no xattr here
+log_must $TAR x@f $TESTDIR/noxattr.tar
+log_mustnot eval "$RUNAT $TESTDIR/tar.$$ $CAT passwd > /dev/null 2>&1"
+log_must $RM $TESTDIR/tar.$$ $TESTDIR/noxattr.tar $TESTDIR/xattr.tar
+
+
+log_assert "Basic applications work with xattrs: cpio cp find mv pax tar"
diff --git a/tests/zfs-tests/tests/functional/xattr/xattr_012_pos.ksh b/tests/zfs-tests/tests/functional/xattr/xattr_012_pos.ksh
new file mode 100755 (executable)
index 0000000..477e155
--- /dev/null
@@ -0,0 +1,103 @@
+#!/bin/ksh -p
+#
+# CDDL HEADER START
+#
+# The contents of this file are subject to the terms of the
+# Common Development and Distribution License (the "License").
+# You may not use this file except in compliance with the License.
+#
+# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
+# or http://www.opensolaris.org/os/licensing.
+# See the License for the specific language governing permissions
+# and limitations under the License.
+#
+# When distributing Covered Code, include this CDDL HEADER in each
+# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
+# If applicable, add the following below this CDDL HEADER, with the
+# fields enclosed by brackets "[]" replaced with your own identifying
+# information: Portions Copyright [yyyy] [name of copyright owner]
+#
+# CDDL HEADER END
+#
+# Copyright 2008 Sun Microsystems, Inc.  All rights reserved.
+# Use is subject to license terms.
+#
+
+#
+# Copyright (c) 2012 by Delphix. All rights reserved.
+#
+
+#
+# Copyright (c) 2013 by Delphix. All rights reserved.
+#
+
+. $STF_SUITE/include/libtest.shlib
+. $STF_SUITE/tests/functional/xattr/xattr_common.kshlib
+
+#
+# DESCRIPTION:
+# xattr file sizes count towards normal disk usage
+#
+# STRATEGY:
+#      1. Create a file, and check pool and filesystem usage
+#       2. Create a 200mb xattr in that file
+#      3. Check pool and filesystem usage, to ensure it reflects the size
+#         of the xattr
+#
+
+function cleanup {
+       log_must $RM $TESTDIR/myfile.$$
+}
+
+function get_pool_size {
+       poolname=$1
+       psize=$($ZPOOL list -H -o allocated $poolname)
+       if [[ $psize == *[mM] ]]
+       then
+               returnvalue=$($ECHO $psize | $SED -e 's/m//g' -e 's/M//g')
+               returnvalue=$((returnvalue * 1024))
+       else
+               returnvalue=$($ECHO $psize | $SED -e 's/k//g' -e 's/K//g')
+       fi
+       echo $returnvalue
+}
+
+log_assert "xattr file sizes count towards normal disk usage"
+log_onexit cleanup
+
+log_must $TOUCH $TESTDIR/myfile.$$
+
+POOL_SIZE=0
+NEW_POOL_SIZE=0
+
+if is_global_zone
+then
+       # get pool and filesystem sizes. Since we're starting with an empty
+       # pool, the usage should be small - a few k.
+       POOL_SIZE=$(get_pool_size $TESTPOOL)
+fi
+
+FS_SIZE=$($ZFS get -p -H -o value used $TESTPOOL/$TESTFS)
+
+log_must $RUNAT $TESTDIR/myfile.$$ $MKFILE 200m xattr
+
+#Make sure the newly created file is counted into zpool usage
+log_must $SYNC
+
+# now check to see if our pool disk usage has increased
+if is_global_zone
+then
+       NEW_POOL_SIZE=$(get_pool_size $TESTPOOL)
+       (($NEW_POOL_SIZE <= $POOL_SIZE)) && \
+           log_fail "The new pool size $NEW_POOL_SIZE was less \
+            than or equal to the old pool size $POOL_SIZE."
+
+fi
+
+# also make sure our filesystem usage has increased
+NEW_FS_SIZE=$($ZFS get -p -H -o value used $TESTPOOL/$TESTFS)
+(($NEW_FS_SIZE <= $FS_SIZE)) && \
+    log_fail "The new filesystem size $NEW_FS_SIZE was less \
+    than or equal to the old filesystem size $FS_SIZE."
+
+log_pass "xattr file sizes count towards normal disk usage"
diff --git a/tests/zfs-tests/tests/functional/xattr/xattr_013_pos.ksh b/tests/zfs-tests/tests/functional/xattr/xattr_013_pos.ksh
new file mode 100755 (executable)
index 0000000..4e9e12e
--- /dev/null
@@ -0,0 +1,88 @@
+#!/bin/ksh -p
+#
+# CDDL HEADER START
+#
+# The contents of this file are subject to the terms of the
+# Common Development and Distribution License (the "License").
+# You may not use this file except in compliance with the License.
+#
+# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
+# or http://www.opensolaris.org/os/licensing.
+# See the License for the specific language governing permissions
+# and limitations under the License.
+#
+# When distributing Covered Code, include this CDDL HEADER in each
+# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
+# If applicable, add the following below this CDDL HEADER, with the
+# fields enclosed by brackets "[]" replaced with your own identifying
+# information: Portions Copyright [yyyy] [name of copyright owner]
+#
+# CDDL HEADER END
+#
+# Copyright 2007 Sun Microsystems, Inc.  All rights reserved.
+# Use is subject to license terms.
+#
+
+#
+# Copyright (c) 2013 by Delphix. All rights reserved.
+#
+
+. $STF_SUITE/include/libtest.shlib
+. $STF_SUITE/tests/functional/xattr/xattr_common.kshlib
+
+#
+# DESCRIPTION:
+# The noxattr mount option functions as expected
+#
+# STRATEGY:
+#      1. Create a file on a filesystem and add an xattr to it
+#      2. Unmount the filesystem, and mount it -o noxattr
+#      3. Verify that the xattr cannot be read and new files
+#         cannot have xattrs set on them.
+#      4. Unmount and mount the filesystem normally
+#      5. Verify that xattrs can be set and accessed again
+#
+
+function cleanup {
+
+       log_must $RM $TESTDIR/myfile.$$
+}
+
+
+log_assert "The noxattr mount option functions as expected"
+log_onexit cleanup
+
+$ZFS set 2>&1 | $GREP xattr > /dev/null
+if [ $? -ne 0 ]
+then
+       log_unsupported "noxattr mount option not supported on this release."
+fi
+
+log_must $TOUCH $TESTDIR/myfile.$$
+create_xattr $TESTDIR/myfile.$$ passwd /etc/passwd
+
+log_must $UMOUNT $TESTDIR
+log_must $ZFS mount -o noxattr $TESTPOOL/$TESTFS
+
+# check that we can't perform xattr operations
+log_mustnot eval "$RUNAT $TESTDIR/myfile.$$ $CAT passwd > /dev/null 2>&1"
+log_mustnot eval "$RUNAT $TESTDIR/myfile.$$ $RM passwd > /dev/null 2>&1"
+log_mustnot eval "$RUNAT $TESTDIR/myfile.$$ $CP /etc/passwd . > /dev/null 2>&1"
+
+log_must $TOUCH $TESTDIR/new.$$
+log_mustnot eval "$RUNAT $TESTDIR/new.$$ $CP /etc/passwd . > /dev/null 2>&1"
+log_mustnot eval "$RUNAT $TESTDIR/new.$$ $RM passwd > /dev/null 2>&1"
+
+# now mount the filesystem again as normal
+log_must $UMOUNT $TESTDIR
+log_must $ZFS mount $TESTPOOL/$TESTFS
+
+# we should still have an xattr on the first file
+verify_xattr $TESTDIR/myfile.$$ passwd /etc/passwd
+
+# there should be no xattr on the file we created while the fs was mounted
+# -o noxattr
+log_mustnot eval "$RUNAT $TESTDIR/new.$$ $CAT passwd > /dev/null 2>&1"
+create_xattr $TESTDIR/new.$$ passwd /etc/passwd
+
+log_pass "The noxattr mount option functions as expected"
diff --git a/tests/zfs-tests/tests/functional/xattr/xattr_common.kshlib b/tests/zfs-tests/tests/functional/xattr/xattr_common.kshlib
new file mode 100644 (file)
index 0000000..d6509a5
--- /dev/null
@@ -0,0 +1,107 @@
+#
+# CDDL HEADER START
+#
+# The contents of this file are subject to the terms of the
+# Common Development and Distribution License (the "License").
+# You may not use this file except in compliance with the License.
+#
+# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
+# or http://www.opensolaris.org/os/licensing.
+# See the License for the specific language governing permissions
+# and limitations under the License.
+#
+# When distributing Covered Code, include this CDDL HEADER in each
+# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
+# If applicable, add the following below this CDDL HEADER, with the
+# fields enclosed by brackets "[]" replaced with your own identifying
+# information: Portions Copyright [yyyy] [name of copyright owner]
+#
+# CDDL HEADER END
+#
+
+#
+# Copyright 2008 Sun Microsystems, Inc.  All rights reserved.
+# Use is subject to license terms.
+#
+
+#
+# Copyright (c) 2013 by Delphix. All rights reserved.
+#
+
+. $STF_SUITE/include/libtest.shlib
+
+# a function that takes a file, then creates and verifies
+# an xattr on that file. The xattr_contents is the file
+# that should appear in the xattr namespace.
+function create_xattr { # filename xattr_name xattr_contents
+       typeset FILE=$1
+       typeset XATTR_NAME=$2
+       typeset XATTR_CONTENTS=$3
+
+       # read any empty xattr on that file
+       log_must $RUNAT $FILE $LS
+       # create the xattr
+       log_must $RUNAT $FILE $CP $XATTR_CONTENTS $XATTR_NAME
+
+       verify_xattr $FILE $XATTR_NAME $XATTR_CONTENTS
+}
+
+# a function that compares the a single xattr between two files
+# and checks to see if their contents are identical
+function compare_xattrs { # filename1 filename2 xattr_name
+       typeset FILE1=$1
+       typeset FILE2=$2
+       typeset XATTR_NAME=$3
+
+       $RUNAT $FILE1 $CAT $XATTR_NAME > /tmp/file1.$$
+       $RUNAT $FILE2 $CAT $XATTR_NAME > /tmp/file2.$$
+
+       log_must $DIFF /tmp/file1.$$ /tmp/file2.$$
+       log_must $RM /tmp/file1.$$ /tmp/file2.$$
+}
+
+function verify_xattr { # filename xattr_name xattr_contents
+       typeset FILE=$1
+       typeset XATTR_NAME=$2
+       typeset XATTR_CONTENTS=$3
+
+       # read the xattr, writing it to a temp file
+       log_must eval "$RUNAT $FILE $CAT $XATTR_NAME > /tmp/$XATTR_NAME.$$ 2>&1"
+       log_must $DIFF $XATTR_CONTENTS /tmp/$XATTR_NAME.$$
+       $RM /tmp/$XATTR_NAME.$$
+}
+
+function delete_xattr { # filename xattr_name
+        typeset FILE=$1
+        typeset XATTR_NAME=$2
+
+        # delete the xattr
+        log_must $RUNAT $FILE $RM $XATTR_NAME
+        log_mustnot eval "$RUNAT $FILE $LS $XATTR_NAME > /dev/null 2>&1"
+}
+
+# not sure about this : really this should be testing write/append
+function verify_write_xattr { # filename xattr_name
+        typeset FILE=$1
+        typeset XATTR_NAME=$2
+
+        log_must eval "$RUNAT $FILE $DD if=/etc/passwd of=$XATTR_NAME"
+        log_must eval "$RUNAT $FILE $CAT $XATTR_NAME > /tmp/$XATTR_NAME.$$ 2>&1"
+        log_must $DD if=/etc/passwd of=/tmp/passwd_dd.$$
+        log_must $DIFF /tmp/passwd_dd.$$ /tmp/$XATTR_NAME.$$
+        log_must $RM /tmp/passwd_dd.$$ /tmp/$XATTR_NAME.$$
+}
+
+# this function is to create the expected output
+function create_expected_output  { # expected_output_file  contents_of_the_output
+   typeset FILE=$1
+   shift
+   if [[ -f $FILE ]]; then
+      log_must $RM $FILE
+   fi
+
+   for line in $@
+   do
+      log_must eval "$ECHO $line >> $FILE"
+   done
+ }
diff --git a/tests/zfs-tests/tests/functional/zvol/Makefile.am b/tests/zfs-tests/tests/functional/zvol/Makefile.am
new file mode 100644 (file)
index 0000000..8aba099
--- /dev/null
@@ -0,0 +1,10 @@
+pkgdatadir = $(datadir)/@PACKAGE@/zfs-tests/tests/functional/zvol
+dist_pkgdata_SCRIPTS = \
+       zvol.cfg \
+       zvol_common.shlib
+
+SUBDIRS = \
+       zvol_ENOSPC \
+       zvol_cli \
+       zvol_misc \
+       zvol_swap
diff --git a/tests/zfs-tests/tests/functional/zvol/zvol.cfg b/tests/zfs-tests/tests/functional/zvol/zvol.cfg
new file mode 100644 (file)
index 0000000..71f3d03
--- /dev/null
@@ -0,0 +1,38 @@
+#
+# CDDL HEADER START
+#
+# The contents of this file are subject to the terms of the
+# Common Development and Distribution License (the "License").
+# You may not use this file except in compliance with the License.
+#
+# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
+# or http://www.opensolaris.org/os/licensing.
+# See the License for the specific language governing permissions
+# and limitations under the License.
+#
+# When distributing Covered Code, include this CDDL HEADER in each
+# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
+# If applicable, add the following below this CDDL HEADER, with the
+# fields enclosed by brackets "[]" replaced with your own identifying
+# information: Portions Copyright [yyyy] [name of copyright owner]
+#
+# CDDL HEADER END
+#
+
+#
+# Copyright 2008 Sun Microsystems, Inc.  All rights reserved.
+# Use is subject to license terms.
+#
+
+#
+# Copyright (c) 2013 by Delphix. All rights reserved.
+#
+
+export DISK=${DISKS%% *}
+
+export TESTVOL=testvol
+export TESTFILE=testfile
+export TESTSNAP=testsnap
+export VOLSIZE=1g
+export DATA=0
+export ENOSPC=28
diff --git a/tests/zfs-tests/tests/functional/zvol/zvol_ENOSPC/Makefile.am b/tests/zfs-tests/tests/functional/zvol/zvol_ENOSPC/Makefile.am
new file mode 100644 (file)
index 0000000..a10023d
--- /dev/null
@@ -0,0 +1,5 @@
+pkgdatadir = $(datadir)/@PACKAGE@/zfs-tests/tests/functional/zvol/zvol_ENOSPC
+dist_pkgdata_SCRIPTS = \
+       cleanup.ksh \
+       setup.ksh \
+       zvol_ENOSPC_001_pos.ksh
diff --git a/tests/zfs-tests/tests/functional/zvol/zvol_ENOSPC/cleanup.ksh b/tests/zfs-tests/tests/functional/zvol/zvol_ENOSPC/cleanup.ksh
new file mode 100755 (executable)
index 0000000..3242298
--- /dev/null
@@ -0,0 +1,44 @@
+#!/bin/ksh -p
+#
+# CDDL HEADER START
+#
+# The contents of this file are subject to the terms of the
+# Common Development and Distribution License (the "License").
+# You may not use this file except in compliance with the License.
+#
+# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
+# or http://www.opensolaris.org/os/licensing.
+# See the License for the specific language governing permissions
+# and limitations under the License.
+#
+# When distributing Covered Code, include this CDDL HEADER in each
+# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
+# If applicable, add the following below this CDDL HEADER, with the
+# fields enclosed by brackets "[]" replaced with your own identifying
+# information: Portions Copyright [yyyy] [name of copyright owner]
+#
+# CDDL HEADER END
+#
+
+#
+# Copyright 2008 Sun Microsystems, Inc.  All rights reserved.
+# Use is subject to license terms.
+#
+
+#
+# Copyright (c) 2013 by Delphix. All rights reserved.
+#
+
+. $STF_SUITE/include/libtest.shlib
+. $STF_SUITE/tests/functional/zvol/zvol_common.shlib
+
+verify_runnable "global"
+
+ismounted $TESTDIR $NEWFS_DEFAULT_FS
+(( $? == 0 )) && log_must $UMOUNT -f $TESTDIR
+
+[[ -e $TESTDIR ]] && $RM -rf $TESTDIR
+
+default_zvol_cleanup
+
+log_pass
diff --git a/tests/zfs-tests/tests/functional/zvol/zvol_ENOSPC/setup.ksh b/tests/zfs-tests/tests/functional/zvol/zvol_ENOSPC/setup.ksh
new file mode 100755 (executable)
index 0000000..9a30a03
--- /dev/null
@@ -0,0 +1,45 @@
+#!/bin/ksh -p
+#
+# CDDL HEADER START
+#
+# The contents of this file are subject to the terms of the
+# Common Development and Distribution License (the "License").
+# You may not use this file except in compliance with the License.
+#
+# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
+# or http://www.opensolaris.org/os/licensing.
+# See the License for the specific language governing permissions
+# and limitations under the License.
+#
+# When distributing Covered Code, include this CDDL HEADER in each
+# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
+# If applicable, add the following below this CDDL HEADER, with the
+# fields enclosed by brackets "[]" replaced with your own identifying
+# information: Portions Copyright [yyyy] [name of copyright owner]
+#
+# CDDL HEADER END
+#
+
+#
+# Copyright 2007 Sun Microsystems, Inc.  All rights reserved.
+# Use is subject to license terms.
+#
+
+#
+# Copyright (c) 2013 by Delphix. All rights reserved.
+#
+
+. $STF_SUITE/include/libtest.shlib
+. $STF_SUITE/tests/functional/zvol/zvol_common.shlib
+
+verify_runnable "global"
+
+default_zvol_setup $DISK $VOLSIZE
+
+$ECHO "y" | $NEWFS -v ${ZVOL_RDEVDIR}/$TESTPOOL/$TESTVOL >/dev/null 2>&1
+(( $? != 0 )) && log_fail "Unable to newfs(1M) $TESTPOOL/$TESTVOL"
+
+log_must $MKDIR $TESTDIR
+log_must $MOUNT ${ZVOL_DEVDIR}/$TESTPOOL/$TESTVOL $TESTDIR
+
+log_pass
diff --git a/tests/zfs-tests/tests/functional/zvol/zvol_ENOSPC/zvol_ENOSPC_001_pos.ksh b/tests/zfs-tests/tests/functional/zvol/zvol_ENOSPC/zvol_ENOSPC_001_pos.ksh
new file mode 100755 (executable)
index 0000000..418ba72
--- /dev/null
@@ -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.
+#
+
+#
+# Copyright (c) 2013 by Delphix. All rights reserved.
+#
+
+. $STF_SUITE/include/libtest.shlib
+. $STF_SUITE/tests/functional/zvol/zvol.cfg
+
+#
+# DESCRIPTION:
+# A zvol volume will return ENOSPC when the underlying pool runs out of
+# space.
+#
+# STRATEGY:
+# 1. Create a pool
+# 2. Create a zvol volume
+# 3. Create a ufs file system ontop of the zvol
+# 4. Mount the ufs file system
+# 5. Fill volume until ENOSPC is returned
+#
+
+verify_runnable "global"
+
+function cleanup
+{
+       $RM -rf $TESTDIR/*
+}
+
+log_assert "A zvol volume will return ENOSPC when the underlying pool " \
+    "runs out of space."
+
+log_onexit cleanup
+
+typeset -i fn=0
+typeset -i retval=0
+
+BLOCKSZ=$(( 1024 * 1024 ))
+NUM_WRITES=40
+
+while (( 1 )); do
+        $FILE_WRITE -o create -f $TESTDIR/testfile$$.$fn \
+            -b $BLOCKSZ -c $NUM_WRITES
+        retval=$?
+        if (( $retval != 0 )); then
+                break
+        fi
+
+        (( fn = fn + 1 ))
+done
+
+(( $retval != $ENOSPC )) &&
+    log_fail "ENOSPC was not returned, $retval was received instead"
+
+log_pass "ENOSPC was returned as expected"
diff --git a/tests/zfs-tests/tests/functional/zvol/zvol_cli/Makefile.am b/tests/zfs-tests/tests/functional/zvol/zvol_cli/Makefile.am
new file mode 100644 (file)
index 0000000..451b8fe
--- /dev/null
@@ -0,0 +1,7 @@
+pkgdatadir = $(datadir)/@PACKAGE@/zfs-tests/tests/functional/zvol/zvol_cli
+dist_pkgdata_SCRIPTS = \
+       cleanup.ksh \
+       setup.ksh \
+       zvol_cli_001_pos.ksh \
+       zvol_cli_002_pos.ksh \
+       zvol_cli_003_neg.ksh
diff --git a/tests/zfs-tests/tests/functional/zvol/zvol_cli/cleanup.ksh b/tests/zfs-tests/tests/functional/zvol/zvol_cli/cleanup.ksh
new file mode 100755 (executable)
index 0000000..79836c2
--- /dev/null
@@ -0,0 +1,39 @@
+#!/bin/ksh -p
+#
+# CDDL HEADER START
+#
+# The contents of this file are subject to the terms of the
+# Common Development and Distribution License (the "License").
+# You may not use this file except in compliance with the License.
+#
+# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
+# or http://www.opensolaris.org/os/licensing.
+# See the License for the specific language governing permissions
+# and limitations under the License.
+#
+# When distributing Covered Code, include this CDDL HEADER in each
+# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
+# If applicable, add the following below this CDDL HEADER, with the
+# fields enclosed by brackets "[]" replaced with your own identifying
+# information: Portions Copyright [yyyy] [name of copyright owner]
+#
+# CDDL HEADER END
+#
+
+#
+# Copyright 2007 Sun Microsystems, Inc.  All rights reserved.
+# Use is subject to license terms.
+#
+
+#
+# Copyright (c) 2013 by Delphix. All rights reserved.
+#
+
+. $STF_SUITE/include/libtest.shlib
+. $STF_SUITE/tests/functional/zvol/zvol_common.shlib
+
+verify_runnable "global"
+
+default_zvol_cleanup
+
+log_pass
diff --git a/tests/zfs-tests/tests/functional/zvol/zvol_cli/setup.ksh b/tests/zfs-tests/tests/functional/zvol/zvol_cli/setup.ksh
new file mode 100755 (executable)
index 0000000..2a62281
--- /dev/null
@@ -0,0 +1,39 @@
+#!/bin/ksh -p
+#
+# CDDL HEADER START
+#
+# The contents of this file are subject to the terms of the
+# Common Development and Distribution License (the "License").
+# You may not use this file except in compliance with the License.
+#
+# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
+# or http://www.opensolaris.org/os/licensing.
+# See the License for the specific language governing permissions
+# and limitations under the License.
+#
+# When distributing Covered Code, include this CDDL HEADER in each
+# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
+# If applicable, add the following below this CDDL HEADER, with the
+# fields enclosed by brackets "[]" replaced with your own identifying
+# information: Portions Copyright [yyyy] [name of copyright owner]
+#
+# CDDL HEADER END
+#
+
+#
+# Copyright 2007 Sun Microsystems, Inc.  All rights reserved.
+# Use is subject to license terms.
+#
+
+#
+# Copyright (c) 2013 by Delphix. All rights reserved.
+#
+
+. $STF_SUITE/include/libtest.shlib
+. $STF_SUITE/tests/functional/zvol/zvol_common.shlib
+
+verify_runnable "global"
+
+default_zvol_setup $DISK $VOLSIZE
+
+log_pass
diff --git a/tests/zfs-tests/tests/functional/zvol/zvol_cli/zvol_cli_001_pos.ksh b/tests/zfs-tests/tests/functional/zvol/zvol_cli/zvol_cli_001_pos.ksh
new file mode 100755 (executable)
index 0000000..4a4c6fb
--- /dev/null
@@ -0,0 +1,63 @@
+#!/bin/ksh -p
+#
+# CDDL HEADER START
+#
+# The contents of this file are subject to the terms of the
+# Common Development and Distribution License (the "License").
+# You may not use this file except in compliance with the License.
+#
+# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
+# or http://www.opensolaris.org/os/licensing.
+# See the License for the specific language governing permissions
+# and limitations under the License.
+#
+# When distributing Covered Code, include this CDDL HEADER in each
+# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
+# If applicable, add the following below this CDDL HEADER, with the
+# fields enclosed by brackets "[]" replaced with your own identifying
+# information: Portions Copyright [yyyy] [name of copyright owner]
+#
+# CDDL HEADER END
+#
+
+#
+# Copyright 2007 Sun Microsystems, Inc.  All rights reserved.
+# Use is subject to license terms.
+#
+
+#
+# Copyright (c) 2013 by Delphix. All rights reserved.
+#
+
+. $STF_SUITE/include/libtest.shlib
+
+#
+# DESCRIPTION:
+# Executing well-formed 'zfs list' commands should return success
+#
+# STRATEGY:
+# 1. Create an array of valid options.
+# 2. Execute each element in the array.
+# 3. Verify success is returned.
+#
+
+verify_runnable "global"
+
+TESTVOL='testvol'
+
+set -A args  "list" "list -r" \
+    "list $TESTPOOL/$TESTVOL" "list -r $TESTPOOL/$TESTVOL"  \
+    "list -H $TESTPOOL/$TESTVOL" "list -Hr $TESTPOOL/$TESTVOL"  \
+    "list -rH $TESTPOOL/$TESTVOL" "list -o name $TESTPOOL/$TESTVOL" \
+    "list -r -o name $TESTPOOL/$TESTVOL" "list -H -o name $TESTPOOL/$TESTVOL" \
+    "list -rH -o name $TESTPOOL/$TESTVOL"
+
+log_assert "Executing well-formed 'zfs list' commands should return success"
+
+typeset -i i=0
+while (( $i < ${#args[*]} )); do
+       log_must eval "$ZFS ${args[i]} > /dev/null"
+       ((i = i + 1))
+done
+
+log_pass "Executing zfs list on volume works as expected"
diff --git a/tests/zfs-tests/tests/functional/zvol/zvol_cli/zvol_cli_002_pos.ksh b/tests/zfs-tests/tests/functional/zvol/zvol_cli/zvol_cli_002_pos.ksh
new file mode 100755 (executable)
index 0000000..65315ed
--- /dev/null
@@ -0,0 +1,62 @@
+#!/bin/ksh -p
+#
+# CDDL HEADER START
+#
+# The contents of this file are subject to the terms of the
+# Common Development and Distribution License (the "License").
+# You may not use this file except in compliance with the License.
+#
+# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
+# or http://www.opensolaris.org/os/licensing.
+# See the License for the specific language governing permissions
+# and limitations under the License.
+#
+# When distributing Covered Code, include this CDDL HEADER in each
+# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
+# If applicable, add the following below this CDDL HEADER, with the
+# fields enclosed by brackets "[]" replaced with your own identifying
+# information: Portions Copyright [yyyy] [name of copyright owner]
+#
+# CDDL HEADER END
+#
+
+#
+# Copyright 2007 Sun Microsystems, Inc.  All rights reserved.
+# Use is subject to license terms.
+#
+
+#
+# Copyright (c) 2013 by Delphix. All rights reserved.
+#
+
+. $STF_SUITE/include/libtest.shlib
+
+#
+# DESCRIPTION:
+# Creating a volume with a 50 letter name should work.
+#
+# STRATEGY:
+# 1. Using a very long name, create a zvol
+# 2. Verify volume exists
+#
+
+verify_runnable "global"
+
+function cleanup
+{
+       datasetexists $TESTPOOL/$LONGVOLNAME && \
+               $ZFS destroy $TESTPOOL/$LONGVOLNAME
+}
+
+log_onexit cleanup
+
+log_assert "Creating a volume a 50 letter name should work."
+
+LONGVOLNAME="volumename50charslong_0123456789012345678901234567"
+
+log_must $ZFS create -V $VOLSIZE $TESTPOOL/$LONGVOLNAME
+
+datasetexists $TESTPOOL/$LONGVOLNAME || \
+       log_fail "Couldn't find long volume name"
+
+log_pass "Created a 50-letter zvol volume name"
diff --git a/tests/zfs-tests/tests/functional/zvol/zvol_cli/zvol_cli_003_neg.ksh b/tests/zfs-tests/tests/functional/zvol/zvol_cli/zvol_cli_003_neg.ksh
new file mode 100755 (executable)
index 0000000..f092e48
--- /dev/null
@@ -0,0 +1,59 @@
+#!/bin/ksh -p
+#
+# CDDL HEADER START
+#
+# The contents of this file are subject to the terms of the
+# Common Development and Distribution License (the "License").
+# You may not use this file except in compliance with the License.
+#
+# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
+# or http://www.opensolaris.org/os/licensing.
+# See the License for the specific language governing permissions
+# and limitations under the License.
+#
+# When distributing Covered Code, include this CDDL HEADER in each
+# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
+# If applicable, add the following below this CDDL HEADER, with the
+# fields enclosed by brackets "[]" replaced with your own identifying
+# information: Portions Copyright [yyyy] [name of copyright owner]
+#
+# CDDL HEADER END
+#
+
+#
+# Copyright 2007 Sun Microsystems, Inc.  All rights reserved.
+# Use is subject to license terms.
+#
+
+#
+# Copyright (c) 2013 by Delphix. All rights reserved.
+#
+
+. $STF_SUITE/include/libtest.shlib
+
+#
+# DESCRIPTION:
+# Try each ZFS volume sub-command without parameters to make sure
+# it returns an error.
+#
+# STRATEGY:
+# 1. Create an array of parameters
+# 2. For each parameter in the array, execute the sub-command
+# 3. Verify an error is returned.
+#
+
+verify_runnable "global"
+
+set -A args "" "create -V" "create -V $TESTPOOL" \
+       "create -V $TESTPOOL/$TESTVOL@" "create -V blah" "destroy"
+
+log_assert "Try each ZFS volume sub-command without parameters to make sure" \
+    " it returns an error."
+
+typeset -i i=0
+while (( $i < ${#args[*]} )); do
+       log_mustnot $ZFS ${args[i]}
+       (( i = i + 1 ))
+done
+
+log_pass "Badly formed ZFS volume sub-commands fail as expected."
diff --git a/tests/zfs-tests/tests/functional/zvol/zvol_common.shlib b/tests/zfs-tests/tests/functional/zvol/zvol_common.shlib
new file mode 100644 (file)
index 0000000..3014979
--- /dev/null
@@ -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 2009 Sun Microsystems, Inc.  All rights reserved.
+# Use is subject to license terms.
+#
+
+#
+# Copyright (c) 2013 by Delphix. All rights reserved.
+#
+
+. $STF_SUITE/include/libtest.shlib
+. $STF_SUITE/tests/functional/zvol/zvol.cfg
+
+#
+# Create a simple zvol volume
+#
+# Where disk_device: is the name of the disk to be used
+#       volume_size: is the size of the volume, e.g. 2G
+#
+function default_zvol_setup # disk_device volume_size
+{
+        typeset disk=$1
+        typeset size=$2
+       typeset savedumpdev
+       typeset -i output
+
+        create_pool $TESTPOOL "$disk"
+
+        log_must $ZFS create -V $size $TESTPOOL/$TESTVOL
+       block_device_wait
+
+       set_dumpsize $TESTPOOL/$TESTVOL
+}
+
+#
+# Destroy the default zvol which was setup using
+# default_zvol_setup().
+#
+function default_zvol_cleanup
+{
+        if datasetexists $TESTPOOL/$TESTVOL ; then
+               log_must $ZFS destroy $TESTPOOL/$TESTVOL
+       fi
+
+        destroy_pool $TESTPOOL
+}
+
+function get_dumpdevice
+{
+       typeset ret=$($DUMPADM | $GREP "Dump device:" | $AWK '{print $3}')
+       echo $ret
+}
+
+function set_dumpsize
+{
+       typeset volume=$1
+
+       if [[ -z $volume ]] ; then
+               log_note "No volume specified."
+               return 1
+       fi
+
+       log_must $ZFS set volsize=64m $volume
+
+       if ! is_linux; then
+               output=$($DUMPADM -d ${ZVOL_DEVDIR}/$volume 2>&1 | \
+                               $TAIL -1 | $AWK '{print $3}')
+
+               if [[ -n $output ]]; then
+                       (( output = output / 1024 / 1024 ))
+                       (( output = output + output / 5 ))
+                       log_must $ZFS set volsize=${output}m $volume
+               fi
+       fi
+
+       return 0
+}
+
+function safe_dumpadm
+{
+       typeset device=$1
+
+       if [[ -z $device || $device == "none" ]] ; then
+               log_note "No dump device volume specified."
+               return 1
+       fi
+       if [[ $device == "${ZVOL_DEVDIR}/"* ]] ; then
+               typeset volume=${device#${ZVOL_DEVDIR}/}
+               set_dumpsize $volume
+               log_must $DUMPADM -d $device
+       else
+               log_must $SWAPADD
+               if ! is_swap_inuse $device ; then
+                       log_must $SWAP -a $device
+               fi
+               log_must $DUMPADM -d swap
+       fi
+}
+
+function is_zvol_dumpified
+{
+       typeset volume=$1
+
+       if [[ -z $volume ]] ; then
+               log_note "No volume specified."
+               return 1
+       fi
+
+       $ZDB -dddd $volume 2 | $GREP "dumpsize" > /dev/null 2>&1
+       return $?
+}
+
+function is_swap_inuse
+{
+       typeset device=$1
+
+       if [[ -z $device ]] ; then
+               log_note "No device specified."
+               return 1
+       fi
+
+       $SWAP -l | $GREP -w $device > /dev/null 2>&1
+       return $?
+}
diff --git a/tests/zfs-tests/tests/functional/zvol/zvol_misc/Makefile.am b/tests/zfs-tests/tests/functional/zvol/zvol_misc/Makefile.am
new file mode 100644 (file)
index 0000000..b52088c
--- /dev/null
@@ -0,0 +1,10 @@
+pkgdatadir = $(datadir)/@PACKAGE@/zfs-tests/tests/functional/zvol/zvol_misc
+dist_pkgdata_SCRIPTS = \
+       cleanup.ksh \
+       setup.ksh \
+       zvol_misc_001_neg.ksh \
+       zvol_misc_002_pos.ksh \
+       zvol_misc_003_neg.ksh \
+       zvol_misc_004_pos.ksh \
+       zvol_misc_005_neg.ksh \
+       zvol_misc_006_pos.ksh
diff --git a/tests/zfs-tests/tests/functional/zvol/zvol_misc/cleanup.ksh b/tests/zfs-tests/tests/functional/zvol/zvol_misc/cleanup.ksh
new file mode 100755 (executable)
index 0000000..79836c2
--- /dev/null
@@ -0,0 +1,39 @@
+#!/bin/ksh -p
+#
+# CDDL HEADER START
+#
+# The contents of this file are subject to the terms of the
+# Common Development and Distribution License (the "License").
+# You may not use this file except in compliance with the License.
+#
+# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
+# or http://www.opensolaris.org/os/licensing.
+# See the License for the specific language governing permissions
+# and limitations under the License.
+#
+# When distributing Covered Code, include this CDDL HEADER in each
+# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
+# If applicable, add the following below this CDDL HEADER, with the
+# fields enclosed by brackets "[]" replaced with your own identifying
+# information: Portions Copyright [yyyy] [name of copyright owner]
+#
+# CDDL HEADER END
+#
+
+#
+# Copyright 2007 Sun Microsystems, Inc.  All rights reserved.
+# Use is subject to license terms.
+#
+
+#
+# Copyright (c) 2013 by Delphix. All rights reserved.
+#
+
+. $STF_SUITE/include/libtest.shlib
+. $STF_SUITE/tests/functional/zvol/zvol_common.shlib
+
+verify_runnable "global"
+
+default_zvol_cleanup
+
+log_pass
diff --git a/tests/zfs-tests/tests/functional/zvol/zvol_misc/setup.ksh b/tests/zfs-tests/tests/functional/zvol/zvol_misc/setup.ksh
new file mode 100755 (executable)
index 0000000..0fb3f1b
--- /dev/null
@@ -0,0 +1,43 @@
+#!/bin/ksh -p
+#
+# CDDL HEADER START
+#
+# The contents of this file are subject to the terms of the
+# Common Development and Distribution License (the "License").
+# You may not use this file except in compliance with the License.
+#
+# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
+# or http://www.opensolaris.org/os/licensing.
+# See the License for the specific language governing permissions
+# and limitations under the License.
+#
+# When distributing Covered Code, include this CDDL HEADER in each
+# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
+# If applicable, add the following below this CDDL HEADER, with the
+# fields enclosed by brackets "[]" replaced with your own identifying
+# information: Portions Copyright [yyyy] [name of copyright owner]
+#
+# CDDL HEADER END
+#
+
+#
+# Copyright 2009 Sun Microsystems, Inc.  All rights reserved.
+# Use is subject to license terms.
+#
+
+#
+# Copyright (c) 2013 by Delphix. All rights reserved.
+#
+
+. $STF_SUITE/include/libtest.shlib
+. $STF_SUITE/tests/functional/zvol/zvol_common.shlib
+
+verify_runnable "global"
+
+if ! $(is_physical_device $DISKS) ; then
+       log_unsupported "This directory cannot be run on raw files."
+fi
+
+default_zvol_setup $DISK $VOLSIZE
+
+log_pass
diff --git a/tests/zfs-tests/tests/functional/zvol/zvol_misc/zvol_misc_001_neg.ksh b/tests/zfs-tests/tests/functional/zvol/zvol_misc/zvol_misc_001_neg.ksh
new file mode 100755 (executable)
index 0000000..9c47451
--- /dev/null
@@ -0,0 +1,64 @@
+#!/bin/ksh -p
+#
+# CDDL HEADER START
+#
+# The contents of this file are subject to the terms of the
+# Common Development and Distribution License (the "License").
+# You may not use this file except in compliance with the License.
+#
+# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
+# or http://www.opensolaris.org/os/licensing.
+# See the License for the specific language governing permissions
+# and limitations under the License.
+#
+# When distributing Covered Code, include this CDDL HEADER in each
+# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
+# If applicable, add the following below this CDDL HEADER, with the
+# fields enclosed by brackets "[]" replaced with your own identifying
+# information: Portions Copyright [yyyy] [name of copyright owner]
+#
+# CDDL HEADER END
+#
+
+#
+# Copyright 2008 Sun Microsystems, Inc.  All rights reserved.
+# Use is subject to license terms.
+#
+
+#
+# Copyright (c) 2013 by Delphix. All rights reserved.
+#
+
+. $STF_SUITE/include/libtest.shlib
+. $STF_SUITE/tests/functional/zvol/zvol_common.shlib
+
+#
+# DESCRIPTION:
+#      Verify that using a zvol as a dump device works.
+#
+# STRATEGY:
+# 1. Create a ZFS volume
+# 2. Use dumpadm add the volume as dump device
+# 3. Verify the return code as expected.
+#
+
+verify_runnable "global"
+
+function cleanup
+{
+       typeset dumpdev=$(get_dumpdevice)
+
+       if [[ $dumpdev != $savedumpdev ]] ; then
+               safe_dumpadm $savedumpdev
+       fi
+}
+
+log_assert "Verify that a ZFS volume can act as dump device."
+log_onexit cleanup
+
+voldev=${ZVOL_DEVDIR}/$TESTPOOL/$TESTVOL
+savedumpdev=$(get_dumpdevice)
+
+safe_dumpadm $voldev
+
+log_pass "Verify that a ZFS volume can act as dump device."
diff --git a/tests/zfs-tests/tests/functional/zvol/zvol_misc/zvol_misc_002_pos.ksh b/tests/zfs-tests/tests/functional/zvol/zvol_misc/zvol_misc_002_pos.ksh
new file mode 100755 (executable)
index 0000000..3a5aa9f
--- /dev/null
@@ -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 2008 Sun Microsystems, Inc.  All rights reserved.
+# Use is subject to license terms.
+#
+
+#
+# Copyright (c) 2013 by Delphix. All rights reserved.
+#
+
+. $STF_SUITE/include/libtest.shlib
+
+#
+# DESCRIPTION:
+# Verify that ZFS volume snapshot could be fscked
+#
+# STRATEGY:
+# 1. Create a ZFS volume
+# 2. Copy some files and create snapshot
+# 3. Verify fsck on the snapshot is OK
+#
+
+verify_runnable "global"
+
+function cleanup
+{
+       snapexists $TESTPOOL/$TESTVOL@snap && \
+               $ZFS destroy $TESTPOOL/$TESTVOL@snap
+
+       ismounted $TESTDIR ufs
+       (( $? == 0 )) && log_must $UMOUNT $TESTDIR
+
+       [[ -e $TESTDIR ]] && $RM -rf $TESTDIR
+}
+
+log_assert "Verify that ZFS volume snapshot could be fscked"
+log_onexit cleanup
+
+TESTVOL='testvol'
+BLOCKSZ=$(( 1024 * 1024 ))
+NUM_WRITES=40
+
+$ECHO "y" | $NEWFS -v ${ZVOL_RDEVDIR}/$TESTPOOL/$TESTVOL >/dev/null 2>&1
+(( $? != 0 )) && log_fail "Unable to newfs(1M) $TESTPOOL/$TESTVOL"
+
+log_must $MKDIR $TESTDIR
+log_must $MOUNT ${ZVOL_DEVDIR}/$TESTPOOL/$TESTVOL $TESTDIR
+
+typeset -i fn=0
+typeset -i retval=0
+
+while (( 1 )); do
+        $FILE_WRITE -o create -f $TESTDIR/testfile$$.$fn \
+            -b $BLOCKSZ -c $NUM_WRITES
+        retval=$?
+        if (( $retval != 0 )); then
+                break
+        fi
+
+        (( fn = fn + 1 ))
+done
+
+log_must $LOCKFS -f $TESTDIR
+log_must $ZFS snapshot $TESTPOOL/$TESTVOL@snap
+
+$FSCK -n ${ZVOL_RDEVDIR}/$TESTPOOL/$TESTVOL@snap >/dev/null 2>&1
+retval=$?
+(( $retval == 39 )) || log_fail "$FSCK exited with wrong value $retval "
+
+log_pass "Verify that ZFS volume snapshot could be fscked"
diff --git a/tests/zfs-tests/tests/functional/zvol/zvol_misc/zvol_misc_003_neg.ksh b/tests/zfs-tests/tests/functional/zvol/zvol_misc/zvol_misc_003_neg.ksh
new file mode 100755 (executable)
index 0000000..04b3014
--- /dev/null
@@ -0,0 +1,75 @@
+#!/bin/ksh -p
+#
+# CDDL HEADER START
+#
+# The contents of this file are subject to the terms of the
+# Common Development and Distribution License (the "License").
+# You may not use this file except in compliance with the License.
+#
+# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
+# or http://www.opensolaris.org/os/licensing.
+# See the License for the specific language governing permissions
+# and limitations under the License.
+#
+# When distributing Covered Code, include this CDDL HEADER in each
+# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
+# If applicable, add the following below this CDDL HEADER, with the
+# fields enclosed by brackets "[]" replaced with your own identifying
+# information: Portions Copyright [yyyy] [name of copyright owner]
+#
+# CDDL HEADER END
+#
+
+#
+# Copyright 2008 Sun Microsystems, Inc.  All rights reserved.
+# Use is subject to license terms.
+#
+
+#
+# Copyright (c) 2013 by Delphix. All rights reserved.
+#
+
+. $STF_SUITE/include/libtest.shlib
+. $STF_SUITE/tests/functional/zvol/zvol_common.shlib
+
+#
+# DESCRIPTION:
+#      Verify creating a storage pool or running newfs on a zvol used as a
+#      dump device is denied.
+#
+# STRATEGY:
+# 1. Create a ZFS volume
+# 2. Use dumpadm to set the volume as dump device
+# 3. Verify creating a pool & running newfs on the zvol returns an error.
+#
+
+verify_runnable "global"
+
+function cleanup
+{
+       typeset dumpdev=$(get_dumpdevice)
+       if [[ $dumpdev != $savedumpdev ]] ; then
+               safe_dumpadm $savedumpdev
+       fi
+
+       if poolexists $TESTPOOL1 ; then
+               destroy_pool $TESTPOOL1
+       fi
+}
+
+log_assert "Verify zpool creation and newfs on dump zvol is denied."
+log_onexit cleanup
+
+voldev=${ZVOL_DEVDIR}/$TESTPOOL/$TESTVOL
+savedumpdev=$(get_dumpdevice)
+
+safe_dumpadm $voldev
+
+$ECHO "y" | $NEWFS -v $voldev > /dev/null 2>&1
+if (( $? == 0 )) ; then
+       log_fail "newfs on dump zvol succeeded unexpectedly"
+fi
+
+log_mustnot $ZPOOL create $TESTPOOL1 $voldev
+
+log_pass "Verify zpool creation and newfs on dump zvol is denied."
diff --git a/tests/zfs-tests/tests/functional/zvol/zvol_misc/zvol_misc_004_pos.ksh b/tests/zfs-tests/tests/functional/zvol/zvol_misc/zvol_misc_004_pos.ksh
new file mode 100755 (executable)
index 0000000..176379e
--- /dev/null
@@ -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 2008 Sun Microsystems, Inc.  All rights reserved.
+# Use is subject to license terms.
+#
+
+#
+# Copyright (c) 2013 by Delphix. All rights reserved.
+#
+
+. $STF_SUITE/include/libtest.shlib
+. $STF_SUITE/tests/functional/zvol/zvol_common.shlib
+
+#
+# DESCRIPTION:
+# Verify the ability to take snapshots of zvols used as dump or swap.
+#
+# STRATEGY:
+# 1. Create a ZFS volume
+# 2. Set the volume as dump or swap
+# 3. Verify creating a snapshot of the zvol succeeds.
+#
+
+verify_runnable "global"
+
+function cleanup
+{
+       typeset dumpdev=$(get_dumpdevice)
+       if [[ $dumpdev != $savedumpdev ]] ; then
+               safe_dumpadm $savedumpdev
+       fi
+
+       $SWAP -l | $GREP -w $voldev > /dev/null 2>&1
+        if (( $? == 0 ));  then
+               log_must $SWAP -d $voldev
+       fi
+
+       typeset snap
+       for snap in snap0 snap1 ; do
+               if datasetexists $TESTPOOL/$TESTVOL@$snap ; then
+                       log_must $ZFS destroy $TESTPOOL/$TESTVOL@$snap
+               fi
+       done
+}
+
+function verify_snapshot
+{
+       typeset volume=$1
+
+       log_must $ZFS snapshot $volume@snap0
+       log_must $ZFS snapshot $volume@snap1
+       log_must datasetexists $volume@snap0 $volume@snap1
+
+       log_must $ZFS destroy $volume@snap1
+       log_must $ZFS snapshot $volume@snap1
+
+       log_mustnot $ZFS rollback -r $volume@snap0
+       log_must datasetexists $volume@snap0
+
+       log_must $ZFS destroy -r $volume@snap0
+}
+
+log_assert "Verify the ability to take snapshots of zvols used as dump or swap."
+log_onexit cleanup
+
+voldev=${ZVOL_DEVDIR}/$TESTPOOL/$TESTVOL
+savedumpdev=$(get_dumpdevice)
+
+# create snapshot over dump zvol
+safe_dumpadm $voldev
+log_must is_zvol_dumpified $TESTPOOL/$TESTVOL
+
+verify_snapshot $TESTPOOL/$TESTVOL
+
+safe_dumpadm $savedumpdev
+log_mustnot is_zvol_dumpified $TESTPOOL/$TESTVOL
+
+# create snapshot over swap zvol
+
+log_must $SWAP -a $voldev
+log_mustnot is_zvol_dumpified $TESTPOOL/$TESTVOL
+
+verify_snapshot $TESTPOOL/$TESTVOL
+
+log_must $SWAP -d $voldev
+log_mustnot is_zvol_dumpified $TESTPOOL/$TESTVOL
+
+log_pass "Creating snapshots from dump/swap zvols succeeds."
diff --git a/tests/zfs-tests/tests/functional/zvol/zvol_misc/zvol_misc_005_neg.ksh b/tests/zfs-tests/tests/functional/zvol/zvol_misc/zvol_misc_005_neg.ksh
new file mode 100755 (executable)
index 0000000..f2cec94
--- /dev/null
@@ -0,0 +1,75 @@
+#!/bin/ksh -p
+#
+# CDDL HEADER START
+#
+# The contents of this file are subject to the terms of the
+# Common Development and Distribution License (the "License").
+# You may not use this file except in compliance with the License.
+#
+# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
+# or http://www.opensolaris.org/os/licensing.
+# See the License for the specific language governing permissions
+# and limitations under the License.
+#
+# When distributing Covered Code, include this CDDL HEADER in each
+# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
+# If applicable, add the following below this CDDL HEADER, with the
+# fields enclosed by brackets "[]" replaced with your own identifying
+# information: Portions Copyright [yyyy] [name of copyright owner]
+#
+# CDDL HEADER END
+#
+
+#
+# Copyright 2008 Sun Microsystems, Inc.  All rights reserved.
+# Use is subject to license terms.
+#
+
+#
+# Copyright (c) 2013 by Delphix. All rights reserved.
+#
+
+. $STF_SUITE/include/libtest.shlib
+. $STF_SUITE/tests/functional/zvol/zvol_common.shlib
+
+#
+# DESCRIPTION:
+#      Verify a device cannot be dump and swap at the same time.
+#
+# STRATEGY:
+# 1. Create a ZFS volume
+# 2. Set it as swap device.
+# 3. Verify dumpadm with this zvol will fail.
+#
+
+verify_runnable "global"
+
+function cleanup
+{
+       $SWAP -l | $GREP $voldev > /dev/null 2>&1
+       if (( $? == 0 )) ; then
+               log_must $SWAP -d $voldev
+       fi
+
+       typeset dumpdev=$(get_dumpdevice)
+       if [[ $dumpdev != $savedumpdev ]] ; then
+               safe_dumpadm $savedumpdev
+       fi
+}
+
+log_assert "Verify a device cannot be dump and swap at the same time."
+log_onexit cleanup
+
+voldev=${ZVOL_DEVDIR}/$TESTPOOL/$TESTVOL
+savedumpdev=$(get_dumpdevice)
+
+# If device in swap list, it cannot be dump device
+log_must $SWAP -a $voldev
+log_mustnot $DUMPADM -d $voldev
+log_must $SWAP -d $voldev
+
+# If device has dedicated as dump device, it cannot add into swap list
+safe_dumpadm $voldev
+log_mustnot $SWAP -a $voldev
+
+log_pass "A device cannot be dump and swap at the same time."
diff --git a/tests/zfs-tests/tests/functional/zvol/zvol_misc/zvol_misc_006_pos.ksh b/tests/zfs-tests/tests/functional/zvol/zvol_misc/zvol_misc_006_pos.ksh
new file mode 100755 (executable)
index 0000000..3b8737f
--- /dev/null
@@ -0,0 +1,72 @@
+#!/bin/ksh -p
+#
+# CDDL HEADER START
+#
+# The contents of this file are subject to the terms of the
+# Common Development and Distribution License (the "License").
+# You may not use this file except in compliance with the License.
+#
+# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
+# or http://www.opensolaris.org/os/licensing.
+# See the License for the specific language governing permissions
+# and limitations under the License.
+#
+# When distributing Covered Code, include this CDDL HEADER in each
+# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
+# If applicable, add the following below this CDDL HEADER, with the
+# fields enclosed by brackets "[]" replaced with your own identifying
+# information: Portions Copyright [yyyy] [name of copyright owner]
+#
+# CDDL HEADER END
+#
+
+#
+# Copyright 2009 Sun Microsystems, Inc.  All rights reserved.
+# Use is subject to license terms.
+#
+
+#
+# Copyright (c) 2013 by Delphix. All rights reserved.
+#
+
+. $STF_SUITE/include/libtest.shlib
+. $STF_SUITE/tests/functional/zvol/zvol_common.shlib
+
+#
+# DESCRIPTION:
+# ZFS volume as dump device, it should always have 128k volblocksize
+#
+# STRATEGY:
+# 1. Create a ZFS volume
+# 2. Use dumpadm set the volume as dump device
+# 3. Verify the volume's volblocksize=128k
+#
+
+verify_runnable "global"
+
+function cleanup
+{
+       typeset dumpdev=$(get_dumpdevice)
+       if [[ $dumpdev != $savedumpdev ]] ; then
+               safe_dumpadm $savedumpdev
+       fi
+}
+
+log_assert "zfs volume as dumpdevice should have 128k volblocksize"
+log_onexit cleanup
+
+voldev=${ZVOL_DEVDIR}/$TESTPOOL/$TESTVOL
+savedumpdev=$(get_dumpdevice)
+
+typeset oblksize=$($ZFS get -H -o value volblocksize $TESTPOOL/$TESTVOL)
+log_note "original $TESTPOOL/$TESTVOL volblocksize=$oblksize"
+
+safe_dumpadm $voldev
+
+typeset blksize=$($ZFS get -H -o value volblocksize $TESTPOOL/$TESTVOL)
+
+if [[ $blksize != "128K" ]]; then
+       log_fail "ZFS volume $TESTPOOL/$TESTVOL volblocksize=$blksize"
+fi
+
+log_pass "zfs volume as dumpdevice should have 128k volblocksize"
diff --git a/tests/zfs-tests/tests/functional/zvol/zvol_swap/Makefile.am b/tests/zfs-tests/tests/functional/zvol/zvol_swap/Makefile.am
new file mode 100644 (file)
index 0000000..7d68d0c
--- /dev/null
@@ -0,0 +1,11 @@
+pkgdatadir = $(datadir)/@PACKAGE@/zfs-tests/tests/functional/zvol/zvol_swap
+dist_pkgdata_SCRIPTS = \
+       zvol_swap.cfg \
+       cleanup.ksh \
+       setup.ksh \
+       zvol_swap_001_pos.ksh \
+       zvol_swap_002_pos.ksh \
+       zvol_swap_003_pos.ksh \
+       zvol_swap_004_pos.ksh \
+       zvol_swap_005_pos.ksh \
+       zvol_swap_006_pos.ksh
diff --git a/tests/zfs-tests/tests/functional/zvol/zvol_swap/cleanup.ksh b/tests/zfs-tests/tests/functional/zvol/zvol_swap/cleanup.ksh
new file mode 100755 (executable)
index 0000000..610bc85
--- /dev/null
@@ -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 2008 Sun Microsystems, Inc.  All rights reserved.
+# Use is subject to license terms.
+#
+
+#
+# Copyright (c) 2013 by Delphix. All rights reserved.
+#
+
+. $STF_SUITE/include/libtest.shlib
+. $STF_SUITE/tests/functional/zvol/zvol_common.shlib
+. $STF_SUITE/tests/functional/zvol/zvol_swap/zvol_swap.cfg
+
+verify_runnable "global"
+
+log_must $SWAPADD
+for swapdev in $SAVESWAPDEVS
+do
+       if ! is_swap_inuse $swapdev ; then
+               log_must $SWAP -a $swapdev >/dev/null 2>&1
+       fi
+done
+
+voldev=${ZVOL_DEVDIR}/$TESTPOOL/$TESTVOL
+if is_swap_inuse $voldev ; then
+       log_must $SWAP -d $voldev
+fi
+
+default_zvol_cleanup
+
+log_pass
diff --git a/tests/zfs-tests/tests/functional/zvol/zvol_swap/setup.ksh b/tests/zfs-tests/tests/functional/zvol/zvol_swap/setup.ksh
new file mode 100755 (executable)
index 0000000..9886bbe
--- /dev/null
@@ -0,0 +1,49 @@
+#!/bin/ksh -p
+#
+# CDDL HEADER START
+#
+# The contents of this file are subject to the terms of the
+# Common Development and Distribution License (the "License").
+# You may not use this file except in compliance with the License.
+#
+# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
+# or http://www.opensolaris.org/os/licensing.
+# See the License for the specific language governing permissions
+# and limitations under the License.
+#
+# When distributing Covered Code, include this CDDL HEADER in each
+# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
+# If applicable, add the following below this CDDL HEADER, with the
+# fields enclosed by brackets "[]" replaced with your own identifying
+# information: Portions Copyright [yyyy] [name of copyright owner]
+#
+# CDDL HEADER END
+#
+
+#
+# Copyright 2007 Sun Microsystems, Inc.  All rights reserved.
+# Use is subject to license terms.
+#
+
+#
+# Copyright (c) 2013 by Delphix. All rights reserved.
+#
+
+. $STF_SUITE/include/libtest.shlib
+. $STF_SUITE/tests/functional/zvol/zvol_common.shlib
+. $STF_SUITE/tests/functional/zvol/zvol_swap/zvol_swap.cfg
+
+verify_runnable "global"
+
+for i in $SAVESWAPDEVS ; do
+       log_note "Executing: swap -d $i"
+       $SWAP -d $i >/dev/null 2>&1
+       if [[ $? != 0 ]]; then
+               log_untested "Unable to delete swap device $i because of" \
+                               "insufficient RAM"
+       fi
+done
+
+default_zvol_setup $DISK $VOLSIZE
+
+log_pass
diff --git a/tests/zfs-tests/tests/functional/zvol/zvol_swap/zvol_swap.cfg b/tests/zfs-tests/tests/functional/zvol/zvol_swap/zvol_swap.cfg
new file mode 100644 (file)
index 0000000..abc31a9
--- /dev/null
@@ -0,0 +1,40 @@
+#
+# CDDL HEADER START
+#
+# The contents of this file are subject to the terms of the
+# Common Development and Distribution License (the "License").
+# You may not use this file except in compliance with the License.
+#
+# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
+# or http://www.opensolaris.org/os/licensing.
+# See the License for the specific language governing permissions
+# and limitations under the License.
+#
+# When distributing Covered Code, include this CDDL HEADER in each
+# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
+# If applicable, add the following below this CDDL HEADER, with the
+# fields enclosed by brackets "[]" replaced with your own identifying
+# information: Portions Copyright [yyyy] [name of copyright owner]
+#
+# CDDL HEADER END
+#
+
+#
+# Copyright 2007 Sun Microsystems, Inc.  All rights reserved.
+# Use is subject to license terms.
+#
+
+#
+# Copyright (c) 2013 by Delphix. All rights reserved.
+#
+
+. $STF_SUITE/tests/functional/zvol/zvol.cfg
+
+#
+# Remember swap devices
+#
+SAVESWAPDEVS=$($SWAP -l | $NAWK '(NR != 1) {print $1}')
+
+export BLOCKSZ=$(( 1024 * 1024 ))
+export NUM_WRITES=40
+export SAVESWAPDEVS
diff --git a/tests/zfs-tests/tests/functional/zvol/zvol_swap/zvol_swap_001_pos.ksh b/tests/zfs-tests/tests/functional/zvol/zvol_swap/zvol_swap_001_pos.ksh
new file mode 100755 (executable)
index 0000000..68d8ebb
--- /dev/null
@@ -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.
+#
+
+#
+# Copyright (c) 2013 by Delphix. All rights reserved.
+#
+
+. $STF_SUITE/include/libtest.shlib
+. $STF_SUITE/tests/functional/zvol/zvol_common.shlib
+. $STF_SUITE/tests/functional/zvol/zvol_swap/zvol_swap.cfg
+
+#
+# DESCRIPTION:
+# Verify that a zvol can be used as a swap device
+#
+# STRATEGY:
+# 1. Create a pool
+# 2. Create a zvol volume
+# 3. Use zvol as swap space
+# 4. Create a file under /tmp
+#
+
+verify_runnable "global"
+
+function cleanup
+{
+       $RM -rf /tmp/$TESTFILE
+
+       if is_swap_inuse $voldev ; then
+               log_must $SWAP -d $voldev
+       fi
+}
+
+log_assert "Verify that a zvol can be used as a swap device"
+
+log_onexit cleanup
+
+voldev=${ZVOL_DEVDIR}/$TESTPOOL/$TESTVOL
+log_note "Add zvol volume as swap space"
+log_must $SWAP -a $voldev
+
+log_note "Create a file under /tmp"
+log_must $FILE_WRITE -o create -f /tmp/$TESTFILE \
+    -b $BLOCKSZ -c $NUM_WRITES -d $DATA
+
+[[ ! -f /tmp/$TESTFILE ]] &&
+    log_fail "Unable to create file under /tmp"
+
+filesize=`$LS -l /tmp/$TESTFILE | $AWK '{print $5}'`
+tf_size=$(( BLOCKSZ * NUM_WRITES ))
+(( $tf_size != $filesize )) &&
+    log_fail "testfile is ($filesize bytes), expected ($tf_size bytes)"
+
+log_pass "Successfully added a zvol to swap area."
diff --git a/tests/zfs-tests/tests/functional/zvol/zvol_swap/zvol_swap_002_pos.ksh b/tests/zfs-tests/tests/functional/zvol/zvol_swap/zvol_swap_002_pos.ksh
new file mode 100755 (executable)
index 0000000..1657be1
--- /dev/null
@@ -0,0 +1,64 @@
+#!/bin/bash
+#
+# CDDL HEADER START
+#
+# The contents of this file are subject to the terms of the
+# Common Development and Distribution License (the "License").
+# You may not use this file except in compliance with the License.
+#
+# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
+# or http://www.opensolaris.org/os/licensing.
+# See the License for the specific language governing permissions
+# and limitations under the License.
+#
+# When distributing Covered Code, include this CDDL HEADER in each
+# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
+# If applicable, add the following below this CDDL HEADER, with the
+# fields enclosed by brackets "[]" replaced with your own identifying
+# information: Portions Copyright [yyyy] [name of copyright owner]
+#
+# CDDL HEADER END
+#
+
+#
+# Copyright 2009 Sun Microsystems, Inc.  All rights reserved.
+# Use is subject to license terms.
+#
+
+#
+# Copyright (c) 2013 by Delphix. All rights reserved.
+#
+
+. $STF_SUITE/include/libtest.shlib
+. $STF_SUITE/tests/functional/zvol/zvol_common.shlib
+
+#
+# DESCRIPTION:
+#      Add a swap zvol, and consume most (not all) of the space. This test
+#      used to fill up swap, which can hang the system.
+#
+# STRATEGY:
+#      1. Create a new zvol and add it as swap
+#      2. Fill /tmp with 80% the size of the zvol
+#      5. Remove the new zvol, and restore original swap devices
+#
+
+verify_runnable "global"
+log_assert "Using a zvol as swap space, fill /tmp to 80%."
+
+vol=$TESTPOOL/$TESTVOL
+swapdev=${ZVOL_DEVDIR}/$vol
+log_must $SWAP -a $swapdev
+
+# Get 80% of the number of 512 blocks in the zvol
+typeset -i count blks volsize=$(get_prop volsize $vol)
+((blks = (volsize / 512) * 80 / 100))
+# Use 'blks' to determine a count for dd based on a 1M block size.
+((count = blks / 2048))
+
+log_note "Fill 80% of swap"
+log_must $DD if=/dev/urandom of=/tmp/$TESTFILE bs=1048576 count=$count
+log_must $RM -f /tmp/$TESTFILE
+log_must $SWAP -d $swapdev
+
+log_pass "Using a zvol as swap space, fill /tmp to 80%."
diff --git a/tests/zfs-tests/tests/functional/zvol/zvol_swap/zvol_swap_003_pos.ksh b/tests/zfs-tests/tests/functional/zvol/zvol_swap/zvol_swap_003_pos.ksh
new file mode 100755 (executable)
index 0000000..0817caa
--- /dev/null
@@ -0,0 +1,96 @@
+#! /bin/ksh -p
+#
+# CDDL HEADER START
+#
+# The contents of this file are subject to the terms of the
+# Common Development and Distribution License (the "License").
+# You may not use this file except in compliance with the License.
+#
+# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
+# or http://www.opensolaris.org/os/licensing.
+# See the License for the specific language governing permissions
+# and limitations under the License.
+#
+# When distributing Covered Code, include this CDDL HEADER in each
+# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
+# If applicable, add the following below this CDDL HEADER, with the
+# fields enclosed by brackets "[]" replaced with your own identifying
+# information: Portions Copyright [yyyy] [name of copyright owner]
+#
+# CDDL HEADER END
+#
+
+#
+# Copyright 2008 Sun Microsystems, Inc.  All rights reserved.
+# Use is subject to license terms.
+#
+
+#
+# Copyright (c) 2013 by Delphix. All rights reserved.
+#
+
+. $STF_SUITE/include/libtest.shlib
+. $STF_SUITE/tests/functional/zvol/zvol_common.shlib
+. $STF_SUITE/tests/functional/zvol/zvol_swap/zvol_swap.cfg
+
+#
+# DESCRIPTION:
+# Verify that a zvol device can be used as a swap device
+# through /etc/vfstab configuration.
+#
+# STRATEGY:
+# 1. Modify /etc/vfstab to add the test zvol as swap device.
+# 2. Use /sbin/swapadd to add zvol as swap device throuth /etc/vfstab
+# 3. Create a file under /tmp and verify the file
+#
+
+verify_runnable "global"
+
+function cleanup
+{
+       [[ -f /tmp/$TESTFILE ]] && log_must $RM -f /tmp/$TESTFILE
+       [[ -f $NEW_VFSTAB_FILE ]] && log_must $RM -f $NEW_VFSTAB_FILE
+       [[ -f $PREV_VFSTAB_FILE ]] && \
+           log_must $MV $PREV_VFSTAB_FILE $VFSTAB_FILE
+       [[ -f $PREV_VFSTAB_FILE ]] && $RM -f $PREV_VFSTAB_FILE
+
+       log_must $SWAPADD $VFSTAB_FILE
+
+        if is_swap_inuse $voldev ; then
+               log_must $SWAP -d $voldev
+       fi
+
+}
+
+log_assert "Verify that a zvol device can be used as a swap device" \
+    "through /etc/vfstab configuration."
+
+log_onexit cleanup
+
+voldev=${ZVOL_DEVDIR}/$TESTPOOL/$TESTVOL
+VFSTAB_FILE=/etc/vfstab
+NEW_VFSTAB_FILE=/var/tmp/zvol_vfstab.$$
+PREV_VFSTAB_FILE=/var/tmp/zvol_vfstab.PREV.$$
+
+[[ -f $NEW_VFSTAB_FILE ]] && $CP /dev/null $NEW_VFSTAB_FILE
+
+$AWK '{if ($4 != "swap") print $1}' /etc/vfstab > $NEW_VFSTAB_FILE
+$ECHO "$voldev\t-\t-\tswap\t-\tno\t-"  >> $NEW_VFSTAB_FILE
+
+# Copy off the original vfstab, and run swapadd on the newly constructed one.
+log_must $CP $VFSTAB_FILE $PREV_VFSTAB_FILE
+log_must $CP $NEW_VFSTAB_FILE $VFSTAB_FILE
+log_must $SWAPADD $VFSTAB_FILE
+
+log_must $FILE_WRITE -o create -f /tmp/$TESTFILE \
+    -b $BLOCKSZ -c $NUM_WRITES -d $DATA
+
+[[ ! -f /tmp/$TESTFILE ]] &&
+    log_fail "Unable to create file under /tmp"
+
+filesize=`$LS -l /tmp/$TESTFILE | $AWK '{print $5}'`
+tf_size=$((BLOCKSZ * NUM_WRITES))
+(($tf_size != $filesize)) && \
+    log_fail "testfile is ($filesize bytes), expected ($tf_size bytes)"
+
+log_pass "Successfully added a zvol to swap area through /etc/vfstab."
diff --git a/tests/zfs-tests/tests/functional/zvol/zvol_swap/zvol_swap_004_pos.ksh b/tests/zfs-tests/tests/functional/zvol/zvol_swap/zvol_swap_004_pos.ksh
new file mode 100755 (executable)
index 0000000..5fc777a
--- /dev/null
@@ -0,0 +1,83 @@
+#!/bin/bash
+#
+# CDDL HEADER START
+#
+# The contents of this file are subject to the terms of the
+# Common Development and Distribution License (the "License").
+# You may not use this file except in compliance with the License.
+#
+# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
+# or http://www.opensolaris.org/os/licensing.
+# See the License for the specific language governing permissions
+# and limitations under the License.
+#
+# When distributing Covered Code, include this CDDL HEADER in each
+# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
+# If applicable, add the following below this CDDL HEADER, with the
+# fields enclosed by brackets "[]" replaced with your own identifying
+# information: Portions Copyright [yyyy] [name of copyright owner]
+#
+# CDDL HEADER END
+#
+
+#
+# Copyright 2007 Sun Microsystems, Inc.  All rights reserved.
+# Use is subject to license terms.
+#
+
+#
+# Copyright (c) 2013 by Delphix. All rights reserved.
+#
+
+. $STF_SUITE/include/libtest.shlib
+
+#
+# DESCRIPTION:
+#      When a swap zvol is added it is resized to be equal to 1/4 c_max,
+#      capped between 2G and 16G.
+#
+# STRATEGY:
+#      1. Determine what 1/4 arc_c_max is.
+#      2. Create a zvols in a variety of sizes.
+#      3. Add them as swap, and verify the volsize is resized correctly.
+#
+
+verify_runnable "global"
+
+log_assert "For an added swap zvol, (2G <= volsize <= 16G)"
+
+typeset -i min max mem
+((mem = $($KSTAT -p ::arcstats:c_max | $AWK '{print $2}') / 4))
+((min = 2 * 1024 * 1024 * 1024))
+((max = 16 * 1024 * 1024 * 1024))
+
+for vbs in 512 1024 2048 4096 8192 16384 32768 65536 131072; do
+       for multiplier in 1 32 16384 131072; do
+               ((volsize = vbs * multiplier))
+               vol="$TESTPOOL/vol_$volsize"
+               swapname="${ZVOL_DEVDIR}/$vol"
+
+               # Create a sparse volume to test larger sizes
+               log_must $ZFS create -s -b $vbs -V $volsize $vol
+               log_must $SWAP -a $swapname
+
+               if ((mem <= min)); then         # volsize should be 2G
+                       new_volsize=$(get_prop volsize $vol)
+                       ((new_volsize == min)) || log_fail \
+                           "Unexpected volsize: $new_volsize"
+               elif ((mem >= max)); then       # volsize should be 16G
+                       new_volsize=$(get_prop volsize $vol)
+                       ((new_volsize == max)) || log_fail \
+                           "Unexpected volsize: $new_volsize"
+               else                            # volsize should be 'mem'
+                       new_volsize=$(get_prop volsize $vol)
+                       ((new_volsize == mem)) || log_fail \
+                           "Unexpected volsize: $new_volsize"
+               fi
+
+               log_must $SWAP -d $swapname
+               log_must $ZFS destroy $vol
+       done
+done
+
+log_pass "For an added swap zvol, (2G <= volsize <= 16G)"
diff --git a/tests/zfs-tests/tests/functional/zvol/zvol_swap/zvol_swap_005_pos.ksh b/tests/zfs-tests/tests/functional/zvol/zvol_swap/zvol_swap_005_pos.ksh
new file mode 100755 (executable)
index 0000000..7710b38
--- /dev/null
@@ -0,0 +1,69 @@
+#!/bin/ksh -p
+#
+# CDDL HEADER START
+#
+# The contents of this file are subject to the terms of the
+# Common Development and Distribution License (the "License").
+# You may not use this file except in compliance with the License.
+#
+# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
+# or http://www.opensolaris.org/os/licensing.
+# See the License for the specific language governing permissions
+# and limitations under the License.
+#
+# When distributing Covered Code, include this CDDL HEADER in each
+# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
+# If applicable, add the following below this CDDL HEADER, with the
+# fields enclosed by brackets "[]" replaced with your own identifying
+# information: Portions Copyright [yyyy] [name of copyright owner]
+#
+# CDDL HEADER END
+#
+
+#
+# Copyright 2008 Sun Microsystems, Inc.  All rights reserved.
+# Use is subject to license terms.
+#
+
+#
+# Copyright (c) 2013 by Delphix. All rights reserved.
+#
+
+. $STF_SUITE/include/libtest.shlib
+. $STF_SUITE/tests/functional/zvol/zvol_common.shlib
+
+#
+# DESCRIPTION:
+#      swaplow + swaplen must be less than or equal to the volume size.
+#
+# STRATEGY:
+#      1. Get test system page size and test volume size.
+#      2. Random get swaplow and swaplen.
+#      3. Verify swap -a should succeed when swaplow + swaplen <= volume size.
+#
+
+verify_runnable "global"
+
+assertion="Verify the sum of swaplow and swaplen is less or equal to volsize"
+log_assert $assertion
+
+typeset vol=$TESTPOOL/$TESTVOL
+typeset swapname="${ZVOL_DEVDIR}/$vol"
+typeset -i pageblocks volblocks max_swaplow
+#
+# Both swaplow and swaplen are the desired length of
+# the swap area in 512-byte blocks.
+#
+((pageblocks = $($PAGESIZE) / 512))
+((volblocks = $(get_prop volsize $vol) / 512))
+((max_swaplow = (volblocks - (pageblocks * 2))))
+
+for i in {0..10}; do
+       swaplow=$($SHUF -n 1 -i ${pageblocks}-${max_swaplow})
+       ((maxlen = max_swaplow - swaplow))
+       swaplen=$($SHUF -n 1 -i ${pageblocks}-${maxlen})
+       log_must $SWAP -a $swapname $swaplow $swaplen
+       log_must $SWAP -d $swapname $swaplow
+done
+
+log_pass $assertion
diff --git a/tests/zfs-tests/tests/functional/zvol/zvol_swap/zvol_swap_006_pos.ksh b/tests/zfs-tests/tests/functional/zvol/zvol_swap/zvol_swap_006_pos.ksh
new file mode 100755 (executable)
index 0000000..fcbbefc
--- /dev/null
@@ -0,0 +1,108 @@
+#!/bin/ksh -p
+#
+# CDDL HEADER START
+#
+# The contents of this file are subject to the terms of the
+# Common Development and Distribution License (the "License").
+# You may not use this file except in compliance with the License.
+#
+# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
+# or http://www.opensolaris.org/os/licensing.
+# See the License for the specific language governing permissions
+# and limitations under the License.
+#
+# When distributing Covered Code, include this CDDL HEADER in each
+# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
+# If applicable, add the following below this CDDL HEADER, with the
+# fields enclosed by brackets "[]" replaced with your own identifying
+# information: Portions Copyright [yyyy] [name of copyright owner]
+#
+# CDDL HEADER END
+#
+
+#
+# Copyright 2008 Sun Microsystems, Inc.  All rights reserved.
+# Use is subject to license terms.
+#
+
+#
+# Copyright (c) 2013 by Delphix. All rights reserved.
+#
+
+. $STF_SUITE/include/libtest.shlib
+. $STF_SUITE/tests/functional/zvol/zvol_common.shlib
+
+#
+# DESCRIPTION:
+#      A volume can be added as several segments, but overlapping segments
+#      are not allowed.
+#
+# STRATEGY:
+#      1. Figure out three groups swaplow and swaplen.
+#      2. Verify different volume segments can be added correctly.
+#      3. Verify overlapping swap volume are not allowed.
+#
+
+verify_runnable "global"
+
+function cleanup
+{
+       typeset -i i=0
+
+       while ((count > 0)); do
+               log_must $SWAP -d $swapname ${swap_opt[$i]}
+
+               ((i += 2))
+               ((count -= 1))
+       done
+}
+
+log_assert "Verify volume can be add as several segments, but overlapping " \
+       "are not allowed."
+log_onexit cleanup
+
+# swap -a won't allow the use of multiple segments of the same volume unless
+# libdiskmgmt is disabled with the environment variable below.
+typeset -x NOINUSE_CHECK=1
+
+typeset vol=$TESTPOOL/$TESTVOL
+typeset -i pageblocks volblocks
+((pageblocks = $($PAGESIZE) / 512))
+((volblocks = $(get_prop volsize $vol) / 512))
+
+log_note "Verify volume can be add as several segments."
+
+#
+#              swaplow                 swaplen
+set -A swap_opt        $((pageblocks))     \
+               $((pageblocks * ((RANDOM % 50) + 1) + (RANDOM % pageblocks) )) \
+               $((volblocks / 3))  \
+               $((pageblocks * ((RANDOM % 50) + 1) + (RANDOM % pageblocks) )) \
+               $((volblocks / 2))  \
+               $((pageblocks * ((RANDOM % 50) + 1) + (RANDOM % pageblocks) )) \
+               $(((volblocks*2) / 3))  \
+               $((pageblocks * ((RANDOM % 50) + 1) + (RANDOM % pageblocks) ))
+
+swapname=${ZVOL_DEVDIR}/$vol
+typeset -i i=0 count=0
+
+if is_swap_inuse $swapname ; then
+       log_must $SWAP -d $swapname
+fi
+
+while ((i < ${#swap_opt[@]})); do
+       log_must $SWAP -a $swapname ${swap_opt[$i]} ${swap_opt[((i+1))]}
+
+       ((i += 2))
+       ((count += 1))
+done
+
+log_note "Verify overlapping swap volume are not allowed"
+i=0
+while ((i < ${#swap_opt[@]})); do
+       log_mustnot $SWAP -a $swapname ${swap_opt[$i]}
+
+       ((i += 2))
+done
+
+log_pass "Verify volume can be added as several segments passed."
diff --git a/tests/zfs-tests/tests/stress/Makefile.am b/tests/zfs-tests/tests/stress/Makefile.am
new file mode 100644 (file)
index 0000000..e69de29
index 10d24f027f2f3725c624e3124a33fbe257715b21..51871b5455c44a9dfcbcad835fe9fc5773698923 100644 (file)
@@ -1,54 +1,79 @@
-#!/bin/bash
+export KERNELSRC=@LINUX@
+export KERNELBUILD=@LINUX_OBJ@
+export KERNELSRCVER=@LINUX_VERSION@
+export KERNELMOD=/lib/modules/${KERNELSRCVER}/kernel
 
-KERNELSRC=@LINUX@
-KERNELBUILD=@LINUX_OBJ@
-KERNELSRCVER=@LINUX_VERSION@
-KERNELMOD=/lib/modules/${KERNELSRCVER}/kernel
+export SPLSRC=@SPL@
+export SPLBUILD=@SPL_OBJ@
+export SPLSRCVER=@SPL_VERSION@
 
-SPLSRC=@SPL@
-SPLBUILD=@SPL_OBJ@
-SPLSRCVER=@SPL_VERSION@
+export SRCDIR=@abs_top_srcdir@
+export BUILDDIR=@abs_top_builddir@
+export LIBDIR=${BUILDDIR}/lib
+export CMDDIR=${BUILDDIR}/cmd
+export MODDIR=${BUILDDIR}/module
+export SCRIPTDIR=${BUILDDIR}/scripts
+export ZPOOLDIR=${BUILDDIR}/scripts/zpool-config
+export ZPIOSDIR=${BUILDDIR}/scripts/zpios-test
+export ZPIOSPROFILEDIR=${BUILDDIR}/scripts/zpios-profile
+export ETCDIR=${SRCDIR}/etc
+export TESTSDIR=${SRCDIR}/tests
+export RUNFILEDIR=${TESTSDIR}/runfiles
 
-SRCDIR=@abs_top_srcdir@
-BUILDDIR=@abs_top_builddir@
-LIBDIR=${BUILDDIR}/lib
-CMDDIR=${BUILDDIR}/cmd
-MODDIR=${BUILDDIR}/module
-SCRIPTDIR=${BUILDDIR}/scripts
-ZPOOLDIR=${BUILDDIR}/scripts/zpool-config
-ZPIOSDIR=${BUILDDIR}/scripts/zpios-test
-ZPIOSPROFILEDIR=${BUILDDIR}/scripts/zpios-profile
-ETCDIR=${SRCDIR}/etc
+export ZDB=${CMDDIR}/zdb/zdb
+export ZFS=${CMDDIR}/zfs/zfs
+export ZINJECT=${CMDDIR}/zinject/zinject
+export ZPOOL=${CMDDIR}/zpool/zpool
+export ZTEST=${CMDDIR}/ztest/ztest
+export ZPIOS=${CMDDIR}/zpios/zpios
 
-ZDB=${CMDDIR}/zdb/zdb
-ZFS=${CMDDIR}/zfs/zfs
-ZINJECT=${CMDDIR}/zinject/zinject
-ZPOOL=${CMDDIR}/zpool/zpool
-ZTEST=${CMDDIR}/ztest/ztest
-ZPIOS=${CMDDIR}/zpios/zpios
+export COMMON_SH=${SCRIPTDIR}/common.sh
+export ZFS_SH=${SCRIPTDIR}/zfs.sh
+export ZPOOL_CREATE_SH=${SCRIPTDIR}/zpool-create.sh
+export ZPIOS_SH=${SCRIPTDIR}/zpios.sh
+export ZPIOS_SURVEY_SH=${SCRIPTDIR}/zpios-survey.sh
 
-COMMON_SH=${SCRIPTDIR}/common.sh
-ZFS_SH=${SCRIPTDIR}/zfs.sh
-ZPOOL_CREATE_SH=${SCRIPTDIR}/zpool-create.sh
-ZPIOS_SH=${SCRIPTDIR}/zpios.sh
-ZPIOS_SURVEY_SH=${SCRIPTDIR}/zpios-survey.sh
+# Test Suite Specific Commands
+export TEST_RUNNER=${TESTSDIR}/test-runner/cmd/test-runner.py
+export STF_TOOLS=${TESTSDIR}/test-runner
+export STF_SUITE=${TESTSDIR}/zfs-tests
 
-INTREE=1
-LDMOD=/sbin/insmod
+export CHG_USR_EXEC=${TESTSDIR}/zfs-tests/cmd/chg_usr_exec/chg_usr_exec
+export DEVNAME2DEVID=${TESTSDIR}/zfs-tests/cmd/devname2devid/devname2devid
+export DIR_RD_UPDATE=${TESTSDIR}/zfs-tests/cmd/dir_rd_update/dir_rd_update
+export FILE_CHECK=${TESTSDIR}/zfs-tests/cmd/file_check/file_check
+export FILE_TRUNC=${TESTSDIR}/zfs-tests/cmd/file_trunc/file_trunc
+export FILE_WRITE=${TESTSDIR}/zfs-tests/cmd/file_write/file_write
+export LARGEST_FILE=${TESTSDIR}/zfs-tests/cmd/largest_file/largest_file
+export MKBUSY=${TESTSDIR}/zfs-tests/cmd/mkbusy/mkbusy
+export MKFILE=${TESTSDIR}/zfs-tests/cmd/mkfile/mkfile
+export MKFILES=${TESTSDIR}/zfs-tests/cmd/mkfile/mkfiles
+export MKTREE=${TESTSDIR}/zfs-tests/cmd/mktree/mktree
+export MMAP_EXEC=${TESTSDIR}/zfs-tests/cmd/mmap_exec/mmap_exec
+export MMAPWRITE=${TESTSDIR}/zfs-tests/cmd/mmapwrite/mmapwrite
+export RANDFREE_FILE=${TESTSDIR}/zfs-tests/cmd/randfree_file/randfree_file
+export READMMAP=${TESTSDIR}/zfs-tests/cmd/readmmap/readmmap
+export RENAME_DIR=${TESTSDIR}/zfs-tests/cmd/rename_dir/rename_dir
+export RM_LNKCNT_ZERO_FILE=${TESTSDIR}/zfs-tests/cmd/rm_lnkcnt_zero_file/rm_lnkcnt_zero_file
+export THREADSAPPEND=${TESTSDIR}/zfs-tests/cmd/threadsappend/threadsappend
+export XATTRTEST=${TESTDIR}/zfs-tests/cmd/xattrtest
 
-ZED_PIDFILE=@runstatedir@/zed.pid
+export INTREE=1
+export LDMOD=/sbin/insmod
 
-KERNEL_MODULES=(                                      \
+export ZED_PIDFILE=@runstatedir@/zed.pid
+
+export KERNEL_MODULES=(                               \
         ${KERNELMOD}/lib/zlib_deflate/zlib_deflate.ko \
         ${KERNELMOD}/lib/zlib_inflate/zlib_inflate.ko \
 )
 
-SPL_MODULES=(                                         \
+export SPL_MODULES=(                                  \
         ${SPLBUILD}/module/spl/spl.ko                 \
         ${SPLBUILD}/module/splat/splat.ko             \
 )
 
-ZFS_MODULES=(                                         \
+export ZFS_MODULES=(                                  \
         ${MODDIR}/avl/zavl.ko                         \
         ${MODDIR}/nvpair/znvpair.ko                   \
         ${MODDIR}/unicode/zunicode.ko                 \
@@ -56,11 +81,11 @@ ZFS_MODULES=(                                         \
         ${MODDIR}/zfs/zfs.ko                          \
 )
 
-ZPIOS_MODULES=(                                       \
+export ZPIOS_MODULES=(                                \
         ${MODDIR}/zpios/zpios.ko                      \
 )
 
-MODULES=(                                             \
+export MODULES=(                                      \
         ${SPL_MODULES[*]}                             \
         ${ZFS_MODULES[*]}                             \
 )