• Home
  • Raw
  • Download

Lines Matching +full:dout +full:- +full:default +full:- +full:2

1 // SPDX-License-Identifier: GPL-2.0
24 * of cmon daemons use a modified version of the Paxos part-time parliament
45 int i, err = -EINVAL; in ceph_monmap_decode()
53 dout("monmap_decode %p %p len %d (%d)\n", p, end, len, (int)(end-p)); in ceph_monmap_decode()
56 ceph_decode_need(&p, end, sizeof(fsid) + 2*sizeof(u32), bad); in ceph_monmap_decode()
66 return ERR_PTR(-ENOMEM); in ceph_monmap_decode()
67 m->fsid = fsid; in ceph_monmap_decode()
68 m->epoch = epoch; in ceph_monmap_decode()
69 m->num_mon = num_mon; in ceph_monmap_decode()
71 struct ceph_entity_inst *inst = &m->mon_inst[i]; in ceph_monmap_decode()
74 ceph_decode_copy_safe(&p, end, &inst->name, in ceph_monmap_decode()
75 sizeof(inst->name), bad); in ceph_monmap_decode()
76 err = ceph_decode_entity_addr(&p, end, &inst->addr); in ceph_monmap_decode()
80 dout("monmap_decode epoch %d, num_mon %d\n", m->epoch, in ceph_monmap_decode()
81 m->num_mon); in ceph_monmap_decode()
82 for (i = 0; i < m->num_mon; i++) in ceph_monmap_decode()
83 dout("monmap_decode mon%d is %s\n", i, in ceph_monmap_decode()
84 ceph_pr_addr(&m->mon_inst[i].addr)); in ceph_monmap_decode()
87 dout("monmap_decode failed with %d\n", err); in ceph_monmap_decode()
99 for (i = 0; i < m->num_mon; i++) { in ceph_monmap_contains()
100 if (ceph_addr_equal_no_type(addr, &m->mon_inst[i].addr)) in ceph_monmap_contains()
112 monc->pending_auth = 1; in __send_prepared_auth_request()
113 monc->m_auth->front.iov_len = len; in __send_prepared_auth_request()
114 monc->m_auth->hdr.front_len = cpu_to_le32(len); in __send_prepared_auth_request()
115 ceph_msg_revoke(monc->m_auth); in __send_prepared_auth_request()
116 ceph_msg_get(monc->m_auth); /* keep our ref */ in __send_prepared_auth_request()
117 ceph_con_send(&monc->con, monc->m_auth); in __send_prepared_auth_request()
125 dout("__close_session closing mon%d\n", monc->cur_mon); in __close_session()
126 ceph_msg_revoke(monc->m_auth); in __close_session()
127 ceph_msg_revoke_incoming(monc->m_auth_reply); in __close_session()
128 ceph_msg_revoke(monc->m_subscribe); in __close_session()
129 ceph_msg_revoke_incoming(monc->m_subscribe_ack); in __close_session()
130 ceph_con_close(&monc->con); in __close_session()
132 monc->pending_auth = 0; in __close_session()
133 ceph_auth_reset(monc->auth); in __close_session()
142 int old_mon = monc->cur_mon; in pick_new_mon()
144 BUG_ON(monc->monmap->num_mon < 1); in pick_new_mon()
146 if (monc->monmap->num_mon == 1) { in pick_new_mon()
147 monc->cur_mon = 0; in pick_new_mon()
149 int max = monc->monmap->num_mon; in pick_new_mon()
150 int o = -1; in pick_new_mon()
153 if (monc->cur_mon >= 0) { in pick_new_mon()
154 if (monc->cur_mon < monc->monmap->num_mon) in pick_new_mon()
155 o = monc->cur_mon; in pick_new_mon()
157 max--; in pick_new_mon()
164 monc->cur_mon = n; in pick_new_mon()
167 dout("%s mon%d -> mon%d out of %d mons\n", __func__, old_mon, in pick_new_mon()
168 monc->cur_mon, monc->monmap->num_mon); in pick_new_mon()
180 monc->hunting = true; in __open_session()
181 if (monc->had_a_connection) { in __open_session()
182 monc->hunt_mult *= CEPH_MONC_HUNT_BACKOFF; in __open_session()
183 if (monc->hunt_mult > CEPH_MONC_HUNT_MAX_MULT) in __open_session()
184 monc->hunt_mult = CEPH_MONC_HUNT_MAX_MULT; in __open_session()
187 monc->sub_renew_after = jiffies; /* i.e., expired */ in __open_session()
188 monc->sub_renew_sent = 0; in __open_session()
190 dout("%s opening mon%d\n", __func__, monc->cur_mon); in __open_session()
191 ceph_con_open(&monc->con, CEPH_ENTITY_TYPE_MON, monc->cur_mon, in __open_session()
192 &monc->monmap->mon_inst[monc->cur_mon].addr); in __open_session()
198 ceph_con_keepalive(&monc->con); in __open_session()
201 ret = ceph_auth_build_hello(monc->auth, in __open_session()
202 monc->m_auth->front.iov_base, in __open_session()
203 monc->m_auth->front_alloc_len); in __open_session()
210 if (!monc->hunting) in reopen_session()
212 monc->cur_mon, ceph_pr_addr(&monc->con.peer_addr)); in reopen_session()
220 mutex_lock(&monc->mutex); in ceph_monc_reopen_session()
222 mutex_unlock(&monc->mutex); in ceph_monc_reopen_session()
227 monc->hunt_mult /= 2; /* reduce by 50% */ in un_backoff()
228 if (monc->hunt_mult < 1) in un_backoff()
229 monc->hunt_mult = 1; in un_backoff()
230 dout("%s hunt_mult now %d\n", __func__, monc->hunt_mult); in un_backoff()
240 if (monc->hunting) in __schedule_delayed()
241 delay = CEPH_MONC_HUNT_INTERVAL * monc->hunt_mult; in __schedule_delayed()
245 dout("__schedule_delayed after %lu\n", delay); in __schedule_delayed()
246 mod_delayed_work(system_wq, &monc->delayed_work, in __schedule_delayed()
259 * monc->subs.
263 struct ceph_msg *msg = monc->m_subscribe; in __send_subscribe()
264 void *p = msg->front.iov_base; in __send_subscribe()
265 void *const end = p + msg->front_alloc_len; in __send_subscribe()
269 dout("%s sent %lu\n", __func__, monc->sub_renew_sent); in __send_subscribe()
271 BUG_ON(monc->cur_mon < 0); in __send_subscribe()
273 if (!monc->sub_renew_sent) in __send_subscribe()
274 monc->sub_renew_sent = jiffies | 1; /* never 0 */ in __send_subscribe()
276 msg->hdr.version = cpu_to_le16(2); in __send_subscribe()
278 for (i = 0; i < ARRAY_SIZE(monc->subs); i++) { in __send_subscribe()
279 if (monc->subs[i].want) in __send_subscribe()
284 for (i = 0; i < ARRAY_SIZE(monc->subs); i++) { in __send_subscribe()
288 if (!monc->subs[i].want) in __send_subscribe()
293 monc->fs_cluster_id != CEPH_FS_CLUSTER_ID_NONE) in __send_subscribe()
294 len += sprintf(buf + len, ".%d", monc->fs_cluster_id); in __send_subscribe()
296 dout("%s %s start %llu flags 0x%x\n", __func__, buf, in __send_subscribe()
297 le64_to_cpu(monc->subs[i].item.start), in __send_subscribe()
298 monc->subs[i].item.flags); in __send_subscribe()
300 memcpy(p, &monc->subs[i].item, sizeof(monc->subs[i].item)); in __send_subscribe()
301 p += sizeof(monc->subs[i].item); in __send_subscribe()
305 msg->front.iov_len = p - msg->front.iov_base; in __send_subscribe()
306 msg->hdr.front_len = cpu_to_le32(msg->front.iov_len); in __send_subscribe()
308 ceph_con_send(&monc->con, ceph_msg_get(msg)); in __send_subscribe()
315 struct ceph_mon_subscribe_ack *h = msg->front.iov_base; in handle_subscribe_ack()
317 if (msg->front.iov_len < sizeof(*h)) in handle_subscribe_ack()
319 seconds = le32_to_cpu(h->duration); in handle_subscribe_ack()
321 mutex_lock(&monc->mutex); in handle_subscribe_ack()
322 if (monc->sub_renew_sent) { in handle_subscribe_ack()
325 * MONs -- see delayed_work(). in handle_subscribe_ack()
327 monc->sub_renew_after = monc->sub_renew_sent + in handle_subscribe_ack()
328 (seconds >> 1) * HZ - 1; in handle_subscribe_ack()
329 dout("%s sent %lu duration %d renew after %lu\n", __func__, in handle_subscribe_ack()
330 monc->sub_renew_sent, seconds, monc->sub_renew_after); in handle_subscribe_ack()
331 monc->sub_renew_sent = 0; in handle_subscribe_ack()
333 dout("%s sent %lu renew after %lu, ignoring\n", __func__, in handle_subscribe_ack()
334 monc->sub_renew_sent, monc->sub_renew_after); in handle_subscribe_ack()
336 mutex_unlock(&monc->mutex); in handle_subscribe_ack()
339 pr_err("got corrupt subscribe-ack msg\n"); in handle_subscribe_ack()
355 dout("%s %s epoch %u continuous %d\n", __func__, ceph_sub_str[sub], in __ceph_monc_want_map()
358 if (monc->subs[sub].want && in __ceph_monc_want_map()
359 monc->subs[sub].item.start == start && in __ceph_monc_want_map()
360 monc->subs[sub].item.flags == flags) in __ceph_monc_want_map()
363 monc->subs[sub].item.start = start; in __ceph_monc_want_map()
364 monc->subs[sub].item.flags = flags; in __ceph_monc_want_map()
365 monc->subs[sub].want = true; in __ceph_monc_want_map()
375 mutex_lock(&monc->mutex); in ceph_monc_want_map()
377 mutex_unlock(&monc->mutex); in ceph_monc_want_map()
391 dout("%s %s epoch %u\n", __func__, ceph_sub_str[sub], epoch); in __ceph_monc_got_map()
393 if (monc->subs[sub].want) { in __ceph_monc_got_map()
394 if (monc->subs[sub].item.flags & CEPH_SUBSCRIBE_ONETIME) in __ceph_monc_got_map()
395 monc->subs[sub].want = false; in __ceph_monc_got_map()
397 monc->subs[sub].item.start = cpu_to_le64(epoch + 1); in __ceph_monc_got_map()
400 monc->subs[sub].have = epoch; in __ceph_monc_got_map()
405 mutex_lock(&monc->mutex); in ceph_monc_got_map()
407 mutex_unlock(&monc->mutex); in ceph_monc_got_map()
413 mutex_lock(&monc->mutex); in ceph_monc_renew_subs()
415 mutex_unlock(&monc->mutex); in ceph_monc_renew_subs()
431 mutex_lock(&monc->mutex); in ceph_monc_wait_osdmap()
432 while (monc->subs[CEPH_SUB_OSDMAP].have < epoch) { in ceph_monc_wait_osdmap()
433 mutex_unlock(&monc->mutex); in ceph_monc_wait_osdmap()
436 return -ETIMEDOUT; in ceph_monc_wait_osdmap()
438 ret = wait_event_interruptible_timeout(monc->client->auth_wq, in ceph_monc_wait_osdmap()
439 monc->subs[CEPH_SUB_OSDMAP].have >= epoch, in ceph_monc_wait_osdmap()
444 mutex_lock(&monc->mutex); in ceph_monc_wait_osdmap()
447 mutex_unlock(&monc->mutex); in ceph_monc_wait_osdmap()
458 mutex_lock(&monc->mutex); in ceph_monc_open_session()
463 mutex_unlock(&monc->mutex); in ceph_monc_open_session()
471 struct ceph_client *client = monc->client; in ceph_monc_handle_map()
475 mutex_lock(&monc->mutex); in ceph_monc_handle_map()
477 dout("handle_monmap\n"); in ceph_monc_handle_map()
478 p = msg->front.iov_base; in ceph_monc_handle_map()
479 end = p + msg->front.iov_len; in ceph_monc_handle_map()
489 if (ceph_check_fsid(client, &monmap->fsid) < 0) { in ceph_monc_handle_map()
494 kfree(monc->monmap); in ceph_monc_handle_map()
495 monc->monmap = monmap; in ceph_monc_handle_map()
497 __ceph_monc_got_map(monc, CEPH_SUB_MONMAP, monc->monmap->epoch); in ceph_monc_handle_map()
498 client->have_fsid = true; in ceph_monc_handle_map()
501 mutex_unlock(&monc->mutex); in ceph_monc_handle_map()
502 wake_up_all(&client->auth_wq); in ceph_monc_handle_map()
515 dout("%s greq %p request %p reply %p\n", __func__, req, req->request, in DEFINE_RB_FUNCS()
516 req->reply); in DEFINE_RB_FUNCS()
517 WARN_ON(!RB_EMPTY_NODE(&req->node)); in DEFINE_RB_FUNCS()
519 if (req->reply) in DEFINE_RB_FUNCS()
520 ceph_msg_put(req->reply); in DEFINE_RB_FUNCS()
521 if (req->request) in DEFINE_RB_FUNCS()
522 ceph_msg_put(req->request); in DEFINE_RB_FUNCS()
530 kref_put(&req->kref, release_generic_request); in put_generic_request()
535 kref_get(&req->kref); in get_generic_request()
547 req->monc = monc; in alloc_generic_request()
548 kref_init(&req->kref); in alloc_generic_request()
549 RB_CLEAR_NODE(&req->node); in alloc_generic_request()
550 init_completion(&req->completion); in alloc_generic_request()
552 dout("%s greq %p\n", __func__, req); in alloc_generic_request()
558 struct ceph_mon_client *monc = req->monc; in register_generic_request()
560 WARN_ON(req->tid); in register_generic_request()
563 req->tid = ++monc->last_tid; in register_generic_request()
564 insert_generic_request(&monc->generic_request_tree, req); in register_generic_request()
570 WARN_ON(!req->tid); in send_generic_request()
572 dout("%s greq %p tid %llu\n", __func__, req, req->tid); in send_generic_request()
573 req->request->hdr.tid = cpu_to_le64(req->tid); in send_generic_request()
574 ceph_con_send(&monc->con, ceph_msg_get(req->request)); in send_generic_request()
579 struct ceph_mon_client *monc = req->monc; in __finish_generic_request()
581 dout("%s greq %p tid %llu\n", __func__, req, req->tid); in __finish_generic_request()
582 erase_generic_request(&monc->generic_request_tree, req); in __finish_generic_request()
584 ceph_msg_revoke(req->request); in __finish_generic_request()
585 ceph_msg_revoke_incoming(req->reply); in __finish_generic_request()
596 if (req->complete_cb) in complete_generic_request()
597 req->complete_cb(req); in complete_generic_request()
599 complete_all(&req->completion); in complete_generic_request()
605 struct ceph_mon_client *monc = req->monc; in cancel_generic_request()
608 dout("%s greq %p tid %llu\n", __func__, req, req->tid); in cancel_generic_request()
610 mutex_lock(&monc->mutex); in cancel_generic_request()
611 lookup_req = lookup_generic_request(&monc->generic_request_tree, in cancel_generic_request()
612 req->tid); in cancel_generic_request()
618 mutex_unlock(&monc->mutex); in cancel_generic_request()
625 dout("%s greq %p tid %llu\n", __func__, req, req->tid); in wait_generic_request()
626 ret = wait_for_completion_interruptible(&req->completion); in wait_generic_request()
630 ret = req->result; /* completed */ in wait_generic_request()
639 struct ceph_mon_client *monc = con->private; in get_generic_reply()
641 u64 tid = le64_to_cpu(hdr->tid); in get_generic_reply()
644 mutex_lock(&monc->mutex); in get_generic_reply()
645 req = lookup_generic_request(&monc->generic_request_tree, tid); in get_generic_reply()
647 dout("get_generic_reply %lld dne\n", tid); in get_generic_reply()
651 dout("get_generic_reply %lld got %p\n", tid, req->reply); in get_generic_reply()
653 m = ceph_msg_get(req->reply); in get_generic_reply()
660 mutex_unlock(&monc->mutex); in get_generic_reply()
671 struct ceph_mon_statfs_reply *reply = msg->front.iov_base; in handle_statfs_reply()
672 u64 tid = le64_to_cpu(msg->hdr.tid); in handle_statfs_reply()
674 dout("%s msg %p tid %llu\n", __func__, msg, tid); in handle_statfs_reply()
676 if (msg->front.iov_len != sizeof(*reply)) in handle_statfs_reply()
679 mutex_lock(&monc->mutex); in handle_statfs_reply()
680 req = lookup_generic_request(&monc->generic_request_tree, tid); in handle_statfs_reply()
682 mutex_unlock(&monc->mutex); in handle_statfs_reply()
686 req->result = 0; in handle_statfs_reply()
687 *req->u.st = reply->st; /* struct */ in handle_statfs_reply()
689 mutex_unlock(&monc->mutex); in handle_statfs_reply()
707 int ret = -ENOMEM; in ceph_monc_do_statfs()
713 req->request = ceph_msg_new(CEPH_MSG_STATFS, sizeof(*h), GFP_NOFS, in ceph_monc_do_statfs()
715 if (!req->request) in ceph_monc_do_statfs()
718 req->reply = ceph_msg_new(CEPH_MSG_STATFS_REPLY, 64, GFP_NOFS, true); in ceph_monc_do_statfs()
719 if (!req->reply) in ceph_monc_do_statfs()
722 req->u.st = buf; in ceph_monc_do_statfs()
723 req->request->hdr.version = cpu_to_le16(2); in ceph_monc_do_statfs()
725 mutex_lock(&monc->mutex); in ceph_monc_do_statfs()
728 h = req->request->front.iov_base; in ceph_monc_do_statfs()
729 h->monhdr.have_version = 0; in ceph_monc_do_statfs()
730 h->monhdr.session_mon = cpu_to_le16(-1); in ceph_monc_do_statfs()
731 h->monhdr.session_mon_tid = 0; in ceph_monc_do_statfs()
732 h->fsid = monc->monmap->fsid; in ceph_monc_do_statfs()
733 h->contains_data_pool = (data_pool != CEPH_NOPOOL); in ceph_monc_do_statfs()
734 h->data_pool = cpu_to_le64(data_pool); in ceph_monc_do_statfs()
736 mutex_unlock(&monc->mutex); in ceph_monc_do_statfs()
749 u64 tid = le64_to_cpu(msg->hdr.tid); in handle_get_version_reply()
750 void *p = msg->front.iov_base; in handle_get_version_reply()
751 void *end = p + msg->front_alloc_len; in handle_get_version_reply()
754 dout("%s msg %p tid %llu\n", __func__, msg, tid); in handle_get_version_reply()
756 ceph_decode_need(&p, end, 2*sizeof(u64), bad); in handle_get_version_reply()
761 mutex_lock(&monc->mutex); in handle_get_version_reply()
762 req = lookup_generic_request(&monc->generic_request_tree, handle); in handle_get_version_reply()
764 mutex_unlock(&monc->mutex); in handle_get_version_reply()
768 req->result = 0; in handle_get_version_reply()
769 req->u.newest = ceph_decode_64(&p); in handle_get_version_reply()
771 mutex_unlock(&monc->mutex); in handle_get_version_reply()
791 req->request = ceph_msg_new(CEPH_MSG_MON_GET_VERSION, in __ceph_monc_get_version()
794 if (!req->request) in __ceph_monc_get_version()
797 req->reply = ceph_msg_new(CEPH_MSG_MON_GET_VERSION_REPLY, 32, GFP_NOIO, in __ceph_monc_get_version()
799 if (!req->reply) in __ceph_monc_get_version()
802 req->complete_cb = cb; in __ceph_monc_get_version()
803 req->private_data = private_data; in __ceph_monc_get_version()
805 mutex_lock(&monc->mutex); in __ceph_monc_get_version()
808 void *p = req->request->front.iov_base; in __ceph_monc_get_version()
809 void *const end = p + req->request->front_alloc_len; in __ceph_monc_get_version()
811 ceph_encode_64(&p, req->tid); /* handle */ in __ceph_monc_get_version()
816 mutex_unlock(&monc->mutex); in __ceph_monc_get_version()
822 return ERR_PTR(-ENOMEM); in __ceph_monc_get_version()
842 *newest = req->u.newest; in ceph_monc_get_version()
872 void *p = msg->front.iov_base; in handle_command_ack()
873 void *const end = p + msg->front_alloc_len; in handle_command_ack()
874 u64 tid = le64_to_cpu(msg->hdr.tid); in handle_command_ack()
876 dout("%s msg %p tid %llu\n", __func__, msg, tid); in handle_command_ack()
882 mutex_lock(&monc->mutex); in handle_command_ack()
883 req = lookup_generic_request(&monc->generic_request_tree, tid); in handle_command_ack()
885 mutex_unlock(&monc->mutex); in handle_command_ack()
889 req->result = ceph_decode_32(&p); in handle_command_ack()
891 mutex_unlock(&monc->mutex); in handle_command_ack()
901 static __printf(2, 0)
907 int ret = -ENOMEM; in do_mon_command_vargs()
914 req->request = ceph_msg_new(CEPH_MSG_MON_COMMAND, 256, GFP_NOIO, true); in do_mon_command_vargs()
915 if (!req->request) in do_mon_command_vargs()
918 req->reply = ceph_msg_new(CEPH_MSG_MON_COMMAND_ACK, 512, GFP_NOIO, in do_mon_command_vargs()
920 if (!req->reply) in do_mon_command_vargs()
923 mutex_lock(&monc->mutex); in do_mon_command_vargs()
925 h = req->request->front.iov_base; in do_mon_command_vargs()
926 h->monhdr.have_version = 0; in do_mon_command_vargs()
927 h->monhdr.session_mon = cpu_to_le16(-1); in do_mon_command_vargs()
928 h->monhdr.session_mon_tid = 0; in do_mon_command_vargs()
929 h->fsid = monc->monmap->fsid; in do_mon_command_vargs()
930 h->num_strs = cpu_to_le32(1); in do_mon_command_vargs()
931 len = vsprintf(h->str, fmt, ap); in do_mon_command_vargs()
932 h->str_len = cpu_to_le32(len); in do_mon_command_vargs()
934 mutex_unlock(&monc->mutex); in do_mon_command_vargs()
942 static __printf(2, 3)
963 &client_addr->in_addr, in ceph_monc_blocklist_add()
964 le32_to_cpu(client_addr->nonce)); in ceph_monc_blocklist_add()
965 if (ret == -EINVAL) { in ceph_monc_blocklist_add()
968 * Try the legacy command -- it is exactly the same except in ceph_monc_blocklist_add()
975 &client_addr->in_addr, in ceph_monc_blocklist_add()
976 le32_to_cpu(client_addr->nonce)); in ceph_monc_blocklist_add()
987 return ceph_wait_for_latest_osdmap(monc->client, 0); in ceph_monc_blocklist_add()
999 for (p = rb_first(&monc->generic_request_tree); p; p = rb_next(p)) { in __resend_generic_request()
1001 ceph_msg_revoke(req->request); in __resend_generic_request()
1002 ceph_msg_revoke_incoming(req->reply); in __resend_generic_request()
1003 ceph_con_send(&monc->con, ceph_msg_get(req->request)); in __resend_generic_request()
1017 mutex_lock(&monc->mutex); in delayed_work()
1018 dout("%s mon%d\n", __func__, monc->cur_mon); in delayed_work()
1019 if (monc->cur_mon < 0) { in delayed_work()
1023 if (monc->hunting) { in delayed_work()
1024 dout("%s continuing hunt\n", __func__); in delayed_work()
1027 int is_auth = ceph_auth_is_authenticated(monc->auth); in delayed_work()
1029 dout("%s is_authed %d\n", __func__, is_auth); in delayed_work()
1030 if (ceph_con_keepalive_expired(&monc->con, in delayed_work()
1032 dout("monc keepalive timeout\n"); in delayed_work()
1037 if (!monc->hunting) { in delayed_work()
1038 ceph_con_keepalive(&monc->con); in delayed_work()
1044 !(monc->con.peer_features & CEPH_FEATURE_MON_STATEFUL_SUB)) { in delayed_work()
1047 dout("%s renew subs? now %lu renew after %lu\n", in delayed_work()
1048 __func__, now, monc->sub_renew_after); in delayed_work()
1049 if (time_after_eq(now, monc->sub_renew_after)) in delayed_work()
1056 mutex_unlock(&monc->mutex); in delayed_work()
1061 * provided by mount(2).
1065 struct ceph_options *opt = monc->client->options; in build_initial_monmap()
1066 struct ceph_entity_addr *mon_addr = opt->mon_addr; in build_initial_monmap()
1067 int num_mon = opt->num_mon; in build_initial_monmap()
1071 monc->monmap = kzalloc(struct_size(monc->monmap, mon_inst, num_mon), in build_initial_monmap()
1073 if (!monc->monmap) in build_initial_monmap()
1074 return -ENOMEM; in build_initial_monmap()
1076 monc->monmap->mon_inst[i].addr = mon_addr[i]; in build_initial_monmap()
1077 monc->monmap->mon_inst[i].addr.nonce = 0; in build_initial_monmap()
1078 monc->monmap->mon_inst[i].name.type = in build_initial_monmap()
1080 monc->monmap->mon_inst[i].name.num = cpu_to_le64(i); in build_initial_monmap()
1082 monc->monmap->num_mon = num_mon; in build_initial_monmap()
1090 dout("init\n"); in ceph_monc_init()
1092 monc->client = cl; in ceph_monc_init()
1093 monc->monmap = NULL; in ceph_monc_init()
1094 mutex_init(&monc->mutex); in ceph_monc_init()
1102 monc->auth = ceph_auth_init(cl->options->name, in ceph_monc_init()
1103 cl->options->key); in ceph_monc_init()
1104 if (IS_ERR(monc->auth)) { in ceph_monc_init()
1105 err = PTR_ERR(monc->auth); in ceph_monc_init()
1108 monc->auth->want_keys = in ceph_monc_init()
1113 err = -ENOMEM; in ceph_monc_init()
1114 monc->m_subscribe_ack = ceph_msg_new(CEPH_MSG_MON_SUBSCRIBE_ACK, in ceph_monc_init()
1117 if (!monc->m_subscribe_ack) in ceph_monc_init()
1120 monc->m_subscribe = ceph_msg_new(CEPH_MSG_MON_SUBSCRIBE, 128, in ceph_monc_init()
1122 if (!monc->m_subscribe) in ceph_monc_init()
1125 monc->m_auth_reply = ceph_msg_new(CEPH_MSG_AUTH_REPLY, 4096, in ceph_monc_init()
1127 if (!monc->m_auth_reply) in ceph_monc_init()
1130 monc->m_auth = ceph_msg_new(CEPH_MSG_AUTH, 4096, GFP_KERNEL, true); in ceph_monc_init()
1131 monc->pending_auth = 0; in ceph_monc_init()
1132 if (!monc->m_auth) in ceph_monc_init()
1135 ceph_con_init(&monc->con, monc, &mon_con_ops, in ceph_monc_init()
1136 &monc->client->msgr); in ceph_monc_init()
1138 monc->cur_mon = -1; in ceph_monc_init()
1139 monc->had_a_connection = false; in ceph_monc_init()
1140 monc->hunt_mult = 1; in ceph_monc_init()
1142 INIT_DELAYED_WORK(&monc->delayed_work, delayed_work); in ceph_monc_init()
1143 monc->generic_request_tree = RB_ROOT; in ceph_monc_init()
1144 monc->last_tid = 0; in ceph_monc_init()
1146 monc->fs_cluster_id = CEPH_FS_CLUSTER_ID_NONE; in ceph_monc_init()
1151 ceph_msg_put(monc->m_auth_reply); in ceph_monc_init()
1153 ceph_msg_put(monc->m_subscribe); in ceph_monc_init()
1155 ceph_msg_put(monc->m_subscribe_ack); in ceph_monc_init()
1157 ceph_auth_destroy(monc->auth); in ceph_monc_init()
1159 kfree(monc->monmap); in ceph_monc_init()
1167 dout("stop\n"); in ceph_monc_stop()
1169 mutex_lock(&monc->mutex); in ceph_monc_stop()
1171 monc->hunting = false; in ceph_monc_stop()
1172 monc->cur_mon = -1; in ceph_monc_stop()
1173 mutex_unlock(&monc->mutex); in ceph_monc_stop()
1175 cancel_delayed_work_sync(&monc->delayed_work); in ceph_monc_stop()
1179 * - any work that references our embedded con is finished. in ceph_monc_stop()
1180 * - any osd_client or other work that may reference an authorizer in ceph_monc_stop()
1185 ceph_auth_destroy(monc->auth); in ceph_monc_stop()
1187 WARN_ON(!RB_EMPTY_ROOT(&monc->generic_request_tree)); in ceph_monc_stop()
1189 ceph_msg_put(monc->m_auth); in ceph_monc_stop()
1190 ceph_msg_put(monc->m_auth_reply); in ceph_monc_stop()
1191 ceph_msg_put(monc->m_subscribe); in ceph_monc_stop()
1192 ceph_msg_put(monc->m_subscribe_ack); in ceph_monc_stop()
1194 kfree(monc->monmap); in ceph_monc_stop()
1200 if (monc->hunting) { in finish_hunting()
1201 dout("%s found mon%d\n", __func__, monc->cur_mon); in finish_hunting()
1202 monc->hunting = false; in finish_hunting()
1203 monc->had_a_connection = true; in finish_hunting()
1215 mutex_lock(&monc->mutex); in handle_auth_reply()
1216 was_auth = ceph_auth_is_authenticated(monc->auth); in handle_auth_reply()
1217 monc->pending_auth = 0; in handle_auth_reply()
1218 ret = ceph_handle_auth_reply(monc->auth, msg->front.iov_base, in handle_auth_reply()
1219 msg->front.iov_len, in handle_auth_reply()
1220 monc->m_auth->front.iov_base, in handle_auth_reply()
1221 monc->m_auth->front_alloc_len); in handle_auth_reply()
1230 monc->client->auth_err = ret; in handle_auth_reply()
1231 } else if (!was_auth && ceph_auth_is_authenticated(monc->auth)) { in handle_auth_reply()
1232 dout("authenticated, starting session\n"); in handle_auth_reply()
1234 monc->client->msgr.inst.name.type = CEPH_ENTITY_TYPE_CLIENT; in handle_auth_reply()
1235 monc->client->msgr.inst.name.num = in handle_auth_reply()
1236 cpu_to_le64(monc->auth->global_id); in handle_auth_reply()
1241 pr_info("mon%d %s session established\n", monc->cur_mon, in handle_auth_reply()
1242 ceph_pr_addr(&monc->con.peer_addr)); in handle_auth_reply()
1246 mutex_unlock(&monc->mutex); in handle_auth_reply()
1247 if (monc->client->auth_err < 0) in handle_auth_reply()
1248 wake_up_all(&monc->client->auth_wq); in handle_auth_reply()
1255 if (monc->pending_auth) in __validate_auth()
1258 ret = ceph_build_auth(monc->auth, monc->m_auth->front.iov_base, in __validate_auth()
1259 monc->m_auth->front_alloc_len); in __validate_auth()
1270 mutex_lock(&monc->mutex); in ceph_monc_validate_auth()
1272 mutex_unlock(&monc->mutex); in ceph_monc_validate_auth()
1282 struct ceph_mon_client *monc = con->private; in dispatch()
1283 int type = le16_to_cpu(msg->hdr.type); in dispatch()
1311 ceph_osdc_handle_map(&monc->client->osdc, msg); in dispatch()
1314 default: in dispatch()
1316 if (monc->client->extra_mon_dispatch && in dispatch()
1317 monc->client->extra_mon_dispatch(monc->client, msg) == 0) in dispatch()
1333 struct ceph_mon_client *monc = con->private; in mon_alloc_msg()
1334 int type = le16_to_cpu(hdr->type); in mon_alloc_msg()
1335 int front_len = le32_to_cpu(hdr->front_len); in mon_alloc_msg()
1342 m = ceph_msg_get(monc->m_subscribe_ack); in mon_alloc_msg()
1348 m = ceph_msg_get(monc->m_auth_reply); in mon_alloc_msg()
1351 if (le64_to_cpu(hdr->tid) != 0) in mon_alloc_msg()
1356 * request had a non-zero tid. Work around this weirdness in mon_alloc_msg()
1366 return NULL; /* ENOMEM--return skip == 0 */ in mon_alloc_msg()
1373 } else if (front_len > m->front_alloc_len) { in mon_alloc_msg()
1375 front_len, m->front_alloc_len, in mon_alloc_msg()
1376 (unsigned int)con->peer_name.type, in mon_alloc_msg()
1377 le64_to_cpu(con->peer_name.num)); in mon_alloc_msg()
1391 struct ceph_mon_client *monc = con->private; in mon_fault()
1393 mutex_lock(&monc->mutex); in mon_fault()
1394 dout("%s mon%d\n", __func__, monc->cur_mon); in mon_fault()
1395 if (monc->cur_mon >= 0) { in mon_fault()
1396 if (!monc->hunting) { in mon_fault()
1397 dout("%s hunting for new mon\n", __func__); in mon_fault()
1401 dout("%s already hunting\n", __func__); in mon_fault()
1404 mutex_unlock(&monc->mutex); in mon_fault()