f60b99b168
create_json_config_with_subsystems contents does not need to be in a function. Moving it to main simplifies --with-subsystems condition. Signed-off-by: Karol Latecki <karol.latecki@intel.com> Change-Id: I1414a209cc666ebb4639fc25133168482bd96c97 Reviewed-on: https://review.spdk.io/gerrit/c/spdk/spdk/+/8775 Community-CI: Broadcom CI <spdk-ci.pdl@broadcom.com> Tested-by: SPDK CI Jenkins <sys_sgci@intel.com> Reviewed-by: Paul Luse <paul.e.luse@intel.com> Reviewed-by: Jim Harris <james.r.harris@intel.com> Reviewed-by: Changpeng Liu <changpeng.liu@intel.com>
80 lines
1.4 KiB
Bash
Executable File
80 lines
1.4 KiB
Bash
Executable File
#!/usr/bin/env bash
|
|
|
|
set -e
|
|
|
|
rootdir=$(readlink -f $(dirname $0))/..
|
|
source "$rootdir/scripts/common.sh"
|
|
|
|
gen_subsystems=false
|
|
|
|
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"
|
|
echo " --json-with-subsystems Wrap bdev subsystem JSON configuration with higher level 'subsystems' dictionary."
|
|
exit 0
|
|
}
|
|
|
|
function create_json_config() {
|
|
local bdev_json_cfg=()
|
|
local bdfs=()
|
|
|
|
bdfs=($(nvme_in_userspace))
|
|
|
|
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
|
|
)")
|
|
done
|
|
|
|
local IFS=","
|
|
cat <<- JSON
|
|
{
|
|
"subsystem": "bdev",
|
|
"config": [
|
|
${bdev_json_cfg[*]}
|
|
]
|
|
}
|
|
JSON
|
|
}
|
|
|
|
while getopts 'h-:' optchar; do
|
|
case "$optchar" in
|
|
-)
|
|
case "$OPTARG" in
|
|
help) usage ;;
|
|
json-with-subsystems) gen_subsystems=true ;;
|
|
*) echo "Invalid argument '$OPTARG'" && usage ;;
|
|
esac
|
|
;;
|
|
h) usage ;;
|
|
*) echo "Invalid argument '$OPTARG'" && usage ;;
|
|
esac
|
|
done
|
|
|
|
bdev_json_cfg=$(create_json_config)
|
|
if [[ $gen_subsystems == true ]]; then
|
|
bdev_json_cfg=$(
|
|
cat <<- JSON
|
|
{
|
|
"subsystems": [
|
|
$bdev_json_cfg
|
|
]
|
|
}
|
|
JSON
|
|
)
|
|
fi
|
|
|
|
echo "$bdev_json_cfg"
|