diff --git a/iscsi-scst/kernel/conn.c b/iscsi-scst/kernel/conn.c index ff72ad835..2b9a64d29 100644 --- a/iscsi-scst/kernel/conn.c +++ b/iscsi-scst/kernel/conn.c @@ -894,7 +894,7 @@ int __del_conn(struct iscsi_session *session, struct iscsi_kern_conn_info *info) conn = conn_lookup(session, info->cid); if (!conn) { - PRINT_ERROR("Connection %d not found", info->cid); + PRINT_WARNING("Connection %d not found", info->cid); return err; } diff --git a/iscsi-scst/usr/conn.c b/iscsi-scst/usr/conn.c index 8ce5fdf38..cd039ab09 100644 --- a/iscsi-scst/usr/conn.c +++ b/iscsi-scst/usr/conn.c @@ -69,6 +69,9 @@ void conn_pass_to_kern(struct connection *conn, int fd) err = kernel_conn_create(conn->tid, conn->sess->sid.id64, conn->cid, conn->stat_sn, conn->exp_stat_sn, fd); + if (err == 0) + conn->passed_to_kern = 1; + /* We don't need to return err, because we are going to close conn anyway */ return; } diff --git a/iscsi-scst/usr/ctldev.c b/iscsi-scst/usr/ctldev.c index 84d4d32d6..dcaa6c255 100644 --- a/iscsi-scst/usr/ctldev.c +++ b/iscsi-scst/usr/ctldev.c @@ -303,7 +303,7 @@ int kernel_conn_destroy(u32 tid, u64 sid, u32 cid) if ((err = ioctl(ctrl_fd, DEL_CONN, &info)) < 0) { err = -errno; - log_error("Can't destroy conn (errno %d, tid %u, sid 0x%" + log_debug(2, "Can't destroy conn (errno %d, tid %u, sid 0x%" PRIx64 ", cid %u\n", errno, tid, sid, cid); } @@ -437,7 +437,7 @@ int kernel_session_destroy(u32 tid, u64 sid) res = ioctl(ctrl_fd, DEL_SESSION, &info); if (res < 0) { res = -errno; - log_error("Can't destroy sess 0x%" PRIu64 " (tid %d): %s\n", + log_debug(2, "Can't destroy sess 0x%" PRIu64 " (tid %d): %s\n", sid, tid, strerror(errno)); } diff --git a/iscsi-scst/usr/event.c b/iscsi-scst/usr/event.c index 784f8c67f..23448179c 100644 --- a/iscsi-scst/usr/event.c +++ b/iscsi-scst/usr/event.c @@ -112,6 +112,7 @@ static int send_mgmt_cmd_res(u32 tid, u32 cookie, u32 req_cmd, int result, res = ioctl(ctrl_fd, MGMT_CMD_CALLBACK, &cinfo); if (res != 0) { + res = -errno; log_error("Can't send mgmt reply (cookie %d, result %d, " "res %d): %s\n", cookie, result, res, strerror(errno)); } diff --git a/iscsi-scst/usr/iscsi_scstd.c b/iscsi-scst/usr/iscsi_scstd.c index fd22b6986..d28df2fcc 100644 --- a/iscsi-scst/usr/iscsi_scstd.c +++ b/iscsi-scst/usr/iscsi_scstd.c @@ -557,12 +557,23 @@ static void event_loop(void) event_conn(conn, pollfd); if (conn->state == STATE_CLOSE) { + struct session *sess = conn->sess; log_debug(1, "closing conn %p", conn); conn_free_pdu(conn); close(pollfd->fd); pollfd->fd = -1; incoming[i] = NULL; incoming_cnt--; + if (conn->passed_to_kern) { + kernel_conn_destroy(conn->tid, + conn->sess->sid.id64, conn->cid); + } else { + conn_free(conn); + log_debug(1, "conn %p freed (sess %p, empty %d)", + conn, sess, sess ? list_empty(&sess->conn_list) : -1); + if (sess && list_empty(&sess->conn_list)) + session_free(sess); + } } } } diff --git a/iscsi-scst/usr/iscsid.h b/iscsi-scst/usr/iscsid.h index 33cb34316..0621fc958 100644 --- a/iscsi-scst/usr/iscsid.h +++ b/iscsi-scst/usr/iscsid.h @@ -70,6 +70,8 @@ struct connection { int iostate; int fd; + unsigned int passed_to_kern:1; + struct session *sess; u32 tid; diff --git a/iscsi-scst/usr/session.c b/iscsi-scst/usr/session.c index a06474917..1836d7477 100644 --- a/iscsi-scst/usr/session.c +++ b/iscsi-scst/usr/session.c @@ -152,8 +152,7 @@ void session_free(struct session *session) { log_debug(1, "Freeing session sid %#"PRIx64, session->sid.id64); - if (!session->sid.id.tsih) - kernel_session_destroy(session->target->tid, session->sid.id64); + kernel_session_destroy(session->target->tid, session->sid.id64); if (session->target) { struct target *target = session->target;