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"
|
|
|
|
|
2020-05-07 11:27:06 +00:00
|
|
|
function create_json_config() {
|
2020-08-20 01:20:13 +00:00
|
|
|
local bdev_json_cfg=()
|
|
|
|
|
|
|
|
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
|
|
|
}
|
|
|
|
|
2020-08-18 19:17:12 +00:00
|
|
|
function create_json_config_with_subsystems() {
|
|
|
|
cat <<- JSON
|
|
|
|
{
|
|
|
|
"subsystems": [
|
|
|
|
$(create_json_config)
|
|
|
|
]
|
|
|
|
}
|
|
|
|
JSON
|
|
|
|
}
|
|
|
|
|
2020-06-23 08:25:15 +00:00
|
|
|
bdfs=($(nvme_in_userspace))
|
2018-12-28 13:41:48 +00:00
|
|
|
|
2020-10-21 10:59:09 +00:00
|
|
|
if [[ "$1" = "--json-with-subsystems" ]]; then
|
2020-08-18 19:17:12 +00:00
|
|
|
create_json_config_with_subsystems
|
2018-05-16 19:45:39 +00:00
|
|
|
else
|
2020-10-21 10:59:09 +00:00
|
|
|
create_json_config
|
2018-05-16 19:45:39 +00:00
|
|
|
fi
|