2 * Copyright (C) 2005-2016 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, see <http://www.gnu.org/licenses/>.
19 * debug print functions
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
)
29 err
= kstrtoint(val
, 0, &n
);
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
)
45 return sprintf(buffer
, "%d", atomic_read(a
));
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) */
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
);
58 DEFINE_MUTEX(au_dbg_mtx
); /* just to serialize the dbg msgs */
59 char *au_plevel
= KERN_DEBUG
;
60 #define dpri(fmt, ...) do { \
62 && strcmp(au_plevel, KERN_DEBUG)) \
64 printk("%s" fmt, au_plevel, ##__VA_ARGS__); \
67 /* ---------------------------------------------------------------------- */
69 void au_dpri_whlist(struct au_nhash
*whlist
)
72 struct hlist_head
*head
;
73 struct au_vdir_wh
*pos
;
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",
81 pos
->wh_str
.len
, pos
->wh_str
.name
,
87 void au_dpri_vdir(struct au_vdir
*vdir
)
90 union au_vdir_deblk_p p
;
93 if (!vdir
|| IS_ERR(vdir
)) {
94 dpri("err %ld\n", PTR_ERR(vdir
));
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
];
104 dpri("[%lu]: %p\n", ul
, o
);
108 static int do_pri_inode(aufs_bindex_t bindex
, struct inode
*inode
, int hn
,
114 if (!inode
|| IS_ERR(inode
)) {
115 dpri("i%d: err %ld\n", bindex
, PTR_ERR(inode
));
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
));
123 n
= (void *)wh
->d_name
.name
;
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",
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
,
137 l
? ", wh " : "", l
, n
);
141 void au_dpri_inode(struct inode
*inode
)
143 struct au_iinfo
*iinfo
;
144 struct au_hinode
*hi
;
145 aufs_bindex_t bindex
;
148 err
= do_pri_inode(-1, inode
, -1, NULL
);
149 if (err
|| !au_test_aufs(inode
->i_sb
) || au_is_bad_inode(inode
))
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)
158 for (bindex
= iinfo
->ii_btop
; bindex
<= iinfo
->ii_bbot
; bindex
++) {
159 hi
= au_hinode(iinfo
, bindex
);
161 do_pri_inode(bindex
, hi
->hi_inode
, hn
, hi
->hi_whdentry
);
165 void au_dpri_dalias(struct inode
*inode
)
169 spin_lock(&inode
->i_lock
);
170 hlist_for_each_entry(d
, &inode
->i_dentry
, d_u
.d_alias
)
172 spin_unlock(&inode
->i_lock
);
175 static int do_pri_dentry(aufs_bindex_t bindex
, struct dentry
*dentry
)
177 struct dentry
*wh
= NULL
;
180 struct au_iinfo
*iinfo
;
181 struct au_hinode
*hi
;
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: %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" : "");
196 if (d_is_positive(dentry
))
197 inode
= d_inode(dentry
);
199 && au_test_aufs(dentry
->d_sb
)
201 && !au_is_bad_inode(inode
)) {
202 iinfo
= au_ii(inode
);
203 hi
= au_hinode(iinfo
, bindex
);
205 wh
= hi
->hi_whdentry
;
207 do_pri_inode(bindex
, inode
, hn
, wh
);
211 void au_dpri_dentry(struct dentry
*dentry
)
213 struct au_dinfo
*dinfo
;
214 aufs_bindex_t bindex
;
217 err
= do_pri_dentry(-1, dentry
);
218 if (err
|| !au_test_aufs(dentry
->d_sb
))
221 dinfo
= au_di(dentry
);
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
),
228 if (dinfo
->di_btop
< 0)
230 for (bindex
= dinfo
->di_btop
; bindex
<= dinfo
->di_bbot
; bindex
++)
231 do_pri_dentry(bindex
, au_hdentry(dinfo
, bindex
)->hd_dentry
);
234 static int do_pri_file(aufs_bindex_t bindex
, struct file
*file
)
238 if (!file
|| IS_ERR(file
)) {
239 dpri("f%d: err %ld\n", bindex
, PTR_ERR(file
));
244 && !IS_ERR_OR_NULL(file
->f_path
.dentry
)
245 && au_test_aufs(file
->f_path
.dentry
->d_sb
)
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
);
257 void au_dpri_file(struct file
*file
)
259 struct au_finfo
*finfo
;
260 struct au_fidir
*fidir
;
261 struct au_hfile
*hfile
;
262 aufs_bindex_t bindex
;
265 err
= do_pri_file(-1, file
);
267 || IS_ERR_OR_NULL(file
->f_path
.dentry
)
268 || !au_test_aufs(file
->f_path
.dentry
->d_sb
))
274 if (finfo
->fi_btop
< 0)
276 fidir
= finfo
->fi_hdir
;
278 do_pri_file(finfo
->fi_btop
, finfo
->fi_htop
.hf_file
);
280 for (bindex
= finfo
->fi_btop
;
281 bindex
>= 0 && bindex
<= fidir
->fd_bbot
;
283 hfile
= fidir
->fd_hfile
+ bindex
;
284 do_pri_file(bindex
, hfile
? hfile
->hf_file
: NULL
);
288 static int do_pri_br(aufs_bindex_t bindex
, struct au_branch
*br
)
290 struct vfsmount
*mnt
;
291 struct super_block
*sb
;
293 if (!br
|| IS_ERR(br
))
296 if (!mnt
|| IS_ERR(mnt
))
299 if (!sb
|| IS_ERR(sb
))
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, "
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
);
312 dpri("s%d: err %ld\n", bindex
, PTR_ERR(br
));
316 void au_dpri_sb(struct super_block
*sb
)
318 struct au_sbinfo
*sbinfo
;
319 aufs_bindex_t bindex
;
321 /* to reuduce stack size */
324 struct au_branch fake
;
327 /* this function can be called from magic sysrq */
328 a
= kzalloc(sizeof(*a
), GFP_ATOMIC
);
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
);
340 dpri("dev 0x%x\n", sb
->s_dev
);
341 if (err
|| !au_test_aufs(sb
))
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
]);
354 /* ---------------------------------------------------------------------- */
356 void __au_dbg_verify_dinode(struct dentry
*dentry
, const char *func
, int line
)
358 struct inode
*h_inode
, *inode
= d_inode(dentry
);
359 struct dentry
*h_dentry
;
360 aufs_bindex_t bindex
, bbot
, bi
;
362 if (!inode
/* || au_di(dentry)->di_lsc == AuLsc_DI_TMP */)
365 bbot
= au_dbbot(dentry
);
366 bi
= au_ibbot(inode
);
369 bindex
= au_dbtop(dentry
);
370 bi
= au_ibtop(inode
);
374 for (; bindex
<= bbot
; bindex
++) {
375 h_dentry
= au_h_dptr(dentry
, bindex
);
378 h_inode
= au_h_iptr(inode
, bindex
);
379 if (unlikely(h_inode
!= d_inode(h_dentry
))) {
381 AuDbg("b%d, %s:%d\n", bindex
, func
, line
);
390 void au_dbg_verify_gen(struct dentry
*parent
, unsigned int sigen
)
393 struct au_dcsub_pages dpages
;
394 struct au_dpage
*dpage
;
395 struct dentry
**dentries
;
397 err
= au_dpages_init(&dpages
, GFP_NOFS
);
399 err
= au_dcsub_pages_rev_aufs(&dpages
, parent
, /*do_include*/1);
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
));
407 au_dpages_free(&dpages
);
410 void au_dbg_verify_kthread(void)
415 * It may be recursive, but udba=notify between two aufs mounts,
416 * where a single ro branch is shared, is not a problem.
422 /* ---------------------------------------------------------------------- */
424 int __init
au_debug_init(void)
426 aufs_bindex_t bindex
;
427 struct au_vdir_destr destr
;
430 AuDebugOn(bindex
>= 0);
433 AuDebugOn(destr
.len
< NAME_MAX
);
435 #ifdef CONFIG_4KSTACKS
436 pr_warn("CONFIG_4KSTACKS is defined.\n");