~ubuntu-branches/ubuntu/precise/linux-ti-omap/precise

« back to all changes in this revision

Viewing changes to ubuntu/aufs/dbgaufs.c

  • Committer: Bazaar Package Importer
  • Author(s): Stefan Bader, Amit Kucheria
  • Date: 2010-03-23 18:05:12 UTC
  • Revision ID: james.westby@ubuntu.com-20100323180512-iavj906ocnphdubp
Tags: 2.6.33-500.3
[ Amit Kucheria ]

* [Config] Fix the debug package name to end in -dbgsym
* SAUCE: Add the ubuntu/ drivers to omap
* SAUCE: Re-export the symbols for aufs
* [Config] Enable AUFS and COMPCACHE

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 * Copyright (C) 2005-2009 Junjiro R. Okajima
 
3
 *
 
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.
 
8
 *
 
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.
 
13
 *
 
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
 
17
 */
 
18
 
 
19
/*
 
20
 * debugfs interface
 
21
 */
 
22
 
 
23
#include <linux/debugfs.h>
 
24
#include "aufs.h"
 
25
 
 
26
#ifndef CONFIG_SYSFS
 
27
#error DEBUG_FS depends upon SYSFS
 
28
#endif
 
29
 
 
30
static struct dentry *dbgaufs;
 
31
static const mode_t dbgaufs_mode = S_IRUSR | S_IRGRP | S_IROTH;
 
32
 
 
33
/* 20 is max digits length of ulong 64 */
 
34
struct dbgaufs_arg {
 
35
        int n;
 
36
        char a[20 * 4];
 
37
};
 
38
 
 
39
/*
 
40
 * common function for all XINO files
 
41
 */
 
42
static int dbgaufs_xi_release(struct inode *inode __maybe_unused,
 
43
                              struct file *file)
 
44
{
 
45
        kfree(file->private_data);
 
46
        return 0;
 
47
}
 
48
 
 
49
static int dbgaufs_xi_open(struct file *xf, struct file *file, int do_fcnt)
 
50
{
 
51
        int err;
 
52
        struct kstat st;
 
53
        struct dbgaufs_arg *p;
 
54
 
 
55
        err = -ENOMEM;
 
56
        p = kmalloc(sizeof(*p), GFP_NOFS);
 
57
        if (unlikely(!p))
 
58
                goto out;
 
59
 
 
60
        err = 0;
 
61
        p->n = 0;
 
62
        file->private_data = p;
 
63
        if (!xf)
 
64
                goto out;
 
65
 
 
66
        err = vfs_getattr(xf->f_vfsmnt, xf->f_dentry, &st);
 
67
        if (!err) {
 
68
                if (do_fcnt)
 
69
                        p->n = snprintf
 
70
                                (p->a, sizeof(p->a), "%ld, %llux%lu %lld\n",
 
71
                                 (long)file_count(xf), st.blocks, st.blksize,
 
72
                                 (long long)st.size);
 
73
                else
 
74
                        p->n = snprintf(p->a, sizeof(p->a), "%llux%lu %lld\n",
 
75
                                        st.blocks, st.blksize,
 
76
                                        (long long)st.size);
 
77
                AuDebugOn(p->n >= sizeof(p->a));
 
78
        } else {
 
79
                p->n = snprintf(p->a, sizeof(p->a), "err %d\n", err);
 
80
                err = 0;
 
81
        }
 
82
 
 
83
 out:
 
84
        return err;
 
85
 
 
86
}
 
87
 
 
88
static ssize_t dbgaufs_xi_read(struct file *file, char __user *buf,
 
89
                               size_t count, loff_t *ppos)
 
90
{
 
91
        struct dbgaufs_arg *p;
 
92
 
 
93
        p = file->private_data;
 
94
        return simple_read_from_buffer(buf, count, ppos, p->a, p->n);
 
95
}
 
96
 
 
97
/* ---------------------------------------------------------------------- */
 
98
 
 
99
static int dbgaufs_xib_open(struct inode *inode, struct file *file)
 
100
{
 
101
        int err;
 
102
        struct au_sbinfo *sbinfo;
 
103
        struct super_block *sb;
 
104
 
 
105
        sbinfo = inode->i_private;
 
106
        sb = sbinfo->si_sb;
 
107
        si_noflush_read_lock(sb);
 
108
        err = dbgaufs_xi_open(sbinfo->si_xib, file, /*do_fcnt*/0);
 
109
        si_read_unlock(sb);
 
110
        return err;
 
111
}
 
