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