]>
Commit | Line | Data |
---|---|---|
e14748e8 SF |
1 | /* |
2 | * Copyright (C) 2005-2016 Junjiro R. Okajima | |
3 | * | |
4 | * This program, aufs is free software; you can redistribute it and/or modify | |
5 | * it under the terms of the GNU General Public License as published by | |
6 | * the Free Software Foundation; either version 2 of the License, or | |
7 | * (at your option) any later version. | |
8 | * | |
9 | * This program is distributed in the hope that it will be useful, | |
10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
12 | * GNU General Public License for more details. | |
13 | * | |
14 | * You should have received a copy of the GNU General Public License | |
15 | * along with this program. If not, see <http://www.gnu.org/licenses/>. | |
16 | */ | |
17 | ||
18 | /* | |
19 | * debug print functions | |
20 | */ | |
21 | ||
22 | #include "aufs.h" | |
23 | ||
24 | /* Returns 0, or -errno. arg is in kp->arg. */ | |
25 | static int param_atomic_t_set(const char *val, const struct kernel_param *kp) | |
26 | { | |
27 | int err, n; | |
28 | ||
29 | err = kstrtoint(val, 0, &n); | |
30 | if (!err) { | |
31 | if (n > 0) | |
32 | au_debug_on(); | |
33 | else | |
34 | au_debug_off(); | |
35 | } | |
36 | return err; | |
37 | } | |
38 | ||
39 | /* Returns length written or -errno. Buffer is 4k (ie. be short!) */ | |
40 | static int param_atomic_t_get(char *buffer, const struct kernel_param *kp) | |
41 | { | |
42 | atomic_t *a; | |
43 | ||
44 | a = kp->arg; | |
45 | return sprintf(buffer, "%d", atomic_read(a)); | |
46 | } | |
47 | ||
48 | static struct kernel_param_ops param_ops_atomic_t = { | |
49 | .set = param_atomic_t_set, | |
50 | .get = param_atomic_t_get | |
51 | /* void (*free)(void *arg) */ | |
52 | }; | |
53 | ||
54 | atomic_t aufs_debug = ATOMIC_INIT(0); | |
55 | MODULE_PARM_DESC(debug, "debug print"); | |
56 | module_param_named(debug, aufs_debug, atomic_t, S_IRUGO | S_IWUSR | S_IWGRP); | |
57 | ||
58 | DEFINE_MUTEX(au_dbg_mtx); /* just to serialize the dbg msgs */ | |
59 | char *au_plevel = KERN_DEBUG; | |
60 | #define dpri(fmt, ...) do { \ | |
61 | if ((au_plevel \ | |
62 | && strcmp(au_plevel, KERN_DEBUG)) \ | |
63 | || au_debug_test()) \ | |
64 | printk("%s" fmt, au_plevel, ##__VA_ARGS__); \ | |
65 | } while (0) | |
66 | ||
67 | /* ---------------------------------------------------------------------- */ | |
68 | ||
69 | void au_dpri_whlist(struct au_nhash *whlist) | |
70 | { | |
71 | unsigned long ul, n; | |
72 | struct hlist_head *head; | |
73 | struct au_vdir_wh *pos; | |
74 | ||
75 | n = whlist->nh_num; | |
76 | head = whlist->nh_head; | |
77 | for (ul = 0; ul < n; ul++) { | |
78 | hlist_for_each_entry(pos, head, wh_hash) | |
79 | dpri("b%d, %.*s, %d\n", | |
80 | pos->wh_bindex, | |
81 | pos->wh_str.len, pos->wh_str.name, | |
82 | pos->wh_str.len); | |
83 | head++; | |
84 | } | |
85 | } | |
86 | ||
87 | void au_dpri_vdir(struct au_vdir *vdir) | |
88 | { | |
89 | unsigned long ul; | |
90 | union au_vdir_deblk_p p; | |
91 | unsigned char *o; | |
92 | ||
93 | if (!vdir || IS_ERR(vdir)) { | |
94 | dpri("err %ld\n", PTR_ERR(vdir)); | |
95 | return; | |
96 | } | |
97 | ||
98 | dpri("deblk %u, nblk %lu, deblk %p, last{%lu, %p}, ver %lu\n", | |
99 | vdir->vd_deblk_sz, vdir->vd_nblk, vdir->vd_deblk, | |
100 | vdir->vd_last.ul, vdir->vd_last.p.deblk, vdir->vd_version); | |
101 | for (ul = 0; ul < vdir->vd_nblk; ul++) { | |
102 | p.deblk = vdir->vd_deblk[ul]; | |
103 | o = p.deblk; | |
104 | dpri("[%lu]: %p\n", ul, o); | |
105 | } | |
106 | } | |
107 | ||
108 | static int do_pri_inode(aufs_bindex_t bindex, struct inode *inode, int hn, | |
109 | struct dentry *wh) | |
110 | { | |
111 | char *n = NULL; | |
112 | int l = 0; | |
113 | ||
114 | if (!inode || IS_ERR(inode)) { | |
115 | dpri("i%d: err %ld\n", bindex, PTR_ERR(inode)); | |
116 | return -1; | |
117 | } | |
118 | ||
119 | /* the type of i_blocks depends upon CONFIG_LBDAF */ | |
120 | BUILD_BUG_ON(sizeof(inode->i_blocks) != sizeof(unsigned long) | |
121 | && sizeof(inode->i_blocks) != sizeof(u64)); | |
122 | if (wh) { | |
123 | n = (void *)wh->d_name.name; | |
124 | l = wh->d_name.len; | |
125 | } | |
126 | ||
127 | dpri("i%d: %p, i%lu, %s, cnt %d, nl %u, 0%o, sz %llu, blk %llu," | |
128 | " hn %d, ct %lld, np %lu, st 0x%lx, f 0x%x, v %llu, g %x%s%.*s\n", | |
129 | bindex, inode, | |
130 | inode->i_ino, inode->i_sb ? au_sbtype(inode->i_sb) : "??", | |
131 | atomic_read(&inode->i_count), inode->i_nlink, inode->i_mode, | |
132 | i_size_read(inode), (unsigned long long)inode->i_blocks, | |
133 | hn, (long long)timespec_to_ns(&inode->i_ctime) & 0x0ffff, | |
134 | inode->i_mapping ? inode->i_mapping->nrpages : 0, | |
135 | inode->i_state, inode->i_flags, inode->i_version, | |
136 | inode->i_generation, | |
137 | l ? ", wh " : "", l, n); | |
138 | return 0; | |
139 | } | |
140 | ||
141 | void au_dpri_inode(struct inode *inode) | |
142 | { | |
143 | struct au_iinfo *iinfo; | |
144 | struct au_hinode *hi; | |
145 | aufs_bindex_t bindex; | |
146 | int err, hn; | |
147 | ||
148 | err = do_pri_inode(-1, inode, -1, NULL); | |
149 | if (err || !au_test_aufs(inode->i_sb) || au_is_bad_inode(inode)) | |
150 | return; | |
151 | ||
152 | iinfo = au_ii(inode); | |
153 | dpri("i-1: btop %d, bbot %d, gen %d\n", | |
154 | iinfo->ii_btop, iinfo->ii_bbot, au_iigen(inode, NULL)); | |
155 | if (iinfo->ii_btop < 0) | |
156 | return; | |
157 | hn = 0; | |
158 | for (bindex = iinfo->ii_btop; bindex <= iinfo->ii_bbot; bindex++) { | |
159 | hi = au_hinode(iinfo, bindex); | |
160 | hn = !!au_hn(hi); | |
161 | do_pri_inode(bindex, hi->hi_inode, hn, hi->hi_whdentry); | |
162 | } | |
163 | } | |
164 | ||
165 | void au_dpri_dalias(struct inode *inode) | |
166 | { | |
167 | struct dentry *d; | |
168 | ||
169 | spin_lock(&inode->i_lock); | |
170 | hlist_for_each_entry(d, &inode->i_dentry, d_u.d_alias) | |
171 | au_dpri_dentry(d); | |
172 | spin_unlock(&inode->i_lock); | |
173 | } | |
174 | ||
175 | static int do_pri_dentry(aufs_bindex_t bindex, struct dentry *dentry) | |
176 | { | |
177 | struct dentry *wh = NULL; | |
178 | int hn; | |
179 | struct inode *inode; | |
180 | struct au_iinfo *iinfo; | |
181 | struct au_hinode *hi; | |
182 | ||
183 | if (!dentry || IS_ERR(dentry)) { | |
184 | dpri("d%d: err %ld\n", bindex, PTR_ERR(dentry)); | |
185 | return -1; | |
186 | } | |
187 | /* do not call dget_parent() here */ | |
188 | /* note: access d_xxx without d_lock */ | |
189 | dpri("d%d: %p, %pd2?, %s, cnt %d, flags 0x%x, %shashed\n", | |
190 | bindex, dentry, dentry, | |
191 | dentry->d_sb ? au_sbtype(dentry->d_sb) : "??", | |
192 | au_dcount(dentry), dentry->d_flags, | |
193 | d_unhashed(dentry) ? "un" : ""); | |
194 | hn = -1; | |
195 | inode = NULL; | |
196 | if (d_is_positive(dentry)) | |
197 | inode = d_inode(dentry); | |
198 | if (inode | |
199 | && au_test_aufs(dentry->d_sb) | |
200 | && bindex >= 0 | |
201 | && !au_is_bad_inode(inode)) { | |
202 | iinfo = au_ii(inode); | |
203 | hi = au_hinode(iinfo, bindex); | |
204 | hn = !!au_hn(hi); | |
205 | wh = hi->hi_whdentry; | |
206 | } | |
207 | do_pri_inode(bindex, inode, hn, wh); | |
208 | return 0; | |
209 | } | |
210 | ||
211 | void au_dpri_dentry(struct dentry *dentry) | |
212 | { | |
213 | struct au_dinfo *dinfo; | |
214 | aufs_bindex_t bindex; | |
215 | int err; | |
216 | ||
217 | err = do_pri_dentry(-1, dentry); | |
218 | if (err || !au_test_aufs(dentry->d_sb)) | |
219 | return; | |
220 | ||
221 | dinfo = au_di(dentry); | |
222 | if (!dinfo) | |
223 | return; | |
224 | dpri("d-1: btop %d, bbot %d, bwh %d, bdiropq %d, gen %d, tmp %d\n", | |
225 | dinfo->di_btop, dinfo->di_bbot, | |
226 | dinfo->di_bwh, dinfo->di_bdiropq, au_digen(dentry), | |
227 | dinfo->di_tmpfile); | |
228 | if (dinfo->di_btop < 0) | |
229 | return; | |
230 | for (bindex = dinfo->di_btop; bindex <= dinfo->di_bbot; bindex++) | |
231 | do_pri_dentry(bindex, au_hdentry(dinfo, bindex)->hd_dentry); | |
232 | } | |
233 | ||
234 | static int do_pri_file(aufs_bindex_t bindex, struct file *file) | |
235 | { | |
236 | char a[32]; | |
237 | ||
238 | if (!file || IS_ERR(file)) { | |
239 | dpri("f%d: err %ld\n", bindex, PTR_ERR(file)); | |
240 | return -1; | |
241 | } | |
242 | a[0] = 0; | |
243 | if (bindex < 0 | |
244 | && !IS_ERR_OR_NULL(file->f_path.dentry) | |
245 | && au_test_aufs(file->f_path.dentry->d_sb) | |
246 | && au_fi(file)) | |
247 | snprintf(a, sizeof(a), ", gen %d, mmapped %d", | |
248 | au_figen(file), atomic_read(&au_fi(file)->fi_mmapped)); | |
249 | dpri("f%d: mode 0x%x, flags 0%o, cnt %ld, v %llu, pos %llu%s\n", | |
250 | bindex, file->f_mode, file->f_flags, (long)file_count(file), | |
251 | file->f_version, file->f_pos, a); | |
252 | if (!IS_ERR_OR_NULL(file->f_path.dentry)) | |
253 | do_pri_dentry(bindex, file->f_path.dentry); | |
254 | return 0; | |
255 | } | |
256 | ||
257 | void au_dpri_file(struct file *file) | |
258 | { | |
259 | struct au_finfo *finfo; | |
260 | struct au_fidir *fidir; | |
261 | struct au_hfile *hfile; | |
262 | aufs_bindex_t bindex; | |
263 | int err; | |
264 | ||
265 | err = do_pri_file(-1, file); | |
266 | if (err | |
267 | || IS_ERR_OR_NULL(file->f_path.dentry) | |
268 | || !au_test_aufs(file->f_path.dentry->d_sb)) | |
269 | return; | |
270 | ||
271 | finfo = au_fi(file); | |
272 | if (!finfo) | |
273 | return; | |
274 | if (finfo->fi_btop < 0) | |
275 | return; | |
276 | fidir = finfo->fi_hdir; | |
277 | if (!fidir) | |
278 | do_pri_file(finfo->fi_btop, finfo->fi_htop.hf_file); | |
279 | else | |
280 | for (bindex = finfo->fi_btop; | |
281 | bindex >= 0 && bindex <= fidir->fd_bbot; | |
282 | bindex++) { | |
283 | hfile = fidir->fd_hfile + bindex; | |
284 | do_pri_file(bindex, hfile ? hfile->hf_file : NULL); | |
285 | } | |
286 | } | |
287 | ||
288 | static int do_pri_br(aufs_bindex_t bindex, struct au_branch *br) | |
289 | { | |
290 | struct vfsmount *mnt; | |
291 | struct super_block *sb; | |
292 | ||
293 | if (!br || IS_ERR(br)) | |
294 | goto out; | |
295 | mnt = au_br_mnt(br); | |
296 | if (!mnt || IS_ERR(mnt)) | |
297 | goto out; | |
298 | sb = mnt->mnt_sb; | |
299 | if (!sb || IS_ERR(sb)) | |
300 | goto out; | |
301 | ||
302 | dpri("s%d: {perm 0x%x, id %d, cnt %lld, wbr %p}, " | |
303 | "%s, dev 0x%02x%02x, flags 0x%lx, cnt %d, active %d, " | |
304 | "xino %d\n", | |
305 | bindex, br->br_perm, br->br_id, au_br_count(br), | |
306 | br->br_wbr, au_sbtype(sb), MAJOR(sb->s_dev), MINOR(sb->s_dev), | |
307 | sb->s_flags, sb->s_count, | |
308 | atomic_read(&sb->s_active), !!br->br_xino.xi_file); | |
309 | return 0; | |
310 | ||
311 | out: | |
312 | dpri("s%d: err %ld\n", bindex, PTR_ERR(br)); | |
313 | return -1; | |
314 | } | |
315 | ||
316 | void au_dpri_sb(struct super_block *sb) | |
317 | { | |
318 | struct au_sbinfo *sbinfo; | |
319 | aufs_bindex_t bindex; | |
320 | int err; | |
321 | /* to reuduce stack size */ | |
322 | struct { | |
323 | struct vfsmount mnt; | |
324 | struct au_branch fake; | |
325 | } *a; | |
326 | ||
327 | /* this function can be called from magic sysrq */ | |
328 | a = kzalloc(sizeof(*a), GFP_ATOMIC); | |
329 | if (unlikely(!a)) { | |
330 | dpri("no memory\n"); | |
331 | return; | |
332 | } | |
333 | ||
334 | a->mnt.mnt_sb = sb; | |
335 | a->fake.br_path.mnt = &a->mnt; | |
336 | au_br_count_init(&a->fake); | |
337 | err = do_pri_br(-1, &a->fake); | |
338 | au_br_count_fin(&a->fake); | |
339 | au_delayed_kfree(a); | |
340 | dpri("dev 0x%x\n", sb->s_dev); | |
341 | if (err || !au_test_aufs(sb)) | |
342 | return; | |
343 | ||
344 | sbinfo = au_sbi(sb); | |
345 | if (!sbinfo) | |
346 | return; | |
347 | dpri("nw %d, gen %u, kobj %d\n", | |
348 | atomic_read(&sbinfo->si_nowait.nw_len), sbinfo->si_generation, | |
349 | atomic_read(&sbinfo->si_kobj.kref.refcount)); | |
350 | for (bindex = 0; bindex <= sbinfo->si_bbot; bindex++) | |
351 | do_pri_br(bindex, sbinfo->si_branch[0 + bindex]); | |
352 | } | |
353 | ||
354 | /* ---------------------------------------------------------------------- */ | |
355 | ||
356 | void __au_dbg_verify_dinode(struct dentry *dentry, const char *func, int line) | |
357 | { | |
358 | struct inode *h_inode, *inode = d_inode(dentry); | |
359 | struct dentry *h_dentry; | |
360 | aufs_bindex_t bindex, bbot, bi; | |
361 | ||
362 | if (!inode /* || au_di(dentry)->di_lsc == AuLsc_DI_TMP */) | |
363 | return; | |
364 | ||
365 | bbot = au_dbbot(dentry); | |
366 | bi = au_ibbot(inode); | |
367 | if (bi < bbot) | |
368 | bbot = bi; | |
369 | bindex = au_dbtop(dentry); | |
370 | bi = au_ibtop(inode); | |
371 | if (bi > bindex) | |
372 | bindex = bi; | |
373 | ||
374 | for (; bindex <= bbot; bindex++) { | |
375 | h_dentry = au_h_dptr(dentry, bindex); | |
376 | if (!h_dentry) | |
377 | continue; | |
378 | h_inode = au_h_iptr(inode, bindex); | |
379 | if (unlikely(h_inode != d_inode(h_dentry))) { | |
380 | au_debug_on(); | |
381 | AuDbg("b%d, %s:%d\n", bindex, func, line); | |
382 | AuDbgDentry(dentry); | |
383 | AuDbgInode(inode); | |
384 | au_debug_off(); | |
385 | BUG(); | |
386 | } | |
387 | } | |
388 | } | |
389 | ||
390 | void au_dbg_verify_gen(struct dentry *parent, unsigned int sigen) | |
391 | { | |
392 | int err, i, j; | |
393 | struct au_dcsub_pages dpages; | |
394 | struct au_dpage *dpage; | |
395 | struct dentry **dentries; | |
396 | ||
397 | err = au_dpages_init(&dpages, GFP_NOFS); | |
398 | AuDebugOn(err); | |
399 | err = au_dcsub_pages_rev_aufs(&dpages, parent, /*do_include*/1); | |
400 | AuDebugOn(err); | |
401 | for (i = dpages.ndpage - 1; !err && i >= 0; i--) { | |
402 | dpage = dpages.dpages + i; | |
403 | dentries = dpage->dentries; | |
404 | for (j = dpage->ndentry - 1; !err && j >= 0; j--) | |
405 | AuDebugOn(au_digen_test(dentries[j], sigen)); | |
406 | } | |
407 | au_dpages_free(&dpages); | |
408 | } | |
409 | ||
410 | void au_dbg_verify_kthread(void) | |
411 | { | |
412 | if (au_wkq_test()) { | |
413 | au_dbg_blocked(); | |
414 | /* | |
415 | * It may be recursive, but udba=notify between two aufs mounts, | |
416 | * where a single ro branch is shared, is not a problem. | |
417 | */ | |
418 | /* WARN_ON(1); */ | |
419 | } | |
420 | } | |
421 | ||
422 | /* ---------------------------------------------------------------------- */ | |
423 | ||
424 | int __init au_debug_init(void) | |
425 | { | |
426 | aufs_bindex_t bindex; | |
427 | struct au_vdir_destr destr; | |
428 | ||
429 | bindex = -1; | |
430 | AuDebugOn(bindex >= 0); | |
431 | ||
432 | destr.len = -1; | |
433 | AuDebugOn(destr.len < NAME_MAX); | |
434 | ||
435 | #ifdef CONFIG_4KSTACKS | |
436 | pr_warn("CONFIG_4KSTACKS is defined.\n"); | |
437 | #endif | |
438 | ||
439 | return 0; | |
440 | } |