PDU use serial32 arithmetic for cmdsn, maxcmdsn and expcmdsn.

RFC3720 says that cmdsn comparison must be done using
serial32 arithmetic. This will definetly avoid a deadlock
if cmdsn wraps from 2^32-1 to 0.

Signed-off-by: Peter Lieven <pl@kamp.de>
This commit is contained in:
Peter Lieven
2012-11-28 10:37:28 +01:00
parent 700d363a88
commit cd09c0f17d
6 changed files with 30 additions and 9 deletions

View File

@@ -30,6 +30,24 @@
#include "scsi-lowlevel.h"
#include "slist.h"
/* This adds 32-bit serial comparision as defined in RFC1982.
* It returns 0 for equality, 1 if s1 is greater than s2 and
* -1 if s1 is less than s2. According to RFC1982 section 3.2
* there are rare cases where the result of the comparision is
* undefined e.g. when s1 = 0 and s2=2^31. This cases should
* not happen in iSCSI protocol.
*/
int
iscsi_serial32_compare(u_int32_t s1, u_int32_t s2) {
if (s1 == s2) return 0;
if (s1 < s2 && s2-s1 < (u_int32_t)1<<31) return -1;
if (s1 > s2 && s1-s2 < (u_int32_t)1<<31) return 1;
if (s1 > s2 && s1-s2 > (u_int32_t)1<<31) return -1;
if (s1 < s2 && s2-s1 > (u_int32_t)1<<31) return 1;
/* undefined result */
return -1;
}
struct iscsi_pdu *
iscsi_allocate_pdu_with_itt_flags_size(struct iscsi_context *iscsi, enum iscsi_opcode opcode,
enum iscsi_opcode response_opcode, uint32_t itt, uint32_t flags, size_t payload_size)