2 * Copyright (C) 2005-2008 Junjiro 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
22 * $Id: debug.c,v 1.2 2008/04/21 01:33:00 sfjro Exp $
25 //#include <linux/errno.h>
28 atomic_t au_cond
= ATOMIC_INIT(0);
30 char *au_plevel
= KERN_DEBUG
;
31 #define dpri(fmt, arg...) do { \
33 printk("%s" fmt, au_plevel, ##arg); \
36 /* ---------------------------------------------------------------------- */
38 void au_dpri_whlist(struct au_nhash
*whlist
)
41 struct hlist_head
*head
;
42 struct au_vdir_wh
*tpos
;
43 struct hlist_node
*pos
;
45 for (i
= 0; i
< AuSize_NHASH
; i
++) {
46 head
= whlist
->heads
+ i
;
47 hlist_for_each_entry(tpos
, pos
, head
, wh_hash
)
48 dpri("b%d, %.*s, %d\n",
50 tpos
->wh_str
.len
, tpos
->wh_str
.name
,
55 void au_dpri_vdir(struct au_vdir
*vdir
)
58 union au_vdir_deblk_p p
;
61 if (!vdir
|| IS_ERR(vdir
)) {
62 dpri("err %ld\n", PTR_ERR(vdir
));
66 dpri("nblk %d, deblk %p, last{%d, %p}, ver %lu\n",
67 vdir
->vd_nblk
, vdir
->vd_deblk
,
68 vdir
->vd_last
.i
, vdir
->vd_last
.p
.p
, vdir
->vd_version
);
69 for (i
= 0; i
< vdir
->vd_nblk
; i
++) {
70 p
.deblk
= vdir
->vd_deblk
[i
];
72 dpri("[%d]: %p\n", i
, o
);
75 for (j
= 0; j
< 8; j
++) {
76 dpri("%p(+%d) {%02x %02x %02x %02x %02x %02x %02x %02x "
77 "%02x %02x %02x %02x %02x %02x %02x %02x}\n",
79 p
.p
[0], p
.p
[1], p
.p
[2], p
.p
[3],
80 p
.p
[4], p
.p
[5], p
.p
[6], p
.p
[7],
81 p
.p
[8], p
.p
[9], p
.p
[10], p
.p
[11],
82 p
.p
[12], p
.p
[13], p
.p
[14], p
.p
[15]);
89 static int do_pri_inode(aufs_bindex_t bindex
, struct inode
*inode
,
95 if (!inode
|| IS_ERR(inode
)) {
96 dpri("i%d: err %ld\n", bindex
, PTR_ERR(inode
));
100 /* the type of i_blocks depends upon CONFIG_LSF */
101 BUILD_BUG_ON(sizeof(inode
->i_blocks
) != sizeof(unsigned long)
102 && sizeof(inode
->i_blocks
) != sizeof(u64
));
104 n
= (void *)wh
->d_name
.name
;
108 ntfy
= au_test_inotify(inode
);
109 dpri("i%d: i%lu, %s, cnt %d, nl %u, 0%o, ntfy %d, sz %Lu, blk %Lu,"
110 " ct %Ld, np %lu, st 0x%lx, f 0x%x, g %x%s%.*s\n",
112 inode
->i_ino
, inode
->i_sb
? au_sbtype(inode
->i_sb
) : "??",
113 atomic_read(&inode
->i_count
), inode
->i_nlink
, inode
->i_mode
,
115 i_size_read(inode
), (u64
)inode
->i_blocks
,
116 timespec_to_ns(&inode
->i_ctime
) & 0x0ffff,
117 inode
->i_mapping
? mapping_nrpages(inode
->i_mapping
) : 0,
118 inode
->i_state
, inode
->i_flags
, inode
->i_generation
,
119 l
? ", wh " : "", l
, n
);
123 void au_dpri_inode(struct inode
*inode
)
125 struct au_iinfo
*iinfo
;
126 aufs_bindex_t bindex
;
129 err
= do_pri_inode(-1, inode
, NULL
);
130 if (err
|| !au_test_aufs(inode
->i_sb
))
133 iinfo
= au_ii(inode
);
136 dpri("i-1: bstart %d, bend %d, gen %d\n",
137 iinfo
->ii_bstart
, iinfo
->ii_bend
, au_iigen(inode
));
138 if (iinfo
->ii_bstart
< 0)
140 for (bindex
= iinfo
->ii_bstart
; bindex
<= iinfo
->ii_bend
; bindex
++)
141 do_pri_inode(bindex
, iinfo
->ii_hinode
[0 + bindex
].hi_inode
,
142 iinfo
->ii_hinode
[0 + bindex
].hi_whdentry
);
145 static int do_pri_dentry(aufs_bindex_t bindex
, struct dentry
*dentry
,
146 struct list_head
*intent
)
148 struct dentry
*wh
= NULL
;
150 if (!dentry
|| IS_ERR(dentry
)) {
151 dpri("d%d: err %ld\n", bindex
, PTR_ERR(dentry
));
154 /* do not call dget_parent() here */
155 dpri("d%d: %.*s/%.*s, %s, cnt %d, flags 0x%x, intent %d\n",
157 AuDLNPair(dentry
->d_parent
), AuDLNPair(dentry
),
158 dentry
->d_sb
? au_sbtype(dentry
->d_sb
) : "??",
159 atomic_read(&dentry
->d_count
), dentry
->d_flags
, !!intent
);
160 if (bindex
>= 0 && dentry
->d_inode
&& au_test_aufs(dentry
->d_sb
)) {
161 struct au_iinfo
*iinfo
= au_ii(dentry
->d_inode
);
163 wh
= iinfo
->ii_hinode
[0 + bindex
].hi_whdentry
;
165 do_pri_inode(bindex
, dentry
->d_inode
, wh
);
169 static struct list_head
*au_dbg_h_intent(struct au_dinfo
*dinfo
,
170 aufs_bindex_t bindex
)
172 #ifdef CONFIG_AUFS_BR_NFS
173 return dinfo
->di_hdentry
[0 + bindex
].hd_intent_list
;
179 void au_dpri_dentry(struct dentry
*dentry
)
181 struct au_dinfo
*dinfo
;
182 aufs_bindex_t bindex
;
185 err
= do_pri_dentry(-1, dentry
, NULL
);
186 if (err
|| !au_test_aufs(dentry
->d_sb
))
189 dinfo
= au_di(dentry
);
192 dpri("d-1: bstart %d, bend %d, bwh %d, bdiropq %d, gen %d\n",
193 dinfo
->di_bstart
, dinfo
->di_bend
,
194 dinfo
->di_bwh
, dinfo
->di_bdiropq
, au_digen(dentry
));
195 if (dinfo
->di_bstart
< 0)
197 for (bindex
= dinfo
->di_bstart
; bindex
<= dinfo
->di_bend
; bindex
++)
198 do_pri_dentry(bindex
, dinfo
->di_hdentry
[0 + bindex
].hd_dentry
,
199 au_dbg_h_intent(dinfo
, bindex
));
202 static int do_pri_file(aufs_bindex_t bindex
, struct file
*file
)
206 if (!file
|| IS_ERR(file
)) {
207 dpri("f%d: err %ld\n", bindex
, PTR_ERR(file
));
213 && au_test_aufs(file
->f_dentry
->d_sb
)
215 snprintf(a
, sizeof(a
), ", mmapped %d", au_test_mmapped(file
));
216 dpri("f%d: mode 0x%x, flags 0%o, cnt %d, pos %Lu%s\n",
217 bindex
, file
->f_mode
, file
->f_flags
, file_count(file
),
220 do_pri_dentry(bindex
, file
->f_dentry
, NULL
);
224 void au_dpri_file(struct file
*file
)
226 struct au_finfo
*finfo
;
227 aufs_bindex_t bindex
;
230 err
= do_pri_file(-1, file
);
231 if (err
|| !file
->f_dentry
|| !au_test_aufs(file
->f_dentry
->d_sb
))
237 if (finfo
->fi_bstart
< 0)
239 for (bindex
= finfo
->fi_bstart
; bindex
<= finfo
->fi_bend
; bindex
++) {
241 //dpri("bindex %d\n", bindex);
242 hf
= finfo
->fi_hfile
+ bindex
;
243 do_pri_file(bindex
, hf
? hf
->hf_file
: NULL
);
247 static int do_pri_br(aufs_bindex_t bindex
, struct au_branch
*br
)
249 struct vfsmount
*mnt
;
250 struct super_block
*sb
;
252 if (!br
|| IS_ERR(br
)
253 || !(mnt
= br
->br_mnt
) || IS_ERR(mnt
)
254 || !(sb
= mnt
->mnt_sb
) || IS_ERR(sb
)) {
255 dpri("s%d: err %ld\n", bindex
, PTR_ERR(br
));
259 dpri("s%d: {perm 0x%x, cnt %d}, "
260 "%s, flags 0x%lx, cnt(BIAS) %d, active %d, xino %d\n",
261 bindex
, br
->br_perm
, au_br_count(br
),
262 au_sbtype(sb
), sb
->s_flags
, sb
->s_count
- S_BIAS
,
263 atomic_read(&sb
->s_active
), !!br
->br_xino
);
267 void au_dpri_sb(struct super_block
*sb
)
269 struct au_sbinfo
*sbinfo
;
270 aufs_bindex_t bindex
;
272 struct vfsmount mnt
= { .mnt_sb
= sb
};
273 struct au_branch fake
= {
276 .br_count
= ATOMIC_INIT(0),
280 atomic_set(&fake
.br_count
, 0);
281 smp_mb(); /* atomic_set */
282 err
= do_pri_br(-1, &fake
);
283 dpri("dev 0x%x\n", sb
->s_dev
);
284 if (err
|| !au_test_aufs(sb
))
290 for (bindex
= 0; bindex
<= sbinfo
->si_bend
; bindex
++) {
291 //dpri("bindex %d\n", bindex);
292 do_pri_br(bindex
, sbinfo
->si_branch
[0 + bindex
]);
296 /* ---------------------------------------------------------------------- */
298 void au_dbg_sleep(int sec
)
300 static DECLARE_WAIT_QUEUE_HEAD(wq
);
301 wait_event_timeout(wq
, 0, sec
* HZ
);
304 /* ---------------------------------------------------------------------- */
306 void au_debug_sbinfo_init(struct au_sbinfo
*sbinfo
)
309 au_opt_set_udba(sbinfo
->si_mntflags
, UDBA_INOTIFY
);
312 au_opt_set(sbinfo
->si_mntflags
, DLGT
);
315 au_opt_clr(sbinfo
->si_mntflags
, PLINK
);
318 au_opt_clr(sbinfo
->si_mntflags
, XINO
);
321 au_opt_clr(sbinfo
->si_mntflags
, REFROF
);
325 int __init
au_debug_init(void)
327 aufs_bindex_t bindex
;
328 struct au_vdir_destr destr
;
331 AuDebugOn(bindex
>= 0);
334 AuDebugOn(destr
.len
< NAME_MAX
);
336 #ifdef CONFIG_4KSTACKS
337 AuWarn("CONFIG_4KSTACKS is defined.\n");
340 #if 0 // verbose debug
343 struct au_branch
*br
;
347 struct au_hinode
*hi
;
348 struct au_sbinfo
*si
;
349 struct au_vdir_destr
*destr
;
350 struct au_vdir_de
*de
;
351 struct au_vdir_wh
*wh
;
357 "id %d, perm %d, mnt %d, count %d, "
358 "wh_sem %d, wh %d, run %d, plink %d, "
363 offsetof(typeof(*u
.br
), br_xino
),
364 offsetof(typeof(*u
.br
), br_id
),
365 offsetof(typeof(*u
.br
), br_perm
),
366 offsetof(typeof(*u
.br
), br_mnt
),
367 offsetof(typeof(*u
.br
), br_count
),
368 offsetof(typeof(*u
.br
), br_wh_rwsem
),
369 offsetof(typeof(*u
.br
), br_wh
),
370 offsetof(typeof(*u
.br
), br_wh_running
),
371 offsetof(typeof(*u
.br
), br_plink
),
372 offsetof(typeof(*u
.br
), br_xino_upper
),
373 offsetof(typeof(*u
.br
), br_xino_running
),
374 offsetof(typeof(*u
.br
), br_bytes
),
375 offsetof(typeof(*u
.br
), br_generation
),
376 offsetof(typeof(*u
.br
), br_sabr
),
378 pr_info("di{gen %d, rwsem %d, bstart %d, bend %d, bwh %d, "
379 "bdiropq %d, hdentry %d} %d\n",
380 offsetof(typeof(*u
.di
), di_generation
),
381 offsetof(typeof(*u
.di
), di_rwsem
),
382 offsetof(typeof(*u
.di
), di_bstart
),
383 offsetof(typeof(*u
.di
), di_bend
),
384 offsetof(typeof(*u
.di
), di_bwh
),
385 offsetof(typeof(*u
.di
), di_bdiropq
),
386 offsetof(typeof(*u
.di
), di_hdentry
),
388 pr_info("fi{gen %d, rwsem %d, hfile %d, bstart %d, bend %d, "
389 "h_vm_ops %d, vdir_cach %d} %d\n",
390 offsetof(typeof(*u
.fi
), fi_generation
),
391 offsetof(typeof(*u
.fi
), fi_rwsem
),
392 offsetof(typeof(*u
.fi
), fi_hfile
),
393 offsetof(typeof(*u
.fi
), fi_bstart
),
394 offsetof(typeof(*u
.fi
), fi_bend
),
395 offsetof(typeof(*u
.fi
), fi_h_vm_ops
),
396 offsetof(typeof(*u
.fi
), fi_vdir_cache
),
398 pr_info("ii{gen %d, hsb %d, "
399 "rwsem %d, bstart %d, bend %d, hinode %d, vdir %d} "
401 offsetof(typeof(*u
.ii
), ii_generation
),
402 offsetof(typeof(*u
.ii
), ii_hsb1
),
403 offsetof(typeof(*u
.ii
), ii_rwsem
),
404 offsetof(typeof(*u
.ii
), ii_bstart
),
405 offsetof(typeof(*u
.ii
), ii_bend
),
406 offsetof(typeof(*u
.ii
), ii_hinode
),
407 offsetof(typeof(*u
.ii
), ii_vdir
),
409 pr_info("hi{inode %d, id %d, notify %d, wh %d} %d\n",
410 offsetof(typeof(*u
.hi
), hi_inode
),
411 offsetof(typeof(*u
.hi
), hi_id
),
412 offsetof(typeof(*u
.hi
), hi_notify
),
413 offsetof(typeof(*u
.hi
), hi_whdentry
),
415 pr_info("si{nwt %d, rwsem %d, gen %d, stat %d, "
416 "bend %d, last id %d, br %d, "
417 "cpup %d, creat %d, ops %d, ops %d, "
420 "xread %d, xwrite %d, xib %d, xmtx %d, buf %d, "
421 "xlast %d, xnext %d, "
424 "pl_lock %d, pl %d, "
427 //"lvma_l %d, lvma %d"
429 offsetof(typeof(*u
.si
), si_nowait
),
430 offsetof(typeof(*u
.si
), si_rwsem
),
431 offsetof(typeof(*u
.si
), si_generation
),
432 offsetof(typeof(*u
.si
), au_si_status
),
433 offsetof(typeof(*u
.si
), si_bend
),
434 offsetof(typeof(*u
.si
), si_last_br_id
),
435 offsetof(typeof(*u
.si
), si_branch
),
436 offsetof(typeof(*u
.si
), si_wbr_copyup
),
437 offsetof(typeof(*u
.si
), si_wbr_create
),
438 offsetof(typeof(*u
.si
), si_wbr_copyup_ops
),
439 offsetof(typeof(*u
.si
), si_wbr_create_ops
),
440 offsetof(typeof(*u
.si
), si_wbr_rr_next
),
441 offsetof(typeof(*u
.si
), si_wbr_mfs
),
442 offsetof(typeof(*u
.si
), si_mntflags
),
443 offsetof(typeof(*u
.si
), si_xread
),
444 offsetof(typeof(*u
.si
), si_xwrite
),
445 offsetof(typeof(*u
.si
), si_xib
),
446 offsetof(typeof(*u
.si
), si_xib_mtx
),
447 offsetof(typeof(*u
.si
), si_xib_buf
),
448 offsetof(typeof(*u
.si
), si_xib_last_pindex
),
449 offsetof(typeof(*u
.si
), si_xib_next_bit
),
450 offsetof(typeof(*u
.si
), si_rdcache
),
451 offsetof(typeof(*u
.si
), si_dirwh
),
452 offsetof(typeof(*u
.si
), si_plink_lock
),
453 offsetof(typeof(*u
.si
), si_plink
),
454 offsetof(typeof(*u
.si
), si_mnt
),
455 offsetof(typeof(*u
.si
), si_list
),
456 offsetof(typeof(*u
.si
), si_sa
),
457 //offsetof(typeof(*u.si), si_lvma_lock),
458 //offsetof(typeof(*u.si), si_lvma),
460 pr_info("destr{len %d, name %d} %d\n",
461 offsetof(typeof(*u
.destr
), len
),
462 offsetof(typeof(*u
.destr
), name
),
464 pr_info("de{ino %d, type %d, str %d} %d\n",
465 offsetof(typeof(*u
.de
), de_ino
),
466 offsetof(typeof(*u
.de
), de_type
),
467 offsetof(typeof(*u
.de
), de_str
),
469 pr_info("wh{hash %d, bindex %d, str %d} %d\n",
470 offsetof(typeof(*u
.wh
), wh_hash
),
471 offsetof(typeof(*u
.wh
), wh_bindex
),
472 offsetof(typeof(*u
.wh
), wh_str
),
474 pr_info("vd{deblk %d, nblk %d, last %d, ver %d, jiffy %d} %d\n",
475 offsetof(typeof(*u
.vd
), vd_deblk
),
476 offsetof(typeof(*u
.vd
), vd_nblk
),
477 offsetof(typeof(*u
.vd
), vd_last
),
478 offsetof(typeof(*u
.vd
), vd_version
),
479 offsetof(typeof(*u
.vd
), vd_jiffy
),