Commit | Line | Data |
---|---|---|
805e021f CE |
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 | /* | |
26 | * NOTE: h/proc_private.h gives the process table locking rules | |
27 | * It indicates that access to p_cred must be protected by | |
28 | * mp_mtproc_lock(p); | |
29 | * mp_mtproc_unlock(p); | |
30 | * | |
31 | * The code in sys/pm_prot.c uses pcred_lock() to protect access to | |
32 | * the process creds, and uses mp_mtproc_lock() only for audit-related | |
33 | * changes. To be safe, we use both. | |
34 | */ | |
35 | ||
36 | void | |
37 | afs_osi_TraverseProcTable(void) | |
38 | { | |
39 | proc_t *p; | |
40 | int endchain = 0; | |
41 | ||
42 | MP_SPINLOCK(activeproc_lock); | |
43 | MP_SPINLOCK(sched_lock); | |
44 | pcred_lock(); | |
45 | ||
46 | /* | |
47 | * Instead of iterating through all of proc[], traverse only | |
48 | * the list of active processes. As an example of this, | |
49 | * see foreach_process() in sys/vm_sched.c. | |
50 | * | |
51 | * We hold the locks for the entire scan in order to get a | |
52 | * consistent view of the current set of creds. | |
53 | */ | |
54 | ||
55 | for (p = proc; endchain == 0; p = &proc[p->p_fandx]) { | |
56 | if (p->p_fandx == 0) { | |
57 | endchain = 1; | |
58 | } | |
59 | ||
60 | if (system_proc(p)) | |
61 | continue; | |
62 | ||
63 | mp_mtproc_lock(p); | |
64 | afs_GCPAGs_perproc_func(p); | |
65 | mp_mtproc_unlock(p); | |
66 | } | |
67 | ||
68 | pcred_unlock(); | |
69 | MP_SPINUNLOCK(sched_lock); | |
70 | MP_SPINUNLOCK(activeproc_lock); | |
71 | } | |
72 | ||
73 | /* return a pointer (sometimes a static copy ) to the cred for a | |
74 | * given afs_proc_t. | |
75 | * subsequent calls may overwrite the previously returned value. | |
76 | */ | |
77 | const afs_ucred_t * | |
78 | afs_osi_proc2cred(afs_proc_t * p) | |
79 | { | |
80 | if (!p) | |
81 | return; | |
82 | ||
83 | /* | |
84 | * Cannot use afs_warnuser() here, as the code path | |
85 | * eventually wants to grab sched_lock, which is | |
86 | * already held here | |
87 | */ | |
88 | ||
89 | return p_cred(p); | |
90 | } | |
91 | ||
92 | #endif /* AFS_GCPAGS */ |