xref: /openbmc/qemu/tests/qemu-iotests/250 (revision 68894b5fed671d49587209697f2224b4e857fd1a)
13dd3e248SVladimir Sementsov-Ogievskiy#!/usr/bin/env bash
29dd003a9SVladimir Sementsov-Ogievskiy# group: rw quick
33dd3e248SVladimir Sementsov-Ogievskiy#
43dd3e248SVladimir Sementsov-Ogievskiy# Test big discard in qcow2 shrink
53dd3e248SVladimir Sementsov-Ogievskiy#
63dd3e248SVladimir Sementsov-Ogievskiy# Copyright (c) 2019 Virtuozzo International GmbH. All rights reserved.
73dd3e248SVladimir Sementsov-Ogievskiy#
83dd3e248SVladimir Sementsov-Ogievskiy# This program is free software; you can redistribute it and/or modify
93dd3e248SVladimir Sementsov-Ogievskiy# it under the terms of the GNU General Public License as published by
103dd3e248SVladimir Sementsov-Ogievskiy# the Free Software Foundation; either version 2 of the License, or
113dd3e248SVladimir Sementsov-Ogievskiy# (at your option) any later version.
123dd3e248SVladimir Sementsov-Ogievskiy#
133dd3e248SVladimir Sementsov-Ogievskiy# This program is distributed in the hope that it will be useful,
143dd3e248SVladimir Sementsov-Ogievskiy# but WITHOUT ANY WARRANTY; without even the implied warranty of
153dd3e248SVladimir Sementsov-Ogievskiy# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
163dd3e248SVladimir Sementsov-Ogievskiy# GNU General Public License for more details.
173dd3e248SVladimir Sementsov-Ogievskiy#
183dd3e248SVladimir Sementsov-Ogievskiy# You should have received a copy of the GNU General Public License
193dd3e248SVladimir Sementsov-Ogievskiy# along with this program.  If not, see <http://www.gnu.org/licenses/>.
203dd3e248SVladimir Sementsov-Ogievskiy#
213dd3e248SVladimir Sementsov-Ogievskiy
223dd3e248SVladimir Sementsov-Ogievskiy# creator
23*42a5009dSJohn Snowowner=v.sementsov-og@mail.ru
243dd3e248SVladimir Sementsov-Ogievskiy
253dd3e248SVladimir Sementsov-Ogievskiyseq=`basename $0`
263dd3e248SVladimir Sementsov-Ogievskiyecho "QA output created by $seq"
273dd3e248SVladimir Sementsov-Ogievskiy
283dd3e248SVladimir Sementsov-Ogievskiystatus=1	# failure is the default!
293dd3e248SVladimir Sementsov-Ogievskiy
303dd3e248SVladimir Sementsov-Ogievskiy_cleanup()
313dd3e248SVladimir Sementsov-Ogievskiy{
323dd3e248SVladimir Sementsov-Ogievskiy    _cleanup_test_img
333dd3e248SVladimir Sementsov-Ogievskiy}
343dd3e248SVladimir Sementsov-Ogievskiytrap "_cleanup; exit \$status" 0 1 2 3 15
353dd3e248SVladimir Sementsov-Ogievskiy
363dd3e248SVladimir Sementsov-Ogievskiy# get standard environment, filters and checks
373dd3e248SVladimir Sementsov-Ogievskiy. ./common.rc
383dd3e248SVladimir Sementsov-Ogievskiy. ./common.filter
393dd3e248SVladimir Sementsov-Ogievskiy
403dd3e248SVladimir Sementsov-Ogievskiy_supported_fmt qcow2
4157284d2aSMax Reitz_supported_proto file fuse
423dd3e248SVladimir Sementsov-Ogievskiy_supported_os Linux
433be2024aSMax Reitz# This test does not make much sense with external data files
443be2024aSMax Reitz_unsupported_imgopts data_file
453dd3e248SVladimir Sementsov-Ogievskiy
463dd3e248SVladimir Sementsov-Ogievskiy# This test checks that qcow2_process_discards does not truncate a discard
473dd3e248SVladimir Sementsov-Ogievskiy# request > 2G.
483dd3e248SVladimir Sementsov-Ogievskiy# To reproduce bug we need to overflow int by one sequential discard, so we
493dd3e248SVladimir Sementsov-Ogievskiy# need size > 2G, bigger cluster size (as with default 64k we may have maximum
503dd3e248SVladimir Sementsov-Ogievskiy# of 512M sequential data, corresponding to one L1 entry), and we need some
513dd3e248SVladimir Sementsov-Ogievskiy# data of the beginning of the disk mapped to the end of file to prevent
523dd3e248SVladimir Sementsov-Ogievskiy# bdrv_co_truncate(bs->file) call in qcow2_co_truncate(), which might succeed
533dd3e248SVladimir Sementsov-Ogievskiy# anyway.
543dd3e248SVladimir Sementsov-Ogievskiy
553dd3e248SVladimir Sementsov-Ogievskiydisk_usage()
563dd3e248SVladimir Sementsov-Ogievskiy{
573dd3e248SVladimir Sementsov-Ogievskiy    du --block-size=1 $1 | awk '{print $1}'
583dd3e248SVladimir Sementsov-Ogievskiy}
593dd3e248SVladimir Sementsov-Ogievskiy
603dd3e248SVladimir Sementsov-Ogievskiysize=2100M
613dd3e248SVladimir Sementsov-Ogievskiy
62407fb56aSMax Reitz_make_test_img -o "cluster_size=1M,preallocation=metadata" $size
633dd3e248SVladimir Sementsov-Ogievskiy$QEMU_IO -c 'discard 0 10M' -c 'discard 2090M 10M' \
643dd3e248SVladimir Sementsov-Ogievskiy         -c 'write 2090M 10M' -c 'write 0 10M' "$TEST_IMG" | _filter_qemu_io
653dd3e248SVladimir Sementsov-Ogievskiy
663dd3e248SVladimir Sementsov-Ogievskiy# Check that our trick with swapping first and last 10M chunks succeeded.
673dd3e248SVladimir Sementsov-Ogievskiy# Otherwise test may pass even if bdrv_pdiscard() fails in
683dd3e248SVladimir Sementsov-Ogievskiy# qcow2_process_discards()
693dd3e248SVladimir Sementsov-Ogievskiy$QEMU_IMG map "$TEST_IMG" | _filter_testdir
703dd3e248SVladimir Sementsov-Ogievskiy
713dd3e248SVladimir Sementsov-Ogievskiybefore=$(disk_usage "$TEST_IMG")
723dd3e248SVladimir Sementsov-Ogievskiy$QEMU_IMG resize --shrink "$TEST_IMG" 5M
733dd3e248SVladimir Sementsov-Ogievskiyafter=$(disk_usage "$TEST_IMG")
743dd3e248SVladimir Sementsov-Ogievskiy
753dd3e248SVladimir Sementsov-Ogievskiyecho "Disk usage delta: $((before - after))"
763dd3e248SVladimir Sementsov-Ogievskiy
773dd3e248SVladimir Sementsov-Ogievskiy# success, all done
783dd3e248SVladimir Sementsov-Ogievskiyecho "*** done"
793dd3e248SVladimir Sementsov-Ogievskiyrm -f $seq.full
803dd3e248SVladimir Sementsov-Ogievskiystatus=0
81