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>
44 #include <rx/rx_globals.h>
46 #include <afs/vlserver.h>
48 #include <afs/cellconfig.h>
50 #include <afs/afsutil.h>
52 #include <afs/afsint.h>
62 #include "volser_prototypes.h"
75 struct hostent *hostutil_GetHostByName(register char *ahost);
77 #define COMMONPARMS cmd_Seek(ts, 12);\
78 cmd_AddParm(ts, "-cell", CMD_SINGLE, CMD_OPTIONAL, "cell name");\
79 cmd_AddParm(ts, "-noauth", CMD_FLAG, CMD_OPTIONAL, "don't authenticate");\
80 cmd_AddParm(ts, "-localauth",CMD_FLAG,CMD_OPTIONAL,"use server tickets");\
81 cmd_AddParm(ts, "-verbose", CMD_FLAG, CMD_OPTIONAL, "verbose");\
82 cmd_AddParm(ts, "-encrypt", CMD_FLAG, CMD_OPTIONAL, "encrypt commands");\
84 #define ERROR_EXIT(code) {error=(code); goto error_exit;}
88 struct rx_connection *tconn;
90 extern struct ubik_client *cstruct;
92 extern struct rx_connection *UV_Bind();
93 extern int UV_SetSecurity();
94 extern int UV_SetVolumeInfo();
95 extern int vsu_SetCrypt();
97 extern VL_ReleaseLock();
98 extern VL_DeleteEntry();
99 extern VL_ListEntry();
100 extern VL_GetAddrs();
101 extern VL_GetAddrsU();
102 extern VL_ChangeAddr();
104 extern int vsu_ExtractName();
106 extern void EnumerateEntry();
107 extern void SubEnumerateEntry();
110 static struct tqHead busyHead, notokHead;
112 static void qInit(ahead)
113 struct tqHead *ahead;
115 memset((char *)ahead, 0, sizeof(struct tqHead));
120 static void qPut(ahead,volid)
121 struct tqHead *ahead;
126 elem = (struct tqElem *)malloc(sizeof(struct tqElem));
127 elem->next = ahead->next;
134 static void qGet(ahead,volid)
135 struct tqHead *ahead;
140 if(ahead->count <= 0) return;
141 *volid = ahead->next->volid;
143 ahead->next = tmp->next;
149 /* returns 1 if <filename> exists else 0 */
150 static FileExists(filename)
157 code = usd_Open(filename, USD_OPEN_RDONLY, 0, &ufd);
161 code = USD_IOCTL(ufd, USD_IOCTL_GETSIZE, &size);
169 /* returns 1 if <name> doesnot end in .readonly or .backup, else 0 */
170 static VolNameOK(name)
176 total = strlen(name);
177 if(!strcmp(&name[total - 9],".readonly")) {
180 else if(!strcmp(&name[total - 7 ],".backup")) {
188 /* return 1 if name is a number else 0 */
189 static IsNumeric(name)
198 for(i = 0; i < len ; i++){
199 if(*ptr < '0' || *ptr > '9'){
213 * Parse a server name/address and return the address in HOST BYTE order
215 afs_int32 GetServer(aname)
217 register struct hostent *th;
220 register afs_int32 code;
221 char hostname[MAXHOSTCHARS];
223 code = sscanf(aname, "%d.%d.%d.%d", &b1, &b2, &b3, &b4);
225 addr = (b1<<24) | (b2<<16) | (b3<<8) | b4;
226 addr = ntohl(addr); /* convert to host order */
228 th = gethostbyname(aname);
230 memcpy(&addr, th->h_addr, sizeof(addr));
233 if (addr == htonl(0x7f000001)) { /* local host */
234 code = gethostname(hostname, MAXHOSTCHARS);
236 th = gethostbyname(hostname); /* returns host byte order */
238 memcpy(&addr, th->h_addr, sizeof(addr));
244 afs_int32 GetVolumeType(aname)
248 if(!strcmp(aname,"ro"))
250 else if(!strcmp(aname, "rw"))
252 else if(!strcmp(aname,"bk"))
257 int IsPartValid(partId, server, code)
258 afs_int32 server, partId,*code;
261 struct partList dummyPartList;
269 *code = UV_ListPartitions(server,&dummyPartList, &cnt);
270 if(*code) return success;
271 for(i = 0 ; i < cnt ; i++) {
272 if(dummyPartList.partFlags[i] & PARTVALID)
273 if(dummyPartList.partId[i] == partId)
281 /*sends the contents of file associated with <fd> and <blksize> to Rx Stream
282 * associated with <call> */
283 SendFile(ufd, call, blksize)
285 register struct rx_call *call;
288 char *buffer = (char*) 0;
293 buffer = (char *)malloc(blksize);
295 fprintf(STDERR,"malloc failed\n");
299 while (!error && !done) {
300 #ifndef AFS_NT40_ENV /* NT csn't select on non-socket fd's */
303 FD_SET((int)(ufd->handle), &in);
304 /* don't timeout if read blocks */
305 IOMGR_Select(((int)(ufd->handle))+1, &in, 0, 0, 0);
307 error = USD_READ(ufd, buffer, blksize, &nbytes);
309 fprintf(STDERR, "File system read failed\n");
316 if (rx_Write(call, buffer, nbytes) != nbytes){
321 if (buffer) free(buffer);
325 /* function invoked by UV_RestoreVolume, reads the data from rx_trx_stream and
326 * writes it out to the volume. */
327 afs_int32 WriteData(call,rock)
328 struct rx_call *call;
334 afs_int32 error,code;
340 if(!filename || !*filename) {
341 usd_StandardInput(&ufd);
345 code = usd_Open(filename, USD_OPEN_RDONLY, 0, &ufd);
348 code = USD_IOCTL(ufd, USD_IOCTL_GETBLKSIZE, &blksize);
351 fprintf(STDERR,"Could not access file '%s'\n", filename);
356 code = SendFile(ufd,call,blksize);
363 code = USD_CLOSE(ufd);
365 fprintf(STDERR,"Could not close dump file %s\n",
366 (filename && *filename)?filename:"STDOUT");
367 if(!error) error = code;
373 /* Receive data from <call> stream into file associated
374 * with <fd> <blksize>
376 int ReceiveFile(ufd, call, blksize)
378 struct rx_call *call;
383 afs_uint32 bytesleft, w;
386 buffer = (char *)malloc(blksize);
388 fprintf(STDERR,"memory allocation failed\n");
392 while ((bytesread=rx_Read(call,buffer,blksize)) > 0) {
393 for (bytesleft=bytesread; bytesleft; bytesleft-=w) {
394 #ifndef AFS_NT40_ENV /* NT csn't select on non-socket fd's */
397 FD_SET((int)(ufd->handle), &out);
398 /* don't timeout if write blocks */
399 IOMGR_Select(((int)(ufd->handle))+1, 0, &out, 0, 0);
401 error = USD_WRITE(ufd, &buffer[bytesread-bytesleft], bytesleft, &w);
403 fprintf(STDERR,"File system write failed\n");
410 if (buffer) free(buffer);
414 afs_int32 DumpFunction(call, filename)
415 struct rx_call *call;
418 usd_handle_t ufd; /* default is to stdout */
419 afs_int32 error=0, code;
424 /* Open the output file */
425 if (!filename || !*filename) {
426 usd_StandardOutput(&ufd);
430 code = usd_Open(filename, USD_OPEN_CREATE|USD_OPEN_RDWR, 0666, &ufd);
434 code = USD_IOCTL(ufd, USD_IOCTL_SETSIZE, &size);
437 code = USD_IOCTL(ufd, USD_IOCTL_GETBLKSIZE, &blksize);
440 fprintf(STDERR, "Could not create file '%s'\n", filename);
441 ERROR_EXIT(VOLSERBADOP);
445 code = ReceiveFile(ufd, call, blksize);
446 if (code) ERROR_EXIT(code);
449 /* Close the output file */
451 code = USD_CLOSE(ufd);
453 fprintf(STDERR,"Could not close dump file %s\n",
454 (filename && *filename)?filename:"STDIN");
455 if (!error) error = code;
462 static void DisplayFormat(pntr,server,part,totalOK,totalNotOK,totalBusy,fast,longlist,disp)
464 afs_int32 server,part;
465 int *totalOK,*totalNotOK,*totalBusy;
466 int fast,longlist, disp;
471 fprintf(STDOUT,"%-10lu\n", (unsigned long) pntr->volid);
474 if(pntr->status == VOK){
475 fprintf(STDOUT,"%-32s ",pntr->name);
476 fprintf(STDOUT,"%10lu ", (unsigned long) pntr->volid);
477 if(pntr->type == 0) fprintf(STDOUT,"RW ");
478 if(pntr->type == 1) fprintf(STDOUT,"RO ");
479 if(pntr->type == 2) fprintf(STDOUT,"BK ");
480 fprintf(STDOUT,"%10d K ",pntr->size);
481 if(pntr->inUse == 1) {
482 fprintf(STDOUT,"On-line");
485 fprintf(STDOUT,"Off-line");
488 if(pntr->needsSalvaged == 1) fprintf(STDOUT,"**needs salvage**");
489 fprintf(STDOUT,"\n");
490 MapPartIdIntoName(part,pname);
491 fprintf(STDOUT," %s %s \n",hostutil_GetNameByINet(server),pname);
492 fprintf(STDOUT," RWrite %10lu ROnly %10lu Backup %10lu \n",
493 (unsigned long) pntr->parentID,
494 (unsigned long) pntr->cloneID,
495 (unsigned long) pntr->backupID);
496 fprintf(STDOUT," MaxQuota %10d K \n",pntr->maxquota);
497 fprintf(STDOUT," Creation %s",
498 ctime((time_t *)&pntr->creationDate));
499 #ifdef FULL_LISTVOL_SWITCH
500 fprintf(STDOUT," Copy %s",
501 ctime((time_t *)&pntr->copyDate));
502 if(!pntr->backupDate)
503 fprintf(STDOUT," Backup Never\n");
505 fprintf(STDOUT," Backup %s",
506 ctime((time_t *)&pntr->backupDate));
507 if (pntr->accessDate)
508 fprintf(STDOUT," Last Access %s",
509 ctime((time_t *)&pntr->accessDate));
511 if(pntr->updateDate < pntr->creationDate)
512 fprintf(STDOUT," Last Update %s",
513 ctime((time_t *)&pntr->creationDate));
515 fprintf(STDOUT," Last Update %s",
516 ctime((time_t *)&pntr->updateDate));
517 fprintf(STDOUT, " %d accesses in the past day (i.e., vnode references)\n",
520 else if (pntr->status == VBUSY) {
522 qPut(&busyHead,pntr->volid);
523 if (disp) fprintf(STDOUT,"**** Volume %lu is busy ****\n",
524 (unsigned long) pntr->volid);
528 qPut(¬okHead,pntr->volid);
529 if (disp) fprintf(STDOUT,"**** Could not attach volume %lu ****\n",
530 (unsigned long) pntr->volid);
532 fprintf(STDOUT,"\n");
534 else {/* default listing */
535 if(pntr->status == VOK){
536 fprintf(STDOUT,"%-32s ",pntr->name);
537 fprintf(STDOUT,"%10lu ",(unsigned long) pntr->volid);
538 if(pntr->type == 0) fprintf(STDOUT,"RW ");
539 if(pntr->type == 1) fprintf(STDOUT,"RO ");
540 if(pntr->type == 2) fprintf(STDOUT,"BK ");
541 fprintf(STDOUT,"%10d K ",pntr->size);
542 if(pntr->inUse == 1) {
543 fprintf(STDOUT,"On-line");
546 fprintf(STDOUT,"Off-line");
549 if(pntr->needsSalvaged == 1) fprintf(STDOUT,"**needs salvage**");
550 fprintf(STDOUT,"\n");
552 else if (pntr->status == VBUSY) {
554 qPut(&busyHead,pntr->volid);
555 if (disp) fprintf(STDOUT,"**** Volume %lu is busy ****\n",
556 (unsigned long) pntr->volid);
560 qPut(¬okHead,pntr->volid);
561 if (disp) fprintf(STDOUT,"**** Could not attach volume %lu ****\n",
562 (unsigned long) pntr->volid);
567 /*------------------------------------------------------------------------
568 * PRIVATE XDisplayFormat
571 * Display the contents of one extended volume info structure.
574 * a_xInfoP : Ptr to extended volume info struct to print.
575 * a_servID : Server ID to print.
576 * a_partID : Partition ID to print.
577 * a_totalOKP : Ptr to total-OK counter.
578 * a_totalNotOKP : Ptr to total-screwed counter.
579 * a_totalBusyP : Ptr to total-busy counter.
580 * a_fast : Fast listing?
581 * a_int32 : Int32 listing?
582 * a_showProblems : Show volume problems?
588 * Nothing interesting.
592 *------------------------------------------------------------------------*/
594 static void XDisplayFormat(a_xInfoP, a_servID, a_partID, a_totalOKP,
595 a_totalNotOKP, a_totalBusyP, a_fast, a_int32,
597 volintXInfo *a_xInfoP;
615 fprintf(STDOUT, "%-10lu\n", (unsigned long) a_xInfoP->volid);
620 * Fully-detailed listing.
622 if (a_xInfoP->status == VOK) {
624 * Volume's status is OK - all the fields are valid.
626 fprintf(STDOUT, "%-32s ", a_xInfoP->name);
627 fprintf(STDOUT, "%10lu ", (unsigned long) a_xInfoP->volid);
628 if (a_xInfoP->type == 0) fprintf(STDOUT,"RW ");
629 if (a_xInfoP->type == 1) fprintf(STDOUT,"RO ");
630 if (a_xInfoP->type == 2) fprintf(STDOUT,"BK ");
631 fprintf(STDOUT, "%10d K used ", a_xInfoP->size);
632 fprintf(STDOUT, "%d files ", a_xInfoP->filecount);
633 if(a_xInfoP->inUse == 1) {
634 fprintf(STDOUT, "On-line");
638 fprintf(STDOUT, "Off-line");
641 fprintf(STDOUT, "\n");
642 MapPartIdIntoName(a_partID, pname);
643 fprintf(STDOUT, " %s %s \n",
644 hostutil_GetNameByINet(a_servID),
646 fprintf(STDOUT, " RWrite %10lu ROnly %10lu Backup %10lu \n",
647 (unsigned long) a_xInfoP->parentID,
648 (unsigned long) a_xInfoP->cloneID,
649 (unsigned long) a_xInfoP->backupID);
650 fprintf(STDOUT, " MaxQuota %10d K \n",
652 fprintf(STDOUT, " Creation %s",
653 ctime((time_t *)&a_xInfoP->creationDate));
654 #ifdef FULL_LISTVOL_SWITCH
655 fprintf(STDOUT," Copy %s",
656 ctime((time_t *)&a_xInfoP->copyDate));
657 if(!a_xInfoP->backupDate)
658 fprintf(STDOUT," Backup Never\n");
660 fprintf(STDOUT," Backup %s",
661 ctime((time_t *)&a_xInfoP->backupDate));
662 if (a_xInfoP->accessDate)
663 fprintf(STDOUT," Last Access %s",
664 ctime((time_t *)&a_xInfoP->accessDate));
666 if (a_xInfoP->updateDate < a_xInfoP->creationDate)
667 fprintf(STDOUT, " Last Update %s",
668 ctime((time_t *)&a_xInfoP->creationDate));
670 fprintf(STDOUT, " Last Update %s",
671 ctime((time_t *)&a_xInfoP->updateDate));
672 fprintf(STDOUT, " %d accesses in the past day (i.e., vnode references)\n",
676 * Print all the read/write and authorship stats.
679 "\n Raw Read/Write Stats\n");
681 " |-------------------------------------------|\n");
683 " | Same Network | Diff Network |\n");
685 " |----------|----------|----------|----------|\n");
687 " | Total | Auth | Total | Auth |\n");
689 " |----------|----------|----------|----------|\n");
691 "Reads | %8d | %8d | %8d | %8d |\n",
692 a_xInfoP->stat_reads[VOLINT_STATS_SAME_NET],
693 a_xInfoP->stat_reads[VOLINT_STATS_SAME_NET_AUTH],
694 a_xInfoP->stat_reads[VOLINT_STATS_DIFF_NET],
695 a_xInfoP->stat_reads[VOLINT_STATS_DIFF_NET_AUTH]);
697 "Writes | %8d | %8d | %8d | %8d |\n",
698 a_xInfoP->stat_writes[VOLINT_STATS_SAME_NET],
699 a_xInfoP->stat_writes[VOLINT_STATS_SAME_NET_AUTH],
700 a_xInfoP->stat_writes[VOLINT_STATS_DIFF_NET],
701 a_xInfoP->stat_writes[VOLINT_STATS_DIFF_NET_AUTH]);
703 " |-------------------------------------------|\n\n");
706 " Writes Affecting Authorship\n");
708 " |-------------------------------------------|\n");
710 " | File Authorship | Directory Authorship|\n");
712 " |----------|----------|----------|----------|\n");
714 " | Same | Diff | Same | Diff |\n");
716 " |----------|----------|----------|----------|\n");
718 "0-60 sec | %8d | %8d | %8d | %8d |\n",
719 a_xInfoP->stat_fileSameAuthor[VOLINT_STATS_TIME_IDX_0],
720 a_xInfoP->stat_fileDiffAuthor[VOLINT_STATS_TIME_IDX_0],
721 a_xInfoP->stat_dirSameAuthor[VOLINT_STATS_TIME_IDX_0],
722 a_xInfoP->stat_dirDiffAuthor[VOLINT_STATS_TIME_IDX_0]);
724 "1-10 min | %8d | %8d | %8d | %8d |\n",
725 a_xInfoP->stat_fileSameAuthor[VOLINT_STATS_TIME_IDX_1],
726 a_xInfoP->stat_fileDiffAuthor[VOLINT_STATS_TIME_IDX_1],
727 a_xInfoP->stat_dirSameAuthor[VOLINT_STATS_TIME_IDX_1],
728 a_xInfoP->stat_dirDiffAuthor[VOLINT_STATS_TIME_IDX_1]);
730 "10min-1hr | %8d | %8d | %8d | %8d |\n",
731 a_xInfoP->stat_fileSameAuthor[VOLINT_STATS_TIME_IDX_2],
732 a_xInfoP->stat_fileDiffAuthor[VOLINT_STATS_TIME_IDX_2],
733 a_xInfoP->stat_dirSameAuthor[VOLINT_STATS_TIME_IDX_2],
734 a_xInfoP->stat_dirDiffAuthor[VOLINT_STATS_TIME_IDX_2]);
736 "1hr-1day | %8d | %8d | %8d | %8d |\n",
737 a_xInfoP->stat_fileSameAuthor[VOLINT_STATS_TIME_IDX_3],
738 a_xInfoP->stat_fileDiffAuthor[VOLINT_STATS_TIME_IDX_3],
739 a_xInfoP->stat_dirSameAuthor[VOLINT_STATS_TIME_IDX_3],
740 a_xInfoP->stat_dirDiffAuthor[VOLINT_STATS_TIME_IDX_3]);
742 "1day-1wk | %8d | %8d | %8d | %8d |\n",
743 a_xInfoP->stat_fileSameAuthor[VOLINT_STATS_TIME_IDX_4],
744 a_xInfoP->stat_fileDiffAuthor[VOLINT_STATS_TIME_IDX_4],
745 a_xInfoP->stat_dirSameAuthor[VOLINT_STATS_TIME_IDX_4],
746 a_xInfoP->stat_dirDiffAuthor[VOLINT_STATS_TIME_IDX_4]);
748 "> 1wk | %8d | %8d | %8d | %8d |\n",
749 a_xInfoP->stat_fileSameAuthor[VOLINT_STATS_TIME_IDX_5],
750 a_xInfoP->stat_fileDiffAuthor[VOLINT_STATS_TIME_IDX_5],
751 a_xInfoP->stat_dirSameAuthor[VOLINT_STATS_TIME_IDX_5],
752 a_xInfoP->stat_dirDiffAuthor[VOLINT_STATS_TIME_IDX_5]);
754 " |-------------------------------------------|\n");
755 } /*Volume status OK*/
757 if (a_xInfoP->status == VBUSY) {
759 qPut(&busyHead, a_xInfoP->volid);
761 fprintf(STDOUT, "**** Volume %lu is busy ****\n",
762 (unsigned long) a_xInfoP->volid);
766 qPut(¬okHead, a_xInfoP->volid);
768 fprintf(STDOUT, "**** Could not attach volume %lu ****\n",
769 (unsigned long) a_xInfoP->volid);
771 fprintf(STDOUT,"\n");
777 if (a_xInfoP->status == VOK) {
778 fprintf(STDOUT, "%-32s ", a_xInfoP->name);
779 fprintf(STDOUT, "%10lu ", (unsigned long) a_xInfoP->volid);
780 if (a_xInfoP->type == 0) fprintf(STDOUT, "RW ");
781 if (a_xInfoP->type == 1) fprintf(STDOUT, "RO ");
782 if (a_xInfoP->type == 2) fprintf(STDOUT, "BK ");
783 fprintf(STDOUT, "%10d K ", a_xInfoP->size);
784 if(a_xInfoP->inUse == 1) {
785 fprintf(STDOUT, "On-line");
788 fprintf(STDOUT, "Off-line");
791 fprintf(STDOUT, "\n");
794 if (a_xInfoP->status == VBUSY) {
796 qPut(&busyHead, a_xInfoP->volid);
798 fprintf(STDOUT,"**** Volume %lu is busy ****\n",
799 (unsigned long) a_xInfoP->volid);
803 qPut(¬okHead, a_xInfoP->volid);
805 fprintf(STDOUT,"**** Could not attach volume %lu ****\n",
806 (unsigned long) a_xInfoP->volid);
808 } /*Default listing*/
811 #ifdef FULL_LISTVOL_SWITCH
812 static void DisplayFormat2(server, partition, pntr)
813 long server, partition;
816 static long server_cache = -1, partition_cache = -1;
817 static char hostname[256],
821 if (server != server_cache) {
825 strcpy(hostname, hostutil_GetNameByINet(server));
826 strcpy(address, inet_ntoa(s));
827 server_cache = server;
829 if (partition != partition_cache) {
830 MapPartIdIntoName(partition, pname);
831 partition_cache = partition;
833 fprintf(STDOUT, "name\t\t%s\n", pntr->name);
834 fprintf(STDOUT, "id\t\t%lu\n", pntr->volid);
835 fprintf(STDOUT, "serv\t\t%s\t%s\n", address, hostname);
836 fprintf(STDOUT, "part\t\t%s\n", pname);
837 switch (pntr->status) {
839 fprintf(STDOUT, "status\t\tOK\n");
842 fprintf(STDOUT, "status\t\tBUSY\n");
845 fprintf(STDOUT, "status\t\tUNATTACHABLE\n");
848 fprintf(STDOUT, "backupID\t%lu\n", pntr->backupID);
849 fprintf(STDOUT, "parentID\t%lu\n", pntr->parentID);
850 fprintf(STDOUT, "cloneID\t\t%lu\n", pntr->cloneID);
851 fprintf(STDOUT, "inUse\t\t%s\n", pntr->inUse ? "Y" : "N");
852 fprintf(STDOUT, "needsSalvaged\t%s\n", pntr->needsSalvaged ? "Y" : "N");
853 /* 0xD3 is from afs/volume.h since I had trouble including the file */
854 fprintf(STDOUT, "destroyMe\t%s\n", pntr->destroyMe == 0xD3 ? "Y" : "N");
855 switch (pntr->type) {
857 fprintf(STDOUT, "type\t\tRW\n");
860 fprintf(STDOUT, "type\t\tRO\n");
863 fprintf(STDOUT, "type\t\tBK\n");
866 fprintf(STDOUT, "type\t\t?\n");
869 fprintf(STDOUT, "creationDate\t%-9lu\t%s", pntr->creationDate, ctime(&pntr->creationDate));
870 fprintf(STDOUT, "accessDate\t%-9lu\t%s", pntr->accessDate, ctime(&pntr->accessDate));
871 fprintf(STDOUT, "updateDate\t%-9lu\t%s", pntr->updateDate, ctime(&pntr->updateDate));
872 fprintf(STDOUT, "backupDate\t%-9lu\t%s", pntr->backupDate, ctime(&pntr->backupDate));
873 fprintf(STDOUT, "copyDate\t%-9lu\t%s", pntr->copyDate, ctime(&pntr->copyDate));
874 fprintf(STDOUT, "flags\t\t%#lx\t(Optional)\n", pntr->flags);
875 fprintf(STDOUT, "diskused\t%u\n", pntr->size);
876 fprintf(STDOUT, "maxquota\t%u\n", pntr->maxquota);
877 fprintf(STDOUT, "minquota\t%lu\t(Optional)\n", pntr->spare0);
878 fprintf(STDOUT, "filecount\t%u\n", pntr->filecount);
879 fprintf(STDOUT, "dayUse\t\t%u\n", pntr->dayUse);
880 fprintf(STDOUT, "weekUse\t\t%lu\t(Optional)\n", pntr->spare1);
881 fprintf(STDOUT, "spare2\t\t%lu\t(Optional)\n", pntr->spare2);
882 fprintf(STDOUT, "spare3\t\t%lu\t(Optional)\n", pntr->spare3);
886 static void DisplayVolumes2(server, partition, pntr, count)
888 long server, partition, count;
892 for (i = 0; i < count; i++) {
893 fprintf(STDOUT, "BEGIN_OF_ENTRY\n");
894 DisplayFormat2(server, partition, pntr);
895 fprintf(STDOUT, "END_OF_ENTRY\n\n");
900 #endif /* FULL_LISTVOL_SWITCH */
902 static void DisplayVolumes(server,part,pntr,count,longlist,fast,quiet)
903 afs_int32 server,part;
905 afs_int32 count,longlist,fast;
908 int totalOK,totalNotOK,totalBusy, i;
916 for(i = 0; i < count; i++){
917 DisplayFormat(pntr,server,part,&totalOK,&totalNotOK,&totalBusy,fast,longlist,0);
921 while(busyHead.count){
922 qGet(&busyHead,&volid);
923 fprintf(STDOUT,"**** Volume %lu is busy ****\n",
924 (unsigned long) volid);
928 while(notokHead.count){
929 qGet(¬okHead,&volid);
930 fprintf(STDOUT,"**** Could not attach volume %lu ****\n",
931 (unsigned long) volid);
935 fprintf(STDOUT,"\n");
937 fprintf(STDOUT,"Total volumes onLine %d ; Total volumes offLine %d ; Total busy %d\n\n",totalOK,totalNotOK,totalBusy);
942 /*------------------------------------------------------------------------
943 * PRIVATE XDisplayVolumes
946 * Display extended volume information.
949 * a_servID : Pointer to the Rx call we're performing.
950 * a_partID : Partition for which we want the extended list.
951 * a_xInfoP : Ptr to extended volume info.
952 * a_count : Number of volume records contained above.
953 * a_int32 : Int32 listing generated?
954 * a_fast : Fast listing generated?
955 * a_quiet : Quiet listing generated?
961 * Nothing interesting.
965 *------------------------------------------------------------------------*/
967 static void XDisplayVolumes(a_servID, a_partID, a_xInfoP,
968 a_count, a_int32, a_fast, a_quiet)
971 volintXInfo *a_xInfoP;
977 { /*XDisplayVolumes*/
979 int totalOK; /*Total OK volumes*/
980 int totalNotOK; /*Total screwed volumes*/
981 int totalBusy; /*Total busy volumes*/
982 int i; /*Loop variable*/
983 afs_int32 volid; /*Current volume ID*/
986 * Initialize counters and (global!!) queues.
995 * Display each volume in the list.
997 for(i = 0; i < a_count; i++) {
998 XDisplayFormat(a_xInfoP,
1011 * If any volumes were found to be busy or screwed, display them.
1014 while (busyHead.count) {
1015 qGet(&busyHead, &volid);
1016 fprintf(STDOUT, "**** Volume %lu is busy ****\n",
1017 (unsigned long) volid);
1021 while (notokHead.count) {
1022 qGet(¬okHead, &volid);
1023 fprintf(STDOUT, "**** Could not attach volume %lu ****\n",
1024 (unsigned long) volid);
1029 fprintf(STDOUT, "\n");
1032 "Total volumes: %d on-line, %d off-line, %d busyd\n\n",
1033 totalOK, totalNotOK, totalBusy);
1037 } /*XDisplayVolumes*/
1039 /* set <server> and <part> to the correct values depending on
1040 * <voltype> and <entry> */
1041 static void GetServerAndPart (entry, voltype, server, part, previdx)
1042 struct nvldbentry *entry;
1043 afs_int32 *server,*part;
1047 int i, istart, vtype;
1052 /* Doesn't check for non-existance of backup volume */
1053 if ((voltype == RWVOL) || (voltype == BACKVOL)) {
1055 istart = 0; /* seach the entire entry */
1058 /* Seach from beginning of entry or pick up where we left off */
1059 istart = ((*previdx < 0) ? 0 : *previdx+1);
1062 for (i = istart; i < entry->nServers; i++) {
1063 if (entry->serverFlags[i] & vtype) {
1064 *server = entry->serverNumber[i];
1065 *part = entry->serverPartition[i];
1071 /* Didn't find any, return -1 */
1076 static void PostVolumeStats(entry)
1077 struct nvldbentry *entry;
1079 SubEnumerateEntry(entry);
1080 /* Check for VLOP_ALLOPERS */
1081 if (entry->flags & VLOP_ALLOPERS)
1082 fprintf(STDOUT," Volume is currently LOCKED \n");
1086 /*------------------------------------------------------------------------
1087 * PRIVATE XVolumeStats
1090 * Display extended volume information.
1093 * a_xInfoP : Ptr to extended volume info.
1094 * a_entryP : Ptr to the volume's VLDB entry.
1095 * a_srvID : Server ID.
1096 * a_partID : Partition ID.
1097 * a_volType : Type of volume to print.
1103 * Nothing interesting.
1107 *------------------------------------------------------------------------*/
1109 static void XVolumeStats(a_xInfoP, a_entryP, a_srvID, a_partID, a_volType)
1110 volintXInfo *a_xInfoP;
1111 struct nvldbentry *a_entryP;
1118 int totalOK, totalNotOK, totalBusy; /*Dummies - we don't really count here*/
1120 XDisplayFormat(a_xInfoP, /*Ptr to extended volume info*/
1121 a_srvID, /*Server ID to print*/
1122 a_partID, /*Partition ID to print*/
1123 &totalOK, /*Ptr to total-OK counter*/
1124 &totalNotOK, /*Ptr to total-screwed counter*/
1125 &totalBusy, /*Ptr to total-busy counter*/
1126 0, /*Don't do a fast listing*/
1127 1, /*Do a long listing*/
1128 1); /*Show volume problems*/
1133 static void VolumeStats(pntr,entry,server,part,voltype)
1135 struct nvldbentry *entry;
1137 afs_int32 server,part;
1139 int totalOK,totalNotOK,totalBusy;
1140 afs_int32 vcode,vcode2;
1142 DisplayFormat(pntr,server,part,&totalOK,&totalNotOK,&totalBusy,0,1,1);
1146 /* command to forcibly remove a volume */
1147 static NukeVolume(as)
1148 register struct cmd_syndesc *as; {
1149 register afs_int32 code;
1150 afs_int32 volID, err;
1155 server = GetServer(tp = as->parms[0].items->data);
1157 fprintf(STDERR,"vos: server '%s' not found in host table\n", tp);
1161 partID = volutil_GetPartitionID(tp = as->parms[1].items->data);
1163 fprintf(STDERR, "vos: could not parse '%s' as a partition name", tp);
1167 volID = vsu_GetVolumeID(tp = as->parms[2].items->data, cstruct, &err);
1169 if (err) PrintError("", err);
1170 else fprintf(STDERR, "vos: could not parse '%s' as a numeric volume ID", tp);
1174 fprintf(STDOUT, "vos: forcibly removing all traces of volume %d, please wait...", volID);
1176 code = UV_NukeVolume(server, partID, volID);
1178 fprintf(STDOUT, "done.\n");
1180 fprintf(STDOUT, "failed with code %d.\n", code);
1185 /*------------------------------------------------------------------------
1186 * PRIVATE ExamineVolume
1189 * Routine used to examine a single volume, contacting the VLDB as
1190 * well as the Volume Server.
1193 * as : Ptr to parsed command line arguments.
1196 * 0 for a successful operation,
1197 * Otherwise, one of the ubik or VolServer error values.
1200 * Nothing interesting.
1204 *------------------------------------------------------------------------
1206 static ExamineVolume(as)
1207 register struct cmd_syndesc *as;
1209 struct nvldbentry entry;
1210 afs_int32 vcode = 0;
1211 volintInfo *pntr = (volintInfo *)0;
1212 volintXInfo *xInfoP = (volintXInfo *)0;
1214 afs_int32 code, err, error = 0;
1215 int voltype, foundserv = 0, foundentry = 0;
1216 afs_int32 aserver, apart;
1218 int wantExtendedInfo; /*Do we want extended vol info?*/
1220 wantExtendedInfo = (as->parms[1].items ? 1 : 0); /* -extended */
1222 volid = vsu_GetVolumeID(as->parms[0].items->data, cstruct, &err); /* -id */
1224 if (err) PrintError("", err);
1225 else fprintf(STDERR, "Unknown volume ID or name '%s'\n", as->parms[0].items->data);
1230 fprintf(STDOUT, "Fetching VLDB entry for %lu .. ",
1231 (unsigned long) volid);
1234 vcode = VLDB_GetEntryByID (volid, -1, &entry);
1236 fprintf(STDERR, "Could not fetch the entry for volume number %lu from VLDB \n",
1237 (unsigned long) volid);
1241 fprintf(STDOUT, "done\n");
1242 MapHostToNetwork(&entry);
1244 if (entry.volumeId[RWVOL] == volid)
1246 else if (entry.volumeId[BACKVOL] == volid)
1248 else /* (entry.volumeId[ROVOL] == volid) */
1251 do { /* do {...} while (voltype == ROVOL) */
1252 /* Get the entry for the volume. If its a RW vol, get the RW entry.
1253 * It its a BK vol, get the RW entry (even if VLDB may say the BK doen't exist).
1254 * If its a RO vol, get the next RO entry.
1256 GetServerAndPart(&entry, ((voltype == ROVOL) ? ROVOL : RWVOL), &aserver, &apart, &previdx);
1257 if (previdx == -1) { /* searched all entries */
1259 fprintf(STDERR,"Volume %s does not exist in VLDB\n\n", as->parms[0].items->data);
1266 /* Get information about the volume from the server */
1268 fprintf(STDOUT,"Getting volume listing from the server %s .. ",
1269 hostutil_GetNameByINet(aserver));
1272 if (wantExtendedInfo)
1273 code = UV_XListOneVolume(aserver, apart, volid, &xInfoP);
1275 code = UV_ListOneVolume(aserver, apart, volid, &pntr);
1277 fprintf(STDOUT,"done\n");
1281 if (code == ENODEV) {
1282 if ((voltype == BACKVOL) && !(entry.flags & BACK_EXISTS)) {
1283 /* The VLDB says there is no backup volume and its not on disk */
1284 fprintf(STDERR, "Volume %s does not exist\n", as->parms[0].items->data);
1287 fprintf(STDERR, "Volume does not exist on server %s as indicated by the VLDB\n",
1288 hostutil_GetNameByINet(aserver));
1291 PrintDiagnostics("examine", code);
1293 fprintf(STDOUT, "\n");
1296 if (wantExtendedInfo)
1297 XVolumeStats(xInfoP, &entry, aserver, apart, voltype);
1299 #ifdef FULL_LISTVOL_SWITCH
1300 if (as->parms[2].items) {
1301 DisplayFormat2(aserver, apart, pntr);
1302 EnumerateEntry(&entry);
1304 #endif /* FULL_LISTVOL_SWITCH */
1305 VolumeStats(pntr, &entry, aserver, apart, voltype);
1307 if ((voltype == BACKVOL) && !(entry.flags & BACK_EXISTS)) {
1308 /* The VLDB says there is no backup volume yet we found one on disk */
1309 fprintf(STDERR, "Volume %s does not exist in VLDB\n", as->parms[0].items->data);
1314 if (pntr) free(pntr);
1315 if (xInfoP) free(xInfoP);
1316 } while (voltype == ROVOL);
1319 fprintf(STDERR,"Dump only information from VLDB\n\n");
1320 fprintf(STDOUT,"%s \n", entry.name); /* PostVolumeStats doesn't print name */
1322 PostVolumeStats(&entry);
1327 /*------------------------------------------------------------------------
1331 * Routine used to change the status of a single volume.
1334 * as : Ptr to parsed command line arguments.
1337 * 0 for a successful operation,
1338 * Otherwise, one of the ubik or VolServer error values.
1341 * Nothing interesting.
1345 *------------------------------------------------------------------------
1347 static SetFields(as)
1348 register struct cmd_syndesc *as;
1350 struct nvldbentry entry;
1351 afs_int32 vcode = 0;
1354 afs_int32 code, err;
1355 afs_int32 aserver, apart;
1358 volid = vsu_GetVolumeID(as->parms[0].items->data, cstruct, &err); /* -id */
1360 if (err) PrintError("", err);
1361 else fprintf(STDERR, "Unknown volume ID or name '%s'\n", as->parms[0].items->data);
1365 code = VLDB_GetEntryByID (volid, RWVOL, &entry);
1367 fprintf(STDERR, "Could not fetch the entry for volume number %lu from VLDB \n",
1368 (unsigned long) volid);
1371 MapHostToNetwork(&entry);
1373 GetServerAndPart(&entry, RWVOL, &aserver, &apart, &previdx);
1374 if (previdx == -1) {
1375 fprintf(STDERR,"Volume %s does not exist in VLDB\n\n", as->parms[0].items->data);
1379 memset(&info, 0, sizeof(info));
1390 if (as->parms[1].items) {
1392 code = util_GetInt32(as->parms[1].items->data, &info.maxquota);
1394 fprintf(STDERR,"invalid quota value\n");
1398 if (as->parms[2].items) {
1402 code = UV_SetVolumeInfo(aserver, apart, volid, &info);
1404 fprintf(STDERR,"Could not update volume info fields for volume number %lu\n",
1405 (unsigned long) volid);
1409 /*------------------------------------------------------------------------
1413 * Brings a volume online.
1416 * as : Ptr to parsed command line arguments.
1419 * 0 for a successful operation,
1422 * Nothing interesting.
1426 *------------------------------------------------------------------------
1428 static volOnline(as)
1429 register struct cmd_syndesc *as;
1431 afs_int32 server, partition, volid;
1432 afs_int32 code, err=0;
1434 server = GetServer(as->parms[0].items->data);
1436 fprintf(STDERR,"vos: server '%s' not found in host table\n", as->parms[0].items->data);
1440 partition = volutil_GetPartitionID(as->parms[1].items->data);
1441 if (partition < 0) {
1442 fprintf(STDERR,"vos: could not interpret partition name '%s'\n", as->parms[1].items->data);
1446 volid = vsu_GetVolumeID(as->parms[2].items->data, cstruct, &err); /* -id */
1448 if (err) PrintError("", err);
1449 else fprintf(STDERR, "Unknown volume ID or name '%s'\n", as->parms[0].items->data);
1453 code = UV_SetVolume(server, partition, volid, ITOffline, 0/*online*/, 0/*sleep*/);
1455 fprintf(STDERR, "Failed to set volume. Code = %d\n", code);
1462 /*------------------------------------------------------------------------
1463 * PRIVATE volOffline
1466 * Brings a volume offline.
1469 * as : Ptr to parsed command line arguments.
1472 * 0 for a successful operation,
1475 * Nothing interesting.
1479 *------------------------------------------------------------------------
1481 static int volOffline(register struct cmd_syndesc *as)
1483 afs_int32 server, partition, volid;
1484 afs_int32 code, err=0;
1485 afs_int32 transflag, sleeptime, transdone;
1487 server = GetServer(as->parms[0].items->data);
1489 fprintf(STDERR,"vos: server '%s' not found in host table\n", as->parms[0].items->data);
1493 partition = volutil_GetPartitionID(as->parms[1].items->data);
1494 if (partition < 0) {
1495 fprintf(STDERR,"vos: could not interpret partition name '%s'\n", as->parms[1].items->data);
1499 volid = vsu_GetVolumeID(as->parms[2].items->data, cstruct, &err); /* -id */
1501 if (err) PrintError("", err);
1502 else fprintf(STDERR, "Unknown volume ID or name '%s'\n", as->parms[0].items->data);
1506 transflag = (as->parms[4].items ? ITBusy : ITOffline);
1507 sleeptime = (as->parms[3].items ? atol(as->parms[3].items->data) : 0);
1508 transdone = (sleeptime ? 0/*online*/ : VTOutOfService);
1509 if (as->parms[4].items && !as->parms[3].items) {
1510 fprintf(STDERR,"-sleep option must be used with -busy flag\n");
1514 code = UV_SetVolume(server, partition, volid, transflag, transdone, sleeptime);
1516 fprintf(STDERR, "Failed to set volume. Code = %d\n", code);
1523 static int CreateVolume(register struct cmd_syndesc *as)
1527 afs_int32 volid,code;
1528 struct nvldbentry entry;
1533 tserver = GetServer(as->parms[0].items->data);
1535 fprintf(STDERR,"vos: host '%s' not found in host table\n",as->parms[0].items->data );
1538 pname = volutil_GetPartitionID(as->parms[1].items->data);
1540 fprintf(STDERR,"vos: could not interpret partition name '%s'\n",as->parms[1].items->data );
1543 if (!IsPartValid(pname,tserver,&code)){/*check for validity of the partition */
1544 if(code) PrintError("",code);
1545 else fprintf(STDERR,"vos : partition %s does not exist on the server\n",as->parms[1].items->data);
1548 if(!ISNAMEVALID(as->parms[2].items->data)) {
1549 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);
1552 if(!VolNameOK(as->parms[2].items->data)){
1553 fprintf(STDERR,"Illegal volume name %s, should not end in .readonly or .backup\n",as->parms[2].items->data);
1556 if(IsNumeric(as->parms[2].items->data)){
1557 fprintf(STDERR,"Illegal volume name %s, should not be a number\n",as->parms[2].items->data);
1560 vcode = VLDB_GetEntryByName(as->parms[2].items->data, &entry);
1562 fprintf(STDERR,"Volume %s already exists\n",as->parms[2].items->data);
1563 PrintDiagnostics("create", code);
1567 if (as->parms[3].items) {
1568 if (!IsNumeric(as->parms[3].items->data)){
1569 fprintf(STDERR,"Initial quota %s should be numeric.\n", as->parms[3].items->data);
1573 code = util_GetInt32(as->parms[3].items->data, "a);
1575 fprintf(STDERR,"vos: bad integer specified for quota.\n");
1580 code = UV_CreateVolume2(tserver, pname,as->parms[2].items->data,
1581 quota, 0, 0, 0, 0, &volid);
1583 PrintDiagnostics("create", code);
1586 MapPartIdIntoName(pname, part);
1587 fprintf(STDOUT,"Volume %lu created on partition %s of %s\n",
1588 (unsigned long) volid, part,as->parms[0].items->data );
1593 static afs_int32 DeleteAll(entry)
1594 struct nvldbentry *entry;
1597 afs_int32 error, code, curserver, curpart, volid;
1599 MapHostToNetwork(entry);
1601 for(i=0; i < entry->nServers; i++){
1602 curserver = entry->serverNumber[i];
1603 curpart = entry->serverPartition[i];
1604 if(entry->serverFlags[i] & ITSROVOL){
1605 volid = entry->volumeId[ROVOL];
1608 volid = entry->volumeId[RWVOL];
1610 code = UV_DeleteVolume(curserver,curpart,volid);
1617 static DeleteVolume(as)
1618 struct cmd_syndesc *as;
1620 afs_int32 err, code = 0;
1621 afs_int32 server = 0, partition = -1, volid;
1625 if (as->parms[0].items) {
1626 server = GetServer(as->parms[0].items->data);
1628 fprintf(STDERR,"vos: server '%s' not found in host table\n",
1629 as->parms[0].items->data);
1634 if (as->parms[1].items) {
1635 partition = volutil_GetPartitionID(as->parms[1].items->data);
1636 if (partition < 0) {
1637 fprintf(STDERR,"vos: could not interpret partition name '%s'\n",
1638 as->parms[1].items->data );
1642 /* Check for validity of the partition */
1643 if (!IsPartValid(partition, server, &code)) {
1645 PrintError("", code);
1647 fprintf(STDERR,"vos : partition %s does not exist on the server\n",
1648 as->parms[1].items->data);
1654 volid = vsu_GetVolumeID(as->parms[2].items->data, cstruct, &err);
1656 fprintf(STDERR, "Can't find volume name '%s' in VLDB\n",
1657 as->parms[2].items->data);
1658 if (err) PrintError("", err);
1662 /* If the server or partition option are not complete, try to fill
1663 * them in from the VLDB entry.
1665 if ((partition == -1) || !server) {
1666 struct nvldbentry entry;
1668 code = VLDB_GetEntryByID(volid, -1, &entry);
1670 fprintf(STDERR,"Could not fetch the entry for volume %lu from VLDB\n",
1671 (unsigned long) volid);
1672 PrintError("",code);
1676 if (((volid == entry.volumeId[RWVOL]) && (entry.flags & RW_EXISTS)) ||
1677 ((volid == entry.volumeId[BACKVOL]) && (entry.flags & BACK_EXISTS)) ) {
1678 idx = Lp_GetRwIndex(&entry);
1680 (server && (server != entry.serverNumber[idx])) ||
1681 ((partition != -1) && (partition != entry.serverPartition[idx])) ) {
1682 fprintf(STDERR,"VLDB: Volume '%s' no match\n", as->parms[2].items->data);
1686 else if ((volid == entry.volumeId[ROVOL]) && (entry.flags & RO_EXISTS)) {
1687 for (idx=-1,j=0; j<entry.nServers; j++) {
1688 if (entry.serverFlags[j] != ITSROVOL) continue;
1690 if ( ((server == 0) || (server == entry.serverNumber[j])) &&
1691 ((partition == -1) || (partition == entry.serverPartition[j])) ) {
1693 fprintf(STDERR,"VLDB: Volume '%s' matches more than one RO\n",
1694 as->parms[2].items->data);
1701 fprintf(STDERR,"VLDB: Volume '%s' no match\n", as->parms[2].items->data);
1706 fprintf(STDERR,"VLDB: Volume '%s' no match\n", as->parms[2].items->data);
1710 server = htonl(entry.serverNumber[idx]);
1711 partition = entry.serverPartition[idx];
1715 code = UV_DeleteVolume(server, partition, volid);
1717 PrintDiagnostics("remove", code);
1721 MapPartIdIntoName(partition, pname);
1722 fprintf(STDOUT,"Volume %lu on partition %s server %s deleted\n",
1723 (unsigned long) volid, pname, hostutil_GetNameByINet(server));
1727 #define TESTM 0 /* set for move space tests, clear for production */
1728 static MoveVolume(as)
1729 register struct cmd_syndesc *as;
1732 afs_int32 volid, fromserver, toserver, frompart, topart,code, err;
1733 char fromPartName[10], toPartName[10];
1735 struct diskPartition partition; /* for space check */
1738 volid = vsu_GetVolumeID(as->parms[0].items->data, cstruct, &err);
1740 if (err) PrintError("", err);
1741 else fprintf(STDERR, "vos: can't find volume ID or name '%s'\n",
1742 as->parms[0].items->data);
1745 fromserver = GetServer(as->parms[1].items->data);
1746 if (fromserver == 0) {
1747 fprintf(STDERR,"vos: server '%s' not found in host table\n", as->parms[1].items->data);
1750 toserver = GetServer(as->parms[3].items->data);
1751 if (toserver == 0) {
1752 fprintf(STDERR,"vos: server '%s' not found in host table\n", as->parms[3].items->data);
1755 frompart = volutil_GetPartitionID(as->parms[2].items->data);
1757 fprintf(STDERR,"vos: could not interpret partition name '%s'\n", as->parms[2].items->data);
1760 if (!IsPartValid(frompart,fromserver,&code)){/*check for validity of the partition */
1761 if(code) PrintError("",code);
1762 else fprintf(STDERR,"vos : partition %s does not exist on the server\n",as->parms[2].items->data);
1765 topart = volutil_GetPartitionID(as->parms[4].items->data);
1767 fprintf(STDERR,"vos: could not interpret partition name '%s'\n",as->parms[4].items->data);
1770 if (!IsPartValid(topart,toserver,&code)){/*check for validity of the partition */
1771 if(code) PrintError("",code);
1772 else fprintf(STDERR,"vos : partition %s does not exist on the server\n",as->parms[4].items->data);
1777 check source partition for space to clone volume
1780 MapPartIdIntoName(topart,toPartName);
1781 MapPartIdIntoName(frompart, fromPartName);
1784 check target partition for space to move volume
1787 code=UV_PartitionInfo(toserver,toPartName,&partition);
1790 fprintf(STDERR,"vos: cannot access partition %s\n",toPartName);
1794 fprintf(STDOUT,"target partition %s free space %d\n",
1795 toPartName,partition.free);
1798 code=UV_ListOneVolume(fromserver,frompart,volid,&p);
1801 fprintf(STDERR,"vos:cannot access volume %lu\n",
1802 (unsigned long) volid);
1807 fprintf(STDOUT,"volume %lu size %d\n",
1808 (unsigned long) volid,p->size);
1809 if(partition.free<=p->size)
1811 fprintf(STDERR,"vos: no space on target partition %s to move volume %lu\n",
1812 toPartName,(unsigned long) volid);
1820 fprintf(STDOUT,"size test - don't do move\n");
1824 /* successful move still not guaranteed but shoot for it */
1826 code = UV_MoveVolume(volid, fromserver, frompart, toserver, topart);
1828 PrintDiagnostics("move", code);
1831 MapPartIdIntoName(topart,toPartName);
1832 MapPartIdIntoName(frompart, fromPartName);
1833 fprintf(STDOUT,"Volume %lu moved from %s %s to %s %s \n",
1834 (unsigned long) volid,
1835 as->parms[1].items->data,fromPartName,
1836 as->parms[3].items->data,toPartName);
1841 static CopyVolume(as)
1842 register struct cmd_syndesc *as;
1844 afs_int32 volid, fromserver, toserver, frompart, topart,code, err;
1845 char fromPartName[10], toPartName[10], *tovolume;
1846 struct nvldbentry entry;
1847 struct diskPartition partition; /* for space check */
1850 volid = vsu_GetVolumeID(as->parms[0].items->data, cstruct, &err);
1852 if (err) PrintError("", err);
1853 else fprintf(STDERR, "vos: can't find volume ID or name '%s'\n",
1854 as->parms[0].items->data);
1857 fromserver = GetServer(as->parms[1].items->data);
1858 if (fromserver == 0) {
1859 fprintf(STDERR,"vos: server '%s' not found in host table\n", as->parms[1].items->data);
1863 toserver = GetServer(as->parms[4].items->data);
1864 if (toserver == 0) {
1865 fprintf(STDERR,"vos: server '%s' not found in host table\n", as->parms[3].items->data);
1869 tovolume = as->parms[3].items->data;
1870 if(!ISNAMEVALID(tovolume)) {
1871 fprintf(STDERR,"vos: the name of the root volume %s exceeds the size limit of %d\n",
1872 tovolume,VOLSER_OLDMAXVOLNAME - 10);
1875 if(!VolNameOK(tovolume)){
1876 fprintf(STDERR,"Illegal volume name %s, should not end in .readonly or .backup\n",tovolume);
1879 if(IsNumeric(tovolume)){
1880 fprintf(STDERR,"Illegal volume name %s, should not be a number\n",tovolume);
1883 code = VLDB_GetEntryByName(tovolume, &entry);
1885 fprintf(STDERR,"Volume %s already exists\n",tovolume);
1886 PrintDiagnostics("copy", code);
1890 frompart = volutil_GetPartitionID(as->parms[2].items->data);
1892 fprintf(STDERR,"vos: could not interpret partition name '%s'\n", as->parms[2].items->data);
1895 if (!IsPartValid(frompart,fromserver,&code)){ /*check for validity of the partition */
1896 if(code) PrintError("",code);
1897 else fprintf(STDERR,"vos : partition %s does not exist on the server\n",as->parms[2].items->data);
1901 topart = volutil_GetPartitionID(as->parms[5].items->data);
1903 fprintf(STDERR,"vos: could not interpret partition name '%s'\n",as->parms[4].items->data);
1906 if (!IsPartValid(topart,toserver,&code)){ /*check for validity of the partition */
1907 if(code) PrintError("",code);
1908 else fprintf(STDERR,"vos : partition %s does not exist on the server\n",as->parms[4].items->data);
1913 * check source partition for space to clone volume
1916 MapPartIdIntoName(topart,toPartName);
1917 MapPartIdIntoName(frompart, fromPartName);
1920 * check target partition for space to move volume
1923 code=UV_PartitionInfo(toserver,toPartName,&partition);
1926 fprintf(STDERR,"vos: cannot access partition %s\n",toPartName);
1930 fprintf(STDOUT,"target partition %s free space %d\n",
1931 toPartName,partition.free);
1934 code=UV_ListOneVolume(fromserver,frompart,volid,&p);
1937 fprintf(STDERR,"vos:cannot access volume %lu\n",
1938 (unsigned long) volid);
1943 if(partition.free<=p->size)
1945 fprintf(STDERR,"vos: no space on target partition %s to copy volume %lu\n",
1946 toPartName,(unsigned long) volid);
1952 /* successful copy still not guaranteed but shoot for it */
1954 code = UV_CopyVolume(volid, fromserver, frompart, tovolume, toserver, topart);
1956 PrintDiagnostics("copy", code);
1959 MapPartIdIntoName(topart,toPartName);
1960 MapPartIdIntoName(frompart, fromPartName);
1961 fprintf(STDOUT,"Volume %lu copied from %s %s to %s on %s %s \n",
1962 (unsigned long) volid,
1963 as->parms[1].items->data,fromPartName,
1964 tovolume, as->parms[4].items->data,toPartName);
1970 static BackupVolume(as)
1971 register struct cmd_syndesc *as;
1973 afs_int32 avolid, aserver, apart,vtype,code, err;
1974 struct nvldbentry entry;
1976 afs_int32 buvolid,buserver,bupart,butype;
1977 struct nvldbentry buentry;
1978 struct rx_connection *conn;
1980 struct nvldbentry store;
1982 avolid = vsu_GetVolumeID(as->parms[0].items->data, cstruct, &err);
1984 if (err) PrintError("", err);
1985 else fprintf(STDERR, "vos: can't find volume ID or name '%s'\n",
1986 as->parms[0].items->data);
1989 code = GetVolumeInfo( avolid,&aserver, &apart,&vtype,&entry);
1992 /* verify this is a readwrite volume */
1996 fprintf(STDERR,"%s not RW volume\n",as->parms[0].items->data);
2000 /* is there a backup volume already? */
2002 if(entry.flags & BACK_EXISTS)
2004 /* yep, where is it? */
2006 buvolid=entry.volumeId[BACKVOL];
2007 code=GetVolumeInfo(buvolid,&buserver,&bupart,&butype,&buentry);
2011 code = VLDB_IsSameAddrs(buserver, aserver, &err);
2013 fprintf(STDERR,"Failed to get info about server's %d address(es) from vlserver; aborting call!\n", buserver);
2018 fprintf(STDERR,"FATAL ERROR: backup volume %lu exists on server %lu\n",
2019 (unsigned long) buvolid,
2020 (unsigned long) buserver);
2025 /* nope, carry on */
2027 code = UV_BackupVolume(aserver, apart, avolid);
2030 PrintDiagnostics("backup", code);
2033 fprintf(STDOUT,"Created backup volume for %s \n",as->parms[0].items->data);
2036 static ReleaseVolume(as)
2037 register struct cmd_syndesc *as;
2040 struct nvldbentry entry;
2041 afs_int32 avolid, aserver, apart,vtype,code, err;
2044 if(as->parms[1].items) force = 1;
2045 avolid = vsu_GetVolumeID(as->parms[0].items->data, cstruct, &err);
2047 if (err) PrintError("", err);
2048 else fprintf(STDERR, "vos: can't find volume '%s'\n", as->parms[0].items->data);
2051 code = GetVolumeInfo( avolid,&aserver, &apart,&vtype,&entry);
2052 if(code) return code;
2054 if (vtype != RWVOL) {
2055 fprintf(STDERR,"%s not a RW volume\n", as->parms[0].items->data);
2059 if(!ISNAMEVALID(entry.name)){
2060 fprintf(STDERR,"Volume name %s is too long, rename before releasing\n",entry.name);
2064 code = UV_ReleaseVolume(avolid, aserver, apart, force);
2066 PrintDiagnostics("release", code);
2069 fprintf(STDOUT,"Released volume %s successfully\n",as->parms[0].items->data );
2072 static DumpVolume(as)
2073 register struct cmd_syndesc *as;
2076 afs_int32 avolid, aserver, apart,voltype,fromdate=0,code, err, i;
2077 char filename[NameLen];
2078 struct nvldbentry entry;
2080 rx_SetRxDeadTime(60 * 10);
2081 for (i = 0; i<MAXSERVERS; i++) {
2082 struct rx_connection *rxConn = ubik_GetRPCConn(cstruct,i);
2083 if (rxConn == 0) break;
2084 rx_SetConnDeadTime(rxConn, rx_connDeadTime);
2085 if (rxConn->service) rxConn->service->connDeadTime = rx_connDeadTime;
2088 avolid = vsu_GetVolumeID(as->parms[0].items->data, cstruct, &err);
2090 if (err) PrintError("", err);
2091 else fprintf(STDERR, "vos: can't find volume '%s'\n", as->parms[0].items->data);
2095 if (as->parms[3].items || as->parms[4].items) {
2096 if (!as->parms[3].items || !as->parms[4].items) {
2097 fprintf(STDERR, "Must specify both -server and -partition options\n");
2100 aserver = GetServer(as->parms[3].items->data);
2102 fprintf(STDERR, "Invalid server name\n");
2105 apart = volutil_GetPartitionID(as->parms[4].items->data);
2107 fprintf(STDERR, "Invalid partition name\n");
2111 code = GetVolumeInfo(avolid, &aserver, &apart, &voltype, &entry);
2112 if (code) return code;
2115 if (as->parms[1].items && strcmp(as->parms[1].items->data,"0")) {
2116 code = ktime_DateToInt32(as->parms[1].items->data, &fromdate);
2118 fprintf(STDERR,"vos: failed to parse date '%s' (error=%d))\n",
2119 as->parms[1].items->data, code);
2123 if(as->parms[2].items){
2124 strcpy(filename,as->parms[2].items->data);
2127 strcpy(filename,"");
2130 if (as->parms[5].items) {
2131 code = UV_DumpClonedVolume(avolid, aserver, apart, fromdate, DumpFunction, filename);
2133 code = UV_DumpVolume(avolid, aserver, apart, fromdate, DumpFunction, filename);
2136 PrintDiagnostics("dump", code);
2139 if(strcmp(filename,""))
2140 fprintf(STDERR,"Dumped volume %s in file %s\n",as->parms[0].items->data, filename);
2142 fprintf(STDERR,"Dumped volume %s in stdout \n",as->parms[0].items->data);
2151 static RestoreVolume(as)
2152 register struct cmd_syndesc *as;
2155 afs_int32 avolid, aserver, apart, code,vcode, err;
2156 afs_int32 aoverwrite = ASK;
2157 int restoreflags, readonly = 0, offline = 0, voltype = RWVOL;
2159 char afilename[NameLen], avolname[VOLSER_MAXVOLNAME +1],apartName[10];
2160 char volname[VOLSER_MAXVOLNAME +1];
2161 struct nvldbentry entry;
2165 if(as->parms[4].items){
2166 avolid = vsu_GetVolumeID(as->parms[4].items->data, cstruct, &err);
2168 if (err) PrintError("", err);
2169 else fprintf(STDERR, "vos: can't find volume '%s'\n", as->parms[4].items->data);
2176 if (as->parms[5].items) {
2177 if ( (strcmp(as->parms[5].items->data, "a") == 0) ||
2178 (strcmp(as->parms[5].items->data, "abort") == 0) ) {
2181 else if ( (strcmp(as->parms[5].items->data, "f") == 0) ||
2182 (strcmp(as->parms[5].items->data, "full") == 0) ) {
2185 else if ( (strcmp(as->parms[5].items->data, "i") == 0) ||
2186 (strcmp(as->parms[5].items->data, "inc") == 0) ||
2187 (strcmp(as->parms[5].items->data, "increment") == 0) ||
2188 (strcmp(as->parms[5].items->data, "incremental") == 0) ) {
2192 fprintf(STDERR, "vos: %s is not a valid argument to -overwrite\n",
2193 as->parms[5].items->data);
2197 if (as->parms[6].items) offline = 1;
2198 if (as->parms[7].items) {
2203 aserver = GetServer(as->parms[0].items->data);
2205 fprintf(STDERR,"vos: server '%s' not found in host table\n", as->parms[0].items->data);
2208 apart = volutil_GetPartitionID(as->parms[1].items->data);
2210 fprintf(STDERR,"vos: could not interpret partition name '%s'\n",as->parms[1].items->data );
2213 if (!IsPartValid(apart,aserver,&code)){/*check for validity of the partition */
2214 if(code) PrintError("",code);
2215 else fprintf(STDERR,"vos : partition %s does not exist on the server\n",as->parms[1].items->data);
2218 strcpy(avolname,as->parms[2].items->data );
2219 if(!ISNAMEVALID(avolname)) {
2220 fprintf(STDERR,"vos: the name of the volume %s exceeds the size limit\n",avolname);
2223 if(!VolNameOK(avolname)){
2224 fprintf(STDERR,"Illegal volume name %s, should not end in .readonly or .backup\n",avolname);
2227 if(as->parms[3].items){
2228 strcpy(afilename,as->parms[3].items->data );
2229 if(!FileExists(afilename)){
2230 fprintf(STDERR,"Can't access file %s\n",afilename);
2235 strcpy(afilename,"");
2238 /* Check if volume exists or not */
2240 vsu_ExtractName(volname,avolname);
2241 vcode = VLDB_GetEntryByName(volname, &entry);
2242 if (vcode) { /* no volume - do a full restore */
2243 restoreflags = RV_FULLRST;
2244 if ( (aoverwrite == INC) || (aoverwrite == ABORT) )
2245 fprintf(STDERR,"Volume does not exist; Will perform a full restore\n");
2248 else if ((!readonly && Lp_GetRwIndex(&entry) == -1) /* RW volume does not exist - do a full */
2249 || (readonly && !Lp_ROMatch(0, 0, &entry))) { /* RO volume does not exist - do a full */
2250 restoreflags = RV_FULLRST;
2251 if ( (aoverwrite == INC) || (aoverwrite == ABORT) )
2252 fprintf(STDERR,"%s Volume does not exist; Will perform a full restore\n",
2253 readonly ? "RO" : "RW");
2256 avolid = entry.volumeId[voltype];
2258 else if (entry.volumeId[voltype] != 0 && entry.volumeId[voltype] != avolid) {
2259 avolid = entry.volumeId[voltype];
2263 else { /* volume exists - do we do a full incremental or abort */
2264 int Oserver, Opart, Otype, vol_elsewhere = 0;
2265 struct nvldbentry Oentry;
2269 avolid = entry.volumeId[voltype];
2271 else if(entry.volumeId[voltype] != 0 && entry.volumeId[voltype] != avolid) {
2272 avolid = entry.volumeId[voltype];
2275 /* A file name was specified - check if volume is on another partition */
2276 vcode = GetVolumeInfo(avolid, &Oserver, &Opart, &Otype, &Oentry);
2279 vcode = VLDB_IsSameAddrs(Oserver, aserver, &err);
2281 fprintf(STDERR,"Failed to get info about server's %d address(es) from vlserver (err=%d); aborting call!\n",
2285 if (!vcode || (Opart != apart)) vol_elsewhere = 1;
2287 if (aoverwrite == ASK) {
2288 if (strcmp(afilename,"") == 0) { /* The file is from standard in */
2289 fprintf(STDERR,"Volume exists and no -overwrite option specified; Aborting restore command\n");
2293 /* Ask what to do */
2294 if (vol_elsewhere) {
2295 fprintf(STDERR,"The volume %s %u already exists on a different server/part\n",
2296 volname, entry.volumeId[voltype]);
2298 "Do you want to do a full restore or abort? [fa](a): ");
2302 fprintf(STDERR,"The volume %s %u already exists in the VLDB\n",
2303 volname, entry.volumeId[voltype]);
2305 "Do you want to do a full/incremental restore or abort? [fia](a): ");
2308 while (!(dc==EOF || dc=='\n')) dc=getchar(); /* goto end of line */
2309 if ((c == 'f') || (c == 'F')) aoverwrite = FULL;
2310 else if ((c == 'i') || (c == 'I')) aoverwrite = INC;
2311 else aoverwrite = ABORT;
2314 if (aoverwrite == ABORT) {
2315 fprintf(STDERR,"Volume exists; Aborting restore command\n");
2318 else if (aoverwrite == FULL) {
2319 restoreflags = RV_FULLRST;
2320 fprintf(STDERR,"Volume exists; Will delete and perform full restore\n");
2322 else if (aoverwrite == INC) {
2324 if (vol_elsewhere) {
2326 "%s volume %lu already exists on a different server/part; not allowed\n",
2327 readonly ? "RO" : "RW", (unsigned long) avolid);
2332 if (offline) restoreflags |= RV_OFFLINE;
2333 if (readonly) restoreflags |= RV_RDONLY;
2334 code = UV_RestoreVolume(aserver, apart, avolid, avolname,
2335 restoreflags, WriteData, afilename);
2337 PrintDiagnostics("restore", code);
2340 MapPartIdIntoName(apart,apartName);
2343 patch typo here - originally "parms[1]", should be "parms[0]"
2346 fprintf(STDOUT,"Restored volume %s on %s %s\n",
2347 avolname, as->parms[0].items->data, apartName);
2350 static LockReleaseCmd(as)
2351 register struct cmd_syndesc *as;
2354 afs_int32 avolid,code, err;
2356 avolid = vsu_GetVolumeID(as->parms[0].items->data, cstruct, &err);
2358 if (err) PrintError("", err);
2359 else fprintf(STDERR, "vos: can't find volume '%s'\n", as->parms[0].items->data);
2363 code = UV_LockRelease(avolid);
2365 PrintDiagnostics("unlock", code);
2368 fprintf(STDOUT,"Released lock on vldb entry for volume %s\n",as->parms[0].items->data);
2372 register struct cmd_syndesc *as;
2374 afs_int32 avolid, aserver, apart,code, err;
2375 char apartName[10], avolname[VOLSER_MAXVOLNAME+1];
2377 vsu_ExtractName(avolname, as->parms[2].items->data);;
2378 avolid = vsu_GetVolumeID(avolname, cstruct, &err);
2380 if (err) PrintError("", err);
2381 else fprintf(STDERR, "vos: can't find volume '%s'\n", as->parms[2].items->data);
2384 aserver = GetServer(as->parms[0].items->data);
2386 fprintf(STDERR,"vos: server '%s' not found in host table\n", as->parms[0].items->data);
2389 apart = volutil_GetPartitionID(as->parms[1].items->data);
2391 fprintf(STDERR,"vos: could not interpret partition name '%s'\n",as->parms[1].items->data );
2394 if (!IsPartValid(apart,aserver,&code)){/*check for validity of the partition */
2395 if(code) PrintError("",code);
2396 else fprintf(STDERR,"vos : partition %s does not exist on the server\n",as->parms[1].items->data);
2399 code = UV_AddSite(aserver, apart, avolid);
2401 PrintDiagnostics("addsite", code);
2404 MapPartIdIntoName(apart,apartName);
2405 fprintf(STDOUT,"Added replication site %s %s for volume %s\n",as->parms[0].items->data, apartName,as->parms[2].items->data);
2409 static RemoveSite(as)
2410 register struct cmd_syndesc *as;
2413 afs_int32 avolid, aserver, apart, code, err;
2414 char apartName[10], avolname[VOLSER_MAXVOLNAME+1];
2416 vsu_ExtractName(avolname, as->parms[2].items->data);
2417 avolid = vsu_GetVolumeID(avolname, cstruct, &err);
2419 if (err) PrintError("", err);
2420 else fprintf(STDERR, "vos: can't find volume '%s'\n", as->parms[2].items->data);
2423 aserver = GetServer(as->parms[0].items->data);
2425 fprintf(STDERR,"vos: server '%s' not found in host table\n", as->parms[0].items->data);
2428 apart = volutil_GetPartitionID(as->parms[1].items->data);
2430 fprintf(STDERR,"vos: could not interpret partition name '%s'\n",as->parms[1].items->data );
2434 *skip the partition validity check, since it is possible that the partition
2435 *has since been decomissioned.
2438 if (!IsPartValid(apart,aserver,&code)){
2439 if(code) PrintError("",code);
2440 else fprintf(STDERR,"vos : partition %s does not exist on the server\n",as->parms[1].items->data);
2444 code = UV_RemoveSite(aserver, apart, avolid);
2446 PrintDiagnostics("remsite", code);
2449 MapPartIdIntoName(apart,apartName);
2450 fprintf(STDOUT,"Removed replication site %s %s for volume %s\n",as->parms[0].items->data,apartName,as->parms[2].items->data);
2453 static ChangeLocation(as)
2454 register struct cmd_syndesc *as;
2456 afs_int32 avolid, aserver, apart,code, err;
2459 avolid = vsu_GetVolumeID(as->parms[2].items->data, cstruct, &err);
2461 if (err) PrintError("", err);
2462 else fprintf(STDERR, "vos: can't find volume '%s'\n", as->parms[2].items->data);
2465 aserver = GetServer(as->parms[0].items->data);
2467 fprintf(STDERR,"vos: server '%s' not found in host table\n", as->parms[0].items->data);
2470 apart = volutil_GetPartitionID(as->parms[1].items->data);
2472 fprintf(STDERR,"vos: could not interpret partition name '%s'\n",as->parms[1].items->data );
2475 if (!IsPartValid(apart,aserver,&code)){/*check for validity of the partition */
2476 if(code) PrintError("",code);
2477 else fprintf(STDERR,"vos : partition %s does not exist on the server\n",as->parms[1].items->data);
2480 code = UV_ChangeLocation(aserver, apart, avolid);
2482 PrintDiagnostics("addsite", code);
2485 MapPartIdIntoName(apart,apartName);
2486 fprintf(STDOUT,"Changed location to %s %s for volume %s\n",as->parms[0].items->data, apartName,as->parms[2].items->data);
2490 static ListPartitions(as)
2491 register struct cmd_syndesc *as;
2493 afs_int32 aserver,code;
2494 struct partList dummyPartList;
2499 aserver = GetServer(as->parms[0].items->data);
2501 fprintf(STDERR,"vos: server '%s' not found in host table\n", as->parms[0].items->data);
2506 code = UV_ListPartitions(aserver,&dummyPartList, &cnt);
2508 PrintDiagnostics("listpart", code);
2512 fprintf(STDOUT,"The partitions on the server are:\n");
2513 for(i = 0 ; i < cnt ; i++){
2514 if(dummyPartList.partFlags[i] & PARTVALID){
2515 memset(pname, 0, sizeof(pname));
2516 MapPartIdIntoName(dummyPartList.partId[i],pname);
2517 fprintf(STDOUT," %10s ",pname);
2519 if( (i % 5) == 0 && (i != 0)) fprintf(STDOUT,"\n");
2522 fprintf(STDOUT,"\n");
2523 fprintf(STDOUT,"Total: %d\n",total);
2528 static int CompareVolName(p1,p2)
2531 volintInfo *arg1,*arg2;
2533 arg1 = (volintInfo *)p1;
2534 arg2 = (volintInfo *)p2;
2535 return(strcmp(arg1->name,arg2->name));
2539 /*------------------------------------------------------------------------
2540 * PRIVATE XCompareVolName
2543 * Comparison routine for volume names coming from an extended
2547 * a_obj1P : Char ptr to first extended vol info object
2548 * a_obj1P : Char ptr to second extended vol info object
2551 * The value of strcmp() on the volume names within the passed
2552 * objects (i,e., -1, 0, or 1).
2555 * Passed to qsort() as the designated comparison routine.
2559 *------------------------------------------------------------------------*/
2561 static int XCompareVolName(a_obj1P, a_obj2P)
2562 char *a_obj1P, *a_obj2P;
2564 { /*XCompareVolName*/
2566 return(strcmp(((struct volintXInfo *)(a_obj1P))->name,
2567 ((struct volintXInfo *)(a_obj2P))->name));
2569 } /*XCompareVolName*/
2571 static int CompareVolID(p1,p2)
2574 volintInfo *arg1,*arg2;
2576 arg1 = (volintInfo *)p1;
2577 arg2 = (volintInfo *)p2;
2578 if(arg1->volid == arg2->volid) return 0;
2579 if(arg1->volid > arg2->volid) return 1;
2584 /*------------------------------------------------------------------------
2585 * PRIVATE XCompareVolID
2588 * Comparison routine for volume IDs coming from an extended
2592 * a_obj1P : Char ptr to first extended vol info object
2593 * a_obj1P : Char ptr to second extended vol info object
2596 * The value of strcmp() on the volume names within the passed
2597 * objects (i,e., -1, 0, or 1).
2600 * Passed to qsort() as the designated comparison routine.
2604 *------------------------------------------------------------------------*/
2606 static int XCompareVolID(a_obj1P, a_obj2P)
2607 char *a_obj1P, *a_obj2P;
2611 afs_int32 id1, id2; /*Volume IDs we're comparing*/
2613 id1 = ((struct volintXInfo *)(a_obj1P))->volid;
2614 id2 = ((struct volintXInfo *)(a_obj2P))->volid;
2625 /*------------------------------------------------------------------------
2626 * PRIVATE ListVolumes
2629 * Routine used to list volumes, contacting the Volume Server
2630 * directly, bypassing the VLDB.
2633 * as : Ptr to parsed command line arguments.
2636 * 0 Successful operation
2639 * Nothing interesting.
2643 *------------------------------------------------------------------------*/
2645 static ListVolumes(as)
2646 register struct cmd_syndesc *as;
2648 afs_int32 apart,int32list,fast;
2649 afs_int32 aserver,code;
2650 volintInfo *pntr,*oldpntr;
2654 volintXInfo *xInfoP, *origxInfoP; /*Ptr to current/orig extended vol info*/
2655 int wantExtendedInfo; /*Do we want extended vol info?*/
2658 struct partList dummyPartList;
2666 if(as->parms[3].items) int32list = 1;
2667 if(as->parms[4].items) quiet = 1;
2669 if(as->parms[2].items) fast = 1;
2672 if (as->parms[5].items) {
2674 * We can't coexist with the fast flag.
2678 "vos: Can't use the -fast and -extended flags together\n");
2683 * We need to turn on ``long'' listings to get the full effect.
2685 wantExtendedInfo = 1;
2689 wantExtendedInfo = 0;
2690 if(as->parms[1].items){
2691 apart = volutil_GetPartitionID(as->parms[1].items->data);
2693 fprintf(STDERR,"vos: could not interpret partition name '%s'\n", as->parms[1].items->data);
2696 dummyPartList.partId[0] = apart;
2697 dummyPartList.partFlags[0] = PARTVALID;
2700 aserver = GetServer(as->parms[0].items->data);
2702 fprintf(STDERR,"vos: server '%s' not found in host table\n",as->parms[0].items->data );
2707 if (!IsPartValid(apart,aserver,&code)){/*check for validity of the partition */
2708 if(code) PrintError("",code);
2709 else fprintf(STDERR,"vos : partition %s does not exist on the server\n",as->parms[1].items->data);
2714 code = UV_ListPartitions(aserver,&dummyPartList, &cnt);
2716 PrintDiagnostics("listvol", code);
2720 for(i = 0 ; i < cnt ; i++){
2721 if(dummyPartList.partFlags[i] & PARTVALID){
2722 if (wantExtendedInfo)
2723 code = UV_XListVolumes(aserver,
2724 dummyPartList.partId[i],
2729 code = UV_ListVolumes(aserver,
2730 dummyPartList.partId[i],
2735 PrintDiagnostics("listvol", code);
2736 if(pntr) free(pntr);
2739 if (wantExtendedInfo) {
2740 origxInfoP = xInfoP;
2741 base = (char *)xInfoP;
2744 base = (char *)pntr;
2748 if (wantExtendedInfo)
2749 qsort(base, count, sizeof(volintXInfo), XCompareVolName);
2751 qsort(base, count, sizeof(volintInfo), CompareVolName);
2753 if (wantExtendedInfo)
2754 qsort(base, count, sizeof(volintXInfo), XCompareVolID);
2756 qsort(base, count, sizeof(volintInfo), CompareVolID);
2758 MapPartIdIntoName(dummyPartList.partId[i],pname);
2760 fprintf(STDOUT,"Total number of volumes on server %s partition %s: %lu \n",as->parms[0].items->data,pname, (unsigned long) count);
2761 if (wantExtendedInfo) {
2762 XDisplayVolumes(aserver,
2763 dummyPartList.partId[i],
2771 xInfoP = (volintXInfo *)0;
2774 #ifdef FULL_LISTVOL_SWITCH
2775 if (as->parms[6].items)
2776 DisplayVolumes2(aserver, dummyPartList.partId[i], oldpntr,
2779 #endif /* FULL_LISTVOL_SWITCH */
2780 DisplayVolumes(aserver,
2781 dummyPartList.partId[i],
2789 pntr = (volintInfo *)0;
2797 register struct cmd_syndesc *as;
2799 afs_int32 pname, code; /* part name */
2805 if (as->parms[0].items) {
2806 tserver = GetServer(as->parms[0].items->data);
2808 fprintf(STDERR,"vos: host '%s' not found in host table\n",as->parms[0].items->data );
2813 if (as->parms[1].items) {
2814 pname = volutil_GetPartitionID(as->parms[1].items->data);
2816 fprintf(STDERR,"vos: could not interpret partition name '%s'\n",as->parms[1].items->data );
2819 if (!IsPartValid(pname,tserver,&code)) { /*check for validity of the partition */
2820 if(code) PrintError("",code);
2821 else fprintf(STDERR,"vos: partition %s does not exist on the server\n",
2822 as->parms[1].items->data);
2828 fprintf(STDERR,"The -partition option requires a -server option\n");
2833 if (as->parms[2].items) {
2834 /* Synchronize an individual volume */
2835 volname = as->parms[2].items->data;
2836 code = UV_SyncVolume(tserver, pname, volname, flags);
2839 fprintf(STDERR,"Without a -volume option, the -server option is required\n");
2842 code = UV_SyncVldb(tserver, pname, flags, 0/*unused*/);
2846 PrintDiagnostics("syncvldb", code);
2850 /* Print a summary of what we did */
2851 if (volname) fprintf(STDOUT,"VLDB volume %s synchronized", volname);
2852 else fprintf(STDOUT,"VLDB synchronized");
2854 fprintf(STDOUT," with state of server %s", as->parms[0].items->data);
2857 MapPartIdIntoName(pname,part);
2858 fprintf(STDOUT," partition %s\n", part);
2860 fprintf(STDOUT, "\n");
2865 static SyncServer(as)
2866 register struct cmd_syndesc *as;
2869 afs_int32 pname,code; /* part name */
2874 tserver = GetServer(as->parms[0].items->data);
2876 fprintf(STDERR,"vos: host '%s' not found in host table\n",as->parms[0].items->data );
2879 if(as->parms[1].items){
2880 pname = volutil_GetPartitionID(as->parms[1].items->data);
2882 fprintf(STDERR,"vos: could not interpret partition name '%s'\n",as->parms[1].items->data);
2885 if (!IsPartValid(pname,tserver,&code)){/*check for validity of the partition */
2886 if(code) PrintError("",code);
2887 else fprintf(STDERR,"vos : partition %s does not exist on the server\n",as->parms[1].items->data);
2893 code = UV_SyncServer(tserver, pname, flags, 0/*unused*/);
2895 PrintDiagnostics("syncserv", code);
2899 MapPartIdIntoName(pname,part);
2900 fprintf(STDOUT,"Server %s partition %s synchronized with VLDB\n",as->parms[0].items->data,part);
2902 else fprintf(STDOUT,"Server %s synchronized with VLDB\n",as->parms[0].items->data);
2907 static VolumeInfoCmd(name)
2910 struct nvldbentry entry;
2913 /* The vlserver will handle names with the .readonly
2914 * and .backup extension as well as volume ids.
2916 vcode = VLDB_GetEntryByName(name, &entry);
2918 PrintError("", vcode);
2921 MapHostToNetwork(&entry);
2922 EnumerateEntry(&entry);
2924 /* Defect #3027: grubby check to handle locked volume.
2925 * If VLOP_ALLOPERS is set, the entry is locked.
2926 * Leave this routine as is, but put in correct check.
2928 if (entry.flags & VLOP_ALLOPERS)
2929 fprintf(STDOUT," Volume is currently LOCKED \n");
2934 static VolumeZap(as)
2935 register struct cmd_syndesc *as;
2938 struct nvldbentry entry;
2939 afs_int32 volid,code,server,part, zapbackupid=0, backupid=0, err;
2941 if (as->parms[3].items) {
2942 /* force flag is on, use the other version */
2943 return NukeVolume(as);
2946 if (as->parms[4].items) {
2950 volid = vsu_GetVolumeID(as->parms[2].items->data, cstruct, &err);
2952 if (err) PrintError("", err);
2953 else fprintf(STDERR, "vos: can't find volume '%s'\n", as->parms[2].items->data);
2956 part = volutil_GetPartitionID(as->parms[1].items->data);
2958 fprintf(STDERR,"vos: could not interpret partition name '%s'\n",as->parms[1].items->data );
2961 server = GetServer(as->parms[0].items->data);
2963 fprintf(STDERR,"vos: host '%s' not found in host table\n",as->parms[0].items->data );
2966 if (!IsPartValid(part,server,&code)){/*check for validity of the partition */
2967 if(code) PrintError("",code);
2968 else fprintf(STDERR,"vos : partition %s does not exist on the server\n",as->parms[1].items->data);
2971 code = VLDB_GetEntryByID(volid,-1, &entry);
2973 if (volid == entry.volumeId[RWVOL])
2974 backupid = entry.volumeId[BACKVOL];
2975 fprintf(STDERR,"Warning: Entry for volume number %lu exists in VLDB (but we're zapping it anyway!)\n",
2976 (unsigned long) volid);
2979 volintInfo *pntr = (volintInfo *)0;
2982 code = UV_ListOneVolume(server, part, volid, &pntr);
2984 if (volid == pntr->parentID)
2985 backupid = pntr->backupID;
2986 if (pntr) free(pntr);
2990 code = UV_VolumeZap(server,part, backupid);
2992 PrintDiagnostics("zap", code);
2995 fprintf(STDOUT,"Backup Volume %lu deleted\n",
2996 (unsigned long) backupid);
2999 code = UV_VolumeZap(server,part,volid);
3001 PrintDiagnostics("zap", code);
3004 fprintf(STDOUT,"Volume %lu deleted\n", (unsigned long) volid);
3009 static VolserStatus(as)
3010 register struct cmd_syndesc *as;
3013 afs_int32 server, code;
3014 transDebugInfo *pntr,*oldpntr;
3019 server = GetServer(as->parms[0].items->data);
3021 fprintf(STDERR,"vos: host '%s' not found in host table\n",as->parms[0].items->data );
3024 code = UV_VolserStatus(server,&pntr,&count);
3026 PrintDiagnostics("status",code);
3031 fprintf(STDOUT,"No active transactions on %s\n",as->parms[0].items->data);
3033 fprintf(STDOUT,"Total transactions: %d\n",count);
3035 for(i = 0; i < count ; i++){
3036 /*print out the relevant info */
3037 fprintf(STDOUT,"--------------------------------------\n");
3038 fprintf(STDOUT,"transaction: %lu created: %s",
3039 (unsigned long) pntr->tid,
3040 ctime((time_t *)&pntr->time));
3041 if(pntr->returnCode){
3042 fprintf(STDOUT,"returnCode: %lu\n",
3043 (unsigned long) pntr->returnCode);
3046 fprintf(STDOUT,"attachFlags: ");
3047 switch(pntr->iflags){
3048 case ITOffline: fprintf(STDOUT,"offline ");
3050 case ITBusy: fprintf(STDOUT,"busy ");
3052 case ITReadOnly: fprintf(STDOUT,"readonly ");
3054 case ITCreate: fprintf(STDOUT,"create ");
3056 case ITCreateVolID: fprintf(STDOUT,"create volid ");
3059 fprintf(STDOUT,"\n");
3062 fprintf(STDOUT,"volumeStatus: ");
3063 switch(pntr->vflags){
3064 case VTDeleteOnSalvage: fprintf(STDOUT,"deleteOnSalvage ");
3065 case VTOutOfService: fprintf(STDOUT,"outOfService ");
3066 case VTDeleted: fprintf(STDOUT,"deleted ");
3068 fprintf(STDOUT,"\n");
3071 fprintf(STDOUT,"transactionFlags: ");
3072 fprintf(STDOUT,"delete\n");
3074 MapPartIdIntoName(pntr->partition ,pname);
3075 fprintf(STDOUT,"volume: %lu partition: %s procedure: %s\n",
3076 (unsigned long) pntr->volid, pname,
3077 pntr->lastProcName);
3078 if(pntr->callValid){
3079 fprintf(STDOUT,"packetRead: %lu lastReceiveTime: %d packetSend: %lu lastSendTime: %d\n",
3080 (unsigned long) pntr->readNext,pntr->lastReceiveTime,
3081 (unsigned long) pntr->transmitNext, pntr->lastSendTime);
3084 fprintf(STDOUT,"--------------------------------------\n");
3085 fprintf(STDOUT,"\n");
3087 if(oldpntr) free(oldpntr);
3091 static RenameVolume(as)
3092 register struct cmd_syndesc *as;
3094 afs_int32 code1,code2,code;
3095 struct nvldbentry entry;
3097 code1 = VLDB_GetEntryByName(as->parms[0].items->data, &entry);
3099 fprintf(STDERR,"vos: Could not find entry for volume %s\n",as->parms[0].items->data);
3102 code2 = VLDB_GetEntryByName(as->parms[1].items->data, &entry);
3103 if((!code1) && (!code2)) { /*the newname already exists */
3104 fprintf(STDERR,"vos: volume %s already exists\n",as->parms[1].items->data);
3109 fprintf(STDERR,"vos: Could not find entry for volume %s or %s\n",as->parms[0].items->data,as->parms[1].items->data);
3112 if(!VolNameOK(as->parms[0].items->data)){
3113 fprintf(STDERR,"Illegal volume name %s, should not end in .readonly or .backup\n",as->parms[0].items->data);
3116 if(!ISNAMEVALID(as->parms[1].items->data)) {
3117 fprintf(STDERR,"vos: the new volume name %s exceeds the size limit of %d\n",as->parms[1].items->data,VOLSER_OLDMAXVOLNAME - 10);
3120 if(!VolNameOK(as->parms[1].items->data)){
3121 fprintf(STDERR,"Illegal volume name %s, should not end in .readonly or .backup\n",as->parms[1].items->data);
3124 if(IsNumeric(as->parms[1].items->data)){
3125 fprintf(STDERR,"Illegal volume name %s, should not be a number\n",as->parms[1].items->data);
3128 MapHostToNetwork(&entry);
3129 code = UV_RenameVolume(&entry,as->parms[0].items->data,as->parms[1].items->data);
3131 PrintDiagnostics("rename", code);
3134 fprintf(STDOUT,"Renamed volume %s to %s\n",as->parms[0].items->data,as->parms[1].items->data);
3138 GetVolumeInfo(volid, server, part, voltype,rentry)
3139 afs_int32 *server, volid, *part, *voltype;
3140 register struct nvldbentry *rentry;
3145 vcode = VLDB_GetEntryByID(volid, -1, rentry);
3147 fprintf(STDERR,"Could not fetch the entry for volume %lu from VLDB \n",
3148 (unsigned long) volid);
3149 PrintError("",vcode);
3152 MapHostToNetwork(rentry);
3153 if(volid == rentry->volumeId[ROVOL]){
3155 for (i = 0; i < rentry->nServers; i++) {
3156 if ( (index == -1) && (rentry->serverFlags[i] & ITSROVOL) &&
3157 !(rentry->serverFlags[i] & RO_DONTUSE) )
3161 fprintf(STDERR,"RO volume is not found in VLDB entry for volume %lu\n", (unsigned long) volid);
3165 *server = rentry->serverNumber[index];
3166 *part = rentry->serverPartition[index];
3170 index = Lp_GetRwIndex(rentry);
3172 fprintf(STDERR,"RW Volume is not found in VLDB entry for volume %lu\n",
3173 (unsigned long) volid);
3176 if(volid == rentry->volumeId[RWVOL]){
3178 *server = rentry->serverNumber[index];
3179 *part = rentry->serverPartition[index];
3182 if(volid == rentry->volumeId[BACKVOL]){
3184 *server = rentry->serverNumber[index];
3185 *part = rentry->serverPartition[index];
3190 static DeleteEntry(as)
3191 register struct cmd_syndesc *as;
3197 struct VldbListByAttributes attributes;
3198 nbulkentries arrayEntries;
3199 register struct nvldbentry *vllist;
3200 struct cmd_item *itp;
3203 char prefix[VOLSER_MAXVOLNAME+1];
3205 afs_int32 totalBack=0, totalFail=0, err;
3207 if (as->parms[0].items) { /* -id */
3208 if (as->parms[1].items || as->parms[2].items || as->parms[3].items) {
3209 fprintf(STDERR,"You cannot use -server, -partition, or -prefix with the -id argument\n");
3212 for (itp=as->parms[0].items; itp; itp=itp->next) {
3213 avolid = vsu_GetVolumeID(itp->data, cstruct, &err);
3215 if (err) PrintError("", err);
3216 else fprintf(STDERR, "vos: can't find volume '%s'\n", itp->data);
3219 if (as->parms[4].items) { /* -noexecute */
3220 fprintf(STDOUT,"Would have deleted VLDB entry for %s \n", itp->data);
3224 vcode = ubik_Call(VL_DeleteEntry,cstruct, 0, avolid, RWVOL);
3226 fprintf(STDERR,"Could not delete entry for volume %s\n", itp->data);
3227 fprintf(STDERR,"You must specify a RW volume name or ID "
3228 "(the entire VLDB entry will be deleted)\n", itp->data);
3229 PrintError("",vcode);
3235 fprintf(STDOUT,"Deleted %d VLDB entries\n", totalBack);
3239 if (!as->parms[1].items && !as->parms[2].items && !as->parms[3].items) {
3240 fprintf(STDERR,"You must specify an option\n");
3244 /* Zero out search attributes */
3245 memset(&attributes, 0, sizeof(struct VldbListByAttributes));
3247 if (as->parms[1].items) { /* -prefix */
3248 strncpy(prefix, as->parms[1].items->data, VOLSER_MAXVOLNAME);
3250 if (!as->parms[2].items && !as->parms[3].items) { /* a single entry only */
3251 fprintf(STDERR,"You must provide -server with the -prefix argument\n");
3256 if (as->parms[2].items) { /* -server */
3258 aserver = GetServer(as->parms[2].items->data);
3260 fprintf(STDERR,"vos: server '%s' not found in host table\n",as->parms[2].items->data );
3263 attributes.server = ntohl(aserver);
3264 attributes.Mask |= VLLIST_SERVER;
3267 if (as->parms[3].items) { /* -partition */
3268 if (!as->parms[2].items) {
3269 fprintf(STDERR,"You must provide -server with the -partition argument\n");
3272 apart = volutil_GetPartitionID(as->parms[3].items->data);
3274 fprintf(STDERR,"vos: could not interpret partition name '%s'\n",
3275 as->parms[3].items->data);
3278 attributes.partition = apart;
3279 attributes.Mask |= VLLIST_PARTITION;
3282 /* Print status line of what we are doing */
3283 fprintf(STDOUT,"Deleting VLDB entries for ");
3284 if (as->parms[2].items) {
3285 fprintf(STDOUT,"server %s ", as->parms[2].items->data);
3287 if (as->parms[3].items) {
3289 MapPartIdIntoName(apart, pname);
3290 fprintf(STDOUT,"partition %s ", pname);
3293 fprintf(STDOUT,"which are prefixed with %s ", prefix);
3295 fprintf(STDOUT,"\n");
3298 /* Get all the VLDB entries on a server and/or partition */
3299 memset(&arrayEntries, 0, sizeof(arrayEntries));
3300 vcode = VLDB_ListAttributes(&attributes, &nentries, &arrayEntries);
3302 fprintf(STDERR,"Could not access the VLDB for attributes\n");
3303 PrintError("",vcode);
3307 /* Process each entry */
3308 for (j=0; j<nentries; j++) {
3309 vllist = &arrayEntries.nbulkentries_val[j];
3311 /* It only deletes the RW volumes */
3312 if (strncmp(vllist->name, prefix, strlen(prefix))){
3314 fprintf(STDOUT,"Omitting to delete %s due to prefix %s mismatch\n",
3315 vllist->name, prefix);
3322 if (as->parms[4].items) { /* -noexecute */
3323 fprintf(STDOUT,"Would have deleted VLDB entry for %s \n", vllist->name);
3328 /* Only matches the RW volume name */
3329 avolid = vllist->volumeId[RWVOL];
3330 vcode = ubik_Call(VL_DeleteEntry, cstruct, 0, avolid, RWVOL);
3332 fprintf(STDOUT,"Could not delete VDLB entry for %s\n",vllist->name);
3334 PrintError("",vcode);
3339 fprintf(STDOUT,"Deleted VLDB entry for %s \n",vllist->name);
3344 fprintf(STDOUT,"----------------------\n");
3345 fprintf(STDOUT,"Total VLDB entries deleted: %lu; failed to delete: %lu\n",
3346 (unsigned long) totalBack, (unsigned long) totalFail);
3347 if (arrayEntries.nbulkentries_val) free(arrayEntries.nbulkentries_val);
3352 static int CompareVldbEntryByName(p1,p2)
3355 struct nvldbentry *arg1,*arg2;
3357 arg1 = (struct nvldbentry *)p1;
3358 arg2 = (struct nvldbentry *)p2;
3359 return(strcmp(arg1->name,arg2->name));
3363 static int CompareVldbEntry(p1,p2)
3366 struct nvldbentry *arg1,*arg2;
3369 char comp1[100],comp2[100];
3370 char temp1[20],temp2[20];
3372 arg1 = (struct nvldbentry *)p1;
3373 arg2 = (struct nvldbentry *)p2;
3377 for(i = 0; i < arg1->nServers; i++)
3378 if(arg1->serverFlags[i] & ITSRWVOL) pos1 = i;
3379 for(i = 0; i < arg2->nServers; i++)
3380 if(arg2->serverFlags[i] & ITSRWVOL) pos2 = i;
3381 if(pos1 == -1 || pos2 == -1){
3385 sprintf(comp1,"%10u",arg1->serverNumber[pos1]);
3386 sprintf(comp2,"%10u",arg2->serverNumber[pos2]);
3387 sprintf(temp1,"%10u",arg1->serverPartition[pos1]);
3388 sprintf(temp2,"%10u",arg2->serverPartition[pos2]);
3389 strcat(comp1,temp1);
3390 strcat(comp2,temp2);
3391 strcat(comp1,arg1->name);
3392 strcat(comp1,arg2->name);
3393 return(strcmp(comp1,comp2));
3399 struct cmd_syndesc *as;
3402 afs_int32 aserver,code;
3404 struct VldbListByAttributes attributes;
3405 nbulkentries arrayEntries;
3406 struct nvldbentry *vllist, *tarray=0, *ttarray;
3407 afs_int32 centries, nentries = 0, tarraysize, parraysize;
3410 int quiet, sort, lock;
3411 afs_int32 thisindex, nextindex;
3416 attributes.Mask = 0;
3417 lock = (as->parms[3].items ? 1 : 0); /* -lock flag */
3418 quiet = (as->parms[4].items ? 1 : 0); /* -quit flag */
3419 sort = (as->parms[5].items ? 0 : 1); /* -nosort flag */
3421 /* If the volume name is given, Use VolumeInfoCmd to look it up
3422 * and not ListAttributes.
3424 if (as->parms[0].items) {
3426 fprintf(STDERR,"vos: illegal use of '-locked' switch, need to specify server and/or partition\n");
3429 code = VolumeInfoCmd(as->parms[0].items->data);
3431 PrintError("",code);
3437 /* Server specified */
3438 if (as->parms[1].items) {
3439 aserver = GetServer(as->parms[1].items->data);
3441 fprintf(STDERR,"vos: server '%s' not found in host table\n",as->parms[1].items->data );
3444 attributes.server = ntohl(aserver);
3445 attributes.Mask |= VLLIST_SERVER;
3448 /* Partition specified */
3449 if (as->parms[2].items) {
3450 apart = volutil_GetPartitionID(as->parms[2].items->data);
3452 fprintf(STDERR,"vos: could not interpret partition name '%s'\n", as->parms[2].items->data);
3455 attributes.partition = apart;
3456 attributes.Mask |= VLLIST_PARTITION;
3460 attributes.Mask |= VLLIST_FLAG;
3461 attributes.flag = VLOP_ALLOPERS;
3464 /* Print header information */
3466 MapPartIdIntoName(apart, pname);
3467 fprintf(STDOUT,"VLDB entries for %s %s%s%s %s\n",
3468 (as->parms[1].items ? "server" : "all" ),
3469 (as->parms[1].items ? as->parms[1].items->data : "servers"),
3470 (as->parms[2].items ? " partition " : ""),
3471 (as->parms[2].items ? pname : ""),
3472 (lock ? "which are locked:" : ""));
3475 for (thisindex = 0; (thisindex != -1); thisindex = nextindex) {
3476 memset(&arrayEntries, 0, sizeof(arrayEntries));
3480 vcode = VLDB_ListAttributesN2(&attributes, 0, thisindex,
3481 ¢ries, &arrayEntries, &nextindex);
3482 if (vcode == RXGEN_OPCODE) {
3483 /* Vlserver not running with ListAttributesN2. Fall back */
3484 vcode = VLDB_ListAttributes(&attributes, ¢ries, &arrayEntries);
3488 fprintf(STDERR,"Could not access the VLDB for attributes\n");
3489 PrintError("",vcode);
3492 nentries += centries;
3494 /* We don't sort, so just print the entries now */
3496 for (j = 0; j < centries; j++) { /* process each entry */
3497 vllist = &arrayEntries.nbulkentries_val[j];
3498 MapHostToNetwork(vllist);
3499 EnumerateEntry(vllist);
3501 if(vllist->flags & VLOP_ALLOPERS)
3502 fprintf(STDOUT," Volume is currently LOCKED \n");
3506 /* So we sort. First we must collect all the entries and keep
3509 else if (centries > 0) {
3511 /* steal away the first bulk entries array */
3512 tarray = (struct nvldbentry *)arrayEntries.nbulkentries_val;
3513 tarraysize = centries * sizeof(struct nvldbentry);
3514 arrayEntries.nbulkentries_val = 0;
3516 /* Grow the tarray to keep the extra entries */
3517 parraysize = (centries * sizeof(struct nvldbentry));
3518 ttarray = (struct nvldbentry *) realloc(tarray, tarraysize + parraysize);
3520 fprintf(STDERR,"Could not allocate enough space for the VLDB entries\n");
3526 memcpy(((char *)tarray)+tarraysize, (char *)arrayEntries.nbulkentries_val, parraysize);
3527 tarraysize += parraysize;
3531 /* Free the bulk array */
3532 if (arrayEntries.nbulkentries_val) {
3533 free(arrayEntries.nbulkentries_val);
3534 arrayEntries.nbulkentries_val = 0;
3538 /* Here is where we now sort all the entries and print them */
3539 if (sort && (nentries > 0)) {
3540 qsort((char *)tarray, nentries, sizeof(struct nvldbentry), CompareVldbEntryByName);
3541 for (vllist=tarray, j=0; j<nentries; j++, vllist++) {
3542 MapHostToNetwork(vllist);
3543 EnumerateEntry(vllist);
3545 if(vllist->flags & VLOP_ALLOPERS)
3546 fprintf(STDOUT," Volume is currently LOCKED \n");
3551 if (!quiet) fprintf(STDOUT,"\nTotal entries: %lu\n",
3552 (unsigned long) nentries);
3553 if (tarray) free(tarray);
3558 register struct cmd_syndesc *as;
3560 afs_int32 apart=0, avolid;
3561 afs_int32 aserver=0, code, aserver1, apart1;
3563 struct VldbListByAttributes attributes;
3564 nbulkentries arrayEntries;
3565 register struct nvldbentry *vllist;
3569 int seenprefix, seenxprefix, exclude, ex, exp, noaction;
3570 afs_int32 totalBack=0;
3571 afs_int32 totalFail=0;
3572 int previdx=-1, error, same;
3575 struct cmd_item *ti;
3579 memset(&attributes, 0, sizeof(struct VldbListByAttributes));
3580 attributes.Mask = 0;
3582 seenprefix = (as->parms[0].items ? 1 : 0);
3583 exclude = (as->parms[3].items ? 1 : 0);
3584 seenxprefix = (as->parms[4].items ? 1 : 0);
3585 noaction = (as->parms[5].items ? 1 : 0);
3587 if (as->parms[1].items) { /* -server */
3588 aserver = GetServer(as->parms[1].items->data);
3590 fprintf(STDERR,"vos: server '%s' not found in host table\n",as->parms[1].items->data );
3593 attributes.server = ntohl(aserver);
3594 attributes.Mask |= VLLIST_SERVER;
3597 if (as->parms[2].items) { /* -partition */
3598 apart = volutil_GetPartitionID(as->parms[2].items->data);
3600 fprintf(STDERR,"vos: could not interpret partition name '%s'\n", as->parms[2].items->data);
3603 attributes.partition = apart;
3604 attributes.Mask |= VLLIST_PARTITION;
3607 /* Check to make sure the prefix and xprefix expressions compile ok */
3609 for (ti=as->parms[0].items; ti; ti=ti->next) {
3610 if (strncmp(ti->data,"^",1) == 0) {
3611 ccode = (char *)re_comp(ti->data);
3613 fprintf(STDERR,"Unrecognizable -prefix regular expression: '%s': %s\n",
3621 for (ti=as->parms[4].items; ti; ti=ti->next) {
3622 if (strncmp(ti->data,"^",1) == 0) {
3623 ccode = (char *)re_comp(ti->data);
3625 fprintf(STDERR,"Unrecognizable -xprefix regular expression: '%s': %s\n",
3633 memset(&arrayEntries, 0, sizeof(arrayEntries)); /* initialize to hint the stub to alloc space */
3634 vcode = VLDB_ListAttributes(&attributes, &nentries, &arrayEntries);
3636 fprintf(STDERR,"Could not access the VLDB for attributes\n");
3637 PrintError("",vcode);
3641 if (as->parms[1].items || as->parms[2].items || verbose) {
3642 fprintf(STDOUT,"%s up volumes", (noaction?"Would have backed":"Backing"));
3644 if (as->parms[1].items) {
3645 fprintf(STDOUT," on server %s", as->parms[1].items->data);
3646 } else if (as->parms[2].items) {
3647 fprintf(STDOUT," for all servers");
3650 if (as->parms[2].items) {
3651 MapPartIdIntoName(apart, pname);
3652 fprintf(STDOUT," partition %s", pname);
3655 if (seenprefix || (!seenprefix && seenxprefix)) {
3656 ti = (seenprefix ? as->parms[0].items : as->parms[4].items);
3657 ex = (seenprefix ? exclude : !exclude);
3658 exp = (strncmp(ti->data,"^",1) == 0);
3659 fprintf(STDOUT," which %smatch %s '%s'", (ex ? "do not " : ""),
3660 (exp?"expression":"prefix"), ti->data);
3661 for (ti=ti->next; ti; ti=ti->next) {
3662 exp = (strncmp(ti->data,"^",1) == 0);
3663 printf(" %sor %s '%s'", (ex ? "n" : ""),
3664 (exp?"expression":"prefix"), ti->data);
3668 if (seenprefix && seenxprefix) {
3669 ti = as->parms[4].items;
3670 exp = (strncmp(ti->data,"^",1) == 0);
3671 fprintf(STDOUT," %swhich match %s '%s'",
3672 (exclude?"adding those ":"removing those "),
3673 (exp?"expression":"prefix"), ti->data);
3674 for (ti=ti->next; ti; ti=ti->next) {
3675 exp = (strncmp(ti->data,"^",1) == 0);
3676 printf(" or %s '%s'", (exp?"expression":"prefix"), ti->data);
3679 fprintf(STDOUT," .. ");
3680 if (verbose) fprintf(STDOUT,"\n");
3684 for (j=0; j<nentries; j++) { /* process each vldb entry */
3685 vllist = &arrayEntries.nbulkentries_val[j];
3688 for (ti=as->parms[0].items; ti; ti=ti->next) {
3689 if (strncmp(ti->data,"^",1) == 0) {
3690 ccode = (char *)re_comp(ti->data);
3692 fprintf(STDERR,"Error in -prefix regular expression: '%s': %s\n",
3696 match = (re_exec(vllist->name) == 1);
3698 match = (strncmp(vllist->name,ti->data,strlen(ti->data)) == 0);
3706 /* Without the -exclude flag: If it matches the prefix, then
3707 * check if we want to exclude any from xprefix.
3708 * With the -exclude flag: If it matches the prefix, then
3709 * check if we want to add any from xprefix.
3711 if (match && seenxprefix) {
3712 for (ti=as->parms[4].items; ti; ti=ti->next) {
3713 if (strncmp(ti->data,"^",1) == 0) {
3714 ccode = (char *)re_comp(ti->data);
3716 fprintf(STDERR,"Error in -xprefix regular expression: '%s': %s\n",
3720 if (re_exec(vllist->name) == 1) {
3725 if (strncmp(vllist->name,ti->data,strlen(ti->data)) == 0) {
3733 if (exclude) match = !match; /* -exclude will reverse the match */
3734 if (!match) continue; /* Skip if no match */
3736 /* Print list of volumes to backup */
3738 fprintf(STDOUT," %s\n", vllist->name);
3742 if(!(vllist->flags & RW_EXISTS)){
3744 fprintf(STDOUT,"Omitting to backup %s since RW volume does not exist \n", vllist->name);
3745 fprintf(STDOUT,"\n");
3751 avolid = vllist->volumeId[RWVOL];
3752 MapHostToNetwork(vllist);
3753 GetServerAndPart(vllist,RWVOL,&aserver1,&apart1,&previdx);
3754 if(aserver1 == -1 || apart1 == -1){
3755 fprintf(STDOUT,"could not backup %s, invalid VLDB entry\n",vllist->name);
3760 same = VLDB_IsSameAddrs(aserver, aserver1, &error);
3762 fprintf(STDERR,"Failed to get info about server's %d address(es) from vlserver (err=%d); aborting call!\n",
3768 if ((aserver && !same) || (apart && (apart != apart1))) {
3770 fprintf(STDOUT, "Omitting to backup %s since the RW is in a different location\n", vllist->name);
3775 time_t now = time(0);
3776 fprintf(STDOUT,"Creating backup volume for %s on %s",vllist->name, ctime(&now));
3780 code = UV_BackupVolume(aserver1, apart1, avolid);
3782 fprintf(STDOUT,"Could not backup %s\n",vllist->name);
3788 if (verbose) fprintf(STDOUT,"\n");
3790 } /* process each vldb entry */
3791 fprintf(STDOUT,"done\n");
3792 fprintf(STDOUT,"Total volumes backed up: %lu; failed to backup: %lu\n",
3793 (unsigned long) totalBack, (unsigned long) totalFail);
3795 if(arrayEntries.nbulkentries_val) free(arrayEntries.nbulkentries_val);
3799 static UnlockVLDB(as)
3800 register struct cmd_syndesc *as;
3803 afs_int32 aserver,code;
3805 struct VldbListByAttributes attributes;
3806 nbulkentries arrayEntries;
3807 register struct nvldbentry *vllist;
3816 attributes.Mask = 0;
3818 if(as->parms[0].items) {/* server specified */
3819 aserver = GetServer(as->parms[0].items->data);
3821 fprintf(STDERR,"vos: server '%s' not found in host table\n",as->parms[0].items->data );
3824 attributes.server = ntohl(aserver);
3825 attributes.Mask |= VLLIST_SERVER;
3827 if(as->parms[1].items) {/* partition specified */
3828 apart = volutil_GetPartitionID(as->parms[1].items->data);
3830 fprintf(STDERR,"vos: could not interpret partition name '%s'\n", as->parms[1].items->data);
3833 if (!IsPartValid(apart,aserver,&code)){/*check for validity of the partition */
3834 if(code) PrintError("",code);
3835 else fprintf(STDERR,"vos : partition %s does not exist on the server\n",as->parms[1].items->data);
3838 attributes.partition = apart;
3839 attributes.Mask |= VLLIST_PARTITION;
3841 attributes.flag = VLOP_ALLOPERS;
3842 attributes.Mask |= VLLIST_FLAG;
3843 memset(&arrayEntries, 0, sizeof(arrayEntries)); /*initialize to hint the stub to alloc space */
3844 vcode = VLDB_ListAttributes(&attributes, &nentries, &arrayEntries);
3846 fprintf(STDERR,"Could not access the VLDB for attributes\n");
3847 PrintError("",vcode);
3850 for(j=0;j<nentries;j++) { /* process each entry */
3851 vllist = &arrayEntries.nbulkentries_val[j];
3852 volid = vllist->volumeId[RWVOL];
3853 vcode = ubik_Call(VL_ReleaseLock,cstruct, 0, volid,-1, LOCKREL_OPCODE | LOCKREL_AFSID | LOCKREL_TIMESTAMP);
3855 fprintf(STDERR,"Could not unlock entry for volume %s\n",vllist->name);
3856 PrintError("",vcode);
3861 MapPartIdIntoName(apart,pname);
3862 if(totalE) fprintf(STDOUT,"Could not lock %lu VLDB entries of %lu locked entries\n", (unsigned long) totalE, (unsigned long) nentries);
3864 if(as->parms[0].items) {
3865 fprintf(STDOUT,"Unlocked all the VLDB entries for volumes on server %s ",as->parms[0].items->data);
3866 if(as->parms[1].items){
3867 MapPartIdIntoName(apart,pname);
3868 fprintf(STDOUT,"partition %s\n",pname);
3870 else fprintf(STDOUT,"\n");
3873 else if(as->parms[1].items){
3874 MapPartIdIntoName(apart,pname);
3875 fprintf(STDOUT,"Unlocked all the VLDB entries for volumes on partition %s on all servers\n",pname);
3879 if(arrayEntries.nbulkentries_val) free(arrayEntries.nbulkentries_val);
3883 static PartitionInfo(as)
3884 register struct cmd_syndesc *as;
3887 afs_int32 aserver,code;
3889 struct diskPartition partition;
3890 struct partList dummyPartList;
3894 aserver = GetServer(as->parms[0].items->data);
3896 fprintf(STDERR,"vos: server '%s' not found in host table\n",as->parms[0].items->data );
3899 if(as->parms[1].items){
3900 apart = volutil_GetPartitionID(as->parms[1].items->data);
3902 fprintf(STDERR,"vos: could not interpret partition name '%s'\n", as->parms[1].items->data);
3905 dummyPartList.partId[0] = apart;
3906 dummyPartList.partFlags[0] = PARTVALID;
3910 if (!IsPartValid(apart,aserver,&code)){/*check for validity of the partition */
3911 if(code) PrintError("",code);
3912 else fprintf(STDERR,"vos : partition %s does not exist on the server\n",as->parms[1].items->data);
3917 code = UV_ListPartitions(aserver,&dummyPartList, &cnt);
3919 PrintDiagnostics("listpart", code);
3923 for(i = 0 ; i < cnt ; i++){
3924 if(dummyPartList.partFlags[i] & PARTVALID){
3925 MapPartIdIntoName(dummyPartList.partId[i],pname);
3926 code = UV_PartitionInfo(aserver,pname,&partition);
3928 fprintf(STDERR,"Could not get information on partition %s\n",pname);
3929 PrintError("",code);
3932 fprintf(STDOUT,"Free space on partition %s: %d K blocks out of total %d\n",pname,partition.free,partition.minFree);
3938 static ChangeAddr(as)
3939 register struct cmd_syndesc *as;
3942 afs_int32 ip1, ip2, vcode;
3945 ip1 = GetServer(as->parms[0].items->data);
3947 fprintf(STDERR, "vos: invalid host address\n");
3951 if ( ( as->parms[1].items && as->parms[2].items) ||
3952 (!as->parms[1].items && !as->parms[2].items) ) {
3953 fprintf(STDERR, "vos: Must specify either '-newaddr <addr>' or '-remove' flag\n");
3957 if (as->parms[1].items) {
3958 ip2 = GetServer(as->parms[1].items->data);
3960 fprintf(STDERR, "vos: invalid host address\n");
3964 /* Play a trick here. If we are removing an address, ip1 will be -1
3965 * and ip2 will be the original address. This switch prevents an
3966 * older revision vlserver from removing the IP address.
3973 vcode = ubik_Call_New(VL_ChangeAddr, cstruct, 0, ntohl(ip1), ntohl(ip2) );
3976 fprintf(STDERR,"Could not remove server %s from the VLDB\n",
3977 as->parms[0].items->data);
3978 if (vcode == VL_NOENT) {
3979 fprintf(STDERR, "vlserver does not support the remove flag or ");
3982 fprintf(STDERR,"Could not change server %s to server %s\n",
3983 as->parms[0].items->data, as->parms[1].items->data);
3985 PrintError("",vcode);
3990 fprintf(STDOUT,"Removed server %s from the VLDB\n",
3991 as->parms[0].items->data);
3993 fprintf(STDOUT,"Changed server %s to server %s\n",
3994 as->parms[0].items->data, as->parms[1].items->data);
4000 print_addrs(const bulkaddrs *addrs, const afsUUID *m_uuid, int nentries, int print, int noresolve)
4004 struct VLCallBack unused;
4007 ListAddrByAttributes m_attrs;
4008 afs_int32 m_unique, m_nentries, *m_addrp;
4009 afs_int32 base, index;
4013 afsUUID_to_string(m_uuid, buf, sizeof(buf));
4014 printf("UUID: %s\n", buf);
4017 /* print out the list of all the server */
4018 addrp = (afs_int32 *)addrs->bulkaddrs_val;
4019 for (i=0; i<nentries; i++, addrp++) {
4020 /* If it is a multihomed address, then we will need to
4021 * get the addresses for this multihomed server from
4022 * the vlserver and print them.
4024 if ( ((*addrp & 0xff000000) == 0xff000000) && ((*addrp)&0xffff) ) {
4025 /* Get the list of multihomed fileservers */
4026 base = (*addrp>>16) & 0xff;
4027 index = (*addrp) & 0xffff;
4029 if ( (base >= 0) && (base <= VL_MAX_ADDREXTBLKS) &&
4030 (index >= 1) && (index <= VL_MHSRV_PERBLK) ) {
4031 m_attrs.Mask = VLADDR_INDEX;
4032 m_attrs.index = (base * VL_MHSRV_PERBLK) + index;
4034 m_addrs.bulkaddrs_val = 0;
4035 m_addrs.bulkaddrs_len = 0;
4036 vcode = ubik_Call(VL_GetAddrsU, cstruct, 0,
4037 &m_attrs, &m_uuid, &m_unique, &m_nentries, &m_addrs);
4039 fprintf(STDERR,"vos: could not list the multi-homed server addresses\n");
4040 PrintError("",vcode);
4043 /* Print the list */
4044 m_addrp = (afs_int32 *)m_addrs.bulkaddrs_val;
4045 for (j=0; j<m_nentries; j++, m_addrp++) {
4046 *m_addrp = htonl(*m_addrp);
4049 printf("%s ", afs_inet_ntoa_r(*m_addrp,hoststr));
4051 printf("%s ", hostutil_GetNameByINet(*m_addrp));
4055 printf("<unknown>\n");
4064 /* Otherwise, it is a non-multihomed entry and contains
4065 * the IP address of the server - print it.
4067 *addrp = htonl(*addrp);
4070 printf("%s\n", afs_inet_ntoa_r(*addrp,hoststr));
4072 printf("%s\n", hostutil_GetNameByINet(*addrp));
4082 static ListAddrs(as)
4083 register struct cmd_syndesc *as;
4086 afs_int32 i, j, noresolve=0, printuuid=0;
4087 struct VLCallBack unused;
4088 afs_int32 nentries, *addrp;
4089 bulkaddrs addrs, m_addrs;
4090 ListAddrByAttributes m_attrs;
4091 afsUUID m_uuid, askuuid;
4092 afs_int32 m_unique, m_nentries, *m_addrp;
4093 afs_int32 base, index;
4095 memset(&m_attrs, 0, sizeof(struct ListAddrByAttributes));
4096 m_attrs.Mask = VLADDR_INDEX;
4098 memset(&m_addrs, 0, sizeof(bulkaddrs));
4099 memset(&askuuid, 0, sizeof(afsUUID));
4100 if (as->parms[0].items) {
4102 afsUUID_from_string(as->parms[0].items->data, &askuuid);
4103 m_attrs.Mask = VLADDR_UUID;
4104 m_attrs.uuid = askuuid;
4106 if (as->parms[1].items) {
4110 he = hostutil_GetHostByName((char*)as->parms[1].items->data);
4113 "Can't get host info for '%s'\n",
4114 as->parms[1].items->data);
4117 memcpy(&saddr, he->h_addr, 4);
4118 m_attrs.Mask = VLADDR_IPADDR;
4119 m_attrs.ipaddr = ntohl(saddr);
4121 if (as->parms[2].items) {
4124 if (as->parms[3].items) {
4128 m_addrs.bulkaddrs_val = 0;
4129 m_addrs.bulkaddrs_len = 0;
4131 vcode = ubik_Call_New(VL_GetAddrs, cstruct, 0,
4132 0, 0, &m_unique, &nentries, &m_addrs);
4134 fprintf(STDERR,"vos: could not list the server addresses\n");
4135 PrintError("",vcode);
4140 m_addrs.bulkaddrs_val = 0;
4141 m_addrs.bulkaddrs_len = 0;
4146 vcode = ubik_Call_New(VL_GetAddrsU, cstruct, 0, &m_attrs, &m_uuid,
4147 &m_unique, &m_nentries, &m_addrs);
4148 if(vcode == VL_NOENT) {
4154 if (vcode == VL_INDEXERANGE) {
4159 fprintf(STDERR,"vos: could not list the server addresses\n");
4160 PrintError("",vcode);
4164 print_addrs(&m_addrs, &m_uuid, m_nentries, printuuid, noresolve);
4167 if ((as->parms[1].items)||(as->parms[0].items)||(i>nentries))
4174 static LockEntry(as)
4175 register struct cmd_syndesc *as;
4178 afs_int32 avolid,vcode, err;
4180 avolid = vsu_GetVolumeID(as->parms[0].items->data, cstruct, &err);
4182 if (err) PrintError("", err);
4183 else fprintf(STDERR, "vos: can't find volume '%s'\n", as->parms[0].items->data);
4186 vcode = ubik_Call(VL_SetLock,cstruct, 0, avolid, -1, VLOP_DELETE);
4188 fprintf(STDERR,"Could not lock VLDB entry for volume %s\n",as->parms[0].items->data);
4189 PrintError("",vcode);
4192 fprintf(STDOUT,"Locked VLDB entry for volume %s\n",as->parms[0].items->data);
4196 static ConvertRO(as)
4197 register struct cmd_syndesc *as;
4200 afs_int32 partition = -1;
4201 afs_int32 server, volid, code, i, same;
4202 struct nvldbentry entry, storeEntry;
4205 afs_int32 rwserver = 0;
4206 afs_int32 rwpartition;
4208 afs_int32 roserver = 0;
4209 afs_int32 ropartition;
4211 struct rx_connection *aconn;
4214 server = GetServer(as->parms[0].items->data);
4216 fprintf(STDERR,"vos: host '%s' not found in host table\n",as->parms[0].items->data );
4219 partition = volutil_GetPartitionID(as->parms[1].items->data);
4220 if (partition < 0) {
4221 fprintf(STDERR,"vos: could not interpret partition name '%s'\n",as->parms[1].items->data );
4224 if (!IsPartValid(partition, server, &code)) {
4225 if(code) PrintError("",code);
4226 else fprintf(STDERR,"vos : partition %s does not exist on the server\n",as->parms[1].items->data);
4229 volid = vsu_GetVolumeID(as->parms[2].items->data, cstruct, &code);
4231 if (code) PrintError("", code);
4232 else fprintf(STDERR, "Unknown volume ID or name '%s'\n", as->parms[0].items->data);
4235 if (as->parms[3].items)
4238 vcode = VLDB_GetEntryByID (volid, -1, &entry);
4240 fprintf(STDERR,"Could not fetch the entry for volume %lu from VLDB\n",
4241 (unsigned long) volid);
4242 PrintError("convertROtoRW", code);
4246 /* use RO volid even if user specified RW or BK volid */
4248 if (volid != entry.volumeId[ROVOL])
4249 volid = entry.volumeId[ROVOL];
4251 MapHostToNetwork(&entry);
4252 for (i=0; i< entry.nServers; i++) {
4253 if (entry.serverFlags[i] & ITSRWVOL) {
4255 rwserver = entry.serverNumber[i];
4256 rwpartition = entry.serverPartition[i];
4258 if (entry.serverFlags[i] & ITSROVOL) {
4259 same = VLDB_IsSameAddrs(server, entry.serverNumber[i], &code);
4261 fprintf(STDERR, "Failed to get info about server's %d address(es) from vlserver (err=%d); aborting call!\n",
4267 roserver = entry.serverNumber[i];
4268 ropartition = entry.serverPartition[i];
4274 fprintf(STDERR, "Warning: RO volume didn't exist in vldb!\n");
4276 if (ropartition != partition) {
4277 fprintf(STDERR, "Warning: RO volume should be in partition %d instead of %d (vldb)\n", ropartition, partition);
4282 "VLDB indicates that a RW volume exists already on %s in partition %s.\n", hostutil_GetNameByINet(rwserver), volutil_PartitionName(rwpartition));
4284 fprintf(STDERR, "Overwrite this VLDB entry? [y|n] (n)\n");
4286 while (!(dc==EOF || dc=='\n')) dc=getchar(); /* goto end of line */
4287 if ((c != 'y') && (c != 'Y')) {
4288 fprintf(STDERR, "aborted.\n");
4294 vcode = ubik_Call(VL_SetLock, cstruct, 0, entry.volumeId[RWVOL], RWVOL,
4296 aconn = UV_Bind(server, AFSCONF_VOLUMEPORT);
4297 code = AFSVolConvertROtoRWvolume(aconn, partition, volid);
4299 fprintf(STDERR,"Converting RO volume %lu to RW volume failed with code %d\n", (unsigned long) volid, code);
4300 PrintError("convertROtoRW ", code);
4303 entry.serverFlags[roindex] = ITSRWVOL;
4304 entry.flags |= RW_EXISTS;
4305 entry.flags &= ~BACK_EXISTS;
4308 if (rwindex != entry.nServers) {
4309 entry.serverNumber[rwindex] = entry.serverNumber[entry.nServers];
4310 entry.serverPartition[rwindex] = entry.serverPartition[entry.nServers];
4311 entry.serverFlags[rwindex] = entry.serverFlags[entry.nServers];
4312 entry.serverNumber[entry.nServers] = 0;
4313 entry.serverPartition[entry.nServers] = 0;
4314 entry.serverFlags[entry.nServers] = 0;
4317 entry.flags &= ~RO_EXISTS;
4318 for (i=0; i<entry.nServers; i++) {
4319 if (entry.serverFlags[i] & ITSROVOL) {
4320 if (!(entry.serverFlags[i] & (RO_DONTUSE | NEW_REPSITE)))
4321 entry.flags |= RO_EXISTS;
4324 MapNetworkToHost(&entry, &storeEntry);
4325 code = VLDB_ReplaceEntry(entry.volumeId[RWVOL], RWVOL, &storeEntry,
4326 (LOCKREL_OPCODE | LOCKREL_AFSID | LOCKREL_TIMESTAMP));
4328 fprintf(STDERR, "Warning: volume converted, but vldb update failed with code %d!\n", code);
4330 vcode = UV_LockRelease(entry.volumeId[RWVOL]);
4332 PrintDiagnostics("unlock", vcode);
4338 register struct cmd_syndesc *as;
4340 afs_int32 avolid, aserver, apart,voltype,fromdate=0,code, err, i;
4341 struct nvldbentry entry;
4342 volintSize vol_size;
4344 rx_SetRxDeadTime(60 * 10);
4345 for (i = 0; i<MAXSERVERS; i++) {
4346 struct rx_connection *rxConn = ubik_GetRPCConn(cstruct,i);
4347 if (rxConn == 0) break;
4348 rx_SetConnDeadTime(rxConn, rx_connDeadTime);
4349 if (rxConn->service) rxConn->service->connDeadTime = rx_connDeadTime;
4352 avolid = vsu_GetVolumeID(as->parms[0].items->data, cstruct, &err);
4354 if (err) PrintError("", err);
4355 else fprintf(STDERR, "vos: can't find volume '%s'\n", as->parms[0].items->data);
4359 if (as->parms[1].items || as->parms[2].items) {
4360 if (!as->parms[1].items || !as->parms[2].items) {
4361 fprintf(STDERR, "Must specify both -server and -partition options\n");
4364 aserver = GetServer(as->parms[2].items->data);
4366 fprintf(STDERR, "Invalid server name\n");
4369 apart = volutil_GetPartitionID(as->parms[1].items->data);
4371 fprintf(STDERR, "Invalid partition name\n");
4375 code = GetVolumeInfo(avolid, &aserver, &apart, &voltype, &entry);
4376 if (code) return code;
4381 if (as->parms[4].items && strcmp(as->parms[4].items->data,"0")) {
4382 code = ktime_DateToInt32(as->parms[4].items->data, &fromdate);
4384 fprintf(STDERR,"vos: failed to parse date '%s' (error=%d))\n",
4385 as->parms[1].items->data, code);
4390 fprintf(STDOUT, "Volume: %s\n", as->parms[0].items->data);
4392 if(as->parms[3].items) /* do the dump estimate */
4394 vol_size.dump_size = 0;
4395 code = UV_GetSize(avolid, aserver, apart, fromdate, &vol_size);
4397 PrintDiagnostics("size", code);
4400 /* presumably the size info is now gathered in pntr */
4401 /* now we display it */
4403 fprintf(STDOUT,"dump_size: %llu\n", vol_size.dump_size);
4411 PrintDiagnostics(astring, acode)
4415 if (acode == EACCES) {
4416 fprintf(STDERR,"You are not authorized to perform the 'vos %s' command (%d)\n",
4420 fprintf(STDERR,"Error in vos %s command.\n", astring);
4421 PrintError("", acode);
4427 static MyBeforeProc(as, arock)
4428 struct cmd_syndesc *as;
4430 register char *tcell;
4431 register afs_int32 code;
4432 register afs_int32 sauth;
4434 /* Initialize the ubik_client connection */
4435 rx_SetRxDeadTime(90);
4436 cstruct = (struct ubik_client *)0;
4440 if (as->parms[12].items) /* if -cell specified */
4441 tcell = as->parms[12].items->data;
4442 if(as->parms[14].items) /* -serverauth specified */
4444 if(as->parms[16].items) /* -crypt specified */
4446 if ((code = vsu_ClientInit((as->parms[13].items != 0), confdir, tcell, sauth,
4447 &cstruct, UV_SetSecurity))) {
4448 fprintf(STDERR,"could not initialize VLDB library (code=%lu) \n",
4449 (unsigned long) code);
4453 if(as->parms[15].items) /* -verbose flag set */
4462 /* this sucks but it works for now.
4467 #include "AFS_component_version_number.c"
4472 register afs_int32 code;
4474 register struct cmd_syndesc *ts;
4476 #ifdef AFS_AIX32_ENV
4478 * The following signal action for AIX is necessary so that in case of a
4479 * crash (i.e. core is generated) we can include the user's data section
4480 * in the core dump. Unfortunately, by default, only a partial core is
4481 * generated which, in many cases, isn't too useful.
4483 struct sigaction nsa;
4485 sigemptyset(&nsa.sa_mask);
4486 nsa.sa_handler = SIG_DFL;
4487 nsa.sa_flags = SA_FULLDUMP;
4488 sigaction(SIGSEGV, &nsa, NULL);
4491 confdir = AFSDIR_CLIENT_ETC_DIRPATH;
4493 cmd_SetBeforeProc(MyBeforeProc, NULL);
4495 ts = cmd_CreateSyntax("create", CreateVolume, 0, "create a new volume");
4496 cmd_AddParm(ts, "-server", CMD_SINGLE, 0, "machine name");
4497 cmd_AddParm(ts, "-partition", CMD_SINGLE, 0, "partition name");
4498 cmd_AddParm(ts, "-name", CMD_SINGLE, 0, "volume name");
4499 cmd_AddParm(ts, "-maxquota", CMD_SINGLE, CMD_OPTIONAL, "initial quota (KB)");
4501 cmd_AddParm(ts, "-minquota", CMD_SINGLE, CMD_OPTIONAL, "");
4505 ts = cmd_CreateSyntax("remove", DeleteVolume, 0, "delete a volume");
4506 cmd_AddParm(ts, "-server", CMD_SINGLE, CMD_OPTIONAL, "machine name");
4507 cmd_AddParm(ts, "-partition", CMD_SINGLE, CMD_OPTIONAL, "partition name");
4508 cmd_AddParm(ts, "-id", CMD_SINGLE, 0, "volume name or ID");
4512 ts = cmd_CreateSyntax("move", MoveVolume, 0, "move a volume");
4513 cmd_AddParm(ts, "-id", CMD_SINGLE, 0, "volume name or ID");
4514 cmd_AddParm(ts, "-fromserver", CMD_SINGLE, 0, "machine name on source");
4515 cmd_AddParm(ts, "-frompartition", CMD_SINGLE, 0, "partition name on source");
4516 cmd_AddParm(ts, "-toserver", CMD_SINGLE, 0, "machine name on destination");
4517 cmd_AddParm(ts, "-topartition", CMD_SINGLE, 0, "partition name on destination");
4520 ts = cmd_CreateSyntax("copy", CopyVolume, 0, "copy a volume");
4521 cmd_AddParm(ts, "-id", CMD_SINGLE, 0, "volume name or ID on source");
4522 cmd_AddParm(ts, "-fromserver", CMD_SINGLE, 0, "machine name on source");
4523 cmd_AddParm(ts, "-frompartition", CMD_SINGLE, 0, "partition name on source");
4524 cmd_AddParm(ts, "-toname", CMD_SINGLE, 0, "volume name on destination");
4525 cmd_AddParm(ts, "-toserver", CMD_SINGLE, 0, "machine name on destination");
4526 cmd_AddParm(ts, "-topartition", CMD_SINGLE, 0, "partition name on destination");
4529 ts = cmd_CreateSyntax("backup", BackupVolume, 0, "make backup of a volume");
4530 cmd_AddParm(ts, "-id", CMD_SINGLE, 0, "volume name or ID");
4533 ts = cmd_CreateSyntax("release", ReleaseVolume, 0, "release a volume");
4534 cmd_AddParm(ts, "-id", CMD_SINGLE, 0, "volume name or ID");
4535 cmd_AddParm(ts, "-force", CMD_FLAG, CMD_OPTIONAL, "force a complete release");
4538 ts = cmd_CreateSyntax("dump", DumpVolume, 0, "dump a volume");
4539 cmd_AddParm(ts, "-id", CMD_SINGLE, 0, "volume name or ID");
4540 cmd_AddParm(ts, "-time", CMD_SINGLE, CMD_OPTIONAL, "dump from time");
4541 cmd_AddParm(ts, "-file", CMD_SINGLE, CMD_OPTIONAL, "dump file");
4542 cmd_AddParm(ts, "-server", CMD_SINGLE, CMD_OPTIONAL, "server");
4543 cmd_AddParm(ts, "-partition", CMD_SINGLE, CMD_OPTIONAL, "partition");
4544 cmd_AddParm(ts, "-clone", CMD_FLAG, CMD_OPTIONAL, "dump a clone of the volume");
4547 ts = cmd_CreateSyntax("restore", RestoreVolume, 0, "restore a volume");
4548 cmd_AddParm(ts, "-server", CMD_SINGLE, 0, "machine name");
4549 cmd_AddParm(ts, "-partition", CMD_SINGLE, 0, "partition name");
4550 cmd_AddParm(ts, "-name", CMD_SINGLE, 0, "name of volume to be restored");
4551 cmd_AddParm(ts, "-file", CMD_SINGLE,CMD_OPTIONAL, "dump file");
4552 cmd_AddParm(ts, "-id", CMD_SINGLE,CMD_OPTIONAL, "volume ID");
4553 cmd_AddParm(ts, "-overwrite", CMD_SINGLE,CMD_OPTIONAL, "abort | full | incremental");
4554 cmd_AddParm(ts, "-offline", CMD_FLAG, CMD_OPTIONAL,
4555 "leave restored volume offline");
4556 cmd_AddParm(ts, "-readonly", CMD_FLAG, CMD_OPTIONAL,
4557 "make restored volume read-only");
4560 ts = cmd_CreateSyntax("unlock", LockReleaseCmd, 0, "release lock on VLDB entry for a volume");
4561 cmd_AddParm(ts, "-id", CMD_SINGLE, 0, "volume name or ID");
4564 ts = cmd_CreateSyntax("changeloc", ChangeLocation, 0, "change an RW volume's location in the VLDB");
4565 cmd_AddParm(ts, "-server", CMD_SINGLE, 0, "machine name for new location");
4566 cmd_AddParm(ts, "-partition", CMD_SINGLE, 0, "partition name for new location");
4567 cmd_AddParm(ts, "-id", CMD_SINGLE, 0, "volume name or ID");
4570 ts = cmd_CreateSyntax("addsite", AddSite, 0, "add a replication site");
4571 cmd_AddParm(ts, "-server", CMD_SINGLE, 0, "machine name for new site");
4572 cmd_AddParm(ts, "-partition", CMD_SINGLE, 0, "partition name for new site");
4573 cmd_AddParm(ts, "-id", CMD_SINGLE, 0, "volume name or ID");
4576 ts = cmd_CreateSyntax("remsite", RemoveSite, 0, "remove a replication site");
4577 cmd_AddParm(ts, "-server", CMD_SINGLE, 0, "machine name");
4578 cmd_AddParm(ts, "-partition", CMD_SINGLE, 0, "partition name");
4579 cmd_AddParm(ts, "-id", CMD_SINGLE, 0, "volume name or ID");
4582 ts = cmd_CreateSyntax("listpart", ListPartitions, 0, "list partitions");
4583 cmd_AddParm(ts, "-server", CMD_SINGLE, 0, "machine name");
4586 ts = cmd_CreateSyntax("listvol", ListVolumes, 0, "list volumes on server (bypass VLDB)");
4587 cmd_AddParm(ts, "-server", CMD_SINGLE, 0, "machine name");
4588 cmd_AddParm(ts, "-partition", CMD_SINGLE,CMD_OPTIONAL, "partition name");
4589 cmd_AddParm(ts, "-fast", CMD_FLAG, CMD_OPTIONAL, "minimal listing");
4590 cmd_AddParm(ts, "-long", CMD_FLAG, CMD_OPTIONAL,
4591 "list all normal volume fields");
4592 cmd_AddParm(ts, "-quiet", CMD_FLAG, CMD_OPTIONAL, "generate minimal information");
4593 cmd_AddParm(ts, "-extended", CMD_FLAG, CMD_OPTIONAL,
4594 "list extended volume fields");
4595 #ifdef FULL_LISTVOL_SWITCH
4596 cmd_AddParm(ts, "-format", CMD_FLAG, CMD_OPTIONAL,
4597 "machine readable format");
4598 #endif /* FULL_LISTVOL_SWITCH */
4601 ts = cmd_CreateSyntax("syncvldb", SyncVldb, 0, "synchronize VLDB with server");
4602 cmd_AddParm(ts, "-server", CMD_SINGLE, CMD_OPTIONAL, "machine name");
4603 cmd_AddParm(ts, "-partition", CMD_SINGLE,CMD_OPTIONAL , "partition name");
4604 cmd_AddParm(ts, "-volume", CMD_SINGLE,CMD_OPTIONAL , "volume name or ID");
4607 ts = cmd_CreateSyntax("syncserv", SyncServer, 0, "synchronize server with VLDB");
4608 cmd_AddParm(ts, "-server", CMD_SINGLE, 0, "machine name");
4609 cmd_AddParm(ts, "-partition", CMD_SINGLE,CMD_OPTIONAL , "partition name");
4612 ts = cmd_CreateSyntax("examine", ExamineVolume, 0, "everything about the volume");
4613 cmd_AddParm(ts, "-id", CMD_SINGLE, 0, "volume name or ID");
4614 cmd_AddParm(ts, "-extended", CMD_FLAG, CMD_OPTIONAL,
4615 "list extended volume fields");
4616 #ifdef FULL_LISTVOL_SWITCH
4617 cmd_AddParm(ts, "-format", CMD_FLAG, CMD_OPTIONAL,
4618 "machine readable format");
4619 #endif /* FULL_LISTVOL_SWITCH */
4621 cmd_CreateAlias (ts, "volinfo");
4623 ts = cmd_CreateSyntax("setfields", SetFields, 0, "change volume info fields");
4624 cmd_AddParm(ts, "-id", CMD_SINGLE, 0, "volume name or ID");
4625 cmd_AddParm(ts, "-maxquota", CMD_SINGLE, CMD_OPTIONAL, "quota (KB)");
4626 cmd_AddParm(ts, "-clearuse", CMD_FLAG, CMD_OPTIONAL, "clear dayUse");
4629 ts = cmd_CreateSyntax("offline", volOffline, 0, (char *) CMD_HIDDEN);
4630 cmd_AddParm(ts, "-server", CMD_SINGLE, 0, "server name");
4631 cmd_AddParm(ts, "-partition", CMD_SINGLE, 0, "partition name");
4632 cmd_AddParm(ts, "-id", CMD_SINGLE, 0, "volume name or ID");
4633 cmd_AddParm(ts, "-sleep", CMD_SINGLE, CMD_OPTIONAL, "seconds to sleep");
4634 cmd_AddParm(ts, "-busy", CMD_FLAG, CMD_OPTIONAL, "busy volume");
4637 ts = cmd_CreateSyntax("online", volOnline, 0, (char *) CMD_HIDDEN);
4638 cmd_AddParm(ts, "-server", CMD_SINGLE, 0, "server name");
4639 cmd_AddParm(ts, "-partition", CMD_SINGLE, 0, "partition name");
4640 cmd_AddParm(ts, "-id", CMD_SINGLE, 0, "volume name or ID");
4643 ts = cmd_CreateSyntax("zap", VolumeZap, 0, "delete the volume, don't bother with VLDB");
4644 cmd_AddParm(ts, "-server", CMD_SINGLE, 0, "machine name");
4645 cmd_AddParm(ts, "-partition", CMD_SINGLE, 0, "partition name");
4646 cmd_AddParm(ts, "-id", CMD_SINGLE, 0, "volume ID");
4647 cmd_AddParm(ts, "-force", CMD_FLAG, CMD_OPTIONAL, "force deletion of bad volumes");
4648 cmd_AddParm(ts, "-backup", CMD_FLAG, CMD_OPTIONAL, "also delete backup volume if one is found");
4651 ts = cmd_CreateSyntax("status", VolserStatus, 0, "report on volser status");
4652 cmd_AddParm(ts, "-server", CMD_SINGLE, 0, "machine name");
4655 ts = cmd_CreateSyntax("rename", RenameVolume, 0, "rename a volume");
4656 cmd_AddParm(ts, "-oldname", CMD_SINGLE, 0, "old volume name ");
4657 cmd_AddParm(ts, "-newname", CMD_SINGLE, 0, "new volume name ");
4660 ts = cmd_CreateSyntax("listvldb", ListVLDB, 0, "list volumes in the VLDB");
4661 cmd_AddParm(ts, "-name", CMD_SINGLE,CMD_OPTIONAL, "volume name or ID");
4662 cmd_AddParm(ts, "-server", CMD_SINGLE,CMD_OPTIONAL, "machine name");
4663 cmd_AddParm(ts, "-partition", CMD_SINGLE,CMD_OPTIONAL, "partition name");
4664 cmd_AddParm(ts, "-locked", CMD_FLAG, CMD_OPTIONAL, "locked volumes only");
4665 cmd_AddParm(ts, "-quiet", CMD_FLAG, CMD_OPTIONAL, "generate minimal information");
4666 cmd_AddParm(ts, "-nosort", CMD_FLAG, CMD_OPTIONAL, "do not alphabetically sort the volume names");
4669 ts = cmd_CreateSyntax("backupsys", BackSys, 0, "en masse backups");
4670 cmd_AddParm(ts, "-prefix", CMD_LIST,CMD_OPTIONAL, "common prefix on volume(s)");
4671 cmd_AddParm(ts, "-server", CMD_SINGLE,CMD_OPTIONAL, "machine name");
4672 cmd_AddParm(ts, "-partition", CMD_SINGLE,CMD_OPTIONAL, "partition name");
4673 cmd_AddParm(ts, "-exclude", CMD_FLAG, CMD_OPTIONAL, "exclude common prefix volumes");
4674 cmd_AddParm(ts, "-xprefix", CMD_LIST, CMD_OPTIONAL, "negative prefix on volume(s)");
4675 cmd_AddParm(ts, "-dryrun", CMD_FLAG, CMD_OPTIONAL, "no action");
4678 ts = cmd_CreateSyntax("delentry", DeleteEntry, 0, "delete VLDB entry for a volume");
4679 cmd_AddParm(ts, "-id", CMD_LIST, CMD_OPTIONAL, "volume name or ID");
4680 cmd_AddParm(ts, "-prefix", CMD_SINGLE,CMD_OPTIONAL, "prefix of the volume whose VLDB entry is to be deleted");
4681 cmd_AddParm(ts, "-server", CMD_SINGLE,CMD_OPTIONAL, "machine name");
4682 cmd_AddParm(ts, "-partition", CMD_SINGLE,CMD_OPTIONAL, "partition name");
4683 cmd_AddParm(ts, "-noexecute", CMD_FLAG,CMD_OPTIONAL|CMD_HIDE, "no execute");
4686 ts = cmd_CreateSyntax("partinfo", PartitionInfo, 0, "list partition information");
4687 cmd_AddParm(ts, "-server", CMD_SINGLE, 0, "machine name");
4688 cmd_AddParm(ts, "-partition", CMD_SINGLE,CMD_OPTIONAL, "partition name");
4691 ts = cmd_CreateSyntax("unlockvldb", UnlockVLDB, 0, "unlock all the locked entries in the VLDB");
4692 cmd_AddParm(ts, "-server", CMD_SINGLE,CMD_OPTIONAL, "machine name");
4693 cmd_AddParm(ts, "-partition", CMD_SINGLE,CMD_OPTIONAL, "partition name");
4696 ts = cmd_CreateSyntax("lock", LockEntry, 0, "lock VLDB entry for a volume");
4697 cmd_AddParm(ts, "-id", CMD_SINGLE, 0, "volume name or ID");
4700 ts = cmd_CreateSyntax("changeaddr", ChangeAddr, 0, "change the IP address of a file server");
4701 cmd_AddParm(ts, "-oldaddr", CMD_SINGLE, 0, "original IP address");
4702 cmd_AddParm(ts, "-newaddr", CMD_SINGLE, CMD_OPTIONAL, "new IP address");
4703 cmd_AddParm(ts, "-remove", CMD_FLAG, CMD_OPTIONAL, "remove the IP address from the VLDB");
4706 ts = cmd_CreateSyntax("listaddrs", ListAddrs, 0, "list the IP address of all file servers registered in the VLDB");
4707 cmd_AddParm(ts, "-uuid", CMD_SINGLE, CMD_OPTIONAL, "uuid of server");
4708 cmd_AddParm(ts, "-host", CMD_SINGLE, CMD_OPTIONAL, "address of host");
4709 cmd_AddParm(ts, "-noresolve", CMD_FLAG, CMD_OPTIONAL, "don't resolve addresses");
4710 cmd_AddParm(ts, "-printuuid", CMD_FLAG, CMD_OPTIONAL, "print uuid of hosts");
4713 ts = cmd_CreateSyntax("convertROtoRW", ConvertRO, 0, "convert a RO volume into a RW volume (after loss of old RW volume)");
4714 cmd_AddParm(ts, "-server", CMD_SINGLE,0, "machine name");
4715 cmd_AddParm(ts, "-partition", CMD_SINGLE,0, "partition name");
4716 cmd_AddParm(ts, "-id", CMD_SINGLE, 0, "volume name or ID");
4717 cmd_AddParm(ts, "-force", CMD_FLAG, CMD_OPTIONAL, "don't ask");
4720 ts = cmd_CreateSyntax("size", Sizes, 0, "obtain various sizes of the volume.");
4721 cmd_AddParm(ts, "-id", CMD_SINGLE, 0, "volume name or ID");
4722 cmd_AddParm(ts, "-partition", CMD_SINGLE, CMD_OPTIONAL, "partition name");
4723 cmd_AddParm(ts, "-server", CMD_SINGLE, CMD_OPTIONAL, "machine name");
4724 cmd_AddParm(ts, "-dump", CMD_FLAG, CMD_OPTIONAL, "Obtain the size of the dump");
4725 cmd_AddParm(ts, "-time", CMD_SINGLE, CMD_OPTIONAL, "dump from time");
4728 code = cmd_Dispatch(argc, argv);
4730 /* Shut down the ubik_client and rx connections */
4732 (void) ubik_ClientDestroy (cstruct);