xref: /openbmc/qemu/tests/qemu-iotests/246 (revision a81df1b6)
1#!/usr/bin/env python3
2#
3# Test persistent bitmap resizing.
4#
5# Copyright (c) 2019 John Snow for Red Hat, Inc.
6#
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.
11#
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.
16#
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/>.
19#
20# owner=jsnow@redhat.com
21
22import iotests
23from iotests import log
24
25iotests.script_initialize(supported_fmts=['qcow2'])
26size = 64 * 1024 * 1024 * 1024
27gran_small = 32 * 1024
28gran_large = 128 * 1024
29
30def query_bitmaps(vm):
31    res = vm.qmp("query-block")
32    return { "bitmaps": { device['device']: device.get('dirty-bitmaps', []) for
33                          device in res['return'] } }
34
35with iotests.FilePath('img') as img_path, \
36     iotests.VM() as vm:
37
38    log('--- Preparing image & VM ---\n')
39    iotests.qemu_img_create('-f', iotests.imgfmt, img_path, str(size))
40    vm.add_drive(img_path)
41
42
43    log('--- 1st Boot (Establish Baseline Image) ---\n')
44    vm.launch()
45
46    log('\n--- Adding bitmaps Small, Medium, Large, and Transient ---\n')
47    vm.qmp_log("block-dirty-bitmap-add", node="drive0",
48               name="Small", granularity=gran_small, persistent=True)
49    vm.qmp_log("block-dirty-bitmap-add", node="drive0",
50               name="Medium", persistent=True)
51    vm.qmp_log("block-dirty-bitmap-add", node="drive0",
52               name="Large", granularity=gran_large, persistent=True)
53    vm.qmp_log("block-dirty-bitmap-add", node="drive0",
54               name="Transient", persistent=False)
55
56    log('--- Forcing flush of bitmaps to disk ---\n')
57    log(query_bitmaps(vm), indent=2)
58    vm.shutdown()
59
60
61    log('--- 2nd Boot (Grow Image) ---\n')
62    vm.launch()
63    log(query_bitmaps(vm), indent=2)
64
65    log('--- Adding new bitmap, growing image, and adding 2nd new bitmap ---')
66    vm.qmp_log("block-dirty-bitmap-add", node="drive0",
67               name="New", persistent=True)
68    vm.qmp_log("human-monitor-command",
69               command_line="block_resize drive0 70G")
70    vm.qmp_log("block-dirty-bitmap-add", node="drive0",
71               name="Newtwo", persistent=True)
72    log(query_bitmaps(vm), indent=2)
73
74    log('--- Forcing flush of bitmaps to disk ---\n')
75    vm.shutdown()
76
77
78    log('--- 3rd Boot (Shrink Image) ---\n')
79    vm.launch()
80    log(query_bitmaps(vm), indent=2)
81
82    log('--- Adding "NewB" bitmap, removing "New" bitmap ---')
83    vm.qmp_log("block-dirty-bitmap-add", node="drive0",
84               name="NewB", persistent=True)
85    vm.qmp_log("block-dirty-bitmap-remove", node="drive0",
86               name="New")
87
88    log('--- Truncating image ---\n')
89    vm.qmp_log("human-monitor-command",
90               command_line="block_resize drive0 50G")
91
92    log('--- Adding "NewC" bitmap, removing "NewTwo" bitmap ---')
93    vm.qmp_log("block-dirty-bitmap-add", node="drive0",
94               name="NewC", persistent=True)
95    vm.qmp_log("block-dirty-bitmap-remove", node="drive0", name="Newtwo")
96
97    log('--- Forcing flush of bitmaps to disk ---\n')
98    vm.shutdown()
99
100
101    log('--- 4th Boot (Verification and Cleanup) ---\n')
102    vm.launch()
103    log(query_bitmaps(vm), indent=2)
104
105    log('--- Removing all Bitmaps ---\n')
106    vm.qmp_log("block-dirty-bitmap-remove", node="drive0", name="Small")
107    vm.qmp_log("block-dirty-bitmap-remove", node="drive0", name="Medium")
108    vm.qmp_log("block-dirty-bitmap-remove", node="drive0", name="Large")
109    vm.qmp_log("block-dirty-bitmap-remove", node="drive0", name="NewB")
110    vm.qmp_log("block-dirty-bitmap-remove", node="drive0", name="NewC")
111    log(query_bitmaps(vm), indent=2)
112
113    log('\n--- Done ---')
114    vm.shutdown()
115