2 * Copyright 2000, International Business Machines Corporation and others.
5 * This software has been released under the terms of the IBM Public
6 * License. For details, see the LICENSE file in the top-level source
7 * directory or online at http://www.openafs.org/dl/license10.html
10 #include <afsconfig.h>
11 #include <afs/param.h>
17 #include "afs_bosAdmin.h"
18 #include "../adminutil/afs_AdminInternal.h"
19 #include <afs/afs_AdminErrors.h>
20 #include <afs/afs_utilAdmin.h>
21 #include <afs/bosint.h>
22 #include <afs/bnode.h>
23 #include <afs/ktime.h>
24 #include <afs/dirpath.h>
26 #include <sys/types.h>
37 * Prototypes for functions that don't exist in any header files
40 extern int BOZO_AddCellHost();
41 extern int BOZO_AddKey();
42 extern int BOZO_AddSUser();
43 extern int BOZO_CreateBnode();
44 extern int BOZO_DeleteBnode();
45 extern int BOZO_DeleteCellHost();
46 extern int BOZO_DeleteKey();
47 extern int BOZO_DeleteSUser();
48 extern int BOZO_EnumerateInstance();
49 extern int BOZO_Exec();
50 extern int BOZO_GetCellHost();
51 extern int BOZO_GetCellName();
52 extern int BOZO_GetDates();
53 extern int BOZO_GetInstanceInfo();
54 extern int BOZO_GetInstanceParm();
55 extern int BOZO_GetInstanceParm();
56 extern int BOZO_GetRestartTime();
57 extern int BOZO_GetStatus();
58 extern int BOZO_ListSUsers();
59 extern int BOZO_ListKeys();
60 extern int BOZO_Prune();
61 extern int BOZO_ReBozo();
62 extern int BOZO_Restart();
63 extern int BOZO_RestartAll();
64 extern int BOZO_SetCellName();
65 extern int BOZO_SetNoAuthFlag();
66 extern int BOZO_SetRestartTime();
67 extern int BOZO_SetStatus(struct rx_connection *, char *, afs_int32);
68 extern int BOZO_SetTStatus(struct rx_connection *, char *, afs_int32);
69 extern int BOZO_ShutdownAll();
70 extern int BOZO_StartupAll();
71 extern int BOZO_UnInstall();
72 extern int BOZO_WaitAll();
73 extern int StartBOZO_GetLog();
74 extern int StartBOZO_Install();
76 typedef struct bos_server {
79 struct rx_connection *server;
80 struct rx_connection *server_encrypt;
81 struct rx_connection *server_stats;
83 } bos_server_t, *bos_server_p;
86 * isValidServerHandle - validate a bos_server_p.
90 * IN serverHandle - the handle to validate
94 * No locks are obtained or released by this function
98 * Returns != 0 upon successful completion.
101 int isValidServerHandle (
102 const bos_server_p serverHandle,
106 afs_status_t tst = 0;
108 if (serverHandle == NULL) {
109 tst = ADMBOSSERVERHANDLENULL;
110 goto fail_IsValidServerHandle;
113 if ((serverHandle->begin_magic != BEGIN_MAGIC) ||
114 (serverHandle->end_magic != END_MAGIC)) {
115 tst = ADMBOSSERVERHANDLEBADMAGIC;
116 goto fail_IsValidServerHandle;
119 if (serverHandle->is_valid == 0) {
120 tst = ADMBOSSERVERHANDLEINVALID;
121 goto fail_IsValidServerHandle;
124 if (serverHandle->server == NULL) {
125 tst = ADMBOSSERVERHANDLENOSERVER;
126 goto fail_IsValidServerHandle;
129 if (serverHandle->server_encrypt == NULL) {
130 tst = ADMBOSSERVERHANDLENOSERVER;
131 goto fail_IsValidServerHandle;
135 fail_IsValidServerHandle:
143 * IsValidCellHandle - verify that a cell handle can be used to make bos
148 * IN cellHandle - the cellHandle to be validated.
152 * No locks are obtained or released by this function
156 * Returns != 0 upon successful completion.
159 static int IsValidCellHandle(
160 afs_cell_handle_p cellHandle,
164 afs_status_t tst = 0;
166 if (!CellHandleIsValid((void *) cellHandle, &tst)) {
167 goto fail_IsValidCellHandle;
170 if (cellHandle->tokens == NULL) {
171 tst = ADMBOSCELLHANDLENOTOKENS;
172 goto fail_IsValidCellHandle;
176 fail_IsValidCellHandle:
185 * bos_ServerOpen - open a bos server for work.
189 * IN cellHandle - a previously opened cellHandle.
191 * IN serverName - the name of the machine that houses the bosserver of
194 * OUT serverHandleP - upon successful completion, this void pointer
195 * will point to a valid server handle for use in future operations.
199 * No locks are obtained or released by this function
203 * Returns != 0 upon successful completion.
206 int ADMINAPI bos_ServerOpen(
207 const void *cellHandle,
208 const char *serverName,
209 void **serverHandleP,
213 afs_status_t tst = 0;
214 afs_cell_handle_p c_handle = (afs_cell_handle_p) cellHandle;
215 bos_server_p bos_server = (bos_server_p) malloc(sizeof(bos_server_t));
219 * Validate parameters
222 if (!IsValidCellHandle(c_handle, &tst)) {
223 goto fail_bos_ServerOpen;
226 if ((serverName == NULL) || (*serverName == 0)) {
227 tst = ADMBOSSERVERNAMENULL;
228 goto fail_bos_ServerOpen;
231 if (serverHandleP == NULL) {
232 tst = ADMBOSSERVERHANDLEPNULL;
233 goto fail_bos_ServerOpen;
236 if (util_AdminServerAddressGetFromName(serverName, &serverAddress, &tst) == 0) {
237 goto fail_bos_ServerOpen;
240 if (bos_server == NULL) {
242 goto fail_bos_ServerOpen;
245 bos_server->server = rx_GetCachedConnection(htonl(serverAddress),
246 htons(AFSCONF_NANNYPORT), 1,
247 c_handle->tokens->afs_sc[c_handle->tokens->sc_index], c_handle->tokens->sc_index);
249 bos_server->server_encrypt = rx_GetCachedConnection(htonl(serverAddress),
250 htons(AFSCONF_NANNYPORT), 1,
251 c_handle->tokens->afs_encrypt_sc[c_handle->tokens->sc_index], c_handle->tokens->sc_index);
253 bos_server->server_stats = rx_GetCachedConnection(htonl(serverAddress),
254 htons(AFSCONF_NANNYPORT),
256 c_handle->tokens->afs_sc[c_handle->tokens->sc_index], c_handle->tokens->sc_index);
258 if ((bos_server->server == NULL) || (bos_server->server_encrypt == NULL)) {
259 tst = ADMBOSSERVERNOCONNECTION;
260 goto fail_bos_ServerOpen;
263 bos_server->begin_magic = BEGIN_MAGIC;
264 bos_server->is_valid = 1;
265 bos_server->end_magic = END_MAGIC;
267 *serverHandleP = (void *) bos_server;
272 if ((rc == 0) && (bos_server != NULL)) {
273 if (bos_server->server) {
274 rx_ReleaseCachedConnection(bos_server->server);
276 if (bos_server->server_encrypt) {
277 rx_ReleaseCachedConnection(bos_server->server_encrypt);
289 * bos_ServerClose - close a bos server handle
293 * IN serverHandle - a bos server handle previously returned by bos_ServerOpen
297 * No locks are obtained or released by this function
301 * Returns != 0 upon successful completion.
304 int ADMINAPI bos_ServerClose(
305 const void *serverHandle,
309 afs_status_t tst = 0;
310 bos_server_p b_handle = (bos_server_p) serverHandle;
312 if (isValidServerHandle(b_handle, &tst)) {
313 rx_ReleaseCachedConnection(b_handle->server);
314 b_handle->is_valid = 0;
326 * bos_ProcessCreate - create a new process to run at a bos server.
330 * IN serverHandle - a previously opened serverHandle.
332 * IN processName - the name of the process to create.
334 * IN processType - the type of process to create.
336 * IN process - the path to the process binary at the bos server.
338 * IN cronTime - the time specification for cron processes.
340 * IN notifier - the path to the notifier binary at the bos server.
344 * No locks are obtained or released by this function
348 * Returns != 0 upon successful completion.
352 * CAUTION - this list must match bos_ProcessType_t definition
355 static char *processTypes[] = {"simple", "fs", "cron", 0};
357 int ADMINAPI bos_ProcessCreate(
358 const void *serverHandle,
359 const char *processName,
360 bos_ProcessType_t processType,
362 const char *cronTime,
363 const char *notifier,
367 afs_status_t tst = 0;
368 bos_server_p b_handle = (bos_server_p) serverHandle;
370 if (!isValidServerHandle(b_handle, &tst)) {
371 goto fail_bos_ProcessCreate;
374 if (processType == BOS_PROCESS_FS) {
375 tst = ADMBOSPROCESSCREATEBADTYPE;
376 goto fail_bos_ProcessCreate;
379 if ((processName == NULL) || (*processName == 0)) {
380 tst = ADMBOSPROCESSNAMENULL;
381 goto fail_bos_ProcessCreate;
384 if ((process == NULL) || (*process == 0)) {
385 tst = ADMBOSPROCESSNULL;
386 goto fail_bos_ProcessCreate;
389 if ((processType == BOS_PROCESS_CRON) && (cronTime == NULL)) {
390 tst = ADMBOSCRONTIMENULL;
391 goto fail_bos_ProcessCreate;
394 if ((processType == BOS_PROCESS_SIMPLE) && (cronTime != NULL)) {
395 tst = ADMBOSCRONTIMENOTNULL;
396 goto fail_bos_ProcessCreate;
399 tst = BOZO_CreateBnode(b_handle->server, processTypes[processType],
400 processName, process,
401 (cronTime) ? cronTime : "", "", "", "",
402 (notifier) ? notifier : NONOTIFIER);
407 fail_bos_ProcessCreate:
416 * bos_FSProcessCreate - create the fs group of processes at the boserver.
420 * IN serverHandle - a previously opened serverHandle.
422 * IN processName - the name of the process to create.
424 * IN fileserverPath - the path to the fileserver binary at the bos server.
426 * IN volserverPath - the path to the volserver binary at the bos server.
428 * IN salvagerPath - the path to the salvager binary at the bos server.
430 * IN notifier - the path to the notifier binary at the bos server.
434 * No locks are obtained or released by this function
438 * Returns != 0 upon successful completion.
441 int ADMINAPI bos_FSProcessCreate(
442 const void *serverHandle,
443 const char *processName,
444 const char *fileserverPath,
445 const char *volserverPath,
446 const char *salvagerPath,
447 const char *notifier,
451 afs_status_t tst = 0;
452 bos_server_p b_handle = (bos_server_p) serverHandle;
454 if (!isValidServerHandle(b_handle, &tst)) {
455 goto fail_bos_ProcessCreate;
458 if ((processName == NULL) || (*processName == 0)) {
459 tst = ADMBOSPROCESSNAMENULL;
460 goto fail_bos_ProcessCreate;
463 if ((fileserverPath == NULL) || (*fileserverPath == 0)) {
464 tst = ADMBOSFILESERVERPATHNULL;
465 goto fail_bos_ProcessCreate;
468 if ((volserverPath == NULL) || (*volserverPath == 0)) {
469 tst = ADMBOSVOLSERVERPATHNULL;
470 goto fail_bos_ProcessCreate;
473 if ((salvagerPath == NULL) || (*salvagerPath == 0)) {
474 tst = ADMBOSSALVAGERPATHNULL;
475 goto fail_bos_ProcessCreate;
478 tst = BOZO_CreateBnode(b_handle->server,
479 processTypes[BOS_PROCESS_FS],
486 (notifier) ? notifier : NONOTIFIER);
491 fail_bos_ProcessCreate:
500 * bos_ProcessDelete - delete an existing process at a bos server.
504 * IN serverHandle - a previously opened serverHandle.
506 * IN processName - the name of the process to delete.
510 * No locks are obtained or released by this function
514 * Returns != 0 upon successful completion.
517 int ADMINAPI bos_ProcessDelete(
518 const void *serverHandle,
519 const char *processName,
523 afs_status_t tst = 0;
524 bos_server_p b_handle = (bos_server_p) serverHandle;
526 if (!isValidServerHandle(b_handle, &tst)) {
527 goto fail_bos_ProcessDelete;
530 if ((processName == NULL) || (*processName == 0)) {
531 tst = ADMBOSPROCESSNAMENULL;
532 goto fail_bos_ProcessDelete;
535 tst = BOZO_DeleteBnode(b_handle->server, processName);
541 fail_bos_ProcessDelete:
550 * bos_ProcessExecutionStateGet - get the current execution state of a
555 * IN serverHandle - a previously opened serverHandle.
557 * IN processName - the name of the process to retrieve.
559 * OUT processStatusP - upon successful completion the process execution state
561 * OUT auxiliaryProcessStatus - set to point to aux proc status if available.
562 * Pass a pointer to an char array at least BOS_MAX_NAME_LEN long.
566 * No locks are obtained or released by this function
570 * Returns != 0 upon successful completion.
573 int ADMINAPI bos_ProcessExecutionStateGet(
574 const void *serverHandle,
575 const char *processName,
576 bos_ProcessExecutionState_p processStatusP,
577 char *auxiliaryProcessStatus,
581 afs_status_t tst = 0;
582 bos_server_p b_handle = (bos_server_p) serverHandle;
585 if (!isValidServerHandle(b_handle, &tst)) {
586 goto fail_bos_ProcessExecutionStateGet;
589 if ((processName == NULL) || (*processName == 0)) {
590 tst = ADMBOSPROCESSNAMENULL;
591 goto fail_bos_ProcessExecutionStateGet;
594 if (processStatusP == NULL) {
595 tst = ADMBOSPROCESSSTATUSPNULL;
596 goto fail_bos_ProcessExecutionStateGet;
599 if (auxiliaryProcessStatus == NULL) {
600 tst = ADMBOSAUXILIARYPROCESSSTATUSNULL;
601 goto fail_bos_ProcessExecutionStateGet;
604 tst = BOZO_GetStatus(b_handle->server, processName, &state, &auxiliaryProcessStatus);
607 goto fail_bos_ProcessExecutionStateGet;
610 *processStatusP = (bos_ProcessExecutionState_t) state;
613 fail_bos_ProcessExecutionStateGet:
622 * SetExecutionState - set the execution state of a process
626 * IN serverHandle - a previously opened serverHandle.
628 * IN processName - the name of the process to modify.
630 * IN processStatus - the new process state.
632 * IN func - the function to call to set the status.
636 * No locks are obtained or released by this function
640 * Returns != 0 upon successful completion.
643 static int SetExecutionState(
644 const void *serverHandle,
645 const char *processName,
646 const bos_ProcessExecutionState_t processStatus,
647 int (*func)(struct rx_connection *, const char *, afs_int32),
651 afs_status_t tst = 0;
652 bos_server_p b_handle = (bos_server_p) serverHandle;
655 if (!isValidServerHandle(b_handle, &tst)) {
656 goto fail_SetExecutionState;
659 if ((processName == NULL) || (*processName == 0)) {
660 tst = ADMBOSPROCESSNAMENULL;
661 goto fail_SetExecutionState;
664 if ((processStatus != BOS_PROCESS_STOPPED) &&
665 (processStatus != BOS_PROCESS_RUNNING)) {
666 tst = ADMBOSPROCESSSTATUSSET;
667 goto fail_SetExecutionState;
670 state = (afs_int32) processStatus;
672 tst = func(b_handle->server, processName, state);
678 fail_SetExecutionState:
687 * bos_ProcessExecutionStateSet - set the execution state of a process
691 * IN serverHandle - a previously opened serverHandle.
693 * IN processName - the name of the process to modify.
695 * IN processStatus - the new process state.
699 * No locks are obtained or released by this function
703 * Returns != 0 upon successful completion.
706 int ADMINAPI bos_ProcessExecutionStateSet(
707 const void *serverHandle,
708 const char *processName,
709 bos_ProcessExecutionState_t processStatus,
712 return SetExecutionState(serverHandle, processName, processStatus,
717 * bos_ProcessExecutionStateSetTemporary - set the execution state of a process
722 * IN serverHandle - a previously opened serverHandle.
724 * IN processName - the name of the process to modify.
726 * IN processStatus - the new process state.
730 * No locks are obtained or released by this function
734 * Returns != 0 upon successful completion.
737 int ADMINAPI bos_ProcessExecutionStateSetTemporary(
738 const void *serverHandle,
739 const char *processName,
740 bos_ProcessExecutionState_t processStatus,
743 return SetExecutionState(serverHandle, processName, processStatus,
744 BOZO_SetTStatus, st);
748 * The iterator functions and data for the process name retrieval functions
751 typedef struct process_name_get {
753 struct rx_connection *server;
754 char process[CACHED_ITEMS][BOS_MAX_NAME_LEN];
755 } process_name_get_t, *process_name_get_p;
757 static int GetProcessNameRPC(
761 int *last_item_contains_data,
765 afs_status_t tst = 0;
766 process_name_get_p proc = (process_name_get_p) rpc_specific;
767 char *ptr = (char *) &proc->process[slot];
769 tst = BOZO_EnumerateInstance(proc->server, proc->next++, &ptr);
773 } else if (tst == BZDOM) {
777 *last_item_contains_data = 0;
786 static int GetProcessNameFromCache(
793 afs_status_t tst = 0;
794 process_name_get_p proc = (process_name_get_p) rpc_specific;
796 strcpy((char *) dest, (char *) &proc->process[slot]);
806 * bos_ProcessNameGetBegin - begin iterating over the list of processes
807 * at a particular bos server.
811 * IN serverHandle - a previously opened serverHandle.
813 * OUT iter - an iterator that can be passed to bos_ProcessNameGetNext
814 * to retrieve the process names.
818 * No locks are obtained or released by this function
822 * Returns != 0 upon successful completion.
826 int ADMINAPI bos_ProcessNameGetBegin(
827 const void *serverHandle,
832 afs_status_t tst = 0;
833 bos_server_p b_handle = (bos_server_p) serverHandle;
834 afs_admin_iterator_p iter = (afs_admin_iterator_p) malloc(sizeof(afs_admin_iterator_t));
835 process_name_get_p proc = (process_name_get_p) malloc(sizeof(process_name_get_t));
837 if (!isValidServerHandle(b_handle, &tst)) {
838 goto fail_bos_ProcessNameGetBegin;
841 if (iterationIdP == NULL) {
842 tst = ADMITERATIONIDPNULL;
843 goto fail_bos_ProcessNameGetBegin;
846 if ((iter == NULL) || (proc == NULL)) {
848 goto fail_bos_ProcessNameGetBegin;
852 proc->server = b_handle->server;
854 if (IteratorInit(iter, (void *) proc, GetProcessNameRPC, GetProcessNameFromCache, NULL, NULL, &tst)) {
855 *iterationIdP = (void *) iter;
857 goto fail_bos_ProcessNameGetBegin;
861 fail_bos_ProcessNameGetBegin:
879 * bos_ProcessNameGetNext - retrieve the next process name from the bos server.
883 * IN iterationId - an iterator previously returned by bos_ProcessNameGetBegin
885 * OUT processName - upon successful completion contains the next process name
886 * retrieved from the server.
890 * No locks are obtained or released by this function
894 * Returns != 0 upon successful completion.
898 int ADMINAPI bos_ProcessNameGetNext(
899 const void *iterationId,
904 afs_status_t tst = 0;
905 afs_admin_iterator_p iter = (afs_admin_iterator_p) iterationId;
907 if (processName == NULL) {
908 tst = ADMBOSPROCESSNAMENULL;
909 goto fail_bos_ProcessNameGetNext;
912 if (iterationId == NULL) {
913 tst = ADMITERATIONIDPNULL;
914 goto fail_bos_ProcessNameGetNext;
917 rc = IteratorNext(iter, (void *) processName, &tst);
919 fail_bos_ProcessNameGetNext:
928 * bos_ProcessNameGetDone - finish using a process name iterator.
932 * IN iterationId - an iterator previously returned by bos_ProcessNameGetBegin
936 * No locks are obtained or released by this function
940 * Returns != 0 upon successful completion.
944 int ADMINAPI bos_ProcessNameGetDone(
945 const void *iterationId,
949 afs_status_t tst = 0;
950 afs_admin_iterator_p iter = (afs_admin_iterator_p) iterationId;
952 if (iterationId == NULL) {
953 tst = ADMITERATIONIDPNULL;
954 goto fail_bos_ProcessNameGetDone;
957 rc = IteratorDone(iter, &tst);
959 fail_bos_ProcessNameGetDone:
968 * bos_ProcessInfoGet - get information about a single process
972 * IN serverHandle - a previously opened serverHandle.
974 * IN processName - the process of interest.
976 * OUT processTypeP - upon successful completion contains the process type
978 * OUT processInfoP - upon successful completion contains the process info
982 * No locks are obtained or released by this function
986 * Returns != 0 upon successful completion.
990 int ADMINAPI bos_ProcessInfoGet(
991 const void *serverHandle,
992 const char *processName,
993 bos_ProcessType_p processTypeP,
994 bos_ProcessInfo_p processInfoP,
998 afs_status_t tst = 0;
999 bos_server_p b_handle = (bos_server_p) serverHandle;
1000 char type[BOS_MAX_NAME_LEN];
1002 struct bozo_status status;
1005 if (!isValidServerHandle(b_handle, &tst)) {
1006 goto fail_bos_ProcessInfoGet;
1009 if ((processName == NULL) || (*processName == 0)) {
1010 tst = ADMBOSPROCESSNAMENULL;
1011 goto fail_bos_ProcessInfoGet;
1014 if (processTypeP == NULL) {
1015 tst = ADMBOSPROCESSTYPEPNULL;
1016 goto fail_bos_ProcessInfoGet;
1019 if (processInfoP == NULL) {
1020 tst = ADMBOSPROCESSINFOPNULL;
1021 goto fail_bos_ProcessInfoGet;
1024 tst = BOZO_GetInstanceInfo(b_handle->server, processName, &ptr, &status);
1027 goto fail_bos_ProcessInfoGet;
1031 for(i=0;(processTypes[i] != NULL); i++) {
1032 if (!strcmp(processTypes[i], type)) {
1033 *processTypeP = (bos_ProcessType_t) i;
1038 if (processTypes[i] == NULL) {
1039 tst = ADMBOSINVALIDPROCESSTYPE;
1040 goto fail_bos_ProcessInfoGet;
1043 processInfoP->processGoal = (bos_ProcessExecutionState_t) status.goal;
1044 processInfoP->processStartTime = status.procStartTime;
1045 processInfoP->numberProcessStarts = status.procStarts;
1046 processInfoP->processExitTime = status.lastAnyExit;
1047 processInfoP->processExitErrorTime = status.lastErrorExit;
1048 processInfoP->processErrorCode = status.errorCode;
1049 processInfoP->processErrorSignal = status.errorSignal;
1050 processInfoP->state = BOS_PROCESS_OK;
1052 if (status.flags & BOZO_ERRORSTOP) {
1053 processInfoP->state |= BOS_PROCESS_TOO_MANY_ERRORS;
1055 if (status.flags & BOZO_HASCORE) {
1056 processInfoP->state |= BOS_PROCESS_CORE_DUMPED;
1058 if (status.flags & BOZO_BADDIRACCESS) {
1059 processInfoP->state |= BOS_PROCESS_BAD_FILE_ACCESS;
1063 fail_bos_ProcessInfoGet:
1072 * The iterator functions and data for the parameter retrieval functions
1075 typedef struct param_get {
1077 struct rx_connection *server;
1078 char processName[BOS_MAX_NAME_LEN];
1079 char param[CACHED_ITEMS][BOS_MAX_NAME_LEN];
1080 } param_get_t, *param_get_p;
1082 static int GetParameterRPC(
1086 int *last_item_contains_data,
1090 afs_status_t tst = 0;
1091 param_get_p param = (param_get_p) rpc_specific;
1092 char *ptr = (char *) ¶m->param[slot];
1094 tst = BOZO_GetInstanceParm(param->server, param->processName,
1095 param->next++, &ptr);
1099 } else if (tst == BZDOM) {
1103 *last_item_contains_data = 0;
1112 static int GetParameterFromCache(
1119 afs_status_t tst = 0;
1120 param_get_p param = (param_get_p) rpc_specific;
1122 strcpy((char *) dest, (char *) ¶m->param[slot]);
1132 * bos_ProcessParameterGetBegin - begin iterating over the parameters
1133 * of a particular process.
1137 * IN serverHandle - a previously opened serverHandle.
1139 * IN processName - the process whose parameters are returned.
1141 * OUT iter - an iterator that can be passed to bos_ProcessParameterGetNext
1142 * to retrieve the parameters.
1146 * No locks are obtained or released by this function
1150 * Returns != 0 upon successful completion.
1154 int ADMINAPI bos_ProcessParameterGetBegin(
1155 const void *serverHandle,
1156 const char *processName,
1157 void **iterationIdP,
1161 afs_status_t tst = 0;
1162 bos_server_p b_handle = (bos_server_p) serverHandle;
1163 afs_admin_iterator_p iter = (afs_admin_iterator_p) malloc(sizeof(afs_admin_iterator_t));
1164 param_get_p param = (param_get_p) malloc(sizeof(param_get_t));
1166 if (!isValidServerHandle(b_handle, &tst)) {
1167 goto fail_bos_ProcessParameterGetBegin;
1170 if ((processName == NULL) || (*processName == 0)) {
1171 tst = ADMBOSPROCESSNAMENULL;
1172 goto fail_bos_ProcessParameterGetBegin;
1175 if (iterationIdP == NULL) {
1176 tst = ADMITERATIONIDPNULL;
1177 goto fail_bos_ProcessParameterGetBegin;
1180 if ((iter == NULL) || (param == NULL)) {
1182 goto fail_bos_ProcessParameterGetBegin;
1186 param->server = b_handle->server;
1187 strcpy(param->processName, processName);
1189 if (IteratorInit(iter, (void *) param, GetParameterRPC,
1190 GetParameterFromCache, NULL, NULL, &tst)) {
1191 *iterationIdP = (void *) iter;
1193 goto fail_bos_ProcessParameterGetBegin;
1197 fail_bos_ProcessParameterGetBegin:
1203 if (param != NULL) {
1215 * bos_ProcessParameterGetNext - retrieve the next parameter
1216 * from the bos server.
1220 * IN iterationId - an iterator previously returned by
1221 * bos_ProcessParameterGetBegin
1223 * OUT parameter - upon successful completion contains the next parameter
1224 * retrieved from the server.
1228 * No locks are obtained or released by this function
1232 * Returns != 0 upon successful completion.
1236 int ADMINAPI bos_ProcessParameterGetNext(
1237 const void *iterationId,
1242 afs_status_t tst = 0;
1243 afs_admin_iterator_p iter = (afs_admin_iterator_p) iterationId;
1245 if (iterationId == NULL) {
1246 tst = ADMITERATIONIDPNULL;
1247 goto fail_bos_ProcessParameterGetNext;
1250 if (parameter == NULL) {
1251 tst = ADMBOSPARAMETERNULL;
1252 goto fail_bos_ProcessParameterGetNext;
1255 rc = IteratorNext(iter, (void *) parameter, &tst);
1257 fail_bos_ProcessParameterGetNext:
1266 * bos_ProcessParameterGetDone - finish using a process name iterator.
1270 * IN iterationId - an iterator previously returned by
1271 * bos_ProcessParameterGetBegin
1275 * No locks are obtained or released by this function
1279 * Returns != 0 upon successful completion.
1283 int ADMINAPI bos_ProcessParameterGetDone(
1284 const void *iterationId,
1288 afs_status_t tst = 0;
1289 afs_admin_iterator_p iter = (afs_admin_iterator_p) iterationId;
1291 if (iterationId == NULL) {
1292 tst = ADMITERATIONIDPNULL;
1293 goto fail_bos_ProcessParameterGetDone;
1296 rc = IteratorDone(iter, &tst);
1298 fail_bos_ProcessParameterGetDone:
1307 * bos_ProcessNotifierGet - retrieve the notifier associated with a
1312 * IN serverHandle - a previously opened serverHandle.
1314 * IN processName - the process whose notifier we are retrieving.
1316 * OUT notifier - upon successful completion contains the notifier.
1320 * No locks are obtained or released by this function
1324 * Returns != 0 upon successful completion.
1328 int ADMINAPI bos_ProcessNotifierGet(
1329 const void *serverHandle,
1330 const char *processName,
1335 afs_status_t tst = 0;
1336 bos_server_p b_handle = (bos_server_p) serverHandle;
1338 if (!isValidServerHandle(b_handle, &tst)) {
1339 goto fail_bos_ProcessNotifierGet;
1342 if ((processName == NULL) || (*processName == 0)) {
1343 tst = ADMBOSPROCESSNAMENULL;
1344 goto fail_bos_ProcessNotifierGet;
1347 if (notifier == NULL) {
1348 tst = ADMBOSNOTIFIERNULL;
1349 goto fail_bos_ProcessNotifierGet;
1352 tst = BOZO_GetInstanceParm(b_handle->server, processName, 999, ¬ifier);
1358 fail_bos_ProcessNotifierGet:
1367 * bos_ProcessRestart - restart a particular process.
1371 * IN serverHandle - a previously opened serverHandle.
1373 * IN processName - the process to restart
1377 * No locks are obtained or released by this function
1381 * Returns != 0 upon successful completion.
1385 int ADMINAPI bos_ProcessRestart(
1386 const void *serverHandle,
1387 const char *processName,
1391 afs_status_t tst = 0;
1392 bos_server_p b_handle = (bos_server_p) serverHandle;
1394 if (!isValidServerHandle(b_handle, &tst)) {
1395 goto fail_bos_ProcessRestart;
1398 if ((processName == NULL) || (*processName == 0)) {
1399 tst = ADMBOSPROCESSNAMENULL;
1400 goto fail_bos_ProcessRestart;
1403 tst = BOZO_Restart(b_handle->server, processName);
1409 fail_bos_ProcessRestart:
1418 * bos_ProcessAllStop - stop all running processes at a server.
1422 * IN serverHandle - a previously opened serverHandle.
1426 * No locks are obtained or released by this function
1430 * Returns != 0 upon successful completion.
1434 int ADMINAPI bos_ProcessAllStop(
1435 const void *serverHandle,
1439 afs_status_t tst = 0;
1440 bos_server_p b_handle = (bos_server_p) serverHandle;
1442 if (!isValidServerHandle(b_handle, &tst)) {
1443 goto fail_bos_ProcessAllStop;
1446 tst = BOZO_ShutdownAll(b_handle->server);
1452 fail_bos_ProcessAllStop:
1461 * bos_ProcessAllStart - start all processes that should be running at a
1466 * IN serverHandle - a previously opened serverHandle.
1470 * No locks are obtained or released by this function
1474 * Returns != 0 upon successful completion.
1478 int ADMINAPI bos_ProcessAllStart(
1479 const void *serverHandle,
1483 afs_status_t tst = 0;
1484 bos_server_p b_handle = (bos_server_p) serverHandle;
1486 if (!isValidServerHandle(b_handle, &tst)) {
1487 goto fail_bos_ProcessAllStart;
1490 tst = BOZO_StartupAll(b_handle->server);
1496 fail_bos_ProcessAllStart:
1505 * bos_ProcessAllWaitStop - stop all processes, and block until they have
1510 * IN serverHandle - a previously opened serverHandle.
1514 * No locks are obtained or released by this function
1518 * Returns != 0 upon successful completion.
1522 int ADMINAPI bos_ProcessAllWaitStop(
1523 const void *serverHandle,
1527 afs_status_t tst = 0;
1528 bos_server_p b_handle = (bos_server_p) serverHandle;
1530 if (!isValidServerHandle(b_handle, &tst)) {
1531 goto fail_bos_ProcessAllWaitStop;
1534 if (!bos_ProcessAllStop(serverHandle, &tst)) {
1535 goto fail_bos_ProcessAllWaitStop;
1538 tst = BOZO_WaitAll(b_handle->server);
1544 fail_bos_ProcessAllWaitStop:
1553 * bos_ProcessAllWaitTransition - block until all processes at the bosserver
1554 * have reached their desired state.
1558 * IN serverHandle - a previously opened serverHandle.
1562 * No locks are obtained or released by this function
1566 * Returns != 0 upon successful completion.
1570 int ADMINAPI bos_ProcessAllWaitTransition(
1571 const void *serverHandle,
1575 afs_status_t tst = 0;
1576 bos_server_p b_handle = (bos_server_p) serverHandle;
1578 if (!isValidServerHandle(b_handle, &tst)) {
1579 goto fail_bos_ProcessAllWaitTransition;
1582 tst = BOZO_WaitAll(b_handle->server);
1588 fail_bos_ProcessAllWaitTransition:
1597 * bos_ProcessAllStopAndRestart - stop all the running processes, restart
1598 * them, and optionally restart the bosserver itself.
1603 * IN serverHandle - a previously opened serverHandle.
1605 * IN restartBosServer - flag to indicate whether to restart bosserver.
1609 * No locks are obtained or released by this function
1613 * Returns != 0 upon successful completion.
1617 int ADMINAPI bos_ProcessAllStopAndRestart(
1618 const void *serverHandle,
1619 bos_RestartBosServer_t restartBosServer,
1623 afs_status_t tst = 0;
1624 bos_server_p b_handle = (bos_server_p) serverHandle;
1626 if (!isValidServerHandle(b_handle, &tst)) {
1627 goto fail_bos_ProcessAllStopAndRestart;
1630 if (restartBosServer == BOS_RESTART_BOS_SERVER) {
1631 tst = BOZO_ReBozo(b_handle->server);
1633 goto fail_bos_ProcessAllStopAndRestart;
1637 tst = BOZO_RestartAll(b_handle->server);
1643 fail_bos_ProcessAllStopAndRestart:
1652 * bos_AdminCreate - create a new admin.
1656 * IN serverHandle - a previously opened serverHandle.
1658 * IN adminName - the new admin name.
1662 * No locks are obtained or released by this function
1666 * Returns != 0 upon successful completion.
1670 int ADMINAPI bos_AdminCreate(
1671 const void *serverHandle,
1672 const char *adminName,
1676 afs_status_t tst = 0;
1677 bos_server_p b_handle = (bos_server_p) serverHandle;
1679 if (!isValidServerHandle(b_handle, &tst)) {
1680 goto fail_bos_AdminCreate;
1683 if ((adminName == NULL) || (*adminName == 0)) {
1684 tst = ADMBOSADMINNAMENULL;
1685 goto fail_bos_AdminCreate;
1688 tst = BOZO_AddSUser(b_handle->server, adminName);
1694 fail_bos_AdminCreate:
1703 * bos_AdminDelete - delete a new admin.
1707 * IN serverHandle - a previously opened serverHandle.
1709 * IN adminName - the admin name.
1713 * No locks are obtained or released by this function
1717 * Returns != 0 upon successful completion.
1721 int ADMINAPI bos_AdminDelete(
1722 const void *serverHandle,
1723 const char *adminName,
1727 afs_status_t tst = 0;
1728 bos_server_p b_handle = (bos_server_p) serverHandle;
1730 if (!isValidServerHandle(b_handle, &tst)) {
1731 goto fail_bos_AdminDelete;
1734 if ((adminName == NULL) || (*adminName == 0)) {
1735 tst = ADMBOSADMINNAMENULL;
1736 goto fail_bos_AdminDelete;
1739 tst = BOZO_DeleteSUser(b_handle->server, adminName);
1745 fail_bos_AdminDelete:
1754 * The iterator functions and data for the admin retrieval functions
1757 typedef struct admin_get {
1759 struct rx_connection *server;
1760 char admin[CACHED_ITEMS][BOS_MAX_NAME_LEN];
1761 } admin_get_t, *admin_get_p;
1763 static int GetAdminRPC(
1767 int *last_item_contains_data,
1771 afs_status_t tst = 0;
1772 admin_get_p admin = (admin_get_p) rpc_specific;
1773 char *ptr = (char *) &admin->admin[slot];
1775 tst = BOZO_ListSUsers(admin->server, admin->next++, &ptr);
1778 * There's no way to tell the difference between an rpc failure
1779 * and the end of the list, so we assume that any error means the
1786 *last_item_contains_data = 0;
1796 static int GetAdminFromCache(
1803 afs_status_t tst = 0;
1804 admin_get_p admin = (admin_get_p) rpc_specific;
1806 strcpy((char *) dest, (char *) &admin->admin[slot]);
1816 * bos_AdminGetBegin - begin iterating over the administrators.
1820 * IN serverHandle - a previously opened serverHandle.
1822 * OUT iter - an iterator that can be passed to bos_AdminGetBegin
1823 * to retrieve the administrators.
1827 * No locks are obtained or released by this function
1831 * Returns != 0 upon successful completion.
1835 int ADMINAPI bos_AdminGetBegin(
1836 const void *serverHandle,
1837 void **iterationIdP,
1841 afs_status_t tst = 0;
1842 bos_server_p b_handle = (bos_server_p) serverHandle;
1843 afs_admin_iterator_p iter = (afs_admin_iterator_p) malloc(sizeof(afs_admin_iterator_t));
1844 admin_get_p admin = (admin_get_p) malloc(sizeof(admin_get_t));
1846 if (!isValidServerHandle(b_handle, &tst)) {
1847 goto fail_bos_AdminGetBegin;
1850 if (iterationIdP == NULL) {
1851 tst = ADMITERATIONIDPNULL;
1852 goto fail_bos_AdminGetBegin;
1855 if ((iter == NULL) || (admin == NULL)) {
1857 goto fail_bos_AdminGetBegin;
1861 admin->server = b_handle->server;
1863 if (IteratorInit(iter, (void *) admin, GetAdminRPC,
1864 GetAdminFromCache, NULL, NULL, &tst)) {
1865 *iterationIdP = (void *) iter;
1869 fail_bos_AdminGetBegin:
1875 if (admin != NULL) {
1887 * bos_AdminGetNext - retrieve the next administrator
1888 * from the bos server.
1892 * IN iterationId - an iterator previously returned by
1895 * OUT adminName - upon successful completion contains the next administrator
1896 * retrieved from the server.
1900 * No locks are obtained or released by this function
1904 * Returns != 0 upon successful completion.
1908 int ADMINAPI bos_AdminGetNext(
1909 const void *iterationId,
1914 afs_status_t tst = 0;
1915 afs_admin_iterator_p iter = (afs_admin_iterator_p) iterationId;
1917 if (iterationId == NULL) {
1918 tst = ADMITERATIONIDPNULL;
1919 goto fail_bos_AdminGetNext;
1922 if (adminName == NULL) {
1923 tst = ADMBOSADMINNAMENULL;
1924 goto fail_bos_AdminGetNext;
1927 rc = IteratorNext(iter, (void *) adminName, &tst);
1929 fail_bos_AdminGetNext:
1938 * bos_AdminGetDone - finish using a administrator iterator.
1942 * IN iterationId - an iterator previously returned by
1947 * No locks are obtained or released by this function
1951 * Returns != 0 upon successful completion.
1955 int ADMINAPI bos_AdminGetDone(
1956 const void *iterationId,
1960 afs_status_t tst = 0;
1961 afs_admin_iterator_p iter = (afs_admin_iterator_p) iterationId;
1963 if (iterationId == NULL) {
1964 tst = ADMITERATIONIDPNULL;
1965 goto fail_bos_AdminGetDone;
1968 rc = IteratorDone(iter, &tst);
1970 fail_bos_AdminGetDone:
1979 * bos_KeyCreate - add a new key to the keyfile.
1983 * IN serverHandle - a previously opened serverHandle.
1985 * IN keyVersionNumber - the key version number.
1987 * IN key - the new key.
1991 * No locks are obtained or released by this function
1995 * Returns != 0 upon successful completion.
1999 int ADMINAPI bos_KeyCreate(
2000 const void *serverHandle,
2001 int keyVersionNumber,
2002 const kas_encryptionKey_p key,
2006 afs_status_t tst = 0;
2007 bos_server_p b_handle = (bos_server_p) serverHandle;
2009 if (!isValidServerHandle(b_handle, &tst)) {
2010 goto fail_bos_KeyCreate;
2014 tst = ADMBOSKEYNULL;
2015 goto fail_bos_KeyCreate;
2018 tst = BOZO_AddKey(b_handle->server_encrypt, keyVersionNumber, key);
2033 * bos_KeyDelete - delete an existing key from the keyfile.
2037 * IN serverHandle - a previously opened serverHandle.
2039 * IN keyVersionNumber - the key version number.
2043 * No locks are obtained or released by this function
2047 * Returns != 0 upon successful completion.
2051 int ADMINAPI bos_KeyDelete(
2052 const void *serverHandle,
2053 int keyVersionNumber,
2057 afs_status_t tst = 0;
2058 bos_server_p b_handle = (bos_server_p) serverHandle;
2060 if (!isValidServerHandle(b_handle, &tst)) {
2061 goto fail_bos_KeyDelete;
2064 tst = BOZO_DeleteKey(b_handle->server, keyVersionNumber);
2079 * The iterator functions and data for the key retrieval functions
2082 typedef struct key_get {
2084 struct rx_connection *server;
2085 bos_KeyInfo_t key[CACHED_ITEMS];
2086 } key_get_t, *key_get_p;
2088 static int GetKeyRPC(
2092 int *last_item_contains_data,
2096 afs_status_t tst = 0;
2097 key_get_p key = (key_get_p) rpc_specific;
2098 struct bozo_keyInfo keyInfo;
2100 tst = BOZO_ListKeys(key->server, key->next++,
2101 &key->key[slot].keyVersionNumber,
2102 &key->key[slot].key, &keyInfo);
2106 key->key[slot].keyStatus.lastModificationDate = keyInfo.mod_sec;
2107 key->key[slot].keyStatus.lastModificationMicroSeconds =
2109 key->key[slot].keyStatus.checkSum = keyInfo.keyCheckSum;
2111 } else if (tst == BZDOM) {
2115 *last_item_contains_data = 0;
2124 static int GetKeyFromCache(
2131 afs_status_t tst = 0;
2132 key_get_p key = (key_get_p) rpc_specific;
2134 memcpy(dest, &key->key[slot], sizeof(bos_KeyInfo_t));
2144 * bos_KeyGetBegin - begin iterating over the keys.
2148 * IN serverHandle - a previously opened serverHandle.
2150 * OUT iter - an iterator that can be passed to bos_KeyGetNext
2151 * to retrieve the keys.
2155 * No locks are obtained or released by this function
2159 * Returns != 0 upon successful completion.
2163 int ADMINAPI bos_KeyGetBegin(
2164 const void *serverHandle,
2165 void **iterationIdP,
2169 afs_status_t tst = 0;
2170 bos_server_p b_handle = (bos_server_p) serverHandle;
2171 afs_admin_iterator_p iter = (afs_admin_iterator_p) malloc(sizeof(afs_admin_iterator_t));
2172 key_get_p key = (key_get_p) malloc(sizeof(key_get_t));
2174 if (!isValidServerHandle(b_handle, &tst)) {
2175 goto fail_bos_KeyGetBegin;
2178 if (iterationIdP == NULL) {
2179 tst = ADMITERATIONIDPNULL;
2180 goto fail_bos_KeyGetBegin;
2183 if ((iter == NULL) || (key == NULL)) {
2185 goto fail_bos_KeyGetBegin;
2189 key->server = b_handle->server_encrypt;
2191 if (IteratorInit(iter, (void *) key, GetKeyRPC,
2192 GetKeyFromCache, NULL, NULL, &tst)) {
2193 *iterationIdP = (void *) iter;
2197 fail_bos_KeyGetBegin:
2215 * bos_KeyGetNext - retrieve the next key
2216 * from the bos server.
2220 * IN iterationId - an iterator previously returned by
2223 * OUT keyP - upon successful completion contains the next key
2224 * retrieved from the server.
2228 * No locks are obtained or released by this function
2232 * Returns != 0 upon successful completion.
2236 int ADMINAPI bos_KeyGetNext(
2237 const void *iterationId,
2242 afs_status_t tst = 0;
2243 afs_admin_iterator_p iter = (afs_admin_iterator_p) iterationId;
2245 if (iterationId == NULL) {
2246 tst = ADMITERATIONIDPNULL;
2247 goto fail_bos_KeyGetNext;
2251 tst = ADMBOSKEYPNULL;
2252 goto fail_bos_KeyGetNext;
2255 rc = IteratorNext(iter, (void *) keyP, &tst);
2257 fail_bos_KeyGetNext:
2266 * bos_KeyGetDone - finish using a key iterator.
2270 * IN iterationId - an iterator previously returned by
2275 * No locks are obtained or released by this function
2279 * Returns != 0 upon successful completion.
2283 int ADMINAPI bos_KeyGetDone(
2284 const void *iterationId,
2288 afs_status_t tst = 0;
2289 afs_admin_iterator_p iter = (afs_admin_iterator_p) iterationId;
2291 if (iterationId == NULL) {
2292 tst = ADMITERATIONIDPNULL;
2293 goto fail_bos_KeyGetDone;
2296 rc = IteratorDone(iter, &tst);
2298 fail_bos_KeyGetDone:
2307 * bos_CellSet - set the cell name at a bos server.
2311 * IN serverHandle - a previously opened serverHandle.
2313 * IN cellName - the new cell name.
2317 * No locks are obtained or released by this function
2321 * Returns != 0 upon successful completion.
2324 int ADMINAPI bos_CellSet(
2325 const void *serverHandle,
2326 const char *cellName,
2330 afs_status_t tst = 0;
2331 bos_server_p b_handle = (bos_server_p) serverHandle;
2333 if (!isValidServerHandle(b_handle, &tst)) {
2334 goto fail_bos_CellSet;
2337 if ((cellName == NULL) || (*cellName == 0)) {
2338 tst = ADMCLIENTCELLNAMENULL;
2339 goto fail_bos_CellSet;
2342 tst = BOZO_SetCellName(b_handle->server, cellName);
2357 * bos_CellGet - get the cell name at a bos server.
2361 * IN serverHandle - a previously opened serverHandle.
2363 * OUT cellName - the cell name.
2367 * No locks are obtained or released by this function
2371 * Returns != 0 upon successful completion.
2374 int ADMINAPI bos_CellGet(
2375 const void *serverHandle,
2380 afs_status_t tst = 0;
2381 bos_server_p b_handle = (bos_server_p) serverHandle;
2383 if (!isValidServerHandle(b_handle, &tst)) {
2384 goto fail_bos_CellGet;
2387 if (cellName == NULL) {
2388 tst = ADMCLIENTCELLNAMENULL;
2389 goto fail_bos_CellGet;
2392 tst = BOZO_GetCellName(b_handle->server, &cellName);
2407 * bos_HostCreate - add a new host to the cell.
2411 * IN serverHandle - a previously opened serverHandle.
2413 * IN hostName - the new host.
2417 * No locks are obtained or released by this function
2421 * Returns != 0 upon successful completion.
2424 int ADMINAPI bos_HostCreate(
2425 const void *serverHandle,
2426 const char *hostName,
2430 afs_status_t tst = 0;
2431 bos_server_p b_handle = (bos_server_p) serverHandle;
2433 if (!isValidServerHandle(b_handle, &tst)) {
2434 goto fail_bos_HostCreate;
2437 if ((hostName == NULL) || (*hostName == 0)) {
2438 tst = ADMBOSHOSTNAMENULL;
2439 goto fail_bos_HostCreate;
2442 tst = BOZO_AddCellHost(b_handle->server, hostName);
2448 fail_bos_HostCreate:
2457 * bos_HostDelete - delete a host from the cell.
2461 * IN serverHandle - a previously opened serverHandle.
2463 * IN hostName - the host.
2467 * No locks are obtained or released by this function
2471 * Returns != 0 upon successful completion.
2474 int ADMINAPI bos_HostDelete(
2475 const void *serverHandle,
2476 const char *hostName,
2480 afs_status_t tst = 0;
2481 bos_server_p b_handle = (bos_server_p) serverHandle;
2483 if (!isValidServerHandle(b_handle, &tst)) {
2484 goto fail_bos_HostDelete;
2487 if ((hostName == NULL) || (*hostName == 0)) {
2488 tst = ADMBOSHOSTNAMENULL;
2489 goto fail_bos_HostDelete;
2492 tst = BOZO_DeleteCellHost(b_handle->server, hostName);
2498 fail_bos_HostDelete:
2507 * The iterator functions and data for the host retrieval functions
2510 typedef struct host_get {
2512 struct rx_connection *server;
2513 char host[CACHED_ITEMS][BOS_MAX_NAME_LEN];
2514 } host_get_t, *host_get_p;
2516 static int GetHostRPC(
2520 int *last_item_contains_data,
2524 afs_status_t tst = 0;
2525 host_get_p host = (host_get_p) rpc_specific;
2526 char *ptr = (char *) &host->host[slot];
2528 tst = BOZO_GetCellHost(host->server, host->next++, &ptr);
2532 } else if (tst == BZDOM) {
2536 *last_item_contains_data = 0;
2545 static int GetHostFromCache(
2552 afs_status_t tst = 0;
2553 host_get_p host = (host_get_p) rpc_specific;
2555 strcpy((char *) dest, (char *) &host->host[slot]);
2565 * bos_HostGetBegin - begin iterating over the hosts in a cell
2566 * at a particular bos server.
2570 * IN serverHandle - a previously opened serverHandle.
2572 * OUT iter - an iterator that can be passed to bos_HostGetNext
2573 * to retrieve the process names.
2577 * No locks are obtained or released by this function
2581 * Returns != 0 upon successful completion.
2585 int ADMINAPI bos_HostGetBegin(
2586 const void *serverHandle,
2587 void **iterationIdP,
2591 afs_status_t tst = 0;
2592 bos_server_p b_handle = (bos_server_p) serverHandle;
2593 afs_admin_iterator_p iter = (afs_admin_iterator_p) malloc(sizeof(afs_admin_iterator_t));
2594 host_get_p host = (host_get_p) malloc(sizeof(host_get_t));
2596 if (!isValidServerHandle(b_handle, &tst)) {
2597 goto fail_bos_HostGetBegin;
2600 if (iterationIdP == NULL) {
2601 tst = ADMITERATIONIDPNULL;
2602 goto fail_bos_HostGetBegin;
2605 if ((iter == NULL) || (host == NULL)) {
2607 goto fail_bos_HostGetBegin;
2611 host->server = b_handle->server;
2613 if (IteratorInit(iter, (void *) host, GetHostRPC,
2614 GetHostFromCache, NULL, NULL, &tst)) {
2615 *iterationIdP = (void *) iter;
2619 fail_bos_HostGetBegin:
2637 * bos_HostGetNext - retrieve the next host
2638 * from the bos server.
2642 * IN iterationId - an iterator previously returned by
2645 * OUT hostName - upon successful completion contains the next host
2646 * retrieved from the server.
2650 * No locks are obtained or released by this function
2654 * Returns != 0 upon successful completion.
2658 int ADMINAPI bos_HostGetNext(
2659 const void *iterationId,
2664 afs_status_t tst = 0;
2665 afs_admin_iterator_p iter = (afs_admin_iterator_p) iterationId;
2667 if (iterationId == NULL) {
2668 tst = ADMITERATIONIDPNULL;
2669 goto fail_bos_HostGetNext;
2672 if (hostName == NULL) {
2673 tst = ADMBOSHOSTNAMENULL;
2674 goto fail_bos_HostGetNext;
2677 rc = IteratorNext(iter, (void *) hostName, &tst);
2679 fail_bos_HostGetNext:
2688 * bos_HostGetDone - finish using a host iterator.
2692 * IN iterationId - an iterator previously returned by
2697 * No locks are obtained or released by this function
2701 * Returns != 0 upon successful completion.
2705 int ADMINAPI bos_HostGetDone(
2706 const void *iterationId,
2710 afs_status_t tst = 0;
2711 afs_admin_iterator_p iter = (afs_admin_iterator_p) iterationId;
2713 if (iterationId == NULL) {
2714 tst = ADMITERATIONIDPNULL;
2715 goto fail_bos_HostGetDone;
2718 rc = IteratorDone(iter, &tst);
2720 fail_bos_HostGetDone:
2729 * bos_ExecutableCreate - create a new executable at the bos server.
2733 * IN serverHandle - a previously opened serverHandle.
2735 * IN sourceFile - the executable to install at the bos server.
2737 * IN destFile - the location where the executable will be installed.
2741 * No locks are obtained or released by this function
2745 * Returns != 0 upon successful completion.
2749 int ADMINAPI bos_ExecutableCreate(
2750 const void *serverHandle,
2751 const char *sourceFile,
2752 const char *destFile,
2756 afs_status_t tst = 0;
2757 bos_server_p b_handle = (bos_server_p) serverHandle;
2760 struct rx_call *tcall;
2763 * Validate arguments
2766 if (!isValidServerHandle(b_handle, &tst)) {
2767 goto fail_bos_ExecutableCreate;
2770 if ((sourceFile == NULL) || (*sourceFile == 0)) {
2771 tst = ADMBOSSOURCEFILENULL;
2772 goto fail_bos_ExecutableCreate;
2775 if ((destFile == NULL) || (*destFile == 0)) {
2776 tst = ADMBOSDESTFILENULL;
2777 goto fail_bos_ExecutableCreate;
2781 * Open the file locally and compute its size
2784 fd = open(sourceFile, O_RDONLY);
2787 tst = ADMBOSCANTOPENSOURCEFILE;
2788 goto fail_bos_ExecutableCreate;
2791 if (fstat(fd, &estat)) {
2792 tst = ADMBOSCANTSTATSOURCEFILE;
2793 goto fail_bos_ExecutableCreate;
2797 * Start a split rpc to the bos server.
2800 tcall = rx_NewCall(b_handle->server);
2802 tst = StartBOZO_Install(tcall, destFile, estat.st_size,
2803 (afs_int32) estat.st_mode, estat.st_mtime);
2806 rx_EndCall(tcall, tst);
2807 goto fail_bos_ExecutableCreate;
2811 * Copy the data to the server
2817 len = read(fd, tbuffer, sizeof(tbuffer));
2819 tst = ADMBOSCANTREADSOURCEFILE;
2820 rx_EndCall(tcall, len);
2821 goto fail_bos_ExecutableCreate;
2827 tst = rx_Write(tcall, tbuffer, len);
2829 tst = ADMBOSSENDSOURCEFILE;
2830 rx_EndCall(tcall, tst);
2831 goto fail_bos_ExecutableCreate;
2836 * Terminate the rpc to the server
2839 tst = rx_EndCall(tcall, tst);
2845 fail_bos_ExecutableCreate:
2854 * bos_ExecutableRevert - revert an executable to a previous .BAK version.
2858 * IN serverHandle - a previously opened serverHandle.
2860 * IN execFile - the executable to revert at the bos server.
2864 * No locks are obtained or released by this function
2868 * Returns != 0 upon successful completion.
2872 int ADMINAPI bos_ExecutableRevert(
2873 const void *serverHandle,
2874 const char *execFile,
2878 afs_status_t tst = 0;
2879 bos_server_p b_handle = (bos_server_p) serverHandle;
2881 if (!isValidServerHandle(b_handle, &tst)) {
2882 goto fail_bos_ExecutableRevert;
2885 if ((execFile == NULL) || (*execFile == 0)) {
2886 tst = ADMBOSEXECFILENULL;
2887 goto fail_bos_ExecutableRevert;
2890 tst = BOZO_UnInstall(b_handle->server, execFile);
2896 fail_bos_ExecutableRevert:
2905 * bos_ExecutableTimestampGet - get the last mod times for an executable,
2906 * the .BAK version of the executable, and the .OLD version of the
2907 * executable if they exist.
2911 * IN serverHandle - a previously opened serverHandle.
2913 * IN execFile - the executable to revert at the bos server.
2917 * No locks are obtained or released by this function
2921 * Returns != 0 upon successful completion.
2925 int ADMINAPI bos_ExecutableTimestampGet(
2926 const void *serverHandle,
2927 const char *execFile,
2928 unsigned long *newTime,
2929 unsigned long *oldTime,
2930 unsigned long *bakTime,
2934 afs_status_t tst = 0;
2935 bos_server_p b_handle = (bos_server_p) serverHandle;
2937 if (!isValidServerHandle(b_handle, &tst)) {
2938 goto fail_bos_ExecutableTimestampGet;
2941 if ((execFile == NULL) || (*execFile == 0)) {
2942 tst = ADMBOSEXECFILENULL;
2943 goto fail_bos_ExecutableTimestampGet;
2946 if (newTime == NULL) {
2947 tst = ADMBOSNEWTIMENULL;
2948 goto fail_bos_ExecutableTimestampGet;
2951 if (oldTime == NULL) {
2952 tst = ADMBOSOLDTIMENULL;
2953 goto fail_bos_ExecutableTimestampGet;
2956 if (bakTime == NULL) {
2957 tst = ADMBOSBAKTIMENULL;
2958 goto fail_bos_ExecutableTimestampGet;
2961 tst = BOZO_GetDates(b_handle->server, execFile, newTime, bakTime, oldTime);
2967 fail_bos_ExecutableTimestampGet:
2976 * bos_ExecutablePrune - prune the bak, old, and core files off a server
2981 * IN serverHandle - a previously opened serverHandle.
2983 * IN oldFiles - prune .OLD files.
2985 * IN bakFiles - prune .BAK files.
2987 * IN coreFiles - prune core files.
2991 * No locks are obtained or released by this function
2995 * Returns != 0 upon successful completion.
2999 int ADMINAPI bos_ExecutablePrune(
3000 const void *serverHandle,
3001 bos_Prune_t oldFiles,
3002 bos_Prune_t bakFiles,
3003 bos_Prune_t coreFiles,
3007 afs_status_t tst = 0;
3008 bos_server_p b_handle = (bos_server_p) serverHandle;
3009 afs_int32 flags = 0;
3011 if (!isValidServerHandle(b_handle, &tst)) {
3012 goto fail_bos_ExecutablePrune;
3015 if (oldFiles == BOS_PRUNE) {
3016 flags |= BOZO_PRUNEOLD;
3019 if (bakFiles == BOS_PRUNE) {
3020 flags |= BOZO_PRUNEBAK;
3023 if (coreFiles == BOS_PRUNE) {
3024 flags |= BOZO_PRUNECORE;
3027 tst = BOZO_Prune(b_handle->server, flags);
3033 fail_bos_ExecutablePrune:
3042 * bos_ExecutableRestartTimeSet - set the restart time of the bos server
3047 * IN serverHandle - a previously opened serverHandle.
3049 * IN type - specifies either weekly restart or daily restart time.
3051 * IN time - the time to begin restarts.
3055 * No locks are obtained or released by this function
3059 * Returns != 0 upon successful completion.
3063 int ADMINAPI bos_ExecutableRestartTimeSet(
3064 const void *serverHandle,
3066 bos_RestartTime_t time,
3070 afs_status_t tst = 0;
3071 bos_server_p b_handle = (bos_server_p) serverHandle;
3072 afs_int32 restartType = 0;
3073 struct ktime restartTime;
3075 if (!isValidServerHandle(b_handle, &tst)) {
3076 goto fail_bos_ExecutableRestartTimeSet;
3079 if (type == BOS_RESTART_WEEKLY) {
3085 if ((time.mask & BOS_RESTART_TIME_HOUR) &&
3086 ((time.hour < 0) || (time.hour > 23))) {
3087 tst = ADMBOSHOURINVALID;
3088 goto fail_bos_ExecutableRestartTimeSet;
3091 if ((time.mask & BOS_RESTART_TIME_MINUTE) &&
3092 ((time.min < 0) || (time.min > 60))) {
3093 tst = ADMBOSMINUTEINVALID;
3094 goto fail_bos_ExecutableRestartTimeSet;
3097 if ((time.mask & BOS_RESTART_TIME_SECOND) &&
3098 ((time.sec < 0) || (time.sec > 60))) {
3099 tst = ADMBOSSECONDINVALID;
3100 goto fail_bos_ExecutableRestartTimeSet;
3103 if ((time.mask & BOS_RESTART_TIME_DAY) &&
3104 ((time.day < 0) || (time.day > 6))) {
3105 tst = ADMBOSDAYINVALID;
3106 goto fail_bos_ExecutableRestartTimeSet;
3109 restartTime.mask = time.mask;
3110 restartTime.hour = time.hour;
3111 restartTime.min = time.min;
3112 restartTime.sec = time.sec;
3113 restartTime.day = time.day;
3115 tst = BOZO_SetRestartTime(b_handle->server, restartType, &restartTime);
3121 fail_bos_ExecutableRestartTimeSet:
3130 * bos_ExecutableRestartTimeGet - get the restart time of the bos server
3135 * IN serverHandle - a previously opened serverHandle.
3137 * IN type - specifies either weekly restart or daily restart time.
3139 * OUT timeP - the time to begin restarts.
3143 * No locks are obtained or released by this function
3147 * Returns != 0 upon successful completion.
3151 int ADMINAPI bos_ExecutableRestartTimeGet(
3152 const void *serverHandle,
3154 bos_RestartTime_p timeP,
3158 afs_status_t tst = 0;
3159 bos_server_p b_handle = (bos_server_p) serverHandle;
3160 afs_int32 restartType = 0;
3161 struct ktime restartTime;
3163 if (!isValidServerHandle(b_handle, &tst)) {
3164 goto fail_bos_ExecutableRestartTimeGet;
3167 if (timeP == NULL) {
3168 tst = ADMBOSTIMEPNULL;
3169 goto fail_bos_ExecutableRestartTimeGet;
3172 if (type == BOS_RESTART_WEEKLY) {
3178 tst = BOZO_GetRestartTime(b_handle->server, restartType, &restartTime);
3181 goto fail_bos_ExecutableRestartTimeGet;
3184 timeP->mask = restartTime.mask;
3185 timeP->hour = restartTime.hour;
3186 timeP->min = restartTime.min;
3187 timeP->sec = restartTime.sec;
3188 timeP->day = restartTime.day;
3191 fail_bos_ExecutableRestartTimeGet:
3200 * bos_LogGet - get a log file from the bos server machine.
3204 * IN serverHandle - a previously opened serverHandle.
3206 * IN log - the log file to retrieve.
3208 * IN/OUT logBufferSizeP - the length of the logData buffer on input,
3209 * and upon successful completion, the length of data stored in the buffer.
3211 * OUT logData - the retrieved data upon successful completion.
3215 * No locks are obtained or released by this function
3219 * Returns != 0 upon successful completion.
3223 int ADMINAPI bos_LogGet(
3224 const void *serverHandle,
3226 unsigned long *logBufferSizeP,
3231 afs_status_t tst = 0;
3232 bos_server_p b_handle = (bos_server_p) serverHandle;
3233 struct rx_call *tcall = NULL;
3237 unsigned long bytes_read = 0;
3240 * Validate parameters
3243 if (!isValidServerHandle(b_handle, &tst)) {
3244 goto fail_bos_LogGet;
3247 if ((log == NULL) || (*log == 0)) {
3248 tst = ADMBOSLOGNULL;
3249 goto fail_bos_LogGet;
3252 if (logBufferSizeP == NULL) {
3253 tst = ADMBOSLOGBUFFERSIZEPNULL;
3254 goto fail_bos_LogGet;
3257 if (logData == NULL) {
3258 tst = ADMBOSLOGDATANULL;
3259 goto fail_bos_LogGet;
3263 * Begin to retrieve the data
3266 tcall = rx_NewCall(b_handle->server);
3268 tst = StartBOZO_GetLog(tcall, log);
3271 goto fail_bos_LogGet;
3275 * Read the log file data
3279 error = rx_Read(tcall, &buffer, 1);
3281 tst = ADMBOSLOGFILEERROR;
3282 goto fail_bos_LogGet;
3286 * check for the end of the log
3290 *logBufferSizeP = bytes_read;
3295 * We've successfully read another byte, copy it to logData
3300 if (bytes_read <= *logBufferSizeP) {
3301 *logData++ = buffer;
3313 rx_EndCall(tcall, 0);
3323 * bos_AuthSet - set the authorization level required at the bos server.
3327 * IN serverHandle - a previously opened serverHandle.
3329 * IN auth - specifies the new auth level.
3333 * No locks are obtained or released by this function
3337 * Returns != 0 upon successful completion.
3341 int ADMINAPI bos_AuthSet(
3342 const void *serverHandle,
3347 afs_status_t tst = 0;
3348 bos_server_p b_handle = (bos_server_p) serverHandle;
3349 afs_int32 level = 0;
3351 if (!isValidServerHandle(b_handle, &tst)) {
3352 goto fail_bos_AuthSet;
3355 if (auth == BOS_AUTH_REQUIRED) {
3361 tst = BOZO_SetNoAuthFlag(b_handle->server, level);
3376 * bos_CommandExecute - execute a command at the bos server.
3380 * IN serverHandle - a previously opened serverHandle.
3382 * IN command - the command to execute.
3386 * No locks are obtained or released by this function
3390 * Returns != 0 upon successful completion.
3394 int ADMINAPI bos_CommandExecute(
3395 const void *serverHandle,
3396 const char *command,
3400 afs_status_t tst = 0;
3401 bos_server_p b_handle = (bos_server_p) serverHandle;
3403 if (!isValidServerHandle(b_handle, &tst)) {
3404 goto fail_bos_CommandExecute;
3407 if ((command == NULL) || (*command == 0)) {
3408 tst = ADMBOSCOMMANDNULL;
3409 goto fail_bos_CommandExecute;
3412 tst = BOZO_Exec(b_handle->server, command);
3418 fail_bos_CommandExecute:
3427 * bos_Salvage - perform a remote salvage operation.
3431 * IN cellHandle - a previously opened cellHandle.
3433 * IN serverHandle - a previously opened serverHandle.
3435 * IN partitionName - the partition to salvage. Can be null.
3437 * IN volumeName - the volume to salvage. Can be null, if non-null,
3438 * partitionName cannot be null.
3440 * IN numSalvagers - the number of salvage processes to run in parallel.
3442 * IN tmpDir - directory to place temporary files. Can be null.
3444 * IN logFile - file where salvage log will be written. Can be null.
3446 * IN force - sets salvager -force flag.
3448 * IN salvageDamagedVolumes - sets salvager -oktozap flag.
3450 * IN writeInodes - sets salvager -inodes flag.
3452 * IN writeRootInodes - sets salvager -rootinodes flag.
3454 * IN forceDirectory - sets salvager -salvagedirs flag.
3456 * IN forceBlockRead - sets salvager -blockread flag.
3460 * No locks are obtained or released by this function
3464 * Returns != 0 upon successful completion.
3468 #define INITIAL_LOG_LEN 4096
3470 int ADMINAPI bos_Salvage(
3471 const void *cellHandle,
3472 const void *serverHandle,
3473 const char *partitionName,
3474 const char *volumeName,
3477 const char *logFile,
3479 bos_SalvageDamagedVolumes_t salvageDamagedVolumes,
3480 bos_WriteInodes_t writeInodes,
3481 bos_WriteRootInodes_t writeRootInodes,
3482 bos_ForceDirectory_t forceDirectory,
3483 bos_ForceBlockRead_t forceBlockRead,
3487 afs_status_t tst = 0;
3488 bos_server_p b_handle = (bos_server_p) serverHandle;
3489 afs_cell_handle_p c_handle = (afs_cell_handle_p) cellHandle;
3490 int have_partition = 0;
3491 int have_volume = 0;
3492 unsigned int part = 0;
3493 int try_to_stop_fileserver = 0;
3494 bos_ProcessType_t procType;
3495 bos_ProcessInfo_t procInfo;
3497 char command[BOS_MAX_NAME_LEN];
3498 int command_len = 0;
3500 char *logData = NULL;
3501 unsigned long logLen = INITIAL_LOG_LEN;
3504 * Validate arguments
3507 if (!IsValidCellHandle(c_handle, &tst)) {
3508 goto fail_bos_Salvage;
3511 if (!isValidServerHandle(b_handle, &tst)) {
3512 goto fail_bos_Salvage;
3515 if (c_handle->vos_valid == 0) {
3516 tst = ADMBOSCELLHANDLENOVOS;
3517 goto fail_bos_Salvage;
3520 if ((partitionName != NULL) && (*partitionName != 0)) {
3521 if (!vos_PartitionNameToId(partitionName, &part, &tst)) {
3522 goto fail_bos_Salvage;
3527 if ((volumeName != NULL) && (*volumeName != 0)) {
3528 if (!have_partition) {
3529 tst = ADMBOSSALVAGEVOLUME;
3530 goto fail_bos_Salvage;
3535 if ((logFile != NULL) && (*logFile != 0)) {
3536 log = fopen(logFile, "w");
3538 tst = ADMBOSSALVAGEBADLOG;
3539 goto fail_bos_Salvage;
3544 * If we are salvaging more than a single volume, stop the fileserver
3548 try_to_stop_fileserver = 1;
3552 * Only try to stop the fileserver if it is running
3555 if (try_to_stop_fileserver) {
3556 if (bos_ProcessInfoGet(serverHandle, "fs", &procType, &procInfo,
3558 if (procInfo.processGoal != BOS_PROCESS_RUNNING) {
3559 try_to_stop_fileserver = 0;
3565 * Make the call to stop the fileserver and wait for it to shutdown
3568 if (try_to_stop_fileserver) {
3569 if (!bos_ProcessExecutionStateSetTemporary(serverHandle, "fs",
3570 BOS_PROCESS_STOPPED,
3572 goto fail_bos_Salvage;
3574 bos_ProcessAllWaitTransition(serverHandle, &tst);
3578 * Create the salvage command line arguments
3581 command_len = sprintf(command, "%s ",
3582 AFSDIR_CANONICAL_SERVER_SALVAGER_FILEPATH);
3583 if (have_partition) {
3584 command_len += sprintf(&command[command_len], "-partition %s ",
3589 command_len += sprintf(&command[command_len], "-volumeid %s ",
3593 if (salvageDamagedVolumes == BOS_DONT_SALVAGE_DAMAGED_VOLUMES) {
3594 command_len += sprintf(&command[command_len], "-nowrite ");
3597 if (writeInodes == BOS_SALVAGE_WRITE_INODES) {
3598 command_len += sprintf(&command[command_len], "-inodes ");
3601 if (force == VOS_FORCE) {
3602 command_len += sprintf(&command[command_len], "-force ");
3605 if (writeRootInodes == BOS_SALVAGE_WRITE_ROOT_INODES) {
3606 command_len += sprintf(&command[command_len], "-rootinodes ");
3609 if (forceDirectory == BOS_SALVAGE_FORCE_DIRECTORIES) {
3610 command_len += sprintf(&command[command_len], "-salvagedirs ");
3613 if (forceBlockRead == BOS_SALVAGE_FORCE_BLOCK_READS) {
3614 command_len += sprintf(&command[command_len], "-blockreads ");
3617 command_len += sprintf(&command[command_len], "-parallel %d ", numSalvagers);
3619 if ((tmpDir != NULL) && (*tmpDir != 0)) {
3620 command_len += sprintf(&command[command_len], "-tmpdir %s ", tmpDir);
3623 if (command_len > BOS_MAX_NAME_LEN) {
3624 tst = ADMBOSSALVAGEBADOPTIONS;
3625 goto fail_bos_Salvage;
3629 * Create the process at the bosserver and wait until it completes
3632 if (!bos_ProcessCreate(serverHandle, "salvage-tmp", BOS_PROCESS_CRON,
3633 command, "now", 0, &tst)) {
3634 goto fail_bos_Salvage;
3637 while ((poll_rc = bos_ProcessInfoGet(serverHandle, "salvage-tmp", &procType,
3638 &procInfo, &tst))) {
3642 if (tst != BZNOENT) {
3643 goto fail_bos_Salvage;
3647 * Print out the salvage log if required by the user
3652 logData = (char *) malloc(INITIAL_LOG_LEN);
3655 goto fail_bos_Salvage;
3658 while(!bos_LogGet(serverHandle,
3659 AFSDIR_CANONICAL_SERVER_SLVGLOG_FILEPATH,
3660 &logLen, logData, &tst)) {
3661 if (logLen > INITIAL_LOG_LEN) {
3662 logData = (char *) realloc(logData, (logLen + (logLen / 10)));
3663 if (logData == NULL) {
3665 goto fail_bos_Salvage;
3668 goto fail_bos_Salvage;
3671 fprintf(log, "SalvageLog:\n%s", logData);
3675 * Restart the fileserver if we had stopped it previously
3678 if (try_to_stop_fileserver) {
3679 try_to_stop_fileserver = 0;
3680 if (!bos_ProcessExecutionStateSetTemporary(serverHandle, "fs",
3681 BOS_PROCESS_RUNNING,
3683 goto fail_bos_Salvage;
3694 if (logData != NULL) {
3698 if (try_to_stop_fileserver) {
3699 bos_ProcessExecutionStateSetTemporary(serverHandle, "fs",
3700 BOS_PROCESS_RUNNING, 0);