subsystem: add "get_subsystems" RPC call

Change-Id: I8927269134a1bab86a1dfb677bc38dc7f25c8ea4
Signed-off-by: Pawel Wodkowski <pawelx.wodkowski@intel.com>
Reviewed-on: https://review.gerrithub.io/400634
Tested-by: SPDK Automated Test System <sys_sgsw@intel.com>
Reviewed-by: Daniel Verkamp <daniel.verkamp@intel.com>
Reviewed-by: Jim Harris <james.r.harris@intel.com>
This commit is contained in:
Pawel Wodkowski 2018-02-20 17:03:57 +01:00 committed by Jim Harris
parent 97cb1713ff
commit ba1859ed55
9 changed files with 100 additions and 11 deletions

View File

@ -60,6 +60,9 @@ struct spdk_subsystem {
TAILQ_ENTRY(spdk_subsystem) tailq;
};
TAILQ_HEAD(spdk_subsystem_list, spdk_subsystem);
extern struct spdk_subsystem_list g_subsystems;
struct spdk_subsystem_depend {
const char *name;
const char *depends_on;
@ -67,6 +70,9 @@ struct spdk_subsystem_depend {
TAILQ_ENTRY(spdk_subsystem_depend) tailq;
};
TAILQ_HEAD(spdk_subsystem_depend_list, spdk_subsystem_depend);
extern struct spdk_subsystem_depend_list g_subsystems_deps;
void spdk_add_subsystem(struct spdk_subsystem *subsystem);
void spdk_add_subsystem_depend(struct spdk_subsystem_depend *depend);

View File

@ -34,7 +34,7 @@
SPDK_ROOT_DIR := $(abspath $(CURDIR)/../../..)
include $(SPDK_ROOT_DIR)/mk/spdk.common.mk
C_SRCS = app_rpc.c
C_SRCS = app_rpc.c subsystem_rpc.c
LIBNAME = app_rpc
include $(SPDK_ROOT_DIR)/mk/spdk.lib.mk

View File

@ -0,0 +1,75 @@
/*-
* BSD LICENSE
*
* Copyright (c) Intel Corporation.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
* * Neither the name of Intel Corporation nor the names of its
* contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#include "spdk_internal/event.h"
#include "spdk/rpc.h"
static void
spdk_rpc_get_subsystems(struct spdk_jsonrpc_request *request,
const struct spdk_json_val *params)
{
struct spdk_json_write_ctx *w;
struct spdk_subsystem *subsystem;
struct spdk_subsystem_depend *deps;
if (params) {
spdk_jsonrpc_send_error_response(request, SPDK_JSONRPC_ERROR_INVALID_PARAMS,
"'get_subsystems' requires no arguments");
return;
}
w = spdk_jsonrpc_begin_result(request);
if (w == NULL) {
return;
}
spdk_json_write_array_begin(w);
TAILQ_FOREACH(subsystem, &g_subsystems, tailq) {
spdk_json_write_object_begin(w);
spdk_json_write_named_string(w, "subsystem", subsystem->name);
spdk_json_write_named_array_begin(w, "depends_on");
TAILQ_FOREACH(deps, &g_subsystems_deps, tailq) {
if (strcmp(subsystem->name, deps->name) == 0) {
spdk_json_write_string(w, deps->depends_on);
}
}
spdk_json_write_array_end(w);
spdk_json_write_object_end(w);
}
spdk_json_write_array_end(w);
spdk_jsonrpc_end_result(request, w);
}
SPDK_RPC_REGISTER("get_subsystems", spdk_rpc_get_subsystems)

View File

@ -38,10 +38,8 @@
#include "spdk_internal/event.h"
#include "spdk/env.h"
static TAILQ_HEAD(spdk_subsystem_list, spdk_subsystem) g_subsystems =
TAILQ_HEAD_INITIALIZER(g_subsystems);
static TAILQ_HEAD(subsystem_depend, spdk_subsystem_depend) g_depends =
TAILQ_HEAD_INITIALIZER(g_depends);
struct spdk_subsystem_list g_subsystems = TAILQ_HEAD_INITIALIZER(g_subsystems);
struct spdk_subsystem_depend_list g_subsystems_deps = TAILQ_HEAD_INITIALIZER(g_subsystems_deps);
static struct spdk_subsystem *g_next_subsystem;
static bool g_subsystems_initialized = false;
static struct spdk_event *g_app_start_event;
@ -57,7 +55,7 @@ spdk_add_subsystem(struct spdk_subsystem *subsystem)
void
spdk_add_subsystem_depend(struct spdk_subsystem_depend *depend)
{
TAILQ_INSERT_TAIL(&g_depends, depend, tailq);
TAILQ_INSERT_TAIL(&g_subsystems_deps, depend, tailq);
}
static struct spdk_subsystem *
@ -86,7 +84,7 @@ subsystem_sort(void)
while (!TAILQ_EMPTY(&g_subsystems)) {
TAILQ_FOREACH_SAFE(subsystem, &g_subsystems, tailq, subsystem_tmp) {
depends_on = false;
TAILQ_FOREACH(subsystem_dep, &g_depends, tailq) {
TAILQ_FOREACH(subsystem_dep, &g_subsystems_deps, tailq) {
if (strcmp(subsystem->name, subsystem_dep->name) == 0) {
depends_on = true;
depends_on_sorted = !!spdk_subsystem_find(&subsystems_list, subsystem_dep->depends_on);
@ -149,7 +147,7 @@ spdk_subsystem_verify(void *arg1, void *arg2)
struct spdk_subsystem_depend *dep;
/* Verify that all dependency name and depends_on subsystems are registered */
TAILQ_FOREACH(dep, &g_depends, tailq) {
TAILQ_FOREACH(dep, &g_subsystems_deps, tailq) {
if (!spdk_subsystem_find(&g_subsystems, dep->name)) {
SPDK_ERRLOG("subsystem %s is missing\n", dep->name);
spdk_app_stop(-1);

View File

@ -62,4 +62,3 @@ spdk_copy_engine_subsystem_finish(void)
SPDK_SUBSYSTEM_REGISTER(copy, spdk_copy_engine_subsystem_initialize,
spdk_copy_engine_subsystem_finish, NULL)
SPDK_SUBSYSTEM_DEPEND(bdev, copy)

View File

@ -393,6 +393,11 @@ if __name__ == "__main__":
p.add_argument('pmem_file', help='Path to pmemblk pool file')
p.set_defaults(func=rpc.pmem.delete_pmem_pool)
# subsystem
p = subparsers.add_parser('get_subsystems', help=""""Print subsystems array in initialization order. Each subsystem
entry contain (unsorted) array of subsystems it depends on.""")
p.set_defaults(func=rpc.subsystem.get_subsystems)
# vhost
p = subparsers.add_parser('set_vhost_controller_coalescing', help='Set vhost controller coalescing')
p.add_argument('ctrlr', help='controller name')

View File

@ -8,6 +8,7 @@ import nbd
import net
import nvmf
import pmem
import subsystem
import vhost

5
scripts/rpc/subsystem.py Executable file
View File

@ -0,0 +1,5 @@
from client import print_dict, print_array, int_arg
def get_subsystems(args):
print_dict(args.client.call('get_subsystems'))

View File

@ -105,8 +105,8 @@ subsystem_clear(void)
TAILQ_REMOVE(&g_subsystems, subsystem, tailq);
}
TAILQ_FOREACH_SAFE(subsystem_dep, &g_depends, tailq, subsystem_dep_tmp) {
TAILQ_REMOVE(&g_depends, subsystem_dep, tailq);
TAILQ_FOREACH_SAFE(subsystem_dep, &g_subsystems_deps, tailq, subsystem_dep_tmp) {
TAILQ_REMOVE(&g_subsystems_deps, subsystem_dep, tailq);
}
}