yeahuh / rpms / qemu-kvm

Forked from rpms/qemu-kvm 2 years ago
Clone

Blame SOURCES/kvm-block-vhdx-log-support-struct-and-defines.patch

0a122b
From a60094cdc27c9913ad93fc42383161ed40015e44 Mon Sep 17 00:00:00 2001
0a122b
From: Jeffrey Cody <jcody@redhat.com>
0a122b
Date: Wed, 20 Nov 2013 19:43:53 +0100
0a122b
Subject: [PATCH 10/25] block: vhdx - log support struct and defines
0a122b
0a122b
RH-Author: Jeffrey Cody <jcody@redhat.com>
0a122b
Message-id: <2dae7f05c8661b506f3bbaa60cd8b3ad35d7a7e4.1384975172.git.jcody@redhat.com>
0a122b
Patchwork-id: 55803
0a122b
O-Subject: [RHEL7 qemu-kvm PATCH 10/26] block: vhdx - log support struct and defines
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 adds some magic number defines, and internal structure definitions
0a122b
for VHDX log replay support.  The struct VHDXLogEntries does not reflect
0a122b
an on-disk data structure, and thus does not need to be packed.
0a122b
0a122b
Some minor code style fixes are applied 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 625565d27e8d7c7f7238ccd118a2cd49c1c52963)
0a122b
---
0a122b
 block/vhdx.h | 46 ++++++++++++++++++++++++++++++----------------
0a122b
 1 file changed, 30 insertions(+), 16 deletions(-)
0a122b
0a122b
Signed-off-by: Miroslav Rezanina <mrezanin@redhat.com>
0a122b
---
0a122b
 block/vhdx.h |   46 ++++++++++++++++++++++++++++++----------------
0a122b
 1 files changed, 30 insertions(+), 16 deletions(-)
0a122b
0a122b
diff --git a/block/vhdx.h b/block/vhdx.h
0a122b
index 57375ff..76ce4aa 100644
0a122b
--- a/block/vhdx.h
0a122b
+++ b/block/vhdx.h
0a122b
@@ -30,12 +30,12 @@
0a122b
  * 0.........64KB...........128KB........192KB..........256KB................1MB
0a122b
  */
0a122b
 
0a122b
-#define VHDX_HEADER_BLOCK_SIZE      (64*1024)
0a122b
+#define VHDX_HEADER_BLOCK_SIZE      (64 * 1024)
0a122b
 
0a122b
 #define VHDX_FILE_ID_OFFSET         0
0a122b
-#define VHDX_HEADER1_OFFSET         (VHDX_HEADER_BLOCK_SIZE*1)
0a122b
-#define VHDX_HEADER2_OFFSET         (VHDX_HEADER_BLOCK_SIZE*2)
0a122b
-#define VHDX_REGION_TABLE_OFFSET    (VHDX_HEADER_BLOCK_SIZE*3)
0a122b
+#define VHDX_HEADER1_OFFSET         (VHDX_HEADER_BLOCK_SIZE * 1)
0a122b
+#define VHDX_HEADER2_OFFSET         (VHDX_HEADER_BLOCK_SIZE * 2)
0a122b
+#define VHDX_REGION_TABLE_OFFSET    (VHDX_HEADER_BLOCK_SIZE * 3)
0a122b
 
0a122b
 
0a122b
 /*
0a122b
@@ -77,10 +77,10 @@ typedef struct QEMU_PACKED MSGUID {
0a122b
 #define guid_eq(a, b) \
0a122b
     (memcmp(&(a), &(b), sizeof(MSGUID)) == 0)
0a122b
 
0a122b
-#define VHDX_HEADER_SIZE (4*1024)   /* although the vhdx_header struct in disk
0a122b
-                                       is only 582 bytes, for purposes of crc
0a122b
-                                       the header is the first 4KB of the 64KB
0a122b
-                                       block */
0a122b
+#define VHDX_HEADER_SIZE (4 * 1024)   /* although the vhdx_header struct in disk
0a122b
+                                         is only 582 bytes, for purposes of crc
0a122b
+                                         the header is the first 4KB of the 64KB
0a122b
+                                         block */
0a122b
 
0a122b
 /* The full header is 4KB, although the actual header data is much smaller.
0a122b
  * But for the checksum calculation, it is over the entire 4KB structure,
0a122b
@@ -92,7 +92,7 @@ typedef struct QEMU_PACKED VHDXHeader {
0a122b
                                            VHDX file has 2 of these headers,
0a122b
                                            and only the header with the highest
0a122b
                                            sequence number is valid */
0a122b
-    MSGUID      file_write_guid;       /* 128 bit unique identifier. Must be
0a122b
+    MSGUID      file_write_guid;        /* 128 bit unique identifier. Must be
0a122b
                                            updated to new, unique value before
0a122b
                                            the first modification is made to
0a122b
                                            file */
