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