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