2 * Copyright 2000, International Business Machines Corporation and others.
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
10 #include <afsconfig.h>
11 #include <afs/param.h>
18 #include "afs_bosAdmin.h"
19 #include "../adminutil/afs_AdminInternal.h"
20 #include <afs/afs_AdminErrors.h>
21 #include <afs/afs_utilAdmin.h>
22 #include <afs/bosint.h>
23 #include <afs/bnode.h>
24 #include <afs/ktime.h>
25 #include <afs/dirpath.h>
27 #include <sys/types.h>
44 typedef struct bos_server {
47 struct rx_connection *server;
48 struct rx_connection *server_encrypt;
49 struct rx_connection *server_stats;
51 } bos_server_t, *bos_server_p;
54 * isValidServerHandle - validate a bos_server_p.
58 * IN serverHandle - the handle to validate
62 * No locks are obtained or released by this function
66 * Returns != 0 upon successful completion.
70 isValidServerHandle(const bos_server_p serverHandle, afs_status_p st)
75 if (serverHandle == NULL) {
76 tst = ADMBOSSERVERHANDLENULL;
77 goto fail_IsValidServerHandle;
80 if ((serverHandle->begin_magic != BEGIN_MAGIC)
81 || (serverHandle->end_magic != END_MAGIC)) {
82 tst = ADMBOSSERVERHANDLEBADMAGIC;
83 goto fail_IsValidServerHandle;
86 if (serverHandle->is_valid == 0) {
87 tst = ADMBOSSERVERHANDLEINVALID;
88 goto fail_IsValidServerHandle;
91 if (serverHandle->server == NULL) {
92 tst = ADMBOSSERVERHANDLENOSERVER;
93 goto fail_IsValidServerHandle;
96 if (serverHandle->server_encrypt == NULL) {
97 tst = ADMBOSSERVERHANDLENOSERVER;
98 goto fail_IsValidServerHandle;
102 fail_IsValidServerHandle:
111 * IsValidCellHandle - verify that a cell handle can be used to make bos
116 * IN cellHandle - the cellHandle to be validated.
120 * No locks are obtained or released by this function
124 * Returns != 0 upon successful completion.
128 IsValidCellHandle(afs_cell_handle_p cellHandle, afs_status_p st)
131 afs_status_t tst = 0;
133 if (!CellHandleIsValid((void *)cellHandle, &tst)) {
134 goto fail_IsValidCellHandle;
137 if (cellHandle->tokens == NULL) {
138 tst = ADMBOSCELLHANDLENOTOKENS;
139 goto fail_IsValidCellHandle;
143 fail_IsValidCellHandle:
152 * bos_ServerOpen - open a bos server for work.
156 * IN cellHandle - a previously opened cellHandle.
158 * IN serverName - the name of the machine that houses the bosserver of
161 * OUT serverHandleP - upon successful completion, this void pointer
162 * will point to a valid server handle for use in future operations.
166 * No locks are obtained or released by this function
170 * Returns != 0 upon successful completion.
174 bos_ServerOpen(const void *cellHandle, const char *serverName,
175 void **serverHandleP, afs_status_p st)
178 afs_status_t tst = 0;
179 afs_cell_handle_p c_handle = (afs_cell_handle_p) cellHandle;
180 bos_server_p bos_server = (bos_server_p) malloc(sizeof(bos_server_t));
184 * Validate parameters
187 if (!IsValidCellHandle(c_handle, &tst)) {
188 goto fail_bos_ServerOpen;
191 if ((serverName == NULL) || (*serverName == 0)) {
192 tst = ADMBOSSERVERNAMENULL;
193 goto fail_bos_ServerOpen;
196 if (serverHandleP == NULL) {
197 tst = ADMBOSSERVERHANDLEPNULL;
198 goto fail_bos_ServerOpen;
201 if (util_AdminServerAddressGetFromName(serverName, &serverAddress, &tst)
203 goto fail_bos_ServerOpen;
206 if (bos_server == NULL) {
208 goto fail_bos_ServerOpen;
212 rx_GetCachedConnection(htonl(serverAddress), htons(AFSCONF_NANNYPORT),
214 c_handle->tokens->afs_sc[c_handle->tokens->
216 c_handle->tokens->sc_index);
218 bos_server->server_encrypt =
219 rx_GetCachedConnection(htonl(serverAddress), htons(AFSCONF_NANNYPORT),
221 c_handle->tokens->afs_encrypt_sc[c_handle->
224 c_handle->tokens->sc_index);
226 bos_server->server_stats =
227 rx_GetCachedConnection(htonl(serverAddress), htons(AFSCONF_NANNYPORT),
229 c_handle->tokens->afs_sc[c_handle->tokens->
231 c_handle->tokens->sc_index);
233 if ((bos_server->server == NULL) || (bos_server->server_encrypt == NULL)) {
234 tst = ADMBOSSERVERNOCONNECTION;
235 goto fail_bos_ServerOpen;
238 bos_server->begin_magic = BEGIN_MAGIC;
239 bos_server->is_valid = 1;
240 bos_server->end_magic = END_MAGIC;
242 *serverHandleP = (void *)bos_server;
247 if ((rc == 0) && (bos_server != NULL)) {
248 if (bos_server->server) {
249 rx_ReleaseCachedConnection(bos_server->server);
251 if (bos_server->server_encrypt) {
252 rx_ReleaseCachedConnection(bos_server->server_encrypt);
264 * bos_ServerClose - close a bos server handle
268 * IN serverHandle - a bos server handle previously returned by bos_ServerOpen
272 * No locks are obtained or released by this function
276 * Returns != 0 upon successful completion.
280 bos_ServerClose(const void *serverHandle, afs_status_p st)
283 afs_status_t tst = 0;
284 bos_server_p b_handle = (bos_server_p) serverHandle;
286 if (isValidServerHandle(b_handle, &tst)) {
287 rx_ReleaseCachedConnection(b_handle->server);
288 b_handle->is_valid = 0;
300 * bos_ProcessCreate - create a new process to run at a bos server.
304 * IN serverHandle - a previously opened serverHandle.
306 * IN processName - the name of the process to create.
308 * IN processType - the type of process to create.
310 * IN process - the path to the process binary at the bos server.
312 * IN cronTime - the time specification for cron processes.
314 * IN notifier - the path to the notifier binary at the bos server.
318 * No locks are obtained or released by this function
322 * Returns != 0 upon successful completion.
326 * CAUTION - this list must match bos_ProcessType_t definition
329 static char *processTypes[] = { "simple", "fs", "cron", 0 };
332 bos_ProcessCreate(const void *serverHandle, const char *processName,
333 bos_ProcessType_t processType, const char *process,
334 const char *cronTime, const char *notifier, afs_status_p st)
337 afs_status_t tst = 0;
338 bos_server_p b_handle = (bos_server_p) serverHandle;
340 if (!isValidServerHandle(b_handle, &tst)) {
341 goto fail_bos_ProcessCreate;
344 if (processType == BOS_PROCESS_FS) {
345 tst = ADMBOSPROCESSCREATEBADTYPE;
346 goto fail_bos_ProcessCreate;
349 if ((processName == NULL) || (*processName == 0)) {
350 tst = ADMBOSPROCESSNAMENULL;
351 goto fail_bos_ProcessCreate;
354 if ((process == NULL) || (*process == 0)) {
355 tst = ADMBOSPROCESSNULL;
356 goto fail_bos_ProcessCreate;
359 if ((processType == BOS_PROCESS_CRON) && (cronTime == NULL)) {
360 tst = ADMBOSCRONTIMENULL;
361 goto fail_bos_ProcessCreate;
364 if ((processType == BOS_PROCESS_SIMPLE) && (cronTime != NULL)) {
365 tst = ADMBOSCRONTIMENOTNULL;
366 goto fail_bos_ProcessCreate;
370 BOZO_CreateBnode(b_handle->server, processTypes[processType],
371 processName, process, (cronTime) ? cronTime : "", "",
372 "", "", (notifier) ? notifier : NONOTIFIER);
377 fail_bos_ProcessCreate:
386 * bos_FSProcessCreate - create the fs group of processes at the boserver.
390 * IN serverHandle - a previously opened serverHandle.
392 * IN processName - the name of the process to create.
394 * IN fileserverPath - the path to the fileserver binary at the bos server.
396 * IN volserverPath - the path to the volserver binary at the bos server.
398 * IN salvagerPath - the path to the salvager binary at the bos server.
400 * IN notifier - the path to the notifier binary at the bos server.
404 * No locks are obtained or released by this function
408 * Returns != 0 upon successful completion.
412 bos_FSProcessCreate(const void *serverHandle, const char *processName,
413 const char *fileserverPath, const char *volserverPath,
414 const char *salvagerPath, const char *notifier,
418 afs_status_t tst = 0;
419 bos_server_p b_handle = (bos_server_p) serverHandle;
421 if (!isValidServerHandle(b_handle, &tst)) {
422 goto fail_bos_ProcessCreate;
425 if ((processName == NULL) || (*processName == 0)) {
426 tst = ADMBOSPROCESSNAMENULL;
427 goto fail_bos_ProcessCreate;
430 if ((fileserverPath == NULL) || (*fileserverPath == 0)) {
431 tst = ADMBOSFILESERVERPATHNULL;
432 goto fail_bos_ProcessCreate;
435 if ((volserverPath == NULL) || (*volserverPath == 0)) {
436 tst = ADMBOSVOLSERVERPATHNULL;
437 goto fail_bos_ProcessCreate;
440 if ((salvagerPath == NULL) || (*salvagerPath == 0)) {
441 tst = ADMBOSSALVAGERPATHNULL;
442 goto fail_bos_ProcessCreate;
446 BOZO_CreateBnode(b_handle->server, processTypes[BOS_PROCESS_FS],
447 processName, fileserverPath, volserverPath,
448 salvagerPath, "", "",
449 (notifier) ? notifier : NONOTIFIER);
454 fail_bos_ProcessCreate:
463 * bos_ProcessDelete - delete an existing process at a bos server.
467 * IN serverHandle - a previously opened serverHandle.
469 * IN processName - the name of the process to delete.
473 * No locks are obtained or released by this function
477 * Returns != 0 upon successful completion.
481 bos_ProcessDelete(const void *serverHandle, const char *processName,
485 afs_status_t tst = 0;
486 bos_server_p b_handle = (bos_server_p) serverHandle;
488 if (!isValidServerHandle(b_handle, &tst)) {
489 goto fail_bos_ProcessDelete;
492 if ((processName == NULL) || (*processName == 0)) {
493 tst = ADMBOSPROCESSNAMENULL;
494 goto fail_bos_ProcessDelete;
497 tst = BOZO_DeleteBnode(b_handle->server, processName);
503 fail_bos_ProcessDelete:
512 * bos_ProcessExecutionStateGet - get the current execution state of a
517 * IN serverHandle - a previously opened serverHandle.
519 * IN processName - the name of the process to retrieve.
521 * OUT processStatusP - upon successful completion the process execution state
523 * OUT auxiliaryProcessStatus - set to point to aux proc status if available.
524 * Pass a pointer to an char array at least BOS_MAX_NAME_LEN long.
528 * No locks are obtained or released by this function
532 * Returns != 0 upon successful completion.
536 bos_ProcessExecutionStateGet(const void *serverHandle,
537 const char *processName,
538 bos_ProcessExecutionState_p processStatusP,
539 char *auxiliaryProcessStatus, afs_status_p st)
542 afs_status_t tst = 0;
543 bos_server_p b_handle = (bos_server_p) serverHandle;
546 if (!isValidServerHandle(b_handle, &tst)) {
547 goto fail_bos_ProcessExecutionStateGet;
550 if ((processName == NULL) || (*processName == 0)) {
551 tst = ADMBOSPROCESSNAMENULL;
552 goto fail_bos_ProcessExecutionStateGet;
555 if (processStatusP == NULL) {
556 tst = ADMBOSPROCESSSTATUSPNULL;
557 goto fail_bos_ProcessExecutionStateGet;
560 if (auxiliaryProcessStatus == NULL) {
561 tst = ADMBOSAUXILIARYPROCESSSTATUSNULL;
562 goto fail_bos_ProcessExecutionStateGet;
566 BOZO_GetStatus(b_handle->server, processName, &state,
567 &auxiliaryProcessStatus);
570 goto fail_bos_ProcessExecutionStateGet;
573 *processStatusP = (bos_ProcessExecutionState_t) state;
576 fail_bos_ProcessExecutionStateGet:
585 * SetExecutionState - set the execution state of a process
589 * IN serverHandle - a previously opened serverHandle.
591 * IN processName - the name of the process to modify.
593 * IN processStatus - the new process state.
595 * IN func - the function to call to set the status.
599 * No locks are obtained or released by this function
603 * Returns != 0 upon successful completion.
607 SetExecutionState(const void *serverHandle, const char *processName,
608 const bos_ProcessExecutionState_t processStatus,
609 int (*func) (struct rx_connection *, const char *,
610 afs_int32), afs_status_p st)
613 afs_status_t tst = 0;
614 bos_server_p b_handle = (bos_server_p) serverHandle;
617 if (!isValidServerHandle(b_handle, &tst)) {
618 goto fail_SetExecutionState;
621 if ((processName == NULL) || (*processName == 0)) {
622 tst = ADMBOSPROCESSNAMENULL;
623 goto fail_SetExecutionState;
626 if ((processStatus != BOS_PROCESS_STOPPED)
627 && (processStatus != BOS_PROCESS_RUNNING)) {
628 tst = ADMBOSPROCESSSTATUSSET;
629 goto fail_SetExecutionState;
632 state = (afs_int32) processStatus;
634 tst = func(b_handle->server, processName, state);
640 fail_SetExecutionState:
649 * bos_ProcessExecutionStateSet - set the execution state of a process
653 * IN serverHandle - a previously opened serverHandle.
655 * IN processName - the name of the process to modify.
657 * IN processStatus - the new process state.
661 * No locks are obtained or released by this function
665 * Returns != 0 upon successful completion.
669 bos_ProcessExecutionStateSet(const void *serverHandle,
670 const char *processName,
671 bos_ProcessExecutionState_t processStatus,
674 return SetExecutionState(serverHandle, processName, processStatus,
679 * bos_ProcessExecutionStateSetTemporary - set the execution state of a process
684 * IN serverHandle - a previously opened serverHandle.
686 * IN processName - the name of the process to modify.
688 * IN processStatus - the new process state.
692 * No locks are obtained or released by this function
696 * Returns != 0 upon successful completion.
700 bos_ProcessExecutionStateSetTemporary(const void *serverHandle,
701 const char *processName,
702 bos_ProcessExecutionState_t
703 processStatus, afs_status_p st)
705 return SetExecutionState(serverHandle, processName, processStatus,
706 BOZO_SetTStatus, st);
710 * The iterator functions and data for the process name retrieval functions
713 typedef struct process_name_get {
715 struct rx_connection *server;
716 char process[CACHED_ITEMS][BOS_MAX_NAME_LEN];
717 } process_name_get_t, *process_name_get_p;
720 GetProcessNameRPC(void *rpc_specific, int slot, int *last_item,
721 int *last_item_contains_data, afs_status_p st)
724 afs_status_t tst = 0;
725 process_name_get_p proc = (process_name_get_p) rpc_specific;
726 char *ptr = (char *)&proc->process[slot];
728 tst = BOZO_EnumerateInstance(proc->server, proc->next++, &ptr);
732 } else if (tst == BZDOM) {
736 *last_item_contains_data = 0;
746 GetProcessNameFromCache(void *rpc_specific, int slot, void *dest,
750 afs_status_t tst = 0;
751 process_name_get_p proc = (process_name_get_p) rpc_specific;
753 strcpy((char *)dest, (char *)&proc->process[slot]);
763 * bos_ProcessNameGetBegin - begin iterating over the list of processes
764 * at a particular bos server.
768 * IN serverHandle - a previously opened serverHandle.
770 * OUT iter - an iterator that can be passed to bos_ProcessNameGetNext
771 * to retrieve the process names.
775 * No locks are obtained or released by this function
779 * Returns != 0 upon successful completion.
784 bos_ProcessNameGetBegin(const void *serverHandle, void **iterationIdP,
788 afs_status_t tst = 0;
789 bos_server_p b_handle = (bos_server_p) serverHandle;
790 afs_admin_iterator_p iter =
791 (afs_admin_iterator_p) malloc(sizeof(afs_admin_iterator_t));
792 process_name_get_p proc =
793 (process_name_get_p) malloc(sizeof(process_name_get_t));
795 if (!isValidServerHandle(b_handle, &tst)) {
796 goto fail_bos_ProcessNameGetBegin;
799 if (iterationIdP == NULL) {
800 tst = ADMITERATIONIDPNULL;
801 goto fail_bos_ProcessNameGetBegin;
804 if ((iter == NULL) || (proc == NULL)) {
806 goto fail_bos_ProcessNameGetBegin;
810 proc->server = b_handle->server;
813 (iter, (void *)proc, GetProcessNameRPC, GetProcessNameFromCache, NULL,
815 *iterationIdP = (void *)iter;
817 goto fail_bos_ProcessNameGetBegin;
821 fail_bos_ProcessNameGetBegin:
839 * bos_ProcessNameGetNext - retrieve the next process name from the bos server.
843 * IN iterationId - an iterator previously returned by bos_ProcessNameGetBegin
845 * OUT processName - upon successful completion contains the next process name
846 * retrieved from the server.
850 * No locks are obtained or released by this function
854 * Returns != 0 upon successful completion.
859 bos_ProcessNameGetNext(const void *iterationId, char *processName,
863 afs_status_t tst = 0;
864 afs_admin_iterator_p iter = (afs_admin_iterator_p) iterationId;
866 if (processName == NULL) {
867 tst = ADMBOSPROCESSNAMENULL;
868 goto fail_bos_ProcessNameGetNext;
871 if (iterationId == NULL) {
872 tst = ADMITERATIONIDPNULL;
873 goto fail_bos_ProcessNameGetNext;
876 rc = IteratorNext(iter, (void *)processName, &tst);
878 fail_bos_ProcessNameGetNext:
887 * bos_ProcessNameGetDone - finish using a process name iterator.
891 * IN iterationId - an iterator previously returned by bos_ProcessNameGetBegin
895 * No locks are obtained or released by this function
899 * Returns != 0 upon successful completion.
904 bos_ProcessNameGetDone(const void *iterationId, afs_status_p st)
907 afs_status_t tst = 0;
908 afs_admin_iterator_p iter = (afs_admin_iterator_p) iterationId;
910 if (iterationId == NULL) {
911 tst = ADMITERATIONIDPNULL;
912 goto fail_bos_ProcessNameGetDone;
915 rc = IteratorDone(iter, &tst);
917 fail_bos_ProcessNameGetDone:
926 * bos_ProcessInfoGet - get information about a single process
930 * IN serverHandle - a previously opened serverHandle.
932 * IN processName - the process of interest.
934 * OUT processTypeP - upon successful completion contains the process type
936 * OUT processInfoP - upon successful completion contains the process info
940 * No locks are obtained or released by this function
944 * Returns != 0 upon successful completion.
949 bos_ProcessInfoGet(const void *serverHandle, const char *processName,
950 bos_ProcessType_p processTypeP,
951 bos_ProcessInfo_p processInfoP, afs_status_p st)
954 afs_status_t tst = 0;
955 bos_server_p b_handle = (bos_server_p) serverHandle;
956 char type[BOS_MAX_NAME_LEN];
958 struct bozo_status status;
961 if (!isValidServerHandle(b_handle, &tst)) {
962 goto fail_bos_ProcessInfoGet;
965 if ((processName == NULL) || (*processName == 0)) {
966 tst = ADMBOSPROCESSNAMENULL;
967 goto fail_bos_ProcessInfoGet;
970 if (processTypeP == NULL) {
971 tst = ADMBOSPROCESSTYPEPNULL;
972 goto fail_bos_ProcessInfoGet;
975 if (processInfoP == NULL) {
976 tst = ADMBOSPROCESSINFOPNULL;
977 goto fail_bos_ProcessInfoGet;
980 tst = BOZO_GetInstanceInfo(b_handle->server, processName, &ptr, &status);
983 goto fail_bos_ProcessInfoGet;
987 for (i = 0; (processTypes[i] != NULL); i++) {
988 if (!strcmp(processTypes[i], type)) {
989 *processTypeP = (bos_ProcessType_t) i;
994 if (processTypes[i] == NULL) {
995 tst = ADMBOSINVALIDPROCESSTYPE;
996 goto fail_bos_ProcessInfoGet;
999 processInfoP->processGoal = (bos_ProcessExecutionState_t) status.goal;
1000 processInfoP->processStartTime = status.procStartTime;
1001 processInfoP->numberProcessStarts = status.procStarts;
1002 processInfoP->processExitTime = status.lastAnyExit;
1003 processInfoP->processExitErrorTime = status.lastErrorExit;
1004 processInfoP->processErrorCode = status.errorCode;
1005 processInfoP->processErrorSignal = status.errorSignal;
1006 processInfoP->state = BOS_PROCESS_OK;
1008 if (status.flags & BOZO_ERRORSTOP) {
1009 processInfoP->state |= BOS_PROCESS_TOO_MANY_ERRORS;
1011 if (status.flags & BOZO_HASCORE) {
1012 processInfoP->state |= BOS_PROCESS_CORE_DUMPED;
1014 if (status.flags & BOZO_BADDIRACCESS) {
1015 processInfoP->state |= BOS_PROCESS_BAD_FILE_ACCESS;
1019 fail_bos_ProcessInfoGet:
1028 * The iterator functions and data for the parameter retrieval functions
1031 typedef struct param_get {
1033 struct rx_connection *server;
1034 char processName[BOS_MAX_NAME_LEN];
1035 char param[CACHED_ITEMS][BOS_MAX_NAME_LEN];
1036 } param_get_t, *param_get_p;
1039 GetParameterRPC(void *rpc_specific, int slot, int *last_item,
1040 int *last_item_contains_data, afs_status_p st)
1043 afs_status_t tst = 0;
1044 param_get_p param = (param_get_p) rpc_specific;
1045 char *ptr = (char *)¶m->param[slot];
1048 BOZO_GetInstanceParm(param->server, param->processName, param->next++,
1053 } else if (tst == BZDOM) {
1057 *last_item_contains_data = 0;
1067 GetParameterFromCache(void *rpc_specific, int slot, void *dest,
1071 afs_status_t tst = 0;
1072 param_get_p param = (param_get_p) rpc_specific;
1074 strcpy((char *)dest, (char *)¶m->param[slot]);
1084 * bos_ProcessParameterGetBegin - begin iterating over the parameters
1085 * of a particular process.
1089 * IN serverHandle - a previously opened serverHandle.
1091 * IN processName - the process whose parameters are returned.
1093 * OUT iter - an iterator that can be passed to bos_ProcessParameterGetNext
1094 * to retrieve the parameters.
1098 * No locks are obtained or released by this function
1102 * Returns != 0 upon successful completion.
1107 bos_ProcessParameterGetBegin(const void *serverHandle,
1108 const char *processName, void **iterationIdP,
1112 afs_status_t tst = 0;
1113 bos_server_p b_handle = (bos_server_p) serverHandle;
1114 afs_admin_iterator_p iter =
1115 (afs_admin_iterator_p) malloc(sizeof(afs_admin_iterator_t));
1116 param_get_p param = (param_get_p) malloc(sizeof(param_get_t));
1118 if (!isValidServerHandle(b_handle, &tst)) {
1119 goto fail_bos_ProcessParameterGetBegin;
1122 if ((processName == NULL) || (*processName == 0)) {
1123 tst = ADMBOSPROCESSNAMENULL;
1124 goto fail_bos_ProcessParameterGetBegin;
1127 if (iterationIdP == NULL) {
1128 tst = ADMITERATIONIDPNULL;
1129 goto fail_bos_ProcessParameterGetBegin;
1132 if ((iter == NULL) || (param == NULL)) {
1134 goto fail_bos_ProcessParameterGetBegin;
1138 param->server = b_handle->server;
1139 strcpy(param->processName, processName);
1142 (iter, (void *)param, GetParameterRPC, GetParameterFromCache, NULL,
1144 *iterationIdP = (void *)iter;
1146 goto fail_bos_ProcessParameterGetBegin;
1150 fail_bos_ProcessParameterGetBegin:
1156 if (param != NULL) {
1168 * bos_ProcessParameterGetNext - retrieve the next parameter
1169 * from the bos server.
1173 * IN iterationId - an iterator previously returned by
1174 * bos_ProcessParameterGetBegin
1176 * OUT parameter - upon successful completion contains the next parameter
1177 * retrieved from the server.
1181 * No locks are obtained or released by this function
1185 * Returns != 0 upon successful completion.
1190 bos_ProcessParameterGetNext(const void *iterationId, char *parameter,
1194 afs_status_t tst = 0;
1195 afs_admin_iterator_p iter = (afs_admin_iterator_p) iterationId;
1197 if (iterationId == NULL) {
1198 tst = ADMITERATIONIDPNULL;
1199 goto fail_bos_ProcessParameterGetNext;
1202 if (parameter == NULL) {
1203 tst = ADMBOSPARAMETERNULL;
1204 goto fail_bos_ProcessParameterGetNext;
1207 rc = IteratorNext(iter, (void *)parameter, &tst);
1209 fail_bos_ProcessParameterGetNext:
1218 * bos_ProcessParameterGetDone - finish using a process name iterator.
1222 * IN iterationId - an iterator previously returned by
1223 * bos_ProcessParameterGetBegin
1227 * No locks are obtained or released by this function
1231 * Returns != 0 upon successful completion.
1236 bos_ProcessParameterGetDone(const void *iterationId, afs_status_p st)
1239 afs_status_t tst = 0;
1240 afs_admin_iterator_p iter = (afs_admin_iterator_p) iterationId;
1242 if (iterationId == NULL) {
1243 tst = ADMITERATIONIDPNULL;
1244 goto fail_bos_ProcessParameterGetDone;
1247 rc = IteratorDone(iter, &tst);
1249 fail_bos_ProcessParameterGetDone:
1258 * bos_ProcessNotifierGet - retrieve the notifier associated with a
1263 * IN serverHandle - a previously opened serverHandle.
1265 * IN processName - the process whose notifier we are retrieving.
1267 * OUT notifier - upon successful completion contains the notifier.
1271 * No locks are obtained or released by this function
1275 * Returns != 0 upon successful completion.
1280 bos_ProcessNotifierGet(const void *serverHandle, const char *processName,
1281 char *notifier, afs_status_p st)
1284 afs_status_t tst = 0;
1285 bos_server_p b_handle = (bos_server_p) serverHandle;
1287 if (!isValidServerHandle(b_handle, &tst)) {
1288 goto fail_bos_ProcessNotifierGet;
1291 if ((processName == NULL) || (*processName == 0)) {
1292 tst = ADMBOSPROCESSNAMENULL;
1293 goto fail_bos_ProcessNotifierGet;
1296 if (notifier == NULL) {
1297 tst = ADMBOSNOTIFIERNULL;
1298 goto fail_bos_ProcessNotifierGet;
1301 tst = BOZO_GetInstanceParm(b_handle->server, processName, 999, ¬ifier);
1307 fail_bos_ProcessNotifierGet:
1316 * bos_ProcessRestart - restart a particular process.
1320 * IN serverHandle - a previously opened serverHandle.
1322 * IN processName - the process to restart
1326 * No locks are obtained or released by this function
1330 * Returns != 0 upon successful completion.
1335 bos_ProcessRestart(const void *serverHandle, const char *processName,
1339 afs_status_t tst = 0;
1340 bos_server_p b_handle = (bos_server_p) serverHandle;
1342 if (!isValidServerHandle(b_handle, &tst)) {
1343 goto fail_bos_ProcessRestart;
1346 if ((processName == NULL) || (*processName == 0)) {
1347 tst = ADMBOSPROCESSNAMENULL;
1348 goto fail_bos_ProcessRestart;
1351 tst = BOZO_Restart(b_handle->server, processName);
1357 fail_bos_ProcessRestart:
1366 * bos_ProcessAllStop - stop all running processes at a server.
1370 * IN serverHandle - a previously opened serverHandle.
1374 * No locks are obtained or released by this function
1378 * Returns != 0 upon successful completion.
1383 bos_ProcessAllStop(const void *serverHandle, afs_status_p st)
1386 afs_status_t tst = 0;
1387 bos_server_p b_handle = (bos_server_p) serverHandle;
1389 if (!isValidServerHandle(b_handle, &tst)) {
1390 goto fail_bos_ProcessAllStop;
1393 tst = BOZO_ShutdownAll(b_handle->server);
1399 fail_bos_ProcessAllStop:
1408 * bos_ProcessAllStart - start all processes that should be running at a
1413 * IN serverHandle - a previously opened serverHandle.
1417 * No locks are obtained or released by this function
1421 * Returns != 0 upon successful completion.
1426 bos_ProcessAllStart(const void *serverHandle, afs_status_p st)
1429 afs_status_t tst = 0;
1430 bos_server_p b_handle = (bos_server_p) serverHandle;
1432 if (!isValidServerHandle(b_handle, &tst)) {
1433 goto fail_bos_ProcessAllStart;
1436 tst = BOZO_StartupAll(b_handle->server);
1442 fail_bos_ProcessAllStart:
1451 * bos_ProcessAllWaitStop - stop all processes, and block until they have
1456 * IN serverHandle - a previously opened serverHandle.
1460 * No locks are obtained or released by this function
1464 * Returns != 0 upon successful completion.
1469 bos_ProcessAllWaitStop(const void *serverHandle, afs_status_p st)
1472 afs_status_t tst = 0;
1473 bos_server_p b_handle = (bos_server_p) serverHandle;
1475 if (!isValidServerHandle(b_handle, &tst)) {
1476 goto fail_bos_ProcessAllWaitStop;
1479 if (!bos_ProcessAllStop(serverHandle, &tst)) {
1480 goto fail_bos_ProcessAllWaitStop;
1483 tst = BOZO_WaitAll(b_handle->server);
1489 fail_bos_ProcessAllWaitStop:
1498 * bos_ProcessAllWaitTransition - block until all processes at the bosserver
1499 * have reached their desired state.
1503 * IN serverHandle - a previously opened serverHandle.
1507 * No locks are obtained or released by this function
1511 * Returns != 0 upon successful completion.
1516 bos_ProcessAllWaitTransition(const void *serverHandle, afs_status_p st)
1519 afs_status_t tst = 0;
1520 bos_server_p b_handle = (bos_server_p) serverHandle;
1522 if (!isValidServerHandle(b_handle, &tst)) {
1523 goto fail_bos_ProcessAllWaitTransition;
1526 tst = BOZO_WaitAll(b_handle->server);
1532 fail_bos_ProcessAllWaitTransition:
1541 * bos_ProcessAllStopAndRestart - stop all the running processes, restart
1542 * them, and optionally restart the bosserver itself.
1547 * IN serverHandle - a previously opened serverHandle.
1549 * IN restartBosServer - flag to indicate whether to restart bosserver.
1553 * No locks are obtained or released by this function
1557 * Returns != 0 upon successful completion.
1562 bos_ProcessAllStopAndRestart(const void *serverHandle,
1563 bos_RestartBosServer_t restartBosServer,
1567 afs_status_t tst = 0;
1568 bos_server_p b_handle = (bos_server_p) serverHandle;
1570 if (!isValidServerHandle(b_handle, &tst)) {
1571 goto fail_bos_ProcessAllStopAndRestart;
1574 if (restartBosServer == BOS_RESTART_BOS_SERVER) {
1575 tst = BOZO_ReBozo(b_handle->server);
1577 goto fail_bos_ProcessAllStopAndRestart;
1581 tst = BOZO_RestartAll(b_handle->server);
1587 fail_bos_ProcessAllStopAndRestart:
1596 * bos_AdminCreate - create a new admin.
1600 * IN serverHandle - a previously opened serverHandle.
1602 * IN adminName - the new admin name.
1606 * No locks are obtained or released by this function
1610 * Returns != 0 upon successful completion.
1615 bos_AdminCreate(const void *serverHandle, const char *adminName,
1619 afs_status_t tst = 0;
1620 bos_server_p b_handle = (bos_server_p) serverHandle;
1622 if (!isValidServerHandle(b_handle, &tst)) {
1623 goto fail_bos_AdminCreate;
1626 if ((adminName == NULL) || (*adminName == 0)) {
1627 tst = ADMBOSADMINNAMENULL;
1628 goto fail_bos_AdminCreate;
1631 tst = BOZO_AddSUser(b_handle->server, adminName);
1637 fail_bos_AdminCreate:
1646 * bos_AdminDelete - delete a new admin.
1650 * IN serverHandle - a previously opened serverHandle.
1652 * IN adminName - the admin name.
1656 * No locks are obtained or released by this function
1660 * Returns != 0 upon successful completion.
1665 bos_AdminDelete(const void *serverHandle, const char *adminName,
1669 afs_status_t tst = 0;
1670 bos_server_p b_handle = (bos_server_p) serverHandle;
1672 if (!isValidServerHandle(b_handle, &tst)) {
1673 goto fail_bos_AdminDelete;
1676 if ((adminName == NULL) || (*adminName == 0)) {
1677 tst = ADMBOSADMINNAMENULL;
1678 goto fail_bos_AdminDelete;
1681 tst = BOZO_DeleteSUser(b_handle->server, adminName);
1687 fail_bos_AdminDelete:
1696 * The iterator functions and data for the admin retrieval functions
1699 typedef struct admin_get {
1701 struct rx_connection *server;
1702 char admin[CACHED_ITEMS][BOS_MAX_NAME_LEN];
1703 } admin_get_t, *admin_get_p;
1706 GetAdminRPC(void *rpc_specific, int slot, int *last_item,
1707 int *last_item_contains_data, afs_status_p st)
1710 afs_status_t tst = 0;
1711 admin_get_p admin = (admin_get_p) rpc_specific;
1712 char *ptr = (char *)&admin->admin[slot];
1714 tst = BOZO_ListSUsers(admin->server, admin->next++, &ptr);
1717 * There's no way to tell the difference between an rpc failure
1718 * and the end of the list, so we assume that any error means the
1725 *last_item_contains_data = 0;
1736 GetAdminFromCache(void *rpc_specific, int slot, void *dest, afs_status_p st)
1739 afs_status_t tst = 0;
1740 admin_get_p admin = (admin_get_p) rpc_specific;
1742 strcpy((char *)dest, (char *)&admin->admin[slot]);
1752 * bos_AdminGetBegin - begin iterating over the administrators.
1756 * IN serverHandle - a previously opened serverHandle.
1758 * OUT iter - an iterator that can be passed to bos_AdminGetBegin
1759 * to retrieve the administrators.
1763 * No locks are obtained or released by this function
1767 * Returns != 0 upon successful completion.
1772 bos_AdminGetBegin(const void *serverHandle, void **iterationIdP,
1776 afs_status_t tst = 0;
1777 bos_server_p b_handle = (bos_server_p) serverHandle;
1778 afs_admin_iterator_p iter =
1779 (afs_admin_iterator_p) malloc(sizeof(afs_admin_iterator_t));
1780 admin_get_p admin = (admin_get_p) malloc(sizeof(admin_get_t));
1782 if (!isValidServerHandle(b_handle, &tst)) {
1783 goto fail_bos_AdminGetBegin;
1786 if (iterationIdP == NULL) {
1787 tst = ADMITERATIONIDPNULL;
1788 goto fail_bos_AdminGetBegin;
1791 if ((iter == NULL) || (admin == NULL)) {
1793 goto fail_bos_AdminGetBegin;
1797 admin->server = b_handle->server;
1800 (iter, (void *)admin, GetAdminRPC, GetAdminFromCache, NULL, NULL,
1802 *iterationIdP = (void *)iter;
1806 fail_bos_AdminGetBegin:
1812 if (admin != NULL) {
1824 * bos_AdminGetNext - retrieve the next administrator
1825 * from the bos server.
1829 * IN iterationId - an iterator previously returned by
1832 * OUT adminName - upon successful completion contains the next administrator
1833 * retrieved from the server.
1837 * No locks are obtained or released by this function
1841 * Returns != 0 upon successful completion.
1846 bos_AdminGetNext(const void *iterationId, char *adminName, afs_status_p st)
1849 afs_status_t tst = 0;
1850 afs_admin_iterator_p iter = (afs_admin_iterator_p) iterationId;
1852 if (iterationId == NULL) {
1853 tst = ADMITERATIONIDPNULL;
1854 goto fail_bos_AdminGetNext;
1857 if (adminName == NULL) {
1858 tst = ADMBOSADMINNAMENULL;
1859 goto fail_bos_AdminGetNext;
1862 rc = IteratorNext(iter, (void *)adminName, &tst);
1864 fail_bos_AdminGetNext:
1873 * bos_AdminGetDone - finish using a administrator iterator.
1877 * IN iterationId - an iterator previously returned by
1882 * No locks are obtained or released by this function
1886 * Returns != 0 upon successful completion.
1891 bos_AdminGetDone(const void *iterationId, afs_status_p st)
1894 afs_status_t tst = 0;
1895 afs_admin_iterator_p iter = (afs_admin_iterator_p) iterationId;
1897 if (iterationId == NULL) {
1898 tst = ADMITERATIONIDPNULL;
1899 goto fail_bos_AdminGetDone;
1902 rc = IteratorDone(iter, &tst);
1904 fail_bos_AdminGetDone:
1913 * bos_KeyCreate - add a new key to the keyfile.
1917 * IN serverHandle - a previously opened serverHandle.
1919 * IN keyVersionNumber - the key version number.
1921 * IN key - the new key.
1925 * No locks are obtained or released by this function
1929 * Returns != 0 upon successful completion.
1934 bos_KeyCreate(const void *serverHandle, int keyVersionNumber,
1935 const kas_encryptionKey_p key, afs_status_p st)
1938 afs_status_t tst = 0;
1939 bos_server_p b_handle = (bos_server_p) serverHandle;
1941 if (!isValidServerHandle(b_handle, &tst)) {
1942 goto fail_bos_KeyCreate;
1946 tst = ADMBOSKEYNULL;
1947 goto fail_bos_KeyCreate;
1950 tst = BOZO_AddKey(b_handle->server_encrypt, keyVersionNumber, key);
1965 * bos_KeyDelete - delete an existing key from the keyfile.
1969 * IN serverHandle - a previously opened serverHandle.
1971 * IN keyVersionNumber - the key version number.
1975 * No locks are obtained or released by this function
1979 * Returns != 0 upon successful completion.
1984 bos_KeyDelete(const void *serverHandle, int keyVersionNumber, afs_status_p st)
1987 afs_status_t tst = 0;
1988 bos_server_p b_handle = (bos_server_p) serverHandle;
1990 if (!isValidServerHandle(b_handle, &tst)) {
1991 goto fail_bos_KeyDelete;
1994 tst = BOZO_DeleteKey(b_handle->server, keyVersionNumber);
2009 * The iterator functions and data for the key retrieval functions
2012 typedef struct key_get {
2014 struct rx_connection *server;
2015 bos_KeyInfo_t key[CACHED_ITEMS];
2016 } key_get_t, *key_get_p;
2019 GetKeyRPC(void *rpc_specific, int slot, int *last_item,
2020 int *last_item_contains_data, afs_status_p st)
2023 afs_status_t tst = 0;
2024 key_get_p key = (key_get_p) rpc_specific;
2025 struct bozo_keyInfo keyInfo;
2028 BOZO_ListKeys(key->server, key->next++,
2029 &key->key[slot].keyVersionNumber, &key->key[slot].key,
2034 key->key[slot].keyStatus.lastModificationDate = keyInfo.mod_sec;
2035 key->key[slot].keyStatus.lastModificationMicroSeconds =
2037 key->key[slot].keyStatus.checkSum = keyInfo.keyCheckSum;
2039 } else if (tst == BZDOM) {
2043 *last_item_contains_data = 0;
2053 GetKeyFromCache(void *rpc_specific, int slot, void *dest, afs_status_p st)
2056 afs_status_t tst = 0;
2057 key_get_p key = (key_get_p) rpc_specific;
2059 memcpy(dest, &key->key[slot], sizeof(bos_KeyInfo_t));
2069 * bos_KeyGetBegin - begin iterating over the keys.
2073 * IN serverHandle - a previously opened serverHandle.
2075 * OUT iter - an iterator that can be passed to bos_KeyGetNext
2076 * to retrieve the keys.
2080 * No locks are obtained or released by this function
2084 * Returns != 0 upon successful completion.
2089 bos_KeyGetBegin(const void *serverHandle, void **iterationIdP,
2093 afs_status_t tst = 0;
2094 bos_server_p b_handle = (bos_server_p) serverHandle;
2095 afs_admin_iterator_p iter =
2096 (afs_admin_iterator_p) malloc(sizeof(afs_admin_iterator_t));
2097 key_get_p key = (key_get_p) malloc(sizeof(key_get_t));
2099 if (!isValidServerHandle(b_handle, &tst)) {
2100 goto fail_bos_KeyGetBegin;
2103 if (iterationIdP == NULL) {
2104 tst = ADMITERATIONIDPNULL;
2105 goto fail_bos_KeyGetBegin;
2108 if ((iter == NULL) || (key == NULL)) {
2110 goto fail_bos_KeyGetBegin;
2114 key->server = b_handle->server_encrypt;
2117 (iter, (void *)key, GetKeyRPC, GetKeyFromCache, NULL, NULL, &tst)) {
2118 *iterationIdP = (void *)iter;
2122 fail_bos_KeyGetBegin:
2140 * bos_KeyGetNext - retrieve the next key
2141 * from the bos server.
2145 * IN iterationId - an iterator previously returned by
2148 * OUT keyP - upon successful completion contains the next key
2149 * retrieved from the server.
2153 * No locks are obtained or released by this function
2157 * Returns != 0 upon successful completion.
2162 bos_KeyGetNext(const void *iterationId, bos_KeyInfo_p keyP, afs_status_p st)
2165 afs_status_t tst = 0;
2166 afs_admin_iterator_p iter = (afs_admin_iterator_p) iterationId;
2168 if (iterationId == NULL) {
2169 tst = ADMITERATIONIDPNULL;
2170 goto fail_bos_KeyGetNext;
2174 tst = ADMBOSKEYPNULL;
2175 goto fail_bos_KeyGetNext;
2178 rc = IteratorNext(iter, (void *)keyP, &tst);
2180 fail_bos_KeyGetNext:
2189 * bos_KeyGetDone - finish using a key iterator.
2193 * IN iterationId - an iterator previously returned by
2198 * No locks are obtained or released by this function
2202 * Returns != 0 upon successful completion.
2207 bos_KeyGetDone(const void *iterationId, afs_status_p st)
2210 afs_status_t tst = 0;
2211 afs_admin_iterator_p iter = (afs_admin_iterator_p) iterationId;
2213 if (iterationId == NULL) {
2214 tst = ADMITERATIONIDPNULL;
2215 goto fail_bos_KeyGetDone;
2218 rc = IteratorDone(iter, &tst);
2220 fail_bos_KeyGetDone:
2229 * bos_CellSet - set the cell name at a bos server.
2233 * IN serverHandle - a previously opened serverHandle.
2235 * IN cellName - the new cell name.
2239 * No locks are obtained or released by this function
2243 * Returns != 0 upon successful completion.
2247 bos_CellSet(const void *serverHandle, const char *cellName, afs_status_p st)
2250 afs_status_t tst = 0;
2251 bos_server_p b_handle = (bos_server_p) serverHandle;
2253 if (!isValidServerHandle(b_handle, &tst)) {
2254 goto fail_bos_CellSet;
2257 if ((cellName == NULL) || (*cellName == 0)) {
2258 tst = ADMCLIENTCELLNAMENULL;
2259 goto fail_bos_CellSet;
2262 tst = BOZO_SetCellName(b_handle->server, cellName);
2277 * bos_CellGet - get the cell name at a bos server.
2281 * IN serverHandle - a previously opened serverHandle.
2283 * OUT cellName - the cell name.
2287 * No locks are obtained or released by this function
2291 * Returns != 0 upon successful completion.
2295 bos_CellGet(const void *serverHandle, char *cellName, afs_status_p st)
2298 afs_status_t tst = 0;
2299 bos_server_p b_handle = (bos_server_p) serverHandle;
2301 if (!isValidServerHandle(b_handle, &tst)) {
2302 goto fail_bos_CellGet;
2305 if (cellName == NULL) {
2306 tst = ADMCLIENTCELLNAMENULL;
2307 goto fail_bos_CellGet;
2310 tst = BOZO_GetCellName(b_handle->server, &cellName);
2325 * bos_HostCreate - add a new host to the cell.
2329 * IN serverHandle - a previously opened serverHandle.
2331 * IN hostName - the new host.
2335 * No locks are obtained or released by this function
2339 * Returns != 0 upon successful completion.
2343 bos_HostCreate(const void *serverHandle, const char *hostName,
2347 afs_status_t tst = 0;
2348 bos_server_p b_handle = (bos_server_p) serverHandle;
2350 if (!isValidServerHandle(b_handle, &tst)) {
2351 goto fail_bos_HostCreate;
2354 if ((hostName == NULL) || (*hostName == 0)) {
2355 tst = ADMBOSHOSTNAMENULL;
2356 goto fail_bos_HostCreate;
2359 tst = BOZO_AddCellHost(b_handle->server, hostName);
2365 fail_bos_HostCreate:
2374 * bos_HostDelete - delete a host from the cell.
2378 * IN serverHandle - a previously opened serverHandle.
2380 * IN hostName - the host.
2384 * No locks are obtained or released by this function
2388 * Returns != 0 upon successful completion.
2392 bos_HostDelete(const void *serverHandle, const char *hostName,
2396 afs_status_t tst = 0;
2397 bos_server_p b_handle = (bos_server_p) serverHandle;
2399 if (!isValidServerHandle(b_handle, &tst)) {
2400 goto fail_bos_HostDelete;
2403 if ((hostName == NULL) || (*hostName == 0)) {
2404 tst = ADMBOSHOSTNAMENULL;
2405 goto fail_bos_HostDelete;
2408 tst = BOZO_DeleteCellHost(b_handle->server, hostName);
2414 fail_bos_HostDelete:
2423 * The iterator functions and data for the host retrieval functions
2426 typedef struct host_get {
2428 struct rx_connection *server;
2429 char host[CACHED_ITEMS][BOS_MAX_NAME_LEN];
2430 } host_get_t, *host_get_p;
2433 GetHostRPC(void *rpc_specific, int slot, int *last_item,
2434 int *last_item_contains_data, afs_status_p st)
2437 afs_status_t tst = 0;
2438 host_get_p host = (host_get_p) rpc_specific;
2439 char *ptr = (char *)&host->host[slot];
2441 tst = BOZO_GetCellHost(host->server, host->next++, &ptr);
2445 } else if (tst == BZDOM) {
2449 *last_item_contains_data = 0;
2459 GetHostFromCache(void *rpc_specific, int slot, void *dest, afs_status_p st)
2462 afs_status_t tst = 0;
2463 host_get_p host = (host_get_p) rpc_specific;
2465 strcpy((char *)dest, (char *)&host->host[slot]);
2475 * bos_HostGetBegin - begin iterating over the hosts in a cell
2476 * at a particular bos server.
2480 * IN serverHandle - a previously opened serverHandle.
2482 * OUT iter - an iterator that can be passed to bos_HostGetNext
2483 * to retrieve the process names.
2487 * No locks are obtained or released by this function
2491 * Returns != 0 upon successful completion.
2496 bos_HostGetBegin(const void *serverHandle, void **iterationIdP,
2500 afs_status_t tst = 0;
2501 bos_server_p b_handle = (bos_server_p) serverHandle;
2502 afs_admin_iterator_p iter =
2503 (afs_admin_iterator_p) malloc(sizeof(afs_admin_iterator_t));
2504 host_get_p host = (host_get_p) malloc(sizeof(host_get_t));
2506 if (!isValidServerHandle(b_handle, &tst)) {
2507 goto fail_bos_HostGetBegin;
2510 if (iterationIdP == NULL) {
2511 tst = ADMITERATIONIDPNULL;
2512 goto fail_bos_HostGetBegin;
2515 if ((iter == NULL) || (host == NULL)) {
2517 goto fail_bos_HostGetBegin;
2521 host->server = b_handle->server;
2524 (iter, (void *)host, GetHostRPC, GetHostFromCache, NULL, NULL,
2526 *iterationIdP = (void *)iter;
2530 fail_bos_HostGetBegin:
2548 * bos_HostGetNext - retrieve the next host
2549 * from the bos server.
2553 * IN iterationId - an iterator previously returned by
2556 * OUT hostName - upon successful completion contains the next host
2557 * retrieved from the server.
2561 * No locks are obtained or released by this function
2565 * Returns != 0 upon successful completion.
2570 bos_HostGetNext(const void *iterationId, char *hostName, afs_status_p st)
2573 afs_status_t tst = 0;
2574 afs_admin_iterator_p iter = (afs_admin_iterator_p) iterationId;
2576 if (iterationId == NULL) {
2577 tst = ADMITERATIONIDPNULL;
2578 goto fail_bos_HostGetNext;
2581 if (hostName == NULL) {
2582 tst = ADMBOSHOSTNAMENULL;
2583 goto fail_bos_HostGetNext;
2586 rc = IteratorNext(iter, (void *)hostName, &tst);
2588 fail_bos_HostGetNext:
2597 * bos_HostGetDone - finish using a host iterator.
2601 * IN iterationId - an iterator previously returned by
2606 * No locks are obtained or released by this function
2610 * Returns != 0 upon successful completion.
2615 bos_HostGetDone(const void *iterationId, afs_status_p st)
2618 afs_status_t tst = 0;
2619 afs_admin_iterator_p iter = (afs_admin_iterator_p) iterationId;
2621 if (iterationId == NULL) {
2622 tst = ADMITERATIONIDPNULL;
2623 goto fail_bos_HostGetDone;
2626 rc = IteratorDone(iter, &tst);
2628 fail_bos_HostGetDone:
2637 * bos_ExecutableCreate - create a new executable at the bos server.
2641 * IN serverHandle - a previously opened serverHandle.
2643 * IN sourceFile - the executable to install at the bos server.
2645 * IN destFile - the location where the executable will be installed.
2649 * No locks are obtained or released by this function
2653 * Returns != 0 upon successful completion.
2658 bos_ExecutableCreate(const void *serverHandle, const char *sourceFile,
2659 const char *destFile, afs_status_p st)
2662 afs_status_t tst = 0;
2663 bos_server_p b_handle = (bos_server_p) serverHandle;
2666 struct rx_call *tcall;
2669 * Validate arguments
2672 if (!isValidServerHandle(b_handle, &tst)) {
2673 goto fail_bos_ExecutableCreate;
2676 if ((sourceFile == NULL) || (*sourceFile == 0)) {
2677 tst = ADMBOSSOURCEFILENULL;
2678 goto fail_bos_ExecutableCreate;
2681 if ((destFile == NULL) || (*destFile == 0)) {
2682 tst = ADMBOSDESTFILENULL;
2683 goto fail_bos_ExecutableCreate;
2687 * Open the file locally and compute its size
2690 fd = open(sourceFile, O_RDONLY);
2693 tst = ADMBOSCANTOPENSOURCEFILE;
2694 goto fail_bos_ExecutableCreate;
2697 if (fstat(fd, &estat)) {
2698 tst = ADMBOSCANTSTATSOURCEFILE;
2699 goto fail_bos_ExecutableCreate;
2703 * Start a split rpc to the bos server.
2706 tcall = rx_NewCall(b_handle->server);
2709 StartBOZO_Install(tcall, destFile, estat.st_size,
2710 (afs_int32) estat.st_mode, estat.st_mtime);
2713 rx_EndCall(tcall, tst);
2714 goto fail_bos_ExecutableCreate;
2718 * Copy the data to the server
2724 len = read(fd, tbuffer, sizeof(tbuffer));
2726 tst = ADMBOSCANTREADSOURCEFILE;
2727 rx_EndCall(tcall, len);
2728 goto fail_bos_ExecutableCreate;
2734 tst = rx_Write(tcall, tbuffer, len);
2736 tst = ADMBOSSENDSOURCEFILE;
2737 rx_EndCall(tcall, tst);
2738 goto fail_bos_ExecutableCreate;
2743 * Terminate the rpc to the server
2746 tst = rx_EndCall(tcall, tst);
2752 fail_bos_ExecutableCreate:
2761 * bos_ExecutableRevert - revert an executable to a previous .BAK version.
2765 * IN serverHandle - a previously opened serverHandle.
2767 * IN execFile - the executable to revert at the bos server.
2771 * No locks are obtained or released by this function
2775 * Returns != 0 upon successful completion.
2780 bos_ExecutableRevert(const void *serverHandle, const char *execFile,
2784 afs_status_t tst = 0;
2785 bos_server_p b_handle = (bos_server_p) serverHandle;
2787 if (!isValidServerHandle(b_handle, &tst)) {
2788 goto fail_bos_ExecutableRevert;
2791 if ((execFile == NULL) || (*execFile == 0)) {
2792 tst = ADMBOSEXECFILENULL;
2793 goto fail_bos_ExecutableRevert;
2796 tst = BOZO_UnInstall(b_handle->server, execFile);
2802 fail_bos_ExecutableRevert:
2811 * bos_ExecutableTimestampGet - get the last mod times for an executable,
2812 * the .BAK version of the executable, and the .OLD version of the
2813 * executable if they exist.
2817 * IN serverHandle - a previously opened serverHandle.
2819 * IN execFile - the executable to revert at the bos server.
2823 * No locks are obtained or released by this function
2827 * Returns != 0 upon successful completion.
2832 bos_ExecutableTimestampGet(const void *serverHandle, const char *execFile,
2833 unsigned long *newTime, unsigned long *oldTime,
2834 unsigned long *bakTime, afs_status_p st)
2837 afs_status_t tst = 0;
2838 bos_server_p b_handle = (bos_server_p) serverHandle;
2840 if (!isValidServerHandle(b_handle, &tst)) {
2841 goto fail_bos_ExecutableTimestampGet;
2844 if ((execFile == NULL) || (*execFile == 0)) {
2845 tst = ADMBOSEXECFILENULL;
2846 goto fail_bos_ExecutableTimestampGet;
2849 if (newTime == NULL) {
2850 tst = ADMBOSNEWTIMENULL;
2851 goto fail_bos_ExecutableTimestampGet;
2854 if (oldTime == NULL) {
2855 tst = ADMBOSOLDTIMENULL;
2856 goto fail_bos_ExecutableTimestampGet;
2859 if (bakTime == NULL) {
2860 tst = ADMBOSBAKTIMENULL;
2861 goto fail_bos_ExecutableTimestampGet;
2865 BOZO_GetDates(b_handle->server, execFile, newTime, bakTime, oldTime);
2871 fail_bos_ExecutableTimestampGet:
2880 * bos_ExecutablePrune - prune the bak, old, and core files off a server
2885 * IN serverHandle - a previously opened serverHandle.
2887 * IN oldFiles - prune .OLD files.
2889 * IN bakFiles - prune .BAK files.
2891 * IN coreFiles - prune core files.
2895 * No locks are obtained or released by this function
2899 * Returns != 0 upon successful completion.
2904 bos_ExecutablePrune(const void *serverHandle, bos_Prune_t oldFiles,
2905 bos_Prune_t bakFiles, bos_Prune_t coreFiles,
2909 afs_status_t tst = 0;
2910 bos_server_p b_handle = (bos_server_p) serverHandle;
2911 afs_int32 flags = 0;
2913 if (!isValidServerHandle(b_handle, &tst)) {
2914 goto fail_bos_ExecutablePrune;
2917 if (oldFiles == BOS_PRUNE) {
2918 flags |= BOZO_PRUNEOLD;
2921 if (bakFiles == BOS_PRUNE) {
2922 flags |= BOZO_PRUNEBAK;
2925 if (coreFiles == BOS_PRUNE) {
2926 flags |= BOZO_PRUNECORE;
2929 tst = BOZO_Prune(b_handle->server, flags);
2935 fail_bos_ExecutablePrune:
2944 * bos_ExecutableRestartTimeSet - set the restart time of the bos server
2949 * IN serverHandle - a previously opened serverHandle.
2951 * IN type - specifies either weekly restart or daily restart time.
2953 * IN time - the time to begin restarts.
2957 * No locks are obtained or released by this function
2961 * Returns != 0 upon successful completion.
2966 bos_ExecutableRestartTimeSet(const void *serverHandle, bos_Restart_t type,
2967 bos_RestartTime_t time, afs_status_p st)
2970 afs_status_t tst = 0;
2971 bos_server_p b_handle = (bos_server_p) serverHandle;
2972 afs_int32 restartType = 0;
2973 struct ktime restartTime;
2975 if (!isValidServerHandle(b_handle, &tst)) {
2976 goto fail_bos_ExecutableRestartTimeSet;
2979 if (type == BOS_RESTART_WEEKLY) {
2985 if ((time.mask & BOS_RESTART_TIME_HOUR)
2986 && ((time.hour < 0) || (time.hour > 23))) {
2987 tst = ADMBOSHOURINVALID;
2988 goto fail_bos_ExecutableRestartTimeSet;
2991 if ((time.mask & BOS_RESTART_TIME_MINUTE)
2992 && ((time.min < 0) || (time.min > 60))) {
2993 tst = ADMBOSMINUTEINVALID;
2994 goto fail_bos_ExecutableRestartTimeSet;
2997 if ((time.mask & BOS_RESTART_TIME_SECOND)
2998 && ((time.sec < 0) || (time.sec > 60))) {
2999 tst = ADMBOSSECONDINVALID;
3000 goto fail_bos_ExecutableRestartTimeSet;
3003 if ((time.mask & BOS_RESTART_TIME_DAY)
3004 && ((time.day < 0) || (time.day > 6))) {
3005 tst = ADMBOSDAYINVALID;
3006 goto fail_bos_ExecutableRestartTimeSet;
3009 restartTime.mask = time.mask;
3010 restartTime.hour = time.hour;
3011 restartTime.min = time.min;
3012 restartTime.sec = time.sec;
3013 restartTime.day = time.day;
3015 tst = BOZO_SetRestartTime(b_handle->server, restartType, &restartTime);
3021 fail_bos_ExecutableRestartTimeSet:
3030 * bos_ExecutableRestartTimeGet - get the restart time of the bos server
3035 * IN serverHandle - a previously opened serverHandle.
3037 * IN type - specifies either weekly restart or daily restart time.
3039 * OUT timeP - the time to begin restarts.
3043 * No locks are obtained or released by this function
3047 * Returns != 0 upon successful completion.
3052 bos_ExecutableRestartTimeGet(const void *serverHandle, bos_Restart_t type,
3053 bos_RestartTime_p timeP, afs_status_p st)
3056 afs_status_t tst = 0;
3057 bos_server_p b_handle = (bos_server_p) serverHandle;
3058 afs_int32 restartType = 0;
3059 struct ktime restartTime;
3061 if (!isValidServerHandle(b_handle, &tst)) {
3062 goto fail_bos_ExecutableRestartTimeGet;
3065 if (timeP == NULL) {
3066 tst = ADMBOSTIMEPNULL;
3067 goto fail_bos_ExecutableRestartTimeGet;
3070 if (type == BOS_RESTART_WEEKLY) {
3076 tst = BOZO_GetRestartTime(b_handle->server, restartType, &restartTime);
3079 goto fail_bos_ExecutableRestartTimeGet;
3082 timeP->mask = restartTime.mask;
3083 timeP->hour = restartTime.hour;
3084 timeP->min = restartTime.min;
3085 timeP->sec = restartTime.sec;
3086 timeP->day = restartTime.day;
3089 fail_bos_ExecutableRestartTimeGet:
3098 * bos_LogGet - get a log file from the bos server machine.
3102 * IN serverHandle - a previously opened serverHandle.
3104 * IN log - the log file to retrieve.
3106 * IN/OUT logBufferSizeP - the length of the logData buffer on input,
3107 * and upon successful completion, the length of data stored in the buffer.
3109 * OUT logData - the retrieved data upon successful completion.
3113 * No locks are obtained or released by this function
3117 * Returns != 0 upon successful completion.
3122 bos_LogGet(const void *serverHandle, const char *log,
3123 unsigned long *logBufferSizeP, char *logData, afs_status_p st)
3126 afs_status_t tst = 0;
3127 bos_server_p b_handle = (bos_server_p) serverHandle;
3128 struct rx_call *tcall = NULL;
3132 unsigned long bytes_read = 0;
3135 * Validate parameters
3138 if (!isValidServerHandle(b_handle, &tst)) {
3139 goto fail_bos_LogGet;
3142 if ((log == NULL) || (*log == 0)) {
3143 tst = ADMBOSLOGNULL;
3144 goto fail_bos_LogGet;
3147 if (logBufferSizeP == NULL) {
3148 tst = ADMBOSLOGBUFFERSIZEPNULL;
3149 goto fail_bos_LogGet;
3152 if (logData == NULL) {
3153 tst = ADMBOSLOGDATANULL;
3154 goto fail_bos_LogGet;
3158 * Begin to retrieve the data
3161 tcall = rx_NewCall(b_handle->server);
3163 tst = StartBOZO_GetLog(tcall, log);
3166 goto fail_bos_LogGet;
3170 * Read the log file data
3174 error = rx_Read(tcall, &buffer, 1);
3176 tst = ADMBOSLOGFILEERROR;
3177 goto fail_bos_LogGet;
3181 * check for the end of the log
3185 *logBufferSizeP = bytes_read;
3190 * We've successfully read another byte, copy it to logData
3195 if (bytes_read <= *logBufferSizeP) {
3196 *logData++ = buffer;
3208 rx_EndCall(tcall, 0);
3218 * bos_AuthSet - set the authorization level required at the bos server.
3222 * IN serverHandle - a previously opened serverHandle.
3224 * IN auth - specifies the new auth level.
3228 * No locks are obtained or released by this function
3232 * Returns != 0 upon successful completion.
3237 bos_AuthSet(const void *serverHandle, bos_Auth_t auth, afs_status_p st)
3240 afs_status_t tst = 0;
3241 bos_server_p b_handle = (bos_server_p) serverHandle;
3242 afs_int32 level = 0;
3244 if (!isValidServerHandle(b_handle, &tst)) {
3245 goto fail_bos_AuthSet;
3248 if (auth == BOS_AUTH_REQUIRED) {
3254 tst = BOZO_SetNoAuthFlag(b_handle->server, level);
3269 * bos_CommandExecute - execute a command at the bos server.
3273 * IN serverHandle - a previously opened serverHandle.
3275 * IN command - the command to execute.
3279 * No locks are obtained or released by this function
3283 * Returns != 0 upon successful completion.
3288 bos_CommandExecute(const void *serverHandle, const char *command,
3292 afs_status_t tst = 0;
3293 bos_server_p b_handle = (bos_server_p) serverHandle;
3295 if (!isValidServerHandle(b_handle, &tst)) {
3296 goto fail_bos_CommandExecute;
3299 if ((command == NULL) || (*command == 0)) {
3300 tst = ADMBOSCOMMANDNULL;
3301 goto fail_bos_CommandExecute;
3304 tst = BOZO_Exec(b_handle->server, command);
3310 fail_bos_CommandExecute:
3319 * bos_Salvage - perform a remote salvage operation.
3323 * IN cellHandle - a previously opened cellHandle.
3325 * IN serverHandle - a previously opened serverHandle.
3327 * IN partitionName - the partition to salvage. Can be null.
3329 * IN volumeName - the volume to salvage. Can be null, if non-null,
3330 * partitionName cannot be null.
3332 * IN numSalvagers - the number of salvage processes to run in parallel.
3334 * IN tmpDir - directory to place temporary files. Can be null.
3336 * IN logFile - file where salvage log will be written. Can be null.
3338 * IN force - sets salvager -force flag.
3340 * IN salvageDamagedVolumes - sets salvager -oktozap flag.
3342 * IN writeInodes - sets salvager -inodes flag.
3344 * IN writeRootInodes - sets salvager -rootinodes flag.
3346 * IN forceDirectory - sets salvager -salvagedirs flag.
3348 * IN forceBlockRead - sets salvager -blockread flag.
3352 * No locks are obtained or released by this function
3356 * Returns != 0 upon successful completion.
3360 #define INITIAL_LOG_LEN 4096
3363 bos_Salvage(const void *cellHandle, const void *serverHandle,
3364 const char *partitionName, const char *volumeName,
3365 int numSalvagers, const char *tmpDir, const char *logFile,
3367 bos_SalvageDamagedVolumes_t salvageDamagedVolumes,
3368 bos_WriteInodes_t writeInodes,
3369 bos_WriteRootInodes_t writeRootInodes,
3370 bos_ForceDirectory_t forceDirectory,
3371 bos_ForceBlockRead_t forceBlockRead, afs_status_p st)
3374 afs_status_t tst = 0;
3375 bos_server_p b_handle = (bos_server_p) serverHandle;
3376 afs_cell_handle_p c_handle = (afs_cell_handle_p) cellHandle;
3377 int have_partition = 0;
3378 int have_volume = 0;
3379 unsigned int part = 0;
3380 int try_to_stop_fileserver = 0;
3381 bos_ProcessType_t procType;
3382 bos_ProcessInfo_t procInfo;
3384 char command[BOS_MAX_NAME_LEN];
3385 int command_len = 0;
3387 char *logData = NULL;
3388 unsigned long logLen = INITIAL_LOG_LEN;
3391 * Validate arguments
3394 if (!IsValidCellHandle(c_handle, &tst)) {
3395 goto fail_bos_Salvage;
3398 if (!isValidServerHandle(b_handle, &tst)) {
3399 goto fail_bos_Salvage;
3402 if (c_handle->vos_valid == 0) {
3403 tst = ADMBOSCELLHANDLENOVOS;
3404 goto fail_bos_Salvage;
3407 if ((partitionName != NULL) && (*partitionName != 0)) {
3408 if (!vos_PartitionNameToId(partitionName, &part, &tst)) {
3409 goto fail_bos_Salvage;
3414 if ((volumeName != NULL) && (*volumeName != 0)) {
3415 if (!have_partition) {
3416 tst = ADMBOSSALVAGEVOLUME;
3417 goto fail_bos_Salvage;
3422 if ((logFile != NULL) && (*logFile != 0)) {
3423 log = fopen(logFile, "w");
3425 tst = ADMBOSSALVAGEBADLOG;
3426 goto fail_bos_Salvage;
3431 * If we are salvaging more than a single volume, stop the fileserver
3435 try_to_stop_fileserver = 1;
3439 * Only try to stop the fileserver if it is running
3442 if (try_to_stop_fileserver) {
3443 if (bos_ProcessInfoGet
3444 (serverHandle, "fs", &procType, &procInfo, &tst)) {
3445 if (procInfo.processGoal != BOS_PROCESS_RUNNING) {
3446 try_to_stop_fileserver = 0;
3452 * Make the call to stop the fileserver and wait for it to shutdown
3455 if (try_to_stop_fileserver) {
3456 if (!bos_ProcessExecutionStateSetTemporary
3457 (serverHandle, "fs", BOS_PROCESS_STOPPED, &tst)) {
3458 goto fail_bos_Salvage;
3460 bos_ProcessAllWaitTransition(serverHandle, &tst);
3464 * Create the salvage command line arguments
3468 sprintf(command, "%s ", AFSDIR_CANONICAL_SERVER_SALVAGER_FILEPATH);
3469 if (have_partition) {
3471 sprintf(&command[command_len], "-partition %s ", partitionName);
3476 sprintf(&command[command_len], "-volumeid %s ", volumeName);
3479 if (salvageDamagedVolumes == BOS_DONT_SALVAGE_DAMAGED_VOLUMES) {
3480 command_len += sprintf(&command[command_len], "-nowrite ");
3483 if (writeInodes == BOS_SALVAGE_WRITE_INODES) {
3484 command_len += sprintf(&command[command_len], "-inodes ");
3487 if (force == VOS_FORCE) {
3488 command_len += sprintf(&command[command_len], "-force ");
3491 if (writeRootInodes == BOS_SALVAGE_WRITE_ROOT_INODES) {
3492 command_len += sprintf(&command[command_len], "-rootinodes ");
3495 if (forceDirectory == BOS_SALVAGE_FORCE_DIRECTORIES) {
3496 command_len += sprintf(&command[command_len], "-salvagedirs ");
3499 if (forceBlockRead == BOS_SALVAGE_FORCE_BLOCK_READS) {
3500 command_len += sprintf(&command[command_len], "-blockreads ");
3504 sprintf(&command[command_len], "-parallel %d ", numSalvagers);
3506 if ((tmpDir != NULL) && (*tmpDir != 0)) {
3507 command_len += sprintf(&command[command_len], "-tmpdir %s ", tmpDir);
3510 if (command_len > BOS_MAX_NAME_LEN) {
3511 tst = ADMBOSSALVAGEBADOPTIONS;
3512 goto fail_bos_Salvage;
3516 * Create the process at the bosserver and wait until it completes
3519 if (!bos_ProcessCreate
3520 (serverHandle, "salvage-tmp", BOS_PROCESS_CRON, command, "now", 0,
3522 goto fail_bos_Salvage;
3526 bos_ProcessInfoGet(serverHandle, "salvage-tmp", &procType,
3527 &procInfo, &tst))) {
3531 if (tst != BZNOENT) {
3532 goto fail_bos_Salvage;
3536 * Print out the salvage log if required by the user
3541 logData = (char *)malloc(INITIAL_LOG_LEN);
3544 goto fail_bos_Salvage;
3548 (serverHandle, AFSDIR_CANONICAL_SERVER_SLVGLOG_FILEPATH,
3549 &logLen, logData, &tst)) {
3550 if (logLen > INITIAL_LOG_LEN) {
3551 logData = (char *)realloc(logData, (logLen + (logLen / 10)));
3552 if (logData == NULL) {
3554 goto fail_bos_Salvage;
3557 goto fail_bos_Salvage;
3560 fprintf(log, "SalvageLog:\n%s", logData);
3564 * Restart the fileserver if we had stopped it previously
3567 if (try_to_stop_fileserver) {
3568 try_to_stop_fileserver = 0;
3569 if (!bos_ProcessExecutionStateSetTemporary
3570 (serverHandle, "fs", BOS_PROCESS_RUNNING, &tst)) {
3571 goto fail_bos_Salvage;
3582 if (logData != NULL) {
3586 if (try_to_stop_fileserver) {
3587 bos_ProcessExecutionStateSetTemporary(serverHandle, "fs",
3588 BOS_PROCESS_RUNNING, 0);