Lines Matching refs:mdsc

60 static void __wake_requests(struct ceph_mds_client *mdsc,
671 struct ceph_mds_session *__ceph_lookup_mds_session(struct ceph_mds_client *mdsc, in __ceph_lookup_mds_session() argument
674 if (mds >= mdsc->max_sessions || !mdsc->sessions[mds]) in __ceph_lookup_mds_session()
676 return ceph_get_mds_session(mdsc->sessions[mds]); in __ceph_lookup_mds_session()
679 static bool __have_session(struct ceph_mds_client *mdsc, int mds) in __have_session() argument
681 if (mds >= mdsc->max_sessions || !mdsc->sessions[mds]) in __have_session()
687 static int __verify_registered_session(struct ceph_mds_client *mdsc, in __verify_registered_session() argument
690 if (s->s_mds >= mdsc->max_sessions || in __verify_registered_session()
691 mdsc->sessions[s->s_mds] != s) in __verify_registered_session()
700 static struct ceph_mds_session *register_session(struct ceph_mds_client *mdsc, in register_session() argument
705 if (mds >= mdsc->mdsmap->possible_max_rank) in register_session()
712 if (mds >= mdsc->max_sessions) { in register_session()
720 if (mdsc->sessions) { in register_session()
721 memcpy(sa, mdsc->sessions, in register_session()
722 mdsc->max_sessions * sizeof(void *)); in register_session()
723 kfree(mdsc->sessions); in register_session()
725 mdsc->sessions = sa; in register_session()
726 mdsc->max_sessions = newmax; in register_session()
730 s->s_mdsc = mdsc; in register_session()
737 ceph_con_init(&s->s_con, s, &mds_con_ops, &mdsc->fsc->client->msgr); in register_session()
761 mdsc->sessions[mds] = s; in register_session()
762 atomic_inc(&mdsc->num_sessions); in register_session()
766 ceph_mdsmap_get_addr(mdsc->mdsmap, mds)); in register_session()
778 static void __unregister_session(struct ceph_mds_client *mdsc, in __unregister_session() argument
782 BUG_ON(mdsc->sessions[s->s_mds] != s); in __unregister_session()
783 mdsc->sessions[s->s_mds] = NULL; in __unregister_session()
786 atomic_dec(&mdsc->num_sessions); in __unregister_session()
856 lookup_get_request(struct ceph_mds_client *mdsc, u64 tid) in DEFINE_RB_FUNCS()
860 req = lookup_request(&mdsc->request_tree, tid); in DEFINE_RB_FUNCS()
873 static void __register_request(struct ceph_mds_client *mdsc, in __register_request() argument
879 req->r_tid = ++mdsc->last_tid; in __register_request()
881 ret = ceph_reserve_caps(mdsc, &req->r_caps_reservation, in __register_request()
893 insert_request(&mdsc->request_tree, req); in __register_request()
898 if (mdsc->oldest_tid == 0 && req->r_op != CEPH_MDS_OP_SETFILELOCK) in __register_request()
899 mdsc->oldest_tid = req->r_tid; in __register_request()
912 static void __unregister_request(struct ceph_mds_client *mdsc, in __unregister_request() argument
920 if (req->r_tid == mdsc->oldest_tid) { in __unregister_request()
922 mdsc->oldest_tid = 0; in __unregister_request()
927 mdsc->oldest_tid = next_req->r_tid; in __unregister_request()
934 erase_request(&mdsc->request_tree, req); in __unregister_request()
991 static int __choose_mds(struct ceph_mds_client *mdsc, in __choose_mds() argument
1011 (__have_session(mdsc, req->r_resend_mds) || in __choose_mds()
1012 ceph_mdsmap_get_state(mdsc->mdsmap, req->r_resend_mds) > 0)) { in __choose_mds()
1042 if (!dir || dir->i_sb != mdsc->fsc->sb) { in __choose_mds()
1089 if (ceph_mdsmap_get_state(mdsc->mdsmap, mds) >= in __choose_mds()
1091 !ceph_mdsmap_is_laggy(mdsc->mdsmap, mds)) in __choose_mds()
1104 if (ceph_mdsmap_get_state(mdsc->mdsmap, mds) >= in __choose_mds()
1106 if (!ceph_mdsmap_is_laggy(mdsc->mdsmap, in __choose_mds()
1141 mds = ceph_mdsmap_get_random_mds(mdsc->mdsmap); in __choose_mds()
1242 static struct ceph_msg *create_session_open_msg(struct ceph_mds_client *mdsc, u64 seq) in create_session_open_msg() argument
1249 struct ceph_options *opt = mdsc->fsc->client->options; in create_session_open_msg()
1250 struct ceph_mount_options *fsopt = mdsc->fsc->mount_options; in create_session_open_msg()
1256 {"hostname", mdsc->nodename}, in create_session_open_msg()
1352 static int __open_session(struct ceph_mds_client *mdsc, in __open_session() argument
1360 mstate = ceph_mdsmap_get_state(mdsc->mdsmap, mds); in __open_session()
1367 msg = create_session_open_msg(mdsc, session->s_seq); in __open_session()
1380 __open_export_target_session(struct ceph_mds_client *mdsc, int target) in __open_export_target_session() argument
1385 session = __ceph_lookup_mds_session(mdsc, target); in __open_export_target_session()
1387 session = register_session(mdsc, target); in __open_export_target_session()
1393 ret = __open_session(mdsc, session); in __open_export_target_session()
1402 ceph_mdsc_open_export_target_session(struct ceph_mds_client *mdsc, int target) in ceph_mdsc_open_export_target_session() argument
1408 mutex_lock(&mdsc->mutex); in ceph_mdsc_open_export_target_session()
1409 session = __open_export_target_session(mdsc, target); in ceph_mdsc_open_export_target_session()
1410 mutex_unlock(&mdsc->mutex); in ceph_mdsc_open_export_target_session()
1415 static void __open_export_target_sessions(struct ceph_mds_client *mdsc, in __open_export_target_sessions() argument
1422 if (mds >= mdsc->mdsmap->possible_max_rank) in __open_export_target_sessions()
1425 mi = &mdsc->mdsmap->m_info[mds]; in __open_export_target_sessions()
1430 ts = __open_export_target_session(mdsc, mi->export_targets[i]); in __open_export_target_sessions()
1436 void ceph_mdsc_open_export_target_sessions(struct ceph_mds_client *mdsc, in ceph_mdsc_open_export_target_sessions() argument
1439 mutex_lock(&mdsc->mutex); in ceph_mdsc_open_export_target_sessions()
1440 __open_export_target_sessions(mdsc, session); in ceph_mdsc_open_export_target_sessions()
1441 mutex_unlock(&mdsc->mutex); in ceph_mdsc_open_export_target_sessions()
1458 static void dispose_cap_releases(struct ceph_mds_client *mdsc, in dispose_cap_releases() argument
1466 ceph_put_cap(mdsc, cap); in dispose_cap_releases()
1470 static void cleanup_session_requests(struct ceph_mds_client *mdsc, in cleanup_session_requests() argument
1478 mutex_lock(&mdsc->mutex); in cleanup_session_requests()
1494 __unregister_request(mdsc, req); in cleanup_session_requests()
1497 p = rb_first(&mdsc->request_tree); in cleanup_session_requests()
1505 mutex_unlock(&mdsc->mutex); in cleanup_session_requests()
1596 struct ceph_mds_client *mdsc = fsc->mdsc; in remove_session_caps_cb() local
1611 spin_lock(&mdsc->cap_dirty_lock); in remove_session_caps_cb()
1632 mdsc->num_cap_flushing--; in remove_session_caps_cb()
1635 spin_unlock(&mdsc->cap_dirty_lock); in remove_session_caps_cb()
1690 wake_up_all(&fsc->mdsc->cap_flushing_wq); in remove_session_caps()
1779 static int send_renew_caps(struct ceph_mds_client *mdsc, in send_renew_caps() argument
1792 state = ceph_mdsmap_get_state(mdsc->mdsmap, session->s_mds); in send_renew_caps()
1809 static int send_flushmsg_ack(struct ceph_mds_client *mdsc, in send_flushmsg_ack() argument
1829 static void renewed_caps(struct ceph_mds_client *mdsc, in renewed_caps() argument
1839 mdsc->mdsmap->m_session_timeout*HZ; in renewed_caps()
1878 static int __close_session(struct ceph_mds_client *mdsc, in __close_session() argument
1993 int ceph_trim_caps(struct ceph_mds_client *mdsc, in ceph_trim_caps() argument
2010 ceph_flush_cap_releases(mdsc, session); in ceph_trim_caps()
2014 static int check_caps_flush(struct ceph_mds_client *mdsc, in check_caps_flush() argument
2019 spin_lock(&mdsc->cap_dirty_lock); in check_caps_flush()
2020 if (!list_empty(&mdsc->cap_flush_list)) { in check_caps_flush()
2022 list_first_entry(&mdsc->cap_flush_list, in check_caps_flush()
2030 spin_unlock(&mdsc->cap_dirty_lock); in check_caps_flush()
2039 static void wait_caps_flush(struct ceph_mds_client *mdsc, in wait_caps_flush() argument
2044 wait_event(mdsc->cap_flushing_wq, in wait_caps_flush()
2045 check_caps_flush(mdsc, want_flush_tid)); in wait_caps_flush()
2053 static void ceph_send_cap_releases(struct ceph_mds_client *mdsc, in ceph_send_cap_releases() argument
2059 struct ceph_osd_client *osdc = &mdsc->fsc->client->osdc; in ceph_send_cap_releases()
2105 ceph_put_cap(mdsc, cap); in ceph_send_cap_releases()
2160 void ceph_flush_cap_releases(struct ceph_mds_client *mdsc, in ceph_flush_cap_releases() argument
2163 if (mdsc->stopping) in ceph_flush_cap_releases()
2167 if (queue_work(mdsc->fsc->cap_wq, in ceph_flush_cap_releases()
2191 struct ceph_mds_client *mdsc = in ceph_cap_reclaim_work() local
2193 int ret = ceph_trim_dentries(mdsc); in ceph_cap_reclaim_work()
2195 ceph_queue_cap_reclaim_work(mdsc); in ceph_cap_reclaim_work()
2198 void ceph_queue_cap_reclaim_work(struct ceph_mds_client *mdsc) in ceph_queue_cap_reclaim_work() argument
2200 if (mdsc->stopping) in ceph_queue_cap_reclaim_work()
2203 if (queue_work(mdsc->fsc->cap_wq, &mdsc->cap_reclaim_work)) { in ceph_queue_cap_reclaim_work()
2210 void ceph_reclaim_caps_nr(struct ceph_mds_client *mdsc, int nr) in ceph_reclaim_caps_nr() argument
2215 val = atomic_add_return(nr, &mdsc->cap_reclaim_pending); in ceph_reclaim_caps_nr()
2217 atomic_set(&mdsc->cap_reclaim_pending, 0); in ceph_reclaim_caps_nr()
2218 ceph_queue_cap_reclaim_work(mdsc); in ceph_reclaim_caps_nr()
2268 ceph_mdsc_create_request(struct ceph_mds_client *mdsc, int op, int mode) in ceph_mdsc_create_request() argument
2277 req->r_mdsc = mdsc; in ceph_mdsc_create_request()
2303 static struct ceph_mds_request *__get_oldest_req(struct ceph_mds_client *mdsc) in __get_oldest_req() argument
2305 if (RB_EMPTY_ROOT(&mdsc->request_tree)) in __get_oldest_req()
2307 return rb_entry(rb_first(&mdsc->request_tree), in __get_oldest_req()
2311 static inline u64 __get_oldest_tid(struct ceph_mds_client *mdsc) in __get_oldest_tid() argument
2313 return mdsc->oldest_tid; in __get_oldest_tid()
2485 static struct ceph_msg *create_request_message(struct ceph_mds_client *mdsc, in create_request_message() argument
2547 head->mdsmap_epoch = cpu_to_le32(mdsc->mdsmap->m_epoch); in create_request_message()
2628 static void complete_request(struct ceph_mds_client *mdsc, in complete_request() argument
2634 req->r_callback(mdsc, req); in complete_request()
2641 static int __prepare_send_request(struct ceph_mds_client *mdsc, in __prepare_send_request() argument
2702 msg = create_request_message(mdsc, req, mds, drop_cap_releases); in __prepare_send_request()
2710 rhead->oldest_client_tid = cpu_to_le64(__get_oldest_tid(mdsc)); in __prepare_send_request()
2728 static int __send_request(struct ceph_mds_client *mdsc, in __send_request() argument
2735 err = __prepare_send_request(mdsc, req, session->s_mds, in __send_request()
2748 static void __do_request(struct ceph_mds_client *mdsc, in __do_request() argument
2758 __unregister_request(mdsc, req); in __do_request()
2768 if (READ_ONCE(mdsc->fsc->mount_state) == CEPH_MOUNT_SHUTDOWN) { in __do_request()
2773 if (READ_ONCE(mdsc->fsc->mount_state) == CEPH_MOUNT_MOUNTING) { in __do_request()
2774 if (mdsc->mdsmap_err) { in __do_request()
2775 err = mdsc->mdsmap_err; in __do_request()
2779 if (mdsc->mdsmap->m_epoch == 0) { in __do_request()
2781 list_add(&req->r_wait, &mdsc->waiting_for_map); in __do_request()
2784 if (!(mdsc->fsc->mount_options->flags & in __do_request()
2786 !ceph_mdsmap_is_cluster_available(mdsc->mdsmap)) { in __do_request()
2794 mds = __choose_mds(mdsc, req, &random); in __do_request()
2796 ceph_mdsmap_get_state(mdsc->mdsmap, mds) < CEPH_MDS_STATE_ACTIVE) { in __do_request()
2802 list_add(&req->r_wait, &mdsc->waiting_for_map); in __do_request()
2807 session = __ceph_lookup_mds_session(mdsc, mds); in __do_request()
2809 session = register_session(mdsc, mds); in __do_request()
2836 err = __open_session(mdsc, session); in __do_request()
2853 err = __send_request(mdsc, session, req, false); in __do_request()
2861 complete_request(mdsc, req); in __do_request()
2862 __unregister_request(mdsc, req); in __do_request()
2870 static void __wake_requests(struct ceph_mds_client *mdsc, in __wake_requests() argument
2883 __do_request(mdsc, req); in __wake_requests()
2891 static void kick_requests(struct ceph_mds_client *mdsc, int mds) in kick_requests() argument
2894 struct rb_node *p = rb_first(&mdsc->request_tree); in kick_requests()
2908 __do_request(mdsc, req); in kick_requests()
2913 int ceph_mdsc_submit_request(struct ceph_mds_client *mdsc, struct inode *dir, in ceph_mdsc_submit_request() argument
2927 __ceph_touch_fmode(ci, mdsc, fmode); in ceph_mdsc_submit_request()
2954 mutex_lock(&mdsc->mutex); in ceph_mdsc_submit_request()
2955 __register_request(mdsc, req, dir); in ceph_mdsc_submit_request()
2956 __do_request(mdsc, req); in ceph_mdsc_submit_request()
2958 mutex_unlock(&mdsc->mutex); in ceph_mdsc_submit_request()
2962 static int ceph_mdsc_wait_request(struct ceph_mds_client *mdsc, in ceph_mdsc_wait_request() argument
2970 err = req->r_wait_for_completion(mdsc, req); in ceph_mdsc_wait_request()
2983 mutex_lock(&mdsc->mutex); in ceph_mdsc_wait_request()
3008 mutex_unlock(&mdsc->mutex); in ceph_mdsc_wait_request()
3016 int ceph_mdsc_do_request(struct ceph_mds_client *mdsc, in ceph_mdsc_do_request() argument
3025 err = ceph_mdsc_submit_request(mdsc, dir, req); in ceph_mdsc_do_request()
3027 err = ceph_mdsc_wait_request(mdsc, req); in ceph_mdsc_do_request()
3061 struct ceph_mds_client *mdsc = session->s_mdsc; in handle_reply() local
3078 mutex_lock(&mdsc->mutex); in handle_reply()
3079 req = lookup_get_request(mdsc, tid); in handle_reply()
3082 mutex_unlock(&mdsc->mutex); in handle_reply()
3092 mutex_unlock(&mdsc->mutex); in handle_reply()
3101 mutex_unlock(&mdsc->mutex); in handle_reply()
3107 mutex_unlock(&mdsc->mutex); in handle_reply()
3126 __do_request(mdsc, req); in handle_reply()
3127 mutex_unlock(&mdsc->mutex); in handle_reply()
3130 int mds = __choose_mds(mdsc, req, NULL); in handle_reply()
3133 __do_request(mdsc, req); in handle_reply()
3134 mutex_unlock(&mdsc->mutex); in handle_reply()
3144 __unregister_request(mdsc, req); in handle_reply()
3147 if (mdsc->stopping && !__get_oldest_req(mdsc)) in handle_reply()
3148 complete_all(&mdsc->safe_umount_waiters); in handle_reply()
3160 mutex_unlock(&mdsc->mutex); in handle_reply()
3174 mutex_unlock(&mdsc->mutex); in handle_reply()
3186 down_write(&mdsc->snap_rwsem); in handle_reply()
3187 ceph_update_snap_trace(mdsc, rinfo->snapblob, in handle_reply()
3191 downgrade_write(&mdsc->snap_rwsem); in handle_reply()
3193 down_read(&mdsc->snap_rwsem); in handle_reply()
3199 err = ceph_fill_trace(mdsc->fsc->sb, req); in handle_reply()
3208 up_read(&mdsc->snap_rwsem); in handle_reply()
3210 ceph_put_snap_realm(mdsc, realm); in handle_reply()
3223 ceph_unreserve_caps(mdsc, &req->r_caps_reservation); in handle_reply()
3226 mutex_lock(&mdsc->mutex); in handle_reply()
3237 mutex_unlock(&mdsc->mutex); in handle_reply()
3242 complete_request(mdsc, req); in handle_reply()
3244 ceph_update_metadata_latency(&mdsc->metric, req->r_start_latency, in handle_reply()
3256 static void handle_forward(struct ceph_mds_client *mdsc, in handle_forward() argument
3272 mutex_lock(&mdsc->mutex); in handle_forward()
3273 req = lookup_get_request(mdsc, tid); in handle_forward()
3281 __unregister_request(mdsc, req); in handle_forward()
3294 __do_request(mdsc, req); in handle_forward()
3298 mutex_unlock(&mdsc->mutex); in handle_forward()
3339 struct ceph_mds_client *mdsc = session->s_mdsc; in handle_session() local
3371 mutex_lock(&mdsc->mutex); in handle_session()
3374 __unregister_session(mdsc, session); in handle_session()
3377 session->s_ttl = jiffies + HZ*mdsc->mdsmap->m_session_autoclose; in handle_session()
3378 mutex_unlock(&mdsc->mutex); in handle_session()
3397 renewed_caps(mdsc, session, 0); in handle_session()
3399 metric_schedule_delayed(&mdsc->metric); in handle_session()
3401 if (mdsc->stopping) in handle_session()
3402 __close_session(mdsc, session); in handle_session()
3407 renewed_caps(mdsc, session, 1); in handle_session()
3414 cleanup_session_requests(mdsc, session); in handle_session()
3417 wake_up_all(&mdsc->session_close_wq); in handle_session()
3427 send_renew_caps(mdsc, session); in handle_session()
3431 ceph_trim_caps(mdsc, session, le32_to_cpu(h->max_caps)); in handle_session()
3435 send_flushmsg_ack(mdsc, session, seq); in handle_session()
3450 cleanup_session_requests(mdsc, session); in handle_session()
3453 mdsc->fsc->blocklisted = true; in handle_session()
3464 mutex_lock(&mdsc->mutex); in handle_session()
3465 __wake_requests(mdsc, &session->s_waiting); in handle_session()
3467 kick_requests(mdsc, mds); in handle_session()
3468 mutex_unlock(&mdsc->mutex); in handle_session()
3507 static void replay_unsafe_requests(struct ceph_mds_client *mdsc, in replay_unsafe_requests() argument
3515 mutex_lock(&mdsc->mutex); in replay_unsafe_requests()
3517 __send_request(mdsc, session, req, true); in replay_unsafe_requests()
3523 p = rb_first(&mdsc->request_tree); in replay_unsafe_requests()
3538 __send_request(mdsc, session, req, true); in replay_unsafe_requests()
3540 mutex_unlock(&mdsc->mutex); in replay_unsafe_requests()
3835 static int encode_snap_realms(struct ceph_mds_client *mdsc, in encode_snap_realms() argument
3843 err = ceph_pagelist_encode_32(pagelist, mdsc->num_snap_realms); in encode_snap_realms()
3853 for (p = rb_first(&mdsc->snap_realms); p; p = rb_next(p)) { in encode_snap_realms()
3905 static void send_mds_reconnect(struct ceph_mds_client *mdsc, in send_mds_reconnect() argument
3951 dispose_cap_releases(mdsc, &dispose); in send_mds_reconnect()
3954 if (mdsc->fsc->sb->s_root) in send_mds_reconnect()
3955 shrink_dcache_parent(mdsc->fsc->sb->s_root); in send_mds_reconnect()
3960 ceph_mdsmap_get_addr(mdsc->mdsmap, mds)); in send_mds_reconnect()
3963 replay_unsafe_requests(mdsc, session); in send_mds_reconnect()
3965 ceph_early_kick_flushing_caps(mdsc, session); in send_mds_reconnect()
3967 down_read(&mdsc->snap_rwsem); in send_mds_reconnect()
3993 if (mdsc->num_snap_realms) { in send_mds_reconnect()
3996 mdsc->num_snap_realms * in send_mds_reconnect()
4002 total_len += mdsc->num_snap_realms * in send_mds_reconnect()
4019 err = encode_snap_realms(mdsc, &recon_state); in send_mds_reconnect()
4035 WARN_ON(recon_state.nr_realms != mdsc->num_snap_realms); in send_mds_reconnect()
4054 mutex_lock(&mdsc->mutex); in send_mds_reconnect()
4055 __wake_requests(mdsc, &session->s_waiting); in send_mds_reconnect()
4056 mutex_unlock(&mdsc->mutex); in send_mds_reconnect()
4058 up_read(&mdsc->snap_rwsem); in send_mds_reconnect()
4064 up_read(&mdsc->snap_rwsem); in send_mds_reconnect()
4080 static void check_new_map(struct ceph_mds_client *mdsc, in check_new_map() argument
4091 for (i = 0; i < oldmap->possible_max_rank && i < mdsc->max_sessions; i++) { in check_new_map()
4092 if (!mdsc->sessions[i]) in check_new_map()
4094 s = mdsc->sessions[i]; in check_new_map()
4108 __unregister_session(mdsc, s); in check_new_map()
4109 __wake_requests(mdsc, &s->s_waiting); in check_new_map()
4110 mutex_unlock(&mdsc->mutex); in check_new_map()
4113 cleanup_session_requests(mdsc, s); in check_new_map()
4119 mutex_lock(&mdsc->mutex); in check_new_map()
4120 kick_requests(mdsc, i); in check_new_map()
4128 mutex_unlock(&mdsc->mutex); in check_new_map()
4130 mutex_lock(&mdsc->mutex); in check_new_map()
4143 mutex_unlock(&mdsc->mutex); in check_new_map()
4144 send_mds_reconnect(mdsc, s); in check_new_map()
4145 mutex_lock(&mdsc->mutex); in check_new_map()
4156 kick_requests(mdsc, i); in check_new_map()
4157 mutex_unlock(&mdsc->mutex); in check_new_map()
4159 mutex_lock(&mdsc->mutex); in check_new_map()
4160 ceph_kick_flushing_caps(mdsc, s); in check_new_map()
4166 for (i = 0; i < newmap->possible_max_rank && i < mdsc->max_sessions; i++) { in check_new_map()
4167 s = mdsc->sessions[i]; in check_new_map()
4177 __open_export_target_sessions(mdsc, s); in check_new_map()
4199 static void handle_lease(struct ceph_mds_client *mdsc, in handle_lease() argument
4203 struct super_block *sb = mdsc->fsc->sb; in handle_lease()
4346 static void lock_unlock_sessions(struct ceph_mds_client *mdsc) in lock_unlock_sessions() argument
4350 mutex_lock(&mdsc->mutex); in lock_unlock_sessions()
4351 for (i = 0; i < mdsc->max_sessions; i++) { in lock_unlock_sessions()
4352 struct ceph_mds_session *s = __ceph_lookup_mds_session(mdsc, i); in lock_unlock_sessions()
4355 mutex_unlock(&mdsc->mutex); in lock_unlock_sessions()
4359 mutex_lock(&mdsc->mutex); in lock_unlock_sessions()
4361 mutex_unlock(&mdsc->mutex); in lock_unlock_sessions()
4364 static void maybe_recover_session(struct ceph_mds_client *mdsc) in maybe_recover_session() argument
4366 struct ceph_fs_client *fsc = mdsc->fsc; in maybe_recover_session()
4433 static void schedule_delayed(struct ceph_mds_client *mdsc) in schedule_delayed() argument
4437 schedule_delayed_work(&mdsc->delayed_work, hz); in schedule_delayed()
4443 struct ceph_mds_client *mdsc = in delayed_work() local
4450 if (mdsc->stopping) in delayed_work()
4453 mutex_lock(&mdsc->mutex); in delayed_work()
4454 renew_interval = mdsc->mdsmap->m_session_timeout >> 2; in delayed_work()
4456 mdsc->last_renew_caps); in delayed_work()
4458 mdsc->last_renew_caps = jiffies; in delayed_work()
4460 for (i = 0; i < mdsc->max_sessions; i++) { in delayed_work()
4461 struct ceph_mds_session *s = __ceph_lookup_mds_session(mdsc, i); in delayed_work()
4469 mutex_unlock(&mdsc->mutex); in delayed_work()
4473 send_renew_caps(mdsc, s); in delayed_work()
4478 ceph_send_cap_releases(mdsc, s); in delayed_work()
4482 mutex_lock(&mdsc->mutex); in delayed_work()
4484 mutex_unlock(&mdsc->mutex); in delayed_work()
4486 ceph_check_delayed_caps(mdsc); in delayed_work()
4488 ceph_queue_cap_reclaim_work(mdsc); in delayed_work()
4490 ceph_trim_snapid_map(mdsc); in delayed_work()
4492 maybe_recover_session(mdsc); in delayed_work()
4494 schedule_delayed(mdsc); in delayed_work()
4500 struct ceph_mds_client *mdsc; in ceph_mdsc_init() local
4503 mdsc = kzalloc(sizeof(struct ceph_mds_client), GFP_NOFS); in ceph_mdsc_init()
4504 if (!mdsc) in ceph_mdsc_init()
4506 mdsc->fsc = fsc; in ceph_mdsc_init()
4507 mutex_init(&mdsc->mutex); in ceph_mdsc_init()
4508 mdsc->mdsmap = kzalloc(sizeof(*mdsc->mdsmap), GFP_NOFS); in ceph_mdsc_init()
4509 if (!mdsc->mdsmap) { in ceph_mdsc_init()
4514 init_completion(&mdsc->safe_umount_waiters); in ceph_mdsc_init()
4515 init_waitqueue_head(&mdsc->session_close_wq); in ceph_mdsc_init()
4516 INIT_LIST_HEAD(&mdsc->waiting_for_map); in ceph_mdsc_init()
4517 mdsc->sessions = NULL; in ceph_mdsc_init()
4518 atomic_set(&mdsc->num_sessions, 0); in ceph_mdsc_init()
4519 mdsc->max_sessions = 0; in ceph_mdsc_init()
4520 mdsc->stopping = 0; in ceph_mdsc_init()
4521 atomic64_set(&mdsc->quotarealms_count, 0); in ceph_mdsc_init()
4522 mdsc->quotarealms_inodes = RB_ROOT; in ceph_mdsc_init()
4523 mutex_init(&mdsc->quotarealms_inodes_mutex); in ceph_mdsc_init()
4524 mdsc->last_snap_seq = 0; in ceph_mdsc_init()
4525 init_rwsem(&mdsc->snap_rwsem); in ceph_mdsc_init()
4526 mdsc->snap_realms = RB_ROOT; in ceph_mdsc_init()
4527 INIT_LIST_HEAD(&mdsc->snap_empty); in ceph_mdsc_init()
4528 mdsc->num_snap_realms = 0; in ceph_mdsc_init()
4529 spin_lock_init(&mdsc->snap_empty_lock); in ceph_mdsc_init()
4530 mdsc->last_tid = 0; in ceph_mdsc_init()
4531 mdsc->oldest_tid = 0; in ceph_mdsc_init()
4532 mdsc->request_tree = RB_ROOT; in ceph_mdsc_init()
4533 INIT_DELAYED_WORK(&mdsc->delayed_work, delayed_work); in ceph_mdsc_init()
4534 mdsc->last_renew_caps = jiffies; in ceph_mdsc_init()
4535 INIT_LIST_HEAD(&mdsc->cap_delay_list); in ceph_mdsc_init()
4536 INIT_LIST_HEAD(&mdsc->cap_wait_list); in ceph_mdsc_init()
4537 spin_lock_init(&mdsc->cap_delay_lock); in ceph_mdsc_init()
4538 INIT_LIST_HEAD(&mdsc->snap_flush_list); in ceph_mdsc_init()
4539 spin_lock_init(&mdsc->snap_flush_lock); in ceph_mdsc_init()
4540 mdsc->last_cap_flush_tid = 1; in ceph_mdsc_init()
4541 INIT_LIST_HEAD(&mdsc->cap_flush_list); in ceph_mdsc_init()
4542 INIT_LIST_HEAD(&mdsc->cap_dirty_migrating); in ceph_mdsc_init()
4543 mdsc->num_cap_flushing = 0; in ceph_mdsc_init()
4544 spin_lock_init(&mdsc->cap_dirty_lock); in ceph_mdsc_init()
4545 init_waitqueue_head(&mdsc->cap_flushing_wq); in ceph_mdsc_init()
4546 INIT_WORK(&mdsc->cap_reclaim_work, ceph_cap_reclaim_work); in ceph_mdsc_init()
4547 atomic_set(&mdsc->cap_reclaim_pending, 0); in ceph_mdsc_init()
4548 err = ceph_metric_init(&mdsc->metric); in ceph_mdsc_init()
4552 spin_lock_init(&mdsc->dentry_list_lock); in ceph_mdsc_init()
4553 INIT_LIST_HEAD(&mdsc->dentry_leases); in ceph_mdsc_init()
4554 INIT_LIST_HEAD(&mdsc->dentry_dir_leases); in ceph_mdsc_init()
4556 ceph_caps_init(mdsc); in ceph_mdsc_init()
4557 ceph_adjust_caps_max_min(mdsc, fsc->mount_options); in ceph_mdsc_init()
4559 spin_lock_init(&mdsc->snapid_map_lock); in ceph_mdsc_init()
4560 mdsc->snapid_map_tree = RB_ROOT; in ceph_mdsc_init()
4561 INIT_LIST_HEAD(&mdsc->snapid_map_lru); in ceph_mdsc_init()
4563 init_rwsem(&mdsc->pool_perm_rwsem); in ceph_mdsc_init()
4564 mdsc->pool_perm_tree = RB_ROOT; in ceph_mdsc_init()
4566 strscpy(mdsc->nodename, utsname()->nodename, in ceph_mdsc_init()
4567 sizeof(mdsc->nodename)); in ceph_mdsc_init()
4569 fsc->mdsc = mdsc; in ceph_mdsc_init()
4573 kfree(mdsc->mdsmap); in ceph_mdsc_init()
4575 kfree(mdsc); in ceph_mdsc_init()
4583 static void wait_requests(struct ceph_mds_client *mdsc) in wait_requests() argument
4585 struct ceph_options *opts = mdsc->fsc->client->options; in wait_requests()
4588 mutex_lock(&mdsc->mutex); in wait_requests()
4589 if (__get_oldest_req(mdsc)) { in wait_requests()
4590 mutex_unlock(&mdsc->mutex); in wait_requests()
4593 wait_for_completion_timeout(&mdsc->safe_umount_waiters, in wait_requests()
4597 mutex_lock(&mdsc->mutex); in wait_requests()
4598 while ((req = __get_oldest_req(mdsc))) { in wait_requests()
4602 __unregister_request(mdsc, req); in wait_requests()
4605 mutex_unlock(&mdsc->mutex); in wait_requests()
4613 void ceph_mdsc_pre_umount(struct ceph_mds_client *mdsc) in ceph_mdsc_pre_umount() argument
4616 mdsc->stopping = 1; in ceph_mdsc_pre_umount()
4618 lock_unlock_sessions(mdsc); in ceph_mdsc_pre_umount()
4619 ceph_flush_dirty_caps(mdsc); in ceph_mdsc_pre_umount()
4620 wait_requests(mdsc); in ceph_mdsc_pre_umount()
4628 ceph_cleanup_quotarealms_inodes(mdsc); in ceph_mdsc_pre_umount()
4634 static void wait_unsafe_requests(struct ceph_mds_client *mdsc, u64 want_tid) in wait_unsafe_requests() argument
4639 mutex_lock(&mdsc->mutex); in wait_unsafe_requests()
4642 req = __get_oldest_req(mdsc); in wait_unsafe_requests()
4656 mutex_unlock(&mdsc->mutex); in wait_unsafe_requests()
4660 mutex_lock(&mdsc->mutex); in wait_unsafe_requests()
4673 mutex_unlock(&mdsc->mutex); in wait_unsafe_requests()
4677 void ceph_mdsc_sync(struct ceph_mds_client *mdsc) in ceph_mdsc_sync() argument
4681 if (READ_ONCE(mdsc->fsc->mount_state) == CEPH_MOUNT_SHUTDOWN) in ceph_mdsc_sync()
4685 mutex_lock(&mdsc->mutex); in ceph_mdsc_sync()
4686 want_tid = mdsc->last_tid; in ceph_mdsc_sync()
4687 mutex_unlock(&mdsc->mutex); in ceph_mdsc_sync()
4689 ceph_flush_dirty_caps(mdsc); in ceph_mdsc_sync()
4690 spin_lock(&mdsc->cap_dirty_lock); in ceph_mdsc_sync()
4691 want_flush = mdsc->last_cap_flush_tid; in ceph_mdsc_sync()
4692 if (!list_empty(&mdsc->cap_flush_list)) { in ceph_mdsc_sync()
4694 list_last_entry(&mdsc->cap_flush_list, in ceph_mdsc_sync()
4698 spin_unlock(&mdsc->cap_dirty_lock); in ceph_mdsc_sync()
4703 wait_unsafe_requests(mdsc, want_tid); in ceph_mdsc_sync()
4704 wait_caps_flush(mdsc, want_flush); in ceph_mdsc_sync()
4710 static bool done_closing_sessions(struct ceph_mds_client *mdsc, int skipped) in done_closing_sessions() argument
4712 if (READ_ONCE(mdsc->fsc->mount_state) == CEPH_MOUNT_SHUTDOWN) in done_closing_sessions()
4714 return atomic_read(&mdsc->num_sessions) <= skipped; in done_closing_sessions()
4720 void ceph_mdsc_close_sessions(struct ceph_mds_client *mdsc) in ceph_mdsc_close_sessions() argument
4722 struct ceph_options *opts = mdsc->fsc->client->options; in ceph_mdsc_close_sessions()
4730 mutex_lock(&mdsc->mutex); in ceph_mdsc_close_sessions()
4731 for (i = 0; i < mdsc->max_sessions; i++) { in ceph_mdsc_close_sessions()
4732 session = __ceph_lookup_mds_session(mdsc, i); in ceph_mdsc_close_sessions()
4735 mutex_unlock(&mdsc->mutex); in ceph_mdsc_close_sessions()
4737 if (__close_session(mdsc, session) <= 0) in ceph_mdsc_close_sessions()
4741 mutex_lock(&mdsc->mutex); in ceph_mdsc_close_sessions()
4743 mutex_unlock(&mdsc->mutex); in ceph_mdsc_close_sessions()
4746 wait_event_timeout(mdsc->session_close_wq, in ceph_mdsc_close_sessions()
4747 done_closing_sessions(mdsc, skipped), in ceph_mdsc_close_sessions()
4751 mutex_lock(&mdsc->mutex); in ceph_mdsc_close_sessions()
4752 for (i = 0; i < mdsc->max_sessions; i++) { in ceph_mdsc_close_sessions()
4753 if (mdsc->sessions[i]) { in ceph_mdsc_close_sessions()
4754 session = ceph_get_mds_session(mdsc->sessions[i]); in ceph_mdsc_close_sessions()
4755 __unregister_session(mdsc, session); in ceph_mdsc_close_sessions()
4756 mutex_unlock(&mdsc->mutex); in ceph_mdsc_close_sessions()
4761 mutex_lock(&mdsc->mutex); in ceph_mdsc_close_sessions()
4764 WARN_ON(!list_empty(&mdsc->cap_delay_list)); in ceph_mdsc_close_sessions()
4765 mutex_unlock(&mdsc->mutex); in ceph_mdsc_close_sessions()
4767 ceph_cleanup_snapid_map(mdsc); in ceph_mdsc_close_sessions()
4768 ceph_cleanup_empty_realms(mdsc); in ceph_mdsc_close_sessions()
4770 cancel_work_sync(&mdsc->cap_reclaim_work); in ceph_mdsc_close_sessions()
4771 cancel_delayed_work_sync(&mdsc->delayed_work); /* cancel timer */ in ceph_mdsc_close_sessions()
4776 void ceph_mdsc_force_umount(struct ceph_mds_client *mdsc) in ceph_mdsc_force_umount() argument
4783 mutex_lock(&mdsc->mutex); in ceph_mdsc_force_umount()
4784 for (mds = 0; mds < mdsc->max_sessions; mds++) { in ceph_mdsc_force_umount()
4785 session = __ceph_lookup_mds_session(mdsc, mds); in ceph_mdsc_force_umount()
4790 __unregister_session(mdsc, session); in ceph_mdsc_force_umount()
4791 __wake_requests(mdsc, &session->s_waiting); in ceph_mdsc_force_umount()
4792 mutex_unlock(&mdsc->mutex); in ceph_mdsc_force_umount()
4795 __close_session(mdsc, session); in ceph_mdsc_force_umount()
4797 cleanup_session_requests(mdsc, session); in ceph_mdsc_force_umount()
4803 mutex_lock(&mdsc->mutex); in ceph_mdsc_force_umount()
4804 kick_requests(mdsc, mds); in ceph_mdsc_force_umount()
4806 __wake_requests(mdsc, &mdsc->waiting_for_map); in ceph_mdsc_force_umount()
4807 mutex_unlock(&mdsc->mutex); in ceph_mdsc_force_umount()
4810 static void ceph_mdsc_stop(struct ceph_mds_client *mdsc) in ceph_mdsc_stop() argument
4821 flush_delayed_work(&mdsc->delayed_work); in ceph_mdsc_stop()
4823 if (mdsc->mdsmap) in ceph_mdsc_stop()
4824 ceph_mdsmap_destroy(mdsc->mdsmap); in ceph_mdsc_stop()
4825 kfree(mdsc->sessions); in ceph_mdsc_stop()
4826 ceph_caps_finalize(mdsc); in ceph_mdsc_stop()
4827 ceph_pool_perm_destroy(mdsc); in ceph_mdsc_stop()
4832 struct ceph_mds_client *mdsc = fsc->mdsc; in ceph_mdsc_destroy() local
4833 dout("mdsc_destroy %p\n", mdsc); in ceph_mdsc_destroy()
4835 if (!mdsc) in ceph_mdsc_destroy()
4841 ceph_mdsc_stop(mdsc); in ceph_mdsc_destroy()
4843 ceph_metric_destroy(&mdsc->metric); in ceph_mdsc_destroy()
4845 flush_delayed_work(&mdsc->metric.delayed_work); in ceph_mdsc_destroy()
4846 fsc->mdsc = NULL; in ceph_mdsc_destroy()
4847 kfree(mdsc); in ceph_mdsc_destroy()
4848 dout("mdsc_destroy %p done\n", mdsc); in ceph_mdsc_destroy()
4851 void ceph_mdsc_handle_fsmap(struct ceph_mds_client *mdsc, struct ceph_msg *msg) in ceph_mdsc_handle_fsmap() argument
4853 struct ceph_fs_client *fsc = mdsc->fsc; in ceph_mdsc_handle_fsmap()
4921 mutex_lock(&mdsc->mutex); in ceph_mdsc_handle_fsmap()
4922 mdsc->mdsmap_err = err; in ceph_mdsc_handle_fsmap()
4923 __wake_requests(mdsc, &mdsc->waiting_for_map); in ceph_mdsc_handle_fsmap()
4924 mutex_unlock(&mdsc->mutex); in ceph_mdsc_handle_fsmap()
4930 void ceph_mdsc_handle_mdsmap(struct ceph_mds_client *mdsc, struct ceph_msg *msg) in ceph_mdsc_handle_mdsmap() argument
4942 if (ceph_check_fsid(mdsc->fsc->client, &fsid) < 0) in ceph_mdsc_handle_mdsmap()
4949 mutex_lock(&mdsc->mutex); in ceph_mdsc_handle_mdsmap()
4950 if (mdsc->mdsmap && epoch <= mdsc->mdsmap->m_epoch) { in ceph_mdsc_handle_mdsmap()
4952 epoch, mdsc->mdsmap->m_epoch); in ceph_mdsc_handle_mdsmap()
4953 mutex_unlock(&mdsc->mutex); in ceph_mdsc_handle_mdsmap()
4964 if (mdsc->mdsmap) { in ceph_mdsc_handle_mdsmap()
4965 oldmap = mdsc->mdsmap; in ceph_mdsc_handle_mdsmap()
4966 mdsc->mdsmap = newmap; in ceph_mdsc_handle_mdsmap()
4967 check_new_map(mdsc, newmap, oldmap); in ceph_mdsc_handle_mdsmap()
4970 mdsc->mdsmap = newmap; /* first mds map */ in ceph_mdsc_handle_mdsmap()
4972 mdsc->fsc->max_file_size = min((loff_t)mdsc->mdsmap->m_max_file_size, in ceph_mdsc_handle_mdsmap()
4975 __wake_requests(mdsc, &mdsc->waiting_for_map); in ceph_mdsc_handle_mdsmap()
4976 ceph_monc_got_map(&mdsc->fsc->client->monc, CEPH_SUB_MDSMAP, in ceph_mdsc_handle_mdsmap()
4977 mdsc->mdsmap->m_epoch); in ceph_mdsc_handle_mdsmap()
4979 mutex_unlock(&mdsc->mutex); in ceph_mdsc_handle_mdsmap()
4980 schedule_delayed(mdsc); in ceph_mdsc_handle_mdsmap()
4984 mutex_unlock(&mdsc->mutex); in ceph_mdsc_handle_mdsmap()
5013 struct ceph_mds_client *mdsc = s->s_mdsc; in peer_reset() local
5016 send_mds_reconnect(mdsc, s); in peer_reset()
5022 struct ceph_mds_client *mdsc = s->s_mdsc; in dispatch() local
5025 mutex_lock(&mdsc->mutex); in dispatch()
5026 if (__verify_registered_session(mdsc, s) < 0) { in dispatch()
5027 mutex_unlock(&mdsc->mutex); in dispatch()
5030 mutex_unlock(&mdsc->mutex); in dispatch()
5034 ceph_mdsc_handle_mdsmap(mdsc, msg); in dispatch()
5037 ceph_mdsc_handle_fsmap(mdsc, msg); in dispatch()
5046 handle_forward(mdsc, s, msg); in dispatch()
5052 ceph_handle_snap(mdsc, s, msg); in dispatch()
5055 handle_lease(mdsc, s, msg); in dispatch()
5058 ceph_handle_quota(mdsc, s, msg); in dispatch()
5081 struct ceph_mds_client *mdsc = s->s_mdsc; in get_authorizer() local
5082 struct ceph_auth_client *ac = mdsc->fsc->client->monc.auth; in get_authorizer()
5109 struct ceph_mds_client *mdsc = s->s_mdsc; in add_authorizer_challenge() local
5110 struct ceph_auth_client *ac = mdsc->fsc->client->monc.auth; in add_authorizer_challenge()
5119 struct ceph_mds_client *mdsc = s->s_mdsc; in verify_authorizer_reply() local
5120 struct ceph_auth_client *ac = mdsc->fsc->client->monc.auth; in verify_authorizer_reply()
5128 struct ceph_mds_client *mdsc = s->s_mdsc; in invalidate_authorizer() local
5129 struct ceph_auth_client *ac = mdsc->fsc->client->monc.auth; in invalidate_authorizer()
5133 return ceph_monc_validate_auth(&mdsc->fsc->client->monc); in invalidate_authorizer()