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