Skip to contentSkip to conversation

nbd: avoid unaligned uint64_t store

PATCH In review John Snow 2 participants 4 messages Feb 3, 2016 – Feb 4, 2016

lore
Share & tools
lore

John Snow

author
#0 lore raw

PATCH 1/1 nbd: avoid unaligned uint64_t store

cpu_to_be64w can't be used to make unaligned stores, but stq_be_p can. The other stores in this routine are left alone, they're aligned already.

---
 nbd/server.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
nbd/server.c +1 -1
index 1ec79cf..5b65059 100644
@@ -441,7 +441,7 @@ static coroutine_fn int nbd_negotiate(NBDClientNewData *data)
         }
 
         assert ((client->exp->nbdflags & ~65535) == 0);
-        cpu_to_be64w((uint64_t*)(buf + 18), client->exp->size);
+        stq_be_p((uint64_t *)(buf + 18), client->exp->size);
         cpu_to_be16w((uint16_t*)(buf + 26), client->exp->nbdflags | myflags);
         if (nbd_negotiate_write(csock, buf + 18,
                                 sizeof(buf) - 18) != sizeof(buf) - 18) {
Signature · 1 line
2.4.3
#1 lore raw
Quoted 14 lines · John Snow

cpu_to_be64w can't be used to make unaligned stores, but stq_be_p can. The other stores in this routine are left alone, they're aligned already.

---
 nbd/server.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
nbd/server.c +0 -0
index 1ec79cf..5b65059 100644

nbd/server.c static coroutine_fn int nbd_negotiate(NBDClientNewData *data) · line 447

Quoted 8 lines
nbd/server.c +1 -1
@@ -441,7 +441,7 @@ static coroutine_fn int nbd_negotiate(NBDClientNewData *data)
         }
 
         assert ((client->exp->nbdflags & ~65535) == 0);
-        cpu_to_be64w((uint64_t*)(buf + 18), client->exp->size);
+        stq_be_p((uint64_t *)(buf + 18), client->exp->size);
         cpu_to_be16w((uint16_t*)(buf + 26), client->exp->nbdflags | myflags);
         if (nbd_negotiate_write(csock, buf + 18,
                                 sizeof(buf) - 18) != sizeof(buf) - 18) {

Let's change all of them. But no need to send another patch.

Paolo

author
#2 lore raw
Quoted 28 lines · Paolo Bonzini
Quoted 14 lines · John Snow

cpu_to_be64w can't be used to make unaligned stores, but stq_be_p can. The other stores in this routine are left alone, they're aligned already.

---
 nbd/server.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
nbd/server.c +0 -0
index 1ec79cf..5b65059 100644

nbd/server.c static coroutine_fn int nbd_negotiate(NBDClientNewData *data) · line 447

Quoted 8 lines
nbd/server.c +1 -1
@@ -441,7 +441,7 @@ static coroutine_fn int nbd_negotiate(NBDClientNewData *data)
         }
 
         assert ((client->exp->nbdflags & ~65535) == 0);
-        cpu_to_be64w((uint64_t*)(buf + 18), client->exp->size);
+        stq_be_p((uint64_t *)(buf + 18), client->exp->size);
         cpu_to_be16w((uint16_t*)(buf + 26), client->exp->nbdflags | myflags);
         if (nbd_negotiate_write(csock, buf + 18,
                                 sizeof(buf) - 18) != sizeof(buf) - 18) {

Let's change all of them. But no need to send another patch.

Quoted 2 lines

Paolo

Does that mean that you're going to re-write the patch?

#3 lore raw
Quoted 31 lines · John Snow
Quoted 28 lines · Paolo Bonzini
Quoted 14 lines · John Snow

cpu_to_be64w can't be used to make unaligned stores, but stq_be_p can. The other stores in this routine are left alone, they're aligned already.

---
 nbd/server.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
nbd/server.c +0 -0
index 1ec79cf..5b65059 100644

nbd/server.c static coroutine_fn int nbd_negotiate(NBDClientNewData *data) · line 447

Quoted 8 lines
nbd/server.c +1 -1
@@ -441,7 +441,7 @@ static coroutine_fn int nbd_negotiate(NBDClientNewData *data)
         }
 
         assert ((client->exp->nbdflags & ~65535) == 0);
-        cpu_to_be64w((uint64_t*)(buf + 18), client->exp->size);
+        stq_be_p((uint64_t *)(buf + 18), client->exp->size);
         cpu_to_be16w((uint16_t*)(buf + 26), client->exp->nbdflags | myflags);
         if (nbd_negotiate_write(csock, buf + 18,
                                 sizeof(buf) - 18) != sizeof(buf) - 18) {

Let's change all of them. But no need to send another patch.

Quoted 4 lines
Quoted 2 lines

Paolo

Does that mean that you're going to re-write the patch?

I will just make it bigger. :) Your one line change will still be there!

Paolo