From b2383207675b3f5562d37dc0aaaf978e0b009567 Mon Sep 17 00:00:00 2001 From: Vladislav Bolkhovitin Date: Tue, 13 Nov 2012 20:55:51 +0000 Subject: [PATCH] target_del(): don't exit on existing sessions Target_del() might has not yet received all connections close events, so it can still has alive sessions. Wait for them to disappear. git-svn-id: http://svn.code.sf.net/p/scst/svn/trunk@4617 d57e44dd-8a1f-0410-8b47-8ef2f437770f --- iscsi-scst/usr/target.c | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/iscsi-scst/usr/target.c b/iscsi-scst/usr/target.c index 9f0fb4211..d34a9241a 100644 --- a/iscsi-scst/usr/target.c +++ b/iscsi-scst/usr/target.c @@ -28,6 +28,7 @@ #include #include #include +#include #include "iscsid.h" @@ -340,13 +341,16 @@ int target_del(u32 tid, u32 cookie) list_del(&target->tlist); - /* We might need to handle session(s) removal event(s) from the kernel */ - while (handle_iscsi_events(nl_fd, false) == 0); + while (1) { + /* We might need to handle session(s) removal event(s) from the kernel */ + while (handle_iscsi_events(nl_fd, false) == 0); - if (!list_empty(&target->sessions_list)) { - log_error("%s: target %u still has sessions\n", __FUNCTION__, - tid); - exit(-1); + if (list_empty(&target->sessions_list)) + break; + + /* We have not yet received session(s) removal event(s), so keep waiting */ + log_debug(1, "Target %d has sessions, keep waiting", tid); + usleep(50000); } if (target->tgt_enabled)