block: Managing inactive nodes (QSD migration)
cover block: Managing inactive nodes (QSD migration)
This series adds a mechanism that allows the user or management tool to manually activate and inactivate block nodes instead of fully relying on the automatic management in the migration code.
One case where this is needed is for migration with shared storage and devices backed by qemu-storage-daemon, which as an external process is not involved in the VM migration. Management tools can manually orchestrate the handover in this scenario. The new qemu-iotests case qsd-migrate demonstrates this.
There are other cases without qemu-storage-daemon where manual management is necessary. For example, after migration, the destination VM only activates images on 'cont', but after migrating a paused VM, the user may want to perform operations on a block node while the VM is still paused.
This series adds support for block exports on an inactive node (needed for shared storage migration with qemu-storage-daemon) only to NBD. Adding it to other export types will be done in a future series.
Kevin Wolf (9):
block: Allow inactivating already inactive nodes
block: Add option to create inactive nodes
block: Support inactive nodes in blk_insert_bs() block/export: Don't ignore image activation error in blk_exp_add() block/export: Add option to allow export of inactive nodes nbd/server: Support inactive nodes
block: Add blockdev-set-active QMP command
iotests: Add filter_qtest()
iotests: Add qsd-migrate case
qapi/block-core.json | 38 +++++ qapi/block-export.json | 10 +- include/block/block-common.h | 1 + include/block/block-global-state.h | 6 + include/block/export.h | 3 + block.c | 50 ++++++- block/block-backend.c | 14 +- block/export/export.c | 29 +++- blockdev.c | 32 +++++ nbd/server.c | 17 +++ tests/qemu-iotests/iotests.py | 4 + tests/qemu-iotests/041 | 4 +- tests/qemu-iotests/165 | 4 +- tests/qemu-iotests/tests/copy-before-write | 3 +- tests/qemu-iotests/tests/migrate-bitmaps-test | 7 +- tests/qemu-iotests/tests/qsd-migrate | 132 ++++++++++++++++++ tests/qemu-iotests/tests/qsd-migrate.out | 51 +++++++ 17 files changed, 379 insertions(+), 26 deletions(-) create mode 100755 tests/qemu-iotests/tests/qsd-migrate create mode 100644 tests/qemu-iotests/tests/qsd-migrate.out
Signature · 1 line
2.48.1
PATCH 6/9 nbd/server: Support inactive nodes
In order to support running an NBD export on inactive nodes, we must make sure to return errors for any operations that aren't allowed on inactive nodes. Reads are the only operation we know we need for inactive images, so to err on the side of caution, return errors for everything else, even if some operations could possibly be okay.
--- nbd/server.c | 17 +++++++++++++++++ 1 file changed, 17 insertions(+)
nbd/server.c +17 -0
@@ -2026,6 +2026,7 @@ static void nbd_export_delete(BlockExport *blk_exp)const BlockExportDriver blk_exp_nbd = { .type =BLOCK_EXPORT_TYPE_NBD , .instance_size =sizeof (NBDExport), + .supports_inactive = true, .create = nbd_export_create, .delete = nbd_export_delete, .request_shutdown = nbd_export_request_shutdown,
@@ -2920,6 +2921,22 @@ static coroutine_fn int nbd_handle_request(NBDClient *client,NBDExport *exp = client->exp;char *msg;size_t i; +bool inactive; + + WITH_GRAPH_RDLOCK_GUARD() { + inactive =bdrv_is_inactive (blk_bs (exp->common.blk)); +if (inactive) { +switch (request->type) { +case NBD_CMD_READ : +/* These commands are allowed on inactive nodes */ +break ; +default : +/* Return an error for the rest */ +return nbd_send_generic_reply (client, request, -EPERM , +"export is inactive" , errp); + } + } + }switch (request->type) {case NBD_CMD_CACHE :
Signature · 1 line
2.48.1
PATCH 9/9 iotests: Add qsd-migrate case
In reply to Kevin WolfTest that it's possible to migrate a VM that uses an image on shared storage through qemu-storage-daemon.
--- tests/qemu-iotests/tests/qsd-migrate | 132 +++++++++++++++++++++++ tests/qemu-iotests/tests/qsd-migrate.out | 51 +++++++++ 2 files changed, 183 insertions(+) create mode 100755 tests/qemu-iotests/tests/qsd-migrate create mode 100644 tests/qemu-iotests/tests/qsd-migrate.out
tests/qemu-iotests/tests/qsd-migrate new file +132 -0
@@ -0,0 +1,132 @@ +#!/usr/bin/env python3 +# group: rw quick +# +# Copyright (C) Red Hat, Inc. +# +# 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/>. +# +# Creator/Owner: Kevin Wolf <[email protected]> + +import iotests + +from iotests import filter_qemu_io, filter_qtest + +iotests.script_initialize(supported_fmts=['generic'], + supported_protocols=['file'], + supported_platforms=['linux']) + +with iotests.FilePath('disk.img') as path, \ + iotests.FilePath('nbd-src.sock', base_dir=iotests.sock_dir) as nbd_src, \ + iotests.FilePath('nbd-dst.sock', base_dir=iotests.sock_dir) as nbd_dst, \ + iotests.FilePath('migrate.sock', base_dir=iotests.sock_dir) as mig_sock, \ + iotests.VM(path_suffix="-src") as vm_src, \ + iotests.VM(path_suffix="-dst") as vm_dst: + + img_size = '10M' + + iotests.log('Preparing disk...') + iotests.qemu_img_create('-f', iotests.imgfmt, path, img_size) + + iotests.log('Launching source QSD...') + qsd_src = iotests.QemuStorageDaemon( + '--blockdev', f'file,node-name=disk-file,filename={path}', + '--blockdev', f'{iotests.imgfmt},file=disk-file,node-name=disk-fmt', + '--nbd-server', f'addr.type=unix,addr.path={nbd_src}', + '--export', 'nbd,id=exp0,node-name=disk-fmt,writable=true,' + 'allow-inactive=true', + qmp=True, + ) + + iotests.log('Launching source VM...') + vm_src.add_args('-blockdev', f'nbd,node-name=disk,server.type=unix,' + f'server.path={nbd_src},export=disk-fmt') + vm_src.add_args('-device', 'virtio-blk,drive=disk,id=virtio0') + vm_src.launch() + + iotests.log('Launching destination QSD...') + qsd_dst = iotests.QemuStorageDaemon( + '--blockdev', f'file,node-name=disk-file,filename={path},active=off', + '--blockdev', f'{iotests.imgfmt},file=disk-file,node-name=disk-fmt,' + f'active=off', + '--nbd-server', f'addr.type=unix,addr.path={nbd_dst}', + '--export', 'nbd,id=exp0,node-name=disk-fmt,writable=true,' + 'allow-inactive=true', + qmp=True, + instance_id='b', + ) + + iotests.log('Launching destination VM...') + vm_dst.add_args('-blockdev', f'nbd,node-name=disk,server.type=unix,' + f'server.path={nbd_dst},export=disk-fmt') + vm_dst.add_args('-device', 'virtio-blk,drive=disk,id=virtio0') + vm_dst.add_args('-incoming', f'unix:{mig_sock}') + vm_dst.launch() + + iotests.log('\nTest I/O on the source') + vm_src.hmp_qemu_io('virtio0/virtio-backend', 'write -P 0x11 0 4k', + use_log=True, qdev=True) + vm_src.hmp_qemu_io('virtio0/virtio-backend', 'read -P 0x11 0 4k', + use_log=True, qdev=True) + + iotests.log('\nStarting migration...') + + mig_caps = [ + {'capability': 'events', 'state': True}, + {'capability': 'pause-before-switchover', 'state': True}, + ] + vm_src.qmp_log('migrate-set-capabilities', capabilities=mig_caps) + vm_dst.qmp_log('migrate-set-capabilities', capabilities=mig_caps) + vm_src.qmp_log('migrate', uri=f'unix:{mig_sock}', + filters=[iotests.filter_qmp_testfiles]) + + vm_src.event_wait('MIGRATION', + match={'data': {'status': 'pre-switchover'}}) + + iotests.log('\nPre-switchover: Reconfigure QSD instances') + + iotests.log(qsd_src.qmp('blockdev-set-active', {'active': False})) + iotests.log(qsd_dst.qmp('blockdev-set-active', {'active': True})) + + iotests.log('\nCompleting migration...') + + vm_src.qmp_log('migrate-continue', state='pre-switchover') + vm_dst.event_wait('MIGRATION', match={'data': {'status': 'completed'}}) + + iotests.log('\nTest I/O on the destination') + + # Now the destination must see what the source wrote + vm_dst.hmp_qemu_io('virtio0/virtio-backend', 'read -P 0x11 0 4k', + use_log=True, qdev=True) + + # And be able to overwrite it + vm_dst.hmp_qemu_io('virtio0/virtio-backend', 'write -P 0x22 0 4k', + use_log=True, qdev=True) + vm_dst.hmp_qemu_io('virtio0/virtio-backend', 'read -P 0x22 0 4k', + use_log=True, qdev=True) + + iotests.log('\nDone') + + vm_src.shutdown() + iotests.log('\n--- vm_src log ---') + log = vm_src.get_log() + if log: + iotests.log(log, [filter_qtest, filter_qemu_io]) + qsd_src.stop() + + vm_dst.shutdown() + iotests.log('\n--- vm_dst log ---') + log = vm_dst.get_log() + if log: + iotests.log(log, [filter_qtest, filter_qemu_io]) + qsd_dst.stop()
tests/qemu-iotests/tests/qsd-migrate.out new file +51 -0
51 lines not on this page · raw message
Signature · 1 line
2.48.1
PATCH 4/9 block/export: Don't ignore image activation error in blk_exp_add()
In reply to Kevin WolfCurrently, block jobs can't handle inactive images correctly. Incoming write requests would run into assertion failures. Make sure that we return an error when creating an export can't activate the image.
--- block/export/export.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-)
block/export/export.c +5 -1
@@ -145,7 +145,11 @@ BlockExport *blk_exp_add(BlockExportOptions *export, Error **errp)* ctx was acquired in the caller. */ bdrv_graph_rdlock_main_loop (); -bdrv_activate (bs,NULL ); + ret =bdrv_activate (bs, errp); +if (ret <0 ) { +bdrv_graph_rdunlock_main_loop (); + goto fail; + }bdrv_graph_rdunlock_main_loop (); perm =BLK_PERM_CONSISTENT_READ ;
Signature · 1 line
2.48.1
PATCH 8/9 iotests: Add filter_qtest()
In reply to Kevin WolfThe open-coded form of this filter has been copied into enough tests that it's better to move it into iotests.py.
--- tests/qemu-iotests/iotests.py | 4 ++++ tests/qemu-iotests/041 | 4 +--- tests/qemu-iotests/165 | 4 +--- tests/qemu-iotests/tests/copy-before-write | 3 +-- tests/qemu-iotests/tests/migrate-bitmaps-test | 7 +++---- 5 files changed, 10 insertions(+), 12 deletions(-)
tests/qemu-iotests/iotests.py +4 -0
@@ -701,6 +701,10 @@ def _filter(_key, value): def filter_nbd_exports(output: str) -> str: return re.sub(r'((min|opt|max) block): [0-9]+', r'\1: XXX', output) +def filter_qtest(output: str) -> str: + output = re.sub(r'^\[I \d+\.\d+\] OPENED\n', '', output) + output = re.sub(r'\n?\[I \+\d+\.\d+\] CLOSED\n?$', '', output) + return output Msg = TypeVar('Msg', Dict[str, Any], List[Any], str)
tests/qemu-iotests/041 +1 -3
@@ -1100,10 +1100,8 @@ class TestRepairQuorum(iotests.QMPTestCase): # Check the full error message now self.vm.shutdown() - log = self.vm.get_log() - log = re.sub(r'^\[I \d+\.\d+\] OPENED\n', '', log) + log = iotests.filter_qtest(self.vm.get_log()) log = re.sub(r'^Formatting.*\n', '', log) - log = re.sub(r'\n\[I \+\d+\.\d+\] CLOSED\n?$', '', log) log = re.sub(r'^%s: ' % os.path.basename(iotests.qemu_prog), '', log) self.assertEqual(log,
tests/qemu-iotests/165 +1 -3
@@ -82,9 +82,7 @@ class TestPersistentDirtyBitmap(iotests.QMPTestCase): self.vm.shutdown() #catch 'Persistent bitmaps are lost' possible error - log = self.vm.get_log() - log = re.sub(r'^\[I \d+\.\d+\] OPENED\n', '', log) - log = re.sub(r'\[I \+\d+\.\d+\] CLOSED\n?$', '', log) + log = iotests.filter_qtest(self.vm.get_log()) if log: print(log)
tests/qemu-iotests/tests/copy-before-write +1 -2
@@ -95,8 +95,7 @@ class TestCbwError(iotests.QMPTestCase): self.vm.shutdown() log = self.vm.get_log() - log = re.sub(r'^\[I \d+\.\d+\] OPENED\n', '', log) - log = re.sub(r'\[I \+\d+\.\d+\] CLOSED\n?$', '', log) + log = iotests.filter_qtest(log) log = iotests.filter_qemu_io(log) return log
tests/qemu-iotests/tests/migrate-bitmaps-test +3 -4
@@ -122,11 +122,10 @@ class TestDirtyBitmapMigration(iotests.QMPTestCase): # catch 'Could not reopen qcow2 layer: Bitmap already exists' # possible error - log = self.vm_a.get_log() - log = re.sub(r'^\[I \d+\.\d+\] OPENED\n', '', log) - log = re.sub(r'^(wrote .* bytes at offset .*\n.*KiB.*ops.*sec.*\n){3}', + log = iotests.filter_qtest(self.vm_a.get_log()) + log = re.sub(r'^(wrote .* bytes at offset .*\n' + r'.*KiB.*ops.*sec.*\n?){3}', '', log) - log = re.sub(r'\[I \+\d+\.\d+\] CLOSED\n?$', '', log) self.assertEqual(log, '') # test that bitmap is still persistent
Signature · 1 line
2.48.1
PATCH 1/9 block: Allow inactivating already inactive nodes
In reply to Kevin WolfWhat we wanted to catch with the assertion is cases where the recursion finds that a child was inactive before its parent. This should never happen. But if the user tries to inactivate an image that is already inactive, that's harmless and we don't want to fail the assertion.
--- block.c | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-)
block.c +12 -4
@@ -6955,7 +6955,8 @@ bdrv_has_bds_parent(BlockDriverState *bs, bool only_active)return false; } -static int GRAPH_RDLOCK bdrv_inactivate_recurse(BlockDriverState *bs) +static int GRAPH_RDLOCK +bdrv_inactivate_recurse (BlockDriverState *bs,bool top_level) {BdrvChild *child, *parent;int ret;
@@ -6973,7 +6974,14 @@ static int GRAPH_RDLOCK bdrv_inactivate_recurse(BlockDriverState *bs)return 0 ; } -assert (!(bs->open_flags &BDRV_O_INACTIVE )); +/* +* Inactivating an already inactive node on user request is harmless, but if +* a child is already inactive before its parent, that's bad. +*/ +if (bs->open_flags &BDRV_O_INACTIVE ) { +assert (top_level); +return 0 ; + }/* Inactivate this node */ if (bs->drv->bdrv_inactivate) {
@@ -7010,7 +7018,7 @@ static int GRAPH_RDLOCK bdrv_inactivate_recurse(BlockDriverState *bs)/* Recursively inactivate children */ QLIST_FOREACH(child, &bs->children, next) { - ret =bdrv_inactivate_recurse (child->bs); + ret =bdrv_inactivate_recurse (child->bs, false);if (ret <0 ) {return ret; }
@@ -7035,7 +7043,7 @@ int bdrv_inactivate_all(void)if (bdrv_has_bds_parent (bs, false)) {continue ; } - ret =bdrv_inactivate_recurse (bs); + ret =bdrv_inactivate_recurse (bs, true);if (ret <0 ) {bdrv_next_cleanup (&it);break ;
Signature · 1 line
2.48.1
PATCH 3/9 block: Support inactive nodes in blk_insert_bs()
In reply to Kevin WolfDevice models have a relatively complex way to set up their block backends, in which blk_attach_dev() sets blk->disable_perm = true. We want to support inactive images in exports, too, so that qemu-storage-daemon can be used with migration. Because they don't use blk_attach_dev(), they need another way to set this flag. The most convenient is to do this automatically when an inactive node is attached to a BlockBackend.
--- block/block-backend.c | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-)
block/block-backend.c +12 -2
@@ -900,14 +900,24 @@ void blk_remove_bs(BlockBackend *blk)int blk_insert_bs (BlockBackend *blk,BlockDriverState *bs,Error **errp) {ThrottleGroupMember *tgm = &blk->public.throttle_group_member; +uint64_t perm, shared_perm;GLOBAL_STATE_CODE ();bdrv_ref (bs);bdrv_graph_wrlock (); + +if (bs->open_flags &BDRV_O_INACTIVE ) { + blk->disable_perm = true; + perm =0 ; + shared_perm =BLK_PERM_ALL ; + }else { + perm = blk->perm; + shared_perm = blk->shared_perm; + } + blk->root =bdrv_root_attach_child (bs,"root" , &child_root,BDRV_CHILD_FILTERED |BDRV_CHILD_PRIMARY , - blk->perm, blk->shared_perm, - blk, errp); + perm, shared_perm, blk, errp);bdrv_graph_wrunlock ();if (blk->root ==NULL ) {return -EPERM ;
Signature · 1 line
2.48.1
PATCH 2/9 block: Add option to create inactive nodes
In reply to Kevin WolfIn QEMU, nodes are automatically created inactive while expecting an incoming migration (i.e. RUN_STATE_INMIGRATE). In qemu-storage-daemon, the notion of runstates doesn't exist. It also wouldn't necessarily make sense to introduce it because a single daemon can serve multiple VMs that can be in different states.
Therefore, allow the user to explicitly open images as inactive with a new option. The default is as before: Nodes are usually active, except when created during RUN_STATE_INMIGRATE.
--- qapi/block-core.json | 6 ++++++ include/block/block-common.h | 1 + block.c | 9 +++++++++ 3 files changed, 16 insertions(+)
qapi/block-core.json +6 -0
@@ -4679,6 +4679,11 @@ # # @cache: cache-related options # +# @active: whether the block node should be activated (default: true). +# Having inactive block nodes is useful primarily for migration because it +# allows opening an image on the destination while the source is still +# holding locks for it. (Since 10.0) +# # @read-only: whether the block device should be read-only (default: # false). Note that some block drivers support only read-only # access, either generally or in certain configurations. In this
@@ -4705,6 +4710,7 @@ '*node-name': 'str', '*discard': 'BlockdevDiscardOptions', '*cache': 'BlockdevCacheOptions', + '*active': 'bool', '*read-only': 'bool', '*auto-read-only': 'bool', '*force-share': 'bool',
include/block/block-common.h +1 -0
@@ -257,6 +257,7 @@ typedef enum {#define BDRV_OPT_AUTO_READ_ONLY "auto-read-only"#define BDRV_OPT_DISCARD "discard"#define BDRV_OPT_FORCE_SHARE "force-share" +#define BDRV_OPT_ACTIVE "active"#define BDRV_SECTOR_BITS 9
block.c +9 -0
@@ -1573,6 +1573,10 @@ static void update_flags_from_options(int *flags, QemuOpts *opts)if (qemu_opt_get_bool_del (opts,BDRV_OPT_AUTO_READ_ONLY , false)) { *flags |=BDRV_O_AUTO_RDONLY ; } + +if (!qemu_opt_get_bool_del (opts,BDRV_OPT_ACTIVE , true)) { + *flags |=BDRV_O_INACTIVE ; + } }static void update_options_from_flags (QDict *options,int flags)
@@ -1799,6 +1803,11 @@ QemuOptsList bdrv_runtime_opts = { .type = QEMU_OPT_BOOL, .help = "Ignore flush requests", }, + { + .name = BDRV_OPT_ACTIVE, + .type = QEMU_OPT_BOOL, + .help = "Node is activated", + }, { .name = BDRV_OPT_READ_ONLY, .type = QEMU_OPT_BOOL,
Signature · 1 line
2.48.1
PATCH 7/9 block: Add blockdev-set-active QMP command
In reply to Kevin WolfThe system emulator tries to automatically activate and inactivate block nodes at the right point during migration. However, there are still cases where it's necessary that the user can do this manually.
Images are only activated on the destination VM of a migration when the VM is actually resumed. If the VM was paused, this doesn't happen automatically. The user may want to perform some operation on a block device (e.g. taking a snapshot or starting a block job) without also resuming the VM yet. This is an example where a manual command is necessary.
Another example is VM migration when the image files are opened by an external qemu-storage-daemon instance on each side. In this case, the process that needs to hand over the images isn't even part of the migration and can't know when the migration completes. Management tools need a way to explicitly inactivate images on the source and activate them on the destination.
This adds a new blockdev-set-active QMP command that lets the user change the status of individual nodes (this is necessary in qemu-storage-daemon because it could be serving multiple VMs and only one of them migrates at a time). For convenience, operating on all devices (like QEMU does automatically during migration) is offered as an option, too, and can be used in the context of single VM.
--- qapi/block-core.json | 32 ++++++++++++++++++++++++++++++ include/block/block-global-state.h | 3 +++ block.c | 21 ++++++++++++++++++++ blockdev.c | 32 ++++++++++++++++++++++++++++++ 4 files changed, 88 insertions(+)
qapi/block-core.json +32 -0
@@ -4941,6 +4941,38 @@ { 'command': 'blockdev-del', 'data': { 'node-name': 'str' }, 'allow-preconfig': true } +## +# @blockdev-set-active: +# +# Activate or inactive a block device. Use this to manage the handover of block +# devices on migration with qemu-storage-daemon. +# +# Activating a node automatically activates all of its child nodes first. +# Inactivating a node automatically inactivates any of its child nodes that are +# not in use by a still active node. +# +# @node-name: Name of the graph node to activate or inactivate. By default, all +# nodes are affected by the operation. +# +# @active: true if the nodes should be active when the command returns success, +# false if they should be inactive. +# +# Since: 10.0 +# +# .. qmp-example:: +# +# -> { "execute": "blockdev-set-active", +# "arguments": { +# "node-name": "node0", +# "active": false +# } +# } +# <- { "return": {} } +## +{ 'command': 'blockdev-set-active', + 'data': { '*node-name': 'str', 'active': 'bool' }, + 'allow-preconfig': true } + ## # @BlockdevCreateOptionsFile: #
include/block/block-global-state.h +3 -0
@@ -184,6 +184,9 @@ bdrv_activate(BlockDriverState *bs, Error **errp); int coroutine_fn no_co_wrapper_bdrv_rdlockbdrv_co_activate (BlockDriverState *bs,Error **errp); +int no_coroutine_fn +bdrv_inactivate (BlockDriverState *bs, Error **errp); +void bdrv_activate_all (Error **errp);int bdrv_inactivate_all (void );
block.c +21 -0
@@ -7040,6 +7040,27 @@ bdrv_inactivate_recurse(BlockDriverState *bs, bool top_level)return 0 ; } +int bdrv_inactivate (BlockDriverState *bs,Error **errp) +{ +int ret; + +GLOBAL_STATE_CODE (); +GRAPH_RDLOCK_GUARD_MAINLOOP (); + +if (bdrv_has_bds_parent (bs, true)) { +error_setg (errp,"Node has active parent node" ); +return -EPERM ; + } + + ret =bdrv_inactivate_recurse (bs, true); +if (ret <0 ) { +error_setg_errno (errp, -ret,"Failed to inactivate node" ); +return ret; + } + +return 0 ; +} +int bdrv_inactivate_all (void ) {BlockDriverState *bs =NULL ;
blockdev.c +32 -0
@@ -3455,6 +3455,38 @@ void qmp_blockdev_del(const char *node_name, Error **errp)bdrv_unref (bs); } +void qmp_blockdev_set_active (const char *node_name,bool active,Error **errp) +{ +int ret; + +GLOBAL_STATE_CODE (); +GRAPH_RDLOCK_GUARD_MAINLOOP (); + +if (!node_name) { +if (active) { +bdrv_activate_all (errp); + }else { + ret =bdrv_inactivate_all (); +if (ret <0 ) { +error_setg_errno (errp, -ret,"Failed to inactivate all nodes" ); + } + } + }else { +BlockDriverState *bs =bdrv_find_node (node_name); +if (!bs) { +error_setg (errp,"Failed to find node with node-name='%s'" , + node_name); +return ; + } + +if (active) { +bdrv_activate (bs, errp); + }else { +bdrv_inactivate (bs, errp); + } + } +} + static BdrvChild * GRAPH_RDLOCKbdrv_find_child (BlockDriverState *parent_bs,const char *child_name) {
Signature · 1 line
2.48.1
PATCH 5/9 block/export: Add option to allow export of inactive nodes
In reply to Kevin WolfAdd an option in BlockExportOptions to allow creating an export on an inactive node without activating the node. This mode needs to be explicitly supported by the export type (so that it doesn't perform any operations that are forbidden for inactive nodes), so this patch alone doesn't allow this option to be successfully used yet.
--- qapi/block-export.json | 10 +++++++++- include/block/block-global-state.h | 3 +++ include/block/export.h | 3 +++ block.c | 4 ++++ block/export/export.c | 31 ++++++++++++++++++++---------- 5 files changed, 40 insertions(+), 11 deletions(-)
qapi/block-export.json +9 -1
@@ -372,6 +372,13 @@ # cannot be moved to the iothread. The default is false. # (since: 5.2) # +# @allow-inactive: If true, the export allows the exported node to be inactive. +# If it is created for an inactive block node, the node remains inactive. If +# the export type doesn't support running on an inactive node, an error is +# returned. If false, inactive block nodes are automatically activated before +# creating the export and trying to inactivate them later fails. +# (since: 10.0; default: false) +# # Since: 4.2 ## { 'union': 'BlockExportOptions',
@@ -381,7 +388,8 @@ '*iothread': 'str', 'node-name': 'str', '*writable': 'bool', - '*writethrough': 'bool' }, + '*writethrough': 'bool', + '*allow-inactive': 'bool' }, 'discriminator': 'type', 'data': { 'nbd': 'BlockExportOptionsNbd',
include/block/block-global-state.h +3 -0
@@ -175,6 +175,9 @@ BlockDriverState * GRAPH_RDLOCK check_to_replace_node(BlockDriverState *parent_bs, const char *node_name, Error **errp); + +bool GRAPH_RDLOCK bdrv_is_inactive(BlockDriverState *bs); + int no_coroutine_fn GRAPH_RDLOCKbdrv_activate (BlockDriverState *bs,Error **errp);
include/block/export.h +3 -0
@@ -29,6 +29,9 @@ typedef struct BlockExportDriver {*/ size_t instance_size; +/* True if the export type supports running on an inactive node */ +bool supports_inactive; +/* Creates and starts a new block export */ int (*create)(BlockExport *,BlockExportOptions *,Error **);
block.c +4 -0
@@ -6833,6 +6833,10 @@ void bdrv_init_with_whitelist(void)bdrv_init (); } +bool bdrv_is_inactive (BlockDriverState *bs) { +return bs->open_flags &BDRV_O_INACTIVE ; +} +int bdrv_activate (BlockDriverState *bs,Error **errp) {BdrvChild *child, *parent;
block/export/export.c +21 -10
@@ -75,6 +75,7 @@ static const BlockExportDriver *blk_exp_find_driver(BlockExportType type)BlockExport *blk_exp_add (BlockExportOptions *export,Error **errp) {bool fixed_iothread = export->has_fixed_iothread && export->fixed_iothread; +bool allow_inactive = export->has_allow_inactive && export->allow_inactive;const BlockExportDriver *drv;BlockExport *exp =NULL ;BlockDriverState *bs;
@@ -138,17 +139,24 @@ BlockExport *blk_exp_add(BlockExportOptions *export, Error **errp) } } -/* -* Block exports are used for non-shared storage migration. Make sure -* that BDRV_O_INACTIVE is cleared and the image is ready for write -* access since the export could be available before migration handover. -* ctx was acquired in the caller. -*/ bdrv_graph_rdlock_main_loop (); - ret =bdrv_activate (bs, errp); -if (ret <0 ) { -bdrv_graph_rdunlock_main_loop (); - goto fail; +if (allow_inactive) { +if (!drv->supports_inactive) { +error_setg (errp,"Export type does not support inactive exports" ); +bdrv_graph_rdunlock_main_loop (); + goto fail; + } + }else { +/* +* Block exports are used for non-shared storage migration. Make sure +* that BDRV_O_INACTIVE is cleared and the image is ready for write +* access since the export could be available before migration handover. +*/ + ret =bdrv_activate (bs, errp); +if (ret <0 ) { +bdrv_graph_rdunlock_main_loop (); + goto fail; + } }bdrv_graph_rdunlock_main_loop ();
@@ -162,6 +170,9 @@ BlockExport *blk_exp_add(BlockExportOptions *export, Error **errp)if (!fixed_iothread) {blk_set_allow_aio_context_change (blk, true); } +if (allow_inactive) { +blk_set_force_allow_inactivate (blk); + } ret =blk_insert_bs (blk, bs, errp);if (ret <0 ) {
Signature · 1 line
2.48.1
Re: [PATCH 1/9] block: Allow inactivating already inactive nodes
In reply to Kevin WolfQuoted 9 lines · Kevin Wolf
What we wanted to catch with the assertion is cases where the recursion finds that a child was inactive before its parent. This should never happen. But if the user tries to inactivate an image that is already inactive, that's harmless and we don't want to fail the assertion.
Signed-off-by Kevin Wolf <[email protected]>--- block.c | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-)
Signature · 3 lines
Eric Blake, Principal Software Engineer Red Hat, Inc. Virtualization: qemu.org | libguestfs.org
Re: [PATCH 2/9] block: Add option to create inactive nodes
In reply to Kevin WolfQuoted 10 lines · Kevin Wolf
In QEMU, nodes are automatically created inactive while expecting an incoming migration (i.e.
RUN_STATE_INMIGRATE). In qemu-storage-daemon, the notion of runstates doesn't exist. It also wouldn't necessarily make sense to introduce it because a single daemon can serve multiple VMs that can be in different states.Therefore, allow the user to explicitly open images as inactive with a new option. The default is as before: Nodes are usually active, except when created during
RUN_STATE_INMIGRATE.
Quoted 6 lines
Signed-off-by Kevin Wolf <[email protected]>--- qapi/block-core.json | 6 ++++++ include/block/block-common.h | 1 + block.c | 9 +++++++++ 3 files changed, 16 insertions(+)
Signature · 3 lines
Eric Blake, Principal Software Engineer Red Hat, Inc. Virtualization: qemu.org | libguestfs.org
Re: [PATCH 3/9] block: Support inactive nodes in blk_insert_bs()
In reply to Kevin WolfQuoted 8 lines · Kevin Wolf
Device models have a relatively complex way to set up their block backends, in which
blk_attach_dev()setsblk->disable_perm= true. We want to support inactive images in exports, too, so that qemu-storage-daemon can be used with migration. Because they don't useblk_attach_dev(), they need another way to set this flag. The most convenient is to do this automatically when an inactive node is attached to a BlockBackend.
Quoted 4 lines
Signed-off-by Kevin Wolf <[email protected]>--- block/block-backend.c | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-)
Signature · 3 lines
Eric Blake, Principal Software Engineer Red Hat, Inc. Virtualization: qemu.org | libguestfs.org
Re: [PATCH 4/9] block/export: Don't ignore image activation error in blk_exp_add()
In reply to Kevin WolfQuoted 8 lines · Kevin Wolf
Currently, block jobs can't handle inactive images correctly. Incoming write requests would run into assertion failures. Make sure that we return an error when creating an export can't activate the image.
Signed-off-by Kevin Wolf <[email protected]>--- block/export/export.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-)
Signature · 3 lines
Eric Blake, Principal Software Engineer Red Hat, Inc. Virtualization: qemu.org | libguestfs.org
Re: [PATCH 5/9] block/export: Add option to allow export of inactive nodes
In reply to Kevin WolfQuoted 6 lines · Kevin Wolf
Add an option in BlockExportOptions to allow creating an export on an inactive node without activating the node. This mode needs to be explicitly supported by the export type (so that it doesn't perform any operations that are forbidden for inactive nodes), so this patch alone doesn't allow this option to be successfully used yet.
Quoted 9 lines
Signed-off-by Kevin Wolf <[email protected]>--- qapi/block-export.json | 10 +++++++++- include/block/block-global-state.h | 3 +++ include/block/export.h | 3 +++ block.c | 4 ++++ block/export/export.c | 31 ++++++++++++++++++++---------- 5 files changed, 40 insertions(+), 11 deletions(-)
Signature · 3 lines
Eric Blake, Principal Software Engineer Red Hat, Inc. Virtualization: qemu.org | libguestfs.org
Quoted 20 lines · Kevin Wolf
This series adds a mechanism that allows the user or management tool to manually activate and inactivate block nodes instead of fully relying on the automatic management in the migration code.
One case where this is needed is for migration with shared storage and devices backed by qemu-storage-daemon, which as an external process is not involved in the VM migration. Management tools can manually orchestrate the handover in this scenario. The new qemu-iotests case qsd-migrate demonstrates this.
There are other cases without qemu-storage-daemon where manual management is necessary. For example, after migration, the destination VM only activates images on 'cont', but after migrating a paused VM, the user may want to perform operations on a block node while the VM is still paused.
This series adds support for block exports on an inactive node (needed for shared storage migration with qemu-storage-daemon) only to NBD. Adding it to other export types will be done in a future series.
Quoted 10 lines
Kevin Wolf (9):
block: Allow inactivating already inactive nodes
block: Add option to create inactive nodes
block: Support inactive nodes inblk_insert_bs()block/export: Don't ignore image activation error inblk_exp_add()block/export: Add option to allow export of inactive nodes nbd/server: Support inactive nodes
block: Add blockdev-set-active QMP command
iotests: Addfilter_qtest()
iotests: Add qsd-migrate case
I started reviewing this, but see v2 now, so I'll resume my review there.
Signature · 3 lines
Eric Blake, Principal Software Engineer Red Hat, Inc. Virtualization: qemu.org | libguestfs.org
Re: [PATCH 6/9] nbd/server: Support inactive nodes
In reply to Kevin WolfQuoted 5 lines · Kevin Wolf
In order to support running an NBD export on inactive nodes, we must make sure to return errors for any operations that aren't allowed on inactive nodes. Reads are the only operation we know we need for inactive images, so to err on the side of caution, return errors for everything else, even if some operations could possibly be okay.
Block status might be the only other command I could see being needed, but I also agree with the approach of not supporting it until we have a use case in mind (if ever).
Quoted 8 lines
Signed-off-by Kevin Wolf <[email protected]>--- nbd/server.c | 17 +++++++++++++++++ 1 file changed, 17 insertions(+)
nbd/server.c static coroutine_fn int nbd_handle_request(NBDClient *client, · line 2927
Quoted 7 lines
nbd/server.c +4
-0@@ -2920,6 +2921,22 @@ static coroutine_fn int nbd_handle_request(NBDClient *client,NBDExport *exp = client->exp;char *msg;size_t i; +bool inactive; + + WITH_GRAPH_RDLOCK_GUARD() { + inactive =bdrv_is_inactive (blk_bs (exp->common.blk));
Can the declaration of bool inactive be moved inside the lock guard block? Not a problem if you want to leave it with all other declarations, though.
Signature · 3 lines
Eric Blake, Principal Software Engineer Red Hat, Inc. Virtualization: qemu.org | libguestfs.org