debugfs.c 6.4 KB
Newer Older
1
#include <linux/ceph/ceph_debug.h>
S
Sage Weil 已提交
2

S
Sage Weil 已提交
3
#include <linux/device.h>
4
#include <linux/slab.h>
S
Sage Weil 已提交
5 6 7 8 9
#include <linux/module.h>
#include <linux/ctype.h>
#include <linux/debugfs.h>
#include <linux/seq_file.h>

10 11 12 13
#include <linux/ceph/libceph.h>
#include <linux/ceph/mon_client.h>
#include <linux/ceph/auth.h>
#include <linux/ceph/debugfs.h>
S
Sage Weil 已提交
14

15 16
#ifdef CONFIG_DEBUG_FS

17 18
#include "super.h"
#include "mds_client.h"
S
Sage Weil 已提交
19 20 21 22

static int mdsmap_show(struct seq_file *s, void *p)
{
	int i;
23
	struct ceph_fs_client *fsc = s->private;
S
Sage Weil 已提交
24

25
	if (fsc->mdsc == NULL || fsc->mdsc->mdsmap == NULL)
S
Sage Weil 已提交
26
		return 0;
27 28
	seq_printf(s, "epoch %d\n", fsc->mdsc->mdsmap->m_epoch);
	seq_printf(s, "root %d\n", fsc->mdsc->mdsmap->m_root);
S
Sage Weil 已提交
29
	seq_printf(s, "session_timeout %d\n",
30
		       fsc->mdsc->mdsmap->m_session_timeout);
S
Sage Weil 已提交
31
	seq_printf(s, "session_autoclose %d\n",
32 33
		       fsc->mdsc->mdsmap->m_session_autoclose);
	for (i = 0; i < fsc->mdsc->mdsmap->m_max_mds; i++) {
S
Sage Weil 已提交
34
		struct ceph_entity_addr *addr =
35 36
			&fsc->mdsc->mdsmap->m_info[i].addr;
		int state = fsc->mdsc->mdsmap->m_info[i].state;
S
Sage Weil 已提交
37

38 39
		seq_printf(s, "\tmds%d\t%s\t(%s)\n", i,
			       ceph_pr_addr(&addr->in_addr),
S
Sage Weil 已提交
40 41 42 43 44
			       ceph_mds_state_name(state));
	}
	return 0;
}

45 46 47
/*
 * mdsc debugfs
 */
S
Sage Weil 已提交
48 49
static int mdsc_show(struct seq_file *s, void *p)
{
50 51
	struct ceph_fs_client *fsc = s->private;
	struct ceph_mds_client *mdsc = fsc->mdsc;
S
Sage Weil 已提交
52 53
	struct ceph_mds_request *req;
	struct rb_node *rp;
S
Sage Weil 已提交
54 55 56 57 58
	int pathlen;
	u64 pathbase;
	char *path;

	mutex_lock(&mdsc->mutex);
S
Sage Weil 已提交
59 60
	for (rp = rb_first(&mdsc->request_tree); rp; rp = rb_next(rp)) {
		req = rb_entry(rp, struct ceph_mds_request, r_node);
S
Sage Weil 已提交
61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78

		if (req->r_request)
			seq_printf(s, "%lld\tmds%d\t", req->r_tid, req->r_mds);
		else
			seq_printf(s, "%lld\t(no request)\t", req->r_tid);

		seq_printf(s, "%s", ceph_mds_op_name(req->r_op));

		if (req->r_got_unsafe)
			seq_printf(s, "\t(unsafe)");
		else
			seq_printf(s, "\t");

		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);
79 80
			if (IS_ERR(path))
				path = NULL;
S
Sage Weil 已提交
81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96
			spin_lock(&req->r_dentry->d_lock);
			seq_printf(s, " #%llx/%.*s (%s)",
				   ceph_ino(req->r_dentry->d_parent->d_inode),
				   req->r_dentry->d_name.len,
				   req->r_dentry->d_name.name,
				   path ? path : "");
			spin_unlock(&req->r_dentry->d_lock);
			kfree(path);
		} else if (req->r_path1) {
			seq_printf(s, " #%llx/%s", req->r_ino1.ino,
				   req->r_path1);
		}

		if (req->r_old_dentry) {
			path = ceph_mdsc_build_path(req->r_old_dentry, &pathlen,
						    &pathbase, 0);
97 98
			if (IS_ERR(path))
				path = NULL;
S
Sage Weil 已提交
99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123
			spin_lock(&req->r_old_dentry->d_lock);
			seq_printf(s, " #%llx/%.*s (%s)",
			   ceph_ino(req->r_old_dentry->d_parent->d_inode),
				   req->r_old_dentry->d_name.len,
				   req->r_old_dentry->d_name.name,
				   path ? path : "");
			spin_unlock(&req->r_old_dentry->d_lock);
			kfree(path);
		} else if (req->r_path2) {
			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_printf(s, "\n");
	}
	mutex_unlock(&mdsc->mutex);

	return 0;
}

