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"
20 #include <WINNT/afsreg.h>
24 #include <sys/statfs.h>
31 #include <rx/rx_globals.h>
33 #include <afs/vlserver.h>
34 #include <afs/cellconfig.h>
36 #include <afs/afsutil.h>
38 #include <afs/afsint.h>
43 #include <afs/ihandle.h>
44 #include <afs/vnode.h>
45 #include <afs/volume.h>
46 #include <afs/com_err.h>
50 #include "volser_internal.h"
51 #include "volser_prototypes.h"
52 #include "vsutils_prototypes.h"
53 #include "lockprocs_prototypes.h"
55 #ifdef HAVE_POSIX_REGEX
59 /* Local Prototypes */
60 int PrintDiagnostics(char *astring, afs_int32 acode);
61 int GetVolumeInfo(afs_uint32 volid, afs_uint32 *server, afs_int32 *part,
62 afs_int32 *voltype, struct nvldbentry *rentry);
74 #define COMMONPARMS cmd_Seek(ts, 12);\
75 cmd_AddParm(ts, "-cell", CMD_SINGLE, CMD_OPTIONAL, "cell name");\
76 cmd_AddParm(ts, "-noauth", CMD_FLAG, CMD_OPTIONAL, "don't authenticate");\
77 cmd_AddParm(ts, "-localauth",CMD_FLAG,CMD_OPTIONAL,"use server tickets");\
78 cmd_AddParm(ts, "-verbose", CMD_FLAG, CMD_OPTIONAL, "verbose");\
79 cmd_AddParm(ts, "-encrypt", CMD_FLAG, CMD_OPTIONAL, "encrypt commands");\
80 cmd_AddParm(ts, "-noresolve", CMD_FLAG, CMD_OPTIONAL, "don't resolve addresses"); \
81 cmd_AddParm(ts, "-config", CMD_SINGLE, CMD_OPTIONAL, "config location"); \
83 #define ERROR_EXIT(code) do { \
89 struct rx_connection *tconn;
91 extern struct ubik_client *cstruct;
94 static struct tqHead busyHead, notokHead;
97 qInit(struct tqHead *ahead)
99 memset(ahead, 0, sizeof(struct tqHead));
105 qPut(struct tqHead *ahead, afs_uint32 volid)
109 elem = (struct tqElem *)malloc(sizeof(struct tqElem));
110 elem->next = ahead->next;
118 qGet(struct tqHead *ahead, afs_uint32 *volid)
122 if (ahead->count <= 0)
124 *volid = ahead->next->volid;
126 ahead->next = tmp->next;
132 /* returns 1 if <filename> exists else 0 */
134 FileExists(char *filename)
140 code = usd_Open(filename, USD_OPEN_RDONLY, 0, &ufd);
144 code = USD_IOCTL(ufd, USD_IOCTL_GETSIZE, &size);
152 /* returns 1 if <name> doesnot end in .readonly or .backup, else 0 */
154 VolNameOK(char *name)
159 total = strlen(name);
160 if (!strcmp(&name[total - 9], ".readonly")) {
162 } else if (!strcmp(&name[total - 7], ".backup")) {
169 /* return 1 if name is a number else 0 */
171 IsNumeric(char *name)
180 for (i = 0; i < len; i++) {
181 if (*ptr < '0' || *ptr > '9') {
193 * Parse a server dotted address and return the address in network byte order
196 GetServerNoresolve(char *aname)
202 code = sscanf(aname, "%d.%d.%d.%d", &b1, &b2, &b3, &b4);
204 addr = (b1 << 24) | (b2 << 16) | (b3 << 8) | b4;
205 addr = htonl(addr); /* convert to network byte order */
211 * Parse a server name/address and return the address in network byte order
214 GetServer(char *aname)
217 afs_uint32 addr; /* in network byte order */
219 char hostname[MAXHOSTCHARS];
221 if ((addr = GetServerNoresolve(aname)) == 0) {
222 th = gethostbyname(aname);
225 memcpy(&addr, th->h_addr, sizeof(addr));
228 if (rx_IsLoopbackAddr(ntohl(addr))) { /* local host */
229 code = gethostname(hostname, MAXHOSTCHARS);
232 th = gethostbyname(hostname);
235 memcpy(&addr, th->h_addr, sizeof(addr));
242 GetVolumeType(char *aname)
245 if (!strcmp(aname, "ro"))
247 else if (!strcmp(aname, "rw"))
249 else if (!strcmp(aname, "bk"))
256 IsPartValid(afs_int32 partId, afs_uint32 server, afs_int32 *code)
258 struct partList dummyPartList;
264 *code = UV_ListPartitions(server, &dummyPartList, &cnt);
267 for (i = 0; i < cnt; i++) {
268 if (dummyPartList.partFlags[i] & PARTVALID)
269 if (dummyPartList.partId[i] == partId)
277 /*sends the contents of file associated with <fd> and <blksize> to Rx Stream
278 * associated with <call> */
280 SendFile(usd_handle_t ufd, struct rx_call *call, long blksize)
282 char *buffer = (char *)0;
287 buffer = (char *)malloc(blksize);
289 fprintf(STDERR, "malloc failed\n");
293 while (!error && !done) {
294 #ifndef AFS_NT40_ENV /* NT csn't select on non-socket fd's */
297 FD_SET((intptr_t)(ufd->handle), &in);
298 /* don't timeout if read blocks */
299 #if defined(AFS_PTHREAD_ENV)
300 select(((intptr_t)(ufd->handle)) + 1, &in, 0, 0, 0);
302 IOMGR_Select(((intptr_t)(ufd->handle)) + 1, &in, 0, 0, 0);
305 error = USD_READ(ufd, buffer, blksize, &nbytes);
307 fprintf(STDERR, "File system read failed: %s\n",
308 afs_error_message(error));
315 if (rx_Write(call, buffer, nbytes) != nbytes) {
325 /* function invoked by UV_RestoreVolume, reads the data from rx_trx_stream and
326 * writes it out to the volume. */
328 WriteData(struct rx_call *call, void *rock)
330 char *filename = (char *) rock;
333 afs_int32 error, code;
335 afs_int64 currOffset;
341 if (!filename || !*filename) {
342 usd_StandardInput(&ufd);
346 code = usd_Open(filename, USD_OPEN_RDONLY, 0, &ufd);
349 code = USD_IOCTL(ufd, USD_IOCTL_GETBLKSIZE, &blksize);
352 fprintf(STDERR, "Could not access file '%s': %s\n", filename,
353 afs_error_message(code));
357 /* test if we have a valid dump */
358 USD_SEEK(ufd, 0, SEEK_END, &currOffset);
359 USD_SEEK(ufd, currOffset - sizeof(afs_uint32), SEEK_SET, &currOffset);
360 USD_READ(ufd, (char *)&buffer, sizeof(afs_uint32), &got);
361 if ((got != sizeof(afs_uint32)) || (ntohl(buffer) != DUMPENDMAGIC)) {
362 fprintf(STDERR, "Signature missing from end of file '%s'\n", filename);
366 USD_SEEK(ufd, 0, SEEK_SET, &currOffset);
368 code = SendFile(ufd, call, blksize);
375 code = USD_CLOSE(ufd);
377 fprintf(STDERR, "Could not close dump file %s\n",
378 (filename && *filename) ? filename : "STDOUT");
386 /* Receive data from <call> stream into file associated
387 * with <fd> <blksize>
390 ReceiveFile(usd_handle_t ufd, struct rx_call *call, long blksize)
394 afs_uint32 bytesleft, w;
397 buffer = (char *)malloc(blksize);
399 fprintf(STDERR, "memory allocation failed\n");
403 while ((bytesread = rx_Read(call, buffer, blksize)) > 0) {
404 for (bytesleft = bytesread; bytesleft; bytesleft -= w) {
405 #ifndef AFS_NT40_ENV /* NT csn't select on non-socket fd's */
408 FD_SET((intptr_t)(ufd->handle), &out);
409 /* don't timeout if write blocks */
410 #if defined(AFS_PTHREAD_ENV)
411 select(((intptr_t)(ufd->handle)) + 1, &out, 0, 0, 0);
413 IOMGR_Select(((intptr_t)(ufd->handle)) + 1, 0, &out, 0, 0);
417 USD_WRITE(ufd, &buffer[bytesread - bytesleft], bytesleft, &w);
419 fprintf(STDERR, "File system write failed: %s\n",
420 afs_error_message(error));
433 DumpFunction(struct rx_call *call, void *rock)
435 char *filename = (char *)rock;
436 usd_handle_t ufd; /* default is to stdout */
437 afs_int32 error = 0, code;
442 /* Open the output file */
443 if (!filename || !*filename) {
444 usd_StandardOutput(&ufd);
449 usd_Open(filename, USD_OPEN_CREATE | USD_OPEN_RDWR, 0666, &ufd);
453 code = USD_IOCTL(ufd, USD_IOCTL_SETSIZE, &size);
456 code = USD_IOCTL(ufd, USD_IOCTL_GETBLKSIZE, &blksize);
459 fprintf(STDERR, "Could not create file '%s': %s\n", filename,
460 afs_error_message(code));
461 ERROR_EXIT(VOLSERBADOP);
465 code = ReceiveFile(ufd, call, blksize);
470 /* Close the output file */
472 code = USD_CLOSE(ufd);
474 fprintf(STDERR, "Could not close dump file %s\n",
475 (filename && *filename) ? filename : "STDIN");
485 DisplayFormat(volintInfo *pntr, afs_uint32 server, afs_int32 part,
486 int *totalOK, int *totalNotOK, int *totalBusy, int fast,
487 int longlist, int disp)
493 fprintf(STDOUT, "%-10lu\n", (unsigned long)pntr->volid);
494 } else if (longlist) {
495 if (pntr->status == VOK) {
496 fprintf(STDOUT, "%-32s ", pntr->name);
497 fprintf(STDOUT, "%10lu ", (unsigned long)pntr->volid);
499 fprintf(STDOUT, "RW ");
501 fprintf(STDOUT, "RO ");
503 fprintf(STDOUT, "BK ");
504 fprintf(STDOUT, "%10d K ", pntr->size);
505 if (pntr->inUse == 1) {
506 fprintf(STDOUT, "On-line");
509 fprintf(STDOUT, "Off-line");
512 if (pntr->needsSalvaged == 1)
513 fprintf(STDOUT, "**needs salvage**");
514 fprintf(STDOUT, "\n");
515 MapPartIdIntoName(part, pname);
516 fprintf(STDOUT, " %s %s \n", hostutil_GetNameByINet(server),
518 fprintf(STDOUT, " RWrite %10lu ROnly %10lu Backup %10lu \n",
519 (unsigned long)pntr->parentID,
520 (unsigned long)pntr->cloneID,
521 (unsigned long)pntr->backupID);
522 fprintf(STDOUT, " MaxQuota %10d K \n", pntr->maxquota);
523 t = pntr->creationDate;
524 fprintf(STDOUT, " Creation %s",
527 fprintf(STDOUT, " Copy %s",
530 t = pntr->backupDate;
532 fprintf(STDOUT, " Backup Never\n");
534 fprintf(STDOUT, " Backup %s",
537 t = pntr->accessDate;
539 fprintf(STDOUT, " Last Access %s",
542 t = pntr->updateDate;
544 fprintf(STDOUT, " Last Update Never\n");
546 fprintf(STDOUT, " Last Update %s",
549 " %d accesses in the past day (i.e., vnode references)\n",
551 } else if (pntr->status == VBUSY) {
553 qPut(&busyHead, pntr->volid);
555 fprintf(STDOUT, "**** Volume %lu is busy ****\n",
556 (unsigned long)pntr->volid);
559 qPut(¬okHead, pntr->volid);
561 fprintf(STDOUT, "**** Could not attach volume %lu ****\n",
562 (unsigned long)pntr->volid);
564 fprintf(STDOUT, "\n");
565 } else { /* default listing */
566 if (pntr->status == VOK) {
567 fprintf(STDOUT, "%-32s ", pntr->name);
568 fprintf(STDOUT, "%10lu ", (unsigned long)pntr->volid);
570 fprintf(STDOUT, "RW ");
572 fprintf(STDOUT, "RO ");
574 fprintf(STDOUT, "BK ");
575 fprintf(STDOUT, "%10d K ", pntr->size);
576 if (pntr->inUse == 1) {
577 fprintf(STDOUT, "On-line");
580 fprintf(STDOUT, "Off-line");
583 if (pntr->needsSalvaged == 1)
584 fprintf(STDOUT, "**needs salvage**");
585 fprintf(STDOUT, "\n");
586 } else if (pntr->status == VBUSY) {
588 qPut(&busyHead, pntr->volid);
590 fprintf(STDOUT, "**** Volume %lu is busy ****\n",
591 (unsigned long)pntr->volid);
594 qPut(¬okHead, pntr->volid);
596 fprintf(STDOUT, "**** Could not attach volume %lu ****\n",
597 (unsigned long)pntr->volid);
602 /*------------------------------------------------------------------------
603 * PRIVATE XDisplayFormat
606 * Display the contents of one extended volume info structure.
609 * a_xInfoP : Ptr to extended volume info struct to print.
610 * a_servID : Server ID to print.
611 * a_partID : Partition ID to print.
612 * a_totalOKP : Ptr to total-OK counter.
613 * a_totalNotOKP : Ptr to total-screwed counter.
614 * a_totalBusyP : Ptr to total-busy counter.
615 * a_fast : Fast listing?
616 * a_int32 : Int32 listing?
617 * a_showProblems : Show volume problems?
623 * Nothing interesting.
627 *------------------------------------------------------------------------*/
630 XDisplayFormat(volintXInfo *a_xInfoP, afs_uint32 a_servID, afs_int32 a_partID,
631 int *a_totalOKP, int *a_totalNotOKP, int *a_totalBusyP,
632 int a_fast, int a_int32, int a_showProblems)
633 { /*XDisplayFormat */
641 fprintf(STDOUT, "%-10lu\n", (unsigned long)a_xInfoP->volid);
642 } else if (a_int32) {
644 * Fully-detailed listing.
646 if (a_xInfoP->status == VOK) {
648 * Volume's status is OK - all the fields are valid.
650 fprintf(STDOUT, "%-32s ", a_xInfoP->name);
651 fprintf(STDOUT, "%10lu ", (unsigned long)a_xInfoP->volid);
652 if (a_xInfoP->type == 0)
653 fprintf(STDOUT, "RW ");
654 if (a_xInfoP->type == 1)
655 fprintf(STDOUT, "RO ");
656 if (a_xInfoP->type == 2)
657 fprintf(STDOUT, "BK ");
658 fprintf(STDOUT, "%10d K used ", a_xInfoP->size);
659 fprintf(STDOUT, "%d files ", a_xInfoP->filecount);
660 if (a_xInfoP->inUse == 1) {
661 fprintf(STDOUT, "On-line");
664 fprintf(STDOUT, "Off-line");
667 fprintf(STDOUT, "\n");
668 MapPartIdIntoName(a_partID, pname);
669 fprintf(STDOUT, " %s %s \n", hostutil_GetNameByINet(a_servID),
671 fprintf(STDOUT, " RWrite %10lu ROnly %10lu Backup %10lu \n",
672 (unsigned long)a_xInfoP->parentID,
673 (unsigned long)a_xInfoP->cloneID,
674 (unsigned long)a_xInfoP->backupID);
675 fprintf(STDOUT, " MaxQuota %10d K \n", a_xInfoP->maxquota);
677 t = a_xInfoP->creationDate;
678 fprintf(STDOUT, " Creation %s",
681 t = a_xInfoP->copyDate;
682 fprintf(STDOUT, " Copy %s",
685 t = a_xInfoP->backupDate;
687 fprintf(STDOUT, " Backup Never\n");
689 fprintf(STDOUT, " Backup %s",
692 t = a_xInfoP->accessDate;
694 fprintf(STDOUT, " Last Access %s",
697 t = a_xInfoP->updateDate;
699 fprintf(STDOUT, " Last Update Never\n");
701 fprintf(STDOUT, " Last Update %s",
704 " %d accesses in the past day (i.e., vnode references)\n",
708 * Print all the read/write and authorship stats.
710 fprintf(STDOUT, "\n Raw Read/Write Stats\n");
712 " |-------------------------------------------|\n");
714 " | Same Network | Diff Network |\n");
716 " |----------|----------|----------|----------|\n");
718 " | Total | Auth | Total | Auth |\n");
720 " |----------|----------|----------|----------|\n");
721 fprintf(STDOUT, "Reads | %8d | %8d | %8d | %8d |\n",
722 a_xInfoP->stat_reads[VOLINT_STATS_SAME_NET],
723 a_xInfoP->stat_reads[VOLINT_STATS_SAME_NET_AUTH],
724 a_xInfoP->stat_reads[VOLINT_STATS_DIFF_NET],
725 a_xInfoP->stat_reads[VOLINT_STATS_DIFF_NET_AUTH]);
726 fprintf(STDOUT, "Writes | %8d | %8d | %8d | %8d |\n",
727 a_xInfoP->stat_writes[VOLINT_STATS_SAME_NET],
728 a_xInfoP->stat_writes[VOLINT_STATS_SAME_NET_AUTH],
729 a_xInfoP->stat_writes[VOLINT_STATS_DIFF_NET],
730 a_xInfoP->stat_writes[VOLINT_STATS_DIFF_NET_AUTH]);
732 " |-------------------------------------------|\n\n");
735 " Writes Affecting Authorship\n");
737 " |-------------------------------------------|\n");
739 " | File Authorship | Directory Authorship|\n");
741 " |----------|----------|----------|----------|\n");
743 " | Same | Diff | Same | Diff |\n");
745 " |----------|----------|----------|----------|\n");
746 fprintf(STDOUT, "0-60 sec | %8d | %8d | %8d | %8d |\n",
747 a_xInfoP->stat_fileSameAuthor[VOLINT_STATS_TIME_IDX_0],
748 a_xInfoP->stat_fileDiffAuthor[VOLINT_STATS_TIME_IDX_0],
749 a_xInfoP->stat_dirSameAuthor[VOLINT_STATS_TIME_IDX_0],
750 a_xInfoP->stat_dirDiffAuthor[VOLINT_STATS_TIME_IDX_0]);
751 fprintf(STDOUT, "1-10 min | %8d | %8d | %8d | %8d |\n",
752 a_xInfoP->stat_fileSameAuthor[VOLINT_STATS_TIME_IDX_1],
753 a_xInfoP->stat_fileDiffAuthor[VOLINT_STATS_TIME_IDX_1],
754 a_xInfoP->stat_dirSameAuthor[VOLINT_STATS_TIME_IDX_1],
755 a_xInfoP->stat_dirDiffAuthor[VOLINT_STATS_TIME_IDX_1]);
756 fprintf(STDOUT, "10min-1hr | %8d | %8d | %8d | %8d |\n",
757 a_xInfoP->stat_fileSameAuthor[VOLINT_STATS_TIME_IDX_2],
758 a_xInfoP->stat_fileDiffAuthor[VOLINT_STATS_TIME_IDX_2],
759 a_xInfoP->stat_dirSameAuthor[VOLINT_STATS_TIME_IDX_2],
760 a_xInfoP->stat_dirDiffAuthor[VOLINT_STATS_TIME_IDX_2]);
761 fprintf(STDOUT, "1hr-1day | %8d | %8d | %8d | %8d |\n",
762 a_xInfoP->stat_fileSameAuthor[VOLINT_STATS_TIME_IDX_3],
763 a_xInfoP->stat_fileDiffAuthor[VOLINT_STATS_TIME_IDX_3],
764 a_xInfoP->stat_dirSameAuthor[VOLINT_STATS_TIME_IDX_3],
765 a_xInfoP->stat_dirDiffAuthor[VOLINT_STATS_TIME_IDX_3]);
766 fprintf(STDOUT, "1day-1wk | %8d | %8d | %8d | %8d |\n",
767 a_xInfoP->stat_fileSameAuthor[VOLINT_STATS_TIME_IDX_4],
768 a_xInfoP->stat_fileDiffAuthor[VOLINT_STATS_TIME_IDX_4],
769 a_xInfoP->stat_dirSameAuthor[VOLINT_STATS_TIME_IDX_4],
770 a_xInfoP->stat_dirDiffAuthor[VOLINT_STATS_TIME_IDX_4]);
771 fprintf(STDOUT, "> 1wk | %8d | %8d | %8d | %8d |\n",
772 a_xInfoP->stat_fileSameAuthor[VOLINT_STATS_TIME_IDX_5],
773 a_xInfoP->stat_fileDiffAuthor[VOLINT_STATS_TIME_IDX_5],
774 a_xInfoP->stat_dirSameAuthor[VOLINT_STATS_TIME_IDX_5],
775 a_xInfoP->stat_dirDiffAuthor[VOLINT_STATS_TIME_IDX_5]);
777 " |-------------------------------------------|\n");
778 } /*Volume status OK */
779 else if (a_xInfoP->status == VBUSY) {
781 qPut(&busyHead, a_xInfoP->volid);
783 fprintf(STDOUT, "**** Volume %lu is busy ****\n",
784 (unsigned long)a_xInfoP->volid);
788 qPut(¬okHead, a_xInfoP->volid);
790 fprintf(STDOUT, "**** Could not attach volume %lu ****\n",
791 (unsigned long)a_xInfoP->volid);
792 } /*Screwed volume */
793 fprintf(STDOUT, "\n");
799 if (a_xInfoP->status == VOK) {
800 fprintf(STDOUT, "%-32s ", a_xInfoP->name);
801 fprintf(STDOUT, "%10lu ", (unsigned long)a_xInfoP->volid);
802 if (a_xInfoP->type == 0)
803 fprintf(STDOUT, "RW ");
804 if (a_xInfoP->type == 1)
805 fprintf(STDOUT, "RO ");
806 if (a_xInfoP->type == 2)
807 fprintf(STDOUT, "BK ");
808 fprintf(STDOUT, "%10d K ", a_xInfoP->size);
809 if (a_xInfoP->inUse == 1) {
810 fprintf(STDOUT, "On-line");
813 fprintf(STDOUT, "Off-line");
816 fprintf(STDOUT, "\n");
818 else if (a_xInfoP->status == VBUSY) {
820 qPut(&busyHead, a_xInfoP->volid);
822 fprintf(STDOUT, "**** Volume %lu is busy ****\n",
823 (unsigned long)a_xInfoP->volid);
827 qPut(¬okHead, a_xInfoP->volid);
829 fprintf(STDOUT, "**** Could not attach volume %lu ****\n",
830 (unsigned long)a_xInfoP->volid);
831 } /*Screwed volume */
832 } /*Default listing */
833 } /*XDisplayFormat */
835 /*------------------------------------------------------------------------
836 * PRIVATE XDisplayFormat2
839 * Display the formated contents of one extended volume info structure.
842 * a_xInfoP : Ptr to extended volume info struct to print.
843 * a_servID : Server ID to print.
844 * a_partID : Partition ID to print.
845 * a_totalOKP : Ptr to total-OK counter.
846 * a_totalNotOKP : Ptr to total-screwed counter.
847 * a_totalBusyP : Ptr to total-busy counter.
848 * a_fast : Fast listing?
849 * a_int32 : Int32 listing?
850 * a_showProblems : Show volume problems?
856 * Nothing interesting.
860 *------------------------------------------------------------------------*/
863 XDisplayFormat2(volintXInfo *a_xInfoP, afs_uint32 a_servID, afs_int32 a_partID,
864 int *a_totalOKP, int *a_totalNotOKP, int *a_totalBusyP,
865 int a_fast, int a_int32, int a_showProblems)
866 { /*XDisplayFormat */
872 fprintf(STDOUT, "vold_id\t%-10lu\n", (unsigned long)a_xInfoP->volid);
873 } else if (a_int32) {
875 * Fully-detailed listing.
877 if (a_xInfoP->status == VOK) {
879 * Volume's status is OK - all the fields are valid.
882 static long server_cache = -1, partition_cache = -1;
883 static char hostname[256], address[32], pname[16];
884 int i,ai[] = {VOLINT_STATS_TIME_IDX_0,VOLINT_STATS_TIME_IDX_1,VOLINT_STATS_TIME_IDX_2,
885 VOLINT_STATS_TIME_IDX_3,VOLINT_STATS_TIME_IDX_4,VOLINT_STATS_TIME_IDX_5};
887 if (a_servID != server_cache) {
891 strcpy(hostname, hostutil_GetNameByINet(a_servID));
892 strcpy(address, inet_ntoa(s));
893 server_cache = a_servID;
895 if (a_partID != partition_cache) {
896 MapPartIdIntoName(a_partID, pname);
897 partition_cache = a_partID;
900 fprintf(STDOUT, "name\t\t%s\n", a_xInfoP->name);
901 fprintf(STDOUT, "id\t\t%lu\n", afs_printable_uint32_lu(a_xInfoP->volid));
902 fprintf(STDOUT, "serv\t\t%s\t%s\n", address, hostname);
903 fprintf(STDOUT, "part\t\t%s\n", pname);
904 fprintf(STDOUT, "status\t\tOK\n");
905 fprintf(STDOUT, "backupID\t%lu\n",
906 afs_printable_uint32_lu(a_xInfoP->backupID));
907 fprintf(STDOUT, "parentID\t%lu\n",
908 afs_printable_uint32_lu(a_xInfoP->parentID));
909 fprintf(STDOUT, "cloneID\t\t%lu\n",
910 afs_printable_uint32_lu(a_xInfoP->cloneID));
911 fprintf(STDOUT, "inUse\t\t%s\n", a_xInfoP->inUse ? "Y" : "N");
912 switch (a_xInfoP->type) {
914 fprintf(STDOUT, "type\t\tRW\n");
917 fprintf(STDOUT, "type\t\tRO\n");
920 fprintf(STDOUT, "type\t\tBK\n");
923 fprintf(STDOUT, "type\t\t?\n");
926 t = a_xInfoP->creationDate;
927 fprintf(STDOUT, "creationDate\t%-9lu\t%s",
928 afs_printable_uint32_lu(a_xInfoP->creationDate),
931 t = a_xInfoP->accessDate;
932 fprintf(STDOUT, "accessDate\t%-9lu\t%s",
933 afs_printable_uint32_lu(a_xInfoP->accessDate),
936 t = a_xInfoP->updateDate;
937 fprintf(STDOUT, "updateDate\t%-9lu\t%s",
938 afs_printable_uint32_lu(a_xInfoP->updateDate),
941 t = a_xInfoP->backupDate;
942 fprintf(STDOUT, "backupDate\t%-9lu\t%s",
943 afs_printable_uint32_lu(a_xInfoP->backupDate),
946 t = a_xInfoP->copyDate;
947 fprintf(STDOUT, "copyDate\t%-9lu\t%s",
948 afs_printable_uint32_lu(a_xInfoP->copyDate),
951 fprintf(STDOUT, "diskused\t%u\n", a_xInfoP->size);
952 fprintf(STDOUT, "maxquota\t%u\n", a_xInfoP->maxquota);
954 fprintf(STDOUT, "filecount\t%u\n", a_xInfoP->filecount);
955 fprintf(STDOUT, "dayUse\t\t%u\n", a_xInfoP->dayUse);
959 fprintf(STDOUT,"reads_same_net\t%8d\n",a_xInfoP->stat_reads[VOLINT_STATS_SAME_NET]);
960 fprintf(STDOUT,"reads_same_net_auth\t%8d\n",a_xInfoP->stat_reads[VOLINT_STATS_SAME_NET_AUTH]);
961 fprintf(STDOUT,"reads_diff_net\t%8d\n",a_xInfoP->stat_reads[VOLINT_STATS_DIFF_NET]);
962 fprintf(STDOUT,"reads_diff_net_auth\t%8d\n",a_xInfoP->stat_reads[VOLINT_STATS_DIFF_NET_AUTH]);
964 fprintf(STDOUT,"writes_same_net\t%8d\n",a_xInfoP->stat_writes[VOLINT_STATS_SAME_NET]);
965 fprintf(STDOUT,"writes_same_net_auth\t%8d\n",a_xInfoP->stat_writes[VOLINT_STATS_SAME_NET_AUTH]);
966 fprintf(STDOUT,"writes_diff_net\t%8d\n",a_xInfoP->stat_writes[VOLINT_STATS_DIFF_NET]);
967 fprintf(STDOUT,"writes_diff_net_auth\t%8d\n",a_xInfoP->stat_writes[VOLINT_STATS_DIFF_NET_AUTH]);
971 fprintf(STDOUT,"file_same_author_idx_%d\t%8d\n",i+1,a_xInfoP->stat_fileSameAuthor[ai[i]]);
972 fprintf(STDOUT,"file_diff_author_idx_%d\t%8d\n",i+1,a_xInfoP->stat_fileDiffAuthor[ai[i]]);
973 fprintf(STDOUT,"dir_same_author_idx_%d\t%8d\n",i+1,a_xInfoP->stat_dirSameAuthor[ai[i]]);
974 fprintf(STDOUT,"dir_dif_author_idx_%d\t%8d\n",i+1,a_xInfoP->stat_dirDiffAuthor[ai[i]]);
977 } /*Volume status OK */
978 else if (a_xInfoP->status == VBUSY) {
980 qPut(&busyHead, a_xInfoP->volid);
982 fprintf(STDOUT, "BUSY_VOL\t%lu\n",
983 (unsigned long)a_xInfoP->volid);
987 qPut(¬okHead, a_xInfoP->volid);
989 fprintf(STDOUT, "COULD_NOT_ATTACH\t%lu\n",
990 (unsigned long)a_xInfoP->volid);
991 } /*Screwed volume */
997 if (a_xInfoP->status == VOK) {
998 fprintf(STDOUT, "name\t%-32s\n", a_xInfoP->name);
999 fprintf(STDOUT, "volID\t%10lu\n", (unsigned long)a_xInfoP->volid);
1000 if (a_xInfoP->type == 0)
1001 fprintf(STDOUT, "type\tRW\n");
1002 if (a_xInfoP->type == 1)
1003 fprintf(STDOUT, "type\tRO\n");
1004 if (a_xInfoP->type == 2)
1005 fprintf(STDOUT, "type\tBK\n");
1006 fprintf(STDOUT, "size\t%10dK\n", a_xInfoP->size);
1008 fprintf(STDOUT, "inUse\t%d\n",a_xInfoP->inUse);
1009 if (a_xInfoP->inUse == 1)
1015 else if (a_xInfoP->status == VBUSY) {
1017 qPut(&busyHead, a_xInfoP->volid);
1019 fprintf(STDOUT, "VOLUME_BUSY\t%lu\n",
1020 (unsigned long)a_xInfoP->volid);
1024 qPut(¬okHead, a_xInfoP->volid);
1026 fprintf(STDOUT, "COULD_NOT_ATTACH_VOLUME\t%lu\n",
1027 (unsigned long)a_xInfoP->volid);
1028 } /*Screwed volume */
1029 } /*Default listing */
1030 } /*XDisplayFormat */
1033 DisplayFormat2(long server, long partition, volintInfo *pntr)
1035 static long server_cache = -1, partition_cache = -1;
1036 static char hostname[256], address[32], pname[16];
1039 if (server != server_cache) {
1043 strcpy(hostname, hostutil_GetNameByINet(server));
1044 strcpy(address, inet_ntoa(s));
1045 server_cache = server;
1047 if (partition != partition_cache) {
1048 MapPartIdIntoName(partition, pname);
1049 partition_cache = partition;
1052 if (pntr->status == VOK)
1053 fprintf(STDOUT, "name\t\t%s\n", pntr->name);
1055 fprintf(STDOUT, "id\t\t%lu\n",
1056 afs_printable_uint32_lu(pntr->volid));
1057 fprintf(STDOUT, "serv\t\t%s\t%s\n", address, hostname);
1058 fprintf(STDOUT, "part\t\t%s\n", pname);
1059 switch (pntr->status) {
1061 fprintf(STDOUT, "status\t\tOK\n");
1064 fprintf(STDOUT, "status\t\tBUSY\n");
1067 fprintf(STDOUT, "status\t\tUNATTACHABLE\n");
1070 fprintf(STDOUT, "backupID\t%lu\n",
1071 afs_printable_uint32_lu(pntr->backupID));
1072 fprintf(STDOUT, "parentID\t%lu\n",
1073 afs_printable_uint32_lu(pntr->parentID));
1074 fprintf(STDOUT, "cloneID\t\t%lu\n",
1075 afs_printable_uint32_lu(pntr->cloneID));
1076 fprintf(STDOUT, "inUse\t\t%s\n", pntr->inUse ? "Y" : "N");
1077 fprintf(STDOUT, "needsSalvaged\t%s\n", pntr->needsSalvaged ? "Y" : "N");
1078 /* 0xD3 is from afs/volume.h since I had trouble including the file */
1079 fprintf(STDOUT, "destroyMe\t%s\n", pntr->destroyMe == 0xD3 ? "Y" : "N");
1080 switch (pntr->type) {
1082 fprintf(STDOUT, "type\t\tRW\n");
1085 fprintf(STDOUT, "type\t\tRO\n");
1088 fprintf(STDOUT, "type\t\tBK\n");
1091 fprintf(STDOUT, "type\t\t?\n");
1094 t = pntr->creationDate;
1095 fprintf(STDOUT, "creationDate\t%-9lu\t%s",
1096 afs_printable_uint32_lu(pntr->creationDate),
1099 t = pntr->accessDate;
1100 fprintf(STDOUT, "accessDate\t%-9lu\t%s",
1101 afs_printable_uint32_lu(pntr->accessDate),
1104 t = pntr->updateDate;
1105 fprintf(STDOUT, "updateDate\t%-9lu\t%s",
1106 afs_printable_uint32_lu(pntr->updateDate),
1109 t = pntr->backupDate;
1110 fprintf(STDOUT, "backupDate\t%-9lu\t%s",
1111 afs_printable_uint32_lu(pntr->backupDate),
1115 fprintf(STDOUT, "copyDate\t%-9lu\t%s",
1116 afs_printable_uint32_lu(pntr->copyDate),
1119 fprintf(STDOUT, "flags\t\t%#lx\t(Optional)\n",
1120 afs_printable_uint32_lu(pntr->flags));
1121 fprintf(STDOUT, "diskused\t%u\n", pntr->size);
1122 fprintf(STDOUT, "maxquota\t%u\n", pntr->maxquota);
1123 fprintf(STDOUT, "minquota\t%lu\t(Optional)\n",
1124 afs_printable_uint32_lu(pntr->spare0));
1125 fprintf(STDOUT, "filecount\t%u\n", pntr->filecount);
1126 fprintf(STDOUT, "dayUse\t\t%u\n", pntr->dayUse);
1127 fprintf(STDOUT, "weekUse\t\t%lu\t(Optional)\n",
1128 afs_printable_uint32_lu(pntr->spare1));
1129 fprintf(STDOUT, "spare2\t\t%lu\t(Optional)\n",
1130 afs_printable_uint32_lu(pntr->spare2));
1131 fprintf(STDOUT, "spare3\t\t%lu\t(Optional)\n",
1132 afs_printable_uint32_lu(pntr->spare3));
1137 DisplayVolumes2(long server, long partition, volintInfo *pntr, long count)
1141 for (i = 0; i < count; i++) {
1142 fprintf(STDOUT, "BEGIN_OF_ENTRY\n");
1143 DisplayFormat2(server, partition, pntr);
1144 fprintf(STDOUT, "END_OF_ENTRY\n\n");
1151 DisplayVolumes(afs_uint32 server, afs_int32 part, volintInfo *pntr,
1152 afs_int32 count, afs_int32 longlist, afs_int32 fast,
1155 int totalOK, totalNotOK, totalBusy, i;
1156 afs_uint32 volid = 0;
1163 for (i = 0; i < count; i++) {
1164 DisplayFormat(pntr, server, part, &totalOK, &totalNotOK, &totalBusy,
1169 while (busyHead.count) {
1170 qGet(&busyHead, &volid);
1171 fprintf(STDOUT, "**** Volume %lu is busy ****\n",
1172 (unsigned long)volid);
1176 while (notokHead.count) {
1177 qGet(¬okHead, &volid);
1178 fprintf(STDOUT, "**** Could not attach volume %lu ****\n",
1179 (unsigned long)volid);
1183 fprintf(STDOUT, "\n");
1186 "Total volumes onLine %d ; Total volumes offLine %d ; Total busy %d\n\n",
1187 totalOK, totalNotOK, totalBusy);
1191 /*------------------------------------------------------------------------
1192 * PRIVATE XDisplayVolumes
1195 * Display extended volume information.
1198 * a_servID : Pointer to the Rx call we're performing.
1199 * a_partID : Partition for which we want the extended list.
1200 * a_xInfoP : Ptr to extended volume info.
1201 * a_count : Number of volume records contained above.
1202 * a_int32 : Int32 listing generated?
1203 * a_fast : Fast listing generated?
1204 * a_quiet : Quiet listing generated?
1210 * Nothing interesting.
1214 *------------------------------------------------------------------------*/
1217 XDisplayVolumes(afs_uint32 a_servID, afs_int32 a_partID, volintXInfo *a_xInfoP,
1218 afs_int32 a_count, afs_int32 a_int32, afs_int32 a_fast,
1220 { /*XDisplayVolumes */
1222 int totalOK; /*Total OK volumes */
1223 int totalNotOK; /*Total screwed volumes */
1224 int totalBusy; /*Total busy volumes */
1225 int i; /*Loop variable */
1226 afs_uint32 volid = 0; /*Current volume ID */
1229 * Initialize counters and (global!!) queues.
1238 * Display each volume in the list.
1240 for (i = 0; i < a_count; i++) {
1241 XDisplayFormat(a_xInfoP, a_servID, a_partID, &totalOK, &totalNotOK,
1242 &totalBusy, a_fast, a_int32, 0);
1247 * If any volumes were found to be busy or screwed, display them.
1250 while (busyHead.count) {
1251 qGet(&busyHead, &volid);
1252 fprintf(STDOUT, "**** Volume %lu is busy ****\n",
1253 (unsigned long)volid);
1257 while (notokHead.count) {
1258 qGet(¬okHead, &volid);
1259 fprintf(STDOUT, "**** Could not attach volume %lu ****\n",
1260 (unsigned long)volid);
1265 fprintf(STDOUT, "\n");
1268 "Total volumes: %d on-line, %d off-line, %d busyd\n\n",
1269 totalOK, totalNotOK, totalBusy);
1273 } /*XDisplayVolumes */
1275 /*------------------------------------------------------------------------
1276 * PRIVATE XDisplayVolumes2
1279 * Display extended formated volume information.
1282 * a_servID : Pointer to the Rx call we're performing.
1283 * a_partID : Partition for which we want the extended list.
1284 * a_xInfoP : Ptr to extended volume info.
1285 * a_count : Number of volume records contained above.
1286 * a_int32 : Int32 listing generated?
1287 * a_fast : Fast listing generated?
1288 * a_quiet : Quiet listing generated?
1294 * Nothing interesting.
1298 *------------------------------------------------------------------------*/
1301 XDisplayVolumes2(afs_uint32 a_servID, afs_int32 a_partID, volintXInfo *a_xInfoP,
1302 afs_int32 a_count, afs_int32 a_int32, afs_int32 a_fast,
1304 { /*XDisplayVolumes */
1306 int totalOK; /*Total OK volumes */
1307 int totalNotOK; /*Total screwed volumes */
1308 int totalBusy; /*Total busy volumes */
1309 int i; /*Loop variable */
1310 afs_uint32 volid = 0; /*Current volume ID */
1313 * Initialize counters and (global!!) queues.
1322 * Display each volume in the list.
1324 for (i = 0; i < a_count; i++) {
1325 fprintf(STDOUT, "BEGIN_OF_ENTRY\n");
1326 XDisplayFormat2(a_xInfoP, a_servID, a_partID, &totalOK, &totalNotOK,
1327 &totalBusy, a_fast, a_int32, 0);
1328 fprintf(STDOUT, "END_OF_ENTRY\n");
1333 * If any volumes were found to be busy or screwed, display them.
1336 while (busyHead.count) {
1337 qGet(&busyHead, &volid);
1338 fprintf(STDOUT, "BUSY_VOL\t%lu\n",
1339 (unsigned long)volid);
1343 while (notokHead.count) {
1344 qGet(¬okHead, &volid);
1345 fprintf(STDOUT, "COULD_NOT_ATTACH\t%lu\n",
1346 (unsigned long)volid);
1351 fprintf(STDOUT, "\n");
1354 "VOLUMES_ONLINE\t%d\nVOLUMES_OFFLINE\t%d\nVOLUMES_BUSY\t%d\n",
1355 totalOK, totalNotOK, totalBusy);
1359 } /*XDisplayVolumes2 */
1362 /* set <server> and <part> to the correct values depending on
1363 * <voltype> and <entry> */
1365 GetServerAndPart(struct nvldbentry *entry, int voltype, afs_uint32 *server,
1366 afs_int32 *part, int *previdx)
1368 int i, istart, vtype;
1373 /* Doesn't check for non-existance of backup volume */
1374 if ((voltype == RWVOL) || (voltype == BACKVOL)) {
1376 istart = 0; /* seach the entire entry */
1379 /* Seach from beginning of entry or pick up where we left off */
1380 istart = ((*previdx < 0) ? 0 : *previdx + 1);
1383 for (i = istart; i < entry->nServers; i++) {
1384 if (entry->serverFlags[i] & vtype) {
1385 *server = entry->serverNumber[i];
1386 *part = entry->serverPartition[i];
1392 /* Didn't find any, return -1 */
1398 PrintLocked(afs_int32 aflags)
1400 afs_int32 flags = aflags & VLOP_ALLOPERS;
1403 fprintf(STDOUT, " Volume is currently LOCKED \n");
1405 if (flags & VLOP_MOVE) {
1406 fprintf(STDOUT, " Volume is locked for a move operation\n");
1408 if (flags & VLOP_RELEASE) {
1409 fprintf(STDOUT, " Volume is locked for a release operation\n");
1411 if (flags & VLOP_BACKUP) {
1412 fprintf(STDOUT, " Volume is locked for a backup operation\n");
1414 if (flags & VLOP_DELETE) {
1415 fprintf(STDOUT, " Volume is locked for a delete/misc operation\n");
1417 if (flags & VLOP_DUMP) {
1418 fprintf(STDOUT, " Volume is locked for a dump/restore operation\n");
1424 PostVolumeStats(struct nvldbentry *entry)
1426 SubEnumerateEntry(entry);
1427 /* Check for VLOP_ALLOPERS */
1428 PrintLocked(entry->flags);
1432 /*------------------------------------------------------------------------
1433 * PRIVATE XVolumeStats
1436 * Display extended volume information.
1439 * a_xInfoP : Ptr to extended volume info.
1440 * a_entryP : Ptr to the volume's VLDB entry.
1441 * a_srvID : Server ID.
1442 * a_partID : Partition ID.
1443 * a_volType : Type of volume to print.
1449 * Nothing interesting.
1453 *------------------------------------------------------------------------*/
1456 XVolumeStats(volintXInfo *a_xInfoP, struct nvldbentry *a_entryP,
1457 afs_int32 a_srvID, afs_int32 a_partID, int a_volType)
1460 int totalOK, totalNotOK, totalBusy; /*Dummies - we don't really count here */
1462 XDisplayFormat(a_xInfoP, /*Ptr to extended volume info */
1463 a_srvID, /*Server ID to print */
1464 a_partID, /*Partition ID to print */
1465 &totalOK, /*Ptr to total-OK counter */
1466 &totalNotOK, /*Ptr to total-screwed counter */
1467 &totalBusy, /*Ptr to total-busy counter */
1468 0, /*Don't do a fast listing */
1469 1, /*Do a long listing */
1470 1); /*Show volume problems */
1476 VolumeStats_int(volintInfo *pntr, struct nvldbentry *entry, afs_uint32 server,
1477 afs_int32 part, int voltype)
1479 int totalOK, totalNotOK, totalBusy;
1481 DisplayFormat(pntr, server, part, &totalOK, &totalNotOK, &totalBusy, 0, 1,
1486 /* command to forcibly remove a volume */
1488 NukeVolume(struct cmd_syndesc *as)
1497 server = GetServer(tp = as->parms[0].items->data);
1499 fprintf(STDERR, "vos: server '%s' not found in host table\n", tp);
1503 partID = volutil_GetPartitionID(tp = as->parms[1].items->data);
1505 fprintf(STDERR, "vos: could not parse '%s' as a partition name", tp);
1509 volID = vsu_GetVolumeID(tp = as->parms[2].items->data, cstruct, &err);
1512 PrintError("", err);
1515 "vos: could not parse '%s' as a numeric volume ID", tp);
1520 "vos: forcibly removing all traces of volume %d, please wait...",
1523 code = UV_NukeVolume(server, partID, volID);
1525 fprintf(STDOUT, "done.\n");
1527 fprintf(STDOUT, "failed with code %d.\n", code);
1532 /*------------------------------------------------------------------------
1533 * PRIVATE ExamineVolume
1536 * Routine used to examine a single volume, contacting the VLDB as
1537 * well as the Volume Server.
1540 * as : Ptr to parsed command line arguments.
1543 * 0 for a successful operation,
1544 * Otherwise, one of the ubik or VolServer error values.
1547 * Nothing interesting.
1551 *------------------------------------------------------------------------
1554 ExamineVolume(struct cmd_syndesc *as, void *arock)
1556 struct nvldbentry entry;
1557 afs_int32 vcode = 0;
1558 volintInfo *pntr = (volintInfo *) 0;
1559 volintXInfo *xInfoP = (volintXInfo *) 0;
1561 afs_int32 code, err, error = 0;
1562 int voltype, foundserv = 0, foundentry = 0;
1566 int wantExtendedInfo; /*Do we want extended vol info? */
1567 int isSubEnum=0; /* Keep track whether sub enumerate called. */
1568 wantExtendedInfo = (as->parms[1].items ? 1 : 0); /* -extended */
1570 volid = vsu_GetVolumeID(as->parms[0].items->data, cstruct, &err); /* -id */
1573 PrintError("", err);
1575 fprintf(STDERR, "Unknown volume ID or name '%s'\n",
1576 as->parms[0].items->data);
1581 fprintf(STDOUT, "Fetching VLDB entry for %lu .. ",
1582 (unsigned long)volid);
1585 vcode = VLDB_GetEntryByID(volid, -1, &entry);
1588 "Could not fetch the entry for volume number %lu from VLDB \n",
1589 (unsigned long)volid);
1593 fprintf(STDOUT, "done\n");
1594 MapHostToNetwork(&entry);
1596 if (entry.volumeId[RWVOL] == volid)
1598 else if (entry.volumeId[BACKVOL] == volid)
1600 else /* (entry.volumeId[ROVOL] == volid) */
1603 do { /* do {...} while (voltype == ROVOL) */
1604 /* Get the entry for the volume. If its a RW vol, get the RW entry.
1605 * It its a BK vol, get the RW entry (even if VLDB may say the BK doen't exist).
1606 * If its a RO vol, get the next RO entry.
1608 GetServerAndPart(&entry, ((voltype == ROVOL) ? ROVOL : RWVOL),
1609 &aserver, &apart, &previdx);
1610 if (previdx == -1) { /* searched all entries */
1612 fprintf(STDERR, "Volume %s does not exist in VLDB\n\n",
1613 as->parms[0].items->data);
1620 /* Get information about the volume from the server */
1622 fprintf(STDOUT, "Getting volume listing from the server %s .. ",
1623 hostutil_GetNameByINet(aserver));
1626 if (wantExtendedInfo)
1627 code = UV_XListOneVolume(aserver, apart, volid, &xInfoP);
1629 code = UV_ListOneVolume(aserver, apart, volid, &pntr);
1631 fprintf(STDOUT, "done\n");
1635 if (code == ENODEV) {
1636 if ((voltype == BACKVOL) && !(entry.flags & BACK_EXISTS)) {
1637 /* The VLDB says there is no backup volume and its not on disk */
1638 fprintf(STDERR, "Volume %s does not exist\n",
1639 as->parms[0].items->data);
1643 "Volume does not exist on server %s as indicated by the VLDB\n",
1644 hostutil_GetNameByINet(aserver));
1647 PrintDiagnostics("examine", code);
1649 fprintf(STDOUT, "\n");
1652 if (wantExtendedInfo)
1653 XVolumeStats(xInfoP, &entry, aserver, apart, voltype);
1654 else if (as->parms[2].items) {
1655 DisplayFormat2(aserver, apart, pntr);
1656 EnumerateEntry(&entry);
1659 VolumeStats_int(pntr, &entry, aserver, apart, voltype);
1661 if ((voltype == BACKVOL) && !(entry.flags & BACK_EXISTS)) {
1662 /* The VLDB says there is no backup volume yet we found one on disk */
1663 fprintf(STDERR, "Volume %s does not exist in VLDB\n",
1664 as->parms[0].items->data);
1673 } while (voltype == ROVOL);
1676 fprintf(STDERR, "Dump only information from VLDB\n\n");
1677 fprintf(STDOUT, "%s \n", entry.name); /* PostVolumeStats doesn't print name */
1681 PostVolumeStats(&entry);
1686 /*------------------------------------------------------------------------
1690 * Routine used to change the status of a single volume.
1693 * as : Ptr to parsed command line arguments.
1696 * 0 for a successful operation,
1697 * Otherwise, one of the ubik or VolServer error values.
1700 * Nothing interesting.
1704 *------------------------------------------------------------------------
1707 SetFields(struct cmd_syndesc *as, void *arock)
1709 struct nvldbentry entry;
1712 afs_int32 code, err;
1717 volid = vsu_GetVolumeID(as->parms[0].items->data, cstruct, &err); /* -id */
1720 PrintError("", err);
1722 fprintf(STDERR, "Unknown volume ID or name '%s'\n",
1723 as->parms[0].items->data);
1727 code = VLDB_GetEntryByID(volid, RWVOL, &entry);
1730 "Could not fetch the entry for volume number %lu from VLDB \n",
1731 (unsigned long)volid);
1734 MapHostToNetwork(&entry);
1736 GetServerAndPart(&entry, RWVOL, &aserver, &apart, &previdx);
1737 if (previdx == -1) {
1738 fprintf(STDERR, "Volume %s does not exist in VLDB\n\n",
1739 as->parms[0].items->data);
1743 init_volintInfo(&info);
1747 if (as->parms[1].items) {
1749 code = util_GetHumanInt32(as->parms[1].items->data, &info.maxquota);
1751 fprintf(STDERR, "invalid quota value\n");
1755 if (as->parms[2].items) {
1759 if (as->parms[3].items) {
1760 /* -clearVolUpCounter */
1763 code = UV_SetVolumeInfo(aserver, apart, volid, &info);
1766 "Could not update volume info fields for volume number %lu\n",
1767 (unsigned long)volid);
1771 /*------------------------------------------------------------------------
1775 * Brings a volume online.
1778 * as : Ptr to parsed command line arguments.
1781 * 0 for a successful operation,
1784 * Nothing interesting.
1788 *------------------------------------------------------------------------
1791 volOnline(struct cmd_syndesc *as, void *arock)
1794 afs_int32 partition;
1796 afs_int32 code, err = 0;
1798 server = GetServer(as->parms[0].items->data);
1800 fprintf(STDERR, "vos: server '%s' not found in host table\n",
1801 as->parms[0].items->data);
1805 partition = volutil_GetPartitionID(as->parms[1].items->data);
1806 if (partition < 0) {
1807 fprintf(STDERR, "vos: could not interpret partition name '%s'\n",
1808 as->parms[1].items->data);
1812 volid = vsu_GetVolumeID(as->parms[2].items->data, cstruct, &err); /* -id */
1815 PrintError("", err);
1817 fprintf(STDERR, "Unknown volume ID or name '%s'\n",
1818 as->parms[0].items->data);
1822 code = UV_SetVolume(server, partition, volid, ITOffline, 0 /*online */ ,
1825 fprintf(STDERR, "Failed to set volume. Code = %d\n", code);
1832 /*------------------------------------------------------------------------
1833 * PRIVATE volOffline
1836 * Brings a volume offline.
1839 * as : Ptr to parsed command line arguments.
1842 * 0 for a successful operation,
1845 * Nothing interesting.
1849 *------------------------------------------------------------------------
1852 volOffline(struct cmd_syndesc *as, void *arock)
1855 afs_int32 partition;
1857 afs_int32 code, err = 0;
1858 afs_int32 transflag, sleeptime, transdone;
1860 server = GetServer(as->parms[0].items->data);
1862 fprintf(STDERR, "vos: server '%s' not found in host table\n",
1863 as->parms[0].items->data);
1867 partition = volutil_GetPartitionID(as->parms[1].items->data);
1868 if (partition < 0) {
1869 fprintf(STDERR, "vos: could not interpret partition name '%s'\n",
1870 as->parms[1].items->data);
1874 volid = vsu_GetVolumeID(as->parms[2].items->data, cstruct, &err); /* -id */
1877 PrintError("", err);
1879 fprintf(STDERR, "Unknown volume ID or name '%s'\n",
1880 as->parms[0].items->data);
1884 transflag = (as->parms[4].items ? ITBusy : ITOffline);
1885 sleeptime = (as->parms[3].items ? atol(as->parms[3].items->data) : 0);
1886 transdone = (sleeptime ? 0 /*online */ : VTOutOfService);
1887 if (as->parms[4].items && !as->parms[3].items) {
1888 fprintf(STDERR, "-sleep option must be used with -busy flag\n");
1893 UV_SetVolume(server, partition, volid, transflag, transdone,
1896 fprintf(STDERR, "Failed to set volume. Code = %d\n", code);
1904 CreateVolume(struct cmd_syndesc *as, void *arock)
1908 afs_uint32 volid = 0, rovolid = 0, bkvolid = 0;
1909 afs_uint32 *arovolid;
1911 struct nvldbentry entry;
1915 arovolid = &rovolid;
1918 tserver = GetServer(as->parms[0].items->data);
1920 fprintf(STDERR, "vos: host '%s' not found in host table\n",
1921 as->parms[0].items->data);
1924 pnum = volutil_GetPartitionID(as->parms[1].items->data);
1926 fprintf(STDERR, "vos: could not interpret partition name '%s'\n",
1927 as->parms[1].items->data);
1930 if (!IsPartValid(pnum, tserver, &code)) { /*check for validity of the partition */
1932 PrintError("", code);
1935 "vos : partition %s does not exist on the server\n",
1936 as->parms[1].items->data);
1939 if (!ISNAMEVALID(as->parms[2].items->data)) {
1941 "vos: the name of the root volume %s exceeds the size limit of %d\n",
1942 as->parms[2].items->data, VOLSER_OLDMAXVOLNAME - 10);
1945 if (!VolNameOK(as->parms[2].items->data)) {
1947 "Illegal volume name %s, should not end in .readonly or .backup\n",
1948 as->parms[2].items->data);
1951 if (IsNumeric(as->parms[2].items->data)) {
1952 fprintf(STDERR, "Illegal volume name %s, should not be a number\n",
1953 as->parms[2].items->data);
1956 vcode = VLDB_GetEntryByName(as->parms[2].items->data, &entry);
1958 fprintf(STDERR, "Volume %s already exists\n",
1959 as->parms[2].items->data);
1960 PrintDiagnostics("create", code);
1964 if (as->parms[3].items) {
1965 code = util_GetHumanInt32(as->parms[3].items->data, "a);
1967 fprintf(STDERR, "vos: bad integer specified for quota.\n");
1972 if (as->parms[4].items) {
1973 if (!IsNumeric(as->parms[4].items->data)) {
1974 fprintf(STDERR, "vos: Given volume ID %s should be numeric.\n",
1975 as->parms[4].items->data);
1979 code = util_GetUInt32(as->parms[4].items->data, &volid);
1981 fprintf(STDERR, "vos: bad integer specified for volume ID.\n");
1986 if (as->parms[5].items) {
1987 if (!IsNumeric(as->parms[5].items->data)) {
1988 fprintf(STDERR, "vos: Given RO volume ID %s should be numeric.\n",
1989 as->parms[5].items->data);
1993 code = util_GetUInt32(as->parms[5].items->data, &rovolid);
1995 fprintf(STDERR, "vos: bad integer specified for volume ID.\n");
2005 UV_CreateVolume3(tserver, pnum, as->parms[2].items->data, quota, 0,
2006 0, 0, 0, &volid, arovolid, &bkvolid);
2008 PrintDiagnostics("create", code);
2011 MapPartIdIntoName(pnum, part);
2012 fprintf(STDOUT, "Volume %lu created on partition %s of %s\n",
2013 (unsigned long)volid, part, as->parms[0].items->data);
2020 DeleteAll(struct nvldbentry *entry)
2023 afs_int32 error, code, curserver, curpart;
2026 MapHostToNetwork(entry);
2028 for (i = 0; i < entry->nServers; i++) {
2029 curserver = entry->serverNumber[i];
2030 curpart = entry->serverPartition[i];
2031 if (entry->serverFlags[i] & ITSROVOL) {
2032 volid = entry->volumeId[ROVOL];
2034 volid = entry->volumeId[RWVOL];
2036 code = UV_DeleteVolume(curserver, curpart, volid);
2045 DeleteVolume(struct cmd_syndesc *as, void *arock)
2047 afs_int32 err, code = 0;
2048 afs_uint32 server = 0;
2049 afs_int32 partition = -1;
2054 if (as->parms[0].items) {
2055 server = GetServer(as->parms[0].items->data);
2057 fprintf(STDERR, "vos: server '%s' not found in host table\n",
2058 as->parms[0].items->data);
2063 if (as->parms[1].items) {
2064 partition = volutil_GetPartitionID(as->parms[1].items->data);
2065 if (partition < 0) {
2066 fprintf(STDERR, "vos: could not interpret partition name '%s'\n",
2067 as->parms[1].items->data);
2071 /* Check for validity of the partition */
2072 if (!IsPartValid(partition, server, &code)) {
2074 PrintError("", code);
2077 "vos : partition %s does not exist on the server\n",
2078 as->parms[1].items->data);
2084 volid = vsu_GetVolumeID(as->parms[2].items->data, cstruct, &err);
2086 fprintf(STDERR, "Can't find volume name '%s' in VLDB\n",
2087 as->parms[2].items->data);
2089 PrintError("", err);
2093 /* If the server or partition option are not complete, try to fill
2094 * them in from the VLDB entry.
2096 if ((partition == -1) || !server) {
2097 struct nvldbentry entry;
2099 code = VLDB_GetEntryByID(volid, -1, &entry);
2102 "Could not fetch the entry for volume %lu from VLDB\n",
2103 (unsigned long)volid);
2104 PrintError("", code);
2108 if (((volid == entry.volumeId[RWVOL]) && (entry.flags & RW_EXISTS))
2109 || ((volid == entry.volumeId[BACKVOL])
2110 && (entry.flags & BACK_EXISTS))) {
2111 idx = Lp_GetRwIndex(&entry);
2112 if ((idx == -1) || (server && (server != entry.serverNumber[idx]))
2113 || ((partition != -1)
2114 && (partition != entry.serverPartition[idx]))) {
2115 fprintf(STDERR, "VLDB: Volume '%s' no match\n",
2116 as->parms[2].items->data);
2119 } else if ((volid == entry.volumeId[ROVOL])
2120 && (entry.flags & RO_EXISTS)) {
2121 for (idx = -1, j = 0; j < entry.nServers; j++) {
2122 if (entry.serverFlags[j] != ITSROVOL)
2125 if (((server == 0) || (server == entry.serverNumber[j]))
2126 && ((partition == -1)
2127 || (partition == entry.serverPartition[j]))) {
2130 "VLDB: Volume '%s' matches more than one RO\n",
2131 as->parms[2].items->data);
2138 fprintf(STDERR, "VLDB: Volume '%s' no match\n",
2139 as->parms[2].items->data);
2143 fprintf(STDERR, "VLDB: Volume '%s' no match\n",
2144 as->parms[2].items->data);
2148 server = htonl(entry.serverNumber[idx]);
2149 partition = entry.serverPartition[idx];
2153 code = UV_DeleteVolume(server, partition, volid);
2155 PrintDiagnostics("remove", code);
2159 MapPartIdIntoName(partition, pname);
2160 fprintf(STDOUT, "Volume %lu on partition %s server %s deleted\n",
2161 (unsigned long)volid, pname, hostutil_GetNameByINet(server));
2165 #define TESTM 0 /* set for move space tests, clear for production */
2167 MoveVolume(struct cmd_syndesc *as, void *arock)
2171 afs_uint32 fromserver, toserver;
2172 afs_int32 frompart, topart;
2173 afs_int32 flags, code, err;
2174 char fromPartName[10], toPartName[10];
2176 struct diskPartition64 partition; /* for space check */
2179 volid = vsu_GetVolumeID(as->parms[0].items->data, cstruct, &err);
2182 PrintError("", err);
2184 fprintf(STDERR, "vos: can't find volume ID or name '%s'\n",
2185 as->parms[0].items->data);
2188 fromserver = GetServer(as->parms[1].items->data);
2189 if (fromserver == 0) {
2190 fprintf(STDERR, "vos: server '%s' not found in host table\n",
2191 as->parms[1].items->data);
2194 toserver = GetServer(as->parms[3].items->data);
2195 if (toserver == 0) {
2196 fprintf(STDERR, "vos: server '%s' not found in host table\n",
2197 as->parms[3].items->data);
2200 frompart = volutil_GetPartitionID(as->parms[2].items->data);
2202 fprintf(STDERR, "vos: could not interpret partition name '%s'\n",
2203 as->parms[2].items->data);
2206 if (!IsPartValid(frompart, fromserver, &code)) { /*check for validity of the partition */
2208 PrintError("", code);
2211 "vos : partition %s does not exist on the server\n",
2212 as->parms[2].items->data);
2215 topart = volutil_GetPartitionID(as->parms[4].items->data);
2217 fprintf(STDERR, "vos: could not interpret partition name '%s'\n",
2218 as->parms[4].items->data);
2221 if (!IsPartValid(topart, toserver, &code)) { /*check for validity of the partition */
2223 PrintError("", code);
2226 "vos : partition %s does not exist on the server\n",
2227 as->parms[4].items->data);
2232 if (as->parms[5].items) flags |= RV_NOCLONE;
2235 * check source partition for space to clone volume
2238 MapPartIdIntoName(topart, toPartName);
2239 MapPartIdIntoName(frompart, fromPartName);
2242 * check target partition for space to move volume
2245 code = UV_PartitionInfo64(toserver, toPartName, &partition);
2247 fprintf(STDERR, "vos: cannot access partition %s\n", toPartName);
2251 fprintf(STDOUT, "target partition %s free space %" AFS_INT64_FMT "\n", toPartName,
2254 p = (volintInfo *) 0;
2255 code = UV_ListOneVolume(fromserver, frompart, volid, &p);
2257 fprintf(STDERR, "vos:cannot access volume %lu\n",
2258 (unsigned long)volid);
2262 fprintf(STDOUT, "volume %lu size %d\n", (unsigned long)volid,
2264 if (partition.free <= p->size) {
2266 "vos: no space on target partition %s to move volume %lu\n",
2267 toPartName, (unsigned long)volid);
2274 fprintf(STDOUT, "size test - don't do move\n");
2278 /* successful move still not guaranteed but shoot for it */
2281 UV_MoveVolume2(volid, fromserver, frompart, toserver, topart, flags);
2283 PrintDiagnostics("move", code);
2286 MapPartIdIntoName(topart, toPartName);
2287 MapPartIdIntoName(frompart, fromPartName);
2288 fprintf(STDOUT, "Volume %lu moved from %s %s to %s %s \n",
2289 (unsigned long)volid, as->parms[1].items->data, fromPartName,
2290 as->parms[3].items->data, toPartName);
2296 CopyVolume(struct cmd_syndesc *as, void *arock)
2299 afs_uint32 fromserver, toserver;
2300 afs_int32 frompart, topart, code, err, flags;
2301 char fromPartName[10], toPartName[10], *tovolume;
2302 struct nvldbentry entry;
2303 struct diskPartition64 partition; /* for space check */
2306 volid = vsu_GetVolumeID(as->parms[0].items->data, cstruct, &err);
2309 PrintError("", err);
2311 fprintf(STDERR, "vos: can't find volume ID or name '%s'\n",
2312 as->parms[0].items->data);
2315 fromserver = GetServer(as->parms[1].items->data);
2316 if (fromserver == 0) {
2317 fprintf(STDERR, "vos: server '%s' not found in host table\n",
2318 as->parms[1].items->data);
2322 toserver = GetServer(as->parms[4].items->data);
2323 if (toserver == 0) {
2324 fprintf(STDERR, "vos: server '%s' not found in host table\n",
2325 as->parms[4].items->data);
2329 tovolume = as->parms[3].items->data;
2330 if (!ISNAMEVALID(tovolume)) {
2332 "vos: the name of the root volume %s exceeds the size limit of %d\n",
2333 tovolume, VOLSER_OLDMAXVOLNAME - 10);
2336 if (!VolNameOK(tovolume)) {
2338 "Illegal volume name %s, should not end in .readonly or .backup\n",
2342 if (IsNumeric(tovolume)) {
2343 fprintf(STDERR, "Illegal volume name %s, should not be a number\n",
2347 code = VLDB_GetEntryByName(tovolume, &entry);
2349 fprintf(STDERR, "Volume %s already exists\n", tovolume);
2350 PrintDiagnostics("copy", code);
2354 frompart = volutil_GetPartitionID(as->parms[2].items->data);
2356 fprintf(STDERR, "vos: could not interpret partition name '%s'\n",
2357 as->parms[2].items->data);
2360 if (!IsPartValid(frompart, fromserver, &code)) { /*check for validity of the partition */
2362 PrintError("", code);
2365 "vos : partition %s does not exist on the server\n",
2366 as->parms[2].items->data);
2370 topart = volutil_GetPartitionID(as->parms[5].items->data);
2372 fprintf(STDERR, "vos: could not interpret partition name '%s'\n",
2373 as->parms[5].items->data);
2376 if (!IsPartValid(topart, toserver, &code)) { /*check for validity of the partition */
2378 PrintError("", code);
2381 "vos : partition %s does not exist on the server\n",
2382 as->parms[5].items->data);
2387 if (as->parms[6].items) flags |= RV_OFFLINE;
2388 if (as->parms[7].items) flags |= RV_RDONLY;
2389 if (as->parms[8].items) flags |= RV_NOCLONE;
2391 MapPartIdIntoName(topart, toPartName);
2392 MapPartIdIntoName(frompart, fromPartName);
2395 * check target partition for space to move volume
2398 code = UV_PartitionInfo64(toserver, toPartName, &partition);
2400 fprintf(STDERR, "vos: cannot access partition %s\n", toPartName);
2404 fprintf(STDOUT, "target partition %s free space %" AFS_INT64_FMT "\n", toPartName,
2407 p = (volintInfo *) 0;
2408 code = UV_ListOneVolume(fromserver, frompart, volid, &p);
2410 fprintf(STDERR, "vos:cannot access volume %lu\n",
2411 (unsigned long)volid);
2415 if (partition.free <= p->size) {
2417 "vos: no space on target partition %s to copy volume %lu\n",
2418 toPartName, (unsigned long)volid);
2424 /* successful copy still not guaranteed but shoot for it */
2427 UV_CopyVolume2(volid, fromserver, frompart, tovolume, toserver,
2430 PrintDiagnostics("copy", code);
2433 MapPartIdIntoName(topart, toPartName);
2434 MapPartIdIntoName(frompart, fromPartName);
2435 fprintf(STDOUT, "Volume %lu copied from %s %s to %s on %s %s \n",
2436 (unsigned long)volid, as->parms[1].items->data, fromPartName,
2437 tovolume, as->parms[4].items->data, toPartName);
2444 ShadowVolume(struct cmd_syndesc *as, void *arock)
2446 afs_uint32 volid, tovolid;
2447 afs_uint32 fromserver, toserver;
2448 afs_int32 frompart, topart;
2449 afs_int32 code, err, flags;
2450 char fromPartName[10], toPartName[10], toVolName[32], *tovolume;
2451 struct diskPartition64 partition; /* for space check */
2454 p = (volintInfo *) 0;
2455 q = (volintInfo *) 0;
2457 volid = vsu_GetVolumeID(as->parms[0].items->data, cstruct, &err);
2460 PrintError("", err);
2462 fprintf(STDERR, "vos: can't find volume ID or name '%s'\n",
2463 as->parms[0].items->data);
2466 fromserver = GetServer(as->parms[1].items->data);
2467 if (fromserver == 0) {
2468 fprintf(STDERR, "vos: server '%s' not found in host table\n",
2469 as->parms[1].items->data);
2473 toserver = GetServer(as->parms[3].items->data);
2474 if (toserver == 0) {
2475 fprintf(STDERR, "vos: server '%s' not found in host table\n",
2476 as->parms[3].items->data);
2480 frompart = volutil_GetPartitionID(as->parms[2].items->data);
2482 fprintf(STDERR, "vos: could not interpret partition name '%s'\n",
2483 as->parms[2].items->data);
2486 if (!IsPartValid(frompart, fromserver, &code)) { /*check for validity of the partition */
2488 PrintError("", code);
2491 "vos : partition %s does not exist on the server\n",
2492 as->parms[2].items->data);
2496 topart = volutil_GetPartitionID(as->parms[4].items->data);
2498 fprintf(STDERR, "vos: could not interpret partition name '%s'\n",
2499 as->parms[4].items->data);
2502 if (!IsPartValid(topart, toserver, &code)) { /*check for validity of the partition */
2504 PrintError("", code);
2507 "vos : partition %s does not exist on the server\n",
2508 as->parms[4].items->data);
2512 if (as->parms[5].items) {
2513 tovolume = as->parms[5].items->data;
2514 if (!ISNAMEVALID(tovolume)) {
2516 "vos: the name of the root volume %s exceeds the size limit of %d\n",
2517 tovolume, VOLSER_OLDMAXVOLNAME - 10);
2520 if (!VolNameOK(tovolume)) {
2522 "Illegal volume name %s, should not end in .readonly or .backup\n",
2526 if (IsNumeric(tovolume)) {
2528 "Illegal volume name %s, should not be a number\n",
2533 /* use actual name of source volume */
2534 code = UV_ListOneVolume(fromserver, frompart, volid, &p);
2536 fprintf(STDERR, "vos:cannot access volume %lu\n",
2537 (unsigned long)volid);
2540 strcpy(toVolName, p->name);
2541 tovolume = toVolName;
2542 /* save p for size checks later */
2545 if (as->parms[6].items) {
2546 tovolid = vsu_GetVolumeID(as->parms[6].items->data, cstruct, &err);
2549 PrintError("", err);
2551 fprintf(STDERR, "vos: can't find volume ID or name '%s'\n",
2552 as->parms[6].items->data);
2558 tovolid = vsu_GetVolumeID(tovolume, cstruct, &err);
2561 PrintError("", err);
2563 fprintf(STDERR, "vos: can't find volume ID or name '%s'\n",
2572 if (as->parms[7].items) flags |= RV_OFFLINE;
2573 if (as->parms[8].items) flags |= RV_RDONLY;
2574 if (as->parms[9].items) flags |= RV_NOCLONE;
2575 if (as->parms[10].items) flags |= RV_CPINCR;
2577 MapPartIdIntoName(topart, toPartName);
2578 MapPartIdIntoName(frompart, fromPartName);
2581 * check target partition for space to move volume
2584 code = UV_PartitionInfo64(toserver, toPartName, &partition);
2586 fprintf(STDERR, "vos: cannot access partition %s\n", toPartName);
2590 fprintf(STDOUT, "target partition %s free space %" AFS_INT64_FMT "\n", toPartName,
2593 /* Don't do this again if we did it above */
2595 code = UV_ListOneVolume(fromserver, frompart, volid, &p);
2597 fprintf(STDERR, "vos:cannot access volume %lu\n",
2598 (unsigned long)volid);
2603 /* OK if this fails */
2604 code = UV_ListOneVolume(toserver, topart, tovolid, &q);
2606 /* Treat existing volume size as "free" */
2608 p->size = (q->size < p->size) ? p->size - q->size : 0;
2610 if (partition.free <= p->size) {
2612 "vos: no space on target partition %s to copy volume %lu\n",
2613 toPartName, (unsigned long)volid);
2621 /* successful copy still not guaranteed but shoot for it */
2624 UV_CopyVolume2(volid, fromserver, frompart, tovolume, toserver,
2625 topart, tovolid, flags);
2627 PrintDiagnostics("shadow", code);
2630 MapPartIdIntoName(topart, toPartName);
2631 MapPartIdIntoName(frompart, fromPartName);
2632 fprintf(STDOUT, "Volume %lu shadowed from %s %s to %s %s \n",
2633 (unsigned long)volid, as->parms[1].items->data, fromPartName,
2634 as->parms[3].items->data, toPartName);
2641 CloneVolume(struct cmd_syndesc *as, void *arock)
2643 afs_uint32 volid, cloneid;
2645 afs_int32 part, voltype;
2646 char partName[10], *volname;
2647 afs_int32 code, err, flags;
2648 struct nvldbentry entry;
2650 volid = vsu_GetVolumeID(as->parms[0].items->data, cstruct, &err);
2653 PrintError("", err);
2655 fprintf(STDERR, "vos: can't find volume ID or name '%s'\n",
2656 as->parms[0].items->data);
2660 if (as->parms[1].items || as->parms[2].items) {
2661 if (!as->parms[1].items || !as->parms[2].items) {
2663 "Must specify both -server and -partition options\n");
2666 server = GetServer(as->parms[1].items->data);
2668 fprintf(STDERR, "vos: server '%s' not found in host table\n",
2669 as->parms[1].items->data);
2672 part = volutil_GetPartitionID(as->parms[2].items->data);
2674 fprintf(STDERR, "vos: could not interpret partition name '%s'\n",
2675 as->parms[2].items->data);
2678 if (!IsPartValid(part, server, &code)) { /*check for validity of the partition */
2680 PrintError("", code);
2683 "vos : partition %s does not exist on the server\n",
2684 as->parms[2].items->data);
2688 code = GetVolumeInfo(volid, &server, &part, &voltype, &entry);
2694 if (as->parms[3].items) {
2695 volname = as->parms[3].items->data;
2696 if (strlen(volname) > VOLSER_OLDMAXVOLNAME - 1) {
2698 "vos: the name of the root volume %s exceeds the size limit of %d\n",
2699 volname, VOLSER_OLDMAXVOLNAME - 1);
2704 * In order that you be able to make clones of RO or BK, this
2705 * check must be omitted.
2707 if (!VolNameOK(volname)) {
2709 "Illegal volume name %s, should not end in .readonly or .backup\n",
2714 if (IsNumeric(volname)) {
2716 "Illegal volume name %s, should not be a number\n",
2723 if (as->parms[4].items) {
2724 cloneid = vsu_GetVolumeID(as->parms[4].items->data, cstruct, &err);
2727 PrintError("", err);
2729 fprintf(STDERR, "vos: can't find volume ID or name '%s'\n",
2730 as->parms[4].items->data);
2736 if (as->parms[5].items) flags |= RV_OFFLINE;
2737 if (as->parms[6].items) flags |= RV_RDONLY;
2741 UV_CloneVolume(server, part, volid, cloneid, volname, flags);
2744 PrintDiagnostics("clone", code);
2747 MapPartIdIntoName(part, partName);
2748 fprintf(STDOUT, "Created clone for volume %s\n",
2749 as->parms[0].items->data);
2756 BackupVolume(struct cmd_syndesc *as, void *arock)
2760 afs_int32 apart, vtype, code, err;
2761 struct nvldbentry entry;
2764 afs_uint32 buserver;
2765 afs_int32 bupart, butype;
2766 struct nvldbentry buentry;
2768 avolid = vsu_GetVolumeID(as->parms[0].items->data, cstruct, &err);
2771 PrintError("", err);
2773 fprintf(STDERR, "vos: can't find volume ID or name '%s'\n",
2774 as->parms[0].items->data);
2777 code = GetVolumeInfo(avolid, &aserver, &apart, &vtype, &entry);
2781 /* verify this is a readwrite volume */
2783 if (vtype != RWVOL) {
2784 fprintf(STDERR, "%s not RW volume\n", as->parms[0].items->data);
2788 /* is there a backup volume already? */
2790 if (entry.flags & BACK_EXISTS) {
2791 /* yep, where is it? */
2793 buvolid = entry.volumeId[BACKVOL];
2794 code = GetVolumeInfo(buvolid, &buserver, &bupart, &butype, &buentry);
2799 code = VLDB_IsSameAddrs(buserver, aserver, &err);
2802 "Failed to get info about server's %d address(es) from vlserver; aborting call!\n",
2808 "FATAL ERROR: backup volume %lu exists on server %lu\n",
2809 (unsigned long)buvolid, (unsigned long)buserver);
2814 /* nope, carry on */
2816 code = UV_BackupVolume(aserver, apart, avolid);
2819 PrintDiagnostics("backup", code);
2822 fprintf(STDOUT, "Created backup volume for %s \n",
2823 as->parms[0].items->data);
2828 ReleaseVolume(struct cmd_syndesc *as, void *arock)
2831 struct nvldbentry entry;
2834 afs_int32 apart, vtype, code, err;
2837 if (as->parms[1].items)
2839 avolid = vsu_GetVolumeID(as->parms[0].items->data, cstruct, &err);
2842 PrintError("", err);
2844 fprintf(STDERR, "vos: can't find volume '%s'\n",
2845 as->parms[0].items->data);
2848 code = GetVolumeInfo(avolid, &aserver, &apart, &vtype, &entry);
2852 if (vtype != RWVOL) {
2853 fprintf(STDERR, "%s not a RW volume\n", as->parms[0].items->data);
2857 if (!ISNAMEVALID(entry.name)) {
2859 "Volume name %s is too long, rename before releasing\n",
2864 code = UV_ReleaseVolume(avolid, aserver, apart, force);
2866 PrintDiagnostics("release", code);
2869 fprintf(STDOUT, "Released volume %s successfully\n",
2870 as->parms[0].items->data);
2875 DumpVolumeCmd(struct cmd_syndesc *as, void *arock)
2879 afs_int32 apart, voltype, fromdate = 0, code, err, i, flags;
2880 char filename[MAXPATHLEN];
2881 struct nvldbentry entry;
2883 rx_SetRxDeadTime(60 * 10);
2884 for (i = 0; i < MAXSERVERS; i++) {
2885 struct rx_connection *rxConn = ubik_GetRPCConn(cstruct, i);
2888 rx_SetConnDeadTime(rxConn, rx_connDeadTime);
2889 if (rxConn->service)
2890 rxConn->service->connDeadTime = rx_connDeadTime;
2893 avolid = vsu_GetVolumeID(as->parms[0].items->data, cstruct, &err);
2896 PrintError("", err);
2898 fprintf(STDERR, "vos: can't find volume '%s'\n",
2899 as->parms[0].items->data);
2903 if (as->parms[3].items || as->parms[4].items) {
2904 if (!as->parms[3].items || !as->parms[4].items) {
2906 "Must specify both -server and -partition options\n");
2909 aserver = GetServer(as->parms[3].items->data);
2911 fprintf(STDERR, "Invalid server name\n");
2914 apart = volutil_GetPartitionID(as->parms[4].items->data);
2916 fprintf(STDERR, "Invalid partition name\n");
2920 code = GetVolumeInfo(avolid, &aserver, &apart, &voltype, &entry);
2925 if (as->parms[1].items && strcmp(as->parms[1].items->data, "0")) {
2926 code = ktime_DateToInt32(as->parms[1].items->data, &fromdate);
2928 fprintf(STDERR, "vos: failed to parse date '%s' (error=%d))\n",
2929 as->parms[1].items->data, code);
2933 if (as->parms[2].items) {
2934 strcpy(filename, as->parms[2].items->data);
2936 strcpy(filename, "");
2939 flags = as->parms[6].items ? VOLDUMPV2_OMITDIRS : 0;
2941 if (as->parms[5].items) {
2943 UV_DumpClonedVolume(avolid, aserver, apart, fromdate,
2944 DumpFunction, filename, flags);
2947 UV_DumpVolume(avolid, aserver, apart, fromdate, DumpFunction,
2950 if ((code == RXGEN_OPCODE) && (as->parms[6].items)) {
2951 flags &= ~VOLDUMPV2_OMITDIRS;
2955 PrintDiagnostics("dump", code);
2958 if (strcmp(filename, ""))
2959 fprintf(STDERR, "Dumped volume %s in file %s\n",
2960 as->parms[0].items->data, filename);
2962 fprintf(STDERR, "Dumped volume %s in stdout \n",
2963 as->parms[0].items->data);
2977 RestoreVolumeCmd(struct cmd_syndesc *as, void *arock)
2979 afs_uint32 avolid, aparentid;
2981 afs_int32 apart, code, vcode, err;
2982 afs_int32 aoverwrite = ASK;
2983 afs_int32 acreation = 0, alastupdate = 0;
2984 int restoreflags = 0;
2985 int readonly = 0, offline = 0, voltype = RWVOL;
2986 char afilename[MAXPATHLEN], avolname[VOLSER_MAXVOLNAME + 1], apartName[10];
2987 char volname[VOLSER_MAXVOLNAME + 1];
2988 struct nvldbentry entry;
2991 if (as->parms[4].items) {
2992 avolid = vsu_GetVolumeID(as->parms[4].items->data, cstruct, &err);
2995 PrintError("", err);
2997 fprintf(STDERR, "vos: can't find volume '%s'\n",
2998 as->parms[4].items->data);
3004 if (as->parms[5].items) {
3005 if ((strcmp(as->parms[5].items->data, "a") == 0)
3006 || (strcmp(as->parms[5].items->data, "abort") == 0)) {
3008 } else if ((strcmp(as->parms[5].items->data, "f") == 0)
3009 || (strcmp(as->parms[5].items->data, "full") == 0)) {
3011 } else if ((strcmp(as->parms[5].items->data, "i") == 0)
3012 || (strcmp(as->parms[5].items->data, "inc") == 0)
3013 || (strcmp(as->parms[5].items->data, "increment") == 0)
3014 || (strcmp(as->parms[5].items->data, "incremental") == 0)) {
3017 fprintf(STDERR, "vos: %s is not a valid argument to -overwrite\n",
3018 as->parms[5].items->data);
3022 if (as->parms[6].items)
3024 if (as->parms[7].items) {
3029 if (as->parms[8].items) {
3030 if ((strcmp(as->parms[8].items->data, "d") == 0)
3031 || (strcmp(as->parms[8].items->data, "dump") == 0)) {
3032 acreation = TS_DUMP;
3033 } else if ((strcmp(as->parms[8].items->data, "k") == 0)
3034 || (strcmp(as->parms[8].items->data, "keep") == 0)) {
3035 acreation = TS_KEEP;
3036 } else if ((strcmp(as->parms[8].items->data, "n") == 0)
3037 || (strcmp(as->parms[8].items->data, "new") == 0)) {
3040 fprintf(STDERR, "vos: %s is not a valid argument to -creation\n",
3041 as->parms[8].items->data);
3046 if (as->parms[9].items) {
3047 if ((strcmp(as->parms[9].items->data, "d") == 0)
3048 || (strcmp(as->parms[9].items->data, "dump") == 0)) {
3049 alastupdate = TS_DUMP;
3050 } else if ((strcmp(as->parms[9].items->data, "k") == 0)
3051 || (strcmp(as->parms[9].items->data, "keep") == 0)) {
3052 alastupdate = TS_KEEP;
3053 } else if ((strcmp(as->parms[9].items->data, "n") == 0)
3054 || (strcmp(as->parms[9].items->data, "new") == 0)) {
3055 alastupdate = TS_NEW;
3057 fprintf(STDERR, "vos: %s is not a valid argument to -lastupdate\n",
3058 as->parms[9].items->data);
3063 aserver = GetServer(as->parms[0].items->data);
3065 fprintf(STDERR, "vos: server '%s' not found in host table\n",
3066 as->parms[0].items->data);
3069 apart = volutil_GetPartitionID(as->parms[1].items->data);
3071 fprintf(STDERR, "vos: could not interpret partition name '%s'\n",
3072 as->parms[1].items->data);
3075 if (!IsPartValid(apart, aserver, &code)) { /*check for validity of the partition */
3077 PrintError("", code);
3080 "vos : partition %s does not exist on the server\n",
3081 as->parms[1].items->data);
3084 strcpy(avolname, as->parms[2].items->data);
3085 if (!ISNAMEVALID(avolname)) {
3087 "vos: the name of the volume %s exceeds the size limit\n",
3091 if (!VolNameOK(avolname)) {
3093 "Illegal volume name %s, should not end in .readonly or .backup\n",
3097 if (as->parms[3].items) {
3098 strcpy(afilename, as->parms[3].items->data);
3099 if (!FileExists(afilename)) {
3100 fprintf(STDERR, "Can't access file %s\n", afilename);
3104 strcpy(afilename, "");
3107 /* Check if volume exists or not */
3109 vsu_ExtractName(volname, avolname);
3110 vcode = VLDB_GetEntryByName(volname, &entry);
3111 if (vcode) { /* no volume - do a full restore */
3112 restoreflags = RV_FULLRST;
3113 if ((aoverwrite == INC) || (aoverwrite == ABORT))
3115 "Volume does not exist; Will perform a full restore\n");
3118 else if ((!readonly && Lp_GetRwIndex(&entry) == -1) /* RW volume does not exist - do a full */
3119 ||(readonly && !Lp_ROMatch(0, 0, &entry))) { /* RO volume does not exist - do a full */
3120 restoreflags = RV_FULLRST;
3121 if ((aoverwrite == INC) || (aoverwrite == ABORT))
3123 "%s Volume does not exist; Will perform a full restore\n",
3124 readonly ? "RO" : "RW");
3127 avolid = entry.volumeId[voltype];
3128 } else if (entry.volumeId[voltype] != 0
3129 && entry.volumeId[voltype] != avolid) {
3130 avolid = entry.volumeId[voltype];
3132 aparentid = entry.volumeId[RWVOL];
3135 else { /* volume exists - do we do a full incremental or abort */
3137 afs_int32 Opart, Otype, vol_elsewhere = 0;
3138 struct nvldbentry Oentry;
3142 avolid = entry.volumeId[voltype];
3143 } else if (entry.volumeId[voltype] != 0
3144 && entry.volumeId[voltype] != avolid) {
3145 avolid = entry.volumeId[voltype];
3147 aparentid = entry.volumeId[RWVOL];
3149 /* A file name was specified - check if volume is on another partition */
3150 vcode = GetVolumeInfo(avolid, &Oserver, &Opart, &Otype, &Oentry);
3154 vcode = VLDB_IsSameAddrs(Oserver, aserver, &err);
3157 "Failed to get info about server's %d address(es) from vlserver (err=%d); aborting call!\n",
3161 if (!vcode || (Opart != apart))
3164 if (aoverwrite == ASK) {
3165 if (strcmp(afilename, "") == 0) { /* The file is from standard in */
3167 "Volume exists and no -overwrite option specified; Aborting restore command\n");
3171 /* Ask what to do */
3172 if (vol_elsewhere) {
3174 "The volume %s %u already exists on a different server/part\n",
3175 volname, entry.volumeId[voltype]);
3177 "Do you want to do a full restore or abort? [fa](a): ");
3180 "The volume %s %u already exists in the VLDB\n",
3181 volname, entry.volumeId[voltype]);
3183 "Do you want to do a full/incremental restore or abort? [fia](a): ");
3186 while (!(dc == EOF || dc == '\n'))
3187 dc = getchar(); /* goto end of line */
3188 if ((c == 'f') || (c == 'F'))
3190 else if ((c == 'i') || (c == 'I'))
3196 if (aoverwrite == ABORT) {
3197 fprintf(STDERR, "Volume exists; Aborting restore command\n");
3199 } else if (aoverwrite == FULL) {
3200 restoreflags = RV_FULLRST;
3202 "Volume exists; Will delete and perform full restore\n");
3203 } else if (aoverwrite == INC) {
3205 if (vol_elsewhere) {
3207 "%s volume %lu already exists on a different server/part; not allowed\n",
3208 readonly ? "RO" : "RW", (unsigned long)avolid);
3214 restoreflags |= RV_OFFLINE;
3216 restoreflags |= RV_RDONLY;
3218 switch (acreation) {
3220 restoreflags |= RV_CRDUMP;
3223 restoreflags |= RV_CRKEEP;
3226 restoreflags |= RV_CRNEW;
3229 if (aoverwrite == FULL)
3230 restoreflags |= RV_CRNEW;
3232 restoreflags |= RV_CRKEEP;
3235 switch (alastupdate) {
3237 restoreflags |= RV_LUDUMP;
3240 restoreflags |= RV_LUKEEP;
3243 restoreflags |= RV_LUNEW;
3246 restoreflags |= RV_LUDUMP;
3248 if (as->parms[10].items) {
3249 restoreflags |= RV_NODEL;
3254 UV_RestoreVolume2(aserver, apart, avolid, aparentid,
3255 avolname, restoreflags, WriteData, afilename);
3257 PrintDiagnostics("restore", code);
3260 MapPartIdIntoName(apart, apartName);
3263 * patch typo here - originally "parms[1]", should be "parms[0]"
3266 fprintf(STDOUT, "Restored volume %s on %s %s\n", avolname,
3267 as->parms[0].items->data, apartName);
3272 LockReleaseCmd(struct cmd_syndesc *as, void *arock)
3275 afs_int32 code, err;
3277 avolid = vsu_GetVolumeID(as->parms[0].items->data, cstruct, &err);
3280 PrintError("", err);
3282 fprintf(STDERR, "vos: can't find volume '%s'\n",
3283 as->parms[0].items->data);
3287 code = UV_LockRelease(avolid);
3289 PrintDiagnostics("unlock", code);
3292 fprintf(STDOUT, "Released lock on vldb entry for volume %s\n",
3293 as->parms[0].items->data);
3298 AddSite(struct cmd_syndesc *as, void *arock)
3302 afs_int32 apart, code, err, arovolid, valid = 0;
3303 char apartName[10], avolname[VOLSER_MAXVOLNAME + 1];
3305 vsu_ExtractName(avolname, as->parms[2].items->data);;
3306 avolid = vsu_GetVolumeID(avolname, cstruct, &err);
3309 PrintError("", err);
3311 fprintf(STDERR, "vos: can't find volume '%s'\n",
3312 as->parms[2].items->data);
3316 if (as->parms[3].items) {
3317 vsu_ExtractName(avolname, as->parms[3].items->data);
3318 arovolid = vsu_GetVolumeID(avolname, cstruct, &err);
3320 fprintf(STDERR, "vos: invalid ro volume id '%s'\n",
3321 as->parms[3].items->data);
3325 aserver = GetServer(as->parms[0].items->data);
3327 fprintf(STDERR, "vos: server '%s' not found in host table\n",
3328 as->parms[0].items->data);
3331 apart = volutil_GetPartitionID(as->parms[1].items->data);
3333 fprintf(STDERR, "vos: could not interpret partition name '%s'\n",
3334 as->parms[1].items->data);
3337 if (!IsPartValid(apart, aserver, &code)) { /*check for validity of the partition */
3339 PrintError("", code);
3342 "vos : partition %s does not exist on the server\n",
3343 as->parms[1].items->data);
3346 if (as->parms[4].items) {
3349 code = UV_AddSite2(aserver, apart, avolid, arovolid, valid);
3351 PrintDiagnostics("addsite", code);
3354 MapPartIdIntoName(apart, apartName);
3355 fprintf(STDOUT, "Added replication site %s %s for volume %s\n",
3356 as->parms[0].items->data, apartName, as->parms[2].items->data);
3361 RemoveSite(struct cmd_syndesc *as, void *arock)
3366 afs_int32 apart, code, err;
3367 char apartName[10], avolname[VOLSER_MAXVOLNAME + 1];
3369 vsu_ExtractName(avolname, as->parms[2].items->data);
3370 avolid = vsu_GetVolumeID(avolname, cstruct, &err);
3373 PrintError("", err);
3375 fprintf(STDERR, "vos: can't find volume '%s'\n",
3376 as->parms[2].items->data);
3379 aserver = GetServer(as->parms[0].items->data);
3381 fprintf(STDERR, "vos: server '%s' not found in host table\n",
3382 as->parms[0].items->data);
3385 apart = volutil_GetPartitionID(as->parms[1].items->data);
3387 fprintf(STDERR, "vos: could not interpret partition name '%s'\n",
3388 as->parms[1].items->data);
3392 *skip the partition validity check, since it is possible that the partition
3393 *has since been decomissioned.
3396 if (!IsPartValid(apart,aserver,&code)){
3397 if(code) PrintError("",code);
3398 else fprintf(STDERR,"vos : partition %s does not exist on the server\n",as->parms[1].items->data);
3402 code = UV_RemoveSite(aserver, apart, avolid);
3404 PrintDiagnostics("remsite", code);
3407 MapPartIdIntoName(apart, apartName);
3408 fprintf(STDOUT, "Removed replication site %s %s for volume %s\n",
3409 as->parms[0].items->data, apartName, as->parms[2].items->data);
3414 ChangeLocation(struct cmd_syndesc *as, void *arock)
3418 afs_int32 apart, code, err;
3421 avolid = vsu_GetVolumeID(as->parms[2].items->data, cstruct, &err);
3424 PrintError("", err);
3426 fprintf(STDERR, "vos: can't find volume '%s'\n",
3427 as->parms[2].items->data);
3430 aserver = GetServer(as->parms[0].items->data);
3432 fprintf(STDERR, "vos: server '%s' not found in host table\n",
3433 as->parms[0].items->data);
3436 apart = volutil_GetPartitionID(as->parms[1].items->data);
3438 fprintf(STDERR, "vos: could not interpret partition name '%s'\n",
3439 as->parms[1].items->data);
3442 if (!IsPartValid(apart, aserver, &code)) { /*check for validity of the partition */
3444 PrintError("", code);
3447 "vos : partition %s does not exist on the server\n",
3448 as->parms[1].items->data);
3451 code = UV_ChangeLocation(aserver, apart, avolid);
3453 PrintDiagnostics("addsite", code);
3456 MapPartIdIntoName(apart, apartName);
3457 fprintf(STDOUT, "Changed location to %s %s for volume %s\n",
3458 as->parms[0].items->data, apartName, as->parms[2].items->data);
3463 ListPartitions(struct cmd_syndesc *as, void *arock)
3467 struct partList dummyPartList;
3472 aserver = GetServer(as->parms[0].items->data);
3474 fprintf(STDERR, "vos: server '%s' not found in host table\n",
3475 as->parms[0].items->data);
3480 code = UV_ListPartitions(aserver, &dummyPartList, &cnt);
3482 PrintDiagnostics("listpart", code);
3486 fprintf(STDOUT, "The partitions on the server are:\n");
3487 for (i = 0; i < cnt; i++) {
3488 if (dummyPartList.partFlags[i] & PARTVALID) {
3489 memset(pname, 0, sizeof(pname));
3490 MapPartIdIntoName(dummyPartList.partId[i], pname);
3491 fprintf(STDOUT, " %10s ", pname);
3493 if ((i % 5) == 0 && (i != 0))
3494 fprintf(STDOUT, "\n");
3497 fprintf(STDOUT, "\n");
3498 fprintf(STDOUT, "Total: %d\n", total);
3504 CompareVolName(const void *p1, const void *p2)
3506 volintInfo *arg1, *arg2;
3508 arg1 = (volintInfo *) p1;
3509 arg2 = (volintInfo *) p2;
3510 return (strcmp(arg1->name, arg2->name));
3514 /*------------------------------------------------------------------------
3515 * PRIVATE XCompareVolName
3518 * Comparison routine for volume names coming from an extended
3522 * a_obj1P : Char ptr to first extended vol info object
3523 * a_obj1P : Char ptr to second extended vol info object
3526 * The value of strcmp() on the volume names within the passed
3527 * objects (i,e., -1, 0, or 1).
3530 * Passed to qsort() as the designated comparison routine.
3534 *------------------------------------------------------------------------*/
3537 XCompareVolName(const void *a_obj1P, const void *a_obj2P)
3538 { /*XCompareVolName */
3541 (((struct volintXInfo *)(a_obj1P))->name,
3542 ((struct volintXInfo *)(a_obj2P))->name));
3544 } /*XCompareVolName */
3547 CompareVolID(const void *p1, const void *p2)
3549 volintInfo *arg1, *arg2;
3551 arg1 = (volintInfo *) p1;
3552 arg2 = (volintInfo *) p2;
3553 if (arg1->volid == arg2->volid)
3555 if (arg1->volid > arg2->volid)
3562 /*------------------------------------------------------------------------
3563 * PRIVATE XCompareVolID
3566 * Comparison routine for volume IDs coming from an extended
3570 * a_obj1P : Char ptr to first extended vol info object
3571 * a_obj1P : Char ptr to second extended vol info object
3574 * The value of strcmp() on the volume names within the passed
3575 * objects (i,e., -1, 0, or 1).
3578 * Passed to qsort() as the designated comparison routine.
3582 *------------------------------------------------------------------------*/
3585 XCompareVolID(const void *a_obj1P, const void *a_obj2P)
3586 { /*XCompareVolID */
3588 afs_int32 id1, id2; /*Volume IDs we're comparing */
3590 id1 = ((struct volintXInfo *)(a_obj1P))->volid;
3591 id2 = ((struct volintXInfo *)(a_obj2P))->volid;
3599 } /*XCompareVolID */
3601 /*------------------------------------------------------------------------
3602 * PRIVATE ListVolumes
3605 * Routine used to list volumes, contacting the Volume Server
3606 * directly, bypassing the VLDB.
3609 * as : Ptr to parsed command line arguments.
3612 * 0 Successful operation
3615 * Nothing interesting.
3619 *------------------------------------------------------------------------*/
3622 ListVolumes(struct cmd_syndesc *as, void *arock)
3624 afs_int32 apart, int32list, fast;
3628 volintInfo *oldpntr = NULL;
3632 volintXInfo *xInfoP;
3633 volintXInfo *origxInfoP = NULL; /*Ptr to current/orig extended vol info */
3634 int wantExtendedInfo; /*Do we want extended vol info? */
3637 struct partList dummyPartList;
3645 if (as->parms[3].items)
3647 if (as->parms[4].items)
3651 if (as->parms[2].items)
3657 if (as->parms[5].items) {
3659 * We can't coexist with the fast flag.
3663 "vos: Can't use the -fast and -extended flags together\n");
3668 * We need to turn on ``long'' listings to get the full effect.
3670 wantExtendedInfo = 1;
3673 wantExtendedInfo = 0;
3674 if (as->parms[1].items) {
3675 apart = volutil_GetPartitionID(as->parms[1].items->data);
3677 fprintf(STDERR, "vos: could not interpret partition name '%s'\n",
3678 as->parms[1].items->data);
3681 dummyPartList.partId[0] = apart;
3682 dummyPartList.partFlags[0] = PARTVALID;
3685 aserver = GetServer(as->parms[0].items->data);
3687 fprintf(STDERR, "vos: server '%s' not found in host table\n",
3688 as->parms[0].items->data);
3693 if (!IsPartValid(apart, aserver, &code)) { /*check for validity of the partition */
3695 PrintError("", code);
3698 "vos : partition %s does not exist on the server\n",
3699 as->parms[1].items->data);
3703 code = UV_ListPartitions(aserver, &dummyPartList, &cnt);
3705 PrintDiagnostics("listvol", code);
3709 for (i = 0; i < cnt; i++) {
3710 if (dummyPartList.partFlags[i] & PARTVALID) {
3711 if (wantExtendedInfo)
3713 UV_XListVolumes(aserver, dummyPartList.partId[i], all,
3717 UV_ListVolumes(aserver, dummyPartList.partId[i], all,
3720 PrintDiagnostics("listvol", code);
3725 if (wantExtendedInfo) {
3726 origxInfoP = xInfoP;
3727 base = (char *)xInfoP;
3730 base = (char *)pntr;
3734 if (wantExtendedInfo)
3735 qsort(base, count, sizeof(volintXInfo), XCompareVolName);
3737 qsort(base, count, sizeof(volintInfo), CompareVolName);
3739 if (wantExtendedInfo)
3740 qsort(base, count, sizeof(volintXInfo), XCompareVolID);
3742 qsort(base, count, sizeof(volintInfo), CompareVolID);
3744 MapPartIdIntoName(dummyPartList.partId[i], pname);
3747 "Total number of volumes on server %s partition %s: %lu \n",
3748 as->parms[0].items->data, pname,
3749 (unsigned long)count);
3750 if (wantExtendedInfo) {
3751 if (as->parms[6].items)
3752 XDisplayVolumes2(aserver, dummyPartList.partId[i], origxInfoP,
3753 count, int32list, fast, quiet);
3755 XDisplayVolumes(aserver, dummyPartList.partId[i], origxInfoP,
3756 count, int32list, fast, quiet);
3759 xInfoP = (volintXInfo *) 0;
3761 if (as->parms[6].items)
3762 DisplayVolumes2(aserver, dummyPartList.partId[i], oldpntr,
3765 DisplayVolumes(aserver, dummyPartList.partId[i], oldpntr,
3766 count, int32list, fast, quiet);
3769 pntr = (volintInfo *) 0;
3777 SyncVldb(struct cmd_syndesc *as, void *arock)
3779 afs_int32 pnum = 0, code; /* part name */
3785 if (as->parms[0].items) {
3786 tserver = GetServer(as->parms[0].items->data);
3788 fprintf(STDERR, "vos: host '%s' not found in host table\n",
3789 as->parms[0].items->data);
3794 if (as->parms[1].items) {
3795 pnum = volutil_GetPartitionID(as->parms[1].items->data);
3797 fprintf(STDERR, "vos: could not interpret partition name '%s'\n",
3798 as->parms[1].items->data);
3801 if (!IsPartValid(pnum, tserver, &code)) { /*check for validity of the partition */
3803 PrintError("", code);
3806 "vos: partition %s does not exist on the server\n",
3807 as->parms[1].items->data);
3814 "The -partition option requires a -server option\n");
3819 if (as->parms[3].items) {
3820 flags |= 2; /* don't update */
3823 if (as->parms[2].items) {
3824 /* Synchronize an individual volume */
3825 volname = as->parms[2].items->data;
3826 code = UV_SyncVolume(tserver, pnum, volname, flags);
3830 "Without a -volume option, the -server option is required\n");
3833 code = UV_SyncVldb(tserver, pnum, flags, 0 /*unused */ );
3837 PrintDiagnostics("syncvldb", code);
3841 /* Print a summary of what we did */
3843 fprintf(STDOUT, "VLDB volume %s synchronized", volname);
3845 fprintf(STDOUT, "VLDB synchronized");
3847 fprintf(STDOUT, " with state of server %s", as->parms[0].items->data);
3850 MapPartIdIntoName(pnum, part);
3851 fprintf(STDOUT, " partition %s\n", part);
3853 fprintf(STDOUT, "\n");
3859 SyncServer(struct cmd_syndesc *as, void *arock)
3861 afs_int32 pnum, code; /* part name */
3866 tserver = GetServer(as->parms[0].items->data);
3868 fprintf(STDERR, "vos: host '%s' not found in host table\n",
3869 as->parms[0].items->data);
3872 if (as->parms[1].items) {
3873 pnum = volutil_GetPartitionID(as->parms[1].items->data);
3875 fprintf(STDERR, "vos: could not interpret partition name '%s'\n",
3876 as->parms[1].items->data);
3879 if (!IsPartValid(pnum, tserver, &code)) { /*check for validity of the partition */
3881 PrintError("", code);
3884 "vos : partition %s does not exist on the server\n",
3885 as->parms[1].items->data);
3893 if (as->parms[2].items) {
3894 flags |= 2; /* don't update */
3896 code = UV_SyncServer(tserver, pnum, flags, 0 /*unused */ );
3898 PrintDiagnostics("syncserv", code);
3902 MapPartIdIntoName(pnum, part);
3903 fprintf(STDOUT, "Server %s partition %s synchronized with VLDB\n",
3904 as->parms[0].items->data, part);
3906 fprintf(STDOUT, "Server %s synchronized with VLDB\n",
3907 as->parms[0].items->data);
3913 VolumeInfoCmd(char *name)
3915 struct nvldbentry entry;
3918 /* The vlserver will handle names with the .readonly
3919 * and .backup extension as well as volume ids.
3921 vcode = VLDB_GetEntryByName(name, &entry);
3923 PrintError("", vcode);
3926 MapHostToNetwork(&entry);
3927 EnumerateEntry(&entry);
3929 /* Defect #3027: grubby check to handle locked volume.
3930 * If VLOP_ALLOPERS is set, the entry is locked.
3931 * Leave this routine as is, but put in correct check.
3933 PrintLocked(entry.flags);
3939 VolumeZap(struct cmd_syndesc *as, void *arock)
3941 struct nvldbentry entry;
3942 afs_uint32 volid, zapbackupid = 0, backupid = 0;
3943 afs_int32 code, server, part, err;
3945 if (as->parms[3].items) {
3946 /* force flag is on, use the other version */
3947 return NukeVolume(as);
3950 if (as->parms[4].items) {
3954 volid = vsu_GetVolumeID(as->parms[2].items->data, cstruct, &err);
3957 PrintError("", err);
3959 fprintf(STDERR, "vos: can't find volume '%s'\n",
3960 as->parms[2].items->data);
3963 part = volutil_GetPartitionID(as->parms[1].items->data);
3965 fprintf(STDERR, "vos: could not interpret partition name '%s'\n",
3966 as->parms[1].items->data);
3969 server = GetServer(as->parms[0].items->data);
3971 fprintf(STDERR, "vos: host '%s' not found in host table\n",
3972 as->parms[0].items->data);
3975 if (!IsPartValid(part, server, &code)) { /*check for validity of the partition */
3977 PrintError("", code);
3980 "vos : partition %s does not exist on the server\n",
3981 as->parms[1].items->data);
3984 code = VLDB_GetEntryByID(volid, -1, &entry);
3986 if (volid == entry.volumeId[RWVOL])
3987 backupid = entry.volumeId[BACKVOL];
3989 "Warning: Entry for volume number %lu exists in VLDB (but we're zapping it anyway!)\n",
3990 (unsigned long)volid);
3993 volintInfo *pntr = (volintInfo *) 0;
3996 code = UV_ListOneVolume(server, part, volid, &pntr);
3998 if (volid == pntr->parentID)
3999 backupid = pntr->backupID;
4005 code = UV_VolumeZap(server, part, backupid);
4007 PrintDiagnostics("zap", code);
4010 fprintf(STDOUT, "Backup Volume %lu deleted\n",
4011 (unsigned long)backupid);
4014 code = UV_VolumeZap(server, part, volid);
4016 PrintDiagnostics("zap", code);
4019 fprintf(STDOUT, "Volume %lu deleted\n", (unsigned long)volid);
4025 VolserStatus(struct cmd_syndesc *as, void *arock)
4029 transDebugInfo *pntr, *oldpntr;
4035 server = GetServer(as->parms[0].items->data);
4037 fprintf(STDERR, "vos: host '%s' not found in host table\n",
4038 as->parms[0].items->data);
4041 code = UV_VolserStatus(server, &pntr, &count);
4043 PrintDiagnostics("status", code);
4048 fprintf(STDOUT, "No active transactions on %s\n",
4049 as->parms[0].items->data);
4051 fprintf(STDOUT, "Total transactions: %d\n", count);
4053 for (i = 0; i < count; i++) {
4054 /*print out the relevant info */
4055 fprintf(STDOUT, "--------------------------------------\n");
4056 t = pntr->creationTime;
4057 fprintf(STDOUT, "transaction: %lu created: %s",
4058 (unsigned long)pntr->tid, ctime(&t));
4060 fprintf(STDOUT, "lastActiveTime: %s", ctime(&t));
4061 if (pntr->returnCode) {
4062 fprintf(STDOUT, "returnCode: %lu\n",
4063 (unsigned long)pntr->returnCode);
4066 fprintf(STDOUT, "attachFlags: ");
4067 switch (pntr->iflags) {
4069 fprintf(STDOUT, "offline ");
4072 fprintf(STDOUT, "busy ");
4075 fprintf(STDOUT, "readonly ");
4078 fprintf(STDOUT, "create ");
4081 fprintf(STDOUT, "create volid ");
4084 fprintf(STDOUT, "\n");
4087 fprintf(STDOUT, "volumeStatus: ");
4088 switch (pntr->vflags) {
4089 case VTDeleteOnSalvage:
4090 fprintf(STDOUT, "deleteOnSalvage ");
4091 case VTOutOfService:
4092 fprintf(STDOUT, "outOfService ");
4094 fprintf(STDOUT, "deleted ");
4096 fprintf(STDOUT, "\n");
4099 fprintf(STDOUT, "transactionFlags: ");
4100 fprintf(STDOUT, "delete\n");
4102 MapPartIdIntoName(pntr->partition, pname);
4103 fprintf(STDOUT, "volume: %lu partition: %s procedure: %s\n",
4104 (unsigned long)pntr->volid, pname, pntr->lastProcName);
4105 if (pntr->callValid) {
4106 t = pntr->lastReceiveTime;
4107 fprintf(STDOUT, "packetRead: %lu lastReceiveTime: %s",
4108 (unsigned long)pntr->readNext, ctime(&t));
4109 t = pntr->lastSendTime;
4110 fprintf(STDOUT, "packetSend: %lu lastSendTime: %s",
4111 (unsigned long)pntr->transmitNext, ctime(&t));
4114 fprintf(STDOUT, "--------------------------------------\n");
4115 fprintf(STDOUT, "\n");
4123 RenameVolume(struct cmd_syndesc *as, void *arock)
4125 afs_int32 code1, code2, code;
4126 struct nvldbentry entry;
4128 code1 = VLDB_GetEntryByName(as->parms[0].items->data, &entry);
4130 fprintf(STDERR, "vos: Could not find entry for volume %s\n",
4131 as->parms[0].items->data);
4134 code2 = VLDB_GetEntryByName(as->parms[1].items->data, &entry);
4135 if ((!code1) && (!code2)) { /*the newname already exists */
4136 fprintf(STDERR, "vos: volume %s already exists\n",
4137 as->parms[1].items->data);
4141 if (code1 && code2) {
4142 fprintf(STDERR, "vos: Could not find entry for volume %s or %s\n",
4143 as->parms[0].items->data, as->parms[1].items->data);
4146 if (!VolNameOK(as->parms[0].items->data)) {
4148 "Illegal volume name %s, should not end in .readonly or .backup\n",
4149 as->parms[0].items->data);
4152 if (!ISNAMEVALID(as->parms[1].items->data)) {
4154 "vos: the new volume name %s exceeds the size limit of %d\n",
4155 as->parms[1].items->data, VOLSER_OLDMAXVOLNAME - 10);
4158 if (!VolNameOK(as->parms[1].items->data)) {
4160 "Illegal volume name %s, should not end in .readonly or .backup\n",
4161 as->parms[1].items->data);
4164 if (IsNumeric(as->parms[1].items->data)) {
4165 fprintf(STDERR, "Illegal volume name %s, should not be a number\n",
4166 as->parms[1].items->data);
4169 MapHostToNetwork(&entry);
4171 UV_RenameVolume(&entry, as->parms[0].items->data,
4172 as->parms[1].items->data);
4174 PrintDiagnostics("rename", code);
4177 fprintf(STDOUT, "Renamed volume %s to %s\n", as->parms[0].items->data,
4178 as->parms[1].items->data);
4183 GetVolumeInfo(afs_uint32 volid, afs_uint32 *server, afs_int32 *part, afs_int32 *voltype,
4184 struct nvldbentry *rentry)
4189 vcode = VLDB_GetEntryByID(volid, -1, rentry);
4192 "Could not fetch the entry for volume %lu from VLDB \n",
4193 (unsigned long)volid);
4194 PrintError("", vcode);
4197 MapHostToNetwork(rentry);
4198 if (volid == rentry->volumeId[ROVOL]) {
4200 for (i = 0; i < rentry->nServers; i++) {
4201 if ((index == -1) && (rentry->serverFlags[i] & ITSROVOL)
4202 && !(rentry->serverFlags[i] & RO_DONTUSE))
4207 "RO volume is not found in VLDB entry for volume %lu\n",
4208 (unsigned long)volid);
4212 *server = rentry->serverNumber[index];
4213 *part = rentry->serverPartition[index];
4217 index = Lp_GetRwIndex(rentry);
4220 "RW Volume is not found in VLDB entry for volume %lu\n",
4221 (unsigned long)volid);
4224 if (volid == rentry->volumeId[RWVOL]) {
4226 *server = rentry->serverNumber[index];
4227 *part = rentry->serverPartition[index];
4230 if (volid == rentry->volumeId[BACKVOL]) {
4232 *server = rentry->serverNumber[index];
4233 *part = rentry->serverPartition[index];
4237 "unexpected volume type for volume %lu\n",
4238 (unsigned long)volid);
4243 DeleteEntry(struct cmd_syndesc *as, void *arock)
4245 afs_int32 apart = 0;
4248 struct VldbListByAttributes attributes;
4249 nbulkentries arrayEntries;
4250 struct nvldbentry *vllist;
4251 struct cmd_item *itp;
4254 char prefix[VOLSER_MAXVOLNAME + 1];
4256 afs_int32 totalBack = 0, totalFail = 0, err;
4258 if (as->parms[0].items) { /* -id */
4259 if (as->parms[1].items || as->parms[2].items || as->parms[3].items) {
4261 "You cannot use -server, -partition, or -prefix with the -id argument\n");
4264 for (itp = as->parms[0].items; itp; itp = itp->next) {
4265 avolid = vsu_GetVolumeID(itp->data, cstruct, &err);
4268 PrintError("", err);
4270 fprintf(STDERR, "vos: can't find volume '%s'\n",
4274 if (as->parms[4].items || as->parms[5].items) {
4275 /* -noexecute (hidden) or -dryrun */
4276 fprintf(STDOUT, "Would have deleted VLDB entry for %s \n",
4281 vcode = ubik_VL_DeleteEntry(cstruct, 0, avolid, RWVOL);
4283 fprintf(STDERR, "Could not delete entry for volume %s\n",
4286 "You must specify a RW volume name or ID "
4287 "(the entire VLDB entry will be deleted)\n");
4288 PrintError("", vcode);
4294 fprintf(STDOUT, "Deleted %d VLDB entries\n", totalBack);
4298 if (!as->parms[1].items && !as->parms[2].items && !as->parms[3].items) {
4299 fprintf(STDERR, "You must specify an option\n");
4303 /* Zero out search attributes */
4304 memset(&attributes, 0, sizeof(struct VldbListByAttributes));
4306 if (as->parms[1].items) { /* -prefix */
4307 strncpy(prefix, as->parms[1].items->data, VOLSER_MAXVOLNAME);
4309 if (!as->parms[2].items && !as->parms[3].items) { /* a single entry only */
4311 "You must provide -server with the -prefix argument\n");
4316 if (as->parms[2].items) { /* -server */
4318 aserver = GetServer(as->parms[2].items->data);
4320 fprintf(STDERR, "vos: server '%s' not found in host table\n",
4321 as->parms[2].items->data);
4324 attributes.server = ntohl(aserver);
4325 attributes.Mask |= VLLIST_SERVER;
4328 if (as->parms[3].items) { /* -partition */
4329 if (!as->parms[2].items) {
4331 "You must provide -server with the -partition argument\n");
4334 apart = volutil_GetPartitionID(as->parms[3].items->data);
4336 fprintf(STDERR, "vos: could not interpret partition name '%s'\n",
4337 as->parms[3].items->data);
4340 attributes.partition = apart;
4341 attributes.Mask |= VLLIST_PARTITION;
4344 /* Print status line of what we are doing */
4345 fprintf(STDOUT, "Deleting VLDB entries for ");
4346 if (as->parms[2].items) {
4347 fprintf(STDOUT, "server %s ", as->parms[2].items->data);
4349 if (as->parms[3].items) {
4351 MapPartIdIntoName(apart, pname);
4352 fprintf(STDOUT, "partition %s ", pname);
4355 fprintf(STDOUT, "which are prefixed with %s ", prefix);
4357 fprintf(STDOUT, "\n");
4360 /* Get all the VLDB entries on a server and/or partition */
4361 memset(&arrayEntries, 0, sizeof(arrayEntries));
4362 vcode = VLDB_ListAttributes(&attributes, &nentries, &arrayEntries);
4364 fprintf(STDERR, "Could not access the VLDB for attributes\n");
4365 PrintError("", vcode);
4369 /* Process each entry */
4370 for (j = 0; j < nentries; j++) {
4371 vllist = &arrayEntries.nbulkentries_val[j];
4373 /* It only deletes the RW volumes */
4374 if (strncmp(vllist->name, prefix, strlen(prefix))) {
4377 "Omitting to delete %s due to prefix %s mismatch\n",
4378 vllist->name, prefix);
4385 if (as->parms[4].items || as->parms[5].items) {
4386 /* -noexecute (hidden) or -dryrun */
4387 fprintf(STDOUT, "Would have deleted VLDB entry for %s \n",
4393 /* Only matches the RW volume name */
4394 avolid = vllist->volumeId[RWVOL];
4395 vcode = ubik_VL_DeleteEntry(cstruct, 0, avolid, RWVOL);
4397 fprintf(STDOUT, "Could not delete VDLB entry for %s\n",
4400 PrintError("", vcode);
4405 fprintf(STDOUT, "Deleted VLDB entry for %s \n", vllist->name);
4410 fprintf(STDOUT, "----------------------\n");
4412 "Total VLDB entries deleted: %lu; failed to delete: %lu\n",
4413 (unsigned long)totalBack, (unsigned long)totalFail);
4415 xdr_free((xdrproc_t) xdr_nbulkentries, &arrayEntries);
4421 CompareVldbEntryByName(const void *p1, const void *p2)
4423 struct nvldbentry *arg1, *arg2;
4425 arg1 = (struct nvldbentry *)p1;
4426 arg2 = (struct nvldbentry *)p2;
4427 return (strcmp(arg1->name, arg2->name));
4431 static int CompareVldbEntry(char *p1, char *p2)
4433 struct nvldbentry *arg1,*arg2;
4436 char comp1[100],comp2[100];
4437 char temp1[20],temp2[20];
4439 arg1 = (struct nvldbentry *)p1;
4440 arg2 = (struct nvldbentry *)p2;
4444 for(i = 0; i < arg1->nServers; i++)
4445 if(arg1->serverFlags[i] & ITSRWVOL) pos1 = i;
4446 for(i = 0; i < arg2->nServers; i++)
4447 if(arg2->serverFlags[i] & ITSRWVOL) pos2 = i;
4448 if(pos1 == -1 || pos2 == -1){
4452 sprintf(comp1,"%10u",arg1->serverNumber[pos1]);
4453 sprintf(comp2,"%10u",arg2->serverNumber[pos2]);
4454 sprintf(temp1,"%10u",arg1->serverPartition[pos1]);
4455 sprintf(temp2,"%10u",arg2->serverPartition[pos2]);
4456 strcat(comp1,temp1);
4457 strcat(comp2,temp2);
4458 strcat(comp1,arg1->name);
4459 strcat(comp1,arg2->name);
4460 return(strcmp(comp1,comp2));
4466 ListVLDB(struct cmd_syndesc *as, void *arock)
4472 struct VldbListByAttributes attributes;
4473 nbulkentries arrayEntries;
4474 struct nvldbentry *vllist, *tarray = 0, *ttarray;
4475 afs_int32 centries, nentries = 0;
4476 afs_int32 tarraysize = 0;
4477 afs_int32 parraysize;
4480 int quiet, sort, lock;
4481 afs_int32 thisindex, nextindex;
4486 attributes.Mask = 0;
4487 lock = (as->parms[3].items ? 1 : 0); /* -lock flag */
4488 quiet = (as->parms[4].items ? 1 : 0); /* -quit flag */
4489 sort = (as->parms[5].items ? 0 : 1); /* -nosort flag */
4491 /* If the volume name is given, Use VolumeInfoCmd to look it up
4492 * and not ListAttributes.
4494 if (as->parms[0].items) {
4497 "vos: illegal use of '-locked' switch, need to specify server and/or partition\n");
4500 code = VolumeInfoCmd(as->parms[0].items->data);
4502 PrintError("", code);
4508 /* Server specified */
4509 if (as->parms[1].items) {
4510 aserver = GetServer(as->parms[1].items->data);
4512 fprintf(STDERR, "vos: server '%s' not found in host table\n",
4513 as->parms[1].items->data);
4516 attributes.server = ntohl(aserver);
4517 attributes.Mask |= VLLIST_SERVER;
4520 /* Partition specified */
4521 if (as->parms[2].items) {
4522 apart = volutil_GetPartitionID(as->parms[2].items->data);
4524 fprintf(STDERR, "vos: could not interpret partition name '%s'\n",
4525 as->parms[2].items->data);
4528 attributes.partition = apart;
4529 attributes.Mask |= VLLIST_PARTITION;
4533 attributes.Mask |= VLLIST_FLAG;
4534 attributes.flag = VLOP_ALLOPERS;
4537 /* Print header information */
4539 MapPartIdIntoName(apart, pname);
4540 fprintf(STDOUT, "VLDB entries for %s %s%s%s %s\n",
4541 (as->parms[1].items ? "server" : "all"),
4542 (as->parms[1].items ? as->parms[1].items->data : "servers"),
4543 (as->parms[2].items ? " partition " : ""),
4544 (as->parms[2].items ? pname : ""),
4545 (lock ? "which are locked:" : ""));
4548 for (thisindex = 0; (thisindex != -1); thisindex = nextindex) {
4549 memset(&arrayEntries, 0, sizeof(arrayEntries));
4554 VLDB_ListAttributesN2(&attributes, 0, thisindex, ¢ries,
4555 &arrayEntries, &nextindex);
4556 if (vcode == RXGEN_OPCODE) {
4557 /* Vlserver not running with ListAttributesN2. Fall back */
4559 VLDB_ListAttributes(&attributes, ¢ries, &arrayEntries);
4563 fprintf(STDERR, "Could not access the VLDB for attributes\n");
4564 PrintError("", vcode);
4567 nentries += centries;
4569 /* We don't sort, so just print the entries now */
4571 for (j = 0; j < centries; j++) { /* process each entry */
4572 vllist = &arrayEntries.nbulkentries_val[j];
4573 MapHostToNetwork(vllist);
4574 EnumerateEntry(vllist);
4576 PrintLocked(vllist->flags);
4580 /* So we sort. First we must collect all the entries and keep
4583 else if (centries > 0) {
4585 /* malloc the first bulk entries array */
4586 tarraysize = centries * sizeof(struct nvldbentry);
4587 tarray = malloc(tarraysize);
4590 "Could not allocate enough space for the VLDB entries\n");
4593 memcpy((char*)tarray, arrayEntries.nbulkentries_val, tarraysize);
4595 /* Grow the tarray to keep the extra entries */
4596 parraysize = (centries * sizeof(struct nvldbentry));
4598 (struct nvldbentry *)realloc(tarray,
4599 tarraysize + parraysize);
4602 "Could not allocate enough space for the VLDB entries\n");
4608 memcpy(((char *)tarray) + tarraysize,
4609 (char *)arrayEntries.nbulkentries_val, parraysize);
4610 tarraysize += parraysize;
4614 /* Free the bulk array */
4615 xdr_free((xdrproc_t) xdr_nbulkentries, &arrayEntries);
4618 /* Here is where we now sort all the entries and print them */
4619 if (sort && (nentries > 0)) {
4620 qsort((char *)tarray, nentries, sizeof(struct nvldbentry),
4621 CompareVldbEntryByName);
4622 for (vllist = tarray, j = 0; j < nentries; j++, vllist++) {
4623 MapHostToNetwork(vllist);
4624 EnumerateEntry(vllist);
4626 PrintLocked(vllist->flags);
4632 fprintf(STDOUT, "\nTotal entries: %lu\n", (unsigned long)nentries);
4639 BackSys(struct cmd_syndesc *as, void *arock)
4642 afs_int32 apart = 0;
4643 afs_uint32 aserver = 0, aserver1;
4644 afs_int32 code, apart1;
4646 struct VldbListByAttributes attributes;
4647 nbulkentries arrayEntries;
4648 struct nvldbentry *vllist;
4652 int seenprefix, seenxprefix, exclude, ex, exp, noaction;
4653 afs_int32 totalBack = 0;
4654 afs_int32 totalFail = 0;
4658 struct cmd_item *ti;
4660 #ifndef HAVE_POSIX_REGEX
4664 memset(&attributes, 0, sizeof(struct VldbListByAttributes));
4665 attributes.Mask = 0;
4667 seenprefix = (as->parms[0].items ? 1 : 0);
4668 exclude = (as->parms[3].items ? 1 : 0);
4669 seenxprefix = (as->parms[4].items ? 1 : 0);
4670 noaction = (as->parms[5].items ? 1 : 0);
4672 if (as->parms[1].items) { /* -server */
4673 aserver = GetServer(as->parms[1].items->data);
4675 fprintf(STDERR, "vos: server '%s' not found in host table\n",
4676 as->parms[1].items->data);
4679 attributes.server = ntohl(aserver);
4680 attributes.Mask |= VLLIST_SERVER;
4683 if (as->parms[2].items) { /* -partition */
4684 apart = volutil_GetPartitionID(as->parms[2].items->data);
4686 fprintf(STDERR, "vos: could not interpret partition name '%s'\n",
4687 as->parms[2].items->data);
4690 attributes.partition = apart;
4691 attributes.Mask |= VLLIST_PARTITION;
4694 /* Check to make sure the prefix and xprefix expressions compile ok */
4696 for (ti = as->parms[0].items; ti; ti = ti->next) {
4697 if (strncmp(ti->data, "^", 1) == 0) {
4698 #ifdef HAVE_POSIX_REGEX
4702 code = regcomp(&re, ti->data, REG_NOSUB);
4704 regerror(code, &re, errbuf, sizeof errbuf);
4706 "Unrecognizable -prefix regular expression: '%s': %s\n",
4712 ccode = (char *)re_comp(ti->data);
4715 "Unrecognizable -prefix regular expression: '%s': %s\n",
4724 for (ti = as->parms[4].items; ti; ti = ti->next) {
4725 if (strncmp(ti->data, "^", 1) == 0) {
4726 #ifdef HAVE_POSIX_REGEX
4730 code = regcomp(&re, ti->data, REG_NOSUB);
4732 regerror(code, &re, errbuf, sizeof errbuf);
4734 "Unrecognizable -xprefix regular expression: '%s': %s\n",
4740 ccode = (char *)re_comp(ti->data);
4743 "Unrecognizable -xprefix regular expression: '%s': %s\n",
4752 memset(&arrayEntries, 0, sizeof(arrayEntries)); /* initialize to hint the stub to alloc space */
4753 vcode = VLDB_ListAttributes(&attributes, &nentries, &arrayEntries);
4755 fprintf(STDERR, "Could not access the VLDB for attributes\n");
4756 PrintError("", vcode);
4760 if (as->parms[1].items || as->parms[2].items || verbose) {
4761 fprintf(STDOUT, "%s up volumes",
4762 (noaction ? "Would have backed" : "Backing"));
4764 if (as->parms[1].items) {
4765 fprintf(STDOUT, " on server %s", as->parms[1].items->data);
4766 } else if (as->parms[2].items) {
4767 fprintf(STDOUT, " for all servers");
4770 if (as->parms[2].items) {
4771 MapPartIdIntoName(apart, pname);
4772 fprintf(STDOUT, " partition %s", pname);
4775 if (seenprefix || (!seenprefix && seenxprefix)) {
4776 ti = (seenprefix ? as->parms[0].items : as->parms[4].items);
4777 ex = (seenprefix ? exclude : !exclude);
4778 exp = (strncmp(ti->data, "^", 1) == 0);
4779 fprintf(STDOUT, " which %smatch %s '%s'", (ex ? "do not " : ""),
4780 (exp ? "expression" : "prefix"), ti->data);
4781 for (ti = ti->next; ti; ti = ti->next) {
4782 exp = (strncmp(ti->data, "^", 1) == 0);
4783 printf(" %sor %s '%s'", (ex ? "n" : ""),
4784 (exp ? "expression" : "prefix"), ti->data);
4788 if (seenprefix && seenxprefix) {
4789 ti = as->parms[4].items;
4790 exp = (strncmp(ti->data, "^", 1) == 0);
4791 fprintf(STDOUT, " %swhich match %s '%s'",
4792 (exclude ? "adding those " : "removing those "),
4793 (exp ? "expression" : "prefix"), ti->data);
4794 for (ti = ti->next; ti; ti = ti->next) {
4795 exp = (strncmp(ti->data, "^", 1) == 0);
4796 printf(" or %s '%s'", (exp ? "expression" : "prefix"),
4800 fprintf(STDOUT, " .. ");
4802 fprintf(STDOUT, "\n");
4806 for (j = 0; j < nentries; j++) { /* process each vldb entry */
4807 vllist = &arrayEntries.nbulkentries_val[j];
4810 for (ti = as->parms[0].items; ti; ti = ti->next) {
4811 if (strncmp(ti->data, "^", 1) == 0) {
4812 #ifdef HAVE_POSIX_REGEX
4816 /* XXX -- should just do the compile once! */
4817 code = regcomp(&re, ti->data, REG_NOSUB);
4819 regerror(code, &re, errbuf, sizeof errbuf);
4821 "Error in -prefix regular expression: '%s': %s\n",
4825 match = (regexec(&re, vllist->name, 0, NULL, 0) == 0);
4828 ccode = (char *)re_comp(ti->data);
4831 "Error in -prefix regular expression: '%s': %s\n",
4835 match = (re_exec(vllist->name) == 1);
4839 (strncmp(vllist->name, ti->data, strlen(ti->data)) ==
4849 /* Without the -exclude flag: If it matches the prefix, then
4850 * check if we want to exclude any from xprefix.
4851 * With the -exclude flag: If it matches the prefix, then
4852 * check if we want to add any from xprefix.
4854 if (match && seenxprefix) {
4855 for (ti = as->parms[4].items; ti; ti = ti->next) {
4856 if (strncmp(ti->data, "^", 1) == 0) {
4857 #ifdef HAVE_POSIX_REGEX
4861 /* XXX -- should just do the compile once! */
4862 code = regcomp(&re, ti->data, REG_NOSUB);
4864 regerror(code, &re, errbuf, sizeof errbuf);
4866 "Error in -xprefix regular expression: '%s': %s\n",
4870 if (regexec(&re, vllist->name, 0, NULL, 0) == 0)
4874 ccode = (char *)re_comp(ti->data);
4877 "Error in -xprefix regular expression: '%s': %s\n",
4881 if (re_exec(vllist->name) == 1) {
4887 if (strncmp(vllist->name, ti->data, strlen(ti->data)) ==
4897 match = !match; /* -exclude will reverse the match */
4899 continue; /* Skip if no match */
4901 /* Print list of volumes to backup */
4903 fprintf(STDOUT, " %s\n", vllist->name);
4907 if (!(vllist->flags & RW_EXISTS)) {
4910 "Omitting to backup %s since RW volume does not exist \n",
4912 fprintf(STDOUT, "\n");
4918 avolid = vllist->volumeId[RWVOL];
4919 MapHostToNetwork(vllist);
4920 GetServerAndPart(vllist, RWVOL, &aserver1, &apart1, &previdx);
4921 if (aserver1 == -1 || apart1 == -1) {
4922 fprintf(STDOUT, "could not backup %s, invalid VLDB entry\n",
4928 same = VLDB_IsSameAddrs(aserver, aserver1, &error);
4931 "Failed to get info about server's %d address(es) from vlserver (err=%d); aborting call!\n",
4937 if ((aserver && !same) || (apart && (apart != apart1))) {
4940 "Omitting to backup %s since the RW is in a different location\n",
4946 time_t now = time(0);
4947 fprintf(STDOUT, "Creating backup volume for %s on %s",
4948 vllist->name, ctime(&now));
4952 code = UV_BackupVolume(aserver1, apart1, avolid);
4954 fprintf(STDOUT, "Could not backup %s\n", vllist->name);
4960 fprintf(STDOUT, "\n");
4962 } /* process each vldb entry */
4963 fprintf(STDOUT, "done\n");
4964 fprintf(STDOUT, "Total volumes backed up: %lu; failed to backup: %lu\n",
4965 (unsigned long)totalBack, (unsigned long)totalFail);
4967 xdr_free((xdrproc_t) xdr_nbulkentries, &arrayEntries);
4972 UnlockVLDB(struct cmd_syndesc *as, void *arock)
4975 afs_uint32 aserver = 0;
4978 struct VldbListByAttributes attributes;
4979 nbulkentries arrayEntries;
4980 struct nvldbentry *vllist;
4989 attributes.Mask = 0;
4991 if (as->parms[0].items) { /* server specified */
4992 aserver = GetServer(as->parms[0].items->data);
4994 fprintf(STDERR, "vos: server '%s' not found in host table\n",
4995 as->parms[0].items->data);
4998 attributes.server = ntohl(aserver);
4999 attributes.Mask |= VLLIST_SERVER;
5001 if (as->parms[1].items) { /* partition specified */
5002 apart = volutil_GetPartitionID(as->parms[1].items->data);
5004 fprintf(STDERR, "vos: could not interpret partition name '%s'\n",
5005 as->parms[1].items->data);
5008 if (!IsPartValid(apart, aserver, &code)) { /*check for validity of the partition */
5010 PrintError("", code);
5013 "vos : partition %s does not exist on the server\n",
5014 as->parms[1].items->data);
5017 attributes.partition = apart;
5018 attributes.Mask |= VLLIST_PARTITION;
5020 attributes.flag = VLOP_ALLOPERS;
5021 attributes.Mask |= VLLIST_FLAG;
5022 memset(&arrayEntries, 0, sizeof(arrayEntries)); /*initialize to hint the stub to alloc space */
5023 vcode = VLDB_ListAttributes(&attributes, &nentries, &arrayEntries);
5025 fprintf(STDERR, "Could not access the VLDB for attributes\n");
5026 PrintError("", vcode);
5029 for (j = 0; j < nentries; j++) { /* process each entry */
5030 vllist = &arrayEntries.nbulkentries_val[j];
5031 volid = vllist->volumeId[RWVOL];
5033 ubik_VL_ReleaseLock(cstruct, 0, volid, -1,
5034 LOCKREL_OPCODE | LOCKREL_AFSID |
5037 fprintf(STDERR, "Could not unlock entry for volume %s\n",
5039 PrintError("", vcode);
5044 MapPartIdIntoName(apart, pname);
5047 "Could not lock %lu VLDB entries of %lu locked entries\n",
5048 (unsigned long)totalE, (unsigned long)nentries);
5050 if (as->parms[0].items) {
5052 "Unlocked all the VLDB entries for volumes on server %s ",
5053 as->parms[0].items->data);
5054 if (as->parms[1].items) {
5055 MapPartIdIntoName(apart, pname);
5056 fprintf(STDOUT, "partition %s\n", pname);
5058 fprintf(STDOUT, "\n");
5060 } else if (as->parms[1].items) {
5061 MapPartIdIntoName(apart, pname);
5063 "Unlocked all the VLDB entries for volumes on partition %s on all servers\n",
5068 xdr_free((xdrproc_t) xdr_nbulkentries, &arrayEntries);
5073 PrintInt64Size(afs_uint64 in)
5077 static char output[16];
5079 SplitInt64(in,hi,lo);
5083 } else if (!(hi & 0xFFFFFC00)) {
5085 lo = (hi << 22) | (lo >> 10);
5086 } else if (!(hi & 0xFFF00000)) {
5088 lo = (hi << 12) | (lo >> 20);
5089 } else if (!(hi & 0xC0000000)) {
5091 lo = (hi << 2) | (lo >> 30);
5096 sprintf(output,"%u %s", lo, units);
5101 PartitionInfo(struct cmd_syndesc *as, void *arock)
5107 struct diskPartition64 partition;
5108 struct partList dummyPartList;
5110 int printSummary=0, sumPartitions=0;
5111 afs_uint64 sumFree, sumStorage;
5114 ZeroInt64(sumStorage);
5116 aserver = GetServer(as->parms[0].items->data);
5118 fprintf(STDERR, "vos: server '%s' not found in host table\n",
5119 as->parms[0].items->data);
5122 if (as->parms[1].items) {
5123 apart = volutil_GetPartitionID(as->parms[1].items->data);
5125 fprintf(STDERR, "vos: could not interpret partition name '%s'\n",
5126 as->parms[1].items->data);
5129 dummyPartList.partId[0] = apart;
5130 dummyPartList.partFlags[0] = PARTVALID;
5133 if (as->parms[2].items) {
5137 if (!IsPartValid(apart, aserver, &code)) { /*check for validity of the partition */
5139 PrintError("", code);
5142 "vos : partition %s does not exist on the server\n",
5143 as->parms[1].items->data);
5147 code = UV_ListPartitions(aserver, &dummyPartList, &cnt);
5149 PrintDiagnostics("listpart", code);
5153 for (i = 0; i < cnt; i++) {
5154 if (dummyPartList.partFlags[i] & PARTVALID) {
5155 MapPartIdIntoName(dummyPartList.partId[i], pname);
5156 code = UV_PartitionInfo64(aserver, pname, &partition);
5158 fprintf(STDERR, "Could not get information on partition %s\n",
5160 PrintError("", code);
5164 "Free space on partition %s: %" AFS_INT64_FMT " K blocks out of total %" AFS_INT64_FMT "\n",
5165 pname, partition.free, partition.minFree);
5167 AddUInt64(sumFree,partition.free,&sumFree);
5168 AddUInt64(sumStorage,partition.minFree,&sumStorage);
5173 "Summary: %s free out of ",
5174 PrintInt64Size(sumFree));
5176 "%s on %d partitions\n",
5177 PrintInt64Size(sumStorage),
5184 ChangeAddr(struct cmd_syndesc *as, void *arock)
5186 afs_int32 ip1, ip2, vcode;
5190 ip1 = GetServerNoresolve(as->parms[0].items->data);
5192 ip1 = GetServer(as->parms[0].items->data);
5194 fprintf(STDERR, "vos: invalid host address\n");
5198 if ((as->parms[1].items && as->parms[2].items)
5199 || (!as->parms[1].items && !as->parms[2].items)) {
5201 "vos: Must specify either '-newaddr <addr>' or '-remove' flag\n");
5205 if (as->parms[1].items) {
5207 ip2 = GetServerNoresolve(as->parms[1].items->data);
5209 ip2 = GetServer(as->parms[1].items->data);
5211 fprintf(STDERR, "vos: invalid host address\n");
5215 /* Play a trick here. If we are removing an address, ip1 will be -1
5216 * and ip2 will be the original address. This switch prevents an
5217 * older revision vlserver from removing the IP address.
5224 vcode = ubik_VL_ChangeAddr(cstruct, UBIK_CALL_NEW, ntohl(ip1), ntohl(ip2));
5226 char hoststr1[16], hoststr2[16];
5228 afs_inet_ntoa_r(ip2, hoststr2);
5229 fprintf(STDERR, "Could not remove server %s from the VLDB\n",
5231 if (vcode == VL_NOENT) {
5233 "vlserver does not support the remove flag or ");
5236 afs_inet_ntoa_r(ip1, hoststr1);
5237 afs_inet_ntoa_r(ip2, hoststr2);
5238 fprintf(STDERR, "Could not change server %s to server %s\n",
5239 hoststr1, hoststr2);
5241 PrintError("", vcode);
5246 fprintf(STDOUT, "Removed server %s from the VLDB\n",
5247 as->parms[0].items->data);
5249 fprintf(STDOUT, "Changed server %s to server %s\n",
5250 as->parms[0].items->data, as->parms[1].items->data);
5256 print_addrs(const bulkaddrs * addrs, afsUUID * m_uuid, int nentries,
5264 afsUUID_to_string(m_uuid, buf, sizeof(buf));
5265 printf("UUID: %s\n", buf);
5268 /* print out the list of all the server */
5269 addrp = (afs_uint32 *) addrs->bulkaddrs_val;
5270 for (i = 0; i < nentries; i++, addrp++) {
5271 *addrp = htonl(*addrp);
5274 printf("%s\n", afs_inet_ntoa_r(*addrp, hoststr));
5276 printf("%s\n", hostutil_GetNameByINet(*addrp));
5287 ListAddrs(struct cmd_syndesc *as, void *arock)
5289 afs_int32 vcode, m_uniq=0;
5290 afs_int32 i, printuuid = 0;
5291 struct VLCallBack vlcb;
5294 ListAddrByAttributes m_attrs;
5295 afsUUID m_uuid, askuuid;
5296 afs_int32 m_nentries;
5298 memset(&m_attrs, 0, sizeof(struct ListAddrByAttributes));
5299 m_attrs.Mask = VLADDR_INDEX;
5301 memset(&askuuid, 0, sizeof(afsUUID));
5302 if (as->parms[0].items) {
5304 if (afsUUID_from_string(as->parms[0].items->data, &askuuid) < 0) {
5305 fprintf(STDERR, "vos: invalid UUID '%s'\n",
5306 as->parms[0].items->data);
5309 m_attrs.Mask = VLADDR_UUID;
5310 m_attrs.uuid = askuuid;
5312 if (as->parms[1].items) {
5316 he = hostutil_GetHostByName((char *)as->parms[1].items->data);
5318 fprintf(STDERR, "vos: Can't get host info for '%s'\n",
5319 as->parms[1].items->data);
5322 memcpy(&saddr, he->h_addr, 4);
5323 m_attrs.Mask = VLADDR_IPADDR;
5324 m_attrs.ipaddr = ntohl(saddr);
5326 if (as->parms[2].items) {
5330 memset(&m_addrs, 0, sizeof(bulkaddrs));
5331 memset(&vlcb, 0, sizeof(struct VLCallBack));
5334 ubik_VL_GetAddrs(cstruct, UBIK_CALL_NEW, 0, 0, &vlcb, &nentries,
5337 fprintf(STDERR, "vos: could not list the server addresses\n");
5338 PrintError("", vcode);
5347 xdr_free((xdrproc_t)xdr_bulkaddrs, &m_addrs); /* reset addr list */
5349 ubik_VL_GetAddrsU(cstruct, UBIK_CALL_NEW, &m_attrs, &m_uuid,
5350 &m_uniq, &m_nentries, &m_addrs);
5352 if (vcode == VL_NOENT) {
5353 if (m_attrs.Mask == VLADDR_UUID) {
5354 fprintf(STDERR, "vos: no entry for UUID '%s' found in VLDB\n",
5355 as->parms[0].items->data);
5357 } else if (m_attrs.Mask == VLADDR_IPADDR) {
5358 fprintf(STDERR, "vos: no entry for host '%s' [0x%08x] found in VLDB\n",
5359 as->parms[1].items->data, m_attrs.ipaddr);
5368 if (vcode == VL_INDEXERANGE) {
5369 vcode = 0; /* not an error, just means we're done */
5374 fprintf(STDERR, "vos: could not list the server addresses\n");
5375 PrintError("", vcode);
5379 print_addrs(&m_addrs, &m_uuid, m_nentries, printuuid);
5382 if ((as->parms[1].items) || (as->parms[0].items) || (i > nentries))
5387 xdr_free((xdrproc_t)xdr_bulkaddrs, &m_addrs);
5393 SetAddrs(struct cmd_syndesc *as, void *arock)
5398 afs_uint32 FS_HostAddrs_HBO[ADDRSPERSITE];
5400 memset(&m_addrs, 0, sizeof(bulkaddrs));
5401 memset(&askuuid, 0, sizeof(afsUUID));
5402 if (as->parms[0].items) {
5404 if (afsUUID_from_string(as->parms[0].items->data, &askuuid) < 0) {
5405 fprintf(STDERR, "vos: invalid UUID '%s'\n",
5406 as->parms[0].items->data);
5410 if (as->parms[1].items) {
5412 struct cmd_item *ti;
5416 for (ti = as->parms[1].items; ti && i < ADDRSPERSITE; ti = ti->next) {
5419 saddr = GetServerNoresolve(ti->data);
5421 saddr = GetServer(ti->data);
5424 fprintf(STDERR, "vos: Can't get host info for '%s'\n",
5428 /* Convert it to host byte order */
5429 FS_HostAddrs_HBO[i] = ntohl(saddr);
5432 m_addrs.bulkaddrs_len = i;
5433 m_addrs.bulkaddrs_val = FS_HostAddrs_HBO;
5436 vcode = ubik_VL_RegisterAddrs(cstruct, 0, &askuuid, 0, &m_addrs);
5439 if (vcode == VL_MULTIPADDR) {
5440 fprintf(STDERR, "vos: VL_RegisterAddrs rpc failed; The IP address exists on a different server; repair it\n");
5441 PrintError("", vcode);
5443 } else if (vcode == RXGEN_OPCODE) {
5444 fprintf(STDERR, "vlserver doesn't support VL_RegisterAddrs rpc; ignored\n");
5445 PrintError("", vcode);
5450 fprintf(STDOUT, "vos: Changed UUID with addresses:\n");
5451 print_addrs(&m_addrs, &askuuid, m_addrs.bulkaddrs_len, 1);
5457 LockEntry(struct cmd_syndesc *as, void *arock)
5460 afs_int32 vcode, err;
5462 avolid = vsu_GetVolumeID(as->parms[0].items->data, cstruct, &err);
5465 PrintError("", err);
5467 fprintf(STDERR, "vos: can't find volume '%s'\n",
5468 as->parms[0].items->data);
5471 vcode = ubik_VL_SetLock(cstruct, 0, avolid, -1, VLOP_DELETE);
5473 fprintf(STDERR, "Could not lock VLDB entry for volume %s\n",
5474 as->parms[0].items->data);
5475 PrintError("", vcode);
5478 fprintf(STDOUT, "Locked VLDB entry for volume %s\n",
5479 as->parms[0].items->data);
5484 ConvertRO(struct cmd_syndesc *as, void *arock)
5486 afs_int32 partition = -1;
5489 afs_int32 code, i, same;
5490 struct nvldbentry entry, storeEntry;
5492 afs_int32 rwindex = 0;
5493 afs_uint32 rwserver = 0;
5494 afs_int32 rwpartition = 0;
5495 afs_int32 roindex = 0;
5496 afs_uint32 roserver = 0;
5497 afs_int32 ropartition = 0;
5499 struct rx_connection *aconn;
5502 server = GetServer(as->parms[0].items->data);
5504 fprintf(STDERR, "vos: host '%s' not found in host table\n",
5505 as->parms[0].items->data);
5508 partition = volutil_GetPartitionID(as->parms[1].items->data);
5509 if (partition < 0) {
5510 fprintf(STDERR, "vos: could not interpret partition name '%s'\n",
5511 as->parms[1].items->data);
5514 if (!IsPartValid(partition, server, &code)) {
5516 PrintError("", code);
5519 "vos : partition %s does not exist on the server\n",
5520 as->parms[1].items->data);
5523 volid = vsu_GetVolumeID(as->parms[2].items->data, cstruct, &code);
5526 PrintError("", code);
5528 fprintf(STDERR, "Unknown volume ID or name '%s'\n",
5529 as->parms[0].items->data);
5532 if (as->parms[3].items)
5535 vcode = VLDB_GetEntryByID(volid, -1, &entry);
5538 "Could not fetch the entry for volume %lu from VLDB\n",
5539 (unsigned long)volid);
5540 PrintError("convertROtoRW", code);
5544 /* use RO volid even if user specified RW or BK volid */
5546 if (volid != entry.volumeId[ROVOL])
5547 volid = entry.volumeId[ROVOL];
5549 MapHostToNetwork(&entry);
5550 for (i = 0; i < entry.nServers; i++) {
5551 if (entry.serverFlags[i] & ITSRWVOL) {
5553 rwserver = entry.serverNumber[i];
5554 rwpartition = entry.serverPartition[i];
5556 if (entry.serverFlags[i] & ITSROVOL) {
5557 same = VLDB_IsSameAddrs(server, entry.serverNumber[i], &code);
5560 "Failed to get info about server's %d address(es) from vlserver (err=%d); aborting call!\n",
5566 roserver = entry.serverNumber[i];
5567 ropartition = entry.serverPartition[i];
5573 fprintf(STDERR, "Warning: RO volume didn't exist in vldb!\n");
5575 if (ropartition != partition) {
5577 "Warning: RO volume should be in partition %d instead of %d (vldb)\n",
5578 ropartition, partition);
5583 "VLDB indicates that a RW volume exists already on %s in partition %s.\n",
5584 hostutil_GetNameByINet(rwserver),
5585 volutil_PartitionName(rwpartition));
5587 fprintf(STDERR, "Overwrite this VLDB entry? [y|n] (n)\n");
5589 while (!(dc == EOF || dc == '\n'))
5590 dc = getchar(); /* goto end of line */
5591 if ((c != 'y') && (c != 'Y')) {
5592 fprintf(STDERR, "aborted.\n");
5599 ubik_VL_SetLock(cstruct, 0, entry.volumeId[RWVOL], RWVOL,
5601 aconn = UV_Bind(server, AFSCONF_VOLUMEPORT);
5602 code = AFSVolConvertROtoRWvolume(aconn, partition, volid);
5605 "Converting RO volume %lu to RW volume failed with code %d\n",
5606 (unsigned long)volid, code);
5607 PrintError("convertROtoRW ", code);
5610 entry.serverFlags[roindex] = ITSRWVOL;
5611 entry.flags |= RW_EXISTS;
5612 entry.flags &= ~BACK_EXISTS;
5615 if (rwindex != entry.nServers) {
5616 entry.serverNumber[rwindex] = entry.serverNumber[entry.nServers];
5617 entry.serverPartition[rwindex] =
5618 entry.serverPartition[entry.nServers];
5619 entry.serverFlags[rwindex] = entry.serverFlags[entry.nServers];
5620 entry.serverNumber[entry.nServers] = 0;
5621 entry.serverPartition[entry.nServers] = 0;
5622 entry.serverFlags[entry.nServers] = 0;
5625 entry.flags &= ~RO_EXISTS;
5626 for (i = 0; i < entry.nServers; i++) {
5627 if (entry.serverFlags[i] & ITSROVOL) {
5628 if (!(entry.serverFlags[i] & (RO_DONTUSE | NEW_REPSITE)))
5629 entry.flags |= RO_EXISTS;
5632 MapNetworkToHost(&entry, &storeEntry);
5634 VLDB_ReplaceEntry(entry.volumeId[RWVOL], RWVOL, &storeEntry,
5635 (LOCKREL_OPCODE | LOCKREL_AFSID |
5636 LOCKREL_TIMESTAMP));
5639 "Warning: volume converted, but vldb update failed with code %d!\n",
5642 vcode = UV_LockRelease(entry.volumeId[RWVOL]);
5644 PrintDiagnostics("unlock", vcode);
5650 Sizes(struct cmd_syndesc *as, void *arock)
5654 afs_int32 apart, voltype, fromdate = 0, code, err, i;
5655 struct nvldbentry entry;
5656 volintSize vol_size;
5658 rx_SetRxDeadTime(60 * 10);
5659 for (i = 0; i < MAXSERVERS; i++) {
5660 struct rx_connection *rxConn = ubik_GetRPCConn(cstruct, i);
5663 rx_SetConnDeadTime(rxConn, rx_connDeadTime);
5664 if (rxConn->service)
5665 rxConn->service->connDeadTime = rx_connDeadTime;
5668 avolid = vsu_GetVolumeID(as->parms[0].items->data, cstruct, &err);
5671 PrintError("", err);
5673 fprintf(STDERR, "vos: can't find volume '%s'\n",
5674 as->parms[0].items->data);
5678 if (as->parms[1].items || as->parms[2].items) {
5679 if (!as->parms[1].items || !as->parms[2].items) {
5681 "Must specify both -server and -partition options\n");
5684 aserver = GetServer(as->parms[2].items->data);
5686 fprintf(STDERR, "Invalid server name\n");
5689 apart = volutil_GetPartitionID(as->parms[1].items->data);
5691 fprintf(STDERR, "Invalid partition name\n");
5695 code = GetVolumeInfo(avolid, &aserver, &apart, &voltype, &entry);
5702 if (as->parms[4].items && strcmp(as->parms[4].items->data, "0")) {
5703 code = ktime_DateToInt32(as->parms[4].items->data, &fromdate);
5705 fprintf(STDERR, "vos: failed to parse date '%s' (error=%d))\n",
5706 as->parms[4].items->data, code);
5711 fprintf(STDOUT, "Volume: %s\n", as->parms[0].items->data);
5713 if (as->parms[3].items) { /* do the dump estimate */
5714 vol_size.dump_size = 0;
5715 code = UV_GetSize(avolid, aserver, apart, fromdate, &vol_size);
5717 PrintDiagnostics("size", code);
5720 /* presumably the size info is now gathered in pntr */
5721 /* now we display it */
5723 fprintf(STDOUT, "dump_size: %llu\n", vol_size.dump_size);
5732 EndTrans(struct cmd_syndesc *as, void *arock)
5735 afs_int32 code, tid, rcode;
5736 struct rx_connection *aconn;
5738 server = GetServer(as->parms[0].items->data);
5740 fprintf(STDERR, "vos: host '%s' not found in host table\n",
5741 as->parms[0].items->data);
5745 code = util_GetInt32(as->parms[1].items->data, &tid);
5747 fprintf(STDERR, "vos: bad integer specified for transaction ID.\n");
5751 aconn = UV_Bind(server, AFSCONF_VOLUMEPORT);
5752 code = AFSVolEndTrans(aconn, tid, &rcode);
5758 PrintDiagnostics("endtrans", code);
5766 PrintDiagnostics(char *astring, afs_int32 acode)
5768 if (acode == EACCES) {
5770 "You are not authorized to perform the 'vos %s' command (%d)\n",
5773 fprintf(STDERR, "Error in vos %s command.\n", astring);
5774 PrintError("", acode);
5782 win32_enableCrypt(void)
5789 /* Look up configuration parameters in Registry */
5790 code = RegOpenKeyEx(HKEY_LOCAL_MACHINE, AFSREG_CLT_SVC_PARAM_SUBKEY,
5791 0, (IsWow64()?KEY_WOW64_64KEY:0)|KEY_QUERY_VALUE, &parmKey);
5792 if (code != ERROR_SUCCESS) {
5793 dummyLen = sizeof(cryptall);
5794 RegQueryValueEx(parmKey, "SecurityLevel", NULL, NULL,
5795 (BYTE *) &cryptall, &dummyLen);
5797 RegCloseKey (parmKey);
5801 #endif /* AFS_NT40_ENV */
5804 MyBeforeProc(struct cmd_syndesc *as, void *arock)
5810 /* Initialize the ubik_client connection */
5811 rx_SetRxDeadTime(90);
5812 cstruct = (struct ubik_client *)0;
5816 if (as->parms[12].items) /* if -cell specified */
5817 tcell = as->parms[12].items->data;
5818 if (as->parms[14].items) /* -serverauth specified */
5820 if (as->parms[16].items /* -encrypt specified */
5822 || win32_enableCrypt()
5823 #endif /* AFS_NT40_ENV */
5827 if (as->parms[18].items) /* -config flag set */
5828 confdir = as->parms[18].items->data;
5831 vsu_ClientInit((as->parms[13].items != 0), confdir, tcell, sauth,
5832 &cstruct, UV_SetSecurity))) {
5833 fprintf(STDERR, "could not initialize VLDB library (code=%lu) \n",
5834 (unsigned long)code);
5838 if (as->parms[15].items) /* -verbose flag set */
5842 if (as->parms[17].items) /* -noresolve flag set */
5853 /* this sucks but it works for now.
5858 #include "AFS_component_version_number.c"
5861 main(int argc, char **argv)
5865 struct cmd_syndesc *ts;
5867 #ifdef AFS_AIX32_ENV
5869 * The following signal action for AIX is necessary so that in case of a
5870 * crash (i.e. core is generated) we can include the user's data section
5871 * in the core dump. Unfortunately, by default, only a partial core is
5872 * generated which, in many cases, isn't too useful.
5874 struct sigaction nsa;
5876 sigemptyset(&nsa.sa_mask);
5877 nsa.sa_handler = SIG_DFL;
5878 nsa.sa_flags = SA_FULLDUMP;
5879 sigaction(SIGSEGV, &nsa, NULL);
5882 confdir = AFSDIR_CLIENT_ETC_DIRPATH;
5884 cmd_SetBeforeProc(MyBeforeProc, NULL);
5886 ts = cmd_CreateSyntax("create", CreateVolume, NULL, "create a new volume");
5887 cmd_AddParm(ts, "-server", CMD_SINGLE, 0, "machine name");
5888 cmd_AddParm(ts, "-partition", CMD_SINGLE, 0, "partition name");
5889 cmd_AddParm(ts, "-name", CMD_SINGLE, 0, "volume name");
5890 cmd_AddParm(ts, "-maxquota", CMD_SINGLE, CMD_OPTIONAL,
5891 "initial quota (KB)");
5892 cmd_AddParm(ts, "-id", CMD_SINGLE, CMD_OPTIONAL, "volume ID");
5893 cmd_AddParm(ts, "-roid", CMD_SINGLE, CMD_OPTIONAL, "readonly volume ID");
5895 cmd_AddParm(ts, "-minquota", CMD_SINGLE, CMD_OPTIONAL, "");
5899 ts = cmd_CreateSyntax("remove", DeleteVolume, NULL, "delete a volume");
5900 cmd_AddParm(ts, "-server", CMD_SINGLE, CMD_OPTIONAL, "machine name");
5901 cmd_AddParm(ts, "-partition", CMD_SINGLE, CMD_OPTIONAL, "partition name");
5902 cmd_AddParm(ts, "-id", CMD_SINGLE, 0, "volume name or ID");
5906 ts = cmd_CreateSyntax("move", MoveVolume, NULL, "move a volume");
5907 cmd_AddParm(ts, "-id", CMD_SINGLE, 0, "volume name or ID");
5908 cmd_AddParm(ts, "-fromserver", CMD_SINGLE, 0, "machine name on source");
5909 cmd_AddParm(ts, "-frompartition", CMD_SINGLE, 0,
5910 "partition name on source");
5911 cmd_AddParm(ts, "-toserver", CMD_SINGLE, 0,
5912 "machine name on destination");
5913 cmd_AddParm(ts, "-topartition", CMD_SINGLE, 0,
5914 "partition name on destination");
5915 cmd_AddParm(ts, "-live", CMD_FLAG, CMD_OPTIONAL,
5916 "copy live volume without cloning");
5919 ts = cmd_CreateSyntax("copy", CopyVolume, NULL, "copy a volume");
5920 cmd_AddParm(ts, "-id", CMD_SINGLE, 0, "volume name or ID on source");
5921 cmd_AddParm(ts, "-fromserver", CMD_SINGLE, 0, "machine name on source");
5922 cmd_AddParm(ts, "-frompartition", CMD_SINGLE, 0,
5923 "partition name on source");
5924 cmd_AddParm(ts, "-toname", CMD_SINGLE, 0, "volume name on destination");
5925 cmd_AddParm(ts, "-toserver", CMD_SINGLE, 0,
5926 "machine name on destination");
5927 cmd_AddParm(ts, "-topartition", CMD_SINGLE, 0,
5928 "partition name on destination");
5929 cmd_AddParm(ts, "-offline", CMD_FLAG, CMD_OPTIONAL,
5930 "leave new volume offline");
5931 cmd_AddParm(ts, "-readonly", CMD_FLAG, CMD_OPTIONAL,
5932 "make new volume read-only");
5933 cmd_AddParm(ts, "-live", CMD_FLAG, CMD_OPTIONAL,
5934 "copy live volume without cloning");
5937 ts = cmd_CreateSyntax("shadow", ShadowVolume, NULL,
5938 "make or update a shadow volume");
5939 cmd_AddParm(ts, "-id", CMD_SINGLE, 0, "volume name or ID on source");
5940 cmd_AddParm(ts, "-fromserver", CMD_SINGLE, 0, "machine name on source");
5941 cmd_AddParm(ts, "-frompartition", CMD_SINGLE, 0,
5942 "partition name on source");
5943 cmd_AddParm(ts, "-toserver", CMD_SINGLE, 0,
5944 "machine name on destination");
5945 cmd_AddParm(ts, "-topartition", CMD_SINGLE, 0,
5946 "partition name on destination");
5947 cmd_AddParm(ts, "-toname", CMD_SINGLE, CMD_OPTIONAL,
5948 "volume name on destination");
5949 cmd_AddParm(ts, "-toid", CMD_SINGLE, CMD_OPTIONAL,
5950 "volume ID on destination");
5951 cmd_AddParm(ts, "-offline", CMD_FLAG, CMD_OPTIONAL,
5952 "leave shadow volume offline");
5953 cmd_AddParm(ts, "-readonly", CMD_FLAG, CMD_OPTIONAL,
5954 "make shadow volume read-only");
5955 cmd_AddParm(ts, "-live", CMD_FLAG, CMD_OPTIONAL,
5956 "copy live volume without cloning");
5957 cmd_AddParm(ts, "-incremental", CMD_FLAG, CMD_OPTIONAL,
5958 "do incremental update if target exists");
5961 ts = cmd_CreateSyntax("backup", BackupVolume, NULL,
5962 "make backup of a volume");
5963 cmd_AddParm(ts, "-id", CMD_SINGLE, 0, "volume name or ID");
5966 ts = cmd_CreateSyntax("clone", CloneVolume, NULL,
5967 "make clone of a volume");
5968 cmd_AddParm(ts, "-id", CMD_SINGLE, 0, "volume name or ID");
5969 cmd_AddParm(ts, "-server", CMD_SINGLE, CMD_OPTIONAL, "server");
5970 cmd_AddParm(ts, "-partition", CMD_SINGLE, CMD_OPTIONAL, "partition");
5971 cmd_AddParm(ts, "-toname", CMD_SINGLE, CMD_OPTIONAL,
5972 "volume name on destination");
5973 cmd_AddParm(ts, "-toid", CMD_SINGLE, CMD_OPTIONAL,
5974 "volume ID on destination");
5975 cmd_AddParm(ts, "-offline", CMD_FLAG, CMD_OPTIONAL,
5976 "leave clone volume offline");
5977 cmd_AddParm(ts, "-readonly", CMD_FLAG, CMD_OPTIONAL,
5978 "make clone volume read-only, not readwrite");
5981 ts = cmd_CreateSyntax("release", ReleaseVolume, NULL, "release a volume");
5982 cmd_AddParm(ts, "-id", CMD_SINGLE, 0, "volume name or ID");
5983 cmd_AddParm(ts, "-force", CMD_FLAG, CMD_OPTIONAL,
5984 "force a complete release");
5987 ts = cmd_CreateSyntax("dump", DumpVolumeCmd, NULL, "dump a volume");
5988 cmd_AddParm(ts, "-id", CMD_SINGLE, 0, "volume name or ID");
5989 cmd_AddParm(ts, "-time", CMD_SINGLE, CMD_OPTIONAL, "dump from time");
5990 cmd_AddParm(ts, "-file", CMD_SINGLE, CMD_OPTIONAL, "dump file");
5991 cmd_AddParm(ts, "-server", CMD_SINGLE, CMD_OPTIONAL, "server");
5992 cmd_AddParm(ts, "-partition", CMD_SINGLE, CMD_OPTIONAL, "partition");
5993 cmd_AddParm(ts, "-clone", CMD_FLAG, CMD_OPTIONAL,
5994 "dump a clone of the volume");
5995 cmd_AddParm(ts, "-omitdirs", CMD_FLAG, CMD_OPTIONAL,
5996 "omit unchanged directories from an incremental dump");
5999 ts = cmd_CreateSyntax("restore", RestoreVolumeCmd, NULL,
6000 "restore a volume");
6001 cmd_AddParm(ts, "-server", CMD_SINGLE, 0, "machine name");
6002 cmd_AddParm(ts, "-partition", CMD_SINGLE, 0, "partition name");
6003 cmd_AddParm(ts, "-name", CMD_SINGLE, 0, "name of volume to be restored");
6004 cmd_AddParm(ts, "-file", CMD_SINGLE, CMD_OPTIONAL, "dump file");
6005 cmd_AddParm(ts, "-id", CMD_SINGLE, CMD_OPTIONAL, "volume ID");
6006 cmd_AddParm(ts, "-overwrite", CMD_SINGLE, CMD_OPTIONAL,
6007 "abort | full | incremental");
6008 cmd_AddParm(ts, "-offline", CMD_FLAG, CMD_OPTIONAL,
6009 "leave restored volume offline");
6010 cmd_AddParm(ts, "-readonly", CMD_FLAG, CMD_OPTIONAL,
6011 "make restored volume read-only");
6012 cmd_AddParm(ts, "-creation", CMD_SINGLE, CMD_OPTIONAL,
6013 "dump | keep | new");
6014 cmd_AddParm(ts, "-lastupdate", CMD_SINGLE, CMD_OPTIONAL,
6015 "dump | keep | new");
6016 cmd_AddParm(ts, "-nodelete", CMD_FLAG, CMD_OPTIONAL,
6017 "do not delete old site when restoring to a new site");
6020 ts = cmd_CreateSyntax("unlock", LockReleaseCmd, NULL,
6021 "release lock on VLDB entry for a volume");
6022 cmd_AddParm(ts, "-id", CMD_SINGLE, 0, "volume name or ID");
6025 ts = cmd_CreateSyntax("changeloc", ChangeLocation, NULL,
6026 "change an RW volume's location in the VLDB");
6027 cmd_AddParm(ts, "-server", CMD_SINGLE, 0,
6028 "machine name for new location");
6029 cmd_AddParm(ts, "-partition", CMD_SINGLE, 0,
6030 "partition name for new location");
6031 cmd_AddParm(ts, "-id", CMD_SINGLE, 0, "volume name or ID");
6034 ts = cmd_CreateSyntax("addsite", AddSite, NULL, "add a replication site");
6035 cmd_AddParm(ts, "-server", CMD_SINGLE, 0, "machine name for new site");
6036 cmd_AddParm(ts, "-partition", CMD_SINGLE, 0,
6037 "partition name for new site");
6038 cmd_AddParm(ts, "-id", CMD_SINGLE, 0, "volume name or ID");
6039 cmd_AddParm(ts, "-roid", CMD_SINGLE, CMD_OPTIONAL, "volume name or ID for RO");
6040 cmd_AddParm(ts, "-valid", CMD_FLAG, CMD_OPTIONAL, "publish as an up-to-date site in VLDB");
6043 ts = cmd_CreateSyntax("remsite", RemoveSite, NULL,
6044 "remove a replication site");
6045 cmd_AddParm(ts, "-server", CMD_SINGLE, 0, "machine name");
6046 cmd_AddParm(ts, "-partition", CMD_SINGLE, 0, "partition name");
6047 cmd_AddParm(ts, "-id", CMD_SINGLE, 0, "volume name or ID");
6050 ts = cmd_CreateSyntax("listpart", ListPartitions, NULL, "list partitions");
6051 cmd_AddParm(ts, "-server", CMD_SINGLE, 0, "machine name");
6054 ts = cmd_CreateSyntax("listvol", ListVolumes, NULL,
6055 "list volumes on server (bypass VLDB)");
6056 cmd_AddParm(ts, "-server", CMD_SINGLE, 0, "machine name");
6057 cmd_AddParm(ts, "-partition", CMD_SINGLE, CMD_OPTIONAL, "partition name");
6058 cmd_AddParm(ts, "-fast", CMD_FLAG, CMD_OPTIONAL, "minimal listing");
6059 cmd_AddParm(ts, "-long", CMD_FLAG, CMD_OPTIONAL,
6060 "list all normal volume fields");
6061 cmd_AddParm(ts, "-quiet", CMD_FLAG, CMD_OPTIONAL,
6062 "generate minimal information");
6063 cmd_AddParm(ts, "-extended", CMD_FLAG, CMD_OPTIONAL,
6064 "list extended volume fields");
6065 cmd_AddParm(ts, "-format", CMD_FLAG, CMD_OPTIONAL,
6066 "machine readable format");
6069 ts = cmd_CreateSyntax("syncvldb", SyncVldb, NULL,
6070 "synchronize VLDB with server");
6071 cmd_AddParm(ts, "-server", CMD_SINGLE, CMD_OPTIONAL, "machine name");
6072 cmd_AddParm(ts, "-partition", CMD_SINGLE, CMD_OPTIONAL, "partition name");
6073 cmd_AddParm(ts, "-volume", CMD_SINGLE, CMD_OPTIONAL, "volume name or ID");
6074 cmd_AddParm(ts, "-dryrun", CMD_FLAG, CMD_OPTIONAL, "list what would be done, don't do it");
6077 ts = cmd_CreateSyntax("syncserv", SyncServer, NULL,
6078 "synchronize server with VLDB");
6079 cmd_AddParm(ts, "-server", CMD_SINGLE, 0, "machine name");
6080 cmd_AddParm(ts, "-partition", CMD_SINGLE, CMD_OPTIONAL, "partition name");
6081 cmd_AddParm(ts, "-dryrun", CMD_FLAG, CMD_OPTIONAL, "list what would be done, don't do it");
6084 ts = cmd_CreateSyntax("examine", ExamineVolume, NULL,
6085 "everything about the volume");
6086 cmd_AddParm(ts, "-id", CMD_SINGLE, 0, "volume name or ID");
6087 cmd_AddParm(ts, "-extended", CMD_FLAG, CMD_OPTIONAL,
6088 "list extended volume fields");
6089 cmd_AddParm(ts, "-format", CMD_FLAG, CMD_OPTIONAL,
6090 "machine readable format");
6092 cmd_CreateAlias(ts, "volinfo");
6094 ts = cmd_CreateSyntax("setfields", SetFields, NULL,
6095 "change volume info fields");
6096 cmd_AddParm(ts, "-id", CMD_SINGLE, 0, "volume name or ID");
6097 cmd_AddParm(ts, "-maxquota", CMD_SINGLE, CMD_OPTIONAL, "quota (KB)");
6098 cmd_AddParm(ts, "-clearuse", CMD_FLAG, CMD_OPTIONAL, "clear dayUse");
6099 cmd_AddParm(ts, "-clearVolUpCounter", CMD_FLAG, CMD_OPTIONAL, "clear volUpdateCounter");
6102 ts = cmd_CreateSyntax("offline", volOffline, NULL, "force the volume status to offline");
6103 cmd_AddParm(ts, "-server", CMD_SINGLE, 0, "server name");
6104 cmd_AddParm(ts, "-partition", CMD_SINGLE, 0, "partition name");
6105 cmd_AddParm(ts, "-id", CMD_SINGLE, 0, "volume name or ID");
6106 cmd_AddParm(ts, "-sleep", CMD_SINGLE, CMD_OPTIONAL, "seconds to sleep");
6107 cmd_AddParm(ts, "-busy", CMD_FLAG, CMD_OPTIONAL, "busy volume");
6110 ts = cmd_CreateSyntax("online", volOnline, NULL, "force the volume status to online");
6111 cmd_AddParm(ts, "-server", CMD_SINGLE, 0, "server name");
6112 cmd_AddParm(ts, "-partition", CMD_SINGLE, 0, "partition name");
6113 cmd_AddParm(ts, "-id", CMD_SINGLE, 0, "volume name or ID");
6116 ts = cmd_CreateSyntax("zap", VolumeZap, NULL,
6117 "delete the volume, don't bother with VLDB");
6118 cmd_AddParm(ts, "-server", CMD_SINGLE, 0, "machine name");
6119 cmd_AddParm(ts, "-partition", CMD_SINGLE, 0, "partition name");
6120 cmd_AddParm(ts, "-id", CMD_SINGLE, 0, "volume ID");
6121 cmd_AddParm(ts, "-force", CMD_FLAG, CMD_OPTIONAL,
6122 "force deletion of bad volumes");
6123 cmd_AddParm(ts, "-backup", CMD_FLAG, CMD_OPTIONAL,
6124 "also delete backup volume if one is found");
6127 ts = cmd_CreateSyntax("status", VolserStatus, NULL,
6128 "report on volser status");
6129 cmd_AddParm(ts, "-server", CMD_SINGLE, 0, "machine name");
6132 ts = cmd_CreateSyntax("rename", RenameVolume, NULL, "rename a volume");
6133 cmd_AddParm(ts, "-oldname", CMD_SINGLE, 0, "old volume name ");
6134 cmd_AddParm(ts, "-newname", CMD_SINGLE, 0, "new volume name ");
6137 ts = cmd_CreateSyntax("listvldb", ListVLDB, NULL,
6138 "list volumes in the VLDB");
6139 cmd_AddParm(ts, "-name", CMD_SINGLE, CMD_OPTIONAL, "volume name or ID");
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, "-locked", CMD_FLAG, CMD_OPTIONAL, "locked volumes only");
6143 cmd_AddParm(ts, "-quiet", CMD_FLAG, CMD_OPTIONAL,
6144 "generate minimal information");
6145 cmd_AddParm(ts, "-nosort", CMD_FLAG, CMD_OPTIONAL,
6146 "do not alphabetically sort the volume names");
6149 ts = cmd_CreateSyntax("backupsys", BackSys, NULL, "en masse backups");
6150 cmd_AddParm(ts, "-prefix", CMD_LIST, CMD_OPTIONAL,
6151 "common prefix on volume(s)");
6152 cmd_AddParm(ts, "-server", CMD_SINGLE, CMD_OPTIONAL, "machine name");
6153 cmd_AddParm(ts, "-partition", CMD_SINGLE, CMD_OPTIONAL, "partition name");
6154 cmd_AddParm(ts, "-exclude", CMD_FLAG, CMD_OPTIONAL,
6155 "exclude common prefix volumes");
6156 cmd_AddParm(ts, "-xprefix", CMD_LIST, CMD_OPTIONAL,
6157 "negative prefix on volume(s)");
6158 cmd_AddParm(ts, "-dryrun", CMD_FLAG, CMD_OPTIONAL, "list what would be done, don't do it");
6161 ts = cmd_CreateSyntax("delentry", DeleteEntry, NULL,
6162 "delete VLDB entry for a volume");
6163 cmd_AddParm(ts, "-id", CMD_LIST, CMD_OPTIONAL, "volume name or ID");
6164 cmd_AddParm(ts, "-prefix", CMD_SINGLE, CMD_OPTIONAL,
6165 "prefix of the volume whose VLDB entry is to be deleted");
6166 cmd_AddParm(ts, "-server", CMD_SINGLE, CMD_OPTIONAL, "machine name");
6167 cmd_AddParm(ts, "-partition", CMD_SINGLE, CMD_OPTIONAL, "partition name");
6168 cmd_AddParm(ts, "-noexecute", CMD_FLAG, CMD_OPTIONAL|CMD_HIDDEN, "");
6169 cmd_AddParm(ts, "-dryrun", CMD_FLAG, CMD_OPTIONAL,
6170 "list what would be done, don't do it");
6173 ts = cmd_CreateSyntax("partinfo", PartitionInfo, NULL,
6174 "list partition information");
6175 cmd_AddParm(ts, "-server", CMD_SINGLE, 0, "machine name");
6176 cmd_AddParm(ts, "-partition", CMD_SINGLE, CMD_OPTIONAL, "partition name");
6177 cmd_AddParm(ts, "-summary", CMD_FLAG, CMD_OPTIONAL,
6178 "print storage summary");
6181 ts = cmd_CreateSyntax("unlockvldb", UnlockVLDB, NULL,
6182 "unlock all the locked entries in the VLDB");
6183 cmd_AddParm(ts, "-server", CMD_SINGLE, CMD_OPTIONAL, "machine name");
6184 cmd_AddParm(ts, "-partition", CMD_SINGLE, CMD_OPTIONAL, "partition name");
6187 ts = cmd_CreateSyntax("lock", LockEntry, NULL,
6188 "lock VLDB entry for a volume");
6189 cmd_AddParm(ts, "-id", CMD_SINGLE, 0, "volume name or ID");
6192 ts = cmd_CreateSyntax("changeaddr", ChangeAddr, NULL,
6193 "change the IP address of a file server");
6194 cmd_AddParm(ts, "-oldaddr", CMD_SINGLE, 0, "original IP address");
6195 cmd_AddParm(ts, "-newaddr", CMD_SINGLE, CMD_OPTIONAL, "new IP address");
6196 cmd_AddParm(ts, "-remove", CMD_FLAG, CMD_OPTIONAL,
6197 "remove the IP address from the VLDB");
6200 ts = cmd_CreateSyntax("listaddrs", ListAddrs, NULL,
6201 "list the IP address of all file servers registered in the VLDB");
6202 cmd_AddParm(ts, "-uuid", CMD_SINGLE, CMD_OPTIONAL, "uuid of server");
6203 cmd_AddParm(ts, "-host", CMD_SINGLE, CMD_OPTIONAL, "address of host");
6204 cmd_AddParm(ts, "-printuuid", CMD_FLAG, CMD_OPTIONAL,
6205 "print uuid of hosts");
6208 ts = cmd_CreateSyntax("convertROtoRW", ConvertRO, NULL,
6209 "convert a RO volume into a RW volume (after loss of old RW volume)");
6210 cmd_AddParm(ts, "-server", CMD_SINGLE, 0, "machine name");
6211 cmd_AddParm(ts, "-partition", CMD_SINGLE, 0, "partition name");
6212 cmd_AddParm(ts, "-id", CMD_SINGLE, 0, "volume name or ID");
6213 cmd_AddParm(ts, "-force", CMD_FLAG, CMD_OPTIONAL, "don't ask");
6216 ts = cmd_CreateSyntax("size", Sizes, NULL,
6217 "obtain various sizes of the volume.");
6218 cmd_AddParm(ts, "-id", CMD_SINGLE, 0, "volume name or ID");
6219 cmd_AddParm(ts, "-partition", CMD_SINGLE, CMD_OPTIONAL, "partition name");
6220 cmd_AddParm(ts, "-server", CMD_SINGLE, CMD_OPTIONAL, "machine name");
6221 cmd_AddParm(ts, "-dump", CMD_FLAG, CMD_OPTIONAL,
6222 "Obtain the size of the dump");
6223 cmd_AddParm(ts, "-time", CMD_SINGLE, CMD_OPTIONAL, "dump from time");
6226 ts = cmd_CreateSyntax("endtrans", EndTrans, NULL,
6227 "end a volserver transaction");
6228 cmd_AddParm(ts, "-server", CMD_SINGLE, 0, "machine name");
6229 cmd_AddParm(ts, "-transaction", CMD_SINGLE, 0,
6233 ts = cmd_CreateSyntax("setaddrs", SetAddrs, NULL,
6234 "set the list of IP address for a given UUID in the VLDB");
6235 cmd_AddParm(ts, "-uuid", CMD_SINGLE, 0, "uuid of server");
6236 cmd_AddParm(ts, "-host", CMD_LIST, 0, "address of host");
6239 code = cmd_Dispatch(argc, argv);
6241 /* Shut down the ubik_client and rx connections */
6243 (void)ubik_ClientDestroy(cstruct);
6249 exit((code ? -1 : 0));