-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmxhtspd-remove-disk
executable file
·78 lines (69 loc) · 1.77 KB
/
mxhtspd-remove-disk
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
#!/bin/sh
#
# V2406C design a hotswap button for umount all the partitions and stop all the disks
#
file=`basename $0`
num=$1
field="\$1"
umount_partitions() {
num=$1
#Check partitions
partitions=`mount | awk -F' ' "/media\/disk${num}/{print $field}" | xargs -n 10`
if [ ! -z "$partitions" ] ; then
echo "$file: WARNING! /media/disk${num}pn should be unmounted before disk is removed"
echo "$file: Force to unmount them"
for i in $partitions; do
/bin/umount $i 2> /dev/null
done
fi
}
#Stop the disks
stop_disk() {
host=$1
target=$2
path=$3
if [ ! -f /sys/class/scsi_host/$host/device/$target/$path/delete ] ; then
echo "mxhtspd: WARNING! can't remove disk $num. It may has been removed before"
exit 0
else
echo 1 > /sys/class/scsi_host/$host/device/$target/$path/delete
fi
}
# Umount all the the partitions on SATA-A disk
if [ "$num" = "1" ] ; then
umount_partitions $num
# Stop the SATA-A disk
host="host1";
target="target1:0:0";
path="1:0:0:0"
stop_disk $host $target $path
fi
# Umount all the the partitions on SATA-B disk
if [ "$num" = "2" ] ; then
umount_partitions $num
# Stop the SATA-B disk
host="host2";
target="target2:0:0";
path="2:0:0:0"
stop_disk $host $target $path
fi
if [ "$num" = "3" ] || [ "$num" = "4" ] ; then
disk_num=$(($num-2))
echo "$file: WARNING! disk${disk_num} is busy."
for i in 1 2 3;
do
mxhtspd-setled $disk_num 0; sleep 1
mxhtspd-setled $disk_num 1; sleep 1
done
# show message to all currently logged in users
echo "mxhtspd: Can't remove disk $disk_num. It is busy." | wall -n
else
#Light success led
for i in 1 2 3;
do
mxhtspd-setled $num 1; sleep 1
mxhtspd-setled $num 0; sleep 1
done
# show message to all currently logged in users
echo "mxhtspd: Remove disk $num is done." | wall -n
fi