debugfs.c 9.8 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24
#include <linux/ceph/ceph_debug.h>

#include <linux/device.h>
#include <linux/slab.h>
#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>

#ifdef CONFIG_DEBUG_FS

/*
 * Implement /sys/kernel/debug/ceph fun
 *
 * /sys/kernel/debug/ceph/client*  - an instance of the ceph client
 *      .../osdmap      - current osdmap
 *      .../monmap      - current monmap
 *      .../osdc        - active osd requests
 *      .../monc        - mon client state
25
 *      .../client_options - libceph-only (i.e. not rbd or cephfs) options
26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56
 *      .../dentry_lru  - dump contents of dentry lru
 *      .../caps        - expose cap (reservation) stats
 *      .../bdi         - symlink to ../../bdi/something
 */

static struct dentry *ceph_debugfs_dir;

static int monmap_show(struct seq_file *s, void *p)
{
	int i;
	struct ceph_client *client = s->private;

	if (client->monc.monmap == NULL)
		return 0;

	seq_printf(s, "epoch %d\n", client->monc.monmap->epoch);
	for (i = 0; i < client->monc.monmap->num_mon; i++) {
		struct ceph_entity_inst *inst =
			&client->monc.monmap->mon_inst[i];

		seq_printf(s, "\t%s%lld\t%s\n",
			   ENTITY_NAME(inst->name),
			   ceph_pr_addr(&inst->addr.in_addr));
	}
	return 0;
}

static int osdmap_show(struct seq_file *s, void *p)
{
	int i;
	struct ceph_client *client = s->private;
57 58
	struct ceph_osd_client *osdc = &client->osdc;
	struct ceph_osdmap *map = osdc->osdmap;
59 60
	struct rb_node *n;

61
	if (map == NULL)
62
		return 0;
63

64 65
	down_read(&osdc->lock);
	seq_printf(s, "epoch %d flags 0x%x\n", map->epoch, map->flags);
66 67

	for (n = rb_first(&map->pg_pools); n; n = rb_next(n)) {
68
		struct ceph_pg_pool_info *pi =
69
			rb_entry(n, struct ceph_pg_pool_info, node);
70

71 72 73 74 75
		seq_printf(s, "pool %lld '%s' type %d size %d min_size %d pg_num %u pg_num_mask %d flags 0x%llx lfor %u read_tier %lld write_tier %lld\n",
			   pi->id, pi->name, pi->type, pi->size, pi->min_size,
			   pi->pg_num, pi->pg_num_mask, pi->flags,
			   pi->last_force_request_resend, pi->read_tier,
			   pi->write_tier);
76
	}
77 78 79
	for (i = 0; i < map->max_osd; i++) {
		struct ceph_entity_addr *addr = &map->osd_addr[i];
		int state = map->osd_state[i];
80 81
		char sb[64];

82
		seq_printf(s, "osd%d\t%s\t%3d%%\t(%s)\t%3d%%\n",
83
			   i, ceph_pr_addr(&addr->in_addr),
84
			   ((map->osd_weight[i]*100) >> 16),
85 86
			   ceph_osdmap_state_str(sb, sizeof(sb), state),
			   ((ceph_get_primary_affinity(map, i)*100) >> 16));
87
	}
88 89 90 91 92 93
	for (n = rb_first(&map->pg_temp); n; n = rb_next(n)) {
		struct ceph_pg_mapping *pg =
			rb_entry(n, struct ceph_pg_mapping, node);

		seq_printf(s, "pg_temp %llu.%x [", pg->pgid.pool,
			   pg->pgid.seed);
94
		for (i = 0; i < pg->pg_temp.len; i++)
95
			seq_printf(s, "%s%d", (i == 0 ? "" : ","),
96
				   pg->pg_temp.osds[i]);
97 98
		seq_printf(s, "]\n");
	}
99 100 101 102 103 104 105
	for (n = rb_first(&map->primary_temp); n; n = rb_next(n)) {
		struct ceph_pg_mapping *pg =
			rb_entry(n, struct ceph_pg_mapping, node);

		seq_printf(s, "primary_temp %llu.%x %d\n", pg->pgid.pool,
			   pg->pgid.seed, pg->primary_temp.osd);
	}
106

107
	up_read(&osdc->lock);
108 109 110 111 112 113 114 115 116
	return 0;
}

