Blame SOURCES/sos-bz1853701-pci_gating_for_lspci.patch

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