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 static int PrintDiagnostics(char *astring, afs_int32 acode);
62 static 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));
124 qPut(struct tqHead *ahead, afs_uint32 volid)
128 elem = malloc(sizeof(struct tqElem));
129 elem->next = ahead->next;
137 qGet(struct tqHead *ahead, afs_uint32 *volid)
141 if (ahead->count <= 0)
143 *volid = ahead->next->volid;
145 ahead->next = tmp->next;
151 /* returns 1 if <filename> exists else 0 */
153 FileExists(char *filename)
159 code = usd_Open(filename, USD_OPEN_RDONLY, 0, &ufd);
163 code = USD_IOCTL(ufd, USD_IOCTL_GETSIZE, &size);
171 /* returns 1 if <name> doesnot end in .readonly or .backup, else 0 */
173 VolNameOK(char *name)
177 total = strlen(name);
178 if (!strcmp(&name[total - 9], ".readonly")) {
180 } else if (!strcmp(&name[total - 7], ".backup")) {
187 /* return 1 if name is a number else 0 */
189 IsNumeric(char *name)
198 for (i = 0; i < len; i++) {
199 if (*ptr < '0' || *ptr > '9') {
210 * Parse a server dotted address and return the address in network byte order
213 GetServerNoresolve(char *aname)
219 code = sscanf(aname, "%d.%d.%d.%d", &b1, &b2, &b3, &b4);
221 addr = (b1 << 24) | (b2 << 16) | (b3 << 8) | b4;
222 addr = htonl(addr); /* convert to network byte order */
228 * Parse a server name/address and return a non-loopback address in network byte order
231 GetServer(char *aname)
234 afs_uint32 addr; /* in network byte order */
236 char hostname[MAXHOSTCHARS];
237 afs_uint32 **addr_list;
240 addr = GetServerNoresolve(aname);
242 if (!rx_IsLoopbackAddr(ntohl(addr)))
248 th = gethostbyname(aname);
249 if (th != NULL && th->h_addrtype == AF_INET) {
250 addr_list = (afs_uint32 **)th->h_addr_list;
251 for(i = 0; addr_list[i] != NULL; i++) {
252 if (!rx_IsLoopbackAddr(ntohl(*addr_list[i]))) {
253 memcpy(&addr, addr_list[i], sizeof(addr));
259 * If we reach this point all of the addresses returned by
260 * gethostbyname() are loopback addresses. We assume that means
261 * that the name is supposed to describe the machine this code
262 * is executing on. Try gethostname() to and check to see if
263 * that name can provide us a non-loopback address.
265 code = gethostname(hostname, MAXHOSTCHARS);
267 th = gethostbyname(hostname);
268 if (th != NULL && th->h_addrtype == AF_INET) {
269 addr_list = (afs_uint32 **)th->h_addr_list;
270 for (i=0; addr_list[i] != NULL; i++) {
271 if (!rx_IsLoopbackAddr(ntohl(*addr_list[i]))) {
272 memcpy(&addr, addr_list[i], sizeof(addr));
281 * No non-loopback address could be obtained for 'aname'.
287 IsPartValid(afs_int32 partId, afs_uint32 server, afs_int32 *code)
289 struct partList dummyPartList;
295 *code = UV_ListPartitions(server, &dummyPartList, &cnt);
298 for (i = 0; i < cnt; i++) {
299 if (dummyPartList.partFlags[i] & PARTVALID)
300 if (dummyPartList.partId[i] == partId)
306 /*sends the contents of file associated with <fd> and <blksize> to Rx Stream
307 * associated with <call> */
309 SendFile(usd_handle_t ufd, struct rx_call *call, long blksize)
311 char *buffer = (char *)0;
315 buffer = malloc(blksize);
317 fprintf(STDERR, "malloc failed\n");
322 #if !defined(AFS_NT40_ENV) && !defined(AFS_PTHREAD_ENV)
323 /* Only for this for non-NT, non-pthread. For NT, we can't select on
324 * non-socket FDs. For pthread environments, we don't need to select at
325 * all, since the following read() will block. */
328 FD_SET((intptr_t)(ufd->handle), &in);
329 /* don't timeout if read blocks */
330 IOMGR_Select(((intptr_t)(ufd->handle)) + 1, &in, 0, 0, 0);
332 error = USD_READ(ufd, buffer, blksize, &nbytes);
334 fprintf(STDERR, "File system read failed: %s\n",
335 afs_error_message(error));
342 if (rx_Write(call, buffer, nbytes) != nbytes) {
352 /* function invoked by UV_RestoreVolume, reads the data from rx_trx_stream and
353 * writes it out to the volume. */
355 WriteData(struct rx_call *call, void *rock)
357 char *filename = (char *) rock;
360 afs_int32 error, code;
362 afs_int64 currOffset;
368 if (!filename || !*filename) {
369 usd_StandardInput(&ufd);
373 code = usd_Open(filename, USD_OPEN_RDONLY, 0, &ufd);
376 code = USD_IOCTL(ufd, USD_IOCTL_GETBLKSIZE, &blksize);
379 fprintf(STDERR, "Could not access file '%s': %s\n", filename,
380 afs_error_message(code));
384 /* test if we have a valid dump */
385 USD_SEEK(ufd, 0, SEEK_END, &currOffset);
386 USD_SEEK(ufd, currOffset - sizeof(afs_uint32), SEEK_SET, &currOffset);
387 USD_READ(ufd, (char *)&buffer, sizeof(afs_uint32), &got);
388 if ((got != sizeof(afs_uint32)) || (ntohl(buffer) != DUMPENDMAGIC)) {
389 fprintf(STDERR, "Signature missing from end of file '%s'\n", filename);
393 USD_SEEK(ufd, 0, SEEK_SET, &currOffset);
395 code = SendFile(ufd, call, blksize);
402 code = USD_CLOSE(ufd);
404 fprintf(STDERR, "Could not close dump file %s\n",
405 (filename && *filename) ? filename : "STDOUT");
413 /* Receive data from <call> stream into file associated
414 * with <fd> <blksize>
417 ReceiveFile(usd_handle_t ufd, struct rx_call *call, long blksize)
421 afs_uint32 bytesleft, w;
424 buffer = malloc(blksize);
426 fprintf(STDERR, "memory allocation failed\n");
430 while ((bytesread = rx_Read(call, buffer, blksize)) > 0) {
431 for (bytesleft = bytesread; bytesleft; bytesleft -= w) {
432 #if !defined(AFS_NT40_ENV) && !defined(AFS_PTHREAD_ENV)
433 /* Only for this for non-NT, non-pthread. For NT, we can't select
434 * on non-socket FDs. For pthread environments, we don't need to
435 * select at all, since the following write() will block. */
438 FD_SET((intptr_t)(ufd->handle), &out);
439 /* don't timeout if write blocks */
440 IOMGR_Select(((intptr_t)(ufd->handle)) + 1, 0, &out, 0, 0);
443 USD_WRITE(ufd, &buffer[bytesread - bytesleft], bytesleft, &w);
445 fprintf(STDERR, "File system write failed: %s\n",
446 afs_error_message(error));
459 DumpFunction(struct rx_call *call, void *rock)
461 char *filename = (char *)rock;
462 usd_handle_t ufd; /* default is to stdout */
463 afs_int32 error = 0, code;
468 /* Open the output file */
469 if (!filename || !*filename) {
470 usd_StandardOutput(&ufd);
475 usd_Open(filename, USD_OPEN_CREATE | USD_OPEN_RDWR, 0666, &ufd);
479 code = USD_IOCTL(ufd, USD_IOCTL_SETSIZE, &size);
482 code = USD_IOCTL(ufd, USD_IOCTL_GETBLKSIZE, &blksize);
485 fprintf(STDERR, "Could not create file '%s': %s\n", filename,
486 afs_error_message(code));
487 ERROR_EXIT(VOLSERBADOP);
491 code = ReceiveFile(ufd, call, blksize);
496 /* Close the output file */
498 code = USD_CLOSE(ufd);
500 fprintf(STDERR, "Could not close dump file %s\n",
501 (filename && *filename) ? filename : "STDIN");
511 DisplayFormat(volintInfo *pntr, afs_uint32 server, afs_int32 part,
512 int *totalOK, int *totalNotOK, int *totalBusy, int fast,
513 int longlist, int disp)
519 fprintf(STDOUT, "%-10lu\n", (unsigned long)pntr->volid);
520 } else if (longlist) {
521 if (pntr->status == VOK) {
522 fprintf(STDOUT, "%-32s ", pntr->name);
523 fprintf(STDOUT, "%10lu ", (unsigned long)pntr->volid);
525 fprintf(STDOUT, "RW ");
527 fprintf(STDOUT, "RO ");
529 fprintf(STDOUT, "BK ");
530 fprintf(STDOUT, "%10d K ", pntr->size);
531 if (pntr->inUse == 1) {
532 fprintf(STDOUT, "On-line");
535 fprintf(STDOUT, "Off-line");
538 if (pntr->needsSalvaged == 1)
539 fprintf(STDOUT, "**needs salvage**");
540 fprintf(STDOUT, "\n");
541 MapPartIdIntoName(part, pname);
542 fprintf(STDOUT, " %s %s \n", hostutil_GetNameByINet(server),
544 fprintf(STDOUT, " RWrite %10lu ROnly %10lu Backup %10lu \n",
545 (unsigned long)pntr->parentID,
546 (unsigned long)pntr->cloneID,
547 (unsigned long)pntr->backupID);
548 fprintf(STDOUT, " MaxQuota %10d K \n", pntr->maxquota);
549 t = pntr->creationDate;
550 fprintf(STDOUT, " Creation %s",
553 fprintf(STDOUT, " Copy %s",
556 t = pntr->backupDate;
558 fprintf(STDOUT, " Backup Never\n");
560 fprintf(STDOUT, " Backup %s",
563 t = pntr->accessDate;
565 fprintf(STDOUT, " Last Access %s",
568 t = pntr->updateDate;
570 fprintf(STDOUT, " Last Update Never\n");
572 fprintf(STDOUT, " Last Update %s",
575 " %d accesses in the past day (i.e., vnode references)\n",
577 } else if (pntr->status == VBUSY) {
579 qPut(&busyHead, pntr->volid);
581 fprintf(STDOUT, "**** Volume %lu is busy ****\n",
582 (unsigned long)pntr->volid);
585 qPut(¬okHead, pntr->volid);
587 fprintf(STDOUT, "**** Could not attach volume %lu ****\n",
588 (unsigned long)pntr->volid);
590 fprintf(STDOUT, "\n");
591 } else { /* default listing */
592 if (pntr->status == VOK) {
593 fprintf(STDOUT, "%-32s ", pntr->name);
594 fprintf(STDOUT, "%10lu ", (unsigned long)pntr->volid);
596 fprintf(STDOUT, "RW ");
598 fprintf(STDOUT, "RO ");
600 fprintf(STDOUT, "BK ");
601 fprintf(STDOUT, "%10d K ", pntr->size);
602 if (pntr->inUse == 1) {
603 fprintf(STDOUT, "On-line");
606 fprintf(STDOUT, "Off-line");
609 if (pntr->needsSalvaged == 1)
610 fprintf(STDOUT, "**needs salvage**");
611 fprintf(STDOUT, "\n");
612 } else if (pntr->status == VBUSY) {
614 qPut(&busyHead, pntr->volid);
616 fprintf(STDOUT, "**** Volume %lu is busy ****\n",
617 (unsigned long)pntr->volid);
620 qPut(¬okHead, pntr->volid);
622 fprintf(STDOUT, "**** Could not attach volume %lu ****\n",
623 (unsigned long)pntr->volid);
628 /*------------------------------------------------------------------------
629 * PRIVATE XDisplayFormat
632 * Display the contents of one extended volume info structure.
635 * a_xInfoP : Ptr to extended volume info struct to print.
636 * a_servID : Server ID to print.
637 * a_partID : Partition ID to print.
638 * a_totalOKP : Ptr to total-OK counter.
639 * a_totalNotOKP : Ptr to total-screwed counter.
640 * a_totalBusyP : Ptr to total-busy counter.
641 * a_fast : Fast listing?
642 * a_int32 : Int32 listing?
643 * a_showProblems : Show volume problems?
649 * Nothing interesting.
653 *------------------------------------------------------------------------*/
656 XDisplayFormat(volintXInfo *a_xInfoP, afs_uint32 a_servID, afs_int32 a_partID,
657 int *a_totalOKP, int *a_totalNotOKP, int *a_totalBusyP,
658 int a_fast, int a_int32, int a_showProblems)
659 { /*XDisplayFormat */
667 fprintf(STDOUT, "%-10lu\n", (unsigned long)a_xInfoP->volid);
668 } else if (a_int32) {
670 * Fully-detailed listing.
672 if (a_xInfoP->status == VOK) {
674 * Volume's status is OK - all the fields are valid.
676 fprintf(STDOUT, "%-32s ", a_xInfoP->name);
677 fprintf(STDOUT, "%10lu ", (unsigned long)a_xInfoP->volid);
678 if (a_xInfoP->type == 0)
679 fprintf(STDOUT, "RW ");
680 if (a_xInfoP->type == 1)
681 fprintf(STDOUT, "RO ");
682 if (a_xInfoP->type == 2)
683 fprintf(STDOUT, "BK ");
684 fprintf(STDOUT, "%10d K used ", a_xInfoP->size);
685 fprintf(STDOUT, "%d files ", a_xInfoP->filecount);
686 if (a_xInfoP->inUse == 1) {
687 fprintf(STDOUT, "On-line");
690 fprintf(STDOUT, "Off-line");
693 fprintf(STDOUT, "\n");
694 MapPartIdIntoName(a_partID, pname);
695 fprintf(STDOUT, " %s %s \n", hostutil_GetNameByINet(a_servID),
697 fprintf(STDOUT, " RWrite %10lu ROnly %10lu Backup %10lu \n",
698 (unsigned long)a_xInfoP->parentID,
699 (unsigned long)a_xInfoP->cloneID,
700 (unsigned long)a_xInfoP->backupID);
701 fprintf(STDOUT, " MaxQuota %10d K \n", a_xInfoP->maxquota);
703 t = a_xInfoP->creationDate;
704 fprintf(STDOUT, " Creation %s",
707 t = a_xInfoP->copyDate;
708 fprintf(STDOUT, " Copy %s",
711 t = a_xInfoP->backupDate;
713 fprintf(STDOUT, " Backup Never\n");
715 fprintf(STDOUT, " Backup %s",
718 t = a_xInfoP->accessDate;
720 fprintf(STDOUT, " Last Access %s",
723 t = a_xInfoP->updateDate;
725 fprintf(STDOUT, " Last Update Never\n");
727 fprintf(STDOUT, " Last Update %s",
730 " %d accesses in the past day (i.e., vnode references)\n",
734 * Print all the read/write and authorship stats.
736 fprintf(STDOUT, "\n Raw Read/Write Stats\n");
738 " |-------------------------------------------|\n");
740 " | Same Network | Diff Network |\n");
742 " |----------|----------|----------|----------|\n");
744 " | Total | Auth | Total | Auth |\n");
746 " |----------|----------|----------|----------|\n");
747 fprintf(STDOUT, "Reads | %8d | %8d | %8d | %8d |\n",
748 a_xInfoP->stat_reads[VOLINT_STATS_SAME_NET],
749 a_xInfoP->stat_reads[VOLINT_STATS_SAME_NET_AUTH],
750 a_xInfoP->stat_reads[VOLINT_STATS_DIFF_NET],
751 a_xInfoP->stat_reads[VOLINT_STATS_DIFF_NET_AUTH]);
752 fprintf(STDOUT, "Writes | %8d | %8d | %8d | %8d |\n",
753 a_xInfoP->stat_writes[VOLINT_STATS_SAME_NET],
754 a_xInfoP->stat_writes[VOLINT_STATS_SAME_NET_AUTH],
755 a_xInfoP->stat_writes[VOLINT_STATS_DIFF_NET],
756 a_xInfoP->stat_writes[VOLINT_STATS_DIFF_NET_AUTH]);
758 " |-------------------------------------------|\n\n");
761 " Writes Affecting Authorship\n");
763 " |-------------------------------------------|\n");
765 " | File Authorship | Directory Authorship|\n");
767 " |----------|----------|----------|----------|\n");
769 " | Same | Diff | Same | Diff |\n");
771 " |----------|----------|----------|----------|\n");
772 fprintf(STDOUT, "0-60 sec | %8d | %8d | %8d | %8d |\n",
773 a_xInfoP->stat_fileSameAuthor[VOLINT_STATS_TIME_IDX_0],
774 a_xInfoP->stat_fileDiffAuthor[VOLINT_STATS_TIME_IDX_0],
775 a_xInfoP->stat_dirSameAuthor[VOLINT_STATS_TIME_IDX_0],
776 a_xInfoP->stat_dirDiffAuthor[VOLINT_STATS_TIME_IDX_0]);
777 fprintf(STDOUT, "1-10 min | %8d | %8d | %8d | %8d |\n",
778 a_xInfoP->stat_fileSameAuthor[VOLINT_STATS_TIME_IDX_1],
779 a_xInfoP->stat_fileDiffAuthor[VOLINT_STATS_TIME_IDX_1],
780 a_xInfoP->stat_dirSameAuthor[VOLINT_STATS_TIME_IDX_1],
781 a_xInfoP->stat_dirDiffAuthor[VOLINT_STATS_TIME_IDX_1]);
782 fprintf(STDOUT, "10min-1hr | %8d | %8d | %8d | %8d |\n",
783 a_xInfoP->stat_fileSameAuthor[VOLINT_STATS_TIME_IDX_2],
784 a_xInfoP->stat_fileDiffAuthor[VOLINT_STATS_TIME_IDX_2],
785 a_xInfoP->stat_dirSameAuthor[VOLINT_STATS_TIME_IDX_2],
786 a_xInfoP->stat_dirDiffAuthor[VOLINT_STATS_TIME_IDX_2]);
787 fprintf(STDOUT, "1hr-1day | %8d | %8d | %8d | %8d |\n",
788 a_xInfoP->stat_fileSameAuthor[VOLINT_STATS_TIME_IDX_3],
789 a_xInfoP->stat_fileDiffAuthor[VOLINT_STATS_TIME_IDX_3],
790 a_xInfoP->stat_dirSameAuthor[VOLINT_STATS_TIME_IDX_3],
791 a_xInfoP->stat_dirDiffAuthor[VOLINT_STATS_TIME_IDX_3]);
792 fprintf(STDOUT, "1day-1wk | %8d | %8d | %8d | %8d |\n",
793 a_xInfoP->stat_fileSameAuthor[VOLINT_STATS_TIME_IDX_4],
794 a_xInfoP->stat_fileDiffAuthor[VOLINT_STATS_TIME_IDX_4],
795 a_xInfoP->stat_dirSameAuthor[VOLINT_STATS_TIME_IDX_4],
796 a_xInfoP->stat_dirDiffAuthor[VOLINT_STATS_TIME_IDX_4]);
797 fprintf(STDOUT, "> 1wk | %8d | %8d | %8d | %8d |\n",
798 a_xInfoP->stat_fileSameAuthor[VOLINT_STATS_TIME_IDX_5],
799 a_xInfoP->stat_fileDiffAuthor[VOLINT_STATS_TIME_IDX_5],
800 a_xInfoP->stat_dirSameAuthor[VOLINT_STATS_TIME_IDX_5],
801 a_xInfoP->stat_dirDiffAuthor[VOLINT_STATS_TIME_IDX_5]);
803 " |-------------------------------------------|\n");
804 } /*Volume status OK */
805 else if (a_xInfoP->status == VBUSY) {
807 qPut(&busyHead, a_xInfoP->volid);
809 fprintf(STDOUT, "**** Volume %lu is busy ****\n",
810 (unsigned long)a_xInfoP->volid);
814 qPut(¬okHead, a_xInfoP->volid);
816 fprintf(STDOUT, "**** Could not attach volume %lu ****\n",
817 (unsigned long)a_xInfoP->volid);
818 } /*Screwed volume */
819 fprintf(STDOUT, "\n");
825 if (a_xInfoP->status == VOK) {
826 fprintf(STDOUT, "%-32s ", a_xInfoP->name);
827 fprintf(STDOUT, "%10lu ", (unsigned long)a_xInfoP->volid);
828 if (a_xInfoP->type == 0)
829 fprintf(STDOUT, "RW ");
830 if (a_xInfoP->type == 1)
831 fprintf(STDOUT, "RO ");
832 if (a_xInfoP->type == 2)
833 fprintf(STDOUT, "BK ");
834 fprintf(STDOUT, "%10d K ", a_xInfoP->size);
835 if (a_xInfoP->inUse == 1) {
836 fprintf(STDOUT, "On-line");
839 fprintf(STDOUT, "Off-line");
842 fprintf(STDOUT, "\n");
844 else if (a_xInfoP->status == VBUSY) {
846 qPut(&busyHead, a_xInfoP->volid);
848 fprintf(STDOUT, "**** Volume %lu is busy ****\n",
849 (unsigned long)a_xInfoP->volid);
853 qPut(¬okHead, a_xInfoP->volid);
855 fprintf(STDOUT, "**** Could not attach volume %lu ****\n",
856 (unsigned long)a_xInfoP->volid);
857 } /*Screwed volume */
858 } /*Default listing */
859 } /*XDisplayFormat */
861 /*------------------------------------------------------------------------
862 * PRIVATE XDisplayFormat2
865 * Display the formated contents of one extended volume info structure.
868 * a_xInfoP : Ptr to extended volume info struct to print.
869 * a_servID : Server ID to print.
870 * a_partID : Partition ID to print.
871 * a_totalOKP : Ptr to total-OK counter.
872 * a_totalNotOKP : Ptr to total-screwed counter.
873 * a_totalBusyP : Ptr to total-busy counter.
874 * a_fast : Fast listing?
875 * a_int32 : Int32 listing?
876 * a_showProblems : Show volume problems?
882 * Nothing interesting.
886 *------------------------------------------------------------------------*/
889 XDisplayFormat2(volintXInfo *a_xInfoP, afs_uint32 a_servID, afs_int32 a_partID,
890 int *a_totalOKP, int *a_totalNotOKP, int *a_totalBusyP,
891 int a_fast, int a_int32, int a_showProblems)
892 { /*XDisplayFormat */
898 fprintf(STDOUT, "vold_id\t%-10lu\n", (unsigned long)a_xInfoP->volid);
899 } else if (a_int32) {
901 * Fully-detailed listing.
903 if (a_xInfoP->status == VOK) {
905 * Volume's status is OK - all the fields are valid.
908 static long server_cache = -1, partition_cache = -1;
909 static char hostname[256], address[32], pname[16];
910 int i,ai[] = {VOLINT_STATS_TIME_IDX_0,VOLINT_STATS_TIME_IDX_1,VOLINT_STATS_TIME_IDX_2,
911 VOLINT_STATS_TIME_IDX_3,VOLINT_STATS_TIME_IDX_4,VOLINT_STATS_TIME_IDX_5};
913 if (a_servID != server_cache) {
917 strcpy(hostname, hostutil_GetNameByINet(a_servID));
918 strcpy(address, inet_ntoa(s));
919 server_cache = a_servID;
921 if (a_partID != partition_cache) {
922 MapPartIdIntoName(a_partID, pname);
923 partition_cache = a_partID;
926 fprintf(STDOUT, "name\t\t%s\n", a_xInfoP->name);
927 fprintf(STDOUT, "id\t\t%lu\n", afs_printable_uint32_lu(a_xInfoP->volid));
928 fprintf(STDOUT, "serv\t\t%s\t%s\n", address, hostname);
929 fprintf(STDOUT, "part\t\t%s\n", pname);
930 fprintf(STDOUT, "status\t\tOK\n");
931 fprintf(STDOUT, "backupID\t%lu\n",
932 afs_printable_uint32_lu(a_xInfoP->backupID));
933 fprintf(STDOUT, "parentID\t%lu\n",
934 afs_printable_uint32_lu(a_xInfoP->parentID));
935 fprintf(STDOUT, "cloneID\t\t%lu\n",
936 afs_printable_uint32_lu(a_xInfoP->cloneID));
937 fprintf(STDOUT, "inUse\t\t%s\n", a_xInfoP->inUse ? "Y" : "N");
938 switch (a_xInfoP->type) {
940 fprintf(STDOUT, "type\t\tRW\n");
943 fprintf(STDOUT, "type\t\tRO\n");
946 fprintf(STDOUT, "type\t\tBK\n");
949 fprintf(STDOUT, "type\t\t?\n");
952 t = a_xInfoP->creationDate;
953 fprintf(STDOUT, "creationDate\t%-9lu\t%s",
954 afs_printable_uint32_lu(a_xInfoP->creationDate),
957 t = a_xInfoP->accessDate;
958 fprintf(STDOUT, "accessDate\t%-9lu\t%s",
959 afs_printable_uint32_lu(a_xInfoP->accessDate),
962 t = a_xInfoP->updateDate;
963 fprintf(STDOUT, "updateDate\t%-9lu\t%s",
964 afs_printable_uint32_lu(a_xInfoP->updateDate),
967 t = a_xInfoP->backupDate;
968 fprintf(STDOUT, "backupDate\t%-9lu\t%s",
969 afs_printable_uint32_lu(a_xInfoP->backupDate),
972 t = a_xInfoP->copyDate;
973 fprintf(STDOUT, "copyDate\t%-9lu\t%s",
974 afs_printable_uint32_lu(a_xInfoP->copyDate),
977 fprintf(STDOUT, "diskused\t%u\n", a_xInfoP->size);
978 fprintf(STDOUT, "maxquota\t%u\n", a_xInfoP->maxquota);
980 fprintf(STDOUT, "filecount\t%u\n", a_xInfoP->filecount);
981 fprintf(STDOUT, "dayUse\t\t%u\n", a_xInfoP->dayUse);
983 fprintf(STDOUT,"reads_same_net\t%8d\n",a_xInfoP->stat_reads[VOLINT_STATS_SAME_NET]);
984 fprintf(STDOUT,"reads_same_net_auth\t%8d\n",a_xInfoP->stat_reads[VOLINT_STATS_SAME_NET_AUTH]);
985 fprintf(STDOUT,"reads_diff_net\t%8d\n",a_xInfoP->stat_reads[VOLINT_STATS_DIFF_NET]);
986 fprintf(STDOUT,"reads_diff_net_auth\t%8d\n",a_xInfoP->stat_reads[VOLINT_STATS_DIFF_NET_AUTH]);
988 fprintf(STDOUT,"writes_same_net\t%8d\n",a_xInfoP->stat_writes[VOLINT_STATS_SAME_NET]);
989 fprintf(STDOUT,"writes_same_net_auth\t%8d\n",a_xInfoP->stat_writes[VOLINT_STATS_SAME_NET_AUTH]);
990 fprintf(STDOUT,"writes_diff_net\t%8d\n",a_xInfoP->stat_writes[VOLINT_STATS_DIFF_NET]);
991 fprintf(STDOUT,"writes_diff_net_auth\t%8d\n",a_xInfoP->stat_writes[VOLINT_STATS_DIFF_NET_AUTH]);
995 fprintf(STDOUT,"file_same_author_idx_%d\t%8d\n",i+1,a_xInfoP->stat_fileSameAuthor[ai[i]]);
996 fprintf(STDOUT,"file_diff_author_idx_%d\t%8d\n",i+1,a_xInfoP->stat_fileDiffAuthor[ai[i]]);
997 fprintf(STDOUT,"dir_same_author_idx_%d\t%8d\n",i+1,a_xInfoP->stat_dirSameAuthor[ai[i]]);
998 fprintf(STDOUT,"dir_dif_author_idx_%d\t%8d\n",i+1,a_xInfoP->stat_dirDiffAuthor[ai[i]]);
1001 } /*Volume status OK */
1002 else if (a_xInfoP->status == VBUSY) {
1004 qPut(&busyHead, a_xInfoP->volid);
1006 fprintf(STDOUT, "BUSY_VOL\t%lu\n",
1007 (unsigned long)a_xInfoP->volid);
1011 qPut(¬okHead, a_xInfoP->volid);
1013 fprintf(STDOUT, "COULD_NOT_ATTACH\t%lu\n",
1014 (unsigned long)a_xInfoP->volid);
1015 } /*Screwed volume */
1021 if (a_xInfoP->status == VOK) {
1022 fprintf(STDOUT, "name\t%-32s\n", a_xInfoP->name);
1023 fprintf(STDOUT, "volID\t%10lu\n", (unsigned long)a_xInfoP->volid);
1024 if (a_xInfoP->type == 0)
1025 fprintf(STDOUT, "type\tRW\n");
1026 if (a_xInfoP->type == 1)
1027 fprintf(STDOUT, "type\tRO\n");
1028 if (a_xInfoP->type == 2)
1029 fprintf(STDOUT, "type\tBK\n");
1030 fprintf(STDOUT, "size\t%10dK\n", a_xInfoP->size);
1032 fprintf(STDOUT, "inUse\t%d\n",a_xInfoP->inUse);
1033 if (a_xInfoP->inUse == 1)
1039 else if (a_xInfoP->status == VBUSY) {
1041 qPut(&busyHead, a_xInfoP->volid);
1043 fprintf(STDOUT, "VOLUME_BUSY\t%lu\n",
1044 (unsigned long)a_xInfoP->volid);
1048 qPut(¬okHead, a_xInfoP->volid);
1050 fprintf(STDOUT, "COULD_NOT_ATTACH_VOLUME\t%lu\n",
1051 (unsigned long)a_xInfoP->volid);
1052 } /*Screwed volume */
1053 } /*Default listing */
1054 } /*XDisplayFormat */
1057 DisplayFormat2(long server, long partition, volintInfo *pntr)
1059 static long server_cache = -1, partition_cache = -1;
1060 static char hostname[256], address[32], pname[16];
1063 if (server != server_cache) {
1067 strcpy(hostname, hostutil_GetNameByINet(server));
1068 strcpy(address, inet_ntoa(s));
1069 server_cache = server;
1071 if (partition != partition_cache) {
1072 MapPartIdIntoName(partition, pname);
1073 partition_cache = partition;
1076 if (pntr->status == VOK)
1077 fprintf(STDOUT, "name\t\t%s\n", pntr->name);
1079 fprintf(STDOUT, "id\t\t%lu\n",
1080 afs_printable_uint32_lu(pntr->volid));
1081 fprintf(STDOUT, "serv\t\t%s\t%s\n", address, hostname);
1082 fprintf(STDOUT, "part\t\t%s\n", pname);
1083 switch (pntr->status) {
1085 fprintf(STDOUT, "status\t\tOK\n");
1088 fprintf(STDOUT, "status\t\tBUSY\n");
1091 fprintf(STDOUT, "status\t\tUNATTACHABLE\n");
1094 fprintf(STDOUT, "backupID\t%lu\n",
1095 afs_printable_uint32_lu(pntr->backupID));
1096 fprintf(STDOUT, "parentID\t%lu\n",
1097 afs_printable_uint32_lu(pntr->parentID));
1098 fprintf(STDOUT, "cloneID\t\t%lu\n",
1099 afs_printable_uint32_lu(pntr->cloneID));
1100 fprintf(STDOUT, "inUse\t\t%s\n", pntr->inUse ? "Y" : "N");
1101 fprintf(STDOUT, "needsSalvaged\t%s\n", pntr->needsSalvaged ? "Y" : "N");
1102 /* 0xD3 is from afs/volume.h since I had trouble including the file */
1103 fprintf(STDOUT, "destroyMe\t%s\n", pntr->destroyMe == 0xD3 ? "Y" : "N");
1104 switch (pntr->type) {
1106 fprintf(STDOUT, "type\t\tRW\n");
1109 fprintf(STDOUT, "type\t\tRO\n");
1112 fprintf(STDOUT, "type\t\tBK\n");
1115 fprintf(STDOUT, "type\t\t?\n");
1118 t = pntr->creationDate;
1119 fprintf(STDOUT, "creationDate\t%-9lu\t%s",
1120 afs_printable_uint32_lu(pntr->creationDate),
1123 t = pntr->accessDate;
1124 fprintf(STDOUT, "accessDate\t%-9lu\t%s",
1125 afs_printable_uint32_lu(pntr->accessDate),
1128 t = pntr->updateDate;
1129 fprintf(STDOUT, "updateDate\t%-9lu\t%s",
1130 afs_printable_uint32_lu(pntr->updateDate),
1133 t = pntr->backupDate;
1134 fprintf(STDOUT, "backupDate\t%-9lu\t%s",
1135 afs_printable_uint32_lu(pntr->backupDate),
1139 fprintf(STDOUT, "copyDate\t%-9lu\t%s",
1140 afs_printable_uint32_lu(pntr->copyDate),
1143 fprintf(STDOUT, "flags\t\t%#lx\t(Optional)\n",
1144 afs_printable_uint32_lu(pntr->flags));
1145 fprintf(STDOUT, "diskused\t%u\n", pntr->size);
1146 fprintf(STDOUT, "maxquota\t%u\n", pntr->maxquota);
1147 fprintf(STDOUT, "minquota\t%lu\t(Optional)\n",
1148 afs_printable_uint32_lu(pntr->spare0));
1149 fprintf(STDOUT, "filecount\t%u\n", pntr->filecount);
1150 fprintf(STDOUT, "dayUse\t\t%u\n", pntr->dayUse);
1151 fprintf(STDOUT, "weekUse\t\t%lu\t(Optional)\n",
1152 afs_printable_uint32_lu(pntr->spare1));
1153 fprintf(STDOUT, "spare2\t\t%lu\t(Optional)\n",
1154 afs_printable_uint32_lu(pntr->spare2));
1155 fprintf(STDOUT, "spare3\t\t%lu\t(Optional)\n",
1156 afs_printable_uint32_lu(pntr->spare3));
1161 DisplayVolumes2(long server, long partition, volintInfo *pntr, long count)
1165 for (i = 0; i < count; i++) {
1166 fprintf(STDOUT, "BEGIN_OF_ENTRY\n");
1167 DisplayFormat2(server, partition, pntr);
1168 fprintf(STDOUT, "END_OF_ENTRY\n\n");
1175 DisplayVolumes(afs_uint32 server, afs_int32 part, volintInfo *pntr,
1176 afs_int32 count, afs_int32 longlist, afs_int32 fast,
1179 int totalOK, totalNotOK, totalBusy, i;
1180 afs_uint32 volid = 0;
1187 for (i = 0; i < count; i++) {
1188 DisplayFormat(pntr, server, part, &totalOK, &totalNotOK, &totalBusy,
1193 while (busyHead.count) {
1194 qGet(&busyHead, &volid);
1195 fprintf(STDOUT, "**** Volume %lu is busy ****\n",
1196 (unsigned long)volid);
1200 while (notokHead.count) {
1201 qGet(¬okHead, &volid);
1202 fprintf(STDOUT, "**** Could not attach volume %lu ****\n",
1203 (unsigned long)volid);
1207 fprintf(STDOUT, "\n");
1210 "Total volumes onLine %d ; Total volumes offLine %d ; Total busy %d\n\n",
1211 totalOK, totalNotOK, totalBusy);
1215 /*------------------------------------------------------------------------
1216 * PRIVATE XDisplayVolumes
1219 * Display extended volume information.
1222 * a_servID : Pointer to the Rx call we're performing.
1223 * a_partID : Partition for which we want the extended list.
1224 * a_xInfoP : Ptr to extended volume info.
1225 * a_count : Number of volume records contained above.
1226 * a_int32 : Int32 listing generated?
1227 * a_fast : Fast listing generated?
1228 * a_quiet : Quiet listing generated?
1234 * Nothing interesting.
1238 *------------------------------------------------------------------------*/
1241 XDisplayVolumes(afs_uint32 a_servID, afs_int32 a_partID, volintXInfo *a_xInfoP,
1242 afs_int32 a_count, afs_int32 a_int32, afs_int32 a_fast,
1244 { /*XDisplayVolumes */
1246 int totalOK; /*Total OK volumes */
1247 int totalNotOK; /*Total screwed volumes */
1248 int totalBusy; /*Total busy volumes */
1249 int i; /*Loop variable */
1250 afs_uint32 volid = 0; /*Current volume ID */
1253 * Initialize counters and (global!!) queues.
1262 * Display each volume in the list.
1264 for (i = 0; i < a_count; i++) {
1265 XDisplayFormat(a_xInfoP, a_servID, a_partID, &totalOK, &totalNotOK,
1266 &totalBusy, a_fast, a_int32, 0);
1271 * If any volumes were found to be busy or screwed, display them.
1274 while (busyHead.count) {
1275 qGet(&busyHead, &volid);
1276 fprintf(STDOUT, "**** Volume %lu is busy ****\n",
1277 (unsigned long)volid);
1281 while (notokHead.count) {
1282 qGet(¬okHead, &volid);
1283 fprintf(STDOUT, "**** Could not attach volume %lu ****\n",
1284 (unsigned long)volid);
1289 fprintf(STDOUT, "\n");
1292 "Total volumes: %d on-line, %d off-line, %d busyd\n\n",
1293 totalOK, totalNotOK, totalBusy);
1297 } /*XDisplayVolumes */
1299 /*------------------------------------------------------------------------
1300 * PRIVATE XDisplayVolumes2
1303 * Display extended formated volume information.
1306 * a_servID : Pointer to the Rx call we're performing.
1307 * a_partID : Partition for which we want the extended list.
1308 * a_xInfoP : Ptr to extended volume info.
1309 * a_count : Number of volume records contained above.
1310 * a_int32 : Int32 listing generated?
1311 * a_fast : Fast listing generated?
1312 * a_quiet : Quiet listing generated?
1318 * Nothing interesting.
1322 *------------------------------------------------------------------------*/
1325 XDisplayVolumes2(afs_uint32 a_servID, afs_int32 a_partID, volintXInfo *a_xInfoP,
1326 afs_int32 a_count, afs_int32 a_int32, afs_int32 a_fast,
1328 { /*XDisplayVolumes */
1330 int totalOK; /*Total OK volumes */
1331 int totalNotOK; /*Total screwed volumes */
1332 int totalBusy; /*Total busy volumes */
1333 int i; /*Loop variable */
1334 afs_uint32 volid = 0; /*Current volume ID */
1337 * Initialize counters and (global!!) queues.
1346 * Display each volume in the list.
1348 for (i = 0; i < a_count; i++) {
1349 fprintf(STDOUT, "BEGIN_OF_ENTRY\n");
1350 XDisplayFormat2(a_xInfoP, a_servID, a_partID, &totalOK, &totalNotOK,
1351 &totalBusy, a_fast, a_int32, 0);
1352 fprintf(STDOUT, "END_OF_ENTRY\n");
1357 * If any volumes were found to be busy or screwed, display them.
1360 while (busyHead.count) {
1361 qGet(&busyHead, &volid);
1362 fprintf(STDOUT, "BUSY_VOL\t%lu\n",
1363 (unsigned long)volid);
1367 while (notokHead.count) {
1368 qGet(¬okHead, &volid);
1369 fprintf(STDOUT, "COULD_NOT_ATTACH\t%lu\n",
1370 (unsigned long)volid);
1375 fprintf(STDOUT, "\n");
1378 "VOLUMES_ONLINE\t%d\nVOLUMES_OFFLINE\t%d\nVOLUMES_BUSY\t%d\n",
1379 totalOK, totalNotOK, totalBusy);
1383 } /*XDisplayVolumes2 */
1386 * Retrieve the sites (i.e., server id, partition id) from a vldb entry for a
1387 * given volume type. May be called repeatedly to get each read-only site.
1389 * @param[in] entry vldb entry from a previous vldb query
1390 * @param[in] voltype type of volume of interest (rw, ro, bk)
1391 * @param[out] server vldb entry server number for voltype
1392 * @param[out] part vldb part id for voltype
1393 * @param[inout] previdx cursor; should be initialized to -1
1394 * before first call on a given entry.
1396 * @returns true when a volume site has been found
1399 GetServerAndPart(struct nvldbentry *entry, int voltype, afs_uint32 *server,
1400 afs_int32 *part, int *previdx)
1402 int i, istart, vtype;
1404 /* Doesn't check for non-existence of backup volume */
1405 if ((voltype == RWVOL) || (voltype == BACKVOL)) {
1407 istart = 0; /* search the entire entry */
1410 /* Search from beginning of entry or pick up where we left off */
1411 istart = ((*previdx < 0) ? 0 : *previdx + 1);
1414 for (i = istart; i < entry->nServers; i++) {
1415 if (entry->serverFlags[i] & vtype) {
1416 *server = entry->serverNumber[i];
1417 *part = entry->serverPartition[i];
1423 /* Didn't find any more, reset index. */
1429 PrintLocked(afs_int32 aflags)
1431 afs_int32 flags = aflags & VLOP_ALLOPERS;
1434 fprintf(STDOUT, " Volume is currently LOCKED \n");
1436 if (flags & VLOP_MOVE) {
1437 fprintf(STDOUT, " Volume is locked for a move operation\n");
1439 if (flags & VLOP_RELEASE) {
1440 fprintf(STDOUT, " Volume is locked for a release operation\n");
1442 if (flags & VLOP_BACKUP) {
1443 fprintf(STDOUT, " Volume is locked for a backup operation\n");
1445 if (flags & VLOP_DELETE) {
1446 fprintf(STDOUT, " Volume is locked for a delete/misc operation\n");
1448 if (flags & VLOP_DUMP) {
1449 fprintf(STDOUT, " Volume is locked for a dump/restore operation\n");
1455 PostVolumeStats(struct nvldbentry *entry)
1457 SubEnumerateEntry(entry);
1458 /* Check for VLOP_ALLOPERS */
1459 PrintLocked(entry->flags);
1463 /*------------------------------------------------------------------------
1464 * PRIVATE XVolumeStats
1467 * Display extended volume information.
1470 * a_xInfoP : Ptr to extended volume info.
1471 * a_entryP : Ptr to the volume's VLDB entry.
1472 * a_srvID : Server ID.
1473 * a_partID : Partition ID.
1474 * a_volType : Type of volume to print.
1480 * Nothing interesting.
1484 *------------------------------------------------------------------------*/
1487 XVolumeStats(volintXInfo *a_xInfoP, struct nvldbentry *a_entryP,
1488 afs_int32 a_srvID, afs_int32 a_partID, int a_volType)
1491 int totalOK, totalNotOK, totalBusy; /*Dummies - we don't really count here */
1493 XDisplayFormat(a_xInfoP, /*Ptr to extended volume info */
1494 a_srvID, /*Server ID to print */
1495 a_partID, /*Partition ID to print */
1496 &totalOK, /*Ptr to total-OK counter */
1497 &totalNotOK, /*Ptr to total-screwed counter */
1498 &totalBusy, /*Ptr to total-busy counter */
1499 0, /*Don't do a fast listing */
1500 1, /*Do a long listing */
1501 1); /*Show volume problems */
1507 VolumeStats_int(volintInfo *pntr, struct nvldbentry *entry, afs_uint32 server,
1508 afs_int32 part, int voltype)
1514 DisplayFormat(pntr, server, part, &totalOK, &totalNotOK, &totalBusy, 0, 1,
1519 /* command to forcibly remove a volume */
1521 NukeVolume(struct cmd_syndesc *as)
1530 server = GetServer(tp = as->parms[0].items->data);
1532 fprintf(STDERR, "vos: server '%s' not found in host table\n", tp);
1536 partID = volutil_GetPartitionID(tp = as->parms[1].items->data);
1538 fprintf(STDERR, "vos: could not parse '%s' as a partition name", tp);
1542 volID = vsu_GetVolumeID(tp = as->parms[2].items->data, cstruct, &err);
1545 PrintError("", err);
1548 "vos: could not parse '%s' as a numeric volume ID", tp);
1553 "vos: forcibly removing all traces of volume %d, please wait...",
1556 code = UV_NukeVolume(server, partID, volID);
1558 fprintf(STDOUT, "done.\n");
1560 fprintf(STDOUT, "failed with code %d.\n", code);
1564 /*------------------------------------------------------------------------
1565 * PRIVATE ExamineVolume
1568 * Routine used to examine a single volume, contacting the VLDB as
1569 * well as the Volume Server.
1572 * as : Ptr to parsed command line arguments.
1575 * 0 for a successful operation,
1576 * Otherwise, one of the ubik or VolServer error values.
1579 * Nothing interesting.
1583 *------------------------------------------------------------------------
1586 ExamineVolume(struct cmd_syndesc *as, void *arock)
1588 struct nvldbentry entry;
1589 afs_int32 vcode = 0;
1590 volintInfo *pntr = (volintInfo *) 0;
1591 volintXInfo *xInfoP = (volintXInfo *) 0;
1593 afs_int32 code, err, error = 0;
1594 int voltype, foundserv = 0, foundentry = 0;
1598 int wantExtendedInfo; /*Do we want extended vol info? */
1599 int isSubEnum=0; /* Keep track whether sub enumerate called. */
1600 wantExtendedInfo = (as->parms[1].items ? 1 : 0); /* -extended */
1602 volid = vsu_GetVolumeID(as->parms[0].items->data, cstruct, &err); /* -id */
1605 PrintError("", err);
1607 fprintf(STDERR, "Unknown volume ID or name '%s'\n",
1608 as->parms[0].items->data);
1613 fprintf(STDOUT, "Fetching VLDB entry for %lu .. ",
1614 (unsigned long)volid);
1617 vcode = VLDB_GetEntryByID(volid, -1, &entry);
1620 "Could not fetch the entry for volume number %lu from VLDB \n",
1621 (unsigned long)volid);
1625 fprintf(STDOUT, "done\n");
1626 MapHostToNetwork(&entry);
1628 if (entry.volumeId[RWVOL] == volid)
1630 else if (entry.volumeId[BACKVOL] == volid)
1632 else /* (entry.volumeId[ROVOL] == volid) */
1635 do { /* do {...} while (voltype == ROVOL) */
1636 /* Get the entry for the volume. If its a RW vol, get the RW entry.
1637 * It its a BK vol, get the RW entry (even if VLDB may say the BK doen't exist).
1638 * If its a RO vol, get the next RO entry.
1640 foundentry = GetServerAndPart(&entry, ((voltype == ROVOL) ? ROVOL : RWVOL),
1641 &aserver, &apart, &previdx);
1642 if (!foundentry) { /* searched all entries */
1643 fprintf(STDERR, "Volume %s does not exist in VLDB\n\n",
1644 as->parms[0].items->data);
1649 /* Get information about the volume from the server */
1651 fprintf(STDOUT, "Getting volume listing from the server %s .. ",
1652 hostutil_GetNameByINet(aserver));
1655 if (wantExtendedInfo)
1656 code = UV_XListOneVolume(aserver, apart, volid, &xInfoP);
1658 code = UV_ListOneVolume(aserver, apart, volid, &pntr);
1660 fprintf(STDOUT, "done\n");
1664 if (code == ENODEV) {
1665 if ((voltype == BACKVOL) && !(entry.flags & VLF_BACKEXISTS)) {
1666 /* The VLDB says there is no backup volume and its not on disk */
1667 fprintf(STDERR, "Volume %s does not exist\n",
1668 as->parms[0].items->data);
1672 "Volume does not exist on server %s as indicated by the VLDB\n",
1673 hostutil_GetNameByINet(aserver));
1676 PrintDiagnostics("examine", code);
1678 fprintf(STDOUT, "\n");
1681 if (wantExtendedInfo)
1682 XVolumeStats(xInfoP, &entry, aserver, apart, voltype);
1683 else if (as->parms[2].items) {
1684 DisplayFormat2(aserver, apart, pntr);
1685 EnumerateEntry(&entry);
1688 VolumeStats_int(pntr, &entry, aserver, apart, voltype);
1690 if ((voltype == BACKVOL) && !(entry.flags & VLF_BACKEXISTS)) {
1691 /* The VLDB says there is no backup volume yet we found one on disk */
1692 fprintf(STDERR, "Volume %s does not exist in VLDB\n",
1693 as->parms[0].items->data);
1702 } while (voltype == ROVOL);
1705 fprintf(STDERR, "Dump only information from VLDB\n\n");
1706 fprintf(STDOUT, "%s \n", entry.name); /* PostVolumeStats doesn't print name */
1710 PostVolumeStats(&entry);
1715 /*------------------------------------------------------------------------
1719 * Routine used to change the status of a single volume.
1722 * as : Ptr to parsed command line arguments.
1725 * 0 for a successful operation,
1726 * Otherwise, one of the ubik or VolServer error values.
1729 * Nothing interesting.
1733 *------------------------------------------------------------------------
1736 SetFields(struct cmd_syndesc *as, void *arock)
1738 struct nvldbentry entry;
1741 afs_int32 code, err;
1748 volid = vsu_GetVolumeID(as->parms[0].items->data, cstruct, &err); /* -id */
1751 PrintError("", err);
1753 fprintf(STDERR, "Unknown volume ID or name '%s'\n",
1754 as->parms[0].items->data);
1758 code = VLDB_GetEntryByID(volid, RWVOL, &entry);
1761 "Could not fetch the entry for volume number %lu from VLDB \n",
1762 (unsigned long)volid);
1765 MapHostToNetwork(&entry);
1767 found = GetServerAndPart(&entry, RWVOL, &aserver, &apart, &previdx);
1769 fprintf(STDERR, "Volume %s does not exist in VLDB\n\n",
1770 as->parms[0].items->data);
1774 init_volintInfo(&info);
1778 if (as->parms[1].items) {
1781 code = util_GetHumanInt32(as->parms[1].items->data, &info.maxquota);
1783 fprintf(STDERR, "invalid quota value\n");
1787 if (as->parms[2].items) {
1792 if (as->parms[3].items) {
1793 /* -clearVolUpCounter */
1798 fprintf(STDERR,"Nothing to set.\n");
1801 code = UV_SetVolumeInfo(aserver, apart, volid, &info);
1804 "Could not update volume info fields for volume number %lu\n",
1805 (unsigned long)volid);
1809 /*------------------------------------------------------------------------
1813 * Brings a volume online.
1816 * as : Ptr to parsed command line arguments.
1819 * 0 for a successful operation,
1822 * Nothing interesting.
1826 *------------------------------------------------------------------------
1829 volOnline(struct cmd_syndesc *as, void *arock)
1832 afs_int32 partition;
1834 afs_int32 code, err = 0;
1836 server = GetServer(as->parms[0].items->data);
1838 fprintf(STDERR, "vos: server '%s' not found in host table\n",
1839 as->parms[0].items->data);
1843 partition = volutil_GetPartitionID(as->parms[1].items->data);
1844 if (partition < 0) {
1845 fprintf(STDERR, "vos: could not interpret partition name '%s'\n",
1846 as->parms[1].items->data);
1850 volid = vsu_GetVolumeID(as->parms[2].items->data, cstruct, &err); /* -id */
1853 PrintError("", err);
1855 fprintf(STDERR, "Unknown volume ID or name '%s'\n",
1856 as->parms[0].items->data);
1860 code = UV_SetVolume(server, partition, volid, ITOffline, 0 /*online */ ,
1863 fprintf(STDERR, "Failed to set volume. Code = %d\n", code);
1870 /*------------------------------------------------------------------------
1871 * PRIVATE volOffline
1874 * Brings a volume offline.
1877 * as : Ptr to parsed command line arguments.
1880 * 0 for a successful operation,
1883 * Nothing interesting.
1887 *------------------------------------------------------------------------
1890 volOffline(struct cmd_syndesc *as, void *arock)
1893 afs_int32 partition;
1895 afs_int32 code, err = 0;
1896 afs_int32 transflag, sleeptime, transdone;
1898 server = GetServer(as->parms[0].items->data);
1900 fprintf(STDERR, "vos: server '%s' not found in host table\n",
1901 as->parms[0].items->data);
1905 partition = volutil_GetPartitionID(as->parms[1].items->data);
1906 if (partition < 0) {
1907 fprintf(STDERR, "vos: could not interpret partition name '%s'\n",
1908 as->parms[1].items->data);
1912 volid = vsu_GetVolumeID(as->parms[2].items->data, cstruct, &err); /* -id */
1915 PrintError("", err);
1917 fprintf(STDERR, "Unknown volume ID or name '%s'\n",
1918 as->parms[0].items->data);
1922 transflag = (as->parms[4].items ? ITBusy : ITOffline);
1923 sleeptime = (as->parms[3].items ? atol(as->parms[3].items->data) : 0);
1924 transdone = ((sleeptime || as->parms[4].items) ? 0 /*online */ : VTOutOfService);
1925 if (as->parms[4].items && !as->parms[3].items) {
1926 fprintf(STDERR, "-sleep option must be used with -busy flag\n");
1931 UV_SetVolume(server, partition, volid, transflag, transdone,
1934 fprintf(STDERR, "Failed to set volume. Code = %d\n", code);
1942 CreateVolume(struct cmd_syndesc *as, void *arock)
1946 afs_uint32 volid = 0, rovolid = 0, bkvolid = 0;
1947 afs_uint32 *arovolid;
1949 struct nvldbentry entry;
1954 arovolid = &rovolid;
1957 tserver = GetServer(as->parms[0].items->data);
1959 fprintf(STDERR, "vos: host '%s' not found in host table\n",
1960 as->parms[0].items->data);
1963 pnum = volutil_GetPartitionID(as->parms[1].items->data);
1965 fprintf(STDERR, "vos: could not interpret partition name '%s'\n",
1966 as->parms[1].items->data);
1969 if (!IsPartValid(pnum, tserver, &code)) { /*check for validity of the partition */
1971 PrintError("", code);
1974 "vos : partition %s does not exist on the server\n",
1975 as->parms[1].items->data);
1978 if (!ISNAMEVALID(as->parms[2].items->data)) {
1980 "vos: the name of the root volume %s exceeds the size limit of %d\n",
1981 as->parms[2].items->data, VOLSER_OLDMAXVOLNAME - 10);
1984 if (!VolNameOK(as->parms[2].items->data)) {
1986 "Illegal volume name %s, should not end in .readonly or .backup\n",
1987 as->parms[2].items->data);
1990 if (IsNumeric(as->parms[2].items->data)) {
1991 fprintf(STDERR, "Illegal volume name %s, should not be a number\n",
1992 as->parms[2].items->data);
1995 vcode = VLDB_GetEntryByName(as->parms[2].items->data, &entry);
1997 fprintf(STDERR, "Volume %s already exists\n",
1998 as->parms[2].items->data);
1999 PrintDiagnostics("create", code);
2003 if (as->parms[3].items) {
2004 code = util_GetHumanInt32(as->parms[3].items->data, "a);
2006 fprintf(STDERR, "vos: bad integer specified for quota.\n");
2011 if (as->parms[4].items) {
2012 if (!IsNumeric(as->parms[4].items->data)) {
2013 fprintf(STDERR, "vos: Given volume ID %s should be numeric.\n",
2014 as->parms[4].items->data);
2018 code = util_GetUInt32(as->parms[4].items->data, &volid);
2020 fprintf(STDERR, "vos: bad integer specified for volume ID.\n");
2025 if (as->parms[5].items) {
2026 if (!IsNumeric(as->parms[5].items->data)) {
2027 fprintf(STDERR, "vos: Given RO volume ID %s should be numeric.\n",
2028 as->parms[5].items->data);
2032 code = util_GetUInt32(as->parms[5].items->data, &rovolid);
2034 fprintf(STDERR, "vos: bad integer specified for volume ID.\n");
2044 UV_CreateVolume3(tserver, pnum, as->parms[2].items->data, quota, 0,
2045 0, 0, 0, &volid, arovolid, &bkvolid);
2047 PrintDiagnostics("create", code);
2050 MapPartIdIntoName(pnum, part);
2051 fprintf(STDOUT, "Volume %lu created on partition %s of %s\n",
2052 (unsigned long)volid, part, as->parms[0].items->data);
2058 DeleteVolume(struct cmd_syndesc *as, void *arock)
2060 afs_int32 err, code = 0;
2061 afs_uint32 server = 0;
2062 afs_int32 partition = -1;
2067 if (as->parms[1].items && !as->parms[0].items) {
2068 fprintf(STDERR, "vos: The -partition option requires the -server option.\n");
2072 if (as->parms[0].items) {
2073 server = GetServer(as->parms[0].items->data);
2075 fprintf(STDERR, "vos: server '%s' not found in host table\n",
2076 as->parms[0].items->data);
2081 if (as->parms[1].items) {
2082 partition = volutil_GetPartitionID(as->parms[1].items->data);
2083 if (partition < 0) {
2084 fprintf(STDERR, "vos: could not interpret partition name '%s'\n",
2085 as->parms[1].items->data);
2089 /* Check for validity of the partition */
2090 if (!IsPartValid(partition, server, &code)) {
2092 PrintError("", code);
2095 "vos : partition %s does not exist on the server\n",
2096 as->parms[1].items->data);
2102 volid = vsu_GetVolumeID(as->parms[2].items->data, cstruct, &err);
2104 fprintf(STDERR, "Can't find volume name '%s' in VLDB\n",
2105 as->parms[2].items->data);
2107 PrintError("", err);
2111 /* If the server or partition option are not complete, try to fill
2112 * them in from the VLDB entry.
2114 if ((partition == -1) || !server) {
2115 struct nvldbentry entry;
2117 code = VLDB_GetEntryByID(volid, -1, &entry);
2120 "Could not fetch the entry for volume %lu from VLDB\n",
2121 (unsigned long)volid);
2122 PrintError("", code);
2126 if (((volid == entry.volumeId[RWVOL]) && (entry.flags & VLF_RWEXISTS))
2127 || ((volid == entry.volumeId[BACKVOL])
2128 && (entry.flags & VLF_BACKEXISTS))) {
2129 idx = Lp_GetRwIndex(&entry);
2130 if ((idx == -1) || (server && (server != entry.serverNumber[idx]))
2131 || ((partition != -1)
2132 && (partition != entry.serverPartition[idx]))) {
2133 fprintf(STDERR, "VLDB: Volume '%s' no match\n",
2134 as->parms[2].items->data);
2137 } else if ((volid == entry.volumeId[ROVOL])
2138 && (entry.flags & VLF_ROEXISTS)) {
2139 for (idx = -1, j = 0; j < entry.nServers; j++) {
2140 if (!(entry.serverFlags[j] & VLSF_ROVOL))
2143 if (((server == 0) || (server == entry.serverNumber[j]))
2144 && ((partition == -1)
2145 || (partition == entry.serverPartition[j]))) {
2148 "VLDB: Volume '%s' matches more than one RO\n",
2149 as->parms[2].items->data);
2156 fprintf(STDERR, "VLDB: Volume '%s' no match\n",
2157 as->parms[2].items->data);
2161 fprintf(STDERR, "VLDB: Volume '%s' no match\n",
2162 as->parms[2].items->data);
2166 server = htonl(entry.serverNumber[idx]);
2167 partition = entry.serverPartition[idx];
2170 code = UV_DeleteVolume(server, partition, volid);
2172 PrintDiagnostics("remove", code);
2176 MapPartIdIntoName(partition, pname);
2177 fprintf(STDOUT, "Volume %lu on partition %s server %s deleted\n",
2178 (unsigned long)volid, pname, hostutil_GetNameByINet(server));
2182 #define TESTM 0 /* set for move space tests, clear for production */
2184 MoveVolume(struct cmd_syndesc *as, void *arock)
2188 afs_uint32 fromserver, toserver;
2189 afs_int32 frompart, topart;
2190 afs_int32 flags, code, err;
2191 char fromPartName[10], toPartName[10];
2193 struct diskPartition64 partition; /* for space check */
2196 volid = vsu_GetVolumeID(as->parms[0].items->data, cstruct, &err);
2199 PrintError("", err);
2201 fprintf(STDERR, "vos: can't find volume ID or name '%s'\n",
2202 as->parms[0].items->data);
2205 fromserver = GetServer(as->parms[1].items->data);
2206 if (fromserver == 0) {
2207 fprintf(STDERR, "vos: server '%s' not found in host table\n",
2208 as->parms[1].items->data);
2211 toserver = GetServer(as->parms[3].items->data);
2212 if (toserver == 0) {
2213 fprintf(STDERR, "vos: server '%s' not found in host table\n",
2214 as->parms[3].items->data);
2217 frompart = volutil_GetPartitionID(as->parms[2].items->data);
2219 fprintf(STDERR, "vos: could not interpret partition name '%s'\n",
2220 as->parms[2].items->data);
2223 if (!IsPartValid(frompart, fromserver, &code)) { /*check for validity of the partition */
2225 PrintError("", code);
2228 "vos : partition %s does not exist on the server\n",
2229 as->parms[2].items->data);
2232 topart = volutil_GetPartitionID(as->parms[4].items->data);
2234 fprintf(STDERR, "vos: could not interpret partition name '%s'\n",
2235 as->parms[4].items->data);
2238 if (!IsPartValid(topart, toserver, &code)) { /*check for validity of the partition */
2240 PrintError("", code);
2243 "vos : partition %s does not exist on the server\n",
2244 as->parms[4].items->data);
2249 if (as->parms[5].items) flags |= RV_NOCLONE;
2252 * check source partition for space to clone volume
2255 MapPartIdIntoName(topart, toPartName);
2256 MapPartIdIntoName(frompart, fromPartName);
2259 * check target partition for space to move volume
2262 code = UV_PartitionInfo64(toserver, toPartName, &partition);
2264 fprintf(STDERR, "vos: cannot access partition %s\n", toPartName);
2268 fprintf(STDOUT, "target partition %s free space %" AFS_INT64_FMT "\n", toPartName,
2271 p = (volintInfo *) 0;
2272 code = UV_ListOneVolume(fromserver, frompart, volid, &p);
2274 fprintf(STDERR, "vos:cannot access volume %lu\n",
2275 (unsigned long)volid);
2279 fprintf(STDOUT, "volume %lu size %d\n", (unsigned long)volid,
2281 if (partition.free <= p->size) {
2283 "vos: no space on target partition %s to move volume %lu\n",
2284 toPartName, (unsigned long)volid);
2291 fprintf(STDOUT, "size test - don't do move\n");
2295 /* successful move still not guaranteed but shoot for it */
2298 UV_MoveVolume2(volid, fromserver, frompart, toserver, topart, flags);
2300 PrintDiagnostics("move", code);
2303 MapPartIdIntoName(topart, toPartName);
2304 MapPartIdIntoName(frompart, fromPartName);
2305 fprintf(STDOUT, "Volume %lu moved from %s %s to %s %s \n",
2306 (unsigned long)volid, as->parms[1].items->data, fromPartName,
2307 as->parms[3].items->data, toPartName);
2313 CopyVolume(struct cmd_syndesc *as, void *arock)
2316 afs_uint32 fromserver, toserver;
2317 afs_int32 frompart, topart, code, err, flags;
2318 char fromPartName[10], toPartName[10], *tovolume;
2319 struct nvldbentry entry;
2320 struct diskPartition64 partition; /* for space check */
2323 volid = vsu_GetVolumeID(as->parms[0].items->data, cstruct, &err);
2326 PrintError("", err);
2328 fprintf(STDERR, "vos: can't find volume ID or name '%s'\n",
2329 as->parms[0].items->data);
2332 fromserver = GetServer(as->parms[1].items->data);
2333 if (fromserver == 0) {
2334 fprintf(STDERR, "vos: server '%s' not found in host table\n",
2335 as->parms[1].items->data);
2339 toserver = GetServer(as->parms[4].items->data);
2340 if (toserver == 0) {
2341 fprintf(STDERR, "vos: server '%s' not found in host table\n",
2342 as->parms[4].items->data);
2346 tovolume = as->parms[3].items->data;
2347 if (!ISNAMEVALID(tovolume)) {
2349 "vos: the name of the root volume %s exceeds the size limit of %d\n",
2350 tovolume, VOLSER_OLDMAXVOLNAME - 10);
2353 if (!VolNameOK(tovolume)) {
2355 "Illegal volume name %s, should not end in .readonly or .backup\n",
2359 if (IsNumeric(tovolume)) {
2360 fprintf(STDERR, "Illegal volume name %s, should not be a number\n",
2364 code = VLDB_GetEntryByName(tovolume, &entry);
2366 fprintf(STDERR, "Volume %s already exists\n", tovolume);
2367 PrintDiagnostics("copy", code);
2371 frompart = volutil_GetPartitionID(as->parms[2].items->data);
2373 fprintf(STDERR, "vos: could not interpret partition name '%s'\n",
2374 as->parms[2].items->data);
2377 if (!IsPartValid(frompart, fromserver, &code)) { /*check for validity of the partition */
2379 PrintError("", code);
2382 "vos : partition %s does not exist on the server\n",
2383 as->parms[2].items->data);
2387 topart = volutil_GetPartitionID(as->parms[5].items->data);
2389 fprintf(STDERR, "vos: could not interpret partition name '%s'\n",
2390 as->parms[5].items->data);
2393 if (!IsPartValid(topart, toserver, &code)) { /*check for validity of the partition */
2395 PrintError("", code);
2398 "vos : partition %s does not exist on the server\n",
2399 as->parms[5].items->data);
2404 if (as->parms[6].items) flags |= RV_OFFLINE;
2405 if (as->parms[7].items) flags |= RV_RDONLY;
2406 if (as->parms[8].items) flags |= RV_NOCLONE;
2408 MapPartIdIntoName(topart, toPartName);
2409 MapPartIdIntoName(frompart, fromPartName);
2412 * check target partition for space to move volume
2415 code = UV_PartitionInfo64(toserver, toPartName, &partition);
2417 fprintf(STDERR, "vos: cannot access partition %s\n", toPartName);
2421 fprintf(STDOUT, "target partition %s free space %" AFS_INT64_FMT "\n", toPartName,
2424 p = (volintInfo *) 0;
2425 code = UV_ListOneVolume(fromserver, frompart, volid, &p);
2427 fprintf(STDERR, "vos:cannot access volume %lu\n",
2428 (unsigned long)volid);
2432 if (partition.free <= p->size) {
2434 "vos: no space on target partition %s to copy volume %lu\n",
2435 toPartName, (unsigned long)volid);
2441 /* successful copy still not guaranteed but shoot for it */
2444 UV_CopyVolume2(volid, fromserver, frompart, tovolume, toserver,
2447 PrintDiagnostics("copy", code);
2450 MapPartIdIntoName(topart, toPartName);
2451 MapPartIdIntoName(frompart, fromPartName);
2452 fprintf(STDOUT, "Volume %lu copied from %s %s to %s on %s %s \n",
2453 (unsigned long)volid, as->parms[1].items->data, fromPartName,
2454 tovolume, as->parms[4].items->data, toPartName);
2460 ShadowVolume(struct cmd_syndesc *as, void *arock)
2462 afs_uint32 volid, tovolid;
2463 afs_uint32 fromserver, toserver;
2464 afs_int32 frompart, topart;
2465 afs_int32 code, err, flags;
2466 char fromPartName[10], toPartName[10], toVolName[32], *tovolume;
2467 struct diskPartition64 partition; /* for space check */
2470 p = (volintInfo *) 0;
2471 q = (volintInfo *) 0;
2473 volid = vsu_GetVolumeID(as->parms[0].items->data, cstruct, &err);
2476 PrintError("", err);
2478 fprintf(STDERR, "vos: can't find volume ID or name '%s'\n",
2479 as->parms[0].items->data);
2482 fromserver = GetServer(as->parms[1].items->data);
2483 if (fromserver == 0) {
2484 fprintf(STDERR, "vos: server '%s' not found in host table\n",
2485 as->parms[1].items->data);
2489 toserver = GetServer(as->parms[3].items->data);
2490 if (toserver == 0) {
2491 fprintf(STDERR, "vos: server '%s' not found in host table\n",
2492 as->parms[3].items->data);
2496 frompart = volutil_GetPartitionID(as->parms[2].items->data);
2498 fprintf(STDERR, "vos: could not interpret partition name '%s'\n",
2499 as->parms[2].items->data);
2502 if (!IsPartValid(frompart, fromserver, &code)) { /*check for validity of the partition */
2504 PrintError("", code);
2507 "vos : partition %s does not exist on the server\n",
2508 as->parms[2].items->data);
2512 topart = volutil_GetPartitionID(as->parms[4].items->data);
2514 fprintf(STDERR, "vos: could not interpret partition name '%s'\n",
2515 as->parms[4].items->data);
2518 if (!IsPartValid(topart, toserver, &code)) { /*check for validity of the partition */
2520 PrintError("", code);
2523 "vos : partition %s does not exist on the server\n",
2524 as->parms[4].items->data);
2528 if (as->parms[5].items) {
2529 tovolume = as->parms[5].items->data;
2530 if (!ISNAMEVALID(tovolume)) {
2532 "vos: the name of the root volume %s exceeds the size limit of %d\n",
2533 tovolume, VOLSER_OLDMAXVOLNAME - 10);
2536 if (!VolNameOK(tovolume)) {
2538 "Illegal volume name %s, should not end in .readonly or .backup\n",
2542 if (IsNumeric(tovolume)) {
2544 "Illegal volume name %s, should not be a number\n",
2549 /* use actual name of source volume */
2550 code = UV_ListOneVolume(fromserver, frompart, volid, &p);
2552 fprintf(STDERR, "vos:cannot access volume %lu\n",
2553 (unsigned long)volid);
2556 strcpy(toVolName, p->name);
2557 tovolume = toVolName;
2558 /* save p for size checks later */
2561 if (as->parms[6].items) {
2562 tovolid = vsu_GetVolumeID(as->parms[6].items->data, cstruct, &err);
2565 PrintError("", err);
2567 fprintf(STDERR, "vos: can't find volume ID or name '%s'\n",
2568 as->parms[6].items->data);
2574 tovolid = vsu_GetVolumeID(tovolume, cstruct, &err);
2577 PrintError("", err);
2579 fprintf(STDERR, "vos: can't find volume ID or name '%s'\n",
2588 if (as->parms[7].items) flags |= RV_OFFLINE;
2589 if (as->parms[8].items) flags |= RV_RDONLY;
2590 if (as->parms[9].items) flags |= RV_NOCLONE;
2591 if (as->parms[10].items) flags |= RV_CPINCR;
2593 MapPartIdIntoName(topart, toPartName);
2594 MapPartIdIntoName(frompart, fromPartName);
2597 * check target partition for space to move volume
2600 code = UV_PartitionInfo64(toserver, toPartName, &partition);
2602 fprintf(STDERR, "vos: cannot access partition %s\n", toPartName);
2606 fprintf(STDOUT, "target partition %s free space %" AFS_INT64_FMT "\n", toPartName,
2609 /* Don't do this again if we did it above */
2611 code = UV_ListOneVolume(fromserver, frompart, volid, &p);
2613 fprintf(STDERR, "vos:cannot access volume %lu\n",
2614 (unsigned long)volid);
2619 /* OK if this fails */
2620 code = UV_ListOneVolume(toserver, topart, tovolid, &q);
2622 /* Treat existing volume size as "free" */
2624 p->size = (q->size < p->size) ? p->size - q->size : 0;
2626 if (partition.free <= p->size) {
2628 "vos: no space on target partition %s to copy volume %lu\n",
2629 toPartName, (unsigned long)volid);
2637 /* successful copy still not guaranteed but shoot for it */
2640 UV_CopyVolume2(volid, fromserver, frompart, tovolume, toserver,
2641 topart, tovolid, flags);
2643 PrintDiagnostics("shadow", code);
2646 MapPartIdIntoName(topart, toPartName);
2647 MapPartIdIntoName(frompart, fromPartName);
2648 fprintf(STDOUT, "Volume %lu shadowed from %s %s to %s %s \n",
2649 (unsigned long)volid, as->parms[1].items->data, fromPartName,
2650 as->parms[3].items->data, toPartName);
2656 CloneVolume(struct cmd_syndesc *as, void *arock)
2658 afs_uint32 volid, cloneid;
2660 afs_int32 part, voltype;
2661 char partName[10], *volname;
2662 afs_int32 code, err, flags;
2663 struct nvldbentry entry;
2665 volid = vsu_GetVolumeID(as->parms[0].items->data, cstruct, &err);
2668 PrintError("", err);
2670 fprintf(STDERR, "vos: can't find volume ID or name '%s'\n",
2671 as->parms[0].items->data);
2675 if (as->parms[1].items || as->parms[2].items) {
2676 if (!as->parms[1].items || !as->parms[2].items) {
2678 "Must specify both -server and -partition options\n");
2681 server = GetServer(as->parms[1].items->data);
2683 fprintf(STDERR, "vos: server '%s' not found in host table\n",
2684 as->parms[1].items->data);
2687 part = volutil_GetPartitionID(as->parms[2].items->data);
2689 fprintf(STDERR, "vos: could not interpret partition name '%s'\n",
2690 as->parms[2].items->data);
2693 if (!IsPartValid(part, server, &code)) { /*check for validity of the partition */
2695 PrintError("", code);
2698 "vos : partition %s does not exist on the server\n",
2699 as->parms[2].items->data);
2703 code = GetVolumeInfo(volid, &server, &part, &voltype, &entry);
2709 if (as->parms[3].items) {
2710 volname = as->parms[3].items->data;
2711 if (strlen(volname) > VOLSER_OLDMAXVOLNAME - 1) {
2713 "vos: the name of the root volume %s exceeds the size limit of %d\n",
2714 volname, VOLSER_OLDMAXVOLNAME - 1);
2717 if (IsNumeric(volname)) {
2719 "Illegal volume name %s, should not be a number\n",
2726 if (as->parms[4].items) {
2727 cloneid = vsu_GetVolumeID(as->parms[4].items->data, cstruct, &err);
2730 PrintError("", err);
2732 fprintf(STDERR, "vos: can't find volume ID or name '%s'\n",
2733 as->parms[4].items->data);
2739 if (as->parms[5].items) flags |= RV_OFFLINE;
2740 if (as->parms[6].items && as->parms[7].items) {
2741 fprintf(STDERR, "vos: cannot specify that a volume be -readwrite and -readonly\n");
2744 if (as->parms[6].items) flags |= RV_RDONLY;
2745 if (as->parms[7].items) flags |= RV_RWONLY;
2748 UV_CloneVolume(server, part, volid, cloneid, volname, flags);
2751 PrintDiagnostics("clone", code);
2754 MapPartIdIntoName(part, partName);
2755 fprintf(STDOUT, "Created clone for volume %s\n",
2756 as->parms[0].items->data);
2762 BackupVolume(struct cmd_syndesc *as, void *arock)
2766 afs_int32 apart, vtype, code, err;
2767 struct nvldbentry entry;
2770 afs_uint32 buserver;
2771 afs_int32 bupart, butype;
2772 struct nvldbentry buentry;
2774 avolid = vsu_GetVolumeID(as->parms[0].items->data, cstruct, &err);
2777 PrintError("", err);
2779 fprintf(STDERR, "vos: can't find volume ID or name '%s'\n",
2780 as->parms[0].items->data);
2783 code = GetVolumeInfo(avolid, &aserver, &apart, &vtype, &entry);
2787 /* verify this is a readwrite volume */
2789 if (vtype != RWVOL) {
2790 fprintf(STDERR, "%s not RW volume\n", as->parms[0].items->data);
2794 /* is there a backup volume already? */
2796 if (entry.flags & VLF_BACKEXISTS) {
2797 /* yep, where is it? */
2799 buvolid = entry.volumeId[BACKVOL];
2800 code = GetVolumeInfo(buvolid, &buserver, &bupart, &butype, &buentry);
2805 code = VLDB_IsSameAddrs(buserver, aserver, &err);
2808 "Failed to get info about server's %d address(es) from vlserver; aborting call!\n",
2814 "FATAL ERROR: backup volume %lu exists on server %lu\n",
2815 (unsigned long)buvolid, (unsigned long)buserver);
2820 /* nope, carry on */
2822 code = UV_BackupVolume(aserver, apart, avolid);
2825 PrintDiagnostics("backup", code);
2828 fprintf(STDOUT, "Created backup volume for %s \n",
2829 as->parms[0].items->data);
2834 ReleaseVolume(struct cmd_syndesc *as, void *arock)
2837 struct nvldbentry entry;
2840 afs_int32 apart, vtype, code, err;
2843 if (as->parms[1].items) /* -force */
2844 flags |= (REL_COMPLETE | REL_FULLDUMPS);
2845 if (as->parms[2].items) { /* -stayonline */
2846 fprintf(STDERR, "vos: -stayonline not supported\n");
2849 if (as->parms[3].items) /* -force-reclone */
2850 flags |= REL_COMPLETE;
2852 avolid = vsu_GetVolumeID(as->parms[0].items->data, cstruct, &err);
2855 PrintError("", err);
2857 fprintf(STDERR, "vos: can't find volume '%s'\n",
2858 as->parms[0].items->data);
2861 code = GetVolumeInfo(avolid, &aserver, &apart, &vtype, &entry);
2865 if (vtype != RWVOL) {
2866 fprintf(STDERR, "%s not a RW volume\n", as->parms[0].items->data);
2870 if (!ISNAMEVALID(entry.name)) {
2872 "Volume name %s is too long, rename before releasing\n",
2877 code = UV_ReleaseVolume(avolid, aserver, apart, flags);
2880 PrintDiagnostics("release", code);
2883 fprintf(STDOUT, "Released volume %s successfully\n",
2884 as->parms[0].items->data);
2889 DumpVolumeCmd(struct cmd_syndesc *as, void *arock)
2893 afs_int32 apart, voltype, fromdate = 0, code, err, i, flags;
2894 char filename[MAXPATHLEN];
2895 struct nvldbentry entry;
2897 rx_SetRxDeadTime(60 * 10);
2898 for (i = 0; i < MAXSERVERS; i++) {
2899 struct rx_connection *rxConn = ubik_GetRPCConn(cstruct, i);
2902 rx_SetConnDeadTime(rxConn, rx_connDeadTime);
2903 if (rx_ServiceOf(rxConn))
2904 rx_ServiceOf(rxConn)->connDeadTime = rx_connDeadTime;
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);
2917 if (as->parms[3].items || as->parms[4].items) {
2918 if (!as->parms[3].items || !as->parms[4].items) {
2920 "Must specify both -server and -partition options\n");
2923 aserver = GetServer(as->parms[3].items->data);
2925 fprintf(STDERR, "Invalid server name\n");
2928 apart = volutil_GetPartitionID(as->parms[4].items->data);
2930 fprintf(STDERR, "Invalid partition name\n");
2934 code = GetVolumeInfo(avolid, &aserver, &apart, &voltype, &entry);
2939 if (as->parms[1].items && strcmp(as->parms[1].items->data, "0")) {
2940 code = ktime_DateToInt32(as->parms[1].items->data, &fromdate);
2942 fprintf(STDERR, "vos: failed to parse date '%s' (error=%d))\n",
2943 as->parms[1].items->data, code);
2947 if (as->parms[2].items) {
2948 strcpy(filename, as->parms[2].items->data);
2950 strcpy(filename, "");
2953 flags = as->parms[6].items ? VOLDUMPV2_OMITDIRS : 0;
2955 if (as->parms[5].items) {
2957 UV_DumpClonedVolume(avolid, aserver, apart, fromdate,
2958 DumpFunction, filename, flags);
2961 UV_DumpVolume(avolid, aserver, apart, fromdate, DumpFunction,
2964 if ((code == RXGEN_OPCODE) && (as->parms[6].items)) {
2965 flags &= ~VOLDUMPV2_OMITDIRS;
2969 PrintDiagnostics("dump", code);
2972 if (strcmp(filename, ""))
2973 fprintf(STDERR, "Dumped volume %s in file %s\n",
2974 as->parms[0].items->data, filename);
2976 fprintf(STDERR, "Dumped volume %s in stdout \n",
2977 as->parms[0].items->data);
2991 RestoreVolumeCmd(struct cmd_syndesc *as, void *arock)
2993 afs_uint32 avolid, aparentid;
2995 afs_int32 apart, code, vcode, err;
2996 afs_int32 aoverwrite = ASK;
2997 afs_int32 acreation = 0, alastupdate = 0;
2998 int restoreflags = 0;
2999 int readonly = 0, offline = 0, voltype = RWVOL;
3000 char afilename[MAXPATHLEN], avolname[VOLSER_MAXVOLNAME + 1], apartName[10];
3001 char volname[VOLSER_MAXVOLNAME + 1];
3002 struct nvldbentry entry;
3005 if (as->parms[4].items) {
3006 avolid = vsu_GetVolumeID(as->parms[4].items->data, cstruct, &err);
3009 PrintError("", err);
3011 fprintf(STDERR, "vos: can't find volume '%s'\n",
3012 as->parms[4].items->data);
3018 if (as->parms[5].items) {
3019 if ((strcmp(as->parms[5].items->data, "a") == 0)
3020 || (strcmp(as->parms[5].items->data, "abort") == 0)) {
3022 } else if ((strcmp(as->parms[5].items->data, "f") == 0)
3023 || (strcmp(as->parms[5].items->data, "full") == 0)) {
3025 } else if ((strcmp(as->parms[5].items->data, "i") == 0)
3026 || (strcmp(as->parms[5].items->data, "inc") == 0)
3027 || (strcmp(as->parms[5].items->data, "increment") == 0)
3028 || (strcmp(as->parms[5].items->data, "incremental") == 0)) {
3031 fprintf(STDERR, "vos: %s is not a valid argument to -overwrite\n",
3032 as->parms[5].items->data);
3036 if (as->parms[6].items)
3038 if (as->parms[7].items) {
3043 if (as->parms[8].items) {
3044 if ((strcmp(as->parms[8].items->data, "d") == 0)
3045 || (strcmp(as->parms[8].items->data, "dump") == 0)) {
3046 acreation = TS_DUMP;
3047 } else if ((strcmp(as->parms[8].items->data, "k") == 0)
3048 || (strcmp(as->parms[8].items->data, "keep") == 0)) {
3049 acreation = TS_KEEP;
3050 } else if ((strcmp(as->parms[8].items->data, "n") == 0)
3051 || (strcmp(as->parms[8].items->data, "new") == 0)) {
3054 fprintf(STDERR, "vos: %s is not a valid argument to -creation\n",
3055 as->parms[8].items->data);
3060 if (as->parms[9].items) {
3061 if ((strcmp(as->parms[9].items->data, "d") == 0)
3062 || (strcmp(as->parms[9].items->data, "dump") == 0)) {
3063 alastupdate = TS_DUMP;
3064 } else if ((strcmp(as->parms[9].items->data, "k") == 0)
3065 || (strcmp(as->parms[9].items->data, "keep") == 0)) {
3066 alastupdate = TS_KEEP;
3067 } else if ((strcmp(as->parms[9].items->data, "n") == 0)
3068 || (strcmp(as->parms[9].items->data, "new") == 0)) {
3069 alastupdate = TS_NEW;
3071 fprintf(STDERR, "vos: %s is not a valid argument to -lastupdate\n",
3072 as->parms[9].items->data);
3077 aserver = GetServer(as->parms[0].items->data);
3079 fprintf(STDERR, "vos: server '%s' not found in host table\n",
3080 as->parms[0].items->data);
3083 apart = volutil_GetPartitionID(as->parms[1].items->data);
3085 fprintf(STDERR, "vos: could not interpret partition name '%s'\n",
3086 as->parms[1].items->data);
3089 if (!IsPartValid(apart, aserver, &code)) { /*check for validity of the partition */
3091 PrintError("", code);
3094 "vos : partition %s does not exist on the server\n",
3095 as->parms[1].items->data);
3098 strcpy(avolname, as->parms[2].items->data);
3099 if (!ISNAMEVALID(avolname)) {
3101 "vos: the name of the volume %s exceeds the size limit\n",
3105 if (!VolNameOK(avolname)) {
3107 "Illegal volume name %s, should not end in .readonly or .backup\n",
3111 if (as->parms[3].items) {
3112 strcpy(afilename, as->parms[3].items->data);
3113 if (!FileExists(afilename)) {
3114 fprintf(STDERR, "Can't access file %s\n", afilename);
3118 strcpy(afilename, "");
3121 /* Check if volume exists or not */
3123 vsu_ExtractName(volname, avolname);
3124 vcode = VLDB_GetEntryByName(volname, &entry);
3125 if (vcode) { /* no volume - do a full restore */
3126 restoreflags = RV_FULLRST;
3127 if ((aoverwrite == INC) || (aoverwrite == ABORT))
3129 "Volume does not exist; Will perform a full restore\n");
3132 else if ((!readonly && Lp_GetRwIndex(&entry) == -1) /* RW volume does not exist - do a full */
3133 ||(readonly && !Lp_ROMatch(0, 0, &entry))) { /* RO volume does not exist - do a full */
3134 restoreflags = RV_FULLRST;
3135 if ((aoverwrite == INC) || (aoverwrite == ABORT))
3137 "%s Volume does not exist; Will perform a full restore\n",
3138 readonly ? "RO" : "RW");
3141 avolid = entry.volumeId[voltype];
3142 } else if (entry.volumeId[voltype] != 0
3143 && entry.volumeId[voltype] != avolid) {
3144 avolid = entry.volumeId[voltype];
3146 aparentid = entry.volumeId[RWVOL];
3149 else { /* volume exists - do we do a full incremental or abort */
3151 afs_int32 Opart, Otype, vol_elsewhere = 0;
3152 struct nvldbentry Oentry;
3156 avolid = entry.volumeId[voltype];
3157 } else if (entry.volumeId[voltype] != 0
3158 && entry.volumeId[voltype] != avolid) {
3159 avolid = entry.volumeId[voltype];
3161 aparentid = entry.volumeId[RWVOL];
3163 /* A file name was specified - check if volume is on another partition */
3164 vcode = GetVolumeInfo(avolid, &Oserver, &Opart, &Otype, &Oentry);
3168 vcode = VLDB_IsSameAddrs(Oserver, aserver, &err);
3171 "Failed to get info about server's %d address(es) from vlserver (err=%d); aborting call!\n",
3175 if (!vcode || (Opart != apart))
3178 if (aoverwrite == ASK) {
3179 if (strcmp(afilename, "") == 0) { /* The file is from standard in */
3181 "Volume exists and no -overwrite option specified; Aborting restore command\n");
3185 /* Ask what to do */
3186 if (vol_elsewhere) {
3188 "The volume %s %u already exists on a different server/part\n",
3189 volname, entry.volumeId[voltype]);
3191 "Do you want to do a full restore or abort? [fa](a): ");
3194 "The volume %s %u already exists in the VLDB\n",
3195 volname, entry.volumeId[voltype]);
3197 "Do you want to do a full/incremental restore or abort? [fia](a): ");
3200 while (!(dc == EOF || dc == '\n'))
3201 dc = getchar(); /* goto end of line */
3202 if ((c == 'f') || (c == 'F'))
3204 else if ((c == 'i') || (c == 'I'))
3210 if (aoverwrite == ABORT) {
3211 fprintf(STDERR, "Volume exists; Aborting restore command\n");
3213 } else if (aoverwrite == FULL) {
3214 restoreflags = RV_FULLRST;
3216 "Volume exists; Will delete and perform full restore\n");
3217 } else if (aoverwrite == INC) {
3219 if (vol_elsewhere) {
3221 "%s volume %lu already exists on a different server/part; not allowed\n",
3222 readonly ? "RO" : "RW", (unsigned long)avolid);
3228 restoreflags |= RV_OFFLINE;
3230 restoreflags |= RV_RDONLY;
3232 switch (acreation) {
3234 restoreflags |= RV_CRDUMP;
3237 restoreflags |= RV_CRKEEP;
3240 restoreflags |= RV_CRNEW;
3243 if (aoverwrite == FULL)
3244 restoreflags |= RV_CRNEW;
3246 restoreflags |= RV_CRKEEP;
3249 switch (alastupdate) {
3251 restoreflags |= RV_LUDUMP;
3254 restoreflags |= RV_LUKEEP;
3257 restoreflags |= RV_LUNEW;
3260 restoreflags |= RV_LUDUMP;
3262 if (as->parms[10].items) {
3263 restoreflags |= RV_NODEL;
3267 UV_RestoreVolume2(aserver, apart, avolid, aparentid,
3268 avolname, restoreflags, WriteData, afilename);
3270 PrintDiagnostics("restore", code);
3273 MapPartIdIntoName(apart, apartName);
3275 fprintf(STDOUT, "Restored volume %s on %s %s\n", avolname,
3276 as->parms[0].items->data, apartName);
3281 LockReleaseCmd(struct cmd_syndesc *as, void *arock)
3284 afs_int32 code, err;
3286 avolid = vsu_GetVolumeID(as->parms[0].items->data, cstruct, &err);
3289 PrintError("", err);
3291 fprintf(STDERR, "vos: can't find volume '%s'\n",
3292 as->parms[0].items->data);
3296 code = UV_LockRelease(avolid);
3298 PrintDiagnostics("unlock", code);
3301 fprintf(STDOUT, "Released lock on vldb entry for volume %s\n",
3302 as->parms[0].items->data);
3307 AddSite(struct cmd_syndesc *as, void *arock)
3311 afs_int32 apart, code, err, arovolid, valid = 0;
3312 char apartName[10], avolname[VOLSER_MAXVOLNAME + 1];
3314 vsu_ExtractName(avolname, as->parms[2].items->data);;
3315 avolid = vsu_GetVolumeID(avolname, cstruct, &err);
3318 PrintError("", err);
3320 fprintf(STDERR, "vos: can't find volume '%s'\n",
3321 as->parms[2].items->data);
3325 if (as->parms[3].items) {
3326 vsu_ExtractName(avolname, as->parms[3].items->data);
3327 arovolid = vsu_GetVolumeID(avolname, cstruct, &err);
3329 fprintf(STDERR, "vos: invalid ro volume id '%s'\n",
3330 as->parms[3].items->data);
3334 aserver = GetServer(as->parms[0].items->data);
3336 fprintf(STDERR, "vos: server '%s' not found in host table\n",
3337 as->parms[0].items->data);
3340 apart = volutil_GetPartitionID(as->parms[1].items->data);
3342 fprintf(STDERR, "vos: could not interpret partition name '%s'\n",
3343 as->parms[1].items->data);
3346 if (!IsPartValid(apart, aserver, &code)) { /*check for validity of the partition */
3348 PrintError("", code);
3351 "vos : partition %s does not exist on the server\n",
3352 as->parms[1].items->data);
3355 if (as->parms[4].items) {
3358 code = UV_AddSite2(aserver, apart, avolid, arovolid, valid);
3360 PrintDiagnostics("addsite", code);
3363 MapPartIdIntoName(apart, apartName);
3364 fprintf(STDOUT, "Added replication site %s %s for volume %s\n",
3365 as->parms[0].items->data, apartName, as->parms[2].items->data);
3370 RemoveSite(struct cmd_syndesc *as, void *arock)
3375 afs_int32 apart, code, err;
3376 char apartName[10], avolname[VOLSER_MAXVOLNAME + 1];
3378 vsu_ExtractName(avolname, as->parms[2].items->data);
3379 avolid = vsu_GetVolumeID(avolname, cstruct, &err);
3382 PrintError("", err);
3384 fprintf(STDERR, "vos: can't find volume '%s'\n",
3385 as->parms[2].items->data);
3388 aserver = GetServer(as->parms[0].items->data);
3390 fprintf(STDERR, "vos: server '%s' not found in host table\n",
3391 as->parms[0].items->data);
3394 apart = volutil_GetPartitionID(as->parms[1].items->data);
3396 fprintf(STDERR, "vos: could not interpret partition name '%s'\n",
3397 as->parms[1].items->data);
3401 * The partition validity check is skipped, since it is possible that the
3402 * partition has already been decomissioned.
3405 code = UV_RemoveSite(aserver, apart, avolid);
3407 PrintDiagnostics("remsite", code);
3410 MapPartIdIntoName(apart, apartName);
3411 fprintf(STDOUT, "Removed replication site %s %s for volume %s\n",
3412 as->parms[0].items->data, apartName, as->parms[2].items->data);
3417 ChangeLocation(struct cmd_syndesc *as, void *arock)
3421 afs_int32 apart, code, err;
3424 avolid = vsu_GetVolumeID(as->parms[2].items->data, cstruct, &err);
3427 PrintError("", err);
3429 fprintf(STDERR, "vos: can't find volume '%s'\n",
3430 as->parms[2].items->data);
3433 aserver = GetServer(as->parms[0].items->data);
3435 fprintf(STDERR, "vos: server '%s' not found in host table\n",
3436 as->parms[0].items->data);
3439 apart = volutil_GetPartitionID(as->parms[1].items->data);
3441 fprintf(STDERR, "vos: could not interpret partition name '%s'\n",
3442 as->parms[1].items->data);
3445 if (!IsPartValid(apart, aserver, &code)) { /*check for validity of the partition */
3447 PrintError("", code);
3450 "vos : partition %s does not exist on the server\n",
3451 as->parms[1].items->data);
3454 code = UV_ChangeLocation(aserver, apart, avolid);
3456 PrintDiagnostics("changeloc", code);
3459 MapPartIdIntoName(apart, apartName);
3460 fprintf(STDOUT, "Changed location to %s %s for volume %s\n",
3461 as->parms[0].items->data, apartName, as->parms[2].items->data);
3466 ListPartitions(struct cmd_syndesc *as, void *arock)
3470 struct partList dummyPartList;
3475 aserver = GetServer(as->parms[0].items->data);
3477 fprintf(STDERR, "vos: server '%s' not found in host table\n",
3478 as->parms[0].items->data);
3482 code = UV_ListPartitions(aserver, &dummyPartList, &cnt);
3484 PrintDiagnostics("listpart", code);
3488 fprintf(STDOUT, "The partitions on the server are:\n");
3489 for (i = 0; i < cnt; i++) {
3490 if (dummyPartList.partFlags[i] & PARTVALID) {
3491 memset(pname, 0, sizeof(pname));
3492 MapPartIdIntoName(dummyPartList.partId[i], pname);
3493 fprintf(STDOUT, " %10s ", pname);
3495 if ((i % 5) == 0 && (i != 0))
3496 fprintf(STDOUT, "\n");
3499 fprintf(STDOUT, "\n");
3500 fprintf(STDOUT, "Total: %d\n", total);
3506 CompareVolName(const void *p1, const void *p2)
3508 volintInfo *arg1, *arg2;
3510 arg1 = (volintInfo *) p1;
3511 arg2 = (volintInfo *) p2;
3512 return (strcmp(arg1->name, arg2->name));
3516 /*------------------------------------------------------------------------
3517 * PRIVATE XCompareVolName
3520 * Comparison routine for volume names coming from an extended
3524 * a_obj1P : Char ptr to first extended vol info object
3525 * a_obj1P : Char ptr to second extended vol info object
3528 * The value of strcmp() on the volume names within the passed
3529 * objects (i,e., -1, 0, or 1).
3532 * Passed to qsort() as the designated comparison routine.
3536 *------------------------------------------------------------------------*/
3539 XCompareVolName(const void *a_obj1P, const void *a_obj2P)
3540 { /*XCompareVolName */
3543 (((struct volintXInfo *)(a_obj1P))->name,
3544 ((struct volintXInfo *)(a_obj2P))->name));
3546 } /*XCompareVolName */
3549 CompareVolID(const void *p1, const void *p2)
3551 volintInfo *arg1, *arg2;
3553 arg1 = (volintInfo *) p1;
3554 arg2 = (volintInfo *) p2;
3555 if (arg1->volid == arg2->volid)
3557 if (arg1->volid > arg2->volid)
3564 /*------------------------------------------------------------------------
3565 * PRIVATE XCompareVolID
3568 * Comparison routine for volume IDs coming from an extended
3572 * a_obj1P : Char ptr to first extended vol info object
3573 * a_obj1P : Char ptr to second extended vol info object
3576 * The value of strcmp() on the volume names within the passed
3577 * objects (i,e., -1, 0, or 1).
3580 * Passed to qsort() as the designated comparison routine.
3584 *------------------------------------------------------------------------*/
3587 XCompareVolID(const void *a_obj1P, const void *a_obj2P)
3588 { /*XCompareVolID */
3590 afs_int32 id1, id2; /*Volume IDs we're comparing */
3592 id1 = ((struct volintXInfo *)(a_obj1P))->volid;
3593 id2 = ((struct volintXInfo *)(a_obj2P))->volid;
3601 } /*XCompareVolID */
3603 /*------------------------------------------------------------------------
3604 * PRIVATE ListVolumes
3607 * Routine used to list volumes, contacting the Volume Server
3608 * directly, bypassing the VLDB.
3611 * as : Ptr to parsed command line arguments.
3614 * 0 Successful operation
3617 * Nothing interesting.
3621 *------------------------------------------------------------------------*/
3624 ListVolumes(struct cmd_syndesc *as, void *arock)
3626 afs_int32 apart, int32list, fast;
3630 volintInfo *oldpntr = NULL;
3634 volintXInfo *xInfoP;
3635 volintXInfo *origxInfoP = NULL; /*Ptr to current/orig extended vol info */
3636 int wantExtendedInfo; /*Do we want extended vol info? */
3639 struct partList dummyPartList;
3647 if (as->parms[3].items)
3649 if (as->parms[4].items)
3653 if (as->parms[2].items)
3659 if (as->parms[5].items) {
3661 * We can't coexist with the fast flag.
3665 "vos: Can't use the -fast and -extended flags together\n");
3670 * We need to turn on ``long'' listings to get the full effect.
3672 wantExtendedInfo = 1;
3675 wantExtendedInfo = 0;
3676 if (as->parms[1].items) {
3677 apart = volutil_GetPartitionID(as->parms[1].items->data);
3679 fprintf(STDERR, "vos: could not interpret partition name '%s'\n",
3680 as->parms[1].items->data);
3683 dummyPartList.partId[0] = apart;
3684 dummyPartList.partFlags[0] = PARTVALID;
3687 aserver = GetServer(as->parms[0].items->data);
3689 fprintf(STDERR, "vos: server '%s' not found in host table\n",
3690 as->parms[0].items->data);
3695 if (!IsPartValid(apart, aserver, &code)) { /*check for validity of the partition */
3697 PrintError("", code);
3700 "vos : partition %s does not exist on the server\n",
3701 as->parms[1].items->data);
3705 code = UV_ListPartitions(aserver, &dummyPartList, &cnt);
3707 PrintDiagnostics("listvol", code);
3711 for (i = 0; i < cnt; i++) {
3712 if (dummyPartList.partFlags[i] & PARTVALID) {
3713 if (wantExtendedInfo)
3715 UV_XListVolumes(aserver, dummyPartList.partId[i], all,
3719 UV_ListVolumes(aserver, dummyPartList.partId[i], all,
3722 PrintDiagnostics("listvol", code);
3725 if (wantExtendedInfo) {
3726 origxInfoP = xInfoP;
3727 base = (char *)xInfoP;
3730 base = (char *)pntr;
3734 if (wantExtendedInfo)
3735 qsort(base, count, sizeof(volintXInfo), XCompareVolName);
3737 qsort(base, count, sizeof(volintInfo), CompareVolName);
3739 if (wantExtendedInfo)
3740 qsort(base, count, sizeof(volintXInfo), XCompareVolID);
3742 qsort(base, count, sizeof(volintInfo), CompareVolID);
3744 MapPartIdIntoName(dummyPartList.partId[i], pname);
3747 "Total number of volumes on server %s partition %s: %lu \n",
3748 as->parms[0].items->data, pname,
3749 (unsigned long)count);
3750 if (wantExtendedInfo) {
3751 if (as->parms[6].items)
3752 XDisplayVolumes2(aserver, dummyPartList.partId[i], origxInfoP,
3753 count, int32list, fast, quiet);
3755 XDisplayVolumes(aserver, dummyPartList.partId[i], origxInfoP,
3756 count, int32list, fast, quiet);
3759 xInfoP = (volintXInfo *) 0;
3761 if (as->parms[6].items)
3762 DisplayVolumes2(aserver, dummyPartList.partId[i], oldpntr,
3765 DisplayVolumes(aserver, dummyPartList.partId[i], oldpntr,
3766 count, int32list, fast, quiet);
3769 pntr = (volintInfo *) 0;
3777 SyncVldb(struct cmd_syndesc *as, void *arock)
3779 afs_int32 pnum = 0, code; /* part name */
3787 if (as->parms[1].items && !as->parms[0].items) {
3788 fprintf(STDERR, "vos: The -partition option requires the -server option.\n");
3792 if (as->parms[0].items) {
3793 tserver = GetServer(as->parms[0].items->data);
3795 fprintf(STDERR, "vos: host '%s' not found in host table\n",
3796 as->parms[0].items->data);
3801 if (as->parms[1].items) {
3802 pnum = volutil_GetPartitionID(as->parms[1].items->data);
3804 fprintf(STDERR, "vos: could not interpret partition name '%s'\n",
3805 as->parms[1].items->data);
3808 if (!IsPartValid(pnum, tserver, &code)) { /*check for validity of the partition */
3810 PrintError("", code);
3813 "vos: partition %s does not exist on the server\n",
3814 as->parms[1].items->data);
3820 if (as->parms[3].items) {
3821 flags |= 2; /* don't update */
3824 if (as->parms[2].items) {
3825 /* Synchronize an individual volume */
3826 volname = as->parms[2].items->data;
3827 code = UV_SyncVolume(tserver, pnum, volname, flags);
3831 "Without a -volume option, the -server option is required\n");
3834 code = UV_SyncVldb(tserver, pnum, flags, 0 /*unused */ );
3838 PrintDiagnostics("syncvldb", code);
3842 /* Print a summary of what we did */
3844 fprintf(STDOUT, "VLDB volume %s synchronized", volname);
3846 fprintf(STDOUT, "VLDB synchronized");
3848 fprintf(STDOUT, " with state of server %s", as->parms[0].items->data);
3851 MapPartIdIntoName(pnum, part);
3852 fprintf(STDOUT, " partition %s\n", part);
3854 fprintf(STDOUT, "\n");
3860 SyncServer(struct cmd_syndesc *as, void *arock)
3862 afs_int32 pnum, code; /* part name */
3868 tserver = GetServer(as->parms[0].items->data);
3870 fprintf(STDERR, "vos: host '%s' not found in host table\n",
3871 as->parms[0].items->data);
3874 if (as->parms[1].items) {
3875 pnum = volutil_GetPartitionID(as->parms[1].items->data);
3877 fprintf(STDERR, "vos: could not interpret partition name '%s'\n",
3878 as->parms[1].items->data);
3881 if (!IsPartValid(pnum, tserver, &code)) { /*check for validity of the partition */
3883 PrintError("", code);
3886 "vos : partition %s does not exist on the server\n",
3887 as->parms[1].items->data);
3895 if (as->parms[2].items) {
3896 flags |= 2; /* don't update */
3898 code = UV_SyncServer(tserver, pnum, flags, 0 /*unused */ );
3900 PrintDiagnostics("syncserv", code);
3904 MapPartIdIntoName(pnum, part);
3905 fprintf(STDOUT, "Server %s partition %s synchronized with VLDB\n",
3906 as->parms[0].items->data, part);
3908 fprintf(STDOUT, "Server %s synchronized with VLDB\n",
3909 as->parms[0].items->data);
3915 VolumeInfoCmd(char *name)
3917 struct nvldbentry entry;
3920 /* The vlserver will handle names with the .readonly
3921 * and .backup extension as well as volume ids.
3923 vcode = VLDB_GetEntryByName(name, &entry);
3925 PrintError("", vcode);
3928 MapHostToNetwork(&entry);
3929 EnumerateEntry(&entry);
3931 /* Defect #3027: grubby check to handle locked volume.
3932 * If VLOP_ALLOPERS is set, the entry is locked.
3933 * Leave this routine as is, but put in correct check.
3935 PrintLocked(entry.flags);
3941 VolumeZap(struct cmd_syndesc *as, void *arock)
3943 struct nvldbentry entry;
3944 afs_uint32 volid, zapbackupid = 0, backupid = 0;
3945 afs_int32 code, server, part, err;
3947 if (as->parms[3].items) {
3948 /* force flag is on, use the other version */
3949 return NukeVolume(as);
3952 if (as->parms[4].items) {
3956 volid = vsu_GetVolumeID(as->parms[2].items->data, cstruct, &err);
3959 PrintError("", err);
3961 fprintf(STDERR, "vos: can't find volume '%s'\n",
3962 as->parms[2].items->data);
3965 part = volutil_GetPartitionID(as->parms[1].items->data);
3967 fprintf(STDERR, "vos: could not interpret partition name '%s'\n",
3968 as->parms[1].items->data);
3971 server = GetServer(as->parms[0].items->data);
3973 fprintf(STDERR, "vos: host '%s' not found in host table\n",
3974 as->parms[0].items->data);
3977 if (!IsPartValid(part, server, &code)) { /*check for validity of the partition */
3979 PrintError("", code);
3982 "vos : partition %s does not exist on the server\n",
3983 as->parms[1].items->data);
3986 code = VLDB_GetEntryByID(volid, -1, &entry);
3988 if (volid == entry.volumeId[RWVOL])
3989 backupid = entry.volumeId[BACKVOL];
3991 "Warning: Entry for volume number %lu exists in VLDB (but we're zapping it anyway!)\n",
3992 (unsigned long)volid);
3995 volintInfo *pntr = (volintInfo *) 0;
3998 code = UV_ListOneVolume(server, part, volid, &pntr);
4000 if (volid == pntr->parentID)
4001 backupid = pntr->backupID;
4007 code = UV_VolumeZap(server, part, backupid);
4009 PrintDiagnostics("zap", code);
4012 fprintf(STDOUT, "Backup Volume %lu deleted\n",
4013 (unsigned long)backupid);
4016 code = UV_VolumeZap(server, part, volid);
4018 PrintDiagnostics("zap", code);
4021 fprintf(STDOUT, "Volume %lu deleted\n", (unsigned long)volid);
4027 VolserStatus(struct cmd_syndesc *as, void *arock)
4031 transDebugInfo *pntr, *oldpntr;
4037 server = GetServer(as->parms[0].items->data);
4039 fprintf(STDERR, "vos: host '%s' not found in host table\n",
4040 as->parms[0].items->data);
4043 code = UV_VolserStatus(server, &pntr, &count);
4045 PrintDiagnostics("status", code);
4050 fprintf(STDOUT, "No active transactions on %s\n",
4051 as->parms[0].items->data);
4053 fprintf(STDOUT, "Total transactions: %d\n", count);
4055 for (i = 0; i < count; i++) {
4056 /*print out the relevant info */
4057 fprintf(STDOUT, "--------------------------------------\n");
4058 t = pntr->creationTime;
4059 fprintf(STDOUT, "transaction: %lu created: %s",
4060 (unsigned long)pntr->tid, ctime(&t));
4062 fprintf(STDOUT, "lastActiveTime: %s", ctime(&t));
4063 if (pntr->returnCode) {
4064 fprintf(STDOUT, "returnCode: %lu\n",
4065 (unsigned long)pntr->returnCode);
4068 fprintf(STDOUT, "attachFlags: ");
4069 if ((pntr->iflags & ITOffline) != 0) {
4070 fprintf(STDOUT, "offline ");
4072 if ((pntr->iflags & ITBusy) != 0) {
4073 fprintf(STDOUT, "busy ");
4075 if ((pntr->iflags & ITReadOnly) != 0) {
4076 fprintf(STDOUT, "readonly ");
4078 if ((pntr->iflags & ITCreate) != 0) {
4079 fprintf(STDOUT, "create ");
4081 if ((pntr->iflags & ITCreateVolID) != 0) {
4082 fprintf(STDOUT, "create volid ");
4084 fprintf(STDOUT, "\n");
4087 fprintf(STDOUT, "volumeStatus: ");
4088 if ((pntr->vflags & VTDeleteOnSalvage) != 0) {
4089 fprintf(STDOUT, "deleteOnSalvage ");
4091 if ((pntr->vflags & VTOutOfService) != 0) {
4092 fprintf(STDOUT, "outOfService ");
4094 if ((pntr->vflags & VTDeleted) != 0) {
4095 fprintf(STDOUT, "deleted ");
4097 fprintf(STDOUT, "\n");
4100 fprintf(STDOUT, "transactionFlags: ");
4101 fprintf(STDOUT, "delete\n");
4103 MapPartIdIntoName(pntr->partition, pname);
4104 fprintf(STDOUT, "volume: %lu partition: %s procedure: %s\n",
4105 (unsigned long)pntr->volid, pname, pntr->lastProcName);
4106 if (pntr->callValid) {
4107 t = pntr->lastReceiveTime;
4108 fprintf(STDOUT, "packetRead: %lu lastReceiveTime: %s",
4109 (unsigned long)pntr->readNext, ctime(&t));
4110 t = pntr->lastSendTime;
4111 fprintf(STDOUT, "packetSend: %lu lastSendTime: %s",
4112 (unsigned long)pntr->transmitNext, ctime(&t));
4115 fprintf(STDOUT, "--------------------------------------\n");
4116 fprintf(STDOUT, "\n");
4124 RenameVolume(struct cmd_syndesc *as, void *arock)
4127 struct nvldbentry entry;
4128 struct nvldbentry entry2;
4130 /* Get the entry of the volume to be renamed (-oldname), by name or id. */
4131 code = VLDB_GetEntryByName(as->parms[0].items->data, &entry);
4133 fprintf(STDERR, "vos: Could not find entry for volume %s\n",
4134 as->parms[0].items->data);
4135 PrintError("", code);
4140 * Verify the new name is available before attempting to rename.
4141 * Allow renaming of the same volume in order to complete a
4142 * previously interrupted rename.
4144 code = VLDB_GetEntryByName(as->parms[1].items->data, &entry2);
4145 if (code != 0 && code != VL_NOENT) {
4146 fprintf(STDERR, "vos: Could not check entry for volume %s\n",
4147 as->parms[1].items->data);
4148 PrintError("", code);
4151 if (code == 0 && entry.volumeId[RWVOL] != entry2.volumeId[RWVOL]) {
4152 fprintf(STDERR, "vos: Cannot rename volume %s (%lu) to %s;"
4153 " volume %s (%lu) already exists\n",
4154 as->parms[0].items->data,
4155 (unsigned long)entry.volumeId[RWVOL],
4156 as->parms[1].items->data,
4157 as->parms[1].items->data,
4158 (unsigned long)entry2.volumeId[RWVOL]);
4161 if (!VolNameOK(as->parms[0].items->data)) {
4163 "Illegal volume name %s, should not end in .readonly or .backup\n",
4164 as->parms[0].items->data);
4167 if (!ISNAMEVALID(as->parms[1].items->data)) {
4169 "vos: the new volume name %s exceeds the size limit of %d\n",
4170 as->parms[1].items->data, VOLSER_OLDMAXVOLNAME - 10);
4173 if (!VolNameOK(as->parms[1].items->data)) {
4175 "Illegal volume name %s, should not end in .readonly or .backup\n",
4176 as->parms[1].items->data);
4179 if (IsNumeric(as->parms[1].items->data)) {
4180 fprintf(STDERR, "Illegal volume name %s, should not be a number\n",
4181 as->parms[1].items->data);
4184 MapHostToNetwork(&entry);
4186 UV_RenameVolume(&entry, as->parms[0].items->data,
4187 as->parms[1].items->data);
4189 PrintDiagnostics("rename", code);
4192 fprintf(STDOUT, "Renamed volume %s to %s\n", as->parms[0].items->data,
4193 as->parms[1].items->data);
4198 GetVolumeInfo(afs_uint32 volid, afs_uint32 *server, afs_int32 *part, afs_int32 *voltype,
4199 struct nvldbentry *rentry)
4204 vcode = VLDB_GetEntryByID(volid, -1, rentry);
4207 "Could not fetch the entry for volume %lu from VLDB \n",
4208 (unsigned long)volid);
4209 PrintError("", vcode);
4212 MapHostToNetwork(rentry);
4213 if (volid == rentry->volumeId[ROVOL]) {
4215 for (i = 0; i < rentry->nServers; i++) {
4216 if ((index == -1) && (rentry->serverFlags[i] & VLSF_ROVOL)
4217 && !(rentry->serverFlags[i] & VLSF_DONTUSE))
4222 "RO volume is not found in VLDB entry for volume %lu\n",
4223 (unsigned long)volid);
4227 *server = rentry->serverNumber[index];
4228 *part = rentry->serverPartition[index];
4232 index = Lp_GetRwIndex(rentry);
4235 "RW Volume is not found in VLDB entry for volume %lu\n",
4236 (unsigned long)volid);
4239 if (volid == rentry->volumeId[RWVOL]) {
4241 *server = rentry->serverNumber[index];
4242 *part = rentry->serverPartition[index];
4245 if (volid == rentry->volumeId[BACKVOL]) {
4247 *server = rentry->serverNumber[index];
4248 *part = rentry->serverPartition[index];
4252 "unexpected volume type for volume %lu\n",
4253 (unsigned long)volid);
4258 DeleteEntry(struct cmd_syndesc *as, void *arock)
4260 afs_int32 apart = 0;
4263 struct VldbListByAttributes attributes;
4264 nbulkentries arrayEntries;
4265 struct nvldbentry *vllist;
4266 struct cmd_item *itp;
4269 char prefix[VOLSER_MAXVOLNAME + 1];
4271 afs_int32 totalBack = 0, totalFail = 0, err;
4273 if (as->parms[0].items) { /* -id */
4274 if (as->parms[1].items || as->parms[2].items || as->parms[3].items) {
4276 "You cannot use -server, -partition, or -prefix with the -id argument\n");
4279 for (itp = as->parms[0].items; itp; itp = itp->next) {
4280 avolid = vsu_GetVolumeID(itp->data, cstruct, &err);
4283 PrintError("", err);
4285 fprintf(STDERR, "vos: can't find volume '%s'\n",
4289 if (as->parms[4].items || as->parms[5].items) {
4290 /* -noexecute (hidden) or -dryrun */
4291 fprintf(STDOUT, "Would have deleted VLDB entry for %s \n",
4296 vcode = ubik_VL_DeleteEntry(cstruct, 0, avolid, RWVOL);
4298 fprintf(STDERR, "Could not delete entry for volume %s\n",
4301 "You must specify a RW volume name or ID "
4302 "(the entire VLDB entry will be deleted)\n");
4303 PrintError("", vcode);
4309 fprintf(STDOUT, "Deleted %d VLDB entries\n", totalBack);
4313 if (!as->parms[1].items && !as->parms[2].items && !as->parms[3].items) {
4314 fprintf(STDERR, "You must specify an option\n");
4318 /* Zero out search attributes */
4319 memset(&attributes, 0, sizeof(struct VldbListByAttributes));
4321 if (as->parms[1].items) { /* -prefix */
4322 strncpy(prefix, as->parms[1].items->data, VOLSER_MAXVOLNAME);
4324 if (!as->parms[2].items && !as->parms[3].items) { /* a single entry only */
4326 "You must provide -server with the -prefix argument\n");
4331 if (as->parms[2].items) { /* -server */
4333 aserver = GetServer(as->parms[2].items->data);
4335 fprintf(STDERR, "vos: server '%s' not found in host table\n",
4336 as->parms[2].items->data);
4339 attributes.server = ntohl(aserver);
4340 attributes.Mask |= VLLIST_SERVER;
4343 if (as->parms[3].items) { /* -partition */
4344 if (!as->parms[2].items) {
4346 "You must provide -server with the -partition argument\n");
4349 apart = volutil_GetPartitionID(as->parms[3].items->data);
4351 fprintf(STDERR, "vos: could not interpret partition name '%s'\n",
4352 as->parms[3].items->data);
4355 attributes.partition = apart;
4356 attributes.Mask |= VLLIST_PARTITION;
4359 /* Print status line of what we are doing */
4360 fprintf(STDOUT, "Deleting VLDB entries for ");
4361 if (as->parms[2].items) {
4362 fprintf(STDOUT, "server %s ", as->parms[2].items->data);
4364 if (as->parms[3].items) {
4366 MapPartIdIntoName(apart, pname);
4367 fprintf(STDOUT, "partition %s ", pname);
4370 fprintf(STDOUT, "which are prefixed with %s ", prefix);
4372 fprintf(STDOUT, "\n");
4375 /* Get all the VLDB entries on a server and/or partition */
4376 memset(&arrayEntries, 0, sizeof(arrayEntries));
4377 vcode = VLDB_ListAttributes(&attributes, &nentries, &arrayEntries);
4379 fprintf(STDERR, "Could not access the VLDB for attributes\n");
4380 PrintError("", vcode);
4384 /* Process each entry */
4385 for (j = 0; j < nentries; j++) {
4386 vllist = &arrayEntries.nbulkentries_val[j];
4388 /* It only deletes the RW volumes */
4389 if (strncmp(vllist->name, prefix, strlen(prefix))) {
4392 "Omitting to delete %s due to prefix %s mismatch\n",
4393 vllist->name, prefix);
4400 if (as->parms[4].items || as->parms[5].items) {
4401 /* -noexecute (hidden) or -dryrun */
4402 fprintf(STDOUT, "Would have deleted VLDB entry for %s \n",
4408 /* Only matches the RW volume name */
4409 avolid = vllist->volumeId[RWVOL];
4410 vcode = ubik_VL_DeleteEntry(cstruct, 0, avolid, RWVOL);
4412 fprintf(STDOUT, "Could not delete VLDB entry for %s\n",
4415 PrintError("", vcode);
4420 fprintf(STDOUT, "Deleted VLDB entry for %s \n", vllist->name);
4425 fprintf(STDOUT, "----------------------\n");
4427 "Total VLDB entries deleted: %lu; failed to delete: %lu\n",
4428 (unsigned long)totalBack, (unsigned long)totalFail);
4430 xdr_free((xdrproc_t) xdr_nbulkentries, &arrayEntries);
4435 CompareVldbEntryByName(const void *p1, const void *p2)
4437 struct nvldbentry *arg1, *arg2;
4439 arg1 = (struct nvldbentry *)p1;
4440 arg2 = (struct nvldbentry *)p2;
4441 return (strcmp(arg1->name, arg2->name));
4445 ListVLDB(struct cmd_syndesc *as, void *arock)
4450 struct VldbListByAttributes attributes;
4451 nbulkentries arrayEntries;
4452 struct nvldbentry *vllist, *tarray = 0, *ttarray;
4453 afs_int32 centries, nentries = 0;
4454 afs_int32 tarraysize = 0;
4455 afs_int32 parraysize;
4458 int quiet, sort, lock;
4459 afs_int32 thisindex, nextindex;
4463 memset(&attributes, 0, sizeof(attributes));
4464 lock = (as->parms[3].items ? 1 : 0); /* -lock flag */
4465 quiet = (as->parms[4].items ? 1 : 0); /* -quit flag */
4466 sort = (as->parms[5].items ? 0 : 1); /* -nosort flag */
4468 /* If the volume name is given, Use VolumeInfoCmd to look it up
4469 * and not ListAttributes.
4471 if (as->parms[0].items) {
4474 "vos: illegal use of '-locked' switch, need to specify server and/or partition\n");
4477 code = VolumeInfoCmd(as->parms[0].items->data);
4479 PrintError("", code);
4485 /* Server specified */
4486 if (as->parms[1].items) {
4489 aserver = GetServer(as->parms[1].items->data);
4491 fprintf(STDERR, "vos: server '%s' not found in host table\n",
4492 as->parms[1].items->data);
4495 attributes.server = ntohl(aserver);
4496 attributes.Mask |= VLLIST_SERVER;
4499 /* Partition specified */
4500 if (as->parms[2].items) {
4501 apart = volutil_GetPartitionID(as->parms[2].items->data);
4503 fprintf(STDERR, "vos: could not interpret partition name '%s'\n",
4504 as->parms[2].items->data);
4507 attributes.partition = apart;
4508 attributes.Mask |= VLLIST_PARTITION;
4512 attributes.Mask |= VLLIST_FLAG;
4513 attributes.flag = VLOP_ALLOPERS;
4516 /* Print header information */
4518 MapPartIdIntoName(apart, pname);
4519 fprintf(STDOUT, "VLDB entries for %s %s%s%s %s\n",
4520 (as->parms[1].items ? "server" : "all"),
4521 (as->parms[1].items ? as->parms[1].items->data : "servers"),
4522 (as->parms[2].items ? " partition " : ""),
4523 (as->parms[2].items ? pname : ""),
4524 (lock ? "which are locked:" : ""));
4527 for (thisindex = 0; (thisindex != -1); thisindex = nextindex) {
4528 memset(&arrayEntries, 0, sizeof(arrayEntries));
4533 VLDB_ListAttributesN2(&attributes, 0, thisindex, ¢ries,
4534 &arrayEntries, &nextindex);
4535 if (vcode == RXGEN_OPCODE) {
4536 /* Vlserver not running with ListAttributesN2. Fall back */
4538 VLDB_ListAttributes(&attributes, ¢ries, &arrayEntries);
4542 fprintf(STDERR, "Could not access the VLDB for attributes\n");
4543 PrintError("", vcode);
4546 nentries += centries;
4548 /* We don't sort, so just print the entries now */
4550 for (j = 0; j < centries; j++) { /* process each entry */
4551 vllist = &arrayEntries.nbulkentries_val[j];
4552 MapHostToNetwork(vllist);
4553 EnumerateEntry(vllist);
4555 PrintLocked(vllist->flags);
4559 /* So we sort. First we must collect all the entries and keep
4562 else if (centries > 0) {
4564 /* malloc the first bulk entries array */
4565 tarraysize = centries * sizeof(struct nvldbentry);
4566 tarray = malloc(tarraysize);
4569 "Could not allocate enough space for the VLDB entries\n");
4572 memcpy((char*)tarray, arrayEntries.nbulkentries_val, tarraysize);
4574 /* Grow the tarray to keep the extra entries */
4575 parraysize = (centries * sizeof(struct nvldbentry));
4576 ttarray = realloc(tarray, tarraysize + parraysize);
4579 "Could not allocate enough space for the VLDB entries\n");
4585 memcpy(((char *)tarray) + tarraysize,
4586 (char *)arrayEntries.nbulkentries_val, parraysize);
4587 tarraysize += parraysize;
4591 /* Free the bulk array */
4592 xdr_free((xdrproc_t) xdr_nbulkentries, &arrayEntries);
4595 /* Here is where we now sort all the entries and print them */
4596 if (sort && (nentries > 0)) {
4597 qsort((char *)tarray, nentries, sizeof(struct nvldbentry),
4598 CompareVldbEntryByName);
4599 for (vllist = tarray, j = 0; j < nentries; j++, vllist++) {
4600 MapHostToNetwork(vllist);
4601 EnumerateEntry(vllist);
4603 PrintLocked(vllist->flags);
4609 fprintf(STDOUT, "\nTotal entries: %lu\n", (unsigned long)nentries);
4616 BackSys(struct cmd_syndesc *as, void *arock)
4619 afs_int32 apart = 0;
4620 afs_uint32 aserver = 0, aserver1;
4621 afs_int32 code, apart1;
4623 struct VldbListByAttributes attributes;
4624 nbulkentries arrayEntries;
4625 struct nvldbentry *vllist;
4629 int seenprefix, seenxprefix, exclude, ex, exp, noaction;
4630 afs_int32 totalBack = 0;
4631 afs_int32 totalFail = 0;
4635 struct cmd_item *ti;
4637 #ifndef HAVE_POSIX_REGEX
4642 memset(&attributes, 0, sizeof(struct VldbListByAttributes));
4643 attributes.Mask = 0;
4645 seenprefix = (as->parms[0].items ? 1 : 0);
4646 exclude = (as->parms[3].items ? 1 : 0);
4647 seenxprefix = (as->parms[4].items ? 1 : 0);
4648 noaction = (as->parms[5].items ? 1 : 0);
4650 if (as->parms[1].items) { /* -server */
4651 aserver = GetServer(as->parms[1].items->data);
4653 fprintf(STDERR, "vos: server '%s' not found in host table\n",
4654 as->parms[1].items->data);
4657 attributes.server = ntohl(aserver);
4658 attributes.Mask |= VLLIST_SERVER;
4661 if (as->parms[2].items) { /* -partition */
4662 apart = volutil_GetPartitionID(as->parms[2].items->data);
4664 fprintf(STDERR, "vos: could not interpret partition name '%s'\n",
4665 as->parms[2].items->data);
4668 attributes.partition = apart;
4669 attributes.Mask |= VLLIST_PARTITION;
4672 /* Check to make sure the prefix and xprefix expressions compile ok */
4674 for (ti = as->parms[0].items; ti; ti = ti->next) {
4675 if (strncmp(ti->data, "^", 1) == 0) {
4676 #ifdef HAVE_POSIX_REGEX
4680 code = regcomp(&re, ti->data, REG_NOSUB);
4682 regerror(code, &re, errbuf, sizeof errbuf);
4684 "Unrecognizable -prefix regular expression: '%s': %s\n",
4690 ccode = (char *)re_comp(ti->data);
4693 "Unrecognizable -prefix regular expression: '%s': %s\n",
4702 for (ti = as->parms[4].items; ti; ti = ti->next) {
4703 if (strncmp(ti->data, "^", 1) == 0) {
4704 #ifdef HAVE_POSIX_REGEX
4708 code = regcomp(&re, ti->data, REG_NOSUB);
4710 regerror(code, &re, errbuf, sizeof errbuf);
4712 "Unrecognizable -xprefix regular expression: '%s': %s\n",
4718 ccode = (char *)re_comp(ti->data);
4721 "Unrecognizable -xprefix regular expression: '%s': %s\n",
4730 memset(&arrayEntries, 0, sizeof(arrayEntries)); /* initialize to hint the stub to alloc space */
4731 vcode = VLDB_ListAttributes(&attributes, &nentries, &arrayEntries);
4733 fprintf(STDERR, "Could not access the VLDB for attributes\n");
4734 PrintError("", vcode);
4738 if (as->parms[1].items || as->parms[2].items || verbose) {
4739 fprintf(STDOUT, "%s up volumes",
4740 (noaction ? "Would have backed" : "Backing"));
4742 if (as->parms[1].items) {
4743 fprintf(STDOUT, " on server %s", as->parms[1].items->data);
4744 } else if (as->parms[2].items) {
4745 fprintf(STDOUT, " for all servers");
4748 if (as->parms[2].items) {
4749 MapPartIdIntoName(apart, pname);
4750 fprintf(STDOUT, " partition %s", pname);
4753 if (seenprefix || (!seenprefix && seenxprefix)) {
4754 ti = (seenprefix ? as->parms[0].items : as->parms[4].items);
4755 ex = (seenprefix ? exclude : !exclude);
4756 exp = (strncmp(ti->data, "^", 1) == 0);
4757 fprintf(STDOUT, " which %smatch %s '%s'", (ex ? "do not " : ""),
4758 (exp ? "expression" : "prefix"), ti->data);
4759 for (ti = ti->next; ti; ti = ti->next) {
4760 exp = (strncmp(ti->data, "^", 1) == 0);
4761 printf(" %sor %s '%s'", (ex ? "n" : ""),
4762 (exp ? "expression" : "prefix"), ti->data);
4766 if (seenprefix && seenxprefix) {
4767 ti = as->parms[4].items;
4768 exp = (strncmp(ti->data, "^", 1) == 0);
4769 fprintf(STDOUT, " %swhich match %s '%s'",
4770 (exclude ? "adding those " : "removing those "),
4771 (exp ? "expression" : "prefix"), ti->data);
4772 for (ti = ti->next; ti; ti = ti->next) {
4773 exp = (strncmp(ti->data, "^", 1) == 0);
4774 printf(" or %s '%s'", (exp ? "expression" : "prefix"),
4778 fprintf(STDOUT, " .. ");
4780 fprintf(STDOUT, "\n");
4784 for (j = 0; j < nentries; j++) { /* process each vldb entry */
4785 vllist = &arrayEntries.nbulkentries_val[j];
4788 for (ti = as->parms[0].items; ti; ti = ti->next) {
4789 if (strncmp(ti->data, "^", 1) == 0) {
4790 #ifdef HAVE_POSIX_REGEX
4794 /* XXX -- should just do the compile once! */
4795 code = regcomp(&re, ti->data, REG_NOSUB);
4797 regerror(code, &re, errbuf, sizeof errbuf);
4799 "Error in -prefix regular expression: '%s': %s\n",
4803 match = (regexec(&re, vllist->name, 0, NULL, 0) == 0);
4806 ccode = (char *)re_comp(ti->data);
4809 "Error in -prefix regular expression: '%s': %s\n",
4813 match = (re_exec(vllist->name) == 1);
4817 (strncmp(vllist->name, ti->data, strlen(ti->data)) ==
4827 /* Without the -exclude flag: If it matches the prefix, then
4828 * check if we want to exclude any from xprefix.
4829 * With the -exclude flag: If it matches the prefix, then
4830 * check if we want to add any from xprefix.
4832 if (match && seenxprefix) {
4833 for (ti = as->parms[4].items; ti; ti = ti->next) {
4834 if (strncmp(ti->data, "^", 1) == 0) {
4835 #ifdef HAVE_POSIX_REGEX
4839 /* XXX -- should just do the compile once! */
4840 code = regcomp(&re, ti->data, REG_NOSUB);
4842 regerror(code, &re, errbuf, sizeof errbuf);
4844 "Error in -xprefix regular expression: '%s': %s\n",
4848 if (regexec(&re, vllist->name, 0, NULL, 0) == 0)
4852 ccode = (char *)re_comp(ti->data);
4855 "Error in -xprefix regular expression: '%s': %s\n",
4859 if (re_exec(vllist->name) == 1) {
4865 if (strncmp(vllist->name, ti->data, strlen(ti->data)) ==
4875 match = !match; /* -exclude will reverse the match */
4877 continue; /* Skip if no match */
4879 /* Print list of volumes to backup */
4881 fprintf(STDOUT, " %s\n", vllist->name);
4885 if (!(vllist->flags & VLF_RWEXISTS)) {
4888 "Omitting to backup %s since RW volume does not exist \n",
4890 fprintf(STDOUT, "\n");
4896 avolid = vllist->volumeId[RWVOL];
4897 MapHostToNetwork(vllist);
4898 found = GetServerAndPart(vllist, RWVOL, &aserver1, &apart1, &previdx);
4900 fprintf(STDOUT, "could not backup %s, invalid VLDB entry\n",
4906 same = VLDB_IsSameAddrs(aserver, aserver1, &error);
4909 "Failed to get info about server's %d address(es) from vlserver (err=%d); aborting call!\n",
4915 if ((aserver && !same) || (apart && (apart != apart1))) {
4918 "Omitting to backup %s since the RW is in a different location\n",
4924 time_t now = time(0);
4925 fprintf(STDOUT, "Creating backup volume for %s on %s",
4926 vllist->name, ctime(&now));
4930 code = UV_BackupVolume(aserver1, apart1, avolid);
4932 fprintf(STDOUT, "Could not backup %s\n", vllist->name);
4938 fprintf(STDOUT, "\n");
4940 } /* process each vldb entry */
4941 fprintf(STDOUT, "done\n");
4942 fprintf(STDOUT, "Total volumes backed up: %lu; failed to backup: %lu\n",
4943 (unsigned long)totalBack, (unsigned long)totalFail);
4945 xdr_free((xdrproc_t) xdr_nbulkentries, &arrayEntries);
4950 UnlockVLDB(struct cmd_syndesc *as, void *arock)
4953 afs_uint32 aserver = 0;
4956 struct VldbListByAttributes attributes;
4957 nbulkentries arrayEntries;
4958 struct nvldbentry *vllist;
4967 memset(&attributes, 0, sizeof(attributes));
4969 if (as->parms[0].items) { /* server specified */
4970 aserver = GetServer(as->parms[0].items->data);
4972 fprintf(STDERR, "vos: server '%s' not found in host table\n",
4973 as->parms[0].items->data);
4976 attributes.server = ntohl(aserver);
4977 attributes.Mask |= VLLIST_SERVER;
4979 if (as->parms[1].items) { /* partition specified */
4980 apart = volutil_GetPartitionID(as->parms[1].items->data);
4982 fprintf(STDERR, "vos: could not interpret partition name '%s'\n",
4983 as->parms[1].items->data);
4987 /* Check for validity of the partition if a server was given. */
4988 if (!IsPartValid(apart, aserver, &code)) {
4990 PrintError("", code);
4993 "vos : partition %s does not exist on the server\n",
4994 as->parms[1].items->data);
4998 attributes.partition = apart;
4999 attributes.Mask |= VLLIST_PARTITION;
5001 attributes.flag = VLOP_ALLOPERS;
5002 attributes.Mask |= VLLIST_FLAG;
5003 memset(&arrayEntries, 0, sizeof(arrayEntries)); /*initialize to hint the stub to alloc space */
5004 vcode = VLDB_ListAttributes(&attributes, &nentries, &arrayEntries);
5006 fprintf(STDERR, "Could not access the VLDB for attributes\n");
5007 PrintError("", vcode);
5010 for (j = 0; j < nentries; j++) { /* process each entry */
5011 vllist = &arrayEntries.nbulkentries_val[j];
5012 volid = vllist->volumeId[RWVOL];
5014 ubik_VL_ReleaseLock(cstruct, 0, volid, -1,
5015 LOCKREL_OPCODE | LOCKREL_AFSID |
5018 fprintf(STDERR, "Could not unlock entry for volume %s\n",
5020 PrintError("", vcode);
5025 MapPartIdIntoName(apart, pname);
5028 "Could not lock %lu VLDB entries of %lu locked entries\n",
5029 (unsigned long)totalE, (unsigned long)nentries);
5031 if (as->parms[0].items) {
5033 "Unlocked all the VLDB entries for volumes on server %s ",
5034 as->parms[0].items->data);
5035 if (as->parms[1].items) {
5036 MapPartIdIntoName(apart, pname);
5037 fprintf(STDOUT, "partition %s\n", pname);
5039 fprintf(STDOUT, "\n");
5041 } else if (as->parms[1].items) {
5042 MapPartIdIntoName(apart, pname);
5044 "Unlocked all the VLDB entries for volumes on partition %s on all servers\n",
5049 xdr_free((xdrproc_t) xdr_nbulkentries, &arrayEntries);
5054 PrintInt64Size(afs_uint64 in)
5058 static char output[16];
5060 SplitInt64(in,hi,lo);
5064 } else if (!(hi & 0xFFFFFC00)) {
5066 lo = (hi << 22) | (lo >> 10);
5067 } else if (!(hi & 0xFFF00000)) {
5069 lo = (hi << 12) | (lo >> 20);
5070 } else if (!(hi & 0xC0000000)) {
5072 lo = (hi << 2) | (lo >> 30);
5077 sprintf(output,"%u %s", lo, units);
5082 PartitionInfo(struct cmd_syndesc *as, void *arock)
5088 struct diskPartition64 partition;
5089 struct partList dummyPartList;
5091 int printSummary=0, sumPartitions=0;
5092 afs_uint64 sumFree, sumStorage;
5095 ZeroInt64(sumStorage);
5097 aserver = GetServer(as->parms[0].items->data);
5099 fprintf(STDERR, "vos: server '%s' not found in host table\n",
5100 as->parms[0].items->data);
5103 if (as->parms[1].items) {
5104 apart = volutil_GetPartitionID(as->parms[1].items->data);
5106 fprintf(STDERR, "vos: could not interpret partition name '%s'\n",
5107 as->parms[1].items->data);
5110 dummyPartList.partId[0] = apart;
5111 dummyPartList.partFlags[0] = PARTVALID;
5114 if (as->parms[2].items) {
5118 if (!IsPartValid(apart, aserver, &code)) { /*check for validity of the partition */
5120 PrintError("", code);
5123 "vos : partition %s does not exist on the server\n",
5124 as->parms[1].items->data);
5128 code = UV_ListPartitions(aserver, &dummyPartList, &cnt);
5130 PrintDiagnostics("listpart", code);
5134 for (i = 0; i < cnt; i++) {
5135 if (dummyPartList.partFlags[i] & PARTVALID) {
5136 MapPartIdIntoName(dummyPartList.partId[i], pname);
5137 code = UV_PartitionInfo64(aserver, pname, &partition);
5139 fprintf(STDERR, "Could not get information on partition %s\n",
5141 PrintError("", code);
5145 "Free space on partition %s: %" AFS_INT64_FMT " K blocks out of total %" AFS_INT64_FMT "\n",
5146 pname, partition.free, partition.minFree);
5148 AddUInt64(sumFree,partition.free,&sumFree);
5149 AddUInt64(sumStorage,partition.minFree,&sumStorage);
5154 "Summary: %s free out of ",
5155 PrintInt64Size(sumFree));
5157 "%s on %d partitions\n",
5158 PrintInt64Size(sumStorage),
5165 ChangeAddr(struct cmd_syndesc *as, void *arock)
5167 afs_int32 ip1, ip2, vcode;
5172 ip1 = GetServerNoresolve(as->parms[0].items->data);
5174 ip1 = GetServer(as->parms[0].items->data);
5176 fprintf(STDERR, "vos: invalid host address\n");
5180 if ((as->parms[1].items && as->parms[2].items)
5181 || (!as->parms[1].items && !as->parms[2].items)) {
5183 "vos: Must specify either '-newaddr <addr>' or '-remove' flag\n");
5187 if (as->parms[3].items) {
5191 if (as->parms[1].items) {
5193 ip2 = GetServerNoresolve(as->parms[1].items->data);
5195 ip2 = GetServer(as->parms[1].items->data);
5197 fprintf(STDERR, "vos: invalid host address\n");
5201 /* Play a trick here. If we are removing an address, ip1 will be -1
5202 * and ip2 will be the original address. This switch prevents an
5203 * older revision vlserver from removing the IP address.
5210 if (!remove && !force) {
5211 afs_int32 m_nentries;
5213 afs_int32 m_uniq = 0;
5215 ListAddrByAttributes m_attrs;
5216 struct uuid_fmtbuf buffer;
5218 memset(&m_attrs, 0, sizeof(m_attrs));
5219 memset(&m_uuid, 0, sizeof(m_uuid));
5220 memset(&m_addrs, 0, sizeof(m_addrs));
5222 m_attrs.Mask = VLADDR_IPADDR;
5223 m_attrs.ipaddr = ntohl(ip1); /* -oldaddr */
5226 ubik_VL_GetAddrsU(cstruct, UBIK_CALL_NEW, &m_attrs, &m_uuid,
5227 &m_uniq, &m_nentries, &m_addrs);
5228 xdr_free((xdrproc_t) xdr_bulkaddrs, &m_addrs);
5230 case 0: /* mh entry detected */
5231 afsUUID_to_string(&m_uuid, &buffer);
5232 fprintf(STDERR, "vos: Refusing to change address in multi-homed server entry.\n");
5233 fprintf(STDERR, " -oldaddr address is registered to file server UUID %s\n",
5235 fprintf(STDERR, " Please restart the file server or use vos setaddrs.\n");
5240 fprintf(STDERR, "vos: could not list the server addresses\n");
5241 PrintError("", vcode);
5246 vcode = ubik_VL_ChangeAddr(cstruct, UBIK_CALL_NEW, ntohl(ip1), ntohl(ip2));
5248 char hoststr1[16], hoststr2[16];
5250 afs_inet_ntoa_r(ip2, hoststr2);
5251 fprintf(STDERR, "Could not remove server %s from the VLDB\n",
5253 if (vcode == VL_NOENT) {
5255 "vlserver does not support the remove flag or ");
5258 afs_inet_ntoa_r(ip1, hoststr1);
5259 afs_inet_ntoa_r(ip2, hoststr2);
5260 fprintf(STDERR, "Could not change server %s to server %s\n",
5261 hoststr1, hoststr2);
5263 PrintError("", vcode);
5268 fprintf(STDOUT, "Removed server %s from the VLDB\n",
5269 as->parms[0].items->data);
5271 fprintf(STDOUT, "Changed server %s to server %s\n",
5272 as->parms[0].items->data, as->parms[1].items->data);
5278 print_addrs(const bulkaddrs * addrs, afsUUID * m_uuid, int nentries,
5283 struct uuid_fmtbuf buf;
5286 afsUUID_to_string(m_uuid, &buf);
5287 printf("UUID: %s\n", buf.buffer);
5290 /* print out the list of all the server */
5291 for (i = 0; i < addrs->bulkaddrs_len; i++) {
5292 addr = htonl(addrs->bulkaddrs_val[i]);
5295 printf("%s\n", afs_inet_ntoa_r(addr, hoststr));
5297 printf("%s\n", hostutil_GetNameByINet(addr));
5308 ListAddrs(struct cmd_syndesc *as, void *arock)
5310 afs_int32 vcode, m_uniq=0;
5311 afs_int32 i, printuuid = 0;
5312 struct VLCallBack vlcb;
5315 ListAddrByAttributes m_attrs;
5316 afsUUID m_uuid, askuuid;
5317 afs_int32 m_nentries;
5319 if (as->parms[0].items && as->parms[1].items) {
5320 fprintf(STDERR, "vos: Can't use the -uuid and -host flags together\n");
5324 memset(&m_attrs, 0, sizeof(struct ListAddrByAttributes));
5325 memset(&askuuid, 0, sizeof(afsUUID));
5326 if (as->parms[0].items) {
5328 if (afsUUID_from_string(as->parms[0].items->data, &askuuid) < 0) {
5329 fprintf(STDERR, "vos: invalid UUID '%s'\n",
5330 as->parms[0].items->data);
5333 m_attrs.Mask = VLADDR_UUID;
5334 m_attrs.uuid = askuuid;
5335 } else if (as->parms[1].items) {
5339 he = hostutil_GetHostByName((char *)as->parms[1].items->data);
5341 fprintf(STDERR, "vos: Can't get host info for '%s'\n",
5342 as->parms[1].items->data);
5345 memcpy(&saddr, he->h_addr, 4);
5346 m_attrs.Mask = VLADDR_IPADDR;
5347 m_attrs.ipaddr = ntohl(saddr);
5350 m_attrs.Mask = VLADDR_INDEX;
5353 if (as->parms[2].items) {
5357 memset(&m_addrs, 0, sizeof(bulkaddrs));
5358 memset(&vlcb, 0, sizeof(struct VLCallBack));
5361 ubik_VL_GetAddrs(cstruct, UBIK_CALL_NEW, 0, 0, &vlcb, &nentries,
5364 fprintf(STDERR, "vos: could not list the server addresses\n");
5365 PrintError("", vcode);
5369 for (i = 1, m_nentries = 0; nentries; i++) {
5372 xdr_free((xdrproc_t)xdr_bulkaddrs, &m_addrs); /* reset addr list */
5374 ubik_VL_GetAddrsU(cstruct, UBIK_CALL_NEW, &m_attrs, &m_uuid,
5375 &m_uniq, &m_nentries, &m_addrs);
5377 case 0: /* success */
5378 print_addrs(&m_addrs, &m_uuid, m_nentries, printuuid);
5383 if (m_attrs.Mask == VLADDR_UUID) {
5384 fprintf(STDERR, "vos: no entry for UUID '%s' found in VLDB\n",
5385 as->parms[0].items->data);
5387 } else if (m_attrs.Mask == VLADDR_IPADDR) {
5388 fprintf(STDERR, "vos: no entry for host '%s' [0x%08x] found in VLDB\n",
5389 as->parms[1].items->data, m_attrs.ipaddr);
5394 case VL_INDEXERANGE:
5395 vcode = 0; /* not an error, just means we're done */
5398 default: /* any other error */
5399 fprintf(STDERR, "vos: could not list the server addresses\n");
5400 PrintError("", vcode);
5404 /* if -uuid or -host, only list one response */
5405 if (as->parms[1].items || as->parms[0].items)
5410 xdr_free((xdrproc_t)xdr_bulkaddrs, &m_addrs);
5415 SetAddrs(struct cmd_syndesc *as, void *arock)
5420 afs_uint32 FS_HostAddrs_HBO[ADDRSPERSITE];
5422 memset(&m_addrs, 0, sizeof(bulkaddrs));
5423 memset(&askuuid, 0, sizeof(afsUUID));
5424 if (as->parms[0].items) {
5426 if (afsUUID_from_string(as->parms[0].items->data, &askuuid) < 0) {
5427 fprintf(STDERR, "vos: invalid UUID '%s'\n",
5428 as->parms[0].items->data);
5432 if (as->parms[1].items) {
5434 struct cmd_item *ti;
5438 for (ti = as->parms[1].items; ti && i < ADDRSPERSITE; ti = ti->next) {
5441 saddr = GetServerNoresolve(ti->data);
5443 saddr = GetServer(ti->data);
5446 fprintf(STDERR, "vos: Can't get host info for '%s'\n",
5450 /* Convert it to host byte order */
5451 FS_HostAddrs_HBO[i] = ntohl(saddr);
5454 m_addrs.bulkaddrs_len = i;
5455 m_addrs.bulkaddrs_val = FS_HostAddrs_HBO;
5458 vcode = ubik_VL_RegisterAddrs(cstruct, 0, &askuuid, 0, &m_addrs);
5461 if (vcode == VL_MULTIPADDR) {
5462 fprintf(STDERR, "vos: VL_RegisterAddrs rpc failed; The IP address exists on a different server; repair it\n");
5463 } else if (vcode == RXGEN_OPCODE) {
5464 fprintf(STDERR, "vlserver doesn't support VL_RegisterAddrs rpc; ignored\n");
5466 fprintf(STDERR, "vos: VL_RegisterAddrs rpc failed\n");
5468 PrintError("", vcode);
5472 fprintf(STDOUT, "vos: Changed UUID with addresses:\n");
5473 print_addrs(&m_addrs, &askuuid, m_addrs.bulkaddrs_len, 1);
5479 RemoveAddrs(struct cmd_syndesc *as, void *arock)
5482 ListAddrByAttributes attrs;
5485 afs_int32 nentries = 0;
5490 memset(&attrs, 0, sizeof(ListAddrByAttributes));
5491 memset(&addrs, 0, sizeof(bulkaddrs));
5492 memset(&uuid, 0, sizeof(afsUUID));
5493 attrs.Mask = VLADDR_UUID;
5495 if (as->parms[0].items) { /* -uuid */
5496 if (afsUUID_from_string(as->parms[0].items->data, &attrs.uuid) < 0) {
5497 fprintf(STDERR, "vos: invalid UUID '%s'\n",
5498 as->parms[0].items->data);
5504 ubik_VL_GetAddrsU(cstruct, UBIK_CALL_NEW, &attrs, &uuid, &uniq,
5506 if (code == VL_NOENT) {
5507 fprintf(STDERR, "vos: UUID not found\n");
5511 fprintf(STDERR, "vos: could not list the server addresses\n");
5512 PrintError("", code);
5515 if (addrs.bulkaddrs_len == 0) {
5516 fprintf(STDERR, "vos: no addresses found for UUID\n");
5520 ip2 = addrs.bulkaddrs_val[0]; /* network byte order */
5521 ip1 = 0xffffffff; /* indicates removal mode */
5524 printf("vos: Removing UUID with hosts:\n");
5525 print_addrs(&addrs, &uuid, nentries, 1);
5528 code = ubik_VL_ChangeAddr(cstruct, UBIK_CALL_NEW, ip1, ip2);
5530 fprintf(STDERR, "Could not remove server entry from the VLDB.\n");
5531 PrintError("", code);
5535 xdr_free((xdrproc_t) xdr_bulkaddrs, &addrs);
5540 LockEntry(struct cmd_syndesc *as, void *arock)
5543 afs_int32 vcode, err;
5545 avolid = vsu_GetVolumeID(as->parms[0].items->data, cstruct, &err);
5548 PrintError("", err);
5550 fprintf(STDERR, "vos: can't find volume '%s'\n",
5551 as->parms[0].items->data);
5554 vcode = ubik_VL_SetLock(cstruct, 0, avolid, -1, VLOP_DELETE);
5556 fprintf(STDERR, "Could not lock VLDB entry for volume %s\n",
5557 as->parms[0].items->data);
5558 PrintError("", vcode);
5561 fprintf(STDOUT, "Locked VLDB entry for volume %s\n",
5562 as->parms[0].items->data);
5567 ConvertRO(struct cmd_syndesc *as, void *arock)
5569 afs_int32 partition = -1;
5572 afs_int32 code, i, same;
5573 struct nvldbentry entry;
5575 afs_uint32 rwserver = 0;
5576 afs_int32 rwpartition = 0;
5577 afs_uint32 roserver = 0;
5578 afs_int32 ropartition = 0;
5582 server = GetServer(as->parms[0].items->data);
5584 fprintf(STDERR, "vos: host '%s' not found in host table\n",
5585 as->parms[0].items->data);
5588 partition = volutil_GetPartitionID(as->parms[1].items->data);
5589 if (partition < 0) {
5590 fprintf(STDERR, "vos: could not interpret partition name '%s'\n",
5591 as->parms[1].items->data);
5594 if (!IsPartValid(partition, server, &code)) {
5596 PrintError("", code);
5599 "vos : partition %s does not exist on the server\n",
5600 as->parms[1].items->data);
5603 volid = vsu_GetVolumeID(as->parms[2].items->data, cstruct, &code);
5606 PrintError("", code);
5608 fprintf(STDERR, "Unknown volume ID or name '%s'\n",
5609 as->parms[2].items->data);
5612 if (as->parms[3].items)
5615 memset(&entry, 0, sizeof(entry));
5616 vcode = VLDB_GetEntryByID(volid, -1, &entry);
5619 "Could not fetch the entry for volume %lu from VLDB\n",
5620 (unsigned long)volid);
5621 PrintError("convertROtoRW ", vcode);
5625 /* use RO volid even if user specified RW or BK volid */
5626 if (volid != entry.volumeId[ROVOL])
5627 volid = entry.volumeId[ROVOL];
5629 MapHostToNetwork(&entry);
5630 for (i = 0; i < entry.nServers; i++) {
5631 if (entry.serverFlags[i] & VLSF_RWVOL) {
5632 rwserver = entry.serverNumber[i];
5633 rwpartition = entry.serverPartition[i];
5636 } else if ((entry.serverFlags[i] & VLSF_ROVOL) && !roserver) {
5637 same = VLDB_IsSameAddrs(server, entry.serverNumber[i], &code);
5640 "Failed to get info about server's %d address(es) from vlserver (err=%d); aborting call!\n",
5645 roserver = entry.serverNumber[i];
5646 ropartition = entry.serverPartition[i];
5653 fprintf(STDERR, "Warning: RO volume didn't exist in vldb!\n");
5655 if (roserver && (ropartition != partition)) {
5657 "Warning: RO volume should be in partition %d instead of %d (vldb)\n",
5658 ropartition, partition);
5663 "VLDB indicates that a RW volume exists already on %s in partition %s.\n",
5664 hostutil_GetNameByINet(rwserver),
5665 volutil_PartitionName(rwpartition));
5667 fprintf(STDERR, "Overwrite this VLDB entry? [y|n] (n)\n");
5669 while (!(dc == EOF || dc == '\n'))
5670 dc = getchar(); /* goto end of line */
5671 if ((c != 'y') && (c != 'Y')) {
5672 fprintf(STDERR, "aborted.\n");
5678 code = UV_ConvertRO(server, partition, volid, &entry);
5684 Sizes(struct cmd_syndesc *as, void *arock)
5688 afs_int32 apart, voltype, fromdate = 0, code, err, i;
5689 struct nvldbentry entry;
5690 volintSize vol_size;
5692 rx_SetRxDeadTime(60 * 10);
5693 for (i = 0; i < MAXSERVERS; i++) {
5694 struct rx_connection *rxConn = ubik_GetRPCConn(cstruct, i);
5697 rx_SetConnDeadTime(rxConn, rx_connDeadTime);
5698 if (rx_ServiceOf(rxConn))
5699 rx_ServiceOf(rxConn)->connDeadTime = rx_connDeadTime;
5702 avolid = vsu_GetVolumeID(as->parms[0].items->data, cstruct, &err);
5705 PrintError("", err);
5707 fprintf(STDERR, "vos: can't find volume '%s'\n",
5708 as->parms[0].items->data);
5712 if (as->parms[1].items || as->parms[2].items) {
5713 if (!as->parms[1].items || !as->parms[2].items) {
5715 "Must specify both -server and -partition options\n");
5718 aserver = GetServer(as->parms[2].items->data);
5720 fprintf(STDERR, "Invalid server name\n");
5723 apart = volutil_GetPartitionID(as->parms[1].items->data);
5725 fprintf(STDERR, "Invalid partition name\n");
5729 code = GetVolumeInfo(avolid, &aserver, &apart, &voltype, &entry);
5736 if (as->parms[4].items && strcmp(as->parms[4].items->data, "0")) {
5737 code = ktime_DateToInt32(as->parms[4].items->data, &fromdate);
5739 fprintf(STDERR, "vos: failed to parse date '%s' (error=%d))\n",
5740 as->parms[4].items->data, code);
5745 fprintf(STDOUT, "Volume: %s\n", as->parms[0].items->data);
5747 if (as->parms[3].items) { /* do the dump estimate */
5748 vol_size.dump_size = 0;
5749 code = UV_GetSize(avolid, aserver, apart, fromdate, &vol_size);
5751 PrintDiagnostics("size", code);
5754 /* presumably the size info is now gathered in pntr */
5755 /* now we display it */
5757 fprintf(STDOUT, "dump_size: %llu\n", vol_size.dump_size);
5766 EndTrans(struct cmd_syndesc *as, void *arock)
5769 afs_int32 code, tid, rcode;
5770 struct rx_connection *aconn;
5772 server = GetServer(as->parms[0].items->data);
5774 fprintf(STDERR, "vos: host '%s' not found in host table\n",
5775 as->parms[0].items->data);
5779 code = util_GetInt32(as->parms[1].items->data, &tid);
5781 fprintf(STDERR, "vos: bad integer specified for transaction ID.\n");
5785 aconn = UV_Bind(server, AFSCONF_VOLUMEPORT);
5786 code = AFSVolEndTrans(aconn, tid, &rcode);
5792 PrintDiagnostics("endtrans", code);
5800 PrintDiagnostics(char *astring, afs_int32 acode)
5805 "You are not authorized to perform the 'vos %s' command (%d)\n",
5809 fprintf(STDERR, "Error in vos %s command.\n", astring);
5810 fprintf(STDERR, "Clone volume is not in the same partition as the read-write volume.\n");
5813 fprintf(STDERR, "Error in vos %s command.\n", astring);
5814 PrintError("", acode);
5822 win32_enableCrypt(void)
5829 /* Look up configuration parameters in Registry */
5830 code = RegOpenKeyEx(HKEY_LOCAL_MACHINE, AFSREG_CLT_SVC_PARAM_SUBKEY,
5831 0, (IsWow64()?KEY_WOW64_64KEY:0)|KEY_QUERY_VALUE, &parmKey);
5832 if (code != ERROR_SUCCESS) {
5833 dummyLen = sizeof(cryptall);
5834 RegQueryValueEx(parmKey, "SecurityLevel", NULL, NULL,
5835 (BYTE *) &cryptall, &dummyLen);
5837 RegCloseKey (parmKey);
5841 #endif /* AFS_NT40_ENV */
5844 MyBeforeProc(struct cmd_syndesc *as, void *arock)
5847 char *rxgk_seclevel_str = NULL;
5851 /* Initialize the ubik_client connection */
5852 rx_SetRxDeadTime(90);
5854 secFlags = AFSCONF_SECOPTS_FALLBACK_NULL;
5857 if (as->parms[COMMONPARM_OFFSET_CELL].items) /* if -cell specified */
5858 tcell = as->parms[COMMONPARM_OFFSET_CELL].items->data;
5860 if (as->parms[COMMONPARM_OFFSET_NOAUTH].items)
5861 secFlags |= AFSCONF_SECOPTS_NOAUTH;
5863 if (as->parms[COMMONPARM_OFFSET_LOCALAUTH].items) { /* -localauth specified */
5864 secFlags |= AFSCONF_SECOPTS_LOCALAUTH;
5865 confdir = AFSDIR_SERVER_ETC_DIRPATH;
5868 if (as->parms[COMMONPARM_OFFSET_ENCRYPT].items /* -encrypt specified */
5870 || win32_enableCrypt()
5871 #endif /* AFS_NT40_ENV */
5873 secFlags |= AFSCONF_SECOPTS_ALWAYSENCRYPT;
5875 if (as->parms[COMMONPARM_OFFSET_CONFIG].items) /* -config flag set */
5876 confdir = as->parms[COMMONPARM_OFFSET_CONFIG].items->data;
5878 if (cmd_OptionAsString(as, COMMONPARM_OFFSET_RXGK, &rxgk_seclevel_str) == 0) {
5879 if (strcmp(rxgk_seclevel_str, "clear") == 0)
5880 secFlags |= AFSCONF_SECOPTS_ALWAYSCLEAR;
5881 else if (strcmp(rxgk_seclevel_str, "auth") == 0)
5882 secFlags |= AFSCONF_SECOPTS_NEVERENCRYPT;
5883 else if (strcmp(rxgk_seclevel_str, "crypt") == 0) {
5884 /* don't need to set any flags; this is the default for rxgk */
5886 fprintf(STDERR, "Invalid argument to -rxgk: %s\n", rxgk_seclevel_str);
5889 secFlags |= AFSCONF_SECOPTS_RXGK;
5891 free(rxgk_seclevel_str);
5892 rxgk_seclevel_str = NULL;
5895 if ((code = vsu_ClientInit(confdir, tcell, secFlags, UV_SetSecurity,
5897 fprintf(STDERR, "could not initialize VLDB library (code=%lu) \n",
5898 (unsigned long)code);
5902 if (as->parms[COMMONPARM_OFFSET_VERBOSE].items) /* -verbose flag set */
5906 if (as->parms[COMMONPARM_OFFSET_NORESOLVE].items) /* -noresolve flag set */
5914 #include "AFS_component_version_number.c"
5917 main(int argc, char **argv)
5921 struct cmd_syndesc *ts;
5923 #ifdef AFS_AIX32_ENV
5925 * The following signal action for AIX is necessary so that in case of a
5926 * crash (i.e. core is generated) we can include the user's data section
5927 * in the core dump. Unfortunately, by default, only a partial core is
5928 * generated which, in many cases, isn't too useful.
5930 struct sigaction nsa;
5932 sigemptyset(&nsa.sa_mask);
5933 nsa.sa_handler = SIG_DFL;
5934 nsa.sa_flags = SA_FULLDUMP;
5935 sigaction(SIGSEGV, &nsa, NULL);
5938 confdir = AFSDIR_CLIENT_ETC_DIRPATH;
5940 cmd_SetBeforeProc(MyBeforeProc, NULL);
5942 ts = cmd_CreateSyntax("create", CreateVolume, NULL, 0, "create a new volume");
5943 cmd_AddParm(ts, "-server", CMD_SINGLE, 0, "machine name");
5944 cmd_AddParm(ts, "-partition", CMD_SINGLE, 0, "partition name");
5945 cmd_AddParm(ts, "-name", CMD_SINGLE, 0, "volume name");
5946 cmd_AddParm(ts, "-maxquota", CMD_SINGLE, CMD_OPTIONAL,
5947 "initial quota (KB)");
5948 cmd_AddParm(ts, "-id", CMD_SINGLE, CMD_OPTIONAL, "volume ID");
5949 cmd_AddParm(ts, "-roid", CMD_SINGLE, CMD_OPTIONAL, "readonly volume ID");
5952 ts = cmd_CreateSyntax("remove", DeleteVolume, NULL, 0, "delete a volume");
5953 cmd_AddParm(ts, "-server", CMD_SINGLE, CMD_OPTIONAL, "machine name");
5954 cmd_AddParm(ts, "-partition", CMD_SINGLE, CMD_OPTIONAL, "partition name");
5955 cmd_AddParm(ts, "-id", CMD_SINGLE, 0, "volume name or ID");
5959 ts = cmd_CreateSyntax("move", MoveVolume, NULL, 0, "move a volume");
5960 cmd_AddParm(ts, "-id", CMD_SINGLE, 0, "volume name or ID");
5961 cmd_AddParm(ts, "-fromserver", CMD_SINGLE, 0, "machine name on source");
5962 cmd_AddParm(ts, "-frompartition", CMD_SINGLE, 0,
5963 "partition name on source");
5964 cmd_AddParm(ts, "-toserver", CMD_SINGLE, 0,
5965 "machine name on destination");
5966 cmd_AddParm(ts, "-topartition", CMD_SINGLE, 0,
5967 "partition name on destination");
5968 cmd_AddParm(ts, "-live", CMD_FLAG, CMD_OPTIONAL,
5969 "copy live volume without cloning");
5972 ts = cmd_CreateSyntax("copy", CopyVolume, NULL, 0, "copy a volume");
5973 cmd_AddParm(ts, "-id", CMD_SINGLE, 0, "volume name or ID on source");
5974 cmd_AddParm(ts, "-fromserver", CMD_SINGLE, 0, "machine name on source");
5975 cmd_AddParm(ts, "-frompartition", CMD_SINGLE, 0,
5976 "partition name on source");
5977 cmd_AddParm(ts, "-toname", CMD_SINGLE, 0, "volume name on destination");
5978 cmd_AddParm(ts, "-toserver", CMD_SINGLE, 0,
5979 "machine name on destination");
5980 cmd_AddParm(ts, "-topartition", CMD_SINGLE, 0,
5981 "partition name on destination");
5982 cmd_AddParm(ts, "-offline", CMD_FLAG, CMD_OPTIONAL,
5983 "leave new volume offline");
5984 cmd_AddParm(ts, "-readonly", CMD_FLAG, CMD_OPTIONAL,
5985 "make new volume read-only");
5986 cmd_AddParm(ts, "-live", CMD_FLAG, CMD_OPTIONAL,
5987 "copy live volume without cloning");
5990 ts = cmd_CreateSyntax("shadow", ShadowVolume, NULL, 0,
5991 "make or update a shadow volume");
5992 cmd_AddParm(ts, "-id", CMD_SINGLE, 0, "volume name or ID on source");
5993 cmd_AddParm(ts, "-fromserver", CMD_SINGLE, 0, "machine name on source");
5994 cmd_AddParm(ts, "-frompartition", CMD_SINGLE, 0,
5995 "partition name on source");
5996 cmd_AddParm(ts, "-toserver", CMD_SINGLE, 0,
5997 "machine name on destination");
5998 cmd_AddParm(ts, "-topartition", CMD_SINGLE, 0,
5999 "partition name on destination");
6000 cmd_AddParm(ts, "-toname", CMD_SINGLE, CMD_OPTIONAL,
6001 "volume name on destination");
6002 cmd_AddParm(ts, "-toid", CMD_SINGLE, CMD_OPTIONAL,
6003 "volume ID on destination");
6004 cmd_AddParm(ts, "-offline", CMD_FLAG, CMD_OPTIONAL,
6005 "leave shadow volume offline");
6006 cmd_AddParm(ts, "-readonly", CMD_FLAG, CMD_OPTIONAL,
6007 "make shadow volume read-only");
6008 cmd_AddParm(ts, "-live", CMD_FLAG, CMD_OPTIONAL,
6009 "copy live volume without cloning");
6010 cmd_AddParm(ts, "-incremental", CMD_FLAG, CMD_OPTIONAL,
6011 "do incremental update if target exists");
6014 ts = cmd_CreateSyntax("backup", BackupVolume, NULL, 0,
6015 "make backup of a volume");
6016 cmd_AddParm(ts, "-id", CMD_SINGLE, 0, "volume name or ID");
6019 ts = cmd_CreateSyntax("clone", CloneVolume, NULL, 0,
6020 "make clone of a volume");
6021 cmd_AddParm(ts, "-id", CMD_SINGLE, 0, "volume name or ID");
6022 cmd_AddParm(ts, "-server", CMD_SINGLE, CMD_OPTIONAL, "server");
6023 cmd_AddParm(ts, "-partition", CMD_SINGLE, CMD_OPTIONAL, "partition");
6024 cmd_AddParm(ts, "-toname", CMD_SINGLE, CMD_OPTIONAL,
6025 "volume name on destination");
6026 cmd_AddParm(ts, "-toid", CMD_SINGLE, CMD_OPTIONAL,
6027 "volume ID on destination");
6028 cmd_AddParm(ts, "-offline", CMD_FLAG, CMD_OPTIONAL,
6029 "leave clone volume offline");
6030 cmd_AddParm(ts, "-readonly", CMD_FLAG, CMD_OPTIONAL,
6031 "make clone volume read-only, not readwrite");
6032 cmd_AddParm(ts, "-readwrite", CMD_FLAG, CMD_OPTIONAL,
6033 "make clone volume readwrite, not read-only");
6036 ts = cmd_CreateSyntax("release", ReleaseVolume, NULL, 0, "release a volume");
6037 cmd_AddParm(ts, "-id", CMD_SINGLE, 0, "volume name or ID");
6038 cmd_AddParm(ts, "-force", CMD_FLAG, CMD_OPTIONAL,
6039 "force a complete release and full dumps");
6040 cmd_AddParmAlias(ts, 1, "-f"); /* original force option */
6041 /* keep this reserved */
6042 cmd_AddParm(ts, "-stayonline", CMD_FLAG, CMD_OPTIONAL|CMD_HIDDEN,
6043 "release to cloned temp vol, then clone back to repsite RO");
6044 cmd_AddParm(ts, "-force-reclone", CMD_FLAG, CMD_OPTIONAL,
6045 "force a reclone and complete release with incremental dumps");
6048 ts = cmd_CreateSyntax("dump", DumpVolumeCmd, NULL, 0, "dump a volume");
6049 cmd_AddParm(ts, "-id", CMD_SINGLE, 0, "volume name or ID");
6050 cmd_AddParm(ts, "-time", CMD_SINGLE, CMD_OPTIONAL, "dump from time");
6051 cmd_AddParm(ts, "-file", CMD_SINGLE, CMD_OPTIONAL, "dump file");
6052 cmd_AddParm(ts, "-server", CMD_SINGLE, CMD_OPTIONAL, "server");
6053 cmd_AddParm(ts, "-partition", CMD_SINGLE, CMD_OPTIONAL, "partition");
6054 cmd_AddParm(ts, "-clone", CMD_FLAG, CMD_OPTIONAL,
6055 "dump a clone of the volume");
6056 cmd_AddParm(ts, "-omitdirs", CMD_FLAG, CMD_OPTIONAL,
6057 "omit unchanged directories from an incremental dump");
6060 ts = cmd_CreateSyntax("restore", RestoreVolumeCmd, NULL, 0,
6061 "restore a volume");
6062 cmd_AddParm(ts, "-server", CMD_SINGLE, 0, "machine name");
6063 cmd_AddParm(ts, "-partition", CMD_SINGLE, 0, "partition name");
6064 cmd_AddParm(ts, "-name", CMD_SINGLE, 0, "name of volume to be restored");
6065 cmd_AddParm(ts, "-file", CMD_SINGLE, CMD_OPTIONAL, "dump file");
6066 cmd_AddParm(ts, "-id", CMD_SINGLE, CMD_OPTIONAL, "volume ID");
6067 cmd_AddParm(ts, "-overwrite", CMD_SINGLE, CMD_OPTIONAL,
6068 "abort | full | incremental");
6069 cmd_AddParm(ts, "-offline", CMD_FLAG, CMD_OPTIONAL,
6070 "leave restored volume offline");
6071 cmd_AddParm(ts, "-readonly", CMD_FLAG, CMD_OPTIONAL,
6072 "make restored volume read-only");
6073 cmd_AddParm(ts, "-creation", CMD_SINGLE, CMD_OPTIONAL,
6074 "dump | keep | new");
6075 cmd_AddParm(ts, "-lastupdate", CMD_SINGLE, CMD_OPTIONAL,
6076 "dump | keep | new");
6077 cmd_AddParm(ts, "-nodelete", CMD_FLAG, CMD_OPTIONAL,
6078 "do not delete old site when restoring to a new site");
6081 ts = cmd_CreateSyntax("unlock", LockReleaseCmd, NULL, 0,
6082 "release lock on VLDB entry for a volume");
6083 cmd_AddParm(ts, "-id", CMD_SINGLE, 0, "volume name or ID");
6086 ts = cmd_CreateSyntax("changeloc", ChangeLocation, NULL, 0,
6087 "change an RW volume's location in the VLDB");
6088 cmd_AddParm(ts, "-server", CMD_SINGLE, 0,
6089 "machine name for new location");
6090 cmd_AddParm(ts, "-partition", CMD_SINGLE, 0,
6091 "partition name for new location");
6092 cmd_AddParm(ts, "-id", CMD_SINGLE, 0, "volume name or ID");
6095 ts = cmd_CreateSyntax("addsite", AddSite, NULL, 0, "add a replication site");
6096 cmd_AddParm(ts, "-server", CMD_SINGLE, 0, "machine name for new site");
6097 cmd_AddParm(ts, "-partition", CMD_SINGLE, 0,
6098 "partition name for new site");
6099 cmd_AddParm(ts, "-id", CMD_SINGLE, 0, "volume name or ID");
6100 cmd_AddParm(ts, "-roid", CMD_SINGLE, CMD_OPTIONAL, "volume name or ID for RO");
6101 cmd_AddParm(ts, "-valid", CMD_FLAG, CMD_OPTIONAL, "publish as an up-to-date site in VLDB");
6104 ts = cmd_CreateSyntax("remsite", RemoveSite, NULL, 0,
6105 "remove a replication site");
6106 cmd_AddParm(ts, "-server", CMD_SINGLE, 0, "machine name");
6107 cmd_AddParm(ts, "-partition", CMD_SINGLE, 0, "partition name");
6108 cmd_AddParm(ts, "-id", CMD_SINGLE, 0, "volume name or ID");
6111 ts = cmd_CreateSyntax("listpart", ListPartitions, NULL, 0, "list partitions");
6112 cmd_AddParm(ts, "-server", CMD_SINGLE, 0, "machine name");
6115 ts = cmd_CreateSyntax("listvol", ListVolumes, NULL, 0,
6116 "list volumes on server (bypass VLDB)");
6117 cmd_AddParm(ts, "-server", CMD_SINGLE, 0, "machine name");
6118 cmd_AddParm(ts, "-partition", CMD_SINGLE, CMD_OPTIONAL, "partition name");
6119 cmd_AddParm(ts, "-fast", CMD_FLAG, CMD_OPTIONAL, "minimal listing");
6120 cmd_AddParm(ts, "-long", CMD_FLAG, CMD_OPTIONAL,
6121 "list all normal volume fields");
6122 cmd_AddParm(ts, "-quiet", CMD_FLAG, CMD_OPTIONAL,
6123 "generate minimal information");
6124 cmd_AddParm(ts, "-extended", CMD_FLAG, CMD_OPTIONAL,
6125 "list extended volume fields");
6126 cmd_AddParm(ts, "-format", CMD_FLAG, CMD_OPTIONAL,
6127 "machine readable format");
6130 ts = cmd_CreateSyntax("syncvldb", SyncVldb, NULL, 0,
6131 "synchronize VLDB with server");
6132 cmd_AddParm(ts, "-server", CMD_SINGLE, CMD_OPTIONAL, "machine name");
6133 cmd_AddParm(ts, "-partition", CMD_SINGLE, CMD_OPTIONAL, "partition name");
6134 cmd_AddParm(ts, "-volume", CMD_SINGLE, CMD_OPTIONAL, "volume name or ID");
6135 cmd_AddParm(ts, "-dryrun", CMD_FLAG, CMD_OPTIONAL, "list what would be done, don't do it");
6138 ts = cmd_CreateSyntax("syncserv", SyncServer, NULL, 0,
6139 "synchronize server with VLDB");
6140 cmd_AddParm(ts, "-server", CMD_SINGLE, 0, "machine name");
6141 cmd_AddParm(ts, "-partition", CMD_SINGLE, CMD_OPTIONAL, "partition name");
6142 cmd_AddParm(ts, "-dryrun", CMD_FLAG, CMD_OPTIONAL, "list what would be done, don't do it");
6145 ts = cmd_CreateSyntax("examine", ExamineVolume, NULL, 0,
6146 "everything about the volume");
6147 cmd_AddParm(ts, "-id", CMD_SINGLE, 0, "volume name or ID");
6148 cmd_AddParm(ts, "-extended", CMD_FLAG, CMD_OPTIONAL,
6149 "list extended volume fields");
6150 cmd_AddParm(ts, "-format", CMD_FLAG, CMD_OPTIONAL,
6151 "machine readable format");
6153 cmd_CreateAlias(ts, "volinfo");
6154 cmd_CreateAlias(ts, "e");
6156 ts = cmd_CreateSyntax("setfields", SetFields, NULL, 0,
6157 "change volume info fields");
6158 cmd_AddParm(ts, "-id", CMD_SINGLE, 0, "volume name or ID");
6159 cmd_AddParm(ts, "-maxquota", CMD_SINGLE, CMD_OPTIONAL, "quota (KB)");
6160 cmd_AddParm(ts, "-clearuse", CMD_FLAG, CMD_OPTIONAL, "clear dayUse");
6161 cmd_AddParm(ts, "-clearVolUpCounter", CMD_FLAG, CMD_OPTIONAL, "clear volUpdateCounter");
6164 ts = cmd_CreateSyntax("offline", volOffline, NULL, 0, "force the volume status to offline");
6165 cmd_AddParm(ts, "-server", CMD_SINGLE, 0, "server name");
6166 cmd_AddParm(ts, "-partition", CMD_SINGLE, 0, "partition name");
6167 cmd_AddParm(ts, "-id", CMD_SINGLE, 0, "volume name or ID");
6168 cmd_AddParm(ts, "-sleep", CMD_SINGLE, CMD_OPTIONAL, "seconds to sleep");
6169 cmd_AddParm(ts, "-busy", CMD_FLAG, CMD_OPTIONAL, "busy volume");
6172 ts = cmd_CreateSyntax("online", volOnline, NULL, 0, "force the volume status to online");
6173 cmd_AddParm(ts, "-server", CMD_SINGLE, 0, "server name");
6174 cmd_AddParm(ts, "-partition", CMD_SINGLE, 0, "partition name");
6175 cmd_AddParm(ts, "-id", CMD_SINGLE, 0, "volume name or ID");
6178 ts = cmd_CreateSyntax("zap", VolumeZap, NULL, 0,
6179 "delete the volume, don't bother with VLDB");
6180 cmd_AddParm(ts, "-server", CMD_SINGLE, 0, "machine name");
6181 cmd_AddParm(ts, "-partition", CMD_SINGLE, 0, "partition name");
6182 cmd_AddParm(ts, "-id", CMD_SINGLE, 0, "volume ID");
6183 cmd_AddParm(ts, "-force", CMD_FLAG, CMD_OPTIONAL,
6184 "force deletion of bad volumes");
6185 cmd_AddParm(ts, "-backup", CMD_FLAG, CMD_OPTIONAL,
6186 "also delete backup volume if one is found");
6189 ts = cmd_CreateSyntax("status", VolserStatus, NULL, 0,
6190 "report on volser status");
6191 cmd_AddParm(ts, "-server", CMD_SINGLE, 0, "machine name");
6194 ts = cmd_CreateSyntax("rename", RenameVolume, NULL, 0, "rename a volume");
6195 cmd_AddParm(ts, "-oldname", CMD_SINGLE, 0, "old volume name ");
6196 cmd_AddParm(ts, "-newname", CMD_SINGLE, 0, "new volume name ");
6199 ts = cmd_CreateSyntax("listvldb", ListVLDB, NULL, 0,
6200 "list volumes in the VLDB");
6201 cmd_AddParm(ts, "-name", CMD_SINGLE, CMD_OPTIONAL, "volume name or ID");
6202 cmd_AddParm(ts, "-server", CMD_SINGLE, CMD_OPTIONAL, "machine name");
6203 cmd_AddParm(ts, "-partition", CMD_SINGLE, CMD_OPTIONAL, "partition name");
6204 cmd_AddParm(ts, "-locked", CMD_FLAG, CMD_OPTIONAL, "locked volumes only");
6205 cmd_AddParm(ts, "-quiet", CMD_FLAG, CMD_OPTIONAL,
6206 "generate minimal information");
6207 cmd_AddParm(ts, "-nosort", CMD_FLAG, CMD_OPTIONAL,
6208 "do not alphabetically sort the volume names");
6211 ts = cmd_CreateSyntax("backupsys", BackSys, NULL, 0, "en masse backups");
6212 cmd_AddParm(ts, "-prefix", CMD_LIST, CMD_OPTIONAL,
6213 "common prefix on volume(s)");
6214 cmd_AddParm(ts, "-server", CMD_SINGLE, CMD_OPTIONAL, "machine name");
6215 cmd_AddParm(ts, "-partition", CMD_SINGLE, CMD_OPTIONAL, "partition name");
6216 cmd_AddParm(ts, "-exclude", CMD_FLAG, CMD_OPTIONAL,
6217 "exclude common prefix volumes");
6218 cmd_AddParm(ts, "-xprefix", CMD_LIST, CMD_OPTIONAL,
6219 "negative prefix on volume(s)");
6220 cmd_AddParm(ts, "-dryrun", CMD_FLAG, CMD_OPTIONAL, "list what would be done, don't do it");
6223 ts = cmd_CreateSyntax("delentry", DeleteEntry, NULL, 0,
6224 "delete VLDB entry for a volume");
6225 cmd_AddParm(ts, "-id", CMD_LIST, CMD_OPTIONAL, "volume name or ID");
6226 cmd_AddParm(ts, "-prefix", CMD_SINGLE, CMD_OPTIONAL,
6227 "prefix of the volume whose VLDB entry is to be deleted");
6228 cmd_AddParm(ts, "-server", CMD_SINGLE, CMD_OPTIONAL, "machine name");
6229 cmd_AddParm(ts, "-partition", CMD_SINGLE, CMD_OPTIONAL, "partition name");
6230 cmd_AddParm(ts, "-noexecute", CMD_FLAG, CMD_OPTIONAL|CMD_HIDDEN, "");
6231 cmd_AddParm(ts, "-dryrun", CMD_FLAG, CMD_OPTIONAL,
6232 "list what would be done, don't do it");
6235 ts = cmd_CreateSyntax("partinfo", PartitionInfo, NULL, 0,
6236 "list partition information");
6237 cmd_AddParm(ts, "-server", CMD_SINGLE, 0, "machine name");
6238 cmd_AddParm(ts, "-partition", CMD_SINGLE, CMD_OPTIONAL, "partition name");
6239 cmd_AddParm(ts, "-summary", CMD_FLAG, CMD_OPTIONAL,
6240 "print storage summary");
6243 ts = cmd_CreateSyntax("unlockvldb", UnlockVLDB, NULL, 0,
6244 "unlock all the locked entries in the VLDB");
6245 cmd_AddParm(ts, "-server", CMD_SINGLE, CMD_OPTIONAL, "machine name");
6246 cmd_AddParm(ts, "-partition", CMD_SINGLE, CMD_OPTIONAL, "partition name");
6249 ts = cmd_CreateSyntax("lock", LockEntry, NULL, 0,
6250 "lock VLDB entry for a volume");
6251 cmd_AddParm(ts, "-id", CMD_SINGLE, 0, "volume name or ID");
6254 ts = cmd_CreateSyntax("changeaddr", ChangeAddr, NULL, 0,
6255 "change the IP address of a file server");
6256 cmd_AddParm(ts, "-oldaddr", CMD_SINGLE, 0, "original IP address");
6257 cmd_AddParm(ts, "-newaddr", CMD_SINGLE, CMD_OPTIONAL, "new IP address");
6258 cmd_AddParm(ts, "-remove", CMD_FLAG, CMD_OPTIONAL,
6259 "remove the IP address from the VLDB");
6260 cmd_AddParm(ts, "-force", CMD_FLAG, CMD_OPTIONAL,
6261 "allow multi-homed server entry change (not recommended)");
6264 ts = cmd_CreateSyntax("listaddrs", ListAddrs, NULL, 0,
6265 "list the IP address of all file servers registered in the VLDB");
6266 cmd_AddParm(ts, "-uuid", CMD_SINGLE, CMD_OPTIONAL, "uuid of server");
6267 cmd_AddParm(ts, "-host", CMD_SINGLE, CMD_OPTIONAL, "address of host");
6268 cmd_AddParm(ts, "-printuuid", CMD_FLAG, CMD_OPTIONAL,
6269 "print uuid of hosts");
6272 ts = cmd_CreateSyntax("convertROtoRW", ConvertRO, NULL, 0,
6273 "convert a RO volume into a RW volume (after loss of old RW volume)");
6274 cmd_AddParm(ts, "-server", CMD_SINGLE, 0, "machine name");
6275 cmd_AddParm(ts, "-partition", CMD_SINGLE, 0, "partition name");
6276 cmd_AddParm(ts, "-id", CMD_SINGLE, 0, "volume name or ID");
6277 cmd_AddParm(ts, "-force", CMD_FLAG, CMD_OPTIONAL, "don't ask");
6280 ts = cmd_CreateSyntax("size", Sizes, NULL, 0,
6281 "obtain various sizes of the volume.");
6282 cmd_AddParm(ts, "-id", CMD_SINGLE, 0, "volume name or ID");
6283 cmd_AddParm(ts, "-partition", CMD_SINGLE, CMD_OPTIONAL, "partition name");
6284 cmd_AddParm(ts, "-server", CMD_SINGLE, CMD_OPTIONAL, "machine name");
6285 cmd_AddParm(ts, "-dump", CMD_FLAG, CMD_OPTIONAL,
6286 "Obtain the size of the dump");
6287 cmd_AddParm(ts, "-time", CMD_SINGLE, CMD_OPTIONAL, "dump from time");
6290 ts = cmd_CreateSyntax("endtrans", EndTrans, NULL, 0,
6291 "end a volserver transaction");
6292 cmd_AddParm(ts, "-server", CMD_SINGLE, 0, "machine name");
6293 cmd_AddParm(ts, "-transaction", CMD_SINGLE, 0,
6297 ts = cmd_CreateSyntax("setaddrs", SetAddrs, NULL, 0,
6298 "set the list of IP addresses for a given UUID in the VLDB");
6299 cmd_AddParm(ts, "-uuid", CMD_SINGLE, 0, "uuid of server");
6300 cmd_AddParm(ts, "-host", CMD_LIST, 0, "address of host");
6303 ts = cmd_CreateSyntax("remaddrs", RemoveAddrs, NULL, 0,
6304 "remove the list of IP addresses for a given UUID in the VLDB");
6305 cmd_AddParm(ts, "-uuid", CMD_SINGLE, 0, "uuid of server");
6308 code = cmd_Dispatch(argc, argv);
6310 /* Shut down the ubik_client and rx connections */
6312 (void)ubik_ClientDestroy(cstruct);
6318 exit((code ? -1 : 0));