1*030262a6SVladimir Sementsov-Ogievskiy#!/usr/bin/env python3 2*030262a6SVladimir Sementsov-Ogievskiy# 3*030262a6SVladimir Sementsov-Ogievskiy# Test removing persistent bitmap from backing 4*030262a6SVladimir Sementsov-Ogievskiy# 5*030262a6SVladimir Sementsov-Ogievskiy# Copyright (c) 2021 Virtuozzo International GmbH. 6*030262a6SVladimir Sementsov-Ogievskiy# 7*030262a6SVladimir Sementsov-Ogievskiy# This program is free software; you can redistribute it and/or modify 8*030262a6SVladimir Sementsov-Ogievskiy# it under the terms of the GNU General Public License as published by 9*030262a6SVladimir Sementsov-Ogievskiy# the Free Software Foundation; either version 2 of the License, or 10*030262a6SVladimir Sementsov-Ogievskiy# (at your option) any later version. 11*030262a6SVladimir Sementsov-Ogievskiy# 12*030262a6SVladimir Sementsov-Ogievskiy# This program is distributed in the hope that it will be useful, 13*030262a6SVladimir Sementsov-Ogievskiy# but WITHOUT ANY WARRANTY; without even the implied warranty of 14*030262a6SVladimir Sementsov-Ogievskiy# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15*030262a6SVladimir Sementsov-Ogievskiy# GNU General Public License for more details. 16*030262a6SVladimir Sementsov-Ogievskiy# 17*030262a6SVladimir Sementsov-Ogievskiy# You should have received a copy of the GNU General Public License 18*030262a6SVladimir Sementsov-Ogievskiy# along with this program. If not, see <http://www.gnu.org/licenses/>. 19*030262a6SVladimir Sementsov-Ogievskiy# 20*030262a6SVladimir Sementsov-Ogievskiy 21*030262a6SVladimir Sementsov-Ogievskiyimport iotests 22*030262a6SVladimir Sementsov-Ogievskiyfrom iotests import log, qemu_img_create, qemu_img, qemu_img_pipe 23*030262a6SVladimir Sementsov-Ogievskiy 24*030262a6SVladimir Sementsov-Ogievskiyiotests.script_initialize(supported_fmts=['qcow2']) 25*030262a6SVladimir Sementsov-Ogievskiy 26*030262a6SVladimir Sementsov-Ogievskiytop, base = iotests.file_path('top', 'base') 27*030262a6SVladimir Sementsov-Ogievskiysize = '1M' 28*030262a6SVladimir Sementsov-Ogievskiy 29*030262a6SVladimir Sementsov-Ogievskiyassert qemu_img_create('-f', iotests.imgfmt, base, size) == 0 30*030262a6SVladimir Sementsov-Ogievskiyassert qemu_img_create('-f', iotests.imgfmt, '-b', base, 31*030262a6SVladimir Sementsov-Ogievskiy '-F', iotests.imgfmt, top, size) == 0 32*030262a6SVladimir Sementsov-Ogievskiy 33*030262a6SVladimir Sementsov-Ogievskiyassert qemu_img('bitmap', '--add', base, 'bitmap0') == 0 34*030262a6SVladimir Sementsov-Ogievskiy# Just assert that our method of checking bitmaps in the image works. 35*030262a6SVladimir Sementsov-Ogievskiyassert 'bitmaps' in qemu_img_pipe('info', base) 36*030262a6SVladimir Sementsov-Ogievskiy 37*030262a6SVladimir Sementsov-Ogievskiyvm = iotests.VM().add_drive(top, 'backing.node-name=base') 38*030262a6SVladimir Sementsov-Ogievskiyvm.launch() 39*030262a6SVladimir Sementsov-Ogievskiy 40*030262a6SVladimir Sementsov-Ogievskiylog('Trying to remove persistent bitmap from r-o base node, should fail:') 41*030262a6SVladimir Sementsov-Ogievskiyvm.qmp_log('block-dirty-bitmap-remove', node='base', name='bitmap0') 42*030262a6SVladimir Sementsov-Ogievskiy 43*030262a6SVladimir Sementsov-Ogievskiynew_base_opts = { 44*030262a6SVladimir Sementsov-Ogievskiy 'node-name': 'base', 45*030262a6SVladimir Sementsov-Ogievskiy 'driver': 'qcow2', 46*030262a6SVladimir Sementsov-Ogievskiy 'file': { 47*030262a6SVladimir Sementsov-Ogievskiy 'driver': 'file', 48*030262a6SVladimir Sementsov-Ogievskiy 'filename': base 49*030262a6SVladimir Sementsov-Ogievskiy }, 50*030262a6SVladimir Sementsov-Ogievskiy 'read-only': False 51*030262a6SVladimir Sementsov-Ogievskiy} 52*030262a6SVladimir Sementsov-Ogievskiy 53*030262a6SVladimir Sementsov-Ogievskiy# Don't want to bother with filtering qmp_log for reopen command 54*030262a6SVladimir Sementsov-Ogievskiyresult = vm.qmp('x-blockdev-reopen', **new_base_opts) 55*030262a6SVladimir Sementsov-Ogievskiyif result != {'return': {}}: 56*030262a6SVladimir Sementsov-Ogievskiy log('Failed to reopen: ' + str(result)) 57*030262a6SVladimir Sementsov-Ogievskiy 58*030262a6SVladimir Sementsov-Ogievskiylog('Remove persistent bitmap from base node reopened to RW:') 59*030262a6SVladimir Sementsov-Ogievskiyvm.qmp_log('block-dirty-bitmap-remove', node='base', name='bitmap0') 60*030262a6SVladimir Sementsov-Ogievskiy 61*030262a6SVladimir Sementsov-Ogievskiynew_base_opts['read-only'] = True 62*030262a6SVladimir Sementsov-Ogievskiyresult = vm.qmp('x-blockdev-reopen', **new_base_opts) 63*030262a6SVladimir Sementsov-Ogievskiyif result != {'return': {}}: 64*030262a6SVladimir Sementsov-Ogievskiy log('Failed to reopen: ' + str(result)) 65*030262a6SVladimir Sementsov-Ogievskiy 66*030262a6SVladimir Sementsov-Ogievskiyvm.shutdown() 67*030262a6SVladimir Sementsov-Ogievskiy 68*030262a6SVladimir Sementsov-Ogievskiyif 'bitmaps' in qemu_img_pipe('info', base): 69*030262a6SVladimir Sementsov-Ogievskiy log('ERROR: Bitmap is still in the base image') 70