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 #include "afs/sysincludes.h"
22 #include "afsincludes.h"
23 #include "afs/nfsclient.h"
24 #include "h/unistd.h" /* For syscall numbers. */
27 #ifdef AFS_AMD64_LINUX20_ENV
28 #include <asm/ia32_unistd.h>
31 #include <linux/proc_fs.h>
32 #include <linux/slab.h>
33 #include <linux/init.h>
34 #include <linux/sched.h>
35 #include <linux/kernel.h>
37 #ifdef HAVE_KERNEL_LINUX_SEQ_FILE_H
38 #include <linux/seq_file.h>
41 struct proc_dir_entry *openafs_procfs;
43 #ifdef HAVE_KERNEL_LINUX_SEQ_FILE_H
44 static void *c_start(struct seq_file *m, loff_t *pos)
46 struct afs_q *cq, *tq;
49 ObtainReadLock(&afs_xcell);
50 for (cq = CellLRU.next; cq != &CellLRU; cq = tq) {
62 static void *c_next(struct seq_file *m, void *p, loff_t *pos)
64 struct afs_q *cq = p, *tq;
75 static void c_stop(struct seq_file *m, void *p)
77 ReleaseReadLock(&afs_xcell);
80 static int c_show(struct seq_file *m, void *p)
83 struct cell *tc = QTOC(cq);
86 seq_printf(m, ">%s #(%d/%d)\n", tc->cellName,
87 tc->cellNum, tc->cellIndex);
89 for (j = 0; j < MAXCELLHOSTS; j++) {
92 if (!tc->cellHosts[j]) break;
94 addr = tc->cellHosts[j]->addr->sa_ip;
95 seq_printf(m, "%u.%u.%u.%u #%u.%u.%u.%u\n",
96 NIPQUAD(addr), NIPQUAD(addr));
102 static struct seq_operations afs_csdb_op = {
109 static int afs_csdb_open(struct inode *inode, struct file *file)
111 return seq_open(file, &afs_csdb_op);
114 static struct file_operations afs_csdb_operations = {
115 .open = afs_csdb_open,
118 .release = seq_release,
122 static void *uu_start(struct seq_file *m, loff_t *pos)
128 ObtainReadLock(&afs_xuser);
132 for (i = 0; i < NUSERS; i++) {
133 for (tu = afs_users[i]; tu; tu = tu->next) {
142 static void *uu_next(struct seq_file *m, void *p, loff_t *pos)
144 struct unixuser *tu = p;
150 if (p != (void *)1) {
151 if (tu->next) return tu->next;
152 i = UHash(tu->uid) + 1;
155 for (; i < NUSERS; i++)
156 if (afs_users[i]) return afs_users[i];
160 static void uu_stop(struct seq_file *m, void *p)
162 ReleaseReadLock(&afs_xuser);
165 static int uu_show(struct seq_file *m, void *p)
168 struct unixuser *tu = p;
171 if (p == (void *)1) {
172 seq_printf(m, "%10s %4s %-6s %-25s %10s",
173 "UID/PAG", "Refs", "States", "Cell", "ViceID");
174 seq_printf(m, " %10s %10s %10s %3s",
175 "Tok Set", "Tok Begin", "Tok Expire", "vno");
176 seq_printf(m, " %-15s %10s %10s %s\n",
177 "NFS Client", "UID/PAG", "Client UID", "Sysname(s)");
182 if (tu->cell == -1) {
183 cellname = "<default>";
185 tc = afs_GetCellStale(tu->cell, READ_LOCK);
186 if (tc) cellname = tc->cellName;
187 else cellname = "<unknown>";
190 seq_printf(m, "%10d %4d %04x %-25s %10d",
191 tu->uid, tu->refCount, tu->states, cellname, tu->vid);
193 if (tc) afs_PutCell(tc, READ_LOCK);
195 if (tu->states & UHasTokens) {
196 seq_printf(m, " %10d %10d %10d %3d",
197 tu->tokenTime, tu->ct.BeginTimestamp, tu->ct.EndTimestamp,
200 seq_printf(m, " %-36s", "Tokens Not Set");
203 if (tu->exporter && tu->exporter->exp_type == EXP_NFS) {
204 struct nfsclientpag *np = (struct nfsclientpag *)(tu->exporter);
208 sprintf(ipaddr, "%u.%u.%u.%u", NIPQUAD(np->host));
209 seq_printf(m, " %-15s %10d %10d", ipaddr, np->uid, np->client_uid);
210 if (np->sysnamecount) {
211 for (i = 0; i < np->sysnamecount; i++)
212 seq_printf(m, " %s", np->sysname[i]);
214 seq_printf(m, " <no sysname list>");
217 } else if (tu->exporter) {
218 seq_printf(m, " Unknown exporter type %d", tu->exporter->exp_type);
225 static struct seq_operations afs_unixuser_seqop = {
232 static int afs_unixuser_open(struct inode *inode, struct file *file)
234 return seq_open(file, &afs_unixuser_seqop);
237 static struct file_operations afs_unixuser_fops = {
238 .open = afs_unixuser_open,
241 .release = seq_release,
245 #else /* HAVE_KERNEL_LINUX_SEQ_FILE_H */
248 csdbproc_info(char *buffer, char **start, off_t offset, int
254 struct afs_q *cq, *tq;
257 /* 90 - 64 cellname, 10 for 32 bit num and index, plus
262 ObtainReadLock(&afs_xcell);
264 for (cq = CellLRU.next; cq != &CellLRU; cq = tq) {
265 tc = QTOC(cq); tq = QNext(cq);
272 sprintf(temp, ">%s #(%d/%d)\n", tc->cellName,
273 tc->cellNum, tc->cellIndex);
274 sprintf(buffer + len, "%-89s\n", temp);
276 if (pos >= offset+length) {
277 ReleaseReadLock(&afs_xcell);
282 for (cnt = 0; cnt < MAXCELLHOSTS; cnt++) {
283 if (!tc->cellHosts[cnt]) break;
288 addr = ntohl(tc->cellHosts[cnt]->addr->sa_ip);
289 sprintf(tbuffer, "%d.%d.%d.%d",
290 (int)((addr>>24) & 0xff),
291 (int)((addr>>16) & 0xff),
292 (int)((addr>>8) & 0xff), (int)( addr & 0xff));
293 sprintf(temp, "%s #%s\n", tbuffer, tbuffer);
294 sprintf(buffer + len, "%-89s\n", temp);
296 if (pos >= offset+length) {
297 ReleaseReadLock(&afs_xcell);
304 ReleaseReadLock(&afs_xcell);
307 *start = buffer + len - (pos - offset);
314 #endif /* HAVE_KERNEL_LINUX_SEQ_FILE_H */
319 struct proc_dir_entry *entry;
320 #if !defined(EXPORTED_PROC_ROOT_FS)
324 #if defined(EXPORTED_PROC_ROOT_FS)
325 openafs_procfs = proc_mkdir(PROC_FSDIRNAME, proc_root_fs);
327 sprintf(path, "fs/%s", PROC_FSDIRNAME);
328 openafs_procfs = proc_mkdir(path, NULL);
330 #ifdef HAVE_KERNEL_LINUX_SEQ_FILE_H
331 entry = create_proc_entry("unixusers", 0, openafs_procfs);
333 entry->proc_fops = &afs_unixuser_fops;
334 entry->owner = THIS_MODULE;
336 entry = create_proc_entry(PROC_CELLSERVDB_NAME, 0, openafs_procfs);
338 entry->proc_fops = &afs_csdb_operations;
340 entry = create_proc_info_entry(PROC_CELLSERVDB_NAME, (S_IFREG|S_IRUGO), openafs_procfs, csdbproc_info);
342 entry->owner = THIS_MODULE;
348 #if !defined(EXPORTED_PROC_ROOT_FS)
352 #if defined(EXPORTED_PROC_ROOT_FS)
353 remove_proc_entry(PROC_FSDIRNAME, proc_root_fs);
355 sprintf(path, "fs/%s", PROC_FSDIRNAME);
356 remove_proc_entry(path, NULL);
358 remove_proc_entry(PROC_CELLSERVDB_NAME, openafs_procfs);
359 #ifdef HAVE_KERNEL_LINUX_SEQ_FILE_H
360 remove_proc_entry("unixusers", openafs_procfs);