1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192 |
- #! /bin/bash
- # aoe-stat - collate and present information about AoE storage
- # Copyright 2012, CORAID, Inc., and licensed under GPL v.2.
- set -e
- me=`basename $0`
- sysd=${sysfs_dir:-/sys}
- # printf "$format" device mac netif state
- # Suse 9.1 Pro doesn't put /sys in /etc/mtab
- #test -z "`mount | grep sysfs`" && {
- test ! -d "$sysd/block" && {
- echo "$me Error: sysfs is not mounted" 1>&2
- exit 1
- }
- checknode () {
- devname="$1"
- m_sysfs="$2"
- if test -b "@devdir@/$devname"; then
- m_node="`ls -l \"@devdir@/$devname\" | awk '{print $6}'`"
- test "$m_sysfs" = "$m_node" || {
- cat 1>&2 <<EOF
- $me Warning: device node @devdir@/$devname has wrong minor device number
- EOF
- }
- fi
- }
- NA="(NA)"
- cat_or_NA () {
- f="${1?}"
- if test -r "$f"; then
- cat "$f"
- else
- echo "$NA"
- fi
- }
- re=.
- if test $# -gt 0; then
- re=$1
- fi
- # compatibility for aoe drivers without payload information
- for d in `ls -d $sysd/block/*e[0-9]*\.[0-9]* 2>/dev/null | grep -v p` end; do
- # maybe ls comes up empty, so we use "end"
- test $d = end && continue
-
- test -r "$d/payload" && payload=yes
- done
- if test "$payload" = "yes"; then
- format="%10s %15s %10s %-5s %-14s\n"
- else
- format="%10s %15s %6s %-14s\n"
- fi
- for d in `ls -d $sysd/block/*e[0-9]*\.[0-9]* 2>/dev/null | grep -v p` end; do
- test $d = end && continue
- dev=`echo "$d" | sed 's/.*!//'`
- if test -r "$d"/dev; then
- minor="`awk -F: '{print $2}' \"$d/dev\"`"
- checknode "$dev" "$minor"
- else
- minor="$NA"
- fi
- sectors=`cat_or_NA "$d"/size`
- if test "$sectors" = "$NA"; then
- psize="$NA"
- else
- psize=$(((512000 * $sectors) / (1000 * 1000 * 1000)))
- psize=`printf "%04d\n" $psize | sed 's!\(...\)$!.\1!'`GB
- fi
- netif=`cat_or_NA "$d"/netif`
- state=`cat_or_NA "$d"/state`
- payload=`cat_or_NA "$d"/payload`
- if test "$payload" != "$NA"; then
- printf "$format" \
- "$dev" \
- "${psize}" \
- "$netif" \
- "$payload" \
- "$state"
- else
- printf "$format" \
- "$dev" \
- "${psize}" \
- "$netif" \
- "$state"
- fi
- done | sort | grep $re
|