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