Commit e27947c7 authored by Alex Elder's avatar Alex Elder Committed by Sage Weil

libceph: define and use an explicit CONNECTED state

There is no state explicitly defined when a ceph connection is fully
operational.  So define one.

It's set when the connection sequence completes successfully, and is
cleared when the connection gets closed.

Be a little more careful when examining the old state when a socket
disconnect event is reported.
Signed-off-by: default avatarAlex Elder <elder@inktank.com>
Reviewed-by: default avatarSage Weil <sage@inktank.com>
parent 3ec50d18
...@@ -120,6 +120,7 @@ struct ceph_msg_pos { ...@@ -120,6 +120,7 @@ struct ceph_msg_pos {
*/ */
#define CONNECTING 1 #define CONNECTING 1
#define NEGOTIATING 2 #define NEGOTIATING 2
#define CONNECTED 5
#define STANDBY 8 /* no outgoing messages, socket closed. we keep #define STANDBY 8 /* no outgoing messages, socket closed. we keep
* the ceph_connection around to maintain shared * the ceph_connection around to maintain shared
* state with the peer. */ * state with the peer. */
......
...@@ -463,6 +463,7 @@ void ceph_con_close(struct ceph_connection *con) ...@@ -463,6 +463,7 @@ void ceph_con_close(struct ceph_connection *con)
ceph_pr_addr(&con->peer_addr.in_addr)); ceph_pr_addr(&con->peer_addr.in_addr));
clear_bit(NEGOTIATING, &con->state); clear_bit(NEGOTIATING, &con->state);
clear_bit(CONNECTING, &con->state); clear_bit(CONNECTING, &con->state);
clear_bit(CONNECTED, &con->state);
clear_bit(STANDBY, &con->state); /* avoid connect_seq bump */ clear_bit(STANDBY, &con->state); /* avoid connect_seq bump */
set_bit(CLOSED, &con->state); set_bit(CLOSED, &con->state);
...@@ -1564,6 +1565,7 @@ static int process_connect(struct ceph_connection *con) ...@@ -1564,6 +1565,7 @@ static int process_connect(struct ceph_connection *con)
} }
clear_bit(NEGOTIATING, &con->state); clear_bit(NEGOTIATING, &con->state);
clear_bit(CONNECTING, &con->state); clear_bit(CONNECTING, &con->state);
set_bit(CONNECTED, &con->state);
con->peer_global_seq = le32_to_cpu(con->in_reply.global_seq); con->peer_global_seq = le32_to_cpu(con->in_reply.global_seq);
con->connect_seq++; con->connect_seq++;
con->peer_features = server_feat; con->peer_features = server_feat;
...@@ -2114,6 +2116,7 @@ static int try_read(struct ceph_connection *con) ...@@ -2114,6 +2116,7 @@ static int try_read(struct ceph_connection *con)
prepare_read_ack(con); prepare_read_ack(con);
break; break;
case CEPH_MSGR_TAG_CLOSE: case CEPH_MSGR_TAG_CLOSE:
clear_bit(CONNECTED, &con->state);
set_bit(CLOSED, &con->state); /* fixme */ set_bit(CLOSED, &con->state); /* fixme */
goto out; goto out;
default: default:
...@@ -2190,11 +2193,13 @@ static void con_work(struct work_struct *work) ...@@ -2190,11 +2193,13 @@ static void con_work(struct work_struct *work)
mutex_lock(&con->mutex); mutex_lock(&con->mutex);
restart: restart:
if (test_and_clear_bit(SOCK_CLOSED, &con->flags)) { if (test_and_clear_bit(SOCK_CLOSED, &con->flags)) {
if (test_and_clear_bit(CONNECTING, &con->state)) { if (test_and_clear_bit(CONNECTED, &con->state))
con->error_msg = "socket closed";
else if (test_and_clear_bit(CONNECTING, &con->state)) {
clear_bit(NEGOTIATING, &con->state); clear_bit(NEGOTIATING, &con->state);
con->error_msg = "connection failed"; con->error_msg = "connection failed";
} else { } else {
con->error_msg = "socket closed"; con->error_msg = "unrecognized con state";
} }
goto fault; goto fault;
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment