Remove the RCSID macro
[openafs.git] / src / butc / tcstatus.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 <sys/types.h>
15 #ifdef AFS_NT40_ENV
16 #include <winsock2.h>
17 #else
18 #include <netinet/in.h>
19 #include <netdb.h>
20 #include <sys/socket.h>
21 #include <sys/time.h>
22 #include <strings.h>
23 #endif
24 #include <stdio.h>
25 #include <string.h>
26 #include <afs/com_err.h>
27 #include <lock.h>
28 #include <afs/bubasics.h>
29 #include <afs/tcdata.h>
30 #include <afs/butc.h>
31 #include "error_macros.h"
32 #include "butc_xbsa.h"
33
34 /* tape coordinator - task status management */
35 extern statusP findStatus();
36 extern afs_int32 xbsaType;
37
38 dlqlinkT statusHead;
39 struct Lock statusQueueLock;
40 struct Lock cmdLineLock;
41
42 /* STC_GetStatus
43  *      get the status of a task
44  * entry:
45  *      taskId - task for which status required
46  * exit:
47  *      statusPtr - filled in with task status
48  */
49
50 afs_int32
51 STC_GetStatus(call, taskId, statusPtr)
52      struct rx_call *call;
53      afs_uint32 taskId;
54      struct tciStatusS *statusPtr;
55 {
56     statusP ptr;
57     int retval = 0;
58
59     if (callPermitted(call) == 0)
60         return (TC_NOTPERMITTED);
61
62     lock_Status();
63     ptr = findStatus(taskId);
64     if (ptr) {
65         /* strcpy(statusPtr->status, ptr->status); */
66
67         strcpy(statusPtr->taskName, ptr->taskName);
68         strcpy(statusPtr->volumeName, ptr->volumeName);
69         statusPtr->taskId = ptr->taskId;
70         statusPtr->flags = ptr->flags;
71         statusPtr->nKBytes = ptr->nKBytes;
72         statusPtr->dbDumpId = ptr->dbDumpId;
73         statusPtr->lastPolled = ptr->lastPolled;
74         statusPtr->volsFailed = ptr->volsFailed;
75         ptr->lastPolled = time(0);
76     } else
77         retval = TC_NODENOTFOUND;
78     unlock_Status();
79
80     return (retval);
81 }
82
83 afs_int32
84 STC_EndStatus(call, taskId)
85      struct rx_call *call;
86      afs_uint32 taskId;
87 {
88     statusP ptr;
89     int retval = 0;
90
91     if (callPermitted(call) == 0)
92         return (TC_NOTPERMITTED);
93
94     lock_Status();
95     ptr = findStatus(taskId);
96     unlock_Status();
97
98     if (ptr)
99         deleteStatusNode(ptr);
100     else
101         retval = TC_NODENOTFOUND;
102
103     return (retval);
104 }
105
106 afs_int32
107 STC_RequestAbort(call, taskId)
108      struct rx_call *call;
109      afs_uint32 taskId;
110 {
111     statusP ptr;
112     int retval = 0;
113
114     if (callPermitted(call) == 0)
115         return (TC_NOTPERMITTED);
116
117     lock_Status();
118     ptr = findStatus(taskId);
119     if (ptr)
120         ptr->flags |= ABORT_REQUEST;
121     else
122         retval = TC_NODENOTFOUND;
123     unlock_Status();
124     return (retval);
125 }
126
127 /* STC_ScanStatus
128  *      Get status of all tasks on the butc, successively. Initial call
129  *      should come in with TSK_STAT_FIRST flag set to initialize the
130  *      scan.
131  * entry:
132  *      taskId - specifies the task whose status is to be returned
133  *              (unless TSK_STAT_FIRST set in which case it is ignored)
134  * exit:
135  *      taskId - id of next task in the list
136  *      flags - TSK_STAT_END will be set when one reaches the end of
137  *              the task list. taskId is not updated in this case.
138  * return values:
139  *      0 - normal
140  *      TC_NOTASKS - no tasks active
141  */
142
143 afs_int32
144 STC_ScanStatus(call, taskId, statusPtr, flags)
145      struct rx_call *call;
146      afs_uint32 *taskId;
147      struct tciStatusS *statusPtr;
148      afs_uint32 *flags;
149 {
150     statusP ptr = 0;
151     statusP nextPtr = 0;
152     dlqlinkP dlqPtr;
153
154     if (callPermitted(call) == 0)
155         return (TC_NOTPERMITTED);
156
157     lock_Status();
158
159     if (CONF_XBSA)
160         *flags |= TSK_STAT_XBSA;
161     if (xbsaType == XBSA_SERVER_TYPE_ADSM)
162         *flags |= TSK_STAT_ADSM;
163
164     if (*flags & TSK_STAT_FIRST) {
165         /* find first status node */
166         dlqPtr = statusHead.dlq_next;
167         if (dlqPtr == &statusHead) {
168             /* no status nodes */
169             *flags |= (TSK_STAT_NOTFOUND | TSK_STAT_END);
170             unlock_Status();
171             return (0);
172         }
173         ptr = (statusP) dlqPtr;
174     } else {
175         ptr = findStatus(*taskId);
176         if (ptr == 0) {
177             /* in the event that the set of tasks has changed, just
178              * finish, letting the caller retry
179              */
180
181             *flags |= (TSK_STAT_NOTFOUND | TSK_STAT_END);
182             unlock_Status();
183             return (0);
184         }
185     }
186
187     /* ptr is now set to the status node we wish to return. Determine
188      * what the next node will be
189      */
190
191     if (ptr->link.dlq_next == &statusHead)
192         *flags |= TSK_STAT_END;
193     else
194         *taskId = ((statusP) ptr->link.dlq_next)->taskId;
195
196     strcpy(statusPtr->taskName, ptr->taskName);
197     strcpy(statusPtr->volumeName, ptr->volumeName);
198     statusPtr->taskId = ptr->taskId;
199     statusPtr->flags = ptr->flags;
200     statusPtr->nKBytes = ptr->nKBytes;
201     statusPtr->lastPolled = ptr->lastPolled;
202
203     unlock_Status();
204     return (0);
205 }
206
207
208 /* ---------------------------------
209  * misc. status management routines
210  * ---------------------------------
211  */
212
213 /* checkAbortByTaskId
214  * exit:
215  *      0 - continue
216  *      n - abort requested
217  */
218
219 checkAbortByTaskId(taskId)
220      afs_uint32 taskId;
221 {
222     statusP statusPtr;
223     int retval = 0;
224
225     extern statusP findStatus();
226
227     lock_Status();
228     statusPtr = findStatus(taskId);
229     if (statusPtr) {
230         retval = statusPtr->flags & ABORT_REQUEST;
231     }
232     unlock_Status();
233     return (retval);
234 }
235
236 /* getStatusFlag
237  *      For backwards compatibility. Queries flag status
238  * exit:
239  *      0 - flag clear
240  *      n - flag set
241  */
242
243 afs_uint32
244 getStatusFlag(taskId, flag)
245      afs_uint32 taskId;
246      afs_uint32 flag;
247 {
248     statusP statusPtr;
249     int retval = 0;
250     extern statusP findStatus();
251
252     lock_Status();
253     statusPtr = findStatus(taskId);
254     if (statusPtr) {
255         retval = statusPtr->flags & flag;
256     }
257     unlock_Status();
258     return (retval);
259 }