LINUX 5.3.0: Check for 'recurse' arg in keyring_search
[openafs.git] / src / afs / LINUX / osi_proc.c
index 3f340de..a1a5724 100644 (file)
 #include <afsconfig.h>
 #include "afs/param.h"
 
-RCSID
-    ("$Header$");
 
 #include <linux/module.h> /* early to avoid printf->printk mapping */
-#ifdef HAVE_KERNEL_LINUX_SEQ_FILE_H
-#include <linux/seq_file.h>
+#ifdef HAVE_LINUX_SEQ_FILE_H
+# include <linux/seq_file.h>
 #endif
 #include "afs/sysincludes.h"
 #include "afsincludes.h"
 #include "afs/nfsclient.h"
-#include "h/unistd.h"          /* For syscall numbers. */
-#include "h/mm.h"
+#include <linux/unistd.h>              /* For syscall numbers. */
+#include <linux/mm.h>
 
 #ifdef AFS_AMD64_LINUX20_ENV
-#include <asm/ia32_unistd.h>
+# include <asm/ia32_unistd.h>
 #endif
 
-#include <linux/proc_fs.h>
 #include <linux/slab.h>
 #include <linux/init.h>
 #include <linux/sched.h>
 #include <linux/kernel.h>
 
+#include "osi_compat.h"
+
 struct proc_dir_entry *openafs_procfs;
 
-#ifdef HAVE_KERNEL_LINUX_SEQ_FILE_H
-static void *c_start(struct seq_file *m, loff_t *pos)
+#ifdef HAVE_LINUX_SEQ_FILE_H
+static void *
+c_start(struct seq_file *m, loff_t *pos)
 {
-       struct afs_q *cq, *tq;
-       loff_t n = 0;
+    struct afs_q *cq, *tq;
+    loff_t n = 0;
 
-       AFS_GLOCK();
-       ObtainReadLock(&afs_xcell);
-       for (cq = CellLRU.next; cq != &CellLRU; cq = tq) {
-               tq = QNext(cq);
+    AFS_GLOCK();
+    ObtainReadLock(&afs_xcell);
+    for (cq = CellLRU.next; cq != &CellLRU; cq = tq) {
+       tq = QNext(cq);
 
-               if (n++ == *pos)
-                       break;
-       }
-       if (cq == &CellLRU)
-               cq = NULL;
+       if (n++ == *pos)
+           break;
+    }
+    if (cq == &CellLRU)
+       cq = NULL;
 
-       AFS_GUNLOCK();
-       return cq;
+    AFS_GUNLOCK();
+    return cq;
 }
 
-static void *c_next(struct seq_file *m, void *p, loff_t *pos)
+static void *
+c_next(struct seq_file *m, void *p, loff_t *pos)
 {
-       struct afs_q *cq = p, *tq;
+    struct afs_q *cq = p, *tq;
 
-       AFS_GLOCK();
-       (*pos)++;
-       tq = QNext(cq);
+    AFS_GLOCK();
+    (*pos)++;
+    tq = QNext(cq);
 
-       if (tq == &CellLRU)
-               return NULL;
+    if (tq == &CellLRU)
+       tq = NULL;
 
-       AFS_GUNLOCK();
-       return tq;
+    AFS_GUNLOCK();
+    return tq;
 }
 
-static void c_stop(struct seq_file *m, void *p)
+static void
+c_stop(struct seq_file *m, void *p)
 {
-        AFS_GLOCK();
-       ReleaseReadLock(&afs_xcell);
-       AFS_GUNLOCK();
+    AFS_GLOCK();
+    ReleaseReadLock(&afs_xcell);
+    AFS_GUNLOCK();
 }
 
-static int c_show(struct seq_file *m, void *p)
+static int
+c_show(struct seq_file *m, void *p)
 {
-       struct afs_q *cq = p;
-       struct cell *tc = QTOC(cq);
-       int j;
+    struct afs_q *cq = p;
+    struct cell *tc = QTOC(cq);
+    int j;
 
-       seq_printf(m, ">%s #(%d/%d)\n", tc->cellName,
-                  tc->cellNum, tc->cellIndex);
+    seq_printf(m, ">%s #(%d/%d)\n", tc->cellName,
+               tc->cellNum, tc->cellIndex);
 
-       for (j = 0; j < MAXCELLHOSTS; j++) {
-               afs_uint32 addr;
+    for (j = 0; j < AFS_MAXCELLHOSTS; j++) {
+       afs_uint32 addr;
 
-               if (!tc->cellHosts[j]) break;
+       if (!tc->cellHosts[j]) break;
 
-               addr = tc->cellHosts[j]->addr->sa_ip;
-               seq_printf(m, "%u.%u.%u.%u #%u.%u.%u.%u\n",
-                          NIPQUAD(addr), NIPQUAD(addr));
-       }
+       addr = tc->cellHosts[j]->addr->sa_ip;
+#if defined(NIPQUAD)
+       seq_printf(m, "%u.%u.%u.%u #%u.%u.%u.%u\n",
+                  NIPQUAD(addr), NIPQUAD(addr));
+#else
+       seq_printf(m, "%pI4 #%pI4\n", &addr, &addr);
+#endif
+    }
 
        return 0;
 }
 
 static struct seq_operations afs_csdb_op = {
-       .start          = c_start,
-       .next           = c_next,
-       .stop           = c_stop,
-       .show           = c_show,
+    .start = c_start,
+    .next  = c_next,
+    .stop  = c_stop,
+    .show  = c_show,
 };
 
