jablonka.czprosek.czf

hotsanic

Subversion Repositories:
[/] [branches/] [HotSaNIC-0.5.0-pre6/] [modules/] [diskio/] [setup.pl] - Blame information for rev 10

 

Line No. Rev Author Line
11simandl#!/usr/bin/env perl
2 
3# $Id: setup.pl,v 1.14 2004/07/12 07:50:13 bernisys Exp $
4 
5# include PERL libraries
6use strict;
7use warnings;
8use diagnostics;
9 
10# include HotSaNIC libraries
11use lib "../../lib";
12use lib "./platform";
13use HotSaNICparser;
14use HotSaNICshellio;
15use HotSaNIClog;
16use common;
17 
18$|=1;
19 
20(my $VERSION = '$Revision: 1.14 $') =~ s/.*(\d+\.\d+).*/$1/;
21(my $IDENTIFIER = '$Id: setup.pl,v 1.14 2004/07/12 07:50:13 bernisys Exp $') =~ s/.*,v (.*) \$/$1/;
22 
23my $MODNAME=HotSaNICparser::get_module_name();
24my %MODCONF=HotSaNICmod::common::configure();
25my $OUTFILE="settings.new";
26if ( ! -e "settings" ) { $OUTFILE="settings"; }
27open OUTFILE,">$OUTFILE" || die "could not open ".HotSaNICparser::get_module_name()." settings file for writing.\n";
28 
29if (! @{$MODCONF{DEV}}) { @{$MODCONF{DEV}}=get_devs(); }
30if (@{$MODCONF{DEV}}) { $MODCONF{DEV}="DEV=\"".join("\"\nDEV=\"",@{$MODCONF{DEV}})."\""; }
31else { $MODCONF{DEV}=""; }
32 
33print OUTFILE "# SHORT DESCRIPTION
34#
35# kernel version
36# KERNEL=\"2.2\" for 2.1.x and 2.2.x kernels
37# KERNEL=\"2.4\" for 2.3.x and 2.4.x kernels
38# etc.
39#
40KERNEL=\"$MODCONF{KERNEL}\"
41 
42# set the correct datasource for kernel 2.4 and later
43# use \"stat\" for kernels <2.4 and for 2.4 kernels
44# without /proc/partitions stats support
45# 2.6 kernels might support /proc/diskstats as well, which
46# seems to be pretty identical with /proc/partitions
47#
48# SOURCE=\"stat\"
49# SOURCE=\"partitions\"
50# SOURCE=\"diskstats\"
51#
52SOURCE=\"$MODCONF{SOURCE}\"
53 
54# all entries have to be of the form:
55# DEV=<device>,<device name>
56#
57# <device> the device-number as in /proc/stat -> disk_io
58# for kernels < 2.3 \"0\" is the first drive, \"1\" the second ...
59# <2.3 kernels support (unless patched) only 4 drives.
60#
61# <device name> a description for the device
62#
63# Example for Kernel >= 2.3:
64# DEV=8_0,sda
65# DEV=3_0,hda
66# DEV=22_0,hdc
67#
68# Example for Kernel <= 2.2:
69# DEV=0,hda
70# DEV=1,hdb
71#
72$MODCONF{DEV}
73";
74 
75close OUTFILE;
76 
77if ($OUTFILE eq "settings.new") {
78 HotSaNICparser::backup_file("settings");
79 rename "settings.new","settings";
80 }
81 
82print "Please check the settings file and adapt it to satisfy your needs.\n";
83 
84sub get_devs {
85# see kernel2.4 /usr/src/linux/fs/proc/proc_misc.c
86 my @devs=();
87 my %devlist = ( "3_0" => "/dev/hda", "3_64" => "/dev/hdb", "22_0" => "/dev/hdc", "22_64" => "/dev/hdd",
88 "33_0" => "/dev/hde", "33_64" => "/dev/hdf", "34_0" => "/dev/hdg", "34_64" => "/dev/hdh",
89 "8_0" => "/dev/sda", "8_1" => "/dev/sdb", "8_2" => "/dev/sdc", "8_3" => "/dev/sdd",
90 "8_4" => "/dev/sde", "8_5" => "/dev/sdf", "8_6" => "/dev/sdg", "8_7" => "/dev/sdh",
91 "8_8" => "/dev/sdi", "8_9" => "/dev/sdj", "8_10" => "/dev/sdk", "8_11" => "/dev/sdl",
92 "8_12" => "/dev/sdm", "8_13" => "/dev/sdn", "8_14" => "/dev/sdo");
93 
94 if ($^O eq "netbsd") {
95 open RESULT,"/usr/sbin/iostat -Ix|";
96 while (<RESULT>) {
97 chomp;
98 my ($drv) = split / /, $_;
99 next if ($drv =~ /device/ || $drv =~ /md?/ ||$drv =~ /fd?/);
100 push @devs,"$drv,$drv";
101 }
102 }
103 elsif ($^O eq "linux") {
104 my $usepart=0;
105 if (-e "/proc/partitions") {
106 open STAT,"/proc/partitions";
107 my $check=<STAT>;
108 if ($check =~ /rio/) {
109 $usepart=1;
110 while (<STAT>) {
111 if ($_ ne "\n") {
112 my ($major,$minor,undef,$device)=split;
113 if (HotSaNICshellio::askyesno("Use $device","y") eq "y") {
114 push @devs,$major."_$minor,$device";
115 }
116 }
117 }
118 }
119 close STAT;
120 }
121 if ($usepart == 0) {
122 open STAT,"/proc/stat";
123 while (<STAT>) {
124 chomp;
125 if (/disk_io/) {
126 foreach (split) {
127 next if /disk_io:/;
128 my $major;
129 my $minor;
130 /\(([0-9]+),([0-9]+)\)/, $major=$1, $minor=$2;
131 my $device=$devlist{$major."_$minor"};
132 if (HotSaNICshellio::askyesno("Use $device","y") eq "y") {
133 push @devs,$major."_$minor,$device";
134 }
135 }
136 last;
137 }
138 }
139 }
140 }
141 else { print "not supported yet, sorry\n"; }
142 return @devs;
143 }
144 

Powered by WebSVN 2.2.1