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