3 # Tests for persistent dirty bitmaps.
5 # Copyright: Vladimir Sementsov-Ogievskiy 2015-2017
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
= os
.path
.join(iotests
.test_dir
, 'disk')
27 disk_size
= 0x40000000 # 1G
29 # regions for qemu_io: (start, count) in bytes
30 regions1
= ((0x0fff00, 0x10000),
33 regions2
= ((0x10000000, 0x20000),
34 (0x3fff0000, 0x10000))
36 class TestPersistentDirtyBitmap(iotests
.QMPTestCase
):
39 qemu_img('create', '-f', iotests
.imgfmt
, disk
, str(disk_size
))
45 return iotests
.VM().add_drive(disk
)
48 return iotests
.VM().add_drive(disk
, opts
='readonly=on')
51 result
= self
.vm
.qmp('x-debug-block-dirty-bitmap-sha256',
52 node
='drive0', name
='bitmap0')
53 return result
['return']['sha256']
55 def checkBitmap(self
, sha256
):
56 result
= self
.vm
.qmp('x-debug-block-dirty-bitmap-sha256',
57 node
='drive0', name
='bitmap0')
58 self
.assert_qmp(result
, 'return/sha256', sha256
);
60 def writeRegions(self
, regions
):
62 self
.vm
.hmp_qemu_io('drive0',
65 def qmpAddBitmap(self
):
66 self
.vm
.qmp('block-dirty-bitmap-add', node
='drive0',
67 name
='bitmap0', persistent
=True)
69 def test_persistent(self
):
74 self
.writeRegions(regions1
)
75 sha256
= self
.getSha256()
79 self
.vm
= self
.mkVmRo()
83 #catch 'Persistent bitmaps are lost' possible error
84 log
= self
.vm
.get_log()
85 log
= re
.sub(r
'^\[I \d+\.\d+\] OPENED\n', '', log
)
86 log
= re
.sub(r
'\[I \+\d+\.\d+\] CLOSED\n?$', '', log
)
93 self
.checkBitmap(sha256
)
94 self
.writeRegions(regions2
)
95 sha256
= self
.getSha256()
100 self
.checkBitmap(sha256
)
104 if __name__
== '__main__':
105 iotests
.main(supported_fmts
=['qcow2'])