H A D | mon_client.c | 35 static int __validate_auth(struct ceph_mon_client *monc); 104 static void __send_prepared_auth_request(struct ceph_mon_client *monc, int len) __send_prepared_auth_request() argument 106 monc->pending_auth = 1; __send_prepared_auth_request() 107 monc->m_auth->front.iov_len = len; __send_prepared_auth_request() 108 monc->m_auth->hdr.front_len = cpu_to_le32(len); __send_prepared_auth_request() 109 ceph_msg_revoke(monc->m_auth); __send_prepared_auth_request() 110 ceph_msg_get(monc->m_auth); /* keep our ref */ __send_prepared_auth_request() 111 ceph_con_send(&monc->con, monc->m_auth); __send_prepared_auth_request() 117 static void __close_session(struct ceph_mon_client *monc) __close_session() argument 119 dout("__close_session closing mon%d\n", monc->cur_mon); __close_session() 120 ceph_msg_revoke(monc->m_auth); __close_session() 121 ceph_msg_revoke_incoming(monc->m_auth_reply); __close_session() 122 ceph_msg_revoke(monc->m_subscribe); __close_session() 123 ceph_msg_revoke_incoming(monc->m_subscribe_ack); __close_session() 124 ceph_con_close(&monc->con); __close_session() 125 monc->cur_mon = -1; __close_session() 126 monc->pending_auth = 0; __close_session() 127 ceph_auth_reset(monc->auth); __close_session() 133 static int __open_session(struct ceph_mon_client *monc) __open_session() argument 138 if (monc->cur_mon < 0) { __open_session() 140 monc->cur_mon = r % monc->monmap->num_mon; __open_session() 142 monc->monmap->num_mon, r, monc->cur_mon); __open_session() 143 monc->sub_sent = 0; __open_session() 144 monc->sub_renew_after = jiffies; /* i.e., expired */ __open_session() 145 monc->want_next_osdmap = !!monc->want_next_osdmap; __open_session() 147 dout("open_session mon%d opening\n", monc->cur_mon); __open_session() 148 ceph_con_open(&monc->con, __open_session() 149 CEPH_ENTITY_TYPE_MON, monc->cur_mon, __open_session() 150 &monc->monmap->mon_inst[monc->cur_mon].addr); __open_session() 154 ceph_con_keepalive(&monc->con); __open_session() 157 ret = ceph_auth_build_hello(monc->auth, __open_session() 158 monc->m_auth->front.iov_base, __open_session() 159 monc->m_auth->front_alloc_len); __open_session() 160 __send_prepared_auth_request(monc, ret); __open_session() 162 dout("open_session mon%d already open\n", monc->cur_mon); __open_session() 167 static bool __sub_expired(struct ceph_mon_client *monc) __sub_expired() argument 169 return time_after_eq(jiffies, monc->sub_renew_after); __sub_expired() 175 static void __schedule_delayed(struct ceph_mon_client *monc) __schedule_delayed() argument 177 struct ceph_options *opt = monc->client->options; __schedule_delayed() 180 if (monc->cur_mon < 0 || __sub_expired(monc)) { __schedule_delayed() 188 schedule_delayed_work(&monc->delayed_work, __schedule_delayed() 195 static void __send_subscribe(struct ceph_mon_client *monc) __send_subscribe() argument 198 (unsigned int)monc->sub_sent, __sub_expired(monc), __send_subscribe() 199 monc->want_next_osdmap); __send_subscribe() 200 if ((__sub_expired(monc) && !monc->sub_sent) || __send_subscribe() 201 monc->want_next_osdmap == 1) { __send_subscribe() 202 struct ceph_msg *msg = monc->m_subscribe; __send_subscribe() 210 num = 1 + !!monc->want_next_osdmap + !!monc->want_mdsmap; __send_subscribe() 213 if (monc->want_next_osdmap) { __send_subscribe() 215 (unsigned int)monc->have_osdmap); __send_subscribe() 218 i->have = cpu_to_le64(monc->have_osdmap); __send_subscribe() 221 monc->want_next_osdmap = 2; /* requested */ __send_subscribe() 223 if (monc->want_mdsmap) { __send_subscribe() 225 (unsigned int)monc->have_mdsmap); __send_subscribe() 228 i->have = cpu_to_le64(monc->have_mdsmap); __send_subscribe() 241 ceph_con_send(&monc->con, ceph_msg_get(msg)); __send_subscribe() 243 monc->sub_sent = jiffies | 1; /* never 0 */ __send_subscribe() 247 static void handle_subscribe_ack(struct ceph_mon_client *monc, handle_subscribe_ack() argument 257 mutex_lock(&monc->mutex); handle_subscribe_ack() 258 if (monc->hunting) { handle_subscribe_ack() 260 monc->cur_mon, handle_subscribe_ack() 261 ceph_pr_addr(&monc->con.peer_addr.in_addr)); handle_subscribe_ack() 262 monc->hunting = false; handle_subscribe_ack() 265 monc->sub_renew_after = monc->sub_sent + (seconds >> 1)*HZ - 1; handle_subscribe_ack() 266 monc->sub_sent = 0; handle_subscribe_ack() 267 mutex_unlock(&monc->mutex); handle_subscribe_ack() 277 int ceph_monc_got_mdsmap(struct ceph_mon_client *monc, u32 got) ceph_monc_got_mdsmap() argument 279 mutex_lock(&monc->mutex); ceph_monc_got_mdsmap() 280 monc->have_mdsmap = got; ceph_monc_got_mdsmap() 281 mutex_unlock(&monc->mutex); ceph_monc_got_mdsmap() 286 int ceph_monc_got_osdmap(struct ceph_mon_client *monc, u32 got) ceph_monc_got_osdmap() argument 288 mutex_lock(&monc->mutex); ceph_monc_got_osdmap() 289 monc->have_osdmap = got; ceph_monc_got_osdmap() 290 monc->want_next_osdmap = 0; ceph_monc_got_osdmap() 291 mutex_unlock(&monc->mutex); ceph_monc_got_osdmap() 298 void ceph_monc_request_next_osdmap(struct ceph_mon_client *monc) ceph_monc_request_next_osdmap() argument 300 dout("request_next_osdmap have %u\n", monc->have_osdmap); ceph_monc_request_next_osdmap() 301 mutex_lock(&monc->mutex); ceph_monc_request_next_osdmap() 302 if (!monc->want_next_osdmap) ceph_monc_request_next_osdmap() 303 monc->want_next_osdmap = 1; ceph_monc_request_next_osdmap() 304 if (monc->want_next_osdmap < 2) ceph_monc_request_next_osdmap() 305 __send_subscribe(monc); ceph_monc_request_next_osdmap() 306 mutex_unlock(&monc->mutex); ceph_monc_request_next_osdmap() 316 int ceph_monc_wait_osdmap(struct ceph_mon_client *monc, u32 epoch, ceph_monc_wait_osdmap() argument 322 mutex_lock(&monc->mutex); ceph_monc_wait_osdmap() 323 while (monc->have_osdmap < epoch) { ceph_monc_wait_osdmap() 324 mutex_unlock(&monc->mutex); ceph_monc_wait_osdmap() 329 ret = wait_event_interruptible_timeout(monc->client->auth_wq, ceph_monc_wait_osdmap() 330 monc->have_osdmap >= epoch, ceph_monc_wait_osdmap() 335 mutex_lock(&monc->mutex); ceph_monc_wait_osdmap() 338 mutex_unlock(&monc->mutex); ceph_monc_wait_osdmap() 346 int ceph_monc_open_session(struct ceph_mon_client *monc) ceph_monc_open_session() argument 348 mutex_lock(&monc->mutex); ceph_monc_open_session() 349 __open_session(monc); ceph_monc_open_session() 350 __schedule_delayed(monc); ceph_monc_open_session() 351 mutex_unlock(&monc->mutex); ceph_monc_open_session() 360 static bool have_debugfs_info(struct ceph_mon_client *monc) have_debugfs_info() argument 363 (int)monc->client->have_fsid, monc->auth->global_id); have_debugfs_info() 364 return monc->client->have_fsid && monc->auth->global_id > 0; have_debugfs_info() 371 static void ceph_monc_handle_map(struct ceph_mon_client *monc, ceph_monc_handle_map() argument 374 struct ceph_client *client = monc->client; ceph_monc_handle_map() 375 struct ceph_monmap *monmap = NULL, *old = monc->monmap; ceph_monc_handle_map() 379 mutex_lock(&monc->mutex); ceph_monc_handle_map() 381 had_debugfs_info = have_debugfs_info(monc); ceph_monc_handle_map() 394 if (ceph_check_fsid(monc->client, &monmap->fsid) < 0) { ceph_monc_handle_map() 399 client->monc.monmap = monmap; ceph_monc_handle_map() 404 if (!had_debugfs_info && have_debugfs_info(monc)) { ceph_monc_handle_map() 406 ceph_client_id(monc->client), ceph_monc_handle_map() 407 &monc->client->fsid); ceph_monc_handle_map() 410 mutex_unlock(&monc->mutex); ceph_monc_handle_map() 417 ceph_debugfs_client_init(monc->client); ceph_monc_handle_map() 423 mutex_unlock(&monc->mutex); ceph_monc_handle_map() 432 struct ceph_mon_client *monc, u64 tid) __lookup_generic_req() 435 struct rb_node *n = monc->generic_request_tree.rb_node; __lookup_generic_req() 449 static void __insert_generic_request(struct ceph_mon_client *monc, __insert_generic_request() argument 452 struct rb_node **p = &monc->generic_request_tree.rb_node; __insert_generic_request() 468 rb_insert_color(&new->node, &monc->generic_request_tree); __insert_generic_request() 498 struct ceph_mon_client *monc = con->private; get_generic_reply() local 503 mutex_lock(&monc->mutex); get_generic_reply() 504 req = __lookup_generic_req(monc, tid); get_generic_reply() 519 mutex_unlock(&monc->mutex); get_generic_reply() 523 static int __do_generic_request(struct ceph_mon_client *monc, u64 tid, __do_generic_request() argument 529 req->tid = tid != 0 ? tid : ++monc->last_tid; __do_generic_request() 531 __insert_generic_request(monc, req); __do_generic_request() 532 monc->num_generic_requests++; __do_generic_request() 533 ceph_con_send(&monc->con, ceph_msg_get(req->request)); __do_generic_request() 534 mutex_unlock(&monc->mutex); __do_generic_request() 538 mutex_lock(&monc->mutex); __do_generic_request() 539 rb_erase(&req->node, &monc->generic_request_tree); __do_generic_request() 540 monc->num_generic_requests--; __do_generic_request() 547 static int do_generic_request(struct ceph_mon_client *monc, do_generic_request() argument 552 mutex_lock(&monc->mutex); do_generic_request() 553 err = __do_generic_request(monc, 0, req); do_generic_request() 554 mutex_unlock(&monc->mutex); do_generic_request() 562 static void handle_statfs_reply(struct ceph_mon_client *monc, handle_statfs_reply() argument 573 mutex_lock(&monc->mutex); handle_statfs_reply() 574 req = __lookup_generic_req(monc, tid); handle_statfs_reply() 580 mutex_unlock(&monc->mutex); handle_statfs_reply() 595 int ceph_monc_do_statfs(struct ceph_mon_client *monc, struct ceph_statfs *buf) ceph_monc_do_statfs() argument 624 h->fsid = monc->monmap->fsid; ceph_monc_do_statfs() 626 err = do_generic_request(monc, req); ceph_monc_do_statfs() 634 static void handle_get_version_reply(struct ceph_mon_client *monc, handle_get_version_reply() argument 650 mutex_lock(&monc->mutex); handle_get_version_reply() 651 req = __lookup_generic_req(monc, handle); handle_get_version_reply() 657 mutex_unlock(&monc->mutex); handle_get_version_reply() 674 int ceph_monc_do_get_version(struct ceph_mon_client *monc, const char *what, ceph_monc_do_get_version() argument 709 mutex_lock(&monc->mutex); ceph_monc_do_get_version() 710 tid = ++monc->last_tid; ceph_monc_do_get_version() 714 err = __do_generic_request(monc, tid, req); ceph_monc_do_get_version() 716 mutex_unlock(&monc->mutex); ceph_monc_do_get_version() 726 static void __resend_generic_request(struct ceph_mon_client *monc) __resend_generic_request() argument 731 for (p = rb_first(&monc->generic_request_tree); p; p = rb_next(p)) { __resend_generic_request() 735 ceph_con_send(&monc->con, ceph_msg_get(req->request)); __resend_generic_request() 746 struct ceph_mon_client *monc = delayed_work() local 749 dout("monc delayed_work\n"); delayed_work() 750 mutex_lock(&monc->mutex); delayed_work() 751 if (monc->hunting) { delayed_work() 752 __close_session(monc); delayed_work() 753 __open_session(monc); /* continue hunting */ delayed_work() 755 struct ceph_options *opt = monc->client->options; delayed_work() 756 int is_auth = ceph_auth_is_authenticated(monc->auth); delayed_work() 757 if (ceph_con_keepalive_expired(&monc->con, delayed_work() 759 dout("monc keepalive timeout\n"); delayed_work() 761 __close_session(monc); delayed_work() 762 monc->hunting = true; delayed_work() 763 __open_session(monc); delayed_work() 766 if (!monc->hunting) { delayed_work() 767 ceph_con_keepalive(&monc->con); delayed_work() 768 __validate_auth(monc); delayed_work() 772 __send_subscribe(monc); delayed_work() 774 __schedule_delayed(monc); delayed_work() 775 mutex_unlock(&monc->mutex); delayed_work() 782 static int build_initial_monmap(struct ceph_mon_client *monc) build_initial_monmap() argument 784 struct ceph_options *opt = monc->client->options; build_initial_monmap() 790 monc->monmap = kzalloc(sizeof(*monc->monmap) + build_initial_monmap() 791 num_mon*sizeof(monc->monmap->mon_inst[0]), build_initial_monmap() 793 if (!monc->monmap) build_initial_monmap() 796 monc->monmap->mon_inst[i].addr = mon_addr[i]; build_initial_monmap() 797 monc->monmap->mon_inst[i].addr.nonce = 0; build_initial_monmap() 798 monc->monmap->mon_inst[i].name.type = build_initial_monmap() 800 monc->monmap->mon_inst[i].name.num = cpu_to_le64(i); build_initial_monmap() 802 monc->monmap->num_mon = num_mon; build_initial_monmap() 806 int ceph_monc_init(struct ceph_mon_client *monc, struct ceph_client *cl) ceph_monc_init() argument 811 memset(monc, 0, sizeof(*monc)); ceph_monc_init() 812 monc->client = cl; ceph_monc_init() 813 monc->monmap = NULL; ceph_monc_init() 814 mutex_init(&monc->mutex); ceph_monc_init() 816 err = build_initial_monmap(monc); ceph_monc_init() 822 monc->auth = ceph_auth_init(cl->options->name, ceph_monc_init() 824 if (IS_ERR(monc->auth)) { ceph_monc_init() 825 err = PTR_ERR(monc->auth); ceph_monc_init() 828 monc->auth->want_keys = ceph_monc_init() 834 monc->m_subscribe_ack = ceph_msg_new(CEPH_MSG_MON_SUBSCRIBE_ACK, ceph_monc_init() 837 if (!monc->m_subscribe_ack) ceph_monc_init() 840 monc->m_subscribe = ceph_msg_new(CEPH_MSG_MON_SUBSCRIBE, 96, GFP_NOFS, ceph_monc_init() 842 if (!monc->m_subscribe) ceph_monc_init() 845 monc->m_auth_reply = ceph_msg_new(CEPH_MSG_AUTH_REPLY, 4096, GFP_NOFS, ceph_monc_init() 847 if (!monc->m_auth_reply) ceph_monc_init() 850 monc->m_auth = ceph_msg_new(CEPH_MSG_AUTH, 4096, GFP_NOFS, true); ceph_monc_init() 851 monc->pending_auth = 0; ceph_monc_init() 852 if (!monc->m_auth) ceph_monc_init() 855 ceph_con_init(&monc->con, monc, &mon_con_ops, ceph_monc_init() 856 &monc->client->msgr); ceph_monc_init() 858 monc->cur_mon = -1; ceph_monc_init() 859 monc->hunting = true; ceph_monc_init() 860 monc->sub_renew_after = jiffies; ceph_monc_init() 861 monc->sub_sent = 0; ceph_monc_init() 863 INIT_DELAYED_WORK(&monc->delayed_work, delayed_work); ceph_monc_init() 864 monc->generic_request_tree = RB_ROOT; ceph_monc_init() 865 monc->num_generic_requests = 0; ceph_monc_init() 866 monc->last_tid = 0; ceph_monc_init() 868 monc->have_mdsmap = 0; ceph_monc_init() 869 monc->have_osdmap = 0; ceph_monc_init() 870 monc->want_next_osdmap = 1; ceph_monc_init() 874 ceph_msg_put(monc->m_auth_reply); ceph_monc_init() 876 ceph_msg_put(monc->m_subscribe); ceph_monc_init() 878 ceph_msg_put(monc->m_subscribe_ack); ceph_monc_init() 880 ceph_auth_destroy(monc->auth); ceph_monc_init() 882 kfree(monc->monmap); ceph_monc_init() 888 void ceph_monc_stop(struct ceph_mon_client *monc) ceph_monc_stop() argument 891 cancel_delayed_work_sync(&monc->delayed_work); ceph_monc_stop() 893 mutex_lock(&monc->mutex); ceph_monc_stop() 894 __close_session(monc); ceph_monc_stop() 896 mutex_unlock(&monc->mutex); ceph_monc_stop() 906 ceph_auth_destroy(monc->auth); ceph_monc_stop() 908 ceph_msg_put(monc->m_auth); ceph_monc_stop() 909 ceph_msg_put(monc->m_auth_reply); ceph_monc_stop() 910 ceph_msg_put(monc->m_subscribe); ceph_monc_stop() 911 ceph_msg_put(monc->m_subscribe_ack); ceph_monc_stop() 913 kfree(monc->monmap); ceph_monc_stop() 917 static void handle_auth_reply(struct ceph_mon_client *monc, handle_auth_reply() argument 924 mutex_lock(&monc->mutex); handle_auth_reply() 925 had_debugfs_info = have_debugfs_info(monc); handle_auth_reply() 926 was_auth = ceph_auth_is_authenticated(monc->auth); handle_auth_reply() 927 monc->pending_auth = 0; handle_auth_reply() 928 ret = ceph_handle_auth_reply(monc->auth, msg->front.iov_base, handle_auth_reply() 930 monc->m_auth->front.iov_base, handle_auth_reply() 931 monc->m_auth->front_alloc_len); handle_auth_reply() 933 monc->client->auth_err = ret; handle_auth_reply() 934 wake_up_all(&monc->client->auth_wq); handle_auth_reply() 936 __send_prepared_auth_request(monc, ret); handle_auth_reply() 937 } else if (!was_auth && ceph_auth_is_authenticated(monc->auth)) { handle_auth_reply() 940 monc->client->msgr.inst.name.type = CEPH_ENTITY_TYPE_CLIENT; handle_auth_reply() 941 monc->client->msgr.inst.name.num = handle_auth_reply() 942 cpu_to_le64(monc->auth->global_id); handle_auth_reply() 944 __send_subscribe(monc); handle_auth_reply() 945 __resend_generic_request(monc); handle_auth_reply() 948 if (!had_debugfs_info && have_debugfs_info(monc)) { handle_auth_reply() 950 ceph_client_id(monc->client), handle_auth_reply() 951 &monc->client->fsid); handle_auth_reply() 954 mutex_unlock(&monc->mutex); handle_auth_reply() 961 ceph_debugfs_client_init(monc->client); handle_auth_reply() 965 static int __validate_auth(struct ceph_mon_client *monc) __validate_auth() argument 969 if (monc->pending_auth) __validate_auth() 972 ret = ceph_build_auth(monc->auth, monc->m_auth->front.iov_base, __validate_auth() 973 monc->m_auth->front_alloc_len); __validate_auth() 976 __send_prepared_auth_request(monc, ret); __validate_auth() 980 int ceph_monc_validate_auth(struct ceph_mon_client *monc) ceph_monc_validate_auth() argument 984 mutex_lock(&monc->mutex); ceph_monc_validate_auth() 985 ret = __validate_auth(monc); ceph_monc_validate_auth() 986 mutex_unlock(&monc->mutex); ceph_monc_validate_auth() 996 struct ceph_mon_client *monc = con->private; dispatch() local 999 if (!monc) dispatch() 1004 handle_auth_reply(monc, msg); dispatch() 1008 handle_subscribe_ack(monc, msg); dispatch() 1012 handle_statfs_reply(monc, msg); dispatch() 1016 handle_get_version_reply(monc, msg); dispatch() 1020 ceph_monc_handle_map(monc, msg); dispatch() 1024 ceph_osdc_handle_map(&monc->client->osdc, msg); dispatch() 1029 if (monc->client->extra_mon_dispatch && dispatch() 1030 monc->client->extra_mon_dispatch(monc->client, msg) == 0) dispatch() 1046 struct ceph_mon_client *monc = con->private; mon_alloc_msg() local 1055 m = ceph_msg_get(monc->m_subscribe_ack); mon_alloc_msg() 1060 m = ceph_msg_get(monc->m_auth_reply); mon_alloc_msg() 1101 struct ceph_mon_client *monc = con->private; mon_fault() local 1103 if (!monc) mon_fault() 1107 mutex_lock(&monc->mutex); mon_fault() 1111 if (!monc->hunting) mon_fault() 1113 "hunting for new mon\n", monc->cur_mon, mon_fault() 1114 ceph_pr_addr(&monc->con.peer_addr.in_addr)); mon_fault() 1116 __close_session(monc); mon_fault() 1117 if (!monc->hunting) { mon_fault() 1119 monc->hunting = true; mon_fault() 1120 __open_session(monc); mon_fault() 1123 __schedule_delayed(monc); mon_fault() 1126 mutex_unlock(&monc->mutex); mon_fault() 431 __lookup_generic_req( struct ceph_mon_client *monc, u64 tid) __lookup_generic_req() argument
|