init: Make some functions entirely private

There were some functions in the internal header that can be entirely
private to the init library. Move them over.

Also, remove the support for including the header from a C++ file
because these headers are internal to SPDK which is pure C.

Change-Id: Ic4323b2b8664e70106a57b3ca8acbc7c2efe621d
Signed-off-by: Ben Walker <benjamin.walker@intel.com>
Reviewed-on: https://review.spdk.io/gerrit/c/spdk/spdk/+/6642
Reviewed-by: Tom Nabarro <tom.nabarro@outlook.com>
Reviewed-by: Jim Harris <james.r.harris@intel.com>
Reviewed-by: Changpeng Liu <changpeng.liu@intel.com>
Reviewed-by: Aleksey Marchuk <alexeymar@mellanox.com>
Tested-by: SPDK CI Jenkins <sys_sgci@intel.com>
Community-CI: Mellanox Build Bot
This commit is contained in:
Ben Walker 2021-03-01 13:55:15 -07:00 committed by Tomasz Zawadzki
parent 00b0dc6624
commit 1a8467b02c
6 changed files with 71 additions and 67 deletions

View File

@ -373,28 +373,6 @@ void _spdk_lw_thread_set_core(struct spdk_lw_thread *thread, uint32_t lcore);
void _spdk_lw_thread_get_current_stats(struct spdk_lw_thread *thread,
struct spdk_thread_stats *stats);
/**
* \brief Register a new subsystem
*/
#define SPDK_SUBSYSTEM_REGISTER(_name) \
__attribute__((constructor)) static void _name ## _register(void) \
{ \
spdk_add_subsystem(&_name); \
}
/**
* \brief Declare that a subsystem depends on another subsystem.
*/
#define SPDK_SUBSYSTEM_DEPEND(_name, _depends_on) \
static struct spdk_subsystem_depend __subsystem_ ## _name ## _depend_on ## _depends_on = { \
.name = #_name, \
.depends_on = #_depends_on, \
}; \
__attribute__((constructor)) static void _name ## _depend_on ## _depends_on(void) \
{ \
spdk_add_subsystem_depend(&__subsystem_ ## _name ## _depend_on ## _depends_on); \
}
#ifdef __cplusplus
}
#endif

View File

