1ef9bba14SAlberto Garcia#!/usr/bin/env bash 29dd003a9SVladimir Sementsov-Ogievskiy# group: rw quick 3ef9bba14SAlberto Garcia# 4ef9bba14SAlberto Garcia# Test drive-mirror with quorum 5ef9bba14SAlberto Garcia# 6ef9bba14SAlberto Garcia# The goal of this test is to check how the quorum driver reports 7ef9bba14SAlberto Garcia# regions that are known to read as zeroes (BDRV_BLOCK_ZERO). The idea 8ef9bba14SAlberto Garcia# is that drive-mirror will try the efficient representation of zeroes 9ef9bba14SAlberto Garcia# in the destination image instead of writing actual zeroes. 10ef9bba14SAlberto Garcia# 11ef9bba14SAlberto Garcia# Copyright (C) 2020 Igalia, S.L. 12ef9bba14SAlberto Garcia# Author: Alberto Garcia <berto@igalia.com> 13ef9bba14SAlberto Garcia# 14ef9bba14SAlberto Garcia# This program is free software; you can redistribute it and/or modify 15ef9bba14SAlberto Garcia# it under the terms of the GNU General Public License as published by 16ef9bba14SAlberto Garcia# the Free Software Foundation; either version 2 of the License, or 17ef9bba14SAlberto Garcia# (at your option) any later version. 18ef9bba14SAlberto Garcia# 19ef9bba14SAlberto Garcia# This program is distributed in the hope that it will be useful, 20ef9bba14SAlberto Garcia# but WITHOUT ANY WARRANTY; without even the implied warranty of 21ef9bba14SAlberto Garcia# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 22ef9bba14SAlberto Garcia# GNU General Public License for more details. 23ef9bba14SAlberto Garcia# 24ef9bba14SAlberto Garcia# You should have received a copy of the GNU General Public License 25ef9bba14SAlberto Garcia# along with this program. If not, see <http://www.gnu.org/licenses/>. 26ef9bba14SAlberto Garcia# 27ef9bba14SAlberto Garcia 28ef9bba14SAlberto Garcia# creator 29ef9bba14SAlberto Garciaowner=berto@igalia.com 30ef9bba14SAlberto Garcia 31ef9bba14SAlberto Garciaseq=`basename $0` 32ef9bba14SAlberto Garciaecho "QA output created by $seq" 33ef9bba14SAlberto Garcia 34ef9bba14SAlberto Garciastatus=1 # failure is the default! 35ef9bba14SAlberto Garcia 36ef9bba14SAlberto Garcia_cleanup() 37ef9bba14SAlberto Garcia{ 38ef9bba14SAlberto Garcia _rm_test_img "$TEST_IMG.0" 39ef9bba14SAlberto Garcia _rm_test_img "$TEST_IMG.1" 40ef9bba14SAlberto Garcia _rm_test_img "$TEST_IMG.2" 41ef9bba14SAlberto Garcia _rm_test_img "$TEST_IMG.3" 42ef9bba14SAlberto Garcia _cleanup_qemu 43ef9bba14SAlberto Garcia} 44ef9bba14SAlberto Garciatrap "_cleanup; exit \$status" 0 1 2 3 15 45ef9bba14SAlberto Garcia 46ef9bba14SAlberto Garcia# get standard environment, filters and checks 47ef9bba14SAlberto Garcia. ./common.rc 48ef9bba14SAlberto Garcia. ./common.filter 49ef9bba14SAlberto Garcia. ./common.qemu 50ef9bba14SAlberto Garcia 51ef9bba14SAlberto Garcia_supported_fmt qcow2 52ef9bba14SAlberto Garcia_supported_proto file 53ef9bba14SAlberto Garcia_supported_os Linux 54ef9bba14SAlberto Garcia_unsupported_imgopts cluster_size data_file 55*724e6703SThomas Huth_require_drivers quorum 56ef9bba14SAlberto Garcia 57ef9bba14SAlberto Garciaecho 58ef9bba14SAlberto Garciaecho '### Create all images' # three source (quorum), one destination 59ef9bba14SAlberto Garciaecho 60ef9bba14SAlberto GarciaTEST_IMG="$TEST_IMG.0" _make_test_img -o cluster_size=64k 10M 61ef9bba14SAlberto GarciaTEST_IMG="$TEST_IMG.1" _make_test_img -o cluster_size=64k 10M 62ef9bba14SAlberto GarciaTEST_IMG="$TEST_IMG.2" _make_test_img -o cluster_size=64k 10M 63ef9bba14SAlberto GarciaTEST_IMG="$TEST_IMG.3" _make_test_img -o cluster_size=64k 10M 64ef9bba14SAlberto Garcia 65ef9bba14SAlberto Garciaquorum="driver=raw,file.driver=quorum,file.vote-threshold=2" 66ef9bba14SAlberto Garciaquorum="$quorum,file.children.0.file.filename=$TEST_IMG.0" 67ef9bba14SAlberto Garciaquorum="$quorum,file.children.1.file.filename=$TEST_IMG.1" 68ef9bba14SAlberto Garciaquorum="$quorum,file.children.2.file.filename=$TEST_IMG.2" 69ef9bba14SAlberto Garciaquorum="$quorum,file.children.0.driver=$IMGFMT" 70ef9bba14SAlberto Garciaquorum="$quorum,file.children.1.driver=$IMGFMT" 71ef9bba14SAlberto Garciaquorum="$quorum,file.children.2.driver=$IMGFMT" 72ef9bba14SAlberto Garcia 73ef9bba14SAlberto Garciaecho 74ef9bba14SAlberto Garciaecho '### Output of qemu-img map (empty quorum)' 75ef9bba14SAlberto Garciaecho 76ef9bba14SAlberto Garcia$QEMU_IMG map --image-opts $quorum | _filter_qemu_img_map 77ef9bba14SAlberto Garcia 78ef9bba14SAlberto Garcia# Now we write data to the quorum. All three images will read as 79ef9bba14SAlberto Garcia# zeroes in all cases, but with different ways to represent them 80ef9bba14SAlberto Garcia# (unallocated clusters, zero clusters, data clusters with zeroes) 81ef9bba14SAlberto Garcia# that will have an effect on how the data will be mirrored and the 82ef9bba14SAlberto Garcia# output of qemu-img map on the resulting image. 83ef9bba14SAlberto Garciaecho 84ef9bba14SAlberto Garciaecho '### Write data to the quorum' 85ef9bba14SAlberto Garciaecho 86ef9bba14SAlberto Garcia# Test 1: data regions surrounded by unallocated clusters. 87ef9bba14SAlberto Garcia# Three data regions, the largest one (0x30000) will be picked, end result: 88ef9bba14SAlberto Garcia# offset 0x10000, length 0x30000 -> data 89ef9bba14SAlberto Garcia$QEMU_IO -c "write -P 0 $((0x10000)) $((0x10000))" "$TEST_IMG.0" | _filter_qemu_io 90ef9bba14SAlberto Garcia$QEMU_IO -c "write -P 0 $((0x10000)) $((0x30000))" "$TEST_IMG.1" | _filter_qemu_io 91ef9bba14SAlberto Garcia$QEMU_IO -c "write -P 0 $((0x10000)) $((0x20000))" "$TEST_IMG.2" | _filter_qemu_io 92ef9bba14SAlberto Garcia 93ef9bba14SAlberto Garcia# Test 2: zero regions surrounded by data clusters. 94ef9bba14SAlberto Garcia# First we allocate the data clusters. 95ef9bba14SAlberto Garcia$QEMU_IO -c "open -o $quorum" -c "write -P 0 $((0x100000)) $((0x40000))" | _filter_qemu_io 96ef9bba14SAlberto Garcia 97ef9bba14SAlberto Garcia# Three zero regions, the smallest one (0x10000) will be picked, end result: 98ef9bba14SAlberto Garcia# offset 0x100000, length 0x10000 -> data 99ef9bba14SAlberto Garcia# offset 0x110000, length 0x10000 -> zeroes 100ef9bba14SAlberto Garcia# offset 0x120000, length 0x20000 -> data 101ef9bba14SAlberto Garcia$QEMU_IO -c "write -z $((0x110000)) $((0x10000))" "$TEST_IMG.0" | _filter_qemu_io 102ef9bba14SAlberto Garcia$QEMU_IO -c "write -z $((0x110000)) $((0x30000))" "$TEST_IMG.1" | _filter_qemu_io 103ef9bba14SAlberto Garcia$QEMU_IO -c "write -z $((0x110000)) $((0x20000))" "$TEST_IMG.2" | _filter_qemu_io 104ef9bba14SAlberto Garcia 105ef9bba14SAlberto Garcia# Test 3: zero clusters surrounded by unallocated clusters. 106ef9bba14SAlberto Garcia# Everything reads as zeroes, no effect on the end result. 107ef9bba14SAlberto Garcia$QEMU_IO -c "write -z $((0x150000)) $((0x10000))" "$TEST_IMG.0" | _filter_qemu_io 108ef9bba14SAlberto Garcia$QEMU_IO -c "write -z $((0x150000)) $((0x30000))" "$TEST_IMG.1" | _filter_qemu_io 109ef9bba14SAlberto Garcia$QEMU_IO -c "write -z $((0x150000)) $((0x20000))" "$TEST_IMG.2" | _filter_qemu_io 110ef9bba14SAlberto Garcia 111ef9bba14SAlberto Garcia# Test 4: mix of data and zero clusters. 112ef9bba14SAlberto Garcia# The zero region will be ignored in favor of the largest data region 113ef9bba14SAlberto Garcia# (0x20000), end result: 114ef9bba14SAlberto Garcia# offset 0x200000, length 0x20000 -> data 115ef9bba14SAlberto Garcia$QEMU_IO -c "write -P 0 $((0x200000)) $((0x10000))" "$TEST_IMG.0" | _filter_qemu_io 116ef9bba14SAlberto Garcia$QEMU_IO -c "write -z $((0x200000)) $((0x30000))" "$TEST_IMG.1" | _filter_qemu_io 117ef9bba14SAlberto Garcia$QEMU_IO -c "write -P 0 $((0x200000)) $((0x20000))" "$TEST_IMG.2" | _filter_qemu_io 118ef9bba14SAlberto Garcia 1195cddb2e9SAlberto Garcia# Test 5: write data to a region and then zeroize it, doing it 1205cddb2e9SAlberto Garcia# directly on the quorum device instead of the individual images. 1215cddb2e9SAlberto Garcia# This has no effect on the end result but proves that the quorum driver 1225cddb2e9SAlberto Garcia# supports 'write -z'. 1235cddb2e9SAlberto Garcia$QEMU_IO -c "open -o $quorum" -c "write -P 1 $((0x250000)) $((0x10000))" | _filter_qemu_io 1245cddb2e9SAlberto Garcia# Verify the data that we just wrote 1255cddb2e9SAlberto Garcia$QEMU_IO -c "open -o $quorum" -c "read -P 1 $((0x250000)) $((0x10000))" | _filter_qemu_io 1265cddb2e9SAlberto Garcia$QEMU_IO -c "open -o $quorum" -c "write -z $((0x250000)) $((0x10000))" | _filter_qemu_io 1275cddb2e9SAlberto Garcia# Now it should read back as zeroes 1285cddb2e9SAlberto Garcia$QEMU_IO -c "open -o $quorum" -c "read -P 0 $((0x250000)) $((0x10000))" | _filter_qemu_io 1295cddb2e9SAlberto Garcia 130ef9bba14SAlberto Garciaecho 131ef9bba14SAlberto Garciaecho '### Launch the drive-mirror job' 132ef9bba14SAlberto Garciaecho 133ef9bba14SAlberto Garciaqemu_comm_method="qmp" _launch_qemu -drive if=virtio,"$quorum" 134ef9bba14SAlberto Garciah=$QEMU_HANDLE 135ef9bba14SAlberto Garcia_send_qemu_cmd $h "{ 'execute': 'qmp_capabilities' }" 'return' 136ef9bba14SAlberto Garcia 137ef9bba14SAlberto Garcia_send_qemu_cmd $h \ 138ef9bba14SAlberto Garcia "{'execute': 'drive-mirror', 139ef9bba14SAlberto Garcia 'arguments': {'device': 'virtio0', 140ef9bba14SAlberto Garcia 'format': '$IMGFMT', 141ef9bba14SAlberto Garcia 'target': '$TEST_IMG.3', 142ef9bba14SAlberto Garcia 'sync': 'full', 143ef9bba14SAlberto Garcia 'mode': 'existing' }}" \ 144ef9bba14SAlberto Garcia "BLOCK_JOB_READY.*virtio0" 145ef9bba14SAlberto Garcia 146ef9bba14SAlberto Garcia_send_qemu_cmd $h \ 147ef9bba14SAlberto Garcia "{ 'execute': 'block-job-complete', 148ef9bba14SAlberto Garcia 'arguments': { 'device': 'virtio0' } }" \ 149ef9bba14SAlberto Garcia 'BLOCK_JOB_COMPLETED' 150ef9bba14SAlberto Garcia 151ef9bba14SAlberto Garcia_send_qemu_cmd $h "{ 'execute': 'quit' }" '' 152ef9bba14SAlberto Garcia 153ef9bba14SAlberto Garciaecho 154ef9bba14SAlberto Garciaecho '### Output of qemu-img map (destination image)' 155ef9bba14SAlberto Garciaecho 156ef9bba14SAlberto Garcia$QEMU_IMG map "$TEST_IMG.3" | _filter_qemu_img_map 157ef9bba14SAlberto Garcia 158ef9bba14SAlberto Garcia# success, all done 159ef9bba14SAlberto Garciaecho "*** done" 160ef9bba14SAlberto Garciarm -f $seq.full 161ef9bba14SAlberto Garciastatus=0 162