rpc/iscsi: Adding an LUN to an existing target
Add JSON-RPC to add an LUN to an existing target. The parameter lun_id is optinal and if skipped, the lowest free LUN ID will be assigned. This JSON-RPC is tested in iscsi_tgt/rpc_config. Change-Id: I010619f2d4ccec89c589bb0618466b4d15949ebb Signed-off-by: Shuhei Matsumoto <shuhei.matsumoto.xt@hitachi.com> Reviewed-on: https://review.gerrithub.io/385181 Tested-by: SPDK Automated Test System <sys_sgsw@intel.com> Reviewed-by: Jim Harris <james.r.harris@intel.com> Reviewed-by: Ben Walker <benjamin.walker@intel.com>
This commit is contained in:
parent
3b3c6002c9
commit
f04569140c
@ -976,6 +976,72 @@ spdk_rpc_get_iscsi_connections(struct spdk_jsonrpc_request *request,
|
||||
}
|
||||
SPDK_RPC_REGISTER("get_iscsi_connections", spdk_rpc_get_iscsi_connections)
|
||||
|
||||
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
|
||||
spdk_rpc_target_node_add_lun(struct spdk_jsonrpc_request *request,
|
||||
const struct spdk_json_val *params)
|
||||
{
|
||||
struct rpc_target_lun req = {};
|
||||
struct spdk_json_write_ctx *w;
|
||||
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;
|
||||
}
|
||||
|
||||
target = spdk_iscsi_find_tgt_node(req.name);
|
||||
if (target == NULL) {
|
||||
SPDK_ERRLOG("target is not found\n");
|
||||
goto invalid;
|
||||
}
|
||||
|
||||
rc = spdk_iscsi_tgt_node_add_lun(target, req.bdev_name, req.lun_id);
|
||||
if (rc < 0) {
|
||||
SPDK_ERRLOG("add lun failed\n");
|
||||
goto invalid;
|
||||
}
|
||||
|
||||
free_rpc_target_lun(&req);
|
||||
|
||||
w = spdk_jsonrpc_begin_result(request);
|
||||
if (w == NULL) {
|
||||
return;
|
||||
}
|
||||
|
||||
spdk_json_write_bool(w, true);
|
||||
spdk_jsonrpc_end_result(request, w);
|
||||
return;
|
||||
|
||||
invalid:
|
||||
spdk_jsonrpc_send_error_response(request, SPDK_JSONRPC_ERROR_INVALID_PARAMS,
|
||||
"Invalid parameters");
|
||||
free_rpc_target_lun(&req);
|
||||
}
|
||||
SPDK_RPC_REGISTER("target_node_add_lun", spdk_rpc_target_node_add_lun)
|
||||
|
||||
static void
|
||||
spdk_rpc_get_iscsi_global_params(struct spdk_jsonrpc_request *request,
|
||||
const struct spdk_json_val *params)
|
||||
|
@ -157,6 +157,24 @@ p.add_argument('chap_auth_group', help="""Authentication group ID for this targe
|
||||
p.set_defaults(func=construct_target_node)
|
||||
|
||||
|
||||
def target_node_add_lun(args):
|
||||
params = {
|
||||
'name': args.name,
|
||||
'bdev_name': args.bdev_name,
|
||||
}
|
||||
if args.lun_id:
|
||||
params['lun_id'] = args.lun_id
|
||||
jsonrpc_call('target_node_add_lun', params)
|
||||
|
||||
p = subparsers.add_parser('target_node_add_lun', help='Add LUN to the target node')
|
||||
p.add_argument('name', help='Target node name (ASCII)')
|
||||
p.add_argument('bdev_name', help="""bdev name enclosed in quotes.
|
||||
*** bdev name cannot contain space or colon characters ***""")
|
||||
p.add_argument('-i', dest='lun_id', help="""LUN ID (integer >= 0)
|
||||
*** If LUN ID is omitted or -1, the lowest free one is assigned ***""", type=int, required=False)
|
||||
p.set_defaults(func=target_node_add_lun)
|
||||
|
||||
|
||||
def add_pg_ig_maps(args):
|
||||
pg_tags = []
|
||||
ig_tags = []
|
||||
|
@ -273,6 +273,9 @@ def verify_target_nodes_rpc_methods(rpc_py, rpc_param):
|
||||
rpc = spdk_rpc(rpc_py)
|
||||
portal_tag = '1'
|
||||
initiator_tag = '1'
|
||||
output = rpc.get_iscsi_global_params()
|
||||
jsonvalues = json.loads(output)
|
||||
nodebase = jsonvalues['node_base']
|
||||
output = rpc.get_target_nodes()
|
||||
jsonvalues = json.loads(output)
|
||||
verify(not jsonvalues, 1,
|
||||
@ -290,11 +293,12 @@ def verify_target_nodes_rpc_methods(rpc_py, rpc_param):
|
||||
jsonvalues = json.loads(output)
|
||||
verify(len(jsonvalues) == 1, 1,
|
||||
"get_target_nodes returned {} nodes, expected 1".format(len(jsonvalues)))
|
||||
verify(jsonvalues[0]['luns'][0]['bdev_name'] == "Malloc" + str(rpc_param['lun_total']), 1,
|
||||
bdev_name = jsonvalues[0]['luns'][0]['bdev_name']
|
||||
verify(bdev_name == "Malloc" + str(rpc_param['lun_total']), 1,
|
||||
"bdev_name value is {}, expected Malloc{}".format(jsonvalues[0]['luns'][0]['bdev_name'], str(rpc_param['lun_total'])))
|
||||
name = jsonvalues[0]['name']
|
||||
verify(name == "iqn.2016-06.io.spdk:" + rpc_param['target_name'], 1,
|
||||
"target name value is {}, expected {}".format(name, "iqn.2016-06.io.spdk:" + rpc_param['target_name']))
|
||||
verify(name == nodebase + ":" + rpc_param['target_name'], 1,
|
||||
"target name value is {}, expected {}".format(name, nodebase + ":" + rpc_param['target_name']))
|
||||
verify(jsonvalues[0]['alias_name'] == rpc_param['alias_name'], 1,
|
||||
"target alias_name value is {}, expected {}".format(jsonvalues[0]['alias_name'], rpc_param['alias_name']))
|
||||
verify(jsonvalues[0]['luns'][0]['id'] == 0, 1,
|
||||
@ -313,6 +317,14 @@ def verify_target_nodes_rpc_methods(rpc_py, rpc_param):
|
||||
"chap required value is {}, expected {}".format(jsonvalues[0]['chap_required'], rpc_param['chap_required']))
|
||||
verify(jsonvalues[0]['chap_auth_group'] == rpc_param['chap_auth_group'], 1,
|
||||
"chap auth group value is {}, expected {}".format(jsonvalues[0]['chap_auth_group'], rpc_param['chap_auth_group']))
|
||||
lun_id = '1'
|
||||
rpc.target_node_add_lun(name, bdev_name, "-i", lun_id)
|
||||
output = rpc.get_target_nodes()
|
||||
jsonvalues = json.loads(output)
|
||||
verify(jsonvalues[0]['luns'][1]['bdev_name'] == "Malloc" + str(rpc_param['lun_total']), 1,
|
||||
"bdev_name value is {}, expected Malloc{}".format(jsonvalues[0]['luns'][0]['bdev_name'], str(rpc_param['lun_total'])))
|
||||
verify(jsonvalues[0]['luns'][1]['id'] == 1, 1,
|
||||
"lun id value is {}, expected 1".format(jsonvalues[0]['luns'][1]['id']))
|
||||
|
||||
rpc.delete_target_node(name)
|
||||
output = rpc.get_target_nodes()
|
||||
|
Loading…
Reference in New Issue
Block a user