xref: /openbmc/qemu/tests/qemu-iotests/283 (revision 7d8140595f1e131935ba1c98a55af7d066660707)
17c477526SPhilippe Mathieu-Daudé#!/usr/bin/env python3
2a541fcc2SVladimir Sementsov-Ogievskiy#
3a541fcc2SVladimir Sementsov-Ogievskiy# Test for backup-top filter permission activation failure
4a541fcc2SVladimir Sementsov-Ogievskiy#
5a541fcc2SVladimir Sementsov-Ogievskiy# Copyright (c) 2019 Virtuozzo International GmbH.
6a541fcc2SVladimir Sementsov-Ogievskiy#
7a541fcc2SVladimir Sementsov-Ogievskiy# This program is free software; you can redistribute it and/or modify
8a541fcc2SVladimir Sementsov-Ogievskiy# it under the terms of the GNU General Public License as published by
9a541fcc2SVladimir Sementsov-Ogievskiy# the Free Software Foundation; either version 2 of the License, or
10a541fcc2SVladimir Sementsov-Ogievskiy# (at your option) any later version.
11a541fcc2SVladimir Sementsov-Ogievskiy#
12a541fcc2SVladimir Sementsov-Ogievskiy# This program is distributed in the hope that it will be useful,
13a541fcc2SVladimir Sementsov-Ogievskiy# but WITHOUT ANY WARRANTY; without even the implied warranty of
14a541fcc2SVladimir Sementsov-Ogievskiy# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15a541fcc2SVladimir Sementsov-Ogievskiy# GNU General Public License for more details.
16a541fcc2SVladimir Sementsov-Ogievskiy#
17a541fcc2SVladimir Sementsov-Ogievskiy# You should have received a copy of the GNU General Public License
18a541fcc2SVladimir Sementsov-Ogievskiy# along with this program.  If not, see <http://www.gnu.org/licenses/>.
19a541fcc2SVladimir Sementsov-Ogievskiy#
20a541fcc2SVladimir Sementsov-Ogievskiy
21a541fcc2SVladimir Sementsov-Ogievskiyimport iotests
22a541fcc2SVladimir Sementsov-Ogievskiy
23a541fcc2SVladimir Sementsov-Ogievskiy# The test is unrelated to formats, restrict it to qcow2 to avoid extra runs
24*7d814059SJohn Snowiotests.script_initialize(
25*7d814059SJohn Snow    supported_fmts=['qcow2'],
26*7d814059SJohn Snow)
27a541fcc2SVladimir Sementsov-Ogievskiy
28a541fcc2SVladimir Sementsov-Ogievskiysize = 1024 * 1024
29a541fcc2SVladimir Sementsov-Ogievskiy
30a541fcc2SVladimir Sementsov-Ogievskiy""" Test description
31a541fcc2SVladimir Sementsov-Ogievskiy
32a541fcc2SVladimir Sementsov-OgievskiyWhen performing a backup, all writes on the source subtree must go through the
33a541fcc2SVladimir Sementsov-Ogievskiybackup-top filter so it can copy all data to the target before it is changed.
34a541fcc2SVladimir Sementsov-Ogievskiybackup-top filter is appended above source node, to achieve this thing, so all
35a541fcc2SVladimir Sementsov-Ogievskiyparents of source node are handled. A configuration with side parents of source
36a541fcc2SVladimir Sementsov-Ogievskiysub-tree with write permission is unsupported (we'd have append several
37a541fcc2SVladimir Sementsov-Ogievskiybackup-top filter like nodes to handle such parents). The test create an
38a541fcc2SVladimir Sementsov-Ogievskiyexample of such configuration and checks that a backup is then not allowed
39a541fcc2SVladimir Sementsov-Ogievskiy(blockdev-backup command should fail).
40a541fcc2SVladimir Sementsov-Ogievskiy
41a541fcc2SVladimir Sementsov-OgievskiyThe configuration:
42a541fcc2SVladimir Sementsov-Ogievskiy
43a541fcc2SVladimir Sementsov-Ogievskiy    ┌────────┐  target  ┌─────────────┐
44a541fcc2SVladimir Sementsov-Ogievskiy    │ target │ ◀─────── │ backup_top  │
45a541fcc2SVladimir Sementsov-Ogievskiy    └────────┘          └─────────────┘
46a541fcc2SVladimir Sementsov-Ogievskiy47a541fcc2SVladimir Sementsov-Ogievskiy                            │ backing
48a541fcc2SVladimir Sementsov-Ogievskiy49a541fcc2SVladimir Sementsov-Ogievskiy                        ┌─────────────┐
50a541fcc2SVladimir Sementsov-Ogievskiy                        │   source    │
51a541fcc2SVladimir Sementsov-Ogievskiy                        └─────────────┘
52a541fcc2SVladimir Sementsov-Ogievskiy53a541fcc2SVladimir Sementsov-Ogievskiy                            │ file
54a541fcc2SVladimir Sementsov-Ogievskiy55a541fcc2SVladimir Sementsov-Ogievskiy                        ┌─────────────┐  write perm   ┌───────┐
56a541fcc2SVladimir Sementsov-Ogievskiy                        │    base     │ ◀──────────── │ other │
57a541fcc2SVladimir Sementsov-Ogievskiy                        └─────────────┘               └───────┘
58a541fcc2SVladimir Sementsov-Ogievskiy
59a541fcc2SVladimir Sementsov-OgievskiyOn activation (see .active field of backup-top state in block/backup-top.c),
60a541fcc2SVladimir Sementsov-Ogievskiybackup-top is going to unshare write permission on its source child. Write
61a541fcc2SVladimir Sementsov-Ogievskiyunsharing will be propagated to the "source->base" link and will conflict with
62a541fcc2SVladimir Sementsov-Ogievskiyother node write permission. So permission update will fail and backup job will
63a541fcc2SVladimir Sementsov-Ogievskiynot be started.
64a541fcc2SVladimir Sementsov-Ogievskiy
65a541fcc2SVladimir Sementsov-OgievskiyNote, that the only thing which prevents backup of running on such
66a541fcc2SVladimir Sementsov-Ogievskiyconfiguration is default permission propagation scheme. It may be altered by
67a541fcc2SVladimir Sementsov-Ogievskiydifferent block drivers, so backup will run in invalid configuration. But
68a541fcc2SVladimir Sementsov-Ogievskiysomething is better than nothing. Also, before the previous commit (commit
69a541fcc2SVladimir Sementsov-Ogievskiypreceding this test creation), starting backup on such configuration led to
70a541fcc2SVladimir Sementsov-Ogievskiycrash, so current "something" is a lot better, and this test actual goal is
71a541fcc2SVladimir Sementsov-Ogievskiyto check that crash is fixed :)
72a541fcc2SVladimir Sementsov-Ogievskiy"""
73a541fcc2SVladimir Sementsov-Ogievskiy
74a541fcc2SVladimir Sementsov-Ogievskiyvm = iotests.VM()
75a541fcc2SVladimir Sementsov-Ogievskiyvm.launch()
76a541fcc2SVladimir Sementsov-Ogievskiy
77a541fcc2SVladimir Sementsov-Ogievskiyvm.qmp_log('blockdev-add', **{'node-name': 'target', 'driver': 'null-co'})
78a541fcc2SVladimir Sementsov-Ogievskiy
79a541fcc2SVladimir Sementsov-Ogievskiyvm.qmp_log('blockdev-add', **{
80a541fcc2SVladimir Sementsov-Ogievskiy    'node-name': 'source',
81a541fcc2SVladimir Sementsov-Ogievskiy    'driver': 'blkdebug',
82a541fcc2SVladimir Sementsov-Ogievskiy    'image': {'node-name': 'base', 'driver': 'null-co', 'size': size}
83a541fcc2SVladimir Sementsov-Ogievskiy})
84a541fcc2SVladimir Sementsov-Ogievskiy
85a541fcc2SVladimir Sementsov-Ogievskiyvm.qmp_log('blockdev-add', **{
86a541fcc2SVladimir Sementsov-Ogievskiy    'node-name': 'other',
87a541fcc2SVladimir Sementsov-Ogievskiy    'driver': 'blkdebug',
88a541fcc2SVladimir Sementsov-Ogievskiy    'image': 'base',
89a541fcc2SVladimir Sementsov-Ogievskiy    'take-child-perms': ['write']
90a541fcc2SVladimir Sementsov-Ogievskiy})
91a541fcc2SVladimir Sementsov-Ogievskiy
92a541fcc2SVladimir Sementsov-Ogievskiyvm.qmp_log('blockdev-backup', sync='full', device='source', target='target')
93a541fcc2SVladimir Sementsov-Ogievskiy
94a541fcc2SVladimir Sementsov-Ogievskiyvm.shutdown()
95