diff options
author | Hannes Reinecke <hare@suse.de> | 2009-08-20 16:10:57 -0400 |
---|---|---|
committer | James Bottomley <James.Bottomley@suse.de> | 2009-09-05 10:42:39 -0400 |
commit | 523eeac6703a995d58918aaf321f128f75c13108 (patch) | |
tree | b9d0ffa377b5d41144961709d94b10415f610e19 /drivers/scsi | |
parent | ac280b670e6d6666667aba02324e2fc50bd96ae7 (diff) |
[SCSI] iscsi_tcp: Evaluate socket state in data_ready()
The network core will call the state_change() callback
prior to the data_ready() callback, which might cause
us to lose a connection state change.
So we have to evaluate the socket state at the end
of the data_ready() callback, too.
Signed-off-by: Hannes Reinecke <hare@suse.de>
Signed-off-by: Mike Christie <michaelc@cs.wisc.edu>
Signed-off-by: James Bottomley <James.Bottomley@suse.de>
Diffstat (limited to 'drivers/scsi')
-rw-r--r-- | drivers/scsi/iscsi_tcp.c | 28 |
1 files changed, 25 insertions, 3 deletions
diff --git a/drivers/scsi/iscsi_tcp.c b/drivers/scsi/iscsi_tcp.c index 518dbd91df85..c7e2ff24ee9e 100644 --- a/drivers/scsi/iscsi_tcp.c +++ b/drivers/scsi/iscsi_tcp.c | |||
@@ -99,6 +99,24 @@ static int iscsi_sw_tcp_recv(read_descriptor_t *rd_desc, struct sk_buff *skb, | |||
99 | return total_consumed; | 99 | return total_consumed; |
100 | } | 100 | } |
101 | 101 | ||
102 | /** | ||
103 | * iscsi_sw_sk_state_check - check socket state | ||
104 | * @sk: socket | ||
105 | * | ||
106 | * If the socket is in CLOSE or CLOSE_WAIT we should | ||
107 | * not close the connection if there is still some | ||
108 | * data pending. | ||
109 | */ | ||
110 | static inline int iscsi_sw_sk_state_check(struct sock *sk) | ||
111 | { | ||
112 | if ((sk->sk_state == TCP_CLOSE_WAIT || | ||
113 | sk->sk_state == TCP_CLOSE) && | ||
114 | !atomic_read(&sk->sk_rmem_alloc)) | ||
115 | return -ECONNRESET; | ||
116 | |||
117 | return 0; | ||
118 | } | ||
119 | |||
102 | static void iscsi_sw_tcp_data_ready(struct sock *sk, int flag) | 120 | static void iscsi_sw_tcp_data_ready(struct sock *sk, int flag) |
103 | { | 121 | { |
104 | struct iscsi_conn *conn = sk->sk_user_data; | 122 | struct iscsi_conn *conn = sk->sk_user_data; |
@@ -117,6 +135,12 @@ static void iscsi_sw_tcp_data_ready(struct sock *sk, int flag) | |||
117 | rd_desc.count = 1; | 135 | rd_desc.count = 1; |
118 | tcp_read_sock(sk, &rd_desc, iscsi_sw_tcp_recv); | 136 | tcp_read_sock(sk, &rd_desc, iscsi_sw_tcp_recv); |
119 | 137 | ||
138 | if (iscsi_sw_sk_state_check(sk) < 0) { | ||
139 | ISCSI_SW_TCP_DBG(conn, "iscsi_tcp_data_ready: " | ||
140 | "TCP_CLOSE|TCP_CLOSE_WAIT\n"); | ||
141 | iscsi_conn_failure(conn, ISCSI_ERR_CONN_FAILED); | ||
142 | } | ||
143 | |||
120 | read_unlock(&sk->sk_callback_lock); | 144 | read_unlock(&sk->sk_callback_lock); |
121 | 145 | ||
122 | /* If we had to (atomically) map a highmem page, | 146 | /* If we had to (atomically) map a highmem page, |
@@ -137,9 +161,7 @@ static void iscsi_sw_tcp_state_change(struct sock *sk) | |||
137 | conn = (struct iscsi_conn*)sk->sk_user_data; | 161 | conn = (struct iscsi_conn*)sk->sk_user_data; |
138 | session = conn->session; | 162 | session = conn->session; |
139 | 163 | ||
140 | if ((sk->sk_state == TCP_CLOSE_WAIT || | 164 | if (iscsi_sw_sk_state_check(sk) < 0) { |
141 | sk->sk_state == TCP_CLOSE) && | ||
142 | !atomic_read(&sk->sk_rmem_alloc)) { | ||
143 | ISCSI_SW_TCP_DBG(conn, "iscsi_tcp_state_change: " | 165 | ISCSI_SW_TCP_DBG(conn, "iscsi_tcp_state_change: " |
144 | "TCP_CLOSE|TCP_CLOSE_WAIT\n"); | 166 | "TCP_CLOSE|TCP_CLOSE_WAIT\n"); |
145 | iscsi_conn_failure(conn, ISCSI_ERR_CONN_FAILED); | 167 | iscsi_conn_failure(conn, ISCSI_ERR_CONN_FAILED); |