2018-03-09 20:19:34 +00:00
|
|
|
import json
|
2020-04-29 15:34:51 +00:00
|
|
|
import os
|
2018-03-09 20:19:34 +00:00
|
|
|
import sys
|
2017-06-06 21:22:03 +00:00
|
|
|
|
2020-04-29 15:34:51 +00:00
|
|
|
from io import IOBase as io
|
|
|
|
|
2018-03-20 00:37:58 +00:00
|
|
|
from . import app
|
|
|
|
from . import bdev
|
2019-08-28 08:06:50 +00:00
|
|
|
from . import blobfs
|
2019-12-10 23:29:37 +00:00
|
|
|
from . import env_dpdk
|
2020-04-07 16:42:02 +00:00
|
|
|
from . import idxd
|
2018-06-12 23:31:20 +00:00
|
|
|
from . import ioat
|
2018-03-20 00:37:58 +00:00
|
|
|
from . import iscsi
|
|
|
|
from . import log
|
|
|
|
from . import lvol
|
|
|
|
from . import nbd
|
2018-12-06 15:56:06 +00:00
|
|
|
from . import notify
|
2018-07-05 07:46:48 +00:00
|
|
|
from . import nvme
|
2018-03-20 00:37:58 +00:00
|
|
|
from . import nvmf
|
|
|
|
from . import pmem
|
|
|
|
from . import subsystem
|
2018-11-29 11:12:26 +00:00
|
|
|
from . import trace
|
2018-03-20 00:37:58 +00:00
|
|
|
from . import vhost
|
2019-07-01 11:54:57 +00:00
|
|
|
from . import vmd
|
2020-01-28 19:24:46 +00:00
|
|
|
from . import sock
|
2018-05-31 02:49:45 +00:00
|
|
|
from . import client as rpc_client
|
2019-05-03 20:59:01 +00:00
|
|
|
from .helpers import deprecated_alias
|
2018-03-20 00:37:58 +00:00
|
|
|
|
2017-06-06 21:22:03 +00:00
|
|
|
|
2019-09-11 13:30:14 +00:00
|
|
|
@deprecated_alias('start_subsystem_init')
|
|
|
|
def framework_start_init(client):
|
2018-07-17 10:00:20 +00:00
|
|
|
"""Start initialization of subsystems"""
|
2019-09-11 13:30:14 +00:00
|
|
|
return client.call('framework_start_init')
|
2018-05-02 04:50:39 +00:00
|
|
|
|
|
|
|
|
2019-09-11 13:35:41 +00:00
|
|
|
@deprecated_alias('wait_subsystem_init')
|
|
|
|
def framework_wait_init(client):
|
2018-11-08 20:24:50 +00:00
|
|
|
"""Block until subsystems have been initialized"""
|
2019-09-11 13:35:41 +00:00
|
|
|
return client.call('framework_wait_init')
|
2018-11-08 20:24:50 +00:00
|
|
|
|
|
|
|
|
2019-05-03 20:59:01 +00:00
|
|
|
@deprecated_alias("get_rpc_methods")
|
2019-08-21 12:43:23 +00:00
|
|
|
def rpc_get_methods(client, current=None, include_aliases=None):
|
2018-07-17 10:00:20 +00:00
|
|
|
"""Get list of supported RPC methods.
|
|
|
|
Args:
|
|
|
|
current: Get list of RPC methods only callable in the current state.
|
2019-08-21 12:43:23 +00:00
|
|
|
include_aliases: Include aliases in the list with RPC methods.
|
2018-07-17 10:00:20 +00:00
|
|
|
"""
|
2018-05-04 01:39:27 +00:00
|
|
|
params = {}
|
|
|
|
|
2018-07-17 10:00:20 +00:00
|
|
|
if current:
|
|
|
|
params['current'] = current
|
2019-08-21 12:43:23 +00:00
|
|
|
if include_aliases:
|
|
|
|
params['include_aliases'] = include_aliases
|
2018-05-04 01:39:27 +00:00
|
|
|
|
2019-05-03 20:59:01 +00:00
|
|
|
return client.call('rpc_get_methods', params)
|
2018-03-09 20:19:34 +00:00
|
|
|
|
|
|
|
|
2019-09-19 21:32:01 +00:00
|
|
|
@deprecated_alias("get_spdk_version")
|
|
|
|
def spdk_get_version(client):
|
2019-03-21 22:02:04 +00:00
|
|
|
"""Get SPDK version"""
|
2019-09-19 21:32:01 +00:00
|
|
|
return client.call('spdk_get_version')
|
2019-03-21 22:02:04 +00:00
|
|
|
|
|
|
|
|
2018-10-09 18:00:56 +00:00
|
|
|
def _json_dump(config, fd, indent):
|
2018-09-10 18:18:08 +00:00
|
|
|
if indent is None:
|
|
|
|
indent = 2
|
|
|
|
elif indent < 0:
|
|
|
|
indent = None
|
2018-10-09 18:00:56 +00:00
|
|
|
json.dump(config, fd, indent=indent)
|
|
|
|
fd.write('\n')
|
2018-09-10 18:18:08 +00:00
|
|
|
|
|
|
|
|
2020-04-29 15:34:51 +00:00
|
|
|
def _json_load(j):
|
|
|
|
if j == sys.stdin or isinstance(j, io):
|
|
|
|
json_conf = json.load(j)
|
|
|
|
elif os.path.exists(j):
|
|
|
|
with open(j, "r") as j:
|
|
|
|
json_conf = json.load(j)
|
|
|
|
else:
|
|
|
|
json_conf = json.loads(j)
|
|
|
|
return json_conf
|
|
|
|
|
|
|
|
|
2018-10-09 18:00:56 +00:00
|
|
|
def save_config(client, fd, indent=2):
|
2018-09-10 18:18:08 +00:00
|
|
|
"""Write current (live) configuration of SPDK subsystems and targets to stdout.
|
2018-07-17 10:00:20 +00:00
|
|
|
Args:
|
2018-10-09 18:00:56 +00:00
|
|
|
fd: opened file descriptor where data will be saved
|
2018-07-17 10:00:20 +00:00
|
|
|
indent: Indent level. Value less than 0 mean compact mode.
|
2018-09-10 18:18:08 +00:00
|
|
|
Default indent level is 2.
|
2018-07-17 10:00:20 +00:00
|
|
|
"""
|
2018-03-09 20:19:34 +00:00
|
|
|
config = {
|
|
|
|
'subsystems': []
|
|
|
|
}
|
|
|
|
|
2019-09-18 08:24:58 +00:00
|
|
|
for elem in client.call('framework_get_subsystems'):
|
2018-03-09 20:19:34 +00:00
|
|
|
cfg = {
|
|
|
|
'subsystem': elem['subsystem'],
|
2019-09-18 10:09:24 +00:00
|
|
|
'config': client.call('framework_get_config', {"name": elem['subsystem']})
|
2018-03-09 20:19:34 +00:00
|
|
|
}
|
|
|
|
config['subsystems'].append(cfg)
|
|
|
|
|
2018-10-09 18:00:56 +00:00
|
|
|
_json_dump(config, fd, indent)
|
2018-03-09 20:19:34 +00:00
|
|
|
|
|
|
|
|
2019-08-21 12:43:23 +00:00
|
|
|
def load_config(client, fd, include_aliases=False):
|
2018-09-10 18:18:08 +00:00
|
|
|
"""Configure SPDK subsystems and targets using JSON RPC read from stdin.
|
2018-07-17 10:00:20 +00:00
|
|
|
Args:
|
2018-10-09 18:00:56 +00:00
|
|
|
fd: opened file descriptor where data will be taken from
|
2018-07-17 10:00:20 +00:00
|
|
|
"""
|
2020-04-29 15:34:51 +00:00
|
|
|
json_config = _json_load(fd)
|
2018-05-14 14:58:01 +00:00
|
|
|
|
2018-06-21 01:53:46 +00:00
|
|
|
# remove subsystems with no config
|
2018-05-14 14:58:01 +00:00
|
|
|
subsystems = json_config['subsystems']
|
2018-06-21 01:53:46 +00:00
|
|
|
for subsystem in list(subsystems):
|
|
|
|
if not subsystem['config']:
|
|
|
|
subsystems.remove(subsystem)
|
|
|
|
|
|
|
|
# check if methods in the config file are known
|
2019-08-21 12:43:23 +00:00
|
|
|
allowed_methods = client.call('rpc_get_methods', {'include_aliases': include_aliases})
|
2019-09-11 13:30:14 +00:00
|
|
|
if not subsystems and 'framework_start_init' in allowed_methods:
|
|
|
|
framework_start_init(client)
|
2018-11-09 12:21:34 +00:00
|
|
|
return
|
|
|
|
|
2018-06-21 01:53:46 +00:00
|
|
|
for subsystem in list(subsystems):
|
|
|
|
config = subsystem['config']
|
|
|
|
for elem in list(config):
|
|
|
|
if 'method' not in elem or elem['method'] not in allowed_methods:
|
|
|
|
raise rpc_client.JSONRPCException("Unknown method was included in the config file")
|
|
|
|
|
2018-05-14 14:58:01 +00:00
|
|
|
while subsystems:
|
2019-08-21 12:43:23 +00:00
|
|
|
allowed_methods = client.call('rpc_get_methods', {'current': True,
|
|
|
|
'include_aliases': include_aliases})
|
2018-05-14 14:58:01 +00:00
|
|
|
allowed_found = False
|
|
|
|
|
|
|
|
for subsystem in list(subsystems):
|
|
|
|
config = subsystem['config']
|
|
|
|
for elem in list(config):
|
2018-06-21 01:53:46 +00:00
|
|
|
if 'method' not in elem or elem['method'] not in allowed_methods:
|
2018-05-14 14:58:01 +00:00
|
|
|
continue
|
|
|
|
|
scripts/rpc: allow methods without params in load_config/load_subsystem_config RPC
JSON-RPC allows for methods that do not contain any params.
Turns out that so far this scenario has not occured for load_config or load_sybsystem_config
RPC, which processes JSON config file saved from previous app run.
Next patch writes out bdev_wait_for_examine to bdev subsystem
configuration. As that methods does not contain any params following
error was seen:
# /home/vagrant/spdk_repo/spdk/scripts/rpc.py load_config
Traceback (most recent call last):
File "/home/vagrant/spdk_repo/spdk/scripts/rpc.py", line 2671, in <module>
call_rpc_func(args)
File "/home/vagrant/spdk_repo/spdk/scripts/rpc.py", line 2601, in call_rpc_func
args.func(args)
File "/home/vagrant/spdk_repo/spdk/scripts/rpc.py", line 100, in load_config
include_aliases=args.include_aliases)
File "/home/vagrant/spdk_repo/spdk/scripts/rpc/__init__.py", line 143, in load_config
client.call(elem['method'], elem['params'])
KeyError: 'params'
Signed-off-by: Tomasz Zawadzki <tomasz.zawadzki@intel.com>
Change-Id: I4a56a9d0caa4b752fb9c1fad4ae581aad8a4c2c1
Reviewed-on: https://review.spdk.io/gerrit/c/spdk/spdk/+/5860
Community-CI: Broadcom CI
Community-CI: Mellanox Build Bot
Tested-by: SPDK CI Jenkins <sys_sgci@intel.com>
Reviewed-by: Jim Harris <james.r.harris@intel.com>
Reviewed-by: <dongx.yi@intel.com>
Reviewed-by: Shuhei Matsumoto <shuhei.matsumoto.xt@hitachi.com>
2021-01-08 12:50:27 +00:00
|
|
|
client.call(**elem)
|
2018-05-14 14:58:01 +00:00
|
|
|
config.remove(elem)
|
|
|
|
allowed_found = True
|
|
|
|
|
|
|
|
if not config:
|
|
|
|
subsystems.remove(subsystem)
|
|
|
|
|
2019-09-11 13:30:14 +00:00
|
|
|
if 'framework_start_init' in allowed_methods:
|
|
|
|
framework_start_init(client)
|
2018-05-14 14:58:01 +00:00
|
|
|
allowed_found = True
|
|
|
|
|
2018-06-21 01:53:46 +00:00
|
|
|
if not allowed_found:
|
|
|
|
break
|
|
|
|
|
|
|
|
if subsystems:
|
|
|
|
print("Some configs were skipped because the RPC state that can call them passed over.")
|
2018-05-16 19:45:39 +00:00
|
|
|
|
|
|
|
|
2018-10-09 18:00:56 +00:00
|
|
|
def save_subsystem_config(client, fd, indent=2, name=None):
|
2018-09-10 18:18:08 +00:00
|
|
|
"""Write current (live) configuration of SPDK subsystem to stdout.
|
2018-07-17 10:00:20 +00:00
|
|
|
Args:
|
2018-10-09 18:00:56 +00:00
|
|
|
fd: opened file descriptor where data will be saved
|
2018-07-17 10:00:20 +00:00
|
|
|
indent: Indent level. Value less than 0 mean compact mode.
|
2018-09-10 18:18:08 +00:00
|
|
|
Default is indent level 2.
|
2018-07-17 10:00:20 +00:00
|
|
|
"""
|
2018-06-21 23:44:54 +00:00
|
|
|
cfg = {
|
2018-07-17 10:00:20 +00:00
|
|
|
'subsystem': name,
|
2019-09-18 10:09:24 +00:00
|
|
|
'config': client.call('framework_get_config', {"name": name})
|
2018-06-21 23:44:54 +00:00
|
|
|
}
|
|
|
|
|
2018-10-09 18:00:56 +00:00
|
|
|
_json_dump(cfg, fd, indent)
|
2018-06-21 23:44:54 +00:00
|
|
|
|
|
|
|
|
2018-10-09 18:00:56 +00:00
|
|
|
def load_subsystem_config(client, fd):
|
2018-09-10 18:18:08 +00:00
|
|
|
"""Configure SPDK subsystem using JSON RPC read from stdin.
|
2018-07-17 10:00:20 +00:00
|
|
|
Args:
|
2018-10-09 18:00:56 +00:00
|
|
|
fd: opened file descriptor where data will be taken from
|
2018-07-17 10:00:20 +00:00
|
|
|
"""
|
2020-04-29 15:34:51 +00:00
|
|
|
subsystem = _json_load(fd)
|
2018-05-16 19:45:39 +00:00
|
|
|
|
2018-06-24 23:06:09 +00:00
|
|
|
if not subsystem['config']:
|
|
|
|
return
|
|
|
|
|
2019-05-03 20:59:01 +00:00
|
|
|
allowed_methods = client.call('rpc_get_methods')
|
2018-06-24 23:06:09 +00:00
|
|
|
config = subsystem['config']
|
|
|
|
for elem in list(config):
|
|
|
|
if 'method' not in elem or elem['method'] not in allowed_methods:
|
|
|
|
raise rpc_client.JSONRPCException("Unknown method was included in the config file")
|
|
|
|
|
2019-05-03 20:59:01 +00:00
|
|
|
allowed_methods = client.call('rpc_get_methods', {'current': True})
|
2018-06-24 23:06:09 +00:00
|
|
|
for elem in list(config):
|
|
|
|
if 'method' not in elem or elem['method'] not in allowed_methods:
|
2018-05-16 19:45:39 +00:00
|
|
|
continue
|
2018-06-24 23:06:09 +00:00
|
|
|
|
scripts/rpc: allow methods without params in load_config/load_subsystem_config RPC
JSON-RPC allows for methods that do not contain any params.
Turns out that so far this scenario has not occured for load_config or load_sybsystem_config
RPC, which processes JSON config file saved from previous app run.
Next patch writes out bdev_wait_for_examine to bdev subsystem
configuration. As that methods does not contain any params following
error was seen:
# /home/vagrant/spdk_repo/spdk/scripts/rpc.py load_config
Traceback (most recent call last):
File "/home/vagrant/spdk_repo/spdk/scripts/rpc.py", line 2671, in <module>
call_rpc_func(args)
File "/home/vagrant/spdk_repo/spdk/scripts/rpc.py", line 2601, in call_rpc_func
args.func(args)
File "/home/vagrant/spdk_repo/spdk/scripts/rpc.py", line 100, in load_config
include_aliases=args.include_aliases)
File "/home/vagrant/spdk_repo/spdk/scripts/rpc/__init__.py", line 143, in load_config
client.call(elem['method'], elem['params'])
KeyError: 'params'
Signed-off-by: Tomasz Zawadzki <tomasz.zawadzki@intel.com>
Change-Id: I4a56a9d0caa4b752fb9c1fad4ae581aad8a4c2c1
Reviewed-on: https://review.spdk.io/gerrit/c/spdk/spdk/+/5860
Community-CI: Broadcom CI
Community-CI: Mellanox Build Bot
Tested-by: SPDK CI Jenkins <sys_sgci@intel.com>
Reviewed-by: Jim Harris <james.r.harris@intel.com>
Reviewed-by: <dongx.yi@intel.com>
Reviewed-by: Shuhei Matsumoto <shuhei.matsumoto.xt@hitachi.com>
2021-01-08 12:50:27 +00:00
|
|
|
client.call(**elem)
|
2018-06-24 23:06:09 +00:00
|
|
|
config.remove(elem)
|
|
|
|
|
|
|
|
if config:
|
|
|
|
print("Some configs were skipped because they cannot be called in the current RPC state.")
|