1*e2ec4119SJohn Snow#!/usr/bin/env python 2*e2ec4119SJohn Snow# 3*e2ec4119SJohn Snow# Test persistent bitmap resizing. 4*e2ec4119SJohn Snow# 5*e2ec4119SJohn Snow# Copyright (c) 2019 John Snow for Red Hat, Inc. 6*e2ec4119SJohn Snow# 7*e2ec4119SJohn Snow# This program is free software; you can redistribute it and/or modify 8*e2ec4119SJohn Snow# it under the terms of the GNU General Public License as published by 9*e2ec4119SJohn Snow# the Free Software Foundation; either version 2 of the License, or 10*e2ec4119SJohn Snow# (at your option) any later version. 11*e2ec4119SJohn Snow# 12*e2ec4119SJohn Snow# This program is distributed in the hope that it will be useful, 13*e2ec4119SJohn Snow# but WITHOUT ANY WARRANTY; without even the implied warranty of 14*e2ec4119SJohn Snow# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15*e2ec4119SJohn Snow# GNU General Public License for more details. 16*e2ec4119SJohn Snow# 17*e2ec4119SJohn Snow# You should have received a copy of the GNU General Public License 18*e2ec4119SJohn Snow# along with this program. If not, see <http://www.gnu.org/licenses/>. 19*e2ec4119SJohn Snow# 20*e2ec4119SJohn Snow# owner=jsnow@redhat.com 21*e2ec4119SJohn Snow 22*e2ec4119SJohn Snowimport iotests 23*e2ec4119SJohn Snowfrom iotests import log 24*e2ec4119SJohn Snow 25*e2ec4119SJohn Snowiotests.verify_image_format(supported_fmts=['qcow2']) 26*e2ec4119SJohn Snowsize = 64 * 1024 * 1024 * 1024 27*e2ec4119SJohn Snowgran_small = 32 * 1024 28*e2ec4119SJohn Snowgran_large = 128 * 1024 29*e2ec4119SJohn Snow 30*e2ec4119SJohn Snowdef query_bitmaps(vm): 31*e2ec4119SJohn Snow res = vm.qmp("query-block") 32*e2ec4119SJohn Snow return { "bitmaps": { device['device']: device.get('dirty-bitmaps', []) for 33*e2ec4119SJohn Snow device in res['return'] } } 34*e2ec4119SJohn Snow 35*e2ec4119SJohn Snowwith iotests.FilePath('img') as img_path, \ 36*e2ec4119SJohn Snow iotests.VM() as vm: 37*e2ec4119SJohn Snow 38*e2ec4119SJohn Snow log('--- Preparing image & VM ---\n') 39*e2ec4119SJohn Snow iotests.qemu_img_create('-f', iotests.imgfmt, img_path, str(size)) 40*e2ec4119SJohn Snow vm.add_drive(img_path) 41*e2ec4119SJohn Snow 42*e2ec4119SJohn Snow 43*e2ec4119SJohn Snow log('--- 1st Boot (Establish Baseline Image) ---\n') 44*e2ec4119SJohn Snow vm.launch() 45*e2ec4119SJohn Snow 46*e2ec4119SJohn Snow log('\n--- Adding bitmaps Small, Medium, Large, and Transient ---\n') 47*e2ec4119SJohn Snow vm.qmp_log("block-dirty-bitmap-add", node="drive0", 48*e2ec4119SJohn Snow name="Small", granularity=gran_small, persistent=True) 49*e2ec4119SJohn Snow vm.qmp_log("block-dirty-bitmap-add", node="drive0", 50*e2ec4119SJohn Snow name="Medium", persistent=True) 51*e2ec4119SJohn Snow vm.qmp_log("block-dirty-bitmap-add", node="drive0", 52*e2ec4119SJohn Snow name="Large", granularity=gran_large, persistent=True) 53*e2ec4119SJohn Snow vm.qmp_log("block-dirty-bitmap-add", node="drive0", 54*e2ec4119SJohn Snow name="Transient", persistent=False) 55*e2ec4119SJohn Snow 56*e2ec4119SJohn Snow log('--- Forcing flush of bitmaps to disk ---\n') 57*e2ec4119SJohn Snow log(query_bitmaps(vm), indent=2) 58*e2ec4119SJohn Snow vm.shutdown() 59*e2ec4119SJohn Snow 60*e2ec4119SJohn Snow 61*e2ec4119SJohn Snow log('--- 2nd Boot (Grow Image) ---\n') 62*e2ec4119SJohn Snow vm.launch() 63*e2ec4119SJohn Snow log(query_bitmaps(vm), indent=2) 64*e2ec4119SJohn Snow 65*e2ec4119SJohn Snow log('--- Adding new bitmap, growing image, and adding 2nd new bitmap ---') 66*e2ec4119SJohn Snow vm.qmp_log("block-dirty-bitmap-add", node="drive0", 67*e2ec4119SJohn Snow name="New", persistent=True) 68*e2ec4119SJohn Snow vm.qmp_log("human-monitor-command", 69*e2ec4119SJohn Snow command_line="block_resize drive0 70G") 70*e2ec4119SJohn Snow vm.qmp_log("block-dirty-bitmap-add", node="drive0", 71*e2ec4119SJohn Snow name="Newtwo", persistent=True) 72*e2ec4119SJohn Snow log(query_bitmaps(vm), indent=2) 73*e2ec4119SJohn Snow 74*e2ec4119SJohn Snow log('--- Forcing flush of bitmaps to disk ---\n') 75*e2ec4119SJohn Snow vm.shutdown() 76*e2ec4119SJohn Snow 77*e2ec4119SJohn Snow 78*e2ec4119SJohn Snow log('--- 3rd Boot (Shrink Image) ---\n') 79*e2ec4119SJohn Snow vm.launch() 80*e2ec4119SJohn Snow log(query_bitmaps(vm), indent=2) 81*e2ec4119SJohn Snow 82*e2ec4119SJohn Snow log('--- Adding "NewB" bitmap, removing "New" bitmap ---') 83*e2ec4119SJohn Snow vm.qmp_log("block-dirty-bitmap-add", node="drive0", 84*e2ec4119SJohn Snow name="NewB", persistent=True) 85*e2ec4119SJohn Snow vm.qmp_log("block-dirty-bitmap-remove", node="drive0", 86*e2ec4119SJohn Snow name="New") 87*e2ec4119SJohn Snow 88*e2ec4119SJohn Snow log('--- Truncating image ---\n') 89*e2ec4119SJohn Snow vm.qmp_log("human-monitor-command", 90*e2ec4119SJohn Snow command_line="block_resize drive0 50G") 91*e2ec4119SJohn Snow 92*e2ec4119SJohn Snow log('--- Adding "NewC" bitmap, removing "NewTwo" bitmap ---') 93*e2ec4119SJohn Snow vm.qmp_log("block-dirty-bitmap-add", node="drive0", 94*e2ec4119SJohn Snow name="NewC", persistent=True) 95*e2ec4119SJohn Snow vm.qmp_log("block-dirty-bitmap-remove", node="drive0", name="Newtwo") 96*e2ec4119SJohn Snow 97*e2ec4119SJohn Snow log('--- Forcing flush of bitmaps to disk ---\n') 98*e2ec4119SJohn Snow vm.shutdown() 99*e2ec4119SJohn Snow 100*e2ec4119SJohn Snow 101*e2ec4119SJohn Snow log('--- 4th Boot (Verification and Cleanup) ---\n') 102*e2ec4119SJohn Snow vm.launch() 103*e2ec4119SJohn Snow log(query_bitmaps(vm), indent=2) 104*e2ec4119SJohn Snow 105*e2ec4119SJohn Snow log('--- Removing all Bitmaps ---\n') 106*e2ec4119SJohn Snow vm.qmp_log("block-dirty-bitmap-remove", node="drive0", name="Small") 107*e2ec4119SJohn Snow vm.qmp_log("block-dirty-bitmap-remove", node="drive0", name="Medium") 108*e2ec4119SJohn Snow vm.qmp_log("block-dirty-bitmap-remove", node="drive0", name="Large") 109*e2ec4119SJohn Snow vm.qmp_log("block-dirty-bitmap-remove", node="drive0", name="NewB") 110*e2ec4119SJohn Snow vm.qmp_log("block-dirty-bitmap-remove", node="drive0", name="NewC") 111*e2ec4119SJohn Snow log(query_bitmaps(vm), indent=2) 112*e2ec4119SJohn Snow 113*e2ec4119SJohn Snow log('\n--- Done ---') 114*e2ec4119SJohn Snow vm.shutdown() 115