Files
linux/fs/ceph/debugfs.c
T

342 lines
8.7 KiB
C
Raw Normal View History

// SPDX-License-Identifier: GPL-2.0
#include <linux/ceph/ceph_debug.h>
2009-10-06 11:31:14 -07:00
2009-12-15 14:44:32 -08:00
#include <linux/device.h>
#include <linux/slab.h>
2009-10-06 11:31:14 -07:00
#include <linux/module.h>
#include <linux/ctype.h>
#include <linux/debugfs.h>
#include <linux/seq_file.h>
#include <linux/ceph/libceph.h>
#include <linux/ceph/mon_client.h>
#include <linux/ceph/auth.h>
#include <linux/ceph/debugfs.h>
2009-10-06 11:31:14 -07:00
2010-09-28 09:53:10 -07:00
#include "super.h"
2009-11-12 15:05:52 -08:00
#ifdef CONFIG_DEBUG_FS
#include "mds_client.h"
2009-10-06 11:31:14 -07:00
static int mdsmap_show(struct seq_file *s, void *p)
{
int i;
struct ceph_fs_client *fsc = s->private;
struct ceph_mdsmap *mdsmap;
2009-10-06 11:31:14 -07:00
2017-08-20 20:22:02 +02:00
if (!fsc->mdsc || !fsc->mdsc->mdsmap)
2009-10-06 11:31:14 -07:00
return 0;
mdsmap = fsc->mdsc->mdsmap;
seq_printf(s, "epoch %d\n", mdsmap->m_epoch);
seq_printf(s, "root %d\n", mdsmap->m_root);
seq_printf(s, "max_mds %d\n", mdsmap->m_max_mds);
seq_printf(s, "session_timeout %d\n", mdsmap->m_session_timeout);
seq_printf(s, "session_autoclose %d\n", mdsmap->m_session_autoclose);
for (i = 0; i < mdsmap->possible_max_rank; i++) {
struct ceph_entity_addr *addr = &mdsmap->m_info[i].addr;
int state = mdsmap->m_info[i].state;
seq_printf(s, "\tmds%d\t%s\t(%s)\n", i,
ceph_pr_addr(addr),
2009-10-06 11:31:14 -07:00
ceph_mds_state_name(state));
}
return 0;
}
/*
* mdsc debugfs
*/
2009-10-06 11:31:14 -07:00
static int mdsc_show(struct seq_file *s, void *p)
{
struct ceph_fs_client *fsc = s->private;
struct ceph_mds_client *mdsc = fsc->mdsc;
2010-02-15 12:08:46 -08:00
struct ceph_mds_request *req;
struct rb_node *rp;
int pathlen = 0;
2009-10-06 11:31:14 -07:00
u64 pathbase;
char *path;
mutex_lock(&mdsc->mutex);
2010-02-15 12:08:46 -08:00
for (rp = rb_first(&mdsc->request_tree); rp; rp = rb_next(rp)) {
req = rb_entry(rp, struct ceph_mds_request, r_node);
2009-10-06 11:31:14 -07:00
2010-11-02 13:41:47 -07:00
if (req->r_request && req->r_session)
seq_printf(s, "%lld\tmds%d\t", req->r_tid,
req->r_session->s_mds);
else if (!req->r_request)
2009-10-06 11:31:14 -07:00
seq_printf(s, "%lld\t(no request)\t", req->r_tid);
2010-11-02 13:41:47 -07:00
else
seq_printf(s, "%lld\t(no session)\t", req->r_tid);
2009-10-06 11:31:14 -07:00
seq_printf(s, "%s", ceph_mds_op_name(req->r_op));
if (test_bit(CEPH_MDS_R_GOT_UNSAFE, &req->r_req_flags))
seq_puts(s, "\t(unsafe)");
2009-10-06 11:31:14 -07:00
else
seq_puts(s, "\t");
2009-10-06 11:31:14 -07:00
if (req->r_inode) {
seq_printf(s, " #%llx", ceph_ino(req->r_inode));
} else if (req->r_dentry) {
path = ceph_mdsc_build_path(req->r_dentry, &pathlen,
&pathbase, 0);
if (IS_ERR(path))
path = NULL;
2009-10-06 11:31:14 -07:00
spin_lock(&req->r_dentry->d_lock);
2014-10-21 20:11:25 -04:00
seq_printf(s, " #%llx/%pd (%s)",
ceph_ino(d_inode(req->r_dentry->d_parent)),
2014-10-21 20:11:25 -04:00
req->r_dentry,
2009-10-06 11:31:14 -07:00
path ? path : "");
spin_unlock(&req->r_dentry->d_lock);
ceph_mdsc_free_path(path, pathlen);
2009-10-06 11:31:14 -07:00
} else if (req->r_path1) {
seq_printf(s, " #%llx/%s", req->r_ino1.ino,
req->r_path1);
} else {
seq_printf(s, " #%llx", req->r_ino1.ino);
2009-10-06 11:31:14 -07:00
}
if (req->r_old_dentry) {
path = ceph_mdsc_build_path(req->r_old_dentry, &pathlen,
&pathbase, 0);
if (IS_ERR(path))
path = NULL;
2009-10-06 11:31:14 -07:00
spin_lock(&req->r_old_dentry->d_lock);
2014-10-21 20:11:25 -04:00
seq_printf(s, " #%llx/%pd (%s)",
req->r_old_dentry_dir ?
ceph_ino(req->r_old_dentry_dir) : 0,
2014-10-21 20:11:25 -04:00
req->r_old_dentry,
2009-10-06 11:31:14 -07:00
path ? path : "");
spin_unlock(&req->r_old_dentry->d_lock);
ceph_mdsc_free_path(path, pathlen);
} else if (req->r_path2 && req->r_op != CEPH_MDS_OP_SYMLINK) {
2009-10-06 11:31:14 -07:00
if (req->r_ino2.ino)
seq_printf(s, " #%llx/%s", req->r_ino2.ino,
req->r_path2);
else
seq_printf(s, " %s", req->r_path2);
}
seq_puts(s, "\n");
2009-10-06 11:31:14 -07:00
}
mutex_unlock(&mdsc->mutex);
return 0;
}
2020-03-19 23:44:59 -04:00
static int metric_show(struct seq_file *s, void *p)
{
struct ceph_fs_client *fsc = s->private;
struct ceph_mds_client *mdsc = fsc->mdsc;
struct ceph_client_metric *m = &mdsc->metric;
seq_printf(s, "item total miss hit\n");
seq_printf(s, "-------------------------------------------------\n");
seq_printf(s, "%-14s%-16lld%-16lld%lld\n", "d_lease",
atomic64_read(&m->total_dentries),
percpu_counter_sum(&m->d_lease_mis),
percpu_counter_sum(&m->d_lease_hit));
return 0;
}
static int caps_show_cb(struct inode *inode, struct ceph_cap *cap, void *p)
{
struct seq_file *s = p;
seq_printf(s, "0x%-17lx%-17s%-17s\n", inode->i_ino,
ceph_cap_string(cap->issued),
ceph_cap_string(cap->implemented));
return 0;
}
2009-10-06 11:31:14 -07:00
static int caps_show(struct seq_file *s, void *p)
{
struct ceph_fs_client *fsc = s->private;
struct ceph_mds_client *mdsc = fsc->mdsc;
int total, avail, used, reserved, min, i;
struct cap_wait *cw;
2009-10-06 11:31:14 -07:00
ceph_reservation_status(fsc, &total, &avail, &used, &reserved, &min);
2009-10-06 11:31:14 -07:00
seq_printf(s, "total\t\t%d\n"
2010-02-17 10:02:43 -08:00
"avail\t\t%d\n"
"used\t\t%d\n"
"reserved\t%d\n"
"min\t\t%d\n\n",
2010-02-17 10:02:43 -08:00
total, avail, used, reserved, min);
seq_printf(s, "ino issued implemented\n");
seq_printf(s, "-----------------------------------------------\n");
mutex_lock(&mdsc->mutex);
for (i = 0; i < mdsc->max_sessions; i++) {
struct ceph_mds_session *session;
session = __ceph_lookup_mds_session(mdsc, i);
if (!session)
continue;
mutex_unlock(&mdsc->mutex);
mutex_lock(&session->s_mutex);
ceph_iterate_session_caps(session, caps_show_cb, s);
mutex_unlock(&session->s_mutex);
ceph_put_mds_session(session);
mutex_lock(&mdsc->mutex);
}
mutex_unlock(&mdsc->mutex);
seq_printf(s, "\n\nWaiters:\n--------\n");
seq_printf(s, "tgid ino need want\n");
seq_printf(s, "-----------------------------------------------------\n");
spin_lock(&mdsc->caps_list_lock);
list_for_each_entry(cw, &mdsc->cap_wait_list, list) {
seq_printf(s, "%-13d0x%-17lx%-17s%-17s\n", cw->tgid, cw->ino,
ceph_cap_string(cw->need),
ceph_cap_string(cw->want));
}
spin_unlock(&mdsc->caps_list_lock);
2009-10-06 11:31:14 -07:00
return 0;
}
2014-09-12 16:58:49 +01:00
static int mds_sessions_show(struct seq_file *s, void *ptr)
{
struct ceph_fs_client *fsc = s->private;
struct ceph_mds_client *mdsc = fsc->mdsc;
struct ceph_auth_client *ac = fsc->client->monc.auth;
struct ceph_options *opt = fsc->client->options;
int mds = -1;
mutex_lock(&mdsc->mutex);
/* The 'num' portion of an 'entity name' */
seq_printf(s, "global_id %llu\n", ac->global_id);
/* The -o name mount argument */
seq_printf(s, "name \"%s\"\n", opt->name ? opt->name : "");
/* The list of MDS session rank+state */
for (mds = 0; mds < mdsc->max_sessions; mds++) {
struct ceph_mds_session *session =
__ceph_lookup_mds_session(mdsc, mds);
if (!session) {
continue;
}
mutex_unlock(&mdsc->mutex);
seq_printf(s, "mds.%d %s\n",
session->s_mds,
ceph_session_state_name(session->s_state));
ceph_put_mds_session(session);
mutex_lock(&mdsc->mutex);
}
mutex_unlock(&mdsc->mutex);
return 0;
}
2020-01-28 20:12:22 +01:00
DEFINE_SHOW_ATTRIBUTE(mdsmap);
DEFINE_SHOW_ATTRIBUTE(mdsc);
DEFINE_SHOW_ATTRIBUTE(caps);
DEFINE_SHOW_ATTRIBUTE(mds_sessions);
2020-03-19 23:44:59 -04:00
DEFINE_SHOW_ATTRIBUTE(metric);
2009-10-06 11:31:14 -07:00
/*
* debugfs
*/
2009-12-18 13:51:57 -08:00
static int congestion_kb_set(void *data, u64 val)
{
struct ceph_fs_client *fsc = (struct ceph_fs_client *)data;
2009-12-18 13:51:57 -08:00
fsc->mount_options->congestion_kb = (int)val;
2009-12-18 13:51:57 -08:00
return 0;
}
static int congestion_kb_get(void *data, u64 *val)
{
struct ceph_fs_client *fsc = (struct ceph_fs_client *)data;
2009-12-18 13:51:57 -08:00
*val = (u64)fsc->mount_options->congestion_kb;
2009-12-18 13:51:57 -08:00
return 0;
}
DEFINE_SIMPLE_ATTRIBUTE(congestion_kb_fops, congestion_kb_get,
congestion_kb_set, "%llu\n");
void ceph_fs_debugfs_cleanup(struct ceph_fs_client *fsc)
2009-10-06 11:31:14 -07:00
{
dout("ceph_fs_debugfs_cleanup\n");
debugfs_remove(fsc->debugfs_bdi);
debugfs_remove(fsc->debugfs_congestion_kb);
debugfs_remove(fsc->debugfs_mdsmap);
2014-09-12 16:58:49 +01:00
debugfs_remove(fsc->debugfs_mds_sessions);
debugfs_remove(fsc->debugfs_caps);
2020-03-19 23:44:59 -04:00
debugfs_remove(fsc->debugfs_metric);
debugfs_remove(fsc->debugfs_mdsc);
2009-10-06 11:31:14 -07:00
}
void ceph_fs_debugfs_init(struct ceph_fs_client *fsc)
2009-10-06 11:31:14 -07:00
{
char name[100];
2009-10-06 11:31:14 -07:00
dout("ceph_fs_debugfs_init\n");
fsc->debugfs_congestion_kb =
2010-08-03 10:25:11 -07:00
debugfs_create_file("writeback_congestion_kb",
0600,
fsc->client->debugfs_dir,
fsc,
2010-08-03 10:25:11 -07:00
&congestion_kb_fops);
2009-12-18 13:51:57 -08:00
snprintf(name, sizeof(name), "../../bdi/%s",
2020-05-04 14:47:55 +02:00
bdi_dev_name(fsc->sb->s_bdi));
fsc->debugfs_bdi =
debugfs_create_symlink("bdi",
fsc->client->debugfs_dir,
name);
fsc->debugfs_mdsmap = debugfs_create_file("mdsmap",
0400,
fsc->client->debugfs_dir,
fsc,
2020-01-28 20:12:22 +01:00
&mdsmap_fops);
2014-09-12 16:58:49 +01:00
fsc->debugfs_mds_sessions = debugfs_create_file("mds_sessions",
0400,
2014-09-12 16:58:49 +01:00
fsc->client->debugfs_dir,
fsc,
2020-01-28 20:12:22 +01:00
&mds_sessions_fops);
2014-09-12 16:58:49 +01:00
fsc->debugfs_mdsc = debugfs_create_file("mdsc",
0400,
fsc->client->debugfs_dir,
fsc,
2020-01-28 20:12:22 +01:00
&mdsc_fops);
2020-03-19 23:44:59 -04:00
fsc->debugfs_metric = debugfs_create_file("metrics",
0400,
fsc->client->debugfs_dir,
fsc,
&metric_fops);
fsc->debugfs_caps = debugfs_create_file("caps",
2020-03-19 23:44:59 -04:00
0400,
fsc->client->debugfs_dir,
fsc,
&caps_fops);
2009-10-06 11:31:14 -07:00
}
2010-08-03 10:25:11 -07:00
#else /* CONFIG_DEBUG_FS */
2009-11-12 15:05:52 -08:00
void ceph_fs_debugfs_init(struct ceph_fs_client *fsc)
2009-11-12 15:05:52 -08:00
{
}
void ceph_fs_debugfs_cleanup(struct ceph_fs_client *fsc)
2009-11-12 15:05:52 -08:00
{
}
2010-08-03 10:25:11 -07:00
#endif /* CONFIG_DEBUG_FS */