|
|
3feead |
#!/usr/bin/env python
|
|
|
3feead |
# SPDX-License-Identifier: GPL-2.0
|
|
|
3feead |
|
|
|
3feead |
import os
|
|
|
3feead |
from optparse import OptionParser
|
|
|
3feead |
|
|
|
3feead |
help_msg = "print verbose messages. Try -vv, -vvv for more verbose messages"
|
|
|
3feead |
parser = OptionParser()
|
|
|
3feead |
parser.add_option(
|
|
|
3feead |
"-v", "--verbose", dest="verbose", help=help_msg, action="count")
|
|
|
3feead |
|
|
|
3feead |
(options, args) = parser.parse_args()
|
|
|
3feead |
|
|
|
3feead |
verbose = 0
|
|
|
3feead |
if options.verbose is not None:
|
|
|
3feead |
verbose = options.verbose
|
|
|
3feead |
|
|
|
3feead |
vmbus_sys_path = '/sys/bus/vmbus/devices'
|
|
|
3feead |
if not os.path.isdir(vmbus_sys_path):
|
|
|
3feead |
print("%s doesn't exist: exiting..." % vmbus_sys_path)
|
|
|
3feead |
exit(-1)
|
|
|
3feead |
|
|
|
3feead |
vmbus_dev_dict = {
|
|
|
3feead |
'{0e0b6031-5213-4934-818b-38d90ced39db}': '[Operating system shutdown]',
|
|
|
3feead |
'{9527e630-d0ae-497b-adce-e80ab0175caf}': '[Time Synchronization]',
|
|
|
3feead |
'{57164f39-9115-4e78-ab55-382f3bd5422d}': '[Heartbeat]',
|
|
|
3feead |
'{a9a0f4e7-5a45-4d96-b827-8a841e8c03e6}': '[Data Exchange]',
|
|
|
3feead |
'{35fa2e29-ea23-4236-96ae-3a6ebacba440}': '[Backup (volume checkpoint)]',
|
|
|
3feead |
'{34d14be3-dee4-41c8-9ae7-6b174977c192}': '[Guest services]',
|
|
|
3feead |
'{525074dc-8985-46e2-8057-a307dc18a502}': '[Dynamic Memory]',
|
|
|
3feead |
'{cfa8b69e-5b4a-4cc0-b98b-8ba1a1f3f95a}': 'Synthetic mouse',
|
|
|
3feead |
'{f912ad6d-2b17-48ea-bd65-f927a61c7684}': 'Synthetic keyboard',
|
|
|
3feead |
'{da0a7802-e377-4aac-8e77-0558eb1073f8}': 'Synthetic framebuffer adapter',
|
|
|
3feead |
'{f8615163-df3e-46c5-913f-f2d2f965ed0e}': 'Synthetic network adapter',
|
|
|
3feead |
'{32412632-86cb-44a2-9b5c-50d1417354f5}': 'Synthetic IDE Controller',
|
|
|
3feead |
'{ba6163d9-04a1-4d29-b605-72e2ffb1dc7f}': 'Synthetic SCSI Controller',
|
|
|
3feead |
'{2f9bcc4a-0069-4af3-b76b-6fd0be528cda}': 'Synthetic fiber channel adapter',
|
|
|
3feead |
'{8c2eaf3d-32a7-4b09-ab99-bd1f1c86b501}': 'Synthetic RDMA adapter',
|
|
|
3feead |
'{44c4f61d-4444-4400-9d52-802e27ede19f}': 'PCI Express pass-through',
|
|
|
3feead |
'{276aacf4-ac15-426c-98dd-7521ad3f01fe}': '[Reserved system device]',
|
|
|
3feead |
'{f8e65716-3cb3-4a06-9a60-1889c5cccab5}': '[Reserved system device]',
|
|
|
3feead |
'{3375baf4-9e15-4b30-b765-67acb10d607b}': '[Reserved system device]',
|
|
|
3feead |
}
|
|
|
3feead |
|
|
|
3feead |
|
|
|
3feead |
def get_vmbus_dev_attr(dev_name, attr):
|
|
|
3feead |
try:
|
|
|
3feead |
f = open('%s/%s/%s' % (vmbus_sys_path, dev_name, attr), 'r')
|
|
|
3feead |
lines = f.readlines()
|
|
|
3feead |
f.close()
|
|
|
3feead |
except IOError:
|
|
|
3feead |
lines = []
|
|
|
3feead |
|
|
|
3feead |
return lines
|
|
|
3feead |
|
|
|
3feead |
|
|
|
3feead |
class VMBus_Dev:
|
|
|
3feead |
pass
|
|
|
3feead |
|
|
|
3feead |
|
|
|
3feead |
vmbus_dev_list = []
|
|
|
3feead |
|
|
|
3feead |
for f in os.listdir(vmbus_sys_path):
|
|
|
3feead |
vmbus_id = get_vmbus_dev_attr(f, 'id')[0].strip()
|
|
|
3feead |
class_id = get_vmbus_dev_attr(f, 'class_id')[0].strip()
|
|
|
3feead |
device_id = get_vmbus_dev_attr(f, 'device_id')[0].strip()
|
|
|
3feead |
dev_desc = vmbus_dev_dict.get(class_id, 'Unknown')
|
|
|
3feead |
|
|
|
3feead |
chn_vp_mapping = get_vmbus_dev_attr(f, 'channel_vp_mapping')
|
|
|
3feead |
chn_vp_mapping = [c.strip() for c in chn_vp_mapping]
|
|
|
3feead |
chn_vp_mapping = sorted(
|
|
|
3feead |
chn_vp_mapping, key=lambda c: int(c.split(':')[0]))
|
|
|
3feead |
|
|
|
3feead |
chn_vp_mapping = [
|
|
|
3feead |
'\tRel_ID=%s, target_cpu=%s' %
|
|
|
3feead |
(c.split(':')[0], c.split(':')[1]) for c in chn_vp_mapping
|
|
|
3feead |
]
|
|
|
3feead |
d = VMBus_Dev()
|
|
|
3feead |
d.sysfs_path = '%s/%s' % (vmbus_sys_path, f)
|
|
|
3feead |
d.vmbus_id = vmbus_id
|
|
|
3feead |
d.class_id = class_id
|
|
|
3feead |
d.device_id = device_id
|
|
|
3feead |
d.dev_desc = dev_desc
|
|
|
3feead |
d.chn_vp_mapping = '\n'.join(chn_vp_mapping)
|
|
|
3feead |
if d.chn_vp_mapping:
|
|
|
3feead |
d.chn_vp_mapping += '\n'
|
|
|
3feead |
|
|
|
3feead |
vmbus_dev_list.append(d)
|
|
|
3feead |
|
|
|
3feead |
|
|
|
3feead |
vmbus_dev_list = sorted(vmbus_dev_list, key=lambda d: int(d.vmbus_id))
|
|
|
3feead |
|
|
|
3feead |
format0 = '%2s: %s'
|
|
|
3feead |
format1 = '%2s: Class_ID = %s - %s\n%s'
|
|
|
3feead |
format2 = '%2s: Class_ID = %s - %s\n\tDevice_ID = %s\n\tSysfs path: %s\n%s'
|
|
|
3feead |
|
|
|
3feead |
for d in vmbus_dev_list:
|
|
|
3feead |
if verbose == 0:
|
|
|
3feead |
print(('VMBUS ID ' + format0) % (d.vmbus_id, d.dev_desc))
|
|
|
3feead |
elif verbose == 1:
|
|
|
3feead |
print(
|
|
|
3feead |
('VMBUS ID ' + format1) %
|
|
|
3feead |
(d.vmbus_id, d.class_id, d.dev_desc, d.chn_vp_mapping)
|
|
|
3feead |
)
|
|
|
3feead |
else:
|
|
|
3feead |
print(
|
|
|
3feead |
('VMBUS ID ' + format2) %
|
|
|
3feead |
(
|
|
|
3feead |
d.vmbus_id, d.class_id, d.dev_desc,
|
|
|
3feead |
d.device_id, d.sysfs_path, d.chn_vp_mapping
|
|
|
3feead |
)
|
|
|
3feead |
)
|