Linux: remove unused cr->next member in struct afs_cred
[openafs.git] / src / afs / LINUX24 / osi_module.c
1 /*
2  * Copyright 2000, International Business Machines Corporation and others.
3  * All Rights Reserved.
4  * 
5  * This software has been released under the terms of the IBM Public
6  * License.  For details, see the LICENSE file in the top-level source
7  * directory or online at http://www.openafs.org/dl/license10.html
8  */
9
10 /*
11  * Linux module support routines.
12  *
13  */
14 #include <afsconfig.h>
15 #include "afs/param.h"
16
17
18 #include <linux/module.h> /* early to avoid printf->printk mapping */
19 #include "afs/sysincludes.h"
20 #include "afsincludes.h"
21 #include "h/unistd.h"           /* For syscall numbers. */
22 #include "h/mm.h"
23
24 #ifdef AFS_AMD64_LINUX20_ENV
25 #include <asm/ia32_unistd.h>
26 #endif
27 #ifdef AFS_SPARC64_LINUX20_ENV
28 #include <linux/ioctl32.h>
29 #endif
30
31 #include <linux/proc_fs.h>
32 #include <linux/slab.h>
33 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,4,0)
34 #include <linux/init.h>
35 #include <linux/sched.h>
36 #include <linux/kernel.h>
37 #endif
38
39 #include "osi_pagecopy.h"
40
41 extern struct file_system_type afs_fs_type;
42
43 #if !defined(AFS_LINUX24_ENV)
44 static long get_page_offset(void);
45 #endif
46
47 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,16)
48 DEFINE_MUTEX(afs_global_lock);
49 #elif LINUX_VERSION_CODE >= KERNEL_VERSION(2,4,0)
50 DECLARE_MUTEX(afs_global_lock);
51 #else
52 struct semaphore afs_global_lock = MUTEX;
53 #endif
54 int afs_global_owner = 0;
55 #if !defined(AFS_LINUX24_ENV)
56 unsigned long afs_linux_page_offset = 0;        /* contains the PAGE_OFFSET value */
57 #endif
58
59
60 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,4,0)
61 int __init
62 afs_init(void)
63 #else
64 int
65 init_module(void)
66 #endif
67 {
68     int err;
69     AFS_RWLOCK_INIT(&afs_xosi, "afs_xosi");
70
71 #if !defined(AFS_LINUX24_ENV)
72     /* obtain PAGE_OFFSET value */
73     afs_linux_page_offset = get_page_offset();
74
75 #ifndef AFS_S390_LINUX22_ENV
76     if (afs_linux_page_offset == 0) {
77         /* couldn't obtain page offset so can't continue */
78         printf("afs: Unable to obtain PAGE_OFFSET. Exiting..");
79         return -EIO;
80     }
81 #endif /* AFS_S390_LINUX22_ENV */
82 #endif /* !defined(AFS_LINUX24_ENV) */
83
84     osi_Init();
85
86 #ifndef LINUX_KEYRING_SUPPORT
87     err = osi_syscall_init();
88     if (err)
89         return err;
90 #endif
91     err = afs_init_inodecache();
92     if (err) {
93 #ifndef LINUX_KEYRING_SUPPORT
94         osi_syscall_clean();
95 #endif
96         return err;
97     }
98     err = register_filesystem(&afs_fs_type);
99     if (err) {
100         afs_destroy_inodecache();
101 #ifndef LINUX_KEYRING_SUPPORT
102         osi_syscall_clean();
103 #endif
104         return err;
105     }
106
107     osi_sysctl_init();
108 #ifdef LINUX_KEYRING_SUPPORT
109     osi_keyring_init();
110 #endif
111 #ifdef AFS_LINUX24_ENV
112     osi_proc_init();
113     osi_ioctl_init();
114 #endif
115 #if defined(AFS_CACHE_BYPASS)
116     afs_warn("Cache bypass patched libafs module init.\n");
117 #endif
118     afs_init_pagecopy();
119
120     return 0;
121 }
122
123 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,4,0)
124 void __exit
125 afs_cleanup(void)
126 #else
127 void
128 cleanup_module(void)
129 #endif
130 {
131 #if defined(AFS_CACHE_BYPASS)
132     afs_warn("Cache bypass patched libafs module cleaning up.\n");
133 #endif
134
135     afs_shutdown_pagecopy();
136
137 #ifdef LINUX_KEYRING_SUPPORT
138     osi_keyring_shutdown();
139 #endif
140     osi_sysctl_clean();
141 #ifndef LINUX_KEYRING_SUPPORT
142     osi_syscall_clean();
143 #endif
144     unregister_filesystem(&afs_fs_type);
145
146     afs_destroy_inodecache();
147     osi_linux_free_afs_memory();
148
149 #ifdef AFS_LINUX24_ENV
150     osi_ioctl_clean();
151     osi_proc_clean();
152 #endif
153
154     return;
155 }
156
157 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,4,0)
158 MODULE_LICENSE("http://www.openafs.org/dl/license10.html");
159 module_init(afs_init);
160 module_exit(afs_cleanup);
161 #endif
162
163
164 #if !defined(AFS_LINUX24_ENV)
165 static long
166 get_page_offset(void)
167 {
168 #if defined(AFS_PPC_LINUX22_ENV) || defined(AFS_SPARC64_LINUX20_ENV) || defined(AFS_SPARC_LINUX20_ENV) || defined(AFS_ALPHA_LINUX20_ENV) || defined(AFS_S390_LINUX22_ENV) || defined(AFS_IA64_LINUX20_ENV) || defined(AFS_PARISC_LINUX24_ENV) || defined(AFS_AMD64_LINUX20_ENV) || defined(AFS_PPC64_LINUX20_ENV)
169     return PAGE_OFFSET;
170 #else
171     struct task_struct *p, *q;
172
173     /* search backward thru the circular list */
174 #if defined(EXPORTED_TASKLIST_LOCK) 
175     read_lock(&tasklist_lock);
176 #endif
177     /* search backward thru the circular list */
178 #ifdef DEFINED_PREV_TASK
179     for (q = current; p = q; q = prev_task(p)) {
180 #else
181     for (p = current; p; p = p->prev_task) {
182 #endif
183         if (p->pid == 1) {
184 #if defined(EXPORTED_TASKLIST_LOCK) 
185             read_unlock(&tasklist_lock);
186 #endif
187             return p->addr_limit.seg;
188         }
189     }
190
191 #if defined(EXPORTED_TASKLIST_LOCK) 
192     read_unlock(&tasklist_lock);
193 #endif
194     return 0;
195 #endif
196 }
197 #endif /* !AFS_LINUX24_ENV */