Skip to content

Commit 928443c

Browse files
Alex ElderAlex Elder
authored andcommitted
libceph: start separating connection flags from state
A ceph_connection holds a mixture of connection state (as in "state machine" state) and connection flags in a single "state" field. To make the distinction more clear, define a new "flags" field and use it rather than the "state" field to hold Boolean flag values. Signed-off-by: Alex Elder <elder@inktank.com> Reviewed-by: Sage Weil<sage@inktank.com>
1 parent 15d9882 commit 928443c

2 files changed

Lines changed: 37 additions & 31 deletions

File tree

‎include/linux/ceph/messenger.h‎

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -103,20 +103,25 @@ struct ceph_msg_pos {
103103
#define MAX_DELAY_INTERVAL (5 * 60 * HZ)
104104

105105
/*
106-
* ceph_connection state bit flags
106+
* ceph_connection flag bits
107107
*/
108+
108109
#define LOSSYTX 0 /* we can close channel or drop messages on errors */
109-
#define CONNECTING 1
110-
#define NEGOTIATING 2
111110
#define KEEPALIVE_PENDING 3
112111
#define WRITE_PENDING 4 /* we have data ready to send */
112+
#define SOCK_CLOSED 11 /* socket state changed to closed */
113+
#define BACKOFF 15
114+
115+
/*
116+
* ceph_connection states
117+
*/
118+
#define CONNECTING 1
119+
#define NEGOTIATING 2
113120
#define STANDBY 8 /* no outgoing messages, socket closed. we keep
114121
* the ceph_connection around to maintain shared
115122
* state with the peer. */
116123
#define CLOSED 10 /* we've closed the connection */
117-
#define SOCK_CLOSED 11 /* socket state changed to closed */
118124
#define OPENING 13 /* open connection w/ (possibly new) peer */
119-
#define BACKOFF 15
120125

121126
/*
122127
* A single connection with another host.
@@ -133,7 +138,8 @@ struct ceph_connection {
133138

134139
struct ceph_messenger *msgr;
135140
struct socket *sock;
136-
unsigned long state; /* connection state (see flags above) */
141+
unsigned long flags;
142+
unsigned long state;
137143
const char *error_msg; /* error message, if any */
138144

139145
struct ceph_entity_addr peer_addr; /* peer address */

‎net/ceph/messenger.c‎

Lines changed: 25 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -176,7 +176,7 @@ static void ceph_sock_write_space(struct sock *sk)
176176
* buffer. See net/ipv4/tcp_input.c:tcp_check_space()
177177
* and net/core/stream.c:sk_stream_write_space().
178178
*/
179-
if (test_bit(WRITE_PENDING, &con->state)) {
179+
if (test_bit(WRITE_PENDING, &con->flags)) {
180180
if (sk_stream_wspace(sk) >= sk_stream_min_wspace(sk)) {
181181
dout("%s %p queueing write work\n", __func__, con);
182182
clear_bit(SOCK_NOSPACE, &sk->sk_socket->flags);
@@ -203,7 +203,7 @@ static void ceph_sock_state_change(struct sock *sk)
203203
dout("%s TCP_CLOSE\n", __func__);
204204
case TCP_CLOSE_WAIT:
205205
dout("%s TCP_CLOSE_WAIT\n", __func__);
206-
if (test_and_set_bit(SOCK_CLOSED, &con->state) == 0) {
206+
if (test_and_set_bit(SOCK_CLOSED, &con->flags) == 0) {
207207
if (test_bit(CONNECTING, &con->state))
208208
con->error_msg = "connection failed";
209209
else
@@ -395,9 +395,9 @@ void ceph_con_close(struct ceph_connection *con)
395395
ceph_pr_addr(&con->peer_addr.in_addr));
396396
set_bit(CLOSED, &con->state); /* in case there's queued work */
397397
clear_bit(STANDBY, &con->state); /* avoid connect_seq bump */
398-
clear_bit(LOSSYTX, &con->state); /* so we retry next connect */
399-
clear_bit(KEEPALIVE_PENDING, &con->state);
400-
clear_bit(WRITE_PENDING, &con->state);
398+
clear_bit(LOSSYTX, &con->flags); /* so we retry next connect */
399+
clear_bit(KEEPALIVE_PENDING, &con->flags);
400+
clear_bit(WRITE_PENDING, &con->flags);
401401
mutex_lock(&con->mutex);
402402
reset_connection(con);
403403
con->peer_global_seq = 0;
@@ -614,7 +614,7 @@ static void prepare_write_message(struct ceph_connection *con)
614614
prepare_write_message_footer(con);
615615
}
616616

617-
set_bit(WRITE_PENDING, &con->state);
617+
set_bit(WRITE_PENDING, &con->flags);
618618
}
619619

620620
/*
@@ -635,7 +635,7 @@ static void prepare_write_ack(struct ceph_connection *con)
635635
&con->out_temp_ack);
636636

637637
con->out_more = 1; /* more will follow.. eventually.. */
638-
set_bit(WRITE_PENDING, &con->state);
638+
set_bit(WRITE_PENDING, &con->flags);
639639
}
640640

641641
/*
@@ -646,7 +646,7 @@ static void prepare_write_keepalive(struct ceph_connection *con)
646646
dout("prepare_write_keepalive %p\n", con);
647647
con_out_kvec_reset(con);
648648
con_out_kvec_add(con, sizeof (tag_keepalive), &tag_keepalive);
649-
set_bit(WRITE_PENDING, &con->state);
649+
set_bit(WRITE_PENDING, &con->flags);
650650
}
651651

652652
/*
@@ -675,7 +675,7 @@ static struct ceph_auth_handshake *get_connect_authorizer(struct ceph_connection
675675

676676
if (IS_ERR(auth))
677677
return auth;
678-
if (test_bit(CLOSED, &con->state) || test_bit(OPENING, &con->state))
678+
if (test_bit(CLOSED, &con->state) || test_bit(OPENING, &con->flags))
679679
return ERR_PTR(-EAGAIN);
680680

681681
con->auth_reply_buf = auth->authorizer_reply_buf;
@@ -695,7 +695,7 @@ static void prepare_write_banner(struct ceph_connection *con)
695695
&con->msgr->my_enc_addr);
696696

697697
con->out_more = 0;
698-
set_bit(WRITE_PENDING, &con->state);
698+
set_bit(WRITE_PENDING, &con->flags);
699699
}
700700

701701
static int prepare_write_connect(struct ceph_connection *con)
@@ -745,7 +745,7 @@ static int prepare_write_connect(struct ceph_connection *con)
745745
auth->authorizer_buf);
746746

747747
con->out_more = 0;
748-
set_bit(WRITE_PENDING, &con->state);
748+
set_bit(WRITE_PENDING, &con->flags);
749749

750750
return 0;
751751
}
@@ -1492,7 +1492,7 @@ static int process_connect(struct ceph_connection *con)
14921492
le32_to_cpu(con->in_reply.connect_seq));
14931493

14941494
if (con->in_reply.flags & CEPH_MSG_CONNECT_LOSSY)
1495-
set_bit(LOSSYTX, &con->state);
1495+
set_bit(LOSSYTX, &con->flags);
14961496

14971497
prepare_read_tag(con);
14981498
break;
@@ -1933,14 +1933,14 @@ static int try_write(struct ceph_connection *con)
19331933
prepare_write_ack(con);
19341934
goto more;
19351935
}
1936-
if (test_and_clear_bit(KEEPALIVE_PENDING, &con->state)) {
1936+
if (test_and_clear_bit(KEEPALIVE_PENDING, &con->flags)) {
19371937
prepare_write_keepalive(con);
19381938
goto more;
19391939
}
19401940
}
19411941

19421942
/* Nothing to do! */
1943-
clear_bit(WRITE_PENDING, &con->state);
1943+
clear_bit(WRITE_PENDING, &con->flags);
19441944
dout("try_write nothing else to write.\n");
19451945
ret = 0;
19461946
out:
@@ -2106,7 +2106,7 @@ static void con_work(struct work_struct *work)
21062106

21072107
mutex_lock(&con->mutex);
21082108
restart:
2109-
if (test_and_clear_bit(BACKOFF, &con->state)) {
2109+
if (test_and_clear_bit(BACKOFF, &con->flags)) {
21102110
dout("con_work %p backing off\n", con);
21112111
if (queue_delayed_work(ceph_msgr_wq, &con->work,
21122112
round_jiffies_relative(con->delay))) {
@@ -2135,7 +2135,7 @@ static void con_work(struct work_struct *work)
21352135
con_close_socket(con);
21362136
}
21372137

2138-
if (test_and_clear_bit(SOCK_CLOSED, &con->state))
2138+
if (test_and_clear_bit(SOCK_CLOSED, &con->flags))
21392139
goto fault;
21402140

21412141
ret = try_read(con);
@@ -2174,7 +2174,7 @@ static void ceph_fault(struct ceph_connection *con)
21742174
dout("fault %p state %lu to peer %s\n",
21752175
con, con->state, ceph_pr_addr(&con->peer_addr.in_addr));
21762176

2177-
if (test_bit(LOSSYTX, &con->state)) {
2177+
if (test_bit(LOSSYTX, &con->flags)) {
21782178
dout("fault on LOSSYTX channel\n");
21792179
goto out;
21802180
}
@@ -2196,9 +2196,9 @@ static void ceph_fault(struct ceph_connection *con)
21962196
/* If there are no messages queued or keepalive pending, place
21972197
* the connection in a STANDBY state */
21982198
if (list_empty(&con->out_queue) &&
2199-
!test_bit(KEEPALIVE_PENDING, &con->state)) {
2199+
!test_bit(KEEPALIVE_PENDING, &con->flags)) {
22002200
dout("fault %p setting STANDBY clearing WRITE_PENDING\n", con);
2201-
clear_bit(WRITE_PENDING, &con->state);
2201+
clear_bit(WRITE_PENDING, &con->flags);
22022202
set_bit(STANDBY, &con->state);
22032203
} else {
22042204
/* retry after a delay. */
@@ -2222,7 +2222,7 @@ static void ceph_fault(struct ceph_connection *con)
22222222
* that when con_work restarts we schedule the
22232223
* delay then.
22242224
*/
2225-
set_bit(BACKOFF, &con->state);
2225+
set_bit(BACKOFF, &con->flags);
22262226
}
22272227
}
22282228

@@ -2278,8 +2278,8 @@ static void clear_standby(struct ceph_connection *con)
22782278
mutex_lock(&con->mutex);
22792279
dout("clear_standby %p and ++connect_seq\n", con);
22802280
con->connect_seq++;
2281-
WARN_ON(test_bit(WRITE_PENDING, &con->state));
2282-
WARN_ON(test_bit(KEEPALIVE_PENDING, &con->state));
2281+
WARN_ON(test_bit(WRITE_PENDING, &con->flags));
2282+
WARN_ON(test_bit(KEEPALIVE_PENDING, &con->flags));
22832283
mutex_unlock(&con->mutex);
22842284
}
22852285
}
@@ -2317,7 +2317,7 @@ void ceph_con_send(struct ceph_connection *con, struct ceph_msg *msg)
23172317
/* if there wasn't anything waiting to send before, queue
23182318
* new work */
23192319
clear_standby(con);
2320-
if (test_and_set_bit(WRITE_PENDING, &con->state) == 0)
2320+
if (test_and_set_bit(WRITE_PENDING, &con->flags) == 0)
23212321
queue_con(con);
23222322
}
23232323
EXPORT_SYMBOL(ceph_con_send);
@@ -2384,8 +2384,8 @@ void ceph_con_keepalive(struct ceph_connection *con)
23842384
{
23852385
dout("con_keepalive %p\n", con);
23862386
clear_standby(con);
2387-
if (test_and_set_bit(KEEPALIVE_PENDING, &con->state) == 0 &&
2388-
test_and_set_bit(WRITE_PENDING, &con->state) == 0)
2387+
if (test_and_set_bit(KEEPALIVE_PENDING, &con->flags) == 0 &&
2388+
test_and_set_bit(WRITE_PENDING, &con->flags) == 0)
23892389
queue_con(con);
23902390
}
23912391
EXPORT_SYMBOL(ceph_con_keepalive);

0 commit comments

Comments
 (0)