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>
47 * Prototypes for functions that don't exist in any header files
50 extern int BOZO_AddCellHost();
51 extern int BOZO_AddKey();
52 extern int BOZO_AddSUser();
53 extern int BOZO_CreateBnode();
54 extern int BOZO_DeleteBnode();
55 extern int BOZO_DeleteCellHost();
56 extern int BOZO_DeleteKey();
57 extern int BOZO_DeleteSUser();
58 extern int BOZO_EnumerateInstance();
59 extern int BOZO_Exec();
60 extern int BOZO_GetCellHost();
61 extern int BOZO_GetCellName();
62 extern int BOZO_GetDates();
63 extern int BOZO_GetInstanceInfo();
64 extern int BOZO_GetInstanceParm();
65 extern int BOZO_GetInstanceParm();
66 extern int BOZO_GetRestartTime();
67 extern int BOZO_GetStatus();
68 extern int BOZO_ListSUsers();
69 extern int BOZO_ListKeys();
70 extern int BOZO_Prune();
71 extern int BOZO_ReBozo();
72 extern int BOZO_Restart();
73 extern int BOZO_RestartAll();
74 extern int BOZO_SetCellName();
75 extern int BOZO_SetNoAuthFlag();
76 extern int BOZO_SetRestartTime();
77 extern int BOZO_SetStatus(struct rx_connection *, char *, afs_int32);
78 extern int BOZO_SetTStatus(struct rx_connection *, char *, afs_int32);
79 extern int BOZO_ShutdownAll();
80 extern int BOZO_StartupAll();
81 extern int BOZO_UnInstall();
82 extern int BOZO_WaitAll();
83 extern int StartBOZO_GetLog();
84 extern int StartBOZO_Install();
86 typedef struct bos_server {
89 struct rx_connection *server;
90 struct rx_connection *server_encrypt;
91 struct rx_connection *server_stats;
93 } bos_server_t, *bos_server_p;
96 * isValidServerHandle - validate a bos_server_p.
100 * IN serverHandle - the handle to validate
104 * No locks are obtained or released by this function
108 * Returns != 0 upon successful completion.
112 isValidServerHandle(const bos_server_p serverHandle, afs_status_p st)
115 afs_status_t tst = 0;
117 if (serverHandle == NULL) {
118 tst = ADMBOSSERVERHANDLENULL;
119 goto fail_IsValidServerHandle;
122 if ((serverHandle->begin_magic != BEGIN_MAGIC)
123 || (serverHandle->end_magic != END_MAGIC)) {
124 tst = ADMBOSSERVERHANDLEBADMAGIC;
125 goto fail_IsValidServerHandle;
128 if (serverHandle->is_valid == 0) {
129 tst = ADMBOSSERVERHANDLEINVALID;
130 goto fail_IsValidServerHandle;
133 if (serverHandle->server == NULL) {
134 tst = ADMBOSSERVERHANDLENOSERVER;
135 goto fail_IsValidServerHandle;
138 if (serverHandle->server_encrypt == NULL) {
139 tst = ADMBOSSERVERHANDLENOSERVER;
140 goto fail_IsValidServerHandle;
144 fail_IsValidServerHandle:
153 * IsValidCellHandle - verify that a cell handle can be used to make bos
158 * IN cellHandle - the cellHandle to be validated.
162 * No locks are obtained or released by this function
166 * Returns != 0 upon successful completion.
170 IsValidCellHandle(afs_cell_handle_p cellHandle, afs_status_p st)
173 afs_status_t tst = 0;
175 if (!CellHandleIsValid((void *)cellHandle, &tst)) {
176 goto fail_IsValidCellHandle;
179 if (cellHandle->tokens == NULL) {
180 tst = ADMBOSCELLHANDLENOTOKENS;
181 goto fail_IsValidCellHandle;
185 fail_IsValidCellHandle:
194 * bos_ServerOpen - open a bos server for work.
198 * IN cellHandle - a previously opened cellHandle.
200 * IN serverName - the name of the machine that houses the bosserver of
203 * OUT serverHandleP - upon successful completion, this void pointer
204 * will point to a valid server handle for use in future operations.
208 * No locks are obtained or released by this function
212 * Returns != 0 upon successful completion.
216 bos_ServerOpen(const void *cellHandle, const char *serverName,
217 void **serverHandleP, afs_status_p st)
220 afs_status_t tst = 0;
221 afs_cell_handle_p c_handle = (afs_cell_handle_p) cellHandle;
222 bos_server_p bos_server = (bos_server_p) malloc(sizeof(bos_server_t));
226 * Validate parameters
229 if (!IsValidCellHandle(c_handle, &tst)) {
230 goto fail_bos_ServerOpen;
233 if ((serverName == NULL) || (*serverName == 0)) {
234 tst = ADMBOSSERVERNAMENULL;
235 goto fail_bos_ServerOpen;
238 if (serverHandleP == NULL) {
239 tst = ADMBOSSERVERHANDLEPNULL;
240 goto fail_bos_ServerOpen;
243 if (util_AdminServerAddressGetFromName(serverName, &serverAddress, &tst)
245 goto fail_bos_ServerOpen;
248 if (bos_server == NULL) {
250 goto fail_bos_ServerOpen;
254 rx_GetCachedConnection(htonl(serverAddress), htons(AFSCONF_NANNYPORT),
256 c_handle->tokens->afs_sc[c_handle->tokens->
258 c_handle->tokens->sc_index);
260 bos_server->server_encrypt =
261 rx_GetCachedConnection(htonl(serverAddress), htons(AFSCONF_NANNYPORT),
263 c_handle->tokens->afs_encrypt_sc[c_handle->
266 c_handle->tokens->sc_index);
268 bos_server->server_stats =
269 rx_GetCachedConnection(htonl(serverAddress), htons(AFSCONF_NANNYPORT),
271 c_handle->tokens->afs_sc[c_handle->tokens->
273 c_handle->tokens->sc_index);
275 if ((bos_server->server == NULL) || (bos_server->server_encrypt == NULL)) {
276 tst = ADMBOSSERVERNOCONNECTION;
277 goto fail_bos_ServerOpen;
280 bos_server->begin_magic = BEGIN_MAGIC;
281 bos_server->is_valid = 1;
282 bos_server->end_magic = END_MAGIC;
284 *serverHandleP = (void *)bos_server;
289 if ((rc == 0) && (bos_server != NULL)) {
290 if (bos_server->server) {
291 rx_ReleaseCachedConnection(bos_server->server);
293 if (bos_server->server_encrypt) {
294 rx_ReleaseCachedConnection(bos_server->server_encrypt);
306 * bos_ServerClose - close a bos server handle
310 * IN serverHandle - a bos server handle previously returned by bos_ServerOpen
314 * No locks are obtained or released by this function
318 * Returns != 0 upon successful completion.
322 bos_ServerClose(const void *serverHandle, afs_status_p st)
325 afs_status_t tst = 0;
326 bos_server_p b_handle = (bos_server_p) serverHandle;
328 if (isValidServerHandle(b_handle, &tst)) {
329 rx_ReleaseCachedConnection(b_handle->server);
330 b_handle->is_valid = 0;
342 * bos_ProcessCreate - create a new process to run at a bos server.
346 * IN serverHandle - a previously opened serverHandle.
348 * IN processName - the name of the process to create.
350 * IN processType - the type of process to create.
352 * IN process - the path to the process binary at the bos server.
354 * IN cronTime - the time specification for cron processes.
356 * IN notifier - the path to the notifier binary at the bos server.
360 * No locks are obtained or released by this function
364 * Returns != 0 upon successful completion.
368 * CAUTION - this list must match bos_ProcessType_t definition
371 static char *processTypes[] = { "simple", "fs", "cron", 0 };
374 bos_ProcessCreate(const void *serverHandle, const char *processName,
375 bos_ProcessType_t processType, const char *process,
376 const char *cronTime, const char *notifier, afs_status_p st)
379 afs_status_t tst = 0;
380 bos_server_p b_handle = (bos_server_p) serverHandle;
382 if (!isValidServerHandle(b_handle, &tst)) {
383 goto fail_bos_ProcessCreate;
386 if (processType == BOS_PROCESS_FS) {
387 tst = ADMBOSPROCESSCREATEBADTYPE;
388 goto fail_bos_ProcessCreate;
391 if ((processName == NULL) || (*processName == 0)) {
392 tst = ADMBOSPROCESSNAMENULL;
393 goto fail_bos_ProcessCreate;
396 if ((process == NULL) || (*process == 0)) {
397 tst = ADMBOSPROCESSNULL;
398 goto fail_bos_ProcessCreate;
401 if ((processType == BOS_PROCESS_CRON) && (cronTime == NULL)) {
402 tst = ADMBOSCRONTIMENULL;
403 goto fail_bos_ProcessCreate;
406 if ((processType == BOS_PROCESS_SIMPLE) && (cronTime != NULL)) {
407 tst = ADMBOSCRONTIMENOTNULL;
408 goto fail_bos_ProcessCreate;
412 BOZO_CreateBnode(b_handle->server, processTypes[processType],
413 processName, process, (cronTime) ? cronTime : "", "",
414 "", "", (notifier) ? notifier : NONOTIFIER);
419 fail_bos_ProcessCreate:
428 * bos_FSProcessCreate - create the fs group of processes at the boserver.
432 * IN serverHandle - a previously opened serverHandle.
434 * IN processName - the name of the process to create.
436 * IN fileserverPath - the path to the fileserver binary at the bos server.
438 * IN volserverPath - the path to the volserver binary at the bos server.
440 * IN salvagerPath - the path to the salvager binary at the bos server.
442 * IN notifier - the path to the notifier binary at the bos server.
446 * No locks are obtained or released by this function
450 * Returns != 0 upon successful completion.
454 bos_FSProcessCreate(const void *serverHandle, const char *processName,
455 const char *fileserverPath, const char *volserverPath,
456 const char *salvagerPath, const char *notifier,
460 afs_status_t tst = 0;
461 bos_server_p b_handle = (bos_server_p) serverHandle;
463 if (!isValidServerHandle(b_handle, &tst)) {
464 goto fail_bos_ProcessCreate;
467 if ((processName == NULL) || (*processName == 0)) {
468 tst = ADMBOSPROCESSNAMENULL;
469 goto fail_bos_ProcessCreate;
472 if ((fileserverPath == NULL) || (*fileserverPath == 0)) {
473 tst = ADMBOSFILESERVERPATHNULL;
474 goto fail_bos_ProcessCreate;
477 if ((volserverPath == NULL) || (*volserverPath == 0)) {
478 tst = ADMBOSVOLSERVERPATHNULL;
479 goto fail_bos_ProcessCreate;
482 if ((salvagerPath == NULL) || (*salvagerPath == 0)) {
483 tst = ADMBOSSALVAGERPATHNULL;
484 goto fail_bos_ProcessCreate;
488 BOZO_CreateBnode(b_handle->server, processTypes[BOS_PROCESS_FS],
489 processName, fileserverPath, volserverPath,
490 salvagerPath, "", "",
491 (notifier) ? notifier : NONOTIFIER);
496 fail_bos_ProcessCreate:
505 * bos_ProcessDelete - delete an existing process at a bos server.
509 * IN serverHandle - a previously opened serverHandle.
511 * IN processName - the name of the process to delete.
515 * No locks are obtained or released by this function
519 * Returns != 0 upon successful completion.
523 bos_ProcessDelete(const void *serverHandle, const char *processName,
527 afs_status_t tst = 0;
528 bos_server_p b_handle = (bos_server_p) serverHandle;
530 if (!isValidServerHandle(b_handle, &tst)) {
531 goto fail_bos_ProcessDelete;
534 if ((processName == NULL) || (*processName == 0)) {
535 tst = ADMBOSPROCESSNAMENULL;
536 goto fail_bos_ProcessDelete;
539 tst = BOZO_DeleteBnode(b_handle->server, processName);
545 fail_bos_ProcessDelete:
554 * bos_ProcessExecutionStateGet - get the current execution state of a
559 * IN serverHandle - a previously opened serverHandle.
561 * IN processName - the name of the process to retrieve.
563 * OUT processStatusP - upon successful completion the process execution state
565 * OUT auxiliaryProcessStatus - set to point to aux proc status if available.
566 * Pass a pointer to an char array at least BOS_MAX_NAME_LEN long.
570 * No locks are obtained or released by this function
574 * Returns != 0 upon successful completion.
578 bos_ProcessExecutionStateGet(const void *serverHandle,
579 const char *processName,
580 bos_ProcessExecutionState_p processStatusP,
581 char *auxiliaryProcessStatus, afs_status_p st)
584 afs_status_t tst = 0;
585 bos_server_p b_handle = (bos_server_p) serverHandle;
588 if (!isValidServerHandle(b_handle, &tst)) {
589 goto fail_bos_ProcessExecutionStateGet;
592 if ((processName == NULL) || (*processName == 0)) {
593 tst = ADMBOSPROCESSNAMENULL;
594 goto fail_bos_ProcessExecutionStateGet;
597 if (processStatusP == NULL) {
598 tst = ADMBOSPROCESSSTATUSPNULL;
599 goto fail_bos_ProcessExecutionStateGet;
602 if (auxiliaryProcessStatus == NULL) {
603 tst = ADMBOSAUXILIARYPROCESSSTATUSNULL;
604 goto fail_bos_ProcessExecutionStateGet;
608 BOZO_GetStatus(b_handle->server, processName, &state,
609 &auxiliaryProcessStatus);
612 goto fail_bos_ProcessExecutionStateGet;
615 *processStatusP = (bos_ProcessExecutionState_t) state;
618 fail_bos_ProcessExecutionStateGet:
627 * SetExecutionState - set the execution state of a process
631 * IN serverHandle - a previously opened serverHandle.
633 * IN processName - the name of the process to modify.
635 * IN processStatus - the new process state.
637 * IN func - the function to call to set the status.
641 * No locks are obtained or released by this function
645 * Returns != 0 upon successful completion.
649 SetExecutionState(const void *serverHandle, const char *processName,
650 const bos_ProcessExecutionState_t processStatus,
651 int (*func) (struct rx_connection *, const char *,
652 afs_int32), afs_status_p st)
655 afs_status_t tst = 0;
656 bos_server_p b_handle = (bos_server_p) serverHandle;
659 if (!isValidServerHandle(b_handle, &tst)) {
660 goto fail_SetExecutionState;
663 if ((processName == NULL) || (*processName == 0)) {
664 tst = ADMBOSPROCESSNAMENULL;
665 goto fail_SetExecutionState;
668 if ((processStatus != BOS_PROCESS_STOPPED)
669 && (processStatus != BOS_PROCESS_RUNNING)) {
670 tst = ADMBOSPROCESSSTATUSSET;
671 goto fail_SetExecutionState;
674 state = (afs_int32) processStatus;
676 tst = func(b_handle->server, processName, state);
682 fail_SetExecutionState:
691 * bos_ProcessExecutionStateSet - set the execution state of a process
695 * IN serverHandle - a previously opened serverHandle.
697 * IN processName - the name of the process to modify.
699 * IN processStatus - the new process state.
703 * No locks are obtained or released by this function
707 * Returns != 0 upon successful completion.
711 bos_ProcessExecutionStateSet(const void *serverHandle,
712 const char *processName,
713 bos_ProcessExecutionState_t processStatus,
716 return SetExecutionState(serverHandle, processName, processStatus,
721 * bos_ProcessExecutionStateSetTemporary - set the execution state of a process
726 * IN serverHandle - a previously opened serverHandle.
728 * IN processName - the name of the process to modify.
730 * IN processStatus - the new process state.
734 * No locks are obtained or released by this function
738 * Returns != 0 upon successful completion.
742 bos_ProcessExecutionStateSetTemporary(const void *serverHandle,
743 const char *processName,
744 bos_ProcessExecutionState_t
745 processStatus, afs_status_p st)
747 return SetExecutionState(serverHandle, processName, processStatus,
748 BOZO_SetTStatus, st);
752 * The iterator functions and data for the process name retrieval functions
755 typedef struct process_name_get {
757 struct rx_connection *server;
758 char process[CACHED_ITEMS][BOS_MAX_NAME_LEN];
759 } process_name_get_t, *process_name_get_p;
762 GetProcessNameRPC(void *rpc_specific, int slot, int *last_item,
763 int *last_item_contains_data, afs_status_p st)
766 afs_status_t tst = 0;
767 process_name_get_p proc = (process_name_get_p) rpc_specific;
768 char *ptr = (char *)&proc->process[slot];
770 tst = BOZO_EnumerateInstance(proc->server, proc->next++, &ptr);
774 } else if (tst == BZDOM) {
778 *last_item_contains_data = 0;
788 GetProcessNameFromCache(void *rpc_specific, int slot, void *dest,
792 afs_status_t tst = 0;
793 process_name_get_p proc = (process_name_get_p) rpc_specific;
795 strcpy((char *)dest, (char *)&proc->process[slot]);
805 * bos_ProcessNameGetBegin - begin iterating over the list of processes
806 * at a particular bos server.
810 * IN serverHandle - a previously opened serverHandle.
812 * OUT iter - an iterator that can be passed to bos_ProcessNameGetNext
813 * to retrieve the process names.
817 * No locks are obtained or released by this function
821 * Returns != 0 upon successful completion.
826 bos_ProcessNameGetBegin(const void *serverHandle, void **iterationIdP,
830 afs_status_t tst = 0;
831 bos_server_p b_handle = (bos_server_p) serverHandle;
832 afs_admin_iterator_p iter =
833 (afs_admin_iterator_p) malloc(sizeof(afs_admin_iterator_t));
834 process_name_get_p proc =
835 (process_name_get_p) malloc(sizeof(process_name_get_t));
837 if (!isValidServerHandle(b_handle, &tst)) {
838 goto fail_bos_ProcessNameGetBegin;
841 if (iterationIdP == NULL) {
842 tst = ADMITERATIONIDPNULL;
843 goto fail_bos_ProcessNameGetBegin;
846 if ((iter == NULL) || (proc == NULL)) {
848 goto fail_bos_ProcessNameGetBegin;
852 proc->server = b_handle->server;
855 (iter, (void *)proc, GetProcessNameRPC, GetProcessNameFromCache, NULL,
857 *iterationIdP = (void *)iter;
859 goto fail_bos_ProcessNameGetBegin;
863 fail_bos_ProcessNameGetBegin:
881 * bos_ProcessNameGetNext - retrieve the next process name from the bos server.
885 * IN iterationId - an iterator previously returned by bos_ProcessNameGetBegin
887 * OUT processName - upon successful completion contains the next process name
888 * retrieved from the server.
892 * No locks are obtained or released by this function
896 * Returns != 0 upon successful completion.
901 bos_ProcessNameGetNext(const void *iterationId, char *processName,
905 afs_status_t tst = 0;
906 afs_admin_iterator_p iter = (afs_admin_iterator_p) iterationId;
908 if (processName == NULL) {
909 tst = ADMBOSPROCESSNAMENULL;
910 goto fail_bos_ProcessNameGetNext;
913 if (iterationId == NULL) {
914 tst = ADMITERATIONIDPNULL;
915 goto fail_bos_ProcessNameGetNext;
918 rc = IteratorNext(iter, (void *)processName, &tst);
920 fail_bos_ProcessNameGetNext:
929 * bos_ProcessNameGetDone - finish using a process name iterator.
933 * IN iterationId - an iterator previously returned by bos_ProcessNameGetBegin
937 * No locks are obtained or released by this function
941 * Returns != 0 upon successful completion.
946 bos_ProcessNameGetDone(const void *iterationId, afs_status_p st)
949 afs_status_t tst = 0;
950 afs_admin_iterator_p iter = (afs_admin_iterator_p) iterationId;
952 if (iterationId == NULL) {
953 tst = ADMITERATIONIDPNULL;
954 goto fail_bos_ProcessNameGetDone;
957 rc = IteratorDone(iter, &tst);
959 fail_bos_ProcessNameGetDone:
968 * bos_ProcessInfoGet - get information about a single process
972 * IN serverHandle - a previously opened serverHandle.
974 * IN processName - the process of interest.
976 * OUT processTypeP - upon successful completion contains the process type
978 * OUT processInfoP - upon successful completion contains the process info
982 * No locks are obtained or released by this function
986 * Returns != 0 upon successful completion.
991 bos_ProcessInfoGet(const void *serverHandle, const char *processName,
992 bos_ProcessType_p processTypeP,
993 bos_ProcessInfo_p processInfoP, afs_status_p st)
996 afs_status_t tst = 0;
997 bos_server_p b_handle = (bos_server_p) serverHandle;
998 char type[BOS_MAX_NAME_LEN];
1000 struct bozo_status status;
1003 if (!isValidServerHandle(b_handle, &tst)) {
1004 goto fail_bos_ProcessInfoGet;
1007 if ((processName == NULL) || (*processName == 0)) {
1008 tst = ADMBOSPROCESSNAMENULL;
1009 goto fail_bos_ProcessInfoGet;
1012 if (processTypeP == NULL) {
1013 tst = ADMBOSPROCESSTYPEPNULL;
1014 goto fail_bos_ProcessInfoGet;
1017 if (processInfoP == NULL) {
1018 tst = ADMBOSPROCESSINFOPNULL;
1019 goto fail_bos_ProcessInfoGet;
1022 tst = BOZO_GetInstanceInfo(b_handle->server, processName, &ptr, &status);
1025 goto fail_bos_ProcessInfoGet;
1029 for (i = 0; (processTypes[i] != NULL); i++) {
1030 if (!strcmp(processTypes[i], type)) {
1031 *processTypeP = (bos_ProcessType_t) i;
1036 if (processTypes[i] == NULL) {
1037 tst = ADMBOSINVALIDPROCESSTYPE;
1038 goto fail_bos_ProcessInfoGet;
1041 processInfoP->processGoal = (bos_ProcessExecutionState_t) status.goal;
1042 processInfoP->processStartTime = status.procStartTime;
1043 processInfoP->numberProcessStarts = status.procStarts;
1044 processInfoP->processExitTime = status.lastAnyExit;
1045 processInfoP->processExitErrorTime = status.lastErrorExit;
1046 processInfoP->processErrorCode = status.errorCode;
1047 processInfoP->processErrorSignal = status.errorSignal;
1048 processInfoP->state = BOS_PROCESS_OK;
1050 if (status.flags & BOZO_ERRORSTOP) {
1051 processInfoP->state |= BOS_PROCESS_TOO_MANY_ERRORS;
1053 if (status.flags & BOZO_HASCORE) {
1054 processInfoP->state |= BOS_PROCESS_CORE_DUMPED;
1056 if (status.flags & BOZO_BADDIRACCESS) {
1057 processInfoP->state |= BOS_PROCESS_BAD_FILE_ACCESS;
1061 fail_bos_ProcessInfoGet:
1070 * The iterator functions and data for the parameter retrieval functions
1073 typedef struct param_get {
1075 struct rx_connection *server;
1076 char processName[BOS_MAX_NAME_LEN];
1077 char param[CACHED_ITEMS][BOS_MAX_NAME_LEN];
1078 } param_get_t, *param_get_p;
1081 GetParameterRPC(void *rpc_specific, int slot, int *last_item,
1082 int *last_item_contains_data, afs_status_p st)
1085 afs_status_t tst = 0;
1086 param_get_p param = (param_get_p) rpc_specific;
1087 char *ptr = (char *)¶m->param[slot];
1090 BOZO_GetInstanceParm(param->server, param->processName, param->next++,
1095 } else if (tst == BZDOM) {
1099 *last_item_contains_data = 0;
1109 GetParameterFromCache(void *rpc_specific, int slot, void *dest,
1113 afs_status_t tst = 0;
1114 param_get_p param = (param_get_p) rpc_specific;
1116 strcpy((char *)dest, (char *)¶m->param[slot]);
1126 * bos_ProcessParameterGetBegin - begin iterating over the parameters
1127 * of a particular process.
1131 * IN serverHandle - a previously opened serverHandle.
1133 * IN processName - the process whose parameters are returned.
1135 * OUT iter - an iterator that can be passed to bos_ProcessParameterGetNext
1136 * to retrieve the parameters.
1140 * No locks are obtained or released by this function
1144 * Returns != 0 upon successful completion.
1149 bos_ProcessParameterGetBegin(const void *serverHandle,
1150 const char *processName, void **iterationIdP,
1154 afs_status_t tst = 0;
1155 bos_server_p b_handle = (bos_server_p) serverHandle;
1156 afs_admin_iterator_p iter =
1157 (afs_admin_iterator_p) malloc(sizeof(afs_admin_iterator_t));
1158 param_get_p param = (param_get_p) malloc(sizeof(param_get_t));
1160 if (!isValidServerHandle(b_handle, &tst)) {
1161 goto fail_bos_ProcessParameterGetBegin;
1164 if ((processName == NULL) || (*processName == 0)) {
1165 tst = ADMBOSPROCESSNAMENULL;
1166 goto fail_bos_ProcessParameterGetBegin;
1169 if (iterationIdP == NULL) {
1170 tst = ADMITERATIONIDPNULL;
1171 goto fail_bos_ProcessParameterGetBegin;
1174 if ((iter == NULL) || (param == NULL)) {
1176 goto fail_bos_ProcessParameterGetBegin;
1180 param->server = b_handle->server;
1181 strcpy(param->processName, processName);
1184 (iter, (void *)param, GetParameterRPC, GetParameterFromCache, NULL,
1186 *iterationIdP = (void *)iter;
1188 goto fail_bos_ProcessParameterGetBegin;
1192 fail_bos_ProcessParameterGetBegin:
1198 if (param != NULL) {
1210 * bos_ProcessParameterGetNext - retrieve the next parameter
1211 * from the bos server.
1215 * IN iterationId - an iterator previously returned by
1216 * bos_ProcessParameterGetBegin
1218 * OUT parameter - upon successful completion contains the next parameter
1219 * retrieved from the server.
1223 * No locks are obtained or released by this function
1227 * Returns != 0 upon successful completion.
1232 bos_ProcessParameterGetNext(const void *iterationId, char *parameter,
1236 afs_status_t tst = 0;
1237 afs_admin_iterator_p iter = (afs_admin_iterator_p) iterationId;
1239 if (iterationId == NULL) {
1240 tst = ADMITERATIONIDPNULL;
1241 goto fail_bos_ProcessParameterGetNext;
1244 if (parameter == NULL) {
1245 tst = ADMBOSPARAMETERNULL;
1246 goto fail_bos_ProcessParameterGetNext;
1249 rc = IteratorNext(iter, (void *)parameter, &tst);
1251 fail_bos_ProcessParameterGetNext:
1260 * bos_ProcessParameterGetDone - finish using a process name iterator.
1264 * IN iterationId - an iterator previously returned by
1265 * bos_ProcessParameterGetBegin
1269 * No locks are obtained or released by this function
1273 * Returns != 0 upon successful completion.
1278 bos_ProcessParameterGetDone(const void *iterationId, afs_status_p st)
1281 afs_status_t tst = 0;
1282 afs_admin_iterator_p iter = (afs_admin_iterator_p) iterationId;
1284 if (iterationId == NULL) {
1285 tst = ADMITERATIONIDPNULL;
1286 goto fail_bos_ProcessParameterGetDone;
1289 rc = IteratorDone(iter, &tst);
1291 fail_bos_ProcessParameterGetDone:
1300 * bos_ProcessNotifierGet - retrieve the notifier associated with a
1305 * IN serverHandle - a previously opened serverHandle.
1307 * IN processName - the process whose notifier we are retrieving.
1309 * OUT notifier - upon successful completion contains the notifier.
1313 * No locks are obtained or released by this function
1317 * Returns != 0 upon successful completion.
1322 bos_ProcessNotifierGet(const void *serverHandle, const char *processName,
1323 char *notifier, afs_status_p st)
1326 afs_status_t tst = 0;
1327 bos_server_p b_handle = (bos_server_p) serverHandle;
1329 if (!isValidServerHandle(b_handle, &tst)) {
1330 goto fail_bos_ProcessNotifierGet;
1333 if ((processName == NULL) || (*processName == 0)) {
1334 tst = ADMBOSPROCESSNAMENULL;
1335 goto fail_bos_ProcessNotifierGet;
1338 if (notifier == NULL) {
1339 tst = ADMBOSNOTIFIERNULL;
1340 goto fail_bos_ProcessNotifierGet;
1343 tst = BOZO_GetInstanceParm(b_handle->server, processName, 999, ¬ifier);
1349 fail_bos_ProcessNotifierGet:
1358 * bos_ProcessRestart - restart a particular process.
1362 * IN serverHandle - a previously opened serverHandle.
1364 * IN processName - the process to restart
1368 * No locks are obtained or released by this function
1372 * Returns != 0 upon successful completion.
1377 bos_ProcessRestart(const void *serverHandle, const char *processName,
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_ProcessRestart;
1388 if ((processName == NULL) || (*processName == 0)) {
1389 tst = ADMBOSPROCESSNAMENULL;
1390 goto fail_bos_ProcessRestart;
1393 tst = BOZO_Restart(b_handle->server, processName);
1399 fail_bos_ProcessRestart:
1408 * bos_ProcessAllStop - stop all running processes at a server.
1412 * IN serverHandle - a previously opened serverHandle.
1416 * No locks are obtained or released by this function
1420 * Returns != 0 upon successful completion.
1425 bos_ProcessAllStop(const void *serverHandle, afs_status_p st)
1428 afs_status_t tst = 0;
1429 bos_server_p b_handle = (bos_server_p) serverHandle;
1431 if (!isValidServerHandle(b_handle, &tst)) {
1432 goto fail_bos_ProcessAllStop;
1435 tst = BOZO_ShutdownAll(b_handle->server);
1441 fail_bos_ProcessAllStop:
1450 * bos_ProcessAllStart - start all processes that should be running at a
1455 * IN serverHandle - a previously opened serverHandle.
1459 * No locks are obtained or released by this function
1463 * Returns != 0 upon successful completion.
1468 bos_ProcessAllStart(const void *serverHandle, afs_status_p st)
1471 afs_status_t tst = 0;
1472 bos_server_p b_handle = (bos_server_p) serverHandle;
1474 if (!isValidServerHandle(b_handle, &tst)) {
1475 goto fail_bos_ProcessAllStart;
1478 tst = BOZO_StartupAll(b_handle->server);
1484 fail_bos_ProcessAllStart:
1493 * bos_ProcessAllWaitStop - stop all processes, and block until they have
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_ProcessAllWaitStop(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_ProcessAllWaitStop;
1521 if (!bos_ProcessAllStop(serverHandle, &tst)) {
1522 goto fail_bos_ProcessAllWaitStop;
1525 tst = BOZO_WaitAll(b_handle->server);
1531 fail_bos_ProcessAllWaitStop:
1540 * bos_ProcessAllWaitTransition - block until all processes at the bosserver
1541 * have reached their desired state.
1545 * IN serverHandle - a previously opened serverHandle.
1549 * No locks are obtained or released by this function
1553 * Returns != 0 upon successful completion.
1558 bos_ProcessAllWaitTransition(const void *serverHandle, afs_status_p st)
1561 afs_status_t tst = 0;
1562 bos_server_p b_handle = (bos_server_p) serverHandle;
1564 if (!isValidServerHandle(b_handle, &tst)) {
1565 goto fail_bos_ProcessAllWaitTransition;
1568 tst = BOZO_WaitAll(b_handle->server);
1574 fail_bos_ProcessAllWaitTransition:
1583 * bos_ProcessAllStopAndRestart - stop all the running processes, restart
1584 * them, and optionally restart the bosserver itself.
1589 * IN serverHandle - a previously opened serverHandle.
1591 * IN restartBosServer - flag to indicate whether to restart bosserver.
1595 * No locks are obtained or released by this function
1599 * Returns != 0 upon successful completion.
1604 bos_ProcessAllStopAndRestart(const void *serverHandle,
1605 bos_RestartBosServer_t restartBosServer,
1609 afs_status_t tst = 0;
1610 bos_server_p b_handle = (bos_server_p) serverHandle;
1612 if (!isValidServerHandle(b_handle, &tst)) {
1613 goto fail_bos_ProcessAllStopAndRestart;
1616 if (restartBosServer == BOS_RESTART_BOS_SERVER) {
1617 tst = BOZO_ReBozo(b_handle->server);
1619 goto fail_bos_ProcessAllStopAndRestart;
1623 tst = BOZO_RestartAll(b_handle->server);
1629 fail_bos_ProcessAllStopAndRestart:
1638 * bos_AdminCreate - create a new admin.
1642 * IN serverHandle - a previously opened serverHandle.
1644 * IN adminName - the new admin name.
1648 * No locks are obtained or released by this function
1652 * Returns != 0 upon successful completion.
1657 bos_AdminCreate(const void *serverHandle, const char *adminName,
1661 afs_status_t tst = 0;
1662 bos_server_p b_handle = (bos_server_p) serverHandle;
1664 if (!isValidServerHandle(b_handle, &tst)) {
1665 goto fail_bos_AdminCreate;
1668 if ((adminName == NULL) || (*adminName == 0)) {
1669 tst = ADMBOSADMINNAMENULL;
1670 goto fail_bos_AdminCreate;
1673 tst = BOZO_AddSUser(b_handle->server, adminName);
1679 fail_bos_AdminCreate:
1688 * bos_AdminDelete - delete a new admin.
1692 * IN serverHandle - a previously opened serverHandle.
1694 * IN adminName - the admin name.
1698 * No locks are obtained or released by this function
1702 * Returns != 0 upon successful completion.
1707 bos_AdminDelete(const void *serverHandle, const char *adminName,
1711 afs_status_t tst = 0;
1712 bos_server_p b_handle = (bos_server_p) serverHandle;
1714 if (!isValidServerHandle(b_handle, &tst)) {
1715 goto fail_bos_AdminDelete;
1718 if ((adminName == NULL) || (*adminName == 0)) {
1719 tst = ADMBOSADMINNAMENULL;
1720 goto fail_bos_AdminDelete;
1723 tst = BOZO_DeleteSUser(b_handle->server, adminName);
1729 fail_bos_AdminDelete:
1738 * The iterator functions and data for the admin retrieval functions
1741 typedef struct admin_get {
1743 struct rx_connection *server;
1744 char admin[CACHED_ITEMS][BOS_MAX_NAME_LEN];
1745 } admin_get_t, *admin_get_p;
1748 GetAdminRPC(void *rpc_specific, int slot, int *last_item,
1749 int *last_item_contains_data, afs_status_p st)
1752 afs_status_t tst = 0;
1753 admin_get_p admin = (admin_get_p) rpc_specific;
1754 char *ptr = (char *)&admin->admin[slot];
1756 tst = BOZO_ListSUsers(admin->server, admin->next++, &ptr);
1759 * There's no way to tell the difference between an rpc failure
1760 * and the end of the list, so we assume that any error means the
1767 *last_item_contains_data = 0;
1778 GetAdminFromCache(void *rpc_specific, int slot, void *dest, afs_status_p st)
1781 afs_status_t tst = 0;
1782 admin_get_p admin = (admin_get_p) rpc_specific;
1784 strcpy((char *)dest, (char *)&admin->admin[slot]);
1794 * bos_AdminGetBegin - begin iterating over the administrators.
1798 * IN serverHandle - a previously opened serverHandle.
1800 * OUT iter - an iterator that can be passed to bos_AdminGetBegin
1801 * to retrieve the administrators.
1805 * No locks are obtained or released by this function
1809 * Returns != 0 upon successful completion.
1814 bos_AdminGetBegin(const void *serverHandle, void **iterationIdP,
1818 afs_status_t tst = 0;
1819 bos_server_p b_handle = (bos_server_p) serverHandle;
1820 afs_admin_iterator_p iter =
1821 (afs_admin_iterator_p) malloc(sizeof(afs_admin_iterator_t));
1822 admin_get_p admin = (admin_get_p) malloc(sizeof(admin_get_t));
1824 if (!isValidServerHandle(b_handle, &tst)) {
1825 goto fail_bos_AdminGetBegin;
1828 if (iterationIdP == NULL) {
1829 tst = ADMITERATIONIDPNULL;
1830 goto fail_bos_AdminGetBegin;
1833 if ((iter == NULL) || (admin == NULL)) {
1835 goto fail_bos_AdminGetBegin;
1839 admin->server = b_handle->server;
1842 (iter, (void *)admin, GetAdminRPC, GetAdminFromCache, NULL, NULL,
1844 *iterationIdP = (void *)iter;
1848 fail_bos_AdminGetBegin:
1854 if (admin != NULL) {
1866 * bos_AdminGetNext - retrieve the next administrator
1867 * from the bos server.
1871 * IN iterationId - an iterator previously returned by
1874 * OUT adminName - upon successful completion contains the next administrator
1875 * retrieved from the server.
1879 * No locks are obtained or released by this function
1883 * Returns != 0 upon successful completion.
1888 bos_AdminGetNext(const void *iterationId, char *adminName, afs_status_p st)
1891 afs_status_t tst = 0;
1892 afs_admin_iterator_p iter = (afs_admin_iterator_p) iterationId;
1894 if (iterationId == NULL) {
1895 tst = ADMITERATIONIDPNULL;
1896 goto fail_bos_AdminGetNext;
1899 if (adminName == NULL) {
1900 tst = ADMBOSADMINNAMENULL;
1901 goto fail_bos_AdminGetNext;
1904 rc = IteratorNext(iter, (void *)adminName, &tst);
1906 fail_bos_AdminGetNext:
1915 * bos_AdminGetDone - finish using a administrator iterator.
1919 * IN iterationId - an iterator previously returned by
1924 * No locks are obtained or released by this function
1928 * Returns != 0 upon successful completion.
1933 bos_AdminGetDone(const void *iterationId, afs_status_p st)
1936 afs_status_t tst = 0;
1937 afs_admin_iterator_p iter = (afs_admin_iterator_p) iterationId;
1939 if (iterationId == NULL) {
1940 tst = ADMITERATIONIDPNULL;
1941 goto fail_bos_AdminGetDone;
1944 rc = IteratorDone(iter, &tst);
1946 fail_bos_AdminGetDone:
1955 * bos_KeyCreate - add a new key to the keyfile.
1959 * IN serverHandle - a previously opened serverHandle.
1961 * IN keyVersionNumber - the key version number.
1963 * IN key - the new key.
1967 * No locks are obtained or released by this function
1971 * Returns != 0 upon successful completion.
1976 bos_KeyCreate(const void *serverHandle, int keyVersionNumber,
1977 const kas_encryptionKey_p key, afs_status_p st)
1980 afs_status_t tst = 0;
1981 bos_server_p b_handle = (bos_server_p) serverHandle;
1983 if (!isValidServerHandle(b_handle, &tst)) {
1984 goto fail_bos_KeyCreate;
1988 tst = ADMBOSKEYNULL;
1989 goto fail_bos_KeyCreate;
1992 tst = BOZO_AddKey(b_handle->server_encrypt, keyVersionNumber, key);
2007 * bos_KeyDelete - delete an existing key from the keyfile.
2011 * IN serverHandle - a previously opened serverHandle.
2013 * IN keyVersionNumber - the key version number.
2017 * No locks are obtained or released by this function
2021 * Returns != 0 upon successful completion.
2026 bos_KeyDelete(const void *serverHandle, int keyVersionNumber, afs_status_p st)
2029 afs_status_t tst = 0;
2030 bos_server_p b_handle = (bos_server_p) serverHandle;
2032 if (!isValidServerHandle(b_handle, &tst)) {
2033 goto fail_bos_KeyDelete;
2036 tst = BOZO_DeleteKey(b_handle->server, keyVersionNumber);
2051 * The iterator functions and data for the key retrieval functions
2054 typedef struct key_get {
2056 struct rx_connection *server;
2057 bos_KeyInfo_t key[CACHED_ITEMS];
2058 } key_get_t, *key_get_p;
2061 GetKeyRPC(void *rpc_specific, int slot, int *last_item,
2062 int *last_item_contains_data, afs_status_p st)
2065 afs_status_t tst = 0;
2066 key_get_p key = (key_get_p) rpc_specific;
2067 struct bozo_keyInfo keyInfo;
2070 BOZO_ListKeys(key->server, key->next++,
2071 &key->key[slot].keyVersionNumber, &key->key[slot].key,
2076 key->key[slot].keyStatus.lastModificationDate = keyInfo.mod_sec;
2077 key->key[slot].keyStatus.lastModificationMicroSeconds =
2079 key->key[slot].keyStatus.checkSum = keyInfo.keyCheckSum;
2081 } else if (tst == BZDOM) {
2085 *last_item_contains_data = 0;
2095 GetKeyFromCache(void *rpc_specific, int slot, void *dest, afs_status_p st)
2098 afs_status_t tst = 0;
2099 key_get_p key = (key_get_p) rpc_specific;
2101 memcpy(dest, &key->key[slot], sizeof(bos_KeyInfo_t));
2111 * bos_KeyGetBegin - begin iterating over the keys.
2115 * IN serverHandle - a previously opened serverHandle.
2117 * OUT iter - an iterator that can be passed to bos_KeyGetNext
2118 * to retrieve the keys.
2122 * No locks are obtained or released by this function
2126 * Returns != 0 upon successful completion.
2131 bos_KeyGetBegin(const void *serverHandle, void **iterationIdP,
2135 afs_status_t tst = 0;
2136 bos_server_p b_handle = (bos_server_p) serverHandle;
2137 afs_admin_iterator_p iter =
2138 (afs_admin_iterator_p) malloc(sizeof(afs_admin_iterator_t));
2139 key_get_p key = (key_get_p) malloc(sizeof(key_get_t));
2141 if (!isValidServerHandle(b_handle, &tst)) {
2142 goto fail_bos_KeyGetBegin;
2145 if (iterationIdP == NULL) {
2146 tst = ADMITERATIONIDPNULL;
2147 goto fail_bos_KeyGetBegin;
2150 if ((iter == NULL) || (key == NULL)) {
2152 goto fail_bos_KeyGetBegin;
2156 key->server = b_handle->server_encrypt;
2159 (iter, (void *)key, GetKeyRPC, GetKeyFromCache, NULL, NULL, &tst)) {
2160 *iterationIdP = (void *)iter;
2164 fail_bos_KeyGetBegin:
2182 * bos_KeyGetNext - retrieve the next key
2183 * from the bos server.
2187 * IN iterationId - an iterator previously returned by
2190 * OUT keyP - upon successful completion contains the next key
2191 * retrieved from the server.
2195 * No locks are obtained or released by this function
2199 * Returns != 0 upon successful completion.
2204 bos_KeyGetNext(const void *iterationId, bos_KeyInfo_p keyP, afs_status_p st)
2207 afs_status_t tst = 0;
2208 afs_admin_iterator_p iter = (afs_admin_iterator_p) iterationId;
2210 if (iterationId == NULL) {
2211 tst = ADMITERATIONIDPNULL;
2212 goto fail_bos_KeyGetNext;
2216 tst = ADMBOSKEYPNULL;
2217 goto fail_bos_KeyGetNext;
2220 rc = IteratorNext(iter, (void *)keyP, &tst);
2222 fail_bos_KeyGetNext:
2231 * bos_KeyGetDone - finish using a key iterator.
2235 * IN iterationId - an iterator previously returned by
2240 * No locks are obtained or released by this function
2244 * Returns != 0 upon successful completion.
2249 bos_KeyGetDone(const void *iterationId, afs_status_p st)
2252 afs_status_t tst = 0;
2253 afs_admin_iterator_p iter = (afs_admin_iterator_p) iterationId;
2255 if (iterationId == NULL) {
2256 tst = ADMITERATIONIDPNULL;
2257 goto fail_bos_KeyGetDone;
2260 rc = IteratorDone(iter, &tst);
2262 fail_bos_KeyGetDone:
2271 * bos_CellSet - set the cell name at a bos server.
2275 * IN serverHandle - a previously opened serverHandle.
2277 * IN cellName - the new cell name.
2281 * No locks are obtained or released by this function
2285 * Returns != 0 upon successful completion.
2289 bos_CellSet(const void *serverHandle, const char *cellName, afs_status_p st)
2292 afs_status_t tst = 0;
2293 bos_server_p b_handle = (bos_server_p) serverHandle;
2295 if (!isValidServerHandle(b_handle, &tst)) {
2296 goto fail_bos_CellSet;
2299 if ((cellName == NULL) || (*cellName == 0)) {
2300 tst = ADMCLIENTCELLNAMENULL;
2301 goto fail_bos_CellSet;
2304 tst = BOZO_SetCellName(b_handle->server, cellName);
2319 * bos_CellGet - get the cell name at a bos server.
2323 * IN serverHandle - a previously opened serverHandle.
2325 * OUT cellName - the cell name.
2329 * No locks are obtained or released by this function
2333 * Returns != 0 upon successful completion.
2337 bos_CellGet(const void *serverHandle, char *cellName, afs_status_p st)
2340 afs_status_t tst = 0;
2341 bos_server_p b_handle = (bos_server_p) serverHandle;
2343 if (!isValidServerHandle(b_handle, &tst)) {
2344 goto fail_bos_CellGet;
2347 if (cellName == NULL) {
2348 tst = ADMCLIENTCELLNAMENULL;
2349 goto fail_bos_CellGet;
2352 tst = BOZO_GetCellName(b_handle->server, &cellName);
2367 * bos_HostCreate - add a new host to the cell.
2371 * IN serverHandle - a previously opened serverHandle.
2373 * IN hostName - the new host.
2377 * No locks are obtained or released by this function
2381 * Returns != 0 upon successful completion.
2385 bos_HostCreate(const void *serverHandle, const char *hostName,
2389 afs_status_t tst = 0;
2390 bos_server_p b_handle = (bos_server_p) serverHandle;
2392 if (!isValidServerHandle(b_handle, &tst)) {
2393 goto fail_bos_HostCreate;
2396 if ((hostName == NULL) || (*hostName == 0)) {
2397 tst = ADMBOSHOSTNAMENULL;
2398 goto fail_bos_HostCreate;
2401 tst = BOZO_AddCellHost(b_handle->server, hostName);
2407 fail_bos_HostCreate:
2416 * bos_HostDelete - delete a host from the cell.
2420 * IN serverHandle - a previously opened serverHandle.
2422 * IN hostName - the host.
2426 * No locks are obtained or released by this function
2430 * Returns != 0 upon successful completion.
2434 bos_HostDelete(const void *serverHandle, const char *hostName,
2438 afs_status_t tst = 0;
2439 bos_server_p b_handle = (bos_server_p) serverHandle;
2441 if (!isValidServerHandle(b_handle, &tst)) {
2442 goto fail_bos_HostDelete;
2445 if ((hostName == NULL) || (*hostName == 0)) {
2446 tst = ADMBOSHOSTNAMENULL;
2447 goto fail_bos_HostDelete;
2450 tst = BOZO_DeleteCellHost(b_handle->server, hostName);
2456 fail_bos_HostDelete:
2465 * The iterator functions and data for the host retrieval functions
2468 typedef struct host_get {
2470 struct rx_connection *server;
2471 char host[CACHED_ITEMS][BOS_MAX_NAME_LEN];
2472 } host_get_t, *host_get_p;
2475 GetHostRPC(void *rpc_specific, int slot, int *last_item,
2476 int *last_item_contains_data, afs_status_p st)
2479 afs_status_t tst = 0;
2480 host_get_p host = (host_get_p) rpc_specific;
2481 char *ptr = (char *)&host->host[slot];
2483 tst = BOZO_GetCellHost(host->server, host->next++, &ptr);
2487 } else if (tst == BZDOM) {
2491 *last_item_contains_data = 0;
2501 GetHostFromCache(void *rpc_specific, int slot, void *dest, afs_status_p st)
2504 afs_status_t tst = 0;
2505 host_get_p host = (host_get_p) rpc_specific;
2507 strcpy((char *)dest, (char *)&host->host[slot]);
2517 * bos_HostGetBegin - begin iterating over the hosts in a cell
2518 * at a particular bos server.
2522 * IN serverHandle - a previously opened serverHandle.
2524 * OUT iter - an iterator that can be passed to bos_HostGetNext
2525 * to retrieve the process names.
2529 * No locks are obtained or released by this function
2533 * Returns != 0 upon successful completion.
2538 bos_HostGetBegin(const void *serverHandle, void **iterationIdP,
2542 afs_status_t tst = 0;
2543 bos_server_p b_handle = (bos_server_p) serverHandle;
2544 afs_admin_iterator_p iter =
2545 (afs_admin_iterator_p) malloc(sizeof(afs_admin_iterator_t));
2546 host_get_p host = (host_get_p) malloc(sizeof(host_get_t));
2548 if (!isValidServerHandle(b_handle, &tst)) {
2549 goto fail_bos_HostGetBegin;
2552 if (iterationIdP == NULL) {
2553 tst = ADMITERATIONIDPNULL;
2554 goto fail_bos_HostGetBegin;
2557 if ((iter == NULL) || (host == NULL)) {
2559 goto fail_bos_HostGetBegin;
2563 host->server = b_handle->server;
2566 (iter, (void *)host, GetHostRPC, GetHostFromCache, NULL, NULL,
2568 *iterationIdP = (void *)iter;
2572 fail_bos_HostGetBegin:
2590 * bos_HostGetNext - retrieve the next host
2591 * from the bos server.
2595 * IN iterationId - an iterator previously returned by
2598 * OUT hostName - upon successful completion contains the next host
2599 * retrieved from the server.
2603 * No locks are obtained or released by this function
2607 * Returns != 0 upon successful completion.
2612 bos_HostGetNext(const void *iterationId, char *hostName, afs_status_p st)
2615 afs_status_t tst = 0;
2616 afs_admin_iterator_p iter = (afs_admin_iterator_p) iterationId;
2618 if (iterationId == NULL) {
2619 tst = ADMITERATIONIDPNULL;
2620 goto fail_bos_HostGetNext;
2623 if (hostName == NULL) {
2624 tst = ADMBOSHOSTNAMENULL;
2625 goto fail_bos_HostGetNext;
2628 rc = IteratorNext(iter, (void *)hostName, &tst);
2630 fail_bos_HostGetNext:
2639 * bos_HostGetDone - finish using a host iterator.
2643 * IN iterationId - an iterator previously returned by
2648 * No locks are obtained or released by this function
2652 * Returns != 0 upon successful completion.
2657 bos_HostGetDone(const void *iterationId, afs_status_p st)
2660 afs_status_t tst = 0;
2661 afs_admin_iterator_p iter = (afs_admin_iterator_p) iterationId;
2663 if (iterationId == NULL) {
2664 tst = ADMITERATIONIDPNULL;
2665 goto fail_bos_HostGetDone;
2668 rc = IteratorDone(iter, &tst);
2670 fail_bos_HostGetDone:
2679 * bos_ExecutableCreate - create a new executable at the bos server.
2683 * IN serverHandle - a previously opened serverHandle.
2685 * IN sourceFile - the executable to install at the bos server.
2687 * IN destFile - the location where the executable will be installed.
2691 * No locks are obtained or released by this function
2695 * Returns != 0 upon successful completion.
2700 bos_ExecutableCreate(const void *serverHandle, const char *sourceFile,
2701 const char *destFile, afs_status_p st)
2704 afs_status_t tst = 0;
2705 bos_server_p b_handle = (bos_server_p) serverHandle;
2708 struct rx_call *tcall;
2711 * Validate arguments
2714 if (!isValidServerHandle(b_handle, &tst)) {
2715 goto fail_bos_ExecutableCreate;
2718 if ((sourceFile == NULL) || (*sourceFile == 0)) {
2719 tst = ADMBOSSOURCEFILENULL;
2720 goto fail_bos_ExecutableCreate;
2723 if ((destFile == NULL) || (*destFile == 0)) {
2724 tst = ADMBOSDESTFILENULL;
2725 goto fail_bos_ExecutableCreate;
2729 * Open the file locally and compute its size
2732 fd = open(sourceFile, O_RDONLY);
2735 tst = ADMBOSCANTOPENSOURCEFILE;
2736 goto fail_bos_ExecutableCreate;
2739 if (fstat(fd, &estat)) {
2740 tst = ADMBOSCANTSTATSOURCEFILE;
2741 goto fail_bos_ExecutableCreate;
2745 * Start a split rpc to the bos server.
2748 tcall = rx_NewCall(b_handle->server);
2751 StartBOZO_Install(tcall, destFile, estat.st_size,
2752 (afs_int32) estat.st_mode, estat.st_mtime);
2755 rx_EndCall(tcall, tst);
2756 goto fail_bos_ExecutableCreate;
2760 * Copy the data to the server
2766 len = read(fd, tbuffer, sizeof(tbuffer));
2768 tst = ADMBOSCANTREADSOURCEFILE;
2769 rx_EndCall(tcall, len);
2770 goto fail_bos_ExecutableCreate;
2776 tst = rx_Write(tcall, tbuffer, len);
2778 tst = ADMBOSSENDSOURCEFILE;
2779 rx_EndCall(tcall, tst);
2780 goto fail_bos_ExecutableCreate;
2785 * Terminate the rpc to the server
2788 tst = rx_EndCall(tcall, tst);
2794 fail_bos_ExecutableCreate:
2803 * bos_ExecutableRevert - revert an executable to a previous .BAK version.
2807 * IN serverHandle - a previously opened serverHandle.
2809 * IN execFile - the executable to revert at the bos server.
2813 * No locks are obtained or released by this function
2817 * Returns != 0 upon successful completion.
2822 bos_ExecutableRevert(const void *serverHandle, const char *execFile,
2826 afs_status_t tst = 0;
2827 bos_server_p b_handle = (bos_server_p) serverHandle;
2829 if (!isValidServerHandle(b_handle, &tst)) {
2830 goto fail_bos_ExecutableRevert;
2833 if ((execFile == NULL) || (*execFile == 0)) {
2834 tst = ADMBOSEXECFILENULL;
2835 goto fail_bos_ExecutableRevert;
2838 tst = BOZO_UnInstall(b_handle->server, execFile);
2844 fail_bos_ExecutableRevert:
2853 * bos_ExecutableTimestampGet - get the last mod times for an executable,
2854 * the .BAK version of the executable, and the .OLD version of the
2855 * executable if they exist.
2859 * IN serverHandle - a previously opened serverHandle.
2861 * IN execFile - the executable to revert at the bos server.
2865 * No locks are obtained or released by this function
2869 * Returns != 0 upon successful completion.
2874 bos_ExecutableTimestampGet(const void *serverHandle, const char *execFile,
2875 unsigned long *newTime, unsigned long *oldTime,
2876 unsigned long *bakTime, afs_status_p st)
2879 afs_status_t tst = 0;
2880 bos_server_p b_handle = (bos_server_p) serverHandle;
2882 if (!isValidServerHandle(b_handle, &tst)) {
2883 goto fail_bos_ExecutableTimestampGet;
2886 if ((execFile == NULL) || (*execFile == 0)) {
2887 tst = ADMBOSEXECFILENULL;
2888 goto fail_bos_ExecutableTimestampGet;
2891 if (newTime == NULL) {
2892 tst = ADMBOSNEWTIMENULL;
2893 goto fail_bos_ExecutableTimestampGet;
2896 if (oldTime == NULL) {
2897 tst = ADMBOSOLDTIMENULL;
2898 goto fail_bos_ExecutableTimestampGet;
2901 if (bakTime == NULL) {
2902 tst = ADMBOSBAKTIMENULL;
2903 goto fail_bos_ExecutableTimestampGet;
2907 BOZO_GetDates(b_handle->server, execFile, newTime, bakTime, oldTime);
2913 fail_bos_ExecutableTimestampGet:
2922 * bos_ExecutablePrune - prune the bak, old, and core files off a server
2927 * IN serverHandle - a previously opened serverHandle.
2929 * IN oldFiles - prune .OLD files.
2931 * IN bakFiles - prune .BAK files.
2933 * IN coreFiles - prune core files.
2937 * No locks are obtained or released by this function
2941 * Returns != 0 upon successful completion.
2946 bos_ExecutablePrune(const void *serverHandle, bos_Prune_t oldFiles,
2947 bos_Prune_t bakFiles, bos_Prune_t coreFiles,
2951 afs_status_t tst = 0;
2952 bos_server_p b_handle = (bos_server_p) serverHandle;
2953 afs_int32 flags = 0;
2955 if (!isValidServerHandle(b_handle, &tst)) {
2956 goto fail_bos_ExecutablePrune;
2959 if (oldFiles == BOS_PRUNE) {
2960 flags |= BOZO_PRUNEOLD;
2963 if (bakFiles == BOS_PRUNE) {
2964 flags |= BOZO_PRUNEBAK;
2967 if (coreFiles == BOS_PRUNE) {
2968 flags |= BOZO_PRUNECORE;
2971 tst = BOZO_Prune(b_handle->server, flags);
2977 fail_bos_ExecutablePrune:
2986 * bos_ExecutableRestartTimeSet - set the restart time of the bos server
2991 * IN serverHandle - a previously opened serverHandle.
2993 * IN type - specifies either weekly restart or daily restart time.
2995 * IN time - the time to begin restarts.
2999 * No locks are obtained or released by this function
3003 * Returns != 0 upon successful completion.
3008 bos_ExecutableRestartTimeSet(const void *serverHandle, bos_Restart_t type,
3009 bos_RestartTime_t time, afs_status_p st)
3012 afs_status_t tst = 0;
3013 bos_server_p b_handle = (bos_server_p) serverHandle;
3014 afs_int32 restartType = 0;
3015 struct ktime restartTime;
3017 if (!isValidServerHandle(b_handle, &tst)) {
3018 goto fail_bos_ExecutableRestartTimeSet;
3021 if (type == BOS_RESTART_WEEKLY) {
3027 if ((time.mask & BOS_RESTART_TIME_HOUR)
3028 && ((time.hour < 0) || (time.hour > 23))) {
3029 tst = ADMBOSHOURINVALID;
3030 goto fail_bos_ExecutableRestartTimeSet;
3033 if ((time.mask & BOS_RESTART_TIME_MINUTE)
3034 && ((time.min < 0) || (time.min > 60))) {
3035 tst = ADMBOSMINUTEINVALID;
3036 goto fail_bos_ExecutableRestartTimeSet;
3039 if ((time.mask & BOS_RESTART_TIME_SECOND)
3040 && ((time.sec < 0) || (time.sec > 60))) {
3041 tst = ADMBOSSECONDINVALID;
3042 goto fail_bos_ExecutableRestartTimeSet;
3045 if ((time.mask & BOS_RESTART_TIME_DAY)
3046 && ((time.day < 0) || (time.day > 6))) {
3047 tst = ADMBOSDAYINVALID;
3048 goto fail_bos_ExecutableRestartTimeSet;
3051 restartTime.mask = time.mask;
3052 restartTime.hour = time.hour;
3053 restartTime.min = time.min;
3054 restartTime.sec = time.sec;
3055 restartTime.day = time.day;
3057 tst = BOZO_SetRestartTime(b_handle->server, restartType, &restartTime);
3063 fail_bos_ExecutableRestartTimeSet:
3072 * bos_ExecutableRestartTimeGet - get the restart time of the bos server
3077 * IN serverHandle - a previously opened serverHandle.
3079 * IN type - specifies either weekly restart or daily restart time.
3081 * OUT timeP - the time to begin restarts.
3085 * No locks are obtained or released by this function
3089 * Returns != 0 upon successful completion.
3094 bos_ExecutableRestartTimeGet(const void *serverHandle, bos_Restart_t type,
3095 bos_RestartTime_p timeP, afs_status_p st)
3098 afs_status_t tst = 0;
3099 bos_server_p b_handle = (bos_server_p) serverHandle;
3100 afs_int32 restartType = 0;
3101 struct ktime restartTime;
3103 if (!isValidServerHandle(b_handle, &tst)) {
3104 goto fail_bos_ExecutableRestartTimeGet;
3107 if (timeP == NULL) {
3108 tst = ADMBOSTIMEPNULL;
3109 goto fail_bos_ExecutableRestartTimeGet;
3112 if (type == BOS_RESTART_WEEKLY) {
3118 tst = BOZO_GetRestartTime(b_handle->server, restartType, &restartTime);
3121 goto fail_bos_ExecutableRestartTimeGet;
3124 timeP->mask = restartTime.mask;
3125 timeP->hour = restartTime.hour;
3126 timeP->min = restartTime.min;
3127 timeP->sec = restartTime.sec;
3128 timeP->day = restartTime.day;
3131 fail_bos_ExecutableRestartTimeGet:
3140 * bos_LogGet - get a log file from the bos server machine.
3144 * IN serverHandle - a previously opened serverHandle.
3146 * IN log - the log file to retrieve.
3148 * IN/OUT logBufferSizeP - the length of the logData buffer on input,
3149 * and upon successful completion, the length of data stored in the buffer.
3151 * OUT logData - the retrieved data upon successful completion.
3155 * No locks are obtained or released by this function
3159 * Returns != 0 upon successful completion.
3164 bos_LogGet(const void *serverHandle, const char *log,
3165 unsigned long *logBufferSizeP, char *logData, afs_status_p st)
3168 afs_status_t tst = 0;
3169 bos_server_p b_handle = (bos_server_p) serverHandle;
3170 struct rx_call *tcall = NULL;
3174 unsigned long bytes_read = 0;
3177 * Validate parameters
3180 if (!isValidServerHandle(b_handle, &tst)) {
3181 goto fail_bos_LogGet;
3184 if ((log == NULL) || (*log == 0)) {
3185 tst = ADMBOSLOGNULL;
3186 goto fail_bos_LogGet;
3189 if (logBufferSizeP == NULL) {
3190 tst = ADMBOSLOGBUFFERSIZEPNULL;
3191 goto fail_bos_LogGet;
3194 if (logData == NULL) {
3195 tst = ADMBOSLOGDATANULL;
3196 goto fail_bos_LogGet;
3200 * Begin to retrieve the data
3203 tcall = rx_NewCall(b_handle->server);
3205 tst = StartBOZO_GetLog(tcall, log);
3208 goto fail_bos_LogGet;
3212 * Read the log file data
3216 error = rx_Read(tcall, &buffer, 1);
3218 tst = ADMBOSLOGFILEERROR;
3219 goto fail_bos_LogGet;
3223 * check for the end of the log
3227 *logBufferSizeP = bytes_read;
3232 * We've successfully read another byte, copy it to logData
3237 if (bytes_read <= *logBufferSizeP) {
3238 *logData++ = buffer;
3250 rx_EndCall(tcall, 0);
3260 * bos_AuthSet - set the authorization level required at the bos server.
3264 * IN serverHandle - a previously opened serverHandle.
3266 * IN auth - specifies the new auth level.
3270 * No locks are obtained or released by this function
3274 * Returns != 0 upon successful completion.
3279 bos_AuthSet(const void *serverHandle, bos_Auth_t auth, afs_status_p st)
3282 afs_status_t tst = 0;
3283 bos_server_p b_handle = (bos_server_p) serverHandle;
3284 afs_int32 level = 0;
3286 if (!isValidServerHandle(b_handle, &tst)) {
3287 goto fail_bos_AuthSet;
3290 if (auth == BOS_AUTH_REQUIRED) {
3296 tst = BOZO_SetNoAuthFlag(b_handle->server, level);
3311 * bos_CommandExecute - execute a command at the bos server.
3315 * IN serverHandle - a previously opened serverHandle.
3317 * IN command - the command to execute.
3321 * No locks are obtained or released by this function
3325 * Returns != 0 upon successful completion.
3330 bos_CommandExecute(const void *serverHandle, const char *command,
3334 afs_status_t tst = 0;
3335 bos_server_p b_handle = (bos_server_p) serverHandle;
3337 if (!isValidServerHandle(b_handle, &tst)) {
3338 goto fail_bos_CommandExecute;
3341 if ((command == NULL) || (*command == 0)) {
3342 tst = ADMBOSCOMMANDNULL;
3343 goto fail_bos_CommandExecute;
3346 tst = BOZO_Exec(b_handle->server, command);
3352 fail_bos_CommandExecute:
3361 * bos_Salvage - perform a remote salvage operation.
3365 * IN cellHandle - a previously opened cellHandle.
3367 * IN serverHandle - a previously opened serverHandle.
3369 * IN partitionName - the partition to salvage. Can be null.
3371 * IN volumeName - the volume to salvage. Can be null, if non-null,
3372 * partitionName cannot be null.
3374 * IN numSalvagers - the number of salvage processes to run in parallel.
3376 * IN tmpDir - directory to place temporary files. Can be null.
3378 * IN logFile - file where salvage log will be written. Can be null.
3380 * IN force - sets salvager -force flag.
3382 * IN salvageDamagedVolumes - sets salvager -oktozap flag.
3384 * IN writeInodes - sets salvager -inodes flag.
3386 * IN writeRootInodes - sets salvager -rootinodes flag.
3388 * IN forceDirectory - sets salvager -salvagedirs flag.
3390 * IN forceBlockRead - sets salvager -blockread flag.
3394 * No locks are obtained or released by this function
3398 * Returns != 0 upon successful completion.
3402 #define INITIAL_LOG_LEN 4096
3405 bos_Salvage(const void *cellHandle, const void *serverHandle,
3406 const char *partitionName, const char *volumeName,
3407 int numSalvagers, const char *tmpDir, const char *logFile,
3409 bos_SalvageDamagedVolumes_t salvageDamagedVolumes,
3410 bos_WriteInodes_t writeInodes,
3411 bos_WriteRootInodes_t writeRootInodes,
3412 bos_ForceDirectory_t forceDirectory,
3413 bos_ForceBlockRead_t forceBlockRead, afs_status_p st)
3416 afs_status_t tst = 0;
3417 bos_server_p b_handle = (bos_server_p) serverHandle;
3418 afs_cell_handle_p c_handle = (afs_cell_handle_p) cellHandle;
3419 int have_partition = 0;
3420 int have_volume = 0;
3421 unsigned int part = 0;
3422 int try_to_stop_fileserver = 0;
3423 bos_ProcessType_t procType;
3424 bos_ProcessInfo_t procInfo;
3426 char command[BOS_MAX_NAME_LEN];
3427 int command_len = 0;
3429 char *logData = NULL;
3430 unsigned long logLen = INITIAL_LOG_LEN;
3433 * Validate arguments
3436 if (!IsValidCellHandle(c_handle, &tst)) {
3437 goto fail_bos_Salvage;
3440 if (!isValidServerHandle(b_handle, &tst)) {
3441 goto fail_bos_Salvage;
3444 if (c_handle->vos_valid == 0) {
3445 tst = ADMBOSCELLHANDLENOVOS;
3446 goto fail_bos_Salvage;
3449 if ((partitionName != NULL) && (*partitionName != 0)) {
3450 if (!vos_PartitionNameToId(partitionName, &part, &tst)) {
3451 goto fail_bos_Salvage;
3456 if ((volumeName != NULL) && (*volumeName != 0)) {
3457 if (!have_partition) {
3458 tst = ADMBOSSALVAGEVOLUME;
3459 goto fail_bos_Salvage;
3464 if ((logFile != NULL) && (*logFile != 0)) {
3465 log = fopen(logFile, "w");
3467 tst = ADMBOSSALVAGEBADLOG;
3468 goto fail_bos_Salvage;
3473 * If we are salvaging more than a single volume, stop the fileserver
3477 try_to_stop_fileserver = 1;
3481 * Only try to stop the fileserver if it is running
3484 if (try_to_stop_fileserver) {
3485 if (bos_ProcessInfoGet
3486 (serverHandle, "fs", &procType, &procInfo, &tst)) {
3487 if (procInfo.processGoal != BOS_PROCESS_RUNNING) {
3488 try_to_stop_fileserver = 0;
3494 * Make the call to stop the fileserver and wait for it to shutdown
3497 if (try_to_stop_fileserver) {
3498 if (!bos_ProcessExecutionStateSetTemporary
3499 (serverHandle, "fs", BOS_PROCESS_STOPPED, &tst)) {
3500 goto fail_bos_Salvage;
3502 bos_ProcessAllWaitTransition(serverHandle, &tst);
3506 * Create the salvage command line arguments
3510 sprintf(command, "%s ", AFSDIR_CANONICAL_SERVER_SALVAGER_FILEPATH);
3511 if (have_partition) {
3513 sprintf(&command[command_len], "-partition %s ", partitionName);
3518 sprintf(&command[command_len], "-volumeid %s ", volumeName);
3521 if (salvageDamagedVolumes == BOS_DONT_SALVAGE_DAMAGED_VOLUMES) {
3522 command_len += sprintf(&command[command_len], "-nowrite ");
3525 if (writeInodes == BOS_SALVAGE_WRITE_INODES) {
3526 command_len += sprintf(&command[command_len], "-inodes ");
3529 if (force == VOS_FORCE) {
3530 command_len += sprintf(&command[command_len], "-force ");
3533 if (writeRootInodes == BOS_SALVAGE_WRITE_ROOT_INODES) {
3534 command_len += sprintf(&command[command_len], "-rootinodes ");
3537 if (forceDirectory == BOS_SALVAGE_FORCE_DIRECTORIES) {
3538 command_len += sprintf(&command[command_len], "-salvagedirs ");
3541 if (forceBlockRead == BOS_SALVAGE_FORCE_BLOCK_READS) {
3542 command_len += sprintf(&command[command_len], "-blockreads ");
3546 sprintf(&command[command_len], "-parallel %d ", numSalvagers);
3548 if ((tmpDir != NULL) && (*tmpDir != 0)) {
3549 command_len += sprintf(&command[command_len], "-tmpdir %s ", tmpDir);
3552 if (command_len > BOS_MAX_NAME_LEN) {
3553 tst = ADMBOSSALVAGEBADOPTIONS;
3554 goto fail_bos_Salvage;
3558 * Create the process at the bosserver and wait until it completes
3561 if (!bos_ProcessCreate
3562 (serverHandle, "salvage-tmp", BOS_PROCESS_CRON, command, "now", 0,
3564 goto fail_bos_Salvage;
3568 bos_ProcessInfoGet(serverHandle, "salvage-tmp", &procType,
3569 &procInfo, &tst))) {
3573 if (tst != BZNOENT) {
3574 goto fail_bos_Salvage;
3578 * Print out the salvage log if required by the user
3583 logData = (char *)malloc(INITIAL_LOG_LEN);
3586 goto fail_bos_Salvage;
3590 (serverHandle, AFSDIR_CANONICAL_SERVER_SLVGLOG_FILEPATH,
3591 &logLen, logData, &tst)) {
3592 if (logLen > INITIAL_LOG_LEN) {
3593 logData = (char *)realloc(logData, (logLen + (logLen / 10)));
3594 if (logData == NULL) {
3596 goto fail_bos_Salvage;
3599 goto fail_bos_Salvage;
3602 fprintf(log, "SalvageLog:\n%s", logData);
3606 * Restart the fileserver if we had stopped it previously
3609 if (try_to_stop_fileserver) {
3610 try_to_stop_fileserver = 0;
3611 if (!bos_ProcessExecutionStateSetTemporary
3612 (serverHandle, "fs", BOS_PROCESS_RUNNING, &tst)) {
3613 goto fail_bos_Salvage;
3624 if (logData != NULL) {
3628 if (try_to_stop_fileserver) {
3629 bos_ProcessExecutionStateSetTemporary(serverHandle, "fs",
3630 BOS_PROCESS_RUNNING, 0);