aoe-flush.in 991 B

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. #! /bin/sh
  2. # aoe-flush - ask aoe driver to forget about devices
  3. # Copyright 2009, CORAID, Inc., and licensed under GPL v.2.
  4. zero="`basename $0`"
  5. f="@devdir@/flush"
  6. spec=""
  7. if ! test -w "$f"; then
  8. echo 1>&2 "$zero: $f does not exist or is not writeable."
  9. exit 1
  10. fi
  11. if ! test -c $f; then
  12. exec 1>&2
  13. echo "$zero: $f is not a character device file"
  14. echo "$zero: use udev or aoe-mkdevs to create it"
  15. exit 1
  16. fi
  17. # make sure that each device in the whitespace-separated
  18. # list exists
  19. verify_devs () {
  20. err=""
  21. for d; do
  22. aoe-stat |
  23. awk -vd="$d" '$1==d{print $1}' |
  24. test "`cat`" || {
  25. exec 2>&1
  26. echo "$zero Error: \"$d\" is not an aoe device"
  27. err="$err $d"
  28. }
  29. done
  30. test ! "$err"
  31. }
  32. err=""
  33. if test "$1"; then
  34. if test "$1" = "-a"; then
  35. spec=all
  36. else
  37. spec="$*"
  38. verify_devs $spec || exit 1
  39. fi
  40. for i in $spec; do
  41. printf "$i" > "$f" || {
  42. echo 1>&2 "$zero: flush failed"
  43. err="$err $i"
  44. }
  45. done
  46. else
  47. echo > "$f" || err=no_args
  48. fi
  49. if test "$err"; then
  50. exit 1
  51. fi