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);
2076 DeleteAll(struct nvldbentry *entry)
2079 afs_int32 error, code, curserver, curpart;
2082 MapHostToNetwork(entry);
2084 for (i = 0; i < entry->nServers; i++) {
2085 curserver = entry->serverNumber[i];
2086 curpart = entry->serverPartition[i];
2087 if (entry->serverFlags[i] & VLSF_ROVOL) {
2088 volid = entry->volumeId[ROVOL];
2090 volid = entry->volumeId[RWVOL];
2092 code = UV_DeleteVolume(curserver, curpart, volid);
2101 DeleteVolume(struct cmd_syndesc *as, void *arock)
2103 afs_int32 err, code = 0;
2104 afs_uint32 server = 0;
2105 afs_int32 partition = -1;
2110 if (as->parms[0].items) {
2111 server = GetServer(as->parms[0].items->data);
2113 fprintf(STDERR, "vos: server '%s' not found in host table\n",
2114 as->parms[0].items->data);
2119 if (as->parms[1].items) {
2120 partition = volutil_GetPartitionID(as->parms[1].items->data);
2121 if (partition < 0) {
2122 fprintf(STDERR, "vos: could not interpret partition name '%s'\n",
2123 as->parms[1].items->data);
2127 /* Check for validity of the partition */
2128 if (!IsPartValid(partition, server, &code)) {
2130 PrintError("", code);
2133 "vos : partition %s does not exist on the server\n",
2134 as->parms[1].items->data);
2140 volid = vsu_GetVolumeID(as->parms[2].items->data, cstruct, &err);
2142 fprintf(STDERR, "Can't find volume name '%s' in VLDB\n",
2143 as->parms[2].items->data);
2145 PrintError("", err);
2149 /* If the server or partition option are not complete, try to fill
2150 * them in from the VLDB entry.
2152 if ((partition == -1) || !server) {
2153 struct nvldbentry entry;
2155 code = VLDB_GetEntryByID(volid, -1, &entry);
2158 "Could not fetch the entry for volume %lu from VLDB\n",
2159 (unsigned long)volid);
2160 PrintError("", code);
2164 if (((volid == entry.volumeId[RWVOL]) && (entry.flags & VLF_RWEXISTS))
2165 || ((volid == entry.volumeId[BACKVOL])
2166 && (entry.flags & VLF_BACKEXISTS))) {
2167 idx = Lp_GetRwIndex(&entry);
2168 if ((idx == -1) || (server && (server != entry.serverNumber[idx]))
2169 || ((partition != -1)
2170 && (partition != entry.serverPartition[idx]))) {
2171 fprintf(STDERR, "VLDB: Volume '%s' no match\n",
2172 as->parms[2].items->data);
2175 } else if ((volid == entry.volumeId[ROVOL])
2176 && (entry.flags & VLF_ROEXISTS)) {
2177 for (idx = -1, j = 0; j < entry.nServers; j++) {
2178 if (!(entry.serverFlags[j] & VLSF_ROVOL))
2181 if (((server == 0) || (server == entry.serverNumber[j]))
2182 && ((partition == -1)
2183 || (partition == entry.serverPartition[j]))) {
2186 "VLDB: Volume '%s' matches more than one RO\n",
2187 as->parms[2].items->data);
2194 fprintf(STDERR, "VLDB: Volume '%s' no match\n",
2195 as->parms[2].items->data);
2199 fprintf(STDERR, "VLDB: Volume '%s' no match\n",
2200 as->parms[2].items->data);
2204 server = htonl(entry.serverNumber[idx]);
2205 partition = entry.serverPartition[idx];
2209 code = UV_DeleteVolume(server, partition, volid);
2211 PrintDiagnostics("remove", code);
2215 MapPartIdIntoName(partition, pname);
2216 fprintf(STDOUT, "Volume %lu on partition %s server %s deleted\n",
2217 (unsigned long)volid, pname, hostutil_GetNameByINet(server));
2221 #define TESTM 0 /* set for move space tests, clear for production */
2223 MoveVolume(struct cmd_syndesc *as, void *arock)
2227 afs_uint32 fromserver, toserver;
2228 afs_int32 frompart, topart;
2229 afs_int32 flags, code, err;
2230 char fromPartName[10], toPartName[10];
2232 struct diskPartition64 partition; /* for space check */
2235 volid = vsu_GetVolumeID(as->parms[0].items->data, cstruct, &err);
2238 PrintError("", err);
2240 fprintf(STDERR, "vos: can't find volume ID or name '%s'\n",
2241 as->parms[0].items->data);
2244 fromserver = GetServer(as->parms[1].items->data);
2245 if (fromserver == 0) {
2246 fprintf(STDERR, "vos: server '%s' not found in host table\n",
2247 as->parms[1].items->data);
2250 toserver = GetServer(as->parms[3].items->data);
2251 if (toserver == 0) {
2252 fprintf(STDERR, "vos: server '%s' not found in host table\n",
2253 as->parms[3].items->data);
2256 frompart = volutil_GetPartitionID(as->parms[2].items->data);
2258 fprintf(STDERR, "vos: could not interpret partition name '%s'\n",
2259 as->parms[2].items->data);
2262 if (!IsPartValid(frompart, fromserver, &code)) { /*check for validity of the partition */
2264 PrintError("", code);
2267 "vos : partition %s does not exist on the server\n",
2268 as->parms[2].items->data);
2271 topart = volutil_GetPartitionID(as->parms[4].items->data);
2273 fprintf(STDERR, "vos: could not interpret partition name '%s'\n",
2274 as->parms[4].items->data);
2277 if (!IsPartValid(topart, toserver, &code)) { /*check for validity of the partition */
2279 PrintError("", code);
2282 "vos : partition %s does not exist on the server\n",
2283 as->parms[4].items->data);
2288 if (as->parms[5].items) flags |= RV_NOCLONE;
2291 * check source partition for space to clone volume
2294 MapPartIdIntoName(topart, toPartName);
2295 MapPartIdIntoName(frompart, fromPartName);
2298 * check target partition for space to move volume
2301 code = UV_PartitionInfo64(toserver, toPartName, &partition);
2303 fprintf(STDERR, "vos: cannot access partition %s\n", toPartName);
2307 fprintf(STDOUT, "target partition %s free space %" AFS_INT64_FMT "\n", toPartName,
2310 p = (volintInfo *) 0;
2311 code = UV_ListOneVolume(fromserver, frompart, volid, &p);
2313 fprintf(STDERR, "vos:cannot access volume %lu\n",
2314 (unsigned long)volid);
2318 fprintf(STDOUT, "volume %lu size %d\n", (unsigned long)volid,
2320 if (partition.free <= p->size) {
2322 "vos: no space on target partition %s to move volume %lu\n",
2323 toPartName, (unsigned long)volid);
2330 fprintf(STDOUT, "size test - don't do move\n");
2334 /* successful move still not guaranteed but shoot for it */
2337 UV_MoveVolume2(volid, fromserver, frompart, toserver, topart, flags);
2339 PrintDiagnostics("move", code);
2342 MapPartIdIntoName(topart, toPartName);
2343 MapPartIdIntoName(frompart, fromPartName);
2344 fprintf(STDOUT, "Volume %lu moved from %s %s to %s %s \n",
2345 (unsigned long)volid, as->parms[1].items->data, fromPartName,
2346 as->parms[3].items->data, toPartName);
2352 CopyVolume(struct cmd_syndesc *as, void *arock)
2355 afs_uint32 fromserver, toserver;
2356 afs_int32 frompart, topart, code, err, flags;
2357 char fromPartName[10], toPartName[10], *tovolume;
2358 struct nvldbentry entry;
2359 struct diskPartition64 partition; /* for space check */
2362 volid = vsu_GetVolumeID(as->parms[0].items->data, cstruct, &err);
2365 PrintError("", err);
2367 fprintf(STDERR, "vos: can't find volume ID or name '%s'\n",
2368 as->parms[0].items->data);
2371 fromserver = GetServer(as->parms[1].items->data);
2372 if (fromserver == 0) {
2373 fprintf(STDERR, "vos: server '%s' not found in host table\n",
2374 as->parms[1].items->data);
2378 toserver = GetServer(as->parms[4].items->data);
2379 if (toserver == 0) {
2380 fprintf(STDERR, "vos: server '%s' not found in host table\n",
2381 as->parms[4].items->data);
2385 tovolume = as->parms[3].items->data;
2386 if (!ISNAMEVALID(tovolume)) {
2388 "vos: the name of the root volume %s exceeds the size limit of %d\n",
2389 tovolume, VOLSER_OLDMAXVOLNAME - 10);
2392 if (!VolNameOK(tovolume)) {
2394 "Illegal volume name %s, should not end in .readonly or .backup\n",
2398 if (IsNumeric(tovolume)) {
2399 fprintf(STDERR, "Illegal volume name %s, should not be a number\n",
2403 code = VLDB_GetEntryByName(tovolume, &entry);
2405 fprintf(STDERR, "Volume %s already exists\n", tovolume);
2406 PrintDiagnostics("copy", code);
2410 frompart = volutil_GetPartitionID(as->parms[2].items->data);
2412 fprintf(STDERR, "vos: could not interpret partition name '%s'\n",
2413 as->parms[2].items->data);
2416 if (!IsPartValid(frompart, fromserver, &code)) { /*check for validity of the partition */
2418 PrintError("", code);
2421 "vos : partition %s does not exist on the server\n",
2422 as->parms[2].items->data);
2426 topart = volutil_GetPartitionID(as->parms[5].items->data);
2428 fprintf(STDERR, "vos: could not interpret partition name '%s'\n",
2429 as->parms[5].items->data);
2432 if (!IsPartValid(topart, toserver, &code)) { /*check for validity of the partition */
2434 PrintError("", code);
2437 "vos : partition %s does not exist on the server\n",
2438 as->parms[5].items->data);
2443 if (as->parms[6].items) flags |= RV_OFFLINE;
2444 if (as->parms[7].items) flags |= RV_RDONLY;
2445 if (as->parms[8].items) flags |= RV_NOCLONE;
2447 MapPartIdIntoName(topart, toPartName);
2448 MapPartIdIntoName(frompart, fromPartName);
2451 * check target partition for space to move volume
2454 code = UV_PartitionInfo64(toserver, toPartName, &partition);
2456 fprintf(STDERR, "vos: cannot access partition %s\n", toPartName);
2460 fprintf(STDOUT, "target partition %s free space %" AFS_INT64_FMT "\n", toPartName,
2463 p = (volintInfo *) 0;
2464 code = UV_ListOneVolume(fromserver, frompart, volid, &p);
2466 fprintf(STDERR, "vos:cannot access volume %lu\n",
2467 (unsigned long)volid);
2471 if (partition.free <= p->size) {
2473 "vos: no space on target partition %s to copy volume %lu\n",
2474 toPartName, (unsigned long)volid);
2480 /* successful copy still not guaranteed but shoot for it */
2483 UV_CopyVolume2(volid, fromserver, frompart, tovolume, toserver,
2486 PrintDiagnostics("copy", code);
2489 MapPartIdIntoName(topart, toPartName);
2490 MapPartIdIntoName(frompart, fromPartName);
2491 fprintf(STDOUT, "Volume %lu copied from %s %s to %s on %s %s \n",
2492 (unsigned long)volid, as->parms[1].items->data, fromPartName,
2493 tovolume, as->parms[4].items->data, toPartName);
2500 ShadowVolume(struct cmd_syndesc *as, void *arock)
2502 afs_uint32 volid, tovolid;
2503 afs_uint32 fromserver, toserver;
2504 afs_int32 frompart, topart;
2505 afs_int32 code, err, flags;
2506 char fromPartName[10], toPartName[10], toVolName[32], *tovolume;
2507 struct diskPartition64 partition; /* for space check */
2510 p = (volintInfo *) 0;
2511 q = (volintInfo *) 0;
2513 volid = vsu_GetVolumeID(as->parms[0].items->data, cstruct, &err);
2516 PrintError("", err);
2518 fprintf(STDERR, "vos: can't find volume ID or name '%s'\n",
2519 as->parms[0].items->data);
2522 fromserver = GetServer(as->parms[1].items->data);
2523 if (fromserver == 0) {
2524 fprintf(STDERR, "vos: server '%s' not found in host table\n",
2525 as->parms[1].items->data);
2529 toserver = GetServer(as->parms[3].items->data);
2530 if (toserver == 0) {
2531 fprintf(STDERR, "vos: server '%s' not found in host table\n",
2532 as->parms[3].items->data);
2536 frompart = volutil_GetPartitionID(as->parms[2].items->data);
2538 fprintf(STDERR, "vos: could not interpret partition name '%s'\n",
2539 as->parms[2].items->data);
2542 if (!IsPartValid(frompart, fromserver, &code)) { /*check for validity of the partition */
2544 PrintError("", code);
2547 "vos : partition %s does not exist on the server\n",
2548 as->parms[2].items->data);
2552 topart = volutil_GetPartitionID(as->parms[4].items->data);
2554 fprintf(STDERR, "vos: could not interpret partition name '%s'\n",
2555 as->parms[4].items->data);
2558 if (!IsPartValid(topart, toserver, &code)) { /*check for validity of the partition */
2560 PrintError("", code);
2563 "vos : partition %s does not exist on the server\n",
2564 as->parms[4].items->data);
2568 if (as->parms[5].items) {
2569 tovolume = as->parms[5].items->data;
2570 if (!ISNAMEVALID(tovolume)) {
2572 "vos: the name of the root volume %s exceeds the size limit of %d\n",
2573 tovolume, VOLSER_OLDMAXVOLNAME - 10);
2576 if (!VolNameOK(tovolume)) {
2578 "Illegal volume name %s, should not end in .readonly or .backup\n",
2582 if (IsNumeric(tovolume)) {
2584 "Illegal volume name %s, should not be a number\n",
2589 /* use actual name of source volume */
2590 code = UV_ListOneVolume(fromserver, frompart, volid, &p);
2592 fprintf(STDERR, "vos:cannot access volume %lu\n",
2593 (unsigned long)volid);
2596 strcpy(toVolName, p->name);
2597 tovolume = toVolName;
2598 /* save p for size checks later */
2601 if (as->parms[6].items) {
2602 tovolid = vsu_GetVolumeID(as->parms[6].items->data, cstruct, &err);
2605 PrintError("", err);
2607 fprintf(STDERR, "vos: can't find volume ID or name '%s'\n",
2608 as->parms[6].items->data);
2614 tovolid = vsu_GetVolumeID(tovolume, cstruct, &err);
2617 PrintError("", err);
2619 fprintf(STDERR, "vos: can't find volume ID or name '%s'\n",
2628 if (as->parms[7].items) flags |= RV_OFFLINE;
2629 if (as->parms[8].items) flags |= RV_RDONLY;
2630 if (as->parms[9].items) flags |= RV_NOCLONE;
2631 if (as->parms[10].items) flags |= RV_CPINCR;
2633 MapPartIdIntoName(topart, toPartName);
2634 MapPartIdIntoName(frompart, fromPartName);
2637 * check target partition for space to move volume
2640 code = UV_PartitionInfo64(toserver, toPartName, &partition);
2642 fprintf(STDERR, "vos: cannot access partition %s\n", toPartName);
2646 fprintf(STDOUT, "target partition %s free space %" AFS_INT64_FMT "\n", toPartName,
2649 /* Don't do this again if we did it above */
2651 code = UV_ListOneVolume(fromserver, frompart, volid, &p);
2653 fprintf(STDERR, "vos:cannot access volume %lu\n",
2654 (unsigned long)volid);
2659 /* OK if this fails */
2660 code = UV_ListOneVolume(toserver, topart, tovolid, &q);
2662 /* Treat existing volume size as "free" */
2664 p->size = (q->size < p->size) ? p->size - q->size : 0;
2666 if (partition.free <= p->size) {
2668 "vos: no space on target partition %s to copy volume %lu\n",
2669 toPartName, (unsigned long)volid);
2677 /* successful copy still not guaranteed but shoot for it */
2680 UV_CopyVolume2(volid, fromserver, frompart, tovolume, toserver,
2681 topart, tovolid, flags);
2683 PrintDiagnostics("shadow", code);
2686 MapPartIdIntoName(topart, toPartName);
2687 MapPartIdIntoName(frompart, fromPartName);
2688 fprintf(STDOUT, "Volume %lu shadowed from %s %s to %s %s \n",
2689 (unsigned long)volid, as->parms[1].items->data, fromPartName,
2690 as->parms[3].items->data, toPartName);
2697 CloneVolume(struct cmd_syndesc *as, void *arock)
2699 afs_uint32 volid, cloneid;
2701 afs_int32 part, voltype;
2702 char partName[10], *volname;
2703 afs_int32 code, err, flags;
2704 struct nvldbentry entry;
2706 volid = vsu_GetVolumeID(as->parms[0].items->data, cstruct, &err);
2709 PrintError("", err);
2711 fprintf(STDERR, "vos: can't find volume ID or name '%s'\n",
2712 as->parms[0].items->data);
2716 if (as->parms[1].items || as->parms[2].items) {
2717 if (!as->parms[1].items || !as->parms[2].items) {
2719 "Must specify both -server and -partition options\n");
2722 server = GetServer(as->parms[1].items->data);
2724 fprintf(STDERR, "vos: server '%s' not found in host table\n",
2725 as->parms[1].items->data);
2728 part = volutil_GetPartitionID(as->parms[2].items->data);
2730 fprintf(STDERR, "vos: could not interpret partition name '%s'\n",
2731 as->parms[2].items->data);
2734 if (!IsPartValid(part, server, &code)) { /*check for validity of the partition */
2736 PrintError("", code);
2739 "vos : partition %s does not exist on the server\n",
2740 as->parms[2].items->data);
2744 code = GetVolumeInfo(volid, &server, &part, &voltype, &entry);
2750 if (as->parms[3].items) {
2751 volname = as->parms[3].items->data;
2752 if (strlen(volname) > VOLSER_OLDMAXVOLNAME - 1) {
2754 "vos: the name of the root volume %s exceeds the size limit of %d\n",
2755 volname, VOLSER_OLDMAXVOLNAME - 1);
2760 * In order that you be able to make clones of RO or BK, this
2761 * check must be omitted.
2763 if (!VolNameOK(volname)) {
2765 "Illegal volume name %s, should not end in .readonly or .backup\n",
2770 if (IsNumeric(volname)) {
2772 "Illegal volume name %s, should not be a number\n",
2779 if (as->parms[4].items) {
2780 cloneid = vsu_GetVolumeID(as->parms[4].items->data, cstruct, &err);
2783 PrintError("", err);
2785 fprintf(STDERR, "vos: can't find volume ID or name '%s'\n",
2786 as->parms[4].items->data);
2792 if (as->parms[5].items) flags |= RV_OFFLINE;
2793 if (as->parms[6].items && as->parms[7].items) {
2794 fprintf(STDERR, "vos: cannot specify that a volume be -readwrite and -readonly\n");
2797 if (as->parms[6].items) flags |= RV_RDONLY;
2798 if (as->parms[7].items) flags |= RV_RWONLY;
2802 UV_CloneVolume(server, part, volid, cloneid, volname, flags);
2805 PrintDiagnostics("clone", code);
2808 MapPartIdIntoName(part, partName);
2809 fprintf(STDOUT, "Created clone for volume %s\n",
2810 as->parms[0].items->data);
2817 BackupVolume(struct cmd_syndesc *as, void *arock)
2821 afs_int32 apart, vtype, code, err;
2822 struct nvldbentry entry;
2825 afs_uint32 buserver;
2826 afs_int32 bupart, butype;
2827 struct nvldbentry buentry;
2829 avolid = vsu_GetVolumeID(as->parms[0].items->data, cstruct, &err);
2832 PrintError("", err);
2834 fprintf(STDERR, "vos: can't find volume ID or name '%s'\n",
2835 as->parms[0].items->data);
2838 code = GetVolumeInfo(avolid, &aserver, &apart, &vtype, &entry);
2842 /* verify this is a readwrite volume */
2844 if (vtype != RWVOL) {
2845 fprintf(STDERR, "%s not RW volume\n", as->parms[0].items->data);
2849 /* is there a backup volume already? */
2851 if (entry.flags & VLF_BACKEXISTS) {
2852 /* yep, where is it? */
2854 buvolid = entry.volumeId[BACKVOL];
2855 code = GetVolumeInfo(buvolid, &buserver, &bupart, &butype, &buentry);
2860 code = VLDB_IsSameAddrs(buserver, aserver, &err);
2863 "Failed to get info about server's %d address(es) from vlserver; aborting call!\n",
2869 "FATAL ERROR: backup volume %lu exists on server %lu\n",
2870 (unsigned long)buvolid, (unsigned long)buserver);
2875 /* nope, carry on */
2877 code = UV_BackupVolume(aserver, apart, avolid);
2880 PrintDiagnostics("backup", code);
2883 fprintf(STDOUT, "Created backup volume for %s \n",
2884 as->parms[0].items->data);
2889 ReleaseVolume(struct cmd_syndesc *as, void *arock)
2892 struct nvldbentry entry;
2895 afs_int32 apart, vtype, code, err;
2898 if (as->parms[1].items) /* -force */
2899 flags |= (REL_COMPLETE | REL_FULLDUMPS);
2900 if (as->parms[2].items) { /* -stayonline */
2901 fprintf(STDERR, "vos: -stayonline not supported\n");
2904 if (as->parms[3].items) /* -force-reclone */
2905 flags |= REL_COMPLETE;
2907 avolid = vsu_GetVolumeID(as->parms[0].items->data, cstruct, &err);
2910 PrintError("", err);
2912 fprintf(STDERR, "vos: can't find volume '%s'\n",
2913 as->parms[0].items->data);
2916 code = GetVolumeInfo(avolid, &aserver, &apart, &vtype, &entry);
2920 if (vtype != RWVOL) {
2921 fprintf(STDERR, "%s not a RW volume\n", as->parms[0].items->data);
2925 if (!ISNAMEVALID(entry.name)) {
2927 "Volume name %s is too long, rename before releasing\n",
2932 code = UV_ReleaseVolume(avolid, aserver, apart, flags);
2935 PrintDiagnostics("release", code);
2938 fprintf(STDOUT, "Released volume %s successfully\n",
2939 as->parms[0].items->data);
2944 DumpVolumeCmd(struct cmd_syndesc *as, void *arock)
2948 afs_int32 apart, voltype, fromdate = 0, code, err, i, flags;
2949 char filename[MAXPATHLEN];
2950 struct nvldbentry entry;
2952 rx_SetRxDeadTime(60 * 10);
2953 for (i = 0; i < MAXSERVERS; i++) {
2954 struct rx_connection *rxConn = ubik_GetRPCConn(cstruct, i);
2957 rx_SetConnDeadTime(rxConn, rx_connDeadTime);
2958 if (rx_ServiceOf(rxConn))
2959 rx_ServiceOf(rxConn)->connDeadTime = rx_connDeadTime;
2962 avolid = vsu_GetVolumeID(as->parms[0].items->data, cstruct, &err);
2965 PrintError("", err);
2967 fprintf(STDERR, "vos: can't find volume '%s'\n",
2968 as->parms[0].items->data);
2972 if (as->parms[3].items || as->parms[4].items) {
2973 if (!as->parms[3].items || !as->parms[4].items) {
2975 "Must specify both -server and -partition options\n");
2978 aserver = GetServer(as->parms[3].items->data);
2980 fprintf(STDERR, "Invalid server name\n");
2983 apart = volutil_GetPartitionID(as->parms[4].items->data);
2985 fprintf(STDERR, "Invalid partition name\n");
2989 code = GetVolumeInfo(avolid, &aserver, &apart, &voltype, &entry);
2994 if (as->parms[1].items && strcmp(as->parms[1].items->data, "0")) {
2995 code = ktime_DateToInt32(as->parms[1].items->data, &fromdate);
2997 fprintf(STDERR, "vos: failed to parse date '%s' (error=%d))\n",
2998 as->parms[1].items->data, code);
3002 if (as->parms[2].items) {
3003 strcpy(filename, as->parms[2].items->data);
3005 strcpy(filename, "");
3008 flags = as->parms[6].items ? VOLDUMPV2_OMITDIRS : 0;
3010 if (as->parms[5].items) {
3012 UV_DumpClonedVolume(avolid, aserver, apart, fromdate,
3013 DumpFunction, filename, flags);
3016 UV_DumpVolume(avolid, aserver, apart, fromdate, DumpFunction,
3019 if ((code == RXGEN_OPCODE) && (as->parms[6].items)) {
3020 flags &= ~VOLDUMPV2_OMITDIRS;
3024 PrintDiagnostics("dump", code);
3027 if (strcmp(filename, ""))
3028 fprintf(STDERR, "Dumped volume %s in file %s\n",
3029 as->parms[0].items->data, filename);
3031 fprintf(STDERR, "Dumped volume %s in stdout \n",
3032 as->parms[0].items->data);
3046 RestoreVolumeCmd(struct cmd_syndesc *as, void *arock)
3048 afs_uint32 avolid, aparentid;
3050 afs_int32 apart, code, vcode, err;
3051 afs_int32 aoverwrite = ASK;
3052 afs_int32 acreation = 0, alastupdate = 0;
3053 int restoreflags = 0;
3054 int readonly = 0, offline = 0, voltype = RWVOL;
3055 char afilename[MAXPATHLEN], avolname[VOLSER_MAXVOLNAME + 1], apartName[10];
3056 char volname[VOLSER_MAXVOLNAME + 1];
3057 struct nvldbentry entry;
3060 if (as->parms[4].items) {
3061 avolid = vsu_GetVolumeID(as->parms[4].items->data, cstruct, &err);
3064 PrintError("", err);
3066 fprintf(STDERR, "vos: can't find volume '%s'\n",
3067 as->parms[4].items->data);
3073 if (as->parms[5].items) {
3074 if ((strcmp(as->parms[5].items->data, "a") == 0)
3075 || (strcmp(as->parms[5].items->data, "abort") == 0)) {
3077 } else if ((strcmp(as->parms[5].items->data, "f") == 0)
3078 || (strcmp(as->parms[5].items->data, "full") == 0)) {
3080 } else if ((strcmp(as->parms[5].items->data, "i") == 0)
3081 || (strcmp(as->parms[5].items->data, "inc") == 0)
3082 || (strcmp(as->parms[5].items->data, "increment") == 0)
3083 || (strcmp(as->parms[5].items->data, "incremental") == 0)) {
3086 fprintf(STDERR, "vos: %s is not a valid argument to -overwrite\n",
3087 as->parms[5].items->data);
3091 if (as->parms[6].items)
3093 if (as->parms[7].items) {
3098 if (as->parms[8].items) {
3099 if ((strcmp(as->parms[8].items->data, "d") == 0)
3100 || (strcmp(as->parms[8].items->data, "dump") == 0)) {
3101 acreation = TS_DUMP;
3102 } else if ((strcmp(as->parms[8].items->data, "k") == 0)
3103 || (strcmp(as->parms[8].items->data, "keep") == 0)) {
3104 acreation = TS_KEEP;
3105 } else if ((strcmp(as->parms[8].items->data, "n") == 0)
3106 || (strcmp(as->parms[8].items->data, "new") == 0)) {
3109 fprintf(STDERR, "vos: %s is not a valid argument to -creation\n",
3110 as->parms[8].items->data);
3115 if (as->parms[9].items) {
3116 if ((strcmp(as->parms[9].items->data, "d") == 0)
3117 || (strcmp(as->parms[9].items->data, "dump") == 0)) {
3118 alastupdate = TS_DUMP;
3119 } else if ((strcmp(as->parms[9].items->data, "k") == 0)
3120 || (strcmp(as->parms[9].items->data, "keep") == 0)) {
3121 alastupdate = TS_KEEP;
3122 } else if ((strcmp(as->parms[9].items->data, "n") == 0)
3123 || (strcmp(as->parms[9].items->data, "new") == 0)) {
3124 alastupdate = TS_NEW;
3126 fprintf(STDERR, "vos: %s is not a valid argument to -lastupdate\n",
3127 as->parms[9].items->data);
3132 aserver = GetServer(as->parms[0].items->data);
3134 fprintf(STDERR, "vos: server '%s' not found in host table\n",
3135 as->parms[0].items->data);
3138 apart = volutil_GetPartitionID(as->parms[1].items->data);
3140 fprintf(STDERR, "vos: could not interpret partition name '%s'\n",
3141 as->parms[1].items->data);
3144 if (!IsPartValid(apart, aserver, &code)) { /*check for validity of the partition */
3146 PrintError("", code);
3149 "vos : partition %s does not exist on the server\n",
3150 as->parms[1].items->data);
3153 strcpy(avolname, as->parms[2].items->data);
3154 if (!ISNAMEVALID(avolname)) {
3156 "vos: the name of the volume %s exceeds the size limit\n",
3160 if (!VolNameOK(avolname)) {
3162 "Illegal volume name %s, should not end in .readonly or .backup\n",
3166 if (as->parms[3].items) {
3167 strcpy(afilename, as->parms[3].items->data);
3168 if (!FileExists(afilename)) {
3169 fprintf(STDERR, "Can't access file %s\n", afilename);
3173 strcpy(afilename, "");
3176 /* Check if volume exists or not */
3178 vsu_ExtractName(volname, avolname);
3179 vcode = VLDB_GetEntryByName(volname, &entry);
3180 if (vcode) { /* no volume - do a full restore */
3181 restoreflags = RV_FULLRST;
3182 if ((aoverwrite == INC) || (aoverwrite == ABORT))
3184 "Volume does not exist; Will perform a full restore\n");
3187 else if ((!readonly && Lp_GetRwIndex(&entry) == -1) /* RW volume does not exist - do a full */
3188 ||(readonly && !Lp_ROMatch(0, 0, &entry))) { /* RO volume does not exist - do a full */
3189 restoreflags = RV_FULLRST;
3190 if ((aoverwrite == INC) || (aoverwrite == ABORT))
3192 "%s Volume does not exist; Will perform a full restore\n",
3193 readonly ? "RO" : "RW");
3196 avolid = entry.volumeId[voltype];
3197 } else if (entry.volumeId[voltype] != 0
3198 && entry.volumeId[voltype] != avolid) {
3199 avolid = entry.volumeId[voltype];
3201 aparentid = entry.volumeId[RWVOL];
3204 else { /* volume exists - do we do a full incremental or abort */
3206 afs_int32 Opart, Otype, vol_elsewhere = 0;
3207 struct nvldbentry Oentry;
3211 avolid = entry.volumeId[voltype];
3212 } else if (entry.volumeId[voltype] != 0
3213 && entry.volumeId[voltype] != avolid) {
3214 avolid = entry.volumeId[voltype];
3216 aparentid = entry.volumeId[RWVOL];
3218 /* A file name was specified - check if volume is on another partition */
3219 vcode = GetVolumeInfo(avolid, &Oserver, &Opart, &Otype, &Oentry);
3223 vcode = VLDB_IsSameAddrs(Oserver, aserver, &err);
3226 "Failed to get info about server's %d address(es) from vlserver (err=%d); aborting call!\n",
3230 if (!vcode || (Opart != apart))
3233 if (aoverwrite == ASK) {
3234 if (strcmp(afilename, "") == 0) { /* The file is from standard in */
3236 "Volume exists and no -overwrite option specified; Aborting restore command\n");
3240 /* Ask what to do */
3241 if (vol_elsewhere) {
3243 "The volume %s %u already exists on a different server/part\n",
3244 volname, entry.volumeId[voltype]);
3246 "Do you want to do a full restore or abort? [fa](a): ");
3249 "The volume %s %u already exists in the VLDB\n",
3250 volname, entry.volumeId[voltype]);
3252 "Do you want to do a full/incremental restore or abort? [fia](a): ");
3255 while (!(dc == EOF || dc == '\n'))
3256 dc = getchar(); /* goto end of line */
3257 if ((c == 'f') || (c == 'F'))
3259 else if ((c == 'i') || (c == 'I'))
3265 if (aoverwrite == ABORT) {
3266 fprintf(STDERR, "Volume exists; Aborting restore command\n");
3268 } else if (aoverwrite == FULL) {
3269 restoreflags = RV_FULLRST;
3271 "Volume exists; Will delete and perform full restore\n");
3272 } else if (aoverwrite == INC) {
3274 if (vol_elsewhere) {
3276 "%s volume %lu already exists on a different server/part; not allowed\n",
3277 readonly ? "RO" : "RW", (unsigned long)avolid);
3283 restoreflags |= RV_OFFLINE;
3285 restoreflags |= RV_RDONLY;
3287 switch (acreation) {
3289 restoreflags |= RV_CRDUMP;
3292 restoreflags |= RV_CRKEEP;
3295 restoreflags |= RV_CRNEW;
3298 if (aoverwrite == FULL)
3299 restoreflags |= RV_CRNEW;
3301 restoreflags |= RV_CRKEEP;
3304 switch (alastupdate) {
3306 restoreflags |= RV_LUDUMP;
3309 restoreflags |= RV_LUKEEP;
3312 restoreflags |= RV_LUNEW;
3315 restoreflags |= RV_LUDUMP;
3317 if (as->parms[10].items) {
3318 restoreflags |= RV_NODEL;
3323 UV_RestoreVolume2(aserver, apart, avolid, aparentid,
3324 avolname, restoreflags, WriteData, afilename);
3326 PrintDiagnostics("restore", code);
3329 MapPartIdIntoName(apart, apartName);
3332 * patch typo here - originally "parms[1]", should be "parms[0]"
3335 fprintf(STDOUT, "Restored volume %s on %s %s\n", avolname,
3336 as->parms[0].items->data, apartName);
3341 LockReleaseCmd(struct cmd_syndesc *as, void *arock)
3344 afs_int32 code, err;
3346 avolid = vsu_GetVolumeID(as->parms[0].items->data, cstruct, &err);
3349 PrintError("", err);
3351 fprintf(STDERR, "vos: can't find volume '%s'\n",
3352 as->parms[0].items->data);
3356 code = UV_LockRelease(avolid);
3358 PrintDiagnostics("unlock", code);
3361 fprintf(STDOUT, "Released lock on vldb entry for volume %s\n",
3362 as->parms[0].items->data);
3367 AddSite(struct cmd_syndesc *as, void *arock)
3371 afs_int32 apart, code, err, arovolid, valid = 0;
3372 char apartName[10], avolname[VOLSER_MAXVOLNAME + 1];
3374 vsu_ExtractName(avolname, as->parms[2].items->data);;
3375 avolid = vsu_GetVolumeID(avolname, cstruct, &err);
3378 PrintError("", err);
3380 fprintf(STDERR, "vos: can't find volume '%s'\n",
3381 as->parms[2].items->data);
3385 if (as->parms[3].items) {
3386 vsu_ExtractName(avolname, as->parms[3].items->data);
3387 arovolid = vsu_GetVolumeID(avolname, cstruct, &err);
3389 fprintf(STDERR, "vos: invalid ro volume id '%s'\n",
3390 as->parms[3].items->data);
3394 aserver = GetServer(as->parms[0].items->data);
3396 fprintf(STDERR, "vos: server '%s' not found in host table\n",
3397 as->parms[0].items->data);
3400 apart = volutil_GetPartitionID(as->parms[1].items->data);
3402 fprintf(STDERR, "vos: could not interpret partition name '%s'\n",
3403 as->parms[1].items->data);
3406 if (!IsPartValid(apart, aserver, &code)) { /*check for validity of the partition */
3408 PrintError("", code);
3411 "vos : partition %s does not exist on the server\n",
3412 as->parms[1].items->data);
3415 if (as->parms[4].items) {
3418 code = UV_AddSite2(aserver, apart, avolid, arovolid, valid);
3420 PrintDiagnostics("addsite", code);
3423 MapPartIdIntoName(apart, apartName);
3424 fprintf(STDOUT, "Added replication site %s %s for volume %s\n",
3425 as->parms[0].items->data, apartName, as->parms[2].items->data);
3430 RemoveSite(struct cmd_syndesc *as, void *arock)
3435 afs_int32 apart, code, err;
3436 char apartName[10], avolname[VOLSER_MAXVOLNAME + 1];
3438 vsu_ExtractName(avolname, as->parms[2].items->data);
3439 avolid = vsu_GetVolumeID(avolname, cstruct, &err);
3442 PrintError("", err);
3444 fprintf(STDERR, "vos: can't find volume '%s'\n",
3445 as->parms[2].items->data);
3448 aserver = GetServer(as->parms[0].items->data);
3450 fprintf(STDERR, "vos: server '%s' not found in host table\n",
3451 as->parms[0].items->data);
3454 apart = volutil_GetPartitionID(as->parms[1].items->data);
3456 fprintf(STDERR, "vos: could not interpret partition name '%s'\n",
3457 as->parms[1].items->data);
3461 *skip the partition validity check, since it is possible that the partition
3462 *has since been decomissioned.
3465 if (!IsPartValid(apart,aserver,&code)){
3466 if(code) PrintError("",code);
3467 else fprintf(STDERR,"vos : partition %s does not exist on the server\n",as->parms[1].items->data);
3471 code = UV_RemoveSite(aserver, apart, avolid);
3473 PrintDiagnostics("remsite", code);
3476 MapPartIdIntoName(apart, apartName);
3477 fprintf(STDOUT, "Removed replication site %s %s for volume %s\n",
3478 as->parms[0].items->data, apartName, as->parms[2].items->data);
3483 ChangeLocation(struct cmd_syndesc *as, void *arock)
3487 afs_int32 apart, code, err;
3490 avolid = vsu_GetVolumeID(as->parms[2].items->data, cstruct, &err);
3493 PrintError("", err);
3495 fprintf(STDERR, "vos: can't find volume '%s'\n",
3496 as->parms[2].items->data);
3499 aserver = GetServer(as->parms[0].items->data);
3501 fprintf(STDERR, "vos: server '%s' not found in host table\n",
3502 as->parms[0].items->data);
3505 apart = volutil_GetPartitionID(as->parms[1].items->data);
3507 fprintf(STDERR, "vos: could not interpret partition name '%s'\n",
3508 as->parms[1].items->data);
3511 if (!IsPartValid(apart, aserver, &code)) { /*check for validity of the partition */
3513 PrintError("", code);
3516 "vos : partition %s does not exist on the server\n",
3517 as->parms[1].items->data);
3520 code = UV_ChangeLocation(aserver, apart, avolid);
3522 PrintDiagnostics("changeloc", code);
3525 MapPartIdIntoName(apart, apartName);
3526 fprintf(STDOUT, "Changed location to %s %s for volume %s\n",
3527 as->parms[0].items->data, apartName, as->parms[2].items->data);
3532 ListPartitions(struct cmd_syndesc *as, void *arock)
3536 struct partList dummyPartList;
3541 aserver = GetServer(as->parms[0].items->data);
3543 fprintf(STDERR, "vos: server '%s' not found in host table\n",
3544 as->parms[0].items->data);
3549 code = UV_ListPartitions(aserver, &dummyPartList, &cnt);
3551 PrintDiagnostics("listpart", code);
3555 fprintf(STDOUT, "The partitions on the server are:\n");
3556 for (i = 0; i < cnt; i++) {
3557 if (dummyPartList.partFlags[i] & PARTVALID) {
3558 memset(pname, 0, sizeof(pname));
3559 MapPartIdIntoName(dummyPartList.partId[i], pname);
3560 fprintf(STDOUT, " %10s ", pname);
3562 if ((i % 5) == 0 && (i != 0))
3563 fprintf(STDOUT, "\n");
3566 fprintf(STDOUT, "\n");
3567 fprintf(STDOUT, "Total: %d\n", total);
3573 CompareVolName(const void *p1, const void *p2)
3575 volintInfo *arg1, *arg2;
3577 arg1 = (volintInfo *) p1;
3578 arg2 = (volintInfo *) p2;
3579 return (strcmp(arg1->name, arg2->name));
3583 /*------------------------------------------------------------------------
3584 * PRIVATE XCompareVolName
3587 * Comparison routine for volume names coming from an extended
3591 * a_obj1P : Char ptr to first extended vol info object
3592 * a_obj1P : Char ptr to second extended vol info object
3595 * The value of strcmp() on the volume names within the passed
3596 * objects (i,e., -1, 0, or 1).
3599 * Passed to qsort() as the designated comparison routine.
3603 *------------------------------------------------------------------------*/
3606 XCompareVolName(const void *a_obj1P, const void *a_obj2P)
3607 { /*XCompareVolName */
3610 (((struct volintXInfo *)(a_obj1P))->name,
3611 ((struct volintXInfo *)(a_obj2P))->name));
3613 } /*XCompareVolName */
3616 CompareVolID(const void *p1, const void *p2)
3618 volintInfo *arg1, *arg2;
3620 arg1 = (volintInfo *) p1;
3621 arg2 = (volintInfo *) p2;
3622 if (arg1->volid == arg2->volid)
3624 if (arg1->volid > arg2->volid)
3631 /*------------------------------------------------------------------------
3632 * PRIVATE XCompareVolID
3635 * Comparison routine for volume IDs coming from an extended
3639 * a_obj1P : Char ptr to first extended vol info object
3640 * a_obj1P : Char ptr to second extended vol info object
3643 * The value of strcmp() on the volume names within the passed
3644 * objects (i,e., -1, 0, or 1).
3647 * Passed to qsort() as the designated comparison routine.
3651 *------------------------------------------------------------------------*/
3654 XCompareVolID(const void *a_obj1P, const void *a_obj2P)
3655 { /*XCompareVolID */
3657 afs_int32 id1, id2; /*Volume IDs we're comparing */
3659 id1 = ((struct volintXInfo *)(a_obj1P))->volid;
3660 id2 = ((struct volintXInfo *)(a_obj2P))->volid;
3668 } /*XCompareVolID */
3670 /*------------------------------------------------------------------------
3671 * PRIVATE ListVolumes
3674 * Routine used to list volumes, contacting the Volume Server
3675 * directly, bypassing the VLDB.
3678 * as : Ptr to parsed command line arguments.
3681 * 0 Successful operation
3684 * Nothing interesting.
3688 *------------------------------------------------------------------------*/
3691 ListVolumes(struct cmd_syndesc *as, void *arock)
3693 afs_int32 apart, int32list, fast;
3697 volintInfo *oldpntr = NULL;
3701 volintXInfo *xInfoP;
3702 volintXInfo *origxInfoP = NULL; /*Ptr to current/orig extended vol info */
3703 int wantExtendedInfo; /*Do we want extended vol info? */
3706 struct partList dummyPartList;
3714 if (as->parms[3].items)
3716 if (as->parms[4].items)
3720 if (as->parms[2].items)
3726 if (as->parms[5].items) {
3728 * We can't coexist with the fast flag.
3732 "vos: Can't use the -fast and -extended flags together\n");
3737 * We need to turn on ``long'' listings to get the full effect.
3739 wantExtendedInfo = 1;
3742 wantExtendedInfo = 0;
3743 if (as->parms[1].items) {
3744 apart = volutil_GetPartitionID(as->parms[1].items->data);
3746 fprintf(STDERR, "vos: could not interpret partition name '%s'\n",
3747 as->parms[1].items->data);
3750 dummyPartList.partId[0] = apart;
3751 dummyPartList.partFlags[0] = PARTVALID;
3754 aserver = GetServer(as->parms[0].items->data);
3756 fprintf(STDERR, "vos: server '%s' not found in host table\n",
3757 as->parms[0].items->data);
3762 if (!IsPartValid(apart, aserver, &code)) { /*check for validity of the partition */
3764 PrintError("", code);
3767 "vos : partition %s does not exist on the server\n",
3768 as->parms[1].items->data);
3772 code = UV_ListPartitions(aserver, &dummyPartList, &cnt);
3774 PrintDiagnostics("listvol", code);
3778 for (i = 0; i < cnt; i++) {
3779 if (dummyPartList.partFlags[i] & PARTVALID) {
3780 if (wantExtendedInfo)
3782 UV_XListVolumes(aserver, dummyPartList.partId[i], all,
3786 UV_ListVolumes(aserver, dummyPartList.partId[i], all,
3789 PrintDiagnostics("listvol", code);
3792 if (wantExtendedInfo) {
3793 origxInfoP = xInfoP;
3794 base = (char *)xInfoP;
3797 base = (char *)pntr;
3801 if (wantExtendedInfo)
3802 qsort(base, count, sizeof(volintXInfo), XCompareVolName);
3804 qsort(base, count, sizeof(volintInfo), CompareVolName);
3806 if (wantExtendedInfo)
3807 qsort(base, count, sizeof(volintXInfo), XCompareVolID);
3809 qsort(base, count, sizeof(volintInfo), CompareVolID);
3811 MapPartIdIntoName(dummyPartList.partId[i], pname);
3814 "Total number of volumes on server %s partition %s: %lu \n",
3815 as->parms[0].items->data, pname,
3816 (unsigned long)count);
3817 if (wantExtendedInfo) {
3818 if (as->parms[6].items)
3819 XDisplayVolumes2(aserver, dummyPartList.partId[i], origxInfoP,
3820 count, int32list, fast, quiet);
3822 XDisplayVolumes(aserver, dummyPartList.partId[i], origxInfoP,
3823 count, int32list, fast, quiet);
3826 xInfoP = (volintXInfo *) 0;
3828 if (as->parms[6].items)
3829 DisplayVolumes2(aserver, dummyPartList.partId[i], oldpntr,
3832 DisplayVolumes(aserver, dummyPartList.partId[i], oldpntr,
3833 count, int32list, fast, quiet);
3836 pntr = (volintInfo *) 0;
3844 SyncVldb(struct cmd_syndesc *as, void *arock)
3846 afs_int32 pnum = 0, code; /* part name */
3853 if (as->parms[0].items) {
3854 tserver = GetServer(as->parms[0].items->data);
3856 fprintf(STDERR, "vos: host '%s' not found in host table\n",
3857 as->parms[0].items->data);
3862 if (as->parms[1].items) {
3863 pnum = volutil_GetPartitionID(as->parms[1].items->data);
3865 fprintf(STDERR, "vos: could not interpret partition name '%s'\n",
3866 as->parms[1].items->data);
3869 if (!IsPartValid(pnum, tserver, &code)) { /*check for validity of the partition */
3871 PrintError("", code);
3874 "vos: partition %s does not exist on the server\n",
3875 as->parms[1].items->data);
3882 "The -partition option requires a -server option\n");
3887 if (as->parms[3].items) {
3888 flags |= 2; /* don't update */
3891 if (as->parms[2].items) {
3892 /* Synchronize an individual volume */
3893 volname = as->parms[2].items->data;
3894 code = UV_SyncVolume(tserver, pnum, volname, flags);
3898 "Without a -volume option, the -server option is required\n");
3901 code = UV_SyncVldb(tserver, pnum, flags, 0 /*unused */ );
3905 PrintDiagnostics("syncvldb", code);
3909 /* Print a summary of what we did */
3911 fprintf(STDOUT, "VLDB volume %s synchronized", volname);
3913 fprintf(STDOUT, "VLDB synchronized");
3915 fprintf(STDOUT, " with state of server %s", as->parms[0].items->data);
3918 MapPartIdIntoName(pnum, part);
3919 fprintf(STDOUT, " partition %s\n", part);
3921 fprintf(STDOUT, "\n");
3927 SyncServer(struct cmd_syndesc *as, void *arock)
3929 afs_int32 pnum, code; /* part name */
3935 tserver = GetServer(as->parms[0].items->data);
3937 fprintf(STDERR, "vos: host '%s' not found in host table\n",
3938 as->parms[0].items->data);
3941 if (as->parms[1].items) {
3942 pnum = volutil_GetPartitionID(as->parms[1].items->data);
3944 fprintf(STDERR, "vos: could not interpret partition name '%s'\n",
3945 as->parms[1].items->data);
3948 if (!IsPartValid(pnum, tserver, &code)) { /*check for validity of the partition */
3950 PrintError("", code);
3953 "vos : partition %s does not exist on the server\n",
3954 as->parms[1].items->data);
3962 if (as->parms[2].items) {
3963 flags |= 2; /* don't update */
3965 code = UV_SyncServer(tserver, pnum, flags, 0 /*unused */ );
3967 PrintDiagnostics("syncserv", code);
3971 MapPartIdIntoName(pnum, part);
3972 fprintf(STDOUT, "Server %s partition %s synchronized with VLDB\n",
3973 as->parms[0].items->data, part);
3975 fprintf(STDOUT, "Server %s synchronized with VLDB\n",
3976 as->parms[0].items->data);
3982 VolumeInfoCmd(char *name)
3984 struct nvldbentry entry;
3987 /* The vlserver will handle names with the .readonly
3988 * and .backup extension as well as volume ids.
3990 vcode = VLDB_GetEntryByName(name, &entry);
3992 PrintError("", vcode);
3995 MapHostToNetwork(&entry);
3996 EnumerateEntry(&entry);
3998 /* Defect #3027: grubby check to handle locked volume.
3999 * If VLOP_ALLOPERS is set, the entry is locked.
4000 * Leave this routine as is, but put in correct check.
4002 PrintLocked(entry.flags);
4008 VolumeZap(struct cmd_syndesc *as, void *arock)
4010 struct nvldbentry entry;
4011 afs_uint32 volid, zapbackupid = 0, backupid = 0;
4012 afs_int32 code, server, part, err;
4014 if (as->parms[3].items) {
4015 /* force flag is on, use the other version */
4016 return NukeVolume(as);
4019 if (as->parms[4].items) {
4023 volid = vsu_GetVolumeID(as->parms[2].items->data, cstruct, &err);
4026 PrintError("", err);
4028 fprintf(STDERR, "vos: can't find volume '%s'\n",
4029 as->parms[2].items->data);
4032 part = volutil_GetPartitionID(as->parms[1].items->data);
4034 fprintf(STDERR, "vos: could not interpret partition name '%s'\n",
4035 as->parms[1].items->data);
4038 server = GetServer(as->parms[0].items->data);
4040 fprintf(STDERR, "vos: host '%s' not found in host table\n",
4041 as->parms[0].items->data);
4044 if (!IsPartValid(part, server, &code)) { /*check for validity of the partition */
4046 PrintError("", code);
4049 "vos : partition %s does not exist on the server\n",
4050 as->parms[1].items->data);
4053 code = VLDB_GetEntryByID(volid, -1, &entry);
4055 if (volid == entry.volumeId[RWVOL])
4056 backupid = entry.volumeId[BACKVOL];
4058 "Warning: Entry for volume number %lu exists in VLDB (but we're zapping it anyway!)\n",
4059 (unsigned long)volid);
4062 volintInfo *pntr = (volintInfo *) 0;
4065 code = UV_ListOneVolume(server, part, volid, &pntr);
4067 if (volid == pntr->parentID)
4068 backupid = pntr->backupID;
4074 code = UV_VolumeZap(server, part, backupid);
4076 PrintDiagnostics("zap", code);
4079 fprintf(STDOUT, "Backup Volume %lu deleted\n",
4080 (unsigned long)backupid);
4083 code = UV_VolumeZap(server, part, volid);
4085 PrintDiagnostics("zap", code);
4088 fprintf(STDOUT, "Volume %lu deleted\n", (unsigned long)volid);
4094 VolserStatus(struct cmd_syndesc *as, void *arock)
4098 transDebugInfo *pntr, *oldpntr;
4104 server = GetServer(as->parms[0].items->data);
4106 fprintf(STDERR, "vos: host '%s' not found in host table\n",
4107 as->parms[0].items->data);
4110 code = UV_VolserStatus(server, &pntr, &count);
4112 PrintDiagnostics("status", code);
4117 fprintf(STDOUT, "No active transactions on %s\n",
4118 as->parms[0].items->data);
4120 fprintf(STDOUT, "Total transactions: %d\n", count);
4122 for (i = 0; i < count; i++) {
4123 /*print out the relevant info */
4124 fprintf(STDOUT, "--------------------------------------\n");
4125 t = pntr->creationTime;
4126 fprintf(STDOUT, "transaction: %lu created: %s",
4127 (unsigned long)pntr->tid, ctime(&t));
4129 fprintf(STDOUT, "lastActiveTime: %s", ctime(&t));
4130 if (pntr->returnCode) {
4131 fprintf(STDOUT, "returnCode: %lu\n",
4132 (unsigned long)pntr->returnCode);
4135 fprintf(STDOUT, "attachFlags: ");
4136 switch (pntr->iflags) {
4138 fprintf(STDOUT, "offline ");
4141 fprintf(STDOUT, "busy ");
4144 fprintf(STDOUT, "readonly ");
4147 fprintf(STDOUT, "create ");
4150 fprintf(STDOUT, "create volid ");
4153 fprintf(STDOUT, "\n");
4156 fprintf(STDOUT, "volumeStatus: ");
4157 switch (pntr->vflags) {
4158 case VTDeleteOnSalvage:
4159 fprintf(STDOUT, "deleteOnSalvage ");
4160 case VTOutOfService:
4161 fprintf(STDOUT, "outOfService ");
4163 fprintf(STDOUT, "deleted ");
4165 fprintf(STDOUT, "\n");
4168 fprintf(STDOUT, "transactionFlags: ");
4169 fprintf(STDOUT, "delete\n");
4171 MapPartIdIntoName(pntr->partition, pname);
4172 fprintf(STDOUT, "volume: %lu partition: %s procedure: %s\n",
4173 (unsigned long)pntr->volid, pname, pntr->lastProcName);
4174 if (pntr->callValid) {
4175 t = pntr->lastReceiveTime;
4176 fprintf(STDOUT, "packetRead: %lu lastReceiveTime: %s",
4177 (unsigned long)pntr->readNext, ctime(&t));
4178 t = pntr->lastSendTime;
4179 fprintf(STDOUT, "packetSend: %lu lastSendTime: %s",
4180 (unsigned long)pntr->transmitNext, ctime(&t));
4183 fprintf(STDOUT, "--------------------------------------\n");
4184 fprintf(STDOUT, "\n");
4192 RenameVolume(struct cmd_syndesc *as, void *arock)
4194 afs_int32 code1, code2, code;
4195 struct nvldbentry entry;
4197 code1 = VLDB_GetEntryByName(as->parms[0].items->data, &entry);
4199 fprintf(STDERR, "vos: Could not find entry for volume %s\n",
4200 as->parms[0].items->data);
4203 code2 = VLDB_GetEntryByName(as->parms[1].items->data, &entry);
4204 if ((!code1) && (!code2)) { /*the newname already exists */
4205 fprintf(STDERR, "vos: volume %s already exists\n",
4206 as->parms[1].items->data);
4210 if (code1 && code2) {
4211 fprintf(STDERR, "vos: Could not find entry for volume %s or %s\n",
4212 as->parms[0].items->data, as->parms[1].items->data);
4215 if (!VolNameOK(as->parms[0].items->data)) {
4217 "Illegal volume name %s, should not end in .readonly or .backup\n",
4218 as->parms[0].items->data);
4221 if (!ISNAMEVALID(as->parms[1].items->data)) {
4223 "vos: the new volume name %s exceeds the size limit of %d\n",
4224 as->parms[1].items->data, VOLSER_OLDMAXVOLNAME - 10);
4227 if (!VolNameOK(as->parms[1].items->data)) {
4229 "Illegal volume name %s, should not end in .readonly or .backup\n",
4230 as->parms[1].items->data);
4233 if (IsNumeric(as->parms[1].items->data)) {
4234 fprintf(STDERR, "Illegal volume name %s, should not be a number\n",
4235 as->parms[1].items->data);
4238 MapHostToNetwork(&entry);
4240 UV_RenameVolume(&entry, as->parms[0].items->data,
4241 as->parms[1].items->data);
4243 PrintDiagnostics("rename", code);
4246 fprintf(STDOUT, "Renamed volume %s to %s\n", as->parms[0].items->data,
4247 as->parms[1].items->data);
4252 GetVolumeInfo(afs_uint32 volid, afs_uint32 *server, afs_int32 *part, afs_int32 *voltype,
4253 struct nvldbentry *rentry)
4258 vcode = VLDB_GetEntryByID(volid, -1, rentry);
4261 "Could not fetch the entry for volume %lu from VLDB \n",
4262 (unsigned long)volid);
4263 PrintError("", vcode);
4266 MapHostToNetwork(rentry);
4267 if (volid == rentry->volumeId[ROVOL]) {
4269 for (i = 0; i < rentry->nServers; i++) {
4270 if ((index == -1) && (rentry->serverFlags[i] & VLSF_ROVOL)
4271 && !(rentry->serverFlags[i] & VLSF_DONTUSE))
4276 "RO volume is not found in VLDB entry for volume %lu\n",
4277 (unsigned long)volid);
4281 *server = rentry->serverNumber[index];
4282 *part = rentry->serverPartition[index];
4286 index = Lp_GetRwIndex(rentry);
4289 "RW Volume is not found in VLDB entry for volume %lu\n",
4290 (unsigned long)volid);
4293 if (volid == rentry->volumeId[RWVOL]) {
4295 *server = rentry->serverNumber[index];
4296 *part = rentry->serverPartition[index];
4299 if (volid == rentry->volumeId[BACKVOL]) {
4301 *server = rentry->serverNumber[index];
4302 *part = rentry->serverPartition[index];
4306 "unexpected volume type for volume %lu\n",
4307 (unsigned long)volid);
4312 DeleteEntry(struct cmd_syndesc *as, void *arock)
4314 afs_int32 apart = 0;
4317 struct VldbListByAttributes attributes;
4318 nbulkentries arrayEntries;
4319 struct nvldbentry *vllist;
4320 struct cmd_item *itp;
4323 char prefix[VOLSER_MAXVOLNAME + 1];
4325 afs_int32 totalBack = 0, totalFail = 0, err;
4327 if (as->parms[0].items) { /* -id */
4328 if (as->parms[1].items || as->parms[2].items || as->parms[3].items) {
4330 "You cannot use -server, -partition, or -prefix with the -id argument\n");
4333 for (itp = as->parms[0].items; itp; itp = itp->next) {
4334 avolid = vsu_GetVolumeID(itp->data, cstruct, &err);
4337 PrintError("", err);
4339 fprintf(STDERR, "vos: can't find volume '%s'\n",
4343 if (as->parms[4].items || as->parms[5].items) {
4344 /* -noexecute (hidden) or -dryrun */
4345 fprintf(STDOUT, "Would have deleted VLDB entry for %s \n",
4350 vcode = ubik_VL_DeleteEntry(cstruct, 0, avolid, RWVOL);
4352 fprintf(STDERR, "Could not delete entry for volume %s\n",
4355 "You must specify a RW volume name or ID "
4356 "(the entire VLDB entry will be deleted)\n");
4357 PrintError("", vcode);
4363 fprintf(STDOUT, "Deleted %d VLDB entries\n", totalBack);
4367 if (!as->parms[1].items && !as->parms[2].items && !as->parms[3].items) {
4368 fprintf(STDERR, "You must specify an option\n");
4372 /* Zero out search attributes */
4373 memset(&attributes, 0, sizeof(struct VldbListByAttributes));
4375 if (as->parms[1].items) { /* -prefix */
4376 strncpy(prefix, as->parms[1].items->data, VOLSER_MAXVOLNAME);
4378 if (!as->parms[2].items && !as->parms[3].items) { /* a single entry only */
4380 "You must provide -server with the -prefix argument\n");
4385 if (as->parms[2].items) { /* -server */
4387 aserver = GetServer(as->parms[2].items->data);
4389 fprintf(STDERR, "vos: server '%s' not found in host table\n",
4390 as->parms[2].items->data);
4393 attributes.server = ntohl(aserver);
4394 attributes.Mask |= VLLIST_SERVER;
4397 if (as->parms[3].items) { /* -partition */
4398 if (!as->parms[2].items) {
4400 "You must provide -server with the -partition argument\n");
4403 apart = volutil_GetPartitionID(as->parms[3].items->data);
4405 fprintf(STDERR, "vos: could not interpret partition name '%s'\n",
4406 as->parms[3].items->data);
4409 attributes.partition = apart;
4410 attributes.Mask |= VLLIST_PARTITION;
4413 /* Print status line of what we are doing */
4414 fprintf(STDOUT, "Deleting VLDB entries for ");
4415 if (as->parms[2].items) {
4416 fprintf(STDOUT, "server %s ", as->parms[2].items->data);
4418 if (as->parms[3].items) {
4420 MapPartIdIntoName(apart, pname);
4421 fprintf(STDOUT, "partition %s ", pname);
4424 fprintf(STDOUT, "which are prefixed with %s ", prefix);
4426 fprintf(STDOUT, "\n");
4429 /* Get all the VLDB entries on a server and/or partition */
4430 memset(&arrayEntries, 0, sizeof(arrayEntries));
4431 vcode = VLDB_ListAttributes(&attributes, &nentries, &arrayEntries);
4433 fprintf(STDERR, "Could not access the VLDB for attributes\n");
4434 PrintError("", vcode);
4438 /* Process each entry */
4439 for (j = 0; j < nentries; j++) {
4440 vllist = &arrayEntries.nbulkentries_val[j];
4442 /* It only deletes the RW volumes */
4443 if (strncmp(vllist->name, prefix, strlen(prefix))) {
4446 "Omitting to delete %s due to prefix %s mismatch\n",
4447 vllist->name, prefix);
4454 if (as->parms[4].items || as->parms[5].items) {
4455 /* -noexecute (hidden) or -dryrun */
4456 fprintf(STDOUT, "Would have deleted VLDB entry for %s \n",
4462 /* Only matches the RW volume name */
4463 avolid = vllist->volumeId[RWVOL];
4464 vcode = ubik_VL_DeleteEntry(cstruct, 0, avolid, RWVOL);
4466 fprintf(STDOUT, "Could not delete VLDB entry for %s\n",
4469 PrintError("", vcode);
4474 fprintf(STDOUT, "Deleted VLDB entry for %s \n", vllist->name);
4479 fprintf(STDOUT, "----------------------\n");
4481 "Total VLDB entries deleted: %lu; failed to delete: %lu\n",
4482 (unsigned long)totalBack, (unsigned long)totalFail);
4484 xdr_free((xdrproc_t) xdr_nbulkentries, &arrayEntries);
4490 CompareVldbEntryByName(const void *p1, const void *p2)
4492 struct nvldbentry *arg1, *arg2;
4494 arg1 = (struct nvldbentry *)p1;
4495 arg2 = (struct nvldbentry *)p2;
4496 return (strcmp(arg1->name, arg2->name));
4500 static int CompareVldbEntry(char *p1, char *p2)
4502 struct nvldbentry *arg1,*arg2;
4505 char comp1[100],comp2[100];
4506 char temp1[20],temp2[20];
4508 arg1 = (struct nvldbentry *)p1;
4509 arg2 = (struct nvldbentry *)p2;
4513 for(i = 0; i < arg1->nServers; i++)
4514 if(arg1->serverFlags[i] & VLSF_RWVOL) pos1 = i;
4515 for(i = 0; i < arg2->nServers; i++)
4516 if(arg2->serverFlags[i] & VLSF_RWVOL) pos2 = i;
4517 if(pos1 == -1 || pos2 == -1){
4521 sprintf(comp1,"%10u",arg1->serverNumber[pos1]);
4522 sprintf(comp2,"%10u",arg2->serverNumber[pos2]);
4523 sprintf(temp1,"%10u",arg1->serverPartition[pos1]);
4524 sprintf(temp2,"%10u",arg2->serverPartition[pos2]);
4525 strcat(comp1,temp1);
4526 strcat(comp2,temp2);
4527 strcat(comp1,arg1->name);
4528 strcat(comp1,arg2->name);
4529 return(strcmp(comp1,comp2));
4535 ListVLDB(struct cmd_syndesc *as, void *arock)
4540 struct VldbListByAttributes attributes;
4541 nbulkentries arrayEntries;
4542 struct nvldbentry *vllist, *tarray = 0, *ttarray;
4543 afs_int32 centries, nentries = 0;
4544 afs_int32 tarraysize = 0;
4545 afs_int32 parraysize;
4548 int quiet, sort, lock;
4549 afs_int32 thisindex, nextindex;
4553 memset(&attributes, 0, sizeof(attributes));
4554 lock = (as->parms[3].items ? 1 : 0); /* -lock flag */
4555 quiet = (as->parms[4].items ? 1 : 0); /* -quit flag */
4556 sort = (as->parms[5].items ? 0 : 1); /* -nosort flag */
4558 /* If the volume name is given, Use VolumeInfoCmd to look it up
4559 * and not ListAttributes.
4561 if (as->parms[0].items) {
4564 "vos: illegal use of '-locked' switch, need to specify server and/or partition\n");
4567 code = VolumeInfoCmd(as->parms[0].items->data);
4569 PrintError("", code);
4575 /* Server specified */
4576 if (as->parms[1].items) {
4579 aserver = GetServer(as->parms[1].items->data);
4581 fprintf(STDERR, "vos: server '%s' not found in host table\n",
4582 as->parms[1].items->data);
4585 attributes.server = ntohl(aserver);
4586 attributes.Mask |= VLLIST_SERVER;
4589 /* Partition specified */
4590 if (as->parms[2].items) {
4591 apart = volutil_GetPartitionID(as->parms[2].items->data);
4593 fprintf(STDERR, "vos: could not interpret partition name '%s'\n",
4594 as->parms[2].items->data);
4597 attributes.partition = apart;
4598 attributes.Mask |= VLLIST_PARTITION;
4602 attributes.Mask |= VLLIST_FLAG;
4603 attributes.flag = VLOP_ALLOPERS;
4606 /* Print header information */
4608 MapPartIdIntoName(apart, pname);
4609 fprintf(STDOUT, "VLDB entries for %s %s%s%s %s\n",
4610 (as->parms[1].items ? "server" : "all"),
4611 (as->parms[1].items ? as->parms[1].items->data : "servers"),
4612 (as->parms[2].items ? " partition " : ""),
4613 (as->parms[2].items ? pname : ""),
4614 (lock ? "which are locked:" : ""));
4617 for (thisindex = 0; (thisindex != -1); thisindex = nextindex) {
4618 memset(&arrayEntries, 0, sizeof(arrayEntries));
4623 VLDB_ListAttributesN2(&attributes, 0, thisindex, ¢ries,
4624 &arrayEntries, &nextindex);
4625 if (vcode == RXGEN_OPCODE) {
4626 /* Vlserver not running with ListAttributesN2. Fall back */
4628 VLDB_ListAttributes(&attributes, ¢ries, &arrayEntries);
4632 fprintf(STDERR, "Could not access the VLDB for attributes\n");
4633 PrintError("", vcode);
4636 nentries += centries;
4638 /* We don't sort, so just print the entries now */
4640 for (j = 0; j < centries; j++) { /* process each entry */
4641 vllist = &arrayEntries.nbulkentries_val[j];
4642 MapHostToNetwork(vllist);
4643 EnumerateEntry(vllist);
4645 PrintLocked(vllist->flags);
4649 /* So we sort. First we must collect all the entries and keep
4652 else if (centries > 0) {
4654 /* malloc the first bulk entries array */
4655 tarraysize = centries * sizeof(struct nvldbentry);
4656 tarray = malloc(tarraysize);
4659 "Could not allocate enough space for the VLDB entries\n");
4662 memcpy((char*)tarray, arrayEntries.nbulkentries_val, tarraysize);
4664 /* Grow the tarray to keep the extra entries */
4665 parraysize = (centries * sizeof(struct nvldbentry));
4666 ttarray = realloc(tarray, tarraysize + parraysize);
4669 "Could not allocate enough space for the VLDB entries\n");
4675 memcpy(((char *)tarray) + tarraysize,
4676 (char *)arrayEntries.nbulkentries_val, parraysize);
4677 tarraysize += parraysize;
4681 /* Free the bulk array */
4682 xdr_free((xdrproc_t) xdr_nbulkentries, &arrayEntries);
4685 /* Here is where we now sort all the entries and print them */
4686 if (sort && (nentries > 0)) {
4687 qsort((char *)tarray, nentries, sizeof(struct nvldbentry),
4688 CompareVldbEntryByName);
4689 for (vllist = tarray, j = 0; j < nentries; j++, vllist++) {
4690 MapHostToNetwork(vllist);
4691 EnumerateEntry(vllist);
4693 PrintLocked(vllist->flags);
4699 fprintf(STDOUT, "\nTotal entries: %lu\n", (unsigned long)nentries);
4706 BackSys(struct cmd_syndesc *as, void *arock)
4709 afs_int32 apart = 0;
4710 afs_uint32 aserver = 0, aserver1;
4711 afs_int32 code, apart1;
4713 struct VldbListByAttributes attributes;
4714 nbulkentries arrayEntries;
4715 struct nvldbentry *vllist;
4719 int seenprefix, seenxprefix, exclude, ex, exp, noaction;
4720 afs_int32 totalBack = 0;
4721 afs_int32 totalFail = 0;
4725 struct cmd_item *ti;
4727 #ifndef HAVE_POSIX_REGEX
4731 memset(&attributes, 0, sizeof(struct VldbListByAttributes));
4732 attributes.Mask = 0;
4734 seenprefix = (as->parms[0].items ? 1 : 0);
4735 exclude = (as->parms[3].items ? 1 : 0);
4736 seenxprefix = (as->parms[4].items ? 1 : 0);
4737 noaction = (as->parms[5].items ? 1 : 0);
4739 if (as->parms[1].items) { /* -server */
4740 aserver = GetServer(as->parms[1].items->data);
4742 fprintf(STDERR, "vos: server '%s' not found in host table\n",
4743 as->parms[1].items->data);
4746 attributes.server = ntohl(aserver);
4747 attributes.Mask |= VLLIST_SERVER;
4750 if (as->parms[2].items) { /* -partition */
4751 apart = volutil_GetPartitionID(as->parms[2].items->data);
4753 fprintf(STDERR, "vos: could not interpret partition name '%s'\n",
4754 as->parms[2].items->data);
4757 attributes.partition = apart;
4758 attributes.Mask |= VLLIST_PARTITION;
4761 /* Check to make sure the prefix and xprefix expressions compile ok */
4763 for (ti = as->parms[0].items; ti; ti = ti->next) {
4764 if (strncmp(ti->data, "^", 1) == 0) {
4765 #ifdef HAVE_POSIX_REGEX
4769 code = regcomp(&re, ti->data, REG_NOSUB);
4771 regerror(code, &re, errbuf, sizeof errbuf);
4773 "Unrecognizable -prefix regular expression: '%s': %s\n",
4779 ccode = (char *)re_comp(ti->data);
4782 "Unrecognizable -prefix regular expression: '%s': %s\n",
4791 for (ti = as->parms[4].items; ti; ti = ti->next) {
4792 if (strncmp(ti->data, "^", 1) == 0) {
4793 #ifdef HAVE_POSIX_REGEX
4797 code = regcomp(&re, ti->data, REG_NOSUB);
4799 regerror(code, &re, errbuf, sizeof errbuf);
4801 "Unrecognizable -xprefix regular expression: '%s': %s\n",
4807 ccode = (char *)re_comp(ti->data);
4810 "Unrecognizable -xprefix regular expression: '%s': %s\n",
4819 memset(&arrayEntries, 0, sizeof(arrayEntries)); /* initialize to hint the stub to alloc space */
4820 vcode = VLDB_ListAttributes(&attributes, &nentries, &arrayEntries);
4822 fprintf(STDERR, "Could not access the VLDB for attributes\n");
4823 PrintError("", vcode);
4827 if (as->parms[1].items || as->parms[2].items || verbose) {
4828 fprintf(STDOUT, "%s up volumes",
4829 (noaction ? "Would have backed" : "Backing"));
4831 if (as->parms[1].items) {
4832 fprintf(STDOUT, " on server %s", as->parms[1].items->data);
4833 } else if (as->parms[2].items) {
4834 fprintf(STDOUT, " for all servers");
4837 if (as->parms[2].items) {
4838 MapPartIdIntoName(apart, pname);
4839 fprintf(STDOUT, " partition %s", pname);
4842 if (seenprefix || (!seenprefix && seenxprefix)) {
4843 ti = (seenprefix ? as->parms[0].items : as->parms[4].items);
4844 ex = (seenprefix ? exclude : !exclude);
4845 exp = (strncmp(ti->data, "^", 1) == 0);
4846 fprintf(STDOUT, " which %smatch %s '%s'", (ex ? "do not " : ""),
4847 (exp ? "expression" : "prefix"), ti->data);
4848 for (ti = ti->next; ti; ti = ti->next) {
4849 exp = (strncmp(ti->data, "^", 1) == 0);
4850 printf(" %sor %s '%s'", (ex ? "n" : ""),
4851 (exp ? "expression" : "prefix"), ti->data);
4855 if (seenprefix && seenxprefix) {
4856 ti = as->parms[4].items;
4857 exp = (strncmp(ti->data, "^", 1) == 0);
4858 fprintf(STDOUT, " %swhich match %s '%s'",
4859 (exclude ? "adding those " : "removing those "),
4860 (exp ? "expression" : "prefix"), ti->data);
4861 for (ti = ti->next; ti; ti = ti->next) {
4862 exp = (strncmp(ti->data, "^", 1) == 0);
4863 printf(" or %s '%s'", (exp ? "expression" : "prefix"),
4867 fprintf(STDOUT, " .. ");
4869 fprintf(STDOUT, "\n");
4873 for (j = 0; j < nentries; j++) { /* process each vldb entry */
4874 vllist = &arrayEntries.nbulkentries_val[j];
4877 for (ti = as->parms[0].items; ti; ti = ti->next) {
4878 if (strncmp(ti->data, "^", 1) == 0) {
4879 #ifdef HAVE_POSIX_REGEX
4883 /* XXX -- should just do the compile once! */
4884 code = regcomp(&re, ti->data, REG_NOSUB);
4886 regerror(code, &re, errbuf, sizeof errbuf);
4888 "Error in -prefix regular expression: '%s': %s\n",
4892 match = (regexec(&re, vllist->name, 0, NULL, 0) == 0);
4895 ccode = (char *)re_comp(ti->data);
4898 "Error in -prefix regular expression: '%s': %s\n",
4902 match = (re_exec(vllist->name) == 1);
4906 (strncmp(vllist->name, ti->data, strlen(ti->data)) ==
4916 /* Without the -exclude flag: If it matches the prefix, then
4917 * check if we want to exclude any from xprefix.
4918 * With the -exclude flag: If it matches the prefix, then
4919 * check if we want to add any from xprefix.
4921 if (match && seenxprefix) {
4922 for (ti = as->parms[4].items; ti; ti = ti->next) {
4923 if (strncmp(ti->data, "^", 1) == 0) {
4924 #ifdef HAVE_POSIX_REGEX
4928 /* XXX -- should just do the compile once! */
4929 code = regcomp(&re, ti->data, REG_NOSUB);
4931 regerror(code, &re, errbuf, sizeof errbuf);
4933 "Error in -xprefix regular expression: '%s': %s\n",
4937 if (regexec(&re, vllist->name, 0, NULL, 0) == 0)
4941 ccode = (char *)re_comp(ti->data);
4944 "Error in -xprefix regular expression: '%s': %s\n",
4948 if (re_exec(vllist->name) == 1) {
4954 if (strncmp(vllist->name, ti->data, strlen(ti->data)) ==
4964 match = !match; /* -exclude will reverse the match */
4966 continue; /* Skip if no match */
4968 /* Print list of volumes to backup */
4970 fprintf(STDOUT, " %s\n", vllist->name);
4974 if (!(vllist->flags & VLF_RWEXISTS)) {
4977 "Omitting to backup %s since RW volume does not exist \n",
4979 fprintf(STDOUT, "\n");
4985 avolid = vllist->volumeId[RWVOL];
4986 MapHostToNetwork(vllist);
4987 GetServerAndPart(vllist, RWVOL, &aserver1, &apart1, &previdx);
4988 if (aserver1 == -1 || apart1 == -1) {
4989 fprintf(STDOUT, "could not backup %s, invalid VLDB entry\n",
4995 same = VLDB_IsSameAddrs(aserver, aserver1, &error);
4998 "Failed to get info about server's %d address(es) from vlserver (err=%d); aborting call!\n",
5004 if ((aserver && !same) || (apart && (apart != apart1))) {
5007 "Omitting to backup %s since the RW is in a different location\n",
5013 time_t now = time(0);
5014 fprintf(STDOUT, "Creating backup volume for %s on %s",
5015 vllist->name, ctime(&now));
5019 code = UV_BackupVolume(aserver1, apart1, avolid);
5021 fprintf(STDOUT, "Could not backup %s\n", vllist->name);
5027 fprintf(STDOUT, "\n");
5029 } /* process each vldb entry */
5030 fprintf(STDOUT, "done\n");
5031 fprintf(STDOUT, "Total volumes backed up: %lu; failed to backup: %lu\n",
5032 (unsigned long)totalBack, (unsigned long)totalFail);
5034 xdr_free((xdrproc_t) xdr_nbulkentries, &arrayEntries);
5039 UnlockVLDB(struct cmd_syndesc *as, void *arock)
5042 afs_uint32 aserver = 0;
5045 struct VldbListByAttributes attributes;
5046 nbulkentries arrayEntries;
5047 struct nvldbentry *vllist;
5056 memset(&attributes, 0, sizeof(attributes));
5058 if (as->parms[0].items) { /* server specified */
5059 aserver = GetServer(as->parms[0].items->data);
5061 fprintf(STDERR, "vos: server '%s' not found in host table\n",
5062 as->parms[0].items->data);
5065 attributes.server = ntohl(aserver);
5066 attributes.Mask |= VLLIST_SERVER;
5068 if (as->parms[1].items) { /* partition specified */
5069 apart = volutil_GetPartitionID(as->parms[1].items->data);
5071 fprintf(STDERR, "vos: could not interpret partition name '%s'\n",
5072 as->parms[1].items->data);
5075 if (!IsPartValid(apart, aserver, &code)) { /*check for validity of the partition */
5077 PrintError("", code);
5080 "vos : partition %s does not exist on the server\n",
5081 as->parms[1].items->data);
5084 attributes.partition = apart;
5085 attributes.Mask |= VLLIST_PARTITION;
5087 attributes.flag = VLOP_ALLOPERS;
5088 attributes.Mask |= VLLIST_FLAG;
5089 memset(&arrayEntries, 0, sizeof(arrayEntries)); /*initialize to hint the stub to alloc space */
5090 vcode = VLDB_ListAttributes(&attributes, &nentries, &arrayEntries);
5092 fprintf(STDERR, "Could not access the VLDB for attributes\n");
5093 PrintError("", vcode);
5096 for (j = 0; j < nentries; j++) { /* process each entry */
5097 vllist = &arrayEntries.nbulkentries_val[j];
5098 volid = vllist->volumeId[RWVOL];
5100 ubik_VL_ReleaseLock(cstruct, 0, volid, -1,
5101 LOCKREL_OPCODE | LOCKREL_AFSID |
5104 fprintf(STDERR, "Could not unlock entry for volume %s\n",
5106 PrintError("", vcode);
5111 MapPartIdIntoName(apart, pname);
5114 "Could not lock %lu VLDB entries of %lu locked entries\n",
5115 (unsigned long)totalE, (unsigned long)nentries);
5117 if (as->parms[0].items) {
5119 "Unlocked all the VLDB entries for volumes on server %s ",
5120 as->parms[0].items->data);
5121 if (as->parms[1].items) {
5122 MapPartIdIntoName(apart, pname);
5123 fprintf(STDOUT, "partition %s\n", pname);
5125 fprintf(STDOUT, "\n");
5127 } else if (as->parms[1].items) {
5128 MapPartIdIntoName(apart, pname);
5130 "Unlocked all the VLDB entries for volumes on partition %s on all servers\n",
5135 xdr_free((xdrproc_t) xdr_nbulkentries, &arrayEntries);
5140 PrintInt64Size(afs_uint64 in)
5144 static char output[16];
5146 SplitInt64(in,hi,lo);
5150 } else if (!(hi & 0xFFFFFC00)) {
5152 lo = (hi << 22) | (lo >> 10);
5153 } else if (!(hi & 0xFFF00000)) {
5155 lo = (hi << 12) | (lo >> 20);
5156 } else if (!(hi & 0xC0000000)) {
5158 lo = (hi << 2) | (lo >> 30);
5163 sprintf(output,"%u %s", lo, units);
5168 PartitionInfo(struct cmd_syndesc *as, void *arock)
5174 struct diskPartition64 partition;
5175 struct partList dummyPartList;
5177 int printSummary=0, sumPartitions=0;
5178 afs_uint64 sumFree, sumStorage;
5181 ZeroInt64(sumStorage);
5183 aserver = GetServer(as->parms[0].items->data);
5185 fprintf(STDERR, "vos: server '%s' not found in host table\n",
5186 as->parms[0].items->data);
5189 if (as->parms[1].items) {
5190 apart = volutil_GetPartitionID(as->parms[1].items->data);
5192 fprintf(STDERR, "vos: could not interpret partition name '%s'\n",
5193 as->parms[1].items->data);
5196 dummyPartList.partId[0] = apart;
5197 dummyPartList.partFlags[0] = PARTVALID;
5200 if (as->parms[2].items) {
5204 if (!IsPartValid(apart, aserver, &code)) { /*check for validity of the partition */
5206 PrintError("", code);
5209 "vos : partition %s does not exist on the server\n",
5210 as->parms[1].items->data);
5214 code = UV_ListPartitions(aserver, &dummyPartList, &cnt);
5216 PrintDiagnostics("listpart", code);
5220 for (i = 0; i < cnt; i++) {
5221 if (dummyPartList.partFlags[i] & PARTVALID) {
5222 MapPartIdIntoName(dummyPartList.partId[i], pname);
5223 code = UV_PartitionInfo64(aserver, pname, &partition);
5225 fprintf(STDERR, "Could not get information on partition %s\n",
5227 PrintError("", code);
5231 "Free space on partition %s: %" AFS_INT64_FMT " K blocks out of total %" AFS_INT64_FMT "\n",
5232 pname, partition.free, partition.minFree);
5234 AddUInt64(sumFree,partition.free,&sumFree);
5235 AddUInt64(sumStorage,partition.minFree,&sumStorage);
5240 "Summary: %s free out of ",
5241 PrintInt64Size(sumFree));
5243 "%s on %d partitions\n",
5244 PrintInt64Size(sumStorage),
5251 ChangeAddr(struct cmd_syndesc *as, void *arock)
5253 afs_int32 ip1, ip2, vcode;
5258 ip1 = GetServerNoresolve(as->parms[0].items->data);
5260 ip1 = GetServer(as->parms[0].items->data);
5262 fprintf(STDERR, "vos: invalid host address\n");
5266 if ((as->parms[1].items && as->parms[2].items)
5267 || (!as->parms[1].items && !as->parms[2].items)) {
5269 "vos: Must specify either '-newaddr <addr>' or '-remove' flag\n");
5273 if (as->parms[3].items) {
5277 if (as->parms[1].items) {
5279 ip2 = GetServerNoresolve(as->parms[1].items->data);
5281 ip2 = GetServer(as->parms[1].items->data);
5283 fprintf(STDERR, "vos: invalid host address\n");
5287 /* Play a trick here. If we are removing an address, ip1 will be -1
5288 * and ip2 will be the original address. This switch prevents an
5289 * older revision vlserver from removing the IP address.
5296 if (!remove && !force) {
5297 afs_int32 m_nentries;
5299 afs_int32 m_uniq = 0;
5301 ListAddrByAttributes m_attrs;
5304 memset(&m_attrs, 0, sizeof(m_attrs));
5305 memset(&m_uuid, 0, sizeof(m_uuid));
5306 memset(&m_addrs, 0, sizeof(m_addrs));
5307 memset(buffer, 0, sizeof(buffer));
5309 m_attrs.Mask = VLADDR_IPADDR;
5310 m_attrs.ipaddr = ntohl(ip1); /* -oldaddr */
5313 ubik_VL_GetAddrsU(cstruct, UBIK_CALL_NEW, &m_attrs, &m_uuid,
5314 &m_uniq, &m_nentries, &m_addrs);
5315 xdr_free((xdrproc_t) xdr_bulkaddrs, &m_addrs);
5317 case 0: /* mh entry detected */
5318 afsUUID_to_string(&m_uuid, buffer, sizeof(buffer) - 1);
5319 fprintf(STDERR, "vos: Refusing to change address in multi-homed server entry.\n");
5320 fprintf(STDERR, " -oldaddr address is registered to file server UUID %s\n", buffer);
5321 fprintf(STDERR, " Please restart the file server or use vos setaddrs.\n");
5326 fprintf(STDERR, "vos: could not list the server addresses\n");
5327 PrintError("", vcode);
5332 vcode = ubik_VL_ChangeAddr(cstruct, UBIK_CALL_NEW, ntohl(ip1), ntohl(ip2));
5334 char hoststr1[16], hoststr2[16];
5336 afs_inet_ntoa_r(ip2, hoststr2);
5337 fprintf(STDERR, "Could not remove server %s from the VLDB\n",
5339 if (vcode == VL_NOENT) {
5341 "vlserver does not support the remove flag or ");
5344 afs_inet_ntoa_r(ip1, hoststr1);
5345 afs_inet_ntoa_r(ip2, hoststr2);
5346 fprintf(STDERR, "Could not change server %s to server %s\n",
5347 hoststr1, hoststr2);
5349 PrintError("", vcode);
5354 fprintf(STDOUT, "Removed server %s from the VLDB\n",
5355 as->parms[0].items->data);
5357 fprintf(STDOUT, "Changed server %s to server %s\n",
5358 as->parms[0].items->data, as->parms[1].items->data);
5364 print_addrs(const bulkaddrs * addrs, afsUUID * m_uuid, int nentries,
5372 afsUUID_to_string(m_uuid, buf, sizeof(buf));
5373 printf("UUID: %s\n", buf);
5376 /* print out the list of all the server */
5377 for (i = 0; i < addrs->bulkaddrs_len; i++) {
5378 addr = htonl(addrs->bulkaddrs_val[i]);
5381 printf("%s\n", afs_inet_ntoa_r(addr, hoststr));
5383 printf("%s\n", hostutil_GetNameByINet(addr));
5394 ListAddrs(struct cmd_syndesc *as, void *arock)
5396 afs_int32 vcode, m_uniq=0;
5397 afs_int32 i, printuuid = 0;
5398 struct VLCallBack vlcb;
5401 ListAddrByAttributes m_attrs;
5402 afsUUID m_uuid, askuuid;
5403 afs_int32 m_nentries;
5405 if (as->parms[0].items && as->parms[1].items) {
5406 fprintf(STDERR, "vos: Can't use the -uuid and -host flags together\n");
5410 memset(&m_attrs, 0, sizeof(struct ListAddrByAttributes));
5411 memset(&askuuid, 0, sizeof(afsUUID));
5412 if (as->parms[0].items) {
5414 if (afsUUID_from_string(as->parms[0].items->data, &askuuid) < 0) {
5415 fprintf(STDERR, "vos: invalid UUID '%s'\n",
5416 as->parms[0].items->data);
5419 m_attrs.Mask = VLADDR_UUID;
5420 m_attrs.uuid = askuuid;
5421 } else if (as->parms[1].items) {
5425 he = hostutil_GetHostByName((char *)as->parms[1].items->data);
5427 fprintf(STDERR, "vos: Can't get host info for '%s'\n",
5428 as->parms[1].items->data);
5431 memcpy(&saddr, he->h_addr, 4);
5432 m_attrs.Mask = VLADDR_IPADDR;
5433 m_attrs.ipaddr = ntohl(saddr);
5436 m_attrs.Mask = VLADDR_INDEX;
5439 if (as->parms[2].items) {
5443 memset(&m_addrs, 0, sizeof(bulkaddrs));
5444 memset(&vlcb, 0, sizeof(struct VLCallBack));
5447 ubik_VL_GetAddrs(cstruct, UBIK_CALL_NEW, 0, 0, &vlcb, &nentries,
5450 fprintf(STDERR, "vos: could not list the server addresses\n");
5451 PrintError("", vcode);
5455 for (i = 1, m_nentries = 0; nentries; i++) {
5458 xdr_free((xdrproc_t)xdr_bulkaddrs, &m_addrs); /* reset addr list */
5460 ubik_VL_GetAddrsU(cstruct, UBIK_CALL_NEW, &m_attrs, &m_uuid,
5461 &m_uniq, &m_nentries, &m_addrs);
5463 case 0: /* success */
5464 print_addrs(&m_addrs, &m_uuid, m_nentries, printuuid);
5469 if (m_attrs.Mask == VLADDR_UUID) {
5470 fprintf(STDERR, "vos: no entry for UUID '%s' found in VLDB\n",
5471 as->parms[0].items->data);
5473 } else if (m_attrs.Mask == VLADDR_IPADDR) {
5474 fprintf(STDERR, "vos: no entry for host '%s' [0x%08x] found in VLDB\n",
5475 as->parms[1].items->data, m_attrs.ipaddr);
5480 case VL_INDEXERANGE:
5481 vcode = 0; /* not an error, just means we're done */
5484 default: /* any other error */
5485 fprintf(STDERR, "vos: could not list the server addresses\n");
5486 PrintError("", vcode);
5490 /* if -uuid or -host, only list one response */
5491 if (as->parms[1].items || as->parms[0].items)
5496 xdr_free((xdrproc_t)xdr_bulkaddrs, &m_addrs);
5502 SetAddrs(struct cmd_syndesc *as, void *arock)
5507 afs_uint32 FS_HostAddrs_HBO[ADDRSPERSITE];
5509 memset(&m_addrs, 0, sizeof(bulkaddrs));
5510 memset(&askuuid, 0, sizeof(afsUUID));
5511 if (as->parms[0].items) {
5513 if (afsUUID_from_string(as->parms[0].items->data, &askuuid) < 0) {
5514 fprintf(STDERR, "vos: invalid UUID '%s'\n",
5515 as->parms[0].items->data);
5519 if (as->parms[1].items) {
5521 struct cmd_item *ti;
5525 for (ti = as->parms[1].items; ti && i < ADDRSPERSITE; ti = ti->next) {
5528 saddr = GetServerNoresolve(ti->data);
5530 saddr = GetServer(ti->data);
5533 fprintf(STDERR, "vos: Can't get host info for '%s'\n",
5537 /* Convert it to host byte order */
5538 FS_HostAddrs_HBO[i] = ntohl(saddr);
5541 m_addrs.bulkaddrs_len = i;
5542 m_addrs.bulkaddrs_val = FS_HostAddrs_HBO;
5545 vcode = ubik_VL_RegisterAddrs(cstruct, 0, &askuuid, 0, &m_addrs);
5548 if (vcode == VL_MULTIPADDR) {
5549 fprintf(STDERR, "vos: VL_RegisterAddrs rpc failed; The IP address exists on a different server; repair it\n");
5550 } else if (vcode == RXGEN_OPCODE) {
5551 fprintf(STDERR, "vlserver doesn't support VL_RegisterAddrs rpc; ignored\n");
5553 fprintf(STDERR, "vos: VL_RegisterAddrs rpc failed\n");
5555 PrintError("", vcode);
5559 fprintf(STDOUT, "vos: Changed UUID with addresses:\n");
5560 print_addrs(&m_addrs, &askuuid, m_addrs.bulkaddrs_len, 1);
5566 RemoveAddrs(struct cmd_syndesc *as, void *arock)
5569 ListAddrByAttributes attrs;
5572 afs_int32 nentries = 0;
5577 memset(&attrs, 0, sizeof(ListAddrByAttributes));
5578 memset(&addrs, 0, sizeof(bulkaddrs));
5579 memset(&uuid, 0, sizeof(afsUUID));
5580 attrs.Mask = VLADDR_UUID;
5582 if (as->parms[0].items) { /* -uuid */
5583 if (afsUUID_from_string(as->parms[0].items->data, &attrs.uuid) < 0) {
5584 fprintf(STDERR, "vos: invalid UUID '%s'\n",
5585 as->parms[0].items->data);
5591 ubik_VL_GetAddrsU(cstruct, UBIK_CALL_NEW, &attrs, &uuid, &uniq,
5593 if (code == VL_NOENT) {
5594 fprintf(STDERR, "vos: UUID not found\n");
5598 fprintf(STDERR, "vos: could not list the server addresses\n");
5599 PrintError("", code);
5602 if (addrs.bulkaddrs_len == 0) {
5603 fprintf(STDERR, "vos: no addresses found for UUID\n");
5607 ip2 = addrs.bulkaddrs_val[0]; /* network byte order */
5608 ip1 = 0xffffffff; /* indicates removal mode */
5611 printf("vos: Removing UUID with hosts:\n");
5612 print_addrs(&addrs, &uuid, nentries, 1);
5615 code = ubik_VL_ChangeAddr(cstruct, UBIK_CALL_NEW, ip1, ip2);
5617 fprintf(STDERR, "Could not remove server entry from the VLDB.\n");
5618 PrintError("", code);
5622 xdr_free((xdrproc_t) xdr_bulkaddrs, &addrs);
5628 LockEntry(struct cmd_syndesc *as, void *arock)
5631 afs_int32 vcode, err;
5633 avolid = vsu_GetVolumeID(as->parms[0].items->data, cstruct, &err);
5636 PrintError("", err);
5638 fprintf(STDERR, "vos: can't find volume '%s'\n",
5639 as->parms[0].items->data);
5642 vcode = ubik_VL_SetLock(cstruct, 0, avolid, -1, VLOP_DELETE);
5644 fprintf(STDERR, "Could not lock VLDB entry for volume %s\n",
5645 as->parms[0].items->data);
5646 PrintError("", vcode);
5649 fprintf(STDOUT, "Locked VLDB entry for volume %s\n",
5650 as->parms[0].items->data);
5655 ConvertRO(struct cmd_syndesc *as, void *arock)
5657 afs_int32 partition = -1;
5660 afs_int32 code, i, same;
5661 struct nvldbentry entry;
5663 afs_uint32 rwserver = 0;
5664 afs_int32 rwpartition = 0;
5665 afs_uint32 roserver = 0;
5666 afs_int32 ropartition = 0;
5670 server = GetServer(as->parms[0].items->data);
5672 fprintf(STDERR, "vos: host '%s' not found in host table\n",
5673 as->parms[0].items->data);
5676 partition = volutil_GetPartitionID(as->parms[1].items->data);
5677 if (partition < 0) {
5678 fprintf(STDERR, "vos: could not interpret partition name '%s'\n",
5679 as->parms[1].items->data);
5682 if (!IsPartValid(partition, server, &code)) {
5684 PrintError("", code);
5687 "vos : partition %s does not exist on the server\n",
5688 as->parms[1].items->data);
5691 volid = vsu_GetVolumeID(as->parms[2].items->data, cstruct, &code);
5694 PrintError("", code);
5696 fprintf(STDERR, "Unknown volume ID or name '%s'\n",
5697 as->parms[2].items->data);
5700 if (as->parms[3].items)
5703 memset(&entry, 0, sizeof(entry));
5704 vcode = VLDB_GetEntryByID(volid, -1, &entry);
5707 "Could not fetch the entry for volume %lu from VLDB\n",
5708 (unsigned long)volid);
5709 PrintError("convertROtoRW ", vcode);
5713 /* use RO volid even if user specified RW or BK volid */
5714 if (volid != entry.volumeId[ROVOL])
5715 volid = entry.volumeId[ROVOL];
5717 MapHostToNetwork(&entry);
5718 for (i = 0; i < entry.nServers; i++) {
5719 if (entry.serverFlags[i] & VLSF_RWVOL) {
5720 rwserver = entry.serverNumber[i];
5721 rwpartition = entry.serverPartition[i];
5724 } else if ((entry.serverFlags[i] & VLSF_ROVOL) && !roserver) {
5725 same = VLDB_IsSameAddrs(server, entry.serverNumber[i], &code);
5728 "Failed to get info about server's %d address(es) from vlserver (err=%d); aborting call!\n",
5733 roserver = entry.serverNumber[i];
5734 ropartition = entry.serverPartition[i];
5741 fprintf(STDERR, "Warning: RO volume didn't exist in vldb!\n");
5743 if (roserver && (ropartition != partition)) {
5745 "Warning: RO volume should be in partition %d instead of %d (vldb)\n",
5746 ropartition, partition);
5751 "VLDB indicates that a RW volume exists already on %s in partition %s.\n",
5752 hostutil_GetNameByINet(rwserver),
5753 volutil_PartitionName(rwpartition));
5755 fprintf(STDERR, "Overwrite this VLDB entry? [y|n] (n)\n");
5757 while (!(dc == EOF || dc == '\n'))
5758 dc = getchar(); /* goto end of line */
5759 if ((c != 'y') && (c != 'Y')) {
5760 fprintf(STDERR, "aborted.\n");
5766 code = UV_ConvertRO(server, partition, volid, &entry);
5772 Sizes(struct cmd_syndesc *as, void *arock)
5776 afs_int32 apart, voltype, fromdate = 0, code, err, i;
5777 struct nvldbentry entry;
5778 volintSize vol_size;
5780 rx_SetRxDeadTime(60 * 10);
5781 for (i = 0; i < MAXSERVERS; i++) {
5782 struct rx_connection *rxConn = ubik_GetRPCConn(cstruct, i);
5785 rx_SetConnDeadTime(rxConn, rx_connDeadTime);
5786 if (rx_ServiceOf(rxConn))
5787 rx_ServiceOf(rxConn)->connDeadTime = rx_connDeadTime;
5790 avolid = vsu_GetVolumeID(as->parms[0].items->data, cstruct, &err);
5793 PrintError("", err);
5795 fprintf(STDERR, "vos: can't find volume '%s'\n",
5796 as->parms[0].items->data);
5800 if (as->parms[1].items || as->parms[2].items) {
5801 if (!as->parms[1].items || !as->parms[2].items) {
5803 "Must specify both -server and -partition options\n");
5806 aserver = GetServer(as->parms[2].items->data);
5808 fprintf(STDERR, "Invalid server name\n");
5811 apart = volutil_GetPartitionID(as->parms[1].items->data);
5813 fprintf(STDERR, "Invalid partition name\n");
5817 code = GetVolumeInfo(avolid, &aserver, &apart, &voltype, &entry);
5824 if (as->parms[4].items && strcmp(as->parms[4].items->data, "0")) {
5825 code = ktime_DateToInt32(as->parms[4].items->data, &fromdate);
5827 fprintf(STDERR, "vos: failed to parse date '%s' (error=%d))\n",
5828 as->parms[4].items->data, code);
5833 fprintf(STDOUT, "Volume: %s\n", as->parms[0].items->data);
5835 if (as->parms[3].items) { /* do the dump estimate */
5836 vol_size.dump_size = 0;
5837 code = UV_GetSize(avolid, aserver, apart, fromdate, &vol_size);
5839 PrintDiagnostics("size", code);
5842 /* presumably the size info is now gathered in pntr */
5843 /* now we display it */
5845 fprintf(STDOUT, "dump_size: %llu\n", vol_size.dump_size);
5854 EndTrans(struct cmd_syndesc *as, void *arock)
5857 afs_int32 code, tid, rcode;
5858 struct rx_connection *aconn;
5860 server = GetServer(as->parms[0].items->data);
5862 fprintf(STDERR, "vos: host '%s' not found in host table\n",
5863 as->parms[0].items->data);
5867 code = util_GetInt32(as->parms[1].items->data, &tid);
5869 fprintf(STDERR, "vos: bad integer specified for transaction ID.\n");
5873 aconn = UV_Bind(server, AFSCONF_VOLUMEPORT);
5874 code = AFSVolEndTrans(aconn, tid, &rcode);
5880 PrintDiagnostics("endtrans", code);
5888 PrintDiagnostics(char *astring, afs_int32 acode)
5893 "You are not authorized to perform the 'vos %s' command (%d)\n",
5897 fprintf(STDERR, "Error in vos %s command.\n", astring);
5898 fprintf(STDERR, "Clone volume is not in the same partition as the read-write volume.\n");
5901 fprintf(STDERR, "Error in vos %s command.\n", astring);
5902 PrintError("", acode);
5911 win32_enableCrypt(void)
5918 /* Look up configuration parameters in Registry */
5919 code = RegOpenKeyEx(HKEY_LOCAL_MACHINE, AFSREG_CLT_SVC_PARAM_SUBKEY,
5920 0, (IsWow64()?KEY_WOW64_64KEY:0)|KEY_QUERY_VALUE, &parmKey);
5921 if (code != ERROR_SUCCESS) {
5922 dummyLen = sizeof(cryptall);
5923 RegQueryValueEx(parmKey, "SecurityLevel", NULL, NULL,
5924 (BYTE *) &cryptall, &dummyLen);
5926 RegCloseKey (parmKey);
5930 #endif /* AFS_NT40_ENV */
5933 MyBeforeProc(struct cmd_syndesc *as, void *arock)
5936 char *rxgk_seclevel_str = NULL;
5940 /* Initialize the ubik_client connection */
5941 rx_SetRxDeadTime(90);
5943 secFlags = AFSCONF_SECOPTS_FALLBACK_NULL;
5946 if (as->parms[COMMONPARM_OFFSET_CELL].items) /* if -cell specified */
5947 tcell = as->parms[COMMONPARM_OFFSET_CELL].items->data;
5949 if (as->parms[COMMONPARM_OFFSET_NOAUTH].items)
5950 secFlags |= AFSCONF_SECOPTS_NOAUTH;
5952 if (as->parms[COMMONPARM_OFFSET_LOCALAUTH].items) { /* -localauth specified */
5953 secFlags |= AFSCONF_SECOPTS_LOCALAUTH;
5954 confdir = AFSDIR_SERVER_ETC_DIRPATH;
5957 if (as->parms[COMMONPARM_OFFSET_ENCRYPT].items /* -encrypt specified */
5959 || win32_enableCrypt()
5960 #endif /* AFS_NT40_ENV */
5962 secFlags |= AFSCONF_SECOPTS_ALWAYSENCRYPT;
5964 if (as->parms[COMMONPARM_OFFSET_CONFIG].items) /* -config flag set */
5965 confdir = as->parms[COMMONPARM_OFFSET_CONFIG].items->data;
5967 if (cmd_OptionAsString(as, COMMONPARM_OFFSET_RXGK, &rxgk_seclevel_str) == 0) {
5968 if (strcmp(rxgk_seclevel_str, "clear") == 0)
5969 secFlags |= AFSCONF_SECOPTS_ALWAYSCLEAR;
5970 else if (strcmp(rxgk_seclevel_str, "auth") == 0)
5971 secFlags |= AFSCONF_SECOPTS_NEVERENCRYPT;
5972 else if (strcmp(rxgk_seclevel_str, "crypt") == 0) {
5973 /* don't need to set any flags; this is the default for rxgk */
5975 fprintf(STDERR, "Invalid argument to -rxgk: %s\n", rxgk_seclevel_str);
5978 secFlags |= AFSCONF_SECOPTS_RXGK;
5980 free(rxgk_seclevel_str);
5981 rxgk_seclevel_str = NULL;
5984 if ((code = vsu_ClientInit(confdir, tcell, secFlags, UV_SetSecurity,
5986 fprintf(STDERR, "could not initialize VLDB library (code=%lu) \n",
5987 (unsigned long)code);
5991 if (as->parms[COMMONPARM_OFFSET_VERBOSE].items) /* -verbose flag set */
5995 if (as->parms[COMMONPARM_OFFSET_NORESOLVE].items) /* -noresolve flag set */
6006 /* this sucks but it works for now.
6011 #include "AFS_component_version_number.c"
6014 main(int argc, char **argv)
6018 struct cmd_syndesc *ts;
6020 #ifdef AFS_AIX32_ENV
6022 * The following signal action for AIX is necessary so that in case of a
6023 * crash (i.e. core is generated) we can include the user's data section
6024 * in the core dump. Unfortunately, by default, only a partial core is
6025 * generated which, in many cases, isn't too useful.
6027 struct sigaction nsa;
6029 sigemptyset(&nsa.sa_mask);
6030 nsa.sa_handler = SIG_DFL;
6031 nsa.sa_flags = SA_FULLDUMP;
6032 sigaction(SIGSEGV, &nsa, NULL);
6035 confdir = AFSDIR_CLIENT_ETC_DIRPATH;
6037 cmd_SetBeforeProc(MyBeforeProc, NULL);
6039 ts = cmd_CreateSyntax("create", CreateVolume, NULL, 0, "create a new volume");
6040 cmd_AddParm(ts, "-server", CMD_SINGLE, 0, "machine name");
6041 cmd_AddParm(ts, "-partition", CMD_SINGLE, 0, "partition name");
6042 cmd_AddParm(ts, "-name", CMD_SINGLE, 0, "volume name");
6043 cmd_AddParm(ts, "-maxquota", CMD_SINGLE, CMD_OPTIONAL,
6044 "initial quota (KB)");
6045 cmd_AddParm(ts, "-id", CMD_SINGLE, CMD_OPTIONAL, "volume ID");
6046 cmd_AddParm(ts, "-roid", CMD_SINGLE, CMD_OPTIONAL, "readonly volume ID");
6048 cmd_AddParm(ts, "-minquota", CMD_SINGLE, CMD_OPTIONAL, "");
6052 ts = cmd_CreateSyntax("remove", DeleteVolume, NULL, 0, "delete a volume");
6053 cmd_AddParm(ts, "-server", CMD_SINGLE, CMD_OPTIONAL, "machine name");
6054 cmd_AddParm(ts, "-partition", CMD_SINGLE, CMD_OPTIONAL, "partition name");
6055 cmd_AddParm(ts, "-id", CMD_SINGLE, 0, "volume name or ID");
6059 ts = cmd_CreateSyntax("move", MoveVolume, NULL, 0, "move a volume");
6060 cmd_AddParm(ts, "-id", CMD_SINGLE, 0, "volume name or ID");
6061 cmd_AddParm(ts, "-fromserver", CMD_SINGLE, 0, "machine name on source");
6062 cmd_AddParm(ts, "-frompartition", CMD_SINGLE, 0,
6063 "partition name on source");
6064 cmd_AddParm(ts, "-toserver", CMD_SINGLE, 0,
6065 "machine name on destination");
6066 cmd_AddParm(ts, "-topartition", CMD_SINGLE, 0,
6067 "partition name on destination");
6068 cmd_AddParm(ts, "-live", CMD_FLAG, CMD_OPTIONAL,
6069 "copy live volume without cloning");
6072 ts = cmd_CreateSyntax("copy", CopyVolume, NULL, 0, "copy a volume");
6073 cmd_AddParm(ts, "-id", CMD_SINGLE, 0, "volume name or ID on source");
6074 cmd_AddParm(ts, "-fromserver", CMD_SINGLE, 0, "machine name on source");
6075 cmd_AddParm(ts, "-frompartition", CMD_SINGLE, 0,
6076 "partition name on source");
6077 cmd_AddParm(ts, "-toname", CMD_SINGLE, 0, "volume name on destination");
6078 cmd_AddParm(ts, "-toserver", CMD_SINGLE, 0,
6079 "machine name on destination");
6080 cmd_AddParm(ts, "-topartition", CMD_SINGLE, 0,
6081 "partition name on destination");
6082 cmd_AddParm(ts, "-offline", CMD_FLAG, CMD_OPTIONAL,
6083 "leave new volume offline");
6084 cmd_AddParm(ts, "-readonly", CMD_FLAG, CMD_OPTIONAL,
6085 "make new volume read-only");
6086 cmd_AddParm(ts, "-live", CMD_FLAG, CMD_OPTIONAL,
6087 "copy live volume without cloning");
6090 ts = cmd_CreateSyntax("shadow", ShadowVolume, NULL, 0,
6091 "make or update a shadow volume");
6092 cmd_AddParm(ts, "-id", CMD_SINGLE, 0, "volume name or ID on source");
6093 cmd_AddParm(ts, "-fromserver", CMD_SINGLE, 0, "machine name on source");
6094 cmd_AddParm(ts, "-frompartition", CMD_SINGLE, 0,
6095 "partition name on source");
6096 cmd_AddParm(ts, "-toserver", CMD_SINGLE, 0,
6097 "machine name on destination");
6098 cmd_AddParm(ts, "-topartition", CMD_SINGLE, 0,
6099 "partition name on destination");
6100 cmd_AddParm(ts, "-toname", CMD_SINGLE, CMD_OPTIONAL,
6101 "volume name on destination");
6102 cmd_AddParm(ts, "-toid", CMD_SINGLE, CMD_OPTIONAL,
6103 "volume ID on destination");
6104 cmd_AddParm(ts, "-offline", CMD_FLAG, CMD_OPTIONAL,
6105 "leave shadow volume offline");
6106 cmd_AddParm(ts, "-readonly", CMD_FLAG, CMD_OPTIONAL,
6107 "make shadow volume read-only");
6108 cmd_AddParm(ts, "-live", CMD_FLAG, CMD_OPTIONAL,
6109 "copy live volume without cloning");
6110 cmd_AddParm(ts, "-incremental", CMD_FLAG, CMD_OPTIONAL,
6111 "do incremental update if target exists");
6114 ts = cmd_CreateSyntax("backup", BackupVolume, NULL, 0,
6115 "make backup of a volume");
6116 cmd_AddParm(ts, "-id", CMD_SINGLE, 0, "volume name or ID");
6119 ts = cmd_CreateSyntax("clone", CloneVolume, NULL, 0,
6120 "make clone of a volume");
6121 cmd_AddParm(ts, "-id", CMD_SINGLE, 0, "volume name or ID");
6122 cmd_AddParm(ts, "-server", CMD_SINGLE, CMD_OPTIONAL, "server");
6123 cmd_AddParm(ts, "-partition", CMD_SINGLE, CMD_OPTIONAL, "partition");
6124 cmd_AddParm(ts, "-toname", CMD_SINGLE, CMD_OPTIONAL,
6125 "volume name on destination");
6126 cmd_AddParm(ts, "-toid", CMD_SINGLE, CMD_OPTIONAL,
6127 "volume ID on destination");
6128 cmd_AddParm(ts, "-offline", CMD_FLAG, CMD_OPTIONAL,
6129 "leave clone volume offline");
6130 cmd_AddParm(ts, "-readonly", CMD_FLAG, CMD_OPTIONAL,
6131 "make clone volume read-only, not readwrite");
6132 cmd_AddParm(ts, "-readwrite", CMD_FLAG, CMD_OPTIONAL,
6133 "make clone volume readwrite, not read-only");
6136 ts = cmd_CreateSyntax("release", ReleaseVolume, NULL, 0, "release a volume");
6137 cmd_AddParm(ts, "-id", CMD_SINGLE, 0, "volume name or ID");
6138 cmd_AddParm(ts, "-force", CMD_FLAG, CMD_OPTIONAL,
6139 "force a complete release and full dumps");
6140 cmd_AddParmAlias(ts, 1, "-f"); /* original force option */
6141 /* keep this reserved */
6142 cmd_AddParm(ts, "-stayonline", CMD_FLAG, CMD_OPTIONAL|CMD_HIDDEN,
6143 "release to cloned temp vol, then clone back to repsite RO");
6144 cmd_AddParm(ts, "-force-reclone", CMD_FLAG, CMD_OPTIONAL,
6145 "force a reclone and complete release with incremental dumps");
6148 ts = cmd_CreateSyntax("dump", DumpVolumeCmd, NULL, 0, "dump a volume");
6149 cmd_AddParm(ts, "-id", CMD_SINGLE, 0, "volume name or ID");
6150 cmd_AddParm(ts, "-time", CMD_SINGLE, CMD_OPTIONAL, "dump from time");
6151 cmd_AddParm(ts, "-file", CMD_SINGLE, CMD_OPTIONAL, "dump file");
6152 cmd_AddParm(ts, "-server", CMD_SINGLE, CMD_OPTIONAL, "server");
6153 cmd_AddParm(ts, "-partition", CMD_SINGLE, CMD_OPTIONAL, "partition");
6154 cmd_AddParm(ts, "-clone", CMD_FLAG, CMD_OPTIONAL,
6155 "dump a clone of the volume");
6156 cmd_AddParm(ts, "-omitdirs", CMD_FLAG, CMD_OPTIONAL,
6157 "omit unchanged directories from an incremental dump");
6160 ts = cmd_CreateSyntax("restore", RestoreVolumeCmd, NULL, 0,
6161 "restore a volume");
6162 cmd_AddParm(ts, "-server", CMD_SINGLE, 0, "machine name");
6163 cmd_AddParm(ts, "-partition", CMD_SINGLE, 0, "partition name");
6164 cmd_AddParm(ts, "-name", CMD_SINGLE, 0, "name of volume to be restored");
6165 cmd_AddParm(ts, "-file", CMD_SINGLE, CMD_OPTIONAL, "dump file");
6166 cmd_AddParm(ts, "-id", CMD_SINGLE, CMD_OPTIONAL, "volume ID");
6167 cmd_AddParm(ts, "-overwrite", CMD_SINGLE, CMD_OPTIONAL,
6168 "abort | full | incremental");
6169 cmd_AddParm(ts, "-offline", CMD_FLAG, CMD_OPTIONAL,
6170 "leave restored volume offline");
6171 cmd_AddParm(ts, "-readonly", CMD_FLAG, CMD_OPTIONAL,
6172 "make restored volume read-only");
6173 cmd_AddParm(ts, "-creation", CMD_SINGLE, CMD_OPTIONAL,
6174 "dump | keep | new");
6175 cmd_AddParm(ts, "-lastupdate", CMD_SINGLE, CMD_OPTIONAL,
6176 "dump | keep | new");
6177 cmd_AddParm(ts, "-nodelete", CMD_FLAG, CMD_OPTIONAL,
6178 "do not delete old site when restoring to a new site");
6181 ts = cmd_CreateSyntax("unlock", LockReleaseCmd, NULL, 0,
6182 "release lock on VLDB entry for a volume");
6183 cmd_AddParm(ts, "-id", CMD_SINGLE, 0, "volume name or ID");
6186 ts = cmd_CreateSyntax("changeloc", ChangeLocation, NULL, 0,
6187 "change an RW volume's location in the VLDB");
6188 cmd_AddParm(ts, "-server", CMD_SINGLE, 0,
6189 "machine name for new location");
6190 cmd_AddParm(ts, "-partition", CMD_SINGLE, 0,
6191 "partition name for new location");
6192 cmd_AddParm(ts, "-id", CMD_SINGLE, 0, "volume name or ID");
6195 ts = cmd_CreateSyntax("addsite", AddSite, NULL, 0, "add a replication site");
6196 cmd_AddParm(ts, "-server", CMD_SINGLE, 0, "machine name for new site");
6197 cmd_AddParm(ts, "-partition", CMD_SINGLE, 0,
6198 "partition name for new site");
6199 cmd_AddParm(ts, "-id", CMD_SINGLE, 0, "volume name or ID");
6200 cmd_AddParm(ts, "-roid", CMD_SINGLE, CMD_OPTIONAL, "volume name or ID for RO");
6201 cmd_AddParm(ts, "-valid", CMD_FLAG, CMD_OPTIONAL, "publish as an up-to-date site in VLDB");
6204 ts = cmd_CreateSyntax("remsite", RemoveSite, NULL, 0,
6205 "remove a replication site");
6206 cmd_AddParm(ts, "-server", CMD_SINGLE, 0, "machine name");
6207 cmd_AddParm(ts, "-partition", CMD_SINGLE, 0, "partition name");
6208 cmd_AddParm(ts, "-id", CMD_SINGLE, 0, "volume name or ID");
6211 ts = cmd_CreateSyntax("listpart", ListPartitions, NULL, 0, "list partitions");
6212 cmd_AddParm(ts, "-server", CMD_SINGLE, 0, "machine name");
6215 ts = cmd_CreateSyntax("listvol", ListVolumes, NULL, 0,
6216 "list volumes on server (bypass VLDB)");
6217 cmd_AddParm(ts, "-server", CMD_SINGLE, 0, "machine name");
6218 cmd_AddParm(ts, "-partition", CMD_SINGLE, CMD_OPTIONAL, "partition name");
6219 cmd_AddParm(ts, "-fast", CMD_FLAG, CMD_OPTIONAL, "minimal listing");
6220 cmd_AddParm(ts, "-long", CMD_FLAG, CMD_OPTIONAL,
6221 "list all normal volume fields");
6222 cmd_AddParm(ts, "-quiet", CMD_FLAG, CMD_OPTIONAL,
6223 "generate minimal information");
6224 cmd_AddParm(ts, "-extended", CMD_FLAG, CMD_OPTIONAL,
6225 "list extended volume fields");
6226 cmd_AddParm(ts, "-format", CMD_FLAG, CMD_OPTIONAL,
6227 "machine readable format");
6230 ts = cmd_CreateSyntax("syncvldb", SyncVldb, NULL, 0,
6231 "synchronize VLDB with server");
6232 cmd_AddParm(ts, "-server", CMD_SINGLE, CMD_OPTIONAL, "machine name");
6233 cmd_AddParm(ts, "-partition", CMD_SINGLE, CMD_OPTIONAL, "partition name");
6234 cmd_AddParm(ts, "-volume", CMD_SINGLE, CMD_OPTIONAL, "volume name or ID");
6235 cmd_AddParm(ts, "-dryrun", CMD_FLAG, CMD_OPTIONAL, "list what would be done, don't do it");
6238 ts = cmd_CreateSyntax("syncserv", SyncServer, NULL, 0,
6239 "synchronize server with VLDB");
6240 cmd_AddParm(ts, "-server", CMD_SINGLE, 0, "machine name");
6241 cmd_AddParm(ts, "-partition", CMD_SINGLE, CMD_OPTIONAL, "partition name");
6242 cmd_AddParm(ts, "-dryrun", CMD_FLAG, CMD_OPTIONAL, "list what would be done, don't do it");
6245 ts = cmd_CreateSyntax("examine", ExamineVolume, NULL, 0,
6246 "everything about the volume");
6247 cmd_AddParm(ts, "-id", CMD_SINGLE, 0, "volume name or ID");
6248 cmd_AddParm(ts, "-extended", CMD_FLAG, CMD_OPTIONAL,
6249 "list extended volume fields");
6250 cmd_AddParm(ts, "-format", CMD_FLAG, CMD_OPTIONAL,
6251 "machine readable format");
6253 cmd_CreateAlias(ts, "volinfo");
6254 cmd_CreateAlias(ts, "e");
6256 ts = cmd_CreateSyntax("setfields", SetFields, NULL, 0,
6257 "change volume info fields");
6258 cmd_AddParm(ts, "-id", CMD_SINGLE, 0, "volume name or ID");
6259 cmd_AddParm(ts, "-maxquota", CMD_SINGLE, CMD_OPTIONAL, "quota (KB)");
6260 cmd_AddParm(ts, "-clearuse", CMD_FLAG, CMD_OPTIONAL, "clear dayUse");
6261 cmd_AddParm(ts, "-clearVolUpCounter", CMD_FLAG, CMD_OPTIONAL, "clear volUpdateCounter");
6264 ts = cmd_CreateSyntax("offline", volOffline, NULL, 0, "force the volume status to offline");
6265 cmd_AddParm(ts, "-server", CMD_SINGLE, 0, "server name");
6266 cmd_AddParm(ts, "-partition", CMD_SINGLE, 0, "partition name");
6267 cmd_AddParm(ts, "-id", CMD_SINGLE, 0, "volume name or ID");
6268 cmd_AddParm(ts, "-sleep", CMD_SINGLE, CMD_OPTIONAL, "seconds to sleep");
6269 cmd_AddParm(ts, "-busy", CMD_FLAG, CMD_OPTIONAL, "busy volume");
6272 ts = cmd_CreateSyntax("online", volOnline, NULL, 0, "force the volume status to online");
6273 cmd_AddParm(ts, "-server", CMD_SINGLE, 0, "server name");
6274 cmd_AddParm(ts, "-partition", CMD_SINGLE, 0, "partition name");
6275 cmd_AddParm(ts, "-id", CMD_SINGLE, 0, "volume name or ID");
6278 ts = cmd_CreateSyntax("zap", VolumeZap, NULL, 0,
6279 "delete the volume, don't bother with VLDB");
6280 cmd_AddParm(ts, "-server", CMD_SINGLE, 0, "machine name");
6281 cmd_AddParm(ts, "-partition", CMD_SINGLE, 0, "partition name");
6282 cmd_AddParm(ts, "-id", CMD_SINGLE, 0, "volume ID");
6283 cmd_AddParm(ts, "-force", CMD_FLAG, CMD_OPTIONAL,
6284 "force deletion of bad volumes");
6285 cmd_AddParm(ts, "-backup", CMD_FLAG, CMD_OPTIONAL,
6286 "also delete backup volume if one is found");
6289 ts = cmd_CreateSyntax("status", VolserStatus, NULL, 0,
6290 "report on volser status");
6291 cmd_AddParm(ts, "-server", CMD_SINGLE, 0, "machine name");
6294 ts = cmd_CreateSyntax("rename", RenameVolume, NULL, 0, "rename a volume");
6295 cmd_AddParm(ts, "-oldname", CMD_SINGLE, 0, "old volume name ");
6296 cmd_AddParm(ts, "-newname", CMD_SINGLE, 0, "new volume name ");
6299 ts = cmd_CreateSyntax("listvldb", ListVLDB, NULL, 0,
6300 "list volumes in the VLDB");
6301 cmd_AddParm(ts, "-name", CMD_SINGLE, CMD_OPTIONAL, "volume name or ID");
6302 cmd_AddParm(ts, "-server", CMD_SINGLE, CMD_OPTIONAL, "machine name");
6303 cmd_AddParm(ts, "-partition", CMD_SINGLE, CMD_OPTIONAL, "partition name");
6304 cmd_AddParm(ts, "-locked", CMD_FLAG, CMD_OPTIONAL, "locked volumes only");
6305 cmd_AddParm(ts, "-quiet", CMD_FLAG, CMD_OPTIONAL,
6306 "generate minimal information");
6307 cmd_AddParm(ts, "-nosort", CMD_FLAG, CMD_OPTIONAL,
6308 "do not alphabetically sort the volume names");
6311 ts = cmd_CreateSyntax("backupsys", BackSys, NULL, 0, "en masse backups");
6312 cmd_AddParm(ts, "-prefix", CMD_LIST, CMD_OPTIONAL,
6313 "common prefix on volume(s)");
6314 cmd_AddParm(ts, "-server", CMD_SINGLE, CMD_OPTIONAL, "machine name");
6315 cmd_AddParm(ts, "-partition", CMD_SINGLE, CMD_OPTIONAL, "partition name");
6316 cmd_AddParm(ts, "-exclude", CMD_FLAG, CMD_OPTIONAL,
6317 "exclude common prefix volumes");
6318 cmd_AddParm(ts, "-xprefix", CMD_LIST, CMD_OPTIONAL,
6319 "negative prefix on volume(s)");
6320 cmd_AddParm(ts, "-dryrun", CMD_FLAG, CMD_OPTIONAL, "list what would be done, don't do it");
6323 ts = cmd_CreateSyntax("delentry", DeleteEntry, NULL, 0,
6324 "delete VLDB entry for a volume");
6325 cmd_AddParm(ts, "-id", CMD_LIST, CMD_OPTIONAL, "volume name or ID");
6326 cmd_AddParm(ts, "-prefix", CMD_SINGLE, CMD_OPTIONAL,
6327 "prefix of the volume whose VLDB entry is to be deleted");
6328 cmd_AddParm(ts, "-server", CMD_SINGLE, CMD_OPTIONAL, "machine name");
6329 cmd_AddParm(ts, "-partition", CMD_SINGLE, CMD_OPTIONAL, "partition name");
6330 cmd_AddParm(ts, "-noexecute", CMD_FLAG, CMD_OPTIONAL|CMD_HIDDEN, "");
6331 cmd_AddParm(ts, "-dryrun", CMD_FLAG, CMD_OPTIONAL,
6332 "list what would be done, don't do it");
6335 ts = cmd_CreateSyntax("partinfo", PartitionInfo, NULL, 0,
6336 "list partition information");
6337 cmd_AddParm(ts, "-server", CMD_SINGLE, 0, "machine name");
6338 cmd_AddParm(ts, "-partition", CMD_SINGLE, CMD_OPTIONAL, "partition name");
6339 cmd_AddParm(ts, "-summary", CMD_FLAG, CMD_OPTIONAL,
6340 "print storage summary");
6343 ts = cmd_CreateSyntax("unlockvldb", UnlockVLDB, NULL, 0,
6344 "unlock all the locked entries in the VLDB");
6345 cmd_AddParm(ts, "-server", CMD_SINGLE, CMD_OPTIONAL, "machine name");
6346 cmd_AddParm(ts, "-partition", CMD_SINGLE, CMD_OPTIONAL, "partition name");
6349 ts = cmd_CreateSyntax("lock", LockEntry, NULL, 0,
6350 "lock VLDB entry for a volume");
6351 cmd_AddParm(ts, "-id", CMD_SINGLE, 0, "volume name or ID");
6354 ts = cmd_CreateSyntax("changeaddr", ChangeAddr, NULL, 0,
6355 "change the IP address of a file server");
6356 cmd_AddParm(ts, "-oldaddr", CMD_SINGLE, 0, "original IP address");
6357 cmd_AddParm(ts, "-newaddr", CMD_SINGLE, CMD_OPTIONAL, "new IP address");
6358 cmd_AddParm(ts, "-remove", CMD_FLAG, CMD_OPTIONAL,
6359 "remove the IP address from the VLDB");
6360 cmd_AddParm(ts, "-force", CMD_FLAG, CMD_OPTIONAL,
6361 "allow multi-homed server entry change (not recommended)");
6364 ts = cmd_CreateSyntax("listaddrs", ListAddrs, NULL, 0,
6365 "list the IP address of all file servers registered in the VLDB");
6366 cmd_AddParm(ts, "-uuid", CMD_SINGLE, CMD_OPTIONAL, "uuid of server");
6367 cmd_AddParm(ts, "-host", CMD_SINGLE, CMD_OPTIONAL, "address of host");
6368 cmd_AddParm(ts, "-printuuid", CMD_FLAG, CMD_OPTIONAL,
6369 "print uuid of hosts");
6372 ts = cmd_CreateSyntax("convertROtoRW", ConvertRO, NULL, 0,
6373 "convert a RO volume into a RW volume (after loss of old RW volume)");
6374 cmd_AddParm(ts, "-server", CMD_SINGLE, 0, "machine name");
6375 cmd_AddParm(ts, "-partition", CMD_SINGLE, 0, "partition name");
6376 cmd_AddParm(ts, "-id", CMD_SINGLE, 0, "volume name or ID");
6377 cmd_AddParm(ts, "-force", CMD_FLAG, CMD_OPTIONAL, "don't ask");
6380 ts = cmd_CreateSyntax("size", Sizes, NULL, 0,
6381 "obtain various sizes of the volume.");
6382 cmd_AddParm(ts, "-id", CMD_SINGLE, 0, "volume name or ID");
6383 cmd_AddParm(ts, "-partition", CMD_SINGLE, CMD_OPTIONAL, "partition name");
6384 cmd_AddParm(ts, "-server", CMD_SINGLE, CMD_OPTIONAL, "machine name");
6385 cmd_AddParm(ts, "-dump", CMD_FLAG, CMD_OPTIONAL,
6386 "Obtain the size of the dump");
6387 cmd_AddParm(ts, "-time", CMD_SINGLE, CMD_OPTIONAL, "dump from time");
6390 ts = cmd_CreateSyntax("endtrans", EndTrans, NULL, 0,
6391 "end a volserver transaction");
6392 cmd_AddParm(ts, "-server", CMD_SINGLE, 0, "machine name");
6393 cmd_AddParm(ts, "-transaction", CMD_SINGLE, 0,
6397 ts = cmd_CreateSyntax("setaddrs", SetAddrs, NULL, 0,
6398 "set the list of IP addresses for a given UUID in the VLDB");
6399 cmd_AddParm(ts, "-uuid", CMD_SINGLE, 0, "uuid of server");
6400 cmd_AddParm(ts, "-host", CMD_LIST, 0, "address of host");
6403 ts = cmd_CreateSyntax("remaddrs", RemoveAddrs, NULL, 0,
6404 "remove the list of IP addresses for a given UUID in the VLDB");
6405 cmd_AddParm(ts, "-uuid", CMD_SINGLE, 0, "uuid of server");
6408 code = cmd_Dispatch(argc, argv);
6410 /* Shut down the ubik_client and rx connections */
6412 (void)ubik_ClientDestroy(cstruct);
6418 exit((code ? -1 : 0));