3 #include <linux/module.h>
4 #include <linux/types.h>
5 #include <linux/slab.h>
6 #include <linux/random.h>
7 #include <linux/sched.h>
52 dout(
"monmap_decode %p %p len %d\n", p, end, (
int)(end-p));
57 ceph_decode_copy(&p, &fsid,
sizeof(fsid));
58 epoch = ceph_decode_32(&p);
60 num_mon = ceph_decode_32(&p);
72 for (i = 0; i < num_mon; i++)
73 ceph_decode_addr(&m->
mon_inst[i].addr);
75 dout(
"monmap_decode epoch %d, num_mon %d\n", m->
epoch,
77 for (i = 0; i < m->
num_mon; i++)
78 dout(
"monmap_decode mon%d is %s\n", i,
83 dout(
"monmap_decode failed with %d\n", err);
95 for (i = 0; i < m->
num_mon; i++)
104 static void __send_prepared_auth_request(
struct ceph_mon_client *monc,
int len)
107 monc->
m_auth->front.iov_len = len;
110 ceph_msg_get(monc->
m_auth);
119 dout(
"__close_session closing mon%d\n", monc->
cur_mon);
141 dout(
"open_session num=%d r=%d -> mon%d\n",
147 dout(
"open_session mon%d opening\n", monc->
cur_mon);
154 monc->
m_auth->front.iov_base,
156 __send_prepared_auth_request(monc, ret);
158 dout(
"open_session mon%d already open\n", monc->
cur_mon);
175 if (monc->
cur_mon < 0 || __sub_expired(monc))
179 dout(
"__schedule_delayed after %u\n", delay);
188 dout(
"__send_subscribe sub_sent=%u exp=%u want_osd=%d\n",
189 (
unsigned int)monc->
sub_sent, __sub_expired(monc),
191 if ((__sub_expired(monc) && !monc->
sub_sent) ||
198 p = msg->
front.iov_base;
202 ceph_encode_32(&p, num);
205 dout(
"__send_subscribe to 'osdmap' %u\n",
207 ceph_encode_string(&p, end,
"osdmap", 6);
215 dout(
"__send_subscribe to 'mdsmap' %u+\n",
217 ceph_encode_string(&p, end,
"mdsmap", 6);
223 ceph_encode_string(&p, end,
"monmap", 6);
244 if (msg->
front.iov_len <
sizeof(*h))
250 pr_info(
"mon%d %s session established\n",
255 dout(
"handle_subscribe_ack after %d seconds\n", seconds);
261 pr_err(
"got corrupt subscribe-ack msg\n");
296 __send_subscribe(monc);
306 __open_session(monc);
307 __schedule_delayed(monc);
319 dout(
"have_debugfs_info fsid %d globalid %lld\n",
320 (
int)monc->
client->have_fsid, monc->
auth->global_id);
321 return monc->
client->have_fsid && monc->
auth->global_id > 0;
334 int had_debugfs_info, init_debugfs = 0;
338 had_debugfs_info = have_debugfs_info(monc);
340 dout(
"handle_monmap\n");
341 p = msg->
front.iov_base;
342 end = p + msg->
front.iov_len;
345 if (IS_ERR(monmap)) {
346 pr_err(
"problem decoding monmap, %d\n",
347 (
int)PTR_ERR(monmap));
356 client->
monc.monmap = monmap;
361 if (!had_debugfs_info && have_debugfs_info(monc)) {
362 pr_info(
"client%lld fsid %pU\n",
398 else if (tid > req->
tid)
416 if (new->tid < req->
tid)
418 else if (new->tid > req->
tid)
424 rb_link_node(&new->node, parent, p);
428 static void release_generic_request(
struct kref *
kref)
434 ceph_msg_put(req->
reply);
443 kref_put(&req->
kref, release_generic_request);
448 kref_get(&req->
kref);
461 req = __lookup_generic_req(monc, tid);
463 dout(
"get_generic_reply %lld dne\n", tid);
467 dout(
"get_generic_reply %lld got %p\n", tid, req->
reply);
469 m = ceph_msg_get(req->
reply);
489 __insert_generic_request(monc, req);
516 if (msg->
front.iov_len !=
sizeof(*reply))
518 dout(
"handle_statfs_reply %p tid %llu\n", msg, tid);
521 req = __lookup_generic_req(monc, tid);
525 get_generic_request(req);
530 put_generic_request(req);
535 pr_err(
"corrupt generic reply, tid %llu\n", tid);
548 req = kzalloc(
sizeof(*req),
GFP_NOFS);
552 kref_init(&req->
kref);
568 h = req->
request->front.iov_base;
569 h->
monhdr.have_version = 0;
571 h->
monhdr.session_mon_tid = 0;
574 err = do_generic_request(monc, req);
577 kref_put(&req->
kref, release_generic_request);
585 static int get_poolop_reply_buf(
const char *
src,
size_t src_len,
586 char *
dst,
size_t dst_len)
590 if (src_len !=
sizeof(
u32) + dst_len)
594 if (buf_len != dst_len)
608 if (msg->
front.iov_len <
sizeof(*reply))
610 dout(
"handle_poolop_reply %p tid %llu\n", msg, tid);
613 req = __lookup_generic_req(monc, tid);
616 get_poolop_reply_buf(msg->
front.iov_base +
sizeof(*reply),
617 msg->
front.iov_len -
sizeof(*reply),
623 get_generic_request(req);
628 put_generic_request(req);
633 pr_err(
"corrupt generic reply, tid %llu\n", tid);
648 req = kzalloc(
sizeof(*req),
GFP_NOFS);
652 kref_init(&req->
kref);
669 h = req->
request->front.iov_base;
670 h->
monhdr.have_version = 0;
672 h->
monhdr.session_mon_tid = 0;
680 err = do_generic_request(monc, req);
683 kref_put(&req->
kref, release_generic_request);
691 pool, 0, (
char *)snapid,
sizeof(*snapid));
730 dout(
"monc delayed_work\n");
733 __close_session(monc);
734 __open_session(monc);
738 __validate_auth(monc);
740 if (monc->
auth->ops->is_authenticated(monc->
auth))
741 __send_subscribe(monc);
743 __schedule_delayed(monc);
760 num_mon*
sizeof(monc->
monmap->mon_inst[0]),
764 for (i = 0; i < num_mon; i++) {
765 monc->
monmap->mon_inst[
i].addr = mon_addr[
i];
766 monc->
monmap->mon_inst[
i].addr.nonce = 0;
767 monc->
monmap->mon_inst[
i].name.type =
771 monc->
monmap->num_mon = num_mon;
780 memset(monc, 0,
sizeof(*monc));
785 err = build_initial_monmap(monc);
793 if (IS_ERR(monc->
auth)) {
794 err = PTR_ERR(monc->
auth);
797 monc->
auth->want_keys =
812 goto out_subscribe_ack;
863 __close_session(monc);
877 ceph_msg_put(monc->
m_auth);
891 int had_debugfs_info, init_debugfs = 0;
894 had_debugfs_info = have_debugfs_info(monc);
896 was_auth = monc->
auth->ops->is_authenticated(monc->
auth);
900 monc->
m_auth->front.iov_base,
905 }
else if (ret > 0) {
906 __send_prepared_auth_request(monc, ret);
907 }
else if (!was_auth && monc->
auth->ops->is_authenticated(monc->
auth)) {
908 dout(
"authenticated, starting session\n");
911 monc->
client->msgr.inst.name.num =
914 __send_subscribe(monc);
915 __resend_generic_request(monc);
918 if (!had_debugfs_info && have_debugfs_info(monc)) {
919 pr_info(
"client%lld fsid %pU\n",
946 __send_prepared_auth_request(monc, ret);
955 ret = __validate_auth(monc);
974 handle_auth_reply(monc, msg);
978 handle_subscribe_ack(monc, msg);
982 handle_statfs_reply(monc, msg);
986 handle_poolop_reply(monc, msg);
990 ceph_monc_handle_map(monc, msg);
999 if (monc->
client->extra_mon_dispatch &&
1000 monc->
client->extra_mon_dispatch(monc->
client, msg) == 0)
1003 pr_err(
"received unknown message type %d %s\n", type,
1029 return get_generic_reply(con, hdr, skip);
1043 pr_info(
"alloc_msg unknown type %d\n", type);
1060 dout(
"mon_fault\n");
1066 pr_info(
"mon%d %s session lost, "
1067 "hunting for new mon\n", monc->
cur_mon,
1070 __close_session(monc);
1074 __open_session(monc);
1077 __schedule_delayed(monc);
1102 .alloc_msg = mon_alloc_msg,