]>
Commit | Line | Data |
---|---|---|
3d14c5d2 | 1 | #include <linux/ceph/ceph_debug.h> |
76aa844d | 2 | |
06edf046 | 3 | #include <linux/device.h> |
5a0e3ad6 | 4 | #include <linux/slab.h> |
76aa844d SW |
5 | #include <linux/module.h> |
6 | #include <linux/ctype.h> | |
7 | #include <linux/debugfs.h> | |
8 | #include <linux/seq_file.h> | |
9 | ||
3d14c5d2 YS |
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> | |
76aa844d | 14 | |
039934b8 SW |
15 | #ifdef CONFIG_DEBUG_FS |
16 | ||
3d14c5d2 YS |
17 | #include "super.h" |
18 | #include "mds_client.h" | |
76aa844d SW |
19 | |
20 | static int mdsmap_show(struct seq_file *s, void *p) | |
21 | { | |
22 | int i; | |
3d14c5d2 | 23 | struct ceph_fs_client *fsc = s->private; |
76aa844d | 24 | |
3d14c5d2 | 25 | if (fsc->mdsc == NULL || fsc->mdsc->mdsmap == NULL) |
76aa844d | 26 | return 0; |
3d14c5d2 YS |
27 | seq_printf(s, "epoch %d\n", fsc->mdsc->mdsmap->m_epoch); |
28 | seq_printf(s, "root %d\n", fsc->mdsc->mdsmap->m_root); | |
76aa844d | 29 | seq_printf(s, "session_timeout %d\n", |
3d14c5d2 | 30 | fsc->mdsc->mdsmap->m_session_timeout); |
76aa844d | 31 | seq_printf(s, "session_autoclose %d\n", |
3d14c5d2 YS |
32 | fsc->mdsc->mdsmap->m_session_autoclose); |
33 | for (i = 0; i < fsc->mdsc->mdsmap->m_max_mds; i++) { | |
76aa844d | 34 | struct ceph_entity_addr *addr = |
3d14c5d2 YS |
35 | &fsc->mdsc->mdsmap->m_info[i].addr; |
36 | int state = fsc->mdsc->mdsmap->m_info[i].state; | |
76aa844d | 37 | |
3d14c5d2 YS |
38 | seq_printf(s, "\tmds%d\t%s\t(%s)\n", i, |
39 | ceph_pr_addr(&addr->in_addr), | |
76aa844d SW |
40 | ceph_mds_state_name(state)); |
41 | } | |
42 | return 0; | |
43 | } | |
44 | ||
3d14c5d2 YS |
45 | /* |
46 | * mdsc debugfs | |
47 | */ | |
76aa844d SW |
48 | static int mdsc_show(struct seq_file *s, void *p) |
49 | { | |
3d14c5d2 YS |
50 | struct ceph_fs_client *fsc = s->private; |
51 | struct ceph_mds_client *mdsc = fsc->mdsc; | |
44ca18f2 SW |
52 | struct ceph_mds_request *req; |
53 | struct rb_node *rp; | |
76aa844d SW |
54 | int pathlen; |
55 | u64 pathbase; | |
56 | char *path; | |
57 | ||
58 | mutex_lock(&mdsc->mutex); | |
44ca18f2 SW |
59 | for (rp = rb_first(&mdsc->request_tree); rp; rp = rb_next(rp)) { |
60 | req = rb_entry(rp, struct ceph_mds_request, r_node); | |
76aa844d SW |
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); | |
f44c3890 DC |
79 | if (IS_ERR(path)) |
80 | path = NULL; | |
76aa844d SW |
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); | |
f44c3890 DC |
97 | if (IS_ERR(path)) |
98 | path = NULL; | |
76aa844d SW |
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 | ||
76aa844d SW |
122 | static int caps_show(struct seq_file *s, void *p) |
123 | { | |
3d14c5d2 | 124 | struct ceph_fs_client *fsc = s->private; |
85ccce43 | 125 | int total, avail, used, reserved, min; |
76aa844d | 126 | |
3d14c5d2 | 127 | ceph_reservation_status(fsc, &total, &avail, &used, &reserved, &min); |
76aa844d | 128 | seq_printf(s, "total\t\t%d\n" |
85ccce43 SW |
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); | |
76aa844d SW |
134 | return 0; |
135 | } | |
136 | ||
137 | static int dentry_lru_show(struct seq_file *s, void *ptr) | |
138 | { | |
3d14c5d2 YS |
139 | struct ceph_fs_client *fsc = s->private; |
140 | struct ceph_mds_client *mdsc = fsc->mdsc; | |
76aa844d SW |
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 | ||
3d14c5d2 YS |
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) | |
158 | ||
76aa844d | 159 | |
3d14c5d2 YS |
160 | /* |
161 | * debugfs | |
162 | */ | |
2baba250 YS |
163 | static int congestion_kb_set(void *data, u64 val) |
164 | { | |
3d14c5d2 | 165 | struct ceph_fs_client *fsc = (struct ceph_fs_client *)data; |
2baba250 | 166 | |
3d14c5d2 | 167 | fsc->mount_options->congestion_kb = (int)val; |
2baba250 YS |
168 | return 0; |
169 | } | |
170 | ||
171 | static int congestion_kb_get(void *data, u64 *val) | |
172 | { | |
3d14c5d2 | 173 | struct ceph_fs_client *fsc = (struct ceph_fs_client *)data; |
2baba250 | 174 | |
3d14c5d2 | 175 | *val = (u64)fsc->mount_options->congestion_kb; |
2baba250 YS |
176 | return 0; |
177 | } | |
178 | ||
2baba250 YS |
179 | DEFINE_SIMPLE_ATTRIBUTE(congestion_kb_fops, congestion_kb_get, |
180 | congestion_kb_set, "%llu\n"); | |
181 | ||
76aa844d | 182 | |
3d14c5d2 | 183 | void ceph_fs_debugfs_cleanup(struct ceph_fs_client *fsc) |
76aa844d | 184 | { |
3d14c5d2 YS |
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); | |
76aa844d SW |
192 | } |
193 | ||
3d14c5d2 | 194 | int ceph_fs_debugfs_init(struct ceph_fs_client *fsc) |
76aa844d | 195 | { |
3d14c5d2 YS |
196 | char name[100]; |
197 | int err = -ENOMEM; | |
76aa844d | 198 | |
3d14c5d2 YS |
199 | dout("ceph_fs_debugfs_init\n"); |
200 | fsc->debugfs_congestion_kb = | |
201 | debugfs_create_file("writeback_congestion_kb", | |
202 | 0600, | |
203 | fsc->client->debugfs_dir, | |
204 | fsc, | |
205 | &congestion_kb_fops); | |
206 | if (!fsc->debugfs_congestion_kb) | |
76aa844d SW |
207 | goto out; |
208 | ||
3d14c5d2 | 209 | dout("a\n"); |
76aa844d | 210 | |
3d14c5d2 YS |
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) | |
76aa844d SW |
218 | goto out; |
219 | ||
3d14c5d2 YS |
220 | dout("b\n"); |
221 | fsc->debugfs_mdsmap = debugfs_create_file("mdsmap", | |
76aa844d | 222 | 0600, |
3d14c5d2 YS |
223 | fsc->client->debugfs_dir, |
224 | fsc, | |
76aa844d | 225 | &mdsmap_show_fops); |
3d14c5d2 | 226 | if (!fsc->debugfs_mdsmap) |
76aa844d SW |
227 | goto out; |
228 | ||
3d14c5d2 YS |
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) | |
76aa844d SW |
236 | goto out; |
237 | ||
3d14c5d2 YS |
238 | dout("da\n"); |
239 | fsc->debugfs_caps = debugfs_create_file("caps", | |
76aa844d | 240 | 0400, |
3d14c5d2 YS |
241 | fsc->client->debugfs_dir, |
242 | fsc, | |
76aa844d | 243 | &caps_show_fops); |
3d14c5d2 | 244 | if (!fsc->debugfs_caps) |
76aa844d SW |
245 | goto out; |
246 | ||
3d14c5d2 YS |
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) | |
2baba250 YS |
254 | goto out; |
255 | ||
76aa844d SW |
256 | return 0; |
257 | ||
258 | out: | |
3d14c5d2 YS |
259 | ceph_fs_debugfs_cleanup(fsc); |
260 | return err; | |
76aa844d SW |
261 | } |
262 | ||
76aa844d | 263 | |
213c99ee | 264 | #else /* CONFIG_DEBUG_FS */ |
039934b8 | 265 | |
3d14c5d2 | 266 | int ceph_fs_debugfs_init(struct ceph_fs_client *fsc) |
039934b8 SW |
267 | { |
268 | return 0; | |
269 | } | |
270 | ||
3d14c5d2 | 271 | void ceph_fs_debugfs_cleanup(struct ceph_fs_client *fsc) |
039934b8 SW |
272 | { |
273 | } | |
274 | ||
213c99ee | 275 | #endif /* CONFIG_DEBUG_FS */ |