block: simplify bdrv_find_base() and bdrv_find_overlay()
This simplifies the function bdrv_find_overlay(). With this change, bdrv_find_base() is just a subset of usage of bdrv_find_overlay(), so this also takes advantage of that. Reviewed-by: Eric Blake <eblake@redhat.com> Reviewed-by: Benoit Canet <benoit@irqsave.net> Signed-off-by: Jeff Cody <jcody@redhat.com> Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com>
This commit is contained in:
parent
7676e2c597
commit
4caf0fcd45
43
block.c
43
block.c
|
@ -2508,32 +2508,23 @@ int bdrv_change_backing_file(BlockDriverState *bs,
|
||||||
*
|
*
|
||||||
* Returns NULL if bs is not found in active's image chain,
|
* Returns NULL if bs is not found in active's image chain,
|
||||||
* or if active == bs.
|
* or if active == bs.
|
||||||
|
*
|
||||||
|
* Returns the bottommost base image if bs == NULL.
|
||||||
*/
|
*/
|
||||||
BlockDriverState *bdrv_find_overlay(BlockDriverState *active,
|
BlockDriverState *bdrv_find_overlay(BlockDriverState *active,
|
||||||
BlockDriverState *bs)
|
BlockDriverState *bs)
|
||||||
{
|
{
|
||||||
BlockDriverState *overlay = NULL;
|
while (active && bs != active->backing_hd) {
|
||||||
BlockDriverState *intermediate;
|
active = active->backing_hd;
|
||||||
|
|
||||||
assert(active != NULL);
|
|
||||||
assert(bs != NULL);
|
|
||||||
|
|
||||||
/* if bs is the same as active, then by definition it has no overlay
|
|
||||||
*/
|
|
||||||
if (active == bs) {
|
|
||||||
return NULL;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
intermediate = active;
|
return active;
|
||||||
while (intermediate->backing_hd) {
|
|
||||||
if (intermediate->backing_hd == bs) {
|
|
||||||
overlay = intermediate;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
intermediate = intermediate->backing_hd;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return overlay;
|
/* Given a BDS, searches for the base layer. */
|
||||||
|
BlockDriverState *bdrv_find_base(BlockDriverState *bs)
|
||||||
|
{
|
||||||
|
return bdrv_find_overlay(bs, NULL);
|
||||||
}
|
}
|
||||||
|
|
||||||
typedef struct BlkIntermediateStates {
|
typedef struct BlkIntermediateStates {
|
||||||
|
@ -4326,22 +4317,6 @@ int bdrv_get_backing_file_depth(BlockDriverState *bs)
|
||||||
return 1 + bdrv_get_backing_file_depth(bs->backing_hd);
|
return 1 + bdrv_get_backing_file_depth(bs->backing_hd);
|
||||||
}
|
}
|
||||||
|
|
||||||
BlockDriverState *bdrv_find_base(BlockDriverState *bs)
|
|
||||||
{
|
|
||||||
BlockDriverState *curr_bs = NULL;
|
|
||||||
|
|
||||||
if (!bs) {
|
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
curr_bs = bs;
|
|
||||||
|
|
||||||
while (curr_bs->backing_hd) {
|
|
||||||
curr_bs = curr_bs->backing_hd;
|
|
||||||
}
|
|
||||||
return curr_bs;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**************************************************************/
|
/**************************************************************/
|
||||||
/* async I/Os */
|
/* async I/Os */
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue