@@ -494,6 +494,8 @@ int bdrv_probe_blocksizes(BlockDriverState *bs, BlockSizes *bsz)
if (drv && drv->bdrv_probe_blocksizes) {
return drv->bdrv_probe_blocksizes(bs, bsz);
+ } else if (drv && drv->is_filter && bs->file) {
+ return bdrv_probe_blocksizes(bs->file->bs, bsz);
}
return -ENOTSUP;
@@ -511,6 +513,8 @@ int bdrv_probe_geometry(BlockDriverState *bs, HDGeometry *geo)
if (drv && drv->bdrv_probe_geometry) {
return drv->bdrv_probe_geometry(bs, geo);
+ } else if (drv && drv->is_filter && bs->file) {
+ return bdrv_probe_geometry(bs->file->bs, geo);
}
return -ENOTSUP;
@@ -3420,11 +3424,15 @@ int bdrv_truncate(BdrvChild *child, int64_t offset, PreallocMode prealloc,
assert(child->perm & BLK_PERM_RESIZE);
+ /* if bs->drv == NULL, bs is closed, so there's nothing to do here */
if (!drv) {
error_setg(errp, "No medium inserted");
return -ENOMEDIUM;
}
if (!drv->bdrv_truncate) {
+ if (bs->file && drv->is_filter) {
+ return bdrv_truncate(bs->file, offset, prealloc, errp);
+ }
error_setg(errp, "Image format driver does not support resize");
return -ENOTSUP;
}
@@ -3761,6 +3769,9 @@ int bdrv_has_zero_init(BlockDriverState *bs)
if (bs->drv->bdrv_has_zero_init) {
return bs->drv->bdrv_has_zero_init(bs);
}
+ if (bs->file && bs->drv->is_filter) {
+ return bdrv_has_zero_init(bs->file->bs);
+ }
/* safe default */
return 0;
@@ -3815,10 +3826,16 @@ void bdrv_get_backing_filename(BlockDriverState *bs,
int bdrv_get_info(BlockDriverState *bs, BlockDriverInfo *bdi)
{
BlockDriver *drv = bs->drv;
- if (!drv)
+ /* if bs->drv == NULL, bs is closed, so there's nothing to do here */
+ if (!drv) {
return -ENOMEDIUM;
- if (!drv->bdrv_get_info)
+ }
+ if (!drv->bdrv_get_info) {
+ if (bs->file && drv->is_filter) {
+ return bdrv_get_info(bs->file->bs, bdi);
+ }
return -ENOTSUP;
+ }
memset(bdi, 0, sizeof(*bdi));
return drv->bdrv_get_info(bs, bdi);
}
@@ -87,7 +87,11 @@ struct BlockDriver {
const char *format_name;
int instance_size;
- /* set to true if the BlockDriver is a block filter */
+ /* set to true if the BlockDriver is a block filter. Block filters pass
+ * certain callbacks that refer to data (see block.c) to their bs->file if
+ * the driver doesn't implement them. Drivers that do not wish to forward
+ * must implement them and return -ENOTSUP.
+ */
bool is_filter;
/* for snapshots block filter like Quorum can implement the
* following recursive callback.