Yehuda Sadeh | 3d14c5d | 2010-04-06 15:14:15 -0700 | [diff] [blame^] | 1 | #include <linux/ceph/ceph_debug.h> |
Sage Weil | 76aa844 | 2009-10-06 11:31:14 -0700 | [diff] [blame] | 2 | |
Sage Weil | 06edf04 | 2009-12-15 14:44:32 -0800 | [diff] [blame] | 3 | #include <linux/device.h> |
Tejun Heo | 5a0e3ad | 2010-03-24 17:04:11 +0900 | [diff] [blame] | 4 | #include <linux/slab.h> |
Sage Weil | 76aa844 | 2009-10-06 11:31:14 -0700 | [diff] [blame] | 5 | #include <linux/module.h> |
| 6 | #include <linux/ctype.h> |
| 7 | #include <linux/debugfs.h> |
| 8 | #include <linux/seq_file.h> |
| 9 | |
Yehuda Sadeh | 3d14c5d | 2010-04-06 15:14:15 -0700 | [diff] [blame^] | 10 | #include <linux/ceph/libceph.h> |
| 11 | #include <linux/ceph/mon_client.h> |
| 12 | #include <linux/ceph/auth.h> |
| 13 | #include <linux/ceph/debugfs.h> |
Sage Weil | 76aa844 | 2009-10-06 11:31:14 -0700 | [diff] [blame] | 14 | |
Sage Weil | 039934b | 2009-11-12 15:05:52 -0800 | [diff] [blame] | 15 | #ifdef CONFIG_DEBUG_FS |
| 16 | |
Yehuda Sadeh | 3d14c5d | 2010-04-06 15:14:15 -0700 | [diff] [blame^] | 17 | #include "super.h" |
| 18 | #include "mds_client.h" |
Sage Weil | 76aa844 | 2009-10-06 11:31:14 -0700 | [diff] [blame] | 19 | |
| 20 | static int mdsmap_show(struct seq_file *s, void *p) |
| 21 | { |
| 22 | int i; |
Yehuda Sadeh | 3d14c5d | 2010-04-06 15:14:15 -0700 | [diff] [blame^] | 23 | struct ceph_fs_client *fsc = s->private; |
Sage Weil | 76aa844 | 2009-10-06 11:31:14 -0700 | [diff] [blame] | 24 | |
Yehuda Sadeh | 3d14c5d | 2010-04-06 15:14:15 -0700 | [diff] [blame^] | 25 | if (fsc->mdsc == NULL || fsc->mdsc->mdsmap == NULL) |
Sage Weil | 76aa844 | 2009-10-06 11:31:14 -0700 | [diff] [blame] | 26 | return 0; |
Yehuda Sadeh | 3d14c5d | 2010-04-06 15:14:15 -0700 | [diff] [blame^] | 27 | seq_printf(s, "epoch %d\n", fsc->mdsc->mdsmap->m_epoch); |
| 28 | seq_printf(s, "root %d\n", fsc->mdsc->mdsmap->m_root); |
Sage Weil | 76aa844 | 2009-10-06 11:31:14 -0700 | [diff] [blame] | 29 | seq_printf(s, "session_timeout %d\n", |
Yehuda Sadeh | 3d14c5d | 2010-04-06 15:14:15 -0700 | [diff] [blame^] | 30 | fsc->mdsc->mdsmap->m_session_timeout); |
Sage Weil | 76aa844 | 2009-10-06 11:31:14 -0700 | [diff] [blame] | 31 | seq_printf(s, "session_autoclose %d\n", |
Yehuda Sadeh | 3d14c5d | 2010-04-06 15:14:15 -0700 | [diff] [blame^] | 32 | fsc->mdsc->mdsmap->m_session_autoclose); |
| 33 | for (i = 0; i < fsc->mdsc->mdsmap->m_max_mds; i++) { |
Sage Weil | 76aa844 | 2009-10-06 11:31:14 -0700 | [diff] [blame] | 34 | struct ceph_entity_addr *addr = |
Yehuda Sadeh | 3d14c5d | 2010-04-06 15:14:15 -0700 | [diff] [blame^] | 35 | &fsc->mdsc->mdsmap->m_info[i].addr; |
| 36 | int state = fsc->mdsc->mdsmap->m_info[i].state; |
Sage Weil | 76aa844 | 2009-10-06 11:31:14 -0700 | [diff] [blame] | 37 | |
Yehuda Sadeh | 3d14c5d | 2010-04-06 15:14:15 -0700 | [diff] [blame^] | 38 | seq_printf(s, "\tmds%d\t%s\t(%s)\n", i, |
| 39 | ceph_pr_addr(&addr->in_addr), |
Sage Weil | 76aa844 | 2009-10-06 11:31:14 -0700 | [diff] [blame] | 40 | ceph_mds_state_name(state)); |
| 41 | } |
| 42 | return 0; |
| 43 | } |
| 44 | |
Yehuda Sadeh | 3d14c5d | 2010-04-06 15:14:15 -0700 | [diff] [blame^] | 45 | /* |
| 46 | * mdsc debugfs |
| 47 | */ |
Sage Weil | 76aa844 | 2009-10-06 11:31:14 -0700 | [diff] [blame] | 48 | static int mdsc_show(struct seq_file *s, void *p) |
| 49 | { |
Yehuda Sadeh | 3d14c5d | 2010-04-06 15:14:15 -0700 | [diff] [blame^] | 50 | struct ceph_fs_client *fsc = s->private; |
| 51 | struct ceph_mds_client *mdsc = fsc->mdsc; |
Sage Weil | 44ca18f | 2010-02-15 12:08:46 -0800 | [diff] [blame] | 52 | struct ceph_mds_request *req; |
| 53 | struct rb_node *rp; |
Sage Weil | 76aa844 | 2009-10-06 11:31:14 -0700 | [diff] [blame] | 54 | int pathlen; |
| 55 | u64 pathbase; |
| 56 | char *path; |
| 57 | |
| 58 | mutex_lock(&mdsc->mutex); |
Sage Weil | 44ca18f | 2010-02-15 12:08:46 -0800 | [diff] [blame] | 59 | for (rp = rb_first(&mdsc->request_tree); rp; rp = rb_next(rp)) { |
| 60 | req = rb_entry(rp, struct ceph_mds_request, r_node); |
Sage Weil | 76aa844 | 2009-10-06 11:31:14 -0700 | [diff] [blame] | 61 | |
| 62 | if (req->r_request) |
| 63 | seq_printf(s, "%lld\tmds%d\t", req->r_tid, req->r_mds); |
| 64 | else |
| 65 | seq_printf(s, "%lld\t(no request)\t", req->r_tid); |
| 66 | |
| 67 | seq_printf(s, "%s", ceph_mds_op_name(req->r_op)); |
| 68 | |
| 69 | if (req->r_got_unsafe) |
| 70 | seq_printf(s, "\t(unsafe)"); |
| 71 | else |
| 72 | seq_printf(s, "\t"); |
| 73 | |
| 74 | if (req->r_inode) { |
| 75 | seq_printf(s, " #%llx", ceph_ino(req->r_inode)); |
| 76 | } else if (req->r_dentry) { |
| 77 | path = ceph_mdsc_build_path(req->r_dentry, &pathlen, |
| 78 | &pathbase, 0); |
Dan Carpenter | f44c389 | 2010-08-26 11:07:24 +0200 | [diff] [blame] | 79 | if (IS_ERR(path)) |
| 80 | path = NULL; |
Sage Weil | 76aa844 | 2009-10-06 11:31:14 -0700 | [diff] [blame] | 81 | spin_lock(&req->r_dentry->d_lock); |
| 82 | seq_printf(s, " #%llx/%.*s (%s)", |
| 83 | ceph_ino(req->r_dentry->d_parent->d_inode), |
| 84 | req->r_dentry->d_name.len, |
| 85 | req->r_dentry->d_name.name, |
| 86 | path ? path : ""); |
| 87 | spin_unlock(&req->r_dentry->d_lock); |
| 88 | kfree(path); |
| 89 | } else if (req->r_path1) { |
| 90 | seq_printf(s, " #%llx/%s", req->r_ino1.ino, |
| 91 | req->r_path1); |
| 92 | } |
| 93 | |
| 94 | if (req->r_old_dentry) { |
| 95 | path = ceph_mdsc_build_path(req->r_old_dentry, &pathlen, |
| 96 | &pathbase, 0); |
Dan Carpenter | f44c389 | 2010-08-26 11:07:24 +0200 | [diff] [blame] | 97 | if (IS_ERR(path)) |
| 98 | path = NULL; |
Sage Weil | 76aa844 | 2009-10-06 11:31:14 -0700 | [diff] [blame] | 99 | spin_lock(&req->r_old_dentry->d_lock); |
| 100 | seq_printf(s, " #%llx/%.*s (%s)", |
| 101 | ceph_ino(req->r_old_dentry->d_parent->d_inode), |
| 102 | req->r_old_dentry->d_name.len, |
| 103 | req->r_old_dentry->d_name.name, |
| 104 | path ? path : ""); |
| 105 | spin_unlock(&req->r_old_dentry->d_lock); |
| 106 | kfree(path); |
| 107 | } else if (req->r_path2) { |
| 108 | if (req->r_ino2.ino) |
| 109 | seq_printf(s, " #%llx/%s", req->r_ino2.ino, |
| 110 | req->r_path2); |
| 111 | else |
| 112 | seq_printf(s, " %s", req->r_path2); |
| 113 | } |
| 114 | |
| 115 | seq_printf(s, "\n"); |
| 116 | } |
| 117 | mutex_unlock(&mdsc->mutex); |
| 118 | |
| 119 | return 0; |
| 120 | } |
| 121 | |
Sage Weil | 76aa844 | 2009-10-06 11:31:14 -0700 | [diff] [blame] | 122 | static int caps_show(struct seq_file *s, void *p) |
| 123 | { |
Yehuda Sadeh | 3d14c5d | 2010-04-06 15:14:15 -0700 | [diff] [blame^] | 124 | struct ceph_fs_client *fsc = s->private; |
Sage Weil | 85ccce4 | 2010-02-17 10:02:43 -0800 | [diff] [blame] | 125 | int total, avail, used, reserved, min; |
Sage Weil | 76aa844 | 2009-10-06 11:31:14 -0700 | [diff] [blame] | 126 | |
Yehuda Sadeh | 3d14c5d | 2010-04-06 15:14:15 -0700 | [diff] [blame^] | 127 | ceph_reservation_status(fsc, &total, &avail, &used, &reserved, &min); |
Sage Weil | 76aa844 | 2009-10-06 11:31:14 -0700 | [diff] [blame] | 128 | seq_printf(s, "total\t\t%d\n" |
Sage Weil | 85ccce4 | 2010-02-17 10:02:43 -0800 | [diff] [blame] | 129 | "avail\t\t%d\n" |
| 130 | "used\t\t%d\n" |
| 131 | "reserved\t%d\n" |
| 132 | "min\t%d\n", |
| 133 | total, avail, used, reserved, min); |
Sage Weil | 76aa844 | 2009-10-06 11:31:14 -0700 | [diff] [blame] | 134 | return 0; |
| 135 | } |
| 136 | |
| 137 | static int dentry_lru_show(struct seq_file *s, void *ptr) |
| 138 | { |
Yehuda Sadeh | 3d14c5d | 2010-04-06 15:14:15 -0700 | [diff] [blame^] | 139 | struct ceph_fs_client *fsc = s->private; |
| 140 | struct ceph_mds_client *mdsc = fsc->mdsc; |
Sage Weil | 76aa844 | 2009-10-06 11:31:14 -0700 | [diff] [blame] | 141 | struct ceph_dentry_info *di; |
| 142 | |
| 143 | spin_lock(&mdsc->dentry_lru_lock); |
| 144 | list_for_each_entry(di, &mdsc->dentry_lru, lru) { |
| 145 | struct dentry *dentry = di->dentry; |
| 146 | seq_printf(s, "%p %p\t%.*s\n", |
| 147 | di, dentry, dentry->d_name.len, dentry->d_name.name); |
| 148 | } |
| 149 | spin_unlock(&mdsc->dentry_lru_lock); |
| 150 | |
| 151 | return 0; |
| 152 | } |
| 153 | |
Yehuda Sadeh | 3d14c5d | 2010-04-06 15:14:15 -0700 | [diff] [blame^] | 154 | CEPH_DEFINE_SHOW_FUNC(mdsmap_show) |
| 155 | CEPH_DEFINE_SHOW_FUNC(mdsc_show) |
| 156 | CEPH_DEFINE_SHOW_FUNC(caps_show) |
| 157 | CEPH_DEFINE_SHOW_FUNC(dentry_lru_show) |
Sage Weil | 76aa844 | 2009-10-06 11:31:14 -0700 | [diff] [blame] | 158 | |
Sage Weil | 76aa844 | 2009-10-06 11:31:14 -0700 | [diff] [blame] | 159 | |
Yehuda Sadeh | 3d14c5d | 2010-04-06 15:14:15 -0700 | [diff] [blame^] | 160 | /* |
| 161 | * debugfs |
| 162 | */ |
Yehuda Sadeh | 2baba25 | 2009-12-18 13:51:57 -0800 | [diff] [blame] | 163 | static int congestion_kb_set(void *data, u64 val) |
| 164 | { |
Yehuda Sadeh | 3d14c5d | 2010-04-06 15:14:15 -0700 | [diff] [blame^] | 165 | struct ceph_fs_client *fsc = (struct ceph_fs_client *)data; |
Yehuda Sadeh | 2baba25 | 2009-12-18 13:51:57 -0800 | [diff] [blame] | 166 | |
Yehuda Sadeh | 3d14c5d | 2010-04-06 15:14:15 -0700 | [diff] [blame^] | 167 | fsc->mount_options->congestion_kb = (int)val; |
Yehuda Sadeh | 2baba25 | 2009-12-18 13:51:57 -0800 | [diff] [blame] | 168 | return 0; |
| 169 | } |
| 170 | |
| 171 | static int congestion_kb_get(void *data, u64 *val) |
| 172 | { |
Yehuda Sadeh | 3d14c5d | 2010-04-06 15:14:15 -0700 | [diff] [blame^] | 173 | struct ceph_fs_client *fsc = (struct ceph_fs_client *)data; |
Yehuda Sadeh | 2baba25 | 2009-12-18 13:51:57 -0800 | [diff] [blame] | 174 | |
Yehuda Sadeh | 3d14c5d | 2010-04-06 15:14:15 -0700 | [diff] [blame^] | 175 | *val = (u64)fsc->mount_options->congestion_kb; |
Yehuda Sadeh | 2baba25 | 2009-12-18 13:51:57 -0800 | [diff] [blame] | 176 | return 0; |
| 177 | } |
| 178 | |
Yehuda Sadeh | 2baba25 | 2009-12-18 13:51:57 -0800 | [diff] [blame] | 179 | DEFINE_SIMPLE_ATTRIBUTE(congestion_kb_fops, congestion_kb_get, |
| 180 | congestion_kb_set, "%llu\n"); |
| 181 | |
Yehuda Sadeh | 3d14c5d | 2010-04-06 15:14:15 -0700 | [diff] [blame^] | 182 | |
| 183 | void ceph_fs_debugfs_cleanup(struct ceph_fs_client *fsc) |
Sage Weil | 76aa844 | 2009-10-06 11:31:14 -0700 | [diff] [blame] | 184 | { |
Yehuda Sadeh | 3d14c5d | 2010-04-06 15:14:15 -0700 | [diff] [blame^] | 185 | dout("ceph_fs_debugfs_cleanup\n"); |
| 186 | debugfs_remove(fsc->debugfs_bdi); |
| 187 | debugfs_remove(fsc->debugfs_congestion_kb); |
| 188 | debugfs_remove(fsc->debugfs_mdsmap); |
| 189 | debugfs_remove(fsc->debugfs_caps); |
| 190 | debugfs_remove(fsc->debugfs_mdsc); |
| 191 | debugfs_remove(fsc->debugfs_dentry_lru); |
Sage Weil | 76aa844 | 2009-10-06 11:31:14 -0700 | [diff] [blame] | 192 | } |
| 193 | |
Yehuda Sadeh | 3d14c5d | 2010-04-06 15:14:15 -0700 | [diff] [blame^] | 194 | int ceph_fs_debugfs_init(struct ceph_fs_client *fsc) |
Sage Weil | 76aa844 | 2009-10-06 11:31:14 -0700 | [diff] [blame] | 195 | { |
Yehuda Sadeh | 3d14c5d | 2010-04-06 15:14:15 -0700 | [diff] [blame^] | 196 | char name[100]; |
| 197 | int err = -ENOMEM; |
Sage Weil | 76aa844 | 2009-10-06 11:31:14 -0700 | [diff] [blame] | 198 | |
Yehuda Sadeh | 3d14c5d | 2010-04-06 15:14:15 -0700 | [diff] [blame^] | 199 | dout("ceph_fs_debugfs_init\n"); |
| 200 | fsc->debugfs_congestion_kb = |
Sage Weil | 213c99e | 2010-08-03 10:25:11 -0700 | [diff] [blame] | 201 | debugfs_create_file("writeback_congestion_kb", |
| 202 | 0600, |
Yehuda Sadeh | 3d14c5d | 2010-04-06 15:14:15 -0700 | [diff] [blame^] | 203 | fsc->client->debugfs_dir, |
| 204 | fsc, |
Sage Weil | 213c99e | 2010-08-03 10:25:11 -0700 | [diff] [blame] | 205 | &congestion_kb_fops); |
Yehuda Sadeh | 3d14c5d | 2010-04-06 15:14:15 -0700 | [diff] [blame^] | 206 | if (!fsc->debugfs_congestion_kb) |
Yehuda Sadeh | 2baba25 | 2009-12-18 13:51:57 -0800 | [diff] [blame] | 207 | goto out; |
| 208 | |
Yehuda Sadeh | 3d14c5d | 2010-04-06 15:14:15 -0700 | [diff] [blame^] | 209 | dout("a\n"); |
| 210 | |
| 211 | snprintf(name, sizeof(name), "../../bdi/%s", |
| 212 | dev_name(fsc->backing_dev_info.dev)); |
| 213 | fsc->debugfs_bdi = |
| 214 | debugfs_create_symlink("bdi", |
| 215 | fsc->client->debugfs_dir, |
| 216 | name); |
| 217 | if (!fsc->debugfs_bdi) |
| 218 | goto out; |
| 219 | |
| 220 | dout("b\n"); |
| 221 | fsc->debugfs_mdsmap = debugfs_create_file("mdsmap", |
| 222 | 0600, |
| 223 | fsc->client->debugfs_dir, |
| 224 | fsc, |
| 225 | &mdsmap_show_fops); |
| 226 | if (!fsc->debugfs_mdsmap) |
| 227 | goto out; |
| 228 | |
| 229 | dout("ca\n"); |
| 230 | fsc->debugfs_mdsc = debugfs_create_file("mdsc", |
| 231 | 0600, |
| 232 | fsc->client->debugfs_dir, |
| 233 | fsc, |
| 234 | &mdsc_show_fops); |
| 235 | if (!fsc->debugfs_mdsc) |
| 236 | goto out; |
| 237 | |
| 238 | dout("da\n"); |
| 239 | fsc->debugfs_caps = debugfs_create_file("caps", |
| 240 | 0400, |
| 241 | fsc->client->debugfs_dir, |
| 242 | fsc, |
| 243 | &caps_show_fops); |
| 244 | if (!fsc->debugfs_caps) |
| 245 | goto out; |
| 246 | |
| 247 | dout("ea\n"); |
| 248 | fsc->debugfs_dentry_lru = debugfs_create_file("dentry_lru", |
| 249 | 0600, |
| 250 | fsc->client->debugfs_dir, |
| 251 | fsc, |
| 252 | &dentry_lru_show_fops); |
| 253 | if (!fsc->debugfs_dentry_lru) |
| 254 | goto out; |
Sage Weil | 06edf04 | 2009-12-15 14:44:32 -0800 | [diff] [blame] | 255 | |
Sage Weil | 76aa844 | 2009-10-06 11:31:14 -0700 | [diff] [blame] | 256 | return 0; |
| 257 | |
| 258 | out: |
Yehuda Sadeh | 3d14c5d | 2010-04-06 15:14:15 -0700 | [diff] [blame^] | 259 | ceph_fs_debugfs_cleanup(fsc); |
| 260 | return err; |
Sage Weil | 76aa844 | 2009-10-06 11:31:14 -0700 | [diff] [blame] | 261 | } |
| 262 | |
Sage Weil | 76aa844 | 2009-10-06 11:31:14 -0700 | [diff] [blame] | 263 | |
Sage Weil | 213c99e | 2010-08-03 10:25:11 -0700 | [diff] [blame] | 264 | #else /* CONFIG_DEBUG_FS */ |
Sage Weil | 039934b | 2009-11-12 15:05:52 -0800 | [diff] [blame] | 265 | |
Yehuda Sadeh | 3d14c5d | 2010-04-06 15:14:15 -0700 | [diff] [blame^] | 266 | int ceph_fs_debugfs_init(struct ceph_fs_client *fsc) |
Sage Weil | 039934b | 2009-11-12 15:05:52 -0800 | [diff] [blame] | 267 | { |
| 268 | return 0; |
| 269 | } |
| 270 | |
Yehuda Sadeh | 3d14c5d | 2010-04-06 15:14:15 -0700 | [diff] [blame^] | 271 | void ceph_fs_debugfs_cleanup(struct ceph_fs_client *fsc) |
Sage Weil | 039934b | 2009-11-12 15:05:52 -0800 | [diff] [blame] | 272 | { |
| 273 | } |
| 274 | |
Sage Weil | 213c99e | 2010-08-03 10:25:11 -0700 | [diff] [blame] | 275 | #endif /* CONFIG_DEBUG_FS */ |