0001
0002 #include <linux/ceph/ceph_debug.h>
0003
0004 #include <linux/device.h>
0005 #include <linux/slab.h>
0006 #include <linux/module.h>
0007 #include <linux/ctype.h>
0008 #include <linux/debugfs.h>
0009 #include <linux/seq_file.h>
0010 #include <linux/math64.h>
0011 #include <linux/ktime.h>
0012
0013 #include <linux/ceph/libceph.h>
0014 #include <linux/ceph/mon_client.h>
0015 #include <linux/ceph/auth.h>
0016 #include <linux/ceph/debugfs.h>
0017
0018 #include "super.h"
0019
0020 #ifdef CONFIG_DEBUG_FS
0021
0022 #include "mds_client.h"
0023 #include "metric.h"
0024
0025 static int mdsmap_show(struct seq_file *s, void *p)
0026 {
0027 int i;
0028 struct ceph_fs_client *fsc = s->private;
0029 struct ceph_mdsmap *mdsmap;
0030
0031 if (!fsc->mdsc || !fsc->mdsc->mdsmap)
0032 return 0;
0033 mdsmap = fsc->mdsc->mdsmap;
0034 seq_printf(s, "epoch %d\n", mdsmap->m_epoch);
0035 seq_printf(s, "root %d\n", mdsmap->m_root);
0036 seq_printf(s, "max_mds %d\n", mdsmap->m_max_mds);
0037 seq_printf(s, "session_timeout %d\n", mdsmap->m_session_timeout);
0038 seq_printf(s, "session_autoclose %d\n", mdsmap->m_session_autoclose);
0039 for (i = 0; i < mdsmap->possible_max_rank; i++) {
0040 struct ceph_entity_addr *addr = &mdsmap->m_info[i].addr;
0041 int state = mdsmap->m_info[i].state;
0042 seq_printf(s, "\tmds%d\t%s\t(%s)\n", i,
0043 ceph_pr_addr(addr),
0044 ceph_mds_state_name(state));
0045 }
0046 return 0;
0047 }
0048
0049
0050
0051
0052 static int mdsc_show(struct seq_file *s, void *p)
0053 {
0054 struct ceph_fs_client *fsc = s->private;
0055 struct ceph_mds_client *mdsc = fsc->mdsc;
0056 struct ceph_mds_request *req;
0057 struct rb_node *rp;
0058 int pathlen = 0;
0059 u64 pathbase;
0060 char *path;
0061
0062 mutex_lock(&mdsc->mutex);
0063 for (rp = rb_first(&mdsc->request_tree); rp; rp = rb_next(rp)) {
0064 req = rb_entry(rp, struct ceph_mds_request, r_node);
0065
0066 if (req->r_request && req->r_session)
0067 seq_printf(s, "%lld\tmds%d\t", req->r_tid,
0068 req->r_session->s_mds);
0069 else if (!req->r_request)
0070 seq_printf(s, "%lld\t(no request)\t", req->r_tid);
0071 else
0072 seq_printf(s, "%lld\t(no session)\t", req->r_tid);
0073
0074 seq_printf(s, "%s", ceph_mds_op_name(req->r_op));
0075
0076 if (test_bit(CEPH_MDS_R_GOT_UNSAFE, &req->r_req_flags))
0077 seq_puts(s, "\t(unsafe)");
0078 else
0079 seq_puts(s, "\t");
0080
0081 if (req->r_inode) {
0082 seq_printf(s, " #%llx", ceph_ino(req->r_inode));
0083 } else if (req->r_dentry) {
0084 path = ceph_mdsc_build_path(req->r_dentry, &pathlen,
0085 &pathbase, 0);
0086 if (IS_ERR(path))
0087 path = NULL;
0088 spin_lock(&req->r_dentry->d_lock);
0089 seq_printf(s, " #%llx/%pd (%s)",
0090 ceph_ino(d_inode(req->r_dentry->d_parent)),
0091 req->r_dentry,
0092 path ? path : "");
0093 spin_unlock(&req->r_dentry->d_lock);
0094 ceph_mdsc_free_path(path, pathlen);
0095 } else if (req->r_path1) {
0096 seq_printf(s, " #%llx/%s", req->r_ino1.ino,
0097 req->r_path1);
0098 } else {
0099 seq_printf(s, " #%llx", req->r_ino1.ino);
0100 }
0101
0102 if (req->r_old_dentry) {
0103 path = ceph_mdsc_build_path(req->r_old_dentry, &pathlen,
0104 &pathbase, 0);
0105 if (IS_ERR(path))
0106 path = NULL;
0107 spin_lock(&req->r_old_dentry->d_lock);
0108 seq_printf(s, " #%llx/%pd (%s)",
0109 req->r_old_dentry_dir ?
0110 ceph_ino(req->r_old_dentry_dir) : 0,
0111 req->r_old_dentry,
0112 path ? path : "");
0113 spin_unlock(&req->r_old_dentry->d_lock);
0114 ceph_mdsc_free_path(path, pathlen);
0115 } else if (req->r_path2 && req->r_op != CEPH_MDS_OP_SYMLINK) {
0116 if (req->r_ino2.ino)
0117 seq_printf(s, " #%llx/%s", req->r_ino2.ino,
0118 req->r_path2);
0119 else
0120 seq_printf(s, " %s", req->r_path2);
0121 }
0122
0123 seq_puts(s, "\n");
0124 }
0125 mutex_unlock(&mdsc->mutex);
0126
0127 return 0;
0128 }
0129
0130 #define CEPH_LAT_METRIC_SHOW(name, total, avg, min, max, sq) { \
0131 s64 _total, _avg, _min, _max, _sq, _st; \
0132 _avg = ktime_to_us(avg); \
0133 _min = ktime_to_us(min == KTIME_MAX ? 0 : min); \
0134 _max = ktime_to_us(max); \
0135 _total = total - 1; \
0136 _sq = _total > 0 ? DIV64_U64_ROUND_CLOSEST(sq, _total) : 0; \
0137 _st = int_sqrt64(_sq); \
0138 _st = ktime_to_us(_st); \
0139 seq_printf(s, "%-14s%-12lld%-16lld%-16lld%-16lld%lld\n", \
0140 name, total, _avg, _min, _max, _st); \
0141 }
0142
0143 #define CEPH_SZ_METRIC_SHOW(name, total, avg, min, max, sum) { \
0144 u64 _min = min == U64_MAX ? 0 : min; \
0145 seq_printf(s, "%-14s%-12lld%-16llu%-16llu%-16llu%llu\n", \
0146 name, total, avg, _min, max, sum); \
0147 }
0148
0149 static int metrics_file_show(struct seq_file *s, void *p)
0150 {
0151 struct ceph_fs_client *fsc = s->private;
0152 struct ceph_client_metric *m = &fsc->mdsc->metric;
0153
0154 seq_printf(s, "item total\n");
0155 seq_printf(s, "------------------------------------------\n");
0156 seq_printf(s, "%-35s%lld\n", "total inodes",
0157 percpu_counter_sum(&m->total_inodes));
0158 seq_printf(s, "%-35s%lld\n", "opened files",
0159 atomic64_read(&m->opened_files));
0160 seq_printf(s, "%-35s%lld\n", "pinned i_caps",
0161 atomic64_read(&m->total_caps));
0162 seq_printf(s, "%-35s%lld\n", "opened inodes",
0163 percpu_counter_sum(&m->opened_inodes));
0164 return 0;
0165 }
0166
0167 static const char * const metric_str[] = {
0168 "read",
0169 "write",
0170 "metadata",
0171 "copyfrom"
0172 };
0173 static int metrics_latency_show(struct seq_file *s, void *p)
0174 {
0175 struct ceph_fs_client *fsc = s->private;
0176 struct ceph_client_metric *cm = &fsc->mdsc->metric;
0177 struct ceph_metric *m;
0178 s64 total, avg, min, max, sq;
0179 int i;
0180
0181 seq_printf(s, "item total avg_lat(us) min_lat(us) max_lat(us) stdev(us)\n");
0182 seq_printf(s, "-----------------------------------------------------------------------------------\n");
0183
0184 for (i = 0; i < METRIC_MAX; i++) {
0185 m = &cm->metric[i];
0186 spin_lock(&m->lock);
0187 total = m->total;
0188 avg = m->latency_avg;
0189 min = m->latency_min;
0190 max = m->latency_max;
0191 sq = m->latency_sq_sum;
0192 spin_unlock(&m->lock);
0193 CEPH_LAT_METRIC_SHOW(metric_str[i], total, avg, min, max, sq);
0194 }
0195
0196 return 0;
0197 }
0198
0199 static int metrics_size_show(struct seq_file *s, void *p)
0200 {
0201 struct ceph_fs_client *fsc = s->private;
0202 struct ceph_client_metric *cm = &fsc->mdsc->metric;
0203 struct ceph_metric *m;
0204 s64 total;
0205 u64 sum, avg, min, max;
0206 int i;
0207
0208 seq_printf(s, "item total avg_sz(bytes) min_sz(bytes) max_sz(bytes) total_sz(bytes)\n");
0209 seq_printf(s, "----------------------------------------------------------------------------------------\n");
0210
0211 for (i = 0; i < METRIC_MAX; i++) {
0212
0213 if (i == METRIC_METADATA)
0214 continue;
0215 m = &cm->metric[i];
0216 spin_lock(&m->lock);
0217 total = m->total;
0218 sum = m->size_sum;
0219 avg = total > 0 ? DIV64_U64_ROUND_CLOSEST(sum, total) : 0;
0220 min = m->size_min;
0221 max = m->size_max;
0222 spin_unlock(&m->lock);
0223 CEPH_SZ_METRIC_SHOW(metric_str[i], total, avg, min, max, sum);
0224 }
0225
0226 return 0;
0227 }
0228
0229 static int metrics_caps_show(struct seq_file *s, void *p)
0230 {
0231 struct ceph_fs_client *fsc = s->private;
0232 struct ceph_client_metric *m = &fsc->mdsc->metric;
0233 int nr_caps = 0;
0234
0235 seq_printf(s, "item total miss hit\n");
0236 seq_printf(s, "-------------------------------------------------\n");
0237
0238 seq_printf(s, "%-14s%-16lld%-16lld%lld\n", "d_lease",
0239 atomic64_read(&m->total_dentries),
0240 percpu_counter_sum(&m->d_lease_mis),
0241 percpu_counter_sum(&m->d_lease_hit));
0242
0243 nr_caps = atomic64_read(&m->total_caps);
0244 seq_printf(s, "%-14s%-16d%-16lld%lld\n", "caps", nr_caps,
0245 percpu_counter_sum(&m->i_caps_mis),
0246 percpu_counter_sum(&m->i_caps_hit));
0247
0248 return 0;
0249 }
0250
0251 static int caps_show_cb(struct inode *inode, struct ceph_cap *cap, void *p)
0252 {
0253 struct seq_file *s = p;
0254
0255 seq_printf(s, "0x%-17llx%-3d%-17s%-17s\n", ceph_ino(inode),
0256 cap->session->s_mds,
0257 ceph_cap_string(cap->issued),
0258 ceph_cap_string(cap->implemented));
0259 return 0;
0260 }
0261
0262 static int caps_show(struct seq_file *s, void *p)
0263 {
0264 struct ceph_fs_client *fsc = s->private;
0265 struct ceph_mds_client *mdsc = fsc->mdsc;
0266 int total, avail, used, reserved, min, i;
0267 struct cap_wait *cw;
0268
0269 ceph_reservation_status(fsc, &total, &avail, &used, &reserved, &min);
0270 seq_printf(s, "total\t\t%d\n"
0271 "avail\t\t%d\n"
0272 "used\t\t%d\n"
0273 "reserved\t%d\n"
0274 "min\t\t%d\n\n",
0275 total, avail, used, reserved, min);
0276 seq_printf(s, "ino mds issued implemented\n");
0277 seq_printf(s, "--------------------------------------------------\n");
0278
0279 mutex_lock(&mdsc->mutex);
0280 for (i = 0; i < mdsc->max_sessions; i++) {
0281 struct ceph_mds_session *session;
0282
0283 session = __ceph_lookup_mds_session(mdsc, i);
0284 if (!session)
0285 continue;
0286 mutex_unlock(&mdsc->mutex);
0287 mutex_lock(&session->s_mutex);
0288 ceph_iterate_session_caps(session, caps_show_cb, s);
0289 mutex_unlock(&session->s_mutex);
0290 ceph_put_mds_session(session);
0291 mutex_lock(&mdsc->mutex);
0292 }
0293 mutex_unlock(&mdsc->mutex);
0294
0295 seq_printf(s, "\n\nWaiters:\n--------\n");
0296 seq_printf(s, "tgid ino need want\n");
0297 seq_printf(s, "-----------------------------------------------------\n");
0298
0299 spin_lock(&mdsc->caps_list_lock);
0300 list_for_each_entry(cw, &mdsc->cap_wait_list, list) {
0301 seq_printf(s, "%-13d0x%-17llx%-17s%-17s\n", cw->tgid, cw->ino,
0302 ceph_cap_string(cw->need),
0303 ceph_cap_string(cw->want));
0304 }
0305 spin_unlock(&mdsc->caps_list_lock);
0306
0307 return 0;
0308 }
0309
0310 static int mds_sessions_show(struct seq_file *s, void *ptr)
0311 {
0312 struct ceph_fs_client *fsc = s->private;
0313 struct ceph_mds_client *mdsc = fsc->mdsc;
0314 struct ceph_auth_client *ac = fsc->client->monc.auth;
0315 struct ceph_options *opt = fsc->client->options;
0316 int mds;
0317
0318 mutex_lock(&mdsc->mutex);
0319
0320
0321 seq_printf(s, "global_id %llu\n", ac->global_id);
0322
0323
0324 seq_printf(s, "name \"%s\"\n", opt->name ? opt->name : "");
0325
0326
0327 for (mds = 0; mds < mdsc->max_sessions; mds++) {
0328 struct ceph_mds_session *session =
0329 __ceph_lookup_mds_session(mdsc, mds);
0330 if (!session) {
0331 continue;
0332 }
0333 mutex_unlock(&mdsc->mutex);
0334 seq_printf(s, "mds.%d %s\n",
0335 session->s_mds,
0336 ceph_session_state_name(session->s_state));
0337
0338 ceph_put_mds_session(session);
0339 mutex_lock(&mdsc->mutex);
0340 }
0341 mutex_unlock(&mdsc->mutex);
0342
0343 return 0;
0344 }
0345
0346 static int status_show(struct seq_file *s, void *p)
0347 {
0348 struct ceph_fs_client *fsc = s->private;
0349 struct ceph_entity_inst *inst = &fsc->client->msgr.inst;
0350 struct ceph_entity_addr *client_addr = ceph_client_addr(fsc->client);
0351
0352 seq_printf(s, "instance: %s.%lld %s/%u\n", ENTITY_NAME(inst->name),
0353 ceph_pr_addr(client_addr), le32_to_cpu(client_addr->nonce));
0354 seq_printf(s, "blocklisted: %s\n", fsc->blocklisted ? "true" : "false");
0355
0356 return 0;
0357 }
0358
0359 DEFINE_SHOW_ATTRIBUTE(mdsmap);
0360 DEFINE_SHOW_ATTRIBUTE(mdsc);
0361 DEFINE_SHOW_ATTRIBUTE(caps);
0362 DEFINE_SHOW_ATTRIBUTE(mds_sessions);
0363 DEFINE_SHOW_ATTRIBUTE(status);
0364 DEFINE_SHOW_ATTRIBUTE(metrics_file);
0365 DEFINE_SHOW_ATTRIBUTE(metrics_latency);
0366 DEFINE_SHOW_ATTRIBUTE(metrics_size);
0367 DEFINE_SHOW_ATTRIBUTE(metrics_caps);
0368
0369
0370
0371
0372
0373 static int congestion_kb_set(void *data, u64 val)
0374 {
0375 struct ceph_fs_client *fsc = (struct ceph_fs_client *)data;
0376
0377 fsc->mount_options->congestion_kb = (int)val;
0378 return 0;
0379 }
0380
0381 static int congestion_kb_get(void *data, u64 *val)
0382 {
0383 struct ceph_fs_client *fsc = (struct ceph_fs_client *)data;
0384
0385 *val = (u64)fsc->mount_options->congestion_kb;
0386 return 0;
0387 }
0388
0389 DEFINE_SIMPLE_ATTRIBUTE(congestion_kb_fops, congestion_kb_get,
0390 congestion_kb_set, "%llu\n");
0391
0392
0393 void ceph_fs_debugfs_cleanup(struct ceph_fs_client *fsc)
0394 {
0395 dout("ceph_fs_debugfs_cleanup\n");
0396 debugfs_remove(fsc->debugfs_bdi);
0397 debugfs_remove(fsc->debugfs_congestion_kb);
0398 debugfs_remove(fsc->debugfs_mdsmap);
0399 debugfs_remove(fsc->debugfs_mds_sessions);
0400 debugfs_remove(fsc->debugfs_caps);
0401 debugfs_remove(fsc->debugfs_status);
0402 debugfs_remove(fsc->debugfs_mdsc);
0403 debugfs_remove_recursive(fsc->debugfs_metrics_dir);
0404 }
0405
0406 void ceph_fs_debugfs_init(struct ceph_fs_client *fsc)
0407 {
0408 char name[100];
0409
0410 dout("ceph_fs_debugfs_init\n");
0411 fsc->debugfs_congestion_kb =
0412 debugfs_create_file("writeback_congestion_kb",
0413 0600,
0414 fsc->client->debugfs_dir,
0415 fsc,
0416 &congestion_kb_fops);
0417
0418 snprintf(name, sizeof(name), "../../bdi/%s",
0419 bdi_dev_name(fsc->sb->s_bdi));
0420 fsc->debugfs_bdi =
0421 debugfs_create_symlink("bdi",
0422 fsc->client->debugfs_dir,
0423 name);
0424
0425 fsc->debugfs_mdsmap = debugfs_create_file("mdsmap",
0426 0400,
0427 fsc->client->debugfs_dir,
0428 fsc,
0429 &mdsmap_fops);
0430
0431 fsc->debugfs_mds_sessions = debugfs_create_file("mds_sessions",
0432 0400,
0433 fsc->client->debugfs_dir,
0434 fsc,
0435 &mds_sessions_fops);
0436
0437 fsc->debugfs_mdsc = debugfs_create_file("mdsc",
0438 0400,
0439 fsc->client->debugfs_dir,
0440 fsc,
0441 &mdsc_fops);
0442
0443 fsc->debugfs_caps = debugfs_create_file("caps",
0444 0400,
0445 fsc->client->debugfs_dir,
0446 fsc,
0447 &caps_fops);
0448
0449 fsc->debugfs_status = debugfs_create_file("status",
0450 0400,
0451 fsc->client->debugfs_dir,
0452 fsc,
0453 &status_fops);
0454
0455 fsc->debugfs_metrics_dir = debugfs_create_dir("metrics",
0456 fsc->client->debugfs_dir);
0457
0458 debugfs_create_file("file", 0400, fsc->debugfs_metrics_dir, fsc,
0459 &metrics_file_fops);
0460 debugfs_create_file("latency", 0400, fsc->debugfs_metrics_dir, fsc,
0461 &metrics_latency_fops);
0462 debugfs_create_file("size", 0400, fsc->debugfs_metrics_dir, fsc,
0463 &metrics_size_fops);
0464 debugfs_create_file("caps", 0400, fsc->debugfs_metrics_dir, fsc,
0465 &metrics_caps_fops);
0466 }
0467
0468
0469 #else
0470
0471 void ceph_fs_debugfs_init(struct ceph_fs_client *fsc)
0472 {
0473 }
0474
0475 void ceph_fs_debugfs_cleanup(struct ceph_fs_client *fsc)
0476 {
0477 }
0478
0479 #endif