xref: /spdk/scripts/gen_ftl.sh (revision 75c2135de5d2e752b8a851e3fa55395b02a47bed)
1#!/usr/bin/env bash
2
3set -e
4
5rootdir=$(readlink -f $(dirname $0))/..
6
7function usage {
8	echo "Usage: [-j] $0 -n BDEV_NAME -d BASE_BDEV [-u UUID] [-c CACHE]"
9	echo "UUID is required when restoring device state"
10	echo
11	echo "BDEV_NAME - name of the bdev"
12	echo "BASE_BDEV - name of the bdev to be used as underlying device"
13	echo "UUID - bdev's uuid (used when in restore mode)"
14	echo "CACHE - name of the bdev to be used as write buffer cache"
15}
16
17function create_json_config()
18{
19	echo "{"
20	echo '"subsystem": "bdev",'
21	echo '"config": ['
22	echo '{'
23	echo '"method": "bdev_ftl_create",'
24	echo '"params": {'
25	echo "\"name\": \"$1\","
26	echo "\"base_bdev\": \"$2\","
27	if [ -n "$4" ]; then
28		echo "\"uuid\": \"$3\","
29		echo "\"cache\": \"$4\""
30	else
31		echo "\"uuid\": \"$3\""
32	fi
33	echo '}'
34	echo '}'
35	echo ']'
36	echo '}'
37}
38
39uuid=00000000-0000-0000-0000-000000000000
40
41while getopts ":c:d:hn:u:" arg; do
42	case "$arg" in
43		n)	name=$OPTARG		;;
44		d)	base_bdev=$OPTARG	;;
45		u)	uuid=$OPTARG		;;
46		c)	cache=$OPTARG		;;
47		h)	usage
48			exit 0			;;
49		*)	usage
50			exit 1			;;
51	esac
52done
53
54if [[ -z "$name" || -z "$base_bdev" ]]; then
55	usage
56	exit 1
57fi
58
59create_json_config $name $base_bdev $uuid $cache
60