krishnanadh / rpms / rasdaemon

Forked from rpms/rasdaemon a year ago
Clone

Blame SOURCES/0051-rasdaemon-add-support-to-match-the-machine-by-system.patch

ac32bf
From 3a38f8e66a2aa5c477cea152e1acc9a781834b83 Mon Sep 17 00:00:00 2001
ac32bf
From: Aristeu Rozanski <aris@redhat.com>
ac32bf
Date: Mon, 1 Jun 2015 17:04:00 -0300
ac32bf
Subject: [PATCH 11/13] rasdaemon: add support to match the machine by system's
ac32bf
 product name
ac32bf
ac32bf
In some cases the motherboard names will change but the mapping won't
ac32bf
across a line of products. This patch adds support for "Product:" to be
ac32bf
specified in the label files instead of Model:.
ac32bf
ac32bf
An example:
ac32bf
	Vendor: Dell Inc.
ac32bf
	  Product: PowerEdge R610
ac32bf
	    DIMM_A1: 0.0.0;     DIMM_A2:  0.0.1;        DIMM_A3:  0.0.2;
ac32bf
	    DIMM_A4: 0.1.0;     DIMM_A5:  0.1.1;        DIMM_A6:  0.1.2;
ac32bf
ac32bf
	    DIMM_B1: 1.0.0;     DIMM_B2:  1.0.1;        DIMM_B3:  1.0.2;
ac32bf
	    DIMM_B4: 1.1.0;     DIMM_B5:  1.1.1;        DIMM_B6:  1.1.2;
ac32bf
ac32bf
Would match all 'PowerEdge R610' machines.
ac32bf
ac32bf
Signed-off-by: Aristeu Rozanski <arozansk@redhat.com>
ac32bf
Signed-off-by: Mauro Carvalho Chehab <mchehab@osg.samsung.com>
ac32bf
---
ac32bf
 util/ras-mc-ctl.in | 127 +++++++++++++++++++++++++++++++++++++++++------------
ac32bf
 1 file changed, 98 insertions(+), 29 deletions(-)
ac32bf
ac32bf
diff --git a/util/ras-mc-ctl.in b/util/ras-mc-ctl.in
ac32bf
index 7b6d798..6350f62 100755
ac32bf
--- a/util/ras-mc-ctl.in
ac32bf
+++ b/util/ras-mc-ctl.in
ac32bf
@@ -288,8 +288,27 @@ sub parse_dimm_nodes
ac32bf
     }
ac32bf
 }
ac32bf
 
