[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PATCH v7 26/47] block: Improve get_allocated_file_size's default
From: |
Max Reitz |
Subject: |
[PATCH v7 26/47] block: Improve get_allocated_file_size's default |
Date: |
Thu, 25 Jun 2020 17:21:54 +0200 |
There are two practical problems with bdrv_get_allocated_file_size()'s
default right now:
(1) For drivers with children, we should generally sum all their sizes
instead of just passing the request through to bs->file. The latter
is good for filters, but not so much for format drivers.
(2) Filters need not have bs->file, so we should actually go to the
filtered child instead of hard-coding bs->file.
And we can make the whole default implementation more idiomatic by using
the three generic functions added by the previous patch.
Signed-off-by: Max Reitz <mreitz@redhat.com>
---
block.c | 17 ++++++++++++++---
1 file changed, 14 insertions(+), 3 deletions(-)
diff --git a/block.c b/block.c
index fc01ce90b3..a19f243997 100644
--- a/block.c
+++ b/block.c
@@ -4997,10 +4997,21 @@ 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 (drv->bdrv_file_open) {
+ /*
+ * Protocol drivers default to -ENOTSUP (most of their data is
+ * not stored in any of their children (if they even have any),
+ * so there is no generic way to figure it out).
+ */
+ return bdrv_notsup_allocated_file_size(bs);
+ } else if (drv->is_filter) {
+ /* Filter drivers default to the size of their primary child */
+ return bdrv_primary_allocated_file_size(bs);
+ } else {
+ /* Other drivers default to summing their children's sizes */
+ return bdrv_sum_allocated_file_size(bs);
}
- return -ENOTSUP;
}
/**
--
2.26.2
- [PATCH v7 16/47] block: Use bdrv_cow_child() in bdrv_co_truncate(), (continued)
- [PATCH v7 16/47] block: Use bdrv_cow_child() in bdrv_co_truncate(), Max Reitz, 2020/06/25
- [PATCH v7 18/47] block: Flush all children in generic code, Max Reitz, 2020/06/25
- [PATCH v7 17/47] block: Re-evaluate backing file handling in reopen, Max Reitz, 2020/06/25
- [PATCH v7 19/47] vmdk: Drop vmdk_co_flush(), Max Reitz, 2020/06/25
- [PATCH v7 20/47] block: Iterate over children in refresh_limits, Max Reitz, 2020/06/25
- [PATCH v7 21/47] block: Use CAFs in bdrv_refresh_filename(), Max Reitz, 2020/06/25
- [PATCH v7 22/47] block: Use CAF in bdrv_co_rw_vmstate(), Max Reitz, 2020/06/25
- [PATCH v7 23/47] block/snapshot: Fix fallback, Max Reitz, 2020/06/25
- [PATCH v7 25/47] block: Def. impl.s for get_allocated_file_size, Max Reitz, 2020/06/25
- [PATCH v7 24/47] block: Use CAFs for debug breakpoints, Max Reitz, 2020/06/25
- [PATCH v7 26/47] block: Improve get_allocated_file_size's default,
Max Reitz <=
- [PATCH v7 28/47] block/null: Implement bdrv_get_allocated_file_size, Max Reitz, 2020/06/25
- [PATCH v7 31/47] block: Use child access functions for QAPI queries, Max Reitz, 2020/06/25
- [PATCH v7 32/47] block-copy: Use CAF to find sync=top base, Max Reitz, 2020/06/25
- [PATCH v7 33/47] mirror: Deal with filters, Max Reitz, 2020/06/25
- [PATCH v7 29/47] blockdev: Use CAF in external_snapshot_prepare(), Max Reitz, 2020/06/25
- [PATCH v7 27/47] blkverify: Use bdrv_sum_allocated_file_size(), Max Reitz, 2020/06/25
- [PATCH v7 30/47] block: Report data child for query-blockstats, Max Reitz, 2020/06/25
- [PATCH v7 34/47] backup: Deal with filters, Max Reitz, 2020/06/25
- [PATCH v7 36/47] nbd: Use CAF when looking for dirty bitmap, Max Reitz, 2020/06/25
- [PATCH v7 37/47] qemu-img: Use child access functions, Max Reitz, 2020/06/25