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);
75 #define COMMONPARMS cmd_Seek(ts, 12);\
76 cmd_AddParm(ts, "-cell", CMD_SINGLE, CMD_OPTIONAL, "cell name");\
77 cmd_AddParmAlias(ts, 12, "-c"); /* original -cell option */ \
78 cmd_AddParm(ts, "-noauth", CMD_FLAG, CMD_OPTIONAL, "don't authenticate");\
79 cmd_AddParm(ts, "-localauth",CMD_FLAG,CMD_OPTIONAL,"use server tickets");\
80 cmd_AddParm(ts, "-verbose", CMD_FLAG, CMD_OPTIONAL, "verbose");\
81 cmd_AddParm(ts, "-encrypt", CMD_FLAG, CMD_OPTIONAL, "encrypt commands");\
82 cmd_AddParm(ts, "-noresolve", CMD_FLAG, CMD_OPTIONAL, "don't resolve addresses"); \
83 cmd_AddParm(ts, "-config", CMD_SINGLE, CMD_OPTIONAL, "config location"); \
85 #define ERROR_EXIT(code) do { \
91 extern struct ubik_client *cstruct;
94 static struct tqHead busyHead, notokHead;
97 qInit(struct tqHead *ahead)
99 memset(ahead, 0, sizeof(struct tqHead));
105 qPut(struct tqHead *ahead, afs_uint32 volid)
109 elem = malloc(sizeof(struct tqElem));
110 elem->next = ahead->next;
118 qGet(struct tqHead *ahead, afs_uint32 *volid)
122 if (ahead->count <= 0)
124 *volid = ahead->next->volid;
126 ahead->next = tmp->next;
132 /* returns 1 if <filename> exists else 0 */
134 FileExists(char *filename)
140 code = usd_Open(filename, USD_OPEN_RDONLY, 0, &ufd);
144 code = USD_IOCTL(ufd, USD_IOCTL_GETSIZE, &size);
152 /* returns 1 if <name> doesnot end in .readonly or .backup, else 0 */
154 VolNameOK(char *name)
159 total = strlen(name);
160 if (!strcmp(&name[total - 9], ".readonly")) {
162 } else if (!strcmp(&name[total - 7], ".backup")) {
169 /* return 1 if name is a number else 0 */
171 IsNumeric(char *name)
180 for (i = 0; i < len; i++) {
181 if (*ptr < '0' || *ptr > '9') {
193 * Parse a server dotted address and return the address in network byte order
196 GetServerNoresolve(char *aname)
202 code = sscanf(aname, "%d.%d.%d.%d", &b1, &b2, &b3, &b4);
204 addr = (b1 << 24) | (b2 << 16) | (b3 << 8) | b4;
205 addr = htonl(addr); /* convert to network byte order */
211 * Parse a server name/address and return a non-loopback address in network byte order
214 GetServer(char *aname)
217 afs_uint32 addr; /* in network byte order */
219 char hostname[MAXHOSTCHARS];
222 addr = GetServerNoresolve(aname);
224 if (!rx_IsLoopbackAddr(ntohl(addr)))
230 th = gethostbyname(aname);
232 for (i=0; i < th->h_length; i++) {
233 if (!rx_IsLoopbackAddr(ntohl(*(afs_uint32 *)th->h_addr_list[i]))) {
234 memcpy(&addr, th->h_addr_list[i], sizeof(addr));
240 * If we reach this point all of the addresses returned by
241 * gethostbyname() are loopback addresses. We assume that means
242 * that the name is supposed to describe the machine this code
243 * is executing on. Try gethostname() to and check to see if
244 * that name can provide us a non-loopback address.
246 code = gethostname(hostname, MAXHOSTCHARS);
248 th = gethostbyname(hostname);
250 for (i=0; i < th->h_length; i++) {
251 if (!rx_IsLoopbackAddr(ntohl(*(afs_uint32 *)th->h_addr_list[i]))) {
252 memcpy(&addr, th->h_addr_list[i], sizeof(addr));
261 * No non-loopback address could be obtained for 'aname'.
267 GetVolumeType(char *aname)
270 if (!strcmp(aname, "ro"))
272 else if (!strcmp(aname, "rw"))
274 else if (!strcmp(aname, "bk"))
281 IsPartValid(afs_int32 partId, afs_uint32 server, afs_int32 *code)
283 struct partList dummyPartList;
289 *code = UV_ListPartitions(server, &dummyPartList, &cnt);
292 for (i = 0; i < cnt; i++) {
293 if (dummyPartList.partFlags[i] & PARTVALID)
294 if (dummyPartList.partId[i] == partId)
302 /*sends the contents of file associated with <fd> and <blksize> to Rx Stream
303 * associated with <call> */
305 SendFile(usd_handle_t ufd, struct rx_call *call, long blksize)
307 char *buffer = (char *)0;
311 buffer = malloc(blksize);
313 fprintf(STDERR, "malloc failed\n");
318 #if !defined(AFS_NT40_ENV) && !defined(AFS_PTHREAD_ENV)
319 /* Only for this for non-NT, non-pthread. For NT, we can't select on
320 * non-socket FDs. For pthread environments, we don't need to select at
321 * all, since the following read() will block. */
324 FD_SET((intptr_t)(ufd->handle), &in);
325 /* don't timeout if read blocks */
326 IOMGR_Select(((intptr_t)(ufd->handle)) + 1, &in, 0, 0, 0);
328 error = USD_READ(ufd, buffer, blksize, &nbytes);
330 fprintf(STDERR, "File system read failed: %s\n",
331 afs_error_message(error));
338 if (rx_Write(call, buffer, nbytes) != nbytes) {
348 /* function invoked by UV_RestoreVolume, reads the data from rx_trx_stream and
349 * writes it out to the volume. */
351 WriteData(struct rx_call *call, void *rock)
353 char *filename = (char *) rock;
356 afs_int32 error, code;
358 afs_int64 currOffset;
364 if (!filename || !*filename) {
365 usd_StandardInput(&ufd);
369 code = usd_Open(filename, USD_OPEN_RDONLY, 0, &ufd);
372 code = USD_IOCTL(ufd, USD_IOCTL_GETBLKSIZE, &blksize);
375 fprintf(STDERR, "Could not access file '%s': %s\n", filename,
376 afs_error_message(code));
380 /* test if we have a valid dump */
381 USD_SEEK(ufd, 0, SEEK_END, &currOffset);
382 USD_SEEK(ufd, currOffset - sizeof(afs_uint32), SEEK_SET, &currOffset);
383 USD_READ(ufd, (char *)&buffer, sizeof(afs_uint32), &got);
384 if ((got != sizeof(afs_uint32)) || (ntohl(buffer) != DUMPENDMAGIC)) {
385 fprintf(STDERR, "Signature missing from end of file '%s'\n", filename);
389 USD_SEEK(ufd, 0, SEEK_SET, &currOffset);
391 code = SendFile(ufd, call, blksize);
398 code = USD_CLOSE(ufd);
400 fprintf(STDERR, "Could not close dump file %s\n",
401 (filename && *filename) ? filename : "STDOUT");
409 /* Receive data from <call> stream into file associated
410 * with <fd> <blksize>
413 ReceiveFile(usd_handle_t ufd, struct rx_call *call, long blksize)
417 afs_uint32 bytesleft, w;
420 buffer = malloc(blksize);
422 fprintf(STDERR, "memory allocation failed\n");
426 while ((bytesread = rx_Read(call, buffer, blksize)) > 0) {
427 for (bytesleft = bytesread; bytesleft; bytesleft -= w) {
428 #if !defined(AFS_NT40_ENV) && !defined(AFS_PTHREAD_ENV)
429 /* Only for this for non-NT, non-pthread. For NT, we can't select
430 * on non-socket FDs. For pthread environments, we don't need to
431 * select at all, since the following write() will block. */
434 FD_SET((intptr_t)(ufd->handle), &out);
435 /* don't timeout if write blocks */
436 IOMGR_Select(((intptr_t)(ufd->handle)) + 1, 0, &out, 0, 0);
439 USD_WRITE(ufd, &buffer[bytesread - bytesleft], bytesleft, &w);
441 fprintf(STDERR, "File system write failed: %s\n",
442 afs_error_message(error));
455 DumpFunction(struct rx_call *call, void *rock)
457 char *filename = (char *)rock;
458 usd_handle_t ufd; /* default is to stdout */
459 afs_int32 error = 0, code;
464 /* Open the output file */
465 if (!filename || !*filename) {
466 usd_StandardOutput(&ufd);
471 usd_Open(filename, USD_OPEN_CREATE | USD_OPEN_RDWR, 0666, &ufd);
475 code = USD_IOCTL(ufd, USD_IOCTL_SETSIZE, &size);
478 code = USD_IOCTL(ufd, USD_IOCTL_GETBLKSIZE, &blksize);
481 fprintf(STDERR, "Could not create file '%s': %s\n", filename,
482 afs_error_message(code));
483 ERROR_EXIT(VOLSERBADOP);
487 code = ReceiveFile(ufd, call, blksize);
492 /* Close the output file */
494 code = USD_CLOSE(ufd);
496 fprintf(STDERR, "Could not close dump file %s\n",
497 (filename && *filename) ? filename : "STDIN");
507 DisplayFormat(volintInfo *pntr, afs_uint32 server, afs_int32 part,
508 int *totalOK, int *totalNotOK, int *totalBusy, int fast,
509 int longlist, int disp)
515 fprintf(STDOUT, "%-10lu\n", (unsigned long)pntr->volid);
516 } else if (longlist) {
517 if (pntr->status == VOK) {
518 fprintf(STDOUT, "%-32s ", pntr->name);
519 fprintf(STDOUT, "%10lu ", (unsigned long)pntr->volid);
521 fprintf(STDOUT, "RW ");
523 fprintf(STDOUT, "RO ");
525 fprintf(STDOUT, "BK ");
526 fprintf(STDOUT, "%10d K ", pntr->size);
527 if (pntr->inUse == 1) {
528 fprintf(STDOUT, "On-line");
531 fprintf(STDOUT, "Off-line");
534 if (pntr->needsSalvaged == 1)
535 fprintf(STDOUT, "**needs salvage**");
536 fprintf(STDOUT, "\n");
537 MapPartIdIntoName(part, pname);
538 fprintf(STDOUT, " %s %s \n", hostutil_GetNameByINet(server),
540 fprintf(STDOUT, " RWrite %10lu ROnly %10lu Backup %10lu \n",
541 (unsigned long)pntr->parentID,
542 (unsigned long)pntr->cloneID,
543 (unsigned long)pntr->backupID);
544 fprintf(STDOUT, " MaxQuota %10d K \n", pntr->maxquota);
545 t = pntr->creationDate;
546 fprintf(STDOUT, " Creation %s",
549 fprintf(STDOUT, " Copy %s",
552 t = pntr->backupDate;
554 fprintf(STDOUT, " Backup Never\n");
556 fprintf(STDOUT, " Backup %s",
559 t = pntr->accessDate;
561 fprintf(STDOUT, " Last Access %s",
564 t = pntr->updateDate;
566 fprintf(STDOUT, " Last Update Never\n");
568 fprintf(STDOUT, " Last Update %s",
571 " %d accesses in the past day (i.e., vnode references)\n",
573 } else if (pntr->status == VBUSY) {
575 qPut(&busyHead, pntr->volid);
577 fprintf(STDOUT, "**** Volume %lu is busy ****\n",
578 (unsigned long)pntr->volid);
581 qPut(¬okHead, pntr->volid);
583 fprintf(STDOUT, "**** Could not attach volume %lu ****\n",
584 (unsigned long)pntr->volid);
586 fprintf(STDOUT, "\n");
587 } else { /* default listing */
588 if (pntr->status == VOK) {
589 fprintf(STDOUT, "%-32s ", pntr->name);
590 fprintf(STDOUT, "%10lu ", (unsigned long)pntr->volid);
592 fprintf(STDOUT, "RW ");
594 fprintf(STDOUT, "RO ");
596 fprintf(STDOUT, "BK ");
597 fprintf(STDOUT, "%10d K ", pntr->size);
598 if (pntr->inUse == 1) {
599 fprintf(STDOUT, "On-line");
602 fprintf(STDOUT, "Off-line");
605 if (pntr->needsSalvaged == 1)
606 fprintf(STDOUT, "**needs salvage**");
607 fprintf(STDOUT, "\n");
608 } else if (pntr->status == VBUSY) {
610 qPut(&busyHead, pntr->volid);
612 fprintf(STDOUT, "**** Volume %lu is busy ****\n",
613 (unsigned long)pntr->volid);
616 qPut(¬okHead, pntr->volid);
618 fprintf(STDOUT, "**** Could not attach volume %lu ****\n",
619 (unsigned long)pntr->volid);
624 /*------------------------------------------------------------------------
625 * PRIVATE XDisplayFormat
628 * Display the contents of one extended volume info structure.
631 * a_xInfoP : Ptr to extended volume info struct to print.
632 * a_servID : Server ID to print.
633 * a_partID : Partition ID to print.
634 * a_totalOKP : Ptr to total-OK counter.
635 * a_totalNotOKP : Ptr to total-screwed counter.
636 * a_totalBusyP : Ptr to total-busy counter.
637 * a_fast : Fast listing?
638 * a_int32 : Int32 listing?
639 * a_showProblems : Show volume problems?
645 * Nothing interesting.
649 *------------------------------------------------------------------------*/
652 XDisplayFormat(volintXInfo *a_xInfoP, afs_uint32 a_servID, afs_int32 a_partID,
653 int *a_totalOKP, int *a_totalNotOKP, int *a_totalBusyP,
654 int a_fast, int a_int32, int a_showProblems)
655 { /*XDisplayFormat */
663 fprintf(STDOUT, "%-10lu\n", (unsigned long)a_xInfoP->volid);
664 } else if (a_int32) {
666 * Fully-detailed listing.
668 if (a_xInfoP->status == VOK) {
670 * Volume's status is OK - all the fields are valid.
672 fprintf(STDOUT, "%-32s ", a_xInfoP->name);
673 fprintf(STDOUT, "%10lu ", (unsigned long)a_xInfoP->volid);
674 if (a_xInfoP->type == 0)
675 fprintf(STDOUT, "RW ");
676 if (a_xInfoP->type == 1)
677 fprintf(STDOUT, "RO ");
678 if (a_xInfoP->type == 2)
679 fprintf(STDOUT, "BK ");
680 fprintf(STDOUT, "%10d K used ", a_xInfoP->size);
681 fprintf(STDOUT, "%d files ", a_xInfoP->filecount);
682 if (a_xInfoP->inUse == 1) {
683 fprintf(STDOUT, "On-line");
686 fprintf(STDOUT, "Off-line");
689 fprintf(STDOUT, "\n");
690 MapPartIdIntoName(a_partID, pname);
691 fprintf(STDOUT, " %s %s \n", hostutil_GetNameByINet(a_servID),
693 fprintf(STDOUT, " RWrite %10lu ROnly %10lu Backup %10lu \n",
694 (unsigned long)a_xInfoP->parentID,
695 (unsigned long)a_xInfoP->cloneID,
696 (unsigned long)a_xInfoP->backupID);
697 fprintf(STDOUT, " MaxQuota %10d K \n", a_xInfoP->maxquota);
699 t = a_xInfoP->creationDate;
700 fprintf(STDOUT, " Creation %s",
703 t = a_xInfoP->copyDate;
704 fprintf(STDOUT, " Copy %s",
707 t = a_xInfoP->backupDate;
709 fprintf(STDOUT, " Backup Never\n");
711 fprintf(STDOUT, " Backup %s",
714 t = a_xInfoP->accessDate;
716 fprintf(STDOUT, " Last Access %s",
719 t = a_xInfoP->updateDate;
721 fprintf(STDOUT, " Last Update Never\n");
723 fprintf(STDOUT, " Last Update %s",
726 " %d accesses in the past day (i.e., vnode references)\n",
730 * Print all the read/write and authorship stats.
732 fprintf(STDOUT, "\n Raw Read/Write Stats\n");
734 " |-------------------------------------------|\n");
736 " | Same Network | Diff Network |\n");
738 " |----------|----------|----------|----------|\n");
740 " | Total | Auth | Total | Auth |\n");
742 " |----------|----------|----------|----------|\n");
743 fprintf(STDOUT, "Reads | %8d | %8d | %8d | %8d |\n",
744 a_xInfoP->stat_reads[VOLINT_STATS_SAME_NET],
745 a_xInfoP->stat_reads[VOLINT_STATS_SAME_NET_AUTH],
746 a_xInfoP->stat_reads[VOLINT_STATS_DIFF_NET],
747 a_xInfoP->stat_reads[VOLINT_STATS_DIFF_NET_AUTH]);
748 fprintf(STDOUT, "Writes | %8d | %8d | %8d | %8d |\n",
749 a_xInfoP->stat_writes[VOLINT_STATS_SAME_NET],
750 a_xInfoP->stat_writes[VOLINT_STATS_SAME_NET_AUTH],
751 a_xInfoP->stat_writes[VOLINT_STATS_DIFF_NET],
752 a_xInfoP->stat_writes[VOLINT_STATS_DIFF_NET_AUTH]);
754 " |-------------------------------------------|\n\n");
757 " Writes Affecting Authorship\n");
759 " |-------------------------------------------|\n");
761 " | File Authorship | Directory Authorship|\n");
763 " |----------|----------|----------|----------|\n");
765 " | Same | Diff | Same | Diff |\n");
767 " |----------|----------|----------|----------|\n");
768 fprintf(STDOUT, "0-60 sec | %8d | %8d | %8d | %8d |\n",
769 a_xInfoP->stat_fileSameAuthor[VOLINT_STATS_TIME_IDX_0],
770 a_xInfoP->stat_fileDiffAuthor[VOLINT_STATS_TIME_IDX_0],
771 a_xInfoP->stat_dirSameAuthor[VOLINT_STATS_TIME_IDX_0],
772 a_xInfoP->stat_dirDiffAuthor[VOLINT_STATS_TIME_IDX_0]);
773 fprintf(STDOUT, "1-10 min | %8d | %8d | %8d | %8d |\n",
774 a_xInfoP->stat_fileSameAuthor[VOLINT_STATS_TIME_IDX_1],
775 a_xInfoP->stat_fileDiffAuthor[VOLINT_STATS_TIME_IDX_1],
776 a_xInfoP->stat_dirSameAuthor[VOLINT_STATS_TIME_IDX_1],
777 a_xInfoP->stat_dirDiffAuthor[VOLINT_STATS_TIME_IDX_1]);
778 fprintf(STDOUT, "10min-1hr | %8d | %8d | %8d | %8d |\n",
779 a_xInfoP->stat_fileSameAuthor[VOLINT_STATS_TIME_IDX_2],
780 a_xInfoP->stat_fileDiffAuthor[VOLINT_STATS_TIME_IDX_2],
781 a_xInfoP->stat_dirSameAuthor[VOLINT_STATS_TIME_IDX_2],
782 a_xInfoP->stat_dirDiffAuthor[VOLINT_STATS_TIME_IDX_2]);
783 fprintf(STDOUT, "1hr-1day | %8d | %8d | %8d | %8d |\n",
784 a_xInfoP->stat_fileSameAuthor[VOLINT_STATS_TIME_IDX_3],
785 a_xInfoP->stat_fileDiffAuthor[VOLINT_STATS_TIME_IDX_3],
786 a_xInfoP->stat_dirSameAuthor[VOLINT_STATS_TIME_IDX_3],
787 a_xInfoP->stat_dirDiffAuthor[VOLINT_STATS_TIME_IDX_3]);
788 fprintf(STDOUT, "1day-1wk | %8d | %8d | %8d | %8d |\n",
789 a_xInfoP->stat_fileSameAuthor[VOLINT_STATS_TIME_IDX_4],
790 a_xInfoP->stat_fileDiffAuthor[VOLINT_STATS_TIME_IDX_4],
791 a_xInfoP->stat_dirSameAuthor[VOLINT_STATS_TIME_IDX_4],
792 a_xInfoP->stat_dirDiffAuthor[VOLINT_STATS_TIME_IDX_4]);
793 fprintf(STDOUT, "> 1wk | %8d | %8d | %8d | %8d |\n",
794 a_xInfoP->stat_fileSameAuthor[VOLINT_STATS_TIME_IDX_5],
795 a_xInfoP->stat_fileDiffAuthor[VOLINT_STATS_TIME_IDX_5],
796 a_xInfoP->stat_dirSameAuthor[VOLINT_STATS_TIME_IDX_5],
797 a_xInfoP->stat_dirDiffAuthor[VOLINT_STATS_TIME_IDX_5]);
799 " |-------------------------------------------|\n");
800 } /*Volume status OK */
801 else if (a_xInfoP->status == VBUSY) {
803 qPut(&busyHead, a_xInfoP->volid);
805 fprintf(STDOUT, "**** Volume %lu is busy ****\n",
806 (unsigned long)a_xInfoP->volid);
810 qPut(¬okHead, a_xInfoP->volid);
812 fprintf(STDOUT, "**** Could not attach volume %lu ****\n",
813 (unsigned long)a_xInfoP->volid);
814 } /*Screwed volume */
815 fprintf(STDOUT, "\n");
821 if (a_xInfoP->status == VOK) {
822 fprintf(STDOUT, "%-32s ", a_xInfoP->name);
823 fprintf(STDOUT, "%10lu ", (unsigned long)a_xInfoP->volid);
824 if (a_xInfoP->type == 0)
825 fprintf(STDOUT, "RW ");
826 if (a_xInfoP->type == 1)
827 fprintf(STDOUT, "RO ");
828 if (a_xInfoP->type == 2)
829 fprintf(STDOUT, "BK ");
830 fprintf(STDOUT, "%10d K ", a_xInfoP->size);
831 if (a_xInfoP->inUse == 1) {
832 fprintf(STDOUT, "On-line");
835 fprintf(STDOUT, "Off-line");
838 fprintf(STDOUT, "\n");
840 else if (a_xInfoP->status == VBUSY) {
842 qPut(&busyHead, a_xInfoP->volid);
844 fprintf(STDOUT, "**** Volume %lu is busy ****\n",
845 (unsigned long)a_xInfoP->volid);
849 qPut(¬okHead, a_xInfoP->volid);
851 fprintf(STDOUT, "**** Could not attach volume %lu ****\n",
852 (unsigned long)a_xInfoP->volid);
853 } /*Screwed volume */
854 } /*Default listing */
855 } /*XDisplayFormat */
857 /*------------------------------------------------------------------------
858 * PRIVATE XDisplayFormat2
861 * Display the formated contents of one extended volume info structure.
864 * a_xInfoP : Ptr to extended volume info struct to print.
865 * a_servID : Server ID to print.
866 * a_partID : Partition ID to print.
867 * a_totalOKP : Ptr to total-OK counter.
868 * a_totalNotOKP : Ptr to total-screwed counter.
869 * a_totalBusyP : Ptr to total-busy counter.
870 * a_fast : Fast listing?
871 * a_int32 : Int32 listing?
872 * a_showProblems : Show volume problems?
878 * Nothing interesting.
882 *------------------------------------------------------------------------*/
885 XDisplayFormat2(volintXInfo *a_xInfoP, afs_uint32 a_servID, afs_int32 a_partID,
886 int *a_totalOKP, int *a_totalNotOKP, int *a_totalBusyP,
887 int a_fast, int a_int32, int a_showProblems)
888 { /*XDisplayFormat */
894 fprintf(STDOUT, "vold_id\t%-10lu\n", (unsigned long)a_xInfoP->volid);
895 } else if (a_int32) {
897 * Fully-detailed listing.
899 if (a_xInfoP->status == VOK) {
901 * Volume's status is OK - all the fields are valid.
904 static long server_cache = -1, partition_cache = -1;
905 static char hostname[256], address[32], pname[16];
906 int i,ai[] = {VOLINT_STATS_TIME_IDX_0,VOLINT_STATS_TIME_IDX_1,VOLINT_STATS_TIME_IDX_2,
907 VOLINT_STATS_TIME_IDX_3,VOLINT_STATS_TIME_IDX_4,VOLINT_STATS_TIME_IDX_5};
909 if (a_servID != server_cache) {
913 strcpy(hostname, hostutil_GetNameByINet(a_servID));
914 strcpy(address, inet_ntoa(s));
915 server_cache = a_servID;
917 if (a_partID != partition_cache) {
918 MapPartIdIntoName(a_partID, pname);
919 partition_cache = a_partID;
922 fprintf(STDOUT, "name\t\t%s\n", a_xInfoP->name);
923 fprintf(STDOUT, "id\t\t%lu\n", afs_printable_uint32_lu(a_xInfoP->volid));
924 fprintf(STDOUT, "serv\t\t%s\t%s\n", address, hostname);
925 fprintf(STDOUT, "part\t\t%s\n", pname);
926 fprintf(STDOUT, "status\t\tOK\n");
927 fprintf(STDOUT, "backupID\t%lu\n",
928 afs_printable_uint32_lu(a_xInfoP->backupID));
929 fprintf(STDOUT, "parentID\t%lu\n",
930 afs_printable_uint32_lu(a_xInfoP->parentID));
931 fprintf(STDOUT, "cloneID\t\t%lu\n",
932 afs_printable_uint32_lu(a_xInfoP->cloneID));
933 fprintf(STDOUT, "inUse\t\t%s\n", a_xInfoP->inUse ? "Y" : "N");
934 switch (a_xInfoP->type) {
936 fprintf(STDOUT, "type\t\tRW\n");
939 fprintf(STDOUT, "type\t\tRO\n");
942 fprintf(STDOUT, "type\t\tBK\n");
945 fprintf(STDOUT, "type\t\t?\n");
948 t = a_xInfoP->creationDate;
949 fprintf(STDOUT, "creationDate\t%-9lu\t%s",
950 afs_printable_uint32_lu(a_xInfoP->creationDate),
953 t = a_xInfoP->accessDate;
954 fprintf(STDOUT, "accessDate\t%-9lu\t%s",
955 afs_printable_uint32_lu(a_xInfoP->accessDate),
958 t = a_xInfoP->updateDate;
959 fprintf(STDOUT, "updateDate\t%-9lu\t%s",
960 afs_printable_uint32_lu(a_xInfoP->updateDate),
963 t = a_xInfoP->backupDate;
964 fprintf(STDOUT, "backupDate\t%-9lu\t%s",
965 afs_printable_uint32_lu(a_xInfoP->backupDate),
968 t = a_xInfoP->copyDate;
969 fprintf(STDOUT, "copyDate\t%-9lu\t%s",
970 afs_printable_uint32_lu(a_xInfoP->copyDate),
973 fprintf(STDOUT, "diskused\t%u\n", a_xInfoP->size);
974 fprintf(STDOUT, "maxquota\t%u\n", a_xInfoP->maxquota);
976 fprintf(STDOUT, "filecount\t%u\n", a_xInfoP->filecount);
977 fprintf(STDOUT, "dayUse\t\t%u\n", a_xInfoP->dayUse);
981 fprintf(STDOUT,"reads_same_net\t%8d\n",a_xInfoP->stat_reads[VOLINT_STATS_SAME_NET]);
982 fprintf(STDOUT,"reads_same_net_auth\t%8d\n",a_xInfoP->stat_reads[VOLINT_STATS_SAME_NET_AUTH]);
983 fprintf(STDOUT,"reads_diff_net\t%8d\n",a_xInfoP->stat_reads[VOLINT_STATS_DIFF_NET]);
984 fprintf(STDOUT,"reads_diff_net_auth\t%8d\n",a_xInfoP->stat_reads[VOLINT_STATS_DIFF_NET_AUTH]);
986 fprintf(STDOUT,"writes_same_net\t%8d\n",a_xInfoP->stat_writes[VOLINT_STATS_SAME_NET]);
987 fprintf(STDOUT,"writes_same_net_auth\t%8d\n",a_xInfoP->stat_writes[VOLINT_STATS_SAME_NET_AUTH]);
988 fprintf(STDOUT,"writes_diff_net\t%8d\n",a_xInfoP->stat_writes[VOLINT_STATS_DIFF_NET]);
989 fprintf(STDOUT,"writes_diff_net_auth\t%8d\n",a_xInfoP->stat_writes[VOLINT_STATS_DIFF_NET_AUTH]);
993 fprintf(STDOUT,"file_same_author_idx_%d\t%8d\n",i+1,a_xInfoP->stat_fileSameAuthor[ai[i]]);
994 fprintf(STDOUT,"file_diff_author_idx_%d\t%8d\n",i+1,a_xInfoP->stat_fileDiffAuthor[ai[i]]);
995 fprintf(STDOUT,"dir_same_author_idx_%d\t%8d\n",i+1,a_xInfoP->stat_dirSameAuthor[ai[i]]);
996 fprintf(STDOUT,"dir_dif_author_idx_%d\t%8d\n",i+1,a_xInfoP->stat_dirDiffAuthor[ai[i]]);
999 } /*Volume status OK */
1000 else if (a_xInfoP->status == VBUSY) {
1002 qPut(&busyHead, a_xInfoP->volid);
1004 fprintf(STDOUT, "BUSY_VOL\t%lu\n",
1005 (unsigned long)a_xInfoP->volid);
1009 qPut(¬okHead, a_xInfoP->volid);
1011 fprintf(STDOUT, "COULD_NOT_ATTACH\t%lu\n",
1012 (unsigned long)a_xInfoP->volid);
1013 } /*Screwed volume */
1019 if (a_xInfoP->status == VOK) {
1020 fprintf(STDOUT, "name\t%-32s\n", a_xInfoP->name);
1021 fprintf(STDOUT, "volID\t%10lu\n", (unsigned long)a_xInfoP->volid);
1022 if (a_xInfoP->type == 0)
1023 fprintf(STDOUT, "type\tRW\n");
1024 if (a_xInfoP->type == 1)
1025 fprintf(STDOUT, "type\tRO\n");
1026 if (a_xInfoP->type == 2)
1027 fprintf(STDOUT, "type\tBK\n");
1028 fprintf(STDOUT, "size\t%10dK\n", a_xInfoP->size);
1030 fprintf(STDOUT, "inUse\t%d\n",a_xInfoP->inUse);
1031 if (a_xInfoP->inUse == 1)
1037 else if (a_xInfoP->status == VBUSY) {
1039 qPut(&busyHead, a_xInfoP->volid);
1041 fprintf(STDOUT, "VOLUME_BUSY\t%lu\n",
1042 (unsigned long)a_xInfoP->volid);
1046 qPut(¬okHead, a_xInfoP->volid);
1048 fprintf(STDOUT, "COULD_NOT_ATTACH_VOLUME\t%lu\n",
1049 (unsigned long)a_xInfoP->volid);
1050 } /*Screwed volume */
1051 } /*Default listing */
1052 } /*XDisplayFormat */
1055 DisplayFormat2(long server, long partition, volintInfo *pntr)
1057 static long server_cache = -1, partition_cache = -1;
1058 static char hostname[256], address[32], pname[16];
1061 if (server != server_cache) {
1065 strcpy(hostname, hostutil_GetNameByINet(server));
1066 strcpy(address, inet_ntoa(s));
1067 server_cache = server;
1069 if (partition != partition_cache) {
1070 MapPartIdIntoName(partition, pname);
1071 partition_cache = partition;
1074 if (pntr->status == VOK)
1075 fprintf(STDOUT, "name\t\t%s\n", pntr->name);
1077 fprintf(STDOUT, "id\t\t%lu\n",
1078 afs_printable_uint32_lu(pntr->volid));
1079 fprintf(STDOUT, "serv\t\t%s\t%s\n", address, hostname);
1080 fprintf(STDOUT, "part\t\t%s\n", pname);
1081 switch (pntr->status) {
1083 fprintf(STDOUT, "status\t\tOK\n");
1086 fprintf(STDOUT, "status\t\tBUSY\n");
1089 fprintf(STDOUT, "status\t\tUNATTACHABLE\n");
1092 fprintf(STDOUT, "backupID\t%lu\n",
1093 afs_printable_uint32_lu(pntr->backupID));
1094 fprintf(STDOUT, "parentID\t%lu\n",
1095 afs_printable_uint32_lu(pntr->parentID));
1096 fprintf(STDOUT, "cloneID\t\t%lu\n",
1097 afs_printable_uint32_lu(pntr->cloneID));
1098 fprintf(STDOUT, "inUse\t\t%s\n", pntr->inUse ? "Y" : "N");
1099 fprintf(STDOUT, "needsSalvaged\t%s\n", pntr->needsSalvaged ? "Y" : "N");
1100 /* 0xD3 is from afs/volume.h since I had trouble including the file */
1101 fprintf(STDOUT, "destroyMe\t%s\n", pntr->destroyMe == 0xD3 ? "Y" : "N");
1102 switch (pntr->type) {
1104 fprintf(STDOUT, "type\t\tRW\n");
1107 fprintf(STDOUT, "type\t\tRO\n");
1110 fprintf(STDOUT, "type\t\tBK\n");
1113 fprintf(STDOUT, "type\t\t?\n");
1116 t = pntr->creationDate;
1117 fprintf(STDOUT, "creationDate\t%-9lu\t%s",
1118 afs_printable_uint32_lu(pntr->creationDate),
1121 t = pntr->accessDate;
1122 fprintf(STDOUT, "accessDate\t%-9lu\t%s",
1123 afs_printable_uint32_lu(pntr->accessDate),
1126 t = pntr->updateDate;
1127 fprintf(STDOUT, "updateDate\t%-9lu\t%s",
1128 afs_printable_uint32_lu(pntr->updateDate),
1131 t = pntr->backupDate;
1132 fprintf(STDOUT, "backupDate\t%-9lu\t%s",
1133 afs_printable_uint32_lu(pntr->backupDate),
1137 fprintf(STDOUT, "copyDate\t%-9lu\t%s",
1138 afs_printable_uint32_lu(pntr->copyDate),
1141 fprintf(STDOUT, "flags\t\t%#lx\t(Optional)\n",
1142 afs_printable_uint32_lu(pntr->flags));
1143 fprintf(STDOUT, "diskused\t%u\n", pntr->size);
1144 fprintf(STDOUT, "maxquota\t%u\n", pntr->maxquota);
1145 fprintf(STDOUT, "minquota\t%lu\t(Optional)\n",
1146 afs_printable_uint32_lu(pntr->spare0));
1147 fprintf(STDOUT, "filecount\t%u\n", pntr->filecount);
1148 fprintf(STDOUT, "dayUse\t\t%u\n", pntr->dayUse);
1149 fprintf(STDOUT, "weekUse\t\t%lu\t(Optional)\n",
1150 afs_printable_uint32_lu(pntr->spare1));
1151 fprintf(STDOUT, "spare2\t\t%lu\t(Optional)\n",
1152 afs_printable_uint32_lu(pntr->spare2));
1153 fprintf(STDOUT, "spare3\t\t%lu\t(Optional)\n",
1154 afs_printable_uint32_lu(pntr->spare3));
1159 DisplayVolumes2(long server, long partition, volintInfo *pntr, long count)
1163 for (i = 0; i < count; i++) {
1164 fprintf(STDOUT, "BEGIN_OF_ENTRY\n");
1165 DisplayFormat2(server, partition, pntr);
1166 fprintf(STDOUT, "END_OF_ENTRY\n\n");
1173 DisplayVolumes(afs_uint32 server, afs_int32 part, volintInfo *pntr,
1174 afs_int32 count, afs_int32 longlist, afs_int32 fast,
1177 int totalOK, totalNotOK, totalBusy, i;
1178 afs_uint32 volid = 0;
1185 for (i = 0; i < count; i++) {
1186 DisplayFormat(pntr, server, part, &totalOK, &totalNotOK, &totalBusy,
1191 while (busyHead.count) {
1192 qGet(&busyHead, &volid);
1193 fprintf(STDOUT, "**** Volume %lu is busy ****\n",
1194 (unsigned long)volid);
1198 while (notokHead.count) {
1199 qGet(¬okHead, &volid);
1200 fprintf(STDOUT, "**** Could not attach volume %lu ****\n",
1201 (unsigned long)volid);
1205 fprintf(STDOUT, "\n");
1208 "Total volumes onLine %d ; Total volumes offLine %d ; Total busy %d\n\n",
1209 totalOK, totalNotOK, totalBusy);
1213 /*------------------------------------------------------------------------
1214 * PRIVATE XDisplayVolumes
1217 * Display extended volume information.
1220 * a_servID : Pointer to the Rx call we're performing.
1221 * a_partID : Partition for which we want the extended list.
1222 * a_xInfoP : Ptr to extended volume info.
1223 * a_count : Number of volume records contained above.
1224 * a_int32 : Int32 listing generated?
1225 * a_fast : Fast listing generated?
1226 * a_quiet : Quiet listing generated?
1232 * Nothing interesting.
1236 *------------------------------------------------------------------------*/
1239 XDisplayVolumes(afs_uint32 a_servID, afs_int32 a_partID, volintXInfo *a_xInfoP,
1240 afs_int32 a_count, afs_int32 a_int32, afs_int32 a_fast,
1242 { /*XDisplayVolumes */
1244 int totalOK; /*Total OK volumes */
1245 int totalNotOK; /*Total screwed volumes */
1246 int totalBusy; /*Total busy volumes */
1247 int i; /*Loop variable */
1248 afs_uint32 volid = 0; /*Current volume ID */
1251 * Initialize counters and (global!!) queues.
1260 * Display each volume in the list.
1262 for (i = 0; i < a_count; i++) {
1263 XDisplayFormat(a_xInfoP, a_servID, a_partID, &totalOK, &totalNotOK,
1264 &totalBusy, a_fast, a_int32, 0);
1269 * If any volumes were found to be busy or screwed, display them.
1272 while (busyHead.count) {
1273 qGet(&busyHead, &volid);
1274 fprintf(STDOUT, "**** Volume %lu is busy ****\n",
1275 (unsigned long)volid);
1279 while (notokHead.count) {
1280 qGet(¬okHead, &volid);
1281 fprintf(STDOUT, "**** Could not attach volume %lu ****\n",
1282 (unsigned long)volid);
1287 fprintf(STDOUT, "\n");
1290 "Total volumes: %d on-line, %d off-line, %d busyd\n\n",
1291 totalOK, totalNotOK, totalBusy);
1295 } /*XDisplayVolumes */
1297 /*------------------------------------------------------------------------
1298 * PRIVATE XDisplayVolumes2
1301 * Display extended formated volume information.
1304 * a_servID : Pointer to the Rx call we're performing.
1305 * a_partID : Partition for which we want the extended list.
1306 * a_xInfoP : Ptr to extended volume info.
1307 * a_count : Number of volume records contained above.
1308 * a_int32 : Int32 listing generated?
1309 * a_fast : Fast listing generated?
1310 * a_quiet : Quiet listing generated?
1316 * Nothing interesting.
1320 *------------------------------------------------------------------------*/
1323 XDisplayVolumes2(afs_uint32 a_servID, afs_int32 a_partID, volintXInfo *a_xInfoP,
1324 afs_int32 a_count, afs_int32 a_int32, afs_int32 a_fast,
1326 { /*XDisplayVolumes */
1328 int totalOK; /*Total OK volumes */
1329 int totalNotOK; /*Total screwed volumes */
1330 int totalBusy; /*Total busy volumes */
1331 int i; /*Loop variable */
1332 afs_uint32 volid = 0; /*Current volume ID */
1335 * Initialize counters and (global!!) queues.
1344 * Display each volume in the list.
1346 for (i = 0; i < a_count; i++) {
1347 fprintf(STDOUT, "BEGIN_OF_ENTRY\n");
1348 XDisplayFormat2(a_xInfoP, a_servID, a_partID, &totalOK, &totalNotOK,
1349 &totalBusy, a_fast, a_int32, 0);
1350 fprintf(STDOUT, "END_OF_ENTRY\n");
1355 * If any volumes were found to be busy or screwed, display them.
1358 while (busyHead.count) {
1359 qGet(&busyHead, &volid);
1360 fprintf(STDOUT, "BUSY_VOL\t%lu\n",
1361 (unsigned long)volid);
1365 while (notokHead.count) {
1366 qGet(¬okHead, &volid);
1367 fprintf(STDOUT, "COULD_NOT_ATTACH\t%lu\n",
1368 (unsigned long)volid);
1373 fprintf(STDOUT, "\n");
1376 "VOLUMES_ONLINE\t%d\nVOLUMES_OFFLINE\t%d\nVOLUMES_BUSY\t%d\n",
1377 totalOK, totalNotOK, totalBusy);
1381 } /*XDisplayVolumes2 */
1384 /* set <server> and <part> to the correct values depending on
1385 * <voltype> and <entry> */
1387 GetServerAndPart(struct nvldbentry *entry, int voltype, afs_uint32 *server,
1388 afs_int32 *part, int *previdx)
1390 int i, istart, vtype;
1395 /* Doesn't check for non-existance of backup volume */
1396 if ((voltype == RWVOL) || (voltype == BACKVOL)) {
1398 istart = 0; /* seach the entire entry */
1401 /* Seach from beginning of entry or pick up where we left off */
1402 istart = ((*previdx < 0) ? 0 : *previdx + 1);
1405 for (i = istart; i < entry->nServers; i++) {
1406 if (entry->serverFlags[i] & vtype) {
1407 *server = entry->serverNumber[i];
1408 *part = entry->serverPartition[i];
1414 /* Didn't find any, return -1 */
1420 PrintLocked(afs_int32 aflags)
1422 afs_int32 flags = aflags & VLOP_ALLOPERS;
1425 fprintf(STDOUT, " Volume is currently LOCKED \n");
1427 if (flags & VLOP_MOVE) {
1428 fprintf(STDOUT, " Volume is locked for a move operation\n");
1430 if (flags & VLOP_RELEASE) {
1431 fprintf(STDOUT, " Volume is locked for a release operation\n");
1433 if (flags & VLOP_BACKUP) {
1434 fprintf(STDOUT, " Volume is locked for a backup operation\n");
1436 if (flags & VLOP_DELETE) {
1437 fprintf(STDOUT, " Volume is locked for a delete/misc operation\n");
1439 if (flags & VLOP_DUMP) {
1440 fprintf(STDOUT, " Volume is locked for a dump/restore operation\n");
1446 PostVolumeStats(struct nvldbentry *entry)
1448 SubEnumerateEntry(entry);
1449 /* Check for VLOP_ALLOPERS */
1450 PrintLocked(entry->flags);
1454 /*------------------------------------------------------------------------
1455 * PRIVATE XVolumeStats
1458 * Display extended volume information.
1461 * a_xInfoP : Ptr to extended volume info.
1462 * a_entryP : Ptr to the volume's VLDB entry.
1463 * a_srvID : Server ID.
1464 * a_partID : Partition ID.
1465 * a_volType : Type of volume to print.
1471 * Nothing interesting.
1475 *------------------------------------------------------------------------*/
1478 XVolumeStats(volintXInfo *a_xInfoP, struct nvldbentry *a_entryP,
1479 afs_int32 a_srvID, afs_int32 a_partID, int a_volType)
1482 int totalOK, totalNotOK, totalBusy; /*Dummies - we don't really count here */
1484 XDisplayFormat(a_xInfoP, /*Ptr to extended volume info */
1485 a_srvID, /*Server ID to print */
1486 a_partID, /*Partition ID to print */
1487 &totalOK, /*Ptr to total-OK counter */
1488 &totalNotOK, /*Ptr to total-screwed counter */
1489 &totalBusy, /*Ptr to total-busy counter */
1490 0, /*Don't do a fast listing */
1491 1, /*Do a long listing */
1492 1); /*Show volume problems */
1498 VolumeStats_int(volintInfo *pntr, struct nvldbentry *entry, afs_uint32 server,
1499 afs_int32 part, int voltype)
1505 DisplayFormat(pntr, server, part, &totalOK, &totalNotOK, &totalBusy, 0, 1,
1510 /* command to forcibly remove a volume */
1512 NukeVolume(struct cmd_syndesc *as)
1521 server = GetServer(tp = as->parms[0].items->data);
1523 fprintf(STDERR, "vos: server '%s' not found in host table\n", tp);
1527 partID = volutil_GetPartitionID(tp = as->parms[1].items->data);
1529 fprintf(STDERR, "vos: could not parse '%s' as a partition name", tp);
1533 volID = vsu_GetVolumeID(tp = as->parms[2].items->data, cstruct, &err);
1536 PrintError("", err);
1539 "vos: could not parse '%s' as a numeric volume ID", tp);
1544 "vos: forcibly removing all traces of volume %d, please wait...",
1547 code = UV_NukeVolume(server, partID, volID);
1549 fprintf(STDOUT, "done.\n");
1551 fprintf(STDOUT, "failed with code %d.\n", code);
1556 /*------------------------------------------------------------------------
1557 * PRIVATE ExamineVolume
1560 * Routine used to examine a single volume, contacting the VLDB as
1561 * well as the Volume Server.
1564 * as : Ptr to parsed command line arguments.
1567 * 0 for a successful operation,
1568 * Otherwise, one of the ubik or VolServer error values.
1571 * Nothing interesting.
1575 *------------------------------------------------------------------------
1578 ExamineVolume(struct cmd_syndesc *as, void *arock)
1580 struct nvldbentry entry;
1581 afs_int32 vcode = 0;
1582 volintInfo *pntr = (volintInfo *) 0;
1583 volintXInfo *xInfoP = (volintXInfo *) 0;
1585 afs_int32 code, err, error = 0;
1586 int voltype, foundserv = 0, foundentry = 0;
1590 int wantExtendedInfo; /*Do we want extended vol info? */
1591 int isSubEnum=0; /* Keep track whether sub enumerate called. */
1592 wantExtendedInfo = (as->parms[1].items ? 1 : 0); /* -extended */
1594 volid = vsu_GetVolumeID(as->parms[0].items->data, cstruct, &err); /* -id */
1597 PrintError("", err);
1599 fprintf(STDERR, "Unknown volume ID or name '%s'\n",
1600 as->parms[0].items->data);
1605 fprintf(STDOUT, "Fetching VLDB entry for %lu .. ",
1606 (unsigned long)volid);
1609 vcode = VLDB_GetEntryByID(volid, -1, &entry);
1612 "Could not fetch the entry for volume number %lu from VLDB \n",
1613 (unsigned long)volid);
1617 fprintf(STDOUT, "done\n");
1618 MapHostToNetwork(&entry);
1620 if (entry.volumeId[RWVOL] == volid)
1622 else if (entry.volumeId[BACKVOL] == volid)
1624 else /* (entry.volumeId[ROVOL] == volid) */
1627 do { /* do {...} while (voltype == ROVOL) */
1628 /* Get the entry for the volume. If its a RW vol, get the RW entry.
1629 * It its a BK vol, get the RW entry (even if VLDB may say the BK doen't exist).
1630 * If its a RO vol, get the next RO entry.
1632 GetServerAndPart(&entry, ((voltype == ROVOL) ? ROVOL : RWVOL),
1633 &aserver, &apart, &previdx);
1634 if (previdx == -1) { /* searched all entries */
1636 fprintf(STDERR, "Volume %s does not exist in VLDB\n\n",
1637 as->parms[0].items->data);
1644 /* Get information about the volume from the server */
1646 fprintf(STDOUT, "Getting volume listing from the server %s .. ",
1647 hostutil_GetNameByINet(aserver));
1650 if (wantExtendedInfo)
1651 code = UV_XListOneVolume(aserver, apart, volid, &xInfoP);
1653 code = UV_ListOneVolume(aserver, apart, volid, &pntr);
1655 fprintf(STDOUT, "done\n");
1659 if (code == ENODEV) {
1660 if ((voltype == BACKVOL) && !(entry.flags & BACK_EXISTS)) {
1661 /* The VLDB says there is no backup volume and its not on disk */
1662 fprintf(STDERR, "Volume %s does not exist\n",
1663 as->parms[0].items->data);
1667 "Volume does not exist on server %s as indicated by the VLDB\n",
1668 hostutil_GetNameByINet(aserver));
1671 PrintDiagnostics("examine", code);
1673 fprintf(STDOUT, "\n");
1676 if (wantExtendedInfo)
1677 XVolumeStats(xInfoP, &entry, aserver, apart, voltype);
1678 else if (as->parms[2].items) {
1679 DisplayFormat2(aserver, apart, pntr);
1680 EnumerateEntry(&entry);
1683 VolumeStats_int(pntr, &entry, aserver, apart, voltype);
1685 if ((voltype == BACKVOL) && !(entry.flags & BACK_EXISTS)) {
1686 /* The VLDB says there is no backup volume yet we found one on disk */
1687 fprintf(STDERR, "Volume %s does not exist in VLDB\n",
1688 as->parms[0].items->data);
1697 } while (voltype == ROVOL);
1700 fprintf(STDERR, "Dump only information from VLDB\n\n");
1701 fprintf(STDOUT, "%s \n", entry.name); /* PostVolumeStats doesn't print name */
1705 PostVolumeStats(&entry);
1710 /*------------------------------------------------------------------------
1714 * Routine used to change the status of a single volume.
1717 * as : Ptr to parsed command line arguments.
1720 * 0 for a successful operation,
1721 * Otherwise, one of the ubik or VolServer error values.
1724 * Nothing interesting.
1728 *------------------------------------------------------------------------
1731 SetFields(struct cmd_syndesc *as, void *arock)
1733 struct nvldbentry entry;
1736 afs_int32 code, err;
1742 volid = vsu_GetVolumeID(as->parms[0].items->data, cstruct, &err); /* -id */
1745 PrintError("", err);
1747 fprintf(STDERR, "Unknown volume ID or name '%s'\n",
1748 as->parms[0].items->data);
1752 code = VLDB_GetEntryByID(volid, RWVOL, &entry);
1755 "Could not fetch the entry for volume number %lu from VLDB \n",
1756 (unsigned long)volid);
1759 MapHostToNetwork(&entry);
1761 GetServerAndPart(&entry, RWVOL, &aserver, &apart, &previdx);
1762 if (previdx == -1) {
1763 fprintf(STDERR, "Volume %s does not exist in VLDB\n\n",
1764 as->parms[0].items->data);
1768 init_volintInfo(&info);
1772 if (as->parms[1].items) {
1775 code = util_GetHumanInt32(as->parms[1].items->data, &info.maxquota);
1777 fprintf(STDERR, "invalid quota value\n");
1781 if (as->parms[2].items) {
1786 if (as->parms[3].items) {
1787 /* -clearVolUpCounter */
1792 fprintf(STDERR,"Nothing to set.\n");
1795 code = UV_SetVolumeInfo(aserver, apart, volid, &info);
1798 "Could not update volume info fields for volume number %lu\n",
1799 (unsigned long)volid);
1803 /*------------------------------------------------------------------------
1807 * Brings a volume online.
1810 * as : Ptr to parsed command line arguments.
1813 * 0 for a successful operation,
1816 * Nothing interesting.
1820 *------------------------------------------------------------------------
1823 volOnline(struct cmd_syndesc *as, void *arock)
1826 afs_int32 partition;
1828 afs_int32 code, err = 0;
1830 server = GetServer(as->parms[0].items->data);
1832 fprintf(STDERR, "vos: server '%s' not found in host table\n",
1833 as->parms[0].items->data);
1837 partition = volutil_GetPartitionID(as->parms[1].items->data);
1838 if (partition < 0) {
1839 fprintf(STDERR, "vos: could not interpret partition name '%s'\n",
1840 as->parms[1].items->data);
1844 volid = vsu_GetVolumeID(as->parms[2].items->data, cstruct, &err); /* -id */
1847 PrintError("", err);
1849 fprintf(STDERR, "Unknown volume ID or name '%s'\n",
1850 as->parms[0].items->data);
1854 code = UV_SetVolume(server, partition, volid, ITOffline, 0 /*online */ ,
1857 fprintf(STDERR, "Failed to set volume. Code = %d\n", code);
1864 /*------------------------------------------------------------------------
1865 * PRIVATE volOffline
1868 * Brings a volume offline.
1871 * as : Ptr to parsed command line arguments.
1874 * 0 for a successful operation,
1877 * Nothing interesting.
1881 *------------------------------------------------------------------------
1884 volOffline(struct cmd_syndesc *as, void *arock)
1887 afs_int32 partition;
1889 afs_int32 code, err = 0;
1890 afs_int32 transflag, sleeptime, transdone;
1892 server = GetServer(as->parms[0].items->data);
1894 fprintf(STDERR, "vos: server '%s' not found in host table\n",
1895 as->parms[0].items->data);
1899 partition = volutil_GetPartitionID(as->parms[1].items->data);
1900 if (partition < 0) {
1901 fprintf(STDERR, "vos: could not interpret partition name '%s'\n",
1902 as->parms[1].items->data);
1906 volid = vsu_GetVolumeID(as->parms[2].items->data, cstruct, &err); /* -id */
1909 PrintError("", err);
1911 fprintf(STDERR, "Unknown volume ID or name '%s'\n",
1912 as->parms[0].items->data);
1916 transflag = (as->parms[4].items ? ITBusy : ITOffline);
1917 sleeptime = (as->parms[3].items ? atol(as->parms[3].items->data) : 0);
1918 transdone = ((sleeptime || as->parms[4].items) ? 0 /*online */ : VTOutOfService);
1919 if (as->parms[4].items && !as->parms[3].items) {
1920 fprintf(STDERR, "-sleep option must be used with -busy flag\n");
1925 UV_SetVolume(server, partition, volid, transflag, transdone,
1928 fprintf(STDERR, "Failed to set volume. Code = %d\n", code);
1936 CreateVolume(struct cmd_syndesc *as, void *arock)
1940 afs_uint32 volid = 0, rovolid = 0, bkvolid = 0;
1941 afs_uint32 *arovolid;
1943 struct nvldbentry entry;
1948 arovolid = &rovolid;
1951 tserver = GetServer(as->parms[0].items->data);
1953 fprintf(STDERR, "vos: host '%s' not found in host table\n",
1954 as->parms[0].items->data);
1957 pnum = volutil_GetPartitionID(as->parms[1].items->data);
1959 fprintf(STDERR, "vos: could not interpret partition name '%s'\n",
1960 as->parms[1].items->data);
1963 if (!IsPartValid(pnum, tserver, &code)) { /*check for validity of the partition */
1965 PrintError("", code);
1968 "vos : partition %s does not exist on the server\n",
1969 as->parms[1].items->data);
1972 if (!ISNAMEVALID(as->parms[2].items->data)) {
1974 "vos: the name of the root volume %s exceeds the size limit of %d\n",
1975 as->parms[2].items->data, VOLSER_OLDMAXVOLNAME - 10);
1978 if (!VolNameOK(as->parms[2].items->data)) {
1980 "Illegal volume name %s, should not end in .readonly or .backup\n",
1981 as->parms[2].items->data);
1984 if (IsNumeric(as->parms[2].items->data)) {
1985 fprintf(STDERR, "Illegal volume name %s, should not be a number\n",
1986 as->parms[2].items->data);
1989 vcode = VLDB_GetEntryByName(as->parms[2].items->data, &entry);
1991 fprintf(STDERR, "Volume %s already exists\n",
1992 as->parms[2].items->data);
1993 PrintDiagnostics("create", code);
1997 if (as->parms[3].items) {
1998 code = util_GetHumanInt32(as->parms[3].items->data, "a);
2000 fprintf(STDERR, "vos: bad integer specified for quota.\n");
2005 if (as->parms[4].items) {
2006 if (!IsNumeric(as->parms[4].items->data)) {
2007 fprintf(STDERR, "vos: Given volume ID %s should be numeric.\n",
2008 as->parms[4].items->data);
2012 code = util_GetUInt32(as->parms[4].items->data, &volid);
2014 fprintf(STDERR, "vos: bad integer specified for volume ID.\n");
2019 if (as->parms[5].items) {
2020 if (!IsNumeric(as->parms[5].items->data)) {
2021 fprintf(STDERR, "vos: Given RO volume ID %s should be numeric.\n",
2022 as->parms[5].items->data);
2026 code = util_GetUInt32(as->parms[5].items->data, &rovolid);
2028 fprintf(STDERR, "vos: bad integer specified for volume ID.\n");
2038 UV_CreateVolume3(tserver, pnum, as->parms[2].items->data, quota, 0,
2039 0, 0, 0, &volid, arovolid, &bkvolid);
2041 PrintDiagnostics("create", code);
2044 MapPartIdIntoName(pnum, part);
2045 fprintf(STDOUT, "Volume %lu created on partition %s of %s\n",
2046 (unsigned long)volid, part, as->parms[0].items->data);
2053 DeleteAll(struct nvldbentry *entry)
2056 afs_int32 error, code, curserver, curpart;
2059 MapHostToNetwork(entry);
2061 for (i = 0; i < entry->nServers; i++) {
2062 curserver = entry->serverNumber[i];
2063 curpart = entry->serverPartition[i];
2064 if (entry->serverFlags[i] & ITSROVOL) {
2065 volid = entry->volumeId[ROVOL];
2067 volid = entry->volumeId[RWVOL];
2069 code = UV_DeleteVolume(curserver, curpart, volid);
2078 DeleteVolume(struct cmd_syndesc *as, void *arock)
2080 afs_int32 err, code = 0;
2081 afs_uint32 server = 0;
2082 afs_int32 partition = -1;
2087 if (as->parms[0].items) {
2088 server = GetServer(as->parms[0].items->data);
2090 fprintf(STDERR, "vos: server '%s' not found in host table\n",
2091 as->parms[0].items->data);
2096 if (as->parms[1].items) {
2097 partition = volutil_GetPartitionID(as->parms[1].items->data);
2098 if (partition < 0) {
2099 fprintf(STDERR, "vos: could not interpret partition name '%s'\n",
2100 as->parms[1].items->data);
2104 /* Check for validity of the partition */
2105 if (!IsPartValid(partition, server, &code)) {
2107 PrintError("", code);
2110 "vos : partition %s does not exist on the server\n",
2111 as->parms[1].items->data);
2117 volid = vsu_GetVolumeID(as->parms[2].items->data, cstruct, &err);
2119 fprintf(STDERR, "Can't find volume name '%s' in VLDB\n",
2120 as->parms[2].items->data);
2122 PrintError("", err);
2126 /* If the server or partition option are not complete, try to fill
2127 * them in from the VLDB entry.
2129 if ((partition == -1) || !server) {
2130 struct nvldbentry entry;
2132 code = VLDB_GetEntryByID(volid, -1, &entry);
2135 "Could not fetch the entry for volume %lu from VLDB\n",
2136 (unsigned long)volid);
2137 PrintError("", code);
2141 if (((volid == entry.volumeId[RWVOL]) && (entry.flags & RW_EXISTS))
2142 || ((volid == entry.volumeId[BACKVOL])
2143 && (entry.flags & BACK_EXISTS))) {
2144 idx = Lp_GetRwIndex(&entry);
2145 if ((idx == -1) || (server && (server != entry.serverNumber[idx]))
2146 || ((partition != -1)
2147 && (partition != entry.serverPartition[idx]))) {
2148 fprintf(STDERR, "VLDB: Volume '%s' no match\n",
2149 as->parms[2].items->data);
2152 } else if ((volid == entry.volumeId[ROVOL])
2153 && (entry.flags & RO_EXISTS)) {
2154 for (idx = -1, j = 0; j < entry.nServers; j++) {
2155 if (entry.serverFlags[j] != ITSROVOL)
2158 if (((server == 0) || (server == entry.serverNumber[j]))
2159 && ((partition == -1)
2160 || (partition == entry.serverPartition[j]))) {
2163 "VLDB: Volume '%s' matches more than one RO\n",
2164 as->parms[2].items->data);
2171 fprintf(STDERR, "VLDB: Volume '%s' no match\n",
2172 as->parms[2].items->data);
2176 fprintf(STDERR, "VLDB: Volume '%s' no match\n",
2177 as->parms[2].items->data);
2181 server = htonl(entry.serverNumber[idx]);
2182 partition = entry.serverPartition[idx];
2186 code = UV_DeleteVolume(server, partition, volid);
2188 PrintDiagnostics("remove", code);
2192 MapPartIdIntoName(partition, pname);
2193 fprintf(STDOUT, "Volume %lu on partition %s server %s deleted\n",
2194 (unsigned long)volid, pname, hostutil_GetNameByINet(server));
2198 #define TESTM 0 /* set for move space tests, clear for production */
2200 MoveVolume(struct cmd_syndesc *as, void *arock)
2204 afs_uint32 fromserver, toserver;
2205 afs_int32 frompart, topart;
2206 afs_int32 flags, code, err;
2207 char fromPartName[10], toPartName[10];
2209 struct diskPartition64 partition; /* for space check */
2212 volid = vsu_GetVolumeID(as->parms[0].items->data, cstruct, &err);
2215 PrintError("", err);
2217 fprintf(STDERR, "vos: can't find volume ID or name '%s'\n",
2218 as->parms[0].items->data);
2221 fromserver = GetServer(as->parms[1].items->data);
2222 if (fromserver == 0) {
2223 fprintf(STDERR, "vos: server '%s' not found in host table\n",
2224 as->parms[1].items->data);
2227 toserver = GetServer(as->parms[3].items->data);
2228 if (toserver == 0) {
2229 fprintf(STDERR, "vos: server '%s' not found in host table\n",
2230 as->parms[3].items->data);
2233 frompart = volutil_GetPartitionID(as->parms[2].items->data);
2235 fprintf(STDERR, "vos: could not interpret partition name '%s'\n",
2236 as->parms[2].items->data);
2239 if (!IsPartValid(frompart, fromserver, &code)) { /*check for validity of the partition */
2241 PrintError("", code);
2244 "vos : partition %s does not exist on the server\n",
2245 as->parms[2].items->data);
2248 topart = volutil_GetPartitionID(as->parms[4].items->data);
2250 fprintf(STDERR, "vos: could not interpret partition name '%s'\n",
2251 as->parms[4].items->data);
2254 if (!IsPartValid(topart, toserver, &code)) { /*check for validity of the partition */
2256 PrintError("", code);
2259 "vos : partition %s does not exist on the server\n",
2260 as->parms[4].items->data);
2265 if (as->parms[5].items) flags |= RV_NOCLONE;
2268 * check source partition for space to clone volume
2271 MapPartIdIntoName(topart, toPartName);
2272 MapPartIdIntoName(frompart, fromPartName);
2275 * check target partition for space to move volume
2278 code = UV_PartitionInfo64(toserver, toPartName, &partition);
2280 fprintf(STDERR, "vos: cannot access partition %s\n", toPartName);
2284 fprintf(STDOUT, "target partition %s free space %" AFS_INT64_FMT "\n", toPartName,
2287 p = (volintInfo *) 0;
2288 code = UV_ListOneVolume(fromserver, frompart, volid, &p);
2290 fprintf(STDERR, "vos:cannot access volume %lu\n",
2291 (unsigned long)volid);
2295 fprintf(STDOUT, "volume %lu size %d\n", (unsigned long)volid,
2297 if (partition.free <= p->size) {
2299 "vos: no space on target partition %s to move volume %lu\n",
2300 toPartName, (unsigned long)volid);
2307 fprintf(STDOUT, "size test - don't do move\n");
2311 /* successful move still not guaranteed but shoot for it */
2314 UV_MoveVolume2(volid, fromserver, frompart, toserver, topart, flags);
2316 PrintDiagnostics("move", code);
2319 MapPartIdIntoName(topart, toPartName);
2320 MapPartIdIntoName(frompart, fromPartName);
2321 fprintf(STDOUT, "Volume %lu moved from %s %s to %s %s \n",
2322 (unsigned long)volid, as->parms[1].items->data, fromPartName,
2323 as->parms[3].items->data, toPartName);
2329 CopyVolume(struct cmd_syndesc *as, void *arock)
2332 afs_uint32 fromserver, toserver;
2333 afs_int32 frompart, topart, code, err, flags;
2334 char fromPartName[10], toPartName[10], *tovolume;
2335 struct nvldbentry entry;
2336 struct diskPartition64 partition; /* for space check */
2339 volid = vsu_GetVolumeID(as->parms[0].items->data, cstruct, &err);
2342 PrintError("", err);
2344 fprintf(STDERR, "vos: can't find volume ID or name '%s'\n",
2345 as->parms[0].items->data);
2348 fromserver = GetServer(as->parms[1].items->data);
2349 if (fromserver == 0) {
2350 fprintf(STDERR, "vos: server '%s' not found in host table\n",
2351 as->parms[1].items->data);
2355 toserver = GetServer(as->parms[4].items->data);
2356 if (toserver == 0) {
2357 fprintf(STDERR, "vos: server '%s' not found in host table\n",
2358 as->parms[4].items->data);
2362 tovolume = as->parms[3].items->data;
2363 if (!ISNAMEVALID(tovolume)) {
2365 "vos: the name of the root volume %s exceeds the size limit of %d\n",
2366 tovolume, VOLSER_OLDMAXVOLNAME - 10);
2369 if (!VolNameOK(tovolume)) {
2371 "Illegal volume name %s, should not end in .readonly or .backup\n",
2375 if (IsNumeric(tovolume)) {
2376 fprintf(STDERR, "Illegal volume name %s, should not be a number\n",
2380 code = VLDB_GetEntryByName(tovolume, &entry);
2382 fprintf(STDERR, "Volume %s already exists\n", tovolume);
2383 PrintDiagnostics("copy", code);
2387 frompart = volutil_GetPartitionID(as->parms[2].items->data);
2389 fprintf(STDERR, "vos: could not interpret partition name '%s'\n",
2390 as->parms[2].items->data);
2393 if (!IsPartValid(frompart, fromserver, &code)) { /*check for validity of the partition */
2395 PrintError("", code);
2398 "vos : partition %s does not exist on the server\n",
2399 as->parms[2].items->data);
2403 topart = volutil_GetPartitionID(as->parms[5].items->data);
2405 fprintf(STDERR, "vos: could not interpret partition name '%s'\n",
2406 as->parms[5].items->data);
2409 if (!IsPartValid(topart, toserver, &code)) { /*check for validity of the partition */
2411 PrintError("", code);
2414 "vos : partition %s does not exist on the server\n",
2415 as->parms[5].items->data);
2420 if (as->parms[6].items) flags |= RV_OFFLINE;
2421 if (as->parms[7].items) flags |= RV_RDONLY;
2422 if (as->parms[8].items) flags |= RV_NOCLONE;
2424 MapPartIdIntoName(topart, toPartName);
2425 MapPartIdIntoName(frompart, fromPartName);
2428 * check target partition for space to move volume
2431 code = UV_PartitionInfo64(toserver, toPartName, &partition);
2433 fprintf(STDERR, "vos: cannot access partition %s\n", toPartName);
2437 fprintf(STDOUT, "target partition %s free space %" AFS_INT64_FMT "\n", toPartName,
2440 p = (volintInfo *) 0;
2441 code = UV_ListOneVolume(fromserver, frompart, volid, &p);
2443 fprintf(STDERR, "vos:cannot access volume %lu\n",
2444 (unsigned long)volid);
2448 if (partition.free <= p->size) {
2450 "vos: no space on target partition %s to copy volume %lu\n",
2451 toPartName, (unsigned long)volid);
2457 /* successful copy still not guaranteed but shoot for it */
2460 UV_CopyVolume2(volid, fromserver, frompart, tovolume, toserver,
2463 PrintDiagnostics("copy", code);
2466 MapPartIdIntoName(topart, toPartName);
2467 MapPartIdIntoName(frompart, fromPartName);
2468 fprintf(STDOUT, "Volume %lu copied from %s %s to %s on %s %s \n",
2469 (unsigned long)volid, as->parms[1].items->data, fromPartName,
2470 tovolume, as->parms[4].items->data, toPartName);
2477 ShadowVolume(struct cmd_syndesc *as, void *arock)
2479 afs_uint32 volid, tovolid;
2480 afs_uint32 fromserver, toserver;
2481 afs_int32 frompart, topart;
2482 afs_int32 code, err, flags;
2483 char fromPartName[10], toPartName[10], toVolName[32], *tovolume;
2484 struct diskPartition64 partition; /* for space check */
2487 p = (volintInfo *) 0;
2488 q = (volintInfo *) 0;
2490 volid = vsu_GetVolumeID(as->parms[0].items->data, cstruct, &err);
2493 PrintError("", err);
2495 fprintf(STDERR, "vos: can't find volume ID or name '%s'\n",
2496 as->parms[0].items->data);
2499 fromserver = GetServer(as->parms[1].items->data);
2500 if (fromserver == 0) {
2501 fprintf(STDERR, "vos: server '%s' not found in host table\n",
2502 as->parms[1].items->data);
2506 toserver = GetServer(as->parms[3].items->data);
2507 if (toserver == 0) {
2508 fprintf(STDERR, "vos: server '%s' not found in host table\n",
2509 as->parms[3].items->data);
2513 frompart = volutil_GetPartitionID(as->parms[2].items->data);
2515 fprintf(STDERR, "vos: could not interpret partition name '%s'\n",
2516 as->parms[2].items->data);
2519 if (!IsPartValid(frompart, fromserver, &code)) { /*check for validity of the partition */
2521 PrintError("", code);
2524 "vos : partition %s does not exist on the server\n",
2525 as->parms[2].items->data);
2529 topart = volutil_GetPartitionID(as->parms[4].items->data);
2531 fprintf(STDERR, "vos: could not interpret partition name '%s'\n",
2532 as->parms[4].items->data);
2535 if (!IsPartValid(topart, toserver, &code)) { /*check for validity of the partition */
2537 PrintError("", code);
2540 "vos : partition %s does not exist on the server\n",
2541 as->parms[4].items->data);
2545 if (as->parms[5].items) {
2546 tovolume = as->parms[5].items->data;
2547 if (!ISNAMEVALID(tovolume)) {
2549 "vos: the name of the root volume %s exceeds the size limit of %d\n",
2550 tovolume, VOLSER_OLDMAXVOLNAME - 10);
2553 if (!VolNameOK(tovolume)) {
2555 "Illegal volume name %s, should not end in .readonly or .backup\n",
2559 if (IsNumeric(tovolume)) {
2561 "Illegal volume name %s, should not be a number\n",
2566 /* use actual name of source volume */
2567 code = UV_ListOneVolume(fromserver, frompart, volid, &p);
2569 fprintf(STDERR, "vos:cannot access volume %lu\n",
2570 (unsigned long)volid);
2573 strcpy(toVolName, p->name);
2574 tovolume = toVolName;
2575 /* save p for size checks later */
2578 if (as->parms[6].items) {
2579 tovolid = vsu_GetVolumeID(as->parms[6].items->data, cstruct, &err);
2582 PrintError("", err);
2584 fprintf(STDERR, "vos: can't find volume ID or name '%s'\n",
2585 as->parms[6].items->data);
2591 tovolid = vsu_GetVolumeID(tovolume, cstruct, &err);
2594 PrintError("", err);
2596 fprintf(STDERR, "vos: can't find volume ID or name '%s'\n",
2605 if (as->parms[7].items) flags |= RV_OFFLINE;
2606 if (as->parms[8].items) flags |= RV_RDONLY;
2607 if (as->parms[9].items) flags |= RV_NOCLONE;
2608 if (as->parms[10].items) flags |= RV_CPINCR;
2610 MapPartIdIntoName(topart, toPartName);
2611 MapPartIdIntoName(frompart, fromPartName);
2614 * check target partition for space to move volume
2617 code = UV_PartitionInfo64(toserver, toPartName, &partition);
2619 fprintf(STDERR, "vos: cannot access partition %s\n", toPartName);
2623 fprintf(STDOUT, "target partition %s free space %" AFS_INT64_FMT "\n", toPartName,
2626 /* Don't do this again if we did it above */
2628 code = UV_ListOneVolume(fromserver, frompart, volid, &p);
2630 fprintf(STDERR, "vos:cannot access volume %lu\n",
2631 (unsigned long)volid);
2636 /* OK if this fails */
2637 code = UV_ListOneVolume(toserver, topart, tovolid, &q);
2639 /* Treat existing volume size as "free" */
2641 p->size = (q->size < p->size) ? p->size - q->size : 0;
2643 if (partition.free <= p->size) {
2645 "vos: no space on target partition %s to copy volume %lu\n",
2646 toPartName, (unsigned long)volid);
2654 /* successful copy still not guaranteed but shoot for it */
2657 UV_CopyVolume2(volid, fromserver, frompart, tovolume, toserver,
2658 topart, tovolid, flags);
2660 PrintDiagnostics("shadow", code);
2663 MapPartIdIntoName(topart, toPartName);
2664 MapPartIdIntoName(frompart, fromPartName);
2665 fprintf(STDOUT, "Volume %lu shadowed from %s %s to %s %s \n",
2666 (unsigned long)volid, as->parms[1].items->data, fromPartName,
2667 as->parms[3].items->data, toPartName);
2674 CloneVolume(struct cmd_syndesc *as, void *arock)
2676 afs_uint32 volid, cloneid;
2678 afs_int32 part, voltype;
2679 char partName[10], *volname;
2680 afs_int32 code, err, flags;
2681 struct nvldbentry entry;
2683 volid = vsu_GetVolumeID(as->parms[0].items->data, cstruct, &err);
2686 PrintError("", err);
2688 fprintf(STDERR, "vos: can't find volume ID or name '%s'\n",
2689 as->parms[0].items->data);
2693 if (as->parms[1].items || as->parms[2].items) {
2694 if (!as->parms[1].items || !as->parms[2].items) {
2696 "Must specify both -server and -partition options\n");
2699 server = GetServer(as->parms[1].items->data);
2701 fprintf(STDERR, "vos: server '%s' not found in host table\n",
2702 as->parms[1].items->data);
2705 part = volutil_GetPartitionID(as->parms[2].items->data);
2707 fprintf(STDERR, "vos: could not interpret partition name '%s'\n",
2708 as->parms[2].items->data);
2711 if (!IsPartValid(part, server, &code)) { /*check for validity of the partition */
2713 PrintError("", code);
2716 "vos : partition %s does not exist on the server\n",
2717 as->parms[2].items->data);
2721 code = GetVolumeInfo(volid, &server, &part, &voltype, &entry);
2727 if (as->parms[3].items) {
2728 volname = as->parms[3].items->data;
2729 if (strlen(volname) > VOLSER_OLDMAXVOLNAME - 1) {
2731 "vos: the name of the root volume %s exceeds the size limit of %d\n",
2732 volname, VOLSER_OLDMAXVOLNAME - 1);
2737 * In order that you be able to make clones of RO or BK, this
2738 * check must be omitted.
2740 if (!VolNameOK(volname)) {
2742 "Illegal volume name %s, should not end in .readonly or .backup\n",
2747 if (IsNumeric(volname)) {
2749 "Illegal volume name %s, should not be a number\n",
2756 if (as->parms[4].items) {
2757 cloneid = vsu_GetVolumeID(as->parms[4].items->data, cstruct, &err);
2760 PrintError("", err);
2762 fprintf(STDERR, "vos: can't find volume ID or name '%s'\n",
2763 as->parms[4].items->data);
2769 if (as->parms[5].items) flags |= RV_OFFLINE;
2770 if (as->parms[6].items && as->parms[7].items) {
2771 fprintf(STDERR, "vos: cannot specify that a volume be -readwrite and -readonly\n");
2774 if (as->parms[6].items) flags |= RV_RDONLY;
2775 if (as->parms[7].items) flags |= RV_RWONLY;
2779 UV_CloneVolume(server, part, volid, cloneid, volname, flags);
2782 PrintDiagnostics("clone", code);
2785 MapPartIdIntoName(part, partName);
2786 fprintf(STDOUT, "Created clone for volume %s\n",
2787 as->parms[0].items->data);
2794 BackupVolume(struct cmd_syndesc *as, void *arock)
2798 afs_int32 apart, vtype, code, err;
2799 struct nvldbentry entry;
2802 afs_uint32 buserver;
2803 afs_int32 bupart, butype;
2804 struct nvldbentry buentry;
2806 avolid = vsu_GetVolumeID(as->parms[0].items->data, cstruct, &err);
2809 PrintError("", err);
2811 fprintf(STDERR, "vos: can't find volume ID or name '%s'\n",
2812 as->parms[0].items->data);
2815 code = GetVolumeInfo(avolid, &aserver, &apart, &vtype, &entry);
2819 /* verify this is a readwrite volume */
2821 if (vtype != RWVOL) {
2822 fprintf(STDERR, "%s not RW volume\n", as->parms[0].items->data);
2826 /* is there a backup volume already? */
2828 if (entry.flags & BACK_EXISTS) {
2829 /* yep, where is it? */
2831 buvolid = entry.volumeId[BACKVOL];
2832 code = GetVolumeInfo(buvolid, &buserver, &bupart, &butype, &buentry);
2837 code = VLDB_IsSameAddrs(buserver, aserver, &err);
2840 "Failed to get info about server's %d address(es) from vlserver; aborting call!\n",
2846 "FATAL ERROR: backup volume %lu exists on server %lu\n",
2847 (unsigned long)buvolid, (unsigned long)buserver);
2852 /* nope, carry on */
2854 code = UV_BackupVolume(aserver, apart, avolid);
2857 PrintDiagnostics("backup", code);
2860 fprintf(STDOUT, "Created backup volume for %s \n",
2861 as->parms[0].items->data);
2866 ReleaseVolume(struct cmd_syndesc *as, void *arock)
2869 struct nvldbentry entry;
2872 afs_int32 apart, vtype, code, err;
2876 if (as->parms[1].items)
2878 if (as->parms[2].items)
2880 avolid = vsu_GetVolumeID(as->parms[0].items->data, cstruct, &err);
2883 PrintError("", err);
2885 fprintf(STDERR, "vos: can't find volume '%s'\n",
2886 as->parms[0].items->data);
2889 code = GetVolumeInfo(avolid, &aserver, &apart, &vtype, &entry);
2893 if (vtype != RWVOL) {
2894 fprintf(STDERR, "%s not a RW volume\n", as->parms[0].items->data);
2898 if (!ISNAMEVALID(entry.name)) {
2900 "Volume name %s is too long, rename before releasing\n",
2905 code = UV_ReleaseVolume(avolid, aserver, apart, force, stayUp);
2908 PrintDiagnostics("release", code);
2911 fprintf(STDOUT, "Released volume %s successfully\n",
2912 as->parms[0].items->data);
2917 DumpVolumeCmd(struct cmd_syndesc *as, void *arock)
2921 afs_int32 apart, voltype, fromdate = 0, code, err, i, flags;
2922 char filename[MAXPATHLEN];
2923 struct nvldbentry entry;
2925 rx_SetRxDeadTime(60 * 10);
2926 for (i = 0; i < MAXSERVERS; i++) {
2927 struct rx_connection *rxConn = ubik_GetRPCConn(cstruct, i);
2930 rx_SetConnDeadTime(rxConn, rx_connDeadTime);
2931 if (rx_ServiceOf(rxConn))
2932 rx_ServiceOf(rxConn)->connDeadTime = rx_connDeadTime;
2935 avolid = vsu_GetVolumeID(as->parms[0].items->data, cstruct, &err);
2938 PrintError("", err);
2940 fprintf(STDERR, "vos: can't find volume '%s'\n",
2941 as->parms[0].items->data);
2945 if (as->parms[3].items || as->parms[4].items) {
2946 if (!as->parms[3].items || !as->parms[4].items) {
2948 "Must specify both -server and -partition options\n");
2951 aserver = GetServer(as->parms[3].items->data);
2953 fprintf(STDERR, "Invalid server name\n");
2956 apart = volutil_GetPartitionID(as->parms[4].items->data);
2958 fprintf(STDERR, "Invalid partition name\n");
2962 code = GetVolumeInfo(avolid, &aserver, &apart, &voltype, &entry);
2967 if (as->parms[1].items && strcmp(as->parms[1].items->data, "0")) {
2968 code = ktime_DateToInt32(as->parms[1].items->data, &fromdate);
2970 fprintf(STDERR, "vos: failed to parse date '%s' (error=%d))\n",
2971 as->parms[1].items->data, code);
2975 if (as->parms[2].items) {
2976 strcpy(filename, as->parms[2].items->data);
2978 strcpy(filename, "");
2981 flags = as->parms[6].items ? VOLDUMPV2_OMITDIRS : 0;
2983 if (as->parms[5].items) {
2985 UV_DumpClonedVolume(avolid, aserver, apart, fromdate,
2986 DumpFunction, filename, flags);
2989 UV_DumpVolume(avolid, aserver, apart, fromdate, DumpFunction,
2992 if ((code == RXGEN_OPCODE) && (as->parms[6].items)) {
2993 flags &= ~VOLDUMPV2_OMITDIRS;
2997 PrintDiagnostics("dump", code);
3000 if (strcmp(filename, ""))
3001 fprintf(STDERR, "Dumped volume %s in file %s\n",
3002 as->parms[0].items->data, filename);
3004 fprintf(STDERR, "Dumped volume %s in stdout \n",
3005 as->parms[0].items->data);
3019 RestoreVolumeCmd(struct cmd_syndesc *as, void *arock)
3021 afs_uint32 avolid, aparentid;
3023 afs_int32 apart, code, vcode, err;
3024 afs_int32 aoverwrite = ASK;
3025 afs_int32 acreation = 0, alastupdate = 0;
3026 int restoreflags = 0;
3027 int readonly = 0, offline = 0, voltype = RWVOL;
3028 char afilename[MAXPATHLEN], avolname[VOLSER_MAXVOLNAME + 1], apartName[10];
3029 char volname[VOLSER_MAXVOLNAME + 1];
3030 struct nvldbentry entry;
3033 if (as->parms[4].items) {
3034 avolid = vsu_GetVolumeID(as->parms[4].items->data, cstruct, &err);
3037 PrintError("", err);
3039 fprintf(STDERR, "vos: can't find volume '%s'\n",
3040 as->parms[4].items->data);
3046 if (as->parms[5].items) {
3047 if ((strcmp(as->parms[5].items->data, "a") == 0)
3048 || (strcmp(as->parms[5].items->data, "abort") == 0)) {
3050 } else if ((strcmp(as->parms[5].items->data, "f") == 0)
3051 || (strcmp(as->parms[5].items->data, "full") == 0)) {
3053 } else if ((strcmp(as->parms[5].items->data, "i") == 0)
3054 || (strcmp(as->parms[5].items->data, "inc") == 0)
3055 || (strcmp(as->parms[5].items->data, "increment") == 0)
3056 || (strcmp(as->parms[5].items->data, "incremental") == 0)) {
3059 fprintf(STDERR, "vos: %s is not a valid argument to -overwrite\n",
3060 as->parms[5].items->data);
3064 if (as->parms[6].items)
3066 if (as->parms[7].items) {
3071 if (as->parms[8].items) {
3072 if ((strcmp(as->parms[8].items->data, "d") == 0)
3073 || (strcmp(as->parms[8].items->data, "dump") == 0)) {
3074 acreation = TS_DUMP;
3075 } else if ((strcmp(as->parms[8].items->data, "k") == 0)
3076 || (strcmp(as->parms[8].items->data, "keep") == 0)) {
3077 acreation = TS_KEEP;
3078 } else if ((strcmp(as->parms[8].items->data, "n") == 0)
3079 || (strcmp(as->parms[8].items->data, "new") == 0)) {
3082 fprintf(STDERR, "vos: %s is not a valid argument to -creation\n",
3083 as->parms[8].items->data);
3088 if (as->parms[9].items) {
3089 if ((strcmp(as->parms[9].items->data, "d") == 0)
3090 || (strcmp(as->parms[9].items->data, "dump") == 0)) {
3091 alastupdate = TS_DUMP;
3092 } else if ((strcmp(as->parms[9].items->data, "k") == 0)
3093 || (strcmp(as->parms[9].items->data, "keep") == 0)) {
3094 alastupdate = TS_KEEP;
3095 } else if ((strcmp(as->parms[9].items->data, "n") == 0)
3096 || (strcmp(as->parms[9].items->data, "new") == 0)) {
3097 alastupdate = TS_NEW;
3099 fprintf(STDERR, "vos: %s is not a valid argument to -lastupdate\n",
3100 as->parms[9].items->data);
3105 aserver = GetServer(as->parms[0].items->data);
3107 fprintf(STDERR, "vos: server '%s' not found in host table\n",
3108 as->parms[0].items->data);
3111 apart = volutil_GetPartitionID(as->parms[1].items->data);
3113 fprintf(STDERR, "vos: could not interpret partition name '%s'\n",
3114 as->parms[1].items->data);
3117 if (!IsPartValid(apart, aserver, &code)) { /*check for validity of the partition */
3119 PrintError("", code);
3122 "vos : partition %s does not exist on the server\n",
3123 as->parms[1].items->data);
3126 strcpy(avolname, as->parms[2].items->data);
3127 if (!ISNAMEVALID(avolname)) {
3129 "vos: the name of the volume %s exceeds the size limit\n",
3133 if (!VolNameOK(avolname)) {
3135 "Illegal volume name %s, should not end in .readonly or .backup\n",
3139 if (as->parms[3].items) {
3140 strcpy(afilename, as->parms[3].items->data);
3141 if (!FileExists(afilename)) {
3142 fprintf(STDERR, "Can't access file %s\n", afilename);
3146 strcpy(afilename, "");
3149 /* Check if volume exists or not */
3151 vsu_ExtractName(volname, avolname);
3152 vcode = VLDB_GetEntryByName(volname, &entry);
3153 if (vcode) { /* no volume - do a full restore */
3154 restoreflags = RV_FULLRST;
3155 if ((aoverwrite == INC) || (aoverwrite == ABORT))
3157 "Volume does not exist; Will perform a full restore\n");
3160 else if ((!readonly && Lp_GetRwIndex(&entry) == -1) /* RW volume does not exist - do a full */
3161 ||(readonly && !Lp_ROMatch(0, 0, &entry))) { /* RO volume does not exist - do a full */
3162 restoreflags = RV_FULLRST;
3163 if ((aoverwrite == INC) || (aoverwrite == ABORT))
3165 "%s Volume does not exist; Will perform a full restore\n",
3166 readonly ? "RO" : "RW");
3169 avolid = entry.volumeId[voltype];
3170 } else if (entry.volumeId[voltype] != 0
3171 && entry.volumeId[voltype] != avolid) {
3172 avolid = entry.volumeId[voltype];
3174 aparentid = entry.volumeId[RWVOL];
3177 else { /* volume exists - do we do a full incremental or abort */
3179 afs_int32 Opart, Otype, vol_elsewhere = 0;
3180 struct nvldbentry Oentry;
3184 avolid = entry.volumeId[voltype];
3185 } else if (entry.volumeId[voltype] != 0
3186 && entry.volumeId[voltype] != avolid) {
3187 avolid = entry.volumeId[voltype];
3189 aparentid = entry.volumeId[RWVOL];
3191 /* A file name was specified - check if volume is on another partition */
3192 vcode = GetVolumeInfo(avolid, &Oserver, &Opart, &Otype, &Oentry);
3196 vcode = VLDB_IsSameAddrs(Oserver, aserver, &err);
3199 "Failed to get info about server's %d address(es) from vlserver (err=%d); aborting call!\n",
3203 if (!vcode || (Opart != apart))
3206 if (aoverwrite == ASK) {
3207 if (strcmp(afilename, "") == 0) { /* The file is from standard in */
3209 "Volume exists and no -overwrite option specified; Aborting restore command\n");
3213 /* Ask what to do */
3214 if (vol_elsewhere) {
3216 "The volume %s %u already exists on a different server/part\n",
3217 volname, entry.volumeId[voltype]);
3219 "Do you want to do a full restore or abort? [fa](a): ");
3222 "The volume %s %u already exists in the VLDB\n",
3223 volname, entry.volumeId[voltype]);
3225 "Do you want to do a full/incremental restore or abort? [fia](a): ");
3228 while (!(dc == EOF || dc == '\n'))
3229 dc = getchar(); /* goto end of line */
3230 if ((c == 'f') || (c == 'F'))
3232 else if ((c == 'i') || (c == 'I'))
3238 if (aoverwrite == ABORT) {
3239 fprintf(STDERR, "Volume exists; Aborting restore command\n");
3241 } else if (aoverwrite == FULL) {
3242 restoreflags = RV_FULLRST;
3244 "Volume exists; Will delete and perform full restore\n");
3245 } else if (aoverwrite == INC) {
3247 if (vol_elsewhere) {
3249 "%s volume %lu already exists on a different server/part; not allowed\n",
3250 readonly ? "RO" : "RW", (unsigned long)avolid);
3256 restoreflags |= RV_OFFLINE;
3258 restoreflags |= RV_RDONLY;
3260 switch (acreation) {
3262 restoreflags |= RV_CRDUMP;
3265 restoreflags |= RV_CRKEEP;
3268 restoreflags |= RV_CRNEW;
3271 if (aoverwrite == FULL)
3272 restoreflags |= RV_CRNEW;
3274 restoreflags |= RV_CRKEEP;
3277 switch (alastupdate) {
3279 restoreflags |= RV_LUDUMP;
3282 restoreflags |= RV_LUKEEP;
3285 restoreflags |= RV_LUNEW;
3288 restoreflags |= RV_LUDUMP;
3290 if (as->parms[10].items) {
3291 restoreflags |= RV_NODEL;
3296 UV_RestoreVolume2(aserver, apart, avolid, aparentid,
3297 avolname, restoreflags, WriteData, afilename);
3299 PrintDiagnostics("restore", code);
3302 MapPartIdIntoName(apart, apartName);
3305 * patch typo here - originally "parms[1]", should be "parms[0]"
3308 fprintf(STDOUT, "Restored volume %s on %s %s\n", avolname,
3309 as->parms[0].items->data, apartName);
3314 LockReleaseCmd(struct cmd_syndesc *as, void *arock)
3317 afs_int32 code, err;
3319 avolid = vsu_GetVolumeID(as->parms[0].items->data, cstruct, &err);
3322 PrintError("", err);
3324 fprintf(STDERR, "vos: can't find volume '%s'\n",
3325 as->parms[0].items->data);
3329 code = UV_LockRelease(avolid);
3331 PrintDiagnostics("unlock", code);
3334 fprintf(STDOUT, "Released lock on vldb entry for volume %s\n",
3335 as->parms[0].items->data);
3340 AddSite(struct cmd_syndesc *as, void *arock)
3344 afs_int32 apart, code, err, arovolid, valid = 0;
3345 char apartName[10], avolname[VOLSER_MAXVOLNAME + 1];
3347 vsu_ExtractName(avolname, as->parms[2].items->data);;
3348 avolid = vsu_GetVolumeID(avolname, cstruct, &err);
3351 PrintError("", err);
3353 fprintf(STDERR, "vos: can't find volume '%s'\n",
3354 as->parms[2].items->data);
3358 if (as->parms[3].items) {
3359 vsu_ExtractName(avolname, as->parms[3].items->data);
3360 arovolid = vsu_GetVolumeID(avolname, cstruct, &err);
3362 fprintf(STDERR, "vos: invalid ro volume id '%s'\n",
3363 as->parms[3].items->data);
3367 aserver = GetServer(as->parms[0].items->data);
3369 fprintf(STDERR, "vos: server '%s' not found in host table\n",
3370 as->parms[0].items->data);
3373 apart = volutil_GetPartitionID(as->parms[1].items->data);
3375 fprintf(STDERR, "vos: could not interpret partition name '%s'\n",
3376 as->parms[1].items->data);
3379 if (!IsPartValid(apart, aserver, &code)) { /*check for validity of the partition */
3381 PrintError("", code);
3384 "vos : partition %s does not exist on the server\n",
3385 as->parms[1].items->data);
3388 if (as->parms[4].items) {
3391 code = UV_AddSite2(aserver, apart, avolid, arovolid, valid);
3393 PrintDiagnostics("addsite", code);
3396 MapPartIdIntoName(apart, apartName);
3397 fprintf(STDOUT, "Added replication site %s %s for volume %s\n",
3398 as->parms[0].items->data, apartName, as->parms[2].items->data);
3403 RemoveSite(struct cmd_syndesc *as, void *arock)
3408 afs_int32 apart, code, err;
3409 char apartName[10], avolname[VOLSER_MAXVOLNAME + 1];
3411 vsu_ExtractName(avolname, as->parms[2].items->data);
3412 avolid = vsu_GetVolumeID(avolname, cstruct, &err);
3415 PrintError("", err);
3417 fprintf(STDERR, "vos: can't find volume '%s'\n",
3418 as->parms[2].items->data);
3421 aserver = GetServer(as->parms[0].items->data);
3423 fprintf(STDERR, "vos: server '%s' not found in host table\n",
3424 as->parms[0].items->data);
3427 apart = volutil_GetPartitionID(as->parms[1].items->data);
3429 fprintf(STDERR, "vos: could not interpret partition name '%s'\n",
3430 as->parms[1].items->data);
3434 *skip the partition validity check, since it is possible that the partition
3435 *has since been decomissioned.
3438 if (!IsPartValid(apart,aserver,&code)){
3439 if(code) PrintError("",code);
3440 else fprintf(STDERR,"vos : partition %s does not exist on the server\n",as->parms[1].items->data);
3444 code = UV_RemoveSite(aserver, apart, avolid);
3446 PrintDiagnostics("remsite", code);
3449 MapPartIdIntoName(apart, apartName);
3450 fprintf(STDOUT, "Removed replication site %s %s for volume %s\n",
3451 as->parms[0].items->data, apartName, as->parms[2].items->data);
3456 ChangeLocation(struct cmd_syndesc *as, void *arock)
3460 afs_int32 apart, code, err;
3463 avolid = vsu_GetVolumeID(as->parms[2].items->data, cstruct, &err);
3466 PrintError("", err);
3468 fprintf(STDERR, "vos: can't find volume '%s'\n",
3469 as->parms[2].items->data);
3472 aserver = GetServer(as->parms[0].items->data);
3474 fprintf(STDERR, "vos: server '%s' not found in host table\n",
3475 as->parms[0].items->data);
3478 apart = volutil_GetPartitionID(as->parms[1].items->data);
3480 fprintf(STDERR, "vos: could not interpret partition name '%s'\n",
3481 as->parms[1].items->data);
3484 if (!IsPartValid(apart, aserver, &code)) { /*check for validity of the partition */
3486 PrintError("", code);
3489 "vos : partition %s does not exist on the server\n",
3490 as->parms[1].items->data);
3493 code = UV_ChangeLocation(aserver, apart, avolid);
3495 PrintDiagnostics("changeloc", code);
3498 MapPartIdIntoName(apart, apartName);
3499 fprintf(STDOUT, "Changed location to %s %s for volume %s\n",
3500 as->parms[0].items->data, apartName, as->parms[2].items->data);
3505 ListPartitions(struct cmd_syndesc *as, void *arock)
3509 struct partList dummyPartList;
3514 aserver = GetServer(as->parms[0].items->data);
3516 fprintf(STDERR, "vos: server '%s' not found in host table\n",
3517 as->parms[0].items->data);
3522 code = UV_ListPartitions(aserver, &dummyPartList, &cnt);
3524 PrintDiagnostics("listpart", code);
3528 fprintf(STDOUT, "The partitions on the server are:\n");
3529 for (i = 0; i < cnt; i++) {
3530 if (dummyPartList.partFlags[i] & PARTVALID) {
3531 memset(pname, 0, sizeof(pname));
3532 MapPartIdIntoName(dummyPartList.partId[i], pname);
3533 fprintf(STDOUT, " %10s ", pname);
3535 if ((i % 5) == 0 && (i != 0))
3536 fprintf(STDOUT, "\n");
3539 fprintf(STDOUT, "\n");
3540 fprintf(STDOUT, "Total: %d\n", total);
3546 CompareVolName(const void *p1, const void *p2)
3548 volintInfo *arg1, *arg2;
3550 arg1 = (volintInfo *) p1;
3551 arg2 = (volintInfo *) p2;
3552 return (strcmp(arg1->name, arg2->name));
3556 /*------------------------------------------------------------------------
3557 * PRIVATE XCompareVolName
3560 * Comparison routine for volume names coming from an extended
3564 * a_obj1P : Char ptr to first extended vol info object
3565 * a_obj1P : Char ptr to second extended vol info object
3568 * The value of strcmp() on the volume names within the passed
3569 * objects (i,e., -1, 0, or 1).
3572 * Passed to qsort() as the designated comparison routine.
3576 *------------------------------------------------------------------------*/
3579 XCompareVolName(const void *a_obj1P, const void *a_obj2P)
3580 { /*XCompareVolName */
3583 (((struct volintXInfo *)(a_obj1P))->name,
3584 ((struct volintXInfo *)(a_obj2P))->name));
3586 } /*XCompareVolName */
3589 CompareVolID(const void *p1, const void *p2)
3591 volintInfo *arg1, *arg2;
3593 arg1 = (volintInfo *) p1;
3594 arg2 = (volintInfo *) p2;
3595 if (arg1->volid == arg2->volid)
3597 if (arg1->volid > arg2->volid)
3604 /*------------------------------------------------------------------------
3605 * PRIVATE XCompareVolID
3608 * Comparison routine for volume IDs coming from an extended
3612 * a_obj1P : Char ptr to first extended vol info object
3613 * a_obj1P : Char ptr to second extended vol info object
3616 * The value of strcmp() on the volume names within the passed
3617 * objects (i,e., -1, 0, or 1).
3620 * Passed to qsort() as the designated comparison routine.
3624 *------------------------------------------------------------------------*/
3627 XCompareVolID(const void *a_obj1P, const void *a_obj2P)
3628 { /*XCompareVolID */
3630 afs_int32 id1, id2; /*Volume IDs we're comparing */
3632 id1 = ((struct volintXInfo *)(a_obj1P))->volid;
3633 id2 = ((struct volintXInfo *)(a_obj2P))->volid;
3641 } /*XCompareVolID */
3643 /*------------------------------------------------------------------------
3644 * PRIVATE ListVolumes
3647 * Routine used to list volumes, contacting the Volume Server
3648 * directly, bypassing the VLDB.
3651 * as : Ptr to parsed command line arguments.
3654 * 0 Successful operation
3657 * Nothing interesting.
3661 *------------------------------------------------------------------------*/
3664 ListVolumes(struct cmd_syndesc *as, void *arock)
3666 afs_int32 apart, int32list, fast;
3670 volintInfo *oldpntr = NULL;
3674 volintXInfo *xInfoP;
3675 volintXInfo *origxInfoP = NULL; /*Ptr to current/orig extended vol info */
3676 int wantExtendedInfo; /*Do we want extended vol info? */
3679 struct partList dummyPartList;
3687 if (as->parms[3].items)
3689 if (as->parms[4].items)
3693 if (as->parms[2].items)
3699 if (as->parms[5].items) {
3701 * We can't coexist with the fast flag.
3705 "vos: Can't use the -fast and -extended flags together\n");
3710 * We need to turn on ``long'' listings to get the full effect.
3712 wantExtendedInfo = 1;
3715 wantExtendedInfo = 0;
3716 if (as->parms[1].items) {
3717 apart = volutil_GetPartitionID(as->parms[1].items->data);
3719 fprintf(STDERR, "vos: could not interpret partition name '%s'\n",
3720 as->parms[1].items->data);
3723 dummyPartList.partId[0] = apart;
3724 dummyPartList.partFlags[0] = PARTVALID;
3727 aserver = GetServer(as->parms[0].items->data);
3729 fprintf(STDERR, "vos: server '%s' not found in host table\n",
3730 as->parms[0].items->data);
3735 if (!IsPartValid(apart, aserver, &code)) { /*check for validity of the partition */
3737 PrintError("", code);
3740 "vos : partition %s does not exist on the server\n",
3741 as->parms[1].items->data);
3745 code = UV_ListPartitions(aserver, &dummyPartList, &cnt);
3747 PrintDiagnostics("listvol", code);
3751 for (i = 0; i < cnt; i++) {
3752 if (dummyPartList.partFlags[i] & PARTVALID) {
3753 if (wantExtendedInfo)
3755 UV_XListVolumes(aserver, dummyPartList.partId[i], all,
3759 UV_ListVolumes(aserver, dummyPartList.partId[i], all,
3762 PrintDiagnostics("listvol", code);
3765 if (wantExtendedInfo) {
3766 origxInfoP = xInfoP;
3767 base = (char *)xInfoP;
3770 base = (char *)pntr;
3774 if (wantExtendedInfo)
3775 qsort(base, count, sizeof(volintXInfo), XCompareVolName);
3777 qsort(base, count, sizeof(volintInfo), CompareVolName);
3779 if (wantExtendedInfo)
3780 qsort(base, count, sizeof(volintXInfo), XCompareVolID);
3782 qsort(base, count, sizeof(volintInfo), CompareVolID);
3784 MapPartIdIntoName(dummyPartList.partId[i], pname);
3787 "Total number of volumes on server %s partition %s: %lu \n",
3788 as->parms[0].items->data, pname,
3789 (unsigned long)count);
3790 if (wantExtendedInfo) {
3791 if (as->parms[6].items)
3792 XDisplayVolumes2(aserver, dummyPartList.partId[i], origxInfoP,
3793 count, int32list, fast, quiet);
3795 XDisplayVolumes(aserver, dummyPartList.partId[i], origxInfoP,
3796 count, int32list, fast, quiet);
3799 xInfoP = (volintXInfo *) 0;
3801 if (as->parms[6].items)
3802 DisplayVolumes2(aserver, dummyPartList.partId[i], oldpntr,
3805 DisplayVolumes(aserver, dummyPartList.partId[i], oldpntr,
3806 count, int32list, fast, quiet);
3809 pntr = (volintInfo *) 0;
3817 SyncVldb(struct cmd_syndesc *as, void *arock)
3819 afs_int32 pnum = 0, code; /* part name */
3826 if (as->parms[0].items) {
3827 tserver = GetServer(as->parms[0].items->data);
3829 fprintf(STDERR, "vos: host '%s' not found in host table\n",
3830 as->parms[0].items->data);
3835 if (as->parms[1].items) {
3836 pnum = volutil_GetPartitionID(as->parms[1].items->data);
3838 fprintf(STDERR, "vos: could not interpret partition name '%s'\n",
3839 as->parms[1].items->data);
3842 if (!IsPartValid(pnum, tserver, &code)) { /*check for validity of the partition */
3844 PrintError("", code);
3847 "vos: partition %s does not exist on the server\n",
3848 as->parms[1].items->data);
3855 "The -partition option requires a -server option\n");
3860 if (as->parms[3].items) {
3861 flags |= 2; /* don't update */
3864 if (as->parms[2].items) {
3865 /* Synchronize an individual volume */
3866 volname = as->parms[2].items->data;
3867 code = UV_SyncVolume(tserver, pnum, volname, flags);
3871 "Without a -volume option, the -server option is required\n");
3874 code = UV_SyncVldb(tserver, pnum, flags, 0 /*unused */ );
3878 PrintDiagnostics("syncvldb", code);
3882 /* Print a summary of what we did */
3884 fprintf(STDOUT, "VLDB volume %s synchronized", volname);
3886 fprintf(STDOUT, "VLDB synchronized");
3888 fprintf(STDOUT, " with state of server %s", as->parms[0].items->data);
3891 MapPartIdIntoName(pnum, part);
3892 fprintf(STDOUT, " partition %s\n", part);
3894 fprintf(STDOUT, "\n");
3900 SyncServer(struct cmd_syndesc *as, void *arock)
3902 afs_int32 pnum, code; /* part name */
3908 tserver = GetServer(as->parms[0].items->data);
3910 fprintf(STDERR, "vos: host '%s' not found in host table\n",
3911 as->parms[0].items->data);
3914 if (as->parms[1].items) {
3915 pnum = volutil_GetPartitionID(as->parms[1].items->data);
3917 fprintf(STDERR, "vos: could not interpret partition name '%s'\n",
3918 as->parms[1].items->data);
3921 if (!IsPartValid(pnum, tserver, &code)) { /*check for validity of the partition */
3923 PrintError("", code);
3926 "vos : partition %s does not exist on the server\n",
3927 as->parms[1].items->data);
3935 if (as->parms[2].items) {
3936 flags |= 2; /* don't update */
3938 code = UV_SyncServer(tserver, pnum, flags, 0 /*unused */ );
3940 PrintDiagnostics("syncserv", code);
3944 MapPartIdIntoName(pnum, part);
3945 fprintf(STDOUT, "Server %s partition %s synchronized with VLDB\n",
3946 as->parms[0].items->data, part);
3948 fprintf(STDOUT, "Server %s synchronized with VLDB\n",
3949 as->parms[0].items->data);
3955 VolumeInfoCmd(char *name)
3957 struct nvldbentry entry;
3960 /* The vlserver will handle names with the .readonly
3961 * and .backup extension as well as volume ids.
3963 vcode = VLDB_GetEntryByName(name, &entry);
3965 PrintError("", vcode);
3968 MapHostToNetwork(&entry);
3969 EnumerateEntry(&entry);
3971 /* Defect #3027: grubby check to handle locked volume.
3972 * If VLOP_ALLOPERS is set, the entry is locked.
3973 * Leave this routine as is, but put in correct check.
3975 PrintLocked(entry.flags);
3981 VolumeZap(struct cmd_syndesc *as, void *arock)
3983 struct nvldbentry entry;
3984 afs_uint32 volid, zapbackupid = 0, backupid = 0;
3985 afs_int32 code, server, part, err;
3987 if (as->parms[3].items) {
3988 /* force flag is on, use the other version */
3989 return NukeVolume(as);
3992 if (as->parms[4].items) {
3996 volid = vsu_GetVolumeID(as->parms[2].items->data, cstruct, &err);
3999 PrintError("", err);
4001 fprintf(STDERR, "vos: can't find volume '%s'\n",
4002 as->parms[2].items->data);
4005 part = volutil_GetPartitionID(as->parms[1].items->data);
4007 fprintf(STDERR, "vos: could not interpret partition name '%s'\n",
4008 as->parms[1].items->data);
4011 server = GetServer(as->parms[0].items->data);
4013 fprintf(STDERR, "vos: host '%s' not found in host table\n",
4014 as->parms[0].items->data);
4017 if (!IsPartValid(part, server, &code)) { /*check for validity of the partition */
4019 PrintError("", code);
4022 "vos : partition %s does not exist on the server\n",
4023 as->parms[1].items->data);
4026 code = VLDB_GetEntryByID(volid, -1, &entry);
4028 if (volid == entry.volumeId[RWVOL])
4029 backupid = entry.volumeId[BACKVOL];
4031 "Warning: Entry for volume number %lu exists in VLDB (but we're zapping it anyway!)\n",
4032 (unsigned long)volid);
4035 volintInfo *pntr = (volintInfo *) 0;
4038 code = UV_ListOneVolume(server, part, volid, &pntr);
4040 if (volid == pntr->parentID)
4041 backupid = pntr->backupID;
4047 code = UV_VolumeZap(server, part, backupid);
4049 PrintDiagnostics("zap", code);
4052 fprintf(STDOUT, "Backup Volume %lu deleted\n",
4053 (unsigned long)backupid);
4056 code = UV_VolumeZap(server, part, volid);
4058 PrintDiagnostics("zap", code);
4061 fprintf(STDOUT, "Volume %lu deleted\n", (unsigned long)volid);
4067 VolserStatus(struct cmd_syndesc *as, void *arock)
4071 transDebugInfo *pntr, *oldpntr;
4077 server = GetServer(as->parms[0].items->data);
4079 fprintf(STDERR, "vos: host '%s' not found in host table\n",
4080 as->parms[0].items->data);
4083 code = UV_VolserStatus(server, &pntr, &count);
4085 PrintDiagnostics("status", code);
4090 fprintf(STDOUT, "No active transactions on %s\n",
4091 as->parms[0].items->data);
4093 fprintf(STDOUT, "Total transactions: %d\n", count);
4095 for (i = 0; i < count; i++) {
4096 /*print out the relevant info */
4097 fprintf(STDOUT, "--------------------------------------\n");
4098 t = pntr->creationTime;
4099 fprintf(STDOUT, "transaction: %lu created: %s",
4100 (unsigned long)pntr->tid, ctime(&t));
4102 fprintf(STDOUT, "lastActiveTime: %s", ctime(&t));
4103 if (pntr->returnCode) {
4104 fprintf(STDOUT, "returnCode: %lu\n",
4105 (unsigned long)pntr->returnCode);
4108 fprintf(STDOUT, "attachFlags: ");
4109 switch (pntr->iflags) {
4111 fprintf(STDOUT, "offline ");
4114 fprintf(STDOUT, "busy ");
4117 fprintf(STDOUT, "readonly ");
4120 fprintf(STDOUT, "create ");
4123 fprintf(STDOUT, "create volid ");
4126 fprintf(STDOUT, "\n");
4129 fprintf(STDOUT, "volumeStatus: ");
4130 switch (pntr->vflags) {
4131 case VTDeleteOnSalvage:
4132 fprintf(STDOUT, "deleteOnSalvage ");
4133 case VTOutOfService:
4134 fprintf(STDOUT, "outOfService ");
4136 fprintf(STDOUT, "deleted ");
4138 fprintf(STDOUT, "\n");
4141 fprintf(STDOUT, "transactionFlags: ");
4142 fprintf(STDOUT, "delete\n");
4144 MapPartIdIntoName(pntr->partition, pname);
4145 fprintf(STDOUT, "volume: %lu partition: %s procedure: %s\n",
4146 (unsigned long)pntr->volid, pname, pntr->lastProcName);
4147 if (pntr->callValid) {
4148 t = pntr->lastReceiveTime;
4149 fprintf(STDOUT, "packetRead: %lu lastReceiveTime: %s",
4150 (unsigned long)pntr->readNext, ctime(&t));
4151 t = pntr->lastSendTime;
4152 fprintf(STDOUT, "packetSend: %lu lastSendTime: %s",
4153 (unsigned long)pntr->transmitNext, ctime(&t));
4156 fprintf(STDOUT, "--------------------------------------\n");
4157 fprintf(STDOUT, "\n");
4165 RenameVolume(struct cmd_syndesc *as, void *arock)
4167 afs_int32 code1, code2, code;
4168 struct nvldbentry entry;
4170 code1 = VLDB_GetEntryByName(as->parms[0].items->data, &entry);
4172 fprintf(STDERR, "vos: Could not find entry for volume %s\n",
4173 as->parms[0].items->data);
4176 code2 = VLDB_GetEntryByName(as->parms[1].items->data, &entry);
4177 if ((!code1) && (!code2)) { /*the newname already exists */
4178 fprintf(STDERR, "vos: volume %s already exists\n",
4179 as->parms[1].items->data);
4183 if (code1 && code2) {
4184 fprintf(STDERR, "vos: Could not find entry for volume %s or %s\n",
4185 as->parms[0].items->data, as->parms[1].items->data);
4188 if (!VolNameOK(as->parms[0].items->data)) {
4190 "Illegal volume name %s, should not end in .readonly or .backup\n",
4191 as->parms[0].items->data);
4194 if (!ISNAMEVALID(as->parms[1].items->data)) {
4196 "vos: the new volume name %s exceeds the size limit of %d\n",
4197 as->parms[1].items->data, VOLSER_OLDMAXVOLNAME - 10);
4200 if (!VolNameOK(as->parms[1].items->data)) {
4202 "Illegal volume name %s, should not end in .readonly or .backup\n",
4203 as->parms[1].items->data);
4206 if (IsNumeric(as->parms[1].items->data)) {
4207 fprintf(STDERR, "Illegal volume name %s, should not be a number\n",
4208 as->parms[1].items->data);
4211 MapHostToNetwork(&entry);
4213 UV_RenameVolume(&entry, as->parms[0].items->data,
4214 as->parms[1].items->data);
4216 PrintDiagnostics("rename", code);
4219 fprintf(STDOUT, "Renamed volume %s to %s\n", as->parms[0].items->data,
4220 as->parms[1].items->data);
4225 GetVolumeInfo(afs_uint32 volid, afs_uint32 *server, afs_int32 *part, afs_int32 *voltype,
4226 struct nvldbentry *rentry)
4231 vcode = VLDB_GetEntryByID(volid, -1, rentry);
4234 "Could not fetch the entry for volume %lu from VLDB \n",
4235 (unsigned long)volid);
4236 PrintError("", vcode);
4239 MapHostToNetwork(rentry);
4240 if (volid == rentry->volumeId[ROVOL]) {
4242 for (i = 0; i < rentry->nServers; i++) {
4243 if ((index == -1) && (rentry->serverFlags[i] & ITSROVOL)
4244 && !(rentry->serverFlags[i] & RO_DONTUSE))
4249 "RO volume is not found in VLDB entry for volume %lu\n",
4250 (unsigned long)volid);
4254 *server = rentry->serverNumber[index];
4255 *part = rentry->serverPartition[index];
4259 index = Lp_GetRwIndex(rentry);
4262 "RW Volume is not found in VLDB entry for volume %lu\n",
4263 (unsigned long)volid);
4266 if (volid == rentry->volumeId[RWVOL]) {
4268 *server = rentry->serverNumber[index];
4269 *part = rentry->serverPartition[index];
4272 if (volid == rentry->volumeId[BACKVOL]) {
4274 *server = rentry->serverNumber[index];
4275 *part = rentry->serverPartition[index];
4279 "unexpected volume type for volume %lu\n",
4280 (unsigned long)volid);
4285 DeleteEntry(struct cmd_syndesc *as, void *arock)
4287 afs_int32 apart = 0;
4290 struct VldbListByAttributes attributes;
4291 nbulkentries arrayEntries;
4292 struct nvldbentry *vllist;
4293 struct cmd_item *itp;
4296 char prefix[VOLSER_MAXVOLNAME + 1];
4298 afs_int32 totalBack = 0, totalFail = 0, err;
4300 if (as->parms[0].items) { /* -id */
4301 if (as->parms[1].items || as->parms[2].items || as->parms[3].items) {
4303 "You cannot use -server, -partition, or -prefix with the -id argument\n");
4306 for (itp = as->parms[0].items; itp; itp = itp->next) {
4307 avolid = vsu_GetVolumeID(itp->data, cstruct, &err);
4310 PrintError("", err);
4312 fprintf(STDERR, "vos: can't find volume '%s'\n",
4316 if (as->parms[4].items || as->parms[5].items) {
4317 /* -noexecute (hidden) or -dryrun */
4318 fprintf(STDOUT, "Would have deleted VLDB entry for %s \n",
4323 vcode = ubik_VL_DeleteEntry(cstruct, 0, avolid, RWVOL);
4325 fprintf(STDERR, "Could not delete entry for volume %s\n",
4328 "You must specify a RW volume name or ID "
4329 "(the entire VLDB entry will be deleted)\n");
4330 PrintError("", vcode);
4336 fprintf(STDOUT, "Deleted %d VLDB entries\n", totalBack);
4340 if (!as->parms[1].items && !as->parms[2].items && !as->parms[3].items) {
4341 fprintf(STDERR, "You must specify an option\n");
4345 /* Zero out search attributes */
4346 memset(&attributes, 0, sizeof(struct VldbListByAttributes));
4348 if (as->parms[1].items) { /* -prefix */
4349 strncpy(prefix, as->parms[1].items->data, VOLSER_MAXVOLNAME);
4351 if (!as->parms[2].items && !as->parms[3].items) { /* a single entry only */
4353 "You must provide -server with the -prefix argument\n");
4358 if (as->parms[2].items) { /* -server */
4360 aserver = GetServer(as->parms[2].items->data);
4362 fprintf(STDERR, "vos: server '%s' not found in host table\n",
4363 as->parms[2].items->data);
4366 attributes.server = ntohl(aserver);
4367 attributes.Mask |= VLLIST_SERVER;
4370 if (as->parms[3].items) { /* -partition */
4371 if (!as->parms[2].items) {
4373 "You must provide -server with the -partition argument\n");
4376 apart = volutil_GetPartitionID(as->parms[3].items->data);
4378 fprintf(STDERR, "vos: could not interpret partition name '%s'\n",
4379 as->parms[3].items->data);
4382 attributes.partition = apart;
4383 attributes.Mask |= VLLIST_PARTITION;
4386 /* Print status line of what we are doing */
4387 fprintf(STDOUT, "Deleting VLDB entries for ");
4388 if (as->parms[2].items) {
4389 fprintf(STDOUT, "server %s ", as->parms[2].items->data);
4391 if (as->parms[3].items) {
4393 MapPartIdIntoName(apart, pname);
4394 fprintf(STDOUT, "partition %s ", pname);
4397 fprintf(STDOUT, "which are prefixed with %s ", prefix);
4399 fprintf(STDOUT, "\n");
4402 /* Get all the VLDB entries on a server and/or partition */
4403 memset(&arrayEntries, 0, sizeof(arrayEntries));
4404 vcode = VLDB_ListAttributes(&attributes, &nentries, &arrayEntries);
4406 fprintf(STDERR, "Could not access the VLDB for attributes\n");
4407 PrintError("", vcode);
4411 /* Process each entry */
4412 for (j = 0; j < nentries; j++) {
4413 vllist = &arrayEntries.nbulkentries_val[j];
4415 /* It only deletes the RW volumes */
4416 if (strncmp(vllist->name, prefix, strlen(prefix))) {
4419 "Omitting to delete %s due to prefix %s mismatch\n",
4420 vllist->name, prefix);
4427 if (as->parms[4].items || as->parms[5].items) {
4428 /* -noexecute (hidden) or -dryrun */
4429 fprintf(STDOUT, "Would have deleted VLDB entry for %s \n",
4435 /* Only matches the RW volume name */
4436 avolid = vllist->volumeId[RWVOL];
4437 vcode = ubik_VL_DeleteEntry(cstruct, 0, avolid, RWVOL);
4439 fprintf(STDOUT, "Could not delete VLDB entry for %s\n",
4442 PrintError("", vcode);
4447 fprintf(STDOUT, "Deleted VLDB entry for %s \n", vllist->name);
4452 fprintf(STDOUT, "----------------------\n");
4454 "Total VLDB entries deleted: %lu; failed to delete: %lu\n",
4455 (unsigned long)totalBack, (unsigned long)totalFail);
4457 xdr_free((xdrproc_t) xdr_nbulkentries, &arrayEntries);
4463 CompareVldbEntryByName(const void *p1, const void *p2)
4465 struct nvldbentry *arg1, *arg2;
4467 arg1 = (struct nvldbentry *)p1;
4468 arg2 = (struct nvldbentry *)p2;
4469 return (strcmp(arg1->name, arg2->name));
4473 static int CompareVldbEntry(char *p1, char *p2)
4475 struct nvldbentry *arg1,*arg2;
4478 char comp1[100],comp2[100];
4479 char temp1[20],temp2[20];
4481 arg1 = (struct nvldbentry *)p1;
4482 arg2 = (struct nvldbentry *)p2;
4486 for(i = 0; i < arg1->nServers; i++)
4487 if(arg1->serverFlags[i] & ITSRWVOL) pos1 = i;
4488 for(i = 0; i < arg2->nServers; i++)
4489 if(arg2->serverFlags[i] & ITSRWVOL) pos2 = i;
4490 if(pos1 == -1 || pos2 == -1){
4494 sprintf(comp1,"%10u",arg1->serverNumber[pos1]);
4495 sprintf(comp2,"%10u",arg2->serverNumber[pos2]);
4496 sprintf(temp1,"%10u",arg1->serverPartition[pos1]);
4497 sprintf(temp2,"%10u",arg2->serverPartition[pos2]);
4498 strcat(comp1,temp1);
4499 strcat(comp2,temp2);
4500 strcat(comp1,arg1->name);
4501 strcat(comp1,arg2->name);
4502 return(strcmp(comp1,comp2));
4508 ListVLDB(struct cmd_syndesc *as, void *arock)
4513 struct VldbListByAttributes attributes;
4514 nbulkentries arrayEntries;
4515 struct nvldbentry *vllist, *tarray = 0, *ttarray;
4516 afs_int32 centries, nentries = 0;
4517 afs_int32 tarraysize = 0;
4518 afs_int32 parraysize;
4521 int quiet, sort, lock;
4522 afs_int32 thisindex, nextindex;
4526 attributes.Mask = 0;
4527 lock = (as->parms[3].items ? 1 : 0); /* -lock flag */
4528 quiet = (as->parms[4].items ? 1 : 0); /* -quit flag */
4529 sort = (as->parms[5].items ? 0 : 1); /* -nosort flag */
4531 /* If the volume name is given, Use VolumeInfoCmd to look it up
4532 * and not ListAttributes.
4534 if (as->parms[0].items) {
4537 "vos: illegal use of '-locked' switch, need to specify server and/or partition\n");
4540 code = VolumeInfoCmd(as->parms[0].items->data);
4542 PrintError("", code);
4548 /* Server specified */
4549 if (as->parms[1].items) {
4552 aserver = GetServer(as->parms[1].items->data);
4554 fprintf(STDERR, "vos: server '%s' not found in host table\n",
4555 as->parms[1].items->data);
4558 attributes.server = ntohl(aserver);
4559 attributes.Mask |= VLLIST_SERVER;
4562 /* Partition specified */
4563 if (as->parms[2].items) {
4564 apart = volutil_GetPartitionID(as->parms[2].items->data);
4566 fprintf(STDERR, "vos: could not interpret partition name '%s'\n",
4567 as->parms[2].items->data);
4570 attributes.partition = apart;
4571 attributes.Mask |= VLLIST_PARTITION;
4575 attributes.Mask |= VLLIST_FLAG;
4576 attributes.flag = VLOP_ALLOPERS;
4579 /* Print header information */
4581 MapPartIdIntoName(apart, pname);
4582 fprintf(STDOUT, "VLDB entries for %s %s%s%s %s\n",
4583 (as->parms[1].items ? "server" : "all"),
4584 (as->parms[1].items ? as->parms[1].items->data : "servers"),
4585 (as->parms[2].items ? " partition " : ""),
4586 (as->parms[2].items ? pname : ""),
4587 (lock ? "which are locked:" : ""));
4590 for (thisindex = 0; (thisindex != -1); thisindex = nextindex) {
4591 memset(&arrayEntries, 0, sizeof(arrayEntries));
4596 VLDB_ListAttributesN2(&attributes, 0, thisindex, ¢ries,
4597 &arrayEntries, &nextindex);
4598 if (vcode == RXGEN_OPCODE) {
4599 /* Vlserver not running with ListAttributesN2. Fall back */
4601 VLDB_ListAttributes(&attributes, ¢ries, &arrayEntries);
4605 fprintf(STDERR, "Could not access the VLDB for attributes\n");
4606 PrintError("", vcode);
4609 nentries += centries;
4611 /* We don't sort, so just print the entries now */
4613 for (j = 0; j < centries; j++) { /* process each entry */
4614 vllist = &arrayEntries.nbulkentries_val[j];
4615 MapHostToNetwork(vllist);
4616 EnumerateEntry(vllist);
4618 PrintLocked(vllist->flags);
4622 /* So we sort. First we must collect all the entries and keep
4625 else if (centries > 0) {
4627 /* malloc the first bulk entries array */
4628 tarraysize = centries * sizeof(struct nvldbentry);
4629 tarray = malloc(tarraysize);
4632 "Could not allocate enough space for the VLDB entries\n");
4635 memcpy((char*)tarray, arrayEntries.nbulkentries_val, tarraysize);
4637 /* Grow the tarray to keep the extra entries */
4638 parraysize = (centries * sizeof(struct nvldbentry));
4639 ttarray = realloc(tarray, tarraysize + parraysize);
4642 "Could not allocate enough space for the VLDB entries\n");
4648 memcpy(((char *)tarray) + tarraysize,
4649 (char *)arrayEntries.nbulkentries_val, parraysize);
4650 tarraysize += parraysize;
4654 /* Free the bulk array */
4655 xdr_free((xdrproc_t) xdr_nbulkentries, &arrayEntries);
4658 /* Here is where we now sort all the entries and print them */
4659 if (sort && (nentries > 0)) {
4660 qsort((char *)tarray, nentries, sizeof(struct nvldbentry),
4661 CompareVldbEntryByName);
4662 for (vllist = tarray, j = 0; j < nentries; j++, vllist++) {
4663 MapHostToNetwork(vllist);
4664 EnumerateEntry(vllist);
4666 PrintLocked(vllist->flags);
4672 fprintf(STDOUT, "\nTotal entries: %lu\n", (unsigned long)nentries);
4679 BackSys(struct cmd_syndesc *as, void *arock)
4682 afs_int32 apart = 0;
4683 afs_uint32 aserver = 0, aserver1;
4684 afs_int32 code, apart1;
4686 struct VldbListByAttributes attributes;
4687 nbulkentries arrayEntries;
4688 struct nvldbentry *vllist;
4692 int seenprefix, seenxprefix, exclude, ex, exp, noaction;
4693 afs_int32 totalBack = 0;
4694 afs_int32 totalFail = 0;
4698 struct cmd_item *ti;
4700 #ifndef HAVE_POSIX_REGEX
4704 memset(&attributes, 0, sizeof(struct VldbListByAttributes));
4705 attributes.Mask = 0;
4707 seenprefix = (as->parms[0].items ? 1 : 0);
4708 exclude = (as->parms[3].items ? 1 : 0);
4709 seenxprefix = (as->parms[4].items ? 1 : 0);
4710 noaction = (as->parms[5].items ? 1 : 0);
4712 if (as->parms[1].items) { /* -server */
4713 aserver = GetServer(as->parms[1].items->data);
4715 fprintf(STDERR, "vos: server '%s' not found in host table\n",
4716 as->parms[1].items->data);
4719 attributes.server = ntohl(aserver);
4720 attributes.Mask |= VLLIST_SERVER;
4723 if (as->parms[2].items) { /* -partition */
4724 apart = volutil_GetPartitionID(as->parms[2].items->data);
4726 fprintf(STDERR, "vos: could not interpret partition name '%s'\n",
4727 as->parms[2].items->data);
4730 attributes.partition = apart;
4731 attributes.Mask |= VLLIST_PARTITION;
4734 /* Check to make sure the prefix and xprefix expressions compile ok */
4736 for (ti = as->parms[0].items; ti; ti = ti->next) {
4737 if (strncmp(ti->data, "^", 1) == 0) {
4738 #ifdef HAVE_POSIX_REGEX
4742 code = regcomp(&re, ti->data, REG_NOSUB);
4744 regerror(code, &re, errbuf, sizeof errbuf);
4746 "Unrecognizable -prefix regular expression: '%s': %s\n",
4752 ccode = (char *)re_comp(ti->data);
4755 "Unrecognizable -prefix regular expression: '%s': %s\n",
4764 for (ti = as->parms[4].items; ti; ti = ti->next) {
4765 if (strncmp(ti->data, "^", 1) == 0) {
4766 #ifdef HAVE_POSIX_REGEX
4770 code = regcomp(&re, ti->data, REG_NOSUB);
4772 regerror(code, &re, errbuf, sizeof errbuf);
4774 "Unrecognizable -xprefix regular expression: '%s': %s\n",
4780 ccode = (char *)re_comp(ti->data);
4783 "Unrecognizable -xprefix regular expression: '%s': %s\n",
4792 memset(&arrayEntries, 0, sizeof(arrayEntries)); /* initialize to hint the stub to alloc space */
4793 vcode = VLDB_ListAttributes(&attributes, &nentries, &arrayEntries);
4795 fprintf(STDERR, "Could not access the VLDB for attributes\n");
4796 PrintError("", vcode);
4800 if (as->parms[1].items || as->parms[2].items || verbose) {
4801 fprintf(STDOUT, "%s up volumes",
4802 (noaction ? "Would have backed" : "Backing"));
4804 if (as->parms[1].items) {
4805 fprintf(STDOUT, " on server %s", as->parms[1].items->data);
4806 } else if (as->parms[2].items) {
4807 fprintf(STDOUT, " for all servers");
4810 if (as->parms[2].items) {
4811 MapPartIdIntoName(apart, pname);
4812 fprintf(STDOUT, " partition %s", pname);
4815 if (seenprefix || (!seenprefix && seenxprefix)) {
4816 ti = (seenprefix ? as->parms[0].items : as->parms[4].items);
4817 ex = (seenprefix ? exclude : !exclude);
4818 exp = (strncmp(ti->data, "^", 1) == 0);
4819 fprintf(STDOUT, " which %smatch %s '%s'", (ex ? "do not " : ""),
4820 (exp ? "expression" : "prefix"), ti->data);
4821 for (ti = ti->next; ti; ti = ti->next) {
4822 exp = (strncmp(ti->data, "^", 1) == 0);
4823 printf(" %sor %s '%s'", (ex ? "n" : ""),
4824 (exp ? "expression" : "prefix"), ti->data);
4828 if (seenprefix && seenxprefix) {
4829 ti = as->parms[4].items;
4830 exp = (strncmp(ti->data, "^", 1) == 0);
4831 fprintf(STDOUT, " %swhich match %s '%s'",
4832 (exclude ? "adding those " : "removing those "),
4833 (exp ? "expression" : "prefix"), ti->data);
4834 for (ti = ti->next; ti; ti = ti->next) {
4835 exp = (strncmp(ti->data, "^", 1) == 0);
4836 printf(" or %s '%s'", (exp ? "expression" : "prefix"),
4840 fprintf(STDOUT, " .. ");
4842 fprintf(STDOUT, "\n");
4846 for (j = 0; j < nentries; j++) { /* process each vldb entry */
4847 vllist = &arrayEntries.nbulkentries_val[j];
4850 for (ti = as->parms[0].items; ti; ti = ti->next) {
4851 if (strncmp(ti->data, "^", 1) == 0) {
4852 #ifdef HAVE_POSIX_REGEX
4856 /* XXX -- should just do the compile once! */
4857 code = regcomp(&re, ti->data, REG_NOSUB);
4859 regerror(code, &re, errbuf, sizeof errbuf);
4861 "Error in -prefix regular expression: '%s': %s\n",
4865 match = (regexec(&re, vllist->name, 0, NULL, 0) == 0);
4868 ccode = (char *)re_comp(ti->data);
4871 "Error in -prefix regular expression: '%s': %s\n",
4875 match = (re_exec(vllist->name) == 1);
4879 (strncmp(vllist->name, ti->data, strlen(ti->data)) ==
4889 /* Without the -exclude flag: If it matches the prefix, then
4890 * check if we want to exclude any from xprefix.
4891 * With the -exclude flag: If it matches the prefix, then
4892 * check if we want to add any from xprefix.
4894 if (match && seenxprefix) {
4895 for (ti = as->parms[4].items; ti; ti = ti->next) {
4896 if (strncmp(ti->data, "^", 1) == 0) {
4897 #ifdef HAVE_POSIX_REGEX
4901 /* XXX -- should just do the compile once! */
4902 code = regcomp(&re, ti->data, REG_NOSUB);
4904 regerror(code, &re, errbuf, sizeof errbuf);
4906 "Error in -xprefix regular expression: '%s': %s\n",
4910 if (regexec(&re, vllist->name, 0, NULL, 0) == 0)
4914 ccode = (char *)re_comp(ti->data);
4917 "Error in -xprefix regular expression: '%s': %s\n",
4921 if (re_exec(vllist->name) == 1) {
4927 if (strncmp(vllist->name, ti->data, strlen(ti->data)) ==
4937 match = !match; /* -exclude will reverse the match */
4939 continue; /* Skip if no match */
4941 /* Print list of volumes to backup */
4943 fprintf(STDOUT, " %s\n", vllist->name);
4947 if (!(vllist->flags & RW_EXISTS)) {
4950 "Omitting to backup %s since RW volume does not exist \n",
4952 fprintf(STDOUT, "\n");
4958 avolid = vllist->volumeId[RWVOL];
4959 MapHostToNetwork(vllist);
4960 GetServerAndPart(vllist, RWVOL, &aserver1, &apart1, &previdx);
4961 if (aserver1 == -1 || apart1 == -1) {
4962 fprintf(STDOUT, "could not backup %s, invalid VLDB entry\n",
4968 same = VLDB_IsSameAddrs(aserver, aserver1, &error);
4971 "Failed to get info about server's %d address(es) from vlserver (err=%d); aborting call!\n",
4977 if ((aserver && !same) || (apart && (apart != apart1))) {
4980 "Omitting to backup %s since the RW is in a different location\n",
4986 time_t now = time(0);
4987 fprintf(STDOUT, "Creating backup volume for %s on %s",
4988 vllist->name, ctime(&now));
4992 code = UV_BackupVolume(aserver1, apart1, avolid);
4994 fprintf(STDOUT, "Could not backup %s\n", vllist->name);
5000 fprintf(STDOUT, "\n");
5002 } /* process each vldb entry */
5003 fprintf(STDOUT, "done\n");
5004 fprintf(STDOUT, "Total volumes backed up: %lu; failed to backup: %lu\n",
5005 (unsigned long)totalBack, (unsigned long)totalFail);
5007 xdr_free((xdrproc_t) xdr_nbulkentries, &arrayEntries);
5012 UnlockVLDB(struct cmd_syndesc *as, void *arock)
5015 afs_uint32 aserver = 0;
5018 struct VldbListByAttributes attributes;
5019 nbulkentries arrayEntries;
5020 struct nvldbentry *vllist;
5029 attributes.Mask = 0;
5031 if (as->parms[0].items) { /* server specified */
5032 aserver = GetServer(as->parms[0].items->data);
5034 fprintf(STDERR, "vos: server '%s' not found in host table\n",
5035 as->parms[0].items->data);
5038 attributes.server = ntohl(aserver);
5039 attributes.Mask |= VLLIST_SERVER;
5041 if (as->parms[1].items) { /* partition specified */
5042 apart = volutil_GetPartitionID(as->parms[1].items->data);
5044 fprintf(STDERR, "vos: could not interpret partition name '%s'\n",
5045 as->parms[1].items->data);
5048 if (!IsPartValid(apart, aserver, &code)) { /*check for validity of the partition */
5050 PrintError("", code);
5053 "vos : partition %s does not exist on the server\n",
5054 as->parms[1].items->data);
5057 attributes.partition = apart;
5058 attributes.Mask |= VLLIST_PARTITION;
5060 attributes.flag = VLOP_ALLOPERS;
5061 attributes.Mask |= VLLIST_FLAG;
5062 memset(&arrayEntries, 0, sizeof(arrayEntries)); /*initialize to hint the stub to alloc space */
5063 vcode = VLDB_ListAttributes(&attributes, &nentries, &arrayEntries);
5065 fprintf(STDERR, "Could not access the VLDB for attributes\n");
5066 PrintError("", vcode);
5069 for (j = 0; j < nentries; j++) { /* process each entry */
5070 vllist = &arrayEntries.nbulkentries_val[j];
5071 volid = vllist->volumeId[RWVOL];
5073 ubik_VL_ReleaseLock(cstruct, 0, volid, -1,
5074 LOCKREL_OPCODE | LOCKREL_AFSID |
5077 fprintf(STDERR, "Could not unlock entry for volume %s\n",
5079 PrintError("", vcode);
5084 MapPartIdIntoName(apart, pname);
5087 "Could not lock %lu VLDB entries of %lu locked entries\n",
5088 (unsigned long)totalE, (unsigned long)nentries);
5090 if (as->parms[0].items) {
5092 "Unlocked all the VLDB entries for volumes on server %s ",
5093 as->parms[0].items->data);
5094 if (as->parms[1].items) {
5095 MapPartIdIntoName(apart, pname);
5096 fprintf(STDOUT, "partition %s\n", pname);
5098 fprintf(STDOUT, "\n");
5100 } else if (as->parms[1].items) {
5101 MapPartIdIntoName(apart, pname);
5103 "Unlocked all the VLDB entries for volumes on partition %s on all servers\n",
5108 xdr_free((xdrproc_t) xdr_nbulkentries, &arrayEntries);
5113 PrintInt64Size(afs_uint64 in)
5117 static char output[16];
5119 SplitInt64(in,hi,lo);
5123 } else if (!(hi & 0xFFFFFC00)) {
5125 lo = (hi << 22) | (lo >> 10);
5126 } else if (!(hi & 0xFFF00000)) {
5128 lo = (hi << 12) | (lo >> 20);
5129 } else if (!(hi & 0xC0000000)) {
5131 lo = (hi << 2) | (lo >> 30);
5136 sprintf(output,"%u %s", lo, units);
5141 PartitionInfo(struct cmd_syndesc *as, void *arock)
5147 struct diskPartition64 partition;
5148 struct partList dummyPartList;
5150 int printSummary=0, sumPartitions=0;
5151 afs_uint64 sumFree, sumStorage;
5154 ZeroInt64(sumStorage);
5156 aserver = GetServer(as->parms[0].items->data);
5158 fprintf(STDERR, "vos: server '%s' not found in host table\n",
5159 as->parms[0].items->data);
5162 if (as->parms[1].items) {
5163 apart = volutil_GetPartitionID(as->parms[1].items->data);
5165 fprintf(STDERR, "vos: could not interpret partition name '%s'\n",
5166 as->parms[1].items->data);
5169 dummyPartList.partId[0] = apart;
5170 dummyPartList.partFlags[0] = PARTVALID;
5173 if (as->parms[2].items) {
5177 if (!IsPartValid(apart, aserver, &code)) { /*check for validity of the partition */
5179 PrintError("", code);
5182 "vos : partition %s does not exist on the server\n",
5183 as->parms[1].items->data);
5187 code = UV_ListPartitions(aserver, &dummyPartList, &cnt);
5189 PrintDiagnostics("listpart", code);
5193 for (i = 0; i < cnt; i++) {
5194 if (dummyPartList.partFlags[i] & PARTVALID) {
5195 MapPartIdIntoName(dummyPartList.partId[i], pname);
5196 code = UV_PartitionInfo64(aserver, pname, &partition);
5198 fprintf(STDERR, "Could not get information on partition %s\n",
5200 PrintError("", code);
5204 "Free space on partition %s: %" AFS_INT64_FMT " K blocks out of total %" AFS_INT64_FMT "\n",
5205 pname, partition.free, partition.minFree);
5207 AddUInt64(sumFree,partition.free,&sumFree);
5208 AddUInt64(sumStorage,partition.minFree,&sumStorage);
5213 "Summary: %s free out of ",
5214 PrintInt64Size(sumFree));
5216 "%s on %d partitions\n",
5217 PrintInt64Size(sumStorage),
5224 ChangeAddr(struct cmd_syndesc *as, void *arock)
5226 afs_int32 ip1, ip2, vcode;
5230 ip1 = GetServerNoresolve(as->parms[0].items->data);
5232 ip1 = GetServer(as->parms[0].items->data);
5234 fprintf(STDERR, "vos: invalid host address\n");
5238 if ((as->parms[1].items && as->parms[2].items)
5239 || (!as->parms[1].items && !as->parms[2].items)) {
5241 "vos: Must specify either '-newaddr <addr>' or '-remove' flag\n");
5245 if (as->parms[1].items) {
5247 ip2 = GetServerNoresolve(as->parms[1].items->data);
5249 ip2 = GetServer(as->parms[1].items->data);
5251 fprintf(STDERR, "vos: invalid host address\n");
5255 /* Play a trick here. If we are removing an address, ip1 will be -1
5256 * and ip2 will be the original address. This switch prevents an
5257 * older revision vlserver from removing the IP address.
5264 vcode = ubik_VL_ChangeAddr(cstruct, UBIK_CALL_NEW, ntohl(ip1), ntohl(ip2));
5266 char hoststr1[16], hoststr2[16];
5268 afs_inet_ntoa_r(ip2, hoststr2);
5269 fprintf(STDERR, "Could not remove server %s from the VLDB\n",
5271 if (vcode == VL_NOENT) {
5273 "vlserver does not support the remove flag or ");
5276 afs_inet_ntoa_r(ip1, hoststr1);
5277 afs_inet_ntoa_r(ip2, hoststr2);
5278 fprintf(STDERR, "Could not change server %s to server %s\n",
5279 hoststr1, hoststr2);
5281 PrintError("", vcode);
5286 fprintf(STDOUT, "Removed server %s from the VLDB\n",
5287 as->parms[0].items->data);
5289 fprintf(STDOUT, "Changed server %s to server %s\n",
5290 as->parms[0].items->data, as->parms[1].items->data);
5296 print_addrs(const bulkaddrs * addrs, afsUUID * m_uuid, int nentries,
5304 afsUUID_to_string(m_uuid, buf, sizeof(buf));
5305 printf("UUID: %s\n", buf);
5308 /* print out the list of all the server */
5309 addrp = (afs_uint32 *) addrs->bulkaddrs_val;
5310 for (i = 0; i < nentries; i++, addrp++) {
5311 *addrp = htonl(*addrp);
5314 printf("%s\n", afs_inet_ntoa_r(*addrp, hoststr));
5316 printf("%s\n", hostutil_GetNameByINet(*addrp));
5327 ListAddrs(struct cmd_syndesc *as, void *arock)
5329 afs_int32 vcode, m_uniq=0;
5330 afs_int32 i, printuuid = 0;
5331 struct VLCallBack vlcb;
5334 ListAddrByAttributes m_attrs;
5335 afsUUID m_uuid, askuuid;
5336 afs_int32 m_nentries;
5338 if (as->parms[0].items && as->parms[1].items) {
5339 fprintf(STDERR, "vos: Can't use the -uuid and -host flags together\n");
5343 memset(&m_attrs, 0, sizeof(struct ListAddrByAttributes));
5344 memset(&askuuid, 0, sizeof(afsUUID));
5345 if (as->parms[0].items) {
5347 if (afsUUID_from_string(as->parms[0].items->data, &askuuid) < 0) {
5348 fprintf(STDERR, "vos: invalid UUID '%s'\n",
5349 as->parms[0].items->data);
5352 m_attrs.Mask = VLADDR_UUID;
5353 m_attrs.uuid = askuuid;
5354 } else if (as->parms[1].items) {
5358 he = hostutil_GetHostByName((char *)as->parms[1].items->data);
5360 fprintf(STDERR, "vos: Can't get host info for '%s'\n",
5361 as->parms[1].items->data);
5364 memcpy(&saddr, he->h_addr, 4);
5365 m_attrs.Mask = VLADDR_IPADDR;
5366 m_attrs.ipaddr = ntohl(saddr);
5369 m_attrs.Mask = VLADDR_INDEX;
5372 if (as->parms[2].items) {
5376 memset(&m_addrs, 0, sizeof(bulkaddrs));
5377 memset(&vlcb, 0, sizeof(struct VLCallBack));
5380 ubik_VL_GetAddrs(cstruct, UBIK_CALL_NEW, 0, 0, &vlcb, &nentries,
5383 fprintf(STDERR, "vos: could not list the server addresses\n");
5384 PrintError("", vcode);
5388 for (i = 1, m_nentries = 0; nentries; i++) {
5391 xdr_free((xdrproc_t)xdr_bulkaddrs, &m_addrs); /* reset addr list */
5393 ubik_VL_GetAddrsU(cstruct, UBIK_CALL_NEW, &m_attrs, &m_uuid,
5394 &m_uniq, &m_nentries, &m_addrs);
5396 case 0: /* success */
5397 print_addrs(&m_addrs, &m_uuid, m_nentries, printuuid);
5402 if (m_attrs.Mask == VLADDR_UUID) {
5403 fprintf(STDERR, "vos: no entry for UUID '%s' found in VLDB\n",
5404 as->parms[0].items->data);
5406 } else if (m_attrs.Mask == VLADDR_IPADDR) {
5407 fprintf(STDERR, "vos: no entry for host '%s' [0x%08x] found in VLDB\n",
5408 as->parms[1].items->data, m_attrs.ipaddr);
5413 case VL_INDEXERANGE:
5414 vcode = 0; /* not an error, just means we're done */
5417 default: /* any other error */
5418 fprintf(STDERR, "vos: could not list the server addresses\n");
5419 PrintError("", vcode);
5423 /* if -uuid or -host, only list one response */
5424 if (as->parms[1].items || as->parms[0].items)
5429 xdr_free((xdrproc_t)xdr_bulkaddrs, &m_addrs);
5435 SetAddrs(struct cmd_syndesc *as, void *arock)
5440 afs_uint32 FS_HostAddrs_HBO[ADDRSPERSITE];
5442 memset(&m_addrs, 0, sizeof(bulkaddrs));
5443 memset(&askuuid, 0, sizeof(afsUUID));
5444 if (as->parms[0].items) {
5446 if (afsUUID_from_string(as->parms[0].items->data, &askuuid) < 0) {
5447 fprintf(STDERR, "vos: invalid UUID '%s'\n",
5448 as->parms[0].items->data);
5452 if (as->parms[1].items) {
5454 struct cmd_item *ti;
5458 for (ti = as->parms[1].items; ti && i < ADDRSPERSITE; ti = ti->next) {
5461 saddr = GetServerNoresolve(ti->data);
5463 saddr = GetServer(ti->data);
5466 fprintf(STDERR, "vos: Can't get host info for '%s'\n",
5470 /* Convert it to host byte order */
5471 FS_HostAddrs_HBO[i] = ntohl(saddr);
5474 m_addrs.bulkaddrs_len = i;
5475 m_addrs.bulkaddrs_val = FS_HostAddrs_HBO;
5478 vcode = ubik_VL_RegisterAddrs(cstruct, 0, &askuuid, 0, &m_addrs);
5481 if (vcode == VL_MULTIPADDR) {
5482 fprintf(STDERR, "vos: VL_RegisterAddrs rpc failed; The IP address exists on a different server; repair it\n");
5483 } else if (vcode == RXGEN_OPCODE) {
5484 fprintf(STDERR, "vlserver doesn't support VL_RegisterAddrs rpc; ignored\n");
5486 fprintf(STDERR, "vos: VL_RegisterAddrs rpc failed\n");
5488 PrintError("", vcode);
5492 fprintf(STDOUT, "vos: Changed UUID with addresses:\n");
5493 print_addrs(&m_addrs, &askuuid, m_addrs.bulkaddrs_len, 1);
5499 LockEntry(struct cmd_syndesc *as, void *arock)
5502 afs_int32 vcode, err;
5504 avolid = vsu_GetVolumeID(as->parms[0].items->data, cstruct, &err);
5507 PrintError("", err);
5509 fprintf(STDERR, "vos: can't find volume '%s'\n",
5510 as->parms[0].items->data);
5513 vcode = ubik_VL_SetLock(cstruct, 0, avolid, -1, VLOP_DELETE);
5515 fprintf(STDERR, "Could not lock VLDB entry for volume %s\n",
5516 as->parms[0].items->data);
5517 PrintError("", vcode);
5520 fprintf(STDOUT, "Locked VLDB entry for volume %s\n",
5521 as->parms[0].items->data);
5526 ConvertRO(struct cmd_syndesc *as, void *arock)
5528 afs_int32 partition = -1;
5531 afs_int32 code, i, same;
5532 struct nvldbentry entry;
5534 afs_uint32 rwserver = 0;
5535 afs_int32 rwpartition = 0;
5536 afs_uint32 roserver = 0;
5537 afs_int32 ropartition = 0;
5541 server = GetServer(as->parms[0].items->data);
5543 fprintf(STDERR, "vos: host '%s' not found in host table\n",
5544 as->parms[0].items->data);
5547 partition = volutil_GetPartitionID(as->parms[1].items->data);
5548 if (partition < 0) {
5549 fprintf(STDERR, "vos: could not interpret partition name '%s'\n",
5550 as->parms[1].items->data);
5553 if (!IsPartValid(partition, server, &code)) {
5555 PrintError("", code);
5558 "vos : partition %s does not exist on the server\n",
5559 as->parms[1].items->data);
5562 volid = vsu_GetVolumeID(as->parms[2].items->data, cstruct, &code);
5565 PrintError("", code);
5567 fprintf(STDERR, "Unknown volume ID or name '%s'\n",
5568 as->parms[2].items->data);
5571 if (as->parms[3].items)
5574 memset(&entry, 0, sizeof(entry));
5575 vcode = VLDB_GetEntryByID(volid, -1, &entry);
5578 "Could not fetch the entry for volume %lu from VLDB\n",
5579 (unsigned long)volid);
5580 PrintError("convertROtoRW ", vcode);
5584 /* use RO volid even if user specified RW or BK volid */
5585 if (volid != entry.volumeId[ROVOL])
5586 volid = entry.volumeId[ROVOL];
5588 MapHostToNetwork(&entry);
5589 for (i = 0; i < entry.nServers; i++) {
5590 if (entry.serverFlags[i] & ITSRWVOL) {
5591 rwserver = entry.serverNumber[i];
5592 rwpartition = entry.serverPartition[i];
5595 } else if ((entry.serverFlags[i] & ITSROVOL) && !roserver) {
5596 same = VLDB_IsSameAddrs(server, entry.serverNumber[i], &code);
5599 "Failed to get info about server's %d address(es) from vlserver (err=%d); aborting call!\n",
5604 roserver = entry.serverNumber[i];
5605 ropartition = entry.serverPartition[i];
5612 fprintf(STDERR, "Warning: RO volume didn't exist in vldb!\n");
5614 if (roserver && (ropartition != partition)) {
5616 "Warning: RO volume should be in partition %d instead of %d (vldb)\n",
5617 ropartition, partition);
5622 "VLDB indicates that a RW volume exists already on %s in partition %s.\n",
5623 hostutil_GetNameByINet(rwserver),
5624 volutil_PartitionName(rwpartition));
5626 fprintf(STDERR, "Overwrite this VLDB entry? [y|n] (n)\n");
5628 while (!(dc == EOF || dc == '\n'))
5629 dc = getchar(); /* goto end of line */
5630 if ((c != 'y') && (c != 'Y')) {
5631 fprintf(STDERR, "aborted.\n");
5637 code = UV_ConvertRO(server, partition, volid, &entry);
5643 Sizes(struct cmd_syndesc *as, void *arock)
5647 afs_int32 apart, voltype, fromdate = 0, code, err, i;
5648 struct nvldbentry entry;
5649 volintSize vol_size;
5651 rx_SetRxDeadTime(60 * 10);
5652 for (i = 0; i < MAXSERVERS; i++) {
5653 struct rx_connection *rxConn = ubik_GetRPCConn(cstruct, i);
5656 rx_SetConnDeadTime(rxConn, rx_connDeadTime);
5657 if (rx_ServiceOf(rxConn))
5658 rx_ServiceOf(rxConn)->connDeadTime = rx_connDeadTime;
5661 avolid = vsu_GetVolumeID(as->parms[0].items->data, cstruct, &err);
5664 PrintError("", err);
5666 fprintf(STDERR, "vos: can't find volume '%s'\n",
5667 as->parms[0].items->data);
5671 if (as->parms[1].items || as->parms[2].items) {
5672 if (!as->parms[1].items || !as->parms[2].items) {
5674 "Must specify both -server and -partition options\n");
5677 aserver = GetServer(as->parms[2].items->data);
5679 fprintf(STDERR, "Invalid server name\n");
5682 apart = volutil_GetPartitionID(as->parms[1].items->data);
5684 fprintf(STDERR, "Invalid partition name\n");
5688 code = GetVolumeInfo(avolid, &aserver, &apart, &voltype, &entry);
5695 if (as->parms[4].items && strcmp(as->parms[4].items->data, "0")) {
5696 code = ktime_DateToInt32(as->parms[4].items->data, &fromdate);
5698 fprintf(STDERR, "vos: failed to parse date '%s' (error=%d))\n",
5699 as->parms[4].items->data, code);
5704 fprintf(STDOUT, "Volume: %s\n", as->parms[0].items->data);
5706 if (as->parms[3].items) { /* do the dump estimate */
5707 vol_size.dump_size = 0;
5708 code = UV_GetSize(avolid, aserver, apart, fromdate, &vol_size);
5710 PrintDiagnostics("size", code);
5713 /* presumably the size info is now gathered in pntr */
5714 /* now we display it */
5716 fprintf(STDOUT, "dump_size: %llu\n", vol_size.dump_size);
5725 EndTrans(struct cmd_syndesc *as, void *arock)
5728 afs_int32 code, tid, rcode;
5729 struct rx_connection *aconn;
5731 server = GetServer(as->parms[0].items->data);
5733 fprintf(STDERR, "vos: host '%s' not found in host table\n",
5734 as->parms[0].items->data);
5738 code = util_GetInt32(as->parms[1].items->data, &tid);
5740 fprintf(STDERR, "vos: bad integer specified for transaction ID.\n");
5744 aconn = UV_Bind(server, AFSCONF_VOLUMEPORT);
5745 code = AFSVolEndTrans(aconn, tid, &rcode);
5751 PrintDiagnostics("endtrans", code);
5759 PrintDiagnostics(char *astring, afs_int32 acode)
5761 if (acode == EACCES) {
5763 "You are not authorized to perform the 'vos %s' command (%d)\n",
5766 fprintf(STDERR, "Error in vos %s command.\n", astring);
5767 PrintError("", acode);
5775 win32_enableCrypt(void)
5782 /* Look up configuration parameters in Registry */
5783 code = RegOpenKeyEx(HKEY_LOCAL_MACHINE, AFSREG_CLT_SVC_PARAM_SUBKEY,
5784 0, (IsWow64()?KEY_WOW64_64KEY:0)|KEY_QUERY_VALUE, &parmKey);
5785 if (code != ERROR_SUCCESS) {
5786 dummyLen = sizeof(cryptall);
5787 RegQueryValueEx(parmKey, "SecurityLevel", NULL, NULL,
5788 (BYTE *) &cryptall, &dummyLen);
5790 RegCloseKey (parmKey);
5794 #endif /* AFS_NT40_ENV */
5797 MyBeforeProc(struct cmd_syndesc *as, void *arock)
5803 /* Initialize the ubik_client connection */
5804 rx_SetRxDeadTime(90);
5806 secFlags = AFSCONF_SECOPTS_FALLBACK_NULL;
5809 if (as->parms[12].items) /* if -cell specified */
5810 tcell = as->parms[12].items->data;
5812 if (as->parms[13].items)
5813 secFlags |= AFSCONF_SECOPTS_NOAUTH;
5815 if (as->parms[14].items) { /* -localauth specified */
5816 secFlags |= AFSCONF_SECOPTS_LOCALAUTH;
5817 confdir = AFSDIR_SERVER_ETC_DIRPATH;
5820 if (as->parms[16].items /* -encrypt specified */
5822 || win32_enableCrypt()
5823 #endif /* AFS_NT40_ENV */
5825 secFlags |= AFSCONF_SECOPTS_ALWAYSENCRYPT;
5827 if (as->parms[18].items) /* -config flag set */
5828 confdir = as->parms[18].items->data;
5830 if ((code = vsu_ClientInit(confdir, tcell, secFlags, UV_SetSecurity,
5832 fprintf(STDERR, "could not initialize VLDB library (code=%lu) \n",
5833 (unsigned long)code);
5837 if (as->parms[15].items) /* -verbose flag set */
5841 if (as->parms[17].items) /* -noresolve flag set */
5852 /* this sucks but it works for now.
5857 #include "AFS_component_version_number.c"
5860 main(int argc, char **argv)
5864 struct cmd_syndesc *ts;
5866 #ifdef AFS_AIX32_ENV
5868 * The following signal action for AIX is necessary so that in case of a
5869 * crash (i.e. core is generated) we can include the user's data section
5870 * in the core dump. Unfortunately, by default, only a partial core is
5871 * generated which, in many cases, isn't too useful.
5873 struct sigaction nsa;
5875 sigemptyset(&nsa.sa_mask);
5876 nsa.sa_handler = SIG_DFL;
5877 nsa.sa_flags = SA_FULLDUMP;
5878 sigaction(SIGSEGV, &nsa, NULL);
5881 confdir = AFSDIR_CLIENT_ETC_DIRPATH;
5883 cmd_SetBeforeProc(MyBeforeProc, NULL);
5885 ts = cmd_CreateSyntax("create", CreateVolume, NULL, "create a new volume");
5886 cmd_AddParm(ts, "-server", CMD_SINGLE, 0, "machine name");
5887 cmd_AddParm(ts, "-partition", CMD_SINGLE, 0, "partition name");
5888 cmd_AddParm(ts, "-name", CMD_SINGLE, 0, "volume name");
5889 cmd_AddParm(ts, "-maxquota", CMD_SINGLE, CMD_OPTIONAL,
5890 "initial quota (KB)");
5891 cmd_AddParm(ts, "-id", CMD_SINGLE, CMD_OPTIONAL, "volume ID");
5892 cmd_AddParm(ts, "-roid", CMD_SINGLE, CMD_OPTIONAL, "readonly volume ID");
5894 cmd_AddParm(ts, "-minquota", CMD_SINGLE, CMD_OPTIONAL, "");
5898 ts = cmd_CreateSyntax("remove", DeleteVolume, NULL, "delete a volume");
5899 cmd_AddParm(ts, "-server", CMD_SINGLE, CMD_OPTIONAL, "machine name");
5900 cmd_AddParm(ts, "-partition", CMD_SINGLE, CMD_OPTIONAL, "partition name");
5901 cmd_AddParm(ts, "-id", CMD_SINGLE, 0, "volume name or ID");
5905 ts = cmd_CreateSyntax("move", MoveVolume, NULL, "move a volume");
5906 cmd_AddParm(ts, "-id", CMD_SINGLE, 0, "volume name or ID");
5907 cmd_AddParm(ts, "-fromserver", CMD_SINGLE, 0, "machine name on source");
5908 cmd_AddParm(ts, "-frompartition", CMD_SINGLE, 0,
5909 "partition name on source");
5910 cmd_AddParm(ts, "-toserver", CMD_SINGLE, 0,
5911 "machine name on destination");
5912 cmd_AddParm(ts, "-topartition", CMD_SINGLE, 0,
5913 "partition name on destination");
5914 cmd_AddParm(ts, "-live", CMD_FLAG, CMD_OPTIONAL,
5915 "copy live volume without cloning");
5918 ts = cmd_CreateSyntax("copy", CopyVolume, NULL, "copy a volume");
5919 cmd_AddParm(ts, "-id", CMD_SINGLE, 0, "volume name or ID on source");
5920 cmd_AddParm(ts, "-fromserver", CMD_SINGLE, 0, "machine name on source");
5921 cmd_AddParm(ts, "-frompartition", CMD_SINGLE, 0,
5922 "partition name on source");
5923 cmd_AddParm(ts, "-toname", CMD_SINGLE, 0, "volume name on destination");
5924 cmd_AddParm(ts, "-toserver", CMD_SINGLE, 0,
5925 "machine name on destination");
5926 cmd_AddParm(ts, "-topartition", CMD_SINGLE, 0,
5927 "partition name on destination");
5928 cmd_AddParm(ts, "-offline", CMD_FLAG, CMD_OPTIONAL,
5929 "leave new volume offline");
5930 cmd_AddParm(ts, "-readonly", CMD_FLAG, CMD_OPTIONAL,
5931 "make new volume read-only");
5932 cmd_AddParm(ts, "-live", CMD_FLAG, CMD_OPTIONAL,
5933 "copy live volume without cloning");
5936 ts = cmd_CreateSyntax("shadow", ShadowVolume, NULL,
5937 "make or update a shadow volume");
5938 cmd_AddParm(ts, "-id", CMD_SINGLE, 0, "volume name or ID on source");
5939 cmd_AddParm(ts, "-fromserver", CMD_SINGLE, 0, "machine name on source");
5940 cmd_AddParm(ts, "-frompartition", CMD_SINGLE, 0,
5941 "partition name on source");
5942 cmd_AddParm(ts, "-toserver", CMD_SINGLE, 0,
5943 "machine name on destination");
5944 cmd_AddParm(ts, "-topartition", CMD_SINGLE, 0,
5945 "partition name on destination");
5946 cmd_AddParm(ts, "-toname", CMD_SINGLE, CMD_OPTIONAL,
5947 "volume name on destination");
5948 cmd_AddParm(ts, "-toid", CMD_SINGLE, CMD_OPTIONAL,
5949 "volume ID on destination");
5950 cmd_AddParm(ts, "-offline", CMD_FLAG, CMD_OPTIONAL,
5951 "leave shadow volume offline");
5952 cmd_AddParm(ts, "-readonly", CMD_FLAG, CMD_OPTIONAL,
5953 "make shadow volume read-only");
5954 cmd_AddParm(ts, "-live", CMD_FLAG, CMD_OPTIONAL,
5955 "copy live volume without cloning");
5956 cmd_AddParm(ts, "-incremental", CMD_FLAG, CMD_OPTIONAL,
5957 "do incremental update if target exists");
5960 ts = cmd_CreateSyntax("backup", BackupVolume, NULL,
5961 "make backup of a volume");
5962 cmd_AddParm(ts, "-id", CMD_SINGLE, 0, "volume name or ID");
5965 ts = cmd_CreateSyntax("clone", CloneVolume, NULL,
5966 "make clone of a volume");
5967 cmd_AddParm(ts, "-id", CMD_SINGLE, 0, "volume name or ID");
5968 cmd_AddParm(ts, "-server", CMD_SINGLE, CMD_OPTIONAL, "server");
5969 cmd_AddParm(ts, "-partition", CMD_SINGLE, CMD_OPTIONAL, "partition");
5970 cmd_AddParm(ts, "-toname", CMD_SINGLE, CMD_OPTIONAL,
5971 "volume name on destination");
5972 cmd_AddParm(ts, "-toid", CMD_SINGLE, CMD_OPTIONAL,
5973 "volume ID on destination");
5974 cmd_AddParm(ts, "-offline", CMD_FLAG, CMD_OPTIONAL,
5975 "leave clone volume offline");
5976 cmd_AddParm(ts, "-readonly", CMD_FLAG, CMD_OPTIONAL,
5977 "make clone volume read-only, not readwrite");
5978 cmd_AddParm(ts, "-readwrite", CMD_FLAG, CMD_OPTIONAL,
5979 "make clone volume readwrite, not read-only");
5982 ts = cmd_CreateSyntax("release", ReleaseVolume, NULL, "release a volume");
5983 cmd_AddParm(ts, "-id", CMD_SINGLE, 0, "volume name or ID");
5984 cmd_AddParm(ts, "-force", CMD_FLAG, CMD_OPTIONAL,
5985 "force a complete release");
5986 cmd_AddParm(ts, "-stayonline", CMD_FLAG, CMD_OPTIONAL,
5987 "release to cloned temp vol, then clone back to repsite RO");
5990 ts = cmd_CreateSyntax("dump", DumpVolumeCmd, NULL, "dump a volume");
5991 cmd_AddParm(ts, "-id", CMD_SINGLE, 0, "volume name or ID");
5992 cmd_AddParm(ts, "-time", CMD_SINGLE, CMD_OPTIONAL, "dump from time");
5993 cmd_AddParm(ts, "-file", CMD_SINGLE, CMD_OPTIONAL, "dump file");
5994 cmd_AddParm(ts, "-server", CMD_SINGLE, CMD_OPTIONAL, "server");
5995 cmd_AddParm(ts, "-partition", CMD_SINGLE, CMD_OPTIONAL, "partition");
5996 cmd_AddParm(ts, "-clone", CMD_FLAG, CMD_OPTIONAL,
5997 "dump a clone of the volume");
5998 cmd_AddParm(ts, "-omitdirs", CMD_FLAG, CMD_OPTIONAL,
5999 "omit unchanged directories from an incremental dump");
6002 ts = cmd_CreateSyntax("restore", RestoreVolumeCmd, NULL,
6003 "restore a volume");
6004 cmd_AddParm(ts, "-server", CMD_SINGLE, 0, "machine name");
6005 cmd_AddParm(ts, "-partition", CMD_SINGLE, 0, "partition name");
6006 cmd_AddParm(ts, "-name", CMD_SINGLE, 0, "name of volume to be restored");
6007 cmd_AddParm(ts, "-file", CMD_SINGLE, CMD_OPTIONAL, "dump file");
6008 cmd_AddParm(ts, "-id", CMD_SINGLE, CMD_OPTIONAL, "volume ID");
6009 cmd_AddParm(ts, "-overwrite", CMD_SINGLE, CMD_OPTIONAL,
6010 "abort | full | incremental");
6011 cmd_AddParm(ts, "-offline", CMD_FLAG, CMD_OPTIONAL,
6012 "leave restored volume offline");
6013 cmd_AddParm(ts, "-readonly", CMD_FLAG, CMD_OPTIONAL,
6014 "make restored volume read-only");
6015 cmd_AddParm(ts, "-creation", CMD_SINGLE, CMD_OPTIONAL,
6016 "dump | keep | new");
6017 cmd_AddParm(ts, "-lastupdate", CMD_SINGLE, CMD_OPTIONAL,
6018 "dump | keep | new");
6019 cmd_AddParm(ts, "-nodelete", CMD_FLAG, CMD_OPTIONAL,
6020 "do not delete old site when restoring to a new site");
6023 ts = cmd_CreateSyntax("unlock", LockReleaseCmd, NULL,
6024 "release lock on VLDB entry for a volume");
6025 cmd_AddParm(ts, "-id", CMD_SINGLE, 0, "volume name or ID");
6028 ts = cmd_CreateSyntax("changeloc", ChangeLocation, NULL,
6029 "change an RW volume's location in the VLDB");
6030 cmd_AddParm(ts, "-server", CMD_SINGLE, 0,
6031 "machine name for new location");
6032 cmd_AddParm(ts, "-partition", CMD_SINGLE, 0,
6033 "partition name for new location");
6034 cmd_AddParm(ts, "-id", CMD_SINGLE, 0, "volume name or ID");
6037 ts = cmd_CreateSyntax("addsite", AddSite, NULL, "add a replication site");
6038 cmd_AddParm(ts, "-server", CMD_SINGLE, 0, "machine name for new site");
6039 cmd_AddParm(ts, "-partition", CMD_SINGLE, 0,
6040 "partition name for new site");
6041 cmd_AddParm(ts, "-id", CMD_SINGLE, 0, "volume name or ID");
6042 cmd_AddParm(ts, "-roid", CMD_SINGLE, CMD_OPTIONAL, "volume name or ID for RO");
6043 cmd_AddParm(ts, "-valid", CMD_FLAG, CMD_OPTIONAL, "publish as an up-to-date site in VLDB");
6046 ts = cmd_CreateSyntax("remsite", RemoveSite, NULL,
6047 "remove a replication site");
6048 cmd_AddParm(ts, "-server", CMD_SINGLE, 0, "machine name");
6049 cmd_AddParm(ts, "-partition", CMD_SINGLE, 0, "partition name");
6050 cmd_AddParm(ts, "-id", CMD_SINGLE, 0, "volume name or ID");
6053 ts = cmd_CreateSyntax("listpart", ListPartitions, NULL, "list partitions");
6054 cmd_AddParm(ts, "-server", CMD_SINGLE, 0, "machine name");
6057 ts = cmd_CreateSyntax("listvol", ListVolumes, NULL,
6058 "list volumes on server (bypass VLDB)");
6059 cmd_AddParm(ts, "-server", CMD_SINGLE, 0, "machine name");
6060 cmd_AddParm(ts, "-partition", CMD_SINGLE, CMD_OPTIONAL, "partition name");
6061 cmd_AddParm(ts, "-fast", CMD_FLAG, CMD_OPTIONAL, "minimal listing");
6062 cmd_AddParm(ts, "-long", CMD_FLAG, CMD_OPTIONAL,
6063 "list all normal volume fields");
6064 cmd_AddParm(ts, "-quiet", CMD_FLAG, CMD_OPTIONAL,
6065 "generate minimal information");
6066 cmd_AddParm(ts, "-extended", CMD_FLAG, CMD_OPTIONAL,
6067 "list extended volume fields");
6068 cmd_AddParm(ts, "-format", CMD_FLAG, CMD_OPTIONAL,
6069 "machine readable format");
6072 ts = cmd_CreateSyntax("syncvldb", SyncVldb, NULL,
6073 "synchronize VLDB with server");
6074 cmd_AddParm(ts, "-server", CMD_SINGLE, CMD_OPTIONAL, "machine name");
6075 cmd_AddParm(ts, "-partition", CMD_SINGLE, CMD_OPTIONAL, "partition name");
6076 cmd_AddParm(ts, "-volume", CMD_SINGLE, CMD_OPTIONAL, "volume name or ID");
6077 cmd_AddParm(ts, "-dryrun", CMD_FLAG, CMD_OPTIONAL, "list what would be done, don't do it");
6080 ts = cmd_CreateSyntax("syncserv", SyncServer, NULL,
6081 "synchronize server with VLDB");
6082 cmd_AddParm(ts, "-server", CMD_SINGLE, 0, "machine name");
6083 cmd_AddParm(ts, "-partition", CMD_SINGLE, CMD_OPTIONAL, "partition name");
6084 cmd_AddParm(ts, "-dryrun", CMD_FLAG, CMD_OPTIONAL, "list what would be done, don't do it");
6087 ts = cmd_CreateSyntax("examine", ExamineVolume, NULL,
6088 "everything about the volume");
6089 cmd_AddParm(ts, "-id", CMD_SINGLE, 0, "volume name or ID");
6090 cmd_AddParm(ts, "-extended", CMD_FLAG, CMD_OPTIONAL,
6091 "list extended volume fields");
6092 cmd_AddParm(ts, "-format", CMD_FLAG, CMD_OPTIONAL,
6093 "machine readable format");
6095 cmd_CreateAlias(ts, "volinfo");
6096 cmd_CreateAlias(ts, "e");
6098 ts = cmd_CreateSyntax("setfields", SetFields, NULL,
6099 "change volume info fields");
6100 cmd_AddParm(ts, "-id", CMD_SINGLE, 0, "volume name or ID");
6101 cmd_AddParm(ts, "-maxquota", CMD_SINGLE, CMD_OPTIONAL, "quota (KB)");
6102 cmd_AddParm(ts, "-clearuse", CMD_FLAG, CMD_OPTIONAL, "clear dayUse");
6103 cmd_AddParm(ts, "-clearVolUpCounter", CMD_FLAG, CMD_OPTIONAL, "clear volUpdateCounter");
6106 ts = cmd_CreateSyntax("offline", volOffline, NULL, "force the volume status to offline");
6107 cmd_AddParm(ts, "-server", CMD_SINGLE, 0, "server name");
6108 cmd_AddParm(ts, "-partition", CMD_SINGLE, 0, "partition name");
6109 cmd_AddParm(ts, "-id", CMD_SINGLE, 0, "volume name or ID");
6110 cmd_AddParm(ts, "-sleep", CMD_SINGLE, CMD_OPTIONAL, "seconds to sleep");
6111 cmd_AddParm(ts, "-busy", CMD_FLAG, CMD_OPTIONAL, "busy volume");
6114 ts = cmd_CreateSyntax("online", volOnline, NULL, "force the volume status to online");
6115 cmd_AddParm(ts, "-server", CMD_SINGLE, 0, "server name");
6116 cmd_AddParm(ts, "-partition", CMD_SINGLE, 0, "partition name");
6117 cmd_AddParm(ts, "-id", CMD_SINGLE, 0, "volume name or ID");
6120 ts = cmd_CreateSyntax("zap", VolumeZap, NULL,
6121 "delete the volume, don't bother with VLDB");
6122 cmd_AddParm(ts, "-server", CMD_SINGLE, 0, "machine name");
6123 cmd_AddParm(ts, "-partition", CMD_SINGLE, 0, "partition name");
6124 cmd_AddParm(ts, "-id", CMD_SINGLE, 0, "volume ID");
6125 cmd_AddParm(ts, "-force", CMD_FLAG, CMD_OPTIONAL,
6126 "force deletion of bad volumes");
6127 cmd_AddParm(ts, "-backup", CMD_FLAG, CMD_OPTIONAL,
6128 "also delete backup volume if one is found");
6131 ts = cmd_CreateSyntax("status", VolserStatus, NULL,
6132 "report on volser status");
6133 cmd_AddParm(ts, "-server", CMD_SINGLE, 0, "machine name");
6136 ts = cmd_CreateSyntax("rename", RenameVolume, NULL, "rename a volume");
6137 cmd_AddParm(ts, "-oldname", CMD_SINGLE, 0, "old volume name ");
6138 cmd_AddParm(ts, "-newname", CMD_SINGLE, 0, "new volume name ");
6141 ts = cmd_CreateSyntax("listvldb", ListVLDB, NULL,
6142 "list volumes in the VLDB");
6143 cmd_AddParm(ts, "-name", CMD_SINGLE, CMD_OPTIONAL, "volume name or ID");
6144 cmd_AddParm(ts, "-server", CMD_SINGLE, CMD_OPTIONAL, "machine name");
6145 cmd_AddParm(ts, "-partition", CMD_SINGLE, CMD_OPTIONAL, "partition name");
6146 cmd_AddParm(ts, "-locked", CMD_FLAG, CMD_OPTIONAL, "locked volumes only");
6147 cmd_AddParm(ts, "-quiet", CMD_FLAG, CMD_OPTIONAL,
6148 "generate minimal information");
6149 cmd_AddParm(ts, "-nosort", CMD_FLAG, CMD_OPTIONAL,
6150 "do not alphabetically sort the volume names");
6153 ts = cmd_CreateSyntax("backupsys", BackSys, NULL, "en masse backups");
6154 cmd_AddParm(ts, "-prefix", CMD_LIST, CMD_OPTIONAL,
6155 "common prefix on volume(s)");
6156 cmd_AddParm(ts, "-server", CMD_SINGLE, CMD_OPTIONAL, "machine name");
6157 cmd_AddParm(ts, "-partition", CMD_SINGLE, CMD_OPTIONAL, "partition name");
6158 cmd_AddParm(ts, "-exclude", CMD_FLAG, CMD_OPTIONAL,
6159 "exclude common prefix volumes");
6160 cmd_AddParm(ts, "-xprefix", CMD_LIST, CMD_OPTIONAL,
6161 "negative prefix on volume(s)");
6162 cmd_AddParm(ts, "-dryrun", CMD_FLAG, CMD_OPTIONAL, "list what would be done, don't do it");
6165 ts = cmd_CreateSyntax("delentry", DeleteEntry, NULL,
6166 "delete VLDB entry for a volume");
6167 cmd_AddParm(ts, "-id", CMD_LIST, CMD_OPTIONAL, "volume name or ID");
6168 cmd_AddParm(ts, "-prefix", CMD_SINGLE, CMD_OPTIONAL,
6169 "prefix of the volume whose VLDB entry is to be deleted");
6170 cmd_AddParm(ts, "-server", CMD_SINGLE, CMD_OPTIONAL, "machine name");
6171 cmd_AddParm(ts, "-partition", CMD_SINGLE, CMD_OPTIONAL, "partition name");
6172 cmd_AddParm(ts, "-noexecute", CMD_FLAG, CMD_OPTIONAL|CMD_HIDDEN, "");
6173 cmd_AddParm(ts, "-dryrun", CMD_FLAG, CMD_OPTIONAL,
6174 "list what would be done, don't do it");
6177 ts = cmd_CreateSyntax("partinfo", PartitionInfo, NULL,
6178 "list partition information");
6179 cmd_AddParm(ts, "-server", CMD_SINGLE, 0, "machine name");
6180 cmd_AddParm(ts, "-partition", CMD_SINGLE, CMD_OPTIONAL, "partition name");
6181 cmd_AddParm(ts, "-summary", CMD_FLAG, CMD_OPTIONAL,
6182 "print storage summary");
6185 ts = cmd_CreateSyntax("unlockvldb", UnlockVLDB, NULL,
6186 "unlock all the locked entries in the VLDB");
6187 cmd_AddParm(ts, "-server", CMD_SINGLE, CMD_OPTIONAL, "machine name");
6188 cmd_AddParm(ts, "-partition", CMD_SINGLE, CMD_OPTIONAL, "partition name");
6191 ts = cmd_CreateSyntax("lock", LockEntry, NULL,
6192 "lock VLDB entry for a volume");
6193 cmd_AddParm(ts, "-id", CMD_SINGLE, 0, "volume name or ID");
6196 ts = cmd_CreateSyntax("changeaddr", ChangeAddr, NULL,
6197 "change the IP address of a file server");
6198 cmd_AddParm(ts, "-oldaddr", CMD_SINGLE, 0, "original IP address");
6199 cmd_AddParm(ts, "-newaddr", CMD_SINGLE, CMD_OPTIONAL, "new IP address");
6200 cmd_AddParm(ts, "-remove", CMD_FLAG, CMD_OPTIONAL,
6201 "remove the IP address from the VLDB");
6204 ts = cmd_CreateSyntax("listaddrs", ListAddrs, NULL,
6205 "list the IP address of all file servers registered in the VLDB");
6206 cmd_AddParm(ts, "-uuid", CMD_SINGLE, CMD_OPTIONAL, "uuid of server");
6207 cmd_AddParm(ts, "-host", CMD_SINGLE, CMD_OPTIONAL, "address of host");
6208 cmd_AddParm(ts, "-printuuid", CMD_FLAG, CMD_OPTIONAL,
6209 "print uuid of hosts");
6212 ts = cmd_CreateSyntax("convertROtoRW", ConvertRO, NULL,
6213 "convert a RO volume into a RW volume (after loss of old RW volume)");
6214 cmd_AddParm(ts, "-server", CMD_SINGLE, 0, "machine name");
6215 cmd_AddParm(ts, "-partition", CMD_SINGLE, 0, "partition name");
6216 cmd_AddParm(ts, "-id", CMD_SINGLE, 0, "volume name or ID");
6217 cmd_AddParm(ts, "-force", CMD_FLAG, CMD_OPTIONAL, "don't ask");
6220 ts = cmd_CreateSyntax("size", Sizes, NULL,
6221 "obtain various sizes of the volume.");
6222 cmd_AddParm(ts, "-id", CMD_SINGLE, 0, "volume name or ID");
6223 cmd_AddParm(ts, "-partition", CMD_SINGLE, CMD_OPTIONAL, "partition name");
6224 cmd_AddParm(ts, "-server", CMD_SINGLE, CMD_OPTIONAL, "machine name");
6225 cmd_AddParm(ts, "-dump", CMD_FLAG, CMD_OPTIONAL,
6226 "Obtain the size of the dump");
6227 cmd_AddParm(ts, "-time", CMD_SINGLE, CMD_OPTIONAL, "dump from time");
6230 ts = cmd_CreateSyntax("endtrans", EndTrans, NULL,
6231 "end a volserver transaction");
6232 cmd_AddParm(ts, "-server", CMD_SINGLE, 0, "machine name");
6233 cmd_AddParm(ts, "-transaction", CMD_SINGLE, 0,
6237 ts = cmd_CreateSyntax("setaddrs", SetAddrs, NULL,
6238 "set the list of IP address for a given UUID in the VLDB");
6239 cmd_AddParm(ts, "-uuid", CMD_SINGLE, 0, "uuid of server");
6240 cmd_AddParm(ts, "-host", CMD_LIST, 0, "address of host");
6243 code = cmd_Dispatch(argc, argv);
6245 /* Shut down the ubik_client and rx connections */
6247 (void)ubik_ClientDestroy(cstruct);
6253 exit((code ? -1 : 0));