PageRenderTime 47ms CodeModel.GetById 19ms RepoModel.GetById 0ms app.codeStats 0ms

/tests/zfs-tests/tests/functional/cli_root/zpool_expand/zpool_expand_001_pos.ksh

http://github.com/zfsonlinux/zfs
Korn Shell | 167 lines | 86 code | 27 blank | 54 comment | 13 complexity | 79000111dad4f6056d5dc03e01d8bbea MD5 | raw file
Possible License(s): Apache-2.0, MPL-2.0-no-copyleft-exception
  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. # Copyright 2009 Sun Microsystems, Inc. All rights reserved.
  24. # Use is subject to license terms.
  25. #
  26. #
  27. # Copyright (c) 2012, 2016 by Delphix. All rights reserved.
  28. # Copyright (c) 2018 by Lawrence Livermore National Security, LLC.
  29. #
  30. . $STF_SUITE/include/libtest.shlib
  31. . $STF_SUITE/tests/functional/cli_root/zpool_expand/zpool_expand.cfg
  32. #
  33. # DESCRIPTION:
  34. # Once zpool set autoexpand=on poolname, zpool can autoexpand by
  35. # Dynamic VDEV Expansion
  36. #
  37. #
  38. # STRATEGY:
  39. # 1) Create three vdevs (loopback, scsi_debug, and file)
  40. # 2) Create pool by using the different devices and set autoexpand=on
  41. # 3) Expand each device as appropriate
  42. # 4) Check that the pool size was expanded
  43. #
  44. # NOTE: Three different device types are used in this test to verify
  45. # expansion of non-partitioned block devices (loopback), partitioned
  46. # block devices (scsi_debug), and non-disk file vdevs. ZFS volumes
  47. # are not used in order to avoid a possible lock inversion when
  48. # layering pools on zvols.
  49. #
  50. verify_runnable "global"
  51. function cleanup
  52. {
  53. poolexists $TESTPOOL1 && destroy_pool $TESTPOOL1
  54. if losetup -a | grep -q $DEV1; then
  55. losetup -d $DEV1
  56. fi
  57. rm -f $FILE_LO $FILE_RAW
  58. block_device_wait
  59. unload_scsi_debug
  60. }
  61. log_onexit cleanup
  62. log_assert "zpool can be autoexpanded after set autoexpand=on on vdev expansion"
  63. for type in " " mirror raidz raidz2; do
  64. log_note "Setting up loopback, scsi_debug, and file vdevs"
  65. log_must truncate -s $org_size $FILE_LO
  66. DEV1=$(losetup -f)
  67. log_must losetup $DEV1 $FILE_LO
  68. load_scsi_debug $org_size_mb 1 1 1 '512b'
  69. block_device_wait
  70. DEV2=$(get_debug_device)
  71. log_must truncate -s $org_size $FILE_RAW
  72. DEV3=$FILE_RAW
  73. # The -f is required since we're mixing disk and file vdevs.
  74. log_must zpool create -f -o autoexpand=on $TESTPOOL1 $type \
  75. $DEV1 $DEV2 $DEV3
  76. typeset autoexp=$(get_pool_prop autoexpand $TESTPOOL1)
  77. if [[ $autoexp != "on" ]]; then
  78. log_fail "zpool $TESTPOOL1 autoexpand should be on but is " \
  79. "$autoexp"
  80. fi
  81. typeset prev_size=$(get_pool_prop size $TESTPOOL1)
  82. typeset zfs_prev_size=$(get_prop avail $TESTPOOL1)
  83. # Expand each device as appropriate being careful to add an artificial
  84. # delay to ensure we get a single history entry for each. This makes
  85. # is easier to verify each expansion for the striped pool case, since
  86. # they will not be merged in to a single larger expansion.
  87. log_note "Expanding loopback, scsi_debug, and file vdevs"
  88. log_must truncate -s $exp_size $FILE_LO
  89. log_must losetup -c $DEV1
  90. sleep 3
  91. echo "2" > /sys/bus/pseudo/drivers/scsi_debug/virtual_gb
  92. echo "1" > /sys/class/block/$DEV2/device/rescan
  93. block_device_wait
  94. sleep 3
  95. log_must truncate -s $exp_size $FILE_RAW
  96. log_must zpool online -e $TESTPOOL1 $FILE_RAW
  97. typeset expand_size=$(get_pool_prop size $TESTPOOL1)
  98. typeset zfs_expand_size=$(get_prop avail $TESTPOOL1)
  99. log_note "$TESTPOOL1 $type has previous size: $prev_size and " \
  100. "expanded size: $expand_size"
  101. # compare available pool size from zfs
  102. if [[ $zfs_expand_size -gt $zfs_prev_size ]]; then
  103. # check for zpool history for the pool size expansion
  104. if [[ $type == " " ]]; then
  105. typeset expansion_size=$(($exp_size-$org_size))
  106. typeset size_addition=$(zpool history -il $TESTPOOL1 |\
  107. grep "pool '$TESTPOOL1' size:" | \
  108. grep "vdev online" | \
  109. grep "(+${expansion_size}" | wc -l)
  110. if [[ $size_addition -ne 3 ]]; then
  111. log_fail "pool $TESTPOOL1 has not expanded, " \
  112. "$size_addition/3 vdevs expanded"
  113. fi
  114. elif [[ $type == "mirror" ]]; then
  115. typeset expansion_size=$(($exp_size-$org_size))
  116. zpool history -il $TESTPOOL1 | \
  117. grep "pool '$TESTPOOL1' size:" | \
  118. grep "vdev online" | \
  119. grep "(+${expansion_size})" >/dev/null 2>&1
  120. if [[ $? -ne 0 ]] ; then
  121. log_fail "pool $TESTPOOL1 has not expanded"
  122. fi
  123. else
  124. typeset expansion_size=$((3*($exp_size-$org_size)))
  125. zpool history -il $TESTPOOL1 | \
  126. grep "pool '$TESTPOOL1' size:" | \
  127. grep "vdev online" | \
  128. grep "(+${expansion_size})" >/dev/null 2>&1
  129. if [[ $? -ne 0 ]]; then
  130. log_fail "pool $TESTPOOL has not expanded"
  131. fi
  132. fi
  133. else
  134. log_fail "pool $TESTPOOL1 is not autoexpanded after vdev " \
  135. "expansion. Previous size: $zfs_prev_size and expanded " \
  136. "size: $zfs_expand_size"
  137. fi
  138. cleanup
  139. done
  140. log_pass "zpool can autoexpand if autoexpand=on after vdev expansion"