migration: API to clear bits of guest free pages from the dirty bitmap
[qemu/ar7.git] / tests / qemu-iotests / 161
blob180df17ad68aab42b8190db10f9ec097c19aee22
1 #!/bin/bash
3 # Test reopening a backing image after block-stream and block-commit
5 # Copyright (C) 2018 Igalia, S.L.
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.
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.
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/>.
21 # creator
22 owner=berto@igalia.com
24 seq=`basename $0`
25 echo "QA output created by $seq"
27 here=`pwd`
28 status=1 # failure is the default!
30 _cleanup()
32 _cleanup_test_img
33 rm -f "$TEST_IMG.base"
34 rm -f "$TEST_IMG.int"
36 trap "_cleanup; exit \$status" 0 1 2 3 15
38 # get standard environment, filters and checks
39 . ./common.rc
40 . ./common.filter
41 . ./common.qemu
43 # Any format implementing BlockDriver.bdrv_change_backing_file
44 _supported_fmt qcow2 qed
45 _supported_proto file
46 _supported_os Linux
48 IMG_SIZE=1M
50 # Create the images
51 TEST_IMG="$TEST_IMG.base" _make_test_img $IMG_SIZE | _filter_imgfmt
52 TEST_IMG="$TEST_IMG.int" _make_test_img -b "$TEST_IMG.base" | _filter_imgfmt
53 _make_test_img -b "$TEST_IMG.int" | _filter_imgfmt
55 # First test: reopen $TEST.IMG changing the detect-zeroes option on
56 # its backing file ($TEST_IMG.int).
57 echo
58 echo "*** Change an option on the backing file"
59 echo
60 _launch_qemu -drive if=none,file="${TEST_IMG}"
61 _send_qemu_cmd $QEMU_HANDLE \
62 "{ 'execute': 'qmp_capabilities' }" \
63 'return'
65 _send_qemu_cmd $QEMU_HANDLE \
66 "{ 'execute': 'human-monitor-command',
67 'arguments': { 'command-line':
68 'qemu-io none0 \"reopen -o backing.detect-zeroes=on\"' } }" \
69 "return"
71 _cleanup_qemu
73 # Second test: stream $TEST_IMG.base into $TEST_IMG.int and then
74 # reopen $TEST.IMG changing the detect-zeroes option on its new
75 # backing file ($TEST_IMG.base).
76 echo
77 echo "*** Stream and then change an option on the backing file"
78 echo
79 _launch_qemu -drive if=none,file="${TEST_IMG}"
80 _send_qemu_cmd $QEMU_HANDLE \
81 "{ 'execute': 'qmp_capabilities' }" \
82 'return'
84 _send_qemu_cmd $QEMU_HANDLE \
85 "{ 'execute': 'block-stream', \
86 'arguments': { 'device': 'none0',
87 'base': '${TEST_IMG}.base' } }" \
88 'return'
90 # Wait for block-stream to finish
91 sleep 0.5
93 _send_qemu_cmd $QEMU_HANDLE \
94 "{ 'execute': 'human-monitor-command',
95 'arguments': { 'command-line':
96 'qemu-io none0 \"reopen -o backing.detect-zeroes=on\"' } }" \
97 "return"
99 _cleanup_qemu
101 # Third test: commit $TEST_IMG.int into $TEST_IMG.base and then reopen
102 # $TEST.IMG changing the detect-zeroes option on its new backing file
103 # ($TEST_IMG.base).
104 echo
105 echo "*** Commit and then change an option on the backing file"
106 echo
107 # Create the images again
108 TEST_IMG="$TEST_IMG.base" _make_test_img $IMG_SIZE | _filter_imgfmt
109 TEST_IMG="$TEST_IMG.int" _make_test_img -b "$TEST_IMG.base" | _filter_imgfmt
110 _make_test_img -b "$TEST_IMG.int" | _filter_imgfmt
112 _launch_qemu -drive if=none,file="${TEST_IMG}"
113 _send_qemu_cmd $QEMU_HANDLE \
114 "{ 'execute': 'qmp_capabilities' }" \
115 'return'
117 _send_qemu_cmd $QEMU_HANDLE \
118 "{ 'execute': 'block-commit', \
119 'arguments': { 'device': 'none0',
120 'top': '${TEST_IMG}.int' } }" \
121 'return'
123 # Wait for block-commit to finish
124 sleep 0.5
126 _send_qemu_cmd $QEMU_HANDLE \
127 "{ 'execute': 'human-monitor-command',
128 'arguments': { 'command-line':
129 'qemu-io none0 \"reopen -o backing.detect-zeroes=on\"' } }" \
130 "return"
132 _cleanup_qemu
134 # success, all done
135 echo "*** done"
136 rm -f $seq.full
137 status=0