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()
153 ret = ceph_auth_build_hello(monc->auth, in __open_session()
154 monc->m_auth->front.iov_base, in __open_session()
155 monc->m_auth->front_alloc_len); in __open_session()
156 __send_prepared_auth_request(monc, ret); in __open_session()
158 dout("open_session mon%d already open\n", monc->cur_mon); in __open_session()
163 static bool __sub_expired(struct ceph_mon_client *monc) in __sub_expired() argument
165 return time_after_eq(jiffies, monc->sub_renew_after); in __sub_expired()
171 static void __schedule_delayed(struct ceph_mon_client *monc) in __schedule_delayed() argument
175 if (monc->cur_mon < 0 || __sub_expired(monc)) in __schedule_delayed()
180 schedule_delayed_work(&monc->delayed_work, delay); in __schedule_delayed()
186 static void __send_subscribe(struct ceph_mon_client *monc) in __send_subscribe() argument
189 (unsigned int)monc->sub_sent, __sub_expired(monc), in __send_subscribe()
190 monc->want_next_osdmap); in __send_subscribe()
191 if ((__sub_expired(monc) && !monc->sub_sent) || in __send_subscribe()
192 monc->want_next_osdmap == 1) { in __send_subscribe()
193 struct ceph_msg *msg = monc->m_subscribe; in __send_subscribe()
201 num = 1 + !!monc->want_next_osdmap + !!monc->want_mdsmap; in __send_subscribe()
204 if (monc->want_next_osdmap) { in __send_subscribe()
206 (unsigned int)monc->have_osdmap); in __send_subscribe()
209 i->have = cpu_to_le64(monc->have_osdmap); in __send_subscribe()
212 monc->want_next_osdmap = 2; /* requested */ in __send_subscribe()
214 if (monc->want_mdsmap) { in __send_subscribe()
216 (unsigned int)monc->have_mdsmap); in __send_subscribe()
219 i->have = cpu_to_le64(monc->have_mdsmap); in __send_subscribe()
232 ceph_con_send(&monc->con, ceph_msg_get(msg)); in __send_subscribe()
234 monc->sub_sent = jiffies | 1; /* never 0 */ in __send_subscribe()
238 static void handle_subscribe_ack(struct ceph_mon_client *monc, in handle_subscribe_ack() argument
248 mutex_lock(&monc->mutex); in handle_subscribe_ack()
249 if (monc->hunting) { in handle_subscribe_ack()
251 monc->cur_mon, in handle_subscribe_ack()
252 ceph_pr_addr(&monc->con.peer_addr.in_addr)); in handle_subscribe_ack()
253 monc->hunting = false; in handle_subscribe_ack()
256 monc->sub_renew_after = monc->sub_sent + (seconds >> 1)*HZ - 1; in handle_subscribe_ack()
257 monc->sub_sent = 0; in handle_subscribe_ack()
258 mutex_unlock(&monc->mutex); in handle_subscribe_ack()
268 int ceph_monc_got_mdsmap(struct ceph_mon_client *monc, u32 got) in ceph_monc_got_mdsmap() argument
270 mutex_lock(&monc->mutex); in ceph_monc_got_mdsmap()
271 monc->have_mdsmap = got; in ceph_monc_got_mdsmap()
272 mutex_unlock(&monc->mutex); in ceph_monc_got_mdsmap()
277 int ceph_monc_got_osdmap(struct ceph_mon_client *monc, u32 got) in ceph_monc_got_osdmap() argument
279 mutex_lock(&monc->mutex); in ceph_monc_got_osdmap()
280 monc->have_osdmap = got; in ceph_monc_got_osdmap()
281 monc->want_next_osdmap = 0; in ceph_monc_got_osdmap()
282 mutex_unlock(&monc->mutex); in ceph_monc_got_osdmap()
289 void ceph_monc_request_next_osdmap(struct ceph_mon_client *monc) in ceph_monc_request_next_osdmap() argument
291 dout("request_next_osdmap have %u\n", monc->have_osdmap); in ceph_monc_request_next_osdmap()
292 mutex_lock(&monc->mutex); in ceph_monc_request_next_osdmap()
293 if (!monc->want_next_osdmap) in ceph_monc_request_next_osdmap()
294 monc->want_next_osdmap = 1; in ceph_monc_request_next_osdmap()
295 if (monc->want_next_osdmap < 2) in ceph_monc_request_next_osdmap()
296 __send_subscribe(monc); in ceph_monc_request_next_osdmap()
297 mutex_unlock(&monc->mutex); in ceph_monc_request_next_osdmap()
301 int ceph_monc_wait_osdmap(struct ceph_mon_client *monc, u32 epoch, in ceph_monc_wait_osdmap() argument
307 mutex_lock(&monc->mutex); in ceph_monc_wait_osdmap()
308 while (monc->have_osdmap < epoch) { in ceph_monc_wait_osdmap()
309 mutex_unlock(&monc->mutex); in ceph_monc_wait_osdmap()
314 ret = wait_event_interruptible_timeout(monc->client->auth_wq, in ceph_monc_wait_osdmap()
315 monc->have_osdmap >= epoch, timeout); in ceph_monc_wait_osdmap()
319 mutex_lock(&monc->mutex); in ceph_monc_wait_osdmap()
322 mutex_unlock(&monc->mutex); in ceph_monc_wait_osdmap()
330 int ceph_monc_open_session(struct ceph_mon_client *monc) in ceph_monc_open_session() argument
332 mutex_lock(&monc->mutex); in ceph_monc_open_session()
333 __open_session(monc); in ceph_monc_open_session()
334 __schedule_delayed(monc); in ceph_monc_open_session()
335 mutex_unlock(&monc->mutex); in ceph_monc_open_session()
344 static bool have_debugfs_info(struct ceph_mon_client *monc) in have_debugfs_info() argument
347 (int)monc->client->have_fsid, monc->auth->global_id); in have_debugfs_info()
348 return monc->client->have_fsid && monc->auth->global_id > 0; in have_debugfs_info()
355 static void ceph_monc_handle_map(struct ceph_mon_client *monc, in ceph_monc_handle_map() argument
358 struct ceph_client *client = monc->client; in ceph_monc_handle_map()
359 struct ceph_monmap *monmap = NULL, *old = monc->monmap; in ceph_monc_handle_map()
363 mutex_lock(&monc->mutex); in ceph_monc_handle_map()
365 had_debugfs_info = have_debugfs_info(monc); in ceph_monc_handle_map()
378 if (ceph_check_fsid(monc->client, &monmap->fsid) < 0) { in ceph_monc_handle_map()
383 client->monc.monmap = monmap; in ceph_monc_handle_map()
388 if (!had_debugfs_info && have_debugfs_info(monc)) { in ceph_monc_handle_map()
390 ceph_client_id(monc->client), in ceph_monc_handle_map()
391 &monc->client->fsid); in ceph_monc_handle_map()
394 mutex_unlock(&monc->mutex); in ceph_monc_handle_map()
401 ceph_debugfs_client_init(monc->client); in ceph_monc_handle_map()
407 mutex_unlock(&monc->mutex); in ceph_monc_handle_map()
416 struct ceph_mon_client *monc, u64 tid) in __lookup_generic_req() argument
419 struct rb_node *n = monc->generic_request_tree.rb_node; in __lookup_generic_req()
433 static void __insert_generic_request(struct ceph_mon_client *monc, in __insert_generic_request() argument
436 struct rb_node **p = &monc->generic_request_tree.rb_node; in __insert_generic_request()
452 rb_insert_color(&new->node, &monc->generic_request_tree); in __insert_generic_request()
482 struct ceph_mon_client *monc = con->private; in get_generic_reply() local
487 mutex_lock(&monc->mutex); in get_generic_reply()
488 req = __lookup_generic_req(monc, tid); in get_generic_reply()
503 mutex_unlock(&monc->mutex); in get_generic_reply()
507 static int __do_generic_request(struct ceph_mon_client *monc, u64 tid, in __do_generic_request() argument
513 req->tid = tid != 0 ? tid : ++monc->last_tid; in __do_generic_request()
515 __insert_generic_request(monc, req); in __do_generic_request()
516 monc->num_generic_requests++; in __do_generic_request()
517 ceph_con_send(&monc->con, ceph_msg_get(req->request)); in __do_generic_request()
518 mutex_unlock(&monc->mutex); in __do_generic_request()
522 mutex_lock(&monc->mutex); in __do_generic_request()
523 rb_erase(&req->node, &monc->generic_request_tree); in __do_generic_request()
524 monc->num_generic_requests--; in __do_generic_request()
531 static int do_generic_request(struct ceph_mon_client *monc, in do_generic_request() argument
536 mutex_lock(&monc->mutex); in do_generic_request()
537 err = __do_generic_request(monc, 0, req); in do_generic_request()
538 mutex_unlock(&monc->mutex); in do_generic_request()
546 static void handle_statfs_reply(struct ceph_mon_client *monc, in handle_statfs_reply() argument
557 mutex_lock(&monc->mutex); in handle_statfs_reply()
558 req = __lookup_generic_req(monc, tid); in handle_statfs_reply()
564 mutex_unlock(&monc->mutex); in handle_statfs_reply()
579 int ceph_monc_do_statfs(struct ceph_mon_client *monc, struct ceph_statfs *buf) in ceph_monc_do_statfs() argument
608 h->fsid = monc->monmap->fsid; in ceph_monc_do_statfs()
610 err = do_generic_request(monc, req); in ceph_monc_do_statfs()
618 static void handle_get_version_reply(struct ceph_mon_client *monc, in handle_get_version_reply() argument
634 mutex_lock(&monc->mutex); in handle_get_version_reply()
635 req = __lookup_generic_req(monc, handle); in handle_get_version_reply()
641 mutex_unlock(&monc->mutex); in handle_get_version_reply()
658 int ceph_monc_do_get_version(struct ceph_mon_client *monc, const char *what, in ceph_monc_do_get_version() argument
693 mutex_lock(&monc->mutex); in ceph_monc_do_get_version()
694 tid = ++monc->last_tid; in ceph_monc_do_get_version()
698 err = __do_generic_request(monc, tid, req); in ceph_monc_do_get_version()
700 mutex_unlock(&monc->mutex); in ceph_monc_do_get_version()
710 static void __resend_generic_request(struct ceph_mon_client *monc) in __resend_generic_request() argument
715 for (p = rb_first(&monc->generic_request_tree); p; p = rb_next(p)) { in __resend_generic_request()
719 ceph_con_send(&monc->con, ceph_msg_get(req->request)); in __resend_generic_request()
730 struct ceph_mon_client *monc = in delayed_work() local
734 mutex_lock(&monc->mutex); in delayed_work()
735 if (monc->hunting) { in delayed_work()
736 __close_session(monc); in delayed_work()
737 __open_session(monc); /* continue hunting */ in delayed_work()
739 ceph_con_keepalive(&monc->con); in delayed_work()
741 __validate_auth(monc); in delayed_work()
743 if (ceph_auth_is_authenticated(monc->auth)) in delayed_work()
744 __send_subscribe(monc); in delayed_work()
746 __schedule_delayed(monc); in delayed_work()
747 mutex_unlock(&monc->mutex); in delayed_work()
754 static int build_initial_monmap(struct ceph_mon_client *monc) in build_initial_monmap() argument
756 struct ceph_options *opt = monc->client->options; in build_initial_monmap()
762 monc->monmap = kzalloc(sizeof(*monc->monmap) + in build_initial_monmap()
763 num_mon*sizeof(monc->monmap->mon_inst[0]), in build_initial_monmap()
765 if (!monc->monmap) in build_initial_monmap()
768 monc->monmap->mon_inst[i].addr = mon_addr[i]; in build_initial_monmap()
769 monc->monmap->mon_inst[i].addr.nonce = 0; in build_initial_monmap()
770 monc->monmap->mon_inst[i].name.type = in build_initial_monmap()
772 monc->monmap->mon_inst[i].name.num = cpu_to_le64(i); in build_initial_monmap()
774 monc->monmap->num_mon = num_mon; in build_initial_monmap()
778 int ceph_monc_init(struct ceph_mon_client *monc, struct ceph_client *cl) in ceph_monc_init() argument
783 memset(monc, 0, sizeof(*monc)); in ceph_monc_init()
784 monc->client = cl; in ceph_monc_init()
785 monc->monmap = NULL; in ceph_monc_init()
786 mutex_init(&monc->mutex); in ceph_monc_init()
788 err = build_initial_monmap(monc); in ceph_monc_init()
794 monc->auth = ceph_auth_init(cl->options->name, in ceph_monc_init()
796 if (IS_ERR(monc->auth)) { in ceph_monc_init()
797 err = PTR_ERR(monc->auth); in ceph_monc_init()
800 monc->auth->want_keys = in ceph_monc_init()
806 monc->m_subscribe_ack = ceph_msg_new(CEPH_MSG_MON_SUBSCRIBE_ACK, in ceph_monc_init()
809 if (!monc->m_subscribe_ack) in ceph_monc_init()
812 monc->m_subscribe = ceph_msg_new(CEPH_MSG_MON_SUBSCRIBE, 96, GFP_NOFS, in ceph_monc_init()
814 if (!monc->m_subscribe) in ceph_monc_init()
817 monc->m_auth_reply = ceph_msg_new(CEPH_MSG_AUTH_REPLY, 4096, GFP_NOFS, in ceph_monc_init()
819 if (!monc->m_auth_reply) in ceph_monc_init()
822 monc->m_auth = ceph_msg_new(CEPH_MSG_AUTH, 4096, GFP_NOFS, true); in ceph_monc_init()
823 monc->pending_auth = 0; in ceph_monc_init()
824 if (!monc->m_auth) in ceph_monc_init()
827 ceph_con_init(&monc->con, monc, &mon_con_ops, in ceph_monc_init()
828 &monc->client->msgr); in ceph_monc_init()
830 monc->cur_mon = -1; in ceph_monc_init()
831 monc->hunting = true; in ceph_monc_init()
832 monc->sub_renew_after = jiffies; in ceph_monc_init()
833 monc->sub_sent = 0; in ceph_monc_init()
835 INIT_DELAYED_WORK(&monc->delayed_work, delayed_work); in ceph_monc_init()
836 monc->generic_request_tree = RB_ROOT; in ceph_monc_init()
837 monc->num_generic_requests = 0; in ceph_monc_init()
838 monc->last_tid = 0; in ceph_monc_init()
840 monc->have_mdsmap = 0; in ceph_monc_init()
841 monc->have_osdmap = 0; in ceph_monc_init()
842 monc->want_next_osdmap = 1; in ceph_monc_init()
846 ceph_msg_put(monc->m_auth_reply); in ceph_monc_init()
848 ceph_msg_put(monc->m_subscribe); in ceph_monc_init()
850 ceph_msg_put(monc->m_subscribe_ack); in ceph_monc_init()
852 ceph_auth_destroy(monc->auth); in ceph_monc_init()
854 kfree(monc->monmap); in ceph_monc_init()
860 void ceph_monc_stop(struct ceph_mon_client *monc) in ceph_monc_stop() argument
863 cancel_delayed_work_sync(&monc->delayed_work); in ceph_monc_stop()
865 mutex_lock(&monc->mutex); in ceph_monc_stop()
866 __close_session(monc); in ceph_monc_stop()
868 mutex_unlock(&monc->mutex); in ceph_monc_stop()
878 ceph_auth_destroy(monc->auth); in ceph_monc_stop()
880 ceph_msg_put(monc->m_auth); in ceph_monc_stop()
881 ceph_msg_put(monc->m_auth_reply); in ceph_monc_stop()
882 ceph_msg_put(monc->m_subscribe); in ceph_monc_stop()
883 ceph_msg_put(monc->m_subscribe_ack); in ceph_monc_stop()
885 kfree(monc->monmap); in ceph_monc_stop()
889 static void handle_auth_reply(struct ceph_mon_client *monc, in handle_auth_reply() argument
896 mutex_lock(&monc->mutex); in handle_auth_reply()
897 had_debugfs_info = have_debugfs_info(monc); in handle_auth_reply()
898 was_auth = ceph_auth_is_authenticated(monc->auth); in handle_auth_reply()
899 monc->pending_auth = 0; in handle_auth_reply()
900 ret = ceph_handle_auth_reply(monc->auth, msg->front.iov_base, in handle_auth_reply()
902 monc->m_auth->front.iov_base, in handle_auth_reply()
903 monc->m_auth->front_alloc_len); in handle_auth_reply()
905 monc->client->auth_err = ret; in handle_auth_reply()
906 wake_up_all(&monc->client->auth_wq); in handle_auth_reply()
908 __send_prepared_auth_request(monc, ret); in handle_auth_reply()
909 } else if (!was_auth && ceph_auth_is_authenticated(monc->auth)) { in handle_auth_reply()
912 monc->client->msgr.inst.name.type = CEPH_ENTITY_TYPE_CLIENT; in handle_auth_reply()
913 monc->client->msgr.inst.name.num = in handle_auth_reply()
914 cpu_to_le64(monc->auth->global_id); in handle_auth_reply()
916 __send_subscribe(monc); in handle_auth_reply()
917 __resend_generic_request(monc); in handle_auth_reply()
920 if (!had_debugfs_info && have_debugfs_info(monc)) { in handle_auth_reply()
922 ceph_client_id(monc->client), in handle_auth_reply()
923 &monc->client->fsid); in handle_auth_reply()
926 mutex_unlock(&monc->mutex); in handle_auth_reply()
933 ceph_debugfs_client_init(monc->client); in handle_auth_reply()
937 static int __validate_auth(struct ceph_mon_client *monc) in __validate_auth() argument
941 if (monc->pending_auth) in __validate_auth()
944 ret = ceph_build_auth(monc->auth, monc->m_auth->front.iov_base, in __validate_auth()
945 monc->m_auth->front_alloc_len); in __validate_auth()
948 __send_prepared_auth_request(monc, ret); in __validate_auth()
952 int ceph_monc_validate_auth(struct ceph_mon_client *monc) in ceph_monc_validate_auth() argument
956 mutex_lock(&monc->mutex); in ceph_monc_validate_auth()
957 ret = __validate_auth(monc); in ceph_monc_validate_auth()
958 mutex_unlock(&monc->mutex); in ceph_monc_validate_auth()
968 struct ceph_mon_client *monc = con->private; in dispatch() local
971 if (!monc) in dispatch()
976 handle_auth_reply(monc, msg); in dispatch()
980 handle_subscribe_ack(monc, msg); in dispatch()
984 handle_statfs_reply(monc, msg); in dispatch()
988 handle_get_version_reply(monc, msg); in dispatch()
992 ceph_monc_handle_map(monc, msg); in dispatch()
996 ceph_osdc_handle_map(&monc->client->osdc, msg); in dispatch()
1001 if (monc->client->extra_mon_dispatch && in dispatch()
1002 monc->client->extra_mon_dispatch(monc->client, msg) == 0) in dispatch()
1018 struct ceph_mon_client *monc = con->private; in mon_alloc_msg() local
1027 m = ceph_msg_get(monc->m_subscribe_ack); in mon_alloc_msg()
1032 m = ceph_msg_get(monc->m_auth_reply); in mon_alloc_msg()
1073 struct ceph_mon_client *monc = con->private; in mon_fault() local
1075 if (!monc) in mon_fault()
1079 mutex_lock(&monc->mutex); in mon_fault()
1083 if (!monc->hunting) in mon_fault()
1085 "hunting for new mon\n", monc->cur_mon, in mon_fault()
1086 ceph_pr_addr(&monc->con.peer_addr.in_addr)); in mon_fault()
1088 __close_session(monc); in mon_fault()
1089 if (!monc->hunting) { in mon_fault()
1091 monc->hunting = true; in mon_fault()
1092 __open_session(monc); in mon_fault()
1095 __schedule_delayed(monc); in mon_fault()
1098 mutex_unlock(&monc->mutex); in mon_fault()