13dd48fdcSMax Reitz#!/bin/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 Reitzhere="$PWD" 363dd48fdcSMax Reitzstatus=1 # failure is the default! 373dd48fdcSMax Reitz 383dd48fdcSMax Reitz_cleanup() 393dd48fdcSMax Reitz{ 40ecfa1854SJeff Cody _cleanup_qemu 41645acdc0SMax Reitz rm -f "$TEST_IMG"{,.target}{,.backing,.overlay} 423dd48fdcSMax Reitz} 433dd48fdcSMax Reitztrap "_cleanup; exit \$status" 0 1 2 3 15 443dd48fdcSMax Reitz 453dd48fdcSMax Reitz# get standard environment, filters and checks 463dd48fdcSMax Reitz. ./common.rc 473dd48fdcSMax Reitz. ./common.filter 483dd48fdcSMax Reitz. ./common.qemu 493dd48fdcSMax Reitz 503dd48fdcSMax Reitz_supported_fmt qcow2 qed 513dd48fdcSMax Reitz_supported_proto generic 52a98f49f4SJeff Cody_unsupported_proto vxhs 533dd48fdcSMax Reitz_supported_os Linux 543dd48fdcSMax Reitz 553dd48fdcSMax Reitz# Create source disk 563dd48fdcSMax ReitzTEST_IMG="$TEST_IMG.backing" _make_test_img 1M 573dd48fdcSMax Reitz_make_test_img -b "$TEST_IMG.backing" 1M 583dd48fdcSMax Reitz 593dd48fdcSMax Reitz$QEMU_IO -c 'write -P 1 0 256k' "$TEST_IMG.backing" | _filter_qemu_io 603dd48fdcSMax Reitz$QEMU_IO -c 'write -P 2 64k 192k' "$TEST_IMG" | _filter_qemu_io 613dd48fdcSMax Reitz 623dd48fdcSMax Reitz_launch_qemu -drive if=none,id=source,file="$TEST_IMG" 633dd48fdcSMax Reitz 643dd48fdcSMax Reitz_send_qemu_cmd $QEMU_HANDLE \ 653dd48fdcSMax Reitz "{ 'execute': 'qmp_capabilities' }" \ 663dd48fdcSMax Reitz 'return' 673dd48fdcSMax Reitz 683dd48fdcSMax Reitz# Create snapshot 696e6e55f5SJohn SnowTEST_IMG="$TEST_IMG.overlay" _make_test_img -u -b "$TEST_IMG" 1M 703dd48fdcSMax Reitz_send_qemu_cmd $QEMU_HANDLE \ 713dd48fdcSMax Reitz "{ 'execute': 'blockdev-snapshot-sync', 723dd48fdcSMax Reitz 'arguments': { 'device': 'source', 733dd48fdcSMax Reitz 'snapshot-file': '$TEST_IMG.overlay', 743dd48fdcSMax Reitz 'format': '$IMGFMT', 753dd48fdcSMax Reitz 'mode': 'existing' } }" \ 763dd48fdcSMax Reitz 'return' 773dd48fdcSMax Reitz 783dd48fdcSMax Reitz# Write something to the snapshot 793dd48fdcSMax Reitz_send_qemu_cmd $QEMU_HANDLE \ 803dd48fdcSMax Reitz "{ 'execute': 'human-monitor-command', 813dd48fdcSMax Reitz 'arguments': { 'command-line': 823dd48fdcSMax Reitz 'qemu-io source \"write -P 3 128k 128k\"' } }" \ 833dd48fdcSMax Reitz 'return' 843dd48fdcSMax Reitz 853dd48fdcSMax Reitz# Create target image 86645acdc0SMax ReitzTEST_IMG="$TEST_IMG.target.overlay" _make_test_img -u -b "$TEST_IMG.target" 1M 873dd48fdcSMax Reitz 883dd48fdcSMax Reitz# Mirror snapshot 893dd48fdcSMax Reitz_send_qemu_cmd $QEMU_HANDLE \ 903dd48fdcSMax Reitz "{ 'execute': 'drive-mirror', 913dd48fdcSMax Reitz 'arguments': { 'device': 'source', 923dd48fdcSMax Reitz 'target': '$TEST_IMG.target.overlay', 933dd48fdcSMax Reitz 'mode': 'existing', 943dd48fdcSMax Reitz 'sync': 'top' } }" \ 953dd48fdcSMax Reitz 'return' 963dd48fdcSMax Reitz 973dd48fdcSMax Reitz# Wait for convergence 983dd48fdcSMax Reitz_send_qemu_cmd $QEMU_HANDLE \ 993dd48fdcSMax Reitz '' \ 1003dd48fdcSMax Reitz 'BLOCK_JOB_READY' 1013dd48fdcSMax Reitz 1023dd48fdcSMax Reitz# Write some more 1033dd48fdcSMax Reitz_send_qemu_cmd $QEMU_HANDLE \ 1043dd48fdcSMax Reitz "{ 'execute': 'human-monitor-command', 1053dd48fdcSMax Reitz 'arguments': { 'command-line': 1063dd48fdcSMax Reitz 'qemu-io source \"write -P 4 192k 64k\"' } }" \ 1073dd48fdcSMax Reitz 'return' 1083dd48fdcSMax Reitz 1093dd48fdcSMax Reitz# Copy source backing chain to the target before completing the job 1103dd48fdcSMax Reitzcp "$TEST_IMG.backing" "$TEST_IMG.target.backing" 1113dd48fdcSMax Reitzcp "$TEST_IMG" "$TEST_IMG.target" 1123dd48fdcSMax Reitz$QEMU_IMG rebase -u -b "$TEST_IMG.target.backing" "$TEST_IMG.target" 1133dd48fdcSMax Reitz 1143dd48fdcSMax Reitz# Complete block job 1153dd48fdcSMax Reitz_send_qemu_cmd $QEMU_HANDLE \ 1163dd48fdcSMax Reitz "{ 'execute': 'block-job-complete', 1173dd48fdcSMax Reitz 'arguments': { 'device': 'source' } }" \ 1183dd48fdcSMax Reitz '' 1193dd48fdcSMax Reitz 1203dd48fdcSMax Reitz_send_qemu_cmd $QEMU_HANDLE \ 1213dd48fdcSMax Reitz '' \ 122*1dac83f1SKevin Wolf '"status": "null"' 1233dd48fdcSMax Reitz 1243dd48fdcSMax Reitz# Remove the source images 1253dd48fdcSMax Reitzrm -f "$TEST_IMG{,.backing,.overlay}" 1263dd48fdcSMax Reitz 1273dd48fdcSMax Reitzecho 1283dd48fdcSMax Reitz 1293dd48fdcSMax Reitz# Check online disk contents 1303dd48fdcSMax Reitz_send_qemu_cmd $QEMU_HANDLE \ 1313dd48fdcSMax Reitz "{ 'execute': 'human-monitor-command', 1323dd48fdcSMax Reitz 'arguments': { 'command-line': 1333dd48fdcSMax Reitz 'qemu-io source \"read -P 1 0k 64k\"' } }" \ 1343dd48fdcSMax Reitz 'return' 1353dd48fdcSMax Reitz 1363dd48fdcSMax Reitz_send_qemu_cmd $QEMU_HANDLE \ 1373dd48fdcSMax Reitz "{ 'execute': 'human-monitor-command', 1383dd48fdcSMax Reitz 'arguments': { 'command-line': 1393dd48fdcSMax Reitz 'qemu-io source \"read -P 2 64k 64k\"' } }" \ 1403dd48fdcSMax Reitz 'return' 1413dd48fdcSMax Reitz 1423dd48fdcSMax Reitz_send_qemu_cmd $QEMU_HANDLE \ 1433dd48fdcSMax Reitz "{ 'execute': 'human-monitor-command', 1443dd48fdcSMax Reitz 'arguments': { 'command-line': 1453dd48fdcSMax Reitz 'qemu-io source \"read -P 3 128k 64k\"' } }" \ 1463dd48fdcSMax Reitz 'return' 1473dd48fdcSMax Reitz 1483dd48fdcSMax Reitz_send_qemu_cmd $QEMU_HANDLE \ 1493dd48fdcSMax Reitz "{ 'execute': 'human-monitor-command', 1503dd48fdcSMax Reitz 'arguments': { 'command-line': 1513dd48fdcSMax Reitz 'qemu-io source \"read -P 4 192k 64k\"' } }" \ 1523dd48fdcSMax Reitz 'return' 1533dd48fdcSMax Reitz 1543dd48fdcSMax Reitzecho 1553dd48fdcSMax Reitz 1563dd48fdcSMax Reitz_send_qemu_cmd $QEMU_HANDLE \ 1573dd48fdcSMax Reitz "{ 'execute': 'quit' }" \ 1583dd48fdcSMax Reitz 'return' 1593dd48fdcSMax Reitz 1603dd48fdcSMax Reitzwait=1 _cleanup_qemu 1613dd48fdcSMax Reitz 1623dd48fdcSMax Reitzecho 1633dd48fdcSMax Reitz 1643dd48fdcSMax Reitz# Check offline disk contents 1653dd48fdcSMax Reitz$QEMU_IO -c 'read -P 1 0k 64k' \ 1663dd48fdcSMax Reitz -c 'read -P 2 64k 64k' \ 1673dd48fdcSMax Reitz -c 'read -P 3 128k 64k' \ 1683dd48fdcSMax Reitz -c 'read -P 4 192k 64k' \ 1693dd48fdcSMax Reitz "$TEST_IMG.target.overlay" | _filter_qemu_io 1703dd48fdcSMax Reitz 1713dd48fdcSMax Reitzecho 1723dd48fdcSMax Reitz 1733dd48fdcSMax Reitz# success, all done 1743dd48fdcSMax Reitzecho '*** done' 1753dd48fdcSMax Reitzrm -f $seq.full 1763dd48fdcSMax Reitzstatus=0 177