Windows: add build and clean rule for bc.h
[openafs.git] / src / bucoord / status.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/stds.h>
15 #include <sys/types.h>
16 #ifdef AFS_NT40_ENV
17 #include <winsock2.h>
18 #else
19 #include <sys/socket.h>
20 #include <netinet/in.h>
21 #include <netdb.h>
22 #include <sys/time.h>
23 #endif
24 #include <afs/com_err.h>
25 #include <afs/bubasics.h>
26 #include "bc.h"
27 #include "error_macros.h"
28 #include "bucoord_internal.h"
29 #include "bucoord_prototypes.h"
30
31 extern dlqlinkT statusHead;     /* chain of status blocks */
32 extern struct Lock statusQueueLock;     /* access control for status chain */
33 extern struct Lock cmdLineLock; /* lock on the cmdLine */
34
35 /* task status management
36  *
37  * These routines are common the backup coordinator and tape coordinator
38  */
39
40 void
41 initStatus(void)
42 {
43     dlqInit(&statusHead);
44     Lock_Init(&statusQueueLock);
45     Lock_Init(&cmdLineLock);
46 }
47
48 /* lock managment */
49
50 void
51 lock_Status(void)
52 {
53     ObtainWriteLock(&statusQueueLock);
54 }
55
56 void
57 unlock_Status(void)
58 {
59     ReleaseWriteLock(&statusQueueLock);
60 }
61
62 void
63 lock_cmdLine(void)
64 {
65     ObtainWriteLock(&cmdLineLock);
66 }
67 void
68 unlock_cmdLine(void)
69 {
70     ReleaseWriteLock(&cmdLineLock);
71 }
72
73 /* general */
74
75 void
76 clearStatus(afs_uint32 taskId, afs_uint32 flags)
77 {
78     statusP ptr;
79
80     ObtainWriteLock(&statusQueueLock);
81     ptr = findStatus(taskId);
82     if (ptr == 0) {
83         ReleaseWriteLock(&statusQueueLock);
84         return;
85     }
86
87     ptr->flags &= ~flags;
88     ReleaseWriteLock(&statusQueueLock);
89 }
90
91 statusP
92 createStatusNode(void)
93 {
94     statusP ptr;
95
96     ptr = (statusP) malloc(sizeof(*ptr));
97     if (ptr == 0) {
98         return (0);
99     }
100     memset(ptr, 0, sizeof(*ptr));
101
102     /* link it onto the chain of status entries */
103     ObtainWriteLock(&statusQueueLock);
104     dlqLinkb(&statusHead, (dlqlinkP) ptr);
105     ptr->flags = STARTING;
106     ReleaseWriteLock(&statusQueueLock);
107
108     return (ptr);
109 }
110
111 void
112 deleteStatusNode(statusP ptr)
113 {
114     ObtainWriteLock(&statusQueueLock);
115     dlqUnlink((dlqlinkP) ptr);
116
117     if (ptr->cmdLine)
118         free(ptr->cmdLine);
119     free(ptr);
120     ReleaseWriteLock(&statusQueueLock);
121 }
122
123 statusP
124 findStatus(afs_uint32 taskId)
125 {
126     statusP ptr = 0;
127     dlqlinkP dlqPtr;
128
129     dlqPtr = statusHead.dlq_next;
130     while (dlqPtr != &statusHead) {
131         if (((statusP) dlqPtr)->taskId == taskId) {
132             ptr = (statusP) dlqPtr;
133             break;
134         }
135         dlqPtr = dlqPtr->dlq_next;
136     }
137
138     return (ptr);
139 }
140
141 void
142 setStatus(afs_uint32 taskId, afs_uint32 flags)
143 {
144     statusP ptr;
145
146     ObtainWriteLock(&statusQueueLock);
147     ptr = findStatus(taskId);
148     if (ptr == 0) {
149         ReleaseWriteLock(&statusQueueLock);
150         return;
151     }
152
153     ptr->flags |= flags;
154     ReleaseWriteLock(&statusQueueLock);
155 }