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