Lines Matching refs:mdsc

62 static void __wake_requests(struct ceph_mds_client *mdsc,
928 struct ceph_mds_session *__ceph_lookup_mds_session(struct ceph_mds_client *mdsc, in __ceph_lookup_mds_session() argument
931 if (mds >= mdsc->max_sessions || !mdsc->sessions[mds]) in __ceph_lookup_mds_session()
933 return ceph_get_mds_session(mdsc->sessions[mds]); in __ceph_lookup_mds_session()
936 static bool __have_session(struct ceph_mds_client *mdsc, int mds) in __have_session() argument
938 if (mds >= mdsc->max_sessions || !mdsc->sessions[mds]) in __have_session()
944 static int __verify_registered_session(struct ceph_mds_client *mdsc, in __verify_registered_session() argument
947 if (s->s_mds >= mdsc->max_sessions || in __verify_registered_session()
948 mdsc->sessions[s->s_mds] != s) in __verify_registered_session()
957 static struct ceph_mds_session *register_session(struct ceph_mds_client *mdsc, in register_session() argument
962 if (READ_ONCE(mdsc->fsc->mount_state) == CEPH_MOUNT_FENCE_IO) in register_session()
965 if (mds >= mdsc->mdsmap->possible_max_rank) in register_session()
972 if (mds >= mdsc->max_sessions) { in register_session()
980 if (mdsc->sessions) { in register_session()
981 memcpy(sa, mdsc->sessions, in register_session()
982 mdsc->max_sessions * sizeof(void *)); in register_session()
983 kfree(mdsc->sessions); in register_session()
985 mdsc->sessions = sa; in register_session()
986 mdsc->max_sessions = newmax; in register_session()
990 s->s_mdsc = mdsc; in register_session()
995 ceph_con_init(&s->s_con, s, &mds_con_ops, &mdsc->fsc->client->msgr); in register_session()
1012 mdsc->sessions[mds] = s; in register_session()
1013 atomic_inc(&mdsc->num_sessions); in register_session()
1017 ceph_mdsmap_get_addr(mdsc->mdsmap, mds)); in register_session()
1029 static void __unregister_session(struct ceph_mds_client *mdsc, in __unregister_session() argument
1033 BUG_ON(mdsc->sessions[s->s_mds] != s); in __unregister_session()
1034 mdsc->sessions[s->s_mds] = NULL; in __unregister_session()
1037 atomic_dec(&mdsc->num_sessions); in __unregister_session()
1053 void ceph_mdsc_iterate_sessions(struct ceph_mds_client *mdsc, in ceph_mdsc_iterate_sessions() argument
1059 mutex_lock(&mdsc->mutex); in ceph_mdsc_iterate_sessions()
1060 for (mds = 0; mds < mdsc->max_sessions; ++mds) { in ceph_mdsc_iterate_sessions()
1063 s = __ceph_lookup_mds_session(mdsc, mds); in ceph_mdsc_iterate_sessions()
1072 mutex_unlock(&mdsc->mutex); in ceph_mdsc_iterate_sessions()
1075 mutex_lock(&mdsc->mutex); in ceph_mdsc_iterate_sessions()
1077 mutex_unlock(&mdsc->mutex); in ceph_mdsc_iterate_sessions()
1137 lookup_get_request(struct ceph_mds_client *mdsc, u64 tid) in DEFINE_RB_FUNCS()
1141 req = lookup_request(&mdsc->request_tree, tid); in DEFINE_RB_FUNCS()
1154 static void __register_request(struct ceph_mds_client *mdsc, in __register_request() argument
1160 req->r_tid = ++mdsc->last_tid; in __register_request()
1162 ret = ceph_reserve_caps(mdsc, &req->r_caps_reservation, in __register_request()
1174 insert_request(&mdsc->request_tree, req); in __register_request()
1178 if (mdsc->oldest_tid == 0 && req->r_op != CEPH_MDS_OP_SETFILELOCK) in __register_request()
1179 mdsc->oldest_tid = req->r_tid; in __register_request()
1192 static void __unregister_request(struct ceph_mds_client *mdsc, in __unregister_request() argument
1200 if (req->r_tid == mdsc->oldest_tid) { in __unregister_request()
1202 mdsc->oldest_tid = 0; in __unregister_request()
1207 mdsc->oldest_tid = next_req->r_tid; in __unregister_request()
1214 erase_request(&mdsc->request_tree, req); in __unregister_request()
1270 static int __choose_mds(struct ceph_mds_client *mdsc, in __choose_mds() argument
1290 (__have_session(mdsc, req->r_resend_mds) || in __choose_mds()
1291 ceph_mdsmap_get_state(mdsc->mdsmap, req->r_resend_mds) > 0)) { in __choose_mds()
1321 if (!dir || dir->i_sb != mdsc->fsc->sb) { in __choose_mds()
1368 if (ceph_mdsmap_get_state(mdsc->mdsmap, mds) >= in __choose_mds()
1370 !ceph_mdsmap_is_laggy(mdsc->mdsmap, mds)) in __choose_mds()
1383 if (ceph_mdsmap_get_state(mdsc->mdsmap, mds) >= in __choose_mds()
1385 if (!ceph_mdsmap_is_laggy(mdsc->mdsmap, in __choose_mds()
1418 mds = ceph_mdsmap_get_random_mds(mdsc->mdsmap); in __choose_mds()
1523 static struct ceph_msg *create_session_open_msg(struct ceph_mds_client *mdsc, u64 seq) in create_session_open_msg() argument
1530 struct ceph_options *opt = mdsc->fsc->client->options; in create_session_open_msg()
1531 struct ceph_mount_options *fsopt = mdsc->fsc->mount_options; in create_session_open_msg()
1537 {"hostname", mdsc->nodename}, in create_session_open_msg()
1633 static int __open_session(struct ceph_mds_client *mdsc, in __open_session() argument
1640 if (READ_ONCE(mdsc->fsc->mount_state) == CEPH_MOUNT_FENCE_IO) in __open_session()
1644 mstate = ceph_mdsmap_get_state(mdsc->mdsmap, mds); in __open_session()
1651 msg = create_session_open_msg(mdsc, session->s_seq); in __open_session()
1664 __open_export_target_session(struct ceph_mds_client *mdsc, int target) in __open_export_target_session() argument
1669 session = __ceph_lookup_mds_session(mdsc, target); in __open_export_target_session()
1671 session = register_session(mdsc, target); in __open_export_target_session()
1677 ret = __open_session(mdsc, session); in __open_export_target_session()
1686 ceph_mdsc_open_export_target_session(struct ceph_mds_client *mdsc, int target) in ceph_mdsc_open_export_target_session() argument
1692 mutex_lock(&mdsc->mutex); in ceph_mdsc_open_export_target_session()
1693 session = __open_export_target_session(mdsc, target); in ceph_mdsc_open_export_target_session()
1694 mutex_unlock(&mdsc->mutex); in ceph_mdsc_open_export_target_session()
1699 static void __open_export_target_sessions(struct ceph_mds_client *mdsc, in __open_export_target_sessions() argument
1706 if (mds >= mdsc->mdsmap->possible_max_rank) in __open_export_target_sessions()
1709 mi = &mdsc->mdsmap->m_info[mds]; in __open_export_target_sessions()
1714 ts = __open_export_target_session(mdsc, mi->export_targets[i]); in __open_export_target_sessions()
1719 void ceph_mdsc_open_export_target_sessions(struct ceph_mds_client *mdsc, in ceph_mdsc_open_export_target_sessions() argument
1722 mutex_lock(&mdsc->mutex); in ceph_mdsc_open_export_target_sessions()
1723 __open_export_target_sessions(mdsc, session); in ceph_mdsc_open_export_target_sessions()
1724 mutex_unlock(&mdsc->mutex); in ceph_mdsc_open_export_target_sessions()
1741 static void dispose_cap_releases(struct ceph_mds_client *mdsc, in dispose_cap_releases() argument
1749 ceph_put_cap(mdsc, cap); in dispose_cap_releases()
1753 static void cleanup_session_requests(struct ceph_mds_client *mdsc, in cleanup_session_requests() argument
1760 mutex_lock(&mdsc->mutex); in cleanup_session_requests()
1770 __unregister_request(mdsc, req); in cleanup_session_requests()
1773 p = rb_first(&mdsc->request_tree); in cleanup_session_requests()
1781 mutex_unlock(&mdsc->mutex); in cleanup_session_requests()
1896 wake_up_all(&fsc->mdsc->cap_flushing_wq); in remove_session_caps()
1985 static int send_renew_caps(struct ceph_mds_client *mdsc, in send_renew_caps() argument
1998 state = ceph_mdsmap_get_state(mdsc->mdsmap, session->s_mds); in send_renew_caps()
2015 static int send_flushmsg_ack(struct ceph_mds_client *mdsc, in send_flushmsg_ack() argument
2035 static void renewed_caps(struct ceph_mds_client *mdsc, in renewed_caps() argument
2045 mdsc->mdsmap->m_session_timeout*HZ; in renewed_caps()
2085 static int __close_session(struct ceph_mds_client *mdsc, in __close_session() argument
2206 int ceph_trim_caps(struct ceph_mds_client *mdsc, in ceph_trim_caps() argument
2223 ceph_flush_cap_releases(mdsc, session); in ceph_trim_caps()
2227 static int check_caps_flush(struct ceph_mds_client *mdsc, in check_caps_flush() argument
2232 spin_lock(&mdsc->cap_dirty_lock); in check_caps_flush()
2233 if (!list_empty(&mdsc->cap_flush_list)) { in check_caps_flush()
2235 list_first_entry(&mdsc->cap_flush_list, in check_caps_flush()
2243 spin_unlock(&mdsc->cap_dirty_lock); in check_caps_flush()
2252 static void wait_caps_flush(struct ceph_mds_client *mdsc, in wait_caps_flush() argument
2257 wait_event(mdsc->cap_flushing_wq, in wait_caps_flush()
2258 check_caps_flush(mdsc, want_flush_tid)); in wait_caps_flush()
2266 static void ceph_send_cap_releases(struct ceph_mds_client *mdsc, in ceph_send_cap_releases() argument
2272 struct ceph_osd_client *osdc = &mdsc->fsc->client->osdc; in ceph_send_cap_releases()
2318 ceph_put_cap(mdsc, cap); in ceph_send_cap_releases()
2373 void ceph_flush_cap_releases(struct ceph_mds_client *mdsc, in ceph_flush_cap_releases() argument
2376 if (mdsc->stopping) in ceph_flush_cap_releases()
2380 if (queue_work(mdsc->fsc->cap_wq, in ceph_flush_cap_releases()
2404 struct ceph_mds_client *mdsc = in ceph_cap_reclaim_work() local
2406 int ret = ceph_trim_dentries(mdsc); in ceph_cap_reclaim_work()
2408 ceph_queue_cap_reclaim_work(mdsc); in ceph_cap_reclaim_work()
2411 void ceph_queue_cap_reclaim_work(struct ceph_mds_client *mdsc) in ceph_queue_cap_reclaim_work() argument
2413 if (mdsc->stopping) in ceph_queue_cap_reclaim_work()
2416 if (queue_work(mdsc->fsc->cap_wq, &mdsc->cap_reclaim_work)) { in ceph_queue_cap_reclaim_work()
2423 void ceph_reclaim_caps_nr(struct ceph_mds_client *mdsc, int nr) in ceph_reclaim_caps_nr() argument
2428 val = atomic_add_return(nr, &mdsc->cap_reclaim_pending); in ceph_reclaim_caps_nr()
2430 atomic_set(&mdsc->cap_reclaim_pending, 0); in ceph_reclaim_caps_nr()
2431 ceph_queue_cap_reclaim_work(mdsc); in ceph_reclaim_caps_nr()
2482 ceph_mdsc_create_request(struct ceph_mds_client *mdsc, int op, int mode) in ceph_mdsc_create_request() argument
2491 req->r_mdsc = mdsc; in ceph_mdsc_create_request()
2518 static struct ceph_mds_request *__get_oldest_req(struct ceph_mds_client *mdsc) in __get_oldest_req() argument
2520 if (RB_EMPTY_ROOT(&mdsc->request_tree)) in __get_oldest_req()
2522 return rb_entry(rb_first(&mdsc->request_tree), in __get_oldest_req()
2526 static inline u64 __get_oldest_tid(struct ceph_mds_client *mdsc) in __get_oldest_tid() argument
2528 return mdsc->oldest_tid; in __get_oldest_tid()
2863 struct ceph_mds_client *mdsc = session->s_mdsc; in create_request_message() local
2993 lhead->mdsmap_epoch = cpu_to_le32(mdsc->mdsmap->m_epoch); in create_request_message()
3083 static void complete_request(struct ceph_mds_client *mdsc, in complete_request() argument
3089 req->r_callback(mdsc, req); in complete_request()
3101 struct ceph_mds_client *mdsc = session->s_mdsc; in __prepare_send_request() local
3189 lhead->oldest_client_tid = cpu_to_le64(__get_oldest_tid(mdsc)); in __prepare_send_request()
3230 static void __do_request(struct ceph_mds_client *mdsc, in __do_request() argument
3240 __unregister_request(mdsc, req); in __do_request()
3244 if (READ_ONCE(mdsc->fsc->mount_state) == CEPH_MOUNT_FENCE_IO) { in __do_request()
3255 if (READ_ONCE(mdsc->fsc->mount_state) == CEPH_MOUNT_SHUTDOWN) { in __do_request()
3260 if (READ_ONCE(mdsc->fsc->mount_state) == CEPH_MOUNT_MOUNTING) { in __do_request()
3261 if (mdsc->mdsmap_err) { in __do_request()
3262 err = mdsc->mdsmap_err; in __do_request()
3266 if (mdsc->mdsmap->m_epoch == 0) { in __do_request()
3268 list_add(&req->r_wait, &mdsc->waiting_for_map); in __do_request()
3271 if (!(mdsc->fsc->mount_options->flags & in __do_request()
3273 !ceph_mdsmap_is_cluster_available(mdsc->mdsmap)) { in __do_request()
3281 mds = __choose_mds(mdsc, req, &random); in __do_request()
3283 ceph_mdsmap_get_state(mdsc->mdsmap, mds) < CEPH_MDS_STATE_ACTIVE) { in __do_request()
3289 list_add(&req->r_wait, &mdsc->waiting_for_map); in __do_request()
3294 session = __ceph_lookup_mds_session(mdsc, mds); in __do_request()
3296 session = register_session(mdsc, mds); in __do_request()
3334 if (ceph_test_mount_opt(mdsc->fsc, CLEANRECOVER)) in __do_request()
3335 list_add(&req->r_wait, &mdsc->waiting_for_map); in __do_request()
3343 err = __open_session(mdsc, session); in __do_request()
3426 complete_request(mdsc, req); in __do_request()
3427 __unregister_request(mdsc, req); in __do_request()
3435 static void __wake_requests(struct ceph_mds_client *mdsc, in __wake_requests() argument
3448 __do_request(mdsc, req); in __wake_requests()
3456 static void kick_requests(struct ceph_mds_client *mdsc, int mds) in kick_requests() argument
3459 struct rb_node *p = rb_first(&mdsc->request_tree); in kick_requests()
3473 __do_request(mdsc, req); in kick_requests()
3478 int ceph_mdsc_submit_request(struct ceph_mds_client *mdsc, struct inode *dir, in ceph_mdsc_submit_request() argument
3492 __ceph_touch_fmode(ci, mdsc, fmode); in ceph_mdsc_submit_request()
3518 mutex_lock(&mdsc->mutex); in ceph_mdsc_submit_request()
3519 __register_request(mdsc, req, dir); in ceph_mdsc_submit_request()
3520 __do_request(mdsc, req); in ceph_mdsc_submit_request()
3522 mutex_unlock(&mdsc->mutex); in ceph_mdsc_submit_request()
3526 int ceph_mdsc_wait_request(struct ceph_mds_client *mdsc, in ceph_mdsc_wait_request() argument
3535 err = wait_func(mdsc, req); in ceph_mdsc_wait_request()
3548 mutex_lock(&mdsc->mutex); in ceph_mdsc_wait_request()
3573 mutex_unlock(&mdsc->mutex); in ceph_mdsc_wait_request()
3581 int ceph_mdsc_do_request(struct ceph_mds_client *mdsc, in ceph_mdsc_do_request() argument
3590 err = ceph_mdsc_submit_request(mdsc, dir, req); in ceph_mdsc_do_request()
3592 err = ceph_mdsc_wait_request(mdsc, req, NULL); in ceph_mdsc_do_request()
3626 struct ceph_mds_client *mdsc = session->s_mdsc; in handle_reply() local
3644 mutex_lock(&mdsc->mutex); in handle_reply()
3645 req = lookup_get_request(mdsc, tid); in handle_reply()
3648 mutex_unlock(&mdsc->mutex); in handle_reply()
3658 mutex_unlock(&mdsc->mutex); in handle_reply()
3667 mutex_unlock(&mdsc->mutex); in handle_reply()
3673 mutex_unlock(&mdsc->mutex); in handle_reply()
3681 __unregister_request(mdsc, req); in handle_reply()
3684 if (mdsc->stopping && !__get_oldest_req(mdsc)) in handle_reply()
3685 complete_all(&mdsc->safe_umount_waiters); in handle_reply()
3697 mutex_unlock(&mdsc->mutex); in handle_reply()
3711 mutex_unlock(&mdsc->mutex); in handle_reply()
3734 in = ceph_get_inode(mdsc->fsc->sb, tvino, in); in handle_reply()
3753 down_write(&mdsc->snap_rwsem); in handle_reply()
3754 err = ceph_update_snap_trace(mdsc, rinfo->snapblob, in handle_reply()
3759 up_write(&mdsc->snap_rwsem); in handle_reply()
3765 downgrade_write(&mdsc->snap_rwsem); in handle_reply()
3767 down_read(&mdsc->snap_rwsem); in handle_reply()
3773 err = ceph_fill_trace(mdsc->fsc->sb, req); in handle_reply()
3782 up_read(&mdsc->snap_rwsem); in handle_reply()
3784 ceph_put_snap_realm(mdsc, realm); in handle_reply()
3797 ceph_unreserve_caps(mdsc, &req->r_caps_reservation); in handle_reply()
3800 mutex_lock(&mdsc->mutex); in handle_reply()
3811 mutex_unlock(&mdsc->mutex); in handle_reply()
3816 complete_request(mdsc, req); in handle_reply()
3818 ceph_update_metadata_metrics(&mdsc->metric, req->r_start_latency, in handle_reply()
3825 ceph_mdsc_close_sessions(mdsc); in handle_reply()
3834 static void handle_forward(struct ceph_mds_client *mdsc, in handle_forward() argument
3851 mutex_lock(&mdsc->mutex); in handle_forward()
3852 req = lookup_get_request(mdsc, tid); in handle_forward()
3854 mutex_unlock(&mdsc->mutex); in handle_forward()
3861 __unregister_request(mdsc, req); in handle_forward()
3886 __do_request(mdsc, req); in handle_forward()
3888 mutex_unlock(&mdsc->mutex); in handle_forward()
3892 complete_request(mdsc, req); in handle_forward()
3935 struct ceph_mds_client *mdsc = session->s_mdsc; in handle_session() local
3988 mutex_lock(&mdsc->mutex); in handle_session()
3991 __unregister_session(mdsc, session); in handle_session()
3994 session->s_ttl = jiffies + HZ*mdsc->mdsmap->m_session_autoclose; in handle_session()
3995 mutex_unlock(&mdsc->mutex); in handle_session()
4018 renewed_caps(mdsc, session, 0); in handle_session()
4021 metric_schedule_delayed(&mdsc->metric); in handle_session()
4033 if (mdsc->stopping) in handle_session()
4034 __close_session(mdsc, session); in handle_session()
4039 renewed_caps(mdsc, session, 1); in handle_session()
4046 cleanup_session_requests(mdsc, session); in handle_session()
4049 wake_up_all(&mdsc->session_close_wq); in handle_session()
4057 send_renew_caps(mdsc, session); in handle_session()
4061 ceph_trim_caps(mdsc, session, le32_to_cpu(h->max_caps)); in handle_session()
4068 ceph_flush_cap_releases(mdsc, session); in handle_session()
4071 send_flushmsg_ack(mdsc, session, seq); in handle_session()
4086 cleanup_session_requests(mdsc, session); in handle_session()
4089 mdsc->fsc->blocklisted = true; in handle_session()
4100 mutex_lock(&mdsc->mutex); in handle_session()
4101 __wake_requests(mdsc, &session->s_waiting); in handle_session()
4103 kick_requests(mdsc, mds); in handle_session()
4104 mutex_unlock(&mdsc->mutex); in handle_session()
4143 static void replay_unsafe_requests(struct ceph_mds_client *mdsc, in replay_unsafe_requests() argument
4151 mutex_lock(&mdsc->mutex); in replay_unsafe_requests()
4159 p = rb_first(&mdsc->request_tree); in replay_unsafe_requests()
4176 mutex_unlock(&mdsc->mutex); in replay_unsafe_requests()
4476 static int encode_snap_realms(struct ceph_mds_client *mdsc, in encode_snap_realms() argument
4484 err = ceph_pagelist_encode_32(pagelist, mdsc->num_snap_realms); in encode_snap_realms()
4494 for (p = rb_first(&mdsc->snap_realms); p; p = rb_next(p)) { in encode_snap_realms()
4546 static void send_mds_reconnect(struct ceph_mds_client *mdsc, in send_mds_reconnect() argument
4590 dispose_cap_releases(mdsc, &dispose); in send_mds_reconnect()
4593 if (mdsc->fsc->sb->s_root) in send_mds_reconnect()
4594 shrink_dcache_parent(mdsc->fsc->sb->s_root); in send_mds_reconnect()
4599 ceph_mdsmap_get_addr(mdsc->mdsmap, mds)); in send_mds_reconnect()
4602 replay_unsafe_requests(mdsc, session); in send_mds_reconnect()
4604 ceph_early_kick_flushing_caps(mdsc, session); in send_mds_reconnect()
4606 down_read(&mdsc->snap_rwsem); in send_mds_reconnect()
4632 if (mdsc->num_snap_realms) { in send_mds_reconnect()
4635 mdsc->num_snap_realms * in send_mds_reconnect()
4641 total_len += mdsc->num_snap_realms * in send_mds_reconnect()
4658 err = encode_snap_realms(mdsc, &recon_state); in send_mds_reconnect()
4674 WARN_ON(recon_state.nr_realms != mdsc->num_snap_realms); in send_mds_reconnect()
4693 mutex_lock(&mdsc->mutex); in send_mds_reconnect()
4694 __wake_requests(mdsc, &session->s_waiting); in send_mds_reconnect()
4695 mutex_unlock(&mdsc->mutex); in send_mds_reconnect()
4697 up_read(&mdsc->snap_rwsem); in send_mds_reconnect()
4703 up_read(&mdsc->snap_rwsem); in send_mds_reconnect()
4719 static void check_new_map(struct ceph_mds_client *mdsc, in check_new_map() argument
4738 for (i = 0; i < oldmap->possible_max_rank && i < mdsc->max_sessions; i++) { in check_new_map()
4739 if (!mdsc->sessions[i]) in check_new_map()
4741 s = mdsc->sessions[i]; in check_new_map()
4755 __unregister_session(mdsc, s); in check_new_map()
4756 __wake_requests(mdsc, &s->s_waiting); in check_new_map()
4757 mutex_unlock(&mdsc->mutex); in check_new_map()
4760 cleanup_session_requests(mdsc, s); in check_new_map()
4766 mutex_lock(&mdsc->mutex); in check_new_map()
4767 kick_requests(mdsc, i); in check_new_map()
4775 mutex_unlock(&mdsc->mutex); in check_new_map()
4777 mutex_lock(&mdsc->mutex); in check_new_map()
4790 mutex_unlock(&mdsc->mutex); in check_new_map()
4792 send_mds_reconnect(mdsc, s); in check_new_map()
4793 mutex_lock(&mdsc->mutex); in check_new_map()
4804 kick_requests(mdsc, i); in check_new_map()
4805 mutex_unlock(&mdsc->mutex); in check_new_map()
4807 mutex_lock(&mdsc->mutex); in check_new_map()
4808 ceph_kick_flushing_caps(mdsc, s); in check_new_map()
4842 s = __ceph_lookup_mds_session(mdsc, i); in check_new_map()
4844 s = __open_export_target_session(mdsc, i); in check_new_map()
4853 mutex_unlock(&mdsc->mutex); in check_new_map()
4854 send_mds_reconnect(mdsc, s); in check_new_map()
4856 mutex_lock(&mdsc->mutex); in check_new_map()
4859 for (i = 0; i < newmap->possible_max_rank && i < mdsc->max_sessions; i++) { in check_new_map()
4860 s = mdsc->sessions[i]; in check_new_map()
4870 __open_export_target_sessions(mdsc, s); in check_new_map()
4892 static void handle_lease(struct ceph_mds_client *mdsc, in handle_lease() argument
4896 struct super_block *sb = mdsc->fsc->sb; in handle_lease()
4909 if (!ceph_inc_mds_stopping_blocker(mdsc, session)) in handle_lease()
4992 ceph_dec_mds_stopping_blocker(mdsc); in handle_lease()
4996 ceph_dec_mds_stopping_blocker(mdsc); in handle_lease()
5043 static void maybe_recover_session(struct ceph_mds_client *mdsc) in maybe_recover_session() argument
5045 struct ceph_fs_client *fsc = mdsc->fsc; in maybe_recover_session()
5106 static void schedule_delayed(struct ceph_mds_client *mdsc, unsigned long delay) in schedule_delayed() argument
5113 schedule_delayed_work(&mdsc->delayed_work, in schedule_delayed()
5119 struct ceph_mds_client *mdsc = in delayed_work() local
5128 if (mdsc->stopping >= CEPH_MDSC_STOPPING_FLUSHED) in delayed_work()
5131 mutex_lock(&mdsc->mutex); in delayed_work()
5132 renew_interval = mdsc->mdsmap->m_session_timeout >> 2; in delayed_work()
5134 mdsc->last_renew_caps); in delayed_work()
5136 mdsc->last_renew_caps = jiffies; in delayed_work()
5138 for (i = 0; i < mdsc->max_sessions; i++) { in delayed_work()
5139 struct ceph_mds_session *s = __ceph_lookup_mds_session(mdsc, i); in delayed_work()
5147 mutex_unlock(&mdsc->mutex); in delayed_work()
5151 send_renew_caps(mdsc, s); in delayed_work()
5156 ceph_send_cap_releases(mdsc, s); in delayed_work()
5160 mutex_lock(&mdsc->mutex); in delayed_work()
5162 mutex_unlock(&mdsc->mutex); in delayed_work()
5164 delay = ceph_check_delayed_caps(mdsc); in delayed_work()
5166 ceph_queue_cap_reclaim_work(mdsc); in delayed_work()
5168 ceph_trim_snapid_map(mdsc); in delayed_work()
5170 maybe_recover_session(mdsc); in delayed_work()
5172 schedule_delayed(mdsc, delay); in delayed_work()
5178 struct ceph_mds_client *mdsc; in ceph_mdsc_init() local
5181 mdsc = kzalloc(sizeof(struct ceph_mds_client), GFP_NOFS); in ceph_mdsc_init()
5182 if (!mdsc) in ceph_mdsc_init()
5184 mdsc->fsc = fsc; in ceph_mdsc_init()
5185 mutex_init(&mdsc->mutex); in ceph_mdsc_init()
5186 mdsc->mdsmap = kzalloc(sizeof(*mdsc->mdsmap), GFP_NOFS); in ceph_mdsc_init()
5187 if (!mdsc->mdsmap) { in ceph_mdsc_init()
5192 init_completion(&mdsc->safe_umount_waiters); in ceph_mdsc_init()
5193 spin_lock_init(&mdsc->stopping_lock); in ceph_mdsc_init()
5194 atomic_set(&mdsc->stopping_blockers, 0); in ceph_mdsc_init()
5195 init_completion(&mdsc->stopping_waiter); in ceph_mdsc_init()
5196 init_waitqueue_head(&mdsc->session_close_wq); in ceph_mdsc_init()
5197 INIT_LIST_HEAD(&mdsc->waiting_for_map); in ceph_mdsc_init()
5198 mdsc->quotarealms_inodes = RB_ROOT; in ceph_mdsc_init()
5199 mutex_init(&mdsc->quotarealms_inodes_mutex); in ceph_mdsc_init()
5200 init_rwsem(&mdsc->snap_rwsem); in ceph_mdsc_init()
5201 mdsc->snap_realms = RB_ROOT; in ceph_mdsc_init()
5202 INIT_LIST_HEAD(&mdsc->snap_empty); in ceph_mdsc_init()
5203 spin_lock_init(&mdsc->snap_empty_lock); in ceph_mdsc_init()
5204 mdsc->request_tree = RB_ROOT; in ceph_mdsc_init()
5205 INIT_DELAYED_WORK(&mdsc->delayed_work, delayed_work); in ceph_mdsc_init()
5206 mdsc->last_renew_caps = jiffies; in ceph_mdsc_init()
5207 INIT_LIST_HEAD(&mdsc->cap_delay_list); in ceph_mdsc_init()
5208 INIT_LIST_HEAD(&mdsc->cap_wait_list); in ceph_mdsc_init()
5209 spin_lock_init(&mdsc->cap_delay_lock); in ceph_mdsc_init()
5210 INIT_LIST_HEAD(&mdsc->snap_flush_list); in ceph_mdsc_init()
5211 spin_lock_init(&mdsc->snap_flush_lock); in ceph_mdsc_init()
5212 mdsc->last_cap_flush_tid = 1; in ceph_mdsc_init()
5213 INIT_LIST_HEAD(&mdsc->cap_flush_list); in ceph_mdsc_init()
5214 INIT_LIST_HEAD(&mdsc->cap_dirty_migrating); in ceph_mdsc_init()
5215 spin_lock_init(&mdsc->cap_dirty_lock); in ceph_mdsc_init()
5216 init_waitqueue_head(&mdsc->cap_flushing_wq); in ceph_mdsc_init()
5217 INIT_WORK(&mdsc->cap_reclaim_work, ceph_cap_reclaim_work); in ceph_mdsc_init()
5218 err = ceph_metric_init(&mdsc->metric); in ceph_mdsc_init()
5222 spin_lock_init(&mdsc->dentry_list_lock); in ceph_mdsc_init()
5223 INIT_LIST_HEAD(&mdsc->dentry_leases); in ceph_mdsc_init()
5224 INIT_LIST_HEAD(&mdsc->dentry_dir_leases); in ceph_mdsc_init()
5226 ceph_caps_init(mdsc); in ceph_mdsc_init()
5227 ceph_adjust_caps_max_min(mdsc, fsc->mount_options); in ceph_mdsc_init()
5229 spin_lock_init(&mdsc->snapid_map_lock); in ceph_mdsc_init()
5230 mdsc->snapid_map_tree = RB_ROOT; in ceph_mdsc_init()
5231 INIT_LIST_HEAD(&mdsc->snapid_map_lru); in ceph_mdsc_init()
5233 init_rwsem(&mdsc->pool_perm_rwsem); in ceph_mdsc_init()
5234 mdsc->pool_perm_tree = RB_ROOT; in ceph_mdsc_init()
5236 strscpy(mdsc->nodename, utsname()->nodename, in ceph_mdsc_init()
5237 sizeof(mdsc->nodename)); in ceph_mdsc_init()
5239 fsc->mdsc = mdsc; in ceph_mdsc_init()
5243 kfree(mdsc->mdsmap); in ceph_mdsc_init()
5245 kfree(mdsc); in ceph_mdsc_init()
5253 static void wait_requests(struct ceph_mds_client *mdsc) in wait_requests() argument
5255 struct ceph_options *opts = mdsc->fsc->client->options; in wait_requests()
5258 mutex_lock(&mdsc->mutex); in wait_requests()
5259 if (__get_oldest_req(mdsc)) { in wait_requests()
5260 mutex_unlock(&mdsc->mutex); in wait_requests()
5263 wait_for_completion_timeout(&mdsc->safe_umount_waiters, in wait_requests()
5267 mutex_lock(&mdsc->mutex); in wait_requests()
5268 while ((req = __get_oldest_req(mdsc))) { in wait_requests()
5272 __unregister_request(mdsc, req); in wait_requests()
5275 mutex_unlock(&mdsc->mutex); in wait_requests()
5307 void ceph_mdsc_pre_umount(struct ceph_mds_client *mdsc) in ceph_mdsc_pre_umount() argument
5310 mdsc->stopping = CEPH_MDSC_STOPPING_BEGIN; in ceph_mdsc_pre_umount()
5312 ceph_mdsc_iterate_sessions(mdsc, send_flush_mdlog, true); in ceph_mdsc_pre_umount()
5313 ceph_mdsc_iterate_sessions(mdsc, lock_unlock_session, false); in ceph_mdsc_pre_umount()
5314 ceph_flush_dirty_caps(mdsc); in ceph_mdsc_pre_umount()
5315 wait_requests(mdsc); in ceph_mdsc_pre_umount()
5323 ceph_cleanup_quotarealms_inodes(mdsc); in ceph_mdsc_pre_umount()
5329 static void flush_mdlog_and_wait_mdsc_unsafe_requests(struct ceph_mds_client *mdsc, in flush_mdlog_and_wait_mdsc_unsafe_requests() argument
5336 mutex_lock(&mdsc->mutex); in flush_mdlog_and_wait_mdsc_unsafe_requests()
5339 req = __get_oldest_req(mdsc); in flush_mdlog_and_wait_mdsc_unsafe_requests()
5361 mutex_unlock(&mdsc->mutex); in flush_mdlog_and_wait_mdsc_unsafe_requests()
5375 mutex_lock(&mdsc->mutex); in flush_mdlog_and_wait_mdsc_unsafe_requests()
5388 mutex_unlock(&mdsc->mutex); in flush_mdlog_and_wait_mdsc_unsafe_requests()
5393 void ceph_mdsc_sync(struct ceph_mds_client *mdsc) in ceph_mdsc_sync() argument
5397 if (READ_ONCE(mdsc->fsc->mount_state) >= CEPH_MOUNT_SHUTDOWN) in ceph_mdsc_sync()
5401 mutex_lock(&mdsc->mutex); in ceph_mdsc_sync()
5402 want_tid = mdsc->last_tid; in ceph_mdsc_sync()
5403 mutex_unlock(&mdsc->mutex); in ceph_mdsc_sync()
5405 ceph_flush_dirty_caps(mdsc); in ceph_mdsc_sync()
5406 spin_lock(&mdsc->cap_dirty_lock); in ceph_mdsc_sync()
5407 want_flush = mdsc->last_cap_flush_tid; in ceph_mdsc_sync()
5408 if (!list_empty(&mdsc->cap_flush_list)) { in ceph_mdsc_sync()
5410 list_last_entry(&mdsc->cap_flush_list, in ceph_mdsc_sync()
5414 spin_unlock(&mdsc->cap_dirty_lock); in ceph_mdsc_sync()
5419 flush_mdlog_and_wait_mdsc_unsafe_requests(mdsc, want_tid); in ceph_mdsc_sync()
5420 wait_caps_flush(mdsc, want_flush); in ceph_mdsc_sync()
5426 static bool done_closing_sessions(struct ceph_mds_client *mdsc, int skipped) in done_closing_sessions() argument
5428 if (READ_ONCE(mdsc->fsc->mount_state) == CEPH_MOUNT_SHUTDOWN) in done_closing_sessions()
5430 return atomic_read(&mdsc->num_sessions) <= skipped; in done_closing_sessions()
5436 void ceph_mdsc_close_sessions(struct ceph_mds_client *mdsc) in ceph_mdsc_close_sessions() argument
5438 struct ceph_options *opts = mdsc->fsc->client->options; in ceph_mdsc_close_sessions()
5446 mutex_lock(&mdsc->mutex); in ceph_mdsc_close_sessions()
5447 for (i = 0; i < mdsc->max_sessions; i++) { in ceph_mdsc_close_sessions()
5448 session = __ceph_lookup_mds_session(mdsc, i); in ceph_mdsc_close_sessions()
5451 mutex_unlock(&mdsc->mutex); in ceph_mdsc_close_sessions()
5453 if (__close_session(mdsc, session) <= 0) in ceph_mdsc_close_sessions()
5457 mutex_lock(&mdsc->mutex); in ceph_mdsc_close_sessions()
5459 mutex_unlock(&mdsc->mutex); in ceph_mdsc_close_sessions()
5462 wait_event_timeout(mdsc->session_close_wq, in ceph_mdsc_close_sessions()
5463 done_closing_sessions(mdsc, skipped), in ceph_mdsc_close_sessions()
5467 mutex_lock(&mdsc->mutex); in ceph_mdsc_close_sessions()
5468 for (i = 0; i < mdsc->max_sessions; i++) { in ceph_mdsc_close_sessions()
5469 if (mdsc->sessions[i]) { in ceph_mdsc_close_sessions()
5470 session = ceph_get_mds_session(mdsc->sessions[i]); in ceph_mdsc_close_sessions()
5471 __unregister_session(mdsc, session); in ceph_mdsc_close_sessions()
5472 mutex_unlock(&mdsc->mutex); in ceph_mdsc_close_sessions()
5477 mutex_lock(&mdsc->mutex); in ceph_mdsc_close_sessions()
5480 WARN_ON(!list_empty(&mdsc->cap_delay_list)); in ceph_mdsc_close_sessions()
5481 mutex_unlock(&mdsc->mutex); in ceph_mdsc_close_sessions()
5483 ceph_cleanup_snapid_map(mdsc); in ceph_mdsc_close_sessions()
5484 ceph_cleanup_global_and_empty_realms(mdsc); in ceph_mdsc_close_sessions()
5486 cancel_work_sync(&mdsc->cap_reclaim_work); in ceph_mdsc_close_sessions()
5487 cancel_delayed_work_sync(&mdsc->delayed_work); /* cancel timer */ in ceph_mdsc_close_sessions()
5492 void ceph_mdsc_force_umount(struct ceph_mds_client *mdsc) in ceph_mdsc_force_umount() argument
5499 mutex_lock(&mdsc->mutex); in ceph_mdsc_force_umount()
5500 for (mds = 0; mds < mdsc->max_sessions; mds++) { in ceph_mdsc_force_umount()
5501 session = __ceph_lookup_mds_session(mdsc, mds); in ceph_mdsc_force_umount()
5506 __unregister_session(mdsc, session); in ceph_mdsc_force_umount()
5507 __wake_requests(mdsc, &session->s_waiting); in ceph_mdsc_force_umount()
5508 mutex_unlock(&mdsc->mutex); in ceph_mdsc_force_umount()
5511 __close_session(mdsc, session); in ceph_mdsc_force_umount()
5513 cleanup_session_requests(mdsc, session); in ceph_mdsc_force_umount()
5519 mutex_lock(&mdsc->mutex); in ceph_mdsc_force_umount()
5520 kick_requests(mdsc, mds); in ceph_mdsc_force_umount()
5522 __wake_requests(mdsc, &mdsc->waiting_for_map); in ceph_mdsc_force_umount()
5523 mutex_unlock(&mdsc->mutex); in ceph_mdsc_force_umount()
5526 static void ceph_mdsc_stop(struct ceph_mds_client *mdsc) in ceph_mdsc_stop() argument
5537 flush_delayed_work(&mdsc->delayed_work); in ceph_mdsc_stop()
5539 if (mdsc->mdsmap) in ceph_mdsc_stop()
5540 ceph_mdsmap_destroy(mdsc->mdsmap); in ceph_mdsc_stop()
5541 kfree(mdsc->sessions); in ceph_mdsc_stop()
5542 ceph_caps_finalize(mdsc); in ceph_mdsc_stop()
5543 ceph_pool_perm_destroy(mdsc); in ceph_mdsc_stop()
5548 struct ceph_mds_client *mdsc = fsc->mdsc; in ceph_mdsc_destroy() local
5549 dout("mdsc_destroy %p\n", mdsc); in ceph_mdsc_destroy()
5551 if (!mdsc) in ceph_mdsc_destroy()
5557 ceph_mdsc_stop(mdsc); in ceph_mdsc_destroy()
5559 ceph_metric_destroy(&mdsc->metric); in ceph_mdsc_destroy()
5561 fsc->mdsc = NULL; in ceph_mdsc_destroy()
5562 kfree(mdsc); in ceph_mdsc_destroy()
5563 dout("mdsc_destroy %p done\n", mdsc); in ceph_mdsc_destroy()
5566 void ceph_mdsc_handle_fsmap(struct ceph_mds_client *mdsc, struct ceph_msg *msg) in ceph_mdsc_handle_fsmap() argument
5568 struct ceph_fs_client *fsc = mdsc->fsc; in ceph_mdsc_handle_fsmap()
5626 ceph_umount_begin(mdsc->fsc->sb); in ceph_mdsc_handle_fsmap()
5629 mutex_lock(&mdsc->mutex); in ceph_mdsc_handle_fsmap()
5630 mdsc->mdsmap_err = err; in ceph_mdsc_handle_fsmap()
5631 __wake_requests(mdsc, &mdsc->waiting_for_map); in ceph_mdsc_handle_fsmap()
5632 mutex_unlock(&mdsc->mutex); in ceph_mdsc_handle_fsmap()
5638 void ceph_mdsc_handle_mdsmap(struct ceph_mds_client *mdsc, struct ceph_msg *msg) in ceph_mdsc_handle_mdsmap() argument
5650 if (ceph_check_fsid(mdsc->fsc->client, &fsid) < 0) in ceph_mdsc_handle_mdsmap()
5657 mutex_lock(&mdsc->mutex); in ceph_mdsc_handle_mdsmap()
5658 if (mdsc->mdsmap && epoch <= mdsc->mdsmap->m_epoch) { in ceph_mdsc_handle_mdsmap()
5660 epoch, mdsc->mdsmap->m_epoch); in ceph_mdsc_handle_mdsmap()
5661 mutex_unlock(&mdsc->mutex); in ceph_mdsc_handle_mdsmap()
5665 newmap = ceph_mdsmap_decode(&p, end, ceph_msgr2(mdsc->fsc->client)); in ceph_mdsc_handle_mdsmap()
5672 if (mdsc->mdsmap) { in ceph_mdsc_handle_mdsmap()
5673 oldmap = mdsc->mdsmap; in ceph_mdsc_handle_mdsmap()
5674 mdsc->mdsmap = newmap; in ceph_mdsc_handle_mdsmap()
5675 check_new_map(mdsc, newmap, oldmap); in ceph_mdsc_handle_mdsmap()
5678 mdsc->mdsmap = newmap; /* first mds map */ in ceph_mdsc_handle_mdsmap()
5680 mdsc->fsc->max_file_size = min((loff_t)mdsc->mdsmap->m_max_file_size, in ceph_mdsc_handle_mdsmap()
5683 __wake_requests(mdsc, &mdsc->waiting_for_map); in ceph_mdsc_handle_mdsmap()
5684 ceph_monc_got_map(&mdsc->fsc->client->monc, CEPH_SUB_MDSMAP, in ceph_mdsc_handle_mdsmap()
5685 mdsc->mdsmap->m_epoch); in ceph_mdsc_handle_mdsmap()
5687 mutex_unlock(&mdsc->mutex); in ceph_mdsc_handle_mdsmap()
5688 schedule_delayed(mdsc, 0); in ceph_mdsc_handle_mdsmap()
5692 mutex_unlock(&mdsc->mutex); in ceph_mdsc_handle_mdsmap()
5695 ceph_umount_begin(mdsc->fsc->sb); in ceph_mdsc_handle_mdsmap()
5723 struct ceph_mds_client *mdsc = s->s_mdsc; in mds_peer_reset() local
5726 if (READ_ONCE(mdsc->fsc->mount_state) != CEPH_MOUNT_FENCE_IO) in mds_peer_reset()
5727 send_mds_reconnect(mdsc, s); in mds_peer_reset()
5733 struct ceph_mds_client *mdsc = s->s_mdsc; in mds_dispatch() local
5736 mutex_lock(&mdsc->mutex); in mds_dispatch()
5737 if (__verify_registered_session(mdsc, s) < 0) { in mds_dispatch()
5738 mutex_unlock(&mdsc->mutex); in mds_dispatch()
5741 mutex_unlock(&mdsc->mutex); in mds_dispatch()
5745 ceph_mdsc_handle_mdsmap(mdsc, msg); in mds_dispatch()
5748 ceph_mdsc_handle_fsmap(mdsc, msg); in mds_dispatch()
5757 handle_forward(mdsc, s, msg); in mds_dispatch()
5763 ceph_handle_snap(mdsc, s, msg); in mds_dispatch()
5766 handle_lease(mdsc, s, msg); in mds_dispatch()
5769 ceph_handle_quota(mdsc, s, msg); in mds_dispatch()
5792 struct ceph_mds_client *mdsc = s->s_mdsc; in mds_get_authorizer() local
5793 struct ceph_auth_client *ac = mdsc->fsc->client->monc.auth; in mds_get_authorizer()
5809 struct ceph_mds_client *mdsc = s->s_mdsc; in mds_add_authorizer_challenge() local
5810 struct ceph_auth_client *ac = mdsc->fsc->client->monc.auth; in mds_add_authorizer_challenge()
5819 struct ceph_mds_client *mdsc = s->s_mdsc; in mds_verify_authorizer_reply() local
5820 struct ceph_auth_client *ac = mdsc->fsc->client->monc.auth; in mds_verify_authorizer_reply()
5831 struct ceph_mds_client *mdsc = s->s_mdsc; in mds_invalidate_authorizer() local
5832 struct ceph_auth_client *ac = mdsc->fsc->client->monc.auth; in mds_invalidate_authorizer()
5836 return ceph_monc_validate_auth(&mdsc->fsc->client->monc); in mds_invalidate_authorizer()