Import Upstream version 1.8.5
[hcoop/debian/openafs.git] / src / afs / afs_exporter.c
CommitLineData
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" /* statistics gathering code */
17
18struct afs_exporter *root_exported = 0; /* Head of "exporters" link list */
19afs_lock_t afs_xexp;
20
21
22/* Add a new "afs exporter" entry to the table of exporters. The default initial values of the entry are passed in as parameters. */
23static afs_int32 init_xexported = 0;
24
25struct afs_exporter *
26exporter_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 = afs_osi_Alloc(length);
39 osi_Assert(ex != NULL);
40 memset(ex, 0, length);
41 ObtainWriteLock(&afs_xexp, 308);
42 for (op = root_exported; op; op = op->exp_next) {
43 if (!op->exp_next)
44 break;
45 }
46 if (op)
47 op->exp_next = ex;
48 else
49 root_exported = ex;
50 ReleaseWriteLock(&afs_xexp);
51 ex->exp_next = 0;
52 ex->exp_op = ops;
53 ex->exp_states = state;
54 ex->exp_data = data;
55 ex->exp_type = type;
56 return ex;
57}
58
59
60/* Returns the "afs exporter" structure of type, "type". NULL is returned if not found */
61struct afs_exporter *
62exporter_find(int type)
63{
64 struct afs_exporter *op;
65
66 AFS_STATCNT(exporter_add);
67 ObtainReadLock(&afs_xexp);
68 for (op = root_exported; op; op = op->exp_next) {
69 if (op->exp_type == type) {
70 ReleaseReadLock(&afs_xexp);
71 return op;
72 }
73 }
74 ReleaseReadLock(&afs_xexp);
75 return (struct afs_exporter *)0;
76}
77
78
79void
80shutdown_exporter(void)
81{
82 struct afs_exporter *ex, *op;
83
84 for (op = root_exported; op; op = ex) {
85 ex = op->exp_next;
86 afs_osi_Free(op, sizeof(struct afs_exporter));
87 }
88 init_xexported = 0;
89}