Blame SOURCES/546cf713f667437fb6e283cc3dc090679eb47d08.patch

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