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 22030262a6SVladimir Sementsov-Ogievskiyfrom iotests import log, qemu_img_create, qemu_img, qemu_img_pipe 23030262a6SVladimir Sementsov-Ogievskiy 24030262a6SVladimir Sementsov-Ogievskiyiotests.script_initialize(supported_fmts=['qcow2']) 25030262a6SVladimir Sementsov-Ogievskiy 26030262a6SVladimir Sementsov-Ogievskiytop, base = iotests.file_path('top', 'base') 27030262a6SVladimir Sementsov-Ogievskiysize = '1M' 28030262a6SVladimir Sementsov-Ogievskiy 29030262a6SVladimir Sementsov-Ogievskiyassert qemu_img_create('-f', iotests.imgfmt, base, size) == 0 30030262a6SVladimir Sementsov-Ogievskiyassert qemu_img_create('-f', iotests.imgfmt, '-b', base, 31030262a6SVladimir Sementsov-Ogievskiy '-F', iotests.imgfmt, top, size) == 0 32030262a6SVladimir Sementsov-Ogievskiy 33030262a6SVladimir Sementsov-Ogievskiyassert qemu_img('bitmap', '--add', base, 'bitmap0') == 0 34030262a6SVladimir Sementsov-Ogievskiy# Just assert that our method of checking bitmaps in the image works. 35030262a6SVladimir Sementsov-Ogievskiyassert 'bitmaps' in qemu_img_pipe('info', base) 36030262a6SVladimir Sementsov-Ogievskiy 37030262a6SVladimir Sementsov-Ogievskiyvm = iotests.VM().add_drive(top, 'backing.node-name=base') 38030262a6SVladimir Sementsov-Ogievskiyvm.launch() 39030262a6SVladimir Sementsov-Ogievskiy 40030262a6SVladimir Sementsov-Ogievskiylog('Trying to remove persistent bitmap from r-o base node, should fail:') 41030262a6SVladimir Sementsov-Ogievskiyvm.qmp_log('block-dirty-bitmap-remove', node='base', name='bitmap0') 42030262a6SVladimir Sementsov-Ogievskiy 43030262a6SVladimir Sementsov-Ogievskiynew_base_opts = { 443908b7a8SAlberto Garcia 'options': [{ 45030262a6SVladimir Sementsov-Ogievskiy 'node-name': 'base', 46030262a6SVladimir Sementsov-Ogievskiy 'driver': 'qcow2', 47030262a6SVladimir Sementsov-Ogievskiy 'file': { 48030262a6SVladimir Sementsov-Ogievskiy 'driver': 'file', 49030262a6SVladimir Sementsov-Ogievskiy 'filename': base 50030262a6SVladimir Sementsov-Ogievskiy }, 51030262a6SVladimir Sementsov-Ogievskiy 'read-only': False 523908b7a8SAlberto Garcia }] 53030262a6SVladimir Sementsov-Ogievskiy} 54030262a6SVladimir Sementsov-Ogievskiy 55030262a6SVladimir Sementsov-Ogievskiy# Don't want to bother with filtering qmp_log for reopen command 56*e60edf69SAlberto Garciaresult = vm.qmp('blockdev-reopen', **new_base_opts) 57030262a6SVladimir Sementsov-Ogievskiyif result != {'return': {}}: 58030262a6SVladimir Sementsov-Ogievskiy log('Failed to reopen: ' + str(result)) 59030262a6SVladimir Sementsov-Ogievskiy 60030262a6SVladimir Sementsov-Ogievskiylog('Remove persistent bitmap from base node reopened to RW:') 61030262a6SVladimir Sementsov-Ogievskiyvm.qmp_log('block-dirty-bitmap-remove', node='base', name='bitmap0') 62030262a6SVladimir Sementsov-Ogievskiy 633908b7a8SAlberto Garcianew_base_opts['options'][0]['read-only'] = True 64*e60edf69SAlberto Garciaresult = vm.qmp('blockdev-reopen', **new_base_opts) 65030262a6SVladimir Sementsov-Ogievskiyif result != {'return': {}}: 66030262a6SVladimir Sementsov-Ogievskiy log('Failed to reopen: ' + str(result)) 67030262a6SVladimir Sementsov-Ogievskiy 68030262a6SVladimir Sementsov-Ogievskiyvm.shutdown() 69030262a6SVladimir Sementsov-Ogievskiy 70030262a6SVladimir Sementsov-Ogievskiyif 'bitmaps' in qemu_img_pipe('info', base): 71030262a6SVladimir Sementsov-Ogievskiy log('ERROR: Bitmap is still in the base image') 72