2 * Copyright 2000, International Business Machines Corporation and others.
5 * This software has been released under the terms of the IBM Public
6 * License. For details, see the LICENSE file in the top-level source
7 * directory or online at http://www.openafs.org/dl/license10.html
10 #include <afsconfig.h>
11 #include <afs/param.h>
16 #include <sys/types.h>
25 #include <netinet/in.h>
29 #include <sys/statfs.h>
45 #include <rx/rx_globals.h>
47 #include <afs/vlserver.h>
49 #include <afs/cellconfig.h>
51 #include <afs/afsutil.h>
53 #include <afs/afsint.h>
63 #include "volser_prototypes.h"
76 struct hostent *hostutil_GetHostByName(register char *ahost);
78 #define COMMONPARMS cmd_Seek(ts, 12);\
79 cmd_AddParm(ts, "-cell", CMD_SINGLE, CMD_OPTIONAL, "cell name");\
80 cmd_AddParm(ts, "-noauth", CMD_FLAG, CMD_OPTIONAL, "don't authenticate");\
81 cmd_AddParm(ts, "-localauth",CMD_FLAG,CMD_OPTIONAL,"use server tickets");\
82 cmd_AddParm(ts, "-verbose", CMD_FLAG, CMD_OPTIONAL, "verbose");\
83 cmd_AddParm(ts, "-encrypt", CMD_FLAG, CMD_OPTIONAL, "encrypt commands");\
85 #define ERROR_EXIT(code) {error=(code); goto error_exit;}
89 struct rx_connection *tconn;
91 extern struct ubik_client *cstruct;
93 extern struct rx_connection *UV_Bind();
94 extern int UV_SetSecurity();
95 extern int UV_SetVolumeInfo();
96 extern int vsu_SetCrypt();
98 extern VL_ReleaseLock();
99 extern VL_DeleteEntry();
100 extern VL_ListEntry();
101 extern VL_GetAddrs();
102 extern VL_GetAddrsU();
103 extern VL_ChangeAddr();
105 extern int vsu_ExtractName();
107 extern void EnumerateEntry();
108 extern void SubEnumerateEntry();
111 static struct tqHead busyHead, notokHead;
115 struct tqHead *ahead;
117 memset((char *)ahead, 0, sizeof(struct tqHead));
124 struct tqHead *ahead;
129 elem = (struct tqElem *)malloc(sizeof(struct tqElem));
130 elem->next = ahead->next;
139 struct tqHead *ahead;
144 if (ahead->count <= 0)
146 *volid = ahead->next->volid;
148 ahead->next = tmp->next;
154 /* returns 1 if <filename> exists else 0 */
163 code = usd_Open(filename, USD_OPEN_RDONLY, 0, &ufd);
167 code = USD_IOCTL(ufd, USD_IOCTL_GETSIZE, &size);
175 /* returns 1 if <name> doesnot end in .readonly or .backup, else 0 */
183 total = strlen(name);
184 if (!strcmp(&name[total - 9], ".readonly")) {
186 } else if (!strcmp(&name[total - 7], ".backup")) {
193 /* return 1 if name is a number else 0 */
204 for (i = 0; i < len; i++) {
205 if (*ptr < '0' || *ptr > '9') {
219 * Parse a server name/address and return the address in HOST BYTE order
225 register struct hostent *th;
228 register afs_int32 code;
229 char hostname[MAXHOSTCHARS];
231 code = sscanf(aname, "%d.%d.%d.%d", &b1, &b2, &b3, &b4);
233 addr = (b1 << 24) | (b2 << 16) | (b3 << 8) | b4;
234 addr = ntohl(addr); /* convert to host order */
236 th = gethostbyname(aname);
239 memcpy(&addr, th->h_addr, sizeof(addr));
242 if (addr == htonl(0x7f000001)) { /* local host */
243 code = gethostname(hostname, MAXHOSTCHARS);
246 th = gethostbyname(hostname); /* returns host byte order */
249 memcpy(&addr, th->h_addr, sizeof(addr));
260 if (!strcmp(aname, "ro"))
262 else if (!strcmp(aname, "rw"))
264 else if (!strcmp(aname, "bk"))
271 IsPartValid(partId, server, code)
272 afs_int32 server, partId, *code;
275 struct partList dummyPartList;
283 *code = UV_ListPartitions(server, &dummyPartList, &cnt);
286 for (i = 0; i < cnt; i++) {
287 if (dummyPartList.partFlags[i] & PARTVALID)
288 if (dummyPartList.partId[i] == partId)
296 /*sends the contents of file associated with <fd> and <blksize> to Rx Stream
297 * associated with <call> */
298 SendFile(ufd, call, blksize)
300 register struct rx_call *call;
303 char *buffer = (char *)0;
308 buffer = (char *)malloc(blksize);
310 fprintf(STDERR, "malloc failed\n");
314 while (!error && !done) {
315 #ifndef AFS_NT40_ENV /* NT csn't select on non-socket fd's */
318 FD_SET((int)(ufd->handle), &in);
319 /* don't timeout if read blocks */
320 IOMGR_Select(((int)(ufd->handle)) + 1, &in, 0, 0, 0);
322 error = USD_READ(ufd, buffer, blksize, &nbytes);
324 fprintf(STDERR, "File system read failed\n");
331 if (rx_Write(call, buffer, nbytes) != nbytes) {
341 /* function invoked by UV_RestoreVolume, reads the data from rx_trx_stream and
342 * writes it out to the volume. */
344 WriteData(call, rock)
345 struct rx_call *call;
351 afs_int32 error, code;
357 if (!filename || !*filename) {
358 usd_StandardInput(&ufd);
362 code = usd_Open(filename, USD_OPEN_RDONLY, 0, &ufd);
365 code = USD_IOCTL(ufd, USD_IOCTL_GETBLKSIZE, &blksize);
368 fprintf(STDERR, "Could not access file '%s'\n", filename);
373 code = SendFile(ufd, call, blksize);
380 code = USD_CLOSE(ufd);
382 fprintf(STDERR, "Could not close dump file %s\n",
383 (filename && *filename) ? filename : "STDOUT");
391 /* Receive data from <call> stream into file associated
392 * with <fd> <blksize>
395 ReceiveFile(ufd, call, blksize)
397 struct rx_call *call;
402 afs_uint32 bytesleft, w;
405 buffer = (char *)malloc(blksize);
407 fprintf(STDERR, "memory allocation failed\n");
411 while ((bytesread = rx_Read(call, buffer, blksize)) > 0) {
412 for (bytesleft = bytesread; bytesleft; bytesleft -= w) {
413 #ifndef AFS_NT40_ENV /* NT csn't select on non-socket fd's */
416 FD_SET((int)(ufd->handle), &out);
417 /* don't timeout if write blocks */
418 IOMGR_Select(((int)(ufd->handle)) + 1, 0, &out, 0, 0);
421 USD_WRITE(ufd, &buffer[bytesread - bytesleft], bytesleft, &w);
423 fprintf(STDERR, "File system write failed\n");
436 DumpFunction(call, filename)
437 struct rx_call *call;
440 usd_handle_t ufd; /* default is to stdout */
441 afs_int32 error = 0, code;
446 /* Open the output file */
447 if (!filename || !*filename) {
448 usd_StandardOutput(&ufd);
453 usd_Open(filename, USD_OPEN_CREATE | USD_OPEN_RDWR, 0666, &ufd);
457 code = USD_IOCTL(ufd, USD_IOCTL_SETSIZE, &size);
460 code = USD_IOCTL(ufd, USD_IOCTL_GETBLKSIZE, &blksize);
463 fprintf(STDERR, "Could not create file '%s'\n", filename);
464 ERROR_EXIT(VOLSERBADOP);
468 code = ReceiveFile(ufd, call, blksize);
473 /* Close the output file */
475 code = USD_CLOSE(ufd);
477 fprintf(STDERR, "Could not close dump file %s\n",
478 (filename && *filename) ? filename : "STDIN");
488 DisplayFormat(pntr, server, part, totalOK, totalNotOK, totalBusy, fast,
491 afs_int32 server, part;
492 int *totalOK, *totalNotOK, *totalBusy;
493 int fast, longlist, disp;
498 fprintf(STDOUT, "%-10lu\n", (unsigned long)pntr->volid);
499 } else if (longlist) {
500 if (pntr->status == VOK) {
501 fprintf(STDOUT, "%-32s ", pntr->name);
502 fprintf(STDOUT, "%10lu ", (unsigned long)pntr->volid);
504 fprintf(STDOUT, "RW ");
506 fprintf(STDOUT, "RO ");
508 fprintf(STDOUT, "BK ");
509 fprintf(STDOUT, "%10d K ", pntr->size);
510 if (pntr->inUse == 1) {
511 fprintf(STDOUT, "On-line");
514 fprintf(STDOUT, "Off-line");
517 if (pntr->needsSalvaged == 1)
518 fprintf(STDOUT, "**needs salvage**");
519 fprintf(STDOUT, "\n");
520 MapPartIdIntoName(part, pname);
521 fprintf(STDOUT, " %s %s \n", hostutil_GetNameByINet(server),
523 fprintf(STDOUT, " RWrite %10lu ROnly %10lu Backup %10lu \n",
524 (unsigned long)pntr->parentID,
525 (unsigned long)pntr->cloneID,
526 (unsigned long)pntr->backupID);
527 fprintf(STDOUT, " MaxQuota %10d K \n", pntr->maxquota);
528 fprintf(STDOUT, " Creation %s",
529 ctime((time_t *) & pntr->creationDate));
530 #ifdef FULL_LISTVOL_SWITCH
531 fprintf(STDOUT, " Copy %s",
532 ctime((time_t *) & pntr->copyDate));
533 if (!pntr->backupDate)
534 fprintf(STDOUT, " Backup Never\n");
536 fprintf(STDOUT, " Backup %s",
537 ctime((time_t *) & pntr->backupDate));
538 if (pntr->accessDate)
539 fprintf(STDOUT, " Last Access %s",
540 ctime((time_t *) & pntr->accessDate));
542 if (pntr->updateDate < pntr->creationDate)
543 fprintf(STDOUT, " Last Update %s",
544 ctime((time_t *) & pntr->creationDate));
546 fprintf(STDOUT, " Last Update %s",
547 ctime((time_t *) & pntr->updateDate));
549 " %d accesses in the past day (i.e., vnode references)\n",
551 } else if (pntr->status == VBUSY) {
553 qPut(&busyHead, pntr->volid);
555 fprintf(STDOUT, "**** Volume %lu is busy ****\n",
556 (unsigned long)pntr->volid);
559 qPut(¬okHead, pntr->volid);
561 fprintf(STDOUT, "**** Could not attach volume %lu ****\n",
562 (unsigned long)pntr->volid);
564 fprintf(STDOUT, "\n");
565 } else { /* default listing */
566 if (pntr->status == VOK) {
567 fprintf(STDOUT, "%-32s ", pntr->name);
568 fprintf(STDOUT, "%10lu ", (unsigned long)pntr->volid);
570 fprintf(STDOUT, "RW ");
572 fprintf(STDOUT, "RO ");
574 fprintf(STDOUT, "BK ");
575 fprintf(STDOUT, "%10d K ", pntr->size);
576 if (pntr->inUse == 1) {
577 fprintf(STDOUT, "On-line");
580 fprintf(STDOUT, "Off-line");
583 if (pntr->needsSalvaged == 1)
584 fprintf(STDOUT, "**needs salvage**");
585 fprintf(STDOUT, "\n");
586 } else if (pntr->status == VBUSY) {
588 qPut(&busyHead, pntr->volid);
590 fprintf(STDOUT, "**** Volume %lu is busy ****\n",
591 (unsigned long)pntr->volid);
594 qPut(¬okHead, pntr->volid);
596 fprintf(STDOUT, "**** Could not attach volume %lu ****\n",
597 (unsigned long)pntr->volid);
602 /*------------------------------------------------------------------------
603 * PRIVATE XDisplayFormat
606 * Display the contents of one extended volume info structure.
609 * a_xInfoP : Ptr to extended volume info struct to print.
610 * a_servID : Server ID to print.
611 * a_partID : Partition ID to print.
612 * a_totalOKP : Ptr to total-OK counter.
613 * a_totalNotOKP : Ptr to total-screwed counter.
614 * a_totalBusyP : Ptr to total-busy counter.
615 * a_fast : Fast listing?
616 * a_int32 : Int32 listing?
617 * a_showProblems : Show volume problems?
623 * Nothing interesting.
627 *------------------------------------------------------------------------*/
630 XDisplayFormat(a_xInfoP, a_servID, a_partID, a_totalOKP, a_totalNotOKP,
631 a_totalBusyP, a_fast, a_int32, a_showProblems)
632 volintXInfo *a_xInfoP;
642 { /*XDisplayFormat */
650 fprintf(STDOUT, "%-10lu\n", (unsigned long)a_xInfoP->volid);
651 } else if (a_int32) {
653 * Fully-detailed listing.
655 if (a_xInfoP->status == VOK) {
657 * Volume's status is OK - all the fields are valid.
659 fprintf(STDOUT, "%-32s ", a_xInfoP->name);
660 fprintf(STDOUT, "%10lu ", (unsigned long)a_xInfoP->volid);
661 if (a_xInfoP->type == 0)
662 fprintf(STDOUT, "RW ");
663 if (a_xInfoP->type == 1)
664 fprintf(STDOUT, "RO ");
665 if (a_xInfoP->type == 2)
666 fprintf(STDOUT, "BK ");
667 fprintf(STDOUT, "%10d K used ", a_xInfoP->size);
668 fprintf(STDOUT, "%d files ", a_xInfoP->filecount);
669 if (a_xInfoP->inUse == 1) {
670 fprintf(STDOUT, "On-line");
673 fprintf(STDOUT, "Off-line");
676 fprintf(STDOUT, "\n");
677 MapPartIdIntoName(a_partID, pname);
678 fprintf(STDOUT, " %s %s \n", hostutil_GetNameByINet(a_servID),
680 fprintf(STDOUT, " RWrite %10lu ROnly %10lu Backup %10lu \n",
681 (unsigned long)a_xInfoP->parentID,
682 (unsigned long)a_xInfoP->cloneID,
683 (unsigned long)a_xInfoP->backupID);
684 fprintf(STDOUT, " MaxQuota %10d K \n", a_xInfoP->maxquota);
685 fprintf(STDOUT, " Creation %s",
686 ctime((time_t *) & a_xInfoP->creationDate));
687 #ifdef FULL_LISTVOL_SWITCH
688 fprintf(STDOUT, " Copy %s",
689 ctime((time_t *) & a_xInfoP->copyDate));
690 if (!a_xInfoP->backupDate)
691 fprintf(STDOUT, " Backup Never\n");
693 fprintf(STDOUT, " Backup %s",
694 ctime((time_t *) & a_xInfoP->backupDate));
695 if (a_xInfoP->accessDate)
696 fprintf(STDOUT, " Last Access %s",
697 ctime((time_t *) & a_xInfoP->accessDate));
699 if (a_xInfoP->updateDate < a_xInfoP->creationDate)
700 fprintf(STDOUT, " Last Update %s",
701 ctime((time_t *) & a_xInfoP->creationDate));
703 fprintf(STDOUT, " Last Update %s",
704 ctime((time_t *) & a_xInfoP->updateDate));
706 " %d accesses in the past day (i.e., vnode references)\n",
710 * Print all the read/write and authorship stats.
712 fprintf(STDOUT, "\n Raw Read/Write Stats\n");
714 " |-------------------------------------------|\n");
716 " | Same Network | Diff Network |\n");
718 " |----------|----------|----------|----------|\n");
720 " | Total | Auth | Total | Auth |\n");
722 " |----------|----------|----------|----------|\n");
723 fprintf(STDOUT, "Reads | %8d | %8d | %8d | %8d |\n",
724 a_xInfoP->stat_reads[VOLINT_STATS_SAME_NET],
725 a_xInfoP->stat_reads[VOLINT_STATS_SAME_NET_AUTH],
726 a_xInfoP->stat_reads[VOLINT_STATS_DIFF_NET],
727 a_xInfoP->stat_reads[VOLINT_STATS_DIFF_NET_AUTH]);
728 fprintf(STDOUT, "Writes | %8d | %8d | %8d | %8d |\n",
729 a_xInfoP->stat_writes[VOLINT_STATS_SAME_NET],
730 a_xInfoP->stat_writes[VOLINT_STATS_SAME_NET_AUTH],
731 a_xInfoP->stat_writes[VOLINT_STATS_DIFF_NET],
732 a_xInfoP->stat_writes[VOLINT_STATS_DIFF_NET_AUTH]);
734 " |-------------------------------------------|\n\n");
737 " Writes Affecting Authorship\n");
739 " |-------------------------------------------|\n");
741 " | File Authorship | Directory Authorship|\n");
743 " |----------|----------|----------|----------|\n");
745 " | Same | Diff | Same | Diff |\n");
747 " |----------|----------|----------|----------|\n");
748 fprintf(STDOUT, "0-60 sec | %8d | %8d | %8d | %8d |\n",
749 a_xInfoP->stat_fileSameAuthor[VOLINT_STATS_TIME_IDX_0],
750 a_xInfoP->stat_fileDiffAuthor[VOLINT_STATS_TIME_IDX_0],
751 a_xInfoP->stat_dirSameAuthor[VOLINT_STATS_TIME_IDX_0],
752 a_xInfoP->stat_dirDiffAuthor[VOLINT_STATS_TIME_IDX_0]);
753 fprintf(STDOUT, "1-10 min | %8d | %8d | %8d | %8d |\n",
754 a_xInfoP->stat_fileSameAuthor[VOLINT_STATS_TIME_IDX_1],
755 a_xInfoP->stat_fileDiffAuthor[VOLINT_STATS_TIME_IDX_1],
756 a_xInfoP->stat_dirSameAuthor[VOLINT_STATS_TIME_IDX_1],
757 a_xInfoP->stat_dirDiffAuthor[VOLINT_STATS_TIME_IDX_1]);
758 fprintf(STDOUT, "10min-1hr | %8d | %8d | %8d | %8d |\n",
759 a_xInfoP->stat_fileSameAuthor[VOLINT_STATS_TIME_IDX_2],
760 a_xInfoP->stat_fileDiffAuthor[VOLINT_STATS_TIME_IDX_2],
761 a_xInfoP->stat_dirSameAuthor[VOLINT_STATS_TIME_IDX_2],
762 a_xInfoP->stat_dirDiffAuthor[VOLINT_STATS_TIME_IDX_2]);
763 fprintf(STDOUT, "1hr-1day | %8d | %8d | %8d | %8d |\n",
764 a_xInfoP->stat_fileSameAuthor[VOLINT_STATS_TIME_IDX_3],
765 a_xInfoP->stat_fileDiffAuthor[VOLINT_STATS_TIME_IDX_3],
766 a_xInfoP->stat_dirSameAuthor[VOLINT_STATS_TIME_IDX_3],
767 a_xInfoP->stat_dirDiffAuthor[VOLINT_STATS_TIME_IDX_3]);
768 fprintf(STDOUT, "1day-1wk | %8d | %8d | %8d | %8d |\n",
769 a_xInfoP->stat_fileSameAuthor[VOLINT_STATS_TIME_IDX_4],
770 a_xInfoP->stat_fileDiffAuthor[VOLINT_STATS_TIME_IDX_4],
771 a_xInfoP->stat_dirSameAuthor[VOLINT_STATS_TIME_IDX_4],
772 a_xInfoP->stat_dirDiffAuthor[VOLINT_STATS_TIME_IDX_4]);
773 fprintf(STDOUT, "> 1wk | %8d | %8d | %8d | %8d |\n",
774 a_xInfoP->stat_fileSameAuthor[VOLINT_STATS_TIME_IDX_5],
775 a_xInfoP->stat_fileDiffAuthor[VOLINT_STATS_TIME_IDX_5],
776 a_xInfoP->stat_dirSameAuthor[VOLINT_STATS_TIME_IDX_5],
777 a_xInfoP->stat_dirDiffAuthor[VOLINT_STATS_TIME_IDX_5]);
779 " |-------------------------------------------|\n");
780 } /*Volume status OK */
781 else if (a_xInfoP->status == VBUSY) {
783 qPut(&busyHead, a_xInfoP->volid);
785 fprintf(STDOUT, "**** Volume %lu is busy ****\n",
786 (unsigned long)a_xInfoP->volid);
790 qPut(¬okHead, a_xInfoP->volid);
792 fprintf(STDOUT, "**** Could not attach volume %lu ****\n",
793 (unsigned long)a_xInfoP->volid);
794 } /*Screwed volume */
795 fprintf(STDOUT, "\n");
801 if (a_xInfoP->status == VOK) {
802 fprintf(STDOUT, "%-32s ", a_xInfoP->name);
803 fprintf(STDOUT, "%10lu ", (unsigned long)a_xInfoP->volid);
804 if (a_xInfoP->type == 0)
805 fprintf(STDOUT, "RW ");
806 if (a_xInfoP->type == 1)
807 fprintf(STDOUT, "RO ");
808 if (a_xInfoP->type == 2)
809 fprintf(STDOUT, "BK ");
810 fprintf(STDOUT, "%10d K ", a_xInfoP->size);
811 if (a_xInfoP->inUse == 1) {
812 fprintf(STDOUT, "On-line");
815 fprintf(STDOUT, "Off-line");
818 fprintf(STDOUT, "\n");
820 else if (a_xInfoP->status == VBUSY) {
822 qPut(&busyHead, a_xInfoP->volid);
824 fprintf(STDOUT, "**** Volume %lu is busy ****\n",
825 (unsigned long)a_xInfoP->volid);
829 qPut(¬okHead, a_xInfoP->volid);
831 fprintf(STDOUT, "**** Could not attach volume %lu ****\n",
832 (unsigned long)a_xInfoP->volid);
833 } /*Screwed volume */
834 } /*Default listing */
835 } /*XDisplayFormat */
837 #ifdef FULL_LISTVOL_SWITCH
839 DisplayFormat2(server, partition, pntr)
840 long server, partition;
843 static long server_cache = -1, partition_cache = -1;
844 static char hostname[256], address[32], pname[16];
846 if (server != server_cache) {
850 strcpy(hostname, hostutil_GetNameByINet(server));
851 strcpy(address, inet_ntoa(s));
852 server_cache = server;
854 if (partition != partition_cache) {
855 MapPartIdIntoName(partition, pname);
856 partition_cache = partition;
858 fprintf(STDOUT, "name\t\t%s\n", pntr->name);
859 fprintf(STDOUT, "id\t\t%lu\n", pntr->volid);
860 fprintf(STDOUT, "serv\t\t%s\t%s\n", address, hostname);
861 fprintf(STDOUT, "part\t\t%s\n", pname);
862 switch (pntr->status) {
864 fprintf(STDOUT, "status\t\tOK\n");
867 fprintf(STDOUT, "status\t\tBUSY\n");
870 fprintf(STDOUT, "status\t\tUNATTACHABLE\n");
873 fprintf(STDOUT, "backupID\t%lu\n", pntr->backupID);
874 fprintf(STDOUT, "parentID\t%lu\n", pntr->parentID);
875 fprintf(STDOUT, "cloneID\t\t%lu\n", pntr->cloneID);
876 fprintf(STDOUT, "inUse\t\t%s\n", pntr->inUse ? "Y" : "N");
877 fprintf(STDOUT, "needsSalvaged\t%s\n", pntr->needsSalvaged ? "Y" : "N");
878 /* 0xD3 is from afs/volume.h since I had trouble including the file */
879 fprintf(STDOUT, "destroyMe\t%s\n", pntr->destroyMe == 0xD3 ? "Y" : "N");
880 switch (pntr->type) {
882 fprintf(STDOUT, "type\t\tRW\n");
885 fprintf(STDOUT, "type\t\tRO\n");
888 fprintf(STDOUT, "type\t\tBK\n");
891 fprintf(STDOUT, "type\t\t?\n");
894 fprintf(STDOUT, "creationDate\t%-9lu\t%s", pntr->creationDate,
895 ctime(&pntr->creationDate));
896 fprintf(STDOUT, "accessDate\t%-9lu\t%s", pntr->accessDate,
897 ctime(&pntr->accessDate));
898 fprintf(STDOUT, "updateDate\t%-9lu\t%s", pntr->updateDate,
899 ctime(&pntr->updateDate));
900 fprintf(STDOUT, "backupDate\t%-9lu\t%s", pntr->backupDate,
901 ctime(&pntr->backupDate));
902 fprintf(STDOUT, "copyDate\t%-9lu\t%s", pntr->copyDate,
903 ctime(&pntr->copyDate));
904 fprintf(STDOUT, "flags\t\t%#lx\t(Optional)\n", pntr->flags);
905 fprintf(STDOUT, "diskused\t%u\n", pntr->size);
906 fprintf(STDOUT, "maxquota\t%u\n", pntr->maxquota);
907 fprintf(STDOUT, "minquota\t%lu\t(Optional)\n", pntr->spare0);
908 fprintf(STDOUT, "filecount\t%u\n", pntr->filecount);
909 fprintf(STDOUT, "dayUse\t\t%u\n", pntr->dayUse);
910 fprintf(STDOUT, "weekUse\t\t%lu\t(Optional)\n", pntr->spare1);
911 fprintf(STDOUT, "spare2\t\t%lu\t(Optional)\n", pntr->spare2);
912 fprintf(STDOUT, "spare3\t\t%lu\t(Optional)\n", pntr->spare3);
917 DisplayVolumes2(server, partition, pntr, count)
919 long server, partition, count;
923 for (i = 0; i < count; i++) {
924 fprintf(STDOUT, "BEGIN_OF_ENTRY\n");
925 DisplayFormat2(server, partition, pntr);
926 fprintf(STDOUT, "END_OF_ENTRY\n\n");
931 #endif /* FULL_LISTVOL_SWITCH */
934 DisplayVolumes(server, part, pntr, count, longlist, fast, quiet)
935 afs_int32 server, part;
937 afs_int32 count, longlist, fast;
940 int totalOK, totalNotOK, totalBusy, i;
948 for (i = 0; i < count; i++) {
949 DisplayFormat(pntr, server, part, &totalOK, &totalNotOK, &totalBusy,
954 while (busyHead.count) {
955 qGet(&busyHead, &volid);
956 fprintf(STDOUT, "**** Volume %lu is busy ****\n",
957 (unsigned long)volid);
961 while (notokHead.count) {
962 qGet(¬okHead, &volid);
963 fprintf(STDOUT, "**** Could not attach volume %lu ****\n",
964 (unsigned long)volid);
968 fprintf(STDOUT, "\n");
971 "Total volumes onLine %d ; Total volumes offLine %d ; Total busy %d\n\n",
972 totalOK, totalNotOK, totalBusy);
977 /*------------------------------------------------------------------------
978 * PRIVATE XDisplayVolumes
981 * Display extended volume information.
984 * a_servID : Pointer to the Rx call we're performing.
985 * a_partID : Partition for which we want the extended list.
986 * a_xInfoP : Ptr to extended volume info.
987 * a_count : Number of volume records contained above.
988 * a_int32 : Int32 listing generated?
989 * a_fast : Fast listing generated?
990 * a_quiet : Quiet listing generated?
996 * Nothing interesting.
1000 *------------------------------------------------------------------------*/
1003 XDisplayVolumes(a_servID, a_partID, a_xInfoP, a_count, a_int32, a_fast,
1007 volintXInfo *a_xInfoP;
1013 { /*XDisplayVolumes */
1015 int totalOK; /*Total OK volumes */
1016 int totalNotOK; /*Total screwed volumes */
1017 int totalBusy; /*Total busy volumes */
1018 int i; /*Loop variable */
1019 afs_int32 volid; /*Current volume ID */
1022 * Initialize counters and (global!!) queues.
1031 * Display each volume in the list.
1033 for (i = 0; i < a_count; i++) {
1034 XDisplayFormat(a_xInfoP, a_servID, a_partID, &totalOK, &totalNotOK,
1035 &totalBusy, a_fast, a_int32, 0);
1040 * If any volumes were found to be busy or screwed, display them.
1043 while (busyHead.count) {
1044 qGet(&busyHead, &volid);
1045 fprintf(STDOUT, "**** Volume %lu is busy ****\n",
1046 (unsigned long)volid);
1050 while (notokHead.count) {
1051 qGet(¬okHead, &volid);
1052 fprintf(STDOUT, "**** Could not attach volume %lu ****\n",
1053 (unsigned long)volid);
1058 fprintf(STDOUT, "\n");
1061 "Total volumes: %d on-line, %d off-line, %d busyd\n\n",
1062 totalOK, totalNotOK, totalBusy);
1066 } /*XDisplayVolumes */
1068 /* set <server> and <part> to the correct values depending on
1069 * <voltype> and <entry> */
1071 GetServerAndPart(entry, voltype, server, part, previdx)
1072 struct nvldbentry *entry;
1073 afs_int32 *server, *part;
1077 int i, istart, vtype;
1082 /* Doesn't check for non-existance of backup volume */
1083 if ((voltype == RWVOL) || (voltype == BACKVOL)) {
1085 istart = 0; /* seach the entire entry */
1088 /* Seach from beginning of entry or pick up where we left off */
1089 istart = ((*previdx < 0) ? 0 : *previdx + 1);
1092 for (i = istart; i < entry->nServers; i++) {
1093 if (entry->serverFlags[i] & vtype) {
1094 *server = entry->serverNumber[i];
1095 *part = entry->serverPartition[i];
1101 /* Didn't find any, return -1 */
1107 PostVolumeStats(entry)
1108 struct nvldbentry *entry;
1110 SubEnumerateEntry(entry);
1111 /* Check for VLOP_ALLOPERS */
1112 if (entry->flags & VLOP_ALLOPERS)
1113 fprintf(STDOUT, " Volume is currently LOCKED \n");
1117 /*------------------------------------------------------------------------
1118 * PRIVATE XVolumeStats
1121 * Display extended volume information.
1124 * a_xInfoP : Ptr to extended volume info.
1125 * a_entryP : Ptr to the volume's VLDB entry.
1126 * a_srvID : Server ID.
1127 * a_partID : Partition ID.
1128 * a_volType : Type of volume to print.
1134 * Nothing interesting.
1138 *------------------------------------------------------------------------*/
1141 XVolumeStats(a_xInfoP, a_entryP, a_srvID, a_partID, a_volType)
1142 volintXInfo *a_xInfoP;
1143 struct nvldbentry *a_entryP;
1150 int totalOK, totalNotOK, totalBusy; /*Dummies - we don't really count here */
1152 XDisplayFormat(a_xInfoP, /*Ptr to extended volume info */
1153 a_srvID, /*Server ID to print */
1154 a_partID, /*Partition ID to print */
1155 &totalOK, /*Ptr to total-OK counter */
1156 &totalNotOK, /*Ptr to total-screwed counter */
1157 &totalBusy, /*Ptr to total-busy counter */
1158 0, /*Don't do a fast listing */
1159 1, /*Do a long listing */
1160 1); /*Show volume problems */
1166 VolumeStats(pntr, entry, server, part, voltype)
1168 struct nvldbentry *entry;
1170 afs_int32 server, part;
1172 int totalOK, totalNotOK, totalBusy;
1173 afs_int32 vcode, vcode2;
1175 DisplayFormat(pntr, server, part, &totalOK, &totalNotOK, &totalBusy, 0, 1,
1180 /* command to forcibly remove a volume */
1183 register struct cmd_syndesc *as;
1185 register afs_int32 code;
1186 afs_int32 volID, err;
1191 server = GetServer(tp = as->parms[0].items->data);
1193 fprintf(STDERR, "vos: server '%s' not found in host table\n", tp);
1197 partID = volutil_GetPartitionID(tp = as->parms[1].items->data);
1199 fprintf(STDERR, "vos: could not parse '%s' as a partition name", tp);
1203 volID = vsu_GetVolumeID(tp = as->parms[2].items->data, cstruct, &err);
1206 PrintError("", err);
1209 "vos: could not parse '%s' as a numeric volume ID", tp);
1214 "vos: forcibly removing all traces of volume %d, please wait...",
1217 code = UV_NukeVolume(server, partID, volID);
1219 fprintf(STDOUT, "done.\n");
1221 fprintf(STDOUT, "failed with code %d.\n", code);
1226 /*------------------------------------------------------------------------
1227 * PRIVATE ExamineVolume
1230 * Routine used to examine a single volume, contacting the VLDB as
1231 * well as the Volume Server.
1234 * as : Ptr to parsed command line arguments.
1237 * 0 for a successful operation,
1238 * Otherwise, one of the ubik or VolServer error values.
1241 * Nothing interesting.
1245 *------------------------------------------------------------------------
1249 register struct cmd_syndesc *as;
1251 struct nvldbentry entry;
1252 afs_int32 vcode = 0;
1253 volintInfo *pntr = (volintInfo *) 0;
1254 volintXInfo *xInfoP = (volintXInfo *) 0;
1256 afs_int32 code, err, error = 0;
1257 int voltype, foundserv = 0, foundentry = 0;
1258 afs_int32 aserver, apart;
1260 int wantExtendedInfo; /*Do we want extended vol info? */
1262 wantExtendedInfo = (as->parms[1].items ? 1 : 0); /* -extended */
1264 volid = vsu_GetVolumeID(as->parms[0].items->data, cstruct, &err); /* -id */
1267 PrintError("", err);
1269 fprintf(STDERR, "Unknown volume ID or name '%s'\n",
1270 as->parms[0].items->data);
1275 fprintf(STDOUT, "Fetching VLDB entry for %lu .. ",
1276 (unsigned long)volid);
1279 vcode = VLDB_GetEntryByID(volid, -1, &entry);
1282 "Could not fetch the entry for volume number %lu from VLDB \n",
1283 (unsigned long)volid);
1287 fprintf(STDOUT, "done\n");
1288 MapHostToNetwork(&entry);
1290 if (entry.volumeId[RWVOL] == volid)
1292 else if (entry.volumeId[BACKVOL] == volid)
1294 else /* (entry.volumeId[ROVOL] == volid) */
1297 do { /* do {...} while (voltype == ROVOL) */
1298 /* Get the entry for the volume. If its a RW vol, get the RW entry.
1299 * It its a BK vol, get the RW entry (even if VLDB may say the BK doen't exist).
1300 * If its a RO vol, get the next RO entry.
1302 GetServerAndPart(&entry, ((voltype == ROVOL) ? ROVOL : RWVOL),
1303 &aserver, &apart, &previdx);
1304 if (previdx == -1) { /* searched all entries */
1306 fprintf(STDERR, "Volume %s does not exist in VLDB\n\n",
1307 as->parms[0].items->data);
1314 /* Get information about the volume from the server */
1316 fprintf(STDOUT, "Getting volume listing from the server %s .. ",
1317 hostutil_GetNameByINet(aserver));
1320 if (wantExtendedInfo)
1321 code = UV_XListOneVolume(aserver, apart, volid, &xInfoP);
1323 code = UV_ListOneVolume(aserver, apart, volid, &pntr);
1325 fprintf(STDOUT, "done\n");
1329 if (code == ENODEV) {
1330 if ((voltype == BACKVOL) && !(entry.flags & BACK_EXISTS)) {
1331 /* The VLDB says there is no backup volume and its not on disk */
1332 fprintf(STDERR, "Volume %s does not exist\n",
1333 as->parms[0].items->data);
1337 "Volume does not exist on server %s as indicated by the VLDB\n",
1338 hostutil_GetNameByINet(aserver));
1341 PrintDiagnostics("examine", code);
1343 fprintf(STDOUT, "\n");
1346 if (wantExtendedInfo)
1347 XVolumeStats(xInfoP, &entry, aserver, apart, voltype);
1349 #ifdef FULL_LISTVOL_SWITCH
1350 if (as->parms[2].items) {
1351 DisplayFormat2(aserver, apart, pntr);
1352 EnumerateEntry(&entry);
1354 #endif /* FULL_LISTVOL_SWITCH */
1355 VolumeStats(pntr, &entry, aserver, apart, voltype);
1357 if ((voltype == BACKVOL) && !(entry.flags & BACK_EXISTS)) {
1358 /* The VLDB says there is no backup volume yet we found one on disk */
1359 fprintf(STDERR, "Volume %s does not exist in VLDB\n",
1360 as->parms[0].items->data);
1369 } while (voltype == ROVOL);
1372 fprintf(STDERR, "Dump only information from VLDB\n\n");
1373 fprintf(STDOUT, "%s \n", entry.name); /* PostVolumeStats doesn't print name */
1375 PostVolumeStats(&entry);
1380 /*------------------------------------------------------------------------
1384 * Routine used to change the status of a single volume.
1387 * as : Ptr to parsed command line arguments.
1390 * 0 for a successful operation,
1391 * Otherwise, one of the ubik or VolServer error values.
1394 * Nothing interesting.
1398 *------------------------------------------------------------------------
1402 register struct cmd_syndesc *as;
1404 struct nvldbentry entry;
1405 afs_int32 vcode = 0;
1408 afs_int32 code, err;
1409 afs_int32 aserver, apart;
1412 volid = vsu_GetVolumeID(as->parms[0].items->data, cstruct, &err); /* -id */
1415 PrintError("", err);
1417 fprintf(STDERR, "Unknown volume ID or name '%s'\n",
1418 as->parms[0].items->data);
1422 code = VLDB_GetEntryByID(volid, RWVOL, &entry);
1425 "Could not fetch the entry for volume number %lu from VLDB \n",
1426 (unsigned long)volid);
1429 MapHostToNetwork(&entry);
1431 GetServerAndPart(&entry, RWVOL, &aserver, &apart, &previdx);
1432 if (previdx == -1) {
1433 fprintf(STDERR, "Volume %s does not exist in VLDB\n\n",
1434 as->parms[0].items->data);
1438 memset(&info, 0, sizeof(info));
1449 if (as->parms[1].items) {
1451 code = util_GetInt32(as->parms[1].items->data, &info.maxquota);
1453 fprintf(STDERR, "invalid quota value\n");
1457 if (as->parms[2].items) {
1461 code = UV_SetVolumeInfo(aserver, apart, volid, &info);
1464 "Could not update volume info fields for volume number %lu\n",
1465 (unsigned long)volid);
1469 /*------------------------------------------------------------------------
1473 * Brings a volume online.
1476 * as : Ptr to parsed command line arguments.
1479 * 0 for a successful operation,
1482 * Nothing interesting.
1486 *------------------------------------------------------------------------
1490 register struct cmd_syndesc *as;
1492 afs_int32 server, partition, volid;
1493 afs_int32 code, err = 0;
1495 server = GetServer(as->parms[0].items->data);
1497 fprintf(STDERR, "vos: server '%s' not found in host table\n",
1498 as->parms[0].items->data);
1502 partition = volutil_GetPartitionID(as->parms[1].items->data);
1503 if (partition < 0) {
1504 fprintf(STDERR, "vos: could not interpret partition name '%s'\n",
1505 as->parms[1].items->data);
1509 volid = vsu_GetVolumeID(as->parms[2].items->data, cstruct, &err); /* -id */
1512 PrintError("", err);
1514 fprintf(STDERR, "Unknown volume ID or name '%s'\n",
1515 as->parms[0].items->data);
1519 code = UV_SetVolume(server, partition, volid, ITOffline, 0 /*online */ ,
1522 fprintf(STDERR, "Failed to set volume. Code = %d\n", code);
1529 /*------------------------------------------------------------------------
1530 * PRIVATE volOffline
1533 * Brings a volume offline.
1536 * as : Ptr to parsed command line arguments.
1539 * 0 for a successful operation,
1542 * Nothing interesting.
1546 *------------------------------------------------------------------------
1549 volOffline(register struct cmd_syndesc *as)
1551 afs_int32 server, partition, volid;
1552 afs_int32 code, err = 0;
1553 afs_int32 transflag, sleeptime, transdone;
1555 server = GetServer(as->parms[0].items->data);
1557 fprintf(STDERR, "vos: server '%s' not found in host table\n",
1558 as->parms[0].items->data);
1562 partition = volutil_GetPartitionID(as->parms[1].items->data);
1563 if (partition < 0) {
1564 fprintf(STDERR, "vos: could not interpret partition name '%s'\n",
1565 as->parms[1].items->data);
1569 volid = vsu_GetVolumeID(as->parms[2].items->data, cstruct, &err); /* -id */
1572 PrintError("", err);
1574 fprintf(STDERR, "Unknown volume ID or name '%s'\n",
1575 as->parms[0].items->data);
1579 transflag = (as->parms[4].items ? ITBusy : ITOffline);
1580 sleeptime = (as->parms[3].items ? atol(as->parms[3].items->data) : 0);
1581 transdone = (sleeptime ? 0 /*online */ : VTOutOfService);
1582 if (as->parms[4].items && !as->parms[3].items) {
1583 fprintf(STDERR, "-sleep option must be used with -busy flag\n");
1588 UV_SetVolume(server, partition, volid, transflag, transdone,
1591 fprintf(STDERR, "Failed to set volume. Code = %d\n", code);
1599 CreateVolume(register struct cmd_syndesc *as)
1603 afs_int32 volid, code;
1604 struct nvldbentry entry;
1609 tserver = GetServer(as->parms[0].items->data);
1611 fprintf(STDERR, "vos: host '%s' not found in host table\n",
1612 as->parms[0].items->data);
1615 pname = volutil_GetPartitionID(as->parms[1].items->data);
1617 fprintf(STDERR, "vos: could not interpret partition name '%s'\n",
1618 as->parms[1].items->data);
1621 if (!IsPartValid(pname, tserver, &code)) { /*check for validity of the partition */
1623 PrintError("", code);
1626 "vos : partition %s does not exist on the server\n",
1627 as->parms[1].items->data);
1630 if (!ISNAMEVALID(as->parms[2].items->data)) {
1632 "vos: the name of the root volume %s exceeds the size limit of %d\n",
1633 as->parms[2].items->data, VOLSER_OLDMAXVOLNAME - 10);
1636 if (!VolNameOK(as->parms[2].items->data)) {
1638 "Illegal volume name %s, should not end in .readonly or .backup\n",
1639 as->parms[2].items->data);
1642 if (IsNumeric(as->parms[2].items->data)) {
1643 fprintf(STDERR, "Illegal volume name %s, should not be a number\n",
1644 as->parms[2].items->data);
1647 vcode = VLDB_GetEntryByName(as->parms[2].items->data, &entry);
1649 fprintf(STDERR, "Volume %s already exists\n",
1650 as->parms[2].items->data);
1651 PrintDiagnostics("create", code);
1655 if (as->parms[3].items) {
1656 if (!IsNumeric(as->parms[3].items->data)) {
1657 fprintf(STDERR, "Initial quota %s should be numeric.\n",
1658 as->parms[3].items->data);
1662 code = util_GetInt32(as->parms[3].items->data, "a);
1664 fprintf(STDERR, "vos: bad integer specified for quota.\n");
1670 UV_CreateVolume2(tserver, pname, as->parms[2].items->data, quota, 0,
1673 PrintDiagnostics("create", code);
1676 MapPartIdIntoName(pname, part);
1677 fprintf(STDOUT, "Volume %lu created on partition %s of %s\n",
1678 (unsigned long)volid, part, as->parms[0].items->data);
1685 struct nvldbentry *entry;
1688 afs_int32 error, code, curserver, curpart, volid;
1690 MapHostToNetwork(entry);
1692 for (i = 0; i < entry->nServers; i++) {
1693 curserver = entry->serverNumber[i];
1694 curpart = entry->serverPartition[i];
1695 if (entry->serverFlags[i] & ITSROVOL) {
1696 volid = entry->volumeId[ROVOL];
1698 volid = entry->volumeId[RWVOL];
1700 code = UV_DeleteVolume(curserver, curpart, volid);
1709 struct cmd_syndesc *as;
1711 afs_int32 err, code = 0;
1712 afs_int32 server = 0, partition = -1, volid;
1716 if (as->parms[0].items) {
1717 server = GetServer(as->parms[0].items->data);
1719 fprintf(STDERR, "vos: server '%s' not found in host table\n",
1720 as->parms[0].items->data);
1725 if (as->parms[1].items) {
1726 partition = volutil_GetPartitionID(as->parms[1].items->data);
1727 if (partition < 0) {
1728 fprintf(STDERR, "vos: could not interpret partition name '%s'\n",
1729 as->parms[1].items->data);
1733 /* Check for validity of the partition */
1734 if (!IsPartValid(partition, server, &code)) {
1736 PrintError("", code);
1739 "vos : partition %s does not exist on the server\n",
1740 as->parms[1].items->data);
1746 volid = vsu_GetVolumeID(as->parms[2].items->data, cstruct, &err);
1748 fprintf(STDERR, "Can't find volume name '%s' in VLDB\n",
1749 as->parms[2].items->data);
1751 PrintError("", err);
1755 /* If the server or partition option are not complete, try to fill
1756 * them in from the VLDB entry.
1758 if ((partition == -1) || !server) {
1759 struct nvldbentry entry;
1761 code = VLDB_GetEntryByID(volid, -1, &entry);
1764 "Could not fetch the entry for volume %lu from VLDB\n",
1765 (unsigned long)volid);
1766 PrintError("", code);
1770 if (((volid == entry.volumeId[RWVOL]) && (entry.flags & RW_EXISTS))
1771 || ((volid == entry.volumeId[BACKVOL])
1772 && (entry.flags & BACK_EXISTS))) {
1773 idx = Lp_GetRwIndex(&entry);
1774 if ((idx == -1) || (server && (server != entry.serverNumber[idx]))
1775 || ((partition != -1)
1776 && (partition != entry.serverPartition[idx]))) {
1777 fprintf(STDERR, "VLDB: Volume '%s' no match\n",
1778 as->parms[2].items->data);
1781 } else if ((volid == entry.volumeId[ROVOL])
1782 && (entry.flags & RO_EXISTS)) {
1783 for (idx = -1, j = 0; j < entry.nServers; j++) {
1784 if (entry.serverFlags[j] != ITSROVOL)
1787 if (((server == 0) || (server == entry.serverNumber[j]))
1788 && ((partition == -1)
1789 || (partition == entry.serverPartition[j]))) {
1792 "VLDB: Volume '%s' matches more than one RO\n",
1793 as->parms[2].items->data);
1800 fprintf(STDERR, "VLDB: Volume '%s' no match\n",
1801 as->parms[2].items->data);
1805 fprintf(STDERR, "VLDB: Volume '%s' no match\n",
1806 as->parms[2].items->data);
1810 server = htonl(entry.serverNumber[idx]);
1811 partition = entry.serverPartition[idx];
1815 code = UV_DeleteVolume(server, partition, volid);
1817 PrintDiagnostics("remove", code);
1821 MapPartIdIntoName(partition, pname);
1822 fprintf(STDOUT, "Volume %lu on partition %s server %s deleted\n",
1823 (unsigned long)volid, pname, hostutil_GetNameByINet(server));
1827 #define TESTM 0 /* set for move space tests, clear for production */
1830 register struct cmd_syndesc *as;
1833 afs_int32 volid, fromserver, toserver, frompart, topart, code, err;
1834 char fromPartName[10], toPartName[10];
1836 struct diskPartition partition; /* for space check */
1839 volid = vsu_GetVolumeID(as->parms[0].items->data, cstruct, &err);
1842 PrintError("", err);
1844 fprintf(STDERR, "vos: can't find volume ID or name '%s'\n",
1845 as->parms[0].items->data);
1848 fromserver = GetServer(as->parms[1].items->data);
1849 if (fromserver == 0) {
1850 fprintf(STDERR, "vos: server '%s' not found in host table\n",
1851 as->parms[1].items->data);
1854 toserver = GetServer(as->parms[3].items->data);
1855 if (toserver == 0) {
1856 fprintf(STDERR, "vos: server '%s' not found in host table\n",
1857 as->parms[3].items->data);
1860 frompart = volutil_GetPartitionID(as->parms[2].items->data);
1862 fprintf(STDERR, "vos: could not interpret partition name '%s'\n",
1863 as->parms[2].items->data);
1866 if (!IsPartValid(frompart, fromserver, &code)) { /*check for validity of the partition */
1868 PrintError("", code);
1871 "vos : partition %s does not exist on the server\n",
1872 as->parms[2].items->data);
1875 topart = volutil_GetPartitionID(as->parms[4].items->data);
1877 fprintf(STDERR, "vos: could not interpret partition name '%s'\n",
1878 as->parms[4].items->data);
1881 if (!IsPartValid(topart, toserver, &code)) { /*check for validity of the partition */
1883 PrintError("", code);
1886 "vos : partition %s does not exist on the server\n",
1887 as->parms[4].items->data);
1892 * check source partition for space to clone volume
1895 MapPartIdIntoName(topart, toPartName);
1896 MapPartIdIntoName(frompart, fromPartName);
1899 * check target partition for space to move volume
1902 code = UV_PartitionInfo(toserver, toPartName, &partition);
1904 fprintf(STDERR, "vos: cannot access partition %s\n", toPartName);
1908 fprintf(STDOUT, "target partition %s free space %d\n", toPartName,
1911 p = (volintInfo *) 0;
1912 code = UV_ListOneVolume(fromserver, frompart, volid, &p);
1914 fprintf(STDERR, "vos:cannot access volume %lu\n",
1915 (unsigned long)volid);
1920 fprintf(STDOUT, "volume %lu size %d\n", (unsigned long)volid,
1922 if (partition.free <= p->size) {
1924 "vos: no space on target partition %s to move volume %lu\n",
1925 toPartName, (unsigned long)volid);
1932 fprintf(STDOUT, "size test - don't do move\n");
1936 /* successful move still not guaranteed but shoot for it */
1938 code = UV_MoveVolume(volid, fromserver, frompart, toserver, topart);
1940 PrintDiagnostics("move", code);
1943 MapPartIdIntoName(topart, toPartName);
1944 MapPartIdIntoName(frompart, fromPartName);
1945 fprintf(STDOUT, "Volume %lu moved from %s %s to %s %s \n",
1946 (unsigned long)volid, as->parms[1].items->data, fromPartName,
1947 as->parms[3].items->data, toPartName);
1954 register struct cmd_syndesc *as;
1956 afs_int32 volid, fromserver, toserver, frompart, topart, code, err;
1957 char fromPartName[10], toPartName[10], *tovolume;
1958 struct nvldbentry entry;
1959 struct diskPartition partition; /* for space check */
1962 volid = vsu_GetVolumeID(as->parms[0].items->data, cstruct, &err);
1965 PrintError("", err);
1967 fprintf(STDERR, "vos: can't find volume ID or name '%s'\n",
1968 as->parms[0].items->data);
1971 fromserver = GetServer(as->parms[1].items->data);
1972 if (fromserver == 0) {
1973 fprintf(STDERR, "vos: server '%s' not found in host table\n",
1974 as->parms[1].items->data);
1978 toserver = GetServer(as->parms[4].items->data);
1979 if (toserver == 0) {
1980 fprintf(STDERR, "vos: server '%s' not found in host table\n",
1981 as->parms[3].items->data);
1985 tovolume = as->parms[3].items->data;
1986 if (!ISNAMEVALID(tovolume)) {
1988 "vos: the name of the root volume %s exceeds the size limit of %d\n",
1989 tovolume, VOLSER_OLDMAXVOLNAME - 10);
1992 if (!VolNameOK(tovolume)) {
1994 "Illegal volume name %s, should not end in .readonly or .backup\n",
1998 if (IsNumeric(tovolume)) {
1999 fprintf(STDERR, "Illegal volume name %s, should not be a number\n",
2003 code = VLDB_GetEntryByName(tovolume, &entry);
2005 fprintf(STDERR, "Volume %s already exists\n", tovolume);
2006 PrintDiagnostics("copy", code);
2010 frompart = volutil_GetPartitionID(as->parms[2].items->data);
2012 fprintf(STDERR, "vos: could not interpret partition name '%s'\n",
2013 as->parms[2].items->data);
2016 if (!IsPartValid(frompart, fromserver, &code)) { /*check for validity of the partition */
2018 PrintError("", code);
2021 "vos : partition %s does not exist on the server\n",
2022 as->parms[2].items->data);
2026 topart = volutil_GetPartitionID(as->parms[5].items->data);
2028 fprintf(STDERR, "vos: could not interpret partition name '%s'\n",
2029 as->parms[4].items->data);
2032 if (!IsPartValid(topart, toserver, &code)) { /*check for validity of the partition */
2034 PrintError("", code);
2037 "vos : partition %s does not exist on the server\n",
2038 as->parms[4].items->data);
2043 * check source partition for space to clone volume
2046 MapPartIdIntoName(topart, toPartName);
2047 MapPartIdIntoName(frompart, fromPartName);
2050 * check target partition for space to move volume
2053 code = UV_PartitionInfo(toserver, toPartName, &partition);
2055 fprintf(STDERR, "vos: cannot access partition %s\n", toPartName);
2059 fprintf(STDOUT, "target partition %s free space %d\n", toPartName,
2062 p = (volintInfo *) 0;
2063 code = UV_ListOneVolume(fromserver, frompart, volid, &p);
2065 fprintf(STDERR, "vos:cannot access volume %lu\n",
2066 (unsigned long)volid);
2071 if (partition.free <= p->size) {
2073 "vos: no space on target partition %s to copy volume %lu\n",
2074 toPartName, (unsigned long)volid);
2080 /* successful copy still not guaranteed but shoot for it */
2083 UV_CopyVolume(volid, fromserver, frompart, tovolume, toserver,
2086 PrintDiagnostics("copy", code);
2089 MapPartIdIntoName(topart, toPartName);
2090 MapPartIdIntoName(frompart, fromPartName);
2091 fprintf(STDOUT, "Volume %lu copied from %s %s to %s on %s %s \n",
2092 (unsigned long)volid, as->parms[1].items->data, fromPartName,
2093 tovolume, as->parms[4].items->data, toPartName);
2101 register struct cmd_syndesc *as;
2103 afs_int32 avolid, aserver, apart, vtype, code, err;
2104 struct nvldbentry entry;
2106 afs_int32 buvolid, buserver, bupart, butype;
2107 struct nvldbentry buentry;
2108 struct rx_connection *conn;
2110 struct nvldbentry store;
2112 avolid = vsu_GetVolumeID(as->parms[0].items->data, cstruct, &err);
2115 PrintError("", err);
2117 fprintf(STDERR, "vos: can't find volume ID or name '%s'\n",
2118 as->parms[0].items->data);
2121 code = GetVolumeInfo(avolid, &aserver, &apart, &vtype, &entry);
2125 /* verify this is a readwrite volume */
2127 if (vtype != RWVOL) {
2128 fprintf(STDERR, "%s not RW volume\n", as->parms[0].items->data);
2132 /* is there a backup volume already? */
2134 if (entry.flags & BACK_EXISTS) {
2135 /* yep, where is it? */
2137 buvolid = entry.volumeId[BACKVOL];
2138 code = GetVolumeInfo(buvolid, &buserver, &bupart, &butype, &buentry);
2143 code = VLDB_IsSameAddrs(buserver, aserver, &err);
2146 "Failed to get info about server's %d address(es) from vlserver; aborting call!\n",
2152 "FATAL ERROR: backup volume %lu exists on server %lu\n",
2153 (unsigned long)buvolid, (unsigned long)buserver);
2158 /* nope, carry on */
2160 code = UV_BackupVolume(aserver, apart, avolid);
2163 PrintDiagnostics("backup", code);
2166 fprintf(STDOUT, "Created backup volume for %s \n",
2167 as->parms[0].items->data);
2173 register struct cmd_syndesc *as;
2176 struct nvldbentry entry;
2177 afs_int32 avolid, aserver, apart, vtype, code, err;
2180 if (as->parms[1].items)
2182 avolid = vsu_GetVolumeID(as->parms[0].items->data, cstruct, &err);
2185 PrintError("", err);
2187 fprintf(STDERR, "vos: can't find volume '%s'\n",
2188 as->parms[0].items->data);
2191 code = GetVolumeInfo(avolid, &aserver, &apart, &vtype, &entry);
2195 if (vtype != RWVOL) {
2196 fprintf(STDERR, "%s not a RW volume\n", as->parms[0].items->data);
2200 if (!ISNAMEVALID(entry.name)) {
2202 "Volume name %s is too long, rename before releasing\n",
2207 code = UV_ReleaseVolume(avolid, aserver, apart, force);
2209 PrintDiagnostics("release", code);
2212 fprintf(STDOUT, "Released volume %s successfully\n",
2213 as->parms[0].items->data);
2219 register struct cmd_syndesc *as;
2222 afs_int32 avolid, aserver, apart, voltype, fromdate = 0, code, err, i;
2223 char filename[NameLen];
2224 struct nvldbentry entry;
2226 rx_SetRxDeadTime(60 * 10);
2227 for (i = 0; i < MAXSERVERS; i++) {
2228 struct rx_connection *rxConn = ubik_GetRPCConn(cstruct, i);
2231 rx_SetConnDeadTime(rxConn, rx_connDeadTime);
2232 if (rxConn->service)
2233 rxConn->service->connDeadTime = rx_connDeadTime;
2236 avolid = vsu_GetVolumeID(as->parms[0].items->data, cstruct, &err);
2239 PrintError("", err);
2241 fprintf(STDERR, "vos: can't find volume '%s'\n",
2242 as->parms[0].items->data);
2246 if (as->parms[3].items || as->parms[4].items) {
2247 if (!as->parms[3].items || !as->parms[4].items) {
2249 "Must specify both -server and -partition options\n");
2252 aserver = GetServer(as->parms[3].items->data);
2254 fprintf(STDERR, "Invalid server name\n");
2257 apart = volutil_GetPartitionID(as->parms[4].items->data);
2259 fprintf(STDERR, "Invalid partition name\n");
2263 code = GetVolumeInfo(avolid, &aserver, &apart, &voltype, &entry);
2268 if (as->parms[1].items && strcmp(as->parms[1].items->data, "0")) {
2269 code = ktime_DateToInt32(as->parms[1].items->data, &fromdate);
2271 fprintf(STDERR, "vos: failed to parse date '%s' (error=%d))\n",
2272 as->parms[1].items->data, code);
2276 if (as->parms[2].items) {
2277 strcpy(filename, as->parms[2].items->data);
2279 strcpy(filename, "");
2282 if (as->parms[5].items) {
2284 UV_DumpClonedVolume(avolid, aserver, apart, fromdate,
2285 DumpFunction, filename);
2288 UV_DumpVolume(avolid, aserver, apart, fromdate, DumpFunction,
2292 PrintDiagnostics("dump", code);
2295 if (strcmp(filename, ""))
2296 fprintf(STDERR, "Dumped volume %s in file %s\n",
2297 as->parms[0].items->data, filename);
2299 fprintf(STDERR, "Dumped volume %s in stdout \n",
2300 as->parms[0].items->data);
2311 register struct cmd_syndesc *as;
2314 afs_int32 avolid, aserver, apart, code, vcode, err;
2315 afs_int32 aoverwrite = ASK;
2316 int restoreflags, readonly = 0, offline = 0, voltype = RWVOL;
2318 char afilename[NameLen], avolname[VOLSER_MAXVOLNAME + 1], apartName[10];
2319 char volname[VOLSER_MAXVOLNAME + 1];
2320 struct nvldbentry entry;
2324 if (as->parms[4].items) {
2325 avolid = vsu_GetVolumeID(as->parms[4].items->data, cstruct, &err);
2328 PrintError("", err);
2330 fprintf(STDERR, "vos: can't find volume '%s'\n",
2331 as->parms[4].items->data);
2337 if (as->parms[5].items) {
2338 if ((strcmp(as->parms[5].items->data, "a") == 0)
2339 || (strcmp(as->parms[5].items->data, "abort") == 0)) {
2341 } else if ((strcmp(as->parms[5].items->data, "f") == 0)
2342 || (strcmp(as->parms[5].items->data, "full") == 0)) {
2344 } else if ((strcmp(as->parms[5].items->data, "i") == 0)
2345 || (strcmp(as->parms[5].items->data, "inc") == 0)
2346 || (strcmp(as->parms[5].items->data, "increment") == 0)
2347 || (strcmp(as->parms[5].items->data, "incremental") == 0)) {
2350 fprintf(STDERR, "vos: %s is not a valid argument to -overwrite\n",
2351 as->parms[5].items->data);
2355 if (as->parms[6].items)
2357 if (as->parms[7].items) {
2362 aserver = GetServer(as->parms[0].items->data);
2364 fprintf(STDERR, "vos: server '%s' not found in host table\n",
2365 as->parms[0].items->data);
2368 apart = volutil_GetPartitionID(as->parms[1].items->data);
2370 fprintf(STDERR, "vos: could not interpret partition name '%s'\n",
2371 as->parms[1].items->data);
2374 if (!IsPartValid(apart, aserver, &code)) { /*check for validity of the partition */
2376 PrintError("", code);
2379 "vos : partition %s does not exist on the server\n",
2380 as->parms[1].items->data);
2383 strcpy(avolname, as->parms[2].items->data);
2384 if (!ISNAMEVALID(avolname)) {
2386 "vos: the name of the volume %s exceeds the size limit\n",
2390 if (!VolNameOK(avolname)) {
2392 "Illegal volume name %s, should not end in .readonly or .backup\n",
2396 if (as->parms[3].items) {
2397 strcpy(afilename, as->parms[3].items->data);
2398 if (!FileExists(afilename)) {
2399 fprintf(STDERR, "Can't access file %s\n", afilename);
2403 strcpy(afilename, "");
2406 /* Check if volume exists or not */
2408 vsu_ExtractName(volname, avolname);
2409 vcode = VLDB_GetEntryByName(volname, &entry);
2410 if (vcode) { /* no volume - do a full restore */
2411 restoreflags = RV_FULLRST;
2412 if ((aoverwrite == INC) || (aoverwrite == ABORT))
2414 "Volume does not exist; Will perform a full restore\n");
2417 else if ((!readonly && Lp_GetRwIndex(&entry) == -1) /* RW volume does not exist - do a full */
2418 ||(readonly && !Lp_ROMatch(0, 0, &entry))) { /* RO volume does not exist - do a full */
2419 restoreflags = RV_FULLRST;
2420 if ((aoverwrite == INC) || (aoverwrite == ABORT))
2422 "%s Volume does not exist; Will perform a full restore\n",
2423 readonly ? "RO" : "RW");
2426 avolid = entry.volumeId[voltype];
2427 } else if (entry.volumeId[voltype] != 0
2428 && entry.volumeId[voltype] != avolid) {
2429 avolid = entry.volumeId[voltype];
2433 else { /* volume exists - do we do a full incremental or abort */
2434 int Oserver, Opart, Otype, vol_elsewhere = 0;
2435 struct nvldbentry Oentry;
2439 avolid = entry.volumeId[voltype];
2440 } else if (entry.volumeId[voltype] != 0
2441 && entry.volumeId[voltype] != avolid) {
2442 avolid = entry.volumeId[voltype];
2445 /* A file name was specified - check if volume is on another partition */
2446 vcode = GetVolumeInfo(avolid, &Oserver, &Opart, &Otype, &Oentry);
2450 vcode = VLDB_IsSameAddrs(Oserver, aserver, &err);
2453 "Failed to get info about server's %d address(es) from vlserver (err=%d); aborting call!\n",
2457 if (!vcode || (Opart != apart))
2460 if (aoverwrite == ASK) {
2461 if (strcmp(afilename, "") == 0) { /* The file is from standard in */
2463 "Volume exists and no -overwrite option specified; Aborting restore command\n");
2467 /* Ask what to do */
2468 if (vol_elsewhere) {
2470 "The volume %s %u already exists on a different server/part\n",
2471 volname, entry.volumeId[voltype]);
2473 "Do you want to do a full restore or abort? [fa](a): ");
2476 "The volume %s %u already exists in the VLDB\n",
2477 volname, entry.volumeId[voltype]);
2479 "Do you want to do a full/incremental restore or abort? [fia](a): ");
2482 while (!(dc == EOF || dc == '\n'))
2483 dc = getchar(); /* goto end of line */
2484 if ((c == 'f') || (c == 'F'))
2486 else if ((c == 'i') || (c == 'I'))
2492 if (aoverwrite == ABORT) {
2493 fprintf(STDERR, "Volume exists; Aborting restore command\n");
2495 } else if (aoverwrite == FULL) {
2496 restoreflags = RV_FULLRST;
2498 "Volume exists; Will delete and perform full restore\n");
2499 } else if (aoverwrite == INC) {
2501 if (vol_elsewhere) {
2503 "%s volume %lu already exists on a different server/part; not allowed\n",
2504 readonly ? "RO" : "RW", (unsigned long)avolid);
2510 restoreflags |= RV_OFFLINE;
2512 restoreflags |= RV_RDONLY;
2514 UV_RestoreVolume(aserver, apart, avolid, avolname, restoreflags,
2515 WriteData, afilename);
2517 PrintDiagnostics("restore", code);
2520 MapPartIdIntoName(apart, apartName);
2523 * patch typo here - originally "parms[1]", should be "parms[0]"
2526 fprintf(STDOUT, "Restored volume %s on %s %s\n", avolname,
2527 as->parms[0].items->data, apartName);
2533 register struct cmd_syndesc *as;
2536 afs_int32 avolid, code, err;
2538 avolid = vsu_GetVolumeID(as->parms[0].items->data, cstruct, &err);
2541 PrintError("", err);
2543 fprintf(STDERR, "vos: can't find volume '%s'\n",
2544 as->parms[0].items->data);
2548 code = UV_LockRelease(avolid);
2550 PrintDiagnostics("unlock", code);
2553 fprintf(STDOUT, "Released lock on vldb entry for volume %s\n",
2554 as->parms[0].items->data);
2560 register struct cmd_syndesc *as;
2562 afs_int32 avolid, aserver, apart, code, err;
2563 char apartName[10], avolname[VOLSER_MAXVOLNAME + 1];
2565 vsu_ExtractName(avolname, as->parms[2].items->data);;
2566 avolid = vsu_GetVolumeID(avolname, cstruct, &err);
2569 PrintError("", err);
2571 fprintf(STDERR, "vos: can't find volume '%s'\n",
2572 as->parms[2].items->data);
2575 aserver = GetServer(as->parms[0].items->data);
2577 fprintf(STDERR, "vos: server '%s' not found in host table\n",
2578 as->parms[0].items->data);
2581 apart = volutil_GetPartitionID(as->parms[1].items->data);
2583 fprintf(STDERR, "vos: could not interpret partition name '%s'\n",
2584 as->parms[1].items->data);
2587 if (!IsPartValid(apart, aserver, &code)) { /*check for validity of the partition */
2589 PrintError("", code);
2592 "vos : partition %s does not exist on the server\n",
2593 as->parms[1].items->data);
2596 code = UV_AddSite(aserver, apart, avolid);
2598 PrintDiagnostics("addsite", code);
2601 MapPartIdIntoName(apart, apartName);
2602 fprintf(STDOUT, "Added replication site %s %s for volume %s\n",
2603 as->parms[0].items->data, apartName, as->parms[2].items->data);
2609 register struct cmd_syndesc *as;
2612 afs_int32 avolid, aserver, apart, code, err;
2613 char apartName[10], avolname[VOLSER_MAXVOLNAME + 1];
2615 vsu_ExtractName(avolname, as->parms[2].items->data);
2616 avolid = vsu_GetVolumeID(avolname, cstruct, &err);
2619 PrintError("", err);
2621 fprintf(STDERR, "vos: can't find volume '%s'\n",
2622 as->parms[2].items->data);
2625 aserver = GetServer(as->parms[0].items->data);
2627 fprintf(STDERR, "vos: server '%s' not found in host table\n",
2628 as->parms[0].items->data);
2631 apart = volutil_GetPartitionID(as->parms[1].items->data);
2633 fprintf(STDERR, "vos: could not interpret partition name '%s'\n",
2634 as->parms[1].items->data);
2638 *skip the partition validity check, since it is possible that the partition
2639 *has since been decomissioned.
2642 if (!IsPartValid(apart,aserver,&code)){
2643 if(code) PrintError("",code);
2644 else fprintf(STDERR,"vos : partition %s does not exist on the server\n",as->parms[1].items->data);
2648 code = UV_RemoveSite(aserver, apart, avolid);
2650 PrintDiagnostics("remsite", code);
2653 MapPartIdIntoName(apart, apartName);
2654 fprintf(STDOUT, "Removed replication site %s %s for volume %s\n",
2655 as->parms[0].items->data, apartName, as->parms[2].items->data);
2661 register struct cmd_syndesc *as;
2663 afs_int32 avolid, aserver, apart, code, err;
2666 avolid = vsu_GetVolumeID(as->parms[2].items->data, cstruct, &err);
2669 PrintError("", err);
2671 fprintf(STDERR, "vos: can't find volume '%s'\n",
2672 as->parms[2].items->data);
2675 aserver = GetServer(as->parms[0].items->data);
2677 fprintf(STDERR, "vos: server '%s' not found in host table\n",
2678 as->parms[0].items->data);
2681 apart = volutil_GetPartitionID(as->parms[1].items->data);
2683 fprintf(STDERR, "vos: could not interpret partition name '%s'\n",
2684 as->parms[1].items->data);
2687 if (!IsPartValid(apart, aserver, &code)) { /*check for validity of the partition */
2689 PrintError("", code);
2692 "vos : partition %s does not exist on the server\n",
2693 as->parms[1].items->data);
2696 code = UV_ChangeLocation(aserver, apart, avolid);
2698 PrintDiagnostics("addsite", code);
2701 MapPartIdIntoName(apart, apartName);
2702 fprintf(STDOUT, "Changed location to %s %s for volume %s\n",
2703 as->parms[0].items->data, apartName, as->parms[2].items->data);
2709 register struct cmd_syndesc *as;
2711 afs_int32 aserver, code;
2712 struct partList dummyPartList;
2717 aserver = GetServer(as->parms[0].items->data);
2719 fprintf(STDERR, "vos: server '%s' not found in host table\n",
2720 as->parms[0].items->data);
2725 code = UV_ListPartitions(aserver, &dummyPartList, &cnt);
2727 PrintDiagnostics("listpart", code);
2731 fprintf(STDOUT, "The partitions on the server are:\n");
2732 for (i = 0; i < cnt; i++) {
2733 if (dummyPartList.partFlags[i] & PARTVALID) {
2734 memset(pname, 0, sizeof(pname));
2735 MapPartIdIntoName(dummyPartList.partId[i], pname);
2736 fprintf(STDOUT, " %10s ", pname);
2738 if ((i % 5) == 0 && (i != 0))
2739 fprintf(STDOUT, "\n");
2742 fprintf(STDOUT, "\n");
2743 fprintf(STDOUT, "Total: %d\n", total);
2749 CompareVolName(p1, p2)
2752 volintInfo *arg1, *arg2;
2754 arg1 = (volintInfo *) p1;
2755 arg2 = (volintInfo *) p2;
2756 return (strcmp(arg1->name, arg2->name));
2760 /*------------------------------------------------------------------------
2761 * PRIVATE XCompareVolName
2764 * Comparison routine for volume names coming from an extended
2768 * a_obj1P : Char ptr to first extended vol info object
2769 * a_obj1P : Char ptr to second extended vol info object
2772 * The value of strcmp() on the volume names within the passed
2773 * objects (i,e., -1, 0, or 1).
2776 * Passed to qsort() as the designated comparison routine.
2780 *------------------------------------------------------------------------*/
2783 XCompareVolName(a_obj1P, a_obj2P)
2784 char *a_obj1P, *a_obj2P;
2786 { /*XCompareVolName */
2789 (((struct volintXInfo *)(a_obj1P))->name,
2790 ((struct volintXInfo *)(a_obj2P))->name));
2792 } /*XCompareVolName */
2795 CompareVolID(p1, p2)
2798 volintInfo *arg1, *arg2;
2800 arg1 = (volintInfo *) p1;
2801 arg2 = (volintInfo *) p2;
2802 if (arg1->volid == arg2->volid)
2804 if (arg1->volid > arg2->volid)
2811 /*------------------------------------------------------------------------
2812 * PRIVATE XCompareVolID
2815 * Comparison routine for volume IDs coming from an extended
2819 * a_obj1P : Char ptr to first extended vol info object
2820 * a_obj1P : Char ptr to second extended vol info object
2823 * The value of strcmp() on the volume names within the passed
2824 * objects (i,e., -1, 0, or 1).
2827 * Passed to qsort() as the designated comparison routine.
2831 *------------------------------------------------------------------------*/
2834 XCompareVolID(a_obj1P, a_obj2P)
2835 char *a_obj1P, *a_obj2P;
2837 { /*XCompareVolID */
2839 afs_int32 id1, id2; /*Volume IDs we're comparing */
2841 id1 = ((struct volintXInfo *)(a_obj1P))->volid;
2842 id2 = ((struct volintXInfo *)(a_obj2P))->volid;
2850 } /*XCompareVolID */
2852 /*------------------------------------------------------------------------
2853 * PRIVATE ListVolumes
2856 * Routine used to list volumes, contacting the Volume Server
2857 * directly, bypassing the VLDB.
2860 * as : Ptr to parsed command line arguments.
2863 * 0 Successful operation
2866 * Nothing interesting.
2870 *------------------------------------------------------------------------*/
2874 register struct cmd_syndesc *as;
2876 afs_int32 apart, int32list, fast;
2877 afs_int32 aserver, code;
2878 volintInfo *pntr, *oldpntr;
2882 volintXInfo *xInfoP, *origxInfoP; /*Ptr to current/orig extended vol info */
2883 int wantExtendedInfo; /*Do we want extended vol info? */
2886 struct partList dummyPartList;
2894 if (as->parms[3].items)
2896 if (as->parms[4].items)
2900 if (as->parms[2].items)
2906 if (as->parms[5].items) {
2908 * We can't coexist with the fast flag.
2912 "vos: Can't use the -fast and -extended flags together\n");
2917 * We need to turn on ``long'' listings to get the full effect.
2919 wantExtendedInfo = 1;
2922 wantExtendedInfo = 0;
2923 if (as->parms[1].items) {
2924 apart = volutil_GetPartitionID(as->parms[1].items->data);
2926 fprintf(STDERR, "vos: could not interpret partition name '%s'\n",
2927 as->parms[1].items->data);
2930 dummyPartList.partId[0] = apart;
2931 dummyPartList.partFlags[0] = PARTVALID;
2934 aserver = GetServer(as->parms[0].items->data);
2936 fprintf(STDERR, "vos: server '%s' not found in host table\n",
2937 as->parms[0].items->data);
2942 if (!IsPartValid(apart, aserver, &code)) { /*check for validity of the partition */
2944 PrintError("", code);
2947 "vos : partition %s does not exist on the server\n",
2948 as->parms[1].items->data);
2952 code = UV_ListPartitions(aserver, &dummyPartList, &cnt);
2954 PrintDiagnostics("listvol", code);
2958 for (i = 0; i < cnt; i++) {
2959 if (dummyPartList.partFlags[i] & PARTVALID) {
2960 if (wantExtendedInfo)
2962 UV_XListVolumes(aserver, dummyPartList.partId[i], all,
2966 UV_ListVolumes(aserver, dummyPartList.partId[i], all,
2969 PrintDiagnostics("listvol", code);
2974 if (wantExtendedInfo) {
2975 origxInfoP = xInfoP;
2976 base = (char *)xInfoP;
2979 base = (char *)pntr;
2983 if (wantExtendedInfo)
2984 qsort(base, count, sizeof(volintXInfo), XCompareVolName);
2986 qsort(base, count, sizeof(volintInfo), CompareVolName);
2988 if (wantExtendedInfo)
2989 qsort(base, count, sizeof(volintXInfo), XCompareVolID);
2991 qsort(base, count, sizeof(volintInfo), CompareVolID);
2993 MapPartIdIntoName(dummyPartList.partId[i], pname);
2996 "Total number of volumes on server %s partition %s: %lu \n",
2997 as->parms[0].items->data, pname,
2998 (unsigned long)count);
2999 if (wantExtendedInfo) {
3000 XDisplayVolumes(aserver, dummyPartList.partId[i], origxInfoP,
3001 count, int32list, fast, quiet);
3004 xInfoP = (volintXInfo *) 0;
3006 #ifdef FULL_LISTVOL_SWITCH
3007 if (as->parms[6].items)
3008 DisplayVolumes2(aserver, dummyPartList.partId[i], oldpntr,
3011 #endif /* FULL_LISTVOL_SWITCH */
3012 DisplayVolumes(aserver, dummyPartList.partId[i], oldpntr,
3013 count, int32list, fast, quiet);
3016 pntr = (volintInfo *) 0;
3025 register struct cmd_syndesc *as;
3027 afs_int32 pname, code; /* part name */
3033 if (as->parms[0].items) {
3034 tserver = GetServer(as->parms[0].items->data);
3036 fprintf(STDERR, "vos: host '%s' not found in host table\n",
3037 as->parms[0].items->data);
3042 if (as->parms[1].items) {
3043 pname = volutil_GetPartitionID(as->parms[1].items->data);
3045 fprintf(STDERR, "vos: could not interpret partition name '%s'\n",
3046 as->parms[1].items->data);
3049 if (!IsPartValid(pname, tserver, &code)) { /*check for validity of the partition */
3051 PrintError("", code);
3054 "vos: partition %s does not exist on the server\n",
3055 as->parms[1].items->data);
3062 "The -partition option requires a -server option\n");
3067 if (as->parms[2].items) {
3068 /* Synchronize an individual volume */
3069 volname = as->parms[2].items->data;
3070 code = UV_SyncVolume(tserver, pname, volname, flags);
3074 "Without a -volume option, the -server option is required\n");
3077 code = UV_SyncVldb(tserver, pname, flags, 0 /*unused */ );
3081 PrintDiagnostics("syncvldb", code);
3085 /* Print a summary of what we did */
3087 fprintf(STDOUT, "VLDB volume %s synchronized", volname);
3089 fprintf(STDOUT, "VLDB synchronized");
3091 fprintf(STDOUT, " with state of server %s", as->parms[0].items->data);
3094 MapPartIdIntoName(pname, part);
3095 fprintf(STDOUT, " partition %s\n", part);
3097 fprintf(STDOUT, "\n");
3104 register struct cmd_syndesc *as;
3107 afs_int32 pname, code; /* part name */
3112 tserver = GetServer(as->parms[0].items->data);
3114 fprintf(STDERR, "vos: host '%s' not found in host table\n",
3115 as->parms[0].items->data);
3118 if (as->parms[1].items) {
3119 pname = volutil_GetPartitionID(as->parms[1].items->data);
3121 fprintf(STDERR, "vos: could not interpret partition name '%s'\n",
3122 as->parms[1].items->data);
3125 if (!IsPartValid(pname, tserver, &code)) { /*check for validity of the partition */
3127 PrintError("", code);
3130 "vos : partition %s does not exist on the server\n",
3131 as->parms[1].items->data);
3137 code = UV_SyncServer(tserver, pname, flags, 0 /*unused */ );
3139 PrintDiagnostics("syncserv", code);
3143 MapPartIdIntoName(pname, part);
3144 fprintf(STDOUT, "Server %s partition %s synchronized with VLDB\n",
3145 as->parms[0].items->data, part);
3147 fprintf(STDOUT, "Server %s synchronized with VLDB\n",
3148 as->parms[0].items->data);
3157 struct nvldbentry entry;
3160 /* The vlserver will handle names with the .readonly
3161 * and .backup extension as well as volume ids.
3163 vcode = VLDB_GetEntryByName(name, &entry);
3165 PrintError("", vcode);
3168 MapHostToNetwork(&entry);
3169 EnumerateEntry(&entry);
3171 /* Defect #3027: grubby check to handle locked volume.
3172 * If VLOP_ALLOPERS is set, the entry is locked.
3173 * Leave this routine as is, but put in correct check.
3175 if (entry.flags & VLOP_ALLOPERS)
3176 fprintf(STDOUT, " Volume is currently LOCKED \n");
3183 register struct cmd_syndesc *as;
3186 struct nvldbentry entry;
3187 afs_int32 volid, code, server, part, zapbackupid = 0, backupid = 0, err;
3189 if (as->parms[3].items) {
3190 /* force flag is on, use the other version */
3191 return NukeVolume(as);
3194 if (as->parms[4].items) {
3198 volid = vsu_GetVolumeID(as->parms[2].items->data, cstruct, &err);
3201 PrintError("", err);
3203 fprintf(STDERR, "vos: can't find volume '%s'\n",
3204 as->parms[2].items->data);
3207 part = volutil_GetPartitionID(as->parms[1].items->data);
3209 fprintf(STDERR, "vos: could not interpret partition name '%s'\n",
3210 as->parms[1].items->data);
3213 server = GetServer(as->parms[0].items->data);
3215 fprintf(STDERR, "vos: host '%s' not found in host table\n",
3216 as->parms[0].items->data);
3219 if (!IsPartValid(part, server, &code)) { /*check for validity of the partition */
3221 PrintError("", code);
3224 "vos : partition %s does not exist on the server\n",
3225 as->parms[1].items->data);
3228 code = VLDB_GetEntryByID(volid, -1, &entry);
3230 if (volid == entry.volumeId[RWVOL])
3231 backupid = entry.volumeId[BACKVOL];
3233 "Warning: Entry for volume number %lu exists in VLDB (but we're zapping it anyway!)\n",
3234 (unsigned long)volid);
3237 volintInfo *pntr = (volintInfo *) 0;
3240 code = UV_ListOneVolume(server, part, volid, &pntr);
3242 if (volid == pntr->parentID)
3243 backupid = pntr->backupID;
3249 code = UV_VolumeZap(server, part, backupid);
3251 PrintDiagnostics("zap", code);
3254 fprintf(STDOUT, "Backup Volume %lu deleted\n",
3255 (unsigned long)backupid);
3258 code = UV_VolumeZap(server, part, volid);
3260 PrintDiagnostics("zap", code);
3263 fprintf(STDOUT, "Volume %lu deleted\n", (unsigned long)volid);
3270 register struct cmd_syndesc *as;
3273 afs_int32 server, code;
3274 transDebugInfo *pntr, *oldpntr;
3279 server = GetServer(as->parms[0].items->data);
3281 fprintf(STDERR, "vos: host '%s' not found in host table\n",
3282 as->parms[0].items->data);
3285 code = UV_VolserStatus(server, &pntr, &count);
3287 PrintDiagnostics("status", code);
3292 fprintf(STDOUT, "No active transactions on %s\n",
3293 as->parms[0].items->data);
3295 fprintf(STDOUT, "Total transactions: %d\n", count);
3297 for (i = 0; i < count; i++) {
3298 /*print out the relevant info */
3299 fprintf(STDOUT, "--------------------------------------\n");
3300 fprintf(STDOUT, "transaction: %lu created: %s",
3301 (unsigned long)pntr->tid, ctime((time_t *) & pntr->time));
3302 if (pntr->returnCode) {
3303 fprintf(STDOUT, "returnCode: %lu\n",
3304 (unsigned long)pntr->returnCode);
3307 fprintf(STDOUT, "attachFlags: ");
3308 switch (pntr->iflags) {
3310 fprintf(STDOUT, "offline ");
3313 fprintf(STDOUT, "busy ");
3316 fprintf(STDOUT, "readonly ");
3319 fprintf(STDOUT, "create ");
3322 fprintf(STDOUT, "create volid ");
3325 fprintf(STDOUT, "\n");
3328 fprintf(STDOUT, "volumeStatus: ");
3329 switch (pntr->vflags) {
3330 case VTDeleteOnSalvage:
3331 fprintf(STDOUT, "deleteOnSalvage ");
3332 case VTOutOfService:
3333 fprintf(STDOUT, "outOfService ");
3335 fprintf(STDOUT, "deleted ");
3337 fprintf(STDOUT, "\n");
3340 fprintf(STDOUT, "transactionFlags: ");
3341 fprintf(STDOUT, "delete\n");
3343 MapPartIdIntoName(pntr->partition, pname);
3344 fprintf(STDOUT, "volume: %lu partition: %s procedure: %s\n",
3345 (unsigned long)pntr->volid, pname, pntr->lastProcName);
3346 if (pntr->callValid) {
3348 "packetRead: %lu lastReceiveTime: %d packetSend: %lu lastSendTime: %d\n",
3349 (unsigned long)pntr->readNext, pntr->lastReceiveTime,
3350 (unsigned long)pntr->transmitNext, pntr->lastSendTime);
3353 fprintf(STDOUT, "--------------------------------------\n");
3354 fprintf(STDOUT, "\n");
3363 register struct cmd_syndesc *as;
3365 afs_int32 code1, code2, code;
3366 struct nvldbentry entry;
3368 code1 = VLDB_GetEntryByName(as->parms[0].items->data, &entry);
3370 fprintf(STDERR, "vos: Could not find entry for volume %s\n",
3371 as->parms[0].items->data);
3374 code2 = VLDB_GetEntryByName(as->parms[1].items->data, &entry);
3375 if ((!code1) && (!code2)) { /*the newname already exists */
3376 fprintf(STDERR, "vos: volume %s already exists\n",
3377 as->parms[1].items->data);
3381 if (code1 && code2) {
3382 fprintf(STDERR, "vos: Could not find entry for volume %s or %s\n",
3383 as->parms[0].items->data, as->parms[1].items->data);
3386 if (!VolNameOK(as->parms[0].items->data)) {
3388 "Illegal volume name %s, should not end in .readonly or .backup\n",
3389 as->parms[0].items->data);
3392 if (!ISNAMEVALID(as->parms[1].items->data)) {
3394 "vos: the new volume name %s exceeds the size limit of %d\n",
3395 as->parms[1].items->data, VOLSER_OLDMAXVOLNAME - 10);
3398 if (!VolNameOK(as->parms[1].items->data)) {
3400 "Illegal volume name %s, should not end in .readonly or .backup\n",
3401 as->parms[1].items->data);
3404 if (IsNumeric(as->parms[1].items->data)) {
3405 fprintf(STDERR, "Illegal volume name %s, should not be a number\n",
3406 as->parms[1].items->data);
3409 MapHostToNetwork(&entry);
3411 UV_RenameVolume(&entry, as->parms[0].items->data,
3412 as->parms[1].items->data);
3414 PrintDiagnostics("rename", code);
3417 fprintf(STDOUT, "Renamed volume %s to %s\n", as->parms[0].items->data,
3418 as->parms[1].items->data);
3422 GetVolumeInfo(volid, server, part, voltype, rentry)
3423 afs_int32 *server, volid, *part, *voltype;
3424 register struct nvldbentry *rentry;
3429 vcode = VLDB_GetEntryByID(volid, -1, rentry);
3432 "Could not fetch the entry for volume %lu from VLDB \n",
3433 (unsigned long)volid);
3434 PrintError("", vcode);
3437 MapHostToNetwork(rentry);
3438 if (volid == rentry->volumeId[ROVOL]) {
3440 for (i = 0; i < rentry->nServers; i++) {
3441 if ((index == -1) && (rentry->serverFlags[i] & ITSROVOL)
3442 && !(rentry->serverFlags[i] & RO_DONTUSE))
3447 "RO volume is not found in VLDB entry for volume %lu\n",
3448 (unsigned long)volid);
3452 *server = rentry->serverNumber[index];
3453 *part = rentry->serverPartition[index];
3457 index = Lp_GetRwIndex(rentry);
3460 "RW Volume is not found in VLDB entry for volume %lu\n",
3461 (unsigned long)volid);
3464 if (volid == rentry->volumeId[RWVOL]) {
3466 *server = rentry->serverNumber[index];
3467 *part = rentry->serverPartition[index];
3470 if (volid == rentry->volumeId[BACKVOL]) {
3472 *server = rentry->serverNumber[index];
3473 *part = rentry->serverPartition[index];
3480 register struct cmd_syndesc *as;
3486 struct VldbListByAttributes attributes;
3487 nbulkentries arrayEntries;
3488 register struct nvldbentry *vllist;
3489 struct cmd_item *itp;
3492 char prefix[VOLSER_MAXVOLNAME + 1];
3494 afs_int32 totalBack = 0, totalFail = 0, err;
3496 if (as->parms[0].items) { /* -id */
3497 if (as->parms[1].items || as->parms[2].items || as->parms[3].items) {
3499 "You cannot use -server, -partition, or -prefix with the -id argument\n");
3502 for (itp = as->parms[0].items; itp; itp = itp->next) {
3503 avolid = vsu_GetVolumeID(itp->data, cstruct, &err);
3506 PrintError("", err);
3508 fprintf(STDERR, "vos: can't find volume '%s'\n",
3512 if (as->parms[4].items) { /* -noexecute */
3513 fprintf(STDOUT, "Would have deleted VLDB entry for %s \n",
3518 vcode = ubik_Call(VL_DeleteEntry, cstruct, 0, avolid, RWVOL);
3520 fprintf(STDERR, "Could not delete entry for volume %s\n",
3523 "You must specify a RW volume name or ID "
3524 "(the entire VLDB entry will be deleted)\n",
3526 PrintError("", vcode);
3532 fprintf(STDOUT, "Deleted %d VLDB entries\n", totalBack);
3536 if (!as->parms[1].items && !as->parms[2].items && !as->parms[3].items) {
3537 fprintf(STDERR, "You must specify an option\n");
3541 /* Zero out search attributes */
3542 memset(&attributes, 0, sizeof(struct VldbListByAttributes));
3544 if (as->parms[1].items) { /* -prefix */
3545 strncpy(prefix, as->parms[1].items->data, VOLSER_MAXVOLNAME);
3547 if (!as->parms[2].items && !as->parms[3].items) { /* a single entry only */
3549 "You must provide -server with the -prefix argument\n");
3554 if (as->parms[2].items) { /* -server */
3556 aserver = GetServer(as->parms[2].items->data);
3558 fprintf(STDERR, "vos: server '%s' not found in host table\n",
3559 as->parms[2].items->data);
3562 attributes.server = ntohl(aserver);
3563 attributes.Mask |= VLLIST_SERVER;
3566 if (as->parms[3].items) { /* -partition */
3567 if (!as->parms[2].items) {
3569 "You must provide -server with the -partition argument\n");
3572 apart = volutil_GetPartitionID(as->parms[3].items->data);
3574 fprintf(STDERR, "vos: could not interpret partition name '%s'\n",
3575 as->parms[3].items->data);
3578 attributes.partition = apart;
3579 attributes.Mask |= VLLIST_PARTITION;
3582 /* Print status line of what we are doing */
3583 fprintf(STDOUT, "Deleting VLDB entries for ");
3584 if (as->parms[2].items) {
3585 fprintf(STDOUT, "server %s ", as->parms[2].items->data);
3587 if (as->parms[3].items) {
3589 MapPartIdIntoName(apart, pname);
3590 fprintf(STDOUT, "partition %s ", pname);
3593 fprintf(STDOUT, "which are prefixed with %s ", prefix);
3595 fprintf(STDOUT, "\n");
3598 /* Get all the VLDB entries on a server and/or partition */
3599 memset(&arrayEntries, 0, sizeof(arrayEntries));
3600 vcode = VLDB_ListAttributes(&attributes, &nentries, &arrayEntries);
3602 fprintf(STDERR, "Could not access the VLDB for attributes\n");
3603 PrintError("", vcode);
3607 /* Process each entry */
3608 for (j = 0; j < nentries; j++) {
3609 vllist = &arrayEntries.nbulkentries_val[j];
3611 /* It only deletes the RW volumes */
3612 if (strncmp(vllist->name, prefix, strlen(prefix))) {
3615 "Omitting to delete %s due to prefix %s mismatch\n",
3616 vllist->name, prefix);
3623 if (as->parms[4].items) { /* -noexecute */
3624 fprintf(STDOUT, "Would have deleted VLDB entry for %s \n",
3630 /* Only matches the RW volume name */
3631 avolid = vllist->volumeId[RWVOL];
3632 vcode = ubik_Call(VL_DeleteEntry, cstruct, 0, avolid, RWVOL);
3634 fprintf(STDOUT, "Could not delete VDLB entry for %s\n",
3637 PrintError("", vcode);
3642 fprintf(STDOUT, "Deleted VLDB entry for %s \n", vllist->name);
3647 fprintf(STDOUT, "----------------------\n");
3649 "Total VLDB entries deleted: %lu; failed to delete: %lu\n",
3650 (unsigned long)totalBack, (unsigned long)totalFail);
3651 if (arrayEntries.nbulkentries_val)
3652 free(arrayEntries.nbulkentries_val);
3658 CompareVldbEntryByName(p1, p2)
3661 struct nvldbentry *arg1, *arg2;
3663 arg1 = (struct nvldbentry *)p1;
3664 arg2 = (struct nvldbentry *)p2;
3665 return (strcmp(arg1->name, arg2->name));
3669 static int CompareVldbEntry(p1,p2)
3672 struct nvldbentry *arg1,*arg2;
3675 char comp1[100],comp2[100];
3676 char temp1[20],temp2[20];
3678 arg1 = (struct nvldbentry *)p1;
3679 arg2 = (struct nvldbentry *)p2;
3683 for(i = 0; i < arg1->nServers; i++)
3684 if(arg1->serverFlags[i] & ITSRWVOL) pos1 = i;
3685 for(i = 0; i < arg2->nServers; i++)
3686 if(arg2->serverFlags[i] & ITSRWVOL) pos2 = i;
3687 if(pos1 == -1 || pos2 == -1){
3691 sprintf(comp1,"%10u",arg1->serverNumber[pos1]);
3692 sprintf(comp2,"%10u",arg2->serverNumber[pos2]);
3693 sprintf(temp1,"%10u",arg1->serverPartition[pos1]);
3694 sprintf(temp2,"%10u",arg2->serverPartition[pos2]);
3695 strcat(comp1,temp1);
3696 strcat(comp2,temp2);
3697 strcat(comp1,arg1->name);
3698 strcat(comp1,arg2->name);
3699 return(strcmp(comp1,comp2));
3706 struct cmd_syndesc *as;
3709 afs_int32 aserver, code;
3711 struct VldbListByAttributes attributes;
3712 nbulkentries arrayEntries;
3713 struct nvldbentry *vllist, *tarray = 0, *ttarray;
3714 afs_int32 centries, nentries = 0, tarraysize, parraysize;
3717 int quiet, sort, lock;
3718 afs_int32 thisindex, nextindex;
3723 attributes.Mask = 0;
3724 lock = (as->parms[3].items ? 1 : 0); /* -lock flag */
3725 quiet = (as->parms[4].items ? 1 : 0); /* -quit flag */
3726 sort = (as->parms[5].items ? 0 : 1); /* -nosort flag */
3728 /* If the volume name is given, Use VolumeInfoCmd to look it up
3729 * and not ListAttributes.
3731 if (as->parms[0].items) {
3734 "vos: illegal use of '-locked' switch, need to specify server and/or partition\n");
3737 code = VolumeInfoCmd(as->parms[0].items->data);
3739 PrintError("", code);
3745 /* Server specified */
3746 if (as->parms[1].items) {
3747 aserver = GetServer(as->parms[1].items->data);
3749 fprintf(STDERR, "vos: server '%s' not found in host table\n",
3750 as->parms[1].items->data);
3753 attributes.server = ntohl(aserver);
3754 attributes.Mask |= VLLIST_SERVER;
3757 /* Partition specified */
3758 if (as->parms[2].items) {
3759 apart = volutil_GetPartitionID(as->parms[2].items->data);
3761 fprintf(STDERR, "vos: could not interpret partition name '%s'\n",
3762 as->parms[2].items->data);
3765 attributes.partition = apart;
3766 attributes.Mask |= VLLIST_PARTITION;
3770 attributes.Mask |= VLLIST_FLAG;
3771 attributes.flag = VLOP_ALLOPERS;
3774 /* Print header information */
3776 MapPartIdIntoName(apart, pname);
3777 fprintf(STDOUT, "VLDB entries for %s %s%s%s %s\n",
3778 (as->parms[1].items ? "server" : "all"),
3779 (as->parms[1].items ? as->parms[1].items->data : "servers"),
3780 (as->parms[2].items ? " partition " : ""),
3781 (as->parms[2].items ? pname : ""),
3782 (lock ? "which are locked:" : ""));
3785 for (thisindex = 0; (thisindex != -1); thisindex = nextindex) {
3786 memset(&arrayEntries, 0, sizeof(arrayEntries));
3791 VLDB_ListAttributesN2(&attributes, 0, thisindex, ¢ries,
3792 &arrayEntries, &nextindex);
3793 if (vcode == RXGEN_OPCODE) {
3794 /* Vlserver not running with ListAttributesN2. Fall back */
3796 VLDB_ListAttributes(&attributes, ¢ries, &arrayEntries);
3800 fprintf(STDERR, "Could not access the VLDB for attributes\n");
3801 PrintError("", vcode);
3804 nentries += centries;
3806 /* We don't sort, so just print the entries now */
3808 for (j = 0; j < centries; j++) { /* process each entry */
3809 vllist = &arrayEntries.nbulkentries_val[j];
3810 MapHostToNetwork(vllist);
3811 EnumerateEntry(vllist);
3813 if (vllist->flags & VLOP_ALLOPERS)
3814 fprintf(STDOUT, " Volume is currently LOCKED \n");
3818 /* So we sort. First we must collect all the entries and keep
3821 else if (centries > 0) {
3823 /* steal away the first bulk entries array */
3824 tarray = (struct nvldbentry *)arrayEntries.nbulkentries_val;
3825 tarraysize = centries * sizeof(struct nvldbentry);
3826 arrayEntries.nbulkentries_val = 0;
3828 /* Grow the tarray to keep the extra entries */
3829 parraysize = (centries * sizeof(struct nvldbentry));
3831 (struct nvldbentry *)realloc(tarray,
3832 tarraysize + parraysize);
3835 "Could not allocate enough space for the VLDB entries\n");
3841 memcpy(((char *)tarray) + tarraysize,
3842 (char *)arrayEntries.nbulkentries_val, parraysize);
3843 tarraysize += parraysize;
3847 /* Free the bulk array */
3848 if (arrayEntries.nbulkentries_val) {
3849 free(arrayEntries.nbulkentries_val);
3850 arrayEntries.nbulkentries_val = 0;
3854 /* Here is where we now sort all the entries and print them */
3855 if (sort && (nentries > 0)) {
3856 qsort((char *)tarray, nentries, sizeof(struct nvldbentry),
3857 CompareVldbEntryByName);
3858 for (vllist = tarray, j = 0; j < nentries; j++, vllist++) {
3859 MapHostToNetwork(vllist);
3860 EnumerateEntry(vllist);
3862 if (vllist->flags & VLOP_ALLOPERS)
3863 fprintf(STDOUT, " Volume is currently LOCKED \n");
3869 fprintf(STDOUT, "\nTotal entries: %lu\n", (unsigned long)nentries);
3877 register struct cmd_syndesc *as;
3879 afs_int32 apart = 0, avolid;
3880 afs_int32 aserver = 0, code, aserver1, apart1;
3882 struct VldbListByAttributes attributes;
3883 nbulkentries arrayEntries;
3884 register struct nvldbentry *vllist;
3888 int seenprefix, seenxprefix, exclude, ex, exp, noaction;
3889 afs_int32 totalBack = 0;
3890 afs_int32 totalFail = 0;
3891 int previdx = -1, error, same;
3894 struct cmd_item *ti;
3898 memset(&attributes, 0, sizeof(struct VldbListByAttributes));
3899 attributes.Mask = 0;
3901 seenprefix = (as->parms[0].items ? 1 : 0);
3902 exclude = (as->parms[3].items ? 1 : 0);
3903 seenxprefix = (as->parms[4].items ? 1 : 0);
3904 noaction = (as->parms[5].items ? 1 : 0);
3906 if (as->parms[1].items) { /* -server */
3907 aserver = GetServer(as->parms[1].items->data);
3909 fprintf(STDERR, "vos: server '%s' not found in host table\n",
3910 as->parms[1].items->data);
3913 attributes.server = ntohl(aserver);
3914 attributes.Mask |= VLLIST_SERVER;
3917 if (as->parms[2].items) { /* -partition */
3918 apart = volutil_GetPartitionID(as->parms[2].items->data);
3920 fprintf(STDERR, "vos: could not interpret partition name '%s'\n",
3921 as->parms[2].items->data);
3924 attributes.partition = apart;
3925 attributes.Mask |= VLLIST_PARTITION;
3928 /* Check to make sure the prefix and xprefix expressions compile ok */
3930 for (ti = as->parms[0].items; ti; ti = ti->next) {
3931 if (strncmp(ti->data, "^", 1) == 0) {
3932 ccode = (char *)re_comp(ti->data);
3935 "Unrecognizable -prefix regular expression: '%s': %s\n",
3943 for (ti = as->parms[4].items; ti; ti = ti->next) {
3944 if (strncmp(ti->data, "^", 1) == 0) {
3945 ccode = (char *)re_comp(ti->data);
3948 "Unrecognizable -xprefix regular expression: '%s': %s\n",
3956 memset(&arrayEntries, 0, sizeof(arrayEntries)); /* initialize to hint the stub to alloc space */
3957 vcode = VLDB_ListAttributes(&attributes, &nentries, &arrayEntries);
3959 fprintf(STDERR, "Could not access the VLDB for attributes\n");
3960 PrintError("", vcode);
3964 if (as->parms[1].items || as->parms[2].items || verbose) {
3965 fprintf(STDOUT, "%s up volumes",
3966 (noaction ? "Would have backed" : "Backing"));
3968 if (as->parms[1].items) {
3969 fprintf(STDOUT, " on server %s", as->parms[1].items->data);
3970 } else if (as->parms[2].items) {
3971 fprintf(STDOUT, " for all servers");
3974 if (as->parms[2].items) {
3975 MapPartIdIntoName(apart, pname);
3976 fprintf(STDOUT, " partition %s", pname);
3979 if (seenprefix || (!seenprefix && seenxprefix)) {
3980 ti = (seenprefix ? as->parms[0].items : as->parms[4].items);
3981 ex = (seenprefix ? exclude : !exclude);
3982 exp = (strncmp(ti->data, "^", 1) == 0);
3983 fprintf(STDOUT, " which %smatch %s '%s'", (ex ? "do not " : ""),
3984 (exp ? "expression" : "prefix"), ti->data);
3985 for (ti = ti->next; ti; ti = ti->next) {
3986 exp = (strncmp(ti->data, "^", 1) == 0);
3987 printf(" %sor %s '%s'", (ex ? "n" : ""),
3988 (exp ? "expression" : "prefix"), ti->data);
3992 if (seenprefix && seenxprefix) {
3993 ti = as->parms[4].items;
3994 exp = (strncmp(ti->data, "^", 1) == 0);
3995 fprintf(STDOUT, " %swhich match %s '%s'",
3996 (exclude ? "adding those " : "removing those "),
3997 (exp ? "expression" : "prefix"), ti->data);
3998 for (ti = ti->next; ti; ti = ti->next) {
3999 exp = (strncmp(ti->data, "^", 1) == 0);
4000 printf(" or %s '%s'", (exp ? "expression" : "prefix"),
4004 fprintf(STDOUT, " .. ");
4006 fprintf(STDOUT, "\n");
4010 for (j = 0; j < nentries; j++) { /* process each vldb entry */
4011 vllist = &arrayEntries.nbulkentries_val[j];
4014 for (ti = as->parms[0].items; ti; ti = ti->next) {
4015 if (strncmp(ti->data, "^", 1) == 0) {
4016 ccode = (char *)re_comp(ti->data);
4019 "Error in -prefix regular expression: '%s': %s\n",
4023 match = (re_exec(vllist->name) == 1);
4026 (strncmp(vllist->name, ti->data, strlen(ti->data)) ==
4036 /* Without the -exclude flag: If it matches the prefix, then
4037 * check if we want to exclude any from xprefix.
4038 * With the -exclude flag: If it matches the prefix, then
4039 * check if we want to add any from xprefix.
4041 if (match && seenxprefix) {
4042 for (ti = as->parms[4].items; ti; ti = ti->next) {
4043 if (strncmp(ti->data, "^", 1) == 0) {
4044 ccode = (char *)re_comp(ti->data);
4047 "Error in -xprefix regular expression: '%s': %s\n",
4051 if (re_exec(vllist->name) == 1) {
4056 if (strncmp(vllist->name, ti->data, strlen(ti->data)) ==
4066 match = !match; /* -exclude will reverse the match */
4068 continue; /* Skip if no match */
4070 /* Print list of volumes to backup */
4072 fprintf(STDOUT, " %s\n", vllist->name);
4076 if (!(vllist->flags & RW_EXISTS)) {
4079 "Omitting to backup %s since RW volume does not exist \n",
4081 fprintf(STDOUT, "\n");
4087 avolid = vllist->volumeId[RWVOL];
4088 MapHostToNetwork(vllist);
4089 GetServerAndPart(vllist, RWVOL, &aserver1, &apart1, &previdx);
4090 if (aserver1 == -1 || apart1 == -1) {
4091 fprintf(STDOUT, "could not backup %s, invalid VLDB entry\n",
4097 same = VLDB_IsSameAddrs(aserver, aserver1, &error);
4100 "Failed to get info about server's %d address(es) from vlserver (err=%d); aborting call!\n",
4106 if ((aserver && !same) || (apart && (apart != apart1))) {
4109 "Omitting to backup %s since the RW is in a different location\n",
4115 time_t now = time(0);
4116 fprintf(STDOUT, "Creating backup volume for %s on %s",
4117 vllist->name, ctime(&now));
4121 code = UV_BackupVolume(aserver1, apart1, avolid);
4123 fprintf(STDOUT, "Could not backup %s\n", vllist->name);
4129 fprintf(STDOUT, "\n");
4131 } /* process each vldb entry */
4132 fprintf(STDOUT, "done\n");
4133 fprintf(STDOUT, "Total volumes backed up: %lu; failed to backup: %lu\n",
4134 (unsigned long)totalBack, (unsigned long)totalFail);
4136 if (arrayEntries.nbulkentries_val)
4137 free(arrayEntries.nbulkentries_val);
4143 register struct cmd_syndesc *as;
4146 afs_int32 aserver, code;
4148 struct VldbListByAttributes attributes;
4149 nbulkentries arrayEntries;
4150 register struct nvldbentry *vllist;
4159 attributes.Mask = 0;
4161 if (as->parms[0].items) { /* server specified */
4162 aserver = GetServer(as->parms[0].items->data);
4164 fprintf(STDERR, "vos: server '%s' not found in host table\n",
4165 as->parms[0].items->data);
4168 attributes.server = ntohl(aserver);
4169 attributes.Mask |= VLLIST_SERVER;
4171 if (as->parms[1].items) { /* partition specified */
4172 apart = volutil_GetPartitionID(as->parms[1].items->data);
4174 fprintf(STDERR, "vos: could not interpret partition name '%s'\n",
4175 as->parms[1].items->data);
4178 if (!IsPartValid(apart, aserver, &code)) { /*check for validity of the partition */
4180 PrintError("", code);
4183 "vos : partition %s does not exist on the server\n",
4184 as->parms[1].items->data);
4187 attributes.partition = apart;
4188 attributes.Mask |= VLLIST_PARTITION;
4190 attributes.flag = VLOP_ALLOPERS;
4191 attributes.Mask |= VLLIST_FLAG;
4192 memset(&arrayEntries, 0, sizeof(arrayEntries)); /*initialize to hint the stub to alloc space */
4193 vcode = VLDB_ListAttributes(&attributes, &nentries, &arrayEntries);
4195 fprintf(STDERR, "Could not access the VLDB for attributes\n");
4196 PrintError("", vcode);
4199 for (j = 0; j < nentries; j++) { /* process each entry */
4200 vllist = &arrayEntries.nbulkentries_val[j];
4201 volid = vllist->volumeId[RWVOL];
4203 ubik_Call(VL_ReleaseLock, cstruct, 0, volid, -1,
4204 LOCKREL_OPCODE | LOCKREL_AFSID | LOCKREL_TIMESTAMP);
4206 fprintf(STDERR, "Could not unlock entry for volume %s\n",
4208 PrintError("", vcode);
4213 MapPartIdIntoName(apart, pname);
4216 "Could not lock %lu VLDB entries of %lu locked entries\n",
4217 (unsigned long)totalE, (unsigned long)nentries);
4219 if (as->parms[0].items) {
4221 "Unlocked all the VLDB entries for volumes on server %s ",
4222 as->parms[0].items->data);
4223 if (as->parms[1].items) {
4224 MapPartIdIntoName(apart, pname);
4225 fprintf(STDOUT, "partition %s\n", pname);
4227 fprintf(STDOUT, "\n");
4229 } else if (as->parms[1].items) {
4230 MapPartIdIntoName(apart, pname);
4232 "Unlocked all the VLDB entries for volumes on partition %s on all servers\n",
4237 if (arrayEntries.nbulkentries_val)
4238 free(arrayEntries.nbulkentries_val);
4244 register struct cmd_syndesc *as;
4247 afs_int32 aserver, code;
4249 struct diskPartition partition;
4250 struct partList dummyPartList;
4254 aserver = GetServer(as->parms[0].items->data);
4256 fprintf(STDERR, "vos: server '%s' not found in host table\n",
4257 as->parms[0].items->data);
4260 if (as->parms[1].items) {
4261 apart = volutil_GetPartitionID(as->parms[1].items->data);
4263 fprintf(STDERR, "vos: could not interpret partition name '%s'\n",
4264 as->parms[1].items->data);
4267 dummyPartList.partId[0] = apart;
4268 dummyPartList.partFlags[0] = PARTVALID;
4272 if (!IsPartValid(apart, aserver, &code)) { /*check for validity of the partition */
4274 PrintError("", code);
4277 "vos : partition %s does not exist on the server\n",
4278 as->parms[1].items->data);
4282 code = UV_ListPartitions(aserver, &dummyPartList, &cnt);
4284 PrintDiagnostics("listpart", code);
4288 for (i = 0; i < cnt; i++) {
4289 if (dummyPartList.partFlags[i] & PARTVALID) {
4290 MapPartIdIntoName(dummyPartList.partId[i], pname);
4291 code = UV_PartitionInfo(aserver, pname, &partition);
4293 fprintf(STDERR, "Could not get information on partition %s\n",
4295 PrintError("", code);
4299 "Free space on partition %s: %d K blocks out of total %d\n",
4300 pname, partition.free, partition.minFree);
4308 register struct cmd_syndesc *as;
4311 afs_int32 ip1, ip2, vcode;
4314 ip1 = GetServer(as->parms[0].items->data);
4316 fprintf(STDERR, "vos: invalid host address\n");
4320 if ((as->parms[1].items && as->parms[2].items)
4321 || (!as->parms[1].items && !as->parms[2].items)) {
4323 "vos: Must specify either '-newaddr <addr>' or '-remove' flag\n");
4327 if (as->parms[1].items) {
4328 ip2 = GetServer(as->parms[1].items->data);
4330 fprintf(STDERR, "vos: invalid host address\n");
4334 /* Play a trick here. If we are removing an address, ip1 will be -1
4335 * and ip2 will be the original address. This switch prevents an
4336 * older revision vlserver from removing the IP address.
4343 vcode = ubik_Call_New(VL_ChangeAddr, cstruct, 0, ntohl(ip1), ntohl(ip2));
4346 fprintf(STDERR, "Could not remove server %s from the VLDB\n",
4347 as->parms[0].items->data);
4348 if (vcode == VL_NOENT) {
4350 "vlserver does not support the remove flag or ");
4353 fprintf(STDERR, "Could not change server %s to server %s\n",
4354 as->parms[0].items->data, as->parms[1].items->data);
4356 PrintError("", vcode);
4361 fprintf(STDOUT, "Removed server %s from the VLDB\n",
4362 as->parms[0].items->data);
4364 fprintf(STDOUT, "Changed server %s to server %s\n",
4365 as->parms[0].items->data, as->parms[1].items->data);
4371 print_addrs(const bulkaddrs * addrs, const afsUUID * m_uuid, int nentries,
4372 int print, int noresolve)
4376 struct VLCallBack unused;
4379 ListAddrByAttributes m_attrs;
4380 afs_int32 m_unique, m_nentries, *m_addrp;
4381 afs_int32 base, index;
4385 afsUUID_to_string(m_uuid, buf, sizeof(buf));
4386 printf("UUID: %s\n", buf);
4389 /* print out the list of all the server */
4390 addrp = (afs_int32 *) addrs->bulkaddrs_val;
4391 for (i = 0; i < nentries; i++, addrp++) {
4392 /* If it is a multihomed address, then we will need to
4393 * get the addresses for this multihomed server from
4394 * the vlserver and print them.
4396 if (((*addrp & 0xff000000) == 0xff000000) && ((*addrp) & 0xffff)) {
4397 /* Get the list of multihomed fileservers */
4398 base = (*addrp >> 16) & 0xff;
4399 index = (*addrp) & 0xffff;
4401 if ((base >= 0) && (base <= VL_MAX_ADDREXTBLKS) && (index >= 1)
4402 && (index <= VL_MHSRV_PERBLK)) {
4403 m_attrs.Mask = VLADDR_INDEX;
4404 m_attrs.index = (base * VL_MHSRV_PERBLK) + index;
4406 m_addrs.bulkaddrs_val = 0;
4407 m_addrs.bulkaddrs_len = 0;
4409 ubik_Call(VL_GetAddrsU, cstruct, 0, &m_attrs, &m_uuid,
4410 &m_unique, &m_nentries, &m_addrs);
4413 "vos: could not list the multi-homed server addresses\n");
4414 PrintError("", vcode);
4417 /* Print the list */
4418 m_addrp = (afs_int32 *) m_addrs.bulkaddrs_val;
4419 for (j = 0; j < m_nentries; j++, m_addrp++) {
4420 *m_addrp = htonl(*m_addrp);
4423 printf("%s ", afs_inet_ntoa_r(*m_addrp, hoststr));
4425 printf("%s ", hostutil_GetNameByINet(*m_addrp));
4429 printf("<unknown>\n");
4438 /* Otherwise, it is a non-multihomed entry and contains
4439 * the IP address of the server - print it.
4441 *addrp = htonl(*addrp);
4444 printf("%s\n", afs_inet_ntoa_r(*addrp, hoststr));
4446 printf("%s\n", hostutil_GetNameByINet(*addrp));
4458 register struct cmd_syndesc *as;
4461 afs_int32 i, j, noresolve = 0, printuuid = 0;
4462 struct VLCallBack unused;
4463 afs_int32 nentries, *addrp;
4464 bulkaddrs addrs, m_addrs;
4465 ListAddrByAttributes m_attrs;
4466 afsUUID m_uuid, askuuid;
4467 afs_int32 m_unique, m_nentries, *m_addrp;
4468 afs_int32 base, index;
4470 memset(&m_attrs, 0, sizeof(struct ListAddrByAttributes));
4471 m_attrs.Mask = VLADDR_INDEX;
4473 memset(&m_addrs, 0, sizeof(bulkaddrs));
4474 memset(&askuuid, 0, sizeof(afsUUID));
4475 if (as->parms[0].items) {
4477 afsUUID_from_string(as->parms[0].items->data, &askuuid);
4478 m_attrs.Mask = VLADDR_UUID;
4479 m_attrs.uuid = askuuid;
4481 if (as->parms[1].items) {
4485 he = hostutil_GetHostByName((char *)as->parms[1].items->data);
4487 fprintf(stderr, "Can't get host info for '%s'\n",
4488 as->parms[1].items->data);
4491 memcpy(&saddr, he->h_addr, 4);
4492 m_attrs.Mask = VLADDR_IPADDR;
4493 m_attrs.ipaddr = ntohl(saddr);
4495 if (as->parms[2].items) {
4498 if (as->parms[3].items) {
4502 m_addrs.bulkaddrs_val = 0;
4503 m_addrs.bulkaddrs_len = 0;
4506 ubik_Call_New(VL_GetAddrs, cstruct, 0, 0, 0, &m_unique, &nentries,
4509 fprintf(STDERR, "vos: could not list the server addresses\n");
4510 PrintError("", vcode);
4515 m_addrs.bulkaddrs_val = 0;
4516 m_addrs.bulkaddrs_len = 0;
4522 ubik_Call_New(VL_GetAddrsU, cstruct, 0, &m_attrs, &m_uuid,
4523 &m_unique, &m_nentries, &m_addrs);
4524 if (vcode == VL_NOENT) {
4530 if (vcode == VL_INDEXERANGE) {
4535 fprintf(STDERR, "vos: could not list the server addresses\n");
4536 PrintError("", vcode);
4540 print_addrs(&m_addrs, &m_uuid, m_nentries, printuuid, noresolve);
4543 if ((as->parms[1].items) || (as->parms[0].items) || (i > nentries))
4552 register struct cmd_syndesc *as;
4555 afs_int32 avolid, vcode, err;
4557 avolid = vsu_GetVolumeID(as->parms[0].items->data, cstruct, &err);
4560 PrintError("", err);
4562 fprintf(STDERR, "vos: can't find volume '%s'\n",
4563 as->parms[0].items->data);
4566 vcode = ubik_Call(VL_SetLock, cstruct, 0, avolid, -1, VLOP_DELETE);
4568 fprintf(STDERR, "Could not lock VLDB entry for volume %s\n",
4569 as->parms[0].items->data);
4570 PrintError("", vcode);
4573 fprintf(STDOUT, "Locked VLDB entry for volume %s\n",
4574 as->parms[0].items->data);
4580 register struct cmd_syndesc *as;
4583 afs_int32 partition = -1;
4584 afs_int32 server, volid, code, i, same;
4585 struct nvldbentry entry, storeEntry;
4588 afs_int32 rwserver = 0;
4589 afs_int32 rwpartition;
4591 afs_int32 roserver = 0;
4592 afs_int32 ropartition;
4594 struct rx_connection *aconn;
4597 server = GetServer(as->parms[0].items->data);
4599 fprintf(STDERR, "vos: host '%s' not found in host table\n",
4600 as->parms[0].items->data);
4603 partition = volutil_GetPartitionID(as->parms[1].items->data);
4604 if (partition < 0) {
4605 fprintf(STDERR, "vos: could not interpret partition name '%s'\n",
4606 as->parms[1].items->data);
4609 if (!IsPartValid(partition, server, &code)) {
4611 PrintError("", code);
4614 "vos : partition %s does not exist on the server\n",
4615 as->parms[1].items->data);
4618 volid = vsu_GetVolumeID(as->parms[2].items->data, cstruct, &code);
4621 PrintError("", code);
4623 fprintf(STDERR, "Unknown volume ID or name '%s'\n",
4624 as->parms[0].items->data);
4627 if (as->parms[3].items)
4630 vcode = VLDB_GetEntryByID(volid, -1, &entry);
4633 "Could not fetch the entry for volume %lu from VLDB\n",
4634 (unsigned long)volid);
4635 PrintError("convertROtoRW", code);
4639 /* use RO volid even if user specified RW or BK volid */
4641 if (volid != entry.volumeId[ROVOL])
4642 volid = entry.volumeId[ROVOL];
4644 MapHostToNetwork(&entry);
4645 for (i = 0; i < entry.nServers; i++) {
4646 if (entry.serverFlags[i] & ITSRWVOL) {
4648 rwserver = entry.serverNumber[i];
4649 rwpartition = entry.serverPartition[i];
4651 if (entry.serverFlags[i] & ITSROVOL) {
4652 same = VLDB_IsSameAddrs(server, entry.serverNumber[i], &code);
4655 "Failed to get info about server's %d address(es) from vlserver (err=%d); aborting call!\n",
4661 roserver = entry.serverNumber[i];
4662 ropartition = entry.serverPartition[i];
4668 fprintf(STDERR, "Warning: RO volume didn't exist in vldb!\n");
4670 if (ropartition != partition) {
4672 "Warning: RO volume should be in partition %d instead of %d (vldb)\n",
4673 ropartition, partition);
4678 "VLDB indicates that a RW volume exists already on %s in partition %s.\n",
4679 hostutil_GetNameByINet(rwserver),
4680 volutil_PartitionName(rwpartition));
4682 fprintf(STDERR, "Overwrite this VLDB entry? [y|n] (n)\n");
4684 while (!(dc == EOF || dc == '\n'))
4685 dc = getchar(); /* goto end of line */
4686 if ((c != 'y') && (c != 'Y')) {
4687 fprintf(STDERR, "aborted.\n");
4694 ubik_Call(VL_SetLock, cstruct, 0, entry.volumeId[RWVOL], RWVOL,
4696 aconn = UV_Bind(server, AFSCONF_VOLUMEPORT);
4697 code = AFSVolConvertROtoRWvolume(aconn, partition, volid);
4700 "Converting RO volume %lu to RW volume failed with code %d\n",
4701 (unsigned long)volid, code);
4702 PrintError("convertROtoRW ", code);
4705 entry.serverFlags[roindex] = ITSRWVOL;
4706 entry.flags |= RW_EXISTS;
4707 entry.flags &= ~BACK_EXISTS;
4710 if (rwindex != entry.nServers) {
4711 entry.serverNumber[rwindex] = entry.serverNumber[entry.nServers];
4712 entry.serverPartition[rwindex] =
4713 entry.serverPartition[entry.nServers];
4714 entry.serverFlags[rwindex] = entry.serverFlags[entry.nServers];
4715 entry.serverNumber[entry.nServers] = 0;
4716 entry.serverPartition[entry.nServers] = 0;
4717 entry.serverFlags[entry.nServers] = 0;
4720 entry.flags &= ~RO_EXISTS;
4721 for (i = 0; i < entry.nServers; i++) {
4722 if (entry.serverFlags[i] & ITSROVOL) {
4723 if (!(entry.serverFlags[i] & (RO_DONTUSE | NEW_REPSITE)))
4724 entry.flags |= RO_EXISTS;
4727 MapNetworkToHost(&entry, &storeEntry);
4729 VLDB_ReplaceEntry(entry.volumeId[RWVOL], RWVOL, &storeEntry,
4730 (LOCKREL_OPCODE | LOCKREL_AFSID |
4731 LOCKREL_TIMESTAMP));
4734 "Warning: volume converted, but vldb update failed with code %d!\n",
4737 vcode = UV_LockRelease(entry.volumeId[RWVOL]);
4739 PrintDiagnostics("unlock", vcode);
4746 register struct cmd_syndesc *as;
4748 afs_int32 avolid, aserver, apart, voltype, fromdate = 0, code, err, i;
4749 struct nvldbentry entry;
4750 volintSize vol_size;
4752 rx_SetRxDeadTime(60 * 10);
4753 for (i = 0; i < MAXSERVERS; i++) {
4754 struct rx_connection *rxConn = ubik_GetRPCConn(cstruct, i);
4757 rx_SetConnDeadTime(rxConn, rx_connDeadTime);
4758 if (rxConn->service)
4759 rxConn->service->connDeadTime = rx_connDeadTime;
4762 avolid = vsu_GetVolumeID(as->parms[0].items->data, cstruct, &err);
4765 PrintError("", err);
4767 fprintf(STDERR, "vos: can't find volume '%s'\n",
4768 as->parms[0].items->data);
4772 if (as->parms[1].items || as->parms[2].items) {
4773 if (!as->parms[1].items || !as->parms[2].items) {
4775 "Must specify both -server and -partition options\n");
4778 aserver = GetServer(as->parms[2].items->data);
4780 fprintf(STDERR, "Invalid server name\n");
4783 apart = volutil_GetPartitionID(as->parms[1].items->data);
4785 fprintf(STDERR, "Invalid partition name\n");
4789 code = GetVolumeInfo(avolid, &aserver, &apart, &voltype, &entry);
4796 if (as->parms[4].items && strcmp(as->parms[4].items->data, "0")) {
4797 code = ktime_DateToInt32(as->parms[4].items->data, &fromdate);
4799 fprintf(STDERR, "vos: failed to parse date '%s' (error=%d))\n",
4800 as->parms[1].items->data, code);
4805 fprintf(STDOUT, "Volume: %s\n", as->parms[0].items->data);
4807 if (as->parms[3].items) { /* do the dump estimate */
4808 vol_size.dump_size = 0;
4809 code = UV_GetSize(avolid, aserver, apart, fromdate, &vol_size);
4811 PrintDiagnostics("size", code);
4814 /* presumably the size info is now gathered in pntr */
4815 /* now we display it */
4817 fprintf(STDOUT, "dump_size: %llu\n", vol_size.dump_size);
4825 PrintDiagnostics(astring, acode)
4829 if (acode == EACCES) {
4831 "You are not authorized to perform the 'vos %s' command (%d)\n",
4834 fprintf(STDERR, "Error in vos %s command.\n", astring);
4835 PrintError("", acode);
4842 MyBeforeProc(as, arock)
4843 struct cmd_syndesc *as;
4846 register char *tcell;
4847 register afs_int32 code;
4848 register afs_int32 sauth;
4850 /* Initialize the ubik_client connection */
4851 rx_SetRxDeadTime(90);
4852 cstruct = (struct ubik_client *)0;
4856 if (as->parms[12].items) /* if -cell specified */
4857 tcell = as->parms[12].items->data;
4858 if (as->parms[14].items) /* -serverauth specified */
4860 if (as->parms[16].items) /* -crypt specified */
4863 vsu_ClientInit((as->parms[13].items != 0), confdir, tcell, sauth,
4864 &cstruct, UV_SetSecurity))) {
4865 fprintf(STDERR, "could not initialize VLDB library (code=%lu) \n",
4866 (unsigned long)code);
4870 if (as->parms[15].items) /* -verbose flag set */
4880 /* this sucks but it works for now.
4885 #include "AFS_component_version_number.c"
4891 register afs_int32 code;
4893 register struct cmd_syndesc *ts;
4895 #ifdef AFS_AIX32_ENV
4897 * The following signal action for AIX is necessary so that in case of a
4898 * crash (i.e. core is generated) we can include the user's data section
4899 * in the core dump. Unfortunately, by default, only a partial core is
4900 * generated which, in many cases, isn't too useful.
4902 struct sigaction nsa;
4904 sigemptyset(&nsa.sa_mask);
4905 nsa.sa_handler = SIG_DFL;
4906 nsa.sa_flags = SA_FULLDUMP;
4907 sigaction(SIGSEGV, &nsa, NULL);
4910 confdir = AFSDIR_CLIENT_ETC_DIRPATH;
4912 cmd_SetBeforeProc(MyBeforeProc, NULL);
4914 ts = cmd_CreateSyntax("create", CreateVolume, 0, "create a new volume");
4915 cmd_AddParm(ts, "-server", CMD_SINGLE, 0, "machine name");
4916 cmd_AddParm(ts, "-partition", CMD_SINGLE, 0, "partition name");
4917 cmd_AddParm(ts, "-name", CMD_SINGLE, 0, "volume name");
4918 cmd_AddParm(ts, "-maxquota", CMD_SINGLE, CMD_OPTIONAL,
4919 "initial quota (KB)");
4921 cmd_AddParm(ts, "-minquota", CMD_SINGLE, CMD_OPTIONAL, "");
4925 ts = cmd_CreateSyntax("remove", DeleteVolume, 0, "delete a volume");
4926 cmd_AddParm(ts, "-server", CMD_SINGLE, CMD_OPTIONAL, "machine name");
4927 cmd_AddParm(ts, "-partition", CMD_SINGLE, CMD_OPTIONAL, "partition name");
4928 cmd_AddParm(ts, "-id", CMD_SINGLE, 0, "volume name or ID");
4932 ts = cmd_CreateSyntax("move", MoveVolume, 0, "move a volume");
4933 cmd_AddParm(ts, "-id", CMD_SINGLE, 0, "volume name or ID");
4934 cmd_AddParm(ts, "-fromserver", CMD_SINGLE, 0, "machine name on source");
4935 cmd_AddParm(ts, "-frompartition", CMD_SINGLE, 0,
4936 "partition name on source");
4937 cmd_AddParm(ts, "-toserver", CMD_SINGLE, 0,
4938 "machine name on destination");
4939 cmd_AddParm(ts, "-topartition", CMD_SINGLE, 0,
4940 "partition name on destination");
4943 ts = cmd_CreateSyntax("copy", CopyVolume, 0, "copy a volume");
4944 cmd_AddParm(ts, "-id", CMD_SINGLE, 0, "volume name or ID on source");
4945 cmd_AddParm(ts, "-fromserver", CMD_SINGLE, 0, "machine name on source");
4946 cmd_AddParm(ts, "-frompartition", CMD_SINGLE, 0,
4947 "partition name on source");
4948 cmd_AddParm(ts, "-toname", CMD_SINGLE, 0, "volume name on destination");
4949 cmd_AddParm(ts, "-toserver", CMD_SINGLE, 0,
4950 "machine name on destination");
4951 cmd_AddParm(ts, "-topartition", CMD_SINGLE, 0,
4952 "partition name on destination");
4955 ts = cmd_CreateSyntax("backup", BackupVolume, 0,
4956 "make backup of a volume");
4957 cmd_AddParm(ts, "-id", CMD_SINGLE, 0, "volume name or ID");
4960 ts = cmd_CreateSyntax("release", ReleaseVolume, 0, "release a volume");
4961 cmd_AddParm(ts, "-id", CMD_SINGLE, 0, "volume name or ID");
4962 cmd_AddParm(ts, "-force", CMD_FLAG, CMD_OPTIONAL,
4963 "force a complete release");
4966 ts = cmd_CreateSyntax("dump", DumpVolume, 0, "dump a volume");
4967 cmd_AddParm(ts, "-id", CMD_SINGLE, 0, "volume name or ID");
4968 cmd_AddParm(ts, "-time", CMD_SINGLE, CMD_OPTIONAL, "dump from time");
4969 cmd_AddParm(ts, "-file", CMD_SINGLE, CMD_OPTIONAL, "dump file");
4970 cmd_AddParm(ts, "-server", CMD_SINGLE, CMD_OPTIONAL, "server");
4971 cmd_AddParm(ts, "-partition", CMD_SINGLE, CMD_OPTIONAL, "partition");
4972 cmd_AddParm(ts, "-clone", CMD_FLAG, CMD_OPTIONAL,
4973 "dump a clone of the volume");
4976 ts = cmd_CreateSyntax("restore", RestoreVolume, 0, "restore a volume");
4977 cmd_AddParm(ts, "-server", CMD_SINGLE, 0, "machine name");
4978 cmd_AddParm(ts, "-partition", CMD_SINGLE, 0, "partition name");
4979 cmd_AddParm(ts, "-name", CMD_SINGLE, 0, "name of volume to be restored");
4980 cmd_AddParm(ts, "-file", CMD_SINGLE, CMD_OPTIONAL, "dump file");
4981 cmd_AddParm(ts, "-id", CMD_SINGLE, CMD_OPTIONAL, "volume ID");
4982 cmd_AddParm(ts, "-overwrite", CMD_SINGLE, CMD_OPTIONAL,
4983 "abort | full | incremental");
4984 cmd_AddParm(ts, "-offline", CMD_FLAG, CMD_OPTIONAL,
4985 "leave restored volume offline");
4986 cmd_AddParm(ts, "-readonly", CMD_FLAG, CMD_OPTIONAL,
4987 "make restored volume read-only");
4990 ts = cmd_CreateSyntax("unlock", LockReleaseCmd, 0,
4991 "release lock on VLDB entry for a volume");
4992 cmd_AddParm(ts, "-id", CMD_SINGLE, 0, "volume name or ID");
4995 ts = cmd_CreateSyntax("changeloc", ChangeLocation, 0,
4996 "change an RW volume's location in the VLDB");
4997 cmd_AddParm(ts, "-server", CMD_SINGLE, 0,
4998 "machine name for new location");
4999 cmd_AddParm(ts, "-partition", CMD_SINGLE, 0,
5000 "partition name for new location");
5001 cmd_AddParm(ts, "-id", CMD_SINGLE, 0, "volume name or ID");
5004 ts = cmd_CreateSyntax("addsite", AddSite, 0, "add a replication site");
5005 cmd_AddParm(ts, "-server", CMD_SINGLE, 0, "machine name for new site");
5006 cmd_AddParm(ts, "-partition", CMD_SINGLE, 0,
5007 "partition name for new site");
5008 cmd_AddParm(ts, "-id", CMD_SINGLE, 0, "volume name or ID");
5011 ts = cmd_CreateSyntax("remsite", RemoveSite, 0,
5012 "remove a replication site");
5013 cmd_AddParm(ts, "-server", CMD_SINGLE, 0, "machine name");
5014 cmd_AddParm(ts, "-partition", CMD_SINGLE, 0, "partition name");
5015 cmd_AddParm(ts, "-id", CMD_SINGLE, 0, "volume name or ID");
5018 ts = cmd_CreateSyntax("listpart", ListPartitions, 0, "list partitions");
5019 cmd_AddParm(ts, "-server", CMD_SINGLE, 0, "machine name");
5022 ts = cmd_CreateSyntax("listvol", ListVolumes, 0,
5023 "list volumes on server (bypass VLDB)");
5024 cmd_AddParm(ts, "-server", CMD_SINGLE, 0, "machine name");
5025 cmd_AddParm(ts, "-partition", CMD_SINGLE, CMD_OPTIONAL, "partition name");
5026 cmd_AddParm(ts, "-fast", CMD_FLAG, CMD_OPTIONAL, "minimal listing");
5027 cmd_AddParm(ts, "-long", CMD_FLAG, CMD_OPTIONAL,
5028 "list all normal volume fields");
5029 cmd_AddParm(ts, "-quiet", CMD_FLAG, CMD_OPTIONAL,
5030 "generate minimal information");
5031 cmd_AddParm(ts, "-extended", CMD_FLAG, CMD_OPTIONAL,
5032 "list extended volume fields");
5033 #ifdef FULL_LISTVOL_SWITCH
5034 cmd_AddParm(ts, "-format", CMD_FLAG, CMD_OPTIONAL,
5035 "machine readable format");
5036 #endif /* FULL_LISTVOL_SWITCH */
5039 ts = cmd_CreateSyntax("syncvldb", SyncVldb, 0,
5040 "synchronize VLDB with server");
5041 cmd_AddParm(ts, "-server", CMD_SINGLE, CMD_OPTIONAL, "machine name");
5042 cmd_AddParm(ts, "-partition", CMD_SINGLE, CMD_OPTIONAL, "partition name");
5043 cmd_AddParm(ts, "-volume", CMD_SINGLE, CMD_OPTIONAL, "volume name or ID");
5046 ts = cmd_CreateSyntax("syncserv", SyncServer, 0,
5047 "synchronize server with VLDB");
5048 cmd_AddParm(ts, "-server", CMD_SINGLE, 0, "machine name");
5049 cmd_AddParm(ts, "-partition", CMD_SINGLE, CMD_OPTIONAL, "partition name");
5052 ts = cmd_CreateSyntax("examine", ExamineVolume, 0,
5053 "everything about the volume");
5054 cmd_AddParm(ts, "-id", CMD_SINGLE, 0, "volume name or ID");
5055 cmd_AddParm(ts, "-extended", CMD_FLAG, CMD_OPTIONAL,
5056 "list extended volume fields");
5057 #ifdef FULL_LISTVOL_SWITCH
5058 cmd_AddParm(ts, "-format", CMD_FLAG, CMD_OPTIONAL,
5059 "machine readable format");
5060 #endif /* FULL_LISTVOL_SWITCH */
5062 cmd_CreateAlias(ts, "volinfo");
5064 ts = cmd_CreateSyntax("setfields", SetFields, 0,
5065 "change volume info fields");
5066 cmd_AddParm(ts, "-id", CMD_SINGLE, 0, "volume name or ID");
5067 cmd_AddParm(ts, "-maxquota", CMD_SINGLE, CMD_OPTIONAL, "quota (KB)");
5068 cmd_AddParm(ts, "-clearuse", CMD_FLAG, CMD_OPTIONAL, "clear dayUse");
5071 ts = cmd_CreateSyntax("offline", volOffline, 0, (char *)CMD_HIDDEN);
5072 cmd_AddParm(ts, "-server", CMD_SINGLE, 0, "server name");
5073 cmd_AddParm(ts, "-partition", CMD_SINGLE, 0, "partition name");
5074 cmd_AddParm(ts, "-id", CMD_SINGLE, 0, "volume name or ID");
5075 cmd_AddParm(ts, "-sleep", CMD_SINGLE, CMD_OPTIONAL, "seconds to sleep");
5076 cmd_AddParm(ts, "-busy", CMD_FLAG, CMD_OPTIONAL, "busy volume");
5079 ts = cmd_CreateSyntax("online", volOnline, 0, (char *)CMD_HIDDEN);
5080 cmd_AddParm(ts, "-server", CMD_SINGLE, 0, "server name");
5081 cmd_AddParm(ts, "-partition", CMD_SINGLE, 0, "partition name");
5082 cmd_AddParm(ts, "-id", CMD_SINGLE, 0, "volume name or ID");
5085 ts = cmd_CreateSyntax("zap", VolumeZap, 0,
5086 "delete the volume, don't bother with VLDB");
5087 cmd_AddParm(ts, "-server", CMD_SINGLE, 0, "machine name");
5088 cmd_AddParm(ts, "-partition", CMD_SINGLE, 0, "partition name");
5089 cmd_AddParm(ts, "-id", CMD_SINGLE, 0, "volume ID");
5090 cmd_AddParm(ts, "-force", CMD_FLAG, CMD_OPTIONAL,
5091 "force deletion of bad volumes");
5092 cmd_AddParm(ts, "-backup", CMD_FLAG, CMD_OPTIONAL,
5093 "also delete backup volume if one is found");
5096 ts = cmd_CreateSyntax("status", VolserStatus, 0,
5097 "report on volser status");
5098 cmd_AddParm(ts, "-server", CMD_SINGLE, 0, "machine name");
5101 ts = cmd_CreateSyntax("rename", RenameVolume, 0, "rename a volume");
5102 cmd_AddParm(ts, "-oldname", CMD_SINGLE, 0, "old volume name ");
5103 cmd_AddParm(ts, "-newname", CMD_SINGLE, 0, "new volume name ");
5106 ts = cmd_CreateSyntax("listvldb", ListVLDB, 0,
5107 "list volumes in the VLDB");
5108 cmd_AddParm(ts, "-name", CMD_SINGLE, CMD_OPTIONAL, "volume name or ID");
5109 cmd_AddParm(ts, "-server", CMD_SINGLE, CMD_OPTIONAL, "machine name");
5110 cmd_AddParm(ts, "-partition", CMD_SINGLE, CMD_OPTIONAL, "partition name");
5111 cmd_AddParm(ts, "-locked", CMD_FLAG, CMD_OPTIONAL, "locked volumes only");
5112 cmd_AddParm(ts, "-quiet", CMD_FLAG, CMD_OPTIONAL,
5113 "generate minimal information");
5114 cmd_AddParm(ts, "-nosort", CMD_FLAG, CMD_OPTIONAL,
5115 "do not alphabetically sort the volume names");
5118 ts = cmd_CreateSyntax("backupsys", BackSys, 0, "en masse backups");
5119 cmd_AddParm(ts, "-prefix", CMD_LIST, CMD_OPTIONAL,
5120 "common prefix on volume(s)");
5121 cmd_AddParm(ts, "-server", CMD_SINGLE, CMD_OPTIONAL, "machine name");
5122 cmd_AddParm(ts, "-partition", CMD_SINGLE, CMD_OPTIONAL, "partition name");
5123 cmd_AddParm(ts, "-exclude", CMD_FLAG, CMD_OPTIONAL,
5124 "exclude common prefix volumes");
5125 cmd_AddParm(ts, "-xprefix", CMD_LIST, CMD_OPTIONAL,
5126 "negative prefix on volume(s)");
5127 cmd_AddParm(ts, "-dryrun", CMD_FLAG, CMD_OPTIONAL, "no action");
5130 ts = cmd_CreateSyntax("delentry", DeleteEntry, 0,
5131 "delete VLDB entry for a volume");
5132 cmd_AddParm(ts, "-id", CMD_LIST, CMD_OPTIONAL, "volume name or ID");
5133 cmd_AddParm(ts, "-prefix", CMD_SINGLE, CMD_OPTIONAL,
5134 "prefix of the volume whose VLDB entry is to be deleted");
5135 cmd_AddParm(ts, "-server", CMD_SINGLE, CMD_OPTIONAL, "machine name");
5136 cmd_AddParm(ts, "-partition", CMD_SINGLE, CMD_OPTIONAL, "partition name");
5137 cmd_AddParm(ts, "-noexecute", CMD_FLAG, CMD_OPTIONAL | CMD_HIDE,
5141 ts = cmd_CreateSyntax("partinfo", PartitionInfo, 0,
5142 "list partition information");
5143 cmd_AddParm(ts, "-server", CMD_SINGLE, 0, "machine name");
5144 cmd_AddParm(ts, "-partition", CMD_SINGLE, CMD_OPTIONAL, "partition name");
5147 ts = cmd_CreateSyntax("unlockvldb", UnlockVLDB, 0,
5148 "unlock all the locked entries in the VLDB");
5149 cmd_AddParm(ts, "-server", CMD_SINGLE, CMD_OPTIONAL, "machine name");
5150 cmd_AddParm(ts, "-partition", CMD_SINGLE, CMD_OPTIONAL, "partition name");
5153 ts = cmd_CreateSyntax("lock", LockEntry, 0,
5154 "lock VLDB entry for a volume");
5155 cmd_AddParm(ts, "-id", CMD_SINGLE, 0, "volume name or ID");
5158 ts = cmd_CreateSyntax("changeaddr", ChangeAddr, 0,
5159 "change the IP address of a file server");
5160 cmd_AddParm(ts, "-oldaddr", CMD_SINGLE, 0, "original IP address");
5161 cmd_AddParm(ts, "-newaddr", CMD_SINGLE, CMD_OPTIONAL, "new IP address");
5162 cmd_AddParm(ts, "-remove", CMD_FLAG, CMD_OPTIONAL,
5163 "remove the IP address from the VLDB");
5166 ts = cmd_CreateSyntax("listaddrs", ListAddrs, 0,
5167 "list the IP address of all file servers registered in the VLDB");
5168 cmd_AddParm(ts, "-uuid", CMD_SINGLE, CMD_OPTIONAL, "uuid of server");
5169 cmd_AddParm(ts, "-host", CMD_SINGLE, CMD_OPTIONAL, "address of host");
5170 cmd_AddParm(ts, "-noresolve", CMD_FLAG, CMD_OPTIONAL,
5171 "don't resolve addresses");
5172 cmd_AddParm(ts, "-printuuid", CMD_FLAG, CMD_OPTIONAL,
5173 "print uuid of hosts");
5176 ts = cmd_CreateSyntax("convertROtoRW", ConvertRO, 0,
5177 "convert a RO volume into a RW volume (after loss of old RW volume)");
5178 cmd_AddParm(ts, "-server", CMD_SINGLE, 0, "machine name");
5179 cmd_AddParm(ts, "-partition", CMD_SINGLE, 0, "partition name");
5180 cmd_AddParm(ts, "-id", CMD_SINGLE, 0, "volume name or ID");
5181 cmd_AddParm(ts, "-force", CMD_FLAG, CMD_OPTIONAL, "don't ask");
5184 ts = cmd_CreateSyntax("size", Sizes, 0,
5185 "obtain various sizes of the volume.");
5186 cmd_AddParm(ts, "-id", CMD_SINGLE, 0, "volume name or ID");
5187 cmd_AddParm(ts, "-partition", CMD_SINGLE, CMD_OPTIONAL, "partition name");
5188 cmd_AddParm(ts, "-server", CMD_SINGLE, CMD_OPTIONAL, "machine name");
5189 cmd_AddParm(ts, "-dump", CMD_FLAG, CMD_OPTIONAL,
5190 "Obtain the size of the dump");
5191 cmd_AddParm(ts, "-time", CMD_SINGLE, CMD_OPTIONAL, "dump from time");
5194 code = cmd_Dispatch(argc, argv);
5196 /* Shut down the ubik_client and rx connections */
5198 (void)ubik_ClientDestroy(cstruct);
5204 exit((code ? -1 : 0));