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 <rx/rxstat.h>
19 #include "afs_bosAdmin.h"
20 #include "../adminutil/afs_AdminInternal.h"
21 #include <afs/afs_AdminErrors.h>
22 #include <afs/afs_utilAdmin.h>
23 #include <afs/bosint.h>
24 #include <afs/bnode.h>
25 #include <afs/ktime.h>
26 #include <afs/dirpath.h>
28 #include <sys/types.h>
38 typedef struct bos_server {
41 struct rx_connection *server;
42 struct rx_connection *server_encrypt;
43 struct rx_connection *server_stats;
45 } bos_server_t, *bos_server_p;
48 * isValidServerHandle - validate a bos_server_p.
52 * IN serverHandle - the handle to validate
56 * No locks are obtained or released by this function
60 * Returns != 0 upon successful completion.
64 isValidServerHandle(const bos_server_p serverHandle, afs_status_p st)
69 if (serverHandle == NULL) {
70 tst = ADMBOSSERVERHANDLENULL;
71 goto fail_IsValidServerHandle;
74 if ((serverHandle->begin_magic != BEGIN_MAGIC)
75 || (serverHandle->end_magic != END_MAGIC)) {
76 tst = ADMBOSSERVERHANDLEBADMAGIC;
77 goto fail_IsValidServerHandle;
80 if (serverHandle->is_valid == 0) {
81 tst = ADMBOSSERVERHANDLEINVALID;
82 goto fail_IsValidServerHandle;
85 if (serverHandle->server == NULL) {
86 tst = ADMBOSSERVERHANDLENOSERVER;
87 goto fail_IsValidServerHandle;
90 if (serverHandle->server_encrypt == NULL) {
91 tst = ADMBOSSERVERHANDLENOSERVER;
92 goto fail_IsValidServerHandle;
96 fail_IsValidServerHandle:
105 * IsValidCellHandle - verify that a cell handle can be used to make bos
110 * IN cellHandle - the cellHandle to be validated.
114 * No locks are obtained or released by this function
118 * Returns != 0 upon successful completion.
122 IsValidCellHandle(afs_cell_handle_p cellHandle, afs_status_p st)
125 afs_status_t tst = 0;
127 if (!CellHandleIsValid((void *)cellHandle, &tst)) {
128 goto fail_IsValidCellHandle;
131 if (cellHandle->tokens == NULL) {
132 tst = ADMBOSCELLHANDLENOTOKENS;
133 goto fail_IsValidCellHandle;
137 fail_IsValidCellHandle:
146 * bos_ServerOpen - open a bos server for work.
150 * IN cellHandle - a previously opened cellHandle.
152 * IN serverName - the name of the machine that houses the bosserver of
155 * OUT serverHandleP - upon successful completion, this void pointer
156 * will point to a valid server handle for use in future operations.
160 * No locks are obtained or released by this function
164 * Returns != 0 upon successful completion.
168 bos_ServerOpen(const void *cellHandle, const char *serverName,
169 void **serverHandleP, afs_status_p st)
172 afs_status_t tst = 0;
173 afs_cell_handle_p c_handle = (afs_cell_handle_p) cellHandle;
174 bos_server_p bos_server = (bos_server_p) malloc(sizeof(bos_server_t));
178 * Validate parameters
181 if (!IsValidCellHandle(c_handle, &tst)) {
182 goto fail_bos_ServerOpen;
185 if ((serverName == NULL) || (*serverName == 0)) {
186 tst = ADMBOSSERVERNAMENULL;
187 goto fail_bos_ServerOpen;
190 if (serverHandleP == NULL) {
191 tst = ADMBOSSERVERHANDLEPNULL;
192 goto fail_bos_ServerOpen;
195 if (util_AdminServerAddressGetFromName(serverName, &serverAddress, &tst)
197 goto fail_bos_ServerOpen;
200 if (bos_server == NULL) {
202 goto fail_bos_ServerOpen;
206 rx_GetCachedConnection(htonl(serverAddress), htons(AFSCONF_NANNYPORT),
208 c_handle->tokens->afs_sc[c_handle->tokens->
210 c_handle->tokens->sc_index);
212 bos_server->server_encrypt =
213 rx_GetCachedConnection(htonl(serverAddress), htons(AFSCONF_NANNYPORT),
215 c_handle->tokens->afs_encrypt_sc[c_handle->
218 c_handle->tokens->sc_index);
220 bos_server->server_stats =
221 rx_GetCachedConnection(htonl(serverAddress), htons(AFSCONF_NANNYPORT),
223 c_handle->tokens->afs_sc[c_handle->tokens->
225 c_handle->tokens->sc_index);
227 if ((bos_server->server == NULL) || (bos_server->server_encrypt == NULL)) {
228 tst = ADMBOSSERVERNOCONNECTION;
229 goto fail_bos_ServerOpen;
232 bos_server->begin_magic = BEGIN_MAGIC;
233 bos_server->is_valid = 1;
234 bos_server->end_magic = END_MAGIC;
236 *serverHandleP = (void *)bos_server;
241 if ((rc == 0) && (bos_server != NULL)) {
242 if (bos_server->server) {
243 rx_ReleaseCachedConnection(bos_server->server);
245 if (bos_server->server_encrypt) {
246 rx_ReleaseCachedConnection(bos_server->server_encrypt);
258 * bos_ServerClose - close a bos server handle
262 * IN serverHandle - a bos server handle previously returned by bos_ServerOpen
266 * No locks are obtained or released by this function
270 * Returns != 0 upon successful completion.
274 bos_ServerClose(const void *serverHandle, afs_status_p st)
277 afs_status_t tst = 0;
278 bos_server_p b_handle = (bos_server_p) serverHandle;
280 if (isValidServerHandle(b_handle, &tst)) {
281 rx_ReleaseCachedConnection(b_handle->server);
282 b_handle->is_valid = 0;
294 * bos_ProcessCreate - create a new process to run at a bos server.
298 * IN serverHandle - a previously opened serverHandle.
300 * IN processName - the name of the process to create.
302 * IN processType - the type of process to create.
304 * IN process - the path to the process binary at the bos server.
306 * IN cronTime - the time specification for cron processes.
308 * IN notifier - the path to the notifier binary at the bos server.
312 * No locks are obtained or released by this function
316 * Returns != 0 upon successful completion.
320 * CAUTION - this list must match bos_ProcessType_t definition
323 static char *processTypes[] = { "simple", "fs", "cron", 0 };
326 bos_ProcessCreate(const void *serverHandle, char *processName,
327 bos_ProcessType_t processType, char *process,
328 char *cronTime, char *notifier, afs_status_p st)
331 afs_status_t tst = 0;
332 bos_server_p b_handle = (bos_server_p) serverHandle;
334 if (!isValidServerHandle(b_handle, &tst)) {
335 goto fail_bos_ProcessCreate;
338 if (processType == BOS_PROCESS_FS) {
339 tst = ADMBOSPROCESSCREATEBADTYPE;
340 goto fail_bos_ProcessCreate;
343 if ((processName == NULL) || (*processName == 0)) {
344 tst = ADMBOSPROCESSNAMENULL;
345 goto fail_bos_ProcessCreate;
348 if ((process == NULL) || (*process == 0)) {
349 tst = ADMBOSPROCESSNULL;
350 goto fail_bos_ProcessCreate;
353 if ((processType == BOS_PROCESS_CRON) && (cronTime == NULL)) {
354 tst = ADMBOSCRONTIMENULL;
355 goto fail_bos_ProcessCreate;
358 if ((processType == BOS_PROCESS_SIMPLE) && (cronTime != NULL)) {
359 tst = ADMBOSCRONTIMENOTNULL;
360 goto fail_bos_ProcessCreate;
364 BOZO_CreateBnode(b_handle->server, processTypes[processType],
365 processName, process, (cronTime) ? cronTime : "", "",
366 "", "", (notifier) ? notifier : NONOTIFIER);
371 fail_bos_ProcessCreate:
380 * bos_FSProcessCreate - create the fs group of processes at the boserver.
384 * IN serverHandle - a previously opened serverHandle.
386 * IN processName - the name of the process to create.
388 * IN fileserverPath - the path to the fileserver binary at the bos server.
390 * IN volserverPath - the path to the volserver binary at the bos server.
392 * IN salvagerPath - the path to the salvager binary at the bos server.
394 * IN notifier - the path to the notifier binary at the bos server.
398 * No locks are obtained or released by this function
402 * Returns != 0 upon successful completion.
406 bos_FSProcessCreate(const void *serverHandle, char *processName,
407 char *fileserverPath, char *volserverPath,
408 char *salvagerPath, char *notifier,
412 afs_status_t tst = 0;
413 bos_server_p b_handle = (bos_server_p) serverHandle;
415 if (!isValidServerHandle(b_handle, &tst)) {
416 goto fail_bos_ProcessCreate;
419 if ((processName == NULL) || (*processName == 0)) {
420 tst = ADMBOSPROCESSNAMENULL;
421 goto fail_bos_ProcessCreate;
424 if ((fileserverPath == NULL) || (*fileserverPath == 0)) {
425 tst = ADMBOSFILESERVERPATHNULL;
426 goto fail_bos_ProcessCreate;
429 if ((volserverPath == NULL) || (*volserverPath == 0)) {
430 tst = ADMBOSVOLSERVERPATHNULL;
431 goto fail_bos_ProcessCreate;
434 if ((salvagerPath == NULL) || (*salvagerPath == 0)) {
435 tst = ADMBOSSALVAGERPATHNULL;
436 goto fail_bos_ProcessCreate;
440 BOZO_CreateBnode(b_handle->server, processTypes[BOS_PROCESS_FS],
441 processName, fileserverPath, volserverPath,
442 salvagerPath, "", "",
443 (notifier) ? notifier : NONOTIFIER);
448 fail_bos_ProcessCreate:
457 * bos_ProcessDelete - delete an existing process at a bos server.
461 * IN serverHandle - a previously opened serverHandle.
463 * IN processName - the name of the process to delete.
467 * No locks are obtained or released by this function
471 * Returns != 0 upon successful completion.
475 bos_ProcessDelete(const void *serverHandle, char *processName,
479 afs_status_t tst = 0;
480 bos_server_p b_handle = (bos_server_p) serverHandle;
482 if (!isValidServerHandle(b_handle, &tst)) {
483 goto fail_bos_ProcessDelete;
486 if ((processName == NULL) || (*processName == 0)) {
487 tst = ADMBOSPROCESSNAMENULL;
488 goto fail_bos_ProcessDelete;
491 tst = BOZO_DeleteBnode(b_handle->server, processName);
497 fail_bos_ProcessDelete:
506 * bos_ProcessExecutionStateGet - get the current execution state of a
511 * IN serverHandle - a previously opened serverHandle.
513 * IN processName - the name of the process to retrieve.
515 * OUT processStatusP - upon successful completion the process execution state
517 * OUT auxiliaryProcessStatus - set to point to aux proc status if available.
518 * Pass a pointer to an char array at least BOS_MAX_NAME_LEN long.
522 * No locks are obtained or released by this function
526 * Returns != 0 upon successful completion.
530 bos_ProcessExecutionStateGet(const void *serverHandle,
532 bos_ProcessExecutionState_p processStatusP,
533 char *auxiliaryProcessStatus, afs_status_p st)
536 afs_status_t tst = 0;
537 bos_server_p b_handle = (bos_server_p) serverHandle;
540 if (!isValidServerHandle(b_handle, &tst)) {
541 goto fail_bos_ProcessExecutionStateGet;
544 if ((processName == NULL) || (*processName == 0)) {
545 tst = ADMBOSPROCESSNAMENULL;
546 goto fail_bos_ProcessExecutionStateGet;
549 if (processStatusP == NULL) {
550 tst = ADMBOSPROCESSSTATUSPNULL;
551 goto fail_bos_ProcessExecutionStateGet;
554 if (auxiliaryProcessStatus == NULL) {
555 tst = ADMBOSAUXILIARYPROCESSSTATUSNULL;
556 goto fail_bos_ProcessExecutionStateGet;
560 BOZO_GetStatus(b_handle->server, processName, &state,
561 &auxiliaryProcessStatus);
564 goto fail_bos_ProcessExecutionStateGet;
567 *processStatusP = (bos_ProcessExecutionState_t) state;
570 fail_bos_ProcessExecutionStateGet:
579 * SetExecutionState - set the execution state of a process
583 * IN serverHandle - a previously opened serverHandle.
585 * IN processName - the name of the process to modify.
587 * IN processStatus - the new process state.
589 * IN func - the function to call to set the status.
593 * No locks are obtained or released by this function
597 * Returns != 0 upon successful completion.
601 SetExecutionState(const void *serverHandle, const char *processName,
602 const bos_ProcessExecutionState_t processStatus,
603 int (*func) (struct rx_connection *, char *,
604 afs_int32), afs_status_p st)
607 afs_status_t tst = 0;
608 bos_server_p b_handle = (bos_server_p) serverHandle;
611 if (!isValidServerHandle(b_handle, &tst)) {
612 goto fail_SetExecutionState;
615 if ((processName == NULL) || (*processName == 0)) {
616 tst = ADMBOSPROCESSNAMENULL;
617 goto fail_SetExecutionState;
620 if ((processStatus != BOS_PROCESS_STOPPED)
621 && (processStatus != BOS_PROCESS_RUNNING)) {
622 tst = ADMBOSPROCESSSTATUSSET;
623 goto fail_SetExecutionState;
626 state = (afs_int32) processStatus;
628 tst = func(b_handle->server, (char *)processName, state);
634 fail_SetExecutionState:
643 * bos_ProcessExecutionStateSet - set the execution state of a process
647 * IN serverHandle - a previously opened serverHandle.
649 * IN processName - the name of the process to modify.
651 * IN processStatus - the new process state.
655 * No locks are obtained or released by this function
659 * Returns != 0 upon successful completion.
663 bos_ProcessExecutionStateSet(const void *serverHandle,
664 const char *processName,
665 const bos_ProcessExecutionState_t processStatus,
668 return SetExecutionState(serverHandle, processName, processStatus,
673 * bos_ProcessExecutionStateSetTemporary - set the execution state of a process
678 * IN serverHandle - a previously opened serverHandle.
680 * IN processName - the name of the process to modify.
682 * IN processStatus - the new process state.
686 * No locks are obtained or released by this function
690 * Returns != 0 upon successful completion.
694 bos_ProcessExecutionStateSetTemporary(const void *serverHandle,
696 bos_ProcessExecutionState_t
697 processStatus, afs_status_p st)
699 return SetExecutionState(serverHandle, processName, processStatus,
700 BOZO_SetTStatus, st);
704 * The iterator functions and data for the process name retrieval functions
707 typedef struct process_name_get {
709 struct rx_connection *server;
710 char process[CACHED_ITEMS][BOS_MAX_NAME_LEN];
711 } process_name_get_t, *process_name_get_p;
714 GetProcessNameRPC(void *rpc_specific, int slot, int *last_item,
715 int *last_item_contains_data, afs_status_p st)
718 afs_status_t tst = 0;
719 process_name_get_p proc = (process_name_get_p) rpc_specific;
720 char *ptr = (char *)&proc->process[slot];
722 tst = BOZO_EnumerateInstance(proc->server, proc->next++, &ptr);
726 } else if (tst == BZDOM) {
730 *last_item_contains_data = 0;
740 GetProcessNameFromCache(void *rpc_specific, int slot, void *dest,
744 afs_status_t tst = 0;
745 process_name_get_p proc = (process_name_get_p) rpc_specific;
747 strcpy((char *)dest, (char *)&proc->process[slot]);
757 * bos_ProcessNameGetBegin - begin iterating over the list of processes
758 * at a particular bos server.
762 * IN serverHandle - a previously opened serverHandle.
764 * OUT iter - an iterator that can be passed to bos_ProcessNameGetNext
765 * to retrieve the process names.
769 * No locks are obtained or released by this function
773 * Returns != 0 upon successful completion.
778 bos_ProcessNameGetBegin(const void *serverHandle, void **iterationIdP,
782 afs_status_t tst = 0;
783 bos_server_p b_handle = (bos_server_p) serverHandle;
784 afs_admin_iterator_p iter =
785 (afs_admin_iterator_p) malloc(sizeof(afs_admin_iterator_t));
786 process_name_get_p proc =
787 (process_name_get_p) malloc(sizeof(process_name_get_t));
789 if (!isValidServerHandle(b_handle, &tst)) {
790 goto fail_bos_ProcessNameGetBegin;
793 if (iterationIdP == NULL) {
794 tst = ADMITERATIONIDPNULL;
795 goto fail_bos_ProcessNameGetBegin;
798 if ((iter == NULL) || (proc == NULL)) {
800 goto fail_bos_ProcessNameGetBegin;
804 proc->server = b_handle->server;
807 (iter, (void *)proc, GetProcessNameRPC, GetProcessNameFromCache, NULL,
809 *iterationIdP = (void *)iter;
811 goto fail_bos_ProcessNameGetBegin;
815 fail_bos_ProcessNameGetBegin:
833 * bos_ProcessNameGetNext - retrieve the next process name from the bos server.
837 * IN iterationId - an iterator previously returned by bos_ProcessNameGetBegin
839 * OUT processName - upon successful completion contains the next process name
840 * retrieved from the server.
844 * No locks are obtained or released by this function
848 * Returns != 0 upon successful completion.
853 bos_ProcessNameGetNext(const void *iterationId, char *processName,
857 afs_status_t tst = 0;
858 afs_admin_iterator_p iter = (afs_admin_iterator_p) iterationId;
860 if (processName == NULL) {
861 tst = ADMBOSPROCESSNAMENULL;
862 goto fail_bos_ProcessNameGetNext;
865 if (iterationId == NULL) {
866 tst = ADMITERATIONIDPNULL;
867 goto fail_bos_ProcessNameGetNext;
870 rc = IteratorNext(iter, (void *)processName, &tst);
872 fail_bos_ProcessNameGetNext:
881 * bos_ProcessNameGetDone - finish using a process name iterator.
885 * IN iterationId - an iterator previously returned by bos_ProcessNameGetBegin
889 * No locks are obtained or released by this function
893 * Returns != 0 upon successful completion.
898 bos_ProcessNameGetDone(const void *iterationId, afs_status_p st)
901 afs_status_t tst = 0;
902 afs_admin_iterator_p iter = (afs_admin_iterator_p) iterationId;
904 if (iterationId == NULL) {
905 tst = ADMITERATIONIDPNULL;
906 goto fail_bos_ProcessNameGetDone;
909 rc = IteratorDone(iter, &tst);
911 fail_bos_ProcessNameGetDone:
920 * bos_ProcessInfoGet - get information about a single process
924 * IN serverHandle - a previously opened serverHandle.
926 * IN processName - the process of interest.
928 * OUT processTypeP - upon successful completion contains the process type
930 * OUT processInfoP - upon successful completion contains the process info
934 * No locks are obtained or released by this function
938 * Returns != 0 upon successful completion.
943 bos_ProcessInfoGet(const void *serverHandle, char *processName,
944 bos_ProcessType_p processTypeP,
945 bos_ProcessInfo_p processInfoP, afs_status_p st)
948 afs_status_t tst = 0;
949 bos_server_p b_handle = (bos_server_p) serverHandle;
950 char type[BOS_MAX_NAME_LEN];
952 struct bozo_status status;
955 if (!isValidServerHandle(b_handle, &tst)) {
956 goto fail_bos_ProcessInfoGet;
959 if ((processName == NULL) || (*processName == 0)) {
960 tst = ADMBOSPROCESSNAMENULL;
961 goto fail_bos_ProcessInfoGet;
964 if (processTypeP == NULL) {
965 tst = ADMBOSPROCESSTYPEPNULL;
966 goto fail_bos_ProcessInfoGet;
969 if (processInfoP == NULL) {
970 tst = ADMBOSPROCESSINFOPNULL;
971 goto fail_bos_ProcessInfoGet;
974 tst = BOZO_GetInstanceInfo(b_handle->server, processName, &ptr, &status);
977 goto fail_bos_ProcessInfoGet;
981 for (i = 0; (processTypes[i] != NULL); i++) {
982 if (!strcmp(processTypes[i], type)) {
983 *processTypeP = (bos_ProcessType_t) i;
988 if (processTypes[i] == NULL) {
989 tst = ADMBOSINVALIDPROCESSTYPE;
990 goto fail_bos_ProcessInfoGet;
993 processInfoP->processGoal = (bos_ProcessExecutionState_t) status.goal;
994 processInfoP->processStartTime = status.procStartTime;
995 processInfoP->numberProcessStarts = status.procStarts;
996 processInfoP->processExitTime = status.lastAnyExit;
997 processInfoP->processExitErrorTime = status.lastErrorExit;
998 processInfoP->processErrorCode = status.errorCode;
999 processInfoP->processErrorSignal = status.errorSignal;
1000 processInfoP->state = BOS_PROCESS_OK;
1002 if (status.flags & BOZO_ERRORSTOP) {
1003 processInfoP->state |= BOS_PROCESS_TOO_MANY_ERRORS;
1005 if (status.flags & BOZO_HASCORE) {
1006 processInfoP->state |= BOS_PROCESS_CORE_DUMPED;
1008 if (status.flags & BOZO_BADDIRACCESS) {
1009 processInfoP->state |= BOS_PROCESS_BAD_FILE_ACCESS;
1013 fail_bos_ProcessInfoGet:
1022 * The iterator functions and data for the parameter retrieval functions
1025 typedef struct param_get {
1027 struct rx_connection *server;
1028 char processName[BOS_MAX_NAME_LEN];
1029 char param[CACHED_ITEMS][BOS_MAX_NAME_LEN];
1030 } param_get_t, *param_get_p;
1033 GetParameterRPC(void *rpc_specific, int slot, int *last_item,
1034 int *last_item_contains_data, afs_status_p st)
1037 afs_status_t tst = 0;
1038 param_get_p param = (param_get_p) rpc_specific;
1039 char *ptr = (char *)¶m->param[slot];
1042 BOZO_GetInstanceParm(param->server, param->processName, param->next++,
1047 } else if (tst == BZDOM) {
1051 *last_item_contains_data = 0;
1061 GetParameterFromCache(void *rpc_specific, int slot, void *dest,
1065 afs_status_t tst = 0;
1066 param_get_p param = (param_get_p) rpc_specific;
1068 strcpy((char *)dest, (char *)¶m->param[slot]);
1078 * bos_ProcessParameterGetBegin - begin iterating over the parameters
1079 * of a particular process.
1083 * IN serverHandle - a previously opened serverHandle.
1085 * IN processName - the process whose parameters are returned.
1087 * OUT iter - an iterator that can be passed to bos_ProcessParameterGetNext
1088 * to retrieve the parameters.
1092 * No locks are obtained or released by this function
1096 * Returns != 0 upon successful completion.
1101 bos_ProcessParameterGetBegin(const void *serverHandle,
1102 const char *processName, void **iterationIdP,
1106 afs_status_t tst = 0;
1107 bos_server_p b_handle = (bos_server_p) serverHandle;
1108 afs_admin_iterator_p iter =
1109 (afs_admin_iterator_p) malloc(sizeof(afs_admin_iterator_t));
1110 param_get_p param = (param_get_p) malloc(sizeof(param_get_t));
1112 if (!isValidServerHandle(b_handle, &tst)) {
1113 goto fail_bos_ProcessParameterGetBegin;
1116 if ((processName == NULL) || (*processName == 0)) {
1117 tst = ADMBOSPROCESSNAMENULL;
1118 goto fail_bos_ProcessParameterGetBegin;
1121 if (iterationIdP == NULL) {
1122 tst = ADMITERATIONIDPNULL;
1123 goto fail_bos_ProcessParameterGetBegin;
1126 if ((iter == NULL) || (param == NULL)) {
1128 goto fail_bos_ProcessParameterGetBegin;
1132 param->server = b_handle->server;
1133 strcpy(param->processName, processName);
1136 (iter, (void *)param, GetParameterRPC, GetParameterFromCache, NULL,
1138 *iterationIdP = (void *)iter;
1140 goto fail_bos_ProcessParameterGetBegin;
1144 fail_bos_ProcessParameterGetBegin:
1150 if (param != NULL) {
1162 * bos_ProcessParameterGetNext - retrieve the next parameter
1163 * from the bos server.
1167 * IN iterationId - an iterator previously returned by
1168 * bos_ProcessParameterGetBegin
1170 * OUT parameter - upon successful completion contains the next parameter
1171 * retrieved from the server.
1175 * No locks are obtained or released by this function
1179 * Returns != 0 upon successful completion.
1184 bos_ProcessParameterGetNext(const void *iterationId, char *parameter,
1188 afs_status_t tst = 0;
1189 afs_admin_iterator_p iter = (afs_admin_iterator_p) iterationId;
1191 if (iterationId == NULL) {
1192 tst = ADMITERATIONIDPNULL;
1193 goto fail_bos_ProcessParameterGetNext;
1196 if (parameter == NULL) {
1197 tst = ADMBOSPARAMETERNULL;
1198 goto fail_bos_ProcessParameterGetNext;
1201 rc = IteratorNext(iter, (void *)parameter, &tst);
1203 fail_bos_ProcessParameterGetNext:
1212 * bos_ProcessParameterGetDone - finish using a process name iterator.
1216 * IN iterationId - an iterator previously returned by
1217 * bos_ProcessParameterGetBegin
1221 * No locks are obtained or released by this function
1225 * Returns != 0 upon successful completion.
1230 bos_ProcessParameterGetDone(const void *iterationId, afs_status_p st)
1233 afs_status_t tst = 0;
1234 afs_admin_iterator_p iter = (afs_admin_iterator_p) iterationId;
1236 if (iterationId == NULL) {
1237 tst = ADMITERATIONIDPNULL;
1238 goto fail_bos_ProcessParameterGetDone;
1241 rc = IteratorDone(iter, &tst);
1243 fail_bos_ProcessParameterGetDone:
1252 * bos_ProcessNotifierGet - retrieve the notifier associated with a
1257 * IN serverHandle - a previously opened serverHandle.
1259 * IN processName - the process whose notifier we are retrieving.
1261 * OUT notifier - upon successful completion contains the notifier.
1265 * No locks are obtained or released by this function
1269 * Returns != 0 upon successful completion.
1274 bos_ProcessNotifierGet(const void *serverHandle, const char *processName,
1275 char *notifier, afs_status_p st)
1278 afs_status_t tst = 0;
1279 bos_server_p b_handle = (bos_server_p) serverHandle;
1281 if (!isValidServerHandle(b_handle, &tst)) {
1282 goto fail_bos_ProcessNotifierGet;
1285 if ((processName == NULL) || (*processName == 0)) {
1286 tst = ADMBOSPROCESSNAMENULL;
1287 goto fail_bos_ProcessNotifierGet;
1290 if (notifier == NULL) {
1291 tst = ADMBOSNOTIFIERNULL;
1292 goto fail_bos_ProcessNotifierGet;
1295 tst = BOZO_GetInstanceParm(b_handle->server, (char *)processName,
1302 fail_bos_ProcessNotifierGet:
1311 * bos_ProcessRestart - restart a particular process.
1315 * IN serverHandle - a previously opened serverHandle.
1317 * IN processName - the process to restart
1321 * No locks are obtained or released by this function
1325 * Returns != 0 upon successful completion.
1330 bos_ProcessRestart(const void *serverHandle, const char *processName,
1334 afs_status_t tst = 0;
1335 bos_server_p b_handle = (bos_server_p) serverHandle;
1337 if (!isValidServerHandle(b_handle, &tst)) {
1338 goto fail_bos_ProcessRestart;
1341 if ((processName == NULL) || (*processName == 0)) {
1342 tst = ADMBOSPROCESSNAMENULL;
1343 goto fail_bos_ProcessRestart;
1346 tst = BOZO_Restart(b_handle->server, (char *)processName);
1352 fail_bos_ProcessRestart:
1361 * bos_ProcessAllStop - stop all running processes at a server.
1365 * IN serverHandle - a previously opened serverHandle.
1369 * No locks are obtained or released by this function
1373 * Returns != 0 upon successful completion.
1378 bos_ProcessAllStop(const void *serverHandle, afs_status_p st)
1381 afs_status_t tst = 0;
1382 bos_server_p b_handle = (bos_server_p) serverHandle;
1384 if (!isValidServerHandle(b_handle, &tst)) {
1385 goto fail_bos_ProcessAllStop;
1388 tst = BOZO_ShutdownAll(b_handle->server);
1394 fail_bos_ProcessAllStop:
1403 * bos_ProcessAllStart - start all processes that should be running at a
1408 * IN serverHandle - a previously opened serverHandle.
1412 * No locks are obtained or released by this function
1416 * Returns != 0 upon successful completion.
1421 bos_ProcessAllStart(const void *serverHandle, afs_status_p st)
1424 afs_status_t tst = 0;
1425 bos_server_p b_handle = (bos_server_p) serverHandle;
1427 if (!isValidServerHandle(b_handle, &tst)) {
1428 goto fail_bos_ProcessAllStart;
1431 tst = BOZO_StartupAll(b_handle->server);
1437 fail_bos_ProcessAllStart:
1446 * bos_ProcessAllWaitStop - stop all processes, and block until they have
1451 * IN serverHandle - a previously opened serverHandle.
1455 * No locks are obtained or released by this function
1459 * Returns != 0 upon successful completion.
1464 bos_ProcessAllWaitStop(const void *serverHandle, afs_status_p st)
1467 afs_status_t tst = 0;
1468 bos_server_p b_handle = (bos_server_p) serverHandle;
1470 if (!isValidServerHandle(b_handle, &tst)) {
1471 goto fail_bos_ProcessAllWaitStop;
1474 if (!bos_ProcessAllStop(serverHandle, &tst)) {
1475 goto fail_bos_ProcessAllWaitStop;
1478 tst = BOZO_WaitAll(b_handle->server);
1484 fail_bos_ProcessAllWaitStop:
1493 * bos_ProcessAllWaitTransition - block until all processes at the bosserver
1494 * have reached their desired state.
1498 * IN serverHandle - a previously opened serverHandle.
1502 * No locks are obtained or released by this function
1506 * Returns != 0 upon successful completion.
1511 bos_ProcessAllWaitTransition(const void *serverHandle, afs_status_p st)
1514 afs_status_t tst = 0;
1515 bos_server_p b_handle = (bos_server_p) serverHandle;
1517 if (!isValidServerHandle(b_handle, &tst)) {
1518 goto fail_bos_ProcessAllWaitTransition;
1521 tst = BOZO_WaitAll(b_handle->server);
1527 fail_bos_ProcessAllWaitTransition:
1536 * bos_ProcessAllStopAndRestart - stop all the running processes, restart
1537 * them, and optionally restart the bosserver itself.
1542 * IN serverHandle - a previously opened serverHandle.
1544 * IN restartBosServer - flag to indicate whether to restart bosserver.
1548 * No locks are obtained or released by this function
1552 * Returns != 0 upon successful completion.
1557 bos_ProcessAllStopAndRestart(const void *serverHandle,
1558 bos_RestartBosServer_t restartBosServer,
1562 afs_status_t tst = 0;
1563 bos_server_p b_handle = (bos_server_p) serverHandle;
1565 if (!isValidServerHandle(b_handle, &tst)) {
1566 goto fail_bos_ProcessAllStopAndRestart;
1569 if (restartBosServer == BOS_RESTART_BOS_SERVER) {
1570 tst = BOZO_ReBozo(b_handle->server);
1572 goto fail_bos_ProcessAllStopAndRestart;
1576 tst = BOZO_RestartAll(b_handle->server);
1582 fail_bos_ProcessAllStopAndRestart:
1591 * bos_AdminCreate - create a new admin.
1595 * IN serverHandle - a previously opened serverHandle.
1597 * IN adminName - the new admin name.
1601 * No locks are obtained or released by this function
1605 * Returns != 0 upon successful completion.
1610 bos_AdminCreate(const void *serverHandle, const char *adminName,
1614 afs_status_t tst = 0;
1615 bos_server_p b_handle = (bos_server_p) serverHandle;
1617 if (!isValidServerHandle(b_handle, &tst)) {
1618 goto fail_bos_AdminCreate;
1621 if ((adminName == NULL) || (*adminName == 0)) {
1622 tst = ADMBOSADMINNAMENULL;
1623 goto fail_bos_AdminCreate;
1626 tst = BOZO_AddSUser(b_handle->server, (char *)adminName);
1632 fail_bos_AdminCreate:
1641 * bos_AdminDelete - delete a new admin.
1645 * IN serverHandle - a previously opened serverHandle.
1647 * IN adminName - the admin name.
1651 * No locks are obtained or released by this function
1655 * Returns != 0 upon successful completion.
1660 bos_AdminDelete(const void *serverHandle, const char *adminName,
1664 afs_status_t tst = 0;
1665 bos_server_p b_handle = (bos_server_p) serverHandle;
1667 if (!isValidServerHandle(b_handle, &tst)) {
1668 goto fail_bos_AdminDelete;
1671 if ((adminName == NULL) || (*adminName == 0)) {
1672 tst = ADMBOSADMINNAMENULL;
1673 goto fail_bos_AdminDelete;
1676 tst = BOZO_DeleteSUser(b_handle->server, (char *)adminName);
1682 fail_bos_AdminDelete:
1691 * The iterator functions and data for the admin retrieval functions
1694 typedef struct admin_get {
1696 struct rx_connection *server;
1697 char admin[CACHED_ITEMS][BOS_MAX_NAME_LEN];
1698 } admin_get_t, *admin_get_p;
1701 GetAdminRPC(void *rpc_specific, int slot, int *last_item,
1702 int *last_item_contains_data, afs_status_p st)
1705 afs_status_t tst = 0;
1706 admin_get_p admin = (admin_get_p) rpc_specific;
1707 char *ptr = (char *)&admin->admin[slot];
1709 tst = BOZO_ListSUsers(admin->server, admin->next++, &ptr);
1712 * There's no way to tell the difference between an rpc failure
1713 * and the end of the list, so we assume that any error means the
1720 *last_item_contains_data = 0;
1731 GetAdminFromCache(void *rpc_specific, int slot, void *dest, afs_status_p st)
1734 afs_status_t tst = 0;
1735 admin_get_p admin = (admin_get_p) rpc_specific;
1737 strcpy((char *)dest, (char *)&admin->admin[slot]);
1747 * bos_AdminGetBegin - begin iterating over the administrators.
1751 * IN serverHandle - a previously opened serverHandle.
1753 * OUT iter - an iterator that can be passed to bos_AdminGetBegin
1754 * to retrieve the administrators.
1758 * No locks are obtained or released by this function
1762 * Returns != 0 upon successful completion.
1767 bos_AdminGetBegin(const void *serverHandle, void **iterationIdP,
1771 afs_status_t tst = 0;
1772 bos_server_p b_handle = (bos_server_p) serverHandle;
1773 afs_admin_iterator_p iter =
1774 (afs_admin_iterator_p) malloc(sizeof(afs_admin_iterator_t));
1775 admin_get_p admin = (admin_get_p) malloc(sizeof(admin_get_t));
1777 if (!isValidServerHandle(b_handle, &tst)) {
1778 goto fail_bos_AdminGetBegin;
1781 if (iterationIdP == NULL) {
1782 tst = ADMITERATIONIDPNULL;
1783 goto fail_bos_AdminGetBegin;
1786 if ((iter == NULL) || (admin == NULL)) {
1788 goto fail_bos_AdminGetBegin;
1792 admin->server = b_handle->server;
1795 (iter, (void *)admin, GetAdminRPC, GetAdminFromCache, NULL, NULL,
1797 *iterationIdP = (void *)iter;
1801 fail_bos_AdminGetBegin:
1807 if (admin != NULL) {
1819 * bos_AdminGetNext - retrieve the next administrator
1820 * from the bos server.
1824 * IN iterationId - an iterator previously returned by
1827 * OUT adminName - upon successful completion contains the next administrator
1828 * retrieved from the server.
1832 * No locks are obtained or released by this function
1836 * Returns != 0 upon successful completion.
1841 bos_AdminGetNext(const void *iterationId, char *adminName, afs_status_p st)
1844 afs_status_t tst = 0;
1845 afs_admin_iterator_p iter = (afs_admin_iterator_p) iterationId;
1847 if (iterationId == NULL) {
1848 tst = ADMITERATIONIDPNULL;
1849 goto fail_bos_AdminGetNext;
1852 if (adminName == NULL) {
1853 tst = ADMBOSADMINNAMENULL;
1854 goto fail_bos_AdminGetNext;
1857 rc = IteratorNext(iter, (void *)adminName, &tst);
1859 fail_bos_AdminGetNext:
1868 * bos_AdminGetDone - finish using a administrator iterator.
1872 * IN iterationId - an iterator previously returned by
1877 * No locks are obtained or released by this function
1881 * Returns != 0 upon successful completion.
1886 bos_AdminGetDone(const void *iterationId, afs_status_p st)
1889 afs_status_t tst = 0;
1890 afs_admin_iterator_p iter = (afs_admin_iterator_p) iterationId;
1892 if (iterationId == NULL) {
1893 tst = ADMITERATIONIDPNULL;
1894 goto fail_bos_AdminGetDone;
1897 rc = IteratorDone(iter, &tst);
1899 fail_bos_AdminGetDone:
1908 * bos_KeyCreate - add a new key to the keyfile.
1912 * IN serverHandle - a previously opened serverHandle.
1914 * IN keyVersionNumber - the key version number.
1916 * IN key - the new key.
1920 * No locks are obtained or released by this function
1924 * Returns != 0 upon successful completion.
1929 bos_KeyCreate(const void *serverHandle, int keyVersionNumber,
1930 const kas_encryptionKey_p key, afs_status_p st)
1933 afs_status_t tst = 0;
1934 bos_server_p b_handle = (bos_server_p) serverHandle;
1936 if (!isValidServerHandle(b_handle, &tst)) {
1937 goto fail_bos_KeyCreate;
1941 tst = ADMBOSKEYNULL;
1942 goto fail_bos_KeyCreate;
1945 tst = BOZO_AddKey(b_handle->server_encrypt, keyVersionNumber, kas_to_bozoptr(key));
1960 * bos_KeyDelete - delete an existing key from the keyfile.
1964 * IN serverHandle - a previously opened serverHandle.
1966 * IN keyVersionNumber - the key version number.
1970 * No locks are obtained or released by this function
1974 * Returns != 0 upon successful completion.
1979 bos_KeyDelete(const void *serverHandle, int keyVersionNumber, afs_status_p st)
1982 afs_status_t tst = 0;
1983 bos_server_p b_handle = (bos_server_p) serverHandle;
1985 if (!isValidServerHandle(b_handle, &tst)) {
1986 goto fail_bos_KeyDelete;
1989 tst = BOZO_DeleteKey(b_handle->server, keyVersionNumber);
2004 * The iterator functions and data for the key retrieval functions
2007 typedef struct key_get {
2009 struct rx_connection *server;
2010 bos_KeyInfo_t key[CACHED_ITEMS];
2011 } key_get_t, *key_get_p;
2014 GetKeyRPC(void *rpc_specific, int slot, int *last_item,
2015 int *last_item_contains_data, afs_status_p st)
2018 afs_status_t tst = 0;
2019 key_get_p key = (key_get_p) rpc_specific;
2020 struct bozo_keyInfo keyInfo;
2023 BOZO_ListKeys(key->server, key->next++,
2024 &key->key[slot].keyVersionNumber, kas_to_bozoptr(&key->key[slot].key),
2029 key->key[slot].keyStatus.lastModificationDate = keyInfo.mod_sec;
2030 key->key[slot].keyStatus.lastModificationMicroSeconds =
2032 key->key[slot].keyStatus.checkSum = keyInfo.keyCheckSum;
2034 } else if (tst == BZDOM) {
2038 *last_item_contains_data = 0;
2048 GetKeyFromCache(void *rpc_specific, int slot, void *dest, afs_status_p st)
2051 afs_status_t tst = 0;
2052 key_get_p key = (key_get_p) rpc_specific;
2054 memcpy(dest, &key->key[slot], sizeof(bos_KeyInfo_t));
2064 * bos_KeyGetBegin - begin iterating over the keys.
2068 * IN serverHandle - a previously opened serverHandle.
2070 * OUT iter - an iterator that can be passed to bos_KeyGetNext
2071 * to retrieve the keys.
2075 * No locks are obtained or released by this function
2079 * Returns != 0 upon successful completion.
2084 bos_KeyGetBegin(const void *serverHandle, void **iterationIdP,
2088 afs_status_t tst = 0;
2089 bos_server_p b_handle = (bos_server_p) serverHandle;
2090 afs_admin_iterator_p iter =
2091 (afs_admin_iterator_p) malloc(sizeof(afs_admin_iterator_t));
2092 key_get_p key = (key_get_p) malloc(sizeof(key_get_t));
2094 if (!isValidServerHandle(b_handle, &tst)) {
2095 goto fail_bos_KeyGetBegin;
2098 if (iterationIdP == NULL) {
2099 tst = ADMITERATIONIDPNULL;
2100 goto fail_bos_KeyGetBegin;
2103 if ((iter == NULL) || (key == NULL)) {
2105 goto fail_bos_KeyGetBegin;
2109 key->server = b_handle->server_encrypt;
2112 (iter, (void *)key, GetKeyRPC, GetKeyFromCache, NULL, NULL, &tst)) {
2113 *iterationIdP = (void *)iter;
2117 fail_bos_KeyGetBegin:
2135 * bos_KeyGetNext - retrieve the next key
2136 * from the bos server.
2140 * IN iterationId - an iterator previously returned by
2143 * OUT keyP - upon successful completion contains the next key
2144 * retrieved from the server.
2148 * No locks are obtained or released by this function
2152 * Returns != 0 upon successful completion.
2157 bos_KeyGetNext(const void *iterationId, bos_KeyInfo_p keyP, afs_status_p st)
2160 afs_status_t tst = 0;
2161 afs_admin_iterator_p iter = (afs_admin_iterator_p) iterationId;
2163 if (iterationId == NULL) {
2164 tst = ADMITERATIONIDPNULL;
2165 goto fail_bos_KeyGetNext;
2169 tst = ADMBOSKEYPNULL;
2170 goto fail_bos_KeyGetNext;
2173 rc = IteratorNext(iter, (void *)keyP, &tst);
2175 fail_bos_KeyGetNext:
2184 * bos_KeyGetDone - finish using a key iterator.
2188 * IN iterationId - an iterator previously returned by
2193 * No locks are obtained or released by this function
2197 * Returns != 0 upon successful completion.
2202 bos_KeyGetDone(const void *iterationId, afs_status_p st)
2205 afs_status_t tst = 0;
2206 afs_admin_iterator_p iter = (afs_admin_iterator_p) iterationId;
2208 if (iterationId == NULL) {
2209 tst = ADMITERATIONIDPNULL;
2210 goto fail_bos_KeyGetDone;
2213 rc = IteratorDone(iter, &tst);
2215 fail_bos_KeyGetDone:
2224 * bos_CellSet - set the cell name at a bos server.
2228 * IN serverHandle - a previously opened serverHandle.
2230 * IN cellName - the new cell name.
2234 * No locks are obtained or released by this function
2238 * Returns != 0 upon successful completion.
2242 bos_CellSet(const void *serverHandle, const char *cellName, afs_status_p st)
2245 afs_status_t tst = 0;
2246 bos_server_p b_handle = (bos_server_p) serverHandle;
2248 if (!isValidServerHandle(b_handle, &tst)) {
2249 goto fail_bos_CellSet;
2252 if ((cellName == NULL) || (*cellName == 0)) {
2253 tst = ADMCLIENTCELLNAMENULL;
2254 goto fail_bos_CellSet;
2257 tst = BOZO_SetCellName(b_handle->server, (char *)cellName);
2272 * bos_CellGet - get the cell name at a bos server.
2276 * IN serverHandle - a previously opened serverHandle.
2278 * OUT cellName - the cell name.
2282 * No locks are obtained or released by this function
2286 * Returns != 0 upon successful completion.
2290 bos_CellGet(const void *serverHandle, char *cellName, afs_status_p st)
2293 afs_status_t tst = 0;
2294 bos_server_p b_handle = (bos_server_p) serverHandle;
2296 if (!isValidServerHandle(b_handle, &tst)) {
2297 goto fail_bos_CellGet;
2300 if (cellName == NULL) {
2301 tst = ADMCLIENTCELLNAMENULL;
2302 goto fail_bos_CellGet;
2305 tst = BOZO_GetCellName(b_handle->server, &cellName);
2320 * bos_HostCreate - add a new host to the cell.
2324 * IN serverHandle - a previously opened serverHandle.
2326 * IN hostName - the new host.
2330 * No locks are obtained or released by this function
2334 * Returns != 0 upon successful completion.
2338 bos_HostCreate(const void *serverHandle, const char *hostName,
2342 afs_status_t tst = 0;
2343 bos_server_p b_handle = (bos_server_p) serverHandle;
2345 if (!isValidServerHandle(b_handle, &tst)) {
2346 goto fail_bos_HostCreate;
2349 if ((hostName == NULL) || (*hostName == 0)) {
2350 tst = ADMBOSHOSTNAMENULL;
2351 goto fail_bos_HostCreate;
2354 tst = BOZO_AddCellHost(b_handle->server, (char *)hostName);
2360 fail_bos_HostCreate:
2369 * bos_HostDelete - delete a host from the cell.
2373 * IN serverHandle - a previously opened serverHandle.
2375 * IN hostName - the host.
2379 * No locks are obtained or released by this function
2383 * Returns != 0 upon successful completion.
2387 bos_HostDelete(const void *serverHandle, const char *hostName,
2391 afs_status_t tst = 0;
2392 bos_server_p b_handle = (bos_server_p) serverHandle;
2394 if (!isValidServerHandle(b_handle, &tst)) {
2395 goto fail_bos_HostDelete;
2398 if ((hostName == NULL) || (*hostName == 0)) {
2399 tst = ADMBOSHOSTNAMENULL;
2400 goto fail_bos_HostDelete;
2403 tst = BOZO_DeleteCellHost(b_handle->server, (char *)hostName);
2409 fail_bos_HostDelete:
2418 * The iterator functions and data for the host retrieval functions
2421 typedef struct host_get {
2423 struct rx_connection *server;
2424 char host[CACHED_ITEMS][BOS_MAX_NAME_LEN];
2425 } host_get_t, *host_get_p;
2428 GetHostRPC(void *rpc_specific, int slot, int *last_item,
2429 int *last_item_contains_data, afs_status_p st)
2432 afs_status_t tst = 0;
2433 host_get_p host = (host_get_p) rpc_specific;
2434 char *ptr = (char *)&host->host[slot];
2436 tst = BOZO_GetCellHost(host->server, host->next++, &ptr);
2440 } else if (tst == BZDOM) {
2444 *last_item_contains_data = 0;
2454 GetHostFromCache(void *rpc_specific, int slot, void *dest, afs_status_p st)
2457 afs_status_t tst = 0;
2458 host_get_p host = (host_get_p) rpc_specific;
2460 strcpy((char *)dest, (char *)&host->host[slot]);
2470 * bos_HostGetBegin - begin iterating over the hosts in a cell
2471 * at a particular bos server.
2475 * IN serverHandle - a previously opened serverHandle.
2477 * OUT iter - an iterator that can be passed to bos_HostGetNext
2478 * to retrieve the process names.
2482 * No locks are obtained or released by this function
2486 * Returns != 0 upon successful completion.
2491 bos_HostGetBegin(const void *serverHandle, void **iterationIdP,
2495 afs_status_t tst = 0;
2496 bos_server_p b_handle = (bos_server_p) serverHandle;
2497 afs_admin_iterator_p iter =
2498 (afs_admin_iterator_p) malloc(sizeof(afs_admin_iterator_t));
2499 host_get_p host = (host_get_p) malloc(sizeof(host_get_t));
2501 if (!isValidServerHandle(b_handle, &tst)) {
2502 goto fail_bos_HostGetBegin;
2505 if (iterationIdP == NULL) {
2506 tst = ADMITERATIONIDPNULL;
2507 goto fail_bos_HostGetBegin;
2510 if ((iter == NULL) || (host == NULL)) {
2512 goto fail_bos_HostGetBegin;
2516 host->server = b_handle->server;
2519 (iter, (void *)host, GetHostRPC, GetHostFromCache, NULL, NULL,
2521 *iterationIdP = (void *)iter;
2525 fail_bos_HostGetBegin:
2543 * bos_HostGetNext - retrieve the next host
2544 * from the bos server.
2548 * IN iterationId - an iterator previously returned by
2551 * OUT hostName - upon successful completion contains the next host
2552 * retrieved from the server.
2556 * No locks are obtained or released by this function
2560 * Returns != 0 upon successful completion.
2565 bos_HostGetNext(const void *iterationId, char *hostName, afs_status_p st)
2568 afs_status_t tst = 0;
2569 afs_admin_iterator_p iter = (afs_admin_iterator_p) iterationId;
2571 if (iterationId == NULL) {
2572 tst = ADMITERATIONIDPNULL;
2573 goto fail_bos_HostGetNext;
2576 if (hostName == NULL) {
2577 tst = ADMBOSHOSTNAMENULL;
2578 goto fail_bos_HostGetNext;
2581 rc = IteratorNext(iter, (void *)hostName, &tst);
2583 fail_bos_HostGetNext:
2592 * bos_HostGetDone - finish using a host iterator.
2596 * IN iterationId - an iterator previously returned by
2601 * No locks are obtained or released by this function
2605 * Returns != 0 upon successful completion.
2610 bos_HostGetDone(const void *iterationId, afs_status_p st)
2613 afs_status_t tst = 0;
2614 afs_admin_iterator_p iter = (afs_admin_iterator_p) iterationId;
2616 if (iterationId == NULL) {
2617 tst = ADMITERATIONIDPNULL;
2618 goto fail_bos_HostGetDone;
2621 rc = IteratorDone(iter, &tst);
2623 fail_bos_HostGetDone:
2632 * bos_ExecutableCreate - create a new executable at the bos server.
2636 * IN serverHandle - a previously opened serverHandle.
2638 * IN sourceFile - the executable to install at the bos server.
2640 * IN destFile - the location where the executable will be installed.
2644 * No locks are obtained or released by this function
2648 * Returns != 0 upon successful completion.
2653 bos_ExecutableCreate(const void *serverHandle, const char *sourceFile,
2654 const char *destFile, afs_status_p st)
2657 afs_status_t tst = 0;
2658 bos_server_p b_handle = (bos_server_p) serverHandle;
2661 struct rx_call *tcall;
2664 * Validate arguments
2667 if (!isValidServerHandle(b_handle, &tst)) {
2668 goto fail_bos_ExecutableCreate;
2671 if ((sourceFile == NULL) || (*sourceFile == 0)) {
2672 tst = ADMBOSSOURCEFILENULL;
2673 goto fail_bos_ExecutableCreate;
2676 if ((destFile == NULL) || (*destFile == 0)) {
2677 tst = ADMBOSDESTFILENULL;
2678 goto fail_bos_ExecutableCreate;
2682 * Open the file locally and compute its size
2685 fd = open(sourceFile, O_RDONLY);
2688 tst = ADMBOSCANTOPENSOURCEFILE;
2689 goto fail_bos_ExecutableCreate;
2692 if (fstat(fd, &estat)) {
2693 tst = ADMBOSCANTSTATSOURCEFILE;
2694 goto fail_bos_ExecutableCreate;
2698 * Start a split rpc to the bos server.
2701 tcall = rx_NewCall(b_handle->server);
2704 StartBOZO_Install(tcall, (char *)destFile, estat.st_size,
2705 (afs_int32) estat.st_mode, estat.st_mtime);
2708 rx_EndCall(tcall, tst);
2709 goto fail_bos_ExecutableCreate;
2713 * Copy the data to the server
2719 len = read(fd, tbuffer, sizeof(tbuffer));
2721 tst = ADMBOSCANTREADSOURCEFILE;
2722 rx_EndCall(tcall, len);
2723 goto fail_bos_ExecutableCreate;
2729 tst = rx_Write(tcall, tbuffer, len);
2731 tst = ADMBOSSENDSOURCEFILE;
2732 rx_EndCall(tcall, tst);
2733 goto fail_bos_ExecutableCreate;
2738 * Terminate the rpc to the server
2741 tst = rx_EndCall(tcall, tst);
2747 fail_bos_ExecutableCreate:
2756 * bos_ExecutableRevert - revert an executable to a previous .BAK version.
2760 * IN serverHandle - a previously opened serverHandle.
2762 * IN execFile - the executable to revert at the bos server.
2766 * No locks are obtained or released by this function
2770 * Returns != 0 upon successful completion.
2775 bos_ExecutableRevert(const void *serverHandle, const char *execFile,
2779 afs_status_t tst = 0;
2780 bos_server_p b_handle = (bos_server_p) serverHandle;
2782 if (!isValidServerHandle(b_handle, &tst)) {
2783 goto fail_bos_ExecutableRevert;
2786 if ((execFile == NULL) || (*execFile == 0)) {
2787 tst = ADMBOSEXECFILENULL;
2788 goto fail_bos_ExecutableRevert;
2791 tst = BOZO_UnInstall(b_handle->server, (char *)execFile);
2797 fail_bos_ExecutableRevert:
2806 * bos_ExecutableTimestampGet - get the last mod times for an executable,
2807 * the .BAK version of the executable, and the .OLD version of the
2808 * executable if they exist.
2812 * IN serverHandle - a previously opened serverHandle.
2814 * IN execFile - the executable to revert at the bos server.
2818 * No locks are obtained or released by this function
2822 * Returns != 0 upon successful completion.
2827 bos_ExecutableTimestampGet(const void *serverHandle, const char *execFile,
2828 afs_int32 *newTime, afs_int32 *oldTime,
2829 afs_int32 *bakTime, afs_status_p st)
2832 afs_status_t tst = 0;
2833 bos_server_p b_handle = (bos_server_p) serverHandle;
2835 if (!isValidServerHandle(b_handle, &tst)) {
2836 goto fail_bos_ExecutableTimestampGet;
2839 if ((execFile == NULL) || (*execFile == 0)) {
2840 tst = ADMBOSEXECFILENULL;
2841 goto fail_bos_ExecutableTimestampGet;
2844 if (newTime == NULL) {
2845 tst = ADMBOSNEWTIMENULL;
2846 goto fail_bos_ExecutableTimestampGet;
2849 if (oldTime == NULL) {
2850 tst = ADMBOSOLDTIMENULL;
2851 goto fail_bos_ExecutableTimestampGet;
2854 if (bakTime == NULL) {
2855 tst = ADMBOSBAKTIMENULL;
2856 goto fail_bos_ExecutableTimestampGet;
2860 BOZO_GetDates(b_handle->server, (char *)execFile, newTime, bakTime, oldTime);
2866 fail_bos_ExecutableTimestampGet:
2875 * bos_ExecutablePrune - prune the bak, old, and core files off a server
2880 * IN serverHandle - a previously opened serverHandle.
2882 * IN oldFiles - prune .OLD files.
2884 * IN bakFiles - prune .BAK files.
2886 * IN coreFiles - prune core files.
2890 * No locks are obtained or released by this function
2894 * Returns != 0 upon successful completion.
2899 bos_ExecutablePrune(const void *serverHandle, bos_Prune_t oldFiles,
2900 bos_Prune_t bakFiles, bos_Prune_t coreFiles,
2904 afs_status_t tst = 0;
2905 bos_server_p b_handle = (bos_server_p) serverHandle;
2906 afs_int32 flags = 0;
2908 if (!isValidServerHandle(b_handle, &tst)) {
2909 goto fail_bos_ExecutablePrune;
2912 if (oldFiles == BOS_PRUNE) {
2913 flags |= BOZO_PRUNEOLD;
2916 if (bakFiles == BOS_PRUNE) {
2917 flags |= BOZO_PRUNEBAK;
2920 if (coreFiles == BOS_PRUNE) {
2921 flags |= BOZO_PRUNECORE;
2924 tst = BOZO_Prune(b_handle->server, flags);
2930 fail_bos_ExecutablePrune:
2939 * bos_ExecutableRestartTimeSet - set the restart time of the bos server
2944 * IN serverHandle - a previously opened serverHandle.
2946 * IN type - specifies either weekly restart or daily restart time.
2948 * IN time - the time to begin restarts.
2952 * No locks are obtained or released by this function
2956 * Returns != 0 upon successful completion.
2961 bos_ExecutableRestartTimeSet(const void *serverHandle, bos_Restart_t type,
2962 bos_RestartTime_t time, afs_status_p st)
2965 afs_status_t tst = 0;
2966 bos_server_p b_handle = (bos_server_p) serverHandle;
2967 afs_int32 restartType = 0;
2968 struct bozo_netKTime restartTime;
2970 if (!isValidServerHandle(b_handle, &tst)) {
2971 goto fail_bos_ExecutableRestartTimeSet;
2974 if (type == BOS_RESTART_WEEKLY) {
2980 if ((time.mask & BOS_RESTART_TIME_HOUR)
2981 && ((time.hour < 0) || (time.hour > 23))) {
2982 tst = ADMBOSHOURINVALID;
2983 goto fail_bos_ExecutableRestartTimeSet;
2986 if ((time.mask & BOS_RESTART_TIME_MINUTE)
2987 && ((time.min < 0) || (time.min > 60))) {
2988 tst = ADMBOSMINUTEINVALID;
2989 goto fail_bos_ExecutableRestartTimeSet;
2992 if ((time.mask & BOS_RESTART_TIME_SECOND)
2993 && ((time.sec < 0) || (time.sec > 60))) {
2994 tst = ADMBOSSECONDINVALID;
2995 goto fail_bos_ExecutableRestartTimeSet;
2998 if ((time.mask & BOS_RESTART_TIME_DAY)
2999 && ((time.day < 0) || (time.day > 6))) {
3000 tst = ADMBOSDAYINVALID;
3001 goto fail_bos_ExecutableRestartTimeSet;
3004 restartTime.mask = time.mask;
3005 restartTime.hour = time.hour;
3006 restartTime.min = time.min;
3007 restartTime.sec = time.sec;
3008 restartTime.day = time.day;
3010 tst = BOZO_SetRestartTime(b_handle->server, restartType, &restartTime);
3016 fail_bos_ExecutableRestartTimeSet:
3025 * bos_ExecutableRestartTimeGet - get the restart time of the bos server
3030 * IN serverHandle - a previously opened serverHandle.
3032 * IN type - specifies either weekly restart or daily restart time.
3034 * OUT timeP - the time to begin restarts.
3038 * No locks are obtained or released by this function
3042 * Returns != 0 upon successful completion.
3047 bos_ExecutableRestartTimeGet(const void *serverHandle, bos_Restart_t type,
3048 bos_RestartTime_p timeP, afs_status_p st)
3051 afs_status_t tst = 0;
3052 bos_server_p b_handle = (bos_server_p) serverHandle;
3053 afs_int32 restartType = 0;
3054 struct bozo_netKTime restartTime;
3056 if (!isValidServerHandle(b_handle, &tst)) {
3057 goto fail_bos_ExecutableRestartTimeGet;
3060 if (timeP == NULL) {
3061 tst = ADMBOSTIMEPNULL;
3062 goto fail_bos_ExecutableRestartTimeGet;
3065 if (type == BOS_RESTART_WEEKLY) {
3071 tst = BOZO_GetRestartTime(b_handle->server, restartType, &restartTime);
3074 goto fail_bos_ExecutableRestartTimeGet;
3077 timeP->mask = restartTime.mask;
3078 timeP->hour = restartTime.hour;
3079 timeP->min = restartTime.min;
3080 timeP->sec = restartTime.sec;
3081 timeP->day = restartTime.day;
3084 fail_bos_ExecutableRestartTimeGet:
3093 * bos_LogGet - get a log file from the bos server machine.
3097 * IN serverHandle - a previously opened serverHandle.
3099 * IN log - the log file to retrieve.
3101 * IN/OUT logBufferSizeP - the length of the logData buffer on input,
3102 * and upon successful completion, the length of data stored in the buffer.
3104 * OUT logData - the retrieved data upon successful completion.
3108 * No locks are obtained or released by this function
3112 * Returns != 0 upon successful completion.
3117 bos_LogGet(const void *serverHandle, const char *log,
3118 unsigned long *logBufferSizeP, char *logData, afs_status_p st)
3121 afs_status_t tst = 0;
3122 bos_server_p b_handle = (bos_server_p) serverHandle;
3123 struct rx_call *tcall = NULL;
3127 unsigned long bytes_read = 0;
3130 * Validate parameters
3133 if (!isValidServerHandle(b_handle, &tst)) {
3134 goto fail_bos_LogGet;
3137 if ((log == NULL) || (*log == 0)) {
3138 tst = ADMBOSLOGNULL;
3139 goto fail_bos_LogGet;
3142 if (logBufferSizeP == NULL) {
3143 tst = ADMBOSLOGBUFFERSIZEPNULL;
3144 goto fail_bos_LogGet;
3147 if (logData == NULL) {
3148 tst = ADMBOSLOGDATANULL;
3149 goto fail_bos_LogGet;
3153 * Begin to retrieve the data
3156 tcall = rx_NewCall(b_handle->server);
3158 tst = StartBOZO_GetLog(tcall, (char *) log);
3161 goto fail_bos_LogGet;
3165 * Read the log file data
3169 error = rx_Read(tcall, &buffer, 1);
3171 tst = ADMBOSLOGFILEERROR;
3172 goto fail_bos_LogGet;
3176 * check for the end of the log
3180 *logBufferSizeP = bytes_read;
3185 * We've successfully read another byte, copy it to logData
3190 if (bytes_read <= *logBufferSizeP) {
3191 *logData++ = buffer;
3203 rx_EndCall(tcall, 0);
3213 * bos_AuthSet - set the authorization level required at the bos server.
3217 * IN serverHandle - a previously opened serverHandle.
3219 * IN auth - specifies the new auth level.
3223 * No locks are obtained or released by this function
3227 * Returns != 0 upon successful completion.
3232 bos_AuthSet(const void *serverHandle, bos_Auth_t auth, afs_status_p st)
3235 afs_status_t tst = 0;
3236 bos_server_p b_handle = (bos_server_p) serverHandle;
3237 afs_int32 level = 0;
3239 if (!isValidServerHandle(b_handle, &tst)) {
3240 goto fail_bos_AuthSet;
3243 if (auth == BOS_AUTH_REQUIRED) {
3249 tst = BOZO_SetNoAuthFlag(b_handle->server, level);
3264 * bos_CommandExecute - execute a command at the bos server.
3268 * IN serverHandle - a previously opened serverHandle.
3270 * IN command - the command to execute.
3274 * No locks are obtained or released by this function
3278 * Returns != 0 upon successful completion.
3283 bos_CommandExecute(const void *serverHandle, const char *command,
3287 afs_status_t tst = 0;
3288 bos_server_p b_handle = (bos_server_p) serverHandle;
3290 if (!isValidServerHandle(b_handle, &tst)) {
3291 goto fail_bos_CommandExecute;
3294 if ((command == NULL) || (*command == 0)) {
3295 tst = ADMBOSCOMMANDNULL;
3296 goto fail_bos_CommandExecute;
3299 tst = BOZO_Exec(b_handle->server, (char *) command);
3305 fail_bos_CommandExecute:
3314 * bos_Salvage - perform a remote salvage operation.
3318 * IN cellHandle - a previously opened cellHandle.
3320 * IN serverHandle - a previously opened serverHandle.
3322 * IN partitionName - the partition to salvage. Can be null.
3324 * IN volumeName - the volume to salvage. Can be null, if non-null,
3325 * partitionName cannot be null.
3327 * IN numSalvagers - the number of salvage processes to run in parallel.
3329 * IN tmpDir - directory to place temporary files. Can be null.
3331 * IN logFile - file where salvage log will be written. Can be null.
3333 * IN force - sets salvager -force flag.
3335 * IN salvageDamagedVolumes - sets salvager -oktozap flag.
3337 * IN writeInodes - sets salvager -inodes flag.
3339 * IN writeRootInodes - sets salvager -rootinodes flag.
3341 * IN forceDirectory - sets salvager -salvagedirs flag.
3343 * IN forceBlockRead - sets salvager -blockread flag.
3347 * No locks are obtained or released by this function
3351 * Returns != 0 upon successful completion.
3355 #define INITIAL_LOG_LEN 4096
3358 bos_Salvage(const void *cellHandle, const void *serverHandle,
3359 const char *partitionName, const char *volumeName,
3360 int numSalvagers, const char *tmpDir, const char *logFile,
3362 bos_SalvageDamagedVolumes_t salvageDamagedVolumes,
3363 bos_WriteInodes_t writeInodes,
3364 bos_WriteRootInodes_t writeRootInodes,
3365 bos_ForceDirectory_t forceDirectory,
3366 bos_ForceBlockRead_t forceBlockRead, afs_status_p st)
3369 afs_status_t tst = 0;
3370 bos_server_p b_handle = (bos_server_p) serverHandle;
3371 afs_cell_handle_p c_handle = (afs_cell_handle_p) cellHandle;
3372 int have_partition = 0;
3373 int have_volume = 0;
3374 unsigned int part = 0;
3375 int try_to_stop_fileserver = 0;
3376 bos_ProcessType_t procType;
3377 bos_ProcessInfo_t procInfo;
3379 char command[BOS_MAX_NAME_LEN];
3380 int command_len = 0;
3382 char *logData = NULL;
3383 unsigned long logLen = INITIAL_LOG_LEN;
3386 * Validate arguments
3389 if (!IsValidCellHandle(c_handle, &tst)) {
3390 goto fail_bos_Salvage;
3393 if (!isValidServerHandle(b_handle, &tst)) {
3394 goto fail_bos_Salvage;
3397 if (c_handle->vos_valid == 0) {
3398 tst = ADMBOSCELLHANDLENOVOS;
3399 goto fail_bos_Salvage;
3402 if ((partitionName != NULL) && (*partitionName != 0)) {
3403 if (!vos_PartitionNameToId(partitionName, &part, &tst)) {
3404 goto fail_bos_Salvage;
3409 if ((volumeName != NULL) && (*volumeName != 0)) {
3410 if (!have_partition) {
3411 tst = ADMBOSSALVAGEVOLUME;
3412 goto fail_bos_Salvage;
3417 if ((logFile != NULL) && (*logFile != 0)) {
3418 log = fopen(logFile, "w");
3420 tst = ADMBOSSALVAGEBADLOG;
3421 goto fail_bos_Salvage;
3426 * If we are salvaging more than a single volume, stop the fileserver
3430 try_to_stop_fileserver = 1;
3434 * Only try to stop the fileserver if it is running
3437 if (try_to_stop_fileserver) {
3438 if (bos_ProcessInfoGet
3439 (serverHandle, "fs", &procType, &procInfo, &tst)) {
3440 if (procInfo.processGoal != BOS_PROCESS_RUNNING) {
3441 try_to_stop_fileserver = 0;
3447 * Make the call to stop the fileserver and wait for it to shutdown
3450 if (try_to_stop_fileserver) {
3451 if (!bos_ProcessExecutionStateSetTemporary
3452 (serverHandle, "fs", BOS_PROCESS_STOPPED, &tst)) {
3453 goto fail_bos_Salvage;
3455 bos_ProcessAllWaitTransition(serverHandle, &tst);
3459 * Create the salvage command line arguments
3463 sprintf(command, "%s ", AFSDIR_CANONICAL_SERVER_SALVAGER_FILEPATH);
3464 if (have_partition) {
3466 sprintf(&command[command_len], "-partition %s ", partitionName);
3471 sprintf(&command[command_len], "-volumeid %s ", volumeName);
3474 if (salvageDamagedVolumes == BOS_DONT_SALVAGE_DAMAGED_VOLUMES) {
3475 command_len += sprintf(&command[command_len], "-nowrite ");
3478 if (writeInodes == BOS_SALVAGE_WRITE_INODES) {
3479 command_len += sprintf(&command[command_len], "-inodes ");
3482 if (force == VOS_FORCE) {
3483 command_len += sprintf(&command[command_len], "-force ");
3486 if (writeRootInodes == BOS_SALVAGE_WRITE_ROOT_INODES) {
3487 command_len += sprintf(&command[command_len], "-rootinodes ");
3490 if (forceDirectory == BOS_SALVAGE_FORCE_DIRECTORIES) {
3491 command_len += sprintf(&command[command_len], "-salvagedirs ");
3494 if (forceBlockRead == BOS_SALVAGE_FORCE_BLOCK_READS) {
3495 command_len += sprintf(&command[command_len], "-blockreads ");
3499 sprintf(&command[command_len], "-parallel %d ", numSalvagers);
3501 if ((tmpDir != NULL) && (*tmpDir != 0)) {
3502 command_len += sprintf(&command[command_len], "-tmpdir %s ", tmpDir);
3505 if (command_len > BOS_MAX_NAME_LEN) {
3506 tst = ADMBOSSALVAGEBADOPTIONS;
3507 goto fail_bos_Salvage;
3511 * Create the process at the bosserver and wait until it completes
3514 if (!bos_ProcessCreate
3515 (serverHandle, "salvage-tmp", BOS_PROCESS_CRON, command, "now", 0,
3517 goto fail_bos_Salvage;
3521 bos_ProcessInfoGet(serverHandle, "salvage-tmp", &procType,
3522 &procInfo, &tst))) {
3526 if (tst != BZNOENT) {
3527 goto fail_bos_Salvage;
3531 * Print out the salvage log if required by the user
3536 logData = (char *)malloc(INITIAL_LOG_LEN);
3539 goto fail_bos_Salvage;
3543 (serverHandle, AFSDIR_CANONICAL_SERVER_SLVGLOG_FILEPATH,
3544 &logLen, logData, &tst)) {
3545 if (logLen > INITIAL_LOG_LEN) {
3546 logData = (char *)realloc(logData, (logLen + (logLen / 10)));
3547 if (logData == NULL) {
3549 goto fail_bos_Salvage;
3552 goto fail_bos_Salvage;
3555 fprintf(log, "SalvageLog:\n%s", logData);
3559 * Restart the fileserver if we had stopped it previously
3562 if (try_to_stop_fileserver) {
3563 try_to_stop_fileserver = 0;
3564 if (!bos_ProcessExecutionStateSetTemporary
3565 (serverHandle, "fs", BOS_PROCESS_RUNNING, &tst)) {
3566 goto fail_bos_Salvage;
3577 if (logData != NULL) {
3581 if (try_to_stop_fileserver) {
3582 bos_ProcessExecutionStateSetTemporary(serverHandle, "fs",
3583 BOS_PROCESS_RUNNING, 0);