forked from hreinecke/tcm-scripts
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtarget_shutdown.sh
93 lines (83 loc) · 1.73 KB
/
target_shutdown.sh
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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
#!/bin/bash
##check if the user has root access
if [ "$EUID" -ne 0 ]
then echo "Please run as root"
exit
fi
TCM_ROOT=/sys/kernel/config/target
shutdown_fcoe() {
for c in /sys/bus/fcoe/devices/ctlr_* ; do
[ -d $c ] || continue
echo 0 > $c/enabled
done
}
shutdown_fabric() {
local fabric=$TCM_ROOT/$1
[[ -d "$fabric" ]] || return
for p in ${fabric}/* ; do
[ -d $p ] || continue
[ "${p##*/}" = "discovery_auth" ] && continue
for t in ${p}/tpgt_* ; do
[ -d $t ] || continue
for a in ${t}/acls/* ; do
[ -d $a ] || continue
for l in ${a}/lun_* ; do
[ -d $l ] || continue
for b in $l/* ; do
[ -L $b ] || continue
echo "Remove $b"
rm -f $b
done
echo "Remove $l"
rmdir $l || exit 1
done
echo "Remove $a"
rmdir $a || exit 1
done
for l in ${t}/lun/lun_* ; do
[ -d $l ] || continue
for b in $l/* ; do
[ -L $b ] || continue
echo "Remove $b"
rm -f $b
done
echo "Remove $l"
rmdir $l || exit 1
done
for n in ${t}/np/* ; do
[ -d $n ] || continue
echo "Remove $n"
rmdir $n
done
echo "Remove $t"
rmdir $t || exit 1
done
echo "Remove $p"
rmdir $p || exit 1
done
rmdir $fabric || exit 1
}
shutdown_backstore() {
local backstore=$TCM_ROOT/core/$1
for f in ${backstore}_* ; do
[ -d $f ] || continue
for d in ${f}/* ; do
[ -d $d ] || continue
for t in ${d}/alua/* ; do
[ -d $t ] || continue
[ ${t##*/} = "default_tg_pt_gp" ] && continue
echo "Remove $t"
rmdir $t || exit 1
done
echo "Remove $d"
rmdir $d || exit 1
done
echo "Remove $f"
rmdir $f || exit 1
done
}
shutdown_fcoe
shutdown_fabric fc
shutdown_fabric iscsi
shutdown_backstore fileio
shutdown_backstore iblock