17c477526SPhilippe Mathieu-Daudé#!/usr/bin/env python3 29dd003a9SVladimir 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 26*b30b8077SVladimir Sementsov-Ogievskiyiotests.script_initialize(supported_fmts=['qcow2'], 27*b30b8077SVladimir Sementsov-Ogievskiy unsupported_imgopts=['compat']) 28e2ec4119SJohn Snowsize = 64 * 1024 * 1024 * 1024 29e2ec4119SJohn Snowgran_small = 32 * 1024 30e2ec4119SJohn Snowgran_large = 128 * 1024 31e2ec4119SJohn Snow 32e2ec4119SJohn Snowdef query_bitmaps(vm): 33e2ec4119SJohn Snow res = vm.qmp("query-block") 34e67d8e29SDaniel P. Berrangé return { "bitmaps": { device['device']: device.get('inserted', {}) 35e67d8e29SDaniel P. Berrangé .get('dirty-bitmaps', []) for 36e2ec4119SJohn Snow device in res['return'] } } 37e2ec4119SJohn Snow 38e2ec4119SJohn Snowwith iotests.FilePath('img') as img_path, \ 39e2ec4119SJohn Snow iotests.VM() as vm: 40e2ec4119SJohn Snow 41e2ec4119SJohn Snow log('--- Preparing image & VM ---\n') 42e2ec4119SJohn Snow iotests.qemu_img_create('-f', iotests.imgfmt, img_path, str(size)) 43e2ec4119SJohn Snow vm.add_drive(img_path) 44e2ec4119SJohn Snow 45e2ec4119SJohn Snow 46e2ec4119SJohn Snow log('--- 1st Boot (Establish Baseline Image) ---\n') 47e2ec4119SJohn Snow vm.launch() 48e2ec4119SJohn Snow 49e2ec4119SJohn Snow log('\n--- Adding bitmaps Small, Medium, Large, and Transient ---\n') 50e2ec4119SJohn Snow vm.qmp_log("block-dirty-bitmap-add", node="drive0", 51e2ec4119SJohn Snow name="Small", granularity=gran_small, persistent=True) 52e2ec4119SJohn Snow vm.qmp_log("block-dirty-bitmap-add", node="drive0", 53e2ec4119SJohn Snow name="Medium", persistent=True) 54e2ec4119SJohn Snow vm.qmp_log("block-dirty-bitmap-add", node="drive0", 55e2ec4119SJohn Snow name="Large", granularity=gran_large, persistent=True) 56e2ec4119SJohn Snow vm.qmp_log("block-dirty-bitmap-add", node="drive0", 57e2ec4119SJohn Snow name="Transient", persistent=False) 58e2ec4119SJohn Snow 59e2ec4119SJohn Snow log('--- Forcing flush of bitmaps to disk ---\n') 60e2ec4119SJohn Snow log(query_bitmaps(vm), indent=2) 61e2ec4119SJohn Snow vm.shutdown() 62e2ec4119SJohn Snow 63e2ec4119SJohn Snow 64e2ec4119SJohn Snow log('--- 2nd Boot (Grow Image) ---\n') 65e2ec4119SJohn Snow vm.launch() 66e2ec4119SJohn Snow log(query_bitmaps(vm), indent=2) 67e2ec4119SJohn Snow 68e2ec4119SJohn Snow log('--- Adding new bitmap, growing image, and adding 2nd new bitmap ---') 69e2ec4119SJohn Snow vm.qmp_log("block-dirty-bitmap-add", node="drive0", 70e2ec4119SJohn Snow name="New", persistent=True) 71e2ec4119SJohn Snow vm.qmp_log("human-monitor-command", 72e2ec4119SJohn Snow command_line="block_resize drive0 70G") 73e2ec4119SJohn Snow vm.qmp_log("block-dirty-bitmap-add", node="drive0", 74e2ec4119SJohn Snow name="Newtwo", persistent=True) 75e2ec4119SJohn Snow log(query_bitmaps(vm), indent=2) 76e2ec4119SJohn Snow 77e2ec4119SJohn Snow log('--- Forcing flush of bitmaps to disk ---\n') 78e2ec4119SJohn Snow vm.shutdown() 79e2ec4119SJohn Snow 80e2ec4119SJohn Snow 81e2ec4119SJohn Snow log('--- 3rd Boot (Shrink Image) ---\n') 82e2ec4119SJohn Snow vm.launch() 83e2ec4119SJohn Snow log(query_bitmaps(vm), indent=2) 84e2ec4119SJohn Snow 85e2ec4119SJohn Snow log('--- Adding "NewB" bitmap, removing "New" bitmap ---') 86e2ec4119SJohn Snow vm.qmp_log("block-dirty-bitmap-add", node="drive0", 87e2ec4119SJohn Snow name="NewB", persistent=True) 88e2ec4119SJohn Snow vm.qmp_log("block-dirty-bitmap-remove", node="drive0", 89e2ec4119SJohn Snow name="New") 90e2ec4119SJohn Snow 91e2ec4119SJohn Snow log('--- Truncating image ---\n') 92e2ec4119SJohn Snow vm.qmp_log("human-monitor-command", 93e2ec4119SJohn Snow command_line="block_resize drive0 50G") 94e2ec4119SJohn Snow 95e2ec4119SJohn Snow log('--- Adding "NewC" bitmap, removing "NewTwo" bitmap ---') 96e2ec4119SJohn Snow vm.qmp_log("block-dirty-bitmap-add", node="drive0", 97e2ec4119SJohn Snow name="NewC", persistent=True) 98e2ec4119SJohn Snow vm.qmp_log("block-dirty-bitmap-remove", node="drive0", name="Newtwo") 99e2ec4119SJohn Snow 100e2ec4119SJohn Snow log('--- Forcing flush of bitmaps to disk ---\n') 101e2ec4119SJohn Snow vm.shutdown() 102e2ec4119SJohn Snow 103e2ec4119SJohn Snow 104e2ec4119SJohn Snow log('--- 4th Boot (Verification and Cleanup) ---\n') 105e2ec4119SJohn Snow vm.launch() 106e2ec4119SJohn Snow log(query_bitmaps(vm), indent=2) 107e2ec4119SJohn Snow 108e2ec4119SJohn Snow log('--- Removing all Bitmaps ---\n') 109e2ec4119SJohn Snow vm.qmp_log("block-dirty-bitmap-remove", node="drive0", name="Small") 110e2ec4119SJohn Snow vm.qmp_log("block-dirty-bitmap-remove", node="drive0", name="Medium") 111e2ec4119SJohn Snow vm.qmp_log("block-dirty-bitmap-remove", node="drive0", name="Large") 112e2ec4119SJohn Snow vm.qmp_log("block-dirty-bitmap-remove", node="drive0", name="NewB") 113e2ec4119SJohn Snow vm.qmp_log("block-dirty-bitmap-remove", node="drive0", name="NewC") 114e2ec4119SJohn Snow log(query_bitmaps(vm), indent=2) 115e2ec4119SJohn Snow 116e2ec4119SJohn Snow log('\n--- Done ---') 117e2ec4119SJohn Snow vm.shutdown() 118