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>
26 #include "../../permit_xprt.h"
30 * Prototypes for functions that don't exist in any header files
33 extern int BOZO_AddCellHost();
34 extern int BOZO_AddKey();
35 extern int BOZO_AddSUser();
36 extern int BOZO_CreateBnode();
37 extern int BOZO_DeleteBnode();
38 extern int BOZO_DeleteCellHost();
39 extern int BOZO_DeleteKey();
40 extern int BOZO_DeleteSUser();
41 extern int BOZO_EnumerateInstance();
42 extern int BOZO_Exec();
43 extern int BOZO_GetCellHost();
44 extern int BOZO_GetCellName();
45 extern int BOZO_GetDates();
46 extern int BOZO_GetInstanceInfo();
47 extern int BOZO_GetInstanceParm();
48 extern int BOZO_GetInstanceParm();
49 extern int BOZO_GetRestartTime();
50 extern int BOZO_GetStatus();
51 extern int BOZO_ListSUsers();
52 extern int BOZO_ListKeys();
53 extern int BOZO_Prune();
54 extern int BOZO_ReBozo();
55 extern int BOZO_Restart();
56 extern int BOZO_RestartAll();
57 extern int BOZO_SetCellName();
58 extern int BOZO_SetNoAuthFlag();
59 extern int BOZO_SetRestartTime();
60 extern int BOZO_SetStatus(struct rx_connection *, const char *, long);
61 extern int BOZO_SetTStatus(struct rx_connection *, const char *, long);
62 extern int BOZO_ShutdownAll();
63 extern int BOZO_StartupAll();
64 extern int BOZO_UnInstall();
65 extern int BOZO_WaitAll();
66 extern int StartBOZO_GetLog();
67 extern int StartBOZO_Install();
69 typedef struct bos_server {
72 struct rx_connection *server;
73 struct rx_connection *server_encrypt;
74 struct rx_connection *server_stats;
76 } bos_server_t, *bos_server_p;
79 * isValidServerHandle - validate a bos_server_p.
83 * IN serverHandle - the handle to validate
87 * No locks are obtained or released by this function
91 * Returns != 0 upon successful completion.
94 int isValidServerHandle (
95 const bos_server_p serverHandle,
101 if (serverHandle == NULL) {
102 tst = ADMBOSSERVERHANDLENULL;
103 goto fail_IsValidServerHandle;
106 if ((serverHandle->begin_magic != BEGIN_MAGIC) ||
107 (serverHandle->end_magic != END_MAGIC)) {
108 tst = ADMBOSSERVERHANDLEBADMAGIC;
109 goto fail_IsValidServerHandle;
112 if (serverHandle->is_valid == 0) {
113 tst = ADMBOSSERVERHANDLEINVALID;
114 goto fail_IsValidServerHandle;
117 if (serverHandle->server == NULL) {
118 tst = ADMBOSSERVERHANDLENOSERVER;
119 goto fail_IsValidServerHandle;
122 if (serverHandle->server_encrypt == NULL) {
123 tst = ADMBOSSERVERHANDLENOSERVER;
124 goto fail_IsValidServerHandle;
128 fail_IsValidServerHandle:
136 * IsValidCellHandle - verify that a cell handle can be used to make bos
141 * IN cellHandle - the cellHandle to be validated.
145 * No locks are obtained or released by this function
149 * Returns != 0 upon successful completion.
152 static int IsValidCellHandle(
153 afs_cell_handle_p cellHandle,
157 afs_status_t tst = 0;
159 if (!CellHandleIsValid((void *) cellHandle, &tst)) {
160 goto fail_IsValidCellHandle;
163 if (cellHandle->tokens == NULL) {
164 tst = ADMBOSCELLHANDLENOTOKENS;
165 goto fail_IsValidCellHandle;
169 fail_IsValidCellHandle:
178 * bos_ServerOpen - open a bos server for work.
182 * IN cellHandle - a previously opened cellHandle.
184 * IN serverName - the name of the machine that houses the bosserver of
187 * OUT serverHandleP - upon successful completion, this void pointer
188 * will point to a valid server handle for use in future operations.
192 * No locks are obtained or released by this function
196 * Returns != 0 upon successful completion.
199 int ADMINAPI bos_ServerOpen(
200 const void *cellHandle,
201 const char *serverName,
202 void **serverHandleP,
206 afs_status_t tst = 0;
207 afs_cell_handle_p c_handle = (afs_cell_handle_p) cellHandle;
208 bos_server_p bos_server = (bos_server_p) malloc(sizeof(bos_server_t));
212 * Validate parameters
215 if (!IsValidCellHandle(c_handle, &tst)) {
216 goto fail_bos_ServerOpen;
219 if ((serverName == NULL) || (*serverName == 0)) {
220 tst = ADMBOSSERVERNAMENULL;
221 goto fail_bos_ServerOpen;
224 if (serverHandleP == NULL) {
225 tst = ADMBOSSERVERHANDLEPNULL;
226 goto fail_bos_ServerOpen;
229 if (util_AdminServerAddressGetFromName(serverName, &serverAddress, &tst) == 0) {
230 goto fail_bos_ServerOpen;
233 if (bos_server == NULL) {
235 goto fail_bos_ServerOpen;
238 bos_server->server = rx_GetCachedConnection(htonl(serverAddress),
239 htons(AFSCONF_NANNYPORT), 1,
240 c_handle->tokens->afs_sc[c_handle->tokens->sc_index], c_handle->tokens->sc_index);
242 bos_server->server_encrypt = rx_GetCachedConnection(htonl(serverAddress),
243 htons(AFSCONF_NANNYPORT), 1,
244 c_handle->tokens->afs_encrypt_sc[c_handle->tokens->sc_index], c_handle->tokens->sc_index);
246 bos_server->server_stats = rx_GetCachedConnection(htonl(serverAddress),
247 htons(AFSCONF_NANNYPORT),
249 c_handle->tokens->afs_sc[c_handle->tokens->sc_index], c_handle->tokens->sc_index);
251 if ((bos_server->server == NULL) || (bos_server->server_encrypt == NULL)) {
252 tst = ADMBOSSERVERNOCONNECTION;
253 goto fail_bos_ServerOpen;
256 bos_server->begin_magic = BEGIN_MAGIC;
257 bos_server->is_valid = 1;
258 bos_server->end_magic = END_MAGIC;
260 *serverHandleP = (void *) bos_server;
265 if ((rc == 0) && (bos_server != NULL)) {
266 if (bos_server->server) {
267 rx_ReleaseCachedConnection(bos_server->server);
269 if (bos_server->server_encrypt) {
270 rx_ReleaseCachedConnection(bos_server->server_encrypt);
282 * bos_ServerClose - close a bos server handle
286 * IN serverHandle - a bos server handle previously returned by bos_ServerOpen
290 * No locks are obtained or released by this function
294 * Returns != 0 upon successful completion.
297 int ADMINAPI bos_ServerClose(
298 const void *serverHandle,
302 afs_status_t tst = 0;
303 bos_server_p b_handle = (bos_server_p) serverHandle;
305 if (isValidServerHandle(b_handle, &tst)) {
306 rx_ReleaseCachedConnection(b_handle->server);
307 b_handle->is_valid = 0;
319 * bos_ProcessCreate - create a new process to run at a bos server.
323 * IN serverHandle - a previously opened serverHandle.
325 * IN processName - the name of the process to create.
327 * IN processType - the type of process to create.
329 * IN process - the path to the process binary at the bos server.
331 * IN cronTime - the time specification for cron processes.
333 * IN notifier - the path to the notifier binary at the bos server.
337 * No locks are obtained or released by this function
341 * Returns != 0 upon successful completion.
345 * CAUTION - this list must match bos_ProcessType_t definition
348 static char *processTypes[] = {"simple", "fs", "cron", 0};
350 int ADMINAPI bos_ProcessCreate(
351 const void *serverHandle,
352 const char *processName,
353 bos_ProcessType_t processType,
355 const char *cronTime,
356 const char *notifier,
360 afs_status_t tst = 0;
361 bos_server_p b_handle = (bos_server_p) serverHandle;
363 if (!isValidServerHandle(b_handle, &tst)) {
364 goto fail_bos_ProcessCreate;
367 if (processType == BOS_PROCESS_FS) {
368 tst = ADMBOSPROCESSCREATEBADTYPE;
369 goto fail_bos_ProcessCreate;
372 if ((processName == NULL) || (*processName == 0)) {
373 tst = ADMBOSPROCESSNAMENULL;
374 goto fail_bos_ProcessCreate;
377 if ((process == NULL) || (*process == 0)) {
378 tst = ADMBOSPROCESSNULL;
379 goto fail_bos_ProcessCreate;
382 if ((processType == BOS_PROCESS_CRON) && (cronTime == NULL)) {
383 tst = ADMBOSCRONTIMENULL;
384 goto fail_bos_ProcessCreate;
387 if ((processType == BOS_PROCESS_SIMPLE) && (cronTime != NULL)) {
388 tst = ADMBOSCRONTIMENOTNULL;
389 goto fail_bos_ProcessCreate;
392 tst = BOZO_CreateBnode(b_handle->server, processTypes[processType],
393 processName, process,
394 (cronTime) ? cronTime : "", "", "", "",
395 (notifier) ? notifier : NONOTIFIER);
400 fail_bos_ProcessCreate:
409 * bos_FSProcessCreate - create the fs group of processes at the boserver.
413 * IN serverHandle - a previously opened serverHandle.
415 * IN processName - the name of the process to create.
417 * IN fileserverPath - the path to the fileserver binary at the bos server.
419 * IN volserverPath - the path to the volserver binary at the bos server.
421 * IN salvagerPath - the path to the salvager binary at the bos server.
423 * IN notifier - the path to the notifier binary at the bos server.
427 * No locks are obtained or released by this function
431 * Returns != 0 upon successful completion.
434 int ADMINAPI bos_FSProcessCreate(
435 const void *serverHandle,
436 const char *processName,
437 const char *fileserverPath,
438 const char *volserverPath,
439 const char *salvagerPath,
440 const char *notifier,
444 afs_status_t tst = 0;
445 bos_server_p b_handle = (bos_server_p) serverHandle;
447 if (!isValidServerHandle(b_handle, &tst)) {
448 goto fail_bos_ProcessCreate;
451 if ((processName == NULL) || (*processName == 0)) {
452 tst = ADMBOSPROCESSNAMENULL;
453 goto fail_bos_ProcessCreate;
456 if ((fileserverPath == NULL) || (*fileserverPath == 0)) {
457 tst = ADMBOSFILESERVERPATHNULL;
458 goto fail_bos_ProcessCreate;
461 if ((volserverPath == NULL) || (*volserverPath == 0)) {
462 tst = ADMBOSVOLSERVERPATHNULL;
463 goto fail_bos_ProcessCreate;
466 if ((salvagerPath == NULL) || (*salvagerPath == 0)) {
467 tst = ADMBOSSALVAGERPATHNULL;
468 goto fail_bos_ProcessCreate;
471 tst = BOZO_CreateBnode(b_handle->server,
472 processTypes[BOS_PROCESS_FS],
479 (notifier) ? notifier : NONOTIFIER);
484 fail_bos_ProcessCreate:
493 * bos_ProcessDelete - delete an existing process at a bos server.
497 * IN serverHandle - a previously opened serverHandle.
499 * IN processName - the name of the process to delete.
503 * No locks are obtained or released by this function
507 * Returns != 0 upon successful completion.
510 int ADMINAPI bos_ProcessDelete(
511 const void *serverHandle,
512 const char *processName,
516 afs_status_t tst = 0;
517 bos_server_p b_handle = (bos_server_p) serverHandle;
519 if (!isValidServerHandle(b_handle, &tst)) {
520 goto fail_bos_ProcessDelete;
523 if ((processName == NULL) || (*processName == 0)) {
524 tst = ADMBOSPROCESSNAMENULL;
525 goto fail_bos_ProcessDelete;
528 tst = BOZO_DeleteBnode(b_handle->server, processName);
534 fail_bos_ProcessDelete:
543 * bos_ProcessExecutionStateGet - get the current execution state of a
548 * IN serverHandle - a previously opened serverHandle.
550 * IN processName - the name of the process to retrieve.
552 * OUT processStatusP - upon successful completion the process execution state
554 * OUT auxiliaryProcessStatus - set to point to aux proc status if available.
555 * Pass a pointer to an char array at least BOS_MAX_NAME_LEN long.
559 * No locks are obtained or released by this function
563 * Returns != 0 upon successful completion.
566 int ADMINAPI bos_ProcessExecutionStateGet(
567 const void *serverHandle,
568 const char *processName,
569 bos_ProcessExecutionState_p processStatusP,
570 char *auxiliaryProcessStatus,
574 afs_status_t tst = 0;
575 bos_server_p b_handle = (bos_server_p) serverHandle;
578 if (!isValidServerHandle(b_handle, &tst)) {
579 goto fail_bos_ProcessExecutionStateGet;
582 if ((processName == NULL) || (*processName == 0)) {
583 tst = ADMBOSPROCESSNAMENULL;
584 goto fail_bos_ProcessExecutionStateGet;
587 if (processStatusP == NULL) {
588 tst = ADMBOSPROCESSSTATUSPNULL;
589 goto fail_bos_ProcessExecutionStateGet;
592 if (auxiliaryProcessStatus == NULL) {
593 tst = ADMBOSAUXILIARYPROCESSSTATUSNULL;
594 goto fail_bos_ProcessExecutionStateGet;
597 tst = BOZO_GetStatus(b_handle->server, processName, &state, &auxiliaryProcessStatus);
600 goto fail_bos_ProcessExecutionStateGet;
603 *processStatusP = (bos_ProcessExecutionState_t) state;
606 fail_bos_ProcessExecutionStateGet:
615 * SetExecutionState - set the execution state of a process
619 * IN serverHandle - a previously opened serverHandle.
621 * IN processName - the name of the process to modify.
623 * IN processStatus - the new process state.
625 * IN func - the function to call to set the status.
629 * No locks are obtained or released by this function
633 * Returns != 0 upon successful completion.
636 static int SetExecutionState(
637 const void *serverHandle,
638 const char *processName,
639 const bos_ProcessExecutionState_t processStatus,
640 int (*func)(struct rx_connection *, const char *, afs_int32),
644 afs_status_t tst = 0;
645 bos_server_p b_handle = (bos_server_p) serverHandle;
648 if (!isValidServerHandle(b_handle, &tst)) {
649 goto fail_SetExecutionState;
652 if ((processName == NULL) || (*processName == 0)) {
653 tst = ADMBOSPROCESSNAMENULL;
654 goto fail_SetExecutionState;
657 if ((processStatus != BOS_PROCESS_STOPPED) &&
658 (processStatus != BOS_PROCESS_RUNNING)) {
659 tst = ADMBOSPROCESSSTATUSSET;
660 goto fail_SetExecutionState;
663 state = (afs_int32) processStatus;
665 tst = func(b_handle->server, processName, state);
671 fail_SetExecutionState:
680 * bos_ProcessExecutionStateSet - set the execution state of a process
684 * IN serverHandle - a previously opened serverHandle.
686 * IN processName - the name of the process to modify.
688 * IN processStatus - the new process state.
692 * No locks are obtained or released by this function
696 * Returns != 0 upon successful completion.
699 int ADMINAPI bos_ProcessExecutionStateSet(
700 const void *serverHandle,
701 const char *processName,
702 bos_ProcessExecutionState_t processStatus,
705 return SetExecutionState(serverHandle, processName, processStatus,
710 * bos_ProcessExecutionStateSetTemporary - set the execution state of a process
715 * IN serverHandle - a previously opened serverHandle.
717 * IN processName - the name of the process to modify.
719 * IN processStatus - the new process state.
723 * No locks are obtained or released by this function
727 * Returns != 0 upon successful completion.
730 int ADMINAPI bos_ProcessExecutionStateSetTemporary(
731 const void *serverHandle,
732 const char *processName,
733 bos_ProcessExecutionState_t processStatus,
736 return SetExecutionState(serverHandle, processName, processStatus,
737 BOZO_SetTStatus, st);
741 * The iterator functions and data for the process name retrieval functions
744 typedef struct process_name_get {
746 struct rx_connection *server;
747 char process[CACHED_ITEMS][BOS_MAX_NAME_LEN];
748 } process_name_get_t, *process_name_get_p;
750 static int GetProcessNameRPC(
754 int *last_item_contains_data,
758 afs_status_t tst = 0;
759 process_name_get_p proc = (process_name_get_p) rpc_specific;
760 char *ptr = (char *) &proc->process[slot];
762 tst = BOZO_EnumerateInstance(proc->server, proc->next++, &ptr);
766 } else if (tst == BZDOM) {
770 *last_item_contains_data = 0;
779 static int GetProcessNameFromCache(
786 afs_status_t tst = 0;
787 process_name_get_p proc = (process_name_get_p) rpc_specific;
789 strcpy((char *) dest, (char *) &proc->process[slot]);
799 * bos_ProcessNameGetBegin - begin iterating over the list of processes
800 * at a particular bos server.
804 * IN serverHandle - a previously opened serverHandle.
806 * OUT iter - an iterator that can be passed to bos_ProcessNameGetNext
807 * to retrieve the process names.
811 * No locks are obtained or released by this function
815 * Returns != 0 upon successful completion.
819 int ADMINAPI bos_ProcessNameGetBegin(
820 const void *serverHandle,
825 afs_status_t tst = 0;
826 bos_server_p b_handle = (bos_server_p) serverHandle;
827 afs_admin_iterator_p iter = (afs_admin_iterator_p) malloc(sizeof(afs_admin_iterator_t));
828 process_name_get_p proc = (process_name_get_p) malloc(sizeof(process_name_get_t));
830 if (!isValidServerHandle(b_handle, &tst)) {
831 goto fail_bos_ProcessNameGetBegin;
834 if (iterationIdP == NULL) {
835 tst = ADMITERATIONIDPNULL;
836 goto fail_bos_ProcessNameGetBegin;
839 if ((iter == NULL) || (proc == NULL)) {
841 goto fail_bos_ProcessNameGetBegin;
845 proc->server = b_handle->server;
847 if (IteratorInit(iter, (void *) proc, GetProcessNameRPC, GetProcessNameFromCache, NULL, NULL, &tst)) {
848 *iterationIdP = (void *) iter;
850 goto fail_bos_ProcessNameGetBegin;
854 fail_bos_ProcessNameGetBegin:
872 * bos_ProcessNameGetNext - retrieve the next process name from the bos server.
876 * IN iterationId - an iterator previously returned by bos_ProcessNameGetBegin
878 * OUT processName - upon successful completion contains the next process name
879 * retrieved from the server.
883 * No locks are obtained or released by this function
887 * Returns != 0 upon successful completion.
891 int ADMINAPI bos_ProcessNameGetNext(
892 const void *iterationId,
897 afs_status_t tst = 0;
898 afs_admin_iterator_p iter = (afs_admin_iterator_p) iterationId;
900 if (processName == NULL) {
901 tst = ADMBOSPROCESSNAMENULL;
902 goto fail_bos_ProcessNameGetNext;
905 if (iterationId == NULL) {
906 tst = ADMITERATIONIDPNULL;
907 goto fail_bos_ProcessNameGetNext;
910 rc = IteratorNext(iter, (void *) processName, &tst);
912 fail_bos_ProcessNameGetNext:
921 * bos_ProcessNameGetDone - finish using a process name iterator.
925 * IN iterationId - an iterator previously returned by bos_ProcessNameGetBegin
929 * No locks are obtained or released by this function
933 * Returns != 0 upon successful completion.
937 int ADMINAPI bos_ProcessNameGetDone(
938 const void *iterationId,
942 afs_status_t tst = 0;
943 afs_admin_iterator_p iter = (afs_admin_iterator_p) iterationId;
945 if (iterationId == NULL) {
946 tst = ADMITERATIONIDPNULL;
947 goto fail_bos_ProcessNameGetDone;
950 rc = IteratorDone(iter, &tst);
952 fail_bos_ProcessNameGetDone:
961 * bos_ProcessInfoGet - get information about a single process
965 * IN serverHandle - a previously opened serverHandle.
967 * IN processName - the process of interest.
969 * OUT processTypeP - upon successful completion contains the process type
971 * OUT processInfoP - upon successful completion contains the process info
975 * No locks are obtained or released by this function
979 * Returns != 0 upon successful completion.
983 int ADMINAPI bos_ProcessInfoGet(
984 const void *serverHandle,
985 const char *processName,
986 bos_ProcessType_p processTypeP,
987 bos_ProcessInfo_p processInfoP,
991 afs_status_t tst = 0;
992 bos_server_p b_handle = (bos_server_p) serverHandle;
993 char type[BOS_MAX_NAME_LEN];
995 struct bozo_status status;
998 if (!isValidServerHandle(b_handle, &tst)) {
999 goto fail_bos_ProcessInfoGet;
1002 if ((processName == NULL) || (*processName == 0)) {
1003 tst = ADMBOSPROCESSNAMENULL;
1004 goto fail_bos_ProcessInfoGet;
1007 if (processTypeP == NULL) {
1008 tst = ADMBOSPROCESSTYPEPNULL;
1009 goto fail_bos_ProcessInfoGet;
1012 if (processInfoP == NULL) {
1013 tst = ADMBOSPROCESSINFOPNULL;
1014 goto fail_bos_ProcessInfoGet;
1017 tst = BOZO_GetInstanceInfo(b_handle->server, processName, &ptr, &status);
1020 goto fail_bos_ProcessInfoGet;
1024 for(i=0;(processTypes[i] != NULL); i++) {
1025 if (!strcmp(processTypes[i], type)) {
1026 *processTypeP = (bos_ProcessType_t) i;
1031 if (processTypes[i] == NULL) {
1032 tst = ADMBOSINVALIDPROCESSTYPE;
1033 goto fail_bos_ProcessInfoGet;
1036 processInfoP->processGoal = (bos_ProcessExecutionState_t) status.goal;
1037 processInfoP->processStartTime = status.procStartTime;
1038 processInfoP->numberProcessStarts = status.procStarts;
1039 processInfoP->processExitTime = status.lastAnyExit;
1040 processInfoP->processExitErrorTime = status.lastErrorExit;
1041 processInfoP->processErrorCode = status.errorCode;
1042 processInfoP->processErrorSignal = status.errorSignal;
1043 processInfoP->state = BOS_PROCESS_OK;
1045 if (status.flags & BOZO_ERRORSTOP) {
1046 processInfoP->state |= BOS_PROCESS_TOO_MANY_ERRORS;
1048 if (status.flags & BOZO_HASCORE) {
1049 processInfoP->state |= BOS_PROCESS_CORE_DUMPED;
1051 if (status.flags & BOZO_BADDIRACCESS) {
1052 processInfoP->state |= BOS_PROCESS_BAD_FILE_ACCESS;
1056 fail_bos_ProcessInfoGet:
1065 * The iterator functions and data for the parameter retrieval functions
1068 typedef struct param_get {
1070 struct rx_connection *server;
1071 char processName[BOS_MAX_NAME_LEN];
1072 char param[CACHED_ITEMS][BOS_MAX_NAME_LEN];
1073 } param_get_t, *param_get_p;
1075 static int GetParameterRPC(
1079 int *last_item_contains_data,
1083 afs_status_t tst = 0;
1084 param_get_p param = (param_get_p) rpc_specific;
1085 char *ptr = (char *) ¶m->param[slot];
1087 tst = BOZO_GetInstanceParm(param->server, param->processName,
1088 param->next++, &ptr);
1092 } else if (tst == BZDOM) {
1096 *last_item_contains_data = 0;
1105 static int GetParameterFromCache(
1112 afs_status_t tst = 0;
1113 param_get_p param = (param_get_p) rpc_specific;
1115 strcpy((char *) dest, (char *) ¶m->param[slot]);
1125 * bos_ProcessParameterGetBegin - begin iterating over the parameters
1126 * of a particular process.
1130 * IN serverHandle - a previously opened serverHandle.
1132 * IN processName - the process whose parameters are returned.
1134 * OUT iter - an iterator that can be passed to bos_ProcessParameterGetNext
1135 * to retrieve the parameters.
1139 * No locks are obtained or released by this function
1143 * Returns != 0 upon successful completion.
1147 int ADMINAPI bos_ProcessParameterGetBegin(
1148 const void *serverHandle,
1149 const char *processName,
1150 void **iterationIdP,
1154 afs_status_t tst = 0;
1155 bos_server_p b_handle = (bos_server_p) serverHandle;
1156 afs_admin_iterator_p iter = (afs_admin_iterator_p) malloc(sizeof(afs_admin_iterator_t));
1157 param_get_p param = (param_get_p) malloc(sizeof(param_get_t));
1159 if (!isValidServerHandle(b_handle, &tst)) {
1160 goto fail_bos_ProcessParameterGetBegin;
1163 if ((processName == NULL) || (*processName == 0)) {
1164 tst = ADMBOSPROCESSNAMENULL;
1165 goto fail_bos_ProcessParameterGetBegin;
1168 if (iterationIdP == NULL) {
1169 tst = ADMITERATIONIDPNULL;
1170 goto fail_bos_ProcessParameterGetBegin;
1173 if ((iter == NULL) || (param == NULL)) {
1175 goto fail_bos_ProcessParameterGetBegin;
1179 param->server = b_handle->server;
1180 strcpy(param->processName, processName);
1182 if (IteratorInit(iter, (void *) param, GetParameterRPC,
1183 GetParameterFromCache, NULL, NULL, &tst)) {
1184 *iterationIdP = (void *) iter;
1186 goto fail_bos_ProcessParameterGetBegin;
1190 fail_bos_ProcessParameterGetBegin:
1196 if (param != NULL) {
1208 * bos_ProcessParameterGetNext - retrieve the next parameter
1209 * from the bos server.
1213 * IN iterationId - an iterator previously returned by
1214 * bos_ProcessParameterGetBegin
1216 * OUT parameter - upon successful completion contains the next parameter
1217 * retrieved from the server.
1221 * No locks are obtained or released by this function
1225 * Returns != 0 upon successful completion.
1229 int ADMINAPI bos_ProcessParameterGetNext(
1230 const void *iterationId,
1235 afs_status_t tst = 0;
1236 afs_admin_iterator_p iter = (afs_admin_iterator_p) iterationId;
1238 if (iterationId == NULL) {
1239 tst = ADMITERATIONIDPNULL;
1240 goto fail_bos_ProcessParameterGetNext;
1243 if (parameter == NULL) {
1244 tst = ADMBOSPARAMETERNULL;
1245 goto fail_bos_ProcessParameterGetNext;
1248 rc = IteratorNext(iter, (void *) parameter, &tst);
1250 fail_bos_ProcessParameterGetNext:
1259 * bos_ProcessParameterGetDone - finish using a process name iterator.
1263 * IN iterationId - an iterator previously returned by
1264 * bos_ProcessParameterGetBegin
1268 * No locks are obtained or released by this function
1272 * Returns != 0 upon successful completion.
1276 int ADMINAPI bos_ProcessParameterGetDone(
1277 const void *iterationId,
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.
1321 int ADMINAPI bos_ProcessNotifierGet(
1322 const void *serverHandle,
1323 const char *processName,
1328 afs_status_t tst = 0;
1329 bos_server_p b_handle = (bos_server_p) serverHandle;
1331 if (!isValidServerHandle(b_handle, &tst)) {
1332 goto fail_bos_ProcessNotifierGet;
1335 if ((processName == NULL) || (*processName == 0)) {
1336 tst = ADMBOSPROCESSNAMENULL;
1337 goto fail_bos_ProcessNotifierGet;
1340 if (notifier == NULL) {
1341 tst = ADMBOSNOTIFIERNULL;
1342 goto fail_bos_ProcessNotifierGet;
1345 tst = BOZO_GetInstanceParm(b_handle->server, processName, 999, ¬ifier);
1351 fail_bos_ProcessNotifierGet:
1360 * bos_ProcessRestart - restart a particular process.
1364 * IN serverHandle - a previously opened serverHandle.
1366 * IN processName - the process to restart
1370 * No locks are obtained or released by this function
1374 * Returns != 0 upon successful completion.
1378 int ADMINAPI bos_ProcessRestart(
1379 const void *serverHandle,
1380 const char *processName,
1384 afs_status_t tst = 0;
1385 bos_server_p b_handle = (bos_server_p) serverHandle;
1387 if (!isValidServerHandle(b_handle, &tst)) {
1388 goto fail_bos_ProcessRestart;
1391 if ((processName == NULL) || (*processName == 0)) {
1392 tst = ADMBOSPROCESSNAMENULL;
1393 goto fail_bos_ProcessRestart;
1396 tst = BOZO_Restart(b_handle->server, processName);
1402 fail_bos_ProcessRestart:
1411 * bos_ProcessAllStop - stop all running processes at a server.
1415 * IN serverHandle - a previously opened serverHandle.
1419 * No locks are obtained or released by this function
1423 * Returns != 0 upon successful completion.
1427 int ADMINAPI bos_ProcessAllStop(
1428 const void *serverHandle,
1432 afs_status_t tst = 0;
1433 bos_server_p b_handle = (bos_server_p) serverHandle;
1435 if (!isValidServerHandle(b_handle, &tst)) {
1436 goto fail_bos_ProcessAllStop;
1439 tst = BOZO_ShutdownAll(b_handle->server);
1445 fail_bos_ProcessAllStop:
1454 * bos_ProcessAllStart - start all processes that should be running at a
1459 * IN serverHandle - a previously opened serverHandle.
1463 * No locks are obtained or released by this function
1467 * Returns != 0 upon successful completion.
1471 int ADMINAPI bos_ProcessAllStart(
1472 const void *serverHandle,
1476 afs_status_t tst = 0;
1477 bos_server_p b_handle = (bos_server_p) serverHandle;
1479 if (!isValidServerHandle(b_handle, &tst)) {
1480 goto fail_bos_ProcessAllStart;
1483 tst = BOZO_StartupAll(b_handle->server);
1489 fail_bos_ProcessAllStart:
1498 * bos_ProcessAllWaitStop - stop all processes, and block until they have
1503 * IN serverHandle - a previously opened serverHandle.
1507 * No locks are obtained or released by this function
1511 * Returns != 0 upon successful completion.
1515 int ADMINAPI bos_ProcessAllWaitStop(
1516 const void *serverHandle,
1520 afs_status_t tst = 0;
1521 bos_server_p b_handle = (bos_server_p) serverHandle;
1523 if (!isValidServerHandle(b_handle, &tst)) {
1524 goto fail_bos_ProcessAllWaitStop;
1527 if (!bos_ProcessAllStop(serverHandle, &tst)) {
1528 goto fail_bos_ProcessAllWaitStop;
1531 tst = BOZO_WaitAll(b_handle->server);
1537 fail_bos_ProcessAllWaitStop:
1546 * bos_ProcessAllWaitTransition - block until all processes at the bosserver
1547 * have reached their desired state.
1551 * IN serverHandle - a previously opened serverHandle.
1555 * No locks are obtained or released by this function
1559 * Returns != 0 upon successful completion.
1563 int ADMINAPI bos_ProcessAllWaitTransition(
1564 const void *serverHandle,
1568 afs_status_t tst = 0;
1569 bos_server_p b_handle = (bos_server_p) serverHandle;
1571 if (!isValidServerHandle(b_handle, &tst)) {
1572 goto fail_bos_ProcessAllWaitTransition;
1575 tst = BOZO_WaitAll(b_handle->server);
1581 fail_bos_ProcessAllWaitTransition:
1590 * bos_ProcessAllStopAndRestart - stop all the running processes, restart
1591 * them, and optionally restart the bosserver itself.
1596 * IN serverHandle - a previously opened serverHandle.
1598 * IN restartBosServer - flag to indicate whether to restart bosserver.
1602 * No locks are obtained or released by this function
1606 * Returns != 0 upon successful completion.
1610 int ADMINAPI bos_ProcessAllStopAndRestart(
1611 const void *serverHandle,
1612 bos_RestartBosServer_t restartBosServer,
1616 afs_status_t tst = 0;
1617 bos_server_p b_handle = (bos_server_p) serverHandle;
1619 if (!isValidServerHandle(b_handle, &tst)) {
1620 goto fail_bos_ProcessAllStopAndRestart;
1623 if (restartBosServer == BOS_RESTART_BOS_SERVER) {
1624 tst = BOZO_ReBozo(b_handle->server);
1626 goto fail_bos_ProcessAllStopAndRestart;
1630 tst = BOZO_RestartAll(b_handle->server);
1636 fail_bos_ProcessAllStopAndRestart:
1645 * bos_AdminCreate - create a new admin.
1649 * IN serverHandle - a previously opened serverHandle.
1651 * IN adminName - the new admin name.
1655 * No locks are obtained or released by this function
1659 * Returns != 0 upon successful completion.
1663 int ADMINAPI bos_AdminCreate(
1664 const void *serverHandle,
1665 const char *adminName,
1669 afs_status_t tst = 0;
1670 bos_server_p b_handle = (bos_server_p) serverHandle;
1672 if (!isValidServerHandle(b_handle, &tst)) {
1673 goto fail_bos_AdminCreate;
1676 if ((adminName == NULL) || (*adminName == 0)) {
1677 tst = ADMBOSADMINNAMENULL;
1678 goto fail_bos_AdminCreate;
1681 tst = BOZO_AddSUser(b_handle->server, adminName);
1687 fail_bos_AdminCreate:
1696 * bos_AdminDelete - delete a new admin.
1700 * IN serverHandle - a previously opened serverHandle.
1702 * IN adminName - the admin name.
1706 * No locks are obtained or released by this function
1710 * Returns != 0 upon successful completion.
1714 int ADMINAPI bos_AdminDelete(
1715 const void *serverHandle,
1716 const char *adminName,
1720 afs_status_t tst = 0;
1721 bos_server_p b_handle = (bos_server_p) serverHandle;
1723 if (!isValidServerHandle(b_handle, &tst)) {
1724 goto fail_bos_AdminDelete;
1727 if ((adminName == NULL) || (*adminName == 0)) {
1728 tst = ADMBOSADMINNAMENULL;
1729 goto fail_bos_AdminDelete;
1732 tst = BOZO_DeleteSUser(b_handle->server, adminName);
1738 fail_bos_AdminDelete:
1747 * The iterator functions and data for the admin retrieval functions
1750 typedef struct admin_get {
1752 struct rx_connection *server;
1753 char admin[CACHED_ITEMS][BOS_MAX_NAME_LEN];
1754 } admin_get_t, *admin_get_p;
1756 static int GetAdminRPC(
1760 int *last_item_contains_data,
1764 afs_status_t tst = 0;
1765 admin_get_p admin = (admin_get_p) rpc_specific;
1766 char *ptr = (char *) &admin->admin[slot];
1768 tst = BOZO_ListSUsers(admin->server, admin->next++, &ptr);
1771 * There's no way to tell the difference between an rpc failure
1772 * and the end of the list, so we assume that any error means the
1779 *last_item_contains_data = 0;
1789 static int GetAdminFromCache(
1796 afs_status_t tst = 0;
1797 admin_get_p admin = (admin_get_p) rpc_specific;
1799 strcpy((char *) dest, (char *) &admin->admin[slot]);
1809 * bos_AdminGetBegin - begin iterating over the administrators.
1813 * IN serverHandle - a previously opened serverHandle.
1815 * OUT iter - an iterator that can be passed to bos_AdminGetBegin
1816 * to retrieve the administrators.
1820 * No locks are obtained or released by this function
1824 * Returns != 0 upon successful completion.
1828 int ADMINAPI bos_AdminGetBegin(
1829 const void *serverHandle,
1830 void **iterationIdP,
1834 afs_status_t tst = 0;
1835 bos_server_p b_handle = (bos_server_p) serverHandle;
1836 afs_admin_iterator_p iter = (afs_admin_iterator_p) malloc(sizeof(afs_admin_iterator_t));
1837 admin_get_p admin = (admin_get_p) malloc(sizeof(admin_get_t));
1839 if (!isValidServerHandle(b_handle, &tst)) {
1840 goto fail_bos_AdminGetBegin;
1843 if (iterationIdP == NULL) {
1844 tst = ADMITERATIONIDPNULL;
1845 goto fail_bos_AdminGetBegin;
1848 if ((iter == NULL) || (admin == NULL)) {
1850 goto fail_bos_AdminGetBegin;
1854 admin->server = b_handle->server;
1856 if (IteratorInit(iter, (void *) admin, GetAdminRPC,
1857 GetAdminFromCache, NULL, NULL, &tst)) {
1858 *iterationIdP = (void *) iter;
1862 fail_bos_AdminGetBegin:
1868 if (admin != NULL) {
1880 * bos_AdminGetNext - retrieve the next administrator
1881 * from the bos server.
1885 * IN iterationId - an iterator previously returned by
1888 * OUT adminName - upon successful completion contains the next administrator
1889 * retrieved from the server.
1893 * No locks are obtained or released by this function
1897 * Returns != 0 upon successful completion.
1901 int ADMINAPI bos_AdminGetNext(
1902 const void *iterationId,
1907 afs_status_t tst = 0;
1908 afs_admin_iterator_p iter = (afs_admin_iterator_p) iterationId;
1910 if (iterationId == NULL) {
1911 tst = ADMITERATIONIDPNULL;
1912 goto fail_bos_AdminGetNext;
1915 if (adminName == NULL) {
1916 tst = ADMBOSADMINNAMENULL;
1917 goto fail_bos_AdminGetNext;
1920 rc = IteratorNext(iter, (void *) adminName, &tst);
1922 fail_bos_AdminGetNext:
1931 * bos_AdminGetDone - finish using a administrator iterator.
1935 * IN iterationId - an iterator previously returned by
1940 * No locks are obtained or released by this function
1944 * Returns != 0 upon successful completion.
1948 int ADMINAPI bos_AdminGetDone(
1949 const void *iterationId,
1953 afs_status_t tst = 0;
1954 afs_admin_iterator_p iter = (afs_admin_iterator_p) iterationId;
1956 if (iterationId == NULL) {
1957 tst = ADMITERATIONIDPNULL;
1958 goto fail_bos_AdminGetDone;
1961 rc = IteratorDone(iter, &tst);
1963 fail_bos_AdminGetDone:
1972 * bos_KeyCreate - add a new key to the keyfile.
1976 * IN serverHandle - a previously opened serverHandle.
1978 * IN keyVersionNumber - the key version number.
1980 * IN key - the new key.
1984 * No locks are obtained or released by this function
1988 * Returns != 0 upon successful completion.
1992 int ADMINAPI bos_KeyCreate(
1993 const void *serverHandle,
1994 int keyVersionNumber,
1995 const kas_encryptionKey_p key,
1999 afs_status_t tst = 0;
2000 bos_server_p b_handle = (bos_server_p) serverHandle;
2002 if (!isValidServerHandle(b_handle, &tst)) {
2003 goto fail_bos_KeyCreate;
2007 tst = ADMBOSKEYNULL;
2008 goto fail_bos_KeyCreate;
2011 tst = BOZO_AddKey(b_handle->server_encrypt, keyVersionNumber, key);
2026 * bos_KeyDelete - delete an existing key from the keyfile.
2030 * IN serverHandle - a previously opened serverHandle.
2032 * IN keyVersionNumber - the key version number.
2036 * No locks are obtained or released by this function
2040 * Returns != 0 upon successful completion.
2044 int ADMINAPI bos_KeyDelete(
2045 const void *serverHandle,
2046 int keyVersionNumber,
2050 afs_status_t tst = 0;
2051 bos_server_p b_handle = (bos_server_p) serverHandle;
2053 if (!isValidServerHandle(b_handle, &tst)) {
2054 goto fail_bos_KeyDelete;
2057 tst = BOZO_DeleteKey(b_handle->server, keyVersionNumber);
2072 * The iterator functions and data for the key retrieval functions
2075 typedef struct key_get {
2077 struct rx_connection *server;
2078 bos_KeyInfo_t key[CACHED_ITEMS];
2079 } key_get_t, *key_get_p;
2081 static int GetKeyRPC(
2085 int *last_item_contains_data,
2089 afs_status_t tst = 0;
2090 key_get_p key = (key_get_p) rpc_specific;
2091 char *ptr = (char *) &key->key[slot];
2092 struct bozo_keyInfo keyInfo;
2094 tst = BOZO_ListKeys(key->server, key->next++,
2095 &key->key[slot].keyVersionNumber,
2096 &key->key[slot].key, &keyInfo);
2100 key->key[slot].keyStatus.lastModificationDate = keyInfo.mod_sec;
2101 key->key[slot].keyStatus.lastModificationMicroSeconds =
2103 key->key[slot].keyStatus.checkSum = keyInfo.keyCheckSum;
2105 } else if (tst == BZDOM) {
2109 *last_item_contains_data = 0;
2118 static int GetKeyFromCache(
2125 afs_status_t tst = 0;
2126 key_get_p key = (key_get_p) rpc_specific;
2128 memcpy(dest, &key->key[slot], sizeof(bos_KeyInfo_t));
2138 * bos_KeyGetBegin - begin iterating over the keys.
2142 * IN serverHandle - a previously opened serverHandle.
2144 * OUT iter - an iterator that can be passed to bos_KeyGetNext
2145 * to retrieve the keys.
2149 * No locks are obtained or released by this function
2153 * Returns != 0 upon successful completion.
2157 int ADMINAPI bos_KeyGetBegin(
2158 const void *serverHandle,
2159 void **iterationIdP,
2163 afs_status_t tst = 0;
2164 bos_server_p b_handle = (bos_server_p) serverHandle;
2165 afs_admin_iterator_p iter = (afs_admin_iterator_p) malloc(sizeof(afs_admin_iterator_t));
2166 key_get_p key = (key_get_p) malloc(sizeof(key_get_t));
2168 if (!isValidServerHandle(b_handle, &tst)) {
2169 goto fail_bos_KeyGetBegin;
2172 if (iterationIdP == NULL) {
2173 tst = ADMITERATIONIDPNULL;
2174 goto fail_bos_KeyGetBegin;
2177 if ((iter == NULL) || (key == NULL)) {
2179 goto fail_bos_KeyGetBegin;
2183 key->server = b_handle->server_encrypt;
2185 if (IteratorInit(iter, (void *) key, GetKeyRPC,
2186 GetKeyFromCache, NULL, NULL, &tst)) {
2187 *iterationIdP = (void *) iter;
2191 fail_bos_KeyGetBegin:
2209 * bos_KeyGetNext - retrieve the next key
2210 * from the bos server.
2214 * IN iterationId - an iterator previously returned by
2217 * OUT keyP - upon successful completion contains the next key
2218 * retrieved from the server.
2222 * No locks are obtained or released by this function
2226 * Returns != 0 upon successful completion.
2230 int ADMINAPI bos_KeyGetNext(
2231 const void *iterationId,
2236 afs_status_t tst = 0;
2237 afs_admin_iterator_p iter = (afs_admin_iterator_p) iterationId;
2239 if (iterationId == NULL) {
2240 tst = ADMITERATIONIDPNULL;
2241 goto fail_bos_KeyGetNext;
2245 tst = ADMBOSKEYPNULL;
2246 goto fail_bos_KeyGetNext;
2249 rc = IteratorNext(iter, (void *) keyP, &tst);
2251 fail_bos_KeyGetNext:
2260 * bos_KeyGetDone - finish using a key iterator.
2264 * IN iterationId - an iterator previously returned by
2269 * No locks are obtained or released by this function
2273 * Returns != 0 upon successful completion.
2277 int ADMINAPI bos_KeyGetDone(
2278 const void *iterationId,
2282 afs_status_t tst = 0;
2283 afs_admin_iterator_p iter = (afs_admin_iterator_p) iterationId;
2285 if (iterationId == NULL) {
2286 tst = ADMITERATIONIDPNULL;
2287 goto fail_bos_KeyGetDone;
2290 rc = IteratorDone(iter, &tst);
2292 fail_bos_KeyGetDone:
2301 * bos_CellSet - set the cell name at a bos server.
2305 * IN serverHandle - a previously opened serverHandle.
2307 * IN cellName - the new cell name.
2311 * No locks are obtained or released by this function
2315 * Returns != 0 upon successful completion.
2318 int ADMINAPI bos_CellSet(
2319 const void *serverHandle,
2320 const char *cellName,
2324 afs_status_t tst = 0;
2325 bos_server_p b_handle = (bos_server_p) serverHandle;
2327 if (!isValidServerHandle(b_handle, &tst)) {
2328 goto fail_bos_CellSet;
2331 if ((cellName == NULL) || (*cellName == 0)) {
2332 tst = ADMCLIENTCELLNAMENULL;
2333 goto fail_bos_CellSet;
2336 tst = BOZO_SetCellName(b_handle->server, cellName);
2351 * bos_CellGet - get the cell name at a bos server.
2355 * IN serverHandle - a previously opened serverHandle.
2357 * OUT cellName - the cell name.
2361 * No locks are obtained or released by this function
2365 * Returns != 0 upon successful completion.
2368 int ADMINAPI bos_CellGet(
2369 const void *serverHandle,
2374 afs_status_t tst = 0;
2375 bos_server_p b_handle = (bos_server_p) serverHandle;
2377 if (!isValidServerHandle(b_handle, &tst)) {
2378 goto fail_bos_CellGet;
2381 if (cellName == NULL) {
2382 tst = ADMCLIENTCELLNAMENULL;
2383 goto fail_bos_CellGet;
2386 tst = BOZO_GetCellName(b_handle->server, &cellName);
2401 * bos_HostCreate - add a new host to the cell.
2405 * IN serverHandle - a previously opened serverHandle.
2407 * IN hostName - the new host.
2411 * No locks are obtained or released by this function
2415 * Returns != 0 upon successful completion.
2418 int ADMINAPI bos_HostCreate(
2419 const void *serverHandle,
2420 const char *hostName,
2424 afs_status_t tst = 0;
2425 bos_server_p b_handle = (bos_server_p) serverHandle;
2427 if (!isValidServerHandle(b_handle, &tst)) {
2428 goto fail_bos_HostCreate;
2431 if ((hostName == NULL) || (*hostName == 0)) {
2432 tst = ADMBOSHOSTNAMENULL;
2433 goto fail_bos_HostCreate;
2436 tst = BOZO_AddCellHost(b_handle->server, hostName);
2442 fail_bos_HostCreate:
2451 * bos_HostDelete - delete a host from the cell.
2455 * IN serverHandle - a previously opened serverHandle.
2457 * IN hostName - the host.
2461 * No locks are obtained or released by this function
2465 * Returns != 0 upon successful completion.
2468 int ADMINAPI bos_HostDelete(
2469 const void *serverHandle,
2470 const char *hostName,
2474 afs_status_t tst = 0;
2475 bos_server_p b_handle = (bos_server_p) serverHandle;
2477 if (!isValidServerHandle(b_handle, &tst)) {
2478 goto fail_bos_HostDelete;
2481 if ((hostName == NULL) || (*hostName == 0)) {
2482 tst = ADMBOSHOSTNAMENULL;
2483 goto fail_bos_HostDelete;
2486 tst = BOZO_DeleteCellHost(b_handle->server, hostName);
2492 fail_bos_HostDelete:
2501 * The iterator functions and data for the host retrieval functions
2504 typedef struct host_get {
2506 struct rx_connection *server;
2507 char host[CACHED_ITEMS][BOS_MAX_NAME_LEN];
2508 } host_get_t, *host_get_p;
2510 static int GetHostRPC(
2514 int *last_item_contains_data,
2518 afs_status_t tst = 0;
2519 host_get_p host = (host_get_p) rpc_specific;
2520 char *ptr = (char *) &host->host[slot];
2522 tst = BOZO_GetCellHost(host->server, host->next++, &ptr);
2526 } else if (tst == BZDOM) {
2530 *last_item_contains_data = 0;
2539 static int GetHostFromCache(
2546 afs_status_t tst = 0;
2547 host_get_p host = (host_get_p) rpc_specific;
2549 strcpy((char *) dest, (char *) &host->host[slot]);
2559 * bos_HostGetBegin - begin iterating over the hosts in a cell
2560 * at a particular bos server.
2564 * IN serverHandle - a previously opened serverHandle.
2566 * OUT iter - an iterator that can be passed to bos_HostGetNext
2567 * to retrieve the process names.
2571 * No locks are obtained or released by this function
2575 * Returns != 0 upon successful completion.
2579 int ADMINAPI bos_HostGetBegin(
2580 const void *serverHandle,
2581 void **iterationIdP,
2585 afs_status_t tst = 0;
2586 bos_server_p b_handle = (bos_server_p) serverHandle;
2587 afs_admin_iterator_p iter = (afs_admin_iterator_p) malloc(sizeof(afs_admin_iterator_t));
2588 host_get_p host = (host_get_p) malloc(sizeof(host_get_t));
2590 if (!isValidServerHandle(b_handle, &tst)) {
2591 goto fail_bos_HostGetBegin;
2594 if (iterationIdP == NULL) {
2595 tst = ADMITERATIONIDPNULL;
2596 goto fail_bos_HostGetBegin;
2599 if ((iter == NULL) || (host == NULL)) {
2601 goto fail_bos_HostGetBegin;
2605 host->server = b_handle->server;
2607 if (IteratorInit(iter, (void *) host, GetHostRPC,
2608 GetHostFromCache, NULL, NULL, &tst)) {
2609 *iterationIdP = (void *) iter;
2613 fail_bos_HostGetBegin:
2631 * bos_HostGetNext - retrieve the next host
2632 * from the bos server.
2636 * IN iterationId - an iterator previously returned by
2639 * OUT hostName - upon successful completion contains the next host
2640 * retrieved from the server.
2644 * No locks are obtained or released by this function
2648 * Returns != 0 upon successful completion.
2652 int ADMINAPI bos_HostGetNext(
2653 const void *iterationId,
2658 afs_status_t tst = 0;
2659 afs_admin_iterator_p iter = (afs_admin_iterator_p) iterationId;
2661 if (iterationId == NULL) {
2662 tst = ADMITERATIONIDPNULL;
2663 goto fail_bos_HostGetNext;
2666 if (hostName == NULL) {
2667 tst = ADMBOSHOSTNAMENULL;
2668 goto fail_bos_HostGetNext;
2671 rc = IteratorNext(iter, (void *) hostName, &tst);
2673 fail_bos_HostGetNext:
2682 * bos_HostGetDone - finish using a host iterator.
2686 * IN iterationId - an iterator previously returned by
2691 * No locks are obtained or released by this function
2695 * Returns != 0 upon successful completion.
2699 int ADMINAPI bos_HostGetDone(
2700 const void *iterationId,
2704 afs_status_t tst = 0;
2705 afs_admin_iterator_p iter = (afs_admin_iterator_p) iterationId;
2707 if (iterationId == NULL) {
2708 tst = ADMITERATIONIDPNULL;
2709 goto fail_bos_HostGetDone;
2712 rc = IteratorDone(iter, &tst);
2714 fail_bos_HostGetDone:
2723 * bos_ExecutableCreate - create a new executable at the bos server.
2727 * IN serverHandle - a previously opened serverHandle.
2729 * IN sourceFile - the executable to install at the bos server.
2731 * IN destFile - the location where the executable will be installed.
2735 * No locks are obtained or released by this function
2739 * Returns != 0 upon successful completion.
2743 int ADMINAPI bos_ExecutableCreate(
2744 const void *serverHandle,
2745 const char *sourceFile,
2746 const char *destFile,
2750 afs_status_t tst = 0;
2751 bos_server_p b_handle = (bos_server_p) serverHandle;
2754 struct rx_call *tcall;
2757 * Validate arguments
2760 if (!isValidServerHandle(b_handle, &tst)) {
2761 goto fail_bos_ExecutableCreate;
2764 if ((sourceFile == NULL) || (*sourceFile == 0)) {
2765 tst = ADMBOSSOURCEFILENULL;
2766 goto fail_bos_ExecutableCreate;
2769 if ((destFile == NULL) || (*destFile == 0)) {
2770 tst = ADMBOSDESTFILENULL;
2771 goto fail_bos_ExecutableCreate;
2775 * Open the file locally and compute its size
2778 fd = open(sourceFile, O_RDONLY);
2781 tst = ADMBOSCANTOPENSOURCEFILE;
2782 goto fail_bos_ExecutableCreate;
2785 if (fstat(fd, &estat)) {
2786 tst = ADMBOSCANTSTATSOURCEFILE;
2787 goto fail_bos_ExecutableCreate;
2791 * Start a split rpc to the bos server.
2794 tcall = rx_NewCall(b_handle->server);
2796 tst = StartBOZO_Install(tcall, destFile, estat.st_size,
2797 (afs_int32) estat.st_mode, estat.st_mtime);
2800 rx_EndCall(tcall, tst);
2801 goto fail_bos_ExecutableCreate;
2805 * Copy the data to the server
2811 len = read(fd, tbuffer, sizeof(tbuffer));
2813 tst = ADMBOSCANTREADSOURCEFILE;
2814 rx_EndCall(tcall, len);
2815 goto fail_bos_ExecutableCreate;
2821 tst = rx_Write(tcall, tbuffer, len);
2823 tst = ADMBOSSENDSOURCEFILE;
2824 rx_EndCall(tcall, tst);
2825 goto fail_bos_ExecutableCreate;
2830 * Terminate the rpc to the server
2833 tst = rx_EndCall(tcall, tst);
2839 fail_bos_ExecutableCreate:
2848 * bos_ExecutableRevert - revert an executable to a previous .BAK version.
2852 * IN serverHandle - a previously opened serverHandle.
2854 * IN execFile - the executable to revert at the bos server.
2858 * No locks are obtained or released by this function
2862 * Returns != 0 upon successful completion.
2866 int ADMINAPI bos_ExecutableRevert(
2867 const void *serverHandle,
2868 const char *execFile,
2872 afs_status_t tst = 0;
2873 bos_server_p b_handle = (bos_server_p) serverHandle;
2875 if (!isValidServerHandle(b_handle, &tst)) {
2876 goto fail_bos_ExecutableRevert;
2879 if ((execFile == NULL) || (*execFile == 0)) {
2880 tst = ADMBOSEXECFILENULL;
2881 goto fail_bos_ExecutableRevert;
2884 tst = BOZO_UnInstall(b_handle->server, execFile);
2890 fail_bos_ExecutableRevert:
2899 * bos_ExecutableTimestampGet - get the last mod times for an executable,
2900 * the .BAK version of the executable, and the .OLD version of the
2901 * executable if they exist.
2905 * IN serverHandle - a previously opened serverHandle.
2907 * IN execFile - the executable to revert at the bos server.
2911 * No locks are obtained or released by this function
2915 * Returns != 0 upon successful completion.
2919 int ADMINAPI bos_ExecutableTimestampGet(
2920 const void *serverHandle,
2921 const char *execFile,
2922 unsigned long *newTime,
2923 unsigned long *oldTime,
2924 unsigned long *bakTime,
2928 afs_status_t tst = 0;
2929 bos_server_p b_handle = (bos_server_p) serverHandle;
2931 if (!isValidServerHandle(b_handle, &tst)) {
2932 goto fail_bos_ExecutableTimestampGet;
2935 if ((execFile == NULL) || (*execFile == 0)) {
2936 tst = ADMBOSEXECFILENULL;
2937 goto fail_bos_ExecutableTimestampGet;
2940 if (newTime == NULL) {
2941 tst = ADMBOSNEWTIMENULL;
2942 goto fail_bos_ExecutableTimestampGet;
2945 if (oldTime == NULL) {
2946 tst = ADMBOSOLDTIMENULL;
2947 goto fail_bos_ExecutableTimestampGet;
2950 if (bakTime == NULL) {
2951 tst = ADMBOSBAKTIMENULL;
2952 goto fail_bos_ExecutableTimestampGet;
2955 tst = BOZO_GetDates(b_handle->server, execFile, newTime, bakTime, oldTime);
2961 fail_bos_ExecutableTimestampGet:
2970 * bos_ExecutablePrune - prune the bak, old, and core files off a server
2975 * IN serverHandle - a previously opened serverHandle.
2977 * IN oldFiles - prune .OLD files.
2979 * IN bakFiles - prune .BAK files.
2981 * IN coreFiles - prune core files.
2985 * No locks are obtained or released by this function
2989 * Returns != 0 upon successful completion.
2993 int ADMINAPI bos_ExecutablePrune(
2994 const void *serverHandle,
2995 bos_Prune_t oldFiles,
2996 bos_Prune_t bakFiles,
2997 bos_Prune_t coreFiles,
3001 afs_status_t tst = 0;
3002 bos_server_p b_handle = (bos_server_p) serverHandle;
3003 afs_int32 flags = 0;
3005 if (!isValidServerHandle(b_handle, &tst)) {
3006 goto fail_bos_ExecutablePrune;
3009 if (oldFiles == BOS_PRUNE) {
3010 flags |= BOZO_PRUNEOLD;
3013 if (bakFiles == BOS_PRUNE) {
3014 flags |= BOZO_PRUNEBAK;
3017 if (coreFiles == BOS_PRUNE) {
3018 flags |= BOZO_PRUNECORE;
3021 tst = BOZO_Prune(b_handle->server, flags);
3027 fail_bos_ExecutablePrune:
3036 * bos_ExecutableRestartTimeSet - set the restart time of the bos server
3041 * IN serverHandle - a previously opened serverHandle.
3043 * IN type - specifies either weekly restart or daily restart time.
3045 * IN time - the time to begin restarts.
3049 * No locks are obtained or released by this function
3053 * Returns != 0 upon successful completion.
3057 int ADMINAPI bos_ExecutableRestartTimeSet(
3058 const void *serverHandle,
3060 bos_RestartTime_t time,
3064 afs_status_t tst = 0;
3065 bos_server_p b_handle = (bos_server_p) serverHandle;
3066 afs_int32 restartType = 0;
3067 struct ktime restartTime;
3069 if (!isValidServerHandle(b_handle, &tst)) {
3070 goto fail_bos_ExecutableRestartTimeSet;
3073 if (type == BOS_RESTART_WEEKLY) {
3079 if ((time.mask & BOS_RESTART_TIME_HOUR) &&
3080 (time.hour < 0) || (time.hour > 23)) {
3081 tst = ADMBOSHOURINVALID;
3082 goto fail_bos_ExecutableRestartTimeSet;
3085 if ((time.mask & BOS_RESTART_TIME_MINUTE) &&
3086 (time.min < 0) || (time.min > 60)) {
3087 tst = ADMBOSMINUTEINVALID;
3088 goto fail_bos_ExecutableRestartTimeSet;
3091 if ((time.mask & BOS_RESTART_TIME_SECOND) &&
3092 (time.sec < 0) || (time.sec > 60)) {
3093 tst = ADMBOSSECONDINVALID;
3094 goto fail_bos_ExecutableRestartTimeSet;
3097 if ((time.mask & BOS_RESTART_TIME_DAY) &&
3098 (time.day < 0) || (time.day > 6)) {
3099 tst = ADMBOSDAYINVALID;
3100 goto fail_bos_ExecutableRestartTimeSet;
3103 restartTime.mask = time.mask;
3104 restartTime.hour = time.hour;
3105 restartTime.min = time.min;
3106 restartTime.sec = time.sec;
3107 restartTime.day = time.day;
3109 tst = BOZO_SetRestartTime(b_handle->server, restartType, restartTime);
3115 fail_bos_ExecutableRestartTimeSet:
3124 * bos_ExecutableRestartTimeGet - get the restart time of the bos server
3129 * IN serverHandle - a previously opened serverHandle.
3131 * IN type - specifies either weekly restart or daily restart time.
3133 * OUT timeP - the time to begin restarts.
3137 * No locks are obtained or released by this function
3141 * Returns != 0 upon successful completion.
3145 int ADMINAPI bos_ExecutableRestartTimeGet(
3146 const void *serverHandle,
3148 bos_RestartTime_p timeP,
3152 afs_status_t tst = 0;
3153 bos_server_p b_handle = (bos_server_p) serverHandle;
3154 afs_int32 restartType = 0;
3155 struct ktime restartTime;
3157 if (!isValidServerHandle(b_handle, &tst)) {
3158 goto fail_bos_ExecutableRestartTimeGet;
3161 if (timeP == NULL) {
3162 tst = ADMBOSTIMEPNULL;
3163 goto fail_bos_ExecutableRestartTimeGet;
3166 if (type == BOS_RESTART_WEEKLY) {
3172 tst = BOZO_GetRestartTime(b_handle->server, restartType, &restartTime);
3175 goto fail_bos_ExecutableRestartTimeGet;
3178 timeP->mask = restartTime.mask;
3179 timeP->hour = restartTime.hour;
3180 timeP->min = restartTime.min;
3181 timeP->sec = restartTime.sec;
3182 timeP->day = restartTime.day;
3185 fail_bos_ExecutableRestartTimeGet:
3194 * bos_LogGet - get a log file from the bos server machine.
3198 * IN serverHandle - a previously opened serverHandle.
3200 * IN log - the log file to retrieve.
3202 * IN/OUT logBufferSizeP - the length of the logData buffer on input,
3203 * and upon successful completion, the length of data stored in the buffer.
3205 * OUT logData - the retrieved data upon successful completion.
3209 * No locks are obtained or released by this function
3213 * Returns != 0 upon successful completion.
3217 int ADMINAPI bos_LogGet(
3218 const void *serverHandle,
3220 unsigned long *logBufferSizeP,
3225 afs_status_t tst = 0;
3226 bos_server_p b_handle = (bos_server_p) serverHandle;
3227 struct rx_call *tcall;
3231 unsigned long bytes_read = 0;
3234 * Validate parameters
3237 if (!isValidServerHandle(b_handle, &tst)) {
3238 goto fail_bos_LogGet;
3241 if ((log == NULL) || (*log == 0)) {
3242 tst = ADMBOSLOGNULL;
3243 goto fail_bos_LogGet;
3246 if (logBufferSizeP == NULL) {
3247 tst = ADMBOSLOGBUFFERSIZEPNULL;
3248 goto fail_bos_LogGet;
3251 if (logData == NULL) {
3252 tst = ADMBOSLOGDATANULL;
3253 goto fail_bos_LogGet;
3257 * Begin to retrieve the data
3260 tcall = rx_NewCall(b_handle->server);
3262 tst = StartBOZO_GetLog(tcall, log);
3265 goto fail_bos_LogGet;
3269 * Read the log file data
3273 error = rx_Read(tcall, &buffer, 1);
3275 tst = ADMBOSLOGFILEERROR;
3276 goto fail_bos_LogGet;
3280 * check for the end of the log
3284 *logBufferSizeP = bytes_read;
3289 * We've successfully read another byte, copy it to logData
3294 if (bytes_read <= *logBufferSizeP) {
3295 *logData++ = buffer;
3307 rx_EndCall(tcall, 0);
3317 * bos_AuthSet - set the authorization level required at the bos server.
3321 * IN serverHandle - a previously opened serverHandle.
3323 * IN auth - specifies the new auth level.
3327 * No locks are obtained or released by this function
3331 * Returns != 0 upon successful completion.
3335 int ADMINAPI bos_AuthSet(
3336 const void *serverHandle,
3341 afs_status_t tst = 0;
3342 bos_server_p b_handle = (bos_server_p) serverHandle;
3343 afs_int32 level = 0;
3345 if (!isValidServerHandle(b_handle, &tst)) {
3346 goto fail_bos_AuthSet;
3349 if (auth == BOS_AUTH_REQUIRED) {
3355 tst = BOZO_SetNoAuthFlag(b_handle->server, level);
3370 * bos_CommandExecute - execute a command at the bos server.
3374 * IN serverHandle - a previously opened serverHandle.
3376 * IN command - the command to execute.
3380 * No locks are obtained or released by this function
3384 * Returns != 0 upon successful completion.
3388 int ADMINAPI bos_CommandExecute(
3389 const void *serverHandle,
3390 const char *command,
3394 afs_status_t tst = 0;
3395 bos_server_p b_handle = (bos_server_p) serverHandle;
3397 if (!isValidServerHandle(b_handle, &tst)) {
3398 goto fail_bos_CommandExecute;
3401 if ((command == NULL) || (*command == 0)) {
3402 tst = ADMBOSCOMMANDNULL;
3403 goto fail_bos_CommandExecute;
3406 tst = BOZO_Exec(b_handle->server, command);
3412 fail_bos_CommandExecute:
3421 * bos_Salvage - perform a remote salvage operation.
3425 * IN cellHandle - a previously opened cellHandle.
3427 * IN serverHandle - a previously opened serverHandle.
3429 * IN partitionName - the partition to salvage. Can be null.
3431 * IN volumeName - the volume to salvage. Can be null, if non-null,
3432 * partitionName cannot be null.
3434 * IN numSalvagers - the number of salvage processes to run in parallel.
3436 * IN tmpDir - directory to place temporary files. Can be null.
3438 * IN logFile - file where salvage log will be written. Can be null.
3440 * IN force - sets salvager -force flag.
3442 * IN salvageDamagedVolumes - sets salvager -oktozap flag.
3444 * IN writeInodes - sets salvager -inodes flag.
3446 * IN writeRootInodes - sets salvager -rootinodes flag.
3448 * IN forceDirectory - sets salvager -salvagedirs flag.
3450 * IN forceBlockRead - sets salvager -blockread flag.
3454 * No locks are obtained or released by this function
3458 * Returns != 0 upon successful completion.
3462 #define INITIAL_LOG_LEN 4096
3464 int ADMINAPI bos_Salvage(
3465 const void *cellHandle,
3466 const void *serverHandle,
3467 const char *partitionName,
3468 const char *volumeName,
3471 const char *logFile,
3473 bos_SalvageDamagedVolumes_t salvageDamagedVolumes,
3474 bos_WriteInodes_t writeInodes,
3475 bos_WriteRootInodes_t writeRootInodes,
3476 bos_ForceDirectory_t forceDirectory,
3477 bos_ForceBlockRead_t forceBlockRead,
3481 afs_status_t tst = 0;
3482 bos_server_p b_handle = (bos_server_p) serverHandle;
3483 afs_cell_handle_p c_handle = (afs_cell_handle_p) cellHandle;
3484 int have_partition = 0;
3485 int have_volume = 0;
3486 unsigned int part = 0;
3487 int try_to_stop_fileserver = 0;
3488 int stopped_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,
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);