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