static int caps_show(struct seq_file *s, void *p)
{
124
	struct ceph_fs_client *fsc = s->private;
125
	int total, avail, used, reserved, min;
S
Sage Weil 已提交
126

127
	ceph_reservation_status(fsc, &total, &avail, &used, &reserved, &min);
S
Sage Weil 已提交
128
	seq_printf(s, "total\t\t%d\n"
129 130 131 132 133
		   "avail\t\t%d\n"
		   "used\t\t%d\n"
		   "reserved\t%d\n"
		   "min\t%d\n",
		   total, avail, used, reserved, min);
S
Sage Weil 已提交
134 135 136 137 138
	return 0;
}

static int dentry_lru_show(struct seq_file *s, void *ptr)
{
139 140
	struct ceph_fs_client *fsc = s->private;
	struct ceph_mds_client *mdsc = fsc->mdsc;
S
Sage Weil 已提交
141 142 143 144 145 146 147 148 149 150 151 152 153
	struct ceph_dentry_info *di;

	spin_lock(&mdsc->dentry_lru_lock);
	list_for_each_entry(di, &mdsc->dentry_lru, lru) {
		struct dentry *dentry = di->dentry;
		seq_printf(s, "%p %p\t%.*s\n",
			   di, dentry, dentry->d_name.len, dentry->d_name.name);
	}
	spin_unlock(&mdsc->dentry_lru_lock);

	return 0;
}

154 155 156 157 158
CEPH_DEFINE_SHOW_FUNC(mdsmap_show)
CEPH_DEFINE_SHOW_FUNC(mdsc_show)
CEPH_DEFINE_SHOW_FUNC(caps_show)
CEPH_DEFINE_SHOW_FUNC(dentry_lru_show)

S
Sage Weil 已提交
159

160 161 162
/*
 * debugfs
 */
Y
Yehuda Sadeh 已提交
163 164
static int congestion_kb_set(void *data, u64 val)
{
165
	struct ceph_fs_client *fsc = (struct ceph_fs_client *)data;
Y
Yehuda Sadeh 已提交
166

167
	fsc->mount_options->congestion_kb = (int)val;
Y
Yehuda Sadeh 已提交
168 169 170 171 172
	return 0;
}

static int congestion_kb_get(void *data, u64 *val)
{
173
	struct ceph_fs_client *fsc = (struct ceph_fs_client *)data;
Y
Yehuda Sadeh 已提交
174

175
	*val = (u64)fsc->mount_options->congestion_kb;
Y
Yehuda Sadeh 已提交
176 177 178 179 180 181
	return 0;
}

DEFINE_SIMPLE_ATTRIBUTE(congestion_kb_fops, congestion_kb_get,
			congestion_kb_set, "%llu\n");

S
Sage Weil 已提交
182

