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>
29 #include <rx/rx_queue.h>
32 #include <rx/rx_globals.h>
34 #include <afs/vlserver.h>
35 #include <afs/cellconfig.h>
37 #include <afs/afsutil.h>
39 #include <afs/afsint.h>
44 #include <afs/ihandle.h>
45 #include <afs/vnode.h>
46 #include <afs/volume.h>
47 #include <afs/com_err.h>
51 #include "volser_internal.h"
52 #include "volser_prototypes.h"
53 #include "vsutils_prototypes.h"
54 #include "lockprocs_prototypes.h"
56 #ifdef HAVE_POSIX_REGEX
60 /* Local Prototypes */
61 int PrintDiagnostics(char *astring, afs_int32 acode);
62 int GetVolumeInfo(afs_uint32 volid, afs_uint32 *server, afs_int32 *part,
63 afs_int32 *voltype, struct nvldbentry *rentry);
76 COMMONPARM_OFFSET_CELL = 25,
77 COMMONPARM_OFFSET_NOAUTH = 26,
78 COMMONPARM_OFFSET_LOCALAUTH = 27,
79 COMMONPARM_OFFSET_VERBOSE = 28,
80 COMMONPARM_OFFSET_ENCRYPT = 29,
81 COMMONPARM_OFFSET_NORESOLVE = 30,
82 COMMONPARM_OFFSET_CONFIG = 31,
83 COMMONPARM_OFFSET_RXGK = 32,
87 cmd_AddParmAtOffset(ts, COMMONPARM_OFFSET_CELL, \
88 "-cell", CMD_SINGLE, CMD_OPTIONAL, "cell name");\
89 cmd_AddParmAlias(ts, COMMONPARM_OFFSET_CELL, "-c"); /* original -cell option */ \
90 cmd_AddParmAtOffset(ts, COMMONPARM_OFFSET_NOAUTH, \
91 "-noauth", CMD_FLAG, CMD_OPTIONAL, "don't authenticate");\
92 cmd_AddParmAtOffset(ts, COMMONPARM_OFFSET_LOCALAUTH, \
93 "-localauth",CMD_FLAG,CMD_OPTIONAL,"use server tickets");\
94 cmd_AddParmAtOffset(ts, COMMONPARM_OFFSET_VERBOSE, \
95 "-verbose", CMD_FLAG, CMD_OPTIONAL, "verbose");\
96 cmd_AddParmAtOffset(ts, COMMONPARM_OFFSET_ENCRYPT, \
97 "-encrypt", CMD_FLAG, CMD_OPTIONAL, "encrypt commands");\
98 cmd_AddParmAtOffset(ts, COMMONPARM_OFFSET_NORESOLVE, \
99 "-noresolve", CMD_FLAG, CMD_OPTIONAL, "don't resolve addresses"); \
100 cmd_AddParmAtOffset(ts, COMMONPARM_OFFSET_CONFIG, \
101 "-config", CMD_SINGLE, CMD_OPTIONAL, "config location"); \
102 cmd_AddParmAtOffset(ts, COMMONPARM_OFFSET_RXGK, \
103 "-rxgk", CMD_SINGLE, CMD_OPTIONAL, "rxgk security level to use"); \
105 #define ERROR_EXIT(code) do { \
111 extern struct ubik_client *cstruct;
114 static struct tqHead busyHead, notokHead;
117 qInit(struct tqHead *ahead)
119 memset(ahead, 0, sizeof(struct tqHead));
125 qPut(struct tqHead *ahead, afs_uint32 volid)
129 elem = malloc(sizeof(struct tqElem));
130 elem->next = ahead->next;
138 qGet(struct tqHead *ahead, afs_uint32 *volid)
142 if (ahead->count <= 0)
144 *volid = ahead->next->volid;
146 ahead->next = tmp->next;
152 /* returns 1 if <filename> exists else 0 */
154 FileExists(char *filename)
160 code = usd_Open(filename, USD_OPEN_RDONLY, 0, &ufd);
164 code = USD_IOCTL(ufd, USD_IOCTL_GETSIZE, &size);
172 /* returns 1 if <name> doesnot end in .readonly or .backup, else 0 */
174 VolNameOK(char *name)
179 total = strlen(name);
180 if (!strcmp(&name[total - 9], ".readonly")) {
182 } else if (!strcmp(&name[total - 7], ".backup")) {
189 /* return 1 if name is a number else 0 */
191 IsNumeric(char *name)
200 for (i = 0; i < len; i++) {
201 if (*ptr < '0' || *ptr > '9') {
213 * Parse a server dotted address and return the address in network byte order
216 GetServerNoresolve(char *aname)
222 code = sscanf(aname, "%d.%d.%d.%d", &b1, &b2, &b3, &b4);
224 addr = (b1 << 24) | (b2 << 16) | (b3 << 8) | b4;
225 addr = htonl(addr); /* convert to network byte order */
231 * Parse a server name/address and return a non-loopback address in network byte order
234 GetServer(char *aname)
237 afs_uint32 addr; /* in network byte order */
239 char hostname[MAXHOSTCHARS];
240 afs_uint32 **addr_list;
243 addr = GetServerNoresolve(aname);
245 if (!rx_IsLoopbackAddr(ntohl(addr)))
251 th = gethostbyname(aname);
252 if (th != NULL && th->h_addrtype == AF_INET) {
253 addr_list = (afs_uint32 **)th->h_addr_list;
254 for(i = 0; addr_list[i] != NULL; i++) {
255 if (!rx_IsLoopbackAddr(ntohl(*addr_list[i]))) {
256 memcpy(&addr, addr_list[i], sizeof(addr));
262 * If we reach this point all of the addresses returned by
263 * gethostbyname() are loopback addresses. We assume that means
264 * that the name is supposed to describe the machine this code
265 * is executing on. Try gethostname() to and check to see if
266 * that name can provide us a non-loopback address.
268 code = gethostname(hostname, MAXHOSTCHARS);
270 th = gethostbyname(hostname);
271 if (th != NULL && th->h_addrtype == AF_INET) {
272 addr_list = (afs_uint32 **)th->h_addr_list;
273 for (i=0; addr_list[i] != NULL; i++) {
274 if (!rx_IsLoopbackAddr(ntohl(*addr_list[i]))) {
275 memcpy(&addr, addr_list[i], sizeof(addr));
284 * No non-loopback address could be obtained for 'aname'.
290 GetVolumeType(char *aname)
293 if (!strcmp(aname, "ro"))
295 else if (!strcmp(aname, "rw"))
297 else if (!strcmp(aname, "bk"))
304 IsPartValid(afs_int32 partId, afs_uint32 server, afs_int32 *code)
306 struct partList dummyPartList;
312 *code = UV_ListPartitions(server, &dummyPartList, &cnt);
315 for (i = 0; i < cnt; i++) {
316 if (dummyPartList.partFlags[i] & PARTVALID)
317 if (dummyPartList.partId[i] == partId)
325 /*sends the contents of file associated with <fd> and <blksize> to Rx Stream
326 * associated with <call> */
328 SendFile(usd_handle_t ufd, struct rx_call *call, long blksize)
330 char *buffer = (char *)0;
334 buffer = malloc(blksize);
336 fprintf(STDERR, "malloc failed\n");
341 #if !defined(AFS_NT40_ENV) && !defined(AFS_PTHREAD_ENV)
342 /* Only for this for non-NT, non-pthread. For NT, we can't select on
343 * non-socket FDs. For pthread environments, we don't need to select at
344 * all, since the following read() will block. */
347 FD_SET((intptr_t)(ufd->handle), &in);
348 /* don't timeout if read blocks */
349 IOMGR_Select(((intptr_t)(ufd->handle)) + 1, &in, 0, 0, 0);
351 error = USD_READ(ufd, buffer, blksize, &nbytes);
353 fprintf(STDERR, "File system read failed: %s\n",
354 afs_error_message(error));
361 if (rx_Write(call, buffer, nbytes) != nbytes) {
371 /* function invoked by UV_RestoreVolume, reads the data from rx_trx_stream and
372 * writes it out to the volume. */
374 WriteData(struct rx_call *call, void *rock)
376 char *filename = (char *) rock;
379 afs_int32 error, code;
381 afs_int64 currOffset;
387 if (!filename || !*filename) {
388 usd_StandardInput(&ufd);
392 code = usd_Open(filename, USD_OPEN_RDONLY, 0, &ufd);
395 code = USD_IOCTL(ufd, USD_IOCTL_GETBLKSIZE, &blksize);
398 fprintf(STDERR, "Could not access file '%s': %s\n", filename,
399 afs_error_message(code));
403 /* test if we have a valid dump */
404 USD_SEEK(ufd, 0, SEEK_END, &currOffset);
405 USD_SEEK(ufd, currOffset - sizeof(afs_uint32), SEEK_SET, &currOffset);
406 USD_READ(ufd, (char *)&buffer, sizeof(afs_uint32), &got);
407 if ((got != sizeof(afs_uint32)) || (ntohl(buffer) != DUMPENDMAGIC)) {
408 fprintf(STDERR, "Signature missing from end of file '%s'\n", filename);
412 USD_SEEK(ufd, 0, SEEK_SET, &currOffset);
414 code = SendFile(ufd, call, blksize);
421 code = USD_CLOSE(ufd);
423 fprintf(STDERR, "Could not close dump file %s\n",
424 (filename && *filename) ? filename : "STDOUT");
432 /* Receive data from <call> stream into file associated
433 * with <fd> <blksize>
436 ReceiveFile(usd_handle_t ufd, struct rx_call *call, long blksize)
440 afs_uint32 bytesleft, w;
443 buffer = malloc(blksize);
445 fprintf(STDERR, "memory allocation failed\n");
449 while ((bytesread = rx_Read(call, buffer, blksize)) > 0) {
450 for (bytesleft = bytesread; bytesleft; bytesleft -= w) {
451 #if !defined(AFS_NT40_ENV) && !defined(AFS_PTHREAD_ENV)
452 /* Only for this for non-NT, non-pthread. For NT, we can't select
453 * on non-socket FDs. For pthread environments, we don't need to
454 * select at all, since the following write() will block. */
457 FD_SET((intptr_t)(ufd->handle), &out);
458 /* don't timeout if write blocks */
459 IOMGR_Select(((intptr_t)(ufd->handle)) + 1, 0, &out, 0, 0);
462 USD_WRITE(ufd, &buffer[bytesread - bytesleft], bytesleft, &w);
464 fprintf(STDERR, "File system write failed: %s\n",
465 afs_error_message(error));
478 DumpFunction(struct rx_call *call, void *rock)
480 char *filename = (char *)rock;
481 usd_handle_t ufd; /* default is to stdout */
482 afs_int32 error = 0, code;
487 /* Open the output file */
488 if (!filename || !*filename) {
489 usd_StandardOutput(&ufd);
494 usd_Open(filename, USD_OPEN_CREATE | USD_OPEN_RDWR, 0666, &ufd);
498 code = USD_IOCTL(ufd, USD_IOCTL_SETSIZE, &size);
501 code = USD_IOCTL(ufd, USD_IOCTL_GETBLKSIZE, &blksize);
504 fprintf(STDERR, "Could not create file '%s': %s\n", filename,
505 afs_error_message(code));
506 ERROR_EXIT(VOLSERBADOP);
510 code = ReceiveFile(ufd, call, blksize);
515 /* Close the output file */
517 code = USD_CLOSE(ufd);
519 fprintf(STDERR, "Could not close dump file %s\n",
520 (filename && *filename) ? filename : "STDIN");
530 DisplayFormat(volintInfo *pntr, afs_uint32 server, afs_int32 part,
531 int *totalOK, int *totalNotOK, int *totalBusy, int fast,
532 int longlist, int disp)
538 fprintf(STDOUT, "%-10lu\n", (unsigned long)pntr->volid);
539 } else if (longlist) {
540 if (pntr->status == VOK) {
541 fprintf(STDOUT, "%-32s ", pntr->name);
542 fprintf(STDOUT, "%10lu ", (unsigned long)pntr->volid);
544 fprintf(STDOUT, "RW ");
546 fprintf(STDOUT, "RO ");
548 fprintf(STDOUT, "BK ");
549 fprintf(STDOUT, "%10d K ", pntr->size);
550 if (pntr->inUse == 1) {
551 fprintf(STDOUT, "On-line");
554 fprintf(STDOUT, "Off-line");
557 if (pntr->needsSalvaged == 1)
558 fprintf(STDOUT, "**needs salvage**");
559 fprintf(STDOUT, "\n");
560 MapPartIdIntoName(part, pname);
561 fprintf(STDOUT, " %s %s \n", hostutil_GetNameByINet(server),
563 fprintf(STDOUT, " RWrite %10lu ROnly %10lu Backup %10lu \n",
564 (unsigned long)pntr->parentID,
565 (unsigned long)pntr->cloneID,
566 (unsigned long)pntr->backupID);
567 fprintf(STDOUT, " MaxQuota %10d K \n", pntr->maxquota);
568 t = pntr->creationDate;
569 fprintf(STDOUT, " Creation %s",
572 fprintf(STDOUT, " Copy %s",
575 t = pntr->backupDate;
577 fprintf(STDOUT, " Backup Never\n");
579 fprintf(STDOUT, " Backup %s",
582 t = pntr->accessDate;
584 fprintf(STDOUT, " Last Access %s",
587 t = pntr->updateDate;
589 fprintf(STDOUT, " Last Update Never\n");
591 fprintf(STDOUT, " Last Update %s",
594 " %d accesses in the past day (i.e., vnode references)\n",
596 } else if (pntr->status == VBUSY) {
598 qPut(&busyHead, pntr->volid);
600 fprintf(STDOUT, "**** Volume %lu is busy ****\n",
601 (unsigned long)pntr->volid);
604 qPut(¬okHead, pntr->volid);
606 fprintf(STDOUT, "**** Could not attach volume %lu ****\n",
607 (unsigned long)pntr->volid);
609 fprintf(STDOUT, "\n");
610 } else { /* default listing */
611 if (pntr->status == VOK) {
612 fprintf(STDOUT, "%-32s ", pntr->name);
613 fprintf(STDOUT, "%10lu ", (unsigned long)pntr->volid);
615 fprintf(STDOUT, "RW ");
617 fprintf(STDOUT, "RO ");
619 fprintf(STDOUT, "BK ");
620 fprintf(STDOUT, "%10d K ", pntr->size);
621 if (pntr->inUse == 1) {
622 fprintf(STDOUT, "On-line");
625 fprintf(STDOUT, "Off-line");
628 if (pntr->needsSalvaged == 1)
629 fprintf(STDOUT, "**needs salvage**");
630 fprintf(STDOUT, "\n");
631 } else if (pntr->status == VBUSY) {
633 qPut(&busyHead, pntr->volid);
635 fprintf(STDOUT, "**** Volume %lu is busy ****\n",
636 (unsigned long)pntr->volid);
639 qPut(¬okHead, pntr->volid);
641 fprintf(STDOUT, "**** Could not attach volume %lu ****\n",
642 (unsigned long)pntr->volid);
647 /*------------------------------------------------------------------------
648 * PRIVATE XDisplayFormat
651 * Display the contents of one extended volume info structure.
654 * a_xInfoP : Ptr to extended volume info struct to print.
655 * a_servID : Server ID to print.
656 * a_partID : Partition ID to print.
657 * a_totalOKP : Ptr to total-OK counter.
658 * a_totalNotOKP : Ptr to total-screwed counter.
659 * a_totalBusyP : Ptr to total-busy counter.
660 * a_fast : Fast listing?
661 * a_int32 : Int32 listing?
662 * a_showProblems : Show volume problems?
668 * Nothing interesting.
672 *------------------------------------------------------------------------*/
675 XDisplayFormat(volintXInfo *a_xInfoP, afs_uint32 a_servID, afs_int32 a_partID,
676 int *a_totalOKP, int *a_totalNotOKP, int *a_totalBusyP,
677 int a_fast, int a_int32, int a_showProblems)
678 { /*XDisplayFormat */
686 fprintf(STDOUT, "%-10lu\n", (unsigned long)a_xInfoP->volid);
687 } else if (a_int32) {
689 * Fully-detailed listing.
691 if (a_xInfoP->status == VOK) {
693 * Volume's status is OK - all the fields are valid.
695 fprintf(STDOUT, "%-32s ", a_xInfoP->name);
696 fprintf(STDOUT, "%10lu ", (unsigned long)a_xInfoP->volid);
697 if (a_xInfoP->type == 0)
698 fprintf(STDOUT, "RW ");
699 if (a_xInfoP->type == 1)
700 fprintf(STDOUT, "RO ");
701 if (a_xInfoP->type == 2)
702 fprintf(STDOUT, "BK ");
703 fprintf(STDOUT, "%10d K used ", a_xInfoP->size);
704 fprintf(STDOUT, "%d files ", a_xInfoP->filecount);
705 if (a_xInfoP->inUse == 1) {
706 fprintf(STDOUT, "On-line");
709 fprintf(STDOUT, "Off-line");
712 fprintf(STDOUT, "\n");
713 MapPartIdIntoName(a_partID, pname);
714 fprintf(STDOUT, " %s %s \n", hostutil_GetNameByINet(a_servID),
716 fprintf(STDOUT, " RWrite %10lu ROnly %10lu Backup %10lu \n",
717 (unsigned long)a_xInfoP->parentID,
718 (unsigned long)a_xInfoP->cloneID,
719 (unsigned long)a_xInfoP->backupID);
720 fprintf(STDOUT, " MaxQuota %10d K \n", a_xInfoP->maxquota);
722 t = a_xInfoP->creationDate;
723 fprintf(STDOUT, " Creation %s",
726 t = a_xInfoP->copyDate;
727 fprintf(STDOUT, " Copy %s",
730 t = a_xInfoP->backupDate;
732 fprintf(STDOUT, " Backup Never\n");
734 fprintf(STDOUT, " Backup %s",
737 t = a_xInfoP->accessDate;
739 fprintf(STDOUT, " Last Access %s",
742 t = a_xInfoP->updateDate;
744 fprintf(STDOUT, " Last Update Never\n");
746 fprintf(STDOUT, " Last Update %s",
749 " %d accesses in the past day (i.e., vnode references)\n",
753 * Print all the read/write and authorship stats.
755 fprintf(STDOUT, "\n Raw Read/Write Stats\n");
757 " |-------------------------------------------|\n");
759 " | Same Network | Diff Network |\n");
761 " |----------|----------|----------|----------|\n");
763 " | Total | Auth | Total | Auth |\n");
765 " |----------|----------|----------|----------|\n");
766 fprintf(STDOUT, "Reads | %8d | %8d | %8d | %8d |\n",
767 a_xInfoP->stat_reads[VOLINT_STATS_SAME_NET],
768 a_xInfoP->stat_reads[VOLINT_STATS_SAME_NET_AUTH],
769 a_xInfoP->stat_reads[VOLINT_STATS_DIFF_NET],
770 a_xInfoP->stat_reads[VOLINT_STATS_DIFF_NET_AUTH]);
771 fprintf(STDOUT, "Writes | %8d | %8d | %8d | %8d |\n",
772 a_xInfoP->stat_writes[VOLINT_STATS_SAME_NET],
773 a_xInfoP->stat_writes[VOLINT_STATS_SAME_NET_AUTH],
774 a_xInfoP->stat_writes[VOLINT_STATS_DIFF_NET],
775 a_xInfoP->stat_writes[VOLINT_STATS_DIFF_NET_AUTH]);
777 " |-------------------------------------------|\n\n");
780 " Writes Affecting Authorship\n");
782 " |-------------------------------------------|\n");
784 " | File Authorship | Directory Authorship|\n");
786 " |----------|----------|----------|----------|\n");
788 " | Same | Diff | Same | Diff |\n");
790 " |----------|----------|----------|----------|\n");
791 fprintf(STDOUT, "0-60 sec | %8d | %8d | %8d | %8d |\n",
792 a_xInfoP->stat_fileSameAuthor[VOLINT_STATS_TIME_IDX_0],
793 a_xInfoP->stat_fileDiffAuthor[VOLINT_STATS_TIME_IDX_0],
794 a_xInfoP->stat_dirSameAuthor[VOLINT_STATS_TIME_IDX_0],
795 a_xInfoP->stat_dirDiffAuthor[VOLINT_STATS_TIME_IDX_0]);
796 fprintf(STDOUT, "1-10 min | %8d | %8d | %8d | %8d |\n",
797 a_xInfoP->stat_fileSameAuthor[VOLINT_STATS_TIME_IDX_1],
798 a_xInfoP->stat_fileDiffAuthor[VOLINT_STATS_TIME_IDX_1],
799 a_xInfoP->stat_dirSameAuthor[VOLINT_STATS_TIME_IDX_1],
800 a_xInfoP->stat_dirDiffAuthor[VOLINT_STATS_TIME_IDX_1]);
801 fprintf(STDOUT, "10min-1hr | %8d | %8d | %8d | %8d |\n",
802 a_xInfoP->stat_fileSameAuthor[VOLINT_STATS_TIME_IDX_2],
803 a_xInfoP->stat_fileDiffAuthor[VOLINT_STATS_TIME_IDX_2],
804 a_xInfoP->stat_dirSameAuthor[VOLINT_STATS_TIME_IDX_2],
805 a_xInfoP->stat_dirDiffAuthor[VOLINT_STATS_TIME_IDX_2]);
806 fprintf(STDOUT, "1hr-1day | %8d | %8d | %8d | %8d |\n",
807 a_xInfoP->stat_fileSameAuthor[VOLINT_STATS_TIME_IDX_3],
808 a_xInfoP->stat_fileDiffAuthor[VOLINT_STATS_TIME_IDX_3],
809 a_xInfoP->stat_dirSameAuthor[VOLINT_STATS_TIME_IDX_3],
810 a_xInfoP->stat_dirDiffAuthor[VOLINT_STATS_TIME_IDX_3]);
811 fprintf(STDOUT, "1day-1wk | %8d | %8d | %8d | %8d |\n",
812 a_xInfoP->stat_fileSameAuthor[VOLINT_STATS_TIME_IDX_4],
813 a_xInfoP->stat_fileDiffAuthor[VOLINT_STATS_TIME_IDX_4],
814 a_xInfoP->stat_dirSameAuthor[VOLINT_STATS_TIME_IDX_4],
815 a_xInfoP->stat_dirDiffAuthor[VOLINT_STATS_TIME_IDX_4]);
816 fprintf(STDOUT, "> 1wk | %8d | %8d | %8d | %8d |\n",
817 a_xInfoP->stat_fileSameAuthor[VOLINT_STATS_TIME_IDX_5],
818 a_xInfoP->stat_fileDiffAuthor[VOLINT_STATS_TIME_IDX_5],
819 a_xInfoP->stat_dirSameAuthor[VOLINT_STATS_TIME_IDX_5],
820 a_xInfoP->stat_dirDiffAuthor[VOLINT_STATS_TIME_IDX_5]);
822 " |-------------------------------------------|\n");
823 } /*Volume status OK */
824 else if (a_xInfoP->status == VBUSY) {
826 qPut(&busyHead, a_xInfoP->volid);
828 fprintf(STDOUT, "**** Volume %lu is busy ****\n",
829 (unsigned long)a_xInfoP->volid);
833 qPut(¬okHead, a_xInfoP->volid);
835 fprintf(STDOUT, "**** Could not attach volume %lu ****\n",
836 (unsigned long)a_xInfoP->volid);
837 } /*Screwed volume */
838 fprintf(STDOUT, "\n");
844 if (a_xInfoP->status == VOK) {
845 fprintf(STDOUT, "%-32s ", a_xInfoP->name);
846 fprintf(STDOUT, "%10lu ", (unsigned long)a_xInfoP->volid);
847 if (a_xInfoP->type == 0)
848 fprintf(STDOUT, "RW ");
849 if (a_xInfoP->type == 1)
850 fprintf(STDOUT, "RO ");
851 if (a_xInfoP->type == 2)
852 fprintf(STDOUT, "BK ");
853 fprintf(STDOUT, "%10d K ", a_xInfoP->size);
854 if (a_xInfoP->inUse == 1) {
855 fprintf(STDOUT, "On-line");
858 fprintf(STDOUT, "Off-line");
861 fprintf(STDOUT, "\n");
863 else if (a_xInfoP->status == VBUSY) {
865 qPut(&busyHead, a_xInfoP->volid);
867 fprintf(STDOUT, "**** Volume %lu is busy ****\n",
868 (unsigned long)a_xInfoP->volid);
872 qPut(¬okHead, a_xInfoP->volid);
874 fprintf(STDOUT, "**** Could not attach volume %lu ****\n",
875 (unsigned long)a_xInfoP->volid);
876 } /*Screwed volume */
877 } /*Default listing */
878 } /*XDisplayFormat */
880 /*------------------------------------------------------------------------
881 * PRIVATE XDisplayFormat2
884 * Display the formated contents of one extended volume info structure.
887 * a_xInfoP : Ptr to extended volume info struct to print.
888 * a_servID : Server ID to print.
889 * a_partID : Partition ID to print.
890 * a_totalOKP : Ptr to total-OK counter.
891 * a_totalNotOKP : Ptr to total-screwed counter.
892 * a_totalBusyP : Ptr to total-busy counter.
893 * a_fast : Fast listing?
894 * a_int32 : Int32 listing?
895 * a_showProblems : Show volume problems?
901 * Nothing interesting.
905 *------------------------------------------------------------------------*/
908 XDisplayFormat2(volintXInfo *a_xInfoP, afs_uint32 a_servID, afs_int32 a_partID,
909 int *a_totalOKP, int *a_totalNotOKP, int *a_totalBusyP,
910 int a_fast, int a_int32, int a_showProblems)
911 { /*XDisplayFormat */
917 fprintf(STDOUT, "vold_id\t%-10lu\n", (unsigned long)a_xInfoP->volid);
918 } else if (a_int32) {
920 * Fully-detailed listing.
922 if (a_xInfoP->status == VOK) {
924 * Volume's status is OK - all the fields are valid.
927 static long server_cache = -1, partition_cache = -1;
928 static char hostname[256], address[32], pname[16];
929 int i,ai[] = {VOLINT_STATS_TIME_IDX_0,VOLINT_STATS_TIME_IDX_1,VOLINT_STATS_TIME_IDX_2,
930 VOLINT_STATS_TIME_IDX_3,VOLINT_STATS_TIME_IDX_4,VOLINT_STATS_TIME_IDX_5};
932 if (a_servID != server_cache) {
936 strcpy(hostname, hostutil_GetNameByINet(a_servID));
937 strcpy(address, inet_ntoa(s));
938 server_cache = a_servID;
940 if (a_partID != partition_cache) {
941 MapPartIdIntoName(a_partID, pname);
942 partition_cache = a_partID;
945 fprintf(STDOUT, "name\t\t%s\n", a_xInfoP->name);
946 fprintf(STDOUT, "id\t\t%lu\n", afs_printable_uint32_lu(a_xInfoP->volid));
947 fprintf(STDOUT, "serv\t\t%s\t%s\n", address, hostname);
948 fprintf(STDOUT, "part\t\t%s\n", pname);
949 fprintf(STDOUT, "status\t\tOK\n");
950 fprintf(STDOUT, "backupID\t%lu\n",
951 afs_printable_uint32_lu(a_xInfoP->backupID));
952 fprintf(STDOUT, "parentID\t%lu\n",
953 afs_printable_uint32_lu(a_xInfoP->parentID));
954 fprintf(STDOUT, "cloneID\t\t%lu\n",
955 afs_printable_uint32_lu(a_xInfoP->cloneID));
956 fprintf(STDOUT, "inUse\t\t%s\n", a_xInfoP->inUse ? "Y" : "N");
957 switch (a_xInfoP->type) {
959 fprintf(STDOUT, "type\t\tRW\n");
962 fprintf(STDOUT, "type\t\tRO\n");
965 fprintf(STDOUT, "type\t\tBK\n");
968 fprintf(STDOUT, "type\t\t?\n");
971 t = a_xInfoP->creationDate;
972 fprintf(STDOUT, "creationDate\t%-9lu\t%s",
973 afs_printable_uint32_lu(a_xInfoP->creationDate),
976 t = a_xInfoP->accessDate;
977 fprintf(STDOUT, "accessDate\t%-9lu\t%s",
978 afs_printable_uint32_lu(a_xInfoP->accessDate),
981 t = a_xInfoP->updateDate;
982 fprintf(STDOUT, "updateDate\t%-9lu\t%s",
983 afs_printable_uint32_lu(a_xInfoP->updateDate),
986 t = a_xInfoP->backupDate;
987 fprintf(STDOUT, "backupDate\t%-9lu\t%s",
988 afs_printable_uint32_lu(a_xInfoP->backupDate),
991 t = a_xInfoP->copyDate;
992 fprintf(STDOUT, "copyDate\t%-9lu\t%s",
993 afs_printable_uint32_lu(a_xInfoP->copyDate),
996 fprintf(STDOUT, "diskused\t%u\n", a_xInfoP->size);
997 fprintf(STDOUT, "maxquota\t%u\n", a_xInfoP->maxquota);
999 fprintf(STDOUT, "filecount\t%u\n", a_xInfoP->filecount);
1000 fprintf(STDOUT, "dayUse\t\t%u\n", a_xInfoP->dayUse);
1004 fprintf(STDOUT,"reads_same_net\t%8d\n",a_xInfoP->stat_reads[VOLINT_STATS_SAME_NET]);
1005 fprintf(STDOUT,"reads_same_net_auth\t%8d\n",a_xInfoP->stat_reads[VOLINT_STATS_SAME_NET_AUTH]);
1006 fprintf(STDOUT,"reads_diff_net\t%8d\n",a_xInfoP->stat_reads[VOLINT_STATS_DIFF_NET]);
1007 fprintf(STDOUT,"reads_diff_net_auth\t%8d\n",a_xInfoP->stat_reads[VOLINT_STATS_DIFF_NET_AUTH]);
1009 fprintf(STDOUT,"writes_same_net\t%8d\n",a_xInfoP->stat_writes[VOLINT_STATS_SAME_NET]);
1010 fprintf(STDOUT,"writes_same_net_auth\t%8d\n",a_xInfoP->stat_writes[VOLINT_STATS_SAME_NET_AUTH]);
1011 fprintf(STDOUT,"writes_diff_net\t%8d\n",a_xInfoP->stat_writes[VOLINT_STATS_DIFF_NET]);
1012 fprintf(STDOUT,"writes_diff_net_auth\t%8d\n",a_xInfoP->stat_writes[VOLINT_STATS_DIFF_NET_AUTH]);
1016 fprintf(STDOUT,"file_same_author_idx_%d\t%8d\n",i+1,a_xInfoP->stat_fileSameAuthor[ai[i]]);
1017 fprintf(STDOUT,"file_diff_author_idx_%d\t%8d\n",i+1,a_xInfoP->stat_fileDiffAuthor[ai[i]]);
1018 fprintf(STDOUT,"dir_same_author_idx_%d\t%8d\n",i+1,a_xInfoP->stat_dirSameAuthor[ai[i]]);
1019 fprintf(STDOUT,"dir_dif_author_idx_%d\t%8d\n",i+1,a_xInfoP->stat_dirDiffAuthor[ai[i]]);
1022 } /*Volume status OK */
1023 else if (a_xInfoP->status == VBUSY) {
1025 qPut(&busyHead, a_xInfoP->volid);
1027 fprintf(STDOUT, "BUSY_VOL\t%lu\n",
1028 (unsigned long)a_xInfoP->volid);
1032 qPut(¬okHead, a_xInfoP->volid);
1034 fprintf(STDOUT, "COULD_NOT_ATTACH\t%lu\n",
1035 (unsigned long)a_xInfoP->volid);
1036 } /*Screwed volume */
1042 if (a_xInfoP->status == VOK) {
1043 fprintf(STDOUT, "name\t%-32s\n", a_xInfoP->name);
1044 fprintf(STDOUT, "volID\t%10lu\n", (unsigned long)a_xInfoP->volid);
1045 if (a_xInfoP->type == 0)
1046 fprintf(STDOUT, "type\tRW\n");
1047 if (a_xInfoP->type == 1)
1048 fprintf(STDOUT, "type\tRO\n");
1049 if (a_xInfoP->type == 2)
1050 fprintf(STDOUT, "type\tBK\n");
1051 fprintf(STDOUT, "size\t%10dK\n", a_xInfoP->size);
1053 fprintf(STDOUT, "inUse\t%d\n",a_xInfoP->inUse);
1054 if (a_xInfoP->inUse == 1)
1060 else if (a_xInfoP->status == VBUSY) {
1062 qPut(&busyHead, a_xInfoP->volid);
1064 fprintf(STDOUT, "VOLUME_BUSY\t%lu\n",
1065 (unsigned long)a_xInfoP->volid);
1069 qPut(¬okHead, a_xInfoP->volid);
1071 fprintf(STDOUT, "COULD_NOT_ATTACH_VOLUME\t%lu\n",
1072 (unsigned long)a_xInfoP->volid);
1073 } /*Screwed volume */
1074 } /*Default listing */
1075 } /*XDisplayFormat */
1078 DisplayFormat2(long server, long partition, volintInfo *pntr)
1080 static long server_cache = -1, partition_cache = -1;
1081 static char hostname[256], address[32], pname[16];
1084 if (server != server_cache) {
1088 strcpy(hostname, hostutil_GetNameByINet(server));
1089 strcpy(address, inet_ntoa(s));
1090 server_cache = server;
1092 if (partition != partition_cache) {
1093 MapPartIdIntoName(partition, pname);
1094 partition_cache = partition;
1097 if (pntr->status == VOK)
1098 fprintf(STDOUT, "name\t\t%s\n", pntr->name);
1100 fprintf(STDOUT, "id\t\t%lu\n",
1101 afs_printable_uint32_lu(pntr->volid));
1102 fprintf(STDOUT, "serv\t\t%s\t%s\n", address, hostname);
1103 fprintf(STDOUT, "part\t\t%s\n", pname);
1104 switch (pntr->status) {
1106 fprintf(STDOUT, "status\t\tOK\n");
1109 fprintf(STDOUT, "status\t\tBUSY\n");
1112 fprintf(STDOUT, "status\t\tUNATTACHABLE\n");
1115 fprintf(STDOUT, "backupID\t%lu\n",
1116 afs_printable_uint32_lu(pntr->backupID));
1117 fprintf(STDOUT, "parentID\t%lu\n",
1118 afs_printable_uint32_lu(pntr->parentID));
1119 fprintf(STDOUT, "cloneID\t\t%lu\n",
1120 afs_printable_uint32_lu(pntr->cloneID));
1121 fprintf(STDOUT, "inUse\t\t%s\n", pntr->inUse ? "Y" : "N");
1122 fprintf(STDOUT, "needsSalvaged\t%s\n", pntr->needsSalvaged ? "Y" : "N");
1123 /* 0xD3 is from afs/volume.h since I had trouble including the file */
1124 fprintf(STDOUT, "destroyMe\t%s\n", pntr->destroyMe == 0xD3 ? "Y" : "N");
1125 switch (pntr->type) {
1127 fprintf(STDOUT, "type\t\tRW\n");
1130 fprintf(STDOUT, "type\t\tRO\n");
1133 fprintf(STDOUT, "type\t\tBK\n");
1136 fprintf(STDOUT, "type\t\t?\n");
1139 t = pntr->creationDate;
1140 fprintf(STDOUT, "creationDate\t%-9lu\t%s",
1141 afs_printable_uint32_lu(pntr->creationDate),
1144 t = pntr->accessDate;
1145 fprintf(STDOUT, "accessDate\t%-9lu\t%s",
1146 afs_printable_uint32_lu(pntr->accessDate),
1149 t = pntr->updateDate;
1150 fprintf(STDOUT, "updateDate\t%-9lu\t%s",
1151 afs_printable_uint32_lu(pntr->updateDate),
1154 t = pntr->backupDate;
1155 fprintf(STDOUT, "backupDate\t%-9lu\t%s",
1156 afs_printable_uint32_lu(pntr->backupDate),
1160 fprintf(STDOUT, "copyDate\t%-9lu\t%s",
1161 afs_printable_uint32_lu(pntr->copyDate),
1164 fprintf(STDOUT, "flags\t\t%#lx\t(Optional)\n",
1165 afs_printable_uint32_lu(pntr->flags));
1166 fprintf(STDOUT, "diskused\t%u\n", pntr->size);
1167 fprintf(STDOUT, "maxquota\t%u\n", pntr->maxquota);
1168 fprintf(STDOUT, "minquota\t%lu\t(Optional)\n",
1169 afs_printable_uint32_lu(pntr->spare0));
1170 fprintf(STDOUT, "filecount\t%u\n", pntr->filecount);
1171 fprintf(STDOUT, "dayUse\t\t%u\n", pntr->dayUse);
1172 fprintf(STDOUT, "weekUse\t\t%lu\t(Optional)\n",
1173 afs_printable_uint32_lu(pntr->spare1));
1174 fprintf(STDOUT, "spare2\t\t%lu\t(Optional)\n",
1175 afs_printable_uint32_lu(pntr->spare2));
1176 fprintf(STDOUT, "spare3\t\t%lu\t(Optional)\n",
1177 afs_printable_uint32_lu(pntr->spare3));
1182 DisplayVolumes2(long server, long partition, volintInfo *pntr, long count)
1186 for (i = 0; i < count; i++) {
1187 fprintf(STDOUT, "BEGIN_OF_ENTRY\n");
1188 DisplayFormat2(server, partition, pntr);
1189 fprintf(STDOUT, "END_OF_ENTRY\n\n");
1196 DisplayVolumes(afs_uint32 server, afs_int32 part, volintInfo *pntr,
1197 afs_int32 count, afs_int32 longlist, afs_int32 fast,
1200 int totalOK, totalNotOK, totalBusy, i;
1201 afs_uint32 volid = 0;
1208 for (i = 0; i < count; i++) {
1209 DisplayFormat(pntr, server, part, &totalOK, &totalNotOK, &totalBusy,
1214 while (busyHead.count) {
1215 qGet(&busyHead, &volid);
1216 fprintf(STDOUT, "**** Volume %lu is busy ****\n",
1217 (unsigned long)volid);
1221 while (notokHead.count) {
1222 qGet(¬okHead, &volid);
1223 fprintf(STDOUT, "**** Could not attach volume %lu ****\n",
1224 (unsigned long)volid);
1228 fprintf(STDOUT, "\n");
1231 "Total volumes onLine %d ; Total volumes offLine %d ; Total busy %d\n\n",
1232 totalOK, totalNotOK, totalBusy);
1236 /*------------------------------------------------------------------------
1237 * PRIVATE XDisplayVolumes
1240 * Display extended volume information.
1243 * a_servID : Pointer to the Rx call we're performing.
1244 * a_partID : Partition for which we want the extended list.
1245 * a_xInfoP : Ptr to extended volume info.
1246 * a_count : Number of volume records contained above.
1247 * a_int32 : Int32 listing generated?
1248 * a_fast : Fast listing generated?
1249 * a_quiet : Quiet listing generated?
1255 * Nothing interesting.
1259 *------------------------------------------------------------------------*/
1262 XDisplayVolumes(afs_uint32 a_servID, afs_int32 a_partID, volintXInfo *a_xInfoP,
1263 afs_int32 a_count, afs_int32 a_int32, afs_int32 a_fast,
1265 { /*XDisplayVolumes */
1267 int totalOK; /*Total OK volumes */
1268 int totalNotOK; /*Total screwed volumes */
1269 int totalBusy; /*Total busy volumes */
1270 int i; /*Loop variable */
1271 afs_uint32 volid = 0; /*Current volume ID */
1274 * Initialize counters and (global!!) queues.
1283 * Display each volume in the list.
1285 for (i = 0; i < a_count; i++) {
1286 XDisplayFormat(a_xInfoP, a_servID, a_partID, &totalOK, &totalNotOK,
1287 &totalBusy, a_fast, a_int32, 0);
1292 * If any volumes were found to be busy or screwed, display them.
1295 while (busyHead.count) {
1296 qGet(&busyHead, &volid);
1297 fprintf(STDOUT, "**** Volume %lu is busy ****\n",
1298 (unsigned long)volid);
1302 while (notokHead.count) {
1303 qGet(¬okHead, &volid);
1304 fprintf(STDOUT, "**** Could not attach volume %lu ****\n",
1305 (unsigned long)volid);
1310 fprintf(STDOUT, "\n");
1313 "Total volumes: %d on-line, %d off-line, %d busyd\n\n",
1314 totalOK, totalNotOK, totalBusy);
1318 } /*XDisplayVolumes */
1320 /*------------------------------------------------------------------------
1321 * PRIVATE XDisplayVolumes2
1324 * Display extended formated volume information.
1327 * a_servID : Pointer to the Rx call we're performing.
1328 * a_partID : Partition for which we want the extended list.
1329 * a_xInfoP : Ptr to extended volume info.
1330 * a_count : Number of volume records contained above.
1331 * a_int32 : Int32 listing generated?
1332 * a_fast : Fast listing generated?
1333 * a_quiet : Quiet listing generated?
1339 * Nothing interesting.
1343 *------------------------------------------------------------------------*/
1346 XDisplayVolumes2(afs_uint32 a_servID, afs_int32 a_partID, volintXInfo *a_xInfoP,
1347 afs_int32 a_count, afs_int32 a_int32, afs_int32 a_fast,
1349 { /*XDisplayVolumes */
1351 int totalOK; /*Total OK volumes */
1352 int totalNotOK; /*Total screwed volumes */
1353 int totalBusy; /*Total busy volumes */
1354 int i; /*Loop variable */
1355 afs_uint32 volid = 0; /*Current volume ID */
1358 * Initialize counters and (global!!) queues.
1367 * Display each volume in the list.
1369 for (i = 0; i < a_count; i++) {
1370 fprintf(STDOUT, "BEGIN_OF_ENTRY\n");
1371 XDisplayFormat2(a_xInfoP, a_servID, a_partID, &totalOK, &totalNotOK,
1372 &totalBusy, a_fast, a_int32, 0);
1373 fprintf(STDOUT, "END_OF_ENTRY\n");
1378 * If any volumes were found to be busy or screwed, display them.
1381 while (busyHead.count) {
1382 qGet(&busyHead, &volid);
1383 fprintf(STDOUT, "BUSY_VOL\t%lu\n",
1384 (unsigned long)volid);
1388 while (notokHead.count) {
1389 qGet(¬okHead, &volid);
1390 fprintf(STDOUT, "COULD_NOT_ATTACH\t%lu\n",
1391 (unsigned long)volid);
1396 fprintf(STDOUT, "\n");
1399 "VOLUMES_ONLINE\t%d\nVOLUMES_OFFLINE\t%d\nVOLUMES_BUSY\t%d\n",
1400 totalOK, totalNotOK, totalBusy);
1404 } /*XDisplayVolumes2 */
1407 /* set <server> and <part> to the correct values depending on
1408 * <voltype> and <entry> */
1410 GetServerAndPart(struct nvldbentry *entry, int voltype, afs_uint32 *server,
1411 afs_int32 *part, int *previdx)
1413 int i, istart, vtype;
1418 /* Doesn't check for non-existance of backup volume */
1419 if ((voltype == RWVOL) || (voltype == BACKVOL)) {
1421 istart = 0; /* seach the entire entry */
1424 /* Seach from beginning of entry or pick up where we left off */
1425 istart = ((*previdx < 0) ? 0 : *previdx + 1);
1428 for (i = istart; i < entry->nServers; i++) {
1429 if (entry->serverFlags[i] & vtype) {
1430 *server = entry->serverNumber[i];
1431 *part = entry->serverPartition[i];
1437 /* Didn't find any, return -1 */
1443 PrintLocked(afs_int32 aflags)
1445 afs_int32 flags = aflags & VLOP_ALLOPERS;
1448 fprintf(STDOUT, " Volume is currently LOCKED \n");
1450 if (flags & VLOP_MOVE) {
1451 fprintf(STDOUT, " Volume is locked for a move operation\n");
1453 if (flags & VLOP_RELEASE) {
1454 fprintf(STDOUT, " Volume is locked for a release operation\n");
1456 if (flags & VLOP_BACKUP) {
1457 fprintf(STDOUT, " Volume is locked for a backup operation\n");
1459 if (flags & VLOP_DELETE) {
1460 fprintf(STDOUT, " Volume is locked for a delete/misc operation\n");
1462 if (flags & VLOP_DUMP) {
1463 fprintf(STDOUT, " Volume is locked for a dump/restore operation\n");
1469 PostVolumeStats(struct nvldbentry *entry)
1471 SubEnumerateEntry(entry);
1472 /* Check for VLOP_ALLOPERS */
1473 PrintLocked(entry->flags);
1477 /*------------------------------------------------------------------------
1478 * PRIVATE XVolumeStats
1481 * Display extended volume information.
1484 * a_xInfoP : Ptr to extended volume info.
1485 * a_entryP : Ptr to the volume's VLDB entry.
1486 * a_srvID : Server ID.
1487 * a_partID : Partition ID.
1488 * a_volType : Type of volume to print.
1494 * Nothing interesting.
1498 *------------------------------------------------------------------------*/
1501 XVolumeStats(volintXInfo *a_xInfoP, struct nvldbentry *a_entryP,
1502 afs_int32 a_srvID, afs_int32 a_partID, int a_volType)
1505 int totalOK, totalNotOK, totalBusy; /*Dummies - we don't really count here */
1507 XDisplayFormat(a_xInfoP, /*Ptr to extended volume info */
1508 a_srvID, /*Server ID to print */
1509 a_partID, /*Partition ID to print */
1510 &totalOK, /*Ptr to total-OK counter */
1511 &totalNotOK, /*Ptr to total-screwed counter */
1512 &totalBusy, /*Ptr to total-busy counter */
1513 0, /*Don't do a fast listing */
1514 1, /*Do a long listing */
1515 1); /*Show volume problems */
1521 VolumeStats_int(volintInfo *pntr, struct nvldbentry *entry, afs_uint32 server,
1522 afs_int32 part, int voltype)
1528 DisplayFormat(pntr, server, part, &totalOK, &totalNotOK, &totalBusy, 0, 1,
1533 /* command to forcibly remove a volume */
1535 NukeVolume(struct cmd_syndesc *as)
1544 server = GetServer(tp = as->parms[0].items->data);
1546 fprintf(STDERR, "vos: server '%s' not found in host table\n", tp);
1550 partID = volutil_GetPartitionID(tp = as->parms[1].items->data);
1552 fprintf(STDERR, "vos: could not parse '%s' as a partition name", tp);
1556 volID = vsu_GetVolumeID(tp = as->parms[2].items->data, cstruct, &err);
1559 PrintError("", err);
1562 "vos: could not parse '%s' as a numeric volume ID", tp);
1567 "vos: forcibly removing all traces of volume %d, please wait...",
1570 code = UV_NukeVolume(server, partID, volID);
1572 fprintf(STDOUT, "done.\n");
1574 fprintf(STDOUT, "failed with code %d.\n", code);
1579 /*------------------------------------------------------------------------
1580 * PRIVATE ExamineVolume
1583 * Routine used to examine a single volume, contacting the VLDB as
1584 * well as the Volume Server.
1587 * as : Ptr to parsed command line arguments.
1590 * 0 for a successful operation,
1591 * Otherwise, one of the ubik or VolServer error values.
1594 * Nothing interesting.
1598 *------------------------------------------------------------------------
1601 ExamineVolume(struct cmd_syndesc *as, void *arock)
1603 struct nvldbentry entry;
1604 afs_int32 vcode = 0;
1605 volintInfo *pntr = (volintInfo *) 0;
1606 volintXInfo *xInfoP = (volintXInfo *) 0;
1608 afs_int32 code, err, error = 0;
1609 int voltype, foundserv = 0, foundentry = 0;
1613 int wantExtendedInfo; /*Do we want extended vol info? */
1614 int isSubEnum=0; /* Keep track whether sub enumerate called. */
1615 wantExtendedInfo = (as->parms[1].items ? 1 : 0); /* -extended */
1617 volid = vsu_GetVolumeID(as->parms[0].items->data, cstruct, &err); /* -id */
1620 PrintError("", err);
1622 fprintf(STDERR, "Unknown volume ID or name '%s'\n",
1623 as->parms[0].items->data);
1628 fprintf(STDOUT, "Fetching VLDB entry for %lu .. ",
1629 (unsigned long)volid);
1632 vcode = VLDB_GetEntryByID(volid, -1, &entry);
1635 "Could not fetch the entry for volume number %lu from VLDB \n",
1636 (unsigned long)volid);
1640 fprintf(STDOUT, "done\n");
1641 MapHostToNetwork(&entry);
1643 if (entry.volumeId[RWVOL] == volid)
1645 else if (entry.volumeId[BACKVOL] == volid)
1647 else /* (entry.volumeId[ROVOL] == volid) */
1650 do { /* do {...} while (voltype == ROVOL) */
1651 /* Get the entry for the volume. If its a RW vol, get the RW entry.
1652 * It its a BK vol, get the RW entry (even if VLDB may say the BK doen't exist).
1653 * If its a RO vol, get the next RO entry.
1655 GetServerAndPart(&entry, ((voltype == ROVOL) ? ROVOL : RWVOL),
1656 &aserver, &apart, &previdx);
1657 if (previdx == -1) { /* searched all entries */
1659 fprintf(STDERR, "Volume %s does not exist in VLDB\n\n",
1660 as->parms[0].items->data);
1667 /* Get information about the volume from the server */
1669 fprintf(STDOUT, "Getting volume listing from the server %s .. ",
1670 hostutil_GetNameByINet(aserver));
1673 if (wantExtendedInfo)
1674 code = UV_XListOneVolume(aserver, apart, volid, &xInfoP);
1676 code = UV_ListOneVolume(aserver, apart, volid, &pntr);
1678 fprintf(STDOUT, "done\n");
1682 if (code == ENODEV) {
1683 if ((voltype == BACKVOL) && !(entry.flags & VLF_BACKEXISTS)) {
1684 /* The VLDB says there is no backup volume and its not on disk */
1685 fprintf(STDERR, "Volume %s does not exist\n",
1686 as->parms[0].items->data);
1690 "Volume does not exist on server %s as indicated by the VLDB\n",
1691 hostutil_GetNameByINet(aserver));
1694 PrintDiagnostics("examine", code);
1696 fprintf(STDOUT, "\n");
1699 if (wantExtendedInfo)
1700 XVolumeStats(xInfoP, &entry, aserver, apart, voltype);
1701 else if (as->parms[2].items) {
1702 DisplayFormat2(aserver, apart, pntr);
1703 EnumerateEntry(&entry);
1706 VolumeStats_int(pntr, &entry, aserver, apart, voltype);
1708 if ((voltype == BACKVOL) && !(entry.flags & VLF_BACKEXISTS)) {
1709 /* The VLDB says there is no backup volume yet we found one on disk */
1710 fprintf(STDERR, "Volume %s does not exist in VLDB\n",
1711 as->parms[0].items->data);
1720 } while (voltype == ROVOL);
1723 fprintf(STDERR, "Dump only information from VLDB\n\n");
1724 fprintf(STDOUT, "%s \n", entry.name); /* PostVolumeStats doesn't print name */
1728 PostVolumeStats(&entry);
1733 /*------------------------------------------------------------------------
1737 * Routine used to change the status of a single volume.
1740 * as : Ptr to parsed command line arguments.
1743 * 0 for a successful operation,
1744 * Otherwise, one of the ubik or VolServer error values.
1747 * Nothing interesting.
1751 *------------------------------------------------------------------------
1754 SetFields(struct cmd_syndesc *as, void *arock)
1756 struct nvldbentry entry;
1759 afs_int32 code, err;
1765 volid = vsu_GetVolumeID(as->parms[0].items->data, cstruct, &err); /* -id */
1768 PrintError("", err);
1770 fprintf(STDERR, "Unknown volume ID or name '%s'\n",
1771 as->parms[0].items->data);
1775 code = VLDB_GetEntryByID(volid, RWVOL, &entry);
1778 "Could not fetch the entry for volume number %lu from VLDB \n",
1779 (unsigned long)volid);
1782 MapHostToNetwork(&entry);
1784 GetServerAndPart(&entry, RWVOL, &aserver, &apart, &previdx);
1785 if (previdx == -1) {
1786 fprintf(STDERR, "Volume %s does not exist in VLDB\n\n",
1787 as->parms[0].items->data);
1791 init_volintInfo(&info);
1795 if (as->parms[1].items) {
1798 code = util_GetHumanInt32(as->parms[1].items->data, &info.maxquota);
1800 fprintf(STDERR, "invalid quota value\n");
1804 if (as->parms[2].items) {
1809 if (as->parms[3].items) {
1810 /* -clearVolUpCounter */
1815 fprintf(STDERR,"Nothing to set.\n");
1818 code = UV_SetVolumeInfo(aserver, apart, volid, &info);
1821 "Could not update volume info fields for volume number %lu\n",
1822 (unsigned long)volid);
1826 /*------------------------------------------------------------------------
1830 * Brings a volume online.
1833 * as : Ptr to parsed command line arguments.
1836 * 0 for a successful operation,
1839 * Nothing interesting.
1843 *------------------------------------------------------------------------
1846 volOnline(struct cmd_syndesc *as, void *arock)
1849 afs_int32 partition;
1851 afs_int32 code, err = 0;
1853 server = GetServer(as->parms[0].items->data);
1855 fprintf(STDERR, "vos: server '%s' not found in host table\n",
1856 as->parms[0].items->data);
1860 partition = volutil_GetPartitionID(as->parms[1].items->data);
1861 if (partition < 0) {
1862 fprintf(STDERR, "vos: could not interpret partition name '%s'\n",
1863 as->parms[1].items->data);
1867 volid = vsu_GetVolumeID(as->parms[2].items->data, cstruct, &err); /* -id */
1870 PrintError("", err);
1872 fprintf(STDERR, "Unknown volume ID or name '%s'\n",
1873 as->parms[0].items->data);
1877 code = UV_SetVolume(server, partition, volid, ITOffline, 0 /*online */ ,
1880 fprintf(STDERR, "Failed to set volume. Code = %d\n", code);
1887 /*------------------------------------------------------------------------
1888 * PRIVATE volOffline
1891 * Brings a volume offline.
1894 * as : Ptr to parsed command line arguments.
1897 * 0 for a successful operation,
1900 * Nothing interesting.
1904 *------------------------------------------------------------------------
1907 volOffline(struct cmd_syndesc *as, void *arock)
1910 afs_int32 partition;
1912 afs_int32 code, err = 0;
1913 afs_int32 transflag, sleeptime, transdone;
1915 server = GetServer(as->parms[0].items->data);
1917 fprintf(STDERR, "vos: server '%s' not found in host table\n",
1918 as->parms[0].items->data);
1922 partition = volutil_GetPartitionID(as->parms[1].items->data);
1923 if (partition < 0) {
1924 fprintf(STDERR, "vos: could not interpret partition name '%s'\n",
1925 as->parms[1].items->data);
1929 volid = vsu_GetVolumeID(as->parms[2].items->data, cstruct, &err); /* -id */
1932 PrintError("", err);
1934 fprintf(STDERR, "Unknown volume ID or name '%s'\n",
1935 as->parms[0].items->data);
1939 transflag = (as->parms[4].items ? ITBusy : ITOffline);
1940 sleeptime = (as->parms[3].items ? atol(as->parms[3].items->data) : 0);
1941 transdone = ((sleeptime || as->parms[4].items) ? 0 /*online */ : VTOutOfService);
1942 if (as->parms[4].items && !as->parms[3].items) {
1943 fprintf(STDERR, "-sleep option must be used with -busy flag\n");
1948 UV_SetVolume(server, partition, volid, transflag, transdone,
1951 fprintf(STDERR, "Failed to set volume. Code = %d\n", code);
1959 CreateVolume(struct cmd_syndesc *as, void *arock)
1963 afs_uint32 volid = 0, rovolid = 0, bkvolid = 0;
1964 afs_uint32 *arovolid;
1966 struct nvldbentry entry;
1971 arovolid = &rovolid;
1974 tserver = GetServer(as->parms[0].items->data);
1976 fprintf(STDERR, "vos: host '%s' not found in host table\n",
1977 as->parms[0].items->data);
1980 pnum = volutil_GetPartitionID(as->parms[1].items->data);
1982 fprintf(STDERR, "vos: could not interpret partition name '%s'\n",
1983 as->parms[1].items->data);
1986 if (!IsPartValid(pnum, tserver, &code)) { /*check for validity of the partition */
1988 PrintError("", code);
1991 "vos : partition %s does not exist on the server\n",
1992 as->parms[1].items->data);
1995 if (!ISNAMEVALID(as->parms[2].items->data)) {
1997 "vos: the name of the root volume %s exceeds the size limit of %d\n",
1998 as->parms[2].items->data, VOLSER_OLDMAXVOLNAME - 10);
2001 if (!VolNameOK(as->parms[2].items->data)) {
2003 "Illegal volume name %s, should not end in .readonly or .backup\n",
2004 as->parms[2].items->data);
2007 if (IsNumeric(as->parms[2].items->data)) {
2008 fprintf(STDERR, "Illegal volume name %s, should not be a number\n",
2009 as->parms[2].items->data);
2012 vcode = VLDB_GetEntryByName(as->parms[2].items->data, &entry);
2014 fprintf(STDERR, "Volume %s already exists\n",
2015 as->parms[2].items->data);
2016 PrintDiagnostics("create", code);
2020 if (as->parms[3].items) {
2021 code = util_GetHumanInt32(as->parms[3].items->data, "a);
2023 fprintf(STDERR, "vos: bad integer specified for quota.\n");
2028 if (as->parms[4].items) {
2029 if (!IsNumeric(as->parms[4].items->data)) {
2030 fprintf(STDERR, "vos: Given volume ID %s should be numeric.\n",
2031 as->parms[4].items->data);
2035 code = util_GetUInt32(as->parms[4].items->data, &volid);
2037 fprintf(STDERR, "vos: bad integer specified for volume ID.\n");
2042 if (as->parms[5].items) {
2043 if (!IsNumeric(as->parms[5].items->data)) {
2044 fprintf(STDERR, "vos: Given RO volume ID %s should be numeric.\n",
2045 as->parms[5].items->data);
2049 code = util_GetUInt32(as->parms[5].items->data, &rovolid);
2051 fprintf(STDERR, "vos: bad integer specified for volume ID.\n");
2061 UV_CreateVolume3(tserver, pnum, as->parms[2].items->data, quota, 0,
2062 0, 0, 0, &volid, arovolid, &bkvolid);
2064 PrintDiagnostics("create", code);
2067 MapPartIdIntoName(pnum, part);
2068 fprintf(STDOUT, "Volume %lu created on partition %s of %s\n",
2069 (unsigned long)volid, part, as->parms[0].items->data);
2075 DeleteVolume(struct cmd_syndesc *as, void *arock)
2077 afs_int32 err, code = 0;
2078 afs_uint32 server = 0;
2079 afs_int32 partition = -1;
2084 if (as->parms[0].items) {
2085 server = GetServer(as->parms[0].items->data);
2087 fprintf(STDERR, "vos: server '%s' not found in host table\n",
2088 as->parms[0].items->data);
2093 if (as->parms[1].items) {
2094 partition = volutil_GetPartitionID(as->parms[1].items->data);
2095 if (partition < 0) {
2096 fprintf(STDERR, "vos: could not interpret partition name '%s'\n",
2097 as->parms[1].items->data);
2101 /* Check for validity of the partition */
2102 if (!IsPartValid(partition, server, &code)) {
2104 PrintError("", code);
2107 "vos : partition %s does not exist on the server\n",
2108 as->parms[1].items->data);
2114 volid = vsu_GetVolumeID(as->parms[2].items->data, cstruct, &err);
2116 fprintf(STDERR, "Can't find volume name '%s' in VLDB\n",
2117 as->parms[2].items->data);
2119 PrintError("", err);
2123 /* If the server or partition option are not complete, try to fill
2124 * them in from the VLDB entry.
2126 if ((partition == -1) || !server) {
2127 struct nvldbentry entry;
2129 code = VLDB_GetEntryByID(volid, -1, &entry);
2132 "Could not fetch the entry for volume %lu from VLDB\n",
2133 (unsigned long)volid);
2134 PrintError("", code);
2138 if (((volid == entry.volumeId[RWVOL]) && (entry.flags & VLF_RWEXISTS))
2139 || ((volid == entry.volumeId[BACKVOL])
2140 && (entry.flags & VLF_BACKEXISTS))) {
2141 idx = Lp_GetRwIndex(&entry);
2142 if ((idx == -1) || (server && (server != entry.serverNumber[idx]))
2143 || ((partition != -1)
2144 && (partition != entry.serverPartition[idx]))) {
2145 fprintf(STDERR, "VLDB: Volume '%s' no match\n",
2146 as->parms[2].items->data);
2149 } else if ((volid == entry.volumeId[ROVOL])
2150 && (entry.flags & VLF_ROEXISTS)) {
2151 for (idx = -1, j = 0; j < entry.nServers; j++) {
2152 if (!(entry.serverFlags[j] & VLSF_ROVOL))
2155 if (((server == 0) || (server == entry.serverNumber[j]))
2156 && ((partition == -1)
2157 || (partition == entry.serverPartition[j]))) {
2160 "VLDB: Volume '%s' matches more than one RO\n",
2161 as->parms[2].items->data);
2168 fprintf(STDERR, "VLDB: Volume '%s' no match\n",
2169 as->parms[2].items->data);
2173 fprintf(STDERR, "VLDB: Volume '%s' no match\n",
2174 as->parms[2].items->data);
2178 server = htonl(entry.serverNumber[idx]);
2179 partition = entry.serverPartition[idx];
2183 code = UV_DeleteVolume(server, partition, volid);
2185 PrintDiagnostics("remove", code);
2189 MapPartIdIntoName(partition, pname);
2190 fprintf(STDOUT, "Volume %lu on partition %s server %s deleted\n",
2191 (unsigned long)volid, pname, hostutil_GetNameByINet(server));
2195 #define TESTM 0 /* set for move space tests, clear for production */
2197 MoveVolume(struct cmd_syndesc *as, void *arock)
2201 afs_uint32 fromserver, toserver;
2202 afs_int32 frompart, topart;
2203 afs_int32 flags, code, err;
2204 char fromPartName[10], toPartName[10];
2206 struct diskPartition64 partition; /* for space check */
2209 volid = vsu_GetVolumeID(as->parms[0].items->data, cstruct, &err);
2212 PrintError("", err);
2214 fprintf(STDERR, "vos: can't find volume ID or name '%s'\n",
2215 as->parms[0].items->data);
2218 fromserver = GetServer(as->parms[1].items->data);
2219 if (fromserver == 0) {
2220 fprintf(STDERR, "vos: server '%s' not found in host table\n",
2221 as->parms[1].items->data);
2224 toserver = GetServer(as->parms[3].items->data);
2225 if (toserver == 0) {
2226 fprintf(STDERR, "vos: server '%s' not found in host table\n",
2227 as->parms[3].items->data);
2230 frompart = volutil_GetPartitionID(as->parms[2].items->data);
2232 fprintf(STDERR, "vos: could not interpret partition name '%s'\n",
2233 as->parms[2].items->data);
2236 if (!IsPartValid(frompart, fromserver, &code)) { /*check for validity of the partition */
2238 PrintError("", code);
2241 "vos : partition %s does not exist on the server\n",
2242 as->parms[2].items->data);
2245 topart = volutil_GetPartitionID(as->parms[4].items->data);
2247 fprintf(STDERR, "vos: could not interpret partition name '%s'\n",
2248 as->parms[4].items->data);
2251 if (!IsPartValid(topart, toserver, &code)) { /*check for validity of the partition */
2253 PrintError("", code);
2256 "vos : partition %s does not exist on the server\n",
2257 as->parms[4].items->data);
2262 if (as->parms[5].items) flags |= RV_NOCLONE;
2265 * check source partition for space to clone volume
2268 MapPartIdIntoName(topart, toPartName);
2269 MapPartIdIntoName(frompart, fromPartName);
2272 * check target partition for space to move volume
2275 code = UV_PartitionInfo64(toserver, toPartName, &partition);
2277 fprintf(STDERR, "vos: cannot access partition %s\n", toPartName);
2281 fprintf(STDOUT, "target partition %s free space %" AFS_INT64_FMT "\n", toPartName,
2284 p = (volintInfo *) 0;
2285 code = UV_ListOneVolume(fromserver, frompart, volid, &p);
2287 fprintf(STDERR, "vos:cannot access volume %lu\n",
2288 (unsigned long)volid);
2292 fprintf(STDOUT, "volume %lu size %d\n", (unsigned long)volid,
2294 if (partition.free <= p->size) {
2296 "vos: no space on target partition %s to move volume %lu\n",
2297 toPartName, (unsigned long)volid);
2304 fprintf(STDOUT, "size test - don't do move\n");
2308 /* successful move still not guaranteed but shoot for it */
2311 UV_MoveVolume2(volid, fromserver, frompart, toserver, topart, flags);
2313 PrintDiagnostics("move", code);
2316 MapPartIdIntoName(topart, toPartName);
2317 MapPartIdIntoName(frompart, fromPartName);
2318 fprintf(STDOUT, "Volume %lu moved from %s %s to %s %s \n",
2319 (unsigned long)volid, as->parms[1].items->data, fromPartName,
2320 as->parms[3].items->data, toPartName);
2326 CopyVolume(struct cmd_syndesc *as, void *arock)
2329 afs_uint32 fromserver, toserver;
2330 afs_int32 frompart, topart, code, err, flags;
2331 char fromPartName[10], toPartName[10], *tovolume;
2332 struct nvldbentry entry;
2333 struct diskPartition64 partition; /* for space check */
2336 volid = vsu_GetVolumeID(as->parms[0].items->data, cstruct, &err);
2339 PrintError("", err);
2341 fprintf(STDERR, "vos: can't find volume ID or name '%s'\n",
2342 as->parms[0].items->data);
2345 fromserver = GetServer(as->parms[1].items->data);
2346 if (fromserver == 0) {
2347 fprintf(STDERR, "vos: server '%s' not found in host table\n",
2348 as->parms[1].items->data);
2352 toserver = GetServer(as->parms[4].items->data);
2353 if (toserver == 0) {
2354 fprintf(STDERR, "vos: server '%s' not found in host table\n",
2355 as->parms[4].items->data);
2359 tovolume = as->parms[3].items->data;
2360 if (!ISNAMEVALID(tovolume)) {
2362 "vos: the name of the root volume %s exceeds the size limit of %d\n",
2363 tovolume, VOLSER_OLDMAXVOLNAME - 10);
2366 if (!VolNameOK(tovolume)) {
2368 "Illegal volume name %s, should not end in .readonly or .backup\n",
2372 if (IsNumeric(tovolume)) {
2373 fprintf(STDERR, "Illegal volume name %s, should not be a number\n",
2377 code = VLDB_GetEntryByName(tovolume, &entry);
2379 fprintf(STDERR, "Volume %s already exists\n", tovolume);
2380 PrintDiagnostics("copy", code);
2384 frompart = volutil_GetPartitionID(as->parms[2].items->data);
2386 fprintf(STDERR, "vos: could not interpret partition name '%s'\n",
2387 as->parms[2].items->data);
2390 if (!IsPartValid(frompart, fromserver, &code)) { /*check for validity of the partition */
2392 PrintError("", code);
2395 "vos : partition %s does not exist on the server\n",
2396 as->parms[2].items->data);
2400 topart = volutil_GetPartitionID(as->parms[5].items->data);
2402 fprintf(STDERR, "vos: could not interpret partition name '%s'\n",
2403 as->parms[5].items->data);
2406 if (!IsPartValid(topart, toserver, &code)) { /*check for validity of the partition */
2408 PrintError("", code);
2411 "vos : partition %s does not exist on the server\n",
2412 as->parms[5].items->data);
2417 if (as->parms[6].items) flags |= RV_OFFLINE;
2418 if (as->parms[7].items) flags |= RV_RDONLY;
2419 if (as->parms[8].items) flags |= RV_NOCLONE;
2421 MapPartIdIntoName(topart, toPartName);
2422 MapPartIdIntoName(frompart, fromPartName);
2425 * check target partition for space to move volume
2428 code = UV_PartitionInfo64(toserver, toPartName, &partition);
2430 fprintf(STDERR, "vos: cannot access partition %s\n", toPartName);
2434 fprintf(STDOUT, "target partition %s free space %" AFS_INT64_FMT "\n", toPartName,
2437 p = (volintInfo *) 0;
2438 code = UV_ListOneVolume(fromserver, frompart, volid, &p);
2440 fprintf(STDERR, "vos:cannot access volume %lu\n",
2441 (unsigned long)volid);
2445 if (partition.free <= p->size) {
2447 "vos: no space on target partition %s to copy volume %lu\n",
2448 toPartName, (unsigned long)volid);
2454 /* successful copy still not guaranteed but shoot for it */
2457 UV_CopyVolume2(volid, fromserver, frompart, tovolume, toserver,
2460 PrintDiagnostics("copy", code);
2463 MapPartIdIntoName(topart, toPartName);
2464 MapPartIdIntoName(frompart, fromPartName);
2465 fprintf(STDOUT, "Volume %lu copied from %s %s to %s on %s %s \n",
2466 (unsigned long)volid, as->parms[1].items->data, fromPartName,
2467 tovolume, as->parms[4].items->data, toPartName);
2474 ShadowVolume(struct cmd_syndesc *as, void *arock)
2476 afs_uint32 volid, tovolid;
2477 afs_uint32 fromserver, toserver;
2478 afs_int32 frompart, topart;
2479 afs_int32 code, err, flags;
2480 char fromPartName[10], toPartName[10], toVolName[32], *tovolume;
2481 struct diskPartition64 partition; /* for space check */
2484 p = (volintInfo *) 0;
2485 q = (volintInfo *) 0;
2487 volid = vsu_GetVolumeID(as->parms[0].items->data, cstruct, &err);
2490 PrintError("", err);
2492 fprintf(STDERR, "vos: can't find volume ID or name '%s'\n",
2493 as->parms[0].items->data);
2496 fromserver = GetServer(as->parms[1].items->data);
2497 if (fromserver == 0) {
2498 fprintf(STDERR, "vos: server '%s' not found in host table\n",
2499 as->parms[1].items->data);
2503 toserver = GetServer(as->parms[3].items->data);
2504 if (toserver == 0) {
2505 fprintf(STDERR, "vos: server '%s' not found in host table\n",
2506 as->parms[3].items->data);
2510 frompart = volutil_GetPartitionID(as->parms[2].items->data);
2512 fprintf(STDERR, "vos: could not interpret partition name '%s'\n",
2513 as->parms[2].items->data);
2516 if (!IsPartValid(frompart, fromserver, &code)) { /*check for validity of the partition */
2518 PrintError("", code);
2521 "vos : partition %s does not exist on the server\n",
2522 as->parms[2].items->data);
2526 topart = volutil_GetPartitionID(as->parms[4].items->data);
2528 fprintf(STDERR, "vos: could not interpret partition name '%s'\n",
2529 as->parms[4].items->data);
2532 if (!IsPartValid(topart, toserver, &code)) { /*check for validity of the partition */
2534 PrintError("", code);
2537 "vos : partition %s does not exist on the server\n",
2538 as->parms[4].items->data);
2542 if (as->parms[5].items) {
2543 tovolume = as->parms[5].items->data;
2544 if (!ISNAMEVALID(tovolume)) {
2546 "vos: the name of the root volume %s exceeds the size limit of %d\n",
2547 tovolume, VOLSER_OLDMAXVOLNAME - 10);
2550 if (!VolNameOK(tovolume)) {
2552 "Illegal volume name %s, should not end in .readonly or .backup\n",
2556 if (IsNumeric(tovolume)) {
2558 "Illegal volume name %s, should not be a number\n",
2563 /* use actual name of source volume */
2564 code = UV_ListOneVolume(fromserver, frompart, volid, &p);
2566 fprintf(STDERR, "vos:cannot access volume %lu\n",
2567 (unsigned long)volid);
2570 strcpy(toVolName, p->name);
2571 tovolume = toVolName;
2572 /* save p for size checks later */
2575 if (as->parms[6].items) {
2576 tovolid = vsu_GetVolumeID(as->parms[6].items->data, cstruct, &err);
2579 PrintError("", err);
2581 fprintf(STDERR, "vos: can't find volume ID or name '%s'\n",
2582 as->parms[6].items->data);
2588 tovolid = vsu_GetVolumeID(tovolume, cstruct, &err);
2591 PrintError("", err);
2593 fprintf(STDERR, "vos: can't find volume ID or name '%s'\n",
2602 if (as->parms[7].items) flags |= RV_OFFLINE;
2603 if (as->parms[8].items) flags |= RV_RDONLY;
2604 if (as->parms[9].items) flags |= RV_NOCLONE;
2605 if (as->parms[10].items) flags |= RV_CPINCR;
2607 MapPartIdIntoName(topart, toPartName);
2608 MapPartIdIntoName(frompart, fromPartName);
2611 * check target partition for space to move volume
2614 code = UV_PartitionInfo64(toserver, toPartName, &partition);
2616 fprintf(STDERR, "vos: cannot access partition %s\n", toPartName);
2620 fprintf(STDOUT, "target partition %s free space %" AFS_INT64_FMT "\n", toPartName,
2623 /* Don't do this again if we did it above */
2625 code = UV_ListOneVolume(fromserver, frompart, volid, &p);
2627 fprintf(STDERR, "vos:cannot access volume %lu\n",
2628 (unsigned long)volid);
2633 /* OK if this fails */
2634 code = UV_ListOneVolume(toserver, topart, tovolid, &q);
2636 /* Treat existing volume size as "free" */
2638 p->size = (q->size < p->size) ? p->size - q->size : 0;
2640 if (partition.free <= p->size) {
2642 "vos: no space on target partition %s to copy volume %lu\n",
2643 toPartName, (unsigned long)volid);
2651 /* successful copy still not guaranteed but shoot for it */
2654 UV_CopyVolume2(volid, fromserver, frompart, tovolume, toserver,
2655 topart, tovolid, flags);
2657 PrintDiagnostics("shadow", code);
2660 MapPartIdIntoName(topart, toPartName);
2661 MapPartIdIntoName(frompart, fromPartName);
2662 fprintf(STDOUT, "Volume %lu shadowed from %s %s to %s %s \n",
2663 (unsigned long)volid, as->parms[1].items->data, fromPartName,
2664 as->parms[3].items->data, toPartName);
2671 CloneVolume(struct cmd_syndesc *as, void *arock)
2673 afs_uint32 volid, cloneid;
2675 afs_int32 part, voltype;
2676 char partName[10], *volname;
2677 afs_int32 code, err, flags;
2678 struct nvldbentry entry;
2680 volid = vsu_GetVolumeID(as->parms[0].items->data, cstruct, &err);
2683 PrintError("", err);
2685 fprintf(STDERR, "vos: can't find volume ID or name '%s'\n",
2686 as->parms[0].items->data);
2690 if (as->parms[1].items || as->parms[2].items) {
2691 if (!as->parms[1].items || !as->parms[2].items) {
2693 "Must specify both -server and -partition options\n");
2696 server = GetServer(as->parms[1].items->data);
2698 fprintf(STDERR, "vos: server '%s' not found in host table\n",
2699 as->parms[1].items->data);
2702 part = volutil_GetPartitionID(as->parms[2].items->data);
2704 fprintf(STDERR, "vos: could not interpret partition name '%s'\n",
2705 as->parms[2].items->data);
2708 if (!IsPartValid(part, server, &code)) { /*check for validity of the partition */
2710 PrintError("", code);
2713 "vos : partition %s does not exist on the server\n",
2714 as->parms[2].items->data);
2718 code = GetVolumeInfo(volid, &server, &part, &voltype, &entry);
2724 if (as->parms[3].items) {
2725 volname = as->parms[3].items->data;
2726 if (strlen(volname) > VOLSER_OLDMAXVOLNAME - 1) {
2728 "vos: the name of the root volume %s exceeds the size limit of %d\n",
2729 volname, VOLSER_OLDMAXVOLNAME - 1);
2732 if (IsNumeric(volname)) {
2734 "Illegal volume name %s, should not be a number\n",
2741 if (as->parms[4].items) {
2742 cloneid = vsu_GetVolumeID(as->parms[4].items->data, cstruct, &err);
2745 PrintError("", err);
2747 fprintf(STDERR, "vos: can't find volume ID or name '%s'\n",
2748 as->parms[4].items->data);
2754 if (as->parms[5].items) flags |= RV_OFFLINE;
2755 if (as->parms[6].items && as->parms[7].items) {
2756 fprintf(STDERR, "vos: cannot specify that a volume be -readwrite and -readonly\n");
2759 if (as->parms[6].items) flags |= RV_RDONLY;
2760 if (as->parms[7].items) flags |= RV_RWONLY;
2764 UV_CloneVolume(server, part, volid, cloneid, volname, flags);
2767 PrintDiagnostics("clone", code);
2770 MapPartIdIntoName(part, partName);
2771 fprintf(STDOUT, "Created clone for volume %s\n",
2772 as->parms[0].items->data);
2779 BackupVolume(struct cmd_syndesc *as, void *arock)
2783 afs_int32 apart, vtype, code, err;
2784 struct nvldbentry entry;
2787 afs_uint32 buserver;
2788 afs_int32 bupart, butype;
2789 struct nvldbentry buentry;
2791 avolid = vsu_GetVolumeID(as->parms[0].items->data, cstruct, &err);
2794 PrintError("", err);
2796 fprintf(STDERR, "vos: can't find volume ID or name '%s'\n",
2797 as->parms[0].items->data);
2800 code = GetVolumeInfo(avolid, &aserver, &apart, &vtype, &entry);
2804 /* verify this is a readwrite volume */
2806 if (vtype != RWVOL) {
2807 fprintf(STDERR, "%s not RW volume\n", as->parms[0].items->data);
2811 /* is there a backup volume already? */
2813 if (entry.flags & VLF_BACKEXISTS) {
2814 /* yep, where is it? */
2816 buvolid = entry.volumeId[BACKVOL];
2817 code = GetVolumeInfo(buvolid, &buserver, &bupart, &butype, &buentry);
2822 code = VLDB_IsSameAddrs(buserver, aserver, &err);
2825 "Failed to get info about server's %d address(es) from vlserver; aborting call!\n",
2831 "FATAL ERROR: backup volume %lu exists on server %lu\n",
2832 (unsigned long)buvolid, (unsigned long)buserver);
2837 /* nope, carry on */
2839 code = UV_BackupVolume(aserver, apart, avolid);
2842 PrintDiagnostics("backup", code);
2845 fprintf(STDOUT, "Created backup volume for %s \n",
2846 as->parms[0].items->data);
2851 ReleaseVolume(struct cmd_syndesc *as, void *arock)
2854 struct nvldbentry entry;
2857 afs_int32 apart, vtype, code, err;
2860 if (as->parms[1].items) /* -force */
2861 flags |= (REL_COMPLETE | REL_FULLDUMPS);
2862 if (as->parms[2].items) { /* -stayonline */
2863 fprintf(STDERR, "vos: -stayonline not supported\n");
2866 if (as->parms[3].items) /* -force-reclone */
2867 flags |= REL_COMPLETE;
2869 avolid = vsu_GetVolumeID(as->parms[0].items->data, cstruct, &err);
2872 PrintError("", err);
2874 fprintf(STDERR, "vos: can't find volume '%s'\n",
2875 as->parms[0].items->data);
2878 code = GetVolumeInfo(avolid, &aserver, &apart, &vtype, &entry);
2882 if (vtype != RWVOL) {
2883 fprintf(STDERR, "%s not a RW volume\n", as->parms[0].items->data);
2887 if (!ISNAMEVALID(entry.name)) {
2889 "Volume name %s is too long, rename before releasing\n",
2894 code = UV_ReleaseVolume(avolid, aserver, apart, flags);
2897 PrintDiagnostics("release", code);
2900 fprintf(STDOUT, "Released volume %s successfully\n",
2901 as->parms[0].items->data);
2906 DumpVolumeCmd(struct cmd_syndesc *as, void *arock)
2910 afs_int32 apart, voltype, fromdate = 0, code, err, i, flags;
2911 char filename[MAXPATHLEN];
2912 struct nvldbentry entry;
2914 rx_SetRxDeadTime(60 * 10);
2915 for (i = 0; i < MAXSERVERS; i++) {
2916 struct rx_connection *rxConn = ubik_GetRPCConn(cstruct, i);
2919 rx_SetConnDeadTime(rxConn, rx_connDeadTime);
2920 if (rx_ServiceOf(rxConn))
2921 rx_ServiceOf(rxConn)->connDeadTime = rx_connDeadTime;
2924 avolid = vsu_GetVolumeID(as->parms[0].items->data, cstruct, &err);
2927 PrintError("", err);
2929 fprintf(STDERR, "vos: can't find volume '%s'\n",
2930 as->parms[0].items->data);
2934 if (as->parms[3].items || as->parms[4].items) {
2935 if (!as->parms[3].items || !as->parms[4].items) {
2937 "Must specify both -server and -partition options\n");
2940 aserver = GetServer(as->parms[3].items->data);
2942 fprintf(STDERR, "Invalid server name\n");
2945 apart = volutil_GetPartitionID(as->parms[4].items->data);
2947 fprintf(STDERR, "Invalid partition name\n");
2951 code = GetVolumeInfo(avolid, &aserver, &apart, &voltype, &entry);
2956 if (as->parms[1].items && strcmp(as->parms[1].items->data, "0")) {
2957 code = ktime_DateToInt32(as->parms[1].items->data, &fromdate);
2959 fprintf(STDERR, "vos: failed to parse date '%s' (error=%d))\n",
2960 as->parms[1].items->data, code);
2964 if (as->parms[2].items) {
2965 strcpy(filename, as->parms[2].items->data);
2967 strcpy(filename, "");
2970 flags = as->parms[6].items ? VOLDUMPV2_OMITDIRS : 0;
2972 if (as->parms[5].items) {
2974 UV_DumpClonedVolume(avolid, aserver, apart, fromdate,
2975 DumpFunction, filename, flags);
2978 UV_DumpVolume(avolid, aserver, apart, fromdate, DumpFunction,
2981 if ((code == RXGEN_OPCODE) && (as->parms[6].items)) {
2982 flags &= ~VOLDUMPV2_OMITDIRS;
2986 PrintDiagnostics("dump", code);
2989 if (strcmp(filename, ""))
2990 fprintf(STDERR, "Dumped volume %s in file %s\n",
2991 as->parms[0].items->data, filename);
2993 fprintf(STDERR, "Dumped volume %s in stdout \n",
2994 as->parms[0].items->data);
3008 RestoreVolumeCmd(struct cmd_syndesc *as, void *arock)
3010 afs_uint32 avolid, aparentid;
3012 afs_int32 apart, code, vcode, err;
3013 afs_int32 aoverwrite = ASK;
3014 afs_int32 acreation = 0, alastupdate = 0;
3015 int restoreflags = 0;
3016 int readonly = 0, offline = 0, voltype = RWVOL;
3017 char afilename[MAXPATHLEN], avolname[VOLSER_MAXVOLNAME + 1], apartName[10];
3018 char volname[VOLSER_MAXVOLNAME + 1];
3019 struct nvldbentry entry;
3022 if (as->parms[4].items) {
3023 avolid = vsu_GetVolumeID(as->parms[4].items->data, cstruct, &err);
3026 PrintError("", err);
3028 fprintf(STDERR, "vos: can't find volume '%s'\n",
3029 as->parms[4].items->data);
3035 if (as->parms[5].items) {
3036 if ((strcmp(as->parms[5].items->data, "a") == 0)
3037 || (strcmp(as->parms[5].items->data, "abort") == 0)) {
3039 } else if ((strcmp(as->parms[5].items->data, "f") == 0)
3040 || (strcmp(as->parms[5].items->data, "full") == 0)) {
3042 } else if ((strcmp(as->parms[5].items->data, "i") == 0)
3043 || (strcmp(as->parms[5].items->data, "inc") == 0)
3044 || (strcmp(as->parms[5].items->data, "increment") == 0)
3045 || (strcmp(as->parms[5].items->data, "incremental") == 0)) {
3048 fprintf(STDERR, "vos: %s is not a valid argument to -overwrite\n",
3049 as->parms[5].items->data);
3053 if (as->parms[6].items)
3055 if (as->parms[7].items) {
3060 if (as->parms[8].items) {
3061 if ((strcmp(as->parms[8].items->data, "d") == 0)
3062 || (strcmp(as->parms[8].items->data, "dump") == 0)) {
3063 acreation = TS_DUMP;
3064 } else if ((strcmp(as->parms[8].items->data, "k") == 0)
3065 || (strcmp(as->parms[8].items->data, "keep") == 0)) {
3066 acreation = TS_KEEP;
3067 } else if ((strcmp(as->parms[8].items->data, "n") == 0)
3068 || (strcmp(as->parms[8].items->data, "new") == 0)) {
3071 fprintf(STDERR, "vos: %s is not a valid argument to -creation\n",
3072 as->parms[8].items->data);
3077 if (as->parms[9].items) {
3078 if ((strcmp(as->parms[9].items->data, "d") == 0)
3079 || (strcmp(as->parms[9].items->data, "dump") == 0)) {
3080 alastupdate = TS_DUMP;
3081 } else if ((strcmp(as->parms[9].items->data, "k") == 0)
3082 || (strcmp(as->parms[9].items->data, "keep") == 0)) {
3083 alastupdate = TS_KEEP;
3084 } else if ((strcmp(as->parms[9].items->data, "n") == 0)
3085 || (strcmp(as->parms[9].items->data, "new") == 0)) {
3086 alastupdate = TS_NEW;
3088 fprintf(STDERR, "vos: %s is not a valid argument to -lastupdate\n",
3089 as->parms[9].items->data);
3094 aserver = GetServer(as->parms[0].items->data);
3096 fprintf(STDERR, "vos: server '%s' not found in host table\n",
3097 as->parms[0].items->data);
3100 apart = volutil_GetPartitionID(as->parms[1].items->data);
3102 fprintf(STDERR, "vos: could not interpret partition name '%s'\n",
3103 as->parms[1].items->data);
3106 if (!IsPartValid(apart, aserver, &code)) { /*check for validity of the partition */
3108 PrintError("", code);
3111 "vos : partition %s does not exist on the server\n",
3112 as->parms[1].items->data);
3115 strcpy(avolname, as->parms[2].items->data);
3116 if (!ISNAMEVALID(avolname)) {
3118 "vos: the name of the volume %s exceeds the size limit\n",
3122 if (!VolNameOK(avolname)) {
3124 "Illegal volume name %s, should not end in .readonly or .backup\n",
3128 if (as->parms[3].items) {
3129 strcpy(afilename, as->parms[3].items->data);
3130 if (!FileExists(afilename)) {
3131 fprintf(STDERR, "Can't access file %s\n", afilename);
3135 strcpy(afilename, "");
3138 /* Check if volume exists or not */
3140 vsu_ExtractName(volname, avolname);
3141 vcode = VLDB_GetEntryByName(volname, &entry);
3142 if (vcode) { /* no volume - do a full restore */
3143 restoreflags = RV_FULLRST;
3144 if ((aoverwrite == INC) || (aoverwrite == ABORT))
3146 "Volume does not exist; Will perform a full restore\n");
3149 else if ((!readonly && Lp_GetRwIndex(&entry) == -1) /* RW volume does not exist - do a full */
3150 ||(readonly && !Lp_ROMatch(0, 0, &entry))) { /* RO volume does not exist - do a full */
3151 restoreflags = RV_FULLRST;
3152 if ((aoverwrite == INC) || (aoverwrite == ABORT))
3154 "%s Volume does not exist; Will perform a full restore\n",
3155 readonly ? "RO" : "RW");
3158 avolid = entry.volumeId[voltype];
3159 } else if (entry.volumeId[voltype] != 0
3160 && entry.volumeId[voltype] != avolid) {
3161 avolid = entry.volumeId[voltype];
3163 aparentid = entry.volumeId[RWVOL];
3166 else { /* volume exists - do we do a full incremental or abort */
3168 afs_int32 Opart, Otype, vol_elsewhere = 0;
3169 struct nvldbentry Oentry;
3173 avolid = entry.volumeId[voltype];
3174 } else if (entry.volumeId[voltype] != 0
3175 && entry.volumeId[voltype] != avolid) {
3176 avolid = entry.volumeId[voltype];
3178 aparentid = entry.volumeId[RWVOL];
3180 /* A file name was specified - check if volume is on another partition */
3181 vcode = GetVolumeInfo(avolid, &Oserver, &Opart, &Otype, &Oentry);
3185 vcode = VLDB_IsSameAddrs(Oserver, aserver, &err);
3188 "Failed to get info about server's %d address(es) from vlserver (err=%d); aborting call!\n",
3192 if (!vcode || (Opart != apart))
3195 if (aoverwrite == ASK) {
3196 if (strcmp(afilename, "") == 0) { /* The file is from standard in */
3198 "Volume exists and no -overwrite option specified; Aborting restore command\n");
3202 /* Ask what to do */
3203 if (vol_elsewhere) {
3205 "The volume %s %u already exists on a different server/part\n",
3206 volname, entry.volumeId[voltype]);
3208 "Do you want to do a full restore or abort? [fa](a): ");
3211 "The volume %s %u already exists in the VLDB\n",
3212 volname, entry.volumeId[voltype]);
3214 "Do you want to do a full/incremental restore or abort? [fia](a): ");
3217 while (!(dc == EOF || dc == '\n'))
3218 dc = getchar(); /* goto end of line */
3219 if ((c == 'f') || (c == 'F'))
3221 else if ((c == 'i') || (c == 'I'))
3227 if (aoverwrite == ABORT) {
3228 fprintf(STDERR, "Volume exists; Aborting restore command\n");
3230 } else if (aoverwrite == FULL) {
3231 restoreflags = RV_FULLRST;
3233 "Volume exists; Will delete and perform full restore\n");
3234 } else if (aoverwrite == INC) {
3236 if (vol_elsewhere) {
3238 "%s volume %lu already exists on a different server/part; not allowed\n",
3239 readonly ? "RO" : "RW", (unsigned long)avolid);
3245 restoreflags |= RV_OFFLINE;
3247 restoreflags |= RV_RDONLY;
3249 switch (acreation) {
3251 restoreflags |= RV_CRDUMP;
3254 restoreflags |= RV_CRKEEP;
3257 restoreflags |= RV_CRNEW;
3260 if (aoverwrite == FULL)
3261 restoreflags |= RV_CRNEW;
3263 restoreflags |= RV_CRKEEP;
3266 switch (alastupdate) {
3268 restoreflags |= RV_LUDUMP;
3271 restoreflags |= RV_LUKEEP;
3274 restoreflags |= RV_LUNEW;
3277 restoreflags |= RV_LUDUMP;
3279 if (as->parms[10].items) {
3280 restoreflags |= RV_NODEL;
3285 UV_RestoreVolume2(aserver, apart, avolid, aparentid,
3286 avolname, restoreflags, WriteData, afilename);
3288 PrintDiagnostics("restore", code);
3291 MapPartIdIntoName(apart, apartName);
3294 * patch typo here - originally "parms[1]", should be "parms[0]"
3297 fprintf(STDOUT, "Restored volume %s on %s %s\n", avolname,
3298 as->parms[0].items->data, apartName);
3303 LockReleaseCmd(struct cmd_syndesc *as, void *arock)
3306 afs_int32 code, err;
3308 avolid = vsu_GetVolumeID(as->parms[0].items->data, cstruct, &err);
3311 PrintError("", err);
3313 fprintf(STDERR, "vos: can't find volume '%s'\n",
3314 as->parms[0].items->data);
3318 code = UV_LockRelease(avolid);
3320 PrintDiagnostics("unlock", code);
3323 fprintf(STDOUT, "Released lock on vldb entry for volume %s\n",
3324 as->parms[0].items->data);
3329 AddSite(struct cmd_syndesc *as, void *arock)
3333 afs_int32 apart, code, err, arovolid, valid = 0;
3334 char apartName[10], avolname[VOLSER_MAXVOLNAME + 1];
3336 vsu_ExtractName(avolname, as->parms[2].items->data);;
3337 avolid = vsu_GetVolumeID(avolname, cstruct, &err);
3340 PrintError("", err);
3342 fprintf(STDERR, "vos: can't find volume '%s'\n",
3343 as->parms[2].items->data);
3347 if (as->parms[3].items) {
3348 vsu_ExtractName(avolname, as->parms[3].items->data);
3349 arovolid = vsu_GetVolumeID(avolname, cstruct, &err);
3351 fprintf(STDERR, "vos: invalid ro volume id '%s'\n",
3352 as->parms[3].items->data);
3356 aserver = GetServer(as->parms[0].items->data);
3358 fprintf(STDERR, "vos: server '%s' not found in host table\n",
3359 as->parms[0].items->data);
3362 apart = volutil_GetPartitionID(as->parms[1].items->data);
3364 fprintf(STDERR, "vos: could not interpret partition name '%s'\n",
3365 as->parms[1].items->data);
3368 if (!IsPartValid(apart, aserver, &code)) { /*check for validity of the partition */
3370 PrintError("", code);
3373 "vos : partition %s does not exist on the server\n",
3374 as->parms[1].items->data);
3377 if (as->parms[4].items) {
3380 code = UV_AddSite2(aserver, apart, avolid, arovolid, valid);
3382 PrintDiagnostics("addsite", code);
3385 MapPartIdIntoName(apart, apartName);
3386 fprintf(STDOUT, "Added replication site %s %s for volume %s\n",
3387 as->parms[0].items->data, apartName, as->parms[2].items->data);
3392 RemoveSite(struct cmd_syndesc *as, void *arock)
3397 afs_int32 apart, code, err;
3398 char apartName[10], avolname[VOLSER_MAXVOLNAME + 1];
3400 vsu_ExtractName(avolname, as->parms[2].items->data);
3401 avolid = vsu_GetVolumeID(avolname, cstruct, &err);
3404 PrintError("", err);
3406 fprintf(STDERR, "vos: can't find volume '%s'\n",
3407 as->parms[2].items->data);
3410 aserver = GetServer(as->parms[0].items->data);
3412 fprintf(STDERR, "vos: server '%s' not found in host table\n",
3413 as->parms[0].items->data);
3416 apart = volutil_GetPartitionID(as->parms[1].items->data);
3418 fprintf(STDERR, "vos: could not interpret partition name '%s'\n",
3419 as->parms[1].items->data);
3423 *skip the partition validity check, since it is possible that the partition
3424 *has since been decomissioned.
3427 if (!IsPartValid(apart,aserver,&code)){
3428 if(code) PrintError("",code);
3429 else fprintf(STDERR,"vos : partition %s does not exist on the server\n",as->parms[1].items->data);
3433 code = UV_RemoveSite(aserver, apart, avolid);
3435 PrintDiagnostics("remsite", code);
3438 MapPartIdIntoName(apart, apartName);
3439 fprintf(STDOUT, "Removed replication site %s %s for volume %s\n",
3440 as->parms[0].items->data, apartName, as->parms[2].items->data);
3445 ChangeLocation(struct cmd_syndesc *as, void *arock)
3449 afs_int32 apart, code, err;
3452 avolid = vsu_GetVolumeID(as->parms[2].items->data, cstruct, &err);
3455 PrintError("", err);
3457 fprintf(STDERR, "vos: can't find volume '%s'\n",
3458 as->parms[2].items->data);
3461 aserver = GetServer(as->parms[0].items->data);
3463 fprintf(STDERR, "vos: server '%s' not found in host table\n",
3464 as->parms[0].items->data);
3467 apart = volutil_GetPartitionID(as->parms[1].items->data);
3469 fprintf(STDERR, "vos: could not interpret partition name '%s'\n",
3470 as->parms[1].items->data);
3473 if (!IsPartValid(apart, aserver, &code)) { /*check for validity of the partition */
3475 PrintError("", code);
3478 "vos : partition %s does not exist on the server\n",
3479 as->parms[1].items->data);
3482 code = UV_ChangeLocation(aserver, apart, avolid);
3484 PrintDiagnostics("changeloc", code);
3487 MapPartIdIntoName(apart, apartName);
3488 fprintf(STDOUT, "Changed location to %s %s for volume %s\n",
3489 as->parms[0].items->data, apartName, as->parms[2].items->data);
3494 ListPartitions(struct cmd_syndesc *as, void *arock)
3498 struct partList dummyPartList;
3503 aserver = GetServer(as->parms[0].items->data);
3505 fprintf(STDERR, "vos: server '%s' not found in host table\n",
3506 as->parms[0].items->data);
3511 code = UV_ListPartitions(aserver, &dummyPartList, &cnt);
3513 PrintDiagnostics("listpart", code);
3517 fprintf(STDOUT, "The partitions on the server are:\n");
3518 for (i = 0; i < cnt; i++) {
3519 if (dummyPartList.partFlags[i] & PARTVALID) {
3520 memset(pname, 0, sizeof(pname));
3521 MapPartIdIntoName(dummyPartList.partId[i], pname);
3522 fprintf(STDOUT, " %10s ", pname);
3524 if ((i % 5) == 0 && (i != 0))
3525 fprintf(STDOUT, "\n");
3528 fprintf(STDOUT, "\n");
3529 fprintf(STDOUT, "Total: %d\n", total);
3535 CompareVolName(const void *p1, const void *p2)
3537 volintInfo *arg1, *arg2;
3539 arg1 = (volintInfo *) p1;
3540 arg2 = (volintInfo *) p2;
3541 return (strcmp(arg1->name, arg2->name));
3545 /*------------------------------------------------------------------------
3546 * PRIVATE XCompareVolName
3549 * Comparison routine for volume names coming from an extended
3553 * a_obj1P : Char ptr to first extended vol info object
3554 * a_obj1P : Char ptr to second extended vol info object
3557 * The value of strcmp() on the volume names within the passed
3558 * objects (i,e., -1, 0, or 1).
3561 * Passed to qsort() as the designated comparison routine.
3565 *------------------------------------------------------------------------*/
3568 XCompareVolName(const void *a_obj1P, const void *a_obj2P)
3569 { /*XCompareVolName */
3572 (((struct volintXInfo *)(a_obj1P))->name,
3573 ((struct volintXInfo *)(a_obj2P))->name));
3575 } /*XCompareVolName */
3578 CompareVolID(const void *p1, const void *p2)
3580 volintInfo *arg1, *arg2;
3582 arg1 = (volintInfo *) p1;
3583 arg2 = (volintInfo *) p2;
3584 if (arg1->volid == arg2->volid)
3586 if (arg1->volid > arg2->volid)
3593 /*------------------------------------------------------------------------
3594 * PRIVATE XCompareVolID
3597 * Comparison routine for volume IDs coming from an extended
3601 * a_obj1P : Char ptr to first extended vol info object
3602 * a_obj1P : Char ptr to second extended vol info object
3605 * The value of strcmp() on the volume names within the passed
3606 * objects (i,e., -1, 0, or 1).
3609 * Passed to qsort() as the designated comparison routine.
3613 *------------------------------------------------------------------------*/
3616 XCompareVolID(const void *a_obj1P, const void *a_obj2P)
3617 { /*XCompareVolID */
3619 afs_int32 id1, id2; /*Volume IDs we're comparing */
3621 id1 = ((struct volintXInfo *)(a_obj1P))->volid;
3622 id2 = ((struct volintXInfo *)(a_obj2P))->volid;
3630 } /*XCompareVolID */
3632 /*------------------------------------------------------------------------
3633 * PRIVATE ListVolumes
3636 * Routine used to list volumes, contacting the Volume Server
3637 * directly, bypassing the VLDB.
3640 * as : Ptr to parsed command line arguments.
3643 * 0 Successful operation
3646 * Nothing interesting.
3650 *------------------------------------------------------------------------*/
3653 ListVolumes(struct cmd_syndesc *as, void *arock)
3655 afs_int32 apart, int32list, fast;
3659 volintInfo *oldpntr = NULL;
3663 volintXInfo *xInfoP;
3664 volintXInfo *origxInfoP = NULL; /*Ptr to current/orig extended vol info */
3665 int wantExtendedInfo; /*Do we want extended vol info? */
3668 struct partList dummyPartList;
3676 if (as->parms[3].items)
3678 if (as->parms[4].items)
3682 if (as->parms[2].items)
3688 if (as->parms[5].items) {
3690 * We can't coexist with the fast flag.
3694 "vos: Can't use the -fast and -extended flags together\n");
3699 * We need to turn on ``long'' listings to get the full effect.
3701 wantExtendedInfo = 1;
3704 wantExtendedInfo = 0;
3705 if (as->parms[1].items) {
3706 apart = volutil_GetPartitionID(as->parms[1].items->data);
3708 fprintf(STDERR, "vos: could not interpret partition name '%s'\n",
3709 as->parms[1].items->data);
3712 dummyPartList.partId[0] = apart;
3713 dummyPartList.partFlags[0] = PARTVALID;
3716 aserver = GetServer(as->parms[0].items->data);
3718 fprintf(STDERR, "vos: server '%s' not found in host table\n",
3719 as->parms[0].items->data);
3724 if (!IsPartValid(apart, aserver, &code)) { /*check for validity of the partition */
3726 PrintError("", code);
3729 "vos : partition %s does not exist on the server\n",
3730 as->parms[1].items->data);
3734 code = UV_ListPartitions(aserver, &dummyPartList, &cnt);
3736 PrintDiagnostics("listvol", code);
3740 for (i = 0; i < cnt; i++) {
3741 if (dummyPartList.partFlags[i] & PARTVALID) {
3742 if (wantExtendedInfo)
3744 UV_XListVolumes(aserver, dummyPartList.partId[i], all,
3748 UV_ListVolumes(aserver, dummyPartList.partId[i], all,
3751 PrintDiagnostics("listvol", code);
3754 if (wantExtendedInfo) {
3755 origxInfoP = xInfoP;
3756 base = (char *)xInfoP;
3759 base = (char *)pntr;
3763 if (wantExtendedInfo)
3764 qsort(base, count, sizeof(volintXInfo), XCompareVolName);
3766 qsort(base, count, sizeof(volintInfo), CompareVolName);
3768 if (wantExtendedInfo)
3769 qsort(base, count, sizeof(volintXInfo), XCompareVolID);
3771 qsort(base, count, sizeof(volintInfo), CompareVolID);
3773 MapPartIdIntoName(dummyPartList.partId[i], pname);
3776 "Total number of volumes on server %s partition %s: %lu \n",
3777 as->parms[0].items->data, pname,
3778 (unsigned long)count);
3779 if (wantExtendedInfo) {
3780 if (as->parms[6].items)
3781 XDisplayVolumes2(aserver, dummyPartList.partId[i], origxInfoP,
3782 count, int32list, fast, quiet);
3784 XDisplayVolumes(aserver, dummyPartList.partId[i], origxInfoP,
3785 count, int32list, fast, quiet);
3788 xInfoP = (volintXInfo *) 0;
3790 if (as->parms[6].items)
3791 DisplayVolumes2(aserver, dummyPartList.partId[i], oldpntr,
3794 DisplayVolumes(aserver, dummyPartList.partId[i], oldpntr,
3795 count, int32list, fast, quiet);
3798 pntr = (volintInfo *) 0;
3806 SyncVldb(struct cmd_syndesc *as, void *arock)
3808 afs_int32 pnum = 0, code; /* part name */
3815 if (as->parms[0].items) {
3816 tserver = GetServer(as->parms[0].items->data);
3818 fprintf(STDERR, "vos: host '%s' not found in host table\n",
3819 as->parms[0].items->data);
3824 if (as->parms[1].items) {
3825 pnum = volutil_GetPartitionID(as->parms[1].items->data);
3827 fprintf(STDERR, "vos: could not interpret partition name '%s'\n",
3828 as->parms[1].items->data);
3831 if (!IsPartValid(pnum, tserver, &code)) { /*check for validity of the partition */
3833 PrintError("", code);
3836 "vos: partition %s does not exist on the server\n",
3837 as->parms[1].items->data);
3844 "The -partition option requires a -server option\n");
3849 if (as->parms[3].items) {
3850 flags |= 2; /* don't update */
3853 if (as->parms[2].items) {
3854 /* Synchronize an individual volume */
3855 volname = as->parms[2].items->data;
3856 code = UV_SyncVolume(tserver, pnum, volname, flags);
3860 "Without a -volume option, the -server option is required\n");
3863 code = UV_SyncVldb(tserver, pnum, flags, 0 /*unused */ );
3867 PrintDiagnostics("syncvldb", code);
3871 /* Print a summary of what we did */
3873 fprintf(STDOUT, "VLDB volume %s synchronized", volname);
3875 fprintf(STDOUT, "VLDB synchronized");
3877 fprintf(STDOUT, " with state of server %s", as->parms[0].items->data);
3880 MapPartIdIntoName(pnum, part);
3881 fprintf(STDOUT, " partition %s\n", part);
3883 fprintf(STDOUT, "\n");
3889 SyncServer(struct cmd_syndesc *as, void *arock)
3891 afs_int32 pnum, code; /* part name */
3897 tserver = GetServer(as->parms[0].items->data);
3899 fprintf(STDERR, "vos: host '%s' not found in host table\n",
3900 as->parms[0].items->data);
3903 if (as->parms[1].items) {
3904 pnum = volutil_GetPartitionID(as->parms[1].items->data);
3906 fprintf(STDERR, "vos: could not interpret partition name '%s'\n",
3907 as->parms[1].items->data);
3910 if (!IsPartValid(pnum, tserver, &code)) { /*check for validity of the partition */
3912 PrintError("", code);
3915 "vos : partition %s does not exist on the server\n",
3916 as->parms[1].items->data);
3924 if (as->parms[2].items) {
3925 flags |= 2; /* don't update */
3927 code = UV_SyncServer(tserver, pnum, flags, 0 /*unused */ );
3929 PrintDiagnostics("syncserv", code);
3933 MapPartIdIntoName(pnum, part);
3934 fprintf(STDOUT, "Server %s partition %s synchronized with VLDB\n",
3935 as->parms[0].items->data, part);
3937 fprintf(STDOUT, "Server %s synchronized with VLDB\n",
3938 as->parms[0].items->data);
3944 VolumeInfoCmd(char *name)
3946 struct nvldbentry entry;
3949 /* The vlserver will handle names with the .readonly
3950 * and .backup extension as well as volume ids.
3952 vcode = VLDB_GetEntryByName(name, &entry);
3954 PrintError("", vcode);
3957 MapHostToNetwork(&entry);
3958 EnumerateEntry(&entry);
3960 /* Defect #3027: grubby check to handle locked volume.
3961 * If VLOP_ALLOPERS is set, the entry is locked.
3962 * Leave this routine as is, but put in correct check.
3964 PrintLocked(entry.flags);
3970 VolumeZap(struct cmd_syndesc *as, void *arock)
3972 struct nvldbentry entry;
3973 afs_uint32 volid, zapbackupid = 0, backupid = 0;
3974 afs_int32 code, server, part, err;
3976 if (as->parms[3].items) {
3977 /* force flag is on, use the other version */
3978 return NukeVolume(as);
3981 if (as->parms[4].items) {
3985 volid = vsu_GetVolumeID(as->parms[2].items->data, cstruct, &err);
3988 PrintError("", err);
3990 fprintf(STDERR, "vos: can't find volume '%s'\n",
3991 as->parms[2].items->data);
3994 part = volutil_GetPartitionID(as->parms[1].items->data);
3996 fprintf(STDERR, "vos: could not interpret partition name '%s'\n",
3997 as->parms[1].items->data);
4000 server = GetServer(as->parms[0].items->data);
4002 fprintf(STDERR, "vos: host '%s' not found in host table\n",
4003 as->parms[0].items->data);
4006 if (!IsPartValid(part, server, &code)) { /*check for validity of the partition */
4008 PrintError("", code);
4011 "vos : partition %s does not exist on the server\n",
4012 as->parms[1].items->data);
4015 code = VLDB_GetEntryByID(volid, -1, &entry);
4017 if (volid == entry.volumeId[RWVOL])
4018 backupid = entry.volumeId[BACKVOL];
4020 "Warning: Entry for volume number %lu exists in VLDB (but we're zapping it anyway!)\n",
4021 (unsigned long)volid);
4024 volintInfo *pntr = (volintInfo *) 0;
4027 code = UV_ListOneVolume(server, part, volid, &pntr);
4029 if (volid == pntr->parentID)
4030 backupid = pntr->backupID;
4036 code = UV_VolumeZap(server, part, backupid);
4038 PrintDiagnostics("zap", code);
4041 fprintf(STDOUT, "Backup Volume %lu deleted\n",
4042 (unsigned long)backupid);
4045 code = UV_VolumeZap(server, part, volid);
4047 PrintDiagnostics("zap", code);
4050 fprintf(STDOUT, "Volume %lu deleted\n", (unsigned long)volid);
4056 VolserStatus(struct cmd_syndesc *as, void *arock)
4060 transDebugInfo *pntr, *oldpntr;
4066 server = GetServer(as->parms[0].items->data);
4068 fprintf(STDERR, "vos: host '%s' not found in host table\n",
4069 as->parms[0].items->data);
4072 code = UV_VolserStatus(server, &pntr, &count);
4074 PrintDiagnostics("status", code);
4079 fprintf(STDOUT, "No active transactions on %s\n",
4080 as->parms[0].items->data);
4082 fprintf(STDOUT, "Total transactions: %d\n", count);
4084 for (i = 0; i < count; i++) {
4085 /*print out the relevant info */
4086 fprintf(STDOUT, "--------------------------------------\n");
4087 t = pntr->creationTime;
4088 fprintf(STDOUT, "transaction: %lu created: %s",
4089 (unsigned long)pntr->tid, ctime(&t));
4091 fprintf(STDOUT, "lastActiveTime: %s", ctime(&t));
4092 if (pntr->returnCode) {
4093 fprintf(STDOUT, "returnCode: %lu\n",
4094 (unsigned long)pntr->returnCode);
4097 fprintf(STDOUT, "attachFlags: ");
4098 if ((pntr->iflags & ITOffline) != 0) {
4099 fprintf(STDOUT, "offline ");
4101 if ((pntr->iflags & ITBusy) != 0) {
4102 fprintf(STDOUT, "busy ");
4104 if ((pntr->iflags & ITReadOnly) != 0) {
4105 fprintf(STDOUT, "readonly ");
4107 if ((pntr->iflags & ITCreate) != 0) {
4108 fprintf(STDOUT, "create ");
4110 if ((pntr->iflags & ITCreateVolID) != 0) {
4111 fprintf(STDOUT, "create volid ");
4113 fprintf(STDOUT, "\n");
4116 fprintf(STDOUT, "volumeStatus: ");
4117 if ((pntr->vflags & VTDeleteOnSalvage) != 0) {
4118 fprintf(STDOUT, "deleteOnSalvage ");
4120 if ((pntr->vflags & VTOutOfService) != 0) {
4121 fprintf(STDOUT, "outOfService ");
4123 if ((pntr->vflags & VTDeleted) != 0) {
4124 fprintf(STDOUT, "deleted ");
4126 fprintf(STDOUT, "\n");
4129 fprintf(STDOUT, "transactionFlags: ");
4130 fprintf(STDOUT, "delete\n");
4132 MapPartIdIntoName(pntr->partition, pname);
4133 fprintf(STDOUT, "volume: %lu partition: %s procedure: %s\n",
4134 (unsigned long)pntr->volid, pname, pntr->lastProcName);
4135 if (pntr->callValid) {
4136 t = pntr->lastReceiveTime;
4137 fprintf(STDOUT, "packetRead: %lu lastReceiveTime: %s",
4138 (unsigned long)pntr->readNext, ctime(&t));
4139 t = pntr->lastSendTime;
4140 fprintf(STDOUT, "packetSend: %lu lastSendTime: %s",
4141 (unsigned long)pntr->transmitNext, ctime(&t));
4144 fprintf(STDOUT, "--------------------------------------\n");
4145 fprintf(STDOUT, "\n");
4153 RenameVolume(struct cmd_syndesc *as, void *arock)
4156 struct nvldbentry entry;
4157 struct nvldbentry entry2;
4159 /* Get the entry of the volume to be renamed (-oldname), by name or id. */
4160 code = VLDB_GetEntryByName(as->parms[0].items->data, &entry);
4162 fprintf(STDERR, "vos: Could not find entry for volume %s\n",
4163 as->parms[0].items->data);
4164 PrintError("", code);
4169 * Verify the new name is available before attempting to rename.
4170 * Allow renaming of the same volume in order to complete a
4171 * previously interrupted rename.
4173 code = VLDB_GetEntryByName(as->parms[1].items->data, &entry2);
4174 if (code != 0 && code != VL_NOENT) {
4175 fprintf(STDERR, "vos: Could not check entry for volume %s\n",
4176 as->parms[1].items->data);
4177 PrintError("", code);
4180 if (code == 0 && entry.volumeId[RWVOL] != entry2.volumeId[RWVOL]) {
4181 fprintf(STDERR, "vos: Cannot rename volume %s (%lu) to %s;"
4182 " volume %s (%lu) already exists\n",
4183 as->parms[0].items->data,
4184 (unsigned long)entry.volumeId[RWVOL],
4185 as->parms[1].items->data,
4186 as->parms[1].items->data,
4187 (unsigned long)entry2.volumeId[RWVOL]);
4190 if (!VolNameOK(as->parms[0].items->data)) {
4192 "Illegal volume name %s, should not end in .readonly or .backup\n",
4193 as->parms[0].items->data);
4196 if (!ISNAMEVALID(as->parms[1].items->data)) {
4198 "vos: the new volume name %s exceeds the size limit of %d\n",
4199 as->parms[1].items->data, VOLSER_OLDMAXVOLNAME - 10);
4202 if (!VolNameOK(as->parms[1].items->data)) {
4204 "Illegal volume name %s, should not end in .readonly or .backup\n",
4205 as->parms[1].items->data);
4208 if (IsNumeric(as->parms[1].items->data)) {
4209 fprintf(STDERR, "Illegal volume name %s, should not be a number\n",
4210 as->parms[1].items->data);
4213 MapHostToNetwork(&entry);
4215 UV_RenameVolume(&entry, as->parms[0].items->data,
4216 as->parms[1].items->data);
4218 PrintDiagnostics("rename", code);
4221 fprintf(STDOUT, "Renamed volume %s to %s\n", as->parms[0].items->data,
4222 as->parms[1].items->data);
4227 GetVolumeInfo(afs_uint32 volid, afs_uint32 *server, afs_int32 *part, afs_int32 *voltype,
4228 struct nvldbentry *rentry)
4233 vcode = VLDB_GetEntryByID(volid, -1, rentry);
4236 "Could not fetch the entry for volume %lu from VLDB \n",
4237 (unsigned long)volid);
4238 PrintError("", vcode);
4241 MapHostToNetwork(rentry);
4242 if (volid == rentry->volumeId[ROVOL]) {
4244 for (i = 0; i < rentry->nServers; i++) {
4245 if ((index == -1) && (rentry->serverFlags[i] & VLSF_ROVOL)
4246 && !(rentry->serverFlags[i] & VLSF_DONTUSE))
4251 "RO volume is not found in VLDB entry for volume %lu\n",
4252 (unsigned long)volid);
4256 *server = rentry->serverNumber[index];
4257 *part = rentry->serverPartition[index];
4261 index = Lp_GetRwIndex(rentry);
4264 "RW Volume is not found in VLDB entry for volume %lu\n",
4265 (unsigned long)volid);
4268 if (volid == rentry->volumeId[RWVOL]) {
4270 *server = rentry->serverNumber[index];
4271 *part = rentry->serverPartition[index];
4274 if (volid == rentry->volumeId[BACKVOL]) {
4276 *server = rentry->serverNumber[index];
4277 *part = rentry->serverPartition[index];
4281 "unexpected volume type for volume %lu\n",
4282 (unsigned long)volid);
4287 DeleteEntry(struct cmd_syndesc *as, void *arock)
4289 afs_int32 apart = 0;
4292 struct VldbListByAttributes attributes;
4293 nbulkentries arrayEntries;
4294 struct nvldbentry *vllist;
4295 struct cmd_item *itp;
4298 char prefix[VOLSER_MAXVOLNAME + 1];
4300 afs_int32 totalBack = 0, totalFail = 0, err;
4302 if (as->parms[0].items) { /* -id */
4303 if (as->parms[1].items || as->parms[2].items || as->parms[3].items) {
4305 "You cannot use -server, -partition, or -prefix with the -id argument\n");
4308 for (itp = as->parms[0].items; itp; itp = itp->next) {
4309 avolid = vsu_GetVolumeID(itp->data, cstruct, &err);
4312 PrintError("", err);
4314 fprintf(STDERR, "vos: can't find volume '%s'\n",
4318 if (as->parms[4].items || as->parms[5].items) {
4319 /* -noexecute (hidden) or -dryrun */
4320 fprintf(STDOUT, "Would have deleted VLDB entry for %s \n",
4325 vcode = ubik_VL_DeleteEntry(cstruct, 0, avolid, RWVOL);
4327 fprintf(STDERR, "Could not delete entry for volume %s\n",
4330 "You must specify a RW volume name or ID "
4331 "(the entire VLDB entry will be deleted)\n");
4332 PrintError("", vcode);
4338 fprintf(STDOUT, "Deleted %d VLDB entries\n", totalBack);
4342 if (!as->parms[1].items && !as->parms[2].items && !as->parms[3].items) {
4343 fprintf(STDERR, "You must specify an option\n");
4347 /* Zero out search attributes */
4348 memset(&attributes, 0, sizeof(struct VldbListByAttributes));
4350 if (as->parms[1].items) { /* -prefix */
4351 strncpy(prefix, as->parms[1].items->data, VOLSER_MAXVOLNAME);
4353 if (!as->parms[2].items && !as->parms[3].items) { /* a single entry only */
4355 "You must provide -server with the -prefix argument\n");
4360 if (as->parms[2].items) { /* -server */
4362 aserver = GetServer(as->parms[2].items->data);
4364 fprintf(STDERR, "vos: server '%s' not found in host table\n",
4365 as->parms[2].items->data);
4368 attributes.server = ntohl(aserver);
4369 attributes.Mask |= VLLIST_SERVER;
4372 if (as->parms[3].items) { /* -partition */
4373 if (!as->parms[2].items) {
4375 "You must provide -server with the -partition argument\n");
4378 apart = volutil_GetPartitionID(as->parms[3].items->data);
4380 fprintf(STDERR, "vos: could not interpret partition name '%s'\n",
4381 as->parms[3].items->data);
4384 attributes.partition = apart;
4385 attributes.Mask |= VLLIST_PARTITION;
4388 /* Print status line of what we are doing */
4389 fprintf(STDOUT, "Deleting VLDB entries for ");
4390 if (as->parms[2].items) {
4391 fprintf(STDOUT, "server %s ", as->parms[2].items->data);
4393 if (as->parms[3].items) {
4395 MapPartIdIntoName(apart, pname);
4396 fprintf(STDOUT, "partition %s ", pname);
4399 fprintf(STDOUT, "which are prefixed with %s ", prefix);
4401 fprintf(STDOUT, "\n");
4404 /* Get all the VLDB entries on a server and/or partition */
4405 memset(&arrayEntries, 0, sizeof(arrayEntries));
4406 vcode = VLDB_ListAttributes(&attributes, &nentries, &arrayEntries);
4408 fprintf(STDERR, "Could not access the VLDB for attributes\n");
4409 PrintError("", vcode);
4413 /* Process each entry */
4414 for (j = 0; j < nentries; j++) {
4415 vllist = &arrayEntries.nbulkentries_val[j];
4417 /* It only deletes the RW volumes */
4418 if (strncmp(vllist->name, prefix, strlen(prefix))) {
4421 "Omitting to delete %s due to prefix %s mismatch\n",
4422 vllist->name, prefix);
4429 if (as->parms[4].items || as->parms[5].items) {
4430 /* -noexecute (hidden) or -dryrun */
4431 fprintf(STDOUT, "Would have deleted VLDB entry for %s \n",
4437 /* Only matches the RW volume name */
4438 avolid = vllist->volumeId[RWVOL];
4439 vcode = ubik_VL_DeleteEntry(cstruct, 0, avolid, RWVOL);
4441 fprintf(STDOUT, "Could not delete VLDB entry for %s\n",
4444 PrintError("", vcode);
4449 fprintf(STDOUT, "Deleted VLDB entry for %s \n", vllist->name);
4454 fprintf(STDOUT, "----------------------\n");
4456 "Total VLDB entries deleted: %lu; failed to delete: %lu\n",
4457 (unsigned long)totalBack, (unsigned long)totalFail);
4459 xdr_free((xdrproc_t) xdr_nbulkentries, &arrayEntries);
4465 CompareVldbEntryByName(const void *p1, const void *p2)
4467 struct nvldbentry *arg1, *arg2;
4469 arg1 = (struct nvldbentry *)p1;
4470 arg2 = (struct nvldbentry *)p2;
4471 return (strcmp(arg1->name, arg2->name));
4475 static int CompareVldbEntry(char *p1, char *p2)
4477 struct nvldbentry *arg1,*arg2;
4480 char comp1[100],comp2[100];
4481 char temp1[20],temp2[20];
4483 arg1 = (struct nvldbentry *)p1;
4484 arg2 = (struct nvldbentry *)p2;
4488 for(i = 0; i < arg1->nServers; i++)
4489 if(arg1->serverFlags[i] & VLSF_RWVOL) pos1 = i;
4490 for(i = 0; i < arg2->nServers; i++)
4491 if(arg2->serverFlags[i] & VLSF_RWVOL) pos2 = i;
4492 if(pos1 == -1 || pos2 == -1){
4496 sprintf(comp1,"%10u",arg1->serverNumber[pos1]);
4497 sprintf(comp2,"%10u",arg2->serverNumber[pos2]);
4498 sprintf(temp1,"%10u",arg1->serverPartition[pos1]);
4499 sprintf(temp2,"%10u",arg2->serverPartition[pos2]);
4500 strcat(comp1,temp1);
4501 strcat(comp2,temp2);
4502 strcat(comp1,arg1->name);
4503 strcat(comp1,arg2->name);
4504 return(strcmp(comp1,comp2));
4510 ListVLDB(struct cmd_syndesc *as, void *arock)
4515 struct VldbListByAttributes attributes;
4516 nbulkentries arrayEntries;
4517 struct nvldbentry *vllist, *tarray = 0, *ttarray;
4518 afs_int32 centries, nentries = 0;
4519 afs_int32 tarraysize = 0;
4520 afs_int32 parraysize;
4523 int quiet, sort, lock;
4524 afs_int32 thisindex, nextindex;
4528 memset(&attributes, 0, sizeof(attributes));
4529 lock = (as->parms[3].items ? 1 : 0); /* -lock flag */
4530 quiet = (as->parms[4].items ? 1 : 0); /* -quit flag */
4531 sort = (as->parms[5].items ? 0 : 1); /* -nosort flag */
4533 /* If the volume name is given, Use VolumeInfoCmd to look it up
4534 * and not ListAttributes.
4536 if (as->parms[0].items) {
4539 "vos: illegal use of '-locked' switch, need to specify server and/or partition\n");
4542 code = VolumeInfoCmd(as->parms[0].items->data);
4544 PrintError("", code);
4550 /* Server specified */
4551 if (as->parms[1].items) {
4554 aserver = GetServer(as->parms[1].items->data);
4556 fprintf(STDERR, "vos: server '%s' not found in host table\n",
4557 as->parms[1].items->data);
4560 attributes.server = ntohl(aserver);
4561 attributes.Mask |= VLLIST_SERVER;
4564 /* Partition specified */
4565 if (as->parms[2].items) {
4566 apart = volutil_GetPartitionID(as->parms[2].items->data);
4568 fprintf(STDERR, "vos: could not interpret partition name '%s'\n",
4569 as->parms[2].items->data);
4572 attributes.partition = apart;
4573 attributes.Mask |= VLLIST_PARTITION;
4577 attributes.Mask |= VLLIST_FLAG;
4578 attributes.flag = VLOP_ALLOPERS;
4581 /* Print header information */
4583 MapPartIdIntoName(apart, pname);
4584 fprintf(STDOUT, "VLDB entries for %s %s%s%s %s\n",
4585 (as->parms[1].items ? "server" : "all"),
4586 (as->parms[1].items ? as->parms[1].items->data : "servers"),
4587 (as->parms[2].items ? " partition " : ""),
4588 (as->parms[2].items ? pname : ""),
4589 (lock ? "which are locked:" : ""));
4592 for (thisindex = 0; (thisindex != -1); thisindex = nextindex) {
4593 memset(&arrayEntries, 0, sizeof(arrayEntries));
4598 VLDB_ListAttributesN2(&attributes, 0, thisindex, ¢ries,
4599 &arrayEntries, &nextindex);
4600 if (vcode == RXGEN_OPCODE) {
4601 /* Vlserver not running with ListAttributesN2. Fall back */
4603 VLDB_ListAttributes(&attributes, ¢ries, &arrayEntries);
4607 fprintf(STDERR, "Could not access the VLDB for attributes\n");
4608 PrintError("", vcode);
4611 nentries += centries;
4613 /* We don't sort, so just print the entries now */
4615 for (j = 0; j < centries; j++) { /* process each entry */
4616 vllist = &arrayEntries.nbulkentries_val[j];
4617 MapHostToNetwork(vllist);
4618 EnumerateEntry(vllist);
4620 PrintLocked(vllist->flags);
4624 /* So we sort. First we must collect all the entries and keep
4627 else if (centries > 0) {
4629 /* malloc the first bulk entries array */
4630 tarraysize = centries * sizeof(struct nvldbentry);
4631 tarray = malloc(tarraysize);
4634 "Could not allocate enough space for the VLDB entries\n");
4637 memcpy((char*)tarray, arrayEntries.nbulkentries_val, tarraysize);
4639 /* Grow the tarray to keep the extra entries */
4640 parraysize = (centries * sizeof(struct nvldbentry));
4641 ttarray = realloc(tarray, tarraysize + parraysize);
4644 "Could not allocate enough space for the VLDB entries\n");
4650 memcpy(((char *)tarray) + tarraysize,
4651 (char *)arrayEntries.nbulkentries_val, parraysize);
4652 tarraysize += parraysize;
4656 /* Free the bulk array */
4657 xdr_free((xdrproc_t) xdr_nbulkentries, &arrayEntries);
4660 /* Here is where we now sort all the entries and print them */
4661 if (sort && (nentries > 0)) {
4662 qsort((char *)tarray, nentries, sizeof(struct nvldbentry),
4663 CompareVldbEntryByName);
4664 for (vllist = tarray, j = 0; j < nentries; j++, vllist++) {
4665 MapHostToNetwork(vllist);
4666 EnumerateEntry(vllist);
4668 PrintLocked(vllist->flags);
4674 fprintf(STDOUT, "\nTotal entries: %lu\n", (unsigned long)nentries);
4681 BackSys(struct cmd_syndesc *as, void *arock)
4684 afs_int32 apart = 0;
4685 afs_uint32 aserver = 0, aserver1;
4686 afs_int32 code, apart1;
4688 struct VldbListByAttributes attributes;
4689 nbulkentries arrayEntries;
4690 struct nvldbentry *vllist;
4694 int seenprefix, seenxprefix, exclude, ex, exp, noaction;
4695 afs_int32 totalBack = 0;
4696 afs_int32 totalFail = 0;
4700 struct cmd_item *ti;
4702 #ifndef HAVE_POSIX_REGEX
4706 memset(&attributes, 0, sizeof(struct VldbListByAttributes));
4707 attributes.Mask = 0;
4709 seenprefix = (as->parms[0].items ? 1 : 0);
4710 exclude = (as->parms[3].items ? 1 : 0);
4711 seenxprefix = (as->parms[4].items ? 1 : 0);
4712 noaction = (as->parms[5].items ? 1 : 0);
4714 if (as->parms[1].items) { /* -server */
4715 aserver = GetServer(as->parms[1].items->data);
4717 fprintf(STDERR, "vos: server '%s' not found in host table\n",
4718 as->parms[1].items->data);
4721 attributes.server = ntohl(aserver);
4722 attributes.Mask |= VLLIST_SERVER;
4725 if (as->parms[2].items) { /* -partition */
4726 apart = volutil_GetPartitionID(as->parms[2].items->data);
4728 fprintf(STDERR, "vos: could not interpret partition name '%s'\n",
4729 as->parms[2].items->data);
4732 attributes.partition = apart;
4733 attributes.Mask |= VLLIST_PARTITION;
4736 /* Check to make sure the prefix and xprefix expressions compile ok */
4738 for (ti = as->parms[0].items; ti; ti = ti->next) {
4739 if (strncmp(ti->data, "^", 1) == 0) {
4740 #ifdef HAVE_POSIX_REGEX
4744 code = regcomp(&re, ti->data, REG_NOSUB);
4746 regerror(code, &re, errbuf, sizeof errbuf);
4748 "Unrecognizable -prefix regular expression: '%s': %s\n",
4754 ccode = (char *)re_comp(ti->data);
4757 "Unrecognizable -prefix regular expression: '%s': %s\n",
4766 for (ti = as->parms[4].items; ti; ti = ti->next) {
4767 if (strncmp(ti->data, "^", 1) == 0) {
4768 #ifdef HAVE_POSIX_REGEX
4772 code = regcomp(&re, ti->data, REG_NOSUB);
4774 regerror(code, &re, errbuf, sizeof errbuf);
4776 "Unrecognizable -xprefix regular expression: '%s': %s\n",
4782 ccode = (char *)re_comp(ti->data);
4785 "Unrecognizable -xprefix regular expression: '%s': %s\n",
4794 memset(&arrayEntries, 0, sizeof(arrayEntries)); /* initialize to hint the stub to alloc space */
4795 vcode = VLDB_ListAttributes(&attributes, &nentries, &arrayEntries);
4797 fprintf(STDERR, "Could not access the VLDB for attributes\n");
4798 PrintError("", vcode);
4802 if (as->parms[1].items || as->parms[2].items || verbose) {
4803 fprintf(STDOUT, "%s up volumes",
4804 (noaction ? "Would have backed" : "Backing"));
4806 if (as->parms[1].items) {
4807 fprintf(STDOUT, " on server %s", as->parms[1].items->data);
4808 } else if (as->parms[2].items) {
4809 fprintf(STDOUT, " for all servers");
4812 if (as->parms[2].items) {
4813 MapPartIdIntoName(apart, pname);
4814 fprintf(STDOUT, " partition %s", pname);
4817 if (seenprefix || (!seenprefix && seenxprefix)) {
4818 ti = (seenprefix ? as->parms[0].items : as->parms[4].items);
4819 ex = (seenprefix ? exclude : !exclude);
4820 exp = (strncmp(ti->data, "^", 1) == 0);
4821 fprintf(STDOUT, " which %smatch %s '%s'", (ex ? "do not " : ""),
4822 (exp ? "expression" : "prefix"), ti->data);
4823 for (ti = ti->next; ti; ti = ti->next) {
4824 exp = (strncmp(ti->data, "^", 1) == 0);
4825 printf(" %sor %s '%s'", (ex ? "n" : ""),
4826 (exp ? "expression" : "prefix"), ti->data);
4830 if (seenprefix && seenxprefix) {
4831 ti = as->parms[4].items;
4832 exp = (strncmp(ti->data, "^", 1) == 0);
4833 fprintf(STDOUT, " %swhich match %s '%s'",
4834 (exclude ? "adding those " : "removing those "),
4835 (exp ? "expression" : "prefix"), ti->data);
4836 for (ti = ti->next; ti; ti = ti->next) {
4837 exp = (strncmp(ti->data, "^", 1) == 0);
4838 printf(" or %s '%s'", (exp ? "expression" : "prefix"),
4842 fprintf(STDOUT, " .. ");
4844 fprintf(STDOUT, "\n");
4848 for (j = 0; j < nentries; j++) { /* process each vldb entry */
4849 vllist = &arrayEntries.nbulkentries_val[j];
4852 for (ti = as->parms[0].items; ti; ti = ti->next) {
4853 if (strncmp(ti->data, "^", 1) == 0) {
4854 #ifdef HAVE_POSIX_REGEX
4858 /* XXX -- should just do the compile once! */
4859 code = regcomp(&re, ti->data, REG_NOSUB);
4861 regerror(code, &re, errbuf, sizeof errbuf);
4863 "Error in -prefix regular expression: '%s': %s\n",
4867 match = (regexec(&re, vllist->name, 0, NULL, 0) == 0);
4870 ccode = (char *)re_comp(ti->data);
4873 "Error in -prefix regular expression: '%s': %s\n",
4877 match = (re_exec(vllist->name) == 1);
4881 (strncmp(vllist->name, ti->data, strlen(ti->data)) ==
4891 /* Without the -exclude flag: If it matches the prefix, then
4892 * check if we want to exclude any from xprefix.
4893 * With the -exclude flag: If it matches the prefix, then
4894 * check if we want to add any from xprefix.
4896 if (match && seenxprefix) {
4897 for (ti = as->parms[4].items; ti; ti = ti->next) {
4898 if (strncmp(ti->data, "^", 1) == 0) {
4899 #ifdef HAVE_POSIX_REGEX
4903 /* XXX -- should just do the compile once! */
4904 code = regcomp(&re, ti->data, REG_NOSUB);
4906 regerror(code, &re, errbuf, sizeof errbuf);
4908 "Error in -xprefix regular expression: '%s': %s\n",
4912 if (regexec(&re, vllist->name, 0, NULL, 0) == 0)
4916 ccode = (char *)re_comp(ti->data);
4919 "Error in -xprefix regular expression: '%s': %s\n",
4923 if (re_exec(vllist->name) == 1) {
4929 if (strncmp(vllist->name, ti->data, strlen(ti->data)) ==
4939 match = !match; /* -exclude will reverse the match */
4941 continue; /* Skip if no match */
4943 /* Print list of volumes to backup */
4945 fprintf(STDOUT, " %s\n", vllist->name);
4949 if (!(vllist->flags & VLF_RWEXISTS)) {
4952 "Omitting to backup %s since RW volume does not exist \n",
4954 fprintf(STDOUT, "\n");
4960 avolid = vllist->volumeId[RWVOL];
4961 MapHostToNetwork(vllist);
4962 GetServerAndPart(vllist, RWVOL, &aserver1, &apart1, &previdx);
4963 if (aserver1 == -1 || apart1 == -1) {
4964 fprintf(STDOUT, "could not backup %s, invalid VLDB entry\n",
4970 same = VLDB_IsSameAddrs(aserver, aserver1, &error);
4973 "Failed to get info about server's %d address(es) from vlserver (err=%d); aborting call!\n",
4979 if ((aserver && !same) || (apart && (apart != apart1))) {
4982 "Omitting to backup %s since the RW is in a different location\n",
4988 time_t now = time(0);
4989 fprintf(STDOUT, "Creating backup volume for %s on %s",
4990 vllist->name, ctime(&now));
4994 code = UV_BackupVolume(aserver1, apart1, avolid);
4996 fprintf(STDOUT, "Could not backup %s\n", vllist->name);
5002 fprintf(STDOUT, "\n");
5004 } /* process each vldb entry */
5005 fprintf(STDOUT, "done\n");
5006 fprintf(STDOUT, "Total volumes backed up: %lu; failed to backup: %lu\n",
5007 (unsigned long)totalBack, (unsigned long)totalFail);
5009 xdr_free((xdrproc_t) xdr_nbulkentries, &arrayEntries);
5014 UnlockVLDB(struct cmd_syndesc *as, void *arock)
5017 afs_uint32 aserver = 0;
5020 struct VldbListByAttributes attributes;
5021 nbulkentries arrayEntries;
5022 struct nvldbentry *vllist;
5031 memset(&attributes, 0, sizeof(attributes));
5033 if (as->parms[0].items) { /* server specified */
5034 aserver = GetServer(as->parms[0].items->data);
5036 fprintf(STDERR, "vos: server '%s' not found in host table\n",
5037 as->parms[0].items->data);
5040 attributes.server = ntohl(aserver);
5041 attributes.Mask |= VLLIST_SERVER;
5043 if (as->parms[1].items) { /* partition specified */
5044 apart = volutil_GetPartitionID(as->parms[1].items->data);
5046 fprintf(STDERR, "vos: could not interpret partition name '%s'\n",
5047 as->parms[1].items->data);
5050 if (!IsPartValid(apart, aserver, &code)) { /*check for validity of the partition */
5052 PrintError("", code);
5055 "vos : partition %s does not exist on the server\n",
5056 as->parms[1].items->data);
5059 attributes.partition = apart;
5060 attributes.Mask |= VLLIST_PARTITION;
5062 attributes.flag = VLOP_ALLOPERS;
5063 attributes.Mask |= VLLIST_FLAG;
5064 memset(&arrayEntries, 0, sizeof(arrayEntries)); /*initialize to hint the stub to alloc space */
5065 vcode = VLDB_ListAttributes(&attributes, &nentries, &arrayEntries);
5067 fprintf(STDERR, "Could not access the VLDB for attributes\n");
5068 PrintError("", vcode);
5071 for (j = 0; j < nentries; j++) { /* process each entry */
5072 vllist = &arrayEntries.nbulkentries_val[j];
5073 volid = vllist->volumeId[RWVOL];
5075 ubik_VL_ReleaseLock(cstruct, 0, volid, -1,
5076 LOCKREL_OPCODE | LOCKREL_AFSID |
5079 fprintf(STDERR, "Could not unlock entry for volume %s\n",
5081 PrintError("", vcode);
5086 MapPartIdIntoName(apart, pname);
5089 "Could not lock %lu VLDB entries of %lu locked entries\n",
5090 (unsigned long)totalE, (unsigned long)nentries);
5092 if (as->parms[0].items) {
5094 "Unlocked all the VLDB entries for volumes on server %s ",
5095 as->parms[0].items->data);
5096 if (as->parms[1].items) {
5097 MapPartIdIntoName(apart, pname);
5098 fprintf(STDOUT, "partition %s\n", pname);
5100 fprintf(STDOUT, "\n");
5102 } else if (as->parms[1].items) {
5103 MapPartIdIntoName(apart, pname);
5105 "Unlocked all the VLDB entries for volumes on partition %s on all servers\n",
5110 xdr_free((xdrproc_t) xdr_nbulkentries, &arrayEntries);
5115 PrintInt64Size(afs_uint64 in)
5119 static char output[16];
5121 SplitInt64(in,hi,lo);
5125 } else if (!(hi & 0xFFFFFC00)) {
5127 lo = (hi << 22) | (lo >> 10);
5128 } else if (!(hi & 0xFFF00000)) {
5130 lo = (hi << 12) | (lo >> 20);
5131 } else if (!(hi & 0xC0000000)) {
5133 lo = (hi << 2) | (lo >> 30);
5138 sprintf(output,"%u %s", lo, units);
5143 PartitionInfo(struct cmd_syndesc *as, void *arock)
5149 struct diskPartition64 partition;
5150 struct partList dummyPartList;
5152 int printSummary=0, sumPartitions=0;
5153 afs_uint64 sumFree, sumStorage;
5156 ZeroInt64(sumStorage);
5158 aserver = GetServer(as->parms[0].items->data);
5160 fprintf(STDERR, "vos: server '%s' not found in host table\n",
5161 as->parms[0].items->data);
5164 if (as->parms[1].items) {
5165 apart = volutil_GetPartitionID(as->parms[1].items->data);
5167 fprintf(STDERR, "vos: could not interpret partition name '%s'\n",
5168 as->parms[1].items->data);
5171 dummyPartList.partId[0] = apart;
5172 dummyPartList.partFlags[0] = PARTVALID;
5175 if (as->parms[2].items) {
5179 if (!IsPartValid(apart, aserver, &code)) { /*check for validity of the partition */
5181 PrintError("", code);
5184 "vos : partition %s does not exist on the server\n",
5185 as->parms[1].items->data);
5189 code = UV_ListPartitions(aserver, &dummyPartList, &cnt);
5191 PrintDiagnostics("listpart", code);
5195 for (i = 0; i < cnt; i++) {
5196 if (dummyPartList.partFlags[i] & PARTVALID) {
5197 MapPartIdIntoName(dummyPartList.partId[i], pname);
5198 code = UV_PartitionInfo64(aserver, pname, &partition);
5200 fprintf(STDERR, "Could not get information on partition %s\n",
5202 PrintError("", code);
5206 "Free space on partition %s: %" AFS_INT64_FMT " K blocks out of total %" AFS_INT64_FMT "\n",
5207 pname, partition.free, partition.minFree);
5209 AddUInt64(sumFree,partition.free,&sumFree);
5210 AddUInt64(sumStorage,partition.minFree,&sumStorage);
5215 "Summary: %s free out of ",
5216 PrintInt64Size(sumFree));
5218 "%s on %d partitions\n",
5219 PrintInt64Size(sumStorage),
5226 ChangeAddr(struct cmd_syndesc *as, void *arock)
5228 afs_int32 ip1, ip2, vcode;
5233 ip1 = GetServerNoresolve(as->parms[0].items->data);
5235 ip1 = GetServer(as->parms[0].items->data);
5237 fprintf(STDERR, "vos: invalid host address\n");
5241 if ((as->parms[1].items && as->parms[2].items)
5242 || (!as->parms[1].items && !as->parms[2].items)) {
5244 "vos: Must specify either '-newaddr <addr>' or '-remove' flag\n");
5248 if (as->parms[3].items) {
5252 if (as->parms[1].items) {
5254 ip2 = GetServerNoresolve(as->parms[1].items->data);
5256 ip2 = GetServer(as->parms[1].items->data);
5258 fprintf(STDERR, "vos: invalid host address\n");
5262 /* Play a trick here. If we are removing an address, ip1 will be -1
5263 * and ip2 will be the original address. This switch prevents an
5264 * older revision vlserver from removing the IP address.
5271 if (!remove && !force) {
5272 afs_int32 m_nentries;
5274 afs_int32 m_uniq = 0;
5276 ListAddrByAttributes m_attrs;
5277 struct uuid_fmtbuf buffer;
5279 memset(&m_attrs, 0, sizeof(m_attrs));
5280 memset(&m_uuid, 0, sizeof(m_uuid));
5281 memset(&m_addrs, 0, sizeof(m_addrs));
5283 m_attrs.Mask = VLADDR_IPADDR;
5284 m_attrs.ipaddr = ntohl(ip1); /* -oldaddr */
5287 ubik_VL_GetAddrsU(cstruct, UBIK_CALL_NEW, &m_attrs, &m_uuid,
5288 &m_uniq, &m_nentries, &m_addrs);
5289 xdr_free((xdrproc_t) xdr_bulkaddrs, &m_addrs);
5291 case 0: /* mh entry detected */
5292 afsUUID_to_string(&m_uuid, &buffer);
5293 fprintf(STDERR, "vos: Refusing to change address in multi-homed server entry.\n");
5294 fprintf(STDERR, " -oldaddr address is registered to file server UUID %s\n",
5296 fprintf(STDERR, " Please restart the file server or use vos setaddrs.\n");
5301 fprintf(STDERR, "vos: could not list the server addresses\n");
5302 PrintError("", vcode);
5307 vcode = ubik_VL_ChangeAddr(cstruct, UBIK_CALL_NEW, ntohl(ip1), ntohl(ip2));
5309 char hoststr1[16], hoststr2[16];
5311 afs_inet_ntoa_r(ip2, hoststr2);
5312 fprintf(STDERR, "Could not remove server %s from the VLDB\n",
5314 if (vcode == VL_NOENT) {
5316 "vlserver does not support the remove flag or ");
5319 afs_inet_ntoa_r(ip1, hoststr1);
5320 afs_inet_ntoa_r(ip2, hoststr2);
5321 fprintf(STDERR, "Could not change server %s to server %s\n",
5322 hoststr1, hoststr2);
5324 PrintError("", vcode);
5329 fprintf(STDOUT, "Removed server %s from the VLDB\n",
5330 as->parms[0].items->data);
5332 fprintf(STDOUT, "Changed server %s to server %s\n",
5333 as->parms[0].items->data, as->parms[1].items->data);
5339 print_addrs(const bulkaddrs * addrs, afsUUID * m_uuid, int nentries,
5344 struct uuid_fmtbuf buf;
5347 afsUUID_to_string(m_uuid, &buf);
5348 printf("UUID: %s\n", buf.buffer);
5351 /* print out the list of all the server */
5352 for (i = 0; i < addrs->bulkaddrs_len; i++) {
5353 addr = htonl(addrs->bulkaddrs_val[i]);
5356 printf("%s\n", afs_inet_ntoa_r(addr, hoststr));
5358 printf("%s\n", hostutil_GetNameByINet(addr));
5369 ListAddrs(struct cmd_syndesc *as, void *arock)
5371 afs_int32 vcode, m_uniq=0;
5372 afs_int32 i, printuuid = 0;
5373 struct VLCallBack vlcb;
5376 ListAddrByAttributes m_attrs;
5377 afsUUID m_uuid, askuuid;
5378 afs_int32 m_nentries;
5380 if (as->parms[0].items && as->parms[1].items) {
5381 fprintf(STDERR, "vos: Can't use the -uuid and -host flags together\n");
5385 memset(&m_attrs, 0, sizeof(struct ListAddrByAttributes));
5386 memset(&askuuid, 0, sizeof(afsUUID));
5387 if (as->parms[0].items) {
5389 if (afsUUID_from_string(as->parms[0].items->data, &askuuid) < 0) {
5390 fprintf(STDERR, "vos: invalid UUID '%s'\n",
5391 as->parms[0].items->data);
5394 m_attrs.Mask = VLADDR_UUID;
5395 m_attrs.uuid = askuuid;
5396 } else if (as->parms[1].items) {
5400 he = hostutil_GetHostByName((char *)as->parms[1].items->data);
5402 fprintf(STDERR, "vos: Can't get host info for '%s'\n",
5403 as->parms[1].items->data);
5406 memcpy(&saddr, he->h_addr, 4);
5407 m_attrs.Mask = VLADDR_IPADDR;
5408 m_attrs.ipaddr = ntohl(saddr);
5411 m_attrs.Mask = VLADDR_INDEX;
5414 if (as->parms[2].items) {
5418 memset(&m_addrs, 0, sizeof(bulkaddrs));
5419 memset(&vlcb, 0, sizeof(struct VLCallBack));
5422 ubik_VL_GetAddrs(cstruct, UBIK_CALL_NEW, 0, 0, &vlcb, &nentries,
5425 fprintf(STDERR, "vos: could not list the server addresses\n");
5426 PrintError("", vcode);
5430 for (i = 1, m_nentries = 0; nentries; i++) {
5433 xdr_free((xdrproc_t)xdr_bulkaddrs, &m_addrs); /* reset addr list */
5435 ubik_VL_GetAddrsU(cstruct, UBIK_CALL_NEW, &m_attrs, &m_uuid,
5436 &m_uniq, &m_nentries, &m_addrs);
5438 case 0: /* success */
5439 print_addrs(&m_addrs, &m_uuid, m_nentries, printuuid);
5444 if (m_attrs.Mask == VLADDR_UUID) {
5445 fprintf(STDERR, "vos: no entry for UUID '%s' found in VLDB\n",
5446 as->parms[0].items->data);
5448 } else if (m_attrs.Mask == VLADDR_IPADDR) {
5449 fprintf(STDERR, "vos: no entry for host '%s' [0x%08x] found in VLDB\n",
5450 as->parms[1].items->data, m_attrs.ipaddr);
5455 case VL_INDEXERANGE:
5456 vcode = 0; /* not an error, just means we're done */
5459 default: /* any other error */
5460 fprintf(STDERR, "vos: could not list the server addresses\n");
5461 PrintError("", vcode);
5465 /* if -uuid or -host, only list one response */
5466 if (as->parms[1].items || as->parms[0].items)
5471 xdr_free((xdrproc_t)xdr_bulkaddrs, &m_addrs);
5477 SetAddrs(struct cmd_syndesc *as, void *arock)
5482 afs_uint32 FS_HostAddrs_HBO[ADDRSPERSITE];
5484 memset(&m_addrs, 0, sizeof(bulkaddrs));
5485 memset(&askuuid, 0, sizeof(afsUUID));
5486 if (as->parms[0].items) {
5488 if (afsUUID_from_string(as->parms[0].items->data, &askuuid) < 0) {
5489 fprintf(STDERR, "vos: invalid UUID '%s'\n",
5490 as->parms[0].items->data);
5494 if (as->parms[1].items) {
5496 struct cmd_item *ti;
5500 for (ti = as->parms[1].items; ti && i < ADDRSPERSITE; ti = ti->next) {
5503 saddr = GetServerNoresolve(ti->data);
5505 saddr = GetServer(ti->data);
5508 fprintf(STDERR, "vos: Can't get host info for '%s'\n",
5512 /* Convert it to host byte order */
5513 FS_HostAddrs_HBO[i] = ntohl(saddr);
5516 m_addrs.bulkaddrs_len = i;
5517 m_addrs.bulkaddrs_val = FS_HostAddrs_HBO;
5520 vcode = ubik_VL_RegisterAddrs(cstruct, 0, &askuuid, 0, &m_addrs);
5523 if (vcode == VL_MULTIPADDR) {
5524 fprintf(STDERR, "vos: VL_RegisterAddrs rpc failed; The IP address exists on a different server; repair it\n");
5525 } else if (vcode == RXGEN_OPCODE) {
5526 fprintf(STDERR, "vlserver doesn't support VL_RegisterAddrs rpc; ignored\n");
5528 fprintf(STDERR, "vos: VL_RegisterAddrs rpc failed\n");
5530 PrintError("", vcode);
5534 fprintf(STDOUT, "vos: Changed UUID with addresses:\n");
5535 print_addrs(&m_addrs, &askuuid, m_addrs.bulkaddrs_len, 1);
5541 RemoveAddrs(struct cmd_syndesc *as, void *arock)
5544 ListAddrByAttributes attrs;
5547 afs_int32 nentries = 0;
5552 memset(&attrs, 0, sizeof(ListAddrByAttributes));
5553 memset(&addrs, 0, sizeof(bulkaddrs));
5554 memset(&uuid, 0, sizeof(afsUUID));
5555 attrs.Mask = VLADDR_UUID;
5557 if (as->parms[0].items) { /* -uuid */
5558 if (afsUUID_from_string(as->parms[0].items->data, &attrs.uuid) < 0) {
5559 fprintf(STDERR, "vos: invalid UUID '%s'\n",
5560 as->parms[0].items->data);
5566 ubik_VL_GetAddrsU(cstruct, UBIK_CALL_NEW, &attrs, &uuid, &uniq,
5568 if (code == VL_NOENT) {
5569 fprintf(STDERR, "vos: UUID not found\n");
5573 fprintf(STDERR, "vos: could not list the server addresses\n");
5574 PrintError("", code);
5577 if (addrs.bulkaddrs_len == 0) {
5578 fprintf(STDERR, "vos: no addresses found for UUID\n");
5582 ip2 = addrs.bulkaddrs_val[0]; /* network byte order */
5583 ip1 = 0xffffffff; /* indicates removal mode */
5586 printf("vos: Removing UUID with hosts:\n");
5587 print_addrs(&addrs, &uuid, nentries, 1);
5590 code = ubik_VL_ChangeAddr(cstruct, UBIK_CALL_NEW, ip1, ip2);
5592 fprintf(STDERR, "Could not remove server entry from the VLDB.\n");
5593 PrintError("", code);
5597 xdr_free((xdrproc_t) xdr_bulkaddrs, &addrs);
5603 LockEntry(struct cmd_syndesc *as, void *arock)
5606 afs_int32 vcode, err;
5608 avolid = vsu_GetVolumeID(as->parms[0].items->data, cstruct, &err);
5611 PrintError("", err);
5613 fprintf(STDERR, "vos: can't find volume '%s'\n",
5614 as->parms[0].items->data);
5617 vcode = ubik_VL_SetLock(cstruct, 0, avolid, -1, VLOP_DELETE);
5619 fprintf(STDERR, "Could not lock VLDB entry for volume %s\n",
5620 as->parms[0].items->data);
5621 PrintError("", vcode);
5624 fprintf(STDOUT, "Locked VLDB entry for volume %s\n",
5625 as->parms[0].items->data);
5630 ConvertRO(struct cmd_syndesc *as, void *arock)
5632 afs_int32 partition = -1;
5635 afs_int32 code, i, same;
5636 struct nvldbentry entry;
5638 afs_uint32 rwserver = 0;
5639 afs_int32 rwpartition = 0;
5640 afs_uint32 roserver = 0;
5641 afs_int32 ropartition = 0;
5645 server = GetServer(as->parms[0].items->data);
5647 fprintf(STDERR, "vos: host '%s' not found in host table\n",
5648 as->parms[0].items->data);
5651 partition = volutil_GetPartitionID(as->parms[1].items->data);
5652 if (partition < 0) {
5653 fprintf(STDERR, "vos: could not interpret partition name '%s'\n",
5654 as->parms[1].items->data);
5657 if (!IsPartValid(partition, server, &code)) {
5659 PrintError("", code);
5662 "vos : partition %s does not exist on the server\n",
5663 as->parms[1].items->data);
5666 volid = vsu_GetVolumeID(as->parms[2].items->data, cstruct, &code);
5669 PrintError("", code);
5671 fprintf(STDERR, "Unknown volume ID or name '%s'\n",
5672 as->parms[2].items->data);
5675 if (as->parms[3].items)
5678 memset(&entry, 0, sizeof(entry));
5679 vcode = VLDB_GetEntryByID(volid, -1, &entry);
5682 "Could not fetch the entry for volume %lu from VLDB\n",
5683 (unsigned long)volid);
5684 PrintError("convertROtoRW ", vcode);
5688 /* use RO volid even if user specified RW or BK volid */
5689 if (volid != entry.volumeId[ROVOL])
5690 volid = entry.volumeId[ROVOL];
5692 MapHostToNetwork(&entry);
5693 for (i = 0; i < entry.nServers; i++) {
5694 if (entry.serverFlags[i] & VLSF_RWVOL) {
5695 rwserver = entry.serverNumber[i];
5696 rwpartition = entry.serverPartition[i];
5699 } else if ((entry.serverFlags[i] & VLSF_ROVOL) && !roserver) {
5700 same = VLDB_IsSameAddrs(server, entry.serverNumber[i], &code);
5703 "Failed to get info about server's %d address(es) from vlserver (err=%d); aborting call!\n",
5708 roserver = entry.serverNumber[i];
5709 ropartition = entry.serverPartition[i];
5716 fprintf(STDERR, "Warning: RO volume didn't exist in vldb!\n");
5718 if (roserver && (ropartition != partition)) {
5720 "Warning: RO volume should be in partition %d instead of %d (vldb)\n",
5721 ropartition, partition);
5726 "VLDB indicates that a RW volume exists already on %s in partition %s.\n",
5727 hostutil_GetNameByINet(rwserver),
5728 volutil_PartitionName(rwpartition));
5730 fprintf(STDERR, "Overwrite this VLDB entry? [y|n] (n)\n");
5732 while (!(dc == EOF || dc == '\n'))
5733 dc = getchar(); /* goto end of line */
5734 if ((c != 'y') && (c != 'Y')) {
5735 fprintf(STDERR, "aborted.\n");
5741 code = UV_ConvertRO(server, partition, volid, &entry);
5747 Sizes(struct cmd_syndesc *as, void *arock)
5751 afs_int32 apart, voltype, fromdate = 0, code, err, i;
5752 struct nvldbentry entry;
5753 volintSize vol_size;
5755 rx_SetRxDeadTime(60 * 10);
5756 for (i = 0; i < MAXSERVERS; i++) {
5757 struct rx_connection *rxConn = ubik_GetRPCConn(cstruct, i);
5760 rx_SetConnDeadTime(rxConn, rx_connDeadTime);
5761 if (rx_ServiceOf(rxConn))
5762 rx_ServiceOf(rxConn)->connDeadTime = rx_connDeadTime;
5765 avolid = vsu_GetVolumeID(as->parms[0].items->data, cstruct, &err);
5768 PrintError("", err);
5770 fprintf(STDERR, "vos: can't find volume '%s'\n",
5771 as->parms[0].items->data);
5775 if (as->parms[1].items || as->parms[2].items) {
5776 if (!as->parms[1].items || !as->parms[2].items) {
5778 "Must specify both -server and -partition options\n");
5781 aserver = GetServer(as->parms[2].items->data);
5783 fprintf(STDERR, "Invalid server name\n");
5786 apart = volutil_GetPartitionID(as->parms[1].items->data);
5788 fprintf(STDERR, "Invalid partition name\n");
5792 code = GetVolumeInfo(avolid, &aserver, &apart, &voltype, &entry);
5799 if (as->parms[4].items && strcmp(as->parms[4].items->data, "0")) {
5800 code = ktime_DateToInt32(as->parms[4].items->data, &fromdate);
5802 fprintf(STDERR, "vos: failed to parse date '%s' (error=%d))\n",
5803 as->parms[4].items->data, code);
5808 fprintf(STDOUT, "Volume: %s\n", as->parms[0].items->data);
5810 if (as->parms[3].items) { /* do the dump estimate */
5811 vol_size.dump_size = 0;
5812 code = UV_GetSize(avolid, aserver, apart, fromdate, &vol_size);
5814 PrintDiagnostics("size", code);
5817 /* presumably the size info is now gathered in pntr */
5818 /* now we display it */
5820 fprintf(STDOUT, "dump_size: %llu\n", vol_size.dump_size);
5829 EndTrans(struct cmd_syndesc *as, void *arock)
5832 afs_int32 code, tid, rcode;
5833 struct rx_connection *aconn;
5835 server = GetServer(as->parms[0].items->data);
5837 fprintf(STDERR, "vos: host '%s' not found in host table\n",
5838 as->parms[0].items->data);
5842 code = util_GetInt32(as->parms[1].items->data, &tid);
5844 fprintf(STDERR, "vos: bad integer specified for transaction ID.\n");
5848 aconn = UV_Bind(server, AFSCONF_VOLUMEPORT);
5849 code = AFSVolEndTrans(aconn, tid, &rcode);
5855 PrintDiagnostics("endtrans", code);
5863 PrintDiagnostics(char *astring, afs_int32 acode)
5868 "You are not authorized to perform the 'vos %s' command (%d)\n",
5872 fprintf(STDERR, "Error in vos %s command.\n", astring);
5873 fprintf(STDERR, "Clone volume is not in the same partition as the read-write volume.\n");
5876 fprintf(STDERR, "Error in vos %s command.\n", astring);
5877 PrintError("", acode);
5886 win32_enableCrypt(void)
5893 /* Look up configuration parameters in Registry */
5894 code = RegOpenKeyEx(HKEY_LOCAL_MACHINE, AFSREG_CLT_SVC_PARAM_SUBKEY,
5895 0, (IsWow64()?KEY_WOW64_64KEY:0)|KEY_QUERY_VALUE, &parmKey);
5896 if (code != ERROR_SUCCESS) {
5897 dummyLen = sizeof(cryptall);
5898 RegQueryValueEx(parmKey, "SecurityLevel", NULL, NULL,
5899 (BYTE *) &cryptall, &dummyLen);
5901 RegCloseKey (parmKey);
5905 #endif /* AFS_NT40_ENV */
5908 MyBeforeProc(struct cmd_syndesc *as, void *arock)
5911 char *rxgk_seclevel_str = NULL;
5915 /* Initialize the ubik_client connection */
5916 rx_SetRxDeadTime(90);
5918 secFlags = AFSCONF_SECOPTS_FALLBACK_NULL;
5921 if (as->parms[COMMONPARM_OFFSET_CELL].items) /* if -cell specified */
5922 tcell = as->parms[COMMONPARM_OFFSET_CELL].items->data;
5924 if (as->parms[COMMONPARM_OFFSET_NOAUTH].items)
5925 secFlags |= AFSCONF_SECOPTS_NOAUTH;
5927 if (as->parms[COMMONPARM_OFFSET_LOCALAUTH].items) { /* -localauth specified */
5928 secFlags |= AFSCONF_SECOPTS_LOCALAUTH;
5929 confdir = AFSDIR_SERVER_ETC_DIRPATH;
5932 if (as->parms[COMMONPARM_OFFSET_ENCRYPT].items /* -encrypt specified */
5934 || win32_enableCrypt()
5935 #endif /* AFS_NT40_ENV */
5937 secFlags |= AFSCONF_SECOPTS_ALWAYSENCRYPT;
5939 if (as->parms[COMMONPARM_OFFSET_CONFIG].items) /* -config flag set */
5940 confdir = as->parms[COMMONPARM_OFFSET_CONFIG].items->data;
5942 if (cmd_OptionAsString(as, COMMONPARM_OFFSET_RXGK, &rxgk_seclevel_str) == 0) {
5943 if (strcmp(rxgk_seclevel_str, "clear") == 0)
5944 secFlags |= AFSCONF_SECOPTS_ALWAYSCLEAR;
5945 else if (strcmp(rxgk_seclevel_str, "auth") == 0)
5946 secFlags |= AFSCONF_SECOPTS_NEVERENCRYPT;
5947 else if (strcmp(rxgk_seclevel_str, "crypt") == 0) {
5948 /* don't need to set any flags; this is the default for rxgk */
5950 fprintf(STDERR, "Invalid argument to -rxgk: %s\n", rxgk_seclevel_str);
5953 secFlags |= AFSCONF_SECOPTS_RXGK;
5955 free(rxgk_seclevel_str);
5956 rxgk_seclevel_str = NULL;
5959 if ((code = vsu_ClientInit(confdir, tcell, secFlags, UV_SetSecurity,
5961 fprintf(STDERR, "could not initialize VLDB library (code=%lu) \n",
5962 (unsigned long)code);
5966 if (as->parms[COMMONPARM_OFFSET_VERBOSE].items) /* -verbose flag set */
5970 if (as->parms[COMMONPARM_OFFSET_NORESOLVE].items) /* -noresolve flag set */
5981 /* this sucks but it works for now.
5986 #include "AFS_component_version_number.c"
5989 main(int argc, char **argv)
5993 struct cmd_syndesc *ts;
5995 #ifdef AFS_AIX32_ENV
5997 * The following signal action for AIX is necessary so that in case of a
5998 * crash (i.e. core is generated) we can include the user's data section
5999 * in the core dump. Unfortunately, by default, only a partial core is
6000 * generated which, in many cases, isn't too useful.
6002 struct sigaction nsa;
6004 sigemptyset(&nsa.sa_mask);
6005 nsa.sa_handler = SIG_DFL;
6006 nsa.sa_flags = SA_FULLDUMP;
6007 sigaction(SIGSEGV, &nsa, NULL);
6010 confdir = AFSDIR_CLIENT_ETC_DIRPATH;
6012 cmd_SetBeforeProc(MyBeforeProc, NULL);
6014 ts = cmd_CreateSyntax("create", CreateVolume, NULL, 0, "create a new volume");
6015 cmd_AddParm(ts, "-server", CMD_SINGLE, 0, "machine name");
6016 cmd_AddParm(ts, "-partition", CMD_SINGLE, 0, "partition name");
6017 cmd_AddParm(ts, "-name", CMD_SINGLE, 0, "volume name");
6018 cmd_AddParm(ts, "-maxquota", CMD_SINGLE, CMD_OPTIONAL,
6019 "initial quota (KB)");
6020 cmd_AddParm(ts, "-id", CMD_SINGLE, CMD_OPTIONAL, "volume ID");
6021 cmd_AddParm(ts, "-roid", CMD_SINGLE, CMD_OPTIONAL, "readonly volume ID");
6024 ts = cmd_CreateSyntax("remove", DeleteVolume, NULL, 0, "delete a volume");
6025 cmd_AddParm(ts, "-server", CMD_SINGLE, CMD_OPTIONAL, "machine name");
6026 cmd_AddParm(ts, "-partition", CMD_SINGLE, CMD_OPTIONAL, "partition name");
6027 cmd_AddParm(ts, "-id", CMD_SINGLE, 0, "volume name or ID");
6031 ts = cmd_CreateSyntax("move", MoveVolume, NULL, 0, "move a volume");
6032 cmd_AddParm(ts, "-id", CMD_SINGLE, 0, "volume name or ID");
6033 cmd_AddParm(ts, "-fromserver", CMD_SINGLE, 0, "machine name on source");
6034 cmd_AddParm(ts, "-frompartition", CMD_SINGLE, 0,
6035 "partition name on source");
6036 cmd_AddParm(ts, "-toserver", CMD_SINGLE, 0,
6037 "machine name on destination");
6038 cmd_AddParm(ts, "-topartition", CMD_SINGLE, 0,
6039 "partition name on destination");
6040 cmd_AddParm(ts, "-live", CMD_FLAG, CMD_OPTIONAL,
6041 "copy live volume without cloning");
6044 ts = cmd_CreateSyntax("copy", CopyVolume, NULL, 0, "copy a volume");
6045 cmd_AddParm(ts, "-id", CMD_SINGLE, 0, "volume name or ID on source");
6046 cmd_AddParm(ts, "-fromserver", CMD_SINGLE, 0, "machine name on source");
6047 cmd_AddParm(ts, "-frompartition", CMD_SINGLE, 0,
6048 "partition name on source");
6049 cmd_AddParm(ts, "-toname", CMD_SINGLE, 0, "volume name on destination");
6050 cmd_AddParm(ts, "-toserver", CMD_SINGLE, 0,
6051 "machine name on destination");
6052 cmd_AddParm(ts, "-topartition", CMD_SINGLE, 0,
6053 "partition name on destination");
6054 cmd_AddParm(ts, "-offline", CMD_FLAG, CMD_OPTIONAL,
6055 "leave new volume offline");
6056 cmd_AddParm(ts, "-readonly", CMD_FLAG, CMD_OPTIONAL,
6057 "make new volume read-only");
6058 cmd_AddParm(ts, "-live", CMD_FLAG, CMD_OPTIONAL,
6059 "copy live volume without cloning");
6062 ts = cmd_CreateSyntax("shadow", ShadowVolume, NULL, 0,
6063 "make or update a shadow volume");
6064 cmd_AddParm(ts, "-id", CMD_SINGLE, 0, "volume name or ID on source");
6065 cmd_AddParm(ts, "-fromserver", CMD_SINGLE, 0, "machine name on source");
6066 cmd_AddParm(ts, "-frompartition", CMD_SINGLE, 0,
6067 "partition name on source");
6068 cmd_AddParm(ts, "-toserver", CMD_SINGLE, 0,
6069 "machine name on destination");
6070 cmd_AddParm(ts, "-topartition", CMD_SINGLE, 0,
6071 "partition name on destination");
6072 cmd_AddParm(ts, "-toname", CMD_SINGLE, CMD_OPTIONAL,
6073 "volume name on destination");
6074 cmd_AddParm(ts, "-toid", CMD_SINGLE, CMD_OPTIONAL,
6075 "volume ID on destination");
6076 cmd_AddParm(ts, "-offline", CMD_FLAG, CMD_OPTIONAL,
6077 "leave shadow volume offline");
6078 cmd_AddParm(ts, "-readonly", CMD_FLAG, CMD_OPTIONAL,
6079 "make shadow volume read-only");
6080 cmd_AddParm(ts, "-live", CMD_FLAG, CMD_OPTIONAL,
6081 "copy live volume without cloning");
6082 cmd_AddParm(ts, "-incremental", CMD_FLAG, CMD_OPTIONAL,
6083 "do incremental update if target exists");
6086 ts = cmd_CreateSyntax("backup", BackupVolume, NULL, 0,
6087 "make backup of a volume");
6088 cmd_AddParm(ts, "-id", CMD_SINGLE, 0, "volume name or ID");
6091 ts = cmd_CreateSyntax("clone", CloneVolume, NULL, 0,
6092 "make clone of a volume");
6093 cmd_AddParm(ts, "-id", CMD_SINGLE, 0, "volume name or ID");
6094 cmd_AddParm(ts, "-server", CMD_SINGLE, CMD_OPTIONAL, "server");
6095 cmd_AddParm(ts, "-partition", CMD_SINGLE, CMD_OPTIONAL, "partition");
6096 cmd_AddParm(ts, "-toname", CMD_SINGLE, CMD_OPTIONAL,
6097 "volume name on destination");
6098 cmd_AddParm(ts, "-toid", CMD_SINGLE, CMD_OPTIONAL,
6099 "volume ID on destination");
6100 cmd_AddParm(ts, "-offline", CMD_FLAG, CMD_OPTIONAL,
6101 "leave clone volume offline");
6102 cmd_AddParm(ts, "-readonly", CMD_FLAG, CMD_OPTIONAL,
6103 "make clone volume read-only, not readwrite");
6104 cmd_AddParm(ts, "-readwrite", CMD_FLAG, CMD_OPTIONAL,
6105 "make clone volume readwrite, not read-only");
6108 ts = cmd_CreateSyntax("release", ReleaseVolume, NULL, 0, "release a volume");
6109 cmd_AddParm(ts, "-id", CMD_SINGLE, 0, "volume name or ID");
6110 cmd_AddParm(ts, "-force", CMD_FLAG, CMD_OPTIONAL,
6111 "force a complete release and full dumps");
6112 cmd_AddParmAlias(ts, 1, "-f"); /* original force option */
6113 /* keep this reserved */
6114 cmd_AddParm(ts, "-stayonline", CMD_FLAG, CMD_OPTIONAL|CMD_HIDDEN,
6115 "release to cloned temp vol, then clone back to repsite RO");
6116 cmd_AddParm(ts, "-force-reclone", CMD_FLAG, CMD_OPTIONAL,
6117 "force a reclone and complete release with incremental dumps");
6120 ts = cmd_CreateSyntax("dump", DumpVolumeCmd, NULL, 0, "dump a volume");
6121 cmd_AddParm(ts, "-id", CMD_SINGLE, 0, "volume name or ID");
6122 cmd_AddParm(ts, "-time", CMD_SINGLE, CMD_OPTIONAL, "dump from time");
6123 cmd_AddParm(ts, "-file", CMD_SINGLE, CMD_OPTIONAL, "dump file");
6124 cmd_AddParm(ts, "-server", CMD_SINGLE, CMD_OPTIONAL, "server");
6125 cmd_AddParm(ts, "-partition", CMD_SINGLE, CMD_OPTIONAL, "partition");
6126 cmd_AddParm(ts, "-clone", CMD_FLAG, CMD_OPTIONAL,
6127 "dump a clone of the volume");
6128 cmd_AddParm(ts, "-omitdirs", CMD_FLAG, CMD_OPTIONAL,
6129 "omit unchanged directories from an incremental dump");
6132 ts = cmd_CreateSyntax("restore", RestoreVolumeCmd, NULL, 0,
6133 "restore a volume");
6134 cmd_AddParm(ts, "-server", CMD_SINGLE, 0, "machine name");
6135 cmd_AddParm(ts, "-partition", CMD_SINGLE, 0, "partition name");
6136 cmd_AddParm(ts, "-name", CMD_SINGLE, 0, "name of volume to be restored");
6137 cmd_AddParm(ts, "-file", CMD_SINGLE, CMD_OPTIONAL, "dump file");
6138 cmd_AddParm(ts, "-id", CMD_SINGLE, CMD_OPTIONAL, "volume ID");
6139 cmd_AddParm(ts, "-overwrite", CMD_SINGLE, CMD_OPTIONAL,
6140 "abort | full | incremental");
6141 cmd_AddParm(ts, "-offline", CMD_FLAG, CMD_OPTIONAL,
6142 "leave restored volume offline");
6143 cmd_AddParm(ts, "-readonly", CMD_FLAG, CMD_OPTIONAL,
6144 "make restored volume read-only");
6145 cmd_AddParm(ts, "-creation", CMD_SINGLE, CMD_OPTIONAL,
6146 "dump | keep | new");
6147 cmd_AddParm(ts, "-lastupdate", CMD_SINGLE, CMD_OPTIONAL,
6148 "dump | keep | new");
6149 cmd_AddParm(ts, "-nodelete", CMD_FLAG, CMD_OPTIONAL,
6150 "do not delete old site when restoring to a new site");
6153 ts = cmd_CreateSyntax("unlock", LockReleaseCmd, NULL, 0,
6154 "release lock on VLDB entry for a volume");
6155 cmd_AddParm(ts, "-id", CMD_SINGLE, 0, "volume name or ID");
6158 ts = cmd_CreateSyntax("changeloc", ChangeLocation, NULL, 0,
6159 "change an RW volume's location in the VLDB");
6160 cmd_AddParm(ts, "-server", CMD_SINGLE, 0,
6161 "machine name for new location");
6162 cmd_AddParm(ts, "-partition", CMD_SINGLE, 0,
6163 "partition name for new location");
6164 cmd_AddParm(ts, "-id", CMD_SINGLE, 0, "volume name or ID");
6167 ts = cmd_CreateSyntax("addsite", AddSite, NULL, 0, "add a replication site");
6168 cmd_AddParm(ts, "-server", CMD_SINGLE, 0, "machine name for new site");
6169 cmd_AddParm(ts, "-partition", CMD_SINGLE, 0,
6170 "partition name for new site");
6171 cmd_AddParm(ts, "-id", CMD_SINGLE, 0, "volume name or ID");
6172 cmd_AddParm(ts, "-roid", CMD_SINGLE, CMD_OPTIONAL, "volume name or ID for RO");
6173 cmd_AddParm(ts, "-valid", CMD_FLAG, CMD_OPTIONAL, "publish as an up-to-date site in VLDB");
6176 ts = cmd_CreateSyntax("remsite", RemoveSite, NULL, 0,
6177 "remove a replication site");
6178 cmd_AddParm(ts, "-server", CMD_SINGLE, 0, "machine name");
6179 cmd_AddParm(ts, "-partition", CMD_SINGLE, 0, "partition name");
6180 cmd_AddParm(ts, "-id", CMD_SINGLE, 0, "volume name or ID");
6183 ts = cmd_CreateSyntax("listpart", ListPartitions, NULL, 0, "list partitions");
6184 cmd_AddParm(ts, "-server", CMD_SINGLE, 0, "machine name");
6187 ts = cmd_CreateSyntax("listvol", ListVolumes, NULL, 0,
6188 "list volumes on server (bypass VLDB)");
6189 cmd_AddParm(ts, "-server", CMD_SINGLE, 0, "machine name");
6190 cmd_AddParm(ts, "-partition", CMD_SINGLE, CMD_OPTIONAL, "partition name");
6191 cmd_AddParm(ts, "-fast", CMD_FLAG, CMD_OPTIONAL, "minimal listing");
6192 cmd_AddParm(ts, "-long", CMD_FLAG, CMD_OPTIONAL,
6193 "list all normal volume fields");
6194 cmd_AddParm(ts, "-quiet", CMD_FLAG, CMD_OPTIONAL,
6195 "generate minimal information");
6196 cmd_AddParm(ts, "-extended", CMD_FLAG, CMD_OPTIONAL,
6197 "list extended volume fields");
6198 cmd_AddParm(ts, "-format", CMD_FLAG, CMD_OPTIONAL,
6199 "machine readable format");
6202 ts = cmd_CreateSyntax("syncvldb", SyncVldb, NULL, 0,
6203 "synchronize VLDB with server");
6204 cmd_AddParm(ts, "-server", CMD_SINGLE, CMD_OPTIONAL, "machine name");
6205 cmd_AddParm(ts, "-partition", CMD_SINGLE, CMD_OPTIONAL, "partition name");
6206 cmd_AddParm(ts, "-volume", CMD_SINGLE, CMD_OPTIONAL, "volume name or ID");
6207 cmd_AddParm(ts, "-dryrun", CMD_FLAG, CMD_OPTIONAL, "list what would be done, don't do it");
6210 ts = cmd_CreateSyntax("syncserv", SyncServer, NULL, 0,
6211 "synchronize server with VLDB");
6212 cmd_AddParm(ts, "-server", CMD_SINGLE, 0, "machine name");
6213 cmd_AddParm(ts, "-partition", CMD_SINGLE, CMD_OPTIONAL, "partition name");
6214 cmd_AddParm(ts, "-dryrun", CMD_FLAG, CMD_OPTIONAL, "list what would be done, don't do it");
6217 ts = cmd_CreateSyntax("examine", ExamineVolume, NULL, 0,
6218 "everything about the volume");
6219 cmd_AddParm(ts, "-id", CMD_SINGLE, 0, "volume name or ID");
6220 cmd_AddParm(ts, "-extended", CMD_FLAG, CMD_OPTIONAL,
6221 "list extended volume fields");
6222 cmd_AddParm(ts, "-format", CMD_FLAG, CMD_OPTIONAL,
6223 "machine readable format");
6225 cmd_CreateAlias(ts, "volinfo");
6226 cmd_CreateAlias(ts, "e");
6228 ts = cmd_CreateSyntax("setfields", SetFields, NULL, 0,
6229 "change volume info fields");
6230 cmd_AddParm(ts, "-id", CMD_SINGLE, 0, "volume name or ID");
6231 cmd_AddParm(ts, "-maxquota", CMD_SINGLE, CMD_OPTIONAL, "quota (KB)");
6232 cmd_AddParm(ts, "-clearuse", CMD_FLAG, CMD_OPTIONAL, "clear dayUse");
6233 cmd_AddParm(ts, "-clearVolUpCounter", CMD_FLAG, CMD_OPTIONAL, "clear volUpdateCounter");
6236 ts = cmd_CreateSyntax("offline", volOffline, NULL, 0, "force the volume status to offline");
6237 cmd_AddParm(ts, "-server", CMD_SINGLE, 0, "server name");
6238 cmd_AddParm(ts, "-partition", CMD_SINGLE, 0, "partition name");
6239 cmd_AddParm(ts, "-id", CMD_SINGLE, 0, "volume name or ID");
6240 cmd_AddParm(ts, "-sleep", CMD_SINGLE, CMD_OPTIONAL, "seconds to sleep");
6241 cmd_AddParm(ts, "-busy", CMD_FLAG, CMD_OPTIONAL, "busy volume");
6244 ts = cmd_CreateSyntax("online", volOnline, NULL, 0, "force the volume status to online");
6245 cmd_AddParm(ts, "-server", CMD_SINGLE, 0, "server name");
6246 cmd_AddParm(ts, "-partition", CMD_SINGLE, 0, "partition name");
6247 cmd_AddParm(ts, "-id", CMD_SINGLE, 0, "volume name or ID");
6250 ts = cmd_CreateSyntax("zap", VolumeZap, NULL, 0,
6251 "delete the volume, don't bother with VLDB");
6252 cmd_AddParm(ts, "-server", CMD_SINGLE, 0, "machine name");
6253 cmd_AddParm(ts, "-partition", CMD_SINGLE, 0, "partition name");
6254 cmd_AddParm(ts, "-id", CMD_SINGLE, 0, "volume ID");
6255 cmd_AddParm(ts, "-force", CMD_FLAG, CMD_OPTIONAL,
6256 "force deletion of bad volumes");
6257 cmd_AddParm(ts, "-backup", CMD_FLAG, CMD_OPTIONAL,
6258 "also delete backup volume if one is found");
6261 ts = cmd_CreateSyntax("status", VolserStatus, NULL, 0,
6262 "report on volser status");
6263 cmd_AddParm(ts, "-server", CMD_SINGLE, 0, "machine name");
6266 ts = cmd_CreateSyntax("rename", RenameVolume, NULL, 0, "rename a volume");
6267 cmd_AddParm(ts, "-oldname", CMD_SINGLE, 0, "old volume name ");
6268 cmd_AddParm(ts, "-newname", CMD_SINGLE, 0, "new volume name ");
6271 ts = cmd_CreateSyntax("listvldb", ListVLDB, NULL, 0,
6272 "list volumes in the VLDB");
6273 cmd_AddParm(ts, "-name", CMD_SINGLE, CMD_OPTIONAL, "volume name or ID");
6274 cmd_AddParm(ts, "-server", CMD_SINGLE, CMD_OPTIONAL, "machine name");
6275 cmd_AddParm(ts, "-partition", CMD_SINGLE, CMD_OPTIONAL, "partition name");
6276 cmd_AddParm(ts, "-locked", CMD_FLAG, CMD_OPTIONAL, "locked volumes only");
6277 cmd_AddParm(ts, "-quiet", CMD_FLAG, CMD_OPTIONAL,
6278 "generate minimal information");
6279 cmd_AddParm(ts, "-nosort", CMD_FLAG, CMD_OPTIONAL,
6280 "do not alphabetically sort the volume names");
6283 ts = cmd_CreateSyntax("backupsys", BackSys, NULL, 0, "en masse backups");
6284 cmd_AddParm(ts, "-prefix", CMD_LIST, CMD_OPTIONAL,
6285 "common prefix on volume(s)");
6286 cmd_AddParm(ts, "-server", CMD_SINGLE, CMD_OPTIONAL, "machine name");
6287 cmd_AddParm(ts, "-partition", CMD_SINGLE, CMD_OPTIONAL, "partition name");
6288 cmd_AddParm(ts, "-exclude", CMD_FLAG, CMD_OPTIONAL,
6289 "exclude common prefix volumes");
6290 cmd_AddParm(ts, "-xprefix", CMD_LIST, CMD_OPTIONAL,
6291 "negative prefix on volume(s)");
6292 cmd_AddParm(ts, "-dryrun", CMD_FLAG, CMD_OPTIONAL, "list what would be done, don't do it");
6295 ts = cmd_CreateSyntax("delentry", DeleteEntry, NULL, 0,
6296 "delete VLDB entry for a volume");
6297 cmd_AddParm(ts, "-id", CMD_LIST, CMD_OPTIONAL, "volume name or ID");
6298 cmd_AddParm(ts, "-prefix", CMD_SINGLE, CMD_OPTIONAL,
6299 "prefix of the volume whose VLDB entry is to be deleted");
6300 cmd_AddParm(ts, "-server", CMD_SINGLE, CMD_OPTIONAL, "machine name");
6301 cmd_AddParm(ts, "-partition", CMD_SINGLE, CMD_OPTIONAL, "partition name");
6302 cmd_AddParm(ts, "-noexecute", CMD_FLAG, CMD_OPTIONAL|CMD_HIDDEN, "");
6303 cmd_AddParm(ts, "-dryrun", CMD_FLAG, CMD_OPTIONAL,
6304 "list what would be done, don't do it");
6307 ts = cmd_CreateSyntax("partinfo", PartitionInfo, NULL, 0,
6308 "list partition information");
6309 cmd_AddParm(ts, "-server", CMD_SINGLE, 0, "machine name");
6310 cmd_AddParm(ts, "-partition", CMD_SINGLE, CMD_OPTIONAL, "partition name");
6311 cmd_AddParm(ts, "-summary", CMD_FLAG, CMD_OPTIONAL,
6312 "print storage summary");
6315 ts = cmd_CreateSyntax("unlockvldb", UnlockVLDB, NULL, 0,
6316 "unlock all the locked entries in the VLDB");
6317 cmd_AddParm(ts, "-server", CMD_SINGLE, CMD_OPTIONAL, "machine name");
6318 cmd_AddParm(ts, "-partition", CMD_SINGLE, CMD_OPTIONAL, "partition name");
6321 ts = cmd_CreateSyntax("lock", LockEntry, NULL, 0,
6322 "lock VLDB entry for a volume");
6323 cmd_AddParm(ts, "-id", CMD_SINGLE, 0, "volume name or ID");
6326 ts = cmd_CreateSyntax("changeaddr", ChangeAddr, NULL, 0,
6327 "change the IP address of a file server");
6328 cmd_AddParm(ts, "-oldaddr", CMD_SINGLE, 0, "original IP address");
6329 cmd_AddParm(ts, "-newaddr", CMD_SINGLE, CMD_OPTIONAL, "new IP address");
6330 cmd_AddParm(ts, "-remove", CMD_FLAG, CMD_OPTIONAL,
6331 "remove the IP address from the VLDB");
6332 cmd_AddParm(ts, "-force", CMD_FLAG, CMD_OPTIONAL,
6333 "allow multi-homed server entry change (not recommended)");
6336 ts = cmd_CreateSyntax("listaddrs", ListAddrs, NULL, 0,
6337 "list the IP address of all file servers registered in the VLDB");
6338 cmd_AddParm(ts, "-uuid", CMD_SINGLE, CMD_OPTIONAL, "uuid of server");
6339 cmd_AddParm(ts, "-host", CMD_SINGLE, CMD_OPTIONAL, "address of host");
6340 cmd_AddParm(ts, "-printuuid", CMD_FLAG, CMD_OPTIONAL,
6341 "print uuid of hosts");
6344 ts = cmd_CreateSyntax("convertROtoRW", ConvertRO, NULL, 0,
6345 "convert a RO volume into a RW volume (after loss of old RW volume)");
6346 cmd_AddParm(ts, "-server", CMD_SINGLE, 0, "machine name");
6347 cmd_AddParm(ts, "-partition", CMD_SINGLE, 0, "partition name");
6348 cmd_AddParm(ts, "-id", CMD_SINGLE, 0, "volume name or ID");
6349 cmd_AddParm(ts, "-force", CMD_FLAG, CMD_OPTIONAL, "don't ask");
6352 ts = cmd_CreateSyntax("size", Sizes, NULL, 0,
6353 "obtain various sizes of the volume.");
6354 cmd_AddParm(ts, "-id", CMD_SINGLE, 0, "volume name or ID");
6355 cmd_AddParm(ts, "-partition", CMD_SINGLE, CMD_OPTIONAL, "partition name");
6356 cmd_AddParm(ts, "-server", CMD_SINGLE, CMD_OPTIONAL, "machine name");
6357 cmd_AddParm(ts, "-dump", CMD_FLAG, CMD_OPTIONAL,
6358 "Obtain the size of the dump");
6359 cmd_AddParm(ts, "-time", CMD_SINGLE, CMD_OPTIONAL, "dump from time");
6362 ts = cmd_CreateSyntax("endtrans", EndTrans, NULL, 0,
6363 "end a volserver transaction");
6364 cmd_AddParm(ts, "-server", CMD_SINGLE, 0, "machine name");
6365 cmd_AddParm(ts, "-transaction", CMD_SINGLE, 0,
6369 ts = cmd_CreateSyntax("setaddrs", SetAddrs, NULL, 0,
6370 "set the list of IP addresses for a given UUID in the VLDB");
6371 cmd_AddParm(ts, "-uuid", CMD_SINGLE, 0, "uuid of server");
6372 cmd_AddParm(ts, "-host", CMD_LIST, 0, "address of host");
6375 ts = cmd_CreateSyntax("remaddrs", RemoveAddrs, NULL, 0,
6376 "remove the list of IP addresses for a given UUID in the VLDB");
6377 cmd_AddParm(ts, "-uuid", CMD_SINGLE, 0, "uuid of server");
6380 code = cmd_Dispatch(argc, argv);
6382 /* Shut down the ubik_client and rx connections */
6384 (void)ubik_ClientDestroy(cstruct);
6390 exit((code ? -1 : 0));