blob: f8ce3288db421795c672791956431bb9af292bf4 [file] [log] [blame]
Philippe Mathieu-Daudé11a82d12019-03-07 15:58:38 +01001#!/usr/bin/env bash
Vladimir Sementsov-Ogievskiy9dd003a2021-01-16 16:44:19 +03002# group: rw auto backing
Stefan Hajnoczi514d9da2012-10-17 14:02:32 +02003#
4# Test that qemu-img info --backing-chain detects infinite loops
5#
6# Copyright (C) 2012 Red Hat, Inc.
7#
8# This program is free software; you can redistribute it and/or modify
9# it under the terms of the GNU General Public License as published by
10# the Free Software Foundation; either version 2 of the License, or
11# (at your option) any later version.
12#
13# This program is distributed in the hope that it will be useful,
14# but WITHOUT ANY WARRANTY; without even the implied warranty of
15# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16# GNU General Public License for more details.
17#
18# You should have received a copy of the GNU General Public License
19# along with this program. If not, see <http://www.gnu.org/licenses/>.
20#
21
22# creator
23owner=stefanha@redhat.com
24
25seq=`basename $0`
26echo "QA output created by $seq"
27
Stefan Hajnoczi514d9da2012-10-17 14:02:32 +020028status=1 # failure is the default!
29
30_cleanup()
31{
32 _cleanup_test_img
Max Reitzf91ecbd2019-11-07 17:37:01 +010033 for img in "$TEST_IMG".[123].base; do
34 _rm_test_img "$img"
35 done
Stefan Hajnoczi514d9da2012-10-17 14:02:32 +020036}
37trap "_cleanup; exit \$status" 0 1 2 3 15
38
39# get standard environment, filters and checks
40. ./common.rc
41. ./common.filter
42
43# Any format supporting backing files
Fam Zhengdbcdd7c2013-05-07 19:13:04 +080044_supported_fmt qcow2 qed
Peter Lieven1f7bf7d2014-02-03 10:26:14 +010045_supported_proto file
Stefan Hajnoczi514d9da2012-10-17 14:02:32 +020046
47
48size=128M
49_make_test_img $size
Eric Blakeb66ff2c2020-07-06 15:39:52 -050050$QEMU_IMG rebase -u -b "$TEST_IMG" -F $IMGFMT "$TEST_IMG"
Stefan Hajnoczi514d9da2012-10-17 14:02:32 +020051
52echo
53echo "== backing file references self =="
54_img_info --backing-chain
55
56_make_test_img $size
Jeff Codyfef9c192013-09-25 08:12:22 -040057mv "$TEST_IMG" "$TEST_IMG.base"
Eric Blakeb66ff2c2020-07-06 15:39:52 -050058_make_test_img -b "$TEST_IMG.base" -F $IMGFMT $size
59$QEMU_IMG rebase -u -b "$TEST_IMG" -F $IMGFMT "$TEST_IMG.base"
Stefan Hajnoczi514d9da2012-10-17 14:02:32 +020060
61echo
62echo "== parent references self =="
63_img_info --backing-chain
64
65_make_test_img $size
Jeff Codyfef9c192013-09-25 08:12:22 -040066mv "$TEST_IMG" "$TEST_IMG.1.base"
Eric Blakeb66ff2c2020-07-06 15:39:52 -050067_make_test_img -b "$TEST_IMG.1.base" -F $IMGFMT $size
Jeff Codyfef9c192013-09-25 08:12:22 -040068mv "$TEST_IMG" "$TEST_IMG.2.base"
Eric Blakeb66ff2c2020-07-06 15:39:52 -050069_make_test_img -b "$TEST_IMG.2.base" -F $IMGFMT $size
Jeff Codyfef9c192013-09-25 08:12:22 -040070mv "$TEST_IMG" "$TEST_IMG.3.base"
Eric Blakeb66ff2c2020-07-06 15:39:52 -050071_make_test_img -b "$TEST_IMG.3.base" -F $IMGFMT $size
72$QEMU_IMG rebase -u -b "$TEST_IMG.2.base" -F $IMGFMT "$TEST_IMG.1.base"
Stefan Hajnoczi514d9da2012-10-17 14:02:32 +020073
74echo
75echo "== ancestor references another ancestor =="
76_img_info --backing-chain
77
78_make_test_img $size
Jeff Codyfef9c192013-09-25 08:12:22 -040079mv "$TEST_IMG" "$TEST_IMG.1.base"
Eric Blakeb66ff2c2020-07-06 15:39:52 -050080_make_test_img -b "$TEST_IMG.1.base" -F $IMGFMT $size
Jeff Codyfef9c192013-09-25 08:12:22 -040081mv "$TEST_IMG" "$TEST_IMG.2.base"
Eric Blakeb66ff2c2020-07-06 15:39:52 -050082_make_test_img -b "$TEST_IMG.2.base" -F $IMGFMT $size
Stefan Hajnoczi514d9da2012-10-17 14:02:32 +020083
84echo
85echo "== finite chain of length 3 (human) =="
Eric Blakeb66ff2c2020-07-06 15:39:52 -050086# Exclude backing format, since qed differs from qcow2 on what gets stored
87_img_info --backing-chain | grep -v '^backing file format:'
Stefan Hajnoczi514d9da2012-10-17 14:02:32 +020088
89echo
90echo "== finite chain of length 3 (json) =="
Eric Blakeb66ff2c2020-07-06 15:39:52 -050091_img_info --backing-chain --output=json | grep -v 'backing-filename-format'
Stefan Hajnoczi514d9da2012-10-17 14:02:32 +020092
93# success, all done
94echo "*** done"
95rm -f $seq.full
96status=0