xref: /openbmc/qemu/tests/qemu-iotests/252 (revision f91ecbd7)
111f6fc50SMax Reitz#!/usr/bin/env bash
211f6fc50SMax Reitz#
311f6fc50SMax Reitz# Tests for rebasing COW images that require zero cluster support
411f6fc50SMax Reitz#
511f6fc50SMax Reitz# Copyright (C) 2019 Red Hat, Inc.
611f6fc50SMax Reitz#
711f6fc50SMax Reitz# This program is free software; you can redistribute it and/or modify
811f6fc50SMax Reitz# it under the terms of the GNU General Public License as published by
911f6fc50SMax Reitz# the Free Software Foundation; either version 2 of the License, or
1011f6fc50SMax Reitz# (at your option) any later version.
1111f6fc50SMax Reitz#
1211f6fc50SMax Reitz# This program is distributed in the hope that it will be useful,
1311f6fc50SMax Reitz# but WITHOUT ANY WARRANTY; without even the implied warranty of
1411f6fc50SMax Reitz# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
1511f6fc50SMax Reitz# GNU General Public License for more details.
1611f6fc50SMax Reitz#
1711f6fc50SMax Reitz# You should have received a copy of the GNU General Public License
1811f6fc50SMax Reitz# along with this program.  If not, see <http://www.gnu.org/licenses/>.
1911f6fc50SMax Reitz#
2011f6fc50SMax Reitz
2111f6fc50SMax Reitz# creator
2211f6fc50SMax Reitzowner=mreitz@redhat.com
2311f6fc50SMax Reitz
2411f6fc50SMax Reitzseq=$(basename $0)
2511f6fc50SMax Reitzecho "QA output created by $seq"
2611f6fc50SMax Reitz
2711f6fc50SMax Reitzstatus=1	# failure is the default!
2811f6fc50SMax Reitz
2911f6fc50SMax Reitz_cleanup()
3011f6fc50SMax Reitz{
3111f6fc50SMax Reitz    _cleanup_test_img
32*f91ecbd7SMax Reitz    _rm_test_img "$TEST_IMG.base_new"
3311f6fc50SMax Reitz}
3411f6fc50SMax Reitztrap "_cleanup; exit \$status" 0 1 2 3 15
3511f6fc50SMax Reitz
3611f6fc50SMax Reitz# get standard environment, filters and checks
3711f6fc50SMax Reitz. ./common.rc
3811f6fc50SMax Reitz. ./common.filter
3911f6fc50SMax Reitz. ./common.pattern
4011f6fc50SMax Reitz
4111f6fc50SMax Reitz# Currently only qcow2 and qed support rebasing, and only qcow2 v3 has
4211f6fc50SMax Reitz# zero cluster support
4311f6fc50SMax Reitz_supported_fmt qcow2
4411f6fc50SMax Reitz_unsupported_imgopts 'compat=0.10'
4511f6fc50SMax Reitz_supported_proto file
4611f6fc50SMax Reitz_supported_os Linux
4711f6fc50SMax Reitz
4811f6fc50SMax ReitzCLUSTER_SIZE=65536
4911f6fc50SMax Reitz
5011f6fc50SMax Reitzecho
5111f6fc50SMax Reitzecho "=== Test rebase without input base ==="
5211f6fc50SMax Reitzecho
5311f6fc50SMax Reitz
5411f6fc50SMax Reitz# Cluster allocations to be tested:
5511f6fc50SMax Reitz#
5611f6fc50SMax Reitz# Backing (new) 11 -- 11 -- 11 --
5711f6fc50SMax Reitz# COW image     22 22 11 11 -- --
5811f6fc50SMax Reitz#
5911f6fc50SMax Reitz# Expected result:
6011f6fc50SMax Reitz#
6111f6fc50SMax Reitz# COW image     22 22 11 11 00 --
6211f6fc50SMax Reitz#
6311f6fc50SMax Reitz# (Cluster 2 might be "--" after the rebase, too, but rebase just
6411f6fc50SMax Reitz#  compares the new backing file to the old one and disregards the
6511f6fc50SMax Reitz#  overlay.  Therefore, it will never discard overlay clusters.)
6611f6fc50SMax Reitz
6711f6fc50SMax Reitz_make_test_img $((6 * CLUSTER_SIZE))
6811f6fc50SMax ReitzTEST_IMG="$TEST_IMG.base_new" _make_test_img $((6 * CLUSTER_SIZE))
6911f6fc50SMax Reitz
7011f6fc50SMax Reitzecho
7111f6fc50SMax Reitz
7211f6fc50SMax Reitz$QEMU_IO "$TEST_IMG" \
7311f6fc50SMax Reitz    -c "write -P 0x22 $((0 * CLUSTER_SIZE)) $((2 * CLUSTER_SIZE))" \
7411f6fc50SMax Reitz    -c "write -P 0x11 $((2 * CLUSTER_SIZE)) $((2 * CLUSTER_SIZE))" \
7511f6fc50SMax Reitz    | _filter_qemu_io
7611f6fc50SMax Reitz
7711f6fc50SMax Reitz$QEMU_IO "$TEST_IMG.base_new" \
7811f6fc50SMax Reitz    -c "write -P 0x11 $((0 * CLUSTER_SIZE)) $CLUSTER_SIZE" \
7911f6fc50SMax Reitz    -c "write -P 0x11 $((2 * CLUSTER_SIZE)) $CLUSTER_SIZE" \
8011f6fc50SMax Reitz    -c "write -P 0x11 $((4 * CLUSTER_SIZE)) $CLUSTER_SIZE" \
8111f6fc50SMax Reitz    | _filter_qemu_io
8211f6fc50SMax Reitz
8311f6fc50SMax Reitzecho
8411f6fc50SMax Reitz
8511f6fc50SMax Reitz# This should be a no-op
8611f6fc50SMax Reitz$QEMU_IMG rebase -b "" "$TEST_IMG"
8711f6fc50SMax Reitz
8811f6fc50SMax Reitz# Verify the data is correct
8911f6fc50SMax Reitz$QEMU_IO "$TEST_IMG" \
9011f6fc50SMax Reitz    -c "read -P 0x22 $((0 * CLUSTER_SIZE)) $((2 * CLUSTER_SIZE))" \
9111f6fc50SMax Reitz    -c "read -P 0x11 $((2 * CLUSTER_SIZE)) $((2 * CLUSTER_SIZE))" \
9211f6fc50SMax Reitz    -c "read -P 0x00 $((4 * CLUSTER_SIZE)) $((2 * CLUSTER_SIZE))" \
9311f6fc50SMax Reitz    | _filter_qemu_io
9411f6fc50SMax Reitz
9511f6fc50SMax Reitzecho
9611f6fc50SMax Reitz
9711f6fc50SMax Reitz# Verify the allocation status (first four cluster should be allocated
9811f6fc50SMax Reitz# in TEST_IMG, clusters 4 and 5 should be unallocated (marked as zero
9911f6fc50SMax Reitz# clusters here because there is no backing file))
10011f6fc50SMax Reitz$QEMU_IMG map --output=json "$TEST_IMG" | _filter_qemu_img_map
10111f6fc50SMax Reitz
10211f6fc50SMax Reitzecho
10311f6fc50SMax Reitz
10411f6fc50SMax Reitz$QEMU_IMG rebase -b "$TEST_IMG.base_new" "$TEST_IMG"
10511f6fc50SMax Reitz
10611f6fc50SMax Reitz# Verify the data is correct
10711f6fc50SMax Reitz$QEMU_IO "$TEST_IMG" \
10811f6fc50SMax Reitz    -c "read -P 0x22 $((0 * CLUSTER_SIZE)) $((2 * CLUSTER_SIZE))" \
10911f6fc50SMax Reitz    -c "read -P 0x11 $((2 * CLUSTER_SIZE)) $((2 * CLUSTER_SIZE))" \
11011f6fc50SMax Reitz    -c "read -P 0x00 $((4 * CLUSTER_SIZE)) $((2 * CLUSTER_SIZE))" \
11111f6fc50SMax Reitz    | _filter_qemu_io
11211f6fc50SMax Reitz
11311f6fc50SMax Reitzecho
11411f6fc50SMax Reitz
11511f6fc50SMax Reitz# Verify the allocation status (first four cluster should be allocated
11611f6fc50SMax Reitz# in TEST_IMG, cluster 4 should be zero, and cluster 5 should be
11711f6fc50SMax Reitz# unallocated (signified by '"depth": 1'))
11811f6fc50SMax Reitz$QEMU_IMG map --output=json "$TEST_IMG" | _filter_qemu_img_map
11911f6fc50SMax Reitz
12011f6fc50SMax Reitz
12111f6fc50SMax Reitz# success, all done
12211f6fc50SMax Reitzecho "*** done"
12311f6fc50SMax Reitzrm -f $seq.full
12411f6fc50SMax Reitzstatus=0
125