2 * Copyright (c) 2001-2002 International Business Machines Corp.
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
9 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
10 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
11 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
12 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR
13 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
14 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
15 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
16 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
17 * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
18 * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
19 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
23 #include "org_openafs_jafs_Server.h"
25 #include <afs_clientAdmin.h>
26 #include <afs_vosAdmin.h>
27 #include <afs_bosAdmin.h>
28 #include <afs_AdminCommonErrors.h>
32 //// definitions in Internal.c //////////////////
34 extern jclass serverCls;
35 extern jfieldID server_nameField;
36 extern jfieldID server_nameField;
37 extern jfieldID server_databaseField;
38 extern jfieldID server_fileServerField;
39 extern jfieldID server_badDatabaseField;
40 extern jfieldID server_badFileServerField;
41 extern jfieldID server_IPAddressField;
43 extern jclass exectimeCls;
44 extern jfieldID exectime_HourField;
45 extern jfieldID exectime_MinField;
46 extern jfieldID exectime_SecField;
47 extern jfieldID exectime_DayField;
48 extern jfieldID exectime_NowField;
49 extern jfieldID exectime_NeverField;
51 extern jclass partitionCls;
52 extern jfieldID partition_cachedInfoField;
55 extern jfieldID key_cachedInfoField;
57 extern jclass processCls;
58 extern jfieldID process_cachedInfoField;
59 extern jfieldID process_nameField;
60 //extern jfieldID process_serverHandleField;
62 extern jclass userCls;
63 extern jfieldID user_nameField;
64 extern jfieldID user_cachedInfoField;
65 //////////////////////////////////////////////////////////
67 ///// definition in jafs_Partition.c /////////////////
69 extern void fillPartitionInfo(JNIEnv * env, jobject partition,
70 vos_partitionEntry_t partEntry);
72 ///////////////////////////////////////////////////
74 ///// definition in jafs_Key.c /////////////////
76 extern void fillKeyInfo(JNIEnv * env, jobject key, bos_KeyInfo_t keyEntry);
78 ///////////////////////////////////////////////////
80 ///// definition in jafs_Process.c /////////////////
82 extern void getProcessInfoChar(JNIEnv * env, void *serverHandle,
83 const char *processName, jobject process);
85 ///////////////////////////////////////////////////
88 * Extract the information from the given server entry and populate the
91 * env the Java environment
92 * cellHandle the handle of the cell to which the server belongs
93 * server the Server object to populate with the info
94 * servEntry the container of the server's information
97 fillServerInfo(JNIEnv * env, jint cellHandle, jobject server,
98 afs_serverEntry_t servEntry)
101 jobjectArray jaddresses;
105 // get the class fields if need be
106 if (serverCls == 0) {
107 internal_getServerClass(env, server);
109 // in case it's blank
110 jserver = (*env)->NewStringUTF(env, servEntry.serverName);
111 (*env)->SetObjectField(env, server, server_nameField, jserver);
113 // let's convert just the addresses in the address array into an IP
115 (jobjectArray) (*env)->GetObjectField(env, server,
116 server_IPAddressField);
117 for (i = 0; i < 16; i++) {
118 if (servEntry.serverAddress[i] != 0) {
119 jip = (*env)->NewStringUTF(env, (char *)
123 (*env)->SetObjectArrayElement(env, jaddresses, i, jip);
129 // let's check if this is really a database server
130 (*env)->SetBooleanField(env, server, server_databaseField,
131 servEntry.serverType & DATABASE_SERVER);
132 if (servEntry.serverType & DATABASE_SERVER) {
133 // for now, if it thinks it's a database server than it is
134 // later, add checks for database configuration, and actual
135 // on-ness of the machine
136 (*env)->SetBooleanField(env, server, server_badDatabaseField, FALSE);
138 (*env)->SetBooleanField(env, server, server_badDatabaseField, FALSE);
141 // we should check to see if this is truly a file server or not
142 // it could just be an old remnant, left over inside the vldb that
143 // should be removed.
144 // if it is a file server, mark it as such. If not, mark it as faulty.
145 (*env)->SetBooleanField(env, server, server_fileServerField,
146 servEntry.serverType & FILE_SERVER);
147 if (servEntry.serverType & FILE_SERVER) {
149 // to see if it's really a file server, make sure the
150 // "fs" process is running
153 bos_ProcessType_t processTypeT;
154 bos_ProcessInfo_t processInfoT;
155 char *fileServerProcessName = "fs";
157 // set the file server to true (it thinks it's a file server)
158 (*env)->SetBooleanField(env, server, server_fileServerField, TRUE);
161 ((void *)cellHandle, servEntry.serverName, &bosHandle, &ast)) {
162 throwAFSException(env, ast);
165 if (!bos_ProcessInfoGet
166 (bosHandle, fileServerProcessName, &processTypeT, &processInfoT,
168 // if the machine does not have a fs process or is not responding
169 // or is part of another cell
170 if (ast == BZNOENT || ast == -1 || ast == RXKADBADTICKET) {
171 (*env)->SetBooleanField(env, server,
172 server_badFileServerField, TRUE);
175 throwAFSException(env, ast);
180 (*env)->SetBooleanField(env, server, server_badFileServerField,
184 (*env)->SetBooleanField(env, server, server_badFileServerField,
191 * Fills in the information fields of the provided Server.
193 * env the Java environment
194 * cls the current Java class
195 * cellHandle the handle of the cell to which the server belongs
196 * jname the name of the server for which to get the information
197 * server the Server object in which to fill in
200 JNIEXPORT void JNICALL
201 Java_org_openafs_jafs_Server_getServerInfo(JNIEnv * env, jclass cls,
202 jint cellHandle, jstring jname,
207 afs_serverEntry_t servEntry;
210 name = getNativeString(env, jname);
212 throwAFSException(env, JAFSADMNOMEM);
216 throwAFSException(env, JAFSNULLSERVER);
220 // get the server entry
221 if (!afsclient_AFSServerGet((void *)cellHandle, name, &servEntry, &ast)) {
222 throwAFSException(env, ast);
225 fillServerInfo(env, cellHandle, server, servEntry);
231 * Returns the total number of partitions hosted by the server denoted by
232 * serverHandle, if the server is a fileserver.
234 * env the Java environment
235 * cls the current Java class
236 * cellHandle the handle of the cell to which the server belongs
237 * serverHandle the vos handle of the server to which the
239 * returns total number of partitions
241 JNIEXPORT jint JNICALL
242 Java_org_openafs_jafs_Server_getPartitionCount(JNIEnv * env, jclass cls,
248 vos_partitionEntry_t partEntry;
251 if (!vos_PartitionGetBegin
252 ((void *)cellHandle, (void *)serverHandle, NULL, &iterationId,
254 throwAFSException(env, ast);
258 while (vos_PartitionGetNext((void *)iterationId, &partEntry, &ast))
261 if (ast != ADMITERATORDONE) {
262 throwAFSException(env, ast);
270 * Begin the process of getting the partitions on a server. Returns
271 * an iteration ID to be used by subsequent calls to
272 * getPartitionsNext and getPartitionsDone.
274 * env the Java environment
275 * cls the current Java class
276 * cellHandle the handle of the cell to which the server belongs
277 * serverHandle the vos handle of the server to which the
279 * returns an iteration ID
281 JNIEXPORT jint JNICALL
282 Java_org_openafs_jafs_Server_getPartitionsBegin(JNIEnv * env, jclass cls,
289 if (!vos_PartitionGetBegin
290 ((void *)cellHandle, (void *)serverHandle, NULL, &iterationId,
292 throwAFSException(env, ast);
296 return (jint) iterationId;
301 * Returns the next partition of the server. Returns null
302 * if there are no more partitions.
304 * env the Java environment
305 * cls the current Java class
306 * iterationId the iteration ID of this iteration
307 * returns the name of the next partition of the server
309 JNIEXPORT jstring JNICALL
310 Java_org_openafs_jafs_Server_getPartitionsNextString(JNIEnv * env, jclass cls,
315 vos_partitionEntry_t partEntry;
317 if (!vos_PartitionGetNext((void *)iterationId, &partEntry, &ast)) {
318 if (ast == ADMITERATORDONE) {
321 throwAFSException(env, ast);
326 jpartition = (*env)->NewStringUTF(env, partEntry.name);
332 * Fills the next partition object of the server. Returns 0 if there
333 * are no more partitions, != 0 otherwise
335 * env the Java environment
336 * cls the current Java class
337 * iterationId the iteration ID of this iteration
338 * thePartition the Partition object in which to fill the
339 * values of the next partition
340 * returns 0 if there are no more servers, != 0 otherwise
342 JNIEXPORT jint JNICALL
343 Java_org_openafs_jafs_Server_getPartitionsNext(JNIEnv * env, jclass cls,
345 jobject jpartitionObject)
348 vos_partitionEntry_t partEntry;
350 if (!vos_PartitionGetNext((void *)iterationId, &partEntry, &ast)) {
351 if (ast == ADMITERATORDONE) {
354 throwAFSException(env, ast);
359 fillPartitionInfo(env, jpartitionObject, partEntry);
361 // get the class fields if need be
362 if (partitionCls == 0) {
363 internal_getPartitionClass(env, jpartitionObject);
365 (*env)->SetBooleanField(env, jpartitionObject, partition_cachedInfoField,
374 * Signals that the iteration is complete and will not be accessed anymore.
376 * env the Java environment
377 * cls the current Java class
378 * iterationId the iteration ID of this iteration
380 JNIEXPORT void JNICALL
381 Java_org_openafs_jafs_Server_getPartitionsDone(JNIEnv * env, jclass cls,
386 if (!vos_PartitionGetDone((void *)iterationId, &ast)) {
387 throwAFSException(env, ast);
394 * Adds the given to name to the list of bos administrators on that server.
396 * env the Java environment
397 * cls the current Java class
398 * serverHandle the bos handle of the server to which the
400 * jnewAdmin the name of the admin to add to the list
402 JNIEXPORT void JNICALL
403 Java_org_openafs_jafs_Server_addBosAdmin(JNIEnv * env, jclass cls,
404 jint serverHandle, jstring jnewAdmin)
409 if (jnewAdmin != NULL) {
410 newAdmin = getNativeString(env, jnewAdmin);
411 if (newAdmin == NULL) {
412 throwAFSException(env, JAFSADMNOMEM);
416 throwAFSException(env, JAFSNULLUSER);
420 if (!bos_AdminCreate((void *)serverHandle, newAdmin, &ast)) {
421 throwAFSException(env, ast);
429 * Removes the given to name from the list of bos administrators on
432 * env the Java environment
433 * cls the current Java class
434 * serverHandle the bos handle of the server to which the
436 * joldAdmin the name of the admin to remove from the list
438 JNIEXPORT void JNICALL
439 Java_org_openafs_jafs_Server_removeBosAdmin(JNIEnv * env, jclass cls,
446 if (joldAdmin != NULL) {
447 oldAdmin = getNativeString(env, joldAdmin);
448 if (oldAdmin == NULL) {
449 throwAFSException(env, JAFSADMNOMEM);
453 throwAFSException(env, JAFSNULLUSER);
457 if (!bos_AdminDelete((void *)serverHandle, oldAdmin, &ast)) {
458 throwAFSException(env, ast);
465 * Returns the total number of BOS administrators associated with the server
466 * denoted by serverHandle.
468 * env the Java environment
469 * cls the current Java class
470 * serverHandle the vos handle of the server to which the
472 * returns total number of BOS administrators
474 JNIEXPORT jint JNICALL
475 Java_org_openafs_jafs_Server_getBosAdminCount(JNIEnv * env, jclass cls,
484 if (!bos_AdminGetBegin((void *)serverHandle, &iterationId, &ast)) {
485 throwAFSException(env, ast);
489 admin = (char *)malloc(sizeof(char) * BOS_MAX_NAME_LEN);
492 throwAFSException(env, JAFSADMNOMEM);
496 while (bos_AdminGetNext((void *)iterationId, admin, &ast))
501 if (ast != ADMITERATORDONE) {
502 throwAFSException(env, ast);
510 * Begin the process of getting the bos amdinistrators on a server. Returns
511 * an iteration ID to be used by subsequent calls to
512 * getBosAdminsNext and getBosAdminsDone.
514 * env the Java environment
515 * cls the current Java class
516 * serverHandle the bos handle of the server to which the
518 * returns an iteration ID
520 JNIEXPORT jint JNICALL
521 Java_org_openafs_jafs_Server_getBosAdminsBegin(JNIEnv * env, jclass cls,
527 if (!bos_AdminGetBegin((void *)serverHandle, &iterationId, &ast)) {
528 throwAFSException(env, ast);
532 return (jint) iterationId;
536 * Returns the next bos admin of the server. Returns null
537 * if there are no more admins.
539 * env the Java environment
540 * cls the current Java class
541 * iterationId the iteration ID of this iteration
542 * returns the name of the next admin of the server
544 JNIEXPORT jstring JNICALL
545 Java_org_openafs_jafs_Server_getBosAdminsNextString(JNIEnv * env, jclass cls,
551 char *admin = (char *)malloc(sizeof(char) * BOS_MAX_NAME_LEN);
554 throwAFSException(env, JAFSADMNOMEM);
558 if (!bos_AdminGetNext((void *)iterationId, admin, &ast)) {
560 if (ast == ADMITERATORDONE) {
563 throwAFSException(env, ast);
568 jadmin = (*env)->NewStringUTF(env, admin);
575 * Returns the next bos admin of the server. Returns 0 if there
576 * are no more admins, != 0 otherwise.
578 * env the Java environment
579 * cls the current Java class
580 * cellHandle the handle of the cell to which these admins belong
581 * iterationId the iteration ID of this iteration
582 * juserObject the user object in which to fill the values of this admin
583 * returns 0 if no more admins, != 0 otherwise
585 JNIEXPORT jint JNICALL
586 Java_org_openafs_jafs_Server_getBosAdminsNext(JNIEnv * env, jclass cls,
595 admin = (char *)malloc(sizeof(char) * BOS_MAX_NAME_LEN);
598 throwAFSException(env, JAFSADMNOMEM);
602 if (!bos_AdminGetNext((void *)iterationId, admin, &ast)) {
604 if (ast == ADMITERATORDONE) {
607 throwAFSException(env, ast);
612 jadmin = (*env)->NewStringUTF(env, admin);
615 internal_getUserClass(env, juserObject);
618 (*env)->SetObjectField(env, juserObject, user_nameField, jadmin);
620 getUserInfoChar(env, cellHandle, admin, juserObject);
621 (*env)->SetBooleanField(env, juserObject, user_cachedInfoField, TRUE);
629 * Signals that the iteration is complete and will not be accessed anymore.
631 * env the Java environment
632 * cls the current Java class
633 * iterationId the iteration ID of this iteration
635 JNIEXPORT void JNICALL
636 Java_org_openafs_jafs_Server_getBosAdminsDone(JNIEnv * env, jclass cls,
641 if (!bos_AdminGetDone((void *)iterationId, &ast)) {
642 throwAFSException(env, ast);
648 * Returns the total number of keys hosted by the server denoted by
651 * env the Java environment
652 * cls the current Java class
653 * serverHandle the vos handle of the server to which the
655 * returns total number of keys
657 JNIEXPORT jint JNICALL
658 Java_org_openafs_jafs_Server_getKeyCount(JNIEnv * env, jclass cls,
663 bos_KeyInfo_t keyEntry;
666 if (!bos_KeyGetBegin((void *)serverHandle, &iterationId, &ast)) {
667 throwAFSException(env, ast);
671 while (bos_KeyGetNext((void *)iterationId, &keyEntry, &ast))
674 if (ast != ADMITERATORDONE) {
675 throwAFSException(env, ast);
683 * Begin the process of getting the keys of a server. Returns
684 * an iteration ID to be used by subsequent calls to
685 * getKeysNext and getKeysDone.
687 * env the Java environment
688 * cls the current Java class
689 * serverHandle the bos handle of the server to which the keys belong
690 * returns an iteration ID
692 JNIEXPORT jint JNICALL
693 Java_org_openafs_jafs_Server_getKeysBegin(JNIEnv * env, jclass cls,
699 if (!bos_KeyGetBegin((void *)serverHandle, &iterationId, &ast)) {
700 throwAFSException(env, ast);
704 return (jint) iterationId;
708 * Returns the next key of the server. Returns 0 if there
709 * are no more keys, != 0 otherwise.
711 * env the Java environment
712 * cls the current Java class
713 * iterationId the iteration ID of this iteration
714 * jkeyObject a Key object, in which to fill in the
715 * properties of the next key.
716 * returns 0 if there are no more keys, != 0 otherwise
718 JNIEXPORT jint JNICALL
719 Java_org_openafs_jafs_Server_getKeysNext(JNIEnv * env, jclass cls,
720 jint iterationId, jobject jkeyObject)
724 bos_KeyInfo_t keyEntry;
726 if (!bos_KeyGetNext((void *)iterationId, &keyEntry, &ast)) {
727 if (ast == ADMITERATORDONE) {
730 throwAFSException(env, ast);
735 fillKeyInfo(env, jkeyObject, keyEntry);
737 // get the class fields if need be
739 internal_getKeyClass(env, jkeyObject);
742 (*env)->SetBooleanField(env, jkeyObject, key_cachedInfoField, TRUE);
748 * Signals that the iteration is complete and will not be accessed anymore.
750 * env the Java environment
751 * cls the current Java class
752 * iterationId the iteration ID of this iteration
754 JNIEXPORT void JNICALL
755 Java_org_openafs_jafs_Server_getKeysDone(JNIEnv * env, jclass cls,
760 if (!bos_KeyGetDone((void *)iterationId, &ast)) {
761 throwAFSException(env, ast);
767 * Returns the total number of processes hosted by the server denoted by
770 * env the Java environment
771 * cls the current Java class
772 * serverHandle the vos handle of the server to which the
774 * returns total number of processes
776 JNIEXPORT jint JNICALL
777 Java_org_openafs_jafs_Server_getProcessCount(JNIEnv * env, jclass cls,
786 if (!bos_ProcessNameGetBegin((void *)serverHandle, &iterationId, &ast)) {
787 throwAFSException(env, ast);
791 process = (char *)malloc(sizeof(char) * BOS_MAX_NAME_LEN);
794 throwAFSException(env, JAFSADMNOMEM);
798 while (bos_ProcessNameGetNext((void *)iterationId, process, &ast))
803 if (ast != ADMITERATORDONE) {
804 throwAFSException(env, ast);
812 * Begin the process of getting the processes on a server. Returns
813 * an iteration ID to be used by subsequent calls to
814 * getProcessesNext and getProcessesDone.
816 * env the Java environment
817 * cls the current Java class
818 * serverHandle the bos handle of the server to which the
820 * returns an iteration ID
822 JNIEXPORT jint JNICALL
823 Java_org_openafs_jafs_Server_getProcessesBegin(JNIEnv * env, jclass cls,
829 if (!bos_ProcessNameGetBegin((void *)serverHandle, &iterationId, &ast)) {
830 throwAFSException(env, ast);
834 return (jint) iterationId;
838 * Returns the next process of the server. Returns null
839 * if there are no more processes.
841 * env the Java environment
842 * cls the current Java class
843 * iterationId the iteration ID of this iteration
844 * returns the name of the next process of the cell
846 JNIEXPORT jstring JNICALL
847 Java_org_openafs_jafs_Server_getProcessesNextString(JNIEnv * env, jclass cls,
852 char *process = (char *)malloc(sizeof(char) * BOS_MAX_NAME_LEN);
855 throwAFSException(env, JAFSADMNOMEM);
859 if (!bos_ProcessNameGetNext((void *)iterationId, process, &ast)) {
861 if (ast == ADMITERATORDONE) {
864 throwAFSException(env, ast);
869 jprocess = (*env)->NewStringUTF(env, process);
875 * Fills the next process object of the server. Returns 0 if there
876 * are no more processes, != 0 otherwise.
878 * env the Java environment
879 * cls the current Java class
880 * serverHandle the handle of the BOS server that hosts the process
881 * iterationId the iteration ID of this iteration
882 * jprocessObject the Process object in which to fill the
883 * values of the next process
884 * returns 0 if there are no more processes, != otherwise
886 JNIEXPORT jint JNICALL
887 Java_org_openafs_jafs_Server_getProcessesNext(JNIEnv * env, jclass cls,
890 jobject jprocessObject)
893 char *process = (char *)malloc(sizeof(char) * BOS_MAX_NAME_LEN);
897 throwAFSException(env, JAFSADMNOMEM);
901 if (!bos_ProcessNameGetNext((void *)iterationId, process, &ast)) {
903 if (ast == ADMITERATORDONE) {
906 throwAFSException(env, ast);
910 // get the class fields if need be
911 if (processCls == 0) {
912 internal_getProcessClass(env, jprocessObject);
915 jprocess = (*env)->NewStringUTF(env, process);
916 (*env)->SetObjectField(env, jprocessObject, process_nameField, jprocess);
918 getProcessInfoChar(env, (void *)serverHandle, process, jprocessObject);
920 (*env)->SetBooleanField(env, jprocessObject, process_cachedInfoField,
928 * Signals that the iteration is complete and will not be accessed anymore.
930 * env the Java environment
931 * cls the current Java class
932 * iterationId the iteration ID of this iteration
934 JNIEXPORT void JNICALL
935 Java_org_openafs_jafs_Server_getProcessesDone(JNIEnv * env, jclass cls,
940 if (!bos_ProcessNameGetDone((void *)iterationId, &ast)) {
941 throwAFSException(env, ast);
947 * Salvages (restores consistency to) a volume, partition, or server
949 * env the Java environment
950 * cls the current Java class
951 * cellHandle the handle of the cell to which the volume belongs
952 * serverHandle the bos handle of the server on which the
954 * jpartName the name of the partition to salvage,
955 * can be null only if volName is
957 * jvolName the name of the volume to salvage,
959 * numSalvagers the number of salvager processes to run in parallel
960 * jtempDir directory to place temporary files, can be
962 * jlogFile where salvager log will be written, can be
964 * inspectAllVolumes whether or not to inspect all volumes,
965 * not just those marked as active at crash
966 * removeBadlyDamaged whether or not to remove a volume if it's
968 * writeInodes whether or not to record a list of inodes modified
969 * writeRootInodes whether or not to record a list of AFS
970 * inodes owned by root
971 * forceDirectory whether or not to salvage an entire directory
973 * forceBlockReads whether or not to force the salvager to read
975 * one block at a time and skip badly damaged
976 * blocks. Use if partition has disk errors
978 JNIEXPORT void JNICALL
979 Java_org_openafs_jafs_Server_salvage(JNIEnv * env, jclass cls,
980 jint cellHandle, jint serverHandle,
981 jstring jpartName, jstring jvolName,
982 jint numSalvagers, jstring jtempDir,
984 jboolean inspectAllVolumes,
985 jboolean removeBadlyDamaged,
986 jboolean writeInodes,
987 jboolean writeRootInodes,
988 jboolean forceDirectory,
989 jboolean forceBlockReads)
997 bos_SalvageDamagedVolumes_t sdv;
998 bos_WriteInodes_t wi;
999 bos_WriteRootInodes_t wri;
1000 bos_ForceDirectory_t forceD;
1001 bos_ForceBlockRead_t forceBR;
1004 if (jpartName != NULL) {
1005 partName = getNativeString(env, jpartName);
1007 throwAFSException(env, JAFSADMNOMEM);
1014 if (jvolName != NULL) {
1015 volName = getNativeString(env, jvolName);
1017 if (partName != NULL)
1019 throwAFSException(env, JAFSADMNOMEM);
1026 if (jtempDir != NULL) {
1027 tempDir = getNativeString(env, jtempDir);
1029 if (partName != NULL)
1031 if (volName != NULL)
1033 throwAFSException(env, JAFSADMNOMEM);
1040 if (jlogFile != NULL) {
1041 logFile = getNativeString(env, jlogFile);
1043 if (partName != NULL)
1045 if (volName != NULL)
1047 if (tempDir != NULL)
1049 throwAFSException(env, JAFSADMNOMEM);
1056 // deal with booleans
1057 if (inspectAllVolumes) {
1062 if (removeBadlyDamaged) {
1063 sdv = BOS_DONT_SALVAGE_DAMAGED_VOLUMES;
1065 sdv = BOS_SALVAGE_DAMAGED_VOLUMES;
1068 wi = BOS_SALVAGE_WRITE_INODES;
1070 wi = BOS_SALVAGE_DONT_WRITE_INODES;
1072 if (writeRootInodes) {
1073 wri = BOS_SALVAGE_WRITE_ROOT_INODES;
1075 wri = BOS_SALVAGE_DONT_WRITE_ROOT_INODES;
1077 if (forceDirectory) {
1078 forceD = BOS_SALVAGE_FORCE_DIRECTORIES;
1080 forceD = BOS_SALVAGE_DONT_FORCE_DIRECTORIES;
1082 if (forceBlockReads) {
1083 forceBR = BOS_SALVAGE_FORCE_BLOCK_READS;
1085 forceBR = BOS_SALVAGE_DONT_FORCE_BLOCK_READS;
1090 ((void *)cellHandle, (void *)serverHandle, partName, volName,
1091 (int)numSalvagers, tempDir, logFile, force, sdv, wi, wri, forceD,
1093 throwAFSException(env, ast);
1096 if (partName != NULL)
1098 if (volName != NULL)
1100 if (tempDir != NULL)
1102 if (logFile != NULL)
1108 * Fills in the restart time fields of the given Server
1111 * env the Java environment
1112 * cls the current Java class
1113 * serverHandle the bos handle of the server to which the key belongs
1114 * jtype whether to get the general or binary restart.
1115 * Acceptable values are:
1116 * org_opemafs_jafs_Server_RESTART_BINARY
1117 * org_opemafs_jafs_Server_RESTART_GENERAL
1118 * execTime the ExecutableTime object, in which
1119 * to fill the restart time fields
1121 JNIEXPORT void JNICALL
1122 Java_org_openafs_jafs_Server_getRestartTime(JNIEnv * env, jclass cls,
1123 jint serverHandle, jint jtype,
1128 bos_RestartTime_t time;
1133 jfieldID neverField;
1136 // get the class fields if need be
1137 if (exectimeCls == 0) {
1138 internal_getExecTimeClass(env, exectime);
1141 if (jtype == org_openafs_jafs_Server_RESTART_BINARY) {
1142 type = BOS_RESTART_DAILY;
1144 type = BOS_RESTART_WEEKLY;
1147 hourField = exectime_HourField;
1148 minField = exectime_MinField;
1149 secField = exectime_SecField;
1150 dayField = exectime_DayField;
1151 neverField = exectime_NeverField;
1152 nowField = exectime_NowField;
1154 if (!bos_ExecutableRestartTimeGet
1155 ((void *)serverHandle, type, &time, &ast)) {
1156 throwAFSException(env, ast);
1160 (*env)->SetBooleanField(env, exectime, nowField,
1161 (time.mask & BOS_RESTART_TIME_NOW));
1164 (*env)->SetBooleanField(env, exectime, neverField,
1165 (time.mask & BOS_RESTART_TIME_NEVER));
1168 (*env)->SetShortField(env, exectime, hourField, time.hour);
1171 (*env)->SetShortField(env, exectime, minField, time.min);
1174 (*env)->SetShortField(env, exectime, secField, time.sec);
1177 if (time.mask & BOS_RESTART_TIME_DAY) {
1178 (*env)->SetShortField(env, exectime, dayField, time.day);
1180 (*env)->SetShortField(env, exectime, dayField, (jshort) - 1);
1186 * Sets the restart time of the bos server.
1188 * env the Java environment
1189 * cls the current Java class
1190 * serverHandle the bos handle of the server to which the key belongs
1191 * jtype whether this is to be a general or binary restart.
1192 * Acceptable values are:
1193 * org_opemafs_jafs_Server_RESTART_BINARY
1194 * org_opemafs_jafs_Server_RESTART_GENERAL
1195 * executableTime the ExecutableTime object containing the
1196 * desired information
1198 JNIEXPORT void JNICALL
1199 Java_org_openafs_jafs_Server_setRestartTime(JNIEnv * env, jclass cls,
1200 jint serverHandle, jint jtype,
1205 bos_RestartTime_t time;
1220 jfieldID neverField;
1223 // get the class fields if need be
1224 if (exectimeCls == 0) {
1225 internal_getExecTimeClass(env, exectime);
1228 if (jtype == org_openafs_jafs_Server_RESTART_BINARY) {
1229 type = BOS_RESTART_DAILY;
1231 type = BOS_RESTART_WEEKLY;
1234 hourField = exectime_HourField;
1235 minField = exectime_MinField;
1236 secField = exectime_SecField;
1237 dayField = exectime_DayField;
1238 neverField = exectime_NeverField;
1239 nowField = exectime_NowField;
1241 hour = (*env)->GetShortField(env, exectime, hourField);
1247 minute = (*env)->GetShortField(env, exectime, minField);
1253 second = (*env)->GetShortField(env, exectime, secField);
1259 day = (*env)->GetShortField(env, exectime, dayField);
1265 doNever = (*env)->GetBooleanField(env, exectime, neverField);
1266 doNow = (*env)->GetBooleanField(env, exectime, nowField);
1268 bzero(&time, sizeof(time));
1270 if (jtype == org_openafs_jafs_Server_RESTART_BINARY) {
1271 type = BOS_RESTART_DAILY;
1273 type = BOS_RESTART_WEEKLY;
1277 time.mask |= BOS_RESTART_TIME_HOUR;
1280 time.mask |= BOS_RESTART_TIME_MINUTE;
1283 time.mask |= BOS_RESTART_TIME_SECOND;
1286 time.mask |= BOS_RESTART_TIME_DAY;
1289 time.mask |= BOS_RESTART_TIME_NEVER;
1292 time.mask |= BOS_RESTART_TIME_NOW;
1300 if (!bos_ExecutableRestartTimeSet((void *)serverHandle, type, time, &ast)) {
1301 throwAFSException(env, ast);
1306 * Synchronizes a particular server with the volume location database.
1308 * env the Java environment
1309 * cls the current Java class
1310 * cellHandle the handle of the cell to which the server belongs
1311 * serverHandle the vos handle of the server
1312 * partition the id of the partition to sync, can be -1 to ignore
1314 JNIEXPORT void JNICALL
1315 Java_org_openafs_jafs_Server_syncServerWithVLDB(JNIEnv * env, jclass cls,
1323 if (partition == -1) {
1326 part = (int *)&partition;
1330 ((void *)cellHandle, (void *)serverHandle, NULL, part, &ast)) {
1331 throwAFSException(env, ast);
1336 * Synchronizes the volume location database with a particular server.
1338 * env the Java environment
1339 * cls the current Java class
1340 * cellHandle the handle of the cell to which the server belongs
1341 * serverHandle the vos handle of the server
1342 * partition the id of the partition to sync, can be -1 to ignore
1343 * forceDeletion whether or not to force the deletion of bad volumes
1345 JNIEXPORT void JNICALL
1346 Java_org_openafs_jafs_Server_syncVLDBWithServer(JNIEnv * env, jclass cls,
1350 jboolean forceDeletion)
1356 if (partition == -1) {
1359 part = (int *)&partition;
1362 if (forceDeletion) {
1369 ((void *)cellHandle, (void *)serverHandle, NULL, part, force, &ast)) {
1370 throwAFSException(env, ast);
1375 * Start all server processes.
1377 * env the Java environment
1378 * cls the current Java class
1379 * serverHandle the bos handle of the server to which the
1382 JNIEXPORT void JNICALL
1383 Java_org_openafs_jafs_Server_startAllProcesses(JNIEnv * env, jclass cls,
1388 if (!bos_ProcessAllStart((void *)serverHandle, &ast)) {
1389 throwAFSException(env, ast);
1395 * Stop all server processes.
1397 * env the Java environment
1398 * cls the current Java class
1399 * serverHandle the bos handle of the server to which the
1402 JNIEXPORT void JNICALL
1403 Java_org_openafs_jafs_Server_stopAllProcesses(JNIEnv * env, jclass cls,
1408 if (!bos_ProcessAllStop((void *)serverHandle, &ast)) {
1409 throwAFSException(env, ast);
1415 * Restart all server processes.
1417 * env the Java environment
1418 * cls the current Java class
1419 * serverHandle the bos handle of the server to which the
1421 * restartBosServer whether or not to restart the bos server as well
1423 JNIEXPORT void JNICALL
1424 Java_org_openafs_jafs_Server_restartAllProcesses(JNIEnv * env, jclass cls,
1426 jboolean restartBosServer)
1429 bos_RestartBosServer_t rbs;
1431 if (restartBosServer) {
1432 rbs = BOS_RESTART_BOS_SERVER;
1434 rbs = BOS_DONT_RESTART_BOS_SERVER;
1437 if (!bos_ProcessAllStopAndRestart((void *)serverHandle, rbs, &ast)) {
1438 throwAFSException(env, ast);
1444 * Retrieves a specified bos log from a server. Right now this
1445 * method will simply return a huge String containing the log, but
1446 * hopefully we can devise a better way to make this work more efficiently.
1448 * env the Java environment
1449 * cls the current Java class
1450 * serverHandle the bos handle of the server to which the key belongs
1451 * jlogFile the full path and name of the desired bos log
1453 JNIEXPORT jstring JNICALL
1454 Java_org_openafs_jafs_Server_getLog(JNIEnv * env, jclass cls,
1455 jint serverHandle, jstring jlogFile)
1460 unsigned long currInLogSize = 1;
1461 unsigned long currOutLogSize = 0;
1464 logData = (char *)malloc(sizeof(char) * currInLogSize);
1465 if (logData == NULL) {
1466 throwAFSException(env, JAFSADMNOMEM);
1470 if (jlogFile != NULL) {
1471 logFile = getNativeString(env, jlogFile);
1472 if (logFile == NULL) {
1474 throwAFSException(env, JAFSADMNOMEM);
1479 throwAFSException(env, JAFSNULLARG);
1483 // check how big the log is . . .
1485 ((void *)serverHandle, logFile, &currOutLogSize, logData, &ast)) {
1486 // anything but not enough room in buffer
1487 if (ast != ADMMOREDATA) {
1490 throwAFSException(env, ast);
1494 // free previous allocation
1497 // increase log size (plus one for terminator)
1498 currInLogSize = currOutLogSize + 1;
1501 logData = (char *)malloc(sizeof(char) * currInLogSize);
1502 if (logData == NULL) {
1504 throwAFSException(env, JAFSADMNOMEM);
1507 // get the log for real
1509 ((void *)serverHandle, logFile, &currOutLogSize, logData, &ast)) {
1512 throwAFSException(env, ast);
1516 logData[currOutLogSize] == '\0';
1518 logOut = (*env)->NewStringUTF(env, logData);
1528 * Executes any command on the specified server.
1530 * env the Java environment
1531 * cls the current Java class
1532 * serverHandle the bos handle of the server to which the key belongs
1533 * jcommand the text of the commmand to execute
1535 JNIEXPORT void JNICALL
1536 Java_org_openafs_jafs_Server_executeCommand(JNIEnv * env, jclass cls,
1543 if (jcommand != NULL) {
1544 command = getNativeString(env, jcommand);
1545 if (command == NULL) {
1546 throwAFSException(env, JAFSADMNOMEM);
1550 throwAFSException(env, JAFSNULLARG);
1554 if (!bos_CommandExecute((void *)serverHandle, command, &ast)) {
1555 throwAFSException(env, ast);
1561 // reclaim global memory being used by this portion
1562 JNIEXPORT void JNICALL
1563 Java_org_openafs_jafs_Server_reclaimServerMemory(JNIEnv * env, jclass cls)
1566 (*env)->DeleteGlobalRef(env, serverCls);