From 29c29ff9b6f44dd891981c641dbfc00b226f3f2b Mon Sep 17 00:00:00 2001 From: Shuhei Matsumoto Date: Thu, 10 May 2018 07:56:04 +0900 Subject: [PATCH] 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 Reviewed-on: https://review.gerrithub.io/407850 Tested-by: SPDK Automated Test System Reviewed-by: Jim Harris Reviewed-by: Pawel Wodkowski Reviewed-by: Daniel Verkamp --- lib/iscsi/iscsi_rpc.c | 34 +----- lib/iscsi/iscsi_subsystem.c | 50 +-------- lib/iscsi/portal_grp.c | 104 ++++++++++++++++++ lib/iscsi/portal_grp.h | 5 + .../lib/iscsi/portal_grp.c/portal_grp_ut.c | 1 + 5 files changed, 113 insertions(+), 81 deletions(-) diff --git a/lib/iscsi/iscsi_rpc.c b/lib/iscsi/iscsi_rpc.c index 072bf4f39..139616c19 100644 --- a/lib/iscsi/iscsi_rpc.c +++ b/lib/iscsi/iscsi_rpc.c @@ -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); diff --git a/lib/iscsi/iscsi_subsystem.c b/lib/iscsi/iscsi_subsystem.c index 9fdcce609..fe5d7f848 100644 --- a/lib/iscsi/iscsi_subsystem.c +++ b/lib/iscsi/iscsi_subsystem.c @@ -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 [:[@]]\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); diff --git a/lib/iscsi/portal_grp.c b/lib/iscsi/portal_grp.c index 0a09e28b9..f26259686 100644 --- a/lib/iscsi/portal_grp.c +++ b/lib/iscsi/portal_grp.c @@ -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 [:[@]]\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); + } +} diff --git a/lib/iscsi/portal_grp.h b/lib/iscsi/portal_grp.h index c4672ea16..08cb39926 100644 --- a/lib/iscsi/portal_grp.h +++ b/lib/iscsi/portal_grp.h @@ -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 diff --git a/test/unit/lib/iscsi/portal_grp.c/portal_grp_ut.c b/test/unit/lib/iscsi/portal_grp.c/portal_grp_ut.c index b45f0adf1..dcbe7507a 100644 --- a/test/unit/lib/iscsi/portal_grp.c/portal_grp_ut.c +++ b/test/unit/lib/iscsi/portal_grp.c/portal_grp_ut.c @@ -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;