1 #!/bin/ksh -p
   2 #
   3 # CDDL HEADER START
   4 #
   5 # This file and its contents are supplied under the terms of the
   6 # Common Development and Distribution License ("CDDL"), version 1.0.
   7 # You may only use this file in accordance with the terms of version
   8 # 1.0 of the CDDL.
   9 #
  10 # A full copy of the text of the CDDL should have accompanied this
  11 # source.  A copy of the CDDL is also available via the Internet at
  12 # http://www.illumos.org/license/CDDL.
  13 #
  14 # CDDL HEADER END
  15 #
  16 
  17 #
  18 # Copyright (c) 2017 by Delphix. All rights reserved.
  19 #
  20 
  21 . $STF_SUITE/include/libtest.shlib
  22 . $STF_SUITE/tests/functional/cli_root/zfs_mount/zfs_mount.kshlib
  23 
  24 # DESCRIPTION:
  25 #       Verify that if 'zfs mount -a' fails to mount one filesystem,
  26 #       the command fails with a non-zero error code, but all other
  27 #       filesystems are mounted.
  28 #
  29 # STRATEGY:
  30 #       1. Create zfs filesystems
  31 #       2. Unmount a leaf filesystem
  32 #       3. Create a file in the above filesystem's mountpoint
  33 #       4. Verify that 'zfs mount -a' fails to mount the above
  34 #       5. Verify that all other filesystems were mounted
  35 #
  36 
  37 verify_runnable "both"
  38 
  39 typeset -a filesystems
  40 typeset path=${TEST_BASE_DIR%%/}/testroot$$/$TESTPOOL
  41 typeset fscount=10
  42 
  43 function setup_all
  44 {
  45         # Create $fscount filesystems at the top level of $path
  46         for ((i=0; i<$fscount; i++)); do
  47                 setup_filesystem "$DISKS" "$TESTPOOL" $i "$path/$i" ctr
  48         done
  49 
  50         zfs list -r $TESTPOOL
  51 
  52         return 0
  53 }
  54 
  55 function cleanup_all
  56 {
  57         export __ZFS_POOL_RESTRICT="$TESTPOOL"
  58         log_must zfs $unmountall
  59         unset __ZFS_POOL_RESTRICT
  60 
  61         [[ -d ${TEST_BASE_DIR%%/}/testroot$$ ]] && \
  62                 rm -rf ${TEST_BASE_DIR%%/}/testroot$$
  63 }
  64 
  65 log_onexit cleanup_all
  66 
  67 log_must setup_all
  68 
  69 #
  70 # Unmount all of the above so that we can create the stray file
  71 # in one of the mountpoint directories.
  72 #
  73 export __ZFS_POOL_RESTRICT="$TESTPOOL"
  74 log_must zfs $unmountall
  75 unset __ZFS_POOL_RESTRICT
  76 
  77 # All of our filesystems should be unmounted at this point
  78 for ((i=0; i<$fscount; i++)); do
  79         log_mustnot mounted "$TESTPOOL/$i"
  80 done
  81 
  82 # Create a stray file in one filesystem's mountpoint
  83 touch $path/0/strayfile
  84 
  85 # Verify that zfs mount -a fails
  86 export __ZFS_POOL_RESTRICT="$TESTPOOL"
  87 log_mustnot zfs $mountall
  88 unset __ZFS_POOL_RESTRICT
  89 
  90 # All filesystems except for "0" should be mounted
  91 log_mustnot mounted "$TESTPOOL/0"
  92 for ((i=1; i<$fscount; i++)); do
  93         log_must mounted "$TESTPOOL/$i"
  94 done
  95 
  96 log_pass "'zfs $mountall' failed as expected."