Skip to content
  • Hanna Reitz's avatar
    66836189
    block: Let bdrv_open_inherit() return the snapshot · 66836189
    Hanna Reitz authored
    
    
    If bdrv_open_inherit() creates a snapshot BDS and *pbs is NULL, that
    snapshot BDS should be returned instead of the BDS under it.
    
    This has worked so far because (nearly) all users of BDRV_O_SNAPSHOT use
    blk_new_open() to create the BDS tree. bdrv_append() (which is called by
    bdrv_append_temp_snapshot()) redirects pointers from parents (i.e. the
    BB in this case) to the newly appended child (i.e. the overlay),
    therefore, while bdrv_open_inherit() did not return the root BDS, the BB
    still pointed to it.
    
    The only instance where BDRV_O_SNAPSHOT is used but blk_new_open() is
    not is in blockdev_init() if no BDS tree is created, and instead
    blk_new() is used and the flags are stored in the BB root state.
    However, qmp_blockdev_change_medium() filters the BDRV_O_SNAPSHOT flag
    before invoking bdrv_open(), so it will not have any effect.
    
    In any case, it would be nicer if bdrv_open_inherit() could just always
    return the root of the BDS tree that has been created.
    
    To this end, bdrv_append_temp_snapshot() now returns the snapshot BDS
    instead of just appending it on top of the snapshotted BDS. Also, it
    calls bdrv_ref() before bdrv_append() (which bdrv_open_inherit() has to
    undo if not returning the overlay).
    
    Signed-off-by: default avatarMax Reitz <mreitz@redhat.com>
    Reviewed-by: default avatarKevin Wolf <kwolf@redhat.com>
    Signed-off-by: default avatarKevin Wolf <kwolf@redhat.com>
    66836189
    block: Let bdrv_open_inherit() return the snapshot
    Hanna Reitz authored
    
    
    If bdrv_open_inherit() creates a snapshot BDS and *pbs is NULL, that
    snapshot BDS should be returned instead of the BDS under it.
    
    This has worked so far because (nearly) all users of BDRV_O_SNAPSHOT use
    blk_new_open() to create the BDS tree. bdrv_append() (which is called by
    bdrv_append_temp_snapshot()) redirects pointers from parents (i.e. the
    BB in this case) to the newly appended child (i.e. the overlay),
    therefore, while bdrv_open_inherit() did not return the root BDS, the BB
    still pointed to it.
    
    The only instance where BDRV_O_SNAPSHOT is used but blk_new_open() is
    not is in blockdev_init() if no BDS tree is created, and instead
    blk_new() is used and the flags are stored in the BB root state.
    However, qmp_blockdev_change_medium() filters the BDRV_O_SNAPSHOT flag
    before invoking bdrv_open(), so it will not have any effect.
    
    In any case, it would be nicer if bdrv_open_inherit() could just always
    return the root of the BDS tree that has been created.
    
    To this end, bdrv_append_temp_snapshot() now returns the snapshot BDS
    instead of just appending it on top of the snapshotted BDS. Also, it
    calls bdrv_ref() before bdrv_append() (which bdrv_open_inherit() has to
    undo if not returning the overlay).
    
    Signed-off-by: default avatarMax Reitz <mreitz@redhat.com>
    Reviewed-by: default avatarKevin Wolf <kwolf@redhat.com>
    Signed-off-by: default avatarKevin Wolf <kwolf@redhat.com>
Loading