>From 4f3c4c69bf7920284ea9894246abc540b4d99cfb Mon Sep 17 00:00:00 2001 From: Ira K. Weiny Date: Thu, 26 Apr 2007 20:40:50 -0700 Subject: [PATCH] Remove all uses of "/tmp" from perl diags Remove all the uses of /tmp for cached application data. Replace with a global defined to /var/cache/infiniband-diags. Signed-off-by: Ira K. Weiny --- diags/scripts/IBswcountlimits.pm | 17 ++++++++++++++--- diags/scripts/ibfindnodesusing.pl | 4 ++-- diags/scripts/ibprintca.pl | 6 +++--- diags/scripts/ibprintswitch.pl | 6 +++--- diags/scripts/ibqueryerrors.pl | 4 ++-- diags/scripts/ibswportwatch.pl | 7 ++++--- 6 files changed, 28 insertions(+), 16 deletions(-) diff --git a/diags/scripts/IBswcountlimits.pm b/diags/scripts/IBswcountlimits.pm index e214f67..1c884e9 100755 --- a/diags/scripts/IBswcountlimits.pm +++ b/diags/scripts/IBswcountlimits.pm @@ -43,6 +43,7 @@ use strict; @IBswcountlimits::suppress_errors = (); $IBswcountlimits::link_ends = undef; $IBswcountlimits::pause_time = 10; +$IBswcountlimits::cache_dir = "/var/cache/infiniband-diags"; # all the PM counters @IBswcountlimits::counters = ( @@ -204,9 +205,19 @@ sub any_counts # ========================================================================= # +sub ensure_cache_dir +{ + if (!(-d "$IBswcountlimits::cache_dir")) { + mkdir $IBswcountlimits::cache_dir, 0700; + } +} + +# ========================================================================= +# sub generate_ibnetdiscover_topology { - `ibnetdiscover -g > /tmp/ibnetdiscover.topology`; + ensure_cache_dir; + `ibnetdiscover -g > $IBswcountlimits::cache_dir/ibnetdiscover.topology`; if ($? != 0) { die "Execution of ibnetdiscover failed with errors\n"; } @@ -216,8 +227,8 @@ sub generate_ibnetdiscover_topology # sub get_link_ends { - if (!(-f "/tmp/ibnetdiscover.topology")) { generate_ibnetdiscover_topology; } - open IBNET_TOPO, ") diff --git a/diags/scripts/ibprintswitch.pl b/diags/scripts/ibprintswitch.pl index 2ce3bbe..5ab8f65 100755 --- a/diags/scripts/ibprintswitch.pl +++ b/diags/scripts/ibprintswitch.pl @@ -62,11 +62,11 @@ if (defined $Getopt::Std::opt_l) { $list my $target_switch = $ARGV[0]; -if ($regenerate_map || !(-f "/tmp/ibnetdiscover.topology")) { generate_ibnetdiscover_topology; } +if ($regenerate_map || !(-f "$IBswcountlimits::cache_dir/ibnetdiscover.topology")) { generate_ibnetdiscover_topology; } if ($list_switches) { - system ("ibswitches /tmp/ibnetdiscover.topology"); + system ("ibswitches $IBswcountlimits::cache_dir/ibnetdiscover.topology"); exit 1; } @@ -80,7 +80,7 @@ if ($target_switch eq "") sub main { my $found_switch = undef; - open IBNET_TOPO, ") diff --git a/diags/scripts/ibqueryerrors.pl b/diags/scripts/ibqueryerrors.pl index e894eb8..9343fcf 100755 --- a/diags/scripts/ibqueryerrors.pl +++ b/diags/scripts/ibqueryerrors.pl @@ -113,7 +113,7 @@ sub get_counts my %switches = (); sub get_switches { - my $data = `ibswitches /tmp/ibnetdiscover.topology`; + my $data = `ibswitches $IBswcountlimits::cache_dir/ibnetdiscover.topology`; my @lines = split("\n", $data); foreach my $line (@lines) { if ($line =~ /^Switch\s+:\s+(\w+)\s+ports\s+(\d+)\s+.*/) @@ -164,7 +164,7 @@ sub main my $msg = join(",", @IBswcountlimits::suppress_errors); print "Suppressing: $msg\n"; } - if ($regenerate_map || !(-f "/tmp/ibnetdiscover.topology")) { generate_ibnetdiscover_topology; } + if ($regenerate_map || !(-f "$IBswcountlimits::cache_dir/ibnetdiscover.topology")) { generate_ibnetdiscover_topology; } get_switches; get_link_ends; foreach my $sw_addr (keys %switches) { diff --git a/diags/scripts/ibswportwatch.pl b/diags/scripts/ibswportwatch.pl index e844acb..e16d15e 100755 --- a/diags/scripts/ibswportwatch.pl +++ b/diags/scripts/ibswportwatch.pl @@ -111,13 +111,14 @@ sub get_new_counts my $addr = $_[0]; my $port = $_[1]; mv_counts; - if (system("perfquery $GUID $addr $port > /tmp/perfquery.out")) + ensure_cache_dir; + if (system("perfquery $GUID $addr $port > $IBswcountlimits::cache_dir/perfquery.out")) { print "perfquery failed : \"perfquery $GUID $addr $port\"\n"; - system("cat /tmp/perfquery.out"); + system("cat $IBswcountlimits::cache_dir/perfquery.out"); exit 1; } - open PERF_QUERY, ") { foreach my $count (@IBswcountlimits::counters) -- 1.4.4