Commit ba1859ed authored by Pawel Wodkowski's avatar Pawel Wodkowski Committed by Jim Harris
Browse files

subsystem: add "get_subsystems" RPC call



Change-Id: I8927269134a1bab86a1dfb677bc38dc7f25c8ea4
Signed-off-by: default avatarPawel Wodkowski <pawelx.wodkowski@intel.com>
Reviewed-on: https://review.gerrithub.io/400634


Tested-by: default avatarSPDK Automated Test System <sys_sgsw@intel.com>
Reviewed-by: default avatarDaniel Verkamp <daniel.verkamp@intel.com>
Reviewed-by: default avatarJim Harris <james.r.harris@intel.com>
parent 97cb1713
Loading
Loading
Loading
Loading
+6 −0
Original line number Diff line number Diff line
@@ -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);

+1 −1
Original line number Diff line number Diff line
@@ -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
+75 −0
Original line number Diff line number Diff line
/*-
 *   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)
+5 −7
Original line number Diff line number Diff line
@@ -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);
+0 −1
Original line number Diff line number Diff line
@@ -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)
Loading