-
Notifications
You must be signed in to change notification settings - Fork 4
/
aoe-flush.in
55 lines (51 loc) · 991 Bytes
/
aoe-flush.in
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
#! /bin/sh
# aoe-flush - ask aoe driver to forget about devices
# Copyright 2009, CORAID, Inc., and licensed under GPL v.2.
zero="`basename $0`"
f="@devdir@/flush"
spec=""
if ! test -w "$f"; then
echo 1>&2 "$zero: $f does not exist or is not writeable."
exit 1
fi
if ! test -c $f; then
exec 1>&2
echo "$zero: $f is not a character device file"
echo "$zero: use udev or aoe-mkdevs to create it"
exit 1
fi
# make sure that each device in the whitespace-separated
# list exists
verify_devs () {
err=""
for d; do
aoe-stat |
awk -vd="$d" '$1==d{print $1}' |
test "`cat`" || {
exec 2>&1
echo "$zero Error: \"$d\" is not an aoe device"
err="$err $d"
}
done
test ! "$err"
}
err=""
if test "$1"; then
if test "$1" = "-a"; then
spec=all
else
spec="$*"
verify_devs $spec || exit 1
fi
for i in $spec; do
printf "$i" > "$f" || {
echo 1>&2 "$zero: flush failed"
err="$err $i"
}
done
else
echo > "$f" || err=no_args
fi
if test "$err"; then
exit 1
fi