jablonka.czprosek.czf

hotsanic

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

Compare with Previous - Blame - Download


#!/usr/bin/env perl

use warnings;
use diagnostics;

use lib "../../lib";
use HotSaNICparser;
use HotSaNICshellio;

my @CONFmod=HotSaNICparser::read_settings(".",$MODNAME);

my %devlist = (  "3_0"  => "/dev/hda",  "3_64" => "/dev/hdb", "22_0"  => "/dev/hdc", "22_64" => "/dev/hdd",
                "33_0"  => "/dev/hde", "33_64" => "/dev/hdf", "34_0"  => "/dev/hdg", "34_64" => "/dev/hdh",
                 "8_0"  => "/dev/sda",  "8_1"  => "/dev/sdb",  "8_2"  => "/dev/sdc",  "8_3"  => "/dev/sdd",
                 "8_4"  => "/dev/sde",  "8_5"  => "/dev/sdf",  "8_6"  => "/dev/sdg",  "8_7"  => "/dev/sdh",
                 "8_8"  => "/dev/sdi",  "8_9"  => "/dev/sdj",  "8_10" => "/dev/sdk",  "8_11" => "/dev/sdl",
                 "8_12" => "/dev/sdm",  "8_13" => "/dev/sdn",  "8_14" => "/dev/sdo");

if ( ! -e "settings" ) { $OUTFILE="settings"; } else { $OUTFILE="settings.new"; }

open OUTFILE,">$OUTFILE" || die "could not open $MODNAME settings file for writing.\n";

print OUTFILE "# SHORT DESCRIPTION
#
# 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
#
";

if ($OUTFILE eq "settings.new") { 
  for (@CONFmod) { print OUTFILE $_,"\n" if /^KERNEL *=/; }
  }
else {
  my $version=HotSaNICparser::identify_kernel();
  print OUTFILE "KERNEL=$version\n";
  }

print OUTFILE "
# 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
#
";

if ($OUTFILE eq "settings.new") { 
  for (@CONFmod) { print OUTFILE $_,"\n" if /^DEV *=/; }
  }
else {
  if ($^O eq "netbsd") {
    open RESULT,"/usr/sbin/iostat -Ix|";
    while (<RESULT>) {
      chomp;
      ($drv) = split / /, $_;
      next if ($drv =~ /device/ || $drv =~ /md?/ ||$drv =~ /fd?/);
      print OUTFILE "DEV=$drv,$drv\n";
      }
    }
  elsif ($^O eq "linux") {
    open STAT,"/proc/stat";
    while (<STAT>) {
      chomp;
      if (/disk_io/) {
        foreach (split) {
          next if /disk_io:/;
          my $major;
          my $minor;
          /\(([0-9]+),([0-9]+)\)/, $major=$1, $minor=$2;
          $device=$devlist{$major."_$minor"};
          if (HotSaNICshellio::askyesno("Use $device","y") eq "y") {
            print OUTFILE "DEV=".$major."_$minor,$device\n";
            }
          }
        last;
        }
      }
    }
  else { print "not supported yet, sorry\n"; }
  }

close OUTFILE;

if ($OUTFILE eq "settings.new") {
  HotSaNICparser::backup_file("settings");
  rename "settings.new","settings";
  }

print "Please check the settings file and adapt it to satisfy your needs.\n";

# 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