Skip to content

Commit

Permalink
lib: reserve the fd on reconnect
Browse files Browse the repository at this point in the history
On reconnect case, the iscsi_tcp_connect tries to reuse
the fd number of old_iscsi. However, this fd could have been
already closed in previous iscsi_tcp_disconnect if
iscsi->fd == iscsi->old_iscsi->fd and the fd number
might have been allocated to some other caller, in this
case the fd reuse in iscsi_tcp_connect is not safe anymore.

Solve this by not closing the fd if iscsi and old_iscsi
share the same fd on reconnect to "really" reserve this
fd number.

Signed-off-by: Tianren Zhang <[email protected]>
  • Loading branch information
Tianren Zhang committed Nov 22, 2024
1 parent 7d1c926 commit 97ba4c3
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion lib/socket.c
Original file line number Diff line number Diff line change
Expand Up @@ -416,7 +416,11 @@ iscsi_tcp_disconnect(struct iscsi_context *iscsi)
return -1;
}

close(iscsi->fd);
if (iscsi->old_iscsi && iscsi->old_iscsi->fd == iscsi->fd) {
/* Reserve this fd because old_iscsi->fd will be reused */
} else {
close(iscsi->fd);
}

if (!(iscsi->pending_reconnect && iscsi->old_iscsi) &&
iscsi->connected_portal[0]) {
Expand Down

0 comments on commit 97ba4c3

Please sign in to comment.