xref: /openbmc/qemu/tests/qemu-iotests/179 (revision e249d519)
1*e249d519SEric Blake#!/bin/bash
2*e249d519SEric Blake#
3*e249d519SEric Blake# Test case for write zeroes with unmap
4*e249d519SEric Blake#
5*e249d519SEric Blake# Copyright (C) 2017 Red Hat, Inc.
6*e249d519SEric Blake#
7*e249d519SEric Blake# This program is free software; you can redistribute it and/or modify
8*e249d519SEric Blake# it under the terms of the GNU General Public License as published by
9*e249d519SEric Blake# the Free Software Foundation; either version 2 of the License, or
10*e249d519SEric Blake# (at your option) any later version.
11*e249d519SEric Blake#
12*e249d519SEric Blake# This program is distributed in the hope that it will be useful,
13*e249d519SEric Blake# but WITHOUT ANY WARRANTY; without even the implied warranty of
14*e249d519SEric Blake# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15*e249d519SEric Blake# GNU General Public License for more details.
16*e249d519SEric Blake#
17*e249d519SEric Blake# You should have received a copy of the GNU General Public License
18*e249d519SEric Blake# along with this program.  If not, see <http://www.gnu.org/licenses/>.
19*e249d519SEric Blake#
20*e249d519SEric Blake
21*e249d519SEric Blake# creator
22*e249d519SEric Blakeowner=eblake@redhat.com
23*e249d519SEric Blake
24*e249d519SEric Blakeseq="$(basename $0)"
25*e249d519SEric Blakeecho "QA output created by $seq"
26*e249d519SEric Blake
27*e249d519SEric Blakehere="$PWD"
28*e249d519SEric Blakestatus=1	# failure is the default!
29*e249d519SEric Blake
30*e249d519SEric Blake_cleanup()
31*e249d519SEric Blake{
32*e249d519SEric Blake	_cleanup_test_img
33*e249d519SEric Blake}
34*e249d519SEric Blaketrap "_cleanup; exit \$status" 0 1 2 3 15
35*e249d519SEric Blake
36*e249d519SEric Blake# get standard environment, filters and checks
37*e249d519SEric Blake. ./common.rc
38*e249d519SEric Blake. ./common.filter
39*e249d519SEric Blake
40*e249d519SEric Blake_supported_fmt qcow2
41*e249d519SEric Blake_supported_proto file
42*e249d519SEric Blake_supported_os Linux
43*e249d519SEric Blake
44*e249d519SEric Blake# v2 images can't mark clusters as zero
45*e249d519SEric Blake_unsupported_imgopts compat=0.10
46*e249d519SEric Blake
47*e249d519SEric Blakeecho
48*e249d519SEric Blakeecho '=== Testing write zeroes with unmap ==='
49*e249d519SEric Blakeecho
50*e249d519SEric Blake
51*e249d519SEric BlakeTEST_IMG="$TEST_IMG.base" _make_test_img 64M
52*e249d519SEric Blake_make_test_img -b "$TEST_IMG.base"
53*e249d519SEric Blake
54*e249d519SEric Blake# Offsets chosen at or near 2M boundaries so test works at all cluster sizes
55*e249d519SEric Blake# 8k and larger (smaller clusters fail due to non-contiguous allocations)
56*e249d519SEric Blake
57*e249d519SEric Blake# Aligned writes to unallocated cluster should not allocate mapping, but must
58*e249d519SEric Blake# mark cluster as zero, whether or not unmap was requested
59*e249d519SEric Blake$QEMU_IO -c "write -z -u 2M 2M" "$TEST_IMG.base" | _filter_qemu_io
60*e249d519SEric Blake$QEMU_IO -c "write -z 6M 2M" "$TEST_IMG.base" | _filter_qemu_io
61*e249d519SEric Blake$QEMU_IO -c "map" "$TEST_IMG.base" | _filter_qemu_io
62*e249d519SEric Blake$QEMU_IMG map --output=json "$TEST_IMG.base" | _filter_qemu_img_map
63*e249d519SEric Blake
64*e249d519SEric Blake# Unaligned writes need not allocate mapping if the cluster already reads
65*e249d519SEric Blake# as zero, but must mark cluster as zero, whether or not unmap was requested
66*e249d519SEric Blake$QEMU_IO -c "write -z -u 10485761 2097150" "$TEST_IMG.base" | _filter_qemu_io
67*e249d519SEric Blake$QEMU_IO -c "write -z 14680065 2097150" "$TEST_IMG.base" | _filter_qemu_io
68*e249d519SEric Blake$QEMU_IO -c "map" "$TEST_IMG.base" | _filter_qemu_io
69*e249d519SEric Blake$QEMU_IMG map --output=json "$TEST_IMG.base" | _filter_qemu_img_map
70*e249d519SEric Blake
71*e249d519SEric Blake# Requesting unmap of normal data must deallocate; omitting unmap should
72*e249d519SEric Blake# preserve the mapping
73*e249d519SEric Blake$QEMU_IO -c "write 18M 14M" "$TEST_IMG.base" | _filter_qemu_io
74*e249d519SEric Blake$QEMU_IO -c "write -z -u 20M 2M" "$TEST_IMG.base" | _filter_qemu_io
75*e249d519SEric Blake$QEMU_IO -c "write -z 24M 6M" "$TEST_IMG.base" | _filter_qemu_io
76*e249d519SEric Blake$QEMU_IO -c "map" "$TEST_IMG.base" | _filter_qemu_io
77*e249d519SEric Blake$QEMU_IMG map --output=json "$TEST_IMG.base" | _filter_qemu_img_map
78*e249d519SEric Blake
79*e249d519SEric Blake# Likewise when writing on already-mapped zero data
80*e249d519SEric Blake$QEMU_IO -c "write -z -u 26M 2M" "$TEST_IMG.base" | _filter_qemu_io
81*e249d519SEric Blake$QEMU_IO -c "write -z 28M 2M" "$TEST_IMG.base" | _filter_qemu_io
82*e249d519SEric Blake$QEMU_IO -c "map" "$TEST_IMG.base" | _filter_qemu_io
83*e249d519SEric Blake$QEMU_IMG map --output=json "$TEST_IMG.base" | _filter_qemu_img_map
84*e249d519SEric Blake
85*e249d519SEric Blake# Writing on unmapped zeroes does not allocate
86*e249d519SEric Blake$QEMU_IO -c "write -z 32M 8M" "$TEST_IMG.base" | _filter_qemu_io
87*e249d519SEric Blake$QEMU_IO -c "write -z -u 34M 2M" "$TEST_IMG.base" | _filter_qemu_io
88*e249d519SEric Blake$QEMU_IO -c "write -z 36M 2M" "$TEST_IMG.base" | _filter_qemu_io
89*e249d519SEric Blake$QEMU_IO -c "map" "$TEST_IMG.base" | _filter_qemu_io
90*e249d519SEric Blake$QEMU_IMG map --output=json "$TEST_IMG.base" | _filter_qemu_img_map
91*e249d519SEric Blake
92*e249d519SEric Blake# Writing zero overrides a backing file, regardless of backing cluster type
93*e249d519SEric Blake$QEMU_IO -c "write -z 40M 8M" "$TEST_IMG.base" | _filter_qemu_io
94*e249d519SEric Blake$QEMU_IO -c "write 48M 8M" "$TEST_IMG.base" | _filter_qemu_io
95*e249d519SEric Blake$QEMU_IO -c "write -z -u 42M 2M" "$TEST_IMG" | _filter_qemu_io
96*e249d519SEric Blake$QEMU_IO -c "write -z 44M 2M" "$TEST_IMG" | _filter_qemu_io
97*e249d519SEric Blake$QEMU_IO -c "write -z -u 50M 2M" "$TEST_IMG" | _filter_qemu_io
98*e249d519SEric Blake$QEMU_IO -c "write -z 52M 2M" "$TEST_IMG" | _filter_qemu_io
99*e249d519SEric Blake$QEMU_IO -c "write -z -u 58M 2M" "$TEST_IMG" | _filter_qemu_io
100*e249d519SEric Blake$QEMU_IO -c "write -z 60M 2M" "$TEST_IMG" | _filter_qemu_io
101*e249d519SEric Blake$QEMU_IO -c "map" "$TEST_IMG" | _filter_qemu_io
102*e249d519SEric Blake$QEMU_IMG map --output=json "$TEST_IMG" | _filter_qemu_img_map
103*e249d519SEric Blake
104*e249d519SEric Blake# Final check that mappings are correct and images are still sane
105*e249d519SEric BlakeTEST_IMG="$TEST_IMG.base" _check_test_img
106*e249d519SEric Blake_check_test_img
107*e249d519SEric Blake
108*e249d519SEric Blakeecho
109*e249d519SEric Blakeecho '=== Testing cache optimization ==='
110*e249d519SEric Blakeecho
111*e249d519SEric Blake
112*e249d519SEric BlakeBLKDBG_TEST_IMG="blkdebug:$TEST_DIR/blkdebug.conf:$TEST_IMG.base"
113*e249d519SEric Blake
114*e249d519SEric Blakecat > "$TEST_DIR/blkdebug.conf" <<EOF
115*e249d519SEric Blake[inject-error]
116*e249d519SEric Blakeevent = "l2_update"
117*e249d519SEric Blakeerrno = "5"
118*e249d519SEric Blakeimmediately = "on"
119*e249d519SEric Blakeonce = "off"
120*e249d519SEric BlakeEOF
121*e249d519SEric Blake
122*e249d519SEric Blake# None of the following writes should trigger an L2 update, because the
123*e249d519SEric Blake# cluster already reads as zero, and we don't have to change allocation
124*e249d519SEric Blake$QEMU_IO -c "w -z -u 20M 2M" "$BLKDBG_TEST_IMG" | _filter_qemu_io
125*e249d519SEric Blake$QEMU_IO -c "w -z 20M 2M" "$BLKDBG_TEST_IMG" | _filter_qemu_io
126*e249d519SEric Blake$QEMU_IO -c "w -z 28M 2M" "$BLKDBG_TEST_IMG" | _filter_qemu_io
127*e249d519SEric Blake
128*e249d519SEric Blake# success, all done
129*e249d519SEric Blakeecho '*** done'
130*e249d519SEric Blakestatus=0
131