cachepc-qemu

Fork of AMDESE/qemu with changes for cachepc side-channel attack
git clone https://git.sinitax.com/sinitax/cachepc-qemu
Log | Files | Refs | Submodules | LICENSE | sfeed.txt

280 (3008B)


      1#!/usr/bin/env python3
      2# group: rw migration quick
      3#
      4# Copyright (C) 2019 Red Hat, Inc.
      5#
      6# This program is free software; you can redistribute it and/or modify
      7# it under the terms of the GNU General Public License as published by
      8# the Free Software Foundation; either version 2 of the License, or
      9# (at your option) any later version.
     10#
     11# This program is distributed in the hope that it will be useful,
     12# but WITHOUT ANY WARRANTY; without even the implied warranty of
     13# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
     14# GNU General Public License for more details.
     15#
     16# You should have received a copy of the GNU General Public License
     17# along with this program.  If not, see <http://www.gnu.org/licenses/>.
     18#
     19# Creator/Owner: Kevin Wolf <kwolf@redhat.com>
     20#
     21# Test migration to file for taking an external snapshot with VM state.
     22
     23import iotests
     24import os
     25
     26iotests.script_initialize(
     27    supported_fmts=['qcow2'],
     28    supported_protocols=['file'],
     29    supported_platforms=['linux'],
     30)
     31
     32with iotests.FilePath('base') as base_path , \
     33     iotests.FilePath('top') as top_path, \
     34     iotests.VM() as vm:
     35
     36    iotests.qemu_img_log('create', '-f', iotests.imgfmt, base_path, '64M')
     37
     38    iotests.log('=== Launch VM ===')
     39    vm.add_object('iothread,id=iothread0')
     40    vm.add_blockdev('file,filename=%s,node-name=base-file' % (base_path))
     41    vm.add_blockdev('%s,file=base-file,node-name=base-fmt' % (iotests.imgfmt))
     42    vm.add_device('virtio-blk,drive=base-fmt,iothread=iothread0,id=vda')
     43    vm.launch()
     44
     45    vm.enable_migration_events('VM')
     46
     47    iotests.log('\n=== Migrate to file ===')
     48    vm.qmp_log('migrate', uri='exec:cat > /dev/null')
     49
     50    with iotests.Timeout(3, 'Migration does not complete'):
     51        vm.wait_migration('postmigrate')
     52
     53    iotests.log('\nVM is now stopped:')
     54    iotests.log(vm.qmp('query-migrate')['return']['status'])
     55    vm.qmp_log('query-status')
     56
     57    iotests.log('\n=== Create a snapshot of the disk image ===')
     58    vm.blockdev_create({
     59        'driver': 'file',
     60        'filename': top_path,
     61        'size': 0,
     62    })
     63    vm.qmp_log('blockdev-add', node_name='top-file',
     64               driver='file', filename=top_path,
     65               filters=[iotests.filter_qmp_testfiles])
     66
     67    vm.blockdev_create({
     68        'driver': iotests.imgfmt,
     69        'file': 'top-file',
     70        'size': 1024 * 1024,
     71    })
     72    vm.qmp_log('blockdev-add', node_name='top-fmt',
     73               driver=iotests.imgfmt, file='top-file')
     74
     75    vm.qmp_log('blockdev-snapshot', node='base-fmt', overlay='top-fmt')
     76
     77    iotests.log('\n=== Resume the VM and simulate a write request ===')
     78    vm.qmp_log('cont')
     79    iotests.log(vm.hmp_qemu_io('-d vda/virtio-backend', 'write 4k 4k'))
     80
     81    iotests.log('\n=== Commit it to the backing file ===')
     82    result = vm.qmp_log('block-commit', job_id='job0', auto_dismiss=False,
     83                        device='top-fmt', top_node='top-fmt',
     84                        filters=[iotests.filter_qmp_testfiles])
     85    if 'return' in result:
     86        vm.run_job('job0')