forked from hreinecke/tcm-scripts
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtarget_save.sh
110 lines (104 loc) · 2.59 KB
/
target_save.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
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
#!/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
TCM_CONF=/tmp/target.conf
print_fabric() {
local dir=$1
for a in $(find $dir -name statistics -prune -o -print) ; do
attr=${a##$TCM_ROOT/}
if [ -L $a ] ; then
echo "link ${attr} $(readlink $a)"
elif [ -f $a ] ; then
[ $(stat -c '%a' $a) = "200" ] && continue
case $a in
*alua*members)
continue
;;
*alua*alua_access_status)
continue
;;
*pr/res_holder)
continue
;;
*pr/res_pr_registered_i_pts)
continue
;;
*pr/res_aptpl_metadata)
continue
;;
esac
if [ "${attr%%_*}" = "core/fileio" ] ; then
if [ "${attr##*/}" = "info" ] ; then
continue
fi
if [ "${attr##*/}" = "enable" ] ; then
continue
fi
fi
if [ "${attr##*/}" = "hba_info" ] ; then
continue
fi
if [ "${attr##*/}" = "alua_lu_gp" ] ; then
val=$(sed -n 's/.*Group Alias: \(.*\)/\1/p' $a)
echo "attr ${attr} $val"
continue
fi
if [ "${attr##*/}" = "alua_tg_pt_gp" ] ; then
val=$(sed -n 's/.*Port Alias: \(.*\)/\1/p' $a)
echo "attr ${attr} $val"
continue
fi
if [ "${attr##*/}" = "vendor_id" ] ; then
val=$(sed -n 's/.*Identification: *\(.*\)/\1/p' $a)
echo "attr ${attr} $val"
continue
fi
val=$(cat $a)
if [[ x"$val" = x15 && x"${attr##*/}" = xalua_access_state ]]; then
tmofile=$TCM_ROOT/${attr//alua_access_state/implicit_trans_secs}
tmo=$(cat $tmofile)
[[ -n "$tmo" ]] || tmo=1
i=0
echo "$attr is ALUA_ACCESS_STATE_TRANSITION, waiting max $tmo s" >&2
while [[ $i -lt $tmo && x$val = x15 ]]; do
sleep 1
val=$(cat $a)
i=$((i+1))
done
[[ x$val != x15 ]] || echo "WARNING: $attr is still ALUA_ACCESS_STATE_TRANSITION" >&2
fi
if [ -n "$val" ] ; then
echo "attr ${attr} $val"
fi
else
echo "dir ${attr}"
case ${attr##*/} in
fd_*)
echo -n "attr ${attr}/control "
sed -n 's/.*File: *\([^ ]*\) *Size: *\([0-9]*\) .*/fd_dev_name=\1,fd_dev_size=\2/p' ${a}/info
enable=$(cat ${a}/enable)
echo "attr ${attr}/enable $enable"
;;
esac
fi
done
}
print_fabric $TCM_ROOT/core
for tcm in $TCM_ROOT/iscsi/*/tpgt_* $TCM_ROOT/fc/*/tpgt_* ; do
[ -d $tcm ] || continue
tpgt=${tcm##$TCM_ROOT/}
port=${tpgt%/*}
fabric=${port%/*}
echo "dir $fabric"
echo "dir $port"
echo "dir $tpgt"
print_fabric $tcm/attrib
print_fabric $tcm/param
print_fabric $tcm/lun
print_fabric $tcm/auth
print_fabric $tcm/acls
done