xref: /openbmc/qemu/tests/qemu-iotests/246 (revision 7c4775260807f1428484a5cebc7bc360c46a872d)
1*7c477526SPhilippe Mathieu-Daudé#!/usr/bin/env python3
2e2ec4119SJohn Snow#
3e2ec4119SJohn Snow# Test persistent bitmap resizing.
4e2ec4119SJohn Snow#
5e2ec4119SJohn Snow# Copyright (c) 2019 John Snow for Red Hat, Inc.
6e2ec4119SJohn Snow#
7e2ec4119SJohn Snow# This program is free software; you can redistribute it and/or modify
8e2ec4119SJohn Snow# it under the terms of the GNU General Public License as published by
9e2ec4119SJohn Snow# the Free Software Foundation; either version 2 of the License, or
10e2ec4119SJohn Snow# (at your option) any later version.
11e2ec4119SJohn Snow#
12e2ec4119SJohn Snow# This program is distributed in the hope that it will be useful,
13e2ec4119SJohn Snow# but WITHOUT ANY WARRANTY; without even the implied warranty of
14e2ec4119SJohn Snow# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15e2ec4119SJohn Snow# GNU General Public License for more details.
16e2ec4119SJohn Snow#
17e2ec4119SJohn Snow# You should have received a copy of the GNU General Public License
18e2ec4119SJohn Snow# along with this program.  If not, see <http://www.gnu.org/licenses/>.
19e2ec4119SJohn Snow#
20e2ec4119SJohn Snow# owner=jsnow@redhat.com
21e2ec4119SJohn Snow
22e2ec4119SJohn Snowimport iotests
23e2ec4119SJohn Snowfrom iotests import log
24e2ec4119SJohn Snow
25e2ec4119SJohn Snowiotests.verify_image_format(supported_fmts=['qcow2'])
26e2ec4119SJohn Snowsize = 64 * 1024 * 1024 * 1024
27e2ec4119SJohn Snowgran_small = 32 * 1024
28e2ec4119SJohn Snowgran_large = 128 * 1024
29e2ec4119SJohn Snow
30e2ec4119SJohn Snowdef query_bitmaps(vm):
31e2ec4119SJohn Snow    res = vm.qmp("query-block")
32e2ec4119SJohn Snow    return { "bitmaps": { device['device']: device.get('dirty-bitmaps', []) for
33e2ec4119SJohn Snow                          device in res['return'] } }
34e2ec4119SJohn Snow
35e2ec4119SJohn Snowwith iotests.FilePath('img') as img_path, \
36e2ec4119SJohn Snow     iotests.VM() as vm:
37e2ec4119SJohn Snow
38e2ec4119SJohn Snow    log('--- Preparing image & VM ---\n')
39e2ec4119SJohn Snow    iotests.qemu_img_create('-f', iotests.imgfmt, img_path, str(size))
40e2ec4119SJohn Snow    vm.add_drive(img_path)
41e2ec4119SJohn Snow
42e2ec4119SJohn Snow
43e2ec4119SJohn Snow    log('--- 1st Boot (Establish Baseline Image) ---\n')
44e2ec4119SJohn Snow    vm.launch()
45e2ec4119SJohn Snow
46e2ec4119SJohn Snow    log('\n--- Adding bitmaps Small, Medium, Large, and Transient ---\n')
47e2ec4119SJohn Snow    vm.qmp_log("block-dirty-bitmap-add", node="drive0",
48e2ec4119SJohn Snow               name="Small", granularity=gran_small, persistent=True)
49e2ec4119SJohn Snow    vm.qmp_log("block-dirty-bitmap-add", node="drive0",
50e2ec4119SJohn Snow               name="Medium", persistent=True)
51e2ec4119SJohn Snow    vm.qmp_log("block-dirty-bitmap-add", node="drive0",
52e2ec4119SJohn Snow               name="Large", granularity=gran_large, persistent=True)
53e2ec4119SJohn Snow    vm.qmp_log("block-dirty-bitmap-add", node="drive0",
54e2ec4119SJohn Snow               name="Transient", persistent=False)
55e2ec4119SJohn Snow
56e2ec4119SJohn Snow    log('--- Forcing flush of bitmaps to disk ---\n')
57e2ec4119SJohn Snow    log(query_bitmaps(vm), indent=2)
58e2ec4119SJohn Snow    vm.shutdown()
59e2ec4119SJohn Snow
60e2ec4119SJohn Snow
61e2ec4119SJohn Snow    log('--- 2nd Boot (Grow Image) ---\n')
62e2ec4119SJohn Snow    vm.launch()
63e2ec4119SJohn Snow    log(query_bitmaps(vm), indent=2)
64e2ec4119SJohn Snow
65e2ec4119SJohn Snow    log('--- Adding new bitmap, growing image, and adding 2nd new bitmap ---')
66e2ec4119SJohn Snow    vm.qmp_log("block-dirty-bitmap-add", node="drive0",
67e2ec4119SJohn Snow               name="New", persistent=True)
68e2ec4119SJohn Snow    vm.qmp_log("human-monitor-command",
69e2ec4119SJohn Snow               command_line="block_resize drive0 70G")
70e2ec4119SJohn Snow    vm.qmp_log("block-dirty-bitmap-add", node="drive0",
71e2ec4119SJohn Snow               name="Newtwo", persistent=True)
72e2ec4119SJohn Snow    log(query_bitmaps(vm), indent=2)
73e2ec4119SJohn Snow
74e2ec4119SJohn Snow    log('--- Forcing flush of bitmaps to disk ---\n')
75e2ec4119SJohn Snow    vm.shutdown()
76e2ec4119SJohn Snow
77e2ec4119SJohn Snow
78e2ec4119SJohn Snow    log('--- 3rd Boot (Shrink Image) ---\n')
79e2ec4119SJohn Snow    vm.launch()
80e2ec4119SJohn Snow    log(query_bitmaps(vm), indent=2)
81e2ec4119SJohn Snow
82e2ec4119SJohn Snow    log('--- Adding "NewB" bitmap, removing "New" bitmap ---')
83e2ec4119SJohn Snow    vm.qmp_log("block-dirty-bitmap-add", node="drive0",
84e2ec4119SJohn Snow               name="NewB", persistent=True)
85e2ec4119SJohn Snow    vm.qmp_log("block-dirty-bitmap-remove", node="drive0",
86e2ec4119SJohn Snow               name="New")
87e2ec4119SJohn Snow
88e2ec4119SJohn Snow    log('--- Truncating image ---\n')
89e2ec4119SJohn Snow    vm.qmp_log("human-monitor-command",
90e2ec4119SJohn Snow               command_line="block_resize drive0 50G")
91e2ec4119SJohn Snow
92e2ec4119SJohn Snow    log('--- Adding "NewC" bitmap, removing "NewTwo" bitmap ---')
93e2ec4119SJohn Snow    vm.qmp_log("block-dirty-bitmap-add", node="drive0",
94e2ec4119SJohn Snow               name="NewC", persistent=True)
95e2ec4119SJohn Snow    vm.qmp_log("block-dirty-bitmap-remove", node="drive0", name="Newtwo")
96e2ec4119SJohn Snow
97e2ec4119SJohn Snow    log('--- Forcing flush of bitmaps to disk ---\n')
98e2ec4119SJohn Snow    vm.shutdown()
99e2ec4119SJohn Snow
100e2ec4119SJohn Snow
101e2ec4119SJohn Snow    log('--- 4th Boot (Verification and Cleanup) ---\n')
102e2ec4119SJohn Snow    vm.launch()
103e2ec4119SJohn Snow    log(query_bitmaps(vm), indent=2)
104e2ec4119SJohn Snow
105e2ec4119SJohn Snow    log('--- Removing all Bitmaps ---\n')
106e2ec4119SJohn Snow    vm.qmp_log("block-dirty-bitmap-remove", node="drive0", name="Small")
107e2ec4119SJohn Snow    vm.qmp_log("block-dirty-bitmap-remove", node="drive0", name="Medium")
108e2ec4119SJohn Snow    vm.qmp_log("block-dirty-bitmap-remove", node="drive0", name="Large")
109e2ec4119SJohn Snow    vm.qmp_log("block-dirty-bitmap-remove", node="drive0", name="NewB")
110e2ec4119SJohn Snow    vm.qmp_log("block-dirty-bitmap-remove", node="drive0", name="NewC")
111e2ec4119SJohn Snow    log(query_bitmaps(vm), indent=2)
112e2ec4119SJohn Snow
113e2ec4119SJohn Snow    log('\n--- Done ---')
114e2ec4119SJohn Snow    vm.shutdown()
115