1#!/usr/bin/env bash
2# group: rw auto quick
3#
4# Check that detect-zeroes=unmap works on writes with registered I/O buffers.
5# This is a regression test for
6# https://gitlab.com/qemu-project/qemu/-/issues/1404 where I/O requests failed
7# unexpectedly.
8#
9# Copyright Red Hat
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
26owner=stefanha@redhat.com
27
28seq=`basename $0`
29echo "QA output created by $seq"
30
31status=1	# failure is the default!
32
33_cleanup()
34{
35	_cleanup_test_img
36}
37trap "_cleanup; exit \$status" 0 1 2 3 15
38
39# get standard environment, filters and checks
40cd ..
41. ./common.rc
42. ./common.filter
43
44_supported_fmt qcow2
45_supported_proto generic
46
47size=128M
48_make_test_img $size
49IMGSPEC="driver=$IMGFMT,file.filename=$TEST_IMG,discard=unmap,detect-zeroes=unmap"
50
51echo
52echo "== writing zero buffer to image =="
53QEMU_IO_OPTIONS="$QEMU_IO_OPTIONS_NO_FMT" $QEMU_IO -c "write -r -P 0 0 4k" --image-opts "$IMGSPEC" | _filter_qemu_io
54
55# success, all done
56echo "*** done"
57rm -f $seq.full
58status=0
59