Commit 496d6e76 authored by Jim Harris's avatar Jim Harris Committed by Konrad Sztyber
Browse files

rpc: add 'subsystems' parameter to save_config



This faciliates saving a config from an application like nvmf_tgt
for later use with bdevperf.

bdevperf doesn't have nvmf or nbd subsystems, so reusing the
nvmf_tgt config file as-is just generates a lot of annoying
NOTICELOGS that confuse users. We can instead instruct users to do
the following to create the json config file for bdevperf:

# scripts/rpc.py save_config -s bdev > bdevperf.json

Signed-off-by: default avatarJim Harris <jim.harris@samsung.com>
Change-Id: Ia0dfc83d16c3a6f5b3ad48f466ecabcf9a470ac8
Reviewed-on: https://review.spdk.io/gerrit/c/spdk/spdk/+/24665


Community-CI: Mellanox Build Bot
Tested-by: default avatarSPDK CI Jenkins <sys_sgci@intel.com>
Reviewed-by: default avatarAleksey Marchuk <alexeymar@nvidia.com>
Reviewed-by: default avatarKonrad Sztyber <konrad.sztyber@intel.com>
parent 77be4b72
Loading
Loading
Loading
Loading
+24 −2
Original line number Diff line number Diff line
@@ -100,18 +100,40 @@ def _json_load(j):
    return json_conf


def save_config(client, fd, indent=2):
def save_config(client, fd, indent=2, subsystems=None):
    """Write current (live) configuration of SPDK subsystems and targets to stdout.
    Args:
        fd: opened file descriptor where data will be saved
        indent: Indent level. Value less than 0 mean compact mode.
            Default indent level is 2.
        subsystems: subsystems (and their dependencies) to save
    """
    config = {
        'subsystems': []
    }

    for elem in client.call('framework_get_subsystems'):
    subsystems_json = client.call('framework_get_subsystems')

    # Build a dictionary of all subsystems to their fully expanded set of
    # dependencies.
    dependencies = dict()
    for elem in subsystems_json:
        subsystem = elem['subsystem']
        dependencies[subsystem] = {subsystem}
        for d in elem['depends_on']:
            dependencies[subsystem].update(dependencies[d])

    # Build a set of all of the subsystems to print based on the
    # subsystems parameter.
    to_print = set()
    if subsystems is None:
        to_print = dependencies.keys()
    else:
        for s in subsystems.split(','):
            to_print.update(dependencies[s])

    def _print(x): return x['subsystem'] in to_print
    for elem in filter(_print, subsystems_json):
        cfg = {
            'subsystem': elem['subsystem'],
            'config': client.call('framework_get_config', {"name": elem['subsystem']})
+3 −1
Original line number Diff line number Diff line
@@ -94,12 +94,14 @@ if __name__ == "__main__":
    def save_config(args):
        rpc.save_config(args.client,
                        sys.stdout,
                        indent=args.indent)
                        indent=args.indent,
                        subsystems=args.subsystems)

    p = subparsers.add_parser('save_config', help="""Write current (live) configuration of SPDK subsystems and targets to stdout.
    """)
    p.add_argument('-i', '--indent', help="""Indent level. Value less than 0 mean compact mode. Default indent level is 2.
    """, type=int, default=2)
    p.add_argument('-s', '--subsystems', help="""Comma-separated list of subsystems (and their dependencies) to save""")
    p.set_defaults(func=save_config)

    def load_config(args):