From 913b2ab70861f0c42826f5b4112de79a1fbbdf4c Mon Sep 17 00:00:00 2001 From: Peter Lieven Date: Mon, 13 Apr 2015 12:08:08 +0200 Subject: [PATCH] reconnect: avoid deadlock if socker error is received during reconnect If we are reconnecting and the connection is already established we end up looping forever if there is a socket error before we finish the login process. Fix this by invoking the reconnect callback if there is an error and no new reconnect is scheduled. Signed-off-by: Peter Lieven --- include/iscsi-private.h | 3 +++ lib/connect.c | 4 ++-- lib/socket.c | 3 +++ 3 files changed, 8 insertions(+), 2 deletions(-) diff --git a/include/iscsi-private.h b/include/iscsi-private.h index c993e11..17322d8 100644 --- a/include/iscsi-private.h +++ b/include/iscsi-private.h @@ -367,6 +367,9 @@ uint32_t iscsi_itt_post_increment(struct iscsi_context *iscsi); void iscsi_timeout_scan(struct iscsi_context *iscsi); +void iscsi_reconnect_cb(struct iscsi_context *iscsi _U_, int status, + void *command_data, void *private_data); + #ifdef __cplusplus } #endif diff --git a/lib/connect.c b/lib/connect.c index 2c485e3..a4354d1 100644 --- a/lib/connect.c +++ b/lib/connect.c @@ -249,8 +249,8 @@ void iscsi_defer_reconnect(struct iscsi_context *iscsi) } } -static void iscsi_reconnect_cb(struct iscsi_context *iscsi _U_, int status, - void *command_data _U_, void *private_data _U_) +void iscsi_reconnect_cb(struct iscsi_context *iscsi _U_, int status, + void *command_data _U_, void *private_data _U_) { int i; if (status != SCSI_STATUS_GOOD) { diff --git a/lib/socket.c b/lib/socket.c index f26cb6a..5e76055 100644 --- a/lib/socket.c +++ b/lib/socket.c @@ -780,6 +780,9 @@ iscsi_service_reconnect_if_loggedin(struct iscsi_context *iscsi) } } if (iscsi->old_iscsi) { + if (!iscsi->pending_reconnect) { + iscsi_reconnect_cb(iscsi, SCSI_STATUS_ERROR, NULL, NULL); + } return 0; } return -1;