2022-11-02 15:49:40 +00:00
|
|
|
# SPDX-License-Identifier: BSD-3-Clause
|
|
|
|
# Copyright (C) 2017 Intel Corporation
|
|
|
|
# All rights reserved.
|
|
|
|
#
|
|
|
|
|
2018-04-04 13:46:41 +00:00
|
|
|
# Network configuration
|
2020-08-21 08:55:20 +00:00
|
|
|
# There is one initiator interface and it is accessed directly.
|
|
|
|
# There are two target interfaces and they are accessed through an namespace.
|
|
|
|
ISCSI_BRIDGE="iscsi_br"
|
2018-04-04 13:46:41 +00:00
|
|
|
INITIATOR_INTERFACE="spdk_init_int"
|
2020-08-21 08:55:20 +00:00
|
|
|
INITIATOR_BRIDGE="init_br"
|
2018-04-25 16:16:08 +00:00
|
|
|
TARGET_NAMESPACE="spdk_iscsi_ns"
|
2020-02-20 10:24:53 +00:00
|
|
|
TARGET_NS_CMD=(ip netns exec "$TARGET_NAMESPACE")
|
2020-08-21 08:55:20 +00:00
|
|
|
TARGET_INTERFACE="spdk_tgt_int"
|
|
|
|
TARGET_INTERFACE2="spdk_tgt_int2"
|
|
|
|
TARGET_BRIDGE="tgt_br"
|
|
|
|
TARGET_BRIDGE2="tgt_br2"
|
2018-04-04 13:46:41 +00:00
|
|
|
|
2018-03-27 13:17:53 +00:00
|
|
|
# iSCSI target configuration
|
2018-04-04 13:46:41 +00:00
|
|
|
TARGET_IP=10.0.0.1
|
2020-08-21 08:55:20 +00:00
|
|
|
TARGET_IP2=10.0.0.3
|
2018-04-04 13:46:41 +00:00
|
|
|
INITIATOR_IP=10.0.0.2
|
2018-03-27 13:17:53 +00:00
|
|
|
ISCSI_PORT=3260
|
2018-04-25 16:16:08 +00:00
|
|
|
NETMASK=$INITIATOR_IP/32
|
2018-03-27 13:17:53 +00:00
|
|
|
INITIATOR_TAG=2
|
|
|
|
INITIATOR_NAME=ANY
|
2018-03-27 13:56:16 +00:00
|
|
|
PORTAL_TAG=1
|
2020-02-20 10:24:53 +00:00
|
|
|
ISCSI_APP=("${TARGET_NS_CMD[@]}" "${ISCSI_APP[@]}")
|
2022-12-01 14:32:33 +00:00
|
|
|
ISCSI_TEST_CORE_MASK=0xF
|
2018-04-04 13:46:41 +00:00
|
|
|
|
|
|
|
function create_veth_interfaces() {
|
2020-08-21 08:55:20 +00:00
|
|
|
ip link set $INITIATOR_BRIDGE nomaster || true
|
|
|
|
ip link set $TARGET_BRIDGE nomaster || true
|
|
|
|
ip link set $TARGET_BRIDGE2 nomaster || true
|
|
|
|
ip link set $INITIATOR_BRIDGE down || true
|
|
|
|
ip link set $TARGET_BRIDGE down || true
|
|
|
|
ip link set $TARGET_BRIDGE2 down || true
|
|
|
|
ip link delete $ISCSI_BRIDGE type bridge || true
|
2018-04-04 13:46:41 +00:00
|
|
|
ip link delete $INITIATOR_INTERFACE || true
|
2020-08-21 08:55:20 +00:00
|
|
|
"${TARGET_NS_CMD[@]}" ip link delete $TARGET_INTERFACE || true
|
|
|
|
"${TARGET_NS_CMD[@]}" ip link delete $TARGET_INTERFACE2 || true
|
|
|
|
ip netns del $TARGET_NAMESPACE || true
|
2018-04-04 13:46:41 +00:00
|
|
|
|
2020-08-11 10:03:58 +00:00
|
|
|
trap 'cleanup_veth_interfaces; exit 1' SIGINT SIGTERM EXIT
|
2018-06-22 12:15:59 +00:00
|
|
|
|
2020-08-21 08:55:20 +00:00
|
|
|
# Create network namespace
|
2018-04-25 16:16:08 +00:00
|
|
|
ip netns add $TARGET_NAMESPACE
|
2020-08-21 08:55:20 +00:00
|
|
|
|
|
|
|
# Create veth (Virtual ethernet) interface pairs
|
|
|
|
ip link add $INITIATOR_INTERFACE type veth peer name $INITIATOR_BRIDGE
|
|
|
|
ip link add $TARGET_INTERFACE type veth peer name $TARGET_BRIDGE
|
|
|
|
ip link add $TARGET_INTERFACE2 type veth peer name $TARGET_BRIDGE2
|
|
|
|
|
|
|
|
# Associate veth interface pairs with network namespace
|
2018-04-25 16:16:08 +00:00
|
|
|
ip link set $TARGET_INTERFACE netns $TARGET_NAMESPACE
|
2020-08-21 08:55:20 +00:00
|
|
|
ip link set $TARGET_INTERFACE2 netns $TARGET_NAMESPACE
|
2018-04-25 16:16:08 +00:00
|
|
|
|
2020-08-21 08:55:20 +00:00
|
|
|
# Allocate IP addresses
|
|
|
|
ip addr add $INITIATOR_IP/24 dev $INITIATOR_INTERFACE
|
|
|
|
"${TARGET_NS_CMD[@]}" ip addr add $TARGET_IP/24 dev $TARGET_INTERFACE
|
|
|
|
"${TARGET_NS_CMD[@]}" ip addr add $TARGET_IP2/24 dev $TARGET_INTERFACE2
|
2018-08-10 13:21:42 +00:00
|
|
|
|
2020-08-21 08:55:20 +00:00
|
|
|
# Link up veth interfaces
|
|
|
|
ip link set $INITIATOR_INTERFACE up
|
|
|
|
ip link set $INITIATOR_BRIDGE up
|
|
|
|
ip link set $TARGET_BRIDGE up
|
|
|
|
ip link set $TARGET_BRIDGE2 up
|
2020-02-20 10:24:53 +00:00
|
|
|
"${TARGET_NS_CMD[@]}" ip link set $TARGET_INTERFACE up
|
2020-08-21 08:55:20 +00:00
|
|
|
"${TARGET_NS_CMD[@]}" ip link set $TARGET_INTERFACE2 up
|
2020-08-11 10:03:58 +00:00
|
|
|
"${TARGET_NS_CMD[@]}" ip link set lo up
|
2020-08-21 08:55:20 +00:00
|
|
|
|
|
|
|
# Create a bridge
|
|
|
|
ip link add $ISCSI_BRIDGE type bridge
|
|
|
|
ip link set $ISCSI_BRIDGE up
|
|
|
|
|
|
|
|
# Add veth interfaces to the bridge
|
|
|
|
ip link set $INITIATOR_BRIDGE master $ISCSI_BRIDGE
|
|
|
|
ip link set $TARGET_BRIDGE master $ISCSI_BRIDGE
|
|
|
|
ip link set $TARGET_BRIDGE2 master $ISCSI_BRIDGE
|
|
|
|
|
|
|
|
# Accept connections from veth interface
|
|
|
|
iptables -I INPUT 1 -i $INITIATOR_INTERFACE -p tcp --dport $ISCSI_PORT -j ACCEPT
|
2022-04-01 19:12:51 +00:00
|
|
|
iptables -A FORWARD -i $ISCSI_BRIDGE -o $ISCSI_BRIDGE -j ACCEPT
|
2018-06-25 12:44:59 +00:00
|
|
|
|
2020-08-11 10:03:58 +00:00
|
|
|
# Verify connectivity
|
|
|
|
ping -c 1 $TARGET_IP
|
2020-08-21 08:55:20 +00:00
|
|
|
ping -c 1 $TARGET_IP2
|
|
|
|
"${TARGET_NS_CMD[@]}" ping -c 1 $INITIATOR_IP
|
|
|
|
"${TARGET_NS_CMD[@]}" ping -c 1 $INITIATOR_IP
|
2018-04-04 13:46:41 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
function cleanup_veth_interfaces() {
|
2020-08-21 08:55:20 +00:00
|
|
|
# Cleanup bridge, veth interfaces, and network namespace
|
2018-04-04 13:46:41 +00:00
|
|
|
# Note: removing one veth, removes the pair
|
2020-08-21 08:55:20 +00:00
|
|
|
ip link set $INITIATOR_BRIDGE nomaster
|
|
|
|
ip link set $TARGET_BRIDGE nomaster
|
|
|
|
ip link set $TARGET_BRIDGE2 nomaster
|
|
|
|
ip link set $INITIATOR_BRIDGE down
|
|
|
|
ip link set $TARGET_BRIDGE down
|
|
|
|
ip link set $TARGET_BRIDGE2 down
|
|
|
|
ip link delete $ISCSI_BRIDGE type bridge
|
2018-04-04 13:46:41 +00:00
|
|
|
ip link delete $INITIATOR_INTERFACE
|
2020-08-21 08:55:20 +00:00
|
|
|
"${TARGET_NS_CMD[@]}" ip link delete $TARGET_INTERFACE
|
|
|
|
"${TARGET_NS_CMD[@]}" ip link delete $TARGET_INTERFACE2
|
2018-04-25 16:16:08 +00:00
|
|
|
ip netns del $TARGET_NAMESPACE
|
2018-04-04 13:46:41 +00:00
|
|
|
}
|
2019-05-06 22:46:30 +00:00
|
|
|
|
|
|
|
function iscsitestinit() {
|
2020-08-11 10:24:22 +00:00
|
|
|
if [ "$TEST_MODE" == "iso" ]; then
|
2019-05-06 22:46:30 +00:00
|
|
|
$rootdir/scripts/setup.sh
|
2020-08-11 10:03:58 +00:00
|
|
|
create_veth_interfaces
|
2019-05-06 22:46:30 +00:00
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
2019-06-17 07:23:20 +00:00
|
|
|
function waitforiscsidevices() {
|
|
|
|
local num=$1
|
|
|
|
|
2020-05-07 11:27:06 +00:00
|
|
|
for ((i = 1; i <= 20; i++)); do
|
|
|
|
n=$(iscsiadm -m session -P 3 | grep -c "Attached scsi disk sd[a-z]*" || true)
|
2019-06-17 07:23:20 +00:00
|
|
|
if [ $n -ne $num ]; then
|
|
|
|
sleep 0.1
|
|
|
|
else
|
|
|
|
return 0
|
|
|
|
fi
|
|
|
|
done
|
|
|
|
|
|
|
|
return 1
|
|
|
|
}
|
|
|
|
|
2019-05-06 22:46:30 +00:00
|
|
|
function iscsitestfini() {
|
2020-08-11 10:24:22 +00:00
|
|
|
if [ "$TEST_MODE" == "iso" ]; then
|
2020-08-11 10:03:58 +00:00
|
|
|
cleanup_veth_interfaces
|
2019-05-06 22:46:30 +00:00
|
|
|
$rootdir/scripts/setup.sh reset
|
|
|
|
fi
|
|
|
|
}
|
2018-06-25 12:44:59 +00:00
|
|
|
|
2020-03-17 14:08:22 +00:00
|
|
|
function initiator_json_config() {
|
|
|
|
# Prepare config file for iSCSI initiator
|
2020-05-07 11:27:06 +00:00
|
|
|
jq . <<- JSON
|
2020-03-17 14:08:22 +00:00
|
|
|
{
|
|
|
|
"subsystems": [
|
|
|
|
{
|
|
|
|
"subsystem": "bdev",
|
|
|
|
"config": [
|
|
|
|
{
|
|
|
|
"method": "bdev_iscsi_create",
|
|
|
|
"params": {
|
|
|
|
"name": "iSCSI0",
|
|
|
|
"url": "iscsi://$TARGET_IP/iqn.2016-06.io.spdk:disk1/0",
|
|
|
|
"initiator_iqn": "iqn.2016-06.io.spdk:disk1/0"
|
|
|
|
}
|
2021-05-12 11:49:53 +00:00
|
|
|
},
|
|
|
|
{
|
|
|
|
"method": "bdev_wait_for_examine"
|
2021-05-12 13:11:27 +00:00
|
|
|
}
|
2020-03-17 14:08:22 +00:00
|
|
|
]
|
|
|
|
}
|
|
|
|
]
|
|
|
|
}
|
|
|
|
JSON
|
|
|
|
}
|