1#!/bin/bash 2# 3# Tests oVirt-like storage migration: 4# - Create snapshot 5# - Create target image with (not yet existing) target backing chain 6# (i.e. just write the name of a soon-to-be-copied-over backing file into it) 7# - drive-mirror the snapshot to the target with mode=existing and sync=top 8# - In the meantime, copy the original source files to the destination via 9# conventional means (i.e. outside of qemu) 10# - Complete the drive-mirror job 11# - Delete all source images 12# 13# Copyright (C) 2016 Red Hat, Inc. 14# 15# This program is free software; you can redistribute it and/or modify 16# it under the terms of the GNU General Public License as published by 17# the Free Software Foundation; either version 2 of the License, or 18# (at your option) any later version. 19# 20# This program is distributed in the hope that it will be useful, 21# but WITHOUT ANY WARRANTY; without even the implied warranty of 22# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 23# GNU General Public License for more details. 24# 25# You should have received a copy of the GNU General Public License 26# along with this program. If not, see <http://www.gnu.org/licenses/>. 27# 28 29# creator 30owner=mreitz@redhat.com 31 32seq="$(basename $0)" 33echo "QA output created by $seq" 34 35here="$PWD" 36status=1 # failure is the default! 37 38_cleanup() 39{ 40 _cleanup_qemu 41 rm -f "$TEST_IMG"{,.target}{,.backing,.overlay} 42} 43trap "_cleanup; exit \$status" 0 1 2 3 15 44 45# get standard environment, filters and checks 46. ./common.rc 47. ./common.filter 48. ./common.qemu 49 50_supported_fmt qcow2 qed 51_supported_proto generic 52_unsupported_proto vxhs 53_supported_os Linux 54 55# Create source disk 56TEST_IMG="$TEST_IMG.backing" _make_test_img 1M 57_make_test_img -b "$TEST_IMG.backing" 1M 58 59$QEMU_IO -c 'write -P 1 0 256k' "$TEST_IMG.backing" | _filter_qemu_io 60$QEMU_IO -c 'write -P 2 64k 192k' "$TEST_IMG" | _filter_qemu_io 61 62_launch_qemu -drive if=none,id=source,file="$TEST_IMG" 63 64_send_qemu_cmd $QEMU_HANDLE \ 65 "{ 'execute': 'qmp_capabilities' }" \ 66 'return' 67 68# Create snapshot 69TEST_IMG="$TEST_IMG.overlay" _make_test_img -u -b "$TEST_IMG" 1M 70_send_qemu_cmd $QEMU_HANDLE \ 71 "{ 'execute': 'blockdev-snapshot-sync', 72 'arguments': { 'device': 'source', 73 'snapshot-file': '$TEST_IMG.overlay', 74 'format': '$IMGFMT', 75 'mode': 'existing' } }" \ 76 'return' 77 78# Write something to the snapshot 79_send_qemu_cmd $QEMU_HANDLE \ 80 "{ 'execute': 'human-monitor-command', 81 'arguments': { 'command-line': 82 'qemu-io source \"write -P 3 128k 128k\"' } }" \ 83 'return' 84 85# Create target image 86TEST_IMG="$TEST_IMG.target.overlay" _make_test_img -u -b "$TEST_IMG.target" 1M 87 88# Mirror snapshot 89_send_qemu_cmd $QEMU_HANDLE \ 90 "{ 'execute': 'drive-mirror', 91 'arguments': { 'device': 'source', 92 'target': '$TEST_IMG.target.overlay', 93 'mode': 'existing', 94 'sync': 'top' } }" \ 95 'return' 96 97# Wait for convergence 98_send_qemu_cmd $QEMU_HANDLE \ 99 '' \ 100 'BLOCK_JOB_READY' 101 102# Write some more 103_send_qemu_cmd $QEMU_HANDLE \ 104 "{ 'execute': 'human-monitor-command', 105 'arguments': { 'command-line': 106 'qemu-io source \"write -P 4 192k 64k\"' } }" \ 107 'return' 108 109# Copy source backing chain to the target before completing the job 110cp "$TEST_IMG.backing" "$TEST_IMG.target.backing" 111cp "$TEST_IMG" "$TEST_IMG.target" 112$QEMU_IMG rebase -u -b "$TEST_IMG.target.backing" "$TEST_IMG.target" 113 114# Complete block job 115_send_qemu_cmd $QEMU_HANDLE \ 116 "{ 'execute': 'block-job-complete', 117 'arguments': { 'device': 'source' } }" \ 118 '' 119 120_send_qemu_cmd $QEMU_HANDLE \ 121 '' \ 122 '"status": "null"' 123 124# Remove the source images 125rm -f "$TEST_IMG{,.backing,.overlay}" 126 127echo 128 129# Check online disk contents 130_send_qemu_cmd $QEMU_HANDLE \ 131 "{ 'execute': 'human-monitor-command', 132 'arguments': { 'command-line': 133 'qemu-io source \"read -P 1 0k 64k\"' } }" \ 134 'return' 135 136_send_qemu_cmd $QEMU_HANDLE \ 137 "{ 'execute': 'human-monitor-command', 138 'arguments': { 'command-line': 139 'qemu-io source \"read -P 2 64k 64k\"' } }" \ 140 'return' 141 142_send_qemu_cmd $QEMU_HANDLE \ 143 "{ 'execute': 'human-monitor-command', 144 'arguments': { 'command-line': 145 'qemu-io source \"read -P 3 128k 64k\"' } }" \ 146 'return' 147 148_send_qemu_cmd $QEMU_HANDLE \ 149 "{ 'execute': 'human-monitor-command', 150 'arguments': { 'command-line': 151 'qemu-io source \"read -P 4 192k 64k\"' } }" \ 152 'return' 153 154echo 155 156_send_qemu_cmd $QEMU_HANDLE \ 157 "{ 'execute': 'quit' }" \ 158 'return' 159 160wait=1 _cleanup_qemu 161 162echo 163 164# Check offline disk contents 165$QEMU_IO -c 'read -P 1 0k 64k' \ 166 -c 'read -P 2 64k 64k' \ 167 -c 'read -P 3 128k 64k' \ 168 -c 'read -P 4 192k 64k' \ 169 "$TEST_IMG.target.overlay" | _filter_qemu_io 170 171echo 172 173# success, all done 174echo '*** done' 175rm -f $seq.full 176status=0 177