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.
Unified · Split
| @@ -103,20 +103,25 @@ struct ceph_msg_pos { · 102 unmodified lines | ||
| 103 | 103 | #define MAX_DELAY_INTERVAL (5 * 60 * HZ) |
| 104 | 104 | |
| 105 | 105 | /* |
| 106 | − * ceph_connection state bit flags | |
| 106 | + * ceph_connection flag bits | |
| 107 | 107 | */ |
| 108 | + | |
| 108 | 109 | #define LOSSYTX 0 /* we can close channel or drop messages on errors */ |
| 109 | −#define CONNECTING 1 | |
| 110 | −#define NEGOTIATING 2 | |
| 111 | 110 | #define KEEPALIVE_PENDING 3 |
| 112 | 111 | #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 | |
| 113 | 120 | #define STANDBY 8 /* no outgoing messages, socket closed. we keep |
| 114 | 121 | * the ceph_connection around to maintain shared |
| 115 | 122 | * state with the peer. */ |
| 116 | 123 | #define CLOSED 10 /* we've closed the connection */ |
| 117 | −#define SOCK_CLOSED 11 /* socket state changed to closed */ | |
| 118 | 124 | #define OPENING 13 /* open connection w/ (possibly new) peer */ |
| 119 | −#define BACKOFF 15 | |
| 120 | 125 | |
| 121 | 126 | /* |
| 122 | 127 | * A single connection with another host. |
| @@ -133,7 +138,8 @@ struct ceph_connection { · 10 unmodified lines | ||
| 133 | 138 | |
| 134 | 139 | struct ceph_messenger *msgr; |
| 135 | 140 | struct socket *sock; |
| 136 | − unsigned long state; /* connection state (see flags above) */ | |
| 141 | + unsigned long flags; | |
| 142 | + unsigned long state; | |
| 137 | 143 | const char *error_msg; /* error message, if any */ |
| 138 | 144 | |
| 139 | 145 | struct ceph_entity_addr peer_addr; /* peer address */ |
| @@ -176,7 +176,7 @@ static void ceph_sock_write_space(struct sock *sk) · 175 unmodified lines | ||
| 176 | 176 | * buffer. See net/ipv4/tcp_input.c:tcp_check_space() |
| 177 | 177 | * and net/core/stream.c:sk_stream_write_space(). |
| 178 | 178 | */ |
| 179 | − if (test_bit(WRITE_PENDING, &con->state)) { | |
| 179 | + if (test_bit(WRITE_PENDING, &con->flags)) { | |
| 180 | 180 | if (sk_stream_wspace(sk) >= sk_stream_min_wspace(sk)) { |
| 181 | 181 | dout("%s %p queueing write work\n", __func__, con); |
| 182 | 182 | clear_bit(SOCK_NOSPACE, &sk->sk_socket->flags); |
| @@ -203,7 +203,7 @@ static void ceph_sock_state_change(struct sock *sk) · 20 unmodified lines | ||
| 203 | 203 | dout("%s TCP_CLOSE\n", __func__); |
| 204 | 204 | case TCP_CLOSE_WAIT: |
| 205 | 205 | 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) { | |
| 207 | 207 | if (test_bit(CONNECTING, &con->state)) |
| 208 | 208 | con->error_msg = "connection failed"; |
| 209 | 209 | else |
| @@ -395,9 +395,9 @@ void ceph_con_close(struct ceph_connection *con) · 185 unmodified lines | ||
| 395 | 395 | ceph_pr_addr(&con->peer_addr.in_addr)); |
| 396 | 396 | set_bit(CLOSED, &con->state); /* in case there's queued work */ |
| 397 | 397 | 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); | |
| 401 | 401 | mutex_lock(&con->mutex); |
| 402 | 402 | reset_connection(con); |
| 403 | 403 | con->peer_global_seq = 0; |
| @@ -614,7 +614,7 @@ static void prepare_write_message(struct ceph_connection *con) · 210 unmodified lines | ||
| 614 | 614 | prepare_write_message_footer(con); |
| 615 | 615 | } |
| 616 | 616 | |
| 617 | − set_bit(WRITE_PENDING, &con->state); | |
| 617 | + set_bit(WRITE_PENDING, &con->flags); | |
| 618 | 618 | } |
| 619 | 619 | |
| 620 | 620 | /* |
| @@ -635,7 +635,7 @@ static void prepare_write_ack(struct ceph_connection *con) · 14 unmodified lines | ||
| 635 | 635 | &con->out_temp_ack); |
| 636 | 636 | |
| 637 | 637 | con->out_more = 1; /* more will follow.. eventually.. */ |
| 638 | − set_bit(WRITE_PENDING, &con->state); | |
| 638 | + set_bit(WRITE_PENDING, &con->flags); | |
| 639 | 639 | } |
| 640 | 640 | |
| 641 | 641 | /* |
| @@ -646,7 +646,7 @@ static void prepare_write_keepalive(struct ceph_connection *con) · 4 unmodified lines | ||
| 646 | 646 | dout("prepare_write_keepalive %p\n", con); |
| 647 | 647 | con_out_kvec_reset(con); |
| 648 | 648 | con_out_kvec_add(con, sizeof (tag_keepalive), &tag_keepalive); |
| 649 | − set_bit(WRITE_PENDING, &con->state); | |
| 649 | + set_bit(WRITE_PENDING, &con->flags); | |
| 650 | 650 | } |
| 651 | 651 | |
| 652 | 652 | /* |
| @@ -675,7 +675,7 @@ static struct ceph_auth_handshake *get_connect_authorizer(struct ceph_connection · 22 unmodified lines | ||
| 675 | 675 | |
| 676 | 676 | if (IS_ERR(auth)) |
| 677 | 677 | 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)) | |
| 679 | 679 | return ERR_PTR(-EAGAIN); |
| 680 | 680 | |
| 681 | 681 | con->auth_reply_buf = auth->authorizer_reply_buf; |
| @@ -695,7 +695,7 @@ static void prepare_write_banner(struct ceph_connection *con) · 13 unmodified lines | ||
| 695 | 695 | &con->msgr->my_enc_addr); |
| 696 | 696 | |
| 697 | 697 | con->out_more = 0; |
| 698 | − set_bit(WRITE_PENDING, &con->state); | |
| 698 | + set_bit(WRITE_PENDING, &con->flags); | |
| 699 | 699 | } |
| 700 | 700 | |
| 701 | 701 | static int prepare_write_connect(struct ceph_connection *con) |
| @@ -745,7 +745,7 @@ static int prepare_write_connect(struct ceph_connection *con) · 43 unmodified lines | ||
| 745 | 745 | auth->authorizer_buf); |
| 746 | 746 | |
| 747 | 747 | con->out_more = 0; |
| 748 | − set_bit(WRITE_PENDING, &con->state); | |
| 748 | + set_bit(WRITE_PENDING, &con->flags); | |
| 749 | 749 | |
| 750 | 750 | return 0; |
| 751 | 751 | } |
| @@ -1492,7 +1492,7 @@ static int process_connect(struct ceph_connection *con) · 740 unmodified lines | ||
| 1492 | 1492 | le32_to_cpu(con->in_reply.connect_seq)); |
| 1493 | 1493 | |
| 1494 | 1494 | if (con->in_reply.flags & CEPH_MSG_CONNECT_LOSSY) |
| 1495 | − set_bit(LOSSYTX, &con->state); | |
| 1495 | + set_bit(LOSSYTX, &con->flags); | |
| 1496 | 1496 | |
| 1497 | 1497 | prepare_read_tag(con); |
| 1498 | 1498 | break; |
| @@ -1933,14 +1933,14 @@ do_next: · 434 unmodified lines | ||
| 1933 | 1933 | prepare_write_ack(con); |
| 1934 | 1934 | goto more; |
| 1935 | 1935 | } |
| 1936 | − if (test_and_clear_bit(KEEPALIVE_PENDING, &con->state)) { | |
| 1936 | + if (test_and_clear_bit(KEEPALIVE_PENDING, &con->flags)) { | |
| 1937 | 1937 | prepare_write_keepalive(con); |
| 1938 | 1938 | goto more; |
| 1939 | 1939 | } |
| 1940 | 1940 | } |
| 1941 | 1941 | |
| 1942 | 1942 | /* Nothing to do! */ |
| 1943 | − clear_bit(WRITE_PENDING, &con->state); | |
| 1943 | + clear_bit(WRITE_PENDING, &con->flags); | |
| 1944 | 1944 | dout("try_write nothing else to write.\n"); |
| 1945 | 1945 | ret = 0; |
| 1946 | 1946 | out: |
| @@ -2106,7 +2106,7 @@ static void con_work(struct work_struct *work) · 159 unmodified lines | ||
| 2106 | 2106 | |
| 2107 | 2107 | mutex_lock(&con->mutex); |
| 2108 | 2108 | restart: |
| 2109 | − if (test_and_clear_bit(BACKOFF, &con->state)) { | |
| 2109 | + if (test_and_clear_bit(BACKOFF, &con->flags)) { | |
| 2110 | 2110 | dout("con_work %p backing off\n", con); |
| 2111 | 2111 | if (queue_delayed_work(ceph_msgr_wq, &con->work, |
| 2112 | 2112 | round_jiffies_relative(con->delay))) { |
| @@ -2135,7 +2135,7 @@ restart: · 22 unmodified lines | ||
| 2135 | 2135 | con_close_socket(con); |
| 2136 | 2136 | } |
| 2137 | 2137 | |
| 2138 | − if (test_and_clear_bit(SOCK_CLOSED, &con->state)) | |
| 2138 | + if (test_and_clear_bit(SOCK_CLOSED, &con->flags)) | |
| 2139 | 2139 | goto fault; |
| 2140 | 2140 | |
| 2141 | 2141 | ret = try_read(con); |
| @@ -2174,7 +2174,7 @@ static void ceph_fault(struct ceph_connection *con) · 32 unmodified lines | ||
| 2174 | 2174 | dout("fault %p state %lu to peer %s\n", |
| 2175 | 2175 | con, con->state, ceph_pr_addr(&con->peer_addr.in_addr)); |
| 2176 | 2176 | |
| 2177 | − if (test_bit(LOSSYTX, &con->state)) { | |
| 2177 | + if (test_bit(LOSSYTX, &con->flags)) { | |
| 2178 | 2178 | dout("fault on LOSSYTX channel\n"); |
| 2179 | 2179 | goto out; |
| 2180 | 2180 | } |
| @@ -2196,9 +2196,9 @@ static void ceph_fault(struct ceph_connection *con) · 15 unmodified lines | ||
| 2196 | 2196 | /* If there are no messages queued or keepalive pending, place |
| 2197 | 2197 | * the connection in a STANDBY state */ |
| 2198 | 2198 | if (list_empty(&con->out_queue) && |
| 2199 | − !test_bit(KEEPALIVE_PENDING, &con->state)) { | |
| 2199 | + !test_bit(KEEPALIVE_PENDING, &con->flags)) { | |
| 2200 | 2200 | dout("fault %p setting STANDBY clearing WRITE_PENDING\n", con); |
| 2201 | − clear_bit(WRITE_PENDING, &con->state); | |
| 2201 | + clear_bit(WRITE_PENDING, &con->flags); | |
| 2202 | 2202 | set_bit(STANDBY, &con->state); |
| 2203 | 2203 | } else { |
| 2204 | 2204 | /* retry after a delay. */ |
| @@ -2222,7 +2222,7 @@ static void ceph_fault(struct ceph_connection *con) · 17 unmodified lines | ||
| 2222 | 2222 | * that when con_work restarts we schedule the |
| 2223 | 2223 | * delay then. |
| 2224 | 2224 | */ |
| 2225 | − set_bit(BACKOFF, &con->state); | |
| 2225 | + set_bit(BACKOFF, &con->flags); | |
| 2226 | 2226 | } |
| 2227 | 2227 | } |
| 2228 | 2228 | |
| @@ -2278,8 +2278,8 @@ static void clear_standby(struct ceph_connection *con) · 49 unmodified lines | ||
| 2278 | 2278 | mutex_lock(&con->mutex); |
| 2279 | 2279 | dout("clear_standby %p and ++connect_seq\n", con); |
| 2280 | 2280 | 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)); | |
| 2283 | 2283 | mutex_unlock(&con->mutex); |
| 2284 | 2284 | } |
| 2285 | 2285 | } |
| @@ -2317,7 +2317,7 @@ void ceph_con_send(struct ceph_connection *con, struct ceph_msg *msg) · 31 unmodified lines | ||
| 2317 | 2317 | /* if there wasn't anything waiting to send before, queue |
| 2318 | 2318 | * new work */ |
| 2319 | 2319 | 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) | |
| 2321 | 2321 | queue_con(con); |
| 2322 | 2322 | } |
| 2323 | 2323 | EXPORT_SYMBOL(ceph_con_send); |
| @@ -2384,8 +2384,8 @@ void ceph_con_keepalive(struct ceph_connection *con) · 60 unmodified lines | ||
| 2384 | 2384 | { |
| 2385 | 2385 | dout("con_keepalive %p\n", con); |
| 2386 | 2386 | 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) | |
| 2389 | 2389 | queue_con(con); |
| 2390 | 2390 | } |
| 2391 | 2391 | EXPORT_SYMBOL(ceph_con_keepalive); |