thebeanogamer / rpms / qemu-kvm

Forked from rpms/qemu-kvm 5 months ago
Clone

Blame SOURCES/kvm-block-vpc-use-QEMU_PACKED-for-on-disk-structures.patch

958e1b
From 18fbf10e53408ce0a74abb32490bacf077713e9a Mon Sep 17 00:00:00 2001
958e1b
From: Jeffrey Cody <jcody@redhat.com>
958e1b
Date: Tue, 16 Sep 2014 20:11:49 +0200
958e1b
Subject: [PATCH 11/20] block: vpc - use QEMU_PACKED for on-disk structures
958e1b
958e1b
Message-id: <924b119681bb117e6551215f16be3f38e80c1179.1410897407.git.jcody@redhat.com>
958e1b
Patchwork-id: 61215
958e1b
O-Subject: [PATCH qemu-kvm-rhel RHEL7.1 10/15] block: vpc - use QEMU_PACKED for on-disk structures
958e1b
Bugzilla: 1098086
958e1b
RH-Acked-by: Fam Zheng <famz@redhat.com>
958e1b
RH-Acked-by: Stefan Hajnoczi <stefanha@redhat.com>
958e1b
RH-Acked-by: Max Reitz <mreitz@redhat.com>
958e1b
958e1b
The VHD footer and header structs (vhd_footer and vhd_dyndisk_header)
958e1b
are on-disk structures for the image format, and as such should be
958e1b
packed.
958e1b
958e1b
Go ahead and make these typedefs as well, with the preferred QEMU
958e1b
naming convention, so that the packed attribute is used consistently
958e1b
with the struct.
958e1b
958e1b
Signed-off-by: Jeff Cody <jcody@redhat.com>
958e1b
Reviewed-by: Richard Henderson <rth@twiddle.net>
958e1b
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
958e1b
(cherry picked from commit e54835c06d1f4896941c1505a86532aa1403ebe8)
958e1b
958e1b
Signed-off-by: Miroslav Rezanina <mrezanin@redhat.com>
958e1b
---
958e1b
 block/vpc.c |   28 ++++++++++++++--------------
958e1b
 1 files changed, 14 insertions(+), 14 deletions(-)
