Lines Matching defs:mdsc

63 static void __wake_requests(struct ceph_mds_client *mdsc,
932 * called under mdsc->mutex
934 struct ceph_mds_session *__ceph_lookup_mds_session(struct ceph_mds_client *mdsc,
937 if (mds >= mdsc->max_sessions || !mdsc->sessions[mds])
939 return ceph_get_mds_session(mdsc->sessions[mds]);
942 static bool __have_session(struct ceph_mds_client *mdsc, int mds)
944 if (mds >= mdsc->max_sessions || !mdsc->sessions[mds])
950 static int __verify_registered_session(struct ceph_mds_client *mdsc,
953 if (s->s_mds >= mdsc->max_sessions ||
954 mdsc->sessions[s->s_mds] != s)
961 * called under mdsc->mutex.
963 static struct ceph_mds_session *register_session(struct ceph_mds_client *mdsc,
966 struct ceph_client *cl = mdsc->fsc->client;
969 if (READ_ONCE(mdsc->fsc->mount_state) == CEPH_MOUNT_FENCE_IO)
972 if (mds >= mdsc->mdsmap->possible_max_rank)
979 if (mds >= mdsc->max_sessions) {
987 if (mdsc->sessions) {
988 memcpy(sa, mdsc->sessions,
989 mdsc->max_sessions * sizeof(void *));
990 kfree(mdsc->sessions);
992 mdsc->sessions = sa;
993 mdsc->max_sessions = newmax;
997 s->s_mdsc = mdsc;
1002 ceph_con_init(&s->s_con, s, &mds_con_ops, &mdsc->fsc->client->msgr);
1019 mdsc->sessions[mds] = s;
1020 atomic_inc(&mdsc->num_sessions);
1024 ceph_mdsmap_get_addr(mdsc->mdsmap, mds));
1034 * called under mdsc->mutex
1036 static void __unregister_session(struct ceph_mds_client *mdsc,
1039 doutc(mdsc->fsc->client, "mds%d %p\n", s->s_mds, s);
1040 BUG_ON(mdsc->sessions[s->s_mds] != s);
1041 mdsc->sessions[s->s_mds] = NULL;
1044 atomic_dec(&mdsc->num_sessions);
1050 * should be last request ref, or hold mdsc->mutex
1060 void ceph_mdsc_iterate_sessions(struct ceph_mds_client *mdsc,
1066 mutex_lock(&mdsc->mutex);
1067 for (mds = 0; mds < mdsc->max_sessions; ++mds) {
1070 s = __ceph_lookup_mds_session(mdsc, mds);
1079 mutex_unlock(&mdsc->mutex);
1082 mutex_lock(&mdsc->mutex);
1084 mutex_unlock(&mdsc->mutex);
1143 * called under mdsc->mutex.
1146 lookup_get_request(struct ceph_mds_client *mdsc, u64 tid)
1150 req = lookup_request(&mdsc->request_tree, tid);
1161 * Called under mdsc->mutex.
1163 static void __register_request(struct ceph_mds_client *mdsc,
1167 struct ceph_client *cl = mdsc->fsc->client;
1170 req->r_tid = ++mdsc->last_tid;
1172 ret = ceph_reserve_caps(mdsc, &req->r_caps_reservation,
1184 insert_request(&mdsc->request_tree, req);
1190 if (mdsc->oldest_tid == 0 && req->r_op != CEPH_MDS_OP_SETFILELOCK)
1191 mdsc->oldest_tid = req->r_tid;
1204 static void __unregister_request(struct ceph_mds_client *mdsc,
1207 doutc(mdsc->fsc->client, "%p tid %lld\n", req, req->r_tid);
1212 if (req->r_tid == mdsc->oldest_tid) {
1214 mdsc->oldest_tid = 0;
1219 mdsc->oldest_tid = next_req->r_tid;
1226 erase_request(&mdsc->request_tree, req);
1280 * Called under mdsc->mutex.
1282 static int __choose_mds(struct ceph_mds_client *mdsc,
1293 struct ceph_client *cl = mdsc->fsc->client;
1303 (__have_session(mdsc, req->r_resend_mds) ||
1304 ceph_mdsmap_get_state(mdsc->mdsmap, req->r_resend_mds) > 0)) {
1334 if (!dir || dir->i_sb != mdsc->fsc->sb) {
1383 if (ceph_mdsmap_get_state(mdsc->mdsmap, mds) >=
1385 !ceph_mdsmap_is_laggy(mdsc->mdsmap, mds))
1397 if (ceph_mdsmap_get_state(mdsc->mdsmap, mds) >=
1399 if (!ceph_mdsmap_is_laggy(mdsc->mdsmap,
1432 mds = ceph_mdsmap_get_random_mds(mdsc->mdsmap);
1538 create_session_full_msg(struct ceph_mds_client *mdsc, int op, u64 seq)
1545 struct ceph_options *opt = mdsc->fsc->client->options;
1546 struct ceph_mount_options *fsopt = mdsc->fsc->mount_options;
1547 struct ceph_client *cl = mdsc->fsc->client;
1553 {"hostname", mdsc->nodename},
1648 ceph_encode_64(&p, mdsc->oldest_tid);
1659 * called under mdsc->mutex
1661 static int __open_session(struct ceph_mds_client *mdsc,
1668 if (READ_ONCE(mdsc->fsc->mount_state) == CEPH_MOUNT_FENCE_IO)
1672 mstate = ceph_mdsmap_get_state(mdsc->mdsmap, mds);
1673 doutc(mdsc->fsc->client, "open_session to mds%d (%s)\n", mds,
1679 msg = create_session_full_msg(mdsc, CEPH_SESSION_REQUEST_OPEN,
1690 * called under mdsc->mutex
1693 __open_export_target_session(struct ceph_mds_client *mdsc, int target)
1698 session = __ceph_lookup_mds_session(mdsc, target);
1700 session = register_session(mdsc, target);
1706 ret = __open_session(mdsc, session);
1715 ceph_mdsc_open_export_target_session(struct ceph_mds_client *mdsc, int target)
1718 struct ceph_client *cl = mdsc->fsc->client;
1722 mutex_lock(&mdsc->mutex);
1723 session = __open_export_target_session(mdsc, target);
1724 mutex_unlock(&mdsc->mutex);
1729 static void __open_export_target_sessions(struct ceph_mds_client *mdsc,
1735 struct ceph_client *cl = mdsc->fsc->client;
1737 if (mds >= mdsc->mdsmap->possible_max_rank)
1740 mi = &mdsc->mdsmap->m_info[mds];
1745 ts = __open_export_target_session(mdsc, mi->export_targets[i]);
1750 void ceph_mdsc_open_export_target_sessions(struct ceph_mds_client *mdsc,
1753 mutex_lock(&mdsc->mutex);
1754 __open_export_target_sessions(mdsc, session);
1755 mutex_unlock(&mdsc->mutex);
1774 static void dispose_cap_releases(struct ceph_mds_client *mdsc,
1782 ceph_put_cap(mdsc, cap);
1786 static void cleanup_session_requests(struct ceph_mds_client *mdsc,
1789 struct ceph_client *cl = mdsc->fsc->client;
1794 mutex_lock(&mdsc->mutex);
1804 __unregister_request(mdsc, req);
1807 p = rb_first(&mdsc->request_tree);
1815 mutex_unlock(&mdsc->mutex);
1931 wake_up_all(&fsc->mdsc->cap_flushing_wq);
2022 static int send_renew_caps(struct ceph_mds_client *mdsc,
2025 struct ceph_client *cl = mdsc->fsc->client;
2036 state = ceph_mdsmap_get_state(mdsc->mdsmap, session->s_mds);
2045 msg = create_session_full_msg(mdsc, CEPH_SESSION_REQUEST_RENEWCAPS,
2053 static int send_flushmsg_ack(struct ceph_mds_client *mdsc,
2056 struct ceph_client *cl = mdsc->fsc->client;
2074 static void renewed_caps(struct ceph_mds_client *mdsc,
2077 struct ceph_client *cl = mdsc->fsc->client;
2085 mdsc->mdsmap->m_session_timeout*HZ;
2127 static int __close_session(struct ceph_mds_client *mdsc,
2171 struct ceph_mds_client *mdsc = ceph_sb_to_mdsc(inode->i_sb);
2172 struct ceph_client *cl = mdsc->fsc->client;
2221 ceph_remove_cap(mdsc, cap, true);
2251 int ceph_trim_caps(struct ceph_mds_client *mdsc,
2255 struct ceph_client *cl = mdsc->fsc->client;
2269 ceph_flush_cap_releases(mdsc, session);
2273 static int check_caps_flush(struct ceph_mds_client *mdsc,
2276 struct ceph_client *cl = mdsc->fsc->client;
2279 spin_lock(&mdsc->cap_dirty_lock);
2280 if (!list_empty(&mdsc->cap_flush_list)) {
2282 list_first_entry(&mdsc->cap_flush_list,
2290 spin_unlock(&mdsc->cap_dirty_lock);
2299 static void wait_caps_flush(struct ceph_mds_client *mdsc,
2302 struct ceph_client *cl = mdsc->fsc->client;
2306 wait_event(mdsc->cap_flushing_wq,
2307 check_caps_flush(mdsc, want_flush_tid));
2315 static void ceph_send_cap_releases(struct ceph_mds_client *mdsc,
2318 struct ceph_client *cl = mdsc->fsc->client;
2322 struct ceph_osd_client *osdc = &mdsc->fsc->client->osdc;
2368 ceph_put_cap(mdsc, cap);
2423 void ceph_flush_cap_releases(struct ceph_mds_client *mdsc,
2426 struct ceph_client *cl = mdsc->fsc->client;
2427 if (mdsc->stopping)
2431 if (queue_work(mdsc->fsc->cap_wq,
2455 struct ceph_mds_client *mdsc =
2457 int ret = ceph_trim_dentries(mdsc);
2459 ceph_queue_cap_reclaim_work(mdsc);
2462 void ceph_queue_cap_reclaim_work(struct ceph_mds_client *mdsc)
2464 struct ceph_client *cl = mdsc->fsc->client;
2465 if (mdsc->stopping)
2468 if (queue_work(mdsc->fsc->cap_wq, &mdsc->cap_reclaim_work)) {
2475 void ceph_reclaim_caps_nr(struct ceph_mds_client *mdsc, int nr)
2480 val = atomic_add_return(nr, &mdsc->cap_reclaim_pending);
2482 atomic_set(&mdsc->cap_reclaim_pending, 0);
2483 ceph_queue_cap_reclaim_work(mdsc);
2487 void ceph_queue_cap_unlink_work(struct ceph_mds_client *mdsc)
2489 struct ceph_client *cl = mdsc->fsc->client;
2490 if (mdsc->stopping)
2493 if (queue_work(mdsc->fsc->cap_wq, &mdsc->cap_unlink_work)) {
2502 struct ceph_mds_client *mdsc =
2504 struct ceph_client *cl = mdsc->fsc->client;
2507 spin_lock(&mdsc->cap_delay_lock);
2508 while (!list_empty(&mdsc->cap_unlink_delay_list)) {
2512 ci = list_first_entry(&mdsc->cap_unlink_delay_list,
2519 spin_unlock(&mdsc->cap_delay_lock);
2524 spin_lock(&mdsc->cap_delay_lock);
2527 spin_unlock(&mdsc->cap_delay_lock);
2578 ceph_mdsc_create_request(struct ceph_mds_client *mdsc, int op, int mode)
2587 req->r_mdsc = mdsc;
2612 * called under mdsc->mutex.
2614 static struct ceph_mds_request *__get_oldest_req(struct ceph_mds_client *mdsc)
2616 if (RB_EMPTY_ROOT(&mdsc->request_tree))
2618 return rb_entry(rb_first(&mdsc->request_tree),
2622 static inline u64 __get_oldest_tid(struct ceph_mds_client *mdsc)
2624 return mdsc->oldest_tid;
2687 * @mdsc: mds client
2707 char *ceph_mdsc_build_path(struct ceph_mds_client *mdsc, struct dentry *dentry,
2710 struct ceph_client *cl = mdsc->fsc->client;
2826 static int build_dentry_path(struct ceph_mds_client *mdsc, struct dentry *dentry,
2844 path = ceph_mdsc_build_path(mdsc, dentry, ppathlen, pino, 1);
2856 struct ceph_mds_client *mdsc = ceph_sb_to_mdsc(inode->i_sb);
2866 path = ceph_mdsc_build_path(mdsc, dentry, ppathlen, pino, 1);
2879 static int set_request_path_attr(struct ceph_mds_client *mdsc, struct inode *rinode,
2885 struct ceph_client *cl = mdsc->fsc->client;
2893 r = build_dentry_path(mdsc, rdentry, rdiri, ppath, pathlen, ino,
2966 * called under mdsc->mutex
2973 struct ceph_mds_client *mdsc = session->s_mdsc;
2974 struct ceph_client *cl = mdsc->fsc->client;
2992 ret = set_request_path_attr(mdsc, req->r_inode, req->r_dentry,
3006 ret = set_request_path_attr(mdsc, NULL, old_dentry,
3154 lhead->mdsmap_epoch = cpu_to_le32(mdsc->mdsmap->m_epoch);
3241 * called under mdsc->mutex if error, under no mutex if
3244 static void complete_request(struct ceph_mds_client *mdsc,
3250 req->r_callback(mdsc, req);
3255 * called under mdsc->mutex
3262 struct ceph_mds_client *mdsc = session->s_mdsc;
3263 struct ceph_client *cl = mdsc->fsc->client;
3351 lhead->oldest_client_tid = cpu_to_le64(__get_oldest_tid(mdsc));
3372 * called under mdsc->mutex
3392 static void __do_request(struct ceph_mds_client *mdsc,
3395 struct ceph_client *cl = mdsc->fsc->client;
3403 __unregister_request(mdsc, req);
3407 if (READ_ONCE(mdsc->fsc->mount_state) == CEPH_MOUNT_FENCE_IO) {
3418 if (READ_ONCE(mdsc->fsc->mount_state) == CEPH_MOUNT_SHUTDOWN) {
3423 if (READ_ONCE(mdsc->fsc->mount_state) == CEPH_MOUNT_MOUNTING) {
3424 if (mdsc->mdsmap_err) {
3425 err = mdsc->mdsmap_err;
3429 if (mdsc->mdsmap->m_epoch == 0) {
3431 list_add(&req->r_wait, &mdsc->waiting_for_map);
3434 if (!(mdsc->fsc->mount_options->flags &
3436 !ceph_mdsmap_is_cluster_available(mdsc->mdsmap)) {
3444 mds = __choose_mds(mdsc, req, &random);
3446 ceph_mdsmap_get_state(mdsc->mdsmap, mds) < CEPH_MDS_STATE_ACTIVE) {
3452 list_add(&req->r_wait, &mdsc->waiting_for_map);
3457 session = __ceph_lookup_mds_session(mdsc, mds);
3459 session = register_session(mdsc, mds);
3494 * it to the mdsc queue.
3497 if (ceph_test_mount_opt(mdsc->fsc, CLEANRECOVER))
3498 list_add(&req->r_wait, &mdsc->waiting_for_map);
3506 err = __open_session(mdsc, session);
3589 complete_request(mdsc, req);
3590 __unregister_request(mdsc, req);
3596 * called under mdsc->mutex
3598 static void __wake_requests(struct ceph_mds_client *mdsc,
3601 struct ceph_client *cl = mdsc->fsc->client;
3613 __do_request(mdsc, req);
3621 static void kick_requests(struct ceph_mds_client *mdsc, int mds)
3623 struct ceph_client *cl = mdsc->fsc->client;
3625 struct rb_node *p = rb_first(&mdsc->request_tree);
3639 __do_request(mdsc, req);
3644 int ceph_mdsc_submit_request(struct ceph_mds_client *mdsc, struct inode *dir,
3647 struct ceph_client *cl = mdsc->fsc->client;
3659 __ceph_touch_fmode(ci, mdsc, fmode);
3683 mutex_lock(&mdsc->mutex);
3684 __register_request(mdsc, req, dir);
3685 __do_request(mdsc, req);
3687 mutex_unlock(&mdsc->mutex);
3691 int ceph_mdsc_wait_request(struct ceph_mds_client *mdsc,
3695 struct ceph_client *cl = mdsc->fsc->client;
3701 err = wait_func(mdsc, req);
3714 mutex_lock(&mdsc->mutex);
3739 mutex_unlock(&mdsc->mutex);
3747 int ceph_mdsc_do_request(struct ceph_mds_client *mdsc,
3751 struct ceph_client *cl = mdsc->fsc->client;
3757 err = ceph_mdsc_submit_request(mdsc, dir, req);
3759 err = ceph_mdsc_wait_request(mdsc, req, NULL);
3795 struct ceph_mds_client *mdsc = session->s_mdsc;
3796 struct ceph_client *cl = mdsc->fsc->client;
3814 mutex_lock(&mdsc->mutex);
3815 req = lookup_get_request(mdsc, tid);
3818 mutex_unlock(&mdsc->mutex);
3828 mutex_unlock(&mdsc->mutex);
3837 mutex_unlock(&mdsc->mutex);
3843 mutex_unlock(&mdsc->mutex);
3851 __unregister_request(mdsc, req);
3854 if (mdsc->stopping && !__get_oldest_req(mdsc))
3855 complete_all(&mdsc->safe_umount_waiters);
3867 mutex_unlock(&mdsc->mutex);
3881 mutex_unlock(&mdsc->mutex);
3904 in = ceph_get_inode(mdsc->fsc->sb, tvino, in);
3924 down_write(&mdsc->snap_rwsem);
3925 err = ceph_update_snap_trace(mdsc, rinfo->snapblob,
3930 up_write(&mdsc->snap_rwsem);
3936 downgrade_write(&mdsc->snap_rwsem);
3938 down_read(&mdsc->snap_rwsem);
3944 err = ceph_fill_trace(mdsc->fsc->sb, req);
3953 up_read(&mdsc->snap_rwsem);
3955 ceph_put_snap_realm(mdsc, realm);
3968 ceph_unreserve_caps(mdsc, &req->r_caps_reservation);
3971 mutex_lock(&mdsc->mutex);
3982 mutex_unlock(&mdsc->mutex);
3987 complete_request(mdsc, req);
3989 ceph_update_metadata_metrics(&mdsc->metric, req->r_start_latency,
3996 ceph_mdsc_close_sessions(mdsc);
4005 static void handle_forward(struct ceph_mds_client *mdsc,
4009 struct ceph_client *cl = mdsc->fsc->client;
4023 mutex_lock(&mdsc->mutex);
4024 req = lookup_get_request(mdsc, tid);
4026 mutex_unlock(&mdsc->mutex);
4033 __unregister_request(mdsc, req);
4059 __do_request(mdsc, req);
4061 mutex_unlock(&mdsc->mutex);
4065 complete_request(mdsc, req);
4108 struct ceph_mds_client *mdsc = session->s_mdsc;
4109 struct ceph_client *cl = mdsc->fsc->client;
4163 mutex_lock(&mdsc->mutex);
4166 __unregister_session(mdsc, session);
4169 session->s_ttl = jiffies + HZ*mdsc->mdsmap->m_session_autoclose;
4170 mutex_unlock(&mdsc->mutex);
4195 renewed_caps(mdsc, session, 0);
4198 metric_schedule_delayed(&mdsc->metric);
4210 if (mdsc->stopping)
4211 __close_session(mdsc, session);
4216 renewed_caps(mdsc, session, 1);
4224 cleanup_session_requests(mdsc, session);
4227 wake_up_all(&mdsc->session_close_wq);
4235 send_renew_caps(mdsc, session);
4239 ceph_trim_caps(mdsc, session, le32_to_cpu(h->max_caps));
4246 ceph_flush_cap_releases(mdsc, session);
4249 send_flushmsg_ack(mdsc, session, seq);
4265 cleanup_session_requests(mdsc, session);
4268 mdsc->fsc->blocklisted = true;
4279 mutex_lock(&mdsc->mutex);
4280 __wake_requests(mdsc, &session->s_waiting);
4282 kick_requests(mdsc, mds);
4283 mutex_unlock(&mdsc->mutex);
4323 static void replay_unsafe_requests(struct ceph_mds_client *mdsc,
4329 doutc(mdsc->fsc->client, "mds%d\n", session->s_mds);
4331 mutex_lock(&mdsc->mutex);
4339 p = rb_first(&mdsc->request_tree);
4356 mutex_unlock(&mdsc->mutex);
4473 struct ceph_mds_client *mdsc = ceph_sb_to_mdsc(inode->i_sb);
4492 path = ceph_mdsc_build_path(mdsc, dentry, &pathlen, &pathbase,
4662 static int encode_snap_realms(struct ceph_mds_client *mdsc,
4667 struct ceph_client *cl = mdsc->fsc->client;
4671 err = ceph_pagelist_encode_32(pagelist, mdsc->num_snap_realms);
4681 for (p = rb_first(&mdsc->snap_realms); p; p = rb_next(p)) {
4733 static void send_mds_reconnect(struct ceph_mds_client *mdsc,
4736 struct ceph_client *cl = mdsc->fsc->client;
4778 dispose_cap_releases(mdsc, &dispose);
4781 if (mdsc->fsc->sb->s_root)
4782 shrink_dcache_parent(mdsc->fsc->sb->s_root);
4787 ceph_mdsmap_get_addr(mdsc->mdsmap, mds));
4790 replay_unsafe_requests(mdsc, session);
4792 ceph_early_kick_flushing_caps(mdsc, session);
4794 down_read(&mdsc->snap_rwsem);
4820 if (mdsc->num_snap_realms) {
4823 mdsc->num_snap_realms *
4829 total_len += mdsc->num_snap_realms *
4846 err = encode_snap_realms(mdsc, &recon_state);
4862 WARN_ON(recon_state.nr_realms != mdsc->num_snap_realms);
4881 mutex_lock(&mdsc->mutex);
4882 __wake_requests(mdsc, &session->s_waiting);
4883 mutex_unlock(&mdsc->mutex);
4885 up_read(&mdsc->snap_rwsem);
4891 up_read(&mdsc->snap_rwsem);
4906 * called under mdsc->mutex.
4908 static void check_new_map(struct ceph_mds_client *mdsc,
4916 struct ceph_client *cl = mdsc->fsc->client;
4927 for (i = 0; i < oldmap->possible_max_rank && i < mdsc->max_sessions; i++) {
4928 if (!mdsc->sessions[i])
4930 s = mdsc->sessions[i];
4944 __unregister_session(mdsc, s);
4945 __wake_requests(mdsc, &s->s_waiting);
4946 mutex_unlock(&mdsc->mutex);
4949 cleanup_session_requests(mdsc, s);
4955 mutex_lock(&mdsc->mutex);
4956 kick_requests(mdsc, i);
4964 mutex_unlock(&mdsc->mutex);
4966 mutex_lock(&mdsc->mutex);
4979 mutex_unlock(&mdsc->mutex);
4981 send_mds_reconnect(mdsc, s);
4982 mutex_lock(&mdsc->mutex);
4994 kick_requests(mdsc, i);
4995 mutex_unlock(&mdsc->mutex);
4997 mutex_lock(&mdsc->mutex);
4998 ceph_kick_flushing_caps(mdsc, s);
5027 * the mdsc->mutex's unlock/lock gap below in rare
5032 s = __ceph_lookup_mds_session(mdsc, i);
5034 s = __open_export_target_session(mdsc, i);
5044 mutex_unlock(&mdsc->mutex);
5045 send_mds_reconnect(mdsc, s);
5047 mutex_lock(&mdsc->mutex);
5050 for (i = 0; i < newmap->possible_max_rank && i < mdsc->max_sessions; i++) {
5051 s = mdsc->sessions[i];
5060 __open_export_target_sessions(mdsc, s);
5082 static void handle_lease(struct ceph_mds_client *mdsc,
5086 struct ceph_client *cl = mdsc->fsc->client;
5087 struct super_block *sb = mdsc->fsc->sb;
5100 if (!ceph_inc_mds_stopping_blocker(mdsc, session))
5182 ceph_dec_mds_stopping_blocker(mdsc);
5186 ceph_dec_mds_stopping_blocker(mdsc);
5234 static void maybe_recover_session(struct ceph_mds_client *mdsc)
5236 struct ceph_client *cl = mdsc->fsc->client;
5237 struct ceph_fs_client *fsc = mdsc->fsc;
5302 static void schedule_delayed(struct ceph_mds_client *mdsc, unsigned long delay)
5309 schedule_delayed_work(&mdsc->delayed_work,
5315 struct ceph_mds_client *mdsc =
5322 doutc(mdsc->fsc->client, "mdsc delayed_work\n");
5324 if (mdsc->stopping >= CEPH_MDSC_STOPPING_FLUSHED)
5327 mutex_lock(&mdsc->mutex);
5328 renew_interval = mdsc->mdsmap->m_session_timeout >> 2;
5330 mdsc->last_renew_caps);
5332 mdsc->last_renew_caps = jiffies;
5334 for (i = 0; i < mdsc->max_sessions; i++) {
5335 struct ceph_mds_session *s = __ceph_lookup_mds_session(mdsc, i);
5343 mutex_unlock(&mdsc->mutex);
5347 send_renew_caps(mdsc, s);
5352 ceph_send_cap_releases(mdsc, s);
5356 mutex_lock(&mdsc->mutex);
5358 mutex_unlock(&mdsc->mutex);
5360 delay = ceph_check_delayed_caps(mdsc);
5362 ceph_queue_cap_reclaim_work(mdsc);
5364 ceph_trim_snapid_map(mdsc);
5366 maybe_recover_session(mdsc);
5368 schedule_delayed(mdsc, delay);
5374 struct ceph_mds_client *mdsc;
5377 mdsc = kzalloc(sizeof(struct ceph_mds_client), GFP_NOFS);
5378 if (!mdsc)
5380 mdsc->fsc = fsc;
5381 mutex_init(&mdsc->mutex);
5382 mdsc->mdsmap = kzalloc(sizeof(*mdsc->mdsmap), GFP_NOFS);
5383 if (!mdsc->mdsmap) {
5388 init_completion(&mdsc->safe_umount_waiters);
5389 spin_lock_init(&mdsc->stopping_lock);
5390 atomic_set(&mdsc->stopping_blockers, 0);
5391 init_completion(&mdsc->stopping_waiter);
5392 init_waitqueue_head(&mdsc->session_close_wq);
5393 INIT_LIST_HEAD(&mdsc->waiting_for_map);
5394 mdsc->quotarealms_inodes = RB_ROOT;
5395 mutex_init(&mdsc->quotarealms_inodes_mutex);
5396 init_rwsem(&mdsc->snap_rwsem);
5397 mdsc->snap_realms = RB_ROOT;
5398 INIT_LIST_HEAD(&mdsc->snap_empty);
5399 spin_lock_init(&mdsc->snap_empty_lock);
5400 mdsc->request_tree = RB_ROOT;
5401 INIT_DELAYED_WORK(&mdsc->delayed_work, delayed_work);
5402 mdsc->last_renew_caps = jiffies;
5403 INIT_LIST_HEAD(&mdsc->cap_delay_list);
5404 INIT_LIST_HEAD(&mdsc->cap_wait_list);
5405 spin_lock_init(&mdsc->cap_delay_lock);
5406 INIT_LIST_HEAD(&mdsc->cap_unlink_delay_list);
5407 INIT_LIST_HEAD(&mdsc->snap_flush_list);
5408 spin_lock_init(&mdsc->snap_flush_lock);
5409 mdsc->last_cap_flush_tid = 1;
5410 INIT_LIST_HEAD(&mdsc->cap_flush_list);
5411 INIT_LIST_HEAD(&mdsc->cap_dirty_migrating);
5412 spin_lock_init(&mdsc->cap_dirty_lock);
5413 init_waitqueue_head(&mdsc->cap_flushing_wq);
5414 INIT_WORK(&mdsc->cap_reclaim_work, ceph_cap_reclaim_work);
5415 INIT_WORK(&mdsc->cap_unlink_work, ceph_cap_unlink_work);
5416 err = ceph_metric_init(&mdsc->metric);
5420 spin_lock_init(&mdsc->dentry_list_lock);
5421 INIT_LIST_HEAD(&mdsc->dentry_leases);
5422 INIT_LIST_HEAD(&mdsc->dentry_dir_leases);
5424 ceph_caps_init(mdsc);
5425 ceph_adjust_caps_max_min(mdsc, fsc->mount_options);
5427 spin_lock_init(&mdsc->snapid_map_lock);
5428 mdsc->snapid_map_tree = RB_ROOT;
5429 INIT_LIST_HEAD(&mdsc->snapid_map_lru);
5431 init_rwsem(&mdsc->pool_perm_rwsem);
5432 mdsc->pool_perm_tree = RB_ROOT;
5434 strscpy(mdsc->nodename, utsname()->nodename,
5435 sizeof(mdsc->nodename));
5437 fsc->mdsc = mdsc;
5441 kfree(mdsc->mdsmap);
5443 kfree(mdsc);
5451 static void wait_requests(struct ceph_mds_client *mdsc)
5453 struct ceph_client *cl = mdsc->fsc->client;
5454 struct ceph_options *opts = mdsc->fsc->client->options;
5457 mutex_lock(&mdsc->mutex);
5458 if (__get_oldest_req(mdsc)) {
5459 mutex_unlock(&mdsc->mutex);
5462 wait_for_completion_timeout(&mdsc->safe_umount_waiters,
5466 mutex_lock(&mdsc->mutex);
5467 while ((req = __get_oldest_req(mdsc))) {
5470 __unregister_request(mdsc, req);
5473 mutex_unlock(&mdsc->mutex);
5506 void ceph_mdsc_pre_umount(struct ceph_mds_client *mdsc)
5508 doutc(mdsc->fsc->client, "begin\n");
5509 mdsc->stopping = CEPH_MDSC_STOPPING_BEGIN;
5511 ceph_mdsc_iterate_sessions(mdsc, send_flush_mdlog, true);
5512 ceph_mdsc_iterate_sessions(mdsc, lock_unlock_session, false);
5513 ceph_flush_dirty_caps(mdsc);
5514 wait_requests(mdsc);
5522 ceph_cleanup_quotarealms_inodes(mdsc);
5523 doutc(mdsc->fsc->client, "done\n");
5529 static void flush_mdlog_and_wait_mdsc_unsafe_requests(struct ceph_mds_client *mdsc,
5532 struct ceph_client *cl = mdsc->fsc->client;
5537 mutex_lock(&mdsc->mutex);
5540 req = __get_oldest_req(mdsc);
5562 mutex_unlock(&mdsc->mutex);
5576 mutex_lock(&mdsc->mutex);
5589 mutex_unlock(&mdsc->mutex);
5594 void ceph_mdsc_sync(struct ceph_mds_client *mdsc)
5596 struct ceph_client *cl = mdsc->fsc->client;
5599 if (READ_ONCE(mdsc->fsc->mount_state) >= CEPH_MOUNT_SHUTDOWN)
5603 mutex_lock(&mdsc->mutex);
5604 want_tid = mdsc->last_tid;
5605 mutex_unlock(&mdsc->mutex);
5607 ceph_flush_dirty_caps(mdsc);
5608 spin_lock(&mdsc->cap_dirty_lock);
5609 want_flush = mdsc->last_cap_flush_tid;
5610 if (!list_empty(&mdsc->cap_flush_list)) {
5612 list_last_entry(&mdsc->cap_flush_list,
5616 spin_unlock(&mdsc->cap_dirty_lock);
5620 flush_mdlog_and_wait_mdsc_unsafe_requests(mdsc, want_tid);
5621 wait_caps_flush(mdsc, want_flush);
5627 static bool done_closing_sessions(struct ceph_mds_client *mdsc, int skipped)
5629 if (READ_ONCE(mdsc->fsc->mount_state) == CEPH_MOUNT_SHUTDOWN)
5631 return atomic_read(&mdsc->num_sessions) <= skipped;
5637 void ceph_mdsc_close_sessions(struct ceph_mds_client *mdsc)
5639 struct ceph_options *opts = mdsc->fsc->client->options;
5640 struct ceph_client *cl = mdsc->fsc->client;
5648 mutex_lock(&mdsc->mutex);
5649 for (i = 0; i < mdsc->max_sessions; i++) {
5650 session = __ceph_lookup_mds_session(mdsc, i);
5653 mutex_unlock(&mdsc->mutex);
5655 if (__close_session(mdsc, session) <= 0)
5659 mutex_lock(&mdsc->mutex);
5661 mutex_unlock(&mdsc->mutex);
5664 wait_event_timeout(mdsc->session_close_wq,
5665 done_closing_sessions(mdsc, skipped),
5669 mutex_lock(&mdsc->mutex);
5670 for (i = 0; i < mdsc->max_sessions; i++) {
5671 if (mdsc->sessions[i]) {
5672 session = ceph_get_mds_session(mdsc->sessions[i]);
5673 __unregister_session(mdsc, session);
5674 mutex_unlock(&mdsc->mutex);
5679 mutex_lock(&mdsc->mutex);
5682 WARN_ON(!list_empty(&mdsc->cap_delay_list));
5683 mutex_unlock(&mdsc->mutex);
5685 ceph_cleanup_snapid_map(mdsc);
5686 ceph_cleanup_global_and_empty_realms(mdsc);
5688 cancel_work_sync(&mdsc->cap_reclaim_work);
5689 cancel_work_sync(&mdsc->cap_unlink_work);
5690 cancel_delayed_work_sync(&mdsc->delayed_work); /* cancel timer */
5695 void ceph_mdsc_force_umount(struct ceph_mds_client *mdsc)
5700 doutc(mdsc->fsc->client, "force umount\n");
5702 mutex_lock(&mdsc->mutex);
5703 for (mds = 0; mds < mdsc->max_sessions; mds++) {
5704 session = __ceph_lookup_mds_session(mdsc, mds);
5709 __unregister_session(mdsc, session);
5710 __wake_requests(mdsc, &session->s_waiting);
5711 mutex_unlock(&mdsc->mutex);
5714 __close_session(mdsc, session);
5716 cleanup_session_requests(mdsc, session);
5722 mutex_lock(&mdsc->mutex);
5723 kick_requests(mdsc, mds);
5725 __wake_requests(mdsc, &mdsc->waiting_for_map);
5726 mutex_unlock(&mdsc->mutex);
5729 static void ceph_mdsc_stop(struct ceph_mds_client *mdsc)
5731 doutc(mdsc->fsc->client, "stop\n");
5740 flush_delayed_work(&mdsc->delayed_work);
5742 if (mdsc->mdsmap)
5743 ceph_mdsmap_destroy(mdsc->mdsmap);
5744 kfree(mdsc->sessions);
5745 ceph_caps_finalize(mdsc);
5746 ceph_pool_perm_destroy(mdsc);
5751 struct ceph_mds_client *mdsc = fsc->mdsc;
5752 doutc(fsc->client, "%p\n", mdsc);
5754 if (!mdsc)
5760 ceph_mdsc_stop(mdsc);
5762 ceph_metric_destroy(&mdsc->metric);
5764 fsc->mdsc = NULL;
5765 kfree(mdsc);
5766 doutc(fsc->client, "%p done\n", mdsc);
5769 void ceph_mdsc_handle_fsmap(struct ceph_mds_client *mdsc, struct ceph_msg *msg)
5771 struct ceph_fs_client *fsc = mdsc->fsc;
5831 ceph_umount_begin(mdsc->fsc->sb);
5834 mutex_lock(&mdsc->mutex);
5835 mdsc->mdsmap_err = err;
5836 __wake_requests(mdsc, &mdsc->waiting_for_map);
5837 mutex_unlock(&mdsc->mutex);
5843 void ceph_mdsc_handle_mdsmap(struct ceph_mds_client *mdsc, struct ceph_msg *msg)
5845 struct ceph_client *cl = mdsc->fsc->client;
5856 if (ceph_check_fsid(mdsc->fsc->client, &fsid) < 0)
5863 mutex_lock(&mdsc->mutex);
5864 if (mdsc->mdsmap && epoch <= mdsc->mdsmap->m_epoch) {
5865 doutc(cl, "epoch %u <= our %u\n", epoch, mdsc->mdsmap->m_epoch);
5866 mutex_unlock(&mdsc->mutex);
5870 newmap = ceph_mdsmap_decode(mdsc, &p, end, ceph_msgr2(mdsc->fsc->client));
5877 if (mdsc->mdsmap) {
5878 oldmap = mdsc->mdsmap;
5879 mdsc->mdsmap = newmap;
5880 check_new_map(mdsc, newmap, oldmap);
5883 mdsc->mdsmap = newmap; /* first mds map */
5885 mdsc->fsc->max_file_size = min((loff_t)mdsc->mdsmap->m_max_file_size,
5888 __wake_requests(mdsc, &mdsc->waiting_for_map);
5889 ceph_monc_got_map(&mdsc->fsc->client->monc, CEPH_SUB_MDSMAP,
5890 mdsc->mdsmap->m_epoch);
5892 mutex_unlock(&mdsc->mutex);
5893 schedule_delayed(mdsc, 0);
5897 mutex_unlock(&mdsc->mutex);
5901 ceph_umount_begin(mdsc->fsc->sb);
5929 struct ceph_mds_client *mdsc = s->s_mdsc;
5931 pr_warn_client(mdsc->fsc->client, "mds%d closed our session\n",
5933 if (READ_ONCE(mdsc->fsc->mount_state) != CEPH_MOUNT_FENCE_IO &&
5934 ceph_mdsmap_get_state(mdsc->mdsmap, s->s_mds) >= CEPH_MDS_STATE_RECONNECT)
5935 send_mds_reconnect(mdsc, s);
5941 struct ceph_mds_client *mdsc = s->s_mdsc;
5942 struct ceph_client *cl = mdsc->fsc->client;
5945 mutex_lock(&mdsc->mutex);
5946 if (__verify_registered_session(mdsc, s) < 0) {
5947 mutex_unlock(&mdsc->mutex);
5950 mutex_unlock(&mdsc->mutex);
5954 ceph_mdsc_handle_mdsmap(mdsc, msg);
5957 ceph_mdsc_handle_fsmap(mdsc, msg);
5966 handle_forward(mdsc, s, msg);
5972 ceph_handle_snap(mdsc, s, msg);
5975 handle_lease(mdsc, s, msg);
5978 ceph_handle_quota(mdsc, s, msg);
6001 struct ceph_mds_client *mdsc = s->s_mdsc;
6002 struct ceph_auth_client *ac = mdsc->fsc->client->monc.auth;
6018 struct ceph_mds_client *mdsc = s->s_mdsc;
6019 struct ceph_auth_client *ac = mdsc->fsc->client->monc.auth;
6028 struct ceph_mds_client *mdsc = s->s_mdsc;
6029 struct ceph_auth_client *ac = mdsc->fsc->client->monc.auth;
6040 struct ceph_mds_client *mdsc = s->s_mdsc;
6041 struct ceph_auth_client *ac = mdsc->fsc->client->monc.auth;
6045 return ceph_monc_validate_auth(&mdsc->fsc->client->monc);