forked from utsaslab/crashmonkey
-
Notifications
You must be signed in to change notification settings - Fork 0
/
base_xfstest.sh
148 lines (130 loc) · 3.67 KB
/
base_xfstest.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
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
#!/bin/bash
# SPDX-License-Identifier: GPL-2.0
# Copyright (c) $CURRENT_YEAR The University of Texas at Austin. All Rights Reserved.
#
# FS QA Test $TEST_NUMBER
#
# Test case created by CrashMonkey
#
# Test if we create a hard link to a file and persist either of the files, all
# the names persist.
#
seq=`basename $0`
seqres=$RESULT_DIR/$seq
echo "QA output created by $seq"
here=`pwd`
tmp=/tmp/$$
status=1 # failure is the default!
trap "_cleanup; exit \$status" 0 1 2 3 15
_cleanup()
{
_cleanup_flakey
cd /
rm -f $tmp.*
}
# get standard environment, filters and checks
. ./common/rc
. ./common/filter
. ./common/dmflakey
# 256MB in byte
fssize=$((2**20 * 256))
# remove previous $seqres.full before test
rm -f $seqres.full
# real QA test starts here
_supported_fs $FILESYSTEM_TYPE
_supported_os Linux
_require_scratch_nocheck
_require_dm_target flakey
# initialize scratch device
_scratch_mkfs_sized $fssize >> $seqres.full 2>&1
_require_metadata_journaling $SCRATCH_DEV
_init_flakey
stat_opt='-c %n - blocks: %b size: %s inode: %i links: %h'
# Rename wraps 'mv' except that 'rename A/ B/'
# would replace B, instead of creating A/B
rename() {
[ -d $1 ] && [ -d $2 ] && rm -rf $2
mv $1 $2
}
# Usage: general_stat [--data-only] file1 [--data-only] [file2] ..
# If the --data-only flag precedes a file, then only that file's
# data will be printed.
general_stat() {
data_only="false"
while (( "$#" )); do
case $1 in
--data-only)
data_only="true"
;;
*)
local file="$1"
echo "-- $file --"
if [ ! -f "$file" ] && [ ! -d "$file" ]; then
echo "Doesn't exist!"
elif [ "$data_only" = "true" ] && [ -d "$file" ]; then
# Directory with --data-only
echo "Directory Data"
[[ -z "$(ls -A $file)" ]] || ls -1 "$file" | sort
elif [ "$data_only" = "true" ]; then
# File with --data-only
echo "File Data"
od "$file"
elif [ -d "$file" ]; then
# Directory with metadata and data
echo "Directory Metadata"
stat "$stat_opt" "$file"
echo "Directory Data"
[[ -z "$(ls -A $file)" ]] || ls -1 "$file" | sort
else
# File with metadata and data
echo "File Metadata"
stat "$stat_opt" "$file"
echo "File Data"
od "$file"
fi
data_only="false"
;;
esac
shift
done
}
# Open a file with O_DIRECT and write a byte into a range
_dwrite_byte() {
local pattern="$1"
local offset="$2"
local len="$3"
local file="$4"
local xfs_io_args="$5"
$XFS_IO_PROG $xfs_io_args -f -c "open -f -d -s $file" -c "pwrite -S $pattern $offset $len" "$file"
}
_mwrite_byte_and_msync() {
local pattern="$1"
local offset="$2"
local len="$3"
local mmap_len="$4"
local file="$5"
$XFS_IO_PROG -f -c "mmap -rw 0 $mmap_len" -c "mwrite -S $pattern $offset $len" "$file" -c "msync -s"
}
check_consistency()
{
before=$(general_stat "$@")
_flakey_drop_and_remount
after=$(general_stat "$@")
if [ "$before" != "$after" ]; then
echo -e "Before:\n$before"
echo -e "After:\n$after"
fi
}
# Using _scratch_mkfs instead of cleaning up the working directory,
# adds about 10 seconds of delay in total for the 37 tests.
clean_dir()
{
rm -rf $(find $SCRATCH_MNT/* | grep -v "lost+found")
sync
_unmount_flakey
}
# Test cases
# Success, all done
echo "Silence is golden"
status=0
exit