2 * Copyright 2000, International Business Machines Corporation and others.
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
11 * Linux module support routines.
14 #include <afsconfig.h>
15 #include "afs/param.h"
18 #include <linux/module.h> /* early to avoid printf->printk mapping */
19 #ifdef HAVE_LINUX_SEQ_FILE_H
20 # include <linux/seq_file.h>
22 #include "afs/sysincludes.h"
23 #include "afsincludes.h"
24 #include "afs/nfsclient.h"
25 #include <linux/unistd.h> /* For syscall numbers. */
28 #ifdef AFS_AMD64_LINUX_ENV
29 # include <asm/ia32_unistd.h>
32 #include <linux/slab.h>
33 #include <linux/init.h>
34 #include <linux/sched.h>
35 #include <linux/kernel.h>
37 #include "osi_compat.h"
39 struct proc_dir_entry *openafs_procfs;
41 #ifdef HAVE_LINUX_SEQ_FILE_H
43 c_start(struct seq_file *m, loff_t *pos)
45 struct afs_q *cq, *tq;
49 ObtainReadLock(&afs_xcell);
50 for (cq = CellLRU.next; cq != &CellLRU; cq = tq) {
64 c_next(struct seq_file *m, void *p, loff_t *pos)
66 struct afs_q *cq = p, *tq;
80 c_stop(struct seq_file *m, void *p)
83 ReleaseReadLock(&afs_xcell);
88 c_show(struct seq_file *m, void *p)
91 struct cell *tc = QTOC(cq);
94 seq_printf(m, ">%s #(%d/%d)\n", tc->cellName,
95 tc->cellNum, tc->cellIndex);
97 for (j = 0; j < AFS_MAXCELLHOSTS; j++) {
100 if (!tc->cellHosts[j]) break;
102 addr = tc->cellHosts[j]->addr->sa_ip;
104 seq_printf(m, "%u.%u.%u.%u #%u.%u.%u.%u\n",
105 NIPQUAD(addr), NIPQUAD(addr));
107 seq_printf(m, "%pI4 #%pI4\n", &addr, &addr);
114 static struct seq_operations afs_csdb_op = {
122 afs_csdb_open(struct inode *inode, struct file *file)
124 return seq_open(file, &afs_csdb_op);
127 #if defined(HAVE_LINUX_STRUCT_PROC_OPS)
128 static struct proc_ops afs_csdb_operations = {
129 .proc_open = afs_csdb_open,
130 .proc_read = seq_read,
131 .proc_lseek = seq_lseek,
132 .proc_release = seq_release,
135 static struct file_operations afs_csdb_operations = {
136 .open = afs_csdb_open,
139 .release = seq_release,
141 #endif /* HAVE_LINUX_STRUCT_PROC_OPS */
144 uu_start(struct seq_file *m, loff_t *pos)
152 ObtainReadLock(&afs_xuser);
161 for (i = 0; i < NUSERS; i++) {
162 for (tu = afs_users[i]; tu; tu = tu->next) {
176 uu_next(struct seq_file *m, void *p, loff_t *pos)
178 struct unixuser *tu = p;
184 if (p != (void *)1) {
185 if (tu->next) return tu->next;
186 i = UHash(tu->uid) + 1;
189 for (; i < NUSERS; i++)
190 if (afs_users[i]) return afs_users[i];
195 uu_stop(struct seq_file *m, void *p)
198 ReleaseReadLock(&afs_xuser);
203 uu_show(struct seq_file *m, void *p)
206 struct unixuser *tu = p;
207 union tokenUnion *token;
210 if (p == (void *)1) {
211 seq_printf(m, "%10s %4s %-6s %-25s %10s",
212 "UID/PAG", "Refs", "States", "Cell", "ViceID");
213 seq_printf(m, " %10s %10s %10s %3s",
214 "Tok Set", "Tok Begin", "Tok Expire", "vno");
215 seq_printf(m, " %-15s %10s %10s %s\n",
216 "NFS Client", "UID/PAG", "Client UID", "Sysname(s)");
224 ReleaseReadLock(&afs_xuser);
226 afs_LockUser(tu, READ_LOCK, 0);
228 if (tu->cell == -1) {
229 cellname = "<default>";
231 tc = afs_GetCellStale(tu->cell, READ_LOCK);
232 if (tc) cellname = tc->cellName;
233 else cellname = "<unknown>";
236 seq_printf(m, "%10d %4d %04x %-25s %10d",
237 tu->uid, tu->refCount, tu->states, cellname, tu->viceId);
239 if (tc) afs_PutCell(tc, READ_LOCK);
241 if (tu->states & UHasTokens) {
242 token = afs_FindToken(tu->tokens, RX_SECIDX_KAD);
243 seq_printf(m, " %10d %10d %10d %3d",
245 (token!=NULL)?token->rxkad.clearToken.BeginTimestamp:0,
246 (token!=NULL)?token->rxkad.clearToken.EndTimestamp:0,
247 (token!=NULL)?token->rxkad.clearToken.AuthHandle:0);
249 seq_printf(m, " %-36s", "Tokens Not Set");
252 if (tu->exporter && tu->exporter->exp_type == EXP_NFS) {
253 struct nfsclientpag *np = (struct nfsclientpag *)(tu->exporter);
258 sprintf(ipaddr, "%u.%u.%u.%u", NIPQUAD(np->host));
260 sprintf(ipaddr, "%pI4", &np->host);
262 seq_printf(m, " %-15s %10d %10d", ipaddr, np->uid, np->client_uid);
263 if (np->sysnamecount) {
264 for (i = 0; i < np->sysnamecount; i++)
265 seq_printf(m, " %s", np->sysname[i]);
267 seq_printf(m, " <no sysname list>");
270 } else if (tu->exporter) {
271 seq_printf(m, " Unknown exporter type %d", tu->exporter->exp_type);
275 afs_PutUser(tu, READ_LOCK);
276 ObtainReadLock(&afs_xuser);
283 static struct seq_operations afs_unixuser_seqop = {
291 afs_unixuser_open(struct inode *inode, struct file *file)
293 return seq_open(file, &afs_unixuser_seqop);
296 #if defined(HAVE_LINUX_STRUCT_PROC_OPS)
297 static struct proc_ops afs_unixuser_ops = {
298 .proc_open = afs_unixuser_open,
299 .proc_read = seq_read,
300 .proc_lseek = seq_lseek,
301 .proc_release = seq_release,
304 static struct file_operations afs_unixuser_ops = {
305 .open = afs_unixuser_open,
308 .release = seq_release,
310 #endif /* HAVE_LINUX_STRUCT_PROC_OPS */
312 #else /* HAVE_LINUX_SEQ_FILE_H */
315 csdbproc_info(char *buffer, char **start, off_t offset, int length)
320 struct afs_q *cq, *tq;
323 /* 90 - 64 cellname, 10 for 32 bit num and index, plus
330 ObtainReadLock(&afs_xcell);
332 for (cq = CellLRU.next; cq != &CellLRU; cq = tq) {
333 tc = QTOC(cq); tq = QNext(cq);
340 sprintf(temp, ">%s #(%d/%d)\n", tc->cellName,
341 tc->cellNum, tc->cellIndex);
342 sprintf(buffer + len, "%-89s\n", temp);
344 if (pos >= offset+length) {
345 ReleaseReadLock(&afs_xcell);
350 for (cnt = 0; cnt < AFS_MAXCELLHOSTS; cnt++) {
351 if (!tc->cellHosts[cnt]) break;
356 addr = ntohl(tc->cellHosts[cnt]->addr->sa_ip);
357 sprintf(tbuffer, "%d.%d.%d.%d",
358 (int)((addr>>24) & 0xff),
359 (int)((addr>>16) & 0xff),
360 (int)((addr>>8) & 0xff), (int)( addr & 0xff));
361 sprintf(temp, "%s #%s\n", tbuffer, tbuffer);
362 sprintf(buffer + len, "%-89s\n", temp);
364 if (pos >= offset+length) {
365 ReleaseReadLock(&afs_xcell);
372 ReleaseReadLock(&afs_xcell);
377 *start = buffer + len - (pos - offset);
384 #endif /* HAVE_LINUX_SEQ_FILE_H */
389 struct proc_dir_entry *entry;
390 #if !defined(EXPORTED_PROC_ROOT_FS)
394 #if defined(EXPORTED_PROC_ROOT_FS)
395 openafs_procfs = proc_mkdir(PROC_FSDIRNAME, proc_root_fs);
397 sprintf(path, "fs/%s", PROC_FSDIRNAME);
398 openafs_procfs = proc_mkdir(path, NULL);
400 #ifdef HAVE_LINUX_SEQ_FILE_H
401 entry = afs_proc_create("unixusers", 0, openafs_procfs, &afs_unixuser_ops);
402 # if defined(STRUCT_PROC_DIR_ENTRY_HAS_OWNER)
404 entry->owner = THIS_MODULE;
406 entry = afs_proc_create(PROC_CELLSERVDB_NAME, 0, openafs_procfs, &afs_csdb_operations);
408 entry = create_proc_info_entry(PROC_CELLSERVDB_NAME, (S_IFREG|S_IRUGO), openafs_procfs, csdbproc_info);
410 #if defined(STRUCT_PROC_DIR_ENTRY_HAS_OWNER)
412 entry->owner = THIS_MODULE;
419 #if !defined(EXPORTED_PROC_ROOT_FS)
423 remove_proc_entry(PROC_CELLSERVDB_NAME, openafs_procfs);
424 #ifdef HAVE_LINUX_SEQ_FILE_H
425 remove_proc_entry("unixusers", openafs_procfs);
427 #if defined(EXPORTED_PROC_ROOT_FS)
428 remove_proc_entry(PROC_FSDIRNAME, proc_root_fs);
430 sprintf(path, "fs/%s", PROC_FSDIRNAME);
431 remove_proc_entry(path, NULL);