2 * Copyright 2000, International Business Machines Corporation and others.
5 * This software has been released under the terms of the IBM Public
6 * License. For details, see the LICENSE file in the top-level source
7 * directory or online at http://www.openafs.org/dl/license10.html
10 #include <afsconfig.h>
11 #include <afs/param.h>
15 #ifdef IGNORE_SOME_GCC_WARNINGS
16 # pragma GCC diagnostic warning "-Wimplicit-function-declaration"
19 #include <sys/types.h>
28 #include <WINNT/afsreg.h>
33 #include <netinet/in.h>
34 #include <arpa/inet.h>
38 #include <sys/statfs.h>
46 #include <rx/rx_globals.h>
48 #include <afs/vlserver.h>
49 #include <afs/cellconfig.h>
51 #include <afs/afsutil.h>
53 #include <afs/afsint.h>
58 #include <afs/ihandle.h>
59 #include <afs/vnode.h>
60 #include <afs/volume.h>
61 #include <afs/com_err.h>
68 #include "volser_internal.h"
69 #include "volser_prototypes.h"
70 #include "vsutils_prototypes.h"
71 #include "lockprocs_prototypes.h"
73 #ifdef HAVE_POSIX_REGEX
77 /* Local Prototypes */
78 int PrintDiagnostics(char *astring, afs_int32 acode);
79 int GetVolumeInfo(afs_uint32 volid, afs_uint32 *server, afs_int32 *part,
80 afs_int32 *voltype, struct uvldbentry *rentry);
92 #define COMMONPARMS cmd_Seek(ts, 12);\
93 cmd_AddParm(ts, "-cell", CMD_SINGLE, CMD_OPTIONAL, "cell name");\
94 cmd_AddParm(ts, "-noauth", CMD_FLAG, CMD_OPTIONAL, "don't authenticate");\
95 cmd_AddParm(ts, "-localauth",CMD_FLAG,CMD_OPTIONAL,"use server tickets");\
96 cmd_AddParm(ts, "-verbose", CMD_FLAG, CMD_OPTIONAL, "verbose");\
97 cmd_AddParm(ts, "-encrypt", CMD_FLAG, CMD_OPTIONAL, "encrypt commands");\
98 cmd_AddParm(ts, "-noresolve", CMD_FLAG, CMD_OPTIONAL, "don't resolve addresses"); \
100 #define ERROR_EXIT(code) do { \
106 struct rx_connection *tconn;
108 extern struct ubik_client *cstruct;
111 static struct tqHead busyHead, notokHead;
114 qInit(struct tqHead *ahead)
116 memset(ahead, 0, sizeof(struct tqHead));
122 qPut(struct tqHead *ahead, afs_uint32 volid)
126 elem = (struct tqElem *)malloc(sizeof(struct tqElem));
127 elem->next = ahead->next;
135 qGet(struct tqHead *ahead, afs_uint32 *volid)
139 if (ahead->count <= 0)
141 *volid = ahead->next->volid;
143 ahead->next = tmp->next;
149 /* returns 1 if <filename> exists else 0 */
151 FileExists(char *filename)
157 code = usd_Open(filename, USD_OPEN_RDONLY, 0, &ufd);
161 code = USD_IOCTL(ufd, USD_IOCTL_GETSIZE, &size);
169 /* returns 1 if <name> doesnot end in .readonly or .backup, else 0 */
171 VolNameOK(char *name)
175 total = strlen(name);
176 if (!strcmp(&name[total - 9], ".readonly")) {
178 } else if (!strcmp(&name[total - 7], ".backup")) {
185 /* return 1 if name is a number else 0 */
187 IsNumeric(char *name)
196 for (i = 0; i < len; i++) {
197 if (*ptr < '0' || *ptr > '9') {
209 * Parse a server dotted address and return the address in network byte order
212 GetServerNoresolve(char *aname)
218 code = sscanf(aname, "%d.%d.%d.%d", &b1, &b2, &b3, &b4);
220 addr = (b1 << 24) | (b2 << 16) | (b3 << 8) | b4;
221 addr = htonl(addr); /* convert to network byte order */
227 * Parse a server name/address and return the address in network byte order
230 GetServer(char *aname)
233 afs_uint32 addr; /* in network byte order */
235 char hostname[MAXHOSTCHARS];
237 if ((addr = GetServerNoresolve(aname)) == 0) {
238 th = gethostbyname(aname);
241 memcpy(&addr, th->h_addr, sizeof(addr));
244 if (rx_IsLoopbackAddr(ntohl(addr))) { /* local host */
245 code = gethostname(hostname, MAXHOSTCHARS);
248 th = gethostbyname(hostname);
251 memcpy(&addr, th->h_addr, sizeof(addr));
258 GetVolumeType(char *aname)
261 if (!strcmp(aname, "ro"))
263 else if (!strcmp(aname, "rw"))
265 else if (!strcmp(aname, "bk"))
272 IsPartValid(afs_int32 partId, afs_uint32 server, afs_int32 *code)
274 struct partList dummyPartList;
280 *code = UV_ListPartitions(server, &dummyPartList, &cnt);
283 for (i = 0; i < cnt; i++) {
284 if (dummyPartList.partFlags[i] & PARTVALID)
285 if (dummyPartList.partId[i] == partId)
293 /*sends the contents of file associated with <fd> and <blksize> to Rx Stream
294 * associated with <call> */
296 SendFile(usd_handle_t ufd, struct rx_call *call, long blksize)
298 char *buffer = (char *)0;
303 buffer = (char *)malloc(blksize);
305 fprintf(STDERR, "malloc failed\n");
309 while (!error && !done) {
310 #ifndef AFS_NT40_ENV /* NT csn't select on non-socket fd's */
313 FD_SET((intptr_t)(ufd->handle), &in);
314 /* don't timeout if read blocks */
315 #if defined(AFS_PTHREAD_ENV)
316 select(((intptr_t)(ufd->handle)) + 1, &in, 0, 0, 0);
318 IOMGR_Select(((intptr_t)(ufd->handle)) + 1, &in, 0, 0, 0);
321 error = USD_READ(ufd, buffer, blksize, &nbytes);
323 fprintf(STDERR, "File system read failed: %s\n",
324 afs_error_message(error));
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(struct rx_call *call, void *rock)
346 char *filename = (char *) rock;
349 afs_int32 error, code;
351 afs_hyper_t filesize, currOffset;
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': %s\n", filename,
369 afs_error_message(code));
373 /* test if we have a valid dump */
374 hset64(filesize, 0, 0);
375 USD_SEEK(ufd, filesize, SEEK_END, &currOffset);
376 hset64(filesize, hgethi(currOffset), hgetlo(currOffset)-sizeof(afs_uint32));
377 USD_SEEK(ufd, filesize, SEEK_SET, &currOffset);
378 USD_READ(ufd, (char *)&buffer, sizeof(afs_uint32), &got);
379 if ((got != sizeof(afs_uint32)) || (ntohl(buffer) != DUMPENDMAGIC)) {
380 fprintf(STDERR, "Signature missing from end of file '%s'\n", filename);
384 /* rewind, we are done */
385 hset64(filesize, 0, 0);
386 USD_SEEK(ufd, filesize, SEEK_SET, &currOffset);
388 code = SendFile(ufd, call, blksize);
395 code = USD_CLOSE(ufd);
397 fprintf(STDERR, "Could not close dump file %s\n",
398 (filename && *filename) ? filename : "STDOUT");
406 /* Receive data from <call> stream into file associated
407 * with <fd> <blksize>
410 ReceiveFile(usd_handle_t ufd, struct rx_call *call, long blksize)
414 afs_uint32 bytesleft, w;
417 buffer = (char *)malloc(blksize);
419 fprintf(STDERR, "memory allocation failed\n");
423 while ((bytesread = rx_Read(call, buffer, blksize)) > 0) {
424 for (bytesleft = bytesread; bytesleft; bytesleft -= w) {
425 #ifndef AFS_NT40_ENV /* NT csn't select on non-socket fd's */
428 FD_SET((intptr_t)(ufd->handle), &out);
429 /* don't timeout if write blocks */
430 #if defined(AFS_PTHREAD_ENV)
431 select(((intptr_t)(ufd->handle)) + 1, &out, 0, 0, 0);
433 IOMGR_Select(((intptr_t)(ufd->handle)) + 1, 0, &out, 0, 0);
437 USD_WRITE(ufd, &buffer[bytesread - bytesleft], bytesleft, &w);
439 fprintf(STDERR, "File system write failed: %s\n",
440 afs_error_message(error));
453 DumpFunction(struct rx_call *call, void *rock)
455 char *filename = (char *)rock;
456 usd_handle_t ufd; /* default is to stdout */
457 afs_int32 error = 0, code;
462 /* Open the output file */
463 if (!filename || !*filename) {
464 usd_StandardOutput(&ufd);
469 usd_Open(filename, USD_OPEN_CREATE | USD_OPEN_RDWR, 0666, &ufd);
473 code = USD_IOCTL(ufd, USD_IOCTL_SETSIZE, &size);
476 code = USD_IOCTL(ufd, USD_IOCTL_GETBLKSIZE, &blksize);
479 fprintf(STDERR, "Could not create file '%s': %s\n", filename,
480 afs_error_message(code));
481 ERROR_EXIT(VOLSERBADOP);
485 code = ReceiveFile(ufd, call, blksize);
490 /* Close the output file */
492 code = USD_CLOSE(ufd);
494 fprintf(STDERR, "Could not close dump file %s\n",
495 (filename && *filename) ? filename : "STDIN");
505 DisplayFormat(volintInfo *pntr, afs_uint32 server, afs_int32 part,
506 int *totalOK, int *totalNotOK, int *totalBusy, int fast,
507 int longlist, int disp)
513 fprintf(STDOUT, "%-10lu\n", (unsigned long)pntr->volid);
514 } else if (longlist) {
515 if (pntr->status == VOK) {
516 fprintf(STDOUT, "%-32s ", pntr->name);
517 fprintf(STDOUT, "%10lu ", (unsigned long)pntr->volid);
519 fprintf(STDOUT, "RW ");
521 fprintf(STDOUT, "RO ");
523 fprintf(STDOUT, "BK ");
524 fprintf(STDOUT, "%10d K ", pntr->size);
525 if (pntr->inUse == 1) {
526 fprintf(STDOUT, "On-line");
529 fprintf(STDOUT, "Off-line");
532 if (pntr->needsSalvaged == 1)
533 fprintf(STDOUT, "**needs salvage**");
534 fprintf(STDOUT, "\n");
535 MapPartIdIntoName(part, pname);
536 fprintf(STDOUT, " %s %s \n", hostutil_GetNameByINet(server),
538 fprintf(STDOUT, " RWrite %10lu ROnly %10lu Backup %10lu \n",
539 (unsigned long)pntr->parentID,
540 (unsigned long)pntr->cloneID,
541 (unsigned long)pntr->backupID);
542 fprintf(STDOUT, " MaxQuota %10d K \n", pntr->maxquota);
543 t = pntr->creationDate;
544 fprintf(STDOUT, " Creation %s",
547 fprintf(STDOUT, " Copy %s",
550 t = pntr->backupDate;
552 fprintf(STDOUT, " Backup Never\n");
554 fprintf(STDOUT, " Backup %s",
557 t = pntr->accessDate;
559 fprintf(STDOUT, " Last Access %s",
562 t = pntr->updateDate;
564 fprintf(STDOUT, " Last Update Never\n");
566 fprintf(STDOUT, " Last Update %s",
569 " %d accesses in the past day (i.e., vnode references)\n",
571 } else if (pntr->status == VBUSY) {
573 qPut(&busyHead, pntr->volid);
575 fprintf(STDOUT, "**** Volume %lu is busy ****\n",
576 (unsigned long)pntr->volid);
579 qPut(¬okHead, pntr->volid);
581 fprintf(STDOUT, "**** Could not attach volume %lu ****\n",
582 (unsigned long)pntr->volid);
584 fprintf(STDOUT, "\n");
585 } else { /* default listing */
586 if (pntr->status == VOK) {
587 fprintf(STDOUT, "%-32s ", pntr->name);
588 fprintf(STDOUT, "%10lu ", (unsigned long)pntr->volid);
590 fprintf(STDOUT, "RW ");
592 fprintf(STDOUT, "RO ");
594 fprintf(STDOUT, "BK ");
595 fprintf(STDOUT, "%10d K ", pntr->size);
596 if (pntr->inUse == 1) {
597 fprintf(STDOUT, "On-line");
600 fprintf(STDOUT, "Off-line");
603 if (pntr->needsSalvaged == 1)
604 fprintf(STDOUT, "**needs salvage**");
605 fprintf(STDOUT, "\n");
606 } else if (pntr->status == VBUSY) {
608 qPut(&busyHead, pntr->volid);
610 fprintf(STDOUT, "**** Volume %lu is busy ****\n",
611 (unsigned long)pntr->volid);
614 qPut(¬okHead, pntr->volid);
616 fprintf(STDOUT, "**** Could not attach volume %lu ****\n",
617 (unsigned long)pntr->volid);
622 /*------------------------------------------------------------------------
623 * PRIVATE XDisplayFormat
626 * Display the contents of one extended volume info structure.
629 * a_xInfoP : Ptr to extended volume info struct to print.
630 * a_servID : Server ID to print.
631 * a_partID : Partition ID to print.
632 * a_totalOKP : Ptr to total-OK counter.
633 * a_totalNotOKP : Ptr to total-screwed counter.
634 * a_totalBusyP : Ptr to total-busy counter.
635 * a_fast : Fast listing?
636 * a_int32 : Int32 listing?
637 * a_showProblems : Show volume problems?
643 * Nothing interesting.
647 *------------------------------------------------------------------------*/
650 XDisplayFormat(volintXInfo *a_xInfoP, afs_uint32 a_servID, afs_int32 a_partID,
651 int *a_totalOKP, int *a_totalNotOKP, int *a_totalBusyP,
652 int a_fast, int a_int32, int a_showProblems)
653 { /*XDisplayFormat */
661 fprintf(STDOUT, "%-10lu\n", (unsigned long)a_xInfoP->volid);
662 } else if (a_int32) {
664 * Fully-detailed listing.
666 if (a_xInfoP->status == VOK) {
668 * Volume's status is OK - all the fields are valid.
670 fprintf(STDOUT, "%-32s ", a_xInfoP->name);
671 fprintf(STDOUT, "%10lu ", (unsigned long)a_xInfoP->volid);
672 if (a_xInfoP->type == 0)
673 fprintf(STDOUT, "RW ");
674 if (a_xInfoP->type == 1)
675 fprintf(STDOUT, "RO ");
676 if (a_xInfoP->type == 2)
677 fprintf(STDOUT, "BK ");
678 fprintf(STDOUT, "%10d K used ", a_xInfoP->size);
679 fprintf(STDOUT, "%d files ", a_xInfoP->filecount);
680 if (a_xInfoP->inUse == 1) {
681 fprintf(STDOUT, "On-line");
684 fprintf(STDOUT, "Off-line");
687 fprintf(STDOUT, "\n");
688 MapPartIdIntoName(a_partID, pname);
689 fprintf(STDOUT, " %s %s \n", hostutil_GetNameByINet(a_servID),
691 fprintf(STDOUT, " RWrite %10lu ROnly %10lu Backup %10lu \n",
692 (unsigned long)a_xInfoP->parentID,
693 (unsigned long)a_xInfoP->cloneID,
694 (unsigned long)a_xInfoP->backupID);
695 fprintf(STDOUT, " MaxQuota %10d K \n", a_xInfoP->maxquota);
697 t = a_xInfoP->creationDate;
698 fprintf(STDOUT, " Creation %s",
701 t = a_xInfoP->copyDate;
702 fprintf(STDOUT, " Copy %s",
705 t = a_xInfoP->backupDate;
707 fprintf(STDOUT, " Backup Never\n");
709 fprintf(STDOUT, " Backup %s",
712 t = a_xInfoP->accessDate;
714 fprintf(STDOUT, " Last Access %s",
717 t = a_xInfoP->updateDate;
719 fprintf(STDOUT, " Last Update Never\n");
721 fprintf(STDOUT, " Last Update %s",
724 " %d accesses in the past day (i.e., vnode references)\n",
728 * Print all the read/write and authorship stats.
730 fprintf(STDOUT, "\n Raw Read/Write Stats\n");
732 " |-------------------------------------------|\n");
734 " | Same Network | Diff Network |\n");
736 " |----------|----------|----------|----------|\n");
738 " | Total | Auth | Total | Auth |\n");
740 " |----------|----------|----------|----------|\n");
741 fprintf(STDOUT, "Reads | %8d | %8d | %8d | %8d |\n",
742 a_xInfoP->stat_reads[VOLINT_STATS_SAME_NET],
743 a_xInfoP->stat_reads[VOLINT_STATS_SAME_NET_AUTH],
744 a_xInfoP->stat_reads[VOLINT_STATS_DIFF_NET],
745 a_xInfoP->stat_reads[VOLINT_STATS_DIFF_NET_AUTH]);
746 fprintf(STDOUT, "Writes | %8d | %8d | %8d | %8d |\n",
747 a_xInfoP->stat_writes[VOLINT_STATS_SAME_NET],
748 a_xInfoP->stat_writes[VOLINT_STATS_SAME_NET_AUTH],
749 a_xInfoP->stat_writes[VOLINT_STATS_DIFF_NET],
750 a_xInfoP->stat_writes[VOLINT_STATS_DIFF_NET_AUTH]);
752 " |-------------------------------------------|\n\n");
755 " Writes Affecting Authorship\n");
757 " |-------------------------------------------|\n");
759 " | File Authorship | Directory Authorship|\n");
761 " |----------|----------|----------|----------|\n");
763 " | Same | Diff | Same | Diff |\n");
765 " |----------|----------|----------|----------|\n");
766 fprintf(STDOUT, "0-60 sec | %8d | %8d | %8d | %8d |\n",
767 a_xInfoP->stat_fileSameAuthor[VOLINT_STATS_TIME_IDX_0],
768 a_xInfoP->stat_fileDiffAuthor[VOLINT_STATS_TIME_IDX_0],
769 a_xInfoP->stat_dirSameAuthor[VOLINT_STATS_TIME_IDX_0],
770 a_xInfoP->stat_dirDiffAuthor[VOLINT_STATS_TIME_IDX_0]);
771 fprintf(STDOUT, "1-10 min | %8d | %8d | %8d | %8d |\n",
772 a_xInfoP->stat_fileSameAuthor[VOLINT_STATS_TIME_IDX_1],
773 a_xInfoP->stat_fileDiffAuthor[VOLINT_STATS_TIME_IDX_1],
774 a_xInfoP->stat_dirSameAuthor[VOLINT_STATS_TIME_IDX_1],
775 a_xInfoP->stat_dirDiffAuthor[VOLINT_STATS_TIME_IDX_1]);
776 fprintf(STDOUT, "10min-1hr | %8d | %8d | %8d | %8d |\n",
777 a_xInfoP->stat_fileSameAuthor[VOLINT_STATS_TIME_IDX_2],
778 a_xInfoP->stat_fileDiffAuthor[VOLINT_STATS_TIME_IDX_2],
779 a_xInfoP->stat_dirSameAuthor[VOLINT_STATS_TIME_IDX_2],
780 a_xInfoP->stat_dirDiffAuthor[VOLINT_STATS_TIME_IDX_2]);
781 fprintf(STDOUT, "1hr-1day | %8d | %8d | %8d | %8d |\n",
782 a_xInfoP->stat_fileSameAuthor[VOLINT_STATS_TIME_IDX_3],
783 a_xInfoP->stat_fileDiffAuthor[VOLINT_STATS_TIME_IDX_3],
784 a_xInfoP->stat_dirSameAuthor[VOLINT_STATS_TIME_IDX_3],
785 a_xInfoP->stat_dirDiffAuthor[VOLINT_STATS_TIME_IDX_3]);
786 fprintf(STDOUT, "1day-1wk | %8d | %8d | %8d | %8d |\n",
787 a_xInfoP->stat_fileSameAuthor[VOLINT_STATS_TIME_IDX_4],
788 a_xInfoP->stat_fileDiffAuthor[VOLINT_STATS_TIME_IDX_4],
789 a_xInfoP->stat_dirSameAuthor[VOLINT_STATS_TIME_IDX_4],
790 a_xInfoP->stat_dirDiffAuthor[VOLINT_STATS_TIME_IDX_4]);
791 fprintf(STDOUT, "> 1wk | %8d | %8d | %8d | %8d |\n",
792 a_xInfoP->stat_fileSameAuthor[VOLINT_STATS_TIME_IDX_5],
793 a_xInfoP->stat_fileDiffAuthor[VOLINT_STATS_TIME_IDX_5],
794 a_xInfoP->stat_dirSameAuthor[VOLINT_STATS_TIME_IDX_5],
795 a_xInfoP->stat_dirDiffAuthor[VOLINT_STATS_TIME_IDX_5]);
797 " |-------------------------------------------|\n");
798 } /*Volume status OK */
799 else if (a_xInfoP->status == VBUSY) {
801 qPut(&busyHead, a_xInfoP->volid);
803 fprintf(STDOUT, "**** Volume %lu is busy ****\n",
804 (unsigned long)a_xInfoP->volid);
808 qPut(¬okHead, a_xInfoP->volid);
810 fprintf(STDOUT, "**** Could not attach volume %lu ****\n",
811 (unsigned long)a_xInfoP->volid);
812 } /*Screwed volume */
813 fprintf(STDOUT, "\n");
819 if (a_xInfoP->status == VOK) {
820 fprintf(STDOUT, "%-32s ", a_xInfoP->name);
821 fprintf(STDOUT, "%10lu ", (unsigned long)a_xInfoP->volid);
822 if (a_xInfoP->type == 0)
823 fprintf(STDOUT, "RW ");
824 if (a_xInfoP->type == 1)
825 fprintf(STDOUT, "RO ");
826 if (a_xInfoP->type == 2)
827 fprintf(STDOUT, "BK ");
828 fprintf(STDOUT, "%10d K ", a_xInfoP->size);
829 if (a_xInfoP->inUse == 1) {
830 fprintf(STDOUT, "On-line");
833 fprintf(STDOUT, "Off-line");
836 fprintf(STDOUT, "\n");
838 else if (a_xInfoP->status == VBUSY) {
840 qPut(&busyHead, a_xInfoP->volid);
842 fprintf(STDOUT, "**** Volume %lu is busy ****\n",
843 (unsigned long)a_xInfoP->volid);
847 qPut(¬okHead, a_xInfoP->volid);
849 fprintf(STDOUT, "**** Could not attach volume %lu ****\n",
850 (unsigned long)a_xInfoP->volid);
851 } /*Screwed volume */
852 } /*Default listing */
853 } /*XDisplayFormat */
855 /*------------------------------------------------------------------------
856 * PRIVATE XDisplayFormat2
859 * Display the formated contents of one extended volume info structure.
862 * a_xInfoP : Ptr to extended volume info struct to print.
863 * a_servID : Server ID to print.
864 * a_partID : Partition ID to print.
865 * a_totalOKP : Ptr to total-OK counter.
866 * a_totalNotOKP : Ptr to total-screwed counter.
867 * a_totalBusyP : Ptr to total-busy counter.
868 * a_fast : Fast listing?
869 * a_int32 : Int32 listing?
870 * a_showProblems : Show volume problems?
876 * Nothing interesting.
880 *------------------------------------------------------------------------*/
883 XDisplayFormat2(volintXInfo *a_xInfoP, afs_uint32 a_servID, afs_int32 a_partID,
884 int *a_totalOKP, int *a_totalNotOKP, int *a_totalBusyP,
885 int a_fast, int a_int32, int a_showProblems)
886 { /*XDisplayFormat */
892 fprintf(STDOUT, "vold_id\t%-10lu\n", (unsigned long)a_xInfoP->volid);
893 } else if (a_int32) {
895 * Fully-detailed listing.
897 if (a_xInfoP->status == VOK) {
899 * Volume's status is OK - all the fields are valid.
902 static long server_cache = -1, partition_cache = -1;
903 static char hostname[256], address[32], pname[16];
904 int i,ai[] = {VOLINT_STATS_TIME_IDX_0,VOLINT_STATS_TIME_IDX_1,VOLINT_STATS_TIME_IDX_2,
905 VOLINT_STATS_TIME_IDX_3,VOLINT_STATS_TIME_IDX_4,VOLINT_STATS_TIME_IDX_5};
907 if (a_servID != server_cache) {
911 strcpy(hostname, hostutil_GetNameByINet(a_servID));
912 strcpy(address, inet_ntoa(s));
913 server_cache = a_servID;
915 if (a_partID != partition_cache) {
916 MapPartIdIntoName(a_partID, pname);
917 partition_cache = a_partID;
920 fprintf(STDOUT, "name\t\t%s\n", a_xInfoP->name);
921 fprintf(STDOUT, "id\t\t%lu\n", afs_printable_uint32_lu(a_xInfoP->volid));
922 fprintf(STDOUT, "serv\t\t%s\t%s\n", address, hostname);
923 fprintf(STDOUT, "part\t\t%s\n", pname);
924 fprintf(STDOUT, "status\t\tOK\n");
925 fprintf(STDOUT, "backupID\t%lu\n",
926 afs_printable_uint32_lu(a_xInfoP->backupID));
927 fprintf(STDOUT, "parentID\t%lu\n",
928 afs_printable_uint32_lu(a_xInfoP->parentID));
929 fprintf(STDOUT, "cloneID\t\t%lu\n",
930 afs_printable_uint32_lu(a_xInfoP->cloneID));
931 fprintf(STDOUT, "inUse\t\t%s\n", a_xInfoP->inUse ? "Y" : "N");
932 switch (a_xInfoP->type) {
934 fprintf(STDOUT, "type\t\tRW\n");
937 fprintf(STDOUT, "type\t\tRO\n");
940 fprintf(STDOUT, "type\t\tBK\n");
943 fprintf(STDOUT, "type\t\t?\n");
946 t = a_xInfoP->creationDate;
947 fprintf(STDOUT, "creationDate\t%-9lu\t%s",
948 afs_printable_uint32_lu(a_xInfoP->creationDate),
951 t = a_xInfoP->accessDate;
952 fprintf(STDOUT, "accessDate\t%-9lu\t%s",
953 afs_printable_uint32_lu(a_xInfoP->accessDate),
956 t = a_xInfoP->updateDate;
957 fprintf(STDOUT, "updateDate\t%-9lu\t%s",
958 afs_printable_uint32_lu(a_xInfoP->updateDate),
961 t = a_xInfoP->backupDate;
962 fprintf(STDOUT, "backupDate\t%-9lu\t%s",
963 afs_printable_uint32_lu(a_xInfoP->backupDate),
966 t = a_xInfoP->copyDate;
967 fprintf(STDOUT, "copyDate\t%-9lu\t%s",
968 afs_printable_uint32_lu(a_xInfoP->copyDate),
971 fprintf(STDOUT, "diskused\t%u\n", a_xInfoP->size);
972 fprintf(STDOUT, "maxquota\t%u\n", a_xInfoP->maxquota);
974 fprintf(STDOUT, "filecount\t%u\n", a_xInfoP->filecount);
975 fprintf(STDOUT, "dayUse\t\t%u\n", a_xInfoP->dayUse);
979 fprintf(STDOUT,"reads_same_net\t%8d\n",a_xInfoP->stat_reads[VOLINT_STATS_SAME_NET]);
980 fprintf(STDOUT,"reads_same_net_auth\t%8d\n",a_xInfoP->stat_reads[VOLINT_STATS_SAME_NET_AUTH]);
981 fprintf(STDOUT,"reads_diff_net\t%8d\n",a_xInfoP->stat_reads[VOLINT_STATS_DIFF_NET]);
982 fprintf(STDOUT,"reads_diff_net_auth\t%8d\n",a_xInfoP->stat_reads[VOLINT_STATS_DIFF_NET_AUTH]);
984 fprintf(STDOUT,"writes_same_net\t%8d\n",a_xInfoP->stat_writes[VOLINT_STATS_SAME_NET]);
985 fprintf(STDOUT,"writes_same_net_auth\t%8d\n",a_xInfoP->stat_writes[VOLINT_STATS_SAME_NET_AUTH]);
986 fprintf(STDOUT,"writes_diff_net\t%8d\n",a_xInfoP->stat_writes[VOLINT_STATS_DIFF_NET]);
987 fprintf(STDOUT,"writes_diff_net_auth\t%8d\n",a_xInfoP->stat_writes[VOLINT_STATS_DIFF_NET_AUTH]);
991 fprintf(STDOUT,"file_same_author_idx_%d\t%8d\n",i+1,a_xInfoP->stat_fileSameAuthor[ai[i]]);
992 fprintf(STDOUT,"file_diff_author_idx_%d\t%8d\n",i+1,a_xInfoP->stat_fileDiffAuthor[ai[i]]);
993 fprintf(STDOUT,"dir_same_author_idx_%d\t%8d\n",i+1,a_xInfoP->stat_dirSameAuthor[ai[i]]);
994 fprintf(STDOUT,"dir_dif_author_idx_%d\t%8d\n",i+1,a_xInfoP->stat_dirDiffAuthor[ai[i]]);
997 } /*Volume status OK */
998 else if (a_xInfoP->status == VBUSY) {
1000 qPut(&busyHead, a_xInfoP->volid);
1002 fprintf(STDOUT, "BUSY_VOL\t%lu\n",
1003 (unsigned long)a_xInfoP->volid);
1007 qPut(¬okHead, a_xInfoP->volid);
1009 fprintf(STDOUT, "COULD_NOT_ATTACH\t%lu\n",
1010 (unsigned long)a_xInfoP->volid);
1011 } /*Screwed volume */
1017 if (a_xInfoP->status == VOK) {
1018 fprintf(STDOUT, "name\t%-32s\n", a_xInfoP->name);
1019 fprintf(STDOUT, "volID\t%10lu\n", (unsigned long)a_xInfoP->volid);
1020 if (a_xInfoP->type == 0)
1021 fprintf(STDOUT, "type\tRW\n");
1022 if (a_xInfoP->type == 1)
1023 fprintf(STDOUT, "type\tRO\n");
1024 if (a_xInfoP->type == 2)
1025 fprintf(STDOUT, "type\tBK\n");
1026 fprintf(STDOUT, "size\t%10dK\n", a_xInfoP->size);
1028 fprintf(STDOUT, "inUse\t%d\n",a_xInfoP->inUse);
1029 if (a_xInfoP->inUse == 1)
1035 else if (a_xInfoP->status == VBUSY) {
1037 qPut(&busyHead, a_xInfoP->volid);
1039 fprintf(STDOUT, "VOLUME_BUSY\t%lu\n",
1040 (unsigned long)a_xInfoP->volid);
1044 qPut(¬okHead, a_xInfoP->volid);
1046 fprintf(STDOUT, "COULD_NOT_ATTACH_VOLUME\t%lu\n",
1047 (unsigned long)a_xInfoP->volid);
1048 } /*Screwed volume */
1049 } /*Default listing */
1050 } /*XDisplayFormat */
1053 DisplayFormat2(long server, long partition, volintInfo *pntr)
1055 static long server_cache = -1, partition_cache = -1;
1056 static char hostname[256], address[32], pname[16];
1059 if (server != server_cache) {
1063 strcpy(hostname, hostutil_GetNameByINet(server));
1064 strcpy(address, inet_ntoa(s));
1065 server_cache = server;
1067 if (partition != partition_cache) {
1068 MapPartIdIntoName(partition, pname);
1069 partition_cache = partition;
1072 if (pntr->status == VOK)
1073 fprintf(STDOUT, "name\t\t%s\n", pntr->name);
1075 fprintf(STDOUT, "id\t\t%lu\n",
1076 afs_printable_uint32_lu(pntr->volid));
1077 fprintf(STDOUT, "serv\t\t%s\t%s\n", address, hostname);
1078 fprintf(STDOUT, "part\t\t%s\n", pname);
1079 switch (pntr->status) {
1081 fprintf(STDOUT, "status\t\tOK\n");
1084 fprintf(STDOUT, "status\t\tBUSY\n");
1087 fprintf(STDOUT, "status\t\tUNATTACHABLE\n");
1090 fprintf(STDOUT, "backupID\t%lu\n",
1091 afs_printable_uint32_lu(pntr->backupID));
1092 fprintf(STDOUT, "parentID\t%lu\n",
1093 afs_printable_uint32_lu(pntr->parentID));
1094 fprintf(STDOUT, "cloneID\t\t%lu\n",
1095 afs_printable_uint32_lu(pntr->cloneID));
1096 fprintf(STDOUT, "inUse\t\t%s\n", pntr->inUse ? "Y" : "N");
1097 fprintf(STDOUT, "needsSalvaged\t%s\n", pntr->needsSalvaged ? "Y" : "N");
1098 /* 0xD3 is from afs/volume.h since I had trouble including the file */
1099 fprintf(STDOUT, "destroyMe\t%s\n", pntr->destroyMe == 0xD3 ? "Y" : "N");
1100 switch (pntr->type) {
1102 fprintf(STDOUT, "type\t\tRW\n");
1105 fprintf(STDOUT, "type\t\tRO\n");
1108 fprintf(STDOUT, "type\t\tBK\n");
1111 fprintf(STDOUT, "type\t\t?\n");
1114 t = pntr->creationDate;
1115 fprintf(STDOUT, "creationDate\t%-9lu\t%s",
1116 afs_printable_uint32_lu(pntr->creationDate),
1119 t = pntr->accessDate;
1120 fprintf(STDOUT, "accessDate\t%-9lu\t%s",
1121 afs_printable_uint32_lu(pntr->accessDate),
1124 t = pntr->updateDate;
1125 fprintf(STDOUT, "updateDate\t%-9lu\t%s",
1126 afs_printable_uint32_lu(pntr->updateDate),
1129 t = pntr->backupDate;
1130 fprintf(STDOUT, "backupDate\t%-9lu\t%s",
1131 afs_printable_uint32_lu(pntr->backupDate),
1135 fprintf(STDOUT, "copyDate\t%-9lu\t%s",
1136 afs_printable_uint32_lu(pntr->copyDate),
1139 fprintf(STDOUT, "flags\t\t%#lx\t(Optional)\n",
1140 afs_printable_uint32_lu(pntr->flags));
1141 fprintf(STDOUT, "diskused\t%u\n", pntr->size);
1142 fprintf(STDOUT, "maxquota\t%u\n", pntr->maxquota);
1143 fprintf(STDOUT, "minquota\t%lu\t(Optional)\n",
1144 afs_printable_uint32_lu(pntr->spare0));
1145 fprintf(STDOUT, "filecount\t%u\n", pntr->filecount);
1146 fprintf(STDOUT, "dayUse\t\t%u\n", pntr->dayUse);
1147 fprintf(STDOUT, "weekUse\t\t%lu\t(Optional)\n",
1148 afs_printable_uint32_lu(pntr->spare1));
1149 fprintf(STDOUT, "spare2\t\t%lu\t(Optional)\n",
1150 afs_printable_uint32_lu(pntr->spare2));
1151 fprintf(STDOUT, "spare3\t\t%lu\t(Optional)\n",
1152 afs_printable_uint32_lu(pntr->spare3));
1157 DisplayVolumes2(long server, long partition, volintInfo *pntr, long count)
1161 for (i = 0; i < count; i++) {
1162 fprintf(STDOUT, "BEGIN_OF_ENTRY\n");
1163 DisplayFormat2(server, partition, pntr);
1164 fprintf(STDOUT, "END_OF_ENTRY\n\n");
1171 DisplayVolumes(afs_uint32 server, afs_int32 part, volintInfo *pntr,
1172 afs_int32 count, afs_int32 longlist, afs_int32 fast,
1175 int totalOK, totalNotOK, totalBusy, i;
1176 afs_uint32 volid = 0;
1183 for (i = 0; i < count; i++) {
1184 DisplayFormat(pntr, server, part, &totalOK, &totalNotOK, &totalBusy,
1189 while (busyHead.count) {
1190 qGet(&busyHead, &volid);
1191 fprintf(STDOUT, "**** Volume %lu is busy ****\n",
1192 (unsigned long)volid);
1196 while (notokHead.count) {
1197 qGet(¬okHead, &volid);
1198 fprintf(STDOUT, "**** Could not attach volume %lu ****\n",
1199 (unsigned long)volid);
1203 fprintf(STDOUT, "\n");
1206 "Total volumes onLine %d ; Total volumes offLine %d ; Total busy %d\n\n",
1207 totalOK, totalNotOK, totalBusy);
1211 /*------------------------------------------------------------------------
1212 * PRIVATE XDisplayVolumes
1215 * Display extended volume information.
1218 * a_servID : Pointer to the Rx call we're performing.
1219 * a_partID : Partition for which we want the extended list.
1220 * a_xInfoP : Ptr to extended volume info.
1221 * a_count : Number of volume records contained above.
1222 * a_int32 : Int32 listing generated?
1223 * a_fast : Fast listing generated?
1224 * a_quiet : Quiet listing generated?
1230 * Nothing interesting.
1234 *------------------------------------------------------------------------*/
1237 XDisplayVolumes(afs_uint32 a_servID, afs_int32 a_partID, volintXInfo *a_xInfoP,
1238 afs_int32 a_count, afs_int32 a_int32, afs_int32 a_fast,
1240 { /*XDisplayVolumes */
1242 int totalOK; /*Total OK volumes */
1243 int totalNotOK; /*Total screwed volumes */
1244 int totalBusy; /*Total busy volumes */
1245 int i; /*Loop variable */
1246 afs_uint32 volid = 0; /*Current volume ID */
1249 * Initialize counters and (global!!) queues.
1258 * Display each volume in the list.
1260 for (i = 0; i < a_count; i++) {
1261 XDisplayFormat(a_xInfoP, a_servID, a_partID, &totalOK, &totalNotOK,
1262 &totalBusy, a_fast, a_int32, 0);
1267 * If any volumes were found to be busy or screwed, display them.
1270 while (busyHead.count) {
1271 qGet(&busyHead, &volid);
1272 fprintf(STDOUT, "**** Volume %lu is busy ****\n",
1273 (unsigned long)volid);
1277 while (notokHead.count) {
1278 qGet(¬okHead, &volid);
1279 fprintf(STDOUT, "**** Could not attach volume %lu ****\n",
1280 (unsigned long)volid);
1285 fprintf(STDOUT, "\n");
1288 "Total volumes: %d on-line, %d off-line, %d busyd\n\n",
1289 totalOK, totalNotOK, totalBusy);
1293 } /*XDisplayVolumes */
1295 /*------------------------------------------------------------------------
1296 * PRIVATE XDisplayVolumes2
1299 * Display extended formated volume information.
1302 * a_servID : Pointer to the Rx call we're performing.
1303 * a_partID : Partition for which we want the extended list.
1304 * a_xInfoP : Ptr to extended volume info.
1305 * a_count : Number of volume records contained above.
1306 * a_int32 : Int32 listing generated?
1307 * a_fast : Fast listing generated?
1308 * a_quiet : Quiet listing generated?
1314 * Nothing interesting.
1318 *------------------------------------------------------------------------*/
1321 XDisplayVolumes2(afs_uint32 a_servID, afs_int32 a_partID, volintXInfo *a_xInfoP,
1322 afs_int32 a_count, afs_int32 a_int32, afs_int32 a_fast,
1324 { /*XDisplayVolumes */
1326 int totalOK; /*Total OK volumes */
1327 int totalNotOK; /*Total screwed volumes */
1328 int totalBusy; /*Total busy volumes */
1329 int i; /*Loop variable */
1330 afs_uint32 volid = 0; /*Current volume ID */
1333 * Initialize counters and (global!!) queues.
1342 * Display each volume in the list.
1344 for (i = 0; i < a_count; i++) {
1345 fprintf(STDOUT, "BEGIN_OF_ENTRY\n");
1346 XDisplayFormat2(a_xInfoP, a_servID, a_partID, &totalOK, &totalNotOK,
1347 &totalBusy, a_fast, a_int32, 0);
1348 fprintf(STDOUT, "END_OF_ENTRY\n");
1353 * If any volumes were found to be busy or screwed, display them.
1356 while (busyHead.count) {
1357 qGet(&busyHead, &volid);
1358 fprintf(STDOUT, "BUSY_VOL\t%lu\n",
1359 (unsigned long)volid);
1363 while (notokHead.count) {
1364 qGet(¬okHead, &volid);
1365 fprintf(STDOUT, "COULD_NOT_ATTACH\t%lu\n",
1366 (unsigned long)volid);
1371 fprintf(STDOUT, "\n");
1374 "VOLUMES_ONLINE\t%d\nVOLUMES_OFFLINE\t%d\nVOLUMES_BUSY\t%d\n",
1375 totalOK, totalNotOK, totalBusy);
1379 } /*XDisplayVolumes2 */
1382 /* set <server> and <part> to the correct values depending on
1383 * <voltype> and <entry> */
1385 GetServerAndPart(struct uvldbentry *entry, int voltype, afs_uint32 *server,
1386 afs_int32 *part, int *previdx)
1388 int i, istart, vtype;
1393 /* Doesn't check for non-existance of backup volume */
1394 if ((voltype == RWVOL) || (voltype == BACKVOL)) {
1396 istart = 0; /* seach the entire entry */
1399 /* Seach from beginning of entry or pick up where we left off */
1400 istart = ((*previdx < 0) ? 0 : *previdx + 1);
1403 for (i = istart; i < entry->nServers && i < NMAXNSERVERS; i++) {
1404 if (entry->serverFlags[i] & vtype) {
1405 /* *uuid = entry->serverNumber[i]; */
1406 *server = entry->serverUnique[i];
1407 *part = entry->serverPartition[i];
1413 /* Didn't find any, return -1 */
1419 PrintLocked(afs_int32 aflags)
1421 afs_int32 flags = aflags & VLOP_ALLOPERS;
1424 fprintf(STDOUT, " Volume is currently LOCKED \n");
1426 if (flags & VLOP_MOVE) {
1427 fprintf(STDOUT, " Volume is locked for a move operation\n");
1429 if (flags & VLOP_RELEASE) {
1430 fprintf(STDOUT, " Volume is locked for a release operation\n");
1432 if (flags & VLOP_BACKUP) {
1433 fprintf(STDOUT, " Volume is locked for a backup operation\n");
1435 if (flags & VLOP_DELETE) {
1436 fprintf(STDOUT, " Volume is locked for a delete/misc operation\n");
1438 if (flags & VLOP_DUMP) {
1439 fprintf(STDOUT, " Volume is locked for a dump/restore operation\n");
1445 PostVolumeStats(struct uvldbentry *entry)
1447 SubEnumerateEntryU(entry);
1448 /* Check for VLOP_ALLOPERS */
1449 PrintLocked(entry->flags);
1453 /*------------------------------------------------------------------------
1454 * PRIVATE XVolumeStats
1457 * Display extended volume information.
1460 * a_xInfoP : Ptr to extended volume info.
1461 * a_entryP : Ptr to the volume's VLDB entry.
1462 * a_srvID : Server ID.
1463 * a_partID : Partition ID.
1464 * a_volType : Type of volume to print.
1470 * Nothing interesting.
1474 *------------------------------------------------------------------------*/
1477 XVolumeStats(volintXInfo *a_xInfoP, struct uvldbentry *a_entryP,
1478 afs_int32 a_srvID, afs_int32 a_partID, int a_volType)
1481 int totalOK, totalNotOK, totalBusy; /*Dummies - we don't really count here */
1483 XDisplayFormat(a_xInfoP, /*Ptr to extended volume info */
1484 a_srvID, /*Server ID to print */
1485 a_partID, /*Partition ID to print */
1486 &totalOK, /*Ptr to total-OK counter */
1487 &totalNotOK, /*Ptr to total-screwed counter */
1488 &totalBusy, /*Ptr to total-busy counter */
1489 0, /*Don't do a fast listing */
1490 1, /*Do a long listing */
1491 1); /*Show volume problems */
1497 VolumeStats_int(volintInfo *pntr, struct uvldbentry *entry, afs_uint32 server,
1498 afs_int32 part, int voltype)
1500 int totalOK, totalNotOK, totalBusy;
1502 DisplayFormat(pntr, server, part, &totalOK, &totalNotOK, &totalBusy, 0, 1,
1507 /* command to forcibly remove a volume */
1509 NukeVolume(struct cmd_syndesc *as)
1518 server = GetServer(tp = as->parms[0].items->data);
1520 fprintf(STDERR, "vos: server '%s' not found in host table\n", tp);
1524 partID = volutil_GetPartitionID(tp = as->parms[1].items->data);
1526 fprintf(STDERR, "vos: could not parse '%s' as a partition name", tp);
1530 volID = vsu_GetVolumeID(tp = as->parms[2].items->data, cstruct, &err);
1533 PrintError("", err);
1536 "vos: could not parse '%s' as a numeric volume ID", tp);
1541 "vos: forcibly removing all traces of volume %d, please wait...",
1544 code = UV_NukeVolume(server, partID, volID);
1546 fprintf(STDOUT, "done.\n");
1548 fprintf(STDOUT, "failed with code %d.\n", code);
1553 /*------------------------------------------------------------------------
1554 * PRIVATE ExamineVolume
1557 * Routine used to examine a single volume, contacting the VLDB as
1558 * well as the Volume Server.
1561 * as : Ptr to parsed command line arguments.
1564 * 0 for a successful operation,
1565 * Otherwise, one of the ubik or VolServer error values.
1568 * Nothing interesting.
1572 *------------------------------------------------------------------------
1575 ExamineVolume(struct cmd_syndesc *as, void *arock)
1577 struct uvldbentry entry;
1578 afs_int32 vcode = 0;
1579 volintInfo *pntr = (volintInfo *) 0;
1580 volintXInfo *xInfoP = (volintXInfo *) 0;
1582 afs_int32 code, err, error = 0;
1583 int voltype, foundserv = 0, foundentry = 0;
1587 int wantExtendedInfo; /*Do we want extended vol info? */
1588 int isSubEnum=0; /* Keep track whether sub enumerate called. */
1589 wantExtendedInfo = (as->parms[1].items ? 1 : 0); /* -extended */
1591 volid = vsu_GetVolumeID(as->parms[0].items->data, cstruct, &err); /* -id */
1594 PrintError("", err);
1596 fprintf(STDERR, "Unknown volume ID or name '%s'\n",
1597 as->parms[0].items->data);
1602 fprintf(STDOUT, "Fetching VLDB entry for %lu .. ",
1603 (unsigned long)volid);
1606 vcode = VLDB_GetEntryByIDU(volid, -1, &entry);
1609 "Could not fetch the entry for volume number %lu from VLDB \n",
1610 (unsigned long)volid);
1614 fprintf(STDOUT, "done\n");
1615 MapHostToNetworkU(&entry);
1617 if (entry.volumeId[RWVOL] == volid)
1619 else if (entry.volumeId[BACKVOL] == volid)
1621 else /* (entry.volumeId[ROVOL] == volid) */
1624 do { /* do {...} while (voltype == ROVOL) */
1625 /* Get the entry for the volume. If its a RW vol, get the RW entry.
1626 * It its a BK vol, get the RW entry (even if VLDB may say the BK doen't exist).
1627 * If its a RO vol, get the next RO entry.
1629 GetServerAndPart(&entry, ((voltype == ROVOL) ? ROVOL : RWVOL),
1630 &aserver, &apart, &previdx);
1631 if (previdx == -1) { /* searched all entries */
1633 fprintf(STDERR, "Volume %s does not exist in VLDB\n\n",
1634 as->parms[0].items->data);
1641 /* Get information about the volume from the server */
1643 fprintf(STDOUT, "Getting volume listing from the server %s .. ",
1644 hostutil_GetNameByINet(aserver));
1647 if (wantExtendedInfo)
1648 code = UV_XListOneVolume(aserver, apart, volid, &xInfoP);
1650 code = UV_ListOneVolume(aserver, apart, volid, &pntr);
1652 fprintf(STDOUT, "done\n");
1656 if (code == ENODEV) {
1657 if ((voltype == BACKVOL) && !(entry.flags & BACK_EXISTS)) {
1658 /* The VLDB says there is no backup volume and its not on disk */
1659 fprintf(STDERR, "Volume %s does not exist\n",
1660 as->parms[0].items->data);
1664 "Volume does not exist on server %s as indicated by the VLDB\n",
1665 hostutil_GetNameByINet(aserver));
1668 PrintDiagnostics("examine", code);
1670 fprintf(STDOUT, "\n");
1673 if (wantExtendedInfo)
1674 XVolumeStats(xInfoP, &entry, aserver, apart, voltype);
1675 else if (as->parms[2].items) {
1676 DisplayFormat2(aserver, apart, pntr);
1677 EnumerateEntryU(&entry);
1680 VolumeStats_int(pntr, &entry, aserver, apart, voltype);
1682 if ((voltype == BACKVOL) && !(entry.flags & BACK_EXISTS)) {
1683 /* The VLDB says there is no backup volume yet we found one on disk */
1684 fprintf(STDERR, "Volume %s does not exist in VLDB\n",
1685 as->parms[0].items->data);
1694 } while (voltype == ROVOL);
1697 fprintf(STDERR, "Dump only information from VLDB\n\n");
1698 fprintf(STDOUT, "%s \n", entry.name); /* PostVolumeStats doesn't print name */
1702 PostVolumeStats(&entry);
1707 /*------------------------------------------------------------------------
1711 * Routine used to change the status of a single volume.
1714 * as : Ptr to parsed command line arguments.
1717 * 0 for a successful operation,
1718 * Otherwise, one of the ubik or VolServer error values.
1721 * Nothing interesting.
1725 *------------------------------------------------------------------------
1728 SetFields(struct cmd_syndesc *as, void *arock)
1730 struct uvldbentry entry;
1733 afs_int32 code, err;
1738 volid = vsu_GetVolumeID(as->parms[0].items->data, cstruct, &err); /* -id */
1741 PrintError("", err);
1743 fprintf(STDERR, "Unknown volume ID or name '%s'\n",
1744 as->parms[0].items->data);
1748 code = VLDB_GetEntryByIDU(volid, RWVOL, &entry);
1751 "Could not fetch the entry for volume number %lu from VLDB \n",
1752 (unsigned long)volid);
1755 MapHostToNetworkU(&entry);
1757 GetServerAndPart(&entry, RWVOL, &aserver, &apart, &previdx);
1758 if (previdx == -1) {
1759 fprintf(STDERR, "Volume %s does not exist in VLDB\n\n",
1760 as->parms[0].items->data);
1764 init_volintInfo(&info);
1768 if (as->parms[1].items) {
1770 code = util_GetHumanInt32(as->parms[1].items->data, &info.maxquota);
1772 fprintf(STDERR, "invalid quota value\n");
1776 if (as->parms[2].items) {
1780 if (as->parms[3].items) {
1781 /* -clearVolUpCounter */
1784 code = UV_SetVolumeInfo(aserver, apart, volid, &info);
1787 "Could not update volume info fields for volume number %lu\n",
1788 (unsigned long)volid);
1792 /*------------------------------------------------------------------------
1796 * Brings a volume online.
1799 * as : Ptr to parsed command line arguments.
1802 * 0 for a successful operation,
1805 * Nothing interesting.
1809 *------------------------------------------------------------------------
1812 volOnline(struct cmd_syndesc *as, void *arock)
1815 afs_int32 partition;
1817 afs_int32 code, err = 0;
1819 server = GetServer(as->parms[0].items->data);
1821 fprintf(STDERR, "vos: server '%s' not found in host table\n",
1822 as->parms[0].items->data);
1826 partition = volutil_GetPartitionID(as->parms[1].items->data);
1827 if (partition < 0) {
1828 fprintf(STDERR, "vos: could not interpret partition name '%s'\n",
1829 as->parms[1].items->data);
1833 volid = vsu_GetVolumeID(as->parms[2].items->data, cstruct, &err); /* -id */
1836 PrintError("", err);
1838 fprintf(STDERR, "Unknown volume ID or name '%s'\n",
1839 as->parms[0].items->data);
1843 code = UV_SetVolume(server, partition, volid, ITOffline, 0 /*online */ ,
1846 fprintf(STDERR, "Failed to set volume. Code = %d\n", code);
1853 /*------------------------------------------------------------------------
1854 * PRIVATE volOffline
1857 * Brings a volume offline.
1860 * as : Ptr to parsed command line arguments.
1863 * 0 for a successful operation,
1866 * Nothing interesting.
1870 *------------------------------------------------------------------------
1873 volOffline(struct cmd_syndesc *as, void *arock)
1876 afs_int32 partition;
1878 afs_int32 code, err = 0;
1879 afs_int32 transflag, sleeptime, transdone;
1881 server = GetServer(as->parms[0].items->data);
1883 fprintf(STDERR, "vos: server '%s' not found in host table\n",
1884 as->parms[0].items->data);
1888 partition = volutil_GetPartitionID(as->parms[1].items->data);
1889 if (partition < 0) {
1890 fprintf(STDERR, "vos: could not interpret partition name '%s'\n",
1891 as->parms[1].items->data);
1895 volid = vsu_GetVolumeID(as->parms[2].items->data, cstruct, &err); /* -id */
1898 PrintError("", err);
1900 fprintf(STDERR, "Unknown volume ID or name '%s'\n",
1901 as->parms[0].items->data);
1905 transflag = (as->parms[4].items ? ITBusy : ITOffline);
1906 sleeptime = (as->parms[3].items ? atol(as->parms[3].items->data) : 0);
1907 transdone = (sleeptime ? 0 /*online */ : VTOutOfService);
1908 if (as->parms[4].items && !as->parms[3].items) {
1909 fprintf(STDERR, "-sleep option must be used with -busy flag\n");
1914 UV_SetVolume(server, partition, volid, transflag, transdone,
1917 fprintf(STDERR, "Failed to set volume. Code = %d\n", code);
1925 CreateVolume(struct cmd_syndesc *as, void *arock)
1929 afs_uint32 volid = 0, rovolid = 0, bkvolid = 0;
1930 afs_uint32 *arovolid;
1932 struct uvldbentry entry;
1936 arovolid = &rovolid;
1939 tserver = GetServer(as->parms[0].items->data);
1941 fprintf(STDERR, "vos: host '%s' not found in host table\n",
1942 as->parms[0].items->data);
1945 pnum = volutil_GetPartitionID(as->parms[1].items->data);
1947 fprintf(STDERR, "vos: could not interpret partition name '%s'\n",
1948 as->parms[1].items->data);
1951 if (!IsPartValid(pnum, tserver, &code)) { /*check for validity of the partition */
1953 PrintError("", code);
1956 "vos : partition %s does not exist on the server\n",
1957 as->parms[1].items->data);
1960 if (!ISNAMEVALID(as->parms[2].items->data)) {
1962 "vos: the name of the root volume %s exceeds the size limit of %d\n",
1963 as->parms[2].items->data, VOLSER_OLDMAXVOLNAME - 10);
1966 if (!VolNameOK(as->parms[2].items->data)) {
1968 "Illegal volume name %s, should not end in .readonly or .backup\n",
1969 as->parms[2].items->data);
1972 if (IsNumeric(as->parms[2].items->data)) {
1973 fprintf(STDERR, "Illegal volume name %s, should not be a number\n",
1974 as->parms[2].items->data);
1977 vcode = VLDB_GetEntryByNameU(as->parms[2].items->data, &entry);
1979 fprintf(STDERR, "Volume %s already exists\n",
1980 as->parms[2].items->data);
1981 PrintDiagnostics("create", code);
1985 if (as->parms[3].items) {
1986 code = util_GetHumanInt32(as->parms[3].items->data, "a);
1988 fprintf(STDERR, "vos: bad integer specified for quota.\n");
1993 if (as->parms[4].items) {
1994 if (!IsNumeric(as->parms[4].items->data)) {
1995 fprintf(STDERR, "vos: Given volume ID %s should be numeric.\n",
1996 as->parms[4].items->data);
2000 code = util_GetUInt32(as->parms[4].items->data, &volid);
2002 fprintf(STDERR, "vos: bad integer specified for volume ID.\n");
2007 if (as->parms[5].items) {
2008 if (!IsNumeric(as->parms[5].items->data)) {
2009 fprintf(STDERR, "vos: Given RO volume ID %s should be numeric.\n",
2010 as->parms[5].items->data);
2014 code = util_GetUInt32(as->parms[5].items->data, &rovolid);
2016 fprintf(STDERR, "vos: bad integer specified for volume ID.\n");
2026 UV_CreateVolume3(tserver, pnum, as->parms[2].items->data, quota, 0,
2027 0, 0, 0, &volid, arovolid, &bkvolid);
2029 PrintDiagnostics("create", code);
2032 MapPartIdIntoName(pnum, part);
2033 fprintf(STDOUT, "Volume %lu created on partition %s of %s\n",
2034 (unsigned long)volid, part, as->parms[0].items->data);
2041 DeleteAll(struct uvldbentry *entry)
2044 afs_int32 error, code, curserver, curpart;
2047 MapHostToNetworkU(entry);
2049 for (i = 0; i < entry->nServers; i++) {
2050 curserver = entry->serverUnique[i];
2051 curpart = entry->serverPartition[i];
2052 if (entry->serverFlags[i] & ITSROVOL) {
2053 volid = entry->volumeId[ROVOL];
2055 volid = entry->volumeId[RWVOL];
2057 code = UV_DeleteVolume(curserver, curpart, volid);
2066 DeleteVolume(struct cmd_syndesc *as, void *arock)
2068 afs_int32 err, code = 0;
2069 afs_uint32 server = 0;
2070 afs_int32 partition = -1;
2075 if (as->parms[0].items) {
2076 server = GetServer(as->parms[0].items->data);
2078 fprintf(STDERR, "vos: server '%s' not found in host table\n",
2079 as->parms[0].items->data);
2084 if (as->parms[1].items) {
2085 partition = volutil_GetPartitionID(as->parms[1].items->data);
2086 if (partition < 0) {
2087 fprintf(STDERR, "vos: could not interpret partition name '%s'\n",
2088 as->parms[1].items->data);
2092 /* Check for validity of the partition */
2093 if (!IsPartValid(partition, server, &code)) {
2095 PrintError("", code);
2098 "vos : partition %s does not exist on the server\n",
2099 as->parms[1].items->data);
2105 volid = vsu_GetVolumeID(as->parms[2].items->data, cstruct, &err);
2107 fprintf(STDERR, "Can't find volume name '%s' in VLDB\n",
2108 as->parms[2].items->data);
2110 PrintError("", err);
2114 /* If the server or partition option are not complete, try to fill
2115 * them in from the VLDB entry.
2117 if ((partition == -1) || !server) {
2118 struct uvldbentry entry;
2120 code = VLDB_GetEntryByIDU(volid, -1, &entry);
2123 "Could not fetch the entry for volume %lu from VLDB\n",
2124 (unsigned long)volid);
2125 PrintError("", code);
2129 if (((volid == entry.volumeId[RWVOL]) && (entry.flags & RW_EXISTS))
2130 || ((volid == entry.volumeId[BACKVOL])
2131 && (entry.flags & BACK_EXISTS))) {
2132 idx = Lp_GetRwIndexU(&entry);
2133 if ((idx == -1) || (server && (server != entry.serverUnique[idx]))
2134 || ((partition != -1)
2135 && (partition != entry.serverPartition[idx]))) {
2136 fprintf(STDERR, "VLDB: Volume '%s' no match\n",
2137 as->parms[2].items->data);
2140 } else if ((volid == entry.volumeId[ROVOL])
2141 && (entry.flags & RO_EXISTS)) {
2142 for (idx = -1, j = 0; j < entry.nServers; j++) {
2143 if (entry.serverFlags[j] != ITSROVOL)
2146 if (((server == 0) || (server == entry.serverUnique[j]))
2147 && ((partition == -1)
2148 || (partition == entry.serverPartition[j]))) {
2151 "VLDB: Volume '%s' matches more than one RO\n",
2152 as->parms[2].items->data);
2159 fprintf(STDERR, "VLDB: Volume '%s' no match\n",
2160 as->parms[2].items->data);
2164 fprintf(STDERR, "VLDB: Volume '%s' no match\n",
2165 as->parms[2].items->data);
2169 server = htonl(entry.serverUnique[idx]);
2170 partition = entry.serverPartition[idx];
2174 code = UV_DeleteVolume(server, partition, volid);
2176 PrintDiagnostics("remove", code);
2180 MapPartIdIntoName(partition, pname);
2181 fprintf(STDOUT, "Volume %lu on partition %s server %s deleted\n",
2182 (unsigned long)volid, pname, hostutil_GetNameByINet(server));
2186 #define TESTM 0 /* set for move space tests, clear for production */
2188 MoveVolume(struct cmd_syndesc *as, void *arock)
2192 afs_uint32 fromserver, toserver;
2193 afs_int32 frompart, topart;
2194 afs_int32 flags, code, err;
2195 char fromPartName[10], toPartName[10];
2197 struct diskPartition64 partition; /* for space check */
2200 volid = vsu_GetVolumeID(as->parms[0].items->data, cstruct, &err);
2203 PrintError("", err);
2205 fprintf(STDERR, "vos: can't find volume ID or name '%s'\n",
2206 as->parms[0].items->data);
2209 fromserver = GetServer(as->parms[1].items->data);
2210 if (fromserver == 0) {
2211 fprintf(STDERR, "vos: server '%s' not found in host table\n",
2212 as->parms[1].items->data);
2215 toserver = GetServer(as->parms[3].items->data);
2216 if (toserver == 0) {
2217 fprintf(STDERR, "vos: server '%s' not found in host table\n",
2218 as->parms[3].items->data);
2221 frompart = volutil_GetPartitionID(as->parms[2].items->data);
2223 fprintf(STDERR, "vos: could not interpret partition name '%s'\n",
2224 as->parms[2].items->data);
2227 if (!IsPartValid(frompart, fromserver, &code)) { /*check for validity of the partition */
2229 PrintError("", code);
2232 "vos : partition %s does not exist on the server\n",
2233 as->parms[2].items->data);
2236 topart = volutil_GetPartitionID(as->parms[4].items->data);
2238 fprintf(STDERR, "vos: could not interpret partition name '%s'\n",
2239 as->parms[4].items->data);
2242 if (!IsPartValid(topart, toserver, &code)) { /*check for validity of the partition */
2244 PrintError("", code);
2247 "vos : partition %s does not exist on the server\n",
2248 as->parms[4].items->data);
2253 if (as->parms[5].items) flags |= RV_NOCLONE;
2256 * check source partition for space to clone volume
2259 MapPartIdIntoName(topart, toPartName);
2260 MapPartIdIntoName(frompart, fromPartName);
2263 * check target partition for space to move volume
2266 code = UV_PartitionInfo64(toserver, toPartName, &partition);
2268 fprintf(STDERR, "vos: cannot access partition %s\n", toPartName);
2272 fprintf(STDOUT, "target partition %s free space %" AFS_INT64_FMT "\n", toPartName,
2275 p = (volintInfo *) 0;
2276 code = UV_ListOneVolume(fromserver, frompart, volid, &p);
2278 fprintf(STDERR, "vos:cannot access volume %lu\n",
2279 (unsigned long)volid);
2283 fprintf(STDOUT, "volume %lu size %d\n", (unsigned long)volid,
2285 if (partition.free <= p->size) {
2287 "vos: no space on target partition %s to move volume %lu\n",
2288 toPartName, (unsigned long)volid);
2295 fprintf(STDOUT, "size test - don't do move\n");
2299 /* successful move still not guaranteed but shoot for it */
2302 UV_MoveVolume2(volid, fromserver, frompart, toserver, topart, flags);
2304 PrintDiagnostics("move", code);
2307 MapPartIdIntoName(topart, toPartName);
2308 MapPartIdIntoName(frompart, fromPartName);
2309 fprintf(STDOUT, "Volume %lu moved from %s %s to %s %s \n",
2310 (unsigned long)volid, as->parms[1].items->data, fromPartName,
2311 as->parms[3].items->data, toPartName);
2317 CopyVolume(struct cmd_syndesc *as, void *arock)
2320 afs_uint32 fromserver, toserver;
2321 afs_int32 frompart, topart, code, err, flags;
2322 char fromPartName[10], toPartName[10], *tovolume;
2323 struct uvldbentry entry;
2324 struct diskPartition64 partition; /* for space check */
2327 volid = vsu_GetVolumeID(as->parms[0].items->data, cstruct, &err);
2330 PrintError("", err);
2332 fprintf(STDERR, "vos: can't find volume ID or name '%s'\n",
2333 as->parms[0].items->data);
2336 fromserver = GetServer(as->parms[1].items->data);
2337 if (fromserver == 0) {
2338 fprintf(STDERR, "vos: server '%s' not found in host table\n",
2339 as->parms[1].items->data);
2343 toserver = GetServer(as->parms[4].items->data);
2344 if (toserver == 0) {
2345 fprintf(STDERR, "vos: server '%s' not found in host table\n",
2346 as->parms[4].items->data);
2350 tovolume = as->parms[3].items->data;
2351 if (!ISNAMEVALID(tovolume)) {
2353 "vos: the name of the root volume %s exceeds the size limit of %d\n",
2354 tovolume, VOLSER_OLDMAXVOLNAME - 10);
2357 if (!VolNameOK(tovolume)) {
2359 "Illegal volume name %s, should not end in .readonly or .backup\n",
2363 if (IsNumeric(tovolume)) {
2364 fprintf(STDERR, "Illegal volume name %s, should not be a number\n",
2368 code = VLDB_GetEntryByNameU(tovolume, &entry);
2370 fprintf(STDERR, "Volume %s already exists\n", tovolume);
2371 PrintDiagnostics("copy", code);
2375 frompart = volutil_GetPartitionID(as->parms[2].items->data);
2377 fprintf(STDERR, "vos: could not interpret partition name '%s'\n",
2378 as->parms[2].items->data);
2381 if (!IsPartValid(frompart, fromserver, &code)) { /*check for validity of the partition */
2383 PrintError("", code);
2386 "vos : partition %s does not exist on the server\n",
2387 as->parms[2].items->data);
2391 topart = volutil_GetPartitionID(as->parms[5].items->data);
2393 fprintf(STDERR, "vos: could not interpret partition name '%s'\n",
2394 as->parms[5].items->data);
2397 if (!IsPartValid(topart, toserver, &code)) { /*check for validity of the partition */
2399 PrintError("", code);
2402 "vos : partition %s does not exist on the server\n",
2403 as->parms[5].items->data);
2408 if (as->parms[6].items) flags |= RV_OFFLINE;
2409 if (as->parms[7].items) flags |= RV_RDONLY;
2410 if (as->parms[8].items) flags |= RV_NOCLONE;
2412 MapPartIdIntoName(topart, toPartName);
2413 MapPartIdIntoName(frompart, fromPartName);
2416 * check target partition for space to move volume
2419 code = UV_PartitionInfo64(toserver, toPartName, &partition);
2421 fprintf(STDERR, "vos: cannot access partition %s\n", toPartName);
2425 fprintf(STDOUT, "target partition %s free space %" AFS_INT64_FMT "\n", toPartName,
2428 p = (volintInfo *) 0;
2429 code = UV_ListOneVolume(fromserver, frompart, volid, &p);
2431 fprintf(STDERR, "vos:cannot access volume %lu\n",
2432 (unsigned long)volid);
2436 if (partition.free <= p->size) {
2438 "vos: no space on target partition %s to copy volume %lu\n",
2439 toPartName, (unsigned long)volid);
2445 /* successful copy still not guaranteed but shoot for it */
2448 UV_CopyVolume2(volid, fromserver, frompart, tovolume, toserver,
2451 PrintDiagnostics("copy", code);
2454 MapPartIdIntoName(topart, toPartName);
2455 MapPartIdIntoName(frompart, fromPartName);
2456 fprintf(STDOUT, "Volume %lu copied from %s %s to %s on %s %s \n",
2457 (unsigned long)volid, as->parms[1].items->data, fromPartName,
2458 tovolume, as->parms[4].items->data, toPartName);
2465 ShadowVolume(struct cmd_syndesc *as, void *arock)
2467 afs_uint32 volid, tovolid;
2468 afs_uint32 fromserver, toserver;
2469 afs_int32 frompart, topart;
2470 afs_int32 code, err, flags;
2471 char fromPartName[10], toPartName[10], toVolName[32], *tovolume;
2472 struct diskPartition64 partition; /* for space check */
2475 p = (volintInfo *) 0;
2476 q = (volintInfo *) 0;
2478 volid = vsu_GetVolumeID(as->parms[0].items->data, cstruct, &err);
2481 PrintError("", err);
2483 fprintf(STDERR, "vos: can't find volume ID or name '%s'\n",
2484 as->parms[0].items->data);
2487 fromserver = GetServer(as->parms[1].items->data);
2488 if (fromserver == 0) {
2489 fprintf(STDERR, "vos: server '%s' not found in host table\n",
2490 as->parms[1].items->data);
2494 toserver = GetServer(as->parms[3].items->data);
2495 if (toserver == 0) {
2496 fprintf(STDERR, "vos: server '%s' not found in host table\n",
2497 as->parms[3].items->data);
2501 frompart = volutil_GetPartitionID(as->parms[2].items->data);
2503 fprintf(STDERR, "vos: could not interpret partition name '%s'\n",
2504 as->parms[2].items->data);
2507 if (!IsPartValid(frompart, fromserver, &code)) { /*check for validity of the partition */
2509 PrintError("", code);
2512 "vos : partition %s does not exist on the server\n",
2513 as->parms[2].items->data);
2517 topart = volutil_GetPartitionID(as->parms[4].items->data);
2519 fprintf(STDERR, "vos: could not interpret partition name '%s'\n",
2520 as->parms[4].items->data);
2523 if (!IsPartValid(topart, toserver, &code)) { /*check for validity of the partition */
2525 PrintError("", code);
2528 "vos : partition %s does not exist on the server\n",
2529 as->parms[4].items->data);
2533 if (as->parms[5].items) {
2534 tovolume = as->parms[5].items->data;
2535 if (!ISNAMEVALID(tovolume)) {
2537 "vos: the name of the root volume %s exceeds the size limit of %d\n",
2538 tovolume, VOLSER_OLDMAXVOLNAME - 10);
2541 if (!VolNameOK(tovolume)) {
2543 "Illegal volume name %s, should not end in .readonly or .backup\n",
2547 if (IsNumeric(tovolume)) {
2549 "Illegal volume name %s, should not be a number\n",
2554 /* use actual name of source volume */
2555 code = UV_ListOneVolume(fromserver, frompart, volid, &p);
2557 fprintf(STDERR, "vos:cannot access volume %lu\n",
2558 (unsigned long)volid);
2561 strcpy(toVolName, p->name);
2562 tovolume = toVolName;
2563 /* save p for size checks later */
2566 if (as->parms[6].items) {
2567 tovolid = vsu_GetVolumeID(as->parms[6].items->data, cstruct, &err);
2570 PrintError("", err);
2572 fprintf(STDERR, "vos: can't find volume ID or name '%s'\n",
2573 as->parms[6].items->data);
2579 tovolid = vsu_GetVolumeID(tovolume, cstruct, &err);
2582 PrintError("", err);
2584 fprintf(STDERR, "vos: can't find volume ID or name '%s'\n",
2593 if (as->parms[7].items) flags |= RV_OFFLINE;
2594 if (as->parms[8].items) flags |= RV_RDONLY;
2595 if (as->parms[9].items) flags |= RV_NOCLONE;
2596 if (as->parms[10].items) flags |= RV_CPINCR;
2598 MapPartIdIntoName(topart, toPartName);
2599 MapPartIdIntoName(frompart, fromPartName);
2602 * check target partition for space to move volume
2605 code = UV_PartitionInfo64(toserver, toPartName, &partition);
2607 fprintf(STDERR, "vos: cannot access partition %s\n", toPartName);
2611 fprintf(STDOUT, "target partition %s free space %" AFS_INT64_FMT "\n", toPartName,
2614 /* Don't do this again if we did it above */
2616 code = UV_ListOneVolume(fromserver, frompart, volid, &p);
2618 fprintf(STDERR, "vos:cannot access volume %lu\n",
2619 (unsigned long)volid);
2624 /* OK if this fails */
2625 code = UV_ListOneVolume(toserver, topart, tovolid, &q);
2627 /* Treat existing volume size as "free" */
2629 p->size = (q->size < p->size) ? p->size - q->size : 0;
2631 if (partition.free <= p->size) {
2633 "vos: no space on target partition %s to copy volume %lu\n",
2634 toPartName, (unsigned long)volid);
2642 /* successful copy still not guaranteed but shoot for it */
2645 UV_CopyVolume2(volid, fromserver, frompart, tovolume, toserver,
2646 topart, tovolid, flags);
2648 PrintDiagnostics("shadow", code);
2651 MapPartIdIntoName(topart, toPartName);
2652 MapPartIdIntoName(frompart, fromPartName);
2653 fprintf(STDOUT, "Volume %lu shadowed from %s %s to %s %s \n",
2654 (unsigned long)volid, as->parms[1].items->data, fromPartName,
2655 as->parms[3].items->data, toPartName);
2662 CloneVolume(struct cmd_syndesc *as, void *arock)
2664 afs_uint32 volid, cloneid;
2666 afs_int32 part, voltype;
2667 char partName[10], *volname;
2668 afs_int32 code, err, flags;
2669 struct uvldbentry entry;
2671 volid = vsu_GetVolumeID(as->parms[0].items->data, cstruct, &err);
2674 PrintError("", err);
2676 fprintf(STDERR, "vos: can't find volume ID or name '%s'\n",
2677 as->parms[0].items->data);
2681 if (as->parms[1].items || as->parms[2].items) {
2682 if (!as->parms[1].items || !as->parms[2].items) {
2684 "Must specify both -server and -partition options\n");
2687 server = GetServer(as->parms[1].items->data);
2689 fprintf(STDERR, "vos: server '%s' not found in host table\n",
2690 as->parms[1].items->data);
2693 part = volutil_GetPartitionID(as->parms[2].items->data);
2695 fprintf(STDERR, "vos: could not interpret partition name '%s'\n",
2696 as->parms[2].items->data);
2699 if (!IsPartValid(part, server, &code)) { /*check for validity of the partition */
2701 PrintError("", code);
2704 "vos : partition %s does not exist on the server\n",
2705 as->parms[2].items->data);
2709 code = GetVolumeInfo(volid, &server, &part, &voltype, &entry);
2715 if (as->parms[3].items) {
2716 volname = as->parms[3].items->data;
2717 if (strlen(volname) > VOLSER_OLDMAXVOLNAME - 1) {
2719 "vos: the name of the root volume %s exceeds the size limit of %d\n",
2720 volname, VOLSER_OLDMAXVOLNAME - 1);
2725 * In order that you be able to make clones of RO or BK, this
2726 * check must be omitted.
2728 if (!VolNameOK(volname)) {
2730 "Illegal volume name %s, should not end in .readonly or .backup\n",
2735 if (IsNumeric(volname)) {
2737 "Illegal volume name %s, should not be a number\n",
2744 if (as->parms[4].items) {
2745 cloneid = vsu_GetVolumeID(as->parms[4].items->data, cstruct, &err);
2748 PrintError("", err);
2750 fprintf(STDERR, "vos: can't find volume ID or name '%s'\n",
2751 as->parms[4].items->data);
2757 if (as->parms[5].items) flags |= RV_OFFLINE;
2758 if (as->parms[6].items) flags |= RV_RDONLY;
2762 UV_CloneVolume(server, part, volid, cloneid, volname, flags);
2765 PrintDiagnostics("clone", code);
2768 MapPartIdIntoName(part, partName);
2769 fprintf(STDOUT, "Created clone for volume %s\n",
2770 as->parms[0].items->data);
2777 BackupVolume(struct cmd_syndesc *as, void *arock)
2781 afs_int32 apart, vtype, code, err;
2782 struct uvldbentry entry;
2785 afs_uint32 buserver;
2786 afs_int32 bupart, butype;
2787 struct uvldbentry buentry;
2789 avolid = vsu_GetVolumeID(as->parms[0].items->data, cstruct, &err);
2792 PrintError("", err);
2794 fprintf(STDERR, "vos: can't find volume ID or name '%s'\n",
2795 as->parms[0].items->data);
2798 code = GetVolumeInfo(avolid, &aserver, &apart, &vtype, &entry);
2802 /* verify this is a readwrite volume */
2804 if (vtype != RWVOL) {
2805 fprintf(STDERR, "%s not RW volume\n", as->parms[0].items->data);
2809 /* is there a backup volume already? */
2811 if (entry.flags & BACK_EXISTS) {
2812 /* yep, where is it? */
2814 buvolid = entry.volumeId[BACKVOL];
2815 code = GetVolumeInfo(buvolid, &buserver, &bupart, &butype, &buentry);
2820 code = VLDB_IsSameAddrs(buserver, aserver, &err);
2823 "Failed to get info about server's %d address(es) from vlserver; aborting call!\n",
2829 "FATAL ERROR: backup volume %lu exists on server %lu\n",
2830 (unsigned long)buvolid, (unsigned long)buserver);
2835 /* nope, carry on */
2837 code = UV_BackupVolume(aserver, apart, avolid);
2840 PrintDiagnostics("backup", code);
2843 fprintf(STDOUT, "Created backup volume for %s \n",
2844 as->parms[0].items->data);
2849 ReleaseVolume(struct cmd_syndesc *as, void *arock)
2852 struct uvldbentry entry;
2855 afs_int32 apart, vtype, code, err;
2858 if (as->parms[1].items)
2860 avolid = vsu_GetVolumeID(as->parms[0].items->data, cstruct, &err);
2863 PrintError("", err);
2865 fprintf(STDERR, "vos: can't find volume '%s'\n",
2866 as->parms[0].items->data);
2869 code = GetVolumeInfo(avolid, &aserver, &apart, &vtype, &entry);
2873 if (vtype != RWVOL) {
2874 fprintf(STDERR, "%s not a RW volume\n", as->parms[0].items->data);
2878 if (!ISNAMEVALID(entry.name)) {
2880 "Volume name %s is too long, rename before releasing\n",
2885 code = UV_ReleaseVolume(avolid, aserver, apart, force);
2887 PrintDiagnostics("release", code);
2890 fprintf(STDOUT, "Released volume %s successfully\n",
2891 as->parms[0].items->data);
2896 DumpVolumeCmd(struct cmd_syndesc *as, void *arock)
2900 afs_int32 apart, voltype, fromdate = 0, code, err, i, flags;
2901 char filename[MAXPATHLEN];
2902 struct uvldbentry entry;
2904 rx_SetRxDeadTime(60 * 10);
2905 for (i = 0; i < MAXSERVERS; i++) {
2906 struct rx_connection *rxConn = ubik_GetRPCConn(cstruct, i);
2909 rx_SetConnDeadTime(rxConn, rx_connDeadTime);
2910 if (rxConn->service)
2911 rxConn->service->connDeadTime = rx_connDeadTime;
2914 avolid = vsu_GetVolumeID(as->parms[0].items->data, cstruct, &err);
2917 PrintError("", err);
2919 fprintf(STDERR, "vos: can't find volume '%s'\n",
2920 as->parms[0].items->data);
2924 if (as->parms[3].items || as->parms[4].items) {
2925 if (!as->parms[3].items || !as->parms[4].items) {
2927 "Must specify both -server and -partition options\n");
2930 aserver = GetServer(as->parms[3].items->data);
2932 fprintf(STDERR, "Invalid server name\n");
2935 apart = volutil_GetPartitionID(as->parms[4].items->data);
2937 fprintf(STDERR, "Invalid partition name\n");
2941 code = GetVolumeInfo(avolid, &aserver, &apart, &voltype, &entry);
2946 if (as->parms[1].items && strcmp(as->parms[1].items->data, "0")) {
2947 code = ktime_DateToInt32(as->parms[1].items->data, &fromdate);
2949 fprintf(STDERR, "vos: failed to parse date '%s' (error=%d))\n",
2950 as->parms[1].items->data, code);
2954 if (as->parms[2].items) {
2955 strcpy(filename, as->parms[2].items->data);
2957 strcpy(filename, "");
2960 flags = as->parms[6].items ? VOLDUMPV2_OMITDIRS : 0;
2962 if (as->parms[5].items) {
2964 UV_DumpClonedVolume(avolid, aserver, apart, fromdate,
2965 DumpFunction, filename, flags);
2968 UV_DumpVolume(avolid, aserver, apart, fromdate, DumpFunction,
2971 if ((code == RXGEN_OPCODE) && (as->parms[6].items)) {
2972 flags &= ~VOLDUMPV2_OMITDIRS;
2976 PrintDiagnostics("dump", code);
2979 if (strcmp(filename, ""))
2980 fprintf(STDERR, "Dumped volume %s in file %s\n",
2981 as->parms[0].items->data, filename);
2983 fprintf(STDERR, "Dumped volume %s in stdout \n",
2984 as->parms[0].items->data);
2998 RestoreVolumeCmd(struct cmd_syndesc *as, void *arock)
3000 afs_uint32 avolid, aparentid;
3002 afs_int32 apart, code, vcode, err;
3003 afs_int32 aoverwrite = ASK;
3004 afs_int32 acreation = 0, alastupdate = 0;
3005 int restoreflags = 0;
3006 int readonly = 0, offline = 0, voltype = RWVOL;
3007 char afilename[MAXPATHLEN], avolname[VOLSER_MAXVOLNAME + 1], apartName[10];
3008 char volname[VOLSER_MAXVOLNAME + 1];
3009 struct uvldbentry entry;
3012 if (as->parms[4].items) {
3013 avolid = vsu_GetVolumeID(as->parms[4].items->data, cstruct, &err);
3016 PrintError("", err);
3018 fprintf(STDERR, "vos: can't find volume '%s'\n",
3019 as->parms[4].items->data);
3025 if (as->parms[5].items) {
3026 if ((strcmp(as->parms[5].items->data, "a") == 0)
3027 || (strcmp(as->parms[5].items->data, "abort") == 0)) {
3029 } else if ((strcmp(as->parms[5].items->data, "f") == 0)
3030 || (strcmp(as->parms[5].items->data, "full") == 0)) {
3032 } else if ((strcmp(as->parms[5].items->data, "i") == 0)
3033 || (strcmp(as->parms[5].items->data, "inc") == 0)
3034 || (strcmp(as->parms[5].items->data, "increment") == 0)
3035 || (strcmp(as->parms[5].items->data, "incremental") == 0)) {
3038 fprintf(STDERR, "vos: %s is not a valid argument to -overwrite\n",
3039 as->parms[5].items->data);
3043 if (as->parms[6].items)
3045 if (as->parms[7].items) {
3050 if (as->parms[8].items) {
3051 if ((strcmp(as->parms[8].items->data, "d") == 0)
3052 || (strcmp(as->parms[8].items->data, "dump") == 0)) {
3053 acreation = TS_DUMP;
3054 } else if ((strcmp(as->parms[8].items->data, "k") == 0)
3055 || (strcmp(as->parms[8].items->data, "keep") == 0)) {
3056 acreation = TS_KEEP;
3057 } else if ((strcmp(as->parms[8].items->data, "n") == 0)
3058 || (strcmp(as->parms[8].items->data, "new") == 0)) {
3061 fprintf(STDERR, "vos: %s is not a valid argument to -creation\n",
3062 as->parms[8].items->data);
3067 if (as->parms[9].items) {
3068 if ((strcmp(as->parms[9].items->data, "d") == 0)
3069 || (strcmp(as->parms[9].items->data, "dump") == 0)) {
3070 alastupdate = TS_DUMP;
3071 } else if ((strcmp(as->parms[9].items->data, "k") == 0)
3072 || (strcmp(as->parms[9].items->data, "keep") == 0)) {
3073 alastupdate = TS_KEEP;
3074 } else if ((strcmp(as->parms[9].items->data, "n") == 0)
3075 || (strcmp(as->parms[9].items->data, "new") == 0)) {
3076 alastupdate = TS_NEW;
3078 fprintf(STDERR, "vos: %s is not a valid argument to -lastupdate\n",
3079 as->parms[9].items->data);
3084 aserver = GetServer(as->parms[0].items->data);
3086 fprintf(STDERR, "vos: server '%s' not found in host table\n",
3087 as->parms[0].items->data);
3090 apart = volutil_GetPartitionID(as->parms[1].items->data);
3092 fprintf(STDERR, "vos: could not interpret partition name '%s'\n",
3093 as->parms[1].items->data);
3096 if (!IsPartValid(apart, aserver, &code)) { /*check for validity of the partition */
3098 PrintError("", code);
3101 "vos : partition %s does not exist on the server\n",
3102 as->parms[1].items->data);
3105 strcpy(avolname, as->parms[2].items->data);
3106 if (!ISNAMEVALID(avolname)) {
3108 "vos: the name of the volume %s exceeds the size limit\n",
3112 if (!VolNameOK(avolname)) {
3114 "Illegal volume name %s, should not end in .readonly or .backup\n",
3118 if (as->parms[3].items) {
3119 strcpy(afilename, as->parms[3].items->data);
3120 if (!FileExists(afilename)) {
3121 fprintf(STDERR, "Can't access file %s\n", afilename);
3125 strcpy(afilename, "");
3128 /* Check if volume exists or not */
3130 vsu_ExtractName(volname, avolname);
3131 vcode = VLDB_GetEntryByNameU(volname, &entry);
3132 if (vcode) { /* no volume - do a full restore */
3133 restoreflags = RV_FULLRST;
3134 if ((aoverwrite == INC) || (aoverwrite == ABORT))
3136 "Volume does not exist; Will perform a full restore\n");
3139 else if ((!readonly && Lp_GetRwIndexU(&entry) == -1) /* RW volume does not exist - do a full */
3140 ||(readonly && !Lp_ROMatchU(0, 0, &entry))) { /* RO volume does not exist - do a full */
3141 restoreflags = RV_FULLRST;
3142 if ((aoverwrite == INC) || (aoverwrite == ABORT))
3144 "%s Volume does not exist; Will perform a full restore\n",
3145 readonly ? "RO" : "RW");
3148 avolid = entry.volumeId[voltype];
3149 } else if (entry.volumeId[voltype] != 0
3150 && entry.volumeId[voltype] != avolid) {
3151 avolid = entry.volumeId[voltype];
3153 aparentid = entry.volumeId[RWVOL];
3156 else { /* volume exists - do we do a full incremental or abort */
3158 afs_int32 Opart, Otype, vol_elsewhere = 0;
3159 struct uvldbentry Oentry;
3163 avolid = entry.volumeId[voltype];
3164 } else if (entry.volumeId[voltype] != 0
3165 && entry.volumeId[voltype] != avolid) {
3166 avolid = entry.volumeId[voltype];
3168 aparentid = entry.volumeId[RWVOL];
3170 /* A file name was specified - check if volume is on another partition */
3171 vcode = GetVolumeInfo(avolid, &Oserver, &Opart, &Otype, &Oentry);
3175 vcode = VLDB_IsSameAddrs(Oserver, aserver, &err);
3178 "Failed to get info about server's %d address(es) from vlserver (err=%d); aborting call!\n",
3182 if (!vcode || (Opart != apart))
3185 if (aoverwrite == ASK) {
3186 if (strcmp(afilename, "") == 0) { /* The file is from standard in */
3188 "Volume exists and no -overwrite option specified; Aborting restore command\n");
3192 /* Ask what to do */
3193 if (vol_elsewhere) {
3195 "The volume %s %u already exists on a different server/part\n",
3196 volname, entry.volumeId[voltype]);
3198 "Do you want to do a full restore or abort? [fa](a): ");
3201 "The volume %s %u already exists in the VLDB\n",
3202 volname, entry.volumeId[voltype]);
3204 "Do you want to do a full/incremental restore or abort? [fia](a): ");
3207 while (!(dc == EOF || dc == '\n'))
3208 dc = getchar(); /* goto end of line */
3209 if ((c == 'f') || (c == 'F'))
3211 else if ((c == 'i') || (c == 'I'))
3217 if (aoverwrite == ABORT) {
3218 fprintf(STDERR, "Volume exists; Aborting restore command\n");
3220 } else if (aoverwrite == FULL) {
3221 restoreflags = RV_FULLRST;
3223 "Volume exists; Will delete and perform full restore\n");
3224 } else if (aoverwrite == INC) {
3226 if (vol_elsewhere) {
3228 "%s volume %lu already exists on a different server/part; not allowed\n",
3229 readonly ? "RO" : "RW", (unsigned long)avolid);
3235 restoreflags |= RV_OFFLINE;
3237 restoreflags |= RV_RDONLY;
3239 switch (acreation) {
3241 restoreflags |= RV_CRDUMP;
3244 restoreflags |= RV_CRKEEP;
3247 restoreflags |= RV_CRNEW;
3250 if (aoverwrite == FULL)
3251 restoreflags |= RV_CRNEW;
3253 restoreflags |= RV_CRKEEP;
3256 switch (alastupdate) {
3258 restoreflags |= RV_LUDUMP;
3261 restoreflags |= RV_LUKEEP;
3264 restoreflags |= RV_LUNEW;
3267 restoreflags |= RV_LUDUMP;
3269 if (as->parms[10].items) {
3270 restoreflags |= RV_NODEL;
3275 UV_RestoreVolume2(aserver, apart, avolid, aparentid,
3276 avolname, restoreflags, WriteData, afilename);
3278 PrintDiagnostics("restore", code);
3281 MapPartIdIntoName(apart, apartName);
3284 * patch typo here - originally "parms[1]", should be "parms[0]"
3287 fprintf(STDOUT, "Restored volume %s on %s %s\n", avolname,
3288 as->parms[0].items->data, apartName);
3293 LockReleaseCmd(struct cmd_syndesc *as, void *arock)
3296 afs_int32 code, err;
3298 avolid = vsu_GetVolumeID(as->parms[0].items->data, cstruct, &err);
3301 PrintError("", err);
3303 fprintf(STDERR, "vos: can't find volume '%s'\n",
3304 as->parms[0].items->data);
3308 code = UV_LockRelease(avolid);
3310 PrintDiagnostics("unlock", code);
3313 fprintf(STDOUT, "Released lock on vldb entry for volume %s\n",
3314 as->parms[0].items->data);
3319 AddSite(struct cmd_syndesc *as, void *arock)
3323 afs_int32 apart, code, err, arovolid, valid = 0;
3324 char apartName[10], avolname[VOLSER_MAXVOLNAME + 1];
3326 vsu_ExtractName(avolname, as->parms[2].items->data);;
3327 avolid = vsu_GetVolumeID(avolname, cstruct, &err);
3330 PrintError("", err);
3332 fprintf(STDERR, "vos: can't find volume '%s'\n",
3333 as->parms[2].items->data);
3337 if (as->parms[3].items) {
3338 vsu_ExtractName(avolname, as->parms[3].items->data);
3339 arovolid = vsu_GetVolumeID(avolname, cstruct, &err);
3341 fprintf(STDERR, "vos: invalid ro volume id '%s'\n",
3342 as->parms[3].items->data);
3346 aserver = GetServer(as->parms[0].items->data);
3348 fprintf(STDERR, "vos: server '%s' not found in host table\n",
3349 as->parms[0].items->data);
3352 apart = volutil_GetPartitionID(as->parms[1].items->data);
3354 fprintf(STDERR, "vos: could not interpret partition name '%s'\n",
3355 as->parms[1].items->data);
3358 if (!IsPartValid(apart, aserver, &code)) { /*check for validity of the partition */
3360 PrintError("", code);
3363 "vos : partition %s does not exist on the server\n",
3364 as->parms[1].items->data);
3367 if (as->parms[4].items) {
3370 code = UV_AddSite2(aserver, apart, avolid, arovolid, valid);
3372 PrintDiagnostics("addsite", code);
3375 MapPartIdIntoName(apart, apartName);
3376 fprintf(STDOUT, "Added replication site %s %s for volume %s\n",
3377 as->parms[0].items->data, apartName, as->parms[2].items->data);
3382 RemoveSite(struct cmd_syndesc *as, void *arock)
3387 afs_int32 apart, code, err;
3388 char apartName[10], avolname[VOLSER_MAXVOLNAME + 1];
3390 vsu_ExtractName(avolname, as->parms[2].items->data);
3391 avolid = vsu_GetVolumeID(avolname, cstruct, &err);
3394 PrintError("", err);
3396 fprintf(STDERR, "vos: can't find volume '%s'\n",
3397 as->parms[2].items->data);
3400 aserver = GetServer(as->parms[0].items->data);
3402 fprintf(STDERR, "vos: server '%s' not found in host table\n",
3403 as->parms[0].items->data);
3406 apart = volutil_GetPartitionID(as->parms[1].items->data);
3408 fprintf(STDERR, "vos: could not interpret partition name '%s'\n",
3409 as->parms[1].items->data);
3413 *skip the partition validity check, since it is possible that the partition
3414 *has since been decomissioned.
3417 if (!IsPartValid(apart,aserver,&code)){
3418 if(code) PrintError("",code);
3419 else fprintf(STDERR,"vos : partition %s does not exist on the server\n",as->parms[1].items->data);
3423 code = UV_RemoveSite(aserver, apart, avolid);
3425 PrintDiagnostics("remsite", code);
3428 MapPartIdIntoName(apart, apartName);
3429 fprintf(STDOUT, "Removed replication site %s %s for volume %s\n",
3430 as->parms[0].items->data, apartName, as->parms[2].items->data);
3435 ChangeLocation(struct cmd_syndesc *as, void *arock)
3439 afs_int32 apart, code, err;
3442 avolid = vsu_GetVolumeID(as->parms[2].items->data, cstruct, &err);
3445 PrintError("", err);
3447 fprintf(STDERR, "vos: can't find volume '%s'\n",
3448 as->parms[2].items->data);
3451 aserver = GetServer(as->parms[0].items->data);
3453 fprintf(STDERR, "vos: server '%s' not found in host table\n",
3454 as->parms[0].items->data);
3457 apart = volutil_GetPartitionID(as->parms[1].items->data);
3459 fprintf(STDERR, "vos: could not interpret partition name '%s'\n",
3460 as->parms[1].items->data);
3463 if (!IsPartValid(apart, aserver, &code)) { /*check for validity of the partition */
3465 PrintError("", code);
3468 "vos : partition %s does not exist on the server\n",
3469 as->parms[1].items->data);
3472 code = UV_ChangeLocation(aserver, apart, avolid);
3474 PrintDiagnostics("addsite", code);
3477 MapPartIdIntoName(apart, apartName);
3478 fprintf(STDOUT, "Changed location to %s %s for volume %s\n",
3479 as->parms[0].items->data, apartName, as->parms[2].items->data);
3484 ListPartitions(struct cmd_syndesc *as, void *arock)
3488 struct partList dummyPartList;
3493 aserver = GetServer(as->parms[0].items->data);
3495 fprintf(STDERR, "vos: server '%s' not found in host table\n",
3496 as->parms[0].items->data);
3501 code = UV_ListPartitions(aserver, &dummyPartList, &cnt);
3503 PrintDiagnostics("listpart", code);
3507 fprintf(STDOUT, "The partitions on the server are:\n");
3508 for (i = 0; i < cnt; i++) {
3509 if (dummyPartList.partFlags[i] & PARTVALID) {
3510 memset(pname, 0, sizeof(pname));
3511 MapPartIdIntoName(dummyPartList.partId[i], pname);
3512 fprintf(STDOUT, " %10s ", pname);
3514 if ((i % 5) == 0 && (i != 0))
3515 fprintf(STDOUT, "\n");
3518 fprintf(STDOUT, "\n");
3519 fprintf(STDOUT, "Total: %d\n", total);
3525 CompareVolName(const void *p1, const void *p2)
3527 volintInfo *arg1, *arg2;
3529 arg1 = (volintInfo *) p1;
3530 arg2 = (volintInfo *) p2;
3531 return (strcmp(arg1->name, arg2->name));
3535 /*------------------------------------------------------------------------
3536 * PRIVATE XCompareVolName
3539 * Comparison routine for volume names coming from an extended
3543 * a_obj1P : Char ptr to first extended vol info object
3544 * a_obj1P : Char ptr to second extended vol info object
3547 * The value of strcmp() on the volume names within the passed
3548 * objects (i,e., -1, 0, or 1).
3551 * Passed to qsort() as the designated comparison routine.
3555 *------------------------------------------------------------------------*/
3558 XCompareVolName(const void *a_obj1P, const void *a_obj2P)
3559 { /*XCompareVolName */
3562 (((struct volintXInfo *)(a_obj1P))->name,
3563 ((struct volintXInfo *)(a_obj2P))->name));
3565 } /*XCompareVolName */
3568 CompareVolID(const void *p1, const void *p2)
3570 volintInfo *arg1, *arg2;
3572 arg1 = (volintInfo *) p1;
3573 arg2 = (volintInfo *) p2;
3574 if (arg1->volid == arg2->volid)
3576 if (arg1->volid > arg2->volid)
3583 /*------------------------------------------------------------------------
3584 * PRIVATE XCompareVolID
3587 * Comparison routine for volume IDs coming from an extended
3591 * a_obj1P : Char ptr to first extended vol info object
3592 * a_obj1P : Char ptr to second extended vol info object
3595 * The value of strcmp() on the volume names within the passed
3596 * objects (i,e., -1, 0, or 1).
3599 * Passed to qsort() as the designated comparison routine.
3603 *------------------------------------------------------------------------*/
3606 XCompareVolID(const void *a_obj1P, const void *a_obj2P)
3607 { /*XCompareVolID */
3609 afs_int32 id1, id2; /*Volume IDs we're comparing */
3611 id1 = ((struct volintXInfo *)(a_obj1P))->volid;
3612 id2 = ((struct volintXInfo *)(a_obj2P))->volid;
3620 } /*XCompareVolID */
3622 /*------------------------------------------------------------------------
3623 * PRIVATE ListVolumes
3626 * Routine used to list volumes, contacting the Volume Server
3627 * directly, bypassing the VLDB.
3630 * as : Ptr to parsed command line arguments.
3633 * 0 Successful operation
3636 * Nothing interesting.
3640 *------------------------------------------------------------------------*/
3643 ListVolumes(struct cmd_syndesc *as, void *arock)
3645 afs_int32 apart, int32list, fast;
3649 volintInfo *oldpntr = NULL;
3653 volintXInfo *xInfoP;
3654 volintXInfo *origxInfoP = NULL; /*Ptr to current/orig extended vol info */
3655 int wantExtendedInfo; /*Do we want extended vol info? */
3658 struct partList dummyPartList;
3666 if (as->parms[3].items)
3668 if (as->parms[4].items)
3672 if (as->parms[2].items)
3678 if (as->parms[5].items) {
3680 * We can't coexist with the fast flag.
3684 "vos: Can't use the -fast and -extended flags together\n");
3689 * We need to turn on ``long'' listings to get the full effect.
3691 wantExtendedInfo = 1;
3694 wantExtendedInfo = 0;
3695 if (as->parms[1].items) {
3696 apart = volutil_GetPartitionID(as->parms[1].items->data);
3698 fprintf(STDERR, "vos: could not interpret partition name '%s'\n",
3699 as->parms[1].items->data);
3702 dummyPartList.partId[0] = apart;
3703 dummyPartList.partFlags[0] = PARTVALID;
3706 aserver = GetServer(as->parms[0].items->data);
3708 fprintf(STDERR, "vos: server '%s' not found in host table\n",
3709 as->parms[0].items->data);
3714 if (!IsPartValid(apart, aserver, &code)) { /*check for validity of the partition */
3716 PrintError("", code);
3719 "vos : partition %s does not exist on the server\n",
3720 as->parms[1].items->data);
3724 code = UV_ListPartitions(aserver, &dummyPartList, &cnt);
3726 PrintDiagnostics("listvol", code);
3730 for (i = 0; i < cnt; i++) {
3731 if (dummyPartList.partFlags[i] & PARTVALID) {
3732 if (wantExtendedInfo)
3734 UV_XListVolumes(aserver, dummyPartList.partId[i], all,
3738 UV_ListVolumes(aserver, dummyPartList.partId[i], all,
3741 PrintDiagnostics("listvol", code);
3746 if (wantExtendedInfo) {
3747 origxInfoP = xInfoP;
3748 base = (char *)xInfoP;
3751 base = (char *)pntr;
3755 if (wantExtendedInfo)
3756 qsort(base, count, sizeof(volintXInfo), XCompareVolName);
3758 qsort(base, count, sizeof(volintInfo), CompareVolName);
3760 if (wantExtendedInfo)
3761 qsort(base, count, sizeof(volintXInfo), XCompareVolID);
3763 qsort(base, count, sizeof(volintInfo), CompareVolID);
3765 MapPartIdIntoName(dummyPartList.partId[i], pname);
3768 "Total number of volumes on server %s partition %s: %lu \n",
3769 as->parms[0].items->data, pname,
3770 (unsigned long)count);
3771 if (wantExtendedInfo) {
3772 if (as->parms[6].items)
3773 XDisplayVolumes2(aserver, dummyPartList.partId[i], origxInfoP,
3774 count, int32list, fast, quiet);
3776 XDisplayVolumes(aserver, dummyPartList.partId[i], origxInfoP,
3777 count, int32list, fast, quiet);
3780 xInfoP = (volintXInfo *) 0;
3782 if (as->parms[6].items)
3783 DisplayVolumes2(aserver, dummyPartList.partId[i], oldpntr,
3786 DisplayVolumes(aserver, dummyPartList.partId[i], oldpntr,
3787 count, int32list, fast, quiet);
3790 pntr = (volintInfo *) 0;
3798 SyncVldb(struct cmd_syndesc *as, void *arock)
3800 afs_int32 pnum = 0, code; /* part name */
3806 if (as->parms[0].items) {
3807 tserver = GetServer(as->parms[0].items->data);
3809 fprintf(STDERR, "vos: host '%s' not found in host table\n",
3810 as->parms[0].items->data);
3815 if (as->parms[1].items) {
3816 pnum = volutil_GetPartitionID(as->parms[1].items->data);
3818 fprintf(STDERR, "vos: could not interpret partition name '%s'\n",
3819 as->parms[1].items->data);
3822 if (!IsPartValid(pnum, tserver, &code)) { /*check for validity of the partition */
3824 PrintError("", code);
3827 "vos: partition %s does not exist on the server\n",
3828 as->parms[1].items->data);
3835 "The -partition option requires a -server option\n");
3840 if (as->parms[3].items) {
3841 flags |= 2; /* don't update */
3844 if (as->parms[2].items) {
3845 /* Synchronize an individual volume */
3846 volname = as->parms[2].items->data;
3847 code = UV_SyncVolume(tserver, pnum, volname, flags);
3851 "Without a -volume option, the -server option is required\n");
3854 code = UV_SyncVldb(tserver, pnum, flags, 0 /*unused */ );
3858 PrintDiagnostics("syncvldb", code);
3862 /* Print a summary of what we did */
3864 fprintf(STDOUT, "VLDB volume %s synchronized", volname);
3866 fprintf(STDOUT, "VLDB synchronized");
3868 fprintf(STDOUT, " with state of server %s", as->parms[0].items->data);
3871 MapPartIdIntoName(pnum, part);
3872 fprintf(STDOUT, " partition %s\n", part);
3874 fprintf(STDOUT, "\n");
3880 SyncServer(struct cmd_syndesc *as, void *arock)
3882 afs_int32 pnum, code; /* part name */
3887 tserver = GetServer(as->parms[0].items->data);
3889 fprintf(STDERR, "vos: host '%s' not found in host table\n",
3890 as->parms[0].items->data);
3893 if (as->parms[1].items) {
3894 pnum = volutil_GetPartitionID(as->parms[1].items->data);
3896 fprintf(STDERR, "vos: could not interpret partition name '%s'\n",
3897 as->parms[1].items->data);
3900 if (!IsPartValid(pnum, tserver, &code)) { /*check for validity of the partition */
3902 PrintError("", code);
3905 "vos : partition %s does not exist on the server\n",
3906 as->parms[1].items->data);
3914 if (as->parms[2].items) {
3915 flags |= 2; /* don't update */
3917 code = UV_SyncServer(tserver, pnum, flags, 0 /*unused */ );
3919 PrintDiagnostics("syncserv", code);
3923 MapPartIdIntoName(pnum, part);
3924 fprintf(STDOUT, "Server %s partition %s synchronized with VLDB\n",
3925 as->parms[0].items->data, part);
3927 fprintf(STDOUT, "Server %s synchronized with VLDB\n",
3928 as->parms[0].items->data);
3934 VolumeInfoCmd(char *name)
3936 struct uvldbentry entry;
3939 /* The vlserver will handle names with the .readonly
3940 * and .backup extension as well as volume ids.
3942 vcode = VLDB_GetEntryByNameU(name, &entry);
3944 PrintError("", vcode);
3947 MapHostToNetworkU(&entry);
3948 EnumerateEntryU(&entry);
3950 /* Defect #3027: grubby check to handle locked volume.
3951 * If VLOP_ALLOPERS is set, the entry is locked.
3952 * Leave this routine as is, but put in correct check.
3954 PrintLocked(entry.flags);
3960 VolumeZap(struct cmd_syndesc *as, void *arock)
3962 struct uvldbentry entry;
3963 afs_uint32 volid, zapbackupid = 0, backupid = 0;
3964 afs_int32 code, server, part, err;
3966 if (as->parms[3].items) {
3967 /* force flag is on, use the other version */
3968 return NukeVolume(as);
3971 if (as->parms[4].items) {
3975 volid = vsu_GetVolumeID(as->parms[2].items->data, cstruct, &err);
3978 PrintError("", err);
3980 fprintf(STDERR, "vos: can't find volume '%s'\n",
3981 as->parms[2].items->data);
3984 part = volutil_GetPartitionID(as->parms[1].items->data);
3986 fprintf(STDERR, "vos: could not interpret partition name '%s'\n",
3987 as->parms[1].items->data);
3990 server = GetServer(as->parms[0].items->data);
3992 fprintf(STDERR, "vos: host '%s' not found in host table\n",
3993 as->parms[0].items->data);
3996 if (!IsPartValid(part, server, &code)) { /*check for validity of the partition */
3998 PrintError("", code);
4001 "vos : partition %s does not exist on the server\n",
4002 as->parms[1].items->data);
4005 code = VLDB_GetEntryByIDU(volid, -1, &entry);
4007 if (volid == entry.volumeId[RWVOL])
4008 backupid = entry.volumeId[BACKVOL];
4010 "Warning: Entry for volume number %lu exists in VLDB (but we're zapping it anyway!)\n",
4011 (unsigned long)volid);
4014 volintInfo *pntr = (volintInfo *) 0;
4017 code = UV_ListOneVolume(server, part, volid, &pntr);
4019 if (volid == pntr->parentID)
4020 backupid = pntr->backupID;
4026 code = UV_VolumeZap(server, part, backupid);
4028 PrintDiagnostics("zap", code);
4031 fprintf(STDOUT, "Backup Volume %lu deleted\n",
4032 (unsigned long)backupid);
4035 code = UV_VolumeZap(server, part, volid);
4037 PrintDiagnostics("zap", code);
4040 fprintf(STDOUT, "Volume %lu deleted\n", (unsigned long)volid);
4046 VolserStatus(struct cmd_syndesc *as, void *arock)
4050 transDebugInfo *pntr, *oldpntr;
4056 server = GetServer(as->parms[0].items->data);
4058 fprintf(STDERR, "vos: host '%s' not found in host table\n",
4059 as->parms[0].items->data);
4062 code = UV_VolserStatus(server, &pntr, &count);
4064 PrintDiagnostics("status", code);
4069 fprintf(STDOUT, "No active transactions on %s\n",
4070 as->parms[0].items->data);
4072 fprintf(STDOUT, "Total transactions: %d\n", count);
4074 for (i = 0; i < count; i++) {
4075 /*print out the relevant info */
4076 fprintf(STDOUT, "--------------------------------------\n");
4077 t = pntr->creationTime;
4078 fprintf(STDOUT, "transaction: %lu created: %s",
4079 (unsigned long)pntr->tid, ctime(&t));
4081 fprintf(STDOUT, "lastActiveTime: %s", ctime(&t));
4082 if (pntr->returnCode) {
4083 fprintf(STDOUT, "returnCode: %lu\n",
4084 (unsigned long)pntr->returnCode);
4087 fprintf(STDOUT, "attachFlags: ");
4088 switch (pntr->iflags) {
4090 fprintf(STDOUT, "offline ");
4093 fprintf(STDOUT, "busy ");
4096 fprintf(STDOUT, "readonly ");
4099 fprintf(STDOUT, "create ");
4102 fprintf(STDOUT, "create volid ");
4105 fprintf(STDOUT, "\n");
4108 fprintf(STDOUT, "volumeStatus: ");
4109 switch (pntr->vflags) {
4110 case VTDeleteOnSalvage:
4111 fprintf(STDOUT, "deleteOnSalvage ");
4112 case VTOutOfService:
4113 fprintf(STDOUT, "outOfService ");
4115 fprintf(STDOUT, "deleted ");
4117 fprintf(STDOUT, "\n");
4120 fprintf(STDOUT, "transactionFlags: ");
4121 fprintf(STDOUT, "delete\n");
4123 MapPartIdIntoName(pntr->partition, pname);
4124 fprintf(STDOUT, "volume: %lu partition: %s procedure: %s\n",
4125 (unsigned long)pntr->volid, pname, pntr->lastProcName);
4126 if (pntr->callValid) {
4127 t = pntr->lastReceiveTime;
4128 fprintf(STDOUT, "packetRead: %lu lastReceiveTime: %s",
4129 (unsigned long)pntr->readNext, ctime(&t));
4130 t = pntr->lastSendTime;
4131 fprintf(STDOUT, "packetSend: %lu lastSendTime: %s",
4132 (unsigned long)pntr->transmitNext, ctime(&t));
4135 fprintf(STDOUT, "--------------------------------------\n");
4136 fprintf(STDOUT, "\n");
4144 RenameVolume(struct cmd_syndesc *as, void *arock)
4146 afs_int32 code1, code2, code;
4147 struct uvldbentry entry;
4149 code1 = VLDB_GetEntryByNameU(as->parms[0].items->data, &entry);
4151 fprintf(STDERR, "vos: Could not find entry for volume %s\n",
4152 as->parms[0].items->data);
4155 code2 = VLDB_GetEntryByNameU(as->parms[1].items->data, &entry);
4156 if ((!code1) && (!code2)) { /*the newname already exists */
4157 fprintf(STDERR, "vos: volume %s already exists\n",
4158 as->parms[1].items->data);
4162 if (code1 && code2) {
4163 fprintf(STDERR, "vos: Could not find entry for volume %s or %s\n",
4164 as->parms[0].items->data, as->parms[1].items->data);
4167 if (!VolNameOK(as->parms[0].items->data)) {
4169 "Illegal volume name %s, should not end in .readonly or .backup\n",
4170 as->parms[0].items->data);
4173 if (!ISNAMEVALID(as->parms[1].items->data)) {
4175 "vos: the new volume name %s exceeds the size limit of %d\n",
4176 as->parms[1].items->data, VOLSER_OLDMAXVOLNAME - 10);
4179 if (!VolNameOK(as->parms[1].items->data)) {
4181 "Illegal volume name %s, should not end in .readonly or .backup\n",
4182 as->parms[1].items->data);
4185 if (IsNumeric(as->parms[1].items->data)) {
4186 fprintf(STDERR, "Illegal volume name %s, should not be a number\n",
4187 as->parms[1].items->data);
4190 MapHostToNetworkU(&entry);
4192 UV_RenameVolumeU(&entry, as->parms[0].items->data,
4193 as->parms[1].items->data);
4195 PrintDiagnostics("rename", code);
4198 fprintf(STDOUT, "Renamed volume %s to %s\n", as->parms[0].items->data,
4199 as->parms[1].items->data);
4204 GetVolumeInfo(afs_uint32 volid, afs_uint32 *server, afs_int32 *part, afs_int32 *voltype,
4205 struct uvldbentry *rentry)
4210 vcode = VLDB_GetEntryByIDU(volid, -1, rentry);
4213 "Could not fetch the entry for volume %lu from VLDB \n",
4214 (unsigned long)volid);
4215 PrintError("", vcode);
4218 MapHostToNetworkU(rentry);
4219 if (volid == rentry->volumeId[ROVOL]) {
4221 for (i = 0; i < rentry->nServers; i++) {
4222 if ((index == -1) && (rentry->serverFlags[i] & ITSROVOL)
4223 && !(rentry->serverFlags[i] & RO_DONTUSE))
4228 "RO volume is not found in VLDB entry for volume %lu\n",
4229 (unsigned long)volid);
4233 *server = rentry->serverUnique[index];
4234 *part = rentry->serverPartition[index];
4238 index = Lp_GetRwIndexU(rentry);
4241 "RW Volume is not found in VLDB entry for volume %lu\n",
4242 (unsigned long)volid);
4245 if (volid == rentry->volumeId[RWVOL]) {
4247 *server = rentry->serverUnique[index];
4248 *part = rentry->serverPartition[index];
4251 if (volid == rentry->volumeId[BACKVOL]) {
4253 *server = rentry->serverUnique[index];
4254 *part = rentry->serverPartition[index];
4258 "unexpected volume type for volume %lu\n",
4259 (unsigned long)volid);
4264 DeleteEntry(struct cmd_syndesc *as, void *arock)
4266 afs_int32 apart = 0;
4269 struct VldbListByAttributes attributes;
4270 ubulkentries arrayEntries;
4271 struct uvldbentry *vllist;
4272 struct cmd_item *itp;
4275 char prefix[VOLSER_MAXVOLNAME + 1];
4277 afs_int32 totalBack = 0, totalFail = 0, err;
4279 if (as->parms[0].items) { /* -id */
4280 if (as->parms[1].items || as->parms[2].items || as->parms[3].items) {
4282 "You cannot use -server, -partition, or -prefix with the -id argument\n");
4285 for (itp = as->parms[0].items; itp; itp = itp->next) {
4286 avolid = vsu_GetVolumeID(itp->data, cstruct, &err);
4289 PrintError("", err);
4291 fprintf(STDERR, "vos: can't find volume '%s'\n",
4295 if (as->parms[4].items) { /* -noexecute */
4296 fprintf(STDOUT, "Would have deleted VLDB entry for %s \n",
4301 vcode = ubik_VL_DeleteEntry(cstruct, 0, avolid, RWVOL);
4303 fprintf(STDERR, "Could not delete entry for volume %s\n",
4306 "You must specify a RW volume name or ID "
4307 "(the entire VLDB entry will be deleted)\n");
4308 PrintError("", vcode);
4314 fprintf(STDOUT, "Deleted %d VLDB entries\n", totalBack);
4318 if (!as->parms[1].items && !as->parms[2].items && !as->parms[3].items) {
4319 fprintf(STDERR, "You must specify an option\n");
4323 /* Zero out search attributes */
4324 memset(&attributes, 0, sizeof(struct VldbListByAttributes));
4326 if (as->parms[1].items) { /* -prefix */
4327 strncpy(prefix, as->parms[1].items->data, VOLSER_MAXVOLNAME);
4329 if (!as->parms[2].items && !as->parms[3].items) { /* a single entry only */
4331 "You must provide -server with the -prefix argument\n");
4336 if (as->parms[2].items) { /* -server */
4338 aserver = GetServer(as->parms[2].items->data);
4340 fprintf(STDERR, "vos: server '%s' not found in host table\n",
4341 as->parms[2].items->data);
4344 attributes.server = ntohl(aserver);
4345 attributes.Mask |= VLLIST_SERVER;
4348 if (as->parms[3].items) { /* -partition */
4349 if (!as->parms[2].items) {
4351 "You must provide -server with the -partition argument\n");
4354 apart = volutil_GetPartitionID(as->parms[3].items->data);
4356 fprintf(STDERR, "vos: could not interpret partition name '%s'\n",
4357 as->parms[3].items->data);
4360 attributes.partition = apart;
4361 attributes.Mask |= VLLIST_PARTITION;
4364 /* Print status line of what we are doing */
4365 fprintf(STDOUT, "Deleting VLDB entries for ");
4366 if (as->parms[2].items) {
4367 fprintf(STDOUT, "server %s ", as->parms[2].items->data);
4369 if (as->parms[3].items) {
4371 MapPartIdIntoName(apart, pname);
4372 fprintf(STDOUT, "partition %s ", pname);
4375 fprintf(STDOUT, "which are prefixed with %s ", prefix);
4377 fprintf(STDOUT, "\n");
4380 /* Get all the VLDB entries on a server and/or partition */
4381 memset(&arrayEntries, 0, sizeof(arrayEntries));
4382 vcode = VLDB_ListAttributesU(&attributes, &nentries, &arrayEntries);
4384 fprintf(STDERR, "Could not access the VLDB for attributes\n");
4385 PrintError("", vcode);
4389 /* Process each entry */
4390 for (j = 0; j < nentries; j++) {
4391 vllist = &arrayEntries.ubulkentries_val[j];
4393 /* It only deletes the RW volumes */
4394 if (strncmp(vllist->name, prefix, strlen(prefix))) {
4397 "Omitting to delete %s due to prefix %s mismatch\n",
4398 vllist->name, prefix);
4405 if (as->parms[4].items) { /* -noexecute */
4406 fprintf(STDOUT, "Would have deleted VLDB entry for %s \n",
4412 /* Only matches the RW volume name */
4413 avolid = vllist->volumeId[RWVOL];
4414 vcode = ubik_VL_DeleteEntry(cstruct, 0, avolid, RWVOL);
4416 fprintf(STDOUT, "Could not delete VDLB entry for %s\n",
4419 PrintError("", vcode);
4424 fprintf(STDOUT, "Deleted VLDB entry for %s \n", vllist->name);
4429 fprintf(STDOUT, "----------------------\n");
4431 "Total VLDB entries deleted: %lu; failed to delete: %lu\n",
4432 (unsigned long)totalBack, (unsigned long)totalFail);
4433 if (arrayEntries.ubulkentries_val)
4434 free(arrayEntries.ubulkentries_val);
4440 CompareVldbEntryByName(const void *p1, const void *p2)
4442 struct uvldbentry *arg1, *arg2;
4444 arg1 = (struct uvldbentry *)p1;
4445 arg2 = (struct uvldbentry *)p2;
4446 return (strcmp(arg1->name, arg2->name));
4450 static int CompareVldbEntry(char *p1, char *p2)
4452 struct uvldbentry *arg1,*arg2;
4455 char comp1[100],comp2[100];
4456 char temp1[20],temp2[20];
4458 arg1 = (struct uvldbentry *)p1;
4459 arg2 = (struct uvldbentry *)p2;
4463 for(i = 0; i < arg1->nServers; i++)
4464 if(arg1->serverFlags[i] & ITSRWVOL) pos1 = i;
4465 for(i = 0; i < arg2->nServers; i++)
4466 if(arg2->serverFlags[i] & ITSRWVOL) pos2 = i;
4467 if(pos1 == -1 || pos2 == -1){
4471 sprintf(comp1,"%10u",arg1->serverUnique[pos1]);
4472 sprintf(comp2,"%10u",arg2->serverUnique[pos2]);
4473 sprintf(temp1,"%10u",arg1->serverPartition[pos1]);
4474 sprintf(temp2,"%10u",arg2->serverPartition[pos2]);
4475 strcat(comp1,temp1);
4476 strcat(comp2,temp2);
4477 strcat(comp1,arg1->name);
4478 strcat(comp1,arg2->name);
4479 return(strcmp(comp1,comp2));
4485 ListVLDB(struct cmd_syndesc *as, void *arock)
4491 struct VldbListByAttributes attributes;
4492 ubulkentries arrayEntries;
4493 struct uvldbentry *vllist, *tarray = 0, *ttarray;
4494 afs_int32 centries, nentries = 0;
4495 afs_int32 tarraysize = 0;
4496 afs_int32 parraysize;
4499 int quiet, sort, lock;
4500 afs_int32 thisindex, nextindex;
4505 attributes.Mask = 0;
4506 lock = (as->parms[3].items ? 1 : 0); /* -lock flag */
4507 quiet = (as->parms[4].items ? 1 : 0); /* -quit flag */
4508 sort = (as->parms[5].items ? 0 : 1); /* -nosort flag */
4510 /* If the volume name is given, Use VolumeInfoCmd to look it up
4511 * and not ListAttributes.
4513 if (as->parms[0].items) {
4516 "vos: illegal use of '-locked' switch, need to specify server and/or partition\n");
4519 code = VolumeInfoCmd(as->parms[0].items->data);
4521 PrintError("", code);
4527 /* Server specified */
4528 if (as->parms[1].items) {
4529 aserver = GetServer(as->parms[1].items->data);
4531 fprintf(STDERR, "vos: server '%s' not found in host table\n",
4532 as->parms[1].items->data);
4535 attributes.server = ntohl(aserver);
4536 attributes.Mask |= VLLIST_SERVER;
4539 /* Partition specified */
4540 if (as->parms[2].items) {
4541 apart = volutil_GetPartitionID(as->parms[2].items->data);
4543 fprintf(STDERR, "vos: could not interpret partition name '%s'\n",
4544 as->parms[2].items->data);
4547 attributes.partition = apart;
4548 attributes.Mask |= VLLIST_PARTITION;
4552 attributes.Mask |= VLLIST_FLAG;
4553 attributes.flag = VLOP_ALLOPERS;
4556 /* Print header information */
4558 MapPartIdIntoName(apart, pname);
4559 fprintf(STDOUT, "VLDB entries for %s %s%s%s %s\n",
4560 (as->parms[1].items ? "server" : "all"),
4561 (as->parms[1].items ? as->parms[1].items->data : "servers"),
4562 (as->parms[2].items ? " partition " : ""),
4563 (as->parms[2].items ? pname : ""),
4564 (lock ? "which are locked:" : ""));
4567 for (thisindex = 0; (thisindex != -1); thisindex = nextindex) {
4568 memset(&arrayEntries, 0, sizeof(arrayEntries));
4573 VLDB_ListAttributesN2U(&attributes, 0, thisindex, ¢ries,
4574 &arrayEntries, &nextindex);
4575 if (vcode == RXGEN_OPCODE) {
4576 /* Vlserver not running with ListAttributesN2. Fall back */
4578 VLDB_ListAttributesU(&attributes, ¢ries, &arrayEntries);
4582 fprintf(STDERR, "Could not access the VLDB for attributes\n");
4583 PrintError("", vcode);
4586 nentries += centries;
4588 /* We don't sort, so just print the entries now */
4590 for (j = 0; j < centries; j++) { /* process each entry */
4591 vllist = &arrayEntries.ubulkentries_val[j];
4592 MapHostToNetworkU(vllist);
4593 EnumerateEntryU(vllist);
4595 PrintLocked(vllist->flags);
4599 /* So we sort. First we must collect all the entries and keep
4602 else if (centries > 0) {
4604 /* steal away the first bulk entries array */
4605 tarray = (struct uvldbentry *)arrayEntries.ubulkentries_val;
4606 tarraysize = centries * sizeof(struct uvldbentry);
4607 arrayEntries.ubulkentries_val = 0;
4609 /* Grow the tarray to keep the extra entries */
4610 parraysize = (centries * sizeof(struct uvldbentry));
4612 (struct uvldbentry *)realloc(tarray,
4613 tarraysize + parraysize);
4616 "Could not allocate enough space for the VLDB entries\n");
4622 memcpy(((char *)tarray) + tarraysize,
4623 (char *)arrayEntries.ubulkentries_val, parraysize);
4624 tarraysize += parraysize;
4628 /* Free the bulk array */
4629 if (arrayEntries.ubulkentries_val) {
4630 free(arrayEntries.ubulkentries_val);
4631 arrayEntries.ubulkentries_val = 0;
4635 /* Here is where we now sort all the entries and print them */
4636 if (sort && (nentries > 0)) {
4637 qsort((char *)tarray, nentries, sizeof(struct uvldbentry),
4638 CompareVldbEntryByName);
4639 for (vllist = tarray, j = 0; j < nentries; j++, vllist++) {
4640 MapHostToNetworkU(vllist);
4641 EnumerateEntryU(vllist);
4643 PrintLocked(vllist->flags);
4649 fprintf(STDOUT, "\nTotal entries: %lu\n", (unsigned long)nentries);
4656 BackSys(struct cmd_syndesc *as, void *arock)
4659 afs_int32 apart = 0;
4660 afs_uint32 aserver = 0, aserver1;
4661 afs_int32 code, apart1;
4663 struct VldbListByAttributes attributes;
4664 ubulkentries arrayEntries;
4665 struct uvldbentry *vllist;
4669 int seenprefix, seenxprefix, exclude, ex, exp, noaction;
4670 afs_int32 totalBack = 0;
4671 afs_int32 totalFail = 0;
4675 struct cmd_item *ti;
4677 #ifndef HAVE_POSIX_REGEX
4681 memset(&attributes, 0, sizeof(struct VldbListByAttributes));
4682 attributes.Mask = 0;
4684 seenprefix = (as->parms[0].items ? 1 : 0);
4685 exclude = (as->parms[3].items ? 1 : 0);
4686 seenxprefix = (as->parms[4].items ? 1 : 0);
4687 noaction = (as->parms[5].items ? 1 : 0);
4689 if (as->parms[1].items) { /* -server */
4690 aserver = GetServer(as->parms[1].items->data);
4692 fprintf(STDERR, "vos: server '%s' not found in host table\n",
4693 as->parms[1].items->data);
4696 attributes.server = ntohl(aserver);
4697 attributes.Mask |= VLLIST_SERVER;
4700 if (as->parms[2].items) { /* -partition */
4701 apart = volutil_GetPartitionID(as->parms[2].items->data);
4703 fprintf(STDERR, "vos: could not interpret partition name '%s'\n",
4704 as->parms[2].items->data);
4707 attributes.partition = apart;
4708 attributes.Mask |= VLLIST_PARTITION;
4711 /* Check to make sure the prefix and xprefix expressions compile ok */
4713 for (ti = as->parms[0].items; ti; ti = ti->next) {
4714 if (strncmp(ti->data, "^", 1) == 0) {
4715 #ifdef HAVE_POSIX_REGEX
4719 code = regcomp(&re, ti->data, REG_NOSUB);
4721 regerror(code, &re, errbuf, sizeof errbuf);
4723 "Unrecognizable -prefix regular expression: '%s': %s\n",
4729 ccode = (char *)re_comp(ti->data);
4732 "Unrecognizable -prefix regular expression: '%s': %s\n",
4741 for (ti = as->parms[4].items; ti; ti = ti->next) {
4742 if (strncmp(ti->data, "^", 1) == 0) {
4743 #ifdef HAVE_POSIX_REGEX
4747 code = regcomp(&re, ti->data, REG_NOSUB);
4749 regerror(code, &re, errbuf, sizeof errbuf);
4751 "Unrecognizable -xprefix regular expression: '%s': %s\n",
4757 ccode = (char *)re_comp(ti->data);
4760 "Unrecognizable -xprefix regular expression: '%s': %s\n",
4769 memset(&arrayEntries, 0, sizeof(arrayEntries)); /* initialize to hint the stub to alloc space */
4770 vcode = VLDB_ListAttributesU(&attributes, &nentries, &arrayEntries);
4772 fprintf(STDERR, "Could not access the VLDB for attributes\n");
4773 PrintError("", vcode);
4777 if (as->parms[1].items || as->parms[2].items || verbose) {
4778 fprintf(STDOUT, "%s up volumes",
4779 (noaction ? "Would have backed" : "Backing"));
4781 if (as->parms[1].items) {
4782 fprintf(STDOUT, " on server %s", as->parms[1].items->data);
4783 } else if (as->parms[2].items) {
4784 fprintf(STDOUT, " for all servers");
4787 if (as->parms[2].items) {
4788 MapPartIdIntoName(apart, pname);
4789 fprintf(STDOUT, " partition %s", pname);
4792 if (seenprefix || (!seenprefix && seenxprefix)) {
4793 ti = (seenprefix ? as->parms[0].items : as->parms[4].items);
4794 ex = (seenprefix ? exclude : !exclude);
4795 exp = (strncmp(ti->data, "^", 1) == 0);
4796 fprintf(STDOUT, " which %smatch %s '%s'", (ex ? "do not " : ""),
4797 (exp ? "expression" : "prefix"), ti->data);
4798 for (ti = ti->next; ti; ti = ti->next) {
4799 exp = (strncmp(ti->data, "^", 1) == 0);
4800 printf(" %sor %s '%s'", (ex ? "n" : ""),
4801 (exp ? "expression" : "prefix"), ti->data);
4805 if (seenprefix && seenxprefix) {
4806 ti = as->parms[4].items;
4807 exp = (strncmp(ti->data, "^", 1) == 0);
4808 fprintf(STDOUT, " %swhich match %s '%s'",
4809 (exclude ? "adding those " : "removing those "),
4810 (exp ? "expression" : "prefix"), ti->data);
4811 for (ti = ti->next; ti; ti = ti->next) {
4812 exp = (strncmp(ti->data, "^", 1) == 0);
4813 printf(" or %s '%s'", (exp ? "expression" : "prefix"),
4817 fprintf(STDOUT, " .. ");
4819 fprintf(STDOUT, "\n");
4823 for (j = 0; j < nentries; j++) { /* process each vldb entry */
4824 vllist = &arrayEntries.ubulkentries_val[j];
4827 for (ti = as->parms[0].items; ti; ti = ti->next) {
4828 if (strncmp(ti->data, "^", 1) == 0) {
4829 #ifdef HAVE_POSIX_REGEX
4833 /* XXX -- should just do the compile once! */
4834 code = regcomp(&re, ti->data, REG_NOSUB);
4836 regerror(code, &re, errbuf, sizeof errbuf);
4838 "Error in -prefix regular expression: '%s': %s\n",
4842 match = (regexec(&re, vllist->name, 0, NULL, 0) == 0);
4845 ccode = (char *)re_comp(ti->data);
4848 "Error in -prefix regular expression: '%s': %s\n",
4852 match = (re_exec(vllist->name) == 1);
4856 (strncmp(vllist->name, ti->data, strlen(ti->data)) ==
4866 /* Without the -exclude flag: If it matches the prefix, then
4867 * check if we want to exclude any from xprefix.
4868 * With the -exclude flag: If it matches the prefix, then
4869 * check if we want to add any from xprefix.
4871 if (match && seenxprefix) {
4872 for (ti = as->parms[4].items; ti; ti = ti->next) {
4873 if (strncmp(ti->data, "^", 1) == 0) {
4874 #ifdef HAVE_POSIX_REGEX
4878 /* XXX -- should just do the compile once! */
4879 code = regcomp(&re, ti->data, REG_NOSUB);
4881 regerror(code, &re, errbuf, sizeof errbuf);
4883 "Error in -xprefix regular expression: '%s': %s\n",
4887 if (regexec(&re, vllist->name, 0, NULL, 0) == 0)
4891 ccode = (char *)re_comp(ti->data);
4894 "Error in -xprefix regular expression: '%s': %s\n",
4898 if (re_exec(vllist->name) == 1) {
4904 if (strncmp(vllist->name, ti->data, strlen(ti->data)) ==
4914 match = !match; /* -exclude will reverse the match */
4916 continue; /* Skip if no match */
4918 /* Print list of volumes to backup */
4920 fprintf(STDOUT, " %s\n", vllist->name);
4924 if (!(vllist->flags & RW_EXISTS)) {
4927 "Omitting to backup %s since RW volume does not exist \n",
4929 fprintf(STDOUT, "\n");
4935 avolid = vllist->volumeId[RWVOL];
4936 MapHostToNetworkU(vllist);
4937 GetServerAndPart(vllist, RWVOL, &aserver1, &apart1, &previdx);
4938 if (aserver1 == -1 || apart1 == -1) {
4939 fprintf(STDOUT, "could not backup %s, invalid VLDB entry\n",
4945 same = VLDB_IsSameAddrs(aserver, aserver1, &error);
4948 "Failed to get info about server's %d address(es) from vlserver (err=%d); aborting call!\n",
4954 if ((aserver && !same) || (apart && (apart != apart1))) {
4957 "Omitting to backup %s since the RW is in a different location\n",
4963 time_t now = time(0);
4964 fprintf(STDOUT, "Creating backup volume for %s on %s",
4965 vllist->name, ctime(&now));
4969 code = UV_BackupVolume(aserver1, apart1, avolid);
4971 fprintf(STDOUT, "Could not backup %s\n", vllist->name);
4977 fprintf(STDOUT, "\n");
4979 } /* process each vldb entry */
4980 fprintf(STDOUT, "done\n");
4981 fprintf(STDOUT, "Total volumes backed up: %lu; failed to backup: %lu\n",
4982 (unsigned long)totalBack, (unsigned long)totalFail);
4984 if (arrayEntries.ubulkentries_val)
4985 free(arrayEntries.ubulkentries_val);
4990 UnlockVLDB(struct cmd_syndesc *as, void *arock)
4993 afs_uint32 aserver = 0;
4996 struct VldbListByAttributes attributes;
4997 ubulkentries arrayEntries;
4998 struct uvldbentry *vllist;
5007 attributes.Mask = 0;
5009 if (as->parms[0].items) { /* server specified */
5010 aserver = GetServer(as->parms[0].items->data);
5012 fprintf(STDERR, "vos: server '%s' not found in host table\n",
5013 as->parms[0].items->data);
5016 attributes.server = ntohl(aserver);
5017 attributes.Mask |= VLLIST_SERVER;
5019 if (as->parms[1].items) { /* partition specified */
5020 apart = volutil_GetPartitionID(as->parms[1].items->data);
5022 fprintf(STDERR, "vos: could not interpret partition name '%s'\n",
5023 as->parms[1].items->data);
5026 if (!IsPartValid(apart, aserver, &code)) { /*check for validity of the partition */
5028 PrintError("", code);
5031 "vos : partition %s does not exist on the server\n",
5032 as->parms[1].items->data);
5035 attributes.partition = apart;
5036 attributes.Mask |= VLLIST_PARTITION;
5038 attributes.flag = VLOP_ALLOPERS;
5039 attributes.Mask |= VLLIST_FLAG;
5040 memset(&arrayEntries, 0, sizeof(arrayEntries)); /*initialize to hint the stub to alloc space */
5041 vcode = VLDB_ListAttributesU(&attributes, &nentries, &arrayEntries);
5043 fprintf(STDERR, "Could not access the VLDB for attributes\n");
5044 PrintError("", vcode);
5047 for (j = 0; j < nentries; j++) { /* process each entry */
5048 vllist = &arrayEntries.ubulkentries_val[j];
5049 volid = vllist->volumeId[RWVOL];
5051 ubik_VL_ReleaseLock(cstruct, 0, volid, -1,
5052 LOCKREL_OPCODE | LOCKREL_AFSID |
5055 fprintf(STDERR, "Could not unlock entry for volume %s\n",
5057 PrintError("", vcode);
5062 MapPartIdIntoName(apart, pname);
5065 "Could not lock %lu VLDB entries of %lu locked entries\n",
5066 (unsigned long)totalE, (unsigned long)nentries);
5068 if (as->parms[0].items) {
5070 "Unlocked all the VLDB entries for volumes on server %s ",
5071 as->parms[0].items->data);
5072 if (as->parms[1].items) {
5073 MapPartIdIntoName(apart, pname);
5074 fprintf(STDOUT, "partition %s\n", pname);
5076 fprintf(STDOUT, "\n");
5078 } else if (as->parms[1].items) {
5079 MapPartIdIntoName(apart, pname);
5081 "Unlocked all the VLDB entries for volumes on partition %s on all servers\n",
5086 if (arrayEntries.ubulkentries_val)
5087 free(arrayEntries.ubulkentries_val);
5092 PrintInt64Size(afs_uint64 in)
5096 static char output[16];
5098 SplitInt64(in,hi,lo);
5102 } else if (!(hi & 0xFFFFFC00)) {
5104 lo = (hi << 22) | (lo >> 10);
5105 } else if (!(hi & 0xFFF00000)) {
5107 lo = (hi << 12) | (lo >> 20);
5108 } else if (!(hi & 0xC0000000)) {
5110 lo = (hi << 2) | (lo >> 30);
5115 sprintf(output,"%u %s", lo, units);
5120 PartitionInfo(struct cmd_syndesc *as, void *arock)
5126 struct diskPartition64 partition;
5127 struct partList dummyPartList;
5129 int printSummary=0, sumPartitions=0;
5130 afs_uint64 sumFree, sumStorage;
5133 ZeroInt64(sumStorage);
5135 aserver = GetServer(as->parms[0].items->data);
5137 fprintf(STDERR, "vos: server '%s' not found in host table\n",
5138 as->parms[0].items->data);
5141 if (as->parms[1].items) {
5142 apart = volutil_GetPartitionID(as->parms[1].items->data);
5144 fprintf(STDERR, "vos: could not interpret partition name '%s'\n",
5145 as->parms[1].items->data);
5148 dummyPartList.partId[0] = apart;
5149 dummyPartList.partFlags[0] = PARTVALID;
5152 if (as->parms[2].items) {
5156 if (!IsPartValid(apart, aserver, &code)) { /*check for validity of the partition */
5158 PrintError("", code);
5161 "vos : partition %s does not exist on the server\n",
5162 as->parms[1].items->data);
5166 code = UV_ListPartitions(aserver, &dummyPartList, &cnt);
5168 PrintDiagnostics("listpart", code);
5172 for (i = 0; i < cnt; i++) {
5173 if (dummyPartList.partFlags[i] & PARTVALID) {
5174 MapPartIdIntoName(dummyPartList.partId[i], pname);
5175 code = UV_PartitionInfo64(aserver, pname, &partition);
5177 fprintf(STDERR, "Could not get information on partition %s\n",
5179 PrintError("", code);
5183 "Free space on partition %s: %" AFS_INT64_FMT " K blocks out of total %" AFS_INT64_FMT "\n",
5184 pname, partition.free, partition.minFree);
5186 AddUInt64(sumFree,partition.free,&sumFree);
5187 AddUInt64(sumStorage,partition.minFree,&sumStorage);
5192 "Summary: %s free out of ",
5193 PrintInt64Size(sumFree));
5195 "%s on %d partitions\n",
5196 PrintInt64Size(sumStorage),
5203 ChangeAddr(struct cmd_syndesc *as, void *arock)
5205 afs_int32 ip1, ip2, vcode;
5209 ip1 = GetServerNoresolve(as->parms[0].items->data);
5211 ip1 = GetServer(as->parms[0].items->data);
5213 fprintf(STDERR, "vos: invalid host address\n");
5217 if ((as->parms[1].items && as->parms[2].items)
5218 || (!as->parms[1].items && !as->parms[2].items)) {
5220 "vos: Must specify either '-newaddr <addr>' or '-remove' flag\n");
5224 if (as->parms[1].items) {
5226 ip2 = GetServerNoresolve(as->parms[1].items->data);
5228 ip2 = GetServer(as->parms[1].items->data);
5230 fprintf(STDERR, "vos: invalid host address\n");
5234 /* Play a trick here. If we are removing an address, ip1 will be -1
5235 * and ip2 will be the original address. This switch prevents an
5236 * older revision vlserver from removing the IP address.
5243 vcode = ubik_VL_ChangeAddr(cstruct, UBIK_CALL_NEW, ntohl(ip1), ntohl(ip2));
5245 char hoststr1[16], hoststr2[16];
5247 afs_inet_ntoa_r(ip2, hoststr2);
5248 fprintf(STDERR, "Could not remove server %s from the VLDB\n",
5250 if (vcode == VL_NOENT) {
5252 "vlserver does not support the remove flag or ");
5255 afs_inet_ntoa_r(ip1, hoststr1);
5256 afs_inet_ntoa_r(ip2, hoststr2);
5257 fprintf(STDERR, "Could not change server %s to server %s\n",
5258 hoststr1, hoststr2);
5260 PrintError("", vcode);
5265 fprintf(STDOUT, "Removed server %s from the VLDB\n",
5266 as->parms[0].items->data);
5268 fprintf(STDOUT, "Changed server %s to server %s\n",
5269 as->parms[0].items->data, as->parms[1].items->data);
5275 print_addrs(const bulkaddrs * addrs, afsUUID * m_uuid, int nentries,
5278 afs_int32 vcode, m_uniq=0;
5282 ListAddrByAttributes m_attrs;
5283 afs_int32 m_nentries;
5284 afs_uint32 *m_addrp;
5285 afs_int32 base, index;
5289 afsUUID_to_string(m_uuid, buf, sizeof(buf));
5290 printf("UUID: %s\n", buf);
5293 /* print out the list of all the server */
5294 addrp = (afs_uint32 *) addrs->bulkaddrs_val;
5295 for (i = 0; i < nentries; i++, addrp++) {
5296 /* If it is a multihomed address, then we will need to
5297 * get the addresses for this multihomed server from
5298 * the vlserver and print them.
5300 if (((*addrp & 0xff000000) == 0xff000000) && ((*addrp) & 0xffff)) {
5301 /* Get the list of multihomed fileservers */
5302 base = (*addrp >> 16) & 0xff;
5303 index = (*addrp) & 0xffff;
5305 if ((base >= 0) && (base <= VL_MAX_ADDREXTBLKS) && (index >= 1)
5306 && (index <= VL_MHSRV_PERBLK)) {
5307 m_attrs.Mask = VLADDR_INDEX;
5308 m_attrs.index = (base * VL_MHSRV_PERBLK) + index;
5310 m_addrs.bulkaddrs_val = 0;
5311 m_addrs.bulkaddrs_len = 0;
5313 ubik_VL_GetAddrsU(cstruct, 0, &m_attrs, m_uuid,
5314 &m_uniq, &m_nentries,
5318 "vos: could not list the multi-homed server addresses\n");
5319 PrintError("", vcode);
5322 /* Print the list */
5323 m_addrp = (afs_uint32 *) m_addrs.bulkaddrs_val;
5324 for (j = 0; j < m_nentries; j++, m_addrp++) {
5325 *m_addrp = htonl(*m_addrp);
5328 printf("%s ", afs_inet_ntoa_r(*m_addrp, hoststr));
5330 printf("%s ", hostutil_GetNameByINet(*m_addrp));
5334 printf("<unknown>\n");
5343 /* Otherwise, it is a non-multihomed entry and contains
5344 * the IP address of the server - print it.
5346 *addrp = htonl(*addrp);
5349 printf("%s\n", afs_inet_ntoa_r(*addrp, hoststr));
5351 printf("%s\n", hostutil_GetNameByINet(*addrp));
5362 ListAddrs(struct cmd_syndesc *as, void *arock)
5364 afs_int32 vcode, m_uniq=0;
5365 afs_int32 i, printuuid = 0;
5366 struct VLCallBack vlcb;
5369 ListAddrByAttributes m_attrs;
5370 afsUUID m_uuid, askuuid;
5371 afs_int32 m_nentries;
5373 memset(&m_attrs, 0, sizeof(struct ListAddrByAttributes));
5374 m_attrs.Mask = VLADDR_INDEX;
5376 memset(&m_addrs, 0, sizeof(bulkaddrs));
5377 memset(&askuuid, 0, sizeof(afsUUID));
5378 if (as->parms[0].items) {
5380 if (afsUUID_from_string(as->parms[0].items->data, &askuuid) < 0) {
5381 fprintf(STDERR, "vos: invalid UUID '%s'\n",
5382 as->parms[0].items->data);
5385 m_attrs.Mask = VLADDR_UUID;
5386 m_attrs.uuid = askuuid;
5388 if (as->parms[1].items) {
5392 he = hostutil_GetHostByName((char *)as->parms[1].items->data);
5394 fprintf(STDERR, "vos: Can't get host info for '%s'\n",
5395 as->parms[1].items->data);
5398 memcpy(&saddr, he->h_addr, 4);
5399 m_attrs.Mask = VLADDR_IPADDR;
5400 m_attrs.ipaddr = ntohl(saddr);
5402 if (as->parms[2].items) {
5406 m_addrs.bulkaddrs_val = 0;
5407 m_addrs.bulkaddrs_len = 0;
5410 ubik_VL_GetAddrs(cstruct, UBIK_CALL_NEW, 0, 0, &vlcb, &nentries,
5413 fprintf(STDERR, "vos: could not list the server addresses\n");
5414 PrintError("", vcode);
5419 m_addrs.bulkaddrs_val = 0;
5420 m_addrs.bulkaddrs_len = 0;
5426 ubik_VL_GetAddrsU(cstruct, UBIK_CALL_NEW, &m_attrs, &m_uuid,
5427 &m_uniq, &m_nentries, &m_addrs);
5429 if (vcode == VL_NOENT) {
5430 if (m_attrs.Mask == VLADDR_UUID) {
5431 fprintf(STDERR, "vos: no entry for UUID '%s' found in VLDB\n",
5432 as->parms[0].items->data);
5434 } else if (m_attrs.Mask == VLADDR_IPADDR) {
5435 fprintf(STDERR, "vos: no entry for host '%s' [0x%08x] found in VLDB\n",
5436 as->parms[1].items->data, m_attrs.ipaddr);
5445 if (vcode == VL_INDEXERANGE) {
5450 fprintf(STDERR, "vos: could not list the server addresses\n");
5451 PrintError("", vcode);
5455 print_addrs(&m_addrs, &m_uuid, m_nentries, printuuid);
5458 if ((as->parms[1].items) || (as->parms[0].items) || (i > nentries))
5467 SetAddrs(struct cmd_syndesc *as, void *arock)
5472 afs_uint32 FS_HostAddrs_HBO[ADDRSPERSITE];
5474 memset(&m_addrs, 0, sizeof(bulkaddrs));
5475 memset(&askuuid, 0, sizeof(afsUUID));
5476 if (as->parms[0].items) {
5478 if (afsUUID_from_string(as->parms[0].items->data, &askuuid) < 0) {
5479 fprintf(STDERR, "vos: invalid UUID '%s'\n",
5480 as->parms[0].items->data);
5484 if (as->parms[1].items) {
5486 struct cmd_item *ti;
5490 for (ti = as->parms[1].items; ti && i < ADDRSPERSITE; ti = ti->next) {
5493 saddr = GetServerNoresolve(ti->data);
5495 saddr = GetServer(ti->data);
5498 fprintf(STDERR, "vos: Can't get host info for '%s'\n",
5502 /* Convert it to host byte order */
5503 FS_HostAddrs_HBO[i] = ntohl(saddr);
5506 m_addrs.bulkaddrs_len = i;
5507 m_addrs.bulkaddrs_val = FS_HostAddrs_HBO;
5510 vcode = ubik_VL_RegisterAddrs(cstruct, 0, &askuuid, 0, &m_addrs);
5513 if (vcode == VL_MULTIPADDR) {
5514 fprintf(STDERR, "vos: VL_RegisterAddrs rpc failed; The IP address exists on a different server; repair it\n");
5515 PrintError("", vcode);
5517 } else if (vcode == RXGEN_OPCODE) {
5518 fprintf(STDERR, "vlserver doesn't support VL_RegisterAddrs rpc; ignored\n");
5519 PrintError("", vcode);
5524 fprintf(STDOUT, "vos: Changed UUID with addresses:\n");
5525 print_addrs(&m_addrs, &askuuid, m_addrs.bulkaddrs_len, 1);
5531 LockEntry(struct cmd_syndesc *as, void *arock)
5534 afs_int32 vcode, err;
5536 avolid = vsu_GetVolumeID(as->parms[0].items->data, cstruct, &err);
5539 PrintError("", err);
5541 fprintf(STDERR, "vos: can't find volume '%s'\n",
5542 as->parms[0].items->data);
5545 vcode = ubik_VL_SetLock(cstruct, 0, avolid, -1, VLOP_DELETE);
5547 fprintf(STDERR, "Could not lock VLDB entry for volume %s\n",
5548 as->parms[0].items->data);
5549 PrintError("", vcode);
5552 fprintf(STDOUT, "Locked VLDB entry for volume %s\n",
5553 as->parms[0].items->data);
5558 ConvertRO(struct cmd_syndesc *as, void *arock)
5560 afs_int32 partition = -1;
5563 afs_int32 code, i, same;
5564 struct uvldbentry entry, storeEntry;
5566 afs_int32 rwindex = 0;
5567 afs_uint32 rwserver = 0;
5568 afs_int32 rwpartition = 0;
5569 afs_int32 roindex = 0;
5570 afs_uint32 roserver = 0;
5571 afs_int32 ropartition = 0;
5573 struct rx_connection *aconn;
5576 server = GetServer(as->parms[0].items->data);
5578 fprintf(STDERR, "vos: host '%s' not found in host table\n",
5579 as->parms[0].items->data);
5582 partition = volutil_GetPartitionID(as->parms[1].items->data);
5583 if (partition < 0) {
5584 fprintf(STDERR, "vos: could not interpret partition name '%s'\n",
5585 as->parms[1].items->data);
5588 if (!IsPartValid(partition, server, &code)) {
5590 PrintError("", code);
5593 "vos : partition %s does not exist on the server\n",
5594 as->parms[1].items->data);
5597 volid = vsu_GetVolumeID(as->parms[2].items->data, cstruct, &code);
5600 PrintError("", code);
5602 fprintf(STDERR, "Unknown volume ID or name '%s'\n",
5603 as->parms[0].items->data);
5606 if (as->parms[3].items)
5609 vcode = VLDB_GetEntryByIDU(volid, -1, &entry);
5612 "Could not fetch the entry for volume %lu from VLDB\n",
5613 (unsigned long)volid);
5614 PrintError("convertROtoRW", code);
5618 /* use RO volid even if user specified RW or BK volid */
5620 if (volid != entry.volumeId[ROVOL])
5621 volid = entry.volumeId[ROVOL];
5623 MapHostToNetworkU(&entry);
5624 for (i = 0; i < entry.nServers; i++) {
5625 if (entry.serverFlags[i] & ITSRWVOL) {
5627 rwserver = entry.serverUnique[i];
5628 rwpartition = entry.serverPartition[i];
5630 if (entry.serverFlags[i] & ITSROVOL) {
5631 same = VLDB_IsSameAddrs(server, entry.serverUnique[i], &code);
5634 "Failed to get info about server's %d address(es) from vlserver (err=%d); aborting call!\n",
5640 roserver = entry.serverUnique[i];
5641 ropartition = entry.serverPartition[i];
5647 fprintf(STDERR, "Warning: RO volume didn't exist in vldb!\n");
5649 if (ropartition != partition) {
5651 "Warning: RO volume should be in partition %d instead of %d (vldb)\n",
5652 ropartition, partition);
5657 "VLDB indicates that a RW volume exists already on %s in partition %s.\n",
5658 hostutil_GetNameByINet(rwserver),
5659 volutil_PartitionName(rwpartition));
5661 fprintf(STDERR, "Overwrite this VLDB entry? [y|n] (n)\n");
5663 while (!(dc == EOF || dc == '\n'))
5664 dc = getchar(); /* goto end of line */
5665 if ((c != 'y') && (c != 'Y')) {
5666 fprintf(STDERR, "aborted.\n");
5673 ubik_VL_SetLock(cstruct, 0, entry.volumeId[RWVOL], RWVOL,
5675 aconn = UV_Bind(server, AFSCONF_VOLUMEPORT);
5676 code = AFSVolConvertROtoRWvolume(aconn, partition, volid);
5679 "Converting RO volume %lu to RW volume failed with code %d\n",
5680 (unsigned long)volid, code);
5681 PrintError("convertROtoRW ", code);
5684 entry.serverFlags[roindex] = ITSRWVOL;
5685 entry.flags |= RW_EXISTS;
5686 entry.flags &= ~BACK_EXISTS;
5689 if (rwindex != entry.nServers) {
5690 entry.serverUnique[rwindex] = entry.serverUnique[entry.nServers];
5691 entry.serverPartition[rwindex] =
5692 entry.serverPartition[entry.nServers];
5693 entry.serverFlags[rwindex] = entry.serverFlags[entry.nServers];
5694 entry.serverUnique[entry.nServers] = 0;
5695 entry.serverPartition[entry.nServers] = 0;
5696 entry.serverFlags[entry.nServers] = 0;
5699 entry.flags &= ~RO_EXISTS;
5700 for (i = 0; i < entry.nServers; i++) {
5701 if (entry.serverFlags[i] & ITSROVOL) {
5702 if (!(entry.serverFlags[i] & (RO_DONTUSE | NEW_REPSITE)))
5703 entry.flags |= RO_EXISTS;
5706 MapNetworkToHostU(&entry, &storeEntry);
5708 VLDB_ReplaceEntryU(entry.volumeId[RWVOL], RWVOL, &storeEntry,
5709 (LOCKREL_OPCODE | LOCKREL_AFSID |
5710 LOCKREL_TIMESTAMP));
5713 "Warning: volume converted, but vldb update failed with code %d!\n",
5716 vcode = UV_LockRelease(entry.volumeId[RWVOL]);
5718 PrintDiagnostics("unlock", vcode);
5724 Sizes(struct cmd_syndesc *as, void *arock)
5728 afs_int32 apart, voltype, fromdate = 0, code, err, i;
5729 struct uvldbentry entry;
5730 volintSize vol_size;
5732 rx_SetRxDeadTime(60 * 10);
5733 for (i = 0; i < MAXSERVERS; i++) {
5734 struct rx_connection *rxConn = ubik_GetRPCConn(cstruct, i);
5737 rx_SetConnDeadTime(rxConn, rx_connDeadTime);
5738 if (rxConn->service)
5739 rxConn->service->connDeadTime = rx_connDeadTime;
5742 avolid = vsu_GetVolumeID(as->parms[0].items->data, cstruct, &err);
5745 PrintError("", err);
5747 fprintf(STDERR, "vos: can't find volume '%s'\n",
5748 as->parms[0].items->data);
5752 if (as->parms[1].items || as->parms[2].items) {
5753 if (!as->parms[1].items || !as->parms[2].items) {
5755 "Must specify both -server and -partition options\n");
5758 aserver = GetServer(as->parms[2].items->data);
5760 fprintf(STDERR, "Invalid server name\n");
5763 apart = volutil_GetPartitionID(as->parms[1].items->data);
5765 fprintf(STDERR, "Invalid partition name\n");
5769 code = GetVolumeInfo(avolid, &aserver, &apart, &voltype, &entry);
5776 if (as->parms[4].items && strcmp(as->parms[4].items->data, "0")) {
5777 code = ktime_DateToInt32(as->parms[4].items->data, &fromdate);
5779 fprintf(STDERR, "vos: failed to parse date '%s' (error=%d))\n",
5780 as->parms[4].items->data, code);
5785 fprintf(STDOUT, "Volume: %s\n", as->parms[0].items->data);
5787 if (as->parms[3].items) { /* do the dump estimate */
5788 vol_size.dump_size = 0;
5789 code = UV_GetSize(avolid, aserver, apart, fromdate, &vol_size);
5791 PrintDiagnostics("size", code);
5794 /* presumably the size info is now gathered in pntr */
5795 /* now we display it */
5797 fprintf(STDOUT, "dump_size: %llu\n", vol_size.dump_size);
5806 EndTrans(struct cmd_syndesc *as, void *arock)
5809 afs_int32 code, tid, rcode;
5810 struct rx_connection *aconn;
5812 server = GetServer(as->parms[0].items->data);
5814 fprintf(STDERR, "vos: host '%s' not found in host table\n",
5815 as->parms[0].items->data);
5819 code = util_GetInt32(as->parms[1].items->data, &tid);
5821 fprintf(STDERR, "vos: bad integer specified for transaction ID.\n");
5825 aconn = UV_Bind(server, AFSCONF_VOLUMEPORT);
5826 code = AFSVolEndTrans(aconn, tid, &rcode);
5832 PrintDiagnostics("endtrans", code);
5840 PrintDiagnostics(char *astring, afs_int32 acode)
5842 if (acode == EACCES) {
5844 "You are not authorized to perform the 'vos %s' command (%d)\n",
5847 fprintf(STDERR, "Error in vos %s command.\n", astring);
5848 PrintError("", acode);
5856 win32_enableCrypt(void)
5863 /* Look up configuration parameters in Registry */
5864 code = RegOpenKeyEx(HKEY_LOCAL_MACHINE, AFSREG_CLT_SVC_PARAM_SUBKEY,
5865 0, (IsWow64()?KEY_WOW64_64KEY:0)|KEY_QUERY_VALUE, &parmKey);
5866 if (code != ERROR_SUCCESS) {
5867 dummyLen = sizeof(cryptall);
5868 RegQueryValueEx(parmKey, "SecurityLevel", NULL, NULL,
5869 (BYTE *) &cryptall, &dummyLen);
5871 RegCloseKey (parmKey);
5875 #endif /* AFS_NT40_ENV */
5878 MyBeforeProc(struct cmd_syndesc *as, void *arock)
5884 /* Initialize the ubik_client connection */
5885 rx_SetRxDeadTime(90);
5886 cstruct = (struct ubik_client *)0;
5890 if (as->parms[12].items) /* if -cell specified */
5891 tcell = as->parms[12].items->data;
5892 if (as->parms[14].items) /* -serverauth specified */
5894 if (as->parms[16].items /* -encrypt specified */
5896 || win32_enableCrypt()
5897 #endif /* AFS_NT40_ENV */
5901 vsu_ClientInit((as->parms[13].items != 0), confdir, tcell, sauth,
5902 &cstruct, UV_SetSecurity))) {
5903 fprintf(STDERR, "could not initialize VLDB library (code=%lu) \n",
5904 (unsigned long)code);
5908 if (as->parms[15].items) /* -verbose flag set */
5912 if (as->parms[17].items) /* -noresolve flag set */
5922 /* this sucks but it works for now.
5927 #include "AFS_component_version_number.c"
5930 main(int argc, char **argv)
5934 struct cmd_syndesc *ts;
5936 #ifdef AFS_AIX32_ENV
5938 * The following signal action for AIX is necessary so that in case of a
5939 * crash (i.e. core is generated) we can include the user's data section
5940 * in the core dump. Unfortunately, by default, only a partial core is
5941 * generated which, in many cases, isn't too useful.
5943 struct sigaction nsa;
5945 sigemptyset(&nsa.sa_mask);
5946 nsa.sa_handler = SIG_DFL;
5947 nsa.sa_flags = SA_FULLDUMP;
5948 sigaction(SIGSEGV, &nsa, NULL);
5951 confdir = AFSDIR_CLIENT_ETC_DIRPATH;
5953 cmd_SetBeforeProc(MyBeforeProc, NULL);
5955 ts = cmd_CreateSyntax("create", CreateVolume, NULL, "create a new volume");
5956 cmd_AddParm(ts, "-server", CMD_SINGLE, 0, "machine name");
5957 cmd_AddParm(ts, "-partition", CMD_SINGLE, 0, "partition name");
5958 cmd_AddParm(ts, "-name", CMD_SINGLE, 0, "volume name");
5959 cmd_AddParm(ts, "-maxquota", CMD_SINGLE, CMD_OPTIONAL,
5960 "initial quota (KB)");
5961 cmd_AddParm(ts, "-id", CMD_SINGLE, CMD_OPTIONAL, "volume ID");
5962 cmd_AddParm(ts, "-roid", CMD_SINGLE, CMD_OPTIONAL, "readonly volume ID");
5964 cmd_AddParm(ts, "-minquota", CMD_SINGLE, CMD_OPTIONAL, "");
5968 ts = cmd_CreateSyntax("remove", DeleteVolume, NULL, "delete a volume");
5969 cmd_AddParm(ts, "-server", CMD_SINGLE, CMD_OPTIONAL, "machine name");
5970 cmd_AddParm(ts, "-partition", CMD_SINGLE, CMD_OPTIONAL, "partition name");
5971 cmd_AddParm(ts, "-id", CMD_SINGLE, 0, "volume name or ID");
5975 ts = cmd_CreateSyntax("move", MoveVolume, NULL, "move a volume");
5976 cmd_AddParm(ts, "-id", CMD_SINGLE, 0, "volume name or ID");
5977 cmd_AddParm(ts, "-fromserver", CMD_SINGLE, 0, "machine name on source");
5978 cmd_AddParm(ts, "-frompartition", CMD_SINGLE, 0,
5979 "partition name on source");
5980 cmd_AddParm(ts, "-toserver", CMD_SINGLE, 0,
5981 "machine name on destination");
5982 cmd_AddParm(ts, "-topartition", CMD_SINGLE, 0,
5983 "partition name on destination");
5984 cmd_AddParm(ts, "-live", CMD_FLAG, CMD_OPTIONAL,
5985 "copy live volume without cloning");
5988 ts = cmd_CreateSyntax("copy", CopyVolume, NULL, "copy a volume");
5989 cmd_AddParm(ts, "-id", CMD_SINGLE, 0, "volume name or ID on source");
5990 cmd_AddParm(ts, "-fromserver", CMD_SINGLE, 0, "machine name on source");
5991 cmd_AddParm(ts, "-frompartition", CMD_SINGLE, 0,
5992 "partition name on source");
5993 cmd_AddParm(ts, "-toname", CMD_SINGLE, 0, "volume name on destination");
5994 cmd_AddParm(ts, "-toserver", CMD_SINGLE, 0,
5995 "machine name on destination");
5996 cmd_AddParm(ts, "-topartition", CMD_SINGLE, 0,
5997 "partition name on destination");
5998 cmd_AddParm(ts, "-offline", CMD_FLAG, CMD_OPTIONAL,
5999 "leave new volume offline");
6000 cmd_AddParm(ts, "-readonly", CMD_FLAG, CMD_OPTIONAL,
6001 "make new volume read-only");
6002 cmd_AddParm(ts, "-live", CMD_FLAG, CMD_OPTIONAL,
6003 "copy live volume without cloning");
6006 ts = cmd_CreateSyntax("shadow", ShadowVolume, NULL,
6007 "make or update a shadow volume");
6008 cmd_AddParm(ts, "-id", CMD_SINGLE, 0, "volume name or ID on source");
6009 cmd_AddParm(ts, "-fromserver", CMD_SINGLE, 0, "machine name on source");
6010 cmd_AddParm(ts, "-frompartition", CMD_SINGLE, 0,
6011 "partition name on source");
6012 cmd_AddParm(ts, "-toserver", CMD_SINGLE, 0,
6013 "machine name on destination");
6014 cmd_AddParm(ts, "-topartition", CMD_SINGLE, 0,
6015 "partition name on destination");
6016 cmd_AddParm(ts, "-toname", CMD_SINGLE, CMD_OPTIONAL,
6017 "volume name on destination");
6018 cmd_AddParm(ts, "-toid", CMD_SINGLE, CMD_OPTIONAL,
6019 "volume ID on destination");
6020 cmd_AddParm(ts, "-offline", CMD_FLAG, CMD_OPTIONAL,
6021 "leave shadow volume offline");
6022 cmd_AddParm(ts, "-readonly", CMD_FLAG, CMD_OPTIONAL,
6023 "make shadow volume read-only");
6024 cmd_AddParm(ts, "-live", CMD_FLAG, CMD_OPTIONAL,
6025 "copy live volume without cloning");
6026 cmd_AddParm(ts, "-incremental", CMD_FLAG, CMD_OPTIONAL,
6027 "do incremental update if target exists");
6030 ts = cmd_CreateSyntax("backup", BackupVolume, NULL,
6031 "make backup of a volume");
6032 cmd_AddParm(ts, "-id", CMD_SINGLE, 0, "volume name or ID");
6035 ts = cmd_CreateSyntax("clone", CloneVolume, NULL,
6036 "make clone of a volume");
6037 cmd_AddParm(ts, "-id", CMD_SINGLE, 0, "volume name or ID");
6038 cmd_AddParm(ts, "-server", CMD_SINGLE, CMD_OPTIONAL, "server");
6039 cmd_AddParm(ts, "-partition", CMD_SINGLE, CMD_OPTIONAL, "partition");
6040 cmd_AddParm(ts, "-toname", CMD_SINGLE, CMD_OPTIONAL,
6041 "volume name on destination");
6042 cmd_AddParm(ts, "-toid", CMD_SINGLE, CMD_OPTIONAL,
6043 "volume ID on destination");
6044 cmd_AddParm(ts, "-offline", CMD_FLAG, CMD_OPTIONAL,
6045 "leave clone volume offline");
6046 cmd_AddParm(ts, "-readonly", CMD_FLAG, CMD_OPTIONAL,
6047 "make clone volume read-only, not readwrite");
6050 ts = cmd_CreateSyntax("release", ReleaseVolume, NULL, "release a volume");
6051 cmd_AddParm(ts, "-id", CMD_SINGLE, 0, "volume name or ID");
6052 cmd_AddParm(ts, "-force", CMD_FLAG, CMD_OPTIONAL,
6053 "force a complete release");
6056 ts = cmd_CreateSyntax("dump", DumpVolumeCmd, NULL, "dump a volume");
6057 cmd_AddParm(ts, "-id", CMD_SINGLE, 0, "volume name or ID");
6058 cmd_AddParm(ts, "-time", CMD_SINGLE, CMD_OPTIONAL, "dump from time");
6059 cmd_AddParm(ts, "-file", CMD_SINGLE, CMD_OPTIONAL, "dump file");
6060 cmd_AddParm(ts, "-server", CMD_SINGLE, CMD_OPTIONAL, "server");
6061 cmd_AddParm(ts, "-partition", CMD_SINGLE, CMD_OPTIONAL, "partition");
6062 cmd_AddParm(ts, "-clone", CMD_FLAG, CMD_OPTIONAL,
6063 "dump a clone of the volume");
6064 cmd_AddParm(ts, "-omitdirs", CMD_FLAG, CMD_OPTIONAL,
6065 "omit unchanged directories from an incremental dump");
6068 ts = cmd_CreateSyntax("restore", RestoreVolumeCmd, NULL,
6069 "restore a volume");
6070 cmd_AddParm(ts, "-server", CMD_SINGLE, 0, "machine name");
6071 cmd_AddParm(ts, "-partition", CMD_SINGLE, 0, "partition name");
6072 cmd_AddParm(ts, "-name", CMD_SINGLE, 0, "name of volume to be restored");
6073 cmd_AddParm(ts, "-file", CMD_SINGLE, CMD_OPTIONAL, "dump file");
6074 cmd_AddParm(ts, "-id", CMD_SINGLE, CMD_OPTIONAL, "volume ID");
6075 cmd_AddParm(ts, "-overwrite", CMD_SINGLE, CMD_OPTIONAL,
6076 "abort | full | incremental");
6077 cmd_AddParm(ts, "-offline", CMD_FLAG, CMD_OPTIONAL,
6078 "leave restored volume offline");
6079 cmd_AddParm(ts, "-readonly", CMD_FLAG, CMD_OPTIONAL,
6080 "make restored volume read-only");
6081 cmd_AddParm(ts, "-creation", CMD_SINGLE, CMD_OPTIONAL,
6082 "dump | keep | new");
6083 cmd_AddParm(ts, "-lastupdate", CMD_SINGLE, CMD_OPTIONAL,
6084 "dump | keep | new");
6085 cmd_AddParm(ts, "-nodelete", CMD_FLAG, CMD_OPTIONAL,
6086 "do not delete old site when restoring to a new site");
6089 ts = cmd_CreateSyntax("unlock", LockReleaseCmd, NULL,
6090 "release lock on VLDB entry for a volume");
6091 cmd_AddParm(ts, "-id", CMD_SINGLE, 0, "volume name or ID");
6094 ts = cmd_CreateSyntax("changeloc", ChangeLocation, NULL,
6095 "change an RW volume's location in the VLDB");
6096 cmd_AddParm(ts, "-server", CMD_SINGLE, 0,
6097 "machine name for new location");
6098 cmd_AddParm(ts, "-partition", CMD_SINGLE, 0,
6099 "partition name for new location");
6100 cmd_AddParm(ts, "-id", CMD_SINGLE, 0, "volume name or ID");
6103 ts = cmd_CreateSyntax("addsite", AddSite, NULL, "add a replication site");
6104 cmd_AddParm(ts, "-server", CMD_SINGLE, 0, "machine name for new site");
6105 cmd_AddParm(ts, "-partition", CMD_SINGLE, 0,
6106 "partition name for new site");
6107 cmd_AddParm(ts, "-id", CMD_SINGLE, 0, "volume name or ID");
6108 cmd_AddParm(ts, "-roid", CMD_SINGLE, CMD_OPTIONAL, "volume name or ID for RO");
6109 cmd_AddParm(ts, "-valid", CMD_FLAG, CMD_OPTIONAL, "publish as an up-to-date site in VLDB");
6112 ts = cmd_CreateSyntax("remsite", RemoveSite, NULL,
6113 "remove a replication site");
6114 cmd_AddParm(ts, "-server", CMD_SINGLE, 0, "machine name");
6115 cmd_AddParm(ts, "-partition", CMD_SINGLE, 0, "partition name");
6116 cmd_AddParm(ts, "-id", CMD_SINGLE, 0, "volume name or ID");
6119 ts = cmd_CreateSyntax("listpart", ListPartitions, NULL, "list partitions");
6120 cmd_AddParm(ts, "-server", CMD_SINGLE, 0, "machine name");
6123 ts = cmd_CreateSyntax("listvol", ListVolumes, NULL,
6124 "list volumes on server (bypass VLDB)");
6125 cmd_AddParm(ts, "-server", CMD_SINGLE, 0, "machine name");
6126 cmd_AddParm(ts, "-partition", CMD_SINGLE, CMD_OPTIONAL, "partition name");
6127 cmd_AddParm(ts, "-fast", CMD_FLAG, CMD_OPTIONAL, "minimal listing");
6128 cmd_AddParm(ts, "-long", CMD_FLAG, CMD_OPTIONAL,
6129 "list all normal volume fields");
6130 cmd_AddParm(ts, "-quiet", CMD_FLAG, CMD_OPTIONAL,
6131 "generate minimal information");
6132 cmd_AddParm(ts, "-extended", CMD_FLAG, CMD_OPTIONAL,
6133 "list extended volume fields");
6134 cmd_AddParm(ts, "-format", CMD_FLAG, CMD_OPTIONAL,
6135 "machine readable format");
6138 ts = cmd_CreateSyntax("syncvldb", SyncVldb, NULL,
6139 "synchronize VLDB with server");
6140 cmd_AddParm(ts, "-server", CMD_SINGLE, CMD_OPTIONAL, "machine name");
6141 cmd_AddParm(ts, "-partition", CMD_SINGLE, CMD_OPTIONAL, "partition name");
6142 cmd_AddParm(ts, "-volume", CMD_SINGLE, CMD_OPTIONAL, "volume name or ID");
6143 cmd_AddParm(ts, "-dryrun", CMD_FLAG, CMD_OPTIONAL, "report without updating");
6146 ts = cmd_CreateSyntax("syncserv", SyncServer, NULL,
6147 "synchronize server with VLDB");
6148 cmd_AddParm(ts, "-server", CMD_SINGLE, 0, "machine name");
6149 cmd_AddParm(ts, "-partition", CMD_SINGLE, CMD_OPTIONAL, "partition name");
6150 cmd_AddParm(ts, "-dryrun", CMD_FLAG, CMD_OPTIONAL, "report without updating");
6153 ts = cmd_CreateSyntax("examine", ExamineVolume, NULL,
6154 "everything about the volume");
6155 cmd_AddParm(ts, "-id", CMD_SINGLE, 0, "volume name or ID");
6156 cmd_AddParm(ts, "-extended", CMD_FLAG, CMD_OPTIONAL,
6157 "list extended volume fields");
6158 cmd_AddParm(ts, "-format", CMD_FLAG, CMD_OPTIONAL,
6159 "machine readable format");
6161 cmd_CreateAlias(ts, "volinfo");
6163 ts = cmd_CreateSyntax("setfields", SetFields, NULL,
6164 "change volume info fields");
6165 cmd_AddParm(ts, "-id", CMD_SINGLE, 0, "volume name or ID");
6166 cmd_AddParm(ts, "-maxquota", CMD_SINGLE, CMD_OPTIONAL, "quota (KB)");
6167 cmd_AddParm(ts, "-clearuse", CMD_FLAG, CMD_OPTIONAL, "clear dayUse");
6168 cmd_AddParm(ts, "-clearVolUpCounter", CMD_FLAG, CMD_OPTIONAL, "clear volUpdateCounter");
6171 ts = cmd_CreateSyntax("offline", volOffline, NULL, "force the volume status to offline");
6172 cmd_AddParm(ts, "-server", CMD_SINGLE, 0, "server name");
6173 cmd_AddParm(ts, "-partition", CMD_SINGLE, 0, "partition name");
6174 cmd_AddParm(ts, "-id", CMD_SINGLE, 0, "volume name or ID");
6175 cmd_AddParm(ts, "-sleep", CMD_SINGLE, CMD_OPTIONAL, "seconds to sleep");
6176 cmd_AddParm(ts, "-busy", CMD_FLAG, CMD_OPTIONAL, "busy volume");
6179 ts = cmd_CreateSyntax("online", volOnline, NULL, "force the volume status to online");
6180 cmd_AddParm(ts, "-server", CMD_SINGLE, 0, "server name");
6181 cmd_AddParm(ts, "-partition", CMD_SINGLE, 0, "partition name");
6182 cmd_AddParm(ts, "-id", CMD_SINGLE, 0, "volume name or ID");
6185 ts = cmd_CreateSyntax("zap", VolumeZap, NULL,
6186 "delete the volume, don't bother with VLDB");
6187 cmd_AddParm(ts, "-server", CMD_SINGLE, 0, "machine name");
6188 cmd_AddParm(ts, "-partition", CMD_SINGLE, 0, "partition name");
6189 cmd_AddParm(ts, "-id", CMD_SINGLE, 0, "volume ID");
6190 cmd_AddParm(ts, "-force", CMD_FLAG, CMD_OPTIONAL,
6191 "force deletion of bad volumes");
6192 cmd_AddParm(ts, "-backup", CMD_FLAG, CMD_OPTIONAL,
6193 "also delete backup volume if one is found");
6196 ts = cmd_CreateSyntax("status", VolserStatus, NULL,
6197 "report on volser status");
6198 cmd_AddParm(ts, "-server", CMD_SINGLE, 0, "machine name");
6201 ts = cmd_CreateSyntax("rename", RenameVolume, NULL, "rename a volume");
6202 cmd_AddParm(ts, "-oldname", CMD_SINGLE, 0, "old volume name ");
6203 cmd_AddParm(ts, "-newname", CMD_SINGLE, 0, "new volume name ");
6206 ts = cmd_CreateSyntax("listvldb", ListVLDB, NULL,
6207 "list volumes in the VLDB");
6208 cmd_AddParm(ts, "-name", CMD_SINGLE, CMD_OPTIONAL, "volume name or ID");
6209 cmd_AddParm(ts, "-server", CMD_SINGLE, CMD_OPTIONAL, "machine name");
6210 cmd_AddParm(ts, "-partition", CMD_SINGLE, CMD_OPTIONAL, "partition name");
6211 cmd_AddParm(ts, "-locked", CMD_FLAG, CMD_OPTIONAL, "locked volumes only");
6212 cmd_AddParm(ts, "-quiet", CMD_FLAG, CMD_OPTIONAL,
6213 "generate minimal information");
6214 cmd_AddParm(ts, "-nosort", CMD_FLAG, CMD_OPTIONAL,
6215 "do not alphabetically sort the volume names");
6218 ts = cmd_CreateSyntax("backupsys", BackSys, NULL, "en masse backups");
6219 cmd_AddParm(ts, "-prefix", CMD_LIST, CMD_OPTIONAL,
6220 "common prefix on volume(s)");
6221 cmd_AddParm(ts, "-server", CMD_SINGLE, CMD_OPTIONAL, "machine name");
6222 cmd_AddParm(ts, "-partition", CMD_SINGLE, CMD_OPTIONAL, "partition name");
6223 cmd_AddParm(ts, "-exclude", CMD_FLAG, CMD_OPTIONAL,
6224 "exclude common prefix volumes");
6225 cmd_AddParm(ts, "-xprefix", CMD_LIST, CMD_OPTIONAL,
6226 "negative prefix on volume(s)");
6227 cmd_AddParm(ts, "-dryrun", CMD_FLAG, CMD_OPTIONAL, "no action");
6230 ts = cmd_CreateSyntax("delentry", DeleteEntry, NULL,
6231 "delete VLDB entry for a volume");
6232 cmd_AddParm(ts, "-id", CMD_LIST, CMD_OPTIONAL, "volume name or ID");
6233 cmd_AddParm(ts, "-prefix", CMD_SINGLE, CMD_OPTIONAL,
6234 "prefix of the volume whose VLDB entry is to be deleted");
6235 cmd_AddParm(ts, "-server", CMD_SINGLE, CMD_OPTIONAL, "machine name");
6236 cmd_AddParm(ts, "-partition", CMD_SINGLE, CMD_OPTIONAL, "partition name");
6237 cmd_AddParm(ts, "-noexecute", CMD_FLAG, CMD_OPTIONAL,
6241 ts = cmd_CreateSyntax("partinfo", PartitionInfo, NULL,
6242 "list partition information");
6243 cmd_AddParm(ts, "-server", CMD_SINGLE, 0, "machine name");
6244 cmd_AddParm(ts, "-partition", CMD_SINGLE, CMD_OPTIONAL, "partition name");
6245 cmd_AddParm(ts, "-summary", CMD_FLAG, CMD_OPTIONAL,
6246 "print storage summary");
6249 ts = cmd_CreateSyntax("unlockvldb", UnlockVLDB, NULL,
6250 "unlock all the locked entries in the VLDB");
6251 cmd_AddParm(ts, "-server", CMD_SINGLE, CMD_OPTIONAL, "machine name");
6252 cmd_AddParm(ts, "-partition", CMD_SINGLE, CMD_OPTIONAL, "partition name");
6255 ts = cmd_CreateSyntax("lock", LockEntry, NULL,
6256 "lock VLDB entry for a volume");
6257 cmd_AddParm(ts, "-id", CMD_SINGLE, 0, "volume name or ID");
6260 ts = cmd_CreateSyntax("changeaddr", ChangeAddr, NULL,
6261 "change the IP address of a file server");
6262 cmd_AddParm(ts, "-oldaddr", CMD_SINGLE, 0, "original IP address");
6263 cmd_AddParm(ts, "-newaddr", CMD_SINGLE, CMD_OPTIONAL, "new IP address");
6264 cmd_AddParm(ts, "-remove", CMD_FLAG, CMD_OPTIONAL,
6265 "remove the IP address from the VLDB");
6268 ts = cmd_CreateSyntax("listaddrs", ListAddrs, NULL,
6269 "list the IP address of all file servers registered in the VLDB");
6270 cmd_AddParm(ts, "-uuid", CMD_SINGLE, CMD_OPTIONAL, "uuid of server");
6271 cmd_AddParm(ts, "-host", CMD_SINGLE, CMD_OPTIONAL, "address of host");
6272 cmd_AddParm(ts, "-printuuid", CMD_FLAG, CMD_OPTIONAL,
6273 "print uuid of hosts");
6276 ts = cmd_CreateSyntax("convertROtoRW", ConvertRO, NULL,
6277 "convert a RO volume into a RW volume (after loss of old RW volume)");
6278 cmd_AddParm(ts, "-server", CMD_SINGLE, 0, "machine name");
6279 cmd_AddParm(ts, "-partition", CMD_SINGLE, 0, "partition name");
6280 cmd_AddParm(ts, "-id", CMD_SINGLE, 0, "volume name or ID");
6281 cmd_AddParm(ts, "-force", CMD_FLAG, CMD_OPTIONAL, "don't ask");
6284 ts = cmd_CreateSyntax("size", Sizes, NULL,
6285 "obtain various sizes of the volume.");
6286 cmd_AddParm(ts, "-id", CMD_SINGLE, 0, "volume name or ID");
6287 cmd_AddParm(ts, "-partition", CMD_SINGLE, CMD_OPTIONAL, "partition name");
6288 cmd_AddParm(ts, "-server", CMD_SINGLE, CMD_OPTIONAL, "machine name");
6289 cmd_AddParm(ts, "-dump", CMD_FLAG, CMD_OPTIONAL,
6290 "Obtain the size of the dump");
6291 cmd_AddParm(ts, "-time", CMD_SINGLE, CMD_OPTIONAL, "dump from time");
6294 ts = cmd_CreateSyntax("endtrans", EndTrans, NULL,
6295 "end a volserver transaction");
6296 cmd_AddParm(ts, "-server", CMD_SINGLE, 0, "machine name");
6297 cmd_AddParm(ts, "-transaction", CMD_SINGLE, 0,
6301 ts = cmd_CreateSyntax("setaddrs", SetAddrs, NULL,
6302 "set the list of IP address for a given UUID in the VLDB");
6303 cmd_AddParm(ts, "-uuid", CMD_SINGLE, 0, "uuid of server");
6304 cmd_AddParm(ts, "-host", CMD_LIST, 0, "address of host");
6307 code = cmd_Dispatch(argc, argv);
6309 /* Shut down the ubik_client and rx connections */
6311 (void)ubik_ClientDestroy(cstruct);
6317 exit((code ? -1 : 0));