aufs: fix up for the new stable kernel
[pandora-kernel.git] / fs / aufs / sysrq.c
1 /*
2  * Copyright (C) 2005-2013 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  * magic sysrq hanlder
21  */
22
23 /* #include <linux/sysrq.h> */
24 #include <linux/writeback.h>
25 #include "aufs.h"
26
27 /* ---------------------------------------------------------------------- */
28
29 static void sysrq_sb(struct super_block *sb)
30 {
31         char *plevel;
32         struct au_sbinfo *sbinfo;
33         struct file *file;
34
35         plevel = au_plevel;
36         au_plevel = KERN_WARNING;
37
38         /* since we define pr_fmt, call printk directly */
39 #define pr(str) printk(KERN_WARNING AUFS_NAME ": " str)
40
41         sbinfo = au_sbi(sb);
42         printk(KERN_WARNING "si=%lx\n", sysaufs_si_id(sbinfo));
43         pr("superblock\n");
44         au_dpri_sb(sb);
45
46 #if 0
47         pr("root dentry\n");
48         au_dpri_dentry(sb->s_root);
49         pr("root inode\n");
50         au_dpri_inode(sb->s_root->d_inode);
51 #endif
52
53 #if 0
54         do {
55                 int err, i, j, ndentry;
56                 struct au_dcsub_pages dpages;
57                 struct au_dpage *dpage;
58
59                 err = au_dpages_init(&dpages, GFP_ATOMIC);
60                 if (unlikely(err))
61                         break;
62                 err = au_dcsub_pages(&dpages, sb->s_root, NULL, NULL);
63                 if (!err)
64                         for (i = 0; i < dpages.ndpage; i++) {
65                                 dpage = dpages.dpages + i;
66                                 ndentry = dpage->ndentry;
67                                 for (j = 0; j < ndentry; j++)
68                                         au_dpri_dentry(dpage->dentries[j]);
69                         }
70                 au_dpages_free(&dpages);
71         } while (0);
72 #endif
73
74 #if 1
75         {
76                 struct inode *i;
77                 pr("isolated inode\n");
78                 spin_lock(&inode_sb_list_lock);
79                 list_for_each_entry(i, &sb->s_inodes, i_sb_list) {
80                         spin_lock(&i->i_lock);
81                         if (1 || list_empty(&i->i_dentry))
82                                 au_dpri_inode(i);
83                         spin_unlock(&i->i_lock);
84                 }
85                 spin_unlock(&inode_sb_list_lock);
86         }
87 #endif
88         pr("files\n");
89         lg_global_lock(files_lglock);
90         do_file_list_for_each_entry(sb, file) {
91                 umode_t mode;
92                 mode = file->f_dentry->d_inode->i_mode;
93                 if (!special_file(mode) || au_special_file(mode))
94                         au_dpri_file(file);
95         } while_file_list_for_each_entry;
96         lg_global_unlock(files_lglock);
97         pr("done\n");
98
99 #undef pr
100         au_plevel = plevel;
101 }
102
103 /* ---------------------------------------------------------------------- */
104
105 /* module parameter */
106 static char *aufs_sysrq_key = "a";
107 module_param_named(sysrq, aufs_sysrq_key, charp, S_IRUGO);
108 MODULE_PARM_DESC(sysrq, "MagicSysRq key for " AUFS_NAME);
109
110 static void au_sysrq(int key __maybe_unused)
111 {
112         struct au_sbinfo *sbinfo;
113
114         lockdep_off();
115         au_sbilist_lock();
116         list_for_each_entry(sbinfo, &au_sbilist.head, si_list)
117                 sysrq_sb(sbinfo->si_sb);
118         au_sbilist_unlock();
119         lockdep_on();
120 }
121
122 static struct sysrq_key_op au_sysrq_op = {
123         .handler        = au_sysrq,
124         .help_msg       = "Aufs",
125         .action_msg     = "Aufs",
126         .enable_mask    = SYSRQ_ENABLE_DUMP
127 };
128
129 /* ---------------------------------------------------------------------- */
130
131 int __init au_sysrq_init(void)
132 {
133         int err;
134         char key;
135
136         err = -1;
137         key = *aufs_sysrq_key;
138         if ('a' <= key && key <= 'z')
139                 err = register_sysrq_key(key, &au_sysrq_op);
140         if (unlikely(err))
141                 pr_err("err %d, sysrq=%c\n", err, key);
142         return err;
143 }
144
145 void au_sysrq_fin(void)
146 {
147         int err;
148         err = unregister_sysrq_key(*aufs_sysrq_key, &au_sysrq_op);
149         if (unlikely(err))
150                 pr_err("err %d (ignored)\n", err);
151 }