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_con_revoke(monc->con, 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 if (monc->con) { in __close_session()
120 dout("__close_session closing mon%d\n", monc->cur_mon); in __close_session()
121 ceph_con_revoke(monc->con, monc->m_auth); in __close_session()
122 ceph_con_close(monc->con); in __close_session()
123 monc->cur_mon = -1; in __close_session()
124 monc->pending_auth = 0; in __close_session()
125 ceph_auth_reset(monc->auth); in __close_session()
132 static int __open_session(struct ceph_mon_client *monc) in __open_session() argument
137 if (monc->cur_mon < 0) { in __open_session()
139 monc->cur_mon = r % monc->monmap->num_mon; in __open_session()
141 monc->monmap->num_mon, r, monc->cur_mon); in __open_session()
142 monc->sub_sent = 0; in __open_session()
143 monc->sub_renew_after = jiffies; /* i.e., expired */ in __open_session()
144 monc->want_next_osdmap = !!monc->want_next_osdmap; in __open_session()
146 dout("open_session mon%d opening\n", monc->cur_mon); in __open_session()
147 monc->con->peer_name.type = CEPH_ENTITY_TYPE_MON; in __open_session()
148 monc->con->peer_name.num = cpu_to_le64(monc->cur_mon); in __open_session()
149 ceph_con_open(monc->con, 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_max); 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)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)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)monc->have_mdsmap); in __send_subscribe()
219 i->have = cpu_to_le64(monc->have_mdsmap); in __send_subscribe()
231 ceph_con_revoke(monc->con, msg); 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()
303 int ceph_monc_open_session(struct ceph_mon_client *monc) in ceph_monc_open_session() argument
305 if (!monc->con) { in ceph_monc_open_session()
306 monc->con = kmalloc(sizeof(*monc->con), GFP_KERNEL); in ceph_monc_open_session()
307 if (!monc->con) in ceph_monc_open_session()
309 ceph_con_init(monc->client->msgr, monc->con); in ceph_monc_open_session()
310 monc->con->private = monc; in ceph_monc_open_session()
311 monc->con->ops = &mon_con_ops; in ceph_monc_open_session()
314 mutex_lock(&monc->mutex); in ceph_monc_open_session()
315 __open_session(monc); in ceph_monc_open_session()
316 __schedule_delayed(monc); in ceph_monc_open_session()
317 mutex_unlock(&monc->mutex); in ceph_monc_open_session()
326 static void ceph_monc_handle_map(struct ceph_mon_client *monc, in ceph_monc_handle_map() argument
329 struct ceph_client *client = monc->client; in ceph_monc_handle_map()
330 struct ceph_monmap *monmap = NULL, *old = monc->monmap; in ceph_monc_handle_map()
333 mutex_lock(&monc->mutex); in ceph_monc_handle_map()
346 if (ceph_check_fsid(monc->client, &monmap->fsid) < 0) { in ceph_monc_handle_map()
351 client->monc.monmap = monmap; in ceph_monc_handle_map()
355 mutex_unlock(&monc->mutex); in ceph_monc_handle_map()
363 struct ceph_mon_client *monc, u64 tid) in __lookup_generic_req() argument
366 struct rb_node *n = monc->generic_request_tree.rb_node; in __lookup_generic_req()
380 static void __insert_generic_request(struct ceph_mon_client *monc, in __insert_generic_request() argument
383 struct rb_node **p = &monc->generic_request_tree.rb_node; in __insert_generic_request()
399 rb_insert_color(&new->node, &monc->generic_request_tree); in __insert_generic_request()
429 struct ceph_mon_client *monc = con->private; in get_generic_reply() local
434 mutex_lock(&monc->mutex); in get_generic_reply()
435 req = __lookup_generic_req(monc, tid); in get_generic_reply()
449 mutex_unlock(&monc->mutex); in get_generic_reply()
453 static int do_generic_request(struct ceph_mon_client *monc, in do_generic_request() argument
459 mutex_lock(&monc->mutex); in do_generic_request()
460 req->tid = ++monc->last_tid; in do_generic_request()
462 __insert_generic_request(monc, req); in do_generic_request()
463 monc->num_generic_requests++; in do_generic_request()
464 ceph_con_send(monc->con, ceph_msg_get(req->request)); in do_generic_request()
465 mutex_unlock(&monc->mutex); in do_generic_request()
469 mutex_lock(&monc->mutex); in do_generic_request()
470 rb_erase(&req->node, &monc->generic_request_tree); in do_generic_request()
471 monc->num_generic_requests--; in do_generic_request()
472 mutex_unlock(&monc->mutex); in do_generic_request()
482 static void handle_statfs_reply(struct ceph_mon_client *monc, in handle_statfs_reply() argument
493 mutex_lock(&monc->mutex); in handle_statfs_reply()
494 req = __lookup_generic_req(monc, tid); in handle_statfs_reply()
500 mutex_unlock(&monc->mutex); in handle_statfs_reply()
515 int ceph_monc_do_statfs(struct ceph_mon_client *monc, struct ceph_statfs *buf) in ceph_monc_do_statfs() argument
543 h->fsid = monc->monmap->fsid; in ceph_monc_do_statfs()
545 err = do_generic_request(monc, req); in ceph_monc_do_statfs()
572 static void handle_poolop_reply(struct ceph_mon_client *monc, in handle_poolop_reply() argument
583 mutex_lock(&monc->mutex); in handle_poolop_reply()
584 req = __lookup_generic_req(monc, tid); in handle_poolop_reply()
590 mutex_unlock(&monc->mutex); in handle_poolop_reply()
596 mutex_unlock(&monc->mutex); in handle_poolop_reply()
611 int ceph_monc_do_poolop(struct ceph_mon_client *monc, u32 op, in ceph_monc_do_poolop() argument
642 h->fsid = monc->monmap->fsid; in ceph_monc_do_poolop()
649 err = do_generic_request(monc, req); in ceph_monc_do_poolop()
656 int ceph_monc_create_snapid(struct ceph_mon_client *monc, in ceph_monc_create_snapid() argument
659 return ceph_monc_do_poolop(monc, POOL_OP_CREATE_UNMANAGED_SNAP, in ceph_monc_create_snapid()
665 int ceph_monc_delete_snapid(struct ceph_mon_client *monc, in ceph_monc_delete_snapid() argument
668 return ceph_monc_do_poolop(monc, POOL_OP_CREATE_UNMANAGED_SNAP, in ceph_monc_delete_snapid()
676 static void __resend_generic_request(struct ceph_mon_client *monc) in __resend_generic_request() argument
681 for (p = rb_first(&monc->generic_request_tree); p; p = rb_next(p)) { in __resend_generic_request()
683 ceph_con_revoke(monc->con, req->request); in __resend_generic_request()
684 ceph_con_send(monc->con, ceph_msg_get(req->request)); in __resend_generic_request()
695 struct ceph_mon_client *monc = in delayed_work() local
699 mutex_lock(&monc->mutex); in delayed_work()
700 if (monc->hunting) { in delayed_work()
701 __close_session(monc); in delayed_work()
702 __open_session(monc); /* continue hunting */ in delayed_work()
704 ceph_con_keepalive(monc->con); in delayed_work()
706 __validate_auth(monc); in delayed_work()
708 if (monc->auth->ops->is_authenticated(monc->auth)) in delayed_work()
709 __send_subscribe(monc); in delayed_work()
711 __schedule_delayed(monc); in delayed_work()
712 mutex_unlock(&monc->mutex); in delayed_work()
719 static int build_initial_monmap(struct ceph_mon_client *monc) in build_initial_monmap() argument
721 struct ceph_options *opt = monc->client->options; in build_initial_monmap()
727 monc->monmap = kzalloc(sizeof(*monc->monmap) + in build_initial_monmap()
728 num_mon*sizeof(monc->monmap->mon_inst[0]), in build_initial_monmap()
730 if (!monc->monmap) in build_initial_monmap()
733 monc->monmap->mon_inst[i].addr = mon_addr[i]; in build_initial_monmap()
734 monc->monmap->mon_inst[i].addr.nonce = 0; in build_initial_monmap()
735 monc->monmap->mon_inst[i].name.type = in build_initial_monmap()
737 monc->monmap->mon_inst[i].name.num = cpu_to_le64(i); in build_initial_monmap()
739 monc->monmap->num_mon = num_mon; in build_initial_monmap()
740 monc->have_fsid = false; in build_initial_monmap()
744 int ceph_monc_init(struct ceph_mon_client *monc, struct ceph_client *cl) in ceph_monc_init() argument
749 memset(monc, 0, sizeof(*monc)); in ceph_monc_init()
750 monc->client = cl; in ceph_monc_init()
751 monc->monmap = NULL; in ceph_monc_init()
752 mutex_init(&monc->mutex); in ceph_monc_init()
754 err = build_initial_monmap(monc); in ceph_monc_init()
758 monc->con = NULL; in ceph_monc_init()
761 monc->auth = ceph_auth_init(cl->options->name, in ceph_monc_init()
763 if (IS_ERR(monc->auth)) in ceph_monc_init()
764 return PTR_ERR(monc->auth); in ceph_monc_init()
765 monc->auth->want_keys = in ceph_monc_init()
771 monc->m_subscribe_ack = ceph_msg_new(CEPH_MSG_MON_SUBSCRIBE_ACK, in ceph_monc_init()
774 if (!monc->m_subscribe_ack) in ceph_monc_init()
777 monc->m_subscribe = ceph_msg_new(CEPH_MSG_MON_SUBSCRIBE, 96, GFP_NOFS); in ceph_monc_init()
778 if (!monc->m_subscribe) in ceph_monc_init()
781 monc->m_auth_reply = ceph_msg_new(CEPH_MSG_AUTH_REPLY, 4096, GFP_NOFS); in ceph_monc_init()
782 if (!monc->m_auth_reply) in ceph_monc_init()
785 monc->m_auth = ceph_msg_new(CEPH_MSG_AUTH, 4096, GFP_NOFS); in ceph_monc_init()
786 monc->pending_auth = 0; in ceph_monc_init()
787 if (!monc->m_auth) in ceph_monc_init()
790 monc->cur_mon = -1; in ceph_monc_init()
791 monc->hunting = true; in ceph_monc_init()
792 monc->sub_renew_after = jiffies; in ceph_monc_init()
793 monc->sub_sent = 0; in ceph_monc_init()
795 INIT_DELAYED_WORK(&monc->delayed_work, delayed_work); in ceph_monc_init()
796 monc->generic_request_tree = RB_ROOT; in ceph_monc_init()
797 monc->num_generic_requests = 0; in ceph_monc_init()
798 monc->last_tid = 0; in ceph_monc_init()
800 monc->have_mdsmap = 0; in ceph_monc_init()
801 monc->have_osdmap = 0; in ceph_monc_init()
802 monc->want_next_osdmap = 1; in ceph_monc_init()
806 ceph_msg_put(monc->m_auth_reply); in ceph_monc_init()
808 ceph_msg_put(monc->m_subscribe); in ceph_monc_init()
810 ceph_msg_put(monc->m_subscribe_ack); in ceph_monc_init()
812 kfree(monc->monmap); in ceph_monc_init()
818 void ceph_monc_stop(struct ceph_mon_client *monc) in ceph_monc_stop() argument
821 cancel_delayed_work_sync(&monc->delayed_work); in ceph_monc_stop()
823 mutex_lock(&monc->mutex); in ceph_monc_stop()
824 __close_session(monc); in ceph_monc_stop()
825 if (monc->con) { in ceph_monc_stop()
826 monc->con->private = NULL; in ceph_monc_stop()
827 monc->con->ops->put(monc->con); in ceph_monc_stop()
828 monc->con = NULL; in ceph_monc_stop()
830 mutex_unlock(&monc->mutex); in ceph_monc_stop()
832 ceph_auth_destroy(monc->auth); in ceph_monc_stop()
834 ceph_msg_put(monc->m_auth); in ceph_monc_stop()
835 ceph_msg_put(monc->m_auth_reply); in ceph_monc_stop()
836 ceph_msg_put(monc->m_subscribe); in ceph_monc_stop()
837 ceph_msg_put(monc->m_subscribe_ack); in ceph_monc_stop()
839 kfree(monc->monmap); in ceph_monc_stop()
843 static void handle_auth_reply(struct ceph_mon_client *monc, in handle_auth_reply() argument
849 mutex_lock(&monc->mutex); in handle_auth_reply()
850 if (monc->auth->ops) in handle_auth_reply()
851 was_auth = monc->auth->ops->is_authenticated(monc->auth); in handle_auth_reply()
852 monc->pending_auth = 0; in handle_auth_reply()
853 ret = ceph_handle_auth_reply(monc->auth, msg->front.iov_base, in handle_auth_reply()
855 monc->m_auth->front.iov_base, in handle_auth_reply()
856 monc->m_auth->front_max); in handle_auth_reply()
858 monc->client->auth_err = ret; in handle_auth_reply()
859 wake_up_all(&monc->client->auth_wq); in handle_auth_reply()
861 __send_prepared_auth_request(monc, ret); in handle_auth_reply()
862 } else if (!was_auth && monc->auth->ops->is_authenticated(monc->auth)) { in handle_auth_reply()
865 monc->client->msgr->inst.name.type = CEPH_ENTITY_TYPE_CLIENT; in handle_auth_reply()
866 monc->client->msgr->inst.name.num = in handle_auth_reply()
867 cpu_to_le64(monc->auth->global_id); in handle_auth_reply()
869 __send_subscribe(monc); in handle_auth_reply()
870 __resend_generic_request(monc); in handle_auth_reply()
872 mutex_unlock(&monc->mutex); in handle_auth_reply()
875 static int __validate_auth(struct ceph_mon_client *monc) in __validate_auth() argument
879 if (monc->pending_auth) in __validate_auth()
882 ret = ceph_build_auth(monc->auth, monc->m_auth->front.iov_base, in __validate_auth()
883 monc->m_auth->front_max); in __validate_auth()
886 __send_prepared_auth_request(monc, ret); in __validate_auth()
890 int ceph_monc_validate_auth(struct ceph_mon_client *monc) in ceph_monc_validate_auth() argument
894 mutex_lock(&monc->mutex); in ceph_monc_validate_auth()
895 ret = __validate_auth(monc); in ceph_monc_validate_auth()
896 mutex_unlock(&monc->mutex); in ceph_monc_validate_auth()
906 struct ceph_mon_client *monc = con->private; in dispatch() local
909 if (!monc) in dispatch()
914 handle_auth_reply(monc, msg); in dispatch()
918 handle_subscribe_ack(monc, msg); in dispatch()
922 handle_statfs_reply(monc, msg); in dispatch()
926 handle_poolop_reply(monc, msg); in dispatch()
930 ceph_monc_handle_map(monc, msg); in dispatch()
934 ceph_osdc_handle_map(&monc->client->osdc, msg); in dispatch()
939 if (monc->client->extra_mon_dispatch && in dispatch()
940 monc->client->extra_mon_dispatch(monc->client, msg) == 0) in dispatch()
956 struct ceph_mon_client *monc = con->private; in mon_alloc_msg() local
965 m = ceph_msg_get(monc->m_subscribe_ack); in mon_alloc_msg()
971 m = ceph_msg_get(monc->m_auth_reply); in mon_alloc_msg()
993 struct ceph_mon_client *monc = con->private; in mon_fault() local
995 if (!monc) in mon_fault()
999 mutex_lock(&monc->mutex); in mon_fault()
1003 if (monc->con && !monc->hunting) in mon_fault()
1005 "hunting for new mon\n", monc->cur_mon, in mon_fault()
1006 ceph_pr_addr(&monc->con->peer_addr.in_addr)); in mon_fault()
1008 __close_session(monc); in mon_fault()
1009 if (!monc->hunting) { in mon_fault()
1011 monc->hunting = true; in mon_fault()
1012 __open_session(monc); in mon_fault()
1015 __schedule_delayed(monc); in mon_fault()
1018 mutex_unlock(&monc->mutex); in mon_fault()