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