Skip to contentSkip to conversation

blockdev-add transaction

PATCH New Vladimir Sementsov-Ogievskiy 1 participant 3 messages Feb 24, 2022

lore
Share & tools
lore
#0 lore raw

cover blockdev-add transaction

Hi all!

If we want to do incremental backups with help of copy-before-write filter bitmap parameter introduced in my in-flight series "[PATCH v4 00/18] Make image fleecing more usable", we actually need to create filter, insert it into graph and do some operations with bitmaps in one transaction.

So, here is basic support for blockdev-add transaction, which may be useful for any scenarios.

Also, I'll need to resend my "[PATCH RFC v2 0/4] blockdev-replace" with transaction support as well.

Why I say that support is "basic"? Ideally we want an ability to call several blockdev-add / blockdev-replace commands not updating the permission and only then update permissions for all touched nodes. That is more flexible and will allow more strict and simple permission requirements in filter drivers. Still this means to implement bdrv_open() transaction action (using Transaction API) which doesn't update permissions (like most of internal graph update functions works now). That's of course is more complicated than this patch. So, let's start with something simple.

Vladimir Sementsov-Ogievskiy (2):
block: transaction support for blockdev-add
iotests: add blockdev-add-transaction

 qapi/transaction.json                         | 11 +++
 blockdev.c                                    | 80 +++++++++++++------
 .../tests/blockdev-add-transaction            | 52 ++++++++++++
 .../tests/blockdev-add-transaction.out        |  6 ++
 4 files changed, 124 insertions(+), 25 deletions(-)
 create mode 100755 tests/qemu-iotests/tests/blockdev-add-transaction
 create mode 100644 tests/qemu-iotests/tests/blockdev-add-transaction.out
Signature · 1 line
2.31.1
#1 lore raw

PATCH 1/2 block: transaction support for blockdev-add

Simply do blockdev_add() in .prepare() and bdrv_unref() in .abort() and that's it.

---
 qapi/transaction.json | 11 ++++++
 blockdev.c            | 80 +++++++++++++++++++++++++++++--------------
 2 files changed, 66 insertions(+), 25 deletions(-)
qapi/transaction.json +11 -0
index 381a2df782..a938dc7d10 100644
@@ -53,6 +53,7 @@
 # @blockdev-snapshot-internal-sync: Since 1.7
 # @blockdev-snapshot-sync: since 1.1
 # @drive-backup: Since 1.6
+# @blockdev-add: since 7.0
 #
 # Features:
 # @deprecated: Member @drive-backup is deprecated.  Use member
@@ -66,6 +67,7 @@
             'block-dirty-bitmap-disable', 'block-dirty-bitmap-merge',
             'blockdev-backup', 'blockdev-snapshot',
             'blockdev-snapshot-internal-sync', 'blockdev-snapshot-sync',
+            'blockdev-add',
             { 'name': 'drive-backup', 'features': [ 'deprecated' ] } ] }
 
 ##
@@ -140,6 +142,14 @@
 { 'struct': 'DriveBackupWrapper',
   'data': { 'data': 'DriveBackup' } }
 
+##
+# @BlockdevAddWrapper:
+#
+# Since: 7.0
+##
+{ 'struct': 'BlockdevAddWrapper',
+  'data': { 'data': 'BlockdevOptions' } }
+
 ##
 # @TransactionAction:
 #
@@ -163,6 +173,7 @@
        'blockdev-snapshot': 'BlockdevSnapshotWrapper',
        'blockdev-snapshot-internal-sync': 'BlockdevSnapshotInternalWrapper',
        'blockdev-snapshot-sync': 'BlockdevSnapshotSyncWrapper',
+       'blockdev-add': 'BlockdevAddWrapper',
        'drive-backup': 'DriveBackupWrapper'
    } }
 
blockdev.c +55 -25

98 lines not on this page · raw message

Signature · 1 line
2.31.1
#2 lore raw

PATCH 2/2 iotests: add blockdev-add-transaction

In reply to Vladimir Sementsov-Ogievskiy

Add a test for transaction support of blockdev-add.

Test is format-agnostic, so limit it to qcow2 to avoid extra test runs.

---
 .../tests/blockdev-add-transaction            | 52 +++++++++++++++++++
 .../tests/blockdev-add-transaction.out        |  6 +++
 2 files changed, 58 insertions(+)
 create mode 100755 tests/qemu-iotests/tests/blockdev-add-transaction
 create mode 100644 tests/qemu-iotests/tests/blockdev-add-transaction.out
tests/qemu-iotests/tests/blockdev-add-transaction new file +52 -0
new file mode 100755
index 0000000000..ce3c1c069b
@@ -0,0 +1,52 @@
+#!/usr/bin/env python3
+#
+# Test blockdev-add transaction action
+#
+# 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 iotests
+from iotests import log
+
+iotests.script_initialize(supported_fmts=['qcow2'])
+
+with iotests.VM() as vm:
+    vm.launch()
+
+    # Use same node-name for nodes, neither one should appear.
+    vm.qmp_log('transaction', actions=[
+        {'type': 'blockdev-add',
+         'data': {'node-name': 'node0', 'driver': 'null-co',
+                  'size': 1024 * 1024}},
+        {'type': 'blockdev-add',
+         'data': {'node-name': 'node0', 'driver': 'null-co',
+                  'size': 1024 * 1024}}
+    ])
+
+    n = len(vm.qmp('query-named-block-nodes')['return'])
+    log(f'Created {n} nodes')
+
+    vm.qmp_log('transaction', actions=[
+        {'type': 'blockdev-add',
+         'data': {'node-name': 'node0', 'driver': 'null-co',
+                  'size': 1024 * 1024}},
+        {'type': 'blockdev-add',
+         'data': {'node-name': 'node1', 'driver': 'null-co',
+                  'size': 1024 * 1024}}
+    ])
+
+    n = len(vm.qmp('query-named-block-nodes')['return'])
+    log(f'Created {n} nodes')
tests/qemu-iotests/tests/blockdev-add-transaction.out new file +6 -0
new file mode 100644
index 0000000000..7e6cd5a9a3
@@ -0,0 +1,6 @@
+{"execute": "transaction", "arguments": {"actions": [{"data": {"driver": "null-co", "node-name": "node0", "size": 1048576}, "type": "blockdev-add"}, {"data": {"driver": "null-co", "node-name": "node0", "size": 1048576}, "type": "blockdev-add"}]}}
+{"error": {"class": "GenericError", "desc": "Duplicate nodes with node-name='node0'"}}
+Created 0 nodes
+{"execute": "transaction", "arguments": {"actions": [{"data": {"driver": "null-co", "node-name": "node0", "size": 1048576}, "type": "blockdev-add"}, {"data": {"driver": "null-co", "node-name": "node1", "size": 1048576}, "type": "blockdev-add"}]}}
+{"return": {}}
+Created 2 nodes
Signature · 1 line
2.31.1