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.         set +e
  19.         zpool status zfstest | grep -i corruption > /dev/null
  20.         if [ $? -eq 0 ]
  21.         then
  22.                 echo "zfs detected corruption"
  23.                 RET=1
  24.         else
  25.                 echo "zfs detected no corruption"
  26.                 RET=0
  27.         fi
  28.         set -e
  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. print_corruption
  61. echo "corrupting filesystem"
  62. echo -n -e '\x34' | dd of=$ZFSDEVICE seek=290000003 bs=1 conv=notrunc 2> /dev/null
  63. #./disktest $ZFSDEVICE 34 290000003
  64. sync
  65. echo 3 > /proc/sys/vm/drop_caches
  66.  
  67. echo "trying to read a file from corrupted filesysten with shasum"
  68. set +e
  69. SUM_B=`shasum /zfstest/testfile`
  70. echo "$SUM_B"
  71. set -e
  72. print_corruption
  73. CORRUPTED=$?
  74. if [ "$SUM_A" != "$SUM_B" ]
  75. then
  76.         if [ $CORRUPTED -eq 0 ]
  77.         then
  78.                 echo "${RED}the pool is silently corrupted${NC}"
  79.                 trap empty EXIT
  80.                 exit 0
  81.         else
  82.                 echo "${RED}zfs detected the corruption${NC}"
  83.         fi
  84. else
  85.         echo "no corruption in file"
  86. fi

Quellcode

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