xref: /openbmc/qemu/tests/qemu-iotests/129 (revision b6aed193)
1903cb1bfSPhilippe Mathieu-Daudé#!/usr/bin/env python3
29dd003a9SVladimir Sementsov-Ogievskiy# group: rw quick
3e62303a4SFam Zheng#
4e62303a4SFam Zheng# Tests that "bdrv_drain_all" doesn't drain block jobs
5e62303a4SFam Zheng#
6e62303a4SFam Zheng# Copyright (C) 2015 Red Hat, Inc.
7e62303a4SFam Zheng#
8e62303a4SFam Zheng# This program is free software; you can redistribute it and/or modify
9e62303a4SFam Zheng# it under the terms of the GNU General Public License as published by
10e62303a4SFam Zheng# the Free Software Foundation; either version 2 of the License, or
11e62303a4SFam Zheng# (at your option) any later version.
12e62303a4SFam Zheng#
13e62303a4SFam Zheng# This program is distributed in the hope that it will be useful,
14e62303a4SFam Zheng# but WITHOUT ANY WARRANTY; without even the implied warranty of
15e62303a4SFam Zheng# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16e62303a4SFam Zheng# GNU General Public License for more details.
17e62303a4SFam Zheng#
18e62303a4SFam Zheng# You should have received a copy of the GNU General Public License
19e62303a4SFam Zheng# along with this program.  If not, see <http://www.gnu.org/licenses/>.
20e62303a4SFam Zheng#
21e62303a4SFam Zheng
22e62303a4SFam Zhengimport os
23e62303a4SFam Zhengimport iotests
24e62303a4SFam Zheng
25e62303a4SFam Zhengclass TestStopWithBlockJob(iotests.QMPTestCase):
26e62303a4SFam Zheng    test_img = os.path.join(iotests.test_dir, 'test.img')
27e62303a4SFam Zheng    target_img = os.path.join(iotests.test_dir, 'target.img')
28e62303a4SFam Zheng    base_img = os.path.join(iotests.test_dir, 'base.img')
2955557b02SMax Reitz    overlay_img = os.path.join(iotests.test_dir, 'overlay.img')
30e62303a4SFam Zheng
31e62303a4SFam Zheng    def setUp(self):
32e62303a4SFam Zheng        iotests.qemu_img('create', '-f', iotests.imgfmt, self.base_img, "1G")
33b66ff2c2SEric Blake        iotests.qemu_img('create', '-f', iotests.imgfmt, self.test_img,
34b66ff2c2SEric Blake                         "-b", self.base_img, '-F', iotests.imgfmt)
35636aa64dSMax Reitz        iotests.qemu_io('-f', iotests.imgfmt, '-c', 'write -P0x5d 1M 128M',
36636aa64dSMax Reitz                        self.test_img)
37a1933dacSMax Reitz        self.vm = iotests.VM()
38a1933dacSMax Reitz        self.vm.add_object('throttle-group,id=tg0,x-bps-total=1024')
39a1933dacSMax Reitz
40a1933dacSMax Reitz        source_drive = 'driver=throttle,' \
4155557b02SMax Reitz                       'node-name=source,' \
42a1933dacSMax Reitz                       'throttle-group=tg0,' \
43a1933dacSMax Reitz                       f'file.driver={iotests.imgfmt},' \
44a1933dacSMax Reitz                       f'file.file.filename={self.test_img}'
45a1933dacSMax Reitz
46a1933dacSMax Reitz        self.vm.add_drive(None, source_drive)
47e62303a4SFam Zheng        self.vm.launch()
48e62303a4SFam Zheng
49e62303a4SFam Zheng    def tearDown(self):
50e62303a4SFam Zheng        self.vm.shutdown()
5155557b02SMax Reitz        for img in (self.test_img, self.target_img, self.base_img,
5255557b02SMax Reitz                    self.overlay_img):
5320e2580eSMax Reitz            iotests.try_remove(img)
54e62303a4SFam Zheng
55e62303a4SFam Zheng    def do_test_stop(self, cmd, **args):
56e62303a4SFam Zheng        """Test 'stop' while block job is running on a throttled drive.
57e62303a4SFam Zheng        The 'stop' command shouldn't drain the job"""
58*b6aed193SVladimir Sementsov-Ogievskiy        self.vm.cmd(cmd, **args)
59a1933dacSMax Reitz
60*b6aed193SVladimir Sementsov-Ogievskiy        self.vm.cmd("stop")
61e62303a4SFam Zheng        result = self.vm.qmp("query-block-jobs")
62a1933dacSMax Reitz
63f9a6256bSMax Reitz        self.assert_qmp(result, 'return[0]/status', 'running')
64e62303a4SFam Zheng        self.assert_qmp(result, 'return[0]/ready', False)
65e62303a4SFam Zheng
66e62303a4SFam Zheng    def test_drive_mirror(self):
67e62303a4SFam Zheng        self.do_test_stop("drive-mirror", device="drive0",
68a1933dacSMax Reitz                          target=self.target_img, format=iotests.imgfmt,
6920c15f7cSMax Reitz                          sync="full", buf_size=65536)
70e62303a4SFam Zheng
71e62303a4SFam Zheng    def test_drive_backup(self):
7267a066fbSMax Reitz        # Limit max-chunk and max-workers so that block-copy will not
7367a066fbSMax Reitz        # launch so many workers working on so much data each that
7467a066fbSMax Reitz        # stop's bdrv_drain_all() would finish the job
75e62303a4SFam Zheng        self.do_test_stop("drive-backup", device="drive0",
76a1933dacSMax Reitz                          target=self.target_img, format=iotests.imgfmt,
7767a066fbSMax Reitz                          sync="full",
7867a066fbSMax Reitz                          x_perf={'max-chunk': 65536,
7967a066fbSMax Reitz                                  'max-workers': 8})
80e62303a4SFam Zheng
81e62303a4SFam Zheng    def test_block_commit(self):
8255557b02SMax Reitz        # Add overlay above the source node so that we actually use a
8355557b02SMax Reitz        # commit job instead of a mirror job
8455557b02SMax Reitz
8555557b02SMax Reitz        iotests.qemu_img('create', '-f', iotests.imgfmt, self.overlay_img,
8655557b02SMax Reitz                         '1G')
8755557b02SMax Reitz
88*b6aed193SVladimir Sementsov-Ogievskiy        self.vm.cmd('blockdev-add', {
8955557b02SMax Reitz            'node-name': 'overlay',
9055557b02SMax Reitz            'driver': iotests.imgfmt,
9155557b02SMax Reitz            'file': {
9255557b02SMax Reitz                'driver': 'file',
9355557b02SMax Reitz                'filename': self.overlay_img
9455557b02SMax Reitz            }
9555557b02SMax Reitz        })
9655557b02SMax Reitz
97*b6aed193SVladimir Sementsov-Ogievskiy        self.vm.cmd('blockdev-snapshot',
9855557b02SMax Reitz                    node='source', overlay='overlay')
9955557b02SMax Reitz
10055557b02SMax Reitz        self.do_test_stop('block-commit', device='drive0', top_node='source')
101e62303a4SFam Zheng
102e62303a4SFam Zhengif __name__ == '__main__':
103103cbc77SMax Reitz    iotests.main(supported_fmts=["qcow2"],
104103cbc77SMax Reitz                 supported_protocols=["file"])
105