ac32bf
+sub guess_product {
ac32bf
+    my $pvendor = undef;
ac32bf
+    my $pname = undef;
ac32bf
+
ac32bf
+    if (open (VENDOR, "/sys/class/dmi/id/product_vendor")) {
ac32bf
+        $pvendor = <VENDOR>;
ac32bf
+        close VENDOR;
ac32bf
+        chomp($pvendor);
ac32bf
+    }
ac32bf
+    if (open (NAME, "/sys/class/dmi/id/product_name")) {
ac32bf
+        $pname = <NAME>;
ac32bf
+        close NAME;
ac32bf
+        chomp($pname);
ac32bf
+    }
ac32bf
+
ac32bf
+    return ($pvendor, $pname);
ac32bf
+}
ac32bf
+
ac32bf
 sub get_mainboard_info {
ac32bf
     my ($vendor, $model);
ac32bf
+    my ($pvendor, $pname);
ac32bf
 
ac32bf
     if ($conf{opt}{mainboard} && $conf{opt}{mainboard} ne "report") {
ac32bf
         ($vendor, $model) = split (/[: ]/, $conf{opt}{mainboard}, 2);
ac32bf
@@ -301,6 +320,15 @@ sub get_mainboard_info {
ac32bf
 
ac32bf
     $conf{mainboard}{vendor} = $vendor;
ac32bf
     $conf{mainboard}{model}  = $model;
ac32bf
+
ac32bf
+    ($pvendor, $pname) = guess_product ();
ac32bf
+    # since product vendor is rare, use mainboard's vendor
ac32bf
+    if ($pvendor) {
ac32bf
+        $conf{mainboard}{product_vendor} = $pvendor;
ac32bf
+    } else {
ac32bf
+        $conf{mainboard}{product_vendor} = $vendor;
ac32bf
+    }
ac32bf
+    $conf{mainboard}{product_name} = $pname if $pname;
ac32bf
 }
ac32bf
 
ac32bf
 sub guess_vendor_model_dmidecode {
ac32bf
@@ -449,10 +477,11 @@ sub guess_dimm_label {
ac32bf
 
ac32bf
 sub parse_dimm_labels_file
ac32bf
 {
ac32bf
-    my ($lh, $num_layers, $file) = (@_);
ac32bf
+    my ($lh, $num_layers, $lh_prod, $num_layers_prod, $file) = (@_);
ac32bf
     my $line = -1;
ac32bf
     my $vendor = "";
ac32bf
     my @models = ();
ac32bf
+    my @products = ();
ac32bf
     my $num;
ac32bf
 
ac32bf
     open (LABELS, "$file")
ac32bf
@@ -469,12 +498,21 @@ sub parse_dimm_labels_file
ac32bf
         if (/vendor\s*:\s*(.*\S)\s*/i) {
ac32bf
             $vendor = lc $1;
ac32bf
             @models = ();
ac32bf
+            @products = ();
ac32bf
             $num = 0;
ac32bf
             next;
ac32bf
         }
ac32bf
         if (/(model|board)\s*:\s*(.*)$/i) {
ac32bf
             !$vendor && die "$file: line $line: MB model without vendor\n";
ac32bf
             @models = grep { s/\s*(.*)\s*$/$1/ } split(/[,;]+/, $2);
ac32bf
+            @products = ();
ac32bf
+            $num = 0;
ac32bf
+            next;
ac32bf
+        }
ac32bf
+        if (/(product)\s*:\s*(.*)$/i) {
ac32bf
+            !$vendor && die "$file: line $line: product without vendor\n";
ac32bf
+            @models = ();
ac32bf
+            @products = grep { s/\s*(.*)\s*$/$1/ } split(/[,;]+/, $2);
ac32bf
             $num = 0;
ac32bf
             next;
ac32bf
         }
ac32bf
@@ -513,10 +551,13 @@ sub parse_dimm_labels_file
ac32bf
                     }
ac32bf
                     map { $lh->{$vendor}{lc $_}{$mc}{$top}{$mid}{$low} = $label }
ac32bf
                             @models;
ac32bf
+                    map { $lh_prod->{$vendor}{lc $_}{$mc}{$top}{$mid}{$low} = $label }
ac32bf
+                            @products;
ac32bf
                 }
ac32bf
                 if (!$num) {
ac32bf
                         $num = $n;
ac32bf
                         map { $num_layers->{$vendor}{lc $_} = $num } @models;
ac32bf
+                        map { $num_layers_prod->{$vendor}{lc $_} = $num } @products;
ac32bf
                 } elsif ($num != $n) {
ac32bf
                         die ("Error: Inconsistent number of layers at label db \"$file\"\n");
ac32bf
                 }
ac32bf
@@ -531,6 +572,8 @@ sub parse_dimm_labels
ac32bf
 {
ac32bf
     my %labels = ();
ac32bf
     my %num_layers = ();
ac32bf
+    my %labels_prod = ();
ac32bf
+    my %num_layers_prod = ();
ac32bf
 
ac32bf
     #
ac32bf
     #  Accrue all DIMM labels from the labels.db file, as
ac32bf
@@ -538,10 +581,10 @@ sub parse_dimm_labels
ac32bf
     #
ac32bf
     for my $file ($conf{labeldb}, <$conf{labeldir}/*>) {
ac32bf
         next unless -r $file;
ac32bf
-        parse_dimm_labels_file (\%labels, \%num_layers, $file);
ac32bf
+        parse_dimm_labels_file (\%labels, \%num_layers, \%labels_prod, \%num_layers_prod, $file);
ac32bf
     }
ac32bf
 
ac32bf
-    return (\%labels, \%num_layers);
ac32bf
+    return (\%labels, \%num_layers, \%labels_prod, \%num_layers_prod);
ac32bf
 }
ac32bf
 
ac32bf
 sub read_dimm_label
ac32bf
@@ -598,25 +641,9 @@ sub get_dimm_label_node
ac32bf
 }
ac32bf
 
ac32bf
 
ac32bf
-sub print_dimm_labels
ac32bf
+sub _print_dimm_labels
ac32bf
 {
ac32bf
-    my $fh = shift || *STDOUT;
ac32bf
-    my ($lref, $num_layers) = parse_dimm_labels ();
ac32bf
-    my $vendor = lc $conf{mainboard}{vendor};
ac32bf
-    my $model  = lc $conf{mainboard}{model};
ac32bf
-    my $format = "%-35s %-20s %-20s\n";
ac32bf
-
ac32bf
-    if (!exists $$lref{$vendor}{$model}) {
ac32bf
-        log_error ("No dimm labels for $conf{mainboard}{vendor} " .
ac32bf
-                   "model $conf{mainboard}{model}\n");
ac32bf
-        return;
ac32bf
-    }
ac32bf
-
ac32bf
-    my $sysfs_dir = "/sys/devices/system/edac/mc";
ac32bf
-
ac32bf
-    find({wanted => \&parse_dimm_nodes, no_chdir => 1}, $sysfs_dir);
ac32bf
-
ac32bf
-    printf $fh $format, "LOCATION", "CONFIGURED LABEL", "SYSFS CONTENTS";
ac32bf
+    my ($lref, $num_layers, $vendor, $model, $fh, $format) = @_;
ac32bf
 
ac32bf
     for my $mc (sort keys %{$$lref{$vendor}{$model}}) {
ac32bf
         for my $top (sort keys %{$$lref{$vendor}{$model}{$mc}}) {
ac32bf
@@ -631,26 +658,40 @@ sub print_dimm_labels
ac32bf
         }
ac32bf
     }
ac32bf
     print $fh "\n";
ac32bf
-
ac32bf
 }
ac32bf
 
ac32bf
-sub register_dimm_labels
ac32bf
+sub print_dimm_labels
ac32bf
 {
ac32bf
-    my ($lref, $num_layers) = parse_dimm_labels ();
ac32bf
+    my $fh = shift || *STDOUT;
ac32bf
+    my ($lref, $num_layers, $lref_prod, $num_layers_prod) = parse_dimm_labels ();
ac32bf
     my $vendor = lc $conf{mainboard}{vendor};
ac32bf
     my $model  = lc $conf{mainboard}{model};
ac32bf
-    my $sysfs  = "/sys/devices/system/edac/mc";
ac32bf
+    my $pvendor = lc $conf{mainboard}{product_vendor};
ac32bf
+    my $pname = lc $conf{mainboard}{product_name};
ac32bf
+    my $format = "%-35s %-20s %-20s\n";
ac32bf
 
ac32bf
-    if (!exists $$lref{$vendor}{$model}) {
ac32bf
+    if (!exists $$lref{$vendor}{$model} && !exists $$lref_prod{$pvendor}{$pname}) {
ac32bf
         log_error ("No dimm labels for $conf{mainboard}{vendor} " .
ac32bf
-                                      "model $conf{mainboard}{model}\n");
ac32bf
-        return 0;
ac32bf
+                   "model $conf{mainboard}{model}\n");
ac32bf
+        return;
ac32bf
     }
ac32bf
+
ac32bf
     my $sysfs_dir = "/sys/devices/system/edac/mc";
ac32bf
 
ac32bf
     find({wanted => \&parse_dimm_nodes, no_chdir => 1}, $sysfs_dir);
ac32bf
 
ac32bf
-    select (undef, undef, undef, $conf{opt}{delay});
ac32bf
+    printf $fh $format, "LOCATION", "CONFIGURED LABEL", "SYSFS CONTENTS";
ac32bf
+
ac32bf
+    if (exists $$lref{$vendor}{$model}) {
ac32bf
+        _print_dimm_labels($lref, $num_layers, $vendor, $model, $fh, $format);
ac32bf
+    } elsif (exists $$lref_prod{$pvendor}{$pname}) {
ac32bf
+        _print_dimm_labels($lref_prod, $num_layers_prod, $pvendor, $pname, $fh, $format);
ac32bf
+    }
ac32bf
+}
ac32bf
+
ac32bf
+sub write_dimm_labels
ac32bf
+{
ac32bf
+    my ($lref, $num_layers, $vendor, $model) = @_;
ac32bf
 
ac32bf
     for my $mc (sort keys %{$$lref{$vendor}{$model}}) {
ac32bf
         for my $top (sort keys %{$$lref{$vendor}{$model}{$mc}}) {
ac32bf
@@ -675,6 +716,34 @@ sub register_dimm_labels
ac32bf
             }
ac32bf
         }
ac32bf
     }
ac32bf
+}
ac32bf
+
ac32bf
+sub register_dimm_labels
ac32bf
+{
ac32bf
+    my ($lref, $num_layers, $lref_prod, $num_layers_prod) = parse_dimm_labels ();
ac32bf
+    my $vendor = lc $conf{mainboard}{vendor};
ac32bf
+    my $model  = lc $conf{mainboard}{model};
ac32bf
+    my $pvendor = lc $conf{mainboard}{product_vendor};
ac32bf
+    my $pname = lc $conf{mainboard}{product_name};
ac32bf
+    my $sysfs  = "/sys/devices/system/edac/mc";
ac32bf
+
ac32bf
+    if (!exists $$lref{$vendor}{$model} && !exists $$lref_prod{$pvendor}{$pname}) {
ac32bf
+        log_error ("No dimm labels for $conf{mainboard}{vendor} " .
ac32bf
+                                      "model $conf{mainboard}{model}\n");
ac32bf
+        return 0;
ac32bf
+    }
ac32bf
+    my $sysfs_dir = "/sys/devices/system/edac/mc";
ac32bf
+
ac32bf
+    find({wanted => \&parse_dimm_nodes, no_chdir => 1}, $sysfs_dir);
ac32bf
+
ac32bf
+    select (undef, undef, undef, $conf{opt}{delay});
ac32bf
+
ac32bf
+    if (exists $$lref{$vendor}{$model}) {
ac32bf
+        write_dimm_labels($lref, $num_layers, $vendor, $model);
ac32bf
+    } else {
ac32bf
+        write_dimm_labels($lref_prod, $num_layers_prod, $pvendor, $pname);
ac32bf
+    }
ac32bf
+
ac32bf
     return 1;
ac32bf
 }
ac32bf
 
ac32bf
-- 
ac32bf
1.8.3.1
ac32bf