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# 64096974eSEric Blake# Variant of 097, which includes snapshots and persistent bitmaps, to 74096974eSEric Blake# tickle the slow codepath in qcow2. See also 198, for another feature 84096974eSEric Blake# that tickles the slow codepath. 907ff948bSDaniel P. Berrange# 104096974eSEric Blake# Copyright (C) 2014, 2017 Red Hat, Inc. 1107ff948bSDaniel P. Berrange# 1207ff948bSDaniel P. Berrange# This program is free software; you can redistribute it and/or modify 1307ff948bSDaniel P. Berrange# it under the terms of the GNU General Public License as published by 1407ff948bSDaniel P. Berrange# the Free Software Foundation; either version 2 of the License, or 1507ff948bSDaniel P. Berrange# (at your option) any later version. 1607ff948bSDaniel P. Berrange# 1707ff948bSDaniel P. Berrange# This program is distributed in the hope that it will be useful, 1807ff948bSDaniel P. Berrange# but WITHOUT ANY WARRANTY; without even the implied warranty of 1907ff948bSDaniel P. Berrange# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 2007ff948bSDaniel P. Berrange# GNU General Public License for more details. 2107ff948bSDaniel P. Berrange# 2207ff948bSDaniel P. Berrange# You should have received a copy of the GNU General Public License 2307ff948bSDaniel P. Berrange# along with this program. If not, see <http://www.gnu.org/licenses/>. 2407ff948bSDaniel P. Berrange# 2507ff948bSDaniel P. Berrange 2607ff948bSDaniel P. Berrange# creator 2707ff948bSDaniel P. Berrangeowner=mreitz@redhat.com 2807ff948bSDaniel P. Berrange 2907ff948bSDaniel P. Berrangeseq="$(basename $0)" 3007ff948bSDaniel P. Berrangeecho "QA output created by $seq" 3107ff948bSDaniel P. Berrange 3207ff948bSDaniel P. Berrangehere="$PWD" 3307ff948bSDaniel P. Berrangestatus=1 # failure is the default! 3407ff948bSDaniel P. Berrange 3507ff948bSDaniel P. Berrange_cleanup() 3607ff948bSDaniel P. Berrange{ 3707ff948bSDaniel P. Berrange _cleanup_test_img 3807ff948bSDaniel P. Berrange _rm_test_img "$TEST_IMG.itmd" 3907ff948bSDaniel P. Berrange} 4007ff948bSDaniel P. Berrangetrap "_cleanup; exit \$status" 0 1 2 3 15 4107ff948bSDaniel P. Berrange 4207ff948bSDaniel P. Berrange# get standard environment, filters and checks 4307ff948bSDaniel P. Berrange. ./common.rc 4407ff948bSDaniel P. Berrange. ./common.filter 4507ff948bSDaniel P. Berrange. ./common.pattern 4607ff948bSDaniel P. Berrange 474096974eSEric Blake# This test is specific to qcow2 4807ff948bSDaniel P. Berrange_supported_fmt qcow2 4907ff948bSDaniel P. Berrange_supported_proto file 5007ff948bSDaniel P. Berrange_supported_os Linux 5194254c9bSMax Reitz# Persistent dirty bitmaps require compat=1.1 5294254c9bSMax Reitz_unsupported_imgopts 'compat=0.10' 5307ff948bSDaniel P. Berrange 544096974eSEric Blakefunction run_qemu() 554096974eSEric Blake{ 564096974eSEric Blake $QEMU -nographic -qmp stdio -serial none "$@" 2>&1 \ 572807746fSEric Blake | _filter_testdir | _filter_qmp | _filter_qemu \ 582807746fSEric Blake | sed 's/"sha256": ".\{64\}"/"sha256": HASH/' 594096974eSEric Blake} 604096974eSEric Blake 614096974eSEric Blakefor reason in snapshot bitmap; do 6207ff948bSDaniel P. Berrange 6307ff948bSDaniel P. Berrange# Four passes: 6407ff948bSDaniel P. Berrange# 0: Two-layer backing chain, commit to upper backing file (implicitly) 6507ff948bSDaniel P. Berrange# (in this case, the top image will be emptied) 6607ff948bSDaniel P. Berrange# 1: Two-layer backing chain, commit to upper backing file (explicitly) 6707ff948bSDaniel P. Berrange# (in this case, the top image will implicitly stay unchanged) 6807ff948bSDaniel P. Berrange# 2: Two-layer backing chain, commit to upper backing file (implicitly with -d) 6907ff948bSDaniel P. Berrange# (in this case, the top image will explicitly stay unchanged) 7007ff948bSDaniel P. Berrange# 3: Two-layer backing chain, commit to lower backing file 7107ff948bSDaniel P. Berrange# (in this case, the top image will implicitly stay unchanged) 7207ff948bSDaniel P. Berrange# 7307ff948bSDaniel P. Berrange# 020 already tests committing, so this only tests whether image chains are 7407ff948bSDaniel P. Berrange# working properly and that all images above the base are emptied; therefore, 7507ff948bSDaniel P. Berrange# no complicated patterns are necessary. Check near the 2G mark, as qcow2 7607ff948bSDaniel P. Berrange# has been buggy at that boundary in the past. 7707ff948bSDaniel P. Berrangefor i in 0 1 2 3; do 7807ff948bSDaniel P. Berrange 7907ff948bSDaniel P. Berrangeecho 804096974eSEric Blakeecho "=== Test pass $reason.$i ===" 8107ff948bSDaniel P. Berrangeecho 8207ff948bSDaniel P. Berrange 83f82c5b17SEric Blakelen=$((2100 * 1024 * 1024 + 512)) # larger than 2G, and not cluster aligned 84f82c5b17SEric BlakeTEST_IMG="$TEST_IMG.base" _make_test_img $len 85f82c5b17SEric BlakeTEST_IMG="$TEST_IMG.itmd" _make_test_img -b "$TEST_IMG.base" $len 86f82c5b17SEric Blake_make_test_img -b "$TEST_IMG.itmd" $len 874096974eSEric Blake# Update the top image to use a feature that is incompatible with fast path 884096974eSEric Blakecase $reason in 894096974eSEric Blake snapshot) $QEMU_IMG snapshot -c snap "$TEST_IMG" ;; 904096974eSEric Blake bitmap) 914096974eSEric Blake run_qemu <<EOF 924096974eSEric Blake{ "execute": "qmp_capabilities" } 934096974eSEric Blake{ "execute": "blockdev-add", 944096974eSEric Blake "arguments": { "driver": "qcow2", "node-name": "drive0", 954096974eSEric Blake "file": { "driver": "file", "filename": "$TEST_IMG" } } } 964096974eSEric Blake{ "execute": "block-dirty-bitmap-add", 974096974eSEric Blake "arguments": { "node": "drive0", "name": "bitmap0", 98*3e99da5eSVladimir Sementsov-Ogievskiy "persistent": true } } 994096974eSEric Blake{ "execute": "quit" } 1004096974eSEric BlakeEOF 1014096974eSEric Blake ;; 1024096974eSEric Blakeesac 10307ff948bSDaniel P. Berrange 104f82c5b17SEric Blake$QEMU_IO -c "write -P 1 0x7ffd0000 192k" "$TEST_IMG.base" | _filter_qemu_io 105f82c5b17SEric Blake$QEMU_IO -c "write -P 2 0x7ffe0000 128k" "$TEST_IMG.itmd" | _filter_qemu_io 106f82c5b17SEric Blake$QEMU_IO -c "write -P 3 0x7fff0000 64k" "$TEST_IMG" | _filter_qemu_io 107f82c5b17SEric Blake$QEMU_IO -c "write -P 4 $(($len - 512)) 512" "$TEST_IMG" | _filter_qemu_io 10807ff948bSDaniel P. Berrange 10907ff948bSDaniel P. Berrangeif [ $i -lt 3 ]; then 11007ff948bSDaniel P. Berrange if [ $i == 0 ]; then 11107ff948bSDaniel P. Berrange # -b "$TEST_IMG.itmd" should be the default (that is, committing to the 11207ff948bSDaniel P. Berrange # first backing file in the chain) 11307ff948bSDaniel P. Berrange $QEMU_IMG commit "$TEST_IMG" 11407ff948bSDaniel P. Berrange elif [ $i == 1 ]; then 11507ff948bSDaniel P. Berrange # explicitly specify the commit target (this should imply -d) 11607ff948bSDaniel P. Berrange $QEMU_IMG commit -b "$TEST_IMG.itmd" "$TEST_IMG" 11707ff948bSDaniel P. Berrange else 11807ff948bSDaniel P. Berrange # do not explicitly specify the commit target, but use -d to leave the 11907ff948bSDaniel P. Berrange # top image unchanged 12007ff948bSDaniel P. Berrange $QEMU_IMG commit -d "$TEST_IMG" 12107ff948bSDaniel P. Berrange fi 12207ff948bSDaniel P. Berrange 12307ff948bSDaniel P. Berrange # Bottom should be unchanged 12407ff948bSDaniel P. Berrange $QEMU_IO -c 'read -P 1 0x7ffd0000 192k' "$TEST_IMG.base" | _filter_qemu_io 125f82c5b17SEric Blake $QEMU_IO -c "read -P 0 $((len - 512)) 512" "$TEST_IMG.base" | _filter_qemu_io 12607ff948bSDaniel P. Berrange 12707ff948bSDaniel P. Berrange # Intermediate should contain changes from top 12807ff948bSDaniel P. Berrange $QEMU_IO -c 'read -P 1 0x7ffd0000 64k' "$TEST_IMG.itmd" | _filter_qemu_io 12907ff948bSDaniel P. Berrange $QEMU_IO -c 'read -P 2 0x7ffe0000 64k' "$TEST_IMG.itmd" | _filter_qemu_io 13007ff948bSDaniel P. Berrange $QEMU_IO -c 'read -P 3 0x7fff0000 64k' "$TEST_IMG.itmd" | _filter_qemu_io 131f82c5b17SEric Blake $QEMU_IO -c "read -P 4 $((len - 512)) 512" "$TEST_IMG.itmd" | _filter_qemu_io 13207ff948bSDaniel P. Berrange 13307ff948bSDaniel P. Berrange # And in pass 0, the top image should be empty, whereas in both other passes 13407ff948bSDaniel P. Berrange # it should be unchanged (which is both checked by qemu-img map) 13507ff948bSDaniel P. Berrangeelse 13607ff948bSDaniel P. Berrange $QEMU_IMG commit -b "$TEST_IMG.base" "$TEST_IMG" 13707ff948bSDaniel P. Berrange 13807ff948bSDaniel P. Berrange # Bottom should contain all changes 13907ff948bSDaniel P. Berrange $QEMU_IO -c 'read -P 1 0x7ffd0000 64k' "$TEST_IMG.base" | _filter_qemu_io 14007ff948bSDaniel P. Berrange $QEMU_IO -c 'read -P 2 0x7ffe0000 64k' "$TEST_IMG.base" | _filter_qemu_io 14107ff948bSDaniel P. Berrange $QEMU_IO -c 'read -P 3 0x7fff0000 64k' "$TEST_IMG.base" | _filter_qemu_io 142f82c5b17SEric Blake $QEMU_IO -c "read -P 4 $((len - 512)) 512" "$TEST_IMG.base" | _filter_qemu_io 14307ff948bSDaniel P. Berrange 14407ff948bSDaniel P. Berrange # Both top and intermediate should be unchanged 14507ff948bSDaniel P. Berrangefi 14607ff948bSDaniel P. Berrange 14707ff948bSDaniel P. Berrange$QEMU_IMG map "$TEST_IMG.base" | _filter_qemu_img_map 14807ff948bSDaniel P. Berrange$QEMU_IMG map "$TEST_IMG.itmd" | _filter_qemu_img_map 14907ff948bSDaniel P. Berrange$QEMU_IMG map "$TEST_IMG" | _filter_qemu_img_map 15007ff948bSDaniel P. Berrange 1514096974eSEric Blake# Check that the reason for slow path is still present, as appropriate 1524096974eSEric Blakecase $reason in 1534096974eSEric Blake snapshot) 1544096974eSEric Blake $QEMU_IMG snapshot -l "$TEST_IMG" | 1554096974eSEric Blake sed 's/^\(.\{20\}\).*/\1/; s/ *$//' ;; 1564096974eSEric Blake bitmap) 1574096974eSEric Blake run_qemu <<EOF 1584096974eSEric Blake{ "execute": "qmp_capabilities" } 1594096974eSEric Blake{ "execute": "blockdev-add", 1604096974eSEric Blake "arguments": { "driver": "qcow2", "node-name": "drive0", 1614096974eSEric Blake "file": { "driver": "file", "filename": "$TEST_IMG" } } } 1624096974eSEric Blake{ "execute": "x-debug-block-dirty-bitmap-sha256", 1634096974eSEric Blake "arguments": { "node": "drive0", "name": "bitmap0" } } 1644096974eSEric Blake{ "execute": "quit" } 1654096974eSEric BlakeEOF 1664096974eSEric Blake ;; 1674096974eSEric Blakeesac 16807ff948bSDaniel P. Berrange 1694096974eSEric Blakedone 1704096974eSEric Blakedone 17107ff948bSDaniel P. Berrange 17207ff948bSDaniel P. Berrange# success, all done 17307ff948bSDaniel P. Berrangeecho "*** done" 17407ff948bSDaniel P. Berrangerm -f $seq.full 17507ff948bSDaniel P. Berrangestatus=0 176