Skip to content
Snippets Groups Projects
  • Hanna Reitz's avatar
    b0a9f6fe
    block: Let replace_child_noperm free children · b0a9f6fe
    Hanna Reitz authored
    
    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: default avatarHanna Reitz <hreitz@redhat.com>
    Message-Id: <20211111120829.81329-10-hreitz@redhat.com>
    Signed-off-by: default avatarKevin Wolf <kwolf@redhat.com>
    Message-Id: <20211115145409.176785-10-kwolf@redhat.com>
    Signed-off-by: default avatarHanna Reitz <hreitz@redhat.com>
    b0a9f6fe
    History
    block: Let replace_child_noperm free children
    Hanna Reitz authored
    
    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: default avatarHanna Reitz <hreitz@redhat.com>
    Message-Id: <20211111120829.81329-10-hreitz@redhat.com>
    Signed-off-by: default avatarKevin Wolf <kwolf@redhat.com>
    Message-Id: <20211115145409.176785-10-kwolf@redhat.com>
    Signed-off-by: default avatarHanna Reitz <hreitz@redhat.com>