xref: /openbmc/qemu/tests/qemu-iotests/097 (revision 07ff948bd135373c516842ae5ce856f41f7c553a)
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
66*07ff948bSDaniel P. Berrangeecho "=== Test pass $i ==="
67e6ea2312SMax Reitzecho
68e6ea2312SMax Reitz
69a3e1505dSEric BlakeTEST_IMG="$TEST_IMG.base" _make_test_img 2100M
70a3e1505dSEric BlakeTEST_IMG="$TEST_IMG.itmd" _make_test_img -b "$TEST_IMG.base" 2100M
71a3e1505dSEric Blake_make_test_img -b "$TEST_IMG.itmd" 2100M
72e6ea2312SMax Reitz
73a3e1505dSEric Blake$QEMU_IO -c 'write -P 1 0x7ffd0000 192k' "$TEST_IMG.base" | _filter_qemu_io
74a3e1505dSEric Blake$QEMU_IO -c 'write -P 2 0x7ffe0000 128k' "$TEST_IMG.itmd" | _filter_qemu_io
75a3e1505dSEric Blake$QEMU_IO -c 'write -P 3 0x7fff0000 64k' "$TEST_IMG" | _filter_qemu_io
76e6ea2312SMax Reitz
77e6ea2312SMax Reitzif [ $i -lt 3 ]; then
78e6ea2312SMax Reitz    if [ $i == 0 ]; then
79e6ea2312SMax Reitz        # -b "$TEST_IMG.itmd" should be the default (that is, committing to the
80e6ea2312SMax Reitz        # first backing file in the chain)
81e6ea2312SMax Reitz        $QEMU_IMG commit "$TEST_IMG"
82e6ea2312SMax Reitz    elif [ $i == 1 ]; then
83e6ea2312SMax Reitz        # explicitly specify the commit target (this should imply -d)
84e6ea2312SMax Reitz        $QEMU_IMG commit -b "$TEST_IMG.itmd" "$TEST_IMG"
85e6ea2312SMax Reitz    else
86e6ea2312SMax Reitz        # do not explicitly specify the commit target, but use -d to leave the
87e6ea2312SMax Reitz        # top image unchanged
88e6ea2312SMax Reitz        $QEMU_IMG commit -d "$TEST_IMG"
89e6ea2312SMax Reitz    fi
90e6ea2312SMax Reitz
91e6ea2312SMax Reitz    # Bottom should be unchanged
92a3e1505dSEric Blake    $QEMU_IO -c 'read -P 1 0x7ffd0000 192k' "$TEST_IMG.base" | _filter_qemu_io
93e6ea2312SMax Reitz
94e6ea2312SMax Reitz    # Intermediate should contain changes from top
95a3e1505dSEric Blake    $QEMU_IO -c 'read -P 1 0x7ffd0000 64k' "$TEST_IMG.itmd" | _filter_qemu_io
96a3e1505dSEric Blake    $QEMU_IO -c 'read -P 2 0x7ffe0000 64k' "$TEST_IMG.itmd" | _filter_qemu_io
97a3e1505dSEric Blake    $QEMU_IO -c 'read -P 3 0x7fff0000 64k' "$TEST_IMG.itmd" | _filter_qemu_io
98e6ea2312SMax Reitz
99e6ea2312SMax Reitz    # And in pass 0, the top image should be empty, whereas in both other passes
100e6ea2312SMax Reitz    # it should be unchanged (which is both checked by qemu-img map)
101e6ea2312SMax Reitzelse
102e6ea2312SMax Reitz    $QEMU_IMG commit -b "$TEST_IMG.base" "$TEST_IMG"
103e6ea2312SMax Reitz
104e6ea2312SMax Reitz    # Bottom should contain all changes
105a3e1505dSEric Blake    $QEMU_IO -c 'read -P 1 0x7ffd0000 64k' "$TEST_IMG.base" | _filter_qemu_io
106a3e1505dSEric Blake    $QEMU_IO -c 'read -P 2 0x7ffe0000 64k' "$TEST_IMG.base" | _filter_qemu_io
107a3e1505dSEric Blake    $QEMU_IO -c 'read -P 3 0x7fff0000 64k' "$TEST_IMG.base" | _filter_qemu_io
108e6ea2312SMax Reitz
109e6ea2312SMax Reitz    # Both top and intermediate should be unchanged
110e6ea2312SMax Reitzfi
111e6ea2312SMax Reitz
112e6ea2312SMax Reitz$QEMU_IMG map "$TEST_IMG.base" | _filter_qemu_img_map
113e6ea2312SMax Reitz$QEMU_IMG map "$TEST_IMG.itmd" | _filter_qemu_img_map
114e6ea2312SMax Reitz$QEMU_IMG map "$TEST_IMG" | _filter_qemu_img_map
115e6ea2312SMax Reitz
116e6ea2312SMax Reitzdone
117e6ea2312SMax Reitz
118e6ea2312SMax Reitz
119e6ea2312SMax Reitz# success, all done
120e6ea2312SMax Reitzecho "*** done"
121e6ea2312SMax Reitzrm -f $seq.full
122e6ea2312SMax Reitzstatus=0
123