2019-03-07 15:58:38 +01:00
|
|
|
#!/usr/bin/env bash
|
2021-01-16 14:44:19 +01:00
|
|
|
# group: rw auto aio quick
|
2012-12-06 14:33:00 +01:00
|
|
|
#
|
|
|
|
# Test concurrent cluster allocations
|
|
|
|
#
|
|
|
|
# Copyright (C) 2012 Red Hat, Inc.
|
|
|
|
#
|
|
|
|
# This program is free software; you can redistribute it and/or modify
|
|
|
|
# it under the terms of the GNU General Public License as published by
|
|
|
|
# the Free Software Foundation; either version 2 of the License, or
|
|
|
|
# (at your option) any later version.
|
|
|
|
#
|
|
|
|
# This program is distributed in the hope that it will be useful,
|
|
|
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
# GNU General Public License for more details.
|
|
|
|
#
|
|
|
|
# You should have received a copy of the GNU General Public License
|
|
|
|
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
#
|
|
|
|
|
|
|
|
# creator
|
|
|
|
owner=kwolf@redhat.com
|
|
|
|
|
|
|
|
seq=`basename $0`
|
|
|
|
echo "QA output created by $seq"
|
|
|
|
|
|
|
|
status=1 # failure is the default!
|
|
|
|
|
|
|
|
_cleanup()
|
|
|
|
{
|
|
|
|
_cleanup_test_img
|
|
|
|
}
|
|
|
|
trap "_cleanup; exit \$status" 0 1 2 3 15
|
|
|
|
|
|
|
|
# get standard environment, filters and checks
|
|
|
|
. ./common.rc
|
|
|
|
. ./common.filter
|
|
|
|
|
|
|
|
_supported_fmt qcow2
|
2020-10-27 20:05:59 +01:00
|
|
|
_supported_proto file fuse
|
2019-11-07 17:37:07 +01:00
|
|
|
# data_file does not support compressed clusters
|
|
|
|
_unsupported_imgopts data_file
|
2012-12-06 14:33:00 +01:00
|
|
|
|
|
|
|
CLUSTER_SIZE=64k
|
|
|
|
size=128M
|
|
|
|
|
|
|
|
echo
|
|
|
|
echo "== creating backing file for COW tests =="
|
|
|
|
|
2020-10-27 20:05:50 +01:00
|
|
|
TEST_IMG_SAVE=$TEST_IMG
|
|
|
|
TEST_IMG="$TEST_IMG.base"
|
2012-12-06 14:33:00 +01:00
|
|
|
_make_test_img $size
|
|
|
|
|
2018-11-16 22:50:02 +01:00
|
|
|
backing_io()
|
2012-12-06 14:33:00 +01:00
|
|
|
{
|
|
|
|
local offset=$1
|
|
|
|
local sectors=$2
|
|
|
|
local op=$3
|
|
|
|
local pattern=0
|
|
|
|
local cur_sec=0
|
|
|
|
|
2019-07-23 13:12:01 +02:00
|
|
|
for ((i=0;i<=$((sectors - 1));i++)); do
|
2012-12-06 14:33:00 +01:00
|
|
|
cur_sec=$((offset / 65536 + i))
|
|
|
|
pattern=$(( ( (cur_sec % 128) + (cur_sec / 128)) % 128 ))
|
|
|
|
|
|
|
|
echo "$op -P $pattern $((cur_sec * 64))k 64k"
|
|
|
|
done
|
|
|
|
}
|
|
|
|
|
2013-09-25 14:12:22 +02:00
|
|
|
backing_io 0 32 write | $QEMU_IO "$TEST_IMG" | _filter_qemu_io
|
2012-12-06 14:33:00 +01:00
|
|
|
|
2020-10-27 20:05:50 +01:00
|
|
|
TEST_IMG=$TEST_IMG_SAVE
|
iotests: Specify explicit backing format where sensible
There are many existing qcow2 images that specify a backing file but
no format. This has been the source of CVEs in the past, but has
become more prominent of a problem now that libvirt has switched to
-blockdev. With older -drive, at least the probing was always done by
qemu (so the only risk of a changed format between successive boots of
a guest was if qemu was upgraded and probed differently). But with
newer -blockdev, libvirt must specify a format; if libvirt guesses raw
where the image was formatted, this results in data corruption visible
to the guest; conversely, if libvirt guesses qcow2 where qemu was
using raw, this can result in potential security holes, so modern
libvirt instead refuses to use images without explicit backing format.
The change in libvirt to reject images without explicit backing format
has pointed out that a number of tools have been far too reliant on
probing in the past. It's time to set a better example in our own
iotests of properly setting this parameter.
iotest calls to create, rebase, and convert are all impacted to some
degree. It's a bit annoying that we are inconsistent on command line
- while all of those accept -o backing_file=...,backing_fmt=..., the
shortcuts are different: create and rebase have -b and -F, while
convert has -B but no -F. (amend has no shortcuts, but the previous
patch just deprecated the use of amend to change backing chains).
Signed-off-by: Eric Blake <eblake@redhat.com>
Message-Id: <20200706203954.341758-9-eblake@redhat.com>
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
2020-07-06 22:39:52 +02:00
|
|
|
_make_test_img -b "$TEST_IMG.base" -F $IMGFMT 6G
|
2012-12-06 14:33:00 +01:00
|
|
|
|
|
|
|
echo
|
|
|
|
echo "== Some concurrent requests touching the same cluster =="
|
|
|
|
|
2018-11-16 22:50:02 +01:00
|
|
|
overlay_io()
|
2012-12-06 14:33:00 +01:00
|
|
|
{
|
|
|
|
# Allocate middle of cluster 1, then write to somewhere before and after it
|
|
|
|
cat <<EOF
|
|
|
|
break write_aio A
|
|
|
|
aio_write -P 10 0x18000 0x2000
|
|
|
|
wait_break A
|
|
|
|
|
|
|
|
aio_write -P 11 0x12000 0x2000
|
|
|
|
aio_write -P 12 0x1c000 0x2000
|
|
|
|
|
|
|
|
resume A
|
|
|
|
aio_flush
|
|
|
|
EOF
|
|
|
|
|
|
|
|
# Sequential write case: Alloc middle of cluster 2, then write overlapping
|
|
|
|
# to next cluster
|
|
|
|
cat <<EOF
|
|
|
|
break write_aio A
|
|
|
|
aio_write -P 20 0x28000 0x2000
|
|
|
|
wait_break A
|
|
|
|
aio_write -P 21 0x2a000 0x10000
|
|
|
|
resume A
|
|
|
|
aio_flush
|
|
|
|
EOF
|
|
|
|
|
|
|
|
# The same with a gap between both requests
|
|
|
|
cat <<EOF
|
|
|
|
break write_aio A
|
|
|
|
aio_write -P 40 0x48000 0x2000
|
|
|
|
wait_break A
|
|
|
|
aio_write -P 41 0x4c000 0x10000
|
|
|
|
resume A
|
|
|
|
aio_flush
|
|
|
|
EOF
|
|
|
|
|
|
|
|
# Sequential write, but the next cluster is already allocated
|
|
|
|
cat <<EOF
|
|
|
|
write -P 70 0x76000 0x8000
|
|
|
|
aio_flush
|
|
|
|
break write_aio A
|
|
|
|
aio_write -P 60 0x66000 0x2000
|
|
|
|
wait_break A
|
|
|
|
aio_write -P 61 0x6a000 0xe000
|
|
|
|
resume A
|
|
|
|
aio_flush
|
|
|
|
EOF
|
|
|
|
|
|
|
|
# Sequential write, but the next cluster is already allocated
|
|
|
|
# and phyiscally in the right position
|
|
|
|
cat <<EOF
|
|
|
|
write -P 89 0x80000 0x1000
|
|
|
|
write -P 90 0x96000 0x8000
|
|
|
|
aio_flush
|
|
|
|
discard 0x80000 0x10000
|
|
|
|
aio_flush
|
|
|
|
break write_aio A
|
|
|
|
aio_write -P 80 0x86000 0x2000
|
|
|
|
wait_break A
|
|
|
|
aio_write -P 81 0x8a000 0xe000
|
|
|
|
resume A
|
|
|
|
aio_flush
|
|
|
|
EOF
|
|
|
|
|
|
|
|
# Sequential write, and the next cluster is compressed
|
|
|
|
cat <<EOF
|
|
|
|
write -P 109 0xa0000 0x1000
|
|
|
|
write -c -P 110 0xb0000 0x10000
|
|
|
|
aio_flush
|
|
|
|
discard 0xa0000 0x10000
|
|
|
|
aio_flush
|
|
|
|
break write_aio A
|
|
|
|
aio_write -P 100 0xa6000 0x2000
|
|
|
|
wait_break A
|
|
|
|
aio_write -P 101 0xaa000 0xe000
|
|
|
|
resume A
|
|
|
|
aio_flush
|
|
|
|
EOF
|
2013-03-26 17:49:53 +01:00
|
|
|
|
|
|
|
# Reverse sequential write
|
|
|
|
cat <<EOF
|
|
|
|
break write_aio A
|
|
|
|
aio_write -P 121 0xdc000 0x2000
|
|
|
|
wait_break A
|
|
|
|
aio_write -P 120 0xc4000 0x18000
|
|
|
|
resume A
|
|
|
|
aio_flush
|
|
|
|
EOF
|
|
|
|
|
|
|
|
# Reverse sequential write with a gap
|
|
|
|
cat <<EOF
|
|
|
|
break write_aio A
|
|
|
|
aio_write -P 141 0xfc000 0x2000
|
|
|
|
wait_break A
|
|
|
|
aio_write -P 140 0xe4000 0x14000
|
|
|
|
resume A
|
|
|
|
aio_flush
|
|
|
|
EOF
|
|
|
|
|
|
|
|
# Allocate an area in the middle and then overwrite with a larger request
|
|
|
|
cat <<EOF
|
|
|
|
break write_aio A
|
|
|
|
aio_write -P 161 0x10c000 0x8000
|
|
|
|
wait_break A
|
|
|
|
aio_write -P 160 0x104000 0x18000
|
|
|
|
resume A
|
|
|
|
aio_flush
|
|
|
|
EOF
|
2012-12-06 14:33:00 +01:00
|
|
|
}
|
|
|
|
|
2013-09-25 14:12:22 +02:00
|
|
|
overlay_io | $QEMU_IO blkdebug::"$TEST_IMG" | _filter_qemu_io |\
|
2020-09-18 17:33:23 +02:00
|
|
|
sed -e 's/[0-9]*\/[0-9]* bytes at offset [0-9]*/XXX\/XXX bytes at offset XXX/g' \
|
|
|
|
-e 's/^[0-9]* KiB/XXX KiB/g'
|
2012-12-06 14:33:00 +01:00
|
|
|
|
|
|
|
echo
|
|
|
|
echo "== Verify image content =="
|
|
|
|
|
2018-11-16 22:50:02 +01:00
|
|
|
verify_io()
|
2012-12-06 14:33:00 +01:00
|
|
|
{
|
2017-05-02 18:35:43 +02:00
|
|
|
if ($QEMU_IMG info -U -f "$IMGFMT" "$TEST_IMG" | grep "compat: 0.10" > /dev/null); then
|
2020-03-31 13:43:45 +02:00
|
|
|
# In v2 images clusters are not discarded when there is a backing file.
|
|
|
|
# Keep the variable empty so that the previous value can be used as
|
2014-02-08 14:38:33 +01:00
|
|
|
# the default below
|
|
|
|
discarded=
|
|
|
|
else
|
|
|
|
# Discarded clusters are zeroed for v3 or later
|
|
|
|
discarded=0
|
|
|
|
fi
|
|
|
|
|
2012-12-06 14:33:00 +01:00
|
|
|
echo read -P 0 0 0x10000
|
|
|
|
|
|
|
|
echo read -P 1 0x10000 0x2000
|
|
|
|
echo read -P 11 0x12000 0x2000
|
|
|
|
echo read -P 1 0x14000 0x4000
|
|
|
|
echo read -P 10 0x18000 0x2000
|
|
|
|
echo read -P 1 0x1a000 0x2000
|
|
|
|
echo read -P 12 0x1c000 0x2000
|
|
|
|
echo read -P 1 0x1e000 0x2000
|
|
|
|
|
|
|
|
echo read -P 2 0x20000 0x8000
|
|
|
|
echo read -P 20 0x28000 0x2000
|
|
|
|
echo read -P 21 0x2a000 0x10000
|
|
|
|
echo read -P 3 0x3a000 0x6000
|
|
|
|
|
|
|
|
echo read -P 4 0x40000 0x8000
|
|
|
|
echo read -P 40 0x48000 0x2000
|
|
|
|
echo read -P 4 0x4a000 0x2000
|
|
|
|
echo read -P 41 0x4c000 0x10000
|
|
|
|
echo read -P 5 0x5c000 0x4000
|
|
|
|
|
|
|
|
echo read -P 6 0x60000 0x6000
|
|
|
|
echo read -P 60 0x66000 0x2000
|
|
|
|
echo read -P 6 0x68000 0x2000
|
|
|
|
echo read -P 61 0x6a000 0xe000
|
|
|
|
echo read -P 70 0x78000 0x6000
|
|
|
|
echo read -P 7 0x7e000 0x2000
|
|
|
|
|
2020-03-31 13:43:45 +02:00
|
|
|
echo read -P ${discarded:-89} 0x80000 0x1000
|
|
|
|
echo read -P ${discarded:-8} 0x81000 0x5000
|
2012-12-06 14:33:00 +01:00
|
|
|
echo read -P 80 0x86000 0x2000
|
2014-02-08 14:38:33 +01:00
|
|
|
echo read -P ${discarded:-8} 0x88000 0x2000
|
2012-12-06 14:33:00 +01:00
|
|
|
echo read -P 81 0x8a000 0xe000
|
|
|
|
echo read -P 90 0x98000 0x6000
|
|
|
|
echo read -P 9 0x9e000 0x2000
|
|
|
|
|
2020-03-31 13:43:45 +02:00
|
|
|
echo read -P ${discarded:-109} 0xa0000 0x1000
|
|
|
|
echo read -P ${discarded:-10} 0xa1000 0x5000
|
2012-12-06 14:33:00 +01:00
|
|
|
echo read -P 100 0xa6000 0x2000
|
2014-02-08 14:38:33 +01:00
|
|
|
echo read -P ${discarded:-10} 0xa8000 0x2000
|
2012-12-06 14:33:00 +01:00
|
|
|
echo read -P 101 0xaa000 0xe000
|
|
|
|
echo read -P 110 0xb8000 0x8000
|
2013-03-26 17:49:53 +01:00
|
|
|
|
|
|
|
echo read -P 12 0xc0000 0x4000
|
|
|
|
echo read -P 120 0xc4000 0x18000
|
|
|
|
echo read -P 121 0xdc000 0x2000
|
|
|
|
echo read -P 13 0xde000 0x2000
|
|
|
|
|
|
|
|
echo read -P 14 0xe0000 0x4000
|
|
|
|
echo read -P 140 0xe4000 0x14000
|
|
|
|
echo read -P 15 0xf8000 0x4000
|
|
|
|
echo read -P 141 0xfc000 0x2000
|
|
|
|
echo read -P 15 0xfe000 0x2000
|
|
|
|
|
|
|
|
echo read -P 16 0x100000 0x4000
|
|
|
|
echo read -P 160 0x104000 0x8000
|
|
|
|
# Undefined content for 0x10c000 0x8000
|
|
|
|
echo read -P 160 0x114000 0x8000
|
|
|
|
echo read -P 17 0x11c000 0x4000
|
2012-12-06 14:33:00 +01:00
|
|
|
}
|
|
|
|
|
2013-09-25 14:12:22 +02:00
|
|
|
verify_io | $QEMU_IO "$TEST_IMG" | _filter_qemu_io
|
2012-12-06 14:33:00 +01:00
|
|
|
|
|
|
|
_check_test_img
|
|
|
|
|
|
|
|
# success, all done
|
|
|
|
echo "*** done"
|
|
|
|
rm -f $seq.full
|
|
|
|
status=0
|