Skip to content

Commit f6a2f5b

Browse files
committed
libceph: always preallocate mon connection
Allocate the mon connection on init. We already reuse it across reconnects. Remove now unnecessary (and incomplete) NULL checks. Signed-off-by: Sage Weil <sage@newdream.net>
1 parent 6ab00d4 commit f6a2f5b

1 file changed

Lines changed: 22 additions & 25 deletions

File tree

‎net/ceph/mon_client.c‎

Lines changed: 22 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -116,14 +116,12 @@ static void __send_prepared_auth_request(struct ceph_mon_client *monc, int len)
116116
*/
117117
static void __close_session(struct ceph_mon_client *monc)
118118
{
119-
if (monc->con) {
120-
dout("__close_session closing mon%d\n", monc->cur_mon);
121-
ceph_con_revoke(monc->con, monc->m_auth);
122-
ceph_con_close(monc->con);
123-
monc->cur_mon = -1;
124-
monc->pending_auth = 0;
125-
ceph_auth_reset(monc->auth);
126-
}
119+
dout("__close_session closing mon%d\n", monc->cur_mon);
120+
ceph_con_revoke(monc->con, monc->m_auth);
121+
ceph_con_close(monc->con);
122+
monc->cur_mon = -1;
123+
monc->pending_auth = 0;
124+
ceph_auth_reset(monc->auth);
127125
}
128126

129127
/*
@@ -302,15 +300,6 @@ void ceph_monc_request_next_osdmap(struct ceph_mon_client *monc)
302300
*/
303301
int ceph_monc_open_session(struct ceph_mon_client *monc)
304302
{
305-
if (!monc->con) {
306-
monc->con = kmalloc(sizeof(*monc->con), GFP_KERNEL);
307-
if (!monc->con)
308-
return -ENOMEM;
309-
ceph_con_init(monc->client->msgr, monc->con);
310-
monc->con->private = monc;
311-
monc->con->ops = &mon_con_ops;
312-
}
313-
314303
mutex_lock(&monc->mutex);
315304
__open_session(monc);
316305
__schedule_delayed(monc);
@@ -755,7 +744,13 @@ int ceph_monc_init(struct ceph_mon_client *monc, struct ceph_client *cl)
755744
if (err)
756745
goto out;
757746

758-
monc->con = NULL;
747+
/* connection */
748+
monc->con = kmalloc(sizeof(*monc->con), GFP_KERNEL);
749+
if (!monc->con)
750+
goto out_monmap;
751+
ceph_con_init(monc->client->msgr, monc->con);
752+
monc->con->private = monc;
753+
monc->con->ops = &mon_con_ops;
759754

760755
/* authentication */
761756
monc->auth = ceph_auth_init(cl->options->name,
@@ -772,7 +767,7 @@ int ceph_monc_init(struct ceph_mon_client *monc, struct ceph_client *cl)
772767
sizeof(struct ceph_mon_subscribe_ack),
773768
GFP_NOFS);
774769
if (!monc->m_subscribe_ack)
775-
goto out_monmap;
770+
goto out_con;
776771

777772
monc->m_subscribe = ceph_msg_new(CEPH_MSG_MON_SUBSCRIBE, 96, GFP_NOFS);
778773
if (!monc->m_subscribe)
@@ -808,6 +803,8 @@ int ceph_monc_init(struct ceph_mon_client *monc, struct ceph_client *cl)
808803
ceph_msg_put(monc->m_subscribe);
809804
out_subscribe_ack:
810805
ceph_msg_put(monc->m_subscribe_ack);
806+
out_con:
807+
monc->con->ops->put(monc->con);
811808
out_monmap:
812809
kfree(monc->monmap);
813810
out:
@@ -822,11 +819,11 @@ void ceph_monc_stop(struct ceph_mon_client *monc)
822819

823820
mutex_lock(&monc->mutex);
824821
__close_session(monc);
825-
if (monc->con) {
826-
monc->con->private = NULL;
827-
monc->con->ops->put(monc->con);
828-
monc->con = NULL;
829-
}
822+
823+
monc->con->private = NULL;
824+
monc->con->ops->put(monc->con);
825+
monc->con = NULL;
826+
830827
mutex_unlock(&monc->mutex);
831828

832829
ceph_auth_destroy(monc->auth);
@@ -1000,7 +997,7 @@ static void mon_fault(struct ceph_connection *con)
1000997
if (!con->private)
1001998
goto out;
1002999

1003-
if (monc->con && !monc->hunting)
1000+
if (!monc->hunting)
10041001
pr_info("mon%d %s session lost, "
10051002
"hunting for new mon\n", monc->cur_mon,
10061003
ceph_pr_addr(&monc->con->peer_addr.in_addr));

0 commit comments

Comments
 (0)