3 # Tests for dirty bitmaps postcopy 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/>.
24 from iotests
import qemu_img
26 disk_a
= os
.path
.join(iotests
.test_dir
, 'disk_a')
27 disk_b
= os
.path
.join(iotests
.test_dir
, 'disk_b')
29 fifo
= os
.path
.join(iotests
.test_dir
, 'mig_fifo')
31 class TestDirtyBitmapPostcopyMigration(iotests
.QMPTestCase
):
42 qemu_img('create', '-f', iotests
.imgfmt
, disk_a
, size
)
43 qemu_img('create', '-f', iotests
.imgfmt
, disk_b
, size
)
44 self
.vm_a
= iotests
.VM(path_suffix
='a').add_drive(disk_a
)
45 self
.vm_b
= iotests
.VM(path_suffix
='b').add_drive(disk_b
)
46 self
.vm_b
.add_incoming("exec: cat '" + fifo
+ "'")
50 def test_postcopy(self
):
51 write_size
= 0x40000000
55 result
= self
.vm_a
.qmp('block-dirty-bitmap-add', node
='drive0',
56 name
='bitmap', granularity
=granularity
)
57 self
.assert_qmp(result
, 'return', {});
61 self
.vm_a
.hmp_qemu_io('drive0', 'write %d %d' % (s
, chunk
))
65 self
.vm_a
.hmp_qemu_io('drive0', 'write %d %d' % (s
, chunk
))
68 result
= self
.vm_a
.qmp('x-debug-block-dirty-bitmap-sha256',
69 node
='drive0', name
='bitmap')
70 sha256
= result
['return']['sha256']
72 result
= self
.vm_a
.qmp('block-dirty-bitmap-clear', node
='drive0',
74 self
.assert_qmp(result
, 'return', {});
77 self
.vm_a
.hmp_qemu_io('drive0', 'write %d %d' % (s
, chunk
))
80 bitmaps_cap
= {'capability': 'dirty-bitmaps', 'state': True}
81 events_cap
= {'capability': 'events', 'state': True}
83 result
= self
.vm_a
.qmp('migrate-set-capabilities',
84 capabilities
=[bitmaps_cap
, events_cap
])
85 self
.assert_qmp(result
, 'return', {})
87 result
= self
.vm_b
.qmp('migrate-set-capabilities',
88 capabilities
=[bitmaps_cap
])
89 self
.assert_qmp(result
, 'return', {})
91 result
= self
.vm_a
.qmp('migrate', uri
='exec:cat>' + fifo
)
92 self
.assert_qmp(result
, 'return', {})
94 result
= self
.vm_a
.qmp('migrate-start-postcopy')
95 self
.assert_qmp(result
, 'return', {})
98 event
= self
.vm_a
.event_wait('MIGRATION')
99 if event
['data']['status'] == 'completed':
103 while s
< write_size
:
104 self
.vm_b
.hmp_qemu_io('drive0', 'write %d %d' % (s
, chunk
))
107 result
= self
.vm_b
.qmp('query-block');
108 while len(result
['return'][0]['dirty-bitmaps']) > 1:
110 result
= self
.vm_b
.qmp('query-block');
112 result
= self
.vm_b
.qmp('x-debug-block-dirty-bitmap-sha256',
113 node
='drive0', name
='bitmap')
115 self
.assert_qmp(result
, 'return/sha256', sha256
);
117 if __name__
== '__main__':
118 iotests
.main(supported_fmts
=['qcow2'], supported_cache_modes
=['none'])