Blame SOURCES/sos-bz1853700-pci-too-strong-condition.patch

bceef4
From c5a3dd0fb1e256772d83f19bc458e79b2cf5baf7 Mon Sep 17 00:00:00 2001
bceef4
From: Jake Hunsaker <jhunsake@redhat.com>
bceef4
Date: Fri, 3 Jul 2020 12:24:10 -0400
bceef4
Subject: [PATCH] [pci] Update gating for lspci commands
bceef4
bceef4
It was reported that certain arches may create subdir structures under
bceef4
/proc/bus/pci differently than others - most notably that the first
bceef4
device subdir could be '0000:00' instead of just '00'.
bceef4
bceef4
Rather than chase these different layouts, update the gating check for
bceef4
running `lspci` commands to being that /proc/bus/pci exists and it has
bceef4
more than just the `devices` file present, as this file may be present
bceef4
but empty when nothing else exists under `/proc/bus/pci`.
bceef4
bceef4
This is the legacy-3.9 backport from #2138
bceef4
bceef4
Signed-off-by: Jake Hunsaker <jhunsake@redhat.com>
bceef4
---
bceef4
 sos/plugins/pci.py | 12 +++++++++++-
bceef4
 1 file changed, 11 insertions(+), 1 deletion(-)
bceef4
bceef4
diff --git a/sos/plugins/pci.py b/sos/plugins/pci.py
bceef4
index ac90f09d..053307cd 100644
bceef4
--- a/sos/plugins/pci.py
bceef4
+++ b/sos/plugins/pci.py
bceef4
@@ -17,6 +17,16 @@ class Pci(Plugin, RedHatPlugin, UbuntuPlugin, DebianPlugin):
bceef4
     plugin_name = "pci"
bceef4
     profiles = ('hardware', 'system')
bceef4
 
bceef4
+    def check_for_bus_devices(self):
bceef4
+        if not os.path.isdir('/proc/bus/pci'):
bceef4
+            return False
bceef4
+        # ensure that more than just the 'devices' file, which can be empty,
bceef4
+        # exists in the pci directory. This implies actual devices are present
bceef4
+        content = os.listdir('/proc/bus/pci')
bceef4
+        if 'devices' in content:
bceef4
+            content.remove('devices')
bceef4
+        return len(content) > 0
bceef4
+
bceef4
     def setup(self):
bceef4
         self.add_copy_spec([
bceef4
             "/proc/ioports",
bceef4
@@ -24,7 +34,7 @@ class Pci(Plugin, RedHatPlugin, UbuntuPlugin, DebianPlugin):
bceef4
             "/proc/bus/pci"
bceef4
         ])
bceef4
 
bceef4
-        if os.path.isdir("/proc/bus/pci/00"):
bceef4
+        if self.check_for_bus_devices():
bceef4
             self.add_cmd_output("lspci -nnvv", root_symlink="lspci")
bceef4
             self.add_cmd_output("lspci -tv")
bceef4
 
bceef4
-- 
bceef4
2.26.2
bceef4