jablonka.czprosek.czf

hotsanic

Subversion Repositories:
[/] [trunk/] [modules/] [diskio/] [setup] - Rev 33 Go to most recent revision

Compare with Previous - Blame - Download


#!/usr/bin/env sh

if ! [ -e settings ]; then OUTFILE="settings"; else OUTFILE="settings.new"; fi

OSTYPE=`uname`
VERSION=`uname -r|awk -F "\." '{ if ( $2 < 3 ) { vrs = "2" ; } else { vrs = "4"; }; print $1"."vrs}'`

cat > $OUTFILE << EOF
# kernel version
# KERNEL="2.2" for 2.1.x and 2.2.x kernels
# KERNEL="2.4" for 2.3.x and 2.4.x kernels
#
EOF

echo "KERNEL=\"$VERSION\"" >> $OUTFILE

cat >> $OUTFILE << EOF

# all entries have to be of the form:
# DEV=<device>,<device name>
#
# <device>       the device-number as in /proc/stat -> disk_io
#                for kernels < 2.3 "0" is the first drive, "1" the second ...
#                <2.3 kernels support (unless patched) only 4 drives.
#
# <device name>  a description for the device
#
# Example for Kernel >= 2.3:
# DEV=8_0,sda
# DEV=3_0,hda
# DEV=22_0,hdc
#
# Example for Kernel <= 2.2:
# DEV=0,hda
# DEV=1,hdb
# 
EOF

if [ "$OUTFILE" = "settings" ]; then
  if [ "$OSTYPE" = "NetBSD" ]; then
    /usr/sbin/iostat -Ix | perl -ne 'chomp; ($drv,$rest) = split / /, $_; next if ($drv =~ /device/ || $drv =~ /md?/ ||$drv =~ /fd?/); print "DEV=$drv,$drv\n";' >> $OUTFILE
    fi
  if [ "$OSTYPE" = "FreeBSD" -o "$OSTYPE" = "OpenBSD" ]; then
    echo "not supported yet, sorry"
    exit 1 
    fi
  if [ "$OSTYPE" = "Linux" ]; then
    DEVS=$(cat /proc/stat |grep disk_io | sed -e "s/):([0-9,]*//g; s/[()]//g; s/disk_io: //g")
    for DEV in $DEVS; do
      ENTRY=$(echo $DEV | sed -e "s/,/_/g")
      NAME="(unknown)"
      case $ENTRY in
        3_0)   NAME="/dev/hda";;
        3_64)  NAME="/dev/hdb";;
        22_0)  NAME="/dev/hdc";;
        22_64) NAME="/dev/hdd";;
        33_0)  NAME="/dev/hde";;
        33_64) NAME="/dev/hdf";;
        34_0)  NAME="/dev/hdg";;
        34_64) NAME="/dev/hdh";;
        8_0)   NAME="/dev/sda";;
        8_1)   NAME="/dev/sdb";;
        8_2)   NAME="/dev/sdc";;
        8_3)   NAME="/dev/sdd";;
        8_4)   NAME="/dev/sde";;
        8_5)   NAME="/dev/sdf";;
        8_6)   NAME="/dev/sdg";;
        8_7)   NAME="/dev/sdh";;
        8_8)   NAME="/dev/sdi";;
        8_9)   NAME="/dev/sdj";;
        8_10)  NAME="/dev/sdk";;
        8_11)  NAME="/dev/sdl";;
        8_12)  NAME="/dev/sdm";;
        8_13)  NAME="/dev/sdn";;
        8_14)  NAME="/dev/sdo";;
        esac
      echo "found: $DEV - $ENTRY - $NAME"
      echo "DEV=$ENTRY,$NAME" >> $OUTFILE
      done
    fi

  fi
if [ "$OUTFILE" = "settings.new" ]; then
  cat settings | grep "^DEV=" >> $OUTFILE
  fi

echo
echo "Please check the settings file and adapt it to satisfy your needs."
if [ "$OUTFILE" = "settings.new" ]; then
  mkdir -p backup
  NOW=`date +%Y%m%d-%H%M%S`
  mv -f settings backup/settings-$NOW
  mv -f settings.new settings
  echo "a backup of the previous settings has been saved."
  fi
echo

# kernel2.4 source-snip (/usr/src/linux/fs/proc/proc_misc.c) :
#
#  proc_sprintf(page, &off, &len, "\ndisk_io: ");
#  
#  for (major = 0; major < DK_MAX_MAJOR; major++) {
#    for (disk = 0; disk < DK_MAX_DISK; disk++) {
#      int active = kstat.dk_drive[major][disk] +
#      kstat.dk_drive_rblk[major][disk] +
#      kstat.dk_drive_wblk[major][disk];
#      if (active)
#        proc_sprintf(page, &off, &len, "(%u,%u):(%u,%u,%u,%u,%u) ", major, disk,
#          kstat.dk_drive[major][disk], kstat.dk_drive_rio[major][disk], kstat.dk_drive_rblk[major][disk],
#          kstat.dk_drive_wio[major][disk], kstat.dk_drive_wblk[major][disk]);
#      }
#    }

Powered by WebSVN 2.2.1