File btrfs-subvol-test.sh of Package ganglia
xxxxxxxxxx
1
2
#
3
# Copyright (c) 2017 SUSE LINUX Products GmbH, Nuernberg, Germany.
4
#
5
# Author: Christian Goll <CGoll@suse.de>
6
#
7
TEST_FILE_NAME=no_btrfs_check
8
function usage() {
9
cat <<EOF
10
$0 /DIR/TO/TEST
11
The test will exactly fail if TEST is on the same fs as / and its
12
btrfs fs. As an overwrite option you can touch the file /etc/TEST/$TEST_FILE_NAME
13
which will make the test always to suceed.
14
Goal of this test is to have a handy script to create the awareness, that the
15
date in /DIR/TO/TEST my be lost on a fs-rollback.
16
EOF
17
}
18
19
if [ $# -ne "1" ] ; then
20
usage
21
exit 1
22
fi
23
testdir=$1
24
# Test for every entry entry in /proc/mounts if the maximum depth
25
basedir="/"
26
depth=0
27
fstype=unknown
28
mountops=unknown
29
while IFS='' read -r entry || [[ -n "$entry" ]] ; do
30
path=$(echo $entry | cut -f 2 -d ' ')
31
echo $testdir | grep $path > /dev/null
32
if [ x$? == "x1" ] ; then
33
continue
34
fi
35
newdepth=$(echo $path | tr -d -c '/' | wc -m)
36
if [ $newdepth -lt $depth ] ; then
37
echo "continue"
38
continue
39
fi
40
depth=$newdepth
41
fstype=$(echo $entry | cut -f 3 -d ' ')
42
mountopts=$(echo $entry | cut -f 4 -d ' ')
43
basedir=$path
44
done < /proc/mounts
45
if [ $fstype != "btrfs" ] ; then
46
exit 0
47
fi
48
echo $mountops | grep 'subvolid' > /dev/null
49
if [ $basedir != "/" ] ; then
50
exit 0
51
fi
52
if [ -e "/etc/$(basename $testdir)/$TEST_FILE_NAME" ] ; then
53
exit 0
54
fi
55
cat << EOF
56
The start of the service failed as the directory $testdir" is located under
57
a btrfs root. On a filesystem rollback data could so become unaccessible or corrupted.
58
To start the service anyway run "touch /etc/$(basename $testdir)/$TEST_FILE_NAME" or
59
install the package with the suffix "skip-bcheck" associtated with the package of the
60
service
61
EOF
62
exit 1
63