aboutsummaryrefslogtreecommitdiffstats
path: root/net/ceph/mon_client.c
diff options
context:
space:
mode:
authorSage Weil <sage@newdream.net>2011-08-09 12:27:44 -0400
committerSage Weil <sage@newdream.net>2011-10-25 19:10:15 -0400
commitf6a2f5be07463ef532b9f4e3cb9e42ab9df85832 (patch)
tree2e0bc35d64631705fffded5f93f9345ff0f0587f /net/ceph/mon_client.c
parent6ab00d465a1c8c02c2216f8220727282f3aa50b5 (diff)
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>
Diffstat (limited to 'net/ceph/mon_client.c')
-rw-r--r--net/ceph/mon_client.c47
1 files changed, 22 insertions, 25 deletions
diff --git a/net/ceph/mon_client.c b/net/ceph/mon_client.c
index cbe31fa45508..556721665335 100644
--- a/net/ceph/mon_client.c
+++ b/net/ceph/mon_client.c
@@ -116,14 +116,12 @@ static void __send_prepared_auth_request(struct ceph_mon_client *monc, int len)
116 */ 116 */
117static void __close_session(struct ceph_mon_client *monc) 117static void __close_session(struct ceph_mon_client *monc)
118{ 118{
119 if (monc->con) { 119 dout("__close_session closing mon%d\n", monc->cur_mon);
120 dout("__close_session closing mon%d\n", monc->cur_mon); 120 ceph_con_revoke(monc->con, monc->m_auth);
121 ceph_con_revoke(monc->con, monc->m_auth); 121 ceph_con_close(monc->con);
122 ceph_con_close(monc->con); 122 monc->cur_mon = -1;
123 monc->cur_mon = -1; 123 monc->pending_auth = 0;
124 monc->pending_auth = 0; 124 ceph_auth_reset(monc->auth);
125 ceph_auth_reset(monc->auth);
126 }
127} 125}
128 126
129/* 127/*
@@ -302,15 +300,6 @@ void ceph_monc_request_next_osdmap(struct ceph_mon_client *monc)
302 */ 300 */
303int ceph_monc_open_session(struct ceph_mon_client *monc) 301int ceph_monc_open_session(struct ceph_mon_client *monc)
304{ 302{
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
314 mutex_lock(&monc->mutex); 303 mutex_lock(&monc->mutex);
315 __open_session(monc); 304 __open_session(monc);
316 __schedule_delayed(monc); 305 __schedule_delayed(monc);
@@ -755,7 +744,13 @@ int ceph_monc_init(struct ceph_mon_client *monc, struct ceph_client *cl)
755 if (err) 744 if (err)
756 goto out; 745 goto out;
757 746
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;
759 754
760 /* authentication */ 755 /* authentication */
761 monc->auth = ceph_auth_init(cl->options->name, 756 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)
772 sizeof(struct ceph_mon_subscribe_ack), 767 sizeof(struct ceph_mon_subscribe_ack),
773 GFP_NOFS); 768 GFP_NOFS);
774 if (!monc->m_subscribe_ack) 769 if (!monc->m_subscribe_ack)
775 goto out_monmap; 770 goto out_con;
776 771
777 monc->m_subscribe = ceph_msg_new(CEPH_MSG_MON_SUBSCRIBE, 96, GFP_NOFS); 772 monc->m_subscribe = ceph_msg_new(CEPH_MSG_MON_SUBSCRIBE, 96, GFP_NOFS);
778 if (!monc->m_subscribe) 773 if (!monc->m_subscribe)
@@ -808,6 +803,8 @@ out_subscribe:
808 ceph_msg_put(monc->m_subscribe); 803 ceph_msg_put(monc->m_subscribe);
809out_subscribe_ack: 804out_subscribe_ack:
810 ceph_msg_put(monc->m_subscribe_ack); 805 ceph_msg_put(monc->m_subscribe_ack);
806out_con:
807 monc->con->ops->put(monc->con);
811out_monmap: 808out_monmap:
812 kfree(monc->monmap); 809 kfree(monc->monmap);
813out: 810out:
@@ -822,11 +819,11 @@ void ceph_monc_stop(struct ceph_mon_client *monc)
822 819
823 mutex_lock(&monc->mutex); 820 mutex_lock(&monc->mutex);
824 __close_session(monc); 821 __close_session(monc);
825 if (monc->con) { 822
826 monc->con->private = NULL; 823 monc->con->private = NULL;
827 monc->con->ops->put(monc->con); 824 monc->con->ops->put(monc->con);
828 monc->con = NULL; 825 monc->con = NULL;
829 } 826
830 mutex_unlock(&monc->mutex); 827 mutex_unlock(&monc->mutex);
831 828
832 ceph_auth_destroy(monc->auth); 829 ceph_auth_destroy(monc->auth);
@@ -1000,7 +997,7 @@ static void mon_fault(struct ceph_connection *con)
1000 if (!con->private) 997 if (!con->private)
1001 goto out; 998 goto out;
1002 999
1003 if (monc->con && !monc->hunting) 1000 if (!monc->hunting)
1004 pr_info("mon%d %s session lost, " 1001 pr_info("mon%d %s session lost, "
1005 "hunting for new mon\n", monc->cur_mon, 1002 "hunting for new mon\n", monc->cur_mon,
1006 ceph_pr_addr(&monc->con->peer_addr.in_addr)); 1003 ceph_pr_addr(&monc->con->peer_addr.in_addr));