From 80c580de586eafe29d09a9acd59616a3b7739355 Mon Sep 17 00:00:00 2001 From: wanghuaz Date: Fri, 18 Jun 2010 10:51:05 +0000 Subject: [PATCH] Remove duplicated entries in /etc/sysctl.conf git-svn-id: https://svn.code.sf.net/p/xcat/code/xcat-core/trunk@6534 8638fb3e-16cb-4fca-ae20-7b5d299a9bcd --- .../share/xcat/ib/scripts/configiba.1port | 48 +++++++++++++-- .../share/xcat/ib/scripts/configiba.2ports | 58 +++++++++++++++---- 2 files changed, 88 insertions(+), 18 deletions(-) diff --git a/xCAT-server/share/xcat/ib/scripts/configiba.1port b/xCAT-server/share/xcat/ib/scripts/configiba.1port index 945802e3b..400b70ec6 100644 --- a/xCAT-server/share/xcat/ib/scripts/configiba.1port +++ b/xCAT-server/share/xcat/ib/scripts/configiba.1port @@ -55,13 +55,11 @@ foreach my $num ( @nums ) { } if ( -f "/etc/sysctl.conf" ) { + updatefile("/etc/sysctl.conf", "net.ipv4.conf.$nic.arp_filter"); + updatefile("/etc/sysctl.conf", "net.ipv4.conf.$nic.arp_ignore"); runcmd("echo 'net.ipv4.conf.$nic.arp_filter=1' >> /etc/sysctl.conf"); runcmd("echo 'net.ipv4.conf.$nic.arp_ignore=1' >> /etc/sysctl.conf"); } - if ( -f "/etc/infiniband/openib.conf" ) - { - runcmd("/usr/bin/sed -i 's/SDP_LOAD=yes/SDP_LOAD=no/g' /etc/infiniband/openib.conf"); - } # Write the info to the ifcfg file my $dir; @@ -108,19 +106,27 @@ foreach my $num ( @nums ) { } if ( $PLTFRM eq "Linux" ) { + + if ( -f "/etc/infiniband/openib.conf" ) + { + updatefile("/etc/infiniband/openib.conf", "SDP_LOAD=yes", "SDP_LOAD=no"); + } + if ( $OS_name eq 'suse') { + updatefile("/etc/modprobe.conf", "options ib_ehca nr_ports"); + updatefile("/etc/modprobe.conf", "options ib_ehca lock_hcalls"); runcmd("echo 'options ib_ehca nr_ports=1' >> /etc/modprobe.conf"); runcmd("echo 'options ib_ehca lock_hcalls=0' >> /etc/modprobe.conf"); } - runcmd("sysctl -p"); - my $openibd_cmd = "/sbin/chkconfig --level 2345 openibd on"; runcmd($openibd_cmd); my $openibd_start_cmd = "/sbin/service openibd restart"; runcmd($openibd_start_cmd); + runcmd("sysctl -p"); + sleep(20); foreach my $nic ( @nics ) { sleep(5); @@ -174,3 +180,33 @@ sub runcmd { } } +sub updatefile { + my $fname = shift; + my $old = shift; + my $new = shift; + unless ( open( HOSTS,"<$fname" )) { + return undef; + } + my @rawdata = ; + my @newdata = (); + close( HOSTS ); + chomp @rawdata; + + foreach my $line ( @rawdata ) { + if ( $line =~ /^(.*)$old(.*)$/ ) { + if ( $new ) { + push @newdata, "$1$new$2"; + } + } else { + push @newdata, $line; + } + } + unless ( open( HOSTS,">$fname" )) { + return undef; + } + for my $line (@newdata) + { + print HOSTS "$line\n"; + } + close( HOSTS ); +} diff --git a/xCAT-server/share/xcat/ib/scripts/configiba.2ports b/xCAT-server/share/xcat/ib/scripts/configiba.2ports index a6777382e..2699ba3a3 100644 --- a/xCAT-server/share/xcat/ib/scripts/configiba.2ports +++ b/xCAT-server/share/xcat/ib/scripts/configiba.2ports @@ -55,17 +55,10 @@ foreach my $num ( @nums ) { } if ( -f "/etc/sysctl.conf" ) { - runcmd("echo 'net.ipv4.conf.$nic.arp_filter=1' >> /etc/sysctl.conf"); - runcmd("echo 'net.ipv4.conf.$nic.arp_ignore=1' >> /etc/sysctl.conf"); - } - if ( -f "/etc/infiniband/openib.conf" ) - { - runcmd("/usr/bin/sed -i 's/SDP_LOAD=yes/SDP_LOAD=no/g' /etc/infiniband/openib.conf"); - } - if ( -f "/etc/modprobe.conf" ) - { - runcmd("sed -i 's/options\ ib_ehca\ nr_ports=1//g' /etc/modprobe.conf"); - runcmd("sed -i 's/options\ ib_ehca\ lock_hcalls=0//g' /etc/modprobe.conf"); + updatefile("/etc/sysctl.conf", "net.ipv4.conf.$nic.arp_filter"); + updatefile("/etc/sysctl.conf", "net.ipv4.conf.$nic.arp_ignore"); + runcmd("echo 'net.ipv4.conf.$nic.arp_filter = 1' >> /etc/sysctl.conf"); + runcmd("echo 'net.ipv4.conf.$nic.arp_ignore = 1' >> /etc/sysctl.conf"); } # Write the info to the ifcfg file my $dir; @@ -115,13 +108,24 @@ foreach my $num ( @nums ) { if ( $PLTFRM eq "Linux" ) { - runcmd("sysctl -p"); + if ( -f "/etc/infiniband/openib.conf" ) + { + updatefile("/etc/infiniband/openib.conf", "SDP_LOAD=yes", "SDP_LOAD=no"); + } + if ( -f "/etc/modprobe.conf" ) + { + updatefile("/etc/modprobe.conf", "options ib_ehca nr_ports=1"); + updatefile("/etc/modprobe.conf", "options ib_ehca lock_hcalls=0"); + } + runcmd("echo 'options ib_ehca lock_hcalls=0' >> /etc/modprobe.conf"); my $openibd_cmd = "/sbin/chkconfig --level 2345 openibd on"; runcmd($openibd_cmd); my $openibd_start_cmd = "/sbin/service openibd restart"; runcmd($openibd_start_cmd); + runcmd("sysctl -p"); + sleep(20); foreach my $nic ( @nics ) { sleep(5); @@ -181,3 +185,33 @@ sub runcmd { } } +sub updatefile { + my $fname = shift; + my $old = shift; + my $new = shift; + unless ( open( HOSTS,"<$fname" )) { + return undef; + } + my @rawdata = ; + my @newdata = (); + close( HOSTS ); + chomp @rawdata; + + foreach my $line ( @rawdata ) { + if ( $line =~ /^(.*)$old(.*)$/ ) { + if ( $new ) { + push @newdata, "$1$new$2"; + } + } else { + push @newdata, $line; + } + } + unless ( open( HOSTS,">$fname" )) { + return undef; + } + for my $line (@newdata) + { + print HOSTS "$line\n"; + } + close( HOSTS ); +}