Received: from eggs.gnu.org ([209.51.188.92]:38480) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gxBW4-00036N-Jl for qemu-devel@nongnu.org; Fri, 22 Feb 2019 09:09:29 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1gxBVs-0002d7-M9 for qemu-devel@nongnu.org; Fri, 22 Feb 2019 09:09:21 -0500 From: Stefan Hajnoczi Date: Fri, 22 Feb 2019 14:07:54 +0000 Message-Id: <20190222140756.29834-26-stefanha@redhat.com> In-Reply-To: <20190222140756.29834-1-stefanha@redhat.com> References: <20190222140756.29834-1-stefanha@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Subject: [Qemu-devel] [PULL 25/27] tests/virtio-blk: add virtio_blk_fix_dwz_hdr() function List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-devel@nongnu.org Cc: qemu-block@nongnu.org, Peter Maydell From: Stefano Garzarella This function is useful to fix the endianness of struct virtio_blk_discard_write_zeroes headers. Reviewed-by: Stefan Hajnoczi Signed-off-by: Stefano Garzarella Message-id: 20190221103314.58500-9-sgarzare@redhat.com Message-Id: <20190221103314.58500-9-sgarzare@redhat.com> Signed-off-by: Stefan Hajnoczi --- 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; =20 +#ifdef HOST_WORDS_BIGENDIAN +const bool host_is_big_endian =3D 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) =20 static inline void virtio_blk_fix_request(QVirtioDevice *d, QVirtioBlkRe= q *req) { -#ifdef HOST_WORDS_BIGENDIAN - const bool host_is_big_endian =3D true; -#else - const bool host_is_big_endian =3D false; -#endif - if (qvirtio_is_big_endian(d) !=3D host_is_big_endian) { req->type =3D bswap32(req->type); req->ioprio =3D bswap32(req->ioprio); @@ -138,6 +138,17 @@ static inline void virtio_blk_fix_request(QVirtioDev= ice *d, QVirtioBlkReq *req) } } =20 + +static inline void virtio_blk_fix_dwz_hdr(QVirtioDevice *d, + struct virtio_blk_discard_write_zeroes *dwz_hdr) +{ + if (qvirtio_is_big_endian(d) !=3D host_is_big_endian) { + dwz_hdr->sector =3D bswap64(dwz_hdr->sector); + dwz_hdr->num_sectors =3D bswap32(dwz_hdr->num_sectors); + dwz_hdr->flags =3D bswap32(dwz_hdr->flags); + } +} + static uint64_t virtio_blk_request(QGuestAllocator *alloc, QVirtioDevice= *d, QVirtioBlkReq *req, uint64_t data_siz= e) { --=20 2.20.1