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

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