[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Qemu-devel] [PULL 25/41] COW: Extend checking allocated bits to beyond
From: |
Kevin Wolf |
Subject: |
[Qemu-devel] [PULL 25/41] COW: Extend checking allocated bits to beyond one sector |
Date: |
Fri, 29 Nov 2013 17:45:40 +0100 |
From: Charlie Shepherd <address@hidden>
cow_co_is_allocated() only checks one sector's worth of allocated bits
before returning. This is allowed but (slightly) inefficient, so extend
it to check all of the file's metadata sectors.
Signed-off-by: Charlie Shepherd <address@hidden>
Reviewed-by: Paolo Bonzini <address@hidden>
Signed-off-by: Stefan Hajnoczi <address@hidden>
[kwolf: silenced compiler warning (-Wmaybe-uninitialized for changed)]
Signed-off-by: Kevin Wolf <address@hidden>
---
block/cow.c | 36 ++++++++++++++++++++++++++----------
1 file changed, 26 insertions(+), 10 deletions(-)
diff --git a/block/cow.c b/block/cow.c
index f759496..dc15e46 100644
--- a/block/cow.c
+++ b/block/cow.c
@@ -152,18 +152,34 @@ static int coroutine_fn
cow_co_is_allocated(BlockDriverState *bs,
{
int64_t bitnum = sector_num + sizeof(struct cow_header_v2) * 8;
uint64_t offset = (bitnum / 8) & -BDRV_SECTOR_SIZE;
- uint8_t bitmap[BDRV_SECTOR_SIZE];
- int ret;
- int changed;
+ bool first = true;
+ int changed = 0, same = 0;
- ret = bdrv_pread(bs->file, offset, &bitmap, sizeof(bitmap));
- if (ret < 0) {
- return ret;
- }
+ do {
+ int ret;
+ uint8_t bitmap[BDRV_SECTOR_SIZE];
+
+ bitnum &= BITS_PER_BITMAP_SECTOR - 1;
+ int sector_bits = MIN(nb_sectors, BITS_PER_BITMAP_SECTOR - bitnum);
+
+ ret = bdrv_pread(bs->file, offset, &bitmap, sizeof(bitmap));
+ if (ret < 0) {
+ return ret;
+ }
+
+ if (first) {
+ changed = cow_test_bit(bitnum, bitmap);
+ first = false;
+ }
+
+ same += cow_find_streak(bitmap, changed, bitnum, nb_sectors);
+
+ bitnum += sector_bits;
+ nb_sectors -= sector_bits;
+ offset += BDRV_SECTOR_SIZE;
+ } while (nb_sectors);
- bitnum &= BITS_PER_BITMAP_SECTOR - 1;
- changed = cow_test_bit(bitnum, bitmap);
- *num_same = cow_find_streak(bitmap, changed, bitnum, nb_sectors);
+ *num_same = same;
return changed;
}
--
1.8.1.4
- [Qemu-devel] [PULL 14/41] block: introduce bdrv_make_zero, (continued)
- [Qemu-devel] [PULL 14/41] block: introduce bdrv_make_zero, Kevin Wolf, 2013/11/29
- [Qemu-devel] [PULL 15/41] block/get_block_status: fix BDRV_BLOCK_ZERO for unallocated blocks, Kevin Wolf, 2013/11/29
- [Qemu-devel] [PULL 16/41] qemu-img: add support for fully allocated images, Kevin Wolf, 2013/11/29
- [Qemu-devel] [PULL 17/41] qemu-img: conditionally zero out target on convert, Kevin Wolf, 2013/11/29
- [Qemu-devel] [PULL 18/41] util/error: Save errno from clobbering, Kevin Wolf, 2013/11/29
- [Qemu-devel] [PULL 19/41] Test coroutine execution order, Kevin Wolf, 2013/11/29
- [Qemu-devel] [PULL 20/41] sheepdog: implement .bdrv_get_allocated_file_size, Kevin Wolf, 2013/11/29
- [Qemu-devel] [PULL 21/41] block/stream: Don't stream unbacked devices, Kevin Wolf, 2013/11/29
- [Qemu-devel] [PULL 22/41] block: per caller dirty bitmap, Kevin Wolf, 2013/11/29
- [Qemu-devel] [PULL 24/41] COW: Speed up writes, Kevin Wolf, 2013/11/29
- [Qemu-devel] [PULL 25/41] COW: Extend checking allocated bits to beyond one sector,
Kevin Wolf <=
- [Qemu-devel] [PULL 26/41] MAINTAINERS: add sheepdog development mailing list, Kevin Wolf, 2013/11/29
- [Qemu-devel] [PULL 23/41] qapi: Change BlockDirtyInfo to list, Kevin Wolf, 2013/11/29
- [Qemu-devel] [PULL 27/41] qdict: Fix memory leak in qdict_do_flatten(), Kevin Wolf, 2013/11/29
- [Qemu-devel] [PULL 28/41] qdict: Optimise qdict_do_flatten(), Kevin Wolf, 2013/11/29
- [Qemu-devel] [PULL 29/41] sheepdog: refactor do_sd_create(), Kevin Wolf, 2013/11/29
- [Qemu-devel] [PULL 31/41] qemu-iotests: Drop local version of cancel_and_wait from 040, Kevin Wolf, 2013/11/29
- [Qemu-devel] [PULL 30/41] sheepdog: support user-defined redundancy option, Kevin Wolf, 2013/11/29
- [Qemu-devel] [PULL 32/41] blkdebug: add "remove_break" command, Kevin Wolf, 2013/11/29
- [Qemu-devel] [PULL 33/41] qemu-iotest: Add pause_drive and resume_drive methods, Kevin Wolf, 2013/11/29