123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144 |
- using System;
- using System.Collections.Generic;
- using System.Text;
- namespace ISCSI.Server
- {
- internal class ISCSISession
- {
- public int MaxConnections = DefaultParameters.Session.MaxConnections;
- public bool InitialR2T = DefaultParameters.Session.InitialR2T;
- public bool ImmediateData = DefaultParameters.Session.ImmediateData;
- public int MaxBurstLength = DefaultParameters.Session.MaxBurstLength;
- public int FirstBurstLength = DefaultParameters.Session.FirstBurstLength;
- public int DefaultTime2Wait = DefaultParameters.Session.DefaultTime2Wait;
- public int DefaultTime2Retain = DefaultParameters.Session.DefaultTime2Retain;
- public int MaxOutstandingR2T = DefaultParameters.Session.MaxOutstandingR2T;
- public bool DataPDUInOrder = DefaultParameters.Session.DataPDUInOrder;
- public bool DataSequenceInOrder = DefaultParameters.Session.DataSequenceInOrder;
- public int ErrorRecoveryLevel = DefaultParameters.Session.ErrorRecoveryLevel;
- public uint CommandQueueSize = ISCSIServer.DefaultCommandQueueSize;
- public readonly string InitiatorName;
- public readonly ulong ISID;
- public readonly ushort TSIH;
- public bool IsDiscovery;
- public bool IsFullFeaturePhase;
- public bool CommandNumberingStarted;
- public uint ExpCmdSN;
- public ISCSITarget Target;
- public List<uint> CommandsInTransfer = new List<uint>();
- public List<SCSICommandPDU> DelayedCommands = new List<SCSICommandPDU>();
-
-
-
-
-
- private uint m_nextTransferTag = 0;
- private object m_transferTagLock = new object();
- public ISCSISession(string initiatorName, ulong isid, ushort tsih)
- {
- InitiatorName = initiatorName;
- ISID = isid;
- TSIH = tsih;
- }
- public uint GetNextTransferTag()
- {
- lock (m_transferTagLock)
- {
- uint transferTag = m_nextTransferTag;
- m_nextTransferTag++;
- return transferTag;
- }
- }
- public bool IsPrecedingCommandPending(uint cmdSN)
- {
- foreach (uint entry in CommandsInTransfer)
- {
- if (IsFirstCmdSNPreceding(entry, cmdSN))
- {
- return true;
- }
- }
- return false;
- }
- public List<SCSICommandPDU> GetDelayedCommandsReadyForExecution()
- {
- List<SCSICommandPDU> result = new List<SCSICommandPDU>();
- if (CommandsInTransfer.Count == 0)
- {
- result.AddRange(DelayedCommands);
- DelayedCommands.Clear();
- return result;
- }
-
- uint earliestCmdSN = CommandsInTransfer[0];
- for(int index = 1; index < CommandsInTransfer.Count; index++)
- {
- if (IsFirstCmdSNPreceding(CommandsInTransfer[index], earliestCmdSN))
- {
- earliestCmdSN = CommandsInTransfer[index];
- }
- }
-
- for(int index = 0; index < DelayedCommands.Count; index++)
- {
- SCSICommandPDU delayedCommand = DelayedCommands[index];
- if (IsFirstCmdSNPreceding(delayedCommand.CmdSN, earliestCmdSN))
- {
- result.Add(delayedCommand);
- DelayedCommands.RemoveAt(index);
- index--;
- }
- }
- return result;
- }
- public string SessionIdentifier
- {
- get
- {
- return String.Format("{0},ISID={1},TSIH={2}", InitiatorName, ISID.ToString("x"), TSIH.ToString("x"));
- }
- }
-
-
-
- public static bool IsFirstCmdSNPreceding(uint cmdSN1, uint cmdSN2)
- {
-
- const uint commandWindow = 2 ^ 31 - 1;
- if (cmdSN2 >= commandWindow)
- {
- if ((cmdSN1 > cmdSN2 - commandWindow) && (cmdSN1 < cmdSN2))
- {
- return true;
- }
- }
- else
- {
- if ((cmdSN1 > cmdSN2 - commandWindow) || (cmdSN1 < cmdSN2))
- {
- return true;
- }
- }
- return false;
- }
- }
- }
|