[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Qemu-devel] [PATCH v2 02/18] qcow2: Save disk size in snapshot header
From: |
Kevin Wolf |
Subject: |
[Qemu-devel] [PATCH v2 02/18] qcow2: Save disk size in snapshot header |
Date: |
Mon, 16 Apr 2012 17:02:00 +0200 |
This allows that different snapshots of an image can have different
sizes, which is a requirement for enabling image resizing even with
images that have internal snapshots.
We don't do the actual support for it now, but make sure that the
additional field is present and not completely ignored in all version 3
images. When trying to load a snapshot of different size, it returns
an error.
Signed-off-by: Kevin Wolf <address@hidden>
---
block/qcow2-snapshot.c | 16 ++++++++++++++++
block/qcow2.h | 1 +
2 files changed, 17 insertions(+), 0 deletions(-)
diff --git a/block/qcow2-snapshot.c b/block/qcow2-snapshot.c
index 7d3fde5..42f971b 100644
--- a/block/qcow2-snapshot.c
+++ b/block/qcow2-snapshot.c
@@ -48,6 +48,7 @@ typedef struct QEMU_PACKED QCowSnapshotHeader {
typedef struct QEMU_PACKED QCowSnapshotExtraData {
uint64_t vm_state_size_large;
+ uint64_t disk_size;
} QCowSnapshotExtraData;
void qcow2_free_snapshots(BlockDriverState *bs)
@@ -117,6 +118,12 @@ int qcow2_read_snapshots(BlockDriverState *bs)
sn->vm_state_size = be64_to_cpu(extra.vm_state_size_large);
}
+ if (extra_data_size >= 16) {
+ sn->disk_size = be64_to_cpu(extra.disk_size);
+ } else {
+ sn->disk_size = bs->total_sectors * BDRV_SECTOR_SIZE;
+ }
+
/* Read snapshot ID */
sn->id_str = g_malloc(id_str_size + 1);
ret = bdrv_pread(bs->file, offset, sn->id_str, id_str_size);
@@ -197,6 +204,7 @@ static int qcow2_write_snapshots(BlockDriverState *bs)
memset(&extra, 0, sizeof(extra));
extra.vm_state_size_large = cpu_to_be64(sn->vm_state_size);
+ extra.disk_size = cpu_to_be64(sn->disk_size);
id_str_size = strlen(sn->id_str);
name_size = strlen(sn->name);
@@ -330,6 +338,7 @@ int qcow2_snapshot_create(BlockDriverState *bs,
QEMUSnapshotInfo *sn_info)
sn->id_str = g_strdup(sn_info->id_str);
sn->name = g_strdup(sn_info->name);
+ sn->disk_size = bs->total_sectors * BDRV_SECTOR_SIZE;
sn->vm_state_size = sn_info->vm_state_size;
sn->date_sec = sn_info->date_sec;
sn->date_nsec = sn_info->date_nsec;
@@ -426,6 +435,13 @@ int qcow2_snapshot_goto(BlockDriverState *bs, const char
*snapshot_id)
}
sn = &s->snapshots[snapshot_index];
+ if (sn->disk_size != bs->total_sectors * BDRV_SECTOR_SIZE) {
+ error_report("qcow2: Loading snapshots with different disk "
+ "size is not implemented");
+ ret = -ENOTSUP;
+ goto fail;
+ }
+
/*
* Make sure that the current L1 table is big enough to contain the whole
* L1 table of the snapshot. If the snapshot L1 table is smaller, the
diff --git a/block/qcow2.h b/block/qcow2.h
index e4ac366..ddb976a 100644
--- a/block/qcow2.h
+++ b/block/qcow2.h
@@ -78,6 +78,7 @@ typedef struct QCowSnapshot {
uint32_t l1_size;
char *id_str;
char *name;
+ uint64_t disk_size;
uint64_t vm_state_size;
uint32_t date_sec;
uint32_t date_nsec;
--
1.7.6.5
- [Qemu-devel] [PATCH v2 00/18] qcow2: Basic version 3 support, Kevin Wolf, 2012/04/16
- [Qemu-devel] [PATCH v2 01/18] Specification for qcow2 version 3, Kevin Wolf, 2012/04/16
- [Qemu-devel] [PATCH v2 02/18] qcow2: Save disk size in snapshot header,
Kevin Wolf <=
- [Qemu-devel] [PATCH v2 04/18] qcow2: Ignore reserved bits in count_contiguous_clusters(), Kevin Wolf, 2012/04/16
- [Qemu-devel] [PATCH v2 03/18] qcow2: Ignore reserved bits in get_cluster_offset, Kevin Wolf, 2012/04/16
- [Qemu-devel] [PATCH v2 05/18] qcow2: Fail write_compressed when overwriting data, Kevin Wolf, 2012/04/16
- [Qemu-devel] [PATCH v2 07/18] qcow2: Refactor qcow2_free_any_clusters, Kevin Wolf, 2012/04/16
- [Qemu-devel] [PATCH v2 06/18] qcow2: Ignore reserved bits in L1/L2 entries, Kevin Wolf, 2012/04/16
- [Qemu-devel] [PATCH v2 09/18] qcow2: Ignore reserved bits in refcount table entries, Kevin Wolf, 2012/04/16
- [Qemu-devel] [PATCH v2 12/18] qcow2: Support reading zero clusters, Kevin Wolf, 2012/04/16
- [Qemu-devel] [PATCH v2 08/18] qcow2: Simplify count_cow_clusters, Kevin Wolf, 2012/04/16
- [Qemu-devel] [PATCH v2 10/18] qcow2: Ignore reserved bits in check_refcounts, Kevin Wolf, 2012/04/16
- [Qemu-devel] [PATCH v2 13/18] qcow2: Support for feature table header extension, Kevin Wolf, 2012/04/16