"Fossies" - the Fresh Open Source Software Archive

Member "aoe-aoe6-86/aoetools-36/aoe-stat.in" (4 Jul 2015, 1971 Bytes) of archive /linux/misc/aoe-aoe6-86.tar.gz:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) Bash source code syntax highlighting (style: standard) with prefixed line numbers. Alternatively you can here view or download the uninterpreted source code file.

    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 
    5 set -e
    6 me=`basename $0`
    7 sysd=${sysfs_dir:-/sys}
    8 
    9 # printf "$format" device mac netif state
   10 
   11 # Suse 9.1 Pro doesn't put /sys in /etc/mtab
   12 #test -z "`mount | grep sysfs`" && {
   13 test ! -d "$sysd/block" && {
   14     echo "$me Error: sysfs is not mounted" 1>&2
   15     exit 1
   16 }
   17 
   18 checknode () {
   19     devname="$1"
   20     m_sysfs="$2"
   21     if test -b "@devdir@/$devname"; then
   22         m_node="`ls -l \"@devdir@/$devname\" | awk '{print $6}'`"
   23         test "$m_sysfs" = "$m_node" || {
   24             cat 1>&2 <<EOF
   25 $me Warning: device node @devdir@/$devname has wrong minor device number
   26 EOF
   27         }
   28     fi
   29 }
   30 
   31 NA="(NA)"
   32 cat_or_NA () {
   33     f="${1?}"
   34     if test -r "$f"; then
   35         cat "$f"
   36     else
   37         echo "$NA"
   38     fi
   39 }
   40 
   41 re=.
   42 if test $# -gt 0; then
   43     re=$1
   44 fi
   45 
   46 # compatibility for aoe drivers without payload information
   47 for d in `ls -d $sysd/block/*e[0-9]*\.[0-9]* 2>/dev/null | grep -v p` end; do
   48     # maybe ls comes up empty, so we use "end"
   49     test $d = end && continue
   50     
   51     test -r "$d/payload" && payload=yes
   52 done
   53 if test "$payload" = "yes"; then
   54     format="%10s %15s %10s %-5s %-14s\n"
   55 else
   56     format="%10s %15s %6s %-14s\n"
   57 fi
   58 for d in `ls -d $sysd/block/*e[0-9]*\.[0-9]* 2>/dev/null | grep -v p` end; do
   59     test $d = end && continue
   60 
   61     dev=`echo "$d" | sed 's/.*!//'`
   62     if test -r "$d"/dev; then
   63         minor="`awk -F: '{print $2}' \"$d/dev\"`"
   64         checknode "$dev" "$minor"
   65     else
   66         minor="$NA"
   67     fi
   68     sectors=`cat_or_NA "$d"/size`
   69     if test "$sectors" = "$NA"; then
   70         psize="$NA"
   71     else
   72         psize=$(((512000 * $sectors) / (1000 * 1000 * 1000)))
   73         psize=`printf "%04d\n" $psize | sed 's!\(...\)$!.\1!'`GB
   74     fi
   75     netif=`cat_or_NA "$d"/netif`
   76     state=`cat_or_NA "$d"/state`
   77     payload=`cat_or_NA "$d"/payload`
   78     if test "$payload" != "$NA"; then
   79         printf "$format" \
   80             "$dev" \
   81             "${psize}" \
   82             "$netif" \
   83             "$payload" \
   84             "$state"
   85     else
   86         printf "$format" \
   87             "$dev" \
   88             "${psize}" \
   89             "$netif" \
   90             "$state"
   91     fi
   92 done | sort | grep $re