PageRenderTime 57ms CodeModel.GetById 23ms RepoModel.GetById 0ms app.codeStats 0ms

/tests/zfs-tests/tests/functional/replacement/replacement_003_pos.ksh

http://github.com/zfsonlinux/zfs
Korn Shell | 161 lines | 84 code | 39 blank | 38 comment | 17 complexity | 18b8f8e9708a086635e98cbcc40f6680 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 2008 Sun Microsystems, Inc. All rights reserved.
  24. # Use is subject to license terms.
  25. #
  26. #
  27. # Copyright (c) 2013, 2016 by Delphix. All rights reserved.
  28. #
  29. . $STF_SUITE/include/libtest.shlib
  30. . $STF_SUITE/tests/functional/replacement/replacement.cfg
  31. #
  32. # DESCRIPTION:
  33. # Detaching disks during I/O should pass for supported pools.
  34. #
  35. # STRATEGY:
  36. # 1. Create multidisk pools (stripe/mirror/raidz) and
  37. # start some random I/O
  38. # 2. Detach a disk from the pool.
  39. # 3. Verify the integrity of the file system and the resilvering.
  40. #
  41. verify_runnable "global"
  42. function cleanup
  43. {
  44. if [[ -n "$child_pids" ]]; then
  45. for wait_pid in $child_pids
  46. do
  47. kill $wait_pid
  48. done
  49. fi
  50. if poolexists $TESTPOOL1; then
  51. destroy_pool $TESTPOOL1
  52. fi
  53. [[ -e $TESTDIR ]] && log_must rm -rf $TESTDIR/*
  54. }
  55. log_assert "Replacing a disk during I/O completes."
  56. options=""
  57. options_display="default options"
  58. log_onexit cleanup
  59. [[ -n "$HOLES_FILESIZE" ]] && options=" $options -f $HOLES_FILESIZE "
  60. [[ -n "$HOLES_BLKSIZE" ]] && options="$options -b $HOLES_BLKSIZE "
  61. [[ -n "$HOLES_COUNT" ]] && options="$options -c $HOLES_COUNT "
  62. [[ -n "$HOLES_SEED" ]] && options="$options -s $HOLES_SEED "
  63. [[ -n "$HOLES_FILEOFFSET" ]] && options="$options -o $HOLES_FILEOFFSET "
  64. ptions="$options -r "
  65. [[ -n "$options" ]] && options_display=$options
  66. child_pids=""
  67. function detach_test
  68. {
  69. typeset -i iters=2
  70. typeset -i index=0
  71. typeset disk1=$1
  72. typeset i=0
  73. while [[ $i -lt $iters ]]; do
  74. log_note "Invoking file_trunc with: $options_display"
  75. file_trunc $options $TESTDIR/$TESTFILE.$i &
  76. typeset pid=$!
  77. sleep 1
  78. child_pids="$child_pids $pid"
  79. ((i = i + 1))
  80. done
  81. log_must zpool detach $TESTPOOL1 $disk1
  82. sleep 10
  83. for wait_pid in $child_pids
  84. do
  85. kill $wait_pid
  86. done
  87. child_pids=""
  88. log_must zpool export $TESTPOOL1
  89. log_must zpool import -d $TESTDIR $TESTPOOL1
  90. log_must zfs umount $TESTPOOL1/$TESTFS1
  91. log_must zdb -cdui $TESTPOOL1/$TESTFS1
  92. log_must zfs mount $TESTPOOL1/$TESTFS1
  93. }
  94. specials_list=""
  95. i=0
  96. while [[ $i != 2 ]]; do
  97. mkfile $MINVDEVSIZE $TESTDIR/$TESTFILE1.$i
  98. specials_list="$specials_list $TESTDIR/$TESTFILE1.$i"
  99. ((i = i + 1))
  100. done
  101. create_pool $TESTPOOL1 mirror $specials_list
  102. log_must zfs create $TESTPOOL1/$TESTFS1
  103. log_must zfs set mountpoint=$TESTDIR1 $TESTPOOL1/$TESTFS1
  104. detach_test $TESTDIR/$TESTFILE1.1
  105. zpool iostat -v $TESTPOOL1 | grep "$TESTDIR/$TESTFILE1.1"
  106. if [[ $? -eq 0 ]]; then
  107. log_fail "$TESTFILE1.1 should no longer be present."
  108. fi
  109. destroy_pool $TESTPOOL1
  110. log_note "Verify 'zpool detach' fails with non-mirrors."
  111. for type in "" "raidz" "raidz1" ; do
  112. create_pool $TESTPOOL1 $type $specials_list
  113. log_must zfs create $TESTPOOL1/$TESTFS1
  114. log_must zfs set mountpoint=$TESTDIR1 $TESTPOOL1/$TESTFS1
  115. log_mustnot zpool detach $TESTDIR/$TESTFILE1.1
  116. zpool iostat -v $TESTPOOL1 | grep "$TESTDIR/$TESTFILE1.1"
  117. if [[ $? -ne 0 ]]; then
  118. log_fail "$TESTFILE1.1 is not present."
  119. fi
  120. destroy_pool $TESTPOOL1
  121. done
  122. log_pass