2 * Copyright 2000, International Business Machines Corporation and others.
5 * This software has been released under the terms of the IBM Public
6 * License. For details, see the LICENSE file in the top-level source
7 * directory or online at http://www.openafs.org/dl/license10.html
10 #include <afsconfig.h>
11 #include <afs/param.h>
16 #include <sys/types.h>
19 #include <sys/statfs.h>
26 #include <netinet/in.h>
29 #include <afs/voldefs.h>
32 #include <afs/vlserver.h>
35 #include <afs/cellconfig.h>
38 #include <afs/afsint.h>
42 #include <afs/com_err.h>
44 #include <afs/kautils.h>
47 #define ERRCODE_RANGE 8 /* from error_table.h */
48 #define CLOCKSKEW 2 /* not really skew, but resolution */
50 /* for UV_MoveVolume() recovery */
52 #include <afs/procmgmt.h> /* signal(), kill(), wait(), etc. */
55 afs_int32 VolumeExists(), CheckVldbRWBK(), CheckVldb();
57 struct ubik_client *cstruct;
59 extern struct rx_securityClass *rxnull_NewClientSecurityObject();
60 extern struct rx_connection *rx_NewConnection();
61 extern void AFSVolExecuteRequest();
62 extern struct rx_securityClass *rxnull_NewServerSecurityObject();
63 extern int VL_GetNewVolumeId();
64 extern int VL_SetLock();
65 extern int VL_ReleaseLock();
66 extern int VL_DeleteEntry();
70 afs_int32 vldbEntryIndex;
73 /*map the partition <partId> into partition name <partName>*/
74 MapPartIdIntoName(partId, partName)
78 if(partId < 26) {/* what if partId > = 26 ? */
79 strcpy(partName,"/vicep");
80 partName[6] = partId + 'a';
83 } else if (partId < VOLMAXPARTS) {
84 strcpy(partName,"/vicep");
86 partName[6] = 'a' + (partId/26);
87 partName[7] = 'a' + (partId%26);
99 fprintf(STDERR, "Do you want to %s? [yn](n): ", str);
100 response = c = getchar();
101 while (!(c==EOF || c=='\n')) c=getchar(); /*skip to end of line*/
102 code = (response=='y'||response=='Y');
107 PrintError(msg, errcode)
112 /*replace by a big switch statement*/
116 case -1 : fprintf(STDERR,"Possible communication failure\n");
118 case VSALVAGE: fprintf(STDERR,"Volume needs to be salvaged\n");
120 case VNOVNODE: fprintf(STDERR,"Bad vnode number quoted\n");
122 case VNOVOL: fprintf(STDERR,"Volume not attached, does not exist, or not on line\n");
124 case VVOLEXISTS:fprintf(STDERR,"Volume already exists\n");
126 case VNOSERVICE:fprintf(STDERR,"Volume is not in service\n");
128 case VOFFLINE: fprintf(STDERR,"Volume is off line\n");
130 case VONLINE: fprintf(STDERR,"Volume is already on line\n");
132 case VDISKFULL: fprintf(STDERR,"Partition is full\n");
134 case VOVERQUOTA:fprintf(STDERR,"Volume max quota exceeded\n");
136 case VBUSY: fprintf(STDERR,"Volume temporarily unavailable\n");
138 case VMOVED:fprintf(STDERR,"Volume has moved to another server\n");
140 case VL_IDEXIST : fprintf(STDERR,"VLDB: volume Id exists in the vldb\n");
142 case VL_IO: fprintf(STDERR,"VLDB: a read terminated too early\n");
144 case VL_NAMEEXIST: fprintf(STDERR,"VLDB: volume entry exists in the vldb\n");
146 case VL_CREATEFAIL: fprintf(STDERR,"VLDB: internal creation failure\n");
148 case VL_NOENT: fprintf(STDERR,"VLDB: no such entry\n");
150 case VL_EMPTY: fprintf(STDERR,"VLDB: vldb database is empty\n");
152 case VL_ENTDELETED: fprintf(STDERR,"VLDB: entry is deleted (soft delete)\n");
154 case VL_BADNAME: fprintf(STDERR,"VLDB: volume name is illegal\n");
156 case VL_BADINDEX: fprintf(STDERR,"VLDB: index was out of range\n");
158 case VL_BADVOLTYPE: fprintf(STDERR,"VLDB: bad volume type\n");
160 case VL_BADSERVER: fprintf(STDERR,"VLDB: illegal server number (not within limits)\n");
162 case VL_BADPARTITION: fprintf(STDERR,"VLDB: bad partition number\n");
164 case VL_REPSFULL: fprintf(STDERR,"VLDB: run out of space for replication sites\n");
166 case VL_NOREPSERVER: fprintf(STDERR,"VLDB: no such repsite server exists\n");
168 case VL_DUPREPSERVER: fprintf(STDERR,"VLDB: replication site server already exists\n");
170 case VL_RWNOTFOUND: fprintf(STDERR,"VLDB: parent r/w entry not found\n");
172 case VL_BADREFCOUNT: fprintf(STDERR,"VLDB: illegal reference count number\n");
174 case VL_SIZEEXCEEDED: fprintf(STDERR,"VLDB: vldb size for attributes exceeded\n");
176 case VL_BADENTRY: fprintf(STDERR,"VLDB: bad incoming vldb entry\n");
178 case VL_BADVOLIDBUMP: fprintf(STDERR,"VLDB: illegal max volid increment\n");
180 case VL_IDALREADYHASHED: fprintf(STDERR,"VLDB: (RO/BACK) Id already hashed\n");
182 case VL_ENTRYLOCKED: fprintf(STDERR,"VLDB: vldb entry is already locked\n");
184 case VL_BADVOLOPER: fprintf(STDERR,"VLDB: bad volume operation code\n");
186 case VL_BADRELLOCKTYPE: fprintf(STDERR,"VLDB: bad release lock type\n");
188 case VL_RERELEASE: fprintf(STDERR,"VLDB: status report: last release was aborted\n");
190 case VL_BADSERVERFLAG: fprintf(STDERR,"VLDB: invalid replication site server flag\n");
192 case VL_PERM: fprintf(STDERR,"VLDB: no permission access for call\n");
194 case VOLSERREAD_DUMPERROR:fprintf(STDERR,"VOLSER: Problems encountered in reading the dump file !\n");
196 case VOLSERDUMPERROR:fprintf(STDERR,"VOLSER: Problems encountered in doing the dump !\n");
198 case VOLSERATTACH_ERROR: fprintf(STDERR,"VOLSER: Could not attach the volume\n");
200 case VOLSERDETACH_ERROR: fprintf(STDERR,"VOLSER: Could not detach the volume\n");
202 case VOLSERILLEGAL_PARTITION: fprintf(STDERR,"VOLSER: encountered illegal partition number\n");
204 case VOLSERBAD_ACCESS: fprintf(STDERR,"VOLSER: permission denied, not a super user\n");
206 case VOLSERVLDB_ERROR: fprintf(STDERR,"VOLSER: error detected in the VLDB\n");
208 case VOLSERBADNAME: fprintf(STDERR,"VOLSER: error in volume name\n");
210 case VOLSERVOLMOVED: fprintf(STDERR,"VOLSER: volume has moved\n");
212 case VOLSERBADOP: fprintf(STDERR,"VOLSER: illegal operation\n");
214 case VOLSERBADRELEASE: fprintf(STDERR,"VOLSER: release could not be completed\n");
216 case VOLSERVOLBUSY: fprintf(STDERR,"VOLSER: volume is busy\n");
218 case VOLSERNO_MEMORY: fprintf(STDERR,"VOLSER: volume server is out of memory\n");
220 case VOLSERNOVOL:fprintf(STDERR,"VOLSER: no such volume - location specified incorrectly or volume does not exist\n");
222 case VOLSERMULTIRWVOL: fprintf(STDERR,"VOLSER: multiple RW volumes with same ID, one of which should be deleted\n");
224 case VOLSERFAILEDOP: fprintf(STDERR,"VOLSER: not all entries were successfully processed\n");
231 initialize_ka_error_table();
232 initialize_rxk_error_table();
233 initialize_ktc_error_table();
234 initialize_acfg_error_table();
235 initialize_cmd_error_table();
236 initialize_vl_error_table();
238 offset = errcode & ((1<<ERRCODE_RANGE)-1);
239 fprintf(STDERR,"%s: %s\n",error_table_name (errcode), error_message (errcode));
247 static struct rx_securityClass *uvclass=0;
248 static int uvindex = -1;
249 /* called by VLDBClient_Init to set the security module to be used in the RPC */
250 UV_SetSecurity(as, aindex)
251 register struct rx_securityClass *as;
257 /* bind to volser on <port> <aserver> */
258 /* takes server address in network order, port in host order. dumb */
259 struct rx_connection *UV_Bind(aserver, port)
260 afs_int32 aserver, port;
262 register struct rx_connection *tc;
264 tc = rx_NewConnection(aserver, htons(port), VOLSERVICE_ID, uvclass, uvindex);
268 /* if <okvol> is allright(indicated by beibg able to
269 * start a transaction, delete the <delvol> */
270 static afs_int32 CheckAndDeleteVolume(aconn,apart,okvol,delvol)
271 struct rx_connection *aconn;
272 afs_int32 apart,okvol,delvol;
274 afs_int32 error,code,tid,rcode;
280 code = AFSVolTransCreate(aconn, delvol, apart, ITOffline,&tid);
281 if(!error && code) error = code;
282 code = AFSVolDeleteVolume(aconn,tid);
283 if(!error && code) error = code;
284 code = AFSVolEndTrans(aconn,tid, &rcode);
285 if(!code) code = rcode;
286 if(!error && code) error = code;
290 code = AFSVolTransCreate(aconn, okvol, apart, ITOffline,&tid);
292 code = AFSVolEndTrans(aconn,tid, &rcode);
293 if(!code) code = rcode;
294 if(!error && code) error = code;
295 code = AFSVolTransCreate(aconn, delvol, apart, ITOffline,&tid);
296 if(!error && code) error = code;
297 code = AFSVolDeleteVolume(aconn,tid);
298 if(!error && code) error = code;
299 code = AFSVolEndTrans(aconn,tid, &rcode);
300 if(!code) code = rcode;
301 if(!error && code) error = code;
309 /* called by EmuerateEntry, show vldb entry in a reasonable format */
310 void SubEnumerateEntry(entry)
311 struct nvldbentry *entry;
318 fprintf(STDOUT," readWriteID %-10u ",entry->volumeId[RWVOL]);
319 if(entry->flags & RW_EXISTS) fprintf(STDOUT," valid \n");else fprintf(STDOUT," invalid \n");
320 fprintf(STDOUT," readOnlyID %-10u ",entry->volumeId[ROVOL]);
321 if(entry->flags & RO_EXISTS) fprintf(STDOUT," valid \n") ;else fprintf(STDOUT," invalid \n");
322 fprintf(STDOUT," backUpID %-10u ",entry->volumeId[BACKVOL]);
323 if(entry->flags & BACK_EXISTS) fprintf(STDOUT," valid \n"); else fprintf(STDOUT," invalid \n");
324 if((entry->cloneId != 0) && (entry->flags & RO_EXISTS))
325 fprintf(STDOUT," releaseClone %-10u \n",entry->cloneId);
327 if (entry->flags & RW_EXISTS)
328 fprintf(STDOUT," RWrite: %-10u",entry->volumeId[RWVOL]);
329 if (entry->flags & RO_EXISTS)
330 fprintf(STDOUT," ROnly: %-10u",entry->volumeId[ROVOL]);
331 if (entry->flags & BACK_EXISTS)
332 fprintf(STDOUT," Backup: %-10u",entry->volumeId[BACKVOL]);
333 if ((entry->cloneId != 0) && (entry->flags & RO_EXISTS))
334 fprintf(STDOUT," RClone: %-10u",entry->cloneId);
335 fprintf(STDOUT,"\n");
337 fprintf(STDOUT," number of sites -> %u\n",entry->nServers);
338 for(i = 0; i < entry->nServers; i++) {
339 if(entry->serverFlags[i] & NEW_REPSITE)
342 for(i = 0; i < entry->nServers; i++) {
343 MapPartIdIntoName(entry->serverPartition[i],pname);
344 fprintf(STDOUT," server %s partition %s ",
345 hostutil_GetNameByINet(entry->serverNumber[i]), pname);
346 if(entry->serverFlags[i] & ITSRWVOL) fprintf(STDOUT,"RW Site ") ; else fprintf(STDOUT,"RO Site ");
348 if (entry->serverFlags[i] & NEW_REPSITE)
349 fprintf(STDOUT," -- New release");
351 fprintf(STDOUT," -- Old release");
353 if (entry->serverFlags[i] & RO_DONTUSE)
354 fprintf(STDOUT," -- Not released");
356 fprintf(STDOUT,"\n");
363 /*enumerate the vldb entry corresponding to <entry> */
364 void EnumerateEntry(entry)
365 struct nvldbentry *entry;
371 fprintf(STDOUT,"\n");
372 fprintf(STDOUT,"%s \n",entry->name);
373 SubEnumerateEntry(entry);
377 /* forcibly remove a volume. Very dangerous call */
378 UV_NukeVolume(server, partid, volid)
380 afs_int32 partid, volid; {
381 register struct rx_connection *tconn;
382 register afs_int32 code;
384 tconn = UV_Bind(server, AFSCONF_VOLUMEPORT);
386 code = AFSVolNukeVolume(tconn, partid, volid);
387 rx_DestroyConnection(tconn);
393 /* like df. Return usage of <pname> on <server> in <partition> */
394 UV_PartitionInfo(server,pname,partition)
397 struct diskPartition *partition;
399 register struct rx_connection *aconn;
403 aconn = (struct rx_connection *)0;
404 aconn = UV_Bind(server, AFSCONF_VOLUMEPORT);
405 code = AFSVolPartitionInfo(aconn,pname,partition);
407 fprintf(STDERR,"Could not get information on partition %s\n",pname);
410 if(aconn) rx_DestroyConnection(aconn);
414 /* old interface to create volume */
415 UV_CreateVolume(aserver, apart, aname, anewid)
416 afs_int32 apart, aserver;
421 code = UV_CreateVolume2(aserver, apart, aname, 5000, 0, 0, 0, 0, anewid);
425 /* create a volume, given a server, partition number, volume name --> sends
426 * back new vol id in <anewid>*/
427 UV_CreateVolume2(aserver, apart, aname, aquota, aspare1, aspare2, aspare3, aspare4, anewid)
428 afs_int32 apart, aserver;
429 afs_int32 aspare1, aspare2, aspare3, aspare4;
435 register struct rx_connection *aconn;
437 register afs_int32 code;
439 afs_int32 rcode,vcode;
440 struct nvldbentry entry,storeEntry;/*the new vldb entry */
441 struct volintInfo tstatus;
444 aconn = (struct rx_connection *)0;
446 memset(&tstatus, 0, sizeof(struct volintInfo));
448 tstatus.maxquota = aquota;
450 aconn = UV_Bind(aserver, AFSCONF_VOLUMEPORT);
451 /* next the next 3 available ids from the VLDB */
452 vcode = ubik_Call(VL_GetNewVolumeId,cstruct, 0, 3, anewid);
454 fprintf(STDERR,"Could not get an Id for volume %s\n",aname);
458 code = AFSVolCreateVolume(aconn, apart, aname, volser_RW, 0, anewid, &tid);
460 fprintf(STDERR,"Failed to create the volume %s %u \n",aname,*anewid);
465 code = AFSVolSetInfo(aconn, tid, &tstatus);
467 fprintf(STDERR,"Could not change quota (error %d), continuing...\n", code);
470 code = AFSVolSetFlags(aconn, tid, 0); /* bring it online (mark it InService */
472 fprintf(STDERR,"Could not bring the volume %s %u online \n",aname,*anewid);
476 if(verbose) fprintf(STDOUT,"Volume %s %u created and brought online\n",aname,*anewid);
477 /* set up the vldb entry for this volume */
478 strncpy(entry.name, aname,VOLSER_OLDMAXVOLNAME);
480 entry.serverNumber[0] = aserver; /* this should have another
481 level of indirection later */
482 entry.serverPartition[0] = apart; /* this should also have
483 another indirection level */
484 entry.flags = RW_EXISTS;/* this records that rw volume exists */
485 entry.serverFlags[0] = ITSRWVOL; /*this rep site has rw vol */
486 entry.volumeId[RWVOL] = *anewid;
487 entry.volumeId[ROVOL] = *anewid + 1;/* rw,ro, bk id are related in the default case */
488 entry.volumeId[BACKVOL] = *anewid + 2;
490 /*map into right byte order, before passing to xdr, the stuff has to be in host
491 byte order. Xdr converts it into network order */
492 MapNetworkToHost(&entry,&storeEntry);
493 /* create the vldb entry */
494 vcode = VLDB_CreateEntry(&storeEntry);
496 fprintf(STDERR,"Could not create a VLDB entry for the volume %s %u\n", aname,*anewid);
497 /*destroy the created volume*/
499 fprintf(STDOUT,"Deleting the newly created volume %u\n",*anewid);
501 AFSVolDeleteVolume(aconn,tid);
505 if(verbose) fprintf(STDOUT,"Created the VLDB entry for the volume %s %u\n",aname,*anewid);
506 /* volume created, now terminate the transaction and release the connection*/
507 code = AFSVolEndTrans(aconn, tid, &rcode);/*if it crashes before this
508 the volume will come online anyway when transaction timesout , so if
509 vldb entry exists then the volume is guaranteed to exist too wrt create*/
512 fprintf(STDERR,"Failed to end the transaction on the volume %s %u\n",aname,*anewid);
520 code= AFSVolEndTrans(aconn, tid, &rcode);
522 fprintf(STDERR,"WARNING: could not end transaction\n");
524 if(aconn) rx_DestroyConnection(aconn);
525 PrintError("",error);
530 /* create a volume, given a server, partition number, volume name --> sends
531 * back new vol id in <anewid>*/
532 UV_AddVLDBEntry(aserver, apart, aname, aid)
533 afs_int32 apart, aserver;
537 register struct rx_connection *aconn;
538 register afs_int32 code;
540 afs_int32 rcode,vcode;
541 struct nvldbentry entry,storeEntry;/*the new vldb entry */
543 aconn = (struct rx_connection *)0;
546 /* set up the vldb entry for this volume */
547 strncpy(entry.name, aname,VOLSER_OLDMAXVOLNAME);
549 entry.serverNumber[0] = aserver; /* this should have another
550 level of indirection later */
551 entry.serverPartition[0] = apart; /* this should also have
552 another indirection level */
553 entry.flags = RW_EXISTS;/* this records that rw volume exists */
554 entry.serverFlags[0] = ITSRWVOL; /*this rep site has rw vol */
555 entry.volumeId[RWVOL] = aid;
557 entry.volumeId[ROVOL] = anewid + 1;/* rw,ro, bk id are related in the default case */
558 entry.volumeId[BACKVOL] = *anewid + 2;
560 entry.volumeId[ROVOL] = 0;
561 entry.volumeId[BACKVOL] = 0;
564 /*map into right byte order, before passing to xdr, the stuff has to be in host
565 byte order. Xdr converts it into network order */
566 MapNetworkToHost(&entry,&storeEntry);
567 /* create the vldb entry */
568 vcode = VLDB_CreateEntry(&storeEntry);
570 fprintf(STDERR,"Could not create a VLDB entry for the volume %s %u\n", aname,aid);
574 if(verbose) fprintf(STDOUT,"Created the VLDB entry for the volume %s %u\n",aname,aid);
577 if(aconn) rx_DestroyConnection(aconn);
578 PrintError("",error);
582 #define ERROR_EXIT(code) {error=(code); goto error_exit;}
584 /* Delete the volume <volid>on <aserver> <apart>
585 * the physical entry gets removed from the vldb only if the ref count
588 UV_DeleteVolume(aserver, apart, avolid)
589 afs_int32 aserver, apart, avolid;
591 struct rx_connection *aconn = (struct rx_connection *)0;
593 afs_int32 code, rcode;
595 struct nvldbentry entry,storeEntry;
597 afs_int32 avoltype = -1, vtype;
598 int notondisk = 0, notinvldb = 0;
600 /* Find and read bhe VLDB entry for this volume */
601 code = ubik_Call(VL_SetLock, cstruct, 0, avolid, avoltype, VLOP_DELETE);
603 if (code != VL_NOENT) {
604 fprintf(STDERR,"Could not lock VLDB entry for the volume %u\n", avolid);
611 code = VLDB_GetEntryByID(avolid, avoltype, &entry);
613 fprintf(STDERR,"Could not fetch VLDB entry for volume %u\n",avolid);
616 MapHostToNetwork(&entry);
619 EnumerateEntry(&entry);
622 /* Whether volume is in the VLDB or not. Delete the volume on disk */
623 aconn = UV_Bind(aserver, AFSCONF_VOLUMEPORT);
624 code = AFSVolTransCreate(aconn, avolid, apart, ITOffline, &ttid);
626 if (code == VNOVOL) {
629 fprintf(STDERR,"Transaction on volume %u failed\n", avolid);
635 fprintf(STDOUT,"Trying to delete the volume %u ...", avolid);
638 code = AFSVolDeleteVolume(aconn, ttid);
640 fprintf(STDERR,"Could not delete the volume %u \n", avolid);
643 code = AFSVolEndTrans(aconn, ttid, &rcode);
644 code = (code ? code : rcode);
647 fprintf(STDERR,"Could not end the transaction for the volume %u \n",avolid);
651 fprintf(STDOUT," done\n");
654 /* Now update the VLDB entry.
655 * But first, verify we have a VLDB entry.
656 * Whether volume is on disk or not. Delete the volume in VLDB.
661 if (avolid == entry.volumeId[BACKVOL]) {
662 /* Its a backup volume, modify the VLDB entry. Check that the
663 * backup volume is on the server/partition we asked to delete.
665 if ( !(entry.flags & BACK_EXISTS) || !Lp_Match(aserver,apart,&entry)) {
666 notinvldb = 2; /* Not on this server and partition */
671 fprintf(STDOUT,"Marking the backup volume %u deleted in the VLDB\n", avolid);
673 entry.flags &= ~BACK_EXISTS;
677 else if (avolid == entry.volumeId[ROVOL]) {
678 /* Its a read-only volume, modify the VLDB entry. Check that the
679 * readonly volume is on the server/partition we asked to delete.
680 * If flags does not have RO_EIXSTS set, then this may mean the RO
681 * hasn't been released (and could exist in VLDB).
683 if (!Lp_ROMatch(aserver,apart,&entry)) {
684 notinvldb = 2; /* Not found on this server and partition */
689 fprintf(STDOUT,"Marking the readonly volume %u deleted in the VLDB\n", avolid);
691 Lp_SetROValue(&entry, aserver, apart, 0, 0); /* delete the site */
693 if (!Lp_ROMatch(0,0,&entry))
694 entry.flags &= ~RO_EXISTS; /* This was the last ro volume */
698 else if (avolid == entry.volumeId[RWVOL]) {
699 /* It's a rw volume, delete the backup volume, modify the VLDB entry.
700 * Check that the readwrite volumes is on the server/partition we
703 if (!(entry.flags & RW_EXISTS) || !Lp_Match(aserver,apart,&entry)) {
704 notinvldb = 2; /* Not found on this server and partition */
708 /* Delete backup if it exists */
709 code = AFSVolTransCreate(aconn, entry.volumeId[BACKVOL], apart, ITOffline, &ttid);
712 fprintf(STDOUT,"Trying to delete the backup volume %u ...", entry.volumeId[BACKVOL]);
715 code = AFSVolDeleteVolume(aconn, ttid);
717 fprintf(STDERR,"Could not delete the volume %u \n", entry.volumeId[BACKVOL]);
720 code = AFSVolEndTrans(aconn, ttid, &rcode);
722 code = (code ? code : rcode);
724 fprintf(STDERR,"Could not end the transaction for the volume %u \n",
725 entry.volumeId[BACKVOL]);
729 fprintf(STDOUT," done\n");
733 fprintf(STDOUT,"Marking the readwrite volume %u%s deleted in the VLDB\n",
734 avolid, ((entry.flags & BACK_EXISTS)?", and its backup volume,":""));
736 Lp_SetRWValue(&entry, aserver, apart, 0L, 0L);
738 entry.flags &= ~(BACK_EXISTS | RW_EXISTS);
741 if (entry.flags & RO_EXISTS)
742 fprintf(STDERR,"WARNING: ReadOnly copy(s) may still exist\n");
746 notinvldb = 2; /* Not found on this server and partition */
750 /* Either delete or replace the VLDB entry */
751 if ((entry.nServers <= 0) || !(entry.flags & (RO_EXISTS | RW_EXISTS))) {
753 fprintf(STDOUT,"Last reference to the VLDB entry for %u - deleting entry\n", avolid);
754 code = ubik_Call(VL_DeleteEntry, cstruct, 0, avolid, vtype);
756 fprintf(STDERR,"Could not delete the VLDB entry for the volume %u \n",avolid);
760 MapNetworkToHost(&entry, &storeEntry);
761 code = VLDB_ReplaceEntry(avolid, vtype, &storeEntry,
762 (LOCKREL_OPCODE | LOCKREL_AFSID | LOCKREL_TIMESTAMP));
764 fprintf(STDERR,"Could not update the VLDB entry for the volume %u \n", avolid);
771 if (error) PrintError("", error);
773 if (notondisk && notinvldb) {
774 fprintf(STDERR,"Volume %u does not exist %s\n",
775 avolid, ((notinvldb == 2)?"on server and partition":""));
776 PrintError("", VOLSERNOVOL);
777 if (!error) error = VOLSERNOVOL;
779 else if (notondisk) {
780 fprintf(STDERR,"WARNING: Volume %u did not exist on the partition\n", avolid);
782 else if (notinvldb) {
783 fprintf(STDERR,"WARNING: Volume %u does not exist in VLDB %s\n",
784 avolid, ((notinvldb == 2)?"on server and partition":""));
788 code = AFSVolEndTrans(aconn, ttid, &rcode);
789 code = (code ? code : rcode);
791 fprintf(STDERR,"Could not end transaction on the volume %u\n", avolid);
792 PrintError("", code);
793 if (!error) error = code;
798 code = ubik_Call(VL_ReleaseLock,cstruct, 0, avolid, -1,
799 (LOCKREL_OPCODE | LOCKREL_AFSID | LOCKREL_TIMESTAMP));
801 fprintf(STDERR,"Could not release the lock on the VLDB entry for the volume %u \n",
803 PrintError("", code);
804 if (!error) error = code;
808 if (aconn) rx_DestroyConnection(aconn);
812 /* add recovery to UV_MoveVolume */
814 #define TESTC 0 /* set to test recovery code, clear for production */
819 void sigint_handler(x)
825 "\nSIGINT handler: vos move operation in progress\n");
827 "WARNING: may leave AFS storage and metadata in indeterminate state\n");
829 "enter second control-c to exit\n");
833 signal(SIGINT,sigint_handler);
838 #define ONERR(ec, es, ep) if (ec) { fprintf(STDERR, (es), (ep)); PrintError(" ",ec); error = (ec); goto mfail; }
840 /* Move volume <afromvol> on <afromserver> <afrompart> to <atoserver>
841 * <atopart>. The operation is almost idempotent
844 UV_MoveVolume(afromvol, afromserver, afrompart, atoserver, atopart)
846 afs_int32 afromserver, atoserver;
847 afs_int32 afrompart, atopart;
849 struct rx_connection *toconn, *fromconn ;
850 afs_int32 fromtid, totid, clonetid;
853 char tmpName[VOLSER_MAXVOLNAME +1];
856 struct restoreCookie cookie;
857 register afs_int32 vcode, code;
858 afs_int32 newVol, volid, backupId;
859 struct volser_status tstatus;
860 struct destServer destination;
862 struct nvldbentry entry, storeEntry;
863 int i, islocked, pntg;
865 char in,lf; /* for test code */
868 #ifdef ENABLE_BUGFIX_1165
869 volEntries volumeInfo;
870 struct volintInfo *infop = 0;
874 fromconn = (struct rx_connection *)0;
875 toconn = (struct rx_connection *)0;
885 /* support control-c processing */
886 if (setjmp(env)) goto mfail;
887 (void) signal(SIGINT,sigint_handler);
892 "\nThere are three tests points - verifies all code paths through recovery.\n");
893 fprintf(STDOUT,"First test point - operation not started.\n");
894 fprintf(STDOUT,"...test here (y, n)? ");
896 fscanf(stdin,"%c",&in);
897 fscanf(stdin,"%c",&lf); /* toss away */
900 fprintf(STDOUT,"type control-c\n");
908 /* or drop through */
911 vcode = VLDB_GetEntryByID(afromvol, -1, &entry);
912 ONERR (vcode, "Could not fetch the entry for the volume %u from the VLDB \n", afromvol);
914 if (entry.volumeId[RWVOL] != afromvol)
916 fprintf(STDERR,"Only RW volume can be moved\n");
920 vcode = ubik_Call(VL_SetLock, cstruct, 0,afromvol, RWVOL, VLOP_MOVE);
921 ONERR (vcode, "Could not lock entry for volume %u \n", afromvol);
924 vcode = VLDB_GetEntryByID (afromvol, RWVOL, &entry);
925 ONERR (vcode, "Could not fetch the entry for the volume %u from the VLDB \n", afromvol);
927 backupId = entry.volumeId[BACKVOL];
928 MapHostToNetwork(&entry);
930 if ( !Lp_Match(afromserver, afrompart, &entry) )
932 /* the from server and partition do not exist in the vldb entry corresponding to volid */
933 if ( !Lp_Match(atoserver, atopart, &entry) )
935 /* the to server and partition do not exist in the vldb entry corresponding to volid */
936 fprintf(STDERR,"The volume %u is not on the specified site. \n", afromvol);
937 fprintf(STDERR,"The current site is :");
938 for (i=0; i<entry.nServers; i++)
940 if (entry.serverFlags[i] == ITSRWVOL)
943 MapPartIdIntoName(entry.serverPartition[i],pname);
944 fprintf(STDERR," server %s partition %s \n",
945 hostutil_GetNameByINet(entry.serverNumber[i]), pname);
948 vcode = ubik_Call(VL_ReleaseLock, cstruct, 0, afromvol, -1,
949 (LOCKREL_OPCODE | LOCKREL_AFSID | LOCKREL_TIMESTAMP));
950 ONERR (vcode, " Could not release lock on the VLDB entry for the volume %u \n",
953 return VOLSERVOLMOVED;
956 /* delete the volume afromvol on src_server */
957 /* from-info does not exist but to-info does =>
958 * we have already done the move, but the volume
959 * may still be existing physically on from fileserver
961 fromconn = UV_Bind(afromserver, AFSCONF_VOLUMEPORT);
965 code = AFSVolTransCreate(fromconn, afromvol, afrompart, ITOffline, &fromtid);
967 { /* volume exists - delete it */
968 code = AFSVolSetFlags(fromconn, fromtid, VTDeleteOnSalvage | VTOutOfService);
969 ONERR (code, "Failed to set flags on the volume %u\n", afromvol);
971 code = AFSVolDeleteVolume(fromconn,fromtid);
972 ONERR (code, "Failed to delete the volume %u\n", afromvol);
974 code = AFSVolEndTrans(fromconn, fromtid, &rcode);
976 if (!code) code = rcode;
977 ONERR (code, "Could not end the transaction for the volume %u \n", afromvol);
980 /*delete the backup volume now */
982 code = AFSVolTransCreate(fromconn, backupId, afrompart, ITOffline, &fromtid);
984 { /* backup volume exists - delete it */
985 code = AFSVolSetFlags(fromconn, fromtid, VTDeleteOnSalvage | VTOutOfService);
986 ONERR (code, "Failed to set flags on the backup volume %u\n", backupId);
988 code = AFSVolDeleteVolume(fromconn,fromtid);
989 ONERR (code, "Could not delete the backup volume %u\n", backupId);
991 code = AFSVolEndTrans(fromconn, fromtid, &rcode);
993 if (!code) code = rcode;
994 ONERR (code,"Could not end the transaction for the backup volume %u \n",backupId);
1002 /* From-info matches the vldb info about volid,
1003 * its ok start the move operation, the backup volume
1004 * on the old site is deleted in the process
1006 if (afrompart == atopart)
1008 same = VLDB_IsSameAddrs (afromserver, atoserver, &error);
1011 fprintf(STDERR, "Failed to get info about server's %d address(es) from vlserver (err=%d); aborting call!\n",
1012 afromserver, error);
1015 if (same) ONERR (VOLSERVOLMOVED,
1016 "Warning: Moving volume %u to its home partition ignored!\n", afromvol);
1020 toconn = UV_Bind(atoserver, AFSCONF_VOLUMEPORT); /* get connections to the servers */
1021 fromconn = UV_Bind(afromserver, AFSCONF_VOLUMEPORT);
1022 fromtid = totid = 0; /* initialize to uncreated */
1025 * clone the read/write volume locally.
1028 if (verbose) fprintf(STDOUT,"Starting transaction on source volume %u ...",afromvol);
1030 code = AFSVolTransCreate(fromconn, afromvol, afrompart, ITBusy, &fromtid);
1031 ONERR (code, "Failed to create transaction on the volume %u\n", afromvol);
1032 if (verbose) fprintf(STDOUT," done\n");
1034 /* Get a clone id */
1036 vcode = ubik_Call (VL_GetNewVolumeId, cstruct, 0, 1, &newVol);
1037 ONERR (vcode, "Could not get an ID for the clone of volume %u from the VLDB\n", afromvol);
1039 /* Do the clone. Default flags on clone are set to delete on salvage and out of service */
1040 if (verbose) fprintf (STDOUT,"Cloning source volume %u ...", afromvol);
1042 strcpy(vname, "move-clone-temp");
1043 code = AFSVolClone(fromconn, fromtid, 0,readonlyVolume, vname, &newVol);
1044 ONERR (code, "Failed to clone the source volume %u\n", afromvol);
1045 if (verbose) fprintf(STDOUT," done\n");
1047 /* lookup the name of the volume we just cloned */
1049 code = AFSVolGetName(fromconn, fromtid, &volName);
1050 ONERR (code, "Failed to get the name of the volume %u\n", newVol);
1052 if (verbose) fprintf (STDOUT,"Ending the transaction on the source volume %u ...", afromvol);
1055 code = AFSVolEndTrans(fromconn, fromtid, &rcode);
1057 if (!code) code = rcode;
1058 ONERR (code, "Failed to end the transaction on the source volume %u\n", afromvol);
1059 if (verbose) fprintf (STDOUT," done\n");
1062 * Create the destination volume
1065 if (verbose) fprintf(STDOUT, "Starting transaction on the cloned volume %u ...", newVol);
1067 code = AFSVolTransCreate (fromconn, newVol, afrompart, ITOffline, &clonetid);
1068 ONERR (code, "Failed to start a transaction on the cloned volume%u\n", newVol);
1069 if (verbose) fprintf(STDOUT," done\n");
1071 code = AFSVolSetFlags (fromconn, clonetid, VTDeleteOnSalvage|VTOutOfService); /*redundant */
1072 ONERR (code, "Could not set falgs on the cloned volume %u\n", newVol);
1074 /* remember time from which we've dumped the volume */
1075 code = AFSVolGetStatus (fromconn, clonetid, &tstatus);
1076 ONERR (code, "Failed to get the status of the cloned volume %u\n", newVol);
1078 fromDate = tstatus.creationDate-CLOCKSKEW;
1080 #ifdef ENABLE_BUGFIX_1165
1082 * Get the internal volume state from the source volume. We'll use such info (i.e. dayUse)
1083 * to copy it to the new volume (via AFSSetInfo later on) so that when we move volumes we
1084 * don't use this information...
1086 volumeInfo.volEntries_val = (volintInfo *)0;/*this hints the stub to allocate space*/
1087 volumeInfo.volEntries_len = 0;
1088 code = AFSVolListOneVolume(fromconn, afrompart, afromvol, &volumeInfo);
1089 ONERR (code, "Failed to get the volint Info of the cloned volume %u\n", afromvol);
1091 infop = (volintInfo *) volumeInfo.volEntries_val;
1092 infop->maxquota = -1; /* Else it will replace the default quota */
1095 /* create a volume on the target machine */
1097 code = AFSVolTransCreate (toconn, volid, atopart, ITOffline, &totid);
1100 /* Delete the existing volume.
1101 * While we are deleting the volume in these steps, the transaction
1102 * we started against the cloned volume (clonetid above) will be
1103 * sitting idle. It will get cleaned up after 600 seconds
1105 if (verbose) fprintf(STDOUT,"Deleting pre-existing volume %u on destination ...",volid);
1108 code = AFSVolDeleteVolume(toconn, totid);
1109 ONERR (code, "Could not delete the pre-existing volume %u on destination\n", volid);
1111 code = AFSVolEndTrans(toconn, totid, &rcode);
1113 if (!code) code = rcode;
1114 ONERR (code, "Could not end the transaction on pre-existing volume %u on destination\n",
1117 if (verbose) fprintf(STDOUT," done\n");
1120 if (verbose) fprintf(STDOUT,"Creating the destination volume %u ...",volid);
1122 code = AFSVolCreateVolume (toconn, atopart, volName, volser_RW, volid, &volid, &totid);
1123 ONERR (code, "Failed to create the destination volume %u\n", volid);
1124 if (verbose) fprintf(STDOUT," done\n");
1126 strncpy(tmpName, volName, VOLSER_OLDMAXVOLNAME);
1128 volName = (char *) 0;
1130 code = AFSVolSetFlags (toconn, totid, (VTDeleteOnSalvage | VTOutOfService));
1131 ONERR(code, "Failed to set the flags on the destination volume %u\n", volid);
1134 * Now dump the clone to the new volume
1137 destination.destHost = ntohl(atoserver);
1138 destination.destPort = AFSCONF_VOLUMEPORT;
1139 destination.destSSID = 1;
1141 /* Copy the clone to the new volume */
1142 if (verbose) fprintf(STDOUT, "Dumping from clone %u on source to volume %u on destination ...",
1145 strncpy(cookie.name,tmpName,VOLSER_OLDMAXVOLNAME);
1146 cookie.type = RWVOL;
1147 cookie.parent = entry.volumeId[RWVOL];
1149 code = AFSVolForward(fromconn, clonetid, 0, &destination, totid, &cookie);
1150 ONERR (code, "Failed to move data for the volume %u\n", volid);
1151 if (verbose) fprintf(STDOUT," done\n");
1153 code = AFSVolEndTrans(fromconn, clonetid, &rcode);
1154 if (!code) code = rcode;
1156 ONERR (code, "Failed to end the transaction on the cloned volume %u\n", newVol);
1159 * reattach to the main-line volume, and incrementally dump it.
1163 fprintf(STDOUT,"Doing the incremental dump from source to destination for volume %u ... ",
1167 code = AFSVolTransCreate(fromconn, afromvol, afrompart, ITBusy, &fromtid);
1168 ONERR (code, "Failed to create a transaction on the source volume %u\n", afromvol);
1170 /* now do the incremental */
1171 code = AFSVolForward(fromconn, fromtid, fromDate, &destination, totid,&cookie);
1172 ONERR (code, "Failed to do the incremental dump from rw volume on old site to rw volume on newsite\n", 0);
1173 if (verbose)fprintf(STDOUT," done\n");
1175 /* now adjust the flags so that the new volume becomes official */
1176 code = AFSVolSetFlags(fromconn, fromtid, VTOutOfService);
1177 ONERR (code, "Failed to set the flags to make old source volume offline\n", 0);
1179 code = AFSVolSetFlags(toconn, totid, 0);
1180 ONERR (code, "Failed to set the flags to make new source volume online\n", 0);
1182 #ifdef ENABLE_BUGFIX_1165
1183 code = AFSVolSetInfo(toconn, totid, infop);
1184 ONERR (code, "Failed to set volume status on the destination volume %u\n", volid);
1187 /* put new volume online */
1188 code = AFSVolEndTrans(toconn, totid, &rcode);
1190 if (!code) code = rcode;
1191 ONERR (code, "Failed to end the transaction on the volume %u on the new site\n", afromvol);
1193 Lp_SetRWValue(&entry, afromserver, afrompart, atoserver, atopart);
1194 MapNetworkToHost(&entry,&storeEntry);
1195 storeEntry.flags &= ~BACK_EXISTS;
1199 fprintf(STDOUT, "Second test point - operation in progress but not complete.\n");
1200 fprintf(STDOUT,"...test here (y, n)? ");
1202 fscanf(stdin,"%c",&in);
1203 fscanf(stdin,"%c",&lf); /* toss away */
1206 fprintf(STDOUT,"type control-c\n");
1209 fprintf(stdout,".");
1214 /* or drop through */
1217 vcode = VLDB_ReplaceEntry (afromvol, -1, &storeEntry,
1218 (LOCKREL_OPCODE | LOCKREL_AFSID | LOCKREL_TIMESTAMP));
1221 fprintf(STDERR," Could not release the lock on the VLDB entry for the volume %s %u \n",
1222 storeEntry.name,afromvol);
1230 fprintf(STDOUT, "Third test point - operation complete but no cleanup.\n");
1231 fprintf(STDOUT,"...test here (y, n)? ");
1233 fscanf(stdin,"%c",&in);
1234 fscanf(stdin,"%c",&lf); /* toss away */
1237 fprintf(STDOUT,"type control-c\n");
1240 fprintf(stdout,".");
1245 /* or drop through */
1249 /* This is tricky. File server is very stupid, and if you mark the volume
1250 * as VTOutOfService, it may mark the *good* instance (if you're moving
1251 * between partitions on the same machine) as out of service. Since
1252 * we're cleaning this code up in DEcorum, we're just going to kludge around
1253 * it for now by removing this call. */
1254 /* already out of service, just zap it now */
1255 code = AFSVolSetFlags(fromconn, fromtid, VTDeleteOnSalvage | VTOutOfService);
1258 fprintf(STDERR,"Failed to set the flags to make the old source volume offline\n");
1262 if (atoserver != afromserver)
1264 /* set forwarding pointer for moved volumes */
1265 code = AFSVolSetForwarding(fromconn, fromtid, atoserver);
1266 ONERR (code, "Failed to set the forwarding pointer for the volume %u\n", afromvol);
1269 if (verbose) fprintf(STDOUT,"Deleting old volume %u on source ...", afromvol);
1272 code = AFSVolDeleteVolume(fromconn,fromtid); /* zap original volume */
1273 ONERR (code, "Failed to delete the old volume %u on source\n", afromvol);
1275 code = AFSVolEndTrans(fromconn, fromtid, &rcode);
1277 if (!code) code = rcode;
1278 ONERR (code, "Failed to end the transaction on the old volume %u on the source\n", afromvol);
1280 if (verbose) fprintf(STDOUT," done\n");
1282 /* Delete the backup volume on the original site */
1283 code = AFSVolTransCreate(fromconn, backupId, afrompart, ITOffline, &fromtid);
1286 fprintf(STDOUT, "WARNING : Deleting the backup volume %u on the source ...",backupId);
1289 code = AFSVolSetFlags(fromconn, fromtid, VTDeleteOnSalvage | VTOutOfService);
1290 ONERR (code, "Failed to set the flags on the backup volume on source\n", 0);
1292 code = AFSVolDeleteVolume(fromconn,fromtid);
1293 ONERR (code, "Failed to delete the backup volume on source\n", 0);
1295 code = AFSVolEndTrans(fromconn,fromtid, &rcode);
1297 if (!code) code = rcode;
1298 ONERR (code, "Failed to end the transaction on the backup volume %u on source\n", 0);
1300 fprintf(STDOUT," done\n");
1302 else code = 0; /* no backup volume? that's okay */
1305 if (verbose) fprintf(STDOUT,"Starting transaction on the cloned volume %u ...",newVol);
1308 code = AFSVolTransCreate(fromconn, newVol, afrompart, ITOffline, &clonetid);
1309 ONERR (code, "Failed to start a transaction on the cloned volume%u\n", newVol);
1311 if (verbose) fprintf(STDOUT," done\n");
1313 /* now delete the clone */
1314 if (verbose) fprintf(STDOUT,"Deleting the clone %u ...", newVol);
1317 code = AFSVolDeleteVolume(fromconn, clonetid);
1318 ONERR (code, "Failed to delete the cloned volume %u\n", newVol);
1320 if (verbose) fprintf(STDOUT," done\n");
1322 code = AFSVolEndTrans(fromconn, clonetid, &rcode);
1323 if (!code) code = rcode;
1325 ONERR (code, "Failed to end the transaction on the cloned volume %u\n", newVol);
1332 fprintf(STDOUT,"Fourth test point - operation complete.\n");
1333 fprintf(STDOUT,"...test here (y, n)? ");
1335 fscanf(stdin,"%c",&in);
1336 fscanf(stdin,"%c",&lf); /* toss away */
1339 fprintf(STDOUT,"type control-c\n");
1342 fprintf(stdout,".");
1347 /* or drop through */
1350 /* normal cleanup code */
1352 if (entry.flags & RO_EXISTS) fprintf(STDERR,"WARNING : readOnly copies still exist \n");
1356 vcode = ubik_Call(VL_ReleaseLock,cstruct, 0, afromvol, -1,
1357 (LOCKREL_OPCODE | LOCKREL_AFSID | LOCKREL_TIMESTAMP));
1360 fprintf(STDERR," Could not release the lock on the VLDB entry for the volume %u \n",
1362 if (!error) error = vcode;
1368 code = AFSVolEndTrans(fromconn, fromtid, &rcode);
1371 fprintf(STDERR,"Could not end transaction on the source's clone volume %u\n", newVol);
1372 if (!error) error = (code ? code : rcode);
1378 code = AFSVolEndTrans(fromconn, clonetid, &rcode);
1381 fprintf(STDERR,"Could not end transaction on the source's clone volume %u\n",newVol);
1382 if (!error) error = (code ? code : rcode);
1388 code = AFSVolEndTrans(toconn, totid, &rcode);
1391 fprintf(STDERR,"Could not end transaction on destination volume %u\n",afromvol);
1392 if (!error) error = (code ? code : rcode);
1395 if (volName) free(volName);
1396 #ifdef ENABLE_BUGFIX_1165
1397 if (infop) free(infop);
1399 if (fromconn) rx_DestroyConnection(fromconn);
1400 if (toconn) rx_DestroyConnection(toconn);
1401 PrintError("",error);
1404 /* come here only when the sky falls */
1409 fprintf(STDOUT,"vos move: operation interrupted, cleanup in progress...\n");
1410 fprintf(STDOUT,"clear transaction contexts\n");
1414 /* unlock VLDB entry */
1416 ubik_Call(VL_ReleaseLock, cstruct, 0, afromvol, -1,
1417 (LOCKREL_OPCODE | LOCKREL_AFSID | LOCKREL_TIMESTAMP));
1419 if (clonetid) AFSVolEndTrans(fromconn, clonetid, &rcode);
1420 if (totid) AFSVolEndTrans(toconn, totid, &rcode);
1422 { /* put it on-line */
1423 AFSVolSetFlags(fromconn,fromtid,0);
1424 AFSVolEndTrans(fromconn, fromtid, &rcode);
1428 { /* get current VLDB entry */
1429 fprintf(STDOUT,"access VLDB\n");
1432 vcode= VLDB_GetEntryByID (afromvol, -1, &entry);
1435 fprintf(STDOUT,"FATAL: VLDB access error: abort cleanup\n");
1439 MapHostToNetwork(&entry);
1441 /* Delete either the volume on the source location or the target location.
1442 * If the vldb entry still points to the source location, then we know the
1443 * volume move didn't finish so we remove the volume from the target
1444 * location. Otherwise, we remove the volume from the source location.
1446 if (Lp_Match(afromserver,afrompart,&entry)) { /* didn't move - delete target volume */
1449 "move incomplete - attempt cleanup of target partition - no guarantee\n");
1453 if (volid && toconn) {
1454 code=AFSVolTransCreate(toconn,volid,atopart, ITOffline,&totid);
1456 AFSVolSetFlags(toconn,totid, VTDeleteOnSalvage | VTOutOfService);
1457 AFSVolDeleteVolume(toconn,totid);
1458 AFSVolEndTrans(toconn,totid,&rcode);
1462 /* put source volume on-line */
1464 code=AFSVolTransCreate(fromconn, afromvol, afrompart, ITBusy, &fromtid);
1466 AFSVolSetFlags(fromconn,fromtid,0);
1467 AFSVolEndTrans(fromconn,fromtid,&rcode);
1471 else { /* yep, move complete */
1474 "move complete - attempt cleanup of source partition - no guarantee\n");
1478 /* delete backup volume */
1480 code=AFSVolTransCreate (fromconn,backupId,afrompart, ITOffline,&fromtid);
1482 AFSVolSetFlags(fromconn,fromtid, VTDeleteOnSalvage | VTOutOfService);
1483 AFSVolDeleteVolume(fromconn,fromtid);
1484 AFSVolEndTrans(fromconn,fromtid,&rcode);
1487 /* delete source volume */
1488 code=AFSVolTransCreate (fromconn, afromvol, afrompart, ITBusy, &fromtid);
1490 AFSVolSetFlags(fromconn,fromtid, VTDeleteOnSalvage | VTOutOfService);
1491 if (atoserver != afromserver)
1492 AFSVolSetForwarding(fromconn,fromtid,atoserver);
1493 AFSVolDeleteVolume(fromconn,fromtid);
1494 AFSVolEndTrans(fromconn,fromtid,&rcode);
1499 /* common cleanup - delete local clone */
1501 code = AFSVolTransCreate (fromconn, newVol, afrompart, ITOffline, &clonetid);
1503 AFSVolDeleteVolume(fromconn,clonetid);
1504 AFSVolEndTrans(fromconn,clonetid,&rcode);
1508 /* unlock VLDB entry */
1509 ubik_Call (VL_ReleaseLock, cstruct, 0, afromvol, -1,
1510 (LOCKREL_OPCODE | LOCKREL_AFSID | LOCKREL_TIMESTAMP));
1512 done: /* routine cleanup */
1513 if (volName) free(volName);
1514 #ifdef ENABLE_BUGFIX_1165
1515 if (infop) free(infop);
1517 if (fromconn) rx_DestroyConnection(fromconn);
1518 if (toconn) rx_DestroyConnection(toconn);
1521 fprintf(STDOUT,"cleanup complete - user verify desired result\n");
1527 /* Make a new backup of volume <avolid> on <aserver> and <apart>
1528 * if one already exists, update it
1531 UV_BackupVolume(aserver, apart, avolid)
1532 afs_int32 aserver, apart, avolid;
1534 struct rx_connection *aconn = (struct rx_connection *)0;
1535 afs_int32 ttid = 0, btid = 0;
1537 afs_int32 code = 0, rcode = 0;
1538 char vname[VOLSER_MAXVOLNAME +1];
1539 struct nvldbentry entry, storeEntry;
1540 afs_int32 error = 0;
1541 int vldblocked = 0, vldbmod = 0, backexists = 1;
1543 aconn = UV_Bind(aserver, AFSCONF_VOLUMEPORT);
1545 /* the calls to VLDB will succeed only if avolid is a RW volume,
1546 * since we are following the RW hash chain for searching */
1547 code = VLDB_GetEntryByID(avolid, RWVOL, &entry);
1549 fprintf(STDERR, "Could not fetch the entry for the volume %u from the VLDB \n", avolid);
1550 error = code; goto bfail;
1552 MapHostToNetwork(&entry);
1554 /* These operations require the VLDB be locked since it means the VLDB
1555 * will change or the vldb is already locked.
1557 if (!(entry.flags & BACK_EXISTS) || /* backup volume doesnt exist */
1558 (entry.flags & VLOP_ALLOPERS) || /* vldb lock already held */
1559 (entry.volumeId[BACKVOL] == INVALID_BID)) { /* no assigned backup volume id */
1561 code = ubik_Call(VL_SetLock,cstruct, 0, avolid, RWVOL, VLOP_BACKUP);
1563 fprintf(STDERR,"Could not lock the VLDB entry for the volume %u\n",avolid);
1569 /* Reread the vldb entry */
1570 code = VLDB_GetEntryByID(avolid, RWVOL, &entry);
1572 fprintf(STDERR,"Could not fetch the entry for the volume %u from the VLDB \n",avolid);
1576 MapHostToNetwork(&entry);
1579 if (!ISNAMEVALID(entry.name)) {
1580 fprintf(STDERR, "Name of the volume %s exceeds the size limit\n", entry.name);
1581 error = VOLSERBADNAME;
1585 backupID = entry.volumeId[BACKVOL];
1586 if (backupID == INVALID_BID) {
1587 /* Get a backup volume id from the VLDB and update the vldb
1590 code = ubik_Call(VL_GetNewVolumeId, cstruct, 0, 1, &backupID);
1593 "Could not allocate ID for the backup volume of %u from the VLDB\n",
1598 entry.volumeId[BACKVOL] = backupID;
1602 /* Test to see if the backup volume exists by trying to create
1603 * a transaction on the backup volume. We've assumed the backup exists.
1605 code = AFSVolTransCreate(aconn, backupID, apart, ITOffline, &btid);
1607 if (code != VNOVOL) {
1608 fprintf(STDERR,"Could not reach the backup volume %u\n", backupID);
1612 backexists = 0; /* backup volume does not exist */
1615 code = AFSVolEndTrans(aconn, btid, &rcode);
1617 if (code || rcode) {
1619 "Could not end transaction on the previous backup volume %u\n",
1621 error = (code ? code : rcode);
1626 /* Now go ahead and try to clone the RW volume.
1627 * First start a transaction on the RW volume
1629 code = AFSVolTransCreate(aconn, avolid, apart, ITBusy, &ttid);
1631 fprintf(STDERR,"Could not start a transaction on the volume %u\n",avolid);
1636 /* Clone or reclone the volume, depending on whether the backup
1637 * volume exists or not
1641 fprintf(STDOUT,"Re-cloning backup volume %u ...", backupID);
1644 code = AFSVolReClone(aconn, ttid, backupID);
1646 fprintf(STDERR,"Could not re-clone backup volume %u\n", backupID);
1653 fprintf(STDOUT,"Creating a new backup clone %u ...", backupID);
1656 strcpy(vname, entry.name);
1657 strcat(vname,".backup");
1659 code = AFSVolClone(aconn, ttid, 0,backupVolume, vname, &backupID);
1661 fprintf(STDERR,"Failed to clone the volume %u\n",avolid);
1667 /* End the transaction on the RW volume */
1668 code = AFSVolEndTrans(aconn, ttid, &rcode);
1670 if (code || rcode) {
1671 fprintf(STDERR, "Failed to end the transaction on the rw volume %u\n", avolid);
1672 error = (code ? code : rcode);
1676 /* Mork vldb as backup exists */
1677 if (!(entry.flags & BACK_EXISTS)) {
1678 entry.flags |= BACK_EXISTS;
1682 /* Now go back to the backup volume and bring it on line */
1683 code = AFSVolTransCreate(aconn, backupID, apart, ITOffline, &btid);
1685 fprintf(STDERR,"Failed to start a transaction on the backup volume %u\n",backupID);
1690 code = AFSVolSetFlags(aconn, btid, 0);
1692 fprintf(STDERR,"Could not mark the backup volume %u on line \n",backupID);
1697 code = AFSVolEndTrans(aconn, btid, &rcode);
1699 if (code || rcode) {
1700 fprintf(STDERR, "Failed to end the transaction on the backup volume %u\n", backupID);
1701 error = (code ? code : rcode);
1706 fprintf(STDOUT,"done\n");
1708 /* Will update the vldb below */
1712 code = AFSVolEndTrans(aconn, ttid, &rcode);
1713 if (code || rcode) {
1714 fprintf(STDERR, "Could not end transaction on the volume %u\n", avolid);
1716 error = (code ? code : rcode);
1721 code = AFSVolEndTrans(aconn, btid, &rcode);
1722 if (code || rcode) {
1723 fprintf(STDERR,"Could not end transaction the backup volume %u\n",backupID);
1725 error = (code ? code : rcode);
1729 /* Now update the vldb - if modified */
1732 MapNetworkToHost(&entry,&storeEntry);
1733 code = VLDB_ReplaceEntry(avolid, RWVOL, &storeEntry,
1734 (LOCKREL_OPCODE | LOCKREL_AFSID | LOCKREL_TIMESTAMP));
1736 fprintf(STDERR,"Could not update the VLDB entry for the volume %u \n",avolid);
1742 code = ubik_Call(VL_ReleaseLock,cstruct, 0, avolid, RWVOL,
1743 (LOCKREL_OPCODE | LOCKREL_AFSID | LOCKREL_TIMESTAMP));
1745 fprintf(STDERR,"Could not unlock the VLDB entry for the volume %u \n",avolid);
1753 rx_DestroyConnection(aconn);
1755 PrintError("",error);
1759 static int DelVol (conn, vid, part, flags)
1760 struct rx_connection *conn;
1761 afs_int32 vid, part, flags;
1763 afs_int32 acode, bcode, ccode, rcode, tid;
1764 ccode = rcode = tid = 0;
1766 acode = AFSVolTransCreate(conn, vid, part, flags, &tid);
1767 if (!acode) { /* It really was there */
1768 acode = AFSVolDeleteVolume(conn, tid);
1770 fprintf(STDERR, "Failed to delete volume %u.\n", vid);
1771 PrintError ("", acode);
1773 ccode = AFSVolEndTrans(conn, tid, &rcode);
1777 fprintf(STDERR, "Failed to end transaction on volume %u.\n", vid);
1778 PrintError ("", ccode);
1785 #define ONERROR(ec, ep, es) if (ec) { fprintf(STDERR, (es), (ep)); error = (ec); goto rfail; }
1786 #define ERROREXIT(ec) { error = (ec); goto rfail; }
1788 /* Get a "transaction" on this replica. Create the volume
1789 * if necessary. Return the time from which a dump should
1790 * be made (0 if it's a new volume)
1792 static int GetTrans (vldbEntryPtr, index, connPtr, transPtr, timePtr)
1793 struct nvldbentry *vldbEntryPtr;
1795 struct rx_connection **connPtr;
1796 afs_int32 *transPtr, *timePtr;
1799 struct volser_status tstatus;
1800 int code, rcode, tcode;
1802 *connPtr = (struct rx_connection *)0;
1806 /* get connection to the replication site */
1807 *connPtr = UV_Bind(vldbEntryPtr->serverNumber[index], AFSCONF_VOLUMEPORT);
1808 if (!*connPtr) goto fail; /* server is down */
1810 volid = vldbEntryPtr->volumeId[ROVOL];
1812 code = AFSVolTransCreate(*connPtr, volid, vldbEntryPtr->serverPartition[index],
1813 ITOffline, transPtr);
1815 /* If the volume does not exist, create it */
1816 if (!volid || code) {
1819 if (volid && (code != VNOVOL)){
1820 PrintError("Failed to start a transaction on the RO volume.\n",
1825 strcpy(volname, vldbEntryPtr->name);
1826 strcat(volname, ".readonly");
1829 fprintf(STDOUT,"Creating new volume %u on replication site %s: ",
1830 volid, hostutil_GetNameByINet(vldbEntryPtr->serverNumber[index]));
1834 code = AFSVolCreateVolume(*connPtr, vldbEntryPtr->serverPartition[index],
1836 vldbEntryPtr->volumeId[RWVOL], &volid, transPtr);
1838 PrintError("Failed to create the ro volume: ",code);
1841 vldbEntryPtr->volumeId[ROVOL] = volid;
1843 if (verbose) fprintf(STDOUT,"done.\n");
1845 /* The following is a bit redundant, since create sets these flags by default */
1846 code = AFSVolSetFlags(*connPtr, *transPtr, VTDeleteOnSalvage | VTOutOfService);
1848 PrintError("Failed to set flags on the ro volume: ", code);
1853 /* Otherwise, the transaction did succeed, so get the creation date of the
1854 * latest RO volume on the replication site
1858 fprintf(STDOUT,"Updating existing ro volume %u on %s ...\n",
1859 volid, hostutil_GetNameByINet(vldbEntryPtr->serverNumber[index]));
1863 code = AFSVolGetStatus(*connPtr, *transPtr, &tstatus);
1865 PrintError("Failed to get status of volume on destination: ",code);
1868 *timePtr = tstatus.creationDate-CLOCKSKEW;
1875 tcode = AFSVolEndTrans(*connPtr, *transPtr, &rcode);
1877 if (!tcode) tcode = rcode;
1878 if (tcode) PrintError("Could not end transaction on a ro volume: ", tcode);
1884 static int SimulateForwardMultiple(fromconn, fromtid, fromdate, tr,
1885 flags, cookie, results)
1886 struct rx_connection *fromconn;
1887 afs_int32 fromtid, fromdate, flags;
1890 manyResults *results;
1894 for (i=0; i<tr->manyDests_len; i++) {
1895 results->manyResults_val[i] = AFSVolForward(fromconn, fromtid,
1896 fromdate, &(tr->manyDests_val[i].server),
1897 tr->manyDests_val[i].trans, cookie);
1903 static int rel_compar (r1, r2)
1904 struct release *r1, *r2;
1906 return (r1->time - r2->time);
1909 /* UV_ReleaseVolume()
1910 * Release volume <afromvol> on <afromserver> <afrompart> to all
1911 * its RO sites (full release). Unless the previous release was
1912 * incomplete: in which case we bring the remaining incomplete
1913 * volumes up to date with the volumes that were released
1915 * forceflag: Performs a full release.
1917 * Will create a clone from the RW, then dump the clone out to
1918 * the remaining replicas. If there is more than 1 RO sites,
1919 * ensure that the VLDB says at least one RO is available all
1920 * the time: Influences when we write back the VLDB entry.
1923 UV_ReleaseVolume(afromvol, afromserver, afrompart, forceflag)
1924 afs_int32 afromserver;
1925 afs_int32 afrompart;
1930 afs_int32 code, vcode, rcode, tcode;
1931 afs_int32 cloneVolId, roVolId;
1932 struct replica *replicas=0;
1933 struct nvldbentry entry,storeEntry;
1934 int i, volcount, k, m, n, fullrelease, vldbindex;
1936 struct restoreCookie cookie;
1937 struct rx_connection **toconns=0;
1938 struct release *times=0;
1940 struct rx_connection *fromconn = (struct rx_connection *)0;
1941 afs_int32 error = 0;
1943 afs_int32 clonetid=0, onlinetid;
1944 afs_int32 fromtid=0;
1945 afs_uint32 fromdate, thisdate;
1948 manyResults results;
1949 int rwindex, roindex, roclone, roexists;
1954 } remembertime[NMAXNSERVERS];
1955 int releasecount = 0;
1956 struct volser_status volstatus;
1958 memset((char *)remembertime, 0, sizeof(remembertime));
1959 memset((char *)&results, 0, sizeof(results));
1961 vcode = ubik_Call(VL_SetLock, cstruct, 0, afromvol, RWVOL, VLOP_RELEASE);
1962 if (vcode != VL_RERELEASE)
1963 ONERROR(vcode, afromvol, "Could not lock the VLDB entry for the volume %u.\n");
1966 /* Get the vldb entry in readable format */
1967 vcode = VLDB_GetEntryByID (afromvol, RWVOL, &entry);
1968 ONERROR(vcode, afromvol, "Could not fetch the entry for the volume %u from the VLDB.\n");
1969 MapHostToNetwork(&entry);
1972 EnumerateEntry(&entry);
1974 if (!ISNAMEVALID(entry.name))
1975 ONERROR(VOLSERBADOP, entry.name,
1976 "Volume name %s is too long, rename before releasing.\n");
1977 if (entry.volumeId[RWVOL] != afromvol)
1978 ONERROR(VOLSERBADOP, afromvol,
1979 "The volume %u being released is not a read-write volume.\n");
1980 if (entry.nServers <= 1)
1981 ONERROR(VOLSERBADOP, afromvol,
1982 "Volume %u has no replicas - release operation is meaningless!\n");
1983 if (strlen(entry.name) > (VOLSER_OLDMAXVOLNAME - 10))
1984 ONERROR(VOLSERBADOP, entry.name,
1985 "RO volume name %s exceeds (VOLSER_OLDMAXVOLNAME - 10) character limit\n");
1987 /* roclone is true if one of the RO volumes is on the same
1988 * partition as the RW volume. In this case, we make the RO volume
1989 * on the same partition a clone instead of a complete copy.
1992 roindex = Lp_ROMatch(afromserver, afrompart, &entry) - 1;
1993 roclone = ((roindex == -1) ? 0 : 1);
1994 rwindex = Lp_GetRwIndex(&entry);
1996 ONERROR(VOLSERNOVOL, 0, "There is no RW volume \n");
1998 /* Make sure we have a RO volume id to work with */
1999 if (entry.volumeId[ROVOL] == INVALID_BID) {
2000 /* need to get a new RO volume id */
2001 vcode = ubik_Call(VL_GetNewVolumeId, cstruct, 0, 1, &roVolId);
2002 ONERROR(vcode, entry.name, "Cant allocate ID for RO volume of %s\n");
2004 entry.volumeId[ROVOL] = roVolId;
2005 MapNetworkToHost(&entry, &storeEntry);
2006 vcode = VLDB_ReplaceEntry(afromvol, RWVOL, &storeEntry, 0);
2007 ONERROR(vcode, entry.name, "Could not update vldb entry for %s.\n");
2010 /* Will we be completing a previously unfinished release. -force overrides */
2011 for (fullrelease=1, i=0; (fullrelease && (i<entry.nServers)); i++) {
2012 if (entry.serverFlags[i] & NEW_REPSITE)
2015 if (forceflag && !fullrelease)
2018 /* Determine which volume id to use and see if it exists */
2019 cloneVolId = ((fullrelease || (entry.cloneId == 0)) ? entry.volumeId[ROVOL] : entry.cloneId);
2020 code = VolumeExists(afromserver, afrompart, cloneVolId);
2021 roexists = ((code == ENODEV) ? 0 : 1);
2022 if (!roexists && !fullrelease)
2023 fullrelease = 1; /* Do a full release if RO clone does not exist */
2027 fprintf(STDOUT,"This is a complete release of the volume %u\n", afromvol);
2029 fprintf(STDOUT,"This is a completion of the previous release\n");
2033 fromconn = UV_Bind(afromserver, AFSCONF_VOLUMEPORT);
2035 ONERROR(-1, afromserver, "Cannot establish connection with server 0x%x\n");
2038 /* If the RO clone exists, then if the clone is a temporary
2039 * clone, delete it. Or if the RO clone is marked RO_DONTUSE
2040 * (it was recently added), then also delete it. We do not
2041 * want to "reclone" a temporary RO clone.
2044 (!roclone || (entry.serverFlags[roindex] & RO_DONTUSE)) ) {
2045 code = DelVol(fromconn, cloneVolId, afrompart, ITOffline);
2046 if (code && (code != VNOVOL))
2051 /* Mark all the ROs in the VLDB entry as RO_DONTUSE. We don't
2052 * write this entry out to the vlserver until after the first
2053 * RO volume is released (temp RO clones don't count).
2055 for (i=0; i<entry.nServers; i++) {
2056 entry.serverFlags[i] &= ~NEW_REPSITE;
2057 entry.serverFlags[i] |= RO_DONTUSE;
2059 entry.serverFlags[rwindex] |= NEW_REPSITE;
2060 entry.serverFlags[rwindex] &= ~RO_DONTUSE;
2062 /* Begin transaction on RW and mark it busy while we clone it */
2063 code = AFSVolTransCreate(fromconn, afromvol, afrompart, ITBusy, &clonetid);
2064 ONERROR(code, afromvol, "Failed to start transaction on volume %u\n");
2066 /* Clone or reclone the volume */
2069 fprintf(STDERR, "Recloning RW volume ...\n");
2071 code = AFSVolReClone(fromconn, clonetid, cloneVolId);
2072 ONERROR(code, afromvol, "Failed to reclone the RW volume %u\n");
2075 strcpy(vname, entry.name);
2076 strcat(vname, ".readonly");
2078 fprintf(STDERR, "Cloning RW volume ...\n");
2080 strcpy(vname, "readonly-clone-temp");
2082 fprintf(STDERR, "Cloning RW volume to temporary RO ...\n");
2084 code = AFSVolClone(fromconn, clonetid, 0, readonlyVolume, vname, &cloneVolId);
2085 ONERROR(code, afromvol, "Failed to clone the RW volume %u\n");
2088 /* Get the time the RW was created for future information */
2089 code = AFSVolGetStatus(fromconn, clonetid, &volstatus);
2090 ONERROR(code, cloneVolId, "Failed to get the status of the RW volume %u\n");
2091 rwcrdate = volstatus.creationDate;
2093 /* End the transaction on the RW volume */
2094 code = AFSVolEndTrans(fromconn, clonetid, &rcode);
2096 ONERROR((code?code:rcode), cloneVolId, "Failed to end cloning transaction on RW %u\n");
2098 /* Remember clone volume ID in case we fail or are interrupted */
2099 entry.cloneId = cloneVolId;
2102 /* Bring the RO clone online - though not if it's a temporary clone */
2103 code = AFSVolTransCreate(fromconn, cloneVolId, afrompart, ITOffline, &onlinetid);
2104 ONERROR(code, cloneVolId, "Failed to start transaction on volume %u\n");
2106 tcode = AFSVolSetFlags(fromconn, onlinetid, 0);
2108 code = AFSVolEndTrans(fromconn, onlinetid, &rcode);
2109 ONERROR((code?code:rcode), cloneVolId, "Failed to end transaction on RO clone %u\n");
2111 ONERROR(tcode, cloneVolId, "Could not bring volume %u on line\n");
2113 /* Sleep so that a client searching for an online volume won't
2114 * find the clone offline and then the next RO offline while the
2115 * release brings the clone online and the next RO offline (race).
2116 * There is a fix in the 3.4 client that does not need this sleep
2117 * anymore, but we don't know what clients we have.
2119 if (entry.nServers > 2)
2122 /* Mark the RO clone in the VLDB as a good site (already released)*/
2123 entry.serverFlags[roindex] |= NEW_REPSITE;
2124 entry.serverFlags[roindex] &= ~RO_DONTUSE;
2125 entry.flags |= RO_EXISTS;
2129 /* Write out the VLDB entry only if the clone is not a temporary
2130 * clone. If we did this to a temporary clone then we would end
2131 * up marking all the ROs as "old release" making the ROs
2132 * temporarily unavailable.
2134 MapNetworkToHost(&entry, &storeEntry);
2135 vcode = VLDB_ReplaceEntry(afromvol, RWVOL, &storeEntry, 0);
2136 ONERROR(vcode, entry.name, "Could not update vldb entry for %s.\n");
2140 /* Now we will release from the clone to the remaining RO replicas.
2141 * The first 2 ROs (counting the non-temporary RO clone) are released
2142 * individually: releasecount. This is to reduce the race condition
2143 * of clients trying to find an on-line RO volume. The remaining ROs
2144 * are released in parallel but no more than half the number of ROs
2145 * (rounded up) at a time: nservers.
2148 strcpy(vname, entry.name);
2149 strcat(vname, ".readonly");
2150 memset(&cookie, 0, sizeof(cookie));
2151 strncpy(cookie.name, vname, VOLSER_OLDMAXVOLNAME);
2152 cookie.type = ROVOL;
2153 cookie.parent = entry.volumeId[RWVOL];
2156 nservers = entry.nServers/2; /* how many to do at once, excluding clone */
2157 replicas = (struct replica *) malloc (sizeof(struct replica)*nservers+1);
2158 times = (struct release *) malloc (sizeof(struct release)*nservers+1);
2159 toconns = (struct rx_connection **) malloc (sizeof(struct rx_connection *)*nservers+1);
2160 results.manyResults_val = (afs_int32 *) malloc (sizeof(afs_int32)*nservers+1);
2161 if ( !replicas || !times || !! !results.manyResults_val || !toconns )
2162 ONERROR(ENOMEM, 0, "Failed to create transaction on the release clone\n");
2164 memset(replicas, 0, (sizeof(struct replica)*nservers+1));
2165 memset(times, 0, (sizeof(struct release)*nservers+1));
2166 memset(toconns, 0, (sizeof(struct rx_connection *)*nservers+1));
2167 memset(results.manyResults_val, 0, (sizeof(afs_int32)*nservers+1));
2169 /* Create a transaction on the cloned volume */
2170 code = AFSVolTransCreate(fromconn, cloneVolId, afrompart, ITBusy, &fromtid);
2171 if (!fullrelease && code)
2172 ONERROR(VOLSERNOVOL, afromvol,"Old clone is inaccessible. Try vos release -f %u.\n");
2173 ONERROR(code, 0, "Failed to create transaction on the release clone\n");
2175 /* For each index in the VLDB */
2176 for (vldbindex=0; vldbindex<entry.nServers; ) {
2178 /* Get a transaction on the replicas. Pick replacas which have an old release. */
2179 for (volcount=0; ((volcount<nservers) && (vldbindex<entry.nServers)); vldbindex++) {
2180 /* The first two RO volumes will be released individually.
2181 * The rest are then released in parallel. This is a hack
2182 * for clients not recognizing right away when a RO volume
2183 * comes back on-line.
2185 if ((volcount == 1) && (releasecount < 2))
2188 if (vldbindex == roindex) continue; /* the clone */
2189 if ( (entry.serverFlags[vldbindex] & NEW_REPSITE) &&
2190 !(entry.serverFlags[vldbindex] & RO_DONTUSE) ) continue;
2191 if (!(entry.serverFlags[vldbindex] & ITSROVOL)) continue; /* not a RO vol */
2194 /* Get a Transaction on this replica. Get a new connection if
2195 * necessary. Create the volume if necessary. Return the
2196 * time from which the dump should be made (0 if it's a new
2197 * volume). Each volume might have a different time.
2199 replicas[volcount].server.destHost = ntohl(entry.serverNumber[vldbindex]);
2200 replicas[volcount].server.destPort = AFSCONF_VOLUMEPORT;
2201 replicas[volcount].server.destSSID = 1;
2202 times[volcount].vldbEntryIndex = vldbindex;
2204 code = GetTrans(&entry, vldbindex, &(toconns[volcount]),
2205 &(replicas[volcount].trans), &(times[volcount].time));
2208 /* Thisdate is the date from which we want to pick up all changes */
2209 if (forceflag || !fullrelease || (rwcrdate > times[volcount].time)) {
2210 /* If the forceflag is set, then we want to do a full dump.
2211 * If it's not a full release, we can't be sure that the creation
2212 * date is good (so we also do a full dump).
2213 * If the RW volume was replaced (its creation date is newer than
2214 * the last release), then we can't be sure what has changed (so
2215 * we do a full dump).
2218 } else if (remembertime[vldbindex].validtime) {
2219 /* Trans was prev ended. Use the time from the prev trans
2220 * because, prev trans may have created the volume. In which
2221 * case time[volcount].time would be now instead of 0.
2223 thisdate = (remembertime[vldbindex].time < times[volcount].time) ?
2224 remembertime[vldbindex].time : times[volcount].time;
2226 thisdate = times[volcount].time;
2228 remembertime[vldbindex].validtime = 1;
2229 remembertime[vldbindex].time = thisdate;
2231 if (volcount == 0) {
2232 fromdate = thisdate;
2234 /* Include this volume if it is within 15 minutes of the earliest */
2235 if (((fromdate>thisdate)?(fromdate-thisdate):(thisdate-fromdate)) > 900) {
2236 AFSVolEndTrans(toconns[volcount], replicas[volcount].trans, &rcode);
2237 replicas[volcount].trans = 0;
2240 if (thisdate < fromdate)
2241 fromdate = thisdate;
2245 if (!volcount) continue;
2248 fprintf(STDOUT,"Starting ForwardMulti from %u to %u on %s",
2249 cloneVolId, entry.volumeId[ROVOL],
2250 hostutil_GetNameByINet(entry.serverNumber[times[0].vldbEntryIndex]));
2252 for (s=1; s<volcount; s++) {
2253 fprintf(STDOUT," and %s",
2254 hostutil_GetNameByINet(entry.serverNumber[times[s].vldbEntryIndex]));
2258 fprintf(STDOUT," (full release)");
2259 fprintf(STDOUT,".\n");
2263 /* Release the ones we have collected */
2264 tr.manyDests_val = &(replicas[0]);
2265 tr.manyDests_len = results.manyResults_len = volcount;
2266 code = AFSVolForwardMultiple(fromconn, fromtid, fromdate, &tr, 0/*spare*/, &cookie, &results);
2267 if (code == RXGEN_OPCODE) { /* RPC Interface Mismatch */
2268 code = SimulateForwardMultiple(fromconn, fromtid, fromdate, &tr, 0/*spare*/, &cookie, &results);
2273 PrintError("Release failed: ", code);
2275 for (m=0; m<volcount; m++) {
2276 if (results.manyResults_val[m]) {
2277 if ((m == 0) || (results.manyResults_val[m] != ENOENT)) {
2278 /* we retry timed out transaction. When it is
2279 * not the first volume and the transaction wasn't found
2280 * (assume it timed out and was garbage collected by volser).
2282 PrintError("Failed to dump volume from clone to a ro site: ",
2283 results.manyResults_val[m]);
2288 code = AFSVolSetIdsTypes(toconns[m], replicas[m].trans,
2289 vname, ROVOL, entry.volumeId[RWVOL], 0, 0);
2291 if ((m == 0) || (code != ENOENT)) {
2292 PrintError("Failed to set correct names and ids: ", code);
2297 /* have to clear dest. flags to ensure new vol goes online:
2298 * because the restore (forwarded) operation copied
2299 * the V_inService(=0) flag over to the destination.
2301 code = AFSVolSetFlags(toconns[m], replicas[m].trans, 0);
2303 if ((m == 0) || (code != ENOENT)) {
2304 PrintError("Failed to set flags on ro volume: ", code);
2309 entry.serverFlags[times[m].vldbEntryIndex] |= NEW_REPSITE;
2310 entry.serverFlags[times[m].vldbEntryIndex] &= ~RO_DONTUSE;
2311 entry.flags |= RO_EXISTS;
2316 /* End the transactions and destroy the connections */
2317 for (s=0; s<volcount; s++) {
2318 if (replicas[s].trans)
2319 code = AFSVolEndTrans(toconns[s], replicas[s].trans, &rcode);
2320 replicas[s].trans = 0;
2321 if (!code) code = rcode;
2323 if ((s == 0) || (code != ENOENT)) {
2324 PrintError("Could not end transaction on a ro volume: ", code);
2326 PrintError("Transaction timed out on a ro volume. Will retry.\n", 0);
2327 if (times[s].vldbEntryIndex < vldbindex)
2328 vldbindex = times[s].vldbEntryIndex;
2333 rx_DestroyConnection(toconns[s]);
2337 MapNetworkToHost(&entry, &storeEntry);
2338 vcode = VLDB_ReplaceEntry(afromvol, RWVOL, &storeEntry, 0);
2339 ONERROR(vcode, afromvol, " Could not update VLDB entry for volume %u\n");
2340 } /* for each index in the vldb */
2342 /* End the transaction on the cloned volume */
2343 code = AFSVolEndTrans(fromconn, fromtid, &rcode);
2345 if (!code) code = rcode;
2347 PrintError("Failed to end transaction on rw volume: ", code);
2349 /* Figure out if any volume were not released and say so */
2350 for (failure=0, i=0; i<entry.nServers; i++) {
2351 if (!(entry.serverFlags[i] & NEW_REPSITE))
2356 fprintf(STDERR, "The volume %u could not be released to the following %d sites:\n",
2358 for (i=0; i<entry.nServers; i++) {
2359 if (!(entry.serverFlags[i] & NEW_REPSITE)) {
2360 MapPartIdIntoName(entry.serverPartition[i],pname);
2361 fprintf(STDERR,"\t%35s %s\n",
2362 hostutil_GetNameByINet(entry.serverNumber[i]), pname);
2366 MapNetworkToHost(&entry,&storeEntry);
2367 vcode = VLDB_ReplaceEntry(afromvol, RWVOL, &storeEntry, LOCKREL_TIMESTAMP);
2368 ONERROR(vcode, afromvol, " Could not update VLDB entry for volume %u\n");
2370 ERROREXIT(VOLSERBADRELEASE);
2373 /* All the ROs were release successfully. Remove the temporary clone */
2376 fprintf(STDOUT,"Deleting the releaseClone %u ...", cloneVolId);
2379 code = DelVol (fromconn, cloneVolId, afrompart, ITOffline);
2380 ONERROR (code, cloneVolId, "Failed to delete volume %u.\n");
2382 fprintf(STDOUT," done\n");
2386 for (i=0; i<entry.nServers; i++)
2387 entry.serverFlags[i] &= ~NEW_REPSITE;
2389 /* Update the VLDB */
2391 fprintf(STDOUT,"updating VLDB ...");
2394 MapNetworkToHost(&entry, &storeEntry);
2395 vcode = VLDB_ReplaceEntry(afromvol, RWVOL, &storeEntry,
2396 LOCKREL_OPCODE | LOCKREL_AFSID | LOCKREL_TIMESTAMP);
2397 ONERROR(vcode, afromvol, " Could not update VLDB entry for volume %u\n");
2399 fprintf(STDOUT," done\n");
2403 code = AFSVolEndTrans(fromconn, clonetid, &rcode);
2406 fprintf (STDERR,"Failed to end cloning transaction on the RW volume %u\n", afromvol);
2407 if (!error) error = code;
2411 code = AFSVolEndTrans(fromconn, fromtid, &rcode);
2414 fprintf (STDERR,"Failed to end transaction on the release clone %u\n", cloneVolId);
2415 if (!error) error = code;
2418 for (i=0; i<nservers; i++) {
2419 if (replicas && replicas[i].trans) {
2420 code = AFSVolEndTrans(toconns[i], replicas[i].trans, &rcode);
2421 replicas[i].trans = 0;
2423 fprintf(STDERR,"Failed to end transaction on ro volume %u at server 0x%x\n",
2424 entry.volumeId[ROVOL],
2425 hostutil_GetNameByINet(htonl(replicas[i].server.destHost)));
2426 if (!error) error = code;
2429 if (toconns && toconns[i]) {
2430 rx_DestroyConnection(toconns[i]);
2435 vcode = ubik_Call(VL_ReleaseLock,cstruct, 0, afromvol, RWVOL,
2436 LOCKREL_OPCODE | LOCKREL_AFSID | LOCKREL_TIMESTAMP);
2438 fprintf(STDERR,"Could not release lock on the VLDB entry for volume %u\n", afromvol);
2439 if (!error) error = vcode;
2443 PrintError("", error);
2445 if (fromconn) rx_DestroyConnection(fromconn);
2446 if (results.manyResults_val) free (results.manyResults_val);
2447 if (replicas) free (replicas);
2448 if (toconns) free (toconns);
2449 if (times) free (times);
2454 void dump_sig_handler(x)
2456 fprintf(STDERR,"\nSignal handler: vos dump operation\n");
2460 /* Dump the volume <afromvol> on <afromserver> and
2461 * <afrompart> to <afilename> starting from <fromdate>.
2462 * DumpFunction does the real work behind the scenes after
2463 * extracting parameters from the rock
2465 UV_DumpVolume(afromvol, afromserver, afrompart, fromdate, DumpFunction, rock)
2466 afs_int32 afromserver;
2467 afs_int32 afrompart;
2470 afs_int32 (*DumpFunction)();
2473 struct rx_connection *fromconn = (struct rx_connection *)0;
2474 struct rx_call *fromcall = (struct rx_call *)0;
2475 afs_int32 fromtid=0, rxError=0, rcode=0;
2476 afs_int32 code, error = 0;
2478 if (setjmp(env)) ERROR_EXIT(EPIPE);
2479 #ifndef AFS_NT40_ENV
2480 (void) signal(SIGPIPE, dump_sig_handler);
2482 (void) signal(SIGINT, dump_sig_handler);
2484 /* get connections to the servers */
2485 fromconn = UV_Bind(afromserver, AFSCONF_VOLUMEPORT);
2486 code = AFSVolTransCreate(fromconn, afromvol, afrompart, ITBusy, &fromtid);
2488 fprintf(STDERR,"Could not start transaction on the volume %u to be dumped\n", afromvol);
2494 fprintf(STDERR,"Full Dump ...");
2496 fprintf(STDERR,"Incremental Dump (as of %.24s) ...",
2497 ctime((time_t *)&fromdate));
2501 fromcall = rx_NewCall(fromconn);
2502 code = StartAFSVolDump(fromcall, fromtid, fromdate);
2504 fprintf(STDERR,"Could not start the dump process \n");
2507 if (code = DumpFunction(fromcall, rock)) {
2508 fprintf(STDERR,"Error while dumping volume \n");
2513 fprintf(STDERR,"completed\n");
2517 code = rx_EndCall(fromcall, rxError);
2519 fprintf(STDERR,"Error in rx_EndCall\n");
2520 if (!error) error = code;
2524 code = AFSVolEndTrans(fromconn, fromtid, &rcode);
2525 if (code || rcode) {
2526 fprintf(STDERR,"Could not end transaction on the volume %u\n", afromvol);
2527 if (!error) error = (code?code:rcode);
2531 rx_DestroyConnection(fromconn);
2533 PrintError("", error);
2539 * Restore a volume <tovolid> <tovolname> on <toserver> <topart> from
2540 * the dump file <afilename>. WriteData does all the real work
2541 * after extracting params from the rock
2543 UV_RestoreVolume(toserver, topart, tovolid, tovolname, flags, WriteData, rock)
2544 afs_int32 toserver, topart, tovolid;
2547 afs_int32 (*WriteData)();
2550 struct rx_connection *toconn,*tempconn;
2551 struct rx_call *tocall;
2552 afs_int32 totid, code, rcode, vcode,terror = 0;
2553 afs_int32 rxError = 0;
2554 struct volser_status tstatus;
2559 struct nvldbentry entry,storeEntry;
2562 struct restoreCookie cookie;
2564 afs_int32 newDate, volflag;
2565 int index, same, errcode;
2569 memset(&cookie, 0, sizeof(cookie));
2574 tocall = (struct rx_call *)0;
2575 toconn = (struct rx_connection *)0;
2576 tempconn = (struct rx_connection *)0;
2581 toconn = UV_Bind(toserver, AFSCONF_VOLUMEPORT);
2582 if(pvolid == 0) {/*alot a new id if needed */
2583 vcode = VLDB_GetEntryByName(tovolname, &entry);
2584 if(vcode == VL_NOENT) {
2585 vcode = ubik_Call(VL_GetNewVolumeId,cstruct, 0, 1, &pvolid);
2587 fprintf(STDERR,"Could not get an Id for the volume %s\n",tovolname);
2594 pvolid = entry.volumeId[RWVOL];
2596 }/* at this point we have a volume id to use/reuse for the volume to be restored */
2598 if(strlen(tovolname) > (VOLSER_OLDMAXVOLNAME - 1)) {
2599 fprintf(STDERR,"The volume name %s exceeds the maximum limit of (VOLSER_OLDMAXVOLNAME -1 ) bytes\n",tovolname);
2600 error = VOLSERBADOP;
2603 MapPartIdIntoName(topart, partName);
2604 fprintf(STDOUT,"Restoring volume %s Id %u on server %s partition %s ..", tovolname,
2605 pvolid, hostutil_GetNameByINet(toserver), partName);
2607 /*what should the volume be restored as ? rw or ro or bk ?
2608 right now the default is rw always */
2609 code = AFSVolCreateVolume(toconn, topart, tovolname, volser_RW, 0,&pvolid, &totid);
2611 if (flags & RV_FULLRST) { /* full restore: delete then create anew */
2613 fprintf(STDOUT,"Deleting the previous volume %u ...",pvolid);
2616 code = AFSVolTransCreate(toconn, pvolid, topart, ITOffline, &totid);
2618 fprintf(STDERR,"Failed to start transaction on %u\n",pvolid);
2622 code = AFSVolSetFlags(toconn, totid, VTDeleteOnSalvage | VTOutOfService);
2624 fprintf(STDERR,"Could not set flags on volume %u \n",pvolid);
2628 code = AFSVolDeleteVolume(toconn,totid);
2630 fprintf(STDERR,"Could not delete volume %u\n",pvolid);
2634 code = AFSVolEndTrans(toconn, totid, &rcode);
2636 if (!code) code = rcode;
2638 fprintf(STDERR,"Could not end transaction on %u\n",pvolid);
2642 if (verbose) fprintf(STDOUT," done\n");
2643 code = AFSVolCreateVolume(toconn, topart, tovolname, volser_RW, 0,&pvolid, &totid);
2645 fprintf(STDERR,"Could not create new volume %u\n",pvolid);
2651 code = AFSVolTransCreate(toconn, pvolid, topart, ITOffline, &totid);
2653 fprintf(STDERR,"Failed to start transaction on %u\n",pvolid);
2659 cookie.parent = pvolid;
2660 cookie.type = RWVOL;
2662 strncpy(cookie.name,tovolname,VOLSER_OLDMAXVOLNAME);
2664 tocall = rx_NewCall(toconn);
2665 terror = StartAFSVolRestore(tocall,totid, 1,&cookie);
2667 fprintf(STDERR,"Volume restore Failed \n");
2671 code = WriteData(tocall, rock);
2673 fprintf(STDERR,"Could not transmit data\n");
2677 terror = rx_EndCall(tocall,rxError);
2678 tocall = (struct rx_call *) 0;
2680 fprintf(STDERR,"rx_EndCall Failed \n");
2684 code = AFSVolGetStatus(toconn,totid, &tstatus);
2686 fprintf(STDERR,"Could not get status information about the volume %u\n",tovolid);
2690 code = AFSVolSetIdsTypes(toconn,totid, tovolname, RWVOL, pvolid,0,0);
2692 fprintf(STDERR,"Could not set the right type and ID on %u\n",pvolid);
2697 code = AFSVolSetDate(toconn,totid, newDate);
2699 fprintf(STDERR,"Could not set the date on %u\n",pvolid);
2704 volflag = ((flags & RV_OFFLINE) ? VTOutOfService : 0); /* off or on-line */
2705 code = AFSVolSetFlags(toconn, totid, volflag);
2707 fprintf(STDERR,"Could not mark %u online\n",pvolid );
2712 /* It isn't handled right in refail */
2713 code = AFSVolEndTrans(toconn, totid, &rcode);
2715 if(!code) code = rcode;
2717 fprintf(STDERR,"Could not end transaction on %u\n",pvolid);
2723 fprintf(STDOUT," done\n");
2725 if (success && (!reuseID || (flags & RV_FULLRST))) {
2726 /* Volume was restored on the file server, update the
2727 * VLDB to reflect the change.
2729 vcode = VLDB_GetEntryByID(pvolid,RWVOL, &entry);
2730 if(vcode && vcode != VL_NOENT && vcode != VL_ENTDELETED) {
2731 fprintf(STDERR,"Could not fetch the entry for volume number %u from VLDB \n",pvolid);
2735 if (!vcode) MapHostToNetwork(&entry);
2736 if(vcode == VL_NOENT) { /* it doesnot exist already */
2737 /*make the vldb return this indication specifically*/
2738 if (verbose) fprintf(STDOUT,"------- Creating a new VLDB entry ------- \n");
2739 strcpy(entry.name, tovolname);
2741 entry.serverNumber[0] = toserver;/*should be indirect */
2742 entry.serverPartition[0] = topart;
2743 entry.serverFlags[0] = ITSRWVOL;
2744 entry.flags = RW_EXISTS;
2745 if(tstatus.cloneID != 0){
2746 entry.volumeId[ROVOL] = tstatus.cloneID;/*this should come from status info on the volume if non zero */
2749 entry.volumeId[ROVOL] = INVALID_BID;
2750 entry.volumeId[RWVOL] = pvolid;
2752 if(tstatus.backupID != 0){
2753 entry.volumeId[BACKVOL] = tstatus.backupID;
2754 /*this should come from status info on the volume if non zero */
2757 entry.volumeId[BACKVOL] = INVALID_BID;
2758 MapNetworkToHost(&entry,&storeEntry);
2759 vcode = VLDB_CreateEntry(&storeEntry);
2761 fprintf(STDERR,"Could not create the VLDB entry for volume number %u \n",pvolid);
2766 if (verbose) EnumerateEntry(&entry);
2768 else { /*update the existing entry */
2770 fprintf(STDOUT,"Updating the existing VLDB entry\n");
2771 fprintf(STDOUT,"------- Old entry -------\n");
2772 EnumerateEntry(&entry);
2773 fprintf(STDOUT,"------- New entry -------\n");
2775 vcode = ubik_Call(VL_SetLock,cstruct, 0, pvolid, RWVOL, VLOP_RESTORE);
2777 fprintf(STDERR,"Could not lock the entry for volume number %u \n",pvolid);
2782 strcpy(entry.name, tovolname);
2784 /* Update the vlentry with the new information */
2785 index = Lp_GetRwIndex(&entry);
2787 /* Add the rw site for the volume being restored */
2788 entry.serverNumber[entry.nServers] = toserver;
2789 entry.serverPartition[entry.nServers] = topart;
2790 entry.serverFlags[entry.nServers] = ITSRWVOL;
2793 /* This volume should be deleted on the old site
2794 * if its different from new site.
2796 same = VLDB_IsSameAddrs(toserver, entry.serverNumber[index], &errcode);
2798 fprintf(STDERR,"Failed to get info about server's %d address(es) from vlserver (err=%d)\n",
2801 if ( (!errcode && !same) || (entry.serverPartition[index] != topart) ) {
2802 tempconn = UV_Bind(entry.serverNumber[index], AFSCONF_VOLUMEPORT);
2804 MapPartIdIntoName(entry.serverPartition[index], apartName);
2805 fprintf(STDOUT,"Deleting the previous volume %u on server %s, partition %s ...",
2807 hostutil_GetNameByINet(entry.serverNumber[index]), apartName);
2810 code = AFSVolTransCreate(tempconn, pvolid, entry.serverPartition[index], ITOffline, &temptid);
2812 code = AFSVolSetFlags(tempconn, temptid, VTDeleteOnSalvage | VTOutOfService);
2814 fprintf(STDERR,"Could not set flags on volume %u on the older site\n",pvolid);
2818 code = AFSVolDeleteVolume(tempconn,temptid);
2820 fprintf(STDERR,"Could not delete volume %u on the older site\n",pvolid);
2824 code = AFSVolEndTrans(tempconn, temptid, &rcode);
2826 if(!code) code = rcode;
2828 fprintf(STDERR,"Could not end transaction on volume %u on the older site\n",pvolid);
2832 if(verbose) fprintf(STDOUT," done\n");
2833 MapPartIdIntoName(entry.serverPartition[index],partName);
2836 entry.serverNumber[index] = toserver;
2837 entry.serverPartition[index] = topart;
2840 entry.flags |= RW_EXISTS;
2841 MapNetworkToHost(&entry,&storeEntry);
2842 vcode = VLDB_ReplaceEntry(pvolid,RWVOL, &storeEntry,LOCKREL_OPCODE | LOCKREL_AFSID | LOCKREL_TIMESTAMP );
2844 fprintf(STDERR,"Could not update the entry for volume number %u \n",pvolid);
2849 if(verbose) EnumerateEntry(&entry);
2856 code = rx_EndCall(tocall, rxError);
2857 if (!error) error = code;
2860 vcode = ubik_Call(VL_ReleaseLock,cstruct, 0, pvolid, RWVOL, LOCKREL_OPCODE | LOCKREL_AFSID | LOCKREL_TIMESTAMP);
2862 fprintf(STDERR,"Could not release lock on the VLDB entry for the volume %u\n",pvolid);
2863 if(!error) error = vcode;
2867 code = AFSVolEndTrans(toconn, totid, &rcode);
2868 if(!code) code = rcode;
2870 fprintf(STDERR,"Could not end transaction on the volume %u \n",pvolid);
2871 if(!error) error = code;
2875 code = AFSVolEndTrans(toconn, temptid, &rcode);
2876 if(!code) code = rcode;
2878 fprintf(STDERR,"Could not end transaction on the volume %u \n",pvolid);
2879 if(!error) error = code;
2882 if(tempconn) rx_DestroyConnection(tempconn);
2883 if(toconn) rx_DestroyConnection(toconn);
2884 PrintError("",error);
2889 /*unlocks the vldb entry associated with <volid> */
2890 UV_LockRelease(volid)
2897 if (verbose) fprintf(STDERR,"Binding to the VLDB server\n");
2898 vcode = ubik_Call(VL_ReleaseLock,cstruct, 0,volid,-1,LOCKREL_OPCODE | LOCKREL_AFSID | LOCKREL_TIMESTAMP );
2900 fprintf(STDERR,"Could not unlock the entry for volume number %u in VLDB \n",volid);
2901 PrintError("",vcode);
2904 if (verbose) fprintf(STDERR,"VLDB updated\n");
2909 /*adds <server> and <part> as a readonly replication site for <volid>
2911 UV_AddSite(server, part, volid)
2912 afs_int32 server, part, volid;
2914 int j, nro=0, islocked=0;
2915 struct nvldbentry entry,storeEntry;
2916 afs_int32 vcode, error=0;
2919 error = ubik_Call(VL_SetLock,cstruct, 0,volid,RWVOL, VLOP_ADDSITE);
2921 fprintf(STDERR," Could not lock the VLDB entry for the volume %u \n", volid);
2926 error = VLDB_GetEntryByID(volid,RWVOL, &entry);
2928 fprintf(STDERR,"Could not fetch the VLDB entry for volume number %u \n",volid);
2932 if (!ISNAMEVALID(entry.name)){
2933 fprintf(STDERR,"Volume name %s is too long, rename before adding site\n", entry.name);
2934 error = VOLSERBADOP;
2937 MapHostToNetwork(&entry);
2939 /* See if it's too many entries */
2940 if (entry.nServers >= NMAXNSERVERS){
2941 fprintf(STDERR,"Total number of entries will exceed %u\n", NMAXNSERVERS);
2942 error = VOLSERBADOP;
2946 /* See if it's on the same server */
2947 for (j=0; j < entry.nServers; j++) {
2948 if (entry.serverFlags[j] & ITSROVOL) {
2950 if (VLDB_IsSameAddrs(server, entry.serverNumber[j], &error)) {
2952 fprintf(STDERR,"Failed to get info about server's %d address(es) from vlserver (err=%d); aborting call!\n",
2955 MapPartIdIntoName(entry.serverPartition[j], apartName);
2956 fprintf(STDERR,"RO already exists on partition %s. Multiple ROs on a single server aren't allowed\n", apartName);
2957 error = VOLSERBADOP;
2964 /* See if it's too many RO sites - leave one for the RW */
2965 if (nro >= NMAXNSERVERS-1){
2966 fprintf(STDERR,"Total number of sites will exceed %u\n", NMAXNSERVERS-1);
2967 error = VOLSERBADOP;
2971 if (verbose) fprintf(STDOUT,"Adding a new site ...");
2973 entry.serverNumber[entry.nServers] = server;
2974 entry.serverPartition[entry.nServers] = part;
2975 entry.serverFlags[entry.nServers] = (ITSROVOL | RO_DONTUSE);
2978 MapNetworkToHost(&entry,&storeEntry);
2979 error = VLDB_ReplaceEntry(volid,RWVOL,&storeEntry,LOCKREL_OPCODE | LOCKREL_AFSID | LOCKREL_TIMESTAMP);
2981 fprintf(STDERR,"Could not update entry for volume %u \n",volid);
2985 if (verbose) fprintf(STDOUT," done\n");
2989 vcode = ubik_Call(VL_ReleaseLock,cstruct, 0, volid, RWVOL, LOCKREL_OPCODE | LOCKREL_AFSID | LOCKREL_TIMESTAMP);
2991 fprintf(STDERR,"Could not release lock on volume entry for %u \n",volid);
2992 PrintError("", vcode);
2996 PrintError("", error);
3000 /*removes <server> <part> as read only site for <volid> from the vldb */
3001 UV_RemoveSite(server, part, volid)
3002 afs_int32 server, part, volid;
3005 struct nvldbentry entry,storeEntry;
3008 vcode = ubik_Call(VL_SetLock,cstruct, 0,volid,RWVOL, VLOP_ADDSITE);
3010 fprintf(STDERR," Could not lock the VLDB entry for volume %u \n", volid);
3011 PrintError("",vcode);
3015 vcode = VLDB_GetEntryByID(volid,RWVOL, &entry);
3017 fprintf(STDERR,"Could not fetch the entry for volume number %u from VLDB \n",volid);
3018 PrintError("",vcode);
3021 MapHostToNetwork(&entry);
3022 if(!Lp_ROMatch(server, part, &entry)){
3023 /*this site doesnot exist */
3024 fprintf(STDERR,"This site is not a replication site \n");
3025 vcode = ubik_Call(VL_ReleaseLock,cstruct, 0, volid, RWVOL, LOCKREL_OPCODE | LOCKREL_AFSID | LOCKREL_TIMESTAMP);
3027 fprintf(STDERR,"Could not update entry for volume %u \n",volid);
3028 PrintError("",vcode);
3029 ubik_Call(VL_ReleaseLock,cstruct, 0, volid, RWVOL, LOCKREL_OPCODE | LOCKREL_AFSID | LOCKREL_TIMESTAMP);
3034 else { /*remove the rep site */
3035 Lp_SetROValue(&entry, server, part, 0, 0);
3037 if((entry.nServers == 1) && (entry.flags & RW_EXISTS))
3038 entry.flags &= ~RO_EXISTS;
3039 if(entry.nServers < 1) { /*this is the last ref */
3040 if(verbose) fprintf(STDOUT,"Deleting the VLDB entry for %u ...",volid);
3042 vcode = ubik_Call(VL_DeleteEntry,cstruct, 0,volid, ROVOL);
3044 fprintf(STDERR,"Could not delete VLDB entry for volume %u \n",volid);
3045 PrintError("",vcode);
3048 if (verbose) fprintf(STDOUT," done\n");
3050 MapNetworkToHost(&entry,&storeEntry);
3051 fprintf(STDOUT,"Deleting the replication site for volume %u ...",volid);
3053 vcode = VLDB_ReplaceEntry(volid,RWVOL,&storeEntry,LOCKREL_OPCODE | LOCKREL_AFSID | LOCKREL_TIMESTAMP);
3055 fprintf(STDERR,"Could not release lock on volume entry for %u \n",volid);
3056 PrintError("",vcode);
3057 ubik_Call(VL_ReleaseLock,cstruct, 0, volid, RWVOL, LOCKREL_OPCODE | LOCKREL_AFSID | LOCKREL_TIMESTAMP);
3060 if(verbose) fprintf(STDOUT," done\n");
3065 /*list all the partitions on <aserver> */
3066 UV_ListPartitions(aserver, ptrPartList, cntp)
3068 struct partList *ptrPartList;
3071 struct rx_connection *aconn;
3072 struct pIDs partIds;
3073 struct partEntries partEnts;
3074 register int i, j=0, code;
3077 aconn = UV_Bind(aserver,AFSCONF_VOLUMEPORT);
3079 partEnts.partEntries_len = 0;
3080 partEnts.partEntries_val = (afs_int32 *)0;
3081 code = AFSVolXListPartitions(aconn, &partEnts); /* this is available only on new servers */
3082 if (code == RXGEN_OPCODE)
3084 for(i = 0; i < 26; i++) /* try old interface */
3085 partIds.partIds[i] = -1;
3086 code = AFSVolListPartitions(aconn, &partIds);
3088 for (i = 0;i < 26; i++) {
3089 if((partIds.partIds[i]) != -1) {
3090 ptrPartList->partId[j] = partIds.partIds[i];
3091 ptrPartList->partFlags[j] = PARTVALID;
3094 ptrPartList->partFlags[i] = 0;
3101 *cntp = partEnts.partEntries_len;
3102 if (*cntp > VOLMAXPARTS) {
3103 fprintf(STDERR,"Warning: number of partitions on the server too high %d (process only %d)\n",
3104 *cntp, VOLMAXPARTS);
3105 *cntp = VOLMAXPARTS;
3107 for (i = 0;i < *cntp; i++) {
3108 ptrPartList->partId[i] = partEnts.partEntries_val[i];
3109 ptrPartList->partFlags[i] = PARTVALID;
3111 free(partEnts.partEntries_val);
3115 fprintf(STDERR,"Could not fetch the list of partitions from the server\n");
3116 PrintError("",code);
3117 if(aconn) rx_DestroyConnection(aconn);
3122 /*zap the list of volumes specified by volPtrArray (the volCloneId field).
3123 This is used by the backup system */
3124 UV_ZapVolumeClones(aserver,apart,volPtr,arraySize)
3125 afs_int32 aserver, apart;
3126 afs_int32 arraySize;
3127 struct volDescription *volPtr;
3129 struct rx_connection *aconn;
3130 struct volDescription *curPtr;
3133 afs_int32 rcode = 0;
3134 afs_int32 success = 1;
3137 aconn = (struct rx_connection *)0;
3138 aconn = UV_Bind(aserver,AFSCONF_VOLUMEPORT);
3140 for(curPtr = volPtr; curPos < arraySize; curPtr++) {
3141 if(curPtr->volFlags & CLONEVALID) {
3142 curPtr->volFlags &= ~CLONEZAPPED;
3144 code = AFSVolTransCreate(aconn, curPtr->volCloneId, apart, ITOffline, &tid);
3145 if(code) success = 0;
3147 code = AFSVolDeleteVolume(aconn, tid);
3148 if(code) success = 0;
3149 code = AFSVolEndTrans(aconn, tid, &rcode);
3150 if(code || rcode) success = 0;
3152 if(success) curPtr->volFlags |= CLONEZAPPED;
3153 if(!success) fprintf(STDERR,"Could not zap volume %u\n",curPtr->volCloneId);
3154 if(success && verbose) fprintf(STDOUT,"Clone of %s %u deleted\n", curPtr->volName,curPtr->volCloneId);
3159 if(aconn)rx_DestroyConnection(aconn);
3163 /*return a list of clones of the volumes specified by volPtrArray. Used by the
3165 UV_GenerateVolumeClones(aserver,apart,volPtr,arraySize)
3166 afs_int32 aserver, apart;
3167 afs_int32 arraySize;
3168 struct volDescription *volPtr;
3170 struct rx_connection *aconn;
3171 struct volDescription *curPtr;
3174 afs_int32 rcode = 0;
3176 int reuseCloneId = 0;
3177 afs_int32 curCloneId = 0;
3178 char cloneName[256];/*max vol name */
3180 aconn = (struct rx_connection *)0;
3181 aconn = UV_Bind(aserver,AFSCONF_VOLUMEPORT);
3183 if((volPtr->volFlags & REUSECLONEID) && (volPtr->volFlags & ENTRYVALID))
3185 else { /*get a bunch of id's from vldb */
3186 code = ubik_Call(VL_GetNewVolumeId,cstruct, 0, arraySize, &curCloneId);
3188 fprintf(STDERR,"Could not get ID's for the clone from VLDB\n");
3189 PrintError("",code);
3194 for(curPtr = volPtr; curPos < arraySize; curPtr++) {
3195 if(curPtr->volFlags & ENTRYVALID) {
3197 curPtr->volFlags |= CLONEVALID;
3198 /*make a clone of curParentId and record as curPtr->volCloneId */
3199 code = AFSVolTransCreate(aconn, curPtr->volId, apart, ITOffline, &tid);
3200 if(verbose && code) fprintf(STDERR,"Clone for volume %s %u failed \n",curPtr->volName,curPtr->volId);
3202 curPtr->volFlags &= ~CLONEVALID; /*cant clone */
3206 if(strlen(curPtr->volName) < (VOLSER_OLDMAXVOLNAME - 9) ){
3207 strcpy(cloneName, curPtr->volName);
3208 strcat(cloneName,"-tmpClone-");
3210 else strcpy(cloneName,"-tmpClone");
3212 curPtr->volCloneId = curCloneId;
3216 code = AFSVolClone(aconn, tid, 0, readonlyVolume, cloneName,&(curPtr->volCloneId));
3218 curPtr->volFlags &= ~CLONEVALID;
3220 fprintf(STDERR,"Could not clone %s due to error %u\n", curPtr->volName,code);
3221 code=AFSVolEndTrans(aconn, tid, &rcode);
3223 fprintf(STDERR,"WARNING: could not end transaction\n");
3226 if(verbose) fprintf(STDOUT,"********** Cloned %s temporary %u\n",cloneName,curPtr->volCloneId);
3227 code = AFSVolEndTrans(aconn, tid, &rcode);
3229 curPtr->volFlags &= ~CLONEVALID;
3237 if (aconn) rx_DestroyConnection(aconn);
3242 /*list all the volumes on <aserver> and <apart>. If all = 1, then all the
3243 * relevant fields of the volume are also returned. This is a heavy weight operation.*/
3244 UV_ListVolumes(aserver,apart,all,resultPtr,size)
3245 afs_int32 aserver, apart;
3247 struct volintInfo **resultPtr;
3250 struct rx_connection *aconn;
3252 volEntries volumeInfo;
3256 *resultPtr = (volintInfo *)0;
3257 volumeInfo.volEntries_val = (volintInfo *)0;/*this hints the stub to allocate space*/
3258 volumeInfo.volEntries_len = 0;
3260 aconn = UV_Bind(aserver,AFSCONF_VOLUMEPORT);
3261 code = AFSVolListVolumes(aconn, apart, all, &volumeInfo);
3263 fprintf(STDERR,"Could not fetch the list of volumes from the server\n");
3266 *resultPtr = volumeInfo.volEntries_val;
3267 *size = volumeInfo.volEntries_len;
3270 if(aconn) rx_DestroyConnection(aconn);
3271 PrintError("",code);
3275 /*------------------------------------------------------------------------
3276 * EXPORTED UV_XListVolumes
3279 * List the extended information for all the volumes on a particular
3280 * File Server and partition. We may either return the volume's ID
3281 * or all of its extended information.
3284 * a_serverID : Address of the File Server for which we want
3285 * extended volume info.
3286 * a_partID : Partition for which we want the extended
3288 * a_all : If non-zero, fetch ALL the volume info,
3289 * otherwise just the volume ID.
3290 * a_resultPP : Ptr to the address of the area containing
3291 * the returned volume info.
3292 * a_numEntsInResultP : Ptr for the value we set for the number of
3297 * Otherise, the return value of AFSVolXListVolumes.
3300 * This routine is closely related to UV_ListVolumes, which returns
3301 * only the standard level of detail on AFS volumes. It is a
3302 * heavyweight operation, zipping through all the volume entries for
3303 * a given server/partition.
3307 *------------------------------------------------------------------------*/
3309 UV_XListVolumes(a_serverID, a_partID, a_all, a_resultPP, a_numEntsInResultP)
3310 afs_int32 a_serverID;
3313 struct volintXInfo **a_resultPP;
3314 afs_int32 *a_numEntsInResultP;
3316 { /*UV_XListVolumes*/
3318 struct rx_connection *rxConnP; /*Ptr to the Rx connection involved*/
3319 afs_int32 code; /*Error code to return*/
3320 volXEntries volumeXInfo; /*Area for returned extended vol info*/
3323 * Set up our error code and the area for returned extended volume info.
3324 * We set the val field to a null pointer as a hint for the stub to
3328 *a_numEntsInResultP = 0;
3329 *a_resultPP = (volintXInfo *)0;
3330 volumeXInfo.volXEntries_val = (volintXInfo *)0;
3331 volumeXInfo.volXEntries_len = 0;
3334 * Bind to the Volume Server port on the File Server machine in question,
3337 rxConnP = UV_Bind(a_serverID, AFSCONF_VOLUMEPORT);
3338 code = AFSVolXListVolumes(rxConnP, a_partID, a_all, &volumeXInfo);
3341 "[UV_XListVolumes] Couldn't fetch volume list\n");
3344 * We got the info; pull out the pointer to where the results lie
3345 * and how many entries are there.
3347 *a_resultPP = volumeXInfo.volXEntries_val;
3348 *a_numEntsInResultP = volumeXInfo.volXEntries_len;
3352 * If we got an Rx connection, throw it away.
3355 rx_DestroyConnection(rxConnP);
3357 PrintError("", code);
3359 } /*UV_XListVolumes*/
3361 /* get all the information about volume <volid> on <aserver> and <apart> */
3362 UV_ListOneVolume(aserver,apart,volid,resultPtr)
3363 afs_int32 aserver, apart;
3365 struct volintInfo **resultPtr;
3367 struct rx_connection *aconn;
3369 volEntries volumeInfo;
3373 *resultPtr = (volintInfo *)0;
3374 volumeInfo.volEntries_val = (volintInfo *)0;/*this hints the stub to allocate space*/
3375 volumeInfo.volEntries_len = 0;
3377 aconn = UV_Bind(aserver,AFSCONF_VOLUMEPORT);
3378 code = AFSVolListOneVolume(aconn, apart, volid, &volumeInfo);
3380 fprintf(STDERR,"Could not fetch the information about volume %u from the server\n",volid);
3383 *resultPtr = volumeInfo.volEntries_val;
3387 if(aconn) rx_DestroyConnection(aconn);
3388 PrintError("",code);
3392 /*------------------------------------------------------------------------
3393 * EXPORTED UV_XListOneVolume
3396 * List the extended information for a volume on a particular File
3397 * Server and partition.
3400 * a_serverID : Address of the File Server for which we want
3401 * extended volume info.
3402 * a_partID : Partition for which we want the extended
3404 * a_volID : Volume ID for which we want the info.
3405 * a_resultPP : Ptr to the address of the area containing
3406 * the returned volume info.
3410 * Otherise, the return value of AFSVolXListOneVolume.
3413 * This routine is closely related to UV_ListOneVolume, which returns
3414 * only the standard level of detail on the chosen AFS volume.
3418 *------------------------------------------------------------------------*/
3420 UV_XListOneVolume(a_serverID, a_partID, a_volID, a_resultPP)
3421 afs_int32 a_serverID;
3424 struct volintXInfo **a_resultPP;
3426 { /*UV_XListOneVolume*/
3427 struct rx_connection *rxConnP; /*Rx connection to Volume Server*/
3428 afs_int32 code; /*Error code*/
3429 volXEntries volumeXInfo; /*Area for returned info*/
3432 * Set up our error code, and the area we're in which we are returning
3433 * the info. Setting the val field to a null pointer tells the stub
3434 * to allocate space for us.
3437 *a_resultPP = (volintXInfo *)0;
3438 volumeXInfo.volXEntries_val = (volintXInfo *)0;
3439 volumeXInfo.volXEntries_len = 0;
3442 * Bind to the Volume Server port on the File Server machine in question,
3445 rxConnP = UV_Bind(a_serverID, AFSCONF_VOLUMEPORT);
3446 code = AFSVolXListOneVolume(rxConnP, a_partID, a_volID, &volumeXInfo);
3449 "[UV_XListOneVolume] Couldn't fetch the volume information\n");
3452 * We got the info; pull out the pointer to where the results lie.
3454 *a_resultPP = volumeXInfo.volXEntries_val;
3457 * If we got an Rx connection, throw it away.
3460 rx_DestroyConnection(rxConnP);
3462 PrintError("",code);
3464 } /*UV_XListOneVolume*/
3467 * Given a volume we read from a partition, check if it is
3468 * represented in the VLDB correctly.
3470 * The VLDB is looked up by the RW volume id (not its name).
3471 * The RW contains the true name of the volume (BK and RO set
3472 * the name in the VLDB only on creation of the VLDB entry).
3473 * We want rules strict enough that when we check all volumes
3474 * on one partition, it does not need to be done again. IE:
3475 * two volumes on different partitions won't constantly
3476 * change a VLDB entry away from what the other set.
3477 * For RW and BK volumes, we will always check the VLDB to see
3478 * if the two exist on the server/partition. May seem redundant,
3479 * but this is an easy check of the VLDB. IE: if the VLDB entry
3480 * says the BK exists but no BK volume is there, we will detect
3481 * this when we check the RW volume.
3482 * VLDB entries are locked only when a change needs to be done.
3483 * Output changed to look a lot like the "vos syncserv" otuput.
3485 static afs_int32 CheckVolume(volumeinfo, aserver, apart, modentry, maxvolid)
3486 volintInfo *volumeinfo;
3487 afs_int32 aserver, apart;
3488 afs_int32 *modentry;
3489 afs_uint32 *maxvolid;
3492 afs_int32 code, error = 0;
3493 struct nvldbentry entry, storeEntry;
3496 int pass=0, islocked=0, createentry, addvolume, modified, mod;
3499 if (modentry) *modentry = 0;
3500 rwvolid = ((volumeinfo->type == RWVOL) ? volumeinfo->volid : volumeinfo->parentID);
3503 /* Check to see if the VLDB is ok without locking it (pass 1).
3504 * If it will change, then lock the VLDB entry, read it again,
3505 * then make the changes to it (pass 2).
3508 code = ubik_Call(VL_SetLock, cstruct, 0, rwvolid, RWVOL, VLOP_DELETE);
3510 fprintf(STDERR, "Could not lock VLDB entry for %u\n", rwvolid);
3516 createentry = 0; /* Do we need to create a VLDB entry */
3517 addvolume = 0; /* Add this volume to the VLDB entry */
3518 modified = 0; /* The VLDB entry was modified */
3520 /* Read the entry from VLDB by its RW volume id */
3521 code = VLDB_GetEntryByID(rwvolid, RWVOL, &entry);
3523 if (code != VL_NOENT) {
3524 fprintf(STDOUT,"Could not retreive the VLDB entry for volume %u \n", rwvolid);
3528 memset(&entry, 0, sizeof(entry));
3529 vsu_ExtractName(entry.name, volumeinfo->name); /* Store name of RW */
3533 MapHostToNetwork(&entry);
3536 if (verbose && (pass == 1)) {
3537 fprintf(STDOUT,"_______________________________\n");
3538 fprintf(STDOUT,"\n-- status before -- \n");
3540 fprintf(STDOUT,"\n**does not exist**\n");
3542 if ((entry.flags & RW_EXISTS) ||
3543 (entry.flags & RO_EXISTS) ||
3544 (entry.flags & BACK_EXISTS))
3545 EnumerateEntry(&entry);
3547 fprintf(STDOUT,"\n");
3550 if (volumeinfo->type == RWVOL) { /* RW volume exists */
3556 /* Check existence of RW and BK volumes */
3557 code = CheckVldbRWBK(&entry, &mod);
3558 if (code) ERROR_EXIT(code);
3559 if (mod) modified++;
3561 idx = Lp_GetRwIndex(&entry);
3562 if (idx == -1) { /* RW index not found in the VLDB entry */
3563 idx = entry.nServers; /* put it into next index */
3566 } else { /* RW index found in the VLDB entry. */
3567 /* Verify if this volume's location matches where the VLDB says it is */
3568 if (!Lp_Match(aserver, apart, &entry)) {
3569 if (entry.flags & RW_EXISTS) {
3570 /* The RW volume exists elsewhere - report this one a duplicate */
3572 MapPartIdIntoName(apart, pname);
3573 fprintf(STDERR,"*** Warning: Orphaned RW volume %u exists on %s %s\n",
3574 rwvolid, hostutil_GetNameByINet(aserver), pname);
3575 MapPartIdIntoName(entry.serverPartition[idx], pname);
3576 fprintf(STDERR," VLDB reports RW volume %u exists on %s %s\n",
3578 hostutil_GetNameByINet(entry.serverNumber[idx]), pname);
3581 /* The RW volume does not exist - have VLDB point to this one */
3584 /* Check for orphaned BK volume on old partition */
3585 if (entry.flags & BACK_EXISTS) {
3587 MapPartIdIntoName(entry.serverPartition[idx], pname);
3588 fprintf(STDERR,"*** Warning: Orphaned BK volume %u exists on %s %s\n",
3589 entry.volumeId[BACKVOL],
3590 hostutil_GetNameByINet(entry.serverNumber[idx]), pname);
3591 MapPartIdIntoName(apart, pname);
3592 fprintf(STDERR," VLDB reports its RW volume %u exists on %s %s\n",
3593 rwvolid, hostutil_GetNameByINet(aserver), pname);
3598 /* Volume location matches the VLDB location */
3599 if ( (volumeinfo->backupID && !entry.volumeId[BACKVOL]) ||
3600 (volumeinfo->cloneID && !entry.volumeId[ROVOL]) ||
3601 (strncmp(entry.name,volumeinfo->name,VOLSER_OLDMAXVOLNAME) != 0) ) {
3609 entry.flags |= RW_EXISTS;
3610 entry.volumeId[RWVOL] = rwvolid;
3611 if (!entry.volumeId[BACKVOL])
3612 entry.volumeId[BACKVOL] = volumeinfo->backupID;
3613 if (!entry.volumeId[ROVOL])
3614 entry.volumeId[ROVOL] = volumeinfo->cloneID;
3616 entry.serverFlags[idx] = ITSRWVOL;
3617 entry.serverNumber[idx] = aserver;
3618 entry.serverPartition[idx] = apart;
3619 strncpy(entry.name, volumeinfo->name, VOLSER_OLDMAXVOLNAME);
3623 /* One last check - to update BK if need to */
3624 code = CheckVldbRWBK(&entry, &mod);
3625 if (code) ERROR_EXIT(code);
3626 if (mod) modified++;
3630 else if (volumeinfo->type == BACKVOL) { /* A BK volume */
3636 /* Check existence of RW and BK volumes */
3637 code = CheckVldbRWBK(&entry, &mod);
3638 if (code) ERROR_EXIT(code);
3639 if (mod) modified++;
3641 idx = Lp_GetRwIndex(&entry);
3642 if (idx == -1) { /* RW index not found in the VLDB entry */
3643 idx = entry.nServers; /* Put it into next index */
3646 } else { /* RW index found in the VLDB entry */
3647 /* Verify if this volume's location matches where the VLDB says it is */
3648 if (!Lp_Match(aserver, apart, &entry)) {
3649 /* VLDB says RW and/or BK is elsewhere - report this BK volume orphaned */
3651 MapPartIdIntoName(apart, pname);
3652 fprintf(STDERR,"*** Warning: Orphaned BK volume %u exists on %s %s\n",
3653 volumeinfo->volid, hostutil_GetNameByINet(aserver), pname);
3654 MapPartIdIntoName(entry.serverPartition[idx], pname);
3655 fprintf(STDERR," VLDB reports its RW/BK volume %u exists on %s %s\n",
3657 hostutil_GetNameByINet(entry.serverNumber[idx]), pname);
3660 if (volumeinfo->volid != entry.volumeId[BACKVOL]) {
3661 if (!(entry.flags & BACK_EXISTS)) {
3664 else if (volumeinfo->volid > entry.volumeId[BACKVOL]) {
3668 MapPartIdIntoName(entry.serverPartition[idx], pname);
3669 fprintf(STDERR,"*** Warning: Orphaned BK volume %u exists on %s %s\n",
3670 entry.volumeId[BACKVOL], hostutil_GetNameByINet(aserver), pname);
3671 fprintf(STDERR," VLDB reports its BK volume ID is %u\n",
3676 MapPartIdIntoName(entry.serverPartition[idx], pname);
3677 fprintf(STDERR,"*** Warning: Orphaned BK volume %u exists on %s %s\n",
3678 volumeinfo->volid, hostutil_GetNameByINet(aserver), pname);
3679 fprintf(STDERR," VLDB reports its BK volume ID is %u\n",
3680 entry.volumeId[BACKVOL]);
3684 else if (!entry.volumeId[BACKVOL]) {
3691 entry.flags |= BACK_EXISTS;
3692 entry.volumeId[RWVOL] = rwvolid;
3693 entry.volumeId[BACKVOL] = volumeinfo->volid;
3695 entry.serverNumber[idx] = aserver;
3696 entry.serverPartition[idx] = apart;
3697 entry.serverFlags[idx] = ITSRWVOL;
3703 else if (volumeinfo->type == ROVOL) { /* A RO volume */
3704 if (volumeinfo->volid == entry.volumeId[ROVOL]) {
3705 /* This is a quick check to see if the RO entry exists in the
3706 * VLDB so we avoid the CheckVldbRO() call (which checks if each
3707 * RO volume listed in the VLDB exists).
3709 idx = Lp_ROMatch(aserver, apart, &entry) - 1;
3711 idx = entry.nServers;
3715 if (!(entry.flags & RO_EXISTS)) {
3720 /* Before we correct the VLDB entry, make sure all the
3721 * ROs listed in the VLDB exist.
3723 code = CheckVldbRO(&entry, &mod);
3724 if (code) ERROR_EXIT(code);
3725 if (mod) modified++;
3727 if (!(entry.flags & RO_EXISTS)) {
3728 /* No RO exists in the VLDB entry - add this one */
3729 idx = entry.nServers;
3733 else if (volumeinfo->volid > entry.volumeId[ROVOL]) {
3734 /* The volume headers's RO ID does not match that in the VLDB entry,
3735 * and the vol hdr's ID is greater (implies more recent). So delete
3736 * all the RO volumes listed in VLDB entry and add this volume.
3738 for (j=0; j<entry.nServers; j++) {
3739 if (entry.serverFlags[j] & ITSROVOL) {
3740 /* Verify this volume exists and print message we are orphaning it */
3742 MapPartIdIntoName(apart, entry.serverPartition[j]);
3743 fprintf(STDERR,"*** Warning: Orphaned RO volume %u exists on %s %s\n",
3744 entry.volumeId[ROVOL],
3745 hostutil_GetNameByINet(entry.serverNumber[j]), pname);
3746 fprintf(STDERR," VLDB reports its RO volume ID is %u\n",
3750 Lp_SetRWValue(entry, entry.serverNumber[idx],
3751 entry.serverPartition[idx], 0L, 0L);
3758 idx = entry.nServers;
3762 else if (volumeinfo->volid < entry.volumeId[ROVOL]) {
3763 /* The volume headers's RO ID does not match that in the VLDB entry,
3764 * and the vol hdr's ID is lower (implies its older). So orphan it.
3767 MapPartIdIntoName(apart, pname);
3768 fprintf(STDERR,"*** Warning: Orphaned RO volume %u exists on %s %s\n",
3769 volumeinfo->volid, hostutil_GetNameByINet(aserver), pname);
3770 fprintf(STDERR," VLDB reports its RO volume ID is %u\n",
3771 entry.volumeId[ROVOL]);
3775 /* The RO volume ID in the volume header match that in the VLDB entry,
3776 * and there exist RO volumes in the VLDB entry. See if any of them
3777 * are this one. If not, then we add it.
3779 idx = Lp_ROMatch(aserver, apart, &entry) - 1;
3781 idx = entry.nServers;
3789 entry.flags |= RO_EXISTS;
3790 entry.volumeId[RWVOL] = rwvolid;
3791 entry.volumeId[ROVOL] = volumeinfo->volid;
3793 entry.serverNumber[idx] = aserver;
3794 entry.serverPartition[idx] = apart;
3795 entry.serverFlags[idx] = ITSROVOL;
3801 /* Remember largest volume id */
3802 if (entry.volumeId[ROVOL] > *maxvolid) *maxvolid = entry.volumeId[ROVOL];
3803 if (entry.volumeId[BACKVOL] > *maxvolid) *maxvolid = entry.volumeId[BACKVOL];
3804 if (entry.volumeId[RWVOL] > *maxvolid) *maxvolid = entry.volumeId[RWVOL];
3807 MapNetworkToHost(&entry, &storeEntry);
3810 code = VLDB_CreateEntry(&storeEntry);
3812 fprintf(STDOUT,"Could not create a VLDB entry for the volume %u\n", rwvolid);
3817 if (pass == 1) goto retry;
3818 code = VLDB_ReplaceEntry(rwvolid, RWVOL, &storeEntry,
3819 LOCKREL_OPCODE | LOCKREL_AFSID | LOCKREL_TIMESTAMP);
3821 fprintf(STDERR,"Could not update entry for %u\n", rwvolid);
3825 if (modentry) *modentry = modified;
3826 } else if (pass == 2) {
3827 code = ubik_Call(VL_ReleaseLock,cstruct, 0, rwvolid, RWVOL,
3828 LOCKREL_OPCODE | LOCKREL_AFSID | LOCKREL_TIMESTAMP);
3830 PrintError("Could not unlock VLDB entry ", code);
3835 fprintf(STDOUT,"-- status after --\n");
3837 EnumerateEntry(&entry);
3839 fprintf(STDOUT,"\n**no change**\n");
3844 fprintf(STDOUT,"\n_______________________________\n");
3849 int sortVolumes(v1, v2)
3850 volintInfo *v1, *v2;
3852 afs_int32 rwvolid1, rwvolid2;
3854 rwvolid1 = ((v1->type == RWVOL) ? v1->volid : v1->parentID);
3855 rwvolid2 = ((v2->type == RWVOL) ? v2->volid : v2->parentID);
3857 if (rwvolid1 > rwvolid2) return -1; /* lower RW id goes first */
3858 if (rwvolid1 < rwvolid2) return 1;
3860 if (v1->type == RWVOL) return -1; /* RW vols go first */
3861 if (v2->type == RWVOL) return 1;
3863 if ((v1->type == BACKVOL) && (v2->type == ROVOL )) return -1; /* BK vols next */
3864 if ((v1->type == ROVOL ) && (v2->type == BACKVOL)) return 1;
3866 if (v1->volid < v2->volid) return 1; /* larger volids first */
3867 if (v1->volid > v2->volid) return -1;
3872 * Synchronise <aserver> <apart>(if flags = 1) <avolid>.
3873 * Synchronize an individual volume against a sever and partition.
3874 * Checks the VLDB entry (similar to syncserv) as well as checks
3875 * if the volume exists on specified servers (similar to syncvldb).
3877 UV_SyncVolume(aserver, apart, avolname, flags)
3878 afs_int32 aserver, apart;
3882 struct rx_connection *aconn = 0;
3883 afs_int32 j, k, code, vcode, error = 0;
3884 afs_int32 tverbose, mod, modified = 0;
3885 struct nvldbentry vldbentry;
3886 afs_int32 volumeid = 0;
3887 volEntries volumeInfo;
3888 struct partList PartList;
3890 afs_int32 maxvolid = 0;
3892 volumeInfo.volEntries_val = (volintInfo *)0;
3893 volumeInfo.volEntries_len = 0;
3895 if (!aserver && flags) {
3896 /* fprintf(STDERR,"Partition option requires a server option\n"); */
3900 /* Turn verbose logging off and do our own verbose logging */
3904 /* Read the VLDB entry */
3905 vcode = VLDB_GetEntryByName(avolname, &vldbentry);
3906 if (vcode && (vcode != VL_NOENT)) {
3907 fprintf(STDERR,"Could not access the VLDB for volume %s\n", avolname);
3909 } else if (!vcode) {
3910 MapHostToNetwork(&vldbentry);
3914 fprintf(STDOUT,"Processing VLDB entry %s ...\n", avolname);
3915 fprintf(STDOUT,"_______________________________\n");
3916 fprintf(STDOUT,"\n-- status before -- \n");
3918 fprintf(STDOUT,"\n**does not exist**\n");
3920 if ((vldbentry.flags & RW_EXISTS) ||
3921 (vldbentry.flags & RO_EXISTS) ||
3922 (vldbentry.flags & BACK_EXISTS))
3923 EnumerateEntry(&vldbentry);
3925 fprintf(STDOUT,"\n");
3928 /* Verify that all of the VLDB entries exist on the repective servers
3929 * and partitions (this does not require that avolname be a volume ID).
3930 * Equivalent to a syncserv.
3933 code = CheckVldb(&vldbentry, &mod);
3935 fprintf(STDERR,"Could not process VLDB entry for volume %s\n", vldbentry.name);
3938 if (mod) modified++;
3941 /* If aserver is given, we will search for the desired volume on it */
3943 /* Generate array of partitions on the server that we will check */
3945 code = UV_ListPartitions(aserver, &PartList, &pcnt);
3947 fprintf(STDERR,"Could not fetch the list of partitions from the server\n");
3951 PartList.partId[0] = apart;
3955 aconn = UV_Bind(aserver,AFSCONF_VOLUMEPORT);
3957 /* If a volume ID were given, search for it on each partition */
3958 if (volumeid = atol(avolname)) {
3959 for (j=0; j<pcnt; j++) {
3960 code = AFSVolListOneVolume(aconn, PartList.partId[j], volumeid, &volumeInfo);
3962 if (code != ENODEV) {
3963 fprintf(STDERR,"Could not query server\n");
3967 /* Found one, sync it with VLDB entry */
3968 code = CheckVolume(volumeInfo.volEntries_val, aserver,
3969 PartList.partId[j], &mod, &maxvolid);
3970 if (code) ERROR_EXIT(code);
3971 if (mod) modified++;
3974 if (volumeInfo.volEntries_val)
3975 free(volumeInfo.volEntries_val);
3976 volumeInfo.volEntries_val = (volintInfo *)0;
3977 volumeInfo.volEntries_len = 0;
3981 /* Check to see if the RW, BK, and RO IDs exist on any
3982 * partitions. We get the volume IDs from the VLDB.
3984 rv = 1; /* Read the VLDB entry ? */
3985 for (j=0; j<MAXTYPES; j++) { /* for RW, RO, and BK IDs */
3987 vcode = VLDB_GetEntryByName(avolname, &vldbentry);
3989 if (vcode == VL_NOENT) break;
3990 fprintf(STDERR,"Could not access the VLDB for volume %s\n", avolname);
3996 if (vldbentry.volumeId[j] == 0) continue;
3998 for (k=0; k<pcnt; k++) { /* For each partition */
3999 volumeInfo.volEntries_val = (volintInfo *)0;
4000 volumeInfo.volEntries_len = 0;
4001 code = AFSVolListOneVolume(aconn, PartList.partId[k],
4002 vldbentry.volumeId[j], &volumeInfo);
4004 if (code != ENODEV) {
4005 fprintf(STDERR,"Could not query server\n");
4009 /* Found one, sync it with VLDB entry */
4010 code = CheckVolume(volumeInfo.volEntries_val, aserver,
4011 PartList.partId[k], &mod, &maxvolid);
4012 if (code) ERROR_EXIT(code);
4013 if (mod) modified++, rv++;
4016 if (volumeInfo.volEntries_val)
4017 free(volumeInfo.volEntries_val);
4018 volumeInfo.volEntries_val = (volintInfo *)0;
4019 volumeInfo.volEntries_len = 0;
4022 } /* if (aserver) */
4024 /* If verbose output, print a summary of what changed */
4026 fprintf(STDOUT,"-- status after --\n");
4027 code = VLDB_GetEntryByName(avolname, &vldbentry);
4028 if (code && (code != VL_NOENT)) {
4029 fprintf(STDERR,"Could not access the VLDB for volume %s\n", avolname);
4032 if (modified && (code == VL_NOENT)) {
4033 fprintf(STDOUT,"\n**entry deleted**\n");
4034 } else if (modified) {
4035 EnumerateEntry(vldbentry);
4037 fprintf(STDOUT,"\n**no change**\n");
4039 fprintf(STDOUT,"\n_______________________________\n");
4043 /* Now check if the maxvolid is larger than that stored in the VLDB */
4045 afs_int32 maxvldbid = 0;
4046 code = ubik_Call(VL_GetNewVolumeId,cstruct, 0, 0, &maxvldbid);
4048 fprintf(STDERR, "Could not get the highest allocated volume id from the VLDB\n");
4049 if (!error) error = code;
4050 } else if (maxvolid > maxvldbid) {
4052 id = maxvolid - maxvldbid + 1;
4053 code = ubik_Call(VL_GetNewVolumeId, cstruct, 0, id, &nid);
4055 fprintf(STDERR,"Error in increasing highest allocated volume id in VLDB\n");
4056 if (!error) error = code;
4063 if (error) fprintf(STDOUT,"...error encountered");
4064 else fprintf(STDOUT,"...done entry\n");
4066 if (aconn) rx_DestroyConnection(aconn);
4067 if (volumeInfo.volEntries_val) free(volumeInfo.volEntries_val);
4069 PrintError("",error);
4074 * Synchronise vldb with the file server <aserver> and,
4075 * optionally, <apart>.
4077 UV_SyncVldb(aserver, apart, flags, force)
4078 afs_int32 aserver, apart;
4081 struct rx_connection *aconn;
4082 afs_int32 code, error=0;
4084 volEntries volumeInfo;
4085 struct partList PartList;
4089 afs_int32 failures = 0, modifications = 0, tentries = 0;
4091 afs_uint32 maxvolid = 0;
4093 volumeInfo.volEntries_val = (volintInfo *)0;
4094 volumeInfo.volEntries_len = 0;
4096 aconn = UV_Bind(aserver, AFSCONF_VOLUMEPORT);
4098 /* Generate array of partitions to check */
4100 code = UV_ListPartitions(aserver, &PartList, &pcnt);
4102 fprintf(STDERR,"Could not fetch the list of partitions from the server\n");
4106 PartList.partId[0] = apart;
4111 fprintf(STDOUT,"Processing volume entries ...\n");
4115 /* Step through the array of partitions */
4116 for (i = 0; i < pcnt; i++) {
4117 apart = PartList.partId[i];
4118 MapPartIdIntoName(apart, pname);
4120 volumeInfo.volEntries_val = (volintInfo *)0;
4121 volumeInfo.volEntries_len = 0;
4122 code = AFSVolListVolumes(aconn, apart, 1, &volumeInfo);
4124 fprintf(STDERR,"Could not fetch the list of volumes from the server\n");
4128 /* May want to sort the entries: RW, BK (high to low), RO (high to low) */
4129 qsort((char *)volumeInfo.volEntries_val, volumeInfo.volEntries_len,
4130 sizeof(volintInfo), sortVolumes);
4133 for (vi=volumeInfo.volEntries_val, j=0; j < volumeInfo.volEntries_len; j++, vi++) {
4140 fprintf(STDOUT,"Processing volume entry %d: %s (%u) on server %s %s...\n",
4141 j+1, vi->name, vi->volid,
4142 hostutil_GetNameByINet(aserver), pname);
4146 code = CheckVolume(vi, aserver, apart, &modified, &maxvolid);
4148 PrintError("",code);
4152 else if (modified) {
4158 fprintf(STDOUT,"...error encountered\n\n");
4160 fprintf(STDOUT,"...done entry %d\n\n", j+1);
4166 fprintf(STDERR,"Could not process entries on server %s partition %s\n",
4167 hostutil_GetNameByINet(aserver), pname);
4169 if (volumeInfo.volEntries_val) {
4170 free(volumeInfo.volEntries_val);
4171 volumeInfo.volEntries_val = 0;
4174 }/* thru all partitions */
4177 fprintf(STDOUT, "Total entries: %u, Failed to process %d, Changed %d\n",
4178 tentries, failures, modifications);
4182 /* Now check if the maxvolid is larger than that stored in the VLDB */
4184 afs_uint32 maxvldbid = 0;
4185 code = ubik_Call(VL_GetNewVolumeId,cstruct, 0, 0, &maxvldbid);
4187 fprintf(STDERR, "Could not get the highest allocated volume id from the VLDB\n");
4188 if (!error) error = code;
4189 } else if (maxvolid > maxvldbid) {
4191 id = maxvolid - maxvldbid + 1;
4192 code = ubik_Call(VL_GetNewVolumeId, cstruct, 0, id, &nid);
4194 fprintf(STDERR,"Error in increasing highest allocated volume id in VLDB\n");
4195 if (!error) error = code;
4200 if (aconn) rx_DestroyConnection(aconn);
4201 if (volumeInfo.volEntries_val)
4202 free(volumeInfo.volEntries_val);
4203 PrintError("",error);
4208 * Determine if a volume exists on a server and partition.
4209 * Try creating a transaction on the volume. If we can,
4210 * the volume exists, if not, then return the error code.
4211 * Some error codes mean the volume is unavailable but
4212 * still exists - so we catch these error codes.
4214 afs_int32 VolumeExists(server, partition, volumeid)
4215 afs_int32 server, partition, volumeid;
4217 struct rx_connection *conn=(struct rx_connection *)0;
4218 afs_int32 code = -1;
4219 volEntries volumeInfo;
4221 conn = UV_Bind(server, AFSCONF_VOLUMEPORT);
4223 volumeInfo.volEntries_val = (volintInfo *)0;
4224 volumeInfo.volEntries_len = 0;
4225 code = AFSVolListOneVolume(conn, partition, volumeid, &volumeInfo);
4226 if (volumeInfo.volEntries_val)
4227 free(volumeInfo.volEntries_val);
4228 if (code == VOLSERILLEGAL_PARTITION)
4230 rx_DestroyConnection(conn);
4238 afs_int32 CheckVldbRWBK(entry, modified)
4239 struct nvldbentry *entry;
4240 afs_int32 *modified;
4244 afs_int32 code, error = 0;
4247 if (modified) *modified = 0;
4248 idx = Lp_GetRwIndex(entry);
4250 /* Check to see if the RW volume exists and set the RW_EXISTS
4253 if (idx == -1) { /* Did not find a RW entry */
4254 if (entry->flags & RW_EXISTS) { /* ... yet entry says RW exists */
4255 entry->flags &= ~RW_EXISTS; /* ... so say RW does not exist */
4259 code = VolumeExists(entry->serverNumber[idx],
4260 entry->serverPartition[idx],
4261 entry->volumeId[RWVOL]);
4262 if (code == 0) { /* RW volume exists */
4263 if (!(entry->flags & RW_EXISTS)) { /* ... yet entry says RW does not exist */
4264 entry->flags |= RW_EXISTS; /* ... so say RW does exist */
4268 else if (code == ENODEV) { /* RW volume does not exist */
4269 if (entry->flags & RW_EXISTS) { /* ... yet entry says RW exists */
4270 entry->flags &= ~RW_EXISTS; /* ... so say RW does not exist */
4275 /* If VLDB says it didn't exist, then ignore error */
4276 if (entry->flags & RW_EXISTS) {
4277 MapPartIdIntoName(entry->serverPartition[idx], pname);
4278 fprintf(STDERR,"Transaction call failed for RW volume %u on server %s %s\n",
4279 entry->volumeId[RWVOL],
4280 hostutil_GetNameByINet(entry->serverNumber[idx]), pname);
4286 /* Check to see if the BK volume exists and set the BACK_EXISTS
4287 * flag accordingly. idx already ponts to the RW entry.
4289 if (idx == -1) { /* Did not find a RW entry */
4290 if (entry->flags & BACK_EXISTS) { /* ... yet entry says BK exists */
4291 entry->flags &= ~BACK_EXISTS; /* ... so say BK does not exist */
4295 else { /* Found a RW entry */
4296 code = VolumeExists(entry->serverNumber[idx],
4297 entry->serverPartition[idx],
4298 entry->volumeId[BACKVOL]);
4299 if (code == 0) { /* BK volume exists */
4300 if (!(entry->flags & BACK_EXISTS)) { /* ... yet entry says BK does not exist */
4301 entry->flags |= BACK_EXISTS; /* ... so say BK does exist */
4305 else if (code == ENODEV) { /* BK volume does not exist */
4306 if (entry->flags & BACK_EXISTS) { /* ... yet entry says BK exists */
4307 entry->flags &= ~BACK_EXISTS; /* ... so say BK does not exist */
4312 /* If VLDB says it didn't exist, then ignore error */
4313 if (entry->flags & BACK_EXISTS) {
4314 MapPartIdIntoName(entry->serverPartition[idx], pname);
4315 fprintf(STDERR,"Transaction call failed for BK volume %u on server %s %s\n",
4316 entry->volumeId[BACKVOL],
4317 hostutil_GetNameByINet(entry->serverNumber[idx]), pname);
4323 /* If there is an idx but the BK and RW volumes no
4324 * longer exist, then remove the RW entry.
4326 if ((idx != -1) && !(entry->flags & RW_EXISTS) &&
4327 !(entry->flags & BACK_EXISTS)) {
4328 Lp_SetRWValue(entry, entry->serverNumber[idx],
4329 entry->serverPartition[idx], 0L, 0L);
4335 if (modified) *modified = modentry;
4339 CheckVldbRO(entry, modified)
4340 struct nvldbentry *entry;
4341 afs_int32 *modified;
4344 int foundro = 0, modentry = 0;
4345 afs_int32 code, error = 0;
4348 if (modified) *modified = 0;
4350 /* Check to see if the RO volumes exist and set the RO_EXISTS
4353 for (idx=0; idx < entry->nServers; idx++) {
4354 if (!(entry->serverFlags[idx] & ITSROVOL)) {
4355 continue; /* not a RO */
4358 code = VolumeExists(entry->serverNumber[idx],
4359 entry->serverPartition[idx],
4360 entry->volumeId[ROVOL]);
4361 if (code == 0) { /* RO volume exists */
4364 else if (code == ENODEV) { /* RW volume does not exist */
4365 Lp_SetROValue(entry, entry->serverNumber[idx],
4366 entry->serverPartition[idx], 0L, 0L);
4372 MapPartIdIntoName(entry->serverPartition[idx], pname);
4373 fprintf(STDERR,"Transaction call failed for RO %u on server %s %s\n",
4374 entry->volumeId[ROVOL],
4375 hostutil_GetNameByINet(entry->serverNumber[idx]), pname);
4380 if (foundro) { /* A RO volume exists */
4381 if (!(entry->flags & RO_EXISTS)) { /* ... yet entry says RW does not exist */
4382 entry->flags |= RO_EXISTS; /* ... so say RW does exist */
4385 } else { /* A RO volume does not exist */
4386 if (entry->flags & RO_EXISTS) { /* ... yet entry says RO exists */
4387 entry->flags &= ~RO_EXISTS; /* ... so say RO does not exist */
4393 if (modified) *modified = modentry;
4398 * Ensure that <entry> matches with the info on file servers
4400 afs_int32 CheckVldb(entry, modified)
4401 struct nvldbentry *entry;
4402 afs_int32 *modified;
4404 afs_int32 code, error=0;
4406 struct nvldbentry storeEntry;
4407 int islocked=0, mod, modentry, delentry=0;
4408 int foundro, pass=0;
4410 if (modified) *modified = 0;
4412 fprintf(STDOUT,"_______________________________\n");
4413 fprintf(STDOUT,"\n-- status before -- \n");
4414 if ((entry->flags & RW_EXISTS) ||
4415 (entry->flags & RO_EXISTS) ||
4416 (entry->flags & BACK_EXISTS))
4417 EnumerateEntry(entry);
4418 fprintf(STDOUT,"\n");
4421 if (strlen(entry->name) > (VOLSER_OLDMAXVOLNAME - 10)) {
4422 fprintf(STDERR,"Volume name %s exceeds limit of %d characters\n",
4423 entry->name, VOLSER_OLDMAXVOLNAME-10);
4427 /* Check to see if the VLDB is ok without locking it (pass 1).
4428 * If it will change, then lock the VLDB entry, read it again,
4429 * then make the changes to it (pass 2).
4432 code = ubik_Call(VL_SetLock,cstruct, 0, entry->volumeId[RWVOL], RWVOL, VLOP_DELETE);
4434 fprintf(STDERR, "Could not lock VLDB entry for %u \n",entry->volumeId[RWVOL] );
4439 code = VLDB_GetEntryByID(entry->volumeId[RWVOL], RWVOL, entry);
4441 fprintf(STDERR,"Could not read VLDB entry for volume %s\n", entry->name);
4445 MapHostToNetwork(entry);
4451 /* Check if the RW and BK entries are ok */
4452 code = CheckVldbRWBK(entry, &mod);
4453 if (code) ERROR_EXIT(code);
4454 if (mod && (pass == 1)) goto retry;
4455 if (mod) modentry++;
4457 /* Check if the RO volumes entries are ok */
4458 code = CheckVldbRO(entry, &mod);
4459 if (code) ERROR_EXIT(code);
4460 if (mod && (pass == 1)) goto retry;
4461 if (mod) modentry++;
4463 /* The VLDB entry has been updated. If it as been modified, then
4464 * write the entry back out the the VLDB.
4467 if (pass == 1) goto retry;
4469 if (!(entry->flags & RW_EXISTS) &&
4470 !(entry->flags & BACK_EXISTS) &&
4471 !(entry->flags & RO_EXISTS)) {
4472 /* The RW, BK, nor RO volumes do not exist. Delete the VLDB entry */
4473 code = ubik_Call(VL_DeleteEntry, cstruct, 0, entry->volumeId[RWVOL], RWVOL);
4475 fprintf(STDERR,"Could not delete VLDB entry for volume %u \n",
4476 entry->volumeId[RWVOL]);
4482 /* Replace old entry with our new one */
4483 MapNetworkToHost(entry,&storeEntry);
4484 code = VLDB_ReplaceEntry(entry->volumeId[RWVOL], RWVOL, &storeEntry,
4485 (LOCKREL_OPCODE | LOCKREL_AFSID | LOCKREL_TIMESTAMP));
4487 fprintf(STDERR,"Could not update VLDB entry for volume %u\n",
4488 entry->volumeId[RWVOL] );
4492 if (modified) *modified = 1;
4497 fprintf(STDOUT,"-- status after --\n");
4499 fprintf(STDOUT,"\n**entry deleted**\n");
4501 EnumerateEntry(entry);
4503 fprintf(STDOUT,"\n**no change**\n");
4508 fprintf(STDOUT,"\n_______________________________\n");
4512 code = ubik_Call(VL_ReleaseLock, cstruct, 0, entry->volumeId[RWVOL], RWVOL,
4513 (LOCKREL_OPCODE | LOCKREL_AFSID | LOCKREL_TIMESTAMP));
4515 fprintf(STDERR,"Could not release lock on VLDB entry for volume %u\n",
4516 entry->volumeId[RWVOL]);
4517 if (!error) error = code;
4524 * Synchronise <aserver> <apart>(if flags = 1) with the VLDB.
4526 UV_SyncServer(aserver, apart, flags, force)
4527 afs_int32 aserver, apart;
4530 struct rx_connection *aconn;
4531 afs_int32 code, error = 0;
4532 afs_int32 nentries, tentries=0;
4533 struct VldbListByAttributes attributes;
4534 nbulkentries arrayEntries;
4535 afs_int32 failures=0, modified, modifications=0;
4536 struct nvldbentry *vlentry;
4537 afs_int32 si, nsi, j;
4539 aconn = UV_Bind(aserver,AFSCONF_VOLUMEPORT);
4541 /* Set up attributes to search VLDB */
4542 attributes.server = ntohl(aserver);
4543 attributes.Mask = VLLIST_SERVER;
4545 attributes.partition = apart;
4546 attributes.Mask |= VLLIST_PARTITION;
4550 fprintf(STDOUT,"Processing VLDB entries ...\n");
4554 /* While we need to collect more VLDB entries */
4555 for (si=0; si != -1; si=nsi) {
4556 memset(&arrayEntries, 0, sizeof(arrayEntries));
4558 /* Collect set of VLDB entries */
4559 code = VLDB_ListAttributesN2(&attributes, 0, si,
4560 &nentries, &arrayEntries, &nsi);
4561 if (code == RXGEN_OPCODE) {
4562 code = VLDB_ListAttributes(&attributes, &nentries, &arrayEntries);
4566 fprintf(STDERR,"Could not access the VLDB for attributes\n");
4569 tentries += nentries;
4571 for (j=0; j<nentries; j++) {
4572 vlentry = &arrayEntries.nbulkentries_val[j];
4573 MapHostToNetwork(vlentry);
4576 fprintf(STDOUT,"Processing VLDB entry %d ...\n", j+1);
4580 code = CheckVldb(vlentry, &modified);
4582 PrintError("",code);
4583 fprintf(STDERR,"Could not process VLDB entry for volume %s\n",
4586 } else if (modified) {
4592 fprintf(STDOUT,"...error encountered\n\n");
4594 fprintf(STDOUT,"...done entry %d\n\n", j+1);
4599 if (arrayEntries.nbulkentries_val) {
4600 free(arrayEntries.nbulkentries_val);
4601 arrayEntries.nbulkentries_val = 0;
4606 fprintf(STDOUT,"Total entries: %u, Failed to process %d, Changed %d\n",
4607 tentries, failures, modifications);
4612 rx_DestroyConnection(aconn);
4613 if (arrayEntries.nbulkentries_val)
4614 free(arrayEntries.nbulkentries_val);
4617 error = VOLSERFAILEDOP;
4621 /*rename volume <oldname> to <newname>, changing the names of the related
4622 *readonly and backup volumes. This operation is also idempotent.
4623 *salvager is capable of recovering from rename operation stopping halfway.
4624 *to recover run syncserver on the affected machines,it will force renaming to completion. name clashes should have been detected before calling this proc */
4625 UV_RenameVolume(entry,oldname,newname)
4626 struct nvldbentry *entry;
4627 char oldname[],newname[];
4629 struct nvldbentry storeEntry;
4630 afs_int32 vcode,code,rcode,error;
4632 char nameBuffer[256];
4634 struct rx_connection *aconn;
4638 aconn = (struct rx_connection *)0;
4642 vcode = ubik_Call(VL_SetLock,cstruct, 0,entry->volumeId[RWVOL], RWVOL, VLOP_ADDSITE);/*last param is dummy*/
4644 fprintf(STDERR," Could not lock the VLDB entry for the volume %u \n",entry->volumeId[RWVOL] );
4649 strncpy(entry->name,newname,VOLSER_OLDMAXVOLNAME);
4650 MapNetworkToHost(entry,&storeEntry);
4651 vcode = VLDB_ReplaceEntry(entry->volumeId[RWVOL],RWVOL, &storeEntry,0 );
4653 fprintf(STDERR,"Could not update VLDB entry for %u\n",entry->volumeId[RWVOL]);
4657 if(verbose) fprintf(STDOUT,"Recorded the new name %s in VLDB\n",newname);
4658 /*at this stage the intent to rename is recorded in the vldb, as far as the vldb
4659 is concerned, oldname is lost */
4660 if(entry->flags & RW_EXISTS) {
4661 index = Lp_GetRwIndex(entry);
4662 if(index == -1){ /* there is a serious discrepancy */
4663 fprintf(STDERR,"There is a serious discrepancy in VLDB entry for volume %u\n",entry->volumeId[RWVOL]);
4664 fprintf(STDERR,"try building VLDB from scratch\n");
4665 error = VOLSERVLDB_ERROR;
4668 aconn = UV_Bind(entry->serverNumber[index],AFSCONF_VOLUMEPORT);
4669 code = AFSVolTransCreate(aconn,entry->volumeId[RWVOL],entry->serverPartition[index], ITOffline, &tid);
4670 if(code) { /*volume doesnot exist */
4671 fprintf(STDERR,"Could not start transaction on the rw volume %u\n",entry->volumeId[RWVOL]);
4675 else {/*volume exists, process it */
4677 code = AFSVolSetIdsTypes(aconn, tid, newname,RWVOL, entry->volumeId[RWVOL],entry->volumeId[ROVOL],entry->volumeId[BACKVOL]);
4679 if(verbose) printf("Renamed rw volume %s to %s\n",oldname,newname);
4680 code = AFSVolEndTrans(aconn, tid, &rcode);
4683 fprintf(STDERR,"Could not end transaction on volume %s %u\n",entry->name,entry->volumeId[RWVOL]);
4689 fprintf(STDERR,"Could not set parameters on volume %s %u\n",entry->name,entry->volumeId[RWVOL]);
4694 if(aconn) rx_DestroyConnection(aconn);
4695 aconn = (struct rx_connection *)0;
4696 } /*end rw volume processing */
4698 if(entry->flags & BACK_EXISTS) {/*process the backup volume */
4699 index = Lp_GetRwIndex(entry);
4700 if(index == -1){ /* there is a serious discrepancy */
4701 fprintf(STDERR,"There is a serious discrepancy in the VLDB entry for the backup volume %u\n",entry->volumeId[BACKVOL]);
4702 fprintf(STDERR,"try building VLDB from scratch\n");
4703 error = VOLSERVLDB_ERROR;
4706 aconn = UV_Bind(entry->serverNumber[index],AFSCONF_VOLUMEPORT);
4707 code = AFSVolTransCreate(aconn,entry->volumeId[BACKVOL],entry->serverPartition[index], ITOffline, &tid);
4708 if(code) { /*volume doesnot exist */
4709 fprintf(STDERR,"Could not start transaction on the backup volume %u\n",entry->volumeId[BACKVOL]);
4713 else {/*volume exists, process it */
4714 if(strlen(newname) > (VOLSER_OLDMAXVOLNAME - 8)){
4715 fprintf(STDERR,"Volume name %s.backup exceeds the limit of %u characters\n",newname,VOLSER_OLDMAXVOLNAME);
4719 strcpy(nameBuffer,newname);
4720 strcat(nameBuffer,".backup");
4722 code = AFSVolSetIdsTypes(aconn, tid,nameBuffer ,BACKVOL, entry->volumeId[RWVOL],0,0);
4724 if(verbose) fprintf(STDOUT,"Renamed backup volume to %s \n",nameBuffer);
4725 code = AFSVolEndTrans(aconn, tid, &rcode);
4728 fprintf(STDERR,"Could not end transaction on the backup volume %u\n",entry->volumeId[BACKVOL]);
4734 fprintf(STDERR,"Could not set parameters on the backup volume %u\n",entry->volumeId[BACKVOL]);
4739 } /* end backup processing */
4740 if(aconn) rx_DestroyConnection(aconn);
4741 aconn = (struct rx_connection *)0;
4742 if(entry->flags & RO_EXISTS){ /*process the ro volumes */
4743 for(i = 0; i < entry->nServers; i++){
4744 if(entry->serverFlags[i] & ITSROVOL) {
4745 aconn = UV_Bind(entry->serverNumber[i],AFSCONF_VOLUMEPORT);
4746 code = AFSVolTransCreate(aconn,entry->volumeId[ROVOL],entry->serverPartition[i], ITOffline, &tid);
4747 if(code) { /*volume doesnot exist */
4748 fprintf(STDERR,"Could not start transaction on the ro volume %u\n",entry->volumeId[ROVOL]);
4752 else {/*volume exists, process it */
4753 strcpy(nameBuffer,newname);
4754 strcat(nameBuffer,".readonly");
4755 if(strlen(nameBuffer) > (VOLSER_OLDMAXVOLNAME - 1)){
4756 fprintf(STDERR,"Volume name %s exceeds the limit of %u characters\n",nameBuffer,VOLSER_OLDMAXVOLNAME);
4760 code = AFSVolSetIdsTypes(aconn, tid, nameBuffer,ROVOL, entry->volumeId[RWVOL],0,0);
4762 if(verbose) fprintf(STDOUT,"Renamed RO volume %s on host %s\n",
4764 hostutil_GetNameByINet(entry->serverNumber[i]));
4765 code = AFSVolEndTrans(aconn, tid, &rcode);
4768 fprintf(STDERR,"Could not end transaction on volume %u\n",entry->volumeId[ROVOL]);
4774 fprintf(STDERR,"Could not set parameters on the ro volume %u\n",entry->volumeId[ROVOL]);
4779 if(aconn) rx_DestroyConnection(aconn);
4780 aconn = (struct rx_connection *)0;
4786 vcode = ubik_Call(VL_ReleaseLock,cstruct, 0,entry->volumeId[RWVOL] , RWVOL, LOCKREL_OPCODE | LOCKREL_AFSID | LOCKREL_TIMESTAMP);
4788 fprintf(STDERR,"Could not unlock the VLDB entry for the volume %s %u\n",entry->name,entry->volumeId[RWVOL]);
4789 if(!error) error = vcode;
4793 code = AFSVolEndTrans(aconn, tid, &rcode);
4794 if(!code) code = rcode;
4796 fprintf(STDERR,"Failed to end transaction on a volume \n");
4797 if(!error) error = code;
4800 if(aconn) rx_DestroyConnection(aconn);
4801 PrintError("",error);
4806 /*report on all the active transactions on volser */
4807 UV_VolserStatus(server,rpntr,rcount)
4809 transDebugInfo **rpntr;
4812 struct rx_connection *aconn;
4813 transDebugEntries transInfo;
4816 aconn = UV_Bind(server, AFSCONF_VOLUMEPORT);
4817 transInfo.transDebugEntries_val = (transDebugInfo *) 0;
4818 transInfo.transDebugEntries_len = 0;
4819 code = AFSVolMonitor(aconn,&transInfo);
4821 fprintf(STDERR,"Could not access status information about the server\n");
4822 PrintError("",code);
4823 if (transInfo.transDebugEntries_val) free(transInfo.transDebugEntries_val);
4824 if(aconn) rx_DestroyConnection(aconn);
4828 *rcount = transInfo.transDebugEntries_len;
4829 *rpntr = transInfo.transDebugEntries_val;
4830 if(aconn) rx_DestroyConnection(aconn);
4836 /*delete the volume without interacting with the vldb */
4837 UV_VolumeZap(server,part,volid)
4838 afs_int32 volid,server,part;
4841 afs_int32 rcode,ttid,error,code;
4842 struct rx_connection *aconn;
4848 aconn = UV_Bind(server, AFSCONF_VOLUMEPORT);
4849 code = AFSVolTransCreate(aconn, volid, part, ITOffline, &ttid);
4851 fprintf(STDERR,"Could not start transaction on volume %u\n",volid);
4855 code = AFSVolDeleteVolume(aconn, ttid);
4857 fprintf(STDERR,"Could not delete volume %u\n",volid);
4861 code = AFSVolEndTrans(aconn, ttid, &rcode);
4863 if(!code) code = rcode;
4865 fprintf(STDERR,"Could not end transaction on volume %u\n",volid);
4871 code = AFSVolEndTrans(aconn,ttid,&rcode);
4872 if(!code) code = rcode;
4873 if(!error) error = code;
4875 PrintError("",error);
4876 if(aconn) rx_DestroyConnection(aconn);
4880 UV_SetVolume(server, partition, volid, transflag, setflag, sleeptime)
4881 afs_int32 server, partition, volid, transflag, setflag;
4883 struct rx_connection *conn = 0;
4885 afs_int32 code, error=0, rcode;
4887 conn = UV_Bind(server, AFSCONF_VOLUMEPORT);
4889 fprintf(STDERR, "SetVolumeStatus: Bind Failed");
4893 code = AFSVolTransCreate(conn, volid, partition, transflag, &tid);
4895 fprintf(STDERR, "SetVolumeStatus: TransCreate Failed\n");
4899 code = AFSVolSetFlags(conn, tid, setflag);
4901 fprintf(STDERR, "SetVolumeStatus: SetFlags Failed\n");
4906 #ifdef AFS_PTHREAD_ENV
4909 IOMGR_Sleep(sleeptime);
4916 code = AFSVolEndTrans(conn, tid, &code);
4917 if (code || rcode) {
4918 fprintf(STDERR, "SetVolumeStatus: EndTrans Failed\n");
4919 if (!error) error = (code ? code : rcode);
4923 if (conn) rx_DestroyConnection(conn);
4927 /*maps the host addresses in <old > (present in network byte order) to
4928 that in< new> (present in host byte order )*/
4929 MapNetworkToHost(old, new)
4930 struct nvldbentry *old, *new;
4934 /*copy all the fields */
4935 strcpy(new->name,old->name);
4936 /* new->volumeType = old->volumeType;*/
4937 new->nServers = old->nServers;
4938 count = old->nServers;
4939 if(count < NMAXNSERVERS) count++;
4940 for(i = 0; i < count; i++) {
4941 new->serverNumber[i] = ntohl(old->serverNumber[i]);
4942 new->serverPartition[i] = old->serverPartition[i];
4943 new->serverFlags[i] = old->serverFlags[i];
4945 new->volumeId[RWVOL]= old->volumeId[RWVOL];
4946 new->volumeId[ROVOL] = old->volumeId[ROVOL];
4947 new->volumeId[BACKVOL] = old->volumeId[BACKVOL];
4948 new->cloneId = old->cloneId;
4949 new->flags = old->flags;
4953 /*maps the host entries in <entry> which are present in host byte order to network byte order */
4954 MapHostToNetwork(entry)
4955 struct nvldbentry *entry;
4959 count = entry->nServers;
4960 if(count < NMAXNSERVERS) count++;
4961 for(i = 0; i < count; i++) {
4962 entry->serverNumber[i] = htonl(entry->serverNumber[i]);