2 * Copyright 2000, International Business Machines Corporation and others.
5 * This software has been released under the terms of the IBM Public
6 * License. For details, see the LICENSE file in the top-level source
7 * directory or online at http://www.openafs.org/dl/license10.html
10 #include <afsconfig.h>
11 #include <afs/param.h>
15 #ifdef IGNORE_SOME_GCC_WARNINGS
16 # pragma GCC diagnostic warning "-Wimplicit-function-declaration"
20 #include <WINNT/afsreg.h>
24 #include <sys/statfs.h>
29 #include <rx/rx_queue.h>
32 #include <rx/rx_globals.h>
34 #include <afs/vlserver.h>
35 #include <afs/cellconfig.h>
37 #include <afs/afsutil.h>
39 #include <afs/afsint.h>
44 #include <afs/ihandle.h>
45 #include <afs/vnode.h>
46 #include <afs/volume.h>
47 #include <afs/com_err.h>
51 #include "volser_internal.h"
52 #include "volser_prototypes.h"
53 #include "vsutils_prototypes.h"
54 #include "lockprocs_prototypes.h"
56 #ifdef HAVE_POSIX_REGEX
60 /* Local Prototypes */
61 int PrintDiagnostics(char *astring, afs_int32 acode);
62 int GetVolumeInfo(afs_uint32 volid, afs_uint32 *server, afs_int32 *part,
63 afs_int32 *voltype, struct nvldbentry *rentry);
76 COMMONPARM_OFFSET_CELL = 25,
77 COMMONPARM_OFFSET_NOAUTH = 26,
78 COMMONPARM_OFFSET_LOCALAUTH = 27,
79 COMMONPARM_OFFSET_VERBOSE = 28,
80 COMMONPARM_OFFSET_ENCRYPT = 29,
81 COMMONPARM_OFFSET_NORESOLVE = 30,
82 COMMONPARM_OFFSET_CONFIG = 31,
86 cmd_AddParmAtOffset(ts, COMMONPARM_OFFSET_CELL, \
87 "-cell", CMD_SINGLE, CMD_OPTIONAL, "cell name");\
88 cmd_AddParmAlias(ts, COMMONPARM_OFFSET_CELL, "-c"); /* original -cell option */ \
89 cmd_AddParmAtOffset(ts, COMMONPARM_OFFSET_NOAUTH, \
90 "-noauth", CMD_FLAG, CMD_OPTIONAL, "don't authenticate");\
91 cmd_AddParmAtOffset(ts, COMMONPARM_OFFSET_LOCALAUTH, \
92 "-localauth",CMD_FLAG,CMD_OPTIONAL,"use server tickets");\
93 cmd_AddParmAtOffset(ts, COMMONPARM_OFFSET_VERBOSE, \
94 "-verbose", CMD_FLAG, CMD_OPTIONAL, "verbose");\
95 cmd_AddParmAtOffset(ts, COMMONPARM_OFFSET_ENCRYPT, \
96 "-encrypt", CMD_FLAG, CMD_OPTIONAL, "encrypt commands");\
97 cmd_AddParmAtOffset(ts, COMMONPARM_OFFSET_NORESOLVE, \
98 "-noresolve", CMD_FLAG, CMD_OPTIONAL, "don't resolve addresses"); \
99 cmd_AddParmAtOffset(ts, COMMONPARM_OFFSET_CONFIG, \
100 "-config", CMD_SINGLE, CMD_OPTIONAL, "config location"); \
102 #define ERROR_EXIT(code) do { \
108 extern struct ubik_client *cstruct;
111 static struct tqHead busyHead, notokHead;
114 qInit(struct tqHead *ahead)
116 memset(ahead, 0, sizeof(struct tqHead));
122 qPut(struct tqHead *ahead, afs_uint32 volid)
126 elem = malloc(sizeof(struct tqElem));
127 elem->next = ahead->next;
135 qGet(struct tqHead *ahead, afs_uint32 *volid)
139 if (ahead->count <= 0)
141 *volid = ahead->next->volid;
143 ahead->next = tmp->next;
149 /* returns 1 if <filename> exists else 0 */
151 FileExists(char *filename)
157 code = usd_Open(filename, USD_OPEN_RDONLY, 0, &ufd);
161 code = USD_IOCTL(ufd, USD_IOCTL_GETSIZE, &size);
169 /* returns 1 if <name> doesnot end in .readonly or .backup, else 0 */
171 VolNameOK(char *name)
176 total = strlen(name);
177 if (!strcmp(&name[total - 9], ".readonly")) {
179 } else if (!strcmp(&name[total - 7], ".backup")) {
186 /* return 1 if name is a number else 0 */
188 IsNumeric(char *name)
197 for (i = 0; i < len; i++) {
198 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 GetVolumeType(char *aname)
290 if (!strcmp(aname, "ro"))
292 else if (!strcmp(aname, "rw"))
294 else if (!strcmp(aname, "bk"))
301 IsPartValid(afs_int32 partId, afs_uint32 server, afs_int32 *code)
303 struct partList dummyPartList;
309 *code = UV_ListPartitions(server, &dummyPartList, &cnt);
312 for (i = 0; i < cnt; i++) {
313 if (dummyPartList.partFlags[i] & PARTVALID)
314 if (dummyPartList.partId[i] == partId)
322 /*sends the contents of file associated with <fd> and <blksize> to Rx Stream
323 * associated with <call> */
325 SendFile(usd_handle_t ufd, struct rx_call *call, long blksize)
327 char *buffer = (char *)0;
331 buffer = malloc(blksize);
333 fprintf(STDERR, "malloc failed\n");
338 #if !defined(AFS_NT40_ENV) && !defined(AFS_PTHREAD_ENV)
339 /* Only for this for non-NT, non-pthread. For NT, we can't select on
340 * non-socket FDs. For pthread environments, we don't need to select at
341 * all, since the following read() will block. */
344 FD_SET((intptr_t)(ufd->handle), &in);
345 /* don't timeout if read blocks */
346 IOMGR_Select(((intptr_t)(ufd->handle)) + 1, &in, 0, 0, 0);
348 error = USD_READ(ufd, buffer, blksize, &nbytes);
350 fprintf(STDERR, "File system read failed: %s\n",
351 afs_error_message(error));
358 if (rx_Write(call, buffer, nbytes) != nbytes) {
368 /* function invoked by UV_RestoreVolume, reads the data from rx_trx_stream and
369 * writes it out to the volume. */
371 WriteData(struct rx_call *call, void *rock)
373 char *filename = (char *) rock;
376 afs_int32 error, code;
378 afs_int64 currOffset;
384 if (!filename || !*filename) {
385 usd_StandardInput(&ufd);
389 code = usd_Open(filename, USD_OPEN_RDONLY, 0, &ufd);
392 code = USD_IOCTL(ufd, USD_IOCTL_GETBLKSIZE, &blksize);
395 fprintf(STDERR, "Could not access file '%s': %s\n", filename,
396 afs_error_message(code));
400 /* test if we have a valid dump */
401 USD_SEEK(ufd, 0, SEEK_END, &currOffset);
402 USD_SEEK(ufd, currOffset - sizeof(afs_uint32), SEEK_SET, &currOffset);
403 USD_READ(ufd, (char *)&buffer, sizeof(afs_uint32), &got);
404 if ((got != sizeof(afs_uint32)) || (ntohl(buffer) != DUMPENDMAGIC)) {
405 fprintf(STDERR, "Signature missing from end of file '%s'\n", filename);
409 USD_SEEK(ufd, 0, SEEK_SET, &currOffset);
411 code = SendFile(ufd, call, blksize);
418 code = USD_CLOSE(ufd);
420 fprintf(STDERR, "Could not close dump file %s\n",
421 (filename && *filename) ? filename : "STDOUT");
429 /* Receive data from <call> stream into file associated
430 * with <fd> <blksize>
433 ReceiveFile(usd_handle_t ufd, struct rx_call *call, long blksize)
437 afs_uint32 bytesleft, w;
440 buffer = malloc(blksize);
442 fprintf(STDERR, "memory allocation failed\n");
446 while ((bytesread = rx_Read(call, buffer, blksize)) > 0) {
447 for (bytesleft = bytesread; bytesleft; bytesleft -= w) {
448 #if !defined(AFS_NT40_ENV) && !defined(AFS_PTHREAD_ENV)
449 /* Only for this for non-NT, non-pthread. For NT, we can't select
450 * on non-socket FDs. For pthread environments, we don't need to
451 * select at all, since the following write() will block. */
454 FD_SET((intptr_t)(ufd->handle), &out);
455 /* don't timeout if write blocks */
456 IOMGR_Select(((intptr_t)(ufd->handle)) + 1, 0, &out, 0, 0);
459 USD_WRITE(ufd, &buffer[bytesread - bytesleft], bytesleft, &w);
461 fprintf(STDERR, "File system write failed: %s\n",
462 afs_error_message(error));
475 DumpFunction(struct rx_call *call, void *rock)
477 char *filename = (char *)rock;
478 usd_handle_t ufd; /* default is to stdout */
479 afs_int32 error = 0, code;
484 /* Open the output file */
485 if (!filename || !*filename) {
486 usd_StandardOutput(&ufd);
491 usd_Open(filename, USD_OPEN_CREATE | USD_OPEN_RDWR, 0666, &ufd);
495 code = USD_IOCTL(ufd, USD_IOCTL_SETSIZE, &size);
498 code = USD_IOCTL(ufd, USD_IOCTL_GETBLKSIZE, &blksize);
501 fprintf(STDERR, "Could not create file '%s': %s\n", filename,
502 afs_error_message(code));
503 ERROR_EXIT(VOLSERBADOP);
507 code = ReceiveFile(ufd, call, blksize);
512 /* Close the output file */
514 code = USD_CLOSE(ufd);
516 fprintf(STDERR, "Could not close dump file %s\n",
517 (filename && *filename) ? filename : "STDIN");
527 DisplayFormat(volintInfo *pntr, afs_uint32 server, afs_int32 part,
528 int *totalOK, int *totalNotOK, int *totalBusy, int fast,
529 int longlist, int disp)
535 fprintf(STDOUT, "%-10lu\n", (unsigned long)pntr->volid);
536 } else if (longlist) {
537 if (pntr->status == VOK) {
538 fprintf(STDOUT, "%-32s ", pntr->name);
539 fprintf(STDOUT, "%10lu ", (unsigned long)pntr->volid);
541 fprintf(STDOUT, "RW ");
543 fprintf(STDOUT, "RO ");
545 fprintf(STDOUT, "BK ");
546 fprintf(STDOUT, "%10d K ", pntr->size);
547 if (pntr->inUse == 1) {
548 fprintf(STDOUT, "On-line");
551 fprintf(STDOUT, "Off-line");
554 if (pntr->needsSalvaged == 1)
555 fprintf(STDOUT, "**needs salvage**");
556 fprintf(STDOUT, "\n");
557 MapPartIdIntoName(part, pname);
558 fprintf(STDOUT, " %s %s \n", hostutil_GetNameByINet(server),
560 fprintf(STDOUT, " RWrite %10lu ROnly %10lu Backup %10lu \n",
561 (unsigned long)pntr->parentID,
562 (unsigned long)pntr->cloneID,
563 (unsigned long)pntr->backupID);
564 fprintf(STDOUT, " MaxQuota %10d K \n", pntr->maxquota);
565 t = pntr->creationDate;
566 fprintf(STDOUT, " Creation %s",
569 fprintf(STDOUT, " Copy %s",
572 t = pntr->backupDate;
574 fprintf(STDOUT, " Backup Never\n");
576 fprintf(STDOUT, " Backup %s",
579 t = pntr->accessDate;
581 fprintf(STDOUT, " Last Access %s",
584 t = pntr->updateDate;
586 fprintf(STDOUT, " Last Update Never\n");
588 fprintf(STDOUT, " Last Update %s",
591 " %d accesses in the past day (i.e., vnode references)\n",
593 } else if (pntr->status == VBUSY) {
595 qPut(&busyHead, pntr->volid);
597 fprintf(STDOUT, "**** Volume %lu is busy ****\n",
598 (unsigned long)pntr->volid);
601 qPut(¬okHead, pntr->volid);
603 fprintf(STDOUT, "**** Could not attach volume %lu ****\n",
604 (unsigned long)pntr->volid);
606 fprintf(STDOUT, "\n");
607 } else { /* default listing */
608 if (pntr->status == VOK) {
609 fprintf(STDOUT, "%-32s ", pntr->name);
610 fprintf(STDOUT, "%10lu ", (unsigned long)pntr->volid);
612 fprintf(STDOUT, "RW ");
614 fprintf(STDOUT, "RO ");
616 fprintf(STDOUT, "BK ");
617 fprintf(STDOUT, "%10d K ", pntr->size);
618 if (pntr->inUse == 1) {
619 fprintf(STDOUT, "On-line");
622 fprintf(STDOUT, "Off-line");
625 if (pntr->needsSalvaged == 1)
626 fprintf(STDOUT, "**needs salvage**");
627 fprintf(STDOUT, "\n");
628 } else if (pntr->status == VBUSY) {
630 qPut(&busyHead, pntr->volid);
632 fprintf(STDOUT, "**** Volume %lu is busy ****\n",
633 (unsigned long)pntr->volid);
636 qPut(¬okHead, pntr->volid);
638 fprintf(STDOUT, "**** Could not attach volume %lu ****\n",
639 (unsigned long)pntr->volid);
644 /*------------------------------------------------------------------------
645 * PRIVATE XDisplayFormat
648 * Display the contents of one extended volume info structure.
651 * a_xInfoP : Ptr to extended volume info struct to print.
652 * a_servID : Server ID to print.
653 * a_partID : Partition ID to print.
654 * a_totalOKP : Ptr to total-OK counter.
655 * a_totalNotOKP : Ptr to total-screwed counter.
656 * a_totalBusyP : Ptr to total-busy counter.
657 * a_fast : Fast listing?
658 * a_int32 : Int32 listing?
659 * a_showProblems : Show volume problems?
665 * Nothing interesting.
669 *------------------------------------------------------------------------*/
672 XDisplayFormat(volintXInfo *a_xInfoP, afs_uint32 a_servID, afs_int32 a_partID,
673 int *a_totalOKP, int *a_totalNotOKP, int *a_totalBusyP,
674 int a_fast, int a_int32, int a_showProblems)
675 { /*XDisplayFormat */
683 fprintf(STDOUT, "%-10lu\n", (unsigned long)a_xInfoP->volid);
684 } else if (a_int32) {
686 * Fully-detailed listing.
688 if (a_xInfoP->status == VOK) {
690 * Volume's status is OK - all the fields are valid.
692 fprintf(STDOUT, "%-32s ", a_xInfoP->name);
693 fprintf(STDOUT, "%10lu ", (unsigned long)a_xInfoP->volid);
694 if (a_xInfoP->type == 0)
695 fprintf(STDOUT, "RW ");
696 if (a_xInfoP->type == 1)
697 fprintf(STDOUT, "RO ");
698 if (a_xInfoP->type == 2)
699 fprintf(STDOUT, "BK ");
700 fprintf(STDOUT, "%10d K used ", a_xInfoP->size);
701 fprintf(STDOUT, "%d files ", a_xInfoP->filecount);
702 if (a_xInfoP->inUse == 1) {
703 fprintf(STDOUT, "On-line");
706 fprintf(STDOUT, "Off-line");
709 fprintf(STDOUT, "\n");
710 MapPartIdIntoName(a_partID, pname);
711 fprintf(STDOUT, " %s %s \n", hostutil_GetNameByINet(a_servID),
713 fprintf(STDOUT, " RWrite %10lu ROnly %10lu Backup %10lu \n",
714 (unsigned long)a_xInfoP->parentID,
715 (unsigned long)a_xInfoP->cloneID,
716 (unsigned long)a_xInfoP->backupID);
717 fprintf(STDOUT, " MaxQuota %10d K \n", a_xInfoP->maxquota);
719 t = a_xInfoP->creationDate;
720 fprintf(STDOUT, " Creation %s",
723 t = a_xInfoP->copyDate;
724 fprintf(STDOUT, " Copy %s",
727 t = a_xInfoP->backupDate;
729 fprintf(STDOUT, " Backup Never\n");
731 fprintf(STDOUT, " Backup %s",
734 t = a_xInfoP->accessDate;
736 fprintf(STDOUT, " Last Access %s",
739 t = a_xInfoP->updateDate;
741 fprintf(STDOUT, " Last Update Never\n");
743 fprintf(STDOUT, " Last Update %s",
746 " %d accesses in the past day (i.e., vnode references)\n",
750 * Print all the read/write and authorship stats.
752 fprintf(STDOUT, "\n Raw Read/Write Stats\n");
754 " |-------------------------------------------|\n");
756 " | Same Network | Diff Network |\n");
758 " |----------|----------|----------|----------|\n");
760 " | Total | Auth | Total | Auth |\n");
762 " |----------|----------|----------|----------|\n");
763 fprintf(STDOUT, "Reads | %8d | %8d | %8d | %8d |\n",
764 a_xInfoP->stat_reads[VOLINT_STATS_SAME_NET],
765 a_xInfoP->stat_reads[VOLINT_STATS_SAME_NET_AUTH],
766 a_xInfoP->stat_reads[VOLINT_STATS_DIFF_NET],
767 a_xInfoP->stat_reads[VOLINT_STATS_DIFF_NET_AUTH]);
768 fprintf(STDOUT, "Writes | %8d | %8d | %8d | %8d |\n",
769 a_xInfoP->stat_writes[VOLINT_STATS_SAME_NET],
770 a_xInfoP->stat_writes[VOLINT_STATS_SAME_NET_AUTH],
771 a_xInfoP->stat_writes[VOLINT_STATS_DIFF_NET],
772 a_xInfoP->stat_writes[VOLINT_STATS_DIFF_NET_AUTH]);
774 " |-------------------------------------------|\n\n");
777 " Writes Affecting Authorship\n");
779 " |-------------------------------------------|\n");
781 " | File Authorship | Directory Authorship|\n");
783 " |----------|----------|----------|----------|\n");
785 " | Same | Diff | Same | Diff |\n");
787 " |----------|----------|----------|----------|\n");
788 fprintf(STDOUT, "0-60 sec | %8d | %8d | %8d | %8d |\n",
789 a_xInfoP->stat_fileSameAuthor[VOLINT_STATS_TIME_IDX_0],
790 a_xInfoP->stat_fileDiffAuthor[VOLINT_STATS_TIME_IDX_0],
791 a_xInfoP->stat_dirSameAuthor[VOLINT_STATS_TIME_IDX_0],
792 a_xInfoP->stat_dirDiffAuthor[VOLINT_STATS_TIME_IDX_0]);
793 fprintf(STDOUT, "1-10 min | %8d | %8d | %8d | %8d |\n",
794 a_xInfoP->stat_fileSameAuthor[VOLINT_STATS_TIME_IDX_1],
795 a_xInfoP->stat_fileDiffAuthor[VOLINT_STATS_TIME_IDX_1],
796 a_xInfoP->stat_dirSameAuthor[VOLINT_STATS_TIME_IDX_1],
797 a_xInfoP->stat_dirDiffAuthor[VOLINT_STATS_TIME_IDX_1]);
798 fprintf(STDOUT, "10min-1hr | %8d | %8d | %8d | %8d |\n",
799 a_xInfoP->stat_fileSameAuthor[VOLINT_STATS_TIME_IDX_2],
800 a_xInfoP->stat_fileDiffAuthor[VOLINT_STATS_TIME_IDX_2],
801 a_xInfoP->stat_dirSameAuthor[VOLINT_STATS_TIME_IDX_2],
802 a_xInfoP->stat_dirDiffAuthor[VOLINT_STATS_TIME_IDX_2]);
803 fprintf(STDOUT, "1hr-1day | %8d | %8d | %8d | %8d |\n",
804 a_xInfoP->stat_fileSameAuthor[VOLINT_STATS_TIME_IDX_3],
805 a_xInfoP->stat_fileDiffAuthor[VOLINT_STATS_TIME_IDX_3],
806 a_xInfoP->stat_dirSameAuthor[VOLINT_STATS_TIME_IDX_3],
807 a_xInfoP->stat_dirDiffAuthor[VOLINT_STATS_TIME_IDX_3]);
808 fprintf(STDOUT, "1day-1wk | %8d | %8d | %8d | %8d |\n",
809 a_xInfoP->stat_fileSameAuthor[VOLINT_STATS_TIME_IDX_4],
810 a_xInfoP->stat_fileDiffAuthor[VOLINT_STATS_TIME_IDX_4],
811 a_xInfoP->stat_dirSameAuthor[VOLINT_STATS_TIME_IDX_4],
812 a_xInfoP->stat_dirDiffAuthor[VOLINT_STATS_TIME_IDX_4]);
813 fprintf(STDOUT, "> 1wk | %8d | %8d | %8d | %8d |\n",
814 a_xInfoP->stat_fileSameAuthor[VOLINT_STATS_TIME_IDX_5],
815 a_xInfoP->stat_fileDiffAuthor[VOLINT_STATS_TIME_IDX_5],
816 a_xInfoP->stat_dirSameAuthor[VOLINT_STATS_TIME_IDX_5],
817 a_xInfoP->stat_dirDiffAuthor[VOLINT_STATS_TIME_IDX_5]);
819 " |-------------------------------------------|\n");
820 } /*Volume status OK */
821 else if (a_xInfoP->status == VBUSY) {
823 qPut(&busyHead, a_xInfoP->volid);
825 fprintf(STDOUT, "**** Volume %lu is busy ****\n",
826 (unsigned long)a_xInfoP->volid);
830 qPut(¬okHead, a_xInfoP->volid);
832 fprintf(STDOUT, "**** Could not attach volume %lu ****\n",
833 (unsigned long)a_xInfoP->volid);
834 } /*Screwed volume */
835 fprintf(STDOUT, "\n");
841 if (a_xInfoP->status == VOK) {
842 fprintf(STDOUT, "%-32s ", a_xInfoP->name);
843 fprintf(STDOUT, "%10lu ", (unsigned long)a_xInfoP->volid);
844 if (a_xInfoP->type == 0)
845 fprintf(STDOUT, "RW ");
846 if (a_xInfoP->type == 1)
847 fprintf(STDOUT, "RO ");
848 if (a_xInfoP->type == 2)
849 fprintf(STDOUT, "BK ");
850 fprintf(STDOUT, "%10d K ", a_xInfoP->size);
851 if (a_xInfoP->inUse == 1) {
852 fprintf(STDOUT, "On-line");
855 fprintf(STDOUT, "Off-line");
858 fprintf(STDOUT, "\n");
860 else if (a_xInfoP->status == VBUSY) {
862 qPut(&busyHead, a_xInfoP->volid);
864 fprintf(STDOUT, "**** Volume %lu is busy ****\n",
865 (unsigned long)a_xInfoP->volid);
869 qPut(¬okHead, a_xInfoP->volid);
871 fprintf(STDOUT, "**** Could not attach volume %lu ****\n",
872 (unsigned long)a_xInfoP->volid);
873 } /*Screwed volume */
874 } /*Default listing */
875 } /*XDisplayFormat */
877 /*------------------------------------------------------------------------
878 * PRIVATE XDisplayFormat2
881 * Display the formated contents of one extended volume info structure.
884 * a_xInfoP : Ptr to extended volume info struct to print.
885 * a_servID : Server ID to print.
886 * a_partID : Partition ID to print.
887 * a_totalOKP : Ptr to total-OK counter.
888 * a_totalNotOKP : Ptr to total-screwed counter.
889 * a_totalBusyP : Ptr to total-busy counter.
890 * a_fast : Fast listing?
891 * a_int32 : Int32 listing?
892 * a_showProblems : Show volume problems?
898 * Nothing interesting.
902 *------------------------------------------------------------------------*/
905 XDisplayFormat2(volintXInfo *a_xInfoP, afs_uint32 a_servID, afs_int32 a_partID,
906 int *a_totalOKP, int *a_totalNotOKP, int *a_totalBusyP,
907 int a_fast, int a_int32, int a_showProblems)
908 { /*XDisplayFormat */
914 fprintf(STDOUT, "vold_id\t%-10lu\n", (unsigned long)a_xInfoP->volid);
915 } else if (a_int32) {
917 * Fully-detailed listing.
919 if (a_xInfoP->status == VOK) {
921 * Volume's status is OK - all the fields are valid.
924 static long server_cache = -1, partition_cache = -1;
925 static char hostname[256], address[32], pname[16];
926 int i,ai[] = {VOLINT_STATS_TIME_IDX_0,VOLINT_STATS_TIME_IDX_1,VOLINT_STATS_TIME_IDX_2,
927 VOLINT_STATS_TIME_IDX_3,VOLINT_STATS_TIME_IDX_4,VOLINT_STATS_TIME_IDX_5};
929 if (a_servID != server_cache) {
933 strcpy(hostname, hostutil_GetNameByINet(a_servID));
934 strcpy(address, inet_ntoa(s));
935 server_cache = a_servID;
937 if (a_partID != partition_cache) {
938 MapPartIdIntoName(a_partID, pname);
939 partition_cache = a_partID;
942 fprintf(STDOUT, "name\t\t%s\n", a_xInfoP->name);
943 fprintf(STDOUT, "id\t\t%lu\n", afs_printable_uint32_lu(a_xInfoP->volid));
944 fprintf(STDOUT, "serv\t\t%s\t%s\n", address, hostname);
945 fprintf(STDOUT, "part\t\t%s\n", pname);
946 fprintf(STDOUT, "status\t\tOK\n");
947 fprintf(STDOUT, "backupID\t%lu\n",
948 afs_printable_uint32_lu(a_xInfoP->backupID));
949 fprintf(STDOUT, "parentID\t%lu\n",
950 afs_printable_uint32_lu(a_xInfoP->parentID));
951 fprintf(STDOUT, "cloneID\t\t%lu\n",
952 afs_printable_uint32_lu(a_xInfoP->cloneID));
953 fprintf(STDOUT, "inUse\t\t%s\n", a_xInfoP->inUse ? "Y" : "N");
954 switch (a_xInfoP->type) {
956 fprintf(STDOUT, "type\t\tRW\n");
959 fprintf(STDOUT, "type\t\tRO\n");
962 fprintf(STDOUT, "type\t\tBK\n");
965 fprintf(STDOUT, "type\t\t?\n");
968 t = a_xInfoP->creationDate;
969 fprintf(STDOUT, "creationDate\t%-9lu\t%s",
970 afs_printable_uint32_lu(a_xInfoP->creationDate),
973 t = a_xInfoP->accessDate;
974 fprintf(STDOUT, "accessDate\t%-9lu\t%s",
975 afs_printable_uint32_lu(a_xInfoP->accessDate),
978 t = a_xInfoP->updateDate;
979 fprintf(STDOUT, "updateDate\t%-9lu\t%s",
980 afs_printable_uint32_lu(a_xInfoP->updateDate),
983 t = a_xInfoP->backupDate;
984 fprintf(STDOUT, "backupDate\t%-9lu\t%s",
985 afs_printable_uint32_lu(a_xInfoP->backupDate),
988 t = a_xInfoP->copyDate;
989 fprintf(STDOUT, "copyDate\t%-9lu\t%s",
990 afs_printable_uint32_lu(a_xInfoP->copyDate),
993 fprintf(STDOUT, "diskused\t%u\n", a_xInfoP->size);
994 fprintf(STDOUT, "maxquota\t%u\n", a_xInfoP->maxquota);
996 fprintf(STDOUT, "filecount\t%u\n", a_xInfoP->filecount);
997 fprintf(STDOUT, "dayUse\t\t%u\n", a_xInfoP->dayUse);
1001 fprintf(STDOUT,"reads_same_net\t%8d\n",a_xInfoP->stat_reads[VOLINT_STATS_SAME_NET]);
1002 fprintf(STDOUT,"reads_same_net_auth\t%8d\n",a_xInfoP->stat_reads[VOLINT_STATS_SAME_NET_AUTH]);
1003 fprintf(STDOUT,"reads_diff_net\t%8d\n",a_xInfoP->stat_reads[VOLINT_STATS_DIFF_NET]);
1004 fprintf(STDOUT,"reads_diff_net_auth\t%8d\n",a_xInfoP->stat_reads[VOLINT_STATS_DIFF_NET_AUTH]);
1006 fprintf(STDOUT,"writes_same_net\t%8d\n",a_xInfoP->stat_writes[VOLINT_STATS_SAME_NET]);
1007 fprintf(STDOUT,"writes_same_net_auth\t%8d\n",a_xInfoP->stat_writes[VOLINT_STATS_SAME_NET_AUTH]);
1008 fprintf(STDOUT,"writes_diff_net\t%8d\n",a_xInfoP->stat_writes[VOLINT_STATS_DIFF_NET]);
1009 fprintf(STDOUT,"writes_diff_net_auth\t%8d\n",a_xInfoP->stat_writes[VOLINT_STATS_DIFF_NET_AUTH]);
1013 fprintf(STDOUT,"file_same_author_idx_%d\t%8d\n",i+1,a_xInfoP->stat_fileSameAuthor[ai[i]]);
1014 fprintf(STDOUT,"file_diff_author_idx_%d\t%8d\n",i+1,a_xInfoP->stat_fileDiffAuthor[ai[i]]);
1015 fprintf(STDOUT,"dir_same_author_idx_%d\t%8d\n",i+1,a_xInfoP->stat_dirSameAuthor[ai[i]]);
1016 fprintf(STDOUT,"dir_dif_author_idx_%d\t%8d\n",i+1,a_xInfoP->stat_dirDiffAuthor[ai[i]]);
1019 } /*Volume status OK */
1020 else if (a_xInfoP->status == VBUSY) {
1022 qPut(&busyHead, a_xInfoP->volid);
1024 fprintf(STDOUT, "BUSY_VOL\t%lu\n",
1025 (unsigned long)a_xInfoP->volid);
1029 qPut(¬okHead, a_xInfoP->volid);
1031 fprintf(STDOUT, "COULD_NOT_ATTACH\t%lu\n",
1032 (unsigned long)a_xInfoP->volid);
1033 } /*Screwed volume */
1039 if (a_xInfoP->status == VOK) {
1040 fprintf(STDOUT, "name\t%-32s\n", a_xInfoP->name);
1041 fprintf(STDOUT, "volID\t%10lu\n", (unsigned long)a_xInfoP->volid);
1042 if (a_xInfoP->type == 0)
1043 fprintf(STDOUT, "type\tRW\n");
1044 if (a_xInfoP->type == 1)
1045 fprintf(STDOUT, "type\tRO\n");
1046 if (a_xInfoP->type == 2)
1047 fprintf(STDOUT, "type\tBK\n");
1048 fprintf(STDOUT, "size\t%10dK\n", a_xInfoP->size);
1050 fprintf(STDOUT, "inUse\t%d\n",a_xInfoP->inUse);
1051 if (a_xInfoP->inUse == 1)
1057 else if (a_xInfoP->status == VBUSY) {
1059 qPut(&busyHead, a_xInfoP->volid);
1061 fprintf(STDOUT, "VOLUME_BUSY\t%lu\n",
1062 (unsigned long)a_xInfoP->volid);
1066 qPut(¬okHead, a_xInfoP->volid);
1068 fprintf(STDOUT, "COULD_NOT_ATTACH_VOLUME\t%lu\n",
1069 (unsigned long)a_xInfoP->volid);
1070 } /*Screwed volume */
1071 } /*Default listing */
1072 } /*XDisplayFormat */
1075 DisplayFormat2(long server, long partition, volintInfo *pntr)
1077 static long server_cache = -1, partition_cache = -1;
1078 static char hostname[256], address[32], pname[16];
1081 if (server != server_cache) {
1085 strcpy(hostname, hostutil_GetNameByINet(server));
1086 strcpy(address, inet_ntoa(s));
1087 server_cache = server;
1089 if (partition != partition_cache) {
1090 MapPartIdIntoName(partition, pname);
1091 partition_cache = partition;
1094 if (pntr->status == VOK)
1095 fprintf(STDOUT, "name\t\t%s\n", pntr->name);
1097 fprintf(STDOUT, "id\t\t%lu\n",
1098 afs_printable_uint32_lu(pntr->volid));
1099 fprintf(STDOUT, "serv\t\t%s\t%s\n", address, hostname);
1100 fprintf(STDOUT, "part\t\t%s\n", pname);
1101 switch (pntr->status) {
1103 fprintf(STDOUT, "status\t\tOK\n");
1106 fprintf(STDOUT, "status\t\tBUSY\n");
1109 fprintf(STDOUT, "status\t\tUNATTACHABLE\n");
1112 fprintf(STDOUT, "backupID\t%lu\n",
1113 afs_printable_uint32_lu(pntr->backupID));
1114 fprintf(STDOUT, "parentID\t%lu\n",
1115 afs_printable_uint32_lu(pntr->parentID));
1116 fprintf(STDOUT, "cloneID\t\t%lu\n",
1117 afs_printable_uint32_lu(pntr->cloneID));
1118 fprintf(STDOUT, "inUse\t\t%s\n", pntr->inUse ? "Y" : "N");
1119 fprintf(STDOUT, "needsSalvaged\t%s\n", pntr->needsSalvaged ? "Y" : "N");
1120 /* 0xD3 is from afs/volume.h since I had trouble including the file */
1121 fprintf(STDOUT, "destroyMe\t%s\n", pntr->destroyMe == 0xD3 ? "Y" : "N");
1122 switch (pntr->type) {
1124 fprintf(STDOUT, "type\t\tRW\n");
1127 fprintf(STDOUT, "type\t\tRO\n");
1130 fprintf(STDOUT, "type\t\tBK\n");
1133 fprintf(STDOUT, "type\t\t?\n");
1136 t = pntr->creationDate;
1137 fprintf(STDOUT, "creationDate\t%-9lu\t%s",
1138 afs_printable_uint32_lu(pntr->creationDate),
1141 t = pntr->accessDate;
1142 fprintf(STDOUT, "accessDate\t%-9lu\t%s",
1143 afs_printable_uint32_lu(pntr->accessDate),
1146 t = pntr->updateDate;
1147 fprintf(STDOUT, "updateDate\t%-9lu\t%s",
1148 afs_printable_uint32_lu(pntr->updateDate),
1151 t = pntr->backupDate;
1152 fprintf(STDOUT, "backupDate\t%-9lu\t%s",
1153 afs_printable_uint32_lu(pntr->backupDate),
1157 fprintf(STDOUT, "copyDate\t%-9lu\t%s",
1158 afs_printable_uint32_lu(pntr->copyDate),
1161 fprintf(STDOUT, "flags\t\t%#lx\t(Optional)\n",
1162 afs_printable_uint32_lu(pntr->flags));
1163 fprintf(STDOUT, "diskused\t%u\n", pntr->size);
1164 fprintf(STDOUT, "maxquota\t%u\n", pntr->maxquota);
1165 fprintf(STDOUT, "minquota\t%lu\t(Optional)\n",
1166 afs_printable_uint32_lu(pntr->spare0));
1167 fprintf(STDOUT, "filecount\t%u\n", pntr->filecount);
1168 fprintf(STDOUT, "dayUse\t\t%u\n", pntr->dayUse);
1169 fprintf(STDOUT, "weekUse\t\t%lu\t(Optional)\n",
1170 afs_printable_uint32_lu(pntr->spare1));
1171 fprintf(STDOUT, "spare2\t\t%lu\t(Optional)\n",
1172 afs_printable_uint32_lu(pntr->spare2));
1173 fprintf(STDOUT, "spare3\t\t%lu\t(Optional)\n",
1174 afs_printable_uint32_lu(pntr->spare3));
1179 DisplayVolumes2(long server, long partition, volintInfo *pntr, long count)
1183 for (i = 0; i < count; i++) {
1184 fprintf(STDOUT, "BEGIN_OF_ENTRY\n");
1185 DisplayFormat2(server, partition, pntr);
1186 fprintf(STDOUT, "END_OF_ENTRY\n\n");
1193 DisplayVolumes(afs_uint32 server, afs_int32 part, volintInfo *pntr,
1194 afs_int32 count, afs_int32 longlist, afs_int32 fast,
1197 int totalOK, totalNotOK, totalBusy, i;
1198 afs_uint32 volid = 0;
1205 for (i = 0; i < count; i++) {
1206 DisplayFormat(pntr, server, part, &totalOK, &totalNotOK, &totalBusy,
1211 while (busyHead.count) {
1212 qGet(&busyHead, &volid);
1213 fprintf(STDOUT, "**** Volume %lu is busy ****\n",
1214 (unsigned long)volid);
1218 while (notokHead.count) {
1219 qGet(¬okHead, &volid);
1220 fprintf(STDOUT, "**** Could not attach volume %lu ****\n",
1221 (unsigned long)volid);
1225 fprintf(STDOUT, "\n");
1228 "Total volumes onLine %d ; Total volumes offLine %d ; Total busy %d\n\n",
1229 totalOK, totalNotOK, totalBusy);
1233 /*------------------------------------------------------------------------
1234 * PRIVATE XDisplayVolumes
1237 * Display extended volume information.
1240 * a_servID : Pointer to the Rx call we're performing.
1241 * a_partID : Partition for which we want the extended list.
1242 * a_xInfoP : Ptr to extended volume info.
1243 * a_count : Number of volume records contained above.
1244 * a_int32 : Int32 listing generated?
1245 * a_fast : Fast listing generated?
1246 * a_quiet : Quiet listing generated?
1252 * Nothing interesting.
1256 *------------------------------------------------------------------------*/
1259 XDisplayVolumes(afs_uint32 a_servID, afs_int32 a_partID, volintXInfo *a_xInfoP,
1260 afs_int32 a_count, afs_int32 a_int32, afs_int32 a_fast,
1262 { /*XDisplayVolumes */
1264 int totalOK; /*Total OK volumes */
1265 int totalNotOK; /*Total screwed volumes */
1266 int totalBusy; /*Total busy volumes */
1267 int i; /*Loop variable */
1268 afs_uint32 volid = 0; /*Current volume ID */
1271 * Initialize counters and (global!!) queues.
1280 * Display each volume in the list.
1282 for (i = 0; i < a_count; i++) {
1283 XDisplayFormat(a_xInfoP, a_servID, a_partID, &totalOK, &totalNotOK,
1284 &totalBusy, a_fast, a_int32, 0);
1289 * If any volumes were found to be busy or screwed, display them.
1292 while (busyHead.count) {
1293 qGet(&busyHead, &volid);
1294 fprintf(STDOUT, "**** Volume %lu is busy ****\n",
1295 (unsigned long)volid);
1299 while (notokHead.count) {
1300 qGet(¬okHead, &volid);
1301 fprintf(STDOUT, "**** Could not attach volume %lu ****\n",
1302 (unsigned long)volid);
1307 fprintf(STDOUT, "\n");
1310 "Total volumes: %d on-line, %d off-line, %d busyd\n\n",
1311 totalOK, totalNotOK, totalBusy);
1315 } /*XDisplayVolumes */
1317 /*------------------------------------------------------------------------
1318 * PRIVATE XDisplayVolumes2
1321 * Display extended formated volume information.
1324 * a_servID : Pointer to the Rx call we're performing.
1325 * a_partID : Partition for which we want the extended list.
1326 * a_xInfoP : Ptr to extended volume info.
1327 * a_count : Number of volume records contained above.
1328 * a_int32 : Int32 listing generated?
1329 * a_fast : Fast listing generated?
1330 * a_quiet : Quiet listing generated?
1336 * Nothing interesting.
1340 *------------------------------------------------------------------------*/
1343 XDisplayVolumes2(afs_uint32 a_servID, afs_int32 a_partID, volintXInfo *a_xInfoP,
1344 afs_int32 a_count, afs_int32 a_int32, afs_int32 a_fast,
1346 { /*XDisplayVolumes */
1348 int totalOK; /*Total OK volumes */
1349 int totalNotOK; /*Total screwed volumes */
1350 int totalBusy; /*Total busy volumes */
1351 int i; /*Loop variable */
1352 afs_uint32 volid = 0; /*Current volume ID */
1355 * Initialize counters and (global!!) queues.
1364 * Display each volume in the list.
1366 for (i = 0; i < a_count; i++) {
1367 fprintf(STDOUT, "BEGIN_OF_ENTRY\n");
1368 XDisplayFormat2(a_xInfoP, a_servID, a_partID, &totalOK, &totalNotOK,
1369 &totalBusy, a_fast, a_int32, 0);
1370 fprintf(STDOUT, "END_OF_ENTRY\n");
1375 * If any volumes were found to be busy or screwed, display them.
1378 while (busyHead.count) {
1379 qGet(&busyHead, &volid);
1380 fprintf(STDOUT, "BUSY_VOL\t%lu\n",
1381 (unsigned long)volid);
1385 while (notokHead.count) {
1386 qGet(¬okHead, &volid);
1387 fprintf(STDOUT, "COULD_NOT_ATTACH\t%lu\n",
1388 (unsigned long)volid);
1393 fprintf(STDOUT, "\n");
1396 "VOLUMES_ONLINE\t%d\nVOLUMES_OFFLINE\t%d\nVOLUMES_BUSY\t%d\n",
1397 totalOK, totalNotOK, totalBusy);
1401 } /*XDisplayVolumes2 */
1404 /* set <server> and <part> to the correct values depending on
1405 * <voltype> and <entry> */
1407 GetServerAndPart(struct nvldbentry *entry, int voltype, afs_uint32 *server,
1408 afs_int32 *part, int *previdx)
1410 int i, istart, vtype;
1415 /* Doesn't check for non-existance of backup volume */
1416 if ((voltype == RWVOL) || (voltype == BACKVOL)) {
1418 istart = 0; /* seach the entire entry */
1421 /* Seach from beginning of entry or pick up where we left off */
1422 istart = ((*previdx < 0) ? 0 : *previdx + 1);
1425 for (i = istart; i < entry->nServers; i++) {
1426 if (entry->serverFlags[i] & vtype) {
1427 *server = entry->serverNumber[i];
1428 *part = entry->serverPartition[i];
1434 /* Didn't find any, return -1 */
1440 PrintLocked(afs_int32 aflags)
1442 afs_int32 flags = aflags & VLOP_ALLOPERS;
1445 fprintf(STDOUT, " Volume is currently LOCKED \n");
1447 if (flags & VLOP_MOVE) {
1448 fprintf(STDOUT, " Volume is locked for a move operation\n");
1450 if (flags & VLOP_RELEASE) {
1451 fprintf(STDOUT, " Volume is locked for a release operation\n");
1453 if (flags & VLOP_BACKUP) {
1454 fprintf(STDOUT, " Volume is locked for a backup operation\n");
1456 if (flags & VLOP_DELETE) {
1457 fprintf(STDOUT, " Volume is locked for a delete/misc operation\n");
1459 if (flags & VLOP_DUMP) {
1460 fprintf(STDOUT, " Volume is locked for a dump/restore operation\n");
1466 PostVolumeStats(struct nvldbentry *entry)
1468 SubEnumerateEntry(entry);
1469 /* Check for VLOP_ALLOPERS */
1470 PrintLocked(entry->flags);
1474 /*------------------------------------------------------------------------
1475 * PRIVATE XVolumeStats
1478 * Display extended volume information.
1481 * a_xInfoP : Ptr to extended volume info.
1482 * a_entryP : Ptr to the volume's VLDB entry.
1483 * a_srvID : Server ID.
1484 * a_partID : Partition ID.
1485 * a_volType : Type of volume to print.
1491 * Nothing interesting.
1495 *------------------------------------------------------------------------*/
1498 XVolumeStats(volintXInfo *a_xInfoP, struct nvldbentry *a_entryP,
1499 afs_int32 a_srvID, afs_int32 a_partID, int a_volType)
1502 int totalOK, totalNotOK, totalBusy; /*Dummies - we don't really count here */
1504 XDisplayFormat(a_xInfoP, /*Ptr to extended volume info */
1505 a_srvID, /*Server ID to print */
1506 a_partID, /*Partition ID to print */
1507 &totalOK, /*Ptr to total-OK counter */
1508 &totalNotOK, /*Ptr to total-screwed counter */
1509 &totalBusy, /*Ptr to total-busy counter */
1510 0, /*Don't do a fast listing */
1511 1, /*Do a long listing */
1512 1); /*Show volume problems */
1518 VolumeStats_int(volintInfo *pntr, struct nvldbentry *entry, afs_uint32 server,
1519 afs_int32 part, int voltype)
1525 DisplayFormat(pntr, server, part, &totalOK, &totalNotOK, &totalBusy, 0, 1,
1530 /* command to forcibly remove a volume */
1532 NukeVolume(struct cmd_syndesc *as)
1541 server = GetServer(tp = as->parms[0].items->data);
1543 fprintf(STDERR, "vos: server '%s' not found in host table\n", tp);
1547 partID = volutil_GetPartitionID(tp = as->parms[1].items->data);
1549 fprintf(STDERR, "vos: could not parse '%s' as a partition name", tp);
1553 volID = vsu_GetVolumeID(tp = as->parms[2].items->data, cstruct, &err);
1556 PrintError("", err);
1559 "vos: could not parse '%s' as a numeric volume ID", tp);
1564 "vos: forcibly removing all traces of volume %d, please wait...",
1567 code = UV_NukeVolume(server, partID, volID);
1569 fprintf(STDOUT, "done.\n");
1571 fprintf(STDOUT, "failed with code %d.\n", code);
1576 /*------------------------------------------------------------------------
1577 * PRIVATE ExamineVolume
1580 * Routine used to examine a single volume, contacting the VLDB as
1581 * well as the Volume Server.
1584 * as : Ptr to parsed command line arguments.
1587 * 0 for a successful operation,
1588 * Otherwise, one of the ubik or VolServer error values.
1591 * Nothing interesting.
1595 *------------------------------------------------------------------------
1598 ExamineVolume(struct cmd_syndesc *as, void *arock)
1600 struct nvldbentry entry;
1601 afs_int32 vcode = 0;
1602 volintInfo *pntr = (volintInfo *) 0;
1603 volintXInfo *xInfoP = (volintXInfo *) 0;
1605 afs_int32 code, err, error = 0;
1606 int voltype, foundserv = 0, foundentry = 0;
1610 int wantExtendedInfo; /*Do we want extended vol info? */
1611 int isSubEnum=0; /* Keep track whether sub enumerate called. */
1612 wantExtendedInfo = (as->parms[1].items ? 1 : 0); /* -extended */
1614 volid = vsu_GetVolumeID(as->parms[0].items->data, cstruct, &err); /* -id */
1617 PrintError("", err);
1619 fprintf(STDERR, "Unknown volume ID or name '%s'\n",
1620 as->parms[0].items->data);
1625 fprintf(STDOUT, "Fetching VLDB entry for %lu .. ",
1626 (unsigned long)volid);
1629 vcode = VLDB_GetEntryByID(volid, -1, &entry);
1632 "Could not fetch the entry for volume number %lu from VLDB \n",
1633 (unsigned long)volid);
1637 fprintf(STDOUT, "done\n");
1638 MapHostToNetwork(&entry);
1640 if (entry.volumeId[RWVOL] == volid)
1642 else if (entry.volumeId[BACKVOL] == volid)
1644 else /* (entry.volumeId[ROVOL] == volid) */
1647 do { /* do {...} while (voltype == ROVOL) */
1648 /* Get the entry for the volume. If its a RW vol, get the RW entry.
1649 * It its a BK vol, get the RW entry (even if VLDB may say the BK doen't exist).
1650 * If its a RO vol, get the next RO entry.
1652 GetServerAndPart(&entry, ((voltype == ROVOL) ? ROVOL : RWVOL),
1653 &aserver, &apart, &previdx);
1654 if (previdx == -1) { /* searched all entries */
1656 fprintf(STDERR, "Volume %s does not exist in VLDB\n\n",
1657 as->parms[0].items->data);
1664 /* Get information about the volume from the server */
1666 fprintf(STDOUT, "Getting volume listing from the server %s .. ",
1667 hostutil_GetNameByINet(aserver));
1670 if (wantExtendedInfo)
1671 code = UV_XListOneVolume(aserver, apart, volid, &xInfoP);
1673 code = UV_ListOneVolume(aserver, apart, volid, &pntr);
1675 fprintf(STDOUT, "done\n");
1679 if (code == ENODEV) {
1680 if ((voltype == BACKVOL) && !(entry.flags & VLF_BACKEXISTS)) {
1681 /* The VLDB says there is no backup volume and its not on disk */
1682 fprintf(STDERR, "Volume %s does not exist\n",
1683 as->parms[0].items->data);
1687 "Volume does not exist on server %s as indicated by the VLDB\n",
1688 hostutil_GetNameByINet(aserver));
1691 PrintDiagnostics("examine", code);
1693 fprintf(STDOUT, "\n");
1696 if (wantExtendedInfo)
1697 XVolumeStats(xInfoP, &entry, aserver, apart, voltype);
1698 else if (as->parms[2].items) {
1699 DisplayFormat2(aserver, apart, pntr);
1700 EnumerateEntry(&entry);
1703 VolumeStats_int(pntr, &entry, aserver, apart, voltype);
1705 if ((voltype == BACKVOL) && !(entry.flags & VLF_BACKEXISTS)) {
1706 /* The VLDB says there is no backup volume yet we found one on disk */
1707 fprintf(STDERR, "Volume %s does not exist in VLDB\n",
1708 as->parms[0].items->data);
1717 } while (voltype == ROVOL);
1720 fprintf(STDERR, "Dump only information from VLDB\n\n");
1721 fprintf(STDOUT, "%s \n", entry.name); /* PostVolumeStats doesn't print name */
1725 PostVolumeStats(&entry);
1730 /*------------------------------------------------------------------------
1734 * Routine used to change the status of a single volume.
1737 * as : Ptr to parsed command line arguments.
1740 * 0 for a successful operation,
1741 * Otherwise, one of the ubik or VolServer error values.
1744 * Nothing interesting.
1748 *------------------------------------------------------------------------
1751 SetFields(struct cmd_syndesc *as, void *arock)
1753 struct nvldbentry entry;
1756 afs_int32 code, err;
1762 volid = vsu_GetVolumeID(as->parms[0].items->data, cstruct, &err); /* -id */
1765 PrintError("", err);
1767 fprintf(STDERR, "Unknown volume ID or name '%s'\n",
1768 as->parms[0].items->data);
1772 code = VLDB_GetEntryByID(volid, RWVOL, &entry);
1775 "Could not fetch the entry for volume number %lu from VLDB \n",
1776 (unsigned long)volid);
1779 MapHostToNetwork(&entry);
1781 GetServerAndPart(&entry, RWVOL, &aserver, &apart, &previdx);
1782 if (previdx == -1) {
1783 fprintf(STDERR, "Volume %s does not exist in VLDB\n\n",
1784 as->parms[0].items->data);
1788 init_volintInfo(&info);
1792 if (as->parms[1].items) {
1795 code = util_GetHumanInt32(as->parms[1].items->data, &info.maxquota);
1797 fprintf(STDERR, "invalid quota value\n");
1801 if (as->parms[2].items) {
1806 if (as->parms[3].items) {
1807 /* -clearVolUpCounter */
1812 fprintf(STDERR,"Nothing to set.\n");
1815 code = UV_SetVolumeInfo(aserver, apart, volid, &info);
1818 "Could not update volume info fields for volume number %lu\n",
1819 (unsigned long)volid);
1823 /*------------------------------------------------------------------------
1827 * Brings a volume online.
1830 * as : Ptr to parsed command line arguments.
1833 * 0 for a successful operation,
1836 * Nothing interesting.
1840 *------------------------------------------------------------------------
1843 volOnline(struct cmd_syndesc *as, void *arock)
1846 afs_int32 partition;
1848 afs_int32 code, err = 0;
1850 server = GetServer(as->parms[0].items->data);
1852 fprintf(STDERR, "vos: server '%s' not found in host table\n",
1853 as->parms[0].items->data);
1857 partition = volutil_GetPartitionID(as->parms[1].items->data);
1858 if (partition < 0) {
1859 fprintf(STDERR, "vos: could not interpret partition name '%s'\n",
1860 as->parms[1].items->data);
1864 volid = vsu_GetVolumeID(as->parms[2].items->data, cstruct, &err); /* -id */
1867 PrintError("", err);
1869 fprintf(STDERR, "Unknown volume ID or name '%s'\n",
1870 as->parms[0].items->data);
1874 code = UV_SetVolume(server, partition, volid, ITOffline, 0 /*online */ ,
1877 fprintf(STDERR, "Failed to set volume. Code = %d\n", code);
1884 /*------------------------------------------------------------------------
1885 * PRIVATE volOffline
1888 * Brings a volume offline.
1891 * as : Ptr to parsed command line arguments.
1894 * 0 for a successful operation,
1897 * Nothing interesting.
1901 *------------------------------------------------------------------------
1904 volOffline(struct cmd_syndesc *as, void *arock)
1907 afs_int32 partition;
1909 afs_int32 code, err = 0;
1910 afs_int32 transflag, sleeptime, transdone;
1912 server = GetServer(as->parms[0].items->data);
1914 fprintf(STDERR, "vos: server '%s' not found in host table\n",
1915 as->parms[0].items->data);
1919 partition = volutil_GetPartitionID(as->parms[1].items->data);
1920 if (partition < 0) {
1921 fprintf(STDERR, "vos: could not interpret partition name '%s'\n",
1922 as->parms[1].items->data);
1926 volid = vsu_GetVolumeID(as->parms[2].items->data, cstruct, &err); /* -id */
1929 PrintError("", err);
1931 fprintf(STDERR, "Unknown volume ID or name '%s'\n",
1932 as->parms[0].items->data);
1936 transflag = (as->parms[4].items ? ITBusy : ITOffline);
1937 sleeptime = (as->parms[3].items ? atol(as->parms[3].items->data) : 0);
1938 transdone = ((sleeptime || as->parms[4].items) ? 0 /*online */ : VTOutOfService);
1939 if (as->parms[4].items && !as->parms[3].items) {
1940 fprintf(STDERR, "-sleep option must be used with -busy flag\n");
1945 UV_SetVolume(server, partition, volid, transflag, transdone,
1948 fprintf(STDERR, "Failed to set volume. Code = %d\n", code);
1956 CreateVolume(struct cmd_syndesc *as, void *arock)
1960 afs_uint32 volid = 0, rovolid = 0, bkvolid = 0;
1961 afs_uint32 *arovolid;
1963 struct nvldbentry entry;
1968 arovolid = &rovolid;
1971 tserver = GetServer(as->parms[0].items->data);
1973 fprintf(STDERR, "vos: host '%s' not found in host table\n",
1974 as->parms[0].items->data);
1977 pnum = volutil_GetPartitionID(as->parms[1].items->data);
1979 fprintf(STDERR, "vos: could not interpret partition name '%s'\n",
1980 as->parms[1].items->data);
1983 if (!IsPartValid(pnum, tserver, &code)) { /*check for validity of the partition */
1985 PrintError("", code);
1988 "vos : partition %s does not exist on the server\n",
1989 as->parms[1].items->data);
1992 if (!ISNAMEVALID(as->parms[2].items->data)) {
1994 "vos: the name of the root volume %s exceeds the size limit of %d\n",
1995 as->parms[2].items->data, VOLSER_OLDMAXVOLNAME - 10);
1998 if (!VolNameOK(as->parms[2].items->data)) {
2000 "Illegal volume name %s, should not end in .readonly or .backup\n",
2001 as->parms[2].items->data);
2004 if (IsNumeric(as->parms[2].items->data)) {
2005 fprintf(STDERR, "Illegal volume name %s, should not be a number\n",
2006 as->parms[2].items->data);
2009 vcode = VLDB_GetEntryByName(as->parms[2].items->data, &entry);
2011 fprintf(STDERR, "Volume %s already exists\n",
2012 as->parms[2].items->data);
2013 PrintDiagnostics("create", code);
2017 if (as->parms[3].items) {
2018 code = util_GetHumanInt32(as->parms[3].items->data, "a);
2020 fprintf(STDERR, "vos: bad integer specified for quota.\n");
2025 if (as->parms[4].items) {
2026 if (!IsNumeric(as->parms[4].items->data)) {
2027 fprintf(STDERR, "vos: Given volume ID %s should be numeric.\n",
2028 as->parms[4].items->data);
2032 code = util_GetUInt32(as->parms[4].items->data, &volid);
2034 fprintf(STDERR, "vos: bad integer specified for volume ID.\n");
2039 if (as->parms[5].items) {
2040 if (!IsNumeric(as->parms[5].items->data)) {
2041 fprintf(STDERR, "vos: Given RO volume ID %s should be numeric.\n",
2042 as->parms[5].items->data);
2046 code = util_GetUInt32(as->parms[5].items->data, &rovolid);
2048 fprintf(STDERR, "vos: bad integer specified for volume ID.\n");
2058 UV_CreateVolume3(tserver, pnum, as->parms[2].items->data, quota, 0,
2059 0, 0, 0, &volid, arovolid, &bkvolid);
2061 PrintDiagnostics("create", code);
2064 MapPartIdIntoName(pnum, part);
2065 fprintf(STDOUT, "Volume %lu created on partition %s of %s\n",
2066 (unsigned long)volid, part, as->parms[0].items->data);
2073 DeleteAll(struct nvldbentry *entry)
2076 afs_int32 error, code, curserver, curpart;
2079 MapHostToNetwork(entry);
2081 for (i = 0; i < entry->nServers; i++) {
2082 curserver = entry->serverNumber[i];
2083 curpart = entry->serverPartition[i];
2084 if (entry->serverFlags[i] & VLSF_ROVOL) {
2085 volid = entry->volumeId[ROVOL];
2087 volid = entry->volumeId[RWVOL];
2089 code = UV_DeleteVolume(curserver, curpart, volid);
2098 DeleteVolume(struct cmd_syndesc *as, void *arock)
2100 afs_int32 err, code = 0;
2101 afs_uint32 server = 0;
2102 afs_int32 partition = -1;
2107 if (as->parms[0].items) {
2108 server = GetServer(as->parms[0].items->data);
2110 fprintf(STDERR, "vos: server '%s' not found in host table\n",
2111 as->parms[0].items->data);
2116 if (as->parms[1].items) {
2117 partition = volutil_GetPartitionID(as->parms[1].items->data);
2118 if (partition < 0) {
2119 fprintf(STDERR, "vos: could not interpret partition name '%s'\n",
2120 as->parms[1].items->data);
2124 /* Check for validity of the partition */
2125 if (!IsPartValid(partition, server, &code)) {
2127 PrintError("", code);
2130 "vos : partition %s does not exist on the server\n",
2131 as->parms[1].items->data);
2137 volid = vsu_GetVolumeID(as->parms[2].items->data, cstruct, &err);
2139 fprintf(STDERR, "Can't find volume name '%s' in VLDB\n",
2140 as->parms[2].items->data);
2142 PrintError("", err);
2146 /* If the server or partition option are not complete, try to fill
2147 * them in from the VLDB entry.
2149 if ((partition == -1) || !server) {
2150 struct nvldbentry entry;
2152 code = VLDB_GetEntryByID(volid, -1, &entry);
2155 "Could not fetch the entry for volume %lu from VLDB\n",
2156 (unsigned long)volid);
2157 PrintError("", code);
2161 if (((volid == entry.volumeId[RWVOL]) && (entry.flags & VLF_RWEXISTS))
2162 || ((volid == entry.volumeId[BACKVOL])
2163 && (entry.flags & VLF_BACKEXISTS))) {
2164 idx = Lp_GetRwIndex(&entry);
2165 if ((idx == -1) || (server && (server != entry.serverNumber[idx]))
2166 || ((partition != -1)
2167 && (partition != entry.serverPartition[idx]))) {
2168 fprintf(STDERR, "VLDB: Volume '%s' no match\n",
2169 as->parms[2].items->data);
2172 } else if ((volid == entry.volumeId[ROVOL])
2173 && (entry.flags & VLF_ROEXISTS)) {
2174 for (idx = -1, j = 0; j < entry.nServers; j++) {
2175 if (!(entry.serverFlags[j] & VLSF_ROVOL))
2178 if (((server == 0) || (server == entry.serverNumber[j]))
2179 && ((partition == -1)
2180 || (partition == entry.serverPartition[j]))) {
2183 "VLDB: Volume '%s' matches more than one RO\n",
2184 as->parms[2].items->data);
2191 fprintf(STDERR, "VLDB: Volume '%s' no match\n",
2192 as->parms[2].items->data);
2196 fprintf(STDERR, "VLDB: Volume '%s' no match\n",
2197 as->parms[2].items->data);
2201 server = htonl(entry.serverNumber[idx]);
2202 partition = entry.serverPartition[idx];
2206 code = UV_DeleteVolume(server, partition, volid);
2208 PrintDiagnostics("remove", code);
2212 MapPartIdIntoName(partition, pname);
2213 fprintf(STDOUT, "Volume %lu on partition %s server %s deleted\n",
2214 (unsigned long)volid, pname, hostutil_GetNameByINet(server));
2218 #define TESTM 0 /* set for move space tests, clear for production */
2220 MoveVolume(struct cmd_syndesc *as, void *arock)
2224 afs_uint32 fromserver, toserver;
2225 afs_int32 frompart, topart;
2226 afs_int32 flags, code, err;
2227 char fromPartName[10], toPartName[10];
2229 struct diskPartition64 partition; /* for space check */
2232 volid = vsu_GetVolumeID(as->parms[0].items->data, cstruct, &err);
2235 PrintError("", err);
2237 fprintf(STDERR, "vos: can't find volume ID or name '%s'\n",
2238 as->parms[0].items->data);
2241 fromserver = GetServer(as->parms[1].items->data);
2242 if (fromserver == 0) {
2243 fprintf(STDERR, "vos: server '%s' not found in host table\n",
2244 as->parms[1].items->data);
2247 toserver = GetServer(as->parms[3].items->data);
2248 if (toserver == 0) {
2249 fprintf(STDERR, "vos: server '%s' not found in host table\n",
2250 as->parms[3].items->data);
2253 frompart = volutil_GetPartitionID(as->parms[2].items->data);
2255 fprintf(STDERR, "vos: could not interpret partition name '%s'\n",
2256 as->parms[2].items->data);
2259 if (!IsPartValid(frompart, fromserver, &code)) { /*check for validity of the partition */
2261 PrintError("", code);
2264 "vos : partition %s does not exist on the server\n",
2265 as->parms[2].items->data);
2268 topart = volutil_GetPartitionID(as->parms[4].items->data);
2270 fprintf(STDERR, "vos: could not interpret partition name '%s'\n",
2271 as->parms[4].items->data);
2274 if (!IsPartValid(topart, toserver, &code)) { /*check for validity of the partition */
2276 PrintError("", code);
2279 "vos : partition %s does not exist on the server\n",
2280 as->parms[4].items->data);
2285 if (as->parms[5].items) flags |= RV_NOCLONE;
2288 * check source partition for space to clone volume
2291 MapPartIdIntoName(topart, toPartName);
2292 MapPartIdIntoName(frompart, fromPartName);
2295 * check target partition for space to move volume
2298 code = UV_PartitionInfo64(toserver, toPartName, &partition);
2300 fprintf(STDERR, "vos: cannot access partition %s\n", toPartName);
2304 fprintf(STDOUT, "target partition %s free space %" AFS_INT64_FMT "\n", toPartName,
2307 p = (volintInfo *) 0;
2308 code = UV_ListOneVolume(fromserver, frompart, volid, &p);
2310 fprintf(STDERR, "vos:cannot access volume %lu\n",
2311 (unsigned long)volid);
2315 fprintf(STDOUT, "volume %lu size %d\n", (unsigned long)volid,
2317 if (partition.free <= p->size) {
2319 "vos: no space on target partition %s to move volume %lu\n",
2320 toPartName, (unsigned long)volid);
2327 fprintf(STDOUT, "size test - don't do move\n");
2331 /* successful move still not guaranteed but shoot for it */
2334 UV_MoveVolume2(volid, fromserver, frompart, toserver, topart, flags);
2336 PrintDiagnostics("move", code);
2339 MapPartIdIntoName(topart, toPartName);
2340 MapPartIdIntoName(frompart, fromPartName);
2341 fprintf(STDOUT, "Volume %lu moved from %s %s to %s %s \n",
2342 (unsigned long)volid, as->parms[1].items->data, fromPartName,
2343 as->parms[3].items->data, toPartName);
2349 CopyVolume(struct cmd_syndesc *as, void *arock)
2352 afs_uint32 fromserver, toserver;
2353 afs_int32 frompart, topart, code, err, flags;
2354 char fromPartName[10], toPartName[10], *tovolume;
2355 struct nvldbentry entry;
2356 struct diskPartition64 partition; /* for space check */
2359 volid = vsu_GetVolumeID(as->parms[0].items->data, cstruct, &err);
2362 PrintError("", err);
2364 fprintf(STDERR, "vos: can't find volume ID or name '%s'\n",
2365 as->parms[0].items->data);
2368 fromserver = GetServer(as->parms[1].items->data);
2369 if (fromserver == 0) {
2370 fprintf(STDERR, "vos: server '%s' not found in host table\n",
2371 as->parms[1].items->data);
2375 toserver = GetServer(as->parms[4].items->data);
2376 if (toserver == 0) {
2377 fprintf(STDERR, "vos: server '%s' not found in host table\n",
2378 as->parms[4].items->data);
2382 tovolume = as->parms[3].items->data;
2383 if (!ISNAMEVALID(tovolume)) {
2385 "vos: the name of the root volume %s exceeds the size limit of %d\n",
2386 tovolume, VOLSER_OLDMAXVOLNAME - 10);
2389 if (!VolNameOK(tovolume)) {
2391 "Illegal volume name %s, should not end in .readonly or .backup\n",
2395 if (IsNumeric(tovolume)) {
2396 fprintf(STDERR, "Illegal volume name %s, should not be a number\n",
2400 code = VLDB_GetEntryByName(tovolume, &entry);
2402 fprintf(STDERR, "Volume %s already exists\n", tovolume);
2403 PrintDiagnostics("copy", code);
2407 frompart = volutil_GetPartitionID(as->parms[2].items->data);
2409 fprintf(STDERR, "vos: could not interpret partition name '%s'\n",
2410 as->parms[2].items->data);
2413 if (!IsPartValid(frompart, fromserver, &code)) { /*check for validity of the partition */
2415 PrintError("", code);
2418 "vos : partition %s does not exist on the server\n",
2419 as->parms[2].items->data);
2423 topart = volutil_GetPartitionID(as->parms[5].items->data);
2425 fprintf(STDERR, "vos: could not interpret partition name '%s'\n",
2426 as->parms[5].items->data);
2429 if (!IsPartValid(topart, toserver, &code)) { /*check for validity of the partition */
2431 PrintError("", code);
2434 "vos : partition %s does not exist on the server\n",
2435 as->parms[5].items->data);
2440 if (as->parms[6].items) flags |= RV_OFFLINE;
2441 if (as->parms[7].items) flags |= RV_RDONLY;
2442 if (as->parms[8].items) flags |= RV_NOCLONE;
2444 MapPartIdIntoName(topart, toPartName);
2445 MapPartIdIntoName(frompart, fromPartName);
2448 * check target partition for space to move volume
2451 code = UV_PartitionInfo64(toserver, toPartName, &partition);
2453 fprintf(STDERR, "vos: cannot access partition %s\n", toPartName);
2457 fprintf(STDOUT, "target partition %s free space %" AFS_INT64_FMT "\n", toPartName,
2460 p = (volintInfo *) 0;
2461 code = UV_ListOneVolume(fromserver, frompart, volid, &p);
2463 fprintf(STDERR, "vos:cannot access volume %lu\n",
2464 (unsigned long)volid);
2468 if (partition.free <= p->size) {
2470 "vos: no space on target partition %s to copy volume %lu\n",
2471 toPartName, (unsigned long)volid);
2477 /* successful copy still not guaranteed but shoot for it */
2480 UV_CopyVolume2(volid, fromserver, frompart, tovolume, toserver,
2483 PrintDiagnostics("copy", code);
2486 MapPartIdIntoName(topart, toPartName);
2487 MapPartIdIntoName(frompart, fromPartName);
2488 fprintf(STDOUT, "Volume %lu copied from %s %s to %s on %s %s \n",
2489 (unsigned long)volid, as->parms[1].items->data, fromPartName,
2490 tovolume, as->parms[4].items->data, toPartName);
2497 ShadowVolume(struct cmd_syndesc *as, void *arock)
2499 afs_uint32 volid, tovolid;
2500 afs_uint32 fromserver, toserver;
2501 afs_int32 frompart, topart;
2502 afs_int32 code, err, flags;
2503 char fromPartName[10], toPartName[10], toVolName[32], *tovolume;
2504 struct diskPartition64 partition; /* for space check */
2507 p = (volintInfo *) 0;
2508 q = (volintInfo *) 0;
2510 volid = vsu_GetVolumeID(as->parms[0].items->data, cstruct, &err);
2513 PrintError("", err);
2515 fprintf(STDERR, "vos: can't find volume ID or name '%s'\n",
2516 as->parms[0].items->data);
2519 fromserver = GetServer(as->parms[1].items->data);
2520 if (fromserver == 0) {
2521 fprintf(STDERR, "vos: server '%s' not found in host table\n",
2522 as->parms[1].items->data);
2526 toserver = GetServer(as->parms[3].items->data);
2527 if (toserver == 0) {
2528 fprintf(STDERR, "vos: server '%s' not found in host table\n",
2529 as->parms[3].items->data);
2533 frompart = volutil_GetPartitionID(as->parms[2].items->data);
2535 fprintf(STDERR, "vos: could not interpret partition name '%s'\n",
2536 as->parms[2].items->data);
2539 if (!IsPartValid(frompart, fromserver, &code)) { /*check for validity of the partition */
2541 PrintError("", code);
2544 "vos : partition %s does not exist on the server\n",
2545 as->parms[2].items->data);
2549 topart = volutil_GetPartitionID(as->parms[4].items->data);
2551 fprintf(STDERR, "vos: could not interpret partition name '%s'\n",
2552 as->parms[4].items->data);
2555 if (!IsPartValid(topart, toserver, &code)) { /*check for validity of the partition */
2557 PrintError("", code);
2560 "vos : partition %s does not exist on the server\n",
2561 as->parms[4].items->data);
2565 if (as->parms[5].items) {
2566 tovolume = as->parms[5].items->data;
2567 if (!ISNAMEVALID(tovolume)) {
2569 "vos: the name of the root volume %s exceeds the size limit of %d\n",
2570 tovolume, VOLSER_OLDMAXVOLNAME - 10);
2573 if (!VolNameOK(tovolume)) {
2575 "Illegal volume name %s, should not end in .readonly or .backup\n",
2579 if (IsNumeric(tovolume)) {
2581 "Illegal volume name %s, should not be a number\n",
2586 /* use actual name of source volume */
2587 code = UV_ListOneVolume(fromserver, frompart, volid, &p);
2589 fprintf(STDERR, "vos:cannot access volume %lu\n",
2590 (unsigned long)volid);
2593 strcpy(toVolName, p->name);
2594 tovolume = toVolName;
2595 /* save p for size checks later */
2598 if (as->parms[6].items) {
2599 tovolid = vsu_GetVolumeID(as->parms[6].items->data, cstruct, &err);
2602 PrintError("", err);
2604 fprintf(STDERR, "vos: can't find volume ID or name '%s'\n",
2605 as->parms[6].items->data);
2611 tovolid = vsu_GetVolumeID(tovolume, cstruct, &err);
2614 PrintError("", err);
2616 fprintf(STDERR, "vos: can't find volume ID or name '%s'\n",
2625 if (as->parms[7].items) flags |= RV_OFFLINE;
2626 if (as->parms[8].items) flags |= RV_RDONLY;
2627 if (as->parms[9].items) flags |= RV_NOCLONE;
2628 if (as->parms[10].items) flags |= RV_CPINCR;
2630 MapPartIdIntoName(topart, toPartName);
2631 MapPartIdIntoName(frompart, fromPartName);
2634 * check target partition for space to move volume
2637 code = UV_PartitionInfo64(toserver, toPartName, &partition);
2639 fprintf(STDERR, "vos: cannot access partition %s\n", toPartName);
2643 fprintf(STDOUT, "target partition %s free space %" AFS_INT64_FMT "\n", toPartName,
2646 /* Don't do this again if we did it above */
2648 code = UV_ListOneVolume(fromserver, frompart, volid, &p);
2650 fprintf(STDERR, "vos:cannot access volume %lu\n",
2651 (unsigned long)volid);
2656 /* OK if this fails */
2657 code = UV_ListOneVolume(toserver, topart, tovolid, &q);
2659 /* Treat existing volume size as "free" */
2661 p->size = (q->size < p->size) ? p->size - q->size : 0;
2663 if (partition.free <= p->size) {
2665 "vos: no space on target partition %s to copy volume %lu\n",
2666 toPartName, (unsigned long)volid);
2674 /* successful copy still not guaranteed but shoot for it */
2677 UV_CopyVolume2(volid, fromserver, frompart, tovolume, toserver,
2678 topart, tovolid, flags);
2680 PrintDiagnostics("shadow", code);
2683 MapPartIdIntoName(topart, toPartName);
2684 MapPartIdIntoName(frompart, fromPartName);
2685 fprintf(STDOUT, "Volume %lu shadowed from %s %s to %s %s \n",
2686 (unsigned long)volid, as->parms[1].items->data, fromPartName,
2687 as->parms[3].items->data, toPartName);
2694 CloneVolume(struct cmd_syndesc *as, void *arock)
2696 afs_uint32 volid, cloneid;
2698 afs_int32 part, voltype;
2699 char partName[10], *volname;
2700 afs_int32 code, err, flags;
2701 struct nvldbentry entry;
2703 volid = vsu_GetVolumeID(as->parms[0].items->data, cstruct, &err);
2706 PrintError("", err);
2708 fprintf(STDERR, "vos: can't find volume ID or name '%s'\n",
2709 as->parms[0].items->data);
2713 if (as->parms[1].items || as->parms[2].items) {
2714 if (!as->parms[1].items || !as->parms[2].items) {
2716 "Must specify both -server and -partition options\n");
2719 server = GetServer(as->parms[1].items->data);
2721 fprintf(STDERR, "vos: server '%s' not found in host table\n",
2722 as->parms[1].items->data);
2725 part = volutil_GetPartitionID(as->parms[2].items->data);
2727 fprintf(STDERR, "vos: could not interpret partition name '%s'\n",
2728 as->parms[2].items->data);
2731 if (!IsPartValid(part, server, &code)) { /*check for validity of the partition */
2733 PrintError("", code);
2736 "vos : partition %s does not exist on the server\n",
2737 as->parms[2].items->data);
2741 code = GetVolumeInfo(volid, &server, &part, &voltype, &entry);
2747 if (as->parms[3].items) {
2748 volname = as->parms[3].items->data;
2749 if (strlen(volname) > VOLSER_OLDMAXVOLNAME - 1) {
2751 "vos: the name of the root volume %s exceeds the size limit of %d\n",
2752 volname, VOLSER_OLDMAXVOLNAME - 1);
2757 * In order that you be able to make clones of RO or BK, this
2758 * check must be omitted.
2760 if (!VolNameOK(volname)) {
2762 "Illegal volume name %s, should not end in .readonly or .backup\n",
2767 if (IsNumeric(volname)) {
2769 "Illegal volume name %s, should not be a number\n",
2776 if (as->parms[4].items) {
2777 cloneid = vsu_GetVolumeID(as->parms[4].items->data, cstruct, &err);
2780 PrintError("", err);
2782 fprintf(STDERR, "vos: can't find volume ID or name '%s'\n",
2783 as->parms[4].items->data);
2789 if (as->parms[5].items) flags |= RV_OFFLINE;
2790 if (as->parms[6].items && as->parms[7].items) {
2791 fprintf(STDERR, "vos: cannot specify that a volume be -readwrite and -readonly\n");
2794 if (as->parms[6].items) flags |= RV_RDONLY;
2795 if (as->parms[7].items) flags |= RV_RWONLY;
2799 UV_CloneVolume(server, part, volid, cloneid, volname, flags);
2802 PrintDiagnostics("clone", code);
2805 MapPartIdIntoName(part, partName);
2806 fprintf(STDOUT, "Created clone for volume %s\n",
2807 as->parms[0].items->data);
2814 BackupVolume(struct cmd_syndesc *as, void *arock)
2818 afs_int32 apart, vtype, code, err;
2819 struct nvldbentry entry;
2822 afs_uint32 buserver;
2823 afs_int32 bupart, butype;
2824 struct nvldbentry buentry;
2826 avolid = vsu_GetVolumeID(as->parms[0].items->data, cstruct, &err);
2829 PrintError("", err);
2831 fprintf(STDERR, "vos: can't find volume ID or name '%s'\n",
2832 as->parms[0].items->data);
2835 code = GetVolumeInfo(avolid, &aserver, &apart, &vtype, &entry);
2839 /* verify this is a readwrite volume */
2841 if (vtype != RWVOL) {
2842 fprintf(STDERR, "%s not RW volume\n", as->parms[0].items->data);
2846 /* is there a backup volume already? */
2848 if (entry.flags & VLF_BACKEXISTS) {
2849 /* yep, where is it? */
2851 buvolid = entry.volumeId[BACKVOL];
2852 code = GetVolumeInfo(buvolid, &buserver, &bupart, &butype, &buentry);
2857 code = VLDB_IsSameAddrs(buserver, aserver, &err);
2860 "Failed to get info about server's %d address(es) from vlserver; aborting call!\n",
2866 "FATAL ERROR: backup volume %lu exists on server %lu\n",
2867 (unsigned long)buvolid, (unsigned long)buserver);
2872 /* nope, carry on */
2874 code = UV_BackupVolume(aserver, apart, avolid);
2877 PrintDiagnostics("backup", code);
2880 fprintf(STDOUT, "Created backup volume for %s \n",
2881 as->parms[0].items->data);
2886 ReleaseVolume(struct cmd_syndesc *as, void *arock)
2889 struct nvldbentry entry;
2892 afs_int32 apart, vtype, code, err;
2895 if (as->parms[1].items) /* -force */
2896 flags |= (REL_COMPLETE | REL_FULLDUMPS);
2897 if (as->parms[2].items) /* -stayonline */
2898 flags |= REL_STAYUP;
2899 if (as->parms[3].items) /* -force-reclone */
2900 flags |= REL_COMPLETE;
2902 avolid = vsu_GetVolumeID(as->parms[0].items->data, cstruct, &err);
2905 PrintError("", err);
2907 fprintf(STDERR, "vos: can't find volume '%s'\n",
2908 as->parms[0].items->data);
2911 code = GetVolumeInfo(avolid, &aserver, &apart, &vtype, &entry);
2915 if (vtype != RWVOL) {
2916 fprintf(STDERR, "%s not a RW volume\n", as->parms[0].items->data);
2920 if (!ISNAMEVALID(entry.name)) {
2922 "Volume name %s is too long, rename before releasing\n",
2927 code = UV_ReleaseVolume(avolid, aserver, apart, flags);
2930 PrintDiagnostics("release", code);
2933 fprintf(STDOUT, "Released volume %s successfully\n",
2934 as->parms[0].items->data);
2939 DumpVolumeCmd(struct cmd_syndesc *as, void *arock)
2943 afs_int32 apart, voltype, fromdate = 0, code, err, i, flags;
2944 char filename[MAXPATHLEN];
2945 struct nvldbentry entry;
2947 rx_SetRxDeadTime(60 * 10);
2948 for (i = 0; i < MAXSERVERS; i++) {
2949 struct rx_connection *rxConn = ubik_GetRPCConn(cstruct, i);
2952 rx_SetConnDeadTime(rxConn, rx_connDeadTime);
2953 if (rx_ServiceOf(rxConn))
2954 rx_ServiceOf(rxConn)->connDeadTime = rx_connDeadTime;
2957 avolid = vsu_GetVolumeID(as->parms[0].items->data, cstruct, &err);
2960 PrintError("", err);
2962 fprintf(STDERR, "vos: can't find volume '%s'\n",
2963 as->parms[0].items->data);
2967 if (as->parms[3].items || as->parms[4].items) {
2968 if (!as->parms[3].items || !as->parms[4].items) {
2970 "Must specify both -server and -partition options\n");
2973 aserver = GetServer(as->parms[3].items->data);
2975 fprintf(STDERR, "Invalid server name\n");
2978 apart = volutil_GetPartitionID(as->parms[4].items->data);
2980 fprintf(STDERR, "Invalid partition name\n");
2984 code = GetVolumeInfo(avolid, &aserver, &apart, &voltype, &entry);
2989 if (as->parms[1].items && strcmp(as->parms[1].items->data, "0")) {
2990 code = ktime_DateToInt32(as->parms[1].items->data, &fromdate);
2992 fprintf(STDERR, "vos: failed to parse date '%s' (error=%d))\n",
2993 as->parms[1].items->data, code);
2997 if (as->parms[2].items) {
2998 strcpy(filename, as->parms[2].items->data);
3000 strcpy(filename, "");
3003 flags = as->parms[6].items ? VOLDUMPV2_OMITDIRS : 0;
3005 if (as->parms[5].items) {
3007 UV_DumpClonedVolume(avolid, aserver, apart, fromdate,
3008 DumpFunction, filename, flags);
3011 UV_DumpVolume(avolid, aserver, apart, fromdate, DumpFunction,
3014 if ((code == RXGEN_OPCODE) && (as->parms[6].items)) {
3015 flags &= ~VOLDUMPV2_OMITDIRS;
3019 PrintDiagnostics("dump", code);
3022 if (strcmp(filename, ""))
3023 fprintf(STDERR, "Dumped volume %s in file %s\n",
3024 as->parms[0].items->data, filename);
3026 fprintf(STDERR, "Dumped volume %s in stdout \n",
3027 as->parms[0].items->data);
3041 RestoreVolumeCmd(struct cmd_syndesc *as, void *arock)
3043 afs_uint32 avolid, aparentid;
3045 afs_int32 apart, code, vcode, err;
3046 afs_int32 aoverwrite = ASK;
3047 afs_int32 acreation = 0, alastupdate = 0;
3048 int restoreflags = 0;
3049 int readonly = 0, offline = 0, voltype = RWVOL;
3050 char afilename[MAXPATHLEN], avolname[VOLSER_MAXVOLNAME + 1], apartName[10];
3051 char volname[VOLSER_MAXVOLNAME + 1];
3052 struct nvldbentry entry;
3055 if (as->parms[4].items) {
3056 avolid = vsu_GetVolumeID(as->parms[4].items->data, cstruct, &err);
3059 PrintError("", err);
3061 fprintf(STDERR, "vos: can't find volume '%s'\n",
3062 as->parms[4].items->data);
3068 if (as->parms[5].items) {
3069 if ((strcmp(as->parms[5].items->data, "a") == 0)
3070 || (strcmp(as->parms[5].items->data, "abort") == 0)) {
3072 } else if ((strcmp(as->parms[5].items->data, "f") == 0)
3073 || (strcmp(as->parms[5].items->data, "full") == 0)) {
3075 } else if ((strcmp(as->parms[5].items->data, "i") == 0)
3076 || (strcmp(as->parms[5].items->data, "inc") == 0)
3077 || (strcmp(as->parms[5].items->data, "increment") == 0)
3078 || (strcmp(as->parms[5].items->data, "incremental") == 0)) {
3081 fprintf(STDERR, "vos: %s is not a valid argument to -overwrite\n",
3082 as->parms[5].items->data);
3086 if (as->parms[6].items)
3088 if (as->parms[7].items) {
3093 if (as->parms[8].items) {
3094 if ((strcmp(as->parms[8].items->data, "d") == 0)
3095 || (strcmp(as->parms[8].items->data, "dump") == 0)) {
3096 acreation = TS_DUMP;
3097 } else if ((strcmp(as->parms[8].items->data, "k") == 0)
3098 || (strcmp(as->parms[8].items->data, "keep") == 0)) {
3099 acreation = TS_KEEP;
3100 } else if ((strcmp(as->parms[8].items->data, "n") == 0)
3101 || (strcmp(as->parms[8].items->data, "new") == 0)) {
3104 fprintf(STDERR, "vos: %s is not a valid argument to -creation\n",
3105 as->parms[8].items->data);
3110 if (as->parms[9].items) {
3111 if ((strcmp(as->parms[9].items->data, "d") == 0)
3112 || (strcmp(as->parms[9].items->data, "dump") == 0)) {
3113 alastupdate = TS_DUMP;
3114 } else if ((strcmp(as->parms[9].items->data, "k") == 0)
3115 || (strcmp(as->parms[9].items->data, "keep") == 0)) {
3116 alastupdate = TS_KEEP;
3117 } else if ((strcmp(as->parms[9].items->data, "n") == 0)
3118 || (strcmp(as->parms[9].items->data, "new") == 0)) {
3119 alastupdate = TS_NEW;
3121 fprintf(STDERR, "vos: %s is not a valid argument to -lastupdate\n",
3122 as->parms[9].items->data);
3127 aserver = GetServer(as->parms[0].items->data);
3129 fprintf(STDERR, "vos: server '%s' not found in host table\n",
3130 as->parms[0].items->data);
3133 apart = volutil_GetPartitionID(as->parms[1].items->data);
3135 fprintf(STDERR, "vos: could not interpret partition name '%s'\n",
3136 as->parms[1].items->data);
3139 if (!IsPartValid(apart, aserver, &code)) { /*check for validity of the partition */
3141 PrintError("", code);
3144 "vos : partition %s does not exist on the server\n",
3145 as->parms[1].items->data);
3148 strcpy(avolname, as->parms[2].items->data);
3149 if (!ISNAMEVALID(avolname)) {
3151 "vos: the name of the volume %s exceeds the size limit\n",
3155 if (!VolNameOK(avolname)) {
3157 "Illegal volume name %s, should not end in .readonly or .backup\n",
3161 if (as->parms[3].items) {
3162 strcpy(afilename, as->parms[3].items->data);
3163 if (!FileExists(afilename)) {
3164 fprintf(STDERR, "Can't access file %s\n", afilename);
3168 strcpy(afilename, "");
3171 /* Check if volume exists or not */
3173 vsu_ExtractName(volname, avolname);
3174 vcode = VLDB_GetEntryByName(volname, &entry);
3175 if (vcode) { /* no volume - do a full restore */
3176 restoreflags = RV_FULLRST;
3177 if ((aoverwrite == INC) || (aoverwrite == ABORT))
3179 "Volume does not exist; Will perform a full restore\n");
3182 else if ((!readonly && Lp_GetRwIndex(&entry) == -1) /* RW volume does not exist - do a full */
3183 ||(readonly && !Lp_ROMatch(0, 0, &entry))) { /* RO volume does not exist - do a full */
3184 restoreflags = RV_FULLRST;
3185 if ((aoverwrite == INC) || (aoverwrite == ABORT))
3187 "%s Volume does not exist; Will perform a full restore\n",
3188 readonly ? "RO" : "RW");
3191 avolid = entry.volumeId[voltype];
3192 } else if (entry.volumeId[voltype] != 0
3193 && entry.volumeId[voltype] != avolid) {
3194 avolid = entry.volumeId[voltype];
3196 aparentid = entry.volumeId[RWVOL];
3199 else { /* volume exists - do we do a full incremental or abort */
3201 afs_int32 Opart, Otype, vol_elsewhere = 0;
3202 struct nvldbentry Oentry;
3206 avolid = entry.volumeId[voltype];
3207 } else if (entry.volumeId[voltype] != 0
3208 && entry.volumeId[voltype] != avolid) {
3209 avolid = entry.volumeId[voltype];
3211 aparentid = entry.volumeId[RWVOL];
3213 /* A file name was specified - check if volume is on another partition */
3214 vcode = GetVolumeInfo(avolid, &Oserver, &Opart, &Otype, &Oentry);
3218 vcode = VLDB_IsSameAddrs(Oserver, aserver, &err);
3221 "Failed to get info about server's %d address(es) from vlserver (err=%d); aborting call!\n",
3225 if (!vcode || (Opart != apart))
3228 if (aoverwrite == ASK) {
3229 if (strcmp(afilename, "") == 0) { /* The file is from standard in */
3231 "Volume exists and no -overwrite option specified; Aborting restore command\n");
3235 /* Ask what to do */
3236 if (vol_elsewhere) {
3238 "The volume %s %u already exists on a different server/part\n",
3239 volname, entry.volumeId[voltype]);
3241 "Do you want to do a full restore or abort? [fa](a): ");
3244 "The volume %s %u already exists in the VLDB\n",
3245 volname, entry.volumeId[voltype]);
3247 "Do you want to do a full/incremental restore or abort? [fia](a): ");
3250 while (!(dc == EOF || dc == '\n'))
3251 dc = getchar(); /* goto end of line */
3252 if ((c == 'f') || (c == 'F'))
3254 else if ((c == 'i') || (c == 'I'))
3260 if (aoverwrite == ABORT) {
3261 fprintf(STDERR, "Volume exists; Aborting restore command\n");
3263 } else if (aoverwrite == FULL) {
3264 restoreflags = RV_FULLRST;
3266 "Volume exists; Will delete and perform full restore\n");
3267 } else if (aoverwrite == INC) {
3269 if (vol_elsewhere) {
3271 "%s volume %lu already exists on a different server/part; not allowed\n",
3272 readonly ? "RO" : "RW", (unsigned long)avolid);
3278 restoreflags |= RV_OFFLINE;
3280 restoreflags |= RV_RDONLY;
3282 switch (acreation) {
3284 restoreflags |= RV_CRDUMP;
3287 restoreflags |= RV_CRKEEP;
3290 restoreflags |= RV_CRNEW;
3293 if (aoverwrite == FULL)
3294 restoreflags |= RV_CRNEW;
3296 restoreflags |= RV_CRKEEP;
3299 switch (alastupdate) {
3301 restoreflags |= RV_LUDUMP;
3304 restoreflags |= RV_LUKEEP;
3307 restoreflags |= RV_LUNEW;
3310 restoreflags |= RV_LUDUMP;
3312 if (as->parms[10].items) {
3313 restoreflags |= RV_NODEL;
3318 UV_RestoreVolume2(aserver, apart, avolid, aparentid,
3319 avolname, restoreflags, WriteData, afilename);
3321 PrintDiagnostics("restore", code);
3324 MapPartIdIntoName(apart, apartName);
3327 * patch typo here - originally "parms[1]", should be "parms[0]"
3330 fprintf(STDOUT, "Restored volume %s on %s %s\n", avolname,
3331 as->parms[0].items->data, apartName);
3336 LockReleaseCmd(struct cmd_syndesc *as, void *arock)
3339 afs_int32 code, err;
3341 avolid = vsu_GetVolumeID(as->parms[0].items->data, cstruct, &err);
3344 PrintError("", err);
3346 fprintf(STDERR, "vos: can't find volume '%s'\n",
3347 as->parms[0].items->data);
3351 code = UV_LockRelease(avolid);
3353 PrintDiagnostics("unlock", code);
3356 fprintf(STDOUT, "Released lock on vldb entry for volume %s\n",
3357 as->parms[0].items->data);
3362 AddSite(struct cmd_syndesc *as, void *arock)
3366 afs_int32 apart, code, err, arovolid, valid = 0;
3367 char apartName[10], avolname[VOLSER_MAXVOLNAME + 1];
3369 vsu_ExtractName(avolname, as->parms[2].items->data);;
3370 avolid = vsu_GetVolumeID(avolname, cstruct, &err);
3373 PrintError("", err);
3375 fprintf(STDERR, "vos: can't find volume '%s'\n",
3376 as->parms[2].items->data);
3380 if (as->parms[3].items) {
3381 vsu_ExtractName(avolname, as->parms[3].items->data);
3382 arovolid = vsu_GetVolumeID(avolname, cstruct, &err);
3384 fprintf(STDERR, "vos: invalid ro volume id '%s'\n",
3385 as->parms[3].items->data);
3389 aserver = GetServer(as->parms[0].items->data);
3391 fprintf(STDERR, "vos: server '%s' not found in host table\n",
3392 as->parms[0].items->data);
3395 apart = volutil_GetPartitionID(as->parms[1].items->data);
3397 fprintf(STDERR, "vos: could not interpret partition name '%s'\n",
3398 as->parms[1].items->data);
3401 if (!IsPartValid(apart, aserver, &code)) { /*check for validity of the partition */
3403 PrintError("", code);
3406 "vos : partition %s does not exist on the server\n",
3407 as->parms[1].items->data);
3410 if (as->parms[4].items) {
3413 code = UV_AddSite2(aserver, apart, avolid, arovolid, valid);
3415 PrintDiagnostics("addsite", code);
3418 MapPartIdIntoName(apart, apartName);
3419 fprintf(STDOUT, "Added replication site %s %s for volume %s\n",
3420 as->parms[0].items->data, apartName, as->parms[2].items->data);
3425 RemoveSite(struct cmd_syndesc *as, void *arock)
3430 afs_int32 apart, code, err;
3431 char apartName[10], avolname[VOLSER_MAXVOLNAME + 1];
3433 vsu_ExtractName(avolname, as->parms[2].items->data);
3434 avolid = vsu_GetVolumeID(avolname, cstruct, &err);
3437 PrintError("", err);
3439 fprintf(STDERR, "vos: can't find volume '%s'\n",
3440 as->parms[2].items->data);
3443 aserver = GetServer(as->parms[0].items->data);
3445 fprintf(STDERR, "vos: server '%s' not found in host table\n",
3446 as->parms[0].items->data);
3449 apart = volutil_GetPartitionID(as->parms[1].items->data);
3451 fprintf(STDERR, "vos: could not interpret partition name '%s'\n",
3452 as->parms[1].items->data);
3456 *skip the partition validity check, since it is possible that the partition
3457 *has since been decomissioned.
3460 if (!IsPartValid(apart,aserver,&code)){
3461 if(code) PrintError("",code);
3462 else fprintf(STDERR,"vos : partition %s does not exist on the server\n",as->parms[1].items->data);
3466 code = UV_RemoveSite(aserver, apart, avolid);
3468 PrintDiagnostics("remsite", code);
3471 MapPartIdIntoName(apart, apartName);
3472 fprintf(STDOUT, "Removed replication site %s %s for volume %s\n",
3473 as->parms[0].items->data, apartName, as->parms[2].items->data);
3478 ChangeLocation(struct cmd_syndesc *as, void *arock)
3482 afs_int32 apart, code, err;
3485 avolid = vsu_GetVolumeID(as->parms[2].items->data, cstruct, &err);
3488 PrintError("", err);
3490 fprintf(STDERR, "vos: can't find volume '%s'\n",
3491 as->parms[2].items->data);
3494 aserver = GetServer(as->parms[0].items->data);
3496 fprintf(STDERR, "vos: server '%s' not found in host table\n",
3497 as->parms[0].items->data);
3500 apart = volutil_GetPartitionID(as->parms[1].items->data);
3502 fprintf(STDERR, "vos: could not interpret partition name '%s'\n",
3503 as->parms[1].items->data);
3506 if (!IsPartValid(apart, aserver, &code)) { /*check for validity of the partition */
3508 PrintError("", code);
3511 "vos : partition %s does not exist on the server\n",
3512 as->parms[1].items->data);
3515 code = UV_ChangeLocation(aserver, apart, avolid);
3517 PrintDiagnostics("changeloc", code);
3520 MapPartIdIntoName(apart, apartName);
3521 fprintf(STDOUT, "Changed location to %s %s for volume %s\n",
3522 as->parms[0].items->data, apartName, as->parms[2].items->data);
3527 ListPartitions(struct cmd_syndesc *as, void *arock)
3531 struct partList dummyPartList;
3536 aserver = GetServer(as->parms[0].items->data);
3538 fprintf(STDERR, "vos: server '%s' not found in host table\n",
3539 as->parms[0].items->data);
3544 code = UV_ListPartitions(aserver, &dummyPartList, &cnt);
3546 PrintDiagnostics("listpart", code);
3550 fprintf(STDOUT, "The partitions on the server are:\n");
3551 for (i = 0; i < cnt; i++) {
3552 if (dummyPartList.partFlags[i] & PARTVALID) {
3553 memset(pname, 0, sizeof(pname));
3554 MapPartIdIntoName(dummyPartList.partId[i], pname);
3555 fprintf(STDOUT, " %10s ", pname);
3557 if ((i % 5) == 0 && (i != 0))
3558 fprintf(STDOUT, "\n");
3561 fprintf(STDOUT, "\n");
3562 fprintf(STDOUT, "Total: %d\n", total);
3568 CompareVolName(const void *p1, const void *p2)
3570 volintInfo *arg1, *arg2;
3572 arg1 = (volintInfo *) p1;
3573 arg2 = (volintInfo *) p2;
3574 return (strcmp(arg1->name, arg2->name));
3578 /*------------------------------------------------------------------------
3579 * PRIVATE XCompareVolName
3582 * Comparison routine for volume names coming from an extended
3586 * a_obj1P : Char ptr to first extended vol info object
3587 * a_obj1P : Char ptr to second extended vol info object
3590 * The value of strcmp() on the volume names within the passed
3591 * objects (i,e., -1, 0, or 1).
3594 * Passed to qsort() as the designated comparison routine.
3598 *------------------------------------------------------------------------*/
3601 XCompareVolName(const void *a_obj1P, const void *a_obj2P)
3602 { /*XCompareVolName */
3605 (((struct volintXInfo *)(a_obj1P))->name,
3606 ((struct volintXInfo *)(a_obj2P))->name));
3608 } /*XCompareVolName */
3611 CompareVolID(const void *p1, const void *p2)
3613 volintInfo *arg1, *arg2;
3615 arg1 = (volintInfo *) p1;
3616 arg2 = (volintInfo *) p2;
3617 if (arg1->volid == arg2->volid)
3619 if (arg1->volid > arg2->volid)
3626 /*------------------------------------------------------------------------
3627 * PRIVATE XCompareVolID
3630 * Comparison routine for volume IDs coming from an extended
3634 * a_obj1P : Char ptr to first extended vol info object
3635 * a_obj1P : Char ptr to second extended vol info object
3638 * The value of strcmp() on the volume names within the passed
3639 * objects (i,e., -1, 0, or 1).
3642 * Passed to qsort() as the designated comparison routine.
3646 *------------------------------------------------------------------------*/
3649 XCompareVolID(const void *a_obj1P, const void *a_obj2P)
3650 { /*XCompareVolID */
3652 afs_int32 id1, id2; /*Volume IDs we're comparing */
3654 id1 = ((struct volintXInfo *)(a_obj1P))->volid;
3655 id2 = ((struct volintXInfo *)(a_obj2P))->volid;
3663 } /*XCompareVolID */
3665 /*------------------------------------------------------------------------
3666 * PRIVATE ListVolumes
3669 * Routine used to list volumes, contacting the Volume Server
3670 * directly, bypassing the VLDB.
3673 * as : Ptr to parsed command line arguments.
3676 * 0 Successful operation
3679 * Nothing interesting.
3683 *------------------------------------------------------------------------*/
3686 ListVolumes(struct cmd_syndesc *as, void *arock)
3688 afs_int32 apart, int32list, fast;
3692 volintInfo *oldpntr = NULL;
3696 volintXInfo *xInfoP;
3697 volintXInfo *origxInfoP = NULL; /*Ptr to current/orig extended vol info */
3698 int wantExtendedInfo; /*Do we want extended vol info? */
3701 struct partList dummyPartList;
3709 if (as->parms[3].items)
3711 if (as->parms[4].items)
3715 if (as->parms[2].items)
3721 if (as->parms[5].items) {
3723 * We can't coexist with the fast flag.
3727 "vos: Can't use the -fast and -extended flags together\n");
3732 * We need to turn on ``long'' listings to get the full effect.
3734 wantExtendedInfo = 1;
3737 wantExtendedInfo = 0;
3738 if (as->parms[1].items) {
3739 apart = volutil_GetPartitionID(as->parms[1].items->data);
3741 fprintf(STDERR, "vos: could not interpret partition name '%s'\n",
3742 as->parms[1].items->data);
3745 dummyPartList.partId[0] = apart;
3746 dummyPartList.partFlags[0] = PARTVALID;
3749 aserver = GetServer(as->parms[0].items->data);
3751 fprintf(STDERR, "vos: server '%s' not found in host table\n",
3752 as->parms[0].items->data);
3757 if (!IsPartValid(apart, aserver, &code)) { /*check for validity of the partition */
3759 PrintError("", code);
3762 "vos : partition %s does not exist on the server\n",
3763 as->parms[1].items->data);
3767 code = UV_ListPartitions(aserver, &dummyPartList, &cnt);
3769 PrintDiagnostics("listvol", code);
3773 for (i = 0; i < cnt; i++) {
3774 if (dummyPartList.partFlags[i] & PARTVALID) {
3775 if (wantExtendedInfo)
3777 UV_XListVolumes(aserver, dummyPartList.partId[i], all,
3781 UV_ListVolumes(aserver, dummyPartList.partId[i], all,
3784 PrintDiagnostics("listvol", code);
3787 if (wantExtendedInfo) {
3788 origxInfoP = xInfoP;
3789 base = (char *)xInfoP;
3792 base = (char *)pntr;
3796 if (wantExtendedInfo)
3797 qsort(base, count, sizeof(volintXInfo), XCompareVolName);
3799 qsort(base, count, sizeof(volintInfo), CompareVolName);
3801 if (wantExtendedInfo)
3802 qsort(base, count, sizeof(volintXInfo), XCompareVolID);
3804 qsort(base, count, sizeof(volintInfo), CompareVolID);
3806 MapPartIdIntoName(dummyPartList.partId[i], pname);
3809 "Total number of volumes on server %s partition %s: %lu \n",
3810 as->parms[0].items->data, pname,
3811 (unsigned long)count);
3812 if (wantExtendedInfo) {
3813 if (as->parms[6].items)
3814 XDisplayVolumes2(aserver, dummyPartList.partId[i], origxInfoP,
3815 count, int32list, fast, quiet);
3817 XDisplayVolumes(aserver, dummyPartList.partId[i], origxInfoP,
3818 count, int32list, fast, quiet);
3821 xInfoP = (volintXInfo *) 0;
3823 if (as->parms[6].items)
3824 DisplayVolumes2(aserver, dummyPartList.partId[i], oldpntr,
3827 DisplayVolumes(aserver, dummyPartList.partId[i], oldpntr,
3828 count, int32list, fast, quiet);
3831 pntr = (volintInfo *) 0;
3839 SyncVldb(struct cmd_syndesc *as, void *arock)
3841 afs_int32 pnum = 0, code; /* part name */
3848 if (as->parms[0].items) {
3849 tserver = GetServer(as->parms[0].items->data);
3851 fprintf(STDERR, "vos: host '%s' not found in host table\n",
3852 as->parms[0].items->data);
3857 if (as->parms[1].items) {
3858 pnum = volutil_GetPartitionID(as->parms[1].items->data);
3860 fprintf(STDERR, "vos: could not interpret partition name '%s'\n",
3861 as->parms[1].items->data);
3864 if (!IsPartValid(pnum, tserver, &code)) { /*check for validity of the partition */
3866 PrintError("", code);
3869 "vos: partition %s does not exist on the server\n",
3870 as->parms[1].items->data);
3877 "The -partition option requires a -server option\n");
3882 if (as->parms[3].items) {
3883 flags |= 2; /* don't update */
3886 if (as->parms[2].items) {
3887 /* Synchronize an individual volume */
3888 volname = as->parms[2].items->data;
3889 code = UV_SyncVolume(tserver, pnum, volname, flags);
3893 "Without a -volume option, the -server option is required\n");
3896 code = UV_SyncVldb(tserver, pnum, flags, 0 /*unused */ );
3900 PrintDiagnostics("syncvldb", code);
3904 /* Print a summary of what we did */
3906 fprintf(STDOUT, "VLDB volume %s synchronized", volname);
3908 fprintf(STDOUT, "VLDB synchronized");
3910 fprintf(STDOUT, " with state of server %s", as->parms[0].items->data);
3913 MapPartIdIntoName(pnum, part);
3914 fprintf(STDOUT, " partition %s\n", part);
3916 fprintf(STDOUT, "\n");
3922 SyncServer(struct cmd_syndesc *as, void *arock)
3924 afs_int32 pnum, code; /* part name */
3930 tserver = GetServer(as->parms[0].items->data);
3932 fprintf(STDERR, "vos: host '%s' not found in host table\n",
3933 as->parms[0].items->data);
3936 if (as->parms[1].items) {
3937 pnum = volutil_GetPartitionID(as->parms[1].items->data);
3939 fprintf(STDERR, "vos: could not interpret partition name '%s'\n",
3940 as->parms[1].items->data);
3943 if (!IsPartValid(pnum, tserver, &code)) { /*check for validity of the partition */
3945 PrintError("", code);
3948 "vos : partition %s does not exist on the server\n",
3949 as->parms[1].items->data);
3957 if (as->parms[2].items) {
3958 flags |= 2; /* don't update */
3960 code = UV_SyncServer(tserver, pnum, flags, 0 /*unused */ );
3962 PrintDiagnostics("syncserv", code);
3966 MapPartIdIntoName(pnum, part);
3967 fprintf(STDOUT, "Server %s partition %s synchronized with VLDB\n",
3968 as->parms[0].items->data, part);
3970 fprintf(STDOUT, "Server %s synchronized with VLDB\n",
3971 as->parms[0].items->data);
3977 VolumeInfoCmd(char *name)
3979 struct nvldbentry entry;
3982 /* The vlserver will handle names with the .readonly
3983 * and .backup extension as well as volume ids.
3985 vcode = VLDB_GetEntryByName(name, &entry);
3987 PrintError("", vcode);
3990 MapHostToNetwork(&entry);
3991 EnumerateEntry(&entry);
3993 /* Defect #3027: grubby check to handle locked volume.
3994 * If VLOP_ALLOPERS is set, the entry is locked.
3995 * Leave this routine as is, but put in correct check.
3997 PrintLocked(entry.flags);
4003 VolumeZap(struct cmd_syndesc *as, void *arock)
4005 struct nvldbentry entry;
4006 afs_uint32 volid, zapbackupid = 0, backupid = 0;
4007 afs_int32 code, server, part, err;
4009 if (as->parms[3].items) {
4010 /* force flag is on, use the other version */
4011 return NukeVolume(as);
4014 if (as->parms[4].items) {
4018 volid = vsu_GetVolumeID(as->parms[2].items->data, cstruct, &err);
4021 PrintError("", err);
4023 fprintf(STDERR, "vos: can't find volume '%s'\n",
4024 as->parms[2].items->data);
4027 part = volutil_GetPartitionID(as->parms[1].items->data);
4029 fprintf(STDERR, "vos: could not interpret partition name '%s'\n",
4030 as->parms[1].items->data);
4033 server = GetServer(as->parms[0].items->data);
4035 fprintf(STDERR, "vos: host '%s' not found in host table\n",
4036 as->parms[0].items->data);
4039 if (!IsPartValid(part, server, &code)) { /*check for validity of the partition */
4041 PrintError("", code);
4044 "vos : partition %s does not exist on the server\n",
4045 as->parms[1].items->data);
4048 code = VLDB_GetEntryByID(volid, -1, &entry);
4050 if (volid == entry.volumeId[RWVOL])
4051 backupid = entry.volumeId[BACKVOL];
4053 "Warning: Entry for volume number %lu exists in VLDB (but we're zapping it anyway!)\n",
4054 (unsigned long)volid);
4057 volintInfo *pntr = (volintInfo *) 0;
4060 code = UV_ListOneVolume(server, part, volid, &pntr);
4062 if (volid == pntr->parentID)
4063 backupid = pntr->backupID;
4069 code = UV_VolumeZap(server, part, backupid);
4071 PrintDiagnostics("zap", code);
4074 fprintf(STDOUT, "Backup Volume %lu deleted\n",
4075 (unsigned long)backupid);
4078 code = UV_VolumeZap(server, part, volid);
4080 PrintDiagnostics("zap", code);
4083 fprintf(STDOUT, "Volume %lu deleted\n", (unsigned long)volid);
4089 VolserStatus(struct cmd_syndesc *as, void *arock)
4093 transDebugInfo *pntr, *oldpntr;
4099 server = GetServer(as->parms[0].items->data);
4101 fprintf(STDERR, "vos: host '%s' not found in host table\n",
4102 as->parms[0].items->data);
4105 code = UV_VolserStatus(server, &pntr, &count);
4107 PrintDiagnostics("status", code);
4112 fprintf(STDOUT, "No active transactions on %s\n",
4113 as->parms[0].items->data);
4115 fprintf(STDOUT, "Total transactions: %d\n", count);
4117 for (i = 0; i < count; i++) {
4118 /*print out the relevant info */
4119 fprintf(STDOUT, "--------------------------------------\n");
4120 t = pntr->creationTime;
4121 fprintf(STDOUT, "transaction: %lu created: %s",
4122 (unsigned long)pntr->tid, ctime(&t));
4124 fprintf(STDOUT, "lastActiveTime: %s", ctime(&t));
4125 if (pntr->returnCode) {
4126 fprintf(STDOUT, "returnCode: %lu\n",
4127 (unsigned long)pntr->returnCode);
4130 fprintf(STDOUT, "attachFlags: ");
4131 switch (pntr->iflags) {
4133 fprintf(STDOUT, "offline ");
4136 fprintf(STDOUT, "busy ");
4139 fprintf(STDOUT, "readonly ");
4142 fprintf(STDOUT, "create ");
4145 fprintf(STDOUT, "create volid ");
4148 fprintf(STDOUT, "\n");
4151 fprintf(STDOUT, "volumeStatus: ");
4152 switch (pntr->vflags) {
4153 case VTDeleteOnSalvage:
4154 fprintf(STDOUT, "deleteOnSalvage ");
4155 case VTOutOfService:
4156 fprintf(STDOUT, "outOfService ");
4158 fprintf(STDOUT, "deleted ");
4160 fprintf(STDOUT, "\n");
4163 fprintf(STDOUT, "transactionFlags: ");
4164 fprintf(STDOUT, "delete\n");
4166 MapPartIdIntoName(pntr->partition, pname);
4167 fprintf(STDOUT, "volume: %lu partition: %s procedure: %s\n",
4168 (unsigned long)pntr->volid, pname, pntr->lastProcName);
4169 if (pntr->callValid) {
4170 t = pntr->lastReceiveTime;
4171 fprintf(STDOUT, "packetRead: %lu lastReceiveTime: %s",
4172 (unsigned long)pntr->readNext, ctime(&t));
4173 t = pntr->lastSendTime;
4174 fprintf(STDOUT, "packetSend: %lu lastSendTime: %s",
4175 (unsigned long)pntr->transmitNext, ctime(&t));
4178 fprintf(STDOUT, "--------------------------------------\n");
4179 fprintf(STDOUT, "\n");
4187 RenameVolume(struct cmd_syndesc *as, void *arock)
4189 afs_int32 code1, code2, code;
4190 struct nvldbentry entry;
4192 code1 = VLDB_GetEntryByName(as->parms[0].items->data, &entry);
4194 fprintf(STDERR, "vos: Could not find entry for volume %s\n",
4195 as->parms[0].items->data);
4198 code2 = VLDB_GetEntryByName(as->parms[1].items->data, &entry);
4199 if ((!code1) && (!code2)) { /*the newname already exists */
4200 fprintf(STDERR, "vos: volume %s already exists\n",
4201 as->parms[1].items->data);
4205 if (code1 && code2) {
4206 fprintf(STDERR, "vos: Could not find entry for volume %s or %s\n",
4207 as->parms[0].items->data, as->parms[1].items->data);
4210 if (!VolNameOK(as->parms[0].items->data)) {
4212 "Illegal volume name %s, should not end in .readonly or .backup\n",
4213 as->parms[0].items->data);
4216 if (!ISNAMEVALID(as->parms[1].items->data)) {
4218 "vos: the new volume name %s exceeds the size limit of %d\n",
4219 as->parms[1].items->data, VOLSER_OLDMAXVOLNAME - 10);
4222 if (!VolNameOK(as->parms[1].items->data)) {
4224 "Illegal volume name %s, should not end in .readonly or .backup\n",
4225 as->parms[1].items->data);
4228 if (IsNumeric(as->parms[1].items->data)) {
4229 fprintf(STDERR, "Illegal volume name %s, should not be a number\n",
4230 as->parms[1].items->data);
4233 MapHostToNetwork(&entry);
4235 UV_RenameVolume(&entry, as->parms[0].items->data,
4236 as->parms[1].items->data);
4238 PrintDiagnostics("rename", code);
4241 fprintf(STDOUT, "Renamed volume %s to %s\n", as->parms[0].items->data,
4242 as->parms[1].items->data);
4247 GetVolumeInfo(afs_uint32 volid, afs_uint32 *server, afs_int32 *part, afs_int32 *voltype,
4248 struct nvldbentry *rentry)
4253 vcode = VLDB_GetEntryByID(volid, -1, rentry);
4256 "Could not fetch the entry for volume %lu from VLDB \n",
4257 (unsigned long)volid);
4258 PrintError("", vcode);
4261 MapHostToNetwork(rentry);
4262 if (volid == rentry->volumeId[ROVOL]) {
4264 for (i = 0; i < rentry->nServers; i++) {
4265 if ((index == -1) && (rentry->serverFlags[i] & VLSF_ROVOL)
4266 && !(rentry->serverFlags[i] & VLSF_DONTUSE))
4271 "RO volume is not found in VLDB entry for volume %lu\n",
4272 (unsigned long)volid);
4276 *server = rentry->serverNumber[index];
4277 *part = rentry->serverPartition[index];
4281 index = Lp_GetRwIndex(rentry);
4284 "RW Volume is not found in VLDB entry for volume %lu\n",
4285 (unsigned long)volid);
4288 if (volid == rentry->volumeId[RWVOL]) {
4290 *server = rentry->serverNumber[index];
4291 *part = rentry->serverPartition[index];
4294 if (volid == rentry->volumeId[BACKVOL]) {
4296 *server = rentry->serverNumber[index];
4297 *part = rentry->serverPartition[index];
4301 "unexpected volume type for volume %lu\n",
4302 (unsigned long)volid);
4307 DeleteEntry(struct cmd_syndesc *as, void *arock)
4309 afs_int32 apart = 0;
4312 struct VldbListByAttributes attributes;
4313 nbulkentries arrayEntries;
4314 struct nvldbentry *vllist;
4315 struct cmd_item *itp;
4318 char prefix[VOLSER_MAXVOLNAME + 1];
4320 afs_int32 totalBack = 0, totalFail = 0, err;
4322 if (as->parms[0].items) { /* -id */
4323 if (as->parms[1].items || as->parms[2].items || as->parms[3].items) {
4325 "You cannot use -server, -partition, or -prefix with the -id argument\n");
4328 for (itp = as->parms[0].items; itp; itp = itp->next) {
4329 avolid = vsu_GetVolumeID(itp->data, cstruct, &err);
4332 PrintError("", err);
4334 fprintf(STDERR, "vos: can't find volume '%s'\n",
4338 if (as->parms[4].items || as->parms[5].items) {
4339 /* -noexecute (hidden) or -dryrun */
4340 fprintf(STDOUT, "Would have deleted VLDB entry for %s \n",
4345 vcode = ubik_VL_DeleteEntry(cstruct, 0, avolid, RWVOL);
4347 fprintf(STDERR, "Could not delete entry for volume %s\n",
4350 "You must specify a RW volume name or ID "
4351 "(the entire VLDB entry will be deleted)\n");
4352 PrintError("", vcode);
4358 fprintf(STDOUT, "Deleted %d VLDB entries\n", totalBack);
4362 if (!as->parms[1].items && !as->parms[2].items && !as->parms[3].items) {
4363 fprintf(STDERR, "You must specify an option\n");
4367 /* Zero out search attributes */
4368 memset(&attributes, 0, sizeof(struct VldbListByAttributes));
4370 if (as->parms[1].items) { /* -prefix */
4371 strncpy(prefix, as->parms[1].items->data, VOLSER_MAXVOLNAME);
4373 if (!as->parms[2].items && !as->parms[3].items) { /* a single entry only */
4375 "You must provide -server with the -prefix argument\n");
4380 if (as->parms[2].items) { /* -server */
4382 aserver = GetServer(as->parms[2].items->data);
4384 fprintf(STDERR, "vos: server '%s' not found in host table\n",
4385 as->parms[2].items->data);
4388 attributes.server = ntohl(aserver);
4389 attributes.Mask |= VLLIST_SERVER;
4392 if (as->parms[3].items) { /* -partition */
4393 if (!as->parms[2].items) {
4395 "You must provide -server with the -partition argument\n");
4398 apart = volutil_GetPartitionID(as->parms[3].items->data);
4400 fprintf(STDERR, "vos: could not interpret partition name '%s'\n",
4401 as->parms[3].items->data);
4404 attributes.partition = apart;
4405 attributes.Mask |= VLLIST_PARTITION;
4408 /* Print status line of what we are doing */
4409 fprintf(STDOUT, "Deleting VLDB entries for ");
4410 if (as->parms[2].items) {
4411 fprintf(STDOUT, "server %s ", as->parms[2].items->data);
4413 if (as->parms[3].items) {
4415 MapPartIdIntoName(apart, pname);
4416 fprintf(STDOUT, "partition %s ", pname);
4419 fprintf(STDOUT, "which are prefixed with %s ", prefix);
4421 fprintf(STDOUT, "\n");
4424 /* Get all the VLDB entries on a server and/or partition */
4425 memset(&arrayEntries, 0, sizeof(arrayEntries));
4426 vcode = VLDB_ListAttributes(&attributes, &nentries, &arrayEntries);
4428 fprintf(STDERR, "Could not access the VLDB for attributes\n");
4429 PrintError("", vcode);
4433 /* Process each entry */
4434 for (j = 0; j < nentries; j++) {
4435 vllist = &arrayEntries.nbulkentries_val[j];
4437 /* It only deletes the RW volumes */
4438 if (strncmp(vllist->name, prefix, strlen(prefix))) {
4441 "Omitting to delete %s due to prefix %s mismatch\n",
4442 vllist->name, prefix);
4449 if (as->parms[4].items || as->parms[5].items) {
4450 /* -noexecute (hidden) or -dryrun */
4451 fprintf(STDOUT, "Would have deleted VLDB entry for %s \n",
4457 /* Only matches the RW volume name */
4458 avolid = vllist->volumeId[RWVOL];
4459 vcode = ubik_VL_DeleteEntry(cstruct, 0, avolid, RWVOL);
4461 fprintf(STDOUT, "Could not delete VLDB entry for %s\n",
4464 PrintError("", vcode);
4469 fprintf(STDOUT, "Deleted VLDB entry for %s \n", vllist->name);
4474 fprintf(STDOUT, "----------------------\n");
4476 "Total VLDB entries deleted: %lu; failed to delete: %lu\n",
4477 (unsigned long)totalBack, (unsigned long)totalFail);
4479 xdr_free((xdrproc_t) xdr_nbulkentries, &arrayEntries);
4485 CompareVldbEntryByName(const void *p1, const void *p2)
4487 struct nvldbentry *arg1, *arg2;
4489 arg1 = (struct nvldbentry *)p1;
4490 arg2 = (struct nvldbentry *)p2;
4491 return (strcmp(arg1->name, arg2->name));
4495 static int CompareVldbEntry(char *p1, char *p2)
4497 struct nvldbentry *arg1,*arg2;
4500 char comp1[100],comp2[100];
4501 char temp1[20],temp2[20];
4503 arg1 = (struct nvldbentry *)p1;
4504 arg2 = (struct nvldbentry *)p2;
4508 for(i = 0; i < arg1->nServers; i++)
4509 if(arg1->serverFlags[i] & VLSF_RWVOL) pos1 = i;
4510 for(i = 0; i < arg2->nServers; i++)
4511 if(arg2->serverFlags[i] & VLSF_RWVOL) pos2 = i;
4512 if(pos1 == -1 || pos2 == -1){
4516 sprintf(comp1,"%10u",arg1->serverNumber[pos1]);
4517 sprintf(comp2,"%10u",arg2->serverNumber[pos2]);
4518 sprintf(temp1,"%10u",arg1->serverPartition[pos1]);
4519 sprintf(temp2,"%10u",arg2->serverPartition[pos2]);
4520 strcat(comp1,temp1);
4521 strcat(comp2,temp2);
4522 strcat(comp1,arg1->name);
4523 strcat(comp1,arg2->name);
4524 return(strcmp(comp1,comp2));
4530 ListVLDB(struct cmd_syndesc *as, void *arock)
4535 struct VldbListByAttributes attributes;
4536 nbulkentries arrayEntries;
4537 struct nvldbentry *vllist, *tarray = 0, *ttarray;
4538 afs_int32 centries, nentries = 0;
4539 afs_int32 tarraysize = 0;
4540 afs_int32 parraysize;
4543 int quiet, sort, lock;
4544 afs_int32 thisindex, nextindex;
4548 attributes.Mask = 0;
4549 lock = (as->parms[3].items ? 1 : 0); /* -lock flag */
4550 quiet = (as->parms[4].items ? 1 : 0); /* -quit flag */
4551 sort = (as->parms[5].items ? 0 : 1); /* -nosort flag */
4553 /* If the volume name is given, Use VolumeInfoCmd to look it up
4554 * and not ListAttributes.
4556 if (as->parms[0].items) {
4559 "vos: illegal use of '-locked' switch, need to specify server and/or partition\n");
4562 code = VolumeInfoCmd(as->parms[0].items->data);
4564 PrintError("", code);
4570 /* Server specified */
4571 if (as->parms[1].items) {
4574 aserver = GetServer(as->parms[1].items->data);
4576 fprintf(STDERR, "vos: server '%s' not found in host table\n",
4577 as->parms[1].items->data);
4580 attributes.server = ntohl(aserver);
4581 attributes.Mask |= VLLIST_SERVER;
4584 /* Partition specified */
4585 if (as->parms[2].items) {
4586 apart = volutil_GetPartitionID(as->parms[2].items->data);
4588 fprintf(STDERR, "vos: could not interpret partition name '%s'\n",
4589 as->parms[2].items->data);
4592 attributes.partition = apart;
4593 attributes.Mask |= VLLIST_PARTITION;
4597 attributes.Mask |= VLLIST_FLAG;
4598 attributes.flag = VLOP_ALLOPERS;
4601 /* Print header information */
4603 MapPartIdIntoName(apart, pname);
4604 fprintf(STDOUT, "VLDB entries for %s %s%s%s %s\n",
4605 (as->parms[1].items ? "server" : "all"),
4606 (as->parms[1].items ? as->parms[1].items->data : "servers"),
4607 (as->parms[2].items ? " partition " : ""),
4608 (as->parms[2].items ? pname : ""),
4609 (lock ? "which are locked:" : ""));
4612 for (thisindex = 0; (thisindex != -1); thisindex = nextindex) {
4613 memset(&arrayEntries, 0, sizeof(arrayEntries));
4618 VLDB_ListAttributesN2(&attributes, 0, thisindex, ¢ries,
4619 &arrayEntries, &nextindex);
4620 if (vcode == RXGEN_OPCODE) {
4621 /* Vlserver not running with ListAttributesN2. Fall back */
4623 VLDB_ListAttributes(&attributes, ¢ries, &arrayEntries);
4627 fprintf(STDERR, "Could not access the VLDB for attributes\n");
4628 PrintError("", vcode);
4631 nentries += centries;
4633 /* We don't sort, so just print the entries now */
4635 for (j = 0; j < centries; j++) { /* process each entry */
4636 vllist = &arrayEntries.nbulkentries_val[j];
4637 MapHostToNetwork(vllist);
4638 EnumerateEntry(vllist);
4640 PrintLocked(vllist->flags);
4644 /* So we sort. First we must collect all the entries and keep
4647 else if (centries > 0) {
4649 /* malloc the first bulk entries array */
4650 tarraysize = centries * sizeof(struct nvldbentry);
4651 tarray = malloc(tarraysize);
4654 "Could not allocate enough space for the VLDB entries\n");
4657 memcpy((char*)tarray, arrayEntries.nbulkentries_val, tarraysize);
4659 /* Grow the tarray to keep the extra entries */
4660 parraysize = (centries * sizeof(struct nvldbentry));
4661 ttarray = realloc(tarray, tarraysize + parraysize);
4664 "Could not allocate enough space for the VLDB entries\n");
4670 memcpy(((char *)tarray) + tarraysize,
4671 (char *)arrayEntries.nbulkentries_val, parraysize);
4672 tarraysize += parraysize;
4676 /* Free the bulk array */
4677 xdr_free((xdrproc_t) xdr_nbulkentries, &arrayEntries);
4680 /* Here is where we now sort all the entries and print them */
4681 if (sort && (nentries > 0)) {
4682 qsort((char *)tarray, nentries, sizeof(struct nvldbentry),
4683 CompareVldbEntryByName);
4684 for (vllist = tarray, j = 0; j < nentries; j++, vllist++) {
4685 MapHostToNetwork(vllist);
4686 EnumerateEntry(vllist);
4688 PrintLocked(vllist->flags);
4694 fprintf(STDOUT, "\nTotal entries: %lu\n", (unsigned long)nentries);
4701 BackSys(struct cmd_syndesc *as, void *arock)
4704 afs_int32 apart = 0;
4705 afs_uint32 aserver = 0, aserver1;
4706 afs_int32 code, apart1;
4708 struct VldbListByAttributes attributes;
4709 nbulkentries arrayEntries;
4710 struct nvldbentry *vllist;
4714 int seenprefix, seenxprefix, exclude, ex, exp, noaction;
4715 afs_int32 totalBack = 0;
4716 afs_int32 totalFail = 0;
4720 struct cmd_item *ti;
4722 #ifndef HAVE_POSIX_REGEX
4726 memset(&attributes, 0, sizeof(struct VldbListByAttributes));
4727 attributes.Mask = 0;
4729 seenprefix = (as->parms[0].items ? 1 : 0);
4730 exclude = (as->parms[3].items ? 1 : 0);
4731 seenxprefix = (as->parms[4].items ? 1 : 0);
4732 noaction = (as->parms[5].items ? 1 : 0);
4734 if (as->parms[1].items) { /* -server */
4735 aserver = GetServer(as->parms[1].items->data);
4737 fprintf(STDERR, "vos: server '%s' not found in host table\n",
4738 as->parms[1].items->data);
4741 attributes.server = ntohl(aserver);
4742 attributes.Mask |= VLLIST_SERVER;
4745 if (as->parms[2].items) { /* -partition */
4746 apart = volutil_GetPartitionID(as->parms[2].items->data);
4748 fprintf(STDERR, "vos: could not interpret partition name '%s'\n",
4749 as->parms[2].items->data);
4752 attributes.partition = apart;
4753 attributes.Mask |= VLLIST_PARTITION;
4756 /* Check to make sure the prefix and xprefix expressions compile ok */
4758 for (ti = as->parms[0].items; ti; ti = ti->next) {
4759 if (strncmp(ti->data, "^", 1) == 0) {
4760 #ifdef HAVE_POSIX_REGEX
4764 code = regcomp(&re, ti->data, REG_NOSUB);
4766 regerror(code, &re, errbuf, sizeof errbuf);
4768 "Unrecognizable -prefix regular expression: '%s': %s\n",
4774 ccode = (char *)re_comp(ti->data);
4777 "Unrecognizable -prefix regular expression: '%s': %s\n",
4786 for (ti = as->parms[4].items; ti; ti = ti->next) {
4787 if (strncmp(ti->data, "^", 1) == 0) {
4788 #ifdef HAVE_POSIX_REGEX
4792 code = regcomp(&re, ti->data, REG_NOSUB);
4794 regerror(code, &re, errbuf, sizeof errbuf);
4796 "Unrecognizable -xprefix regular expression: '%s': %s\n",
4802 ccode = (char *)re_comp(ti->data);
4805 "Unrecognizable -xprefix regular expression: '%s': %s\n",
4814 memset(&arrayEntries, 0, sizeof(arrayEntries)); /* initialize to hint the stub to alloc space */
4815 vcode = VLDB_ListAttributes(&attributes, &nentries, &arrayEntries);
4817 fprintf(STDERR, "Could not access the VLDB for attributes\n");
4818 PrintError("", vcode);
4822 if (as->parms[1].items || as->parms[2].items || verbose) {
4823 fprintf(STDOUT, "%s up volumes",
4824 (noaction ? "Would have backed" : "Backing"));
4826 if (as->parms[1].items) {
4827 fprintf(STDOUT, " on server %s", as->parms[1].items->data);
4828 } else if (as->parms[2].items) {
4829 fprintf(STDOUT, " for all servers");
4832 if (as->parms[2].items) {
4833 MapPartIdIntoName(apart, pname);
4834 fprintf(STDOUT, " partition %s", pname);
4837 if (seenprefix || (!seenprefix && seenxprefix)) {
4838 ti = (seenprefix ? as->parms[0].items : as->parms[4].items);
4839 ex = (seenprefix ? exclude : !exclude);
4840 exp = (strncmp(ti->data, "^", 1) == 0);
4841 fprintf(STDOUT, " which %smatch %s '%s'", (ex ? "do not " : ""),
4842 (exp ? "expression" : "prefix"), ti->data);
4843 for (ti = ti->next; ti; ti = ti->next) {
4844 exp = (strncmp(ti->data, "^", 1) == 0);
4845 printf(" %sor %s '%s'", (ex ? "n" : ""),
4846 (exp ? "expression" : "prefix"), ti->data);
4850 if (seenprefix && seenxprefix) {
4851 ti = as->parms[4].items;
4852 exp = (strncmp(ti->data, "^", 1) == 0);
4853 fprintf(STDOUT, " %swhich match %s '%s'",
4854 (exclude ? "adding those " : "removing those "),
4855 (exp ? "expression" : "prefix"), ti->data);
4856 for (ti = ti->next; ti; ti = ti->next) {
4857 exp = (strncmp(ti->data, "^", 1) == 0);
4858 printf(" or %s '%s'", (exp ? "expression" : "prefix"),
4862 fprintf(STDOUT, " .. ");
4864 fprintf(STDOUT, "\n");
4868 for (j = 0; j < nentries; j++) { /* process each vldb entry */
4869 vllist = &arrayEntries.nbulkentries_val[j];
4872 for (ti = as->parms[0].items; ti; ti = ti->next) {
4873 if (strncmp(ti->data, "^", 1) == 0) {
4874 #ifdef HAVE_POSIX_REGEX
4878 /* XXX -- should just do the compile once! */
4879 code = regcomp(&re, ti->data, REG_NOSUB);
4881 regerror(code, &re, errbuf, sizeof errbuf);
4883 "Error in -prefix regular expression: '%s': %s\n",
4887 match = (regexec(&re, vllist->name, 0, NULL, 0) == 0);
4890 ccode = (char *)re_comp(ti->data);
4893 "Error in -prefix regular expression: '%s': %s\n",
4897 match = (re_exec(vllist->name) == 1);
4901 (strncmp(vllist->name, ti->data, strlen(ti->data)) ==
4911 /* Without the -exclude flag: If it matches the prefix, then
4912 * check if we want to exclude any from xprefix.
4913 * With the -exclude flag: If it matches the prefix, then
4914 * check if we want to add any from xprefix.
4916 if (match && seenxprefix) {
4917 for (ti = as->parms[4].items; ti; ti = ti->next) {
4918 if (strncmp(ti->data, "^", 1) == 0) {
4919 #ifdef HAVE_POSIX_REGEX
4923 /* XXX -- should just do the compile once! */
4924 code = regcomp(&re, ti->data, REG_NOSUB);
4926 regerror(code, &re, errbuf, sizeof errbuf);
4928 "Error in -xprefix regular expression: '%s': %s\n",
4932 if (regexec(&re, vllist->name, 0, NULL, 0) == 0)
4936 ccode = (char *)re_comp(ti->data);
4939 "Error in -xprefix regular expression: '%s': %s\n",
4943 if (re_exec(vllist->name) == 1) {
4949 if (strncmp(vllist->name, ti->data, strlen(ti->data)) ==
4959 match = !match; /* -exclude will reverse the match */
4961 continue; /* Skip if no match */
4963 /* Print list of volumes to backup */
4965 fprintf(STDOUT, " %s\n", vllist->name);
4969 if (!(vllist->flags & VLF_RWEXISTS)) {
4972 "Omitting to backup %s since RW volume does not exist \n",
4974 fprintf(STDOUT, "\n");
4980 avolid = vllist->volumeId[RWVOL];
4981 MapHostToNetwork(vllist);
4982 GetServerAndPart(vllist, RWVOL, &aserver1, &apart1, &previdx);
4983 if (aserver1 == -1 || apart1 == -1) {
4984 fprintf(STDOUT, "could not backup %s, invalid VLDB entry\n",
4990 same = VLDB_IsSameAddrs(aserver, aserver1, &error);
4993 "Failed to get info about server's %d address(es) from vlserver (err=%d); aborting call!\n",
4999 if ((aserver && !same) || (apart && (apart != apart1))) {
5002 "Omitting to backup %s since the RW is in a different location\n",
5008 time_t now = time(0);
5009 fprintf(STDOUT, "Creating backup volume for %s on %s",
5010 vllist->name, ctime(&now));
5014 code = UV_BackupVolume(aserver1, apart1, avolid);
5016 fprintf(STDOUT, "Could not backup %s\n", vllist->name);
5022 fprintf(STDOUT, "\n");
5024 } /* process each vldb entry */
5025 fprintf(STDOUT, "done\n");
5026 fprintf(STDOUT, "Total volumes backed up: %lu; failed to backup: %lu\n",
5027 (unsigned long)totalBack, (unsigned long)totalFail);
5029 xdr_free((xdrproc_t) xdr_nbulkentries, &arrayEntries);
5034 UnlockVLDB(struct cmd_syndesc *as, void *arock)
5037 afs_uint32 aserver = 0;
5040 struct VldbListByAttributes attributes;
5041 nbulkentries arrayEntries;
5042 struct nvldbentry *vllist;
5051 attributes.Mask = 0;
5053 if (as->parms[0].items) { /* server specified */
5054 aserver = GetServer(as->parms[0].items->data);
5056 fprintf(STDERR, "vos: server '%s' not found in host table\n",
5057 as->parms[0].items->data);
5060 attributes.server = ntohl(aserver);
5061 attributes.Mask |= VLLIST_SERVER;
5063 if (as->parms[1].items) { /* partition specified */
5064 apart = volutil_GetPartitionID(as->parms[1].items->data);
5066 fprintf(STDERR, "vos: could not interpret partition name '%s'\n",
5067 as->parms[1].items->data);
5070 if (!IsPartValid(apart, aserver, &code)) { /*check for validity of the partition */
5072 PrintError("", code);
5075 "vos : partition %s does not exist on the server\n",
5076 as->parms[1].items->data);
5079 attributes.partition = apart;
5080 attributes.Mask |= VLLIST_PARTITION;
5082 attributes.flag = VLOP_ALLOPERS;
5083 attributes.Mask |= VLLIST_FLAG;
5084 memset(&arrayEntries, 0, sizeof(arrayEntries)); /*initialize to hint the stub to alloc space */
5085 vcode = VLDB_ListAttributes(&attributes, &nentries, &arrayEntries);
5087 fprintf(STDERR, "Could not access the VLDB for attributes\n");
5088 PrintError("", vcode);
5091 for (j = 0; j < nentries; j++) { /* process each entry */
5092 vllist = &arrayEntries.nbulkentries_val[j];
5093 volid = vllist->volumeId[RWVOL];
5095 ubik_VL_ReleaseLock(cstruct, 0, volid, -1,
5096 LOCKREL_OPCODE | LOCKREL_AFSID |
5099 fprintf(STDERR, "Could not unlock entry for volume %s\n",
5101 PrintError("", vcode);
5106 MapPartIdIntoName(apart, pname);
5109 "Could not lock %lu VLDB entries of %lu locked entries\n",
5110 (unsigned long)totalE, (unsigned long)nentries);
5112 if (as->parms[0].items) {
5114 "Unlocked all the VLDB entries for volumes on server %s ",
5115 as->parms[0].items->data);
5116 if (as->parms[1].items) {
5117 MapPartIdIntoName(apart, pname);
5118 fprintf(STDOUT, "partition %s\n", pname);
5120 fprintf(STDOUT, "\n");
5122 } else if (as->parms[1].items) {
5123 MapPartIdIntoName(apart, pname);
5125 "Unlocked all the VLDB entries for volumes on partition %s on all servers\n",
5130 xdr_free((xdrproc_t) xdr_nbulkentries, &arrayEntries);
5135 PrintInt64Size(afs_uint64 in)
5139 static char output[16];
5141 SplitInt64(in,hi,lo);
5145 } else if (!(hi & 0xFFFFFC00)) {
5147 lo = (hi << 22) | (lo >> 10);
5148 } else if (!(hi & 0xFFF00000)) {
5150 lo = (hi << 12) | (lo >> 20);
5151 } else if (!(hi & 0xC0000000)) {
5153 lo = (hi << 2) | (lo >> 30);
5158 sprintf(output,"%u %s", lo, units);
5163 PartitionInfo(struct cmd_syndesc *as, void *arock)
5169 struct diskPartition64 partition;
5170 struct partList dummyPartList;
5172 int printSummary=0, sumPartitions=0;
5173 afs_uint64 sumFree, sumStorage;
5176 ZeroInt64(sumStorage);
5178 aserver = GetServer(as->parms[0].items->data);
5180 fprintf(STDERR, "vos: server '%s' not found in host table\n",
5181 as->parms[0].items->data);
5184 if (as->parms[1].items) {
5185 apart = volutil_GetPartitionID(as->parms[1].items->data);
5187 fprintf(STDERR, "vos: could not interpret partition name '%s'\n",
5188 as->parms[1].items->data);
5191 dummyPartList.partId[0] = apart;
5192 dummyPartList.partFlags[0] = PARTVALID;
5195 if (as->parms[2].items) {
5199 if (!IsPartValid(apart, aserver, &code)) { /*check for validity of the partition */
5201 PrintError("", code);
5204 "vos : partition %s does not exist on the server\n",
5205 as->parms[1].items->data);
5209 code = UV_ListPartitions(aserver, &dummyPartList, &cnt);
5211 PrintDiagnostics("listpart", code);
5215 for (i = 0; i < cnt; i++) {
5216 if (dummyPartList.partFlags[i] & PARTVALID) {
5217 MapPartIdIntoName(dummyPartList.partId[i], pname);
5218 code = UV_PartitionInfo64(aserver, pname, &partition);
5220 fprintf(STDERR, "Could not get information on partition %s\n",
5222 PrintError("", code);
5226 "Free space on partition %s: %" AFS_INT64_FMT " K blocks out of total %" AFS_INT64_FMT "\n",
5227 pname, partition.free, partition.minFree);
5229 AddUInt64(sumFree,partition.free,&sumFree);
5230 AddUInt64(sumStorage,partition.minFree,&sumStorage);
5235 "Summary: %s free out of ",
5236 PrintInt64Size(sumFree));
5238 "%s on %d partitions\n",
5239 PrintInt64Size(sumStorage),
5246 ChangeAddr(struct cmd_syndesc *as, void *arock)
5248 afs_int32 ip1, ip2, vcode;
5252 ip1 = GetServerNoresolve(as->parms[0].items->data);
5254 ip1 = GetServer(as->parms[0].items->data);
5256 fprintf(STDERR, "vos: invalid host address\n");
5260 if ((as->parms[1].items && as->parms[2].items)
5261 || (!as->parms[1].items && !as->parms[2].items)) {
5263 "vos: Must specify either '-newaddr <addr>' or '-remove' flag\n");
5267 if (as->parms[1].items) {
5269 ip2 = GetServerNoresolve(as->parms[1].items->data);
5271 ip2 = GetServer(as->parms[1].items->data);
5273 fprintf(STDERR, "vos: invalid host address\n");
5277 /* Play a trick here. If we are removing an address, ip1 will be -1
5278 * and ip2 will be the original address. This switch prevents an
5279 * older revision vlserver from removing the IP address.
5286 vcode = ubik_VL_ChangeAddr(cstruct, UBIK_CALL_NEW, ntohl(ip1), ntohl(ip2));
5288 char hoststr1[16], hoststr2[16];
5290 afs_inet_ntoa_r(ip2, hoststr2);
5291 fprintf(STDERR, "Could not remove server %s from the VLDB\n",
5293 if (vcode == VL_NOENT) {
5295 "vlserver does not support the remove flag or ");
5298 afs_inet_ntoa_r(ip1, hoststr1);
5299 afs_inet_ntoa_r(ip2, hoststr2);
5300 fprintf(STDERR, "Could not change server %s to server %s\n",
5301 hoststr1, hoststr2);
5303 PrintError("", vcode);
5308 fprintf(STDOUT, "Removed server %s from the VLDB\n",
5309 as->parms[0].items->data);
5311 fprintf(STDOUT, "Changed server %s to server %s\n",
5312 as->parms[0].items->data, as->parms[1].items->data);
5318 print_addrs(const bulkaddrs * addrs, afsUUID * m_uuid, int nentries,
5326 afsUUID_to_string(m_uuid, buf, sizeof(buf));
5327 printf("UUID: %s\n", buf);
5330 /* print out the list of all the server */
5331 addrp = (afs_uint32 *) addrs->bulkaddrs_val;
5332 for (i = 0; i < nentries; i++, addrp++) {
5333 *addrp = htonl(*addrp);
5336 printf("%s\n", afs_inet_ntoa_r(*addrp, hoststr));
5338 printf("%s\n", hostutil_GetNameByINet(*addrp));
5349 ListAddrs(struct cmd_syndesc *as, void *arock)
5351 afs_int32 vcode, m_uniq=0;
5352 afs_int32 i, printuuid = 0;
5353 struct VLCallBack vlcb;
5356 ListAddrByAttributes m_attrs;
5357 afsUUID m_uuid, askuuid;
5358 afs_int32 m_nentries;
5360 if (as->parms[0].items && as->parms[1].items) {
5361 fprintf(STDERR, "vos: Can't use the -uuid and -host flags together\n");
5365 memset(&m_attrs, 0, sizeof(struct ListAddrByAttributes));
5366 memset(&askuuid, 0, sizeof(afsUUID));
5367 if (as->parms[0].items) {
5369 if (afsUUID_from_string(as->parms[0].items->data, &askuuid) < 0) {
5370 fprintf(STDERR, "vos: invalid UUID '%s'\n",
5371 as->parms[0].items->data);
5374 m_attrs.Mask = VLADDR_UUID;
5375 m_attrs.uuid = askuuid;
5376 } else if (as->parms[1].items) {
5380 he = hostutil_GetHostByName((char *)as->parms[1].items->data);
5382 fprintf(STDERR, "vos: Can't get host info for '%s'\n",
5383 as->parms[1].items->data);
5386 memcpy(&saddr, he->h_addr, 4);
5387 m_attrs.Mask = VLADDR_IPADDR;
5388 m_attrs.ipaddr = ntohl(saddr);
5391 m_attrs.Mask = VLADDR_INDEX;
5394 if (as->parms[2].items) {
5398 memset(&m_addrs, 0, sizeof(bulkaddrs));
5399 memset(&vlcb, 0, sizeof(struct VLCallBack));
5402 ubik_VL_GetAddrs(cstruct, UBIK_CALL_NEW, 0, 0, &vlcb, &nentries,
5405 fprintf(STDERR, "vos: could not list the server addresses\n");
5406 PrintError("", vcode);
5410 for (i = 1, m_nentries = 0; nentries; i++) {
5413 xdr_free((xdrproc_t)xdr_bulkaddrs, &m_addrs); /* reset addr list */
5415 ubik_VL_GetAddrsU(cstruct, UBIK_CALL_NEW, &m_attrs, &m_uuid,
5416 &m_uniq, &m_nentries, &m_addrs);
5418 case 0: /* success */
5419 print_addrs(&m_addrs, &m_uuid, m_nentries, printuuid);
5424 if (m_attrs.Mask == VLADDR_UUID) {
5425 fprintf(STDERR, "vos: no entry for UUID '%s' found in VLDB\n",
5426 as->parms[0].items->data);
5428 } else if (m_attrs.Mask == VLADDR_IPADDR) {
5429 fprintf(STDERR, "vos: no entry for host '%s' [0x%08x] found in VLDB\n",
5430 as->parms[1].items->data, m_attrs.ipaddr);
5435 case VL_INDEXERANGE:
5436 vcode = 0; /* not an error, just means we're done */
5439 default: /* any other error */
5440 fprintf(STDERR, "vos: could not list the server addresses\n");
5441 PrintError("", vcode);
5445 /* if -uuid or -host, only list one response */
5446 if (as->parms[1].items || as->parms[0].items)
5451 xdr_free((xdrproc_t)xdr_bulkaddrs, &m_addrs);
5457 SetAddrs(struct cmd_syndesc *as, void *arock)
5462 afs_uint32 FS_HostAddrs_HBO[ADDRSPERSITE];
5464 memset(&m_addrs, 0, sizeof(bulkaddrs));
5465 memset(&askuuid, 0, sizeof(afsUUID));
5466 if (as->parms[0].items) {
5468 if (afsUUID_from_string(as->parms[0].items->data, &askuuid) < 0) {
5469 fprintf(STDERR, "vos: invalid UUID '%s'\n",
5470 as->parms[0].items->data);
5474 if (as->parms[1].items) {
5476 struct cmd_item *ti;
5480 for (ti = as->parms[1].items; ti && i < ADDRSPERSITE; ti = ti->next) {
5483 saddr = GetServerNoresolve(ti->data);
5485 saddr = GetServer(ti->data);
5488 fprintf(STDERR, "vos: Can't get host info for '%s'\n",
5492 /* Convert it to host byte order */
5493 FS_HostAddrs_HBO[i] = ntohl(saddr);
5496 m_addrs.bulkaddrs_len = i;
5497 m_addrs.bulkaddrs_val = FS_HostAddrs_HBO;
5500 vcode = ubik_VL_RegisterAddrs(cstruct, 0, &askuuid, 0, &m_addrs);
5503 if (vcode == VL_MULTIPADDR) {
5504 fprintf(STDERR, "vos: VL_RegisterAddrs rpc failed; The IP address exists on a different server; repair it\n");
5505 } else if (vcode == RXGEN_OPCODE) {
5506 fprintf(STDERR, "vlserver doesn't support VL_RegisterAddrs rpc; ignored\n");
5508 fprintf(STDERR, "vos: VL_RegisterAddrs rpc failed\n");
5510 PrintError("", vcode);
5514 fprintf(STDOUT, "vos: Changed UUID with addresses:\n");
5515 print_addrs(&m_addrs, &askuuid, m_addrs.bulkaddrs_len, 1);
5521 LockEntry(struct cmd_syndesc *as, void *arock)
5524 afs_int32 vcode, err;
5526 avolid = vsu_GetVolumeID(as->parms[0].items->data, cstruct, &err);
5529 PrintError("", err);
5531 fprintf(STDERR, "vos: can't find volume '%s'\n",
5532 as->parms[0].items->data);
5535 vcode = ubik_VL_SetLock(cstruct, 0, avolid, -1, VLOP_DELETE);
5537 fprintf(STDERR, "Could not lock VLDB entry for volume %s\n",
5538 as->parms[0].items->data);
5539 PrintError("", vcode);
5542 fprintf(STDOUT, "Locked VLDB entry for volume %s\n",
5543 as->parms[0].items->data);
5548 ConvertRO(struct cmd_syndesc *as, void *arock)
5550 afs_int32 partition = -1;
5553 afs_int32 code, i, same;
5554 struct nvldbentry entry;
5556 afs_uint32 rwserver = 0;
5557 afs_int32 rwpartition = 0;
5558 afs_uint32 roserver = 0;
5559 afs_int32 ropartition = 0;
5563 server = GetServer(as->parms[0].items->data);
5565 fprintf(STDERR, "vos: host '%s' not found in host table\n",
5566 as->parms[0].items->data);
5569 partition = volutil_GetPartitionID(as->parms[1].items->data);
5570 if (partition < 0) {
5571 fprintf(STDERR, "vos: could not interpret partition name '%s'\n",
5572 as->parms[1].items->data);
5575 if (!IsPartValid(partition, server, &code)) {
5577 PrintError("", code);
5580 "vos : partition %s does not exist on the server\n",
5581 as->parms[1].items->data);
5584 volid = vsu_GetVolumeID(as->parms[2].items->data, cstruct, &code);
5587 PrintError("", code);
5589 fprintf(STDERR, "Unknown volume ID or name '%s'\n",
5590 as->parms[2].items->data);
5593 if (as->parms[3].items)
5596 memset(&entry, 0, sizeof(entry));
5597 vcode = VLDB_GetEntryByID(volid, -1, &entry);
5600 "Could not fetch the entry for volume %lu from VLDB\n",
5601 (unsigned long)volid);
5602 PrintError("convertROtoRW ", vcode);
5606 /* use RO volid even if user specified RW or BK volid */
5607 if (volid != entry.volumeId[ROVOL])
5608 volid = entry.volumeId[ROVOL];
5610 MapHostToNetwork(&entry);
5611 for (i = 0; i < entry.nServers; i++) {
5612 if (entry.serverFlags[i] & VLSF_RWVOL) {
5613 rwserver = entry.serverNumber[i];
5614 rwpartition = entry.serverPartition[i];
5617 } else if ((entry.serverFlags[i] & VLSF_ROVOL) && !roserver) {
5618 same = VLDB_IsSameAddrs(server, entry.serverNumber[i], &code);
5621 "Failed to get info about server's %d address(es) from vlserver (err=%d); aborting call!\n",
5626 roserver = entry.serverNumber[i];
5627 ropartition = entry.serverPartition[i];
5634 fprintf(STDERR, "Warning: RO volume didn't exist in vldb!\n");
5636 if (roserver && (ropartition != partition)) {
5638 "Warning: RO volume should be in partition %d instead of %d (vldb)\n",
5639 ropartition, partition);
5644 "VLDB indicates that a RW volume exists already on %s in partition %s.\n",
5645 hostutil_GetNameByINet(rwserver),
5646 volutil_PartitionName(rwpartition));
5648 fprintf(STDERR, "Overwrite this VLDB entry? [y|n] (n)\n");
5650 while (!(dc == EOF || dc == '\n'))
5651 dc = getchar(); /* goto end of line */
5652 if ((c != 'y') && (c != 'Y')) {
5653 fprintf(STDERR, "aborted.\n");
5659 code = UV_ConvertRO(server, partition, volid, &entry);
5665 Sizes(struct cmd_syndesc *as, void *arock)
5669 afs_int32 apart, voltype, fromdate = 0, code, err, i;
5670 struct nvldbentry entry;
5671 volintSize vol_size;
5673 rx_SetRxDeadTime(60 * 10);
5674 for (i = 0; i < MAXSERVERS; i++) {
5675 struct rx_connection *rxConn = ubik_GetRPCConn(cstruct, i);
5678 rx_SetConnDeadTime(rxConn, rx_connDeadTime);
5679 if (rx_ServiceOf(rxConn))
5680 rx_ServiceOf(rxConn)->connDeadTime = rx_connDeadTime;
5683 avolid = vsu_GetVolumeID(as->parms[0].items->data, cstruct, &err);
5686 PrintError("", err);
5688 fprintf(STDERR, "vos: can't find volume '%s'\n",
5689 as->parms[0].items->data);
5693 if (as->parms[1].items || as->parms[2].items) {
5694 if (!as->parms[1].items || !as->parms[2].items) {
5696 "Must specify both -server and -partition options\n");
5699 aserver = GetServer(as->parms[2].items->data);
5701 fprintf(STDERR, "Invalid server name\n");
5704 apart = volutil_GetPartitionID(as->parms[1].items->data);
5706 fprintf(STDERR, "Invalid partition name\n");
5710 code = GetVolumeInfo(avolid, &aserver, &apart, &voltype, &entry);
5717 if (as->parms[4].items && strcmp(as->parms[4].items->data, "0")) {
5718 code = ktime_DateToInt32(as->parms[4].items->data, &fromdate);
5720 fprintf(STDERR, "vos: failed to parse date '%s' (error=%d))\n",
5721 as->parms[4].items->data, code);
5726 fprintf(STDOUT, "Volume: %s\n", as->parms[0].items->data);
5728 if (as->parms[3].items) { /* do the dump estimate */
5729 vol_size.dump_size = 0;
5730 code = UV_GetSize(avolid, aserver, apart, fromdate, &vol_size);
5732 PrintDiagnostics("size", code);
5735 /* presumably the size info is now gathered in pntr */
5736 /* now we display it */
5738 fprintf(STDOUT, "dump_size: %llu\n", vol_size.dump_size);
5747 EndTrans(struct cmd_syndesc *as, void *arock)
5750 afs_int32 code, tid, rcode;
5751 struct rx_connection *aconn;
5753 server = GetServer(as->parms[0].items->data);
5755 fprintf(STDERR, "vos: host '%s' not found in host table\n",
5756 as->parms[0].items->data);
5760 code = util_GetInt32(as->parms[1].items->data, &tid);
5762 fprintf(STDERR, "vos: bad integer specified for transaction ID.\n");
5766 aconn = UV_Bind(server, AFSCONF_VOLUMEPORT);
5767 code = AFSVolEndTrans(aconn, tid, &rcode);
5773 PrintDiagnostics("endtrans", code);
5781 PrintDiagnostics(char *astring, afs_int32 acode)
5786 "You are not authorized to perform the 'vos %s' command (%d)\n",
5790 fprintf(STDERR, "Error in vos %s command.\n", astring);
5791 fprintf(STDERR, "Clone volume is not in the same partition as the read-write volume.\n");
5794 fprintf(STDERR, "Error in vos %s command.\n", astring);
5795 PrintError("", acode);
5804 win32_enableCrypt(void)
5811 /* Look up configuration parameters in Registry */
5812 code = RegOpenKeyEx(HKEY_LOCAL_MACHINE, AFSREG_CLT_SVC_PARAM_SUBKEY,
5813 0, (IsWow64()?KEY_WOW64_64KEY:0)|KEY_QUERY_VALUE, &parmKey);
5814 if (code != ERROR_SUCCESS) {
5815 dummyLen = sizeof(cryptall);
5816 RegQueryValueEx(parmKey, "SecurityLevel", NULL, NULL,
5817 (BYTE *) &cryptall, &dummyLen);
5819 RegCloseKey (parmKey);
5823 #endif /* AFS_NT40_ENV */
5826 MyBeforeProc(struct cmd_syndesc *as, void *arock)
5832 /* Initialize the ubik_client connection */
5833 rx_SetRxDeadTime(90);
5835 secFlags = AFSCONF_SECOPTS_FALLBACK_NULL;
5838 if (as->parms[COMMONPARM_OFFSET_CELL].items) /* if -cell specified */
5839 tcell = as->parms[COMMONPARM_OFFSET_CELL].items->data;
5841 if (as->parms[COMMONPARM_OFFSET_NOAUTH].items)
5842 secFlags |= AFSCONF_SECOPTS_NOAUTH;
5844 if (as->parms[COMMONPARM_OFFSET_LOCALAUTH].items) { /* -localauth specified */
5845 secFlags |= AFSCONF_SECOPTS_LOCALAUTH;
5846 confdir = AFSDIR_SERVER_ETC_DIRPATH;
5849 if (as->parms[COMMONPARM_OFFSET_ENCRYPT].items /* -encrypt specified */
5851 || win32_enableCrypt()
5852 #endif /* AFS_NT40_ENV */
5854 secFlags |= AFSCONF_SECOPTS_ALWAYSENCRYPT;
5856 if (as->parms[COMMONPARM_OFFSET_CONFIG].items) /* -config flag set */
5857 confdir = as->parms[COMMONPARM_OFFSET_CONFIG].items->data;
5859 if ((code = vsu_ClientInit(confdir, tcell, secFlags, UV_SetSecurity,
5861 fprintf(STDERR, "could not initialize VLDB library (code=%lu) \n",
5862 (unsigned long)code);
5866 if (as->parms[COMMONPARM_OFFSET_VERBOSE].items) /* -verbose flag set */
5870 if (as->parms[COMMONPARM_OFFSET_NORESOLVE].items) /* -noresolve flag set */
5881 /* this sucks but it works for now.
5886 #include "AFS_component_version_number.c"
5889 main(int argc, char **argv)
5893 struct cmd_syndesc *ts;
5895 #ifdef AFS_AIX32_ENV
5897 * The following signal action for AIX is necessary so that in case of a
5898 * crash (i.e. core is generated) we can include the user's data section
5899 * in the core dump. Unfortunately, by default, only a partial core is
5900 * generated which, in many cases, isn't too useful.
5902 struct sigaction nsa;
5904 sigemptyset(&nsa.sa_mask);
5905 nsa.sa_handler = SIG_DFL;
5906 nsa.sa_flags = SA_FULLDUMP;
5907 sigaction(SIGSEGV, &nsa, NULL);
5910 confdir = AFSDIR_CLIENT_ETC_DIRPATH;
5912 cmd_SetBeforeProc(MyBeforeProc, NULL);
5914 ts = cmd_CreateSyntax("create", CreateVolume, NULL, 0, "create a new volume");
5915 cmd_AddParm(ts, "-server", CMD_SINGLE, 0, "machine name");
5916 cmd_AddParm(ts, "-partition", CMD_SINGLE, 0, "partition name");
5917 cmd_AddParm(ts, "-name", CMD_SINGLE, 0, "volume name");
5918 cmd_AddParm(ts, "-maxquota", CMD_SINGLE, CMD_OPTIONAL,
5919 "initial quota (KB)");
5920 cmd_AddParm(ts, "-id", CMD_SINGLE, CMD_OPTIONAL, "volume ID");
5921 cmd_AddParm(ts, "-roid", CMD_SINGLE, CMD_OPTIONAL, "readonly volume ID");
5923 cmd_AddParm(ts, "-minquota", CMD_SINGLE, CMD_OPTIONAL, "");
5927 ts = cmd_CreateSyntax("remove", DeleteVolume, NULL, 0, "delete a volume");
5928 cmd_AddParm(ts, "-server", CMD_SINGLE, CMD_OPTIONAL, "machine name");
5929 cmd_AddParm(ts, "-partition", CMD_SINGLE, CMD_OPTIONAL, "partition name");
5930 cmd_AddParm(ts, "-id", CMD_SINGLE, 0, "volume name or ID");
5934 ts = cmd_CreateSyntax("move", MoveVolume, NULL, 0, "move a volume");
5935 cmd_AddParm(ts, "-id", CMD_SINGLE, 0, "volume name or ID");
5936 cmd_AddParm(ts, "-fromserver", CMD_SINGLE, 0, "machine name on source");
5937 cmd_AddParm(ts, "-frompartition", CMD_SINGLE, 0,
5938 "partition name on source");
5939 cmd_AddParm(ts, "-toserver", CMD_SINGLE, 0,
5940 "machine name on destination");
5941 cmd_AddParm(ts, "-topartition", CMD_SINGLE, 0,
5942 "partition name on destination");
5943 cmd_AddParm(ts, "-live", CMD_FLAG, CMD_OPTIONAL,
5944 "copy live volume without cloning");
5947 ts = cmd_CreateSyntax("copy", CopyVolume, NULL, 0, "copy a volume");
5948 cmd_AddParm(ts, "-id", CMD_SINGLE, 0, "volume name or ID on source");
5949 cmd_AddParm(ts, "-fromserver", CMD_SINGLE, 0, "machine name on source");
5950 cmd_AddParm(ts, "-frompartition", CMD_SINGLE, 0,
5951 "partition name on source");
5952 cmd_AddParm(ts, "-toname", CMD_SINGLE, 0, "volume name on destination");
5953 cmd_AddParm(ts, "-toserver", CMD_SINGLE, 0,
5954 "machine name on destination");
5955 cmd_AddParm(ts, "-topartition", CMD_SINGLE, 0,
5956 "partition name on destination");
5957 cmd_AddParm(ts, "-offline", CMD_FLAG, CMD_OPTIONAL,
5958 "leave new volume offline");
5959 cmd_AddParm(ts, "-readonly", CMD_FLAG, CMD_OPTIONAL,
5960 "make new volume read-only");
5961 cmd_AddParm(ts, "-live", CMD_FLAG, CMD_OPTIONAL,
5962 "copy live volume without cloning");
5965 ts = cmd_CreateSyntax("shadow", ShadowVolume, NULL, 0,
5966 "make or update a shadow volume");
5967 cmd_AddParm(ts, "-id", CMD_SINGLE, 0, "volume name or ID on source");
5968 cmd_AddParm(ts, "-fromserver", CMD_SINGLE, 0, "machine name on source");
5969 cmd_AddParm(ts, "-frompartition", CMD_SINGLE, 0,
5970 "partition name on source");
5971 cmd_AddParm(ts, "-toserver", CMD_SINGLE, 0,
5972 "machine name on destination");
5973 cmd_AddParm(ts, "-topartition", CMD_SINGLE, 0,
5974 "partition name on destination");
5975 cmd_AddParm(ts, "-toname", CMD_SINGLE, CMD_OPTIONAL,
5976 "volume name on destination");
5977 cmd_AddParm(ts, "-toid", CMD_SINGLE, CMD_OPTIONAL,
5978 "volume ID on destination");
5979 cmd_AddParm(ts, "-offline", CMD_FLAG, CMD_OPTIONAL,
5980 "leave shadow volume offline");
5981 cmd_AddParm(ts, "-readonly", CMD_FLAG, CMD_OPTIONAL,
5982 "make shadow volume read-only");
5983 cmd_AddParm(ts, "-live", CMD_FLAG, CMD_OPTIONAL,
5984 "copy live volume without cloning");
5985 cmd_AddParm(ts, "-incremental", CMD_FLAG, CMD_OPTIONAL,
5986 "do incremental update if target exists");
5989 ts = cmd_CreateSyntax("backup", BackupVolume, NULL, 0,
5990 "make backup of a volume");
5991 cmd_AddParm(ts, "-id", CMD_SINGLE, 0, "volume name or ID");
5994 ts = cmd_CreateSyntax("clone", CloneVolume, NULL, 0,
5995 "make clone of a volume");
5996 cmd_AddParm(ts, "-id", CMD_SINGLE, 0, "volume name or ID");
5997 cmd_AddParm(ts, "-server", CMD_SINGLE, CMD_OPTIONAL, "server");
5998 cmd_AddParm(ts, "-partition", CMD_SINGLE, CMD_OPTIONAL, "partition");
5999 cmd_AddParm(ts, "-toname", CMD_SINGLE, CMD_OPTIONAL,
6000 "volume name on destination");
6001 cmd_AddParm(ts, "-toid", CMD_SINGLE, CMD_OPTIONAL,
6002 "volume ID on destination");
6003 cmd_AddParm(ts, "-offline", CMD_FLAG, CMD_OPTIONAL,
6004 "leave clone volume offline");
6005 cmd_AddParm(ts, "-readonly", CMD_FLAG, CMD_OPTIONAL,
6006 "make clone volume read-only, not readwrite");
6007 cmd_AddParm(ts, "-readwrite", CMD_FLAG, CMD_OPTIONAL,
6008 "make clone volume readwrite, not read-only");
6011 ts = cmd_CreateSyntax("release", ReleaseVolume, NULL, 0, "release a volume");
6012 cmd_AddParm(ts, "-id", CMD_SINGLE, 0, "volume name or ID");
6013 cmd_AddParm(ts, "-force", CMD_FLAG, CMD_OPTIONAL,
6014 "force a complete release and full dumps");
6015 cmd_AddParmAlias(ts, 1, "-f"); /* original force option */
6016 cmd_AddParm(ts, "-stayonline", CMD_FLAG, CMD_OPTIONAL,
6017 "release to cloned temp vol, then clone back to repsite RO");
6018 cmd_AddParm(ts, "-force-reclone", CMD_FLAG, CMD_OPTIONAL,
6019 "force a reclone and complete release with incremental dumps");
6022 ts = cmd_CreateSyntax("dump", DumpVolumeCmd, NULL, 0, "dump a volume");
6023 cmd_AddParm(ts, "-id", CMD_SINGLE, 0, "volume name or ID");
6024 cmd_AddParm(ts, "-time", CMD_SINGLE, CMD_OPTIONAL, "dump from time");
6025 cmd_AddParm(ts, "-file", CMD_SINGLE, CMD_OPTIONAL, "dump file");
6026 cmd_AddParm(ts, "-server", CMD_SINGLE, CMD_OPTIONAL, "server");
6027 cmd_AddParm(ts, "-partition", CMD_SINGLE, CMD_OPTIONAL, "partition");
6028 cmd_AddParm(ts, "-clone", CMD_FLAG, CMD_OPTIONAL,
6029 "dump a clone of the volume");
6030 cmd_AddParm(ts, "-omitdirs", CMD_FLAG, CMD_OPTIONAL,
6031 "omit unchanged directories from an incremental dump");
6034 ts = cmd_CreateSyntax("restore", RestoreVolumeCmd, NULL, 0,
6035 "restore a volume");
6036 cmd_AddParm(ts, "-server", CMD_SINGLE, 0, "machine name");
6037 cmd_AddParm(ts, "-partition", CMD_SINGLE, 0, "partition name");
6038 cmd_AddParm(ts, "-name", CMD_SINGLE, 0, "name of volume to be restored");
6039 cmd_AddParm(ts, "-file", CMD_SINGLE, CMD_OPTIONAL, "dump file");
6040 cmd_AddParm(ts, "-id", CMD_SINGLE, CMD_OPTIONAL, "volume ID");
6041 cmd_AddParm(ts, "-overwrite", CMD_SINGLE, CMD_OPTIONAL,
6042 "abort | full | incremental");
6043 cmd_AddParm(ts, "-offline", CMD_FLAG, CMD_OPTIONAL,
6044 "leave restored volume offline");
6045 cmd_AddParm(ts, "-readonly", CMD_FLAG, CMD_OPTIONAL,
6046 "make restored volume read-only");
6047 cmd_AddParm(ts, "-creation", CMD_SINGLE, CMD_OPTIONAL,
6048 "dump | keep | new");
6049 cmd_AddParm(ts, "-lastupdate", CMD_SINGLE, CMD_OPTIONAL,
6050 "dump | keep | new");
6051 cmd_AddParm(ts, "-nodelete", CMD_FLAG, CMD_OPTIONAL,
6052 "do not delete old site when restoring to a new site");
6055 ts = cmd_CreateSyntax("unlock", LockReleaseCmd, NULL, 0,
6056 "release lock on VLDB entry for a volume");
6057 cmd_AddParm(ts, "-id", CMD_SINGLE, 0, "volume name or ID");
6060 ts = cmd_CreateSyntax("changeloc", ChangeLocation, NULL, 0,
6061 "change an RW volume's location in the VLDB");
6062 cmd_AddParm(ts, "-server", CMD_SINGLE, 0,
6063 "machine name for new location");
6064 cmd_AddParm(ts, "-partition", CMD_SINGLE, 0,
6065 "partition name for new location");
6066 cmd_AddParm(ts, "-id", CMD_SINGLE, 0, "volume name or ID");
6069 ts = cmd_CreateSyntax("addsite", AddSite, NULL, 0, "add a replication site");
6070 cmd_AddParm(ts, "-server", CMD_SINGLE, 0, "machine name for new site");
6071 cmd_AddParm(ts, "-partition", CMD_SINGLE, 0,
6072 "partition name for new site");
6073 cmd_AddParm(ts, "-id", CMD_SINGLE, 0, "volume name or ID");
6074 cmd_AddParm(ts, "-roid", CMD_SINGLE, CMD_OPTIONAL, "volume name or ID for RO");
6075 cmd_AddParm(ts, "-valid", CMD_FLAG, CMD_OPTIONAL, "publish as an up-to-date site in VLDB");
6078 ts = cmd_CreateSyntax("remsite", RemoveSite, NULL, 0,
6079 "remove a replication site");
6080 cmd_AddParm(ts, "-server", CMD_SINGLE, 0, "machine name");
6081 cmd_AddParm(ts, "-partition", CMD_SINGLE, 0, "partition name");
6082 cmd_AddParm(ts, "-id", CMD_SINGLE, 0, "volume name or ID");
6085 ts = cmd_CreateSyntax("listpart", ListPartitions, NULL, 0, "list partitions");
6086 cmd_AddParm(ts, "-server", CMD_SINGLE, 0, "machine name");
6089 ts = cmd_CreateSyntax("listvol", ListVolumes, NULL, 0,
6090 "list volumes on server (bypass VLDB)");
6091 cmd_AddParm(ts, "-server", CMD_SINGLE, 0, "machine name");
6092 cmd_AddParm(ts, "-partition", CMD_SINGLE, CMD_OPTIONAL, "partition name");
6093 cmd_AddParm(ts, "-fast", CMD_FLAG, CMD_OPTIONAL, "minimal listing");
6094 cmd_AddParm(ts, "-long", CMD_FLAG, CMD_OPTIONAL,
6095 "list all normal volume fields");
6096 cmd_AddParm(ts, "-quiet", CMD_FLAG, CMD_OPTIONAL,
6097 "generate minimal information");
6098 cmd_AddParm(ts, "-extended", CMD_FLAG, CMD_OPTIONAL,
6099 "list extended volume fields");
6100 cmd_AddParm(ts, "-format", CMD_FLAG, CMD_OPTIONAL,
6101 "machine readable format");
6104 ts = cmd_CreateSyntax("syncvldb", SyncVldb, NULL, 0,
6105 "synchronize VLDB with server");
6106 cmd_AddParm(ts, "-server", CMD_SINGLE, CMD_OPTIONAL, "machine name");
6107 cmd_AddParm(ts, "-partition", CMD_SINGLE, CMD_OPTIONAL, "partition name");
6108 cmd_AddParm(ts, "-volume", CMD_SINGLE, CMD_OPTIONAL, "volume name or ID");
6109 cmd_AddParm(ts, "-dryrun", CMD_FLAG, CMD_OPTIONAL, "list what would be done, don't do it");
6112 ts = cmd_CreateSyntax("syncserv", SyncServer, NULL, 0,
6113 "synchronize server with VLDB");
6114 cmd_AddParm(ts, "-server", CMD_SINGLE, 0, "machine name");
6115 cmd_AddParm(ts, "-partition", CMD_SINGLE, CMD_OPTIONAL, "partition name");
6116 cmd_AddParm(ts, "-dryrun", CMD_FLAG, CMD_OPTIONAL, "list what would be done, don't do it");
6119 ts = cmd_CreateSyntax("examine", ExamineVolume, NULL, 0,
6120 "everything about the volume");
6121 cmd_AddParm(ts, "-id", CMD_SINGLE, 0, "volume name or ID");
6122 cmd_AddParm(ts, "-extended", CMD_FLAG, CMD_OPTIONAL,
6123 "list extended volume fields");
6124 cmd_AddParm(ts, "-format", CMD_FLAG, CMD_OPTIONAL,
6125 "machine readable format");
6127 cmd_CreateAlias(ts, "volinfo");
6128 cmd_CreateAlias(ts, "e");
6130 ts = cmd_CreateSyntax("setfields", SetFields, NULL, 0,
6131 "change volume info fields");
6132 cmd_AddParm(ts, "-id", CMD_SINGLE, 0, "volume name or ID");
6133 cmd_AddParm(ts, "-maxquota", CMD_SINGLE, CMD_OPTIONAL, "quota (KB)");
6134 cmd_AddParm(ts, "-clearuse", CMD_FLAG, CMD_OPTIONAL, "clear dayUse");
6135 cmd_AddParm(ts, "-clearVolUpCounter", CMD_FLAG, CMD_OPTIONAL, "clear volUpdateCounter");
6138 ts = cmd_CreateSyntax("offline", volOffline, NULL, 0, "force the volume status to offline");
6139 cmd_AddParm(ts, "-server", CMD_SINGLE, 0, "server name");
6140 cmd_AddParm(ts, "-partition", CMD_SINGLE, 0, "partition name");
6141 cmd_AddParm(ts, "-id", CMD_SINGLE, 0, "volume name or ID");
6142 cmd_AddParm(ts, "-sleep", CMD_SINGLE, CMD_OPTIONAL, "seconds to sleep");
6143 cmd_AddParm(ts, "-busy", CMD_FLAG, CMD_OPTIONAL, "busy volume");
6146 ts = cmd_CreateSyntax("online", volOnline, NULL, 0, "force the volume status to online");
6147 cmd_AddParm(ts, "-server", CMD_SINGLE, 0, "server name");
6148 cmd_AddParm(ts, "-partition", CMD_SINGLE, 0, "partition name");
6149 cmd_AddParm(ts, "-id", CMD_SINGLE, 0, "volume name or ID");
6152 ts = cmd_CreateSyntax("zap", VolumeZap, NULL, 0,
6153 "delete the volume, don't bother with VLDB");
6154 cmd_AddParm(ts, "-server", CMD_SINGLE, 0, "machine name");
6155 cmd_AddParm(ts, "-partition", CMD_SINGLE, 0, "partition name");
6156 cmd_AddParm(ts, "-id", CMD_SINGLE, 0, "volume ID");
6157 cmd_AddParm(ts, "-force", CMD_FLAG, CMD_OPTIONAL,
6158 "force deletion of bad volumes");
6159 cmd_AddParm(ts, "-backup", CMD_FLAG, CMD_OPTIONAL,
6160 "also delete backup volume if one is found");
6163 ts = cmd_CreateSyntax("status", VolserStatus, NULL, 0,
6164 "report on volser status");
6165 cmd_AddParm(ts, "-server", CMD_SINGLE, 0, "machine name");
6168 ts = cmd_CreateSyntax("rename", RenameVolume, NULL, 0, "rename a volume");
6169 cmd_AddParm(ts, "-oldname", CMD_SINGLE, 0, "old volume name ");
6170 cmd_AddParm(ts, "-newname", CMD_SINGLE, 0, "new volume name ");
6173 ts = cmd_CreateSyntax("listvldb", ListVLDB, NULL, 0,
6174 "list volumes in the VLDB");
6175 cmd_AddParm(ts, "-name", CMD_SINGLE, CMD_OPTIONAL, "volume name or ID");
6176 cmd_AddParm(ts, "-server", CMD_SINGLE, CMD_OPTIONAL, "machine name");
6177 cmd_AddParm(ts, "-partition", CMD_SINGLE, CMD_OPTIONAL, "partition name");
6178 cmd_AddParm(ts, "-locked", CMD_FLAG, CMD_OPTIONAL, "locked volumes only");
6179 cmd_AddParm(ts, "-quiet", CMD_FLAG, CMD_OPTIONAL,
6180 "generate minimal information");
6181 cmd_AddParm(ts, "-nosort", CMD_FLAG, CMD_OPTIONAL,
6182 "do not alphabetically sort the volume names");
6185 ts = cmd_CreateSyntax("backupsys", BackSys, NULL, 0, "en masse backups");
6186 cmd_AddParm(ts, "-prefix", CMD_LIST, CMD_OPTIONAL,
6187 "common prefix on volume(s)");
6188 cmd_AddParm(ts, "-server", CMD_SINGLE, CMD_OPTIONAL, "machine name");
6189 cmd_AddParm(ts, "-partition", CMD_SINGLE, CMD_OPTIONAL, "partition name");
6190 cmd_AddParm(ts, "-exclude", CMD_FLAG, CMD_OPTIONAL,
6191 "exclude common prefix volumes");
6192 cmd_AddParm(ts, "-xprefix", CMD_LIST, CMD_OPTIONAL,
6193 "negative prefix on volume(s)");
6194 cmd_AddParm(ts, "-dryrun", CMD_FLAG, CMD_OPTIONAL, "list what would be done, don't do it");
6197 ts = cmd_CreateSyntax("delentry", DeleteEntry, NULL, 0,
6198 "delete VLDB entry for a volume");
6199 cmd_AddParm(ts, "-id", CMD_LIST, CMD_OPTIONAL, "volume name or ID");
6200 cmd_AddParm(ts, "-prefix", CMD_SINGLE, CMD_OPTIONAL,
6201 "prefix of the volume whose VLDB entry is to be deleted");
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, "-noexecute", CMD_FLAG, CMD_OPTIONAL|CMD_HIDDEN, "");
6205 cmd_AddParm(ts, "-dryrun", CMD_FLAG, CMD_OPTIONAL,
6206 "list what would be done, don't do it");
6209 ts = cmd_CreateSyntax("partinfo", PartitionInfo, NULL, 0,
6210 "list partition information");
6211 cmd_AddParm(ts, "-server", CMD_SINGLE, 0, "machine name");
6212 cmd_AddParm(ts, "-partition", CMD_SINGLE, CMD_OPTIONAL, "partition name");
6213 cmd_AddParm(ts, "-summary", CMD_FLAG, CMD_OPTIONAL,
6214 "print storage summary");
6217 ts = cmd_CreateSyntax("unlockvldb", UnlockVLDB, NULL, 0,
6218 "unlock all the locked entries in the VLDB");
6219 cmd_AddParm(ts, "-server", CMD_SINGLE, CMD_OPTIONAL, "machine name");
6220 cmd_AddParm(ts, "-partition", CMD_SINGLE, CMD_OPTIONAL, "partition name");
6223 ts = cmd_CreateSyntax("lock", LockEntry, NULL, 0,
6224 "lock VLDB entry for a volume");
6225 cmd_AddParm(ts, "-id", CMD_SINGLE, 0, "volume name or ID");
6228 ts = cmd_CreateSyntax("changeaddr", ChangeAddr, NULL, 0,
6229 "change the IP address of a file server");
6230 cmd_AddParm(ts, "-oldaddr", CMD_SINGLE, 0, "original IP address");
6231 cmd_AddParm(ts, "-newaddr", CMD_SINGLE, CMD_OPTIONAL, "new IP address");
6232 cmd_AddParm(ts, "-remove", CMD_FLAG, CMD_OPTIONAL,
6233 "remove the IP address from the VLDB");
6236 ts = cmd_CreateSyntax("listaddrs", ListAddrs, NULL, 0,
6237 "list the IP address of all file servers registered in the VLDB");
6238 cmd_AddParm(ts, "-uuid", CMD_SINGLE, CMD_OPTIONAL, "uuid of server");
6239 cmd_AddParm(ts, "-host", CMD_SINGLE, CMD_OPTIONAL, "address of host");
6240 cmd_AddParm(ts, "-printuuid", CMD_FLAG, CMD_OPTIONAL,
6241 "print uuid of hosts");
6244 ts = cmd_CreateSyntax("convertROtoRW", ConvertRO, NULL, 0,
6245 "convert a RO volume into a RW volume (after loss of old RW volume)");
6246 cmd_AddParm(ts, "-server", CMD_SINGLE, 0, "machine name");
6247 cmd_AddParm(ts, "-partition", CMD_SINGLE, 0, "partition name");
6248 cmd_AddParm(ts, "-id", CMD_SINGLE, 0, "volume name or ID");
6249 cmd_AddParm(ts, "-force", CMD_FLAG, CMD_OPTIONAL, "don't ask");
6252 ts = cmd_CreateSyntax("size", Sizes, NULL, 0,
6253 "obtain various sizes of the volume.");
6254 cmd_AddParm(ts, "-id", CMD_SINGLE, 0, "volume name or ID");
6255 cmd_AddParm(ts, "-partition", CMD_SINGLE, CMD_OPTIONAL, "partition name");
6256 cmd_AddParm(ts, "-server", CMD_SINGLE, CMD_OPTIONAL, "machine name");
6257 cmd_AddParm(ts, "-dump", CMD_FLAG, CMD_OPTIONAL,
6258 "Obtain the size of the dump");
6259 cmd_AddParm(ts, "-time", CMD_SINGLE, CMD_OPTIONAL, "dump from time");
6262 ts = cmd_CreateSyntax("endtrans", EndTrans, NULL, 0,
6263 "end a volserver transaction");
6264 cmd_AddParm(ts, "-server", CMD_SINGLE, 0, "machine name");
6265 cmd_AddParm(ts, "-transaction", CMD_SINGLE, 0,
6269 ts = cmd_CreateSyntax("setaddrs", SetAddrs, NULL, 0,
6270 "set the list of IP address for a given UUID in the VLDB");
6271 cmd_AddParm(ts, "-uuid", CMD_SINGLE, 0, "uuid of server");
6272 cmd_AddParm(ts, "-host", CMD_LIST, 0, "address of host");
6275 code = cmd_Dispatch(argc, argv);
6277 /* Shut down the ubik_client and rx connections */
6279 (void)ubik_ClientDestroy(cstruct);
6285 exit((code ? -1 : 0));