Skip to content

Commit e3069f7

Browse files
Merge pull request #6 from stephenchengCloud/private/stephenche/CP-47959
CP-47959: Parse lspci-vv for driver information
2 parents 5b29574 + 4121cb6 commit e3069f7

File tree

3 files changed

+28
-1
lines changed

3 files changed

+28
-1
lines changed

hwinfo/pci/__init__.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,9 @@ def get_subvendor_name(self):
7676
def get_subvendor_id(self):
7777
return self._fmt(self.lookup_value('pci_subvendor_id'))
7878

79+
def get_driver(self):
80+
return self._fmt(self.lookup_value('pci_device_driver'))
81+
7982
def get_pci_id(self):
8083
return "%s:%s %s:%s" % (
8184
self._fmt(self.lookup_value('pci_vendor_id')),
@@ -109,5 +112,6 @@ def get_rec(self):
109112
rec['subdevice_name'] = self.get_subdevice_name()
110113
rec['subvendor_id'] = self.get_subvendor_id()
111114
rec['subdevice_id'] = self.get_subdevice_id()
115+
rec['driver'] = self.get_driver()
112116

113117
return rec

hwinfo/pci/lspci.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ class LspciVVParser(CommandParser):
1616
r'(?P<pci_device_bus_id>(' + BUSID_REGEX + r'))\ (?P<pci_device_class_name>' + LABEL_REGEX + r'):\ (?P<pci_device_string>(.*))\n',
1717
r'Product\ Name:\ (?P<pci_device_vpd_product_name>(.)*)\n',
1818
r'Subsystem:\ (?P<pci_device_sub_string>(.)*)\n',
19+
r'Kernel driver in use:\ (?P<pci_device_driver>\S+)\n',
1920
]
2021

2122
ITEM_SEPERATOR = "\n\n"
@@ -24,6 +25,7 @@ class LspciVVParser(CommandParser):
2425
'pci_device_bus_id',
2526
'pci_device_class_name',
2627
'pci_device_string',
28+
'pci_device_driver',
2729
]
2830

2931
class LspciNParser(CommandParser):

hwinfo/tools/inspector.py

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,9 @@ def exec_command(self, cmd):
112112

113113
def get_lspci_data(self):
114114
return self.exec_command(['lspci', '-nnmm'])
115+
116+
def get_lspci_vv_data(self):
117+
return self.exec_command(['lspci', '-vv'])
115118

116119
def get_dmidecode_data(self):
117120
return self.exec_command(['dmidecode'])
@@ -134,6 +137,16 @@ def get_pci_devices(self):
134137
data = self.get_lspci_data()
135138
parser = LspciNNMMParser(data)
136139
devices = parser.parse_items()
140+
# Parse also lspci -vv for driver information
141+
data = self.get_lspci_vv_data()
142+
parser = LspciVVParser(data)
143+
devices_vv = parser.parse_items()
144+
driver_info = {d['pci_device_bus_id']: d.get('pci_device_driver') for d in devices_vv if 'pci_device_bus_id' in d}
145+
# Add driver information to devices
146+
for device in devices:
147+
bus_id = device.get('pci_device_bus_id')
148+
if bus_id and bus_id in driver_info:
149+
device['pci_device_driver'] = driver_info[bus_id]
137150
return [PCIDevice(device) for device in devices]
138151

139152
def get_info(self):
@@ -206,6 +219,9 @@ def _load_from_file(self, filename):
206219

207220
def get_lspci_data(self):
208221
return self._load_from_file('lspci-nnm.out')
222+
223+
def get_lspci_vv_data(self):
224+
return self._load_from_file('lspci-vv.out')
209225

210226
def get_dmidecode_data(self):
211227
return self._load_from_file('dmidecode.out')
@@ -360,7 +376,7 @@ def system_info(host, options):
360376

361377
return "".join(info).strip()
362378

363-
def export_system_info(host, options):
379+
def system_info_as_dict(host, options):
364380
rec = {}
365381

366382
if 'bios' in options:
@@ -381,6 +397,11 @@ def export_system_info(host, options):
381397
devices = pci_filter_for_gpu(host.get_pci_devices())
382398
rec["gpus"] = [dev.get_rec() for dev in devices]
383399

400+
return rec
401+
402+
def export_system_info(host, options):
403+
rec = system_info_as_dict(host, options)
404+
384405
return json.dumps(rec, indent=4, separators=(',', ': '))
385406

386407
def main():

0 commit comments

Comments
 (0)