Lines Matching refs:mdsc
60 static void __wake_requests(struct ceph_mds_client *mdsc,
681 struct ceph_mds_session *__ceph_lookup_mds_session(struct ceph_mds_client *mdsc, in __ceph_lookup_mds_session() argument
684 if (mds >= mdsc->max_sessions || !mdsc->sessions[mds]) in __ceph_lookup_mds_session()
686 return ceph_get_mds_session(mdsc->sessions[mds]); in __ceph_lookup_mds_session()
689 static bool __have_session(struct ceph_mds_client *mdsc, int mds) in __have_session() argument
691 if (mds >= mdsc->max_sessions || !mdsc->sessions[mds]) in __have_session()
697 static int __verify_registered_session(struct ceph_mds_client *mdsc, in __verify_registered_session() argument
700 if (s->s_mds >= mdsc->max_sessions || in __verify_registered_session()
701 mdsc->sessions[s->s_mds] != s) in __verify_registered_session()
710 static struct ceph_mds_session *register_session(struct ceph_mds_client *mdsc, in register_session() argument
715 if (mds >= mdsc->mdsmap->possible_max_rank) in register_session()
722 if (mds >= mdsc->max_sessions) { in register_session()
730 if (mdsc->sessions) { in register_session()
731 memcpy(sa, mdsc->sessions, in register_session()
732 mdsc->max_sessions * sizeof(void *)); in register_session()
733 kfree(mdsc->sessions); in register_session()
735 mdsc->sessions = sa; in register_session()
736 mdsc->max_sessions = newmax; in register_session()
740 s->s_mdsc = mdsc; in register_session()
747 ceph_con_init(&s->s_con, s, &mds_con_ops, &mdsc->fsc->client->msgr); in register_session()
771 mdsc->sessions[mds] = s; in register_session()
772 atomic_inc(&mdsc->num_sessions); in register_session()
776 ceph_mdsmap_get_addr(mdsc->mdsmap, mds)); in register_session()
788 static void __unregister_session(struct ceph_mds_client *mdsc, in __unregister_session() argument
792 BUG_ON(mdsc->sessions[s->s_mds] != s); in __unregister_session()
793 mdsc->sessions[s->s_mds] = NULL; in __unregister_session()
796 atomic_dec(&mdsc->num_sessions); in __unregister_session()
812 void ceph_mdsc_iterate_sessions(struct ceph_mds_client *mdsc, in ceph_mdsc_iterate_sessions() argument
818 mutex_lock(&mdsc->mutex); in ceph_mdsc_iterate_sessions()
819 for (mds = 0; mds < mdsc->max_sessions; ++mds) { in ceph_mdsc_iterate_sessions()
822 s = __ceph_lookup_mds_session(mdsc, mds); in ceph_mdsc_iterate_sessions()
831 mutex_unlock(&mdsc->mutex); in ceph_mdsc_iterate_sessions()
834 mutex_lock(&mdsc->mutex); in ceph_mdsc_iterate_sessions()
836 mutex_unlock(&mdsc->mutex); in ceph_mdsc_iterate_sessions()
893 lookup_get_request(struct ceph_mds_client *mdsc, u64 tid) in DEFINE_RB_FUNCS()
897 req = lookup_request(&mdsc->request_tree, tid); in DEFINE_RB_FUNCS()
910 static void __register_request(struct ceph_mds_client *mdsc, in __register_request() argument
916 req->r_tid = ++mdsc->last_tid; in __register_request()
918 ret = ceph_reserve_caps(mdsc, &req->r_caps_reservation, in __register_request()
930 insert_request(&mdsc->request_tree, req); in __register_request()
935 if (mdsc->oldest_tid == 0 && req->r_op != CEPH_MDS_OP_SETFILELOCK) in __register_request()
936 mdsc->oldest_tid = req->r_tid; in __register_request()
949 static void __unregister_request(struct ceph_mds_client *mdsc, in __unregister_request() argument
957 if (req->r_tid == mdsc->oldest_tid) { in __unregister_request()
959 mdsc->oldest_tid = 0; in __unregister_request()
964 mdsc->oldest_tid = next_req->r_tid; in __unregister_request()
971 erase_request(&mdsc->request_tree, req); in __unregister_request()
1028 static int __choose_mds(struct ceph_mds_client *mdsc, in __choose_mds() argument
1048 (__have_session(mdsc, req->r_resend_mds) || in __choose_mds()
1049 ceph_mdsmap_get_state(mdsc->mdsmap, req->r_resend_mds) > 0)) { in __choose_mds()
1079 if (!dir || dir->i_sb != mdsc->fsc->sb) { in __choose_mds()
1126 if (ceph_mdsmap_get_state(mdsc->mdsmap, mds) >= in __choose_mds()
1128 !ceph_mdsmap_is_laggy(mdsc->mdsmap, mds)) in __choose_mds()
1141 if (ceph_mdsmap_get_state(mdsc->mdsmap, mds) >= in __choose_mds()
1143 if (!ceph_mdsmap_is_laggy(mdsc->mdsmap, in __choose_mds()
1178 mds = ceph_mdsmap_get_random_mds(mdsc->mdsmap); in __choose_mds()
1283 static struct ceph_msg *create_session_open_msg(struct ceph_mds_client *mdsc, u64 seq) in create_session_open_msg() argument
1290 struct ceph_options *opt = mdsc->fsc->client->options; in create_session_open_msg()
1291 struct ceph_mount_options *fsopt = mdsc->fsc->mount_options; in create_session_open_msg()
1297 {"hostname", mdsc->nodename}, in create_session_open_msg()
1393 static int __open_session(struct ceph_mds_client *mdsc, in __open_session() argument
1401 mstate = ceph_mdsmap_get_state(mdsc->mdsmap, mds); in __open_session()
1408 msg = create_session_open_msg(mdsc, session->s_seq); in __open_session()
1421 __open_export_target_session(struct ceph_mds_client *mdsc, int target) in __open_export_target_session() argument
1426 session = __ceph_lookup_mds_session(mdsc, target); in __open_export_target_session()
1428 session = register_session(mdsc, target); in __open_export_target_session()
1434 ret = __open_session(mdsc, session); in __open_export_target_session()
1443 ceph_mdsc_open_export_target_session(struct ceph_mds_client *mdsc, int target) in ceph_mdsc_open_export_target_session() argument
1449 mutex_lock(&mdsc->mutex); in ceph_mdsc_open_export_target_session()
1450 session = __open_export_target_session(mdsc, target); in ceph_mdsc_open_export_target_session()
1451 mutex_unlock(&mdsc->mutex); in ceph_mdsc_open_export_target_session()
1456 static void __open_export_target_sessions(struct ceph_mds_client *mdsc, in __open_export_target_sessions() argument
1463 if (mds >= mdsc->mdsmap->possible_max_rank) in __open_export_target_sessions()
1466 mi = &mdsc->mdsmap->m_info[mds]; in __open_export_target_sessions()
1471 ts = __open_export_target_session(mdsc, mi->export_targets[i]); in __open_export_target_sessions()
1476 void ceph_mdsc_open_export_target_sessions(struct ceph_mds_client *mdsc, in ceph_mdsc_open_export_target_sessions() argument
1479 mutex_lock(&mdsc->mutex); in ceph_mdsc_open_export_target_sessions()
1480 __open_export_target_sessions(mdsc, session); in ceph_mdsc_open_export_target_sessions()
1481 mutex_unlock(&mdsc->mutex); in ceph_mdsc_open_export_target_sessions()
1498 static void dispose_cap_releases(struct ceph_mds_client *mdsc, in dispose_cap_releases() argument
1506 ceph_put_cap(mdsc, cap); in dispose_cap_releases()
1510 static void cleanup_session_requests(struct ceph_mds_client *mdsc, in cleanup_session_requests() argument
1517 mutex_lock(&mdsc->mutex); in cleanup_session_requests()
1527 __unregister_request(mdsc, req); in cleanup_session_requests()
1530 p = rb_first(&mdsc->request_tree); in cleanup_session_requests()
1538 mutex_unlock(&mdsc->mutex); in cleanup_session_requests()
1614 static int remove_capsnaps(struct ceph_mds_client *mdsc, struct inode *inode) in remove_capsnaps() argument
1633 wake_up_all(&mdsc->cap_flushing_wq); in remove_capsnaps()
1641 struct ceph_mds_client *mdsc = fsc->mdsc; in remove_session_caps_cb() local
1668 spin_lock(&mdsc->cap_dirty_lock); in remove_session_caps_cb()
1689 mdsc->num_cap_flushing--; in remove_session_caps_cb()
1692 spin_unlock(&mdsc->cap_dirty_lock); in remove_session_caps_cb()
1719 capsnap_release = remove_capsnaps(mdsc, inode); in remove_session_caps_cb()
1753 wake_up_all(&fsc->mdsc->cap_flushing_wq); in remove_session_caps()
1842 static int send_renew_caps(struct ceph_mds_client *mdsc, in send_renew_caps() argument
1855 state = ceph_mdsmap_get_state(mdsc->mdsmap, session->s_mds); in send_renew_caps()
1872 static int send_flushmsg_ack(struct ceph_mds_client *mdsc, in send_flushmsg_ack() argument
1892 static void renewed_caps(struct ceph_mds_client *mdsc, in renewed_caps() argument
1902 mdsc->mdsmap->m_session_timeout*HZ; in renewed_caps()
1942 static int __close_session(struct ceph_mds_client *mdsc, in __close_session() argument
2057 int ceph_trim_caps(struct ceph_mds_client *mdsc, in ceph_trim_caps() argument
2074 ceph_flush_cap_releases(mdsc, session); in ceph_trim_caps()
2078 static int check_caps_flush(struct ceph_mds_client *mdsc, in check_caps_flush() argument
2083 spin_lock(&mdsc->cap_dirty_lock); in check_caps_flush()
2084 if (!list_empty(&mdsc->cap_flush_list)) { in check_caps_flush()
2086 list_first_entry(&mdsc->cap_flush_list, in check_caps_flush()
2094 spin_unlock(&mdsc->cap_dirty_lock); in check_caps_flush()
2103 static void wait_caps_flush(struct ceph_mds_client *mdsc, in wait_caps_flush() argument
2108 wait_event(mdsc->cap_flushing_wq, in wait_caps_flush()
2109 check_caps_flush(mdsc, want_flush_tid)); in wait_caps_flush()
2117 static void ceph_send_cap_releases(struct ceph_mds_client *mdsc, in ceph_send_cap_releases() argument
2123 struct ceph_osd_client *osdc = &mdsc->fsc->client->osdc; in ceph_send_cap_releases()
2169 ceph_put_cap(mdsc, cap); in ceph_send_cap_releases()
2224 void ceph_flush_cap_releases(struct ceph_mds_client *mdsc, in ceph_flush_cap_releases() argument
2227 if (mdsc->stopping) in ceph_flush_cap_releases()
2231 if (queue_work(mdsc->fsc->cap_wq, in ceph_flush_cap_releases()
2255 struct ceph_mds_client *mdsc = in ceph_cap_reclaim_work() local
2257 int ret = ceph_trim_dentries(mdsc); in ceph_cap_reclaim_work()
2259 ceph_queue_cap_reclaim_work(mdsc); in ceph_cap_reclaim_work()
2262 void ceph_queue_cap_reclaim_work(struct ceph_mds_client *mdsc) in ceph_queue_cap_reclaim_work() argument
2264 if (mdsc->stopping) in ceph_queue_cap_reclaim_work()
2267 if (queue_work(mdsc->fsc->cap_wq, &mdsc->cap_reclaim_work)) { in ceph_queue_cap_reclaim_work()
2274 void ceph_reclaim_caps_nr(struct ceph_mds_client *mdsc, int nr) in ceph_reclaim_caps_nr() argument
2279 val = atomic_add_return(nr, &mdsc->cap_reclaim_pending); in ceph_reclaim_caps_nr()
2281 atomic_set(&mdsc->cap_reclaim_pending, 0); in ceph_reclaim_caps_nr()
2282 ceph_queue_cap_reclaim_work(mdsc); in ceph_reclaim_caps_nr()
2332 ceph_mdsc_create_request(struct ceph_mds_client *mdsc, int op, int mode) in ceph_mdsc_create_request() argument
2341 req->r_mdsc = mdsc; in ceph_mdsc_create_request()
2367 static struct ceph_mds_request *__get_oldest_req(struct ceph_mds_client *mdsc) in __get_oldest_req() argument
2369 if (RB_EMPTY_ROOT(&mdsc->request_tree)) in __get_oldest_req()
2371 return rb_entry(rb_first(&mdsc->request_tree), in __get_oldest_req()
2375 static inline u64 __get_oldest_tid(struct ceph_mds_client *mdsc) in __get_oldest_tid() argument
2377 return mdsc->oldest_tid; in __get_oldest_tid()
2549 static struct ceph_msg *create_request_message(struct ceph_mds_client *mdsc, in create_request_message() argument
2611 head->mdsmap_epoch = cpu_to_le32(mdsc->mdsmap->m_epoch); in create_request_message()
2692 static void complete_request(struct ceph_mds_client *mdsc, in complete_request() argument
2698 req->r_callback(mdsc, req); in complete_request()
2705 static int __prepare_send_request(struct ceph_mds_client *mdsc, in __prepare_send_request() argument
2766 msg = create_request_message(mdsc, req, mds, drop_cap_releases); in __prepare_send_request()
2774 rhead->oldest_client_tid = cpu_to_le64(__get_oldest_tid(mdsc)); in __prepare_send_request()
2792 static int __send_request(struct ceph_mds_client *mdsc, in __send_request() argument
2799 err = __prepare_send_request(mdsc, req, session->s_mds, in __send_request()
2812 static void __do_request(struct ceph_mds_client *mdsc, in __do_request() argument
2822 __unregister_request(mdsc, req); in __do_request()
2832 if (READ_ONCE(mdsc->fsc->mount_state) == CEPH_MOUNT_SHUTDOWN) { in __do_request()
2837 if (READ_ONCE(mdsc->fsc->mount_state) == CEPH_MOUNT_MOUNTING) { in __do_request()
2838 if (mdsc->mdsmap_err) { in __do_request()
2839 err = mdsc->mdsmap_err; in __do_request()
2843 if (mdsc->mdsmap->m_epoch == 0) { in __do_request()
2845 list_add(&req->r_wait, &mdsc->waiting_for_map); in __do_request()
2848 if (!(mdsc->fsc->mount_options->flags & in __do_request()
2850 !ceph_mdsmap_is_cluster_available(mdsc->mdsmap)) { in __do_request()
2858 mds = __choose_mds(mdsc, req, &random); in __do_request()
2860 ceph_mdsmap_get_state(mdsc->mdsmap, mds) < CEPH_MDS_STATE_ACTIVE) { in __do_request()
2866 list_add(&req->r_wait, &mdsc->waiting_for_map); in __do_request()
2871 session = __ceph_lookup_mds_session(mdsc, mds); in __do_request()
2873 session = register_session(mdsc, mds); in __do_request()
2900 err = __open_session(mdsc, session); in __do_request()
2917 err = __send_request(mdsc, session, req, false); in __do_request()
2925 complete_request(mdsc, req); in __do_request()
2926 __unregister_request(mdsc, req); in __do_request()
2934 static void __wake_requests(struct ceph_mds_client *mdsc, in __wake_requests() argument
2947 __do_request(mdsc, req); in __wake_requests()
2955 static void kick_requests(struct ceph_mds_client *mdsc, int mds) in kick_requests() argument
2958 struct rb_node *p = rb_first(&mdsc->request_tree); in kick_requests()
2972 __do_request(mdsc, req); in kick_requests()
2977 int ceph_mdsc_submit_request(struct ceph_mds_client *mdsc, struct inode *dir, in ceph_mdsc_submit_request() argument
2991 __ceph_touch_fmode(ci, mdsc, fmode); in ceph_mdsc_submit_request()
3018 mutex_lock(&mdsc->mutex); in ceph_mdsc_submit_request()
3019 __register_request(mdsc, req, dir); in ceph_mdsc_submit_request()
3020 __do_request(mdsc, req); in ceph_mdsc_submit_request()
3022 mutex_unlock(&mdsc->mutex); in ceph_mdsc_submit_request()
3026 static int ceph_mdsc_wait_request(struct ceph_mds_client *mdsc, in ceph_mdsc_wait_request() argument
3034 err = req->r_wait_for_completion(mdsc, req); in ceph_mdsc_wait_request()
3047 mutex_lock(&mdsc->mutex); in ceph_mdsc_wait_request()
3072 mutex_unlock(&mdsc->mutex); in ceph_mdsc_wait_request()
3080 int ceph_mdsc_do_request(struct ceph_mds_client *mdsc, in ceph_mdsc_do_request() argument
3089 err = ceph_mdsc_submit_request(mdsc, dir, req); in ceph_mdsc_do_request()
3091 err = ceph_mdsc_wait_request(mdsc, req); in ceph_mdsc_do_request()
3125 struct ceph_mds_client *mdsc = session->s_mdsc; in handle_reply() local
3142 mutex_lock(&mdsc->mutex); in handle_reply()
3143 req = lookup_get_request(mdsc, tid); in handle_reply()
3146 mutex_unlock(&mdsc->mutex); in handle_reply()
3156 mutex_unlock(&mdsc->mutex); in handle_reply()
3165 mutex_unlock(&mdsc->mutex); in handle_reply()
3171 mutex_unlock(&mdsc->mutex); in handle_reply()
3190 __do_request(mdsc, req); in handle_reply()
3191 mutex_unlock(&mdsc->mutex); in handle_reply()
3194 int mds = __choose_mds(mdsc, req, NULL); in handle_reply()
3197 __do_request(mdsc, req); in handle_reply()
3198 mutex_unlock(&mdsc->mutex); in handle_reply()
3208 __unregister_request(mdsc, req); in handle_reply()
3211 if (mdsc->stopping && !__get_oldest_req(mdsc)) in handle_reply()
3212 complete_all(&mdsc->safe_umount_waiters); in handle_reply()
3224 mutex_unlock(&mdsc->mutex); in handle_reply()
3238 mutex_unlock(&mdsc->mutex); in handle_reply()
3250 down_write(&mdsc->snap_rwsem); in handle_reply()
3251 ceph_update_snap_trace(mdsc, rinfo->snapblob, in handle_reply()
3255 downgrade_write(&mdsc->snap_rwsem); in handle_reply()
3257 down_read(&mdsc->snap_rwsem); in handle_reply()
3263 err = ceph_fill_trace(mdsc->fsc->sb, req); in handle_reply()
3272 up_read(&mdsc->snap_rwsem); in handle_reply()
3274 ceph_put_snap_realm(mdsc, realm); in handle_reply()
3287 ceph_unreserve_caps(mdsc, &req->r_caps_reservation); in handle_reply()
3290 mutex_lock(&mdsc->mutex); in handle_reply()
3301 mutex_unlock(&mdsc->mutex); in handle_reply()
3306 complete_request(mdsc, req); in handle_reply()
3308 ceph_update_metadata_latency(&mdsc->metric, req->r_start_latency, in handle_reply()
3320 static void handle_forward(struct ceph_mds_client *mdsc, in handle_forward() argument
3336 mutex_lock(&mdsc->mutex); in handle_forward()
3337 req = lookup_get_request(mdsc, tid); in handle_forward()
3345 __unregister_request(mdsc, req); in handle_forward()
3358 __do_request(mdsc, req); in handle_forward()
3362 mutex_unlock(&mdsc->mutex); in handle_forward()
3403 struct ceph_mds_client *mdsc = session->s_mdsc; in handle_session() local
3435 mutex_lock(&mdsc->mutex); in handle_session()
3438 __unregister_session(mdsc, session); in handle_session()
3441 session->s_ttl = jiffies + HZ*mdsc->mdsmap->m_session_autoclose; in handle_session()
3442 mutex_unlock(&mdsc->mutex); in handle_session()
3461 renewed_caps(mdsc, session, 0); in handle_session()
3463 metric_schedule_delayed(&mdsc->metric); in handle_session()
3465 if (mdsc->stopping) in handle_session()
3466 __close_session(mdsc, session); in handle_session()
3471 renewed_caps(mdsc, session, 1); in handle_session()
3478 cleanup_session_requests(mdsc, session); in handle_session()
3481 wake_up_all(&mdsc->session_close_wq); in handle_session()
3491 send_renew_caps(mdsc, session); in handle_session()
3495 ceph_trim_caps(mdsc, session, le32_to_cpu(h->max_caps)); in handle_session()
3499 send_flushmsg_ack(mdsc, session, seq); in handle_session()
3514 cleanup_session_requests(mdsc, session); in handle_session()
3517 mdsc->fsc->blocklisted = true; in handle_session()
3528 mutex_lock(&mdsc->mutex); in handle_session()
3529 __wake_requests(mdsc, &session->s_waiting); in handle_session()
3531 kick_requests(mdsc, mds); in handle_session()
3532 mutex_unlock(&mdsc->mutex); in handle_session()
3571 static void replay_unsafe_requests(struct ceph_mds_client *mdsc, in replay_unsafe_requests() argument
3579 mutex_lock(&mdsc->mutex); in replay_unsafe_requests()
3581 __send_request(mdsc, session, req, true); in replay_unsafe_requests()
3587 p = rb_first(&mdsc->request_tree); in replay_unsafe_requests()
3602 __send_request(mdsc, session, req, true); in replay_unsafe_requests()
3604 mutex_unlock(&mdsc->mutex); in replay_unsafe_requests()
3898 static int encode_snap_realms(struct ceph_mds_client *mdsc, in encode_snap_realms() argument
3906 err = ceph_pagelist_encode_32(pagelist, mdsc->num_snap_realms); in encode_snap_realms()
3916 for (p = rb_first(&mdsc->snap_realms); p; p = rb_next(p)) { in encode_snap_realms()
3968 static void send_mds_reconnect(struct ceph_mds_client *mdsc, in send_mds_reconnect() argument
4014 dispose_cap_releases(mdsc, &dispose); in send_mds_reconnect()
4017 if (mdsc->fsc->sb->s_root) in send_mds_reconnect()
4018 shrink_dcache_parent(mdsc->fsc->sb->s_root); in send_mds_reconnect()
4023 ceph_mdsmap_get_addr(mdsc->mdsmap, mds)); in send_mds_reconnect()
4026 replay_unsafe_requests(mdsc, session); in send_mds_reconnect()
4028 ceph_early_kick_flushing_caps(mdsc, session); in send_mds_reconnect()
4030 down_read(&mdsc->snap_rwsem); in send_mds_reconnect()
4056 if (mdsc->num_snap_realms) { in send_mds_reconnect()
4059 mdsc->num_snap_realms * in send_mds_reconnect()
4065 total_len += mdsc->num_snap_realms * in send_mds_reconnect()
4082 err = encode_snap_realms(mdsc, &recon_state); in send_mds_reconnect()
4098 WARN_ON(recon_state.nr_realms != mdsc->num_snap_realms); in send_mds_reconnect()
4117 mutex_lock(&mdsc->mutex); in send_mds_reconnect()
4118 __wake_requests(mdsc, &session->s_waiting); in send_mds_reconnect()
4119 mutex_unlock(&mdsc->mutex); in send_mds_reconnect()
4121 up_read(&mdsc->snap_rwsem); in send_mds_reconnect()
4127 up_read(&mdsc->snap_rwsem); in send_mds_reconnect()
4143 static void check_new_map(struct ceph_mds_client *mdsc, in check_new_map() argument
4154 for (i = 0; i < oldmap->possible_max_rank && i < mdsc->max_sessions; i++) { in check_new_map()
4155 if (!mdsc->sessions[i]) in check_new_map()
4157 s = mdsc->sessions[i]; in check_new_map()
4171 __unregister_session(mdsc, s); in check_new_map()
4172 __wake_requests(mdsc, &s->s_waiting); in check_new_map()
4173 mutex_unlock(&mdsc->mutex); in check_new_map()
4176 cleanup_session_requests(mdsc, s); in check_new_map()
4182 mutex_lock(&mdsc->mutex); in check_new_map()
4183 kick_requests(mdsc, i); in check_new_map()
4191 mutex_unlock(&mdsc->mutex); in check_new_map()
4193 mutex_lock(&mdsc->mutex); in check_new_map()
4206 mutex_unlock(&mdsc->mutex); in check_new_map()
4207 send_mds_reconnect(mdsc, s); in check_new_map()
4208 mutex_lock(&mdsc->mutex); in check_new_map()
4219 kick_requests(mdsc, i); in check_new_map()
4220 mutex_unlock(&mdsc->mutex); in check_new_map()
4222 mutex_lock(&mdsc->mutex); in check_new_map()
4223 ceph_kick_flushing_caps(mdsc, s); in check_new_map()
4229 for (i = 0; i < newmap->possible_max_rank && i < mdsc->max_sessions; i++) { in check_new_map()
4230 s = mdsc->sessions[i]; in check_new_map()
4240 __open_export_target_sessions(mdsc, s); in check_new_map()
4262 static void handle_lease(struct ceph_mds_client *mdsc, in handle_lease() argument
4266 struct super_block *sb = mdsc->fsc->sb; in handle_lease()
4415 static void maybe_recover_session(struct ceph_mds_client *mdsc) in maybe_recover_session() argument
4417 struct ceph_fs_client *fsc = mdsc->fsc; in maybe_recover_session()
4486 static void schedule_delayed(struct ceph_mds_client *mdsc, unsigned long delay) in schedule_delayed() argument
4493 schedule_delayed_work(&mdsc->delayed_work, in schedule_delayed()
4499 struct ceph_mds_client *mdsc = in delayed_work() local
4508 if (mdsc->stopping) in delayed_work()
4511 mutex_lock(&mdsc->mutex); in delayed_work()
4512 renew_interval = mdsc->mdsmap->m_session_timeout >> 2; in delayed_work()
4514 mdsc->last_renew_caps); in delayed_work()
4516 mdsc->last_renew_caps = jiffies; in delayed_work()
4518 for (i = 0; i < mdsc->max_sessions; i++) { in delayed_work()
4519 struct ceph_mds_session *s = __ceph_lookup_mds_session(mdsc, i); in delayed_work()
4527 mutex_unlock(&mdsc->mutex); in delayed_work()
4531 send_renew_caps(mdsc, s); in delayed_work()
4536 ceph_send_cap_releases(mdsc, s); in delayed_work()
4540 mutex_lock(&mdsc->mutex); in delayed_work()
4542 mutex_unlock(&mdsc->mutex); in delayed_work()
4544 delay = ceph_check_delayed_caps(mdsc); in delayed_work()
4546 ceph_queue_cap_reclaim_work(mdsc); in delayed_work()
4548 ceph_trim_snapid_map(mdsc); in delayed_work()
4550 maybe_recover_session(mdsc); in delayed_work()
4552 schedule_delayed(mdsc, delay); in delayed_work()
4558 struct ceph_mds_client *mdsc; in ceph_mdsc_init() local
4561 mdsc = kzalloc(sizeof(struct ceph_mds_client), GFP_NOFS); in ceph_mdsc_init()
4562 if (!mdsc) in ceph_mdsc_init()
4564 mdsc->fsc = fsc; in ceph_mdsc_init()
4565 mutex_init(&mdsc->mutex); in ceph_mdsc_init()
4566 mdsc->mdsmap = kzalloc(sizeof(*mdsc->mdsmap), GFP_NOFS); in ceph_mdsc_init()
4567 if (!mdsc->mdsmap) { in ceph_mdsc_init()
4572 init_completion(&mdsc->safe_umount_waiters); in ceph_mdsc_init()
4573 init_waitqueue_head(&mdsc->session_close_wq); in ceph_mdsc_init()
4574 INIT_LIST_HEAD(&mdsc->waiting_for_map); in ceph_mdsc_init()
4575 mdsc->sessions = NULL; in ceph_mdsc_init()
4576 atomic_set(&mdsc->num_sessions, 0); in ceph_mdsc_init()
4577 mdsc->max_sessions = 0; in ceph_mdsc_init()
4578 mdsc->stopping = 0; in ceph_mdsc_init()
4579 atomic64_set(&mdsc->quotarealms_count, 0); in ceph_mdsc_init()
4580 mdsc->quotarealms_inodes = RB_ROOT; in ceph_mdsc_init()
4581 mutex_init(&mdsc->quotarealms_inodes_mutex); in ceph_mdsc_init()
4582 mdsc->last_snap_seq = 0; in ceph_mdsc_init()
4583 init_rwsem(&mdsc->snap_rwsem); in ceph_mdsc_init()
4584 mdsc->snap_realms = RB_ROOT; in ceph_mdsc_init()
4585 INIT_LIST_HEAD(&mdsc->snap_empty); in ceph_mdsc_init()
4586 mdsc->num_snap_realms = 0; in ceph_mdsc_init()
4587 spin_lock_init(&mdsc->snap_empty_lock); in ceph_mdsc_init()
4588 mdsc->last_tid = 0; in ceph_mdsc_init()
4589 mdsc->oldest_tid = 0; in ceph_mdsc_init()
4590 mdsc->request_tree = RB_ROOT; in ceph_mdsc_init()
4591 INIT_DELAYED_WORK(&mdsc->delayed_work, delayed_work); in ceph_mdsc_init()
4592 mdsc->last_renew_caps = jiffies; in ceph_mdsc_init()
4593 INIT_LIST_HEAD(&mdsc->cap_delay_list); in ceph_mdsc_init()
4594 INIT_LIST_HEAD(&mdsc->cap_wait_list); in ceph_mdsc_init()
4595 spin_lock_init(&mdsc->cap_delay_lock); in ceph_mdsc_init()
4596 INIT_LIST_HEAD(&mdsc->snap_flush_list); in ceph_mdsc_init()
4597 spin_lock_init(&mdsc->snap_flush_lock); in ceph_mdsc_init()
4598 mdsc->last_cap_flush_tid = 1; in ceph_mdsc_init()
4599 INIT_LIST_HEAD(&mdsc->cap_flush_list); in ceph_mdsc_init()
4600 INIT_LIST_HEAD(&mdsc->cap_dirty_migrating); in ceph_mdsc_init()
4601 mdsc->num_cap_flushing = 0; in ceph_mdsc_init()
4602 spin_lock_init(&mdsc->cap_dirty_lock); in ceph_mdsc_init()
4603 init_waitqueue_head(&mdsc->cap_flushing_wq); in ceph_mdsc_init()
4604 INIT_WORK(&mdsc->cap_reclaim_work, ceph_cap_reclaim_work); in ceph_mdsc_init()
4605 atomic_set(&mdsc->cap_reclaim_pending, 0); in ceph_mdsc_init()
4606 err = ceph_metric_init(&mdsc->metric); in ceph_mdsc_init()
4610 spin_lock_init(&mdsc->dentry_list_lock); in ceph_mdsc_init()
4611 INIT_LIST_HEAD(&mdsc->dentry_leases); in ceph_mdsc_init()
4612 INIT_LIST_HEAD(&mdsc->dentry_dir_leases); in ceph_mdsc_init()
4614 ceph_caps_init(mdsc); in ceph_mdsc_init()
4615 ceph_adjust_caps_max_min(mdsc, fsc->mount_options); in ceph_mdsc_init()
4617 spin_lock_init(&mdsc->snapid_map_lock); in ceph_mdsc_init()
4618 mdsc->snapid_map_tree = RB_ROOT; in ceph_mdsc_init()
4619 INIT_LIST_HEAD(&mdsc->snapid_map_lru); in ceph_mdsc_init()
4621 init_rwsem(&mdsc->pool_perm_rwsem); in ceph_mdsc_init()
4622 mdsc->pool_perm_tree = RB_ROOT; in ceph_mdsc_init()
4624 strscpy(mdsc->nodename, utsname()->nodename, in ceph_mdsc_init()
4625 sizeof(mdsc->nodename)); in ceph_mdsc_init()
4627 fsc->mdsc = mdsc; in ceph_mdsc_init()
4631 kfree(mdsc->mdsmap); in ceph_mdsc_init()
4633 kfree(mdsc); in ceph_mdsc_init()
4641 static void wait_requests(struct ceph_mds_client *mdsc) in wait_requests() argument
4643 struct ceph_options *opts = mdsc->fsc->client->options; in wait_requests()
4646 mutex_lock(&mdsc->mutex); in wait_requests()
4647 if (__get_oldest_req(mdsc)) { in wait_requests()
4648 mutex_unlock(&mdsc->mutex); in wait_requests()
4651 wait_for_completion_timeout(&mdsc->safe_umount_waiters, in wait_requests()
4655 mutex_lock(&mdsc->mutex); in wait_requests()
4656 while ((req = __get_oldest_req(mdsc))) { in wait_requests()
4660 __unregister_request(mdsc, req); in wait_requests()
4663 mutex_unlock(&mdsc->mutex); in wait_requests()
4695 void ceph_mdsc_pre_umount(struct ceph_mds_client *mdsc) in ceph_mdsc_pre_umount() argument
4698 mdsc->stopping = 1; in ceph_mdsc_pre_umount()
4700 ceph_mdsc_iterate_sessions(mdsc, send_flush_mdlog, true); in ceph_mdsc_pre_umount()
4701 ceph_mdsc_iterate_sessions(mdsc, lock_unlock_session, false); in ceph_mdsc_pre_umount()
4702 ceph_flush_dirty_caps(mdsc); in ceph_mdsc_pre_umount()
4703 wait_requests(mdsc); in ceph_mdsc_pre_umount()
4711 ceph_cleanup_quotarealms_inodes(mdsc); in ceph_mdsc_pre_umount()
4717 static void wait_unsafe_requests(struct ceph_mds_client *mdsc, u64 want_tid) in wait_unsafe_requests() argument
4722 mutex_lock(&mdsc->mutex); in wait_unsafe_requests()
4725 req = __get_oldest_req(mdsc); in wait_unsafe_requests()
4739 mutex_unlock(&mdsc->mutex); in wait_unsafe_requests()
4743 mutex_lock(&mdsc->mutex); in wait_unsafe_requests()
4756 mutex_unlock(&mdsc->mutex); in wait_unsafe_requests()
4760 void ceph_mdsc_sync(struct ceph_mds_client *mdsc) in ceph_mdsc_sync() argument
4764 if (READ_ONCE(mdsc->fsc->mount_state) == CEPH_MOUNT_SHUTDOWN) in ceph_mdsc_sync()
4768 mutex_lock(&mdsc->mutex); in ceph_mdsc_sync()
4769 want_tid = mdsc->last_tid; in ceph_mdsc_sync()
4770 mutex_unlock(&mdsc->mutex); in ceph_mdsc_sync()
4772 ceph_flush_dirty_caps(mdsc); in ceph_mdsc_sync()
4773 spin_lock(&mdsc->cap_dirty_lock); in ceph_mdsc_sync()
4774 want_flush = mdsc->last_cap_flush_tid; in ceph_mdsc_sync()
4775 if (!list_empty(&mdsc->cap_flush_list)) { in ceph_mdsc_sync()
4777 list_last_entry(&mdsc->cap_flush_list, in ceph_mdsc_sync()
4781 spin_unlock(&mdsc->cap_dirty_lock); in ceph_mdsc_sync()
4786 wait_unsafe_requests(mdsc, want_tid); in ceph_mdsc_sync()
4787 wait_caps_flush(mdsc, want_flush); in ceph_mdsc_sync()
4793 static bool done_closing_sessions(struct ceph_mds_client *mdsc, int skipped) in done_closing_sessions() argument
4795 if (READ_ONCE(mdsc->fsc->mount_state) == CEPH_MOUNT_SHUTDOWN) in done_closing_sessions()
4797 return atomic_read(&mdsc->num_sessions) <= skipped; in done_closing_sessions()
4803 void ceph_mdsc_close_sessions(struct ceph_mds_client *mdsc) in ceph_mdsc_close_sessions() argument
4805 struct ceph_options *opts = mdsc->fsc->client->options; in ceph_mdsc_close_sessions()
4813 mutex_lock(&mdsc->mutex); in ceph_mdsc_close_sessions()
4814 for (i = 0; i < mdsc->max_sessions; i++) { in ceph_mdsc_close_sessions()
4815 session = __ceph_lookup_mds_session(mdsc, i); in ceph_mdsc_close_sessions()
4818 mutex_unlock(&mdsc->mutex); in ceph_mdsc_close_sessions()
4820 if (__close_session(mdsc, session) <= 0) in ceph_mdsc_close_sessions()
4824 mutex_lock(&mdsc->mutex); in ceph_mdsc_close_sessions()
4826 mutex_unlock(&mdsc->mutex); in ceph_mdsc_close_sessions()
4829 wait_event_timeout(mdsc->session_close_wq, in ceph_mdsc_close_sessions()
4830 done_closing_sessions(mdsc, skipped), in ceph_mdsc_close_sessions()
4834 mutex_lock(&mdsc->mutex); in ceph_mdsc_close_sessions()
4835 for (i = 0; i < mdsc->max_sessions; i++) { in ceph_mdsc_close_sessions()
4836 if (mdsc->sessions[i]) { in ceph_mdsc_close_sessions()
4837 session = ceph_get_mds_session(mdsc->sessions[i]); in ceph_mdsc_close_sessions()
4838 __unregister_session(mdsc, session); in ceph_mdsc_close_sessions()
4839 mutex_unlock(&mdsc->mutex); in ceph_mdsc_close_sessions()
4844 mutex_lock(&mdsc->mutex); in ceph_mdsc_close_sessions()
4847 WARN_ON(!list_empty(&mdsc->cap_delay_list)); in ceph_mdsc_close_sessions()
4848 mutex_unlock(&mdsc->mutex); in ceph_mdsc_close_sessions()
4850 ceph_cleanup_snapid_map(mdsc); in ceph_mdsc_close_sessions()
4851 ceph_cleanup_empty_realms(mdsc); in ceph_mdsc_close_sessions()
4853 cancel_work_sync(&mdsc->cap_reclaim_work); in ceph_mdsc_close_sessions()
4854 cancel_delayed_work_sync(&mdsc->delayed_work); /* cancel timer */ in ceph_mdsc_close_sessions()
4859 void ceph_mdsc_force_umount(struct ceph_mds_client *mdsc) in ceph_mdsc_force_umount() argument
4866 mutex_lock(&mdsc->mutex); in ceph_mdsc_force_umount()
4867 for (mds = 0; mds < mdsc->max_sessions; mds++) { in ceph_mdsc_force_umount()
4868 session = __ceph_lookup_mds_session(mdsc, mds); in ceph_mdsc_force_umount()
4873 __unregister_session(mdsc, session); in ceph_mdsc_force_umount()
4874 __wake_requests(mdsc, &session->s_waiting); in ceph_mdsc_force_umount()
4875 mutex_unlock(&mdsc->mutex); in ceph_mdsc_force_umount()
4878 __close_session(mdsc, session); in ceph_mdsc_force_umount()
4880 cleanup_session_requests(mdsc, session); in ceph_mdsc_force_umount()
4886 mutex_lock(&mdsc->mutex); in ceph_mdsc_force_umount()
4887 kick_requests(mdsc, mds); in ceph_mdsc_force_umount()
4889 __wake_requests(mdsc, &mdsc->waiting_for_map); in ceph_mdsc_force_umount()
4890 mutex_unlock(&mdsc->mutex); in ceph_mdsc_force_umount()
4893 static void ceph_mdsc_stop(struct ceph_mds_client *mdsc) in ceph_mdsc_stop() argument
4904 flush_delayed_work(&mdsc->delayed_work); in ceph_mdsc_stop()
4906 if (mdsc->mdsmap) in ceph_mdsc_stop()
4907 ceph_mdsmap_destroy(mdsc->mdsmap); in ceph_mdsc_stop()
4908 kfree(mdsc->sessions); in ceph_mdsc_stop()
4909 ceph_caps_finalize(mdsc); in ceph_mdsc_stop()
4910 ceph_pool_perm_destroy(mdsc); in ceph_mdsc_stop()
4915 struct ceph_mds_client *mdsc = fsc->mdsc; in ceph_mdsc_destroy() local
4916 dout("mdsc_destroy %p\n", mdsc); in ceph_mdsc_destroy()
4918 if (!mdsc) in ceph_mdsc_destroy()
4924 ceph_mdsc_stop(mdsc); in ceph_mdsc_destroy()
4926 ceph_metric_destroy(&mdsc->metric); in ceph_mdsc_destroy()
4928 fsc->mdsc = NULL; in ceph_mdsc_destroy()
4929 kfree(mdsc); in ceph_mdsc_destroy()
4930 dout("mdsc_destroy %p done\n", mdsc); in ceph_mdsc_destroy()
4933 void ceph_mdsc_handle_fsmap(struct ceph_mds_client *mdsc, struct ceph_msg *msg) in ceph_mdsc_handle_fsmap() argument
4935 struct ceph_fs_client *fsc = mdsc->fsc; in ceph_mdsc_handle_fsmap()
5003 mutex_lock(&mdsc->mutex); in ceph_mdsc_handle_fsmap()
5004 mdsc->mdsmap_err = err; in ceph_mdsc_handle_fsmap()
5005 __wake_requests(mdsc, &mdsc->waiting_for_map); in ceph_mdsc_handle_fsmap()
5006 mutex_unlock(&mdsc->mutex); in ceph_mdsc_handle_fsmap()
5012 void ceph_mdsc_handle_mdsmap(struct ceph_mds_client *mdsc, struct ceph_msg *msg) in ceph_mdsc_handle_mdsmap() argument
5024 if (ceph_check_fsid(mdsc->fsc->client, &fsid) < 0) in ceph_mdsc_handle_mdsmap()
5031 mutex_lock(&mdsc->mutex); in ceph_mdsc_handle_mdsmap()
5032 if (mdsc->mdsmap && epoch <= mdsc->mdsmap->m_epoch) { in ceph_mdsc_handle_mdsmap()
5034 epoch, mdsc->mdsmap->m_epoch); in ceph_mdsc_handle_mdsmap()
5035 mutex_unlock(&mdsc->mutex); in ceph_mdsc_handle_mdsmap()
5046 if (mdsc->mdsmap) { in ceph_mdsc_handle_mdsmap()
5047 oldmap = mdsc->mdsmap; in ceph_mdsc_handle_mdsmap()
5048 mdsc->mdsmap = newmap; in ceph_mdsc_handle_mdsmap()
5049 check_new_map(mdsc, newmap, oldmap); in ceph_mdsc_handle_mdsmap()
5052 mdsc->mdsmap = newmap; /* first mds map */ in ceph_mdsc_handle_mdsmap()
5054 mdsc->fsc->max_file_size = min((loff_t)mdsc->mdsmap->m_max_file_size, in ceph_mdsc_handle_mdsmap()
5057 __wake_requests(mdsc, &mdsc->waiting_for_map); in ceph_mdsc_handle_mdsmap()
5058 ceph_monc_got_map(&mdsc->fsc->client->monc, CEPH_SUB_MDSMAP, in ceph_mdsc_handle_mdsmap()
5059 mdsc->mdsmap->m_epoch); in ceph_mdsc_handle_mdsmap()
5061 mutex_unlock(&mdsc->mutex); in ceph_mdsc_handle_mdsmap()
5062 schedule_delayed(mdsc, 0); in ceph_mdsc_handle_mdsmap()
5066 mutex_unlock(&mdsc->mutex); in ceph_mdsc_handle_mdsmap()
5095 struct ceph_mds_client *mdsc = s->s_mdsc; in peer_reset() local
5098 send_mds_reconnect(mdsc, s); in peer_reset()
5104 struct ceph_mds_client *mdsc = s->s_mdsc; in dispatch() local
5107 mutex_lock(&mdsc->mutex); in dispatch()
5108 if (__verify_registered_session(mdsc, s) < 0) { in dispatch()
5109 mutex_unlock(&mdsc->mutex); in dispatch()
5112 mutex_unlock(&mdsc->mutex); in dispatch()
5116 ceph_mdsc_handle_mdsmap(mdsc, msg); in dispatch()
5119 ceph_mdsc_handle_fsmap(mdsc, msg); in dispatch()
5128 handle_forward(mdsc, s, msg); in dispatch()
5134 ceph_handle_snap(mdsc, s, msg); in dispatch()
5137 handle_lease(mdsc, s, msg); in dispatch()
5140 ceph_handle_quota(mdsc, s, msg); in dispatch()
5163 struct ceph_mds_client *mdsc = s->s_mdsc; in get_authorizer() local
5164 struct ceph_auth_client *ac = mdsc->fsc->client->monc.auth; in get_authorizer()
5191 struct ceph_mds_client *mdsc = s->s_mdsc; in add_authorizer_challenge() local
5192 struct ceph_auth_client *ac = mdsc->fsc->client->monc.auth; in add_authorizer_challenge()
5201 struct ceph_mds_client *mdsc = s->s_mdsc; in verify_authorizer_reply() local
5202 struct ceph_auth_client *ac = mdsc->fsc->client->monc.auth; in verify_authorizer_reply()
5210 struct ceph_mds_client *mdsc = s->s_mdsc; in invalidate_authorizer() local
5211 struct ceph_auth_client *ac = mdsc->fsc->client->monc.auth; in invalidate_authorizer()
5215 return ceph_monc_validate_auth(&mdsc->fsc->client->monc); in invalidate_authorizer()