aboutsummaryrefslogtreecommitdiffstats
path: root/net
diff options
context:
space:
mode:
authorSage Weil <sage@inktank.com>2012-07-20 20:29:55 -0400
committerSage Weil <sage@inktank.com>2012-07-30 21:16:01 -0400
commit4a8616920860920abaa51193146fe36b38ef09aa (patch)
tree306a64ebcfaaae76b1b45d8f8916e6f68a190255 /net
parent8dacc7da69a491c515851e68de6036f21b5663ce (diff)
libceph: clean up con flags
Rename flags with CON_FLAG prefix, move the definitions into the c file, and (better) document their meaning. Signed-off-by: Sage Weil <sage@inktank.com>
Diffstat (limited to 'net')
-rw-r--r--net/ceph/messenger.c62
1 files changed, 36 insertions, 26 deletions
diff --git a/net/ceph/messenger.c b/net/ceph/messenger.c
index 563e46aa4d6d..b872db5c4989 100644
--- a/net/ceph/messenger.c
+++ b/net/ceph/messenger.c
@@ -87,6 +87,15 @@
87#define CON_STATE_OPEN 5 /* -> STANDBY, CLOSED */ 87#define CON_STATE_OPEN 5 /* -> STANDBY, CLOSED */
88#define CON_STATE_STANDBY 6 /* -> PREOPEN, CLOSED */ 88#define CON_STATE_STANDBY 6 /* -> PREOPEN, CLOSED */
89 89
90/*
91 * ceph_connection flag bits
92 */
93#define CON_FLAG_LOSSYTX 0 /* we can close channel or drop
94 * messages on errors */
95#define CON_FLAG_KEEPALIVE_PENDING 1 /* we need to send a keepalive */
96#define CON_FLAG_WRITE_PENDING 2 /* we have data ready to send */
97#define CON_FLAG_SOCK_CLOSED 3 /* socket state changed to closed */
98#define CON_FLAG_BACKOFF 4 /* need to retry queuing delayed work */
90 99
91/* static tag bytes (protocol control messages) */ 100/* static tag bytes (protocol control messages) */
92static char tag_msg = CEPH_MSGR_TAG_MSG; 101static char tag_msg = CEPH_MSGR_TAG_MSG;
@@ -288,7 +297,7 @@ static void ceph_sock_write_space(struct sock *sk)
288 * buffer. See net/ipv4/tcp_input.c:tcp_check_space() 297 * buffer. See net/ipv4/tcp_input.c:tcp_check_space()
289 * and net/core/stream.c:sk_stream_write_space(). 298 * and net/core/stream.c:sk_stream_write_space().
290 */ 299 */
291 if (test_bit(WRITE_PENDING, &con->flags)) { 300 if (test_bit(CON_FLAG_WRITE_PENDING, &con->flags)) {
292 if (sk_stream_wspace(sk) >= sk_stream_min_wspace(sk)) { 301 if (sk_stream_wspace(sk) >= sk_stream_min_wspace(sk)) {
293 dout("%s %p queueing write work\n", __func__, con); 302 dout("%s %p queueing write work\n", __func__, con);
294 clear_bit(SOCK_NOSPACE, &sk->sk_socket->flags); 303 clear_bit(SOCK_NOSPACE, &sk->sk_socket->flags);
@@ -313,7 +322,7 @@ static void ceph_sock_state_change(struct sock *sk)
313 case TCP_CLOSE_WAIT: 322 case TCP_CLOSE_WAIT:
314 dout("%s TCP_CLOSE_WAIT\n", __func__); 323 dout("%s TCP_CLOSE_WAIT\n", __func__);
315 con_sock_state_closing(con); 324 con_sock_state_closing(con);
316 set_bit(SOCK_CLOSED, &con->flags); 325 set_bit(CON_FLAG_SOCK_CLOSED, &con->flags);
317 queue_con(con); 326 queue_con(con);
318 break; 327 break;
319 case TCP_ESTABLISHED: 328 case TCP_ESTABLISHED:
@@ -449,12 +458,12 @@ static int con_close_socket(struct ceph_connection *con)
449 con->sock = NULL; 458 con->sock = NULL;
450 459
451 /* 460 /*
452 * Forcibly clear the SOCK_CLOSE flag. It gets set 461 * Forcibly clear the SOCK_CLOSED flag. It gets set
453 * independent of the connection mutex, and we could have 462 * independent of the connection mutex, and we could have
454 * received a socket close event before we had the chance to 463 * received a socket close event before we had the chance to
455 * shut the socket down. 464 * shut the socket down.
456 */ 465 */
457 clear_bit(SOCK_CLOSED, &con->flags); 466 clear_bit(CON_FLAG_SOCK_CLOSED, &con->flags);
458 con_sock_state_closed(con); 467 con_sock_state_closed(con);
459 return rc; 468 return rc;
460} 469}
@@ -516,9 +525,9 @@ void ceph_con_close(struct ceph_connection *con)
516 ceph_pr_addr(&con->peer_addr.in_addr)); 525 ceph_pr_addr(&con->peer_addr.in_addr));
517 con->state = CON_STATE_CLOSED; 526 con->state = CON_STATE_CLOSED;
518 527
519 clear_bit(LOSSYTX, &con->flags); /* so we retry next connect */ 528 clear_bit(CON_FLAG_LOSSYTX, &con->flags); /* so we retry next connect */
520 clear_bit(KEEPALIVE_PENDING, &con->flags); 529 clear_bit(CON_FLAG_KEEPALIVE_PENDING, &con->flags);
521 clear_bit(WRITE_PENDING, &con->flags); 530 clear_bit(CON_FLAG_WRITE_PENDING, &con->flags);
522 531
523 reset_connection(con); 532 reset_connection(con);
524 con->peer_global_seq = 0; 533 con->peer_global_seq = 0;
@@ -770,7 +779,7 @@ static void prepare_write_message(struct ceph_connection *con)
770 /* no, queue up footer too and be done */ 779 /* no, queue up footer too and be done */
771 prepare_write_message_footer(con); 780 prepare_write_message_footer(con);
772 781
773 set_bit(WRITE_PENDING, &con->flags); 782 set_bit(CON_FLAG_WRITE_PENDING, &con->flags);
774} 783}
775 784
776/* 785/*
@@ -791,7 +800,7 @@ static void prepare_write_ack(struct ceph_connection *con)
791 &con->out_temp_ack); 800 &con->out_temp_ack);
792 801
793 con->out_more = 1; /* more will follow.. eventually.. */ 802 con->out_more = 1; /* more will follow.. eventually.. */
794 set_bit(WRITE_PENDING, &con->flags); 803 set_bit(CON_FLAG_WRITE_PENDING, &con->flags);
795} 804}
796 805
797/* 806/*
@@ -802,7 +811,7 @@ static void prepare_write_keepalive(struct ceph_connection *con)
802 dout("prepare_write_keepalive %p\n", con); 811 dout("prepare_write_keepalive %p\n", con);
803 con_out_kvec_reset(con); 812 con_out_kvec_reset(con);
804 con_out_kvec_add(con, sizeof (tag_keepalive), &tag_keepalive); 813 con_out_kvec_add(con, sizeof (tag_keepalive), &tag_keepalive);
805 set_bit(WRITE_PENDING, &con->flags); 814 set_bit(CON_FLAG_WRITE_PENDING, &con->flags);
806} 815}
807 816
808/* 817/*
@@ -845,7 +854,7 @@ static void prepare_write_banner(struct ceph_connection *con)
845 &con->msgr->my_enc_addr); 854 &con->msgr->my_enc_addr);
846 855
847 con->out_more = 0; 856 con->out_more = 0;
848 set_bit(WRITE_PENDING, &con->flags); 857 set_bit(CON_FLAG_WRITE_PENDING, &con->flags);
849} 858}
850 859
851static int prepare_write_connect(struct ceph_connection *con) 860static int prepare_write_connect(struct ceph_connection *con)
@@ -896,7 +905,7 @@ static int prepare_write_connect(struct ceph_connection *con)
896 auth->authorizer_buf); 905 auth->authorizer_buf);
897 906
898 con->out_more = 0; 907 con->out_more = 0;
899 set_bit(WRITE_PENDING, &con->flags); 908 set_bit(CON_FLAG_WRITE_PENDING, &con->flags);
900 909
901 return 0; 910 return 0;
902} 911}
@@ -1622,7 +1631,7 @@ static int process_connect(struct ceph_connection *con)
1622 le32_to_cpu(con->in_reply.connect_seq)); 1631 le32_to_cpu(con->in_reply.connect_seq));
1623 1632
1624 if (con->in_reply.flags & CEPH_MSG_CONNECT_LOSSY) 1633 if (con->in_reply.flags & CEPH_MSG_CONNECT_LOSSY)
1625 set_bit(LOSSYTX, &con->flags); 1634 set_bit(CON_FLAG_LOSSYTX, &con->flags);
1626 1635
1627 con->delay = 0; /* reset backoff memory */ 1636 con->delay = 0; /* reset backoff memory */
1628 1637
@@ -2061,14 +2070,15 @@ do_next:
2061 prepare_write_ack(con); 2070 prepare_write_ack(con);
2062 goto more; 2071 goto more;
2063 } 2072 }
2064 if (test_and_clear_bit(KEEPALIVE_PENDING, &con->flags)) { 2073 if (test_and_clear_bit(CON_FLAG_KEEPALIVE_PENDING,
2074 &con->flags)) {
2065 prepare_write_keepalive(con); 2075 prepare_write_keepalive(con);
2066 goto more; 2076 goto more;
2067 } 2077 }
2068 } 2078 }
2069 2079
2070 /* Nothing to do! */ 2080 /* Nothing to do! */
2071 clear_bit(WRITE_PENDING, &con->flags); 2081 clear_bit(CON_FLAG_WRITE_PENDING, &con->flags);
2072 dout("try_write nothing else to write.\n"); 2082 dout("try_write nothing else to write.\n");
2073 ret = 0; 2083 ret = 0;
2074out: 2084out:
@@ -2241,7 +2251,7 @@ static void con_work(struct work_struct *work)
2241 2251
2242 mutex_lock(&con->mutex); 2252 mutex_lock(&con->mutex);
2243restart: 2253restart:
2244 if (test_and_clear_bit(SOCK_CLOSED, &con->flags)) { 2254 if (test_and_clear_bit(CON_FLAG_SOCK_CLOSED, &con->flags)) {
2245 switch (con->state) { 2255 switch (con->state) {
2246 case CON_STATE_CONNECTING: 2256 case CON_STATE_CONNECTING:
2247 con->error_msg = "connection failed"; 2257 con->error_msg = "connection failed";
@@ -2260,7 +2270,7 @@ restart:
2260 goto fault; 2270 goto fault;
2261 } 2271 }
2262 2272
2263 if (test_and_clear_bit(BACKOFF, &con->flags)) { 2273 if (test_and_clear_bit(CON_FLAG_BACKOFF, &con->flags)) {
2264 dout("con_work %p backing off\n", con); 2274 dout("con_work %p backing off\n", con);
2265 if (queue_delayed_work(ceph_msgr_wq, &con->work, 2275 if (queue_delayed_work(ceph_msgr_wq, &con->work,
2266 round_jiffies_relative(con->delay))) { 2276 round_jiffies_relative(con->delay))) {
@@ -2336,7 +2346,7 @@ static void ceph_fault(struct ceph_connection *con)
2336 2346
2337 con_close_socket(con); 2347 con_close_socket(con);
2338 2348
2339 if (test_bit(LOSSYTX, &con->flags)) { 2349 if (test_bit(CON_FLAG_LOSSYTX, &con->flags)) {
2340 dout("fault on LOSSYTX channel, marking CLOSED\n"); 2350 dout("fault on LOSSYTX channel, marking CLOSED\n");
2341 con->state = CON_STATE_CLOSED; 2351 con->state = CON_STATE_CLOSED;
2342 goto out_unlock; 2352 goto out_unlock;
@@ -2356,9 +2366,9 @@ static void ceph_fault(struct ceph_connection *con)
2356 /* If there are no messages queued or keepalive pending, place 2366 /* If there are no messages queued or keepalive pending, place
2357 * the connection in a STANDBY state */ 2367 * the connection in a STANDBY state */
2358 if (list_empty(&con->out_queue) && 2368 if (list_empty(&con->out_queue) &&
2359 !test_bit(KEEPALIVE_PENDING, &con->flags)) { 2369 !test_bit(CON_FLAG_KEEPALIVE_PENDING, &con->flags)) {
2360 dout("fault %p setting STANDBY clearing WRITE_PENDING\n", con); 2370 dout("fault %p setting STANDBY clearing WRITE_PENDING\n", con);
2361 clear_bit(WRITE_PENDING, &con->flags); 2371 clear_bit(CON_FLAG_WRITE_PENDING, &con->flags);
2362 con->state = CON_STATE_STANDBY; 2372 con->state = CON_STATE_STANDBY;
2363 } else { 2373 } else {
2364 /* retry after a delay. */ 2374 /* retry after a delay. */
@@ -2383,7 +2393,7 @@ static void ceph_fault(struct ceph_connection *con)
2383 * that when con_work restarts we schedule the 2393 * that when con_work restarts we schedule the
2384 * delay then. 2394 * delay then.
2385 */ 2395 */
2386 set_bit(BACKOFF, &con->flags); 2396 set_bit(CON_FLAG_BACKOFF, &con->flags);
2387 } 2397 }
2388 } 2398 }
2389 2399
@@ -2440,8 +2450,8 @@ static void clear_standby(struct ceph_connection *con)
2440 dout("clear_standby %p and ++connect_seq\n", con); 2450 dout("clear_standby %p and ++connect_seq\n", con);
2441 con->state = CON_STATE_PREOPEN; 2451 con->state = CON_STATE_PREOPEN;
2442 con->connect_seq++; 2452 con->connect_seq++;
2443 WARN_ON(test_bit(WRITE_PENDING, &con->flags)); 2453 WARN_ON(test_bit(CON_FLAG_WRITE_PENDING, &con->flags));
2444 WARN_ON(test_bit(KEEPALIVE_PENDING, &con->flags)); 2454 WARN_ON(test_bit(CON_FLAG_KEEPALIVE_PENDING, &con->flags));
2445 } 2455 }
2446} 2456}
2447 2457
@@ -2482,7 +2492,7 @@ void ceph_con_send(struct ceph_connection *con, struct ceph_msg *msg)
2482 2492
2483 /* if there wasn't anything waiting to send before, queue 2493 /* if there wasn't anything waiting to send before, queue
2484 * new work */ 2494 * new work */
2485 if (test_and_set_bit(WRITE_PENDING, &con->flags) == 0) 2495 if (test_and_set_bit(CON_FLAG_WRITE_PENDING, &con->flags) == 0)
2486 queue_con(con); 2496 queue_con(con);
2487} 2497}
2488EXPORT_SYMBOL(ceph_con_send); 2498EXPORT_SYMBOL(ceph_con_send);
@@ -2571,8 +2581,8 @@ void ceph_con_keepalive(struct ceph_connection *con)
2571 mutex_lock(&con->mutex); 2581 mutex_lock(&con->mutex);
2572 clear_standby(con); 2582 clear_standby(con);
2573 mutex_unlock(&con->mutex); 2583 mutex_unlock(&con->mutex);
2574 if (test_and_set_bit(KEEPALIVE_PENDING, &con->flags) == 0 && 2584 if (test_and_set_bit(CON_FLAG_KEEPALIVE_PENDING, &con->flags) == 0 &&
2575 test_and_set_bit(WRITE_PENDING, &con->flags) == 0) 2585 test_and_set_bit(CON_FLAG_WRITE_PENDING, &con->flags) == 0)
2576 queue_con(con); 2586 queue_con(con);
2577} 2587}
2578EXPORT_SYMBOL(ceph_con_keepalive); 2588EXPORT_SYMBOL(ceph_con_keepalive);