111a82d14SPhilippe Mathieu-Daudé#!/usr/bin/env bash 29dd003a9SVladimir Sementsov-Ogievskiy# group: rw auto backing 307ff948bSDaniel P. Berrange# 407ff948bSDaniel P. Berrange# Commit changes into backing chains and empty the top image if the 507ff948bSDaniel P. Berrange# backing image is not explicitly specified. 607ff948bSDaniel P. Berrange# 74096974eSEric Blake# Variant of 097, which includes snapshots and persistent bitmaps, to 84096974eSEric Blake# tickle the slow codepath in qcow2. See also 198, for another feature 94096974eSEric Blake# that tickles the slow codepath. 1007ff948bSDaniel P. Berrange# 114096974eSEric Blake# Copyright (C) 2014, 2017 Red Hat, Inc. 1207ff948bSDaniel P. Berrange# 1307ff948bSDaniel P. Berrange# This program is free software; you can redistribute it and/or modify 1407ff948bSDaniel P. Berrange# it under the terms of the GNU General Public License as published by 1507ff948bSDaniel P. Berrange# the Free Software Foundation; either version 2 of the License, or 1607ff948bSDaniel P. Berrange# (at your option) any later version. 1707ff948bSDaniel P. Berrange# 1807ff948bSDaniel P. Berrange# This program is distributed in the hope that it will be useful, 1907ff948bSDaniel P. Berrange# but WITHOUT ANY WARRANTY; without even the implied warranty of 2007ff948bSDaniel P. Berrange# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 2107ff948bSDaniel P. Berrange# GNU General Public License for more details. 2207ff948bSDaniel P. Berrange# 2307ff948bSDaniel P. Berrange# You should have received a copy of the GNU General Public License 2407ff948bSDaniel P. Berrange# along with this program. If not, see <http://www.gnu.org/licenses/>. 2507ff948bSDaniel P. Berrange# 2607ff948bSDaniel P. Berrange 2707ff948bSDaniel P. Berrange# creator 28*42a5009dSJohn Snowowner=hreitz@redhat.com 2907ff948bSDaniel P. Berrange 3007ff948bSDaniel P. Berrangeseq="$(basename $0)" 3107ff948bSDaniel P. Berrangeecho "QA output created by $seq" 3207ff948bSDaniel P. Berrange 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 4957284d2aSMax Reitz_supported_proto file fuse 5007ff948bSDaniel P. Berrange_supported_os Linux 513be2024aSMax Reitz# Persistent dirty bitmaps require compat=1.1; 523be2024aSMax Reitz# Internal snapshots forbid using an external data file 533be2024aSMax Reitz# (they work with refcount_bits=1 here, though, because there actually 543be2024aSMax Reitz# is no data when creating the snapshot) 553be2024aSMax Reitz_unsupported_imgopts 'compat=0.10' data_file 5607ff948bSDaniel P. Berrange 578cedcffdSEric Blakerun_qemu() 584096974eSEric Blake{ 594096974eSEric Blake $QEMU -nographic -qmp stdio -serial none "$@" 2>&1 \ 602807746fSEric Blake | _filter_testdir | _filter_qmp | _filter_qemu \ 612807746fSEric Blake | sed 's/"sha256": ".\{64\}"/"sha256": HASH/' 624096974eSEric Blake} 634096974eSEric Blake 644096974eSEric Blakefor reason in snapshot bitmap; do 6507ff948bSDaniel P. Berrange 6607ff948bSDaniel P. Berrange# Four passes: 6707ff948bSDaniel P. Berrange# 0: Two-layer backing chain, commit to upper backing file (implicitly) 6807ff948bSDaniel P. Berrange# (in this case, the top image will be emptied) 6907ff948bSDaniel P. Berrange# 1: Two-layer backing chain, commit to upper backing file (explicitly) 7007ff948bSDaniel P. Berrange# (in this case, the top image will implicitly stay unchanged) 7107ff948bSDaniel P. Berrange# 2: Two-layer backing chain, commit to upper backing file (implicitly with -d) 7207ff948bSDaniel P. Berrange# (in this case, the top image will explicitly stay unchanged) 7307ff948bSDaniel P. Berrange# 3: Two-layer backing chain, commit to lower backing file 7407ff948bSDaniel P. Berrange# (in this case, the top image will implicitly stay unchanged) 7507ff948bSDaniel P. Berrange# 7607ff948bSDaniel P. Berrange# 020 already tests committing, so this only tests whether image chains are 7707ff948bSDaniel P. Berrange# working properly and that all images above the base are emptied; therefore, 7807ff948bSDaniel P. Berrange# no complicated patterns are necessary. Check near the 2G mark, as qcow2 7907ff948bSDaniel P. Berrange# has been buggy at that boundary in the past. 8007ff948bSDaniel P. Berrangefor i in 0 1 2 3; do 8107ff948bSDaniel P. Berrange 8207ff948bSDaniel P. Berrangeecho 834096974eSEric Blakeecho "=== Test pass $reason.$i ===" 8407ff948bSDaniel P. Berrangeecho 8507ff948bSDaniel P. Berrange 86f82c5b17SEric Blakelen=$((2100 * 1024 * 1024 + 512)) # larger than 2G, and not cluster aligned 87f82c5b17SEric BlakeTEST_IMG="$TEST_IMG.base" _make_test_img $len 88b66ff2c2SEric BlakeTEST_IMG="$TEST_IMG.itmd" _make_test_img -b "$TEST_IMG.base" -F $IMGFMT $len 89b66ff2c2SEric Blake_make_test_img -b "$TEST_IMG.itmd" -F $IMGFMT $len 904096974eSEric Blake# Update the top image to use a feature that is incompatible with fast path 914096974eSEric Blakecase $reason in 924096974eSEric Blake snapshot) $QEMU_IMG snapshot -c snap "$TEST_IMG" ;; 934096974eSEric Blake bitmap) 944096974eSEric Blake run_qemu <<EOF 954096974eSEric Blake{ "execute": "qmp_capabilities" } 964096974eSEric Blake{ "execute": "blockdev-add", 974096974eSEric Blake "arguments": { "driver": "qcow2", "node-name": "drive0", 984096974eSEric Blake "file": { "driver": "file", "filename": "$TEST_IMG" } } } 994096974eSEric Blake{ "execute": "block-dirty-bitmap-add", 1004096974eSEric Blake "arguments": { "node": "drive0", "name": "bitmap0", 1013e99da5eSVladimir Sementsov-Ogievskiy "persistent": true } } 1024096974eSEric Blake{ "execute": "quit" } 1034096974eSEric BlakeEOF 1044096974eSEric Blake ;; 1054096974eSEric Blakeesac 10607ff948bSDaniel P. Berrange 107f82c5b17SEric Blake$QEMU_IO -c "write -P 1 0x7ffd0000 192k" "$TEST_IMG.base" | _filter_qemu_io 108f82c5b17SEric Blake$QEMU_IO -c "write -P 2 0x7ffe0000 128k" "$TEST_IMG.itmd" | _filter_qemu_io 109f82c5b17SEric Blake$QEMU_IO -c "write -P 3 0x7fff0000 64k" "$TEST_IMG" | _filter_qemu_io 110f82c5b17SEric Blake$QEMU_IO -c "write -P 4 $(($len - 512)) 512" "$TEST_IMG" | _filter_qemu_io 11107ff948bSDaniel P. Berrange 11207ff948bSDaniel P. Berrangeif [ $i -lt 3 ]; then 11307ff948bSDaniel P. Berrange if [ $i == 0 ]; then 11407ff948bSDaniel P. Berrange # -b "$TEST_IMG.itmd" should be the default (that is, committing to the 11507ff948bSDaniel P. Berrange # first backing file in the chain) 11607ff948bSDaniel P. Berrange $QEMU_IMG commit "$TEST_IMG" 11707ff948bSDaniel P. Berrange elif [ $i == 1 ]; then 11807ff948bSDaniel P. Berrange # explicitly specify the commit target (this should imply -d) 11907ff948bSDaniel P. Berrange $QEMU_IMG commit -b "$TEST_IMG.itmd" "$TEST_IMG" 12007ff948bSDaniel P. Berrange else 12107ff948bSDaniel P. Berrange # do not explicitly specify the commit target, but use -d to leave the 12207ff948bSDaniel P. Berrange # top image unchanged 12307ff948bSDaniel P. Berrange $QEMU_IMG commit -d "$TEST_IMG" 12407ff948bSDaniel P. Berrange fi 12507ff948bSDaniel P. Berrange 12607ff948bSDaniel P. Berrange # Bottom should be unchanged 12707ff948bSDaniel P. Berrange $QEMU_IO -c 'read -P 1 0x7ffd0000 192k' "$TEST_IMG.base" | _filter_qemu_io 128f82c5b17SEric Blake $QEMU_IO -c "read -P 0 $((len - 512)) 512" "$TEST_IMG.base" | _filter_qemu_io 12907ff948bSDaniel P. Berrange 13007ff948bSDaniel P. Berrange # Intermediate should contain changes from top 13107ff948bSDaniel P. Berrange $QEMU_IO -c 'read -P 1 0x7ffd0000 64k' "$TEST_IMG.itmd" | _filter_qemu_io 13207ff948bSDaniel P. Berrange $QEMU_IO -c 'read -P 2 0x7ffe0000 64k' "$TEST_IMG.itmd" | _filter_qemu_io 13307ff948bSDaniel P. Berrange $QEMU_IO -c 'read -P 3 0x7fff0000 64k' "$TEST_IMG.itmd" | _filter_qemu_io 134f82c5b17SEric Blake $QEMU_IO -c "read -P 4 $((len - 512)) 512" "$TEST_IMG.itmd" | _filter_qemu_io 13507ff948bSDaniel P. Berrange 13607ff948bSDaniel P. Berrange # And in pass 0, the top image should be empty, whereas in both other passes 13707ff948bSDaniel P. Berrange # it should be unchanged (which is both checked by qemu-img map) 13807ff948bSDaniel P. Berrangeelse 13907ff948bSDaniel P. Berrange $QEMU_IMG commit -b "$TEST_IMG.base" "$TEST_IMG" 14007ff948bSDaniel P. Berrange 14107ff948bSDaniel P. Berrange # Bottom should contain all changes 14207ff948bSDaniel P. Berrange $QEMU_IO -c 'read -P 1 0x7ffd0000 64k' "$TEST_IMG.base" | _filter_qemu_io 14307ff948bSDaniel P. Berrange $QEMU_IO -c 'read -P 2 0x7ffe0000 64k' "$TEST_IMG.base" | _filter_qemu_io 14407ff948bSDaniel P. Berrange $QEMU_IO -c 'read -P 3 0x7fff0000 64k' "$TEST_IMG.base" | _filter_qemu_io 145f82c5b17SEric Blake $QEMU_IO -c "read -P 4 $((len - 512)) 512" "$TEST_IMG.base" | _filter_qemu_io 14607ff948bSDaniel P. Berrange 14707ff948bSDaniel P. Berrange # Both top and intermediate should be unchanged 14807ff948bSDaniel P. Berrangefi 14907ff948bSDaniel P. Berrange 15007ff948bSDaniel P. Berrange$QEMU_IMG map "$TEST_IMG.base" | _filter_qemu_img_map 15107ff948bSDaniel P. Berrange$QEMU_IMG map "$TEST_IMG.itmd" | _filter_qemu_img_map 15207ff948bSDaniel P. Berrange$QEMU_IMG map "$TEST_IMG" | _filter_qemu_img_map 15307ff948bSDaniel P. Berrange 1544096974eSEric Blake# Check that the reason for slow path is still present, as appropriate 1554096974eSEric Blakecase $reason in 1564096974eSEric Blake snapshot) 1574096974eSEric Blake $QEMU_IMG snapshot -l "$TEST_IMG" | 1584096974eSEric Blake sed 's/^\(.\{20\}\).*/\1/; s/ *$//' ;; 1594096974eSEric Blake bitmap) 1604096974eSEric Blake run_qemu <<EOF 1614096974eSEric Blake{ "execute": "qmp_capabilities" } 1624096974eSEric Blake{ "execute": "blockdev-add", 1634096974eSEric Blake "arguments": { "driver": "qcow2", "node-name": "drive0", 1644096974eSEric Blake "file": { "driver": "file", "filename": "$TEST_IMG" } } } 1654096974eSEric Blake{ "execute": "x-debug-block-dirty-bitmap-sha256", 1664096974eSEric Blake "arguments": { "node": "drive0", "name": "bitmap0" } } 1674096974eSEric Blake{ "execute": "quit" } 1684096974eSEric BlakeEOF 1694096974eSEric Blake ;; 1704096974eSEric Blakeesac 17107ff948bSDaniel P. Berrange 1724096974eSEric Blakedone 1734096974eSEric Blakedone 17407ff948bSDaniel P. Berrange 17507ff948bSDaniel P. Berrange# success, all done 17607ff948bSDaniel P. Berrangeecho "*** done" 17707ff948bSDaniel P. Berrangerm -f $seq.full 17807ff948bSDaniel P. Berrangestatus=0 179