xref: /openbmc/qemu/tests/qemu-iotests/156 (revision 11a82d14)
1*11a82d14SPhilippe Mathieu-Daudé#!/usr/bin/env bash
23dd48fdcSMax Reitz#
33dd48fdcSMax Reitz# Tests oVirt-like storage migration:
43dd48fdcSMax Reitz#  - Create snapshot
53dd48fdcSMax Reitz#  - Create target image with (not yet existing) target backing chain
63dd48fdcSMax Reitz#    (i.e. just write the name of a soon-to-be-copied-over backing file into it)
73dd48fdcSMax Reitz#  - drive-mirror the snapshot to the target with mode=existing and sync=top
83dd48fdcSMax Reitz#  - In the meantime, copy the original source files to the destination via
93dd48fdcSMax Reitz#    conventional means (i.e. outside of qemu)
103dd48fdcSMax Reitz#  - Complete the drive-mirror job
113dd48fdcSMax Reitz#  - Delete all source images
123dd48fdcSMax Reitz#
133dd48fdcSMax Reitz# Copyright (C) 2016 Red Hat, Inc.
143dd48fdcSMax Reitz#
153dd48fdcSMax Reitz# This program is free software; you can redistribute it and/or modify
163dd48fdcSMax Reitz# it under the terms of the GNU General Public License as published by
173dd48fdcSMax Reitz# the Free Software Foundation; either version 2 of the License, or
183dd48fdcSMax Reitz# (at your option) any later version.
193dd48fdcSMax Reitz#
203dd48fdcSMax Reitz# This program is distributed in the hope that it will be useful,
213dd48fdcSMax Reitz# but WITHOUT ANY WARRANTY; without even the implied warranty of
223dd48fdcSMax Reitz# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
233dd48fdcSMax Reitz# GNU General Public License for more details.
243dd48fdcSMax Reitz#
253dd48fdcSMax Reitz# You should have received a copy of the GNU General Public License
263dd48fdcSMax Reitz# along with this program.  If not, see <http://www.gnu.org/licenses/>.
273dd48fdcSMax Reitz#
283dd48fdcSMax Reitz
293dd48fdcSMax Reitz# creator
303dd48fdcSMax Reitzowner=mreitz@redhat.com
313dd48fdcSMax Reitz
323dd48fdcSMax Reitzseq="$(basename $0)"
333dd48fdcSMax Reitzecho "QA output created by $seq"
343dd48fdcSMax Reitz
353dd48fdcSMax Reitzstatus=1	# failure is the default!
363dd48fdcSMax Reitz
373dd48fdcSMax Reitz_cleanup()
383dd48fdcSMax Reitz{
39ecfa1854SJeff Cody    _cleanup_qemu
40645acdc0SMax Reitz    rm -f "$TEST_IMG"{,.target}{,.backing,.overlay}
413dd48fdcSMax Reitz}
423dd48fdcSMax Reitztrap "_cleanup; exit \$status" 0 1 2 3 15
433dd48fdcSMax Reitz
443dd48fdcSMax Reitz# get standard environment, filters and checks
453dd48fdcSMax Reitz. ./common.rc
463dd48fdcSMax Reitz. ./common.filter
473dd48fdcSMax Reitz. ./common.qemu
483dd48fdcSMax Reitz
493dd48fdcSMax Reitz_supported_fmt qcow2 qed
503dd48fdcSMax Reitz_supported_proto generic
51a98f49f4SJeff Cody_unsupported_proto vxhs
523dd48fdcSMax Reitz_supported_os Linux
533dd48fdcSMax Reitz
543dd48fdcSMax Reitz# Create source disk
553dd48fdcSMax ReitzTEST_IMG="$TEST_IMG.backing" _make_test_img 1M
563dd48fdcSMax Reitz_make_test_img -b "$TEST_IMG.backing" 1M
573dd48fdcSMax Reitz
583dd48fdcSMax Reitz$QEMU_IO -c 'write -P 1 0 256k' "$TEST_IMG.backing" | _filter_qemu_io
593dd48fdcSMax Reitz$QEMU_IO -c 'write -P 2 64k 192k' "$TEST_IMG" | _filter_qemu_io
603dd48fdcSMax Reitz
613dd48fdcSMax Reitz_launch_qemu -drive if=none,id=source,file="$TEST_IMG"
623dd48fdcSMax Reitz
633dd48fdcSMax Reitz_send_qemu_cmd $QEMU_HANDLE \
643dd48fdcSMax Reitz    "{ 'execute': 'qmp_capabilities' }" \
653dd48fdcSMax Reitz    'return'
663dd48fdcSMax Reitz
673dd48fdcSMax Reitz# Create snapshot
686e6e55f5SJohn SnowTEST_IMG="$TEST_IMG.overlay" _make_test_img -u -b "$TEST_IMG" 1M
693dd48fdcSMax Reitz_send_qemu_cmd $QEMU_HANDLE \
703dd48fdcSMax Reitz    "{ 'execute': 'blockdev-snapshot-sync',
713dd48fdcSMax Reitz       'arguments': { 'device': 'source',
723dd48fdcSMax Reitz                      'snapshot-file': '$TEST_IMG.overlay',
733dd48fdcSMax Reitz                      'format': '$IMGFMT',
743dd48fdcSMax Reitz                      'mode': 'existing' } }" \
753dd48fdcSMax Reitz    'return'
763dd48fdcSMax Reitz
773dd48fdcSMax Reitz# Write something to the snapshot
783dd48fdcSMax Reitz_send_qemu_cmd $QEMU_HANDLE \
793dd48fdcSMax Reitz    "{ 'execute': 'human-monitor-command',
803dd48fdcSMax Reitz       'arguments': { 'command-line':
813dd48fdcSMax Reitz                      'qemu-io source \"write -P 3 128k 128k\"' } }" \
823dd48fdcSMax Reitz    'return'
833dd48fdcSMax Reitz
843dd48fdcSMax Reitz# Create target image
85645acdc0SMax ReitzTEST_IMG="$TEST_IMG.target.overlay" _make_test_img -u -b "$TEST_IMG.target" 1M
863dd48fdcSMax Reitz
873dd48fdcSMax Reitz# Mirror snapshot
883dd48fdcSMax Reitz_send_qemu_cmd $QEMU_HANDLE \
893dd48fdcSMax Reitz    "{ 'execute': 'drive-mirror',
903dd48fdcSMax Reitz       'arguments': { 'device': 'source',
913dd48fdcSMax Reitz                      'target': '$TEST_IMG.target.overlay',
923dd48fdcSMax Reitz                      'mode': 'existing',
933dd48fdcSMax Reitz                      'sync': 'top' } }" \
943dd48fdcSMax Reitz    'return'
953dd48fdcSMax Reitz
963dd48fdcSMax Reitz# Wait for convergence
973dd48fdcSMax Reitz_send_qemu_cmd $QEMU_HANDLE \
983dd48fdcSMax Reitz    '' \
993dd48fdcSMax Reitz    'BLOCK_JOB_READY'
1003dd48fdcSMax Reitz
1013dd48fdcSMax Reitz# Write some more
1023dd48fdcSMax Reitz_send_qemu_cmd $QEMU_HANDLE \
1033dd48fdcSMax Reitz    "{ 'execute': 'human-monitor-command',
1043dd48fdcSMax Reitz       'arguments': { 'command-line':
1053dd48fdcSMax Reitz                      'qemu-io source \"write -P 4 192k 64k\"' } }" \
1063dd48fdcSMax Reitz    'return'
1073dd48fdcSMax Reitz
1083dd48fdcSMax Reitz# Copy source backing chain to the target before completing the job
1093dd48fdcSMax Reitzcp "$TEST_IMG.backing" "$TEST_IMG.target.backing"
1103dd48fdcSMax Reitzcp "$TEST_IMG" "$TEST_IMG.target"
1113dd48fdcSMax Reitz$QEMU_IMG rebase -u -b "$TEST_IMG.target.backing" "$TEST_IMG.target"
1123dd48fdcSMax Reitz
1133dd48fdcSMax Reitz# Complete block job
1143dd48fdcSMax Reitz_send_qemu_cmd $QEMU_HANDLE \
1153dd48fdcSMax Reitz    "{ 'execute': 'block-job-complete',
1163dd48fdcSMax Reitz       'arguments': { 'device': 'source' } }" \
1173dd48fdcSMax Reitz    ''
1183dd48fdcSMax Reitz
1193dd48fdcSMax Reitz_send_qemu_cmd $QEMU_HANDLE \
1203dd48fdcSMax Reitz    '' \
1211dac83f1SKevin Wolf    '"status": "null"'
1223dd48fdcSMax Reitz
1233dd48fdcSMax Reitz# Remove the source images
1243dd48fdcSMax Reitzrm -f "$TEST_IMG{,.backing,.overlay}"
1253dd48fdcSMax Reitz
1263dd48fdcSMax Reitzecho
1273dd48fdcSMax Reitz
1283dd48fdcSMax Reitz# Check online disk contents
1293dd48fdcSMax Reitz_send_qemu_cmd $QEMU_HANDLE \
1303dd48fdcSMax Reitz    "{ 'execute': 'human-monitor-command',
1313dd48fdcSMax Reitz       'arguments': { 'command-line':
1323dd48fdcSMax Reitz                      'qemu-io source \"read -P 1 0k 64k\"' } }" \
1333dd48fdcSMax Reitz    'return'
1343dd48fdcSMax Reitz
1353dd48fdcSMax Reitz_send_qemu_cmd $QEMU_HANDLE \
1363dd48fdcSMax Reitz    "{ 'execute': 'human-monitor-command',
1373dd48fdcSMax Reitz       'arguments': { 'command-line':
1383dd48fdcSMax Reitz                      'qemu-io source \"read -P 2 64k 64k\"' } }" \
1393dd48fdcSMax Reitz    'return'
1403dd48fdcSMax Reitz
1413dd48fdcSMax Reitz_send_qemu_cmd $QEMU_HANDLE \
1423dd48fdcSMax Reitz    "{ 'execute': 'human-monitor-command',
1433dd48fdcSMax Reitz       'arguments': { 'command-line':
1443dd48fdcSMax Reitz                      'qemu-io source \"read -P 3 128k 64k\"' } }" \
1453dd48fdcSMax Reitz    'return'
1463dd48fdcSMax Reitz
1473dd48fdcSMax Reitz_send_qemu_cmd $QEMU_HANDLE \
1483dd48fdcSMax Reitz    "{ 'execute': 'human-monitor-command',
1493dd48fdcSMax Reitz       'arguments': { 'command-line':
1503dd48fdcSMax Reitz                      'qemu-io source \"read -P 4 192k 64k\"' } }" \
1513dd48fdcSMax Reitz    'return'
1523dd48fdcSMax Reitz
1533dd48fdcSMax Reitzecho
1543dd48fdcSMax Reitz
1553dd48fdcSMax Reitz_send_qemu_cmd $QEMU_HANDLE \
1563dd48fdcSMax Reitz    "{ 'execute': 'quit' }" \
1573dd48fdcSMax Reitz    'return'
1583dd48fdcSMax Reitz
1593dd48fdcSMax Reitzwait=1 _cleanup_qemu
1603dd48fdcSMax Reitz
1613dd48fdcSMax Reitzecho
1623dd48fdcSMax Reitz
1633dd48fdcSMax Reitz# Check offline disk contents
1643dd48fdcSMax Reitz$QEMU_IO -c 'read -P 1 0k 64k' \
1653dd48fdcSMax Reitz         -c 'read -P 2 64k 64k' \
1663dd48fdcSMax Reitz         -c 'read -P 3 128k 64k' \
1673dd48fdcSMax Reitz         -c 'read -P 4 192k 64k' \
1683dd48fdcSMax Reitz         "$TEST_IMG.target.overlay" | _filter_qemu_io
1693dd48fdcSMax Reitz
1703dd48fdcSMax Reitzecho
1713dd48fdcSMax Reitz
1723dd48fdcSMax Reitz# success, all done
1733dd48fdcSMax Reitzecho '*** done'
1743dd48fdcSMax Reitzrm -f $seq.full
1753dd48fdcSMax Reitzstatus=0
176