1*f700ceaeSMax Reitz#!/bin/bash 2*f700ceaeSMax Reitz# 3*f700ceaeSMax Reitz# Test case for mirroring with dataplane 4*f700ceaeSMax Reitz# 5*f700ceaeSMax Reitz# Copyright (C) 2017 Red Hat, Inc. 6*f700ceaeSMax Reitz# 7*f700ceaeSMax Reitz# This program is free software; you can redistribute it and/or modify 8*f700ceaeSMax Reitz# it under the terms of the GNU General Public License as published by 9*f700ceaeSMax Reitz# the Free Software Foundation; either version 2 of the License, or 10*f700ceaeSMax Reitz# (at your option) any later version. 11*f700ceaeSMax Reitz# 12*f700ceaeSMax Reitz# This program is distributed in the hope that it will be useful, 13*f700ceaeSMax Reitz# but WITHOUT ANY WARRANTY; without even the implied warranty of 14*f700ceaeSMax Reitz# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15*f700ceaeSMax Reitz# GNU General Public License for more details. 16*f700ceaeSMax Reitz# 17*f700ceaeSMax Reitz# You should have received a copy of the GNU General Public License 18*f700ceaeSMax Reitz# along with this program. If not, see <http://www.gnu.org/licenses/>. 19*f700ceaeSMax Reitz# 20*f700ceaeSMax Reitz 21*f700ceaeSMax Reitz# creator 22*f700ceaeSMax Reitzowner=mreitz@redhat.com 23*f700ceaeSMax Reitz 24*f700ceaeSMax Reitzseq=$(basename $0) 25*f700ceaeSMax Reitzecho "QA output created by $seq" 26*f700ceaeSMax Reitz 27*f700ceaeSMax Reitzhere=$PWD 28*f700ceaeSMax Reitzstatus=1 # failure is the default! 29*f700ceaeSMax Reitz 30*f700ceaeSMax Reitz_cleanup() 31*f700ceaeSMax Reitz{ 32*f700ceaeSMax Reitz _cleanup_qemu 33*f700ceaeSMax Reitz _cleanup_test_img 34*f700ceaeSMax Reitz _rm_test_img "$TEST_IMG.overlay0" 35*f700ceaeSMax Reitz _rm_test_img "$TEST_IMG.overlay1" 36*f700ceaeSMax Reitz} 37*f700ceaeSMax Reitztrap "_cleanup; exit \$status" 0 1 2 3 15 38*f700ceaeSMax Reitz 39*f700ceaeSMax Reitz# get standard environment, filters and qemu instance handling 40*f700ceaeSMax Reitz. ./common.rc 41*f700ceaeSMax Reitz. ./common.filter 42*f700ceaeSMax Reitz. ./common.qemu 43*f700ceaeSMax Reitz 44*f700ceaeSMax Reitz_supported_fmt qcow2 45*f700ceaeSMax Reitz_supported_proto file 46*f700ceaeSMax Reitz_supported_os Linux 47*f700ceaeSMax Reitz 48*f700ceaeSMax ReitzIMG_SIZE=64K 49*f700ceaeSMax Reitz 50*f700ceaeSMax Reitz_make_test_img $IMG_SIZE 51*f700ceaeSMax ReitzTEST_IMG="$TEST_IMG.overlay0" _make_test_img -b "$TEST_IMG" $IMG_SIZE 52*f700ceaeSMax ReitzTEST_IMG="$TEST_IMG.overlay1" _make_test_img -b "$TEST_IMG" $IMG_SIZE 53*f700ceaeSMax Reitz 54*f700ceaeSMax Reitz# So that we actually have something to mirror and the job does not return 55*f700ceaeSMax Reitz# immediately (which may be bad because then we cannot know whether the 56*f700ceaeSMax Reitz# 'return' or the 'BLOCK_JOB_READY' comes first). 57*f700ceaeSMax Reitz$QEMU_IO -c 'write 0 42' "$TEST_IMG.overlay0" | _filter_qemu_io 58*f700ceaeSMax Reitz 59*f700ceaeSMax Reitz# We cannot use virtio-blk here because that does not actually set the attached 60*f700ceaeSMax Reitz# BB's AioContext in qtest mode 61*f700ceaeSMax Reitz_launch_qemu \ 62*f700ceaeSMax Reitz -object iothread,id=iothr \ 63*f700ceaeSMax Reitz -blockdev node-name=source,driver=$IMGFMT,file.driver=file,file.filename="$TEST_IMG.overlay0" \ 64*f700ceaeSMax Reitz -device virtio-scsi,id=scsi-bus,iothread=iothr \ 65*f700ceaeSMax Reitz -device scsi-hd,bus=scsi-bus.0,drive=source 66*f700ceaeSMax Reitz 67*f700ceaeSMax Reitz_send_qemu_cmd $QEMU_HANDLE \ 68*f700ceaeSMax Reitz "{ 'execute': 'qmp_capabilities' }" \ 69*f700ceaeSMax Reitz 'return' 70*f700ceaeSMax Reitz 71*f700ceaeSMax Reitz_send_qemu_cmd $QEMU_HANDLE \ 72*f700ceaeSMax Reitz "{ 'execute': 'drive-mirror', 73*f700ceaeSMax Reitz 'arguments': { 74*f700ceaeSMax Reitz 'job-id': 'mirror', 75*f700ceaeSMax Reitz 'device': 'source', 76*f700ceaeSMax Reitz 'target': '$TEST_IMG.overlay1', 77*f700ceaeSMax Reitz 'mode': 'existing', 78*f700ceaeSMax Reitz 'sync': 'top' 79*f700ceaeSMax Reitz } }" \ 80*f700ceaeSMax Reitz 'BLOCK_JOB_READY' 81*f700ceaeSMax Reitz 82*f700ceaeSMax Reitz# The backing BDS should be assigned the overlay's AioContext 83*f700ceaeSMax Reitz_send_qemu_cmd $QEMU_HANDLE \ 84*f700ceaeSMax Reitz "{ 'execute': 'block-job-complete', 85*f700ceaeSMax Reitz 'arguments': { 'device': 'mirror' } }" \ 86*f700ceaeSMax Reitz 'BLOCK_JOB_COMPLETED' 87*f700ceaeSMax Reitz 88*f700ceaeSMax Reitz_send_qemu_cmd $QEMU_HANDLE \ 89*f700ceaeSMax Reitz "{ 'execute': 'quit' }" \ 90*f700ceaeSMax Reitz 'return' 91*f700ceaeSMax Reitz 92*f700ceaeSMax Reitzwait=yes _cleanup_qemu 93*f700ceaeSMax Reitz 94*f700ceaeSMax Reitz# success, all done 95*f700ceaeSMax Reitzecho '*** done' 96*f700ceaeSMax Reitzrm -f $seq.full 97*f700ceaeSMax Reitzstatus=0 98