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
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 .owner = THIS_MODULE,
115 .open = dbgaufs_xib_open,
116 .release = dbgaufs_xi_release,
117 .read = dbgaufs_xi_read
120 /* ---------------------------------------------------------------------- */
122 #define DbgaufsXi_PREFIX "xi"
124 static int dbgaufs_xino_open(struct inode *inode, struct file *file)
128 struct au_sbinfo *sbinfo;
129 struct super_block *sb;
135 name = &file->f_dentry->d_name;
136 if (unlikely(name->len < sizeof(DbgaufsXi_PREFIX)
137 || memcmp(name->name, DbgaufsXi_PREFIX,
138 sizeof(DbgaufsXi_PREFIX) - 1)))
140 err = kstrtol(name->name + sizeof(DbgaufsXi_PREFIX) - 1, 10, &l);
144 sbinfo = inode->i_private;
146 si_noflush_read_lock(sb);
147 if (l <= au_sbend(sb)) {
148 xf = au_sbr(sb, (aufs_bindex_t)l)->br_xino.xi_file;
149 err = dbgaufs_xi_open(xf, file, /*do_fcnt*/1);
158 static const struct file_operations dbgaufs_xino_fop = {
159 .owner = THIS_MODULE,
160 .open = dbgaufs_xino_open,
161 .release = dbgaufs_xi_release,
162 .read = dbgaufs_xi_read
165 void dbgaufs_brs_del(struct super_block *sb, aufs_bindex_t bindex)
168 struct au_branch *br;
169 struct au_xino_file *xi;
171 if (!au_sbi(sb)->si_dbgaufs)
175 for (; bindex <= bend; bindex++) {
176 br = au_sbr(sb, bindex);
178 if (xi->xi_dbgaufs) {
179 debugfs_remove(xi->xi_dbgaufs);
180 xi->xi_dbgaufs = NULL;
185 void dbgaufs_brs_add(struct super_block *sb, aufs_bindex_t bindex)
187 struct au_sbinfo *sbinfo;
188 struct dentry *parent;
189 struct au_branch *br;
190 struct au_xino_file *xi;
192 char name[sizeof(DbgaufsXi_PREFIX) + 5]; /* "xi" bindex NULL */
195 parent = sbinfo->si_dbgaufs;
200 for (; bindex <= bend; bindex++) {
201 snprintf(name, sizeof(name), DbgaufsXi_PREFIX "%d", bindex);
202 br = au_sbr(sb, bindex);
204 AuDebugOn(xi->xi_dbgaufs);
205 xi->xi_dbgaufs = debugfs_create_file(name, dbgaufs_mode, parent,
206 sbinfo, &dbgaufs_xino_fop);
207 /* ignore an error */
208 if (unlikely(!xi->xi_dbgaufs))
209 AuWarn1("failed %s under debugfs\n", name);
213 /* ---------------------------------------------------------------------- */
215 #ifdef CONFIG_AUFS_EXPORT
216 static int dbgaufs_xigen_open(struct inode *inode, struct file *file)
219 struct au_sbinfo *sbinfo;
220 struct super_block *sb;
222 sbinfo = inode->i_private;
224 si_noflush_read_lock(sb);
225 err = dbgaufs_xi_open(sbinfo->si_xigen, file, /*do_fcnt*/0);
230 static const struct file_operations dbgaufs_xigen_fop = {
231 .owner = THIS_MODULE,
232 .open = dbgaufs_xigen_open,
233 .release = dbgaufs_xi_release,
234 .read = dbgaufs_xi_read
237 static int dbgaufs_xigen_init(struct au_sbinfo *sbinfo)
242 * This function is a dynamic '__init' fucntion actually,
243 * so the tiny check for si_rwsem is unnecessary.
245 /* AuRwMustWriteLock(&sbinfo->si_rwsem); */
248 sbinfo->si_dbgaufs_xigen = debugfs_create_file
249 ("xigen", dbgaufs_mode, sbinfo->si_dbgaufs, sbinfo,
251 if (sbinfo->si_dbgaufs_xigen)
257 static int dbgaufs_xigen_init(struct au_sbinfo *sbinfo)
261 #endif /* CONFIG_AUFS_EXPORT */
263 /* ---------------------------------------------------------------------- */
265 void dbgaufs_si_fin(struct au_sbinfo *sbinfo)
268 * This function is a dynamic '__init' fucntion actually,
269 * so the tiny check for si_rwsem is unnecessary.
271 /* AuRwMustWriteLock(&sbinfo->si_rwsem); */
273 debugfs_remove_recursive(sbinfo->si_dbgaufs);
274 sbinfo->si_dbgaufs = NULL;
275 kobject_put(&sbinfo->si_kobj);
278 int dbgaufs_si_init(struct au_sbinfo *sbinfo)
281 char name[SysaufsSiNameLen];
284 * This function is a dynamic '__init' fucntion actually,
285 * so the tiny check for si_rwsem is unnecessary.
287 /* AuRwMustWriteLock(&sbinfo->si_rwsem); */
291 AuErr1("/debug/aufs is uninitialized\n");
296 sysaufs_name(sbinfo, name);
297 sbinfo->si_dbgaufs = debugfs_create_dir(name, dbgaufs);
298 if (unlikely(!sbinfo->si_dbgaufs))
300 kobject_get(&sbinfo->si_kobj);
302 sbinfo->si_dbgaufs_xib = debugfs_create_file
303 ("xib", dbgaufs_mode, sbinfo->si_dbgaufs, sbinfo,
305 if (unlikely(!sbinfo->si_dbgaufs_xib))
308 err = dbgaufs_xigen_init(sbinfo);
310 goto out; /* success */
313 dbgaufs_si_fin(sbinfo);
318 /* ---------------------------------------------------------------------- */
320 void dbgaufs_fin(void)
322 debugfs_remove(dbgaufs);
325 int __init dbgaufs_init(void)
330 dbgaufs = debugfs_create_dir(AUFS_NAME, NULL);