2 * Copyright (C) 2005-2012 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>
27 MODULE_PARM_DESC(debug, "debug print");
28 module_param_named(debug, aufs_debug, int, S_IRUGO | S_IWUSR | S_IWGRP);
30 char *au_plevel = KERN_DEBUG;
31 #define dpri(fmt, ...) do { \
33 && strcmp(au_plevel, KERN_DEBUG)) \
35 printk("%s" fmt, au_plevel, ##__VA_ARGS__); \
38 /* ---------------------------------------------------------------------- */
40 void au_dpri_whlist(struct au_nhash *whlist)
43 struct hlist_head *head;
44 struct au_vdir_wh *tpos;
45 struct hlist_node *pos;
48 head = whlist->nh_head;
49 for (ul = 0; ul < n; ul++) {
50 hlist_for_each_entry(tpos, pos, head, wh_hash)
51 dpri("b%d, %.*s, %d\n",
53 tpos->wh_str.len, tpos->wh_str.name,
59 void au_dpri_vdir(struct au_vdir *vdir)
62 union au_vdir_deblk_p p;
65 if (!vdir || IS_ERR(vdir)) {
66 dpri("err %ld\n", PTR_ERR(vdir));
70 dpri("deblk %u, nblk %lu, deblk %p, last{%lu, %p}, ver %lu\n",
71 vdir->vd_deblk_sz, vdir->vd_nblk, vdir->vd_deblk,
72 vdir->vd_last.ul, vdir->vd_last.p.deblk, vdir->vd_version);
73 for (ul = 0; ul < vdir->vd_nblk; ul++) {
74 p.deblk = vdir->vd_deblk[ul];
76 dpri("[%lu]: %p\n", ul, o);
80 static int do_pri_inode(aufs_bindex_t bindex, struct inode *inode, int hn,
86 if (!inode || IS_ERR(inode)) {
87 dpri("i%d: err %ld\n", bindex, PTR_ERR(inode));
91 /* the type of i_blocks depends upon CONFIG_LSF */
92 BUILD_BUG_ON(sizeof(inode->i_blocks) != sizeof(unsigned long)
93 && sizeof(inode->i_blocks) != sizeof(u64));
95 n = (void *)wh->d_name.name;
99 dpri("i%d: %p, i%lu, %s, cnt %d, nl %u, 0%o, sz %llu, blk %llu,"
100 " hn %d, ct %lld, np %lu, st 0x%lx, f 0x%x, v %llu, g %x%s%.*s\n",
102 inode->i_ino, inode->i_sb ? au_sbtype(inode->i_sb) : "??",
103 atomic_read(&inode->i_count), inode->i_nlink, inode->i_mode,
104 i_size_read(inode), (unsigned long long)inode->i_blocks,
105 hn, (long long)timespec_to_ns(&inode->i_ctime) & 0x0ffff,
106 inode->i_mapping ? inode->i_mapping->nrpages : 0,
107 inode->i_state, inode->i_flags, inode->i_version,
109 l ? ", wh " : "", l, n);
113 void au_dpri_inode(struct inode *inode)
115 struct au_iinfo *iinfo;
116 aufs_bindex_t bindex;
119 err = do_pri_inode(-1, inode, -1, NULL);
120 if (err || !au_test_aufs(inode->i_sb))
123 iinfo = au_ii(inode);
126 dpri("i-1: bstart %d, bend %d, gen %d\n",
127 iinfo->ii_bstart, iinfo->ii_bend, au_iigen(inode));
128 if (iinfo->ii_bstart < 0)
131 for (bindex = iinfo->ii_bstart; bindex <= iinfo->ii_bend; bindex++) {
132 hn = !!au_hn(iinfo->ii_hinode + bindex);
133 do_pri_inode(bindex, iinfo->ii_hinode[0 + bindex].hi_inode, hn,
134 iinfo->ii_hinode[0 + bindex].hi_whdentry);
138 void au_dpri_dalias(struct inode *inode)
142 spin_lock(&inode->i_lock);
143 list_for_each_entry(d, &inode->i_dentry, d_alias)
145 spin_unlock(&inode->i_lock);
148 static int do_pri_dentry(aufs_bindex_t bindex, struct dentry *dentry)
150 struct dentry *wh = NULL;
153 if (!dentry || IS_ERR(dentry)) {
154 dpri("d%d: err %ld\n", bindex, PTR_ERR(dentry));
157 /* do not call dget_parent() here */
158 /* note: access d_xxx without d_lock */
159 dpri("d%d: %.*s?/%.*s, %s, cnt %d, flags 0x%x\n",
161 AuDLNPair(dentry->d_parent), AuDLNPair(dentry),
162 dentry->d_sb ? au_sbtype(dentry->d_sb) : "??",
163 dentry->d_count, dentry->d_flags);
165 if (bindex >= 0 && dentry->d_inode && au_test_aufs(dentry->d_sb)) {
166 struct au_iinfo *iinfo = au_ii(dentry->d_inode);
168 hn = !!au_hn(iinfo->ii_hinode + bindex);
169 wh = iinfo->ii_hinode[0 + bindex].hi_whdentry;
172 do_pri_inode(bindex, dentry->d_inode, hn, wh);
176 void au_dpri_dentry(struct dentry *dentry)
178 struct au_dinfo *dinfo;
179 aufs_bindex_t bindex;
181 struct au_hdentry *hdp;
183 err = do_pri_dentry(-1, dentry);
184 if (err || !au_test_aufs(dentry->d_sb))
187 dinfo = au_di(dentry);
190 dpri("d-1: bstart %d, bend %d, bwh %d, bdiropq %d, gen %d\n",
191 dinfo->di_bstart, dinfo->di_bend,
192 dinfo->di_bwh, dinfo->di_bdiropq, au_digen(dentry));
193 if (dinfo->di_bstart < 0)
195 hdp = dinfo->di_hdentry;
196 for (bindex = dinfo->di_bstart; bindex <= dinfo->di_bend; bindex++)
197 do_pri_dentry(bindex, hdp[0 + bindex].hd_dentry);
200 static int do_pri_file(aufs_bindex_t bindex, struct file *file)
204 if (!file || IS_ERR(file)) {
205 dpri("f%d: err %ld\n", bindex, PTR_ERR(file));
211 && au_test_aufs(file->f_dentry->d_sb)
213 snprintf(a, sizeof(a), ", gen %d, mmapped %d",
214 au_figen(file), atomic_read(&au_fi(file)->fi_mmapped));
215 dpri("f%d: mode 0x%x, flags 0%o, cnt %ld, v %llu, pos %llu%s\n",
216 bindex, file->f_mode, file->f_flags, (long)file_count(file),
217 file->f_version, file->f_pos, a);
219 do_pri_dentry(bindex, file->f_dentry);
223 void au_dpri_file(struct file *file)
225 struct au_finfo *finfo;
226 struct au_fidir *fidir;
227 struct au_hfile *hfile;
228 aufs_bindex_t bindex;
231 err = do_pri_file(-1, file);
232 if (err || !file->f_dentry || !au_test_aufs(file->f_dentry->d_sb))
238 if (finfo->fi_btop < 0)
240 fidir = finfo->fi_hdir;
242 do_pri_file(finfo->fi_btop, finfo->fi_htop.hf_file);
244 for (bindex = finfo->fi_btop;
245 bindex >= 0 && bindex <= fidir->fd_bbot;
247 hfile = fidir->fd_hfile + bindex;
248 do_pri_file(bindex, hfile ? hfile->hf_file : NULL);
252 static int do_pri_br(aufs_bindex_t bindex, struct au_branch *br)
254 struct vfsmount *mnt;
255 struct super_block *sb;
257 if (!br || IS_ERR(br))
260 if (!mnt || IS_ERR(mnt))
263 if (!sb || IS_ERR(sb))
266 dpri("s%d: {perm 0x%x, id %d, cnt %d, wbr %p}, "
267 "%s, dev 0x%02x%02x, flags 0x%lx, cnt %d, active %d, "
269 bindex, br->br_perm, br->br_id, atomic_read(&br->br_count),
270 br->br_wbr, au_sbtype(sb), MAJOR(sb->s_dev), MINOR(sb->s_dev),
271 sb->s_flags, sb->s_count,
272 atomic_read(&sb->s_active), !!br->br_xino.xi_file);
276 dpri("s%d: err %ld\n", bindex, PTR_ERR(br));
280 void au_dpri_sb(struct super_block *sb)
282 struct au_sbinfo *sbinfo;
283 aufs_bindex_t bindex;
285 /* to reuduce stack size */
288 struct au_branch fake;
291 /* this function can be called from magic sysrq */
292 a = kzalloc(sizeof(*a), GFP_ATOMIC);
300 a->fake.br_mnt = &a->mnt;
301 a->fake.br_xino.xi_file = NULL;
302 atomic_set(&a->fake.br_count, 0);
303 smp_mb(); /* atomic_set */
304 err = do_pri_br(-1, &a->fake);
306 dpri("dev 0x%x\n", sb->s_dev);
307 if (err || !au_test_aufs(sb))
313 dpri("nw %d, gen %u, kobj %d\n",
314 atomic_read(&sbinfo->si_nowait.nw_len), sbinfo->si_generation,
315 atomic_read(&sbinfo->si_kobj.kref.refcount));
316 for (bindex = 0; bindex <= sbinfo->si_bend; bindex++)
317 do_pri_br(bindex, sbinfo->si_branch[0 + bindex]);
320 /* ---------------------------------------------------------------------- */
322 void au_dbg_sleep_jiffy(int jiffy)
325 jiffy = schedule_timeout_uninterruptible(jiffy);
328 void au_dbg_iattr(struct iattr *ia)
330 #define AuBit(name) if (ia->ia_valid & ATTR_ ## name) \
350 dpri("ia_file %p\n", ia->ia_file);
353 /* ---------------------------------------------------------------------- */
355 void __au_dbg_verify_dinode(struct dentry *dentry, const char *func, int line)
357 struct inode *h_inode, *inode = dentry->d_inode;
358 struct dentry *h_dentry;
359 aufs_bindex_t bindex, bend, bi;
361 if (!inode /* || au_di(dentry)->di_lsc == AuLsc_DI_TMP */)
364 bend = au_dbend(dentry);
365 bi = au_ibend(inode);
368 bindex = au_dbstart(dentry);
369 bi = au_ibstart(inode);
373 for (; bindex <= bend; bindex++) {
374 h_dentry = au_h_dptr(dentry, bindex);
377 h_inode = au_h_iptr(inode, bindex);
378 if (unlikely(h_inode != h_dentry->d_inode)) {
379 int old = au_debug_test();
382 AuDbg("b%d, %s:%d\n", bindex, func, line);
392 void au_dbg_verify_dir_parent(struct dentry *dentry, unsigned int sigen)
394 struct dentry *parent;
396 parent = dget_parent(dentry);
397 AuDebugOn(!S_ISDIR(dentry->d_inode->i_mode));
398 AuDebugOn(IS_ROOT(dentry));
399 AuDebugOn(au_digen_test(parent, sigen));
403 void au_dbg_verify_nondir_parent(struct dentry *dentry, unsigned int sigen)
405 struct dentry *parent;
408 parent = dget_parent(dentry);
409 inode = dentry->d_inode;
410 AuDebugOn(inode && S_ISDIR(dentry->d_inode->i_mode));
411 AuDebugOn(au_digen_test(parent, sigen));
415 void au_dbg_verify_gen(struct dentry *parent, unsigned int sigen)
418 struct au_dcsub_pages dpages;
419 struct au_dpage *dpage;
420 struct dentry **dentries;
422 err = au_dpages_init(&dpages, GFP_NOFS);
424 err = au_dcsub_pages_rev_aufs(&dpages, parent, /*do_include*/1);
426 for (i = dpages.ndpage - 1; !err && i >= 0; i--) {
427 dpage = dpages.dpages + i;
428 dentries = dpage->dentries;
429 for (j = dpage->ndentry - 1; !err && j >= 0; j--)
430 AuDebugOn(au_digen_test(dentries[j], sigen));
432 au_dpages_free(&dpages);
435 void au_dbg_verify_kthread(void)
440 * It may be recursive, but udba=notify between two aufs mounts,
441 * where a single ro branch is shared, is not a problem.
447 /* ---------------------------------------------------------------------- */
449 void au_debug_sbinfo_init(struct au_sbinfo *sbinfo __maybe_unused)
451 #ifdef AuForceNoPlink
452 au_opt_clr(sbinfo->si_mntflags, PLINK);
455 au_opt_clr(sbinfo->si_mntflags, XINO);
457 #ifdef AuForceNoRefrof
458 au_opt_clr(sbinfo->si_mntflags, REFROF);
460 #ifdef AuForceHnotify
461 au_opt_set_udba(sbinfo->si_mntflags, UDBA_HNOTIFY);
464 sbinfo->si_rdblk = 0;
465 sbinfo->si_rdhash = 0;
469 int __init au_debug_init(void)
471 aufs_bindex_t bindex;
472 struct au_vdir_destr destr;
475 AuDebugOn(bindex >= 0);
478 AuDebugOn(destr.len < NAME_MAX);
480 #ifdef CONFIG_4KSTACKS
481 pr_warning("CONFIG_4KSTACKS is defined.\n");