static int monc_show(struct seq_file *s, void *p)
{
	struct ceph_client *client = s->private;
	struct ceph_mon_generic_request *req;
	struct ceph_mon_client *monc = &client->monc;
	struct rb_node *rp;
117
	int i;
118 119 120

	mutex_lock(&monc->mutex);

121 122 123 124 125 126 127 128 129 130
	for (i = 0; i < ARRAY_SIZE(monc->subs); i++) {
		seq_printf(s, "have %s %u", ceph_sub_str[i],
			   monc->subs[i].have);
		if (monc->subs[i].want)
			seq_printf(s, " want %llu%s",
				   le64_to_cpu(monc->subs[i].item.start),
				   (monc->subs[i].item.flags &
					CEPH_SUBSCRIBE_ONETIME ?  "" : "+"));
		seq_putc(s, '\n');
	}
131
	seq_printf(s, "fs_cluster_id %d\n", monc->fs_cluster_id);
132 133 134 135 136 137

	for (rp = rb_first(&monc->generic_request_tree); rp; rp = rb_next(rp)) {
		__u16 op;
		req = rb_entry(rp, struct ceph_mon_generic_request, node);
		op = le16_to_cpu(req->request->hdr.type);
		if (op == CEPH_MSG_STATFS)
138
			seq_printf(s, "%llu statfs\n", req->tid);
139 140
		else if (op == CEPH_MSG_MON_GET_VERSION)
			seq_printf(s, "%llu mon_get_version", req->tid);
141
		else
142
			seq_printf(s, "%llu unknown\n", req->tid);
143 144 145 146 147 148
	}

	mutex_unlock(&monc->mutex);
	return 0;
}

149 150 151 152 153 154 155 156 157 158
static void dump_target(struct seq_file *s, struct ceph_osd_request_target *t)
{
	int i;

	seq_printf(s, "osd%d\t%llu.%x\t[", t->osd, t->pgid.pool, t->pgid.seed);
	for (i = 0; i < t->up.size; i++)
		seq_printf(s, "%s%d", (!i ? "" : ","), t->up.osds[i]);
	seq_printf(s, "]/%d\t[", t->up.primary);
	for (i = 0; i < t->acting.size; i++)
		seq_printf(s, "%s%d", (!i ? "" : ","), t->acting.osds[i]);
159 160 161 162 163 164 165 166 167 168
	seq_printf(s, "]/%d\t", t->acting.primary);
	if (t->target_oloc.pool_ns) {
		seq_printf(s, "%*pE/%*pE\t0x%x",
			(int)t->target_oloc.pool_ns->len,
			t->target_oloc.pool_ns->str,
			t->target_oid.name_len, t->target_oid.name, t->flags);
	} else {
		seq_printf(s, "%*pE\t0x%x", t->target_oid.name_len,
			t->target_oid.name, t->flags);
	}
169 170 171 172 173 174 175 176 177 178 179
	if (t->paused)
		seq_puts(s, "\tP");
}

static void dump_request(struct seq_file *s, struct ceph_osd_request *req)
{
	int i;

	seq_printf(s, "%llu\t", req->r_tid);
	dump_target(s, &req->r_t);

180
	seq_printf(s, "\t%d", req->r_attempts);
181 182 183 184 185 186

	for (i = 0; i < req->r_num_ops; i++) {
		struct ceph_osd_req_op *op = &req->r_ops[i];

		seq_printf(s, "%s%s", (i == 0 ? "\t" : ","),
			   ceph_osd_op_name(op->op));
187 188 189
		if (op->op == CEPH_OSD_OP_WATCH)
			seq_printf(s, "-%s",
				   ceph_osd_watch_op_name(op->watch.op));
190 191 192 193 194
	}

	seq_putc(s, '\n');
}

195 196 197 198 199 200 201 202 203 204 205 206 207 208 209
static void dump_requests(struct seq_file *s, struct ceph_osd *osd)
{
	struct rb_node *n;

	mutex_lock(&osd->lock);
	for (n = rb_first(&osd->o_requests); n; n = rb_next(n)) {
		struct ceph_osd_request *req =
		    rb_entry(n, struct ceph_osd_request, r_node);

		dump_request(s, req);
	}

	mutex_unlock(&osd->lock);
}

210 211 212 213 214 215
static void dump_linger_request(struct seq_file *s,
				struct ceph_osd_linger_request *lreq)
{
	seq_printf(s, "%llu\t", lreq->linger_id);
	dump_target(s, &lreq->t);

216 217 218
	seq_printf(s, "\t%u\t%s%s/%d\n", lreq->register_gen,
		   lreq->is_watch ? "W" : "N", lreq->committed ? "C" : "",
		   lreq->last_error);
219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235
}

static void dump_linger_requests(struct seq_file *s, struct ceph_osd *osd)
{
	struct rb_node *n;

	mutex_lock(&osd->lock);
	for (n = rb_first(&osd->o_linger_requests); n; n = rb_next(n)) {
		struct ceph_osd_linger_request *lreq =
		    rb_entry(n, struct ceph_osd_linger_request, node);

		dump_linger_request(s, lreq);
	}

	mutex_unlock(&osd->lock);
}

