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