Lines Matching refs:mdsc
54 static void __wake_requests(struct ceph_mds_client *mdsc,
426 struct ceph_mds_session *__ceph_lookup_mds_session(struct ceph_mds_client *mdsc, in __ceph_lookup_mds_session() argument
431 if (mds >= mdsc->max_sessions || !mdsc->sessions[mds]) in __ceph_lookup_mds_session()
433 session = mdsc->sessions[mds]; in __ceph_lookup_mds_session()
440 static bool __have_session(struct ceph_mds_client *mdsc, int mds) in __have_session() argument
442 if (mds >= mdsc->max_sessions || !mdsc->sessions[mds]) in __have_session()
448 static int __verify_registered_session(struct ceph_mds_client *mdsc, in __verify_registered_session() argument
451 if (s->s_mds >= mdsc->max_sessions || in __verify_registered_session()
452 mdsc->sessions[s->s_mds] != s) in __verify_registered_session()
461 static struct ceph_mds_session *register_session(struct ceph_mds_client *mdsc, in register_session() argument
466 if (mds >= mdsc->mdsmap->m_num_mds) in register_session()
473 if (mds >= mdsc->max_sessions) { in register_session()
481 if (mdsc->sessions) { in register_session()
482 memcpy(sa, mdsc->sessions, in register_session()
483 mdsc->max_sessions * sizeof(void *)); in register_session()
484 kfree(mdsc->sessions); in register_session()
486 mdsc->sessions = sa; in register_session()
487 mdsc->max_sessions = newmax; in register_session()
491 s->s_mdsc = mdsc; in register_session()
498 ceph_con_init(&s->s_con, s, &mds_con_ops, &mdsc->fsc->client->msgr); in register_session()
519 mdsc->sessions[mds] = s; in register_session()
520 atomic_inc(&mdsc->num_sessions); in register_session()
524 ceph_mdsmap_get_addr(mdsc->mdsmap, mds)); in register_session()
536 static void __unregister_session(struct ceph_mds_client *mdsc, in __unregister_session() argument
540 BUG_ON(mdsc->sessions[s->s_mds] != s); in __unregister_session()
541 mdsc->sessions[s->s_mds] = NULL; in __unregister_session()
544 atomic_dec(&mdsc->num_sessions); in __unregister_session()
609 lookup_get_request(struct ceph_mds_client *mdsc, u64 tid) in DEFINE_RB_FUNCS()
613 req = lookup_request(&mdsc->request_tree, tid); in DEFINE_RB_FUNCS()
626 static void __register_request(struct ceph_mds_client *mdsc, in __register_request() argument
632 req->r_tid = ++mdsc->last_tid; in __register_request()
634 ret = ceph_reserve_caps(mdsc, &req->r_caps_reservation, in __register_request()
646 insert_request(&mdsc->request_tree, req); in __register_request()
651 if (mdsc->oldest_tid == 0 && req->r_op != CEPH_MDS_OP_SETFILELOCK) in __register_request()
652 mdsc->oldest_tid = req->r_tid; in __register_request()
660 static void __unregister_request(struct ceph_mds_client *mdsc, in __unregister_request() argument
668 if (req->r_tid == mdsc->oldest_tid) { in __unregister_request()
670 mdsc->oldest_tid = 0; in __unregister_request()
675 mdsc->oldest_tid = next_req->r_tid; in __unregister_request()
682 erase_request(&mdsc->request_tree, req); in __unregister_request()
739 static int __choose_mds(struct ceph_mds_client *mdsc, in __choose_mds() argument
755 (__have_session(mdsc, req->r_resend_mds) || in __choose_mds()
756 ceph_mdsmap_get_state(mdsc->mdsmap, req->r_resend_mds) > 0)) { in __choose_mds()
786 if (!dir || dir->i_sb != mdsc->fsc->sb) { in __choose_mds()
835 if (ceph_mdsmap_get_state(mdsc->mdsmap, mds) >= in __choose_mds()
850 if (ceph_mdsmap_get_state(mdsc->mdsmap, mds) >= in __choose_mds()
878 mds = ceph_mdsmap_get_random_mds(mdsc->mdsmap); in __choose_mds()
930 static struct ceph_msg *create_session_open_msg(struct ceph_mds_client *mdsc, u64 seq) in create_session_open_msg() argument
937 struct ceph_options *opt = mdsc->fsc->client->options; in create_session_open_msg()
938 struct ceph_mount_options *fsopt = mdsc->fsc->mount_options; in create_session_open_msg()
942 {"hostname", mdsc->nodename}, in create_session_open_msg()
1013 static int __open_session(struct ceph_mds_client *mdsc, in __open_session() argument
1021 mstate = ceph_mdsmap_get_state(mdsc->mdsmap, mds); in __open_session()
1028 msg = create_session_open_msg(mdsc, session->s_seq); in __open_session()
1041 __open_export_target_session(struct ceph_mds_client *mdsc, int target) in __open_export_target_session() argument
1045 session = __ceph_lookup_mds_session(mdsc, target); in __open_export_target_session()
1047 session = register_session(mdsc, target); in __open_export_target_session()
1053 __open_session(mdsc, session); in __open_export_target_session()
1059 ceph_mdsc_open_export_target_session(struct ceph_mds_client *mdsc, int target) in ceph_mdsc_open_export_target_session() argument
1065 mutex_lock(&mdsc->mutex); in ceph_mdsc_open_export_target_session()
1066 session = __open_export_target_session(mdsc, target); in ceph_mdsc_open_export_target_session()
1067 mutex_unlock(&mdsc->mutex); in ceph_mdsc_open_export_target_session()
1072 static void __open_export_target_sessions(struct ceph_mds_client *mdsc, in __open_export_target_sessions() argument
1079 if (mds >= mdsc->mdsmap->m_num_mds) in __open_export_target_sessions()
1082 mi = &mdsc->mdsmap->m_info[mds]; in __open_export_target_sessions()
1087 ts = __open_export_target_session(mdsc, mi->export_targets[i]); in __open_export_target_sessions()
1093 void ceph_mdsc_open_export_target_sessions(struct ceph_mds_client *mdsc, in ceph_mdsc_open_export_target_sessions() argument
1096 mutex_lock(&mdsc->mutex); in ceph_mdsc_open_export_target_sessions()
1097 __open_export_target_sessions(mdsc, session); in ceph_mdsc_open_export_target_sessions()
1098 mutex_unlock(&mdsc->mutex); in ceph_mdsc_open_export_target_sessions()
1115 static void dispose_cap_releases(struct ceph_mds_client *mdsc, in dispose_cap_releases() argument
1123 ceph_put_cap(mdsc, cap); in dispose_cap_releases()
1127 static void cleanup_session_requests(struct ceph_mds_client *mdsc, in cleanup_session_requests() argument
1134 mutex_lock(&mdsc->mutex); in cleanup_session_requests()
1140 __unregister_request(mdsc, req); in cleanup_session_requests()
1143 p = rb_first(&mdsc->request_tree); in cleanup_session_requests()
1151 mutex_unlock(&mdsc->mutex); in cleanup_session_requests()
1242 struct ceph_mds_client *mdsc = fsc->mdsc; in remove_session_caps_cb() local
1256 spin_lock(&mdsc->cap_dirty_lock); in remove_session_caps_cb()
1277 mdsc->num_cap_flushing--; in remove_session_caps_cb()
1280 spin_unlock(&mdsc->cap_dirty_lock); in remove_session_caps_cb()
1323 wake_up_all(&fsc->mdsc->cap_flushing_wq); in remove_session_caps()
1397 static int send_renew_caps(struct ceph_mds_client *mdsc, in send_renew_caps() argument
1410 state = ceph_mdsmap_get_state(mdsc->mdsmap, session->s_mds); in send_renew_caps()
1427 static int send_flushmsg_ack(struct ceph_mds_client *mdsc, in send_flushmsg_ack() argument
1447 static void renewed_caps(struct ceph_mds_client *mdsc, in renewed_caps() argument
1457 mdsc->mdsmap->m_session_timeout*HZ; in renewed_caps()
1479 static int request_close_session(struct ceph_mds_client *mdsc, in request_close_session() argument
1497 static int __close_session(struct ceph_mds_client *mdsc, in __close_session() argument
1503 return request_close_session(mdsc, session); in __close_session()
1611 int ceph_trim_caps(struct ceph_mds_client *mdsc, in ceph_trim_caps() argument
1628 ceph_send_cap_releases(mdsc, session); in ceph_trim_caps()
1632 static int check_caps_flush(struct ceph_mds_client *mdsc, in check_caps_flush() argument
1637 spin_lock(&mdsc->cap_dirty_lock); in check_caps_flush()
1638 if (!list_empty(&mdsc->cap_flush_list)) { in check_caps_flush()
1640 list_first_entry(&mdsc->cap_flush_list, in check_caps_flush()
1648 spin_unlock(&mdsc->cap_dirty_lock); in check_caps_flush()
1657 static void wait_caps_flush(struct ceph_mds_client *mdsc, in wait_caps_flush() argument
1662 wait_event(mdsc->cap_flushing_wq, in wait_caps_flush()
1663 check_caps_flush(mdsc, want_flush_tid)); in wait_caps_flush()
1671 void ceph_send_cap_releases(struct ceph_mds_client *mdsc, in ceph_send_cap_releases() argument
1677 struct ceph_osd_client *osdc = &mdsc->fsc->client->osdc; in ceph_send_cap_releases()
1722 ceph_put_cap(mdsc, cap); in ceph_send_cap_releases()
1809 ceph_mdsc_create_request(struct ceph_mds_client *mdsc, int op, int mode) in ceph_mdsc_create_request() argument
1818 req->r_mdsc = mdsc; in ceph_mdsc_create_request()
1832 req->r_stamp = timespec64_trunc(ts, mdsc->fsc->sb->s_time_gran); in ceph_mdsc_create_request()
1844 static struct ceph_mds_request *__get_oldest_req(struct ceph_mds_client *mdsc) in __get_oldest_req() argument
1846 if (RB_EMPTY_ROOT(&mdsc->request_tree)) in __get_oldest_req()
1848 return rb_entry(rb_first(&mdsc->request_tree), in __get_oldest_req()
1852 static inline u64 __get_oldest_tid(struct ceph_mds_client *mdsc) in __get_oldest_tid() argument
1854 return mdsc->oldest_tid; in __get_oldest_tid()
2028 static struct ceph_msg *create_request_message(struct ceph_mds_client *mdsc, in create_request_message() argument
2087 head->mdsmap_epoch = cpu_to_le32(mdsc->mdsmap->m_epoch); in create_request_message()
2162 static void complete_request(struct ceph_mds_client *mdsc, in complete_request() argument
2166 req->r_callback(mdsc, req); in complete_request()
2174 static int __prepare_send_request(struct ceph_mds_client *mdsc, in __prepare_send_request() argument
2235 msg = create_request_message(mdsc, req, mds, drop_cap_releases); in __prepare_send_request()
2243 rhead->oldest_client_tid = cpu_to_le64(__get_oldest_tid(mdsc)); in __prepare_send_request()
2260 static void __do_request(struct ceph_mds_client *mdsc, in __do_request() argument
2269 __unregister_request(mdsc, req); in __do_request()
2279 if (READ_ONCE(mdsc->fsc->mount_state) == CEPH_MOUNT_SHUTDOWN) { in __do_request()
2284 if (READ_ONCE(mdsc->fsc->mount_state) == CEPH_MOUNT_MOUNTING) { in __do_request()
2285 if (mdsc->mdsmap_err) { in __do_request()
2286 err = mdsc->mdsmap_err; in __do_request()
2290 if (mdsc->mdsmap->m_epoch == 0) { in __do_request()
2292 list_add(&req->r_wait, &mdsc->waiting_for_map); in __do_request()
2295 if (!(mdsc->fsc->mount_options->flags & in __do_request()
2297 !ceph_mdsmap_is_cluster_available(mdsc->mdsmap)) { in __do_request()
2306 mds = __choose_mds(mdsc, req); in __do_request()
2308 ceph_mdsmap_get_state(mdsc->mdsmap, mds) < CEPH_MDS_STATE_ACTIVE) { in __do_request()
2310 list_add(&req->r_wait, &mdsc->waiting_for_map); in __do_request()
2315 session = __ceph_lookup_mds_session(mdsc, mds); in __do_request()
2317 session = register_session(mdsc, mds); in __do_request()
2335 __open_session(mdsc, session); in __do_request()
2346 err = __prepare_send_request(mdsc, req, mds, false); in __do_request()
2358 complete_request(mdsc, req); in __do_request()
2359 __unregister_request(mdsc, req); in __do_request()
2367 static void __wake_requests(struct ceph_mds_client *mdsc, in __wake_requests() argument
2380 __do_request(mdsc, req); in __wake_requests()
2388 static void kick_requests(struct ceph_mds_client *mdsc, int mds) in kick_requests() argument
2391 struct rb_node *p = rb_first(&mdsc->request_tree); in kick_requests()
2405 __do_request(mdsc, req); in kick_requests()
2410 void ceph_mdsc_submit_request(struct ceph_mds_client *mdsc, in ceph_mdsc_submit_request() argument
2414 mutex_lock(&mdsc->mutex); in ceph_mdsc_submit_request()
2415 __register_request(mdsc, req, NULL); in ceph_mdsc_submit_request()
2416 __do_request(mdsc, req); in ceph_mdsc_submit_request()
2417 mutex_unlock(&mdsc->mutex); in ceph_mdsc_submit_request()
2424 int ceph_mdsc_do_request(struct ceph_mds_client *mdsc, in ceph_mdsc_do_request() argument
2442 mutex_lock(&mdsc->mutex); in ceph_mdsc_do_request()
2443 __register_request(mdsc, req, dir); in ceph_mdsc_do_request()
2444 __do_request(mdsc, req); in ceph_mdsc_do_request()
2452 mutex_unlock(&mdsc->mutex); in ceph_mdsc_do_request()
2455 err = req->r_wait_for_completion(mdsc, req); in ceph_mdsc_do_request()
2468 mutex_lock(&mdsc->mutex); in ceph_mdsc_do_request()
2494 mutex_unlock(&mdsc->mutex); in ceph_mdsc_do_request()
2528 struct ceph_mds_client *mdsc = session->s_mdsc; in handle_reply() local
2545 mutex_lock(&mdsc->mutex); in handle_reply()
2546 req = lookup_get_request(mdsc, tid); in handle_reply()
2549 mutex_unlock(&mdsc->mutex); in handle_reply()
2559 mutex_unlock(&mdsc->mutex); in handle_reply()
2568 mutex_unlock(&mdsc->mutex); in handle_reply()
2574 mutex_unlock(&mdsc->mutex); in handle_reply()
2593 __do_request(mdsc, req); in handle_reply()
2594 mutex_unlock(&mdsc->mutex); in handle_reply()
2597 int mds = __choose_mds(mdsc, req); in handle_reply()
2600 __do_request(mdsc, req); in handle_reply()
2601 mutex_unlock(&mdsc->mutex); in handle_reply()
2611 __unregister_request(mdsc, req); in handle_reply()
2624 if (mdsc->stopping && !__get_oldest_req(mdsc)) in handle_reply()
2625 complete_all(&mdsc->safe_umount_waiters); in handle_reply()
2626 mutex_unlock(&mdsc->mutex); in handle_reply()
2645 mutex_unlock(&mdsc->mutex); in handle_reply()
2657 down_write(&mdsc->snap_rwsem); in handle_reply()
2658 ceph_update_snap_trace(mdsc, rinfo->snapblob, in handle_reply()
2662 downgrade_write(&mdsc->snap_rwsem); in handle_reply()
2664 down_read(&mdsc->snap_rwsem); in handle_reply()
2670 err = ceph_fill_trace(mdsc->fsc->sb, req); in handle_reply()
2675 ceph_unreserve_caps(mdsc, &req->r_caps_reservation); in handle_reply()
2680 up_read(&mdsc->snap_rwsem); in handle_reply()
2682 ceph_put_snap_realm(mdsc, realm); in handle_reply()
2692 mutex_lock(&mdsc->mutex); in handle_reply()
2703 mutex_unlock(&mdsc->mutex); in handle_reply()
2708 complete_request(mdsc, req); in handle_reply()
2719 static void handle_forward(struct ceph_mds_client *mdsc, in handle_forward() argument
2735 mutex_lock(&mdsc->mutex); in handle_forward()
2736 req = lookup_get_request(mdsc, tid); in handle_forward()
2744 __unregister_request(mdsc, req); in handle_forward()
2757 __do_request(mdsc, req); in handle_forward()
2761 mutex_unlock(&mdsc->mutex); in handle_forward()
2774 struct ceph_mds_client *mdsc = session->s_mdsc; in handle_session() local
2787 mutex_lock(&mdsc->mutex); in handle_session()
2790 __unregister_session(mdsc, session); in handle_session()
2793 session->s_ttl = jiffies + HZ*mdsc->mdsmap->m_session_autoclose; in handle_session()
2794 mutex_unlock(&mdsc->mutex); in handle_session()
2812 renewed_caps(mdsc, session, 0); in handle_session()
2814 if (mdsc->stopping) in handle_session()
2815 __close_session(mdsc, session); in handle_session()
2820 renewed_caps(mdsc, session, 1); in handle_session()
2826 cleanup_session_requests(mdsc, session); in handle_session()
2829 wake_up_all(&mdsc->session_close_wq); in handle_session()
2839 send_renew_caps(mdsc, session); in handle_session()
2843 ceph_trim_caps(mdsc, session, le32_to_cpu(h->max_caps)); in handle_session()
2847 send_flushmsg_ack(mdsc, session, seq); in handle_session()
2862 cleanup_session_requests(mdsc, session); in handle_session()
2874 mutex_lock(&mdsc->mutex); in handle_session()
2875 __wake_requests(mdsc, &session->s_waiting); in handle_session()
2877 kick_requests(mdsc, mds); in handle_session()
2878 mutex_unlock(&mdsc->mutex); in handle_session()
2895 static void replay_unsafe_requests(struct ceph_mds_client *mdsc, in replay_unsafe_requests() argument
2904 mutex_lock(&mdsc->mutex); in replay_unsafe_requests()
2906 err = __prepare_send_request(mdsc, req, session->s_mds, true); in replay_unsafe_requests()
2917 p = rb_first(&mdsc->request_tree); in replay_unsafe_requests()
2927 err = __prepare_send_request(mdsc, req, in replay_unsafe_requests()
2935 mutex_unlock(&mdsc->mutex); in replay_unsafe_requests()
3115 static void send_mds_reconnect(struct ceph_mds_client *mdsc, in send_mds_reconnect() argument
3161 dispose_cap_releases(mdsc, &dispose); in send_mds_reconnect()
3164 if (mdsc->fsc->sb->s_root) in send_mds_reconnect()
3165 shrink_dcache_parent(mdsc->fsc->sb->s_root); in send_mds_reconnect()
3170 ceph_mdsmap_get_addr(mdsc->mdsmap, mds)); in send_mds_reconnect()
3173 replay_unsafe_requests(mdsc, session); in send_mds_reconnect()
3175 down_read(&mdsc->snap_rwsem); in send_mds_reconnect()
3204 for (p = rb_first(&mdsc->snap_realms); p; p = rb_next(p)) { in send_mds_reconnect()
3233 ceph_early_kick_flushing_caps(mdsc, session); in send_mds_reconnect()
3239 mutex_lock(&mdsc->mutex); in send_mds_reconnect()
3240 __wake_requests(mdsc, &session->s_waiting); in send_mds_reconnect()
3241 mutex_unlock(&mdsc->mutex); in send_mds_reconnect()
3243 up_read(&mdsc->snap_rwsem); in send_mds_reconnect()
3248 up_read(&mdsc->snap_rwsem); in send_mds_reconnect()
3264 static void check_new_map(struct ceph_mds_client *mdsc, in check_new_map() argument
3275 for (i = 0; i < oldmap->m_num_mds && i < mdsc->max_sessions; i++) { in check_new_map()
3276 if (!mdsc->sessions[i]) in check_new_map()
3278 s = mdsc->sessions[i]; in check_new_map()
3297 __unregister_session(mdsc, s); in check_new_map()
3298 __wake_requests(mdsc, &s->s_waiting); in check_new_map()
3303 __unregister_session(mdsc, s); in check_new_map()
3304 __wake_requests(mdsc, &s->s_waiting); in check_new_map()
3305 kick_requests(mdsc, i); in check_new_map()
3306 mutex_unlock(&mdsc->mutex); in check_new_map()
3309 cleanup_session_requests(mdsc, s); in check_new_map()
3315 mutex_lock(&mdsc->mutex); in check_new_map()
3318 mutex_unlock(&mdsc->mutex); in check_new_map()
3320 mutex_lock(&mdsc->mutex); in check_new_map()
3334 mutex_unlock(&mdsc->mutex); in check_new_map()
3335 send_mds_reconnect(mdsc, s); in check_new_map()
3336 mutex_lock(&mdsc->mutex); in check_new_map()
3347 kick_requests(mdsc, i); in check_new_map()
3348 ceph_kick_flushing_caps(mdsc, s); in check_new_map()
3353 for (i = 0; i < newmap->m_num_mds && i < mdsc->max_sessions; i++) { in check_new_map()
3354 s = mdsc->sessions[i]; in check_new_map()
3364 __open_export_target_sessions(mdsc, s); in check_new_map()
3386 static void handle_lease(struct ceph_mds_client *mdsc, in handle_lease() argument
3390 struct super_block *sb = mdsc->fsc->sb; in handle_lease()
3530 static void lock_unlock_sessions(struct ceph_mds_client *mdsc) in lock_unlock_sessions() argument
3534 mutex_lock(&mdsc->mutex); in lock_unlock_sessions()
3535 for (i = 0; i < mdsc->max_sessions; i++) { in lock_unlock_sessions()
3536 struct ceph_mds_session *s = __ceph_lookup_mds_session(mdsc, i); in lock_unlock_sessions()
3539 mutex_unlock(&mdsc->mutex); in lock_unlock_sessions()
3543 mutex_lock(&mdsc->mutex); in lock_unlock_sessions()
3545 mutex_unlock(&mdsc->mutex); in lock_unlock_sessions()
3553 static void schedule_delayed(struct ceph_mds_client *mdsc) in schedule_delayed() argument
3557 schedule_delayed_work(&mdsc->delayed_work, hz); in schedule_delayed()
3563 struct ceph_mds_client *mdsc = in delayed_work() local
3569 ceph_check_delayed_caps(mdsc); in delayed_work()
3571 mutex_lock(&mdsc->mutex); in delayed_work()
3572 renew_interval = mdsc->mdsmap->m_session_timeout >> 2; in delayed_work()
3574 mdsc->last_renew_caps); in delayed_work()
3576 mdsc->last_renew_caps = jiffies; in delayed_work()
3578 for (i = 0; i < mdsc->max_sessions; i++) { in delayed_work()
3579 struct ceph_mds_session *s = __ceph_lookup_mds_session(mdsc, i); in delayed_work()
3585 request_close_session(mdsc, s); in delayed_work()
3600 mutex_unlock(&mdsc->mutex); in delayed_work()
3604 send_renew_caps(mdsc, s); in delayed_work()
3609 ceph_send_cap_releases(mdsc, s); in delayed_work()
3613 mutex_lock(&mdsc->mutex); in delayed_work()
3615 mutex_unlock(&mdsc->mutex); in delayed_work()
3617 schedule_delayed(mdsc); in delayed_work()
3623 struct ceph_mds_client *mdsc; in ceph_mdsc_init() local
3625 mdsc = kzalloc(sizeof(struct ceph_mds_client), GFP_NOFS); in ceph_mdsc_init()
3626 if (!mdsc) in ceph_mdsc_init()
3628 mdsc->fsc = fsc; in ceph_mdsc_init()
3629 mutex_init(&mdsc->mutex); in ceph_mdsc_init()
3630 mdsc->mdsmap = kzalloc(sizeof(*mdsc->mdsmap), GFP_NOFS); in ceph_mdsc_init()
3631 if (!mdsc->mdsmap) { in ceph_mdsc_init()
3632 kfree(mdsc); in ceph_mdsc_init()
3636 fsc->mdsc = mdsc; in ceph_mdsc_init()
3637 init_completion(&mdsc->safe_umount_waiters); in ceph_mdsc_init()
3638 init_waitqueue_head(&mdsc->session_close_wq); in ceph_mdsc_init()
3639 INIT_LIST_HEAD(&mdsc->waiting_for_map); in ceph_mdsc_init()
3640 mdsc->sessions = NULL; in ceph_mdsc_init()
3641 atomic_set(&mdsc->num_sessions, 0); in ceph_mdsc_init()
3642 mdsc->max_sessions = 0; in ceph_mdsc_init()
3643 mdsc->stopping = 0; in ceph_mdsc_init()
3644 atomic64_set(&mdsc->quotarealms_count, 0); in ceph_mdsc_init()
3645 mdsc->last_snap_seq = 0; in ceph_mdsc_init()
3646 init_rwsem(&mdsc->snap_rwsem); in ceph_mdsc_init()
3647 mdsc->snap_realms = RB_ROOT; in ceph_mdsc_init()
3648 INIT_LIST_HEAD(&mdsc->snap_empty); in ceph_mdsc_init()
3649 spin_lock_init(&mdsc->snap_empty_lock); in ceph_mdsc_init()
3650 mdsc->last_tid = 0; in ceph_mdsc_init()
3651 mdsc->oldest_tid = 0; in ceph_mdsc_init()
3652 mdsc->request_tree = RB_ROOT; in ceph_mdsc_init()
3653 INIT_DELAYED_WORK(&mdsc->delayed_work, delayed_work); in ceph_mdsc_init()
3654 mdsc->last_renew_caps = jiffies; in ceph_mdsc_init()
3655 INIT_LIST_HEAD(&mdsc->cap_delay_list); in ceph_mdsc_init()
3656 spin_lock_init(&mdsc->cap_delay_lock); in ceph_mdsc_init()
3657 INIT_LIST_HEAD(&mdsc->snap_flush_list); in ceph_mdsc_init()
3658 spin_lock_init(&mdsc->snap_flush_lock); in ceph_mdsc_init()
3659 mdsc->last_cap_flush_tid = 1; in ceph_mdsc_init()
3660 INIT_LIST_HEAD(&mdsc->cap_flush_list); in ceph_mdsc_init()
3661 INIT_LIST_HEAD(&mdsc->cap_dirty); in ceph_mdsc_init()
3662 INIT_LIST_HEAD(&mdsc->cap_dirty_migrating); in ceph_mdsc_init()
3663 mdsc->num_cap_flushing = 0; in ceph_mdsc_init()
3664 spin_lock_init(&mdsc->cap_dirty_lock); in ceph_mdsc_init()
3665 init_waitqueue_head(&mdsc->cap_flushing_wq); in ceph_mdsc_init()
3666 spin_lock_init(&mdsc->dentry_lru_lock); in ceph_mdsc_init()
3667 INIT_LIST_HEAD(&mdsc->dentry_lru); in ceph_mdsc_init()
3669 ceph_caps_init(mdsc); in ceph_mdsc_init()
3670 ceph_adjust_min_caps(mdsc, fsc->min_caps); in ceph_mdsc_init()
3672 init_rwsem(&mdsc->pool_perm_rwsem); in ceph_mdsc_init()
3673 mdsc->pool_perm_tree = RB_ROOT; in ceph_mdsc_init()
3675 strscpy(mdsc->nodename, utsname()->nodename, in ceph_mdsc_init()
3676 sizeof(mdsc->nodename)); in ceph_mdsc_init()
3684 static void wait_requests(struct ceph_mds_client *mdsc) in wait_requests() argument
3686 struct ceph_options *opts = mdsc->fsc->client->options; in wait_requests()
3689 mutex_lock(&mdsc->mutex); in wait_requests()
3690 if (__get_oldest_req(mdsc)) { in wait_requests()
3691 mutex_unlock(&mdsc->mutex); in wait_requests()
3694 wait_for_completion_timeout(&mdsc->safe_umount_waiters, in wait_requests()
3698 mutex_lock(&mdsc->mutex); in wait_requests()
3699 while ((req = __get_oldest_req(mdsc))) { in wait_requests()
3702 __unregister_request(mdsc, req); in wait_requests()
3705 mutex_unlock(&mdsc->mutex); in wait_requests()
3713 void ceph_mdsc_pre_umount(struct ceph_mds_client *mdsc) in ceph_mdsc_pre_umount() argument
3716 mdsc->stopping = 1; in ceph_mdsc_pre_umount()
3718 lock_unlock_sessions(mdsc); in ceph_mdsc_pre_umount()
3719 ceph_flush_dirty_caps(mdsc); in ceph_mdsc_pre_umount()
3720 wait_requests(mdsc); in ceph_mdsc_pre_umount()
3732 static void wait_unsafe_requests(struct ceph_mds_client *mdsc, u64 want_tid) in wait_unsafe_requests() argument
3737 mutex_lock(&mdsc->mutex); in wait_unsafe_requests()
3740 req = __get_oldest_req(mdsc); in wait_unsafe_requests()
3754 mutex_unlock(&mdsc->mutex); in wait_unsafe_requests()
3758 mutex_lock(&mdsc->mutex); in wait_unsafe_requests()
3771 mutex_unlock(&mdsc->mutex); in wait_unsafe_requests()
3775 void ceph_mdsc_sync(struct ceph_mds_client *mdsc) in ceph_mdsc_sync() argument
3779 if (READ_ONCE(mdsc->fsc->mount_state) == CEPH_MOUNT_SHUTDOWN) in ceph_mdsc_sync()
3783 mutex_lock(&mdsc->mutex); in ceph_mdsc_sync()
3784 want_tid = mdsc->last_tid; in ceph_mdsc_sync()
3785 mutex_unlock(&mdsc->mutex); in ceph_mdsc_sync()
3787 ceph_flush_dirty_caps(mdsc); in ceph_mdsc_sync()
3788 spin_lock(&mdsc->cap_dirty_lock); in ceph_mdsc_sync()
3789 want_flush = mdsc->last_cap_flush_tid; in ceph_mdsc_sync()
3790 if (!list_empty(&mdsc->cap_flush_list)) { in ceph_mdsc_sync()
3792 list_last_entry(&mdsc->cap_flush_list, in ceph_mdsc_sync()
3796 spin_unlock(&mdsc->cap_dirty_lock); in ceph_mdsc_sync()
3801 wait_unsafe_requests(mdsc, want_tid); in ceph_mdsc_sync()
3802 wait_caps_flush(mdsc, want_flush); in ceph_mdsc_sync()
3808 static bool done_closing_sessions(struct ceph_mds_client *mdsc, int skipped) in done_closing_sessions() argument
3810 if (READ_ONCE(mdsc->fsc->mount_state) == CEPH_MOUNT_SHUTDOWN) in done_closing_sessions()
3812 return atomic_read(&mdsc->num_sessions) <= skipped; in done_closing_sessions()
3818 void ceph_mdsc_close_sessions(struct ceph_mds_client *mdsc) in ceph_mdsc_close_sessions() argument
3820 struct ceph_options *opts = mdsc->fsc->client->options; in ceph_mdsc_close_sessions()
3828 mutex_lock(&mdsc->mutex); in ceph_mdsc_close_sessions()
3829 for (i = 0; i < mdsc->max_sessions; i++) { in ceph_mdsc_close_sessions()
3830 session = __ceph_lookup_mds_session(mdsc, i); in ceph_mdsc_close_sessions()
3833 mutex_unlock(&mdsc->mutex); in ceph_mdsc_close_sessions()
3835 if (__close_session(mdsc, session) <= 0) in ceph_mdsc_close_sessions()
3839 mutex_lock(&mdsc->mutex); in ceph_mdsc_close_sessions()
3841 mutex_unlock(&mdsc->mutex); in ceph_mdsc_close_sessions()
3844 wait_event_timeout(mdsc->session_close_wq, in ceph_mdsc_close_sessions()
3845 done_closing_sessions(mdsc, skipped), in ceph_mdsc_close_sessions()
3849 mutex_lock(&mdsc->mutex); in ceph_mdsc_close_sessions()
3850 for (i = 0; i < mdsc->max_sessions; i++) { in ceph_mdsc_close_sessions()
3851 if (mdsc->sessions[i]) { in ceph_mdsc_close_sessions()
3852 session = get_session(mdsc->sessions[i]); in ceph_mdsc_close_sessions()
3853 __unregister_session(mdsc, session); in ceph_mdsc_close_sessions()
3854 mutex_unlock(&mdsc->mutex); in ceph_mdsc_close_sessions()
3859 mutex_lock(&mdsc->mutex); in ceph_mdsc_close_sessions()
3862 WARN_ON(!list_empty(&mdsc->cap_delay_list)); in ceph_mdsc_close_sessions()
3863 mutex_unlock(&mdsc->mutex); in ceph_mdsc_close_sessions()
3865 ceph_cleanup_empty_realms(mdsc); in ceph_mdsc_close_sessions()
3867 cancel_delayed_work_sync(&mdsc->delayed_work); /* cancel timer */ in ceph_mdsc_close_sessions()
3872 void ceph_mdsc_force_umount(struct ceph_mds_client *mdsc) in ceph_mdsc_force_umount() argument
3879 mutex_lock(&mdsc->mutex); in ceph_mdsc_force_umount()
3880 for (mds = 0; mds < mdsc->max_sessions; mds++) { in ceph_mdsc_force_umount()
3881 session = __ceph_lookup_mds_session(mdsc, mds); in ceph_mdsc_force_umount()
3884 mutex_unlock(&mdsc->mutex); in ceph_mdsc_force_umount()
3886 __close_session(mdsc, session); in ceph_mdsc_force_umount()
3888 cleanup_session_requests(mdsc, session); in ceph_mdsc_force_umount()
3893 mutex_lock(&mdsc->mutex); in ceph_mdsc_force_umount()
3894 kick_requests(mdsc, mds); in ceph_mdsc_force_umount()
3896 __wake_requests(mdsc, &mdsc->waiting_for_map); in ceph_mdsc_force_umount()
3897 mutex_unlock(&mdsc->mutex); in ceph_mdsc_force_umount()
3900 static void ceph_mdsc_stop(struct ceph_mds_client *mdsc) in ceph_mdsc_stop() argument
3903 cancel_delayed_work_sync(&mdsc->delayed_work); /* cancel timer */ in ceph_mdsc_stop()
3904 if (mdsc->mdsmap) in ceph_mdsc_stop()
3905 ceph_mdsmap_destroy(mdsc->mdsmap); in ceph_mdsc_stop()
3906 kfree(mdsc->sessions); in ceph_mdsc_stop()
3907 ceph_caps_finalize(mdsc); in ceph_mdsc_stop()
3908 ceph_pool_perm_destroy(mdsc); in ceph_mdsc_stop()
3913 struct ceph_mds_client *mdsc = fsc->mdsc; in ceph_mdsc_destroy() local
3914 dout("mdsc_destroy %p\n", mdsc); in ceph_mdsc_destroy()
3916 if (!mdsc) in ceph_mdsc_destroy()
3922 ceph_mdsc_stop(mdsc); in ceph_mdsc_destroy()
3924 fsc->mdsc = NULL; in ceph_mdsc_destroy()
3925 kfree(mdsc); in ceph_mdsc_destroy()
3926 dout("mdsc_destroy %p done\n", mdsc); in ceph_mdsc_destroy()
3929 void ceph_mdsc_handle_fsmap(struct ceph_mds_client *mdsc, struct ceph_msg *msg) in ceph_mdsc_handle_fsmap() argument
3931 struct ceph_fs_client *fsc = mdsc->fsc; in ceph_mdsc_handle_fsmap()
3999 mutex_lock(&mdsc->mutex); in ceph_mdsc_handle_fsmap()
4000 mdsc->mdsmap_err = err; in ceph_mdsc_handle_fsmap()
4001 __wake_requests(mdsc, &mdsc->waiting_for_map); in ceph_mdsc_handle_fsmap()
4002 mutex_unlock(&mdsc->mutex); in ceph_mdsc_handle_fsmap()
4008 void ceph_mdsc_handle_mdsmap(struct ceph_mds_client *mdsc, struct ceph_msg *msg) in ceph_mdsc_handle_mdsmap() argument
4020 if (ceph_check_fsid(mdsc->fsc->client, &fsid) < 0) in ceph_mdsc_handle_mdsmap()
4027 mutex_lock(&mdsc->mutex); in ceph_mdsc_handle_mdsmap()
4028 if (mdsc->mdsmap && epoch <= mdsc->mdsmap->m_epoch) { in ceph_mdsc_handle_mdsmap()
4030 epoch, mdsc->mdsmap->m_epoch); in ceph_mdsc_handle_mdsmap()
4031 mutex_unlock(&mdsc->mutex); in ceph_mdsc_handle_mdsmap()
4042 if (mdsc->mdsmap) { in ceph_mdsc_handle_mdsmap()
4043 oldmap = mdsc->mdsmap; in ceph_mdsc_handle_mdsmap()
4044 mdsc->mdsmap = newmap; in ceph_mdsc_handle_mdsmap()
4045 check_new_map(mdsc, newmap, oldmap); in ceph_mdsc_handle_mdsmap()
4048 mdsc->mdsmap = newmap; /* first mds map */ in ceph_mdsc_handle_mdsmap()
4050 mdsc->fsc->max_file_size = min((loff_t)mdsc->mdsmap->m_max_file_size, in ceph_mdsc_handle_mdsmap()
4053 __wake_requests(mdsc, &mdsc->waiting_for_map); in ceph_mdsc_handle_mdsmap()
4054 ceph_monc_got_map(&mdsc->fsc->client->monc, CEPH_SUB_MDSMAP, in ceph_mdsc_handle_mdsmap()
4055 mdsc->mdsmap->m_epoch); in ceph_mdsc_handle_mdsmap()
4057 mutex_unlock(&mdsc->mutex); in ceph_mdsc_handle_mdsmap()
4058 schedule_delayed(mdsc); in ceph_mdsc_handle_mdsmap()
4062 mutex_unlock(&mdsc->mutex); in ceph_mdsc_handle_mdsmap()
4095 struct ceph_mds_client *mdsc = s->s_mdsc; in peer_reset() local
4098 send_mds_reconnect(mdsc, s); in peer_reset()
4104 struct ceph_mds_client *mdsc = s->s_mdsc; in dispatch() local
4107 mutex_lock(&mdsc->mutex); in dispatch()
4108 if (__verify_registered_session(mdsc, s) < 0) { in dispatch()
4109 mutex_unlock(&mdsc->mutex); in dispatch()
4112 mutex_unlock(&mdsc->mutex); in dispatch()
4116 ceph_mdsc_handle_mdsmap(mdsc, msg); in dispatch()
4119 ceph_mdsc_handle_fsmap(mdsc, msg); in dispatch()
4128 handle_forward(mdsc, s, msg); in dispatch()
4134 ceph_handle_snap(mdsc, s, msg); in dispatch()
4137 handle_lease(mdsc, s, msg); in dispatch()
4140 ceph_handle_quota(mdsc, s, msg); in dispatch()
4163 struct ceph_mds_client *mdsc = s->s_mdsc; in get_authorizer() local
4164 struct ceph_auth_client *ac = mdsc->fsc->client->monc.auth; in get_authorizer()
4191 struct ceph_mds_client *mdsc = s->s_mdsc; in add_authorizer_challenge() local
4192 struct ceph_auth_client *ac = mdsc->fsc->client->monc.auth; in add_authorizer_challenge()
4201 struct ceph_mds_client *mdsc = s->s_mdsc; in verify_authorizer_reply() local
4202 struct ceph_auth_client *ac = mdsc->fsc->client->monc.auth; in verify_authorizer_reply()
4210 struct ceph_mds_client *mdsc = s->s_mdsc; in invalidate_authorizer() local
4211 struct ceph_auth_client *ac = mdsc->fsc->client->monc.auth; in invalidate_authorizer()
4215 return ceph_monc_validate_auth(&mdsc->fsc->client->monc); in invalidate_authorizer()