block: Use bdrv_filter_(bs|child) where obvious
Places that use patterns like if (bs->drv->is_filter && bs->file) { ... something about bs->file->bs ... } should be BlockDriverState *filtered = bdrv_filter_bs(bs); if (filtered) { ... something about @filtered ... } instead. Signed-off-by: Max Reitz <mreitz@redhat.com> Reviewed-by: Andrey Shinkevich <andrey.shinkevich@virtuozzo.com> Reviewed-by: Kevin Wolf <kwolf@redhat.com>
This commit is contained in:
parent
4935e8be22
commit
93393e698c
31
block.c
31
block.c
@ -712,11 +712,12 @@ int coroutine_fn bdrv_co_delete_file(BlockDriverState *bs, Error **errp)
|
|||||||
int bdrv_probe_blocksizes(BlockDriverState *bs, BlockSizes *bsz)
|
int bdrv_probe_blocksizes(BlockDriverState *bs, BlockSizes *bsz)
|
||||||
{
|
{
|
||||||
BlockDriver *drv = bs->drv;
|
BlockDriver *drv = bs->drv;
|
||||||
|
BlockDriverState *filtered = bdrv_filter_bs(bs);
|
||||||
|
|
||||||
if (drv && drv->bdrv_probe_blocksizes) {
|
if (drv && drv->bdrv_probe_blocksizes) {
|
||||||
return drv->bdrv_probe_blocksizes(bs, bsz);
|
return drv->bdrv_probe_blocksizes(bs, bsz);
|
||||||
} else if (drv && drv->is_filter && bs->file) {
|
} else if (filtered) {
|
||||||
return bdrv_probe_blocksizes(bs->file->bs, bsz);
|
return bdrv_probe_blocksizes(filtered, bsz);
|
||||||
}
|
}
|
||||||
|
|
||||||
return -ENOTSUP;
|
return -ENOTSUP;
|
||||||
@ -731,11 +732,12 @@ int bdrv_probe_blocksizes(BlockDriverState *bs, BlockSizes *bsz)
|
|||||||
int bdrv_probe_geometry(BlockDriverState *bs, HDGeometry *geo)
|
int bdrv_probe_geometry(BlockDriverState *bs, HDGeometry *geo)
|
||||||
{
|
{
|
||||||
BlockDriver *drv = bs->drv;
|
BlockDriver *drv = bs->drv;
|
||||||
|
BlockDriverState *filtered = bdrv_filter_bs(bs);
|
||||||
|
|
||||||
if (drv && drv->bdrv_probe_geometry) {
|
if (drv && drv->bdrv_probe_geometry) {
|
||||||
return drv->bdrv_probe_geometry(bs, geo);
|
return drv->bdrv_probe_geometry(bs, geo);
|
||||||
} else if (drv && drv->is_filter && bs->file) {
|
} else if (filtered) {
|
||||||
return bdrv_probe_geometry(bs->file->bs, geo);
|
return bdrv_probe_geometry(filtered, geo);
|
||||||
}
|
}
|
||||||
|
|
||||||
return -ENOTSUP;
|
return -ENOTSUP;
|
||||||
@ -5442,6 +5444,8 @@ int bdrv_has_zero_init_1(BlockDriverState *bs)
|
|||||||
|
|
||||||
int bdrv_has_zero_init(BlockDriverState *bs)
|
int bdrv_has_zero_init(BlockDriverState *bs)
|
||||||
{
|
{
|
||||||
|
BlockDriverState *filtered;
|
||||||
|
|
||||||
if (!bs->drv) {
|
if (!bs->drv) {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
@ -5454,8 +5458,10 @@ int bdrv_has_zero_init(BlockDriverState *bs)
|
|||||||
if (bs->drv->bdrv_has_zero_init) {
|
if (bs->drv->bdrv_has_zero_init) {
|
||||||
return bs->drv->bdrv_has_zero_init(bs);
|
return bs->drv->bdrv_has_zero_init(bs);
|
||||||
}
|
}
|
||||||
if (bs->file && bs->drv->is_filter) {
|
|
||||||
return bdrv_has_zero_init(bs->file->bs);
|
filtered = bdrv_filter_bs(bs);
|
||||||
|
if (filtered) {
|
||||||
|
return bdrv_has_zero_init(filtered);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* safe default */
|
/* safe default */
|
||||||
@ -5485,8 +5491,9 @@ int bdrv_get_info(BlockDriverState *bs, BlockDriverInfo *bdi)
|
|||||||
return -ENOMEDIUM;
|
return -ENOMEDIUM;
|
||||||
}
|
}
|
||||||
if (!drv->bdrv_get_info) {
|
if (!drv->bdrv_get_info) {
|
||||||
if (bs->file && drv->is_filter) {
|
BlockDriverState *filtered = bdrv_filter_bs(bs);
|
||||||
return bdrv_get_info(bs->file->bs, bdi);
|
if (filtered) {
|
||||||
|
return bdrv_get_info(filtered, bdi);
|
||||||
}
|
}
|
||||||
return -ENOTSUP;
|
return -ENOTSUP;
|
||||||
}
|
}
|
||||||
@ -6571,6 +6578,8 @@ int bdrv_amend_options(BlockDriverState *bs, QemuOpts *opts,
|
|||||||
bool bdrv_recurse_can_replace(BlockDriverState *bs,
|
bool bdrv_recurse_can_replace(BlockDriverState *bs,
|
||||||
BlockDriverState *to_replace)
|
BlockDriverState *to_replace)
|
||||||
{
|
{
|
||||||
|
BlockDriverState *filtered;
|
||||||
|
|
||||||
if (!bs || !bs->drv) {
|
if (!bs || !bs->drv) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
@ -6585,9 +6594,9 @@ bool bdrv_recurse_can_replace(BlockDriverState *bs,
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* For filters without an own implementation, we can recurse on our own */
|
/* For filters without an own implementation, we can recurse on our own */
|
||||||
if (bs->drv->is_filter) {
|
filtered = bdrv_filter_bs(bs);
|
||||||
BdrvChild *child = bs->file ?: bs->backing;
|
if (filtered) {
|
||||||
return bdrv_recurse_can_replace(child->bs, to_replace);
|
return bdrv_recurse_can_replace(filtered, to_replace);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Safe default */
|
/* Safe default */
|
||||||
|
@ -3309,6 +3309,7 @@ int coroutine_fn bdrv_co_truncate(BdrvChild *child, int64_t offset, bool exact,
|
|||||||
Error **errp)
|
Error **errp)
|
||||||
{
|
{
|
||||||
BlockDriverState *bs = child->bs;
|
BlockDriverState *bs = child->bs;
|
||||||
|
BdrvChild *filtered;
|
||||||
BlockDriver *drv = bs->drv;
|
BlockDriver *drv = bs->drv;
|
||||||
BdrvTrackedRequest req;
|
BdrvTrackedRequest req;
|
||||||
int64_t old_size, new_bytes;
|
int64_t old_size, new_bytes;
|
||||||
@ -3360,6 +3361,8 @@ int coroutine_fn bdrv_co_truncate(BdrvChild *child, int64_t offset, bool exact,
|
|||||||
goto out;
|
goto out;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
filtered = bdrv_filter_child(bs);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* If the image has a backing file that is large enough that it would
|
* If the image has a backing file that is large enough that it would
|
||||||
* provide data for the new area, we cannot leave it unallocated because
|
* provide data for the new area, we cannot leave it unallocated because
|
||||||
@ -3392,8 +3395,8 @@ int coroutine_fn bdrv_co_truncate(BdrvChild *child, int64_t offset, bool exact,
|
|||||||
goto out;
|
goto out;
|
||||||
}
|
}
|
||||||
ret = drv->bdrv_co_truncate(bs, offset, exact, prealloc, flags, errp);
|
ret = drv->bdrv_co_truncate(bs, offset, exact, prealloc, flags, errp);
|
||||||
} else if (bs->file && drv->is_filter) {
|
} else if (filtered) {
|
||||||
ret = bdrv_co_truncate(bs->file, offset, exact, prealloc, flags, errp);
|
ret = bdrv_co_truncate(filtered, offset, exact, prealloc, flags, errp);
|
||||||
} else {
|
} else {
|
||||||
error_setg(errp, "Image format driver does not support resize");
|
error_setg(errp, "Image format driver does not support resize");
|
||||||
ret = -ENOTSUP;
|
ret = -ENOTSUP;
|
||||||
|
@ -615,13 +615,7 @@ static int init_dirty_bitmap_migration(DBMSaveState *s)
|
|||||||
while (bs && bs->drv && bs->drv->is_filter &&
|
while (bs && bs->drv && bs->drv->is_filter &&
|
||||||
!bdrv_has_named_bitmaps(bs))
|
!bdrv_has_named_bitmaps(bs))
|
||||||
{
|
{
|
||||||
if (bs->backing) {
|
bs = bdrv_filter_bs(bs);
|
||||||
bs = bs->backing->bs;
|
|
||||||
} else if (bs->file) {
|
|
||||||
bs = bs->file->bs;
|
|
||||||
} else {
|
|
||||||
bs = NULL;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (bs && bs->drv && !bs->drv->is_filter) {
|
if (bs && bs->drv && !bs->drv->is_filter) {
|
||||||
|
Loading…
Reference in New Issue
Block a user