6a458568b05d1fb65c2c051d226ff8effdcb0aa9
[openafs.git] / src / afs / LINUX / 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 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
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 #endif
36
37 extern struct file_system_type afs_fs_type;
38
39 #if !defined(AFS_LINUX24_ENV)
40 static long get_page_offset(void);
41 #endif
42
43 #if defined(AFS_LINUX24_ENV)
44 DECLARE_MUTEX(afs_global_lock);
45 #else
46 struct semaphore afs_global_lock = MUTEX;
47 #endif
48 int afs_global_owner = 0;
49 #if !defined(AFS_LINUX24_ENV)
50 unsigned long afs_linux_page_offset = 0;        /* contains the PAGE_OFFSET value */
51 #endif
52
53
54 static int afs_ioctl(struct inode *, struct file *, unsigned int,
55                      unsigned long);
56
57 static struct file_operations afs_syscall_fops = {
58     .ioctl = afs_ioctl,
59 };
60
61 int
62 csdbproc_read(char *buffer, char **start, off_t offset, int count,
63               int *eof, void *data)
64 {
65     int len, j;
66     struct afs_q *cq, *tq;
67     struct cell *tc;
68     char tbuffer[16];
69     afs_uint32 addr;
70     
71     len = 0;
72     ObtainReadLock(&afs_xcell);
73     for (cq = CellLRU.next; cq != &CellLRU; cq = tq) {
74         tc = QTOC(cq); tq = QNext(cq);
75         len += sprintf(buffer + len, ">%s #(%d/%d)\n", tc->cellName, 
76                        tc->cellNum, tc->cellIndex);
77         for (j = 0; j < MAXCELLHOSTS; j++) {
78             if (!tc->cellHosts[j]) break;
79             addr = ntohl(tc->cellHosts[j]->addr->sa_ip);
80             sprintf(tbuffer, "%d.%d.%d.%d", 
81                     (int)((addr>>24) & 0xff), (int)((addr>>16) & 0xff),
82                     (int)((addr>>8)  & 0xff), (int)( addr      & 0xff));
83             len += sprintf(buffer + len, "%s #%s\n", tbuffer, tbuffer);
84         }
85     }
86     ReleaseReadLock(&afs_xcell);
87     
88     if (offset >= len) {
89         *start = buffer;
90         *eof = 1;
91         return 0;
92     }
93     *start = buffer + offset;
94     if ((len -= offset) > count)
95         return count;
96     *eof = 1;
97     return len;
98 }
99
100 int
101 peerproc_read(char *buffer, char **start, off_t offset, int count,
102               int *eof, void *data)
103 {
104     int len, i, j;
105     struct rx_peer *sep;
106     
107     len = 0;
108     for (i = 0, j = 0; i < 256; i++) {
109         for (sep = rx_peerHashTable[i]; sep; sep = sep->next, j++) {
110             len += sprintf(buffer + len, "%lx: next=0x%lx, host=0x%x, ", (unsigned long)sep,
111                    (unsigned long)sep->next, sep->host);
112             len += sprintf(buffer + len, "ifMTU=%d, natMTU=%d, maxMTU=%d\n", sep->ifMTU,
113                    sep->natMTU, sep->maxMTU);
114             len += sprintf(buffer + len, "\trtt=%d:%d, timeout(%d:%d), nSent=%d, reSends=%d\n",
115                    sep->rtt, sep->rtt_dev, sep->timeout.sec,
116                    sep->timeout.usec, sep->nSent, sep->reSends);
117             len += sprintf(buffer + len, "\trefCount=%d, port=%d, idleWhen=0x%x\n",
118                    sep->refCount, sep->port, sep->idleWhen);
119             len += sprintf(buffer + len, "\tCongestionQueue (0x%lx:0x%lx), inPacketSkew=0x%x, outPacketSkew=0x%x\n",
120                  (unsigned long)sep->congestionQueue.prev, (unsigned long)sep->congestionQueue.next,
121                  sep->inPacketSkew, sep->outPacketSkew);
122 #ifdef RX_ENABLE_LOCKS
123             len += sprintf(buffer + len, "\tpeer_lock=%d\n", sep->peer_lock);
124 #endif /* RX_ENABLE_LOCKS */
125         }
126     }
127     
128     if (offset >= len) {
129         *start = buffer;
130         *eof = 1;
131         return 0;
132     }
133     *start = buffer + offset;
134     if ((len -= offset) > count)
135         return count;
136     *eof = 1;
137     return len;
138 }
139
140 int
141 rxstatsproc_read(char *buffer, char **start, off_t offset, int count,
142               int *eof, void *data)
143 {
144     int len, i;
145     
146     len = 0;
147     len += sprintf(buffer + len, "packetRequests = %d\n", rx_stats.packetRequests);
148     len += sprintf(buffer + len, "noPackets[%d] = %d\n", RX_PACKET_CLASS_RECEIVE,
149            rx_stats.receivePktAllocFailures);
150     len += sprintf(buffer + len, "noPackets[%d] = %d\n", RX_PACKET_CLASS_SEND,
151            rx_stats.sendPktAllocFailures);
152     len += sprintf(buffer + len, "noPackets[%d] = %d\n", RX_PACKET_CLASS_SPECIAL,
153            rx_stats.specialPktAllocFailures);
154     len += sprintf(buffer + len, "noPackets[%d] = %d\n", RX_PACKET_CLASS_RECV_CBUF,
155            rx_stats.receiveCbufPktAllocFailures);
156     len += sprintf(buffer + len, "noPackets[%d] = %d\n", RX_PACKET_CLASS_SEND_CBUF,
157            rx_stats.sendCbufPktAllocFailures);
158     len += sprintf(buffer + len, "socketGreedy = %d\n", rx_stats.socketGreedy);
159     len += sprintf(buffer + len, "bogusPacketOnRead = %d\n", rx_stats.bogusPacketOnRead);
160     len += sprintf(buffer + len, "bogusHost = %d\n", rx_stats.bogusHost);
161     len += sprintf(buffer + len, "noPacketOnRead = %d\n", rx_stats.noPacketOnRead);
162     len += sprintf(buffer + len, "noPacketBuffersOnRead = %d\n",
163            rx_stats.noPacketBuffersOnRead);
164     len += sprintf(buffer + len, "selects = %d\n", rx_stats.selects);
165     len += sprintf(buffer + len, "sendSelects = %d\n", rx_stats.sendSelects);
166     for (i = 0; i < RX_N_PACKET_TYPES; i++)
167         len += sprintf(buffer + len, "packetsRead[%d] = %d\n", i, rx_stats.packetsRead[i]);
168     len += sprintf(buffer + len, "dataPacketsRead = %d\n", rx_stats.dataPacketsRead);
169     len += sprintf(buffer + len, "ackPacketsRead = %d\n", rx_stats.ackPacketsRead);
170     len += sprintf(buffer + len, "dupPacketsRead = %d\n", rx_stats.dupPacketsRead);
171     len += sprintf(buffer + len, "spuriousPacketsRead = %d\n", rx_stats.spuriousPacketsRead);
172     for (i = 0; i < RX_N_PACKET_TYPES; i++)
173         len += sprintf(buffer + len, "packetsSent[%d] = %d\n", i, rx_stats.packetsSent[i]);
174     len += sprintf(buffer + len, "ackPacketsSent = %d\n", rx_stats.ackPacketsSent);
175     len += sprintf(buffer + len, "pingPacketsSent = %d\n", rx_stats.pingPacketsSent);
176     len += sprintf(buffer + len, "abortPacketsSent = %d\n", rx_stats.abortPacketsSent);
177     len += sprintf(buffer + len, "busyPacketsSent = %d\n", rx_stats.busyPacketsSent);
178     len += sprintf(buffer + len, "dataPacketsSent = %d\n", rx_stats.dataPacketsSent);
179     len += sprintf(buffer + len, "dataPacketsReSent = %d\n", rx_stats.dataPacketsReSent);
180     len += sprintf(buffer + len, "dataPacketsPushed = %d\n", rx_stats.dataPacketsPushed);
181     len += sprintf(buffer + len, "ignoreAckedPacket = %d\n", rx_stats.ignoreAckedPacket);
182     len += sprintf(buffer + len, "totalRtt = %d sec, %d usec\n", rx_stats.totalRtt.sec,
183            rx_stats.totalRtt.usec);
184     len += sprintf(buffer + len, "minRtt = %d sec, %d usec\n", rx_stats.minRtt.sec,
185            rx_stats.minRtt.usec);
186     len += sprintf(buffer + len, "maxRtt = %d sec, %d usec\n", rx_stats.maxRtt.sec,
187            rx_stats.maxRtt.usec);
188     len += sprintf(buffer + len, "nRttSamples = %d\n", rx_stats.nRttSamples);
189     len += sprintf(buffer + len, "nServerConns = %d\n", rx_stats.nServerConns);
190     len += sprintf(buffer + len, "nClientConns = %d\n", rx_stats.nClientConns);
191     len += sprintf(buffer + len, "nPeerStructs = %d\n", rx_stats.nPeerStructs);
192     len += sprintf(buffer + len, "nCallStructs = %d\n", rx_stats.nCallStructs);
193     len += sprintf(buffer + len, "nFreeCallStructs = %d\n", rx_stats.nFreeCallStructs);
194     len += sprintf(buffer + len, "netSendFailures  = %d\n", rx_stats.netSendFailures);
195     len += sprintf(buffer + len, "fatalErrors      = %d\n", rx_stats.fatalErrors);
196     
197     if (offset >= len) {
198         *start = buffer;
199         *eof = 1;
200         return 0;
201     }
202     *start = buffer + offset;
203     if ((len -= offset) > count)
204         return count;
205     *eof = 1;
206     return len;
207 }
208
209 int
210 rxproc_read(char *buffer, char **start, off_t offset, int count,
211               int *eof, void *data)
212 {
213     int len, i;
214     
215     len = 0;
216     len += sprintf(buffer + len, "rx_extraQuota = %d\n", rx_extraQuota);
217     len += sprintf(buffer + len, "rx_extraPackets = %d\n", rx_extraPackets);
218     len += sprintf(buffer + len, "rx_stackSize = %d\n", rx_stackSize);
219     len += sprintf(buffer + len, "rx_connDeadTime = %d\n", rx_connDeadTime);
220     len += sprintf(buffer + len, "rx_idleConnectionTime = %d\n", rx_idleConnectionTime);
221     len += sprintf(buffer + len, "rx_idlePeerTime = %d\n", rx_idlePeerTime);
222     len += sprintf(buffer + len, "rx_initSendWindow = %d\n", rx_initSendWindow);
223     len += sprintf(buffer + len, "rxi_nSendFrags = %d\n", rxi_nSendFrags);
224     len += sprintf(buffer + len, "rx_nPackets = %d\n", rx_nPackets);
225     len += sprintf(buffer + len, "rx_nFreePackets = %d\n", rx_nFreePackets);
226     len += sprintf(buffer + len, "rx_socket = 0x%lx\n", (unsigned long)rx_socket);
227     len += sprintf(buffer + len, "rx_Port = %d\n", rx_port);
228     for (i = 0; i < RX_N_PACKET_CLASSES; i++)
229         len += sprintf(buffer + len, "\trx_packetQuota[%d] = %d\n", i, rx_packetQuota[i]);
230
231     len += sprintf(buffer + len, "rx_nextCid = 0x%x\n", rx_nextCid);
232     len += sprintf(buffer + len, "rx_epoch = 0u%u\n", rx_epoch);
233     len += sprintf(buffer + len, "rx_waitingForPackets = %x\n", rx_waitingForPackets);
234     len += sprintf(buffer + len, "rxi_nCalls = %d\n", rxi_nCalls);
235     len += sprintf(buffer + len, "rxi_dataQuota = %d\n", rxi_dataQuota);
236     len += sprintf(buffer + len, "rxi_availProcs = %d\n", rxi_availProcs);
237     len += sprintf(buffer + len, "rxi_totalMin = %d\n", rxi_totalMin);
238     len += sprintf(buffer + len, "rxi_minDeficit = %d\n", rxi_minDeficit);
239
240     len += sprintf(buffer + len, "rxevent_nFree = %d\nrxevent_nPosted = %d\n", rxevent_nFree, rxevent_nPosted);
241     
242     if (offset >= len) {
243         *start = buffer;
244         *eof = 1;
245         return 0;
246     }
247     *start = buffer + offset;
248     if ((len -= offset) > count)
249         return count;
250     *eof = 1;
251     return len;
252 }
253
254 int
255 connproc_read(char *buffer, char **start, off_t offset, int count,
256               int *eof, void *data)
257 {
258     int len, i, j;
259     struct rx_connection *sep;
260     
261     len = 0;
262     for (i = 0, j = 0; i < 256; i++) {
263         for (sep = rx_connHashTable[i]; sep; sep = sep->next, j++) {
264             len += sprintf(buffer + len, "%lx: next=0x%lx, peer=0x%lx, epoch=0x%x, cid=0x%x, ackRate=%d\n",
265                            (unsigned long)sep, (unsigned long)sep->next, (unsigned long)sep->peer,
266                            sep->epoch, sep->cid, sep->ackRate);
267             len += sprintf(buffer + len, "\tcall[%lx=%d, %lx=%d, %lx=%d, %lx=%d]\n", 
268                            (unsigned long)sep->call[0], sep->callNumber[0],
269                            (unsigned long)sep->call[1], sep->callNumber[1],
270                            (unsigned long)sep->call[2], sep->callNumber[2],
271                            (unsigned long)sep->call[3], sep->callNumber[3]);
272             len += sprintf(buffer + len, "\ttimeout=%d, flags=0x%x, type=0x%x, serviceId=%d, service=0x%lx, refCount=%d\n",
273                            sep->timeout, sep->flags, sep->type, 
274                            sep->serviceId, (unsigned long)sep->service, sep->refCount);
275             len += sprintf(buffer + len, "\tserial=%d, lastSerial=%d, secsUntilDead=%d, secsUntilPing=%d, secIndex=%d\n",
276                            sep->serial, sep->lastSerial, sep->secondsUntilDead,
277                            sep->secondsUntilPing, sep->securityIndex);
278             len += sprintf(buffer + len, "\terror=%d, secObject=0x%lx, secData=0x%lx, secHeaderSize=%d, secmaxTrailerSize=%d\n",
279                            sep->error, (unsigned long)sep->securityObject,
280                            (unsigned long)sep->securityData,
281                            sep->securityHeaderSize, sep->securityMaxTrailerSize);
282             len += sprintf(buffer + len, "\tchallEvent=0x%lx, lastSendTime=0x%x, maxSerial=%d, hardDeadTime=%d\n",
283                            (unsigned long)sep->challengeEvent, sep->lastSendTime, 
284                            sep->maxSerial, sep->hardDeadTime);
285             if (sep->flags & RX_CONN_MAKECALL_WAITING)
286                 len += sprintf(buffer + len, "\t***** Conn in RX_CONN_MAKECALL_WAITING state *****\n");
287 #ifdef RX_ENABLE_LOCKS
288             len += sprintf(buffer + len, "\tcall_lock=%d, call_cv=%d, data_lock=%d, refCount=%d\n",
289                            sep->conn_call_lock, sep->conn_call_cv, 
290                            sep->conn_data_lock, sep->refCount);
291 #endif /* RX_ENABLE_LOCKS */
292         }
293     }
294     
295     if (offset >= len) {
296         *start = buffer;
297         *eof = 1;
298         return 0;
299     }
300     *start = buffer + offset;
301     if ((len -= offset) > count)
302         return count;
303     *eof = 1;
304     return len;
305 }
306
307 int
308 servicesproc_read(char *buffer, char **start, off_t offset, int count,
309               int *eof, void *data)
310 {
311     int len, i, j;
312     struct rx_service *sentry;
313     
314     len = 0;
315     for (i = 0, j = 0; i < RX_MAX_SERVICES; i++) {
316         if ((sentry = rx_services[i])) {
317             j++;
318             len += sprintf(buffer + len,
319                            "\t%lx: serviceId=%d, port=%d, serviceName=%s, socket=0x%lx\n",
320                            (unsigned long)sentry, sentry->serviceId, sentry->servicePort,
321                            sentry->serviceName, (unsigned long)sentry->socket);
322             len += sprintf(buffer + len,
323                            "\t\tnSecObj=%d, nReqRunning=%d, maxProcs=%d, minProcs=%d, connDeadTime=%d, idleDeadTime=%d\n",
324                            sentry->nSecurityObjects, sentry->nRequestsRunning,
325                            sentry->maxProcs, sentry->minProcs, 
326                            sentry->connDeadTime, sentry->idleDeadTime);
327         }
328     }
329     
330     if (offset >= len) {
331         *start = buffer;
332         *eof = 1;
333         return 0;
334     }
335     *start = buffer + offset;
336     if ((len -= offset) > count)
337         return count;
338     *eof = 1;
339     return len;
340 }
341
342 int
343 callproc_read(char *buffer, char **start, off_t offset, int count,
344               int *eof, void *data)
345 {
346     int len, i, j, k;
347     struct rx_connection *sep;
348     
349     len = 0;
350     for (i = 0, j = 0; i < 256; i++) {
351         for (sep = rx_connHashTable[i]; sep; sep = sep->next) {
352             for (k = 0; k < RX_MAXCALLS; k++) {
353                 struct rx_call *call = sep->call[k];
354                 if (call) {
355                     j++;
356                     len += sprintf(buffer + len,
357                                    "%lx: conn=0x%lx, qiheader(0x%lx:0x%lx), tq(0x%lx:0x%lx), rq(0x%lx:0x%lx)\n",
358                                    (unsigned long)call, (unsigned long)call->conn,
359                                    (unsigned long)call->queue_item_header.prev,
360                                    (unsigned long)call->queue_item_header.next,
361                                    (unsigned long)call->tq.prev, (unsigned long)call->tq.next,
362                                    (unsigned long)call->rq.prev, (unsigned long)call->rq.next);
363                     len += sprintf(buffer + len, 
364                                    "\t: curvec=%d, curpos=%lx, nLeft=%d, nFree=%d, currPacket=0x%lx, callNumber=0x%lx\n",
365                                    call->curvec, (unsigned long)call->curpos, call->nLeft,
366                                    call->nFree, (unsigned long)call->currentPacket,
367                                    (unsigned long)call->callNumber);
368                     len += sprintf(buffer + len,
369                                    "\t: channel=%d, state=0x%x, mode=0x%x, flags=0x%x, localStatus=0x%x, remStatus=0x%x\n",
370                                    call->channel, call->state, call->mode,
371                                    call->flags, call->localStatus,
372                                    call->remoteStatus);
373                     len += sprintf(buffer + len,
374                                    "\t: error=%d, timeout=0x%x, rnext=0x%x, rprev=0x%x, rwind=0x%x, tfirst=0x%x, tnext=0x%x\n",
375                                    call->error, call->timeout, call->rnext,
376                                    call->rprev, call->rwind, call->tfirst,
377                                    call->tnext);
378                     len += sprintf(buffer + len,
379                                    "\t: twind=%d, resendEvent=0x%lx, timeoutEvent=0x%lx, keepAliveEvent=0x%lx, delayedAckEvent=0x%lx\n",
380                                    call->twind, (unsigned long)call->resendEvent,
381                                    (unsigned long)call->timeoutEvent,
382                                    (unsigned long)call->keepAliveEvent,
383                                    (unsigned long)call->delayedAckEvent);
384                     len += sprintf(buffer + len,
385                                    "\t: lastSendTime=0x%x, lastReceiveTime=0x%x, lastAcked=0x%x, startTime=0x%x, startWait=0x%x\n",
386                                    call->lastSendTime, call->lastReceiveTime,
387                                    call->lastAcked, call->startTime.sec,
388                                    call->startWait);
389                     if (call->flags & RX_CALL_WAIT_PROC)
390                         len += sprintf(buffer + len,
391                                        "\t******** Call in RX_CALL_WAIT_PROC state **********\n");
392                     if (call->flags & RX_CALL_WAIT_WINDOW_ALLOC)
393                         len += sprintf(buffer + len,
394                                        "\t******** Call in RX_CALL_WAIT_WINDOW_ALLOC state **********\n");
395                     if (call->flags & RX_CALL_READER_WAIT)
396                         len += sprintf(buffer + len,
397                                        "\t******** Conn in RX_CALL_READER_WAIT state **********\n");
398                     if (call->flags & RX_CALL_WAIT_PACKETS)
399                         len += sprintf(buffer + len,
400                                        "\t******** Conn in RX_CALL_WAIT_PACKETS state **********\n");
401 #ifdef RX_ENABLE_LOCKS
402                     len += sprintf(buffer + len,
403                                    "\t: lock=0x%x, cv_twind=0x%x, cv_rq=0x%x, refCount= %d\n",
404                                    call->lock, call->cv_twind, call->cv_rq,
405                                    call->refCount);
406 #endif /* RX_ENABLE_LOCKS */
407                     len += sprintf(buffer + len, "\t: MTU=%d\n", call->MTU);
408                 }
409             }
410         }
411     }
412     
413     if (offset >= len) {
414         *start = buffer;
415         *eof = 1;
416         return 0;
417     }
418     *start = buffer + offset;
419     if ((len -= offset) > count)
420         return count;
421     *eof = 1;
422     return len;
423 }
424
425 static struct proc_dir_entry *openafs_procfs;
426 #if defined(AFS_LINUX_64BIT_KERNEL) && !defined(AFS_ALPHA_LINUX20_ENV) && !defined(AFS_IA64_LINUX20_ENV)
427 static int ioctl32_done;
428 #endif
429
430 static int
431 afsproc_init(void)
432 {
433     struct proc_dir_entry *entry1;
434     struct proc_dir_entry *entry;
435
436     openafs_procfs = proc_mkdir(PROC_FSDIRNAME, proc_root_fs);
437     entry1 = create_proc_entry(PROC_SYSCALL_NAME, 0666, openafs_procfs);
438
439     entry1->proc_fops = &afs_syscall_fops;
440
441     entry1->owner = THIS_MODULE;
442
443     entry = create_proc_read_entry(PROC_CELLSERVDB_NAME, (S_IFREG|S_IRUGO), openafs_procfs, csdbproc_read, NULL);
444
445     entry = create_proc_read_entry(PROC_PEER_NAME, (S_IFREG|S_IRUGO), openafs_procfs, peerproc_read, NULL);
446
447     entry = create_proc_read_entry(PROC_CONN_NAME, (S_IFREG|S_IRUGO), openafs_procfs, connproc_read, NULL);
448
449     entry = create_proc_read_entry(PROC_CALL_NAME, (S_IFREG|S_IRUGO), openafs_procfs, connproc_read, NULL);
450
451     entry = create_proc_read_entry(PROC_RX_NAME, (S_IFREG|S_IRUGO), openafs_procfs, rxproc_read, NULL);
452
453     entry = create_proc_read_entry(PROC_SERVICES_NAME, (S_IFREG|S_IRUGO), openafs_procfs, servicesproc_read, NULL);
454
455     entry = create_proc_read_entry(PROC_RXSTATS_NAME, (S_IFREG|S_IRUGO), openafs_procfs, rxstatsproc_read, NULL);
456 #if defined(AFS_LINUX_64BIT_KERNEL) && !defined(AFS_ALPHA_LINUX20_ENV) && !defined(AFS_IA64_LINUX20_ENV)
457     if (register_ioctl32_conversion(VIOC_SYSCALL32, NULL) == 0) 
458             ioctl32_done = 1;
459 #endif
460
461     return 0;
462 }
463
464 static void
465 afsproc_exit(void)
466 {
467     remove_proc_entry(PROC_RXSTATS_NAME, openafs_procfs);
468     remove_proc_entry(PROC_SERVICES_NAME, openafs_procfs);
469     remove_proc_entry(PROC_RX_NAME, openafs_procfs);
470     remove_proc_entry(PROC_CALL_NAME, openafs_procfs);
471     remove_proc_entry(PROC_CONN_NAME, openafs_procfs);
472     remove_proc_entry(PROC_PEER_NAME, openafs_procfs);
473     remove_proc_entry(PROC_CELLSERVDB_NAME, openafs_procfs);
474     remove_proc_entry(PROC_SYSCALL_NAME, openafs_procfs);
475     remove_proc_entry(PROC_FSDIRNAME, proc_root_fs);
476 #if defined(AFS_LINUX_64BIT_KERNEL) && !defined(AFS_ALPHA_LINUX20_ENV) && !defined(AFS_IA64_LINUX20_ENV)
477     if (ioctl32_done)
478             unregister_ioctl32_conversion(VIOC_SYSCALL32);
479 #endif
480 }
481
482 extern asmlinkage long
483 afs_syscall(long syscall, long parm1, long parm2, long parm3, long parm4);
484
485 static int
486 afs_ioctl(struct inode *inode, struct file *file, unsigned int cmd,
487           unsigned long arg)
488 {
489
490     struct afsprocdata sysargs;
491     struct afsprocdata32 sysargs32;
492
493     if (cmd != VIOC_SYSCALL && cmd != VIOC_SYSCALL32) return -EINVAL;
494
495 #if defined(AFS_LINUX_64BIT_KERNEL) && !defined(AFS_ALPHA_LINUX20_ENV) && !defined(AFS_IA64_LINUX20_ENV)
496 #ifdef AFS_SPARC64_LINUX24_ENV
497     if (current->thread.flags & SPARC_FLAG_32BIT)
498 #elif defined(AFS_SPARC64_LINUX20_ENV)
499     if (current->tss.flags & SPARC_FLAG_32BIT)
500 #elif defined(AFS_AMD64_LINUX20_ENV)
501 #ifdef AFS_LINUX26_ENV
502     if (test_thread_flag(TIF_IA32))
503 #else
504     if (current->thread.flags & THREAD_IA32)
505 #endif
506 #elif defined(AFS_PPC64_LINUX20_ENV)
507 #ifdef AFS_PPC64_LINUX26_ENV
508     if (current->thread_info->flags & _TIF_32BIT)
509 #else /*Linux 2.6 */
510     if (current->thread.flags & PPC_FLAG_32BIT)
511 #endif
512 #elif defined(AFS_S390X_LINUX20_ENV)
513     if (current->thread.flags & S390_FLAG_31BIT)
514 #else
515 #error Not done for this linux type
516 #endif
517     {
518         if (copy_from_user(&sysargs32, (void *)arg,
519                            sizeof(struct afsprocdata32)))
520             return -EFAULT;
521
522         return afs_syscall((unsigned long)sysargs32.syscall,
523                            (unsigned long)sysargs32.param1,
524                            (unsigned long)sysargs32.param2,
525                            (unsigned long)sysargs32.param3,
526                            (unsigned long)sysargs32.param4);
527     } else
528 #endif
529     {
530         if (copy_from_user(&sysargs, (void *)arg, sizeof(struct afsprocdata)))
531             return -EFAULT;
532
533         return afs_syscall(sysargs.syscall, sysargs.param1,
534                            sysargs.param2, sysargs.param3, sysargs.param4);
535     }
536 }
537
538
539 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,4,0)
540 int __init
541 afs_init(void)
542 #else
543 int
544 init_module(void)
545 #endif
546 {
547     int e;
548     RWLOCK_INIT(&afs_xosi, "afs_xosi");
549
550 #if !defined(AFS_LINUX24_ENV)
551     /* obtain PAGE_OFFSET value */
552     afs_linux_page_offset = get_page_offset();
553
554 #ifndef AFS_S390_LINUX22_ENV
555     if (afs_linux_page_offset == 0) {
556         /* couldn't obtain page offset so can't continue */
557         printf("afs: Unable to obtain PAGE_OFFSET. Exiting..");
558         return -EIO;
559     }
560 #endif /* AFS_S390_LINUX22_ENV */
561 #endif /* !defined(AFS_LINUX24_ENV) */
562
563     osi_Init();
564
565     e = osi_syscall_init();
566     if (e) return e;
567     register_filesystem(&afs_fs_type);
568     osi_sysctl_init();
569     afsproc_init();
570
571     return 0;
572 }
573
574 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,4,0)
575 void __exit
576 afs_cleanup(void)
577 #else
578 void
579 cleanup_module(void)
580 #endif
581 {
582     osi_sysctl_clean();
583     osi_syscall_clean();
584     unregister_filesystem(&afs_fs_type);
585
586     osi_linux_free_inode_pages();       /* Invalidate all pages using AFS inodes. */
587     osi_linux_free_afs_memory();
588
589     afsproc_exit();
590     return;
591 }
592
593 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,4,0)
594 module_init(afs_init);
595 module_exit(afs_cleanup);
596 #endif
597
598
599 #if !defined(AFS_LINUX24_ENV)
600 static long
601 get_page_offset(void)
602 {
603 #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)
604     return PAGE_OFFSET;
605 #else
606     struct task_struct *p, *q;
607
608     /* search backward thru the circular list */
609 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,4,0)
610     read_lock(&tasklist_lock);
611 #endif
612     /* search backward thru the circular list */
613 #ifdef DEFINED_PREV_TASK
614     for (q = current; p = q; q = prev_task(p)) {
615 #else
616     for (p = current; p; p = p->prev_task) {
617 #endif
618         if (p->pid == 1) {
619 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,4,0)
620             read_unlock(&tasklist_lock);
621 #endif
622             return p->addr_limit.seg;
623         }
624     }
625
626 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,4,0)
627     read_unlock(&tasklist_lock);
628 #endif
629     return 0;
630 #endif
631 }
632 #endif /* !AFS_LINUX24_ENV */