]> www.infradead.org Git - qemu-nvme.git/commit
block: Let replace_child_noperm free children
authorHanna Reitz <hreitz@redhat.com>
Mon, 15 Nov 2021 14:54:05 +0000 (15:54 +0100)
committerHanna Reitz <hreitz@redhat.com>
Tue, 16 Nov 2021 08:43:46 +0000 (09:43 +0100)
commitb0a9f6fed3d80de610dcd04a7e66f9f30a04174f
tree817c18b0dbd9679f8d1df9eee70ce1b752660f95
parent82b54cf51656bf3cd5ed1ac549e8a1085a0e3290
block: Let replace_child_noperm free children

In most of the block layer, especially when traversing down from other
BlockDriverStates, we assume that BdrvChild.bs can never be NULL.  When
it becomes NULL, it is expected that the corresponding BdrvChild pointer
also becomes NULL and the BdrvChild object is freed.

Therefore, once bdrv_replace_child_noperm() sets the BdrvChild.bs
pointer to NULL, it should also immediately set the corresponding
BdrvChild pointer (like bs->file or bs->backing) to NULL.

In that context, it also makes sense for this function to free the
child.  Sometimes we cannot do so, though, because it is called in a
transactional context where the caller might still want to reinstate the
child in the abort branch (and free it only on commit), so this behavior
has to remain optional.

In bdrv_replace_child_tran()'s abort handler, we now rely on the fact
that the BdrvChild passed to bdrv_replace_child_tran() must have had a
non-NULL .bs pointer initially.  Make a note of that and assert it.

Signed-off-by: Hanna Reitz <hreitz@redhat.com>
Message-Id: <20211111120829.81329-10-hreitz@redhat.com>
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
Message-Id: <20211115145409.176785-10-kwolf@redhat.com>
Signed-off-by: Hanna Reitz <hreitz@redhat.com>
block.c