Lines Matching refs:mdsc
58 static void __wake_requests(struct ceph_mds_client *mdsc,
566 struct ceph_mds_session *__ceph_lookup_mds_session(struct ceph_mds_client *mdsc, in __ceph_lookup_mds_session() argument
569 if (mds >= mdsc->max_sessions || !mdsc->sessions[mds]) in __ceph_lookup_mds_session()
571 return get_session(mdsc->sessions[mds]); in __ceph_lookup_mds_session()
574 static bool __have_session(struct ceph_mds_client *mdsc, int mds) in __have_session() argument
576 if (mds >= mdsc->max_sessions || !mdsc->sessions[mds]) in __have_session()
582 static int __verify_registered_session(struct ceph_mds_client *mdsc, in __verify_registered_session() argument
585 if (s->s_mds >= mdsc->max_sessions || in __verify_registered_session()
586 mdsc->sessions[s->s_mds] != s) in __verify_registered_session()
595 static struct ceph_mds_session *register_session(struct ceph_mds_client *mdsc, in register_session() argument
600 if (mds >= mdsc->mdsmap->m_num_mds) in register_session()
607 if (mds >= mdsc->max_sessions) { in register_session()
615 if (mdsc->sessions) { in register_session()
616 memcpy(sa, mdsc->sessions, in register_session()
617 mdsc->max_sessions * sizeof(void *)); in register_session()
618 kfree(mdsc->sessions); in register_session()
620 mdsc->sessions = sa; in register_session()
621 mdsc->max_sessions = newmax; in register_session()
625 s->s_mdsc = mdsc; in register_session()
632 ceph_con_init(&s->s_con, s, &mds_con_ops, &mdsc->fsc->client->msgr); in register_session()
654 mdsc->sessions[mds] = s; in register_session()
655 atomic_inc(&mdsc->num_sessions); in register_session()
659 ceph_mdsmap_get_addr(mdsc->mdsmap, mds)); in register_session()
671 static void __unregister_session(struct ceph_mds_client *mdsc, in __unregister_session() argument
675 BUG_ON(mdsc->sessions[s->s_mds] != s); in __unregister_session()
676 mdsc->sessions[s->s_mds] = NULL; in __unregister_session()
680 atomic_dec(&mdsc->num_sessions); in __unregister_session()
747 lookup_get_request(struct ceph_mds_client *mdsc, u64 tid) in DEFINE_RB_FUNCS()
751 req = lookup_request(&mdsc->request_tree, tid); in DEFINE_RB_FUNCS()
764 static void __register_request(struct ceph_mds_client *mdsc, in __register_request() argument
770 req->r_tid = ++mdsc->last_tid; in __register_request()
772 ret = ceph_reserve_caps(mdsc, &req->r_caps_reservation, in __register_request()
784 insert_request(&mdsc->request_tree, req); in __register_request()
789 if (mdsc->oldest_tid == 0 && req->r_op != CEPH_MDS_OP_SETFILELOCK) in __register_request()
790 mdsc->oldest_tid = req->r_tid; in __register_request()
798 static void __unregister_request(struct ceph_mds_client *mdsc, in __unregister_request() argument
806 if (req->r_tid == mdsc->oldest_tid) { in __unregister_request()
808 mdsc->oldest_tid = 0; in __unregister_request()
813 mdsc->oldest_tid = next_req->r_tid; in __unregister_request()
820 erase_request(&mdsc->request_tree, req); in __unregister_request()
878 static int __choose_mds(struct ceph_mds_client *mdsc, in __choose_mds() argument
894 (__have_session(mdsc, req->r_resend_mds) || in __choose_mds()
895 ceph_mdsmap_get_state(mdsc->mdsmap, req->r_resend_mds) > 0)) { in __choose_mds()
925 if (!dir || dir->i_sb != mdsc->fsc->sb) { in __choose_mds()
974 if (ceph_mdsmap_get_state(mdsc->mdsmap, mds) >= in __choose_mds()
989 if (ceph_mdsmap_get_state(mdsc->mdsmap, mds) >= in __choose_mds()
1019 mds = ceph_mdsmap_get_random_mds(mdsc->mdsmap); in __choose_mds()
1071 static struct ceph_msg *create_session_open_msg(struct ceph_mds_client *mdsc, u64 seq) in create_session_open_msg() argument
1078 struct ceph_options *opt = mdsc->fsc->client->options; in create_session_open_msg()
1079 struct ceph_mount_options *fsopt = mdsc->fsc->mount_options; in create_session_open_msg()
1083 {"hostname", mdsc->nodename}, in create_session_open_msg()
1154 static int __open_session(struct ceph_mds_client *mdsc, in __open_session() argument
1162 mstate = ceph_mdsmap_get_state(mdsc->mdsmap, mds); in __open_session()
1169 msg = create_session_open_msg(mdsc, session->s_seq); in __open_session()
1182 __open_export_target_session(struct ceph_mds_client *mdsc, int target) in __open_export_target_session() argument
1186 session = __ceph_lookup_mds_session(mdsc, target); in __open_export_target_session()
1188 session = register_session(mdsc, target); in __open_export_target_session()
1194 __open_session(mdsc, session); in __open_export_target_session()
1200 ceph_mdsc_open_export_target_session(struct ceph_mds_client *mdsc, int target) in ceph_mdsc_open_export_target_session() argument
1206 mutex_lock(&mdsc->mutex); in ceph_mdsc_open_export_target_session()
1207 session = __open_export_target_session(mdsc, target); in ceph_mdsc_open_export_target_session()
1208 mutex_unlock(&mdsc->mutex); in ceph_mdsc_open_export_target_session()
1213 static void __open_export_target_sessions(struct ceph_mds_client *mdsc, in __open_export_target_sessions() argument
1220 if (mds >= mdsc->mdsmap->m_num_mds) in __open_export_target_sessions()
1223 mi = &mdsc->mdsmap->m_info[mds]; in __open_export_target_sessions()
1228 ts = __open_export_target_session(mdsc, mi->export_targets[i]); in __open_export_target_sessions()
1234 void ceph_mdsc_open_export_target_sessions(struct ceph_mds_client *mdsc, in ceph_mdsc_open_export_target_sessions() argument
1237 mutex_lock(&mdsc->mutex); in ceph_mdsc_open_export_target_sessions()
1238 __open_export_target_sessions(mdsc, session); in ceph_mdsc_open_export_target_sessions()
1239 mutex_unlock(&mdsc->mutex); in ceph_mdsc_open_export_target_sessions()
1256 static void dispose_cap_releases(struct ceph_mds_client *mdsc, in dispose_cap_releases() argument
1264 ceph_put_cap(mdsc, cap); in dispose_cap_releases()
1268 static void cleanup_session_requests(struct ceph_mds_client *mdsc, in cleanup_session_requests() argument
1276 mutex_lock(&mdsc->mutex); in cleanup_session_requests()
1292 __unregister_request(mdsc, req); in cleanup_session_requests()
1295 p = rb_first(&mdsc->request_tree); in cleanup_session_requests()
1303 mutex_unlock(&mdsc->mutex); in cleanup_session_requests()
1395 struct ceph_mds_client *mdsc = fsc->mdsc; in remove_session_caps_cb() local
1410 spin_lock(&mdsc->cap_dirty_lock); in remove_session_caps_cb()
1431 mdsc->num_cap_flushing--; in remove_session_caps_cb()
1434 spin_unlock(&mdsc->cap_dirty_lock); in remove_session_caps_cb()
1489 wake_up_all(&fsc->mdsc->cap_flushing_wq); in remove_session_caps()
1581 static int send_renew_caps(struct ceph_mds_client *mdsc, in send_renew_caps() argument
1594 state = ceph_mdsmap_get_state(mdsc->mdsmap, session->s_mds); in send_renew_caps()
1611 static int send_flushmsg_ack(struct ceph_mds_client *mdsc, in send_flushmsg_ack() argument
1631 static void renewed_caps(struct ceph_mds_client *mdsc, in renewed_caps() argument
1641 mdsc->mdsmap->m_session_timeout*HZ; in renewed_caps()
1663 static int request_close_session(struct ceph_mds_client *mdsc, in request_close_session() argument
1681 static int __close_session(struct ceph_mds_client *mdsc, in __close_session() argument
1687 return request_close_session(mdsc, session); in __close_session()
1795 int ceph_trim_caps(struct ceph_mds_client *mdsc, in ceph_trim_caps() argument
1812 ceph_flush_cap_releases(mdsc, session); in ceph_trim_caps()
1816 static int check_caps_flush(struct ceph_mds_client *mdsc, in check_caps_flush() argument
1821 spin_lock(&mdsc->cap_dirty_lock); in check_caps_flush()
1822 if (!list_empty(&mdsc->cap_flush_list)) { in check_caps_flush()
1824 list_first_entry(&mdsc->cap_flush_list, in check_caps_flush()
1832 spin_unlock(&mdsc->cap_dirty_lock); in check_caps_flush()
1841 static void wait_caps_flush(struct ceph_mds_client *mdsc, in wait_caps_flush() argument
1846 wait_event(mdsc->cap_flushing_wq, in wait_caps_flush()
1847 check_caps_flush(mdsc, want_flush_tid)); in wait_caps_flush()
1855 static void ceph_send_cap_releases(struct ceph_mds_client *mdsc, in ceph_send_cap_releases() argument
1861 struct ceph_osd_client *osdc = &mdsc->fsc->client->osdc; in ceph_send_cap_releases()
1907 ceph_put_cap(mdsc, cap); in ceph_send_cap_releases()
1962 void ceph_flush_cap_releases(struct ceph_mds_client *mdsc, in ceph_flush_cap_releases() argument
1965 if (mdsc->stopping) in ceph_flush_cap_releases()
1969 if (queue_work(mdsc->fsc->cap_wq, in ceph_flush_cap_releases()
1993 struct ceph_mds_client *mdsc = in ceph_cap_reclaim_work() local
1995 int ret = ceph_trim_dentries(mdsc); in ceph_cap_reclaim_work()
1997 ceph_queue_cap_reclaim_work(mdsc); in ceph_cap_reclaim_work()
2000 void ceph_queue_cap_reclaim_work(struct ceph_mds_client *mdsc) in ceph_queue_cap_reclaim_work() argument
2002 if (mdsc->stopping) in ceph_queue_cap_reclaim_work()
2005 if (queue_work(mdsc->fsc->cap_wq, &mdsc->cap_reclaim_work)) { in ceph_queue_cap_reclaim_work()
2012 void ceph_reclaim_caps_nr(struct ceph_mds_client *mdsc, int nr) in ceph_reclaim_caps_nr() argument
2017 val = atomic_add_return(nr, &mdsc->cap_reclaim_pending); in ceph_reclaim_caps_nr()
2019 atomic_set(&mdsc->cap_reclaim_pending, 0); in ceph_reclaim_caps_nr()
2020 ceph_queue_cap_reclaim_work(mdsc); in ceph_reclaim_caps_nr()
2069 ceph_mdsc_create_request(struct ceph_mds_client *mdsc, int op, int mode) in ceph_mdsc_create_request() argument
2078 req->r_mdsc = mdsc; in ceph_mdsc_create_request()
2092 req->r_stamp = timespec64_trunc(ts, mdsc->fsc->sb->s_time_gran); in ceph_mdsc_create_request()
2104 static struct ceph_mds_request *__get_oldest_req(struct ceph_mds_client *mdsc) in __get_oldest_req() argument
2106 if (RB_EMPTY_ROOT(&mdsc->request_tree)) in __get_oldest_req()
2108 return rb_entry(rb_first(&mdsc->request_tree), in __get_oldest_req()
2112 static inline u64 __get_oldest_tid(struct ceph_mds_client *mdsc) in __get_oldest_tid() argument
2114 return mdsc->oldest_tid; in __get_oldest_tid()
2282 static struct ceph_msg *create_request_message(struct ceph_mds_client *mdsc, in create_request_message() argument
2344 head->mdsmap_epoch = cpu_to_le32(mdsc->mdsmap->m_epoch); in create_request_message()
2418 static void complete_request(struct ceph_mds_client *mdsc, in complete_request() argument
2422 req->r_callback(mdsc, req); in complete_request()
2429 static int __prepare_send_request(struct ceph_mds_client *mdsc, in __prepare_send_request() argument
2490 msg = create_request_message(mdsc, req, mds, drop_cap_releases); in __prepare_send_request()
2498 rhead->oldest_client_tid = cpu_to_le64(__get_oldest_tid(mdsc)); in __prepare_send_request()
2515 static void __do_request(struct ceph_mds_client *mdsc, in __do_request() argument
2524 __unregister_request(mdsc, req); in __do_request()
2534 if (READ_ONCE(mdsc->fsc->mount_state) == CEPH_MOUNT_SHUTDOWN) { in __do_request()
2539 if (READ_ONCE(mdsc->fsc->mount_state) == CEPH_MOUNT_MOUNTING) { in __do_request()
2540 if (mdsc->mdsmap_err) { in __do_request()
2541 err = mdsc->mdsmap_err; in __do_request()
2545 if (mdsc->mdsmap->m_epoch == 0) { in __do_request()
2547 list_add(&req->r_wait, &mdsc->waiting_for_map); in __do_request()
2550 if (!(mdsc->fsc->mount_options->flags & in __do_request()
2552 !ceph_mdsmap_is_cluster_available(mdsc->mdsmap)) { in __do_request()
2561 mds = __choose_mds(mdsc, req); in __do_request()
2563 ceph_mdsmap_get_state(mdsc->mdsmap, mds) < CEPH_MDS_STATE_ACTIVE) { in __do_request()
2565 list_add(&req->r_wait, &mdsc->waiting_for_map); in __do_request()
2570 session = __ceph_lookup_mds_session(mdsc, mds); in __do_request()
2572 session = register_session(mdsc, mds); in __do_request()
2590 __open_session(mdsc, session); in __do_request()
2601 err = __prepare_send_request(mdsc, req, mds, false); in __do_request()
2613 complete_request(mdsc, req); in __do_request()
2614 __unregister_request(mdsc, req); in __do_request()
2622 static void __wake_requests(struct ceph_mds_client *mdsc, in __wake_requests() argument
2635 __do_request(mdsc, req); in __wake_requests()
2643 static void kick_requests(struct ceph_mds_client *mdsc, int mds) in kick_requests() argument
2646 struct rb_node *p = rb_first(&mdsc->request_tree); in kick_requests()
2660 __do_request(mdsc, req); in kick_requests()
2665 int ceph_mdsc_submit_request(struct ceph_mds_client *mdsc, struct inode *dir, in ceph_mdsc_submit_request() argument
2680 mutex_lock(&mdsc->mutex); in ceph_mdsc_submit_request()
2681 __register_request(mdsc, req, dir); in ceph_mdsc_submit_request()
2682 __do_request(mdsc, req); in ceph_mdsc_submit_request()
2684 mutex_unlock(&mdsc->mutex); in ceph_mdsc_submit_request()
2688 static int ceph_mdsc_wait_request(struct ceph_mds_client *mdsc, in ceph_mdsc_wait_request() argument
2696 err = req->r_wait_for_completion(mdsc, req); in ceph_mdsc_wait_request()
2709 mutex_lock(&mdsc->mutex); in ceph_mdsc_wait_request()
2734 mutex_unlock(&mdsc->mutex); in ceph_mdsc_wait_request()
2742 int ceph_mdsc_do_request(struct ceph_mds_client *mdsc, in ceph_mdsc_do_request() argument
2751 err = ceph_mdsc_submit_request(mdsc, dir, req); in ceph_mdsc_do_request()
2753 err = ceph_mdsc_wait_request(mdsc, req); in ceph_mdsc_do_request()
2787 struct ceph_mds_client *mdsc = session->s_mdsc; in handle_reply() local
2804 mutex_lock(&mdsc->mutex); in handle_reply()
2805 req = lookup_get_request(mdsc, tid); in handle_reply()
2808 mutex_unlock(&mdsc->mutex); in handle_reply()
2818 mutex_unlock(&mdsc->mutex); in handle_reply()
2827 mutex_unlock(&mdsc->mutex); in handle_reply()
2833 mutex_unlock(&mdsc->mutex); in handle_reply()
2852 __do_request(mdsc, req); in handle_reply()
2853 mutex_unlock(&mdsc->mutex); in handle_reply()
2856 int mds = __choose_mds(mdsc, req); in handle_reply()
2859 __do_request(mdsc, req); in handle_reply()
2860 mutex_unlock(&mdsc->mutex); in handle_reply()
2870 __unregister_request(mdsc, req); in handle_reply()
2883 if (mdsc->stopping && !__get_oldest_req(mdsc)) in handle_reply()
2884 complete_all(&mdsc->safe_umount_waiters); in handle_reply()
2885 mutex_unlock(&mdsc->mutex); in handle_reply()
2907 mutex_unlock(&mdsc->mutex); in handle_reply()
2919 down_write(&mdsc->snap_rwsem); in handle_reply()
2920 ceph_update_snap_trace(mdsc, rinfo->snapblob, in handle_reply()
2924 downgrade_write(&mdsc->snap_rwsem); in handle_reply()
2926 down_read(&mdsc->snap_rwsem); in handle_reply()
2932 err = ceph_fill_trace(mdsc->fsc->sb, req); in handle_reply()
2941 up_read(&mdsc->snap_rwsem); in handle_reply()
2943 ceph_put_snap_realm(mdsc, realm); in handle_reply()
2956 ceph_unreserve_caps(mdsc, &req->r_caps_reservation); in handle_reply()
2959 mutex_lock(&mdsc->mutex); in handle_reply()
2970 mutex_unlock(&mdsc->mutex); in handle_reply()
2975 complete_request(mdsc, req); in handle_reply()
2986 static void handle_forward(struct ceph_mds_client *mdsc, in handle_forward() argument
3002 mutex_lock(&mdsc->mutex); in handle_forward()
3003 req = lookup_get_request(mdsc, tid); in handle_forward()
3011 __unregister_request(mdsc, req); in handle_forward()
3024 __do_request(mdsc, req); in handle_forward()
3028 mutex_unlock(&mdsc->mutex); in handle_forward()
3065 struct ceph_mds_client *mdsc = session->s_mdsc; in handle_session() local
3097 mutex_lock(&mdsc->mutex); in handle_session()
3100 __unregister_session(mdsc, session); in handle_session()
3103 session->s_ttl = jiffies + HZ*mdsc->mdsmap->m_session_autoclose; in handle_session()
3104 mutex_unlock(&mdsc->mutex); in handle_session()
3123 renewed_caps(mdsc, session, 0); in handle_session()
3125 if (mdsc->stopping) in handle_session()
3126 __close_session(mdsc, session); in handle_session()
3131 renewed_caps(mdsc, session, 1); in handle_session()
3137 cleanup_session_requests(mdsc, session); in handle_session()
3140 wake_up_all(&mdsc->session_close_wq); in handle_session()
3150 send_renew_caps(mdsc, session); in handle_session()
3154 ceph_trim_caps(mdsc, session, le32_to_cpu(h->max_caps)); in handle_session()
3158 send_flushmsg_ack(mdsc, session, seq); in handle_session()
3173 cleanup_session_requests(mdsc, session); in handle_session()
3176 mdsc->fsc->blacklisted = true; in handle_session()
3187 mutex_lock(&mdsc->mutex); in handle_session()
3188 __wake_requests(mdsc, &session->s_waiting); in handle_session()
3190 kick_requests(mdsc, mds); in handle_session()
3191 mutex_unlock(&mdsc->mutex); in handle_session()
3208 static void replay_unsafe_requests(struct ceph_mds_client *mdsc, in replay_unsafe_requests() argument
3217 mutex_lock(&mdsc->mutex); in replay_unsafe_requests()
3219 err = __prepare_send_request(mdsc, req, session->s_mds, true); in replay_unsafe_requests()
3230 p = rb_first(&mdsc->request_tree); in replay_unsafe_requests()
3240 err = __prepare_send_request(mdsc, req, in replay_unsafe_requests()
3248 mutex_unlock(&mdsc->mutex); in replay_unsafe_requests()
3501 static int encode_snap_realms(struct ceph_mds_client *mdsc, in encode_snap_realms() argument
3509 err = ceph_pagelist_encode_32(pagelist, mdsc->num_snap_realms); in encode_snap_realms()
3519 for (p = rb_first(&mdsc->snap_realms); p; p = rb_next(p)) { in encode_snap_realms()
3573 static void send_mds_reconnect(struct ceph_mds_client *mdsc, in send_mds_reconnect() argument
3617 dispose_cap_releases(mdsc, &dispose); in send_mds_reconnect()
3620 if (mdsc->fsc->sb->s_root) in send_mds_reconnect()
3621 shrink_dcache_parent(mdsc->fsc->sb->s_root); in send_mds_reconnect()
3626 ceph_mdsmap_get_addr(mdsc->mdsmap, mds)); in send_mds_reconnect()
3629 replay_unsafe_requests(mdsc, session); in send_mds_reconnect()
3631 ceph_early_kick_flushing_caps(mdsc, session); in send_mds_reconnect()
3633 down_read(&mdsc->snap_rwsem); in send_mds_reconnect()
3659 if (mdsc->num_snap_realms) { in send_mds_reconnect()
3662 mdsc->num_snap_realms * in send_mds_reconnect()
3668 total_len += mdsc->num_snap_realms * in send_mds_reconnect()
3685 err = encode_snap_realms(mdsc, &recon_state); in send_mds_reconnect()
3701 WARN_ON(recon_state.nr_realms != mdsc->num_snap_realms); in send_mds_reconnect()
3720 mutex_lock(&mdsc->mutex); in send_mds_reconnect()
3721 __wake_requests(mdsc, &session->s_waiting); in send_mds_reconnect()
3722 mutex_unlock(&mdsc->mutex); in send_mds_reconnect()
3724 up_read(&mdsc->snap_rwsem); in send_mds_reconnect()
3730 up_read(&mdsc->snap_rwsem); in send_mds_reconnect()
3746 static void check_new_map(struct ceph_mds_client *mdsc, in check_new_map() argument
3757 for (i = 0; i < oldmap->m_num_mds && i < mdsc->max_sessions; i++) { in check_new_map()
3758 if (!mdsc->sessions[i]) in check_new_map()
3760 s = mdsc->sessions[i]; in check_new_map()
3774 __unregister_session(mdsc, s); in check_new_map()
3775 __wake_requests(mdsc, &s->s_waiting); in check_new_map()
3776 mutex_unlock(&mdsc->mutex); in check_new_map()
3779 cleanup_session_requests(mdsc, s); in check_new_map()
3785 mutex_lock(&mdsc->mutex); in check_new_map()
3786 kick_requests(mdsc, i); in check_new_map()
3794 mutex_unlock(&mdsc->mutex); in check_new_map()
3796 mutex_lock(&mdsc->mutex); in check_new_map()
3809 mutex_unlock(&mdsc->mutex); in check_new_map()
3810 send_mds_reconnect(mdsc, s); in check_new_map()
3811 mutex_lock(&mdsc->mutex); in check_new_map()
3822 kick_requests(mdsc, i); in check_new_map()
3823 ceph_kick_flushing_caps(mdsc, s); in check_new_map()
3828 for (i = 0; i < newmap->m_num_mds && i < mdsc->max_sessions; i++) { in check_new_map()
3829 s = mdsc->sessions[i]; in check_new_map()
3839 __open_export_target_sessions(mdsc, s); in check_new_map()
3861 static void handle_lease(struct ceph_mds_client *mdsc, in handle_lease() argument
3865 struct super_block *sb = mdsc->fsc->sb; in handle_lease()
4008 static void lock_unlock_sessions(struct ceph_mds_client *mdsc) in lock_unlock_sessions() argument
4012 mutex_lock(&mdsc->mutex); in lock_unlock_sessions()
4013 for (i = 0; i < mdsc->max_sessions; i++) { in lock_unlock_sessions()
4014 struct ceph_mds_session *s = __ceph_lookup_mds_session(mdsc, i); in lock_unlock_sessions()
4017 mutex_unlock(&mdsc->mutex); in lock_unlock_sessions()
4021 mutex_lock(&mdsc->mutex); in lock_unlock_sessions()
4023 mutex_unlock(&mdsc->mutex); in lock_unlock_sessions()
4026 static void maybe_recover_session(struct ceph_mds_client *mdsc) in maybe_recover_session() argument
4028 struct ceph_fs_client *fsc = mdsc->fsc; in maybe_recover_session()
4051 static void schedule_delayed(struct ceph_mds_client *mdsc) in schedule_delayed() argument
4055 schedule_delayed_work(&mdsc->delayed_work, hz); in schedule_delayed()
4061 struct ceph_mds_client *mdsc = in delayed_work() local
4068 mutex_lock(&mdsc->mutex); in delayed_work()
4069 renew_interval = mdsc->mdsmap->m_session_timeout >> 2; in delayed_work()
4071 mdsc->last_renew_caps); in delayed_work()
4073 mdsc->last_renew_caps = jiffies; in delayed_work()
4075 for (i = 0; i < mdsc->max_sessions; i++) { in delayed_work()
4076 struct ceph_mds_session *s = __ceph_lookup_mds_session(mdsc, i); in delayed_work()
4082 request_close_session(mdsc, s); in delayed_work()
4099 mutex_unlock(&mdsc->mutex); in delayed_work()
4103 send_renew_caps(mdsc, s); in delayed_work()
4108 ceph_send_cap_releases(mdsc, s); in delayed_work()
4112 mutex_lock(&mdsc->mutex); in delayed_work()
4114 mutex_unlock(&mdsc->mutex); in delayed_work()
4116 ceph_check_delayed_caps(mdsc); in delayed_work()
4118 ceph_queue_cap_reclaim_work(mdsc); in delayed_work()
4120 ceph_trim_snapid_map(mdsc); in delayed_work()
4122 maybe_recover_session(mdsc); in delayed_work()
4124 schedule_delayed(mdsc); in delayed_work()
4130 struct ceph_mds_client *mdsc; in ceph_mdsc_init() local
4132 mdsc = kzalloc(sizeof(struct ceph_mds_client), GFP_NOFS); in ceph_mdsc_init()
4133 if (!mdsc) in ceph_mdsc_init()
4135 mdsc->fsc = fsc; in ceph_mdsc_init()
4136 mutex_init(&mdsc->mutex); in ceph_mdsc_init()
4137 mdsc->mdsmap = kzalloc(sizeof(*mdsc->mdsmap), GFP_NOFS); in ceph_mdsc_init()
4138 if (!mdsc->mdsmap) { in ceph_mdsc_init()
4139 kfree(mdsc); in ceph_mdsc_init()
4143 fsc->mdsc = mdsc; in ceph_mdsc_init()
4144 init_completion(&mdsc->safe_umount_waiters); in ceph_mdsc_init()
4145 init_waitqueue_head(&mdsc->session_close_wq); in ceph_mdsc_init()
4146 INIT_LIST_HEAD(&mdsc->waiting_for_map); in ceph_mdsc_init()
4147 mdsc->sessions = NULL; in ceph_mdsc_init()
4148 atomic_set(&mdsc->num_sessions, 0); in ceph_mdsc_init()
4149 mdsc->max_sessions = 0; in ceph_mdsc_init()
4150 mdsc->stopping = 0; in ceph_mdsc_init()
4151 atomic64_set(&mdsc->quotarealms_count, 0); in ceph_mdsc_init()
4152 mdsc->quotarealms_inodes = RB_ROOT; in ceph_mdsc_init()
4153 mutex_init(&mdsc->quotarealms_inodes_mutex); in ceph_mdsc_init()
4154 mdsc->last_snap_seq = 0; in ceph_mdsc_init()
4155 init_rwsem(&mdsc->snap_rwsem); in ceph_mdsc_init()
4156 mdsc->snap_realms = RB_ROOT; in ceph_mdsc_init()
4157 INIT_LIST_HEAD(&mdsc->snap_empty); in ceph_mdsc_init()
4158 mdsc->num_snap_realms = 0; in ceph_mdsc_init()
4159 spin_lock_init(&mdsc->snap_empty_lock); in ceph_mdsc_init()
4160 mdsc->last_tid = 0; in ceph_mdsc_init()
4161 mdsc->oldest_tid = 0; in ceph_mdsc_init()
4162 mdsc->request_tree = RB_ROOT; in ceph_mdsc_init()
4163 INIT_DELAYED_WORK(&mdsc->delayed_work, delayed_work); in ceph_mdsc_init()
4164 mdsc->last_renew_caps = jiffies; in ceph_mdsc_init()
4165 INIT_LIST_HEAD(&mdsc->cap_delay_list); in ceph_mdsc_init()
4166 spin_lock_init(&mdsc->cap_delay_lock); in ceph_mdsc_init()
4167 INIT_LIST_HEAD(&mdsc->snap_flush_list); in ceph_mdsc_init()
4168 spin_lock_init(&mdsc->snap_flush_lock); in ceph_mdsc_init()
4169 mdsc->last_cap_flush_tid = 1; in ceph_mdsc_init()
4170 INIT_LIST_HEAD(&mdsc->cap_flush_list); in ceph_mdsc_init()
4171 INIT_LIST_HEAD(&mdsc->cap_dirty); in ceph_mdsc_init()
4172 INIT_LIST_HEAD(&mdsc->cap_dirty_migrating); in ceph_mdsc_init()
4173 mdsc->num_cap_flushing = 0; in ceph_mdsc_init()
4174 spin_lock_init(&mdsc->cap_dirty_lock); in ceph_mdsc_init()
4175 init_waitqueue_head(&mdsc->cap_flushing_wq); in ceph_mdsc_init()
4176 INIT_WORK(&mdsc->cap_reclaim_work, ceph_cap_reclaim_work); in ceph_mdsc_init()
4177 atomic_set(&mdsc->cap_reclaim_pending, 0); in ceph_mdsc_init()
4179 spin_lock_init(&mdsc->dentry_list_lock); in ceph_mdsc_init()
4180 INIT_LIST_HEAD(&mdsc->dentry_leases); in ceph_mdsc_init()
4181 INIT_LIST_HEAD(&mdsc->dentry_dir_leases); in ceph_mdsc_init()
4183 ceph_caps_init(mdsc); in ceph_mdsc_init()
4184 ceph_adjust_caps_max_min(mdsc, fsc->mount_options); in ceph_mdsc_init()
4186 spin_lock_init(&mdsc->snapid_map_lock); in ceph_mdsc_init()
4187 mdsc->snapid_map_tree = RB_ROOT; in ceph_mdsc_init()
4188 INIT_LIST_HEAD(&mdsc->snapid_map_lru); in ceph_mdsc_init()
4190 init_rwsem(&mdsc->pool_perm_rwsem); in ceph_mdsc_init()
4191 mdsc->pool_perm_tree = RB_ROOT; in ceph_mdsc_init()
4193 strscpy(mdsc->nodename, utsname()->nodename, in ceph_mdsc_init()
4194 sizeof(mdsc->nodename)); in ceph_mdsc_init()
4202 static void wait_requests(struct ceph_mds_client *mdsc) in wait_requests() argument
4204 struct ceph_options *opts = mdsc->fsc->client->options; in wait_requests()
4207 mutex_lock(&mdsc->mutex); in wait_requests()
4208 if (__get_oldest_req(mdsc)) { in wait_requests()
4209 mutex_unlock(&mdsc->mutex); in wait_requests()
4212 wait_for_completion_timeout(&mdsc->safe_umount_waiters, in wait_requests()
4216 mutex_lock(&mdsc->mutex); in wait_requests()
4217 while ((req = __get_oldest_req(mdsc))) { in wait_requests()
4221 __unregister_request(mdsc, req); in wait_requests()
4224 mutex_unlock(&mdsc->mutex); in wait_requests()
4232 void ceph_mdsc_pre_umount(struct ceph_mds_client *mdsc) in ceph_mdsc_pre_umount() argument
4235 mdsc->stopping = 1; in ceph_mdsc_pre_umount()
4237 lock_unlock_sessions(mdsc); in ceph_mdsc_pre_umount()
4238 ceph_flush_dirty_caps(mdsc); in ceph_mdsc_pre_umount()
4239 wait_requests(mdsc); in ceph_mdsc_pre_umount()
4247 ceph_cleanup_quotarealms_inodes(mdsc); in ceph_mdsc_pre_umount()
4253 static void wait_unsafe_requests(struct ceph_mds_client *mdsc, u64 want_tid) in wait_unsafe_requests() argument
4258 mutex_lock(&mdsc->mutex); in wait_unsafe_requests()
4261 req = __get_oldest_req(mdsc); in wait_unsafe_requests()
4275 mutex_unlock(&mdsc->mutex); in wait_unsafe_requests()
4279 mutex_lock(&mdsc->mutex); in wait_unsafe_requests()
4292 mutex_unlock(&mdsc->mutex); in wait_unsafe_requests()
4296 void ceph_mdsc_sync(struct ceph_mds_client *mdsc) in ceph_mdsc_sync() argument
4300 if (READ_ONCE(mdsc->fsc->mount_state) == CEPH_MOUNT_SHUTDOWN) in ceph_mdsc_sync()
4304 mutex_lock(&mdsc->mutex); in ceph_mdsc_sync()
4305 want_tid = mdsc->last_tid; in ceph_mdsc_sync()
4306 mutex_unlock(&mdsc->mutex); in ceph_mdsc_sync()
4308 ceph_flush_dirty_caps(mdsc); in ceph_mdsc_sync()
4309 spin_lock(&mdsc->cap_dirty_lock); in ceph_mdsc_sync()
4310 want_flush = mdsc->last_cap_flush_tid; in ceph_mdsc_sync()
4311 if (!list_empty(&mdsc->cap_flush_list)) { in ceph_mdsc_sync()
4313 list_last_entry(&mdsc->cap_flush_list, in ceph_mdsc_sync()
4317 spin_unlock(&mdsc->cap_dirty_lock); in ceph_mdsc_sync()
4322 wait_unsafe_requests(mdsc, want_tid); in ceph_mdsc_sync()
4323 wait_caps_flush(mdsc, want_flush); in ceph_mdsc_sync()
4329 static bool done_closing_sessions(struct ceph_mds_client *mdsc, int skipped) in done_closing_sessions() argument
4331 if (READ_ONCE(mdsc->fsc->mount_state) == CEPH_MOUNT_SHUTDOWN) in done_closing_sessions()
4333 return atomic_read(&mdsc->num_sessions) <= skipped; in done_closing_sessions()
4339 void ceph_mdsc_close_sessions(struct ceph_mds_client *mdsc) in ceph_mdsc_close_sessions() argument
4341 struct ceph_options *opts = mdsc->fsc->client->options; in ceph_mdsc_close_sessions()
4349 mutex_lock(&mdsc->mutex); in ceph_mdsc_close_sessions()
4350 for (i = 0; i < mdsc->max_sessions; i++) { in ceph_mdsc_close_sessions()
4351 session = __ceph_lookup_mds_session(mdsc, i); in ceph_mdsc_close_sessions()
4354 mutex_unlock(&mdsc->mutex); in ceph_mdsc_close_sessions()
4356 if (__close_session(mdsc, session) <= 0) in ceph_mdsc_close_sessions()
4360 mutex_lock(&mdsc->mutex); in ceph_mdsc_close_sessions()
4362 mutex_unlock(&mdsc->mutex); in ceph_mdsc_close_sessions()
4365 wait_event_timeout(mdsc->session_close_wq, in ceph_mdsc_close_sessions()
4366 done_closing_sessions(mdsc, skipped), in ceph_mdsc_close_sessions()
4370 mutex_lock(&mdsc->mutex); in ceph_mdsc_close_sessions()
4371 for (i = 0; i < mdsc->max_sessions; i++) { in ceph_mdsc_close_sessions()
4372 if (mdsc->sessions[i]) { in ceph_mdsc_close_sessions()
4373 session = get_session(mdsc->sessions[i]); in ceph_mdsc_close_sessions()
4374 __unregister_session(mdsc, session); in ceph_mdsc_close_sessions()
4375 mutex_unlock(&mdsc->mutex); in ceph_mdsc_close_sessions()
4380 mutex_lock(&mdsc->mutex); in ceph_mdsc_close_sessions()
4383 WARN_ON(!list_empty(&mdsc->cap_delay_list)); in ceph_mdsc_close_sessions()
4384 mutex_unlock(&mdsc->mutex); in ceph_mdsc_close_sessions()
4386 ceph_cleanup_snapid_map(mdsc); in ceph_mdsc_close_sessions()
4387 ceph_cleanup_empty_realms(mdsc); in ceph_mdsc_close_sessions()
4389 cancel_work_sync(&mdsc->cap_reclaim_work); in ceph_mdsc_close_sessions()
4390 cancel_delayed_work_sync(&mdsc->delayed_work); /* cancel timer */ in ceph_mdsc_close_sessions()
4395 void ceph_mdsc_force_umount(struct ceph_mds_client *mdsc) in ceph_mdsc_force_umount() argument
4402 mutex_lock(&mdsc->mutex); in ceph_mdsc_force_umount()
4403 for (mds = 0; mds < mdsc->max_sessions; mds++) { in ceph_mdsc_force_umount()
4404 session = __ceph_lookup_mds_session(mdsc, mds); in ceph_mdsc_force_umount()
4409 __unregister_session(mdsc, session); in ceph_mdsc_force_umount()
4410 __wake_requests(mdsc, &session->s_waiting); in ceph_mdsc_force_umount()
4411 mutex_unlock(&mdsc->mutex); in ceph_mdsc_force_umount()
4414 __close_session(mdsc, session); in ceph_mdsc_force_umount()
4416 cleanup_session_requests(mdsc, session); in ceph_mdsc_force_umount()
4422 mutex_lock(&mdsc->mutex); in ceph_mdsc_force_umount()
4423 kick_requests(mdsc, mds); in ceph_mdsc_force_umount()
4425 __wake_requests(mdsc, &mdsc->waiting_for_map); in ceph_mdsc_force_umount()
4426 mutex_unlock(&mdsc->mutex); in ceph_mdsc_force_umount()
4429 static void ceph_mdsc_stop(struct ceph_mds_client *mdsc) in ceph_mdsc_stop() argument
4432 cancel_delayed_work_sync(&mdsc->delayed_work); /* cancel timer */ in ceph_mdsc_stop()
4433 if (mdsc->mdsmap) in ceph_mdsc_stop()
4434 ceph_mdsmap_destroy(mdsc->mdsmap); in ceph_mdsc_stop()
4435 kfree(mdsc->sessions); in ceph_mdsc_stop()
4436 ceph_caps_finalize(mdsc); in ceph_mdsc_stop()
4437 ceph_pool_perm_destroy(mdsc); in ceph_mdsc_stop()
4442 struct ceph_mds_client *mdsc = fsc->mdsc; in ceph_mdsc_destroy() local
4443 dout("mdsc_destroy %p\n", mdsc); in ceph_mdsc_destroy()
4445 if (!mdsc) in ceph_mdsc_destroy()
4451 ceph_mdsc_stop(mdsc); in ceph_mdsc_destroy()
4453 fsc->mdsc = NULL; in ceph_mdsc_destroy()
4454 kfree(mdsc); in ceph_mdsc_destroy()
4455 dout("mdsc_destroy %p done\n", mdsc); in ceph_mdsc_destroy()
4458 void ceph_mdsc_handle_fsmap(struct ceph_mds_client *mdsc, struct ceph_msg *msg) in ceph_mdsc_handle_fsmap() argument
4460 struct ceph_fs_client *fsc = mdsc->fsc; in ceph_mdsc_handle_fsmap()
4528 mutex_lock(&mdsc->mutex); in ceph_mdsc_handle_fsmap()
4529 mdsc->mdsmap_err = err; in ceph_mdsc_handle_fsmap()
4530 __wake_requests(mdsc, &mdsc->waiting_for_map); in ceph_mdsc_handle_fsmap()
4531 mutex_unlock(&mdsc->mutex); in ceph_mdsc_handle_fsmap()
4537 void ceph_mdsc_handle_mdsmap(struct ceph_mds_client *mdsc, struct ceph_msg *msg) in ceph_mdsc_handle_mdsmap() argument
4549 if (ceph_check_fsid(mdsc->fsc->client, &fsid) < 0) in ceph_mdsc_handle_mdsmap()
4556 mutex_lock(&mdsc->mutex); in ceph_mdsc_handle_mdsmap()
4557 if (mdsc->mdsmap && epoch <= mdsc->mdsmap->m_epoch) { in ceph_mdsc_handle_mdsmap()
4559 epoch, mdsc->mdsmap->m_epoch); in ceph_mdsc_handle_mdsmap()
4560 mutex_unlock(&mdsc->mutex); in ceph_mdsc_handle_mdsmap()
4571 if (mdsc->mdsmap) { in ceph_mdsc_handle_mdsmap()
4572 oldmap = mdsc->mdsmap; in ceph_mdsc_handle_mdsmap()
4573 mdsc->mdsmap = newmap; in ceph_mdsc_handle_mdsmap()
4574 check_new_map(mdsc, newmap, oldmap); in ceph_mdsc_handle_mdsmap()
4577 mdsc->mdsmap = newmap; /* first mds map */ in ceph_mdsc_handle_mdsmap()
4579 mdsc->fsc->max_file_size = min((loff_t)mdsc->mdsmap->m_max_file_size, in ceph_mdsc_handle_mdsmap()
4582 __wake_requests(mdsc, &mdsc->waiting_for_map); in ceph_mdsc_handle_mdsmap()
4583 ceph_monc_got_map(&mdsc->fsc->client->monc, CEPH_SUB_MDSMAP, in ceph_mdsc_handle_mdsmap()
4584 mdsc->mdsmap->m_epoch); in ceph_mdsc_handle_mdsmap()
4586 mutex_unlock(&mdsc->mutex); in ceph_mdsc_handle_mdsmap()
4587 schedule_delayed(mdsc); in ceph_mdsc_handle_mdsmap()
4591 mutex_unlock(&mdsc->mutex); in ceph_mdsc_handle_mdsmap()
4624 struct ceph_mds_client *mdsc = s->s_mdsc; in peer_reset() local
4627 send_mds_reconnect(mdsc, s); in peer_reset()
4633 struct ceph_mds_client *mdsc = s->s_mdsc; in dispatch() local
4636 mutex_lock(&mdsc->mutex); in dispatch()
4637 if (__verify_registered_session(mdsc, s) < 0) { in dispatch()
4638 mutex_unlock(&mdsc->mutex); in dispatch()
4641 mutex_unlock(&mdsc->mutex); in dispatch()
4645 ceph_mdsc_handle_mdsmap(mdsc, msg); in dispatch()
4648 ceph_mdsc_handle_fsmap(mdsc, msg); in dispatch()
4657 handle_forward(mdsc, s, msg); in dispatch()
4663 ceph_handle_snap(mdsc, s, msg); in dispatch()
4666 handle_lease(mdsc, s, msg); in dispatch()
4669 ceph_handle_quota(mdsc, s, msg); in dispatch()
4692 struct ceph_mds_client *mdsc = s->s_mdsc; in get_authorizer() local
4693 struct ceph_auth_client *ac = mdsc->fsc->client->monc.auth; in get_authorizer()
4720 struct ceph_mds_client *mdsc = s->s_mdsc; in add_authorizer_challenge() local
4721 struct ceph_auth_client *ac = mdsc->fsc->client->monc.auth; in add_authorizer_challenge()
4730 struct ceph_mds_client *mdsc = s->s_mdsc; in verify_authorizer_reply() local
4731 struct ceph_auth_client *ac = mdsc->fsc->client->monc.auth; in verify_authorizer_reply()
4739 struct ceph_mds_client *mdsc = s->s_mdsc; in invalidate_authorizer() local
4740 struct ceph_auth_client *ac = mdsc->fsc->client->monc.auth; in invalidate_authorizer()
4744 return ceph_monc_validate_auth(&mdsc->fsc->client->monc); in invalidate_authorizer()