2018-03-09 20:19:34 +00:00
|
|
|
import json
|
|
|
|
import sys
|
2017-06-06 21:22:03 +00:00
|
|
|
|
2018-03-20 00:37:58 +00:00
|
|
|
from . import app
|
|
|
|
from . import bdev
|
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
|
|
|
|
from . import net
|
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
|
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
|
|
|
|
2018-05-02 04:50:39 +00:00
|
|
|
def start_subsystem_init(client):
|
2018-07-17 10:00:20 +00:00
|
|
|
"""Start initialization of subsystems"""
|
2018-05-02 04:50:39 +00:00
|
|
|
return client.call('start_subsystem_init')
|
|
|
|
|
|
|
|
|
2018-11-08 20:24:50 +00:00
|
|
|
def wait_subsystem_init(client):
|
|
|
|
"""Block until subsystems have been initialized"""
|
|
|
|
return client.call('wait_subsystem_init')
|
|
|
|
|
|
|
|
|
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
|
|
|
|
|
|
|
|
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': []
|
|
|
|
}
|
|
|
|
|
2018-03-27 21:31:52 +00:00
|
|
|
for elem in client.call('get_subsystems'):
|
2018-03-09 20:19:34 +00:00
|
|
|
cfg = {
|
|
|
|
'subsystem': elem['subsystem'],
|
2018-03-27 21:31:52 +00:00
|
|
|
'config': client.call('get_subsystem_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
|
|
|
"""
|
2018-10-09 18:00:56 +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})
|
2018-11-09 12:21:34 +00:00
|
|
|
if not subsystems and 'start_subsystem_init' in allowed_methods:
|
|
|
|
start_subsystem_init(client)
|
|
|
|
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
|
|
|
|
|
|
|
|
client.call(elem['method'], elem['params'])
|
|
|
|
config.remove(elem)
|
|
|
|
allowed_found = True
|
|
|
|
|
|
|
|
if not config:
|
|
|
|
subsystems.remove(subsystem)
|
|
|
|
|
|
|
|
if 'start_subsystem_init' in allowed_methods:
|
2018-11-09 12:21:34 +00:00
|
|
|
start_subsystem_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,
|
|
|
|
'config': client.call('get_subsystem_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
|
|
|
"""
|
2018-10-09 18:00:56 +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
|
|
|
|
2018-05-16 19:45:39 +00:00
|
|
|
client.call(elem['method'], elem['params'])
|
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.")
|