diff options
author | Sage Weil <sage@inktank.com> | 2012-07-30 21:16:16 -0400 |
---|---|---|
committer | Sage Weil <sage@inktank.com> | 2012-07-30 21:16:16 -0400 |
commit | 8007b8d626b49c34fb146ec16dc639d8b10c862f (patch) | |
tree | 0271899a42c00696a7fefad0bdab0c7f5e74b892 /net | |
parent | 09d9032751bfdabcba8752ab4b01a30fedea3d67 (diff) |
libceph: fix handling of immediate socket connect failure
If the connect() call immediately fails such that sock == NULL, we
still need con_close_socket() to reset our socket state to CLOSED.
Signed-off-by: Sage Weil <sage@inktank.com>
Reviewed-by: Alex Elder <elder@inktank.com>
Diffstat (limited to 'net')
-rw-r--r-- | net/ceph/messenger.c | 26 |
1 files changed, 19 insertions, 7 deletions
diff --git a/net/ceph/messenger.c b/net/ceph/messenger.c index fa16f2cc35fe..a6a0c7a0a979 100644 --- a/net/ceph/messenger.c +++ b/net/ceph/messenger.c | |||
@@ -224,6 +224,8 @@ static void con_sock_state_init(struct ceph_connection *con) | |||
224 | old_state = atomic_xchg(&con->sock_state, CON_SOCK_STATE_CLOSED); | 224 | old_state = atomic_xchg(&con->sock_state, CON_SOCK_STATE_CLOSED); |
225 | if (WARN_ON(old_state != CON_SOCK_STATE_NEW)) | 225 | if (WARN_ON(old_state != CON_SOCK_STATE_NEW)) |
226 | printk("%s: unexpected old state %d\n", __func__, old_state); | 226 | printk("%s: unexpected old state %d\n", __func__, old_state); |
227 | dout("%s con %p sock %d -> %d\n", __func__, con, old_state, | ||
228 | CON_SOCK_STATE_CLOSED); | ||
227 | } | 229 | } |
228 | 230 | ||
229 | static void con_sock_state_connecting(struct ceph_connection *con) | 231 | static void con_sock_state_connecting(struct ceph_connection *con) |
@@ -233,6 +235,8 @@ static void con_sock_state_connecting(struct ceph_connection *con) | |||
233 | old_state = atomic_xchg(&con->sock_state, CON_SOCK_STATE_CONNECTING); | 235 | old_state = atomic_xchg(&con->sock_state, CON_SOCK_STATE_CONNECTING); |
234 | if (WARN_ON(old_state != CON_SOCK_STATE_CLOSED)) | 236 | if (WARN_ON(old_state != CON_SOCK_STATE_CLOSED)) |
235 | printk("%s: unexpected old state %d\n", __func__, old_state); | 237 | printk("%s: unexpected old state %d\n", __func__, old_state); |
238 | dout("%s con %p sock %d -> %d\n", __func__, con, old_state, | ||
239 | CON_SOCK_STATE_CONNECTING); | ||
236 | } | 240 | } |
237 | 241 | ||
238 | static void con_sock_state_connected(struct ceph_connection *con) | 242 | static void con_sock_state_connected(struct ceph_connection *con) |
@@ -242,6 +246,8 @@ static void con_sock_state_connected(struct ceph_connection *con) | |||
242 | old_state = atomic_xchg(&con->sock_state, CON_SOCK_STATE_CONNECTED); | 246 | old_state = atomic_xchg(&con->sock_state, CON_SOCK_STATE_CONNECTED); |
243 | if (WARN_ON(old_state != CON_SOCK_STATE_CONNECTING)) | 247 | if (WARN_ON(old_state != CON_SOCK_STATE_CONNECTING)) |
244 | printk("%s: unexpected old state %d\n", __func__, old_state); | 248 | printk("%s: unexpected old state %d\n", __func__, old_state); |
249 | dout("%s con %p sock %d -> %d\n", __func__, con, old_state, | ||
250 | CON_SOCK_STATE_CONNECTED); | ||
245 | } | 251 | } |
246 | 252 | ||
247 | static void con_sock_state_closing(struct ceph_connection *con) | 253 | static void con_sock_state_closing(struct ceph_connection *con) |
@@ -253,6 +259,8 @@ static void con_sock_state_closing(struct ceph_connection *con) | |||
253 | old_state != CON_SOCK_STATE_CONNECTED && | 259 | old_state != CON_SOCK_STATE_CONNECTED && |
254 | old_state != CON_SOCK_STATE_CLOSING)) | 260 | old_state != CON_SOCK_STATE_CLOSING)) |
255 | printk("%s: unexpected old state %d\n", __func__, old_state); | 261 | printk("%s: unexpected old state %d\n", __func__, old_state); |
262 | dout("%s con %p sock %d -> %d\n", __func__, con, old_state, | ||
263 | CON_SOCK_STATE_CLOSING); | ||
256 | } | 264 | } |
257 | 265 | ||
258 | static void con_sock_state_closed(struct ceph_connection *con) | 266 | static void con_sock_state_closed(struct ceph_connection *con) |
@@ -262,8 +270,11 @@ static void con_sock_state_closed(struct ceph_connection *con) | |||
262 | old_state = atomic_xchg(&con->sock_state, CON_SOCK_STATE_CLOSED); | 270 | old_state = atomic_xchg(&con->sock_state, CON_SOCK_STATE_CLOSED); |
263 | if (WARN_ON(old_state != CON_SOCK_STATE_CONNECTED && | 271 | if (WARN_ON(old_state != CON_SOCK_STATE_CONNECTED && |
264 | old_state != CON_SOCK_STATE_CLOSING && | 272 | old_state != CON_SOCK_STATE_CLOSING && |
265 | old_state != CON_SOCK_STATE_CONNECTING)) | 273 | old_state != CON_SOCK_STATE_CONNECTING && |
274 | old_state != CON_SOCK_STATE_CLOSED)) | ||
266 | printk("%s: unexpected old state %d\n", __func__, old_state); | 275 | printk("%s: unexpected old state %d\n", __func__, old_state); |
276 | dout("%s con %p sock %d -> %d\n", __func__, con, old_state, | ||
277 | CON_SOCK_STATE_CLOSED); | ||
267 | } | 278 | } |
268 | 279 | ||
269 | /* | 280 | /* |
@@ -448,14 +459,14 @@ static int ceph_tcp_sendpage(struct socket *sock, struct page *page, | |||
448 | */ | 459 | */ |
449 | static int con_close_socket(struct ceph_connection *con) | 460 | static int con_close_socket(struct ceph_connection *con) |
450 | { | 461 | { |
451 | int rc; | 462 | int rc = 0; |
452 | 463 | ||
453 | dout("con_close_socket on %p sock %p\n", con, con->sock); | 464 | dout("con_close_socket on %p sock %p\n", con, con->sock); |
454 | if (!con->sock) | 465 | if (con->sock) { |
455 | return 0; | 466 | rc = con->sock->ops->shutdown(con->sock, SHUT_RDWR); |
456 | rc = con->sock->ops->shutdown(con->sock, SHUT_RDWR); | 467 | sock_release(con->sock); |
457 | sock_release(con->sock); | 468 | con->sock = NULL; |
458 | con->sock = NULL; | 469 | } |
459 | 470 | ||
460 | /* | 471 | /* |
461 | * Forcibly clear the SOCK_CLOSED flag. It gets set | 472 | * Forcibly clear the SOCK_CLOSED flag. It gets set |
@@ -464,6 +475,7 @@ static int con_close_socket(struct ceph_connection *con) | |||
464 | * shut the socket down. | 475 | * shut the socket down. |
465 | */ | 476 | */ |
466 | clear_bit(CON_FLAG_SOCK_CLOSED, &con->flags); | 477 | clear_bit(CON_FLAG_SOCK_CLOSED, &con->flags); |
478 | |||
467 | con_sock_state_closed(con); | 479 | con_sock_state_closed(con); |
468 | return rc; | 480 | return rc; |
469 | } | 481 | } |