darwin-head-build-fixes-20020821
[openafs.git] / src / afs / afs_exporter.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 RCSID("$Header$");
14
15 #include "../afs/sysincludes.h" /* Standard vendor system headers */
16 #include "../afs/afsincludes.h" /* Afs-based standard headers */
17 #include "../afs/afs_stats.h"   /* statistics gathering code */
18
19 struct afs_exporter     *root_exported=0;   /* Head of "exporters" link list */
20 afs_lock_t              afs_xexp;
21
22
23 /* Add a new "afs exporter" entry to the table of exporters. The default initial values of the entry are passed in as parameters. */
24 static afs_int32 init_xexported = 0;
25
26 struct afs_exporter *exporter_add(afs_int32 size, struct exporterops *ops, afs_int32 state, 
27         afs_int32 type, char *data)
28 {
29     struct afs_exporter *ex, *op;
30     afs_int32 length;
31
32     AFS_STATCNT(exporter_add);
33     if (!init_xexported) {
34         init_xexported = 1;
35         LOCK_INIT(&afs_xexp, "afs_xexp");
36     }
37     length = (size ? size : sizeof(struct afs_exporter));
38     ex = (struct afs_exporter *) afs_osi_Alloc(length);
39     memset((char *)ex, 0, length);
40     MObtainWriteLock(&afs_xexp,308);
41     for (op = root_exported; op; op = op->exp_next) {
42         if (!op->exp_next)
43             break;
44     }
45     if (op) 
46         op->exp_next = ex;
47     else
48         root_exported = ex;
49     MReleaseWriteLock(&afs_xexp);
50     ex->exp_next = 0;
51     ex->exp_op = ops;
52     ex->exp_states = state;
53     ex->exp_data = data;
54     ex->exp_type = type;
55     return ex;
56 }
57
58
59 /* Returns the "afs exporter" structure of type, "type". NULL is returned if not found */
60 struct afs_exporter *exporter_find(int type)
61 {
62     struct afs_exporter *op;
63
64     AFS_STATCNT(exporter_add);
65     MObtainReadLock(&afs_xexp);
66     for (op = root_exported; op; op = op->exp_next) {
67         if (op->exp_type == type) {
68             MReleaseReadLock(&afs_xexp);
69             return op;
70         }
71     }
72     MReleaseReadLock(&afs_xexp);
73     return (struct afs_exporter *)0;
74 }
75
76
77 void shutdown_exporter(void) 
78 {
79     struct afs_exporter *ex, *op;
80
81     for (op = root_exported; op; op = ex) {
82         ex = op->exp_next;
83         afs_osi_Free(op, sizeof(struct afs_exporter));
84     }
85     init_xexported = 0;
86 }