Commit 36fc9b2d authored by Shuhei Matsumoto's avatar Shuhei Matsumoto Committed by Jim Harris
Browse files

iscsi/rpc: Convert type of CHAP params of target from int to bool



This is a TODO from long ago. Complete this while adjusting dump()
and construct() format of target.

Besides names of variables and parameters about CHAP are not unified
between JSON-RPC and SPDK internal. JSON-RPC's wording looks better
and adjust SPDK internal to JSON-RPC.

Change-Id: I89bcd1ce13a11f7d63a62d51ef094dd302186d37
Signed-off-by: default avatarShuhei Matsumoto <shuhei.matsumoto.xt@hitachi.com>
Reviewed-on: https://review.gerrithub.io/400201


Tested-by: default avatarSPDK Automated Test System <sys_sgsw@intel.com>
Reviewed-by: default avatarJim Harris <james.r.harris@intel.com>
Reviewed-by: default avatarDaniel Verkamp <daniel.verkamp@intel.com>
parent b94ba1ee
Loading
Loading
Loading
Loading
+19 −23
Original line number Diff line number Diff line
@@ -392,20 +392,16 @@ dump_target_node(struct spdk_json_write_ctx *w, struct spdk_iscsi_tgt_node *tgtn
	spdk_json_write_name(w, "queue_depth");
	spdk_json_write_int32(w, tgtnode->queue_depth);

	/*
	 * TODO: convert these to bool
	 */

	spdk_json_write_name(w, "chap_disabled");
	spdk_json_write_int32(w, tgtnode->auth_chap_disabled);
	spdk_json_write_name(w, "disable_chap");
	spdk_json_write_bool(w, tgtnode->auth_chap_disabled);

	spdk_json_write_name(w, "chap_required");
	spdk_json_write_int32(w, tgtnode->auth_chap_required);
	spdk_json_write_name(w, "require_chap");
	spdk_json_write_bool(w, tgtnode->auth_chap_required);

	spdk_json_write_name(w, "chap_mutual");
	spdk_json_write_int32(w, tgtnode->auth_chap_mutual);
	spdk_json_write_name(w, "mutual_chap");
	spdk_json_write_bool(w, tgtnode->auth_chap_mutual);

	spdk_json_write_name(w, "chap_auth_group");
	spdk_json_write_name(w, "chap_group");
	spdk_json_write_int32(w, tgtnode->auth_group);

	spdk_json_write_name(w, "header_digest");
@@ -536,10 +532,10 @@ struct rpc_target_node {
	struct rpc_luns luns;

	int32_t queue_depth;
	int32_t chap_disabled;
	int32_t chap_required;
	int32_t chap_mutual;
	int32_t chap_auth_group;
	bool disable_chap;
	bool require_chap;
	bool mutual_chap;
	int32_t chap_group;

	bool header_digest;
	bool data_digest;
@@ -559,10 +555,10 @@ static const struct spdk_json_object_decoder rpc_target_node_decoders[] = {
	{"pg_ig_maps", offsetof(struct rpc_target_node, pg_ig_maps), decode_rpc_pg_ig_maps},
	{"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},
	{"chap_mutual", offsetof(struct rpc_target_node, chap_mutual), spdk_json_decode_int32},
	{"chap_auth_group", offsetof(struct rpc_target_node, chap_auth_group), spdk_json_decode_int32},
	{"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},
	{"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},
};
@@ -609,10 +605,10 @@ spdk_rpc_construct_target_node(struct spdk_jsonrpc_request *request,
					       lun_ids,
					       req.luns.num_luns,
					       req.queue_depth,
					       req.chap_disabled,
					       req.chap_required,
					       req.chap_mutual,
					       req.chap_auth_group,
					       req.disable_chap,
					       req.require_chap,
					       req.mutual_chap,
					       req.chap_group,
					       req.header_digest,
					       req.data_digest);

+20 −20
Original line number Diff line number Diff line
@@ -844,16 +844,16 @@ spdk_check_iscsi_name(const char *name)
}

static bool
spdk_iscsi_check_chap_params(int disabled, int required, int mutual, int group)
spdk_iscsi_check_chap_params(bool disabled, bool required, bool mutual, int group)
{
	if (group < 0) {
		SPDK_ERRLOG("Invalid auth group ID (%d)\n", group);
		return false;
	}
	if ((disabled == 0 && required == 0 && mutual == 0) ||	/* Auto */
	    (disabled == 1 && required == 0 && mutual == 0) ||	/* None */
	    (disabled == 0 && required == 1 && mutual == 0) ||	/* CHAP */
	    (disabled == 0 && required == 1 && mutual == 1)) {	/* CHAP Mutual */
	if ((!disabled && !required && !mutual) ||	/* Auto */
	    (disabled && !required && !mutual) ||	/* None */
	    (!disabled && required && !mutual) ||	/* CHAP */
	    (!disabled && required && mutual)) {	/* CHAP Mutual */
		return true;
	}
	SPDK_ERRLOG("Invalid combination of CHAP params (d=%d,r=%d,m=%d)\n",
@@ -867,7 +867,7 @@ spdk_iscsi_tgt_node_construct(int target_index,
			      int *pg_tag_list, int *ig_tag_list, uint16_t num_maps,
			      const char *bdev_name_list[], int *lun_id_list, int num_luns,
			      int queue_depth,
			      int auth_chap_disabled, int auth_chap_required, int auth_chap_mutual, int auth_group,
			      bool auth_chap_disabled, bool auth_chap_required, bool auth_chap_mutual, int auth_group,
			      bool header_digest, bool data_digest)
{
	char				fullname[MAX_TMPBUF];
@@ -991,7 +991,7 @@ spdk_cf_add_iscsi_tgt_node(struct spdk_conf_section *sp)
	const char *val, *name;
	int target_num, auth_group, pg_tag_i, ig_tag_i;
	bool header_digest, data_digest;
	int auth_chap_disabled, auth_chap_required, auth_chap_mutual;
	bool auth_chap_disabled, auth_chap_required, auth_chap_mutual;
	int i;
	int lun_id_list[SPDK_SCSI_DEV_MAX_LUN];
	const char *bdev_name_list[SPDK_SCSI_DEV_MAX_LUN];
@@ -1056,9 +1056,9 @@ spdk_cf_add_iscsi_tgt_node(struct spdk_conf_section *sp)

	/* Setup AuthMethod */
	val = spdk_conf_section_get_val(sp, "AuthMethod");
	auth_chap_disabled = 0;
	auth_chap_required = 0;
	auth_chap_mutual = 0;
	auth_chap_disabled = false;
	auth_chap_required = false;
	auth_chap_mutual = false;
	if (val != NULL) {
		for (i = 0; ; i++) {
			val = spdk_conf_section_get_nmval(sp, "AuthMethod", 0, i);
@@ -1066,17 +1066,17 @@ spdk_cf_add_iscsi_tgt_node(struct spdk_conf_section *sp)
				break;
			}
			if (strcasecmp(val, "CHAP") == 0) {
				auth_chap_required = 1;
				auth_chap_required = true;
			} else if (strcasecmp(val, "Mutual") == 0) {
				auth_chap_mutual = 1;
				auth_chap_mutual = true;
			} else if (strcasecmp(val, "Auto") == 0) {
				auth_chap_disabled = 0;
				auth_chap_required = 0;
				auth_chap_mutual = 0;
				auth_chap_disabled = false;
				auth_chap_required = false;
				auth_chap_mutual = false;
			} else if (strcasecmp(val, "None") == 0) {
				auth_chap_disabled = 1;
				auth_chap_required = 0;
				auth_chap_mutual = 0;
				auth_chap_disabled = true;
				auth_chap_required = false;
				auth_chap_mutual = false;
			} else {
				SPDK_ERRLOG("tgt_node%d: unknown auth\n", target_num);
				return -1;
@@ -1087,9 +1087,9 @@ spdk_cf_add_iscsi_tgt_node(struct spdk_conf_section *sp)
			return -1;
		}
	}
	if (auth_chap_disabled == 1) {
	if (auth_chap_disabled) {
		SPDK_DEBUGLOG(SPDK_LOG_ISCSI, "AuthMethod None\n");
	} else if (auth_chap_required == 0) {
	} else if (!auth_chap_required) {
		SPDK_DEBUGLOG(SPDK_LOG_ISCSI, "AuthMethod Auto\n");
	} else {
		SPDK_DEBUGLOG(SPDK_LOG_ISCSI, "AuthMethod CHAP %s\n",
+4 −4
Original line number Diff line number Diff line
@@ -66,9 +66,9 @@ struct spdk_iscsi_tgt_node {

	pthread_mutex_t mutex;

	int auth_chap_disabled;
	int auth_chap_required;
	int auth_chap_mutual;
	bool auth_chap_disabled;
	bool auth_chap_required;
	bool auth_chap_mutual;
	int auth_group;
	bool header_digest;
	bool data_digest;
@@ -112,7 +112,7 @@ spdk_iscsi_tgt_node_construct(int target_index,
			      int *pg_tag_list, int *ig_tag_list, uint16_t num_maps,
			      const char *bdev_name_list[], int *lun_id_list, int num_luns,
			      int queue_depth,
			      int no_auth_chap, int auth_chap, int auth_chap_mutual, int auth_group,
			      bool no_auth_chap, bool auth_chap, bool auth_chap_mutual, int auth_group,
			      bool header_digest, bool data_digest);

int spdk_iscsi_tgt_node_add_pg_ig_maps(struct spdk_iscsi_tgt_node *target,
+7 −7
Original line number Diff line number Diff line
@@ -134,14 +134,14 @@ if __name__ == "__main__":
    Example: '1:1 2:2 2:1'
    *** The Portal/Initiator Groups must be precreated ***""")
    p.add_argument('queue_depth', help='Desired target queue depth', type=int)
    p.add_argument('chap_disabled', help="""CHAP authentication should be disabled for this target node.
    *** Mutually exclusive with chap_required ***""", type=int)
    p.add_argument('chap_required', help="""CHAP authentication should be required for this target node.
    *** Mutually exclusive with chap_disabled ***""", type=int)
    p.add_argument('-g', '--chap-group', help="""Authentication group ID for this target node.
    *** Authentication group must be precreated ***""", type=int, default=0)
    p.add_argument('-d', '--disable-chap', help="""CHAP authentication should be disabled for this target node.
    *** Mutually exclusive with --require-chap ***""", action='store_true')
    p.add_argument('-r', '--require-chap', help="""CHAP authentication should be required for this target node.
    *** Mutually exclusive with --disable-chap ***""", action='store_true')
    p.add_argument(
        'chap_mutual', help='CHAP authentication should be mutual/bidirectional.', type=int)
    p.add_argument('chap_auth_group', help="""Authentication group ID for this target node.
    *** Authentication group must be precreated ***""", type=int)
        '-m', '--mutual-chap', help='CHAP authentication should be mutual/bidirectional.', action='store_true')
    p.add_argument('-H', '--header-digest',
                   help='Header Digest should be required for this target node.', action='store_true')
    p.add_argument('-D', '--data-digest',
+8 −4
Original line number Diff line number Diff line
@@ -34,12 +34,16 @@ def construct_target_node(args):
        'pg_ig_maps': pg_ig_maps,
        'luns': luns,
        'queue_depth': args.queue_depth,
        'chap_disabled': args.chap_disabled,
        'chap_required': args.chap_required,
        'chap_mutual': args.chap_mutual,
        'chap_auth_group': args.chap_auth_group,
    }

    if args.chap_group:
        params['chap_group'] = args.chap_group
    if args.disable_chap:
        params['disable_chap'] = args.disable_chap
    if args.require_chap:
        params['require_chap'] = args.require_chap
    if args.mutual_chap:
        params['mutual_chap'] = args.mutual_chap
    if args.header_digest:
        params['header_digest'] = args.header_digest
    if args.data_digest:
Loading