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 ( JNIEnv *env, jint cellHandle, jobject server, afs_serverEntry_t servEntry )
100 jobjectArray jaddresses;
104 // get the class fields if need be
105 if( serverCls == 0 ) {
106 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
114 jaddresses = (jobjectArray) (*env)->GetObjectField( env, server,
115 server_IPAddressField );
116 for (i = 0; i < 16; i++) {
117 if (servEntry.serverAddress[i] != 0) {
119 (*env)->NewStringUTF(env, (char *)
120 inet_ntoa(htonl(servEntry.serverAddress[i])));
121 (*env)->SetObjectArrayElement(env, jaddresses, i, jip);
127 // let's check if this is really a database server
128 (*env)->SetBooleanField(env, server, server_databaseField,
129 servEntry.serverType & DATABASE_SERVER);
130 if( servEntry.serverType & DATABASE_SERVER ) {
131 // for now, if it thinks it's a database server than it is
132 // later, add checks for database configuration, and actual
133 // on-ness of the machine
134 (*env)->SetBooleanField(env, server, server_badDatabaseField, FALSE);
136 (*env)->SetBooleanField(env, server, server_badDatabaseField, FALSE);
139 // we should check to see if this is truly a file server or not
140 // it could just be an old remnant, left over inside the vldb that
141 // should be removed.
142 // if it is a file server, mark it as such. If not, mark it as faulty.
143 (*env)->SetBooleanField(env, server, server_fileServerField,
144 servEntry.serverType & FILE_SERVER);
145 if( servEntry.serverType & FILE_SERVER ) {
147 // to see if it's really a file server, make sure the
148 // "fs" process is running
151 bos_ProcessType_t processTypeT;
152 bos_ProcessInfo_t processInfoT;
153 char *fileServerProcessName = "fs";
155 // set the file server to true (it thinks it's a file server)
156 (*env)->SetBooleanField(env, server, server_fileServerField, TRUE);
158 if( !bos_ServerOpen( (void *) cellHandle, servEntry.serverName,
159 &bosHandle, &ast ) ) {
160 throwAFSException( env, ast );
163 if( !bos_ProcessInfoGet( bosHandle, fileServerProcessName, &processTypeT,
164 &processInfoT, &ast ) ) {
165 // if the machine does not have a fs process or is not responding
166 // or is part of another cell
167 if( ast == BZNOENT || ast == -1 || ast == RXKADBADTICKET ) {
168 (*env)->SetBooleanField(env, server, server_badFileServerField, TRUE);
171 throwAFSException( env, ast );
176 (*env)->SetBooleanField(env, server, server_badFileServerField, FALSE);
179 (*env)->SetBooleanField(env, server, server_badFileServerField, FALSE);
185 * Fills in the information fields of the provided Server.
187 * env the Java environment
188 * cls the current Java class
189 * cellHandle the handle of the cell to which the server belongs
190 * jname the name of the server for which to get the information
191 * server the Server object in which to fill in
194 JNIEXPORT void JNICALL
195 Java_org_openafs_jafs_Server_getServerInfo (JNIEnv *env, jclass cls,
196 jint cellHandle, jstring jname,
201 afs_serverEntry_t servEntry;
203 if( jname != NULL ) {
204 name = (*env)->GetStringUTFChars(env, jname, 0);
206 throwAFSException( env, JAFSADMNOMEM );
213 // get the server entry
214 if ( !afsclient_AFSServerGet( (void *) cellHandle, name,
215 &servEntry, &ast ) ) {
217 (*env)->ReleaseStringUTFChars(env, jname, name);
219 throwAFSException( env, ast );
223 fillServerInfo( env, cellHandle, server, servEntry );
226 (*env)->ReleaseStringUTFChars(env, jname, name);
232 * Returns the total number of partitions hosted by the server denoted by
233 * serverHandle, if the server is a fileserver.
235 * env the Java environment
236 * cls the current Java class
237 * cellHandle the handle of the cell to which the server belongs
238 * serverHandle the vos handle of the server to which the
240 * returns total number of partitions
242 JNIEXPORT jint JNICALL
243 Java_org_openafs_jafs_Server_getPartitionCount (JNIEnv *env, jclass cls,
249 vos_partitionEntry_t partEntry;
252 if( !vos_PartitionGetBegin( (void *) cellHandle, (void *) serverHandle,
253 NULL, &iterationId, &ast ) ) {
254 throwAFSException( env, ast );
258 while ( vos_PartitionGetNext( (void *) iterationId, &partEntry, &ast ) ) i++;
260 if( ast != ADMITERATORDONE ) {
261 throwAFSException( env, ast );
269 * Begin the process of getting the partitions on a server. Returns
270 * an iteration ID to be used by subsequent calls to
271 * getPartitionsNext and getPartitionsDone.
273 * env the Java environment
274 * cls the current Java class
275 * cellHandle the handle of the cell to which the server belongs
276 * serverHandle the vos handle of the server to which the
278 * returns an iteration ID
280 JNIEXPORT jint JNICALL
281 Java_org_openafs_jafs_Server_getPartitionsBegin (JNIEnv *env, jclass cls,
288 if( !vos_PartitionGetBegin( (void *) cellHandle, (void *) serverHandle,
289 NULL, &iterationId, &ast ) ) {
290 throwAFSException( env, ast );
294 return (jint) iterationId;
299 * Returns the next partition of the server. Returns null
300 * if there are no more partitions.
302 * env the Java environment
303 * cls the current Java class
304 * iterationId the iteration ID of this iteration
305 * returns the name of the next partition of the server
307 JNIEXPORT jstring JNICALL
308 Java_org_openafs_jafs_Server_getPartitionsNextString (JNIEnv *env,
314 vos_partitionEntry_t partEntry;
316 if( !vos_PartitionGetNext( (void *) iterationId, &partEntry, &ast ) ) {
317 if( ast == ADMITERATORDONE ) {
320 throwAFSException( env, ast );
325 jpartition = (*env)->NewStringUTF(env, partEntry.name);
331 * Fills the next partition object of the server. Returns 0 if there
332 * are no more partitions, != 0 otherwise
334 * env the Java environment
335 * cls the current Java class
336 * iterationId the iteration ID of this iteration
337 * thePartition the Partition object in which to fill the
338 * values of the next partition
339 * returns 0 if there are no more servers, != 0 otherwise
341 JNIEXPORT jint JNICALL
342 Java_org_openafs_jafs_Server_getPartitionsNext (JNIEnv *env, jclass cls,
344 jobject jpartitionObject) {
347 vos_partitionEntry_t partEntry;
349 if( !vos_PartitionGetNext( (void *) iterationId, &partEntry, &ast ) ) {
350 if( ast == ADMITERATORDONE ) {
353 throwAFSException( env, ast );
358 fillPartitionInfo( env, jpartitionObject, partEntry );
360 // get the class fields if need be
361 if( partitionCls == 0 ) {
362 internal_getPartitionClass( env, jpartitionObject );
364 (*env)->SetBooleanField( env, jpartitionObject, partition_cachedInfoField,
373 * Signals that the iteration is complete and will not be accessed anymore.
375 * env the Java environment
376 * cls the current Java class
377 * iterationId the iteration ID of this iteration
379 JNIEXPORT void JNICALL
380 Java_org_openafs_jafs_Server_getPartitionsDone (JNIEnv *env, jclass cls,
385 if( !vos_PartitionGetDone( (void *) iterationId, &ast ) ) {
386 throwAFSException( env, ast );
393 * Adds the given to name to the list of bos administrators on that server.
395 * env the Java environment
396 * cls the current Java class
397 * serverHandle the bos handle of the server to which the
399 * jnewAdmin the name of the admin to add to the list
401 JNIEXPORT void JNICALL
402 Java_org_openafs_jafs_Server_addBosAdmin (JNIEnv *env, jclass cls,
407 const char *newAdmin;
409 if( jnewAdmin != NULL ) {
410 newAdmin = (*env)->GetStringUTFChars(env, jnewAdmin, 0);
412 throwAFSException( env, JAFSADMNOMEM );
419 if( !bos_AdminCreate( (void *) serverHandle, newAdmin, &ast ) ) {
420 if( newAdmin != NULL ) {
421 (*env)->ReleaseStringUTFChars(env, jnewAdmin, newAdmin);
423 throwAFSException( env, ast );
427 if( newAdmin != NULL ) {
428 (*env)->ReleaseStringUTFChars(env, jnewAdmin, newAdmin);
434 * Removes the given to name from the list of bos administrators on
437 * env the Java environment
438 * cls the current Java class
439 * serverHandle the bos handle of the server to which the
441 * joldAdmin the name of the admin to remove from the list
443 JNIEXPORT void JNICALL
444 Java_org_openafs_jafs_Server_removeBosAdmin (JNIEnv *env, jclass cls,
449 const char *oldAdmin;
451 if( joldAdmin != NULL ) {
452 oldAdmin = (*env)->GetStringUTFChars(env, joldAdmin, 0);
454 throwAFSException( env, JAFSADMNOMEM );
461 if( !bos_AdminDelete( (void *) serverHandle, oldAdmin, &ast ) ) {
462 if( oldAdmin != NULL ) {
463 (*env)->ReleaseStringUTFChars(env, joldAdmin, oldAdmin);
465 throwAFSException( env, ast );
469 if( oldAdmin != NULL ) {
470 (*env)->ReleaseStringUTFChars(env, joldAdmin, oldAdmin);
476 * Returns the total number of BOS administrators associated with the server
477 * denoted by serverHandle.
479 * env the Java environment
480 * cls the current Java class
481 * serverHandle the vos handle of the server to which the
483 * returns total number of BOS administrators
485 JNIEXPORT jint JNICALL
486 Java_org_openafs_jafs_Server_getBosAdminCount (JNIEnv *env, jclass cls,
495 if( !bos_AdminGetBegin( (void *) serverHandle, &iterationId, &ast ) ) {
496 throwAFSException( env, ast );
500 admin = (char *) malloc( sizeof(char)*BOS_MAX_NAME_LEN);
503 throwAFSException( env, JAFSADMNOMEM );
507 while ( bos_AdminGetNext( (void *) iterationId, admin, &ast ) ) i++;
511 if( ast != ADMITERATORDONE ) {
512 throwAFSException( env, ast );
520 * Begin the process of getting the bos amdinistrators on a server. Returns
521 * an iteration ID to be used by subsequent calls to
522 * getBosAdminsNext and getBosAdminsDone.
524 * env the Java environment
525 * cls the current Java class
526 * serverHandle the bos handle of the server to which the
528 * returns an iteration ID
530 JNIEXPORT jint JNICALL
531 Java_org_openafs_jafs_Server_getBosAdminsBegin (JNIEnv *env, jclass cls,
537 if( !bos_AdminGetBegin( (void *) serverHandle, &iterationId, &ast ) ) {
538 throwAFSException( env, ast );
542 return (jint) iterationId;
547 * Returns the next bos admin of the server. Returns null
548 * if there are no more admins.
550 * env the Java environment
551 * cls the current Java class
552 * iterationId the iteration ID of this iteration
553 * returns the name of the next admin of the server
555 JNIEXPORT jstring JNICALL
556 Java_org_openafs_jafs_Server_getBosAdminsNextString (JNIEnv *env,
562 char *admin = (char *) malloc( sizeof(char)*BOS_MAX_NAME_LEN );
565 throwAFSException( env, JAFSADMNOMEM );
569 if( !bos_AdminGetNext( (void *) iterationId, admin, &ast ) ) {
571 if( ast == ADMITERATORDONE ) {
574 throwAFSException( env, ast );
579 jadmin = (*env)->NewStringUTF(env, admin);
586 * Returns the next bos admin of the server. Returns 0 if there
587 * are no more admins, != 0 otherwise.
589 * env the Java environment
590 * cls the current Java class
591 * cellHandle the handle of the cell to which these admins belong
592 * iterationId the iteration ID of this iteration
593 * juserObject the user object in which to fill the values of this admin
594 * returns 0 if no more admins, != 0 otherwise
596 JNIEXPORT jint JNICALL
597 Java_org_openafs_jafs_Server_getBosAdminsNext (JNIEnv *env, jclass cls,
600 jobject juserObject ) {
606 admin = (char *) malloc( sizeof(char)*BOS_MAX_NAME_LEN);
609 throwAFSException( env, JAFSADMNOMEM );
613 if( !bos_AdminGetNext( (void *) iterationId, admin, &ast ) ) {
615 if( ast == ADMITERATORDONE ) {
618 throwAFSException( env, ast );
623 jadmin = (*env)->NewStringUTF(env, admin);
626 internal_getUserClass( env, juserObject );
629 (*env)->SetObjectField(env, juserObject, user_nameField, jadmin);
631 getUserInfoChar( env, cellHandle, admin, juserObject );
632 (*env)->SetBooleanField( env, juserObject, user_cachedInfoField, TRUE );
640 * Signals that the iteration is complete and will not be accessed anymore.
642 * env the Java environment
643 * cls the current Java class
644 * iterationId the iteration ID of this iteration
646 JNIEXPORT void JNICALL
647 Java_org_openafs_jafs_Server_getBosAdminsDone (JNIEnv *env, jclass cls,
652 if( !bos_AdminGetDone( (void *) iterationId, &ast ) ) {
653 throwAFSException( env, ast );
660 * Returns the total number of keys hosted by the server denoted by
663 * env the Java environment
664 * cls the current Java class
665 * serverHandle the vos handle of the server to which the
667 * returns total number of keys
669 JNIEXPORT jint JNICALL
670 Java_org_openafs_jafs_Server_getKeyCount (JNIEnv *env, jclass cls,
675 bos_KeyInfo_t keyEntry;
678 if( !bos_KeyGetBegin( (void *) serverHandle, &iterationId, &ast ) ) {
679 throwAFSException( env, ast );
683 while ( bos_KeyGetNext( (void *) iterationId, &keyEntry, &ast ) ) i++;
685 if( ast != ADMITERATORDONE ) {
686 throwAFSException( env, ast );
694 * Begin the process of getting the keys of a server. Returns
695 * an iteration ID to be used by subsequent calls to
696 * getKeysNext and getKeysDone.
698 * env the Java environment
699 * cls the current Java class
700 * serverHandle the bos handle of the server to which the keys belong
701 * returns an iteration ID
703 JNIEXPORT jint JNICALL
704 Java_org_openafs_jafs_Server_getKeysBegin (JNIEnv *env, jclass cls,
710 if( !bos_KeyGetBegin( (void *) serverHandle, &iterationId, &ast ) ) {
711 throwAFSException( env, ast );
715 return (jint) iterationId;
720 * Returns the next key of the server. Returns 0 if there
721 * are no more keys, != 0 otherwise.
723 * env the Java environment
724 * cls the current Java class
725 * iterationId the iteration ID of this iteration
726 * jkeyObject a Key object, in which to fill in the
727 * properties of the next key.
728 * returns 0 if there are no more keys, != 0 otherwise
730 JNIEXPORT jint JNICALL
731 Java_org_openafs_jafs_Server_getKeysNext (JNIEnv *env, jclass cls,
733 jobject jkeyObject) {
736 bos_KeyInfo_t keyEntry;
738 if( !bos_KeyGetNext( (void *) iterationId, &keyEntry, &ast ) ) {
739 if( ast == ADMITERATORDONE ) {
742 throwAFSException( env, ast );
747 fillKeyInfo( env, jkeyObject, keyEntry );
749 // get the class fields if need be
751 internal_getKeyClass( env, jkeyObject );
754 (*env)->SetBooleanField( env, jkeyObject, key_cachedInfoField, TRUE );
761 * Signals that the iteration is complete and will not be accessed anymore.
763 * env the Java environment
764 * cls the current Java class
765 * iterationId the iteration ID of this iteration
767 JNIEXPORT void JNICALL
768 Java_org_openafs_jafs_Server_getKeysDone (JNIEnv *env, jclass cls,
773 if( !bos_KeyGetDone( (void *) iterationId, &ast ) ) {
774 throwAFSException( env, ast );
781 * Returns the total number of processes hosted by the server denoted by
784 * env the Java environment
785 * cls the current Java class
786 * serverHandle the vos handle of the server to which the
788 * returns total number of processes
790 JNIEXPORT jint JNICALL
791 Java_org_openafs_jafs_Server_getProcessCount (JNIEnv *env, jclass cls,
800 if( !bos_ProcessNameGetBegin( (void *) serverHandle, &iterationId, &ast ) ) {
801 throwAFSException( env, ast );
805 process = (char *) malloc( sizeof(char)*BOS_MAX_NAME_LEN );
808 throwAFSException( env, JAFSADMNOMEM );
812 while ( bos_ProcessNameGetNext( (void *) iterationId, process, &ast ) ) i++;
816 if( ast != ADMITERATORDONE ) {
817 throwAFSException( env, ast );
825 * Begin the process of getting the processes on a server. Returns
826 * an iteration ID to be used by subsequent calls to
827 * getProcessesNext and getProcessesDone.
829 * env the Java environment
830 * cls the current Java class
831 * serverHandle the bos handle of the server to which the
833 * returns an iteration ID
835 JNIEXPORT jint JNICALL
836 Java_org_openafs_jafs_Server_getProcessesBegin (JNIEnv *env, jclass cls,
842 if( !bos_ProcessNameGetBegin( (void *) serverHandle, &iterationId, &ast ) ) {
843 throwAFSException( env, ast );
847 return (jint) iterationId;
852 * Returns the next process of the server. Returns null
853 * if there are no more processes.
855 * env the Java environment
856 * cls the current Java class
857 * iterationId the iteration ID of this iteration
858 * returns the name of the next process of the cell
860 JNIEXPORT jstring JNICALL
861 Java_org_openafs_jafs_Server_getProcessesNextString (JNIEnv *env,
867 char *process = (char *) malloc( sizeof(char)*BOS_MAX_NAME_LEN );
870 throwAFSException( env, JAFSADMNOMEM );
874 if( !bos_ProcessNameGetNext( (void *) iterationId, process, &ast ) ) {
876 if( ast == ADMITERATORDONE ) {
879 throwAFSException( env, ast );
884 jprocess = (*env)->NewStringUTF(env, process);
891 * Fills the next process object of the server. Returns 0 if there
892 * are no more processes, != 0 otherwise.
894 * env the Java environment
895 * cls the current Java class
896 * serverHandle the handle of the BOS server that hosts the process
897 * iterationId the iteration ID of this iteration
898 * jprocessObject the Process object in which to fill the
899 * values of the next process
900 * returns 0 if there are no more processes, != otherwise
902 JNIEXPORT jint JNICALL
903 Java_org_openafs_jafs_Server_getProcessesNext (JNIEnv *env, jclass cls,
906 jobject jprocessObject) {
909 char *process = (char *) malloc( sizeof(char)*BOS_MAX_NAME_LEN );
913 throwAFSException( env, JAFSADMNOMEM );
917 if( !bos_ProcessNameGetNext( (void *) iterationId, process, &ast ) ) {
918 if( ast == ADMITERATORDONE ) {
922 throwAFSException( env, ast );
927 // get the class fields if need be
928 if( processCls == 0 ) {
929 internal_getProcessClass( env, jprocessObject );
932 jprocess = (*env)->NewStringUTF(env, process);
933 (*env)->SetObjectField(env, jprocessObject, process_nameField, jprocess);
935 getProcessInfoChar( env, (void *) serverHandle, process, jprocessObject );
937 (*env)->SetBooleanField( env, jprocessObject,
938 process_cachedInfoField, TRUE );
946 * Signals that the iteration is complete and will not be accessed anymore.
948 * env the Java environment
949 * cls the current Java class
950 * iterationId the iteration ID of this iteration
952 JNIEXPORT void JNICALL
953 Java_org_openafs_jafs_Server_getProcessesDone (JNIEnv *env, jclass cls,
958 if( !bos_ProcessNameGetDone( (void *) iterationId, &ast ) ) {
959 throwAFSException( env, ast );
966 * Salvages (restores consistency to) a volume, partition, or server
968 * env the Java environment
969 * cls the current Java class
970 * cellHandle the handle of the cell to which the volume belongs
971 * serverHandle the bos handle of the server on which the
973 * jpartName the name of the partition to salvage,
974 * can be null only if volName is
976 * jvolName the name of the volume to salvage,
978 * numSalvagers the number of salvager processes to run in parallel
979 * jtempDir directory to place temporary files, can be
981 * jlogFile where salvager log will be written, can be
983 * inspectAllVolumes whether or not to inspect all volumes,
984 * not just those marked as active at crash
985 * removeBadlyDamaged whether or not to remove a volume if it's
987 * writeInodes whether or not to record a list of inodes modified
988 * writeRootInodes whether or not to record a list of AFS
989 * inodes owned by root
990 * forceDirectory whether or not to salvage an entire directory
992 * forceBlockReads whether or not to force the salvager to read
994 * one block at a time and skip badly damaged
995 * blocks. Use if partition has disk errors
997 JNIEXPORT void JNICALL
998 Java_org_openafs_jafs_Server_salvage (JNIEnv *env, jclass cls,
999 jint cellHandle, jint serverHandle,
1000 jstring jpartName, jstring jvolName,
1001 jint numSalvagers, jstring jtempDir,
1003 jboolean inspectAllVolumes,
1004 jboolean removeBadlyDamaged,
1005 jboolean writeInodes,
1006 jboolean writeRootInodes,
1007 jboolean forceDirectory,
1008 jboolean forceBlockReads) {
1011 const char *partName;
1012 const char *volName;
1013 const char *tempDir;
1014 const char *logFile;
1016 bos_SalvageDamagedVolumes_t sdv;
1017 bos_WriteInodes_t wi;
1018 bos_WriteRootInodes_t wri;
1019 bos_ForceDirectory_t forceD;
1020 bos_ForceBlockRead_t forceBR;
1023 if( jpartName != NULL ) {
1024 partName = (*env)->GetStringUTFChars(env, jpartName, 0);
1026 throwAFSException( env, JAFSADMNOMEM );
1032 if( jvolName != NULL ) {
1033 volName = (*env)->GetStringUTFChars(env, jvolName, 0);
1035 if( partName != NULL ) {
1036 (*env)->ReleaseStringUTFChars(env, jpartName, partName);
1038 throwAFSException( env, JAFSADMNOMEM );
1044 if( jtempDir != NULL ) {
1045 tempDir = (*env)->GetStringUTFChars(env, jtempDir, 0);
1047 if( partName != NULL ) {
1048 (*env)->ReleaseStringUTFChars(env, jpartName, partName);
1050 if( volName != NULL ) {
1051 (*env)->ReleaseStringUTFChars(env, jvolName, volName);
1053 throwAFSException( env, JAFSADMNOMEM );
1059 if( jlogFile != NULL ) {
1060 logFile = (*env)->GetStringUTFChars(env, jlogFile, 0);
1062 if( partName != NULL ) {
1063 (*env)->ReleaseStringUTFChars(env, jpartName, partName);
1065 if( volName != NULL ) {
1066 (*env)->ReleaseStringUTFChars(env, jvolName, volName);
1068 if( tempDir != NULL ) {
1069 (*env)->ReleaseStringUTFChars(env, jtempDir, tempDir);
1071 throwAFSException( env, JAFSADMNOMEM );
1078 // deal with booleans
1079 if( inspectAllVolumes ) {
1084 if( removeBadlyDamaged ) {
1085 sdv = BOS_DONT_SALVAGE_DAMAGED_VOLUMES;
1087 sdv = BOS_SALVAGE_DAMAGED_VOLUMES;
1090 wi = BOS_SALVAGE_WRITE_INODES;
1092 wi = BOS_SALVAGE_DONT_WRITE_INODES;
1094 if( writeRootInodes ) {
1095 wri = BOS_SALVAGE_WRITE_ROOT_INODES;
1097 wri = BOS_SALVAGE_DONT_WRITE_ROOT_INODES;
1099 if( forceDirectory ) {
1100 forceD = BOS_SALVAGE_FORCE_DIRECTORIES;
1102 forceD = BOS_SALVAGE_DONT_FORCE_DIRECTORIES;
1104 if( forceBlockReads ) {
1105 forceBR = BOS_SALVAGE_FORCE_BLOCK_READS;
1107 forceBR = BOS_SALVAGE_DONT_FORCE_BLOCK_READS;
1111 if( !bos_Salvage( (void *) cellHandle, (void *) serverHandle, partName,
1112 volName, (int) numSalvagers, tempDir, logFile, force, sdv,
1113 wi, wri, forceD, forceBR, &ast ) ) {
1114 if( partName != NULL ) {
1115 (*env)->ReleaseStringUTFChars(env, jpartName, partName);
1117 if( volName != NULL ) {
1118 (*env)->ReleaseStringUTFChars(env, jvolName, volName);
1120 if( tempDir != NULL ) {
1121 (*env)->ReleaseStringUTFChars(env, jtempDir, tempDir);
1123 if( logFile != NULL ) {
1124 (*env)->ReleaseStringUTFChars(env, jlogFile, logFile);
1126 throwAFSException( env, ast );
1131 if( partName != NULL ) {
1132 (*env)->ReleaseStringUTFChars(env, jpartName, partName);
1134 if( volName != NULL ) {
1135 (*env)->ReleaseStringUTFChars(env, jvolName, volName);
1137 if( tempDir != NULL ) {
1138 (*env)->ReleaseStringUTFChars(env, jtempDir, tempDir);
1140 if( logFile != NULL ) {
1141 (*env)->ReleaseStringUTFChars(env, jlogFile, logFile);
1147 * Fills in the restart time fields of the given Server
1150 * env the Java environment
1151 * cls the current Java class
1152 * serverHandle the bos handle of the server to which the key belongs
1153 * jtype whether to get the general or binary restart.
1154 * Acceptable values are:
1155 * org_opemafs_jafs_Server_RESTART_BINARY
1156 * org_opemafs_jafs_Server_RESTART_GENERAL
1157 * execTime the ExecutableTime object, in which
1158 * to fill the restart time fields
1160 JNIEXPORT void JNICALL
1161 Java_org_openafs_jafs_Server_getRestartTime
1162 (JNIEnv *env, jclass cls, jint serverHandle, jint jtype, jobject exectime)
1166 bos_RestartTime_t time;
1171 jfieldID neverField;
1174 // get the class fields if need be
1175 if( exectimeCls == 0 ) {
1176 internal_getExecTimeClass( env, exectime );
1179 if( jtype == org_openafs_jafs_Server_RESTART_BINARY ) {
1180 type = BOS_RESTART_DAILY;
1182 type = BOS_RESTART_WEEKLY;
1185 hourField = exectime_HourField;
1186 minField = exectime_MinField;
1187 secField = exectime_SecField;
1188 dayField = exectime_DayField;
1189 neverField = exectime_NeverField;
1190 nowField = exectime_NowField;
1192 if( !bos_ExecutableRestartTimeGet( (void *) serverHandle, type,
1194 throwAFSException( env, ast );
1199 (*env)->SetBooleanField(env, exectime, nowField,
1200 (time.mask & BOS_RESTART_TIME_NOW) );
1203 (*env)->SetBooleanField(env, exectime, neverField,
1204 (time.mask & BOS_RESTART_TIME_NEVER) );
1207 (*env)->SetShortField(env, exectime, hourField, time.hour );
1210 (*env)->SetShortField(env, exectime, minField, time.min );
1213 (*env)->SetShortField(env, exectime, secField, time.sec );
1216 if( time.mask & BOS_RESTART_TIME_DAY ) {
1217 (*env)->SetShortField(env, exectime, dayField, time.day );
1219 (*env)->SetShortField(env, exectime, dayField, (jshort) -1 );
1225 * Sets the restart time of the bos server.
1227 * env the Java environment
1228 * cls the current Java class
1229 * serverHandle the bos handle of the server to which the key belongs
1230 * jtype whether this is to be a general or binary restart.
1231 * Acceptable values are:
1232 * org_opemafs_jafs_Server_RESTART_BINARY
1233 * org_opemafs_jafs_Server_RESTART_GENERAL
1234 * executableTime the ExecutableTime object containing the
1235 * desired information
1237 JNIEXPORT void JNICALL
1238 Java_org_openafs_jafs_Server_setRestartTime (JNIEnv *env, jclass cls,
1239 jint serverHandle, jint jtype,
1240 jobject exectime ) {
1244 bos_RestartTime_t time;
1259 jfieldID neverField;
1262 // get the class fields if need be
1263 if( exectimeCls == 0 ) {
1264 internal_getExecTimeClass( env, exectime );
1267 if( jtype == org_openafs_jafs_Server_RESTART_BINARY ) {
1268 type = BOS_RESTART_DAILY;
1270 type = BOS_RESTART_WEEKLY;
1273 hourField = exectime_HourField;
1274 minField = exectime_MinField;
1275 secField = exectime_SecField;
1276 dayField = exectime_DayField;
1277 neverField = exectime_NeverField;
1278 nowField = exectime_NowField;
1280 hour = (*env)->GetShortField(env, exectime, hourField );
1286 minute = (*env)->GetShortField(env, exectime, minField );
1292 second = (*env)->GetShortField(env, exectime, secField );
1298 day = (*env)->GetShortField(env, exectime, dayField );
1304 doNever = (*env)->GetBooleanField(env, exectime, neverField );
1305 doNow = (*env)->GetBooleanField(env, exectime, nowField );
1307 bzero(&time, sizeof(time));
1309 if( jtype == org_openafs_jafs_Server_RESTART_BINARY ) {
1310 type = BOS_RESTART_DAILY;
1312 type = BOS_RESTART_WEEKLY;
1316 time.mask |= BOS_RESTART_TIME_HOUR;
1319 time.mask |= BOS_RESTART_TIME_MINUTE;
1322 time.mask |= BOS_RESTART_TIME_SECOND;
1325 time.mask |= BOS_RESTART_TIME_DAY;
1328 time.mask |= BOS_RESTART_TIME_NEVER;
1331 time.mask |= BOS_RESTART_TIME_NOW;
1339 if( !bos_ExecutableRestartTimeSet( (void *) serverHandle, type,
1341 throwAFSException( env, ast );
1348 * Synchronizes a particular server with the volume location database.
1350 * env the Java environment
1351 * cls the current Java class
1352 * cellHandle the handle of the cell to which the server belongs
1353 * serverHandle the vos handle of the server
1354 * partition the id of the partition to sync, can be -1 to ignore
1356 JNIEXPORT void JNICALL
1357 Java_org_openafs_jafs_Server_syncServerWithVLDB (JNIEnv *env, jclass cls,
1365 if( partition == -1 ) {
1368 part = (int *) &partition;
1371 if( !vos_ServerSync( (void *) cellHandle, (void *) serverHandle,
1372 NULL, part, &ast ) ) {
1373 throwAFSException( env, ast );
1380 * Synchronizes the volume location database with a particular server.
1382 * env the Java environment
1383 * cls the current Java class
1384 * cellHandle the handle of the cell to which the server belongs
1385 * serverHandle the vos handle of the server
1386 * partition the id of the partition to sync, can be -1 to ignore
1387 * forceDeletion whether or not to force the deletion of bad volumes
1389 JNIEXPORT void JNICALL
1390 Java_org_openafs_jafs_Server_syncVLDBWithServer (JNIEnv *env, jclass cls,
1394 jboolean forceDeletion) {
1400 if( partition == -1 ) {
1403 part = (int *) &partition;
1406 if( forceDeletion ) {
1412 if( !vos_VLDBSync( (void *) cellHandle, (void *) serverHandle, NULL, part,
1414 throwAFSException( env, ast );
1421 * Start all server processes.
1423 * env the Java environment
1424 * cls the current Java class
1425 * serverHandle the bos handle of the server to which the
1428 JNIEXPORT void JNICALL
1429 Java_org_openafs_jafs_Server_startAllProcesses (JNIEnv *env, jclass cls,
1430 jint serverHandle) {
1434 if( !bos_ProcessAllStart( (void *) serverHandle, &ast ) ) {
1435 throwAFSException( env, ast );
1442 * Stop all server processes.
1444 * env the Java environment
1445 * cls the current Java class
1446 * serverHandle the bos handle of the server to which the
1449 JNIEXPORT void JNICALL
1450 Java_org_openafs_jafs_Server_stopAllProcesses (JNIEnv *env, jclass cls,
1451 jint serverHandle) {
1455 if( !bos_ProcessAllStop( (void *) serverHandle, &ast ) ) {
1456 throwAFSException( env, ast );
1463 * Restart all server processes.
1465 * env the Java environment
1466 * cls the current Java class
1467 * serverHandle the bos handle of the server to which the
1469 * restartBosServer whether or not to restart the bos server as well
1471 JNIEXPORT void JNICALL
1472 Java_org_openafs_jafs_Server_restartAllProcesses (JNIEnv *env, jclass cls,
1474 jboolean restartBosServer) {
1477 bos_RestartBosServer_t rbs;
1479 if( restartBosServer ) {
1480 rbs = BOS_RESTART_BOS_SERVER;
1482 rbs = BOS_DONT_RESTART_BOS_SERVER;
1485 if( !bos_ProcessAllStopAndRestart( (void *) serverHandle, rbs, &ast ) ) {
1486 throwAFSException( env, ast );
1493 * Retrieves a specified bos log from a server. Right now this
1494 * method will simply return a huge String containing the log, but
1495 * hopefully we can devise a better way to make this work more efficiently.
1497 * env the Java environment
1498 * cls the current Java class
1499 * serverHandle the bos handle of the server to which the key belongs
1500 * jlogFile the full path and name of the desired bos log
1502 JNIEXPORT jstring JNICALL
1503 Java_org_openafs_jafs_Server_getLog(JNIEnv *env, jclass cls,
1504 jint serverHandle, jstring jlogFile) {
1507 const char *logFile;
1509 unsigned long currInLogSize = 1;
1510 unsigned long currOutLogSize = 0;
1513 if( jlogFile != NULL ) {
1514 logFile = (*env)->GetStringUTFChars(env, jlogFile, 0);
1516 throwAFSException( env, JAFSADMNOMEM );
1523 logData = (char *) malloc( sizeof(char)*currInLogSize );
1525 throwAFSException( env, JAFSADMNOMEM );
1529 // check how big the log is . . .
1530 if( !bos_LogGet( (void *) serverHandle, logFile,
1531 &currOutLogSize, logData, &ast ) ) {
1532 // anything but not enough room in buffer
1533 if( ast != ADMMOREDATA ) {
1535 if( logFile != NULL ) {
1536 (*env)->ReleaseStringUTFChars(env, jlogFile, logFile);
1538 throwAFSException( env, ast );
1545 // increase log size (plus one for terminator)
1546 currInLogSize = currOutLogSize + 1;
1548 logData = (char *) malloc( sizeof(char)*currInLogSize );
1550 throwAFSException( env, JAFSADMNOMEM );
1556 if( logFile != NULL ) {
1557 (*env)->ReleaseStringUTFChars(env, jlogFile, logFile);
1559 throwAFSException( env, ast );
1563 // get the log for real
1564 if( !bos_LogGet( (void *) serverHandle, logFile, &currOutLogSize,
1567 if( logFile != NULL ) {
1568 (*env)->ReleaseStringUTFChars(env, jlogFile, logFile);
1570 (*env)->ReleaseStringUTFChars(env, jlogFile, logFile);
1571 throwAFSException( env, ast );
1575 logData[currOutLogSize] == '\0';
1577 logOut = (*env)->NewStringUTF(env, logData);
1580 if( logFile != NULL ) {
1581 (*env)->ReleaseStringUTFChars(env, jlogFile, logFile);
1589 * Executes any command on the specified server.
1591 * env the Java environment
1592 * cls the current Java class
1593 * serverHandle the bos handle of the server to which the key belongs
1594 * jcommand the text of the commmand to execute
1596 JNIEXPORT void JNICALL
1597 Java_org_openafs_jafs_Server_executeCommand (JNIEnv *env, jclass cls,
1602 const char *command;
1604 if( jcommand != NULL ) {
1605 command = (*env)->GetStringUTFChars(env, jcommand, 0);
1607 throwAFSException( env, JAFSADMNOMEM );
1614 if( !bos_CommandExecute( (void *) serverHandle, command, &ast ) ) {
1615 if( command != NULL ) {
1616 (*env)->ReleaseStringUTFChars(env, jcommand, command);
1618 throwAFSException( env, ast );
1622 if( command != NULL ) {
1623 (*env)->ReleaseStringUTFChars(env, jcommand, command);
1628 // reclaim global memory being used by this portion
1629 JNIEXPORT void JNICALL
1630 Java_org_openafs_jafs_Server_reclaimServerMemory (JNIEnv *env, jclass cls) {
1633 (*env)->DeleteGlobalRef(env, serverCls);