1 #! /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) 2012 by Delphix. All rights reserved.
  30 #
  31 
  32 . $STF_SUITE/include/libtest.shlib
  33 . $STF_SUITE/tests/functional/cli_root/zpool_expand/zpool_expand.cfg
  34 
  35 #
  36 # DESCRIPTION:
  37 # vdev retains asize when 2nd last mirror child is removed while autoexpand=off
  38 #
  39 #
  40 # STRATEGY:
  41 # 1) Create a pool
  42 # 2) Create different sized volumes on top of the pool
  43 # 3) Create pool with autoepand=off using the zvols in a 2-way mirror
  44 # 4) Detach the smaller of the 2 vdev's from the mirror 
  45 # 5) Ensure that smaller vdev can be re-attached
  46 # 6) Detach the smaller vdev again to ensure no expand at import 
  47 # 7) Export pool
  48 # 8) Import pool 
  49 # 9) Check that the pool size has not expanded
  50 # 10) Ensure that smaller vdev can be re-attached
  51 #
  52 
  53 verify_runnable "global"
  54 
  55 function cleanup
  56 {
  57         if poolexists $TESTPOOL1; then
  58                 log_must $ZPOOL destroy $TESTPOOL1
  59         fi
  60 
  61         for i in 1 2; do
  62                 if datasetexists $VFS/vol$i; then
  63                         log_must $ZFS destroy $VFS/vol$i
  64                 fi
  65         done
  66 }
  67 
  68 log_onexit cleanup
  69 
  70 log_assert "vdev retains asize when 2nd last mirror child is removed while" \
  71     "autoexpand=off"
  72 
  73 log_must $ZFS create -V $org_size $VFS/vol1
  74 log_must $ZFS create -V $exp_size $VFS/vol2
  75 
  76 log_must $ZPOOL create -f -o autoexpand=off $TESTPOOL1 mirror \
  77     /dev/zvol/dsk/$VFS/vol1  /dev/zvol/dsk/$VFS/vol2
  78 
  79 typeset autoexp=$(get_pool_prop autoexpand $TESTPOOL1)
  80 if [[ $autoexp != "off" ]]; then
  81         log_fail "zpool $TESTPOOL1 autoexpand should off but is $autoexp"
  82 fi
  83 
  84 typeset prev_size=$(get_pool_prop size $TESTPOOL1)
  85 typeset zfs_prev_size=$($ZFS get -p avail $TESTPOOL1 | $TAIL -1 | \
  86     $AWK '{print $3}')
  87 
  88 log_must $ZPOOL detach $TESTPOOL1 /dev/zvol/dsk/$VFS/vol1 
  89 
  90 $SYNC
  91 $SLEEP 10
  92 $SYNC
  93 
  94 log_must $ZPOOL attach $TESTPOOL1 /dev/zvol/dsk/$VFS/vol2 \
  95     /dev/zvol/dsk/$VFS/vol1
  96 
  97 log_must $ZPOOL detach $TESTPOOL1 /dev/zvol/dsk/$VFS/vol1 
  98 
  99 log_must $ZPOOL export $TESTPOOL1
 100 
 101 log_must $ZPOOL import -d /dev/zvol/dsk/$VFS $TESTPOOL1
 102 
 103 typeset post_size=$(get_pool_prop size $TESTPOOL1)
 104 typeset zfs_post_size=$($ZFS get -p avail $TESTPOOL1 | $TAIL -1 | \
 105     $AWK '{print $3}')
 106 
 107 log_note "$TESTPOOL1 mirror had previous size: $prev_size and " \
 108     "after detach has size: $post_size"
 109 # compare available pool size from zfs
 110 if [[ $zfs_post_size > $zfs_prev_size ]]; then
 111         log_fail "pool $TESTPOOL1 has autoexpanded with " \
 112             "autoexpand=off when smaller mirror child removed"
 113 fi
 114 
 115 log_must $ZPOOL attach $TESTPOOL1 /dev/zvol/dsk/$VFS/vol2 /dev/zvol/dsk/$VFS/vol1 
 116 
 117 log_must $ZPOOL destroy $TESTPOOL1
 118 
 119 log_pass "pool $TESTPOOL1 retained size after smaller child" \
 120     "was removed from mirror with autoexpand=off"