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