1030262a6SVladimir Sementsov-Ogievskiy#!/usr/bin/env python3 2030262a6SVladimir Sementsov-Ogievskiy# 3030262a6SVladimir Sementsov-Ogievskiy# Test removing persistent bitmap from backing 4030262a6SVladimir Sementsov-Ogievskiy# 5030262a6SVladimir Sementsov-Ogievskiy# Copyright (c) 2021 Virtuozzo International GmbH. 6030262a6SVladimir Sementsov-Ogievskiy# 7030262a6SVladimir Sementsov-Ogievskiy# This program is free software; you can redistribute it and/or modify 8030262a6SVladimir Sementsov-Ogievskiy# it under the terms of the GNU General Public License as published by 9030262a6SVladimir Sementsov-Ogievskiy# the Free Software Foundation; either version 2 of the License, or 10030262a6SVladimir Sementsov-Ogievskiy# (at your option) any later version. 11030262a6SVladimir Sementsov-Ogievskiy# 12030262a6SVladimir Sementsov-Ogievskiy# This program is distributed in the hope that it will be useful, 13030262a6SVladimir Sementsov-Ogievskiy# but WITHOUT ANY WARRANTY; without even the implied warranty of 14030262a6SVladimir Sementsov-Ogievskiy# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15030262a6SVladimir Sementsov-Ogievskiy# GNU General Public License for more details. 16030262a6SVladimir Sementsov-Ogievskiy# 17030262a6SVladimir Sementsov-Ogievskiy# You should have received a copy of the GNU General Public License 18030262a6SVladimir Sementsov-Ogievskiy# along with this program. If not, see <http://www.gnu.org/licenses/>. 19030262a6SVladimir Sementsov-Ogievskiy# 20030262a6SVladimir Sementsov-Ogievskiy 21030262a6SVladimir Sementsov-Ogievskiyimport iotests 22*ac5bb486SJohn Snowfrom iotests import log, qemu_img_create, qemu_img, qemu_img_info 23030262a6SVladimir Sementsov-Ogievskiy 24b30b8077SVladimir Sementsov-Ogievskiyiotests.script_initialize(supported_fmts=['qcow2'], 25b30b8077SVladimir Sementsov-Ogievskiy unsupported_imgopts=['compat']) 26030262a6SVladimir Sementsov-Ogievskiy 27030262a6SVladimir Sementsov-Ogievskiytop, base = iotests.file_path('top', 'base') 28030262a6SVladimir Sementsov-Ogievskiysize = '1M' 29030262a6SVladimir Sementsov-Ogievskiy 30fc272d3cSJohn Snowqemu_img_create('-f', iotests.imgfmt, base, size) 31fc272d3cSJohn Snowqemu_img_create('-f', iotests.imgfmt, '-b', base, 32fc272d3cSJohn Snow '-F', iotests.imgfmt, top, size) 33030262a6SVladimir Sementsov-Ogievskiy 34fc272d3cSJohn Snowqemu_img('bitmap', '--add', base, 'bitmap0') 35030262a6SVladimir Sementsov-Ogievskiy# Just assert that our method of checking bitmaps in the image works. 36*ac5bb486SJohn Snowassert 'bitmaps' in qemu_img_info(base)['format-specific']['data'] 37030262a6SVladimir Sementsov-Ogievskiy 38030262a6SVladimir Sementsov-Ogievskiyvm = iotests.VM().add_drive(top, 'backing.node-name=base') 39030262a6SVladimir Sementsov-Ogievskiyvm.launch() 40030262a6SVladimir Sementsov-Ogievskiy 41030262a6SVladimir Sementsov-Ogievskiylog('Trying to remove persistent bitmap from r-o base node, should fail:') 42030262a6SVladimir Sementsov-Ogievskiyvm.qmp_log('block-dirty-bitmap-remove', node='base', name='bitmap0') 43030262a6SVladimir Sementsov-Ogievskiy 44030262a6SVladimir Sementsov-Ogievskiynew_base_opts = { 453908b7a8SAlberto Garcia 'options': [{ 46030262a6SVladimir Sementsov-Ogievskiy 'node-name': 'base', 47030262a6SVladimir Sementsov-Ogievskiy 'driver': 'qcow2', 48030262a6SVladimir Sementsov-Ogievskiy 'file': { 49030262a6SVladimir Sementsov-Ogievskiy 'driver': 'file', 50030262a6SVladimir Sementsov-Ogievskiy 'filename': base 51030262a6SVladimir Sementsov-Ogievskiy }, 52030262a6SVladimir Sementsov-Ogievskiy 'read-only': False 533908b7a8SAlberto Garcia }] 54030262a6SVladimir Sementsov-Ogievskiy} 55030262a6SVladimir Sementsov-Ogievskiy 56030262a6SVladimir Sementsov-Ogievskiy# Don't want to bother with filtering qmp_log for reopen command 57e60edf69SAlberto Garciaresult = vm.qmp('blockdev-reopen', **new_base_opts) 58030262a6SVladimir Sementsov-Ogievskiyif result != {'return': {}}: 59030262a6SVladimir Sementsov-Ogievskiy log('Failed to reopen: ' + str(result)) 60030262a6SVladimir Sementsov-Ogievskiy 61030262a6SVladimir Sementsov-Ogievskiylog('Remove persistent bitmap from base node reopened to RW:') 62030262a6SVladimir Sementsov-Ogievskiyvm.qmp_log('block-dirty-bitmap-remove', node='base', name='bitmap0') 63030262a6SVladimir Sementsov-Ogievskiy 643908b7a8SAlberto Garcianew_base_opts['options'][0]['read-only'] = True 65e60edf69SAlberto Garciaresult = vm.qmp('blockdev-reopen', **new_base_opts) 66030262a6SVladimir Sementsov-Ogievskiyif result != {'return': {}}: 67030262a6SVladimir Sementsov-Ogievskiy log('Failed to reopen: ' + str(result)) 68030262a6SVladimir Sementsov-Ogievskiy 69030262a6SVladimir Sementsov-Ogievskiyvm.shutdown() 70030262a6SVladimir Sementsov-Ogievskiy 71*ac5bb486SJohn Snowif 'bitmaps' in qemu_img_info(base)['format-specific']['data']: 72030262a6SVladimir Sementsov-Ogievskiy log('ERROR: Bitmap is still in the base image') 73