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"
20 #include <linux/module.h> /* early to avoid printf->printk mapping */
21 #ifdef HAVE_KERNEL_LINUX_SEQ_FILE_H
22 #include <linux/seq_file.h>
24 #include "afs/sysincludes.h"
25 #include "afsincludes.h"
26 #include "afs/nfsclient.h"
27 #include "h/unistd.h" /* For syscall numbers. */
30 #ifdef AFS_AMD64_LINUX20_ENV
31 #include <asm/ia32_unistd.h>
34 #include <linux/proc_fs.h>
35 #include <linux/slab.h>
36 #include <linux/init.h>
37 #include <linux/sched.h>
38 #include <linux/kernel.h>
40 struct proc_dir_entry *openafs_procfs;
42 #ifdef HAVE_KERNEL_LINUX_SEQ_FILE_H
43 static void *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) {
63 static void *c_next(struct seq_file *m, void *p, loff_t *pos)
65 struct afs_q *cq = p, *tq;
78 static void c_stop(struct seq_file *m, void *p)
81 ReleaseReadLock(&afs_xcell);
85 static int c_show(struct seq_file *m, void *p)
88 struct cell *tc = QTOC(cq);
91 seq_printf(m, ">%s #(%d/%d)\n", tc->cellName,
92 tc->cellNum, tc->cellIndex);
94 for (j = 0; j < MAXCELLHOSTS; j++) {
97 if (!tc->cellHosts[j]) break;
99 addr = tc->cellHosts[j]->addr->sa_ip;
100 seq_printf(m, "%u.%u.%u.%u #%u.%u.%u.%u\n",
101 NIPQUAD(addr), NIPQUAD(addr));
107 static struct seq_operations afs_csdb_op = {
114 static int afs_csdb_open(struct inode *inode, struct file *file)
116 return seq_open(file, &afs_csdb_op);
119 static struct file_operations afs_csdb_operations = {
120 .open = afs_csdb_open,
123 .release = seq_release,
127 static void *uu_start(struct seq_file *m, loff_t *pos)
133 ObtainReadLock(&afs_xuser);
137 for (i = 0; i < NUSERS; i++) {
138 for (tu = afs_users[i]; tu; tu = tu->next) {
147 static void *uu_next(struct seq_file *m, void *p, loff_t *pos)
149 struct unixuser *tu = p;
155 if (p != (void *)1) {
156 if (tu->next) return tu->next;
157 i = UHash(tu->uid) + 1;
160 for (; i < NUSERS; i++)
161 if (afs_users[i]) return afs_users[i];
165 static void uu_stop(struct seq_file *m, void *p)
167 ReleaseReadLock(&afs_xuser);
170 static int uu_show(struct seq_file *m, void *p)
173 struct unixuser *tu = p;
176 if (p == (void *)1) {
177 seq_printf(m, "%10s %4s %-6s %-25s %10s",
178 "UID/PAG", "Refs", "States", "Cell", "ViceID");
179 seq_printf(m, " %10s %10s %10s %3s",
180 "Tok Set", "Tok Begin", "Tok Expire", "vno");
181 seq_printf(m, " %-15s %10s %10s %s\n",
182 "NFS Client", "UID/PAG", "Client UID", "Sysname(s)");
187 if (tu->cell == -1) {
188 cellname = "<default>";
190 tc = afs_GetCellStale(tu->cell, READ_LOCK);
191 if (tc) cellname = tc->cellName;
192 else cellname = "<unknown>";
195 seq_printf(m, "%10d %4d %04x %-25s %10d",
196 tu->uid, tu->refCount, tu->states, cellname, tu->vid);
198 if (tc) afs_PutCell(tc, READ_LOCK);
200 if (tu->states & UHasTokens) {
201 seq_printf(m, " %10d %10d %10d %3d",
202 tu->tokenTime, tu->ct.BeginTimestamp, tu->ct.EndTimestamp,
205 seq_printf(m, " %-36s", "Tokens Not Set");
208 if (tu->exporter && tu->exporter->exp_type == EXP_NFS) {
209 struct nfsclientpag *np = (struct nfsclientpag *)(tu->exporter);
213 sprintf(ipaddr, "%u.%u.%u.%u", NIPQUAD(np->host));
214 seq_printf(m, " %-15s %10d %10d", ipaddr, np->uid, np->client_uid);
215 if (np->sysnamecount) {
216 for (i = 0; i < np->sysnamecount; i++)
217 seq_printf(m, " %s", np->sysname[i]);
219 seq_printf(m, " <no sysname list>");
222 } else if (tu->exporter) {
223 seq_printf(m, " Unknown exporter type %d", tu->exporter->exp_type);
230 static struct seq_operations afs_unixuser_seqop = {
237 static int afs_unixuser_open(struct inode *inode, struct file *file)
239 return seq_open(file, &afs_unixuser_seqop);
242 static struct file_operations afs_unixuser_fops = {
243 .open = afs_unixuser_open,
246 .release = seq_release,
250 #else /* HAVE_KERNEL_LINUX_SEQ_FILE_H */
253 csdbproc_info(char *buffer, char **start, off_t offset, int
259 struct afs_q *cq, *tq;
262 /* 90 - 64 cellname, 10 for 32 bit num and index, plus
267 ObtainReadLock(&afs_xcell);
269 for (cq = CellLRU.next; cq != &CellLRU; cq = tq) {
270 tc = QTOC(cq); tq = QNext(cq);
277 sprintf(temp, ">%s #(%d/%d)\n", tc->cellName,
278 tc->cellNum, tc->cellIndex);
279 sprintf(buffer + len, "%-89s\n", temp);
281 if (pos >= offset+length) {
282 ReleaseReadLock(&afs_xcell);
287 for (cnt = 0; cnt < MAXCELLHOSTS; cnt++) {
288 if (!tc->cellHosts[cnt]) break;
293 addr = ntohl(tc->cellHosts[cnt]->addr->sa_ip);
294 sprintf(tbuffer, "%d.%d.%d.%d",
295 (int)((addr>>24) & 0xff),
296 (int)((addr>>16) & 0xff),
297 (int)((addr>>8) & 0xff), (int)( addr & 0xff));
298 sprintf(temp, "%s #%s\n", tbuffer, tbuffer);
299 sprintf(buffer + len, "%-89s\n", temp);
301 if (pos >= offset+length) {
302 ReleaseReadLock(&afs_xcell);
309 ReleaseReadLock(&afs_xcell);
312 *start = buffer + len - (pos - offset);
319 #endif /* HAVE_KERNEL_LINUX_SEQ_FILE_H */
324 struct proc_dir_entry *entry;
325 #if !defined(EXPORTED_PROC_ROOT_FS)
329 #if defined(EXPORTED_PROC_ROOT_FS)
330 openafs_procfs = proc_mkdir(PROC_FSDIRNAME, proc_root_fs);
332 sprintf(path, "fs/%s", PROC_FSDIRNAME);
333 openafs_procfs = proc_mkdir(path, NULL);
335 #ifdef HAVE_KERNEL_LINUX_SEQ_FILE_H
336 entry = create_proc_entry("unixusers", 0, openafs_procfs);
338 entry->proc_fops = &afs_unixuser_fops;
339 #if defined(STRUCT_PROC_DIR_ENTRY_HAS_OWNER)
340 entry->owner = THIS_MODULE;
343 entry = create_proc_entry(PROC_CELLSERVDB_NAME, 0, openafs_procfs);
345 entry->proc_fops = &afs_csdb_operations;
347 entry = create_proc_info_entry(PROC_CELLSERVDB_NAME, (S_IFREG|S_IRUGO), openafs_procfs, csdbproc_info);
349 #if defined(STRUCT_PROC_DIR_ENTRY_HAS_OWNER)
350 entry->owner = THIS_MODULE;
357 #if !defined(EXPORTED_PROC_ROOT_FS)
361 remove_proc_entry(PROC_CELLSERVDB_NAME, openafs_procfs);
362 #ifdef HAVE_KERNEL_LINUX_SEQ_FILE_H
363 remove_proc_entry("unixusers", openafs_procfs);
365 #if defined(EXPORTED_PROC_ROOT_FS)
366 remove_proc_entry(PROC_FSDIRNAME, proc_root_fs);
368 sprintf(path, "fs/%s", PROC_FSDIRNAME);
369 remove_proc_entry(path, NULL);