Skip to content

Commit d3002b9

Browse files
author
Alex Elder
committed
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>
1 parent 41617d0 commit d3002b9

1 file changed

Lines changed: 18 additions & 14 deletions

File tree

‎net/ceph/messenger.c‎

Lines changed: 18 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -80,8 +80,8 @@ const char *ceph_pr_addr(const struct sockaddr_storage *ss)
8080
break;
8181

8282
default:
83-
snprintf(s, MAX_ADDR_STR_LEN, "(unknown sockaddr family %d)",
84-
(int)ss->ss_family);
83+
snprintf(s, MAX_ADDR_STR_LEN, "(unknown sockaddr family %hu)",
84+
ss->ss_family);
8585
}
8686

8787
return s;
@@ -101,8 +101,10 @@ static struct workqueue_struct *ceph_msgr_wq;
101101

102102
void _ceph_msgr_exit(void)
103103
{
104-
if (ceph_msgr_wq)
104+
if (ceph_msgr_wq) {
105105
destroy_workqueue(ceph_msgr_wq);
106+
ceph_msgr_wq = NULL;
107+
}
106108

107109
BUG_ON(zero_page_address == NULL);
108110
zero_page_address = NULL;
@@ -167,8 +169,7 @@ static void ceph_data_ready(struct sock *sk, int count_unused)
167169
/* socket has buffer space for writing */
168170
static void ceph_write_space(struct sock *sk)
169171
{
170-
struct ceph_connection *con =
171-
(struct ceph_connection *)sk->sk_user_data;
172+
struct ceph_connection *con = sk->sk_user_data;
172173

173174
/* only queue to workqueue if there is data we want to write,
174175
* and there is sufficient space in the socket buffer to accept
@@ -216,6 +217,8 @@ static void ceph_state_change(struct sock *sk)
216217
dout("ceph_state_change TCP_ESTABLISHED\n");
217218
queue_con(con);
218219
break;
220+
default: /* Everything else is uninteresting */
221+
break;
219222
}
220223
}
221224

@@ -420,22 +423,23 @@ bool ceph_con_opened(struct ceph_connection *con)
420423
*/
421424
struct ceph_connection *ceph_con_get(struct ceph_connection *con)
422425
{
423-
dout("con_get %p nref = %d -> %d\n", con,
424-
atomic_read(&con->nref), atomic_read(&con->nref) + 1);
425-
if (atomic_inc_not_zero(&con->nref))
426-
return con;
427-
return NULL;
426+
int nref = __atomic_add_unless(&con->nref, 1, 0);
427+
428+
dout("con_get %p nref = %d -> %d\n", con, nref, nref + 1);
429+
430+
return nref ? con : NULL;
428431
}
429432

430433
void ceph_con_put(struct ceph_connection *con)
431434
{
432-
dout("con_put %p nref = %d -> %d\n", con,
433-
atomic_read(&con->nref), atomic_read(&con->nref) - 1);
434-
BUG_ON(atomic_read(&con->nref) == 0);
435-
if (atomic_dec_and_test(&con->nref)) {
435+
int nref = atomic_dec_return(&con->nref);
436+
437+
BUG_ON(nref < 0);
438+
if (nref == 0) {
436439
BUG_ON(con->sock);
437440
kfree(con);
438441
}
442+
dout("con_put %p nref = %d -> %d\n", con, nref + 1, nref);
439443
}
440444

441445
/*

0 commit comments

Comments
 (0)