Skip to content

Commit

Permalink
mxnetctl: Remove redundant whitespace and useless comments
Browse files Browse the repository at this point in the history
  • Loading branch information
donald committed Jun 20, 2023
1 parent a9c03aa commit 6c2c6bb
Showing 1 changed file with 5 additions and 31 deletions.
36 changes: 5 additions & 31 deletions mxnetctl/mxnetctl
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@ use warnings;

use Getopt::Long;

# options

our ($opt_quiet,$opt_noop,$opt_ignore_hw);
use constant OPTIONS => (
'quiet' => \$opt_quiet,
Expand All @@ -24,7 +22,7 @@ options:
__EOF__
}

sub scandir {
my ($dirname)=@_;
opendir my $dir,$dirname or die "$dirname: $!\n";
Expand Down Expand Up @@ -58,27 +56,23 @@ sub get_hw_address { # 'eth1' -> '00:1b:21:79:76:67'
return slurpfile_chomp($path);
}


our %HW_TO_DEV; # ( '00:1b:21:79:76:67' => 'net02' , ... )
our %DEV_TO_HW; # ('net02'=>'00:1b:21:79:76:67', ... )
our $CHANGES;


sub register_stable {
my ($hw,$dev)=@_;

# force one-to-one mapping, even if file is erroneus

exists $DEV_TO_HW{$dev} and delete $HW_TO_DEV{$DEV_TO_HW{$dev}};
exists $HW_TO_DEV{$dev} and delete $DEV_TO_HW{$HW_TO_DEV{$hw}};


$HW_TO_DEV{$hw}=$dev;
$DEV_TO_HW{$dev}=$hw;
$CHANGES++;
}


sub read_mxnet {
%HW_TO_DEV=();
%DEV_TO_HW=();
Expand All @@ -102,12 +96,6 @@ sub write_mxnet {
print $mxnet $DEV_TO_HW{$dev},' ',$dev."\n";
}
print $mxnet "\n";

# open my $out,'>',"/etc/local/mxnet-udev.rules" or die "/etc/local/mxnet-udev.rules: $!\n";
# print $out "# generated ".scalar(localtime)." by $0\n\n";
# for my $dev (sort keys %DEV_TO_HW) {
# print $out qq'SUBSYSTEM=="net", ACTION=="add", ATTR{address}=="$DEV_TO_HW{$dev}", NAME="$dev"\n';
# }
}
}

Expand All @@ -119,7 +107,6 @@ sub get_unused_name {
}
}


sub rename_if {
my ($src,$dst)=@_;
warn "rename $src to $dst\n" unless $opt_quiet;
Expand All @@ -134,7 +121,6 @@ sub rename_if {
}
}


sub preferred_device_name {
my ($dev,$hw)=@_;

Expand All @@ -152,21 +138,19 @@ sub preferred_device_name {
return $new_dev;
}



our $TMP_NUM=0;
sub out_of_the_way {
my ($dev)=@_; # only 'netXX' or 'ethX' - never 'tmpXX'

-e "/sys/class/net/$dev/device" or return;

my $i = $dev=~/(\d+)/;
rename_if($dev,sprintf('tmpnet%02d',$TMP_NUM++));
}

sub start {
read_mxnet();

# 1: rename configured ethX and netXX devices to configured netXX - move away conflicting devices

for my $dev (grep /^(eth|net)(\d+)/,network_hardware_devices()) {
Expand All @@ -186,7 +170,6 @@ sub start {
rename_if($dev,$new_dev);
}

#if ($CHANGES || ! -e "/etc/local/mxnet-udev.rules") {
if ($CHANGES) {
write_mxnet();
}
Expand All @@ -198,19 +181,10 @@ GetOptions(OPTIONS) or die USAGE;

my ($cmd)=@ARGV;


if ($cmd eq 'start') {
start();
} elsif ($cmd eq 'stop') {
;
} else {
die USAGE;
}








0 comments on commit 6c2c6bb

Please sign in to comment.