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

/tests/sys/cddl/zfs/tests/cli_root/zpool_import/zpool_import_corrupt_001_pos.ksh

https://bitbucket.org/freebsd/freebsd-base
Korn Shell | 130 lines | 50 code | 18 blank | 62 comment | 6 complexity | 7ecbd0ec9a9f31e8b2a1c6aac3634783 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. # $FreeBSD$
  23. #
  24. # Copyright 2013 Spectra Logic All rights reserved.
  25. # Use is subject to license terms.
  26. #
  27. . $STF_SUITE/include/libtest.kshlib
  28. #################################################################################
  29. #
  30. # __stc_assertion_start
  31. #
  32. # ID: zpool_import_014_pos
  33. #
  34. # DESCRIPTION:
  35. # Verify that a disk-backed exported pool with some of its vdev labels
  36. # corrupted can still be imported
  37. # STRATEGY:
  38. # 1. Create a disk-backed pool
  39. # 2. Export it
  40. # 3. Overwrite one or more of its vdev labels
  41. # 4. Use zdb to verify that the labels are damaged
  42. # 5. Verify 'zpool import' can import it
  43. #
  44. # TESTABILITY: explicit
  45. #
  46. # TEST_AUTOMATION_LEVEL: automated
  47. #
  48. # CODING_STATUS: COMPLETED (2013-03-15)
  49. #
  50. # __stc_assertion_end
  51. #
  52. ################################################################################
  53. verify_runnable "global"
  54. # ZFS has four vdev labels per vdev
  55. typeset -i N_VDEV_LABELS=4
  56. # Size of a single label, in bytes
  57. typeset -i VDEV_LABEL_SIZE=$(( 256 * 1024))
  58. #
  59. # The authoritative version of this calculation can be found in the function of
  60. # the same name in vdev_label.c. The rounding of psize is based on the
  61. # calculation in vdev_disk_read_rootlabel in vdev_disk.c
  62. #
  63. # arg1: vdev size in bytes
  64. # arg2: label index, 0 through 3
  65. #
  66. function vdev_label_offset
  67. {
  68. typeset -il psize=$1
  69. typeset -i l=$2
  70. typeset -il offset
  71. typeset -il roundsize
  72. roundsize=$(( $psize & -$VDEV_LABEL_SIZE ))
  73. if [[ $l -lt $(( N_VDEV_LABELS / 2 )) ]]; then
  74. offset=$(( l * $VDEV_LABEL_SIZE))
  75. else
  76. offset=$(( l * $VDEV_LABEL_SIZE + $roundsize - $N_VDEV_LABELS * $VDEV_LABEL_SIZE ))
  77. fi
  78. echo $offset
  79. }
  80. log_assert "Verify that a disk-backed exported pool with some of its vdev labels corrupted can still be imported"
  81. typeset -i i
  82. typeset -i j
  83. set -A DISKS_ARRAY $DISKS
  84. typeset DISK=${DISKS_ARRAY[0]}
  85. typeset PROV=${DISK#/dev/}
  86. typeset -il psize=$(geom disk list $PROV | awk '/Mediasize/ {print $2}')
  87. if [[ -z $psize ]]; then
  88. log_fail "Could not determine the capacity of $DISK"
  89. fi
  90. for ((i=0; $i<$N_VDEV_LABELS; i=$i+1 )); do
  91. log_must $ZPOOL create -f $TESTPOOL $DISK
  92. log_must $ZPOOL export $TESTPOOL
  93. # Corrupt all labels except the ith
  94. for ((j=0; $j<$N_VDEV_LABELS; j=$j+1 )); do
  95. typeset -il offset
  96. [[ $i -eq $j ]] && continue
  97. log_note offset=vdev_label_offset $psize $j
  98. offset=$(vdev_label_offset $psize $j)
  99. log_must $DD if=/dev/zero of=$DISK bs=1024 \
  100. count=$(( $VDEV_LABEL_SIZE / 1024 )) \
  101. oseek=$(( $offset / 1024 )) \
  102. conv=notrunc
  103. done
  104. typeset -i num_labels=$( $ZDB -l $DISK | $GREP pool_guid | wc -l )
  105. if [[ $num_labels -ne 1 ]]; then
  106. $ZDB -l $DISK
  107. log_fail "Expected 1 vdev label but found $num_labels"
  108. fi
  109. log_must $ZPOOL import $TESTPOOL
  110. destroy_pool $TESTPOOL
  111. done
  112. log_pass