2017-01-25 23:36:40 +00:00
|
|
|
#!/usr/bin/env bash
|
|
|
|
|
|
|
|
set -e
|
|
|
|
|
2018-01-02 21:44:48 +00:00
|
|
|
rootdir=$(readlink -f $(dirname $0))/..
|
|
|
|
source "$rootdir/scripts/common.sh"
|
|
|
|
|
2021-07-13 16:36:58 +00:00
|
|
|
gen_subsystems=false
|
2021-07-14 07:05:51 +00:00
|
|
|
gen_mode="local"
|
|
|
|
gen_function="create_local_json_config"
|
|
|
|
gen_args=()
|
2021-07-13 16:36:58 +00:00
|
|
|
|
|
|
|
function usage() {
|
|
|
|
echo "Script for generating JSON configuration file for attaching"
|
|
|
|
echo "local userspace NVMe drives."
|
|
|
|
echo "Usage: ${0##*/} [OPTIONS]"
|
|
|
|
echo
|
|
|
|
echo "-h, --help Print help and exit"
|
2021-07-14 07:05:51 +00:00
|
|
|
echo " --mode Generate 'local' or 'remote' NVMe JSON configuration. Default is 'local'."
|
|
|
|
echo " Remote needs --trid option to be present."
|
|
|
|
echo " --trid Comma separated list target subsystem information containing transport type,"
|
|
|
|
echo " IP addresses, port numbers and NQN names."
|
|
|
|
echo " Example: tcp:127.0.0.1:4420:nqn.2016-06.io.spdk:cnode1,tcp:127.0.0.1:4421:nqn.2016-06.io.spdk:cnode2"
|
2021-07-13 16:36:58 +00:00
|
|
|
echo " --json-with-subsystems Wrap bdev subsystem JSON configuration with higher level 'subsystems' dictionary."
|
|
|
|
exit 0
|
|
|
|
}
|
|
|
|
|
2021-07-14 07:05:51 +00:00
|
|
|
function create_local_json_config() {
|
2020-08-20 01:20:13 +00:00
|
|
|
local bdev_json_cfg=()
|
2021-07-13 17:00:46 +00:00
|
|
|
local bdfs=()
|
|
|
|
|
|
|
|
bdfs=($(nvme_in_userspace))
|
2020-08-20 01:20:13 +00:00
|
|
|
|
|
|
|
for i in "${!bdfs[@]}"; do
|
|
|
|
bdev_json_cfg+=("$(
|
|
|
|
cat <<- JSON
|
|
|
|
{
|
|
|
|
"method": "bdev_nvme_attach_controller",
|
|
|
|
"params": {
|
|
|
|
"trtype": "PCIe",
|
|
|
|
"name":"Nvme${i}",
|
|
|
|
"traddr":"${bdfs[i]}"
|
|
|
|
}
|
|
|
|
}
|
|
|
|
JSON
|
|
|
|
)")
|
2018-05-16 19:45:39 +00:00
|
|
|
done
|
2020-08-20 01:20:13 +00:00
|
|
|
|
|
|
|
local IFS=","
|
|
|
|
cat <<- JSON
|
|
|
|
{
|
|
|
|
"subsystem": "bdev",
|
|
|
|
"config": [
|
|
|
|
${bdev_json_cfg[*]}
|
|
|
|
]
|
|
|
|
}
|
|
|
|
JSON
|
2018-05-16 19:45:39 +00:00
|
|
|
}
|
|
|
|
|
2021-07-14 07:05:51 +00:00
|
|
|
function create_remote_json_config() {
|
|
|
|
local trids
|
|
|
|
local bdev_json_cfg=()
|
|
|
|
|
|
|
|
IFS="," read -r -a trids <<< $1
|
|
|
|
for ((i = 0; i < ${#trids[@]}; i++)); do
|
|
|
|
local transport
|
|
|
|
local ip_addr
|
|
|
|
local svc_port
|
|
|
|
local nqn
|
|
|
|
|
|
|
|
IFS=":" read -r transport ip_addr svc_port nqn <<< ${trids[i]}
|
|
|
|
bdev_json_cfg+=("$(
|
|
|
|
cat <<- JSON
|
|
|
|
{
|
|
|
|
"method": "bdev_nvme_attach_controller",
|
|
|
|
"params": {
|
|
|
|
"trtype": "$transport",
|
|
|
|
"adrfam": "IPv4",
|
|
|
|
"name": "Nvme${i}",
|
|
|
|
"subnqn": "$nqn",
|
|
|
|
"traddr": "$ip_addr",
|
|
|
|
"trsvcid": "$svc_port"
|
|
|
|
}
|
|
|
|
}
|
|
|
|
JSON
|
|
|
|
)")
|
|
|
|
done
|
|
|
|
|
|
|
|
local IFS=","
|
|
|
|
cat <<- JSON
|
|
|
|
{
|
|
|
|
"subsystem": "bdev",
|
|
|
|
"config": [
|
|
|
|
${bdev_json_cfg[*]}
|
|
|
|
]
|
|
|
|
}
|
|
|
|
JSON
|
|
|
|
}
|
|
|
|
|
2021-07-13 16:36:58 +00:00
|
|
|
while getopts 'h-:' optchar; do
|
|
|
|
case "$optchar" in
|
|
|
|
-)
|
|
|
|
case "$OPTARG" in
|
|
|
|
help) usage ;;
|
2021-07-14 07:05:51 +00:00
|
|
|
mode=*)
|
|
|
|
gen_mode="${OPTARG#*=}"
|
|
|
|
gen_function="create_${OPTARG#*=}_json_config"
|
|
|
|
;;
|
|
|
|
trid=*) remote_trid="${OPTARG#*=}" ;;
|
2021-07-13 16:36:58 +00:00
|
|
|
json-with-subsystems) gen_subsystems=true ;;
|
|
|
|
*) echo "Invalid argument '$OPTARG'" && usage ;;
|
|
|
|
esac
|
|
|
|
;;
|
|
|
|
h) usage ;;
|
|
|
|
*) echo "Invalid argument '$OPTARG'" && usage ;;
|
|
|
|
esac
|
|
|
|
done
|
|
|
|
|
2021-07-14 07:05:51 +00:00
|
|
|
if [[ "$gen_mode" == "remote" ]] && [[ -z "$remote_trid" ]]; then
|
|
|
|
echo "For $gen_mode --trid argument must be provided."
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
|
|
|
if [[ "$gen_mode" == "remote" ]]; then
|
|
|
|
gen_args+=("$remote_trid")
|
|
|
|
fi
|
|
|
|
|
|
|
|
bdev_json_cfg=$("$gen_function" "${gen_args[@]}")
|
2021-07-13 16:36:58 +00:00
|
|
|
if [[ $gen_subsystems == true ]]; then
|
2021-07-13 17:23:15 +00:00
|
|
|
bdev_json_cfg=$(
|
|
|
|
cat <<- JSON
|
|
|
|
{
|
|
|
|
"subsystems": [
|
|
|
|
$bdev_json_cfg
|
|
|
|
]
|
|
|
|
}
|
|
|
|
JSON
|
|
|
|
)
|
2018-05-16 19:45:39 +00:00
|
|
|
fi
|
2021-07-13 17:23:15 +00:00
|
|
|
|
|
|
|
echo "$bdev_json_cfg"
|