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
42 static struct ceph_monmap *ceph_monmap_decode(void *p, void *end) in ceph_monmap_decode() argument
45 int i, err = -EINVAL; in ceph_monmap_decode()
50 ceph_decode_32_safe(&p, end, len, bad); in ceph_monmap_decode()
51 ceph_decode_need(&p, end, len, bad); 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()
84 ceph_pr_addr(&m->mon_inst[i].addr)); in ceph_monmap_decode()
99 for (i = 0; i < m->num_mon; i++) in ceph_monmap_contains()
100 if (memcmp(addr, &m->mon_inst[i].addr, sizeof(*addr)) == 0) in ceph_monmap_contains()
110 monc->pending_auth = 1; in __send_prepared_auth_request()
111 monc->m_auth->front.iov_len = len; in __send_prepared_auth_request()
112 monc->m_auth->hdr.front_len = cpu_to_le32(len); in __send_prepared_auth_request()
113 ceph_msg_revoke(monc->m_auth); in __send_prepared_auth_request()
114 ceph_msg_get(monc->m_auth); /* keep our ref */ in __send_prepared_auth_request()
115 ceph_con_send(&monc->con, monc->m_auth); in __send_prepared_auth_request()
123 dout("__close_session closing mon%d\n", monc->cur_mon); in __close_session()
124 ceph_msg_revoke(monc->m_auth); in __close_session()
125 ceph_msg_revoke_incoming(monc->m_auth_reply); in __close_session()
126 ceph_msg_revoke(monc->m_subscribe); in __close_session()
127 ceph_msg_revoke_incoming(monc->m_subscribe_ack); in __close_session()
128 ceph_con_close(&monc->con); in __close_session()
130 monc->pending_auth = 0; in __close_session()
131 ceph_auth_reset(monc->auth); in __close_session()
140 int old_mon = monc->cur_mon; in pick_new_mon()
142 BUG_ON(monc->monmap->num_mon < 1); in pick_new_mon()
144 if (monc->monmap->num_mon == 1) { in pick_new_mon()
145 monc->cur_mon = 0; in pick_new_mon()
147 int max = monc->monmap->num_mon; in pick_new_mon()
148 int o = -1; in pick_new_mon()
151 if (monc->cur_mon >= 0) { in pick_new_mon()
152 if (monc->cur_mon < monc->monmap->num_mon) in pick_new_mon()
153 o = monc->cur_mon; in pick_new_mon()
155 max--; in pick_new_mon()
162 monc->cur_mon = n; in pick_new_mon()
165 dout("%s mon%d -> mon%d out of %d mons\n", __func__, old_mon, in pick_new_mon()
166 monc->cur_mon, monc->monmap->num_mon); in pick_new_mon()
178 monc->hunting = true; in __open_session()
179 if (monc->had_a_connection) { in __open_session()
180 monc->hunt_mult *= CEPH_MONC_HUNT_BACKOFF; in __open_session()
181 if (monc->hunt_mult > CEPH_MONC_HUNT_MAX_MULT) in __open_session()
182 monc->hunt_mult = CEPH_MONC_HUNT_MAX_MULT; in __open_session()
185 monc->sub_renew_after = jiffies; /* i.e., expired */ in __open_session()
186 monc->sub_renew_sent = 0; in __open_session()
188 dout("%s opening mon%d\n", __func__, monc->cur_mon); in __open_session()
189 ceph_con_open(&monc->con, CEPH_ENTITY_TYPE_MON, monc->cur_mon, in __open_session()
190 &monc->monmap->mon_inst[monc->cur_mon].addr); in __open_session()
196 ceph_con_keepalive(&monc->con); in __open_session()
199 ret = ceph_auth_build_hello(monc->auth, in __open_session()
200 monc->m_auth->front.iov_base, in __open_session()
201 monc->m_auth->front_alloc_len); in __open_session()
208 if (!monc->hunting) in reopen_session()
210 monc->cur_mon, ceph_pr_addr(&monc->con.peer_addr)); in reopen_session()
218 mutex_lock(&monc->mutex); in ceph_monc_reopen_session()
220 mutex_unlock(&monc->mutex); in ceph_monc_reopen_session()
225 monc->hunt_mult /= 2; /* reduce by 50% */ in un_backoff()
226 if (monc->hunt_mult < 1) in un_backoff()
227 monc->hunt_mult = 1; in un_backoff()
228 dout("%s hunt_mult now %d\n", __func__, monc->hunt_mult); in un_backoff()
238 if (monc->hunting) in __schedule_delayed()
239 delay = CEPH_MONC_HUNT_INTERVAL * monc->hunt_mult; in __schedule_delayed()
244 mod_delayed_work(system_wq, &monc->delayed_work, in __schedule_delayed()
257 * monc->subs.
261 struct ceph_msg *msg = monc->m_subscribe; in __send_subscribe()
262 void *p = msg->front.iov_base; in __send_subscribe()
263 void *const end = p + msg->front_alloc_len; in __send_subscribe() local
267 dout("%s sent %lu\n", __func__, monc->sub_renew_sent); in __send_subscribe()
269 BUG_ON(monc->cur_mon < 0); in __send_subscribe()
271 if (!monc->sub_renew_sent) in __send_subscribe()
272 monc->sub_renew_sent = jiffies | 1; /* never 0 */ in __send_subscribe()
274 msg->hdr.version = cpu_to_le16(2); in __send_subscribe()
276 for (i = 0; i < ARRAY_SIZE(monc->subs); i++) { in __send_subscribe()
277 if (monc->subs[i].want) in __send_subscribe()
282 for (i = 0; i < ARRAY_SIZE(monc->subs); i++) { in __send_subscribe()
286 if (!monc->subs[i].want) in __send_subscribe()
291 monc->fs_cluster_id != CEPH_FS_CLUSTER_ID_NONE) in __send_subscribe()
292 len += sprintf(buf + len, ".%d", monc->fs_cluster_id); in __send_subscribe()
295 le64_to_cpu(monc->subs[i].item.start), in __send_subscribe()
296 monc->subs[i].item.flags); in __send_subscribe()
297 ceph_encode_string(&p, end, buf, len); in __send_subscribe()
298 memcpy(p, &monc->subs[i].item, sizeof(monc->subs[i].item)); in __send_subscribe()
299 p += sizeof(monc->subs[i].item); in __send_subscribe()
302 BUG_ON(p > end); in __send_subscribe()
303 msg->front.iov_len = p - msg->front.iov_base; in __send_subscribe()
304 msg->hdr.front_len = cpu_to_le32(msg->front.iov_len); in __send_subscribe()
306 ceph_con_send(&monc->con, ceph_msg_get(msg)); in __send_subscribe()
313 struct ceph_mon_subscribe_ack *h = msg->front.iov_base; in handle_subscribe_ack()
315 if (msg->front.iov_len < sizeof(*h)) in handle_subscribe_ack()
317 seconds = le32_to_cpu(h->duration); in handle_subscribe_ack()
319 mutex_lock(&monc->mutex); in handle_subscribe_ack()
320 if (monc->sub_renew_sent) { in handle_subscribe_ack()
323 * MONs -- see delayed_work(). in handle_subscribe_ack()
325 monc->sub_renew_after = monc->sub_renew_sent + in handle_subscribe_ack()
326 (seconds >> 1) * HZ - 1; in handle_subscribe_ack()
328 monc->sub_renew_sent, seconds, monc->sub_renew_after); in handle_subscribe_ack()
329 monc->sub_renew_sent = 0; in handle_subscribe_ack()
332 monc->sub_renew_sent, monc->sub_renew_after); in handle_subscribe_ack()
334 mutex_unlock(&monc->mutex); in handle_subscribe_ack()
337 pr_err("got corrupt subscribe-ack msg\n"); in handle_subscribe_ack()
356 if (monc->subs[sub].want && in __ceph_monc_want_map()
357 monc->subs[sub].item.start == start && in __ceph_monc_want_map()
358 monc->subs[sub].item.flags == flags) in __ceph_monc_want_map()
361 monc->subs[sub].item.start = start; in __ceph_monc_want_map()
362 monc->subs[sub].item.flags = flags; in __ceph_monc_want_map()
363 monc->subs[sub].want = true; in __ceph_monc_want_map()
373 mutex_lock(&monc->mutex); in ceph_monc_want_map()
375 mutex_unlock(&monc->mutex); in ceph_monc_want_map()
391 if (monc->subs[sub].want) { in __ceph_monc_got_map()
392 if (monc->subs[sub].item.flags & CEPH_SUBSCRIBE_ONETIME) in __ceph_monc_got_map()
393 monc->subs[sub].want = false; in __ceph_monc_got_map()
395 monc->subs[sub].item.start = cpu_to_le64(epoch + 1); in __ceph_monc_got_map()
398 monc->subs[sub].have = epoch; in __ceph_monc_got_map()
403 mutex_lock(&monc->mutex); in ceph_monc_got_map()
405 mutex_unlock(&monc->mutex); in ceph_monc_got_map()
411 mutex_lock(&monc->mutex); in ceph_monc_renew_subs()
413 mutex_unlock(&monc->mutex); in ceph_monc_renew_subs()
429 mutex_lock(&monc->mutex); in ceph_monc_wait_osdmap()
430 while (monc->subs[CEPH_SUB_OSDMAP].have < epoch) { in ceph_monc_wait_osdmap()
431 mutex_unlock(&monc->mutex); in ceph_monc_wait_osdmap()
434 return -ETIMEDOUT; in ceph_monc_wait_osdmap()
436 ret = wait_event_interruptible_timeout(monc->client->auth_wq, in ceph_monc_wait_osdmap()
437 monc->subs[CEPH_SUB_OSDMAP].have >= epoch, in ceph_monc_wait_osdmap()
442 mutex_lock(&monc->mutex); in ceph_monc_wait_osdmap()
445 mutex_unlock(&monc->mutex); in ceph_monc_wait_osdmap()
456 mutex_lock(&monc->mutex); in ceph_monc_open_session()
461 mutex_unlock(&monc->mutex); in ceph_monc_open_session()
469 struct ceph_client *client = monc->client; in ceph_monc_handle_map()
471 void *p, *end; in ceph_monc_handle_map() local
473 mutex_lock(&monc->mutex); in ceph_monc_handle_map()
476 p = msg->front.iov_base; in ceph_monc_handle_map()
477 end = p + msg->front.iov_len; in ceph_monc_handle_map()
479 monmap = ceph_monmap_decode(p, end); in ceph_monc_handle_map()
487 if (ceph_check_fsid(client, &monmap->fsid) < 0) { in ceph_monc_handle_map()
492 kfree(monc->monmap); in ceph_monc_handle_map()
493 monc->monmap = monmap; in ceph_monc_handle_map()
495 __ceph_monc_got_map(monc, CEPH_SUB_MONMAP, monc->monmap->epoch); in ceph_monc_handle_map()
496 client->have_fsid = true; in ceph_monc_handle_map()
499 mutex_unlock(&monc->mutex); in ceph_monc_handle_map()
500 wake_up_all(&client->auth_wq); in ceph_monc_handle_map()
513 dout("%s greq %p request %p reply %p\n", __func__, req, req->request, in DEFINE_RB_FUNCS()
514 req->reply); in DEFINE_RB_FUNCS()
515 WARN_ON(!RB_EMPTY_NODE(&req->node)); in DEFINE_RB_FUNCS()
517 if (req->reply) in DEFINE_RB_FUNCS()
518 ceph_msg_put(req->reply); in DEFINE_RB_FUNCS()
519 if (req->request) in DEFINE_RB_FUNCS()
520 ceph_msg_put(req->request); in DEFINE_RB_FUNCS()
528 kref_put(&req->kref, release_generic_request); in put_generic_request()
533 kref_get(&req->kref); in get_generic_request()
545 req->monc = monc; in alloc_generic_request()
546 kref_init(&req->kref); in alloc_generic_request()
547 RB_CLEAR_NODE(&req->node); in alloc_generic_request()
548 init_completion(&req->completion); in alloc_generic_request()
556 struct ceph_mon_client *monc = req->monc; in register_generic_request()
558 WARN_ON(req->tid); in register_generic_request()
561 req->tid = ++monc->last_tid; in register_generic_request()
562 insert_generic_request(&monc->generic_request_tree, req); in register_generic_request()
568 WARN_ON(!req->tid); in send_generic_request()
570 dout("%s greq %p tid %llu\n", __func__, req, req->tid); in send_generic_request()
571 req->request->hdr.tid = cpu_to_le64(req->tid); in send_generic_request()
572 ceph_con_send(&monc->con, ceph_msg_get(req->request)); in send_generic_request()
577 struct ceph_mon_client *monc = req->monc; in __finish_generic_request()
579 dout("%s greq %p tid %llu\n", __func__, req, req->tid); in __finish_generic_request()
580 erase_generic_request(&monc->generic_request_tree, req); in __finish_generic_request()
582 ceph_msg_revoke(req->request); in __finish_generic_request()
583 ceph_msg_revoke_incoming(req->reply); in __finish_generic_request()
594 if (req->complete_cb) in complete_generic_request()
595 req->complete_cb(req); in complete_generic_request()
597 complete_all(&req->completion); in complete_generic_request()
603 struct ceph_mon_client *monc = req->monc; in cancel_generic_request()
606 dout("%s greq %p tid %llu\n", __func__, req, req->tid); in cancel_generic_request()
608 mutex_lock(&monc->mutex); in cancel_generic_request()
609 lookup_req = lookup_generic_request(&monc->generic_request_tree, in cancel_generic_request()
610 req->tid); in cancel_generic_request()
616 mutex_unlock(&monc->mutex); in cancel_generic_request()
623 dout("%s greq %p tid %llu\n", __func__, req, req->tid); in wait_generic_request()
624 ret = wait_for_completion_interruptible(&req->completion); in wait_generic_request()
628 ret = req->result; /* completed */ in wait_generic_request()
637 struct ceph_mon_client *monc = con->private; in get_generic_reply()
639 u64 tid = le64_to_cpu(hdr->tid); in get_generic_reply()
642 mutex_lock(&monc->mutex); in get_generic_reply()
643 req = lookup_generic_request(&monc->generic_request_tree, tid); in get_generic_reply()
649 dout("get_generic_reply %lld got %p\n", tid, req->reply); in get_generic_reply()
651 m = ceph_msg_get(req->reply); in get_generic_reply()
658 mutex_unlock(&monc->mutex); in get_generic_reply()
669 struct ceph_mon_statfs_reply *reply = msg->front.iov_base; in handle_statfs_reply()
670 u64 tid = le64_to_cpu(msg->hdr.tid); in handle_statfs_reply()
674 if (msg->front.iov_len != sizeof(*reply)) in handle_statfs_reply()
677 mutex_lock(&monc->mutex); in handle_statfs_reply()
678 req = lookup_generic_request(&monc->generic_request_tree, tid); in handle_statfs_reply()
680 mutex_unlock(&monc->mutex); in handle_statfs_reply()
684 req->result = 0; in handle_statfs_reply()
685 *req->u.st = reply->st; /* struct */ in handle_statfs_reply()
687 mutex_unlock(&monc->mutex); in handle_statfs_reply()
705 int ret = -ENOMEM; in ceph_monc_do_statfs()
711 req->request = ceph_msg_new(CEPH_MSG_STATFS, sizeof(*h), GFP_NOFS, in ceph_monc_do_statfs()
713 if (!req->request) in ceph_monc_do_statfs()
716 req->reply = ceph_msg_new(CEPH_MSG_STATFS_REPLY, 64, GFP_NOFS, true); in ceph_monc_do_statfs()
717 if (!req->reply) in ceph_monc_do_statfs()
720 req->u.st = buf; in ceph_monc_do_statfs()
721 req->request->hdr.version = cpu_to_le16(2); in ceph_monc_do_statfs()
723 mutex_lock(&monc->mutex); in ceph_monc_do_statfs()
726 h = req->request->front.iov_base; in ceph_monc_do_statfs()
727 h->monhdr.have_version = 0; in ceph_monc_do_statfs()
728 h->monhdr.session_mon = cpu_to_le16(-1); in ceph_monc_do_statfs()
729 h->monhdr.session_mon_tid = 0; in ceph_monc_do_statfs()
730 h->fsid = monc->monmap->fsid; in ceph_monc_do_statfs()
731 h->contains_data_pool = (data_pool != CEPH_NOPOOL); in ceph_monc_do_statfs()
732 h->data_pool = cpu_to_le64(data_pool); in ceph_monc_do_statfs()
734 mutex_unlock(&monc->mutex); in ceph_monc_do_statfs()
747 u64 tid = le64_to_cpu(msg->hdr.tid); in handle_get_version_reply()
748 void *p = msg->front.iov_base; in handle_get_version_reply()
749 void *end = p + msg->front_alloc_len; in handle_get_version_reply() local
754 ceph_decode_need(&p, end, 2*sizeof(u64), bad); in handle_get_version_reply()
759 mutex_lock(&monc->mutex); in handle_get_version_reply()
760 req = lookup_generic_request(&monc->generic_request_tree, handle); in handle_get_version_reply()
762 mutex_unlock(&monc->mutex); in handle_get_version_reply()
766 req->result = 0; in handle_get_version_reply()
767 req->u.newest = ceph_decode_64(&p); in handle_get_version_reply()
769 mutex_unlock(&monc->mutex); in handle_get_version_reply()
789 req->request = ceph_msg_new(CEPH_MSG_MON_GET_VERSION, in __ceph_monc_get_version()
792 if (!req->request) in __ceph_monc_get_version()
795 req->reply = ceph_msg_new(CEPH_MSG_MON_GET_VERSION_REPLY, 32, GFP_NOIO, in __ceph_monc_get_version()
797 if (!req->reply) in __ceph_monc_get_version()
800 req->complete_cb = cb; in __ceph_monc_get_version()
801 req->private_data = private_data; in __ceph_monc_get_version()
803 mutex_lock(&monc->mutex); in __ceph_monc_get_version()
806 void *p = req->request->front.iov_base; in __ceph_monc_get_version()
807 void *const end = p + req->request->front_alloc_len; in __ceph_monc_get_version() local
809 ceph_encode_64(&p, req->tid); /* handle */ in __ceph_monc_get_version()
810 ceph_encode_string(&p, end, what, strlen(what)); in __ceph_monc_get_version()
811 WARN_ON(p != end); in __ceph_monc_get_version()
814 mutex_unlock(&monc->mutex); in __ceph_monc_get_version()
820 return ERR_PTR(-ENOMEM); in __ceph_monc_get_version()
840 *newest = req->u.newest; in ceph_monc_get_version()
870 void *p = msg->front.iov_base; in handle_command_ack()
871 void *const end = p + msg->front_alloc_len; in handle_command_ack() local
872 u64 tid = le64_to_cpu(msg->hdr.tid); in handle_command_ack()
876 ceph_decode_need(&p, end, sizeof(struct ceph_mon_request_header) + in handle_command_ack()
880 mutex_lock(&monc->mutex); in handle_command_ack()
881 req = lookup_generic_request(&monc->generic_request_tree, tid); in handle_command_ack()
883 mutex_unlock(&monc->mutex); in handle_command_ack()
887 req->result = ceph_decode_32(&p); in handle_command_ack()
889 mutex_unlock(&monc->mutex); in handle_command_ack()
905 int ret = -ENOMEM; in do_mon_command_vargs()
912 req->request = ceph_msg_new(CEPH_MSG_MON_COMMAND, 256, GFP_NOIO, true); in do_mon_command_vargs()
913 if (!req->request) in do_mon_command_vargs()
916 req->reply = ceph_msg_new(CEPH_MSG_MON_COMMAND_ACK, 512, GFP_NOIO, in do_mon_command_vargs()
918 if (!req->reply) in do_mon_command_vargs()
921 mutex_lock(&monc->mutex); in do_mon_command_vargs()
923 h = req->request->front.iov_base; in do_mon_command_vargs()
924 h->monhdr.have_version = 0; in do_mon_command_vargs()
925 h->monhdr.session_mon = cpu_to_le16(-1); in do_mon_command_vargs()
926 h->monhdr.session_mon_tid = 0; in do_mon_command_vargs()
927 h->fsid = monc->monmap->fsid; in do_mon_command_vargs()
928 h->num_strs = cpu_to_le32(1); in do_mon_command_vargs()
929 len = vsprintf(h->str, fmt, ap); in do_mon_command_vargs()
930 h->str_len = cpu_to_le32(len); in do_mon_command_vargs()
932 mutex_unlock(&monc->mutex); in do_mon_command_vargs()
961 &client_addr->in_addr, in ceph_monc_blocklist_add()
962 le32_to_cpu(client_addr->nonce)); in ceph_monc_blocklist_add()
963 if (ret == -EINVAL) { in ceph_monc_blocklist_add()
966 * Try the legacy command -- it is exactly the same except in ceph_monc_blocklist_add()
973 &client_addr->in_addr, in ceph_monc_blocklist_add()
974 le32_to_cpu(client_addr->nonce)); in ceph_monc_blocklist_add()
985 return ceph_wait_for_latest_osdmap(monc->client, 0); in ceph_monc_blocklist_add()
997 for (p = rb_first(&monc->generic_request_tree); p; p = rb_next(p)) { in __resend_generic_request()
999 ceph_msg_revoke(req->request); in __resend_generic_request()
1000 ceph_msg_revoke_incoming(req->reply); in __resend_generic_request()
1001 ceph_con_send(&monc->con, ceph_msg_get(req->request)); in __resend_generic_request()
1016 mutex_lock(&monc->mutex); in delayed_work()
1017 if (monc->hunting) { in delayed_work()
1021 int is_auth = ceph_auth_is_authenticated(monc->auth); in delayed_work()
1022 if (ceph_con_keepalive_expired(&monc->con, in delayed_work()
1029 if (!monc->hunting) { in delayed_work()
1030 ceph_con_keepalive(&monc->con); in delayed_work()
1036 !(monc->con.peer_features & CEPH_FEATURE_MON_STATEFUL_SUB)) { in delayed_work()
1040 __func__, now, monc->sub_renew_after); in delayed_work()
1041 if (time_after_eq(now, monc->sub_renew_after)) in delayed_work()
1046 mutex_unlock(&monc->mutex); in delayed_work()
1055 struct ceph_options *opt = monc->client->options; in build_initial_monmap()
1056 struct ceph_entity_addr *mon_addr = opt->mon_addr; in build_initial_monmap()
1057 int num_mon = opt->num_mon; in build_initial_monmap()
1061 monc->monmap = kzalloc(struct_size(monc->monmap, mon_inst, num_mon), in build_initial_monmap()
1063 if (!monc->monmap) in build_initial_monmap()
1064 return -ENOMEM; in build_initial_monmap()
1066 monc->monmap->mon_inst[i].addr = mon_addr[i]; in build_initial_monmap()
1067 monc->monmap->mon_inst[i].addr.nonce = 0; in build_initial_monmap()
1068 monc->monmap->mon_inst[i].name.type = in build_initial_monmap()
1070 monc->monmap->mon_inst[i].name.num = cpu_to_le64(i); in build_initial_monmap()
1072 monc->monmap->num_mon = num_mon; in build_initial_monmap()
1082 monc->client = cl; in ceph_monc_init()
1083 monc->monmap = NULL; in ceph_monc_init()
1084 mutex_init(&monc->mutex); in ceph_monc_init()
1092 monc->auth = ceph_auth_init(cl->options->name, in ceph_monc_init()
1093 cl->options->key); in ceph_monc_init()
1094 if (IS_ERR(monc->auth)) { in ceph_monc_init()
1095 err = PTR_ERR(monc->auth); in ceph_monc_init()
1098 monc->auth->want_keys = in ceph_monc_init()
1103 err = -ENOMEM; in ceph_monc_init()
1104 monc->m_subscribe_ack = ceph_msg_new(CEPH_MSG_MON_SUBSCRIBE_ACK, in ceph_monc_init()
1107 if (!monc->m_subscribe_ack) in ceph_monc_init()
1110 monc->m_subscribe = ceph_msg_new(CEPH_MSG_MON_SUBSCRIBE, 128, in ceph_monc_init()
1112 if (!monc->m_subscribe) in ceph_monc_init()
1115 monc->m_auth_reply = ceph_msg_new(CEPH_MSG_AUTH_REPLY, 4096, in ceph_monc_init()
1117 if (!monc->m_auth_reply) in ceph_monc_init()
1120 monc->m_auth = ceph_msg_new(CEPH_MSG_AUTH, 4096, GFP_KERNEL, true); in ceph_monc_init()
1121 monc->pending_auth = 0; in ceph_monc_init()
1122 if (!monc->m_auth) in ceph_monc_init()
1125 ceph_con_init(&monc->con, monc, &mon_con_ops, in ceph_monc_init()
1126 &monc->client->msgr); in ceph_monc_init()
1128 monc->cur_mon = -1; in ceph_monc_init()
1129 monc->had_a_connection = false; in ceph_monc_init()
1130 monc->hunt_mult = 1; in ceph_monc_init()
1132 INIT_DELAYED_WORK(&monc->delayed_work, delayed_work); in ceph_monc_init()
1133 monc->generic_request_tree = RB_ROOT; in ceph_monc_init()
1134 monc->last_tid = 0; in ceph_monc_init()
1136 monc->fs_cluster_id = CEPH_FS_CLUSTER_ID_NONE; in ceph_monc_init()
1141 ceph_msg_put(monc->m_auth_reply); in ceph_monc_init()
1143 ceph_msg_put(monc->m_subscribe); in ceph_monc_init()
1145 ceph_msg_put(monc->m_subscribe_ack); in ceph_monc_init()
1147 ceph_auth_destroy(monc->auth); in ceph_monc_init()
1149 kfree(monc->monmap); in ceph_monc_init()
1158 cancel_delayed_work_sync(&monc->delayed_work); in ceph_monc_stop()
1160 mutex_lock(&monc->mutex); in ceph_monc_stop()
1162 monc->cur_mon = -1; in ceph_monc_stop()
1163 mutex_unlock(&monc->mutex); in ceph_monc_stop()
1167 * - any work that references our embedded con is finished. in ceph_monc_stop()
1168 * - any osd_client or other work that may reference an authorizer in ceph_monc_stop()
1173 ceph_auth_destroy(monc->auth); in ceph_monc_stop()
1175 WARN_ON(!RB_EMPTY_ROOT(&monc->generic_request_tree)); in ceph_monc_stop()
1177 ceph_msg_put(monc->m_auth); in ceph_monc_stop()
1178 ceph_msg_put(monc->m_auth_reply); in ceph_monc_stop()
1179 ceph_msg_put(monc->m_subscribe); in ceph_monc_stop()
1180 ceph_msg_put(monc->m_subscribe_ack); in ceph_monc_stop()
1182 kfree(monc->monmap); in ceph_monc_stop()
1188 if (monc->hunting) { in finish_hunting()
1189 dout("%s found mon%d\n", __func__, monc->cur_mon); in finish_hunting()
1190 monc->hunting = false; in finish_hunting()
1191 monc->had_a_connection = true; in finish_hunting()
1203 mutex_lock(&monc->mutex); in handle_auth_reply()
1204 was_auth = ceph_auth_is_authenticated(monc->auth); in handle_auth_reply()
1205 monc->pending_auth = 0; in handle_auth_reply()
1206 ret = ceph_handle_auth_reply(monc->auth, msg->front.iov_base, in handle_auth_reply()
1207 msg->front.iov_len, in handle_auth_reply()
1208 monc->m_auth->front.iov_base, in handle_auth_reply()
1209 monc->m_auth->front_alloc_len); in handle_auth_reply()
1218 monc->client->auth_err = ret; in handle_auth_reply()
1219 } else if (!was_auth && ceph_auth_is_authenticated(monc->auth)) { in handle_auth_reply()
1222 monc->client->msgr.inst.name.type = CEPH_ENTITY_TYPE_CLIENT; in handle_auth_reply()
1223 monc->client->msgr.inst.name.num = in handle_auth_reply()
1224 cpu_to_le64(monc->auth->global_id); in handle_auth_reply()
1229 pr_info("mon%d %s session established\n", monc->cur_mon, in handle_auth_reply()
1230 ceph_pr_addr(&monc->con.peer_addr)); in handle_auth_reply()
1234 mutex_unlock(&monc->mutex); in handle_auth_reply()
1235 if (monc->client->auth_err < 0) in handle_auth_reply()
1236 wake_up_all(&monc->client->auth_wq); in handle_auth_reply()
1243 if (monc->pending_auth) in __validate_auth()
1246 ret = ceph_build_auth(monc->auth, monc->m_auth->front.iov_base, in __validate_auth()
1247 monc->m_auth->front_alloc_len); in __validate_auth()
1258 mutex_lock(&monc->mutex); in ceph_monc_validate_auth()
1260 mutex_unlock(&monc->mutex); in ceph_monc_validate_auth()
1270 struct ceph_mon_client *monc = con->private; in dispatch()
1271 int type = le16_to_cpu(msg->hdr.type); in dispatch()
1299 ceph_osdc_handle_map(&monc->client->osdc, msg); in dispatch()
1304 if (monc->client->extra_mon_dispatch && in dispatch()
1305 monc->client->extra_mon_dispatch(monc->client, msg) == 0) in dispatch()
1321 struct ceph_mon_client *monc = con->private; in mon_alloc_msg()
1322 int type = le16_to_cpu(hdr->type); in mon_alloc_msg()
1323 int front_len = le32_to_cpu(hdr->front_len); in mon_alloc_msg()
1330 m = ceph_msg_get(monc->m_subscribe_ack); in mon_alloc_msg()
1336 m = ceph_msg_get(monc->m_auth_reply); in mon_alloc_msg()
1339 if (le64_to_cpu(hdr->tid) != 0) in mon_alloc_msg()
1344 * request had a non-zero tid. Work around this weirdness in mon_alloc_msg()
1354 return NULL; /* ENOMEM--return skip == 0 */ in mon_alloc_msg()
1361 } else if (front_len > m->front_alloc_len) { in mon_alloc_msg()
1362 pr_warn("mon_alloc_msg front %d > prealloc %d (%u#%llu)\n", in mon_alloc_msg()
1363 front_len, m->front_alloc_len, in mon_alloc_msg()
1364 (unsigned int)con->peer_name.type, in mon_alloc_msg()
1365 le64_to_cpu(con->peer_name.num)); in mon_alloc_msg()
1379 struct ceph_mon_client *monc = con->private; in mon_fault()
1381 mutex_lock(&monc->mutex); in mon_fault()
1382 dout("%s mon%d\n", __func__, monc->cur_mon); in mon_fault()
1383 if (monc->cur_mon >= 0) { in mon_fault()
1384 if (!monc->hunting) { in mon_fault()
1392 mutex_unlock(&monc->mutex); in mon_fault()