Lines Matching refs:monc
35 static int __validate_auth(struct ceph_mon_client *monc);
104 static void __send_prepared_auth_request(struct ceph_mon_client *monc, int len) in __send_prepared_auth_request() argument
106 monc->pending_auth = 1; in __send_prepared_auth_request()
107 monc->m_auth->front.iov_len = len; in __send_prepared_auth_request()
108 monc->m_auth->hdr.front_len = cpu_to_le32(len); in __send_prepared_auth_request()
109 ceph_msg_revoke(monc->m_auth); in __send_prepared_auth_request()
110 ceph_msg_get(monc->m_auth); /* keep our ref */ in __send_prepared_auth_request()
111 ceph_con_send(&monc->con, monc->m_auth); in __send_prepared_auth_request()
117 static void __close_session(struct ceph_mon_client *monc) in __close_session() argument
119 dout("__close_session closing mon%d\n", monc->cur_mon); in __close_session()
120 ceph_msg_revoke(monc->m_auth); in __close_session()
121 ceph_msg_revoke_incoming(monc->m_auth_reply); in __close_session()
122 ceph_msg_revoke(monc->m_subscribe); in __close_session()
123 ceph_msg_revoke_incoming(monc->m_subscribe_ack); in __close_session()
124 ceph_con_close(&monc->con); in __close_session()
125 monc->cur_mon = -1; in __close_session()
126 monc->pending_auth = 0; in __close_session()
127 ceph_auth_reset(monc->auth); in __close_session()
133 static int __open_session(struct ceph_mon_client *monc) in __open_session() argument
138 if (monc->cur_mon < 0) { in __open_session()
140 monc->cur_mon = r % monc->monmap->num_mon; in __open_session()
142 monc->monmap->num_mon, r, monc->cur_mon); in __open_session()
143 monc->sub_sent = 0; in __open_session()
144 monc->sub_renew_after = jiffies; /* i.e., expired */ in __open_session()
145 monc->want_next_osdmap = !!monc->want_next_osdmap; in __open_session()
147 dout("open_session mon%d opening\n", monc->cur_mon); in __open_session()
148 ceph_con_open(&monc->con, in __open_session()
149 CEPH_ENTITY_TYPE_MON, monc->cur_mon, in __open_session()
150 &monc->monmap->mon_inst[monc->cur_mon].addr); in __open_session()
154 ceph_con_keepalive(&monc->con); in __open_session()
157 ret = ceph_auth_build_hello(monc->auth, in __open_session()
158 monc->m_auth->front.iov_base, in __open_session()
159 monc->m_auth->front_alloc_len); in __open_session()
160 __send_prepared_auth_request(monc, ret); in __open_session()
162 dout("open_session mon%d already open\n", monc->cur_mon); in __open_session()
167 static bool __sub_expired(struct ceph_mon_client *monc) in __sub_expired() argument
169 return time_after_eq(jiffies, monc->sub_renew_after); in __sub_expired()
175 static void __schedule_delayed(struct ceph_mon_client *monc) in __schedule_delayed() argument
177 struct ceph_options *opt = monc->client->options; in __schedule_delayed()
180 if (monc->cur_mon < 0 || __sub_expired(monc)) { in __schedule_delayed()
188 schedule_delayed_work(&monc->delayed_work, in __schedule_delayed()
195 static void __send_subscribe(struct ceph_mon_client *monc) in __send_subscribe() argument
198 (unsigned int)monc->sub_sent, __sub_expired(monc), in __send_subscribe()
199 monc->want_next_osdmap); in __send_subscribe()
200 if ((__sub_expired(monc) && !monc->sub_sent) || in __send_subscribe()
201 monc->want_next_osdmap == 1) { in __send_subscribe()
202 struct ceph_msg *msg = monc->m_subscribe; in __send_subscribe()
210 num = 1 + !!monc->want_next_osdmap + !!monc->want_mdsmap; in __send_subscribe()
213 if (monc->want_next_osdmap) { in __send_subscribe()
215 (unsigned int)monc->have_osdmap); in __send_subscribe()
218 i->have = cpu_to_le64(monc->have_osdmap); in __send_subscribe()
221 monc->want_next_osdmap = 2; /* requested */ in __send_subscribe()
223 if (monc->want_mdsmap) { in __send_subscribe()
225 (unsigned int)monc->have_mdsmap); in __send_subscribe()
228 i->have = cpu_to_le64(monc->have_mdsmap); in __send_subscribe()
241 ceph_con_send(&monc->con, ceph_msg_get(msg)); in __send_subscribe()
243 monc->sub_sent = jiffies | 1; /* never 0 */ in __send_subscribe()
247 static void handle_subscribe_ack(struct ceph_mon_client *monc, in handle_subscribe_ack() argument
257 mutex_lock(&monc->mutex); in handle_subscribe_ack()
258 if (monc->hunting) { in handle_subscribe_ack()
260 monc->cur_mon, in handle_subscribe_ack()
261 ceph_pr_addr(&monc->con.peer_addr.in_addr)); in handle_subscribe_ack()
262 monc->hunting = false; in handle_subscribe_ack()
265 monc->sub_renew_after = monc->sub_sent + (seconds >> 1)*HZ - 1; in handle_subscribe_ack()
266 monc->sub_sent = 0; in handle_subscribe_ack()
267 mutex_unlock(&monc->mutex); in handle_subscribe_ack()
277 int ceph_monc_got_mdsmap(struct ceph_mon_client *monc, u32 got) in ceph_monc_got_mdsmap() argument
279 mutex_lock(&monc->mutex); in ceph_monc_got_mdsmap()
280 monc->have_mdsmap = got; in ceph_monc_got_mdsmap()
281 mutex_unlock(&monc->mutex); in ceph_monc_got_mdsmap()
286 int ceph_monc_got_osdmap(struct ceph_mon_client *monc, u32 got) in ceph_monc_got_osdmap() argument
288 mutex_lock(&monc->mutex); in ceph_monc_got_osdmap()
289 monc->have_osdmap = got; in ceph_monc_got_osdmap()
290 monc->want_next_osdmap = 0; in ceph_monc_got_osdmap()
291 mutex_unlock(&monc->mutex); in ceph_monc_got_osdmap()
298 void ceph_monc_request_next_osdmap(struct ceph_mon_client *monc) in ceph_monc_request_next_osdmap() argument
300 dout("request_next_osdmap have %u\n", monc->have_osdmap); in ceph_monc_request_next_osdmap()
301 mutex_lock(&monc->mutex); in ceph_monc_request_next_osdmap()
302 if (!monc->want_next_osdmap) in ceph_monc_request_next_osdmap()
303 monc->want_next_osdmap = 1; in ceph_monc_request_next_osdmap()
304 if (monc->want_next_osdmap < 2) in ceph_monc_request_next_osdmap()
305 __send_subscribe(monc); in ceph_monc_request_next_osdmap()
306 mutex_unlock(&monc->mutex); in ceph_monc_request_next_osdmap()
316 int ceph_monc_wait_osdmap(struct ceph_mon_client *monc, u32 epoch, in ceph_monc_wait_osdmap() argument
322 mutex_lock(&monc->mutex); in ceph_monc_wait_osdmap()
323 while (monc->have_osdmap < epoch) { in ceph_monc_wait_osdmap()
324 mutex_unlock(&monc->mutex); in ceph_monc_wait_osdmap()
329 ret = wait_event_interruptible_timeout(monc->client->auth_wq, in ceph_monc_wait_osdmap()
330 monc->have_osdmap >= epoch, in ceph_monc_wait_osdmap()
335 mutex_lock(&monc->mutex); in ceph_monc_wait_osdmap()
338 mutex_unlock(&monc->mutex); in ceph_monc_wait_osdmap()
346 int ceph_monc_open_session(struct ceph_mon_client *monc) in ceph_monc_open_session() argument
348 mutex_lock(&monc->mutex); in ceph_monc_open_session()
349 __open_session(monc); in ceph_monc_open_session()
350 __schedule_delayed(monc); in ceph_monc_open_session()
351 mutex_unlock(&monc->mutex); in ceph_monc_open_session()
360 static bool have_debugfs_info(struct ceph_mon_client *monc) in have_debugfs_info() argument
363 (int)monc->client->have_fsid, monc->auth->global_id); in have_debugfs_info()
364 return monc->client->have_fsid && monc->auth->global_id > 0; in have_debugfs_info()
371 static void ceph_monc_handle_map(struct ceph_mon_client *monc, in ceph_monc_handle_map() argument
374 struct ceph_client *client = monc->client; in ceph_monc_handle_map()
375 struct ceph_monmap *monmap = NULL, *old = monc->monmap; in ceph_monc_handle_map()
379 mutex_lock(&monc->mutex); in ceph_monc_handle_map()
381 had_debugfs_info = have_debugfs_info(monc); in ceph_monc_handle_map()
394 if (ceph_check_fsid(monc->client, &monmap->fsid) < 0) { in ceph_monc_handle_map()
399 client->monc.monmap = monmap; in ceph_monc_handle_map()
404 if (!had_debugfs_info && have_debugfs_info(monc)) { in ceph_monc_handle_map()
406 ceph_client_id(monc->client), in ceph_monc_handle_map()
407 &monc->client->fsid); in ceph_monc_handle_map()
410 mutex_unlock(&monc->mutex); in ceph_monc_handle_map()
417 ceph_debugfs_client_init(monc->client); in ceph_monc_handle_map()
423 mutex_unlock(&monc->mutex); in ceph_monc_handle_map()
432 struct ceph_mon_client *monc, u64 tid) in __lookup_generic_req() argument
435 struct rb_node *n = monc->generic_request_tree.rb_node; in __lookup_generic_req()
449 static void __insert_generic_request(struct ceph_mon_client *monc, in __insert_generic_request() argument
452 struct rb_node **p = &monc->generic_request_tree.rb_node; in __insert_generic_request()
468 rb_insert_color(&new->node, &monc->generic_request_tree); in __insert_generic_request()
498 struct ceph_mon_client *monc = con->private; in get_generic_reply() local
503 mutex_lock(&monc->mutex); in get_generic_reply()
504 req = __lookup_generic_req(monc, tid); in get_generic_reply()
519 mutex_unlock(&monc->mutex); in get_generic_reply()
523 static int __do_generic_request(struct ceph_mon_client *monc, u64 tid, in __do_generic_request() argument
529 req->tid = tid != 0 ? tid : ++monc->last_tid; in __do_generic_request()
531 __insert_generic_request(monc, req); in __do_generic_request()
532 monc->num_generic_requests++; in __do_generic_request()
533 ceph_con_send(&monc->con, ceph_msg_get(req->request)); in __do_generic_request()
534 mutex_unlock(&monc->mutex); in __do_generic_request()
538 mutex_lock(&monc->mutex); in __do_generic_request()
539 rb_erase(&req->node, &monc->generic_request_tree); in __do_generic_request()
540 monc->num_generic_requests--; in __do_generic_request()
547 static int do_generic_request(struct ceph_mon_client *monc, in do_generic_request() argument
552 mutex_lock(&monc->mutex); in do_generic_request()
553 err = __do_generic_request(monc, 0, req); in do_generic_request()
554 mutex_unlock(&monc->mutex); in do_generic_request()
562 static void handle_statfs_reply(struct ceph_mon_client *monc, in handle_statfs_reply() argument
573 mutex_lock(&monc->mutex); in handle_statfs_reply()
574 req = __lookup_generic_req(monc, tid); in handle_statfs_reply()
580 mutex_unlock(&monc->mutex); in handle_statfs_reply()
595 int ceph_monc_do_statfs(struct ceph_mon_client *monc, struct ceph_statfs *buf) in ceph_monc_do_statfs() argument
624 h->fsid = monc->monmap->fsid; in ceph_monc_do_statfs()
626 err = do_generic_request(monc, req); in ceph_monc_do_statfs()
634 static void handle_get_version_reply(struct ceph_mon_client *monc, in handle_get_version_reply() argument
650 mutex_lock(&monc->mutex); in handle_get_version_reply()
651 req = __lookup_generic_req(monc, handle); in handle_get_version_reply()
657 mutex_unlock(&monc->mutex); in handle_get_version_reply()
674 int ceph_monc_do_get_version(struct ceph_mon_client *monc, const char *what, in ceph_monc_do_get_version() argument
709 mutex_lock(&monc->mutex); in ceph_monc_do_get_version()
710 tid = ++monc->last_tid; in ceph_monc_do_get_version()
714 err = __do_generic_request(monc, tid, req); in ceph_monc_do_get_version()
716 mutex_unlock(&monc->mutex); in ceph_monc_do_get_version()
726 static void __resend_generic_request(struct ceph_mon_client *monc) in __resend_generic_request() argument
731 for (p = rb_first(&monc->generic_request_tree); p; p = rb_next(p)) { in __resend_generic_request()
735 ceph_con_send(&monc->con, ceph_msg_get(req->request)); in __resend_generic_request()
746 struct ceph_mon_client *monc = in delayed_work() local
750 mutex_lock(&monc->mutex); in delayed_work()
751 if (monc->hunting) { in delayed_work()
752 __close_session(monc); in delayed_work()
753 __open_session(monc); /* continue hunting */ in delayed_work()
755 struct ceph_options *opt = monc->client->options; in delayed_work()
756 int is_auth = ceph_auth_is_authenticated(monc->auth); in delayed_work()
757 if (ceph_con_keepalive_expired(&monc->con, in delayed_work()
761 __close_session(monc); in delayed_work()
762 monc->hunting = true; in delayed_work()
763 __open_session(monc); in delayed_work()
766 if (!monc->hunting) { in delayed_work()
767 ceph_con_keepalive(&monc->con); in delayed_work()
768 __validate_auth(monc); in delayed_work()
772 __send_subscribe(monc); in delayed_work()
774 __schedule_delayed(monc); in delayed_work()
775 mutex_unlock(&monc->mutex); in delayed_work()
782 static int build_initial_monmap(struct ceph_mon_client *monc) in build_initial_monmap() argument
784 struct ceph_options *opt = monc->client->options; in build_initial_monmap()
790 monc->monmap = kzalloc(sizeof(*monc->monmap) + in build_initial_monmap()
791 num_mon*sizeof(monc->monmap->mon_inst[0]), in build_initial_monmap()
793 if (!monc->monmap) in build_initial_monmap()
796 monc->monmap->mon_inst[i].addr = mon_addr[i]; in build_initial_monmap()
797 monc->monmap->mon_inst[i].addr.nonce = 0; in build_initial_monmap()
798 monc->monmap->mon_inst[i].name.type = in build_initial_monmap()
800 monc->monmap->mon_inst[i].name.num = cpu_to_le64(i); in build_initial_monmap()
802 monc->monmap->num_mon = num_mon; in build_initial_monmap()
806 int ceph_monc_init(struct ceph_mon_client *monc, struct ceph_client *cl) in ceph_monc_init() argument
811 memset(monc, 0, sizeof(*monc)); in ceph_monc_init()
812 monc->client = cl; in ceph_monc_init()
813 monc->monmap = NULL; in ceph_monc_init()
814 mutex_init(&monc->mutex); in ceph_monc_init()
816 err = build_initial_monmap(monc); in ceph_monc_init()
822 monc->auth = ceph_auth_init(cl->options->name, in ceph_monc_init()
824 if (IS_ERR(monc->auth)) { in ceph_monc_init()
825 err = PTR_ERR(monc->auth); in ceph_monc_init()
828 monc->auth->want_keys = in ceph_monc_init()
834 monc->m_subscribe_ack = ceph_msg_new(CEPH_MSG_MON_SUBSCRIBE_ACK, in ceph_monc_init()
837 if (!monc->m_subscribe_ack) in ceph_monc_init()
840 monc->m_subscribe = ceph_msg_new(CEPH_MSG_MON_SUBSCRIBE, 96, GFP_NOFS, in ceph_monc_init()
842 if (!monc->m_subscribe) in ceph_monc_init()
845 monc->m_auth_reply = ceph_msg_new(CEPH_MSG_AUTH_REPLY, 4096, GFP_NOFS, in ceph_monc_init()
847 if (!monc->m_auth_reply) in ceph_monc_init()
850 monc->m_auth = ceph_msg_new(CEPH_MSG_AUTH, 4096, GFP_NOFS, true); in ceph_monc_init()
851 monc->pending_auth = 0; in ceph_monc_init()
852 if (!monc->m_auth) in ceph_monc_init()
855 ceph_con_init(&monc->con, monc, &mon_con_ops, in ceph_monc_init()
856 &monc->client->msgr); in ceph_monc_init()
858 monc->cur_mon = -1; in ceph_monc_init()
859 monc->hunting = true; in ceph_monc_init()
860 monc->sub_renew_after = jiffies; in ceph_monc_init()
861 monc->sub_sent = 0; in ceph_monc_init()
863 INIT_DELAYED_WORK(&monc->delayed_work, delayed_work); in ceph_monc_init()
864 monc->generic_request_tree = RB_ROOT; in ceph_monc_init()
865 monc->num_generic_requests = 0; in ceph_monc_init()
866 monc->last_tid = 0; in ceph_monc_init()
868 monc->have_mdsmap = 0; in ceph_monc_init()
869 monc->have_osdmap = 0; in ceph_monc_init()
870 monc->want_next_osdmap = 1; in ceph_monc_init()
874 ceph_msg_put(monc->m_auth_reply); in ceph_monc_init()
876 ceph_msg_put(monc->m_subscribe); in ceph_monc_init()
878 ceph_msg_put(monc->m_subscribe_ack); in ceph_monc_init()
880 ceph_auth_destroy(monc->auth); in ceph_monc_init()
882 kfree(monc->monmap); in ceph_monc_init()
888 void ceph_monc_stop(struct ceph_mon_client *monc) in ceph_monc_stop() argument
891 cancel_delayed_work_sync(&monc->delayed_work); in ceph_monc_stop()
893 mutex_lock(&monc->mutex); in ceph_monc_stop()
894 __close_session(monc); in ceph_monc_stop()
896 mutex_unlock(&monc->mutex); in ceph_monc_stop()
906 ceph_auth_destroy(monc->auth); in ceph_monc_stop()
908 ceph_msg_put(monc->m_auth); in ceph_monc_stop()
909 ceph_msg_put(monc->m_auth_reply); in ceph_monc_stop()
910 ceph_msg_put(monc->m_subscribe); in ceph_monc_stop()
911 ceph_msg_put(monc->m_subscribe_ack); in ceph_monc_stop()
913 kfree(monc->monmap); in ceph_monc_stop()
917 static void handle_auth_reply(struct ceph_mon_client *monc, in handle_auth_reply() argument
924 mutex_lock(&monc->mutex); in handle_auth_reply()
925 had_debugfs_info = have_debugfs_info(monc); in handle_auth_reply()
926 was_auth = ceph_auth_is_authenticated(monc->auth); in handle_auth_reply()
927 monc->pending_auth = 0; in handle_auth_reply()
928 ret = ceph_handle_auth_reply(monc->auth, msg->front.iov_base, in handle_auth_reply()
930 monc->m_auth->front.iov_base, in handle_auth_reply()
931 monc->m_auth->front_alloc_len); in handle_auth_reply()
933 monc->client->auth_err = ret; in handle_auth_reply()
934 wake_up_all(&monc->client->auth_wq); in handle_auth_reply()
936 __send_prepared_auth_request(monc, ret); in handle_auth_reply()
937 } else if (!was_auth && ceph_auth_is_authenticated(monc->auth)) { in handle_auth_reply()
940 monc->client->msgr.inst.name.type = CEPH_ENTITY_TYPE_CLIENT; in handle_auth_reply()
941 monc->client->msgr.inst.name.num = in handle_auth_reply()
942 cpu_to_le64(monc->auth->global_id); in handle_auth_reply()
944 __send_subscribe(monc); in handle_auth_reply()
945 __resend_generic_request(monc); in handle_auth_reply()
948 if (!had_debugfs_info && have_debugfs_info(monc)) { in handle_auth_reply()
950 ceph_client_id(monc->client), in handle_auth_reply()
951 &monc->client->fsid); in handle_auth_reply()
954 mutex_unlock(&monc->mutex); in handle_auth_reply()
961 ceph_debugfs_client_init(monc->client); in handle_auth_reply()
965 static int __validate_auth(struct ceph_mon_client *monc) in __validate_auth() argument
969 if (monc->pending_auth) in __validate_auth()
972 ret = ceph_build_auth(monc->auth, monc->m_auth->front.iov_base, in __validate_auth()
973 monc->m_auth->front_alloc_len); in __validate_auth()
976 __send_prepared_auth_request(monc, ret); in __validate_auth()
980 int ceph_monc_validate_auth(struct ceph_mon_client *monc) in ceph_monc_validate_auth() argument
984 mutex_lock(&monc->mutex); in ceph_monc_validate_auth()
985 ret = __validate_auth(monc); in ceph_monc_validate_auth()
986 mutex_unlock(&monc->mutex); in ceph_monc_validate_auth()
996 struct ceph_mon_client *monc = con->private; in dispatch() local
999 if (!monc) in dispatch()
1004 handle_auth_reply(monc, msg); in dispatch()
1008 handle_subscribe_ack(monc, msg); in dispatch()
1012 handle_statfs_reply(monc, msg); in dispatch()
1016 handle_get_version_reply(monc, msg); in dispatch()
1020 ceph_monc_handle_map(monc, msg); in dispatch()
1024 ceph_osdc_handle_map(&monc->client->osdc, msg); in dispatch()
1029 if (monc->client->extra_mon_dispatch && in dispatch()
1030 monc->client->extra_mon_dispatch(monc->client, msg) == 0) in dispatch()
1046 struct ceph_mon_client *monc = con->private; in mon_alloc_msg() local
1055 m = ceph_msg_get(monc->m_subscribe_ack); in mon_alloc_msg()
1060 m = ceph_msg_get(monc->m_auth_reply); in mon_alloc_msg()
1101 struct ceph_mon_client *monc = con->private; in mon_fault() local
1103 if (!monc) in mon_fault()
1107 mutex_lock(&monc->mutex); in mon_fault()
1111 if (!monc->hunting) in mon_fault()
1113 "hunting for new mon\n", monc->cur_mon, in mon_fault()
1114 ceph_pr_addr(&monc->con.peer_addr.in_addr)); in mon_fault()
1116 __close_session(monc); in mon_fault()
1117 if (!monc->hunting) { in mon_fault()
1119 monc->hunting = true; in mon_fault()
1120 __open_session(monc); in mon_fault()
1123 __schedule_delayed(monc); in mon_fault()
1126 mutex_unlock(&monc->mutex); in mon_fault()