]> git.proxmox.com Git - mirror_qemu.git/blob - tests/qemu-iotests/108
nbd-server: Call blk_set_allow_aio_context_change()
[mirror_qemu.git] / tests / qemu-iotests / 108
1 #!/usr/bin/env bash
2 #
3 # Test case for repairing qcow2 images which cannot be repaired using
4 # the on-disk refcount structures
5 #
6 # Copyright (C) 2014 Red Hat, Inc.
7 #
8 # This program is free software; you can redistribute it and/or modify
9 # it under the terms of the GNU General Public License as published by
10 # the Free Software Foundation; either version 2 of the License, or
11 # (at your option) any later version.
12 #
13 # This program is distributed in the hope that it will be useful,
14 # but WITHOUT ANY WARRANTY; without even the implied warranty of
15 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 # GNU General Public License for more details.
17 #
18 # You should have received a copy of the GNU General Public License
19 # along with this program. If not, see <http://www.gnu.org/licenses/>.
20 #
21
22 # creator
23 owner=mreitz@redhat.com
24
25 seq="$(basename $0)"
26 echo "QA output created by $seq"
27
28 status=1 # failure is the default!
29
30 _cleanup()
31 {
32 _cleanup_test_img
33 }
34 trap "_cleanup; exit \$status" 0 1 2 3 15
35
36 # get standard environment, filters and checks
37 . ./common.rc
38 . ./common.filter
39
40 # This tests qocw2-specific low-level functionality
41 _supported_fmt qcow2
42 _supported_proto file
43 _supported_os Linux
44 # This test directly modifies a refblock so it relies on refcount_bits being 16
45 _unsupported_imgopts 'refcount_bits=\([^1]\|.\([^6]\|$\)\)'
46
47 echo
48 echo '=== Repairing an image without any refcount table ==='
49 echo
50
51 _make_test_img 64M
52 # just write some data
53 $QEMU_IO -c 'write -P 42 0 64k' "$TEST_IMG" | _filter_qemu_io
54
55 # refcount_table_offset
56 poke_file "$TEST_IMG" $((0x30)) "\x00\x00\x00\x00\x00\x00\x00\x00"
57 # refcount_table_clusters
58 poke_file "$TEST_IMG" $((0x38)) "\x00\x00\x00\x00"
59
60 _check_test_img -r all
61
62 $QEMU_IO -c 'read -P 42 0 64k' "$TEST_IMG" | _filter_qemu_io
63
64 echo
65 echo '=== Repairing unreferenced data cluster in new refblock area ==='
66 echo
67
68 IMGOPTS='cluster_size=512' _make_test_img 64M
69 # Allocate the first 128 kB in the image (first refblock)
70 $QEMU_IO -c 'write 0 0x1b200' "$TEST_IMG" | _filter_qemu_io
71 # should be 131072 == 0x20000
72 stat -c '%s' "$TEST_IMG"
73
74 # Enter a cluster at 128 kB (0x20000)
75 # XXX: This should be the first free entry in the last L2 table, but we cannot
76 # be certain
77 poke_file "$TEST_IMG" $((0x1ccc8)) "\x80\x00\x00\x00\x00\x02\x00\x00"
78
79 # Fill the cluster
80 truncate -s $((0x20200)) "$TEST_IMG"
81 $QEMU_IO -c "open -o driver=raw $TEST_IMG" -c 'write -P 42 128k 512' \
82 | _filter_qemu_io
83
84 # The data should now appear at this guest offset
85 $QEMU_IO -c 'read -P 42 0x1b200 512' "$TEST_IMG" | _filter_qemu_io
86
87 # This cluster is unallocated; fix it
88 _check_test_img -r all
89
90 # This repair operation must have allocated a new refblock; and that refblock
91 # should not overlap with the unallocated data cluster. If it does, the data
92 # will be damaged, so check it.
93 $QEMU_IO -c 'read -P 42 0x1b200 512' "$TEST_IMG" | _filter_qemu_io
94
95 echo
96 echo '=== Repairing refblock beyond the image end ==='
97 echo
98
99 echo
100 echo '--- Otherwise clean ---'
101 echo
102
103 _make_test_img 64M
104 # Normally, qemu doesn't create empty refblocks, so we just have to do it by
105 # hand
106 # XXX: This should be the entry for the second refblock
107 poke_file "$TEST_IMG" $((0x10008)) "\x00\x00\x00\x00\x00\x10\x00\x00"
108 # Mark that refblock as used
109 # XXX: This should be the 17th entry (cluster 16) of the first
110 # refblock
111 poke_file "$TEST_IMG" $((0x20020)) "\x00\x01"
112 _check_test_img -r all
113
114 echo
115 echo '--- Refblock is unallocated ---'
116 echo
117
118 _make_test_img 64M
119 poke_file "$TEST_IMG" $((0x10008)) "\x00\x00\x00\x00\x00\x10\x00\x00"
120 _check_test_img -r all
121
122 echo
123 echo '--- Signed overflow after the refblock ---'
124 echo
125
126 _make_test_img 64M
127 poke_file "$TEST_IMG" $((0x10008)) "\x7f\xff\xff\xff\xff\xff\x00\x00"
128 _check_test_img -r all
129
130 echo
131 echo '--- Unsigned overflow after the refblock ---'
132 echo
133
134 _make_test_img 64M
135 poke_file "$TEST_IMG" $((0x10008)) "\xff\xff\xff\xff\xff\xff\x00\x00"
136 _check_test_img -r all
137
138 # success, all done
139 echo '*** done'
140 rm -f $seq.full
141 status=0