On Tue, 19 Apr 2011, Prasad Joshi wrote:
On Tue, Apr 19, 2011 at 10:07 PM, Pekka Enberg <penberg@xxxxxxxxxx> wrote: This patch extends the QCOW1 format to also support QCOW2 images as specified by the following document: http://people.gnome.org/~markmc/qcow-image-format.html Cc: Asias He <asias.hejun@xxxxxxxxx> Cc: Cyrill Gorcunov <gorcunov@xxxxxxxxx> Cc: Prasad Joshi <prasadjoshi124@xxxxxxxxx> Cc: Sasha Levin <levinsasha928@xxxxxxxxx> Cc: Ingo Molnar <mingo@xxxxxxx> Signed-off-by: Pekka Enberg <penberg@xxxxxxxxxx> --- tools/kvm/include/kvm/qcow.h | 42 ++++++++++- tools/kvm/qcow.c | 177 +++++++++++++++++++++++++++++++++--------- 2 files changed, 181 insertions(+), 38 deletions(-) diff --git a/tools/kvm/include/kvm/qcow.h b/tools/kvm/include/kvm/qcow.h index 4be2597..afd776d 100644 --- a/tools/kvm/include/kvm/qcow.h +++ b/tools/kvm/include/kvm/qcow.h @@ -4,9 +4,17 @@ #include <linux/types.h> #define QCOW_MAGIC (('Q' << 24) | ('F' << 16) | ('I' << 8) | 0xfb) + #define QCOW1_VERSION 1 +#define QCOW2_VERSION 2 + +#define QCOW1_OFLAG_COMPRESSED (1LL << 63) + +#define QCOW1_OFLAG_MASK QCOW1_OFLAG_COMPRESSED -#define QCOW_OFLAG_COMPRESSED (1LL << 63) +#define QCOW2_OFLAG_COPIED (1LL << 63) +#define QCOW2_OFLAG_COMPRESSED (1LL << 62) +#define QCOW2_OFLAG_MASK (QCOW2_OFLAG_COPIED|QCOW2_OFLAG_COMPRESSED) struct qcow_table { u32 table_size; @@ -19,7 +27,16 @@ struct qcow { int fd; }; -struct qcow1_header { +struct qcow_header { + u64 size; /* in bytes */ + u64 l1_table_offset; + u32 l1_size; + u8 cluster_bits; + u8 l2_bits; + uint64_t oflag_mask; +}; + +struct qcow1_header_disk { u32 magic; u32 version; @@ -36,6 +53,27 @@ struct qcow1_header { u64 l1_table_offset; }; +struct qcow2_header_disk { + u32 magic; + u32 version; + + u64 backing_file_offset; + u32 backing_file_size; + + u32 cluster_bits; + u64 size; /* in bytes */ + u32 crypt_method; + + u32 l1_size; + u64 l1_table_offset; + + u64 refcount_table_offset; + u32 refcount_table_clusters; + + u32 nb_snapshots; + u64 snapshots_offset; +}; IMHO, as we start adding other features of QCOW, the two structures qcow2_header_disk and qcow_header might eventually become the same.
No, the point of 'struct qcow2_header_disk' is to map to the on-disk representation. 'struct qcow_header' is the in-memory version of the data.
+ disk_image = disk_image__new(fd, h->size, &qcow1_disk_ops); qcow1_disk_ops can be changed to qcow_disk_ops.
Sure, there's more qcow1 prefixes that need fixing now as well.