111a82d14SPhilippe Mathieu-Daudé#!/usr/bin/env 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. 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 464096974eSEric Blake# This test is specific to qcow2 4707ff948bSDaniel P. Berrange_supported_fmt qcow2 4807ff948bSDaniel P. Berrange_supported_proto file 4907ff948bSDaniel P. Berrange_supported_os Linux 50*3be2024aSMax Reitz# Persistent dirty bitmaps require compat=1.1; 51*3be2024aSMax Reitz# Internal snapshots forbid using an external data file 52*3be2024aSMax Reitz# (they work with refcount_bits=1 here, though, because there actually 53*3be2024aSMax Reitz# is no data when creating the snapshot) 54*3be2024aSMax Reitz_unsupported_imgopts 'compat=0.10' data_file 5507ff948bSDaniel P. Berrange 568cedcffdSEric Blakerun_qemu() 574096974eSEric Blake{ 584096974eSEric Blake $QEMU -nographic -qmp stdio -serial none "$@" 2>&1 \ 592807746fSEric Blake | _filter_testdir | _filter_qmp | _filter_qemu \ 602807746fSEric Blake | sed 's/"sha256": ".\{64\}"/"sha256": HASH/' 614096974eSEric Blake} 624096974eSEric Blake 634096974eSEric Blakefor reason in snapshot bitmap; do 6407ff948bSDaniel P. Berrange 6507ff948bSDaniel P. Berrange# Four passes: 6607ff948bSDaniel P. Berrange# 0: Two-layer backing chain, commit to upper backing file (implicitly) 6707ff948bSDaniel P. Berrange# (in this case, the top image will be emptied) 6807ff948bSDaniel P. Berrange# 1: Two-layer backing chain, commit to upper backing file (explicitly) 6907ff948bSDaniel P. Berrange# (in this case, the top image will implicitly stay unchanged) 7007ff948bSDaniel P. Berrange# 2: Two-layer backing chain, commit to upper backing file (implicitly with -d) 7107ff948bSDaniel P. Berrange# (in this case, the top image will explicitly stay unchanged) 7207ff948bSDaniel P. Berrange# 3: Two-layer backing chain, commit to lower backing file 7307ff948bSDaniel P. Berrange# (in this case, the top image will implicitly stay unchanged) 7407ff948bSDaniel P. Berrange# 7507ff948bSDaniel P. Berrange# 020 already tests committing, so this only tests whether image chains are 7607ff948bSDaniel P. Berrange# working properly and that all images above the base are emptied; therefore, 7707ff948bSDaniel P. Berrange# no complicated patterns are necessary. Check near the 2G mark, as qcow2 7807ff948bSDaniel P. Berrange# has been buggy at that boundary in the past. 7907ff948bSDaniel P. Berrangefor i in 0 1 2 3; do 8007ff948bSDaniel P. Berrange 8107ff948bSDaniel P. Berrangeecho 824096974eSEric Blakeecho "=== Test pass $reason.$i ===" 8307ff948bSDaniel P. Berrangeecho 8407ff948bSDaniel P. Berrange 85f82c5b17SEric Blakelen=$((2100 * 1024 * 1024 + 512)) # larger than 2G, and not cluster aligned 86f82c5b17SEric BlakeTEST_IMG="$TEST_IMG.base" _make_test_img $len 87f82c5b17SEric BlakeTEST_IMG="$TEST_IMG.itmd" _make_test_img -b "$TEST_IMG.base" $len 88f82c5b17SEric Blake_make_test_img -b "$TEST_IMG.itmd" $len 894096974eSEric Blake# Update the top image to use a feature that is incompatible with fast path 904096974eSEric Blakecase $reason in 914096974eSEric Blake snapshot) $QEMU_IMG snapshot -c snap "$TEST_IMG" ;; 924096974eSEric Blake bitmap) 934096974eSEric Blake run_qemu <<EOF 944096974eSEric Blake{ "execute": "qmp_capabilities" } 954096974eSEric Blake{ "execute": "blockdev-add", 964096974eSEric Blake "arguments": { "driver": "qcow2", "node-name": "drive0", 974096974eSEric Blake "file": { "driver": "file", "filename": "$TEST_IMG" } } } 984096974eSEric Blake{ "execute": "block-dirty-bitmap-add", 994096974eSEric Blake "arguments": { "node": "drive0", "name": "bitmap0", 1003e99da5eSVladimir Sementsov-Ogievskiy "persistent": true } } 1014096974eSEric Blake{ "execute": "quit" } 1024096974eSEric BlakeEOF 1034096974eSEric Blake ;; 1044096974eSEric Blakeesac 10507ff948bSDaniel P. Berrange 106f82c5b17SEric Blake$QEMU_IO -c "write -P 1 0x7ffd0000 192k" "$TEST_IMG.base" | _filter_qemu_io 107f82c5b17SEric Blake$QEMU_IO -c "write -P 2 0x7ffe0000 128k" "$TEST_IMG.itmd" | _filter_qemu_io 108f82c5b17SEric Blake$QEMU_IO -c "write -P 3 0x7fff0000 64k" "$TEST_IMG" | _filter_qemu_io 109f82c5b17SEric Blake$QEMU_IO -c "write -P 4 $(($len - 512)) 512" "$TEST_IMG" | _filter_qemu_io 11007ff948bSDaniel P. Berrange 11107ff948bSDaniel P. Berrangeif [ $i -lt 3 ]; then 11207ff948bSDaniel P. Berrange if [ $i == 0 ]; then 11307ff948bSDaniel P. Berrange # -b "$TEST_IMG.itmd" should be the default (that is, committing to the 11407ff948bSDaniel P. Berrange # first backing file in the chain) 11507ff948bSDaniel P. Berrange $QEMU_IMG commit "$TEST_IMG" 11607ff948bSDaniel P. Berrange elif [ $i == 1 ]; then 11707ff948bSDaniel P. Berrange # explicitly specify the commit target (this should imply -d) 11807ff948bSDaniel P. Berrange $QEMU_IMG commit -b "$TEST_IMG.itmd" "$TEST_IMG" 11907ff948bSDaniel P. Berrange else 12007ff948bSDaniel P. Berrange # do not explicitly specify the commit target, but use -d to leave the 12107ff948bSDaniel P. Berrange # top image unchanged 12207ff948bSDaniel P. Berrange $QEMU_IMG commit -d "$TEST_IMG" 12307ff948bSDaniel P. Berrange fi 12407ff948bSDaniel P. Berrange 12507ff948bSDaniel P. Berrange # Bottom should be unchanged 12607ff948bSDaniel P. Berrange $QEMU_IO -c 'read -P 1 0x7ffd0000 192k' "$TEST_IMG.base" | _filter_qemu_io 127f82c5b17SEric Blake $QEMU_IO -c "read -P 0 $((len - 512)) 512" "$TEST_IMG.base" | _filter_qemu_io 12807ff948bSDaniel P. Berrange 12907ff948bSDaniel P. Berrange # Intermediate should contain changes from top 13007ff948bSDaniel P. Berrange $QEMU_IO -c 'read -P 1 0x7ffd0000 64k' "$TEST_IMG.itmd" | _filter_qemu_io 13107ff948bSDaniel P. Berrange $QEMU_IO -c 'read -P 2 0x7ffe0000 64k' "$TEST_IMG.itmd" | _filter_qemu_io 13207ff948bSDaniel P. Berrange $QEMU_IO -c 'read -P 3 0x7fff0000 64k' "$TEST_IMG.itmd" | _filter_qemu_io 133f82c5b17SEric Blake $QEMU_IO -c "read -P 4 $((len - 512)) 512" "$TEST_IMG.itmd" | _filter_qemu_io 13407ff948bSDaniel P. Berrange 13507ff948bSDaniel P. Berrange # And in pass 0, the top image should be empty, whereas in both other passes 13607ff948bSDaniel P. Berrange # it should be unchanged (which is both checked by qemu-img map) 13707ff948bSDaniel P. Berrangeelse 13807ff948bSDaniel P. Berrange $QEMU_IMG commit -b "$TEST_IMG.base" "$TEST_IMG" 13907ff948bSDaniel P. Berrange 14007ff948bSDaniel P. Berrange # Bottom should contain all changes 14107ff948bSDaniel P. Berrange $QEMU_IO -c 'read -P 1 0x7ffd0000 64k' "$TEST_IMG.base" | _filter_qemu_io 14207ff948bSDaniel P. Berrange $QEMU_IO -c 'read -P 2 0x7ffe0000 64k' "$TEST_IMG.base" | _filter_qemu_io 14307ff948bSDaniel P. Berrange $QEMU_IO -c 'read -P 3 0x7fff0000 64k' "$TEST_IMG.base" | _filter_qemu_io 144f82c5b17SEric Blake $QEMU_IO -c "read -P 4 $((len - 512)) 512" "$TEST_IMG.base" | _filter_qemu_io 14507ff948bSDaniel P. Berrange 14607ff948bSDaniel P. Berrange # Both top and intermediate should be unchanged 14707ff948bSDaniel P. Berrangefi 14807ff948bSDaniel P. Berrange 14907ff948bSDaniel P. Berrange$QEMU_IMG map "$TEST_IMG.base" | _filter_qemu_img_map 15007ff948bSDaniel P. Berrange$QEMU_IMG map "$TEST_IMG.itmd" | _filter_qemu_img_map 15107ff948bSDaniel P. Berrange$QEMU_IMG map "$TEST_IMG" | _filter_qemu_img_map 15207ff948bSDaniel P. Berrange 1534096974eSEric Blake# Check that the reason for slow path is still present, as appropriate 1544096974eSEric Blakecase $reason in 1554096974eSEric Blake snapshot) 1564096974eSEric Blake $QEMU_IMG snapshot -l "$TEST_IMG" | 1574096974eSEric Blake sed 's/^\(.\{20\}\).*/\1/; s/ *$//' ;; 1584096974eSEric Blake bitmap) 1594096974eSEric Blake run_qemu <<EOF 1604096974eSEric Blake{ "execute": "qmp_capabilities" } 1614096974eSEric Blake{ "execute": "blockdev-add", 1624096974eSEric Blake "arguments": { "driver": "qcow2", "node-name": "drive0", 1634096974eSEric Blake "file": { "driver": "file", "filename": "$TEST_IMG" } } } 1644096974eSEric Blake{ "execute": "x-debug-block-dirty-bitmap-sha256", 1654096974eSEric Blake "arguments": { "node": "drive0", "name": "bitmap0" } } 1664096974eSEric Blake{ "execute": "quit" } 1674096974eSEric BlakeEOF 1684096974eSEric Blake ;; 1694096974eSEric Blakeesac 17007ff948bSDaniel P. Berrange 1714096974eSEric Blakedone 1724096974eSEric Blakedone 17307ff948bSDaniel P. Berrange 17407ff948bSDaniel P. Berrange# success, all done 17507ff948bSDaniel P. Berrangeecho "*** done" 17607ff948bSDaniel P. Berrangerm -f $seq.full 17707ff948bSDaniel P. Berrangestatus=0 178