1 // SPDX-License-Identifier: GPL-2.0
3 * Copyright (C) 2005-2021 Junjiro R. Okajima
5 * This program, aufs is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with this program. If not, see <http://www.gnu.org/licenses/>.
20 * debug print functions
23 #include <linux/iversion.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
, 0664);
60 DEFINE_MUTEX(au_dbg_mtx
); /* just to serialize the dbg msgs */
61 char *au_plevel
= KERN_DEBUG
;
62 #define dpri(fmt, ...) do { \
64 && strcmp(au_plevel, KERN_DEBUG)) \
66 printk("%s" fmt, au_plevel, ##__VA_ARGS__); \
69 /* ---------------------------------------------------------------------- */
71 void au_dpri_whlist(struct au_nhash
*whlist
)
74 struct hlist_head
*head
;
75 struct au_vdir_wh
*pos
;
78 head
= whlist
->nh_head
;
79 for (ul
= 0; ul
< n
; ul
++) {
80 hlist_for_each_entry(pos
, head
, wh_hash
)
81 dpri("b%d, %.*s, %d\n",
83 pos
->wh_str
.len
, pos
->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 %llu\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)timespec64_to_ns(&inode
->i_ctime
) & 0x0ffff,
136 inode
->i_mapping
? inode
->i_mapping
->nrpages
: 0,
137 inode
->i_state
, inode
->i_flags
, inode_peek_iversion(inode
),
139 l
? ", wh " : "", l
, n
);
143 void au_dpri_inode(struct inode
*inode
)
145 struct au_iinfo
*iinfo
;
146 struct au_hinode
*hi
;
147 aufs_bindex_t bindex
;
150 err
= do_pri_inode(-1, inode
, -1, NULL
);
151 if (err
|| !au_test_aufs(inode
->i_sb
) || au_is_bad_inode(inode
))
154 iinfo
= au_ii(inode
);
155 dpri("i-1: btop %d, bbot %d, gen %d\n",
156 iinfo
->ii_btop
, iinfo
->ii_bbot
, au_iigen(inode
, NULL
));
157 if (iinfo
->ii_btop
< 0)
160 for (bindex
= iinfo
->ii_btop
; bindex
<= iinfo
->ii_bbot
; bindex
++) {
161 hi
= au_hinode(iinfo
, bindex
);
163 do_pri_inode(bindex
, hi
->hi_inode
, hn
, hi
->hi_whdentry
);
167 void au_dpri_dalias(struct inode
*inode
)
171 spin_lock(&inode
->i_lock
);
172 hlist_for_each_entry(d
, &inode
->i_dentry
, d_u
.d_alias
)
174 spin_unlock(&inode
->i_lock
);
177 static int do_pri_dentry(aufs_bindex_t bindex
, struct dentry
*dentry
)
179 struct dentry
*wh
= NULL
;
182 struct au_iinfo
*iinfo
;
183 struct au_hinode
*hi
;
185 if (!dentry
|| IS_ERR(dentry
)) {
186 dpri("d%d: err %ld\n", bindex
, PTR_ERR(dentry
));
189 /* do not call dget_parent() here */
190 /* note: access d_xxx without d_lock */
191 dpri("d%d: %p, %pd2?, %s, cnt %d, flags 0x%x, %shashed\n",
192 bindex
, dentry
, dentry
,
193 dentry
->d_sb
? au_sbtype(dentry
->d_sb
) : "??",
194 au_dcount(dentry
), dentry
->d_flags
,
195 d_unhashed(dentry
) ? "un" : "");
198 if (d_is_positive(dentry
))
199 inode
= d_inode(dentry
);
201 && au_test_aufs(dentry
->d_sb
)
203 && !au_is_bad_inode(inode
)) {
204 iinfo
= au_ii(inode
);
205 hi
= au_hinode(iinfo
, bindex
);
207 wh
= hi
->hi_whdentry
;
209 do_pri_inode(bindex
, inode
, hn
, wh
);
213 void au_dpri_dentry(struct dentry
*dentry
)
215 struct au_dinfo
*dinfo
;
216 aufs_bindex_t bindex
;
219 err
= do_pri_dentry(-1, dentry
);
220 if (err
|| !au_test_aufs(dentry
->d_sb
))
223 dinfo
= au_di(dentry
);
226 dpri("d-1: btop %d, bbot %d, bwh %d, bdiropq %d, gen %d, tmp %d\n",
227 dinfo
->di_btop
, dinfo
->di_bbot
,
228 dinfo
->di_bwh
, dinfo
->di_bdiropq
, au_digen(dentry
),
230 if (dinfo
->di_btop
< 0)
232 for (bindex
= dinfo
->di_btop
; bindex
<= dinfo
->di_bbot
; bindex
++)
233 do_pri_dentry(bindex
, au_hdentry(dinfo
, bindex
)->hd_dentry
);
236 static int do_pri_file(aufs_bindex_t bindex
, struct file
*file
)
240 if (!file
|| IS_ERR(file
)) {
241 dpri("f%d: err %ld\n", bindex
, PTR_ERR(file
));
246 && !IS_ERR_OR_NULL(file
->f_path
.dentry
)
247 && au_test_aufs(file
->f_path
.dentry
->d_sb
)
249 snprintf(a
, sizeof(a
), ", gen %d, mmapped %d",
250 au_figen(file
), atomic_read(&au_fi(file
)->fi_mmapped
));
251 dpri("f%d: mode 0x%x, flags 0%o, cnt %ld, v %llu, pos %llu%s\n",
252 bindex
, file
->f_mode
, file
->f_flags
, (long)file_count(file
),
253 file
->f_version
, file
->f_pos
, a
);
254 if (!IS_ERR_OR_NULL(file
->f_path
.dentry
))
255 do_pri_dentry(bindex
, file
->f_path
.dentry
);
259 void au_dpri_file(struct file
*file
)
261 struct au_finfo
*finfo
;
262 struct au_fidir
*fidir
;
263 struct au_hfile
*hfile
;
264 aufs_bindex_t bindex
;
267 err
= do_pri_file(-1, file
);
269 || IS_ERR_OR_NULL(file
->f_path
.dentry
)
270 || !au_test_aufs(file
->f_path
.dentry
->d_sb
))
276 if (finfo
->fi_btop
< 0)
278 fidir
= finfo
->fi_hdir
;
280 do_pri_file(finfo
->fi_btop
, finfo
->fi_htop
.hf_file
);
282 for (bindex
= finfo
->fi_btop
;
283 bindex
>= 0 && bindex
<= fidir
->fd_bbot
;
285 hfile
= fidir
->fd_hfile
+ bindex
;
286 do_pri_file(bindex
, hfile
? hfile
->hf_file
: NULL
);
290 static int do_pri_br(aufs_bindex_t bindex
, struct au_branch
*br
)
292 struct vfsmount
*mnt
;
293 struct super_block
*sb
;
295 if (!br
|| IS_ERR(br
))
298 if (!mnt
|| IS_ERR(mnt
))
301 if (!sb
|| IS_ERR(sb
))
304 dpri("s%d: {perm 0x%x, id %d, wbr %p}, "
305 "%s, dev 0x%02x%02x, flags 0x%lx, cnt %d, active %d, "
307 bindex
, br
->br_perm
, br
->br_id
, br
->br_wbr
,
308 au_sbtype(sb
), MAJOR(sb
->s_dev
), MINOR(sb
->s_dev
),
309 sb
->s_flags
, sb
->s_count
,
310 atomic_read(&sb
->s_active
),
311 !!au_xino_file(br
->br_xino
, /*idx*/-1));
315 dpri("s%d: err %ld\n", bindex
, PTR_ERR(br
));
319 void au_dpri_sb(struct super_block
*sb
)
321 struct au_sbinfo
*sbinfo
;
322 aufs_bindex_t bindex
;
324 /* to reduce stack size */
327 struct au_branch fake
;
330 /* this function can be called from magic sysrq */
331 a
= kzalloc(sizeof(*a
), GFP_ATOMIC
);
338 a
->fake
.br_path
.mnt
= &a
->mnt
;
339 err
= do_pri_br(-1, &a
->fake
);
341 dpri("dev 0x%x\n", sb
->s_dev
);
342 if (err
|| !au_test_aufs(sb
))
348 dpri("nw %d, gen %u, kobj %d\n",
349 atomic_read(&sbinfo
->si_nowait
.nw_len
), sbinfo
->si_generation
,
350 kref_read(&sbinfo
->si_kobj
.kref
));
351 for (bindex
= 0; bindex
<= sbinfo
->si_bbot
; bindex
++)
352 do_pri_br(bindex
, sbinfo
->si_branch
[0 + bindex
]);
355 /* ---------------------------------------------------------------------- */
357 void __au_dbg_verify_dinode(struct dentry
*dentry
, const char *func
, int line
)
359 struct inode
*h_inode
, *inode
= d_inode(dentry
);
360 struct dentry
*h_dentry
;
361 aufs_bindex_t bindex
, bbot
, bi
;
363 if (!inode
/* || au_di(dentry)->di_lsc == AuLsc_DI_TMP */)
366 bbot
= au_dbbot(dentry
);
367 bi
= au_ibbot(inode
);
370 bindex
= au_dbtop(dentry
);
371 bi
= au_ibtop(inode
);
375 for (; bindex
<= bbot
; bindex
++) {
376 h_dentry
= au_h_dptr(dentry
, bindex
);
379 h_inode
= au_h_iptr(inode
, bindex
);
380 if (unlikely(h_inode
!= d_inode(h_dentry
))) {
382 AuDbg("b%d, %s:%d\n", bindex
, func
, line
);
386 if (au_test_fuse(h_inode
->i_sb
))
394 void au_dbg_verify_gen(struct dentry
*parent
, unsigned int sigen
)
397 struct au_dcsub_pages dpages
;
398 struct au_dpage
*dpage
;
399 struct dentry
**dentries
;
401 err
= au_dpages_init(&dpages
, GFP_NOFS
);
403 err
= au_dcsub_pages_rev_aufs(&dpages
, parent
, /*do_include*/1);
405 for (i
= dpages
.ndpage
- 1; !err
&& i
>= 0; i
--) {
406 dpage
= dpages
.dpages
+ i
;
407 dentries
= dpage
->dentries
;
408 for (j
= dpage
->ndentry
- 1; !err
&& j
>= 0; j
--)
409 AuDebugOn(au_digen_test(dentries
[j
], sigen
));
411 au_dpages_free(&dpages
);
414 void au_dbg_verify_kthread(void)
419 * It may be recursive, but udba=notify between two aufs mounts,
420 * where a single ro branch is shared, is not a problem.
426 /* ---------------------------------------------------------------------- */
428 int __init
au_debug_init(void)
430 aufs_bindex_t bindex
;
431 struct au_vdir_destr destr
;
434 AuDebugOn(bindex
>= 0);
437 AuDebugOn(destr
.len
< NAME_MAX
);
439 #ifdef CONFIG_4KSTACKS
440 pr_warn("CONFIG_4KSTACKS is defined.\n");