1#!/bin/bash 2# 3# Test commit block job where top has two parents 4# 5# Copyright (C) 2017 Red Hat, Inc. 6# 7# This program is free software; you can redistribute it and/or modify 8# it under the terms of the GNU General Public License as published by 9# the Free Software Foundation; either version 2 of the License, or 10# (at your option) any later version. 11# 12# This program is distributed in the hope that it will be useful, 13# but WITHOUT ANY WARRANTY; without even the implied warranty of 14# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15# GNU General Public License for more details. 16# 17# You should have received a copy of the GNU General Public License 18# along with this program. If not, see <http://www.gnu.org/licenses/>. 19# 20 21# creator 22owner=kwolf@redhat.com 23 24seq=`basename $0` 25echo "QA output created by $seq" 26 27here=`pwd` 28status=1 # failure is the default! 29 30_cleanup() 31{ 32 rm -f "${TEST_IMG}.mid" 33 rm -f "${TEST_IMG}.ovl2" 34 rm -f "${TEST_IMG}.ovl3" 35 _cleanup_test_img 36 _cleanup_qemu 37} 38trap "_cleanup; exit \$status" 0 1 2 3 15 39 40# get standard environment, filters and checks 41. ./common.rc 42. ./common.filter 43. ./common.qemu 44 45_supported_fmt qcow2 46_supported_proto file 47_supported_os Linux 48 49size=64M 50 51echo 52echo === Preparing and starting VM === 53echo 54 55TEST_IMG="${TEST_IMG}.base" _make_test_img $size 56IMGOPTS=$(_optstr_add "$IMGOPTS" "backing_fmt=$IMGFMT") \ 57 TEST_IMG="${TEST_IMG}.mid" _make_test_img -b "${TEST_IMG}.base" 58_make_test_img -b "${TEST_IMG}.mid" 59TEST_IMG="${TEST_IMG}.ovl2" _make_test_img -b "${TEST_IMG}.mid" 60 61$QEMU_IO -c 'write -P 0x55 1M 64k' "${TEST_IMG}.mid" | _filter_qemu_io 62 63qemu_comm_method="qmp" 64qmp_pretty="y" 65 66_launch_qemu \ 67 -blockdev "driver=${IMGFMT},file.driver=file,file.filename=${TEST_IMG}.base,node-name=base" \ 68 -blockdev "driver=${IMGFMT},file.driver=file,file.filename=${TEST_IMG}.mid,node-name=mid,backing=base" \ 69 -blockdev "driver=${IMGFMT},file.driver=file,file.filename=${TEST_IMG},node-name=top,backing=mid" \ 70 -blockdev "driver=${IMGFMT},file.driver=file,file.filename=${TEST_IMG}.ovl2,node-name=top2,backing=mid" 71h=$QEMU_HANDLE 72_send_qemu_cmd $h "{ 'execute': 'qmp_capabilities' }" '^}' 73 74echo 75echo === Perform commit job === 76echo 77 78_send_qemu_cmd $h \ 79 "{ 'execute': 'block-commit', 80 'arguments': { 'job-id': 'commit0', 81 'device': 'top', 82 'base':'$TEST_IMG.base', 83 'top': '$TEST_IMG.mid' } }" \ 84 '"status": "null"' 85_send_qemu_cmd $h "" "^}" 86 87echo 88echo === Check that both top and top2 point to base now === 89echo 90 91_send_qemu_cmd $h "{ 'execute': 'query-named-block-nodes' }" "^}" | 92 _filter_generated_node_ids | _filter_actual_image_size | _filter_img_info 93 94_send_qemu_cmd $h "{ 'execute': 'quit' }" "^}" 95wait=1 _cleanup_qemu 96 97_img_info 98TEST_IMG="$TEST_IMG.ovl2" _img_info 99 100 101echo 102echo === Preparing and starting VM with -drive === 103echo 104 105TEST_IMG="${TEST_IMG}.base" _make_test_img $size 106TEST_IMG="${TEST_IMG}.mid" _make_test_img -b "${TEST_IMG}.base" 107_make_test_img -b "${TEST_IMG}.mid" 108TEST_IMG="${TEST_IMG}.ovl2" _make_test_img -b "${TEST_IMG}.mid" 109TEST_IMG="${TEST_IMG}.ovl3" _make_test_img -b "${TEST_IMG}.ovl2" 110 111$QEMU_IO -c 'write -P 0x55 1M 64k' "${TEST_IMG}.mid" | _filter_qemu_io 112 113qemu_comm_method="qmp" 114qmp_pretty="y" 115 116_launch_qemu \ 117 -drive "driver=${IMGFMT},file=${TEST_IMG},node-name=top,backing.node-name=mid" \ 118 -drive "driver=${IMGFMT},file=${TEST_IMG}.ovl3,node-name=top2,backing.backing=mid" 119h=$QEMU_HANDLE 120_send_qemu_cmd $h "{ 'execute': 'qmp_capabilities' }" '^}' 121 122echo 123echo === Perform commit job === 124echo 125 126_send_qemu_cmd $h \ 127 "{ 'execute': 'block-commit', 128 'arguments': { 'job-id': 'commit0', 129 'device': 'top', 130 'base':'$TEST_IMG.base', 131 'top': '$TEST_IMG.mid' } }" \ 132 '"status": "null"' 133_send_qemu_cmd $h "" "^}" 134 135echo 136echo === Check that both top and top2 point to base now === 137echo 138 139_send_qemu_cmd $h "{ 'execute': 'query-named-block-nodes' }" "^}" | 140 _filter_generated_node_ids | _filter_actual_image_size | _filter_img_info 141 142_send_qemu_cmd $h "{ 'execute': 'quit' }" "^}" 143wait=1 _cleanup_qemu 144 145_img_info 146TEST_IMG="$TEST_IMG.ovl2" _img_info 147 148# success, all done 149echo "*** done" 150rm -f $seq.full 151status=0 152