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
12 #include "afs_bosAdmin.h"
13 #include "../adminutil/afs_AdminInternal.h"
14 #include <afs/afs_AdminErrors.h>
15 #include <afs/afs_utilAdmin.h>
16 #include <afs/bosint.h>
17 #include <afs/bnode.h>
18 #include <afs/ktime.h>
19 #include <afs/dirpath.h>
21 #include <sys/types.h>
32 * Prototypes for functions that don't exist in any header files
35 extern int BOZO_AddCellHost();
36 extern int BOZO_AddKey();
37 extern int BOZO_AddSUser();
38 extern int BOZO_CreateBnode();
39 extern int BOZO_DeleteBnode();
40 extern int BOZO_DeleteCellHost();
41 extern int BOZO_DeleteKey();
42 extern int BOZO_DeleteSUser();
43 extern int BOZO_EnumerateInstance();
44 extern int BOZO_Exec();
45 extern int BOZO_GetCellHost();
46 extern int BOZO_GetCellName();
47 extern int BOZO_GetDates();
48 extern int BOZO_GetInstanceInfo();
49 extern int BOZO_GetInstanceParm();
50 extern int BOZO_GetInstanceParm();
51 extern int BOZO_GetRestartTime();
52 extern int BOZO_GetStatus();
53 extern int BOZO_ListSUsers();
54 extern int BOZO_ListKeys();
55 extern int BOZO_Prune();
56 extern int BOZO_ReBozo();
57 extern int BOZO_Restart();
58 extern int BOZO_RestartAll();
59 extern int BOZO_SetCellName();
60 extern int BOZO_SetNoAuthFlag();
61 extern int BOZO_SetRestartTime();
62 extern int BOZO_SetStatus(struct rx_connection *, const char *, long);
63 extern int BOZO_SetTStatus(struct rx_connection *, const char *, long);
64 extern int BOZO_ShutdownAll();
65 extern int BOZO_StartupAll();
66 extern int BOZO_UnInstall();
67 extern int BOZO_WaitAll();
68 extern int StartBOZO_GetLog();
69 extern int StartBOZO_Install();
71 typedef struct bos_server {
74 struct rx_connection *server;
75 struct rx_connection *server_encrypt;
76 struct rx_connection *server_stats;
78 } bos_server_t, *bos_server_p;
81 * isValidServerHandle - validate a bos_server_p.
85 * IN serverHandle - the handle to validate
89 * No locks are obtained or released by this function
93 * Returns != 0 upon successful completion.
96 int isValidServerHandle (
97 const bos_server_p serverHandle,
101 afs_status_t tst = 0;
103 if (serverHandle == NULL) {
104 tst = ADMBOSSERVERHANDLENULL;
105 goto fail_IsValidServerHandle;
108 if ((serverHandle->begin_magic != BEGIN_MAGIC) ||
109 (serverHandle->end_magic != END_MAGIC)) {
110 tst = ADMBOSSERVERHANDLEBADMAGIC;
111 goto fail_IsValidServerHandle;
114 if (serverHandle->is_valid == 0) {
115 tst = ADMBOSSERVERHANDLEINVALID;
116 goto fail_IsValidServerHandle;
119 if (serverHandle->server == NULL) {
120 tst = ADMBOSSERVERHANDLENOSERVER;
121 goto fail_IsValidServerHandle;
124 if (serverHandle->server_encrypt == NULL) {
125 tst = ADMBOSSERVERHANDLENOSERVER;
126 goto fail_IsValidServerHandle;
130 fail_IsValidServerHandle:
138 * IsValidCellHandle - verify that a cell handle can be used to make bos
143 * IN cellHandle - the cellHandle to be validated.
147 * No locks are obtained or released by this function
151 * Returns != 0 upon successful completion.
154 static int IsValidCellHandle(
155 afs_cell_handle_p cellHandle,
159 afs_status_t tst = 0;
161 if (!CellHandleIsValid((void *) cellHandle, &tst)) {
162 goto fail_IsValidCellHandle;
165 if (cellHandle->tokens == NULL) {
166 tst = ADMBOSCELLHANDLENOTOKENS;
167 goto fail_IsValidCellHandle;
171 fail_IsValidCellHandle:
180 * bos_ServerOpen - open a bos server for work.
184 * IN cellHandle - a previously opened cellHandle.
186 * IN serverName - the name of the machine that houses the bosserver of
189 * OUT serverHandleP - upon successful completion, this void pointer
190 * will point to a valid server handle for use in future operations.
194 * No locks are obtained or released by this function
198 * Returns != 0 upon successful completion.
201 int ADMINAPI bos_ServerOpen(
202 const void *cellHandle,
203 const char *serverName,
204 void **serverHandleP,
208 afs_status_t tst = 0;
209 afs_cell_handle_p c_handle = (afs_cell_handle_p) cellHandle;
210 bos_server_p bos_server = (bos_server_p) malloc(sizeof(bos_server_t));
214 * Validate parameters
217 if (!IsValidCellHandle(c_handle, &tst)) {
218 goto fail_bos_ServerOpen;
221 if ((serverName == NULL) || (*serverName == 0)) {
222 tst = ADMBOSSERVERNAMENULL;
223 goto fail_bos_ServerOpen;
226 if (serverHandleP == NULL) {
227 tst = ADMBOSSERVERHANDLEPNULL;
228 goto fail_bos_ServerOpen;
231 if (util_AdminServerAddressGetFromName(serverName, &serverAddress, &tst) == 0) {
232 goto fail_bos_ServerOpen;
235 if (bos_server == NULL) {
237 goto fail_bos_ServerOpen;
240 bos_server->server = rx_GetCachedConnection(htonl(serverAddress),
241 htons(AFSCONF_NANNYPORT), 1,
242 c_handle->tokens->afs_sc[c_handle->tokens->sc_index], c_handle->tokens->sc_index);
244 bos_server->server_encrypt = rx_GetCachedConnection(htonl(serverAddress),
245 htons(AFSCONF_NANNYPORT), 1,
246 c_handle->tokens->afs_encrypt_sc[c_handle->tokens->sc_index], c_handle->tokens->sc_index);
248 bos_server->server_stats = rx_GetCachedConnection(htonl(serverAddress),
249 htons(AFSCONF_NANNYPORT),
251 c_handle->tokens->afs_sc[c_handle->tokens->sc_index], c_handle->tokens->sc_index);
253 if ((bos_server->server == NULL) || (bos_server->server_encrypt == NULL)) {
254 tst = ADMBOSSERVERNOCONNECTION;
255 goto fail_bos_ServerOpen;
258 bos_server->begin_magic = BEGIN_MAGIC;
259 bos_server->is_valid = 1;
260 bos_server->end_magic = END_MAGIC;
262 *serverHandleP = (void *) bos_server;
267 if ((rc == 0) && (bos_server != NULL)) {
268 if (bos_server->server) {
269 rx_ReleaseCachedConnection(bos_server->server);
271 if (bos_server->server_encrypt) {
272 rx_ReleaseCachedConnection(bos_server->server_encrypt);
284 * bos_ServerClose - close a bos server handle
288 * IN serverHandle - a bos server handle previously returned by bos_ServerOpen
292 * No locks are obtained or released by this function
296 * Returns != 0 upon successful completion.
299 int ADMINAPI bos_ServerClose(
300 const void *serverHandle,
304 afs_status_t tst = 0;
305 bos_server_p b_handle = (bos_server_p) serverHandle;
307 if (isValidServerHandle(b_handle, &tst)) {
308 rx_ReleaseCachedConnection(b_handle->server);
309 b_handle->is_valid = 0;
321 * bos_ProcessCreate - create a new process to run at a bos server.
325 * IN serverHandle - a previously opened serverHandle.
327 * IN processName - the name of the process to create.
329 * IN processType - the type of process to create.
331 * IN process - the path to the process binary at the bos server.
333 * IN cronTime - the time specification for cron processes.
335 * IN notifier - the path to the notifier binary at the bos server.
339 * No locks are obtained or released by this function
343 * Returns != 0 upon successful completion.
347 * CAUTION - this list must match bos_ProcessType_t definition
350 static char *processTypes[] = {"simple", "fs", "cron", 0};
352 int ADMINAPI bos_ProcessCreate(
353 const void *serverHandle,
354 const char *processName,
355 bos_ProcessType_t processType,
357 const char *cronTime,
358 const char *notifier,
362 afs_status_t tst = 0;
363 bos_server_p b_handle = (bos_server_p) serverHandle;
365 if (!isValidServerHandle(b_handle, &tst)) {
366 goto fail_bos_ProcessCreate;
369 if (processType == BOS_PROCESS_FS) {
370 tst = ADMBOSPROCESSCREATEBADTYPE;
371 goto fail_bos_ProcessCreate;
374 if ((processName == NULL) || (*processName == 0)) {
375 tst = ADMBOSPROCESSNAMENULL;
376 goto fail_bos_ProcessCreate;
379 if ((process == NULL) || (*process == 0)) {
380 tst = ADMBOSPROCESSNULL;
381 goto fail_bos_ProcessCreate;
384 if ((processType == BOS_PROCESS_CRON) && (cronTime == NULL)) {
385 tst = ADMBOSCRONTIMENULL;
386 goto fail_bos_ProcessCreate;
389 if ((processType == BOS_PROCESS_SIMPLE) && (cronTime != NULL)) {
390 tst = ADMBOSCRONTIMENOTNULL;
391 goto fail_bos_ProcessCreate;
394 tst = BOZO_CreateBnode(b_handle->server, processTypes[processType],
395 processName, process,
396 (cronTime) ? cronTime : "", "", "", "",
397 (notifier) ? notifier : NONOTIFIER);
402 fail_bos_ProcessCreate:
411 * bos_FSProcessCreate - create the fs group of processes at the boserver.
415 * IN serverHandle - a previously opened serverHandle.
417 * IN processName - the name of the process to create.
419 * IN fileserverPath - the path to the fileserver binary at the bos server.
421 * IN volserverPath - the path to the volserver binary at the bos server.
423 * IN salvagerPath - the path to the salvager binary at the bos server.
425 * IN notifier - the path to the notifier binary at the bos server.
429 * No locks are obtained or released by this function
433 * Returns != 0 upon successful completion.
436 int ADMINAPI bos_FSProcessCreate(
437 const void *serverHandle,
438 const char *processName,
439 const char *fileserverPath,
440 const char *volserverPath,
441 const char *salvagerPath,
442 const char *notifier,
446 afs_status_t tst = 0;
447 bos_server_p b_handle = (bos_server_p) serverHandle;
449 if (!isValidServerHandle(b_handle, &tst)) {
450 goto fail_bos_ProcessCreate;
453 if ((processName == NULL) || (*processName == 0)) {
454 tst = ADMBOSPROCESSNAMENULL;
455 goto fail_bos_ProcessCreate;
458 if ((fileserverPath == NULL) || (*fileserverPath == 0)) {
459 tst = ADMBOSFILESERVERPATHNULL;
460 goto fail_bos_ProcessCreate;
463 if ((volserverPath == NULL) || (*volserverPath == 0)) {
464 tst = ADMBOSVOLSERVERPATHNULL;
465 goto fail_bos_ProcessCreate;
468 if ((salvagerPath == NULL) || (*salvagerPath == 0)) {
469 tst = ADMBOSSALVAGERPATHNULL;
470 goto fail_bos_ProcessCreate;
473 tst = BOZO_CreateBnode(b_handle->server,
474 processTypes[BOS_PROCESS_FS],
481 (notifier) ? notifier : NONOTIFIER);
486 fail_bos_ProcessCreate:
495 * bos_ProcessDelete - delete an existing process at a bos server.
499 * IN serverHandle - a previously opened serverHandle.
501 * IN processName - the name of the process to delete.
505 * No locks are obtained or released by this function
509 * Returns != 0 upon successful completion.
512 int ADMINAPI bos_ProcessDelete(
513 const void *serverHandle,
514 const char *processName,
518 afs_status_t tst = 0;
519 bos_server_p b_handle = (bos_server_p) serverHandle;
521 if (!isValidServerHandle(b_handle, &tst)) {
522 goto fail_bos_ProcessDelete;
525 if ((processName == NULL) || (*processName == 0)) {
526 tst = ADMBOSPROCESSNAMENULL;
527 goto fail_bos_ProcessDelete;
530 tst = BOZO_DeleteBnode(b_handle->server, processName);
536 fail_bos_ProcessDelete:
545 * bos_ProcessExecutionStateGet - get the current execution state of a
550 * IN serverHandle - a previously opened serverHandle.
552 * IN processName - the name of the process to retrieve.
554 * OUT processStatusP - upon successful completion the process execution state
556 * OUT auxiliaryProcessStatus - set to point to aux proc status if available.
557 * Pass a pointer to an char array at least BOS_MAX_NAME_LEN long.
561 * No locks are obtained or released by this function
565 * Returns != 0 upon successful completion.
568 int ADMINAPI bos_ProcessExecutionStateGet(
569 const void *serverHandle,
570 const char *processName,
571 bos_ProcessExecutionState_p processStatusP,
572 char *auxiliaryProcessStatus,
576 afs_status_t tst = 0;
577 bos_server_p b_handle = (bos_server_p) serverHandle;
580 if (!isValidServerHandle(b_handle, &tst)) {
581 goto fail_bos_ProcessExecutionStateGet;
584 if ((processName == NULL) || (*processName == 0)) {
585 tst = ADMBOSPROCESSNAMENULL;
586 goto fail_bos_ProcessExecutionStateGet;
589 if (processStatusP == NULL) {
590 tst = ADMBOSPROCESSSTATUSPNULL;
591 goto fail_bos_ProcessExecutionStateGet;
594 if (auxiliaryProcessStatus == NULL) {
595 tst = ADMBOSAUXILIARYPROCESSSTATUSNULL;
596 goto fail_bos_ProcessExecutionStateGet;
599 tst = BOZO_GetStatus(b_handle->server, processName, &state, &auxiliaryProcessStatus);
602 goto fail_bos_ProcessExecutionStateGet;
605 *processStatusP = (bos_ProcessExecutionState_t) state;
608 fail_bos_ProcessExecutionStateGet:
617 * SetExecutionState - set the execution state of a process
621 * IN serverHandle - a previously opened serverHandle.
623 * IN processName - the name of the process to modify.
625 * IN processStatus - the new process state.
627 * IN func - the function to call to set the status.
631 * No locks are obtained or released by this function
635 * Returns != 0 upon successful completion.
638 static int SetExecutionState(
639 const void *serverHandle,
640 const char *processName,
641 const bos_ProcessExecutionState_t processStatus,
642 int (*func)(struct rx_connection *, const char *, afs_int32),
646 afs_status_t tst = 0;
647 bos_server_p b_handle = (bos_server_p) serverHandle;
650 if (!isValidServerHandle(b_handle, &tst)) {
651 goto fail_SetExecutionState;
654 if ((processName == NULL) || (*processName == 0)) {
655 tst = ADMBOSPROCESSNAMENULL;
656 goto fail_SetExecutionState;
659 if ((processStatus != BOS_PROCESS_STOPPED) &&
660 (processStatus != BOS_PROCESS_RUNNING)) {
661 tst = ADMBOSPROCESSSTATUSSET;
662 goto fail_SetExecutionState;
665 state = (afs_int32) processStatus;
667 tst = func(b_handle->server, processName, state);
673 fail_SetExecutionState:
682 * bos_ProcessExecutionStateSet - set the execution state of a process
686 * IN serverHandle - a previously opened serverHandle.
688 * IN processName - the name of the process to modify.
690 * IN processStatus - the new process state.
694 * No locks are obtained or released by this function
698 * Returns != 0 upon successful completion.
701 int ADMINAPI bos_ProcessExecutionStateSet(
702 const void *serverHandle,
703 const char *processName,
704 bos_ProcessExecutionState_t processStatus,
707 return SetExecutionState(serverHandle, processName, processStatus,
712 * bos_ProcessExecutionStateSetTemporary - set the execution state of a process
717 * IN serverHandle - a previously opened serverHandle.
719 * IN processName - the name of the process to modify.
721 * IN processStatus - the new process state.
725 * No locks are obtained or released by this function
729 * Returns != 0 upon successful completion.
732 int ADMINAPI bos_ProcessExecutionStateSetTemporary(
733 const void *serverHandle,
734 const char *processName,
735 bos_ProcessExecutionState_t processStatus,
738 return SetExecutionState(serverHandle, processName, processStatus,
739 BOZO_SetTStatus, st);
743 * The iterator functions and data for the process name retrieval functions
746 typedef struct process_name_get {
748 struct rx_connection *server;
749 char process[CACHED_ITEMS][BOS_MAX_NAME_LEN];
750 } process_name_get_t, *process_name_get_p;
752 static int GetProcessNameRPC(
756 int *last_item_contains_data,
760 afs_status_t tst = 0;
761 process_name_get_p proc = (process_name_get_p) rpc_specific;
762 char *ptr = (char *) &proc->process[slot];
764 tst = BOZO_EnumerateInstance(proc->server, proc->next++, &ptr);
768 } else if (tst == BZDOM) {
772 *last_item_contains_data = 0;
781 static int GetProcessNameFromCache(
788 afs_status_t tst = 0;
789 process_name_get_p proc = (process_name_get_p) rpc_specific;
791 strcpy((char *) dest, (char *) &proc->process[slot]);
801 * bos_ProcessNameGetBegin - begin iterating over the list of processes
802 * at a particular bos server.
806 * IN serverHandle - a previously opened serverHandle.
808 * OUT iter - an iterator that can be passed to bos_ProcessNameGetNext
809 * to retrieve the process names.
813 * No locks are obtained or released by this function
817 * Returns != 0 upon successful completion.
821 int ADMINAPI bos_ProcessNameGetBegin(
822 const void *serverHandle,
827 afs_status_t tst = 0;
828 bos_server_p b_handle = (bos_server_p) serverHandle;
829 afs_admin_iterator_p iter = (afs_admin_iterator_p) malloc(sizeof(afs_admin_iterator_t));
830 process_name_get_p proc = (process_name_get_p) malloc(sizeof(process_name_get_t));
832 if (!isValidServerHandle(b_handle, &tst)) {
833 goto fail_bos_ProcessNameGetBegin;
836 if (iterationIdP == NULL) {
837 tst = ADMITERATIONIDPNULL;
838 goto fail_bos_ProcessNameGetBegin;
841 if ((iter == NULL) || (proc == NULL)) {
843 goto fail_bos_ProcessNameGetBegin;
847 proc->server = b_handle->server;
849 if (IteratorInit(iter, (void *) proc, GetProcessNameRPC, GetProcessNameFromCache, NULL, NULL, &tst)) {
850 *iterationIdP = (void *) iter;
852 goto fail_bos_ProcessNameGetBegin;
856 fail_bos_ProcessNameGetBegin:
874 * bos_ProcessNameGetNext - retrieve the next process name from the bos server.
878 * IN iterationId - an iterator previously returned by bos_ProcessNameGetBegin
880 * OUT processName - upon successful completion contains the next process name
881 * retrieved from the server.
885 * No locks are obtained or released by this function
889 * Returns != 0 upon successful completion.
893 int ADMINAPI bos_ProcessNameGetNext(
894 const void *iterationId,
899 afs_status_t tst = 0;
900 afs_admin_iterator_p iter = (afs_admin_iterator_p) iterationId;
902 if (processName == NULL) {
903 tst = ADMBOSPROCESSNAMENULL;
904 goto fail_bos_ProcessNameGetNext;
907 if (iterationId == NULL) {
908 tst = ADMITERATIONIDPNULL;
909 goto fail_bos_ProcessNameGetNext;
912 rc = IteratorNext(iter, (void *) processName, &tst);
914 fail_bos_ProcessNameGetNext:
923 * bos_ProcessNameGetDone - finish using a process name iterator.
927 * IN iterationId - an iterator previously returned by bos_ProcessNameGetBegin
931 * No locks are obtained or released by this function
935 * Returns != 0 upon successful completion.
939 int ADMINAPI bos_ProcessNameGetDone(
940 const void *iterationId,
944 afs_status_t tst = 0;
945 afs_admin_iterator_p iter = (afs_admin_iterator_p) iterationId;
947 if (iterationId == NULL) {
948 tst = ADMITERATIONIDPNULL;
949 goto fail_bos_ProcessNameGetDone;
952 rc = IteratorDone(iter, &tst);
954 fail_bos_ProcessNameGetDone:
963 * bos_ProcessInfoGet - get information about a single process
967 * IN serverHandle - a previously opened serverHandle.
969 * IN processName - the process of interest.
971 * OUT processTypeP - upon successful completion contains the process type
973 * OUT processInfoP - upon successful completion contains the process info
977 * No locks are obtained or released by this function
981 * Returns != 0 upon successful completion.
985 int ADMINAPI bos_ProcessInfoGet(
986 const void *serverHandle,
987 const char *processName,
988 bos_ProcessType_p processTypeP,
989 bos_ProcessInfo_p processInfoP,
993 afs_status_t tst = 0;
994 bos_server_p b_handle = (bos_server_p) serverHandle;
995 char type[BOS_MAX_NAME_LEN];
997 struct bozo_status status;
1000 if (!isValidServerHandle(b_handle, &tst)) {
1001 goto fail_bos_ProcessInfoGet;
1004 if ((processName == NULL) || (*processName == 0)) {
1005 tst = ADMBOSPROCESSNAMENULL;
1006 goto fail_bos_ProcessInfoGet;
1009 if (processTypeP == NULL) {
1010 tst = ADMBOSPROCESSTYPEPNULL;
1011 goto fail_bos_ProcessInfoGet;
1014 if (processInfoP == NULL) {
1015 tst = ADMBOSPROCESSINFOPNULL;
1016 goto fail_bos_ProcessInfoGet;
1019 tst = BOZO_GetInstanceInfo(b_handle->server, processName, &ptr, &status);
1022 goto fail_bos_ProcessInfoGet;
1026 for(i=0;(processTypes[i] != NULL); i++) {
1027 if (!strcmp(processTypes[i], type)) {
1028 *processTypeP = (bos_ProcessType_t) i;
1033 if (processTypes[i] == NULL) {
1034 tst = ADMBOSINVALIDPROCESSTYPE;
1035 goto fail_bos_ProcessInfoGet;
1038 processInfoP->processGoal = (bos_ProcessExecutionState_t) status.goal;
1039 processInfoP->processStartTime = status.procStartTime;
1040 processInfoP->numberProcessStarts = status.procStarts;
1041 processInfoP->processExitTime = status.lastAnyExit;
1042 processInfoP->processExitErrorTime = status.lastErrorExit;
1043 processInfoP->processErrorCode = status.errorCode;
1044 processInfoP->processErrorSignal = status.errorSignal;
1045 processInfoP->state = BOS_PROCESS_OK;
1047 if (status.flags & BOZO_ERRORSTOP) {
1048 processInfoP->state |= BOS_PROCESS_TOO_MANY_ERRORS;
1050 if (status.flags & BOZO_HASCORE) {
1051 processInfoP->state |= BOS_PROCESS_CORE_DUMPED;
1053 if (status.flags & BOZO_BADDIRACCESS) {
1054 processInfoP->state |= BOS_PROCESS_BAD_FILE_ACCESS;
1058 fail_bos_ProcessInfoGet:
1067 * The iterator functions and data for the parameter retrieval functions
1070 typedef struct param_get {
1072 struct rx_connection *server;
1073 char processName[BOS_MAX_NAME_LEN];
1074 char param[CACHED_ITEMS][BOS_MAX_NAME_LEN];
1075 } param_get_t, *param_get_p;
1077 static int GetParameterRPC(
1081 int *last_item_contains_data,
1085 afs_status_t tst = 0;
1086 param_get_p param = (param_get_p) rpc_specific;
1087 char *ptr = (char *) ¶m->param[slot];
1089 tst = BOZO_GetInstanceParm(param->server, param->processName,
1090 param->next++, &ptr);
1094 } else if (tst == BZDOM) {
1098 *last_item_contains_data = 0;
1107 static int GetParameterFromCache(
1114 afs_status_t tst = 0;
1115 param_get_p param = (param_get_p) rpc_specific;
1117 strcpy((char *) dest, (char *) ¶m->param[slot]);
1127 * bos_ProcessParameterGetBegin - begin iterating over the parameters
1128 * of a particular process.
1132 * IN serverHandle - a previously opened serverHandle.
1134 * IN processName - the process whose parameters are returned.
1136 * OUT iter - an iterator that can be passed to bos_ProcessParameterGetNext
1137 * to retrieve the parameters.
1141 * No locks are obtained or released by this function
1145 * Returns != 0 upon successful completion.
1149 int ADMINAPI bos_ProcessParameterGetBegin(
1150 const void *serverHandle,
1151 const char *processName,
1152 void **iterationIdP,
1156 afs_status_t tst = 0;
1157 bos_server_p b_handle = (bos_server_p) serverHandle;
1158 afs_admin_iterator_p iter = (afs_admin_iterator_p) malloc(sizeof(afs_admin_iterator_t));
1159 param_get_p param = (param_get_p) malloc(sizeof(param_get_t));
1161 if (!isValidServerHandle(b_handle, &tst)) {
1162 goto fail_bos_ProcessParameterGetBegin;
1165 if ((processName == NULL) || (*processName == 0)) {
1166 tst = ADMBOSPROCESSNAMENULL;
1167 goto fail_bos_ProcessParameterGetBegin;
1170 if (iterationIdP == NULL) {
1171 tst = ADMITERATIONIDPNULL;
1172 goto fail_bos_ProcessParameterGetBegin;
1175 if ((iter == NULL) || (param == NULL)) {
1177 goto fail_bos_ProcessParameterGetBegin;
1181 param->server = b_handle->server;
1182 strcpy(param->processName, processName);
1184 if (IteratorInit(iter, (void *) param, GetParameterRPC,
1185 GetParameterFromCache, NULL, NULL, &tst)) {
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.
1231 int ADMINAPI bos_ProcessParameterGetNext(
1232 const void *iterationId,
1237 afs_status_t tst = 0;
1238 afs_admin_iterator_p iter = (afs_admin_iterator_p) iterationId;
1240 if (iterationId == NULL) {
1241 tst = ADMITERATIONIDPNULL;
1242 goto fail_bos_ProcessParameterGetNext;
1245 if (parameter == NULL) {
1246 tst = ADMBOSPARAMETERNULL;
1247 goto fail_bos_ProcessParameterGetNext;
1250 rc = IteratorNext(iter, (void *) parameter, &tst);
1252 fail_bos_ProcessParameterGetNext:
1261 * bos_ProcessParameterGetDone - finish using a process name iterator.
1265 * IN iterationId - an iterator previously returned by
1266 * bos_ProcessParameterGetBegin
1270 * No locks are obtained or released by this function
1274 * Returns != 0 upon successful completion.
1278 int ADMINAPI bos_ProcessParameterGetDone(
1279 const void *iterationId,
1283 afs_status_t tst = 0;
1284 afs_admin_iterator_p iter = (afs_admin_iterator_p) iterationId;
1286 if (iterationId == NULL) {
1287 tst = ADMITERATIONIDPNULL;
1288 goto fail_bos_ProcessParameterGetDone;
1291 rc = IteratorDone(iter, &tst);
1293 fail_bos_ProcessParameterGetDone:
1302 * bos_ProcessNotifierGet - retrieve the notifier associated with a
1307 * IN serverHandle - a previously opened serverHandle.
1309 * IN processName - the process whose notifier we are retrieving.
1311 * OUT notifier - upon successful completion contains the notifier.
1315 * No locks are obtained or released by this function
1319 * Returns != 0 upon successful completion.
1323 int ADMINAPI bos_ProcessNotifierGet(
1324 const void *serverHandle,
1325 const char *processName,
1330 afs_status_t tst = 0;
1331 bos_server_p b_handle = (bos_server_p) serverHandle;
1333 if (!isValidServerHandle(b_handle, &tst)) {
1334 goto fail_bos_ProcessNotifierGet;
1337 if ((processName == NULL) || (*processName == 0)) {
1338 tst = ADMBOSPROCESSNAMENULL;
1339 goto fail_bos_ProcessNotifierGet;
1342 if (notifier == NULL) {
1343 tst = ADMBOSNOTIFIERNULL;
1344 goto fail_bos_ProcessNotifierGet;
1347 tst = BOZO_GetInstanceParm(b_handle->server, processName, 999, ¬ifier);
1353 fail_bos_ProcessNotifierGet:
1362 * bos_ProcessRestart - restart a particular process.
1366 * IN serverHandle - a previously opened serverHandle.
1368 * IN processName - the process to restart
1372 * No locks are obtained or released by this function
1376 * Returns != 0 upon successful completion.
1380 int ADMINAPI bos_ProcessRestart(
1381 const void *serverHandle,
1382 const char *processName,
1386 afs_status_t tst = 0;
1387 bos_server_p b_handle = (bos_server_p) serverHandle;
1389 if (!isValidServerHandle(b_handle, &tst)) {
1390 goto fail_bos_ProcessRestart;
1393 if ((processName == NULL) || (*processName == 0)) {
1394 tst = ADMBOSPROCESSNAMENULL;
1395 goto fail_bos_ProcessRestart;
1398 tst = BOZO_Restart(b_handle->server, processName);
1404 fail_bos_ProcessRestart:
1413 * bos_ProcessAllStop - stop all running processes at a server.
1417 * IN serverHandle - a previously opened serverHandle.
1421 * No locks are obtained or released by this function
1425 * Returns != 0 upon successful completion.
1429 int ADMINAPI bos_ProcessAllStop(
1430 const void *serverHandle,
1434 afs_status_t tst = 0;
1435 bos_server_p b_handle = (bos_server_p) serverHandle;
1437 if (!isValidServerHandle(b_handle, &tst)) {
1438 goto fail_bos_ProcessAllStop;
1441 tst = BOZO_ShutdownAll(b_handle->server);
1447 fail_bos_ProcessAllStop:
1456 * bos_ProcessAllStart - start all processes that should be running at a
1461 * IN serverHandle - a previously opened serverHandle.
1465 * No locks are obtained or released by this function
1469 * Returns != 0 upon successful completion.
1473 int ADMINAPI bos_ProcessAllStart(
1474 const void *serverHandle,
1478 afs_status_t tst = 0;
1479 bos_server_p b_handle = (bos_server_p) serverHandle;
1481 if (!isValidServerHandle(b_handle, &tst)) {
1482 goto fail_bos_ProcessAllStart;
1485 tst = BOZO_StartupAll(b_handle->server);
1491 fail_bos_ProcessAllStart:
1500 * bos_ProcessAllWaitStop - stop all processes, and block until they have
1505 * IN serverHandle - a previously opened serverHandle.
1509 * No locks are obtained or released by this function
1513 * Returns != 0 upon successful completion.
1517 int ADMINAPI bos_ProcessAllWaitStop(
1518 const void *serverHandle,
1522 afs_status_t tst = 0;
1523 bos_server_p b_handle = (bos_server_p) serverHandle;
1525 if (!isValidServerHandle(b_handle, &tst)) {
1526 goto fail_bos_ProcessAllWaitStop;
1529 if (!bos_ProcessAllStop(serverHandle, &tst)) {
1530 goto fail_bos_ProcessAllWaitStop;
1533 tst = BOZO_WaitAll(b_handle->server);
1539 fail_bos_ProcessAllWaitStop:
1548 * bos_ProcessAllWaitTransition - block until all processes at the bosserver
1549 * have reached their desired state.
1553 * IN serverHandle - a previously opened serverHandle.
1557 * No locks are obtained or released by this function
1561 * Returns != 0 upon successful completion.
1565 int ADMINAPI bos_ProcessAllWaitTransition(
1566 const void *serverHandle,
1570 afs_status_t tst = 0;
1571 bos_server_p b_handle = (bos_server_p) serverHandle;
1573 if (!isValidServerHandle(b_handle, &tst)) {
1574 goto fail_bos_ProcessAllWaitTransition;
1577 tst = BOZO_WaitAll(b_handle->server);
1583 fail_bos_ProcessAllWaitTransition:
1592 * bos_ProcessAllStopAndRestart - stop all the running processes, restart
1593 * them, and optionally restart the bosserver itself.
1598 * IN serverHandle - a previously opened serverHandle.
1600 * IN restartBosServer - flag to indicate whether to restart bosserver.
1604 * No locks are obtained or released by this function
1608 * Returns != 0 upon successful completion.
1612 int ADMINAPI bos_ProcessAllStopAndRestart(
1613 const void *serverHandle,
1614 bos_RestartBosServer_t restartBosServer,
1618 afs_status_t tst = 0;
1619 bos_server_p b_handle = (bos_server_p) serverHandle;
1621 if (!isValidServerHandle(b_handle, &tst)) {
1622 goto fail_bos_ProcessAllStopAndRestart;
1625 if (restartBosServer == BOS_RESTART_BOS_SERVER) {
1626 tst = BOZO_ReBozo(b_handle->server);
1628 goto fail_bos_ProcessAllStopAndRestart;
1632 tst = BOZO_RestartAll(b_handle->server);
1638 fail_bos_ProcessAllStopAndRestart:
1647 * bos_AdminCreate - create a new admin.
1651 * IN serverHandle - a previously opened serverHandle.
1653 * IN adminName - the new admin name.
1657 * No locks are obtained or released by this function
1661 * Returns != 0 upon successful completion.
1665 int ADMINAPI bos_AdminCreate(
1666 const void *serverHandle,
1667 const char *adminName,
1671 afs_status_t tst = 0;
1672 bos_server_p b_handle = (bos_server_p) serverHandle;
1674 if (!isValidServerHandle(b_handle, &tst)) {
1675 goto fail_bos_AdminCreate;
1678 if ((adminName == NULL) || (*adminName == 0)) {
1679 tst = ADMBOSADMINNAMENULL;
1680 goto fail_bos_AdminCreate;
1683 tst = BOZO_AddSUser(b_handle->server, adminName);
1689 fail_bos_AdminCreate:
1698 * bos_AdminDelete - delete a new admin.
1702 * IN serverHandle - a previously opened serverHandle.
1704 * IN adminName - the admin name.
1708 * No locks are obtained or released by this function
1712 * Returns != 0 upon successful completion.
1716 int ADMINAPI bos_AdminDelete(
1717 const void *serverHandle,
1718 const char *adminName,
1722 afs_status_t tst = 0;
1723 bos_server_p b_handle = (bos_server_p) serverHandle;
1725 if (!isValidServerHandle(b_handle, &tst)) {
1726 goto fail_bos_AdminDelete;
1729 if ((adminName == NULL) || (*adminName == 0)) {
1730 tst = ADMBOSADMINNAMENULL;
1731 goto fail_bos_AdminDelete;
1734 tst = BOZO_DeleteSUser(b_handle->server, adminName);
1740 fail_bos_AdminDelete:
1749 * The iterator functions and data for the admin retrieval functions
1752 typedef struct admin_get {
1754 struct rx_connection *server;
1755 char admin[CACHED_ITEMS][BOS_MAX_NAME_LEN];
1756 } admin_get_t, *admin_get_p;
1758 static int GetAdminRPC(
1762 int *last_item_contains_data,
1766 afs_status_t tst = 0;
1767 admin_get_p admin = (admin_get_p) rpc_specific;
1768 char *ptr = (char *) &admin->admin[slot];
1770 tst = BOZO_ListSUsers(admin->server, admin->next++, &ptr);
1773 * There's no way to tell the difference between an rpc failure
1774 * and the end of the list, so we assume that any error means the
1781 *last_item_contains_data = 0;
1791 static int GetAdminFromCache(
1798 afs_status_t tst = 0;
1799 admin_get_p admin = (admin_get_p) rpc_specific;
1801 strcpy((char *) dest, (char *) &admin->admin[slot]);
1811 * bos_AdminGetBegin - begin iterating over the administrators.
1815 * IN serverHandle - a previously opened serverHandle.
1817 * OUT iter - an iterator that can be passed to bos_AdminGetBegin
1818 * to retrieve the administrators.
1822 * No locks are obtained or released by this function
1826 * Returns != 0 upon successful completion.
1830 int ADMINAPI bos_AdminGetBegin(
1831 const void *serverHandle,
1832 void **iterationIdP,
1836 afs_status_t tst = 0;
1837 bos_server_p b_handle = (bos_server_p) serverHandle;
1838 afs_admin_iterator_p iter = (afs_admin_iterator_p) malloc(sizeof(afs_admin_iterator_t));
1839 admin_get_p admin = (admin_get_p) malloc(sizeof(admin_get_t));
1841 if (!isValidServerHandle(b_handle, &tst)) {
1842 goto fail_bos_AdminGetBegin;
1845 if (iterationIdP == NULL) {
1846 tst = ADMITERATIONIDPNULL;
1847 goto fail_bos_AdminGetBegin;
1850 if ((iter == NULL) || (admin == NULL)) {
1852 goto fail_bos_AdminGetBegin;
1856 admin->server = b_handle->server;
1858 if (IteratorInit(iter, (void *) admin, GetAdminRPC,
1859 GetAdminFromCache, NULL, NULL, &tst)) {
1860 *iterationIdP = (void *) iter;
1864 fail_bos_AdminGetBegin:
1870 if (admin != NULL) {
1882 * bos_AdminGetNext - retrieve the next administrator
1883 * from the bos server.
1887 * IN iterationId - an iterator previously returned by
1890 * OUT adminName - upon successful completion contains the next administrator
1891 * retrieved from the server.
1895 * No locks are obtained or released by this function
1899 * Returns != 0 upon successful completion.
1903 int ADMINAPI bos_AdminGetNext(
1904 const void *iterationId,
1909 afs_status_t tst = 0;
1910 afs_admin_iterator_p iter = (afs_admin_iterator_p) iterationId;
1912 if (iterationId == NULL) {
1913 tst = ADMITERATIONIDPNULL;
1914 goto fail_bos_AdminGetNext;
1917 if (adminName == NULL) {
1918 tst = ADMBOSADMINNAMENULL;
1919 goto fail_bos_AdminGetNext;
1922 rc = IteratorNext(iter, (void *) adminName, &tst);
1924 fail_bos_AdminGetNext:
1933 * bos_AdminGetDone - finish using a administrator iterator.
1937 * IN iterationId - an iterator previously returned by
1942 * No locks are obtained or released by this function
1946 * Returns != 0 upon successful completion.
1950 int ADMINAPI bos_AdminGetDone(
1951 const void *iterationId,
1955 afs_status_t tst = 0;
1956 afs_admin_iterator_p iter = (afs_admin_iterator_p) iterationId;
1958 if (iterationId == NULL) {
1959 tst = ADMITERATIONIDPNULL;
1960 goto fail_bos_AdminGetDone;
1963 rc = IteratorDone(iter, &tst);
1965 fail_bos_AdminGetDone:
1974 * bos_KeyCreate - add a new key to the keyfile.
1978 * IN serverHandle - a previously opened serverHandle.
1980 * IN keyVersionNumber - the key version number.
1982 * IN key - the new key.
1986 * No locks are obtained or released by this function
1990 * Returns != 0 upon successful completion.
1994 int ADMINAPI bos_KeyCreate(
1995 const void *serverHandle,
1996 int keyVersionNumber,
1997 const kas_encryptionKey_p key,
2001 afs_status_t tst = 0;
2002 bos_server_p b_handle = (bos_server_p) serverHandle;
2004 if (!isValidServerHandle(b_handle, &tst)) {
2005 goto fail_bos_KeyCreate;
2009 tst = ADMBOSKEYNULL;
2010 goto fail_bos_KeyCreate;
2013 tst = BOZO_AddKey(b_handle->server_encrypt, keyVersionNumber, key);
2028 * bos_KeyDelete - delete an existing key from the keyfile.
2032 * IN serverHandle - a previously opened serverHandle.
2034 * IN keyVersionNumber - the key version number.
2038 * No locks are obtained or released by this function
2042 * Returns != 0 upon successful completion.
2046 int ADMINAPI bos_KeyDelete(
2047 const void *serverHandle,
2048 int keyVersionNumber,
2052 afs_status_t tst = 0;
2053 bos_server_p b_handle = (bos_server_p) serverHandle;
2055 if (!isValidServerHandle(b_handle, &tst)) {
2056 goto fail_bos_KeyDelete;
2059 tst = BOZO_DeleteKey(b_handle->server, keyVersionNumber);
2074 * The iterator functions and data for the key retrieval functions
2077 typedef struct key_get {
2079 struct rx_connection *server;
2080 bos_KeyInfo_t key[CACHED_ITEMS];
2081 } key_get_t, *key_get_p;
2083 static int GetKeyRPC(
2087 int *last_item_contains_data,
2091 afs_status_t tst = 0;
2092 key_get_p key = (key_get_p) rpc_specific;
2093 struct bozo_keyInfo keyInfo;
2095 tst = BOZO_ListKeys(key->server, key->next++,
2096 &key->key[slot].keyVersionNumber,
2097 &key->key[slot].key, &keyInfo);
2101 key->key[slot].keyStatus.lastModificationDate = keyInfo.mod_sec;
2102 key->key[slot].keyStatus.lastModificationMicroSeconds =
2104 key->key[slot].keyStatus.checkSum = keyInfo.keyCheckSum;
2106 } else if (tst == BZDOM) {
2110 *last_item_contains_data = 0;
2119 static int GetKeyFromCache(
2126 afs_status_t tst = 0;
2127 key_get_p key = (key_get_p) rpc_specific;
2129 memcpy(dest, &key->key[slot], sizeof(bos_KeyInfo_t));
2139 * bos_KeyGetBegin - begin iterating over the keys.
2143 * IN serverHandle - a previously opened serverHandle.
2145 * OUT iter - an iterator that can be passed to bos_KeyGetNext
2146 * to retrieve the keys.
2150 * No locks are obtained or released by this function
2154 * Returns != 0 upon successful completion.
2158 int ADMINAPI bos_KeyGetBegin(
2159 const void *serverHandle,
2160 void **iterationIdP,
2164 afs_status_t tst = 0;
2165 bos_server_p b_handle = (bos_server_p) serverHandle;
2166 afs_admin_iterator_p iter = (afs_admin_iterator_p) malloc(sizeof(afs_admin_iterator_t));
2167 key_get_p key = (key_get_p) malloc(sizeof(key_get_t));
2169 if (!isValidServerHandle(b_handle, &tst)) {
2170 goto fail_bos_KeyGetBegin;
2173 if (iterationIdP == NULL) {
2174 tst = ADMITERATIONIDPNULL;
2175 goto fail_bos_KeyGetBegin;
2178 if ((iter == NULL) || (key == NULL)) {
2180 goto fail_bos_KeyGetBegin;
2184 key->server = b_handle->server_encrypt;
2186 if (IteratorInit(iter, (void *) key, GetKeyRPC,
2187 GetKeyFromCache, NULL, NULL, &tst)) {
2188 *iterationIdP = (void *) iter;
2192 fail_bos_KeyGetBegin:
2210 * bos_KeyGetNext - retrieve the next key
2211 * from the bos server.
2215 * IN iterationId - an iterator previously returned by
2218 * OUT keyP - upon successful completion contains the next key
2219 * retrieved from the server.
2223 * No locks are obtained or released by this function
2227 * Returns != 0 upon successful completion.
2231 int ADMINAPI bos_KeyGetNext(
2232 const void *iterationId,
2237 afs_status_t tst = 0;
2238 afs_admin_iterator_p iter = (afs_admin_iterator_p) iterationId;
2240 if (iterationId == NULL) {
2241 tst = ADMITERATIONIDPNULL;
2242 goto fail_bos_KeyGetNext;
2246 tst = ADMBOSKEYPNULL;
2247 goto fail_bos_KeyGetNext;
2250 rc = IteratorNext(iter, (void *) keyP, &tst);
2252 fail_bos_KeyGetNext:
2261 * bos_KeyGetDone - finish using a key iterator.
2265 * IN iterationId - an iterator previously returned by
2270 * No locks are obtained or released by this function
2274 * Returns != 0 upon successful completion.
2278 int ADMINAPI bos_KeyGetDone(
2279 const void *iterationId,
2283 afs_status_t tst = 0;
2284 afs_admin_iterator_p iter = (afs_admin_iterator_p) iterationId;
2286 if (iterationId == NULL) {
2287 tst = ADMITERATIONIDPNULL;
2288 goto fail_bos_KeyGetDone;
2291 rc = IteratorDone(iter, &tst);
2293 fail_bos_KeyGetDone:
2302 * bos_CellSet - set the cell name at a bos server.
2306 * IN serverHandle - a previously opened serverHandle.
2308 * IN cellName - the new cell name.
2312 * No locks are obtained or released by this function
2316 * Returns != 0 upon successful completion.
2319 int ADMINAPI bos_CellSet(
2320 const void *serverHandle,
2321 const char *cellName,
2325 afs_status_t tst = 0;
2326 bos_server_p b_handle = (bos_server_p) serverHandle;
2328 if (!isValidServerHandle(b_handle, &tst)) {
2329 goto fail_bos_CellSet;
2332 if ((cellName == NULL) || (*cellName == 0)) {
2333 tst = ADMCLIENTCELLNAMENULL;
2334 goto fail_bos_CellSet;
2337 tst = BOZO_SetCellName(b_handle->server, cellName);
2352 * bos_CellGet - get the cell name at a bos server.
2356 * IN serverHandle - a previously opened serverHandle.
2358 * OUT cellName - the cell name.
2362 * No locks are obtained or released by this function
2366 * Returns != 0 upon successful completion.
2369 int ADMINAPI bos_CellGet(
2370 const void *serverHandle,
2375 afs_status_t tst = 0;
2376 bos_server_p b_handle = (bos_server_p) serverHandle;
2378 if (!isValidServerHandle(b_handle, &tst)) {
2379 goto fail_bos_CellGet;
2382 if (cellName == NULL) {
2383 tst = ADMCLIENTCELLNAMENULL;
2384 goto fail_bos_CellGet;
2387 tst = BOZO_GetCellName(b_handle->server, &cellName);
2402 * bos_HostCreate - add a new host to the cell.
2406 * IN serverHandle - a previously opened serverHandle.
2408 * IN hostName - the new host.
2412 * No locks are obtained or released by this function
2416 * Returns != 0 upon successful completion.
2419 int ADMINAPI bos_HostCreate(
2420 const void *serverHandle,
2421 const char *hostName,
2425 afs_status_t tst = 0;
2426 bos_server_p b_handle = (bos_server_p) serverHandle;
2428 if (!isValidServerHandle(b_handle, &tst)) {
2429 goto fail_bos_HostCreate;
2432 if ((hostName == NULL) || (*hostName == 0)) {
2433 tst = ADMBOSHOSTNAMENULL;
2434 goto fail_bos_HostCreate;
2437 tst = BOZO_AddCellHost(b_handle->server, hostName);
2443 fail_bos_HostCreate:
2452 * bos_HostDelete - delete a host from the cell.
2456 * IN serverHandle - a previously opened serverHandle.
2458 * IN hostName - the host.
2462 * No locks are obtained or released by this function
2466 * Returns != 0 upon successful completion.
2469 int ADMINAPI bos_HostDelete(
2470 const void *serverHandle,
2471 const char *hostName,
2475 afs_status_t tst = 0;
2476 bos_server_p b_handle = (bos_server_p) serverHandle;
2478 if (!isValidServerHandle(b_handle, &tst)) {
2479 goto fail_bos_HostDelete;
2482 if ((hostName == NULL) || (*hostName == 0)) {
2483 tst = ADMBOSHOSTNAMENULL;
2484 goto fail_bos_HostDelete;
2487 tst = BOZO_DeleteCellHost(b_handle->server, hostName);
2493 fail_bos_HostDelete:
2502 * The iterator functions and data for the host retrieval functions
2505 typedef struct host_get {
2507 struct rx_connection *server;
2508 char host[CACHED_ITEMS][BOS_MAX_NAME_LEN];
2509 } host_get_t, *host_get_p;
2511 static int GetHostRPC(
2515 int *last_item_contains_data,
2519 afs_status_t tst = 0;
2520 host_get_p host = (host_get_p) rpc_specific;
2521 char *ptr = (char *) &host->host[slot];
2523 tst = BOZO_GetCellHost(host->server, host->next++, &ptr);
2527 } else if (tst == BZDOM) {
2531 *last_item_contains_data = 0;
2540 static int GetHostFromCache(
2547 afs_status_t tst = 0;
2548 host_get_p host = (host_get_p) rpc_specific;
2550 strcpy((char *) dest, (char *) &host->host[slot]);
2560 * bos_HostGetBegin - begin iterating over the hosts in a cell
2561 * at a particular bos server.
2565 * IN serverHandle - a previously opened serverHandle.
2567 * OUT iter - an iterator that can be passed to bos_HostGetNext
2568 * to retrieve the process names.
2572 * No locks are obtained or released by this function
2576 * Returns != 0 upon successful completion.
2580 int ADMINAPI bos_HostGetBegin(
2581 const void *serverHandle,
2582 void **iterationIdP,
2586 afs_status_t tst = 0;
2587 bos_server_p b_handle = (bos_server_p) serverHandle;
2588 afs_admin_iterator_p iter = (afs_admin_iterator_p) malloc(sizeof(afs_admin_iterator_t));
2589 host_get_p host = (host_get_p) malloc(sizeof(host_get_t));
2591 if (!isValidServerHandle(b_handle, &tst)) {
2592 goto fail_bos_HostGetBegin;
2595 if (iterationIdP == NULL) {
2596 tst = ADMITERATIONIDPNULL;
2597 goto fail_bos_HostGetBegin;
2600 if ((iter == NULL) || (host == NULL)) {
2602 goto fail_bos_HostGetBegin;
2606 host->server = b_handle->server;
2608 if (IteratorInit(iter, (void *) host, GetHostRPC,
2609 GetHostFromCache, NULL, NULL, &tst)) {
2610 *iterationIdP = (void *) iter;
2614 fail_bos_HostGetBegin:
2632 * bos_HostGetNext - retrieve the next host
2633 * from the bos server.
2637 * IN iterationId - an iterator previously returned by
2640 * OUT hostName - upon successful completion contains the next host
2641 * retrieved from the server.
2645 * No locks are obtained or released by this function
2649 * Returns != 0 upon successful completion.
2653 int ADMINAPI bos_HostGetNext(
2654 const void *iterationId,
2659 afs_status_t tst = 0;
2660 afs_admin_iterator_p iter = (afs_admin_iterator_p) iterationId;
2662 if (iterationId == NULL) {
2663 tst = ADMITERATIONIDPNULL;
2664 goto fail_bos_HostGetNext;
2667 if (hostName == NULL) {
2668 tst = ADMBOSHOSTNAMENULL;
2669 goto fail_bos_HostGetNext;
2672 rc = IteratorNext(iter, (void *) hostName, &tst);
2674 fail_bos_HostGetNext:
2683 * bos_HostGetDone - finish using a host iterator.
2687 * IN iterationId - an iterator previously returned by
2692 * No locks are obtained or released by this function
2696 * Returns != 0 upon successful completion.
2700 int ADMINAPI bos_HostGetDone(
2701 const void *iterationId,
2705 afs_status_t tst = 0;
2706 afs_admin_iterator_p iter = (afs_admin_iterator_p) iterationId;
2708 if (iterationId == NULL) {
2709 tst = ADMITERATIONIDPNULL;
2710 goto fail_bos_HostGetDone;
2713 rc = IteratorDone(iter, &tst);
2715 fail_bos_HostGetDone:
2724 * bos_ExecutableCreate - create a new executable at the bos server.
2728 * IN serverHandle - a previously opened serverHandle.
2730 * IN sourceFile - the executable to install at the bos server.
2732 * IN destFile - the location where the executable will be installed.
2736 * No locks are obtained or released by this function
2740 * Returns != 0 upon successful completion.
2744 int ADMINAPI bos_ExecutableCreate(
2745 const void *serverHandle,
2746 const char *sourceFile,
2747 const char *destFile,
2751 afs_status_t tst = 0;
2752 bos_server_p b_handle = (bos_server_p) serverHandle;
2755 struct rx_call *tcall;
2758 * Validate arguments
2761 if (!isValidServerHandle(b_handle, &tst)) {
2762 goto fail_bos_ExecutableCreate;
2765 if ((sourceFile == NULL) || (*sourceFile == 0)) {
2766 tst = ADMBOSSOURCEFILENULL;
2767 goto fail_bos_ExecutableCreate;
2770 if ((destFile == NULL) || (*destFile == 0)) {
2771 tst = ADMBOSDESTFILENULL;
2772 goto fail_bos_ExecutableCreate;
2776 * Open the file locally and compute its size
2779 fd = open(sourceFile, O_RDONLY);
2782 tst = ADMBOSCANTOPENSOURCEFILE;
2783 goto fail_bos_ExecutableCreate;
2786 if (fstat(fd, &estat)) {
2787 tst = ADMBOSCANTSTATSOURCEFILE;
2788 goto fail_bos_ExecutableCreate;
2792 * Start a split rpc to the bos server.
2795 tcall = rx_NewCall(b_handle->server);
2797 tst = StartBOZO_Install(tcall, destFile, estat.st_size,
2798 (afs_int32) estat.st_mode, estat.st_mtime);
2801 rx_EndCall(tcall, tst);
2802 goto fail_bos_ExecutableCreate;
2806 * Copy the data to the server
2812 len = read(fd, tbuffer, sizeof(tbuffer));
2814 tst = ADMBOSCANTREADSOURCEFILE;
2815 rx_EndCall(tcall, len);
2816 goto fail_bos_ExecutableCreate;
2822 tst = rx_Write(tcall, tbuffer, len);
2824 tst = ADMBOSSENDSOURCEFILE;
2825 rx_EndCall(tcall, tst);
2826 goto fail_bos_ExecutableCreate;
2831 * Terminate the rpc to the server
2834 tst = rx_EndCall(tcall, tst);
2840 fail_bos_ExecutableCreate:
2849 * bos_ExecutableRevert - revert an executable to a previous .BAK version.
2853 * IN serverHandle - a previously opened serverHandle.
2855 * IN execFile - the executable to revert at the bos server.
2859 * No locks are obtained or released by this function
2863 * Returns != 0 upon successful completion.
2867 int ADMINAPI bos_ExecutableRevert(
2868 const void *serverHandle,
2869 const char *execFile,
2873 afs_status_t tst = 0;
2874 bos_server_p b_handle = (bos_server_p) serverHandle;
2876 if (!isValidServerHandle(b_handle, &tst)) {
2877 goto fail_bos_ExecutableRevert;
2880 if ((execFile == NULL) || (*execFile == 0)) {
2881 tst = ADMBOSEXECFILENULL;
2882 goto fail_bos_ExecutableRevert;
2885 tst = BOZO_UnInstall(b_handle->server, execFile);
2891 fail_bos_ExecutableRevert:
2900 * bos_ExecutableTimestampGet - get the last mod times for an executable,
2901 * the .BAK version of the executable, and the .OLD version of the
2902 * executable if they exist.
2906 * IN serverHandle - a previously opened serverHandle.
2908 * IN execFile - the executable to revert at the bos server.
2912 * No locks are obtained or released by this function
2916 * Returns != 0 upon successful completion.
2920 int ADMINAPI bos_ExecutableTimestampGet(
2921 const void *serverHandle,
2922 const char *execFile,
2923 unsigned long *newTime,
2924 unsigned long *oldTime,
2925 unsigned long *bakTime,
2929 afs_status_t tst = 0;
2930 bos_server_p b_handle = (bos_server_p) serverHandle;
2932 if (!isValidServerHandle(b_handle, &tst)) {
2933 goto fail_bos_ExecutableTimestampGet;
2936 if ((execFile == NULL) || (*execFile == 0)) {
2937 tst = ADMBOSEXECFILENULL;
2938 goto fail_bos_ExecutableTimestampGet;
2941 if (newTime == NULL) {
2942 tst = ADMBOSNEWTIMENULL;
2943 goto fail_bos_ExecutableTimestampGet;
2946 if (oldTime == NULL) {
2947 tst = ADMBOSOLDTIMENULL;
2948 goto fail_bos_ExecutableTimestampGet;
2951 if (bakTime == NULL) {
2952 tst = ADMBOSBAKTIMENULL;
2953 goto fail_bos_ExecutableTimestampGet;
2956 tst = BOZO_GetDates(b_handle->server, execFile, newTime, bakTime, oldTime);
2962 fail_bos_ExecutableTimestampGet:
2971 * bos_ExecutablePrune - prune the bak, old, and core files off a server
2976 * IN serverHandle - a previously opened serverHandle.
2978 * IN oldFiles - prune .OLD files.
2980 * IN bakFiles - prune .BAK files.
2982 * IN coreFiles - prune core files.
2986 * No locks are obtained or released by this function
2990 * Returns != 0 upon successful completion.
2994 int ADMINAPI bos_ExecutablePrune(
2995 const void *serverHandle,
2996 bos_Prune_t oldFiles,
2997 bos_Prune_t bakFiles,
2998 bos_Prune_t coreFiles,
3002 afs_status_t tst = 0;
3003 bos_server_p b_handle = (bos_server_p) serverHandle;
3004 afs_int32 flags = 0;
3006 if (!isValidServerHandle(b_handle, &tst)) {
3007 goto fail_bos_ExecutablePrune;
3010 if (oldFiles == BOS_PRUNE) {
3011 flags |= BOZO_PRUNEOLD;
3014 if (bakFiles == BOS_PRUNE) {
3015 flags |= BOZO_PRUNEBAK;
3018 if (coreFiles == BOS_PRUNE) {
3019 flags |= BOZO_PRUNECORE;
3022 tst = BOZO_Prune(b_handle->server, flags);
3028 fail_bos_ExecutablePrune:
3037 * bos_ExecutableRestartTimeSet - set the restart time of the bos server
3042 * IN serverHandle - a previously opened serverHandle.
3044 * IN type - specifies either weekly restart or daily restart time.
3046 * IN time - the time to begin restarts.
3050 * No locks are obtained or released by this function
3054 * Returns != 0 upon successful completion.
3058 int ADMINAPI bos_ExecutableRestartTimeSet(
3059 const void *serverHandle,
3061 bos_RestartTime_t time,
3065 afs_status_t tst = 0;
3066 bos_server_p b_handle = (bos_server_p) serverHandle;
3067 afs_int32 restartType = 0;
3068 struct ktime restartTime;
3070 if (!isValidServerHandle(b_handle, &tst)) {
3071 goto fail_bos_ExecutableRestartTimeSet;
3074 if (type == BOS_RESTART_WEEKLY) {
3080 if ((time.mask & BOS_RESTART_TIME_HOUR) &&
3081 ((time.hour < 0) || (time.hour > 23))) {
3082 tst = ADMBOSHOURINVALID;
3083 goto fail_bos_ExecutableRestartTimeSet;
3086 if ((time.mask & BOS_RESTART_TIME_MINUTE) &&
3087 ((time.min < 0) || (time.min > 60))) {
3088 tst = ADMBOSMINUTEINVALID;
3089 goto fail_bos_ExecutableRestartTimeSet;
3092 if ((time.mask & BOS_RESTART_TIME_SECOND) &&
3093 ((time.sec < 0) || (time.sec > 60))) {
3094 tst = ADMBOSSECONDINVALID;
3095 goto fail_bos_ExecutableRestartTimeSet;
3098 if ((time.mask & BOS_RESTART_TIME_DAY) &&
3099 ((time.day < 0) || (time.day > 6))) {
3100 tst = ADMBOSDAYINVALID;
3101 goto fail_bos_ExecutableRestartTimeSet;
3104 restartTime.mask = time.mask;
3105 restartTime.hour = time.hour;
3106 restartTime.min = time.min;
3107 restartTime.sec = time.sec;
3108 restartTime.day = time.day;
3110 tst = BOZO_SetRestartTime(b_handle->server, restartType, restartTime);
3116 fail_bos_ExecutableRestartTimeSet:
3125 * bos_ExecutableRestartTimeGet - get the restart time of the bos server
3130 * IN serverHandle - a previously opened serverHandle.
3132 * IN type - specifies either weekly restart or daily restart time.
3134 * OUT timeP - the time to begin restarts.
3138 * No locks are obtained or released by this function
3142 * Returns != 0 upon successful completion.
3146 int ADMINAPI bos_ExecutableRestartTimeGet(
3147 const void *serverHandle,
3149 bos_RestartTime_p timeP,
3153 afs_status_t tst = 0;
3154 bos_server_p b_handle = (bos_server_p) serverHandle;
3155 afs_int32 restartType = 0;
3156 struct ktime restartTime;
3158 if (!isValidServerHandle(b_handle, &tst)) {
3159 goto fail_bos_ExecutableRestartTimeGet;
3162 if (timeP == NULL) {
3163 tst = ADMBOSTIMEPNULL;
3164 goto fail_bos_ExecutableRestartTimeGet;
3167 if (type == BOS_RESTART_WEEKLY) {
3173 tst = BOZO_GetRestartTime(b_handle->server, restartType, &restartTime);
3176 goto fail_bos_ExecutableRestartTimeGet;
3179 timeP->mask = restartTime.mask;
3180 timeP->hour = restartTime.hour;
3181 timeP->min = restartTime.min;
3182 timeP->sec = restartTime.sec;
3183 timeP->day = restartTime.day;
3186 fail_bos_ExecutableRestartTimeGet:
3195 * bos_LogGet - get a log file from the bos server machine.
3199 * IN serverHandle - a previously opened serverHandle.
3201 * IN log - the log file to retrieve.
3203 * IN/OUT logBufferSizeP - the length of the logData buffer on input,
3204 * and upon successful completion, the length of data stored in the buffer.
3206 * OUT logData - the retrieved data upon successful completion.
3210 * No locks are obtained or released by this function
3214 * Returns != 0 upon successful completion.
3218 int ADMINAPI bos_LogGet(
3219 const void *serverHandle,
3221 unsigned long *logBufferSizeP,
3226 afs_status_t tst = 0;
3227 bos_server_p b_handle = (bos_server_p) serverHandle;
3228 struct rx_call *tcall = NULL;
3232 unsigned long bytes_read = 0;
3235 * Validate parameters
3238 if (!isValidServerHandle(b_handle, &tst)) {
3239 goto fail_bos_LogGet;
3242 if ((log == NULL) || (*log == 0)) {
3243 tst = ADMBOSLOGNULL;
3244 goto fail_bos_LogGet;
3247 if (logBufferSizeP == NULL) {
3248 tst = ADMBOSLOGBUFFERSIZEPNULL;
3249 goto fail_bos_LogGet;
3252 if (logData == NULL) {
3253 tst = ADMBOSLOGDATANULL;
3254 goto fail_bos_LogGet;
3258 * Begin to retrieve the data
3261 tcall = rx_NewCall(b_handle->server);
3263 tst = StartBOZO_GetLog(tcall, log);
3266 goto fail_bos_LogGet;
3270 * Read the log file data
3274 error = rx_Read(tcall, &buffer, 1);
3276 tst = ADMBOSLOGFILEERROR;
3277 goto fail_bos_LogGet;
3281 * check for the end of the log
3285 *logBufferSizeP = bytes_read;
3290 * We've successfully read another byte, copy it to logData
3295 if (bytes_read <= *logBufferSizeP) {
3296 *logData++ = buffer;
3308 rx_EndCall(tcall, 0);
3318 * bos_AuthSet - set the authorization level required at the bos server.
3322 * IN serverHandle - a previously opened serverHandle.
3324 * IN auth - specifies the new auth level.
3328 * No locks are obtained or released by this function
3332 * Returns != 0 upon successful completion.
3336 int ADMINAPI bos_AuthSet(
3337 const void *serverHandle,
3342 afs_status_t tst = 0;
3343 bos_server_p b_handle = (bos_server_p) serverHandle;
3344 afs_int32 level = 0;
3346 if (!isValidServerHandle(b_handle, &tst)) {
3347 goto fail_bos_AuthSet;
3350 if (auth == BOS_AUTH_REQUIRED) {
3356 tst = BOZO_SetNoAuthFlag(b_handle->server, level);
3371 * bos_CommandExecute - execute a command at the bos server.
3375 * IN serverHandle - a previously opened serverHandle.
3377 * IN command - the command to execute.
3381 * No locks are obtained or released by this function
3385 * Returns != 0 upon successful completion.
3389 int ADMINAPI bos_CommandExecute(
3390 const void *serverHandle,
3391 const char *command,
3395 afs_status_t tst = 0;
3396 bos_server_p b_handle = (bos_server_p) serverHandle;
3398 if (!isValidServerHandle(b_handle, &tst)) {
3399 goto fail_bos_CommandExecute;
3402 if ((command == NULL) || (*command == 0)) {
3403 tst = ADMBOSCOMMANDNULL;
3404 goto fail_bos_CommandExecute;
3407 tst = BOZO_Exec(b_handle->server, command);
3413 fail_bos_CommandExecute:
3422 * bos_Salvage - perform a remote salvage operation.
3426 * IN cellHandle - a previously opened cellHandle.
3428 * IN serverHandle - a previously opened serverHandle.
3430 * IN partitionName - the partition to salvage. Can be null.
3432 * IN volumeName - the volume to salvage. Can be null, if non-null,
3433 * partitionName cannot be null.
3435 * IN numSalvagers - the number of salvage processes to run in parallel.
3437 * IN tmpDir - directory to place temporary files. Can be null.
3439 * IN logFile - file where salvage log will be written. Can be null.
3441 * IN force - sets salvager -force flag.
3443 * IN salvageDamagedVolumes - sets salvager -oktozap flag.
3445 * IN writeInodes - sets salvager -inodes flag.
3447 * IN writeRootInodes - sets salvager -rootinodes flag.
3449 * IN forceDirectory - sets salvager -salvagedirs flag.
3451 * IN forceBlockRead - sets salvager -blockread flag.
3455 * No locks are obtained or released by this function
3459 * Returns != 0 upon successful completion.
3463 #define INITIAL_LOG_LEN 4096
3465 int ADMINAPI bos_Salvage(
3466 const void *cellHandle,
3467 const void *serverHandle,
3468 const char *partitionName,
3469 const char *volumeName,
3472 const char *logFile,
3474 bos_SalvageDamagedVolumes_t salvageDamagedVolumes,
3475 bos_WriteInodes_t writeInodes,
3476 bos_WriteRootInodes_t writeRootInodes,
3477 bos_ForceDirectory_t forceDirectory,
3478 bos_ForceBlockRead_t forceBlockRead,
3482 afs_status_t tst = 0;
3483 bos_server_p b_handle = (bos_server_p) serverHandle;
3484 afs_cell_handle_p c_handle = (afs_cell_handle_p) cellHandle;
3485 int have_partition = 0;
3486 int have_volume = 0;
3487 unsigned int part = 0;
3488 int try_to_stop_fileserver = 0;
3489 bos_ProcessType_t procType;
3490 bos_ProcessInfo_t procInfo;
3492 char command[BOS_MAX_NAME_LEN];
3493 int command_len = 0;
3495 char *logData = NULL;
3496 unsigned long logLen = INITIAL_LOG_LEN;
3499 * Validate arguments
3502 if (!IsValidCellHandle(c_handle, &tst)) {
3503 goto fail_bos_Salvage;
3506 if (!isValidServerHandle(b_handle, &tst)) {
3507 goto fail_bos_Salvage;
3510 if (c_handle->vos_valid == 0) {
3511 tst = ADMBOSCELLHANDLENOVOS;
3512 goto fail_bos_Salvage;
3515 if ((partitionName != NULL) && (*partitionName != 0)) {
3516 if (!vos_PartitionNameToId(partitionName, &part, &tst)) {
3517 goto fail_bos_Salvage;
3522 if ((volumeName != NULL) && (*volumeName != 0)) {
3523 if (!have_partition) {
3524 tst = ADMBOSSALVAGEVOLUME;
3525 goto fail_bos_Salvage;
3530 if ((logFile != NULL) && (*logFile != 0)) {
3531 log = fopen(logFile, "w");
3533 tst = ADMBOSSALVAGEBADLOG;
3534 goto fail_bos_Salvage;
3539 * If we are salvaging more than a single volume, stop the fileserver
3543 try_to_stop_fileserver = 1;
3547 * Only try to stop the fileserver if it is running
3550 if (try_to_stop_fileserver) {
3551 if (bos_ProcessInfoGet(serverHandle, "fs", &procType, &procInfo,
3553 if (procInfo.processGoal != BOS_PROCESS_RUNNING) {
3554 try_to_stop_fileserver = 0;
3560 * Make the call to stop the fileserver and wait for it to shutdown
3563 if (try_to_stop_fileserver) {
3564 if (!bos_ProcessExecutionStateSetTemporary(serverHandle, "fs",
3565 BOS_PROCESS_STOPPED,
3567 goto fail_bos_Salvage;
3569 bos_ProcessAllWaitTransition(serverHandle, &tst);
3573 * Create the salvage command line arguments
3576 command_len = sprintf(command, "%s ",
3577 AFSDIR_CANONICAL_SERVER_SALVAGER_FILEPATH);
3578 if (have_partition) {
3579 command_len += sprintf(&command[command_len], "-partition %s ",
3584 command_len += sprintf(&command[command_len], "-volumeid %s ",
3588 if (salvageDamagedVolumes == BOS_DONT_SALVAGE_DAMAGED_VOLUMES) {
3589 command_len += sprintf(&command[command_len], "-nowrite ");
3592 if (writeInodes == BOS_SALVAGE_WRITE_INODES) {
3593 command_len += sprintf(&command[command_len], "-inodes ");
3596 if (force == VOS_FORCE) {
3597 command_len += sprintf(&command[command_len], "-force ");
3600 if (writeRootInodes == BOS_SALVAGE_WRITE_ROOT_INODES) {
3601 command_len += sprintf(&command[command_len], "-rootinodes ");
3604 if (forceDirectory == BOS_SALVAGE_FORCE_DIRECTORIES) {
3605 command_len += sprintf(&command[command_len], "-salvagedirs ");
3608 if (forceBlockRead == BOS_SALVAGE_FORCE_BLOCK_READS) {
3609 command_len += sprintf(&command[command_len], "-blockreads ");
3612 command_len += sprintf(&command[command_len], "-parallel %d ", numSalvagers);
3614 if ((tmpDir != NULL) && (*tmpDir != 0)) {
3615 command_len += sprintf(&command[command_len], "-tmpdir %s ", tmpDir);
3618 if (command_len > BOS_MAX_NAME_LEN) {
3619 tst = ADMBOSSALVAGEBADOPTIONS;
3620 goto fail_bos_Salvage;
3624 * Create the process at the bosserver and wait until it completes
3627 if (!bos_ProcessCreate(serverHandle, "salvage-tmp", BOS_PROCESS_CRON,
3628 command, "now", 0, &tst)) {
3629 goto fail_bos_Salvage;
3632 while ((poll_rc = bos_ProcessInfoGet(serverHandle, "salvage-tmp", &procType,
3633 &procInfo, &tst))) {
3637 if (tst != BZNOENT) {
3638 goto fail_bos_Salvage;
3642 * Print out the salvage log if required by the user
3647 logData = (char *) malloc(INITIAL_LOG_LEN);
3650 goto fail_bos_Salvage;
3653 while(!bos_LogGet(serverHandle,
3654 AFSDIR_CANONICAL_SERVER_SLVGLOG_FILEPATH,
3655 &logLen, logData, &tst)) {
3656 if (logLen > INITIAL_LOG_LEN) {
3657 logData = (char *) realloc(logData, (logLen + (logLen / 10)));
3658 if (logData == NULL) {
3660 goto fail_bos_Salvage;
3663 goto fail_bos_Salvage;
3666 fprintf(log, "SalvageLog:\n%s", logData);
3670 * Restart the fileserver if we had stopped it previously
3673 if (try_to_stop_fileserver) {
3674 try_to_stop_fileserver = 0;
3675 if (!bos_ProcessExecutionStateSetTemporary(serverHandle, "fs",
3676 BOS_PROCESS_RUNNING,
3678 goto fail_bos_Salvage;
3689 if (logData != NULL) {
3693 if (try_to_stop_fileserver) {
3694 bos_ProcessExecutionStateSetTemporary(serverHandle, "fs",
3695 BOS_PROCESS_RUNNING, 0);