qemu

FORK: QEMU emulator
git clone https://git.neptards.moe/neptards/qemu.git
Log | Files | Refs | Submodules | LICENSE

246 (4178B)


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