[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Qemu-devel] [PULL 05/69] vpc: Implement bdrv_co_get_block_status()
From: |
Stefan Hajnoczi |
Subject: |
[Qemu-devel] [PULL 05/69] vpc: Implement bdrv_co_get_block_status() |
Date: |
Fri, 27 Feb 2015 18:18:03 +0000 |
From: Kevin Wolf <address@hidden>
This implements bdrv_co_get_block_status() for VHD images. This can
significantly speed up qemu-img convert operation because only with this
function implemented sparseness can be considered. (Before, converting a
1 TB empty image took several minutes for me, now it's instantaneous.)
Signed-off-by: Kevin Wolf <address@hidden>
Reviewed-by: Max Reitz <address@hidden>
---
block/vpc.c | 50 ++++++++++++++++++++++++++++++++++++++++++++++++--
1 file changed, 48 insertions(+), 2 deletions(-)
diff --git a/block/vpc.c b/block/vpc.c
index 7fddbf0..1533b6a 100644
--- a/block/vpc.c
+++ b/block/vpc.c
@@ -597,6 +597,51 @@ static coroutine_fn int vpc_co_write(BlockDriverState *bs,
int64_t sector_num,
return ret;
}
+static int64_t coroutine_fn vpc_co_get_block_status(BlockDriverState *bs,
+ int64_t sector_num, int nb_sectors, int *pnum)
+{
+ BDRVVPCState *s = bs->opaque;
+ VHDFooter *footer = (VHDFooter*) s->footer_buf;
+ int64_t start, offset, next;
+ bool allocated;
+ int n;
+
+ if (be32_to_cpu(footer->type) == VHD_FIXED) {
+ *pnum = nb_sectors;
+ return BDRV_BLOCK_RAW | BDRV_BLOCK_OFFSET_VALID | BDRV_BLOCK_DATA |
+ (sector_num << BDRV_SECTOR_BITS);
+ }
+
+ offset = get_sector_offset(bs, sector_num, 0);
+ start = offset;
+ allocated = (offset != -1);
+ *pnum = 0;
+
+ do {
+ /* All sectors in a block are contiguous (without using the bitmap) */
+ n = ROUND_UP(sector_num + 1, s->block_size / BDRV_SECTOR_SIZE)
+ - sector_num;
+ n = MIN(n, nb_sectors);
+
+ *pnum += n;
+ sector_num += n;
+ nb_sectors -= n;
+ next = start + (*pnum * BDRV_SECTOR_SIZE);
+
+ if (nb_sectors == 0) {
+ break;
+ }
+
+ offset = get_sector_offset(bs, sector_num, 0);
+ } while ((allocated && offset == next) || (!allocated && offset == -1));
+
+ if (allocated) {
+ return BDRV_BLOCK_DATA | BDRV_BLOCK_OFFSET_VALID | start;
+ } else {
+ return 0;
+ }
+}
+
/*
* Calculates the number of cylinders, heads and sectors per cylinder
* based on a given number of sectors. This is the algorithm described
@@ -903,8 +948,9 @@ static BlockDriver bdrv_vpc = {
.bdrv_reopen_prepare = vpc_reopen_prepare,
.bdrv_create = vpc_create,
- .bdrv_read = vpc_co_read,
- .bdrv_write = vpc_co_write,
+ .bdrv_read = vpc_co_read,
+ .bdrv_write = vpc_co_write,
+ .bdrv_co_get_block_status = vpc_co_get_block_status,
.bdrv_get_info = vpc_get_info,
--
2.1.0
- [Qemu-devel] [PULL 00/69] Block patches, Stefan Hajnoczi, 2015/02/27
- [Qemu-devel] [PULL 03/69] test-coroutine: Regression test for yield bug, Stefan Hajnoczi, 2015/02/27
- [Qemu-devel] [PULL 01/69] coroutine: Fix use after free with qemu_coroutine_yield(), Stefan Hajnoczi, 2015/02/27
- [Qemu-devel] [PULL 02/69] coroutine: Clean up qemu_coroutine_enter(), Stefan Hajnoczi, 2015/02/27
- [Qemu-devel] [PULL 04/69] vpc: Fix size in fixed image creation, Stefan Hajnoczi, 2015/02/27
- [Qemu-devel] [PULL 07/69] block/raw-posix: fix compilation warning on OSX, Stefan Hajnoczi, 2015/02/27
- [Qemu-devel] [PULL 05/69] vpc: Implement bdrv_co_get_block_status(),
Stefan Hajnoczi <=
- [Qemu-devel] [PULL 08/69] qcow2: Remove unused struct QCowCreateState, Stefan Hajnoczi, 2015/02/27
- [Qemu-devel] [PULL 09/69] virtio-blk: Check return value of blk_aio_ioctl, Stefan Hajnoczi, 2015/02/27
- [Qemu-devel] [PULL 11/69] tests: Prepare virtio-blk-test for multi-arch implementation, Stefan Hajnoczi, 2015/02/27
- [Qemu-devel] [PULL 10/69] libqos: Change use of pointers to uint64_t in virtio, Stefan Hajnoczi, 2015/02/27
- [Qemu-devel] [PULL 12/69] libqos: Remove PCI assumptions in constants of virtio driver, Stefan Hajnoczi, 2015/02/27
- [Qemu-devel] [PULL 13/69] libqos: Add malloc generic, Stefan Hajnoczi, 2015/02/27
- [Qemu-devel] [PULL 06/69] sheepdog: selectable object size support, Stefan Hajnoczi, 2015/02/27
- [Qemu-devel] [PULL 16/69] qcow2: Add refcount_bits to format-specific info, Stefan Hajnoczi, 2015/02/27
- [Qemu-devel] [PULL 14/69] libqos: Add virtio MMIO support, Stefan Hajnoczi, 2015/02/27
- [Qemu-devel] [PULL 15/69] qcow2: Add two new fields to BDRVQcowState, Stefan Hajnoczi, 2015/02/27