cryptospore / rpms / qemu-kvm

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