krishnanadh / rpms / rasdaemon

Forked from rpms/rasdaemon a year ago
Clone

Blame SOURCES/546cf713f667437fb6e283cc3dc090679eb47d08.patch

394513
commit 546cf713f667437fb6e283cc3dc090679eb47d08
394513
Author: Subhendu Saha <subhends@akamai.com>
394513
Date:   Tue Jan 12 03:29:55 2021 -0500
394513
394513
    Fix ras-mc-ctl script.
394513
    
394513
    When rasdaemon is compiled without enabling aer, mce, devlink,
394513
    etc., those tables are not created in the database file. Then
394513
    ras-mc-ctl script breaks trying to query data from non-existent
394513
    tables.
394513
    
394513
    Signed-off-by: Subhendu Saha subhends@akamai.com
394513
    Signed-off-by: Mauro Carvalho Chehab <mchehab+huawei@kernel.org>
394513
394513
---
394513
 util/ras-mc-ctl.in |  310 ++++++++++++++++++++++++++++-------------------------
394513
 1 file changed, 168 insertions(+), 142 deletions(-)
394513
394513
--- a/util/ras-mc-ctl.in	2021-10-12 13:45:43.260646935 -0400
394513
+++ b/util/ras-mc-ctl.in	2021-10-12 13:46:38.610158949 -0400
394513
@@ -41,6 +41,16 @@ my $sysconfdir  = "@sysconfdir@";
394513
 my $dmidecode   = find_prog ("dmidecode");
394513
 my $modprobe    = find_prog ("modprobe")  or exit (1);
394513
 
394513
+my $has_aer = 0;
394513
+my $has_arm = 0;
394513
+my $has_extlog = 0;
394513
+my $has_mce = 0;
394513
+
394513
+@WITH_AER_TRUE@$has_aer = 1;
394513
+@WITH_ARM_TRUE@$has_arm = 1;
394513
+@WITH_EXTLOG_TRUE@$has_extlog = 1;
394513
+@WITH_MCE_TRUE@$has_mce = 1;
394513
+
394513
 my %conf        = ();
394513
 my %bus         = ();
394513
 my %dimm_size   = ();
394513
@@ -1145,70 +1155,78 @@ sub summary
394513
     $query_handle->finish;
394513
 
394513
     # PCIe AER aer_event errors