112
 
 
113
static const struct file_operations dbgaufs_xib_fop = {
 
114
        .open           = dbgaufs_xib_open,
 
115
        .release        = dbgaufs_xi_release,
 
116
        .read           = dbgaufs_xi_read
 
117
};
 
118
 
 
119
/* ---------------------------------------------------------------------- */
 
120
 
 
121
#define DbgaufsXi_PREFIX "xi"
 
122
 
 
123
static int dbgaufs_xino_open(struct inode *inode, struct file *file)
 
124
{
 
125
        int err;
 
126
        long l;
 
127
        struct au_sbinfo *sbinfo;
 
128
        struct super_block *sb;
 
129
        struct file *xf;
 
130
        struct qstr *name;
 
131
 
 
132
        err = -ENOENT;
 
133
        xf = NULL;
 
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)))
 
138
                goto out;
 
139
        err = strict_strtol(name->name + sizeof(DbgaufsXi_PREFIX) - 1, 10, &l);
 
140
        if (unlikely(err))
 
141
                goto out;
 
142
 
 
143
        sbinfo = inode->i_private;
 
144
        sb = sbinfo->si_sb;
 
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);
 
149
        } else
 
150
                err = -ENOENT;
 
151
        si_read_unlock(sb);
 
152
 
 
153
 out:
 
154
        return err;
 
155
}
 
156
 
 
157
static const struct file_operations dbgaufs_xino_fop = {
 
158
        .open           = dbgaufs_xino_open,
 
159
        .release        = dbgaufs_xi_release,
 
160
        .read           = dbgaufs_xi_read
 
161
};
 
162
 
 
163
void dbgaufs_brs_del(struct super_block *sb, aufs_bindex_t bindex)
 
164
{
 
165
        aufs_bindex_t bend;
 
166
        struct au_branch *br;
 
167
        struct au_xino_file *xi;
 
168
 
 
169
        if (!au_sbi(sb)->si_dbgaufs)
 
170
                return;
 
171
 
 
172
        bend = au_sbend(sb);
 
173
        for (; bindex <= bend; bindex++) {
 
174
                br = au_sbr(sb, bindex);
 
175
                xi = &br->br_xino;
 
176
                if (xi->xi_dbgaufs) {
 
177
                        debugfs_remove(xi->xi_dbgaufs);
 
178
                        xi->xi_dbgaufs = NULL;
 
179
                }
 
180
        }
 
181
}
 
182
 
 
183
void dbgaufs_brs_add(struct super_block *sb, aufs_bindex_t bindex)
 
184
{
 
185
        struct au_sbinfo *sbinfo;
 
186
        struct dentry *parent;
 
187
        struct au_branch *br;
 
188
        struct au_xino_file *xi;
 
189
        aufs_bindex_t bend;
 
190
        char name[sizeof(DbgaufsXi_PREFIX) + 5]; /* "xi" bindex NULL */
 
191
 
 
192
        sbinfo = au_sbi(sb);
 
193
        parent = sbinfo->si_dbgaufs;
 
194
        if (!parent)
 
195
                return;
 
196
 
 
197
        bend = au_sbend(sb);
 
198
        for (; bindex <= bend; bindex++) {
 
199
                snprintf(name, sizeof(name), DbgaufsXi_PREFIX "%d", bindex);
 
200
                br = au_sbr(sb, bindex);
 
201
                xi = &br->br_xino;
 
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);
 
208
        }
 
209
}
 
210
 
 
211
/* ---------------------------------------------------------------------- */
 
212
 
 
213
#ifdef CONFIG_AUFS_EXPORT
 
214
static int dbgaufs_xigen_open(struct inode *inode, struct file *file)
 
215
{
 
216
        int err;
 
217
        struct au_sbinfo *sbinfo;
 
218
        struct super_block *sb;
 
219
 
 
220
        sbinfo = inode->i_private;
 
221
        sb = sbinfo->si_sb;
 
222
        si_noflush_read_lock(sb);
 
223
        err = dbgaufs_xi_open(sbinfo->si_xigen, file, /*do_fcnt*/0);
 
224
        si_read_unlock(sb);
 
225
        return err;
 
226
}
 
