]> git.proxmox.com Git - mirror_qemu.git/commit
block: Let bdrv_open_inherit() return the snapshot
authorMax Reitz <mreitz@redhat.com>
Tue, 17 May 2016 14:41:27 +0000 (16:41 +0200)
committerKevin Wolf <kwolf@redhat.com>
Wed, 25 May 2016 17:04:10 +0000 (19:04 +0200)
commit668361898e0181c74ffc23fdecfb575a7e7c0f3c
tree996a81c1c2804e1705cad3b23c99a55c2a46be34
parent506f8709ceddd26542824d8cb9eac80201d085f1
block: Let bdrv_open_inherit() return the snapshot

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: Max Reitz <mreitz@redhat.com>
Reviewed-by: Kevin Wolf <kwolf@redhat.com>
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
block.c