aboutsummaryrefslogtreecommitdiffstats
path: root/net/ceph
diff options
context:
space:
mode:
authorAlex Elder <elder@dreamhost.com>2012-02-14 15:05:33 -0500
committerAlex Elder <elder@dreamhost.com>2012-03-22 11:47:51 -0400
commitd3002b974cefbb7c1e325cc296966f768ff76b06 (patch)
tree8685d72f6530959c4e19c4c9f3a12709ec1f4b08 /net/ceph
parent41617d0c9c9832e030667277ddf6b4ffb4ecdc90 (diff)
libceph: a few small changes
This gathers a number of very minor changes: - use %hu when formatting the a socket address's address family - null out the ceph_msgr_wq pointer after the queue has been destroyed - drop a needless cast in ceph_write_space() - add a WARN() call in ceph_state_change() in the event an unrecognized socket state is encountered - rearrange the logic in ceph_con_get() and ceph_con_put() so that: - the reference counts are only atomically read once - the values displayed via dout() calls are known to be meaningful at the time they are formatted Signed-off-by: Alex Elder <elder@dreamhost.com> Signed-off-by: Sage Weil <sage@newdream.net>
Diffstat (limited to 'net/ceph')
-rw-r--r--net/ceph/messenger.c32
1 files changed, 18 insertions, 14 deletions
diff --git a/net/ceph/messenger.c b/net/ceph/messenger.c
index e1e53bb2d0cf..44d8c77cabdd 100644
--- a/net/ceph/messenger.c
+++ b/net/ceph/messenger.c
@@ -80,8 +80,8 @@ const char *ceph_pr_addr(const struct sockaddr_storage *ss)
80 break; 80 break;
81 81
82 default: 82 default:
83 snprintf(s, MAX_ADDR_STR_LEN, "(unknown sockaddr family %d)", 83 snprintf(s, MAX_ADDR_STR_LEN, "(unknown sockaddr family %hu)",
84 (int)ss->ss_family); 84 ss->ss_family);
85 } 85 }
86 86
87 return s; 87 return s;
@@ -101,8 +101,10 @@ static struct workqueue_struct *ceph_msgr_wq;
101 101
102void _ceph_msgr_exit(void) 102void _ceph_msgr_exit(void)
103{ 103{
104 if (ceph_msgr_wq) 104 if (ceph_msgr_wq) {
105 destroy_workqueue(ceph_msgr_wq); 105 destroy_workqueue(ceph_msgr_wq);
106 ceph_msgr_wq = NULL;
107 }
106 108
107 BUG_ON(zero_page_address == NULL); 109 BUG_ON(zero_page_address == NULL);
108 zero_page_address = NULL; 110 zero_page_address = NULL;
@@ -167,8 +169,7 @@ static void ceph_data_ready(struct sock *sk, int count_unused)
167/* socket has buffer space for writing */ 169/* socket has buffer space for writing */
168static void ceph_write_space(struct sock *sk) 170static void ceph_write_space(struct sock *sk)
169{ 171{
170 struct ceph_connection *con = 172 struct ceph_connection *con = sk->sk_user_data;
171 (struct ceph_connection *)sk->sk_user_data;
172 173
173 /* only queue to workqueue if there is data we want to write, 174 /* only queue to workqueue if there is data we want to write,
174 * and there is sufficient space in the socket buffer to accept 175 * and there is sufficient space in the socket buffer to accept
@@ -216,6 +217,8 @@ static void ceph_state_change(struct sock *sk)
216 dout("ceph_state_change TCP_ESTABLISHED\n"); 217 dout("ceph_state_change TCP_ESTABLISHED\n");
217 queue_con(con); 218 queue_con(con);
218 break; 219 break;
220 default: /* Everything else is uninteresting */
221 break;
219 } 222 }
220} 223}
221 224
@@ -420,22 +423,23 @@ bool ceph_con_opened(struct ceph_connection *con)
420 */ 423 */
421struct ceph_connection *ceph_con_get(struct ceph_connection *con) 424struct ceph_connection *ceph_con_get(struct ceph_connection *con)
422{ 425{
423 dout("con_get %p nref = %d -> %d\n", con, 426 int nref = __atomic_add_unless(&con->nref, 1, 0);
424 atomic_read(&con->nref), atomic_read(&con->nref) + 1); 427
425 if (atomic_inc_not_zero(&con->nref)) 428 dout("con_get %p nref = %d -> %d\n", con, nref, nref + 1);
426 return con; 429
427 return NULL; 430 return nref ? con : NULL;
428} 431}
429 432
430void ceph_con_put(struct ceph_connection *con) 433void ceph_con_put(struct ceph_connection *con)
431{ 434{
432 dout("con_put %p nref = %d -> %d\n", con, 435 int nref = atomic_dec_return(&con->nref);
433 atomic_read(&con->nref), atomic_read(&con->nref) - 1); 436
434 BUG_ON(atomic_read(&con->nref) == 0); 437 BUG_ON(nref < 0);
435 if (atomic_dec_and_test(&con->nref)) { 438 if (nref == 0) {
436 BUG_ON(con->sock); 439 BUG_ON(con->sock);
437 kfree(con); 440 kfree(con);
438 } 441 }
442 dout("con_put %p nref = %d -> %d\n", con, nref + 1, nref);
439} 443}
440 444
441/* 445/*