qemu

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

304 (1820B)


      1 #!/usr/bin/env python3
      2 # group: rw quick
      3 #
      4 # Tests dirty-bitmap backup with unaligned bitmap granularity
      5 #
      6 # Copyright (c) 2020 Proxmox Server Solutions
      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=s.reiter@proxmox.com
     22 
     23 import iotests
     24 from iotests import qemu_img_create, qemu_img_log, file_path
     25 
     26 iotests.script_initialize(supported_fmts=['qcow2'],
     27                           supported_protocols=['file'])
     28 
     29 test_img = file_path('test.qcow2')
     30 target_img = file_path('target.qcow2')
     31 
     32 # unaligned by one byte
     33 image_len = 4097
     34 bitmap_granularity = 4096
     35 
     36 qemu_img_create('-f', iotests.imgfmt, test_img, str(image_len))
     37 
     38 # create VM
     39 vm = iotests.VM().add_drive(test_img)
     40 vm.launch()
     41 
     42 # write to the entire image
     43 vm.hmp_qemu_io('drive0', 'write -P0x16 0 4096');
     44 vm.hmp_qemu_io('drive0', 'write -P0x17 4096 1');
     45 
     46 # do backup and wait for completion
     47 vm.qmp('drive-backup', **{
     48     'device': 'drive0',
     49     'sync': 'full',
     50     'target': target_img
     51 })
     52 
     53 event = vm.event_wait(name='BLOCK_JOB_COMPLETED',
     54                       match={'data': {'device': 'drive0'}},
     55                       timeout=5.0)
     56 
     57 # shutdown to sync images
     58 vm.shutdown()
     59 
     60 # backup succeeded, check if image is correct
     61 qemu_img_log('compare', test_img, target_img)