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