394513
-    $query = "select err_type, err_msg, count(*) from aer_event group by err_type, err_msg";
394513
-    $query_handle = $dbh->prepare($query);
394513
-    $query_handle->execute();
394513
-    $query_handle->bind_columns(\($err_type, $msg, $count));
394513
-    $out = "";
394513
-    while($query_handle->fetch()) {
394513
-        $out .= "\t$count $err_type errors: $msg\n";
394513
-    }
394513
-    if ($out ne "") {
394513
-        print "PCIe AER events summary:\n$out\n";
394513
-    } else {
394513
-        print "No PCIe AER errors.\n\n";
394513
+    if ($has_aer == 1) {
394513
+        $query = "select err_type, err_msg, count(*) from aer_event group by err_type, err_msg";
394513
+        $query_handle = $dbh->prepare($query);
394513
+        $query_handle->execute();
394513
+        $query_handle->bind_columns(\($err_type, $msg, $count));
394513
+        $out = "";
394513
+        while($query_handle->fetch()) {
394513
+            $out .= "\t$count $err_type errors: $msg\n";
394513
+        }
394513
+        if ($out ne "") {
394513
+            print "PCIe AER events summary:\n$out\n";
394513
+        } else {
394513
+            print "No PCIe AER errors.\n\n";
394513
+        }
394513
+        $query_handle->finish;
394513
     }
394513
-    $query_handle->finish;
394513
 
394513
     # ARM processor arm_event errors
394513
-    $query = "select affinity, mpidr, count(*) from arm_event group by affinity, mpidr";
394513
-    $query_handle = $dbh->prepare($query);
394513
-    $query_handle->execute();
394513
-    $query_handle->bind_columns(\($affinity, $mpidr, $count));
394513
-    $out = "";
394513
-    while($query_handle->fetch()) {
394513
-        $out .= "\t$count errors\n";
394513
-    }
394513
-    if ($out ne "") {
394513
-        print "ARM processor events summary:\n$out\n";
394513
-    } else {
394513
-        print "No ARM processor errors.\n\n";
394513
+    if ($has_arm == 1) {
394513
+        $query = "select affinity, mpidr, count(*) from arm_event group by affinity, mpidr";
394513
+        $query_handle = $dbh->prepare($query);
394513
+        $query_handle->execute();
394513
+        $query_handle->bind_columns(\($affinity, $mpidr, $count));
394513
+        $out = "";
394513
+        while($query_handle->fetch()) {
394513
+            $out .= "\t$count errors\n";
394513
+        }
394513
+        if ($out ne "") {
394513
+            print "ARM processor events summary:\n$out\n";
394513
+        } else {
394513
+            print "No ARM processor errors.\n\n";
394513
+        }
394513
+        $query_handle->finish;
394513
     }
394513
-    $query_handle->finish;
394513
 
394513
     # extlog errors
394513
-    $query = "select etype, severity, count(*) from extlog_event group by etype, severity";
394513
-    $query_handle = $dbh->prepare($query);
394513
-    $query_handle->execute();
394513
-    $query_handle->bind_columns(\($etype, $severity, $count));
394513
-    $out = "";
394513
-    while($query_handle->fetch()) {
394513
-        $etype_string = get_extlog_type($etype);
394513
-        $severity_string = get_extlog_severity($severity);
394513
-        $out .= "\t$count $etype_string $severity_string errors\n";
394513
-    }
394513
-    if ($out ne "") {
394513
-        print "Extlog records summary:\n$out";
394513
-    } else {
394513
-        print "No Extlog errors.\n";
394513
+    if ($has_extlog == 1) {
394513
+        $query = "select etype, severity, count(*) from extlog_event group by etype, severity";
394513
+        $query_handle = $dbh->prepare($query);
394513
+        $query_handle->execute();
394513
+        $query_handle->bind_columns(\($etype, $severity, $count));
394513
+        $out = "";
394513
+        while($query_handle->fetch()) {
394513
+            $etype_string = get_extlog_type($etype);
394513
+            $severity_string = get_extlog_severity($severity);
394513
+            $out .= "\t$count $etype_string $severity_string errors\n";
394513
+        }
394513
+        if ($out ne "") {
394513
+            print "Extlog records summary:\n$out";
394513
+        } else {
394513
+            print "No Extlog errors.\n";
394513
+        }
394513
+        $query_handle->finish;
394513
     }
394513
-    $query_handle->finish;
394513
 
394513
     # MCE mce_record errors
394513
-    $query = "select error_msg, count(*) from mce_record group by error_msg";
394513
-    $query_handle = $dbh->prepare($query);
394513
-    $query_handle->execute();
394513
-    $query_handle->bind_columns(\($msg, $count));
394513
-    $out = "";
394513
-    while($query_handle->fetch()) {
394513
-        $out .= "\t$count $msg errors\n";
394513
-    }
394513
-    if ($out ne "") {
394513
-        print "MCE records summary:\n$out";
394513
-    } else {
394513
-        print "No MCE errors.\n";
394513
+    if ($has_mce == 1) {
394513
+        $query = "select error_msg, count(*) from mce_record group by error_msg";
394513
+        $query_handle = $dbh->prepare($query);
394513
+        $query_handle->execute();
394513
+        $query_handle->bind_columns(\($msg, $count));
394513
+        $out = "";
394513
+        while($query_handle->fetch()) {
394513
+            $out .= "\t$count $msg errors\n";
394513
+        }
394513
+        if ($out ne "") {
394513
+            print "MCE records summary:\n$out";
394513
+        } else {
394513
+            print "No MCE errors.\n";
394513
+        }
394513
+        $query_handle->finish;
394513
     }
394513
-    $query_handle->finish;
394513
 
394513
     undef($dbh);
394513
 }
394513
@@ -1244,105 +1262,113 @@ sub errors
394513
     $query_handle->finish;
394513
 
394513
     # PCIe AER aer_event errors
394513
-    $query = "select id, timestamp, err_type, err_msg from aer_event order by id";
394513
-    $query_handle = $dbh->prepare($query);
394513
-    $query_handle->execute();
394513
-    $query_handle->bind_columns(\($id, $time, $type, $msg));
394513
-    $out = "";
394513
-    while($query_handle->fetch()) {
394513
-        $out .= "$id $time $type error: $msg\n";
394513
-    }
394513
-    if ($out ne "") {
394513
-        print "PCIe AER events:\n$out\n";
394513
-    } else {
394513
-        print "No PCIe AER errors.\n\n";
394513
+    if ($has_aer == 1) {
394513
+        $query = "select id, timestamp, err_type, err_msg from aer_event order by id";
394513
+        $query_handle = $dbh->prepare($query);
394513
+        $query_handle->execute();
394513
+        $query_handle->bind_columns(\($id, $time, $type, $msg));
394513
+        $out = "";
394513
+        while($query_handle->fetch()) {
394513
+            $out .= "$id $time $type error: $msg\n";
394513
+        }
394513
+        if ($out ne "") {
394513
+            print "PCIe AER events:\n$out\n";
394513
+        } else {
394513
+            print "No PCIe AER errors.\n\n";
394513
+        }
394513
+        $query_handle->finish;
394513
     }
394513
-    $query_handle->finish;
394513
 
394513
     # ARM processor arm_event errors
394513
-    $query = "select id, timestamp, error_count, affinity, mpidr, running_state, psci_state from arm_event order by id";
394513
-    $query_handle = $dbh->prepare($query);
394513
-    $query_handle->execute();
394513
-    $query_handle->bind_columns(\($id, $timestamp, $error_count, $affinity, $mpidr, $r_state, $psci_state));
394513
-    $out = "";
394513
-    while($query_handle->fetch()) {
394513
-        $out .= "$id $timestamp error: ";
394513
-        $out .= "error_count=$error_count, " if ($error_count);
394513
-        $out .= "affinity_level=$affinity, ";
394513
-        $out .= sprintf "mpidr=0x%x, ", $mpidr;
394513
-        $out .= sprintf "running_state=0x%x, ", $r_state;
394513
-        $out .= sprintf "psci_state=0x%x", $psci_state;
394513
-        $out .= "\n";
394513
-    }
394513
-    if ($out ne "") {
394513
-        print "ARM processor events:\n$out\n";
394513
-    } else {
394513
-        print "No ARM processor errors.\n\n";
394513
+    if ($has_arm == 1) {
394513
+        $query = "select id, timestamp, error_count, affinity, mpidr, running_state, psci_state from arm_event order by id";
394513
+        $query_handle = $dbh->prepare($query);
394513
+        $query_handle->execute();
394513
+        $query_handle->bind_columns(\($id, $timestamp, $error_count, $affinity, $mpidr, $r_state, $psci_state));
394513
+        $out = "";
394513
+        while($query_handle->fetch()) {
394513
+            $out .= "$id $timestamp error: ";
394513
+            $out .= "error_count=$error_count, " if ($error_count);
394513
+            $out .= "affinity_level=$affinity, ";
394513
+            $out .= sprintf "mpidr=0x%x, ", $mpidr;
394513
+            $out .= sprintf "running_state=0x%x, ", $r_state;
394513
+            $out .= sprintf "psci_state=0x%x", $psci_state;
394513
+            $out .= "\n";
394513
+        }
394513
+        if ($out ne "") {
394513
+            print "ARM processor events:\n$out\n";
394513
+        } else {
394513
+            print "No ARM processor errors.\n\n";
394513
+        }
394513
+        $query_handle->finish;
394513
     }
394513
-    $query_handle->finish;
394513
 
394513
     # Extlog errors
394513
-    $query = "select id, timestamp, etype, severity, address, fru_id, fru_text, cper_data from extlog_event order by id";
394513
-    $query_handle = $dbh->prepare($query);
394513
-    $query_handle->execute();
394513
-    $query_handle->bind_columns(\($id, $timestamp, $etype, $severity, $addr, $fru_id, $fru_text, $cper_data));
394513
-    $out = "";
394513
-    while($query_handle->fetch()) {
394513
-        $etype_string = get_extlog_type($etype);
394513
-        $severity_string = get_extlog_severity($severity);
394513
-        $out .= "$id $timestamp error: ";
394513
-        $out .= "type=$etype_string, ";
394513
-        $out .= "severity=$severity_string, ";
394513
-        $out .= sprintf "address=0x%08x, ", $addr;
394513
-        $out .= sprintf "fru_id=%s, ", get_uuid_le($fru_id);
394513
-        $out .= "fru_text='$fru_text', ";
394513
-        $out .= get_cper_data_text($cper_data) if ($cper_data);
394513
-        $out .= "\n";
394513
-    }
394513
-    if ($out ne "") {
394513
-        print "Extlog events:\n$out\n";
394513
-    } else {
394513
-        print "No Extlog errors.\n\n";
394513
+    if ($has_extlog) {
394513
+        $query = "select id, timestamp, etype, severity, address, fru_id, fru_text, cper_data from extlog_event order by id";
394513
+        $query_handle = $dbh->prepare($query);
394513
+        $query_handle->execute();
394513
+        $query_handle->bind_columns(\($id, $timestamp, $etype, $severity, $addr, $fru_id, $fru_text, $cper_data));
394513
+        $out = "";
394513
+        while($query_handle->fetch()) {
394513
+            $etype_string = get_extlog_type($etype);
394513
+            $severity_string = get_extlog_severity($severity);
394513
+            $out .= "$id $timestamp error: ";
394513
+            $out .= "type=$etype_string, ";
394513
+            $out .= "severity=$severity_string, ";
394513
+            $out .= sprintf "address=0x%08x, ", $addr;
394513
+            $out .= sprintf "fru_id=%s, ", get_uuid_le($fru_id);
394513
+            $out .= "fru_text='$fru_text', ";
394513
+            $out .= get_cper_data_text($cper_data) if ($cper_data);
394513
+            $out .= "\n";
394513
+        }
394513
+        if ($out ne "") {
394513
+            print "Extlog events:\n$out\n";
394513
+        } else {
394513
+            print "No Extlog errors.\n\n";
394513
+        }
394513
+        $query_handle->finish;
394513
     }
394513
-    $query_handle->finish;
394513
 
394513
     # MCE mce_record errors
394513
-    $query = "select id, timestamp, mcgcap, mcgstatus, status, addr, misc, ip, tsc, walltime, cpu, cpuid, apicid, socketid, cs, bank, cpuvendor, bank_name, error_msg, mcgstatus_msg, mcistatus_msg, user_action, mc_location from mce_record order by id";
394513
-    $query_handle = $dbh->prepare($query);
394513
-    $query_handle->execute();
394513
-    $query_handle->bind_columns(\($id, $time, $mcgcap,$mcgstatus, $status, $addr, $misc, $ip, $tsc, $walltime, $cpu, $cpuid, $apicid, $socketid, $cs, $bank, $cpuvendor, $bank_name, $msg, $mcgstatus_msg, $mcistatus_msg, $user_action, $mc_location));
394513
-    $out = "";
394513
-    while($query_handle->fetch()) {
394513
-        $out .= "$id $time error: $msg";
394513
-	$out .= ", CPU $cpuvendor" if ($cpuvendor);
394513
-	$out .= ", bank $bank_name" if ($bank_name);
394513
-	$out .= ", mcg $mcgstatus_msg" if ($mcgstatus_msg);
394513
-	$out .= ", mci $mcistatus_msg" if ($mcistatus_msg);
394513
-	$out .= ", $mc_location" if ($mc_location);
394513
-	$out .= ", $user_action" if ($user_action);
394513
-	$out .= sprintf ", mcgcap=0x%08x", $mcgcap if ($mcgcap);
394513
-	$out .= sprintf ", mcgstatus=0x%08x", $mcgstatus if ($mcgstatus);
394513
-	$out .= sprintf ", status=0x%08x", $status if ($status);
394513
-	$out .= sprintf ", addr=0x%08x", $addr if ($addr);
394513
-	$out .= sprintf ", misc=0x%08x", $misc if ($misc);
394513
-	$out .= sprintf ", ip=0x%08x", $ip if ($ip);
394513
-	$out .= sprintf ", tsc=0x%08x", $tsc if ($tsc);
394513
-	$out .= sprintf ", walltime=0x%08x", $walltime if ($walltime);
394513
-	$out .= sprintf ", cpu=0x%08x", $cpu if ($cpu);
394513
-	$out .= sprintf ", cpuid=0x%08x", $cpuid if ($cpuid);
394513
-	$out .= sprintf ", apicid=0x%08x", $apicid if ($apicid);
394513
-	$out .= sprintf ", socketid=0x%08x", $socketid if ($socketid);
394513
-	$out .= sprintf ", cs=0x%08x", $cs if ($cs);
394513
-	$out .= sprintf ", bank=0x%08x", $bank if ($bank);
394513
+    if ($has_mce == 1) {
394513
+        $query = "select id, timestamp, mcgcap, mcgstatus, status, addr, misc, ip, tsc, walltime, cpu, cpuid, apicid, socketid, cs, bank, cpuvendor, bank_name, error_msg, mcgstatus_msg, mcistatus_msg, user_action, mc_location from mce_record order by id";
394513
+        $query_handle = $dbh->prepare($query);
394513
+        $query_handle->execute();
394513
+        $query_handle->bind_columns(\($id, $time, $mcgcap,$mcgstatus, $status, $addr, $misc, $ip, $tsc, $walltime, $cpu, $cpuid, $apicid, $socketid, $cs, $bank, $cpuvendor, $bank_name, $msg, $mcgstatus_msg, $mcistatus_msg, $user_action, $mc_location));
394513
+        $out = "";
394513
+        while($query_handle->fetch()) {
394513
+            $out .= "$id $time error: $msg";
394513
+        $out .= ", CPU $cpuvendor" if ($cpuvendor);
394513
+        $out .= ", bank $bank_name" if ($bank_name);
394513
+        $out .= ", mcg $mcgstatus_msg" if ($mcgstatus_msg);
394513
+        $out .= ", mci $mcistatus_msg" if ($mcistatus_msg);
394513
+        $out .= ", $mc_location" if ($mc_location);
394513
+        $out .= ", $user_action" if ($user_action);
394513
+        $out .= sprintf ", mcgcap=0x%08x", $mcgcap if ($mcgcap);
394513
+        $out .= sprintf ", mcgstatus=0x%08x", $mcgstatus if ($mcgstatus);
394513
+        $out .= sprintf ", status=0x%08x", $status if ($status);
394513
+        $out .= sprintf ", addr=0x%08x", $addr if ($addr);
394513
+        $out .= sprintf ", misc=0x%08x", $misc if ($misc);
394513
+        $out .= sprintf ", ip=0x%08x", $ip if ($ip);
394513
+        $out .= sprintf ", tsc=0x%08x", $tsc if ($tsc);
394513
+        $out .= sprintf ", walltime=0x%08x", $walltime if ($walltime);
394513
+        $out .= sprintf ", cpu=0x%08x", $cpu if ($cpu);
394513
+        $out .= sprintf ", cpuid=0x%08x", $cpuid if ($cpuid);
394513
+        $out .= sprintf ", apicid=0x%08x", $apicid if ($apicid);
394513
+        $out .= sprintf ", socketid=0x%08x", $socketid if ($socketid);
394513
+        $out .= sprintf ", cs=0x%08x", $cs if ($cs);
394513
+        $out .= sprintf ", bank=0x%08x", $bank if ($bank);
394513
 
394513
-	$out .= "\n";
394513
-    }
394513
-    if ($out ne "") {
394513
-        print "MCE events:\n$out\n";
394513
-    } else {
394513
-        print "No MCE errors.\n\n";
394513
+        $out .= "\n";
394513
+        }
394513
+        if ($out ne "") {
394513
+            print "MCE events:\n$out\n";
394513
+        } else {
394513
+            print "No MCE errors.\n\n";
394513
+        }
394513
+        $query_handle->finish;
394513
     }
394513
-    $query_handle->finish;
394513
 
394513
     undef($dbh);
394513
 }