[REFACTOR] move and rename install_file_probes()
[kernel/swap-modules.git] / driver / module.c
1 ////////////////////////////////////////////////////////////////////////////////////
2 //
3 //      FILE:           module.c
4 //
5 //      DESCRIPTION:
6 //      This file is C source for SWAP driver.
7 //
8 //      SEE ALSO:       module.h
9 //      AUTHOR:         L.Komkov, A.Gerenkov
10 //      COMPANY NAME:   Samsung Research Center in Moscow
11 //      DEPT NAME:      Advanced Software Group
12 //      CREATED:        2008.02.15
13 //      VERSION:        1.0
14 //      REVISION DATE:  2008.12.03
15 //
16 ////////////////////////////////////////////////////////////////////////////////////
17
18 #include "module.h"
19 #include <ksyms.h>
20 #include "helper.h"
21
22 static char gl_szDefaultDeviceName[128] = DEFAULT_DEVICE_NAME;
23 char* device_name = NULL;
24 module_param (device_name, charp, 0);
25 MODULE_PARM_DESC (device_name, "device name for '/proc/devices'");
26
27 unsigned int device_major = 0;
28 module_param (device_major, uint, 0);
29 MODULE_PARM_DESC (device_major, "default device major number");
30
31 #if (LINUX_VERSION_CODE != KERNEL_VERSION(2, 6, 16))
32 static void (*__real_put_task_struct) (struct task_struct * tsk);
33 #if (LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 11))
34 #define SWAPDRV_PUT_TASK_STRUCT "put_task_struct"
35 void
36 put_task_struct (struct task_struct *tsk)
37 {
38         __real_put_task_struct (tsk);
39 }
40 #else
41 #define SWAPDRV_PUT_TASK_STRUCT "__put_task_struct"
42 void
43 __put_task_struct (struct task_struct *tsk)
44 {
45         __real_put_task_struct (tsk);
46 }
47 #endif
48 #else /*2.6.16 */
49 void (*__real_put_task_struct) (struct rcu_head * rhp);
50 #define SWAPDRV_PUT_TASK_STRUCT "__put_task_struct_cb"
51 void
52 __put_task_struct_cb (struct rcu_head *rhp)
53 {
54         __real_put_task_struct (rhp);
55 }
56 #endif
57 /*void (*__real_put_task_struct)(struct task_struct *tsk);
58 void __put_task_struct(struct task_struct *tsk)
59 {
60         __real_put_task_struct(tsk);
61 }*/
62
63 #if defined(CONFIG_MIPS)
64 void (*flush_cache_page) (struct vm_area_struct * vma, unsigned long page);
65 #endif
66
67 static int probes_manager_init(void)
68 {
69         int ret;
70 #if LINUX_VERSION_CODE > KERNEL_VERSION(2, 6, 38)
71         spin_lock_init(&ec_spinlock);
72 #endif /* LINUX_VERSION_CODE > KERNEL_VERSION(2, 6, 38) */
73
74         ret = init_helper();
75         if (ret)
76                 return ret;
77
78         return storage_init();
79 }
80
81 static void probes_manager_down(void)
82 {
83         unset_kernel_probes();
84         uninit_helper();
85         storage_down();
86 }
87
88 static int __init InitializeModule(void)
89 {
90         if(device_name == NULL) {
91                 EPRINTF("Using default device name!");
92                 device_name = gl_szDefaultDeviceName;
93         }
94         if(device_major == 0) {
95                 EPRINTF("Using default device major number!");
96                 device_major = DEFAULT_DEVICE_MAJOR;
97         }
98
99         __real_put_task_struct = (void *)swap_ksyms(SWAPDRV_PUT_TASK_STRUCT);
100         if (!__real_put_task_struct)
101         {
102                 EPRINTF (SWAPDRV_PUT_TASK_STRUCT " is not found! Oops. Where is it?");
103                 return -ESRCH;
104         }
105
106 #if defined(CONFIG_MIPS)
107         flush_cache_page = (void *)swap_ksyms("r4k_flush_cache_page");
108         if (!flush_cache_page)
109         {
110                 EPRINTF ("failed to resolve 'flush_cache_page'!\n");
111                 return -ESRCH;
112         }
113 #endif
114
115         if(probes_manager_init() < 0) {
116                 EPRINTF ("Cannot initialize probe manager!");
117                 return -1;
118         }
119         if(device_init() < 0) {
120                 EPRINTF ("Cannot initialize device!");
121                 return -1;
122         }
123
124         INIT_LIST_HEAD(&cond_list.list);
125
126         DPRINTF ("is successfully initialized.");
127
128         return 0;
129 }
130
131 static void __exit UninitializeModule (void)
132 {
133         ec_user_stop ();
134         device_down ();
135         probes_manager_down ();
136         DPRINTF ("is successfully finished.");
137 }
138
139 module_init (InitializeModule);
140 module_exit (UninitializeModule);
141 MODULE_LICENSE ("GPL");
142 MODULE_AUTHOR("Adwanced Software Group (SRC, Moscow)");
143 MODULE_DESCRIPTION("SWAP Device Driver");
144 MODULE_VERSION("4:1.0");