]> git.ipfire.org Git - thirdparty/mdadm.git/blob - tests/21raid5cache
mdadm: add test case for raid5 write back cache
[thirdparty/mdadm.git] / tests / 21raid5cache
1 # check data integrity with raid5 write back cache
2
3 # create a 4kB random file and 4 files each with a 1kB chunk of the random file:
4 # randfile: ABCD randchunk[0-3]: A B C D
5 #
6 # then create another random 1kB chunk E, and a new random page with A, B, E, D:
7 # randchunk4: E newrandfile: ABED
8 create_random_data() {
9 dd if=/dev/urandom of=/tmp/randfile bs=4k count=1
10 for x in {0..3}
11 do
12 dd if=/tmp/randfile of=/tmp/randchunk$x bs=1k count=1 skip=$x count=1
13 done
14
15 dd if=/dev/urandom of=/tmp/randchunk4 bs=1k count=1
16
17 rm /tmp/newrandfile
18 for x in 0 1 4 3
19 do
20 cat /tmp/randchunk$x >> /tmp/newrandfile
21 done
22 }
23
24 # create array, $1 could be 5 for raid5 and 6 for raid6
25 create_array() {
26 if [ $1 -lt 5 -o $1 -gt 6 ]
27 then
28 echo wrong array type $1
29 exit 2
30 fi
31
32 mdadm -CR $md0 -c4 -l5 -n10 $dev0 $dev1 $dev2 $dev3 $dev4 $dev5 $dev6 $dev11 $dev8 $dev9 --write-journal $dev10
33 check wait
34 echo write-back > /sys/block/md0/md/journal_mode
35 }
36
37 restart_array_write_back() {
38 mdadm -S $md0
39 mdadm -A $md0 $dev0 $dev1 $dev2 $dev3 $dev4 $dev5 $dev6 $dev11 $dev8 $dev9 $dev10
40 echo write-back > /sys/block/md0/md/journal_mode
41 }
42
43 # compare the first page of md0 with file in $1
44 cmp_first_page() {
45 cmp -n 4096 $1 $md0 || { echo cmp failed ; exit 2 ; }
46 }
47
48 # write 3 pages after the first page of md0
49 write_three_pages() {
50 for x in {1..3}
51 do
52 dd if=/dev/urandom of=$md0 bs=4k count=1 seek=$x count=1
53 done
54 }
55
56 # run_test <array_type:5/6> <degraded_or_not:yes/no>
57 run_test() {
58 create_random_data
59 create_array $1
60
61 if [ $2 == yes ]
62 then
63 mdadm --fail $md0 $dev0
64 fi
65
66 dd if=/tmp/randfile of=$md0 bs=4k count=1
67 restart_array_write_back
68 cmp_first_page /tmp/randfile
69 restart_array_write_back
70 write_three_pages
71 cmp_first_page /tmp/randfile
72
73
74 dd if=/tmp/randchunk4 of=/dev/md0 bs=1k count=1 seek=2
75 restart_array_write_back
76 cmp_first_page /tmp/newrandfile
77 restart_array_write_back
78 write_three_pages
79 cmp_first_page /tmp/newrandfile
80
81 mdadm -S $md0
82 }
83
84 run_test 5 no
85 run_test 5 yes
86 run_test 6 no
87 run_test 6 yes