[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Qemu-block] [PULL 15/27] uuid: Make qemu_uuid_bswap() take and return a
From: |
Kevin Wolf |
Subject: |
[Qemu-block] [PULL 15/27] uuid: Make qemu_uuid_bswap() take and return a QemuUUID |
Date: |
Fri, 1 Feb 2019 17:35:06 +0100 |
From: Peter Maydell <address@hidden>
Currently qemu_uuid_bswap() takes a pointer to the QemuUUID to
be byte-swapped. This means it can't be used when the UUID
to be swapped is in a packed member of a struct. It's also
out of line with the general bswap*() functions we provide
in bswap.h, which take the value to be swapped and return it.
Make qemu_uuid_bswap() take a QemuUUID and return the swapped version.
This fixes some clang warnings about taking the address of
a packed struct member in block/vdi.c.
Signed-off-by: Peter Maydell <address@hidden>
Reviewed-by: Michael S. Tsirkin <address@hidden>
Reviewed-by: Marc-André Lureau <address@hidden>
Signed-off-by: Kevin Wolf <address@hidden>
---
include/qemu/uuid.h | 2 +-
block/vdi.c | 16 ++++++++--------
hw/acpi/vmgenid.c | 6 ++----
tests/vmgenid-test.c | 2 +-
util/uuid.c | 10 +++++-----
5 files changed, 17 insertions(+), 19 deletions(-)
diff --git a/include/qemu/uuid.h b/include/qemu/uuid.h
index 09489ce5c5..037357d990 100644
--- a/include/qemu/uuid.h
+++ b/include/qemu/uuid.h
@@ -56,6 +56,6 @@ char *qemu_uuid_unparse_strdup(const QemuUUID *uuid);
int qemu_uuid_parse(const char *str, QemuUUID *uuid);
-void qemu_uuid_bswap(QemuUUID *uuid);
+QemuUUID qemu_uuid_bswap(QemuUUID uuid);
#endif
diff --git a/block/vdi.c b/block/vdi.c
index 4cc726047c..0c34f6bae4 100644
--- a/block/vdi.c
+++ b/block/vdi.c
@@ -203,10 +203,10 @@ static void vdi_header_to_cpu(VdiHeader *header)
header->block_extra = le32_to_cpu(header->block_extra);
header->blocks_in_image = le32_to_cpu(header->blocks_in_image);
header->blocks_allocated = le32_to_cpu(header->blocks_allocated);
- qemu_uuid_bswap(&header->uuid_image);
- qemu_uuid_bswap(&header->uuid_last_snap);
- qemu_uuid_bswap(&header->uuid_link);
- qemu_uuid_bswap(&header->uuid_parent);
+ header->uuid_image = qemu_uuid_bswap(header->uuid_image);
+ header->uuid_last_snap = qemu_uuid_bswap(header->uuid_last_snap);
+ header->uuid_link = qemu_uuid_bswap(header->uuid_link);
+ header->uuid_parent = qemu_uuid_bswap(header->uuid_parent);
}
static void vdi_header_to_le(VdiHeader *header)
@@ -227,10 +227,10 @@ static void vdi_header_to_le(VdiHeader *header)
header->block_extra = cpu_to_le32(header->block_extra);
header->blocks_in_image = cpu_to_le32(header->blocks_in_image);
header->blocks_allocated = cpu_to_le32(header->blocks_allocated);
- qemu_uuid_bswap(&header->uuid_image);
- qemu_uuid_bswap(&header->uuid_last_snap);
- qemu_uuid_bswap(&header->uuid_link);
- qemu_uuid_bswap(&header->uuid_parent);
+ header->uuid_image = qemu_uuid_bswap(header->uuid_image);
+ header->uuid_last_snap = qemu_uuid_bswap(header->uuid_last_snap);
+ header->uuid_link = qemu_uuid_bswap(header->uuid_link);
+ header->uuid_parent = qemu_uuid_bswap(header->uuid_parent);
}
static void vdi_header_print(VdiHeader *header)
diff --git a/hw/acpi/vmgenid.c b/hw/acpi/vmgenid.c
index d78b579a20..02717a8b0d 100644
--- a/hw/acpi/vmgenid.c
+++ b/hw/acpi/vmgenid.c
@@ -30,8 +30,7 @@ void vmgenid_build_acpi(VmGenIdState *vms, GArray
*table_data, GArray *guid,
* first, since that's what the guest expects
*/
g_array_set_size(guid, VMGENID_FW_CFG_SIZE - ARRAY_SIZE(guid_le.data));
- guid_le = vms->guid;
- qemu_uuid_bswap(&guid_le);
+ guid_le = qemu_uuid_bswap(vms->guid);
/* The GUID is written at a fixed offset into the fw_cfg file
* in order to implement the "OVMF SDT Header probe suppressor"
* see docs/specs/vmgenid.txt for more details
@@ -149,8 +148,7 @@ static void vmgenid_update_guest(VmGenIdState *vms)
* however, will expect the fields to be little-endian.
* Perform a byte swap immediately before writing.
*/
- guid_le = vms->guid;
- qemu_uuid_bswap(&guid_le);
+ guid_le = qemu_uuid_bswap(vms->guid);
/* The GUID is written at a fixed offset into the fw_cfg file
* in order to implement the "OVMF SDT Header probe suppressor"
* see docs/specs/vmgenid.txt for more details.
diff --git a/tests/vmgenid-test.c b/tests/vmgenid-test.c
index 52cdd83ec0..ae38ee5ac0 100644
--- a/tests/vmgenid-test.c
+++ b/tests/vmgenid-test.c
@@ -88,7 +88,7 @@ static void read_guid_from_memory(QTestState *qts, QemuUUID
*guid)
/* The GUID is in little-endian format in the guest, while QEMU
* uses big-endian. Swap after reading.
*/
- qemu_uuid_bswap(guid);
+ *guid = qemu_uuid_bswap(*guid);
}
static void read_guid_from_monitor(QTestState *qts, QemuUUID *guid)
diff --git a/util/uuid.c b/util/uuid.c
index ebf06c049a..5787f0978c 100644
--- a/util/uuid.c
+++ b/util/uuid.c
@@ -110,10 +110,10 @@ int qemu_uuid_parse(const char *str, QemuUUID *uuid)
/* Swap from UUID format endian (BE) to the opposite or vice versa.
*/
-void qemu_uuid_bswap(QemuUUID *uuid)
+QemuUUID qemu_uuid_bswap(QemuUUID uuid)
{
- assert(QEMU_PTR_IS_ALIGNED(uuid, sizeof(uint32_t)));
- bswap32s(&uuid->fields.time_low);
- bswap16s(&uuid->fields.time_mid);
- bswap16s(&uuid->fields.time_high_and_version);
+ bswap32s(&uuid.fields.time_low);
+ bswap16s(&uuid.fields.time_mid);
+ bswap16s(&uuid.fields.time_high_and_version);
+ return uuid;
}
--
2.20.1
- [Qemu-block] [PULL 17/27] block: Remove blk_attach_dev_legacy() / legacy_dev code, (continued)
- [Qemu-block] [PULL 17/27] block: Remove blk_attach_dev_legacy() / legacy_dev code, Kevin Wolf, 2019/02/01
- [Qemu-block] [PULL 11/27] iotests: Add VMDK tests for blockdev-create, Kevin Wolf, 2019/02/01
- [Qemu-block] [PULL 16/27] block: Apply auto-read-only for ro-whitelist drivers, Kevin Wolf, 2019/02/01
- [Qemu-block] [PULL 10/27] iotests: Filter cid numbers in VMDK extent info, Kevin Wolf, 2019/02/01
- [Qemu-block] [PULL 13/27] block/vpc: Don't take address of fields in packed structs, Kevin Wolf, 2019/02/01
- [Qemu-block] [PULL 23/27] iotests/236: fix transaction kwarg order, Kevin Wolf, 2019/02/01
- [Qemu-block] [PULL 24/27] block: Fix invalidate_cache error path for parent activation, Kevin Wolf, 2019/02/01
- [Qemu-block] [PULL 03/27] qcow2: Assert that refcount block offsets fit in the refcount table, Kevin Wolf, 2019/02/01
- [Qemu-block] [PULL 07/27] iotests: Make 234 stable, Kevin Wolf, 2019/02/01
- [Qemu-block] [PULL 08/27] vmdk: Refactor vmdk_create_extent, Kevin Wolf, 2019/02/01
- [Qemu-block] [PULL 15/27] uuid: Make qemu_uuid_bswap() take and return a QemuUUID,
Kevin Wolf <=
- [Qemu-block] [PULL 21/27] virtio-scsi: Forbid devices with different iothreads sharing a blockdev, Kevin Wolf, 2019/02/01
- [Qemu-block] [PULL 09/27] vmdk: Implement .bdrv_co_create callback, Kevin Wolf, 2019/02/01
- [Qemu-block] [PULL 27/27] scsi-disk: Add device_id property, Kevin Wolf, 2019/02/01
- [Qemu-block] [PULL 26/27] scsi-disk: Don't use empty string as device id, Kevin Wolf, 2019/02/01
- [Qemu-block] [PULL 25/27] qtest.py: Wait for the result of qtest commands, Kevin Wolf, 2019/02/01
- [Qemu-block] [PULL 18/27] block: Eliminate the S_1KiB, S_2KiB, ... macros, Kevin Wolf, 2019/02/01
- [Qemu-block] [PULL 14/27] block/vdi: Don't take address of fields in packed structs, Kevin Wolf, 2019/02/01
- [Qemu-block] [PULL 19/27] virtio-scsi: Move BlockBackend back to the main AioContext on unplug, Kevin Wolf, 2019/02/01
- [Qemu-block] [PULL 22/27] iotests: Filter second BLOCK_JOB_ERROR from 229, Kevin Wolf, 2019/02/01
- [Qemu-block] [PULL 04/27] qemu-iotests: add test case for dmg, Kevin Wolf, 2019/02/01