Skip to content

Commit

Permalink
Patch to get the location code of any pci device
Browse files Browse the repository at this point in the history
Location code is used to trigger eeh injections on any pci device in kvm environment

Patch is used to get the location code of the pci devices using there pci id's

Signed-off-by: Tasmiya Nalatwad <[email protected]>
  • Loading branch information
TasmiyaNalatwad committed Dec 31, 2024
1 parent 80ca89f commit 5d3ba98
Showing 1 changed file with 25 additions and 0 deletions.
25 changes: 25 additions & 0 deletions virttest/utils_misc.py
Original file line number Diff line number Diff line change
Expand Up @@ -4599,3 +4599,28 @@ def _md5(fd):
if _md5(fd_a) == _md5(fd_b):
return True
return False


def get_location_code(pci_id):
"""
Retrieves the location code for a PCI device using the `cat` command.
:param device : The PCI device address in the format 'xxxx:xx:xx.x'.
:return: location code if available, or an error message.
"""
try:
# Construct the path
pci_id = pci_id.replace(":", "\\:")
loc_code_path = "/sys/bus/pci/devices/%s/of_node/ibm,loc-code" % pci_id

# Execute the cat command and capture the output
loc_code = process.run("cat %s" % loc_code_path, shell=True)
loc_code = ''.join(
c for c in loc_code.stdout_text.strip() if 0x20 <= ord(c) <= 0x7E)
logging.debug("The location code of the pci device is %s" % loc_code)
return loc_code

except FileNotFoundError:
return "Location code file not found for device %s." % pci_id
except Exception as e:
return "An error occurred: %s" % e

0 comments on commit 5d3ba98

Please sign in to comment.