Blame SOURCES/546cf713f667437fb6e283cc3dc090679eb47d08.patch

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