aoe-stat.in 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  1. #! /bin/bash
  2. # aoe-stat - collate and present information about AoE storage
  3. # Copyright 2012, 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. 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. NA="(NA)"
  27. cat_or_NA () {
  28. f="${1?}"
  29. if test -r "$f"; then
  30. cat "$f"
  31. else
  32. echo "$NA"
  33. fi
  34. }
  35. re=.
  36. if test $# -gt 0; then
  37. re=$1
  38. fi
  39. # compatibility for aoe drivers without payload information
  40. for d in `ls -d $sysd/block/*e[0-9]*\.[0-9]* 2>/dev/null | grep -v p` end; do
  41. # maybe ls comes up empty, so we use "end"
  42. test $d = end && continue
  43. test -r "$d/payload" && payload=yes
  44. done
  45. if test "$payload" = "yes"; then
  46. format="%10s %15s %10s %-5s %-14s\n"
  47. else
  48. format="%10s %15s %6s %-14s\n"
  49. fi
  50. for d in `ls -d $sysd/block/*e[0-9]*\.[0-9]* 2>/dev/null | grep -v p` end; do
  51. test $d = end && continue
  52. dev=`echo "$d" | sed 's/.*!//'`
  53. if test -r "$d"/dev; then
  54. minor="`awk -F: '{print $2}' \"$d/dev\"`"
  55. checknode "$dev" "$minor"
  56. else
  57. minor="$NA"
  58. fi
  59. sectors=`cat_or_NA "$d"/size`
  60. if test "$sectors" = "$NA"; then
  61. psize="$NA"
  62. else
  63. psize=$(((512000 * $sectors) / (1000 * 1000 * 1000)))
  64. psize=`printf "%04d\n" $psize | sed 's!\(...\)$!.\1!'`GB
  65. fi
  66. netif=`cat_or_NA "$d"/netif`
  67. state=`cat_or_NA "$d"/state`
  68. payload=`cat_or_NA "$d"/payload`
  69. if test "$payload" != "$NA"; then
  70. printf "$format" \
  71. "$dev" \
  72. "${psize}" \
  73. "$netif" \
  74. "$payload" \
  75. "$state"
  76. else
  77. printf "$format" \
  78. "$dev" \
  79. "${psize}" \
  80. "$netif" \
  81. "$state"
  82. fi
  83. done | sort | grep $re