NoPaste

zfstest

von king-crash

SNIPPET_TEXT:
  1. #!/bin/sh
  2.  
  3. deleteimage () {
  4.         if [ ! -b "$ZFSDEVICE" ]
  5.         then
  6.                 rm $ZFSDEVICE
  7.                 sleep 1
  8.         fi
  9. }
  10.  
  11. destroypool () {
  12.         zpool destroy zfstest
  13.         rmdir /zfstest
  14.         deleteimage
  15. }
  16.  
  17. print_corruption () {
  18.         sleep 1
  19.         zpool status zfstest
  20.         zpool status zfstest | grep -i corruption > /dev/null
  21.         if [ $? -eq 0 ]
  22.         then
  23.                 echo "zfs detected corruption"
  24.                 RET=1
  25.         else
  26.                 echo "zfs detected no corruption"
  27.                 RET=0
  28.         fi
  29.         return $RET
  30. }
  31.  
  32. empty () {
  33.         sleep 0
  34. }
  35.  
  36.  
  37. if [ "$#" -ne 1 ]
  38. then
  39.         echo "Usage: $0 device"
  40. fi
  41. ZFSDEVICE="$1"
  42.  
  43. RED='\033[0;31m'
  44. GREEN='\033[0;32m'
  45. NC='\033[0m'
  46.  
  47. set -e
  48. modprobe -v zfs
  49. if [ ! -b "$ZFSDEVICE" ]
  50. then
  51.         truncate -s 1G $ZFSDEVICE
  52. fi
  53. trap deleteimage EXIT
  54. #set -o xtrace
  55. zpool create -f -m /zfstest zfstest `readlink -f $ZFSDEVICE`
  56. trap destroypool EXIT
  57. dd if=/dev/zero of=/zfstest/testfile bs=1M count=800 2> /dev/null
  58. SUM_A=`shasum /zfstest/testfile`
  59. echo "$SUM_A"
  60. set +e
  61. print_corruption
  62. set -e
  63. echo "corrupting filesystem"
  64. echo -n -e '\x34' | dd of=$ZFSDEVICE seek=290000003 bs=1 conv=notrunc 2> /dev/null
  65. #./disktest $ZFSDEVICE 34 290000003
  66. sync
  67. echo 3 > /proc/sys/vm/drop_caches
  68.  
  69. echo "trying to read a file from corrupted filesysten with shasum"
  70. set +e
  71. SUM_B=`shasum /zfstest/testfile`
  72. echo "$SUM_B"
  73. print_corruption
  74. CORRUPTED=$?
  75. set -e
  76. if [ "$SUM_A" != "$SUM_B" ]
  77. then
  78.         echo "corrupted $CORRUPTED"
  79.         if [ $CORRUPTED -eq 0 ]
  80.         then
  81.                 echo "${RED}the pool is silently corrupted${NC}"
  82.                 trap empty EXIT
  83.                 exit 0
  84.         else
  85.                 echo "${GREEN}zfs detected the corruption${NC}"
  86.         fi
  87. else
  88.         echo "no corruption in file"
  89. fi

Quellcode

Hier kannst du den Code kopieren und ihn in deinen bevorzugten Editor einfügen. PASTEBIN_DOWNLOAD_SNIPPET_EXPLAIN