107ff948bSDaniel P. Berrange#!/bin/bash 207ff948bSDaniel P. Berrange# 307ff948bSDaniel P. Berrange# Commit changes into backing chains and empty the top image if the 407ff948bSDaniel P. Berrange# backing image is not explicitly specified. 507ff948bSDaniel P. Berrange# 607ff948bSDaniel P. Berrange# Variant of 097, which includes snapshots to test different codepath 707ff948bSDaniel P. Berrange# in qcow2 807ff948bSDaniel P. Berrange# 907ff948bSDaniel P. Berrange# Copyright (C) 2014 Red Hat, Inc. 1007ff948bSDaniel P. Berrange# 1107ff948bSDaniel P. Berrange# This program is free software; you can redistribute it and/or modify 1207ff948bSDaniel P. Berrange# it under the terms of the GNU General Public License as published by 1307ff948bSDaniel P. Berrange# the Free Software Foundation; either version 2 of the License, or 1407ff948bSDaniel P. Berrange# (at your option) any later version. 1507ff948bSDaniel P. Berrange# 1607ff948bSDaniel P. Berrange# This program is distributed in the hope that it will be useful, 1707ff948bSDaniel P. Berrange# but WITHOUT ANY WARRANTY; without even the implied warranty of 1807ff948bSDaniel P. Berrange# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 1907ff948bSDaniel P. Berrange# GNU General Public License for more details. 2007ff948bSDaniel P. Berrange# 2107ff948bSDaniel P. Berrange# You should have received a copy of the GNU General Public License 2207ff948bSDaniel P. Berrange# along with this program. If not, see <http://www.gnu.org/licenses/>. 2307ff948bSDaniel P. Berrange# 2407ff948bSDaniel P. Berrange 2507ff948bSDaniel P. Berrange# creator 2607ff948bSDaniel P. Berrangeowner=mreitz@redhat.com 2707ff948bSDaniel P. Berrange 2807ff948bSDaniel P. Berrangeseq="$(basename $0)" 2907ff948bSDaniel P. Berrangeecho "QA output created by $seq" 3007ff948bSDaniel P. Berrange 3107ff948bSDaniel P. Berrangehere="$PWD" 3207ff948bSDaniel P. Berrangestatus=1 # failure is the default! 3307ff948bSDaniel P. Berrange 3407ff948bSDaniel P. Berrange_cleanup() 3507ff948bSDaniel P. Berrange{ 3607ff948bSDaniel P. Berrange _cleanup_test_img 3707ff948bSDaniel P. Berrange _rm_test_img "$TEST_IMG.itmd" 3807ff948bSDaniel P. Berrange} 3907ff948bSDaniel P. Berrangetrap "_cleanup; exit \$status" 0 1 2 3 15 4007ff948bSDaniel P. Berrange 4107ff948bSDaniel P. Berrange# get standard environment, filters and checks 4207ff948bSDaniel P. Berrange. ./common.rc 4307ff948bSDaniel P. Berrange. ./common.filter 4407ff948bSDaniel P. Berrange. ./common.pattern 4507ff948bSDaniel P. Berrange 4607ff948bSDaniel P. Berrange# Any format supporting backing files and bdrv_make_empty 4707ff948bSDaniel P. Berrange_supported_fmt qcow2 4807ff948bSDaniel P. Berrange_supported_proto file 4907ff948bSDaniel P. Berrange_supported_os Linux 5007ff948bSDaniel P. Berrange 5107ff948bSDaniel P. Berrange 5207ff948bSDaniel P. Berrange# Four passes: 5307ff948bSDaniel P. Berrange# 0: Two-layer backing chain, commit to upper backing file (implicitly) 5407ff948bSDaniel P. Berrange# (in this case, the top image will be emptied) 5507ff948bSDaniel P. Berrange# 1: Two-layer backing chain, commit to upper backing file (explicitly) 5607ff948bSDaniel P. Berrange# (in this case, the top image will implicitly stay unchanged) 5707ff948bSDaniel P. Berrange# 2: Two-layer backing chain, commit to upper backing file (implicitly with -d) 5807ff948bSDaniel P. Berrange# (in this case, the top image will explicitly stay unchanged) 5907ff948bSDaniel P. Berrange# 3: Two-layer backing chain, commit to lower backing file 6007ff948bSDaniel P. Berrange# (in this case, the top image will implicitly stay unchanged) 6107ff948bSDaniel P. Berrange# 6207ff948bSDaniel P. Berrange# 020 already tests committing, so this only tests whether image chains are 6307ff948bSDaniel P. Berrange# working properly and that all images above the base are emptied; therefore, 6407ff948bSDaniel P. Berrange# no complicated patterns are necessary. Check near the 2G mark, as qcow2 6507ff948bSDaniel P. Berrange# has been buggy at that boundary in the past. 6607ff948bSDaniel P. Berrangefor i in 0 1 2 3; do 6707ff948bSDaniel P. Berrange 6807ff948bSDaniel P. Berrangeecho 6907ff948bSDaniel P. Berrangeecho "=== Test pass $i ===" 7007ff948bSDaniel P. Berrangeecho 7107ff948bSDaniel P. Berrange 72*f82c5b17SEric Blakelen=$((2100 * 1024 * 1024 + 512)) # larger than 2G, and not cluster aligned 73*f82c5b17SEric BlakeTEST_IMG="$TEST_IMG.base" _make_test_img $len 74*f82c5b17SEric BlakeTEST_IMG="$TEST_IMG.itmd" _make_test_img -b "$TEST_IMG.base" $len 75*f82c5b17SEric Blake_make_test_img -b "$TEST_IMG.itmd" $len 7607ff948bSDaniel P. Berrange$QEMU_IMG snapshot -c snap "$TEST_IMG" 7707ff948bSDaniel P. Berrange 78*f82c5b17SEric Blake$QEMU_IO -c "write -P 1 0x7ffd0000 192k" "$TEST_IMG.base" | _filter_qemu_io 79*f82c5b17SEric Blake$QEMU_IO -c "write -P 2 0x7ffe0000 128k" "$TEST_IMG.itmd" | _filter_qemu_io 80*f82c5b17SEric Blake$QEMU_IO -c "write -P 3 0x7fff0000 64k" "$TEST_IMG" | _filter_qemu_io 81*f82c5b17SEric Blake$QEMU_IO -c "write -P 4 $(($len - 512)) 512" "$TEST_IMG" | _filter_qemu_io 8207ff948bSDaniel P. Berrange 8307ff948bSDaniel P. Berrangeif [ $i -lt 3 ]; then 8407ff948bSDaniel P. Berrange if [ $i == 0 ]; then 8507ff948bSDaniel P. Berrange # -b "$TEST_IMG.itmd" should be the default (that is, committing to the 8607ff948bSDaniel P. Berrange # first backing file in the chain) 8707ff948bSDaniel P. Berrange $QEMU_IMG commit "$TEST_IMG" 8807ff948bSDaniel P. Berrange elif [ $i == 1 ]; then 8907ff948bSDaniel P. Berrange # explicitly specify the commit target (this should imply -d) 9007ff948bSDaniel P. Berrange $QEMU_IMG commit -b "$TEST_IMG.itmd" "$TEST_IMG" 9107ff948bSDaniel P. Berrange else 9207ff948bSDaniel P. Berrange # do not explicitly specify the commit target, but use -d to leave the 9307ff948bSDaniel P. Berrange # top image unchanged 9407ff948bSDaniel P. Berrange $QEMU_IMG commit -d "$TEST_IMG" 9507ff948bSDaniel P. Berrange fi 9607ff948bSDaniel P. Berrange 9707ff948bSDaniel P. Berrange # Bottom should be unchanged 9807ff948bSDaniel P. Berrange $QEMU_IO -c 'read -P 1 0x7ffd0000 192k' "$TEST_IMG.base" | _filter_qemu_io 99*f82c5b17SEric Blake $QEMU_IO -c "read -P 0 $((len - 512)) 512" "$TEST_IMG.base" | _filter_qemu_io 10007ff948bSDaniel P. Berrange 10107ff948bSDaniel P. Berrange # Intermediate should contain changes from top 10207ff948bSDaniel P. Berrange $QEMU_IO -c 'read -P 1 0x7ffd0000 64k' "$TEST_IMG.itmd" | _filter_qemu_io 10307ff948bSDaniel P. Berrange $QEMU_IO -c 'read -P 2 0x7ffe0000 64k' "$TEST_IMG.itmd" | _filter_qemu_io 10407ff948bSDaniel P. Berrange $QEMU_IO -c 'read -P 3 0x7fff0000 64k' "$TEST_IMG.itmd" | _filter_qemu_io 105*f82c5b17SEric Blake $QEMU_IO -c "read -P 4 $((len - 512)) 512" "$TEST_IMG.itmd" | _filter_qemu_io 10607ff948bSDaniel P. Berrange 10707ff948bSDaniel P. Berrange # And in pass 0, the top image should be empty, whereas in both other passes 10807ff948bSDaniel P. Berrange # it should be unchanged (which is both checked by qemu-img map) 10907ff948bSDaniel P. Berrangeelse 11007ff948bSDaniel P. Berrange $QEMU_IMG commit -b "$TEST_IMG.base" "$TEST_IMG" 11107ff948bSDaniel P. Berrange 11207ff948bSDaniel P. Berrange # Bottom should contain all changes 11307ff948bSDaniel P. Berrange $QEMU_IO -c 'read -P 1 0x7ffd0000 64k' "$TEST_IMG.base" | _filter_qemu_io 11407ff948bSDaniel P. Berrange $QEMU_IO -c 'read -P 2 0x7ffe0000 64k' "$TEST_IMG.base" | _filter_qemu_io 11507ff948bSDaniel P. Berrange $QEMU_IO -c 'read -P 3 0x7fff0000 64k' "$TEST_IMG.base" | _filter_qemu_io 116*f82c5b17SEric Blake $QEMU_IO -c "read -P 4 $((len - 512)) 512" "$TEST_IMG.base" | _filter_qemu_io 11707ff948bSDaniel P. Berrange 11807ff948bSDaniel P. Berrange # Both top and intermediate should be unchanged 11907ff948bSDaniel P. Berrangefi 12007ff948bSDaniel P. Berrange 12107ff948bSDaniel P. Berrange$QEMU_IMG map "$TEST_IMG.base" | _filter_qemu_img_map 12207ff948bSDaniel P. Berrange$QEMU_IMG map "$TEST_IMG.itmd" | _filter_qemu_img_map 12307ff948bSDaniel P. Berrange$QEMU_IMG map "$TEST_IMG" | _filter_qemu_img_map 12407ff948bSDaniel P. Berrange 12507ff948bSDaniel P. Berrangedone 12607ff948bSDaniel P. Berrange 12707ff948bSDaniel P. Berrange 12807ff948bSDaniel P. Berrange# success, all done 12907ff948bSDaniel P. Berrangeecho "*** done" 13007ff948bSDaniel P. Berrangerm -f $seq.full 13107ff948bSDaniel P. Berrangestatus=0 132