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# 6*4096974eSEric Blake# Variant of 097, which includes snapshots and persistent bitmaps, to 7*4096974eSEric Blake# tickle the slow codepath in qcow2. See also 198, for another feature 8*4096974eSEric Blake# that tickles the slow codepath. 907ff948bSDaniel P. Berrange# 10*4096974eSEric 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 47*4096974eSEric 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 5107ff948bSDaniel P. Berrange 52*4096974eSEric Blakefunction run_qemu() 53*4096974eSEric Blake{ 54*4096974eSEric Blake $QEMU -nographic -qmp stdio -serial none "$@" 2>&1 \ 55*4096974eSEric Blake | _filter_testdir | _filter_qmp | _filter_qemu 56*4096974eSEric Blake} 57*4096974eSEric Blake 58*4096974eSEric Blakefor reason in snapshot bitmap; do 5907ff948bSDaniel P. Berrange 6007ff948bSDaniel P. Berrange# Four passes: 6107ff948bSDaniel P. Berrange# 0: Two-layer backing chain, commit to upper backing file (implicitly) 6207ff948bSDaniel P. Berrange# (in this case, the top image will be emptied) 6307ff948bSDaniel P. Berrange# 1: Two-layer backing chain, commit to upper backing file (explicitly) 6407ff948bSDaniel P. Berrange# (in this case, the top image will implicitly stay unchanged) 6507ff948bSDaniel P. Berrange# 2: Two-layer backing chain, commit to upper backing file (implicitly with -d) 6607ff948bSDaniel P. Berrange# (in this case, the top image will explicitly stay unchanged) 6707ff948bSDaniel P. Berrange# 3: Two-layer backing chain, commit to lower backing file 6807ff948bSDaniel P. Berrange# (in this case, the top image will implicitly stay unchanged) 6907ff948bSDaniel P. Berrange# 7007ff948bSDaniel P. Berrange# 020 already tests committing, so this only tests whether image chains are 7107ff948bSDaniel P. Berrange# working properly and that all images above the base are emptied; therefore, 7207ff948bSDaniel P. Berrange# no complicated patterns are necessary. Check near the 2G mark, as qcow2 7307ff948bSDaniel P. Berrange# has been buggy at that boundary in the past. 7407ff948bSDaniel P. Berrangefor i in 0 1 2 3; do 7507ff948bSDaniel P. Berrange 7607ff948bSDaniel P. Berrangeecho 77*4096974eSEric Blakeecho "=== Test pass $reason.$i ===" 7807ff948bSDaniel P. Berrangeecho 7907ff948bSDaniel P. Berrange 80f82c5b17SEric Blakelen=$((2100 * 1024 * 1024 + 512)) # larger than 2G, and not cluster aligned 81f82c5b17SEric BlakeTEST_IMG="$TEST_IMG.base" _make_test_img $len 82f82c5b17SEric BlakeTEST_IMG="$TEST_IMG.itmd" _make_test_img -b "$TEST_IMG.base" $len 83f82c5b17SEric Blake_make_test_img -b "$TEST_IMG.itmd" $len 84*4096974eSEric Blake# Update the top image to use a feature that is incompatible with fast path 85*4096974eSEric Blakecase $reason in 86*4096974eSEric Blake snapshot) $QEMU_IMG snapshot -c snap "$TEST_IMG" ;; 87*4096974eSEric Blake bitmap) 88*4096974eSEric Blake run_qemu <<EOF 89*4096974eSEric Blake{ "execute": "qmp_capabilities" } 90*4096974eSEric Blake{ "execute": "blockdev-add", 91*4096974eSEric Blake "arguments": { "driver": "qcow2", "node-name": "drive0", 92*4096974eSEric Blake "file": { "driver": "file", "filename": "$TEST_IMG" } } } 93*4096974eSEric Blake{ "execute": "block-dirty-bitmap-add", 94*4096974eSEric Blake "arguments": { "node": "drive0", "name": "bitmap0", 95*4096974eSEric Blake "persistent": true, "autoload": true } } 96*4096974eSEric Blake{ "execute": "quit" } 97*4096974eSEric BlakeEOF 98*4096974eSEric Blake ;; 99*4096974eSEric Blakeesac 10007ff948bSDaniel P. Berrange 101f82c5b17SEric Blake$QEMU_IO -c "write -P 1 0x7ffd0000 192k" "$TEST_IMG.base" | _filter_qemu_io 102f82c5b17SEric Blake$QEMU_IO -c "write -P 2 0x7ffe0000 128k" "$TEST_IMG.itmd" | _filter_qemu_io 103f82c5b17SEric Blake$QEMU_IO -c "write -P 3 0x7fff0000 64k" "$TEST_IMG" | _filter_qemu_io 104f82c5b17SEric Blake$QEMU_IO -c "write -P 4 $(($len - 512)) 512" "$TEST_IMG" | _filter_qemu_io 10507ff948bSDaniel P. Berrange 10607ff948bSDaniel P. Berrangeif [ $i -lt 3 ]; then 10707ff948bSDaniel P. Berrange if [ $i == 0 ]; then 10807ff948bSDaniel P. Berrange # -b "$TEST_IMG.itmd" should be the default (that is, committing to the 10907ff948bSDaniel P. Berrange # first backing file in the chain) 11007ff948bSDaniel P. Berrange $QEMU_IMG commit "$TEST_IMG" 11107ff948bSDaniel P. Berrange elif [ $i == 1 ]; then 11207ff948bSDaniel P. Berrange # explicitly specify the commit target (this should imply -d) 11307ff948bSDaniel P. Berrange $QEMU_IMG commit -b "$TEST_IMG.itmd" "$TEST_IMG" 11407ff948bSDaniel P. Berrange else 11507ff948bSDaniel P. Berrange # do not explicitly specify the commit target, but use -d to leave the 11607ff948bSDaniel P. Berrange # top image unchanged 11707ff948bSDaniel P. Berrange $QEMU_IMG commit -d "$TEST_IMG" 11807ff948bSDaniel P. Berrange fi 11907ff948bSDaniel P. Berrange 12007ff948bSDaniel P. Berrange # Bottom should be unchanged 12107ff948bSDaniel P. Berrange $QEMU_IO -c 'read -P 1 0x7ffd0000 192k' "$TEST_IMG.base" | _filter_qemu_io 122f82c5b17SEric Blake $QEMU_IO -c "read -P 0 $((len - 512)) 512" "$TEST_IMG.base" | _filter_qemu_io 12307ff948bSDaniel P. Berrange 12407ff948bSDaniel P. Berrange # Intermediate should contain changes from top 12507ff948bSDaniel P. Berrange $QEMU_IO -c 'read -P 1 0x7ffd0000 64k' "$TEST_IMG.itmd" | _filter_qemu_io 12607ff948bSDaniel P. Berrange $QEMU_IO -c 'read -P 2 0x7ffe0000 64k' "$TEST_IMG.itmd" | _filter_qemu_io 12707ff948bSDaniel P. Berrange $QEMU_IO -c 'read -P 3 0x7fff0000 64k' "$TEST_IMG.itmd" | _filter_qemu_io 128f82c5b17SEric Blake $QEMU_IO -c "read -P 4 $((len - 512)) 512" "$TEST_IMG.itmd" | _filter_qemu_io 12907ff948bSDaniel P. Berrange 13007ff948bSDaniel P. Berrange # And in pass 0, the top image should be empty, whereas in both other passes 13107ff948bSDaniel P. Berrange # it should be unchanged (which is both checked by qemu-img map) 13207ff948bSDaniel P. Berrangeelse 13307ff948bSDaniel P. Berrange $QEMU_IMG commit -b "$TEST_IMG.base" "$TEST_IMG" 13407ff948bSDaniel P. Berrange 13507ff948bSDaniel P. Berrange # Bottom should contain all changes 13607ff948bSDaniel P. Berrange $QEMU_IO -c 'read -P 1 0x7ffd0000 64k' "$TEST_IMG.base" | _filter_qemu_io 13707ff948bSDaniel P. Berrange $QEMU_IO -c 'read -P 2 0x7ffe0000 64k' "$TEST_IMG.base" | _filter_qemu_io 13807ff948bSDaniel P. Berrange $QEMU_IO -c 'read -P 3 0x7fff0000 64k' "$TEST_IMG.base" | _filter_qemu_io 139f82c5b17SEric Blake $QEMU_IO -c "read -P 4 $((len - 512)) 512" "$TEST_IMG.base" | _filter_qemu_io 14007ff948bSDaniel P. Berrange 14107ff948bSDaniel P. Berrange # Both top and intermediate should be unchanged 14207ff948bSDaniel P. Berrangefi 14307ff948bSDaniel P. Berrange 14407ff948bSDaniel P. Berrange$QEMU_IMG map "$TEST_IMG.base" | _filter_qemu_img_map 14507ff948bSDaniel P. Berrange$QEMU_IMG map "$TEST_IMG.itmd" | _filter_qemu_img_map 14607ff948bSDaniel P. Berrange$QEMU_IMG map "$TEST_IMG" | _filter_qemu_img_map 14707ff948bSDaniel P. Berrange 148*4096974eSEric Blake# Check that the reason for slow path is still present, as appropriate 149*4096974eSEric Blakecase $reason in 150*4096974eSEric Blake snapshot) 151*4096974eSEric Blake $QEMU_IMG snapshot -l "$TEST_IMG" | 152*4096974eSEric Blake sed 's/^\(.\{20\}\).*/\1/; s/ *$//' ;; 153*4096974eSEric Blake bitmap) 154*4096974eSEric Blake run_qemu <<EOF 155*4096974eSEric Blake{ "execute": "qmp_capabilities" } 156*4096974eSEric Blake{ "execute": "blockdev-add", 157*4096974eSEric Blake "arguments": { "driver": "qcow2", "node-name": "drive0", 158*4096974eSEric Blake "file": { "driver": "file", "filename": "$TEST_IMG" } } } 159*4096974eSEric Blake{ "execute": "x-debug-block-dirty-bitmap-sha256", 160*4096974eSEric Blake "arguments": { "node": "drive0", "name": "bitmap0" } } 161*4096974eSEric Blake{ "execute": "quit" } 162*4096974eSEric BlakeEOF 163*4096974eSEric Blake ;; 164*4096974eSEric Blakeesac 16507ff948bSDaniel P. Berrange 166*4096974eSEric Blakedone 167*4096974eSEric Blakedone 16807ff948bSDaniel P. Berrange 16907ff948bSDaniel P. Berrange# success, all done 17007ff948bSDaniel P. Berrangeecho "*** done" 17107ff948bSDaniel P. Berrangerm -f $seq.full 17207ff948bSDaniel P. Berrangestatus=0 173