diff options
author | An-Cheng Huang <ancheng@vyatta.com> | 2009-07-17 14:35:30 -0700 |
---|---|---|
committer | An-Cheng Huang <ancheng@vyatta.com> | 2009-07-17 14:35:30 -0700 |
commit | dd8e37e0d1fe9db8b3dace3af1d0fedc60eca6b3 (patch) | |
tree | 00efba5ec592953c657a8e482763e236d4ad3e38 /scripts/vyatta-bonding.pl | |
parent | a26515cbc2a0fbf2369ee25c89e294f73126ad81 (diff) | |
download | vyatta-cfg-system-dd8e37e0d1fe9db8b3dace3af1d0fedc60eca6b3.tar.gz vyatta-cfg-system-dd8e37e0d1fe9db8b3dace3af1d0fedc60eca6b3.zip |
Use sysfs for bonding device control
Bug 4511
Since loading bond module is broken in 2.6.29 or later kernel
and the root cause is in sysfs/procfs which is a mess.
Workaround the problem by loading bond module once and using sysfs.
(cherry picked from commit 47f054cb196959bb79960f3b6c1524b4ff7d32a8)
Conflicts:
templates/interfaces/bonding/node.def
Diffstat (limited to 'scripts/vyatta-bonding.pl')
-rwxr-xr-x | scripts/vyatta-bonding.pl | 64 |
1 files changed, 29 insertions, 35 deletions
diff --git a/scripts/vyatta-bonding.pl b/scripts/vyatta-bonding.pl index f1ff3193..2f2167fa 100755 --- a/scripts/vyatta-bonding.pl +++ b/scripts/vyatta-bonding.pl @@ -29,9 +29,9 @@ # use lib "/opt/vyatta/share/perl5/"; -use Vyatta::Config; - +use Vyatta::Interface; use Getopt::Long; + use strict; use warnings; @@ -45,52 +45,46 @@ my %modes = ( "adaptive-load-balance" => 6, ); -sub create_bond { - my $bond = shift; - my $config = new Vyatta::Config; +sub set_mode { + my ($intf, $mode) = @_; + my $val = $modes{$mode}; + die "Unknown bonding mode $mode\n" unless $val; - $config->setLevel("interfaces bonding $bond"); - my $mode = $modes{ $config->returnValue("mode") }; - defined $mode or die "bonding mode not defined"; + open my $fm, '>', "/sys/class/net/$intf/bonding/mode" + or die "Error: $intf is not a bonding device:$!\n"; + print {$fm} $val, "\n"; + close $fm + or die "Error: $intf can not set mode $val:$!\n"; +} - system("sudo modprobe -o \"$bond\" bonding mode=$mode") == 0 - or die "modprobe of bonding failed: $!\n"; - system("sudo ip link set \"$bond\" up") == 0 - or die "enabling $bond failed: $!\n"; -} +sub change_mode { + my ($intf, $mode) = @_; + my $interface = new Vyatta::Interface($intf); -sub delete_bond { - my $bond = shift; - system("sudo rmmod \"$bond\"") == 0 - or die "removal of bonding module failed: $!\n"; -} + die "$intf is not a valid interface" unless $interface; + if ($interface->up()) { + system "sudo ip link set $intf down" + and die "Could not set $intf down ($!)\n"; -# See if bonding device exists and the mode has changed -sub change_bond { - my $bond = shift; - my $config = new Vyatta::Config; + set_mode($intf, $mode); - $config->setLevel("interfaces bonding"); - if ( !( $config->isAdded($bond) || $config->isDeleted($bond) ) - && $config->isChanged("$bond mode") ) - { - delete_bond($bond); - create_bond($bond); + system "sudo ip link set $intf up" + and die "Could not set $intf up ($!)\n"; + } else { + set_mode($intf, $mode); } - exit 0; } sub usage { - print "Usage: $0 --create bondX\n"; - print " --delete bondX\n"; - print " --mode-change bondX\n"; + print "Usage: $0 --set-mode=s{2}\n"; exit 1; } +my @mode_change; + GetOptions( - 'create=s' => sub { create_bond( $_[1] ); }, - 'delete=s' => sub { delete_bond( $_[1] ); }, - 'mode-change=s' => sub { change_bond( $_[1] ); }, + 'set-mode=s{2}' => \@mode_change, ) or usage(); +change_mode( @mode_change ) if @mode_change; |