111a82d14SPhilippe Mathieu-Daudé#!/usr/bin/env bash 29dd003a9SVladimir Sementsov-Ogievskiy# group: rw auto quick 33dd48fdcSMax Reitz# 43dd48fdcSMax Reitz# Tests oVirt-like storage migration: 53dd48fdcSMax Reitz# - Create snapshot 63dd48fdcSMax Reitz# - Create target image with (not yet existing) target backing chain 73dd48fdcSMax Reitz# (i.e. just write the name of a soon-to-be-copied-over backing file into it) 83dd48fdcSMax Reitz# - drive-mirror the snapshot to the target with mode=existing and sync=top 93dd48fdcSMax Reitz# - In the meantime, copy the original source files to the destination via 103dd48fdcSMax Reitz# conventional means (i.e. outside of qemu) 113dd48fdcSMax Reitz# - Complete the drive-mirror job 123dd48fdcSMax Reitz# - Delete all source images 133dd48fdcSMax Reitz# 143dd48fdcSMax Reitz# Copyright (C) 2016 Red Hat, Inc. 153dd48fdcSMax Reitz# 163dd48fdcSMax Reitz# This program is free software; you can redistribute it and/or modify 173dd48fdcSMax Reitz# it under the terms of the GNU General Public License as published by 183dd48fdcSMax Reitz# the Free Software Foundation; either version 2 of the License, or 193dd48fdcSMax Reitz# (at your option) any later version. 203dd48fdcSMax Reitz# 213dd48fdcSMax Reitz# This program is distributed in the hope that it will be useful, 223dd48fdcSMax Reitz# but WITHOUT ANY WARRANTY; without even the implied warranty of 233dd48fdcSMax Reitz# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 243dd48fdcSMax Reitz# GNU General Public License for more details. 253dd48fdcSMax Reitz# 263dd48fdcSMax Reitz# You should have received a copy of the GNU General Public License 273dd48fdcSMax Reitz# along with this program. If not, see <http://www.gnu.org/licenses/>. 283dd48fdcSMax Reitz# 293dd48fdcSMax Reitz 303dd48fdcSMax Reitz# creator 3142a5009dSJohn Snowowner=hreitz@redhat.com 323dd48fdcSMax Reitz 333dd48fdcSMax Reitzseq="$(basename $0)" 343dd48fdcSMax Reitzecho "QA output created by $seq" 353dd48fdcSMax Reitz 363dd48fdcSMax Reitzstatus=1 # failure is the default! 373dd48fdcSMax Reitz 383dd48fdcSMax Reitz_cleanup() 393dd48fdcSMax Reitz{ 40ecfa1854SJeff Cody _cleanup_qemu 41f91ecbd7SMax Reitz for img in "$TEST_IMG"{,.target}{,.backing,.overlay}; do 42f91ecbd7SMax Reitz _rm_test_img "$img" 43f91ecbd7SMax Reitz done 443dd48fdcSMax Reitz} 453dd48fdcSMax Reitztrap "_cleanup; exit \$status" 0 1 2 3 15 463dd48fdcSMax Reitz 473dd48fdcSMax Reitz# get standard environment, filters and checks 483dd48fdcSMax Reitz. ./common.rc 493dd48fdcSMax Reitz. ./common.filter 503dd48fdcSMax Reitz. ./common.qemu 513dd48fdcSMax Reitz 523dd48fdcSMax Reitz_supported_fmt qcow2 qed 53*e7a271beSThomas Huth_supported_proto file 543be2024aSMax Reitz# Copying files around with cp does not work with external data files 553be2024aSMax Reitz_unsupported_imgopts data_file 563dd48fdcSMax Reitz 573dd48fdcSMax Reitz# Create source disk 583dd48fdcSMax ReitzTEST_IMG="$TEST_IMG.backing" _make_test_img 1M 59b66ff2c2SEric Blake_make_test_img -b "$TEST_IMG.backing" -F $IMGFMT 1M 603dd48fdcSMax Reitz 613dd48fdcSMax Reitz$QEMU_IO -c 'write -P 1 0 256k' "$TEST_IMG.backing" | _filter_qemu_io 623dd48fdcSMax Reitz$QEMU_IO -c 'write -P 2 64k 192k' "$TEST_IMG" | _filter_qemu_io 633dd48fdcSMax Reitz 643dd48fdcSMax Reitz_launch_qemu -drive if=none,id=source,file="$TEST_IMG" 653dd48fdcSMax Reitz 663dd48fdcSMax Reitz_send_qemu_cmd $QEMU_HANDLE \ 673dd48fdcSMax Reitz "{ 'execute': 'qmp_capabilities' }" \ 683dd48fdcSMax Reitz 'return' 693dd48fdcSMax Reitz 703dd48fdcSMax Reitz# Create snapshot 71b66ff2c2SEric BlakeTEST_IMG="$TEST_IMG.overlay" _make_test_img -u -b "$TEST_IMG" -F $IMGFMT 1M 723dd48fdcSMax Reitz_send_qemu_cmd $QEMU_HANDLE \ 733dd48fdcSMax Reitz "{ 'execute': 'blockdev-snapshot-sync', 743dd48fdcSMax Reitz 'arguments': { 'device': 'source', 753dd48fdcSMax Reitz 'snapshot-file': '$TEST_IMG.overlay', 763dd48fdcSMax Reitz 'format': '$IMGFMT', 773dd48fdcSMax Reitz 'mode': 'existing' } }" \ 783dd48fdcSMax Reitz 'return' 793dd48fdcSMax Reitz 803dd48fdcSMax Reitz# Write something to the snapshot 813dd48fdcSMax Reitz_send_qemu_cmd $QEMU_HANDLE \ 823dd48fdcSMax Reitz "{ 'execute': 'human-monitor-command', 833dd48fdcSMax Reitz 'arguments': { 'command-line': 843dd48fdcSMax Reitz 'qemu-io source \"write -P 3 128k 128k\"' } }" \ 853dd48fdcSMax Reitz 'return' 863dd48fdcSMax Reitz 873dd48fdcSMax Reitz# Create target image 88b66ff2c2SEric BlakeTEST_IMG="$TEST_IMG.target.overlay" _make_test_img -u -b "$TEST_IMG.target" \ 89b66ff2c2SEric Blake -F $IMGFMT 1M 903dd48fdcSMax Reitz 913dd48fdcSMax Reitz# Mirror snapshot 923dd48fdcSMax Reitz_send_qemu_cmd $QEMU_HANDLE \ 933dd48fdcSMax Reitz "{ 'execute': 'drive-mirror', 943dd48fdcSMax Reitz 'arguments': { 'device': 'source', 953dd48fdcSMax Reitz 'target': '$TEST_IMG.target.overlay', 963dd48fdcSMax Reitz 'mode': 'existing', 973dd48fdcSMax Reitz 'sync': 'top' } }" \ 983dd48fdcSMax Reitz 'return' 993dd48fdcSMax Reitz 1003dd48fdcSMax Reitz# Wait for convergence 1013dd48fdcSMax Reitz_send_qemu_cmd $QEMU_HANDLE \ 1023dd48fdcSMax Reitz '' \ 1033dd48fdcSMax Reitz 'BLOCK_JOB_READY' 1043dd48fdcSMax Reitz 1053dd48fdcSMax Reitz# Write some more 1063dd48fdcSMax Reitz_send_qemu_cmd $QEMU_HANDLE \ 1073dd48fdcSMax Reitz "{ 'execute': 'human-monitor-command', 1083dd48fdcSMax Reitz 'arguments': { 'command-line': 1093dd48fdcSMax Reitz 'qemu-io source \"write -P 4 192k 64k\"' } }" \ 1103dd48fdcSMax Reitz 'return' 1113dd48fdcSMax Reitz 1123dd48fdcSMax Reitz# Copy source backing chain to the target before completing the job 1133dd48fdcSMax Reitzcp "$TEST_IMG.backing" "$TEST_IMG.target.backing" 1143dd48fdcSMax Reitzcp "$TEST_IMG" "$TEST_IMG.target" 115b66ff2c2SEric Blake$QEMU_IMG rebase -u -b "$TEST_IMG.target.backing" -F $IMGFMT "$TEST_IMG.target" 1163dd48fdcSMax Reitz 1173dd48fdcSMax Reitz# Complete block job 1183dd48fdcSMax Reitz_send_qemu_cmd $QEMU_HANDLE \ 1193dd48fdcSMax Reitz "{ 'execute': 'block-job-complete', 1203dd48fdcSMax Reitz 'arguments': { 'device': 'source' } }" \ 1213dd48fdcSMax Reitz '' 1223dd48fdcSMax Reitz 1233dd48fdcSMax Reitz_send_qemu_cmd $QEMU_HANDLE \ 1243dd48fdcSMax Reitz '' \ 1251dac83f1SKevin Wolf '"status": "null"' 1263dd48fdcSMax Reitz 1273dd48fdcSMax Reitz# Remove the source images 128f91ecbd7SMax Reitzfor img in "$TEST_IMG{,.backing,.overlay}"; do 129f91ecbd7SMax Reitz _rm_test_img "$img" 130f91ecbd7SMax Reitzdone 1313dd48fdcSMax Reitz 1323dd48fdcSMax Reitzecho 1333dd48fdcSMax Reitz 1343dd48fdcSMax Reitz# Check online disk contents 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 1 0k 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 2 64k 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 3 128k 64k\"' } }" \ 1513dd48fdcSMax Reitz 'return' 1523dd48fdcSMax Reitz 1533dd48fdcSMax Reitz_send_qemu_cmd $QEMU_HANDLE \ 1543dd48fdcSMax Reitz "{ 'execute': 'human-monitor-command', 1553dd48fdcSMax Reitz 'arguments': { 'command-line': 1563dd48fdcSMax Reitz 'qemu-io source \"read -P 4 192k 64k\"' } }" \ 1573dd48fdcSMax Reitz 'return' 1583dd48fdcSMax Reitz 1593dd48fdcSMax Reitzecho 1603dd48fdcSMax Reitz 1613dd48fdcSMax Reitz_send_qemu_cmd $QEMU_HANDLE \ 1623dd48fdcSMax Reitz "{ 'execute': 'quit' }" \ 1633dd48fdcSMax Reitz 'return' 1643dd48fdcSMax Reitz 1653dd48fdcSMax Reitzwait=1 _cleanup_qemu 1663dd48fdcSMax Reitz 1673dd48fdcSMax Reitzecho 1683dd48fdcSMax Reitz 1693dd48fdcSMax Reitz# Check offline disk contents 1703dd48fdcSMax Reitz$QEMU_IO -c 'read -P 1 0k 64k' \ 1713dd48fdcSMax Reitz -c 'read -P 2 64k 64k' \ 1723dd48fdcSMax Reitz -c 'read -P 3 128k 64k' \ 1733dd48fdcSMax Reitz -c 'read -P 4 192k 64k' \ 1743dd48fdcSMax Reitz "$TEST_IMG.target.overlay" | _filter_qemu_io 1753dd48fdcSMax Reitz 1763dd48fdcSMax Reitzecho 1773dd48fdcSMax Reitz 1783dd48fdcSMax Reitz# success, all done 1793dd48fdcSMax Reitzecho '*** done' 1803dd48fdcSMax Reitzrm -f $seq.full 1813dd48fdcSMax Reitzstatus=0 182