blob: 0beb08927bdb47a2604a196cc7cc06c355562ff7 (
plain)
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
|
#! /bin/bash
# SPDX-License-Identifier: GPL-2.0-or-later
# Copyright (c) 2022 Oracle. All Rights Reserved.
#
# FS QA Test No. 721
#
# Test non-root atomic file updates when (a) the file contents are cloned into
# the staging file; and (b) when the staging file is created empty.
. ./common/preamble
_begin_fstest auto quick fiexchange swapext
# Override the default cleanup function.
_cleanup()
{
cd /
rm -r -f $tmp.* $dir
}
# Import common functions.
. ./common/filter
. ./common/reflink
# real QA test starts here
_require_xfs_io_command startupdate
_require_test_reflink
_require_test
_require_user
filesnap() {
echo "$1"
md5sum $2 | _filter_test_dir
}
mkfile() {
rm -f $dir/a
_pwrite_byte 0x58 0 $((blksz * nrblks)) $dir/a >> $seqres.full
chown $qa_user $dir/a $dir/
sync
}
dir=$TEST_DIR/test-$seq
mkdir -p $dir
blksz=65536
nrblks=64
# Use the atomic file update staging prototype in xfs_io to update a file.
mkfile
filesnap "before commit" $dir/a
cmd="$XFS_IO_PROG \
-c 'startupdate' \
-c 'pwrite -S 0x60 44k 55k -b 1m' \
-c 'commitupdate -q' \
\"$dir/a\""
su -s /bin/bash -c "$cmd" $qa_user 2>&1 | _filter_xfs_io | _filter_test_dir
filesnap "after commit" $dir/a
echo
# Use the atomic file updates to replace a file with a shorter file.
mkfile
filesnap "before shorten commit" $dir/a
cmd="$XFS_IO_PROG \
-c 'startupdate' \
-c 'truncate 55k' \
-c 'pwrite -S 0x60 0 55k' \
-c 'commitupdate -q' \
\"$dir/a\""
su -s /bin/bash -c "$cmd" $qa_user 2>&1 | _filter_xfs_io | _filter_test_dir
filesnap "after shorten commit" $dir/a
echo
# Use the atomic file updates to replace a file with a longer file.
mkfile
filesnap "before lengthen commit" $dir/a
cmd="$XFS_IO_PROG \
-c 'startupdate' \
-c \"pwrite -S 0x60 0 $(( (blksz * nrblks) + 37373 ))\" \
-c 'commitupdate -q' \
\"$dir/a\""
su -s /bin/bash -c "$cmd" $qa_user 2>&1 | _filter_xfs_io | _filter_test_dir
filesnap "after lengthen commit" $dir/a
echo
# Use the atomic file update staging prototype in xfs_io to cancel updating a
# file.
mkfile
filesnap "before cancel" $dir/a
cmd="$XFS_IO_PROG \
-c 'startupdate' \
-c 'pwrite -S 0x60 44k 55k -b 1m' \
-c 'cancelupdate' \
\"$dir/a\""
su -s /bin/bash -c "$cmd" $qa_user 2>&1 | _filter_xfs_io | _filter_test_dir
filesnap "after cancel" $dir/a
echo
# Now try the update but with the A file open separately so that we clobber
# mtime and fail the update.
mkfile
filesnap "before fail commit" $dir/a
cmd="$XFS_IO_PROG \
-c \"open $dir/a\" \
-c 'startupdate' \
-c 'pwrite -S 0x58 44k 55k -b 1m' \
-c 'file 0' \
-c 'close' \
-c 'pwrite -S 0x61 22k 11k -b 1m' \
-c 'commitupdate -q' \
\"$dir/a\""
su -s /bin/bash -c "$cmd" $qa_user 2>&1 | _filter_xfs_io | _filter_test_dir
filesnap "after fail commit" $dir/a
echo
# success, all done
status=0
exit
|