PageRenderTime 49ms CodeModel.GetById 16ms RepoModel.GetById 0ms app.codeStats 0ms

/tests/sys/cddl/zfs/tests/zfsd/zfsd_replace_003_pos.ksh

https://bitbucket.org/freebsd/freebsd-base
Korn Shell | 125 lines | 64 code | 15 blank | 46 comment | 19 complexity | 531b76dbb142de801138dd3956d570ee MD5 | raw file
  1. #!/usr/local/bin/ksh93 -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. # Copyright 2012,2013 Spectra Logic Corporation. All rights reserved.
  27. # Use is subject to license terms.
  28. #
  29. # Portions taken from:
  30. # ident "@(#)replacement_001_pos.ksh 1.4 08/02/27 SMI"
  31. #
  32. # $FreeBSD$
  33. . $STF_SUITE/include/libtest.kshlib
  34. . $STF_SUITE/include/libgnop.kshlib
  35. . $STF_SUITE/tests/hotspare/hotspare.kshlib
  36. . $STF_SUITE/tests/zfsd/zfsd.kshlib
  37. function cleanup
  38. {
  39. destroy_pool $TESTPOOL
  40. [[ -e $TESTDIR ]] && log_must $RM -rf $TESTDIR/*
  41. for md in $MD0 $MD1 $MD2 $MD3; do
  42. gnop destroy -f $md
  43. for ((i=0; i<5; i=i+1)); do
  44. $MDCONFIG -d -u $md && break
  45. $SLEEP 1
  46. done
  47. done
  48. }
  49. log_assert "ZFSD will correctly replace disks that disappear and reappear \
  50. with different devnames"
  51. # Outline
  52. # Use gnop on top of file-backed md devices
  53. # * file-backed md devices so we can destroy them and recreate them with
  54. # different devnames
  55. # * gnop so we can destroy them while still in use
  56. # Create a double-parity pool
  57. # Remove two vdevs
  58. # Destroy the md devices and recreate in the opposite order
  59. # Check that the md's devnames have swapped
  60. # Verify that the pool regains its health
  61. log_onexit cleanup
  62. ensure_zfsd_running
  63. N_DEVARRAY_FILES=4
  64. set_devs
  65. typeset FILE0="${devarray[0]}"
  66. typeset FILE1="${devarray[1]}"
  67. typeset FILE2="${devarray[2]}"
  68. typeset FILE3="${devarray[3]}"
  69. typeset MD0=`$MDCONFIG -a -t vnode -f ${FILE0}`
  70. [ $? -eq 0 ] || atf_fail "Failed to create md device"
  71. typeset MD1=`$MDCONFIG -a -t vnode -f ${FILE1}`
  72. [ $? -eq 0 ] || atf_fail "Failed to create md device"
  73. typeset MD2=`$MDCONFIG -a -t vnode -f ${FILE2}`
  74. [ $? -eq 0 ] || atf_fail "Failed to create md device"
  75. typeset MD3=`$MDCONFIG -a -t vnode -f ${FILE3}`
  76. [ $? -eq 0 ] || atf_fail "Failed to create md device"
  77. log_must create_gnops $MD0 $MD1 $MD2 $MD3
  78. for type in "raidz2" "mirror"; do
  79. # Create a pool on the supplied disks
  80. create_pool $TESTPOOL $type ${MD0}.nop ${MD1}.nop ${MD2}.nop ${MD3}.nop
  81. log_must destroy_gnop $MD0
  82. for ((i=0; i<5; i=i+1)); do
  83. $MDCONFIG -d -u $MD0 && break
  84. $SLEEP 1
  85. done
  86. [ -c /dev/$MD0.nop ] && atf_fail "failed to destroy $MD0"
  87. log_must destroy_gnop $MD1
  88. for ((i=0; i<5; i=i+1)); do
  89. $MDCONFIG -d -u $MD1 && break
  90. $SLEEP 1
  91. done
  92. [ -c /dev/$MD1.nop ] && atf_fail "failed to destroy $MD0"
  93. # Make sure that the pool is degraded
  94. $ZPOOL status $TESTPOOL |grep "state:" |grep DEGRADED > /dev/null
  95. if [ $? != 0 ]; then
  96. log_fail "Pool $TESTPOOL not listed as DEGRADED"
  97. fi
  98. # Do some I/O to ensure that the old vdevs will be out of date
  99. log_must $DD if=/dev/random of=/$TESTPOOL/randfile bs=1m count=1
  100. log_must $SYNC
  101. # Recreate the vdevs in the opposite order
  102. typeset MD0=`$MDCONFIG -a -t vnode -f ${FILE1}`
  103. [ $? -eq 0 ] || atf_fail "Failed to create md device"
  104. typeset MD1=`$MDCONFIG -a -t vnode -f ${FILE0}`
  105. [ $? -eq 0 ] || atf_fail "Failed to create md device"
  106. log_must create_gnops $MD0 $MD1
  107. wait_until_resilvered
  108. destroy_pool $TESTPOOL
  109. done
  110. log_pass