958e1b
958e1b
diff --git a/block/vpc.c b/block/vpc.c
958e1b
index 2f3d4ac..ab74eb9 100644
958e1b
--- a/block/vpc.c
958e1b
+++ b/block/vpc.c
958e1b
@@ -48,7 +48,7 @@ enum vhd_type {
958e1b
 #define VHD_MAX_SECTORS       (65535LL * 255 * 255)
958e1b
 
958e1b
 // always big-endian
958e1b
-struct vhd_footer {
958e1b
+typedef struct vhd_footer {
958e1b
     char        creator[8]; // "conectix"
958e1b
     uint32_t    features;
958e1b
     uint32_t    version;
958e1b
@@ -81,9 +81,9 @@ struct vhd_footer {
958e1b
     uint8_t     uuid[16];
958e1b
 
958e1b
     uint8_t     in_saved_state;
958e1b
-};
958e1b
+} QEMU_PACKED VHDFooter;
958e1b
 
958e1b
-struct vhd_dyndisk_header {
958e1b
+typedef struct vhd_dyndisk_header {
958e1b
     char        magic[8]; // "cxsparse"
958e1b
 
958e1b
     // Offset of next header structure, 0xFFFFFFFF if none
958e1b
@@ -113,7 +113,7 @@ struct vhd_dyndisk_header {
958e1b
         uint32_t    reserved;
958e1b
         uint64_t    data_offset;
958e1b
     } parent_locator[8];
958e1b
-};
958e1b
+} QEMU_PACKED VHDDynDiskHeader;
958e1b
 
958e1b
 typedef struct BDRVVPCState {
958e1b
     CoMutex lock;
958e1b
@@ -162,8 +162,8 @@ static int vpc_open(BlockDriverState *bs, QDict *options, int flags,
958e1b
 {
958e1b
     BDRVVPCState *s = bs->opaque;
958e1b
     int i;
958e1b
-    struct vhd_footer* footer;
958e1b
-    struct vhd_dyndisk_header* dyndisk_header;
958e1b
+    VHDFooter *footer;
958e1b
+    VHDDynDiskHeader *dyndisk_header;
958e1b
     uint8_t buf[HEADER_SIZE];
958e1b
     uint32_t checksum;
958e1b
     uint64_t computed_size;
958e1b
@@ -175,7 +175,7 @@ static int vpc_open(BlockDriverState *bs, QDict *options, int flags,
958e1b
         goto fail;
958e1b
     }
958e1b
 
958e1b
-    footer = (struct vhd_footer*) s->footer_buf;
958e1b
+    footer = (VHDFooter *) s->footer_buf;
958e1b
     if (strncmp(footer->creator, "conectix", 8)) {
958e1b
         int64_t offset = bdrv_getlength(bs->file);
958e1b
         if (offset < 0) {
958e1b
@@ -228,7 +228,7 @@ static int vpc_open(BlockDriverState *bs, QDict *options, int flags,
958e1b
             goto fail;
958e1b
         }
958e1b
 
958e1b
-        dyndisk_header = (struct vhd_dyndisk_header *) buf;
958e1b
+        dyndisk_header = (VHDDynDiskHeader *) buf;
958e1b
 
958e1b
         if (strncmp(dyndisk_header->magic, "cxsparse", 8)) {
958e1b
             ret = -EINVAL;
958e1b
@@ -484,7 +484,7 @@ static int vpc_read(BlockDriverState *bs, int64_t sector_num,
958e1b
     int ret;
958e1b
     int64_t offset;
958e1b
     int64_t sectors, sectors_per_block;
958e1b
-    struct vhd_footer *footer = (struct vhd_footer *) s->footer_buf;
958e1b
+    VHDFooter *footer = (VHDFooter *) s->footer_buf;
958e1b
 
958e1b
     if (cpu_to_be32(footer->type) == VHD_FIXED) {
958e1b
         return bdrv_read(bs->file, sector_num, buf, nb_sectors);
958e1b
@@ -533,7 +533,7 @@ static int vpc_write(BlockDriverState *bs, int64_t sector_num,
958e1b
     int64_t offset;
958e1b
     int64_t sectors, sectors_per_block;
958e1b
     int ret;
958e1b
-    struct vhd_footer *footer =  (struct vhd_footer *) s->footer_buf;
958e1b
+    VHDFooter *footer =  (VHDFooter *) s->footer_buf;
958e1b
 
958e1b
     if (cpu_to_be32(footer->type) == VHD_FIXED) {
958e1b
         return bdrv_write(bs->file, sector_num, buf, nb_sectors);
958e1b
@@ -635,8 +635,8 @@ static int calculate_geometry(int64_t total_sectors, uint16_t* cyls,
958e1b
 
958e1b
 static int create_dynamic_disk(int fd, uint8_t *buf, int64_t total_sectors)
958e1b
 {
958e1b
-    struct vhd_dyndisk_header* dyndisk_header =
958e1b
-        (struct vhd_dyndisk_header*) buf;
958e1b
+    VHDDynDiskHeader *dyndisk_header =
958e1b
+        (VHDDynDiskHeader *) buf;
958e1b
     size_t block_size, num_bat_entries;
958e1b
     int i;
958e1b
     int ret = -EIO;
958e1b
@@ -726,7 +726,7 @@ static int vpc_create(const char *filename, QEMUOptionParameter *options,
958e1b
                       Error **errp)
958e1b
 {
958e1b
     uint8_t buf[1024];
958e1b
-    struct vhd_footer *footer = (struct vhd_footer *) buf;
958e1b
+    VHDFooter *footer = (VHDFooter *) buf;
958e1b
     QEMUOptionParameter *disk_type_param;
958e1b
     int fd, i;
958e1b
     uint16_t cyls = 0;
958e1b
@@ -829,7 +829,7 @@ static int vpc_create(const char *filename, QEMUOptionParameter *options,
958e1b
 static int vpc_has_zero_init(BlockDriverState *bs)
958e1b
 {
958e1b
     BDRVVPCState *s = bs->opaque;
958e1b
-    struct vhd_footer *footer =  (struct vhd_footer *) s->footer_buf;
958e1b
+    VHDFooter *footer =  (VHDFooter *) s->footer_buf;
958e1b
 
958e1b
     if (cpu_to_be32(footer->type) == VHD_FIXED) {
958e1b
         return bdrv_has_zero_init(bs->file);
958e1b
-- 
958e1b
1.7.1
958e1b