@@ -19,6 +19,7 @@
#include "libqos/pci-pc.h"
#include "libqos/malloc.h"
#include "libqos/malloc-pc.h"
+#include "qemu/bswap.h"
#define QVIRTIO_BLK_F_BARRIER 0x00000001
#define QVIRTIO_BLK_F_SIZE_MAX 0x00000002
@@ -96,6 +97,21 @@ static QVirtioPCIDevice *virtio_blk_init(QPCIBus *bus)
return dev;
}
+static inline void virtio_blk_fix_request(QVirtioBlkReq *req)
+{
+#ifdef HOST_WORDS_BIGENDIAN
+ bool host_endian = true;
+#else
+ bool host_endian = false;
+#endif
+
+ if (qtest_big_endian() != host_endian) {
+ req->type = bswap32(req->type);
+ req->ioprio = bswap32(req->ioprio);
+ req->sector = bswap64(req->sector);
+ }
+}
+
static uint64_t virtio_blk_request(QGuestAllocator *alloc, QVirtioBlkReq *req,
uint64_t data_size)
{
@@ -105,6 +121,8 @@ static uint64_t virtio_blk_request(QGuestAllocator *alloc, QVirtioBlkReq *req,
g_assert_cmpuint(data_size % 512, ==, 0);
addr = guest_alloc(alloc, sizeof(*req) + data_size);
+ virtio_blk_fix_request(req);
+
memwrite(addr, req, 16);
memwrite(addr + 16, req->data, data_size);
memwrite(addr + 16 + data_size, &status, sizeof(status));
The virtio block request header is in target cpu byte order, which may be different from the host cpu byte order. This patch allows the virtio-blk-test to run with a x86_64 (LE) target on a ppc64 (BE) host. Signed-off-by: Greg Kurz <gkurz@linux.vnet.ibm.com> --- tests/virtio-blk-test.c | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+)