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()
1332 wake_up_all(&fsc->mdsc->cap_flushing_wq); in remove_session_caps()
1406 static int send_renew_caps(struct ceph_mds_client *mdsc, in send_renew_caps() argument
1419 state = ceph_mdsmap_get_state(mdsc->mdsmap, session->s_mds); in send_renew_caps()
1436 static int send_flushmsg_ack(struct ceph_mds_client *mdsc, in send_flushmsg_ack() argument
1456 static void renewed_caps(struct ceph_mds_client *mdsc, in renewed_caps() argument
1466 mdsc->mdsmap->m_session_timeout*HZ; in renewed_caps()
1488 static int request_close_session(struct ceph_mds_client *mdsc, in request_close_session() argument
1506 static int __close_session(struct ceph_mds_client *mdsc, in __close_session() argument
1512 return request_close_session(mdsc, session); in __close_session()
1620 int ceph_trim_caps(struct ceph_mds_client *mdsc, in ceph_trim_caps() argument
1637 ceph_send_cap_releases(mdsc, session); in ceph_trim_caps()
1641 static int check_caps_flush(struct ceph_mds_client *mdsc, in check_caps_flush() argument
1646 spin_lock(&mdsc->cap_dirty_lock); in check_caps_flush()
1647 if (!list_empty(&mdsc->cap_flush_list)) { in check_caps_flush()
1649 list_first_entry(&mdsc->cap_flush_list, in check_caps_flush()
1657 spin_unlock(&mdsc->cap_dirty_lock); in check_caps_flush()
1666 static void wait_caps_flush(struct ceph_mds_client *mdsc, in wait_caps_flush() argument
1671 wait_event(mdsc->cap_flushing_wq, in wait_caps_flush()
1672 check_caps_flush(mdsc, want_flush_tid)); in wait_caps_flush()
1680 void ceph_send_cap_releases(struct ceph_mds_client *mdsc, in ceph_send_cap_releases() argument
1686 struct ceph_osd_client *osdc = &mdsc->fsc->client->osdc; in ceph_send_cap_releases()
1731 ceph_put_cap(mdsc, cap); in ceph_send_cap_releases()
1818 ceph_mdsc_create_request(struct ceph_mds_client *mdsc, int op, int mode) in ceph_mdsc_create_request() argument
1827 req->r_mdsc = mdsc; in ceph_mdsc_create_request()
1841 req->r_stamp = timespec64_trunc(ts, mdsc->fsc->sb->s_time_gran); in ceph_mdsc_create_request()
1853 static struct ceph_mds_request *__get_oldest_req(struct ceph_mds_client *mdsc) in __get_oldest_req() argument
1855 if (RB_EMPTY_ROOT(&mdsc->request_tree)) in __get_oldest_req()
1857 return rb_entry(rb_first(&mdsc->request_tree), in __get_oldest_req()
1861 static inline u64 __get_oldest_tid(struct ceph_mds_client *mdsc) in __get_oldest_tid() argument
1863 return mdsc->oldest_tid; in __get_oldest_tid()
2073 static struct ceph_msg *create_request_message(struct ceph_mds_client *mdsc, in create_request_message() argument
2135 head->mdsmap_epoch = cpu_to_le32(mdsc->mdsmap->m_epoch); in create_request_message()
2210 static void complete_request(struct ceph_mds_client *mdsc, in complete_request() argument
2214 req->r_callback(mdsc, req); in complete_request()
2222 static int __prepare_send_request(struct ceph_mds_client *mdsc, in __prepare_send_request() argument
2283 msg = create_request_message(mdsc, req, mds, drop_cap_releases); in __prepare_send_request()
2291 rhead->oldest_client_tid = cpu_to_le64(__get_oldest_tid(mdsc)); in __prepare_send_request()
2308 static void __do_request(struct ceph_mds_client *mdsc, in __do_request() argument
2317 __unregister_request(mdsc, req); in __do_request()
2327 if (READ_ONCE(mdsc->fsc->mount_state) == CEPH_MOUNT_SHUTDOWN) { in __do_request()
2332 if (READ_ONCE(mdsc->fsc->mount_state) == CEPH_MOUNT_MOUNTING) { in __do_request()
2333 if (mdsc->mdsmap_err) { in __do_request()
2334 err = mdsc->mdsmap_err; in __do_request()
2338 if (mdsc->mdsmap->m_epoch == 0) { in __do_request()
2340 list_add(&req->r_wait, &mdsc->waiting_for_map); in __do_request()
2343 if (!(mdsc->fsc->mount_options->flags & in __do_request()
2345 !ceph_mdsmap_is_cluster_available(mdsc->mdsmap)) { in __do_request()
2353 mds = __choose_mds(mdsc, req); in __do_request()
2355 ceph_mdsmap_get_state(mdsc->mdsmap, mds) < CEPH_MDS_STATE_ACTIVE) { in __do_request()
2357 list_add(&req->r_wait, &mdsc->waiting_for_map); in __do_request()
2362 session = __ceph_lookup_mds_session(mdsc, mds); in __do_request()
2364 session = register_session(mdsc, mds); in __do_request()
2382 __open_session(mdsc, session); in __do_request()
2393 err = __prepare_send_request(mdsc, req, mds, false); in __do_request()
2405 complete_request(mdsc, req); in __do_request()
2406 __unregister_request(mdsc, req); in __do_request()
2414 static void __wake_requests(struct ceph_mds_client *mdsc, in __wake_requests() argument
2427 __do_request(mdsc, req); in __wake_requests()
2435 static void kick_requests(struct ceph_mds_client *mdsc, int mds) in kick_requests() argument
2438 struct rb_node *p = rb_first(&mdsc->request_tree); in kick_requests()
2452 __do_request(mdsc, req); in kick_requests()
2457 void ceph_mdsc_submit_request(struct ceph_mds_client *mdsc, in ceph_mdsc_submit_request() argument
2461 mutex_lock(&mdsc->mutex); in ceph_mdsc_submit_request()
2462 __register_request(mdsc, req, NULL); in ceph_mdsc_submit_request()
2463 __do_request(mdsc, req); in ceph_mdsc_submit_request()
2464 mutex_unlock(&mdsc->mutex); in ceph_mdsc_submit_request()
2471 int ceph_mdsc_do_request(struct ceph_mds_client *mdsc, in ceph_mdsc_do_request() argument
2489 mutex_lock(&mdsc->mutex); in ceph_mdsc_do_request()
2490 __register_request(mdsc, req, dir); in ceph_mdsc_do_request()
2491 __do_request(mdsc, req); in ceph_mdsc_do_request()
2499 mutex_unlock(&mdsc->mutex); in ceph_mdsc_do_request()
2502 err = req->r_wait_for_completion(mdsc, req); in ceph_mdsc_do_request()
2515 mutex_lock(&mdsc->mutex); in ceph_mdsc_do_request()
2541 mutex_unlock(&mdsc->mutex); in ceph_mdsc_do_request()
2575 struct ceph_mds_client *mdsc = session->s_mdsc; in handle_reply() local
2592 mutex_lock(&mdsc->mutex); in handle_reply()
2593 req = lookup_get_request(mdsc, tid); in handle_reply()
2596 mutex_unlock(&mdsc->mutex); in handle_reply()
2606 mutex_unlock(&mdsc->mutex); in handle_reply()
2615 mutex_unlock(&mdsc->mutex); in handle_reply()
2621 mutex_unlock(&mdsc->mutex); in handle_reply()
2640 __do_request(mdsc, req); in handle_reply()
2641 mutex_unlock(&mdsc->mutex); in handle_reply()
2644 int mds = __choose_mds(mdsc, req); in handle_reply()
2647 __do_request(mdsc, req); in handle_reply()
2648 mutex_unlock(&mdsc->mutex); in handle_reply()
2658 __unregister_request(mdsc, req); in handle_reply()
2671 if (mdsc->stopping && !__get_oldest_req(mdsc)) in handle_reply()
2672 complete_all(&mdsc->safe_umount_waiters); in handle_reply()
2673 mutex_unlock(&mdsc->mutex); in handle_reply()
2692 mutex_unlock(&mdsc->mutex); in handle_reply()
2704 down_write(&mdsc->snap_rwsem); in handle_reply()
2705 ceph_update_snap_trace(mdsc, rinfo->snapblob, in handle_reply()
2709 downgrade_write(&mdsc->snap_rwsem); in handle_reply()
2711 down_read(&mdsc->snap_rwsem); in handle_reply()
2717 err = ceph_fill_trace(mdsc->fsc->sb, req); in handle_reply()
2722 ceph_unreserve_caps(mdsc, &req->r_caps_reservation); in handle_reply()
2727 up_read(&mdsc->snap_rwsem); in handle_reply()
2729 ceph_put_snap_realm(mdsc, realm); in handle_reply()
2739 mutex_lock(&mdsc->mutex); in handle_reply()
2750 mutex_unlock(&mdsc->mutex); in handle_reply()
2755 complete_request(mdsc, req); in handle_reply()
2766 static void handle_forward(struct ceph_mds_client *mdsc, in handle_forward() argument
2782 mutex_lock(&mdsc->mutex); in handle_forward()
2783 req = lookup_get_request(mdsc, tid); in handle_forward()
2791 __unregister_request(mdsc, req); in handle_forward()
2804 __do_request(mdsc, req); in handle_forward()
2808 mutex_unlock(&mdsc->mutex); in handle_forward()
2821 struct ceph_mds_client *mdsc = session->s_mdsc; in handle_session() local
2834 mutex_lock(&mdsc->mutex); in handle_session()
2837 __unregister_session(mdsc, session); in handle_session()
2840 session->s_ttl = jiffies + HZ*mdsc->mdsmap->m_session_autoclose; in handle_session()
2841 mutex_unlock(&mdsc->mutex); in handle_session()
2859 renewed_caps(mdsc, session, 0); in handle_session()
2861 if (mdsc->stopping) in handle_session()
2862 __close_session(mdsc, session); in handle_session()
2867 renewed_caps(mdsc, session, 1); in handle_session()
2873 cleanup_session_requests(mdsc, session); in handle_session()
2876 wake_up_all(&mdsc->session_close_wq); in handle_session()
2886 send_renew_caps(mdsc, session); in handle_session()
2890 ceph_trim_caps(mdsc, session, le32_to_cpu(h->max_caps)); in handle_session()
2894 send_flushmsg_ack(mdsc, session, seq); in handle_session()
2909 cleanup_session_requests(mdsc, session); in handle_session()
2921 mutex_lock(&mdsc->mutex); in handle_session()
2922 __wake_requests(mdsc, &session->s_waiting); in handle_session()
2924 kick_requests(mdsc, mds); in handle_session()
2925 mutex_unlock(&mdsc->mutex); in handle_session()
2942 static void replay_unsafe_requests(struct ceph_mds_client *mdsc, in replay_unsafe_requests() argument
2951 mutex_lock(&mdsc->mutex); in replay_unsafe_requests()
2953 err = __prepare_send_request(mdsc, req, session->s_mds, true); in replay_unsafe_requests()
2964 p = rb_first(&mdsc->request_tree); in replay_unsafe_requests()
2974 err = __prepare_send_request(mdsc, req, in replay_unsafe_requests()
2982 mutex_unlock(&mdsc->mutex); in replay_unsafe_requests()
3162 static void send_mds_reconnect(struct ceph_mds_client *mdsc, in send_mds_reconnect() argument
3208 dispose_cap_releases(mdsc, &dispose); in send_mds_reconnect()
3211 if (mdsc->fsc->sb->s_root) in send_mds_reconnect()
3212 shrink_dcache_parent(mdsc->fsc->sb->s_root); in send_mds_reconnect()
3217 ceph_mdsmap_get_addr(mdsc->mdsmap, mds)); in send_mds_reconnect()
3220 replay_unsafe_requests(mdsc, session); in send_mds_reconnect()
3222 down_read(&mdsc->snap_rwsem); in send_mds_reconnect()
3251 for (p = rb_first(&mdsc->snap_realms); p; p = rb_next(p)) { in send_mds_reconnect()
3280 ceph_early_kick_flushing_caps(mdsc, session); in send_mds_reconnect()
3286 mutex_lock(&mdsc->mutex); in send_mds_reconnect()
3287 __wake_requests(mdsc, &session->s_waiting); in send_mds_reconnect()
3288 mutex_unlock(&mdsc->mutex); in send_mds_reconnect()
3290 up_read(&mdsc->snap_rwsem); in send_mds_reconnect()
3295 up_read(&mdsc->snap_rwsem); in send_mds_reconnect()
3311 static void check_new_map(struct ceph_mds_client *mdsc, in check_new_map() argument
3322 for (i = 0; i < oldmap->m_num_mds && i < mdsc->max_sessions; i++) { in check_new_map()
3323 if (!mdsc->sessions[i]) in check_new_map()
3325 s = mdsc->sessions[i]; in check_new_map()
3344 __unregister_session(mdsc, s); in check_new_map()
3345 __wake_requests(mdsc, &s->s_waiting); in check_new_map()
3350 __unregister_session(mdsc, s); in check_new_map()
3351 __wake_requests(mdsc, &s->s_waiting); in check_new_map()
3352 kick_requests(mdsc, i); in check_new_map()
3353 mutex_unlock(&mdsc->mutex); in check_new_map()
3356 cleanup_session_requests(mdsc, s); in check_new_map()
3362 mutex_lock(&mdsc->mutex); in check_new_map()
3365 mutex_unlock(&mdsc->mutex); in check_new_map()
3367 mutex_lock(&mdsc->mutex); in check_new_map()
3381 mutex_unlock(&mdsc->mutex); in check_new_map()
3382 send_mds_reconnect(mdsc, s); in check_new_map()
3383 mutex_lock(&mdsc->mutex); in check_new_map()
3394 kick_requests(mdsc, i); in check_new_map()
3395 ceph_kick_flushing_caps(mdsc, s); in check_new_map()
3400 for (i = 0; i < newmap->m_num_mds && i < mdsc->max_sessions; i++) { in check_new_map()
3401 s = mdsc->sessions[i]; in check_new_map()
3411 __open_export_target_sessions(mdsc, s); in check_new_map()
3433 static void handle_lease(struct ceph_mds_client *mdsc, in handle_lease() argument
3437 struct super_block *sb = mdsc->fsc->sb; in handle_lease()
3577 static void lock_unlock_sessions(struct ceph_mds_client *mdsc) in lock_unlock_sessions() argument
3581 mutex_lock(&mdsc->mutex); in lock_unlock_sessions()
3582 for (i = 0; i < mdsc->max_sessions; i++) { in lock_unlock_sessions()
3583 struct ceph_mds_session *s = __ceph_lookup_mds_session(mdsc, i); in lock_unlock_sessions()
3586 mutex_unlock(&mdsc->mutex); in lock_unlock_sessions()
3590 mutex_lock(&mdsc->mutex); in lock_unlock_sessions()
3592 mutex_unlock(&mdsc->mutex); in lock_unlock_sessions()
3600 static void schedule_delayed(struct ceph_mds_client *mdsc) in schedule_delayed() argument
3604 schedule_delayed_work(&mdsc->delayed_work, hz); in schedule_delayed()
3610 struct ceph_mds_client *mdsc = in delayed_work() local
3616 ceph_check_delayed_caps(mdsc); in delayed_work()
3618 if (mdsc->stopping) in delayed_work()
3621 mutex_lock(&mdsc->mutex); in delayed_work()
3622 renew_interval = mdsc->mdsmap->m_session_timeout >> 2; in delayed_work()
3624 mdsc->last_renew_caps); in delayed_work()
3626 mdsc->last_renew_caps = jiffies; in delayed_work()
3628 for (i = 0; i < mdsc->max_sessions; i++) { in delayed_work()
3629 struct ceph_mds_session *s = __ceph_lookup_mds_session(mdsc, i); in delayed_work()
3635 request_close_session(mdsc, s); in delayed_work()
3652 mutex_unlock(&mdsc->mutex); in delayed_work()
3656 send_renew_caps(mdsc, s); in delayed_work()
3661 ceph_send_cap_releases(mdsc, s); in delayed_work()
3665 mutex_lock(&mdsc->mutex); in delayed_work()
3667 mutex_unlock(&mdsc->mutex); in delayed_work()
3669 schedule_delayed(mdsc); in delayed_work()
3675 struct ceph_mds_client *mdsc; in ceph_mdsc_init() local
3677 mdsc = kzalloc(sizeof(struct ceph_mds_client), GFP_NOFS); in ceph_mdsc_init()
3678 if (!mdsc) in ceph_mdsc_init()
3680 mdsc->fsc = fsc; in ceph_mdsc_init()
3681 mutex_init(&mdsc->mutex); in ceph_mdsc_init()
3682 mdsc->mdsmap = kzalloc(sizeof(*mdsc->mdsmap), GFP_NOFS); in ceph_mdsc_init()
3683 if (!mdsc->mdsmap) { in ceph_mdsc_init()
3684 kfree(mdsc); in ceph_mdsc_init()
3688 init_completion(&mdsc->safe_umount_waiters); in ceph_mdsc_init()
3689 init_waitqueue_head(&mdsc->session_close_wq); in ceph_mdsc_init()
3690 INIT_LIST_HEAD(&mdsc->waiting_for_map); in ceph_mdsc_init()
3691 mdsc->sessions = NULL; in ceph_mdsc_init()
3692 atomic_set(&mdsc->num_sessions, 0); in ceph_mdsc_init()
3693 mdsc->max_sessions = 0; in ceph_mdsc_init()
3694 mdsc->stopping = 0; in ceph_mdsc_init()
3695 atomic64_set(&mdsc->quotarealms_count, 0); in ceph_mdsc_init()
3696 mdsc->last_snap_seq = 0; in ceph_mdsc_init()
3697 init_rwsem(&mdsc->snap_rwsem); in ceph_mdsc_init()
3698 mdsc->snap_realms = RB_ROOT; in ceph_mdsc_init()
3699 INIT_LIST_HEAD(&mdsc->snap_empty); in ceph_mdsc_init()
3700 spin_lock_init(&mdsc->snap_empty_lock); in ceph_mdsc_init()
3701 mdsc->last_tid = 0; in ceph_mdsc_init()
3702 mdsc->oldest_tid = 0; in ceph_mdsc_init()
3703 mdsc->request_tree = RB_ROOT; in ceph_mdsc_init()
3704 INIT_DELAYED_WORK(&mdsc->delayed_work, delayed_work); in ceph_mdsc_init()
3705 mdsc->last_renew_caps = jiffies; in ceph_mdsc_init()
3706 INIT_LIST_HEAD(&mdsc->cap_delay_list); in ceph_mdsc_init()
3707 spin_lock_init(&mdsc->cap_delay_lock); in ceph_mdsc_init()
3708 INIT_LIST_HEAD(&mdsc->snap_flush_list); in ceph_mdsc_init()
3709 spin_lock_init(&mdsc->snap_flush_lock); in ceph_mdsc_init()
3710 mdsc->last_cap_flush_tid = 1; in ceph_mdsc_init()
3711 INIT_LIST_HEAD(&mdsc->cap_flush_list); in ceph_mdsc_init()
3712 INIT_LIST_HEAD(&mdsc->cap_dirty); in ceph_mdsc_init()
3713 INIT_LIST_HEAD(&mdsc->cap_dirty_migrating); in ceph_mdsc_init()
3714 mdsc->num_cap_flushing = 0; in ceph_mdsc_init()
3715 spin_lock_init(&mdsc->cap_dirty_lock); in ceph_mdsc_init()
3716 init_waitqueue_head(&mdsc->cap_flushing_wq); in ceph_mdsc_init()
3717 spin_lock_init(&mdsc->dentry_lru_lock); in ceph_mdsc_init()
3718 INIT_LIST_HEAD(&mdsc->dentry_lru); in ceph_mdsc_init()
3720 ceph_caps_init(mdsc); in ceph_mdsc_init()
3721 ceph_adjust_min_caps(mdsc, fsc->min_caps); in ceph_mdsc_init()
3723 init_rwsem(&mdsc->pool_perm_rwsem); in ceph_mdsc_init()
3724 mdsc->pool_perm_tree = RB_ROOT; in ceph_mdsc_init()
3726 strscpy(mdsc->nodename, utsname()->nodename, in ceph_mdsc_init()
3727 sizeof(mdsc->nodename)); in ceph_mdsc_init()
3729 fsc->mdsc = mdsc; in ceph_mdsc_init()
3737 static void wait_requests(struct ceph_mds_client *mdsc) in wait_requests() argument
3739 struct ceph_options *opts = mdsc->fsc->client->options; in wait_requests()
3742 mutex_lock(&mdsc->mutex); in wait_requests()
3743 if (__get_oldest_req(mdsc)) { in wait_requests()
3744 mutex_unlock(&mdsc->mutex); in wait_requests()
3747 wait_for_completion_timeout(&mdsc->safe_umount_waiters, in wait_requests()
3751 mutex_lock(&mdsc->mutex); in wait_requests()
3752 while ((req = __get_oldest_req(mdsc))) { in wait_requests()
3755 __unregister_request(mdsc, req); in wait_requests()
3758 mutex_unlock(&mdsc->mutex); in wait_requests()
3766 void ceph_mdsc_pre_umount(struct ceph_mds_client *mdsc) in ceph_mdsc_pre_umount() argument
3769 mdsc->stopping = 1; in ceph_mdsc_pre_umount()
3771 lock_unlock_sessions(mdsc); in ceph_mdsc_pre_umount()
3772 ceph_flush_dirty_caps(mdsc); in ceph_mdsc_pre_umount()
3773 wait_requests(mdsc); in ceph_mdsc_pre_umount()
3785 static void wait_unsafe_requests(struct ceph_mds_client *mdsc, u64 want_tid) in wait_unsafe_requests() argument
3790 mutex_lock(&mdsc->mutex); in wait_unsafe_requests()
3793 req = __get_oldest_req(mdsc); in wait_unsafe_requests()
3807 mutex_unlock(&mdsc->mutex); in wait_unsafe_requests()
3811 mutex_lock(&mdsc->mutex); in wait_unsafe_requests()
3824 mutex_unlock(&mdsc->mutex); in wait_unsafe_requests()
3828 void ceph_mdsc_sync(struct ceph_mds_client *mdsc) in ceph_mdsc_sync() argument
3832 if (READ_ONCE(mdsc->fsc->mount_state) == CEPH_MOUNT_SHUTDOWN) in ceph_mdsc_sync()
3836 mutex_lock(&mdsc->mutex); in ceph_mdsc_sync()
3837 want_tid = mdsc->last_tid; in ceph_mdsc_sync()
3838 mutex_unlock(&mdsc->mutex); in ceph_mdsc_sync()
3840 ceph_flush_dirty_caps(mdsc); in ceph_mdsc_sync()
3841 spin_lock(&mdsc->cap_dirty_lock); in ceph_mdsc_sync()
3842 want_flush = mdsc->last_cap_flush_tid; in ceph_mdsc_sync()
3843 if (!list_empty(&mdsc->cap_flush_list)) { in ceph_mdsc_sync()
3845 list_last_entry(&mdsc->cap_flush_list, in ceph_mdsc_sync()
3849 spin_unlock(&mdsc->cap_dirty_lock); in ceph_mdsc_sync()
3854 wait_unsafe_requests(mdsc, want_tid); in ceph_mdsc_sync()
3855 wait_caps_flush(mdsc, want_flush); in ceph_mdsc_sync()
3861 static bool done_closing_sessions(struct ceph_mds_client *mdsc, int skipped) in done_closing_sessions() argument
3863 if (READ_ONCE(mdsc->fsc->mount_state) == CEPH_MOUNT_SHUTDOWN) in done_closing_sessions()
3865 return atomic_read(&mdsc->num_sessions) <= skipped; in done_closing_sessions()
3871 void ceph_mdsc_close_sessions(struct ceph_mds_client *mdsc) in ceph_mdsc_close_sessions() argument
3873 struct ceph_options *opts = mdsc->fsc->client->options; in ceph_mdsc_close_sessions()
3881 mutex_lock(&mdsc->mutex); in ceph_mdsc_close_sessions()
3882 for (i = 0; i < mdsc->max_sessions; i++) { in ceph_mdsc_close_sessions()
3883 session = __ceph_lookup_mds_session(mdsc, i); in ceph_mdsc_close_sessions()
3886 mutex_unlock(&mdsc->mutex); in ceph_mdsc_close_sessions()
3888 if (__close_session(mdsc, session) <= 0) in ceph_mdsc_close_sessions()
3892 mutex_lock(&mdsc->mutex); in ceph_mdsc_close_sessions()
3894 mutex_unlock(&mdsc->mutex); in ceph_mdsc_close_sessions()
3897 wait_event_timeout(mdsc->session_close_wq, in ceph_mdsc_close_sessions()
3898 done_closing_sessions(mdsc, skipped), in ceph_mdsc_close_sessions()
3902 mutex_lock(&mdsc->mutex); in ceph_mdsc_close_sessions()
3903 for (i = 0; i < mdsc->max_sessions; i++) { in ceph_mdsc_close_sessions()
3904 if (mdsc->sessions[i]) { in ceph_mdsc_close_sessions()
3905 session = get_session(mdsc->sessions[i]); in ceph_mdsc_close_sessions()
3906 __unregister_session(mdsc, session); in ceph_mdsc_close_sessions()
3907 mutex_unlock(&mdsc->mutex); in ceph_mdsc_close_sessions()
3912 mutex_lock(&mdsc->mutex); in ceph_mdsc_close_sessions()
3915 WARN_ON(!list_empty(&mdsc->cap_delay_list)); in ceph_mdsc_close_sessions()
3916 mutex_unlock(&mdsc->mutex); in ceph_mdsc_close_sessions()
3918 ceph_cleanup_empty_realms(mdsc); in ceph_mdsc_close_sessions()
3920 cancel_delayed_work_sync(&mdsc->delayed_work); /* cancel timer */ in ceph_mdsc_close_sessions()
3925 void ceph_mdsc_force_umount(struct ceph_mds_client *mdsc) in ceph_mdsc_force_umount() argument
3932 mutex_lock(&mdsc->mutex); in ceph_mdsc_force_umount()
3933 for (mds = 0; mds < mdsc->max_sessions; mds++) { in ceph_mdsc_force_umount()
3934 session = __ceph_lookup_mds_session(mdsc, mds); in ceph_mdsc_force_umount()
3937 mutex_unlock(&mdsc->mutex); in ceph_mdsc_force_umount()
3939 __close_session(mdsc, session); in ceph_mdsc_force_umount()
3941 cleanup_session_requests(mdsc, session); in ceph_mdsc_force_umount()
3946 mutex_lock(&mdsc->mutex); in ceph_mdsc_force_umount()
3947 kick_requests(mdsc, mds); in ceph_mdsc_force_umount()
3949 __wake_requests(mdsc, &mdsc->waiting_for_map); in ceph_mdsc_force_umount()
3950 mutex_unlock(&mdsc->mutex); in ceph_mdsc_force_umount()
3953 static void ceph_mdsc_stop(struct ceph_mds_client *mdsc) in ceph_mdsc_stop() argument
3964 flush_delayed_work(&mdsc->delayed_work); in ceph_mdsc_stop()
3966 if (mdsc->mdsmap) in ceph_mdsc_stop()
3967 ceph_mdsmap_destroy(mdsc->mdsmap); in ceph_mdsc_stop()
3968 kfree(mdsc->sessions); in ceph_mdsc_stop()
3969 ceph_caps_finalize(mdsc); in ceph_mdsc_stop()
3970 ceph_pool_perm_destroy(mdsc); in ceph_mdsc_stop()
3975 struct ceph_mds_client *mdsc = fsc->mdsc; in ceph_mdsc_destroy() local
3976 dout("mdsc_destroy %p\n", mdsc); in ceph_mdsc_destroy()
3978 if (!mdsc) in ceph_mdsc_destroy()
3984 ceph_mdsc_stop(mdsc); in ceph_mdsc_destroy()
3986 fsc->mdsc = NULL; in ceph_mdsc_destroy()
3987 kfree(mdsc); in ceph_mdsc_destroy()
3988 dout("mdsc_destroy %p done\n", mdsc); in ceph_mdsc_destroy()
3991 void ceph_mdsc_handle_fsmap(struct ceph_mds_client *mdsc, struct ceph_msg *msg) in ceph_mdsc_handle_fsmap() argument
3993 struct ceph_fs_client *fsc = mdsc->fsc; in ceph_mdsc_handle_fsmap()
4061 mutex_lock(&mdsc->mutex); in ceph_mdsc_handle_fsmap()
4062 mdsc->mdsmap_err = err; in ceph_mdsc_handle_fsmap()
4063 __wake_requests(mdsc, &mdsc->waiting_for_map); in ceph_mdsc_handle_fsmap()
4064 mutex_unlock(&mdsc->mutex); in ceph_mdsc_handle_fsmap()
4070 void ceph_mdsc_handle_mdsmap(struct ceph_mds_client *mdsc, struct ceph_msg *msg) in ceph_mdsc_handle_mdsmap() argument
4082 if (ceph_check_fsid(mdsc->fsc->client, &fsid) < 0) in ceph_mdsc_handle_mdsmap()
4089 mutex_lock(&mdsc->mutex); in ceph_mdsc_handle_mdsmap()
4090 if (mdsc->mdsmap && epoch <= mdsc->mdsmap->m_epoch) { in ceph_mdsc_handle_mdsmap()
4092 epoch, mdsc->mdsmap->m_epoch); in ceph_mdsc_handle_mdsmap()
4093 mutex_unlock(&mdsc->mutex); in ceph_mdsc_handle_mdsmap()
4104 if (mdsc->mdsmap) { in ceph_mdsc_handle_mdsmap()
4105 oldmap = mdsc->mdsmap; in ceph_mdsc_handle_mdsmap()
4106 mdsc->mdsmap = newmap; in ceph_mdsc_handle_mdsmap()
4107 check_new_map(mdsc, newmap, oldmap); in ceph_mdsc_handle_mdsmap()
4110 mdsc->mdsmap = newmap; /* first mds map */ in ceph_mdsc_handle_mdsmap()
4112 mdsc->fsc->max_file_size = min((loff_t)mdsc->mdsmap->m_max_file_size, in ceph_mdsc_handle_mdsmap()
4115 __wake_requests(mdsc, &mdsc->waiting_for_map); in ceph_mdsc_handle_mdsmap()
4116 ceph_monc_got_map(&mdsc->fsc->client->monc, CEPH_SUB_MDSMAP, in ceph_mdsc_handle_mdsmap()
4117 mdsc->mdsmap->m_epoch); in ceph_mdsc_handle_mdsmap()
4119 mutex_unlock(&mdsc->mutex); in ceph_mdsc_handle_mdsmap()
4120 schedule_delayed(mdsc); in ceph_mdsc_handle_mdsmap()
4124 mutex_unlock(&mdsc->mutex); in ceph_mdsc_handle_mdsmap()
4157 struct ceph_mds_client *mdsc = s->s_mdsc; in peer_reset() local
4160 send_mds_reconnect(mdsc, s); in peer_reset()
4166 struct ceph_mds_client *mdsc = s->s_mdsc; in dispatch() local
4169 mutex_lock(&mdsc->mutex); in dispatch()
4170 if (__verify_registered_session(mdsc, s) < 0) { in dispatch()
4171 mutex_unlock(&mdsc->mutex); in dispatch()
4174 mutex_unlock(&mdsc->mutex); in dispatch()
4178 ceph_mdsc_handle_mdsmap(mdsc, msg); in dispatch()
4181 ceph_mdsc_handle_fsmap(mdsc, msg); in dispatch()
4190 handle_forward(mdsc, s, msg); in dispatch()
4196 ceph_handle_snap(mdsc, s, msg); in dispatch()
4199 handle_lease(mdsc, s, msg); in dispatch()
4202 ceph_handle_quota(mdsc, s, msg); in dispatch()
4225 struct ceph_mds_client *mdsc = s->s_mdsc; in get_authorizer() local
4226 struct ceph_auth_client *ac = mdsc->fsc->client->monc.auth; in get_authorizer()
4253 struct ceph_mds_client *mdsc = s->s_mdsc; in add_authorizer_challenge() local
4254 struct ceph_auth_client *ac = mdsc->fsc->client->monc.auth; in add_authorizer_challenge()
4263 struct ceph_mds_client *mdsc = s->s_mdsc; in verify_authorizer_reply() local
4264 struct ceph_auth_client *ac = mdsc->fsc->client->monc.auth; in verify_authorizer_reply()
4272 struct ceph_mds_client *mdsc = s->s_mdsc; in invalidate_authorizer() local
4273 struct ceph_auth_client *ac = mdsc->fsc->client->monc.auth; in invalidate_authorizer()
4277 return ceph_monc_validate_auth(&mdsc->fsc->client->monc); in invalidate_authorizer()