-static int afs_csdb_open(struct inode *inode, struct file *file)
+static int
+afs_csdb_open(struct inode *inode, struct file *file)
 {
-       return seq_open(file, &afs_csdb_op);
+    return seq_open(file, &afs_csdb_op);
 }
 
 static struct file_operations afs_csdb_operations = {
-       .open           = afs_csdb_open,
-       .read           = seq_read,
-       .llseek         = seq_lseek,
-       .release        = seq_release,
+    .open    = afs_csdb_open,
+    .read    = seq_read,
+    .llseek  = seq_lseek,
+    .release = seq_release,
 };
 
-
-static void *uu_start(struct seq_file *m, loff_t *pos)
+static void *
+uu_start(struct seq_file *m, loff_t *pos)
 {
     struct unixuser *tu;
+    void *ret;
     loff_t n = 0;
     afs_int32 i;
 
+    AFS_GLOCK();
     ObtainReadLock(&afs_xuser);
-    if (!*pos)
-       return (void *)(1);
+
+    if (!*pos) {
+       ret = (void *)(1);
+       goto done;
+    }
+
+    ret = NULL;
 
     for (i = 0; i < NUSERS; i++) {
        for (tu = afs_users[i]; tu; tu = tu->next) {
-           if (++n == *pos)
-               return tu;
+           if (++n == *pos) {
+               ret = tu;
+               goto done;
+           }
        }
     }
 
-    return NULL;
+ done:
+    AFS_GUNLOCK();
+    return ret;
 }
 
-static void *uu_next(struct seq_file *m, void *p, loff_t *pos)
+static void *
+uu_next(struct seq_file *m, void *p, loff_t *pos)
 {
     struct unixuser *tu = p;
     afs_int32 i = 0;
@@ -162,15 +182,20 @@ static void *uu_next(struct seq_file *m, void *p, loff_t *pos)
     return NULL;
 }
 
-static void uu_stop(struct seq_file *m, void *p)
+static void
+uu_stop(struct seq_file *m, void *p)
 {
+    AFS_GLOCK();
     ReleaseReadLock(&afs_xuser);
+    AFS_GUNLOCK();
 }
 
-static int uu_show(struct seq_file *m, void *p)
+static int
+uu_show(struct seq_file *m, void *p)
 {
     struct cell *tc = 0;
     struct unixuser *tu = p;
+    union tokenUnion *token;
     char *cellname;
 
     if (p == (void *)1) {
@@ -184,6 +209,13 @@ static int uu_show(struct seq_file *m, void *p)
        return 0;
     }
 
+    AFS_GLOCK();
+
+    tu->refCount++;
+    ReleaseReadLock(&afs_xuser);
+
+    afs_LockUser(tu, READ_LOCK, 0);
+
     if (tu->cell == -1) {
        cellname = "<default>";
     } else {
@@ -193,14 +225,17 @@ static int uu_show(struct seq_file *m, void *p)
     }
 
     seq_printf(m, "%10d %4d %04x    %-25s %10d",
-              tu->uid, tu->refCount, tu->states, cellname, tu->vid);
+              tu->uid, tu->refCount, tu->states, cellname, tu->viceId);
 
     if (tc) afs_PutCell(tc, READ_LOCK);
 
     if (tu->states & UHasTokens) {
+       token = afs_FindToken(tu->tokens, RX_SECIDX_KAD);
        seq_printf(m, "  %10d %10d %10d %3d",
-                  tu->tokenTime, tu->ct.BeginTimestamp, tu->ct.EndTimestamp,
-                  tu->ct.AuthHandle);
+                  tu->tokenTime,
+                  (token!=NULL)?token->rxkad.clearToken.BeginTimestamp:0,
+                  (token!=NULL)?token->rxkad.clearToken.EndTimestamp:0,
+                  (token!=NULL)?token->rxkad.clearToken.AuthHandle:0);
     } else {
        seq_printf(m, "  %-36s", "Tokens Not Set");
     }
@@ -210,7 +245,11 @@ static int uu_show(struct seq_file *m, void *p)
         char ipaddr[16];
        int i;
 
+#if defined(NIPQUAD)
         sprintf(ipaddr, "%u.%u.%u.%u", NIPQUAD(np->host));
