| 1 | #!/usr/bin/env bash |
| 2 | # group: rw backing quick |
| 3 | # |
| 4 | # Test that backing files can be smaller than the image |
| 5 | # |
| 6 | # Copyright (C) 2010 IBM, Corp. |
| 7 | # |
| 8 | # Based on 017: |
| 9 | # Copyright (C) 2009 Red Hat, Inc. |
| 10 | # |
| 11 | # This program is free software; you can redistribute it and/or modify |
| 12 | # it under the terms of the GNU General Public License as published by |
| 13 | # the Free Software Foundation; either version 2 of the License, or |
| 14 | # (at your option) any later version. |
| 15 | # |
| 16 | # This program is distributed in the hope that it will be useful, |
| 17 | # but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 18 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 19 | # GNU General Public License for more details. |
| 20 | # |
| 21 | # You should have received a copy of the GNU General Public License |
| 22 | # along with this program. If not, see <http://www.gnu.org/licenses/>. |
| 23 | # |
| 24 | |
| 25 | # creator |
| 26 | owner=stefanha@redhat.com |
| 27 | |
| 28 | seq=`basename $0` |
| 29 | echo "QA output created by $seq" |
| 30 | |
| 31 | status=1 # failure is the default! |
| 32 | |
| 33 | _cleanup() |
| 34 | { |
| 35 | _cleanup_qemu |
| 36 | _rm_test_img "${TEST_IMG}.copy" |
| 37 | _cleanup_test_img |
| 38 | } |
| 39 | trap "_cleanup; exit \$status" 0 1 2 3 15 |
| 40 | |
| 41 | # get standard environment, filters and checks |
| 42 | . ./common.rc |
| 43 | . ./common.filter |
| 44 | . ./common.pattern |
| 45 | . ./common.qemu |
| 46 | |
| 47 | # Any format supporting backing files except vmdk and qcow which do not support |
| 48 | # smaller backing files. |
| 49 | _supported_fmt qcow2 qed |
| 50 | _supported_proto file fuse |
| 51 | _supported_os Linux |
| 52 | _require_hmp |
| 53 | |
| 54 | # Choose a size that is not necessarily a cluster size multiple for image |
| 55 | # formats that use clusters. This will ensure that the base image doesn't end |
| 56 | # precisely on a cluster boundary (the easy case). |
| 57 | image_size=$(( 4 * 1024 * 1024 * 1024 + 3 * 512 )) |
| 58 | |
| 59 | # The base image is smaller than the image file |
| 60 | base_size=$(( image_size - 1024 * 1024 * 1024 )) |
| 61 | |
| 62 | offset=$(( base_size - 32 * 1024 )) |
| 63 | |
| 64 | TEST_IMG_SAVE="$TEST_IMG" |
| 65 | TEST_IMG="$TEST_IMG.base" |
| 66 | |
| 67 | _make_test_img $base_size |
| 68 | |
| 69 | echo "Filling base image" |
| 70 | echo |
| 71 | |
| 72 | # Fill end of base image with a pattern, skipping every other sector |
| 73 | io writev $offset 512 1024 32 |
| 74 | |
| 75 | _check_test_img |
| 76 | |
| 77 | echo "Creating test image with backing file" |
| 78 | echo |
| 79 | |
| 80 | TEST_IMG="$TEST_IMG_SAVE" |
| 81 | _make_test_img -b "$TEST_IMG.base" -F $IMGFMT $image_size |
| 82 | |
| 83 | echo "Filling test image" |
| 84 | echo |
| 85 | |
| 86 | # Write every other sector around where the base image ends |
| 87 | io writev $(( offset + 512 )) 512 1024 64 |
| 88 | |
| 89 | _check_test_img |
| 90 | |
| 91 | echo "Reading" |
| 92 | echo |
| 93 | |
| 94 | # Base image sectors |
| 95 | io readv $(( offset )) 512 1024 32 |
| 96 | |
| 97 | # Image sectors |
| 98 | io readv $(( offset + 512 )) 512 1024 64 |
| 99 | |
| 100 | # Zero sectors beyond end of base image |
| 101 | io_zero readv $(( offset + 32 * 1024 )) 512 1024 32 |
| 102 | |
| 103 | _check_test_img |
| 104 | |
| 105 | # Rebase it on top of its base image |
| 106 | $QEMU_IMG rebase -b "$TEST_IMG.base" -F $IMGFMT "$TEST_IMG" |
| 107 | |
| 108 | echo |
| 109 | echo block-backup |
| 110 | echo |
| 111 | |
| 112 | qemu_comm_method="monitor" |
| 113 | _launch_qemu -drive file="${TEST_IMG}",cache=${CACHEMODE},aio=${AIOMODE},id=disk |
| 114 | h=$QEMU_HANDLE |
| 115 | if [ "${VALGRIND_QEMU}" == "y" ]; then |
| 116 | QEMU_COMM_TIMEOUT=7 |
| 117 | else |
| 118 | QEMU_COMM_TIMEOUT=1 |
| 119 | fi |
| 120 | |
| 121 | TEST_IMG="$TEST_IMG.copy" _make_test_img $image_size |
| 122 | _send_qemu_cmd $h "drive_backup -n disk ${TEST_IMG}.copy" "(qemu)" \ |
| 123 | | _filter_imgfmt |
| 124 | |
| 125 | silent=y qemu_cmd_repeat=20 _send_qemu_cmd $h "info block-jobs" "No active jobs" |
| 126 | _send_qemu_cmd $h "info block-jobs" "No active jobs" |
| 127 | _send_qemu_cmd $h 'quit' "" |
| 128 | |
| 129 | # Base image sectors |
| 130 | TEST_IMG="${TEST_IMG}.copy" io readv $(( offset )) 512 1024 32 |
| 131 | |
| 132 | # Image sectors |
| 133 | TEST_IMG="${TEST_IMG}.copy" io readv $(( offset + 512 )) 512 1024 64 |
| 134 | |
| 135 | # Zero sectors beyond end of base image |
| 136 | TEST_IMG="${TEST_IMG}.copy" io_zero readv $(( offset + 32 * 1024 )) 512 1024 32 |
| 137 | |
| 138 | |
| 139 | _check_test_img |
| 140 | |
| 141 | echo |
| 142 | echo '=== Reading across backing EOF in one operation ===' |
| 143 | echo |
| 144 | |
| 145 | # Use a cluster boundary as the base end here |
| 146 | base_size=$((3 * 1024 * 1024 * 1024)) |
| 147 | |
| 148 | TEST_IMG="$TEST_IMG.base" _make_test_img $base_size |
| 149 | _make_test_img -b "$TEST_IMG.base" -F $IMGFMT $image_size |
| 150 | |
| 151 | # Write 16 times 42 at the end of the base image |
| 152 | $QEMU_IO -c "write -P 42 $((base_size - 16)) 16" "$TEST_IMG.base" \ |
| 153 | | _filter_qemu_io |
| 154 | |
| 155 | # Read 32 bytes across the base EOF from the top; |
| 156 | # should be 16 times 0x2a, then 16 times 0x00 |
| 157 | $QEMU_IO -c "read -v $((base_size - 16)) 32" "$TEST_IMG" \ |
| 158 | | _filter_qemu_io |
| 159 | |
| 160 | # success, all done |
| 161 | echo "*** done" |
| 162 | rm -f $seq.full |
| 163 | status=0 |