iscsi/rpc: Adjust format of bdev_name_id_pair between dump and construct
JSON format of bdev_name_id_pair is different between construct_target_node() and get_target_nodes(). construct_target_nodes() uses the following format: "lun_ids": [ 1 ], "bdev_names": [ "Malloc0" ] get_target_nodes() uses the following format: "luns": [ { "lun_id": 0, "bdev_name": "lvs_1/lbd_1" }, ] The second format is better than the first format. Hence unify to the second format. Change-Id: If097e41ada0f2fe3754691cee0a0774db97c4ebb Signed-off-by: Shuhei Matsumoto <shuhei.matsumoto.xt@hitachi.com> Reviewed-on: https://review.gerrithub.io/399993 Tested-by: SPDK Automated Test System <sys_sgsw@intel.com> Reviewed-by: Daniel Verkamp <daniel.verkamp@intel.com> Reviewed-by: Jim Harris <james.r.harris@intel.com>
This commit is contained in:
parent
3b4e5493d9
commit
f35f395b82
@ -484,54 +484,56 @@ decode_rpc_pg_ig_maps(const struct spdk_json_val *val, void *out)
|
||||
|
||||
#define RPC_CONSTRUCT_TARGET_NODE_MAX_LUN 64
|
||||
|
||||
struct rpc_bdev_names {
|
||||
size_t num_names;
|
||||
char *names[RPC_CONSTRUCT_TARGET_NODE_MAX_LUN];
|
||||
struct rpc_lun {
|
||||
char *bdev_name;
|
||||
int32_t lun_id;
|
||||
};
|
||||
|
||||
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},
|
||||
};
|
||||
|
||||
static int
|
||||
decode_rpc_bdev_names(const struct spdk_json_val *val, void *out)
|
||||
decode_rpc_lun(const struct spdk_json_val *val, void *out)
|
||||
{
|
||||
struct rpc_bdev_names *bdev_names = out;
|
||||
struct rpc_lun *lun = out;
|
||||
|
||||
return spdk_json_decode_array(val, spdk_json_decode_string, bdev_names->names,
|
||||
return spdk_json_decode_object(val, rpc_lun_decoders,
|
||||
SPDK_COUNTOF(rpc_lun_decoders), lun);
|
||||
}
|
||||
|
||||
struct rpc_luns {
|
||||
size_t num_luns;
|
||||
struct rpc_lun luns[RPC_CONSTRUCT_TARGET_NODE_MAX_LUN];
|
||||
};
|
||||
|
||||
static int
|
||||
decode_rpc_luns(const struct spdk_json_val *val, void *out)
|
||||
{
|
||||
struct rpc_luns *luns = out;
|
||||
|
||||
return spdk_json_decode_array(val, decode_rpc_lun, luns->luns,
|
||||
RPC_CONSTRUCT_TARGET_NODE_MAX_LUN,
|
||||
&bdev_names->num_names, sizeof(char *));
|
||||
&luns->num_luns, sizeof(struct rpc_lun));
|
||||
}
|
||||
|
||||
static void
|
||||
free_rpc_bdev_names(struct rpc_bdev_names *r)
|
||||
free_rpc_luns(struct rpc_luns *p)
|
||||
{
|
||||
size_t i;
|
||||
|
||||
for (i = 0; i < r->num_names; i++) {
|
||||
free(r->names[i]);
|
||||
for (i = 0; i < p->num_luns; i++) {
|
||||
free(p->luns[i].bdev_name);
|
||||
}
|
||||
}
|
||||
|
||||
struct rpc_lun_ids {
|
||||
size_t num_ids;
|
||||
int32_t ids[RPC_CONSTRUCT_TARGET_NODE_MAX_LUN];
|
||||
};
|
||||
|
||||
static int
|
||||
decode_rpc_lun_ids(const struct spdk_json_val *val, void *out)
|
||||
{
|
||||
struct rpc_lun_ids *lun_ids = out;
|
||||
|
||||
return spdk_json_decode_array(val, spdk_json_decode_int32, lun_ids->ids,
|
||||
RPC_CONSTRUCT_TARGET_NODE_MAX_LUN,
|
||||
&lun_ids->num_ids, sizeof(int32_t));
|
||||
}
|
||||
|
||||
struct rpc_target_node {
|
||||
char *name;
|
||||
char *alias_name;
|
||||
|
||||
struct rpc_pg_ig_maps pg_ig_maps;
|
||||
|
||||
struct rpc_bdev_names bdev_names;
|
||||
struct rpc_lun_ids lun_ids;
|
||||
struct rpc_luns luns;
|
||||
|
||||
int32_t queue_depth;
|
||||
int32_t chap_disabled;
|
||||
@ -548,15 +550,14 @@ free_rpc_target_node(struct rpc_target_node *req)
|
||||
{
|
||||
free(req->name);
|
||||
free(req->alias_name);
|
||||
free_rpc_bdev_names(&req->bdev_names);
|
||||
free_rpc_luns(&req->luns);
|
||||
}
|
||||
|
||||
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},
|
||||
{"pg_ig_maps", offsetof(struct rpc_target_node, pg_ig_maps), decode_rpc_pg_ig_maps},
|
||||
{"bdev_names", offsetof(struct rpc_target_node, bdev_names), decode_rpc_bdev_names},
|
||||
{"lun_ids", offsetof(struct rpc_target_node, lun_ids), decode_rpc_lun_ids},
|
||||
{"luns", offsetof(struct rpc_target_node, luns), decode_rpc_luns},
|
||||
{"queue_depth", offsetof(struct rpc_target_node, queue_depth), spdk_json_decode_int32},
|
||||
{"chap_disabled", offsetof(struct rpc_target_node, chap_disabled), spdk_json_decode_int32},
|
||||
{"chap_required", offsetof(struct rpc_target_node, chap_required), spdk_json_decode_int32},
|
||||
@ -574,6 +575,8 @@ spdk_rpc_construct_target_node(struct spdk_jsonrpc_request *request,
|
||||
struct spdk_json_write_ctx *w;
|
||||
struct spdk_iscsi_tgt_node *target;
|
||||
int32_t pg_tags[MAX_TARGET_MAP] = {0}, ig_tags[MAX_TARGET_MAP] = {0};
|
||||
char *bdev_names[RPC_CONSTRUCT_TARGET_NODE_MAX_LUN] = {0};
|
||||
int32_t lun_ids[RPC_CONSTRUCT_TARGET_NODE_MAX_LUN] = {0};
|
||||
size_t i;
|
||||
|
||||
req.header_digest = 0;
|
||||
@ -586,16 +589,16 @@ spdk_rpc_construct_target_node(struct spdk_jsonrpc_request *request,
|
||||
goto invalid;
|
||||
}
|
||||
|
||||
if (req.bdev_names.num_names != req.lun_ids.num_ids) {
|
||||
SPDK_ERRLOG("bdev_names/lun_ids count mismatch\n");
|
||||
goto invalid;
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
/*
|
||||
* Use default parameters in a few places:
|
||||
* index = -1 : automatically pick an index for the new target node
|
||||
@ -606,9 +609,9 @@ spdk_rpc_construct_target_node(struct spdk_jsonrpc_request *request,
|
||||
pg_tags,
|
||||
ig_tags,
|
||||
req.pg_ig_maps.num_maps,
|
||||
(const char **)req.bdev_names.names,
|
||||
req.lun_ids.ids,
|
||||
req.bdev_names.num_names,
|
||||
(const char **)bdev_names,
|
||||
lun_ids,
|
||||
req.luns.num_luns,
|
||||
req.queue_depth,
|
||||
req.chap_disabled,
|
||||
req.chap_required,
|
||||
|
@ -18,9 +18,10 @@ def get_target_nodes(args):
|
||||
|
||||
|
||||
def construct_target_node(args):
|
||||
bdev_name_id_dict = dict(u.split(":") for u in args.bdev_name_id_pairs.strip().split(" "))
|
||||
bdev_names = bdev_name_id_dict.keys()
|
||||
lun_ids = list(map(int, bdev_name_id_dict.values()))
|
||||
luns = []
|
||||
for u in args.bdev_name_id_pairs.strip().split(" "):
|
||||
bdev_name, lun_id = u.split(":")
|
||||
luns.append({"bdev_name": bdev_name, "lun_id": int(lun_id)})
|
||||
|
||||
pg_ig_maps = []
|
||||
for u in args.pg_ig_mappings.strip().split(" "):
|
||||
@ -31,8 +32,7 @@ def construct_target_node(args):
|
||||
'name': args.name,
|
||||
'alias_name': args.alias_name,
|
||||
'pg_ig_maps': pg_ig_maps,
|
||||
'bdev_names': bdev_names,
|
||||
'lun_ids': lun_ids,
|
||||
'luns': luns,
|
||||
'queue_depth': args.queue_depth,
|
||||
'chap_disabled': args.chap_disabled,
|
||||
'chap_required': args.chap_required,
|
||||
|
Loading…
Reference in New Issue
Block a user