Skip to content
  • Alberto Garcia's avatar
    50a3efb0
    block: Close a BlockDriverState completely even when bs->drv is NULL · 50a3efb0
    Alberto Garcia authored
    
    
    bdrv_close() skips much of its logic when bs->drv is NULL. This is
    fine when we're closing a BlockDriverState that has just been created
    (because e.g the initialization process failed), but it's not enough
    in other cases.
    
    For example, when a valid qcow2 image is found to be corrupted then
    QEMU marks it as such in the file header and then sets bs->drv to
    NULL in order to make the BlockDriverState unusable. When that BDS is
    later closed then many of its data structures are not freed (leaking
    their memory) and none of its children are detached. This results in
    bdrv_close_all() failing to close all BDSs and making this assertion
    fail when QEMU is being shut down:
    
       bdrv_close_all: Assertion `QTAILQ_EMPTY(&all_bdrv_states)' failed.
    
    This patch makes bdrv_close() do the full uninitialization process
    in all cases. This fixes the problem with corrupted images and still
    works fine with freshly created BDSs.
    
    Signed-off-by: default avatarAlberto Garcia <berto@igalia.com>
    Message-id: 20171106145345.12038-1-berto@igalia.com
    Reviewed-by: default avatarEric Blake <eblake@redhat.com>
    Signed-off-by: default avatarMax Reitz <mreitz@redhat.com>
    50a3efb0
    block: Close a BlockDriverState completely even when bs->drv is NULL
    Alberto Garcia authored
    
    
    bdrv_close() skips much of its logic when bs->drv is NULL. This is
    fine when we're closing a BlockDriverState that has just been created
    (because e.g the initialization process failed), but it's not enough
    in other cases.
    
    For example, when a valid qcow2 image is found to be corrupted then
    QEMU marks it as such in the file header and then sets bs->drv to
    NULL in order to make the BlockDriverState unusable. When that BDS is
    later closed then many of its data structures are not freed (leaking
    their memory) and none of its children are detached. This results in
    bdrv_close_all() failing to close all BDSs and making this assertion
    fail when QEMU is being shut down:
    
       bdrv_close_all: Assertion `QTAILQ_EMPTY(&all_bdrv_states)' failed.
    
    This patch makes bdrv_close() do the full uninitialization process
    in all cases. This fixes the problem with corrupted images and still
    works fine with freshly created BDSs.
    
    Signed-off-by: default avatarAlberto Garcia <berto@igalia.com>
    Message-id: 20171106145345.12038-1-berto@igalia.com
    Reviewed-by: default avatarEric Blake <eblake@redhat.com>
    Signed-off-by: default avatarMax Reitz <mreitz@redhat.com>
Loading