aoe-stat.in 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. #! /bin/bash
  2. # aoe-stat - collate and present information about AoE storage
  3. # Copyright 2009, CORAID, Inc., and licensed under GPL v.2.
  4. set -e
  5. me=`basename $0`
  6. sysd=${sysfs_dir:-/sys}
  7. # printf "$format" device mac netif state
  8. # Suse 9.1 Pro doesn't put /sys in /etc/mtab
  9. #test -z "`mount | grep sysfs`" && {
  10. test ! -d "$sysd/block" && {
  11. echo "$me Error: sysfs is not mounted" 1>&2
  12. exit 1
  13. }
  14. function checknode () {
  15. devname="$1"
  16. m_sysfs="$2"
  17. if test -b "@devdir@/$devname"; then
  18. m_node="`ls -l \"@devdir@/$devname\" | awk '{print $6}'`"
  19. test "$m_sysfs" = "$m_node" || {
  20. cat 1>&2 <<EOF
  21. $me Warning: device node @devdir@/$devname has wrong minor device number
  22. EOF
  23. }
  24. fi
  25. }
  26. re=.
  27. if test $# -gt 0; then
  28. re=$1
  29. fi
  30. # compatibility for aoe drivers without payload information
  31. for d in `ls -d $sysd/block/*e[0-9]*\.[0-9]* 2>/dev/null | grep -v p` end; do
  32. # maybe ls comes up empty, so we use "end"
  33. test $d = end && continue
  34. test -r "$d/payload" && payload=yes
  35. done
  36. if test "$payload" = "yes"; then
  37. format="%10s %15s %10s %-5s %-14s\n"
  38. else
  39. format="%10s %15s %6s %-14s\n"
  40. fi
  41. for d in `ls -d $sysd/block/*e[0-9]*\.[0-9]* 2>/dev/null | grep -v p` end; do
  42. test $d = end && continue
  43. dev=`echo "$d" | sed 's/.*!//'`
  44. sectors="`cat \"$d/size\"`"
  45. minor="`awk -F: '{print $2}' \"$d/dev\"`"
  46. checknode "$dev" "$minor"
  47. psize=$(((512000 * $sectors) / (1000 * 1000 * 1000)))
  48. psize=`printf "%04d\n" $psize | sed 's!\(...\)$!.\1!'`
  49. if test "$payload" = "yes"; then
  50. printf "$format" \
  51. "$dev" \
  52. "${psize}GB" \
  53. "`cat \"$d/netif\"`" \
  54. "`cat \"$d/payload\"`" \
  55. "`cat \"$d/state\"`"
  56. else
  57. printf "$format" \
  58. "$dev" \
  59. "${psize}GB" \
  60. "`cat \"$d/netif\"`" \
  61. "`cat \"$d/state\"`"
  62. fi
  63. done | sort | grep $re