All of lore.kernel.org
 help / color / mirror / Atom feed
From: Kevin Wolf <kwolf@redhat.com>
To: qemu-block@nongnu.org
Cc: kwolf@redhat.com, richard.henderson@linaro.org, qemu-devel@nongnu.org
Subject: [PULL 03/21] block: fix bdrv_next() skipping monitor-owned nodes
Date: Wed,  7 Oct 2026 18:32:44 +0200	[thread overview]
Message-ID: <20261007163302.332250-4-kwolf@redhat.com> (raw)
In-Reply-To: <20261007163302.332250-1-kwolf@redhat.com>

From: "Denis V. Lunev" <den@openvz.org>

it->bs is the cursor into monitor_bdrv_states for the second phase of
bdrv_next(), so it has to be NULL when that phase starts. Commit
f6d38c9f6d made the first phase store the node it returns there, to
unreference the right one when the graph changes underneath. The cursor
is now left pointing at the last BlockBackend root, so the second phase
resumes from there instead of from the head of the list and never
returns a node added before it.

A skipped node drops out of the vm_stop and migration handover paths:
not flushed, not inactivated, not snapshotted. bdrv_inactivate_all()
still reports success, so the node keeps its image lock and the
migration target cannot open the image. Only detached nodes are hit in
practice, as these callers also recurse into children.

Reset the cursor when the second phase starts. old_bs is taken at the
top of the function, so f6d38c9f6d keeps working.

Cc: qemu-stable@nongnu.org
Fixes: f6d38c9f6d ("block-backend: fix edge case in bdrv_next() where BDS associated to BB changes")
Signed-off-by: Denis V. Lunev <den@openvz.org>
Cc: Fiona Ebner <f.ebner@proxmox.com>
Cc: Kevin Wolf <kwolf@redhat.com>
Message-ID: <20260828222005.2888213-1-den@openvz.org>
Reviewed-by: Fiona Ebner <f.ebner@proxmox.com>
Tested-by: Fiona Ebner <f.ebner@proxmox.com>
Reviewed-by: Kevin Wolf <kwolf@redhat.com>
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
---
 block/block-backend.c                          |  1 +
 tests/qemu-iotests/tests/inactive-node-nbd     | 16 ++++++++++++++++
 tests/qemu-iotests/tests/inactive-node-nbd.out |  8 ++++++++
 3 files changed, 25 insertions(+)

diff --git a/block/block-backend.c b/block/block-backend.c
index 5e59bac1a3c..ab837fac921 100644
--- a/block/block-backend.c
+++ b/block/block-backend.c
@@ -625,6 +625,7 @@ BlockDriverState *bdrv_next(BdrvNextIterator *it)
             return bs;
         }
         it->phase = BDRV_NEXT_MONITOR_OWNED;
