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>
29 * Prototypes for functions that don't exist in any header files
32 extern int BOZO_AddCellHost();
33 extern int BOZO_AddKey();
34 extern int BOZO_AddSUser();
35 extern int BOZO_CreateBnode();
36 extern int BOZO_DeleteBnode();
37 extern int BOZO_DeleteCellHost();
38 extern int BOZO_DeleteKey();
39 extern int BOZO_DeleteSUser();
40 extern int BOZO_EnumerateInstance();
41 extern int BOZO_Exec();
42 extern int BOZO_GetCellHost();
43 extern int BOZO_GetCellName();
44 extern int BOZO_GetDates();
45 extern int BOZO_GetInstanceInfo();
46 extern int BOZO_GetInstanceParm();
47 extern int BOZO_GetInstanceParm();
48 extern int BOZO_GetRestartTime();
49 extern int BOZO_GetStatus();
50 extern int BOZO_ListSUsers();
51 extern int BOZO_ListKeys();
52 extern int BOZO_Prune();
53 extern int BOZO_ReBozo();
54 extern int BOZO_Restart();
55 extern int BOZO_RestartAll();
56 extern int BOZO_SetCellName();
57 extern int BOZO_SetNoAuthFlag();
58 extern int BOZO_SetRestartTime();
59 extern int BOZO_SetStatus(struct rx_connection *, const char *, long);
60 extern int BOZO_SetTStatus(struct rx_connection *, const char *, long);
61 extern int BOZO_ShutdownAll();
62 extern int BOZO_StartupAll();
63 extern int BOZO_UnInstall();
64 extern int BOZO_WaitAll();
65 extern int StartBOZO_GetLog();
66 extern int StartBOZO_Install();
68 typedef struct bos_server {
71 struct rx_connection *server;
72 struct rx_connection *server_encrypt;
73 struct rx_connection *server_stats;
75 } bos_server_t, *bos_server_p;
78 * isValidServerHandle - validate a bos_server_p.
82 * IN serverHandle - the handle to validate
86 * No locks are obtained or released by this function
90 * Returns != 0 upon successful completion.
93 int isValidServerHandle (
94 const bos_server_p serverHandle,
100 if (serverHandle == NULL) {
101 tst = ADMBOSSERVERHANDLENULL;
102 goto fail_IsValidServerHandle;
105 if ((serverHandle->begin_magic != BEGIN_MAGIC) ||
106 (serverHandle->end_magic != END_MAGIC)) {
107 tst = ADMBOSSERVERHANDLEBADMAGIC;
108 goto fail_IsValidServerHandle;
111 if (serverHandle->is_valid == 0) {
112 tst = ADMBOSSERVERHANDLEINVALID;
113 goto fail_IsValidServerHandle;
116 if (serverHandle->server == NULL) {
117 tst = ADMBOSSERVERHANDLENOSERVER;
118 goto fail_IsValidServerHandle;
121 if (serverHandle->server_encrypt == NULL) {
122 tst = ADMBOSSERVERHANDLENOSERVER;
123 goto fail_IsValidServerHandle;
127 fail_IsValidServerHandle:
135 * IsValidCellHandle - verify that a cell handle can be used to make bos
140 * IN cellHandle - the cellHandle to be validated.
144 * No locks are obtained or released by this function
148 * Returns != 0 upon successful completion.
151 static int IsValidCellHandle(
152 afs_cell_handle_p cellHandle,
156 afs_status_t tst = 0;
158 if (!CellHandleIsValid((void *) cellHandle, &tst)) {
159 goto fail_IsValidCellHandle;
162 if (cellHandle->tokens == NULL) {
163 tst = ADMBOSCELLHANDLENOTOKENS;
164 goto fail_IsValidCellHandle;
168 fail_IsValidCellHandle:
177 * bos_ServerOpen - open a bos server for work.
181 * IN cellHandle - a previously opened cellHandle.
183 * IN serverName - the name of the machine that houses the bosserver of
186 * OUT serverHandleP - upon successful completion, this void pointer
187 * will point to a valid server handle for use in future operations.
191 * No locks are obtained or released by this function
195 * Returns != 0 upon successful completion.
198 int ADMINAPI bos_ServerOpen(
199 const void *cellHandle,
200 const char *serverName,
201 void **serverHandleP,
205 afs_status_t tst = 0;
206 afs_cell_handle_p c_handle = (afs_cell_handle_p) cellHandle;
207 bos_server_p bos_server = (bos_server_p) malloc(sizeof(bos_server_t));
211 * Validate parameters
214 if (!IsValidCellHandle(c_handle, &tst)) {
215 goto fail_bos_ServerOpen;
218 if ((serverName == NULL) || (*serverName == 0)) {
219 tst = ADMBOSSERVERNAMENULL;
220 goto fail_bos_ServerOpen;
223 if (serverHandleP == NULL) {
224 tst = ADMBOSSERVERHANDLEPNULL;
225 goto fail_bos_ServerOpen;
228 if (util_AdminServerAddressGetFromName(serverName, &serverAddress, &tst) == 0) {
229 goto fail_bos_ServerOpen;
232 if (bos_server == NULL) {
234 goto fail_bos_ServerOpen;
237 bos_server->server = rx_GetCachedConnection(htonl(serverAddress),
238 htons(AFSCONF_NANNYPORT), 1,
239 c_handle->tokens->afs_sc[c_handle->tokens->sc_index], c_handle->tokens->sc_index);
241 bos_server->server_encrypt = rx_GetCachedConnection(htonl(serverAddress),
242 htons(AFSCONF_NANNYPORT), 1,
243 c_handle->tokens->afs_encrypt_sc[c_handle->tokens->sc_index], c_handle->tokens->sc_index);
245 bos_server->server_stats = rx_GetCachedConnection(htonl(serverAddress),
246 htons(AFSCONF_NANNYPORT),
248 c_handle->tokens->afs_sc[c_handle->tokens->sc_index], c_handle->tokens->sc_index);
250 if ((bos_server->server == NULL) || (bos_server->server_encrypt == NULL)) {
251 tst = ADMBOSSERVERNOCONNECTION;
252 goto fail_bos_ServerOpen;
255 bos_server->begin_magic = BEGIN_MAGIC;
256 bos_server->is_valid = 1;
257 bos_server->end_magic = END_MAGIC;
259 *serverHandleP = (void *) bos_server;
264 if ((rc == 0) && (bos_server != NULL)) {
265 if (bos_server->server) {
266 rx_ReleaseCachedConnection(bos_server->server);
268 if (bos_server->server_encrypt) {
269 rx_ReleaseCachedConnection(bos_server->server_encrypt);
281 * bos_ServerClose - close a bos server handle
285 * IN serverHandle - a bos server handle previously returned by bos_ServerOpen
289 * No locks are obtained or released by this function
293 * Returns != 0 upon successful completion.
296 int ADMINAPI bos_ServerClose(
297 const void *serverHandle,
301 afs_status_t tst = 0;
302 bos_server_p b_handle = (bos_server_p) serverHandle;
304 if (isValidServerHandle(b_handle, &tst)) {
305 rx_ReleaseCachedConnection(b_handle->server);
306 b_handle->is_valid = 0;
318 * bos_ProcessCreate - create a new process to run at a bos server.
322 * IN serverHandle - a previously opened serverHandle.
324 * IN processName - the name of the process to create.
326 * IN processType - the type of process to create.
328 * IN process - the path to the process binary at the bos server.
330 * IN cronTime - the time specification for cron processes.
332 * IN notifier - the path to the notifier binary at the bos server.
336 * No locks are obtained or released by this function
340 * Returns != 0 upon successful completion.
344 * CAUTION - this list must match bos_ProcessType_t definition
347 static char *processTypes[] = {"simple", "fs", "cron", 0};
349 int ADMINAPI bos_ProcessCreate(
350 const void *serverHandle,
351 const char *processName,
352 bos_ProcessType_t processType,
354 const char *cronTime,
355 const char *notifier,
359 afs_status_t tst = 0;
360 bos_server_p b_handle = (bos_server_p) serverHandle;
362 if (!isValidServerHandle(b_handle, &tst)) {
363 goto fail_bos_ProcessCreate;
366 if (processType == BOS_PROCESS_FS) {
367 tst = ADMBOSPROCESSCREATEBADTYPE;
368 goto fail_bos_ProcessCreate;
371 if ((processName == NULL) || (*processName == 0)) {
372 tst = ADMBOSPROCESSNAMENULL;
373 goto fail_bos_ProcessCreate;
376 if ((process == NULL) || (*process == 0)) {
377 tst = ADMBOSPROCESSNULL;
378 goto fail_bos_ProcessCreate;
381 if ((processType == BOS_PROCESS_CRON) && (cronTime == NULL)) {
382 tst = ADMBOSCRONTIMENULL;
383 goto fail_bos_ProcessCreate;
386 if ((processType == BOS_PROCESS_SIMPLE) && (cronTime != NULL)) {
387 tst = ADMBOSCRONTIMENOTNULL;
388 goto fail_bos_ProcessCreate;
391 tst = BOZO_CreateBnode(b_handle->server, processTypes[processType],
392 processName, process,
393 (cronTime) ? cronTime : "", "", "", "",
394 (notifier) ? notifier : NONOTIFIER);
399 fail_bos_ProcessCreate:
408 * bos_FSProcessCreate - create the fs group of processes at the boserver.
412 * IN serverHandle - a previously opened serverHandle.
414 * IN processName - the name of the process to create.
416 * IN fileserverPath - the path to the fileserver binary at the bos server.
418 * IN volserverPath - the path to the volserver binary at the bos server.
420 * IN salvagerPath - the path to the salvager binary at the bos server.
422 * IN notifier - the path to the notifier binary at the bos server.
426 * No locks are obtained or released by this function
430 * Returns != 0 upon successful completion.
433 int ADMINAPI bos_FSProcessCreate(
434 const void *serverHandle,
435 const char *processName,
436 const char *fileserverPath,
437 const char *volserverPath,
438 const char *salvagerPath,
439 const char *notifier,
443 afs_status_t tst = 0;
444 bos_server_p b_handle = (bos_server_p) serverHandle;
446 if (!isValidServerHandle(b_handle, &tst)) {
447 goto fail_bos_ProcessCreate;
450 if ((processName == NULL) || (*processName == 0)) {
451 tst = ADMBOSPROCESSNAMENULL;
452 goto fail_bos_ProcessCreate;
455 if ((fileserverPath == NULL) || (*fileserverPath == 0)) {
456 tst = ADMBOSFILESERVERPATHNULL;
457 goto fail_bos_ProcessCreate;
460 if ((volserverPath == NULL) || (*volserverPath == 0)) {
461 tst = ADMBOSVOLSERVERPATHNULL;
462 goto fail_bos_ProcessCreate;
465 if ((salvagerPath == NULL) || (*salvagerPath == 0)) {
466 tst = ADMBOSSALVAGERPATHNULL;
467 goto fail_bos_ProcessCreate;
470 tst = BOZO_CreateBnode(b_handle->server,
471 processTypes[BOS_PROCESS_FS],
478 (notifier) ? notifier : NONOTIFIER);
483 fail_bos_ProcessCreate:
492 * bos_ProcessDelete - delete an existing process at a bos server.
496 * IN serverHandle - a previously opened serverHandle.
498 * IN processName - the name of the process to delete.
502 * No locks are obtained or released by this function
506 * Returns != 0 upon successful completion.
509 int ADMINAPI bos_ProcessDelete(
510 const void *serverHandle,
511 const char *processName,
515 afs_status_t tst = 0;
516 bos_server_p b_handle = (bos_server_p) serverHandle;
518 if (!isValidServerHandle(b_handle, &tst)) {
519 goto fail_bos_ProcessDelete;
522 if ((processName == NULL) || (*processName == 0)) {
523 tst = ADMBOSPROCESSNAMENULL;
524 goto fail_bos_ProcessDelete;
527 tst = BOZO_DeleteBnode(b_handle->server, processName);
533 fail_bos_ProcessDelete:
542 * bos_ProcessExecutionStateGet - get the current execution state of a
547 * IN serverHandle - a previously opened serverHandle.
549 * IN processName - the name of the process to retrieve.
551 * OUT processStatusP - upon successful completion the process execution state
553 * OUT auxiliaryProcessStatus - set to point to aux proc status if available.
554 * Pass a pointer to an char array at least BOS_MAX_NAME_LEN long.
558 * No locks are obtained or released by this function
562 * Returns != 0 upon successful completion.
565 int ADMINAPI bos_ProcessExecutionStateGet(
566 const void *serverHandle,
567 const char *processName,
568 bos_ProcessExecutionState_p processStatusP,
569 char *auxiliaryProcessStatus,
573 afs_status_t tst = 0;
574 bos_server_p b_handle = (bos_server_p) serverHandle;
577 if (!isValidServerHandle(b_handle, &tst)) {
578 goto fail_bos_ProcessExecutionStateGet;
581 if ((processName == NULL) || (*processName == 0)) {
582 tst = ADMBOSPROCESSNAMENULL;
583 goto fail_bos_ProcessExecutionStateGet;
586 if (processStatusP == NULL) {
587 tst = ADMBOSPROCESSSTATUSPNULL;
588 goto fail_bos_ProcessExecutionStateGet;
591 if (auxiliaryProcessStatus == NULL) {
592 tst = ADMBOSAUXILIARYPROCESSSTATUSNULL;
593 goto fail_bos_ProcessExecutionStateGet;
596 tst = BOZO_GetStatus(b_handle->server, processName, &state, &auxiliaryProcessStatus);
599 goto fail_bos_ProcessExecutionStateGet;
602 *processStatusP = (bos_ProcessExecutionState_t) state;
605 fail_bos_ProcessExecutionStateGet:
614 * SetExecutionState - set the execution state of a process
618 * IN serverHandle - a previously opened serverHandle.
620 * IN processName - the name of the process to modify.
622 * IN processStatus - the new process state.
624 * IN func - the function to call to set the status.
628 * No locks are obtained or released by this function
632 * Returns != 0 upon successful completion.
635 static int SetExecutionState(
636 const void *serverHandle,
637 const char *processName,
638 const bos_ProcessExecutionState_t processStatus,
639 int (*func)(struct rx_connection *, const char *, afs_int32),
643 afs_status_t tst = 0;
644 bos_server_p b_handle = (bos_server_p) serverHandle;
647 if (!isValidServerHandle(b_handle, &tst)) {
648 goto fail_SetExecutionState;
651 if ((processName == NULL) || (*processName == 0)) {
652 tst = ADMBOSPROCESSNAMENULL;
653 goto fail_SetExecutionState;
656 if ((processStatus != BOS_PROCESS_STOPPED) &&
657 (processStatus != BOS_PROCESS_RUNNING)) {
658 tst = ADMBOSPROCESSSTATUSSET;
659 goto fail_SetExecutionState;
662 state = (afs_int32) processStatus;
664 tst = func(b_handle->server, processName, state);
670 fail_SetExecutionState:
679 * bos_ProcessExecutionStateSet - set the execution state of a process
683 * IN serverHandle - a previously opened serverHandle.
685 * IN processName - the name of the process to modify.
687 * IN processStatus - the new process state.
691 * No locks are obtained or released by this function
695 * Returns != 0 upon successful completion.
698 int ADMINAPI bos_ProcessExecutionStateSet(
699 const void *serverHandle,
700 const char *processName,
701 bos_ProcessExecutionState_t processStatus,
704 return SetExecutionState(serverHandle, processName, processStatus,
709 * bos_ProcessExecutionStateSetTemporary - set the execution state of a process
714 * IN serverHandle - a previously opened serverHandle.
716 * IN processName - the name of the process to modify.
718 * IN processStatus - the new process state.
722 * No locks are obtained or released by this function
726 * Returns != 0 upon successful completion.
729 int ADMINAPI bos_ProcessExecutionStateSetTemporary(
730 const void *serverHandle,
731 const char *processName,
732 bos_ProcessExecutionState_t processStatus,
735 return SetExecutionState(serverHandle, processName, processStatus,
736 BOZO_SetTStatus, st);
740 * The iterator functions and data for the process name retrieval functions
743 typedef struct process_name_get {
745 struct rx_connection *server;
746 char process[CACHED_ITEMS][BOS_MAX_NAME_LEN];
747 } process_name_get_t, *process_name_get_p;
749 static int GetProcessNameRPC(
753 int *last_item_contains_data,
757 afs_status_t tst = 0;
758 process_name_get_p proc = (process_name_get_p) rpc_specific;
759 char *ptr = (char *) &proc->process[slot];
761 tst = BOZO_EnumerateInstance(proc->server, proc->next++, &ptr);
765 } else if (tst == BZDOM) {
769 *last_item_contains_data = 0;
778 static int GetProcessNameFromCache(
785 afs_status_t tst = 0;
786 process_name_get_p proc = (process_name_get_p) rpc_specific;
788 strcpy((char *) dest, (char *) &proc->process[slot]);
798 * bos_ProcessNameGetBegin - begin iterating over the list of processes
799 * at a particular bos server.
803 * IN serverHandle - a previously opened serverHandle.
805 * OUT iter - an iterator that can be passed to bos_ProcessNameGetNext
806 * to retrieve the process names.
810 * No locks are obtained or released by this function
814 * Returns != 0 upon successful completion.
818 int ADMINAPI bos_ProcessNameGetBegin(
819 const void *serverHandle,
824 afs_status_t tst = 0;
825 bos_server_p b_handle = (bos_server_p) serverHandle;
826 afs_admin_iterator_p iter = (afs_admin_iterator_p) malloc(sizeof(afs_admin_iterator_t));
827 process_name_get_p proc = (process_name_get_p) malloc(sizeof(process_name_get_t));
829 if (!isValidServerHandle(b_handle, &tst)) {
830 goto fail_bos_ProcessNameGetBegin;
833 if (iterationIdP == NULL) {
834 tst = ADMITERATIONIDPNULL;
835 goto fail_bos_ProcessNameGetBegin;
838 if ((iter == NULL) || (proc == NULL)) {
840 goto fail_bos_ProcessNameGetBegin;
844 proc->server = b_handle->server;
846 if (IteratorInit(iter, (void *) proc, GetProcessNameRPC, GetProcessNameFromCache, NULL, NULL, &tst)) {
847 *iterationIdP = (void *) iter;
849 goto fail_bos_ProcessNameGetBegin;
853 fail_bos_ProcessNameGetBegin:
871 * bos_ProcessNameGetNext - retrieve the next process name from the bos server.
875 * IN iterationId - an iterator previously returned by bos_ProcessNameGetBegin
877 * OUT processName - upon successful completion contains the next process name
878 * retrieved from the server.
882 * No locks are obtained or released by this function
886 * Returns != 0 upon successful completion.
890 int ADMINAPI bos_ProcessNameGetNext(
891 const void *iterationId,
896 afs_status_t tst = 0;
897 afs_admin_iterator_p iter = (afs_admin_iterator_p) iterationId;
899 if (processName == NULL) {
900 tst = ADMBOSPROCESSNAMENULL;
901 goto fail_bos_ProcessNameGetNext;
904 if (iterationId == NULL) {
905 tst = ADMITERATIONIDPNULL;
906 goto fail_bos_ProcessNameGetNext;
909 rc = IteratorNext(iter, (void *) processName, &tst);
911 fail_bos_ProcessNameGetNext:
920 * bos_ProcessNameGetDone - finish using a process name iterator.
924 * IN iterationId - an iterator previously returned by bos_ProcessNameGetBegin
928 * No locks are obtained or released by this function
932 * Returns != 0 upon successful completion.
936 int ADMINAPI bos_ProcessNameGetDone(
937 const void *iterationId,
941 afs_status_t tst = 0;
942 afs_admin_iterator_p iter = (afs_admin_iterator_p) iterationId;
944 if (iterationId == NULL) {
945 tst = ADMITERATIONIDPNULL;
946 goto fail_bos_ProcessNameGetDone;
949 rc = IteratorDone(iter, &tst);
951 fail_bos_ProcessNameGetDone:
960 * bos_ProcessInfoGet - get information about a single process
964 * IN serverHandle - a previously opened serverHandle.
966 * IN processName - the process of interest.
968 * OUT processTypeP - upon successful completion contains the process type
970 * OUT processInfoP - upon successful completion contains the process info
974 * No locks are obtained or released by this function
978 * Returns != 0 upon successful completion.
982 int ADMINAPI bos_ProcessInfoGet(
983 const void *serverHandle,
984 const char *processName,
985 bos_ProcessType_p processTypeP,
986 bos_ProcessInfo_p processInfoP,
990 afs_status_t tst = 0;
991 bos_server_p b_handle = (bos_server_p) serverHandle;
992 char type[BOS_MAX_NAME_LEN];
994 struct bozo_status status;
997 if (!isValidServerHandle(b_handle, &tst)) {
998 goto fail_bos_ProcessInfoGet;
1001 if ((processName == NULL) || (*processName == 0)) {
1002 tst = ADMBOSPROCESSNAMENULL;
1003 goto fail_bos_ProcessInfoGet;
1006 if (processTypeP == NULL) {
1007 tst = ADMBOSPROCESSTYPEPNULL;
1008 goto fail_bos_ProcessInfoGet;
1011 if (processInfoP == NULL) {
1012 tst = ADMBOSPROCESSINFOPNULL;
1013 goto fail_bos_ProcessInfoGet;
1016 tst = BOZO_GetInstanceInfo(b_handle->server, processName, &ptr, &status);
1019 goto fail_bos_ProcessInfoGet;
1023 for(i=0;(processTypes[i] != NULL); i++) {
1024 if (!strcmp(processTypes[i], type)) {
1025 *processTypeP = (bos_ProcessType_t) i;
1030 if (processTypes[i] == NULL) {
1031 tst = ADMBOSINVALIDPROCESSTYPE;
1032 goto fail_bos_ProcessInfoGet;
1035 processInfoP->processGoal = (bos_ProcessExecutionState_t) status.goal;
1036 processInfoP->processStartTime = status.procStartTime;
1037 processInfoP->numberProcessStarts = status.procStarts;
1038 processInfoP->processExitTime = status.lastAnyExit;
1039 processInfoP->processExitErrorTime = status.lastErrorExit;
1040 processInfoP->processErrorCode = status.errorCode;
1041 processInfoP->processErrorSignal = status.errorSignal;
1042 processInfoP->state = BOS_PROCESS_OK;
1044 if (status.flags & BOZO_ERRORSTOP) {
1045 processInfoP->state |= BOS_PROCESS_TOO_MANY_ERRORS;
1047 if (status.flags & BOZO_HASCORE) {
1048 processInfoP->state |= BOS_PROCESS_CORE_DUMPED;
1050 if (status.flags & BOZO_BADDIRACCESS) {
1051 processInfoP->state |= BOS_PROCESS_BAD_FILE_ACCESS;
1055 fail_bos_ProcessInfoGet:
1064 * The iterator functions and data for the parameter retrieval functions
1067 typedef struct param_get {
1069 struct rx_connection *server;
1070 char processName[BOS_MAX_NAME_LEN];
1071 char param[CACHED_ITEMS][BOS_MAX_NAME_LEN];
1072 } param_get_t, *param_get_p;
1074 static int GetParameterRPC(
1078 int *last_item_contains_data,
1082 afs_status_t tst = 0;
1083 param_get_p param = (param_get_p) rpc_specific;
1084 char *ptr = (char *) ¶m->param[slot];
1086 tst = BOZO_GetInstanceParm(param->server, param->processName,
1087 param->next++, &ptr);
1091 } else if (tst == BZDOM) {
1095 *last_item_contains_data = 0;
1104 static int GetParameterFromCache(
1111 afs_status_t tst = 0;
1112 param_get_p param = (param_get_p) rpc_specific;
1114 strcpy((char *) dest, (char *) ¶m->param[slot]);
1124 * bos_ProcessParameterGetBegin - begin iterating over the parameters
1125 * of a particular process.
1129 * IN serverHandle - a previously opened serverHandle.
1131 * IN processName - the process whose parameters are returned.
1133 * OUT iter - an iterator that can be passed to bos_ProcessParameterGetNext
1134 * to retrieve the parameters.
1138 * No locks are obtained or released by this function
1142 * Returns != 0 upon successful completion.
1146 int ADMINAPI bos_ProcessParameterGetBegin(
1147 const void *serverHandle,
1148 const char *processName,
1149 void **iterationIdP,
1153 afs_status_t tst = 0;
1154 bos_server_p b_handle = (bos_server_p) serverHandle;
1155 afs_admin_iterator_p iter = (afs_admin_iterator_p) malloc(sizeof(afs_admin_iterator_t));
1156 param_get_p param = (param_get_p) malloc(sizeof(param_get_t));
1158 if (!isValidServerHandle(b_handle, &tst)) {
1159 goto fail_bos_ProcessParameterGetBegin;
1162 if ((processName == NULL) || (*processName == 0)) {
1163 tst = ADMBOSPROCESSNAMENULL;
1164 goto fail_bos_ProcessParameterGetBegin;
1167 if (iterationIdP == NULL) {
1168 tst = ADMITERATIONIDPNULL;
1169 goto fail_bos_ProcessParameterGetBegin;
1172 if ((iter == NULL) || (param == NULL)) {
1174 goto fail_bos_ProcessParameterGetBegin;
1178 param->server = b_handle->server;
1179 strcpy(param->processName, processName);
1181 if (IteratorInit(iter, (void *) param, GetParameterRPC,
1182 GetParameterFromCache, NULL, NULL, &tst)) {
1183 *iterationIdP = (void *) iter;
1185 goto fail_bos_ProcessParameterGetBegin;
1189 fail_bos_ProcessParameterGetBegin:
1195 if (param != NULL) {
1207 * bos_ProcessParameterGetNext - retrieve the next parameter
1208 * from the bos server.
1212 * IN iterationId - an iterator previously returned by
1213 * bos_ProcessParameterGetBegin
1215 * OUT parameter - upon successful completion contains the next parameter
1216 * retrieved from the server.
1220 * No locks are obtained or released by this function
1224 * Returns != 0 upon successful completion.
1228 int ADMINAPI bos_ProcessParameterGetNext(
1229 const void *iterationId,
1234 afs_status_t tst = 0;
1235 afs_admin_iterator_p iter = (afs_admin_iterator_p) iterationId;
1237 if (iterationId == NULL) {
1238 tst = ADMITERATIONIDPNULL;
1239 goto fail_bos_ProcessParameterGetNext;
1242 if (parameter == NULL) {
1243 tst = ADMBOSPARAMETERNULL;
1244 goto fail_bos_ProcessParameterGetNext;
1247 rc = IteratorNext(iter, (void *) parameter, &tst);
1249 fail_bos_ProcessParameterGetNext:
1258 * bos_ProcessParameterGetDone - finish using a process name iterator.
1262 * IN iterationId - an iterator previously returned by
1263 * bos_ProcessParameterGetBegin
1267 * No locks are obtained or released by this function
1271 * Returns != 0 upon successful completion.
1275 int ADMINAPI bos_ProcessParameterGetDone(
1276 const void *iterationId,
1280 afs_status_t tst = 0;
1281 afs_admin_iterator_p iter = (afs_admin_iterator_p) iterationId;
1283 if (iterationId == NULL) {
1284 tst = ADMITERATIONIDPNULL;
1285 goto fail_bos_ProcessParameterGetDone;
1288 rc = IteratorDone(iter, &tst);
1290 fail_bos_ProcessParameterGetDone:
1299 * bos_ProcessNotifierGet - retrieve the notifier associated with a
1304 * IN serverHandle - a previously opened serverHandle.
1306 * IN processName - the process whose notifier we are retrieving.
1308 * OUT notifier - upon successful completion contains the notifier.
1312 * No locks are obtained or released by this function
1316 * Returns != 0 upon successful completion.
1320 int ADMINAPI bos_ProcessNotifierGet(
1321 const void *serverHandle,
1322 const char *processName,
1327 afs_status_t tst = 0;
1328 bos_server_p b_handle = (bos_server_p) serverHandle;
1330 if (!isValidServerHandle(b_handle, &tst)) {
1331 goto fail_bos_ProcessNotifierGet;
1334 if ((processName == NULL) || (*processName == 0)) {
1335 tst = ADMBOSPROCESSNAMENULL;
1336 goto fail_bos_ProcessNotifierGet;
1339 if (notifier == NULL) {
1340 tst = ADMBOSNOTIFIERNULL;
1341 goto fail_bos_ProcessNotifierGet;
1344 tst = BOZO_GetInstanceParm(b_handle->server, processName, 999, ¬ifier);
1350 fail_bos_ProcessNotifierGet:
1359 * bos_ProcessRestart - restart a particular process.
1363 * IN serverHandle - a previously opened serverHandle.
1365 * IN processName - the process to restart
1369 * No locks are obtained or released by this function
1373 * Returns != 0 upon successful completion.
1377 int ADMINAPI bos_ProcessRestart(
1378 const void *serverHandle,
1379 const char *processName,
1383 afs_status_t tst = 0;
1384 bos_server_p b_handle = (bos_server_p) serverHandle;
1386 if (!isValidServerHandle(b_handle, &tst)) {
1387 goto fail_bos_ProcessRestart;
1390 if ((processName == NULL) || (*processName == 0)) {
1391 tst = ADMBOSPROCESSNAMENULL;
1392 goto fail_bos_ProcessRestart;
1395 tst = BOZO_Restart(b_handle->server, processName);
1401 fail_bos_ProcessRestart:
1410 * bos_ProcessAllStop - stop all running processes at a server.
1414 * IN serverHandle - a previously opened serverHandle.
1418 * No locks are obtained or released by this function
1422 * Returns != 0 upon successful completion.
1426 int ADMINAPI bos_ProcessAllStop(
1427 const void *serverHandle,
1431 afs_status_t tst = 0;
1432 bos_server_p b_handle = (bos_server_p) serverHandle;
1434 if (!isValidServerHandle(b_handle, &tst)) {
1435 goto fail_bos_ProcessAllStop;
1438 tst = BOZO_ShutdownAll(b_handle->server);
1444 fail_bos_ProcessAllStop:
1453 * bos_ProcessAllStart - start all processes that should be running at a
1458 * IN serverHandle - a previously opened serverHandle.
1462 * No locks are obtained or released by this function
1466 * Returns != 0 upon successful completion.
1470 int ADMINAPI bos_ProcessAllStart(
1471 const void *serverHandle,
1475 afs_status_t tst = 0;
1476 bos_server_p b_handle = (bos_server_p) serverHandle;
1478 if (!isValidServerHandle(b_handle, &tst)) {
1479 goto fail_bos_ProcessAllStart;
1482 tst = BOZO_StartupAll(b_handle->server);
1488 fail_bos_ProcessAllStart:
1497 * bos_ProcessAllWaitStop - stop all processes, and block until they have
1502 * IN serverHandle - a previously opened serverHandle.
1506 * No locks are obtained or released by this function
1510 * Returns != 0 upon successful completion.
1514 int ADMINAPI bos_ProcessAllWaitStop(
1515 const void *serverHandle,
1519 afs_status_t tst = 0;
1520 bos_server_p b_handle = (bos_server_p) serverHandle;
1522 if (!isValidServerHandle(b_handle, &tst)) {
1523 goto fail_bos_ProcessAllWaitStop;
1526 if (!bos_ProcessAllStop(serverHandle, &tst)) {
1527 goto fail_bos_ProcessAllWaitStop;
1530 tst = BOZO_WaitAll(b_handle->server);
1536 fail_bos_ProcessAllWaitStop:
1545 * bos_ProcessAllWaitTransition - block until all processes at the bosserver
1546 * have reached their desired state.
1550 * IN serverHandle - a previously opened serverHandle.
1554 * No locks are obtained or released by this function
1558 * Returns != 0 upon successful completion.
1562 int ADMINAPI bos_ProcessAllWaitTransition(
1563 const void *serverHandle,
1567 afs_status_t tst = 0;
1568 bos_server_p b_handle = (bos_server_p) serverHandle;
1570 if (!isValidServerHandle(b_handle, &tst)) {
1571 goto fail_bos_ProcessAllWaitTransition;
1574 tst = BOZO_WaitAll(b_handle->server);
1580 fail_bos_ProcessAllWaitTransition:
1589 * bos_ProcessAllStopAndRestart - stop all the running processes, restart
1590 * them, and optionally restart the bosserver itself.
1595 * IN serverHandle - a previously opened serverHandle.
1597 * IN restartBosServer - flag to indicate whether to restart bosserver.
1601 * No locks are obtained or released by this function
1605 * Returns != 0 upon successful completion.
1609 int ADMINAPI bos_ProcessAllStopAndRestart(
1610 const void *serverHandle,
1611 bos_RestartBosServer_t restartBosServer,
1615 afs_status_t tst = 0;
1616 bos_server_p b_handle = (bos_server_p) serverHandle;
1618 if (!isValidServerHandle(b_handle, &tst)) {
1619 goto fail_bos_ProcessAllStopAndRestart;
1622 if (restartBosServer == BOS_RESTART_BOS_SERVER) {
1623 tst = BOZO_ReBozo(b_handle->server);
1625 goto fail_bos_ProcessAllStopAndRestart;
1629 tst = BOZO_RestartAll(b_handle->server);
1635 fail_bos_ProcessAllStopAndRestart:
1644 * bos_AdminCreate - create a new admin.
1648 * IN serverHandle - a previously opened serverHandle.
1650 * IN adminName - the new admin name.
1654 * No locks are obtained or released by this function
1658 * Returns != 0 upon successful completion.
1662 int ADMINAPI bos_AdminCreate(
1663 const void *serverHandle,
1664 const char *adminName,
1668 afs_status_t tst = 0;
1669 bos_server_p b_handle = (bos_server_p) serverHandle;
1671 if (!isValidServerHandle(b_handle, &tst)) {
1672 goto fail_bos_AdminCreate;
1675 if ((adminName == NULL) || (*adminName == 0)) {
1676 tst = ADMBOSADMINNAMENULL;
1677 goto fail_bos_AdminCreate;
1680 tst = BOZO_AddSUser(b_handle->server, adminName);
1686 fail_bos_AdminCreate:
1695 * bos_AdminDelete - delete a new admin.
1699 * IN serverHandle - a previously opened serverHandle.
1701 * IN adminName - the admin name.
1705 * No locks are obtained or released by this function
1709 * Returns != 0 upon successful completion.
1713 int ADMINAPI bos_AdminDelete(
1714 const void *serverHandle,
1715 const char *adminName,
1719 afs_status_t tst = 0;
1720 bos_server_p b_handle = (bos_server_p) serverHandle;
1722 if (!isValidServerHandle(b_handle, &tst)) {
1723 goto fail_bos_AdminDelete;
1726 if ((adminName == NULL) || (*adminName == 0)) {
1727 tst = ADMBOSADMINNAMENULL;
1728 goto fail_bos_AdminDelete;
1731 tst = BOZO_DeleteSUser(b_handle->server, adminName);
1737 fail_bos_AdminDelete:
1746 * The iterator functions and data for the admin retrieval functions
1749 typedef struct admin_get {
1751 struct rx_connection *server;
1752 char admin[CACHED_ITEMS][BOS_MAX_NAME_LEN];
1753 } admin_get_t, *admin_get_p;
1755 static int GetAdminRPC(
1759 int *last_item_contains_data,
1763 afs_status_t tst = 0;
1764 admin_get_p admin = (admin_get_p) rpc_specific;
1765 char *ptr = (char *) &admin->admin[slot];
1767 tst = BOZO_ListSUsers(admin->server, admin->next++, &ptr);
1770 * There's no way to tell the difference between an rpc failure
1771 * and the end of the list, so we assume that any error means the
1778 *last_item_contains_data = 0;
1788 static int GetAdminFromCache(
1795 afs_status_t tst = 0;
1796 admin_get_p admin = (admin_get_p) rpc_specific;
1798 strcpy((char *) dest, (char *) &admin->admin[slot]);
1808 * bos_AdminGetBegin - begin iterating over the administrators.
1812 * IN serverHandle - a previously opened serverHandle.
1814 * OUT iter - an iterator that can be passed to bos_AdminGetBegin
1815 * to retrieve the administrators.
1819 * No locks are obtained or released by this function
1823 * Returns != 0 upon successful completion.
1827 int ADMINAPI bos_AdminGetBegin(
1828 const void *serverHandle,
1829 void **iterationIdP,
1833 afs_status_t tst = 0;
1834 bos_server_p b_handle = (bos_server_p) serverHandle;
1835 afs_admin_iterator_p iter = (afs_admin_iterator_p) malloc(sizeof(afs_admin_iterator_t));
1836 admin_get_p admin = (admin_get_p) malloc(sizeof(admin_get_t));
1838 if (!isValidServerHandle(b_handle, &tst)) {
1839 goto fail_bos_AdminGetBegin;
1842 if (iterationIdP == NULL) {
1843 tst = ADMITERATIONIDPNULL;
1844 goto fail_bos_AdminGetBegin;
1847 if ((iter == NULL) || (admin == NULL)) {
1849 goto fail_bos_AdminGetBegin;
1853 admin->server = b_handle->server;
1855 if (IteratorInit(iter, (void *) admin, GetAdminRPC,
1856 GetAdminFromCache, NULL, NULL, &tst)) {
1857 *iterationIdP = (void *) iter;
1861 fail_bos_AdminGetBegin:
1867 if (admin != NULL) {
1879 * bos_AdminGetNext - retrieve the next administrator
1880 * from the bos server.
1884 * IN iterationId - an iterator previously returned by
1887 * OUT adminName - upon successful completion contains the next administrator
1888 * retrieved from the server.
1892 * No locks are obtained or released by this function
1896 * Returns != 0 upon successful completion.
1900 int ADMINAPI bos_AdminGetNext(
1901 const void *iterationId,
1906 afs_status_t tst = 0;
1907 afs_admin_iterator_p iter = (afs_admin_iterator_p) iterationId;
1909 if (iterationId == NULL) {
1910 tst = ADMITERATIONIDPNULL;
1911 goto fail_bos_AdminGetNext;
1914 if (adminName == NULL) {
1915 tst = ADMBOSADMINNAMENULL;
1916 goto fail_bos_AdminGetNext;
1919 rc = IteratorNext(iter, (void *) adminName, &tst);
1921 fail_bos_AdminGetNext:
1930 * bos_AdminGetDone - finish using a administrator iterator.
1934 * IN iterationId - an iterator previously returned by
1939 * No locks are obtained or released by this function
1943 * Returns != 0 upon successful completion.
1947 int ADMINAPI bos_AdminGetDone(
1948 const void *iterationId,
1952 afs_status_t tst = 0;
1953 afs_admin_iterator_p iter = (afs_admin_iterator_p) iterationId;
1955 if (iterationId == NULL) {
1956 tst = ADMITERATIONIDPNULL;
1957 goto fail_bos_AdminGetDone;
1960 rc = IteratorDone(iter, &tst);
1962 fail_bos_AdminGetDone:
1971 * bos_KeyCreate - add a new key to the keyfile.
1975 * IN serverHandle - a previously opened serverHandle.
1977 * IN keyVersionNumber - the key version number.
1979 * IN key - the new key.
1983 * No locks are obtained or released by this function
1987 * Returns != 0 upon successful completion.
1991 int ADMINAPI bos_KeyCreate(
1992 const void *serverHandle,
1993 int keyVersionNumber,
1994 const kas_encryptionKey_p key,
1998 afs_status_t tst = 0;
1999 bos_server_p b_handle = (bos_server_p) serverHandle;
2001 if (!isValidServerHandle(b_handle, &tst)) {
2002 goto fail_bos_KeyCreate;
2006 tst = ADMBOSKEYNULL;
2007 goto fail_bos_KeyCreate;
2010 tst = BOZO_AddKey(b_handle->server_encrypt, keyVersionNumber, key);
2025 * bos_KeyDelete - delete an existing key from the keyfile.
2029 * IN serverHandle - a previously opened serverHandle.
2031 * IN keyVersionNumber - the key version number.
2035 * No locks are obtained or released by this function
2039 * Returns != 0 upon successful completion.
2043 int ADMINAPI bos_KeyDelete(
2044 const void *serverHandle,
2045 int keyVersionNumber,
2049 afs_status_t tst = 0;
2050 bos_server_p b_handle = (bos_server_p) serverHandle;
2052 if (!isValidServerHandle(b_handle, &tst)) {
2053 goto fail_bos_KeyDelete;
2056 tst = BOZO_DeleteKey(b_handle->server, keyVersionNumber);
2071 * The iterator functions and data for the key retrieval functions
2074 typedef struct key_get {
2076 struct rx_connection *server;
2077 bos_KeyInfo_t key[CACHED_ITEMS];
2078 } key_get_t, *key_get_p;
2080 static int GetKeyRPC(
2084 int *last_item_contains_data,
2088 afs_status_t tst = 0;
2089 key_get_p key = (key_get_p) rpc_specific;
2090 char *ptr = (char *) &key->key[slot];
2091 struct bozo_keyInfo keyInfo;
2093 tst = BOZO_ListKeys(key->server, key->next++,
2094 &key->key[slot].keyVersionNumber,
2095 &key->key[slot].key, &keyInfo);
2099 key->key[slot].keyStatus.lastModificationDate = keyInfo.mod_sec;
2100 key->key[slot].keyStatus.lastModificationMicroSeconds =
2102 key->key[slot].keyStatus.checkSum = keyInfo.keyCheckSum;
2104 } else if (tst == BZDOM) {
2108 *last_item_contains_data = 0;
2117 static int GetKeyFromCache(
2124 afs_status_t tst = 0;
2125 key_get_p key = (key_get_p) rpc_specific;
2127 memcpy(dest, &key->key[slot], sizeof(bos_KeyInfo_t));
2137 * bos_KeyGetBegin - begin iterating over the keys.
2141 * IN serverHandle - a previously opened serverHandle.
2143 * OUT iter - an iterator that can be passed to bos_KeyGetNext
2144 * to retrieve the keys.
2148 * No locks are obtained or released by this function
2152 * Returns != 0 upon successful completion.
2156 int ADMINAPI bos_KeyGetBegin(
2157 const void *serverHandle,
2158 void **iterationIdP,
2162 afs_status_t tst = 0;
2163 bos_server_p b_handle = (bos_server_p) serverHandle;
2164 afs_admin_iterator_p iter = (afs_admin_iterator_p) malloc(sizeof(afs_admin_iterator_t));
2165 key_get_p key = (key_get_p) malloc(sizeof(key_get_t));
2167 if (!isValidServerHandle(b_handle, &tst)) {
2168 goto fail_bos_KeyGetBegin;
2171 if (iterationIdP == NULL) {
2172 tst = ADMITERATIONIDPNULL;
2173 goto fail_bos_KeyGetBegin;
2176 if ((iter == NULL) || (key == NULL)) {
2178 goto fail_bos_KeyGetBegin;
2182 key->server = b_handle->server_encrypt;
2184 if (IteratorInit(iter, (void *) key, GetKeyRPC,
2185 GetKeyFromCache, NULL, NULL, &tst)) {
2186 *iterationIdP = (void *) iter;
2190 fail_bos_KeyGetBegin:
2208 * bos_KeyGetNext - retrieve the next key
2209 * from the bos server.
2213 * IN iterationId - an iterator previously returned by
2216 * OUT keyP - upon successful completion contains the next key
2217 * retrieved from the server.
2221 * No locks are obtained or released by this function
2225 * Returns != 0 upon successful completion.
2229 int ADMINAPI bos_KeyGetNext(
2230 const void *iterationId,
2235 afs_status_t tst = 0;
2236 afs_admin_iterator_p iter = (afs_admin_iterator_p) iterationId;
2238 if (iterationId == NULL) {
2239 tst = ADMITERATIONIDPNULL;
2240 goto fail_bos_KeyGetNext;
2244 tst = ADMBOSKEYPNULL;
2245 goto fail_bos_KeyGetNext;
2248 rc = IteratorNext(iter, (void *) keyP, &tst);
2250 fail_bos_KeyGetNext:
2259 * bos_KeyGetDone - finish using a key iterator.
2263 * IN iterationId - an iterator previously returned by
2268 * No locks are obtained or released by this function
2272 * Returns != 0 upon successful completion.
2276 int ADMINAPI bos_KeyGetDone(
2277 const void *iterationId,
2281 afs_status_t tst = 0;
2282 afs_admin_iterator_p iter = (afs_admin_iterator_p) iterationId;
2284 if (iterationId == NULL) {
2285 tst = ADMITERATIONIDPNULL;
2286 goto fail_bos_KeyGetDone;
2289 rc = IteratorDone(iter, &tst);
2291 fail_bos_KeyGetDone:
2300 * bos_CellSet - set the cell name at a bos server.
2304 * IN serverHandle - a previously opened serverHandle.
2306 * IN cellName - the new cell name.
2310 * No locks are obtained or released by this function
2314 * Returns != 0 upon successful completion.
2317 int ADMINAPI bos_CellSet(
2318 const void *serverHandle,
2319 const char *cellName,
2323 afs_status_t tst = 0;
2324 bos_server_p b_handle = (bos_server_p) serverHandle;
2326 if (!isValidServerHandle(b_handle, &tst)) {
2327 goto fail_bos_CellSet;
2330 if ((cellName == NULL) || (*cellName == 0)) {
2331 tst = ADMCLIENTCELLNAMENULL;
2332 goto fail_bos_CellSet;
2335 tst = BOZO_SetCellName(b_handle->server, cellName);
2350 * bos_CellGet - get the cell name at a bos server.
2354 * IN serverHandle - a previously opened serverHandle.
2356 * OUT cellName - the cell name.
2360 * No locks are obtained or released by this function
2364 * Returns != 0 upon successful completion.
2367 int ADMINAPI bos_CellGet(
2368 const void *serverHandle,
2373 afs_status_t tst = 0;
2374 bos_server_p b_handle = (bos_server_p) serverHandle;
2376 if (!isValidServerHandle(b_handle, &tst)) {
2377 goto fail_bos_CellGet;
2380 if (cellName == NULL) {
2381 tst = ADMCLIENTCELLNAMENULL;
2382 goto fail_bos_CellGet;
2385 tst = BOZO_GetCellName(b_handle->server, &cellName);
2400 * bos_HostCreate - add a new host to the cell.
2404 * IN serverHandle - a previously opened serverHandle.
2406 * IN hostName - the new host.
2410 * No locks are obtained or released by this function
2414 * Returns != 0 upon successful completion.
2417 int ADMINAPI bos_HostCreate(
2418 const void *serverHandle,
2419 const char *hostName,
2423 afs_status_t tst = 0;
2424 bos_server_p b_handle = (bos_server_p) serverHandle;
2426 if (!isValidServerHandle(b_handle, &tst)) {
2427 goto fail_bos_HostCreate;
2430 if ((hostName == NULL) || (*hostName == 0)) {
2431 tst = ADMBOSHOSTNAMENULL;
2432 goto fail_bos_HostCreate;
2435 tst = BOZO_AddCellHost(b_handle->server, hostName);
2441 fail_bos_HostCreate:
2450 * bos_HostDelete - delete a host from the cell.
2454 * IN serverHandle - a previously opened serverHandle.
2456 * IN hostName - the host.
2460 * No locks are obtained or released by this function
2464 * Returns != 0 upon successful completion.
2467 int ADMINAPI bos_HostDelete(
2468 const void *serverHandle,
2469 const char *hostName,
2473 afs_status_t tst = 0;
2474 bos_server_p b_handle = (bos_server_p) serverHandle;
2476 if (!isValidServerHandle(b_handle, &tst)) {
2477 goto fail_bos_HostDelete;
2480 if ((hostName == NULL) || (*hostName == 0)) {
2481 tst = ADMBOSHOSTNAMENULL;
2482 goto fail_bos_HostDelete;
2485 tst = BOZO_DeleteCellHost(b_handle->server, hostName);
2491 fail_bos_HostDelete:
2500 * The iterator functions and data for the host retrieval functions
2503 typedef struct host_get {
2505 struct rx_connection *server;
2506 char host[CACHED_ITEMS][BOS_MAX_NAME_LEN];
2507 } host_get_t, *host_get_p;
2509 static int GetHostRPC(
2513 int *last_item_contains_data,
2517 afs_status_t tst = 0;
2518 host_get_p host = (host_get_p) rpc_specific;
2519 char *ptr = (char *) &host->host[slot];
2521 tst = BOZO_GetCellHost(host->server, host->next++, &ptr);
2525 } else if (tst == BZDOM) {
2529 *last_item_contains_data = 0;
2538 static int GetHostFromCache(
2545 afs_status_t tst = 0;
2546 host_get_p host = (host_get_p) rpc_specific;
2548 strcpy((char *) dest, (char *) &host->host[slot]);
2558 * bos_HostGetBegin - begin iterating over the hosts in a cell
2559 * at a particular bos server.
2563 * IN serverHandle - a previously opened serverHandle.
2565 * OUT iter - an iterator that can be passed to bos_HostGetNext
2566 * to retrieve the process names.
2570 * No locks are obtained or released by this function
2574 * Returns != 0 upon successful completion.
2578 int ADMINAPI bos_HostGetBegin(
2579 const void *serverHandle,
2580 void **iterationIdP,
2584 afs_status_t tst = 0;
2585 bos_server_p b_handle = (bos_server_p) serverHandle;
2586 afs_admin_iterator_p iter = (afs_admin_iterator_p) malloc(sizeof(afs_admin_iterator_t));
2587 host_get_p host = (host_get_p) malloc(sizeof(host_get_t));
2589 if (!isValidServerHandle(b_handle, &tst)) {
2590 goto fail_bos_HostGetBegin;
2593 if (iterationIdP == NULL) {
2594 tst = ADMITERATIONIDPNULL;
2595 goto fail_bos_HostGetBegin;
2598 if ((iter == NULL) || (host == NULL)) {
2600 goto fail_bos_HostGetBegin;
2604 host->server = b_handle->server;
2606 if (IteratorInit(iter, (void *) host, GetHostRPC,
2607 GetHostFromCache, NULL, NULL, &tst)) {
2608 *iterationIdP = (void *) iter;
2612 fail_bos_HostGetBegin:
2630 * bos_HostGetNext - retrieve the next host
2631 * from the bos server.
2635 * IN iterationId - an iterator previously returned by
2638 * OUT hostName - upon successful completion contains the next host
2639 * retrieved from the server.
2643 * No locks are obtained or released by this function
2647 * Returns != 0 upon successful completion.
2651 int ADMINAPI bos_HostGetNext(
2652 const void *iterationId,
2657 afs_status_t tst = 0;
2658 afs_admin_iterator_p iter = (afs_admin_iterator_p) iterationId;
2660 if (iterationId == NULL) {
2661 tst = ADMITERATIONIDPNULL;
2662 goto fail_bos_HostGetNext;
2665 if (hostName == NULL) {
2666 tst = ADMBOSHOSTNAMENULL;
2667 goto fail_bos_HostGetNext;
2670 rc = IteratorNext(iter, (void *) hostName, &tst);
2672 fail_bos_HostGetNext:
2681 * bos_HostGetDone - finish using a host iterator.
2685 * IN iterationId - an iterator previously returned by
2690 * No locks are obtained or released by this function
2694 * Returns != 0 upon successful completion.
2698 int ADMINAPI bos_HostGetDone(
2699 const void *iterationId,
2703 afs_status_t tst = 0;
2704 afs_admin_iterator_p iter = (afs_admin_iterator_p) iterationId;
2706 if (iterationId == NULL) {
2707 tst = ADMITERATIONIDPNULL;
2708 goto fail_bos_HostGetDone;
2711 rc = IteratorDone(iter, &tst);
2713 fail_bos_HostGetDone:
2722 * bos_ExecutableCreate - create a new executable at the bos server.
2726 * IN serverHandle - a previously opened serverHandle.
2728 * IN sourceFile - the executable to install at the bos server.
2730 * IN destFile - the location where the executable will be installed.
2734 * No locks are obtained or released by this function
2738 * Returns != 0 upon successful completion.
2742 int ADMINAPI bos_ExecutableCreate(
2743 const void *serverHandle,
2744 const char *sourceFile,
2745 const char *destFile,
2749 afs_status_t tst = 0;
2750 bos_server_p b_handle = (bos_server_p) serverHandle;
2753 struct rx_call *tcall;
2756 * Validate arguments
2759 if (!isValidServerHandle(b_handle, &tst)) {
2760 goto fail_bos_ExecutableCreate;
2763 if ((sourceFile == NULL) || (*sourceFile == 0)) {
2764 tst = ADMBOSSOURCEFILENULL;
2765 goto fail_bos_ExecutableCreate;
2768 if ((destFile == NULL) || (*destFile == 0)) {
2769 tst = ADMBOSDESTFILENULL;
2770 goto fail_bos_ExecutableCreate;
2774 * Open the file locally and compute its size
2777 fd = open(sourceFile, O_RDONLY);
2780 tst = ADMBOSCANTOPENSOURCEFILE;
2781 goto fail_bos_ExecutableCreate;
2784 if (fstat(fd, &estat)) {
2785 tst = ADMBOSCANTSTATSOURCEFILE;
2786 goto fail_bos_ExecutableCreate;
2790 * Start a split rpc to the bos server.
2793 tcall = rx_NewCall(b_handle->server);
2795 tst = StartBOZO_Install(tcall, destFile, estat.st_size,
2796 (afs_int32) estat.st_mode, estat.st_mtime);
2799 rx_EndCall(tcall, tst);
2800 goto fail_bos_ExecutableCreate;
2804 * Copy the data to the server
2810 len = read(fd, tbuffer, sizeof(tbuffer));
2812 tst = ADMBOSCANTREADSOURCEFILE;
2813 rx_EndCall(tcall, len);
2814 goto fail_bos_ExecutableCreate;
2820 tst = rx_Write(tcall, tbuffer, len);
2822 tst = ADMBOSSENDSOURCEFILE;
2823 rx_EndCall(tcall, tst);
2824 goto fail_bos_ExecutableCreate;
2829 * Terminate the rpc to the server
2832 tst = rx_EndCall(tcall, tst);
2838 fail_bos_ExecutableCreate:
2847 * bos_ExecutableRevert - revert an executable to a previous .BAK version.
2851 * IN serverHandle - a previously opened serverHandle.
2853 * IN execFile - the executable to revert at the bos server.
2857 * No locks are obtained or released by this function
2861 * Returns != 0 upon successful completion.
2865 int ADMINAPI bos_ExecutableRevert(
2866 const void *serverHandle,
2867 const char *execFile,
2871 afs_status_t tst = 0;
2872 bos_server_p b_handle = (bos_server_p) serverHandle;
2874 if (!isValidServerHandle(b_handle, &tst)) {
2875 goto fail_bos_ExecutableRevert;
2878 if ((execFile == NULL) || (*execFile == 0)) {
2879 tst = ADMBOSEXECFILENULL;
2880 goto fail_bos_ExecutableRevert;
2883 tst = BOZO_UnInstall(b_handle->server, execFile);
2889 fail_bos_ExecutableRevert:
2898 * bos_ExecutableTimestampGet - get the last mod times for an executable,
2899 * the .BAK version of the executable, and the .OLD version of the
2900 * executable if they exist.
2904 * IN serverHandle - a previously opened serverHandle.
2906 * IN execFile - the executable to revert at the bos server.
2910 * No locks are obtained or released by this function
2914 * Returns != 0 upon successful completion.
2918 int ADMINAPI bos_ExecutableTimestampGet(
2919 const void *serverHandle,
2920 const char *execFile,
2921 unsigned long *newTime,
2922 unsigned long *oldTime,
2923 unsigned long *bakTime,
2927 afs_status_t tst = 0;
2928 bos_server_p b_handle = (bos_server_p) serverHandle;
2930 if (!isValidServerHandle(b_handle, &tst)) {
2931 goto fail_bos_ExecutableTimestampGet;
2934 if ((execFile == NULL) || (*execFile == 0)) {
2935 tst = ADMBOSEXECFILENULL;
2936 goto fail_bos_ExecutableTimestampGet;
2939 if (newTime == NULL) {
2940 tst = ADMBOSNEWTIMENULL;
2941 goto fail_bos_ExecutableTimestampGet;
2944 if (oldTime == NULL) {
2945 tst = ADMBOSOLDTIMENULL;
2946 goto fail_bos_ExecutableTimestampGet;
2949 if (bakTime == NULL) {
2950 tst = ADMBOSBAKTIMENULL;
2951 goto fail_bos_ExecutableTimestampGet;
2954 tst = BOZO_GetDates(b_handle->server, execFile, newTime, bakTime, oldTime);
2960 fail_bos_ExecutableTimestampGet:
2969 * bos_ExecutablePrune - prune the bak, old, and core files off a server
2974 * IN serverHandle - a previously opened serverHandle.
2976 * IN oldFiles - prune .OLD files.
2978 * IN bakFiles - prune .BAK files.
2980 * IN coreFiles - prune core files.
2984 * No locks are obtained or released by this function
2988 * Returns != 0 upon successful completion.
2992 int ADMINAPI bos_ExecutablePrune(
2993 const void *serverHandle,
2994 bos_Prune_t oldFiles,
2995 bos_Prune_t bakFiles,
2996 bos_Prune_t coreFiles,
3000 afs_status_t tst = 0;
3001 bos_server_p b_handle = (bos_server_p) serverHandle;
3002 afs_int32 flags = 0;
3004 if (!isValidServerHandle(b_handle, &tst)) {
3005 goto fail_bos_ExecutablePrune;
3008 if (oldFiles == BOS_PRUNE) {
3009 flags |= BOZO_PRUNEOLD;
3012 if (bakFiles == BOS_PRUNE) {
3013 flags |= BOZO_PRUNEBAK;
3016 if (coreFiles == BOS_PRUNE) {
3017 flags |= BOZO_PRUNECORE;
3020 tst = BOZO_Prune(b_handle->server, flags);
3026 fail_bos_ExecutablePrune:
3035 * bos_ExecutableRestartTimeSet - set the restart time of the bos server
3040 * IN serverHandle - a previously opened serverHandle.
3042 * IN type - specifies either weekly restart or daily restart time.
3044 * IN time - the time to begin restarts.
3048 * No locks are obtained or released by this function
3052 * Returns != 0 upon successful completion.
3056 int ADMINAPI bos_ExecutableRestartTimeSet(
3057 const void *serverHandle,
3059 bos_RestartTime_t time,
3063 afs_status_t tst = 0;
3064 bos_server_p b_handle = (bos_server_p) serverHandle;
3065 afs_int32 restartType = 0;
3066 struct ktime restartTime;
3068 if (!isValidServerHandle(b_handle, &tst)) {
3069 goto fail_bos_ExecutableRestartTimeSet;
3072 if (type == BOS_RESTART_WEEKLY) {
3078 if ((time.mask & BOS_RESTART_TIME_HOUR) &&
3079 (time.hour < 0) || (time.hour > 23)) {
3080 tst = ADMBOSHOURINVALID;
3081 goto fail_bos_ExecutableRestartTimeSet;
3084 if ((time.mask & BOS_RESTART_TIME_MINUTE) &&
3085 (time.min < 0) || (time.min > 60)) {
3086 tst = ADMBOSMINUTEINVALID;
3087 goto fail_bos_ExecutableRestartTimeSet;
3090 if ((time.mask & BOS_RESTART_TIME_SECOND) &&
3091 (time.sec < 0) || (time.sec > 60)) {
3092 tst = ADMBOSSECONDINVALID;
3093 goto fail_bos_ExecutableRestartTimeSet;
3096 if ((time.mask & BOS_RESTART_TIME_DAY) &&
3097 (time.day < 0) || (time.day > 6)) {
3098 tst = ADMBOSDAYINVALID;
3099 goto fail_bos_ExecutableRestartTimeSet;
3102 restartTime.mask = time.mask;
3103 restartTime.hour = time.hour;
3104 restartTime.min = time.min;
3105 restartTime.sec = time.sec;
3106 restartTime.day = time.day;
3108 tst = BOZO_SetRestartTime(b_handle->server, restartType, restartTime);
3114 fail_bos_ExecutableRestartTimeSet:
3123 * bos_ExecutableRestartTimeGet - get the restart time of the bos server
3128 * IN serverHandle - a previously opened serverHandle.
3130 * IN type - specifies either weekly restart or daily restart time.
3132 * OUT timeP - the time to begin restarts.
3136 * No locks are obtained or released by this function
3140 * Returns != 0 upon successful completion.
3144 int ADMINAPI bos_ExecutableRestartTimeGet(
3145 const void *serverHandle,
3147 bos_RestartTime_p timeP,
3151 afs_status_t tst = 0;
3152 bos_server_p b_handle = (bos_server_p) serverHandle;
3153 afs_int32 restartType = 0;
3154 struct ktime restartTime;
3156 if (!isValidServerHandle(b_handle, &tst)) {
3157 goto fail_bos_ExecutableRestartTimeGet;
3160 if (timeP == NULL) {
3161 tst = ADMBOSTIMEPNULL;
3162 goto fail_bos_ExecutableRestartTimeGet;
3165 if (type == BOS_RESTART_WEEKLY) {
3171 tst = BOZO_GetRestartTime(b_handle->server, restartType, &restartTime);
3174 goto fail_bos_ExecutableRestartTimeGet;
3177 timeP->mask = restartTime.mask;
3178 timeP->hour = restartTime.hour;
3179 timeP->min = restartTime.min;
3180 timeP->sec = restartTime.sec;
3181 timeP->day = restartTime.day;
3184 fail_bos_ExecutableRestartTimeGet:
3193 * bos_LogGet - get a log file from the bos server machine.
3197 * IN serverHandle - a previously opened serverHandle.
3199 * IN log - the log file to retrieve.
3201 * IN/OUT logBufferSizeP - the length of the logData buffer on input,
3202 * and upon successful completion, the length of data stored in the buffer.
3204 * OUT logData - the retrieved data upon successful completion.
3208 * No locks are obtained or released by this function
3212 * Returns != 0 upon successful completion.
3216 int ADMINAPI bos_LogGet(
3217 const void *serverHandle,
3219 unsigned long *logBufferSizeP,
3224 afs_status_t tst = 0;
3225 bos_server_p b_handle = (bos_server_p) serverHandle;
3226 struct rx_call *tcall;
3230 unsigned long bytes_read = 0;
3233 * Validate parameters
3236 if (!isValidServerHandle(b_handle, &tst)) {
3237 goto fail_bos_LogGet;
3240 if ((log == NULL) || (*log == 0)) {
3241 tst = ADMBOSLOGNULL;
3242 goto fail_bos_LogGet;
3245 if (logBufferSizeP == NULL) {
3246 tst = ADMBOSLOGBUFFERSIZEPNULL;
3247 goto fail_bos_LogGet;
3250 if (logData == NULL) {
3251 tst = ADMBOSLOGDATANULL;
3252 goto fail_bos_LogGet;
3256 * Begin to retrieve the data
3259 tcall = rx_NewCall(b_handle->server);
3261 tst = StartBOZO_GetLog(tcall, log);
3264 goto fail_bos_LogGet;
3268 * Read the log file data
3272 error = rx_Read(tcall, &buffer, 1);
3274 tst = ADMBOSLOGFILEERROR;
3275 goto fail_bos_LogGet;
3279 * check for the end of the log
3283 *logBufferSizeP = bytes_read;
3288 * We've successfully read another byte, copy it to logData
3293 if (bytes_read <= *logBufferSizeP) {
3294 *logData++ = buffer;
3306 rx_EndCall(tcall, 0);
3316 * bos_AuthSet - set the authorization level required at the bos server.
3320 * IN serverHandle - a previously opened serverHandle.
3322 * IN auth - specifies the new auth level.
3326 * No locks are obtained or released by this function
3330 * Returns != 0 upon successful completion.
3334 int ADMINAPI bos_AuthSet(
3335 const void *serverHandle,
3340 afs_status_t tst = 0;
3341 bos_server_p b_handle = (bos_server_p) serverHandle;
3342 afs_int32 level = 0;
3344 if (!isValidServerHandle(b_handle, &tst)) {
3345 goto fail_bos_AuthSet;
3348 if (auth == BOS_AUTH_REQUIRED) {
3354 tst = BOZO_SetNoAuthFlag(b_handle->server, level);
3369 * bos_CommandExecute - execute a command at the bos server.
3373 * IN serverHandle - a previously opened serverHandle.
3375 * IN command - the command to execute.
3379 * No locks are obtained or released by this function
3383 * Returns != 0 upon successful completion.
3387 int ADMINAPI bos_CommandExecute(
3388 const void *serverHandle,
3389 const char *command,
3393 afs_status_t tst = 0;
3394 bos_server_p b_handle = (bos_server_p) serverHandle;
3396 if (!isValidServerHandle(b_handle, &tst)) {
3397 goto fail_bos_CommandExecute;
3400 if ((command == NULL) || (*command == 0)) {
3401 tst = ADMBOSCOMMANDNULL;
3402 goto fail_bos_CommandExecute;
3405 tst = BOZO_Exec(b_handle->server, command);
3411 fail_bos_CommandExecute:
3420 * bos_Salvage - perform a remote salvage operation.
3424 * IN cellHandle - a previously opened cellHandle.
3426 * IN serverHandle - a previously opened serverHandle.
3428 * IN partitionName - the partition to salvage. Can be null.
3430 * IN volumeName - the volume to salvage. Can be null, if non-null,
3431 * partitionName cannot be null.
3433 * IN numSalvagers - the number of salvage processes to run in parallel.
3435 * IN tmpDir - directory to place temporary files. Can be null.
3437 * IN logFile - file where salvage log will be written. Can be null.
3439 * IN force - sets salvager -force flag.
3441 * IN salvageDamagedVolumes - sets salvager -oktozap flag.
3443 * IN writeInodes - sets salvager -inodes flag.
3445 * IN writeRootInodes - sets salvager -rootinodes flag.
3447 * IN forceDirectory - sets salvager -salvagedirs flag.
3449 * IN forceBlockRead - sets salvager -blockread flag.
3453 * No locks are obtained or released by this function
3457 * Returns != 0 upon successful completion.
3461 #define INITIAL_LOG_LEN 4096
3463 int ADMINAPI bos_Salvage(
3464 const void *cellHandle,
3465 const void *serverHandle,
3466 const char *partitionName,
3467 const char *volumeName,
3470 const char *logFile,
3472 bos_SalvageDamagedVolumes_t salvageDamagedVolumes,
3473 bos_WriteInodes_t writeInodes,
3474 bos_WriteRootInodes_t writeRootInodes,
3475 bos_ForceDirectory_t forceDirectory,
3476 bos_ForceBlockRead_t forceBlockRead,
3480 afs_status_t tst = 0;
3481 bos_server_p b_handle = (bos_server_p) serverHandle;
3482 afs_cell_handle_p c_handle = (afs_cell_handle_p) cellHandle;
3483 int have_partition = 0;
3484 int have_volume = 0;
3485 unsigned int part = 0;
3486 int try_to_stop_fileserver = 0;
3487 int stopped_fileserver = 0;
3488 bos_ProcessType_t procType;
3489 bos_ProcessInfo_t procInfo;
3491 char command[BOS_MAX_NAME_LEN];
3492 int command_len = 0;
3494 char *logData = NULL;
3495 unsigned long logLen = INITIAL_LOG_LEN;
3498 * Validate arguments
3501 if (!IsValidCellHandle(c_handle, &tst)) {
3502 goto fail_bos_Salvage;
3505 if (!isValidServerHandle(b_handle, &tst)) {
3506 goto fail_bos_Salvage;
3509 if (c_handle->vos_valid == 0) {
3510 tst = ADMBOSCELLHANDLENOVOS;
3511 goto fail_bos_Salvage;
3514 if ((partitionName != NULL) && (*partitionName != 0)) {
3515 if (!vos_PartitionNameToId(partitionName, &part, &tst)) {
3516 goto fail_bos_Salvage;
3521 if ((volumeName != NULL) && (*volumeName != 0)) {
3522 if (!have_partition) {
3523 tst = ADMBOSSALVAGEVOLUME;
3524 goto fail_bos_Salvage;
3529 if ((logFile != NULL) && (*logFile != 0)) {
3530 log = fopen(logFile, "w");
3532 tst = ADMBOSSALVAGEBADLOG;
3533 goto fail_bos_Salvage;
3538 * If we are salvaging more than a single volume, stop the fileserver
3542 try_to_stop_fileserver = 1;
3546 * Only try to stop the fileserver if it is running
3549 if (try_to_stop_fileserver) {
3550 if (bos_ProcessInfoGet(serverHandle, "fs", &procType, &procInfo,
3552 if (procInfo.processGoal != BOS_PROCESS_RUNNING) {
3553 try_to_stop_fileserver = 0;
3559 * Make the call to stop the fileserver and wait for it to shutdown
3562 if (try_to_stop_fileserver) {
3563 if (!bos_ProcessExecutionStateSetTemporary(serverHandle, "fs",
3564 BOS_PROCESS_STOPPED,
3566 goto fail_bos_Salvage;
3568 bos_ProcessAllWaitTransition(serverHandle, &tst);
3572 * Create the salvage command line arguments
3575 command_len = sprintf(command, "%s ",
3576 AFSDIR_CANONICAL_SERVER_SALVAGER_FILEPATH);
3577 if (have_partition) {
3578 command_len += sprintf(&command[command_len], "-partition %s ",
3583 command_len += sprintf(&command[command_len], "-volumeid %s ",
3587 if (salvageDamagedVolumes == BOS_DONT_SALVAGE_DAMAGED_VOLUMES) {
3588 command_len += sprintf(&command[command_len], "-nowrite ");
3591 if (writeInodes == BOS_SALVAGE_WRITE_INODES) {
3592 command_len += sprintf(&command[command_len], "-inodes ");
3595 if (force == VOS_FORCE) {
3596 command_len += sprintf(&command[command_len], "-force ");
3599 if (writeRootInodes == BOS_SALVAGE_WRITE_ROOT_INODES) {
3600 command_len += sprintf(&command[command_len], "-rootinodes ");
3603 if (forceDirectory == BOS_SALVAGE_FORCE_DIRECTORIES) {
3604 command_len += sprintf(&command[command_len], "-salvagedirs ");
3607 if (forceBlockRead == BOS_SALVAGE_FORCE_BLOCK_READS) {
3608 command_len += sprintf(&command[command_len], "-blockreads ");
3611 command_len += sprintf(&command[command_len], "-parallel %d ", numSalvagers);
3613 if ((tmpDir != NULL) && (*tmpDir != 0)) {
3614 command_len += sprintf(&command[command_len], "-tmpdir %s ", tmpDir);
3617 if (command_len > BOS_MAX_NAME_LEN) {
3618 tst = ADMBOSSALVAGEBADOPTIONS;
3619 goto fail_bos_Salvage;
3623 * Create the process at the bosserver and wait until it completes
3626 if (!bos_ProcessCreate(serverHandle, "salvage-tmp", BOS_PROCESS_CRON,
3627 command, "now", 0, &tst)) {
3628 goto fail_bos_Salvage;
3631 while (poll_rc = bos_ProcessInfoGet(serverHandle, "salvage-tmp", &procType,
3636 if (tst != BZNOENT) {
3637 goto fail_bos_Salvage;
3641 * Print out the salvage log if required by the user
3646 logData = (char *) malloc(INITIAL_LOG_LEN);
3649 goto fail_bos_Salvage;
3652 while(!bos_LogGet(serverHandle,
3653 AFSDIR_CANONICAL_SERVER_SLVGLOG_FILEPATH,
3654 &logLen, logData, &tst)) {
3655 if (logLen > INITIAL_LOG_LEN) {
3656 logData = (char *) realloc(logData, (logLen + (logLen / 10)));
3657 if (logData == NULL) {
3659 goto fail_bos_Salvage;
3662 goto fail_bos_Salvage;
3665 fprintf(log, "SalvageLog:\n%s", logData);
3669 * Restart the fileserver if we had stopped it previously
3672 if (try_to_stop_fileserver) {
3673 try_to_stop_fileserver = 0;
3674 if (!bos_ProcessExecutionStateSetTemporary(serverHandle, "fs",
3675 BOS_PROCESS_RUNNING,
3677 goto fail_bos_Salvage;
3688 if (logData != NULL) {
3692 if (try_to_stop_fileserver) {
3693 bos_ProcessExecutionStateSetTemporary(serverHandle, "fs",
3694 BOS_PROCESS_RUNNING, 0);