From: Vladimir Sementsov-Ogievskiy <v.sementsov-og@mail.ru>
To: qemu-block@nongnu.org
Cc: qemu-devel@nongnu.org, kwolf@redhat.com, hreitz@redhat.com,
v.sementsov-og@mail.ru
Subject: [PATCH v4 43/45] iotests: add filter-insertion
Date: Wed, 30 Mar 2022 13:12:15 +0300 [thread overview]
Message-ID: <20220330101217.4229-5-v.sementsov-og@mail.ru> (raw)
In-Reply-To: <20220329204107.411011-1-v.sementsov-og@mail.ru>
Demonstrate new API for filter insertion and removal.
Signed-off-by: Vladimir Sementsov-Ogievskiy <v.sementsov-og@mail.ru>
---
tests/qemu-iotests/tests/filter-insertion | 253 ++++++++++++++++++
tests/qemu-iotests/tests/filter-insertion.out | 5 +
2 files changed, 258 insertions(+)
create mode 100755 tests/qemu-iotests/tests/filter-insertion
create mode 100644 tests/qemu-iotests/tests/filter-insertion.out
diff --git a/tests/qemu-iotests/tests/filter-insertion b/tests/qemu-iotests/tests/filter-insertion
new file mode 100755
index 0000000000..4898d6e043
--- /dev/null
+++ b/tests/qemu-iotests/tests/filter-insertion
@@ -0,0 +1,253 @@
+#!/usr/bin/env python3
+#
+# Tests for inserting and removing filters in a block graph.
+#
+# Copyright (c) 2022 Virtuozzo International GmbH.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <http://www.gnu.org/licenses/>.
+#
+
+import os
+
+import iotests
+from iotests import qemu_img_create, try_remove
+
+
+disk = os.path.join(iotests.test_dir, 'disk')
+sock = os.path.join(iotests.sock_dir, 'sock')
+size = 1024 * 1024
+
+
+class TestFilterInsertion(iotests.QMPTestCase):
+ def setUp(self):
+ qemu_img_create(disk, str(size))
+
+ self.vm = iotests.VM()
+ self.vm.launch()
+
+ self.vm.qmp_check('blockdev-add', {
+ 'node-name': 'disk0',
+ 'driver': 'qcow2',
+ 'file': {
+ 'node-name': 'file0',
+ 'driver': 'file',
+ 'filename': disk
+ }
+ })
+
+ def tearDown(self):
+ self.vm.shutdown()
+ os.remove(disk)
+ try_remove(sock)
+
+ def test_simple_insertion(self):
+ vm = self.vm
+
+ vm.qmp_check('blockdev-add', {
+ 'node-name': 'filter',
+ 'driver': 'preallocate',
+ 'file': 'file0'
+ })
+
+ vm.qmp_check('x-blockdev-replace', {
+ 'parent-type': 'driver',
+ 'node-name': 'disk0',
+ 'child': 'file',
+ 'new-child': 'filter'
+ })
+
+ # Filter inserted:
+ # disk0 -file-> filter -file-> file0
+ vm.assert_edges_list([
+ ('disk0', 'file', 'filter'),
+ ('filter', 'file', 'file0')
+ ])
+
+ vm.qmp_check('x-blockdev-replace', {
+ 'parent-type': 'driver',
+ 'node-name': 'disk0',
+ 'child': 'file',
+ 'new-child': 'file0'
+ })
+
+ # Filter replaced, but still exists:
+ # dik0 -file-> file0 <-file- filter
+ vm.assert_edges_list([
+ ('disk0', 'file', 'file0'),
+ ('filter', 'file', 'file0')
+ ])
+
+ vm.qmp_check('blockdev-del', node_name='filter')
+
+ # Filter removed
+ # dik0 -file-> file0
+ vm.assert_edges_list([
+ ('disk0', 'file', 'file0')
+ ])
+
+ def test_tran_insert_under_qdev(self):
+ vm = self.vm
+
+ vm.qmp_check('device_add', driver='virtio-scsi')
+ vm.qmp_check('device_add', id='sda', driver='scsi-hd', drive='disk0')
+
+ vm.qmp_check('transaction', actions=[
+ {
+ 'type': 'blockdev-add',
+ 'data': {
+ 'node-name': 'filter',
+ 'driver': 'compress',
+ 'file': 'disk0'
+ }
+ }, {
+ 'type': 'x-blockdev-replace',
+ 'data': {
+ 'parent-type': 'qdev',
+ 'qdev-id': 'sda',
+ 'new-child': 'filter'
+ }
+ }
+ ])
+
+ # Filter inserted:
+ # sda -root-> filter -file-> disk0 -file-> file0
+ vm.assert_edges_list([
+ # parent_node_name, child_name, child_node_name
+ ('sda', 'root', 'filter'),
+ ('filter', 'file', 'disk0'),
+ ('disk0', 'file', 'file0'),
+ ])
+
+ vm.qmp_check('x-blockdev-replace', {
+ 'parent-type': 'qdev',
+ 'qdev-id': 'sda',
+ 'new-child': 'disk0'
+ })
+ vm.qmp_check('blockdev-del', node_name='filter')
+
+ # Filter removed:
+ # sda -root-> disk0 -file-> file0
+ vm.assert_edges_list([
+ # parent_node_name, child_name, child_node_name
+ ('sda', 'root', 'disk0'),
+ ('disk0', 'file', 'file0'),
+ ])
+
+ def test_tran_insert_under_nbd_export(self):
+ vm = self.vm
+
+ vm.qmp_check('nbd-server-start',
+ addr={'type': 'unix', 'data': {'path': sock}})
+ vm.qmp_check('block-export-add', id='exp1', type='nbd',
+ node_name='disk0', name='exp1')
+ vm.qmp_check('block-export-add', id='exp2', type='nbd',
+ node_name='disk0', name='exp2')
+ vm.qmp_check('object-add', qom_type='throttle-group',
+ id='tg', limits={'iops-read': 1})
+
+ vm.qmp_check('transaction', actions=[
+ {
+ 'type': 'blockdev-add',
+ 'data': {
+ 'node-name': 'filter',
+ 'driver': 'throttle',
+ 'throttle-group': 'tg',
+ 'file': 'disk0'
+ }
+ }, {
+ 'type': 'x-blockdev-replace',
+ 'data': {
+ 'parent-type': 'export',
+ 'export-id': 'exp1',
+ 'new-child': 'filter'
+ }
+ }
+ ])
+
+ # Only exp1 is throttled, exp2 is not:
+ # exp1 -root-> filter
+ # |
+ # |file
+ # v
+ # exp2 -file-> disk0 -file> file0
+ vm.assert_edges_list([
+ # parent_node_name, child_name, child_node_name
+ ('exp1', 'root', 'filter'),
+ ('filter', 'file', 'disk0'),
+ ('disk0', 'file', 'file0'),
+ ('exp2', 'root', 'disk0')
+ ])
+
+ vm.qmp_check('x-blockdev-replace', {
+ 'parent-type': 'export',
+ 'export-id': 'exp2',
+ 'new-child': 'filter'
+ })
+
+ # Both throttled:
+ # exp1 -root-> filter <-file- exp2
+ # |
+ # |file
+ # v
+ # disk0 -file> file0
+ vm.assert_edges_list([
+ # parent_node_name, child_name, child_node_name
+ ('exp1', 'root', 'filter'),
+ ('filter', 'file', 'disk0'),
+ ('disk0', 'file', 'file0'),
+ ('exp2', 'root', 'filter')
+ ])
+
+ # Check, that filter is in use and can't be removed
+ result = vm.qmp('blockdev-del', node_name='filter')
+ self.assert_qmp(result, 'error/desc', 'Node filter is in use')
+
+ vm.qmp_check('transaction', actions=[
+ {
+ 'type': 'x-blockdev-replace',
+ 'data': {
+ 'parent-type': 'export',
+ 'export-id': 'exp1',
+ 'new-child': 'disk0'
+ }
+ }, {
+ 'type': 'x-blockdev-replace',
+ 'data': {
+ 'parent-type': 'export',
+ 'export-id': 'exp2',
+ 'new-child': 'disk0'
+ }
+ }
+ ])
+ vm.qmp_check('blockdev-del', node_name='filter')
+
+ # Filter removed:
+ # exp1 -root-> disk0 <-file- exp2
+ # |
+ # |file
+ # v
+ # file0
+ vm.assert_edges_list([
+ # parent_node_name, child_name, child_node_name
+ ('exp1', 'root', 'disk0'),
+ ('disk0', 'file', 'file0'),
+ ('exp2', 'root', 'disk0')
+ ])
+
+
+if __name__ == '__main__':
+ iotests.main(
+ supported_fmts=['qcow2'],
+ supported_protocols=['file']
+ )
diff --git a/tests/qemu-iotests/tests/filter-insertion.out b/tests/qemu-iotests/tests/filter-insertion.out
new file mode 100644
index 0000000000..8d7e996700
--- /dev/null
+++ b/tests/qemu-iotests/tests/filter-insertion.out
@@ -0,0 +1,5 @@
+...
+----------------------------------------------------------------------
+Ran 3 tests
+
+OK
--
2.35.1
next prev parent reply other threads:[~2022-03-30 10:27 UTC|newest]
Thread overview: 47+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-03-29 20:40 [PATCH v4 00/45] Transactional block-graph modifying API Vladimir Sementsov-Ogievskiy
2022-03-29 20:40 ` [PATCH v4 01/45] block: BlockDriver: add .filtered_child_is_backing field Vladimir Sementsov-Ogievskiy
2022-03-29 20:40 ` [PATCH v4 02/45] block: introduce bdrv_open_file_child() helper Vladimir Sementsov-Ogievskiy
2022-03-29 20:40 ` [PATCH v4 03/45] block/blklogwrites: don't care to remove bs->file child on failure Vladimir Sementsov-Ogievskiy
2022-03-29 20:40 ` [PATCH v4 04/45] test-bdrv-graph-mod: update test_parallel_perm_update test case Vladimir Sementsov-Ogievskiy
2022-03-29 20:40 ` [PATCH v4 05/45] tests-bdrv-drain: bdrv_replace_test driver: declare supports_backing Vladimir Sementsov-Ogievskiy
2022-03-29 20:40 ` [PATCH v4 06/45] test-bdrv-graph-mod: fix filters to be filters Vladimir Sementsov-Ogievskiy
2022-03-29 20:40 ` [PATCH v4 07/45] block: document connection between child roles and bs->backing/bs->file Vladimir Sementsov-Ogievskiy
2022-03-29 20:40 ` [PATCH v4 08/45] block/snapshot: stress that we fallback to primary child Vladimir Sementsov-Ogievskiy
2022-03-29 20:40 ` [PATCH v4 09/45] Revert "block: Let replace_child_noperm free children" Vladimir Sementsov-Ogievskiy
2022-03-29 20:40 ` [PATCH v4 10/45] Revert "block: Let replace_child_tran keep indirect pointer" Vladimir Sementsov-Ogievskiy
2022-03-29 20:40 ` [PATCH v4 11/45] Revert "block: Restructure remove_file_or_backing_child()" Vladimir Sementsov-Ogievskiy
2022-03-29 20:40 ` [PATCH v4 12/45] Revert "block: Pass BdrvChild ** to replace_child_noperm" Vladimir Sementsov-Ogievskiy
2022-03-29 20:40 ` [PATCH v4 13/45] block: Manipulate bs->file / bs->backing pointers in .attach/.detach Vladimir Sementsov-Ogievskiy
2022-03-29 20:40 ` [PATCH v4 14/45] block/snapshot: drop indirection around bdrv_snapshot_fallback_ptr Vladimir Sementsov-Ogievskiy
2022-03-29 20:40 ` [PATCH v4 15/45] block: refactor bdrv_remove_file_or_backing_child to bdrv_remove_child Vladimir Sementsov-Ogievskiy
2022-03-29 20:40 ` [PATCH v4 16/45] block: drop bdrv_detach_child() Vladimir Sementsov-Ogievskiy
2022-03-29 20:40 ` [PATCH v4 17/45] block: drop bdrv_remove_filter_or_cow_child Vladimir Sementsov-Ogievskiy
2022-03-29 20:40 ` [PATCH v4 18/45] block: bdrv_refresh_perms(): allow external tran Vladimir Sementsov-Ogievskiy
2022-03-29 20:40 ` [PATCH v4 19/45] block: refactor bdrv_list_refresh_perms to allow any list of nodes Vladimir Sementsov-Ogievskiy
2022-03-29 20:40 ` [PATCH v4 20/45] block: make permission update functions public Vladimir Sementsov-Ogievskiy
2022-03-29 20:40 ` [PATCH v4 21/45] block: add bdrv_try_set_aio_context_tran transaction action Vladimir Sementsov-Ogievskiy
2022-03-29 20:40 ` [PATCH v4 22/45] block: implemet bdrv_unref_tran() Vladimir Sementsov-Ogievskiy
2022-03-29 20:40 ` [PATCH v4 23/45] blockdev: refactor transaction to use Transaction API Vladimir Sementsov-Ogievskiy
2022-03-29 20:40 ` [PATCH v4 24/45] blockdev: transactions: rename some things Vladimir Sementsov-Ogievskiy
2022-03-29 20:40 ` [PATCH v4 25/45] blockdev: qmp_transaction: refactor loop to classic for Vladimir Sementsov-Ogievskiy
2022-03-29 20:40 ` [PATCH v4 26/45] blockdev: transaction: refactor handling transaction properties Vladimir Sementsov-Ogievskiy
2022-03-29 20:40 ` [PATCH v4 27/45] blockdev: qmp_transaction: drop extra generic layer Vladimir Sementsov-Ogievskiy
2022-03-29 20:40 ` [PATCH v4 28/45] qapi: block: add blockdev-del transaction action Vladimir Sementsov-Ogievskiy
2022-03-29 20:40 ` [PATCH v4 29/45] block: introduce BDRV_O_NOPERM flag Vladimir Sementsov-Ogievskiy
2022-03-29 20:40 ` [PATCH v4 30/45] block: bdrv_insert_node(): use BDRV_O_NOPERM Vladimir Sementsov-Ogievskiy
2022-03-29 20:40 ` [PATCH v4 31/45] qapi: block: add blockdev-add transaction action Vladimir Sementsov-Ogievskiy
2022-03-29 20:40 ` [PATCH v4 32/45] iotests: add blockdev-add-transaction Vladimir Sementsov-Ogievskiy
2022-03-29 20:40 ` [PATCH v4 33/45] block-backend: blk_root(): drop const specifier on return type Vladimir Sementsov-Ogievskiy
2022-03-29 20:40 ` [PATCH v4 34/45] block/export: add blk_by_export_id() Vladimir Sementsov-Ogievskiy
2022-03-29 20:40 ` [PATCH v4 35/45] block: make bdrv_find_child() function public Vladimir Sementsov-Ogievskiy
2022-03-29 20:40 ` [PATCH v4 36/45] block: bdrv_replace_child_bs(): move to external transaction Vladimir Sementsov-Ogievskiy
2022-03-29 20:40 ` [PATCH v4 37/45] qapi: add x-blockdev-replace command Vladimir Sementsov-Ogievskiy
2022-03-29 20:41 ` [PATCH v4 38/45] qapi: add x-blockdev-replace transaction action Vladimir Sementsov-Ogievskiy
2022-03-30 10:12 ` [PATCH v4 39/45] block: bdrv_get_xdbg_block_graph(): report export ids Vladimir Sementsov-Ogievskiy
2022-03-30 10:12 ` [PATCH v4 40/45] iotests.py: qemu_img_create: use imgfmt by default Vladimir Sementsov-Ogievskiy
2022-03-30 10:12 ` [PATCH v4 41/45] iotests.py: introduce VM.assert_edges_list() method Vladimir Sementsov-Ogievskiy
2022-03-30 10:12 ` [PATCH v4 42/45] iotests.py: add VM.qmp_check() helper Vladimir Sementsov-Ogievskiy
2022-03-30 10:12 ` Vladimir Sementsov-Ogievskiy [this message]
2022-03-30 10:12 ` [PATCH v4 44/45] block: bdrv_open_inherit: create BlockBackend only when necessary Vladimir Sementsov-Ogievskiy
2022-03-30 10:12 ` [PATCH v4 45/45] block/copy-before-write: correct permission scheme Vladimir Sementsov-Ogievskiy
2022-03-30 19:03 ` [PATCH v4 00/45] Transactional block-graph modifying API Vladimir Sementsov-Ogievskiy
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20220330101217.4229-5-v.sementsov-og@mail.ru \
--to=v.sementsov-og@mail.ru \
--cc=hreitz@redhat.com \
--cc=kwolf@redhat.com \
--cc=qemu-block@nongnu.org \
--cc=qemu-devel@nongnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).