Merge remote-tracking branch 'remotes/maxreitz/tags/pull-block-2020-07-28' into staging
[qemu/ar7.git] / tests / qemu-iotests / 283
blob383797ed626c4c2d6ad6af9212ba706aefe8f792
1 #!/usr/bin/env python3
3 # Test for backup-top filter permission activation failure
5 # Copyright (c) 2019 Virtuozzo International GmbH.
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/>.
21 import iotests
23 # The test is unrelated to formats, restrict it to qcow2 to avoid extra runs
24 iotests.script_initialize(
25     supported_fmts=['qcow2'],
28 size = 1024 * 1024
30 """ Test description
32 When performing a backup, all writes on the source subtree must go through the
33 backup-top filter so it can copy all data to the target before it is changed.
34 backup-top filter is appended above source node, to achieve this thing, so all
35 parents of source node are handled. A configuration with side parents of source
36 sub-tree with write permission is unsupported (we'd have append several
37 backup-top filter like nodes to handle such parents). The test create an
38 example of such configuration and checks that a backup is then not allowed
39 (blockdev-backup command should fail).
41 The configuration:
43     ┌────────┐  target  ┌─────────────┐
44     │ target │ ◀─────── │ backup_top  │
45     └────────┘          └─────────────┘
46                             │
47                             │ backing
48                             ▼
49                         ┌─────────────┐
50                         │   source    │
51                         └─────────────┘
52                             │
53                             │ file
54                             ▼
55                         ┌─────────────┐  write perm   ┌───────┐
56                         │    base     │ ◀──────────── │ other │
57                         └─────────────┘               └───────┘
59 On activation (see .active field of backup-top state in block/backup-top.c),
60 backup-top is going to unshare write permission on its source child. Write
61 unsharing will be propagated to the "source->base" link and will conflict with
62 other node write permission. So permission update will fail and backup job will
63 not be started.
65 Note, that the only thing which prevents backup of running on such
66 configuration is default permission propagation scheme. It may be altered by
67 different block drivers, so backup will run in invalid configuration. But
68 something is better than nothing. Also, before the previous commit (commit
69 preceding this test creation), starting backup on such configuration led to
70 crash, so current "something" is a lot better, and this test actual goal is
71 to check that crash is fixed :)
72 """
74 vm = iotests.VM()
75 vm.launch()
77 vm.qmp_log('blockdev-add', **{
78     'node-name': 'target',
79     'driver': 'null-co',
80     'size': size,
83 vm.qmp_log('blockdev-add', **{
84     'node-name': 'source',
85     'driver': 'blkdebug',
86     'image': {'node-name': 'base', 'driver': 'null-co', 'size': size}
89 vm.qmp_log('blockdev-add', **{
90     'node-name': 'other',
91     'driver': 'blkdebug',
92     'image': 'base',
93     'take-child-perms': ['write']
96 vm.qmp_log('blockdev-backup', sync='full', device='source', target='target')
98 vm.shutdown()