linux/iscsi: storagemgr.sh

File storagemgr.sh, 1003 bytes (added by yuna, 11 years ago)
Line 
1#!/bin/sh
2# usage:
3# 作成
4#  # mngstorage create disk1 100M
5#  # mngstorage delete disk1
6#  # mngstorage snap   disk1 disk2
7#
8#
9STORAGE_PATH=/storage/lv
10iqn=iqn.2008-09.com.example
11vgname=vg
12
13
14case $1 in
15    create)
16        MESURE=`echo $3|sed -e 's/\([0-9]\+\)\(.\)$/\2/'`
17        SIZE=`echo $3|sed -e 's/\([0-9]\+\)\(.\)$/\1/'`
18
19        dd of=$STORAGE_PATH/$2.img bs=1$MESURE seek=$SIZE count=0
20echo "<target ${iqn}:${vgname}.$2>
21    backing-store ${STORAGE_PATH}/$2.raw
22</target>
23" >> /etc/tgt/conf.d/${vgname}_$2.conf
24        service tgt reload
25    ;;
26
27    snap)
28        cp --reflink $STORAGE_PATH/$2.raw $STORAGE_PATH/$3.raw
29echo "<target ${iqn}:${vgname}.$3>
30    backing-store ${STORAGE_PATH}/$3.raw
31</target>
32" >> /etc/tgt/conf.d/${vgname}_$3.conf
33        service tgt reload
34    ;;
35
36    delete)
37        rm /etc/tgt/conf.d/${vgname}_${2}.conf
38        rm $STORAGE_PATH/$2.raw
39        service tgt reload
40    ;;
41
42    *)
43        echo "error"
44    ;;
45
46esac