]>
Commit | Line | Data |
---|---|---|
11a82d14 | 1 | #!/usr/bin/env bash |
a2c7e082 HR |
2 | # |
3 | # Test preallocated resize of raw images | |
4 | # | |
5 | # Copyright (C) 2017 Red Hat, Inc. | |
6 | # | |
7 | # This program is free software; you can redistribute it and/or modify | |
8 | # it under the terms of the GNU General Public License as published by | |
9 | # the Free Software Foundation; either version 2 of the License, or | |
10 | # (at your option) any later version. | |
11 | # | |
12 | # This program is distributed in the hope that it will be useful, | |
13 | # but WITHOUT ANY WARRANTY; without even the implied warranty of | |
14 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
15 | # GNU General Public License for more details. | |
16 | # | |
17 | # You should have received a copy of the GNU General Public License | |
18 | # along with this program. If not, see <http://www.gnu.org/licenses/>. | |
19 | # | |
20 | ||
21 | # creator | |
22 | [email protected] | |
23 | ||
24 | seq=$(basename $0) | |
25 | echo "QA output created by $seq" | |
26 | ||
a2c7e082 HR |
27 | status=1 # failure is the default! |
28 | ||
29 | _cleanup() | |
30 | { | |
31 | _cleanup_test_img | |
32 | } | |
33 | trap "_cleanup; exit \$status" 0 1 2 3 15 | |
34 | ||
35 | # get standard environment and filters | |
36 | . ./common.rc | |
37 | . ./common.filter | |
38 | ||
39 | _supported_fmt raw | |
40 | _supported_proto file | |
41 | _supported_os Linux | |
42 | ||
43 | # in kB | |
44 | CREATION_SIZE=128 | |
45 | GROWTH_SIZE=256 | |
46 | ||
47 | echo '=== Testing image growth ===' | |
48 | ||
49 | for create_mode in off falloc full; do | |
50 | for growth_mode in off falloc full; do | |
51 | echo | |
52 | echo "--- create_mode=$create_mode growth_mode=$growth_mode ---" | |
53 | ||
54 | IMGOPTS="preallocation=$create_mode" _make_test_img ${CREATION_SIZE}K | |
55 | $QEMU_IMG resize -f "$IMGFMT" --preallocation=$growth_mode "$TEST_IMG" +${GROWTH_SIZE}K | |
56 | ||
57 | expected_size=0 | |
58 | if [ $create_mode != off ]; then | |
59 | expected_size=$CREATION_SIZE | |
60 | fi | |
61 | if [ $growth_mode != off ]; then | |
62 | expected_size=$((expected_size + $GROWTH_SIZE)) | |
63 | fi | |
64 | ||
65 | actual_size=$($QEMU_IMG info -f "$IMGFMT" "$TEST_IMG" | grep 'disk size') | |
66 | actual_size=$(echo "$actual_size" | sed -e 's/^[^0-9]*\([0-9]\+\).*$/\1/') | |
67 | ||
68 | # The actual size may exceed the expected size, depending on the file | |
69 | # system. Therefore we just test that the actual size is at least what | |
70 | # we expect. | |
71 | if [ $actual_size -lt $expected_size ]; then | |
72 | echo "ERROR: Image should have at least ${expected_size}K, but has ${actual_size}K" | |
73 | fi | |
74 | done | |
75 | done | |
76 | ||
77 | echo | |
78 | echo '=== Testing image shrinking ===' | |
79 | ||
80 | # None of this should work except for "off", because other modes cannot be used | |
81 | # for shrinking | |
82 | for growth_mode in falloc full off; do | |
83 | echo | |
84 | echo "--- growth_mode=$growth_mode ---" | |
4ffca890 | 85 | $QEMU_IMG resize -f "$IMGFMT" --shrink --preallocation=$growth_mode "$TEST_IMG" -${GROWTH_SIZE}K |
a2c7e082 HR |
86 | done |
87 | ||
733d1dce HR |
88 | echo |
89 | echo '=== Testing image growth on 2G empty image ===' | |
90 | ||
91 | for growth_mode in falloc full; do | |
92 | echo | |
93 | echo "--- growth_mode=$growth_mode ---" | |
94 | ||
95 | # Maybe we want to do an lseek() to the end of the file before the | |
96 | # preallocation; if the file has a length of 2 GB, that would | |
97 | # return an integer that overflows to negative when put into a | |
98 | # plain int. We should use the correct type for the result, and | |
99 | # this tests we do. | |
100 | ||
101 | _make_test_img 2G | |
102 | $QEMU_IMG resize -f "$IMGFMT" --preallocation=$growth_mode "$TEST_IMG" +${GROWTH_SIZE}K | |
103 | ||
104 | actual_size=$($QEMU_IMG info -f "$IMGFMT" "$TEST_IMG" | grep 'disk size') | |
105 | actual_size=$(echo "$actual_size" | sed -e 's/^[^0-9]*\([0-9]\+\).*$/\1/') | |
106 | ||
107 | if [ $actual_size -lt $GROWTH_SIZE ]; then | |
108 | echo "ERROR: Image should have at least ${GROWTH_SIZE}K, but has ${actual_size}K" | |
109 | fi | |
110 | done | |
111 | ||
a2c7e082 HR |
112 | # success, all done |
113 | echo '*** done' | |
114 | rm -f $seq.full | |
115 | status=0 |