Cleanup usage of LINUX_VERSION_CODE for older kernels
[openafs.git] / src / afs / LINUX / osi_gcpags.c
1 /*
2  * Copyright 2000, International Business Machines Corporation and others.
3  * All Rights Reserved.
4  *
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
8  */
9
10 #include <afsconfig.h>
11 #include "afs/param.h"
12
13
14 #include "afs/sysincludes.h"    /* Standard vendor system headers */
15 #include "afsincludes.h"        /* Afs-based standard headers */
16 #include "afs/afs_stats.h"      /* afs statistics */
17
18 #if AFS_GCPAGS
19
20 /* afs_osi_TraverseProcTable() - Walk through the systems process
21  * table, calling afs_GCPAGs_perproc_func() for each process.
22  */
23
24
25 #ifdef EXPORTED_TASKLIST_LOCK
26 extern rwlock_t tasklist_lock __attribute__((weak));
27 #endif
28 void
29 afs_osi_TraverseProcTable(void)
30 {
31 #if !defined(LINUX_KEYRING_SUPPORT) && (!defined(STRUCT_TASK_STRUCT_HAS_CRED) || defined(HAVE_LINUX_RCU_READ_LOCK))
32     struct task_struct *p;
33
34     rcu_read_lock();
35
36 #if defined(for_each_process)
37     for_each_process(p) if (p->pid) {
38 #ifdef STRUCT_TASK_STRUCT_HAS_EXIT_STATE
39         if (p->exit_state)
40             continue;
41 #else
42         if (p->state & TASK_ZOMBIE)
43             continue;
44 #endif
45         afs_GCPAGs_perproc_func(p);
46     }
47 #else
48     for_each_task(p) if (p->pid) {
49 #ifdef STRUCT_TASK_STRUCT_HAS_EXIT_STATE
50         if (p->exit_state)
51             continue;
52 #else
53         if (p->state & TASK_ZOMBIE)
54             continue;
55 #endif
56         afs_GCPAGs_perproc_func(p);
57     }
58 #endif
59
60     rcu_read_unlock();
61 #endif
62 }
63
64 /* return a pointer (sometimes a static copy ) to the cred for a
65  * given afs_proc_t.
66  * subsequent calls may overwrite the previously returned value.
67  */
68
69 #if !defined(LINUX_KEYRING_SUPPORT) && (!defined(STRUCT_TASK_STRUCT_HAS_CRED) || defined(HAVE_LINUX_RCU_READ_LOCK))
70 const afs_ucred_t *
71 afs_osi_proc2cred(afs_proc_t * pr)
72 {
73     afs_ucred_t *rv = NULL;
74     static afs_ucred_t cr;
75
76     if (pr == NULL) {
77         return NULL;
78     }
79
80     if ((pr->state == TASK_RUNNING) || (pr->state == TASK_INTERRUPTIBLE)
81         || (pr->state == TASK_UNINTERRUPTIBLE)
82         || (pr->state == TASK_STOPPED)) {
83         /* This is dangerous. If anyone ever crfree's the cred that's
84          * returned from here, we'll go boom, because it's statically
85          * allocated. */
86         atomic_set(&cr.cr_ref, 1);
87         afs_set_cr_uid(&cr, task_uid(pr));
88 #if defined(STRUCT_TASK_STRUCT_HAS_CRED)
89         get_group_info(pr->cred->group_info);
90         afs_set_cr_group_info(&cr, pr->cred->group_info);
91 #else
92         get_group_info(pr->group_info);
93         afs_set_cr_group_info(&cr, pr->group_info);
94 #endif
95         rv = &cr;
96     }
97
98     return rv;
99 }
100 #endif
101
102 #endif /* AFS_GCPAGS */