From 3911bc344bfd2eadf048e3ae311162abcf47facf Mon Sep 17 00:00:00 2001 From: Konrad Sztyber Date: Sun, 12 Dec 2021 11:27:27 +0100 Subject: [PATCH] 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 Change-Id: I41a0f846f32506c28cf6ca3a299ed264f64db1a4 Reviewed-on: https://review.spdk.io/gerrit/c/spdk/spdk/+/10653 Tested-by: SPDK CI Jenkins Community-CI: Mellanox Build Bot Reviewed-by: Jim Harris Reviewed-by: Tomasz Zawadzki --- scripts/lspci | 6 ++++++ scripts/rpc.py | 15 ++++++++++++++- 2 files changed, 20 insertions(+), 1 deletion(-) create mode 100755 scripts/lspci diff --git a/scripts/lspci b/scripts/lspci new file mode 100755 index 0000000000..a2ed25d5e5 --- /dev/null +++ b/scripts/lspci @@ -0,0 +1,6 @@ +#!/usr/bin/env bash + +set -e + +scriptdir=$(dirname $0) +lspci -F <($scriptdir/rpc.py framework_get_pci_devices --format-lspci) "$@" diff --git a/scripts/rpc.py b/scripts/rpc.py index 6a64f8c87a..9d4a8048c5 100755 --- a/scripts/rpc.py +++ b/scripts/rpc.py @@ -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):