1 ////////////////////////////////////////////////////////////////////////////////////
6 // This file is C source for SWAP driver.
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
14 // REVISION DATE: 2008.12.03
16 ////////////////////////////////////////////////////////////////////////////////////
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'");
27 unsigned int device_major = 0;
28 module_param (device_major, uint, 0);
29 MODULE_PARM_DESC (device_major, "default device major number");
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"
36 put_task_struct (struct task_struct *tsk)
38 __real_put_task_struct (tsk);
41 #define SWAPDRV_PUT_TASK_STRUCT "__put_task_struct"
43 __put_task_struct (struct task_struct *tsk)
45 __real_put_task_struct (tsk);
49 void (*__real_put_task_struct) (struct rcu_head * rhp);
50 #define SWAPDRV_PUT_TASK_STRUCT "__put_task_struct_cb"
52 __put_task_struct_cb (struct rcu_head *rhp)
54 __real_put_task_struct (rhp);
57 /*void (*__real_put_task_struct)(struct task_struct *tsk);
58 void __put_task_struct(struct task_struct *tsk)
60 __real_put_task_struct(tsk);
63 #if defined(CONFIG_MIPS)
64 void (*flush_cache_page) (struct vm_area_struct * vma, unsigned long page);
67 static int probes_manager_init(void)
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) */
78 return storage_init();
81 static void probes_manager_down(void)
83 unset_kernel_probes();
88 static int __init InitializeModule(void)
90 if(device_name == NULL) {
91 EPRINTF("Using default device name!");
92 device_name = gl_szDefaultDeviceName;
94 if(device_major == 0) {
95 EPRINTF("Using default device major number!");
96 device_major = DEFAULT_DEVICE_MAJOR;
99 __real_put_task_struct = (void *)swap_ksyms(SWAPDRV_PUT_TASK_STRUCT);
100 if (!__real_put_task_struct)
102 EPRINTF (SWAPDRV_PUT_TASK_STRUCT " is not found! Oops. Where is it?");
106 #if defined(CONFIG_MIPS)
107 flush_cache_page = (void *)swap_ksyms("r4k_flush_cache_page");
108 if (!flush_cache_page)
110 EPRINTF ("failed to resolve 'flush_cache_page'!\n");
115 if(probes_manager_init() < 0) {
116 EPRINTF ("Cannot initialize probe manager!");
119 if(device_init() < 0) {
120 EPRINTF ("Cannot initialize device!");
124 INIT_LIST_HEAD(&cond_list.list);
126 DPRINTF ("is successfully initialized.");
131 static void __exit UninitializeModule (void)
135 probes_manager_down ();
136 DPRINTF ("is successfully finished.");
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");