Commit 6d7f62bf authored by Ilya Dryomov's avatar Ilya Dryomov

libceph: rename and export con->state states

In preparation for msgr2, rename msgr1 specific states and move the
defines to the header file.

Also drop state transition comments.  They don't cover all possible
transitions (e.g. NEGOTIATING -> STANDBY, etc) and currently do more
harm than good.
Signed-off-by: default avatarIlya Dryomov <idryomov@gmail.com>
parent 30be780a
...@@ -239,6 +239,16 @@ struct ceph_msg { ...@@ -239,6 +239,16 @@ struct ceph_msg {
struct ceph_msgpool *pool; struct ceph_msgpool *pool;
}; };
/*
* connection states
*/
#define CEPH_CON_S_CLOSED 1
#define CEPH_CON_S_PREOPEN 2
#define CEPH_CON_S_V1_BANNER 3
#define CEPH_CON_S_V1_CONNECT_MSG 4
#define CEPH_CON_S_OPEN 5
#define CEPH_CON_S_STANDBY 6
/* ceph connection fault delay defaults, for exponential backoff */ /* ceph connection fault delay defaults, for exponential backoff */
#define BASE_DELAY_INTERVAL (HZ / 4) #define BASE_DELAY_INTERVAL (HZ / 4)
#define MAX_DELAY_INTERVAL (15 * HZ) #define MAX_DELAY_INTERVAL (15 * HZ)
...@@ -257,7 +267,7 @@ struct ceph_connection { ...@@ -257,7 +267,7 @@ struct ceph_connection {
struct ceph_messenger *msgr; struct ceph_messenger *msgr;
int state; int state; /* CEPH_CON_S_* */
atomic_t sock_state; atomic_t sock_state;
struct socket *sock; struct socket *sock;
struct ceph_entity_addr peer_addr; /* peer address */ struct ceph_entity_addr peer_addr; /* peer address */
......
...@@ -82,16 +82,6 @@ ...@@ -82,16 +82,6 @@
#define CON_SOCK_STATE_CONNECTED 3 /* -> CLOSING or -> CLOSED */ #define CON_SOCK_STATE_CONNECTED 3 /* -> CLOSING or -> CLOSED */
#define CON_SOCK_STATE_CLOSING 4 /* -> CLOSED */ #define CON_SOCK_STATE_CLOSING 4 /* -> CLOSED */
/*
* connection states
*/
#define CON_STATE_CLOSED 1 /* -> PREOPEN */
#define CON_STATE_PREOPEN 2 /* -> CONNECTING, CLOSED */
#define CON_STATE_CONNECTING 3 /* -> NEGOTIATING, CLOSED */
#define CON_STATE_NEGOTIATING 4 /* -> OPEN, CLOSED */
#define CON_STATE_OPEN 5 /* -> STANDBY, CLOSED */
#define CON_STATE_STANDBY 6 /* -> PREOPEN, CLOSED */
/* /*
* ceph_connection flag bits * ceph_connection flag bits
*/ */
...@@ -674,7 +664,7 @@ void ceph_con_close(struct ceph_connection *con) ...@@ -674,7 +664,7 @@ void ceph_con_close(struct ceph_connection *con)
{ {
mutex_lock(&con->mutex); mutex_lock(&con->mutex);
dout("con_close %p peer %s\n", con, ceph_pr_addr(&con->peer_addr)); dout("con_close %p peer %s\n", con, ceph_pr_addr(&con->peer_addr));
con->state = CON_STATE_CLOSED; con->state = CEPH_CON_S_CLOSED;
con_flag_clear(con, CON_FLAG_LOSSYTX); /* so we retry next connect */ con_flag_clear(con, CON_FLAG_LOSSYTX); /* so we retry next connect */
con_flag_clear(con, CON_FLAG_KEEPALIVE_PENDING); con_flag_clear(con, CON_FLAG_KEEPALIVE_PENDING);
...@@ -698,8 +688,8 @@ void ceph_con_open(struct ceph_connection *con, ...@@ -698,8 +688,8 @@ void ceph_con_open(struct ceph_connection *con,
mutex_lock(&con->mutex); mutex_lock(&con->mutex);
dout("con_open %p %s\n", con, ceph_pr_addr(addr)); dout("con_open %p %s\n", con, ceph_pr_addr(addr));
WARN_ON(con->state != CON_STATE_CLOSED); WARN_ON(con->state != CEPH_CON_S_CLOSED);
con->state = CON_STATE_PREOPEN; con->state = CEPH_CON_S_PREOPEN;
con->peer_name.type = (__u8) entity_type; con->peer_name.type = (__u8) entity_type;
con->peer_name.num = cpu_to_le64(entity_num); con->peer_name.num = cpu_to_le64(entity_num);
...@@ -739,7 +729,7 @@ void ceph_con_init(struct ceph_connection *con, void *private, ...@@ -739,7 +729,7 @@ void ceph_con_init(struct ceph_connection *con, void *private,
INIT_LIST_HEAD(&con->out_sent); INIT_LIST_HEAD(&con->out_sent);
INIT_DELAYED_WORK(&con->work, ceph_con_workfn); INIT_DELAYED_WORK(&con->work, ceph_con_workfn);
con->state = CON_STATE_CLOSED; con->state = CEPH_CON_S_CLOSED;
} }
EXPORT_SYMBOL(ceph_con_init); EXPORT_SYMBOL(ceph_con_init);
...@@ -2183,7 +2173,7 @@ static int process_connect(struct ceph_connection *con) ...@@ -2183,7 +2173,7 @@ static int process_connect(struct ceph_connection *con)
if (con->ops->peer_reset) if (con->ops->peer_reset)
con->ops->peer_reset(con); con->ops->peer_reset(con);
mutex_lock(&con->mutex); mutex_lock(&con->mutex);
if (con->state != CON_STATE_NEGOTIATING) if (con->state != CEPH_CON_S_V1_CONNECT_MSG)
return -EAGAIN; return -EAGAIN;
break; break;
...@@ -2232,8 +2222,8 @@ static int process_connect(struct ceph_connection *con) ...@@ -2232,8 +2222,8 @@ static int process_connect(struct ceph_connection *con)
return -1; return -1;
} }
WARN_ON(con->state != CON_STATE_NEGOTIATING); WARN_ON(con->state != CEPH_CON_S_V1_CONNECT_MSG);
con->state = CON_STATE_OPEN; con->state = CEPH_CON_S_OPEN;
con->auth_retry = 0; /* we authenticated; clear flag */ con->auth_retry = 0; /* we authenticated; clear flag */
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++;
...@@ -2583,16 +2573,16 @@ static int try_write(struct ceph_connection *con) ...@@ -2583,16 +2573,16 @@ static int try_write(struct ceph_connection *con)
int ret = 1; int ret = 1;
dout("try_write start %p state %d\n", con, con->state); dout("try_write start %p state %d\n", con, con->state);
if (con->state != CON_STATE_PREOPEN && if (con->state != CEPH_CON_S_PREOPEN &&
con->state != CON_STATE_CONNECTING && con->state != CEPH_CON_S_V1_BANNER &&
con->state != CON_STATE_NEGOTIATING && con->state != CEPH_CON_S_V1_CONNECT_MSG &&
con->state != CON_STATE_OPEN) con->state != CEPH_CON_S_OPEN)
return 0; return 0;
/* open the socket first? */ /* open the socket first? */
if (con->state == CON_STATE_PREOPEN) { if (con->state == CEPH_CON_S_PREOPEN) {
BUG_ON(con->sock); BUG_ON(con->sock);
con->state = CON_STATE_CONNECTING; con->state = CEPH_CON_S_V1_BANNER;
con_out_kvec_reset(con); con_out_kvec_reset(con);
prepare_write_banner(con); prepare_write_banner(con);
...@@ -2646,7 +2636,7 @@ static int try_write(struct ceph_connection *con) ...@@ -2646,7 +2636,7 @@ static int try_write(struct ceph_connection *con)
} }
do_next: do_next:
if (con->state == CON_STATE_OPEN) { if (con->state == CEPH_CON_S_OPEN) {
if (con_flag_test_and_clear(con, CON_FLAG_KEEPALIVE_PENDING)) { if (con_flag_test_and_clear(con, CON_FLAG_KEEPALIVE_PENDING)) {
prepare_write_keepalive(con); prepare_write_keepalive(con);
goto more; goto more;
...@@ -2680,9 +2670,9 @@ static int try_read(struct ceph_connection *con) ...@@ -2680,9 +2670,9 @@ static int try_read(struct ceph_connection *con)
more: more:
dout("try_read start %p state %d\n", con, con->state); dout("try_read start %p state %d\n", con, con->state);
if (con->state != CON_STATE_CONNECTING && if (con->state != CEPH_CON_S_V1_BANNER &&
con->state != CON_STATE_NEGOTIATING && con->state != CEPH_CON_S_V1_CONNECT_MSG &&
con->state != CON_STATE_OPEN) con->state != CEPH_CON_S_OPEN)
return 0; return 0;
BUG_ON(!con->sock); BUG_ON(!con->sock);
...@@ -2690,8 +2680,7 @@ static int try_read(struct ceph_connection *con) ...@@ -2690,8 +2680,7 @@ static int try_read(struct ceph_connection *con)
dout("try_read tag %d in_base_pos %d\n", (int)con->in_tag, dout("try_read tag %d in_base_pos %d\n", (int)con->in_tag,
con->in_base_pos); con->in_base_pos);
if (con->state == CON_STATE_CONNECTING) { if (con->state == CEPH_CON_S_V1_BANNER) {
dout("try_read connecting\n");
ret = read_partial_banner(con); ret = read_partial_banner(con);
if (ret <= 0) if (ret <= 0)
goto out; goto out;
...@@ -2699,7 +2688,7 @@ static int try_read(struct ceph_connection *con) ...@@ -2699,7 +2688,7 @@ static int try_read(struct ceph_connection *con)
if (ret < 0) if (ret < 0)
goto out; goto out;
con->state = CON_STATE_NEGOTIATING; con->state = CEPH_CON_S_V1_CONNECT_MSG;
/* /*
* Received banner is good, exchange connection info. * Received banner is good, exchange connection info.
...@@ -2715,8 +2704,7 @@ static int try_read(struct ceph_connection *con) ...@@ -2715,8 +2704,7 @@ static int try_read(struct ceph_connection *con)
goto out; goto out;
} }
if (con->state == CON_STATE_NEGOTIATING) { if (con->state == CEPH_CON_S_V1_CONNECT_MSG) {
dout("try_read negotiating\n");
ret = read_partial_connect(con); ret = read_partial_connect(con);
if (ret <= 0) if (ret <= 0)
goto out; goto out;
...@@ -2726,7 +2714,7 @@ static int try_read(struct ceph_connection *con) ...@@ -2726,7 +2714,7 @@ static int try_read(struct ceph_connection *con)
goto more; goto more;
} }
WARN_ON(con->state != CON_STATE_OPEN); WARN_ON(con->state != CEPH_CON_S_OPEN);
if (con->in_base_pos < 0) { if (con->in_base_pos < 0) {
/* /*
...@@ -2760,7 +2748,7 @@ static int try_read(struct ceph_connection *con) ...@@ -2760,7 +2748,7 @@ static int try_read(struct ceph_connection *con)
break; break;
case CEPH_MSGR_TAG_CLOSE: case CEPH_MSGR_TAG_CLOSE:
con_close_socket(con); con_close_socket(con);
con->state = CON_STATE_CLOSED; con->state = CEPH_CON_S_CLOSED;
goto out; goto out;
default: default:
goto bad_tag; goto bad_tag;
...@@ -2785,7 +2773,7 @@ static int try_read(struct ceph_connection *con) ...@@ -2785,7 +2773,7 @@ static int try_read(struct ceph_connection *con)
if (con->in_tag == CEPH_MSGR_TAG_READY) if (con->in_tag == CEPH_MSGR_TAG_READY)
goto more; goto more;
process_message(con); process_message(con);
if (con->state == CON_STATE_OPEN) if (con->state == CEPH_CON_S_OPEN)
prepare_read_tag(con); prepare_read_tag(con);
goto more; goto more;
} }
...@@ -2864,15 +2852,15 @@ static bool con_sock_closed(struct ceph_connection *con) ...@@ -2864,15 +2852,15 @@ static bool con_sock_closed(struct ceph_connection *con)
return false; return false;
#define CASE(x) \ #define CASE(x) \
case CON_STATE_ ## x: \ case CEPH_CON_S_ ## x: \
con->error_msg = "socket closed (con state " #x ")"; \ con->error_msg = "socket closed (con state " #x ")"; \
break; break;
switch (con->state) { switch (con->state) {
CASE(CLOSED); CASE(CLOSED);
CASE(PREOPEN); CASE(PREOPEN);
CASE(CONNECTING); CASE(V1_BANNER);
CASE(NEGOTIATING); CASE(V1_CONNECT_MSG);
CASE(OPEN); CASE(OPEN);
CASE(STANDBY); CASE(STANDBY);
default: default:
...@@ -2943,16 +2931,16 @@ static void ceph_con_workfn(struct work_struct *work) ...@@ -2943,16 +2931,16 @@ static void ceph_con_workfn(struct work_struct *work)
dout("%s: con %p BACKOFF\n", __func__, con); dout("%s: con %p BACKOFF\n", __func__, con);
break; break;
} }
if (con->state == CON_STATE_STANDBY) { if (con->state == CEPH_CON_S_STANDBY) {
dout("%s: con %p STANDBY\n", __func__, con); dout("%s: con %p STANDBY\n", __func__, con);
break; break;
} }
if (con->state == CON_STATE_CLOSED) { if (con->state == CEPH_CON_S_CLOSED) {
dout("%s: con %p CLOSED\n", __func__, con); dout("%s: con %p CLOSED\n", __func__, con);
BUG_ON(con->sock); BUG_ON(con->sock);
break; break;
} }
if (con->state == CON_STATE_PREOPEN) { if (con->state == CEPH_CON_S_PREOPEN) {
dout("%s: con %p PREOPEN\n", __func__, con); dout("%s: con %p PREOPEN\n", __func__, con);
BUG_ON(con->sock); BUG_ON(con->sock);
} }
...@@ -3001,15 +2989,15 @@ static void con_fault(struct ceph_connection *con) ...@@ -3001,15 +2989,15 @@ static void con_fault(struct ceph_connection *con)
ceph_pr_addr(&con->peer_addr), con->error_msg); ceph_pr_addr(&con->peer_addr), con->error_msg);
con->error_msg = NULL; con->error_msg = NULL;
WARN_ON(con->state != CON_STATE_CONNECTING && WARN_ON(con->state != CEPH_CON_S_V1_BANNER &&
con->state != CON_STATE_NEGOTIATING && con->state != CEPH_CON_S_V1_CONNECT_MSG &&
con->state != CON_STATE_OPEN); con->state != CEPH_CON_S_OPEN);
ceph_con_reset_protocol(con); ceph_con_reset_protocol(con);
if (con_flag_test(con, CON_FLAG_LOSSYTX)) { if (con_flag_test(con, CON_FLAG_LOSSYTX)) {
dout("fault on LOSSYTX channel, marking CLOSED\n"); dout("fault on LOSSYTX channel, marking CLOSED\n");
con->state = CON_STATE_CLOSED; con->state = CEPH_CON_S_CLOSED;
return; return;
} }
...@@ -3022,10 +3010,10 @@ static void con_fault(struct ceph_connection *con) ...@@ -3022,10 +3010,10 @@ static void con_fault(struct ceph_connection *con)
!con_flag_test(con, CON_FLAG_KEEPALIVE_PENDING)) { !con_flag_test(con, CON_FLAG_KEEPALIVE_PENDING)) {
dout("fault %p setting STANDBY clearing WRITE_PENDING\n", con); dout("fault %p setting STANDBY clearing WRITE_PENDING\n", con);
con_flag_clear(con, CON_FLAG_WRITE_PENDING); con_flag_clear(con, CON_FLAG_WRITE_PENDING);
con->state = CON_STATE_STANDBY; con->state = CEPH_CON_S_STANDBY;
} else { } else {
/* retry after a delay. */ /* retry after a delay. */
con->state = CON_STATE_PREOPEN; con->state = CEPH_CON_S_PREOPEN;
if (!con->delay) { if (!con->delay) {
con->delay = BASE_DELAY_INTERVAL; con->delay = BASE_DELAY_INTERVAL;
} else if (con->delay < MAX_DELAY_INTERVAL) { } else if (con->delay < MAX_DELAY_INTERVAL) {
...@@ -3092,9 +3080,9 @@ static void msg_con_set(struct ceph_msg *msg, struct ceph_connection *con) ...@@ -3092,9 +3080,9 @@ static void msg_con_set(struct ceph_msg *msg, struct ceph_connection *con)
static void clear_standby(struct ceph_connection *con) static void clear_standby(struct ceph_connection *con)
{ {
/* come back from STANDBY? */ /* come back from STANDBY? */
if (con->state == CON_STATE_STANDBY) { if (con->state == CEPH_CON_S_STANDBY) {
dout("clear_standby %p and ++connect_seq\n", con); dout("clear_standby %p and ++connect_seq\n", con);
con->state = CON_STATE_PREOPEN; con->state = CEPH_CON_S_PREOPEN;
con->connect_seq++; con->connect_seq++;
WARN_ON(con_flag_test(con, CON_FLAG_WRITE_PENDING)); WARN_ON(con_flag_test(con, CON_FLAG_WRITE_PENDING));
WARN_ON(con_flag_test(con, CON_FLAG_KEEPALIVE_PENDING)); WARN_ON(con_flag_test(con, CON_FLAG_KEEPALIVE_PENDING));
...@@ -3115,7 +3103,7 @@ void ceph_con_send(struct ceph_connection *con, struct ceph_msg *msg) ...@@ -3115,7 +3103,7 @@ void ceph_con_send(struct ceph_connection *con, struct ceph_msg *msg)
mutex_lock(&con->mutex); mutex_lock(&con->mutex);
if (con->state == CON_STATE_CLOSED) { if (con->state == CEPH_CON_S_CLOSED) {
dout("con_send %p closed, dropping %p\n", con, msg); dout("con_send %p closed, dropping %p\n", con, msg);
ceph_msg_put(msg); ceph_msg_put(msg);
mutex_unlock(&con->mutex); mutex_unlock(&con->mutex);
...@@ -3456,7 +3444,7 @@ static int ceph_con_in_msg_alloc(struct ceph_connection *con, ...@@ -3456,7 +3444,7 @@ static int ceph_con_in_msg_alloc(struct ceph_connection *con,
mutex_unlock(&con->mutex); mutex_unlock(&con->mutex);
msg = con->ops->alloc_msg(con, hdr, skip); msg = con->ops->alloc_msg(con, hdr, skip);
mutex_lock(&con->mutex); mutex_lock(&con->mutex);
if (con->state != CON_STATE_OPEN) { if (con->state != CEPH_CON_S_OPEN) {
if (msg) if (msg)
ceph_msg_put(msg); ceph_msg_put(msg);
return -EAGAIN; return -EAGAIN;
......
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