aoe-stat.in 1.2 KB

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