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 49*a3e1505dSEric 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# 59*a3e1505dSEric Blake# Each pass is run twice, since qcow2 has different code paths for cleaning 60*a3e1505dSEric Blake# an image depending on whether it has a snapshot. 61*a3e1505dSEric Blake# 62e6ea2312SMax Reitz# 020 already tests committing, so this only tests whether image chains are 63e6ea2312SMax Reitz# working properly and that all images above the base are emptied; therefore, 64*a3e1505dSEric Blake# no complicated patterns are necessary. Check near the 2G mark, as qcow2 65*a3e1505dSEric Blake# has been buggy at that boundary in the past. 66e6ea2312SMax Reitzfor i in 0 1 2 3; do 67*a3e1505dSEric Blakefor j in 0 1; do 68e6ea2312SMax Reitz 69e6ea2312SMax Reitzecho 70*a3e1505dSEric Blakeecho "=== Test pass $i.$j ===" 71e6ea2312SMax Reitzecho 72e6ea2312SMax Reitz 73*a3e1505dSEric BlakeTEST_IMG="$TEST_IMG.base" _make_test_img 2100M 74*a3e1505dSEric BlakeTEST_IMG="$TEST_IMG.itmd" _make_test_img -b "$TEST_IMG.base" 2100M 75*a3e1505dSEric Blake_make_test_img -b "$TEST_IMG.itmd" 2100M 76*a3e1505dSEric Blakeif [ $j -eq 0 ]; then 77*a3e1505dSEric Blake $QEMU_IMG snapshot -c snap "$TEST_IMG" 78*a3e1505dSEric Blakefi 79e6ea2312SMax Reitz 80*a3e1505dSEric Blake$QEMU_IO -c 'write -P 1 0x7ffd0000 192k' "$TEST_IMG.base" | _filter_qemu_io 81*a3e1505dSEric Blake$QEMU_IO -c 'write -P 2 0x7ffe0000 128k' "$TEST_IMG.itmd" | _filter_qemu_io 82*a3e1505dSEric Blake$QEMU_IO -c 'write -P 3 0x7fff0000 64k' "$TEST_IMG" | _filter_qemu_io 83e6ea2312SMax Reitz 84e6ea2312SMax Reitzif [ $i -lt 3 ]; then 85e6ea2312SMax Reitz if [ $i == 0 ]; then 86e6ea2312SMax Reitz # -b "$TEST_IMG.itmd" should be the default (that is, committing to the 87e6ea2312SMax Reitz # first backing file in the chain) 88e6ea2312SMax Reitz $QEMU_IMG commit "$TEST_IMG" 89e6ea2312SMax Reitz elif [ $i == 1 ]; then 90e6ea2312SMax Reitz # explicitly specify the commit target (this should imply -d) 91e6ea2312SMax Reitz $QEMU_IMG commit -b "$TEST_IMG.itmd" "$TEST_IMG" 92e6ea2312SMax Reitz else 93e6ea2312SMax Reitz # do not explicitly specify the commit target, but use -d to leave the 94e6ea2312SMax Reitz # top image unchanged 95e6ea2312SMax Reitz $QEMU_IMG commit -d "$TEST_IMG" 96e6ea2312SMax Reitz fi 97e6ea2312SMax Reitz 98e6ea2312SMax Reitz # Bottom should be unchanged 99*a3e1505dSEric Blake $QEMU_IO -c 'read -P 1 0x7ffd0000 192k' "$TEST_IMG.base" | _filter_qemu_io 100e6ea2312SMax Reitz 101e6ea2312SMax Reitz # Intermediate should contain changes from top 102*a3e1505dSEric Blake $QEMU_IO -c 'read -P 1 0x7ffd0000 64k' "$TEST_IMG.itmd" | _filter_qemu_io 103*a3e1505dSEric Blake $QEMU_IO -c 'read -P 2 0x7ffe0000 64k' "$TEST_IMG.itmd" | _filter_qemu_io 104*a3e1505dSEric Blake $QEMU_IO -c 'read -P 3 0x7fff0000 64k' "$TEST_IMG.itmd" | _filter_qemu_io 105e6ea2312SMax Reitz 106e6ea2312SMax Reitz # And in pass 0, the top image should be empty, whereas in both other passes 107e6ea2312SMax Reitz # it should be unchanged (which is both checked by qemu-img map) 108e6ea2312SMax Reitzelse 109e6ea2312SMax Reitz $QEMU_IMG commit -b "$TEST_IMG.base" "$TEST_IMG" 110e6ea2312SMax Reitz 111e6ea2312SMax Reitz # Bottom should contain all changes 112*a3e1505dSEric Blake $QEMU_IO -c 'read -P 1 0x7ffd0000 64k' "$TEST_IMG.base" | _filter_qemu_io 113*a3e1505dSEric Blake $QEMU_IO -c 'read -P 2 0x7ffe0000 64k' "$TEST_IMG.base" | _filter_qemu_io 114*a3e1505dSEric Blake $QEMU_IO -c 'read -P 3 0x7fff0000 64k' "$TEST_IMG.base" | _filter_qemu_io 115e6ea2312SMax Reitz 116e6ea2312SMax Reitz # Both top and intermediate should be unchanged 117e6ea2312SMax Reitzfi 118e6ea2312SMax Reitz 119e6ea2312SMax Reitz$QEMU_IMG map "$TEST_IMG.base" | _filter_qemu_img_map 120e6ea2312SMax Reitz$QEMU_IMG map "$TEST_IMG.itmd" | _filter_qemu_img_map 121e6ea2312SMax Reitz$QEMU_IMG map "$TEST_IMG" | _filter_qemu_img_map 122e6ea2312SMax Reitz 123e6ea2312SMax Reitzdone 124*a3e1505dSEric Blakedone 125e6ea2312SMax Reitz 126e6ea2312SMax Reitz 127e6ea2312SMax Reitz# success, all done 128e6ea2312SMax Reitzecho "*** done" 129e6ea2312SMax Reitzrm -f $seq.full 130e6ea2312SMax Reitzstatus=0 131