xref: /qemu/tests/qemu-iotests/097 (revision b66ff2c29817f5efa18f5120fd6f089fbf59a933)
111a82d14SPhilippe Mathieu-Daudé#!/usr/bin/env bash
2e6ea2312SMax Reitz#
3e6ea2312SMax Reitz# Commit changes into backing chains and empty the top image if the
4e6ea2312SMax Reitz# backing image is not explicitly specified
5e6ea2312SMax Reitz#
6e6ea2312SMax Reitz# Copyright (C) 2014 Red Hat, Inc.
7e6ea2312SMax Reitz#
8e6ea2312SMax Reitz# This program is free software; you can redistribute it and/or modify
9e6ea2312SMax Reitz# it under the terms of the GNU General Public License as published by
10e6ea2312SMax Reitz# the Free Software Foundation; either version 2 of the License, or
11e6ea2312SMax Reitz# (at your option) any later version.
12e6ea2312SMax Reitz#
13e6ea2312SMax Reitz# This program is distributed in the hope that it will be useful,
14e6ea2312SMax Reitz# but WITHOUT ANY WARRANTY; without even the implied warranty of
15e6ea2312SMax Reitz# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16e6ea2312SMax Reitz# GNU General Public License for more details.
17e6ea2312SMax Reitz#
18e6ea2312SMax Reitz# You should have received a copy of the GNU General Public License
19e6ea2312SMax Reitz# along with this program.  If not, see <http://www.gnu.org/licenses/>.
20e6ea2312SMax Reitz#
21e6ea2312SMax Reitz
22e6ea2312SMax Reitz# creator
23e6ea2312SMax Reitzowner=mreitz@redhat.com
24e6ea2312SMax Reitz
25e6ea2312SMax Reitzseq="$(basename $0)"
26e6ea2312SMax Reitzecho "QA output created by $seq"
27e6ea2312SMax Reitz
28e6ea2312SMax Reitzstatus=1	# failure is the default!
29e6ea2312SMax Reitz
30e6ea2312SMax Reitz_cleanup()
31e6ea2312SMax Reitz{
32e6ea2312SMax Reitz    _cleanup_test_img
33e6ea2312SMax Reitz    _rm_test_img "$TEST_IMG.itmd"
34e6ea2312SMax Reitz}
35e6ea2312SMax Reitztrap "_cleanup; exit \$status" 0 1 2 3 15
36e6ea2312SMax Reitz
37e6ea2312SMax Reitz# get standard environment, filters and checks
38e6ea2312SMax Reitz. ./common.rc
39e6ea2312SMax Reitz. ./common.filter
40e6ea2312SMax Reitz. ./common.pattern
41e6ea2312SMax Reitz
42e6ea2312SMax Reitz# Any format supporting backing files and bdrv_make_empty
43e6ea2312SMax Reitz_supported_fmt qcow qcow2
44e6ea2312SMax Reitz_supported_proto file
45e6ea2312SMax Reitz_supported_os Linux
46e6ea2312SMax Reitz
47e6ea2312SMax Reitz
48a3e1505dSEric Blake# Four main passes:
49e6ea2312SMax Reitz#  0: Two-layer backing chain, commit to upper backing file (implicitly)
50e6ea2312SMax Reitz#     (in this case, the top image will be emptied)
51e6ea2312SMax Reitz#  1: Two-layer backing chain, commit to upper backing file (explicitly)
52e6ea2312SMax Reitz#     (in this case, the top image will implicitly stay unchanged)
53e6ea2312SMax Reitz#  2: Two-layer backing chain, commit to upper backing file (implicitly with -d)
54e6ea2312SMax Reitz#     (in this case, the top image will explicitly stay unchanged)
55e6ea2312SMax Reitz#  3: Two-layer backing chain, commit to lower backing file
56e6ea2312SMax Reitz#     (in this case, the top image will implicitly stay unchanged)
57e6ea2312SMax Reitz#
58e6ea2312SMax Reitz# 020 already tests committing, so this only tests whether image chains are
59e6ea2312SMax Reitz# working properly and that all images above the base are emptied; therefore,
60a3e1505dSEric Blake# no complicated patterns are necessary.  Check near the 2G mark, as qcow2
61a3e1505dSEric Blake# has been buggy at that boundary in the past.
62e6ea2312SMax Reitzfor i in 0 1 2 3; do
63e6ea2312SMax Reitz
64e6ea2312SMax Reitzecho
6507ff948bSDaniel P. Berrangeecho "=== Test pass $i ==="
66e6ea2312SMax Reitzecho
67e6ea2312SMax Reitz
68f82c5b17SEric Blakelen=$((2100 * 1024 * 1024 + 512)) # larger than 2G, and not cluster aligned
69f82c5b17SEric BlakeTEST_IMG="$TEST_IMG.base" _make_test_img $len
70*b66ff2c2SEric BlakeTEST_IMG="$TEST_IMG.itmd" _make_test_img -b "$TEST_IMG.base" -F $IMGFMT $len
71*b66ff2c2SEric Blake_make_test_img -b "$TEST_IMG.itmd" -F $IMGFMT $len
72e6ea2312SMax Reitz
73f82c5b17SEric Blake$QEMU_IO -c "write -P 1 0x7ffd0000 192k" "$TEST_IMG.base" | _filter_qemu_io
74f82c5b17SEric Blake$QEMU_IO -c "write -P 2 0x7ffe0000 128k" "$TEST_IMG.itmd" | _filter_qemu_io
75f82c5b17SEric Blake$QEMU_IO -c "write -P 3 0x7fff0000 64k" "$TEST_IMG" | _filter_qemu_io
76f82c5b17SEric Blake$QEMU_IO -c "write -P 4 $(($len - 512)) 512" "$TEST_IMG" | _filter_qemu_io
77e6ea2312SMax Reitz
78e6ea2312SMax Reitzif [ $i -lt 3 ]; then
79e6ea2312SMax Reitz    if [ $i == 0 ]; then
80e6ea2312SMax Reitz        # -b "$TEST_IMG.itmd" should be the default (that is, committing to the
81e6ea2312SMax Reitz        # first backing file in the chain)
82e6ea2312SMax Reitz        $QEMU_IMG commit "$TEST_IMG"
83e6ea2312SMax Reitz    elif [ $i == 1 ]; then
84e6ea2312SMax Reitz        # explicitly specify the commit target (this should imply -d)
85e6ea2312SMax Reitz        $QEMU_IMG commit -b "$TEST_IMG.itmd" "$TEST_IMG"
86e6ea2312SMax Reitz    else
87e6ea2312SMax Reitz        # do not explicitly specify the commit target, but use -d to leave the
88e6ea2312SMax Reitz        # top image unchanged
89e6ea2312SMax Reitz        $QEMU_IMG commit -d "$TEST_IMG"
90e6ea2312SMax Reitz    fi
91e6ea2312SMax Reitz
92e6ea2312SMax Reitz    # Bottom should be unchanged
93a3e1505dSEric Blake    $QEMU_IO -c 'read -P 1 0x7ffd0000 192k' "$TEST_IMG.base" | _filter_qemu_io
94f82c5b17SEric Blake    $QEMU_IO -c "read -P 0 $((len - 512)) 512" "$TEST_IMG.base" | _filter_qemu_io
95e6ea2312SMax Reitz
96e6ea2312SMax Reitz    # Intermediate should contain changes from top
97a3e1505dSEric Blake    $QEMU_IO -c 'read -P 1 0x7ffd0000 64k' "$TEST_IMG.itmd" | _filter_qemu_io
98a3e1505dSEric Blake    $QEMU_IO -c 'read -P 2 0x7ffe0000 64k' "$TEST_IMG.itmd" | _filter_qemu_io
99a3e1505dSEric Blake    $QEMU_IO -c 'read -P 3 0x7fff0000 64k' "$TEST_IMG.itmd" | _filter_qemu_io
100f82c5b17SEric Blake    $QEMU_IO -c "read -P 4 $((len - 512)) 512" "$TEST_IMG.itmd" | _filter_qemu_io
101e6ea2312SMax Reitz
102e6ea2312SMax Reitz    # And in pass 0, the top image should be empty, whereas in both other passes
103e6ea2312SMax Reitz    # it should be unchanged (which is both checked by qemu-img map)
104e6ea2312SMax Reitzelse
105e6ea2312SMax Reitz    $QEMU_IMG commit -b "$TEST_IMG.base" "$TEST_IMG"
106e6ea2312SMax Reitz
107e6ea2312SMax Reitz    # Bottom should contain all changes
108a3e1505dSEric Blake    $QEMU_IO -c 'read -P 1 0x7ffd0000 64k' "$TEST_IMG.base" | _filter_qemu_io
109a3e1505dSEric Blake    $QEMU_IO -c 'read -P 2 0x7ffe0000 64k' "$TEST_IMG.base" | _filter_qemu_io
110a3e1505dSEric Blake    $QEMU_IO -c 'read -P 3 0x7fff0000 64k' "$TEST_IMG.base" | _filter_qemu_io
111f82c5b17SEric Blake    $QEMU_IO -c "read -P 4 $((len - 512)) 512" "$TEST_IMG.base" | _filter_qemu_io
112e6ea2312SMax Reitz
113e6ea2312SMax Reitz    # Both top and intermediate should be unchanged
114e6ea2312SMax Reitzfi
115e6ea2312SMax Reitz
116e6ea2312SMax Reitz$QEMU_IMG map "$TEST_IMG.base" | _filter_qemu_img_map
117e6ea2312SMax Reitz$QEMU_IMG map "$TEST_IMG.itmd" | _filter_qemu_img_map
118e6ea2312SMax Reitz$QEMU_IMG map "$TEST_IMG" | _filter_qemu_img_map
119e6ea2312SMax Reitz
120e6ea2312SMax Reitzdone
121e6ea2312SMax Reitz
122e6ea2312SMax Reitz
123e6ea2312SMax Reitz# success, all done
124e6ea2312SMax Reitzecho "*** done"
125e6ea2312SMax Reitzrm -f $seq.full
126e6ea2312SMax Reitzstatus=0
127