1#!/usr/bin/env bash 2# 3# Tests for rebasing COW images that require zero cluster support 4# 5# Copyright (C) 2019 Red Hat, Inc. 6# 7# This program is free software; you can redistribute it and/or modify 8# it under the terms of the GNU General Public License as published by 9# the Free Software Foundation; either version 2 of the License, or 10# (at your option) any later version. 11# 12# This program is distributed in the hope that it will be useful, 13# but WITHOUT ANY WARRANTY; without even the implied warranty of 14# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15# GNU General Public License for more details. 16# 17# You should have received a copy of the GNU General Public License 18# along with this program. If not, see <http://www.gnu.org/licenses/>. 19# 20 21# creator 22owner=mreitz@redhat.com 23 24seq=$(basename $0) 25echo "QA output created by $seq" 26 27status=1 # failure is the default! 28 29_cleanup() 30{ 31 _cleanup_test_img 32 _rm_test_img "$TEST_IMG.base_new" 33} 34trap "_cleanup; exit \$status" 0 1 2 3 15 35 36# get standard environment, filters and checks 37. ./common.rc 38. ./common.filter 39. ./common.pattern 40 41# Currently only qcow2 and qed support rebasing, and only qcow2 v3 has 42# zero cluster support 43_supported_fmt qcow2 44_unsupported_imgopts 'compat=0.10' 45_supported_proto file fuse 46_supported_os Linux 47 48CLUSTER_SIZE=65536 49 50echo 51echo "=== Test rebase without input base ===" 52echo 53 54# Cluster allocations to be tested: 55# 56# Backing (new) 11 -- 11 -- 11 -- 57# COW image 22 22 11 11 -- -- 58# 59# Expected result: 60# 61# COW image 22 22 11 11 00 -- 62# 63# (Cluster 2 might be "--" after the rebase, too, but rebase just 64# compares the new backing file to the old one and disregards the 65# overlay. Therefore, it will never discard overlay clusters.) 66 67_make_test_img $((6 * CLUSTER_SIZE)) 68TEST_IMG="$TEST_IMG.base_new" _make_test_img $((6 * CLUSTER_SIZE)) 69 70echo 71 72$QEMU_IO "$TEST_IMG" \ 73 -c "write -P 0x22 $((0 * CLUSTER_SIZE)) $((2 * CLUSTER_SIZE))" \ 74 -c "write -P 0x11 $((2 * CLUSTER_SIZE)) $((2 * CLUSTER_SIZE))" \ 75 | _filter_qemu_io 76 77$QEMU_IO "$TEST_IMG.base_new" \ 78 -c "write -P 0x11 $((0 * CLUSTER_SIZE)) $CLUSTER_SIZE" \ 79 -c "write -P 0x11 $((2 * CLUSTER_SIZE)) $CLUSTER_SIZE" \ 80 -c "write -P 0x11 $((4 * CLUSTER_SIZE)) $CLUSTER_SIZE" \ 81 | _filter_qemu_io 82 83echo 84 85# This should be a no-op 86$QEMU_IMG rebase -b "" "$TEST_IMG" 87 88# Verify the data is correct 89$QEMU_IO "$TEST_IMG" \ 90 -c "read -P 0x22 $((0 * CLUSTER_SIZE)) $((2 * CLUSTER_SIZE))" \ 91 -c "read -P 0x11 $((2 * CLUSTER_SIZE)) $((2 * CLUSTER_SIZE))" \ 92 -c "read -P 0x00 $((4 * CLUSTER_SIZE)) $((2 * CLUSTER_SIZE))" \ 93 | _filter_qemu_io 94 95echo 96 97# Verify the allocation status (first four cluster should be allocated 98# in TEST_IMG, clusters 4 and 5 should be unallocated (marked as zero 99# clusters here because there is no backing file)) 100$QEMU_IMG map --output=json "$TEST_IMG" | _filter_qemu_img_map 101 102echo 103 104$QEMU_IMG rebase -b "$TEST_IMG.base_new" -F $IMGFMT "$TEST_IMG" 105 106# Verify the data is correct 107$QEMU_IO "$TEST_IMG" \ 108 -c "read -P 0x22 $((0 * CLUSTER_SIZE)) $((2 * CLUSTER_SIZE))" \ 109 -c "read -P 0x11 $((2 * CLUSTER_SIZE)) $((2 * CLUSTER_SIZE))" \ 110 -c "read -P 0x00 $((4 * CLUSTER_SIZE)) $((2 * CLUSTER_SIZE))" \ 111 | _filter_qemu_io 112 113echo 114 115# Verify the allocation status (first four cluster should be allocated 116# in TEST_IMG, cluster 4 should be zero, and cluster 5 should be 117# unallocated (signified by '"depth": 1')) 118$QEMU_IMG map --output=json "$TEST_IMG" | _filter_qemu_img_map 119 120 121# success, all done 122echo "*** done" 123rm -f $seq.full 124status=0 125