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