@ -41,10 +41,6 @@
#include "spdk/stdinc.h"
#include "spdk/queue.h"
#ifdef __cplusplus
extern "C" {
#endif
struct spdk_json_write_ctx;
struct spdk_subsystem {
@ -62,20 +58,12 @@ struct spdk_subsystem {
TAILQ_ENTRY(spdk_subsystem) tailq;
};
struct spdk_subsystem *spdk_subsystem_find(const char *name);
struct spdk_subsystem *spdk_subsystem_get_first(void);
struct spdk_subsystem *spdk_subsystem_get_next(struct spdk_subsystem *cur_subsystem);
struct spdk_subsystem_depend {
const char *name;
const char *depends_on;
TAILQ_ENTRY(spdk_subsystem_depend) tailq;
};
struct spdk_subsystem_depend *spdk_subsystem_get_first_depend(void);
struct spdk_subsystem_depend *spdk_subsystem_get_next_depend(struct spdk_subsystem_depend
*cur_depend);
void spdk_add_subsystem(struct spdk_subsystem *subsystem);
void spdk_add_subsystem_depend(struct spdk_subsystem_depend *depend);
@ -87,15 +75,6 @@ void spdk_subsystem_fini(spdk_subsystem_fini_fn cb_fn, void *cb_arg);
void spdk_subsystem_init_next(int rc);
void spdk_subsystem_fini_next(void);
/**
* Save pointed \c subsystem configuration to the JSON write context \c w. In case of
* error \c null is written to the JSON context.
*
* \param w JSON write context
* \param subsystem the subsystem to query
*/
void spdk_subsystem_config_json(struct spdk_json_write_ctx *w, struct spdk_subsystem *subsystem);
/**
* \brief Register a new subsystem
*/
@ -118,8 +97,4 @@ void spdk_subsystem_config_json(struct spdk_json_write_ctx *w, struct spdk_subsy
spdk_add_subsystem_depend(&__subsystem_ ## _name ## _depend_on ## _depends_on); \
}
#ifdef __cplusplus
}
#endif
#endif

View File

@ -2,18 +2,12 @@
global:
# Public functions
spdk_subsystem_find;
spdk_subsystem_get_first;
spdk_subsystem_get_next;
spdk_subsystem_get_first_depend;
spdk_subsystem_get_next_depend;
spdk_add_subsystem;
spdk_add_subsystem_depend;
spdk_subsystem_init;
spdk_subsystem_fini;
spdk_subsystem_init_next;
spdk_subsystem_fini_next;
spdk_subsystem_config_json;
local: *;
};

View File

@ -41,6 +41,8 @@
#include "spdk/json.h"
#include "subsystem.h"
TAILQ_HEAD(spdk_subsystem_list, spdk_subsystem);
struct spdk_subsystem_list g_subsystems = TAILQ_HEAD_INITIALIZER(g_subsystems);
@ -82,32 +84,32 @@ _subsystem_find(struct spdk_subsystem_list *list, const char *name)
}
struct spdk_subsystem *
spdk_subsystem_find(const char *name)
subsystem_find(const char *name)
{
return _subsystem_find(&g_subsystems, name);
}
struct spdk_subsystem *
spdk_subsystem_get_first(void)
subsystem_get_first(void)
{
return TAILQ_FIRST(&g_subsystems);
}
struct spdk_subsystem *
spdk_subsystem_get_next(struct spdk_subsystem *cur_subsystem)
subsystem_get_next(struct spdk_subsystem *cur_subsystem)
{
return TAILQ_NEXT(cur_subsystem, tailq);
}
struct spdk_subsystem_depend *
spdk_subsystem_get_first_depend(void)
subsystem_get_first_depend(void)
{
return TAILQ_FIRST(&g_subsystems_deps);
}
struct spdk_subsystem_depend *
spdk_subsystem_get_next_depend(struct spdk_subsystem_depend *cur_depend)
subsystem_get_next_depend(struct spdk_subsystem_depend *cur_depend)
{
return TAILQ_NEXT(cur_depend, tailq);
}
@ -196,12 +198,12 @@ spdk_subsystem_init(spdk_subsystem_init_fn cb_fn, void *cb_arg)
/* Verify that all dependency name and depends_on subsystems are registered */
TAILQ_FOREACH(dep, &g_subsystems_deps, tailq) {
if (!spdk_subsystem_find(dep->name)) {
if (!subsystem_find(dep->name)) {
SPDK_ERRLOG("subsystem %s is missing\n", dep->name);
g_subsystem_start_fn(-1, g_subsystem_start_arg);
return;
}
if (!spdk_subsystem_find(dep->depends_on)) {
if (!subsystem_find(dep->depends_on)) {
SPDK_ERRLOG("subsystem %s dependency %s is missing\n",
dep->name, dep->depends_on);
g_subsystem_start_fn(-1, g_subsystem_start_arg);
@ -268,7 +270,7 @@ spdk_subsystem_fini(spdk_msg_fn cb_fn, void *cb_arg)
}
void
spdk_subsystem_config_json(struct spdk_json_write_ctx *w, struct spdk_subsystem *subsystem)
subsystem_config_json(struct spdk_json_write_ctx *w, struct spdk_subsystem *subsystem)
{
if (subsystem && subsystem->write_config_json) {
subsystem->write_config_json(w);

53
lib/init/subsystem.h Normal file
View File

@ -0,0 +1,53 @@
/*-
* 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.
*/
#ifndef SPDK_SUBSYSTEM_H
#define SPDK_SUBSYSTEM_H
struct spdk_subsystem *subsystem_find(const char *name);
struct spdk_subsystem *subsystem_get_first(void);
struct spdk_subsystem *subsystem_get_next(struct spdk_subsystem *cur_subsystem);
struct spdk_subsystem_depend *subsystem_get_first_depend(void);
struct spdk_subsystem_depend *subsystem_get_next_depend(struct spdk_subsystem_depend
*cur_depend);
/**
* Save pointed \c subsystem configuration to the JSON write context \c w. In case of
* error \c null is written to the JSON context.
*
* \param w JSON write context
* \param subsystem the subsystem to query
*/
void subsystem_config_json(struct spdk_json_write_ctx *w, struct spdk_subsystem *subsystem);
#endif

View File

@ -38,6 +38,8 @@
#include "spdk_internal/init.h"
#include "subsystem.h"
static void
rpc_framework_get_subsystems(struct spdk_jsonrpc_request *request,
const struct spdk_json_val *params)
@ -54,22 +56,22 @@ rpc_framework_get_subsystems(struct spdk_jsonrpc_request *request,
w = spdk_jsonrpc_begin_result(request);
spdk_json_write_array_begin(w);
subsystem = spdk_subsystem_get_first();
subsystem = subsystem_get_first();
while (subsystem != NULL) {
spdk_json_write_object_begin(w);
spdk_json_write_named_string(w, "subsystem", subsystem->name);
spdk_json_write_named_array_begin(w, "depends_on");
deps = spdk_subsystem_get_first_depend();
deps = subsystem_get_first_depend();
while (deps != NULL) {
if (strcmp(subsystem->name, deps->name) == 0) {
spdk_json_write_string(w, deps->depends_on);
}
deps = spdk_subsystem_get_next_depend(deps);
deps = subsystem_get_next_depend(deps);
}
spdk_json_write_array_end(w);
spdk_json_write_object_end(w);
subsystem = spdk_subsystem_get_next(subsystem);
subsystem = subsystem_get_next(subsystem);
}
spdk_json_write_array_end(w);
spdk_jsonrpc_end_result(request, w);
@ -100,7 +102,7 @@ rpc_framework_get_config(struct spdk_jsonrpc_request *request,
return;
}
subsystem = spdk_subsystem_find(req.name);
subsystem = subsystem_find(req.name);
if (!subsystem) {
spdk_jsonrpc_send_error_response_fmt(request, SPDK_JSONRPC_ERROR_INVALID_PARAMS,
"Subsystem '%s' not found", req.name);
@ -111,7 +113,7 @@ rpc_framework_get_config(struct spdk_jsonrpc_request *request,
free(req.name);
w = spdk_jsonrpc_begin_result(request);
spdk_subsystem_config_json(w, subsystem);
subsystem_config_json(w, subsystem);
spdk_jsonrpc_end_result(request, w);
}