3 # Tests that "bdrv_drain_all" doesn't drain block jobs
5 # Copyright (C) 2015 Red Hat, Inc.
7 # This program is free software; you can redistribute it and/or modify
8 # it under the terms of the GNU General Public License as published by
9 # the Free Software Foundation; either version 2 of the License, or
10 # (at your option) any later version.
12 # This program is distributed in the hope that it will be useful,
13 # but WITHOUT ANY WARRANTY; without even the implied warranty of
14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 # GNU General Public License for more details.
17 # You should have received a copy of the GNU General Public License
18 # along with this program. If not, see <http://www.gnu.org/licenses/>.
25 class TestStopWithBlockJob(iotests.QMPTestCase):
26 test_img = os.path.join(iotests.test_dir, 'test.img')
27 target_img = os.path.join(iotests.test_dir, 'target.img')
28 base_img = os.path.join(iotests.test_dir, 'base.img')
31 iotests.qemu_img('create', '-f', iotests.imgfmt, self.base_img, "1G")
32 iotests.qemu_img('create', '-f', iotests.imgfmt, self.test_img,
33 "-b", self.base_img, '-F', iotests.imgfmt)
34 iotests.qemu_io('-f', iotests.imgfmt, '-c', 'write -P0x5d 1M 128M', self.test_img)
35 self.vm = iotests.VM().add_drive(self.test_img)
39 params = {"device": "drive0",
47 result = self.vm.qmp("block_set_io_throttle", conv_keys=False,
51 def do_test_stop(self, cmd, **args):
52 """Test 'stop' while block job is running on a throttled drive.
53 The 'stop' command shouldn't drain the job"""
54 params = {"device": "drive0",
62 result = self.vm.qmp("block_set_io_throttle", conv_keys=False,
64 self.assert_qmp(result, 'return', {})
65 result = self.vm.qmp(cmd, **args)
66 self.assert_qmp(result, 'return', {})
67 result = self.vm.qmp("stop")
68 self.assert_qmp(result, 'return', {})
69 result = self.vm.qmp("query-block-jobs")
70 self.assert_qmp(result, 'return[0]/busy', True)
71 self.assert_qmp(result, 'return[0]/ready', False)
73 def test_drive_mirror(self):
74 self.do_test_stop("drive-mirror", device="drive0",
75 target=self.target_img,
78 def test_drive_backup(self):
79 self.do_test_stop("drive-backup", device="drive0",
80 target=self.target_img,
83 def test_block_commit(self):
84 self.do_test_stop("block-commit", device="drive0")
86 if __name__ == '__main__':
87 iotests.main(supported_fmts=["qcow2"],
88 supported_protocols=["file"])