[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Qemu-devel] [PATCH v6 02/14] qcow2: Implement bdrv_make_empty()
From: |
Max Reitz |
Subject: |
[Qemu-devel] [PATCH v6 02/14] qcow2: Implement bdrv_make_empty() |
Date: |
Tue, 29 Apr 2014 17:07:40 +0200 |
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>
---
block/qcow2.c | 27 +++++++++++++++++++++++++++
1 file changed, 27 insertions(+)
diff --git a/block/qcow2.c b/block/qcow2.c
index 1e7b7d5..db34366 100644
--- a/block/qcow2.c
+++ b/block/qcow2.c
@@ -2006,6 +2006,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;
@@ -2388,6 +2414,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.2
- [Qemu-devel] [PATCH v6 00/14] qemu-img: Implement commit like QMP, Max Reitz, 2014/04/29
- [Qemu-devel] [PATCH v6 01/14] qcow2: Allow "full" discard, Max Reitz, 2014/04/29
- [Qemu-devel] [PATCH v6 02/14] qcow2: Implement bdrv_make_empty(),
Max Reitz <=
- [Qemu-devel] [PATCH v6 03/14] qcow2: Optimize bdrv_make_empty(), Max Reitz, 2014/04/29
- [Qemu-devel] [PATCH v6 04/14] blockjob: Introduce block_job_complete_sync(), Max Reitz, 2014/04/29
- [Qemu-devel] [PATCH v6 05/14] blockjob: Add "ready" field, Max Reitz, 2014/04/29
- [Qemu-devel] [PATCH v6 06/14] block/mirror: Improve progress report, Max Reitz, 2014/04/29
- [Qemu-devel] [PATCH v6 07/14] qemu-img: Implement commit like QMP, Max Reitz, 2014/04/29