2016-08-02 16:34:45 +00:00
|
|
|
/*-
|
|
|
|
* BSD LICENSE
|
|
|
|
*
|
|
|
|
* Copyright (C) 2008-2012 Daisuke Aoyama <aoyama@peach.ne.jp>.
|
|
|
|
* 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 "iscsi/iscsi.h"
|
|
|
|
#include "iscsi/conn.h"
|
|
|
|
#include "iscsi/tgt_node.h"
|
|
|
|
#include "iscsi/portal_grp.h"
|
|
|
|
#include "iscsi/init_grp.h"
|
|
|
|
|
|
|
|
#include "spdk/rpc.h"
|
2017-03-03 20:44:04 +00:00
|
|
|
#include "spdk/util.h"
|
2018-08-22 04:43:18 +00:00
|
|
|
#include "spdk/string.h"
|
2020-10-06 16:16:26 +00:00
|
|
|
#include "spdk/log.h"
|
2016-11-07 22:10:28 +00:00
|
|
|
|
2016-08-02 16:34:45 +00:00
|
|
|
static void
|
2020-04-16 03:15:35 +00:00
|
|
|
rpc_iscsi_get_initiator_groups(struct spdk_jsonrpc_request *request,
|
|
|
|
const struct spdk_json_val *params)
|
2016-08-02 16:34:45 +00:00
|
|
|
{
|
|
|
|
struct spdk_json_write_ctx *w;
|
|
|
|
|
|
|
|
if (params != NULL) {
|
2017-06-29 20:37:39 +00:00
|
|
|
spdk_jsonrpc_send_error_response(request, SPDK_JSONRPC_ERROR_INVALID_PARAMS,
|
2019-09-02 22:10:36 +00:00
|
|
|
"iscsi_get_initiator_groups requires no parameters");
|
2016-08-02 16:34:45 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2017-06-29 20:37:39 +00:00
|
|
|
w = spdk_jsonrpc_begin_result(request);
|
2016-08-02 16:34:45 +00:00
|
|
|
spdk_json_write_array_begin(w);
|
2020-04-15 21:39:41 +00:00
|
|
|
iscsi_init_grps_info_json(w);
|
2016-08-02 16:34:45 +00:00
|
|
|
spdk_json_write_array_end(w);
|
|
|
|
|
2017-06-29 20:37:39 +00:00
|
|
|
spdk_jsonrpc_end_result(request, w);
|
2016-08-02 16:34:45 +00:00
|
|
|
}
|
2020-04-16 03:15:35 +00:00
|
|
|
SPDK_RPC_REGISTER("iscsi_get_initiator_groups", rpc_iscsi_get_initiator_groups,
|
2019-09-02 22:10:36 +00:00
|
|
|
SPDK_RPC_RUNTIME)
|
|
|
|
SPDK_RPC_REGISTER_ALIAS_DEPRECATED(iscsi_get_initiator_groups, get_initiator_groups)
|
2016-08-02 16:34:45 +00:00
|
|
|
|
|
|
|
struct rpc_initiator_list {
|
|
|
|
size_t num_initiators;
|
|
|
|
char *initiators[MAX_INITIATOR];
|
|
|
|
};
|
|
|
|
|
|
|
|
static int
|
|
|
|
decode_rpc_initiator_list(const struct spdk_json_val *val, void *out)
|
|
|
|
{
|
|
|
|
struct rpc_initiator_list *list = out;
|
|
|
|
|
|
|
|
return spdk_json_decode_array(val, spdk_json_decode_string, list->initiators, MAX_INITIATOR,
|
|
|
|
&list->num_initiators, sizeof(char *));
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
free_rpc_initiator_list(struct rpc_initiator_list *list)
|
|
|
|
{
|
|
|
|
size_t i;
|
|
|
|
|
|
|
|
for (i = 0; i < list->num_initiators; i++) {
|
|
|
|
free(list->initiators[i]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
struct rpc_netmask_list {
|
|
|
|
size_t num_netmasks;
|
|
|
|
char *netmasks[MAX_NETMASK];
|
|
|
|
};
|
|
|
|
|
|
|
|
static int
|
|
|
|
decode_rpc_netmask_list(const struct spdk_json_val *val, void *out)
|
|
|
|
{
|
|
|
|
struct rpc_netmask_list *list = out;
|
|
|
|
|
|
|
|
return spdk_json_decode_array(val, spdk_json_decode_string, list->netmasks, MAX_NETMASK,
|
|
|
|
&list->num_netmasks, sizeof(char *));
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
free_rpc_netmask_list(struct rpc_netmask_list *list)
|
|
|
|
{
|
|
|
|
size_t i;
|
|
|
|
|
|
|
|
for (i = 0; i < list->num_netmasks; i++) {
|
|
|
|
free(list->netmasks[i]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
struct rpc_initiator_group {
|
|
|
|
int32_t tag;
|
|
|
|
struct rpc_initiator_list initiator_list;
|
|
|
|
struct rpc_netmask_list netmask_list;
|
|
|
|
};
|
|
|
|
|
|
|
|
static void
|
|
|
|
free_rpc_initiator_group(struct rpc_initiator_group *ig)
|
|
|
|
{
|
|
|
|
free_rpc_initiator_list(&ig->initiator_list);
|
|
|
|
free_rpc_netmask_list(&ig->netmask_list);
|
|
|
|
}
|
|
|
|
|
|
|
|
static const struct spdk_json_object_decoder rpc_initiator_group_decoders[] = {
|
|
|
|
{"tag", offsetof(struct rpc_initiator_group, tag), spdk_json_decode_int32},
|
|
|
|
{"initiators", offsetof(struct rpc_initiator_group, initiator_list), decode_rpc_initiator_list},
|
|
|
|
{"netmasks", offsetof(struct rpc_initiator_group, netmask_list), decode_rpc_netmask_list},
|
|
|
|
};
|
|
|
|
|
|
|
|
static void
|
2020-04-16 03:15:35 +00:00
|
|
|
rpc_iscsi_create_initiator_group(struct spdk_jsonrpc_request *request,
|
|
|
|
const struct spdk_json_val *params)
|
2016-08-02 16:34:45 +00:00
|
|
|
{
|
|
|
|
struct rpc_initiator_group req = {};
|
|
|
|
|
|
|
|
if (spdk_json_decode_object(params, rpc_initiator_group_decoders,
|
2017-03-03 20:44:04 +00:00
|
|
|
SPDK_COUNTOF(rpc_initiator_group_decoders), &req)) {
|
2016-11-17 06:33:54 +00:00
|
|
|
SPDK_ERRLOG("spdk_json_decode_object failed\n");
|
2016-08-02 16:34:45 +00:00
|
|
|
goto invalid;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (req.initiator_list.num_initiators == 0 ||
|
|
|
|
req.netmask_list.num_netmasks == 0) {
|
|
|
|
goto invalid;
|
|
|
|
}
|
|
|
|
|
2020-04-15 21:39:41 +00:00
|
|
|
if (iscsi_init_grp_create_from_initiator_list(req.tag,
|
2016-08-02 16:34:45 +00:00
|
|
|
req.initiator_list.num_initiators,
|
2017-10-24 01:01:12 +00:00
|
|
|
req.initiator_list.initiators,
|
2016-08-02 16:34:45 +00:00
|
|
|
req.netmask_list.num_netmasks,
|
2017-10-24 01:01:12 +00:00
|
|
|
req.netmask_list.netmasks)) {
|
2016-11-17 06:33:54 +00:00
|
|
|
SPDK_ERRLOG("create_from_initiator_list failed\n");
|
2016-08-02 16:34:45 +00:00
|
|
|
goto invalid;
|
|
|
|
}
|
|
|
|
|
|
|
|
free_rpc_initiator_group(&req);
|
|
|
|
|
2020-11-06 16:58:30 +00:00
|
|
|
spdk_jsonrpc_send_bool_response(request, true);
|
2016-08-02 16:34:45 +00:00
|
|
|
return;
|
|
|
|
|
|
|
|
invalid:
|
2017-06-29 20:37:39 +00:00
|
|
|
spdk_jsonrpc_send_error_response(request, SPDK_JSONRPC_ERROR_INVALID_PARAMS, "Invalid parameters");
|
2016-08-02 16:34:45 +00:00
|
|
|
free_rpc_initiator_group(&req);
|
|
|
|
}
|
2020-04-16 03:15:35 +00:00
|
|
|
SPDK_RPC_REGISTER("iscsi_create_initiator_group", rpc_iscsi_create_initiator_group,
|
2019-09-03 08:53:37 +00:00
|
|
|
SPDK_RPC_RUNTIME)
|
|
|
|
SPDK_RPC_REGISTER_ALIAS_DEPRECATED(iscsi_create_initiator_group, add_initiator_group)
|
2016-08-02 16:34:45 +00:00
|
|
|
|
2018-02-06 23:22:00 +00:00
|
|
|
static const struct spdk_json_object_decoder rpc_add_or_delete_initiators_decoders[] = {
|
|
|
|
{"tag", offsetof(struct rpc_initiator_group, tag), spdk_json_decode_int32},
|
|
|
|
{"initiators", offsetof(struct rpc_initiator_group, initiator_list), decode_rpc_initiator_list, true},
|
|
|
|
{"netmasks", offsetof(struct rpc_initiator_group, netmask_list), decode_rpc_netmask_list, true},
|
|
|
|
};
|
|
|
|
|
|
|
|
static void
|
2020-04-16 03:15:35 +00:00
|
|
|
rpc_iscsi_initiator_group_add_initiators(struct spdk_jsonrpc_request *request,
|
2018-02-06 23:22:00 +00:00
|
|
|
const struct spdk_json_val *params)
|
|
|
|
{
|
|
|
|
struct rpc_initiator_group req = {};
|
|
|
|
|
|
|
|
if (spdk_json_decode_object(params, rpc_add_or_delete_initiators_decoders,
|
|
|
|
SPDK_COUNTOF(rpc_add_or_delete_initiators_decoders), &req)) {
|
|
|
|
SPDK_ERRLOG("spdk_json_decode_object failed\n");
|
|
|
|
goto invalid;
|
|
|
|
}
|
|
|
|
|
2020-04-15 21:39:41 +00:00
|
|
|
if (iscsi_init_grp_add_initiators_from_initiator_list(req.tag,
|
2018-02-06 23:22:00 +00:00
|
|
|
req.initiator_list.num_initiators,
|
|
|
|
req.initiator_list.initiators,
|
|
|
|
req.netmask_list.num_netmasks,
|
|
|
|
req.netmask_list.netmasks)) {
|
|
|
|
SPDK_ERRLOG("add_initiators_from_initiator_list failed\n");
|
|
|
|
goto invalid;
|
|
|
|
}
|
|
|
|
|
|
|
|
free_rpc_initiator_group(&req);
|
|
|
|
|
2020-11-06 16:58:30 +00:00
|
|
|
spdk_jsonrpc_send_bool_response(request, true);
|
2018-02-06 23:22:00 +00:00
|
|
|
return;
|
|
|
|
|
|
|
|
invalid:
|
|
|
|
spdk_jsonrpc_send_error_response(request, SPDK_JSONRPC_ERROR_INVALID_PARAMS, "Invalid parameters");
|
|
|
|
free_rpc_initiator_group(&req);
|
|
|
|
}
|
2019-09-03 09:59:23 +00:00
|
|
|
SPDK_RPC_REGISTER("iscsi_initiator_group_add_initiators",
|
2020-04-16 03:15:35 +00:00
|
|
|
rpc_iscsi_initiator_group_add_initiators, SPDK_RPC_RUNTIME)
|
2019-09-03 09:59:23 +00:00
|
|
|
SPDK_RPC_REGISTER_ALIAS_DEPRECATED(iscsi_initiator_group_add_initiators,
|
|
|
|
add_initiators_to_initiator_group)
|
2018-02-06 23:22:00 +00:00
|
|
|
|
|
|
|
static void
|
2020-04-16 03:15:35 +00:00
|
|
|
rpc_iscsi_initiator_group_remove_initiators(struct spdk_jsonrpc_request *request,
|
2018-02-06 23:22:00 +00:00
|
|
|
const struct spdk_json_val *params)
|
|
|
|
{
|
|
|
|
struct rpc_initiator_group req = {};
|
|
|
|
|
|
|
|
if (spdk_json_decode_object(params, rpc_add_or_delete_initiators_decoders,
|
|
|
|
SPDK_COUNTOF(rpc_add_or_delete_initiators_decoders), &req)) {
|
|
|
|
SPDK_ERRLOG("spdk_json_decode_object failed\n");
|
|
|
|
goto invalid;
|
|
|
|
}
|
|
|
|
|
2020-04-15 21:39:41 +00:00
|
|
|
if (iscsi_init_grp_delete_initiators_from_initiator_list(req.tag,
|
2018-02-06 23:22:00 +00:00
|
|
|
req.initiator_list.num_initiators,
|
|
|
|
req.initiator_list.initiators,
|
|
|
|
req.netmask_list.num_netmasks,
|
|
|
|
req.netmask_list.netmasks)) {
|
|
|
|
SPDK_ERRLOG("delete_initiators_from_initiator_list failed\n");
|
|
|
|
goto invalid;
|
|
|
|
}
|
|
|
|
|
|
|
|
free_rpc_initiator_group(&req);
|
|
|
|
|
2020-11-06 16:58:30 +00:00
|
|
|
spdk_jsonrpc_send_bool_response(request, true);
|
2018-02-06 23:22:00 +00:00
|
|
|
return;
|
|
|
|
|
|
|
|
invalid:
|
|
|
|
spdk_jsonrpc_send_error_response(request, SPDK_JSONRPC_ERROR_INVALID_PARAMS, "Invalid parameters");
|
|
|
|
free_rpc_initiator_group(&req);
|
|
|
|
}
|
2019-09-04 09:52:01 +00:00
|
|
|
SPDK_RPC_REGISTER("iscsi_initiator_group_remove_initiators",
|
2020-04-16 03:15:35 +00:00
|
|
|
rpc_iscsi_initiator_group_remove_initiators, SPDK_RPC_RUNTIME)
|
2019-09-04 09:52:01 +00:00
|
|
|
SPDK_RPC_REGISTER_ALIAS_DEPRECATED(iscsi_initiator_group_remove_initiators,
|
|
|
|
delete_initiators_from_initiator_group)
|
2018-02-06 23:22:00 +00:00
|
|
|
|
2019-09-03 09:30:46 +00:00
|
|
|
struct rpc_iscsi_delete_initiator_group {
|
2016-08-02 16:34:45 +00:00
|
|
|
int32_t tag;
|
|
|
|
};
|
|
|
|
|
2019-09-03 09:30:46 +00:00
|
|
|
static const struct spdk_json_object_decoder rpc_iscsi_delete_initiator_group_decoders[] = {
|
|
|
|
{"tag", offsetof(struct rpc_iscsi_delete_initiator_group, tag), spdk_json_decode_int32},
|
2016-08-02 16:34:45 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
static void
|
2020-04-16 03:15:35 +00:00
|
|
|
rpc_iscsi_delete_initiator_group(struct spdk_jsonrpc_request *request,
|
|
|
|
const struct spdk_json_val *params)
|
2016-08-02 16:34:45 +00:00
|
|
|
{
|
2019-09-03 09:30:46 +00:00
|
|
|
struct rpc_iscsi_delete_initiator_group req = {};
|
2016-08-02 16:34:45 +00:00
|
|
|
struct spdk_iscsi_init_grp *ig;
|
|
|
|
|
2019-09-03 09:30:46 +00:00
|
|
|
if (spdk_json_decode_object(params, rpc_iscsi_delete_initiator_group_decoders,
|
|
|
|
SPDK_COUNTOF(rpc_iscsi_delete_initiator_group_decoders),
|
2016-08-02 16:34:45 +00:00
|
|
|
&req)) {
|
2016-11-17 06:33:54 +00:00
|
|
|
SPDK_ERRLOG("spdk_json_decode_object failed\n");
|
2016-08-02 16:34:45 +00:00
|
|
|
goto invalid;
|
|
|
|
}
|
|
|
|
|
2020-04-15 21:39:41 +00:00
|
|
|
ig = iscsi_init_grp_unregister(req.tag);
|
2016-08-02 16:34:45 +00:00
|
|
|
if (!ig) {
|
|
|
|
goto invalid;
|
|
|
|
}
|
2020-04-15 21:04:36 +00:00
|
|
|
iscsi_tgt_node_delete_map(NULL, ig);
|
2020-04-15 21:39:41 +00:00
|
|
|
iscsi_init_grp_destroy(ig);
|
2016-08-02 16:34:45 +00:00
|
|
|
|
2020-11-06 16:58:30 +00:00
|
|
|
spdk_jsonrpc_send_bool_response(request, true);
|
2016-08-02 16:34:45 +00:00
|
|
|
return;
|
|
|
|
|
|
|
|
invalid:
|
2017-06-29 20:37:39 +00:00
|
|
|
spdk_jsonrpc_send_error_response(request, SPDK_JSONRPC_ERROR_INVALID_PARAMS, "Invalid parameters");
|
2016-08-02 16:34:45 +00:00
|
|
|
}
|
2020-04-16 03:15:35 +00:00
|
|
|
SPDK_RPC_REGISTER("iscsi_delete_initiator_group", rpc_iscsi_delete_initiator_group,
|
2019-09-03 09:30:46 +00:00
|
|
|
SPDK_RPC_RUNTIME)
|
|
|
|
SPDK_RPC_REGISTER_ALIAS_DEPRECATED(iscsi_delete_initiator_group, delete_initiator_group)
|
2016-08-02 16:34:45 +00:00
|
|
|
|
2018-02-15 07:01:37 +00:00
|
|
|
static void
|
2020-04-16 03:15:35 +00:00
|
|
|
rpc_iscsi_get_target_nodes(struct spdk_jsonrpc_request *request,
|
|
|
|
const struct spdk_json_val *params)
|
2018-02-15 07:01:37 +00:00
|
|
|
{
|
|
|
|
struct spdk_json_write_ctx *w;
|
2018-01-12 05:48:39 +00:00
|
|
|
|
2018-02-15 07:01:37 +00:00
|
|
|
if (params != NULL) {
|
|
|
|
spdk_jsonrpc_send_error_response(request, SPDK_JSONRPC_ERROR_INVALID_PARAMS,
|
2019-09-04 10:20:43 +00:00
|
|
|
"iscsi_get_target_nodes requires no parameters");
|
2018-02-15 07:01:37 +00:00
|
|
|
return;
|
|
|
|
}
|
2018-01-12 05:48:39 +00:00
|
|
|
|
2018-02-15 07:01:37 +00:00
|
|
|
w = spdk_jsonrpc_begin_result(request);
|
|
|
|
spdk_json_write_array_begin(w);
|
2020-04-15 21:04:36 +00:00
|
|
|
iscsi_tgt_nodes_info_json(w);
|
2016-08-02 16:34:45 +00:00
|
|
|
spdk_json_write_array_end(w);
|
|
|
|
|
2017-06-29 20:37:39 +00:00
|
|
|
spdk_jsonrpc_end_result(request, w);
|
2016-08-02 16:34:45 +00:00
|
|
|
}
|
2020-04-16 03:15:35 +00:00
|
|
|
SPDK_RPC_REGISTER("iscsi_get_target_nodes", rpc_iscsi_get_target_nodes, SPDK_RPC_RUNTIME)
|
2019-09-04 10:20:43 +00:00
|
|
|
SPDK_RPC_REGISTER_ALIAS_DEPRECATED(iscsi_get_target_nodes, get_target_nodes)
|
2016-08-02 16:34:45 +00:00
|
|
|
|
2018-02-18 23:22:22 +00:00
|
|
|
struct rpc_pg_ig_map {
|
|
|
|
int32_t pg_tag;
|
|
|
|
int32_t ig_tag;
|
|
|
|
};
|
|
|
|
|
|
|
|
static const struct spdk_json_object_decoder rpc_pg_ig_map_decoders[] = {
|
|
|
|
{"pg_tag", offsetof(struct rpc_pg_ig_map, pg_tag), spdk_json_decode_int32},
|
|
|
|
{"ig_tag", offsetof(struct rpc_pg_ig_map, ig_tag), spdk_json_decode_int32},
|
2016-08-02 16:34:45 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
static int
|
2018-02-18 23:22:22 +00:00
|
|
|
decode_rpc_pg_ig_map(const struct spdk_json_val *val, void *out)
|
2016-08-02 16:34:45 +00:00
|
|
|
{
|
2018-02-18 23:22:22 +00:00
|
|
|
struct rpc_pg_ig_map *pg_ig_map = out;
|
2016-08-02 16:34:45 +00:00
|
|
|
|
2018-02-18 23:22:22 +00:00
|
|
|
return spdk_json_decode_object(val, rpc_pg_ig_map_decoders,
|
|
|
|
SPDK_COUNTOF(rpc_pg_ig_map_decoders),
|
|
|
|
pg_ig_map);
|
2016-08-02 16:34:45 +00:00
|
|
|
}
|
|
|
|
|
2018-02-18 23:22:22 +00:00
|
|
|
struct rpc_pg_ig_maps {
|
|
|
|
size_t num_maps;
|
|
|
|
struct rpc_pg_ig_map maps[MAX_TARGET_MAP];
|
2016-08-02 16:34:45 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
static int
|
2018-02-18 23:22:22 +00:00
|
|
|
decode_rpc_pg_ig_maps(const struct spdk_json_val *val, void *out)
|
2016-08-02 16:34:45 +00:00
|
|
|
{
|
2018-02-18 23:22:22 +00:00
|
|
|
struct rpc_pg_ig_maps *pg_ig_maps = out;
|
2016-08-02 16:34:45 +00:00
|
|
|
|
2018-02-18 23:22:22 +00:00
|
|
|
return spdk_json_decode_array(val, decode_rpc_pg_ig_map, pg_ig_maps->maps,
|
|
|
|
MAX_TARGET_MAP, &pg_ig_maps->num_maps,
|
|
|
|
sizeof(struct rpc_pg_ig_map));
|
2016-08-02 16:34:45 +00:00
|
|
|
}
|
|
|
|
|
2019-09-05 10:35:18 +00:00
|
|
|
#define RPC_ISCSI_CREATE_TARGET_NODE_MAX_LUN 64
|
2016-08-02 16:34:45 +00:00
|
|
|
|
2018-02-18 23:41:48 +00:00
|
|
|
struct rpc_lun {
|
|
|
|
char *bdev_name;
|
|
|
|
int32_t lun_id;
|
2016-08-02 16:34:45 +00:00
|
|
|
};
|
|
|
|
|
2018-02-18 23:41:48 +00:00
|
|
|
static const struct spdk_json_object_decoder rpc_lun_decoders[] = {
|
|
|
|
{"bdev_name", offsetof(struct rpc_lun, bdev_name), spdk_json_decode_string},
|
|
|
|
{"lun_id", offsetof(struct rpc_lun, lun_id), spdk_json_decode_int32},
|
|
|
|
};
|
2016-08-02 16:34:45 +00:00
|
|
|
|
2018-02-18 23:41:48 +00:00
|
|
|
static int
|
|
|
|
decode_rpc_lun(const struct spdk_json_val *val, void *out)
|
2016-08-02 16:34:45 +00:00
|
|
|
{
|
2018-02-18 23:41:48 +00:00
|
|
|
struct rpc_lun *lun = out;
|
2016-08-02 16:34:45 +00:00
|
|
|
|
2018-02-18 23:41:48 +00:00
|
|
|
return spdk_json_decode_object(val, rpc_lun_decoders,
|
|
|
|
SPDK_COUNTOF(rpc_lun_decoders), lun);
|
2016-08-02 16:34:45 +00:00
|
|
|
}
|
|
|
|
|
2018-02-18 23:41:48 +00:00
|
|
|
struct rpc_luns {
|
|
|
|
size_t num_luns;
|
2019-09-05 10:35:18 +00:00
|
|
|
struct rpc_lun luns[RPC_ISCSI_CREATE_TARGET_NODE_MAX_LUN];
|
2016-08-02 16:34:45 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
static int
|
2018-02-18 23:41:48 +00:00
|
|
|
decode_rpc_luns(const struct spdk_json_val *val, void *out)
|
2016-08-02 16:34:45 +00:00
|
|
|
{
|
2018-02-18 23:41:48 +00:00
|
|
|
struct rpc_luns *luns = out;
|
2016-08-02 16:34:45 +00:00
|
|
|
|
2018-02-18 23:41:48 +00:00
|
|
|
return spdk_json_decode_array(val, decode_rpc_lun, luns->luns,
|
2019-09-05 10:35:18 +00:00
|
|
|
RPC_ISCSI_CREATE_TARGET_NODE_MAX_LUN,
|
2018-02-18 23:41:48 +00:00
|
|
|
&luns->num_luns, sizeof(struct rpc_lun));
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
free_rpc_luns(struct rpc_luns *p)
|
|
|
|
{
|
|
|
|
size_t i;
|
|
|
|
|
|
|
|
for (i = 0; i < p->num_luns; i++) {
|
|
|
|
free(p->luns[i].bdev_name);
|
|
|
|
}
|
2016-08-02 16:34:45 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
struct rpc_target_node {
|
|
|
|
char *name;
|
|
|
|
char *alias_name;
|
|
|
|
|
2018-02-18 23:22:22 +00:00
|
|
|
struct rpc_pg_ig_maps pg_ig_maps;
|
2018-02-18 23:41:48 +00:00
|
|
|
struct rpc_luns luns;
|
2016-08-02 16:34:45 +00:00
|
|
|
|
|
|
|
int32_t queue_depth;
|
2018-02-21 17:51:16 +00:00
|
|
|
bool disable_chap;
|
|
|
|
bool require_chap;
|
|
|
|
bool mutual_chap;
|
|
|
|
int32_t chap_group;
|
2018-01-12 05:48:39 +00:00
|
|
|
|
2018-02-21 09:47:34 +00:00
|
|
|
bool header_digest;
|
|
|
|
bool data_digest;
|
2016-08-02 16:34:45 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
static void
|
|
|
|
free_rpc_target_node(struct rpc_target_node *req)
|
|
|
|
{
|
2017-08-08 23:09:26 +00:00
|
|
|
free(req->name);
|
|
|
|
free(req->alias_name);
|
2018-02-18 23:41:48 +00:00
|
|
|
free_rpc_luns(&req->luns);
|
2016-08-02 16:34:45 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static const struct spdk_json_object_decoder rpc_target_node_decoders[] = {
|
|
|
|
{"name", offsetof(struct rpc_target_node, name), spdk_json_decode_string},
|
|
|
|
{"alias_name", offsetof(struct rpc_target_node, alias_name), spdk_json_decode_string},
|
2018-02-18 23:22:22 +00:00
|
|
|
{"pg_ig_maps", offsetof(struct rpc_target_node, pg_ig_maps), decode_rpc_pg_ig_maps},
|
2018-02-18 23:41:48 +00:00
|
|
|
{"luns", offsetof(struct rpc_target_node, luns), decode_rpc_luns},
|
2016-08-02 16:34:45 +00:00
|
|
|
{"queue_depth", offsetof(struct rpc_target_node, queue_depth), spdk_json_decode_int32},
|
2018-02-21 17:51:16 +00:00
|
|
|
{"disable_chap", offsetof(struct rpc_target_node, disable_chap), spdk_json_decode_bool, true},
|
|
|
|
{"require_chap", offsetof(struct rpc_target_node, require_chap), spdk_json_decode_bool, true},
|
|
|
|
{"mutual_chap", offsetof(struct rpc_target_node, mutual_chap), spdk_json_decode_bool, true},
|
|
|
|
{"chap_group", offsetof(struct rpc_target_node, chap_group), spdk_json_decode_int32, true},
|
2018-02-21 09:47:34 +00:00
|
|
|
{"header_digest", offsetof(struct rpc_target_node, header_digest), spdk_json_decode_bool, true},
|
|
|
|
{"data_digest", offsetof(struct rpc_target_node, data_digest), spdk_json_decode_bool, true},
|
2016-08-02 16:34:45 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
static void
|
2020-04-16 03:15:35 +00:00
|
|
|
rpc_iscsi_create_target_node(struct spdk_jsonrpc_request *request,
|
|
|
|
const struct spdk_json_val *params)
|
2016-08-02 16:34:45 +00:00
|
|
|
{
|
|
|
|
struct rpc_target_node req = {};
|
|
|
|
struct spdk_iscsi_tgt_node *target;
|
2018-02-18 23:22:22 +00:00
|
|
|
int32_t pg_tags[MAX_TARGET_MAP] = {0}, ig_tags[MAX_TARGET_MAP] = {0};
|
2019-09-05 10:35:18 +00:00
|
|
|
char *bdev_names[RPC_ISCSI_CREATE_TARGET_NODE_MAX_LUN] = {0};
|
|
|
|
int32_t lun_ids[RPC_ISCSI_CREATE_TARGET_NODE_MAX_LUN] = {0};
|
2018-02-18 23:22:22 +00:00
|
|
|
size_t i;
|
2016-08-02 16:34:45 +00:00
|
|
|
|
|
|
|
if (spdk_json_decode_object(params, rpc_target_node_decoders,
|
2017-03-03 20:44:04 +00:00
|
|
|
SPDK_COUNTOF(rpc_target_node_decoders),
|
2016-08-02 16:34:45 +00:00
|
|
|
&req)) {
|
2016-11-17 06:33:54 +00:00
|
|
|
SPDK_ERRLOG("spdk_json_decode_object failed\n");
|
2016-08-02 16:34:45 +00:00
|
|
|
goto invalid;
|
|
|
|
}
|
|
|
|
|
2018-02-18 23:22:22 +00:00
|
|
|
for (i = 0; i < req.pg_ig_maps.num_maps; i++) {
|
|
|
|
pg_tags[i] = req.pg_ig_maps.maps[i].pg_tag;
|
|
|
|
ig_tags[i] = req.pg_ig_maps.maps[i].ig_tag;
|
|
|
|
}
|
|
|
|
|
2018-02-18 23:41:48 +00:00
|
|
|
for (i = 0; i < req.luns.num_luns; i++) {
|
|
|
|
bdev_names[i] = req.luns.luns[i].bdev_name;
|
|
|
|
lun_ids[i] = req.luns.luns[i].lun_id;
|
|
|
|
}
|
|
|
|
|
2016-08-02 16:34:45 +00:00
|
|
|
/*
|
|
|
|
* Use default parameters in a few places:
|
|
|
|
* index = -1 : automatically pick an index for the new target node
|
|
|
|
* alias = NULL
|
|
|
|
*/
|
2020-04-15 21:04:36 +00:00
|
|
|
target = iscsi_tgt_node_construct(-1, req.name, req.alias_name,
|
|
|
|
pg_tags,
|
|
|
|
ig_tags,
|
|
|
|
req.pg_ig_maps.num_maps,
|
|
|
|
(const char **)bdev_names,
|
|
|
|
lun_ids,
|
|
|
|
req.luns.num_luns,
|
|
|
|
req.queue_depth,
|
|
|
|
req.disable_chap,
|
|
|
|
req.require_chap,
|
|
|
|
req.mutual_chap,
|
|
|
|
req.chap_group,
|
|
|
|
req.header_digest,
|
|
|
|
req.data_digest);
|
2016-08-02 16:34:45 +00:00
|
|
|
|
|
|
|
if (target == NULL) {
|
|
|
|
goto invalid;
|
|
|
|
}
|
|
|
|
|
|
|
|
free_rpc_target_node(&req);
|
|
|
|
|
2020-11-06 16:58:30 +00:00
|
|
|
spdk_jsonrpc_send_bool_response(request, true);
|
2016-08-02 16:34:45 +00:00
|
|
|
return;
|
|
|
|
|
|
|
|
invalid:
|
2017-06-29 20:37:39 +00:00
|
|
|
spdk_jsonrpc_send_error_response(request, SPDK_JSONRPC_ERROR_INVALID_PARAMS, "Invalid parameters");
|
2016-08-02 16:34:45 +00:00
|
|
|
free_rpc_target_node(&req);
|
|
|
|
}
|
2020-04-16 03:15:35 +00:00
|
|
|
SPDK_RPC_REGISTER("iscsi_create_target_node", rpc_iscsi_create_target_node, SPDK_RPC_RUNTIME)
|
2019-09-05 10:35:18 +00:00
|
|
|
SPDK_RPC_REGISTER_ALIAS_DEPRECATED(iscsi_create_target_node, construct_target_node)
|
2016-08-02 16:34:45 +00:00
|
|
|
|
2018-02-18 23:22:22 +00:00
|
|
|
struct rpc_tgt_node_pg_ig_maps {
|
2017-12-05 06:54:57 +00:00
|
|
|
char *name;
|
2018-02-18 23:22:22 +00:00
|
|
|
struct rpc_pg_ig_maps pg_ig_maps;
|
2017-12-05 06:54:57 +00:00
|
|
|
};
|
|
|
|
|
2018-02-18 23:22:22 +00:00
|
|
|
static const struct spdk_json_object_decoder rpc_tgt_node_pg_ig_maps_decoders[] = {
|
|
|
|
{"name", offsetof(struct rpc_tgt_node_pg_ig_maps, name), spdk_json_decode_string},
|
|
|
|
{"pg_ig_maps", offsetof(struct rpc_tgt_node_pg_ig_maps, pg_ig_maps), decode_rpc_pg_ig_maps},
|
2017-12-05 06:54:57 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
static void
|
2020-04-16 03:15:35 +00:00
|
|
|
rpc_iscsi_target_node_add_pg_ig_maps(struct spdk_jsonrpc_request *request,
|
|
|
|
const struct spdk_json_val *params)
|
2017-12-05 06:54:57 +00:00
|
|
|
{
|
2018-02-18 23:22:22 +00:00
|
|
|
struct rpc_tgt_node_pg_ig_maps req = {};
|
2017-12-05 06:54:57 +00:00
|
|
|
struct spdk_iscsi_tgt_node *target;
|
2018-02-18 23:22:22 +00:00
|
|
|
int32_t pg_tags[MAX_TARGET_MAP] = {0}, ig_tags[MAX_TARGET_MAP] = {0};
|
|
|
|
size_t i;
|
2017-12-05 06:54:57 +00:00
|
|
|
int rc;
|
|
|
|
|
2018-02-18 23:22:22 +00:00
|
|
|
if (spdk_json_decode_object(params, rpc_tgt_node_pg_ig_maps_decoders,
|
|
|
|
SPDK_COUNTOF(rpc_tgt_node_pg_ig_maps_decoders),
|
2017-12-05 06:54:57 +00:00
|
|
|
&req)) {
|
|
|
|
SPDK_ERRLOG("spdk_json_decode_object failed\n");
|
|
|
|
goto invalid;
|
|
|
|
}
|
|
|
|
|
2020-04-15 21:04:36 +00:00
|
|
|
target = iscsi_find_tgt_node(req.name);
|
2017-12-05 06:54:57 +00:00
|
|
|
if (target == NULL) {
|
|
|
|
SPDK_ERRLOG("target is not found\n");
|
|
|
|
goto invalid;
|
|
|
|
}
|
|
|
|
|
2018-02-18 23:22:22 +00:00
|
|
|
for (i = 0; i < req.pg_ig_maps.num_maps; i++) {
|
|
|
|
pg_tags[i] = req.pg_ig_maps.maps[i].pg_tag;
|
|
|
|
ig_tags[i] = req.pg_ig_maps.maps[i].ig_tag;
|
|
|
|
}
|
|
|
|
|
2020-04-15 21:04:36 +00:00
|
|
|
rc = iscsi_target_node_add_pg_ig_maps(target, pg_tags, ig_tags,
|
|
|
|
req.pg_ig_maps.num_maps);
|
2017-12-05 06:54:57 +00:00
|
|
|
if (rc < 0) {
|
|
|
|
SPDK_ERRLOG("add pg-ig maps failed\n");
|
|
|
|
goto invalid;
|
|
|
|
}
|
|
|
|
|
|
|
|
free(req.name);
|
|
|
|
|
2020-11-06 16:58:30 +00:00
|
|
|
spdk_jsonrpc_send_bool_response(request, true);
|
2017-12-05 06:54:57 +00:00
|
|
|
return;
|
|
|
|
|
|
|
|
invalid:
|
|
|
|
spdk_jsonrpc_send_error_response(request, SPDK_JSONRPC_ERROR_INVALID_PARAMS,
|
|
|
|
"Invalid parameters");
|
|
|
|
free(req.name);
|
|
|
|
}
|
2019-09-06 08:42:19 +00:00
|
|
|
SPDK_RPC_REGISTER("iscsi_target_node_add_pg_ig_maps",
|
2020-04-16 03:15:35 +00:00
|
|
|
rpc_iscsi_target_node_add_pg_ig_maps, SPDK_RPC_RUNTIME)
|
2019-09-06 08:42:19 +00:00
|
|
|
SPDK_RPC_REGISTER_ALIAS_DEPRECATED(iscsi_target_node_add_pg_ig_maps, add_pg_ig_maps)
|
2017-12-05 06:54:57 +00:00
|
|
|
|
|
|
|
static void
|
2020-04-16 03:15:35 +00:00
|
|
|
rpc_iscsi_target_node_remove_pg_ig_maps(struct spdk_jsonrpc_request *request,
|
|
|
|
const struct spdk_json_val *params)
|
2017-12-05 06:54:57 +00:00
|
|
|
{
|
2018-02-18 23:22:22 +00:00
|
|
|
struct rpc_tgt_node_pg_ig_maps req = {};
|
2017-12-05 06:54:57 +00:00
|
|
|
struct spdk_iscsi_tgt_node *target;
|
2018-02-18 23:22:22 +00:00
|
|
|
int32_t pg_tags[MAX_TARGET_MAP] = {0}, ig_tags[MAX_TARGET_MAP] = {0};
|
|
|
|
size_t i;
|
2017-12-05 06:54:57 +00:00
|
|
|
int rc;
|
|
|
|
|
2018-02-18 23:22:22 +00:00
|
|
|
if (spdk_json_decode_object(params, rpc_tgt_node_pg_ig_maps_decoders,
|
|
|
|
SPDK_COUNTOF(rpc_tgt_node_pg_ig_maps_decoders),
|
2017-12-05 06:54:57 +00:00
|
|
|
&req)) {
|
|
|
|
SPDK_ERRLOG("spdk_json_decode_object failed\n");
|
|
|
|
goto invalid;
|
|
|
|
}
|
|
|
|
|
2020-04-15 21:04:36 +00:00
|
|
|
target = iscsi_find_tgt_node(req.name);
|
2017-12-05 06:54:57 +00:00
|
|
|
if (target == NULL) {
|
|
|
|
SPDK_ERRLOG("target is not found\n");
|
|
|
|
goto invalid;
|
|
|
|
}
|
|
|
|
|
2018-02-18 23:22:22 +00:00
|
|
|
for (i = 0; i < req.pg_ig_maps.num_maps; i++) {
|
|
|
|
pg_tags[i] = req.pg_ig_maps.maps[i].pg_tag;
|
|
|
|
ig_tags[i] = req.pg_ig_maps.maps[i].ig_tag;
|
|
|
|
}
|
|
|
|
|
2020-04-15 21:04:36 +00:00
|
|
|
rc = iscsi_target_node_remove_pg_ig_maps(target, pg_tags, ig_tags,
|
2018-02-18 23:22:22 +00:00
|
|
|
req.pg_ig_maps.num_maps);
|
2017-12-05 06:54:57 +00:00
|
|
|
if (rc < 0) {
|
|
|
|
SPDK_ERRLOG("remove pg-ig maps failed\n");
|
|
|
|
goto invalid;
|
|
|
|
}
|
|
|
|
|
|
|
|
free(req.name);
|
|
|
|
|
2020-11-06 16:58:30 +00:00
|
|
|
spdk_jsonrpc_send_bool_response(request, true);
|
2017-12-05 06:54:57 +00:00
|
|
|
return;
|
|
|
|
|
|
|
|
invalid:
|
|
|
|
spdk_jsonrpc_send_error_response(request, SPDK_JSONRPC_ERROR_INVALID_PARAMS,
|
|
|
|
"Invalid parameters");
|
|
|
|
free(req.name);
|
|
|
|
}
|
2019-09-06 08:59:10 +00:00
|
|
|
SPDK_RPC_REGISTER("iscsi_target_node_remove_pg_ig_maps",
|
2020-04-16 03:15:35 +00:00
|
|
|
rpc_iscsi_target_node_remove_pg_ig_maps, SPDK_RPC_RUNTIME)
|
2019-09-06 08:59:10 +00:00
|
|
|
SPDK_RPC_REGISTER_ALIAS_DEPRECATED(iscsi_target_node_remove_pg_ig_maps,
|
|
|
|
delete_pg_ig_maps)
|
2017-12-05 06:54:57 +00:00
|
|
|
|
2019-09-05 10:52:14 +00:00
|
|
|
struct rpc_iscsi_delete_target_node {
|
2016-08-02 16:34:45 +00:00
|
|
|
char *name;
|
|
|
|
};
|
|
|
|
|
|
|
|
static void
|
2019-09-05 10:52:14 +00:00
|
|
|
free_rpc_iscsi_delete_target_node(struct rpc_iscsi_delete_target_node *r)
|
2016-08-02 16:34:45 +00:00
|
|
|
{
|
|
|
|
free(r->name);
|
|
|
|
}
|
|
|
|
|
2019-09-05 10:52:14 +00:00
|
|
|
static const struct spdk_json_object_decoder rpc_iscsi_delete_target_node_decoders[] = {
|
|
|
|
{"name", offsetof(struct rpc_iscsi_delete_target_node, name), spdk_json_decode_string},
|
2016-08-02 16:34:45 +00:00
|
|
|
};
|
|
|
|
|
2019-09-05 10:52:14 +00:00
|
|
|
struct rpc_iscsi_delete_target_node_ctx {
|
|
|
|
struct rpc_iscsi_delete_target_node req;
|
2019-04-09 05:22:19 +00:00
|
|
|
struct spdk_jsonrpc_request *request;
|
|
|
|
};
|
|
|
|
|
|
|
|
static void
|
2019-09-05 10:52:14 +00:00
|
|
|
rpc_iscsi_delete_target_node_done(void *cb_arg, int rc)
|
2019-04-09 05:22:19 +00:00
|
|
|
{
|
2019-09-05 10:52:14 +00:00
|
|
|
struct rpc_iscsi_delete_target_node_ctx *ctx = cb_arg;
|
2019-04-09 05:22:19 +00:00
|
|
|
|
2019-09-05 10:52:14 +00:00
|
|
|
free_rpc_iscsi_delete_target_node(&ctx->req);
|
2020-11-06 16:58:30 +00:00
|
|
|
spdk_jsonrpc_send_bool_response(ctx->request, rc == 0);
|
2019-04-09 05:22:19 +00:00
|
|
|
free(ctx);
|
|
|
|
}
|
|
|
|
|
2016-08-02 16:34:45 +00:00
|
|
|
static void
|
2020-04-16 03:15:35 +00:00
|
|
|
rpc_iscsi_delete_target_node(struct spdk_jsonrpc_request *request,
|
|
|
|
const struct spdk_json_val *params)
|
2016-08-02 16:34:45 +00:00
|
|
|
{
|
2019-09-05 10:52:14 +00:00
|
|
|
struct rpc_iscsi_delete_target_node_ctx *ctx;
|
2019-04-09 05:22:19 +00:00
|
|
|
|
|
|
|
ctx = calloc(1, sizeof(*ctx));
|
|
|
|
if (!ctx) {
|
|
|
|
spdk_jsonrpc_send_error_response(request, SPDK_JSONRPC_ERROR_INTERNAL_ERROR,
|
|
|
|
spdk_strerror(ENOMEM));
|
|
|
|
return;
|
|
|
|
}
|
2016-08-02 16:34:45 +00:00
|
|
|
|
2019-09-05 10:52:14 +00:00
|
|
|
if (spdk_json_decode_object(params, rpc_iscsi_delete_target_node_decoders,
|
|
|
|
SPDK_COUNTOF(rpc_iscsi_delete_target_node_decoders),
|
2019-04-09 05:22:19 +00:00
|
|
|
&ctx->req)) {
|
2016-11-17 06:33:54 +00:00
|
|
|
SPDK_ERRLOG("spdk_json_decode_object failed\n");
|
2016-08-02 16:34:45 +00:00
|
|
|
goto invalid;
|
|
|
|
}
|
|
|
|
|
2019-04-09 05:22:19 +00:00
|
|
|
if (ctx->req.name == NULL) {
|
2016-11-17 06:33:54 +00:00
|
|
|
SPDK_ERRLOG("missing name param\n");
|
2016-08-02 16:34:45 +00:00
|
|
|
goto invalid;
|
|
|
|
}
|
|
|
|
|
2019-04-09 05:22:19 +00:00
|
|
|
ctx->request = request;
|
|
|
|
|
2020-04-15 21:04:36 +00:00
|
|
|
iscsi_shutdown_tgt_node_by_name(ctx->req.name,
|
|
|
|
rpc_iscsi_delete_target_node_done, ctx);
|
2016-08-02 16:34:45 +00:00
|
|
|
return;
|
|
|
|
|
|
|
|
invalid:
|
2017-06-29 20:37:39 +00:00
|
|
|
spdk_jsonrpc_send_error_response(request, SPDK_JSONRPC_ERROR_INVALID_PARAMS, "Invalid parameters");
|
2019-09-05 10:52:14 +00:00
|
|
|
free_rpc_iscsi_delete_target_node(&ctx->req);
|
2019-04-09 05:22:19 +00:00
|
|
|
free(ctx);
|
2016-08-02 16:34:45 +00:00
|
|
|
}
|
2020-04-16 03:15:35 +00:00
|
|
|
SPDK_RPC_REGISTER("iscsi_delete_target_node", rpc_iscsi_delete_target_node, SPDK_RPC_RUNTIME)
|
2019-09-05 10:52:14 +00:00
|
|
|
SPDK_RPC_REGISTER_ALIAS_DEPRECATED(iscsi_delete_target_node, delete_target_node)
|
2016-08-02 16:34:45 +00:00
|
|
|
|
|
|
|
static void
|
2020-04-16 03:15:35 +00:00
|
|
|
rpc_iscsi_get_portal_groups(struct spdk_jsonrpc_request *request,
|
|
|
|
const struct spdk_json_val *params)
|
2016-08-02 16:34:45 +00:00
|
|
|
{
|
|
|
|
struct spdk_json_write_ctx *w;
|
|
|
|
|
|
|
|
if (params != NULL) {
|
2017-06-29 20:37:39 +00:00
|
|
|
spdk_jsonrpc_send_error_response(request, SPDK_JSONRPC_ERROR_INVALID_PARAMS,
|
2019-09-09 10:12:04 +00:00
|
|
|
"iscsi_get_portal_groups requires no parameters");
|
2016-08-02 16:34:45 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2017-06-29 20:37:39 +00:00
|
|
|
w = spdk_jsonrpc_begin_result(request);
|
2016-08-02 16:34:45 +00:00
|
|
|
spdk_json_write_array_begin(w);
|
2020-04-15 21:54:21 +00:00
|
|
|
iscsi_portal_grps_info_json(w);
|
2016-08-02 16:34:45 +00:00
|
|
|
spdk_json_write_array_end(w);
|
|
|
|
|
2017-06-29 20:37:39 +00:00
|
|
|
spdk_jsonrpc_end_result(request, w);
|
2016-08-02 16:34:45 +00:00
|
|
|
}
|
2020-04-16 03:15:35 +00:00
|
|
|
SPDK_RPC_REGISTER("iscsi_get_portal_groups", rpc_iscsi_get_portal_groups, SPDK_RPC_RUNTIME)
|
2019-09-09 10:12:04 +00:00
|
|
|
SPDK_RPC_REGISTER_ALIAS_DEPRECATED(iscsi_get_portal_groups, get_portal_groups)
|
2016-08-02 16:34:45 +00:00
|
|
|
|
|
|
|
struct rpc_portal {
|
|
|
|
char *host;
|
|
|
|
char *port;
|
|
|
|
};
|
|
|
|
|
|
|
|
struct rpc_portal_list {
|
|
|
|
size_t num_portals;
|
|
|
|
struct rpc_portal portals[MAX_PORTAL];
|
|
|
|
};
|
|
|
|
|
|
|
|
struct rpc_portal_group {
|
|
|
|
int32_t tag;
|
|
|
|
struct rpc_portal_list portal_list;
|
2020-07-21 12:53:06 +00:00
|
|
|
bool is_private;
|
2020-11-12 04:42:35 +00:00
|
|
|
bool wait;
|
2016-08-02 16:34:45 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
static void
|
|
|
|
free_rpc_portal(struct rpc_portal *portal)
|
|
|
|
{
|
|
|
|
free(portal->host);
|
|
|
|
free(portal->port);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
free_rpc_portal_list(struct rpc_portal_list *pl)
|
|
|
|
{
|
|
|
|
size_t i;
|
|
|
|
|
|
|
|
for (i = 0; i < pl->num_portals; i++) {
|
|
|
|
free_rpc_portal(&pl->portals[i]);
|
|
|
|
}
|
|
|
|
pl->num_portals = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
free_rpc_portal_group(struct rpc_portal_group *pg)
|
|
|
|
{
|
|
|
|
free_rpc_portal_list(&pg->portal_list);
|
|
|
|
}
|
|
|
|
|
|
|
|
static const struct spdk_json_object_decoder rpc_portal_decoders[] = {
|
|
|
|
{"host", offsetof(struct rpc_portal, host), spdk_json_decode_string},
|
|
|
|
{"port", offsetof(struct rpc_portal, port), spdk_json_decode_string},
|
|
|
|
};
|
|
|
|
|
|
|
|
static int
|
|
|
|
decode_rpc_portal(const struct spdk_json_val *val, void *out)
|
|
|
|
{
|
|
|
|
struct rpc_portal *portal = out;
|
|
|
|
|
|
|
|
return spdk_json_decode_object(val, rpc_portal_decoders,
|
2017-03-03 20:44:04 +00:00
|
|
|
SPDK_COUNTOF(rpc_portal_decoders),
|
2016-08-02 16:34:45 +00:00
|
|
|
portal);
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
decode_rpc_portal_list(const struct spdk_json_val *val, void *out)
|
|
|
|
{
|
|
|
|
struct rpc_portal_list *list = out;
|
|
|
|
|
|
|
|
return spdk_json_decode_array(val, decode_rpc_portal, list->portals, MAX_PORTAL, &list->num_portals,
|
|
|
|
sizeof(struct rpc_portal));
|
|
|
|
}
|
|
|
|
|
|
|
|
static const struct spdk_json_object_decoder rpc_portal_group_decoders[] = {
|
|
|
|
{"tag", offsetof(struct rpc_portal_group, tag), spdk_json_decode_int32},
|
|
|
|
{"portals", offsetof(struct rpc_portal_group, portal_list), decode_rpc_portal_list},
|
2020-07-21 12:53:06 +00:00
|
|
|
{"private", offsetof(struct rpc_portal_group, is_private), spdk_json_decode_bool, true},
|
2020-11-12 04:42:35 +00:00
|
|
|
{"wait", offsetof(struct rpc_portal_group, wait), spdk_json_decode_bool, true},
|
2016-08-02 16:34:45 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
static void
|
2020-04-16 03:15:35 +00:00
|
|
|
rpc_iscsi_create_portal_group(struct spdk_jsonrpc_request *request,
|
|
|
|
const struct spdk_json_val *params)
|
2016-08-02 16:34:45 +00:00
|
|
|
{
|
|
|
|
struct rpc_portal_group req = {};
|
2018-01-29 04:36:03 +00:00
|
|
|
struct spdk_iscsi_portal_grp *pg = NULL;
|
|
|
|
struct spdk_iscsi_portal *portal;
|
2017-09-30 02:23:27 +00:00
|
|
|
size_t i = 0;
|
2017-03-09 14:23:00 +00:00
|
|
|
int rc = -1;
|
2016-08-02 16:34:45 +00:00
|
|
|
|
|
|
|
if (spdk_json_decode_object(params, rpc_portal_group_decoders,
|
2017-03-03 20:44:04 +00:00
|
|
|
SPDK_COUNTOF(rpc_portal_group_decoders),
|
2016-08-02 16:34:45 +00:00
|
|
|
&req)) {
|
2016-11-17 06:33:54 +00:00
|
|
|
SPDK_ERRLOG("spdk_json_decode_object failed\n");
|
2017-03-09 14:23:00 +00:00
|
|
|
goto out;
|
2016-08-02 16:34:45 +00:00
|
|
|
}
|
|
|
|
|
2020-07-21 12:53:06 +00:00
|
|
|
pg = iscsi_portal_grp_create(req.tag, req.is_private);
|
2018-01-29 04:36:03 +00:00
|
|
|
if (pg == NULL) {
|
|
|
|
SPDK_ERRLOG("portal_grp_create failed\n");
|
|
|
|
goto out;
|
|
|
|
}
|
2016-08-02 16:34:45 +00:00
|
|
|
for (i = 0; i < req.portal_list.num_portals; i++) {
|
2020-04-15 21:54:21 +00:00
|
|
|
portal = iscsi_portal_create(req.portal_list.portals[i].host,
|
|
|
|
req.portal_list.portals[i].port);
|
2018-01-29 04:36:03 +00:00
|
|
|
if (portal == NULL) {
|
|
|
|
SPDK_ERRLOG("portal_create failed\n");
|
2017-03-09 14:23:00 +00:00
|
|
|
goto out;
|
2016-08-02 16:34:45 +00:00
|
|
|
}
|
2020-04-15 21:54:21 +00:00
|
|
|
iscsi_portal_grp_add_portal(pg, portal);
|
2016-08-02 16:34:45 +00:00
|
|
|
}
|
|
|
|
|
2020-11-12 04:42:35 +00:00
|
|
|
rc = iscsi_portal_grp_open(pg, req.wait);
|
2018-01-29 04:36:03 +00:00
|
|
|
if (rc != 0) {
|
|
|
|
SPDK_ERRLOG("portal_grp_open failed\n");
|
|
|
|
goto out;
|
|
|
|
}
|
2017-03-09 14:23:00 +00:00
|
|
|
|
2020-04-15 21:54:21 +00:00
|
|
|
rc = iscsi_portal_grp_register(pg);
|
2018-01-29 04:36:03 +00:00
|
|
|
if (rc != 0) {
|
|
|
|
SPDK_ERRLOG("portal_grp_register failed\n");
|
2016-08-02 16:34:45 +00:00
|
|
|
}
|
|
|
|
|
2017-03-09 14:23:00 +00:00
|
|
|
out:
|
2017-03-28 16:21:35 +00:00
|
|
|
if (rc == 0) {
|
2020-11-06 16:58:30 +00:00
|
|
|
spdk_jsonrpc_send_bool_response(request, true);
|
2017-03-09 14:23:00 +00:00
|
|
|
} else {
|
2017-06-29 20:37:39 +00:00
|
|
|
spdk_jsonrpc_send_error_response(request, SPDK_JSONRPC_ERROR_INVALID_PARAMS, "Invalid parameters");
|
2016-08-02 16:34:45 +00:00
|
|
|
|
2018-01-29 04:36:03 +00:00
|
|
|
if (pg != NULL) {
|
2020-04-15 21:54:21 +00:00
|
|
|
iscsi_portal_grp_release(pg);
|
2017-03-09 14:23:00 +00:00
|
|
|
}
|
2016-08-02 16:34:45 +00:00
|
|
|
}
|
|
|
|
free_rpc_portal_group(&req);
|
|
|
|
}
|
2020-04-16 03:15:35 +00:00
|
|
|
SPDK_RPC_REGISTER("iscsi_create_portal_group", rpc_iscsi_create_portal_group, SPDK_RPC_RUNTIME)
|
2019-09-09 10:35:30 +00:00
|
|
|
SPDK_RPC_REGISTER_ALIAS_DEPRECATED(iscsi_create_portal_group, add_portal_group)
|
2016-08-02 16:34:45 +00:00
|
|
|
|
2020-11-16 07:37:14 +00:00
|
|
|
struct rpc_iscsi_change_portal_group {
|
2016-08-02 16:34:45 +00:00
|
|
|
int32_t tag;
|
|
|
|
};
|
|
|
|
|
2020-11-16 07:37:14 +00:00
|
|
|
static const struct spdk_json_object_decoder rpc_iscsi_change_portal_group_decoders[] = {
|
|
|
|
{"tag", offsetof(struct rpc_iscsi_change_portal_group, tag), spdk_json_decode_int32},
|
2016-08-02 16:34:45 +00:00
|
|
|
};
|
|
|
|
|
2020-11-16 07:37:14 +00:00
|
|
|
typedef int (*iscsi_change_portal_grp_fn)(int pg_tag);
|
|
|
|
|
2016-08-02 16:34:45 +00:00
|
|
|
static void
|
2020-11-16 07:37:14 +00:00
|
|
|
_rpc_iscsi_change_portal_group(struct spdk_jsonrpc_request *request,
|
|
|
|
const struct spdk_json_val *params,
|
|
|
|
iscsi_change_portal_grp_fn fn)
|
2016-08-02 16:34:45 +00:00
|
|
|
{
|
2020-11-16 07:37:14 +00:00
|
|
|
struct rpc_iscsi_change_portal_group req = {};
|
|
|
|
int rc;
|
2016-08-02 16:34:45 +00:00
|
|
|
|
2020-11-16 07:37:14 +00:00
|
|
|
if (spdk_json_decode_object(params, rpc_iscsi_change_portal_group_decoders,
|
|
|
|
SPDK_COUNTOF(rpc_iscsi_change_portal_group_decoders),
|
2016-08-02 16:34:45 +00:00
|
|
|
&req)) {
|
2016-11-17 06:33:54 +00:00
|
|
|
SPDK_ERRLOG("spdk_json_decode_object failed\n");
|
2016-08-02 16:34:45 +00:00
|
|
|
goto invalid;
|
|
|
|
}
|
|
|
|
|
2020-11-16 07:37:14 +00:00
|
|
|
rc = fn(req.tag);
|
|
|
|
if (rc != 0) {
|
2016-08-02 16:34:45 +00:00
|
|
|
goto invalid;
|
|
|
|
}
|
|
|
|
|
2020-11-06 16:58:30 +00:00
|
|
|
spdk_jsonrpc_send_bool_response(request, true);
|
2016-08-02 16:34:45 +00:00
|
|
|
return;
|
|
|
|
|
|
|
|
invalid:
|
2017-06-29 20:37:39 +00:00
|
|
|
spdk_jsonrpc_send_error_response(request, SPDK_JSONRPC_ERROR_INVALID_PARAMS, "Invalid parameters");
|
2016-08-02 16:34:45 +00:00
|
|
|
}
|
2020-11-16 07:37:14 +00:00
|
|
|
|
|
|
|
static int
|
|
|
|
_rpc_iscsi_delete_portal_group(int pg_tag)
|
|
|
|
{
|
|
|
|
struct spdk_iscsi_portal_grp *pg;
|
|
|
|
|
|
|
|
pg = iscsi_portal_grp_unregister(pg_tag);
|
|
|
|
if (!pg) {
|
|
|
|
return -ENODEV;
|
|
|
|
}
|
|
|
|
|
|
|
|
iscsi_tgt_node_delete_map(pg, NULL);
|
|
|
|
iscsi_portal_grp_release(pg);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
rpc_iscsi_delete_portal_group(struct spdk_jsonrpc_request *request,
|
|
|
|
const struct spdk_json_val *params)
|
|
|
|
{
|
|
|
|
_rpc_iscsi_change_portal_group(request, params, _rpc_iscsi_delete_portal_group);
|
|
|
|
}
|
2020-04-16 03:15:35 +00:00
|
|
|
SPDK_RPC_REGISTER("iscsi_delete_portal_group", rpc_iscsi_delete_portal_group, SPDK_RPC_RUNTIME)
|
2019-09-09 10:51:22 +00:00
|
|
|
SPDK_RPC_REGISTER_ALIAS_DEPRECATED(iscsi_delete_portal_group, delete_portal_group)
|
2016-08-02 16:34:45 +00:00
|
|
|
|
2020-11-12 04:19:51 +00:00
|
|
|
static int
|
|
|
|
_rpc_iscsi_start_portal_group(int pg_tag)
|
|
|
|
{
|
|
|
|
struct spdk_iscsi_portal_grp *pg;
|
|
|
|
|
|
|
|
pg = iscsi_portal_grp_find_by_tag(pg_tag);
|
|
|
|
if (!pg) {
|
|
|
|
return -ENODEV;
|
|
|
|
}
|
|
|
|
|
|
|
|
iscsi_portal_grp_resume(pg);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
rpc_iscsi_start_portal_group(struct spdk_jsonrpc_request *request,
|
|
|
|
const struct spdk_json_val *params)
|
|
|
|
{
|
|
|
|
_rpc_iscsi_change_portal_group(request, params, _rpc_iscsi_start_portal_group);
|
|
|
|
}
|
|
|
|
SPDK_RPC_REGISTER("iscsi_start_portal_group", rpc_iscsi_start_portal_group, SPDK_RPC_RUNTIME)
|
|
|
|
|
2019-09-25 06:42:29 +00:00
|
|
|
struct rpc_portal_group_auth {
|
|
|
|
int32_t tag;
|
|
|
|
bool disable_chap;
|
|
|
|
bool require_chap;
|
|
|
|
bool mutual_chap;
|
|
|
|
int32_t chap_group;
|
|
|
|
};
|
|
|
|
|
|
|
|
static const struct spdk_json_object_decoder rpc_portal_group_auth_decoders[] = {
|
|
|
|
{"tag", offsetof(struct rpc_portal_group_auth, tag), spdk_json_decode_int32},
|
|
|
|
{"disable_chap", offsetof(struct rpc_portal_group_auth, disable_chap), spdk_json_decode_bool, true},
|
|
|
|
{"require_chap", offsetof(struct rpc_portal_group_auth, require_chap), spdk_json_decode_bool, true},
|
|
|
|
{"mutual_chap", offsetof(struct rpc_portal_group_auth, mutual_chap), spdk_json_decode_bool, true},
|
|
|
|
{"chap_group", offsetof(struct rpc_portal_group_auth, chap_group), spdk_json_decode_int32, true},
|
|
|
|
};
|
|
|
|
|
|
|
|
static void
|
2020-04-16 03:15:35 +00:00
|
|
|
rpc_iscsi_portal_group_set_auth(struct spdk_jsonrpc_request *request,
|
|
|
|
const struct spdk_json_val *params)
|
2019-09-25 06:42:29 +00:00
|
|
|
{
|
|
|
|
struct rpc_portal_group_auth req = {};
|
|
|
|
struct spdk_iscsi_portal_grp *pg;
|
|
|
|
int rc;
|
|
|
|
|
|
|
|
if (spdk_json_decode_object(params, rpc_portal_group_auth_decoders,
|
|
|
|
SPDK_COUNTOF(rpc_portal_group_auth_decoders), &req)) {
|
|
|
|
SPDK_ERRLOG("spdk_json_decode_object failed\n");
|
|
|
|
spdk_jsonrpc_send_error_response(request, SPDK_JSONRPC_ERROR_INVALID_PARAMS,
|
|
|
|
"Invalid parameters");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2020-04-13 21:05:20 +00:00
|
|
|
pthread_mutex_lock(&g_iscsi.mutex);
|
2019-09-25 06:42:29 +00:00
|
|
|
|
2020-04-15 21:54:21 +00:00
|
|
|
pg = iscsi_portal_grp_find_by_tag(req.tag);
|
2019-09-25 06:42:29 +00:00
|
|
|
if (pg == NULL) {
|
|
|
|
spdk_jsonrpc_send_error_response_fmt(request, SPDK_JSONRPC_ERROR_INVALID_PARAMS,
|
|
|
|
"Could not find portal group %d", req.tag);
|
|
|
|
goto exit;
|
|
|
|
}
|
|
|
|
|
2020-04-15 21:54:21 +00:00
|
|
|
rc = iscsi_portal_grp_set_chap_params(pg, req.disable_chap, req.require_chap,
|
|
|
|
req.mutual_chap, req.chap_group);
|
2019-09-25 06:42:29 +00:00
|
|
|
if (rc < 0) {
|
|
|
|
spdk_jsonrpc_send_error_response(request, SPDK_JSONRPC_ERROR_INVALID_PARAMS,
|
|
|
|
"Invalid combination of auth params");
|
|
|
|
goto exit;
|
|
|
|
}
|
|
|
|
|
2020-04-13 21:05:20 +00:00
|
|
|
pthread_mutex_unlock(&g_iscsi.mutex);
|
2019-09-25 06:42:29 +00:00
|
|
|
|
2020-11-06 16:58:30 +00:00
|
|
|
spdk_jsonrpc_send_bool_response(request, true);
|
2019-09-25 06:42:29 +00:00
|
|
|
return;
|
|
|
|
|
|
|
|
exit:
|
2020-04-13 21:05:20 +00:00
|
|
|
pthread_mutex_unlock(&g_iscsi.mutex);
|
2019-09-25 06:42:29 +00:00
|
|
|
}
|
2020-04-16 03:15:35 +00:00
|
|
|
SPDK_RPC_REGISTER("iscsi_portal_group_set_auth", rpc_iscsi_portal_group_set_auth,
|
2019-09-25 06:42:29 +00:00
|
|
|
SPDK_RPC_RUNTIME)
|
|
|
|
|
2019-09-10 09:32:18 +00:00
|
|
|
struct rpc_iscsi_get_connections_ctx {
|
2019-07-30 05:13:34 +00:00
|
|
|
struct spdk_jsonrpc_request *request;
|
|
|
|
struct spdk_json_write_ctx *w;
|
|
|
|
};
|
|
|
|
|
|
|
|
static void
|
2020-04-16 03:15:35 +00:00
|
|
|
_rpc_iscsi_get_connections_done(struct spdk_io_channel_iter *i, int status)
|
2019-07-30 05:13:34 +00:00
|
|
|
{
|
2019-09-10 09:32:18 +00:00
|
|
|
struct rpc_iscsi_get_connections_ctx *ctx = spdk_io_channel_iter_get_ctx(i);
|
2019-07-30 05:13:34 +00:00
|
|
|
|
|
|
|
spdk_json_write_array_end(ctx->w);
|
|
|
|
spdk_jsonrpc_end_result(ctx->request, ctx->w);
|
|
|
|
|
|
|
|
free(ctx);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2020-04-16 03:15:35 +00:00
|
|
|
_rpc_iscsi_get_connections(struct spdk_io_channel_iter *i)
|
2019-07-30 05:13:34 +00:00
|
|
|
{
|
2019-09-10 09:32:18 +00:00
|
|
|
struct rpc_iscsi_get_connections_ctx *ctx = spdk_io_channel_iter_get_ctx(i);
|
2019-07-30 05:13:34 +00:00
|
|
|
struct spdk_io_channel *ch = spdk_io_channel_iter_get_channel(i);
|
|
|
|
struct spdk_iscsi_poll_group *pg = spdk_io_channel_get_ctx(ch);
|
|
|
|
struct spdk_iscsi_conn *conn;
|
|
|
|
|
2020-06-23 06:41:58 +00:00
|
|
|
STAILQ_FOREACH(conn, &pg->connections, pg_link) {
|
2020-04-15 22:28:10 +00:00
|
|
|
iscsi_conn_info_json(ctx->w, conn);
|
2019-07-30 05:13:34 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
spdk_for_each_channel_continue(i, 0);
|
|
|
|
}
|
|
|
|
|
2016-08-02 16:34:45 +00:00
|
|
|
static void
|
2020-04-16 03:15:35 +00:00
|
|
|
rpc_iscsi_get_connections(struct spdk_jsonrpc_request *request,
|
|
|
|
const struct spdk_json_val *params)
|
2016-08-02 16:34:45 +00:00
|
|
|
{
|
2019-09-10 09:32:18 +00:00
|
|
|
struct rpc_iscsi_get_connections_ctx *ctx;
|
2016-08-02 16:34:45 +00:00
|
|
|
|
|
|
|
if (params != NULL) {
|
2017-06-29 20:37:39 +00:00
|
|
|
spdk_jsonrpc_send_error_response(request, SPDK_JSONRPC_ERROR_INVALID_PARAMS,
|
2019-09-10 09:32:18 +00:00
|
|
|
"iscsi_get_connections requires no parameters");
|
2016-08-02 16:34:45 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2019-09-10 09:32:18 +00:00
|
|
|
ctx = calloc(1, sizeof(struct rpc_iscsi_get_connections_ctx));
|
2019-07-30 05:13:34 +00:00
|
|
|
if (ctx == NULL) {
|
|
|
|
SPDK_ERRLOG("Failed to allocate rpc_get_iscsi_conns_ctx struct\n");
|
|
|
|
spdk_jsonrpc_send_error_response(request, -ENOMEM, spdk_strerror(ENOMEM));
|
|
|
|
return;
|
|
|
|
}
|
2016-08-02 16:34:45 +00:00
|
|
|
|
2019-07-30 05:13:34 +00:00
|
|
|
ctx->request = request;
|
|
|
|
ctx->w = spdk_jsonrpc_begin_result(request);
|
2016-08-02 16:34:45 +00:00
|
|
|
|
2019-07-30 05:13:34 +00:00
|
|
|
spdk_json_write_array_begin(ctx->w);
|
2016-08-02 16:34:45 +00:00
|
|
|
|
2020-04-13 21:05:20 +00:00
|
|
|
spdk_for_each_channel(&g_iscsi,
|
2020-04-16 03:15:35 +00:00
|
|
|
_rpc_iscsi_get_connections,
|
2019-07-30 05:13:34 +00:00
|
|
|
ctx,
|
2020-04-16 03:15:35 +00:00
|
|
|
_rpc_iscsi_get_connections_done);
|
2016-08-02 16:34:45 +00:00
|
|
|
}
|
2020-04-16 03:15:35 +00:00
|
|
|
SPDK_RPC_REGISTER("iscsi_get_connections", rpc_iscsi_get_connections, SPDK_RPC_RUNTIME)
|
2019-09-10 09:32:18 +00:00
|
|
|
SPDK_RPC_REGISTER_ALIAS_DEPRECATED(iscsi_get_connections, get_iscsi_connections)
|
2017-12-12 23:59:54 +00:00
|
|
|
|
2018-01-12 00:45:36 +00:00
|
|
|
struct rpc_target_lun {
|
|
|
|
char *name;
|
|
|
|
char *bdev_name;
|
|
|
|
int32_t lun_id;
|
|
|
|
};
|
|
|
|
|
|
|
|
static void
|
|
|
|
free_rpc_target_lun(struct rpc_target_lun *req)
|
|
|
|
{
|
|
|
|
free(req->name);
|
|
|
|
free(req->bdev_name);
|
|
|
|
}
|
|
|
|
|
|
|
|
static const struct spdk_json_object_decoder rpc_target_lun_decoders[] = {
|
|
|
|
{"name", offsetof(struct rpc_target_lun, name), spdk_json_decode_string},
|
|
|
|
{"bdev_name", offsetof(struct rpc_target_lun, bdev_name), spdk_json_decode_string},
|
|
|
|
{"lun_id", offsetof(struct rpc_target_lun, lun_id), spdk_json_decode_int32, true},
|
|
|
|
};
|
|
|
|
|
|
|
|
static void
|
2020-04-16 03:15:35 +00:00
|
|
|
rpc_iscsi_target_node_add_lun(struct spdk_jsonrpc_request *request,
|
|
|
|
const struct spdk_json_val *params)
|
2018-01-12 00:45:36 +00:00
|
|
|
{
|
|
|
|
struct rpc_target_lun req = {};
|
|
|
|
struct spdk_iscsi_tgt_node *target;
|
|
|
|
int rc;
|
|
|
|
|
|
|
|
req.lun_id = -1;
|
|
|
|
|
|
|
|
if (spdk_json_decode_object(params, rpc_target_lun_decoders,
|
|
|
|
SPDK_COUNTOF(rpc_target_lun_decoders), &req)) {
|
|
|
|
SPDK_ERRLOG("spdk_json_decode_object failed\n");
|
|
|
|
goto invalid;
|
|
|
|
}
|
|
|
|
|
2020-04-15 21:04:36 +00:00
|
|
|
target = iscsi_find_tgt_node(req.name);
|
2018-01-12 00:45:36 +00:00
|
|
|
if (target == NULL) {
|
|
|
|
SPDK_ERRLOG("target is not found\n");
|
|
|
|
goto invalid;
|
|
|
|
}
|
|
|
|
|
2020-04-15 21:04:36 +00:00
|
|
|
rc = iscsi_tgt_node_add_lun(target, req.bdev_name, req.lun_id);
|
2018-01-12 00:45:36 +00:00
|
|
|
if (rc < 0) {
|
|
|
|
SPDK_ERRLOG("add lun failed\n");
|
|
|
|
goto invalid;
|
|
|
|
}
|
|
|
|
|
|
|
|
free_rpc_target_lun(&req);
|
|
|
|
|
2020-11-06 16:58:30 +00:00
|
|
|
spdk_jsonrpc_send_bool_response(request, true);
|
2018-01-12 00:45:36 +00:00
|
|
|
return;
|
|
|
|
|
|
|
|
invalid:
|
|
|
|
spdk_jsonrpc_send_error_response(request, SPDK_JSONRPC_ERROR_INVALID_PARAMS,
|
|
|
|
"Invalid parameters");
|
|
|
|
free_rpc_target_lun(&req);
|
|
|
|
}
|
2020-04-16 03:15:35 +00:00
|
|
|
SPDK_RPC_REGISTER("iscsi_target_node_add_lun", rpc_iscsi_target_node_add_lun, SPDK_RPC_RUNTIME)
|
2019-09-10 11:06:57 +00:00
|
|
|
SPDK_RPC_REGISTER_ALIAS_DEPRECATED(iscsi_target_node_add_lun, target_node_add_lun)
|
2018-01-12 00:45:36 +00:00
|
|
|
|
2018-08-20 00:12:59 +00:00
|
|
|
struct rpc_target_auth {
|
|
|
|
char *name;
|
|
|
|
bool disable_chap;
|
|
|
|
bool require_chap;
|
|
|
|
bool mutual_chap;
|
|
|
|
int32_t chap_group;
|
|
|
|
};
|
|
|
|
|
|
|
|
static void
|
|
|
|
free_rpc_target_auth(struct rpc_target_auth *req)
|
|
|
|
{
|
|
|
|
free(req->name);
|
|
|
|
}
|
|
|
|
|
|
|
|
static const struct spdk_json_object_decoder rpc_target_auth_decoders[] = {
|
|
|
|
{"name", offsetof(struct rpc_target_auth, name), spdk_json_decode_string},
|
|
|
|
{"disable_chap", offsetof(struct rpc_target_auth, disable_chap), spdk_json_decode_bool, true},
|
|
|
|
{"require_chap", offsetof(struct rpc_target_auth, require_chap), spdk_json_decode_bool, true},
|
|
|
|
{"mutual_chap", offsetof(struct rpc_target_auth, mutual_chap), spdk_json_decode_bool, true},
|
|
|
|
{"chap_group", offsetof(struct rpc_target_auth, chap_group), spdk_json_decode_int32, true},
|
|
|
|
};
|
|
|
|
|
|
|
|
static void
|
2020-04-16 03:15:35 +00:00
|
|
|
rpc_iscsi_target_node_set_auth(struct spdk_jsonrpc_request *request,
|
|
|
|
const struct spdk_json_val *params)
|
2018-08-20 00:12:59 +00:00
|
|
|
{
|
|
|
|
struct rpc_target_auth req = {};
|
|
|
|
struct spdk_iscsi_tgt_node *target;
|
|
|
|
int rc;
|
|
|
|
|
|
|
|
if (spdk_json_decode_object(params, rpc_target_auth_decoders,
|
|
|
|
SPDK_COUNTOF(rpc_target_auth_decoders), &req)) {
|
|
|
|
SPDK_ERRLOG("spdk_json_decode_object failed\n");
|
|
|
|
spdk_jsonrpc_send_error_response(request, SPDK_JSONRPC_ERROR_INVALID_PARAMS,
|
|
|
|
"Invalid parameters");
|
2019-01-07 12:28:35 +00:00
|
|
|
goto exit;
|
2018-08-20 00:12:59 +00:00
|
|
|
}
|
|
|
|
|
2020-04-15 21:04:36 +00:00
|
|
|
target = iscsi_find_tgt_node(req.name);
|
2018-08-20 00:12:59 +00:00
|
|
|
if (target == NULL) {
|
|
|
|
spdk_jsonrpc_send_error_response_fmt(request, SPDK_JSONRPC_ERROR_INVALID_PARAMS,
|
|
|
|
"Could not find target %s", req.name);
|
2019-01-07 12:28:35 +00:00
|
|
|
goto exit;
|
2018-08-20 00:12:59 +00:00
|
|
|
}
|
|
|
|
|
2020-04-15 21:04:36 +00:00
|
|
|
rc = iscsi_tgt_node_set_chap_params(target, req.disable_chap, req.require_chap,
|
|
|
|
req.mutual_chap, req.chap_group);
|
2018-08-20 00:12:59 +00:00
|
|
|
if (rc < 0) {
|
|
|
|
spdk_jsonrpc_send_error_response(request, SPDK_JSONRPC_ERROR_INVALID_PARAMS,
|
2018-08-09 03:16:11 +00:00
|
|
|
"Invalid combination of auth params");
|
2019-01-07 12:28:35 +00:00
|
|
|
goto exit;
|
2018-08-20 00:12:59 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
free_rpc_target_auth(&req);
|
|
|
|
|
2020-11-06 16:58:30 +00:00
|
|
|
spdk_jsonrpc_send_bool_response(request, true);
|
2019-01-07 12:28:35 +00:00
|
|
|
return;
|
|
|
|
|
|
|
|
exit:
|
|
|
|
free_rpc_target_auth(&req);
|
2018-08-20 00:12:59 +00:00
|
|
|
}
|
2020-04-16 03:15:35 +00:00
|
|
|
SPDK_RPC_REGISTER("iscsi_target_node_set_auth", rpc_iscsi_target_node_set_auth,
|
2018-08-20 00:12:59 +00:00
|
|
|
SPDK_RPC_RUNTIME)
|
2019-09-10 11:13:46 +00:00
|
|
|
SPDK_RPC_REGISTER_ALIAS_DEPRECATED(iscsi_target_node_set_auth, set_iscsi_target_node_auth)
|
2018-08-20 00:12:59 +00:00
|
|
|
|
2020-07-17 09:33:36 +00:00
|
|
|
struct rpc_target_redirect {
|
|
|
|
char *name;
|
|
|
|
int32_t pg_tag;
|
|
|
|
char *redirect_host;
|
|
|
|
char *redirect_port;
|
|
|
|
};
|
|
|
|
|
|
|
|
static void
|
|
|
|
free_rpc_target_redirect(struct rpc_target_redirect *req)
|
|
|
|
{
|
|
|
|
free(req->name);
|
|
|
|
free(req->redirect_host);
|
|
|
|
free(req->redirect_port);
|
|
|
|
}
|
|
|
|
|
|
|
|
static const struct spdk_json_object_decoder rpc_target_redirect_decoders[] = {
|
|
|
|
{"name", offsetof(struct rpc_target_redirect, name), spdk_json_decode_string},
|
|
|
|
{"pg_tag", offsetof(struct rpc_target_redirect, pg_tag), spdk_json_decode_int32},
|
|
|
|
{"redirect_host", offsetof(struct rpc_target_redirect, redirect_host), spdk_json_decode_string, true},
|
|
|
|
{"redirect_port", offsetof(struct rpc_target_redirect, redirect_port), spdk_json_decode_string, true},
|
|
|
|
};
|
|
|
|
|
|
|
|
static void
|
|
|
|
rpc_iscsi_target_node_set_redirect(struct spdk_jsonrpc_request *request,
|
|
|
|
const struct spdk_json_val *params)
|
|
|
|
{
|
|
|
|
struct rpc_target_redirect req = {};
|
|
|
|
struct spdk_iscsi_tgt_node *target;
|
|
|
|
int rc;
|
|
|
|
|
|
|
|
if (spdk_json_decode_object(params, rpc_target_redirect_decoders,
|
|
|
|
SPDK_COUNTOF(rpc_target_redirect_decoders),
|
|
|
|
&req)) {
|
|
|
|
SPDK_ERRLOG("spdk_json_decode_object failed\n");
|
|
|
|
spdk_jsonrpc_send_error_response(request, SPDK_JSONRPC_ERROR_INVALID_PARAMS,
|
|
|
|
"Invalid parameters");
|
|
|
|
free_rpc_target_redirect(&req);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
target = iscsi_find_tgt_node(req.name);
|
|
|
|
if (target == NULL) {
|
|
|
|
SPDK_ERRLOG("target %s is not found\n", req.name);
|
|
|
|
spdk_jsonrpc_send_error_response_fmt(request, SPDK_JSONRPC_ERROR_INVALID_PARAMS,
|
|
|
|
"Target %s is not found", req.name);
|
|
|
|
free_rpc_target_redirect(&req);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
rc = iscsi_tgt_node_redirect(target, req.pg_tag, req.redirect_host, req.redirect_port);
|
|
|
|
if (rc != 0) {
|
|
|
|
SPDK_ERRLOG("failed to redirect target %s\n", req.name);
|
|
|
|
spdk_jsonrpc_send_error_response_fmt(request, SPDK_JSONRPC_ERROR_INVALID_PARAMS,
|
|
|
|
"Failed to redirect target %s, (%d): %s",
|
|
|
|
req.name, rc, spdk_strerror(-rc));
|
|
|
|
free_rpc_target_redirect(&req);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
free_rpc_target_redirect(&req);
|
|
|
|
|
2020-11-06 16:58:30 +00:00
|
|
|
spdk_jsonrpc_send_bool_response(request, true);
|
2020-07-17 09:33:36 +00:00
|
|
|
}
|
|
|
|
SPDK_RPC_REGISTER("iscsi_target_node_set_redirect", rpc_iscsi_target_node_set_redirect,
|
|
|
|
SPDK_RPC_RUNTIME)
|
|
|
|
|
2020-08-14 03:14:27 +00:00
|
|
|
struct rpc_target_logout {
|
|
|
|
char *name;
|
|
|
|
int32_t pg_tag;
|
|
|
|
};
|
|
|
|
|
|
|
|
static void
|
|
|
|
free_rpc_target_logout(struct rpc_target_logout *req)
|
|
|
|
{
|
|
|
|
free(req->name);
|
|
|
|
}
|
|
|
|
|
|
|
|
static const struct spdk_json_object_decoder rpc_target_logout_decoders[] = {
|
|
|
|
{"name", offsetof(struct rpc_target_logout, name), spdk_json_decode_string},
|
|
|
|
{"pg_tag", offsetof(struct rpc_target_logout, pg_tag), spdk_json_decode_int32, true},
|
|
|
|
};
|
|
|
|
|
|
|
|
static void
|
|
|
|
rpc_iscsi_target_node_request_logout(struct spdk_jsonrpc_request *request,
|
|
|
|
const struct spdk_json_val *params)
|
|
|
|
{
|
|
|
|
struct rpc_target_logout req = {};
|
|
|
|
struct spdk_iscsi_tgt_node *target;
|
|
|
|
|
|
|
|
/* If pg_tag is omitted, request all connections to the specified target
|
|
|
|
* to logout.
|
|
|
|
*/
|
|
|
|
req.pg_tag = -1;
|
|
|
|
|
|
|
|
if (spdk_json_decode_object(params, rpc_target_logout_decoders,
|
|
|
|
SPDK_COUNTOF(rpc_target_logout_decoders),
|
|
|
|
&req)) {
|
|
|
|
SPDK_ERRLOG("spdk_json_decode_object failed\n");
|
|
|
|
spdk_jsonrpc_send_error_response(request, SPDK_JSONRPC_ERROR_INVALID_PARAMS,
|
|
|
|
"Invalid parameters");
|
|
|
|
free_rpc_target_logout(&req);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
target = iscsi_find_tgt_node(req.name);
|
|
|
|
if (target == NULL) {
|
|
|
|
SPDK_ERRLOG("target %s is not found\n", req.name);
|
|
|
|
spdk_jsonrpc_send_error_response_fmt(request, SPDK_JSONRPC_ERROR_INVALID_PARAMS,
|
|
|
|
"Target %s is not found", req.name);
|
|
|
|
free_rpc_target_logout(&req);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
iscsi_conns_request_logout(target, req.pg_tag);
|
|
|
|
|
|
|
|
free_rpc_target_logout(&req);
|
|
|
|
|
2020-11-06 16:58:30 +00:00
|
|
|
spdk_jsonrpc_send_bool_response(request, true);
|
2020-08-14 03:14:27 +00:00
|
|
|
}
|
|
|
|
SPDK_RPC_REGISTER("iscsi_target_node_request_logout", rpc_iscsi_target_node_request_logout,
|
|
|
|
SPDK_RPC_RUNTIME)
|
|
|
|
|
2017-12-12 23:59:54 +00:00
|
|
|
static void
|
2020-04-16 03:15:35 +00:00
|
|
|
rpc_iscsi_get_options(struct spdk_jsonrpc_request *request,
|
|
|
|
const struct spdk_json_val *params)
|
2017-12-12 23:59:54 +00:00
|
|
|
{
|
|
|
|
struct spdk_json_write_ctx *w;
|
|
|
|
|
|
|
|
if (params != NULL) {
|
|
|
|
spdk_jsonrpc_send_error_response(request, SPDK_JSONRPC_ERROR_INVALID_PARAMS,
|
2019-09-11 11:39:42 +00:00
|
|
|
"iscsi_get_options requires no parameters");
|
2017-12-12 23:59:54 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
w = spdk_jsonrpc_begin_result(request);
|
2020-04-16 02:18:51 +00:00
|
|
|
iscsi_opts_info_json(w);
|
2017-12-12 23:59:54 +00:00
|
|
|
|
|
|
|
spdk_jsonrpc_end_result(request, w);
|
|
|
|
}
|
2020-04-16 03:15:35 +00:00
|
|
|
SPDK_RPC_REGISTER("iscsi_get_options", rpc_iscsi_get_options, SPDK_RPC_RUNTIME)
|
2019-09-11 11:39:42 +00:00
|
|
|
SPDK_RPC_REGISTER_ALIAS_DEPRECATED(iscsi_get_options, get_iscsi_global_params)
|
2018-08-22 04:43:18 +00:00
|
|
|
|
|
|
|
struct rpc_discovery_auth {
|
|
|
|
bool disable_chap;
|
|
|
|
bool require_chap;
|
|
|
|
bool mutual_chap;
|
|
|
|
int32_t chap_group;
|
|
|
|
};
|
|
|
|
|
|
|
|
static const struct spdk_json_object_decoder rpc_discovery_auth_decoders[] = {
|
|
|
|
{"disable_chap", offsetof(struct rpc_discovery_auth, disable_chap), spdk_json_decode_bool, true},
|
|
|
|
{"require_chap", offsetof(struct rpc_discovery_auth, require_chap), spdk_json_decode_bool, true},
|
|
|
|
{"mutual_chap", offsetof(struct rpc_discovery_auth, mutual_chap), spdk_json_decode_bool, true},
|
|
|
|
{"chap_group", offsetof(struct rpc_discovery_auth, chap_group), spdk_json_decode_int32, true},
|
|
|
|
};
|
|
|
|
|
|
|
|
static void
|
2020-04-16 03:15:35 +00:00
|
|
|
rpc_iscsi_set_discovery_auth(struct spdk_jsonrpc_request *request,
|
|
|
|
const struct spdk_json_val *params)
|
2018-08-22 04:43:18 +00:00
|
|
|
{
|
|
|
|
struct rpc_discovery_auth req = {};
|
|
|
|
int rc;
|
|
|
|
|
|
|
|
if (spdk_json_decode_object(params, rpc_discovery_auth_decoders,
|
|
|
|
SPDK_COUNTOF(rpc_discovery_auth_decoders), &req)) {
|
|
|
|
SPDK_ERRLOG("spdk_json_decode_object failed\n");
|
|
|
|
spdk_jsonrpc_send_error_response(request, SPDK_JSONRPC_ERROR_INVALID_PARAMS,
|
|
|
|
"Invalid parameters");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2020-04-16 02:18:51 +00:00
|
|
|
rc = iscsi_set_discovery_auth(req.disable_chap, req.require_chap,
|
|
|
|
req.mutual_chap, req.chap_group);
|
2018-08-22 04:43:18 +00:00
|
|
|
if (rc < 0) {
|
|
|
|
spdk_jsonrpc_send_error_response(request, SPDK_JSONRPC_ERROR_INVALID_PARAMS,
|
|
|
|
"Invalid combination of CHAP params");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2020-11-06 16:58:30 +00:00
|
|
|
spdk_jsonrpc_send_bool_response(request, true);
|
2018-08-22 04:43:18 +00:00
|
|
|
}
|
2020-04-16 03:15:35 +00:00
|
|
|
SPDK_RPC_REGISTER("iscsi_set_discovery_auth", rpc_iscsi_set_discovery_auth, SPDK_RPC_RUNTIME)
|
2019-09-13 13:10:13 +00:00
|
|
|
SPDK_RPC_REGISTER_ALIAS_DEPRECATED(iscsi_set_discovery_auth, set_iscsi_discovery_auth)
|
2018-08-09 03:16:11 +00:00
|
|
|
|
|
|
|
#define MAX_AUTH_SECRETS 64
|
|
|
|
|
|
|
|
struct rpc_auth_secret {
|
|
|
|
char *user;
|
|
|
|
char *secret;
|
|
|
|
char *muser;
|
|
|
|
char *msecret;
|
|
|
|
};
|
|
|
|
|
|
|
|
static void
|
|
|
|
free_rpc_auth_secret(struct rpc_auth_secret *_secret)
|
|
|
|
{
|
|
|
|
free(_secret->user);
|
|
|
|
free(_secret->secret);
|
|
|
|
free(_secret->muser);
|
|
|
|
free(_secret->msecret);
|
|
|
|
}
|
|
|
|
|
|
|
|
static const struct spdk_json_object_decoder rpc_auth_secret_decoders[] = {
|
|
|
|
{"user", offsetof(struct rpc_auth_secret, user), spdk_json_decode_string},
|
|
|
|
{"secret", offsetof(struct rpc_auth_secret, secret), spdk_json_decode_string},
|
|
|
|
{"muser", offsetof(struct rpc_auth_secret, muser), spdk_json_decode_string, true},
|
|
|
|
{"msecret", offsetof(struct rpc_auth_secret, msecret), spdk_json_decode_string, true},
|
|
|
|
};
|
|
|
|
|
|
|
|
static int
|
|
|
|
decode_rpc_auth_secret(const struct spdk_json_val *val, void *out)
|
|
|
|
{
|
|
|
|
struct rpc_auth_secret *_secret = out;
|
|
|
|
|
|
|
|
return spdk_json_decode_object(val, rpc_auth_secret_decoders,
|
|
|
|
SPDK_COUNTOF(rpc_auth_secret_decoders), _secret);
|
|
|
|
}
|
|
|
|
|
|
|
|
struct rpc_auth_secrets {
|
|
|
|
size_t num_secret;
|
|
|
|
struct rpc_auth_secret secrets[MAX_AUTH_SECRETS];
|
|
|
|
};
|
|
|
|
|
|
|
|
static void
|
|
|
|
free_rpc_auth_secrets(struct rpc_auth_secrets *secrets)
|
|
|
|
{
|
|
|
|
size_t i;
|
|
|
|
|
|
|
|
for (i = 0; i < secrets->num_secret; i++) {
|
|
|
|
free_rpc_auth_secret(&secrets->secrets[i]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
decode_rpc_auth_secrets(const struct spdk_json_val *val, void *out)
|
|
|
|
{
|
|
|
|
struct rpc_auth_secrets *secrets = out;
|
|
|
|
|
|
|
|
return spdk_json_decode_array(val, decode_rpc_auth_secret, secrets->secrets,
|
|
|
|
MAX_AUTH_SECRETS, &secrets->num_secret,
|
|
|
|
sizeof(struct rpc_auth_secret));
|
|
|
|
}
|
|
|
|
|
|
|
|
struct rpc_auth_group {
|
|
|
|
int32_t tag;
|
|
|
|
struct rpc_auth_secrets secrets;
|
|
|
|
};
|
|
|
|
|
|
|
|
static void
|
|
|
|
free_rpc_auth_group(struct rpc_auth_group *group)
|
|
|
|
{
|
|
|
|
free_rpc_auth_secrets(&group->secrets);
|
|
|
|
}
|
|
|
|
|
|
|
|
static const struct spdk_json_object_decoder rpc_auth_group_decoders[] = {
|
|
|
|
{"tag", offsetof(struct rpc_auth_group, tag), spdk_json_decode_int32},
|
|
|
|
{"secrets", offsetof(struct rpc_auth_group, secrets), decode_rpc_auth_secrets, true},
|
|
|
|
};
|
|
|
|
|
|
|
|
static void
|
2020-04-16 03:15:35 +00:00
|
|
|
rpc_iscsi_create_auth_group(struct spdk_jsonrpc_request *request,
|
|
|
|
const struct spdk_json_val *params)
|
2018-08-09 03:16:11 +00:00
|
|
|
{
|
|
|
|
struct rpc_auth_group req = {};
|
|
|
|
struct rpc_auth_secret *_secret;
|
|
|
|
struct spdk_iscsi_auth_group *group = NULL;
|
|
|
|
int rc;
|
|
|
|
size_t i;
|
|
|
|
|
|
|
|
if (spdk_json_decode_object(params, rpc_auth_group_decoders,
|
|
|
|
SPDK_COUNTOF(rpc_auth_group_decoders), &req)) {
|
|
|
|
SPDK_ERRLOG("spdk_json_decode_object failed\n");
|
|
|
|
spdk_jsonrpc_send_error_response(request, SPDK_JSONRPC_ERROR_INVALID_PARAMS,
|
|
|
|
"Invalid parameters");
|
|
|
|
free_rpc_auth_group(&req);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2020-04-13 21:05:20 +00:00
|
|
|
pthread_mutex_lock(&g_iscsi.mutex);
|
2018-08-09 03:16:11 +00:00
|
|
|
|
2020-04-16 02:18:51 +00:00
|
|
|
rc = iscsi_add_auth_group(req.tag, &group);
|
2018-08-09 03:16:11 +00:00
|
|
|
if (rc != 0) {
|
2020-04-13 21:05:20 +00:00
|
|
|
pthread_mutex_unlock(&g_iscsi.mutex);
|
2018-08-09 03:16:11 +00:00
|
|
|
|
|
|
|
spdk_jsonrpc_send_error_response_fmt(request, SPDK_JSONRPC_ERROR_INVALID_PARAMS,
|
|
|
|
"Could not add auth group (%d), %s",
|
|
|
|
req.tag, spdk_strerror(-rc));
|
|
|
|
free_rpc_auth_group(&req);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
for (i = 0; i < req.secrets.num_secret; i++) {
|
|
|
|
_secret = &req.secrets.secrets[i];
|
2020-04-16 02:18:51 +00:00
|
|
|
rc = iscsi_auth_group_add_secret(group, _secret->user, _secret->secret,
|
|
|
|
_secret->muser, _secret->msecret);
|
2018-08-09 03:16:11 +00:00
|
|
|
if (rc != 0) {
|
2020-04-16 02:18:51 +00:00
|
|
|
iscsi_delete_auth_group(group);
|
2020-04-13 21:05:20 +00:00
|
|
|
pthread_mutex_unlock(&g_iscsi.mutex);
|
2018-08-09 03:16:11 +00:00
|
|
|
|
|
|
|
spdk_jsonrpc_send_error_response_fmt(request, SPDK_JSONRPC_ERROR_INVALID_PARAMS,
|
|
|
|
"Could not add secret to auth group (%d), %s",
|
|
|
|
req.tag, spdk_strerror(-rc));
|
|
|
|
free_rpc_auth_group(&req);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-04-13 21:05:20 +00:00
|
|
|
pthread_mutex_unlock(&g_iscsi.mutex);
|
2018-08-09 03:16:11 +00:00
|
|
|
|
|
|
|
free_rpc_auth_group(&req);
|
|
|
|
|
2020-11-06 16:58:30 +00:00
|
|
|
spdk_jsonrpc_send_bool_response(request, true);
|
2018-08-09 03:16:11 +00:00
|
|
|
}
|
2020-04-16 03:15:35 +00:00
|
|
|
SPDK_RPC_REGISTER("iscsi_create_auth_group", rpc_iscsi_create_auth_group, SPDK_RPC_RUNTIME)
|
2019-09-13 13:26:19 +00:00
|
|
|
SPDK_RPC_REGISTER_ALIAS_DEPRECATED(iscsi_create_auth_group, add_iscsi_auth_group)
|
2018-08-09 03:16:11 +00:00
|
|
|
|
|
|
|
struct rpc_delete_auth_group {
|
|
|
|
int32_t tag;
|
|
|
|
};
|
|
|
|
|
|
|
|
static const struct spdk_json_object_decoder rpc_delete_auth_group_decoders[] = {
|
|
|
|
{"tag", offsetof(struct rpc_delete_auth_group, tag), spdk_json_decode_int32},
|
|
|
|
};
|
|
|
|
|
|
|
|
static void
|
2020-04-16 03:15:35 +00:00
|
|
|
rpc_iscsi_delete_auth_group(struct spdk_jsonrpc_request *request,
|
|
|
|
const struct spdk_json_val *params)
|
2018-08-09 03:16:11 +00:00
|
|
|
{
|
|
|
|
struct rpc_delete_auth_group req = {};
|
|
|
|
struct spdk_iscsi_auth_group *group;
|
|
|
|
|
|
|
|
if (spdk_json_decode_object(params, rpc_delete_auth_group_decoders,
|
|
|
|
SPDK_COUNTOF(rpc_delete_auth_group_decoders), &req)) {
|
|
|
|
SPDK_ERRLOG("spdk_json_decode_object failed\n");
|
|
|
|
spdk_jsonrpc_send_error_response(request, SPDK_JSONRPC_ERROR_INVALID_PARAMS,
|
|
|
|
"Invalid parameters");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2020-04-13 21:05:20 +00:00
|
|
|
pthread_mutex_lock(&g_iscsi.mutex);
|
2018-08-09 03:16:11 +00:00
|
|
|
|
2020-04-16 02:18:51 +00:00
|
|
|
group = iscsi_find_auth_group_by_tag(req.tag);
|
2018-08-09 03:16:11 +00:00
|
|
|
if (group == NULL) {
|
2020-04-13 21:05:20 +00:00
|
|
|
pthread_mutex_unlock(&g_iscsi.mutex);
|
2018-08-09 03:16:11 +00:00
|
|
|
|
|
|
|
spdk_jsonrpc_send_error_response_fmt(request, SPDK_JSONRPC_ERROR_INVALID_PARAMS,
|
|
|
|
"Could not find auth group (%d)", req.tag);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2020-04-16 02:18:51 +00:00
|
|
|
iscsi_delete_auth_group(group);
|
2018-08-09 03:16:11 +00:00
|
|
|
|
2020-04-13 21:05:20 +00:00
|
|
|
pthread_mutex_unlock(&g_iscsi.mutex);
|
2018-08-09 03:16:11 +00:00
|
|
|
|
2020-11-06 16:58:30 +00:00
|
|
|
spdk_jsonrpc_send_bool_response(request, true);
|
2018-08-09 03:16:11 +00:00
|
|
|
}
|
2020-04-16 03:15:35 +00:00
|
|
|
SPDK_RPC_REGISTER("iscsi_delete_auth_group", rpc_iscsi_delete_auth_group, SPDK_RPC_RUNTIME)
|
2019-09-13 13:39:01 +00:00
|
|
|
SPDK_RPC_REGISTER_ALIAS_DEPRECATED(iscsi_delete_auth_group, delete_iscsi_auth_group)
|
2018-08-09 04:05:34 +00:00
|
|
|
|
|
|
|
struct rpc_add_auth_secret {
|
|
|
|
int32_t tag;
|
|
|
|
char *user;
|
|
|
|
char *secret;
|
|
|
|
char *muser;
|
|
|
|
char *msecret;
|
|
|
|
};
|
|
|
|
|
|
|
|
static void
|
|
|
|
free_rpc_add_auth_secret(struct rpc_add_auth_secret *_secret)
|
|
|
|
{
|
|
|
|
free(_secret->user);
|
|
|
|
free(_secret->secret);
|
|
|
|
free(_secret->muser);
|
|
|
|
free(_secret->msecret);
|
|
|
|
}
|
|
|
|
|
|
|
|
static const struct spdk_json_object_decoder rpc_add_auth_secret_decoders[] = {
|
|
|
|
{"tag", offsetof(struct rpc_add_auth_secret, tag), spdk_json_decode_int32},
|
|
|
|
{"user", offsetof(struct rpc_add_auth_secret, user), spdk_json_decode_string},
|
|
|
|
{"secret", offsetof(struct rpc_add_auth_secret, secret), spdk_json_decode_string},
|
|
|
|
{"muser", offsetof(struct rpc_add_auth_secret, muser), spdk_json_decode_string, true},
|
|
|
|
{"msecret", offsetof(struct rpc_add_auth_secret, msecret), spdk_json_decode_string, true},
|
|
|
|
};
|
|
|
|
|
|
|
|
static void
|
2020-04-16 03:15:35 +00:00
|
|
|
rpc_iscsi_auth_group_add_secret(struct spdk_jsonrpc_request *request,
|
|
|
|
const struct spdk_json_val *params)
|
2018-08-09 04:05:34 +00:00
|
|
|
{
|
|
|
|
struct rpc_add_auth_secret req = {};
|
|
|
|
struct spdk_iscsi_auth_group *group;
|
|
|
|
int rc;
|
|
|
|
|
|
|
|
if (spdk_json_decode_object(params, rpc_add_auth_secret_decoders,
|
|
|
|
SPDK_COUNTOF(rpc_add_auth_secret_decoders), &req)) {
|
|
|
|
SPDK_ERRLOG("spdk_json_decode_object failed\n");
|
|
|
|
spdk_jsonrpc_send_error_response(request, SPDK_JSONRPC_ERROR_INVALID_PARAMS,
|
|
|
|
"Invalid parameters");
|
|
|
|
free_rpc_add_auth_secret(&req);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2020-04-13 21:05:20 +00:00
|
|
|
pthread_mutex_lock(&g_iscsi.mutex);
|
2018-08-09 04:05:34 +00:00
|
|
|
|
2020-04-16 02:18:51 +00:00
|
|
|
group = iscsi_find_auth_group_by_tag(req.tag);
|
2018-08-09 04:05:34 +00:00
|
|
|
if (group == NULL) {
|
2020-04-13 21:05:20 +00:00
|
|
|
pthread_mutex_unlock(&g_iscsi.mutex);
|
2018-08-09 04:05:34 +00:00
|
|
|
|
|
|
|
spdk_jsonrpc_send_error_response_fmt(request, SPDK_JSONRPC_ERROR_INVALID_PARAMS,
|
|
|
|
"Could not find auth group (%d)", req.tag);
|
|
|
|
free_rpc_add_auth_secret(&req);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2020-04-16 02:18:51 +00:00
|
|
|
rc = iscsi_auth_group_add_secret(group, req.user, req.secret, req.muser, req.msecret);
|
2018-08-09 04:05:34 +00:00
|
|
|
if (rc != 0) {
|
2020-04-13 21:05:20 +00:00
|
|
|
pthread_mutex_unlock(&g_iscsi.mutex);
|
2018-08-09 04:05:34 +00:00
|
|
|
|
|
|
|
spdk_jsonrpc_send_error_response_fmt(request, SPDK_JSONRPC_ERROR_INVALID_PARAMS,
|
|
|
|
"Could not add secret to auth group (%d), %s",
|
|
|
|
req.tag, spdk_strerror(-rc));
|
|
|
|
free_rpc_add_auth_secret(&req);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2020-04-13 21:05:20 +00:00
|
|
|
pthread_mutex_unlock(&g_iscsi.mutex);
|
2018-08-09 04:05:34 +00:00
|
|
|
|
|
|
|
free_rpc_add_auth_secret(&req);
|
|
|
|
|
2020-11-06 16:58:30 +00:00
|
|
|
spdk_jsonrpc_send_bool_response(request, true);
|
2018-08-09 04:05:34 +00:00
|
|
|
}
|
2020-04-16 03:15:35 +00:00
|
|
|
SPDK_RPC_REGISTER("iscsi_auth_group_add_secret", rpc_iscsi_auth_group_add_secret,
|
2018-08-09 04:05:34 +00:00
|
|
|
SPDK_RPC_RUNTIME)
|
2019-09-16 13:15:11 +00:00
|
|
|
SPDK_RPC_REGISTER_ALIAS_DEPRECATED(iscsi_auth_group_add_secret, add_secret_to_iscsi_auth_group)
|
|
|
|
|
2018-08-09 04:05:34 +00:00
|
|
|
|
2019-09-16 13:38:55 +00:00
|
|
|
struct rpc_remove_auth_secret {
|
2018-08-09 04:05:34 +00:00
|
|
|
int32_t tag;
|
|
|
|
char *user;
|
|
|
|
};
|
|
|
|
|
|
|
|
static void
|
2019-09-16 13:38:55 +00:00
|
|
|
free_rpc_remove_auth_secret(struct rpc_remove_auth_secret *_secret)
|
2018-08-09 04:05:34 +00:00
|
|
|
{
|
|
|
|
free(_secret->user);
|
|
|
|
}
|
|
|
|
|
2019-09-16 13:38:55 +00:00
|
|
|
static const struct spdk_json_object_decoder rpc_remove_auth_secret_decoders[] = {
|
|
|
|
{"tag", offsetof(struct rpc_remove_auth_secret, tag), spdk_json_decode_int32},
|
|
|
|
{"user", offsetof(struct rpc_remove_auth_secret, user), spdk_json_decode_string},
|
2018-08-09 04:05:34 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
static void
|
2020-04-16 03:15:35 +00:00
|
|
|
rpc_iscsi_auth_group_remove_secret(struct spdk_jsonrpc_request *request,
|
|
|
|
const struct spdk_json_val *params)
|
2018-08-09 04:05:34 +00:00
|
|
|
{
|
2019-09-16 13:38:55 +00:00
|
|
|
struct rpc_remove_auth_secret req = {};
|
2018-08-09 04:05:34 +00:00
|
|
|
struct spdk_iscsi_auth_group *group;
|
|
|
|
int rc;
|
|
|
|
|
2019-09-16 13:38:55 +00:00
|
|
|
if (spdk_json_decode_object(params, rpc_remove_auth_secret_decoders,
|
|
|
|
SPDK_COUNTOF(rpc_remove_auth_secret_decoders), &req)) {
|
2018-08-09 04:05:34 +00:00
|
|
|
SPDK_ERRLOG("spdk_json_decode_object failed\n");
|
|
|
|
spdk_jsonrpc_send_error_response(request, SPDK_JSONRPC_ERROR_INVALID_PARAMS,
|
|
|
|
"Invalid parameters");
|
2019-09-16 13:38:55 +00:00
|
|
|
free_rpc_remove_auth_secret(&req);
|
2018-08-09 04:05:34 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2020-04-13 21:05:20 +00:00
|
|
|
pthread_mutex_lock(&g_iscsi.mutex);
|
2018-08-09 04:05:34 +00:00
|
|
|
|
2020-04-16 02:18:51 +00:00
|
|
|
group = iscsi_find_auth_group_by_tag(req.tag);
|
2018-08-09 04:05:34 +00:00
|
|
|
if (group == NULL) {
|
2020-04-13 21:05:20 +00:00
|
|
|
pthread_mutex_unlock(&g_iscsi.mutex);
|
2018-08-09 04:05:34 +00:00
|
|
|
|
|
|
|
spdk_jsonrpc_send_error_response_fmt(request, SPDK_JSONRPC_ERROR_INVALID_PARAMS,
|
|
|
|
"Could not find auth group (%d)", req.tag);
|
2019-09-16 13:38:55 +00:00
|
|
|
free_rpc_remove_auth_secret(&req);
|
2018-08-09 04:05:34 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2020-04-16 02:18:51 +00:00
|
|
|
rc = iscsi_auth_group_delete_secret(group, req.user);
|
2018-08-09 04:05:34 +00:00
|
|
|
if (rc != 0) {
|
2020-04-13 21:05:20 +00:00
|
|
|
pthread_mutex_unlock(&g_iscsi.mutex);
|
2018-08-09 04:05:34 +00:00
|
|
|
|
|
|
|
spdk_jsonrpc_send_error_response_fmt(request, SPDK_JSONRPC_ERROR_INVALID_PARAMS,
|
|
|
|
"Could not delete secret from CHAP group (%d), %s",
|
|
|
|
req.tag, spdk_strerror(-rc));
|
2019-09-16 13:38:55 +00:00
|
|
|
free_rpc_remove_auth_secret(&req);
|
2018-08-09 04:05:34 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2020-04-13 21:05:20 +00:00
|
|
|
pthread_mutex_unlock(&g_iscsi.mutex);
|
2018-08-09 04:05:34 +00:00
|
|
|
|
2019-09-16 13:38:55 +00:00
|
|
|
free_rpc_remove_auth_secret(&req);
|
2018-08-09 04:05:34 +00:00
|
|
|
|
2020-11-06 16:58:30 +00:00
|
|
|
spdk_jsonrpc_send_bool_response(request, true);
|
2018-08-09 04:05:34 +00:00
|
|
|
}
|
2019-09-16 13:38:55 +00:00
|
|
|
SPDK_RPC_REGISTER("iscsi_auth_group_remove_secret",
|
2020-04-16 03:15:35 +00:00
|
|
|
rpc_iscsi_auth_group_remove_secret, SPDK_RPC_RUNTIME)
|
2019-09-16 13:38:55 +00:00
|
|
|
SPDK_RPC_REGISTER_ALIAS_DEPRECATED(iscsi_auth_group_remove_secret,
|
|
|
|
delete_secret_from_iscsi_auth_group)
|
2018-08-09 05:07:15 +00:00
|
|
|
|
|
|
|
static void
|
2020-04-16 03:15:35 +00:00
|
|
|
rpc_iscsi_get_auth_groups(struct spdk_jsonrpc_request *request,
|
|
|
|
const struct spdk_json_val *params)
|
2018-08-09 05:07:15 +00:00
|
|
|
{
|
|
|
|
struct spdk_json_write_ctx *w;
|
|
|
|
|
|
|
|
if (params != NULL) {
|
|
|
|
spdk_jsonrpc_send_error_response(request, SPDK_JSONRPC_ERROR_INVALID_PARAMS,
|
2019-09-13 13:55:55 +00:00
|
|
|
"iscsi_get_auth_groups requires no parameters");
|
2018-08-09 05:07:15 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
w = spdk_jsonrpc_begin_result(request);
|
|
|
|
spdk_json_write_array_begin(w);
|
2020-04-16 02:18:51 +00:00
|
|
|
iscsi_auth_groups_info_json(w);
|
2018-08-09 05:07:15 +00:00
|
|
|
spdk_json_write_array_end(w);
|
|
|
|
|
|
|
|
spdk_jsonrpc_end_result(request, w);
|
|
|
|
}
|
2020-04-16 03:15:35 +00:00
|
|
|
SPDK_RPC_REGISTER("iscsi_get_auth_groups", rpc_iscsi_get_auth_groups, SPDK_RPC_RUNTIME)
|
2019-09-13 13:55:55 +00:00
|
|
|
SPDK_RPC_REGISTER_ALIAS_DEPRECATED(iscsi_get_auth_groups, get_iscsi_auth_groups)
|
2019-08-14 22:41:33 +00:00
|
|
|
|
|
|
|
static const struct spdk_json_object_decoder rpc_set_iscsi_opts_decoders[] = {
|
|
|
|
{"auth_file", offsetof(struct spdk_iscsi_opts, authfile), spdk_json_decode_string, true},
|
|
|
|
{"node_base", offsetof(struct spdk_iscsi_opts, nodebase), spdk_json_decode_string, true},
|
|
|
|
{"nop_timeout", offsetof(struct spdk_iscsi_opts, timeout), spdk_json_decode_int32, true},
|
|
|
|
{"nop_in_interval", offsetof(struct spdk_iscsi_opts, nopininterval), spdk_json_decode_int32, true},
|
|
|
|
{"no_discovery_auth", offsetof(struct spdk_iscsi_opts, disable_chap), spdk_json_decode_bool, true},
|
|
|
|
{"req_discovery_auth", offsetof(struct spdk_iscsi_opts, require_chap), spdk_json_decode_bool, true},
|
|
|
|
{"req_discovery_auth_mutual", offsetof(struct spdk_iscsi_opts, mutual_chap), spdk_json_decode_bool, true},
|
|
|
|
{"discovery_auth_group", offsetof(struct spdk_iscsi_opts, chap_group), spdk_json_decode_int32, true},
|
|
|
|
{"disable_chap", offsetof(struct spdk_iscsi_opts, disable_chap), spdk_json_decode_bool, true},
|
|
|
|
{"require_chap", offsetof(struct spdk_iscsi_opts, require_chap), spdk_json_decode_bool, true},
|
|
|
|
{"mutual_chap", offsetof(struct spdk_iscsi_opts, mutual_chap), spdk_json_decode_bool, true},
|
|
|
|
{"chap_group", offsetof(struct spdk_iscsi_opts, chap_group), spdk_json_decode_int32, true},
|
|
|
|
{"max_sessions", offsetof(struct spdk_iscsi_opts, MaxSessions), spdk_json_decode_uint32, true},
|
|
|
|
{"max_queue_depth", offsetof(struct spdk_iscsi_opts, MaxQueueDepth), spdk_json_decode_uint32, true},
|
|
|
|
{"max_connections_per_session", offsetof(struct spdk_iscsi_opts, MaxConnectionsPerSession), spdk_json_decode_uint32, true},
|
|
|
|
{"default_time2wait", offsetof(struct spdk_iscsi_opts, DefaultTime2Wait), spdk_json_decode_uint32, true},
|
|
|
|
{"default_time2retain", offsetof(struct spdk_iscsi_opts, DefaultTime2Retain), spdk_json_decode_uint32, true},
|
|
|
|
{"first_burst_length", offsetof(struct spdk_iscsi_opts, FirstBurstLength), spdk_json_decode_uint32, true},
|
|
|
|
{"immediate_data", offsetof(struct spdk_iscsi_opts, ImmediateData), spdk_json_decode_bool, true},
|
|
|
|
{"error_recovery_level", offsetof(struct spdk_iscsi_opts, ErrorRecoveryLevel), spdk_json_decode_uint32, true},
|
|
|
|
{"allow_duplicated_isid", offsetof(struct spdk_iscsi_opts, AllowDuplicateIsid), spdk_json_decode_bool, true},
|
2020-08-13 15:49:25 +00:00
|
|
|
{"max_large_datain_per_connection", offsetof(struct spdk_iscsi_opts, MaxLargeDataInPerConnection), spdk_json_decode_uint32, true},
|
2020-08-14 01:26:31 +00:00
|
|
|
{"max_r2t_per_connection", offsetof(struct spdk_iscsi_opts, MaxR2TPerConnection), spdk_json_decode_uint32, true},
|
2021-06-09 03:24:06 +00:00
|
|
|
{"pdu_pool_size", offsetof(struct spdk_iscsi_opts, pdu_pool_size), spdk_json_decode_uint32, true},
|
|
|
|
{"immediate_data_pool_size", offsetof(struct spdk_iscsi_opts, immediate_data_pool_size), spdk_json_decode_uint32, true},
|
|
|
|
{"data_out_pool_size", offsetof(struct spdk_iscsi_opts, data_out_pool_size), spdk_json_decode_uint32, true},
|
2019-08-14 22:41:33 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
static void
|
2020-04-16 03:15:35 +00:00
|
|
|
rpc_iscsi_set_options(struct spdk_jsonrpc_request *request,
|
|
|
|
const struct spdk_json_val *params)
|
2019-08-14 22:41:33 +00:00
|
|
|
{
|
|
|
|
struct spdk_iscsi_opts *opts;
|
|
|
|
|
|
|
|
if (g_spdk_iscsi_opts != NULL) {
|
|
|
|
SPDK_ERRLOG("this RPC must not be called more than once.\n");
|
|
|
|
spdk_jsonrpc_send_error_response(request, SPDK_JSONRPC_ERROR_INTERNAL_ERROR,
|
|
|
|
"Must not call more than once");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2020-04-16 02:18:51 +00:00
|
|
|
opts = iscsi_opts_alloc();
|
2019-08-14 22:41:33 +00:00
|
|
|
if (opts == NULL) {
|
2020-04-16 02:18:51 +00:00
|
|
|
SPDK_ERRLOG("iscsi_opts_alloc() failed.\n");
|
2019-08-14 22:41:33 +00:00
|
|
|
spdk_jsonrpc_send_error_response(request, SPDK_JSONRPC_ERROR_INTERNAL_ERROR,
|
|
|
|
"Out of memory");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (params != NULL) {
|
|
|
|
if (spdk_json_decode_object(params, rpc_set_iscsi_opts_decoders,
|
|
|
|
SPDK_COUNTOF(rpc_set_iscsi_opts_decoders), opts)) {
|
|
|
|
SPDK_ERRLOG("spdk_json_decode_object() failed\n");
|
|
|
|
spdk_jsonrpc_send_error_response(request, SPDK_JSONRPC_ERROR_INVALID_PARAMS,
|
|
|
|
"Invalid parameters");
|
2020-04-16 02:18:51 +00:00
|
|
|
iscsi_opts_free(opts);
|
2019-08-14 22:41:33 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-04-16 02:18:51 +00:00
|
|
|
g_spdk_iscsi_opts = iscsi_opts_copy(opts);
|
|
|
|
iscsi_opts_free(opts);
|
2019-08-14 22:41:33 +00:00
|
|
|
|
|
|
|
if (g_spdk_iscsi_opts == NULL) {
|
2020-04-16 02:18:51 +00:00
|
|
|
SPDK_ERRLOG("iscsi_opts_copy() failed\n");
|
2019-08-14 22:41:33 +00:00
|
|
|
spdk_jsonrpc_send_error_response(request, SPDK_JSONRPC_ERROR_INTERNAL_ERROR,
|
|
|
|
"Out of memory");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2020-11-06 16:58:30 +00:00
|
|
|
spdk_jsonrpc_send_bool_response(request, true);
|
2019-08-14 22:41:33 +00:00
|
|
|
}
|
2020-04-16 03:15:35 +00:00
|
|
|
SPDK_RPC_REGISTER("iscsi_set_options", rpc_iscsi_set_options, SPDK_RPC_STARTUP)
|
2019-09-11 11:15:34 +00:00
|
|
|
SPDK_RPC_REGISTER_ALIAS_DEPRECATED(iscsi_set_options, set_iscsi_options)
|