]>
Commit | Line | Data |
---|---|---|
903cb1bf | 1 | #!/usr/bin/env python3 |
9dd003a9 | 2 | # group: rw quick |
e62303a4 FZ |
3 | # |
4 | # Tests that "bdrv_drain_all" doesn't drain block jobs | |
5 | # | |
6 | # Copyright (C) 2015 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 | ||
22 | import os | |
23 | import iotests | |
e62303a4 FZ |
24 | |
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') | |
55557b02 | 29 | overlay_img = os.path.join(iotests.test_dir, 'overlay.img') |
e62303a4 FZ |
30 | |
31 | def setUp(self): | |
32 | iotests.qemu_img('create', '-f', iotests.imgfmt, self.base_img, "1G") | |
b66ff2c2 EB |
33 | iotests.qemu_img('create', '-f', iotests.imgfmt, self.test_img, |
34 | "-b", self.base_img, '-F', iotests.imgfmt) | |
636aa64d HR |
35 | iotests.qemu_io('-f', iotests.imgfmt, '-c', 'write -P0x5d 1M 128M', |
36 | self.test_img) | |
a1933dac HR |
37 | self.vm = iotests.VM() |
38 | self.vm.add_object('throttle-group,id=tg0,x-bps-total=1024') | |
39 | ||
40 | source_drive = 'driver=throttle,' \ | |
55557b02 | 41 | 'node-name=source,' \ |
a1933dac HR |
42 | 'throttle-group=tg0,' \ |
43 | f'file.driver={iotests.imgfmt},' \ | |
44 | f'file.file.filename={self.test_img}' | |
45 | ||
46 | self.vm.add_drive(None, source_drive) | |
e62303a4 FZ |
47 | self.vm.launch() |
48 | ||
49 | def tearDown(self): | |
e62303a4 | 50 | self.vm.shutdown() |
55557b02 HR |
51 | for img in (self.test_img, self.target_img, self.base_img, |
52 | self.overlay_img): | |
20e2580e | 53 | iotests.try_remove(img) |
e62303a4 FZ |
54 | |
55 | def do_test_stop(self, cmd, **args): | |
56 | """Test 'stop' while block job is running on a throttled drive. | |
57 | The 'stop' command shouldn't drain the job""" | |
e62303a4 FZ |
58 | result = self.vm.qmp(cmd, **args) |
59 | self.assert_qmp(result, 'return', {}) | |
a1933dac | 60 | |
e62303a4 FZ |
61 | result = self.vm.qmp("stop") |
62 | self.assert_qmp(result, 'return', {}) | |
63 | result = self.vm.qmp("query-block-jobs") | |
a1933dac | 64 | |
f9a6256b | 65 | self.assert_qmp(result, 'return[0]/status', 'running') |
e62303a4 FZ |
66 | self.assert_qmp(result, 'return[0]/ready', False) |
67 | ||
68 | def test_drive_mirror(self): | |
69 | self.do_test_stop("drive-mirror", device="drive0", | |
a1933dac | 70 | target=self.target_img, format=iotests.imgfmt, |
20c15f7c | 71 | sync="full", buf_size=65536) |
e62303a4 FZ |
72 | |
73 | def test_drive_backup(self): | |
67a066fb HR |
74 | # Limit max-chunk and max-workers so that block-copy will not |
75 | # launch so many workers working on so much data each that | |
76 | # stop's bdrv_drain_all() would finish the job | |
e62303a4 | 77 | self.do_test_stop("drive-backup", device="drive0", |
a1933dac | 78 | target=self.target_img, format=iotests.imgfmt, |
67a066fb | 79 | sync="full", |
87e4d4a2 EGE |
80 | x_perf={'max-chunk': 65536, |
81 | 'max-workers': 8}) | |
e62303a4 FZ |
82 | |
83 | def test_block_commit(self): | |
55557b02 HR |
84 | # Add overlay above the source node so that we actually use a |
85 | # commit job instead of a mirror job | |
86 | ||
87 | iotests.qemu_img('create', '-f', iotests.imgfmt, self.overlay_img, | |
88 | '1G') | |
89 | ||
90 | result = self.vm.qmp('blockdev-add', **{ | |
87e4d4a2 EGE |
91 | 'node-name': 'overlay', |
92 | 'driver': iotests.imgfmt, | |
93 | 'file': { | |
94 | 'driver': 'file', | |
95 | 'filename': self.overlay_img | |
96 | } | |
97 | }) | |
55557b02 HR |
98 | self.assert_qmp(result, 'return', {}) |
99 | ||
100 | result = self.vm.qmp('blockdev-snapshot', | |
101 | node='source', overlay='overlay') | |
102 | self.assert_qmp(result, 'return', {}) | |
103 | ||
104 | self.do_test_stop('block-commit', device='drive0', top_node='source') | |
e62303a4 FZ |
105 | |
106 | if __name__ == '__main__': | |
103cbc77 HR |
107 | iotests.main(supported_fmts=["qcow2"], |
108 | supported_protocols=["file"]) |