Import Upstream version 1.8.5
[hcoop/debian/openafs.git] / src / JAVA / libjafs / Volume.c
1 /*
2 * Copyright (c) 2001-2002 International Business Machines Corp.
3 * All rights reserved.
4 *
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
8 *
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.
20 */
21
22 #include "Internal.h"
23 #include "org_openafs_jafs_Volume.h"
24
25 #include <afs_vosAdmin.h>
26 #include <afs_AdminCommonErrors.h>
27
28 //// definitions in Internal.c //////////////////
29
30 extern jclass volumeCls;
31 extern jfieldID volume_nameField;
32 extern jfieldID volume_idField;
33 extern jfieldID volume_readWriteIdField;
34 extern jfieldID volume_readOnlyIdField;
35 extern jfieldID volume_backupIdField;
36 extern jfieldID volume_creationDateField;
37 extern jfieldID volume_lastAccessDateField;
38 extern jfieldID volume_lastUpdateDateField;
39 extern jfieldID volume_lastBackupDateField;
40 extern jfieldID volume_copyCreationDateField;
41 extern jfieldID volume_accessesSinceMidnightField;
42 extern jfieldID volume_fileCountField;
43 extern jfieldID volume_maxQuotaField;
44 extern jfieldID volume_currentSizeField;
45 extern jfieldID volume_statusField;
46 extern jfieldID volume_dispositionField;
47 extern jfieldID volume_typeField;
48
49 //////////////////////////////////////////////////////////
50
51 /**
52 * Extract the information from the given volume entry and populate the
53 * given object
54 *
55 * env the Java environment
56 * volume the Volume object to populate with the info
57 * volEntry the container of the volume's information
58 */
59 extern void fillVolumeInfo( JNIEnv *env, jobject volume,
60 vos_volumeEntry_t volEntry ) {
61
62 jstring jvolume;
63
64 // get the class fields if need be
65 if( volumeCls == 0 ) {
66 internal_getVolumeClass( env, volume );
67 }
68
69 // set name, just in case it was a completely blank object
70 jvolume = (*env)->NewStringUTF(env, volEntry.name);
71 (*env)->SetObjectField(env, volume, volume_nameField, jvolume);
72
73 (*env)->SetIntField(env, volume, volume_idField, volEntry.id);
74 (*env)->SetIntField(env, volume, volume_readWriteIdField,
75 volEntry.readWriteId);
76 (*env)->SetIntField(env, volume, volume_readOnlyIdField,
77 volEntry.readOnlyId);
78 (*env)->SetIntField(env, volume, volume_backupIdField, volEntry.backupId);
79 (*env)->SetLongField(env, volume, volume_creationDateField,
80 volEntry.creationDate);
81 (*env)->SetLongField(env, volume, volume_lastAccessDateField,
82 volEntry.lastAccessDate);
83 (*env)->SetLongField(env, volume, volume_lastUpdateDateField,
84 volEntry.lastUpdateDate);
85 (*env)->SetLongField(env, volume, volume_lastBackupDateField,
86 volEntry.lastBackupDate);
87 (*env)->SetLongField(env, volume, volume_copyCreationDateField,
88 volEntry.copyCreationDate);
89 (*env)->SetIntField(env, volume, volume_accessesSinceMidnightField,
90 volEntry.accessesSinceMidnight);
91 (*env)->SetIntField(env, volume, volume_fileCountField, volEntry.fileCount);
92 (*env)->SetIntField(env, volume, volume_maxQuotaField, volEntry.maxQuota);
93 (*env)->SetIntField(env, volume, volume_currentSizeField,
94 volEntry.currentSize);
95
96 // set status variable
97 switch( volEntry.status ) {
98 case VOS_OK :
99 (*env)->SetIntField(env, volume, volume_statusField,
100 org_openafs_jafs_Volume_VOLUME_OK);
101 break;
102 case VOS_SALVAGE :
103 (*env)->SetIntField(env, volume, volume_statusField,
104 org_openafs_jafs_Volume_VOLUME_SALVAGE);
105 break;
106 case VOS_NO_VNODE:
107 (*env)->SetIntField(env, volume, volume_statusField,
108 org_openafs_jafs_Volume_VOLUME_NO_VNODE);
109 break;
110 case VOS_NO_VOL:
111 (*env)->SetIntField(env, volume, volume_statusField,
112 org_openafs_jafs_Volume_VOLUME_NO_VOL);
113 break;
114 case VOS_VOL_EXISTS:
115 (*env)->SetIntField(env, volume, volume_statusField,
116 org_openafs_jafs_Volume_VOLUME_VOL_EXISTS);
117 break;
118 case VOS_NO_SERVICE:
119 (*env)->SetIntField(env, volume, volume_statusField,
120 org_openafs_jafs_Volume_VOLUME_NO_SERVICE);
121 break;
122 case VOS_OFFLINE:
123 (*env)->SetIntField(env, volume, volume_statusField,
124 org_openafs_jafs_Volume_VOLUME_OFFLINE);
125 break;
126 case VOS_ONLINE:
127 (*env)->SetIntField(env, volume, volume_statusField,
128 org_openafs_jafs_Volume_VOLUME_ONLINE);
129 break;
130 case VOS_DISK_FULL:
131 (*env)->SetIntField(env, volume, volume_statusField,
132 org_openafs_jafs_Volume_VOLUME_DISK_FULL);
133 break;
134 case VOS_OVER_QUOTA:
135 (*env)->SetIntField(env, volume, volume_statusField,
136 org_openafs_jafs_Volume_VOLUME_OVER_QUOTA);
137 break;
138 case VOS_BUSY:
139 (*env)->SetIntField(env, volume, volume_statusField,
140 org_openafs_jafs_Volume_VOLUME_BUSY);
141 break;
142 case VOS_MOVED:
143 (*env)->SetIntField(env, volume, volume_statusField,
144 org_openafs_jafs_Volume_VOLUME_MOVED);
145 break;
146 default:
147 throwAFSException( env, volEntry.status );
148 }
149
150 // set disposition variable
151 switch( volEntry.volumeDisposition ) {
152 case VOS_OK :
153 (*env)->SetIntField(env, volume, volume_dispositionField,
154 org_openafs_jafs_Volume_VOLUME_OK);
155 break;
156 case VOS_SALVAGE :
157 (*env)->SetIntField(env, volume, volume_dispositionField,
158 org_openafs_jafs_Volume_VOLUME_SALVAGE);
159 break;
160 case VOS_NO_VNODE:
161 (*env)->SetIntField(env, volume, volume_dispositionField,
162 org_openafs_jafs_Volume_VOLUME_NO_VNODE);
163 break;
164 case VOS_NO_VOL:
165 (*env)->SetIntField(env, volume, volume_dispositionField,
166 org_openafs_jafs_Volume_VOLUME_NO_VOL);
167 break;
168 case VOS_VOL_EXISTS:
169 (*env)->SetIntField(env, volume, volume_dispositionField,
170 org_openafs_jafs_Volume_VOLUME_VOL_EXISTS);
171 break;
172 case VOS_NO_SERVICE:
173 (*env)->SetIntField(env, volume, volume_dispositionField,
174 org_openafs_jafs_Volume_VOLUME_NO_SERVICE);
175 break;
176 case VOS_OFFLINE:
177 (*env)->SetIntField(env, volume, volume_dispositionField,
178 org_openafs_jafs_Volume_VOLUME_OFFLINE);
179 break;
180 case VOS_ONLINE:
181 (*env)->SetIntField(env, volume, volume_dispositionField,
182 org_openafs_jafs_Volume_VOLUME_ONLINE);
183 break;
184 case VOS_DISK_FULL:
185 (*env)->SetIntField(env, volume, volume_dispositionField,
186 org_openafs_jafs_Volume_VOLUME_DISK_FULL);
187 break;
188 case VOS_OVER_QUOTA:
189 (*env)->SetIntField(env, volume, volume_dispositionField,
190 org_openafs_jafs_Volume_VOLUME_OVER_QUOTA);
191 break;
192 case VOS_BUSY:
193 (*env)->SetIntField(env, volume, volume_dispositionField,
194 org_openafs_jafs_Volume_VOLUME_BUSY);
195 break;
196 case VOS_MOVED:
197 (*env)->SetIntField(env, volume, volume_dispositionField,
198 org_openafs_jafs_Volume_VOLUME_MOVED);
199 break;
200 default:
201 throwAFSException( env, volEntry.volumeDisposition );
202 }
203
204 // set type variable
205 switch( volEntry.type ) {
206 case VOS_READ_WRITE_VOLUME:
207 (*env)->SetIntField(env, volume, volume_typeField,
208 org_openafs_jafs_Volume_VOLUME_TYPE_READ_WRITE);
209 break;
210 case VOS_READ_ONLY_VOLUME:
211 (*env)->SetIntField(env, volume, volume_typeField,
212 org_openafs_jafs_Volume_VOLUME_TYPE_READ_ONLY);
213 break;
214 case VOS_BACKUP_VOLUME:
215 (*env)->SetIntField(env, volume, volume_typeField,
216 org_openafs_jafs_Volume_VOLUME_TYPE_BACKUP);
217 break;
218 default:
219 throwAFSException( env, volEntry.type );
220 }
221
222 }
223
224 /**
225 * Fills in the information fields of the provided Volume.
226 *
227 * env the Java environment
228 * cls the current Java class
229 * cellHandle the handle of the cell to which the volume belongs
230 * serverHandle the vos handle of the server on which the volume
231 * resides
232 * partition the numeric id of the partition on which the volume
233 * resides
234 * volId the numeric id of the volume for which to get the info
235 * jvolumeObject the Volume object in which to fill in
236 * the information
237 */
238 JNIEXPORT void JNICALL
239 Java_org_openafs_jafs_Volume_getVolumeInfo (JNIEnv *env, jclass cls,
240 jlong cellHandle,
241 jlong serverHandle,
242 jint partition, jint volID,
243 jobject jvolumeObject) {
244
245 afs_status_t ast;
246 vos_volumeEntry_t volEntry;
247
248 // get the volume entry
249 if ( !vos_VolumeGet( (void *) cellHandle, (void *) serverHandle, NULL,
250 (unsigned int) partition, (unsigned int) volID,
251 &volEntry, &ast ) ) {
252 throwAFSException( env, ast );
253 return;
254 }
255
256 fillVolumeInfo( env, jvolumeObject, volEntry );
257
258 }
259
260 /**
261 * Creates a volume on a particular partition.
262 *
263 * env the Java environment
264 * cls the current Java class
265 * cellHandle the handle of the cell in which to create the volume
266 * serverHandle the vos handle of the server on which to create
267 * the volume
268 * partition the numeric id of the partition on which to create
269 * the volume
270 * jvolName the name of the volume to create
271 * quota the amount of space (in KB) to set as this volume's quota
272 * returns the numeric ID assigned to the volume
273 */
274 JNIEXPORT jint JNICALL
275 Java_org_openafs_jafs_Volume_create (JNIEnv *env, jclass cls,
276 jlong cellHandle, jlong serverHandle,
277 jint partition, jstring jvolName,
278 jint quota) {
279
280 afs_status_t ast;
281 const char *volName;
282 int id;
283
284 if( jvolName != NULL ) {
285 volName = (*env)->GetStringUTFChars(env, jvolName, 0);
286 if( !volName ) {
287 throwAFSException( env, JAFSADMNOMEM );
288 return;
289 }
290 } else {
291 volName = NULL;
292 }
293
294 if( !vos_VolumeCreate( (void *) cellHandle, (void *) serverHandle, NULL,
295 (unsigned int) partition, volName,
296 (unsigned int) quota, &id, &ast ) ) {
297 if( volName != NULL ) {
298 (*env)->ReleaseStringUTFChars(env, jvolName, volName);
299 }
300 throwAFSException( env, ast );
301 return;
302 }
303
304 if( volName != NULL ) {
305 (*env)->ReleaseStringUTFChars(env, jvolName, volName);
306 }
307 return (jint) id;
308
309 }
310
311 /**
312 * Deletes a volume from a particular partition.
313 *
314 * env the Java environment
315 * cls the current Java class
316 * cellHandle the handle of the cell in which to delete the volume
317 * serverHandle the vos handle of the server from which to delete
318 * the volume
319 * partition the numeric id of the partition from which to delete
320 * the volume
321 * volId the numeric id of the volume to delete
322 */
323 JNIEXPORT void JNICALL
324 Java_org_openafs_jafs_Volume_delete (JNIEnv *env, jclass cls,
325 jlong cellHandle, jlong serverHandle,
326 jint partition, jint volID) {
327
328 afs_status_t ast;
329
330 if( !vos_VolumeDelete( (void *) cellHandle, (void *) serverHandle, NULL,
331 (unsigned int) partition,
332 (unsigned int) volID, &ast ) ) {
333 throwAFSException( env, ast );
334 return;
335 }
336
337 }
338
339 /**
340 * Creates a backup volume for the specified regular volume.
341 *
342 * env the Java environment
343 * cls the current Java class
344 * cellHandle the handle of the cell to which the volume belongs
345 * volId the numeric id of the volume for which to create a backup
346 * volume
347 */
348 JNIEXPORT void JNICALL
349 Java_org_openafs_jafs_Volume_createBackupVolume (JNIEnv *env, jclass cls,
350 jlong cellHandle,
351 jint volID) {
352
353 afs_status_t ast;
354
355 if( !vos_BackupVolumeCreate( (void *) cellHandle, NULL,
356 (unsigned int) volID, &ast ) ) {
357 throwAFSException( env, ast );
358 return;
359 }
360
361 }
362
363 /**
364 * Creates a read-only volume for the specified regular volume.
365 *
366 * env the Java environment
367 * cls the current Java class
368 * cellHandle the handle of the cell to which the volume belongs
369 * serverHandle the vos handle of the server on which the read-only
370 * volume is to reside
371 * partition the numeric id of the partition on which the read-only
372 * volume is to reside
373 * volId the numeric id of the volume for which to
374 * create a read-only volume
375 */
376 JNIEXPORT void JNICALL
377 Java_org_openafs_jafs_Volume_createReadOnlyVolume (JNIEnv *env, jclass cls,
378 jlong cellHandle,
379 jlong serverHandle,
380 jint partition,
381 jint volID) {
382
383 afs_status_t ast;
384
385 if( !vos_VLDBReadOnlySiteCreate( (void *) cellHandle, (void *) serverHandle,
386 NULL, (unsigned int) partition,
387 (unsigned int) volID, &ast ) ) {
388 throwAFSException( env, ast );
389 return;
390 }
391
392 }
393
394 /**
395 * Deletes a read-only volume for the specified regular volume.
396 *
397 * env the Java environment
398 * cls the current Java class
399 * cellHandle the handle of the cell to which the volume belongs
400 * serverHandle the vos handle of the server on which the read-only
401 * volume residea
402 * partition the numeric id of the partition on which the read-only
403 * volume resides
404 * volId the numeric read-write id of the volume for which to
405 * delete the read-only volume
406 */
407 JNIEXPORT void JNICALL
408 Java_org_openafs_jafs_Volume_deleteReadOnlyVolume (JNIEnv *env, jclass cls,
409 jlong cellHandle,
410 jlong serverHandle,
411 jint partition,
412 jint volID) {
413
414 afs_status_t ast;
415
416 if( !vos_VLDBReadOnlySiteDelete( (void *) cellHandle, (void *) serverHandle,
417 NULL, (unsigned int) partition,
418 (unsigned int) volID, &ast ) ) {
419 throwAFSException( env, ast );
420 return;
421 }
422
423 }
424
425 /**
426 * Changes the quota of the specified volume.
427 *
428 * env the Java environment
429 * cls the current Java class
430 * cellHandle the handle of the cell to which the volume belongs
431 * serverHandle the vos handle of the server on which the volume
432 * resides
433 * partition the numeric id of the partition on which the volume
434 * resides
435 * volId the numeric id of the volume for which to change the quota
436 * newQuota the new quota (in KB) to assign the volume
437 */
438 JNIEXPORT void JNICALL
439 Java_org_openafs_jafs_Volume_changeQuota (JNIEnv *env, jclass cls,
440 jlong cellHandle,
441 jlong serverHandle,
442 jint partition, jint volID,
443 jint newQuota) {
444
445 afs_status_t ast;
446
447 if( !vos_VolumeQuotaChange( (void *) cellHandle, (void *) serverHandle,
448 NULL, (unsigned int) partition,
449 (unsigned int) volID, (unsigned int) newQuota,
450 &ast ) ) {
451 throwAFSException( env, ast );
452 return;
453 }
454
455 }
456
457 /**
458 * Move the specified volume to a different site.
459 *
460 * env the Java environment
461 * cls the current Java class
462 * cellHandle the handle of the cell to which the volume belongs
463 * fromServerHandle the vos handle of the server on which the volume
464 * currently resides
465 * fromPartition the numeric id of the partition on which the volume
466 * currently resides
467 * toServerHandle the vos handle of the server to which the volume
468 * should be moved
469 * toPartition the numeric id of the partition to which the volume
470 * should be moved
471 * volId the numeric id of the volume to move
472 */
473 JNIEXPORT void JNICALL
474 Java_org_openafs_jafs_Volume_move
475 (JNIEnv *env, jclass cls, jlong cellHandle, jlong fromServerHandle,
476 jint fromPartition, jlong toServerHandle, jint toPartition, jint volID)
477 {
478 afs_status_t ast;
479
480 if( !vos_VolumeMove( (void *) cellHandle, NULL, (unsigned int) volID,
481 (void *) fromServerHandle, (unsigned int) fromPartition,
482 (void *) toServerHandle, (unsigned int) toPartition,
483 &ast ) ) {
484 throwAFSException( env, ast );
485 return;
486 }
487
488 }
489
490 /**
491 * Releases the specified volume that has readonly volume sites.
492 *
493 * env the Java environment
494 * cls the current Java class
495 * cellHandle the handle of the cell to which the volume belongs
496 * volId the numeric id of the volume to release
497 * forceComplete whether or not to force a complete release
498 */
499 JNIEXPORT void JNICALL
500 Java_org_openafs_jafs_Volume_release
501 (JNIEnv *env, jclass cls, jlong cellHandle, jint volID, jboolean forceComplete)
502 {
503 afs_status_t ast;
504 vos_force_t force;
505
506 if( forceComplete ) {
507 force = VOS_FORCE;
508 } else {
509 force = VOS_NORMAL;
510 }
511
512 if( !vos_VolumeRelease( (void *) cellHandle, NULL, (unsigned int) volID,
513 force, &ast )) {
514 throwAFSException( env, ast );
515 return;
516 }
517
518 }
519
520 /**
521 * Dumps the specified volume to a file.
522 *
523 * env the Java environment
524 * cls the current Java class
525 * cellHandle the handle of the cell to which the volume belongs
526 * serverHandle the vos handle of the server on which the volume
527 * resides
528 * partition the numeric id of the partition on which the
529 * volume resides
530 * volId the numeric id of the volume to dump
531 * startTime files with a modification time >= to this time will
532 * be dumped
533 * jdumpFile the full path of the file to which to dump
534 */
535 JNIEXPORT void JNICALL
536 Java_org_openafs_jafs_Volume_dump (JNIEnv *env, jclass cls,
537 jlong cellHandle, jlong serverHandle,
538 jint partition, jint volID,
539 jint startTime, jstring jdumpFile) {
540
541 afs_status_t ast;
542 const char *dumpFile;
543
544 if( jdumpFile != NULL ) {
545 dumpFile = (*env)->GetStringUTFChars(env, jdumpFile, 0);
546 if( !dumpFile ) {
547 throwAFSException( env, JAFSADMNOMEM );
548 return;
549 }
550 } else {
551 dumpFile = NULL;
552 }
553
554 if( !vos_VolumeDump( (void *) cellHandle, (void *) serverHandle, NULL,
555 (unsigned int *) &partition, (unsigned int) volID,
556 (unsigned int) startTime, dumpFile, &ast ) ) {
557 if( dumpFile != NULL ) {
558 (*env)->ReleaseStringUTFChars(env, jdumpFile, dumpFile);
559 }
560 throwAFSException( env, ast );
561 return;
562 }
563
564 if( dumpFile != NULL ) {
565 (*env)->ReleaseStringUTFChars(env, jdumpFile, dumpFile);
566 }
567
568 }
569
570 /**
571 * Restores the specified volume from a dump file.
572 *
573 * env the Java environment
574 * cls the current Java class
575 * cellHandle the handle of the cell to which the volume belongs
576 * serverHandle the vos handle of the server on which the volume is
577 * to reside
578 * partition the numeric id of the partition on which the volume is
579 * to reside
580 * volId the numeric id to assign the restored volume (can be 0)
581 * jvolName the name of the volume to restore as
582 * jdumpFile the full path of the dump file from which to restore
583 * incremental if true, restores an incremental dump over an existing
584 * volume (server and partition values must correctly
585 * indicate the current position of the existing volume),
586 * otherwise restores a full dump
587 */
588 JNIEXPORT void JNICALL
589 Java_org_openafs_jafs_Volume_restore (JNIEnv *env, jclass cls,
590 jlong cellHandle, jlong serverHandle,
591 jint partition, jint volID,
592 jstring jvolName, jstring jdumpFile,
593 jboolean incremental) {
594
595 afs_status_t ast;
596 const char *volName;
597 const char *dumpFile;
598 int *volumeIDp;
599 vos_volumeRestoreType_t vrt;
600
601 if( jvolName != NULL ) {
602 volName = (*env)->GetStringUTFChars(env, jvolName, 0);
603 if( !volName ) {
604 throwAFSException( env, JAFSADMNOMEM );
605 return;
606 }
607 } else {
608 volName = NULL;
609 }
610
611 if( jdumpFile != NULL ) {
612 dumpFile = (*env)->GetStringUTFChars(env, jdumpFile, 0);
613 if( !dumpFile ) {
614 if( volName != NULL ) {
615 (*env)->ReleaseStringUTFChars(env, jvolName, volName);
616 }
617 throwAFSException( env, JAFSADMNOMEM );
618 return;
619 }
620 } else {
621 dumpFile = NULL;
622 }
623
624 if( volID == 0 ) {
625 volumeIDp = NULL;
626 } else {
627 volumeIDp = (int *) &volID;
628 }
629
630 if( incremental ) {
631 vrt = VOS_RESTORE_INCREMENTAL;
632 } else {
633 vrt = VOS_RESTORE_FULL;
634 }
635
636 if( !vos_VolumeRestore( (void *) cellHandle, (void *) serverHandle, NULL,
637 (unsigned int) partition, (unsigned int *) volumeIDp,
638 volName, dumpFile, vrt, &ast ) ) {
639 if( volName != NULL ) {
640 (*env)->ReleaseStringUTFChars(env, jvolName, volName);
641 }
642 if( dumpFile != NULL ) {
643 (*env)->ReleaseStringUTFChars(env, jdumpFile, dumpFile);
644 }
645 throwAFSException( env, ast );
646 return;
647 }
648
649 if( dumpFile != NULL ) {
650 (*env)->ReleaseStringUTFChars(env, jdumpFile, dumpFile);
651 }
652 if( volName != NULL ) {
653 (*env)->ReleaseStringUTFChars(env, jvolName, volName);
654 }
655
656 }
657
658 /**
659 * Renames the specified read-write volume.
660 *
661 * env the Java environment
662 * cls the current Java class
663 * cellHandle the handle of the cell to which the volume belongs
664 * volId the numeric id of the read-write volume to rename
665 * jnewName the new name for the volume
666 */
667 JNIEXPORT void JNICALL
668 Java_org_openafs_jafs_Volume_rename (JNIEnv *env, jclass cls,
669 jlong cellHandle, jint volID,
670 jstring jnewName) {
671
672 afs_status_t ast;
673 const char *newName;
674
675 if( jnewName != NULL ) {
676 newName = (*env)->GetStringUTFChars(env, jnewName, 0);
677 if( !newName ) {
678 throwAFSException( env, JAFSADMNOMEM );
679 return;
680 }
681 } else {
682 newName = NULL;
683 }
684
685 if( !vos_VolumeRename( (void *) cellHandle, NULL, (unsigned int) volID,
686 newName, &ast ) ) {
687 if( newName != NULL ) {
688 (*env)->ReleaseStringUTFChars(env, jnewName, newName);
689 }
690 throwAFSException( env, ast );
691 return;
692 }
693
694 if( newName != NULL ) {
695 (*env)->ReleaseStringUTFChars(env, jnewName, newName);
696 }
697
698 }
699
700 /**
701 * "Mounts" the specified volume, bringing it online.
702 *
703 * env the Java environment
704 * cls the current Java class
705 * serverHandle the vos handle of the server on which the volume
706 * resides
707 * partition the numeric id of the partition on which the volume
708 * resides
709 * volId the numeric id of the volume to bring online
710 * sleepTime ? (not sure what this is yet, possibly a time to wait
711 * before brining it online)
712 * offline ? (not sure what this is either, probably the current
713 * status of the volume -- busy or offline)
714 */
715 JNIEXPORT void JNICALL
716 Java_org_openafs_jafs_Volume_mount (JNIEnv *env, jclass cls,
717 jlong serverHandle, jint partition,
718 jint volID, jint sleepTime,
719 jboolean offline) {
720
721 afs_status_t ast;
722 vos_volumeOnlineType_t volumeStatus;
723
724 if( offline ) {
725 volumeStatus = VOS_ONLINE_OFFLINE;
726 } else {
727 volumeStatus = VOS_ONLINE_BUSY;
728 }
729
730 if( !vos_VolumeOnline( (void *) serverHandle, NULL, (unsigned int) partition,
731 (unsigned int) volID, (unsigned int) sleepTime,
732 volumeStatus, &ast ) ) {
733 throwAFSException( env, ast );
734 return;
735 }
736
737 }
738
739 /**
740 * "Unmounts" the specified volume, bringing it offline.
741 *
742 * env the Java environment
743 * cls the current Java class
744 * serverHandle the vos handle of the server on which the volume
745 * resides
746 * partition the numeric id of the partition on which the volume
747 * resides
748 * volId the numeric id of the volume to bring offline
749 */
750 JNIEXPORT void JNICALL
751 Java_org_openafs_jafs_Volume_unmount (JNIEnv *env, jclass cls,
752 jlong serverHandle, jint partition,
753 jint volID) {
754
755 afs_status_t ast;
756
757 if( !vos_VolumeOffline( (void *) serverHandle, NULL,
758 (unsigned int) partition, (unsigned int) volID,
759 &ast ) ) {
760 throwAFSException( env, ast );
761 return;
762 }
763
764 }
765
766 /**
767 * Locks the VLDB entry specified volume
768 *
769 * env the Java environment
770 * cls the current Java class
771 * cellHandle the handle of the cell on which the volume resides
772 * volId the numeric id of the volume to lock
773 */
774 JNIEXPORT void JNICALL
775 Java_org_openafs_jafs_Volume_lock (JNIEnv *env, jclass cls,
776 jlong cellHandle, jint volID ) {
777
778 afs_status_t ast;
779
780 if( !vos_VLDBEntryLock( (void *) cellHandle, NULL, (unsigned int) volID,
781 &ast ) ) {
782 throwAFSException( env, ast );
783 return;
784 }
785
786 }
787
788 /**
789 * Unlocks the VLDB entry of the specified volume
790 *
791 * env the Java environment
792 * cls the current Java class
793 * cellHandle the handle of the cell on which the volume resides
794 * volId the numeric id of the volume to unlock
795 */
796 JNIEXPORT void JNICALL
797 Java_org_openafs_jafs_Volume_unlock (JNIEnv *env, jclass cls,
798 jlong cellHandle, jint volID) {
799
800 afs_status_t ast;
801
802 if( !vos_VLDBEntryUnlock( (void *) cellHandle, NULL, (unsigned int) volID,
803 &ast ) ) {
804 throwAFSException( env, ast );
805 return;
806 }
807
808 }
809
810 /**
811 * Translates a volume name into a volume id
812 *
813 * env the Java environment
814 * cls the current Java class
815 * cellHandle the handle of the cell to which the volume belongs
816 * jname the name of the volume in question, cannot end in backup or
817 * readonly
818 * type the type of volume: read-write, read-only, or backup.
819 * Acceptable values are:
820 * org_openafs_jafs_Volume_VOLUME_TYPE_READ_WRITE
821 * org_openafs_jafs_Volume_VOLUME_TYPE_READ_ONLY
822 * org_openafs_jafs_Volume_VOLUME_TYPE_BACKUP
823 * returns the id of the volume in question
824 */
825 JNIEXPORT jint JNICALL
826 Java_org_openafs_jafs_Volume_translateNameToID (JNIEnv *env, jclass cls,
827 jlong cellHandle,
828 jstring jname, jint type) {
829
830 afs_status_t ast;
831 const char *name;
832 vos_vldbEntry_t vldbEntry;
833
834 if( jname != NULL ) {
835 name = (*env)->GetStringUTFChars(env, jname, 0);
836 if( !name ) {
837 throwAFSException( env, JAFSADMNOMEM );
838 return;
839 }
840 } else {
841 name = NULL;
842 }
843
844 // get the id
845 if( !vos_VLDBGet( (void *) cellHandle, NULL, NULL, name,
846 &vldbEntry, &ast ) ) {
847 if( name != NULL ) {
848 (*env)->ReleaseStringUTFChars(env, jname, name);
849 }
850 throwAFSException( env, ast );
851 return -1;
852 }
853
854 if( name != NULL ) {
855 (*env)->ReleaseStringUTFChars(env, jname, name);
856 }
857
858 if( type == org_openafs_jafs_Volume_VOLUME_TYPE_READ_WRITE ) {
859 return vldbEntry.volumeId[VOS_READ_WRITE_VOLUME];
860 } else if( type == org_openafs_jafs_Volume_VOLUME_TYPE_READ_ONLY ) {
861 return vldbEntry.volumeId[VOS_READ_ONLY_VOLUME];
862 } else {
863 return vldbEntry.volumeId[VOS_BACKUP_VOLUME];
864 }
865
866 }
867
868
869 // reclaim global memory being used by this portion
870 JNIEXPORT void JNICALL
871 Java_org_openafs_jafs_Volume_reclaimVolumeMemory (JNIEnv *env, jclass cls) {
872
873 if( volumeCls ) {
874 (*env)->DeleteGlobalRef(env, volumeCls);
875 volumeCls = 0;
876 }
877
878 }
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901