-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpixie
More file actions
69 lines (59 loc) · 1.8 KB
/
pixie
File metadata and controls
69 lines (59 loc) · 1.8 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
#!/bin/bash
logger "pixie ${@}"
if [ ! $1 ]
then
cat << EOF
Usage: pixie [COMMAND]
Commands:
new NAME Create a new instance
Returns the iscsi target. Exitcode 1 if it already exists.
del NAME Delete an existing instance
list List info
enable-all (dangerous) Make existing instances available over iscsi
Only use this after restarting iscsitarget server
EOF
exit 1
fi
case "$1" in
"new")
if zfs list | grep $2 > /dev/null
then
#echo "This instance already exists. Exiting 1."
grep $2 /proc/net/iet/volume | sed -rn '1s/.*name:(.*)$/\1/p'
exit 1
fi
lasttid=$(sed -nr '1s/.*tid:([0-9]*).*/\1/p' /proc/net/iet/volume)
newtid=$((lasttid+1))
zfs snapshot tank/winbase@$2 && \
zfs clone tank/winbase@$2 tank/$2 && \
ietadm --op new --tid=$newtid --params Name=iqn.lan.hal:instance.$2 && \
ietadm --op new --tid=$newtid --lun=0 --params Path=/dev/zvol/tank/$2,Type=blockio && \
sed -rn '1s/.*name:(.*)$/\1/p' /proc/net/iet/volume
exit 0
;;
"del")
# get the tid from ietadm
tid=$(grep $2 /proc/net/iet/volume | sed -nr '1s/.*tid:([0-9]*).*/\1/p')
ietadm --op delete --tid=$tid
zfs destroy tank/$2
zfs destroy tank/winbase@$2
;;
"enable-all")
for instance in $(zfs list | sed -rn '/@/s/^tank\/winbase@([^\S ]*) .*$/\1/p')
do
lasttid=$(sed -nr '1s/.*tid:([0-9]*).*/\1/p' /proc/net/iet/volume)
newtid=$((lasttid+1))
ietadm --op new --tid=$newtid --params Name=iqn.lan.hal:instance.$instance
ietadm --op new --tid=$newtid --lun=0 --params Path=/dev/zvol/tank/$instance,Type=blockio
done
;;
"list")
echo "[ISCSI]"
cat /proc/net/iet/volume
echo "[ZFS]"
zfs list
;;
*) echo "Invalid command"
exit 1
;;
esac