xref: /linux/fs/ceph/debugfs.c (revision 0ea5c948cb64bab5bc7a5516774eb8536f05aa0d)
1b2441318SGreg Kroah-Hartman // SPDX-License-Identifier: GPL-2.0
23d14c5d2SYehuda Sadeh #include <linux/ceph/ceph_debug.h>
376aa844dSSage Weil 
406edf046SSage Weil #include <linux/device.h>
55a0e3ad6STejun Heo #include <linux/slab.h>
676aa844dSSage Weil #include <linux/module.h>
776aa844dSSage Weil #include <linux/ctype.h>
876aa844dSSage Weil #include <linux/debugfs.h>
976aa844dSSage Weil #include <linux/seq_file.h>
1097e27aaaSXiubo Li #include <linux/math64.h>
1197e27aaaSXiubo Li #include <linux/ktime.h>
1276aa844dSSage Weil 
133d14c5d2SYehuda Sadeh #include <linux/ceph/libceph.h>
143d14c5d2SYehuda Sadeh #include <linux/ceph/mon_client.h>
153d14c5d2SYehuda Sadeh #include <linux/ceph/auth.h>
163d14c5d2SYehuda Sadeh #include <linux/ceph/debugfs.h>
1776aa844dSSage Weil 
186f453ed6SRandy Dunlap #include "super.h"
196f453ed6SRandy Dunlap 
20039934b8SSage Weil #ifdef CONFIG_DEBUG_FS
21039934b8SSage Weil 
223d14c5d2SYehuda Sadeh #include "mds_client.h"
2397e27aaaSXiubo Li #include "metric.h"
2476aa844dSSage Weil 
mdsmap_show(struct seq_file * s,void * p)2576aa844dSSage Weil static int mdsmap_show(struct seq_file *s, void *p)
2676aa844dSSage Weil {
2776aa844dSSage Weil 	int i;
283d14c5d2SYehuda Sadeh 	struct ceph_fs_client *fsc = s->private;
2976201b63SYan, Zheng 	struct ceph_mdsmap *mdsmap;
3076aa844dSSage Weil 
31d37b1d99SMarkus Elfring 	if (!fsc->mdsc || !fsc->mdsc->mdsmap)
3276aa844dSSage Weil 		return 0;
3376201b63SYan, Zheng 	mdsmap = fsc->mdsc->mdsmap;
3476201b63SYan, Zheng 	seq_printf(s, "epoch %d\n", mdsmap->m_epoch);
3576201b63SYan, Zheng 	seq_printf(s, "root %d\n", mdsmap->m_root);
3676201b63SYan, Zheng 	seq_printf(s, "max_mds %d\n", mdsmap->m_max_mds);
3776201b63SYan, Zheng 	seq_printf(s, "session_timeout %d\n", mdsmap->m_session_timeout);
3876201b63SYan, Zheng 	seq_printf(s, "session_autoclose %d\n", mdsmap->m_session_autoclose);
39b38c9eb4SXiubo Li 	for (i = 0; i < mdsmap->possible_max_rank; i++) {
4076201b63SYan, Zheng 		struct ceph_entity_addr *addr = &mdsmap->m_info[i].addr;
4176201b63SYan, Zheng 		int state = mdsmap->m_info[i].state;
423d14c5d2SYehuda Sadeh 		seq_printf(s, "\tmds%d\t%s\t(%s)\n", i,
43b726ec97SJeff Layton 			       ceph_pr_addr(addr),
4476aa844dSSage Weil 			       ceph_mds_state_name(state));
4576aa844dSSage Weil 	}
4676aa844dSSage Weil 	return 0;
4776aa844dSSage Weil }
4876aa844dSSage Weil 
493d14c5d2SYehuda Sadeh /*
503d14c5d2SYehuda Sadeh  * mdsc debugfs
513d14c5d2SYehuda Sadeh  */
mdsc_show(struct seq_file * s,void * p)5276aa844dSSage Weil static int mdsc_show(struct seq_file *s, void *p)
5376aa844dSSage Weil {
543d14c5d2SYehuda Sadeh 	struct ceph_fs_client *fsc = s->private;
553d14c5d2SYehuda Sadeh 	struct ceph_mds_client *mdsc = fsc->mdsc;
5644ca18f2SSage Weil 	struct ceph_mds_request *req;
5744ca18f2SSage Weil 	struct rb_node *rp;
5813c41737SDan Carpenter 	int pathlen = 0;
5976aa844dSSage Weil 	u64 pathbase;
6076aa844dSSage Weil 	char *path;
6176aa844dSSage Weil 
6276aa844dSSage Weil 	mutex_lock(&mdsc->mutex);
6344ca18f2SSage Weil 	for (rp = rb_first(&mdsc->request_tree); rp; rp = rb_next(rp)) {
6444ca18f2SSage Weil 		req = rb_entry(rp, struct ceph_mds_request, r_node);
6576aa844dSSage Weil 
664af25fddSSage Weil 		if (req->r_request && req->r_session)
674af25fddSSage Weil 			seq_printf(s, "%lld\tmds%d\t", req->r_tid,
684af25fddSSage Weil 				   req->r_session->s_mds);
694af25fddSSage Weil 		else if (!req->r_request)
7076aa844dSSage Weil 			seq_printf(s, "%lld\t(no request)\t", req->r_tid);
714af25fddSSage Weil 		else
724af25fddSSage Weil 			seq_printf(s, "%lld\t(no session)\t", req->r_tid);
7376aa844dSSage Weil 
7476aa844dSSage Weil 		seq_printf(s, "%s", ceph_mds_op_name(req->r_op));
7576aa844dSSage Weil 
76bc2de10dSJeff Layton 		if (test_bit(CEPH_MDS_R_GOT_UNSAFE, &req->r_req_flags))
773364d113SFabian Frederick 			seq_puts(s, "\t(unsafe)");
7876aa844dSSage Weil 		else
793364d113SFabian Frederick 			seq_puts(s, "\t");
8076aa844dSSage Weil 
8176aa844dSSage Weil 		if (req->r_inode) {
8276aa844dSSage Weil 			seq_printf(s, " #%llx", ceph_ino(req->r_inode));
8376aa844dSSage Weil 		} else if (req->r_dentry) {
84197b7d79SXiubo Li 			path = ceph_mdsc_build_path(mdsc, req->r_dentry, &pathlen,
8576aa844dSSage Weil 						    &pathbase, 0);
86f44c3890SDan Carpenter 			if (IS_ERR(path))
87f44c3890SDan Carpenter 				path = NULL;
8876aa844dSSage Weil 			spin_lock(&req->r_dentry->d_lock);
89a455589fSAl Viro 			seq_printf(s, " #%llx/%pd (%s)",
902b0143b5SDavid Howells 				   ceph_ino(d_inode(req->r_dentry->d_parent)),
91a455589fSAl Viro 				   req->r_dentry,
9276aa844dSSage Weil 				   path ? path : "");
9376aa844dSSage Weil 			spin_unlock(&req->r_dentry->d_lock);
94f77f21bbSJeff Layton 			ceph_mdsc_free_path(path, pathlen);
9576aa844dSSage Weil 		} else if (req->r_path1) {
9676aa844dSSage Weil 			seq_printf(s, " #%llx/%s", req->r_ino1.ino,
9776aa844dSSage Weil 				   req->r_path1);
98c137a32aSYan, Zheng 		} else {
99c137a32aSYan, Zheng 			seq_printf(s, " #%llx", req->r_ino1.ino);
10076aa844dSSage Weil 		}
10176aa844dSSage Weil 
10276aa844dSSage Weil 		if (req->r_old_dentry) {
103197b7d79SXiubo Li 			path = ceph_mdsc_build_path(mdsc, req->r_old_dentry, &pathlen,
10476aa844dSSage Weil 						    &pathbase, 0);
105f44c3890SDan Carpenter 			if (IS_ERR(path))
106f44c3890SDan Carpenter 				path = NULL;
10776aa844dSSage Weil 			spin_lock(&req->r_old_dentry->d_lock);
108a455589fSAl Viro 			seq_printf(s, " #%llx/%pd (%s)",
109844d87c3SSage Weil 				   req->r_old_dentry_dir ?
110844d87c3SSage Weil 				   ceph_ino(req->r_old_dentry_dir) : 0,
111a455589fSAl Viro 				   req->r_old_dentry,
11276aa844dSSage Weil 				   path ? path : "");
11376aa844dSSage Weil 			spin_unlock(&req->r_old_dentry->d_lock);
114f77f21bbSJeff Layton 			ceph_mdsc_free_path(path, pathlen);
115aeda081cSYan, Zheng 		} else if (req->r_path2 && req->r_op != CEPH_MDS_OP_SYMLINK) {
11676aa844dSSage Weil 			if (req->r_ino2.ino)
11776aa844dSSage Weil 				seq_printf(s, " #%llx/%s", req->r_ino2.ino,
11876aa844dSSage Weil 					   req->r_path2);
11976aa844dSSage Weil 			else
12076aa844dSSage Weil 				seq_printf(s, " %s", req->r_path2);
12176aa844dSSage Weil 		}
12276aa844dSSage Weil 
1233364d113SFabian Frederick 		seq_puts(s, "\n");
12476aa844dSSage Weil 	}
12576aa844dSSage Weil 	mutex_unlock(&mdsc->mutex);
12676aa844dSSage Weil 
12776aa844dSSage Weil 	return 0;
12876aa844dSSage Weil }
12976aa844dSSage Weil 
130903f4fecSXiubo Li #define CEPH_LAT_METRIC_SHOW(name, total, avg, min, max, sq) {		\
13197e27aaaSXiubo Li 	s64 _total, _avg, _min, _max, _sq, _st;				\
13297e27aaaSXiubo Li 	_avg = ktime_to_us(avg);					\
13397e27aaaSXiubo Li 	_min = ktime_to_us(min == KTIME_MAX ? 0 : min);			\
13497e27aaaSXiubo Li 	_max = ktime_to_us(max);					\
13597e27aaaSXiubo Li 	_total = total - 1;						\
13697e27aaaSXiubo Li 	_sq = _total > 0 ? DIV64_U64_ROUND_CLOSEST(sq, _total) : 0;	\
13797e27aaaSXiubo Li 	_st = int_sqrt64(_sq);						\
13897e27aaaSXiubo Li 	_st = ktime_to_us(_st);						\
13997e27aaaSXiubo Li 	seq_printf(s, "%-14s%-12lld%-16lld%-16lld%-16lld%lld\n",	\
14097e27aaaSXiubo Li 		   name, total, _avg, _min, _max, _st);			\
14197e27aaaSXiubo Li }
14297e27aaaSXiubo Li 
143903f4fecSXiubo Li #define CEPH_SZ_METRIC_SHOW(name, total, avg, min, max, sum) {		\
144903f4fecSXiubo Li 	u64 _min = min == U64_MAX ? 0 : min;				\
145903f4fecSXiubo Li 	seq_printf(s, "%-14s%-12lld%-16llu%-16llu%-16llu%llu\n",	\
146903f4fecSXiubo Li 		   name, total, avg, _min, max, sum);			\
147903f4fecSXiubo Li }
148903f4fecSXiubo Li 
metrics_file_show(struct seq_file * s,void * p)149cbed4ff7SLuís Henriques static int metrics_file_show(struct seq_file *s, void *p)
150f9009efaSXiubo Li {
151f9009efaSXiubo Li 	struct ceph_fs_client *fsc = s->private;
152cbed4ff7SLuís Henriques 	struct ceph_client_metric *m = &fsc->mdsc->metric;
153f9009efaSXiubo Li 
1541dd8d470SXiubo Li 	seq_printf(s, "item                               total\n");
1551dd8d470SXiubo Li 	seq_printf(s, "------------------------------------------\n");
156cbed4ff7SLuís Henriques 	seq_printf(s, "%-35s%lld\n", "total inodes",
157cbed4ff7SLuís Henriques 		   percpu_counter_sum(&m->total_inodes));
158cbed4ff7SLuís Henriques 	seq_printf(s, "%-35s%lld\n", "opened files",
159cbed4ff7SLuís Henriques 		   atomic64_read(&m->opened_files));
160cbed4ff7SLuís Henriques 	seq_printf(s, "%-35s%lld\n", "pinned i_caps",
161cbed4ff7SLuís Henriques 		   atomic64_read(&m->total_caps));
162cbed4ff7SLuís Henriques 	seq_printf(s, "%-35s%lld\n", "opened inodes",
163cbed4ff7SLuís Henriques 		   percpu_counter_sum(&m->opened_inodes));
164cbed4ff7SLuís Henriques 	return 0;
165cbed4ff7SLuís Henriques }
1661dd8d470SXiubo Li 
16717e9fc9fSLuís Henriques static const char * const metric_str[] = {
16817e9fc9fSLuís Henriques 	"read",
16917e9fc9fSLuís Henriques 	"write",
170c02cb7bdSLuís Henriques 	"metadata",
171c02cb7bdSLuís Henriques 	"copyfrom"
17217e9fc9fSLuís Henriques };
metrics_latency_show(struct seq_file * s,void * p)173cbed4ff7SLuís Henriques static int metrics_latency_show(struct seq_file *s, void *p)
174cbed4ff7SLuís Henriques {
175cbed4ff7SLuís Henriques 	struct ceph_fs_client *fsc = s->private;
17617e9fc9fSLuís Henriques 	struct ceph_client_metric *cm = &fsc->mdsc->metric;
17717e9fc9fSLuís Henriques 	struct ceph_metric *m;
178271251f8SVenky Shankar 	s64 total, avg, min, max, sq;
17917e9fc9fSLuís Henriques 	int i;
180cbed4ff7SLuís Henriques 
18197e27aaaSXiubo Li 	seq_printf(s, "item          total       avg_lat(us)     min_lat(us)     max_lat(us)     stdev(us)\n");
18297e27aaaSXiubo Li 	seq_printf(s, "-----------------------------------------------------------------------------------\n");
18397e27aaaSXiubo Li 
18417e9fc9fSLuís Henriques 	for (i = 0; i < METRIC_MAX; i++) {
18517e9fc9fSLuís Henriques 		m = &cm->metric[i];
18617e9fc9fSLuís Henriques 		spin_lock(&m->lock);
18717e9fc9fSLuís Henriques 		total = m->total;
188271251f8SVenky Shankar 		avg = m->latency_avg;
18917e9fc9fSLuís Henriques 		min = m->latency_min;
19017e9fc9fSLuís Henriques 		max = m->latency_max;
19117e9fc9fSLuís Henriques 		sq = m->latency_sq_sum;
19217e9fc9fSLuís Henriques 		spin_unlock(&m->lock);
19317e9fc9fSLuís Henriques 		CEPH_LAT_METRIC_SHOW(metric_str[i], total, avg, min, max, sq);
19417e9fc9fSLuís Henriques 	}
195903f4fecSXiubo Li 
196cbed4ff7SLuís Henriques 	return 0;
197cbed4ff7SLuís Henriques }
198cbed4ff7SLuís Henriques 
metrics_size_show(struct seq_file * s,void * p)199cbed4ff7SLuís Henriques static int metrics_size_show(struct seq_file *s, void *p)
200cbed4ff7SLuís Henriques {
201cbed4ff7SLuís Henriques 	struct ceph_fs_client *fsc = s->private;
20217e9fc9fSLuís Henriques 	struct ceph_client_metric *cm = &fsc->mdsc->metric;
20317e9fc9fSLuís Henriques 	struct ceph_metric *m;
204cbed4ff7SLuís Henriques 	s64 total;
20517e9fc9fSLuís Henriques 	u64 sum, avg, min, max;
20617e9fc9fSLuís Henriques 	int i;
207cbed4ff7SLuís Henriques 
208903f4fecSXiubo Li 	seq_printf(s, "item          total       avg_sz(bytes)   min_sz(bytes)   max_sz(bytes)  total_sz(bytes)\n");
209903f4fecSXiubo Li 	seq_printf(s, "----------------------------------------------------------------------------------------\n");
210903f4fecSXiubo Li 
21117e9fc9fSLuís Henriques 	for (i = 0; i < METRIC_MAX; i++) {
21217e9fc9fSLuís Henriques 		/* skip 'metadata' as it doesn't use the size metric */
21317e9fc9fSLuís Henriques 		if (i == METRIC_METADATA)
21417e9fc9fSLuís Henriques 			continue;
21517e9fc9fSLuís Henriques 		m = &cm->metric[i];
21617e9fc9fSLuís Henriques 		spin_lock(&m->lock);
21717e9fc9fSLuís Henriques 		total = m->total;
21817e9fc9fSLuís Henriques 		sum = m->size_sum;
21917e9fc9fSLuís Henriques 		avg = total > 0 ? DIV64_U64_ROUND_CLOSEST(sum, total) : 0;
22017e9fc9fSLuís Henriques 		min = m->size_min;
22117e9fc9fSLuís Henriques 		max = m->size_max;
22217e9fc9fSLuís Henriques 		spin_unlock(&m->lock);
22317e9fc9fSLuís Henriques 		CEPH_SZ_METRIC_SHOW(metric_str[i], total, avg, min, max, sum);
22417e9fc9fSLuís Henriques 	}
22570c94820SXiubo Li 
226cbed4ff7SLuís Henriques 	return 0;
227cbed4ff7SLuís Henriques }
228cbed4ff7SLuís Henriques 
metrics_caps_show(struct seq_file * s,void * p)229cbed4ff7SLuís Henriques static int metrics_caps_show(struct seq_file *s, void *p)
230cbed4ff7SLuís Henriques {
231cbed4ff7SLuís Henriques 	struct ceph_fs_client *fsc = s->private;
232cbed4ff7SLuís Henriques 	struct ceph_client_metric *m = &fsc->mdsc->metric;
233cbed4ff7SLuís Henriques 	int nr_caps = 0;
234cbed4ff7SLuís Henriques 
235f9009efaSXiubo Li 	seq_printf(s, "item          total           miss            hit\n");
236f9009efaSXiubo Li 	seq_printf(s, "-------------------------------------------------\n");
237f9009efaSXiubo Li 
238f9009efaSXiubo Li 	seq_printf(s, "%-14s%-16lld%-16lld%lld\n", "d_lease",
239f9009efaSXiubo Li 		   atomic64_read(&m->total_dentries),
240f9009efaSXiubo Li 		   percpu_counter_sum(&m->d_lease_mis),
241f9009efaSXiubo Li 		   percpu_counter_sum(&m->d_lease_hit));
242f9009efaSXiubo Li 
2434f1d756dSXiubo Li 	nr_caps = atomic64_read(&m->total_caps);
2441af16d54SXiubo Li 	seq_printf(s, "%-14s%-16d%-16lld%lld\n", "caps", nr_caps,
2451af16d54SXiubo Li 		   percpu_counter_sum(&m->i_caps_mis),
2461af16d54SXiubo Li 		   percpu_counter_sum(&m->i_caps_hit));
2471af16d54SXiubo Li 
248f9009efaSXiubo Li 	return 0;
249f9009efaSXiubo Li }
250f9009efaSXiubo Li 
caps_show_cb(struct inode * inode,int mds,void * p)251aaf67de7SXiubo Li static int caps_show_cb(struct inode *inode, int mds, void *p)
252ff4a80bfSJeff Layton {
253aaf67de7SXiubo Li 	struct ceph_inode_info *ci = ceph_inode(inode);
254ff4a80bfSJeff Layton 	struct seq_file *s = p;
255aaf67de7SXiubo Li 	struct ceph_cap *cap;
256ff4a80bfSJeff Layton 
257aaf67de7SXiubo Li 	spin_lock(&ci->i_ceph_lock);
258aaf67de7SXiubo Li 	cap = __get_cap_for_mds(ci, mds);
259aaf67de7SXiubo Li 	if (cap)
2603a8ebe0bSYanhu Cao 		seq_printf(s, "0x%-17llx%-3d%-17s%-17s\n", ceph_ino(inode),
2613a8ebe0bSYanhu Cao 			   cap->session->s_mds,
262ff4a80bfSJeff Layton 			   ceph_cap_string(cap->issued),
263ff4a80bfSJeff Layton 			   ceph_cap_string(cap->implemented));
264aaf67de7SXiubo Li 	spin_unlock(&ci->i_ceph_lock);
265ff4a80bfSJeff Layton 	return 0;
266ff4a80bfSJeff Layton }
267ff4a80bfSJeff Layton 
caps_show(struct seq_file * s,void * p)26876aa844dSSage Weil static int caps_show(struct seq_file *s, void *p)
26976aa844dSSage Weil {
2703d14c5d2SYehuda Sadeh 	struct ceph_fs_client *fsc = s->private;
271ff4a80bfSJeff Layton 	struct ceph_mds_client *mdsc = fsc->mdsc;
272ff4a80bfSJeff Layton 	int total, avail, used, reserved, min, i;
2733a3430afSJeff Layton 	struct cap_wait	*cw;
27476aa844dSSage Weil 
2753d14c5d2SYehuda Sadeh 	ceph_reservation_status(fsc, &total, &avail, &used, &reserved, &min);
27676aa844dSSage Weil 	seq_printf(s, "total\t\t%d\n"
27776aa844dSSage Weil 		   "avail\t\t%d\n"
27876aa844dSSage Weil 		   "used\t\t%d\n"
27985ccce43SSage Weil 		   "reserved\t%d\n"
280ff4a80bfSJeff Layton 		   "min\t\t%d\n\n",
28185ccce43SSage Weil 		   total, avail, used, reserved, min);
2823a8ebe0bSYanhu Cao 	seq_printf(s, "ino              mds  issued           implemented\n");
2833a8ebe0bSYanhu Cao 	seq_printf(s, "--------------------------------------------------\n");
284ff4a80bfSJeff Layton 
285ff4a80bfSJeff Layton 	mutex_lock(&mdsc->mutex);
286ff4a80bfSJeff Layton 	for (i = 0; i < mdsc->max_sessions; i++) {
287ff4a80bfSJeff Layton 		struct ceph_mds_session *session;
288ff4a80bfSJeff Layton 
289ff4a80bfSJeff Layton 		session = __ceph_lookup_mds_session(mdsc, i);
290ff4a80bfSJeff Layton 		if (!session)
291ff4a80bfSJeff Layton 			continue;
292ff4a80bfSJeff Layton 		mutex_unlock(&mdsc->mutex);
293ff4a80bfSJeff Layton 		mutex_lock(&session->s_mutex);
294ff4a80bfSJeff Layton 		ceph_iterate_session_caps(session, caps_show_cb, s);
295ff4a80bfSJeff Layton 		mutex_unlock(&session->s_mutex);
296ff4a80bfSJeff Layton 		ceph_put_mds_session(session);
297ff4a80bfSJeff Layton 		mutex_lock(&mdsc->mutex);
298ff4a80bfSJeff Layton 	}
299ff4a80bfSJeff Layton 	mutex_unlock(&mdsc->mutex);
300ff4a80bfSJeff Layton 
3013a3430afSJeff Layton 	seq_printf(s, "\n\nWaiters:\n--------\n");
3023a3430afSJeff Layton 	seq_printf(s, "tgid         ino                need             want\n");
3033a3430afSJeff Layton 	seq_printf(s, "-----------------------------------------------------\n");
3043a3430afSJeff Layton 
3053a3430afSJeff Layton 	spin_lock(&mdsc->caps_list_lock);
3063a3430afSJeff Layton 	list_for_each_entry(cw, &mdsc->cap_wait_list, list) {
307ebce3eb2SJeff Layton 		seq_printf(s, "%-13d0x%-17llx%-17s%-17s\n", cw->tgid, cw->ino,
3083a3430afSJeff Layton 				ceph_cap_string(cw->need),
3093a3430afSJeff Layton 				ceph_cap_string(cw->want));
3103a3430afSJeff Layton 	}
3113a3430afSJeff Layton 	spin_unlock(&mdsc->caps_list_lock);
3123a3430afSJeff Layton 
31376aa844dSSage Weil 	return 0;
31476aa844dSSage Weil }
31576aa844dSSage Weil 
mds_sessions_show(struct seq_file * s,void * ptr)31614ed9703SJohn Spray static int mds_sessions_show(struct seq_file *s, void *ptr)
31714ed9703SJohn Spray {
31814ed9703SJohn Spray 	struct ceph_fs_client *fsc = s->private;
31914ed9703SJohn Spray 	struct ceph_mds_client *mdsc = fsc->mdsc;
32014ed9703SJohn Spray 	struct ceph_auth_client *ac = fsc->client->monc.auth;
32114ed9703SJohn Spray 	struct ceph_options *opt = fsc->client->options;
3222c81ef28SColin Ian King 	int mds;
32314ed9703SJohn Spray 
32414ed9703SJohn Spray 	mutex_lock(&mdsc->mutex);
32514ed9703SJohn Spray 
32614ed9703SJohn Spray 	/* The 'num' portion of an 'entity name' */
32714ed9703SJohn Spray 	seq_printf(s, "global_id %llu\n", ac->global_id);
32814ed9703SJohn Spray 
32914ed9703SJohn Spray 	/* The -o name mount argument */
33014ed9703SJohn Spray 	seq_printf(s, "name \"%s\"\n", opt->name ? opt->name : "");
33114ed9703SJohn Spray 
33214ed9703SJohn Spray 	/* The list of MDS session rank+state */
33314ed9703SJohn Spray 	for (mds = 0; mds < mdsc->max_sessions; mds++) {
33414ed9703SJohn Spray 		struct ceph_mds_session *session =
33514ed9703SJohn Spray 			__ceph_lookup_mds_session(mdsc, mds);
33614ed9703SJohn Spray 		if (!session) {
33714ed9703SJohn Spray 			continue;
33814ed9703SJohn Spray 		}
33914ed9703SJohn Spray 		mutex_unlock(&mdsc->mutex);
34014ed9703SJohn Spray 		seq_printf(s, "mds.%d %s\n",
34114ed9703SJohn Spray 				session->s_mds,
34214ed9703SJohn Spray 				ceph_session_state_name(session->s_state));
34314ed9703SJohn Spray 
34414ed9703SJohn Spray 		ceph_put_mds_session(session);
34514ed9703SJohn Spray 		mutex_lock(&mdsc->mutex);
34614ed9703SJohn Spray 	}
34714ed9703SJohn Spray 	mutex_unlock(&mdsc->mutex);
34814ed9703SJohn Spray 
34914ed9703SJohn Spray 	return 0;
35014ed9703SJohn Spray }
35114ed9703SJohn Spray 
status_show(struct seq_file * s,void * p)352247b1f19SXiubo Li static int status_show(struct seq_file *s, void *p)
353247b1f19SXiubo Li {
354247b1f19SXiubo Li 	struct ceph_fs_client *fsc = s->private;
355247b1f19SXiubo Li 	struct ceph_entity_inst *inst = &fsc->client->msgr.inst;
356247b1f19SXiubo Li 	struct ceph_entity_addr *client_addr = ceph_client_addr(fsc->client);
357247b1f19SXiubo Li 
358247b1f19SXiubo Li 	seq_printf(s, "instance: %s.%lld %s/%u\n", ENTITY_NAME(inst->name),
359247b1f19SXiubo Li 		   ceph_pr_addr(client_addr), le32_to_cpu(client_addr->nonce));
360247b1f19SXiubo Li 	seq_printf(s, "blocklisted: %s\n", fsc->blocklisted ? "true" : "false");
361247b1f19SXiubo Li 
362247b1f19SXiubo Li 	return 0;
363247b1f19SXiubo Li }
364247b1f19SXiubo Li 
365072eaf3cSIlya Dryomov DEFINE_SHOW_ATTRIBUTE(mdsmap);
366072eaf3cSIlya Dryomov DEFINE_SHOW_ATTRIBUTE(mdsc);
367072eaf3cSIlya Dryomov DEFINE_SHOW_ATTRIBUTE(caps);
368072eaf3cSIlya Dryomov DEFINE_SHOW_ATTRIBUTE(mds_sessions);
369247b1f19SXiubo Li DEFINE_SHOW_ATTRIBUTE(status);
370cbed4ff7SLuís Henriques DEFINE_SHOW_ATTRIBUTE(metrics_file);
371cbed4ff7SLuís Henriques DEFINE_SHOW_ATTRIBUTE(metrics_latency);
372cbed4ff7SLuís Henriques DEFINE_SHOW_ATTRIBUTE(metrics_size);
373cbed4ff7SLuís Henriques DEFINE_SHOW_ATTRIBUTE(metrics_caps);
37476aa844dSSage Weil 
37576aa844dSSage Weil 
3763d14c5d2SYehuda Sadeh /*
3773d14c5d2SYehuda Sadeh  * debugfs
3783d14c5d2SYehuda Sadeh  */
congestion_kb_set(void * data,u64 val)3792baba250SYehuda Sadeh static int congestion_kb_set(void *data, u64 val)
3802baba250SYehuda Sadeh {
3813d14c5d2SYehuda Sadeh 	struct ceph_fs_client *fsc = (struct ceph_fs_client *)data;
3822baba250SYehuda Sadeh 
3833d14c5d2SYehuda Sadeh 	fsc->mount_options->congestion_kb = (int)val;
3842baba250SYehuda Sadeh 	return 0;
3852baba250SYehuda Sadeh }
3862baba250SYehuda Sadeh 
congestion_kb_get(void * data,u64 * val)3872baba250SYehuda Sadeh static int congestion_kb_get(void *data, u64 *val)
3882baba250SYehuda Sadeh {
3893d14c5d2SYehuda Sadeh 	struct ceph_fs_client *fsc = (struct ceph_fs_client *)data;
3902baba250SYehuda Sadeh 
3913d14c5d2SYehuda Sadeh 	*val = (u64)fsc->mount_options->congestion_kb;
3922baba250SYehuda Sadeh 	return 0;
3932baba250SYehuda Sadeh }
3942baba250SYehuda Sadeh 
3952baba250SYehuda Sadeh DEFINE_SIMPLE_ATTRIBUTE(congestion_kb_fops, congestion_kb_get,
3962baba250SYehuda Sadeh 			congestion_kb_set, "%llu\n");
3972baba250SYehuda Sadeh 
3983d14c5d2SYehuda Sadeh 
ceph_fs_debugfs_cleanup(struct ceph_fs_client * fsc)3993d14c5d2SYehuda Sadeh void ceph_fs_debugfs_cleanup(struct ceph_fs_client *fsc)
40076aa844dSSage Weil {
401*38d46409SXiubo Li 	doutc(fsc->client, "begin\n");
4023d14c5d2SYehuda Sadeh 	debugfs_remove(fsc->debugfs_bdi);
4033d14c5d2SYehuda Sadeh 	debugfs_remove(fsc->debugfs_congestion_kb);
4043d14c5d2SYehuda Sadeh 	debugfs_remove(fsc->debugfs_mdsmap);
40514ed9703SJohn Spray 	debugfs_remove(fsc->debugfs_mds_sessions);
4063d14c5d2SYehuda Sadeh 	debugfs_remove(fsc->debugfs_caps);
407cbed4ff7SLuís Henriques 	debugfs_remove(fsc->debugfs_status);
4083d14c5d2SYehuda Sadeh 	debugfs_remove(fsc->debugfs_mdsc);
409cbed4ff7SLuís Henriques 	debugfs_remove_recursive(fsc->debugfs_metrics_dir);
410*38d46409SXiubo Li 	doutc(fsc->client, "done\n");
41176aa844dSSage Weil }
41276aa844dSSage Weil 
ceph_fs_debugfs_init(struct ceph_fs_client * fsc)4131a829ff2SGreg Kroah-Hartman void ceph_fs_debugfs_init(struct ceph_fs_client *fsc)
41476aa844dSSage Weil {
4153d14c5d2SYehuda Sadeh 	char name[100];
41676aa844dSSage Weil 
417*38d46409SXiubo Li 	doutc(fsc->client, "begin\n");
4183d14c5d2SYehuda Sadeh 	fsc->debugfs_congestion_kb =
419213c99eeSSage Weil 		debugfs_create_file("writeback_congestion_kb",
4202baba250SYehuda Sadeh 				    0600,
4213d14c5d2SYehuda Sadeh 				    fsc->client->debugfs_dir,
4223d14c5d2SYehuda Sadeh 				    fsc,
4232baba250SYehuda Sadeh 				    &congestion_kb_fops);
4242baba250SYehuda Sadeh 
4253d14c5d2SYehuda Sadeh 	snprintf(name, sizeof(name), "../../bdi/%s",
426d51cfc53SYufen Yu 		 bdi_dev_name(fsc->sb->s_bdi));
4273d14c5d2SYehuda Sadeh 	fsc->debugfs_bdi =
4283d14c5d2SYehuda Sadeh 		debugfs_create_symlink("bdi",
4293d14c5d2SYehuda Sadeh 				       fsc->client->debugfs_dir,
43006edf046SSage Weil 				       name);
4313d14c5d2SYehuda Sadeh 
4323d14c5d2SYehuda Sadeh 	fsc->debugfs_mdsmap = debugfs_create_file("mdsmap",
43311e1478dSChengguang Xu 					0400,
4343d14c5d2SYehuda Sadeh 					fsc->client->debugfs_dir,
4353d14c5d2SYehuda Sadeh 					fsc,
436072eaf3cSIlya Dryomov 					&mdsmap_fops);
4373d14c5d2SYehuda Sadeh 
43814ed9703SJohn Spray 	fsc->debugfs_mds_sessions = debugfs_create_file("mds_sessions",
43911e1478dSChengguang Xu 					0400,
44014ed9703SJohn Spray 					fsc->client->debugfs_dir,
44114ed9703SJohn Spray 					fsc,
442072eaf3cSIlya Dryomov 					&mds_sessions_fops);
44314ed9703SJohn Spray 
4443d14c5d2SYehuda Sadeh 	fsc->debugfs_mdsc = debugfs_create_file("mdsc",
44511e1478dSChengguang Xu 						0400,
4463d14c5d2SYehuda Sadeh 						fsc->client->debugfs_dir,
4473d14c5d2SYehuda Sadeh 						fsc,
448072eaf3cSIlya Dryomov 						&mdsc_fops);
4493d14c5d2SYehuda Sadeh 
4503d14c5d2SYehuda Sadeh 	fsc->debugfs_caps = debugfs_create_file("caps",
4513d14c5d2SYehuda Sadeh 						0400,
4523d14c5d2SYehuda Sadeh 						fsc->client->debugfs_dir,
4533d14c5d2SYehuda Sadeh 						fsc,
454072eaf3cSIlya Dryomov 						&caps_fops);
455247b1f19SXiubo Li 
456247b1f19SXiubo Li 	fsc->debugfs_status = debugfs_create_file("status",
457247b1f19SXiubo Li 						  0400,
458247b1f19SXiubo Li 						  fsc->client->debugfs_dir,
459247b1f19SXiubo Li 						  fsc,
460247b1f19SXiubo Li 						  &status_fops);
461cbed4ff7SLuís Henriques 
462cbed4ff7SLuís Henriques 	fsc->debugfs_metrics_dir = debugfs_create_dir("metrics",
463cbed4ff7SLuís Henriques 						      fsc->client->debugfs_dir);
464cbed4ff7SLuís Henriques 
465cbed4ff7SLuís Henriques 	debugfs_create_file("file", 0400, fsc->debugfs_metrics_dir, fsc,
466cbed4ff7SLuís Henriques 			    &metrics_file_fops);
467cbed4ff7SLuís Henriques 	debugfs_create_file("latency", 0400, fsc->debugfs_metrics_dir, fsc,
468cbed4ff7SLuís Henriques 			    &metrics_latency_fops);
469cbed4ff7SLuís Henriques 	debugfs_create_file("size", 0400, fsc->debugfs_metrics_dir, fsc,
470cbed4ff7SLuís Henriques 			    &metrics_size_fops);
471cbed4ff7SLuís Henriques 	debugfs_create_file("caps", 0400, fsc->debugfs_metrics_dir, fsc,
472cbed4ff7SLuís Henriques 			    &metrics_caps_fops);
473*38d46409SXiubo Li 	doutc(fsc->client, "done\n");
47476aa844dSSage Weil }
47576aa844dSSage Weil 
47676aa844dSSage Weil 
477213c99eeSSage Weil #else  /* CONFIG_DEBUG_FS */
478039934b8SSage Weil 
ceph_fs_debugfs_init(struct ceph_fs_client * fsc)4791a829ff2SGreg Kroah-Hartman void ceph_fs_debugfs_init(struct ceph_fs_client *fsc)
480039934b8SSage Weil {
481039934b8SSage Weil }
482039934b8SSage Weil 
ceph_fs_debugfs_cleanup(struct ceph_fs_client * fsc)4833d14c5d2SYehuda Sadeh void ceph_fs_debugfs_cleanup(struct ceph_fs_client *fsc)
484039934b8SSage Weil {
485039934b8SSage Weil }
486039934b8SSage Weil 
487213c99eeSSage Weil #endif  /* CONFIG_DEBUG_FS */
488