Skip to content
  • Eric Blake's avatar
    8cb98a72
    nbd/client: Simplify cookie vs. index computation · 8cb98a72
    Eric Blake authored
    
    
    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.
    
    Using ((uint64_t)-1) as the sentinel instead of NULL such that the two
    macros could be entirely eliminated might also be possible, but would
    require a more careful audit to find places where we currently rely on
    zero-initialization to be interpreted as the sentinel value, so I did
    not pursue that course.
    
    Signed-off-by: default avatarEric Blake <eblake@redhat.com>
    Message-ID: <20230608135653.2918540-7-eblake@redhat.com>
    [eblake: enhance commit message]
    Reviewed-by: default avatarVladimir Sementsov-Ogievskiy <vsementsov@yandex-team.ru>
    8cb98a72
    nbd/client: Simplify cookie vs. index computation
    Eric Blake authored
    
    
    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.
    
    Using ((uint64_t)-1) as the sentinel instead of NULL such that the two
    macros could be entirely eliminated might also be possible, but would
    require a more careful audit to find places where we currently rely on
    zero-initialization to be interpreted as the sentinel value, so I did
    not pursue that course.
    
    Signed-off-by: default avatarEric Blake <eblake@redhat.com>
    Message-ID: <20230608135653.2918540-7-eblake@redhat.com>
    [eblake: enhance commit message]
    Reviewed-by: default avatarVladimir Sementsov-Ogievskiy <vsementsov@yandex-team.ru>
Loading