iscsi: Simplify serial number comparisons
A message that is not in the archive (sent off-list or not yet received): [email protected]
Quoted 44 lines · Mark Rustad
Unsigned serial number comparison is very simple if you simply put the difference into a signed integer of the same size and then compare that value with zero. All the complexity and confusion fall away.
Signed-off-by Mark Rustad <[email protected]>--- include/scsi/iscsi_proto.h | 21 ++++++++++++--------- 1 files changed, 12 insertions(+), 9 deletions(-)include/scsi/iscsi_proto.h +9
-7@@ -35,30 +35,33 @@/* * Serial Number Arithmetic, 32 bits, RFC1982 */ -#define SNA32_CHECK 2147483648ULstatic inline int iscsi_sna_lt (u32 n1,u32 n2) { -return n1 != n2 && ((n1 < n2 && (n2 - n1 <SNA32_CHECK )) || - (n1 > n2 && (n2 - n1 <SNA32_CHECK ))); +s32 diff = n1 - n2; + +return diff <0 ; }static inline int iscsi_sna_lte (u32 n1,u32 n2) { -return n1 == n2 || ((n1 < n2 && (n2 - n1 <SNA32_CHECK )) || - (n1 > n2 && (n2 - n1 <SNA32_CHECK ))); +s32 diff = n1 - n2; + +return diff <=0 ; }static inline int iscsi_sna_gt (u32 n1,u32 n2) { -return n1 != n2 && (((n1 < n2) && ((n2 - n1) >SNA32_CHECK )) || - ((n1 > n2) && ((n1 - n2) <SNA32_CHECK ))); +s32 diff = n1 - n2; + +return diff >0 ;
include/scsi/iscsi_proto.h line 65
Quoted 10 lines
include/scsi/iscsi_proto.h +3
-2}static inline int iscsi_sna_gte (u32 n1,u32 n2) { -return n1 == n2 || (((n1 < n2) && ((n2 - n1) >SNA32_CHECK )) || - ((n1 > n2) && ((n1 - n2) <SNA32_CHECK ))); +s32 diff = n1 - n2; + +return diff >=0 ; }
Hi Mark,
My apolgies for the delayed response on this patch.
I think this simplification to use s32 for iSCSI Command Serial Number arithmetic looks perfectly reasonable, and am including this into lio-core-2.6.git/lio-4.1. Thank you for your contribution!!
Mike, Hannes and Co, do you have any objections here for mainline Open-iSCSI and iSCSI-Target code for .40 code..?
Best Regards,
--nab