[FIX] Ksyms: Fix warnings
[kernel/swap-modules.git] / us_manager / us_manager.c
1 /*
2  *  SWAP uprobe manager
3  *  modules/us_manager/us_manager.c
4  *
5  * This program is free software; you can redistribute it and/or modify
6  * it under the terms of the GNU General Public License as published by
7  * the Free Software Foundation; either version 2 of the License, or
8  * (at your option) any later version.
9  *
10  * This program is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13  * GNU General Public License for more details.
14  *
15  * You should have received a copy of the GNU General Public License
16  * along with this program; if not, write to the Free Software
17  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
18  *
19  * Copyright (C) Samsung Electronics, 2013
20  *
21  * 2013  Vyacheslav Cherkashin: SWAP us_manager implement
22  *
23  */
24
25 #include <linux/module.h>
26 #include <linux/mutex.h>
27 #include "pf/pf_group.h"
28 #include "sspt/sspt_proc.h"
29 #include "helper.h"
30 #include "us_manager.h"
31 #include "debugfs_us_manager.h"
32
33 #include <writer/event_filter.h>
34
35 /* FIXME: move /un/init_msg() elsewhere and remove this include  */
36 #include <writer/swap_writer_module.h>          /* for /un/init_msg() */
37
38
39
40 static DEFINE_MUTEX(mutex_inst);
41 static enum status_type status = ST_OFF;
42
43
44 static void do_usm_stop(void)
45 {
46         unregister_helper();
47         uninstall_all();
48         sspt_proc_free_all();
49 }
50
51 static int do_usm_start(void)
52 {
53         int ret;
54
55         ret = register_helper();
56         if (ret)
57                 return ret;
58
59         install_all();
60
61         return 0;
62 }
63
64 enum status_type usm_get_status(void)
65 {
66         mutex_lock(&mutex_inst);
67         return status;
68 }
69 EXPORT_SYMBOL_GPL(usm_get_status);
70
71 void usm_put_status(enum status_type st)
72 {
73         status = st;
74         mutex_unlock(&mutex_inst);
75 }
76 EXPORT_SYMBOL_GPL(usm_put_status);
77
78 int usm_stop(void)
79 {
80         int ret = 0;
81
82         if (usm_get_status() == ST_OFF) {
83                 printk("US instrumentation is not running!\n");
84                 ret = -EINVAL;
85                 goto put;
86         }
87
88         do_usm_stop();
89
90 put:
91         usm_put_status(ST_OFF);
92
93         return ret;
94 }
95 EXPORT_SYMBOL_GPL(usm_stop);
96
97 int usm_start(void)
98 {
99         int ret = -EINVAL;
100         enum status_type st;
101
102         st = usm_get_status();
103         if (st == ST_ON) {
104                 printk("US instrumentation is already run!\n");
105                 goto put;
106         }
107
108         ret = do_usm_start();
109         if (ret == 0)
110                 st = ST_ON;
111
112 put:
113         usm_put_status(st);
114
115         return ret;
116 }
117 EXPORT_SYMBOL_GPL(usm_start);
118
119
120
121
122
123 /* ============================================================================
124  * ===                                QUIET                                 ===
125  * ============================================================================
126  */
127 static enum quiet_type quiet = QT_ON;
128
129 void set_quiet(enum quiet_type q)
130 {
131         quiet = q;
132 }
133 EXPORT_SYMBOL_GPL(set_quiet);
134
135 enum quiet_type get_quiet(void)
136 {
137         return quiet;
138 }
139 EXPORT_SYMBOL_GPL(get_quiet);
140
141
142
143
144
145 /* ============================================================================
146  * ===                              US_FILTER                               ===
147  * ============================================================================
148  */
149 static int us_filter(struct task_struct *task)
150 {
151         return !!sspt_proc_get_by_task(task);
152 }
153
154 static struct ev_filter ev_us_filter = {
155         .name = "traced_process_only",
156         .filter = us_filter
157 };
158
159 static int init_us_filter(void)
160 {
161         int ret;
162
163         ret = event_filter_register(&ev_us_filter);
164         if (ret)
165                 return ret;
166
167         return event_filter_set(ev_us_filter.name);
168 }
169
170 static void exit_us_filter(void)
171 {
172         event_filter_unregister(&ev_us_filter);
173 }
174
175
176
177
178
179 static int __init init_us_manager(void)
180 {
181         int ret;
182
183         ret = init_us_filter();
184         if (ret)
185                 goto us_filter_init_fail;
186
187         init_msg(32*1024);
188
189         ret = init_helper();
190         if (ret)
191                 goto helper_init_fail;
192
193         ret = init_debugfs_us_manager();
194         if (ret)
195                 goto debugfs_init_fail;
196
197         return 0;
198
199 debugfs_init_fail:
200         uninit_helper();
201
202 helper_init_fail:
203         uninit_msg();
204         exit_us_filter();
205
206 us_filter_init_fail:
207         return ret;
208 }
209
210 static void __exit exit_us_manager(void)
211 {
212         if (status == ST_ON)
213                 do_usm_stop();
214
215         exit_debugfs_us_manager();
216         uninit_msg();
217         uninit_helper();
218         exit_us_filter();
219 }
220
221 module_init(init_us_manager);
222 module_exit(exit_us_manager);
223
224 MODULE_LICENSE ("GPL");
225