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>
15 #include <sys/types.h>
24 #include <netinet/in.h>
28 #include <sys/statfs.h>
35 #include <rx/rx_globals.h>
37 #include <afs/vlserver.h>
39 #include <afs/cellconfig.h>
41 #include <afs/afsutil.h>
43 #include <afs/afsint.h>
65 #define COMMONPARMS cmd_Seek(ts, 12);\
66 cmd_AddParm(ts, "-cell", CMD_SINGLE, CMD_OPTIONAL, "cell name");\
67 cmd_AddParm(ts, "-noauth", CMD_FLAG, CMD_OPTIONAL, "don't authenticate");\
68 cmd_AddParm(ts, "-localauth",CMD_FLAG,CMD_OPTIONAL,"use server tickets");\
69 cmd_AddParm(ts, "-verbose", CMD_FLAG, CMD_OPTIONAL, "verbose");\
71 #define ERROR_EXIT(code) {error=(code); goto error_exit;}
75 struct rx_connection *tconn;
77 extern struct ubik_client *cstruct;
79 extern struct rx_connection *UV_Bind();
80 extern struct rx_securityClass *rxnull_NewClientSecurityObject();
81 extern int UV_SetSecurity();
83 extern VL_ReleaseLock();
84 extern VL_DeleteEntry();
85 extern VL_ListEntry();
87 extern VL_GetAddrsU();
88 extern VL_ChangeAddr();
90 extern int vsu_ExtractName();
92 extern int MapPartIdIntoName();
93 extern int MapHostToNetwork();
94 extern int MapNetworkToHost();
95 extern void EnumerateEntry();
96 extern void SubEnumerateEntry();
99 static struct tqHead busyHead, notokHead;
101 static void qInit(ahead)
102 struct tqHead *ahead;
104 bzero((char *)ahead, sizeof(struct tqHead));
109 static void qPut(ahead,volid)
110 struct tqHead *ahead;
115 elem = (struct tqElem *)malloc(sizeof(struct tqElem));
116 elem->next = ahead->next;
123 static void qGet(ahead,volid)
124 struct tqHead *ahead;
129 if(ahead->count <= 0) return;
130 *volid = ahead->next->volid;
132 ahead->next = tmp->next;
138 /* returns 1 if <filename> exists else 0 */
139 static FileExists(filename)
146 code = usd_Open(filename, USD_OPEN_RDONLY, 0, &ufd);
150 code = USD_IOCTL(ufd, USD_IOCTL_GETSIZE, &size);
158 /* returns 1 if <name> doesnot end in .readonly or .backup, else 0 */
159 static VolNameOK(name)
165 total = strlen(name);
166 if(!strcmp(&name[total - 9],".readonly")) {
169 else if(!strcmp(&name[total - 7 ],".backup")) {
177 /* return 1 if name is a number else 0 */
178 static IsNumeric(name)
187 for(i = 0; i < len ; i++){
188 if(*ptr < '0' || *ptr > '9'){
202 * Parse a server name/address and return the address in HOST BYTE order
204 afs_int32 GetServer(aname)
206 register struct hostent *th;
209 register afs_int32 code;
210 char hostname[MAXHOSTCHARS];
212 code = sscanf(aname, "%d.%d.%d.%d", &b1, &b2, &b3, &b4);
214 addr = (b1<<24) | (b2<<16) | (b3<<8) | b4;
215 addr = ntohl(addr); /* convert to host order */
217 th = gethostbyname(aname);
219 bcopy(th->h_addr, &addr, sizeof(addr));
222 if (addr == htonl(0x7f000001)) { /* local host */
223 code = gethostname(hostname, MAXHOSTCHARS);
225 th = gethostbyname(hostname); /* returns host byte order */
227 bcopy(th->h_addr, &addr, sizeof(addr));
233 afs_int32 GetVolumeType(aname)
237 if(!strcmp(aname,"ro"))
239 else if(!strcmp(aname, "rw"))
241 else if(!strcmp(aname,"bk"))
246 int IsPartValid(partId, server, code)
247 afs_int32 server, partId,*code;
250 struct partList dummyPartList;
258 *code = UV_ListPartitions(server,&dummyPartList, &cnt);
259 if(*code) return success;
260 for(i = 0 ; i < cnt ; i++) {
261 if(dummyPartList.partFlags[i] & PARTVALID)
262 if(dummyPartList.partId[i] == partId)
270 /*sends the contents of file associated with <fd> and <blksize> to Rx Stream
271 * associated with <call> */
272 SendFile(ufd, call, blksize)
274 register struct rx_call *call;
277 char *buffer = (char*) 0;
282 buffer = (char *)malloc(blksize);
284 fprintf(STDERR,"malloc failed\n");
288 while (!error && !done) {
289 #ifndef AFS_NT40_ENV /* NT csn't select on non-socket fd's */
292 FD_SET((int)(ufd->handle), &in);
293 /* don't timeout if read blocks */
294 IOMGR_Select(((int)(ufd->handle))+1, &in, 0, 0, 0);
296 error = USD_READ(ufd, buffer, blksize, &nbytes);
298 fprintf(STDERR, "File system read failed\n");
305 if (rx_Write(call, buffer, nbytes) != nbytes){
310 if (buffer) free(buffer);
314 /* function invoked by UV_RestoreVolume, reads the data from rx_trx_stream and
315 * writes it out to the volume. */
316 afs_int32 WriteData(call,rock)
317 struct rx_call *call;
323 afs_int32 error,code;
329 if(!filename || !*filename) {
330 usd_StandardInput(&ufd);
334 code = usd_Open(filename, USD_OPEN_RDONLY, 0, &ufd);
337 code = USD_IOCTL(ufd, USD_IOCTL_GETBLKSIZE, &blksize);
340 fprintf(STDERR,"Could not access file '%s'\n", filename);
345 code = SendFile(ufd,call,blksize);
352 code = USD_CLOSE(ufd);
354 fprintf(STDERR,"Could not close dump file %s\n",
355 (filename && *filename)?filename:"STDOUT");
356 if(!error) error = code;
362 /* Receive data from <call> stream into file associated
363 * with <fd> <blksize>
365 int ReceiveFile(ufd, call, blksize)
367 struct rx_call *call;
370 char *buffer = (char *) 0;
372 afs_uint32 bytesleft, w;
375 buffer = (char *)malloc(blksize);
377 fprintf(STDERR,"memory allocation failed\n");
381 while ((bytesread=rx_Read(call,buffer,blksize)) > 0) {
382 for (bytesleft=bytesread; bytesleft; bytesleft-=w) {
383 #ifndef AFS_NT40_ENV /* NT csn't select on non-socket fd's */
386 FD_SET((int)(ufd->handle), &out);
387 /* don't timeout if write blocks */
388 IOMGR_Select(((int)(ufd->handle))+1, 0, &out, 0, 0);
390 error = USD_WRITE(ufd, &buffer[bytesread-bytesleft], bytesleft, &w);
392 fprintf(STDERR,"File system write failed\n");
399 if (buffer) free(buffer);
403 afs_int32 DumpFunction(call, filename)
404 struct rx_call *call;
407 usd_handle_t ufd; /* default is to stdout */
408 afs_int32 error=0, code;
413 /* Open the output file */
414 if (!filename || !*filename) {
415 usd_StandardOutput(&ufd);
419 code = usd_Open(filename, USD_OPEN_CREATE|USD_OPEN_RDWR, 0666, &ufd);
423 code = USD_IOCTL(ufd, USD_IOCTL_SETSIZE, &size);
426 code = USD_IOCTL(ufd, USD_IOCTL_GETBLKSIZE, &blksize);
429 fprintf(STDERR, "Could not create file '%s'\n", filename);
430 ERROR_EXIT(VOLSERBADOP);
434 code = ReceiveFile(ufd, call, blksize);
435 if (code) ERROR_EXIT(code);
438 /* Close the output file */
440 code = USD_CLOSE(ufd);
442 fprintf(STDERR,"Could not close dump file %s\n",
443 (filename && *filename)?filename:"STDIN");
444 if (!error) error = code;
451 static void DisplayFormat(pntr,server,part,totalOK,totalNotOK,totalBusy,fast,longlist,disp)
453 afs_int32 server,part;
454 int *totalOK,*totalNotOK,*totalBusy;
455 int fast,longlist, disp;
460 fprintf(STDOUT,"%-10u\n",pntr->volid);
463 if(pntr->status == VOK){
464 fprintf(STDOUT,"%-32s ",pntr->name);
465 fprintf(STDOUT,"%10u ",pntr->volid);
466 if(pntr->type == 0) fprintf(STDOUT,"RW ");
467 if(pntr->type == 1) fprintf(STDOUT,"RO ");
468 if(pntr->type == 2) fprintf(STDOUT,"BK ");
469 fprintf(STDOUT,"%10d K ",pntr->size);
470 if(pntr->inUse == 1) {
471 fprintf(STDOUT,"On-line");
474 fprintf(STDOUT,"Off-line");
477 if(pntr->needsSalvaged == 1) fprintf(STDOUT,"**needs salvage**");
478 fprintf(STDOUT,"\n");
479 MapPartIdIntoName(part,pname);
480 fprintf(STDOUT," %s %s \n",hostutil_GetNameByINet(server),pname);
481 fprintf(STDOUT," RWrite %10u ROnly %10u Backup %10u \n", pntr->parentID,pntr->cloneID, pntr->backupID);
482 fprintf(STDOUT," MaxQuota %10d K \n",pntr->maxquota);
483 fprintf(STDOUT," Creation %s",
484 ctime((time_t *)&pntr->creationDate));
485 if(pntr->updateDate < pntr->creationDate)
486 fprintf(STDOUT," Last Update %s",
487 ctime((time_t *)&pntr->creationDate));
489 fprintf(STDOUT," Last Update %s",
490 ctime((time_t *)&pntr->updateDate));
491 fprintf(STDOUT, " %d accesses in the past day (i.e., vnode references)\n",
494 else if (pntr->status == VBUSY) {
496 qPut(&busyHead,pntr->volid);
497 if (disp) fprintf(STDOUT,"**** Volume %u is busy ****\n",pntr->volid);
501 qPut(¬okHead,pntr->volid);
502 if (disp) fprintf(STDOUT,"**** Could not attach volume %u ****\n",pntr->volid);
504 fprintf(STDOUT,"\n");
506 else {/* default listing */
507 if(pntr->status == VOK){
508 fprintf(STDOUT,"%-32s ",pntr->name);
509 fprintf(STDOUT,"%10u ",pntr->volid);
510 if(pntr->type == 0) fprintf(STDOUT,"RW ");
511 if(pntr->type == 1) fprintf(STDOUT,"RO ");
512 if(pntr->type == 2) fprintf(STDOUT,"BK ");
513 fprintf(STDOUT,"%10d K ",pntr->size);
514 if(pntr->inUse == 1) {
515 fprintf(STDOUT,"On-line");
518 fprintf(STDOUT,"Off-line");
521 if(pntr->needsSalvaged == 1) fprintf(STDOUT,"**needs salvage**");
522 fprintf(STDOUT,"\n");
524 else if (pntr->status == VBUSY) {
526 qPut(&busyHead,pntr->volid);
527 if (disp) fprintf(STDOUT,"**** Volume %u is busy ****\n",pntr->volid);
531 qPut(¬okHead,pntr->volid);
532 if (disp) fprintf(STDOUT,"**** Could not attach volume %u ****\n",pntr->volid);
537 /*------------------------------------------------------------------------
538 * PRIVATE XDisplayFormat
541 * Display the contents of one extended volume info structure.
544 * a_xInfoP : Ptr to extended volume info struct to print.
545 * a_servID : Server ID to print.
546 * a_partID : Partition ID to print.
547 * a_totalOKP : Ptr to total-OK counter.
548 * a_totalNotOKP : Ptr to total-screwed counter.
549 * a_totalBusyP : Ptr to total-busy counter.
550 * a_fast : Fast listing?
551 * a_int32 : Int32 listing?
552 * a_showProblems : Show volume problems?
558 * Nothing interesting.
562 *------------------------------------------------------------------------*/
564 static void XDisplayFormat(a_xInfoP, a_servID, a_partID, a_totalOKP,
565 a_totalNotOKP, a_totalBusyP, a_fast, a_int32,
567 volintXInfo *a_xInfoP;
585 fprintf(STDOUT, "%-10u\n", a_xInfoP->volid);
590 * Fully-detailed listing.
592 if (a_xInfoP->status == VOK) {
594 * Volume's status is OK - all the fields are valid.
596 fprintf(STDOUT, "%-32s ", a_xInfoP->name);
597 fprintf(STDOUT, "%10u ", a_xInfoP->volid);
598 if (a_xInfoP->type == 0) fprintf(STDOUT,"RW ");
599 if (a_xInfoP->type == 1) fprintf(STDOUT,"RO ");
600 if (a_xInfoP->type == 2) fprintf(STDOUT,"BK ");
601 fprintf(STDOUT, "%10d K used ", a_xInfoP->size);
602 fprintf(STDOUT, "%d files ", a_xInfoP->filecount);
603 if(a_xInfoP->inUse == 1) {
604 fprintf(STDOUT, "On-line");
608 fprintf(STDOUT, "Off-line");
611 fprintf(STDOUT, "\n");
612 MapPartIdIntoName(a_partID, pname);
613 fprintf(STDOUT, " %s %s \n",
614 hostutil_GetNameByINet(a_servID),
616 fprintf(STDOUT, " RWrite %10u ROnly %10u Backup %10u \n",
617 a_xInfoP->parentID, a_xInfoP->cloneID, a_xInfoP->backupID);
618 fprintf(STDOUT, " MaxQuota %10d K \n",
620 fprintf(STDOUT, " Creation %s",
621 ctime((time_t *)&a_xInfoP->creationDate));
622 if (a_xInfoP->updateDate < a_xInfoP->creationDate)
623 fprintf(STDOUT, " Last Update %s",
624 ctime((time_t *)&a_xInfoP->creationDate));
626 fprintf(STDOUT, " Last Update %s",
627 ctime((time_t *)&a_xInfoP->updateDate));
628 fprintf(STDOUT, " %d accesses in the past day (i.e., vnode references)\n",
632 * Print all the read/write and authorship stats.
635 "\n Raw Read/Write Stats\n");
637 " |-------------------------------------------|\n");
639 " | Same Network | Diff Network |\n");
641 " |----------|----------|----------|----------|\n");
643 " | Total | Auth | Total | Auth |\n");
645 " |----------|----------|----------|----------|\n");
647 "Reads | %8d | %8d | %8d | %8d |\n",
648 a_xInfoP->stat_reads[VOLINT_STATS_SAME_NET],
649 a_xInfoP->stat_reads[VOLINT_STATS_SAME_NET_AUTH],
650 a_xInfoP->stat_reads[VOLINT_STATS_DIFF_NET],
651 a_xInfoP->stat_reads[VOLINT_STATS_DIFF_NET_AUTH]);
653 "Writes | %8d | %8d | %8d | %8d |\n",
654 a_xInfoP->stat_writes[VOLINT_STATS_SAME_NET],
655 a_xInfoP->stat_writes[VOLINT_STATS_SAME_NET_AUTH],
656 a_xInfoP->stat_writes[VOLINT_STATS_DIFF_NET],
657 a_xInfoP->stat_writes[VOLINT_STATS_DIFF_NET_AUTH]);
659 " |-------------------------------------------|\n\n");
662 " Writes Affecting Authorship\n");
664 " |-------------------------------------------|\n");
666 " | File Authorship | Directory Authorship|\n");
668 " |----------|----------|----------|----------|\n");
670 " | Same | Diff | Same | Diff |\n");
672 " |----------|----------|----------|----------|\n");
674 "0-60 sec | %8d | %8d | %8d | %8d |\n",
675 a_xInfoP->stat_fileSameAuthor[VOLINT_STATS_TIME_IDX_0],
676 a_xInfoP->stat_fileDiffAuthor[VOLINT_STATS_TIME_IDX_0],
677 a_xInfoP->stat_dirSameAuthor[VOLINT_STATS_TIME_IDX_0],
678 a_xInfoP->stat_dirDiffAuthor[VOLINT_STATS_TIME_IDX_0]);
680 "1-10 min | %8d | %8d | %8d | %8d |\n",
681 a_xInfoP->stat_fileSameAuthor[VOLINT_STATS_TIME_IDX_1],
682 a_xInfoP->stat_fileDiffAuthor[VOLINT_STATS_TIME_IDX_1],
683 a_xInfoP->stat_dirSameAuthor[VOLINT_STATS_TIME_IDX_1],
684 a_xInfoP->stat_dirDiffAuthor[VOLINT_STATS_TIME_IDX_1]);
686 "10min-1hr | %8d | %8d | %8d | %8d |\n",
687 a_xInfoP->stat_fileSameAuthor[VOLINT_STATS_TIME_IDX_2],
688 a_xInfoP->stat_fileDiffAuthor[VOLINT_STATS_TIME_IDX_2],
689 a_xInfoP->stat_dirSameAuthor[VOLINT_STATS_TIME_IDX_2],
690 a_xInfoP->stat_dirDiffAuthor[VOLINT_STATS_TIME_IDX_2]);
692 "1hr-1day | %8d | %8d | %8d | %8d |\n",
693 a_xInfoP->stat_fileSameAuthor[VOLINT_STATS_TIME_IDX_3],
694 a_xInfoP->stat_fileDiffAuthor[VOLINT_STATS_TIME_IDX_3],
695 a_xInfoP->stat_dirSameAuthor[VOLINT_STATS_TIME_IDX_3],
696 a_xInfoP->stat_dirDiffAuthor[VOLINT_STATS_TIME_IDX_3]);
698 "1day-1wk | %8d | %8d | %8d | %8d |\n",
699 a_xInfoP->stat_fileSameAuthor[VOLINT_STATS_TIME_IDX_4],
700 a_xInfoP->stat_fileDiffAuthor[VOLINT_STATS_TIME_IDX_4],
701 a_xInfoP->stat_dirSameAuthor[VOLINT_STATS_TIME_IDX_4],
702 a_xInfoP->stat_dirDiffAuthor[VOLINT_STATS_TIME_IDX_4]);
704 "> 1wk | %8d | %8d | %8d | %8d |\n",
705 a_xInfoP->stat_fileSameAuthor[VOLINT_STATS_TIME_IDX_5],
706 a_xInfoP->stat_fileDiffAuthor[VOLINT_STATS_TIME_IDX_5],
707 a_xInfoP->stat_dirSameAuthor[VOLINT_STATS_TIME_IDX_5],
708 a_xInfoP->stat_dirDiffAuthor[VOLINT_STATS_TIME_IDX_5]);
710 " |-------------------------------------------|\n");
711 } /*Volume status OK*/
713 if (a_xInfoP->status == VBUSY) {
715 qPut(&busyHead, a_xInfoP->volid);
717 fprintf(STDOUT, "**** Volume %u is busy ****\n",
722 qPut(¬okHead, a_xInfoP->volid);
724 fprintf(STDOUT, "**** Could not attach volume %u ****\n",
727 fprintf(STDOUT,"\n");
733 if (a_xInfoP->status == VOK) {
734 fprintf(STDOUT, "%-32s ", a_xInfoP->name);
735 fprintf(STDOUT, "%10u ", a_xInfoP->volid);
736 if (a_xInfoP->type == 0) fprintf(STDOUT, "RW ");
737 if (a_xInfoP->type == 1) fprintf(STDOUT, "RO ");
738 if (a_xInfoP->type == 2) fprintf(STDOUT, "BK ");
739 fprintf(STDOUT, "%10d K ", a_xInfoP->size);
740 if(a_xInfoP->inUse == 1) {
741 fprintf(STDOUT, "On-line");
744 fprintf(STDOUT, "Off-line");
747 fprintf(STDOUT, "\n");
750 if (a_xInfoP->status == VBUSY) {
752 qPut(&busyHead, a_xInfoP->volid);
754 fprintf(STDOUT,"**** Volume %u is busy ****\n",
759 qPut(¬okHead, a_xInfoP->volid);
761 fprintf(STDOUT,"**** Could not attach volume %u ****\n",
764 } /*Default listing*/
767 static void DisplayVolumes(server,part,pntr,count,longlist,fast,quiet)
768 afs_int32 server,part;
770 afs_int32 count,longlist,fast;
773 int totalOK,totalNotOK,totalBusy, i;
781 for(i = 0; i < count; i++){
782 DisplayFormat(pntr,server,part,&totalOK,&totalNotOK,&totalBusy,fast,longlist,0);
786 while(busyHead.count){
787 qGet(&busyHead,&volid);
788 fprintf(STDOUT,"**** Volume %u is busy ****\n",volid);
792 while(notokHead.count){
793 qGet(¬okHead,&volid);
794 fprintf(STDOUT,"**** Could not attach volume %u ****\n",volid);
798 fprintf(STDOUT,"\n");
800 fprintf(STDOUT,"Total volumes onLine %d ; Total volumes offLine %d ; Total busy %d\n\n",totalOK,totalNotOK,totalBusy);
805 /*------------------------------------------------------------------------
806 * PRIVATE XDisplayVolumes
809 * Display extended volume information.
812 * a_servID : Pointer to the Rx call we're performing.
813 * a_partID : Partition for which we want the extended list.
814 * a_xInfoP : Ptr to extended volume info.
815 * a_count : Number of volume records contained above.
816 * a_int32 : Int32 listing generated?
817 * a_fast : Fast listing generated?
818 * a_quiet : Quiet listing generated?
824 * Nothing interesting.
828 *------------------------------------------------------------------------*/
830 static void XDisplayVolumes(a_servID, a_partID, a_xInfoP,
831 a_count, a_int32, a_fast, a_quiet)
834 volintXInfo *a_xInfoP;
840 { /*XDisplayVolumes*/
842 int totalOK; /*Total OK volumes*/
843 int totalNotOK; /*Total screwed volumes*/
844 int totalBusy; /*Total busy volumes*/
845 int i; /*Loop variable*/
846 afs_int32 volid; /*Current volume ID*/
849 * Initialize counters and (global!!) queues.
858 * Display each volume in the list.
860 for(i = 0; i < a_count; i++) {
861 XDisplayFormat(a_xInfoP,
874 * If any volumes were found to be busy or screwed, display them.
877 while (busyHead.count) {
878 qGet(&busyHead, &volid);
879 fprintf(STDOUT, "**** Volume %u is busy ****\n", volid);
883 while (notokHead.count) {
884 qGet(¬okHead, &volid);
885 fprintf(STDOUT, "**** Could not attach volume %u ****\n", volid);
890 fprintf(STDOUT, "\n");
893 "Total volumes: %d on-line, %d off-line, %d busyd\n\n",
894 totalOK, totalNotOK, totalBusy);
898 } /*XDisplayVolumes*/
900 /* set <server> and <part> to the correct values depending on
901 * <voltype> and <entry> */
902 static void GetServerAndPart (entry, voltype, server, part, previdx)
903 struct nvldbentry *entry;
904 afs_int32 *server,*part;
908 int i, istart, vtype;
913 /* Doesn't check for non-existance of backup volume */
914 if ((voltype == RWVOL) || (voltype == BACKVOL)) {
916 istart = 0; /* seach the entire entry */
919 /* Seach from beginning of entry or pick up where we left off */
920 istart = ((*previdx < 0) ? 0 : *previdx+1);
923 for (i = istart; i < entry->nServers; i++) {
924 if (entry->serverFlags[i] & vtype) {
925 *server = entry->serverNumber[i];
926 *part = entry->serverPartition[i];
932 /* Didn't find any, return -1 */
937 static void PostVolumeStats(entry)
938 struct nvldbentry *entry;
940 SubEnumerateEntry(entry);
941 /* Check for VLOP_ALLOPERS */
942 if (entry->flags & VLOP_ALLOPERS)
943 fprintf(STDOUT," Volume is currently LOCKED \n");
947 /*------------------------------------------------------------------------
948 * PRIVATE XVolumeStats
951 * Display extended volume information.
954 * a_xInfoP : Ptr to extended volume info.
955 * a_entryP : Ptr to the volume's VLDB entry.
956 * a_srvID : Server ID.
957 * a_partID : Partition ID.
958 * a_volType : Type of volume to print.
964 * Nothing interesting.
968 *------------------------------------------------------------------------*/
970 static void XVolumeStats(a_xInfoP, a_entryP, a_srvID, a_partID, a_volType)
971 volintXInfo *a_xInfoP;
972 struct nvldbentry *a_entryP;
979 int totalOK, totalNotOK, totalBusy; /*Dummies - we don't really count here*/
981 XDisplayFormat(a_xInfoP, /*Ptr to extended volume info*/
982 a_srvID, /*Server ID to print*/
983 a_partID, /*Partition ID to print*/
984 &totalOK, /*Ptr to total-OK counter*/
985 &totalNotOK, /*Ptr to total-screwed counter*/
986 &totalBusy, /*Ptr to total-busy counter*/
987 0, /*Don't do a fast listing*/
988 1, /*Do a long listing*/
989 1); /*Show volume problems*/
994 static void VolumeStats(pntr,entry,server,part,voltype)
996 struct nvldbentry *entry;
998 afs_int32 server,part;
1000 int totalOK,totalNotOK,totalBusy;
1001 afs_int32 vcode,vcode2;
1003 DisplayFormat(pntr,server,part,&totalOK,&totalNotOK,&totalBusy,0,1,1);
1007 /* command to forcibly remove a volume */
1008 static NukeVolume(as)
1009 register struct cmd_syndesc *as; {
1010 register afs_int32 code;
1011 afs_int32 volID, err;
1016 server = GetServer(tp = as->parms[0].items->data);
1018 fprintf(STDERR,"vos: server '%s' not found in host table\n", tp);
1022 partID = volutil_GetPartitionID(tp = as->parms[1].items->data);
1024 fprintf(STDERR, "vos: could not parse '%s' as a partition name", tp);
1028 volID = vsu_GetVolumeID(tp = as->parms[2].items->data, cstruct, &err);
1030 if (err) PrintError("", err);
1031 else fprintf(STDERR, "vos: could not parse '%s' as a numeric volume ID", tp);
1035 fprintf(STDOUT, "vos: forcibly removing all traces of volume %d, please wait...", volID);
1037 code = UV_NukeVolume(server, partID, volID);
1039 fprintf(STDOUT, "done.\n");
1041 fprintf(STDOUT, "failed with code %d.\n", code);
1046 /*------------------------------------------------------------------------
1047 * PRIVATE ExamineVolume
1050 * Routine used to examine a single volume, contacting the VLDB as
1051 * well as the Volume Server.
1054 * as : Ptr to parsed command line arguments.
1057 * 0 for a successful operation,
1058 * Otherwise, one of the ubik or VolServer error values.
1061 * Nothing interesting.
1065 *------------------------------------------------------------------------
1067 static ExamineVolume(as)
1068 register struct cmd_syndesc *as;
1070 struct nvldbentry entry;
1071 afs_int32 vcode = 0;
1072 volintInfo *pntr = (volintInfo *)0;
1073 volintXInfo *xInfoP = (volintXInfo *)0;
1075 afs_int32 code, err, error = 0;
1076 int voltype, foundserv = 0, foundentry = 0;
1077 afs_int32 aserver, apart;
1079 int wantExtendedInfo; /*Do we want extended vol info?*/
1081 wantExtendedInfo = (as->parms[1].items ? 1 : 0); /* -extended */
1083 volid = vsu_GetVolumeID(as->parms[0].items->data, cstruct, &err); /* -id */
1085 if (err) PrintError("", err);
1086 else fprintf(STDERR, "Unknown volume ID or name '%s'\n", as->parms[0].items->data);
1091 fprintf(STDOUT, "Fetching VLDB entry for %u .. ", volid);
1094 vcode = VLDB_GetEntryByID (volid, -1, &entry);
1096 fprintf(STDERR, "Could not fetch the entry for volume number %u from VLDB \n",volid);
1100 fprintf(STDOUT, "done\n");
1101 MapHostToNetwork(&entry);
1103 if (entry.volumeId[RWVOL] == volid)
1105 else if (entry.volumeId[BACKVOL] == volid)
1107 else /* (entry.volumeId[ROVOL] == volid) */
1110 do { /* do {...} while (voltype == ROVOL) */
1111 /* Get the entry for the volume. If its a RW vol, get the RW entry.
1112 * It its a BK vol, get the RW entry (even if VLDB may say the BK doen't exist).
1113 * If its a RO vol, get the next RO entry.
1115 GetServerAndPart(&entry, ((voltype == ROVOL) ? ROVOL : RWVOL), &aserver, &apart, &previdx);
1116 if (previdx == -1) { /* searched all entries */
1118 fprintf(STDERR,"Volume %s does not exist in VLDB\n\n", as->parms[0].items->data);
1125 /* Get information about the volume from the server */
1127 fprintf(STDOUT,"Getting volume listing from the server %s .. ",
1128 hostutil_GetNameByINet(aserver));
1131 if (wantExtendedInfo)
1132 code = UV_XListOneVolume(aserver, apart, volid, &xInfoP);
1134 code = UV_ListOneVolume(aserver, apart, volid, &pntr);
1136 fprintf(STDOUT,"done\n");
1140 if (code == ENODEV) {
1141 if ((voltype == BACKVOL) && !(entry.flags & BACK_EXISTS)) {
1142 /* The VLDB says there is no backup volume and its not on disk */
1143 fprintf(STDERR, "Volume %s does not exist\n", as->parms[0].items->data);
1146 fprintf(STDERR, "Volume does not exist on server %s as indicated by the VLDB\n",
1147 hostutil_GetNameByINet(aserver));
1150 PrintDiagnostics("examine", code);
1152 fprintf(STDOUT, "\n");
1155 if (wantExtendedInfo)
1156 XVolumeStats(xInfoP, &entry, aserver, apart, voltype);
1158 VolumeStats(pntr, &entry, aserver, apart, voltype);
1160 if ((voltype == BACKVOL) && !(entry.flags & BACK_EXISTS)) {
1161 /* The VLDB says there is no backup volume yet we found one on disk */
1162 fprintf(STDERR, "Volume %s does not exist in VLDB\n", as->parms[0].items->data);
1167 if (pntr) free(pntr);
1168 if (xInfoP) free(xInfoP);
1169 } while (voltype == ROVOL);
1172 fprintf(STDERR,"Dump only information from VLDB\n\n");
1173 fprintf(STDOUT,"%s \n", entry.name); /* PostVolumeStats doesn't print name */
1175 PostVolumeStats(&entry);
1180 /*------------------------------------------------------------------------
1184 * Brings a volume online.
1187 * as : Ptr to parsed command line arguments.
1190 * 0 for a successful operation,
1193 * Nothing interesting.
1197 *------------------------------------------------------------------------
1199 static volOnline(as)
1200 register struct cmd_syndesc *as;
1202 afs_int32 server, partition, volid;
1203 afs_int32 code, err=0;
1205 server = GetServer(as->parms[0].items->data);
1207 fprintf(STDERR,"vos: server '%s' not found in host table\n", as->parms[0].items->data);
1211 partition = volutil_GetPartitionID(as->parms[1].items->data);
1212 if (partition < 0) {
1213 fprintf(STDERR,"vos: could not interpret partition name '%s'\n", as->parms[1].items->data);
1217 volid = vsu_GetVolumeID(as->parms[2].items->data, cstruct, &err); /* -id */
1219 if (err) PrintError("", err);
1220 else fprintf(STDERR, "Unknown volume ID or name '%s'\n", as->parms[0].items->data);
1224 code = UV_SetVolume(server, partition, volid, ITOffline, 0/*online*/, 0/*sleep*/);
1226 fprintf(STDERR, "Failed to set volume. Code = %d\n", code);
1233 /*------------------------------------------------------------------------
1234 * PRIVATE volOffline
1237 * Brings a volume offline.
1240 * as : Ptr to parsed command line arguments.
1243 * 0 for a successful operation,
1246 * Nothing interesting.
1250 *------------------------------------------------------------------------
1252 static volOffline(as)
1253 register struct cmd_syndesc *as;
1255 afs_int32 server, partition, volid;
1256 afs_int32 code, err=0;
1257 afs_int32 transflag, sleeptime, transdone;
1259 server = GetServer(as->parms[0].items->data);
1261 fprintf(STDERR,"vos: server '%s' not found in host table\n", as->parms[0].items->data);
1265 partition = volutil_GetPartitionID(as->parms[1].items->data);
1266 if (partition < 0) {
1267 fprintf(STDERR,"vos: could not interpret partition name '%s'\n", as->parms[1].items->data);
1271 volid = vsu_GetVolumeID(as->parms[2].items->data, cstruct, &err); /* -id */
1273 if (err) PrintError("", err);
1274 else fprintf(STDERR, "Unknown volume ID or name '%s'\n", as->parms[0].items->data);
1278 transflag = (as->parms[4].items ? ITBusy : ITOffline);
1279 sleeptime = (as->parms[3].items ? atol(as->parms[3].items->data) : 0);
1280 transdone = (sleeptime ? 0/*online*/ : VTOutOfService);
1281 if (as->parms[4].items && !as->parms[3].items) {
1282 fprintf(STDERR,"-sleep option must be used with -busy flag\n");
1286 code = UV_SetVolume(server, partition, volid, transflag, transdone, sleeptime);
1288 fprintf(STDERR, "Failed to set volume. Code = %d\n", code);
1295 static CreateVolume(as)
1296 register struct cmd_syndesc *as;
1300 afs_int32 volid,code;
1301 struct nvldbentry entry;
1306 tserver = GetServer(as->parms[0].items->data);
1308 fprintf(STDERR,"vos: host '%s' not found in host table\n",as->parms[0].items->data );
1311 pname = volutil_GetPartitionID(as->parms[1].items->data);
1313 fprintf(STDERR,"vos: could not interpret partition name '%s'\n",as->parms[1].items->data );
1316 if (!IsPartValid(pname,tserver,&code)){/*check for validity of the partition */
1317 if(code) PrintError("",code);
1318 else fprintf(STDERR,"vos : partition %s does not exist on the server\n",as->parms[1].items->data);
1321 if(!ISNAMEVALID(as->parms[2].items->data)) {
1322 fprintf(STDERR,"vos: the name of the root volume %s exceeds the size limit of %d\n",as->parms[2].items->data,VOLSER_OLDMAXVOLNAME - 10);
1325 if(!VolNameOK(as->parms[2].items->data)){
1326 fprintf(STDERR,"Illegal volume name %s, should not end in .readonly or .backup\n",as->parms[2].items->data);
1329 if(IsNumeric(as->parms[2].items->data)){
1330 fprintf(STDERR,"Illegal volume name %s, should not be a number\n",as->parms[2].items->data);
1333 vcode = VLDB_GetEntryByName(as->parms[2].items->data, &entry);
1335 fprintf(STDERR,"Volume %s already exists\n",as->parms[2].items->data);
1336 PrintDiagnostics("create", code);
1340 if (as->parms[3].items) {
1341 if (!IsNumeric(as->parms[3].items->data)){
1342 fprintf(STDERR,"Initial quota %s should be numeric.\n", as->parms[3].items->data);
1346 code = util_GetInt32(as->parms[3].items->data, "a);
1348 fprintf(STDERR,"vos: bad integer specified for quota.\n");
1353 code = UV_CreateVolume2(tserver, pname,as->parms[2].items->data,
1354 quota, 0, 0, 0, 0, &volid);
1356 PrintDiagnostics("create", code);
1359 MapPartIdIntoName(pname, part);
1360 fprintf(STDOUT,"Volume %u created on partition %s of %s\n", volid, part,as->parms[0].items->data );
1365 static afs_int32 DeleteAll(entry)
1366 struct nvldbentry *entry;
1369 afs_int32 error, code, curserver, curpart, volid;
1371 MapHostToNetwork(entry);
1373 for(i=0; i < entry->nServers; i++){
1374 curserver = entry->serverNumber[i];
1375 curpart = entry->serverPartition[i];
1376 if(entry->serverFlags[i] & ITSROVOL){
1377 volid = entry->volumeId[ROVOL];
1380 volid = entry->volumeId[RWVOL];
1382 code = UV_DeleteVolume(curserver,curpart,volid);
1389 static DeleteVolume(as)
1390 struct cmd_syndesc *as;
1392 afs_int32 err, code = 0;
1393 afs_int32 server = 0, partition = -1, volid;
1397 if (as->parms[0].items) {
1398 server = GetServer(as->parms[0].items->data);
1400 fprintf(STDERR,"vos: server '%s' not found in host table\n",
1401 as->parms[0].items->data);
1406 if (as->parms[1].items) {
1407 partition = volutil_GetPartitionID(as->parms[1].items->data);
1408 if (partition < 0) {
1409 fprintf(STDERR,"vos: could not interpret partition name '%s'\n",
1410 as->parms[1].items->data );
1414 /* Check for validity of the partition */
1415 if (!IsPartValid(partition, server, &code)) {
1417 PrintError("", code);
1419 fprintf(STDERR,"vos : partition %s does not exist on the server\n",
1420 as->parms[1].items->data);
1426 volid = vsu_GetVolumeID(as->parms[2].items->data, cstruct, &err);
1428 fprintf(STDERR, "Can't find volume name '%s' in VLDB\n",
1429 as->parms[2].items->data);
1430 if (err) PrintError("", err);
1434 /* If the server or partition option are not complete, try to fill
1435 * them in from the VLDB entry.
1437 if ((partition == -1) || !server) {
1438 struct nvldbentry entry;
1440 code = VLDB_GetEntryByID(volid, -1, &entry);
1442 fprintf(STDERR,"Could not fetch the entry for volume %u from VLDB\n",
1444 PrintError("",code);
1448 if (((volid == entry.volumeId[RWVOL]) && (entry.flags & RW_EXISTS)) ||
1449 ((volid == entry.volumeId[BACKVOL]) && (entry.flags & BACK_EXISTS)) ) {
1450 idx = Lp_GetRwIndex(&entry);
1452 (server && (server != entry.serverNumber[idx])) ||
1453 ((partition != -1) && (partition != entry.serverPartition[idx])) ) {
1454 fprintf(STDERR,"VLDB: Volume '%s' no match\n", as->parms[2].items->data);
1458 else if ((volid == entry.volumeId[ROVOL]) && (entry.flags & RO_EXISTS)) {
1459 for (idx=-1,j=0; j<entry.nServers; j++) {
1460 if (entry.serverFlags[j] != ITSROVOL) continue;
1462 if ( ((server == 0) || (server == entry.serverNumber[j])) &&
1463 ((partition == -1) || (partition == entry.serverPartition[j])) ) {
1465 fprintf(STDERR,"VLDB: Volume '%s' matches more than one RO\n",
1466 as->parms[2].items->data);
1473 fprintf(STDERR,"VLDB: Volume '%s' no match\n", as->parms[2].items->data);
1478 fprintf(STDERR,"VLDB: Volume '%s' no match\n", as->parms[2].items->data);
1482 server = htonl(entry.serverNumber[idx]);
1483 partition = entry.serverPartition[idx];
1487 code = UV_DeleteVolume(server, partition, volid);
1489 PrintDiagnostics("remove", code);
1493 MapPartIdIntoName(partition, pname);
1494 fprintf(STDOUT,"Volume %u on partition %s server %s deleted\n",
1495 volid, pname, hostutil_GetNameByINet(server));
1499 #define TESTM 0 /* set for move space tests, clear for production */
1500 static MoveVolume(as)
1501 register struct cmd_syndesc *as;
1504 afs_int32 volid, fromserver, toserver, frompart, topart,code, err;
1505 char fromPartName[10], toPartName[10];
1507 struct diskPartition partition; /* for space check */
1510 volid = vsu_GetVolumeID(as->parms[0].items->data, cstruct, &err);
1512 if (err) PrintError("", err);
1513 else fprintf(STDERR, "vos: can't find volume ID or name '%s'\n",
1514 as->parms[0].items->data);
1517 fromserver = GetServer(as->parms[1].items->data);
1518 if (fromserver == 0) {
1519 fprintf(STDERR,"vos: server '%s' not found in host table\n", as->parms[1].items->data);
1522 toserver = GetServer(as->parms[3].items->data);
1523 if (toserver == 0) {
1524 fprintf(STDERR,"vos: server '%s' not found in host table\n", as->parms[3].items->data);
1527 frompart = volutil_GetPartitionID(as->parms[2].items->data);
1529 fprintf(STDERR,"vos: could not interpret partition name '%s'\n", as->parms[2].items->data);
1532 if (!IsPartValid(frompart,fromserver,&code)){/*check for validity of the partition */
1533 if(code) PrintError("",code);
1534 else fprintf(STDERR,"vos : partition %s does not exist on the server\n",as->parms[2].items->data);
1537 topart = volutil_GetPartitionID(as->parms[4].items->data);
1539 fprintf(STDERR,"vos: could not interpret partition name '%s'\n",as->parms[4].items->data);
1542 if (!IsPartValid(topart,toserver,&code)){/*check for validity of the partition */
1543 if(code) PrintError("",code);
1544 else fprintf(STDERR,"vos : partition %s does not exist on the server\n",as->parms[4].items->data);
1549 check source partition for space to clone volume
1552 MapPartIdIntoName(topart,toPartName);
1553 MapPartIdIntoName(frompart, fromPartName);
1556 check target partition for space to move volume
1559 code=UV_PartitionInfo(toserver,toPartName,&partition);
1562 fprintf(STDERR,"vos: cannot access partition %s\n",toPartName);
1566 fprintf(STDOUT,"target partition %s free space %d\n",
1567 toPartName,partition.free);
1570 code=UV_ListOneVolume(fromserver,frompart,volid,&p);
1573 fprintf(STDERR,"vos:cannot access volume %u\n",volid);
1578 fprintf(STDOUT,"volume %u size %d\n",volid,p->size);
1579 if(partition.free<=p->size)
1581 fprintf(STDERR,"vos: no space on target partition %s to move volume %u\n",
1590 fprintf(STDOUT,"size test - don't do move\n");
1594 /* successful move still not guaranteed but shoot for it */
1596 code = UV_MoveVolume(volid, fromserver, frompart, toserver, topart);
1598 PrintDiagnostics("move", code);
1601 MapPartIdIntoName(topart,toPartName);
1602 MapPartIdIntoName(frompart, fromPartName);
1603 fprintf(STDOUT,"Volume %u moved from %s %s to %s %s \n",volid,as->parms[1].items->data,fromPartName,as->parms[3].items->data,toPartName);
1607 static BackupVolume(as)
1608 register struct cmd_syndesc *as;
1610 afs_int32 avolid, aserver, apart,vtype,code, err;
1611 struct nvldbentry entry;
1613 afs_int32 buvolid,buserver,bupart,butype;
1614 struct nvldbentry buentry;
1615 struct rx_connection *conn;
1617 struct nvldbentry store;
1619 avolid = vsu_GetVolumeID(as->parms[0].items->data, cstruct, &err);
1621 if (err) PrintError("", err);
1622 else fprintf(STDERR, "vos: can't find volume ID or name '%s'\n",
1623 as->parms[0].items->data);
1626 code = GetVolumeInfo( avolid,&aserver, &apart,&vtype,&entry);
1629 /* verify this is a readwrite volume */
1633 fprintf(STDERR,"%s not RW volume\n",as->parms[0].items->data);
1637 /* is there a backup volume already? */
1639 if(entry.flags & BACK_EXISTS)
1641 /* yep, where is it? */
1643 buvolid=entry.volumeId[BACKVOL];
1644 code=GetVolumeInfo(buvolid,&buserver,&bupart,&butype,&buentry);
1648 code = VLDB_IsSameAddrs(buserver, aserver, &err);
1650 fprintf(STDERR,"Failed to get info about server's %d address(es) from vlserver; aborting call!\n", buserver);
1655 fprintf(STDERR,"FATAL ERROR: backup volume %u exists on server %u\n",
1661 /* nope, carry on */
1663 code = UV_BackupVolume(aserver, apart, avolid);
1666 PrintDiagnostics("backup", code);
1669 fprintf(STDOUT,"Created backup volume for %s \n",as->parms[0].items->data);
1672 static ReleaseVolume(as)
1673 register struct cmd_syndesc *as;
1676 struct nvldbentry entry;
1677 afs_int32 avolid, aserver, apart,vtype,code, err;
1680 if(as->parms[1].items) force = 1;
1681 avolid = vsu_GetVolumeID(as->parms[0].items->data, cstruct, &err);
1683 if (err) PrintError("", err);
1684 else fprintf(STDERR, "vos: can't find volume '%s'\n", as->parms[0].items->data);
1687 code = GetVolumeInfo( avolid,&aserver, &apart,&vtype,&entry);
1688 if(code) return code;
1690 if (vtype != RWVOL) {
1691 fprintf(STDERR,"%s not a RW volume\n", as->parms[0].items->data);
1695 if(!ISNAMEVALID(entry.name)){
1696 fprintf(STDERR,"Volume name %s is too long, rename before releasing\n",entry.name);
1700 code = UV_ReleaseVolume(avolid, aserver, apart, force);
1702 PrintDiagnostics("release", code);
1705 fprintf(STDOUT,"Released volume %s successfully\n",as->parms[0].items->data );
1708 static DumpVolume(as)
1709 register struct cmd_syndesc *as;
1712 afs_int32 avolid, aserver, apart,voltype,fromdate=0,code, err, i;
1713 char filename[NameLen];
1714 struct nvldbentry entry;
1716 rx_SetRxDeadTime(60 * 10);
1717 for (i = 0; i<MAXSERVERS; i++) {
1718 struct rx_connection *rxConn = ubik_GetRPCConn(cstruct,i);
1719 if (rxConn == 0) break;
1720 rx_SetConnDeadTime(rxConn, rx_connDeadTime);
1721 if (rxConn->service) rxConn->service->connDeadTime = rx_connDeadTime;
1724 avolid = vsu_GetVolumeID(as->parms[0].items->data, cstruct, &err);
1726 if (err) PrintError("", err);
1727 else fprintf(STDERR, "vos: can't find volume '%s'\n", as->parms[0].items->data);
1731 if (as->parms[3].items || as->parms[4].items) {
1732 if (!as->parms[3].items || !as->parms[4].items) {
1733 fprintf(STDERR, "Must specify both -server and -partition options\n");
1736 aserver = GetServer(as->parms[3].items->data);
1738 fprintf(STDERR, "Invalid server name\n");
1741 apart = volutil_GetPartitionID(as->parms[4].items->data);
1743 fprintf(STDERR, "Invalid partition name\n");
1747 code = GetVolumeInfo(avolid, &aserver, &apart, &voltype, &entry);
1748 if (code) return code;
1751 if (as->parms[1].items && strcmp(as->parms[1].items->data,"0")) {
1752 code = ktime_DateToInt32(as->parms[1].items->data, &fromdate);
1754 fprintf(STDERR,"vos: failed to parse date '%s' (error=%d))\n",
1755 as->parms[1].items->data, code);
1759 if(as->parms[2].items){
1760 strcpy(filename,as->parms[2].items->data);
1763 strcpy(filename,"");
1765 code = UV_DumpVolume(avolid, aserver, apart, fromdate, DumpFunction, filename);
1767 PrintDiagnostics("dump", code);
1770 if(strcmp(filename,""))
1771 fprintf(STDERR,"Dumped volume %s in file %s\n",as->parms[0].items->data, filename);
1773 fprintf(STDERR,"Dumped volume %s in stdout \n",as->parms[0].items->data);
1782 static RestoreVolume(as)
1783 register struct cmd_syndesc *as;
1786 afs_int32 avolid, aserver, apart, code,vcode, err;
1787 afs_int32 aoverwrite = ASK;
1790 char afilename[NameLen], avolname[VOLSER_MAXVOLNAME +1],apartName[10];
1791 char volname[VOLSER_MAXVOLNAME +1];
1792 struct nvldbentry entry;
1796 if(as->parms[4].items){
1797 avolid = vsu_GetVolumeID(as->parms[4].items->data, cstruct, &err);
1799 if (err) PrintError("", err);
1800 else fprintf(STDERR, "vos: can't find volume '%s'\n", as->parms[4].items->data);
1807 if (as->parms[5].items) {
1808 if ( (strcmp(as->parms[5].items->data, "a") == 0) ||
1809 (strcmp(as->parms[5].items->data, "abort") == 0) ) {
1812 else if ( (strcmp(as->parms[5].items->data, "f") == 0) ||
1813 (strcmp(as->parms[5].items->data, "full") == 0) ) {
1816 else if ( (strcmp(as->parms[5].items->data, "i") == 0) ||
1817 (strcmp(as->parms[5].items->data, "inc") == 0) ||
1818 (strcmp(as->parms[5].items->data, "increment") == 0) ||
1819 (strcmp(as->parms[5].items->data, "incremental") == 0) ) {
1823 fprintf(STDERR, "vos: %s is not a valid argument to -overwrite\n",
1824 as->parms[5].items->data);
1829 aserver = GetServer(as->parms[0].items->data);
1831 fprintf(STDERR,"vos: server '%s' not found in host table\n", as->parms[0].items->data);
1834 apart = volutil_GetPartitionID(as->parms[1].items->data);
1836 fprintf(STDERR,"vos: could not interpret partition name '%s'\n",as->parms[1].items->data );
1839 if (!IsPartValid(apart,aserver,&code)){/*check for validity of the partition */
1840 if(code) PrintError("",code);
1841 else fprintf(STDERR,"vos : partition %s does not exist on the server\n",as->parms[1].items->data);
1844 strcpy(avolname,as->parms[2].items->data );
1845 if(!ISNAMEVALID(avolname)) {
1846 fprintf(STDERR,"vos: the name of the volume %s exceeds the size limit\n",avolname);
1849 if(!VolNameOK(avolname)){
1850 fprintf(STDERR,"Illegal volume name %s, should not end in .readonly or .backup\n",avolname);
1853 if(as->parms[3].items){
1854 strcpy(afilename,as->parms[3].items->data );
1855 if(!FileExists(afilename)){
1856 fprintf(STDERR,"Can't access file %s\n",afilename);
1861 strcpy(afilename,"");
1864 /* Check if volume exists or not */
1866 vsu_ExtractName(volname,avolname);
1867 vcode = VLDB_GetEntryByName(volname, &entry);
1868 if (vcode) { /* no volume - do a full restore */
1869 restoreflags = RV_FULLRST;
1870 if ( (aoverwrite == INC) || (aoverwrite == ABORT) )
1871 fprintf(STDERR,"Volume does not exist; Will perform a full restore\n");
1874 else if (Lp_GetRwIndex(&entry) == -1) { /* RW volume does not exist - do a full */
1875 restoreflags = RV_FULLRST;
1876 if ( (aoverwrite == INC) || (aoverwrite == ABORT) )
1877 fprintf(STDERR,"RW Volume does not exist; Will perform a full restore\n");
1880 avolid = entry.volumeId[RWVOL];
1882 else if (entry.volumeId[RWVOL] != 0 && entry.volumeId[RWVOL] != avolid) {
1883 avolid = entry.volumeId[RWVOL];
1887 else { /* volume exists - do we do a full incremental or abort */
1888 int Oserver, Opart, Otype, vol_elsewhere = 0;
1889 struct nvldbentry Oentry;
1893 avolid = entry.volumeId[RWVOL];
1895 else if(entry.volumeId[RWVOL] != 0 && entry.volumeId[RWVOL] != avolid) {
1896 avolid = entry.volumeId[RWVOL];
1899 /* A file name was specified - check if volume is on another partition */
1900 vcode = GetVolumeInfo(avolid, &Oserver, &Opart, &Otype, &Oentry);
1903 vcode = VLDB_IsSameAddrs(Oserver, aserver, &err);
1905 fprintf(STDERR,"Failed to get info about server's %d address(es) from vlserver (err=%d); aborting call!\n",
1909 if (!vcode || (Opart != apart)) vol_elsewhere = 1;
1911 if (aoverwrite == ASK) {
1912 if (strcmp(afilename,"") == 0) { /* The file is from standard in */
1913 fprintf(STDERR,"Volume exists and no -overwrite option specified; Aborting restore command\n");
1917 /* Ask what to do */
1918 if (vol_elsewhere) {
1919 fprintf(STDERR,"The volume %s %u already exists on a different server/part\n",
1920 volname, entry.volumeId[RWVOL]);
1922 "Do you want to do a full restore or abort? [fa](a): ");
1926 fprintf(STDERR,"The volume %s %u already exists in the VLDB\n",
1927 volname, entry.volumeId[RWVOL]);
1929 "Do you want to do a full/incremental restore or abort? [fia](a): ");
1932 while (!(dc==EOF || dc=='\n')) dc=getchar(); /* goto end of line */
1933 if ((c == 'f') || (c == 'F')) aoverwrite = FULL;
1934 else if ((c == 'i') || (c == 'I')) aoverwrite = INC;
1935 else aoverwrite = ABORT;
1938 if (aoverwrite == ABORT) {
1939 fprintf(STDERR,"Volume exists; Aborting restore command\n");
1942 else if (aoverwrite == FULL) {
1943 restoreflags = RV_FULLRST;
1944 fprintf(STDERR,"Volume exists; Will delete and perform full restore\n");
1946 else if (aoverwrite == INC) {
1948 if (vol_elsewhere) {
1950 "RW volume %u already exists on a different server/part; not allowed\n",
1956 code = UV_RestoreVolume(aserver, apart, avolid, avolname,
1957 restoreflags, WriteData, afilename);
1959 PrintDiagnostics("restore", code);
1962 MapPartIdIntoName(apart,apartName);
1965 patch typo here - originally "parms[1]", should be "parms[0]"
1968 fprintf(STDOUT,"Restored volume %s on %s %s\n",
1969 avolname, as->parms[0].items->data, apartName);
1972 static LockReleaseCmd(as)
1973 register struct cmd_syndesc *as;
1976 afs_int32 avolid,code, err;
1978 avolid = vsu_GetVolumeID(as->parms[0].items->data, cstruct, &err);
1980 if (err) PrintError("", err);
1981 else fprintf(STDERR, "vos: can't find volume '%s'\n", as->parms[0].items->data);
1985 code = UV_LockRelease(avolid);
1987 PrintDiagnostics("unlock", code);
1990 fprintf(STDOUT,"Released lock on vldb entry for volume %s\n",as->parms[0].items->data);
1994 register struct cmd_syndesc *as;
1996 afs_int32 avolid, aserver, apart,code, err;
1999 avolid = vsu_GetVolumeID(as->parms[2].items->data, cstruct, &err);
2001 if (err) PrintError("", err);
2002 else fprintf(STDERR, "vos: can't find volume '%s'\n", as->parms[2].items->data);
2005 aserver = GetServer(as->parms[0].items->data);
2007 fprintf(STDERR,"vos: server '%s' not found in host table\n", as->parms[0].items->data);
2010 apart = volutil_GetPartitionID(as->parms[1].items->data);
2012 fprintf(STDERR,"vos: could not interpret partition name '%s'\n",as->parms[1].items->data );
2015 if (!IsPartValid(apart,aserver,&code)){/*check for validity of the partition */
2016 if(code) PrintError("",code);
2017 else fprintf(STDERR,"vos : partition %s does not exist on the server\n",as->parms[1].items->data);
2020 code = UV_AddSite(aserver, apart, avolid);
2022 PrintDiagnostics("addsite", code);
2025 MapPartIdIntoName(apart,apartName);
2026 fprintf(STDOUT,"Added replication site %s %s for volume %s\n",as->parms[0].items->data, apartName,as->parms[2].items->data);
2030 static RemoveSite(as)
2031 register struct cmd_syndesc *as;
2034 afs_int32 avolid, aserver, apart, code, err;
2037 avolid = vsu_GetVolumeID(as->parms[2].items->data, cstruct, &err);
2039 if (err) PrintError("", err);
2040 else fprintf(STDERR, "vos: can't find volume '%s'\n", as->parms[2].items->data);
2043 aserver = GetServer(as->parms[0].items->data);
2045 fprintf(STDERR,"vos: server '%s' not found in host table\n", as->parms[0].items->data);
2048 apart = volutil_GetPartitionID(as->parms[1].items->data);
2050 fprintf(STDERR,"vos: could not interpret partition name '%s'\n",as->parms[1].items->data );
2054 *skip the partition validity check, since it is possible that the partition
2055 *has since been decomissioned.
2058 if (!IsPartValid(apart,aserver,&code)){
2059 if(code) PrintError("",code);
2060 else fprintf(STDERR,"vos : partition %s does not exist on the server\n",as->parms[1].items->data);
2064 code = UV_RemoveSite(aserver, apart, avolid);
2066 PrintDiagnostics("remsite", code);
2069 MapPartIdIntoName(apart,apartName);
2070 fprintf(STDOUT,"Removed replication site %s %s for volume %s\n",as->parms[0].items->data,apartName,as->parms[2].items->data);
2074 static ListPartitions(as)
2075 register struct cmd_syndesc *as;
2077 afs_int32 aserver,code;
2078 struct partList dummyPartList;
2083 aserver = GetServer(as->parms[0].items->data);
2085 fprintf(STDERR,"vos: server '%s' not found in host table\n", as->parms[0].items->data);
2090 code = UV_ListPartitions(aserver,&dummyPartList, &cnt);
2092 PrintDiagnostics("listpart", code);
2096 fprintf(STDOUT,"The partitions on the server are:\n");
2097 for(i = 0 ; i < cnt ; i++){
2098 if(dummyPartList.partFlags[i] & PARTVALID){
2099 bzero(pname,sizeof(pname));
2100 MapPartIdIntoName(dummyPartList.partId[i],pname);
2101 fprintf(STDOUT," %10s ",pname);
2103 if( (i % 5) == 0 && (i != 0)) fprintf(STDOUT,"\n");
2106 fprintf(STDOUT,"\n");
2107 fprintf(STDOUT,"Total: %d\n",total);
2112 static int CompareVolName(p1,p2)
2115 volintInfo *arg1,*arg2;
2117 arg1 = (volintInfo *)p1;
2118 arg2 = (volintInfo *)p2;
2119 return(strcmp(arg1->name,arg2->name));
2123 /*------------------------------------------------------------------------
2124 * PRIVATE XCompareVolName
2127 * Comparison routine for volume names coming from an extended
2131 * a_obj1P : Char ptr to first extended vol info object
2132 * a_obj1P : Char ptr to second extended vol info object
2135 * The value of strcmp() on the volume names within the passed
2136 * objects (i,e., -1, 0, or 1).
2139 * Passed to qsort() as the designated comparison routine.
2143 *------------------------------------------------------------------------*/
2145 static int XCompareVolName(a_obj1P, a_obj2P)
2146 char *a_obj1P, *a_obj2P;
2148 { /*XCompareVolName*/
2150 return(strcmp(((struct volintXInfo *)(a_obj1P))->name,
2151 ((struct volintXInfo *)(a_obj2P))->name));
2153 } /*XCompareVolName*/
2155 static int CompareVolID(p1,p2)
2158 volintInfo *arg1,*arg2;
2160 arg1 = (volintInfo *)p1;
2161 arg2 = (volintInfo *)p2;
2162 if(arg1->volid == arg2->volid) return 0;
2163 if(arg1->volid > arg2->volid) return 1;
2168 /*------------------------------------------------------------------------
2169 * PRIVATE XCompareVolID
2172 * Comparison routine for volume IDs coming from an extended
2176 * a_obj1P : Char ptr to first extended vol info object
2177 * a_obj1P : Char ptr to second extended vol info object
2180 * The value of strcmp() on the volume names within the passed
2181 * objects (i,e., -1, 0, or 1).
2184 * Passed to qsort() as the designated comparison routine.
2188 *------------------------------------------------------------------------*/
2190 static int XCompareVolID(a_obj1P, a_obj2P)
2191 char *a_obj1P, *a_obj2P;
2195 afs_int32 id1, id2; /*Volume IDs we're comparing*/
2197 id1 = ((struct volintXInfo *)(a_obj1P))->volid;
2198 id2 = ((struct volintXInfo *)(a_obj2P))->volid;
2209 /*------------------------------------------------------------------------
2210 * PRIVATE ListVolumes
2213 * Routine used to list volumes, contacting the Volume Server
2214 * directly, bypassing the VLDB.
2217 * as : Ptr to parsed command line arguments.
2220 * 0 Successful operation
2223 * Nothing interesting.
2227 *------------------------------------------------------------------------*/
2229 static ListVolumes(as)
2230 register struct cmd_syndesc *as;
2232 afs_int32 apart,int32list,fast;
2233 afs_int32 aserver,code;
2234 volintInfo *pntr,*oldpntr;
2238 volintXInfo *xInfoP, *origxInfoP; /*Ptr to current/orig extended vol info*/
2239 int wantExtendedInfo; /*Do we want extended vol info?*/
2242 struct partList dummyPartList;
2250 if(as->parms[3].items) int32list = 1;
2251 if(as->parms[4].items) quiet = 1;
2253 if(as->parms[2].items) fast = 1;
2256 if (as->parms[5].items) {
2258 * We can't coexist with the fast flag.
2262 "vos: Can't use the -fast and -extended flags together\n");
2267 * We need to turn on ``long'' listings to get the full effect.
2269 wantExtendedInfo = 1;
2273 wantExtendedInfo = 0;
2274 if(as->parms[1].items){
2275 apart = volutil_GetPartitionID(as->parms[1].items->data);
2277 fprintf(STDERR,"vos: could not interpret partition name '%s'\n", as->parms[1].items->data);
2280 dummyPartList.partId[0] = apart;
2281 dummyPartList.partFlags[0] = PARTVALID;
2284 aserver = GetServer(as->parms[0].items->data);
2286 fprintf(STDERR,"vos: server '%s' not found in host table\n",as->parms[0].items->data );
2291 if (!IsPartValid(apart,aserver,&code)){/*check for validity of the partition */
2292 if(code) PrintError("",code);
2293 else fprintf(STDERR,"vos : partition %s does not exist on the server\n",as->parms[1].items->data);
2298 code = UV_ListPartitions(aserver,&dummyPartList, &cnt);
2300 PrintDiagnostics("listvol", code);
2304 for(i = 0 ; i < cnt ; i++){
2305 if(dummyPartList.partFlags[i] & PARTVALID){
2306 if (wantExtendedInfo)
2307 code = UV_XListVolumes(aserver,
2308 dummyPartList.partId[i],
2313 code = UV_ListVolumes(aserver,
2314 dummyPartList.partId[i],
2319 PrintDiagnostics("listvol", code);
2320 if(pntr) free(pntr);
2323 if (wantExtendedInfo) {
2324 origxInfoP = xInfoP;
2325 base = (char *)xInfoP;
2328 base = (char *)pntr;
2332 if (wantExtendedInfo)
2333 qsort(base, count, sizeof(volintXInfo), XCompareVolName);
2335 qsort(base, count, sizeof(volintInfo), CompareVolName);
2337 if (wantExtendedInfo)
2338 qsort(base, count, sizeof(volintXInfo), XCompareVolID);
2340 qsort(base, count, sizeof(volintInfo), CompareVolID);
2342 MapPartIdIntoName(dummyPartList.partId[i],pname);
2344 fprintf(STDOUT,"Total number of volumes on server %s partition %s: %u \n",as->parms[0].items->data,pname,count);
2345 if (wantExtendedInfo) {
2346 XDisplayVolumes(aserver,
2347 dummyPartList.partId[i],
2355 xInfoP = (volintXInfo *)0;
2358 DisplayVolumes(aserver,
2359 dummyPartList.partId[i],
2367 pntr = (volintInfo *)0;
2375 register struct cmd_syndesc *as;
2377 afs_int32 pname, code; /* part name */
2383 if (as->parms[0].items) {
2384 tserver = GetServer(as->parms[0].items->data);
2386 fprintf(STDERR,"vos: host '%s' not found in host table\n",as->parms[0].items->data );
2391 if (as->parms[1].items) {
2392 pname = volutil_GetPartitionID(as->parms[1].items->data);
2394 fprintf(STDERR,"vos: could not interpret partition name '%s'\n",as->parms[1].items->data );
2397 if (!IsPartValid(pname,tserver,&code)) { /*check for validity of the partition */
2398 if(code) PrintError("",code);
2399 else fprintf(STDERR,"vos: partition %s does not exist on the server\n",
2400 as->parms[1].items->data);
2406 fprintf(STDERR,"The -partition option requires a -server option\n");
2411 if (as->parms[2].items) {
2412 /* Synchronize an individual volume */
2413 volname = as->parms[2].items->data;
2414 code = UV_SyncVolume(tserver, pname, volname, flags);
2417 fprintf(STDERR,"Without a -volume option, the -server option is required\n");
2420 code = UV_SyncVldb(tserver, pname, flags, 0/*unused*/);
2424 PrintDiagnostics("syncvldb", code);
2428 /* Print a summary of what we did */
2429 if (volname) fprintf(STDOUT,"VLDB volume %s synchronized", volname);
2430 else fprintf(STDOUT,"VLDB synchronized");
2432 fprintf(STDOUT," with state of server %s", as->parms[0].items->data);
2435 MapPartIdIntoName(pname,part);
2436 fprintf(STDOUT," partition %s\n", part);
2438 fprintf(STDOUT, "\n");
2443 static SyncServer(as)
2444 register struct cmd_syndesc *as;
2447 afs_int32 pname,code; /* part name */
2452 tserver = GetServer(as->parms[0].items->data);
2454 fprintf(STDERR,"vos: host '%s' not found in host table\n",as->parms[0].items->data );
2457 if(as->parms[1].items){
2458 pname = volutil_GetPartitionID(as->parms[1].items->data);
2460 fprintf(STDERR,"vos: could not interpret partition name '%s'\n",as->parms[1].items->data);
2463 if (!IsPartValid(pname,tserver,&code)){/*check for validity of the partition */
2464 if(code) PrintError("",code);
2465 else fprintf(STDERR,"vos : partition %s does not exist on the server\n",as->parms[1].items->data);
2471 code = UV_SyncServer(tserver, pname, flags, 0/*unused*/);
2473 PrintDiagnostics("syncserv", code);
2477 MapPartIdIntoName(pname,part);
2478 fprintf(STDOUT,"Server %s partition %s synchronized with VLDB\n",as->parms[0].items->data,part);
2480 else fprintf(STDOUT,"Server %s synchronized with VLDB\n",as->parms[0].items->data);
2485 static VolumeInfoCmd(name)
2488 struct nvldbentry entry;
2491 /* The vlserver will handle names with the .readonly
2492 * and .backup extension as well as volume ids.
2494 vcode = VLDB_GetEntryByName(name, &entry);
2496 PrintError("", vcode);
2499 MapHostToNetwork(&entry);
2500 EnumerateEntry(&entry);
2502 /* Defect #3027: grubby check to handle locked volume.
2503 * If VLOP_ALLOPERS is set, the entry is locked.
2504 * Leave this routine as is, but put in correct check.
2506 if (entry.flags & VLOP_ALLOPERS)
2507 fprintf(STDOUT," Volume is currently LOCKED \n");
2512 static VolumeZap(as)
2513 register struct cmd_syndesc *as;
2516 struct nvldbentry entry;
2517 afs_int32 volid,code,server,part, zapbackupid=0, backupid=0, err;
2519 if (as->parms[3].items) {
2520 /* force flag is on, use the other version */
2521 return NukeVolume(as);
2524 if (as->parms[4].items) {
2528 volid = vsu_GetVolumeID(as->parms[2].items->data, cstruct, &err);
2530 if (err) PrintError("", err);
2531 else fprintf(STDERR, "vos: can't find volume '%s'\n", as->parms[2].items->data);
2534 part = volutil_GetPartitionID(as->parms[1].items->data);
2536 fprintf(STDERR,"vos: could not interpret partition name '%s'\n",as->parms[1].items->data );
2539 server = GetServer(as->parms[0].items->data);
2541 fprintf(STDERR,"vos: host '%s' not found in host table\n",as->parms[0].items->data );
2544 if (!IsPartValid(part,server,&code)){/*check for validity of the partition */
2545 if(code) PrintError("",code);
2546 else fprintf(STDERR,"vos : partition %s does not exist on the server\n",as->parms[1].items->data);
2549 code = VLDB_GetEntryByID(volid,-1, &entry);
2551 if (volid == entry.volumeId[RWVOL])
2552 backupid = entry.volumeId[BACKVOL];
2553 fprintf(STDERR,"Warning: Entry for volume number %u exists in VLDB (but we're zapping it anyway!)\n",
2557 volintInfo *pntr = (volintInfo *)0;
2560 code = UV_ListOneVolume(server, part, volid, &pntr);
2562 if (volid == pntr->parentID)
2563 backupid = pntr->backupID;
2564 if (pntr) free(pntr);
2568 code = UV_VolumeZap(server,part, backupid);
2570 PrintDiagnostics("zap", code);
2573 fprintf(STDOUT,"Backup Volume %u deleted\n", backupid);
2576 code = UV_VolumeZap(server,part,volid);
2578 PrintDiagnostics("zap", code);
2581 fprintf(STDOUT,"Volume %u deleted\n",volid);
2586 static VolserStatus(as)
2587 register struct cmd_syndesc *as;
2590 afs_int32 server, code;
2591 transDebugInfo *pntr,*oldpntr;
2596 server = GetServer(as->parms[0].items->data);
2598 fprintf(STDERR,"vos: host '%s' not found in host table\n",as->parms[0].items->data );
2601 code = UV_VolserStatus(server,&pntr,&count);
2603 PrintDiagnostics("status",code);
2608 fprintf(STDOUT,"No active transactions on %s\n",as->parms[0].items->data);
2610 fprintf(STDOUT,"Total transactions: %d\n",count);
2612 for(i = 0; i < count ; i++){
2613 /*print out the relevant info */
2614 fprintf(STDOUT,"--------------------------------------\n");
2615 fprintf(STDOUT,"transaction: %u created: %s",pntr->tid,
2616 ctime((time_t *)&pntr->time));
2617 if(pntr->returnCode){
2618 fprintf(STDOUT,"returnCode: %u\n",pntr->returnCode);
2621 fprintf(STDOUT,"attachFlags: ");
2622 switch(pntr->iflags){
2623 case ITOffline: fprintf(STDOUT,"offline ");
2625 case ITBusy: fprintf(STDOUT,"busy ");
2627 case ITReadOnly: fprintf(STDOUT,"readonly ");
2629 case ITCreate: fprintf(STDOUT,"create ");
2631 case ITCreateVolID: fprintf(STDOUT,"create volid ");
2634 fprintf(STDOUT,"\n");
2637 fprintf(STDOUT,"volumeStatus: ");
2638 switch(pntr->vflags){
2639 case VTDeleteOnSalvage: fprintf(STDOUT,"deleteOnSalvage ");
2640 case VTOutOfService: fprintf(STDOUT,"outOfService ");
2641 case VTDeleted: fprintf(STDOUT,"deleted ");
2643 fprintf(STDOUT,"\n");
2646 fprintf(STDOUT,"transactionFlags: ");
2647 fprintf(STDOUT,"delete\n");
2649 MapPartIdIntoName(pntr->partition ,pname);
2650 fprintf(STDOUT,"volume: %u partition: %s procedure: %s\n",pntr->volid,pname, pntr->lastProcName);
2651 if(pntr->callValid){
2652 fprintf(STDOUT,"packetRead: %u lastReceiveTime: %d packetSend: %u lastSendTime: %d\n",pntr->readNext,pntr->lastReceiveTime,pntr->transmitNext, pntr->lastSendTime);
2655 fprintf(STDOUT,"--------------------------------------\n");
2656 fprintf(STDOUT,"\n");
2658 if(oldpntr) free(oldpntr);
2662 static RenameVolume(as)
2663 register struct cmd_syndesc *as;
2665 afs_int32 code1,code2,code;
2666 struct nvldbentry entry;
2668 code1 = VLDB_GetEntryByName(as->parms[0].items->data, &entry);
2670 fprintf(STDERR,"vos: Could not find entry for volume %s\n",as->parms[0].items->data);
2673 code2 = VLDB_GetEntryByName(as->parms[1].items->data, &entry);
2674 if((!code1) && (!code2)) { /*the newname already exists */
2675 fprintf(STDERR,"vos: volume %s already exists\n",as->parms[1].items->data);
2680 fprintf(STDERR,"vos: Could not find entry for volume %s or %s\n",as->parms[0].items->data,as->parms[1].items->data);
2683 if(!VolNameOK(as->parms[0].items->data)){
2684 fprintf(STDERR,"Illegal volume name %s, should not end in .readonly or .backup\n",as->parms[0].items->data);
2687 if(!ISNAMEVALID(as->parms[1].items->data)) {
2688 fprintf(STDERR,"vos: the new volume name %s exceeds the size limit of %d\n",as->parms[1].items->data,VOLSER_OLDMAXVOLNAME - 10);
2691 if(!VolNameOK(as->parms[1].items->data)){
2692 fprintf(STDERR,"Illegal volume name %s, should not end in .readonly or .backup\n",as->parms[1].items->data);
2695 if(IsNumeric(as->parms[1].items->data)){
2696 fprintf(STDERR,"Illegal volume name %s, should not be a number\n",as->parms[1].items->data);
2699 MapHostToNetwork(&entry);
2700 code = UV_RenameVolume(&entry,as->parms[0].items->data,as->parms[1].items->data);
2702 PrintDiagnostics("rename", code);
2705 fprintf(STDOUT,"Renamed volume %s to %s\n",as->parms[0].items->data,as->parms[1].items->data);
2709 GetVolumeInfo(volid, server, part, voltype,rentry)
2710 afs_int32 *server, volid, *part, *voltype;
2711 register struct nvldbentry *rentry;
2716 vcode = VLDB_GetEntryByID(volid, -1, rentry);
2718 fprintf(STDERR,"Could not fetch the entry for volume %u from VLDB \n",volid);
2719 PrintError("",vcode);
2722 MapHostToNetwork(rentry);
2723 if(volid == rentry->volumeId[ROVOL]){
2725 for (i = 0; i < rentry->nServers; i++) {
2726 if ( (index == -1) && (rentry->serverFlags[i] & ITSROVOL) &&
2727 !(rentry->serverFlags[i] & RO_DONTUSE) )
2731 fprintf(STDERR,"RO volume is not found in VLDB entry for volume %u\n", volid);
2735 *server = rentry->serverNumber[index];
2736 *part = rentry->serverPartition[index];
2740 index = Lp_GetRwIndex(rentry);
2742 fprintf(STDERR,"RW Volume is not found in VLDB entry for volume %u\n", volid);
2745 if(volid == rentry->volumeId[RWVOL]){
2747 *server = rentry->serverNumber[index];
2748 *part = rentry->serverPartition[index];
2751 if(volid == rentry->volumeId[BACKVOL]){
2753 *server = rentry->serverNumber[index];
2754 *part = rentry->serverPartition[index];
2759 static DeleteEntry(as)
2760 register struct cmd_syndesc *as;
2766 struct VldbListByAttributes attributes;
2767 nbulkentries arrayEntries;
2768 register struct nvldbentry *vllist;
2769 struct cmd_item *itp;
2772 char prefix[VOLSER_MAXVOLNAME+1];
2774 afs_int32 totalBack=0, totalFail=0, err;
2776 if (as->parms[0].items) { /* -id */
2777 if (as->parms[1].items || as->parms[2].items || as->parms[3].items) {
2778 fprintf(STDERR,"You cannot use -server, -partition, or -prefix with the -id argument\n");
2781 for (itp=as->parms[0].items; itp; itp=itp->next) {
2782 avolid = vsu_GetVolumeID(itp->data, cstruct, &err);
2784 if (err) PrintError("", err);
2785 else fprintf(STDERR, "vos: can't find volume '%s'\n", itp->data);
2788 if (as->parms[4].items) { /* -noexecute */
2789 fprintf(STDOUT,"Would have deleted VLDB entry for %s \n", itp->data);
2793 vcode = ubik_Call(VL_DeleteEntry,cstruct, 0, avolid, RWVOL);
2795 fprintf(STDERR,"Could not delete entry for volume %s\n", itp->data);
2796 fprintf(STDERR,"You must specify a RW volume name or ID "
2797 "(the entire VLDB entry will be deleted)\n", itp->data);
2798 PrintError("",vcode);
2804 fprintf(STDOUT,"Deleted %d VLDB entries\n", totalBack);
2808 if (!as->parms[1].items && !as->parms[2].items && !as->parms[3].items) {
2809 fprintf(STDERR,"You must specify an option\n");
2813 /* Zero out search attributes */
2814 bzero(&attributes,sizeof(struct VldbListByAttributes));
2816 if (as->parms[1].items) { /* -prefix */
2817 strncpy(prefix, as->parms[1].items->data, VOLSER_MAXVOLNAME);
2819 if (!as->parms[2].items && !as->parms[3].items) { /* a single entry only */
2820 fprintf(STDERR,"You must provide -server with the -prefix argument\n");
2825 if (as->parms[2].items) { /* -server */
2827 aserver = GetServer(as->parms[2].items->data);
2829 fprintf(STDERR,"vos: server '%s' not found in host table\n",as->parms[2].items->data );
2832 attributes.server = ntohl(aserver);
2833 attributes.Mask |= VLLIST_SERVER;
2836 if (as->parms[3].items) { /* -partition */
2837 if (!as->parms[2].items) {
2838 fprintf(STDERR,"You must provide -server with the -partition argument\n");
2841 apart = volutil_GetPartitionID(as->parms[3].items->data);
2843 fprintf(STDERR,"vos: could not interpret partition name '%s'\n",
2844 as->parms[3].items->data);
2847 attributes.partition = apart;
2848 attributes.Mask |= VLLIST_PARTITION;
2851 /* Print status line of what we are doing */
2852 fprintf(STDOUT,"Deleting VLDB entries for ");
2853 if (as->parms[2].items) {
2854 fprintf(STDOUT,"server %s ", as->parms[2].items->data);
2856 if (as->parms[3].items) {
2858 MapPartIdIntoName(apart, pname);
2859 fprintf(STDOUT,"partition %s ", pname);
2862 fprintf(STDOUT,"which are prefixed with %s ", prefix);
2864 fprintf(STDOUT,"\n");
2867 /* Get all the VLDB entries on a server and/or partition */
2868 bzero(&arrayEntries, sizeof(arrayEntries));
2869 vcode = VLDB_ListAttributes(&attributes, &nentries, &arrayEntries);
2871 fprintf(STDERR,"Could not access the VLDB for attributes\n");
2872 PrintError("",vcode);
2876 /* Process each entry */
2877 for (j=0; j<nentries; j++) {
2878 vllist = &arrayEntries.nbulkentries_val[j];
2880 /* It only deletes the RW volumes */
2881 if (strncmp(vllist->name, prefix, strlen(prefix))){
2883 fprintf(STDOUT,"Omitting to delete %s due to prefix %s mismatch\n",
2884 vllist->name, prefix);
2891 if (as->parms[4].items) { /* -noexecute */
2892 fprintf(STDOUT,"Would have deleted VLDB entry for %s \n", vllist->name);
2897 /* Only matches the RW volume name */
2898 avolid = vllist->volumeId[RWVOL];
2899 vcode = ubik_Call(VL_DeleteEntry, cstruct, 0, avolid, RWVOL);
2901 fprintf(STDOUT,"Could not delete VDLB entry for %s\n",vllist->name);
2903 PrintError("",vcode);
2908 fprintf(STDOUT,"Deleted VLDB entry for %s \n",vllist->name);
2913 fprintf(STDOUT,"----------------------\n");
2914 fprintf(STDOUT,"Total VLDB entries deleted: %u; failed to delete: %u\n",totalBack,totalFail);
2915 if (arrayEntries.nbulkentries_val) free(arrayEntries.nbulkentries_val);
2920 static int CompareVldbEntryByName(p1,p2)
2923 struct nvldbentry *arg1,*arg2;
2925 arg1 = (struct nvldbentry *)p1;
2926 arg2 = (struct nvldbentry *)p2;
2927 return(strcmp(arg1->name,arg2->name));
2931 static int CompareVldbEntry(p1,p2)
2934 struct nvldbentry *arg1,*arg2;
2937 char comp1[100],comp2[100];
2938 char temp1[20],temp2[20];
2940 arg1 = (struct nvldbentry *)p1;
2941 arg2 = (struct nvldbentry *)p2;
2945 for(i = 0; i < arg1->nServers; i++)
2946 if(arg1->serverFlags[i] & ITSRWVOL) pos1 = i;
2947 for(i = 0; i < arg2->nServers; i++)
2948 if(arg2->serverFlags[i] & ITSRWVOL) pos2 = i;
2949 if(pos1 == -1 || pos2 == -1){
2953 sprintf(comp1,"%10u",arg1->serverNumber[pos1]);
2954 sprintf(comp2,"%10u",arg2->serverNumber[pos2]);
2955 sprintf(temp1,"%10u",arg1->serverPartition[pos1]);
2956 sprintf(temp2,"%10u",arg2->serverPartition[pos2]);
2957 strcat(comp1,temp1);
2958 strcat(comp2,temp2);
2959 strcat(comp1,arg1->name);
2960 strcat(comp1,arg2->name);
2961 return(strcmp(comp1,comp2));
2967 struct cmd_syndesc *as;
2970 afs_int32 aserver,code;
2972 struct VldbListByAttributes attributes;
2973 nbulkentries arrayEntries;
2974 struct nvldbentry *vllist, *tarray=0, *ttarray;
2975 afs_int32 centries, nentries = 0, tarraysize, parraysize;
2978 int quiet, sort, lock;
2979 afs_int32 thisindex, nextindex;
2984 attributes.Mask = 0;
2985 lock = (as->parms[3].items ? 1 : 0); /* -lock flag */
2986 quiet = (as->parms[4].items ? 1 : 0); /* -quit flag */
2987 sort = (as->parms[5].items ? 0 : 1); /* -nosort flag */
2989 /* If the volume name is given, Use VolumeInfoCmd to look it up
2990 * and not ListAttributes.
2992 if (as->parms[0].items) {
2994 fprintf(STDERR,"vos: illegal use of '-locked' switch, need to specify server and/or partition\n");
2997 code = VolumeInfoCmd(as->parms[0].items->data);
2999 PrintError("",code);
3005 /* Server specified */
3006 if (as->parms[1].items) {
3007 aserver = GetServer(as->parms[1].items->data);
3009 fprintf(STDERR,"vos: server '%s' not found in host table\n",as->parms[1].items->data );
3012 attributes.server = ntohl(aserver);
3013 attributes.Mask |= VLLIST_SERVER;
3016 /* Partition specified */
3017 if (as->parms[2].items) {
3018 apart = volutil_GetPartitionID(as->parms[2].items->data);
3020 fprintf(STDERR,"vos: could not interpret partition name '%s'\n", as->parms[2].items->data);
3023 attributes.partition = apart;
3024 attributes.Mask |= VLLIST_PARTITION;
3028 attributes.Mask |= VLLIST_FLAG;
3029 attributes.flag = VLOP_ALLOPERS;
3032 /* Print header information */
3034 MapPartIdIntoName(apart, pname);
3035 fprintf(STDOUT,"VLDB entries for %s %s%s%s %s\n",
3036 (as->parms[1].items ? "server" : "all" ),
3037 (as->parms[1].items ? as->parms[1].items->data : "servers"),
3038 (as->parms[2].items ? " partition " : ""),
3039 (as->parms[2].items ? pname : ""),
3040 (lock ? "which are locked:" : ""));
3043 for (thisindex = 0; (thisindex != -1); thisindex = nextindex) {
3044 bzero(&arrayEntries, sizeof(arrayEntries));
3048 vcode = VLDB_ListAttributesN2(&attributes, 0, thisindex,
3049 ¢ries, &arrayEntries, &nextindex);
3050 if (vcode == RXGEN_OPCODE) {
3051 /* Vlserver not running with ListAttributesN2. Fall back */
3052 vcode = VLDB_ListAttributes(&attributes, ¢ries, &arrayEntries);
3056 fprintf(STDERR,"Could not access the VLDB for attributes\n");
3057 PrintError("",vcode);
3060 nentries += centries;
3062 /* We don't sort, so just print the entries now */
3064 for (j = 0; j < centries; j++) { /* process each entry */
3065 vllist = &arrayEntries.nbulkentries_val[j];
3066 MapHostToNetwork(vllist);
3067 EnumerateEntry(vllist);
3069 if(vllist->flags & VLOP_ALLOPERS)
3070 fprintf(STDOUT," Volume is currently LOCKED \n");
3074 /* So we sort. First we must collect all the entries and keep
3077 else if (centries > 0) {
3079 /* steal away the first bulk entries array */
3080 tarray = (struct nvldbentry *)arrayEntries.nbulkentries_val;
3081 tarraysize = centries * sizeof(struct nvldbentry);
3082 arrayEntries.nbulkentries_val = 0;
3084 /* Grow the tarray to keep the extra entries */
3085 parraysize = (centries * sizeof(struct nvldbentry));
3086 ttarray = (struct nvldbentry *) realloc(tarray, tarraysize + parraysize);
3088 fprintf(STDERR,"Could not allocate enough space for the VLDB entries\n");
3094 bcopy((char *)arrayEntries.nbulkentries_val,
3095 ((char *)tarray)+tarraysize, parraysize);
3096 tarraysize += parraysize;
3100 /* Free the bulk array */
3101 if (arrayEntries.nbulkentries_val) {
3102 free(arrayEntries.nbulkentries_val);
3103 arrayEntries.nbulkentries_val = 0;
3107 /* Here is where we now sort all the entries and print them */
3108 if (sort && (nentries > 0)) {
3109 qsort((char *)tarray, nentries, sizeof(struct nvldbentry), CompareVldbEntryByName);
3110 for (vllist=tarray, j=0; j<nentries; j++, vllist++) {
3111 MapHostToNetwork(vllist);
3112 EnumerateEntry(vllist);
3114 if(vllist->flags & VLOP_ALLOPERS)
3115 fprintf(STDOUT," Volume is currently LOCKED \n");
3120 if (!quiet) fprintf(STDOUT,"\nTotal entries: %u\n", nentries);
3121 if (tarray) free(tarray);
3126 register struct cmd_syndesc *as;
3128 afs_int32 apart=0, avolid;
3129 afs_int32 aserver=0, code, aserver1, apart1;
3131 struct VldbListByAttributes attributes;
3132 nbulkentries arrayEntries;
3133 register struct nvldbentry *vllist;
3137 int seenprefix, seenxprefix, exclude, ex, exp, noaction;
3138 afs_int32 totalBack=0;
3139 afs_int32 totalFail=0;
3140 int previdx=-1, error, same;
3143 struct cmd_item *ti;
3147 bzero(&attributes,sizeof(struct VldbListByAttributes));
3148 attributes.Mask = 0;
3150 seenprefix = (as->parms[0].items ? 1 : 0);
3151 exclude = (as->parms[3].items ? 1 : 0);
3152 seenxprefix = (as->parms[4].items ? 1 : 0);
3153 noaction = (as->parms[5].items ? 1 : 0);
3155 if (as->parms[1].items) { /* -server */
3156 aserver = GetServer(as->parms[1].items->data);
3158 fprintf(STDERR,"vos: server '%s' not found in host table\n",as->parms[1].items->data );
3161 attributes.server = ntohl(aserver);
3162 attributes.Mask |= VLLIST_SERVER;
3165 if (as->parms[2].items) { /* -partition */
3166 apart = volutil_GetPartitionID(as->parms[2].items->data);
3168 fprintf(STDERR,"vos: could not interpret partition name '%s'\n", as->parms[2].items->data);
3171 attributes.partition = apart;
3172 attributes.Mask |= VLLIST_PARTITION;
3175 /* Check to make sure the prefix and xprefix expressions compile ok */
3177 for (ti=as->parms[0].items; ti; ti=ti->next) {
3178 if (strncmp(ti->data,"^",1) == 0) {
3179 ccode = (char *)re_comp(ti->data);
3181 fprintf(STDERR,"Unrecognizable -prefix regular expression: '%s': %s\n",
3189 for (ti=as->parms[4].items; ti; ti=ti->next) {
3190 if (strncmp(ti->data,"^",1) == 0) {
3191 ccode = (char *)re_comp(ti->data);
3193 fprintf(STDERR,"Unrecognizable -xprefix regular expression: '%s': %s\n",
3201 bzero(&arrayEntries, sizeof(arrayEntries)); /* initialize to hint the stub to alloc space */
3202 vcode = VLDB_ListAttributes(&attributes, &nentries, &arrayEntries);
3204 fprintf(STDERR,"Could not access the VLDB for attributes\n");
3205 PrintError("",vcode);
3209 if (as->parms[1].items || as->parms[2].items || verbose) {
3210 fprintf(STDOUT,"%s up volumes", (noaction?"Would have backed":"Backing"));
3212 if (as->parms[1].items) {
3213 fprintf(STDOUT," on server %s", as->parms[1].items->data);
3214 } else if (as->parms[2].items) {
3215 fprintf(STDOUT," for all servers");
3218 if (as->parms[2].items) {
3219 MapPartIdIntoName(apart, pname);
3220 fprintf(STDOUT," partition %s", pname);
3223 if (seenprefix || (!seenprefix && seenxprefix)) {
3224 ti = (seenprefix ? as->parms[0].items : as->parms[4].items);
3225 ex = (seenprefix ? exclude : !exclude);
3226 exp = (strncmp(ti->data,"^",1) == 0);
3227 fprintf(STDOUT," which %smatch %s '%s'", (ex ? "do not " : ""),
3228 (exp?"expression":"prefix"), ti->data);
3229 for (ti=ti->next; ti; ti=ti->next) {
3230 exp = (strncmp(ti->data,"^",1) == 0);
3231 printf(" %sor %s '%s'", (ex ? "n" : ""),
3232 (exp?"expression":"prefix"), ti->data);
3236 if (seenprefix && seenxprefix) {
3237 ti = as->parms[4].items;
3238 exp = (strncmp(ti->data,"^",1) == 0);
3239 fprintf(STDOUT," %swhich match %s '%s'",
3240 (exclude?"adding those ":"removing those "),
3241 (exp?"expression":"prefix"), ti->data);
3242 for (ti=ti->next; ti; ti=ti->next) {
3243 exp = (strncmp(ti->data,"^",1) == 0);
3244 printf(" or %s '%s'", (exp?"expression":"prefix"), ti->data);
3247 fprintf(STDOUT," .. ");
3248 if (verbose) fprintf(STDOUT,"\n");
3252 for (j=0; j<nentries; j++) { /* process each vldb entry */
3253 vllist = &arrayEntries.nbulkentries_val[j];
3256 for (ti=as->parms[0].items; ti; ti=ti->next) {
3257 if (strncmp(ti->data,"^",1) == 0) {
3258 ccode = (char *)re_comp(ti->data);
3260 fprintf(STDERR,"Error in -prefix regular expression: '%s': %s\n",
3264 match = (re_exec(vllist->name) == 1);
3266 match = (strncmp(vllist->name,ti->data,strlen(ti->data)) == 0);
3274 /* Without the -exclude flag: If it matches the prefix, then
3275 * check if we want to exclude any from xprefix.
3276 * With the -exclude flag: If it matches the prefix, then
3277 * check if we want to add any from xprefix.
3279 if (match && seenxprefix) {
3280 for (ti=as->parms[4].items; ti; ti=ti->next) {
3281 if (strncmp(ti->data,"^",1) == 0) {
3282 ccode = (char *)re_comp(ti->data);
3284 fprintf(STDERR,"Error in -xprefix regular expression: '%s': %s\n",
3288 if (re_exec(vllist->name) == 1) {
3293 if (strncmp(vllist->name,ti->data,strlen(ti->data)) == 0) {
3301 if (exclude) match = !match; /* -exclude will reverse the match */
3302 if (!match) continue; /* Skip if no match */
3304 /* Print list of volumes to backup */
3306 fprintf(STDOUT," %s\n", vllist->name);
3310 if(!(vllist->flags & RW_EXISTS)){
3312 fprintf(STDOUT,"Omitting to backup %s since RW volume does not exist \n", vllist->name);
3313 fprintf(STDOUT,"\n");
3319 avolid = vllist->volumeId[RWVOL];
3320 MapHostToNetwork(vllist);
3321 GetServerAndPart(vllist,RWVOL,&aserver1,&apart1,&previdx);
3322 if(aserver1 == -1 || apart1 == -1){
3323 fprintf(STDOUT,"could not backup %s, invalid VLDB entry\n",vllist->name);
3328 same = VLDB_IsSameAddrs(aserver, aserver1, &error);
3330 fprintf(STDERR,"Failed to get info about server's %d address(es) from vlserver (err=%d); aborting call!\n",
3336 if ((aserver && !same) || (apart && (apart != apart1))) {
3338 fprintf(STDOUT, "Omitting to backup %s since the RW is in a different location\n", vllist->name);
3343 time_t now = time(0);
3344 fprintf(STDOUT,"Creating backup volume for %s on %s",vllist->name, ctime(&now));
3348 code = UV_BackupVolume(aserver1, apart1, avolid);
3350 fprintf(STDOUT,"Could not backup %s\n",vllist->name);
3356 if (verbose) fprintf(STDOUT,"\n");
3358 } /* process each vldb entry */
3359 fprintf(STDOUT,"done\n");
3360 fprintf(STDOUT,"Total volumes backed up: %u; failed to backup: %u\n",totalBack,totalFail);
3362 if(arrayEntries.nbulkentries_val) free(arrayEntries.nbulkentries_val);
3366 static UnlockVLDB(as)
3367 register struct cmd_syndesc *as;
3370 afs_int32 aserver,code;
3372 struct VldbListByAttributes attributes;
3373 nbulkentries arrayEntries;
3374 register struct nvldbentry *vllist;
3383 attributes.Mask = 0;
3385 if(as->parms[0].items) {/* server specified */
3386 aserver = GetServer(as->parms[0].items->data);
3388 fprintf(STDERR,"vos: server '%s' not found in host table\n",as->parms[0].items->data );
3391 attributes.server = ntohl(aserver);
3392 attributes.Mask |= VLLIST_SERVER;
3394 if(as->parms[1].items) {/* partition specified */
3395 apart = volutil_GetPartitionID(as->parms[1].items->data);
3397 fprintf(STDERR,"vos: could not interpret partition name '%s'\n", as->parms[1].items->data);
3400 if (!IsPartValid(apart,aserver,&code)){/*check for validity of the partition */
3401 if(code) PrintError("",code);
3402 else fprintf(STDERR,"vos : partition %s does not exist on the server\n",as->parms[1].items->data);
3405 attributes.partition = apart;
3406 attributes.Mask |= VLLIST_PARTITION;
3408 attributes.flag = VLOP_ALLOPERS;
3409 attributes.Mask |= VLLIST_FLAG;
3410 bzero(&arrayEntries, sizeof(arrayEntries)); /*initialize to hint the stub to alloc space */
3411 vcode = VLDB_ListAttributes(&attributes, &nentries, &arrayEntries);
3413 fprintf(STDERR,"Could not access the VLDB for attributes\n");
3414 PrintError("",vcode);
3417 for(j=0;j<nentries;j++) { /* process each entry */
3418 vllist = &arrayEntries.nbulkentries_val[j];
3419 volid = vllist->volumeId[RWVOL];
3420 vcode = ubik_Call(VL_ReleaseLock,cstruct, 0, volid,-1, LOCKREL_OPCODE | LOCKREL_AFSID | LOCKREL_TIMESTAMP);
3422 fprintf(STDERR,"Could not unlock entry for volume %s\n",vllist->name);
3423 PrintError("",vcode);
3428 MapPartIdIntoName(apart,pname);
3429 if(totalE) fprintf(STDOUT,"Could not lock %u VLDB entries of %u locked entries\n",totalE,nentries);
3431 if(as->parms[0].items) {
3432 fprintf(STDOUT,"Unlocked all the VLDB entries for volumes on server %s ",as->parms[0].items->data);
3433 if(as->parms[1].items){
3434 MapPartIdIntoName(apart,pname);
3435 fprintf(STDOUT,"partition %s\n",pname);
3437 else fprintf(STDOUT,"\n");
3440 else if(as->parms[1].items){
3441 MapPartIdIntoName(apart,pname);
3442 fprintf(STDOUT,"Unlocked all the VLDB entries for volumes on partition %s on all servers\n",pname);
3446 if(arrayEntries.nbulkentries_val) free(arrayEntries.nbulkentries_val);
3450 static PartitionInfo(as)
3451 register struct cmd_syndesc *as;
3454 afs_int32 aserver,code;
3456 struct diskPartition partition;
3457 struct partList dummyPartList;
3461 aserver = GetServer(as->parms[0].items->data);
3463 fprintf(STDERR,"vos: server '%s' not found in host table\n",as->parms[0].items->data );
3466 if(as->parms[1].items){
3467 apart = volutil_GetPartitionID(as->parms[1].items->data);
3469 fprintf(STDERR,"vos: could not interpret partition name '%s'\n", as->parms[1].items->data);
3472 dummyPartList.partId[0] = apart;
3473 dummyPartList.partFlags[0] = PARTVALID;
3477 if (!IsPartValid(apart,aserver,&code)){/*check for validity of the partition */
3478 if(code) PrintError("",code);
3479 else fprintf(STDERR,"vos : partition %s does not exist on the server\n",as->parms[1].items->data);
3484 code = UV_ListPartitions(aserver,&dummyPartList, &cnt);
3486 PrintDiagnostics("listpart", code);
3490 for(i = 0 ; i < cnt ; i++){
3491 if(dummyPartList.partFlags[i] & PARTVALID){
3492 MapPartIdIntoName(dummyPartList.partId[i],pname);
3493 code = UV_PartitionInfo(aserver,pname,&partition);
3495 fprintf(STDERR,"Could not get information on partition %s\n",pname);
3496 PrintError("",code);
3499 fprintf(STDOUT,"Free space on partition %s: %d K blocks out of total %d\n",pname,partition.free,partition.minFree);
3505 static ChangeAddr(as)
3506 register struct cmd_syndesc *as;
3509 afs_int32 ip1, ip2, vcode;
3512 ip1 = GetServer(as->parms[0].items->data);
3514 fprintf(STDERR, "vos: invalid host address\n");
3518 if ( ( as->parms[1].items && as->parms[2].items) ||
3519 (!as->parms[1].items && !as->parms[2].items) ) {
3520 fprintf(STDERR, "vos: Must specify either '-newaddr <addr>' or '-remove' flag\n");
3524 if (as->parms[1].items) {
3525 ip2 = GetServer(as->parms[1].items->data);
3527 fprintf(STDERR, "vos: invalid host address\n");
3531 /* Play a trick here. If we are removing an address, ip1 will be -1
3532 * and ip2 will be the original address. This switch prevents an
3533 * older revision vlserver from removing the IP address.
3540 vcode = ubik_Call_New(VL_ChangeAddr, cstruct, 0, ntohl(ip1), ntohl(ip2) );
3543 fprintf(STDERR,"Could not remove server %s from the VLDB\n",
3544 as->parms[0].items->data);
3545 if (vcode == VL_NOENT) {
3546 fprintf(STDERR, "vlserver does not support the remove flag or ");
3549 fprintf(STDERR,"Could not change server %s to server %s\n",
3550 as->parms[0].items->data, as->parms[1].items->data);
3552 PrintError("",vcode);
3557 fprintf(STDOUT,"Removed server %s from the VLDB\n",
3558 as->parms[0].items->data);
3560 fprintf(STDOUT,"Changed server %s to server %s\n",
3561 as->parms[0].items->data, as->parms[1].items->data);
3566 static ListAddrs(as)
3567 register struct cmd_syndesc *as;
3572 struct VLCallBack unused;
3573 afs_int32 nentries, *addrp;
3574 bulkaddrs addrs, m_addrs;
3575 ListAddrByAttributes m_attrs;
3577 afs_int32 m_unique, m_nentries, *m_addrp;
3578 afs_int32 base, index;
3580 /* Get the list of non multihomed fileservers */
3581 addrs.bulkaddrs_val = 0;
3582 addrs.bulkaddrs_len = 0;
3583 vcode = ubik_Call_New(VL_GetAddrs, cstruct, 0,
3584 0, 0, &unused, &nentries, &addrs);
3586 fprintf(STDERR,"vos: could not list the server addresses\n");
3587 PrintError("",vcode);
3591 /* print out the list of all the server */
3592 addrp = (afs_int32 *)addrs.bulkaddrs_val;
3593 for (i=0; i<nentries; i++, addrp++) {
3594 /* If it is a multihomed address, then we will need to
3595 * get the addresses for this multihomed server from
3596 * the vlserver and print them.
3598 if ( ((*addrp & 0xff000000) == 0xff000000) && ((*addrp)&0xffff) ) {
3599 /* Get the list of multihomed fileservers */
3600 base = (*addrp>>16) & 0xff;
3601 index = (*addrp) & 0xffff;
3603 if ( (base >= 0) && (base <= VL_MAX_ADDREXTBLKS) &&
3604 (index >= 1) && (index <= VL_MHSRV_PERBLK) ) {
3605 m_attrs.Mask = VLADDR_INDEX;
3606 m_attrs.index = (base * VL_MHSRV_PERBLK) + index;
3608 m_addrs.bulkaddrs_val = 0;
3609 m_addrs.bulkaddrs_len = 0;
3610 vcode = ubik_Call(VL_GetAddrsU, cstruct, 0,
3611 &m_attrs, &m_uuid, &m_unique, &m_nentries, &m_addrs);
3613 fprintf(STDERR,"vos: could not list the multi-homed server addresses\n");
3614 PrintError("",vcode);
3617 /* Print the list */
3618 m_addrp = (afs_int32 *)m_addrs.bulkaddrs_val;
3619 for (j=0; j<m_nentries; j++, m_addrp++) {
3620 *m_addrp = htonl(*m_addrp);
3621 printf("%s ", hostutil_GetNameByINet(*m_addrp));
3624 printf("<unknown>\n");
3633 /* Otherwise, it is a non-multihomed entry and contains
3634 * the IP address of the server - print it.
3636 printf ("%s\n", hostutil_GetNameByINet(htonl(*addrp)));
3639 if (addrs.bulkaddrs_val) {
3640 free (addrs.bulkaddrs_val);
3645 static LockEntry(as)
3646 register struct cmd_syndesc *as;
3649 afs_int32 avolid,vcode, err;
3651 avolid = vsu_GetVolumeID(as->parms[0].items->data, cstruct, &err);
3653 if (err) PrintError("", err);
3654 else fprintf(STDERR, "vos: can't find volume '%s'\n", as->parms[0].items->data);
3657 vcode = ubik_Call(VL_SetLock,cstruct, 0, avolid, -1, VLOP_DELETE);
3659 fprintf(STDERR,"Could not lock VLDB entry for volume %s\n",as->parms[0].items->data);
3660 PrintError("",vcode);
3663 fprintf(STDOUT,"Locked VLDB entry for volume %s\n",as->parms[0].items->data);
3667 PrintDiagnostics(astring, acode)
3671 if (acode == EACCES) {
3672 fprintf(STDERR,"You are not authorized to perform the 'vos %s' command (%d)\n",
3676 fprintf(STDERR,"Error in vos %s command.\n", astring);
3677 PrintError("", acode);
3683 static MyBeforeProc(as, arock)
3684 struct cmd_syndesc *as;
3686 register char *tcell;
3687 register afs_int32 code;
3688 register afs_int32 sauth;
3690 /* Initialize the ubik_client connection */
3691 rx_SetRxDeadTime(90);
3692 cstruct = (struct ubik_client *)0;
3696 if (as->parms[12].items) /* if -cell specified */
3697 tcell = as->parms[12].items->data;
3698 if(as->parms[14].items) /* -serverauth specified */
3700 if (code = vsu_ClientInit((as->parms[13].items != 0), confdir, tcell, sauth,
3701 &cstruct, UV_SetSecurity)) {
3702 fprintf(STDERR,"could not initialize VLDB library (code=%u) \n",code);
3706 if(as->parms[15].items) /* -verbose flag set */
3715 /* this sucks but it works for now.
3720 #include "AFS_component_version_number.c"
3725 register afs_int32 code;
3727 register struct cmd_syndesc *ts;
3729 #ifdef AFS_AIX32_ENV
3731 * The following signal action for AIX is necessary so that in case of a
3732 * crash (i.e. core is generated) we can include the user's data section
3733 * in the core dump. Unfortunately, by default, only a partial core is
3734 * generated which, in many cases, isn't too useful.
3736 struct sigaction nsa;
3738 sigemptyset(&nsa.sa_mask);
3739 nsa.sa_handler = SIG_DFL;
3740 nsa.sa_flags = SA_FULLDUMP;
3741 sigaction(SIGSEGV, &nsa, NULL);
3744 confdir = AFSDIR_CLIENT_ETC_DIRPATH;
3746 cmd_SetBeforeProc(MyBeforeProc, (char *) 0);
3748 ts = cmd_CreateSyntax("create", CreateVolume, 0, "create a new volume");
3749 cmd_AddParm(ts, "-server", CMD_SINGLE, 0, "machine name");
3750 cmd_AddParm(ts, "-partition", CMD_SINGLE, 0, "partition name");
3751 cmd_AddParm(ts, "-name", CMD_SINGLE, 0, "volume name");
3752 cmd_AddParm(ts, "-maxquota", CMD_SINGLE, CMD_OPTIONAL, "initial quota (KB)");
3754 cmd_AddParm(ts, "-minquota", CMD_SINGLE, CMD_OPTIONAL, "");
3758 ts = cmd_CreateSyntax("remove", DeleteVolume, 0, "delete a volume");
3759 cmd_AddParm(ts, "-server", CMD_SINGLE, CMD_OPTIONAL, "machine name");
3760 cmd_AddParm(ts, "-partition", CMD_SINGLE, CMD_OPTIONAL, "partition name");
3761 cmd_AddParm(ts, "-id", CMD_SINGLE, 0, "volume name or ID");
3765 ts = cmd_CreateSyntax("move", MoveVolume, 0, "move a volume");
3766 cmd_AddParm(ts, "-id", CMD_SINGLE, 0, "volume name or ID");
3767 cmd_AddParm(ts, "-fromserver", CMD_SINGLE, 0, "machine name on source");
3768 cmd_AddParm(ts, "-frompartition", CMD_SINGLE, 0, "partition name on source");
3769 cmd_AddParm(ts, "-toserver", CMD_SINGLE, 0, "machine name on destination");
3770 cmd_AddParm(ts, "-topartition", CMD_SINGLE, 0, "partition name on destination");
3773 ts = cmd_CreateSyntax("backup", BackupVolume, 0, "make backup of a volume");
3774 cmd_AddParm(ts, "-id", CMD_SINGLE, 0, "volume name or ID");
3777 ts = cmd_CreateSyntax("release", ReleaseVolume, 0, "release a volume");
3778 cmd_AddParm(ts, "-id", CMD_SINGLE, 0, "volume name or ID");
3779 cmd_AddParm(ts, "-force", CMD_FLAG, CMD_OPTIONAL, "force a complete release");
3782 ts = cmd_CreateSyntax("dump", DumpVolume, 0, "dump a volume");
3783 cmd_AddParm(ts, "-id", CMD_SINGLE, 0, "volume name or ID");
3784 cmd_AddParm(ts, "-time", CMD_SINGLE, CMD_OPTIONAL, "dump from time");
3785 cmd_AddParm(ts, "-file", CMD_SINGLE, CMD_OPTIONAL, "dump file");
3786 cmd_AddParm(ts, "-server", CMD_SINGLE, CMD_OPTIONAL, "server");
3787 cmd_AddParm(ts, "-partition", CMD_SINGLE, CMD_OPTIONAL, "partition");
3790 ts = cmd_CreateSyntax("restore", RestoreVolume, 0, "restore a volume");
3791 cmd_AddParm(ts, "-server", CMD_SINGLE, 0, "machine name");
3792 cmd_AddParm(ts, "-partition", CMD_SINGLE, 0, "partition name");
3793 cmd_AddParm(ts, "-name", CMD_SINGLE, 0, "name of volume to be restored");
3794 cmd_AddParm(ts, "-file", CMD_SINGLE,CMD_OPTIONAL, "dump file");
3795 cmd_AddParm(ts, "-id", CMD_SINGLE,CMD_OPTIONAL, "volume ID");
3796 cmd_AddParm(ts, "-overwrite", CMD_SINGLE,CMD_OPTIONAL, "abort | full | incremental");
3799 ts = cmd_CreateSyntax("unlock", LockReleaseCmd, 0, "release lock on VLDB entry for a volume");
3800 cmd_AddParm(ts, "-id", CMD_SINGLE, 0, "volume name or ID");
3803 ts = cmd_CreateSyntax("addsite", AddSite, 0, "add a replication site");
3804 cmd_AddParm(ts, "-server", CMD_SINGLE, 0, "machine name for new site");
3805 cmd_AddParm(ts, "-partition", CMD_SINGLE, 0, "partition name for new site");
3806 cmd_AddParm(ts, "-id", CMD_SINGLE, 0, "volume name or ID");
3809 ts = cmd_CreateSyntax("remsite", RemoveSite, 0, "remove a replication site");
3810 cmd_AddParm(ts, "-server", CMD_SINGLE, 0, "machine name");
3811 cmd_AddParm(ts, "-partition", CMD_SINGLE, 0, "partition name");
3812 cmd_AddParm(ts, "-id", CMD_SINGLE, 0, "volume name or ID");
3815 ts = cmd_CreateSyntax("listpart", ListPartitions, 0, "list partitions");
3816 cmd_AddParm(ts, "-server", CMD_SINGLE, 0, "machine name");
3819 ts = cmd_CreateSyntax("listvol", ListVolumes, 0, "list volumes on server (bypass VLDB)");
3820 cmd_AddParm(ts, "-server", CMD_SINGLE, 0, "machine name");
3821 cmd_AddParm(ts, "-partition", CMD_SINGLE,CMD_OPTIONAL, "partition name");
3822 cmd_AddParm(ts, "-fast", CMD_FLAG, CMD_OPTIONAL, "minimal listing");
3823 cmd_AddParm(ts, "-long", CMD_FLAG, CMD_OPTIONAL,
3824 "list all normal volume fields");
3825 cmd_AddParm(ts, "-quiet", CMD_FLAG, CMD_OPTIONAL, "generate minimal information");
3826 cmd_AddParm(ts, "-extended", CMD_FLAG, CMD_OPTIONAL,
3827 "list extended volume fields");
3830 ts = cmd_CreateSyntax("syncvldb", SyncVldb, 0, "synchronize VLDB with server");
3831 cmd_AddParm(ts, "-server", CMD_SINGLE, CMD_OPTIONAL, "machine name");
3832 cmd_AddParm(ts, "-partition", CMD_SINGLE,CMD_OPTIONAL , "partition name");
3833 cmd_AddParm(ts, "-volume", CMD_SINGLE,CMD_OPTIONAL , "volume name or ID");
3836 ts = cmd_CreateSyntax("syncserv", SyncServer, 0, "synchronize server with VLDB");
3837 cmd_AddParm(ts, "-server", CMD_SINGLE, 0, "machine name");
3838 cmd_AddParm(ts, "-partition", CMD_SINGLE,CMD_OPTIONAL , "partition name");
3841 ts = cmd_CreateSyntax("examine", ExamineVolume, 0, "everything about the volume");
3842 cmd_AddParm(ts, "-id", CMD_SINGLE, 0, "volume name or ID");
3843 cmd_AddParm(ts, "-extended", CMD_FLAG, CMD_OPTIONAL,
3844 "list extended volume fields");
3846 cmd_CreateAlias (ts, "volinfo");
3848 ts = cmd_CreateSyntax("offline", volOffline, 0, (char *) CMD_HIDDEN);
3849 cmd_AddParm(ts, "-server", CMD_SINGLE, 0, "server name");
3850 cmd_AddParm(ts, "-partition", CMD_SINGLE, 0, "partition name");
3851 cmd_AddParm(ts, "-id", CMD_SINGLE, 0, "volume name or ID");
3852 cmd_AddParm(ts, "-sleep", CMD_SINGLE, CMD_OPTIONAL, "seconds to sleep");
3853 cmd_AddParm(ts, "-busy", CMD_FLAG, CMD_OPTIONAL, "busy volume");
3856 ts = cmd_CreateSyntax("online", volOnline, 0, (char *) CMD_HIDDEN);
3857 cmd_AddParm(ts, "-server", CMD_SINGLE, 0, "server name");
3858 cmd_AddParm(ts, "-partition", CMD_SINGLE, 0, "partition name");
3859 cmd_AddParm(ts, "-id", CMD_SINGLE, 0, "volume name or ID");
3862 ts = cmd_CreateSyntax("zap", VolumeZap, 0, "delete the volume, don't bother with VLDB");
3863 cmd_AddParm(ts, "-server", CMD_SINGLE, 0, "machine name");
3864 cmd_AddParm(ts, "-partition", CMD_SINGLE, 0, "partition name");
3865 cmd_AddParm(ts, "-id", CMD_SINGLE, 0, "volume ID");
3866 cmd_AddParm(ts, "-force", CMD_FLAG, CMD_OPTIONAL, "force deletion of bad volumes");
3867 cmd_AddParm(ts, "-backup", CMD_FLAG, CMD_OPTIONAL, "also delete backup volume if one is found");
3870 ts = cmd_CreateSyntax("status", VolserStatus, 0, "report on volser status");
3871 cmd_AddParm(ts, "-server", CMD_SINGLE, 0, "machine name");
3874 ts = cmd_CreateSyntax("rename", RenameVolume, 0, "rename a volume");
3875 cmd_AddParm(ts, "-oldname", CMD_SINGLE, 0, "old volume name ");
3876 cmd_AddParm(ts, "-newname", CMD_SINGLE, 0, "new volume name ");
3879 ts = cmd_CreateSyntax("listvldb", ListVLDB, 0, "list volumes in the VLDB");
3880 cmd_AddParm(ts, "-name", CMD_SINGLE,CMD_OPTIONAL, "volume name or ID");
3881 cmd_AddParm(ts, "-server", CMD_SINGLE,CMD_OPTIONAL, "machine name");
3882 cmd_AddParm(ts, "-partition", CMD_SINGLE,CMD_OPTIONAL, "partition name");
3883 cmd_AddParm(ts, "-locked", CMD_FLAG, CMD_OPTIONAL, "locked volumes only");
3884 cmd_AddParm(ts, "-quiet", CMD_FLAG, CMD_OPTIONAL, "generate minimal information");
3885 cmd_AddParm(ts, "-nosort", CMD_FLAG, CMD_OPTIONAL, "do not alphabetically sort the volume names");
3888 ts = cmd_CreateSyntax("backupsys", BackSys, 0, "en masse backups");
3889 cmd_AddParm(ts, "-prefix", CMD_LIST,CMD_OPTIONAL, "common prefix on volume(s)");
3890 cmd_AddParm(ts, "-server", CMD_SINGLE,CMD_OPTIONAL, "machine name");
3891 cmd_AddParm(ts, "-partition", CMD_SINGLE,CMD_OPTIONAL, "partition name");
3892 cmd_AddParm(ts, "-exclude", CMD_FLAG, CMD_OPTIONAL, "exclude common prefix volumes");
3893 cmd_AddParm(ts, "-xprefix", CMD_LIST, CMD_OPTIONAL, "negative prefix on volume(s)");
3894 cmd_AddParm(ts, "-dryrun", CMD_FLAG, CMD_OPTIONAL, "no action");
3897 ts = cmd_CreateSyntax("delentry", DeleteEntry, 0, "delete VLDB entry for a volume");
3898 cmd_AddParm(ts, "-id", CMD_LIST, CMD_OPTIONAL, "volume name or ID");
3899 cmd_AddParm(ts, "-prefix", CMD_SINGLE,CMD_OPTIONAL, "prefix of the volume whose VLDB entry is to be deleted");
3900 cmd_AddParm(ts, "-server", CMD_SINGLE,CMD_OPTIONAL, "machine name");
3901 cmd_AddParm(ts, "-partition", CMD_SINGLE,CMD_OPTIONAL, "partition name");
3902 cmd_AddParm(ts, "-noexecute", CMD_FLAG,CMD_OPTIONAL|CMD_HIDE, "no execute");
3905 ts = cmd_CreateSyntax("partinfo", PartitionInfo, 0, "list partition information");
3906 cmd_AddParm(ts, "-server", CMD_SINGLE, 0, "machine name");
3907 cmd_AddParm(ts, "-partition", CMD_SINGLE,CMD_OPTIONAL, "partition name");
3910 ts = cmd_CreateSyntax("unlockvldb", UnlockVLDB, 0, "unlock all the locked entries in the VLDB");
3911 cmd_AddParm(ts, "-server", CMD_SINGLE,CMD_OPTIONAL, "machine name");
3912 cmd_AddParm(ts, "-partition", CMD_SINGLE,CMD_OPTIONAL, "partition name");
3915 ts = cmd_CreateSyntax("lock", LockEntry, 0, "lock VLDB entry for a volume");
3916 cmd_AddParm(ts, "-id", CMD_SINGLE, 0, "volume name or ID");
3919 ts = cmd_CreateSyntax("changeaddr", ChangeAddr, 0, "change the IP address of a file server");
3920 cmd_AddParm(ts, "-oldaddr", CMD_SINGLE, 0, "original IP address");
3921 cmd_AddParm(ts, "-newaddr", CMD_SINGLE, CMD_OPTIONAL, "new IP address");
3922 cmd_AddParm(ts, "-remove", CMD_FLAG, CMD_OPTIONAL, "remove the IP address from the VLDB");
3925 ts = cmd_CreateSyntax("listaddrs", ListAddrs, 0, "list the IP address of all file servers registered in the VLDB");
3928 code = cmd_Dispatch(argc, argv);
3930 /* Shut down the ubik_client and rx connections */
3932 ubik_ClientDestroy (cstruct);