]> git.ipfire.org Git - thirdparty/qemu.git/commitdiff
block-backend: fix edge case in bdrv_next_cleanup() where BDS associated to BB changes
authorFiona Ebner <f.ebner@proxmox.com>
Fri, 22 Mar 2024 09:50:08 +0000 (10:50 +0100)
committerMichael Tokarev <mjt@tls.msk.ru>
Wed, 27 Mar 2024 06:42:57 +0000 (09:42 +0300)
Same rationale as for commit "block-backend: fix edge case in
bdrv_next() where BDS associated to BB changes". The block graph might
change between the bdrv_next() call and the bdrv_next_cleanup() call,
so it could be that the associated BDS is not the same that was
referenced previously anymore. Instead, rely on bdrv_next() to set
it->bs to the BDS it referenced and unreference that one in any case.

Signed-off-by: Fiona Ebner <f.ebner@proxmox.com>
Message-ID: <20240322095009.346989-4-f.ebner@proxmox.com>
Reviewed-by: Kevin Wolf <kwolf@redhat.com>
Reviewed-by: Stefan Hajnoczi <stefanha@redhat.com>
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
(cherry picked from commit bac09b093ebbb79e6a7444c7b979c32ca5540132)
Signed-off-by: Michael Tokarev <mjt@tls.msk.ru>
block/block-backend.c

index 4a419f75fb2d43419bd23ed438be0e3bae874ed5..86315d62c6ed783b25b50f151103aa2091757e18 100644 (file)
@@ -677,13 +677,10 @@ void bdrv_next_cleanup(BdrvNextIterator *it)
     /* Must be called from the main loop */
     assert(qemu_get_current_aio_context() == qemu_get_aio_context());
 
-    if (it->phase == BDRV_NEXT_BACKEND_ROOTS) {
-        if (it->blk) {
-            bdrv_unref(blk_bs(it->blk));
-            blk_unref(it->blk);
-        }
-    } else {
-        bdrv_unref(it->bs);
+    bdrv_unref(it->bs);
+
+    if (it->phase == BDRV_NEXT_BACKEND_ROOTS && it->blk) {
+        blk_unref(it->blk);
     }
 
     bdrv_next_reset(it);