+#else
+        sprintf(ipaddr, "%pI4", &np->host);
+#endif
        seq_printf(m, "  %-15s %10d %10d", ipaddr, np->uid, np->client_uid);
        if (np->sysnamecount) {
            for (i = 0; i < np->sysnamecount; i++)
@@ -224,34 +263,39 @@ static int uu_show(struct seq_file *m, void *p)
     }
     seq_printf(m, "\n");
 
+    afs_PutUser(tu, READ_LOCK);
+    ObtainReadLock(&afs_xuser);
+
+    AFS_GUNLOCK();
+
     return 0;
 }
 
 static struct seq_operations afs_unixuser_seqop = {
-    .start             = uu_start,
-    .next              = uu_next,
-    .stop              = uu_stop,
-    .show              = uu_show,
+    .start = uu_start,
+    .next  = uu_next,
+    .stop  = uu_stop,
+    .show  = uu_show,
 };
 
-static int afs_unixuser_open(struct inode *inode, struct file *file)
+static int
+afs_unixuser_open(struct inode *inode, struct file *file)
 {
     return seq_open(file, &afs_unixuser_seqop);
 }
 
 static struct file_operations afs_unixuser_fops = {
-    .open              = afs_unixuser_open,
-    .read              = seq_read,
-    .llseek            = seq_lseek,
-    .release   = seq_release,
+    .open    = afs_unixuser_open,
+    .read    = seq_read,
+    .llseek  = seq_lseek,
+    .release = seq_release,
 };
 
 
-#else /* HAVE_KERNEL_LINUX_SEQ_FILE_H */
+#else /* HAVE_LINUX_SEQ_FILE_H */
 
 static int
-csdbproc_info(char *buffer, char **start, off_t offset, int
-length)
+csdbproc_info(char *buffer, char **start, off_t offset, int length)
 {
     int len = 0;
     off_t pos = 0;
@@ -263,6 +307,8 @@ length)
        decor */
     char temp[91];
     afs_uint32 addr;
+
+    AFS_GLOCK();
     
     ObtainReadLock(&afs_xcell);
 
@@ -284,7 +330,7 @@ length)
             }
         }
 
-        for (cnt = 0; cnt < MAXCELLHOSTS; cnt++) {
+        for (cnt = 0; cnt < AFS_MAXCELLHOSTS; cnt++) {
             if (!tc->cellHosts[cnt]) break;
             pos += 90;
             if (pos <= offset) {
@@ -309,6 +355,8 @@ length)
     ReleaseReadLock(&afs_xcell);
     
 done:
+    AFS_GUNLOCK();
+
     *start = buffer + len - (pos - offset);
     len = pos - offset;
     if (len > length)
@@ -316,7 +364,7 @@ done:
     return len;
 }
 
-#endif /* HAVE_KERNEL_LINUX_SEQ_FILE_H */
+#endif /* HAVE_LINUX_SEQ_FILE_H */
 
 void
 osi_proc_init(void)
@@ -332,19 +380,20 @@ osi_proc_init(void)
     sprintf(path, "fs/%s", PROC_FSDIRNAME);
     openafs_procfs = proc_mkdir(path, NULL);
 #endif
-#ifdef HAVE_KERNEL_LINUX_SEQ_FILE_H
-    entry = create_proc_entry("unixusers", 0, openafs_procfs);
-    if (entry) {
-       entry->proc_fops = &afs_unixuser_fops;
-       entry->owner = THIS_MODULE;
-    }
-    entry = create_proc_entry(PROC_CELLSERVDB_NAME, 0, openafs_procfs);
+#ifdef HAVE_LINUX_SEQ_FILE_H
+    entry = afs_proc_create("unixusers", 0, openafs_procfs, &afs_unixuser_fops);
+# if defined(STRUCT_PROC_DIR_ENTRY_HAS_OWNER)
     if (entry)
-       entry->proc_fops = &afs_csdb_operations;
+       entry->owner = THIS_MODULE;
+# endif
+    entry = afs_proc_create(PROC_CELLSERVDB_NAME, 0, openafs_procfs, &afs_csdb_operations);
 #else
     entry = create_proc_info_entry(PROC_CELLSERVDB_NAME, (S_IFREG|S_IRUGO), openafs_procfs, csdbproc_info);
 #endif
-    entry->owner = THIS_MODULE;
+#if defined(STRUCT_PROC_DIR_ENTRY_HAS_OWNER)
+    if (entry)
+       entry->owner = THIS_MODULE;
+#endif
 }
 
 void
@@ -355,7 +404,7 @@ osi_proc_clean(void)
 #endif
 
     remove_proc_entry(PROC_CELLSERVDB_NAME, openafs_procfs);
-#ifdef HAVE_KERNEL_LINUX_SEQ_FILE_H
+#ifdef HAVE_LINUX_SEQ_FILE_H
     remove_proc_entry("unixusers", openafs_procfs);
 #endif
 #if defined(EXPORTED_PROC_ROOT_FS)