Philippe Mathieu-Daudé | 11a82d1 | 2019-03-07 15:58:38 +0100 | [diff] [blame] | 1 | #!/usr/bin/env bash |
Vladimir Sementsov-Ogievskiy | 9dd003a | 2021-01-16 16:44:19 +0300 | [diff] [blame] | 2 | # group: rw auto backing quick |
Kevin Wolf | 0446919 | 2012-06-13 17:15:14 +0200 | [diff] [blame] | 3 | # |
| 4 | # Test COW from backing files with AIO |
| 5 | # |
| 6 | # Copyright (C) 2012 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=kwolf@redhat.com |
| 24 | |
| 25 | seq=`basename $0` |
| 26 | echo "QA output created by $seq" |
| 27 | |
Kevin Wolf | 0446919 | 2012-06-13 17:15:14 +0200 | [diff] [blame] | 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 | _supported_fmt qcow2 qed |
Max Reitz | 57284d2 | 2020-10-27 20:05:59 +0100 | [diff] [blame] | 41 | _supported_proto file fuse |
Kevin Wolf | 0446919 | 2012-06-13 17:15:14 +0200 | [diff] [blame] | 42 | _supported_os Linux |
| 43 | |
| 44 | CLUSTER_SIZE=2M |
| 45 | size=128M |
| 46 | |
| 47 | echo |
| 48 | echo "== creating backing file for COW tests ==" |
| 49 | |
Fam Zheng | 1b935e1 | 2015-12-22 10:49:18 +0800 | [diff] [blame] | 50 | TEST_IMG_SAVE="$TEST_IMG" |
| 51 | TEST_IMG="$TEST_IMG.base" |
| 52 | |
Kevin Wolf | 0446919 | 2012-06-13 17:15:14 +0200 | [diff] [blame] | 53 | _make_test_img $size |
| 54 | |
Eric Blake | 8cedcff | 2018-11-16 15:50:02 -0600 | [diff] [blame] | 55 | backing_io() |
Kevin Wolf | 0446919 | 2012-06-13 17:15:14 +0200 | [diff] [blame] | 56 | { |
| 57 | local offset=$1 |
| 58 | local sectors=$2 |
| 59 | local op=$3 |
| 60 | local pattern=0 |
| 61 | local cur_sec=0 |
| 62 | |
| 63 | for i in $(seq 0 $((sectors - 1))); do |
| 64 | cur_sec=$((offset / 65536 + i)) |
| 65 | pattern=$(( ( (cur_sec % 128) + (cur_sec / 128)) % 128 )) |
| 66 | |
| 67 | echo "$op -P $pattern $((cur_sec * 64))k 64k" |
| 68 | done |
| 69 | } |
| 70 | |
Jeff Cody | fef9c19 | 2013-09-25 08:12:22 -0400 | [diff] [blame] | 71 | backing_io 0 256 write | $QEMU_IO "$TEST_IMG" | _filter_qemu_io |
Kevin Wolf | 0446919 | 2012-06-13 17:15:14 +0200 | [diff] [blame] | 72 | |
Fam Zheng | 1b935e1 | 2015-12-22 10:49:18 +0800 | [diff] [blame] | 73 | TEST_IMG="$TEST_IMG_SAVE" |
Kevin Wolf | 0446919 | 2012-06-13 17:15:14 +0200 | [diff] [blame] | 74 | |
Eric Blake | b66ff2c | 2020-07-06 15:39:52 -0500 | [diff] [blame] | 75 | _make_test_img -b "$TEST_IMG.base" -F $IMGFMT 6G |
Kevin Wolf | 0446919 | 2012-06-13 17:15:14 +0200 | [diff] [blame] | 76 | |
| 77 | echo |
| 78 | echo "== Some concurrent requests touching the same cluster ==" |
| 79 | |
Eric Blake | 8cedcff | 2018-11-16 15:50:02 -0600 | [diff] [blame] | 80 | overlay_io() |
Kevin Wolf | 0446919 | 2012-06-13 17:15:14 +0200 | [diff] [blame] | 81 | { |
| 82 | # Start with a request touching two clusters |
| 83 | echo aio_write -P 0x80 2020k 80k |
| 84 | |
| 85 | # Then add some requests all over the place |
| 86 | for i in $(seq 0 15; seq 17 31; seq 33 47); do |
| 87 | echo aio_write -P $((0x81 + i)) $((i * 128))k 64k |
| 88 | done |
| 89 | |
| 90 | # Then backwards overwriting part of them |
| 91 | for i in $( (seq 0 15; seq 17 31; seq 33 47) | tac); do |
| 92 | echo aio_write -P $((0x81 + i)) $((i * 128 + 32))k 64k |
| 93 | done |
| 94 | |
| 95 | # And finally crossing the next cluster boundary |
| 96 | echo aio_write -P 0x90 4080k 80k |
| 97 | } |
| 98 | |
Jeff Cody | fef9c19 | 2013-09-25 08:12:22 -0400 | [diff] [blame] | 99 | overlay_io | $QEMU_IO "$TEST_IMG" | _filter_qemu_io |\ |
Max Reitz | c21bddf | 2013-09-13 10:37:12 +0200 | [diff] [blame] | 100 | sed -e 's/bytes at offset [0-9]*/bytes at offset XXX/g' \ |
| 101 | -e 's/qemu-io> //g' | paste - - | sort | tr '\t' '\n' |
Kevin Wolf | 0446919 | 2012-06-13 17:15:14 +0200 | [diff] [blame] | 102 | |
| 103 | echo |
| 104 | echo "== Verify image content ==" |
| 105 | |
Eric Blake | 8cedcff | 2018-11-16 15:50:02 -0600 | [diff] [blame] | 106 | verify_io() |
Kevin Wolf | 0446919 | 2012-06-13 17:15:14 +0200 | [diff] [blame] | 107 | { |
| 108 | echo read -P 31 2016k 4k |
| 109 | echo read -P 0x80 2020k 80k |
| 110 | echo read -P 32 2100k 12k |
| 111 | echo read -P 33 2112k 64k |
| 112 | |
| 113 | echo read -P 63 4064k 16k |
| 114 | echo read -P 0x90 4080k 80k |
| 115 | echo read -P 65 4160k 64k |
| 116 | |
| 117 | for i in $(seq 0 15; seq 17 31; seq 33 47); do |
| 118 | echo read -P $((0x81 + i)) $((i * 128))k 96k |
| 119 | done |
| 120 | |
| 121 | for i in $(seq 0 14; seq 16 30; seq 32 47); do |
| 122 | local cur_sec=$(( i * 2 + 1 )) |
| 123 | local pattern=$(( ( (cur_sec % 128) + (cur_sec / 128)) % 128 )) |
| 124 | |
| 125 | echo read -P $pattern $((i * 128 + 96))k 32k |
| 126 | done |
| 127 | } |
| 128 | |
Jeff Cody | fef9c19 | 2013-09-25 08:12:22 -0400 | [diff] [blame] | 129 | verify_io | $QEMU_IO "$TEST_IMG" | _filter_qemu_io |
Kevin Wolf | 0446919 | 2012-06-13 17:15:14 +0200 | [diff] [blame] | 130 | |
| 131 | _check_test_img |
| 132 | |
| 133 | # success, all done |
| 134 | echo "*** done" |
| 135 | rm -f $seq.full |
| 136 | status=0 |