iscsi: Add JSON config/info dump for portal group.
Support JSON config/info dump for portal group. These are added to portal_grp.c. Text config dump is moved to portal_grp.c. Add accesses to g_spdk_iscsi.pg_head are consolidated into portal_grp.c to extract pg_head from g_spdk_iscsi. Change-Id: I8c551b067c68a785eb0c7d83d695bde5f7219c2b Signed-off-by: Shuhei Matsumoto <shuhei.matsumoto.xt@hitachi.com> Reviewed-on: https://review.gerrithub.io/407850 Tested-by: SPDK Automated Test System <sys_sgsw@intel.com> Reviewed-by: Jim Harris <james.r.harris@intel.com> Reviewed-by: Pawel Wodkowski <pawelx.wodkowski@intel.com> Reviewed-by: Daniel Verkamp <daniel.verkamp@intel.com>
This commit is contained in:
parent
8107d04bfb
commit
29c29ff9b6
@ -694,39 +694,11 @@ invalid:
|
||||
}
|
||||
SPDK_RPC_REGISTER("delete_target_node", spdk_rpc_delete_target_node, SPDK_RPC_RUNTIME)
|
||||
|
||||
static void
|
||||
dump_portal_group(struct spdk_json_write_ctx *w, struct spdk_iscsi_portal_grp *pg)
|
||||
{
|
||||
struct spdk_iscsi_portal *portal;
|
||||
|
||||
spdk_json_write_object_begin(w);
|
||||
|
||||
spdk_json_write_name(w, "portals");
|
||||
spdk_json_write_array_begin(w);
|
||||
TAILQ_FOREACH(portal, &pg->head, per_pg_tailq) {
|
||||
spdk_json_write_object_begin(w);
|
||||
spdk_json_write_name(w, "host");
|
||||
spdk_json_write_string(w, portal->host);
|
||||
spdk_json_write_name(w, "port");
|
||||
spdk_json_write_string(w, portal->port);
|
||||
spdk_json_write_name(w, "cpumask");
|
||||
spdk_json_write_string_fmt(w, "0x%s", spdk_cpuset_fmt(portal->cpumask));
|
||||
spdk_json_write_object_end(w);
|
||||
}
|
||||
spdk_json_write_array_end(w);
|
||||
|
||||
spdk_json_write_name(w, "tag");
|
||||
spdk_json_write_int32(w, pg->tag);
|
||||
|
||||
spdk_json_write_object_end(w);
|
||||
}
|
||||
|
||||
static void
|
||||
spdk_rpc_get_portal_groups(struct spdk_jsonrpc_request *request,
|
||||
const struct spdk_json_val *params)
|
||||
{
|
||||
struct spdk_json_write_ctx *w;
|
||||
struct spdk_iscsi_portal_grp *pg;
|
||||
|
||||
if (params != NULL) {
|
||||
spdk_jsonrpc_send_error_response(request, SPDK_JSONRPC_ERROR_INVALID_PARAMS,
|
||||
@ -740,11 +712,7 @@ spdk_rpc_get_portal_groups(struct spdk_jsonrpc_request *request,
|
||||
}
|
||||
|
||||
spdk_json_write_array_begin(w);
|
||||
|
||||
TAILQ_FOREACH(pg, &g_spdk_iscsi.pg_head, tailq) {
|
||||
dump_portal_group(w, pg);
|
||||
}
|
||||
|
||||
spdk_iscsi_portal_grps_info_json(w);
|
||||
spdk_json_write_array_end(w);
|
||||
|
||||
spdk_jsonrpc_end_result(request, w);
|
||||
|
@ -116,53 +116,6 @@ spdk_iscsi_globals_config_text(FILE *fp)
|
||||
g_spdk_iscsi.ErrorRecoveryLevel);
|
||||
}
|
||||
|
||||
/* Portal groups */
|
||||
static const char *portal_group_section = \
|
||||
"\n"
|
||||
"# Users must change the PortalGroup section(s) to match the IP addresses\n"
|
||||
"# for their environment.\n"
|
||||
"# PortalGroup sections define which network portals the iSCSI target\n"
|
||||
"# will use to listen for incoming connections. These are also used to\n"
|
||||
"# determine which targets are accessible over each portal group.\n"
|
||||
"# Up to 1024 Portal directives are allowed. These define the network\n"
|
||||
"# portals of the portal group. The user must specify a IP address\n"
|
||||
"# for each network portal, and may optionally specify a port and\n"
|
||||
"# a cpumask. If the port is omitted, 3260 will be used. Cpumask will\n"
|
||||
"# be used to set the processor affinity of the iSCSI connection\n"
|
||||
"# through the portal. If the cpumask is omitted, cpumask will be\n"
|
||||
"# set to all available processors.\n"
|
||||
"# Syntax:\n"
|
||||
"# Portal <Name> <IP address>[:<port>[@<cpumask>]]\n";
|
||||
|
||||
#define PORTAL_GROUP_TMPL \
|
||||
"[PortalGroup%d]\n" \
|
||||
" Comment \"Portal%d\"\n"
|
||||
|
||||
#define PORTAL_TMPL \
|
||||
" Portal DA1 %s:%s@0x%s\n"
|
||||
|
||||
static void
|
||||
spdk_iscsi_config_dump_portal_groups(FILE *fp)
|
||||
{
|
||||
struct spdk_iscsi_portal *p = NULL;
|
||||
struct spdk_iscsi_portal_grp *pg = NULL;
|
||||
|
||||
/* Create portal group section */
|
||||
fprintf(fp, "%s", portal_group_section);
|
||||
|
||||
/* Dump portal groups */
|
||||
TAILQ_FOREACH(pg, &g_spdk_iscsi.pg_head, tailq) {
|
||||
if (NULL == pg) { continue; }
|
||||
fprintf(fp, PORTAL_GROUP_TMPL, pg->tag, pg->tag);
|
||||
/* Dump portals */
|
||||
TAILQ_FOREACH(p, &pg->head, per_pg_tailq) {
|
||||
if (NULL == p) { continue; }
|
||||
fprintf(fp, PORTAL_TMPL, p->host, p->port,
|
||||
spdk_cpuset_fmt(p->cpumask));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
spdk_mobj_ctor(struct spdk_mempool *mp, __attribute__((unused)) void *arg,
|
||||
void *_m, __attribute__((unused)) unsigned i)
|
||||
@ -961,7 +914,7 @@ void
|
||||
spdk_iscsi_config_text(FILE *fp)
|
||||
{
|
||||
spdk_iscsi_globals_config_text(fp);
|
||||
spdk_iscsi_config_dump_portal_groups(fp);
|
||||
spdk_iscsi_portal_grps_config_text(fp);
|
||||
spdk_iscsi_init_grps_config_text(fp);
|
||||
spdk_iscsi_tgt_nodes_config_text(fp);
|
||||
}
|
||||
@ -970,6 +923,7 @@ void
|
||||
spdk_iscsi_config_json(struct spdk_json_write_ctx *w)
|
||||
{
|
||||
spdk_json_write_array_begin(w);
|
||||
spdk_iscsi_portal_grps_config_json(w);
|
||||
spdk_iscsi_init_grps_config_json(w);
|
||||
spdk_iscsi_tgt_nodes_config_json(w);
|
||||
spdk_json_write_array_end(w);
|
||||
|
@ -599,3 +599,107 @@ spdk_iscsi_portal_grp_release(struct spdk_iscsi_portal_grp *pg)
|
||||
spdk_iscsi_portal_grp_close(pg);
|
||||
spdk_iscsi_portal_grp_destroy(pg);
|
||||
}
|
||||
|
||||
static const char *portal_group_section = \
|
||||
"\n"
|
||||
"# Users must change the PortalGroup section(s) to match the IP addresses\n"
|
||||
"# for their environment.\n"
|
||||
"# PortalGroup sections define which network portals the iSCSI target\n"
|
||||
"# will use to listen for incoming connections. These are also used to\n"
|
||||
"# determine which targets are accessible over each portal group.\n"
|
||||
"# Up to 1024 Portal directives are allowed. These define the network\n"
|
||||
"# portals of the portal group. The user must specify a IP address\n"
|
||||
"# for each network portal, and may optionally specify a port and\n"
|
||||
"# a cpumask. If the port is omitted, 3260 will be used. Cpumask will\n"
|
||||
"# be used to set the processor affinity of the iSCSI connection\n"
|
||||
"# through the portal. If the cpumask is omitted, cpumask will be\n"
|
||||
"# set to all available processors.\n"
|
||||
"# Syntax:\n"
|
||||
"# Portal <Name> <IP address>[:<port>[@<cpumask>]]\n";
|
||||
|
||||
#define PORTAL_GROUP_TMPL \
|
||||
"[PortalGroup%d]\n" \
|
||||
" Comment \"Portal%d\"\n"
|
||||
|
||||
#define PORTAL_TMPL \
|
||||
" Portal DA1 %s:%s@0x%s\n"
|
||||
|
||||
void
|
||||
spdk_iscsi_portal_grps_config_text(FILE *fp)
|
||||
{
|
||||
struct spdk_iscsi_portal *p = NULL;
|
||||
struct spdk_iscsi_portal_grp *pg = NULL;
|
||||
|
||||
/* Create portal group section */
|
||||
fprintf(fp, "%s", portal_group_section);
|
||||
|
||||
/* Dump portal groups */
|
||||
TAILQ_FOREACH(pg, &g_spdk_iscsi.pg_head, tailq) {
|
||||
if (NULL == pg) { continue; }
|
||||
fprintf(fp, PORTAL_GROUP_TMPL, pg->tag, pg->tag);
|
||||
/* Dump portals */
|
||||
TAILQ_FOREACH(p, &pg->head, per_pg_tailq) {
|
||||
if (NULL == p) { continue; }
|
||||
fprintf(fp, PORTAL_TMPL, p->host, p->port,
|
||||
spdk_cpuset_fmt(p->cpumask));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
spdk_iscsi_portal_grp_info_json(struct spdk_iscsi_portal_grp *pg,
|
||||
struct spdk_json_write_ctx *w)
|
||||
{
|
||||
struct spdk_iscsi_portal *portal;
|
||||
|
||||
spdk_json_write_object_begin(w);
|
||||
|
||||
spdk_json_write_named_int32(w, "tag", pg->tag);
|
||||
|
||||
spdk_json_write_named_array_begin(w, "portals");
|
||||
TAILQ_FOREACH(portal, &pg->head, per_pg_tailq) {
|
||||
spdk_json_write_object_begin(w);
|
||||
|
||||
spdk_json_write_named_string(w, "host", portal->host);
|
||||
spdk_json_write_named_string(w, "port", portal->port);
|
||||
spdk_json_write_named_string_fmt(w, "cpumask", "0x%s",
|
||||
spdk_cpuset_fmt(portal->cpumask));
|
||||
|
||||
spdk_json_write_object_end(w);
|
||||
}
|
||||
spdk_json_write_array_end(w);
|
||||
|
||||
spdk_json_write_object_end(w);
|
||||
}
|
||||
|
||||
static void
|
||||
spdk_iscsi_portal_grp_config_json(struct spdk_iscsi_portal_grp *pg,
|
||||
struct spdk_json_write_ctx *w)
|
||||
{
|
||||
spdk_json_write_named_string(w, "method", "add_portal_group");
|
||||
|
||||
spdk_json_write_name(w, "params");
|
||||
spdk_iscsi_portal_grp_info_json(pg, w);
|
||||
|
||||
spdk_json_write_object_end(w);
|
||||
}
|
||||
|
||||
void
|
||||
spdk_iscsi_portal_grps_info_json(struct spdk_json_write_ctx *w)
|
||||
{
|
||||
struct spdk_iscsi_portal_grp *pg;
|
||||
|
||||
TAILQ_FOREACH(pg, &g_spdk_iscsi.pg_head, tailq) {
|
||||
spdk_iscsi_portal_grp_info_json(pg, w);
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
spdk_iscsi_portal_grps_config_json(struct spdk_json_write_ctx *w)
|
||||
{
|
||||
struct spdk_iscsi_portal_grp *pg;
|
||||
|
||||
TAILQ_FOREACH(pg, &g_spdk_iscsi.pg_head, tailq) {
|
||||
spdk_iscsi_portal_grp_config_json(pg, w);
|
||||
}
|
||||
}
|
||||
|
@ -38,6 +38,8 @@
|
||||
#include "spdk/conf.h"
|
||||
#include "spdk/cpuset.h"
|
||||
|
||||
struct spdk_json_write_ctx;
|
||||
|
||||
struct spdk_iscsi_portal {
|
||||
struct spdk_iscsi_portal_grp *group;
|
||||
char *host;
|
||||
@ -75,4 +77,7 @@ struct spdk_iscsi_portal_grp *spdk_iscsi_portal_grp_find_by_tag(int tag);
|
||||
int spdk_iscsi_portal_grp_open(struct spdk_iscsi_portal_grp *pg);
|
||||
|
||||
void spdk_iscsi_portal_grp_close_all(void);
|
||||
void spdk_iscsi_portal_grps_config_text(FILE *fp);
|
||||
void spdk_iscsi_portal_grps_info_json(struct spdk_json_write_ctx *w);
|
||||
void spdk_iscsi_portal_grps_config_json(struct spdk_json_write_ctx *w);
|
||||
#endif // SPDK_PORTAL_GRP_H
|
||||
|
@ -38,6 +38,7 @@
|
||||
|
||||
#include "../common.c"
|
||||
#include "iscsi/portal_grp.c"
|
||||
#include "unit/lib/json_mock.c"
|
||||
|
||||
struct spdk_iscsi_globals g_spdk_iscsi;
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user