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