Skip to content

Commit

Permalink
tests/virtio-blk: add virtio_blk_fix_dwz_hdr() function
Browse files Browse the repository at this point in the history
This function is useful to fix the endianness of struct
virtio_blk_discard_write_zeroes headers.

Reviewed-by: Stefan Hajnoczi <stefanha@redhat.com>
Signed-off-by: Stefano Garzarella <sgarzare@redhat.com>
Message-id: 20190221103314.58500-9-sgarzare@redhat.com
Message-Id: <20190221103314.58500-9-sgarzare@redhat.com>
Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com>
  • Loading branch information
stefano-garzarella authored and stefanhaRH committed Feb 22, 2019
1 parent f6cd8a6 commit ca1a980
Showing 1 changed file with 17 additions and 6 deletions.
23 changes: 17 additions & 6 deletions tests/virtio-blk-test.c
Expand Up @@ -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;
Expand Down Expand Up @@ -125,19 +131,24 @@ 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);
req->sector = bswap64(req->sector);
}
}


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)
{
Expand Down

0 comments on commit ca1a980

Please sign in to comment.