1 #!/usr/bin/ksh -p
   2 #
   3 # CDDL HEADER START
   4 #
   5 # The contents of this file are subject to the terms of the
   6 # Common Development and Distribution License (the "License").
   7 # You may not use this file except in compliance with the License.
   8 #
   9 # You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
  10 # or http://www.opensolaris.org/os/licensing.
  11 # See the License for the specific language governing permissions
  12 # and limitations under the License.
  13 #
  14 # When distributing Covered Code, include this CDDL HEADER in each
  15 # file and include the License file at usr/src/OPENSOLARIS.LICENSE.
  16 # If applicable, add the following below this CDDL HEADER, with the
  17 # fields enclosed by brackets "[]" replaced with your own identifying
  18 # information: Portions Copyright [yyyy] [name of copyright owner]
  19 #
  20 # CDDL HEADER END
  21 #
  22 
  23 #
  24 # Copyright 2009 Sun Microsystems, Inc.  All rights reserved.
  25 # Use is subject to license terms.
  26 #
  27 
  28 #
  29 # Copyright (c) 2013 by Delphix. All rights reserved.
  30 #
  31 
  32 . $STF_SUITE/include/libtest.shlib
  33 . $STF_SUITE/tests/functional/online_offline/online_offline.cfg
  34 
  35 #
  36 # DESCRIPTION:
  37 #       Turning both disks offline should fail.
  38 #
  39 # STRATEGY:
  40 #       1. Create a mirror and start some random I/O
  41 #       2. For each disk in the mirror, set them offline sequentially.
  42 #       3. Only one disk can be offline at any one time.
  43 #       4. Verify the integrity of the file system and the resilvering.
  44 #
  45 
  46 verify_runnable "global"
  47 
  48 DISKLIST=$(get_disklist $TESTPOOL)
  49 
  50 function cleanup
  51 {
  52         if [[ -n "$child_pids" ]]; then
  53                 for wait_pid in $child_pids
  54                 do
  55                         $KILL $wait_pid
  56                 done
  57         fi
  58 
  59         #
  60         # Ensure we don't leave disks in the offline state
  61         #
  62         for disk in $DISKLIST; do
  63                 log_must $ZPOOL online $TESTPOOL $disk
  64                 check_state $TESTPOOL $disk "online"
  65                 if [[ $? != 0 ]]; then
  66                         log_fail "Unable to online $disk"
  67                 fi
  68 
  69         done
  70 
  71         [[ -e $TESTDIR ]] && log_must $RM -rf $TESTDIR/*
  72 }
  73 
  74 log_assert "Turning both disks offline should fail."
  75 
  76 options=""
  77 options_display="default options"
  78 
  79 log_onexit cleanup
  80 
  81 [[ -n "$HOLES_FILESIZE" ]] && options=" $options -f $HOLES_FILESIZE "
  82 
  83 [[ -n "$HOLES_BLKSIZE" ]] && options="$options -b $HOLES_BLKSIZE "
  84 
  85 [[ -n "$HOLES_COUNT" ]] && options="$options -c $HOLES_COUNT "
  86 
  87 [[ -n "$HOLES_SEED" ]] && options="$options -s $HOLES_SEED "
  88 
  89 [[ -n "$HOLES_FILEOFFSET" ]] && options="$options -o $HOLES_FILEOFFSET "
  90 
  91 options="$options -r "
  92 
  93 [[ -n "$options" ]] && options_display=$options
  94 
  95 child_pid=""
  96 
  97 typeset -i iters=2
  98 typeset -i index=0
  99 
 100 i=0
 101 while [[ $i -lt $iters ]]; do
 102         log_note "Invoking $FILE_TRUNC with: $options_display"
 103         $FILE_TRUNC $options $TESTDIR/$TESTFILE.$i &
 104         typeset pid=$!
 105 
 106         $SLEEP 1
 107         if ! $PS -p $pid > /dev/null 2>&1; then
 108                 log_fail "$FILE_TRUNC $options $TESTDIR/$TESTFILE.$i"
 109         fi
 110 
 111         child_pids="$child_pids $pid"
 112         ((i = i + 1))
 113 done
 114 
 115 set -A disk "" $DISKLIST
 116 
 117 log_must $ZPOOL offline $TESTPOOL ${disk[1]}
 118 
 119 $SLEEP 60
 120 
 121 for wait_pid in $child_pids
 122 do
 123         $KILL $wait_pid
 124 done
 125 child_pids=""
 126 
 127 i=1
 128 while [[ $i != ${#disk[*]} ]]; do
 129         log_must $ZPOOL online $TESTPOOL ${disk[$i]}
 130         check_state $TESTPOOL ${disk[$i]} "online"
 131         if [[ $? != 0 ]]; then
 132                 log_fail "${disk[$i]} of $TESTPOOL did not match online state"
 133         fi
 134 
 135         ((i = i + 1))
 136 done
 137 
 138 typeset dir=$(get_device_dir $DISKS)
 139 verify_filesys "$TESTPOOL" "$TESTPOOL/$TESTFS" "$dir"
 140 
 141 log_pass