[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Qemu-devel] [PULL 13/28] nbd: avoid unaligned uint64_t store
From: |
Paolo Bonzini |
Subject: |
[Qemu-devel] [PULL 13/28] nbd: avoid unaligned uint64_t store |
Date: |
Mon, 8 Feb 2016 18:03:04 +0100 |
From: John Snow <address@hidden>
cpu_to_be64w can't be used to make unaligned stores, but stq_be_p can.
Also, the st?_be_p takes a void* so it is more clearly suited to the
case where you're writing into a byte buffer.
Use the st?_be_p family of functions everywhere in nbd/server.c.
Signed-off-by: John Snow <address@hidden>
[Changed to use st?_be_p everywhere. - Paolo]
Signed-off-by: Paolo Bonzini <address@hidden>
---
nbd/server.c | 20 ++++++++++----------
1 file changed, 10 insertions(+), 10 deletions(-)
diff --git a/nbd/server.c b/nbd/server.c
index 4313530..dc1d66f 100644
--- a/nbd/server.c
+++ b/nbd/server.c
@@ -417,12 +417,12 @@ static coroutine_fn int nbd_negotiate(NBDClientNewData
*data)
memcpy(buf, "NBDMAGIC", 8);
if (client->exp) {
assert ((client->exp->nbdflags & ~65535) == 0);
- cpu_to_be64w((uint64_t*)(buf + 8), NBD_CLIENT_MAGIC);
- cpu_to_be64w((uint64_t*)(buf + 16), client->exp->size);
- cpu_to_be16w((uint16_t*)(buf + 26), client->exp->nbdflags | myflags);
+ stq_be_p(buf + 8, NBD_CLIENT_MAGIC);
+ stq_be_p(buf + 16, client->exp->size);
+ stw_be_p(buf + 26, client->exp->nbdflags | myflags);
} else {
- cpu_to_be64w((uint64_t*)(buf + 8), NBD_OPTS_MAGIC);
- cpu_to_be16w((uint16_t *)(buf + 16), NBD_FLAG_FIXED_NEWSTYLE);
+ stq_be_p(buf + 8, NBD_OPTS_MAGIC);
+ stw_be_p(buf + 16, NBD_FLAG_FIXED_NEWSTYLE);
}
if (client->exp) {
@@ -442,8 +442,8 @@ static coroutine_fn int nbd_negotiate(NBDClientNewData
*data)
}
assert ((client->exp->nbdflags & ~65535) == 0);
- cpu_to_be64w((uint64_t*)(buf + 18), client->exp->size);
- cpu_to_be16w((uint16_t*)(buf + 26), client->exp->nbdflags | myflags);
+ stq_be_p(buf + 18, client->exp->size);
+ stw_be_p(buf + 26, client->exp->nbdflags | myflags);
if (nbd_negotiate_write(csock, buf + 18,
sizeof(buf) - 18) != sizeof(buf) - 18) {
LOG("write failed");
@@ -528,9 +528,9 @@ static ssize_t nbd_send_reply(int csock, struct nbd_reply
*reply)
[ 4 .. 7] error (0 == no error)
[ 7 .. 15] handle
*/
- cpu_to_be32w((uint32_t*)buf, NBD_REPLY_MAGIC);
- cpu_to_be32w((uint32_t*)(buf + 4), reply->error);
- cpu_to_be64w((uint64_t*)(buf + 8), reply->handle);
+ stl_be_p(buf, NBD_REPLY_MAGIC);
+ stl_be_p(buf + 4, reply->error);
+ stq_be_p(buf + 8, reply->handle);
TRACE("Sending response to client");
--
1.8.3.1
- [Qemu-devel] [PULL 04/28] configure: sanity check the glib library that pkg-config finds, (continued)
- [Qemu-devel] [PULL 04/28] configure: sanity check the glib library that pkg-config finds, Paolo Bonzini, 2016/02/08
- [Qemu-devel] [PULL 09/28] qemu-nbd: Fix unintended texi verbatim formatting, Paolo Bonzini, 2016/02/08
- [Qemu-devel] [PULL 12/28] scripts/kvm/kvm_stat: Fix tracefs access checking, Paolo Bonzini, 2016/02/08
- [Qemu-devel] [PULL 14/28] kvm-all: trace: strerror fixup, Paolo Bonzini, 2016/02/08
- [Qemu-devel] [PULL 17/28] target-i386: Introduce mo_stacksize, Paolo Bonzini, 2016/02/08
- [Qemu-devel] [PULL 15/28] char: fix repeated registration of tcp chardev I/O handlers, Paolo Bonzini, 2016/02/08
- [Qemu-devel] [PULL 18/28] target-i386: Use gen_lea_v_seg in gen_lea_modrm, Paolo Bonzini, 2016/02/08
- [Qemu-devel] [PULL 19/28] target-i386: Use gen_lea_v_seg in stack subroutines, Paolo Bonzini, 2016/02/08
- [Qemu-devel] [PULL 10/28] qemu-nbd: Minor texi updates, Paolo Bonzini, 2016/02/08
- [Qemu-devel] [PULL 11/28] qemu-nbd: Fix texi sentence capitalisation, Paolo Bonzini, 2016/02/08
- [Qemu-devel] [PULL 13/28] nbd: avoid unaligned uint64_t store,
Paolo Bonzini <=
- [Qemu-devel] [PULL 16/28] target-i386: Create gen_lea_v_seg, Paolo Bonzini, 2016/02/08
- [Qemu-devel] [PULL 08/28] hw: Add support for LSI SAS1068 (mptsas) device, Paolo Bonzini, 2016/02/08
- [Qemu-devel] [PULL 20/28] target-i386: Access segs via TCG registers, Paolo Bonzini, 2016/02/08
- [Qemu-devel] [PULL 22/28] target-i386: Rewrite gen_enter inline, Paolo Bonzini, 2016/02/08
- [Qemu-devel] [PULL 21/28] target-i386: Use gen_lea_v_seg in pusha/popa, Paolo Bonzini, 2016/02/08
- [Qemu-devel] [PULL 27/28] ipmi_bmc_sim: Fix off by one in check., Paolo Bonzini, 2016/02/08
- [Qemu-devel] [PULL 24/28] target-i386: Tidy gen_add_A0_im, Paolo Bonzini, 2016/02/08
- [Qemu-devel] [PULL 23/28] target-i386: Rewrite leave, Paolo Bonzini, 2016/02/08
- [Qemu-devel] [PULL 26/28] ipmi: do not take/drop iothread lock, Paolo Bonzini, 2016/02/08
- [Qemu-devel] [PULL 28/28] ipmi_bmc_sim: Add break to correct watchdog NMI check, Paolo Bonzini, 2016/02/08