DEVEL15-linux-2626-updates-20080612
[openafs.git] / src / afs / LINUX / osi_pag_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 RCSID
18     ("$Header$");
19
20 #if !defined(AFS_NONFSTRANS) || defined(AFS_AIX_IAUTH_ENV)
21 #include <linux/module.h> /* early to avoid printf->printk mapping */
22 #include "afs/sysincludes.h"
23 #include "afsincludes.h"
24 #include "h/unistd.h"           /* For syscall numbers. */
25 #include "h/mm.h"
26
27 #ifdef AFS_AMD64_LINUX20_ENV
28 #include <asm/ia32_unistd.h>
29 #endif
30 #ifdef AFS_SPARC64_LINUX20_ENV
31 #include <linux/ioctl32.h>
32 #endif
33
34 #include <linux/proc_fs.h>
35 #include <linux/slab.h>
36 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,4,0)
37 #include <linux/init.h>
38 #include <linux/sched.h>
39 #include <linux/kernel.h>
40 #endif
41
42 static unsigned long nfs_server_addr = 0;
43 #if defined(module_param) && LINUX_VERSION_CODE > KERNEL_VERSION(2,6,9)
44 module_param(nfs_server_addr, long, 0);
45 #else
46 MODULE_PARM(nfs_server_addr,  "l");
47 #endif
48 MODULE_PARM_DESC(nfs_server_addr,  "IP Address of NFS Server");
49
50 static char *this_cell = 0;
51 #if defined(module_param_array) && LINUX_VERSION_CODE > KERNEL_VERSION(2,6,9)
52 module_param(this_cell, charp, 0);
53 #else
54 MODULE_PARM(this_cell, "s");
55 #endif
56 MODULE_PARM_DESC(this_cell, "Local cell name");
57
58 #if defined(AFS_LINUX24_ENV)
59 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,16)
60 DEFINE_MUTEX(afs_global_lock);
61 #else
62 DECLARE_MUTEX(afs_global_lock);
63 #endif
64 struct proc_dir_entry *openafs_procfs;
65 #else
66 struct semaphore afs_global_lock = MUTEX;
67 #endif
68 int afs_global_owner = 0;
69
70 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,4,0)
71 int __init
72 afspag_init(void)
73 #else
74 int
75 init_module(void)
76 #endif
77 {
78 #if !defined(EXPORTED_PROC_ROOT_FS) && defined(AFS_LINUX24_ENV)
79     char path[64];
80 #endif
81     int err;
82
83     osi_Init();
84
85     err = osi_syscall_init();
86     if (err)
87         return err;
88 #ifdef AFS_LINUX24_ENV
89 #if defined(EXPORTED_PROC_ROOT_FS)
90     openafs_procfs = proc_mkdir(PROC_FSDIRNAME, proc_root_fs);
91 #else
92     sprintf(path, "fs/%s", PROC_FSDIRNAME);
93     openafs_procfs = proc_mkdir(path, NULL);
94 #endif
95     osi_ioctl_init();
96 #endif
97
98     afspag_Init(htonl(nfs_server_addr));
99     if (this_cell)
100         afspag_SetPrimaryCell(this_cell);
101
102     return 0;
103 }
104
105 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,4,0)
106 void __exit
107 afspag_cleanup(void)
108 #else
109 void
110 cleanup_module(void)
111 #endif
112 {
113 #if !defined(EXPORTED_PROC_ROOT_FS) && defined(AFS_LINUX24_ENV)
114     char path[64];
115 #endif
116     osi_syscall_clean();
117
118     osi_linux_free_afs_memory();
119
120 #ifdef AFS_LINUX24_ENV
121     osi_ioctl_clean();
122 #if defined(EXPORTED_PROC_ROOT_FS)
123     remove_proc_entry(PROC_FSDIRNAME, proc_root_fs);
124 #else
125     sprintf(path, "fs/%s", PROC_FSDIRNAME);
126     remove_proc_entry(path, NULL);
127 #endif
128 #endif
129     return;
130 }
131
132 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,4,0)
133 MODULE_LICENSE("http://www.openafs.org/dl/license10.html");
134 module_init(afspag_init);
135 module_exit(afspag_cleanup);
136 #endif
137
138 #ifdef AFS_LINUX26_ENV
139 /* Hack alert!
140  * These will never be called in the standalone PAG manager, because
141  * they are only referenced in afs_InitReq, and nothing calls that.
142  * However, we need to define them in order to resolve the reference,
143  * unless we want to move afs_InitReq out of afs_osi_pag.c.
144  */
145 int osi_linux_nfs_initreq(struct vrequest *av, struct AFS_UCRED *cr, int *code)
146 {
147     *code = EACCES;
148     return 1;
149 }
150
151 int
152 afs_nfsclient_reqhandler(struct afs_exporter *exporter,
153                          struct AFS_UCRED **cred,
154                          afs_int32 host, afs_int32 *pagparam,
155                          struct afs_exporter **outexporter)
156 {
157     return EINVAL;
158 }
159 #endif
160 #endif /* AFS_NONFSTRANS */
161