+        it->bs = NULL;
     }
 
     /* Then return the monitor-owned BDSes without a BB attached. Ignore all
diff --git a/tests/qemu-iotests/tests/inactive-node-nbd b/tests/qemu-iotests/tests/inactive-node-nbd
index 24242265b16..bb6ee5c75ab 100755
--- a/tests/qemu-iotests/tests/inactive-node-nbd
+++ b/tests/qemu-iotests/tests/inactive-node-nbd
@@ -48,6 +48,7 @@ def node_is_active(_vm, node_name):
 
 with iotests.FilePath('disk.img') as path, \
      iotests.FilePath('ro.img') as ro_path, \
+     iotests.FilePath('detached.img') as detached_path, \
      iotests.FilePath('snap.qcow2') as snap_path, \
      iotests.FilePath('snap2.qcow2') as snap2_path, \
      iotests.FilePath('target.img') as target_path, \
@@ -60,6 +61,7 @@ with iotests.FilePath('disk.img') as path, \
     iotests.qemu_img_create('-f', iotests.imgfmt, path, img_size)
     iotests.qemu_img_create('-f', iotests.imgfmt, target_path, img_size)
     iotests.qemu_img_create('-f', iotests.imgfmt, ro_path, img_size)
+    iotests.qemu_img_create('-f', iotests.imgfmt, detached_path, img_size)
 
     iotests.qemu_img_create('-f', 'qcow2', '-b', path, '-F', iotests.imgfmt,
                             snap_path)
@@ -70,6 +72,9 @@ with iotests.FilePath('disk.img') as path, \
     vm.add_blockdev(f'file,node-name=disk-file,filename={path}')
     vm.add_blockdev(f'{iotests.imgfmt},file=disk-file,node-name=disk-fmt,'
                      'active=off')
+    vm.add_blockdev(f'file,node-name=detached-file,filename={detached_path}')
+    vm.add_blockdev(f'{iotests.imgfmt},file=detached-file,'
+                     'node-name=detached-fmt')
     vm.add_blockdev(f'file,node-name=target-file,filename={target_path}')
     vm.add_blockdev(f'{iotests.imgfmt},file=target-file,node-name=target-fmt')
     vm.add_blockdev(f'file,node-name=ro-file,filename={ro_path},read-only=on')
@@ -311,6 +316,17 @@ with iotests.FilePath('disk.img') as path, \
     iotests.log('snap2-fmt active: %s' % node_is_active(vm, 'snap2-fmt'))
     iotests.log('target-fmt active: %s' % node_is_active(vm, 'target-fmt'))
 
+    iotests.log('\n=== Inactivating all nodes at once ===')
+
+    # detached-fmt has no parent and no BlockBackend, so nothing can reach it
+    # by recursion. It is only inactivated if bdrv_next() actually returns it.
+    vm.qmp_log('stop')
+    vm.qmp_log('blockdev-set-active', active=False)
+
+    iotests.log('detached-fmt active: %s' % node_is_active(vm, 'detached-fmt'))
+    iotests.log('detached-file active: %s'
+                % node_is_active(vm, 'detached-file'))
+
     iotests.log('\nShutting down...')
     vm.shutdown()
     log = vm.get_log()
diff --git a/tests/qemu-iotests/tests/inactive-node-nbd.out b/tests/qemu-iotests/tests/inactive-node-nbd.out
index 96af7608ded..5ff0063ec46 100644
--- a/tests/qemu-iotests/tests/inactive-node-nbd.out
+++ b/tests/qemu-iotests/tests/inactive-node-nbd.out
@@ -243,5 +243,13 @@ snap-fmt active: True
 snap2-fmt active: True
 target-fmt active: True
 
+=== Inactivating all nodes at once ===
+{"execute": "stop", "arguments": {}}
+{"return": {}}
+{"execute": "blockdev-set-active", "arguments": {"active": false}}
+{"return": {}}
+detached-fmt active: False
+detached-file active: False
+
 Shutting down...
 
-- 
2.56.0



  parent reply	other threads:[~2026-10-07 16:35 UTC|newest]

Thread overview: 23+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-10-07 16:32 [PULL 00/21] Block layer patches Kevin Wolf
2026-10-07 16:32 ` [PULL 01/21] block-common: fix BDRV_WANT_PRECISE duplicating BDRV_WANT_OFFSET_VALID Kevin Wolf
2026-10-07 16:32 ` [PULL 02/21] block/throttle-groups: fix crash when enabling I/O limits on a busy disk Kevin Wolf
2026-10-07 16:32 ` Kevin Wolf [this message]
2026-10-07 16:32 ` [PULL 04/21] block: allocate aligned write buffer for 'truncate -m full' Kevin Wolf
2026-10-07 16:32 ` [PULL 05/21] scripts/qemugdb: coroutine: Fix selected frame leak on error path Kevin Wolf
2026-10-07 16:32 ` [PULL 06/21] scripts/qemugdb: coroutine: Get rid of fallback pattern when dumping backtrace Kevin Wolf
2026-10-07 16:32 ` [PULL 07/21] scripts/qemugdb: coroutine: Only attempt to restore regs in coredump Kevin Wolf
2026-10-07 16:32 ` [PULL 08/21] scripts/qemugdb: coroutine: Don't unwind past the outermost frame Kevin Wolf
2026-10-07 16:32 ` [PULL 09/21] scripts/qemugdb: coroutine: Fix patching pt_regs in the coredump Kevin Wolf
2026-10-07 16:32 ` [PULL 10/21] scripts/qemugdb: coroutine: Fix '--detailed' description Kevin Wolf
2026-10-07 16:32 ` [PULL 11/21] scripts/qemugdb: coroutine: Handle target absence gracefully Kevin Wolf
2026-10-07 16:32 ` [PULL 12/21] scripts/qemugdb: coroutine: Speed up coroutine lookup in a coredump Kevin Wolf
2026-10-07 16:32 ` [PULL 13/21] scripts/qemugdb: coroutine: Don't touch the coredump for a plain backtrace Kevin Wolf
2026-10-07 16:32 ` [PULL 14/21] iotests: remove unused 'owner=' variable assignment Kevin Wolf
2026-10-07 16:32 ` [PULL 15/21] hw/block/fdc: account for read and write requests Kevin Wolf
2026-10-07 16:32 ` [PULL 16/21] iotests: annotate TestRunner.shared_self for mypy 2.4 Kevin Wolf
2026-10-07 16:32 ` [PULL 17/21] file-posix: add statx(STATX_DIOALIGN) support Kevin Wolf
2026-10-07 16:32 ` [PULL 18/21] qcow2: do not clear the dirty bit when reopening a read-only node Kevin Wolf
2026-10-07 16:33 ` [PULL 19/21] block: reject a reopen of an unusable node instead of crashing Kevin Wolf
2026-10-07 16:33 ` [PULL 20/21] block: Fix corruption from broken RMW atomicity Kevin Wolf
2026-10-07 16:33 ` [PULL 21/21] block: Remove now redundant bdrv_wait_serialising_requests() calls Kevin Wolf
2026-10-09 12:29 ` [PULL 00/21] Block layer patches Richard Henderson

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=20261007163302.332250-4-kwolf@redhat.com \
    --to=kwolf@redhat.com \
    --cc=qemu-block@nongnu.org \
    --cc=qemu-devel@nongnu.org \
    --cc=richard.henderson@linaro.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.