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_LINUX20_ENV
29 #include <asm/ia32_unistd.h>
32 #include <linux/proc_fs.h>
33 #include <linux/slab.h>
34 #include <linux/init.h>
35 #include <linux/sched.h>
36 #include <linux/kernel.h>
38 struct proc_dir_entry *openafs_procfs;
40 #ifdef HAVE_LINUX_SEQ_FILE_H
41 static void *c_start(struct seq_file *m, loff_t *pos)
43 struct afs_q *cq, *tq;
47 ObtainReadLock(&afs_xcell);
48 for (cq = CellLRU.next; cq != &CellLRU; cq = tq) {
61 static void *c_next(struct seq_file *m, void *p, loff_t *pos)
63 struct afs_q *cq = p, *tq;
76 static void c_stop(struct seq_file *m, void *p)
79 ReleaseReadLock(&afs_xcell);
83 static int c_show(struct seq_file *m, void *p)
86 struct cell *tc = QTOC(cq);
89 seq_printf(m, ">%s #(%d/%d)\n", tc->cellName,
90 tc->cellNum, tc->cellIndex);
92 for (j = 0; j < AFS_MAXCELLHOSTS; j++) {
95 if (!tc->cellHosts[j]) break;
97 addr = tc->cellHosts[j]->addr->sa_ip;
99 seq_printf(m, "%u.%u.%u.%u #%u.%u.%u.%u\n",
100 NIPQUAD(addr), NIPQUAD(addr));
102 seq_printf(m, "%pI4 #%pI4\n", &addr, &addr);
109 static struct seq_operations afs_csdb_op = {
116 static int afs_csdb_open(struct inode *inode, struct file *file)
118 return seq_open(file, &afs_csdb_op);
121 static struct file_operations afs_csdb_operations = {
122 .open = afs_csdb_open,
125 .release = seq_release,
129 static void *uu_start(struct seq_file *m, loff_t *pos)
135 ObtainReadLock(&afs_xuser);
139 for (i = 0; i < NUSERS; i++) {
140 for (tu = afs_users[i]; tu; tu = tu->next) {
149 static void *uu_next(struct seq_file *m, void *p, loff_t *pos)
151 struct unixuser *tu = p;
157 if (p != (void *)1) {
158 if (tu->next) return tu->next;
159 i = UHash(tu->uid) + 1;
162 for (; i < NUSERS; i++)
163 if (afs_users[i]) return afs_users[i];
167 static void uu_stop(struct seq_file *m, void *p)
169 ReleaseReadLock(&afs_xuser);
172 static int uu_show(struct seq_file *m, void *p)
175 struct unixuser *tu = p;
176 union tokenUnion *token;
179 if (p == (void *)1) {
180 seq_printf(m, "%10s %4s %-6s %-25s %10s",
181 "UID/PAG", "Refs", "States", "Cell", "ViceID");
182 seq_printf(m, " %10s %10s %10s %3s",
183 "Tok Set", "Tok Begin", "Tok Expire", "vno");
184 seq_printf(m, " %-15s %10s %10s %s\n",
185 "NFS Client", "UID/PAG", "Client UID", "Sysname(s)");
191 ReleaseReadLock(&afs_xuser);
193 afs_LockUser(tu, READ_LOCK, 0);
195 if (tu->cell == -1) {
196 cellname = "<default>";
198 tc = afs_GetCellStale(tu->cell, READ_LOCK);
199 if (tc) cellname = tc->cellName;
200 else cellname = "<unknown>";
203 seq_printf(m, "%10d %4d %04x %-25s %10d",
204 tu->uid, tu->refCount, tu->states, cellname, tu->viceId);
206 if (tc) afs_PutCell(tc, READ_LOCK);
208 if (tu->states & UHasTokens) {
209 token = afs_FindToken(tu->tokens, RX_SECIDX_KAD);
210 seq_printf(m, " %10d %10d %10d %3d",
212 (token!=NULL)?token->rxkad.clearToken.BeginTimestamp:0,
213 (token!=NULL)?token->rxkad.clearToken.EndTimestamp:0,
214 (token!=NULL)?token->rxkad.clearToken.AuthHandle:0);
216 seq_printf(m, " %-36s", "Tokens Not Set");
219 if (tu->exporter && tu->exporter->exp_type == EXP_NFS) {
220 struct nfsclientpag *np = (struct nfsclientpag *)(tu->exporter);
225 sprintf(ipaddr, "%u.%u.%u.%u", NIPQUAD(np->host));
227 sprintf(ipaddr, "%pI4", &np->host);
229 seq_printf(m, " %-15s %10d %10d", ipaddr, np->uid, np->client_uid);
230 if (np->sysnamecount) {
231 for (i = 0; i < np->sysnamecount; i++)
232 seq_printf(m, " %s", np->sysname[i]);
234 seq_printf(m, " <no sysname list>");
237 } else if (tu->exporter) {
238 seq_printf(m, " Unknown exporter type %d", tu->exporter->exp_type);
242 afs_PutUser(tu, READ_LOCK);
243 ObtainReadLock(&afs_xuser);
248 static struct seq_operations afs_unixuser_seqop = {
255 static int afs_unixuser_open(struct inode *inode, struct file *file)
257 return seq_open(file, &afs_unixuser_seqop);
260 static struct file_operations afs_unixuser_fops = {
261 .open = afs_unixuser_open,
264 .release = seq_release,
268 #else /* HAVE_LINUX_SEQ_FILE_H */
271 csdbproc_info(char *buffer, char **start, off_t offset, int
277 struct afs_q *cq, *tq;
280 /* 90 - 64 cellname, 10 for 32 bit num and index, plus
285 ObtainReadLock(&afs_xcell);
287 for (cq = CellLRU.next; cq != &CellLRU; cq = tq) {
288 tc = QTOC(cq); tq = QNext(cq);
295 sprintf(temp, ">%s #(%d/%d)\n", tc->cellName,
296 tc->cellNum, tc->cellIndex);
297 sprintf(buffer + len, "%-89s\n", temp);
299 if (pos >= offset+length) {
300 ReleaseReadLock(&afs_xcell);
305 for (cnt = 0; cnt < AFS_MAXCELLHOSTS; cnt++) {
306 if (!tc->cellHosts[cnt]) break;
311 addr = ntohl(tc->cellHosts[cnt]->addr->sa_ip);
312 sprintf(tbuffer, "%d.%d.%d.%d",
313 (int)((addr>>24) & 0xff),
314 (int)((addr>>16) & 0xff),
315 (int)((addr>>8) & 0xff), (int)( addr & 0xff));
316 sprintf(temp, "%s #%s\n", tbuffer, tbuffer);
317 sprintf(buffer + len, "%-89s\n", temp);
319 if (pos >= offset+length) {
320 ReleaseReadLock(&afs_xcell);
327 ReleaseReadLock(&afs_xcell);
330 *start = buffer + len - (pos - offset);
337 #endif /* HAVE_LINUX_SEQ_FILE_H */
342 struct proc_dir_entry *entry;
343 #if !defined(EXPORTED_PROC_ROOT_FS)
347 #if defined(EXPORTED_PROC_ROOT_FS)
348 openafs_procfs = proc_mkdir(PROC_FSDIRNAME, proc_root_fs);
350 sprintf(path, "fs/%s", PROC_FSDIRNAME);
351 openafs_procfs = proc_mkdir(path, NULL);
353 #ifdef HAVE_LINUX_SEQ_FILE_H
354 entry = create_proc_entry("unixusers", 0, openafs_procfs);
356 entry->proc_fops = &afs_unixuser_fops;
357 #if defined(STRUCT_PROC_DIR_ENTRY_HAS_OWNER)
358 entry->owner = THIS_MODULE;
361 entry = create_proc_entry(PROC_CELLSERVDB_NAME, 0, openafs_procfs);
363 entry->proc_fops = &afs_csdb_operations;
365 entry = create_proc_info_entry(PROC_CELLSERVDB_NAME, (S_IFREG|S_IRUGO), openafs_procfs, csdbproc_info);
367 #if defined(STRUCT_PROC_DIR_ENTRY_HAS_OWNER)
368 entry->owner = THIS_MODULE;
375 #if !defined(EXPORTED_PROC_ROOT_FS)
379 remove_proc_entry(PROC_CELLSERVDB_NAME, openafs_procfs);
380 #ifdef HAVE_LINUX_SEQ_FILE_H
381 remove_proc_entry("unixusers", openafs_procfs);
383 #if defined(EXPORTED_PROC_ROOT_FS)
384 remove_proc_entry(PROC_FSDIRNAME, proc_root_fs);
386 sprintf(path, "fs/%s", PROC_FSDIRNAME);
387 remove_proc_entry(path, NULL);