[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [PATCH v4 06/24] nbd/client: Simplify cookie vs. index computation
From: |
Vladimir Sementsov-Ogievskiy |
Subject: |
Re: [PATCH v4 06/24] nbd/client: Simplify cookie vs. index computation |
Date: |
Mon, 12 Jun 2023 17:27:19 +0300 |
User-agent: |
Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101 Thunderbird/102.9.0 |
On 08.06.23 16:56, Eric Blake wrote:
Our code relies on a sentinel cookie value of zero for deciding when a
packet has been handled, as well as relying on array indices between 0
and MAX_NBD_REQUESTS-1 for dereferencing purposes. As long as we can
symmetrically convert between two forms, there is no reason to go with
the odd choice of using XOR with a random pointer, when we can instead
simplify the mappings with a mere offset of 1.
Should we go further and use (uint64)-1 as a sentinel cookie value, and just
use index as a cookie? Or, using zero cookie in a wire looks too asymmetric?
Signed-off-by: Eric Blake <eblake@redhat.com>
Reviewed-by: Vladimir Sementsov-Ogievskiy <vsementsov@yandex-team.ru>
---
v4: new patch
---
block/nbd.c | 16 ++++++++--------
1 file changed, 8 insertions(+), 8 deletions(-)
diff --git a/block/nbd.c b/block/nbd.c
index be3c46c6fee..5322e66166c 100644
--- a/block/nbd.c
+++ b/block/nbd.c
@@ -50,8 +50,8 @@
#define EN_OPTSTR ":exportname="
#define MAX_NBD_REQUESTS 16
-#define COOKIE_TO_INDEX(bs, cookie) ((cookie) ^ (uint64_t)(intptr_t)(bs))
-#define INDEX_TO_COOKIE(bs, index) ((index) ^ (uint64_t)(intptr_t)(bs))
That looked like some security trick to hide real indices. But I don't think
that index of request in a list is a secret information.
+#define COOKIE_TO_INDEX(cookie) ((cookie) - 1)
+#define INDEX_TO_COOKIE(index) ((index) + 1)
[..]
--
Best regards,
Vladimir
- Re: [Libguestfs] [PATCH v4 02/24] nbd: Consistent typedef usage in header, (continued)
- [PATCH v4 03/24] nbd/server: Prepare for alternate-size headers, Eric Blake, 2023/06/08
- [PATCH v4 04/24] nbd/server: Refactor to pass full request around, Eric Blake, 2023/06/08
- [PATCH v4 05/24] nbd: s/handle/cookie/ to match NBD spec, Eric Blake, 2023/06/08
- [PATCH v4 08/24] nbd: Use enum for various negotiation modes, Eric Blake, 2023/06/08
- [PATCH v4 06/24] nbd/client: Simplify cookie vs. index computation, Eric Blake, 2023/06/08
- Re: [PATCH v4 06/24] nbd/client: Simplify cookie vs. index computation,
Vladimir Sementsov-Ogievskiy <=
- [PATCH v4 14/24] nbd/server: Prepare to receive extended header requests, Eric Blake, 2023/06/08
- [PATCH v4 17/24] nbd/server: Enable initial support for extended headers, Eric Blake, 2023/06/08
- [PATCH v4 07/24] nbd/client: Add safety check on chunk payload length, Eric Blake, 2023/06/08
- [PATCH v4 10/24] nbd/client: Pass mode through to nbd_send_request, Eric Blake, 2023/06/08
- [PATCH v4 12/24] nbd: Prepare for 64-bit request effect lengths, Eric Blake, 2023/06/08