[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Qemu-devel] [PATCH v6 22/42] block: Fix bdrv_get_allocated_file_size's
From: |
Max Reitz |
Subject: |
[Qemu-devel] [PATCH v6 22/42] block: Fix bdrv_get_allocated_file_size's fallback |
Date: |
Fri, 9 Aug 2019 18:13:47 +0200 |
If the driver does not implement bdrv_get_allocated_file_size(), we
should fall back to cumulating the allocated size of all non-COW
children instead of just bs->file.
Suggested-by: Vladimir Sementsov-Ogievskiy <address@hidden>
Signed-off-by: Max Reitz <address@hidden>
---
block.c | 22 ++++++++++++++++++++--
1 file changed, 20 insertions(+), 2 deletions(-)
diff --git a/block.c b/block.c
index 1070aa1ba9..6e1ddab056 100644
--- a/block.c
+++ b/block.c
@@ -4650,9 +4650,27 @@ int64_t bdrv_get_allocated_file_size(BlockDriverState
*bs)
if (drv->bdrv_get_allocated_file_size) {
return drv->bdrv_get_allocated_file_size(bs);
}
- if (bs->file) {
- return bdrv_get_allocated_file_size(bs->file->bs);
+
+ if (!QLIST_EMPTY(&bs->children)) {
+ BdrvChild *child;
+ int64_t child_size, total_size = 0;
+
+ QLIST_FOREACH(child, &bs->children, next) {
+ if (child == bdrv_filtered_cow_child(bs)) {
+ /* Ignore COW backing files */
+ continue;
+ }
+
+ child_size = bdrv_get_allocated_file_size(child->bs);
+ if (child_size < 0) {
+ return child_size;
+ }
+ total_size += child_size;
+ }
+
+ return total_size;
}
+
return -ENOTSUP;
}
--
2.21.0
- Re: [Qemu-devel] [PATCH v6 16/42] block: Flush all children in generic code, (continued)
- [Qemu-devel] [PATCH v6 17/42] block: Use CAFs in bdrv_refresh_limits(), Max Reitz, 2019/08/09
- [Qemu-devel] [PATCH v6 18/42] block: Use CAFs in bdrv_refresh_filename(), Max Reitz, 2019/08/09
- [Qemu-devel] [PATCH v6 19/42] block: Use CAF in bdrv_co_rw_vmstate(), Max Reitz, 2019/08/09
- [Qemu-devel] [PATCH v6 20/42] block/snapshot: Fix fallback, Max Reitz, 2019/08/09
- [Qemu-devel] [PATCH v6 21/42] block: Use CAFs for debug breakpoints, Max Reitz, 2019/08/09
- [Qemu-devel] [PATCH v6 22/42] block: Fix bdrv_get_allocated_file_size's fallback,
Max Reitz <=
[Qemu-devel] [PATCH v6 23/42] blockdev: Use CAF in external_snapshot_prepare(), Max Reitz, 2019/08/09
[Qemu-devel] [PATCH v6 24/42] block: Use child access functions for QAPI queries, Max Reitz, 2019/08/09
[Qemu-devel] [PATCH v6 26/42] backup: Deal with filters, Max Reitz, 2019/08/09
[Qemu-devel] [PATCH v6 25/42] mirror: Deal with filters, Max Reitz, 2019/08/09