227
 
 
228
static const struct file_operations dbgaufs_xigen_fop = {
 
229
        .open           = dbgaufs_xigen_open,
 
230
        .release        = dbgaufs_xi_release,
 
231
        .read           = dbgaufs_xi_read
 
232
};
 
233
 
 
234
static int dbgaufs_xigen_init(struct au_sbinfo *sbinfo)
 
235
{
 
236
        int err;
 
237
 
 
238
        /*
 
239
         * This function is a dynamic '__init' fucntion actually,
 
240
         * so the tiny check for si_rwsem is unnecessary.
 
241
         */
 
242
        /* AuRwMustWriteLock(&sbinfo->si_rwsem); */
 
243
 
 
244
        err = -EIO;
 
245
        sbinfo->si_dbgaufs_xigen = debugfs_create_file
 
246
                ("xigen", dbgaufs_mode, sbinfo->si_dbgaufs, sbinfo,
 
247
                 &dbgaufs_xigen_fop);
 
248
        if (sbinfo->si_dbgaufs_xigen)
 
249
                err = 0;
 
250
 
 
251
        return err;
 
252
}
 
253
#else
 
254
static int dbgaufs_xigen_init(struct au_sbinfo *sbinfo)
 
255
{
 
256
        return 0;
 
257
}
 
258
#endif /* CONFIG_AUFS_EXPORT */
 
259
 
 
260
/* ---------------------------------------------------------------------- */
 
261
 
 
262
void dbgaufs_si_fin(struct au_sbinfo *sbinfo)
 
263
{
 
264
        /*
 
265
         * This function is a dynamic '__init' fucntion actually,
 
266
         * so the tiny check for si_rwsem is unnecessary.
 
267
         */
 
268
        /* AuRwMustWriteLock(&sbinfo->si_rwsem); */
 
269
 
 
270
        debugfs_remove_recursive(sbinfo->si_dbgaufs);
 
271
        sbinfo->si_dbgaufs = NULL;
 
272
        kobject_put(&sbinfo->si_kobj);
 
273
}
 
274
 
 
275
int dbgaufs_si_init(struct au_sbinfo *sbinfo)
 
276
{
 
277
        int err;
 
278
        char name[SysaufsSiNameLen];
 
279
 
 
280
        /*
 
281
         * This function is a dynamic '__init' fucntion actually,
 
282
         * so the tiny check for si_rwsem is unnecessary.
 
283
         */
 
284
        /* AuRwMustWriteLock(&sbinfo->si_rwsem); */
 
285
 
 
286
        err = -ENOENT;
 
287
        if (!dbgaufs) {
 
288
                AuErr1("/debug/aufs is uninitialized\n");
 
289
                goto out;
 
290
        }
 
291
 
 
292
        err = -EIO;
 
293
        sysaufs_name(sbinfo, name);
 
294
        sbinfo->si_dbgaufs = debugfs_create_dir(name, dbgaufs);
 
295
        if (unlikely(!sbinfo->si_dbgaufs))
 
296
                goto out;
 
297
        kobject_get(&sbinfo->si_kobj);
 
298
 
 
299
        sbinfo->si_dbgaufs_xib = debugfs_create_file
 
300
                ("xib", dbgaufs_mode, sbinfo->si_dbgaufs, sbinfo,
 
301
                 &dbgaufs_xib_fop);
 
302
        if (unlikely(!sbinfo->si_dbgaufs_xib))
 
303
                goto out_dir;
 
304
 
 
305
        err = dbgaufs_xigen_init(sbinfo);
 
306
        if (!err)
 
307
                goto out; /* success */
 
308
 
 
309
 out_dir:
 
310
        dbgaufs_si_fin(sbinfo);
 
311
 out:
 
312
        return err;
 
313
}
 
314
 
 
315
/* ---------------------------------------------------------------------- */
 
316
 
 
317
void dbgaufs_fin(void)
 
318
{
 
319
        debugfs_remove(dbgaufs);
 
320
}
 
321
 
 
322
int __init dbgaufs_init(void)
 
323
{
 
324
        int err;
 
325
 
 
326
        err = -EIO;
 
327
        dbgaufs = debugfs_create_dir(AUFS_NAME, NULL);
 
328
        if (dbgaufs)
 
329
                err = 0;
 
330
        return err;
 
331
}