vhost: Allow adjoining regions
[qemu/ar7.git] / tests / qemu-iotests / 169
blob153b10b6e75844f897621c3f11c8263020c1e875
1 #!/usr/bin/env python
3 # Tests for dirty bitmaps migration.
5 # Copyright (c) 2016-2017 Virtuozzo International GmbH. All rights reserved.
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 import os
22 import iotests
23 import time
24 import itertools
25 import operator
26 import new
27 from iotests import qemu_img
30 disk_a = os.path.join(iotests.test_dir, 'disk_a')
31 disk_b = os.path.join(iotests.test_dir, 'disk_b')
32 size = '1M'
33 mig_file = os.path.join(iotests.test_dir, 'mig_file')
36 class TestDirtyBitmapMigration(iotests.QMPTestCase):
37 def tearDown(self):
38 self.vm_a.shutdown()
39 self.vm_b.shutdown()
40 os.remove(disk_a)
41 os.remove(disk_b)
42 os.remove(mig_file)
44 def setUp(self):
45 qemu_img('create', '-f', iotests.imgfmt, disk_a, size)
46 qemu_img('create', '-f', iotests.imgfmt, disk_b, size)
48 self.vm_a = iotests.VM(path_suffix='a').add_drive(disk_a)
49 self.vm_a.launch()
51 self.vm_b = iotests.VM(path_suffix='b')
52 self.vm_b.add_incoming("exec: cat '" + mig_file + "'")
54 def add_bitmap(self, vm, granularity, persistent):
55 params = {'node': 'drive0',
56 'name': 'bitmap0',
57 'granularity': granularity}
58 if persistent:
59 params['persistent'] = True
60 params['autoload'] = True
62 result = vm.qmp('block-dirty-bitmap-add', **params)
63 self.assert_qmp(result, 'return', {});
65 def get_bitmap_hash(self, vm):
66 result = vm.qmp('x-debug-block-dirty-bitmap-sha256',
67 node='drive0', name='bitmap0')
68 return result['return']['sha256']
70 def check_bitmap(self, vm, sha256):
71 result = vm.qmp('x-debug-block-dirty-bitmap-sha256',
72 node='drive0', name='bitmap0')
73 if sha256:
74 self.assert_qmp(result, 'return/sha256', sha256);
75 else:
76 self.assert_qmp(result, 'error/desc',
77 "Dirty bitmap 'bitmap0' not found");
79 def do_test_migration(self, persistent, migrate_bitmaps, online,
80 shared_storage):
81 granularity = 512
83 # regions = ((start, count), ...)
84 regions = ((0, 0x10000),
85 (0xf0000, 0x10000),
86 (0xa0201, 0x1000))
88 should_migrate = migrate_bitmaps or persistent and shared_storage
90 self.vm_b.add_drive(disk_a if shared_storage else disk_b)
92 if online:
93 os.mkfifo(mig_file)
94 self.vm_b.launch()
96 self.add_bitmap(self.vm_a, granularity, persistent)
97 for r in regions:
98 self.vm_a.hmp_qemu_io('drive0', 'write %d %d' % r)
99 sha256 = self.get_bitmap_hash(self.vm_a)
101 if migrate_bitmaps:
102 capabilities = [{'capability': 'dirty-bitmaps', 'state': True}]
104 result = self.vm_a.qmp('migrate-set-capabilities',
105 capabilities=capabilities)
106 self.assert_qmp(result, 'return', {})
108 if online:
109 result = self.vm_b.qmp('migrate-set-capabilities',
110 capabilities=capabilities)
111 self.assert_qmp(result, 'return', {})
113 result = self.vm_a.qmp('migrate-set-capabilities',
114 capabilities=[{'capability': 'events',
115 'state': True}])
116 self.assert_qmp(result, 'return', {})
118 result = self.vm_a.qmp('migrate', uri='exec:cat>' + mig_file)
119 while True:
120 event = self.vm_a.event_wait('MIGRATION')
121 if event['data']['status'] == 'completed':
122 break
124 if not online:
125 self.vm_a.shutdown()
126 self.vm_b.launch()
127 # TODO enable bitmap capability for vm_b in this case
129 self.vm_b.event_wait("RESUME", timeout=10.0)
131 self.check_bitmap(self.vm_b, sha256 if should_migrate else False)
133 if should_migrate:
134 self.vm_b.shutdown()
135 self.vm_b.launch()
136 self.check_bitmap(self.vm_b, sha256 if persistent else False)
139 def inject_test_case(klass, name, method, *args, **kwargs):
140 mc = operator.methodcaller(method, *args, **kwargs)
141 setattr(klass, 'test_' + name, new.instancemethod(mc, None, klass))
143 for cmb in list(itertools.product((True, False), repeat=4)):
144 name = ('_' if cmb[0] else '_not_') + 'persistent_'
145 name += ('_' if cmb[1] else '_not_') + 'migbitmap_'
146 name += '_online' if cmb[2] else '_offline'
147 name += '_shared' if cmb[3] else '_nonshared'
149 inject_test_case(TestDirtyBitmapMigration, name, 'do_test_migration',
150 *list(cmb))
153 if __name__ == '__main__':
154 iotests.main(supported_fmts=['qcow2'])