coraid-update 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. #! /bin/sh
  2. # usage: coraid-update {update file} {AoE target}
  3. # coraid-update depends upon sysfs mounted on /sys
  4. # The destination must be,
  5. # 1) an AoE target ready for I/O, and
  6. # 2) not too big to be an update target
  7. #
  8. # Later, when CORAID appliances mark update targets with special ATA
  9. # device identify content or special target content, a prompt should
  10. # be added after the check of the target's size if the identifying
  11. # content is not detected.
  12. #
  13. # The update file must either,
  14. # 1) be an SR tarc file that looks OK to the local tar, or
  15. # 2) any file not ending in ".tarc".
  16. # size of update LUN in /proc/partitions is 40000
  17. max=70000
  18. usage="usage: coraid-update {update file} {AoE device}"
  19. if test "$#" != 2; then
  20. echo "$usage" 1>&2
  21. exit 1
  22. fi
  23. update="$1"
  24. ulb="$2"
  25. # if it's an update target, it should be in `aoe-stat`
  26. aoe-stat | awk -vt="`basename $ulb`" '
  27. BEGIN{fail=1}
  28. $1==t{fail=0}
  29. END{exit fail}' || {
  30. exec 1>&2
  31. echo "coraid-update Error: \"$ulb\" is not an AoE target"
  32. echo "$usage"
  33. exit 1
  34. }
  35. # it should have a size no larger than $max in /proc/partitions
  36. t="`echo $ulb | sed 's!^/dev/!!'`"
  37. awk -vt="$t" '$NF==t{print $3}' /proc/partitions |
  38. awk -vhi=$max -vdev="$ulb" '
  39. BEGIN{
  40. err = "could not get size of " dev
  41. } {
  42. err = "none"
  43. if ($1 > hi) {
  44. err = dev " is too large to be an update target"
  45. exit
  46. }
  47. } END{
  48. if (err != "none") {
  49. print "Error coraid-update: " err > "/dev/stderr"
  50. exit 1
  51. }
  52. exit 0
  53. }' || exit 1
  54. # this test should be removed when it is performed on the appliance
  55. #
  56. # For a 2734080-byte tarc file, an incomplete file of 2727450 bytes passes
  57. # this test, but one of 2727400 does not. So this test isn't fullproof.
  58. #
  59. if test "`echo \"$update\" | grep '\.tarc$'`"; then
  60. tar tf "$update" > /dev/null 2>&1 || {
  61. exec 1>&2
  62. echo "coraid-update Error: \"$update\" does not appear to be a valid tarc file"
  63. exit 1
  64. }
  65. fi
  66. if test ! -r "$update"; then
  67. echo "coraid-update Error: \"$update\" is not readable" 1>&2
  68. exit 1
  69. fi
  70. # send it over and complain on error
  71. if ! dd if="$update" of="$ulb" 2> /dev/null || ! sync; then
  72. exec 1>&2
  73. echo "coraid-update Error: could not successfully write \"$update\" to \"$ulb\""
  74. exit 1
  75. fi