[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Qemu-block] [PATCH v6 08/10] tests/virtio-blk: add virtio_blk_fix_dwz_h
From: |
Stefano Garzarella |
Subject: |
[Qemu-block] [PATCH v6 08/10] tests/virtio-blk: add virtio_blk_fix_dwz_hdr() function |
Date: |
Thu, 21 Feb 2019 11:33:12 +0100 |
This function is useful to fix the endianness of struct
virtio_blk_discard_write_zeroes headers.
Reviewed-by: Stefan Hajnoczi <address@hidden>
Signed-off-by: Stefano Garzarella <address@hidden>
---
tests/virtio-blk-test.c | 23 +++++++++++++++++------
1 file changed, 17 insertions(+), 6 deletions(-)
diff --git a/tests/virtio-blk-test.c b/tests/virtio-blk-test.c
index 0739498da7..85b6b99adc 100644
--- a/tests/virtio-blk-test.c
+++ b/tests/virtio-blk-test.c
@@ -46,6 +46,12 @@ typedef struct QVirtioBlkReq {
uint8_t status;
} QVirtioBlkReq;
+#ifdef HOST_WORDS_BIGENDIAN
+const bool host_is_big_endian = true;
+#else
+const bool host_is_big_endian; /* false */
+#endif
+
static char *drive_create(void)
{
int fd, ret;
@@ -125,12 +131,6 @@ static QVirtioPCIDevice *virtio_blk_pci_init(QPCIBus *bus,
int slot)
static inline void virtio_blk_fix_request(QVirtioDevice *d, QVirtioBlkReq *req)
{
-#ifdef HOST_WORDS_BIGENDIAN
- const bool host_is_big_endian = true;
-#else
- const bool host_is_big_endian = false;
-#endif
-
if (qvirtio_is_big_endian(d) != host_is_big_endian) {
req->type = bswap32(req->type);
req->ioprio = bswap32(req->ioprio);
@@ -138,6 +138,17 @@ static inline void virtio_blk_fix_request(QVirtioDevice
*d, QVirtioBlkReq *req)
}
}
+
+static inline void virtio_blk_fix_dwz_hdr(QVirtioDevice *d,
+ struct virtio_blk_discard_write_zeroes *dwz_hdr)
+{
+ if (qvirtio_is_big_endian(d) != host_is_big_endian) {
+ dwz_hdr->sector = bswap64(dwz_hdr->sector);
+ dwz_hdr->num_sectors = bswap32(dwz_hdr->num_sectors);
+ dwz_hdr->flags = bswap32(dwz_hdr->flags);
+ }
+}
+
static uint64_t virtio_blk_request(QGuestAllocator *alloc, QVirtioDevice *d,
QVirtioBlkReq *req, uint64_t data_size)
{
--
2.20.1
- [Qemu-block] [PATCH v6 00/10] virtio-blk: add DISCARD and WRITE_ZEROES features, Stefano Garzarella, 2019/02/21
- [Qemu-block] [PATCH v6 02/10] virtio-blk: add host_features field in VirtIOBlock, Stefano Garzarella, 2019/02/21
- [Qemu-block] [PATCH v6 01/10] virtio-blk: add acct_failed param to virtio_blk_handle_rw_error(), Stefano Garzarella, 2019/02/21
- [Qemu-block] [PATCH v6 03/10] virtio-blk: add "discard" and "write-zeroes" properties, Stefano Garzarella, 2019/02/21
- [Qemu-block] [PATCH v6 04/10] virtio-net: make VirtIOFeature usable for other virtio devices, Stefano Garzarella, 2019/02/21
- [Qemu-block] [PATCH v6 07/10] tests/virtio-blk: change assert on data_size in virtio_blk_request(), Stefano Garzarella, 2019/02/21
- [Qemu-block] [PATCH v6 06/10] virtio-blk: add DISCARD and WRITE_ZEROES features, Stefano Garzarella, 2019/02/21
- [Qemu-block] [PATCH v6 09/10] tests/virtio-blk: add test for WRITE_ZEROES command, Stefano Garzarella, 2019/02/21
- [Qemu-block] [PATCH v6 08/10] tests/virtio-blk: add virtio_blk_fix_dwz_hdr() function,
Stefano Garzarella <=
- [Qemu-block] [PATCH v6 05/10] virtio-blk: set config size depending on the features enabled, Stefano Garzarella, 2019/02/21
- [Qemu-block] [PATCH v6 10/10] tests/virtio-blk: add test for DISCARD command, Stefano Garzarella, 2019/02/21
- Re: [Qemu-block] [PATCH v6 00/10] virtio-blk: add DISCARD and WRITE_ZEROES features, Stefan Hajnoczi, 2019/02/22