krishnanadh / rpms / rasdaemon

Forked from rpms/rasdaemon a year ago
Clone

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

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