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