scripts/rpc: option to format framework_get_pci_devices for use with lspci

Added an option, `--format-lspci` that produces output that can be
consumed by `lspci -F`.  Additionally, added a simple convenience script
that executes lspci with the the output of the RPC.

Signed-off-by: Konrad Sztyber <konrad.sztyber@intel.com>
Change-Id: I41a0f846f32506c28cf6ca3a299ed264f64db1a4
Reviewed-on: https://review.spdk.io/gerrit/c/spdk/spdk/+/10653
Tested-by: SPDK CI Jenkins <sys_sgci@intel.com>
Community-CI: Mellanox Build Bot
Reviewed-by: Jim Harris <james.r.harris@intel.com>
Reviewed-by: Tomasz Zawadzki <tomasz.zawadzki@intel.com>
This commit is contained in:
Konrad Sztyber 2021-12-12 11:27:27 +01:00 committed by Tomasz Zawadzki
parent 9647fd4e8d
commit 3911bc344b
2 changed files with 20 additions and 1 deletions

6
scripts/lspci Executable file
View File

@ -0,0 +1,6 @@
#!/usr/bin/env bash
set -e
scriptdir=$(dirname $0)
lspci -F <($scriptdir/rpc.py framework_get_pci_devices --format-lspci) "$@"

View File

@ -2691,9 +2691,22 @@ Format: 'user:u1 secret:s1 muser:mu1 msecret:ms1,user:u2 secret:s2 muser:mu2 mse
p.set_defaults(func=sock_set_default_impl)
def framework_get_pci_devices(args):
print_json(rpc.subsystem.framework_get_pci_devices(args.client))
def splitbuf(buf, step):
return [buf[i:i+step] for i in range(0, len(buf), step)]
devices = rpc.subsystem.framework_get_pci_devices(args.client)
if not args.format_lspci:
print_json(devices)
else:
for devid, dev in enumerate(devices):
print('{} device #{}'.format(dev['address'], devid))
for lineid, line in enumerate(splitbuf(dev['config_space'], 32)):
print('{:02x}: {}'.format(lineid * 16, ' '.join(splitbuf(line.lower(), 2))))
print()
p = subparsers.add_parser('framework_get_pci_devices', help='''Get a list of attached PCI devices''')
p.add_argument('--format-lspci', help='Format the output in a way to be consumed by lspci -F',
action='store_true')
p.set_defaults(func=framework_get_pci_devices)
def check_called_name(name):