0a122b
@@ -151,7 +151,10 @@ typedef struct QEMU_PACKED VHDXRegionTableEntry {
0a122b
 
0a122b
 
0a122b
 /* ---- LOG ENTRY STRUCTURES ---- */
0a122b
+#define VHDX_LOG_MIN_SIZE (1024 * 1024)
0a122b
+#define VHDX_LOG_SECTOR_SIZE 4096
0a122b
 #define VHDX_LOG_HDR_SIZE 64
0a122b
+#define VHDX_LOG_SIGNATURE 0x65676f6c
0a122b
 typedef struct QEMU_PACKED VHDXLogEntryHeader {
0a122b
     uint32_t    signature;              /* "loge" in ASCII */
0a122b
     uint32_t    checksum;               /* CRC-32C hash of the 64KB table */
0a122b
@@ -174,7 +177,8 @@ typedef struct QEMU_PACKED VHDXLogEntryHeader {
0a122b
 } VHDXLogEntryHeader;
0a122b
 
0a122b
 #define VHDX_LOG_DESC_SIZE 32
0a122b
-
0a122b
+#define VHDX_LOG_DESC_SIGNATURE 0x63736564
0a122b
+#define VHDX_LOG_ZERO_SIGNATURE 0x6f72657a
0a122b
 typedef struct QEMU_PACKED VHDXLogDescriptor {
0a122b
     uint32_t    signature;              /* "zero" or "desc" in ASCII */
0a122b
     union  {
0a122b
@@ -194,6 +198,7 @@ typedef struct QEMU_PACKED VHDXLogDescriptor {
0a122b
                                            vhdx_log_entry_header */
0a122b
 } VHDXLogDescriptor;
0a122b
 
0a122b
+#define VHDX_LOG_DATA_SIGNATURE 0x61746164
0a122b
 typedef struct QEMU_PACKED VHDXLogDataSector {
0a122b
     uint32_t    data_signature;         /* "data" in ASCII */
0a122b
     uint32_t    sequence_high;          /* 4 MSB of 8 byte sequence_number */
0a122b
@@ -219,12 +224,12 @@ typedef struct QEMU_PACKED VHDXLogDataSector {
0a122b
 #define SB_BLOCK_PRESENT        6
0a122b
 
0a122b
 /* per the spec */
0a122b
-#define VHDX_MAX_SECTORS_PER_BLOCK  (1<<23)
0a122b
+#define VHDX_MAX_SECTORS_PER_BLOCK  (1 << 23)
0a122b
 
0a122b
 /* upper 44 bits are the file offset in 1MB units lower 3 bits are the state
0a122b
    other bits are reserved */
0a122b
 #define VHDX_BAT_STATE_BIT_MASK 0x07
0a122b
-#define VHDX_BAT_FILE_OFF_BITS (64-44)
0a122b
+#define VHDX_BAT_FILE_OFF_BITS (64 - 44)
0a122b
 typedef uint64_t VHDXBatEntry;
0a122b
 
0a122b
 /* ---- METADATA REGION STRUCTURES ---- */
0a122b
@@ -252,8 +257,8 @@ typedef struct QEMU_PACKED VHDXMetadataTableEntry {
0a122b
                                            metadata region */
0a122b
                                         /* note: if length = 0, so is offset */
0a122b
     uint32_t    length;                 /* length of metadata. <= 1MB. */
0a122b
-    uint32_t    data_bits;      /* least-significant 3 bits are flags, the
0a122b
-                                   rest are reserved (see above) */
0a122b
+    uint32_t    data_bits;              /* least-significant 3 bits are flags,
0a122b
+                                           the rest are reserved (see above) */
0a122b
     uint32_t    reserved2;
0a122b
 } VHDXMetadataTableEntry;
0a122b
 
0a122b
@@ -265,8 +270,8 @@ typedef struct QEMU_PACKED VHDXMetadataTableEntry {
0a122b
 typedef struct QEMU_PACKED VHDXFileParameters {
0a122b
     uint32_t    block_size;             /* size of each payload block, always
0a122b
                                            power of 2, <= 256MB and >= 1MB. */
0a122b
-    uint32_t data_bits;     /* least-significant 2 bits are flags, the rest
0a122b
-                               are reserved (see above) */
0a122b
+    uint32_t data_bits;                 /* least-significant 2 bits are flags,
0a122b
+                                           the rest are reserved (see above) */
0a122b
 } VHDXFileParameters;
0a122b
 
0a122b
 typedef struct QEMU_PACKED VHDXVirtualDiskSize {
0a122b
@@ -318,6 +323,13 @@ typedef struct VHDXMetadataEntries {
0a122b
     uint16_t present;
0a122b
 } VHDXMetadataEntries;
0a122b
 
0a122b
+typedef struct VHDXLogEntries {
0a122b
+    uint64_t offset;
0a122b
+    uint64_t length;
0a122b
+    uint32_t head;
0a122b
+    uint32_t tail;
0a122b
+} VHDXLogEntries;
0a122b
+
0a122b
 typedef struct BDRVVHDXState {
0a122b
     CoMutex lock;
0a122b
 
0a122b
@@ -351,6 +363,8 @@ typedef struct BDRVVHDXState {
0a122b
 
0a122b
     MSGUID session_guid;
0a122b
 
0a122b
+    VHDXLogEntries log;
0a122b
+
0a122b
     VHDXParentLocatorHeader parent_header;
0a122b
     VHDXParentLocatorEntry *parent_entries;
0a122b
 
0a122b
-- 
0a122b
1.7.1
0a122b