Commit 92ef1a64 authored by Shuhei Matsumoto's avatar Shuhei Matsumoto Committed by Daniel Verkamp
Browse files

iscsi and ut/iscsi: return code to fail of IG creation



spdk_iscsi_init_grp_create_from_configfile() returns 0 even if
creating an initiator group (IG) is failed due to empty netmask or
initiator name. This will be unexpected behavior for end users.
Hence change the return code from 0 to -ENVAL for this failure.

Besides do the following.

Change other error return codes in the function by using errno too.

Current IG don't have any UT code in repository. UT code to confirm
this fix is also submitted.

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


Tested-by: default avatarSPDK Automated Test System <sys_sgsw@intel.com>
Reviewed-by: default avatarDaniel Verkamp <daniel.verkamp@intel.com>
parent cf6fe9b1
Loading
Loading
Loading
Loading
+5 −5
Original line number Diff line number Diff line
@@ -184,12 +184,12 @@ spdk_iscsi_init_grp_create_from_configfile(struct spdk_conf_section *sp)
	}
	if (i == 0) {
		SPDK_ERRLOG("num_initiator_names = 0\n");
		goto cleanup;
		return -EINVAL;
	}
	num_initiator_names = i;
	if (num_initiator_names > MAX_INITIATOR) {
		SPDK_ERRLOG("%d > MAX_INITIATOR\n", num_initiator_names);
		return -1;
		return -E2BIG;
	}
	for (i = 0; ; i++) {
		val = spdk_conf_section_get_nval(sp, "Netmask", i);
@@ -198,18 +198,18 @@ spdk_iscsi_init_grp_create_from_configfile(struct spdk_conf_section *sp)
	}
	if (i == 0) {
		SPDK_ERRLOG("num_initiator_mask = 0\n");
		goto cleanup;
		return -EINVAL;
	}
	num_initiator_masks = i;
	if (num_initiator_masks > MAX_NETMASK) {
		SPDK_ERRLOG("%d > MAX_NETMASK\n", num_initiator_masks);
		return -1;
		return -E2BIG;
	}

	initiators = calloc(num_initiator_names, sizeof(char *));
	if (!initiators) {
		perror("initiators");
		return -1;
		return -ENOMEM;
	}
	for (i = 0; i < num_initiator_names; i++) {
		val = spdk_conf_section_get_nval(sp, "InitiatorName", i);
+1 −1
Original line number Diff line number Diff line
@@ -34,7 +34,7 @@
SPDK_ROOT_DIR := $(abspath $(CURDIR)/../../../..)
include $(SPDK_ROOT_DIR)/mk/spdk.common.mk

DIRS-y = iscsi.c param.c tgt_node.c
DIRS-y = init_grp.c iscsi.c param.c tgt_node.c

.PHONY: all clean $(DIRS-y)

+1 −0
Original line number Diff line number Diff line
init_grp_ut
+57 −0
Original line number Diff line number Diff line
#
#  BSD LICENSE
#
#  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.
#

SPDK_ROOT_DIR := $(abspath $(CURDIR)/../../../../..)
include $(SPDK_ROOT_DIR)/mk/spdk.common.mk
include $(SPDK_ROOT_DIR)/mk/spdk.app.mk

SPDK_LIB_LIST = log conf util cunit

CFLAGS += $(ENV_CFLAGS)
CFLAGS += -I$(SPDK_ROOT_DIR)/test
CFLAGS += -I$(SPDK_ROOT_DIR)/lib
LIBS += $(SPDK_LIB_LINKER_ARGS)
LIBS += -lcunit

APP = init_grp_ut
C_SRCS = init_grp_ut.c

all: $(APP)

$(APP): $(OBJS) $(SPDK_LIB_FILES)
	$(LINK_C)

clean:
	$(CLEAN_C) $(APP)

include $(SPDK_ROOT_DIR)/mk/spdk.deps.mk
+31 −0
Original line number Diff line number Diff line
[IG_Valid0]
# Success is expected.
  InitiatorName iqn.2017-10.spdk.io:0001
  Netmask 192.168.2.0

[IG_Valid1]
# Success is expected.
  InitiatorName iqn.2017-10.spdk.io:0001
  Netmask 192.168.2.0
  Netmask 192.168.2.1

[IG_Valid2]
# Success is expected.
  InitiatorName iqn.2017-10.spdk.io:0001
  InitiatorName iqn.2017-10.spdk.io:0002
  Netmask 192.168.2.0

[IG_Valid3]
# Success is expected.
  InitiatorName iqn.2017-10.spdk.io:0001
  InitiatorName iqn.2017-10.spdk.io:0002
  Netmask 192.168.2.0
  Netmask 192.168.2.1

[IG_Invalid0]
# Failure is expected.
  InitiatorName iqn.2017-10.spdk.io:0001

[IG_Invalid1]
# Failure is expected.
  Netmask 192.168.2.0
Loading