2018-10-29 14:40:34 +00:00
|
|
|
#!/usr/bin/env bash
|
|
|
|
|
|
|
|
set -e
|
|
|
|
|
|
|
|
rootdir=$(readlink -f $(dirname $0))/..
|
|
|
|
|
2020-05-07 11:27:06 +00:00
|
|
|
function usage() {
|
2019-10-25 07:31:14 +00:00
|
|
|
echo "Usage: [-j] $0 -n BDEV_NAME -d BASE_BDEV [-u UUID] [-c CACHE]"
|
2018-10-29 14:40:34 +00:00
|
|
|
echo "UUID is required when restoring device state"
|
2019-01-29 09:54:46 +00:00
|
|
|
echo
|
|
|
|
echo "BDEV_NAME - name of the bdev"
|
2019-10-25 07:31:14 +00:00
|
|
|
echo "BASE_BDEV - name of the bdev to be used as underlying device"
|
2019-01-29 09:54:46 +00:00
|
|
|
echo "UUID - bdev's uuid (used when in restore mode)"
|
2019-03-20 08:36:02 +00:00
|
|
|
echo "CACHE - name of the bdev to be used as write buffer cache"
|
2018-10-29 14:40:34 +00:00
|
|
|
}
|
|
|
|
|
2020-05-07 11:27:06 +00:00
|
|
|
function create_json_config() {
|
2019-02-19 10:06:12 +00:00
|
|
|
echo "{"
|
|
|
|
echo '"subsystem": "bdev",'
|
|
|
|
echo '"config": ['
|
|
|
|
echo '{'
|
2019-08-21 09:03:04 +00:00
|
|
|
echo '"method": "bdev_ftl_create",'
|
2019-02-19 10:06:12 +00:00
|
|
|
echo '"params": {'
|
2019-10-25 07:31:14 +00:00
|
|
|
echo "\"name\": \"$1\","
|
|
|
|
echo "\"base_bdev\": \"$2\","
|
2019-09-10 13:01:27 +00:00
|
|
|
if [ -n "$4" ]; then
|
|
|
|
echo "\"uuid\": \"$3\","
|
|
|
|
echo "\"cache\": \"$4\""
|
2019-02-19 10:06:12 +00:00
|
|
|
else
|
2019-09-10 13:01:27 +00:00
|
|
|
echo "\"uuid\": \"$3\""
|
2019-02-19 10:06:12 +00:00
|
|
|
fi
|
|
|
|
echo '}'
|
|
|
|
echo '}'
|
|
|
|
echo ']'
|
|
|
|
echo '}'
|
|
|
|
}
|
|
|
|
|
2019-03-22 08:21:30 +00:00
|
|
|
uuid=00000000-0000-0000-0000-000000000000
|
|
|
|
|
2019-10-25 07:31:14 +00:00
|
|
|
while getopts ":c:d:hn:u:" arg; do
|
2018-10-29 14:40:34 +00:00
|
|
|
case "$arg" in
|
2020-05-07 11:27:06 +00:00
|
|
|
n) name=$OPTARG ;;
|
|
|
|
d) base_bdev=$OPTARG ;;
|
|
|
|
u) uuid=$OPTARG ;;
|
|
|
|
c) cache=$OPTARG ;;
|
|
|
|
h)
|
|
|
|
usage
|
|
|
|
exit 0
|
|
|
|
;;
|
|
|
|
*)
|
|
|
|
usage
|
|
|
|
exit 1
|
|
|
|
;;
|
2018-10-29 14:40:34 +00:00
|
|
|
esac
|
|
|
|
done
|
|
|
|
|
2019-10-25 07:31:14 +00:00
|
|
|
if [[ -z "$name" || -z "$base_bdev" ]]; then
|
2018-10-29 14:40:34 +00:00
|
|
|
usage
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
2019-10-25 07:31:14 +00:00
|
|
|
create_json_config $name $base_bdev $uuid $cache
|