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;
50 ObtainReadLock(&afs_xcell);
51 for (cq = CellLRU.next; cq != &CellLRU; cq = tq) {
64 static void *c_next(struct seq_file *m, void *p, loff_t *pos)
66 struct afs_q *cq = p, *tq;
79 static void c_stop(struct seq_file *m, void *p)
82 ReleaseReadLock(&afs_xcell);
86 static int c_show(struct seq_file *m, void *p)
89 struct cell *tc = QTOC(cq);
92 seq_printf(m, ">%s #(%d/%d)\n", tc->cellName,
93 tc->cellNum, tc->cellIndex);
95 for (j = 0; j < MAXCELLHOSTS; j++) {
98 if (!tc->cellHosts[j]) break;
100 addr = tc->cellHosts[j]->addr->sa_ip;
101 seq_printf(m, "%u.%u.%u.%u #%u.%u.%u.%u\n",
102 NIPQUAD(addr), NIPQUAD(addr));
108 static struct seq_operations afs_csdb_op = {
115 static int afs_csdb_open(struct inode *inode, struct file *file)
117 return seq_open(file, &afs_csdb_op);
120 static struct file_operations afs_csdb_operations = {
121 .open = afs_csdb_open,
124 .release = seq_release,
128 static void *uu_start(struct seq_file *m, loff_t *pos)
134 ObtainReadLock(&afs_xuser);
138 for (i = 0; i < NUSERS; i++) {
139 for (tu = afs_users[i]; tu; tu = tu->next) {
148 static void *uu_next(struct seq_file *m, void *p, loff_t *pos)
150 struct unixuser *tu = p;
156 if (p != (void *)1) {
157 if (tu->next) return tu->next;
158 i = UHash(tu->uid) + 1;
161 for (; i < NUSERS; i++)
162 if (afs_users[i]) return afs_users[i];
166 static void uu_stop(struct seq_file *m, void *p)
168 ReleaseReadLock(&afs_xuser);
171 static int uu_show(struct seq_file *m, void *p)
174 struct unixuser *tu = p;
177 if (p == (void *)1) {
178 seq_printf(m, "%10s %4s %-6s %-25s %10s",
179 "UID/PAG", "Refs", "States", "Cell", "ViceID");
180 seq_printf(m, " %10s %10s %10s %3s",
181 "Tok Set", "Tok Begin", "Tok Expire", "vno");
182 seq_printf(m, " %-15s %10s %10s %s\n",
183 "NFS Client", "UID/PAG", "Client UID", "Sysname(s)");
188 if (tu->cell == -1) {
189 cellname = "<default>";
191 tc = afs_GetCellStale(tu->cell, READ_LOCK);
192 if (tc) cellname = tc->cellName;
193 else cellname = "<unknown>";
196 seq_printf(m, "%10d %4d %04x %-25s %10d",
197 tu->uid, tu->refCount, tu->states, cellname, tu->vid);
199 if (tc) afs_PutCell(tc, READ_LOCK);
201 if (tu->states & UHasTokens) {
202 seq_printf(m, " %10d %10d %10d %3d",
203 tu->tokenTime, tu->ct.BeginTimestamp, tu->ct.EndTimestamp,
206 seq_printf(m, " %-36s", "Tokens Not Set");
209 if (tu->exporter && tu->exporter->exp_type == EXP_NFS) {
210 struct nfsclientpag *np = (struct nfsclientpag *)(tu->exporter);
214 sprintf(ipaddr, "%u.%u.%u.%u", NIPQUAD(np->host));
215 seq_printf(m, " %-15s %10d %10d", ipaddr, np->uid, np->client_uid);
216 if (np->sysnamecount) {
217 for (i = 0; i < np->sysnamecount; i++)
218 seq_printf(m, " %s", np->sysname[i]);
220 seq_printf(m, " <no sysname list>");
223 } else if (tu->exporter) {
224 seq_printf(m, " Unknown exporter type %d", tu->exporter->exp_type);
231 static struct seq_operations afs_unixuser_seqop = {
238 static int afs_unixuser_open(struct inode *inode, struct file *file)
240 return seq_open(file, &afs_unixuser_seqop);
243 static struct file_operations afs_unixuser_fops = {
244 .open = afs_unixuser_open,
247 .release = seq_release,
251 #else /* HAVE_KERNEL_LINUX_SEQ_FILE_H */
254 csdbproc_info(char *buffer, char **start, off_t offset, int
260 struct afs_q *cq, *tq;
263 /* 90 - 64 cellname, 10 for 32 bit num and index, plus
268 ObtainReadLock(&afs_xcell);
270 for (cq = CellLRU.next; cq != &CellLRU; cq = tq) {
271 tc = QTOC(cq); tq = QNext(cq);
278 sprintf(temp, ">%s #(%d/%d)\n", tc->cellName,
279 tc->cellNum, tc->cellIndex);
280 sprintf(buffer + len, "%-89s\n", temp);
282 if (pos >= offset+length) {
283 ReleaseReadLock(&afs_xcell);
288 for (cnt = 0; cnt < MAXCELLHOSTS; cnt++) {
289 if (!tc->cellHosts[cnt]) break;
294 addr = ntohl(tc->cellHosts[cnt]->addr->sa_ip);
295 sprintf(tbuffer, "%d.%d.%d.%d",
296 (int)((addr>>24) & 0xff),
297 (int)((addr>>16) & 0xff),
298 (int)((addr>>8) & 0xff), (int)( addr & 0xff));
299 sprintf(temp, "%s #%s\n", tbuffer, tbuffer);
300 sprintf(buffer + len, "%-89s\n", temp);
302 if (pos >= offset+length) {
303 ReleaseReadLock(&afs_xcell);
310 ReleaseReadLock(&afs_xcell);
313 *start = buffer + len - (pos - offset);
320 #endif /* HAVE_KERNEL_LINUX_SEQ_FILE_H */
325 struct proc_dir_entry *entry;
326 #if !defined(EXPORTED_PROC_ROOT_FS)
330 #if defined(EXPORTED_PROC_ROOT_FS)
331 openafs_procfs = proc_mkdir(PROC_FSDIRNAME, proc_root_fs);
333 sprintf(path, "fs/%s", PROC_FSDIRNAME);
334 openafs_procfs = proc_mkdir(path, NULL);
336 #ifdef HAVE_KERNEL_LINUX_SEQ_FILE_H
337 entry = create_proc_entry("unixusers", 0, openafs_procfs);
339 entry->proc_fops = &afs_unixuser_fops;
340 entry->owner = THIS_MODULE;
342 entry = create_proc_entry(PROC_CELLSERVDB_NAME, 0, openafs_procfs);
344 entry->proc_fops = &afs_csdb_operations;
346 entry = create_proc_info_entry(PROC_CELLSERVDB_NAME, (S_IFREG|S_IRUGO), openafs_procfs, csdbproc_info);
348 entry->owner = THIS_MODULE;
354 #if !defined(EXPORTED_PROC_ROOT_FS)
358 remove_proc_entry(PROC_CELLSERVDB_NAME, openafs_procfs);
359 #ifdef HAVE_KERNEL_LINUX_SEQ_FILE_H
360 remove_proc_entry("unixusers", openafs_procfs);
362 #if defined(EXPORTED_PROC_ROOT_FS)
363 remove_proc_entry(PROC_FSDIRNAME, proc_root_fs);
365 sprintf(path, "fs/%s", PROC_FSDIRNAME);
366 remove_proc_entry(path, NULL);