183
void ceph_fs_debugfs_cleanup(struct ceph_fs_client *fsc)
S
Sage Weil 已提交
184
{
185 186 187 188 189 190 191
	dout("ceph_fs_debugfs_cleanup\n");
	debugfs_remove(fsc->debugfs_bdi);
	debugfs_remove(fsc->debugfs_congestion_kb);
	debugfs_remove(fsc->debugfs_mdsmap);
	debugfs_remove(fsc->debugfs_caps);
	debugfs_remove(fsc->debugfs_mdsc);
	debugfs_remove(fsc->debugfs_dentry_lru);
S
Sage Weil 已提交
192 193
}

194
int ceph_fs_debugfs_init(struct ceph_fs_client *fsc)
S
Sage Weil 已提交
195
{
196 197
	char name[100];
	int err = -ENOMEM;
S
Sage Weil 已提交
198

199 200 201 202 203 204 205 206
	dout("ceph_fs_debugfs_init\n");
	fsc->debugfs_congestion_kb =
		debugfs_create_file("writeback_congestion_kb",
				    0600,
				    fsc->client->debugfs_dir,
				    fsc,
				    &congestion_kb_fops);
	if (!fsc->debugfs_congestion_kb)
S
Sage Weil 已提交
207 208
		goto out;

209
	dout("a\n");
S
Sage Weil 已提交
210

211 212 213 214 215 216 217
	snprintf(name, sizeof(name), "../../bdi/%s",
		 dev_name(fsc->backing_dev_info.dev));
	fsc->debugfs_bdi =
		debugfs_create_symlink("bdi",
				       fsc->client->debugfs_dir,
				       name);
	if (!fsc->debugfs_bdi)
S
Sage Weil 已提交
218 219
		goto out;

220 221
	dout("b\n");
	fsc->debugfs_mdsmap = debugfs_create_file("mdsmap",
S
Sage Weil 已提交
222
					0600,
223 224
					fsc->client->debugfs_dir,
					fsc,
S
Sage Weil 已提交
225
					&mdsmap_show_fops);
226
	if (!fsc->debugfs_mdsmap)
S
Sage Weil 已提交
227 228
		goto out;

229 230 231 232 233 234 235
	dout("ca\n");
	fsc->debugfs_mdsc = debugfs_create_file("mdsc",
						0600,
						fsc->client->debugfs_dir,
						fsc,
						&mdsc_show_fops);
	if (!fsc->debugfs_mdsc)
S
Sage Weil 已提交
236 237
		goto out;

238 239
	dout("da\n");
	fsc->debugfs_caps = debugfs_create_file("caps",
S
Sage Weil 已提交
240
						   0400,
241 242
						   fsc->client->debugfs_dir,
						   fsc,
S
Sage Weil 已提交
243
						   &caps_show_fops);
244
	if (!fsc->debugfs_caps)
S
Sage Weil 已提交
245 246
		goto out;

247 248 249 250 251 252 253
	dout("ea\n");
	fsc->debugfs_dentry_lru = debugfs_create_file("dentry_lru",
					0600,
					fsc->client->debugfs_dir,
					fsc,
					&dentry_lru_show_fops);
	if (!fsc->debugfs_dentry_lru)
Y
Yehuda Sadeh 已提交
254 255
		goto out;

S
Sage Weil 已提交
256 257 258
	return 0;

out:
259 260
	ceph_fs_debugfs_cleanup(fsc);
	return err;
S
Sage Weil 已提交
261 262 263
}


S
Sage Weil 已提交
264
#else  /* CONFIG_DEBUG_FS */
265

266
int ceph_fs_debugfs_init(struct ceph_fs_client *fsc)
267 268 269 270
{
	return 0;
}

271
void ceph_fs_debugfs_cleanup(struct ceph_fs_client *fsc)
272 273 274
{
}

S
Sage Weil 已提交
275
#endif  /* CONFIG_DEBUG_FS */