2 * Copyright (C) 2005-2013 Junjiro R. Okajima
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.
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.
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the Free Software
16 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
20 * debug print functions
23 #include <linux/vt_kern.h>
26 /* Returns 0, or -errno. arg is in kp->arg. */
27 static int param_atomic_t_set(const char *val, const struct kernel_param *kp)
31 err = kstrtoint(val, 0, &n);
41 /* Returns length written or -errno. Buffer is 4k (ie. be short!) */
42 static int param_atomic_t_get(char *buffer, const struct kernel_param *kp)
47 return sprintf(buffer, "%d", atomic_read(a));
50 static struct kernel_param_ops param_ops_atomic_t = {
51 .set = param_atomic_t_set,
52 .get = param_atomic_t_get
53 /* void (*free)(void *arg) */
56 atomic_t aufs_debug = ATOMIC_INIT(0);
57 MODULE_PARM_DESC(debug, "debug print");
58 module_param_named(debug, aufs_debug, atomic_t, S_IRUGO | S_IWUSR | S_IWGRP);
60 char *au_plevel = KERN_DEBUG;
61 #define dpri(fmt, ...) do { \
63 && strcmp(au_plevel, KERN_DEBUG)) \
65 printk("%s" fmt, au_plevel, ##__VA_ARGS__); \
68 /* ---------------------------------------------------------------------- */
70 void au_dpri_whlist(struct au_nhash *whlist)
73 struct hlist_head *head;
74 struct au_vdir_wh *tpos;
75 struct hlist_node *pos;
78 head = whlist->nh_head;
79 for (ul = 0; ul < n; ul++) {
80 hlist_for_each_entry(tpos, pos, head, wh_hash)
81 dpri("b%d, %.*s, %d\n",
83 tpos->wh_str.len, tpos->wh_str.name,
89 void au_dpri_vdir(struct au_vdir *vdir)
92 union au_vdir_deblk_p p;
95 if (!vdir || IS_ERR(vdir)) {
96 dpri("err %ld\n", PTR_ERR(vdir));
100 dpri("deblk %u, nblk %lu, deblk %p, last{%lu, %p}, ver %lu\n",
101 vdir->vd_deblk_sz, vdir->vd_nblk, vdir->vd_deblk,
102 vdir->vd_last.ul, vdir->vd_last.p.deblk, vdir->vd_version);
103 for (ul = 0; ul < vdir->vd_nblk; ul++) {
104 p.deblk = vdir->vd_deblk[ul];
106 dpri("[%lu]: %p\n", ul, o);
110 static int do_pri_inode(aufs_bindex_t bindex, struct inode *inode, int hn,
116 if (!inode || IS_ERR(inode)) {
117 dpri("i%d: err %ld\n", bindex, PTR_ERR(inode));
121 /* the type of i_blocks depends upon CONFIG_LBDAF */
122 BUILD_BUG_ON(sizeof(inode->i_blocks) != sizeof(unsigned long)
123 && sizeof(inode->i_blocks) != sizeof(u64));
125 n = (void *)wh->d_name.name;
129 dpri("i%d: %p, i%lu, %s, cnt %d, nl %u, 0%o, sz %llu, blk %llu,"
130 " hn %d, ct %lld, np %lu, st 0x%lx, f 0x%x, v %llu, g %x%s%.*s\n",
132 inode->i_ino, inode->i_sb ? au_sbtype(inode->i_sb) : "??",
133 atomic_read(&inode->i_count), inode->i_nlink, inode->i_mode,
134 i_size_read(inode), (unsigned long long)inode->i_blocks,
135 hn, (long long)timespec_to_ns(&inode->i_ctime) & 0x0ffff,
136 inode->i_mapping ? inode->i_mapping->nrpages : 0,
137 inode->i_state, inode->i_flags, inode->i_version,
139 l ? ", wh " : "", l, n);
143 void au_dpri_inode(struct inode *inode)
145 struct au_iinfo *iinfo;
146 aufs_bindex_t bindex;
149 err = do_pri_inode(-1, inode, -1, NULL);
150 if (err || !au_test_aufs(inode->i_sb))
153 iinfo = au_ii(inode);
156 dpri("i-1: bstart %d, bend %d, gen %d\n",
157 iinfo->ii_bstart, iinfo->ii_bend, au_iigen(inode, NULL));
158 if (iinfo->ii_bstart < 0)
161 for (bindex = iinfo->ii_bstart; bindex <= iinfo->ii_bend; bindex++) {
162 hn = !!au_hn(iinfo->ii_hinode + bindex);
163 do_pri_inode(bindex, iinfo->ii_hinode[0 + bindex].hi_inode, hn,
164 iinfo->ii_hinode[0 + bindex].hi_whdentry);
168 void au_dpri_dalias(struct inode *inode)
172 spin_lock(&inode->i_lock);
173 list_for_each_entry(d, &inode->i_dentry, d_alias)
175 spin_unlock(&inode->i_lock);
178 static int do_pri_dentry(aufs_bindex_t bindex, struct dentry *dentry)
180 struct dentry *wh = NULL;
183 if (!dentry || IS_ERR(dentry)) {
184 dpri("d%d: err %ld\n", bindex, PTR_ERR(dentry));
187 /* do not call dget_parent() here */
188 /* note: access d_xxx without d_lock */
189 dpri("d%d: %.*s?/%.*s, %s, cnt %d, flags 0x%x\n",
191 AuDLNPair(dentry->d_parent), AuDLNPair(dentry),
192 dentry->d_sb ? au_sbtype(dentry->d_sb) : "??",
193 dentry->d_count, dentry->d_flags);
195 if (bindex >= 0 && dentry->d_inode && au_test_aufs(dentry->d_sb)) {
196 struct au_iinfo *iinfo = au_ii(dentry->d_inode);
198 hn = !!au_hn(iinfo->ii_hinode + bindex);
199 wh = iinfo->ii_hinode[0 + bindex].hi_whdentry;
202 do_pri_inode(bindex, dentry->d_inode, hn, wh);
206 void au_dpri_dentry(struct dentry *dentry)
208 struct au_dinfo *dinfo;
209 aufs_bindex_t bindex;
211 struct au_hdentry *hdp;
213 err = do_pri_dentry(-1, dentry);
214 if (err || !au_test_aufs(dentry->d_sb))
217 dinfo = au_di(dentry);
220 dpri("d-1: bstart %d, bend %d, bwh %d, bdiropq %d, gen %d\n",
221 dinfo->di_bstart, dinfo->di_bend,
222 dinfo->di_bwh, dinfo->di_bdiropq, au_digen(dentry));
223 if (dinfo->di_bstart < 0)
225 hdp = dinfo->di_hdentry;
226 for (bindex = dinfo->di_bstart; bindex <= dinfo->di_bend; bindex++)
227 do_pri_dentry(bindex, hdp[0 + bindex].hd_dentry);
230 static int do_pri_file(aufs_bindex_t bindex, struct file *file)
234 if (!file || IS_ERR(file)) {
235 dpri("f%d: err %ld\n", bindex, PTR_ERR(file));
241 && au_test_aufs(file->f_dentry->d_sb)
243 snprintf(a, sizeof(a), ", gen %d, mmapped %d",
244 au_figen(file), atomic_read(&au_fi(file)->fi_mmapped));
245 dpri("f%d: mode 0x%x, flags 0%o, cnt %ld, v %llu, pos %llu%s\n",
246 bindex, file->f_mode, file->f_flags, (long)file_count(file),
247 file->f_version, file->f_pos, a);
249 do_pri_dentry(bindex, file->f_dentry);
253 void au_dpri_file(struct file *file)
255 struct au_finfo *finfo;
256 struct au_fidir *fidir;
257 struct au_hfile *hfile;
258 aufs_bindex_t bindex;
261 err = do_pri_file(-1, file);
262 if (err || !file->f_dentry || !au_test_aufs(file->f_dentry->d_sb))
268 if (finfo->fi_btop < 0)
270 fidir = finfo->fi_hdir;
272 do_pri_file(finfo->fi_btop, finfo->fi_htop.hf_file);
274 for (bindex = finfo->fi_btop;
275 bindex >= 0 && bindex <= fidir->fd_bbot;
277 hfile = fidir->fd_hfile + bindex;
278 do_pri_file(bindex, hfile ? hfile->hf_file : NULL);
282 static int do_pri_br(aufs_bindex_t bindex, struct au_branch *br)
284 struct vfsmount *mnt;
285 struct super_block *sb;
287 if (!br || IS_ERR(br))
290 if (!mnt || IS_ERR(mnt))
293 if (!sb || IS_ERR(sb))
296 dpri("s%d: {perm 0x%x, id %d, cnt %d, wbr %p}, "
297 "%s, dev 0x%02x%02x, flags 0x%lx, cnt %d, active %d, "
299 bindex, br->br_perm, br->br_id, atomic_read(&br->br_count),
300 br->br_wbr, au_sbtype(sb), MAJOR(sb->s_dev), MINOR(sb->s_dev),
301 sb->s_flags, sb->s_count,
302 atomic_read(&sb->s_active), !!br->br_xino.xi_file);
306 dpri("s%d: err %ld\n", bindex, PTR_ERR(br));
310 void au_dpri_sb(struct super_block *sb)
312 struct au_sbinfo *sbinfo;
313 aufs_bindex_t bindex;
315 /* to reuduce stack size */
318 struct au_branch fake;
321 /* this function can be called from magic sysrq */
322 a = kzalloc(sizeof(*a), GFP_ATOMIC);
330 a->fake.br_path.mnt = &a->mnt;
331 a->fake.br_xino.xi_file = NULL;
332 atomic_set(&a->fake.br_count, 0);
333 smp_mb(); /* atomic_set */
334 err = do_pri_br(-1, &a->fake);
336 dpri("dev 0x%x\n", sb->s_dev);
337 if (err || !au_test_aufs(sb))
343 dpri("nw %d, gen %u, kobj %d\n",
344 atomic_read(&sbinfo->si_nowait.nw_len), sbinfo->si_generation,
345 atomic_read(&sbinfo->si_kobj.kref.refcount));
346 for (bindex = 0; bindex <= sbinfo->si_bend; bindex++)
347 do_pri_br(bindex, sbinfo->si_branch[0 + bindex]);
350 /* ---------------------------------------------------------------------- */
352 void au_dbg_sleep_jiffy(int jiffy)
355 jiffy = schedule_timeout_uninterruptible(jiffy);
358 void au_dbg_iattr(struct iattr *ia)
360 #define AuBit(name) \
362 if (ia->ia_valid & ATTR_ ## name) \
383 dpri("ia_file %p\n", ia->ia_file);
386 /* ---------------------------------------------------------------------- */
388 void __au_dbg_verify_dinode(struct dentry *dentry, const char *func, int line)
390 struct inode *h_inode, *inode = dentry->d_inode;
391 struct dentry *h_dentry;
392 aufs_bindex_t bindex, bend, bi;
394 if (!inode /* || au_di(dentry)->di_lsc == AuLsc_DI_TMP */)
397 bend = au_dbend(dentry);
398 bi = au_ibend(inode);
401 bindex = au_dbstart(dentry);
402 bi = au_ibstart(inode);
406 for (; bindex <= bend; bindex++) {
407 h_dentry = au_h_dptr(dentry, bindex);
410 h_inode = au_h_iptr(inode, bindex);
411 if (unlikely(h_inode != h_dentry->d_inode)) {
413 AuDbg("b%d, %s:%d\n", bindex, func, line);
422 void au_dbg_verify_dir_parent(struct dentry *dentry, unsigned int sigen)
424 struct dentry *parent;
426 parent = dget_parent(dentry);
427 AuDebugOn(!S_ISDIR(dentry->d_inode->i_mode));
428 AuDebugOn(IS_ROOT(dentry));
429 AuDebugOn(au_digen_test(parent, sigen));
433 void au_dbg_verify_nondir_parent(struct dentry *dentry, unsigned int sigen)
435 struct dentry *parent;
438 parent = dget_parent(dentry);
439 inode = dentry->d_inode;
440 AuDebugOn(inode && S_ISDIR(dentry->d_inode->i_mode));
441 AuDebugOn(au_digen_test(parent, sigen));
445 void au_dbg_verify_gen(struct dentry *parent, unsigned int sigen)
448 struct au_dcsub_pages dpages;
449 struct au_dpage *dpage;
450 struct dentry **dentries;
452 err = au_dpages_init(&dpages, GFP_NOFS);
454 err = au_dcsub_pages_rev_aufs(&dpages, parent, /*do_include*/1);
456 for (i = dpages.ndpage - 1; !err && i >= 0; i--) {
457 dpage = dpages.dpages + i;
458 dentries = dpage->dentries;
459 for (j = dpage->ndentry - 1; !err && j >= 0; j--)
460 AuDebugOn(au_digen_test(dentries[j], sigen));
462 au_dpages_free(&dpages);
465 void au_dbg_verify_kthread(void)
470 * It may be recursive, but udba=notify between two aufs mounts,
471 * where a single ro branch is shared, is not a problem.
477 /* ---------------------------------------------------------------------- */
479 void au_debug_sbinfo_init(struct au_sbinfo *sbinfo __maybe_unused)
481 #ifdef AuForceNoPlink
482 au_opt_clr(sbinfo->si_mntflags, PLINK);
485 au_opt_clr(sbinfo->si_mntflags, XINO);
487 #ifdef AuForceNoRefrof
488 au_opt_clr(sbinfo->si_mntflags, REFROF);
490 #ifdef AuForceHnotify
491 au_opt_set_udba(sbinfo->si_mntflags, UDBA_HNOTIFY);
494 sbinfo->si_rdblk = 0;
495 sbinfo->si_rdhash = 0;
499 int __init au_debug_init(void)
501 aufs_bindex_t bindex;
502 struct au_vdir_destr destr;
505 AuDebugOn(bindex >= 0);
508 AuDebugOn(destr.len < NAME_MAX);
510 #ifdef CONFIG_4KSTACKS
511 pr_warn("CONFIG_4KSTACKS is defined.\n");