Lines Matching +full:front +full:- +full:end
1 // SPDX-License-Identifier: GPL-2.0
24 * of cmon daemons use a modified version of the Paxos part-time parliament
39 static int decode_mon_info(void **p, void *end, bool msgr2, in decode_mon_info() argument
47 ret = ceph_start_decoding(p, end, 1, "mon_info_t", &struct_v, in decode_mon_info()
53 ceph_decode_skip_string(p, end, e_inval); /* skip mon name */ in decode_mon_info()
54 ret = ceph_decode_entity_addrvec(p, end, msgr2, addr); in decode_mon_info()
62 return -EINVAL; in decode_mon_info()
70 static struct ceph_monmap *ceph_monmap_decode(void **p, void *end, bool msgr2) in ceph_monmap_decode() argument
82 ceph_decode_32_safe(p, end, blob_len, e_inval); in ceph_monmap_decode()
83 ceph_decode_need(p, end, blob_len, e_inval); in ceph_monmap_decode()
85 ret = ceph_start_decoding(p, end, 6, "monmap", &struct_v, &struct_len); in ceph_monmap_decode()
90 ceph_decode_copy_safe(p, end, &fsid, sizeof(fsid), e_inval); in ceph_monmap_decode()
91 ceph_decode_32_safe(p, end, epoch, e_inval); in ceph_monmap_decode()
99 ret = ceph_start_decoding(p, end, 1, "mon_feature_t", in ceph_monmap_decode()
106 ret = ceph_start_decoding(p, end, 1, "mon_feature_t", in ceph_monmap_decode()
113 ceph_decode_32_safe(p, end, num_mon, e_inval); in ceph_monmap_decode()
122 ret = -ENOMEM; in ceph_monmap_decode()
125 monmap->fsid = fsid; in ceph_monmap_decode()
126 monmap->epoch = epoch; in ceph_monmap_decode()
127 monmap->num_mon = num_mon; in ceph_monmap_decode()
131 struct ceph_entity_inst *inst = &monmap->mon_inst[i]; in ceph_monmap_decode()
133 ceph_decode_skip_string(p, end, e_inval); /* skip mon name */ in ceph_monmap_decode()
134 inst->name.type = CEPH_ENTITY_TYPE_MON; in ceph_monmap_decode()
135 inst->name.num = cpu_to_le64(i); in ceph_monmap_decode()
138 ret = decode_mon_info(p, end, msgr2, &inst->addr); in ceph_monmap_decode()
140 ret = ceph_decode_entity_addr(p, end, &inst->addr); in ceph_monmap_decode()
145 ceph_pr_addr(&inst->addr)); in ceph_monmap_decode()
151 ret = -EINVAL; in ceph_monmap_decode()
164 for (i = 0; i < m->num_mon; i++) { in ceph_monmap_contains()
165 if (ceph_addr_equal_no_type(addr, &m->mon_inst[i].addr)) in ceph_monmap_contains()
177 monc->pending_auth = 1; in __send_prepared_auth_request()
178 monc->m_auth->front.iov_len = len; in __send_prepared_auth_request()
179 monc->m_auth->hdr.front_len = cpu_to_le32(len); in __send_prepared_auth_request()
180 ceph_msg_revoke(monc->m_auth); in __send_prepared_auth_request()
181 ceph_msg_get(monc->m_auth); /* keep our ref */ in __send_prepared_auth_request()
182 ceph_con_send(&monc->con, monc->m_auth); in __send_prepared_auth_request()
190 dout("__close_session closing mon%d\n", monc->cur_mon); in __close_session()
191 ceph_msg_revoke(monc->m_auth); in __close_session()
192 ceph_msg_revoke_incoming(monc->m_auth_reply); in __close_session()
193 ceph_msg_revoke(monc->m_subscribe); in __close_session()
194 ceph_msg_revoke_incoming(monc->m_subscribe_ack); in __close_session()
195 ceph_con_close(&monc->con); in __close_session()
197 monc->pending_auth = 0; in __close_session()
198 ceph_auth_reset(monc->auth); in __close_session()
207 int old_mon = monc->cur_mon; in pick_new_mon()
209 BUG_ON(monc->monmap->num_mon < 1); in pick_new_mon()
211 if (monc->monmap->num_mon == 1) { in pick_new_mon()
212 monc->cur_mon = 0; in pick_new_mon()
214 int max = monc->monmap->num_mon; in pick_new_mon()
215 int o = -1; in pick_new_mon()
218 if (monc->cur_mon >= 0) { in pick_new_mon()
219 if (monc->cur_mon < monc->monmap->num_mon) in pick_new_mon()
220 o = monc->cur_mon; in pick_new_mon()
222 max--; in pick_new_mon()
229 monc->cur_mon = n; in pick_new_mon()
232 dout("%s mon%d -> mon%d out of %d mons\n", __func__, old_mon, in pick_new_mon()
233 monc->cur_mon, monc->monmap->num_mon); in pick_new_mon()
245 monc->hunting = true; in __open_session()
246 if (monc->had_a_connection) { in __open_session()
247 monc->hunt_mult *= CEPH_MONC_HUNT_BACKOFF; in __open_session()
248 if (monc->hunt_mult > CEPH_MONC_HUNT_MAX_MULT) in __open_session()
249 monc->hunt_mult = CEPH_MONC_HUNT_MAX_MULT; in __open_session()
252 monc->sub_renew_after = jiffies; /* i.e., expired */ in __open_session()
253 monc->sub_renew_sent = 0; in __open_session()
255 dout("%s opening mon%d\n", __func__, monc->cur_mon); in __open_session()
256 ceph_con_open(&monc->con, CEPH_ENTITY_TYPE_MON, monc->cur_mon, in __open_session()
257 &monc->monmap->mon_inst[monc->cur_mon].addr); in __open_session()
265 ceph_con_keepalive(&monc->con); in __open_session()
266 if (ceph_msgr2(monc->client)) { in __open_session()
267 monc->pending_auth = 1; in __open_session()
272 ret = ceph_auth_build_hello(monc->auth, in __open_session()
273 monc->m_auth->front.iov_base, in __open_session()
274 monc->m_auth->front_alloc_len); in __open_session()
281 if (!monc->hunting) in reopen_session()
283 monc->cur_mon, ceph_pr_addr(&monc->con.peer_addr)); in reopen_session()
291 mutex_lock(&monc->mutex); in ceph_monc_reopen_session()
293 mutex_unlock(&monc->mutex); in ceph_monc_reopen_session()
298 monc->hunt_mult /= 2; /* reduce by 50% */ in un_backoff()
299 if (monc->hunt_mult < 1) in un_backoff()
300 monc->hunt_mult = 1; in un_backoff()
301 dout("%s hunt_mult now %d\n", __func__, monc->hunt_mult); in un_backoff()
311 if (monc->hunting) in __schedule_delayed()
312 delay = CEPH_MONC_HUNT_INTERVAL * monc->hunt_mult; in __schedule_delayed()
317 mod_delayed_work(system_wq, &monc->delayed_work, in __schedule_delayed()
330 * monc->subs.
334 struct ceph_msg *msg = monc->m_subscribe; in __send_subscribe()
335 void *p = msg->front.iov_base; in __send_subscribe()
336 void *const end = p + msg->front_alloc_len; in __send_subscribe() local
340 dout("%s sent %lu\n", __func__, monc->sub_renew_sent); in __send_subscribe()
342 BUG_ON(monc->cur_mon < 0); in __send_subscribe()
344 if (!monc->sub_renew_sent) in __send_subscribe()
345 monc->sub_renew_sent = jiffies | 1; /* never 0 */ in __send_subscribe()
347 msg->hdr.version = cpu_to_le16(2); in __send_subscribe()
349 for (i = 0; i < ARRAY_SIZE(monc->subs); i++) { in __send_subscribe()
350 if (monc->subs[i].want) in __send_subscribe()
355 for (i = 0; i < ARRAY_SIZE(monc->subs); i++) { in __send_subscribe()
359 if (!monc->subs[i].want) in __send_subscribe()
364 monc->fs_cluster_id != CEPH_FS_CLUSTER_ID_NONE) in __send_subscribe()
365 len += sprintf(buf + len, ".%d", monc->fs_cluster_id); in __send_subscribe()
368 le64_to_cpu(monc->subs[i].item.start), in __send_subscribe()
369 monc->subs[i].item.flags); in __send_subscribe()
370 ceph_encode_string(&p, end, buf, len); in __send_subscribe()
371 memcpy(p, &monc->subs[i].item, sizeof(monc->subs[i].item)); in __send_subscribe()
372 p += sizeof(monc->subs[i].item); in __send_subscribe()
375 BUG_ON(p > end); in __send_subscribe()
376 msg->front.iov_len = p - msg->front.iov_base; in __send_subscribe()
377 msg->hdr.front_len = cpu_to_le32(msg->front.iov_len); in __send_subscribe()
379 ceph_con_send(&monc->con, ceph_msg_get(msg)); in __send_subscribe()
386 struct ceph_mon_subscribe_ack *h = msg->front.iov_base; in handle_subscribe_ack()
388 if (msg->front.iov_len < sizeof(*h)) in handle_subscribe_ack()
390 seconds = le32_to_cpu(h->duration); in handle_subscribe_ack()
392 mutex_lock(&monc->mutex); in handle_subscribe_ack()
393 if (monc->sub_renew_sent) { in handle_subscribe_ack()
396 * MONs -- see delayed_work(). in handle_subscribe_ack()
398 monc->sub_renew_after = monc->sub_renew_sent + in handle_subscribe_ack()
399 (seconds >> 1) * HZ - 1; in handle_subscribe_ack()
401 monc->sub_renew_sent, seconds, monc->sub_renew_after); in handle_subscribe_ack()
402 monc->sub_renew_sent = 0; in handle_subscribe_ack()
405 monc->sub_renew_sent, monc->sub_renew_after); in handle_subscribe_ack()
407 mutex_unlock(&monc->mutex); in handle_subscribe_ack()
410 pr_err("got corrupt subscribe-ack msg\n"); in handle_subscribe_ack()
429 if (monc->subs[sub].want && in __ceph_monc_want_map()
430 monc->subs[sub].item.start == start && in __ceph_monc_want_map()
431 monc->subs[sub].item.flags == flags) in __ceph_monc_want_map()
434 monc->subs[sub].item.start = start; in __ceph_monc_want_map()
435 monc->subs[sub].item.flags = flags; in __ceph_monc_want_map()
436 monc->subs[sub].want = true; in __ceph_monc_want_map()
446 mutex_lock(&monc->mutex); in ceph_monc_want_map()
448 mutex_unlock(&monc->mutex); in ceph_monc_want_map()
464 if (monc->subs[sub].want) { in __ceph_monc_got_map()
465 if (monc->subs[sub].item.flags & CEPH_SUBSCRIBE_ONETIME) in __ceph_monc_got_map()
466 monc->subs[sub].want = false; in __ceph_monc_got_map()
468 monc->subs[sub].item.start = cpu_to_le64(epoch + 1); in __ceph_monc_got_map()
471 monc->subs[sub].have = epoch; in __ceph_monc_got_map()
476 mutex_lock(&monc->mutex); in ceph_monc_got_map()
478 mutex_unlock(&monc->mutex); in ceph_monc_got_map()
484 mutex_lock(&monc->mutex); in ceph_monc_renew_subs()
486 mutex_unlock(&monc->mutex); in ceph_monc_renew_subs()
502 mutex_lock(&monc->mutex); in ceph_monc_wait_osdmap()
503 while (monc->subs[CEPH_SUB_OSDMAP].have < epoch) { in ceph_monc_wait_osdmap()
504 mutex_unlock(&monc->mutex); in ceph_monc_wait_osdmap()
507 return -ETIMEDOUT; in ceph_monc_wait_osdmap()
509 ret = wait_event_interruptible_timeout(monc->client->auth_wq, in ceph_monc_wait_osdmap()
510 monc->subs[CEPH_SUB_OSDMAP].have >= epoch, in ceph_monc_wait_osdmap()
515 mutex_lock(&monc->mutex); in ceph_monc_wait_osdmap()
518 mutex_unlock(&monc->mutex); in ceph_monc_wait_osdmap()
529 mutex_lock(&monc->mutex); in ceph_monc_open_session()
534 mutex_unlock(&monc->mutex); in ceph_monc_open_session()
542 struct ceph_client *client = monc->client; in ceph_monc_handle_map()
544 void *p, *end; in ceph_monc_handle_map() local
546 mutex_lock(&monc->mutex); in ceph_monc_handle_map()
549 p = msg->front.iov_base; in ceph_monc_handle_map()
550 end = p + msg->front.iov_len; in ceph_monc_handle_map()
552 monmap = ceph_monmap_decode(&p, end, ceph_msgr2(client)); in ceph_monc_handle_map()
560 if (ceph_check_fsid(client, &monmap->fsid) < 0) { in ceph_monc_handle_map()
565 kfree(monc->monmap); in ceph_monc_handle_map()
566 monc->monmap = monmap; in ceph_monc_handle_map()
568 __ceph_monc_got_map(monc, CEPH_SUB_MONMAP, monc->monmap->epoch); in ceph_monc_handle_map()
569 client->have_fsid = true; in ceph_monc_handle_map()
572 mutex_unlock(&monc->mutex); in ceph_monc_handle_map()
573 wake_up_all(&client->auth_wq); in ceph_monc_handle_map()
586 dout("%s greq %p request %p reply %p\n", __func__, req, req->request, in DEFINE_RB_FUNCS()
587 req->reply); in DEFINE_RB_FUNCS()
588 WARN_ON(!RB_EMPTY_NODE(&req->node)); in DEFINE_RB_FUNCS()
590 if (req->reply) in DEFINE_RB_FUNCS()
591 ceph_msg_put(req->reply); in DEFINE_RB_FUNCS()
592 if (req->request) in DEFINE_RB_FUNCS()
593 ceph_msg_put(req->request); in DEFINE_RB_FUNCS()
601 kref_put(&req->kref, release_generic_request); in put_generic_request()
606 kref_get(&req->kref); in get_generic_request()
618 req->monc = monc; in alloc_generic_request()
619 kref_init(&req->kref); in alloc_generic_request()
620 RB_CLEAR_NODE(&req->node); in alloc_generic_request()
621 init_completion(&req->completion); in alloc_generic_request()
629 struct ceph_mon_client *monc = req->monc; in register_generic_request()
631 WARN_ON(req->tid); in register_generic_request()
634 req->tid = ++monc->last_tid; in register_generic_request()
635 insert_generic_request(&monc->generic_request_tree, req); in register_generic_request()
641 WARN_ON(!req->tid); in send_generic_request()
643 dout("%s greq %p tid %llu\n", __func__, req, req->tid); in send_generic_request()
644 req->request->hdr.tid = cpu_to_le64(req->tid); in send_generic_request()
645 ceph_con_send(&monc->con, ceph_msg_get(req->request)); in send_generic_request()
650 struct ceph_mon_client *monc = req->monc; in __finish_generic_request()
652 dout("%s greq %p tid %llu\n", __func__, req, req->tid); in __finish_generic_request()
653 erase_generic_request(&monc->generic_request_tree, req); in __finish_generic_request()
655 ceph_msg_revoke(req->request); in __finish_generic_request()
656 ceph_msg_revoke_incoming(req->reply); in __finish_generic_request()
667 if (req->complete_cb) in complete_generic_request()
668 req->complete_cb(req); in complete_generic_request()
670 complete_all(&req->completion); in complete_generic_request()
676 struct ceph_mon_client *monc = req->monc; in cancel_generic_request()
679 dout("%s greq %p tid %llu\n", __func__, req, req->tid); in cancel_generic_request()
681 mutex_lock(&monc->mutex); in cancel_generic_request()
682 lookup_req = lookup_generic_request(&monc->generic_request_tree, in cancel_generic_request()
683 req->tid); in cancel_generic_request()
689 mutex_unlock(&monc->mutex); in cancel_generic_request()
696 dout("%s greq %p tid %llu\n", __func__, req, req->tid); in wait_generic_request()
697 ret = wait_for_completion_interruptible(&req->completion); in wait_generic_request()
701 ret = req->result; /* completed */ in wait_generic_request()
710 struct ceph_mon_client *monc = con->private; in get_generic_reply()
712 u64 tid = le64_to_cpu(hdr->tid); in get_generic_reply()
715 mutex_lock(&monc->mutex); in get_generic_reply()
716 req = lookup_generic_request(&monc->generic_request_tree, tid); in get_generic_reply()
722 dout("get_generic_reply %lld got %p\n", tid, req->reply); in get_generic_reply()
724 m = ceph_msg_get(req->reply); in get_generic_reply()
731 mutex_unlock(&monc->mutex); in get_generic_reply()
742 struct ceph_mon_statfs_reply *reply = msg->front.iov_base; in handle_statfs_reply()
743 u64 tid = le64_to_cpu(msg->hdr.tid); in handle_statfs_reply()
747 if (msg->front.iov_len != sizeof(*reply)) in handle_statfs_reply()
750 mutex_lock(&monc->mutex); in handle_statfs_reply()
751 req = lookup_generic_request(&monc->generic_request_tree, tid); in handle_statfs_reply()
753 mutex_unlock(&monc->mutex); in handle_statfs_reply()
757 req->result = 0; in handle_statfs_reply()
758 *req->u.st = reply->st; /* struct */ in handle_statfs_reply()
760 mutex_unlock(&monc->mutex); in handle_statfs_reply()
778 int ret = -ENOMEM; in ceph_monc_do_statfs()
784 req->request = ceph_msg_new(CEPH_MSG_STATFS, sizeof(*h), GFP_NOFS, in ceph_monc_do_statfs()
786 if (!req->request) in ceph_monc_do_statfs()
789 req->reply = ceph_msg_new(CEPH_MSG_STATFS_REPLY, 64, GFP_NOFS, true); in ceph_monc_do_statfs()
790 if (!req->reply) in ceph_monc_do_statfs()
793 req->u.st = buf; in ceph_monc_do_statfs()
794 req->request->hdr.version = cpu_to_le16(2); in ceph_monc_do_statfs()
796 mutex_lock(&monc->mutex); in ceph_monc_do_statfs()
799 h = req->request->front.iov_base; in ceph_monc_do_statfs()
800 h->monhdr.have_version = 0; in ceph_monc_do_statfs()
801 h->monhdr.session_mon = cpu_to_le16(-1); in ceph_monc_do_statfs()
802 h->monhdr.session_mon_tid = 0; in ceph_monc_do_statfs()
803 h->fsid = monc->monmap->fsid; in ceph_monc_do_statfs()
804 h->contains_data_pool = (data_pool != CEPH_NOPOOL); in ceph_monc_do_statfs()
805 h->data_pool = cpu_to_le64(data_pool); in ceph_monc_do_statfs()
807 mutex_unlock(&monc->mutex); in ceph_monc_do_statfs()
820 u64 tid = le64_to_cpu(msg->hdr.tid); in handle_get_version_reply()
821 void *p = msg->front.iov_base; in handle_get_version_reply()
822 void *end = p + msg->front_alloc_len; in handle_get_version_reply() local
827 ceph_decode_need(&p, end, 2*sizeof(u64), bad); in handle_get_version_reply()
832 mutex_lock(&monc->mutex); in handle_get_version_reply()
833 req = lookup_generic_request(&monc->generic_request_tree, handle); in handle_get_version_reply()
835 mutex_unlock(&monc->mutex); in handle_get_version_reply()
839 req->result = 0; in handle_get_version_reply()
840 req->u.newest = ceph_decode_64(&p); in handle_get_version_reply()
842 mutex_unlock(&monc->mutex); in handle_get_version_reply()
862 req->request = ceph_msg_new(CEPH_MSG_MON_GET_VERSION, in __ceph_monc_get_version()
865 if (!req->request) in __ceph_monc_get_version()
868 req->reply = ceph_msg_new(CEPH_MSG_MON_GET_VERSION_REPLY, 32, GFP_NOIO, in __ceph_monc_get_version()
870 if (!req->reply) in __ceph_monc_get_version()
873 req->complete_cb = cb; in __ceph_monc_get_version()
874 req->private_data = private_data; in __ceph_monc_get_version()
876 mutex_lock(&monc->mutex); in __ceph_monc_get_version()
879 void *p = req->request->front.iov_base; in __ceph_monc_get_version()
880 void *const end = p + req->request->front_alloc_len; in __ceph_monc_get_version() local
882 ceph_encode_64(&p, req->tid); /* handle */ in __ceph_monc_get_version()
883 ceph_encode_string(&p, end, what, strlen(what)); in __ceph_monc_get_version()
884 WARN_ON(p != end); in __ceph_monc_get_version()
887 mutex_unlock(&monc->mutex); in __ceph_monc_get_version()
893 return ERR_PTR(-ENOMEM); in __ceph_monc_get_version()
913 *newest = req->u.newest; in ceph_monc_get_version()
943 void *p = msg->front.iov_base; in handle_command_ack()
944 void *const end = p + msg->front_alloc_len; in handle_command_ack() local
945 u64 tid = le64_to_cpu(msg->hdr.tid); in handle_command_ack()
949 ceph_decode_need(&p, end, sizeof(struct ceph_mon_request_header) + in handle_command_ack()
953 mutex_lock(&monc->mutex); in handle_command_ack()
954 req = lookup_generic_request(&monc->generic_request_tree, tid); in handle_command_ack()
956 mutex_unlock(&monc->mutex); in handle_command_ack()
960 req->result = ceph_decode_32(&p); in handle_command_ack()
962 mutex_unlock(&monc->mutex); in handle_command_ack()
978 int ret = -ENOMEM; in do_mon_command_vargs()
985 req->request = ceph_msg_new(CEPH_MSG_MON_COMMAND, 256, GFP_NOIO, true); in do_mon_command_vargs()
986 if (!req->request) in do_mon_command_vargs()
989 req->reply = ceph_msg_new(CEPH_MSG_MON_COMMAND_ACK, 512, GFP_NOIO, in do_mon_command_vargs()
991 if (!req->reply) in do_mon_command_vargs()
994 mutex_lock(&monc->mutex); in do_mon_command_vargs()
996 h = req->request->front.iov_base; in do_mon_command_vargs()
997 h->monhdr.have_version = 0; in do_mon_command_vargs()
998 h->monhdr.session_mon = cpu_to_le16(-1); in do_mon_command_vargs()
999 h->monhdr.session_mon_tid = 0; in do_mon_command_vargs()
1000 h->fsid = monc->monmap->fsid; in do_mon_command_vargs()
1001 h->num_strs = cpu_to_le32(1); in do_mon_command_vargs()
1002 len = vsprintf(h->str, fmt, ap); in do_mon_command_vargs()
1003 h->str_len = cpu_to_le32(len); in do_mon_command_vargs()
1005 mutex_unlock(&monc->mutex); in do_mon_command_vargs()
1034 &client_addr->in_addr, in ceph_monc_blocklist_add()
1035 le32_to_cpu(client_addr->nonce)); in ceph_monc_blocklist_add()
1036 if (ret == -EINVAL) { in ceph_monc_blocklist_add()
1039 * Try the legacy command -- it is exactly the same except in ceph_monc_blocklist_add()
1046 &client_addr->in_addr, in ceph_monc_blocklist_add()
1047 le32_to_cpu(client_addr->nonce)); in ceph_monc_blocklist_add()
1058 return ceph_wait_for_latest_osdmap(monc->client, 0); in ceph_monc_blocklist_add()
1070 for (p = rb_first(&monc->generic_request_tree); p; p = rb_next(p)) { in __resend_generic_request()
1072 ceph_msg_revoke(req->request); in __resend_generic_request()
1073 ceph_msg_revoke_incoming(req->reply); in __resend_generic_request()
1074 ceph_con_send(&monc->con, ceph_msg_get(req->request)); in __resend_generic_request()
1088 mutex_lock(&monc->mutex); in delayed_work()
1089 dout("%s mon%d\n", __func__, monc->cur_mon); in delayed_work()
1090 if (monc->cur_mon < 0) { in delayed_work()
1094 if (monc->hunting) { in delayed_work()
1098 int is_auth = ceph_auth_is_authenticated(monc->auth); in delayed_work()
1101 if (ceph_con_keepalive_expired(&monc->con, in delayed_work()
1108 if (!monc->hunting) { in delayed_work()
1109 ceph_con_keepalive(&monc->con); in delayed_work()
1115 !(monc->con.peer_features & CEPH_FEATURE_MON_STATEFUL_SUB)) { in delayed_work()
1119 __func__, now, monc->sub_renew_after); in delayed_work()
1120 if (time_after_eq(now, monc->sub_renew_after)) in delayed_work()
1127 mutex_unlock(&monc->mutex); in delayed_work()
1136 __le32 my_type = ceph_msgr2(monc->client) ? in build_initial_monmap()
1138 struct ceph_options *opt = monc->client->options; in build_initial_monmap()
1139 int num_mon = opt->num_mon; in build_initial_monmap()
1143 monc->monmap = kzalloc(struct_size(monc->monmap, mon_inst, num_mon), in build_initial_monmap()
1145 if (!monc->monmap) in build_initial_monmap()
1146 return -ENOMEM; in build_initial_monmap()
1147 monc->monmap->num_mon = num_mon; in build_initial_monmap()
1150 struct ceph_entity_inst *inst = &monc->monmap->mon_inst[i]; in build_initial_monmap()
1152 memcpy(&inst->addr.in_addr, &opt->mon_addr[i].in_addr, in build_initial_monmap()
1153 sizeof(inst->addr.in_addr)); in build_initial_monmap()
1154 inst->addr.type = my_type; in build_initial_monmap()
1155 inst->addr.nonce = 0; in build_initial_monmap()
1156 inst->name.type = CEPH_ENTITY_TYPE_MON; in build_initial_monmap()
1157 inst->name.num = cpu_to_le64(i); in build_initial_monmap()
1168 monc->client = cl; in ceph_monc_init()
1169 mutex_init(&monc->mutex); in ceph_monc_init()
1177 monc->auth = ceph_auth_init(cl->options->name, cl->options->key, in ceph_monc_init()
1178 cl->options->con_modes); in ceph_monc_init()
1179 if (IS_ERR(monc->auth)) { in ceph_monc_init()
1180 err = PTR_ERR(monc->auth); in ceph_monc_init()
1183 monc->auth->want_keys = in ceph_monc_init()
1188 err = -ENOMEM; in ceph_monc_init()
1189 monc->m_subscribe_ack = ceph_msg_new(CEPH_MSG_MON_SUBSCRIBE_ACK, in ceph_monc_init()
1192 if (!monc->m_subscribe_ack) in ceph_monc_init()
1195 monc->m_subscribe = ceph_msg_new(CEPH_MSG_MON_SUBSCRIBE, 128, in ceph_monc_init()
1197 if (!monc->m_subscribe) in ceph_monc_init()
1200 monc->m_auth_reply = ceph_msg_new(CEPH_MSG_AUTH_REPLY, 4096, in ceph_monc_init()
1202 if (!monc->m_auth_reply) in ceph_monc_init()
1205 monc->m_auth = ceph_msg_new(CEPH_MSG_AUTH, 4096, GFP_KERNEL, true); in ceph_monc_init()
1206 monc->pending_auth = 0; in ceph_monc_init()
1207 if (!monc->m_auth) in ceph_monc_init()
1210 ceph_con_init(&monc->con, monc, &mon_con_ops, in ceph_monc_init()
1211 &monc->client->msgr); in ceph_monc_init()
1213 monc->cur_mon = -1; in ceph_monc_init()
1214 monc->had_a_connection = false; in ceph_monc_init()
1215 monc->hunt_mult = 1; in ceph_monc_init()
1217 INIT_DELAYED_WORK(&monc->delayed_work, delayed_work); in ceph_monc_init()
1218 monc->generic_request_tree = RB_ROOT; in ceph_monc_init()
1219 monc->last_tid = 0; in ceph_monc_init()
1221 monc->fs_cluster_id = CEPH_FS_CLUSTER_ID_NONE; in ceph_monc_init()
1226 ceph_msg_put(monc->m_auth_reply); in ceph_monc_init()
1228 ceph_msg_put(monc->m_subscribe); in ceph_monc_init()
1230 ceph_msg_put(monc->m_subscribe_ack); in ceph_monc_init()
1232 ceph_auth_destroy(monc->auth); in ceph_monc_init()
1234 kfree(monc->monmap); in ceph_monc_init()
1244 mutex_lock(&monc->mutex); in ceph_monc_stop()
1246 monc->hunting = false; in ceph_monc_stop()
1247 monc->cur_mon = -1; in ceph_monc_stop()
1248 mutex_unlock(&monc->mutex); in ceph_monc_stop()
1250 cancel_delayed_work_sync(&monc->delayed_work); in ceph_monc_stop()
1254 * - any work that references our embedded con is finished. in ceph_monc_stop()
1255 * - any osd_client or other work that may reference an authorizer in ceph_monc_stop()
1260 ceph_auth_destroy(monc->auth); in ceph_monc_stop()
1262 WARN_ON(!RB_EMPTY_ROOT(&monc->generic_request_tree)); in ceph_monc_stop()
1264 ceph_msg_put(monc->m_auth); in ceph_monc_stop()
1265 ceph_msg_put(monc->m_auth_reply); in ceph_monc_stop()
1266 ceph_msg_put(monc->m_subscribe); in ceph_monc_stop()
1267 ceph_msg_put(monc->m_subscribe_ack); in ceph_monc_stop()
1269 kfree(monc->monmap); in ceph_monc_stop()
1275 if (monc->hunting) { in finish_hunting()
1276 dout("%s found mon%d\n", __func__, monc->cur_mon); in finish_hunting()
1277 monc->hunting = false; in finish_hunting()
1278 monc->had_a_connection = true; in finish_hunting()
1290 monc->pending_auth = 0; in finish_auth()
1292 monc->client->auth_err = auth_err; in finish_auth()
1293 wake_up_all(&monc->client->auth_wq); in finish_auth()
1297 if (!was_authed && ceph_auth_is_authenticated(monc->auth)) { in finish_auth()
1299 __func__, monc->auth->global_id); in finish_auth()
1301 monc->client->msgr.inst.name.type = CEPH_ENTITY_TYPE_CLIENT; in finish_auth()
1302 monc->client->msgr.inst.name.num = in finish_auth()
1303 cpu_to_le64(monc->auth->global_id); in finish_auth()
1308 pr_info("mon%d %s session established\n", monc->cur_mon, in finish_auth()
1309 ceph_pr_addr(&monc->con.peer_addr)); in finish_auth()
1319 mutex_lock(&monc->mutex); in handle_auth_reply()
1320 was_authed = ceph_auth_is_authenticated(monc->auth); in handle_auth_reply()
1321 ret = ceph_handle_auth_reply(monc->auth, msg->front.iov_base, in handle_auth_reply()
1322 msg->front.iov_len, in handle_auth_reply()
1323 monc->m_auth->front.iov_base, in handle_auth_reply()
1324 monc->m_auth->front_alloc_len); in handle_auth_reply()
1331 mutex_unlock(&monc->mutex); in handle_auth_reply()
1338 if (monc->pending_auth) in __validate_auth()
1341 ret = ceph_build_auth(monc->auth, monc->m_auth->front.iov_base, in __validate_auth()
1342 monc->m_auth->front_alloc_len); in __validate_auth()
1353 mutex_lock(&monc->mutex); in ceph_monc_validate_auth()
1355 mutex_unlock(&monc->mutex); in ceph_monc_validate_auth()
1364 struct ceph_mon_client *monc = con->private; in mon_get_auth_request()
1367 mutex_lock(&monc->mutex); in mon_get_auth_request()
1368 ret = ceph_auth_get_request(monc->auth, buf, *buf_len); in mon_get_auth_request()
1369 mutex_unlock(&monc->mutex); in mon_get_auth_request()
1384 struct ceph_mon_client *monc = con->private; in mon_handle_auth_reply_more()
1387 mutex_lock(&monc->mutex); in mon_handle_auth_reply_more()
1388 ret = ceph_auth_handle_reply_more(monc->auth, reply, reply_len, in mon_handle_auth_reply_more()
1390 mutex_unlock(&monc->mutex); in mon_handle_auth_reply_more()
1405 struct ceph_mon_client *monc = con->private; in mon_handle_auth_done()
1409 mutex_lock(&monc->mutex); in mon_handle_auth_done()
1410 WARN_ON(!monc->hunting); in mon_handle_auth_done()
1411 was_authed = ceph_auth_is_authenticated(monc->auth); in mon_handle_auth_done()
1412 ret = ceph_auth_handle_reply_done(monc->auth, global_id, in mon_handle_auth_done()
1419 mutex_unlock(&monc->mutex); in mon_handle_auth_done()
1428 struct ceph_mon_client *monc = con->private; in mon_handle_auth_bad_method()
1431 mutex_lock(&monc->mutex); in mon_handle_auth_bad_method()
1432 WARN_ON(!monc->hunting); in mon_handle_auth_bad_method()
1433 was_authed = ceph_auth_is_authenticated(monc->auth); in mon_handle_auth_bad_method()
1434 ceph_auth_handle_bad_method(monc->auth, used_proto, result, in mon_handle_auth_bad_method()
1437 finish_auth(monc, -EACCES, was_authed); in mon_handle_auth_bad_method()
1438 mutex_unlock(&monc->mutex); in mon_handle_auth_bad_method()
1447 struct ceph_mon_client *monc = con->private; in mon_dispatch()
1448 int type = le16_to_cpu(msg->hdr.type); in mon_dispatch()
1476 ceph_osdc_handle_map(&monc->client->osdc, msg); in mon_dispatch()
1481 if (monc->client->extra_mon_dispatch && in mon_dispatch()
1482 monc->client->extra_mon_dispatch(monc->client, msg) == 0) in mon_dispatch()
1498 struct ceph_mon_client *monc = con->private; in mon_alloc_msg()
1499 int type = le16_to_cpu(hdr->type); in mon_alloc_msg()
1500 int front_len = le32_to_cpu(hdr->front_len); in mon_alloc_msg()
1507 m = ceph_msg_get(monc->m_subscribe_ack); in mon_alloc_msg()
1513 m = ceph_msg_get(monc->m_auth_reply); in mon_alloc_msg()
1516 if (le64_to_cpu(hdr->tid) != 0) in mon_alloc_msg()
1521 * request had a non-zero tid. Work around this weirdness in mon_alloc_msg()
1531 return NULL; /* ENOMEM--return skip == 0 */ in mon_alloc_msg()
1538 } else if (front_len > m->front_alloc_len) { in mon_alloc_msg()
1539 pr_warn("mon_alloc_msg front %d > prealloc %d (%u#%llu)\n", in mon_alloc_msg()
1540 front_len, m->front_alloc_len, in mon_alloc_msg()
1541 (unsigned int)con->peer_name.type, in mon_alloc_msg()
1542 le64_to_cpu(con->peer_name.num)); in mon_alloc_msg()
1556 struct ceph_mon_client *monc = con->private; in mon_fault()
1558 mutex_lock(&monc->mutex); in mon_fault()
1559 dout("%s mon%d\n", __func__, monc->cur_mon); in mon_fault()
1560 if (monc->cur_mon >= 0) { in mon_fault()
1561 if (!monc->hunting) { in mon_fault()
1569 mutex_unlock(&monc->mutex); in mon_fault()