From 144026a7bdcd4ab2aef79e06fd21ba2119095c55 Mon Sep 17 00:00:00 2001 From: Peter Lieven Date: Thu, 8 Nov 2012 16:56:44 +0100 Subject: [PATCH] RECONNECT allow a consecutive reconnect only every 5 seconds In case there is an error condition e.g. out of memory. We are heavily disconnecting and reconnecting without any limit. This patch adds a 5 seconds period that has to go by between 2 reconnects. --- include/iscsi-private.h | 5 ++++- lib/connect.c | 5 +++++ 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/include/iscsi-private.h b/include/iscsi-private.h index 5655d9e..99bec11 100644 --- a/include/iscsi-private.h +++ b/include/iscsi-private.h @@ -18,6 +18,7 @@ #define __iscsi_private_h__ #include +#include #if defined(WIN32) #include @@ -133,6 +134,8 @@ struct iscsi_context { int mallocs; int reallocs; int frees; + + time_t last_reconnect; }; #define ISCSI_PDU_IMMEDIATE 0x40 @@ -304,7 +307,7 @@ struct scsi_task *iscsi_scsi_get_task_from_pdu(struct iscsi_pdu *pdu); void iscsi_set_noautoreconnect(struct iscsi_context *iscsi, int state); -void iscsi_decrement_iface_rr(); +void iscsi_decrement_iface_rr(void); #ifdef __cplusplus } diff --git a/lib/connect.c b/lib/connect.c index 76000be..e88a4d6 100644 --- a/lib/connect.c +++ b/lib/connect.c @@ -220,6 +220,10 @@ int iscsi_reconnect(struct iscsi_context *old_iscsi) int retry = 0; + if (old_iscsi->last_reconnect) { + while (time(NULL) - old_iscsi->last_reconnect < 5) sleep(1); + } + try_again: iscsi = iscsi_create_context(old_iscsi->initiator_name); @@ -339,6 +343,7 @@ try_again: free(iscsi); old_iscsi->is_reconnecting = 0; + old_iscsi->last_reconnect = time(NULL); return 0; }