summaryrefslogtreecommitdiffstats
path: root/tests/basic/ec/ec-discard.t
blob: 4a44cecf0a99f59e28a58139fbd42210d03b189a (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
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
#!/bin/bash
#
# Test discard functionality
#
# Test that basic discard (hole punch) functionality works via the fallocate
# command line tool. Hole punch deallocates a region of a file, creating a hole
# and a zero-filled data region. We verify that hole punch works, frees blocks
# and that subsequent reads do not read stale data (caches are invalidated).
#
# NOTE: fuse fallocate is known to be broken with regard to cache invalidation
# 	up to 3.9.0 kernels. Therefore, FOPEN_KEEP_CACHE is not used in this
#	test (opens will invalidate the fuse cache).
###

. $(dirname $0)/../../include.rc
. $(dirname $0)/../../fallocate.rc
. $(dirname $0)/../../volume.rc

cleanup

#cleate and start volume
TEST glusterd
TEST pidof glusterd
TEST $CLI volume create $V0 disperse 6 redundancy 2 $H0:$B0/${V0}{0..5}
TEST $CLI volume set $V0 disperse.optimistic-change-log on
TEST $CLI volume start $V0

#Mount the volume
TEST $GFS --volfile-id=/$V0 --volfile-server=$H0 $M0;
EXPECT_WITHIN $CHILD_UP_TIMEOUT "6" ec_child_up_count $V0 0

#Check for fallocate and hole punch support
require_fallocate -l 1m $M0/file
require_fallocate -p -l 512k $M0/file && rm -f $M0/file

#Write some data, punch a hole and verify the file content changes
TEST dd if=/dev/urandom of=$M0/file bs=1024k count=1
TEST cp $M0/file $M0/file.copy.pre
TEST fallocate -p -o 512k -l 128k $M0/file
TEST ! cmp $M0/file.copy.pre $M0/file
TEST rm -f $M0/file $M0/file.copy.pre

#Allocate some blocks, punch a hole and verify block allocation
TEST fallocate -l 1m $M0/file
blksz=`stat -c %B $M0/file`
nblks=`stat -c %b $M0/file`
TEST [ $(($blksz * $nblks)) -ge 1048576 ]
TEST fallocate -p -o 512k -l 128k $M0/file
nblks=`stat -c %b $M0/file`
TEST [ $(($blksz * $nblks)) -lt $((933889)) ]
TEST unlink $M0/file

###Punch hole test cases without fallocate
##With write
#Touching starting boundary
TEST dd if=/dev/urandom of=$B0/test_file bs=1024 count=8
TEST cp $B0/test_file $M0/test_file
TEST fallocate -p -o 0 -l 500 $B0/test_file
TEST fallocate -p -o 0 -l 500 $M0/test_file
TEST md5_sum=`get_md5_sum $B0/test_file`
EXPECT $md5_sum get_md5_sum $M0/test_file
TEST rm -f $B0/test_file $M0/test_file

#Touching boundary
TEST dd if=/dev/urandom of=$B0/test_file bs=1024 count=8
TEST cp $B0/test_file $M0/test_file
TEST fallocate -p -o 500 -l 1548 $B0/test_file
TEST fallocate -p -o 500 -l 1548 $M0/test_file
TEST md5_sum=`get_md5_sum $B0/test_file`
EXPECT $md5_sum get_md5_sum $M0/test_file
TEST rm -f $B0/test_file $M0/test_file

#Not touching boundary
TEST dd if=/dev/urandom of=$B0/test_file bs=1024 count=8
TEST cp $B0/test_file $M0/test_file
TEST fallocate -p -o 500 -l 1000 $B0/test_file
TEST fallocate -p -o 500 -l 1000 $M0/test_file
TEST md5_sum=`get_md5_sum $B0/test_file`
EXPECT $md5_sum get_md5_sum $M0/test_file
TEST rm -f $B0/test_file $M0/test_file

#Over boundary
TEST dd if=/dev/urandom of=$B0/test_file bs=1024 count=8
TEST cp $B0/test_file $M0/test_file
TEST fallocate -p -o 1500 -l 1000 $B0/test_file
TEST fallocate -p -o 1500 -l 1000 $M0/test_file
TEST md5_sum=`get_md5_sum $B0/test_file`
EXPECT $md5_sum get_md5_sum $M0/test_file
TEST rm -f $B0/test_file $M0/test_file

###Punch hole test cases with fallocate
##Without write

#Zero size
TEST dd if=/dev/urandom of=$M0/test_file bs=1024 count=8
TEST ! fallocate -p -o 1500 -l 0 $M0/test_file

#Negative size
TEST ! fallocate -p -o 1500 -l -100 $M0/test_file
TEST rm -f $M0/test_file

#Touching boundary
TEST dd if=/dev/urandom of=$B0/test_file bs=1024 count=8
TEST cp $B0/test_file $M0/test_file
TEST fallocate -p -o 2048 -l 2048 $B0/test_file
TEST fallocate -p -o 2048 -l 2048 $M0/test_file
TEST md5_sum=`get_md5_sum $B0/test_file`
EXPECT $md5_sum get_md5_sum $M0/test_file
TEST rm -f $B0/test_file $M0/test_file

#Touching boundary,multiple stripe
TEST dd if=/dev/urandom of=$B0/test_file bs=1024 count=8
TEST cp $B0/test_file $M0/test_file
TEST fallocate -p -o 2048 -l 4096 $B0/test_file
TEST fallocate -p -o 2048 -l 4096 $M0/test_file
TEST md5_sum=`get_md5_sum $B0/test_file`
EXPECT $md5_sum get_md5_sum $M0/test_file
TEST rm -f $B0/test_file $M0/test_file

##With write

#Size ends in boundary
TEST dd if=/dev/urandom of=$B0/test_file bs=1024 count=8
TEST cp $B0/test_file $M0/test_file
TEST fallocate -p -o 600 -l 3496 $B0/test_file
TEST fallocate -p -o 600 -l 3496 $M0/test_file
TEST md5_sum=`get_md5_sum $B0/test_file`
EXPECT $md5_sum get_md5_sum $M0/test_file
TEST rm -f $B0/test_file $M0/test_file

#Offset at boundary
TEST dd if=/dev/urandom of=$B0/test_file bs=1024 count=8
TEST cp $B0/test_file $M0/test_file
TEST fallocate -p -o 2048 -l 3072 $B0/test_file
TEST fallocate -p -o 2048 -l 3072 $M0/test_file
TEST md5_sum=`get_md5_sum $B0/test_file`
EXPECT $md5_sum get_md5_sum $M0/test_file
TEST rm -f $B0/test_file $M0/test_file

#Offset and Size not at boundary
TEST dd if=/dev/urandom of=$B0/test_file bs=1024 count=8
TEST cp $B0/test_file $M0/test_file
TEST fallocate -p -o 1000 -l 3072 $B0/test_file
TEST fallocate -p -o 1000 -l 3072 $M0/test_file
TEST md5_sum=`get_md5_sum $B0/test_file`
EXPECT $md5_sum get_md5_sum $M0/test_file
#TEST rm -f $B0/test_file $M0/test_file

#Data Corruption Tests
#Kill brick1 and brick2
TEST kill_brick $V0 $H0 $B0/${V0}0
TEST kill_brick $V0 $H0 $B0/${V0}1
EXPECT_WITHIN $CHILD_UP_TIMEOUT "4" ec_child_up_count $V0 0

#Unmount and mount
EXPECT_WITHIN $UMOUNT_TIMEOUT "Y" force_umount $M0;
TEST $GFS --volfile-id=/$V0 --volfile-server=$H0 $M0;
EXPECT_WITHIN $CHILD_UP_TIMEOUT "4" ec_child_up_count $V0 0

#verify md5 sum
EXPECT $md5_sum get_md5_sum $M0/test_file

#Bring up the bricks
TEST $CLI volume start $V0 force
EXPECT_WITHIN $CHILD_UP_TIMEOUT "6" ec_child_up_count $V0 0

#Kill brick3 and brick4
TEST kill_brick $V0 $H0 $B0/${V0}2
TEST kill_brick $V0 $H0 $B0/${V0}3
EXPECT_WITHIN $CHILD_UP_TIMEOUT "4" ec_child_up_count $V0 0

#Unmount and mount
EXPECT_WITHIN $UMOUNT_TIMEOUT "Y" force_umount $M0;
TEST $GFS --volfile-id=/$V0 --volfile-server=$H0 $M0;
EXPECT_WITHIN $CHILD_UP_TIMEOUT "4" ec_child_up_count $V0 0

#verify md5 sum
EXPECT $md5_sum get_md5_sum $M0/test_file

#Bring up the bricks
TEST $CLI volume start $V0 force
EXPECT_WITHIN $CHILD_UP_TIMEOUT "6" ec_child_up_count $V0 0

#Kill brick5 and brick6
TEST kill_brick $V0 $H0 $B0/${V0}4
TEST kill_brick $V0 $H0 $B0/${V0}5
EXPECT_WITHIN $CHILD_UP_TIMEOUT "4" ec_child_up_count $V0 0

#Unmount and mount
EXPECT_WITHIN $UMOUNT_TIMEOUT "Y" force_umount $M0;
TEST $GFS --volfile-id=/$V0 --volfile-server=$H0 $M0;
EXPECT_WITHIN $CHILD_UP_TIMEOUT "4" ec_child_up_count $V0 0

#verify md5 sum
EXPECT $md5_sum get_md5_sum $M0/test_file

cleanup