[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Qemu-devel] [PULL 22/53] qcow2: Implement bdrv_make_empty()
From: |
Stefan Hajnoczi |
Subject: |
[Qemu-devel] [PULL 22/53] qcow2: Implement bdrv_make_empty() |
Date: |
Mon, 3 Nov 2014 11:50:25 +0000 |
From: Max Reitz <address@hidden>
Implement this function by making all clusters in the image file fall
through to the backing file (by using the recently extended discard).
Signed-off-by: Max Reitz <address@hidden>
Reviewed-by: Eric Blake <address@hidden>
Reviewed-by: Kevin Wolf <address@hidden>
Message-id: address@hidden
Signed-off-by: Stefan Hajnoczi <address@hidden>
---
block/qcow2.c | 27 +++++++++++++++++++++++++++
1 file changed, 27 insertions(+)
diff --git a/block/qcow2.c b/block/qcow2.c
index d64a4ba..bf871d5 100644
--- a/block/qcow2.c
+++ b/block/qcow2.c
@@ -2230,6 +2230,32 @@ fail:
return ret;
}
+static int qcow2_make_empty(BlockDriverState *bs)
+{
+ int ret = 0;
+ uint64_t start_sector;
+ int sector_step = INT_MAX / BDRV_SECTOR_SIZE;
+
+ for (start_sector = 0; start_sector < bs->total_sectors;
+ start_sector += sector_step)
+ {
+ /* As this function is generally used after committing an external
+ * snapshot, QCOW2_DISCARD_SNAPSHOT seems appropriate. Also, the
+ * default action for this kind of discard is to pass the discard,
+ * which will ideally result in an actually smaller image file, as
+ * is probably desired. */
+ ret = qcow2_discard_clusters(bs, start_sector * BDRV_SECTOR_SIZE,
+ MIN(sector_step,
+ bs->total_sectors - start_sector),
+ QCOW2_DISCARD_SNAPSHOT, true);
+ if (ret < 0) {
+ break;
+ }
+ }
+
+ return ret;
+}
+
static coroutine_fn int qcow2_co_flush_to_os(BlockDriverState *bs)
{
BDRVQcowState *s = bs->opaque;
@@ -2676,6 +2702,7 @@ static BlockDriver bdrv_qcow2 = {
.bdrv_co_discard = qcow2_co_discard,
.bdrv_truncate = qcow2_truncate,
.bdrv_write_compressed = qcow2_write_compressed,
+ .bdrv_make_empty = qcow2_make_empty,
.bdrv_snapshot_create = qcow2_snapshot_create,
.bdrv_snapshot_goto = qcow2_snapshot_goto,
--
1.9.3
- [Qemu-devel] [PULL 12/53] iotests: add v2 parallels sample image and simple test for it, (continued)
- [Qemu-devel] [PULL 12/53] iotests: add v2 parallels sample image and simple test for it, Stefan Hajnoczi, 2014/11/03
- [Qemu-devel] [PULL 13/53] block/parallels: fix access to not initialized memory in catalog_bitmap, Stefan Hajnoczi, 2014/11/03
- [Qemu-devel] [PULL 14/53] rbd: Add support for bdrv_invalidate_cache, Stefan Hajnoczi, 2014/11/03
- [Qemu-devel] [PULL 15/53] block.c: Fix type of IoOperationType variable in send_qmp_error_event(), Stefan Hajnoczi, 2014/11/03
- [Qemu-devel] [PULL 17/53] block/curl: Improve type safety of s->timeout., Stefan Hajnoczi, 2014/11/03
- [Qemu-devel] [PULL 16/53] snapshot: add bdrv_drain_all() to bdrv_snapshot_delete() to avoid concurrency problem, Stefan Hajnoczi, 2014/11/03
- [Qemu-devel] [PULL 18/53] raw-posix: Fix raw_co_get_block_status() after EOF, Stefan Hajnoczi, 2014/11/03
- [Qemu-devel] [PULL 19/53] raw-posix: raw_co_get_block_status() return value, Stefan Hajnoczi, 2014/11/03
- [Qemu-devel] [PULL 20/53] iotests: Add test for external image truncation, Stefan Hajnoczi, 2014/11/03
- [Qemu-devel] [PULL 21/53] qcow2: Allow "full" discard, Stefan Hajnoczi, 2014/11/03
- [Qemu-devel] [PULL 22/53] qcow2: Implement bdrv_make_empty(),
Stefan Hajnoczi <=
- [Qemu-devel] [PULL 23/53] qcow2: Optimize bdrv_make_empty(), Stefan Hajnoczi, 2014/11/03
- [Qemu-devel] [PULL 24/53] blockjob: Introduce block_job_complete_sync(), Stefan Hajnoczi, 2014/11/03
- [Qemu-devel] [PULL 26/53] iotests: Omit length/offset test in 040 and 041, Stefan Hajnoczi, 2014/11/03
- [Qemu-devel] [PULL 25/53] blockjob: Add "ready" field, Stefan Hajnoczi, 2014/11/03
- [Qemu-devel] [PULL 27/53] block/mirror: Improve progress report, Stefan Hajnoczi, 2014/11/03
- [Qemu-devel] [PULL 28/53] qemu-img: Implement commit like QMP, Stefan Hajnoczi, 2014/11/03
- [Qemu-devel] [PULL 29/53] qemu-img: Empty image after commit, Stefan Hajnoczi, 2014/11/03
- [Qemu-devel] [PULL 30/53] qemu-img: Enable progress output for commit, Stefan Hajnoczi, 2014/11/03
- [Qemu-devel] [PULL 31/53] qemu-img: Specify backing file for commit, Stefan Hajnoczi, 2014/11/03
- [Qemu-devel] [PULL 32/53] iotests: Add _filter_qemu_img_map, Stefan Hajnoczi, 2014/11/03