1#!/usr/bin/env 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 27status=1 # failure is the default! 28 29_cleanup() 30{ 31 rm -f "${TEST_IMG}.mid" 32 rm -f "${TEST_IMG}.ovl2" 33 rm -f "${TEST_IMG}.ovl3" 34 _cleanup_test_img 35 _cleanup_qemu 36} 37trap "_cleanup; exit \$status" 0 1 2 3 15 38 39# get standard environment, filters and checks 40. ./common.rc 41. ./common.filter 42. ./common.qemu 43 44_supported_fmt qcow2 45_supported_proto file 46 47size=64M 48 49echo 50echo === Preparing and starting VM === 51echo 52 53TEST_IMG="${TEST_IMG}.base" _make_test_img $size 54TEST_IMG="${TEST_IMG}.mid" _make_test_img -o "backing_fmt=$IMGFMT" -b "${TEST_IMG}.base" 55_make_test_img -b "${TEST_IMG}.mid" 56TEST_IMG="${TEST_IMG}.ovl2" _make_test_img -b "${TEST_IMG}.mid" 57 58$QEMU_IO -c 'write -P 0x55 1M 64k' "${TEST_IMG}.mid" | _filter_qemu_io 59 60qemu_comm_method="qmp" 61qmp_pretty="y" 62 63_launch_qemu \ 64 -blockdev "driver=${IMGFMT},file.driver=file,file.filename=${TEST_IMG}.base,node-name=base" \ 65 -blockdev "driver=${IMGFMT},file.driver=file,file.filename=${TEST_IMG}.mid,node-name=mid,backing=base" \ 66 -blockdev "driver=${IMGFMT},file.driver=file,file.filename=${TEST_IMG},node-name=top,backing=mid" \ 67 -blockdev "driver=${IMGFMT},file.driver=file,file.filename=${TEST_IMG}.ovl2,node-name=top2,backing=mid" 68h=$QEMU_HANDLE 69_send_qemu_cmd $h "{ 'execute': 'qmp_capabilities' }" '^}' 70 71echo 72echo === Perform commit job === 73echo 74 75_send_qemu_cmd $h \ 76 "{ 'execute': 'block-commit', 77 'arguments': { 'job-id': 'commit0', 78 'device': 'top', 79 'base':'$TEST_IMG.base', 80 'top': '$TEST_IMG.mid' } }" \ 81 '"status": "null"' 82_send_qemu_cmd $h "" "^}" 83 84echo 85echo === Check that both top and top2 point to base now === 86echo 87 88_send_qemu_cmd $h "{ 'execute': 'query-named-block-nodes' }" "^}" | 89 _filter_generated_node_ids | _filter_actual_image_size | _filter_img_info 90 91_send_qemu_cmd $h "{ 'execute': 'quit' }" "^}" 92wait=1 _cleanup_qemu 93 94_img_info 95TEST_IMG="$TEST_IMG.ovl2" _img_info 96 97 98echo 99echo === Preparing and starting VM with -drive === 100echo 101 102TEST_IMG="${TEST_IMG}.base" _make_test_img $size 103TEST_IMG="${TEST_IMG}.mid" _make_test_img -b "${TEST_IMG}.base" 104_make_test_img -b "${TEST_IMG}.mid" 105TEST_IMG="${TEST_IMG}.ovl2" _make_test_img -b "${TEST_IMG}.mid" 106TEST_IMG="${TEST_IMG}.ovl3" _make_test_img -b "${TEST_IMG}.ovl2" 107 108$QEMU_IO -c 'write -P 0x55 1M 64k' "${TEST_IMG}.mid" | _filter_qemu_io 109 110qemu_comm_method="qmp" 111qmp_pretty="y" 112 113_launch_qemu \ 114 -drive "driver=${IMGFMT},file=${TEST_IMG},node-name=top,backing.node-name=mid" \ 115 -drive "driver=${IMGFMT},file=${TEST_IMG}.ovl3,node-name=top2,backing.backing=mid" 116h=$QEMU_HANDLE 117_send_qemu_cmd $h "{ 'execute': 'qmp_capabilities' }" '^}' 118 119echo 120echo === Perform commit job === 121echo 122 123_send_qemu_cmd $h \ 124 "{ 'execute': 'block-commit', 125 'arguments': { 'job-id': 'commit0', 126 'device': 'top', 127 'base':'$TEST_IMG.base', 128 'top': '$TEST_IMG.mid' } }" \ 129 '"status": "null"' 130_send_qemu_cmd $h "" "^}" 131 132echo 133echo === Check that both top and top2 point to base now === 134echo 135 136_send_qemu_cmd $h "{ 'execute': 'query-named-block-nodes' }" "^}" | 137 _filter_generated_node_ids | _filter_actual_image_size | _filter_img_info 138 139_send_qemu_cmd $h "{ 'execute': 'quit' }" "^}" 140wait=1 _cleanup_qemu 141 142_img_info 143TEST_IMG="$TEST_IMG.ovl2" _img_info 144 145# success, all done 146echo "*** done" 147rm -f $seq.full 148status=0 149