xref: /qemu/tests/qemu-iotests/097 (revision f82c5b17ea85d8f432069a4afd6cbdb65d9d8a66)
1e6ea2312SMax Reitz#!/bin/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 Reitzhere="$PWD"
29e6ea2312SMax Reitzstatus=1	# failure is the default!
30e6ea2312SMax Reitz
31e6ea2312SMax Reitz_cleanup()
32e6ea2312SMax Reitz{
33e6ea2312SMax Reitz    _cleanup_test_img
34e6ea2312SMax Reitz    _rm_test_img "$TEST_IMG.itmd"
35e6ea2312SMax Reitz}
36e6ea2312SMax Reitztrap "_cleanup; exit \$status" 0 1 2 3 15
37e6ea2312SMax Reitz
38e6ea2312SMax Reitz# get standard environment, filters and checks
39e6ea2312SMax Reitz. ./common.rc
40e6ea2312SMax Reitz. ./common.filter
41e6ea2312SMax Reitz. ./common.pattern
42e6ea2312SMax Reitz
43e6ea2312SMax Reitz# Any format supporting backing files and bdrv_make_empty
44e6ea2312SMax Reitz_supported_fmt qcow qcow2
45e6ea2312SMax Reitz_supported_proto file
46e6ea2312SMax Reitz_supported_os Linux
47e6ea2312SMax Reitz
48e6ea2312SMax Reitz
49a3e1505dSEric Blake# Four main passes:
50e6ea2312SMax Reitz#  0: Two-layer backing chain, commit to upper backing file (implicitly)
51e6ea2312SMax Reitz#     (in this case, the top image will be emptied)
52e6ea2312SMax Reitz#  1: Two-layer backing chain, commit to upper backing file (explicitly)
53e6ea2312SMax Reitz#     (in this case, the top image will implicitly stay unchanged)
54e6ea2312SMax Reitz#  2: Two-layer backing chain, commit to upper backing file (implicitly with -d)
55e6ea2312SMax Reitz#     (in this case, the top image will explicitly stay unchanged)
56e6ea2312SMax Reitz#  3: Two-layer backing chain, commit to lower backing file
57e6ea2312SMax Reitz#     (in this case, the top image will implicitly stay unchanged)
58e6ea2312SMax Reitz#
59e6ea2312SMax Reitz# 020 already tests committing, so this only tests whether image chains are
60e6ea2312SMax Reitz# working properly and that all images above the base are emptied; therefore,
61a3e1505dSEric Blake# no complicated patterns are necessary.  Check near the 2G mark, as qcow2
62a3e1505dSEric Blake# has been buggy at that boundary in the past.
63e6ea2312SMax Reitzfor i in 0 1 2 3; do
64e6ea2312SMax Reitz
65e6ea2312SMax Reitzecho
6607ff948bSDaniel P. Berrangeecho "=== Test pass $i ==="
67e6ea2312SMax Reitzecho
68e6ea2312SMax Reitz
69*f82c5b17SEric Blakelen=$((2100 * 1024 * 1024 + 512)) # larger than 2G, and not cluster aligned
70*f82c5b17SEric BlakeTEST_IMG="$TEST_IMG.base" _make_test_img $len
71*f82c5b17SEric BlakeTEST_IMG="$TEST_IMG.itmd" _make_test_img -b "$TEST_IMG.base" $len
72*f82c5b17SEric Blake_make_test_img -b "$TEST_IMG.itmd" $len
73e6ea2312SMax Reitz
74*f82c5b17SEric Blake$QEMU_IO -c "write -P 1 0x7ffd0000 192k" "$TEST_IMG.base" | _filter_qemu_io
75*f82c5b17SEric Blake$QEMU_IO -c "write -P 2 0x7ffe0000 128k" "$TEST_IMG.itmd" | _filter_qemu_io
76*f82c5b17SEric Blake$QEMU_IO -c "write -P 3 0x7fff0000 64k" "$TEST_IMG" | _filter_qemu_io
77*f82c5b17SEric Blake$QEMU_IO -c "write -P 4 $(($len - 512)) 512" "$TEST_IMG" | _filter_qemu_io
78e6ea2312SMax Reitz
79e6ea2312SMax Reitzif [ $i -lt 3 ]; then
80e6ea2312SMax Reitz    if [ $i == 0 ]; then
81e6ea2312SMax Reitz        # -b "$TEST_IMG.itmd" should be the default (that is, committing to the
82e6ea2312SMax Reitz        # first backing file in the chain)
83e6ea2312SMax Reitz        $QEMU_IMG commit "$TEST_IMG"
84e6ea2312SMax Reitz    elif [ $i == 1 ]; then
85e6ea2312SMax Reitz        # explicitly specify the commit target (this should imply -d)
86e6ea2312SMax Reitz        $QEMU_IMG commit -b "$TEST_IMG.itmd" "$TEST_IMG"
87e6ea2312SMax Reitz    else
88e6ea2312SMax Reitz        # do not explicitly specify the commit target, but use -d to leave the
89e6ea2312SMax Reitz        # top image unchanged
90e6ea2312SMax Reitz        $QEMU_IMG commit -d "$TEST_IMG"
91e6ea2312SMax Reitz    fi
92e6ea2312SMax Reitz
93e6ea2312SMax Reitz    # Bottom should be unchanged
94a3e1505dSEric Blake    $QEMU_IO -c 'read -P 1 0x7ffd0000 192k' "$TEST_IMG.base" | _filter_qemu_io
95*f82c5b17SEric Blake    $QEMU_IO -c "read -P 0 $((len - 512)) 512" "$TEST_IMG.base" | _filter_qemu_io
96e6ea2312SMax Reitz
97e6ea2312SMax Reitz    # Intermediate should contain changes from top
98a3e1505dSEric Blake    $QEMU_IO -c 'read -P 1 0x7ffd0000 64k' "$TEST_IMG.itmd" | _filter_qemu_io
99a3e1505dSEric Blake    $QEMU_IO -c 'read -P 2 0x7ffe0000 64k' "$TEST_IMG.itmd" | _filter_qemu_io
100a3e1505dSEric Blake    $QEMU_IO -c 'read -P 3 0x7fff0000 64k' "$TEST_IMG.itmd" | _filter_qemu_io
101*f82c5b17SEric Blake    $QEMU_IO -c "read -P 4 $((len - 512)) 512" "$TEST_IMG.itmd" | _filter_qemu_io
102e6ea2312SMax Reitz
103e6ea2312SMax Reitz    # And in pass 0, the top image should be empty, whereas in both other passes
104e6ea2312SMax Reitz    # it should be unchanged (which is both checked by qemu-img map)
105e6ea2312SMax Reitzelse
106e6ea2312SMax Reitz    $QEMU_IMG commit -b "$TEST_IMG.base" "$TEST_IMG"
107e6ea2312SMax Reitz
108e6ea2312SMax Reitz    # Bottom should contain all changes
109a3e1505dSEric Blake    $QEMU_IO -c 'read -P 1 0x7ffd0000 64k' "$TEST_IMG.base" | _filter_qemu_io
110a3e1505dSEric Blake    $QEMU_IO -c 'read -P 2 0x7ffe0000 64k' "$TEST_IMG.base" | _filter_qemu_io
111a3e1505dSEric Blake    $QEMU_IO -c 'read -P 3 0x7fff0000 64k' "$TEST_IMG.base" | _filter_qemu_io
112*f82c5b17SEric Blake    $QEMU_IO -c "read -P 4 $((len - 512)) 512" "$TEST_IMG.base" | _filter_qemu_io
113e6ea2312SMax Reitz
114e6ea2312SMax Reitz    # Both top and intermediate should be unchanged
115e6ea2312SMax Reitzfi
116e6ea2312SMax Reitz
117e6ea2312SMax Reitz$QEMU_IMG map "$TEST_IMG.base" | _filter_qemu_img_map
118e6ea2312SMax Reitz$QEMU_IMG map "$TEST_IMG.itmd" | _filter_qemu_img_map
119e6ea2312SMax Reitz$QEMU_IMG map "$TEST_IMG" | _filter_qemu_img_map
120e6ea2312SMax Reitz
121e6ea2312SMax Reitzdone
122e6ea2312SMax Reitz
123e6ea2312SMax Reitz
124e6ea2312SMax Reitz# success, all done
125e6ea2312SMax Reitzecho "*** done"
126e6ea2312SMax Reitzrm -f $seq.full
127e6ea2312SMax Reitzstatus=0
128