|
|
9ae3a8 |
From 88e96c366d923305d0d3f124bbe295ef5068c6bc Mon Sep 17 00:00:00 2001
|
|
|
9ae3a8 |
From: Jeffrey Cody <jcody@redhat.com>
|
|
|
9ae3a8 |
Date: Wed, 20 Nov 2013 19:43:54 +0100
|
|
|
9ae3a8 |
Subject: [PATCH 11/25] block: vhdx - break endian translation functions out
|
|
|
9ae3a8 |
|
|
|
9ae3a8 |
RH-Author: Jeffrey Cody <jcody@redhat.com>
|
|
|
9ae3a8 |
Message-id: <0f4c21e92172fde45d0a5c609a19afa2e1f5a015.1384975172.git.jcody@redhat.com>
|
|
|
9ae3a8 |
Patchwork-id: 55804
|
|
|
9ae3a8 |
O-Subject: [RHEL7 qemu-kvm PATCH 11/26] block: vhdx - break endian translation functions out
|
|
|
9ae3a8 |
Bugzilla: 879234
|
|
|
9ae3a8 |
RH-Acked-by: Stefan Hajnoczi <stefanha@redhat.com>
|
|
|
9ae3a8 |
RH-Acked-by: Paolo Bonzini <pbonzini@redhat.com>
|
|
|
9ae3a8 |
RH-Acked-by: Fam Zheng <famz@redhat.com>
|
|
|
9ae3a8 |
|
|
|
9ae3a8 |
This moves the endian translation functions out from the vhdx.c source,
|
|
|
9ae3a8 |
into a separate source file. In addition to the previously defined
|
|
|
9ae3a8 |
endian functions, new endian translation functions for log support are
|
|
|
9ae3a8 |
added as well.
|
|
|
9ae3a8 |
|
|
|
9ae3a8 |
Signed-off-by: Jeff Cody <jcody@redhat.com>
|
|
|
9ae3a8 |
Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com>
|
|
|
9ae3a8 |
(cherry picked from commit 0f48e8f0978afe0bd44c63749e7df6411da6c437)
|
|
|
9ae3a8 |
---
|
|
|
9ae3a8 |
block/Makefile.objs | 2 +-
|
|
|
9ae3a8 |
block/vhdx-endian.c | 141 ++++++++++++++++++++++++++++++++++++++++++++++++++++
|
|
|
9ae3a8 |
block/vhdx.c | 43 ----------------
|
|
|
9ae3a8 |
block/vhdx.h | 8 +++
|
|
|
9ae3a8 |
4 files changed, 150 insertions(+), 44 deletions(-)
|
|
|
9ae3a8 |
create mode 100644 block/vhdx-endian.c
|
|
|
9ae3a8 |
|
|
|
9ae3a8 |
Signed-off-by: Miroslav Rezanina <mrezanin@redhat.com>
|
|
|
9ae3a8 |
---
|
|
|
9ae3a8 |
block/Makefile.objs | 2 +-
|
|
|
9ae3a8 |
block/vhdx-endian.c | 141 +++++++++++++++++++++++++++++++++++++++++++++++++++
|
|
|
9ae3a8 |
block/vhdx.c | 43 ----------------
|
|
|
9ae3a8 |
block/vhdx.h | 8 +++
|
|
|
9ae3a8 |
4 files changed, 150 insertions(+), 44 deletions(-)
|
|
|
9ae3a8 |
create mode 100644 block/vhdx-endian.c
|
|
|
9ae3a8 |
|
|
|
9ae3a8 |
diff --git a/block/Makefile.objs b/block/Makefile.objs
|
|
|
9ae3a8 |
index 114f8a5..a7b3b87 100644
|
|
|
9ae3a8 |
--- a/block/Makefile.objs
|
|
|
9ae3a8 |
+++ b/block/Makefile.objs
|
|
|
9ae3a8 |
@@ -2,7 +2,7 @@ block-obj-y += raw.o cow.o qcow.o vdi.o vmdk.o cloop.o dmg.o bochs.o vpc.o vvfat
|
|
|
9ae3a8 |
block-obj-y += qcow2.o qcow2-refcount.o qcow2-cluster.o qcow2-snapshot.o qcow2-cache.o
|
|
|
9ae3a8 |
block-obj-y += qed.o qed-gencb.o qed-l2-cache.o qed-table.o qed-cluster.o
|
|
|
9ae3a8 |
block-obj-y += qed-check.o
|
|
|
9ae3a8 |
-block-obj-$(CONFIG_VHDX) += vhdx.o
|
|
|
9ae3a8 |
+block-obj-$(CONFIG_VHDX) += vhdx.o vhdx-endian.o
|
|
|
9ae3a8 |
block-obj-y += parallels.o blkdebug.o blkverify.o
|
|
|
9ae3a8 |
block-obj-y += snapshot.o qapi.o
|
|
|
9ae3a8 |
block-obj-$(CONFIG_WIN32) += raw-win32.o win32-aio.o
|
|
|
9ae3a8 |
diff --git a/block/vhdx-endian.c b/block/vhdx-endian.c
|
|
|
9ae3a8 |
new file mode 100644
|
|
|
9ae3a8 |
index 0000000..3e93e63
|
|
|
9ae3a8 |
--- /dev/null
|
|
|
9ae3a8 |
+++ b/block/vhdx-endian.c
|
|
|
9ae3a8 |
@@ -0,0 +1,141 @@
|
|
|
9ae3a8 |
+/*
|
|
|
9ae3a8 |
+ * Block driver for Hyper-V VHDX Images
|
|
|
9ae3a8 |
+ *
|
|
|
9ae3a8 |
+ * Copyright (c) 2013 Red Hat, Inc.,
|
|
|
9ae3a8 |
+ *
|
|
|
9ae3a8 |
+ * Authors:
|
|
|
9ae3a8 |
+ * Jeff Cody <jcody@redhat.com>
|
|
|
9ae3a8 |
+ *
|
|
|
9ae3a8 |
+ * This is based on the "VHDX Format Specification v1.00", published 8/25/2012
|
|
|
9ae3a8 |
+ * by Microsoft:
|
|
|
9ae3a8 |
+ * https://www.microsoft.com/en-us/download/details.aspx?id=34750
|
|
|
9ae3a8 |
+ *
|
|
|
9ae3a8 |
+ * This work is licensed under the terms of the GNU LGPL, version 2 or later.
|
|
|
9ae3a8 |
+ * See the COPYING.LIB file in the top-level directory.
|
|
|
9ae3a8 |
+ *
|
|
|
9ae3a8 |
+ */
|
|
|
9ae3a8 |
+
|
|
|
9ae3a8 |
+#include "qemu-common.h"
|
|
|
9ae3a8 |
+#include "block/block_int.h"
|
|
|
9ae3a8 |
+#include "block/vhdx.h"
|
|
|
9ae3a8 |
+
|
|
|
9ae3a8 |
+#include <uuid/uuid.h>
|
|
|
9ae3a8 |
+
|
|
|
9ae3a8 |
+
|
|
|
9ae3a8 |
+/*
|
|
|
9ae3a8 |
+ * All the VHDX formats on disk are little endian - the following
|
|
|
9ae3a8 |
+ * are helper import/export functions to correctly convert
|
|
|
9ae3a8 |
+ * endianness from disk read to native cpu format, and back again.
|
|
|
9ae3a8 |
+ */
|
|
|
9ae3a8 |
+
|
|
|
9ae3a8 |
+
|
|
|
9ae3a8 |
+/* VHDX File Header */
|
|
|
9ae3a8 |
+
|
|
|
9ae3a8 |
+
|
|
|
9ae3a8 |
+void vhdx_header_le_import(VHDXHeader *h)
|
|
|
9ae3a8 |
+{
|
|
|
9ae3a8 |
+ assert(h != NULL);
|
|
|
9ae3a8 |
+
|
|
|
9ae3a8 |
+ le32_to_cpus(&h->signature);
|
|
|
9ae3a8 |
+ le32_to_cpus(&h->checksum);
|
|
|
9ae3a8 |
+ le64_to_cpus(&h->sequence_number);
|
|
|
9ae3a8 |
+
|
|
|
9ae3a8 |
+ leguid_to_cpus(&h->file_write_guid);
|
|
|
9ae3a8 |
+ leguid_to_cpus(&h->data_write_guid);
|
|
|
9ae3a8 |
+ leguid_to_cpus(&h->log_guid);
|
|
|
9ae3a8 |
+
|
|
|
9ae3a8 |
+ le16_to_cpus(&h->log_version);
|
|
|
9ae3a8 |
+ le16_to_cpus(&h->version);
|
|
|
9ae3a8 |
+ le32_to_cpus(&h->log_length);
|
|
|
9ae3a8 |
+ le64_to_cpus(&h->log_offset);
|
|
|
9ae3a8 |
+}
|
|
|
9ae3a8 |
+
|
|
|
9ae3a8 |
+void vhdx_header_le_export(VHDXHeader *orig_h, VHDXHeader *new_h)
|
|
|
9ae3a8 |
+{
|
|
|
9ae3a8 |
+ assert(orig_h != NULL);
|
|
|
9ae3a8 |
+ assert(new_h != NULL);
|
|
|
9ae3a8 |
+
|
|
|
9ae3a8 |
+ new_h->signature = cpu_to_le32(orig_h->signature);
|
|
|
9ae3a8 |
+ new_h->checksum = cpu_to_le32(orig_h->checksum);
|
|
|
9ae3a8 |
+ new_h->sequence_number = cpu_to_le64(orig_h->sequence_number);
|
|
|
9ae3a8 |
+
|
|
|
9ae3a8 |
+ new_h->file_write_guid = orig_h->file_write_guid;
|
|
|
9ae3a8 |
+ new_h->data_write_guid = orig_h->data_write_guid;
|
|
|
9ae3a8 |
+ new_h->log_guid = orig_h->log_guid;
|
|
|
9ae3a8 |
+
|
|
|
9ae3a8 |
+ cpu_to_leguids(&new_h->file_write_guid);
|
|
|
9ae3a8 |
+ cpu_to_leguids(&new_h->data_write_guid);
|
|
|
9ae3a8 |
+ cpu_to_leguids(&new_h->log_guid);
|
|
|
9ae3a8 |
+
|
|
|
9ae3a8 |
+ new_h->log_version = cpu_to_le16(orig_h->log_version);
|
|
|
9ae3a8 |
+ new_h->version = cpu_to_le16(orig_h->version);
|
|
|
9ae3a8 |
+ new_h->log_length = cpu_to_le32(orig_h->log_length);
|
|
|
9ae3a8 |
+ new_h->log_offset = cpu_to_le64(orig_h->log_offset);
|
|
|
9ae3a8 |
+}
|
|
|
9ae3a8 |
+
|
|
|
9ae3a8 |
+
|
|
|
9ae3a8 |
+/* VHDX Log Headers */
|
|
|
9ae3a8 |
+
|
|
|
9ae3a8 |
+
|
|
|
9ae3a8 |
+void vhdx_log_desc_le_import(VHDXLogDescriptor *d)
|
|
|
9ae3a8 |
+{
|
|
|
9ae3a8 |
+ assert(d != NULL);
|
|
|
9ae3a8 |
+
|
|
|
9ae3a8 |
+ le32_to_cpus(&d->signature);
|
|
|
9ae3a8 |
+ le32_to_cpus(&d->trailing_bytes);
|
|
|
9ae3a8 |
+ le64_to_cpus(&d->leading_bytes);
|
|
|
9ae3a8 |
+ le64_to_cpus(&d->file_offset);
|
|
|
9ae3a8 |
+ le64_to_cpus(&d->sequence_number);
|
|
|
9ae3a8 |
+}
|
|
|
9ae3a8 |
+
|
|
|
9ae3a8 |
+void vhdx_log_desc_le_export(VHDXLogDescriptor *d)
|
|
|
9ae3a8 |
+{
|
|
|
9ae3a8 |
+ assert(d != NULL);
|
|
|
9ae3a8 |
+
|
|
|
9ae3a8 |
+ cpu_to_le32s(&d->signature);
|
|
|
9ae3a8 |
+ cpu_to_le32s(&d->trailing_bytes);
|
|
|
9ae3a8 |
+ cpu_to_le64s(&d->leading_bytes);
|
|
|
9ae3a8 |
+ cpu_to_le64s(&d->file_offset);
|
|
|
9ae3a8 |
+ cpu_to_le64s(&d->sequence_number);
|
|
|
9ae3a8 |
+}
|
|
|
9ae3a8 |
+
|
|
|
9ae3a8 |
+void vhdx_log_data_le_export(VHDXLogDataSector *d)
|
|
|
9ae3a8 |
+{
|
|
|
9ae3a8 |
+ assert(d != NULL);
|
|
|
9ae3a8 |
+
|
|
|
9ae3a8 |
+ cpu_to_le32s(&d->data_signature);
|
|
|
9ae3a8 |
+ cpu_to_le32s(&d->sequence_high);
|
|
|
9ae3a8 |
+ cpu_to_le32s(&d->sequence_low);
|
|
|
9ae3a8 |
+}
|
|
|
9ae3a8 |
+
|
|
|
9ae3a8 |
+void vhdx_log_entry_hdr_le_import(VHDXLogEntryHeader *hdr)
|
|
|
9ae3a8 |
+{
|
|
|
9ae3a8 |
+ assert(hdr != NULL);
|
|
|
9ae3a8 |
+
|
|
|
9ae3a8 |
+ le32_to_cpus(&hdr->signature);
|
|
|
9ae3a8 |
+ le32_to_cpus(&hdr->checksum);
|
|
|
9ae3a8 |
+ le32_to_cpus(&hdr->entry_length);
|
|
|
9ae3a8 |
+ le32_to_cpus(&hdr->tail);
|
|
|
9ae3a8 |
+ le64_to_cpus(&hdr->sequence_number);
|
|
|
9ae3a8 |
+ le32_to_cpus(&hdr->descriptor_count);
|
|
|
9ae3a8 |
+ leguid_to_cpus(&hdr->log_guid);
|
|
|
9ae3a8 |
+ le64_to_cpus(&hdr->flushed_file_offset);
|
|
|
9ae3a8 |
+ le64_to_cpus(&hdr->last_file_offset);
|
|
|
9ae3a8 |
+}
|
|
|
9ae3a8 |
+
|
|
|
9ae3a8 |
+void vhdx_log_entry_hdr_le_export(VHDXLogEntryHeader *hdr)
|
|
|
9ae3a8 |
+{
|
|
|
9ae3a8 |
+ assert(hdr != NULL);
|
|
|
9ae3a8 |
+
|
|
|
9ae3a8 |
+ cpu_to_le32s(&hdr->signature);
|
|
|
9ae3a8 |
+ cpu_to_le32s(&hdr->checksum);
|
|
|
9ae3a8 |
+ cpu_to_le32s(&hdr->entry_length);
|
|
|
9ae3a8 |
+ cpu_to_le32s(&hdr->tail);
|
|
|
9ae3a8 |
+ cpu_to_le64s(&hdr->sequence_number);
|
|
|
9ae3a8 |
+ cpu_to_le32s(&hdr->descriptor_count);
|
|
|
9ae3a8 |
+ cpu_to_leguids(&hdr->log_guid);
|
|
|
9ae3a8 |
+ cpu_to_le64s(&hdr->flushed_file_offset);
|
|
|
9ae3a8 |
+ cpu_to_le64s(&hdr->last_file_offset);
|
|
|
9ae3a8 |
+}
|
|
|
9ae3a8 |
+
|
|
|
9ae3a8 |
+
|
|
|
9ae3a8 |
diff --git a/block/vhdx.c b/block/vhdx.c
|
|
|
9ae3a8 |
index 16321ff..2efece1 100644
|
|
|
9ae3a8 |
--- a/block/vhdx.c
|
|
|
9ae3a8 |
+++ b/block/vhdx.c
|
|
|
9ae3a8 |
@@ -223,49 +223,6 @@ static int vhdx_probe(const uint8_t *buf, int buf_size, const char *filename)
|
|
|
9ae3a8 |
return 0;
|
|
|
9ae3a8 |
}
|
|
|
9ae3a8 |
|
|
|
9ae3a8 |
-/* All VHDX structures on disk are little endian */
|
|
|
9ae3a8 |
-static void vhdx_header_le_import(VHDXHeader *h)
|
|
|
9ae3a8 |
-{
|
|
|
9ae3a8 |
- assert(h != NULL);
|
|
|
9ae3a8 |
-
|
|
|
9ae3a8 |
- le32_to_cpus(&h->signature);
|
|
|
9ae3a8 |
- le32_to_cpus(&h->checksum);
|
|
|
9ae3a8 |
- le64_to_cpus(&h->sequence_number);
|
|
|
9ae3a8 |
-
|
|
|
9ae3a8 |
- leguid_to_cpus(&h->file_write_guid);
|
|
|
9ae3a8 |
- leguid_to_cpus(&h->data_write_guid);
|
|
|
9ae3a8 |
- leguid_to_cpus(&h->log_guid);
|
|
|
9ae3a8 |
-
|
|
|
9ae3a8 |
- le16_to_cpus(&h->log_version);
|
|
|
9ae3a8 |
- le16_to_cpus(&h->version);
|
|
|
9ae3a8 |
- le32_to_cpus(&h->log_length);
|
|
|
9ae3a8 |
- le64_to_cpus(&h->log_offset);
|
|
|
9ae3a8 |
-}
|
|
|
9ae3a8 |
-
|
|
|
9ae3a8 |
-/* All VHDX structures on disk are little endian */
|
|
|
9ae3a8 |
-static void vhdx_header_le_export(VHDXHeader *orig_h, VHDXHeader *new_h)
|
|
|
9ae3a8 |
-{
|
|
|
9ae3a8 |
- assert(orig_h != NULL);
|
|
|
9ae3a8 |
- assert(new_h != NULL);
|
|
|
9ae3a8 |
-
|
|
|
9ae3a8 |
- new_h->signature = cpu_to_le32(orig_h->signature);
|
|
|
9ae3a8 |
- new_h->checksum = cpu_to_le32(orig_h->checksum);
|
|
|
9ae3a8 |
- new_h->sequence_number = cpu_to_le64(orig_h->sequence_number);
|
|
|
9ae3a8 |
-
|
|
|
9ae3a8 |
- new_h->file_write_guid = orig_h->file_write_guid;
|
|
|
9ae3a8 |
- new_h->data_write_guid = orig_h->data_write_guid;
|
|
|
9ae3a8 |
- new_h->log_guid = orig_h->log_guid;
|
|
|
9ae3a8 |
-
|
|
|
9ae3a8 |
- cpu_to_leguids(&new_h->file_write_guid);
|
|
|
9ae3a8 |
- cpu_to_leguids(&new_h->data_write_guid);
|
|
|
9ae3a8 |
- cpu_to_leguids(&new_h->log_guid);
|
|
|
9ae3a8 |
-
|
|
|
9ae3a8 |
- new_h->log_version = cpu_to_le16(orig_h->log_version);
|
|
|
9ae3a8 |
- new_h->version = cpu_to_le16(orig_h->version);
|
|
|
9ae3a8 |
- new_h->log_length = cpu_to_le32(orig_h->log_length);
|
|
|
9ae3a8 |
- new_h->log_offset = cpu_to_le64(orig_h->log_offset);
|
|
|
9ae3a8 |
-}
|
|
|
9ae3a8 |
-
|
|
|
9ae3a8 |
/* Update the VHDX headers
|
|
|
9ae3a8 |
*
|
|
|
9ae3a8 |
* This follows the VHDX spec procedures for header updates.
|
|
|
9ae3a8 |
diff --git a/block/vhdx.h b/block/vhdx.h
|
|
|
9ae3a8 |
index 76ce4aa..55975a2 100644
|
|
|
9ae3a8 |
--- a/block/vhdx.h
|
|
|
9ae3a8 |
+++ b/block/vhdx.h
|
|
|
9ae3a8 |
@@ -394,4 +394,12 @@ static inline void cpu_to_leguids(MSGUID *guid)
|
|
|
9ae3a8 |
cpu_to_le16s(&guid->data3);
|
|
|
9ae3a8 |
}
|
|
|
9ae3a8 |
|
|
|
9ae3a8 |
+void vhdx_header_le_import(VHDXHeader *h);
|
|
|
9ae3a8 |
+void vhdx_header_le_export(VHDXHeader *orig_h, VHDXHeader *new_h);
|
|
|
9ae3a8 |
+void vhdx_log_desc_le_import(VHDXLogDescriptor *d);
|
|
|
9ae3a8 |
+void vhdx_log_desc_le_export(VHDXLogDescriptor *d);
|
|
|
9ae3a8 |
+void vhdx_log_data_le_export(VHDXLogDataSector *d);
|
|
|
9ae3a8 |
+void vhdx_log_entry_hdr_le_import(VHDXLogEntryHeader *hdr);
|
|
|
9ae3a8 |
+void vhdx_log_entry_hdr_le_export(VHDXLogEntryHeader *hdr);
|
|
|
9ae3a8 |
+
|
|
|
9ae3a8 |
#endif
|
|
|
9ae3a8 |
--
|
|
|
9ae3a8 |
1.7.1
|
|
|
9ae3a8 |
|