2
* Copyright (C) 2005-2009 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
23
#include <linux/debugfs.h>
27
#error DEBUG_FS depends upon SYSFS
30
static struct dentry *dbgaufs;
31
static const mode_t dbgaufs_mode = S_IRUSR | S_IRGRP | S_IROTH;
33
/* 20 is max digits length of ulong 64 */
40
* common function for all XINO files
42
static int dbgaufs_xi_release(struct inode *inode __maybe_unused,
45
kfree(file->private_data);
49
static int dbgaufs_xi_open(struct file *xf, struct file *file, int do_fcnt)
53
struct dbgaufs_arg *p;
56
p = kmalloc(sizeof(*p), GFP_NOFS);
62
file->private_data = p;
66
err = vfs_getattr(xf->f_vfsmnt, xf->f_dentry, &st);
70
(p->a, sizeof(p->a), "%ld, %llux%lu %lld\n",
71
(long)file_count(xf), st.blocks, st.blksize,
74
p->n = snprintf(p->a, sizeof(p->a), "%llux%lu %lld\n",
75
st.blocks, st.blksize,
77
AuDebugOn(p->n >= sizeof(p->a));
79
p->n = snprintf(p->a, sizeof(p->a), "err %d\n", err);
88
static ssize_t dbgaufs_xi_read(struct file *file, char __user *buf,
89
size_t count, loff_t *ppos)
91
struct dbgaufs_arg *p;
93
p = file->private_data;
94
return simple_read_from_buffer(buf, count, ppos, p->a, p->n);
97
/* ---------------------------------------------------------------------- */
99
static int dbgaufs_xib_open(struct inode *inode, struct file *file)
102
struct au_sbinfo *sbinfo;
103
struct super_block *sb;
105
sbinfo = inode->i_private;
107
si_noflush_read_lock(sb);
108
err = dbgaufs_xi_open(sbinfo->si_xib, file, /*do_fcnt*/0);
113
static const struct file_operations dbgaufs_xib_fop = {
114
.open = dbgaufs_xib_open,
115
.release = dbgaufs_xi_release,
116
.read = dbgaufs_xi_read
119
/* ---------------------------------------------------------------------- */
121
#define DbgaufsXi_PREFIX "xi"
123
static int dbgaufs_xino_open(struct inode *inode, struct file *file)
127
struct au_sbinfo *sbinfo;
128
struct super_block *sb;
134
name = &file->f_dentry->d_name;
135
if (unlikely(name->len < sizeof(DbgaufsXi_PREFIX)
136
|| memcmp(name->name, DbgaufsXi_PREFIX,
137
sizeof(DbgaufsXi_PREFIX) - 1)))
139
err = strict_strtol(name->name + sizeof(DbgaufsXi_PREFIX) - 1, 10, &l);
143
sbinfo = inode->i_private;
145
si_noflush_read_lock(sb);
146
if (l <= au_sbend(sb)) {
147
xf = au_sbr(sb, (aufs_bindex_t)l)->br_xino.xi_file;
148
err = dbgaufs_xi_open(xf, file, /*do_fcnt*/1);
157
static const struct file_operations dbgaufs_xino_fop = {
158
.open = dbgaufs_xino_open,
159
.release = dbgaufs_xi_release,
160
.read = dbgaufs_xi_read
163
void dbgaufs_brs_del(struct super_block *sb, aufs_bindex_t bindex)
166
struct au_branch *br;
167
struct au_xino_file *xi;
169
if (!au_sbi(sb)->si_dbgaufs)
173
for (; bindex <= bend; bindex++) {
174
br = au_sbr(sb, bindex);
176
if (xi->xi_dbgaufs) {
177
debugfs_remove(xi->xi_dbgaufs);
178
xi->xi_dbgaufs = NULL;
183
void dbgaufs_brs_add(struct super_block *sb, aufs_bindex_t bindex)
185
struct au_sbinfo *sbinfo;
186
struct dentry *parent;
187
struct au_branch *br;
188
struct au_xino_file *xi;
190
char name[sizeof(DbgaufsXi_PREFIX) + 5]; /* "xi" bindex NULL */
193
parent = sbinfo->si_dbgaufs;
198
for (; bindex <= bend; bindex++) {
199
snprintf(name, sizeof(name), DbgaufsXi_PREFIX "%d", bindex);
200
br = au_sbr(sb, bindex);
202
AuDebugOn(xi->xi_dbgaufs);
203
xi->xi_dbgaufs = debugfs_create_file(name, dbgaufs_mode, parent,
204
sbinfo, &dbgaufs_xino_fop);
205
/* ignore an error */
206
if (unlikely(!xi->xi_dbgaufs))
207
AuWarn1("failed %s under debugfs\n", name);
211
/* ---------------------------------------------------------------------- */
213
#ifdef CONFIG_AUFS_EXPORT
214
static int dbgaufs_xigen_open(struct inode *inode, struct file *file)
217
struct au_sbinfo *sbinfo;
218
struct super_block *sb;
220
sbinfo = inode->i_private;
222
si_noflush_read_lock(sb);
223
err = dbgaufs_xi_open(sbinfo->si_xigen, file, /*do_fcnt*/0);
228
static const struct file_operations dbgaufs_xigen_fop = {
229
.open = dbgaufs_xigen_open,
230
.release = dbgaufs_xi_release,
231
.read = dbgaufs_xi_read
234
static int dbgaufs_xigen_init(struct au_sbinfo *sbinfo)
239
* This function is a dynamic '__init' fucntion actually,
240
* so the tiny check for si_rwsem is unnecessary.
242
/* AuRwMustWriteLock(&sbinfo->si_rwsem); */
245
sbinfo->si_dbgaufs_xigen = debugfs_create_file
246
("xigen", dbgaufs_mode, sbinfo->si_dbgaufs, sbinfo,
248
if (sbinfo->si_dbgaufs_xigen)
254
static int dbgaufs_xigen_init(struct au_sbinfo *sbinfo)
258
#endif /* CONFIG_AUFS_EXPORT */
260
/* ---------------------------------------------------------------------- */
262
void dbgaufs_si_fin(struct au_sbinfo *sbinfo)
265
* This function is a dynamic '__init' fucntion actually,
266
* so the tiny check for si_rwsem is unnecessary.
268
/* AuRwMustWriteLock(&sbinfo->si_rwsem); */
270
debugfs_remove_recursive(sbinfo->si_dbgaufs);
271
sbinfo->si_dbgaufs = NULL;
272
kobject_put(&sbinfo->si_kobj);
275
int dbgaufs_si_init(struct au_sbinfo *sbinfo)
278
char name[SysaufsSiNameLen];
281
* This function is a dynamic '__init' fucntion actually,
282
* so the tiny check for si_rwsem is unnecessary.
284
/* AuRwMustWriteLock(&sbinfo->si_rwsem); */
288
AuErr1("/debug/aufs is uninitialized\n");
293
sysaufs_name(sbinfo, name);
294
sbinfo->si_dbgaufs = debugfs_create_dir(name, dbgaufs);
295
if (unlikely(!sbinfo->si_dbgaufs))
297
kobject_get(&sbinfo->si_kobj);
299
sbinfo->si_dbgaufs_xib = debugfs_create_file
300
("xib", dbgaufs_mode, sbinfo->si_dbgaufs, sbinfo,
302
if (unlikely(!sbinfo->si_dbgaufs_xib))
305
err = dbgaufs_xigen_init(sbinfo);
307
goto out; /* success */
310
dbgaufs_si_fin(sbinfo);
315
/* ---------------------------------------------------------------------- */
317
void dbgaufs_fin(void)
319
debugfs_remove(dbgaufs);
322
int __init dbgaufs_init(void)
327
dbgaufs = debugfs_create_dir(AUFS_NAME, NULL);