1#!/usr/bin/env bash 2# group: quick 3# 4# Test write zeros unmap. 5# 6# Copyright (C) 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 22seq="$(basename $0)" 23echo "QA output created by $seq" 24 25trap _cleanup_test_img exit 26 27# get standard environment, filters and checks 28cd .. 29. ./common.rc 30. ./common.filter 31 32_supported_fmt raw 33_supported_proto file 34_supported_os Linux 35 36create_test_image() { 37 _make_test_img -f $IMGFMT 1m 38} 39 40filter_command() { 41 _filter_testdir | _filter_qemu_io | _filter_qemu | _filter_hmp 42} 43 44print_disk_usage() { 45 du -sh $TEST_IMG | _filter_testdir 46} 47 48echo 49echo "=== defaults - write zeros ===" 50echo 51 52create_test_image 53echo -e 'qemu-io none0 "write -z 0 1m"\nquit' \ 54 | $QEMU -monitor stdio -drive if=none,file=$TEST_IMG,format=$IMGFMT \ 55 | filter_command 56print_disk_usage 57 58echo 59echo "=== defaults - write zeros unmap ===" 60echo 61 62create_test_image 63echo -e 'qemu-io none0 "write -zu 0 1m"\nquit' \ 64 | $QEMU -monitor stdio -drive if=none,file=$TEST_IMG,format=$IMGFMT \ 65 | filter_command 66print_disk_usage 67 68 69echo 70echo "=== defaults - write actual zeros ===" 71echo 72 73create_test_image 74echo -e 'qemu-io none0 "write -P 0 0 1m"\nquit' \ 75 | $QEMU -monitor stdio -drive if=none,file=$TEST_IMG,format=$IMGFMT \ 76 | filter_command 77print_disk_usage 78 79echo 80echo "=== discard=off - write zeroes unmap ===" 81echo 82 83create_test_image 84echo -e 'qemu-io none0 "write -zu 0 1m"\nquit' \ 85 | $QEMU -monitor stdio -drive if=none,file=$TEST_IMG,format=$IMGFMT,discard=off \ 86 | filter_command 87print_disk_usage 88 89echo 90echo "=== detect-zeroes=on - write actual zeros ===" 91echo 92 93create_test_image 94echo -e 'qemu-io none0 "write -P 0 0 1m"\nquit' \ 95 | $QEMU -monitor stdio -drive if=none,file=$TEST_IMG,format=$IMGFMT,detect-zeroes=on \ 96 | filter_command 97print_disk_usage 98 99echo 100echo "=== detect-zeroes=on,discard=on - write actual zeros ===" 101echo 102 103create_test_image 104echo -e 'qemu-io none0 "write -P 0 0 1m"\nquit' \ 105 | $QEMU -monitor stdio -drive if=none,file=$TEST_IMG,format=$IMGFMT,detect-zeroes=on,discard=on \ 106 | filter_command 107print_disk_usage 108 109echo 110echo "=== discard=on - write zeroes ===" 111echo 112 113create_test_image 114echo -e 'qemu-io none0 "write -z 0 1m"\nquit' \ 115 | $QEMU -monitor stdio -drive if=none,file=$TEST_IMG,format=$IMGFMT,discard=on \ 116 | filter_command 117print_disk_usage 118 119echo 120echo "=== discard=on - write zeroes unmap ===" 121echo 122 123create_test_image 124echo -e 'qemu-io none0 "write -zu 0 1m"\nquit' \ 125 | $QEMU -monitor stdio -drive if=none,file=$TEST_IMG,format=$IMGFMT,discard=on \ 126 | filter_command 127print_disk_usage 128