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