[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Qemu-devel] [PULL 24/58] qcow2: Fix preallocation size formula
From: |
Kevin Wolf |
Subject: |
[Qemu-devel] [PULL 24/58] qcow2: Fix preallocation size formula |
Date: |
Thu, 11 May 2017 16:32:27 +0200 |
From: Max Reitz <address@hidden>
When calculating the number of reftable entries, we should actually use
the number of refblocks and not (wrongly[1]) re-calculate it.
[1] "Wrongly" means: Dividing the number of clusters by the number of
entries per refblock and rounding down instead of up.
Reported-by: Eric Blake <address@hidden>
Signed-off-by: Max Reitz <address@hidden>
Reviewed-by: Eric Blake <address@hidden>
Signed-off-by: Kevin Wolf <address@hidden>
---
block/qcow2.c | 9 +++++----
1 file changed, 5 insertions(+), 4 deletions(-)
diff --git a/block/qcow2.c b/block/qcow2.c
index 1c26977..8caf800 100644
--- a/block/qcow2.c
+++ b/block/qcow2.c
@@ -2139,7 +2139,7 @@ static int qcow2_create2(const char *filename, int64_t
total_size,
* too, as long as the bulk is allocated here). Therefore, using
* floating point arithmetic is fine. */
int64_t meta_size = 0;
- uint64_t nreftablee, nrefblocke, nl1e, nl2e;
+ uint64_t nreftablee, nrefblocke, nl1e, nl2e, refblock_count;
int64_t aligned_total_size = align_offset(total_size, cluster_size);
int refblock_bits, refblock_size;
/* refcount entry size in bytes */
@@ -2182,11 +2182,12 @@ static int qcow2_create2(const char *filename, int64_t
total_size,
nrefblocke = (aligned_total_size + meta_size + cluster_size)
/ (cluster_size - rces - rces * sizeof(uint64_t)
/ cluster_size);
- meta_size += DIV_ROUND_UP(nrefblocke, refblock_size) * cluster_size;
+ refblock_count = DIV_ROUND_UP(nrefblocke, refblock_size);
+ meta_size += refblock_count * cluster_size;
/* total size of refcount tables */
- nreftablee = nrefblocke / refblock_size;
- nreftablee = align_offset(nreftablee, cluster_size / sizeof(uint64_t));
+ nreftablee = align_offset(refblock_count,
+ cluster_size / sizeof(uint64_t));
meta_size += nreftablee * sizeof(uint64_t);
qemu_opt_set_number(opts, BLOCK_OPT_SIZE,
--
1.8.3.1
- [Qemu-devel] [PULL 11/58] iotests: 087: Don't attach test image twice, (continued)
- [Qemu-devel] [PULL 11/58] iotests: 087: Don't attach test image twice, Kevin Wolf, 2017/05/11
- [Qemu-devel] [PULL 16/58] file-win32: Error out if locking=on, Kevin Wolf, 2017/05/11
- [Qemu-devel] [PULL 17/58] tests: Disable image lock in test-replication, Kevin Wolf, 2017/05/11
- [Qemu-devel] [PULL 15/58] file-posix: Add 'locking' option, Kevin Wolf, 2017/05/11
- [Qemu-devel] [PULL 19/58] osdep: Add qemu_lock_fd and qemu_unlock_fd, Kevin Wolf, 2017/05/11
- [Qemu-devel] [PULL 13/58] iotests: 172: Use separate images for multiple devices, Kevin Wolf, 2017/05/11
- [Qemu-devel] [PULL 18/58] block: Reuse bs as backing hd for drive-backup sync=none, Kevin Wolf, 2017/05/11
- [Qemu-devel] [PULL 14/58] tests: Use null-co:// instead of /dev/null as the dummy image, Kevin Wolf, 2017/05/11
- [Qemu-devel] [PULL 20/58] osdep: Fall back to posix lock when OFD lock is unavailable, Kevin Wolf, 2017/05/11
- [Qemu-devel] [PULL 23/58] tests: Add POSIX image locking test case 182, Kevin Wolf, 2017/05/11
- [Qemu-devel] [PULL 24/58] qcow2: Fix preallocation size formula,
Kevin Wolf <=
- [Qemu-devel] [PULL 22/58] qemu-iotests: Add test case 153 for image locking, Kevin Wolf, 2017/05/11
- [Qemu-devel] [PULL 21/58] file-posix: Add image locking to perm operations, Kevin Wolf, 2017/05/11
- [Qemu-devel] [PULL 25/58] qcow2: Reuse preallocated zero clusters, Kevin Wolf, 2017/05/11
- [Qemu-devel] [PULL 26/58] qcow2: Discard preallocated zero clusters, Kevin Wolf, 2017/05/11
- [Qemu-devel] [PULL 27/58] iotests: Extend test 066, Kevin Wolf, 2017/05/11
- [Qemu-devel] [PULL 28/58] migration: Unify block node activation error handling, Kevin Wolf, 2017/05/11
- [Qemu-devel] [PULL 29/58] block: New BdrvChildRole.activate() for blk_resume_after_migration(), Kevin Wolf, 2017/05/11
- [Qemu-devel] [PULL 34/58] qemu-img: wait for convert coroutines to complete, Kevin Wolf, 2017/05/11
- [Qemu-devel] [PULL 30/58] block: Drop permissions when migration completes, Kevin Wolf, 2017/05/11
- [Qemu-devel] [PULL 35/58] nvme: Implement Write Zeroes, Kevin Wolf, 2017/05/11