236 237 238 239
static int osdc_show(struct seq_file *s, void *pp)
{
	struct ceph_client *client = s->private;
	struct ceph_osd_client *osdc = &client->osdc;
240
	struct rb_node *n;
241

242 243 244 245 246 247
	down_read(&osdc->lock);
	seq_printf(s, "REQUESTS %d homeless %d\n",
		   atomic_read(&osdc->num_requests),
		   atomic_read(&osdc->num_homeless));
	for (n = rb_first(&osdc->osds); n; n = rb_next(n)) {
		struct ceph_osd *osd = rb_entry(n, struct ceph_osd, o_node);
248

249
		dump_requests(s, osd);
250
	}
251 252
	dump_requests(s, &osdc->homeless_osd);

253 254 255 256 257 258 259 260
	seq_puts(s, "LINGER REQUESTS\n");
	for (n = rb_first(&osdc->osds); n; n = rb_next(n)) {
		struct ceph_osd *osd = rb_entry(n, struct ceph_osd, o_node);

		dump_linger_requests(s, osd);
	}
	dump_linger_requests(s, &osdc->homeless_osd);

261
	up_read(&osdc->lock);
262 263 264
	return 0;
}

265 266 267 268 269 270 271 272 273 274 275 276 277
static int client_options_show(struct seq_file *s, void *p)
{
	struct ceph_client *client = s->private;
	int ret;

	ret = ceph_print_client_options(s, client);
	if (ret)
		return ret;

	seq_putc(s, '\n');
	return 0;
}

278 279 280 281
CEPH_DEFINE_SHOW_FUNC(monmap_show)
CEPH_DEFINE_SHOW_FUNC(osdmap_show)
CEPH_DEFINE_SHOW_FUNC(monc_show)
CEPH_DEFINE_SHOW_FUNC(osdc_show)
282
CEPH_DEFINE_SHOW_FUNC(client_options_show)
283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304

int ceph_debugfs_init(void)
{
	ceph_debugfs_dir = debugfs_create_dir("ceph", NULL);
	if (!ceph_debugfs_dir)
		return -ENOMEM;
	return 0;
}

void ceph_debugfs_cleanup(void)
{
	debugfs_remove(ceph_debugfs_dir);
}

int ceph_debugfs_client_init(struct ceph_client *client)
{
	int ret = -ENOMEM;
	char name[80];

	snprintf(name, sizeof(name), "%pU.client%lld", &client->fsid,
		 client->monc.auth->global_id);

305 306 307
	dout("ceph_debugfs_client_init %p %s\n", client, name);

	BUG_ON(client->debugfs_dir);
308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343
	client->debugfs_dir = debugfs_create_dir(name, ceph_debugfs_dir);
	if (!client->debugfs_dir)
		goto out;

	client->monc.debugfs_file = debugfs_create_file("monc",
						      0600,
						      client->debugfs_dir,
						      client,
						      &monc_show_fops);
	if (!client->monc.debugfs_file)
		goto out;

	client->osdc.debugfs_file = debugfs_create_file("osdc",
						      0600,
						      client->debugfs_dir,
						      client,
						      &osdc_show_fops);
	if (!client->osdc.debugfs_file)
		goto out;

	client->debugfs_monmap = debugfs_create_file("monmap",
					0600,
					client->debugfs_dir,
					client,
					&monmap_show_fops);
	if (!client->debugfs_monmap)
		goto out;

	client->debugfs_osdmap = debugfs_create_file("osdmap",
					0600,
					client->debugfs_dir,
					client,
					&osdmap_show_fops);
	if (!client->debugfs_osdmap)
		goto out;

344 345 346 347 348 349 350 351
	client->debugfs_options = debugfs_create_file("client_options",
					0600,
					client->debugfs_dir,
					client,
					&client_options_show_fops);
	if (!client->debugfs_options)
		goto out;

352 353 354 355 356 357 358 359 360
	return 0;

out:
	ceph_debugfs_client_cleanup(client);
	return ret;
}

void ceph_debugfs_client_cleanup(struct ceph_client *client)
{
361
	dout("ceph_debugfs_client_cleanup %p\n", client);
362
	debugfs_remove(client->debugfs_options);
363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380
	debugfs_remove(client->debugfs_osdmap);
	debugfs_remove(client->debugfs_monmap);
	debugfs_remove(client->osdc.debugfs_file);
	debugfs_remove(client->monc.debugfs_file);
	debugfs_remove(client->debugfs_dir);
}

#else  /* CONFIG_DEBUG_FS */

int ceph_debugfs_init(void)
{
	return 0;
}

void ceph_debugfs_cleanup(void)
{
}

381
int ceph_debugfs_client_init(struct ceph_client *client)
382 383 384 385 386 387 388 389 390 391 392 393
{
	return 0;
}

void ceph_debugfs_client_cleanup(struct ceph_client *client)
{
}

#endif  /* CONFIG_DEBUG_FS */

EXPORT_SYMBOL(ceph_debugfs_init);
EXPORT_SYMBOL(ceph_debugfs_cleanup);