^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1) #!/usr/bin/env python
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2) # SPDX-License-Identifier: GPL-2.0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4) import os
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5) from optparse import OptionParser
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7) help_msg = "print verbose messages. Try -vv, -vvv for more verbose messages"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8) parser = OptionParser()
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9) parser.add_option(
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10) "-v", "--verbose", dest="verbose", help=help_msg, action="count")
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12) (options, args) = parser.parse_args()
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14) verbose = 0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15) if options.verbose is not None:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16) verbose = options.verbose
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18) vmbus_sys_path = '/sys/bus/vmbus/devices'
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19) if not os.path.isdir(vmbus_sys_path):
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20) print("%s doesn't exist: exiting..." % vmbus_sys_path)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 21) exit(-1)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 22)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 23) vmbus_dev_dict = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 24) '{0e0b6031-5213-4934-818b-38d90ced39db}': '[Operating system shutdown]',
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 25) '{9527e630-d0ae-497b-adce-e80ab0175caf}': '[Time Synchronization]',
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 26) '{57164f39-9115-4e78-ab55-382f3bd5422d}': '[Heartbeat]',
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 27) '{a9a0f4e7-5a45-4d96-b827-8a841e8c03e6}': '[Data Exchange]',
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 28) '{35fa2e29-ea23-4236-96ae-3a6ebacba440}': '[Backup (volume checkpoint)]',
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 29) '{34d14be3-dee4-41c8-9ae7-6b174977c192}': '[Guest services]',
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 30) '{525074dc-8985-46e2-8057-a307dc18a502}': '[Dynamic Memory]',
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 31) '{cfa8b69e-5b4a-4cc0-b98b-8ba1a1f3f95a}': 'Synthetic mouse',
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 32) '{f912ad6d-2b17-48ea-bd65-f927a61c7684}': 'Synthetic keyboard',
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 33) '{da0a7802-e377-4aac-8e77-0558eb1073f8}': 'Synthetic framebuffer adapter',
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 34) '{f8615163-df3e-46c5-913f-f2d2f965ed0e}': 'Synthetic network adapter',
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 35) '{32412632-86cb-44a2-9b5c-50d1417354f5}': 'Synthetic IDE Controller',
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 36) '{ba6163d9-04a1-4d29-b605-72e2ffb1dc7f}': 'Synthetic SCSI Controller',
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 37) '{2f9bcc4a-0069-4af3-b76b-6fd0be528cda}': 'Synthetic fiber channel adapter',
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 38) '{8c2eaf3d-32a7-4b09-ab99-bd1f1c86b501}': 'Synthetic RDMA adapter',
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 39) '{44c4f61d-4444-4400-9d52-802e27ede19f}': 'PCI Express pass-through',
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 40) '{276aacf4-ac15-426c-98dd-7521ad3f01fe}': '[Reserved system device]',
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 41) '{f8e65716-3cb3-4a06-9a60-1889c5cccab5}': '[Reserved system device]',
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 42) '{3375baf4-9e15-4b30-b765-67acb10d607b}': '[Reserved system device]',
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 43) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 44)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 45)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 46) def get_vmbus_dev_attr(dev_name, attr):
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 47) try:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 48) f = open('%s/%s/%s' % (vmbus_sys_path, dev_name, attr), 'r')
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 49) lines = f.readlines()
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 50) f.close()
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 51) except IOError:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 52) lines = []
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 53)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 54) return lines
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 55)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 56)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 57) class VMBus_Dev:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 58) pass
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 59)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 60)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 61) vmbus_dev_list = []
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 62)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 63) for f in os.listdir(vmbus_sys_path):
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 64) vmbus_id = get_vmbus_dev_attr(f, 'id')[0].strip()
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 65) class_id = get_vmbus_dev_attr(f, 'class_id')[0].strip()
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 66) device_id = get_vmbus_dev_attr(f, 'device_id')[0].strip()
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 67) dev_desc = vmbus_dev_dict.get(class_id, 'Unknown')
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 68)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 69) chn_vp_mapping = get_vmbus_dev_attr(f, 'channel_vp_mapping')
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 70) chn_vp_mapping = [c.strip() for c in chn_vp_mapping]
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 71) chn_vp_mapping = sorted(
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 72) chn_vp_mapping, key=lambda c: int(c.split(':')[0]))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 73)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 74) chn_vp_mapping = [
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 75) '\tRel_ID=%s, target_cpu=%s' %
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 76) (c.split(':')[0], c.split(':')[1]) for c in chn_vp_mapping
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 77) ]
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 78) d = VMBus_Dev()
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 79) d.sysfs_path = '%s/%s' % (vmbus_sys_path, f)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 80) d.vmbus_id = vmbus_id
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 81) d.class_id = class_id
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 82) d.device_id = device_id
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 83) d.dev_desc = dev_desc
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 84) d.chn_vp_mapping = '\n'.join(chn_vp_mapping)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 85) if d.chn_vp_mapping:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 86) d.chn_vp_mapping += '\n'
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 87)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 88) vmbus_dev_list.append(d)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 89)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 90)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 91) vmbus_dev_list = sorted(vmbus_dev_list, key=lambda d: int(d.vmbus_id))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 92)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 93) format0 = '%2s: %s'
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 94) format1 = '%2s: Class_ID = %s - %s\n%s'
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 95) format2 = '%2s: Class_ID = %s - %s\n\tDevice_ID = %s\n\tSysfs path: %s\n%s'
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 96)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 97) for d in vmbus_dev_list:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 98) if verbose == 0:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 99) print(('VMBUS ID ' + format0) % (d.vmbus_id, d.dev_desc))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100) elif verbose == 1:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101) print(
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 102) ('VMBUS ID ' + format1) %
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 103) (d.vmbus_id, d.class_id, d.dev_desc, d.chn_vp_mapping)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 104) )
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 105) else:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 106) print(
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 107) ('VMBUS ID ' + format2) %
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 108) (
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 109) d.vmbus_id, d.class_id, d.dev_desc,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 110) d.device_id, d.sysfs_path, d.chn_vp_mapping
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 111) )
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 112) )