1 | 31 | simandl | #!/usr/bin/env perl |
2 | | | |
3 | | | use warnings; |
4 | | | use diagnostics; |
5 | | | |
6 | | | use lib "../../lib"; |
7 | | | use HotSaNICparser; |
8 | | | use HotSaNICshellio; |
9 | | | |
10 | | | my @CONFmod=HotSaNICparser::read_settings(".",$MODNAME); |
11 | | | |
12 | | | my %devlist = ( "3_0" => "/dev/hda", "3_64" => "/dev/hdb", "22_0" => "/dev/hdc", "22_64" => "/dev/hdd", |
13 | | | "33_0" => "/dev/hde", "33_64" => "/dev/hdf", "34_0" => "/dev/hdg", "34_64" => "/dev/hdh", |
14 | | | "8_0" => "/dev/sda", "8_1" => "/dev/sdb", "8_2" => "/dev/sdc", "8_3" => "/dev/sdd", |
15 | | | "8_4" => "/dev/sde", "8_5" => "/dev/sdf", "8_6" => "/dev/sdg", "8_7" => "/dev/sdh", |
16 | | | "8_8" => "/dev/sdi", "8_9" => "/dev/sdj", "8_10" => "/dev/sdk", "8_11" => "/dev/sdl", |
17 | | | "8_12" => "/dev/sdm", "8_13" => "/dev/sdn", "8_14" => "/dev/sdo"); |
18 | | | |
19 | | | if ( ! -e "settings" ) { $OUTFILE="settings"; } else { $OUTFILE="settings.new"; } |
20 | | | |
21 | | | open OUTFILE,">$OUTFILE" || die "could not open $MODNAME settings file for writing.\n"; |
22 | | | |
23 | | | print OUTFILE "# SHORT DESCRIPTION |
24 | | | # |
25 | | | # kernel version |
26 | | | # KERNEL=\"2.2\" for 2.1.x and 2.2.x kernels |
27 | | | # KERNEL=\"2.4\" for 2.3.x and 2.4.x kernels |
28 | | | # |
29 | | | "; |
30 | | | |
31 | | | if ($OUTFILE eq "settings.new") { |
32 | | | for (@CONFmod) { print OUTFILE $_,"\n" if /^KERNEL *=/; } |
33 | | | } |
34 | | | else { |
35 | | | my $version=HotSaNICparser::identify_kernel(); |
36 | | | print OUTFILE "KERNEL=$version\n"; |
37 | | | } |
38 | | | |
39 | | | print OUTFILE " |
40 | | | # all entries have to be of the form: |
41 | | | # DEV=<device>,<device name> |
42 | | | # |
43 | | | # <device> the device-number as in /proc/stat -> disk_io |
44 | | | # for kernels < 2.3 \"0\" is the first drive, \"1\" the second ... |
45 | | | # <2.3 kernels support (unless patched) only 4 drives. |
46 | | | # |
47 | | | # <device name> a description for the device |
48 | | | # |
49 | | | # Example for Kernel >= 2.3: |
50 | | | # DEV=8_0,sda |
51 | | | # DEV=3_0,hda |
52 | | | # DEV=22_0,hdc |
53 | | | # |
54 | | | # Example for Kernel <= 2.2: |
55 | | | # DEV=0,hda |
56 | | | # DEV=1,hdb |
57 | | | # |
58 | | | "; |
59 | | | |
60 | | | if ($OUTFILE eq "settings.new") { |
61 | | | for (@CONFmod) { print OUTFILE $_,"\n" if /^DEV *=/; } |
62 | | | } |
63 | | | else { |
64 | | | if ($^O eq "netbsd") { |
65 | | | open RESULT,"/usr/sbin/iostat -Ix|"; |
66 | | | while (<RESULT>) { |
67 | | | chomp; |
68 | | | ($drv) = split / /, $_; |
69 | | | next if ($drv =~ /device/ || $drv =~ /md?/ ||$drv =~ /fd?/); |
70 | | | print OUTFILE "DEV=$drv,$drv\n"; |
71 | | | } |
72 | | | } |
73 | | | elsif ($^O eq "linux") { |
74 | | | open STAT,"/proc/stat"; |
75 | | | while (<STAT>) { |
76 | | | chomp; |
77 | | | if (/disk_io/) { |
78 | | | foreach (split) { |
79 | | | next if /disk_io:/; |
80 | | | my $major; |
81 | | | my $minor; |
82 | | | /\(([0-9]+),([0-9]+)\)/, $major=$1, $minor=$2; |
83 | | | $device=$devlist{$major."_$minor"}; |
84 | | | if (HotSaNICshellio::askyesno("Use $device","y") eq "y") { |
85 | | | print OUTFILE "DEV=".$major."_$minor,$device\n"; |
86 | | | } |
87 | | | } |
88 | | | last; |
89 | | | } |
90 | | | } |
91 | | | } |
92 | | | else { print "not supported yet, sorry\n"; } |
93 | | | } |
94 | | | |
95 | | | close OUTFILE; |
96 | | | |
97 | | | if ($OUTFILE eq "settings.new") { |
98 | | | HotSaNICparser::backup_file("settings"); |
99 | | | rename "settings.new","settings"; |
100 | | | } |
101 | | | |
102 | | | print "Please check the settings file and adapt it to satisfy your needs.\n"; |
103 | | | |
104 | | | # kernel2.4 source-snip (/usr/src/linux/fs/proc/proc_misc.c) : |
105 | | | # |
106 | | | # proc_sprintf(page, &off, &len, "\ndisk_io: "); |
107 | | | # |
108 | | | # for (major = 0; major < DK_MAX_MAJOR; major++) { |
109 | | | # for (disk = 0; disk < DK_MAX_DISK; disk++) { |
110 | | | # int active = kstat.dk_drive[major][disk] + |
111 | | | # kstat.dk_drive_rblk[major][disk] + |
112 | | | # kstat.dk_drive_wblk[major][disk]; |
113 | | | # if (active) |
114 | | | # proc_sprintf(page, &off, &len, "(%u,%u):(%u,%u,%u,%u,%u) ", major, disk, |
115 | | | # kstat.dk_drive[major][disk], kstat.dk_drive_rio[major][disk], kstat.dk_drive_rblk[major][disk], |
116 | | | # kstat.dk_drive_wio[major][disk], kstat.dk_drive_wblk[major][disk]); |
117 | | | # } |
118 | | | # } |
119 | | | |