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, 1, "-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 the address in network byte order
214 GetServer(char *aname)
217 afs_uint32 addr; /* in network byte order */
219 char hostname[MAXHOSTCHARS];
221 if ((addr = GetServerNoresolve(aname)) == 0) {
222 th = gethostbyname(aname);
225 memcpy(&addr, th->h_addr, sizeof(addr));
228 if (rx_IsLoopbackAddr(ntohl(addr))) { /* local host */
229 code = gethostname(hostname, MAXHOSTCHARS);
232 th = gethostbyname(hostname);
235 memcpy(&addr, th->h_addr, sizeof(addr));
242 GetVolumeType(char *aname)
245 if (!strcmp(aname, "ro"))
247 else if (!strcmp(aname, "rw"))
249 else if (!strcmp(aname, "bk"))
256 IsPartValid(afs_int32 partId, afs_uint32 server, afs_int32 *code)
258 struct partList dummyPartList;
264 *code = UV_ListPartitions(server, &dummyPartList, &cnt);
267 for (i = 0; i < cnt; i++) {
268 if (dummyPartList.partFlags[i] & PARTVALID)
269 if (dummyPartList.partId[i] == partId)
277 /*sends the contents of file associated with <fd> and <blksize> to Rx Stream
278 * associated with <call> */
280 SendFile(usd_handle_t ufd, struct rx_call *call, long blksize)
282 char *buffer = (char *)0;
286 buffer = malloc(blksize);
288 fprintf(STDERR, "malloc failed\n");
293 #ifndef AFS_NT40_ENV /* NT csn't select on non-socket fd's */
296 FD_SET((intptr_t)(ufd->handle), &in);
297 /* don't timeout if read blocks */
298 #if defined(AFS_PTHREAD_ENV)
299 select(((intptr_t)(ufd->handle)) + 1, &in, 0, 0, 0);
301 IOMGR_Select(((intptr_t)(ufd->handle)) + 1, &in, 0, 0, 0);
304 error = USD_READ(ufd, buffer, blksize, &nbytes);
306 fprintf(STDERR, "File system read failed: %s\n",
307 afs_error_message(error));
314 if (rx_Write(call, buffer, nbytes) != nbytes) {
324 /* function invoked by UV_RestoreVolume, reads the data from rx_trx_stream and
325 * writes it out to the volume. */
327 WriteData(struct rx_call *call, void *rock)
329 char *filename = (char *) rock;
332 afs_int32 error, code;
334 afs_int64 currOffset;
340 if (!filename || !*filename) {
341 usd_StandardInput(&ufd);
345 code = usd_Open(filename, USD_OPEN_RDONLY, 0, &ufd);
348 code = USD_IOCTL(ufd, USD_IOCTL_GETBLKSIZE, &blksize);
351 fprintf(STDERR, "Could not access file '%s': %s\n", filename,
352 afs_error_message(code));
356 /* test if we have a valid dump */
357 USD_SEEK(ufd, 0, SEEK_END, &currOffset);
358 USD_SEEK(ufd, currOffset - sizeof(afs_uint32), SEEK_SET, &currOffset);
359 USD_READ(ufd, (char *)&buffer, sizeof(afs_uint32), &got);
360 if ((got != sizeof(afs_uint32)) || (ntohl(buffer) != DUMPENDMAGIC)) {
361 fprintf(STDERR, "Signature missing from end of file '%s'\n", filename);
365 USD_SEEK(ufd, 0, SEEK_SET, &currOffset);
367 code = SendFile(ufd, call, blksize);
374 code = USD_CLOSE(ufd);
376 fprintf(STDERR, "Could not close dump file %s\n",
377 (filename && *filename) ? filename : "STDOUT");
385 /* Receive data from <call> stream into file associated
386 * with <fd> <blksize>
389 ReceiveFile(usd_handle_t ufd, struct rx_call *call, long blksize)
393 afs_uint32 bytesleft, w;
396 buffer = malloc(blksize);
398 fprintf(STDERR, "memory allocation failed\n");
402 while ((bytesread = rx_Read(call, buffer, blksize)) > 0) {
403 for (bytesleft = bytesread; bytesleft; bytesleft -= w) {
404 #ifndef AFS_NT40_ENV /* NT csn't select on non-socket fd's */
407 FD_SET((intptr_t)(ufd->handle), &out);
408 /* don't timeout if write blocks */
409 #if defined(AFS_PTHREAD_ENV)
410 select(((intptr_t)(ufd->handle)) + 1, &out, 0, 0, 0);
412 IOMGR_Select(((intptr_t)(ufd->handle)) + 1, 0, &out, 0, 0);
416 USD_WRITE(ufd, &buffer[bytesread - bytesleft], bytesleft, &w);
418 fprintf(STDERR, "File system write failed: %s\n",
419 afs_error_message(error));
432 DumpFunction(struct rx_call *call, void *rock)
434 char *filename = (char *)rock;
435 usd_handle_t ufd; /* default is to stdout */
436 afs_int32 error = 0, code;
441 /* Open the output file */
442 if (!filename || !*filename) {
443 usd_StandardOutput(&ufd);
448 usd_Open(filename, USD_OPEN_CREATE | USD_OPEN_RDWR, 0666, &ufd);
452 code = USD_IOCTL(ufd, USD_IOCTL_SETSIZE, &size);
455 code = USD_IOCTL(ufd, USD_IOCTL_GETBLKSIZE, &blksize);
458 fprintf(STDERR, "Could not create file '%s': %s\n", filename,
459 afs_error_message(code));
460 ERROR_EXIT(VOLSERBADOP);
464 code = ReceiveFile(ufd, call, blksize);
469 /* Close the output file */
471 code = USD_CLOSE(ufd);
473 fprintf(STDERR, "Could not close dump file %s\n",
474 (filename && *filename) ? filename : "STDIN");
484 DisplayFormat(volintInfo *pntr, afs_uint32 server, afs_int32 part,
485 int *totalOK, int *totalNotOK, int *totalBusy, int fast,
486 int longlist, int disp)
492 fprintf(STDOUT, "%-10lu\n", (unsigned long)pntr->volid);
493 } else if (longlist) {
494 if (pntr->status == VOK) {
495 fprintf(STDOUT, "%-32s ", pntr->name);
496 fprintf(STDOUT, "%10lu ", (unsigned long)pntr->volid);
498 fprintf(STDOUT, "RW ");
500 fprintf(STDOUT, "RO ");
502 fprintf(STDOUT, "BK ");
503 fprintf(STDOUT, "%10d K ", pntr->size);
504 if (pntr->inUse == 1) {
505 fprintf(STDOUT, "On-line");
508 fprintf(STDOUT, "Off-line");
511 if (pntr->needsSalvaged == 1)
512 fprintf(STDOUT, "**needs salvage**");
513 fprintf(STDOUT, "\n");
514 MapPartIdIntoName(part, pname);
515 fprintf(STDOUT, " %s %s \n", hostutil_GetNameByINet(server),
517 fprintf(STDOUT, " RWrite %10lu ROnly %10lu Backup %10lu \n",
518 (unsigned long)pntr->parentID,
519 (unsigned long)pntr->cloneID,
520 (unsigned long)pntr->backupID);
521 fprintf(STDOUT, " MaxQuota %10d K \n", pntr->maxquota);
522 t = pntr->creationDate;
523 fprintf(STDOUT, " Creation %s",
526 fprintf(STDOUT, " Copy %s",
529 t = pntr->backupDate;
531 fprintf(STDOUT, " Backup Never\n");
533 fprintf(STDOUT, " Backup %s",
536 t = pntr->accessDate;
538 fprintf(STDOUT, " Last Access %s",
541 t = pntr->updateDate;
543 fprintf(STDOUT, " Last Update Never\n");
545 fprintf(STDOUT, " Last Update %s",
548 " %d accesses in the past day (i.e., vnode references)\n",
550 } else if (pntr->status == VBUSY) {
552 qPut(&busyHead, pntr->volid);
554 fprintf(STDOUT, "**** Volume %lu is busy ****\n",
555 (unsigned long)pntr->volid);
558 qPut(¬okHead, pntr->volid);
560 fprintf(STDOUT, "**** Could not attach volume %lu ****\n",
561 (unsigned long)pntr->volid);
563 fprintf(STDOUT, "\n");
564 } else { /* default listing */
565 if (pntr->status == VOK) {
566 fprintf(STDOUT, "%-32s ", pntr->name);
567 fprintf(STDOUT, "%10lu ", (unsigned long)pntr->volid);
569 fprintf(STDOUT, "RW ");
571 fprintf(STDOUT, "RO ");
573 fprintf(STDOUT, "BK ");
574 fprintf(STDOUT, "%10d K ", pntr->size);
575 if (pntr->inUse == 1) {
576 fprintf(STDOUT, "On-line");
579 fprintf(STDOUT, "Off-line");
582 if (pntr->needsSalvaged == 1)
583 fprintf(STDOUT, "**needs salvage**");
584 fprintf(STDOUT, "\n");
585 } else if (pntr->status == VBUSY) {
587 qPut(&busyHead, pntr->volid);
589 fprintf(STDOUT, "**** Volume %lu is busy ****\n",
590 (unsigned long)pntr->volid);
593 qPut(¬okHead, pntr->volid);
595 fprintf(STDOUT, "**** Could not attach volume %lu ****\n",
596 (unsigned long)pntr->volid);
601 /*------------------------------------------------------------------------
602 * PRIVATE XDisplayFormat
605 * Display the contents of one extended volume info structure.
608 * a_xInfoP : Ptr to extended volume info struct to print.
609 * a_servID : Server ID to print.
610 * a_partID : Partition ID to print.
611 * a_totalOKP : Ptr to total-OK counter.
612 * a_totalNotOKP : Ptr to total-screwed counter.
613 * a_totalBusyP : Ptr to total-busy counter.
614 * a_fast : Fast listing?
615 * a_int32 : Int32 listing?
616 * a_showProblems : Show volume problems?
622 * Nothing interesting.
626 *------------------------------------------------------------------------*/
629 XDisplayFormat(volintXInfo *a_xInfoP, afs_uint32 a_servID, afs_int32 a_partID,
630 int *a_totalOKP, int *a_totalNotOKP, int *a_totalBusyP,
631 int a_fast, int a_int32, int a_showProblems)
632 { /*XDisplayFormat */
640 fprintf(STDOUT, "%-10lu\n", (unsigned long)a_xInfoP->volid);
641 } else if (a_int32) {
643 * Fully-detailed listing.
645 if (a_xInfoP->status == VOK) {
647 * Volume's status is OK - all the fields are valid.
649 fprintf(STDOUT, "%-32s ", a_xInfoP->name);
650 fprintf(STDOUT, "%10lu ", (unsigned long)a_xInfoP->volid);
651 if (a_xInfoP->type == 0)
652 fprintf(STDOUT, "RW ");
653 if (a_xInfoP->type == 1)
654 fprintf(STDOUT, "RO ");
655 if (a_xInfoP->type == 2)
656 fprintf(STDOUT, "BK ");
657 fprintf(STDOUT, "%10d K used ", a_xInfoP->size);
658 fprintf(STDOUT, "%d files ", a_xInfoP->filecount);
659 if (a_xInfoP->inUse == 1) {
660 fprintf(STDOUT, "On-line");
663 fprintf(STDOUT, "Off-line");
666 fprintf(STDOUT, "\n");
667 MapPartIdIntoName(a_partID, pname);
668 fprintf(STDOUT, " %s %s \n", hostutil_GetNameByINet(a_servID),
670 fprintf(STDOUT, " RWrite %10lu ROnly %10lu Backup %10lu \n",
671 (unsigned long)a_xInfoP->parentID,
672 (unsigned long)a_xInfoP->cloneID,
673 (unsigned long)a_xInfoP->backupID);
674 fprintf(STDOUT, " MaxQuota %10d K \n", a_xInfoP->maxquota);
676 t = a_xInfoP->creationDate;
677 fprintf(STDOUT, " Creation %s",
680 t = a_xInfoP->copyDate;
681 fprintf(STDOUT, " Copy %s",
684 t = a_xInfoP->backupDate;
686 fprintf(STDOUT, " Backup Never\n");
688 fprintf(STDOUT, " Backup %s",
691 t = a_xInfoP->accessDate;
693 fprintf(STDOUT, " Last Access %s",
696 t = a_xInfoP->updateDate;
698 fprintf(STDOUT, " Last Update Never\n");
700 fprintf(STDOUT, " Last Update %s",
703 " %d accesses in the past day (i.e., vnode references)\n",
707 * Print all the read/write and authorship stats.
709 fprintf(STDOUT, "\n Raw Read/Write Stats\n");
711 " |-------------------------------------------|\n");
713 " | Same Network | Diff Network |\n");
715 " |----------|----------|----------|----------|\n");
717 " | Total | Auth | Total | Auth |\n");
719 " |----------|----------|----------|----------|\n");
720 fprintf(STDOUT, "Reads | %8d | %8d | %8d | %8d |\n",
721 a_xInfoP->stat_reads[VOLINT_STATS_SAME_NET],
722 a_xInfoP->stat_reads[VOLINT_STATS_SAME_NET_AUTH],
723 a_xInfoP->stat_reads[VOLINT_STATS_DIFF_NET],
724 a_xInfoP->stat_reads[VOLINT_STATS_DIFF_NET_AUTH]);
725 fprintf(STDOUT, "Writes | %8d | %8d | %8d | %8d |\n",
726 a_xInfoP->stat_writes[VOLINT_STATS_SAME_NET],
727 a_xInfoP->stat_writes[VOLINT_STATS_SAME_NET_AUTH],
728 a_xInfoP->stat_writes[VOLINT_STATS_DIFF_NET],
729 a_xInfoP->stat_writes[VOLINT_STATS_DIFF_NET_AUTH]);
731 " |-------------------------------------------|\n\n");
734 " Writes Affecting Authorship\n");
736 " |-------------------------------------------|\n");
738 " | File Authorship | Directory Authorship|\n");
740 " |----------|----------|----------|----------|\n");
742 " | Same | Diff | Same | Diff |\n");
744 " |----------|----------|----------|----------|\n");
745 fprintf(STDOUT, "0-60 sec | %8d | %8d | %8d | %8d |\n",
746 a_xInfoP->stat_fileSameAuthor[VOLINT_STATS_TIME_IDX_0],
747 a_xInfoP->stat_fileDiffAuthor[VOLINT_STATS_TIME_IDX_0],
748 a_xInfoP->stat_dirSameAuthor[VOLINT_STATS_TIME_IDX_0],
749 a_xInfoP->stat_dirDiffAuthor[VOLINT_STATS_TIME_IDX_0]);
750 fprintf(STDOUT, "1-10 min | %8d | %8d | %8d | %8d |\n",
751 a_xInfoP->stat_fileSameAuthor[VOLINT_STATS_TIME_IDX_1],
752 a_xInfoP->stat_fileDiffAuthor[VOLINT_STATS_TIME_IDX_1],
753 a_xInfoP->stat_dirSameAuthor[VOLINT_STATS_TIME_IDX_1],
754 a_xInfoP->stat_dirDiffAuthor[VOLINT_STATS_TIME_IDX_1]);
755 fprintf(STDOUT, "10min-1hr | %8d | %8d | %8d | %8d |\n",
756 a_xInfoP->stat_fileSameAuthor[VOLINT_STATS_TIME_IDX_2],
757 a_xInfoP->stat_fileDiffAuthor[VOLINT_STATS_TIME_IDX_2],
758 a_xInfoP->stat_dirSameAuthor[VOLINT_STATS_TIME_IDX_2],
759 a_xInfoP->stat_dirDiffAuthor[VOLINT_STATS_TIME_IDX_2]);
760 fprintf(STDOUT, "1hr-1day | %8d | %8d | %8d | %8d |\n",
761 a_xInfoP->stat_fileSameAuthor[VOLINT_STATS_TIME_IDX_3],
762 a_xInfoP->stat_fileDiffAuthor[VOLINT_STATS_TIME_IDX_3],
763 a_xInfoP->stat_dirSameAuthor[VOLINT_STATS_TIME_IDX_3],
764 a_xInfoP->stat_dirDiffAuthor[VOLINT_STATS_TIME_IDX_3]);
765 fprintf(STDOUT, "1day-1wk | %8d | %8d | %8d | %8d |\n",
766 a_xInfoP->stat_fileSameAuthor[VOLINT_STATS_TIME_IDX_4],
767 a_xInfoP->stat_fileDiffAuthor[VOLINT_STATS_TIME_IDX_4],
768 a_xInfoP->stat_dirSameAuthor[VOLINT_STATS_TIME_IDX_4],
769 a_xInfoP->stat_dirDiffAuthor[VOLINT_STATS_TIME_IDX_4]);
770 fprintf(STDOUT, "> 1wk | %8d | %8d | %8d | %8d |\n",
771 a_xInfoP->stat_fileSameAuthor[VOLINT_STATS_TIME_IDX_5],
772 a_xInfoP->stat_fileDiffAuthor[VOLINT_STATS_TIME_IDX_5],
773 a_xInfoP->stat_dirSameAuthor[VOLINT_STATS_TIME_IDX_5],
774 a_xInfoP->stat_dirDiffAuthor[VOLINT_STATS_TIME_IDX_5]);
776 " |-------------------------------------------|\n");
777 } /*Volume status OK */
778 else if (a_xInfoP->status == VBUSY) {
780 qPut(&busyHead, a_xInfoP->volid);
782 fprintf(STDOUT, "**** Volume %lu is busy ****\n",
783 (unsigned long)a_xInfoP->volid);
787 qPut(¬okHead, a_xInfoP->volid);
789 fprintf(STDOUT, "**** Could not attach volume %lu ****\n",
790 (unsigned long)a_xInfoP->volid);
791 } /*Screwed volume */
792 fprintf(STDOUT, "\n");
798 if (a_xInfoP->status == VOK) {
799 fprintf(STDOUT, "%-32s ", a_xInfoP->name);
800 fprintf(STDOUT, "%10lu ", (unsigned long)a_xInfoP->volid);
801 if (a_xInfoP->type == 0)
802 fprintf(STDOUT, "RW ");
803 if (a_xInfoP->type == 1)
804 fprintf(STDOUT, "RO ");
805 if (a_xInfoP->type == 2)
806 fprintf(STDOUT, "BK ");
807 fprintf(STDOUT, "%10d K ", a_xInfoP->size);
808 if (a_xInfoP->inUse == 1) {
809 fprintf(STDOUT, "On-line");
812 fprintf(STDOUT, "Off-line");
815 fprintf(STDOUT, "\n");
817 else if (a_xInfoP->status == VBUSY) {
819 qPut(&busyHead, a_xInfoP->volid);
821 fprintf(STDOUT, "**** Volume %lu is busy ****\n",
822 (unsigned long)a_xInfoP->volid);
826 qPut(¬okHead, a_xInfoP->volid);
828 fprintf(STDOUT, "**** Could not attach volume %lu ****\n",
829 (unsigned long)a_xInfoP->volid);
830 } /*Screwed volume */
831 } /*Default listing */
832 } /*XDisplayFormat */
834 /*------------------------------------------------------------------------
835 * PRIVATE XDisplayFormat2
838 * Display the formated contents of one extended volume info structure.
841 * a_xInfoP : Ptr to extended volume info struct to print.
842 * a_servID : Server ID to print.
843 * a_partID : Partition ID to print.
844 * a_totalOKP : Ptr to total-OK counter.
845 * a_totalNotOKP : Ptr to total-screwed counter.
846 * a_totalBusyP : Ptr to total-busy counter.
847 * a_fast : Fast listing?
848 * a_int32 : Int32 listing?
849 * a_showProblems : Show volume problems?
855 * Nothing interesting.
859 *------------------------------------------------------------------------*/
862 XDisplayFormat2(volintXInfo *a_xInfoP, afs_uint32 a_servID, afs_int32 a_partID,
863 int *a_totalOKP, int *a_totalNotOKP, int *a_totalBusyP,
864 int a_fast, int a_int32, int a_showProblems)
865 { /*XDisplayFormat */
871 fprintf(STDOUT, "vold_id\t%-10lu\n", (unsigned long)a_xInfoP->volid);
872 } else if (a_int32) {
874 * Fully-detailed listing.
876 if (a_xInfoP->status == VOK) {
878 * Volume's status is OK - all the fields are valid.
881 static long server_cache = -1, partition_cache = -1;
882 static char hostname[256], address[32], pname[16];
883 int i,ai[] = {VOLINT_STATS_TIME_IDX_0,VOLINT_STATS_TIME_IDX_1,VOLINT_STATS_TIME_IDX_2,
884 VOLINT_STATS_TIME_IDX_3,VOLINT_STATS_TIME_IDX_4,VOLINT_STATS_TIME_IDX_5};
886 if (a_servID != server_cache) {
890 strcpy(hostname, hostutil_GetNameByINet(a_servID));
891 strcpy(address, inet_ntoa(s));
892 server_cache = a_servID;
894 if (a_partID != partition_cache) {
895 MapPartIdIntoName(a_partID, pname);
896 partition_cache = a_partID;
899 fprintf(STDOUT, "name\t\t%s\n", a_xInfoP->name);
900 fprintf(STDOUT, "id\t\t%lu\n", afs_printable_uint32_lu(a_xInfoP->volid));
901 fprintf(STDOUT, "serv\t\t%s\t%s\n", address, hostname);
902 fprintf(STDOUT, "part\t\t%s\n", pname);
903 fprintf(STDOUT, "status\t\tOK\n");
904 fprintf(STDOUT, "backupID\t%lu\n",
905 afs_printable_uint32_lu(a_xInfoP->backupID));
906 fprintf(STDOUT, "parentID\t%lu\n",
907 afs_printable_uint32_lu(a_xInfoP->parentID));
908 fprintf(STDOUT, "cloneID\t\t%lu\n",
909 afs_printable_uint32_lu(a_xInfoP->cloneID));
910 fprintf(STDOUT, "inUse\t\t%s\n", a_xInfoP->inUse ? "Y" : "N");
911 switch (a_xInfoP->type) {
913 fprintf(STDOUT, "type\t\tRW\n");
916 fprintf(STDOUT, "type\t\tRO\n");
919 fprintf(STDOUT, "type\t\tBK\n");
922 fprintf(STDOUT, "type\t\t?\n");
925 t = a_xInfoP->creationDate;
926 fprintf(STDOUT, "creationDate\t%-9lu\t%s",
927 afs_printable_uint32_lu(a_xInfoP->creationDate),
930 t = a_xInfoP->accessDate;
931 fprintf(STDOUT, "accessDate\t%-9lu\t%s",
932 afs_printable_uint32_lu(a_xInfoP->accessDate),
935 t = a_xInfoP->updateDate;
936 fprintf(STDOUT, "updateDate\t%-9lu\t%s",
937 afs_printable_uint32_lu(a_xInfoP->updateDate),
940 t = a_xInfoP->backupDate;
941 fprintf(STDOUT, "backupDate\t%-9lu\t%s",
942 afs_printable_uint32_lu(a_xInfoP->backupDate),
945 t = a_xInfoP->copyDate;
946 fprintf(STDOUT, "copyDate\t%-9lu\t%s",
947 afs_printable_uint32_lu(a_xInfoP->copyDate),
950 fprintf(STDOUT, "diskused\t%u\n", a_xInfoP->size);
951 fprintf(STDOUT, "maxquota\t%u\n", a_xInfoP->maxquota);
953 fprintf(STDOUT, "filecount\t%u\n", a_xInfoP->filecount);
954 fprintf(STDOUT, "dayUse\t\t%u\n", a_xInfoP->dayUse);
958 fprintf(STDOUT,"reads_same_net\t%8d\n",a_xInfoP->stat_reads[VOLINT_STATS_SAME_NET]);
959 fprintf(STDOUT,"reads_same_net_auth\t%8d\n",a_xInfoP->stat_reads[VOLINT_STATS_SAME_NET_AUTH]);
960 fprintf(STDOUT,"reads_diff_net\t%8d\n",a_xInfoP->stat_reads[VOLINT_STATS_DIFF_NET]);
961 fprintf(STDOUT,"reads_diff_net_auth\t%8d\n",a_xInfoP->stat_reads[VOLINT_STATS_DIFF_NET_AUTH]);
963 fprintf(STDOUT,"writes_same_net\t%8d\n",a_xInfoP->stat_writes[VOLINT_STATS_SAME_NET]);
964 fprintf(STDOUT,"writes_same_net_auth\t%8d\n",a_xInfoP->stat_writes[VOLINT_STATS_SAME_NET_AUTH]);
965 fprintf(STDOUT,"writes_diff_net\t%8d\n",a_xInfoP->stat_writes[VOLINT_STATS_DIFF_NET]);
966 fprintf(STDOUT,"writes_diff_net_auth\t%8d\n",a_xInfoP->stat_writes[VOLINT_STATS_DIFF_NET_AUTH]);
970 fprintf(STDOUT,"file_same_author_idx_%d\t%8d\n",i+1,a_xInfoP->stat_fileSameAuthor[ai[i]]);
971 fprintf(STDOUT,"file_diff_author_idx_%d\t%8d\n",i+1,a_xInfoP->stat_fileDiffAuthor[ai[i]]);
972 fprintf(STDOUT,"dir_same_author_idx_%d\t%8d\n",i+1,a_xInfoP->stat_dirSameAuthor[ai[i]]);
973 fprintf(STDOUT,"dir_dif_author_idx_%d\t%8d\n",i+1,a_xInfoP->stat_dirDiffAuthor[ai[i]]);
976 } /*Volume status OK */
977 else if (a_xInfoP->status == VBUSY) {
979 qPut(&busyHead, a_xInfoP->volid);
981 fprintf(STDOUT, "BUSY_VOL\t%lu\n",
982 (unsigned long)a_xInfoP->volid);
986 qPut(¬okHead, a_xInfoP->volid);
988 fprintf(STDOUT, "COULD_NOT_ATTACH\t%lu\n",
989 (unsigned long)a_xInfoP->volid);
990 } /*Screwed volume */
996 if (a_xInfoP->status == VOK) {
997 fprintf(STDOUT, "name\t%-32s\n", a_xInfoP->name);
998 fprintf(STDOUT, "volID\t%10lu\n", (unsigned long)a_xInfoP->volid);
999 if (a_xInfoP->type == 0)
1000 fprintf(STDOUT, "type\tRW\n");
1001 if (a_xInfoP->type == 1)
1002 fprintf(STDOUT, "type\tRO\n");
1003 if (a_xInfoP->type == 2)
1004 fprintf(STDOUT, "type\tBK\n");
1005 fprintf(STDOUT, "size\t%10dK\n", a_xInfoP->size);
1007 fprintf(STDOUT, "inUse\t%d\n",a_xInfoP->inUse);
1008 if (a_xInfoP->inUse == 1)
1014 else if (a_xInfoP->status == VBUSY) {
1016 qPut(&busyHead, a_xInfoP->volid);
1018 fprintf(STDOUT, "VOLUME_BUSY\t%lu\n",
1019 (unsigned long)a_xInfoP->volid);
1023 qPut(¬okHead, a_xInfoP->volid);
1025 fprintf(STDOUT, "COULD_NOT_ATTACH_VOLUME\t%lu\n",
1026 (unsigned long)a_xInfoP->volid);
1027 } /*Screwed volume */
1028 } /*Default listing */
1029 } /*XDisplayFormat */
1032 DisplayFormat2(long server, long partition, volintInfo *pntr)
1034 static long server_cache = -1, partition_cache = -1;
1035 static char hostname[256], address[32], pname[16];
1038 if (server != server_cache) {
1042 strcpy(hostname, hostutil_GetNameByINet(server));
1043 strcpy(address, inet_ntoa(s));
1044 server_cache = server;
1046 if (partition != partition_cache) {
1047 MapPartIdIntoName(partition, pname);
1048 partition_cache = partition;
1051 if (pntr->status == VOK)
1052 fprintf(STDOUT, "name\t\t%s\n", pntr->name);
1054 fprintf(STDOUT, "id\t\t%lu\n",
1055 afs_printable_uint32_lu(pntr->volid));
1056 fprintf(STDOUT, "serv\t\t%s\t%s\n", address, hostname);
1057 fprintf(STDOUT, "part\t\t%s\n", pname);
1058 switch (pntr->status) {
1060 fprintf(STDOUT, "status\t\tOK\n");
1063 fprintf(STDOUT, "status\t\tBUSY\n");
1066 fprintf(STDOUT, "status\t\tUNATTACHABLE\n");
1069 fprintf(STDOUT, "backupID\t%lu\n",
1070 afs_printable_uint32_lu(pntr->backupID));
1071 fprintf(STDOUT, "parentID\t%lu\n",
1072 afs_printable_uint32_lu(pntr->parentID));
1073 fprintf(STDOUT, "cloneID\t\t%lu\n",
1074 afs_printable_uint32_lu(pntr->cloneID));
1075 fprintf(STDOUT, "inUse\t\t%s\n", pntr->inUse ? "Y" : "N");
1076 fprintf(STDOUT, "needsSalvaged\t%s\n", pntr->needsSalvaged ? "Y" : "N");
1077 /* 0xD3 is from afs/volume.h since I had trouble including the file */
1078 fprintf(STDOUT, "destroyMe\t%s\n", pntr->destroyMe == 0xD3 ? "Y" : "N");
1079 switch (pntr->type) {
1081 fprintf(STDOUT, "type\t\tRW\n");
1084 fprintf(STDOUT, "type\t\tRO\n");
1087 fprintf(STDOUT, "type\t\tBK\n");
1090 fprintf(STDOUT, "type\t\t?\n");
1093 t = pntr->creationDate;
1094 fprintf(STDOUT, "creationDate\t%-9lu\t%s",
1095 afs_printable_uint32_lu(pntr->creationDate),
1098 t = pntr->accessDate;
1099 fprintf(STDOUT, "accessDate\t%-9lu\t%s",
1100 afs_printable_uint32_lu(pntr->accessDate),
1103 t = pntr->updateDate;
1104 fprintf(STDOUT, "updateDate\t%-9lu\t%s",
1105 afs_printable_uint32_lu(pntr->updateDate),
1108 t = pntr->backupDate;
1109 fprintf(STDOUT, "backupDate\t%-9lu\t%s",
1110 afs_printable_uint32_lu(pntr->backupDate),
1114 fprintf(STDOUT, "copyDate\t%-9lu\t%s",
1115 afs_printable_uint32_lu(pntr->copyDate),
1118 fprintf(STDOUT, "flags\t\t%#lx\t(Optional)\n",
1119 afs_printable_uint32_lu(pntr->flags));
1120 fprintf(STDOUT, "diskused\t%u\n", pntr->size);
1121 fprintf(STDOUT, "maxquota\t%u\n", pntr->maxquota);
1122 fprintf(STDOUT, "minquota\t%lu\t(Optional)\n",
1123 afs_printable_uint32_lu(pntr->spare0));
1124 fprintf(STDOUT, "filecount\t%u\n", pntr->filecount);
1125 fprintf(STDOUT, "dayUse\t\t%u\n", pntr->dayUse);
1126 fprintf(STDOUT, "weekUse\t\t%lu\t(Optional)\n",
1127 afs_printable_uint32_lu(pntr->spare1));
1128 fprintf(STDOUT, "spare2\t\t%lu\t(Optional)\n",
1129 afs_printable_uint32_lu(pntr->spare2));
1130 fprintf(STDOUT, "spare3\t\t%lu\t(Optional)\n",
1131 afs_printable_uint32_lu(pntr->spare3));
1136 DisplayVolumes2(long server, long partition, volintInfo *pntr, long count)
1140 for (i = 0; i < count; i++) {
1141 fprintf(STDOUT, "BEGIN_OF_ENTRY\n");
1142 DisplayFormat2(server, partition, pntr);
1143 fprintf(STDOUT, "END_OF_ENTRY\n\n");
1150 DisplayVolumes(afs_uint32 server, afs_int32 part, volintInfo *pntr,
1151 afs_int32 count, afs_int32 longlist, afs_int32 fast,
1154 int totalOK, totalNotOK, totalBusy, i;
1155 afs_uint32 volid = 0;
1162 for (i = 0; i < count; i++) {
1163 DisplayFormat(pntr, server, part, &totalOK, &totalNotOK, &totalBusy,
1168 while (busyHead.count) {
1169 qGet(&busyHead, &volid);
1170 fprintf(STDOUT, "**** Volume %lu is busy ****\n",
1171 (unsigned long)volid);
1175 while (notokHead.count) {
1176 qGet(¬okHead, &volid);
1177 fprintf(STDOUT, "**** Could not attach volume %lu ****\n",
1178 (unsigned long)volid);
1182 fprintf(STDOUT, "\n");
1185 "Total volumes onLine %d ; Total volumes offLine %d ; Total busy %d\n\n",
1186 totalOK, totalNotOK, totalBusy);
1190 /*------------------------------------------------------------------------
1191 * PRIVATE XDisplayVolumes
1194 * Display extended volume information.
1197 * a_servID : Pointer to the Rx call we're performing.
1198 * a_partID : Partition for which we want the extended list.
1199 * a_xInfoP : Ptr to extended volume info.
1200 * a_count : Number of volume records contained above.
1201 * a_int32 : Int32 listing generated?
1202 * a_fast : Fast listing generated?
1203 * a_quiet : Quiet listing generated?
1209 * Nothing interesting.
1213 *------------------------------------------------------------------------*/
1216 XDisplayVolumes(afs_uint32 a_servID, afs_int32 a_partID, volintXInfo *a_xInfoP,
1217 afs_int32 a_count, afs_int32 a_int32, afs_int32 a_fast,
1219 { /*XDisplayVolumes */
1221 int totalOK; /*Total OK volumes */
1222 int totalNotOK; /*Total screwed volumes */
1223 int totalBusy; /*Total busy volumes */
1224 int i; /*Loop variable */
1225 afs_uint32 volid = 0; /*Current volume ID */
1228 * Initialize counters and (global!!) queues.
1237 * Display each volume in the list.
1239 for (i = 0; i < a_count; i++) {
1240 XDisplayFormat(a_xInfoP, a_servID, a_partID, &totalOK, &totalNotOK,
1241 &totalBusy, a_fast, a_int32, 0);
1246 * If any volumes were found to be busy or screwed, display them.
1249 while (busyHead.count) {
1250 qGet(&busyHead, &volid);
1251 fprintf(STDOUT, "**** Volume %lu is busy ****\n",
1252 (unsigned long)volid);
1256 while (notokHead.count) {
1257 qGet(¬okHead, &volid);
1258 fprintf(STDOUT, "**** Could not attach volume %lu ****\n",
1259 (unsigned long)volid);
1264 fprintf(STDOUT, "\n");
1267 "Total volumes: %d on-line, %d off-line, %d busyd\n\n",
1268 totalOK, totalNotOK, totalBusy);
1272 } /*XDisplayVolumes */
1274 /*------------------------------------------------------------------------
1275 * PRIVATE XDisplayVolumes2
1278 * Display extended formated volume information.
1281 * a_servID : Pointer to the Rx call we're performing.
1282 * a_partID : Partition for which we want the extended list.
1283 * a_xInfoP : Ptr to extended volume info.
1284 * a_count : Number of volume records contained above.
1285 * a_int32 : Int32 listing generated?
1286 * a_fast : Fast listing generated?
1287 * a_quiet : Quiet listing generated?
1293 * Nothing interesting.
1297 *------------------------------------------------------------------------*/
1300 XDisplayVolumes2(afs_uint32 a_servID, afs_int32 a_partID, volintXInfo *a_xInfoP,
1301 afs_int32 a_count, afs_int32 a_int32, afs_int32 a_fast,
1303 { /*XDisplayVolumes */
1305 int totalOK; /*Total OK volumes */
1306 int totalNotOK; /*Total screwed volumes */
1307 int totalBusy; /*Total busy volumes */
1308 int i; /*Loop variable */
1309 afs_uint32 volid = 0; /*Current volume ID */
1312 * Initialize counters and (global!!) queues.
1321 * Display each volume in the list.
1323 for (i = 0; i < a_count; i++) {
1324 fprintf(STDOUT, "BEGIN_OF_ENTRY\n");
1325 XDisplayFormat2(a_xInfoP, a_servID, a_partID, &totalOK, &totalNotOK,
1326 &totalBusy, a_fast, a_int32, 0);
1327 fprintf(STDOUT, "END_OF_ENTRY\n");
1332 * If any volumes were found to be busy or screwed, display them.
1335 while (busyHead.count) {
1336 qGet(&busyHead, &volid);
1337 fprintf(STDOUT, "BUSY_VOL\t%lu\n",
1338 (unsigned long)volid);
1342 while (notokHead.count) {
1343 qGet(¬okHead, &volid);
1344 fprintf(STDOUT, "COULD_NOT_ATTACH\t%lu\n",
1345 (unsigned long)volid);
1350 fprintf(STDOUT, "\n");
1353 "VOLUMES_ONLINE\t%d\nVOLUMES_OFFLINE\t%d\nVOLUMES_BUSY\t%d\n",
1354 totalOK, totalNotOK, totalBusy);
1358 } /*XDisplayVolumes2 */
1361 /* set <server> and <part> to the correct values depending on
1362 * <voltype> and <entry> */
1364 GetServerAndPart(struct nvldbentry *entry, int voltype, afs_uint32 *server,
1365 afs_int32 *part, int *previdx)
1367 int i, istart, vtype;
1372 /* Doesn't check for non-existance of backup volume */
1373 if ((voltype == RWVOL) || (voltype == BACKVOL)) {
1375 istart = 0; /* seach the entire entry */
1378 /* Seach from beginning of entry or pick up where we left off */
1379 istart = ((*previdx < 0) ? 0 : *previdx + 1);
1382 for (i = istart; i < entry->nServers; i++) {
1383 if (entry->serverFlags[i] & vtype) {
1384 *server = entry->serverNumber[i];
1385 *part = entry->serverPartition[i];
1391 /* Didn't find any, return -1 */
1397 PrintLocked(afs_int32 aflags)
1399 afs_int32 flags = aflags & VLOP_ALLOPERS;
1402 fprintf(STDOUT, " Volume is currently LOCKED \n");
1404 if (flags & VLOP_MOVE) {
1405 fprintf(STDOUT, " Volume is locked for a move operation\n");
1407 if (flags & VLOP_RELEASE) {
1408 fprintf(STDOUT, " Volume is locked for a release operation\n");
1410 if (flags & VLOP_BACKUP) {
1411 fprintf(STDOUT, " Volume is locked for a backup operation\n");
1413 if (flags & VLOP_DELETE) {
1414 fprintf(STDOUT, " Volume is locked for a delete/misc operation\n");
1416 if (flags & VLOP_DUMP) {
1417 fprintf(STDOUT, " Volume is locked for a dump/restore operation\n");
1423 PostVolumeStats(struct nvldbentry *entry)
1425 SubEnumerateEntry(entry);
1426 /* Check for VLOP_ALLOPERS */
1427 PrintLocked(entry->flags);
1431 /*------------------------------------------------------------------------
1432 * PRIVATE XVolumeStats
1435 * Display extended volume information.
1438 * a_xInfoP : Ptr to extended volume info.
1439 * a_entryP : Ptr to the volume's VLDB entry.
1440 * a_srvID : Server ID.
1441 * a_partID : Partition ID.
1442 * a_volType : Type of volume to print.
1448 * Nothing interesting.
1452 *------------------------------------------------------------------------*/
1455 XVolumeStats(volintXInfo *a_xInfoP, struct nvldbentry *a_entryP,
1456 afs_int32 a_srvID, afs_int32 a_partID, int a_volType)
1459 int totalOK, totalNotOK, totalBusy; /*Dummies - we don't really count here */
1461 XDisplayFormat(a_xInfoP, /*Ptr to extended volume info */
1462 a_srvID, /*Server ID to print */
1463 a_partID, /*Partition ID to print */
1464 &totalOK, /*Ptr to total-OK counter */
1465 &totalNotOK, /*Ptr to total-screwed counter */
1466 &totalBusy, /*Ptr to total-busy counter */
1467 0, /*Don't do a fast listing */
1468 1, /*Do a long listing */
1469 1); /*Show volume problems */
1475 VolumeStats_int(volintInfo *pntr, struct nvldbentry *entry, afs_uint32 server,
1476 afs_int32 part, int voltype)
1482 DisplayFormat(pntr, server, part, &totalOK, &totalNotOK, &totalBusy, 0, 1,
1487 /* command to forcibly remove a volume */
1489 NukeVolume(struct cmd_syndesc *as)
1498 server = GetServer(tp = as->parms[0].items->data);
1500 fprintf(STDERR, "vos: server '%s' not found in host table\n", tp);
1504 partID = volutil_GetPartitionID(tp = as->parms[1].items->data);
1506 fprintf(STDERR, "vos: could not parse '%s' as a partition name", tp);
1510 volID = vsu_GetVolumeID(tp = as->parms[2].items->data, cstruct, &err);
1513 PrintError("", err);
1516 "vos: could not parse '%s' as a numeric volume ID", tp);
1521 "vos: forcibly removing all traces of volume %d, please wait...",
1524 code = UV_NukeVolume(server, partID, volID);
1526 fprintf(STDOUT, "done.\n");
1528 fprintf(STDOUT, "failed with code %d.\n", code);
1533 /*------------------------------------------------------------------------
1534 * PRIVATE ExamineVolume
1537 * Routine used to examine a single volume, contacting the VLDB as
1538 * well as the Volume Server.
1541 * as : Ptr to parsed command line arguments.
1544 * 0 for a successful operation,
1545 * Otherwise, one of the ubik or VolServer error values.
1548 * Nothing interesting.
1552 *------------------------------------------------------------------------
1555 ExamineVolume(struct cmd_syndesc *as, void *arock)
1557 struct nvldbentry entry;
1558 afs_int32 vcode = 0;
1559 volintInfo *pntr = (volintInfo *) 0;
1560 volintXInfo *xInfoP = (volintXInfo *) 0;
1562 afs_int32 code, err, error = 0;
1563 int voltype, foundserv = 0, foundentry = 0;
1567 int wantExtendedInfo; /*Do we want extended vol info? */
1568 int isSubEnum=0; /* Keep track whether sub enumerate called. */
1569 wantExtendedInfo = (as->parms[1].items ? 1 : 0); /* -extended */
1571 volid = vsu_GetVolumeID(as->parms[0].items->data, cstruct, &err); /* -id */
1574 PrintError("", err);
1576 fprintf(STDERR, "Unknown volume ID or name '%s'\n",
1577 as->parms[0].items->data);
1582 fprintf(STDOUT, "Fetching VLDB entry for %lu .. ",
1583 (unsigned long)volid);
1586 vcode = VLDB_GetEntryByID(volid, -1, &entry);
1589 "Could not fetch the entry for volume number %lu from VLDB \n",
1590 (unsigned long)volid);
1594 fprintf(STDOUT, "done\n");
1595 MapHostToNetwork(&entry);
1597 if (entry.volumeId[RWVOL] == volid)
1599 else if (entry.volumeId[BACKVOL] == volid)
1601 else /* (entry.volumeId[ROVOL] == volid) */
1604 do { /* do {...} while (voltype == ROVOL) */
1605 /* Get the entry for the volume. If its a RW vol, get the RW entry.
1606 * It its a BK vol, get the RW entry (even if VLDB may say the BK doen't exist).
1607 * If its a RO vol, get the next RO entry.
1609 GetServerAndPart(&entry, ((voltype == ROVOL) ? ROVOL : RWVOL),
1610 &aserver, &apart, &previdx);
1611 if (previdx == -1) { /* searched all entries */
1613 fprintf(STDERR, "Volume %s does not exist in VLDB\n\n",
1614 as->parms[0].items->data);
1621 /* Get information about the volume from the server */
1623 fprintf(STDOUT, "Getting volume listing from the server %s .. ",
1624 hostutil_GetNameByINet(aserver));
1627 if (wantExtendedInfo)
1628 code = UV_XListOneVolume(aserver, apart, volid, &xInfoP);
1630 code = UV_ListOneVolume(aserver, apart, volid, &pntr);
1632 fprintf(STDOUT, "done\n");
1636 if (code == ENODEV) {
1637 if ((voltype == BACKVOL) && !(entry.flags & BACK_EXISTS)) {
1638 /* The VLDB says there is no backup volume and its not on disk */
1639 fprintf(STDERR, "Volume %s does not exist\n",
1640 as->parms[0].items->data);
1644 "Volume does not exist on server %s as indicated by the VLDB\n",
1645 hostutil_GetNameByINet(aserver));
1648 PrintDiagnostics("examine", code);
1650 fprintf(STDOUT, "\n");
1653 if (wantExtendedInfo)
1654 XVolumeStats(xInfoP, &entry, aserver, apart, voltype);
1655 else if (as->parms[2].items) {
1656 DisplayFormat2(aserver, apart, pntr);
1657 EnumerateEntry(&entry);
1660 VolumeStats_int(pntr, &entry, aserver, apart, voltype);
1662 if ((voltype == BACKVOL) && !(entry.flags & BACK_EXISTS)) {
1663 /* The VLDB says there is no backup volume yet we found one on disk */
1664 fprintf(STDERR, "Volume %s does not exist in VLDB\n",
1665 as->parms[0].items->data);
1674 } while (voltype == ROVOL);
1677 fprintf(STDERR, "Dump only information from VLDB\n\n");
1678 fprintf(STDOUT, "%s \n", entry.name); /* PostVolumeStats doesn't print name */
1682 PostVolumeStats(&entry);
1687 /*------------------------------------------------------------------------
1691 * Routine used to change the status of a single volume.
1694 * as : Ptr to parsed command line arguments.
1697 * 0 for a successful operation,
1698 * Otherwise, one of the ubik or VolServer error values.
1701 * Nothing interesting.
1705 *------------------------------------------------------------------------
1708 SetFields(struct cmd_syndesc *as, void *arock)
1710 struct nvldbentry entry;
1713 afs_int32 code, err;
1718 volid = vsu_GetVolumeID(as->parms[0].items->data, cstruct, &err); /* -id */
1721 PrintError("", err);
1723 fprintf(STDERR, "Unknown volume ID or name '%s'\n",
1724 as->parms[0].items->data);
1728 code = VLDB_GetEntryByID(volid, RWVOL, &entry);
1731 "Could not fetch the entry for volume number %lu from VLDB \n",
1732 (unsigned long)volid);
1735 MapHostToNetwork(&entry);
1737 GetServerAndPart(&entry, RWVOL, &aserver, &apart, &previdx);
1738 if (previdx == -1) {
1739 fprintf(STDERR, "Volume %s does not exist in VLDB\n\n",
1740 as->parms[0].items->data);
1744 init_volintInfo(&info);
1748 if (as->parms[1].items) {
1750 code = util_GetHumanInt32(as->parms[1].items->data, &info.maxquota);
1752 fprintf(STDERR, "invalid quota value\n");
1756 if (as->parms[2].items) {
1760 if (as->parms[3].items) {
1761 /* -clearVolUpCounter */
1764 code = UV_SetVolumeInfo(aserver, apart, volid, &info);
1767 "Could not update volume info fields for volume number %lu\n",
1768 (unsigned long)volid);
1772 /*------------------------------------------------------------------------
1776 * Brings a volume online.
1779 * as : Ptr to parsed command line arguments.
1782 * 0 for a successful operation,
1785 * Nothing interesting.
1789 *------------------------------------------------------------------------
1792 volOnline(struct cmd_syndesc *as, void *arock)
1795 afs_int32 partition;
1797 afs_int32 code, err = 0;
1799 server = GetServer(as->parms[0].items->data);
1801 fprintf(STDERR, "vos: server '%s' not found in host table\n",
1802 as->parms[0].items->data);
1806 partition = volutil_GetPartitionID(as->parms[1].items->data);
1807 if (partition < 0) {
1808 fprintf(STDERR, "vos: could not interpret partition name '%s'\n",
1809 as->parms[1].items->data);
1813 volid = vsu_GetVolumeID(as->parms[2].items->data, cstruct, &err); /* -id */
1816 PrintError("", err);
1818 fprintf(STDERR, "Unknown volume ID or name '%s'\n",
1819 as->parms[0].items->data);
1823 code = UV_SetVolume(server, partition, volid, ITOffline, 0 /*online */ ,
1826 fprintf(STDERR, "Failed to set volume. Code = %d\n", code);
1833 /*------------------------------------------------------------------------
1834 * PRIVATE volOffline
1837 * Brings a volume offline.
1840 * as : Ptr to parsed command line arguments.
1843 * 0 for a successful operation,
1846 * Nothing interesting.
1850 *------------------------------------------------------------------------
1853 volOffline(struct cmd_syndesc *as, void *arock)
1856 afs_int32 partition;
1858 afs_int32 code, err = 0;
1859 afs_int32 transflag, sleeptime, transdone;
1861 server = GetServer(as->parms[0].items->data);
1863 fprintf(STDERR, "vos: server '%s' not found in host table\n",
1864 as->parms[0].items->data);
1868 partition = volutil_GetPartitionID(as->parms[1].items->data);
1869 if (partition < 0) {
1870 fprintf(STDERR, "vos: could not interpret partition name '%s'\n",
1871 as->parms[1].items->data);
1875 volid = vsu_GetVolumeID(as->parms[2].items->data, cstruct, &err); /* -id */
1878 PrintError("", err);
1880 fprintf(STDERR, "Unknown volume ID or name '%s'\n",
1881 as->parms[0].items->data);
1885 transflag = (as->parms[4].items ? ITBusy : ITOffline);
1886 sleeptime = (as->parms[3].items ? atol(as->parms[3].items->data) : 0);
1887 transdone = ((sleeptime || as->parms[4].items) ? 0 /*online */ : VTOutOfService);
1888 if (as->parms[4].items && !as->parms[3].items) {
1889 fprintf(STDERR, "-sleep option must be used with -busy flag\n");
1894 UV_SetVolume(server, partition, volid, transflag, transdone,
1897 fprintf(STDERR, "Failed to set volume. Code = %d\n", code);
1905 CreateVolume(struct cmd_syndesc *as, void *arock)
1909 afs_uint32 volid = 0, rovolid = 0, bkvolid = 0;
1910 afs_uint32 *arovolid;
1912 struct nvldbentry entry;
1917 arovolid = &rovolid;
1920 tserver = GetServer(as->parms[0].items->data);
1922 fprintf(STDERR, "vos: host '%s' not found in host table\n",
1923 as->parms[0].items->data);
1926 pnum = volutil_GetPartitionID(as->parms[1].items->data);
1928 fprintf(STDERR, "vos: could not interpret partition name '%s'\n",
1929 as->parms[1].items->data);
1932 if (!IsPartValid(pnum, tserver, &code)) { /*check for validity of the partition */
1934 PrintError("", code);
1937 "vos : partition %s does not exist on the server\n",
1938 as->parms[1].items->data);
1941 if (!ISNAMEVALID(as->parms[2].items->data)) {
1943 "vos: the name of the root volume %s exceeds the size limit of %d\n",
1944 as->parms[2].items->data, VOLSER_OLDMAXVOLNAME - 10);
1947 if (!VolNameOK(as->parms[2].items->data)) {
1949 "Illegal volume name %s, should not end in .readonly or .backup\n",
1950 as->parms[2].items->data);
1953 if (IsNumeric(as->parms[2].items->data)) {
1954 fprintf(STDERR, "Illegal volume name %s, should not be a number\n",
1955 as->parms[2].items->data);
1958 vcode = VLDB_GetEntryByName(as->parms[2].items->data, &entry);
1960 fprintf(STDERR, "Volume %s already exists\n",
1961 as->parms[2].items->data);
1962 PrintDiagnostics("create", code);
1966 if (as->parms[3].items) {
1967 code = util_GetHumanInt32(as->parms[3].items->data, "a);
1969 fprintf(STDERR, "vos: bad integer specified for quota.\n");
1974 if (as->parms[4].items) {
1975 if (!IsNumeric(as->parms[4].items->data)) {
1976 fprintf(STDERR, "vos: Given volume ID %s should be numeric.\n",
1977 as->parms[4].items->data);
1981 code = util_GetUInt32(as->parms[4].items->data, &volid);
1983 fprintf(STDERR, "vos: bad integer specified for volume ID.\n");
1988 if (as->parms[5].items) {
1989 if (!IsNumeric(as->parms[5].items->data)) {
1990 fprintf(STDERR, "vos: Given RO volume ID %s should be numeric.\n",
1991 as->parms[5].items->data);
1995 code = util_GetUInt32(as->parms[5].items->data, &rovolid);
1997 fprintf(STDERR, "vos: bad integer specified for volume ID.\n");
2007 UV_CreateVolume3(tserver, pnum, as->parms[2].items->data, quota, 0,
2008 0, 0, 0, &volid, arovolid, &bkvolid);
2010 PrintDiagnostics("create", code);
2013 MapPartIdIntoName(pnum, part);
2014 fprintf(STDOUT, "Volume %lu created on partition %s of %s\n",
2015 (unsigned long)volid, part, as->parms[0].items->data);
2022 DeleteAll(struct nvldbentry *entry)
2025 afs_int32 error, code, curserver, curpart;
2028 MapHostToNetwork(entry);
2030 for (i = 0; i < entry->nServers; i++) {
2031 curserver = entry->serverNumber[i];
2032 curpart = entry->serverPartition[i];
2033 if (entry->serverFlags[i] & ITSROVOL) {
2034 volid = entry->volumeId[ROVOL];
2036 volid = entry->volumeId[RWVOL];
2038 code = UV_DeleteVolume(curserver, curpart, volid);
2047 DeleteVolume(struct cmd_syndesc *as, void *arock)
2049 afs_int32 err, code = 0;
2050 afs_uint32 server = 0;
2051 afs_int32 partition = -1;
2056 if (as->parms[0].items) {
2057 server = GetServer(as->parms[0].items->data);
2059 fprintf(STDERR, "vos: server '%s' not found in host table\n",
2060 as->parms[0].items->data);
2065 if (as->parms[1].items) {
2066 partition = volutil_GetPartitionID(as->parms[1].items->data);
2067 if (partition < 0) {
2068 fprintf(STDERR, "vos: could not interpret partition name '%s'\n",
2069 as->parms[1].items->data);
2073 /* Check for validity of the partition */
2074 if (!IsPartValid(partition, server, &code)) {
2076 PrintError("", code);
2079 "vos : partition %s does not exist on the server\n",
2080 as->parms[1].items->data);
2086 volid = vsu_GetVolumeID(as->parms[2].items->data, cstruct, &err);
2088 fprintf(STDERR, "Can't find volume name '%s' in VLDB\n",
2089 as->parms[2].items->data);
2091 PrintError("", err);
2095 /* If the server or partition option are not complete, try to fill
2096 * them in from the VLDB entry.
2098 if ((partition == -1) || !server) {
2099 struct nvldbentry entry;
2101 code = VLDB_GetEntryByID(volid, -1, &entry);
2104 "Could not fetch the entry for volume %lu from VLDB\n",
2105 (unsigned long)volid);
2106 PrintError("", code);
2110 if (((volid == entry.volumeId[RWVOL]) && (entry.flags & RW_EXISTS))
2111 || ((volid == entry.volumeId[BACKVOL])
2112 && (entry.flags & BACK_EXISTS))) {
2113 idx = Lp_GetRwIndex(&entry);
2114 if ((idx == -1) || (server && (server != entry.serverNumber[idx]))
2115 || ((partition != -1)
2116 && (partition != entry.serverPartition[idx]))) {
2117 fprintf(STDERR, "VLDB: Volume '%s' no match\n",
2118 as->parms[2].items->data);
2121 } else if ((volid == entry.volumeId[ROVOL])
2122 && (entry.flags & RO_EXISTS)) {
2123 for (idx = -1, j = 0; j < entry.nServers; j++) {
2124 if (entry.serverFlags[j] != ITSROVOL)
2127 if (((server == 0) || (server == entry.serverNumber[j]))
2128 && ((partition == -1)
2129 || (partition == entry.serverPartition[j]))) {
2132 "VLDB: Volume '%s' matches more than one RO\n",
2133 as->parms[2].items->data);
2140 fprintf(STDERR, "VLDB: Volume '%s' no match\n",
2141 as->parms[2].items->data);
2145 fprintf(STDERR, "VLDB: Volume '%s' no match\n",
2146 as->parms[2].items->data);
2150 server = htonl(entry.serverNumber[idx]);
2151 partition = entry.serverPartition[idx];
2155 code = UV_DeleteVolume(server, partition, volid);
2157 PrintDiagnostics("remove", code);
2161 MapPartIdIntoName(partition, pname);
2162 fprintf(STDOUT, "Volume %lu on partition %s server %s deleted\n",
2163 (unsigned long)volid, pname, hostutil_GetNameByINet(server));
2167 #define TESTM 0 /* set for move space tests, clear for production */
2169 MoveVolume(struct cmd_syndesc *as, void *arock)
2173 afs_uint32 fromserver, toserver;
2174 afs_int32 frompart, topart;
2175 afs_int32 flags, code, err;
2176 char fromPartName[10], toPartName[10];
2178 struct diskPartition64 partition; /* for space check */
2181 volid = vsu_GetVolumeID(as->parms[0].items->data, cstruct, &err);
2184 PrintError("", err);
2186 fprintf(STDERR, "vos: can't find volume ID or name '%s'\n",
2187 as->parms[0].items->data);
2190 fromserver = GetServer(as->parms[1].items->data);
2191 if (fromserver == 0) {
2192 fprintf(STDERR, "vos: server '%s' not found in host table\n",
2193 as->parms[1].items->data);
2196 toserver = GetServer(as->parms[3].items->data);
2197 if (toserver == 0) {
2198 fprintf(STDERR, "vos: server '%s' not found in host table\n",
2199 as->parms[3].items->data);
2202 frompart = volutil_GetPartitionID(as->parms[2].items->data);
2204 fprintf(STDERR, "vos: could not interpret partition name '%s'\n",
2205 as->parms[2].items->data);
2208 if (!IsPartValid(frompart, fromserver, &code)) { /*check for validity of the partition */
2210 PrintError("", code);
2213 "vos : partition %s does not exist on the server\n",
2214 as->parms[2].items->data);
2217 topart = volutil_GetPartitionID(as->parms[4].items->data);
2219 fprintf(STDERR, "vos: could not interpret partition name '%s'\n",
2220 as->parms[4].items->data);
2223 if (!IsPartValid(topart, toserver, &code)) { /*check for validity of the partition */
2225 PrintError("", code);
2228 "vos : partition %s does not exist on the server\n",
2229 as->parms[4].items->data);
2234 if (as->parms[5].items) flags |= RV_NOCLONE;
2237 * check source partition for space to clone volume
2240 MapPartIdIntoName(topart, toPartName);
2241 MapPartIdIntoName(frompart, fromPartName);
2244 * check target partition for space to move volume
2247 code = UV_PartitionInfo64(toserver, toPartName, &partition);
2249 fprintf(STDERR, "vos: cannot access partition %s\n", toPartName);
2253 fprintf(STDOUT, "target partition %s free space %" AFS_INT64_FMT "\n", toPartName,
2256 p = (volintInfo *) 0;
2257 code = UV_ListOneVolume(fromserver, frompart, volid, &p);
2259 fprintf(STDERR, "vos:cannot access volume %lu\n",
2260 (unsigned long)volid);
2264 fprintf(STDOUT, "volume %lu size %d\n", (unsigned long)volid,
2266 if (partition.free <= p->size) {
2268 "vos: no space on target partition %s to move volume %lu\n",
2269 toPartName, (unsigned long)volid);
2276 fprintf(STDOUT, "size test - don't do move\n");
2280 /* successful move still not guaranteed but shoot for it */
2283 UV_MoveVolume2(volid, fromserver, frompart, toserver, topart, flags);
2285 PrintDiagnostics("move", code);
2288 MapPartIdIntoName(topart, toPartName);
2289 MapPartIdIntoName(frompart, fromPartName);
2290 fprintf(STDOUT, "Volume %lu moved from %s %s to %s %s \n",
2291 (unsigned long)volid, as->parms[1].items->data, fromPartName,
2292 as->parms[3].items->data, toPartName);
2298 CopyVolume(struct cmd_syndesc *as, void *arock)
2301 afs_uint32 fromserver, toserver;
2302 afs_int32 frompart, topart, code, err, flags;
2303 char fromPartName[10], toPartName[10], *tovolume;
2304 struct nvldbentry entry;
2305 struct diskPartition64 partition; /* for space check */
2308 volid = vsu_GetVolumeID(as->parms[0].items->data, cstruct, &err);
2311 PrintError("", err);
2313 fprintf(STDERR, "vos: can't find volume ID or name '%s'\n",
2314 as->parms[0].items->data);
2317 fromserver = GetServer(as->parms[1].items->data);
2318 if (fromserver == 0) {
2319 fprintf(STDERR, "vos: server '%s' not found in host table\n",
2320 as->parms[1].items->data);
2324 toserver = GetServer(as->parms[4].items->data);
2325 if (toserver == 0) {
2326 fprintf(STDERR, "vos: server '%s' not found in host table\n",
2327 as->parms[4].items->data);
2331 tovolume = as->parms[3].items->data;
2332 if (!ISNAMEVALID(tovolume)) {
2334 "vos: the name of the root volume %s exceeds the size limit of %d\n",
2335 tovolume, VOLSER_OLDMAXVOLNAME - 10);
2338 if (!VolNameOK(tovolume)) {
2340 "Illegal volume name %s, should not end in .readonly or .backup\n",
2344 if (IsNumeric(tovolume)) {
2345 fprintf(STDERR, "Illegal volume name %s, should not be a number\n",
2349 code = VLDB_GetEntryByName(tovolume, &entry);
2351 fprintf(STDERR, "Volume %s already exists\n", tovolume);
2352 PrintDiagnostics("copy", code);
2356 frompart = volutil_GetPartitionID(as->parms[2].items->data);
2358 fprintf(STDERR, "vos: could not interpret partition name '%s'\n",
2359 as->parms[2].items->data);
2362 if (!IsPartValid(frompart, fromserver, &code)) { /*check for validity of the partition */
2364 PrintError("", code);
2367 "vos : partition %s does not exist on the server\n",
2368 as->parms[2].items->data);
2372 topart = volutil_GetPartitionID(as->parms[5].items->data);
2374 fprintf(STDERR, "vos: could not interpret partition name '%s'\n",
2375 as->parms[5].items->data);
2378 if (!IsPartValid(topart, toserver, &code)) { /*check for validity of the partition */
2380 PrintError("", code);
2383 "vos : partition %s does not exist on the server\n",
2384 as->parms[5].items->data);
2389 if (as->parms[6].items) flags |= RV_OFFLINE;
2390 if (as->parms[7].items) flags |= RV_RDONLY;
2391 if (as->parms[8].items) flags |= RV_NOCLONE;
2393 MapPartIdIntoName(topart, toPartName);
2394 MapPartIdIntoName(frompart, fromPartName);
2397 * check target partition for space to move volume
2400 code = UV_PartitionInfo64(toserver, toPartName, &partition);
2402 fprintf(STDERR, "vos: cannot access partition %s\n", toPartName);
2406 fprintf(STDOUT, "target partition %s free space %" AFS_INT64_FMT "\n", toPartName,
2409 p = (volintInfo *) 0;
2410 code = UV_ListOneVolume(fromserver, frompart, volid, &p);
2412 fprintf(STDERR, "vos:cannot access volume %lu\n",
2413 (unsigned long)volid);
2417 if (partition.free <= p->size) {
2419 "vos: no space on target partition %s to copy volume %lu\n",
2420 toPartName, (unsigned long)volid);
2426 /* successful copy still not guaranteed but shoot for it */
2429 UV_CopyVolume2(volid, fromserver, frompart, tovolume, toserver,
2432 PrintDiagnostics("copy", code);
2435 MapPartIdIntoName(topart, toPartName);
2436 MapPartIdIntoName(frompart, fromPartName);
2437 fprintf(STDOUT, "Volume %lu copied from %s %s to %s on %s %s \n",
2438 (unsigned long)volid, as->parms[1].items->data, fromPartName,
2439 tovolume, as->parms[4].items->data, toPartName);
2446 ShadowVolume(struct cmd_syndesc *as, void *arock)
2448 afs_uint32 volid, tovolid;
2449 afs_uint32 fromserver, toserver;
2450 afs_int32 frompart, topart;
2451 afs_int32 code, err, flags;
2452 char fromPartName[10], toPartName[10], toVolName[32], *tovolume;
2453 struct diskPartition64 partition; /* for space check */
2456 p = (volintInfo *) 0;
2457 q = (volintInfo *) 0;
2459 volid = vsu_GetVolumeID(as->parms[0].items->data, cstruct, &err);
2462 PrintError("", err);
2464 fprintf(STDERR, "vos: can't find volume ID or name '%s'\n",
2465 as->parms[0].items->data);
2468 fromserver = GetServer(as->parms[1].items->data);
2469 if (fromserver == 0) {
2470 fprintf(STDERR, "vos: server '%s' not found in host table\n",
2471 as->parms[1].items->data);
2475 toserver = GetServer(as->parms[3].items->data);
2476 if (toserver == 0) {
2477 fprintf(STDERR, "vos: server '%s' not found in host table\n",
2478 as->parms[3].items->data);
2482 frompart = volutil_GetPartitionID(as->parms[2].items->data);
2484 fprintf(STDERR, "vos: could not interpret partition name '%s'\n",
2485 as->parms[2].items->data);
2488 if (!IsPartValid(frompart, fromserver, &code)) { /*check for validity of the partition */
2490 PrintError("", code);
2493 "vos : partition %s does not exist on the server\n",
2494 as->parms[2].items->data);
2498 topart = volutil_GetPartitionID(as->parms[4].items->data);
2500 fprintf(STDERR, "vos: could not interpret partition name '%s'\n",
2501 as->parms[4].items->data);
2504 if (!IsPartValid(topart, toserver, &code)) { /*check for validity of the partition */
2506 PrintError("", code);
2509 "vos : partition %s does not exist on the server\n",
2510 as->parms[4].items->data);
2514 if (as->parms[5].items) {
2515 tovolume = as->parms[5].items->data;
2516 if (!ISNAMEVALID(tovolume)) {
2518 "vos: the name of the root volume %s exceeds the size limit of %d\n",
2519 tovolume, VOLSER_OLDMAXVOLNAME - 10);
2522 if (!VolNameOK(tovolume)) {
2524 "Illegal volume name %s, should not end in .readonly or .backup\n",
2528 if (IsNumeric(tovolume)) {
2530 "Illegal volume name %s, should not be a number\n",
2535 /* use actual name of source volume */
2536 code = UV_ListOneVolume(fromserver, frompart, volid, &p);
2538 fprintf(STDERR, "vos:cannot access volume %lu\n",
2539 (unsigned long)volid);
2542 strcpy(toVolName, p->name);
2543 tovolume = toVolName;
2544 /* save p for size checks later */
2547 if (as->parms[6].items) {
2548 tovolid = vsu_GetVolumeID(as->parms[6].items->data, cstruct, &err);
2551 PrintError("", err);
2553 fprintf(STDERR, "vos: can't find volume ID or name '%s'\n",
2554 as->parms[6].items->data);
2560 tovolid = vsu_GetVolumeID(tovolume, cstruct, &err);
2563 PrintError("", err);
2565 fprintf(STDERR, "vos: can't find volume ID or name '%s'\n",
2574 if (as->parms[7].items) flags |= RV_OFFLINE;
2575 if (as->parms[8].items) flags |= RV_RDONLY;
2576 if (as->parms[9].items) flags |= RV_NOCLONE;
2577 if (as->parms[10].items) flags |= RV_CPINCR;
2579 MapPartIdIntoName(topart, toPartName);
2580 MapPartIdIntoName(frompart, fromPartName);
2583 * check target partition for space to move volume
2586 code = UV_PartitionInfo64(toserver, toPartName, &partition);
2588 fprintf(STDERR, "vos: cannot access partition %s\n", toPartName);
2592 fprintf(STDOUT, "target partition %s free space %" AFS_INT64_FMT "\n", toPartName,
2595 /* Don't do this again if we did it above */
2597 code = UV_ListOneVolume(fromserver, frompart, volid, &p);
2599 fprintf(STDERR, "vos:cannot access volume %lu\n",
2600 (unsigned long)volid);
2605 /* OK if this fails */
2606 code = UV_ListOneVolume(toserver, topart, tovolid, &q);
2608 /* Treat existing volume size as "free" */
2610 p->size = (q->size < p->size) ? p->size - q->size : 0;
2612 if (partition.free <= p->size) {
2614 "vos: no space on target partition %s to copy volume %lu\n",
2615 toPartName, (unsigned long)volid);
2623 /* successful copy still not guaranteed but shoot for it */
2626 UV_CopyVolume2(volid, fromserver, frompart, tovolume, toserver,
2627 topart, tovolid, flags);
2629 PrintDiagnostics("shadow", code);
2632 MapPartIdIntoName(topart, toPartName);
2633 MapPartIdIntoName(frompart, fromPartName);
2634 fprintf(STDOUT, "Volume %lu shadowed from %s %s to %s %s \n",
2635 (unsigned long)volid, as->parms[1].items->data, fromPartName,
2636 as->parms[3].items->data, toPartName);
2643 CloneVolume(struct cmd_syndesc *as, void *arock)
2645 afs_uint32 volid, cloneid;
2647 afs_int32 part, voltype;
2648 char partName[10], *volname;
2649 afs_int32 code, err, flags;
2650 struct nvldbentry entry;
2652 volid = vsu_GetVolumeID(as->parms[0].items->data, cstruct, &err);
2655 PrintError("", err);
2657 fprintf(STDERR, "vos: can't find volume ID or name '%s'\n",
2658 as->parms[0].items->data);
2662 if (as->parms[1].items || as->parms[2].items) {
2663 if (!as->parms[1].items || !as->parms[2].items) {
2665 "Must specify both -server and -partition options\n");
2668 server = GetServer(as->parms[1].items->data);
2670 fprintf(STDERR, "vos: server '%s' not found in host table\n",
2671 as->parms[1].items->data);
2674 part = volutil_GetPartitionID(as->parms[2].items->data);
2676 fprintf(STDERR, "vos: could not interpret partition name '%s'\n",
2677 as->parms[2].items->data);
2680 if (!IsPartValid(part, server, &code)) { /*check for validity of the partition */
2682 PrintError("", code);
2685 "vos : partition %s does not exist on the server\n",
2686 as->parms[2].items->data);
2690 code = GetVolumeInfo(volid, &server, &part, &voltype, &entry);
2696 if (as->parms[3].items) {
2697 volname = as->parms[3].items->data;
2698 if (strlen(volname) > VOLSER_OLDMAXVOLNAME - 1) {
2700 "vos: the name of the root volume %s exceeds the size limit of %d\n",
2701 volname, VOLSER_OLDMAXVOLNAME - 1);
2706 * In order that you be able to make clones of RO or BK, this
2707 * check must be omitted.
2709 if (!VolNameOK(volname)) {
2711 "Illegal volume name %s, should not end in .readonly or .backup\n",
2716 if (IsNumeric(volname)) {
2718 "Illegal volume name %s, should not be a number\n",
2725 if (as->parms[4].items) {
2726 cloneid = vsu_GetVolumeID(as->parms[4].items->data, cstruct, &err);
2729 PrintError("", err);
2731 fprintf(STDERR, "vos: can't find volume ID or name '%s'\n",
2732 as->parms[4].items->data);
2738 if (as->parms[5].items) flags |= RV_OFFLINE;
2739 if (as->parms[6].items && as->parms[7].items) {
2740 fprintf(STDERR, "vos: cannot specify that a volume be -readwrite and -readonly\n");
2743 if (as->parms[6].items) flags |= RV_RDONLY;
2744 if (as->parms[7].items) flags |= RV_RWONLY;
2748 UV_CloneVolume(server, part, volid, cloneid, volname, flags);
2751 PrintDiagnostics("clone", code);
2754 MapPartIdIntoName(part, partName);
2755 fprintf(STDOUT, "Created clone for volume %s\n",
2756 as->parms[0].items->data);
2763 BackupVolume(struct cmd_syndesc *as, void *arock)
2767 afs_int32 apart, vtype, code, err;
2768 struct nvldbentry entry;
2771 afs_uint32 buserver;
2772 afs_int32 bupart, butype;
2773 struct nvldbentry buentry;
2775 avolid = vsu_GetVolumeID(as->parms[0].items->data, cstruct, &err);
2778 PrintError("", err);
2780 fprintf(STDERR, "vos: can't find volume ID or name '%s'\n",
2781 as->parms[0].items->data);
2784 code = GetVolumeInfo(avolid, &aserver, &apart, &vtype, &entry);
2788 /* verify this is a readwrite volume */
2790 if (vtype != RWVOL) {
2791 fprintf(STDERR, "%s not RW volume\n", as->parms[0].items->data);
2795 /* is there a backup volume already? */
2797 if (entry.flags & BACK_EXISTS) {
2798 /* yep, where is it? */
2800 buvolid = entry.volumeId[BACKVOL];
2801 code = GetVolumeInfo(buvolid, &buserver, &bupart, &butype, &buentry);
2806 code = VLDB_IsSameAddrs(buserver, aserver, &err);
2809 "Failed to get info about server's %d address(es) from vlserver; aborting call!\n",
2815 "FATAL ERROR: backup volume %lu exists on server %lu\n",
2816 (unsigned long)buvolid, (unsigned long)buserver);
2821 /* nope, carry on */
2823 code = UV_BackupVolume(aserver, apart, avolid);
2826 PrintDiagnostics("backup", code);
2829 fprintf(STDOUT, "Created backup volume for %s \n",
2830 as->parms[0].items->data);
2835 ReleaseVolume(struct cmd_syndesc *as, void *arock)
2838 struct nvldbentry entry;
2841 afs_int32 apart, vtype, code, err;
2845 if (as->parms[1].items)
2847 if (as->parms[2].items)
2849 avolid = vsu_GetVolumeID(as->parms[0].items->data, cstruct, &err);
2852 PrintError("", err);
2854 fprintf(STDERR, "vos: can't find volume '%s'\n",
2855 as->parms[0].items->data);
2858 code = GetVolumeInfo(avolid, &aserver, &apart, &vtype, &entry);
2862 if (vtype != RWVOL) {
2863 fprintf(STDERR, "%s not a RW volume\n", as->parms[0].items->data);
2867 if (!ISNAMEVALID(entry.name)) {
2869 "Volume name %s is too long, rename before releasing\n",
2874 code = UV_ReleaseVolume(avolid, aserver, apart, force, stayUp);
2877 PrintDiagnostics("release", code);
2880 fprintf(STDOUT, "Released volume %s successfully\n",
2881 as->parms[0].items->data);
2886 DumpVolumeCmd(struct cmd_syndesc *as, void *arock)
2890 afs_int32 apart, voltype, fromdate = 0, code, err, i, flags;
2891 char filename[MAXPATHLEN];
2892 struct nvldbentry entry;
2894 rx_SetRxDeadTime(60 * 10);
2895 for (i = 0; i < MAXSERVERS; i++) {
2896 struct rx_connection *rxConn = ubik_GetRPCConn(cstruct, i);
2899 rx_SetConnDeadTime(rxConn, rx_connDeadTime);
2900 if (rx_ServiceOf(rxConn))
2901 rx_ServiceOf(rxConn)->connDeadTime = rx_connDeadTime;
2904 avolid = vsu_GetVolumeID(as->parms[0].items->data, cstruct, &err);
2907 PrintError("", err);
2909 fprintf(STDERR, "vos: can't find volume '%s'\n",
2910 as->parms[0].items->data);
2914 if (as->parms[3].items || as->parms[4].items) {
2915 if (!as->parms[3].items || !as->parms[4].items) {
2917 "Must specify both -server and -partition options\n");
2920 aserver = GetServer(as->parms[3].items->data);
2922 fprintf(STDERR, "Invalid server name\n");
2925 apart = volutil_GetPartitionID(as->parms[4].items->data);
2927 fprintf(STDERR, "Invalid partition name\n");
2931 code = GetVolumeInfo(avolid, &aserver, &apart, &voltype, &entry);
2936 if (as->parms[1].items && strcmp(as->parms[1].items->data, "0")) {
2937 code = ktime_DateToInt32(as->parms[1].items->data, &fromdate);
2939 fprintf(STDERR, "vos: failed to parse date '%s' (error=%d))\n",
2940 as->parms[1].items->data, code);
2944 if (as->parms[2].items) {
2945 strcpy(filename, as->parms[2].items->data);
2947 strcpy(filename, "");
2950 flags = as->parms[6].items ? VOLDUMPV2_OMITDIRS : 0;
2952 if (as->parms[5].items) {
2954 UV_DumpClonedVolume(avolid, aserver, apart, fromdate,
2955 DumpFunction, filename, flags);
2958 UV_DumpVolume(avolid, aserver, apart, fromdate, DumpFunction,
2961 if ((code == RXGEN_OPCODE) && (as->parms[6].items)) {
2962 flags &= ~VOLDUMPV2_OMITDIRS;
2966 PrintDiagnostics("dump", code);
2969 if (strcmp(filename, ""))
2970 fprintf(STDERR, "Dumped volume %s in file %s\n",
2971 as->parms[0].items->data, filename);
2973 fprintf(STDERR, "Dumped volume %s in stdout \n",
2974 as->parms[0].items->data);
2988 RestoreVolumeCmd(struct cmd_syndesc *as, void *arock)
2990 afs_uint32 avolid, aparentid;
2992 afs_int32 apart, code, vcode, err;
2993 afs_int32 aoverwrite = ASK;
2994 afs_int32 acreation = 0, alastupdate = 0;
2995 int restoreflags = 0;
2996 int readonly = 0, offline = 0, voltype = RWVOL;
2997 char afilename[MAXPATHLEN], avolname[VOLSER_MAXVOLNAME + 1], apartName[10];
2998 char volname[VOLSER_MAXVOLNAME + 1];
2999 struct nvldbentry entry;
3002 if (as->parms[4].items) {
3003 avolid = vsu_GetVolumeID(as->parms[4].items->data, cstruct, &err);
3006 PrintError("", err);
3008 fprintf(STDERR, "vos: can't find volume '%s'\n",
3009 as->parms[4].items->data);
3015 if (as->parms[5].items) {
3016 if ((strcmp(as->parms[5].items->data, "a") == 0)
3017 || (strcmp(as->parms[5].items->data, "abort") == 0)) {
3019 } else if ((strcmp(as->parms[5].items->data, "f") == 0)
3020 || (strcmp(as->parms[5].items->data, "full") == 0)) {
3022 } else if ((strcmp(as->parms[5].items->data, "i") == 0)
3023 || (strcmp(as->parms[5].items->data, "inc") == 0)
3024 || (strcmp(as->parms[5].items->data, "increment") == 0)
3025 || (strcmp(as->parms[5].items->data, "incremental") == 0)) {
3028 fprintf(STDERR, "vos: %s is not a valid argument to -overwrite\n",
3029 as->parms[5].items->data);
3033 if (as->parms[6].items)
3035 if (as->parms[7].items) {
3040 if (as->parms[8].items) {
3041 if ((strcmp(as->parms[8].items->data, "d") == 0)
3042 || (strcmp(as->parms[8].items->data, "dump") == 0)) {
3043 acreation = TS_DUMP;
3044 } else if ((strcmp(as->parms[8].items->data, "k") == 0)
3045 || (strcmp(as->parms[8].items->data, "keep") == 0)) {
3046 acreation = TS_KEEP;
3047 } else if ((strcmp(as->parms[8].items->data, "n") == 0)
3048 || (strcmp(as->parms[8].items->data, "new") == 0)) {
3051 fprintf(STDERR, "vos: %s is not a valid argument to -creation\n",
3052 as->parms[8].items->data);
3057 if (as->parms[9].items) {
3058 if ((strcmp(as->parms[9].items->data, "d") == 0)
3059 || (strcmp(as->parms[9].items->data, "dump") == 0)) {
3060 alastupdate = TS_DUMP;
3061 } else if ((strcmp(as->parms[9].items->data, "k") == 0)
3062 || (strcmp(as->parms[9].items->data, "keep") == 0)) {
3063 alastupdate = TS_KEEP;
3064 } else if ((strcmp(as->parms[9].items->data, "n") == 0)
3065 || (strcmp(as->parms[9].items->data, "new") == 0)) {
3066 alastupdate = TS_NEW;
3068 fprintf(STDERR, "vos: %s is not a valid argument to -lastupdate\n",
3069 as->parms[9].items->data);
3074 aserver = GetServer(as->parms[0].items->data);
3076 fprintf(STDERR, "vos: server '%s' not found in host table\n",
3077 as->parms[0].items->data);
3080 apart = volutil_GetPartitionID(as->parms[1].items->data);
3082 fprintf(STDERR, "vos: could not interpret partition name '%s'\n",
3083 as->parms[1].items->data);
3086 if (!IsPartValid(apart, aserver, &code)) { /*check for validity of the partition */
3088 PrintError("", code);
3091 "vos : partition %s does not exist on the server\n",
3092 as->parms[1].items->data);
3095 strcpy(avolname, as->parms[2].items->data);
3096 if (!ISNAMEVALID(avolname)) {
3098 "vos: the name of the volume %s exceeds the size limit\n",
3102 if (!VolNameOK(avolname)) {
3104 "Illegal volume name %s, should not end in .readonly or .backup\n",
3108 if (as->parms[3].items) {
3109 strcpy(afilename, as->parms[3].items->data);
3110 if (!FileExists(afilename)) {
3111 fprintf(STDERR, "Can't access file %s\n", afilename);
3115 strcpy(afilename, "");
3118 /* Check if volume exists or not */
3120 vsu_ExtractName(volname, avolname);
3121 vcode = VLDB_GetEntryByName(volname, &entry);
3122 if (vcode) { /* no volume - do a full restore */
3123 restoreflags = RV_FULLRST;
3124 if ((aoverwrite == INC) || (aoverwrite == ABORT))
3126 "Volume does not exist; Will perform a full restore\n");
3129 else if ((!readonly && Lp_GetRwIndex(&entry) == -1) /* RW volume does not exist - do a full */
3130 ||(readonly && !Lp_ROMatch(0, 0, &entry))) { /* RO volume does not exist - do a full */
3131 restoreflags = RV_FULLRST;
3132 if ((aoverwrite == INC) || (aoverwrite == ABORT))
3134 "%s Volume does not exist; Will perform a full restore\n",
3135 readonly ? "RO" : "RW");
3138 avolid = entry.volumeId[voltype];
3139 } else if (entry.volumeId[voltype] != 0
3140 && entry.volumeId[voltype] != avolid) {
3141 avolid = entry.volumeId[voltype];
3143 aparentid = entry.volumeId[RWVOL];
3146 else { /* volume exists - do we do a full incremental or abort */
3148 afs_int32 Opart, Otype, vol_elsewhere = 0;
3149 struct nvldbentry Oentry;
3153 avolid = entry.volumeId[voltype];
3154 } else if (entry.volumeId[voltype] != 0
3155 && entry.volumeId[voltype] != avolid) {
3156 avolid = entry.volumeId[voltype];
3158 aparentid = entry.volumeId[RWVOL];
3160 /* A file name was specified - check if volume is on another partition */
3161 vcode = GetVolumeInfo(avolid, &Oserver, &Opart, &Otype, &Oentry);
3165 vcode = VLDB_IsSameAddrs(Oserver, aserver, &err);
3168 "Failed to get info about server's %d address(es) from vlserver (err=%d); aborting call!\n",
3172 if (!vcode || (Opart != apart))
3175 if (aoverwrite == ASK) {
3176 if (strcmp(afilename, "") == 0) { /* The file is from standard in */
3178 "Volume exists and no -overwrite option specified; Aborting restore command\n");
3182 /* Ask what to do */
3183 if (vol_elsewhere) {
3185 "The volume %s %u already exists on a different server/part\n",
3186 volname, entry.volumeId[voltype]);
3188 "Do you want to do a full restore or abort? [fa](a): ");
3191 "The volume %s %u already exists in the VLDB\n",
3192 volname, entry.volumeId[voltype]);
3194 "Do you want to do a full/incremental restore or abort? [fia](a): ");
3197 while (!(dc == EOF || dc == '\n'))
3198 dc = getchar(); /* goto end of line */
3199 if ((c == 'f') || (c == 'F'))
3201 else if ((c == 'i') || (c == 'I'))
3207 if (aoverwrite == ABORT) {
3208 fprintf(STDERR, "Volume exists; Aborting restore command\n");
3210 } else if (aoverwrite == FULL) {
3211 restoreflags = RV_FULLRST;
3213 "Volume exists; Will delete and perform full restore\n");
3214 } else if (aoverwrite == INC) {
3216 if (vol_elsewhere) {
3218 "%s volume %lu already exists on a different server/part; not allowed\n",
3219 readonly ? "RO" : "RW", (unsigned long)avolid);
3225 restoreflags |= RV_OFFLINE;
3227 restoreflags |= RV_RDONLY;
3229 switch (acreation) {
3231 restoreflags |= RV_CRDUMP;
3234 restoreflags |= RV_CRKEEP;
3237 restoreflags |= RV_CRNEW;
3240 if (aoverwrite == FULL)
3241 restoreflags |= RV_CRNEW;
3243 restoreflags |= RV_CRKEEP;
3246 switch (alastupdate) {
3248 restoreflags |= RV_LUDUMP;
3251 restoreflags |= RV_LUKEEP;
3254 restoreflags |= RV_LUNEW;
3257 restoreflags |= RV_LUDUMP;
3259 if (as->parms[10].items) {
3260 restoreflags |= RV_NODEL;
3265 UV_RestoreVolume2(aserver, apart, avolid, aparentid,
3266 avolname, restoreflags, WriteData, afilename);
3268 PrintDiagnostics("restore", code);
3271 MapPartIdIntoName(apart, apartName);
3274 * patch typo here - originally "parms[1]", should be "parms[0]"
3277 fprintf(STDOUT, "Restored volume %s on %s %s\n", avolname,
3278 as->parms[0].items->data, apartName);
3283 LockReleaseCmd(struct cmd_syndesc *as, void *arock)
3286 afs_int32 code, err;
3288 avolid = vsu_GetVolumeID(as->parms[0].items->data, cstruct, &err);
3291 PrintError("", err);
3293 fprintf(STDERR, "vos: can't find volume '%s'\n",
3294 as->parms[0].items->data);
3298 code = UV_LockRelease(avolid);
3300 PrintDiagnostics("unlock", code);
3303 fprintf(STDOUT, "Released lock on vldb entry for volume %s\n",
3304 as->parms[0].items->data);
3309 AddSite(struct cmd_syndesc *as, void *arock)
3313 afs_int32 apart, code, err, arovolid, valid = 0;
3314 char apartName[10], avolname[VOLSER_MAXVOLNAME + 1];
3316 vsu_ExtractName(avolname, as->parms[2].items->data);;
3317 avolid = vsu_GetVolumeID(avolname, cstruct, &err);
3320 PrintError("", err);
3322 fprintf(STDERR, "vos: can't find volume '%s'\n",
3323 as->parms[2].items->data);
3327 if (as->parms[3].items) {
3328 vsu_ExtractName(avolname, as->parms[3].items->data);
3329 arovolid = vsu_GetVolumeID(avolname, cstruct, &err);
3331 fprintf(STDERR, "vos: invalid ro volume id '%s'\n",
3332 as->parms[3].items->data);
3336 aserver = GetServer(as->parms[0].items->data);
3338 fprintf(STDERR, "vos: server '%s' not found in host table\n",
3339 as->parms[0].items->data);
3342 apart = volutil_GetPartitionID(as->parms[1].items->data);
3344 fprintf(STDERR, "vos: could not interpret partition name '%s'\n",
3345 as->parms[1].items->data);
3348 if (!IsPartValid(apart, aserver, &code)) { /*check for validity of the partition */
3350 PrintError("", code);
3353 "vos : partition %s does not exist on the server\n",
3354 as->parms[1].items->data);
3357 if (as->parms[4].items) {
3360 code = UV_AddSite2(aserver, apart, avolid, arovolid, valid);
3362 PrintDiagnostics("addsite", code);
3365 MapPartIdIntoName(apart, apartName);
3366 fprintf(STDOUT, "Added replication site %s %s for volume %s\n",
3367 as->parms[0].items->data, apartName, as->parms[2].items->data);
3372 RemoveSite(struct cmd_syndesc *as, void *arock)
3377 afs_int32 apart, code, err;
3378 char apartName[10], avolname[VOLSER_MAXVOLNAME + 1];
3380 vsu_ExtractName(avolname, as->parms[2].items->data);
3381 avolid = vsu_GetVolumeID(avolname, cstruct, &err);
3384 PrintError("", err);
3386 fprintf(STDERR, "vos: can't find volume '%s'\n",
3387 as->parms[2].items->data);
3390 aserver = GetServer(as->parms[0].items->data);
3392 fprintf(STDERR, "vos: server '%s' not found in host table\n",
3393 as->parms[0].items->data);
3396 apart = volutil_GetPartitionID(as->parms[1].items->data);
3398 fprintf(STDERR, "vos: could not interpret partition name '%s'\n",
3399 as->parms[1].items->data);
3403 *skip the partition validity check, since it is possible that the partition
3404 *has since been decomissioned.
3407 if (!IsPartValid(apart,aserver,&code)){
3408 if(code) PrintError("",code);
3409 else fprintf(STDERR,"vos : partition %s does not exist on the server\n",as->parms[1].items->data);
3413 code = UV_RemoveSite(aserver, apart, avolid);
3415 PrintDiagnostics("remsite", code);
3418 MapPartIdIntoName(apart, apartName);
3419 fprintf(STDOUT, "Removed replication site %s %s for volume %s\n",
3420 as->parms[0].items->data, apartName, as->parms[2].items->data);
3425 ChangeLocation(struct cmd_syndesc *as, void *arock)
3429 afs_int32 apart, code, err;
3432 avolid = vsu_GetVolumeID(as->parms[2].items->data, cstruct, &err);
3435 PrintError("", err);
3437 fprintf(STDERR, "vos: can't find volume '%s'\n",
3438 as->parms[2].items->data);
3441 aserver = GetServer(as->parms[0].items->data);
3443 fprintf(STDERR, "vos: server '%s' not found in host table\n",
3444 as->parms[0].items->data);
3447 apart = volutil_GetPartitionID(as->parms[1].items->data);
3449 fprintf(STDERR, "vos: could not interpret partition name '%s'\n",
3450 as->parms[1].items->data);
3453 if (!IsPartValid(apart, aserver, &code)) { /*check for validity of the partition */
3455 PrintError("", code);
3458 "vos : partition %s does not exist on the server\n",
3459 as->parms[1].items->data);
3462 code = UV_ChangeLocation(aserver, apart, avolid);
3464 PrintDiagnostics("changeloc", code);
3467 MapPartIdIntoName(apart, apartName);
3468 fprintf(STDOUT, "Changed location to %s %s for volume %s\n",
3469 as->parms[0].items->data, apartName, as->parms[2].items->data);
3474 ListPartitions(struct cmd_syndesc *as, void *arock)
3478 struct partList dummyPartList;
3483 aserver = GetServer(as->parms[0].items->data);
3485 fprintf(STDERR, "vos: server '%s' not found in host table\n",
3486 as->parms[0].items->data);
3491 code = UV_ListPartitions(aserver, &dummyPartList, &cnt);
3493 PrintDiagnostics("listpart", code);
3497 fprintf(STDOUT, "The partitions on the server are:\n");
3498 for (i = 0; i < cnt; i++) {
3499 if (dummyPartList.partFlags[i] & PARTVALID) {
3500 memset(pname, 0, sizeof(pname));
3501 MapPartIdIntoName(dummyPartList.partId[i], pname);
3502 fprintf(STDOUT, " %10s ", pname);
3504 if ((i % 5) == 0 && (i != 0))
3505 fprintf(STDOUT, "\n");
3508 fprintf(STDOUT, "\n");
3509 fprintf(STDOUT, "Total: %d\n", total);
3515 CompareVolName(const void *p1, const void *p2)
3517 volintInfo *arg1, *arg2;
3519 arg1 = (volintInfo *) p1;
3520 arg2 = (volintInfo *) p2;
3521 return (strcmp(arg1->name, arg2->name));
3525 /*------------------------------------------------------------------------
3526 * PRIVATE XCompareVolName
3529 * Comparison routine for volume names coming from an extended
3533 * a_obj1P : Char ptr to first extended vol info object
3534 * a_obj1P : Char ptr to second extended vol info object
3537 * The value of strcmp() on the volume names within the passed
3538 * objects (i,e., -1, 0, or 1).
3541 * Passed to qsort() as the designated comparison routine.
3545 *------------------------------------------------------------------------*/
3548 XCompareVolName(const void *a_obj1P, const void *a_obj2P)
3549 { /*XCompareVolName */
3552 (((struct volintXInfo *)(a_obj1P))->name,
3553 ((struct volintXInfo *)(a_obj2P))->name));
3555 } /*XCompareVolName */
3558 CompareVolID(const void *p1, const void *p2)
3560 volintInfo *arg1, *arg2;
3562 arg1 = (volintInfo *) p1;
3563 arg2 = (volintInfo *) p2;
3564 if (arg1->volid == arg2->volid)
3566 if (arg1->volid > arg2->volid)
3573 /*------------------------------------------------------------------------
3574 * PRIVATE XCompareVolID
3577 * Comparison routine for volume IDs coming from an extended
3581 * a_obj1P : Char ptr to first extended vol info object
3582 * a_obj1P : Char ptr to second extended vol info object
3585 * The value of strcmp() on the volume names within the passed
3586 * objects (i,e., -1, 0, or 1).
3589 * Passed to qsort() as the designated comparison routine.
3593 *------------------------------------------------------------------------*/
3596 XCompareVolID(const void *a_obj1P, const void *a_obj2P)
3597 { /*XCompareVolID */
3599 afs_int32 id1, id2; /*Volume IDs we're comparing */
3601 id1 = ((struct volintXInfo *)(a_obj1P))->volid;
3602 id2 = ((struct volintXInfo *)(a_obj2P))->volid;
3610 } /*XCompareVolID */
3612 /*------------------------------------------------------------------------
3613 * PRIVATE ListVolumes
3616 * Routine used to list volumes, contacting the Volume Server
3617 * directly, bypassing the VLDB.
3620 * as : Ptr to parsed command line arguments.
3623 * 0 Successful operation
3626 * Nothing interesting.
3630 *------------------------------------------------------------------------*/
3633 ListVolumes(struct cmd_syndesc *as, void *arock)
3635 afs_int32 apart, int32list, fast;
3639 volintInfo *oldpntr = NULL;
3643 volintXInfo *xInfoP;
3644 volintXInfo *origxInfoP = NULL; /*Ptr to current/orig extended vol info */
3645 int wantExtendedInfo; /*Do we want extended vol info? */
3648 struct partList dummyPartList;
3656 if (as->parms[3].items)
3658 if (as->parms[4].items)
3662 if (as->parms[2].items)
3668 if (as->parms[5].items) {
3670 * We can't coexist with the fast flag.
3674 "vos: Can't use the -fast and -extended flags together\n");
3679 * We need to turn on ``long'' listings to get the full effect.
3681 wantExtendedInfo = 1;
3684 wantExtendedInfo = 0;
3685 if (as->parms[1].items) {
3686 apart = volutil_GetPartitionID(as->parms[1].items->data);
3688 fprintf(STDERR, "vos: could not interpret partition name '%s'\n",
3689 as->parms[1].items->data);
3692 dummyPartList.partId[0] = apart;
3693 dummyPartList.partFlags[0] = PARTVALID;
3696 aserver = GetServer(as->parms[0].items->data);
3698 fprintf(STDERR, "vos: server '%s' not found in host table\n",
3699 as->parms[0].items->data);
3704 if (!IsPartValid(apart, aserver, &code)) { /*check for validity of the partition */
3706 PrintError("", code);
3709 "vos : partition %s does not exist on the server\n",
3710 as->parms[1].items->data);
3714 code = UV_ListPartitions(aserver, &dummyPartList, &cnt);
3716 PrintDiagnostics("listvol", code);
3720 for (i = 0; i < cnt; i++) {
3721 if (dummyPartList.partFlags[i] & PARTVALID) {
3722 if (wantExtendedInfo)
3724 UV_XListVolumes(aserver, dummyPartList.partId[i], all,
3728 UV_ListVolumes(aserver, dummyPartList.partId[i], all,
3731 PrintDiagnostics("listvol", code);
3734 if (wantExtendedInfo) {
3735 origxInfoP = xInfoP;
3736 base = (char *)xInfoP;
3739 base = (char *)pntr;
3743 if (wantExtendedInfo)
3744 qsort(base, count, sizeof(volintXInfo), XCompareVolName);
3746 qsort(base, count, sizeof(volintInfo), CompareVolName);
3748 if (wantExtendedInfo)
3749 qsort(base, count, sizeof(volintXInfo), XCompareVolID);
3751 qsort(base, count, sizeof(volintInfo), CompareVolID);
3753 MapPartIdIntoName(dummyPartList.partId[i], pname);
3756 "Total number of volumes on server %s partition %s: %lu \n",
3757 as->parms[0].items->data, pname,
3758 (unsigned long)count);
3759 if (wantExtendedInfo) {
3760 if (as->parms[6].items)
3761 XDisplayVolumes2(aserver, dummyPartList.partId[i], origxInfoP,
3762 count, int32list, fast, quiet);
3764 XDisplayVolumes(aserver, dummyPartList.partId[i], origxInfoP,
3765 count, int32list, fast, quiet);
3768 xInfoP = (volintXInfo *) 0;
3770 if (as->parms[6].items)
3771 DisplayVolumes2(aserver, dummyPartList.partId[i], oldpntr,
3774 DisplayVolumes(aserver, dummyPartList.partId[i], oldpntr,
3775 count, int32list, fast, quiet);
3778 pntr = (volintInfo *) 0;
3786 SyncVldb(struct cmd_syndesc *as, void *arock)
3788 afs_int32 pnum = 0, code; /* part name */
3795 if (as->parms[0].items) {
3796 tserver = GetServer(as->parms[0].items->data);
3798 fprintf(STDERR, "vos: host '%s' not found in host table\n",
3799 as->parms[0].items->data);
3804 if (as->parms[1].items) {
3805 pnum = volutil_GetPartitionID(as->parms[1].items->data);
3807 fprintf(STDERR, "vos: could not interpret partition name '%s'\n",
3808 as->parms[1].items->data);
3811 if (!IsPartValid(pnum, tserver, &code)) { /*check for validity of the partition */
3813 PrintError("", code);
3816 "vos: partition %s does not exist on the server\n",
3817 as->parms[1].items->data);
3824 "The -partition option requires a -server option\n");
3829 if (as->parms[3].items) {
3830 flags |= 2; /* don't update */
3833 if (as->parms[2].items) {
3834 /* Synchronize an individual volume */
3835 volname = as->parms[2].items->data;
3836 code = UV_SyncVolume(tserver, pnum, volname, flags);
3840 "Without a -volume option, the -server option is required\n");
3843 code = UV_SyncVldb(tserver, pnum, flags, 0 /*unused */ );
3847 PrintDiagnostics("syncvldb", code);
3851 /* Print a summary of what we did */
3853 fprintf(STDOUT, "VLDB volume %s synchronized", volname);
3855 fprintf(STDOUT, "VLDB synchronized");
3857 fprintf(STDOUT, " with state of server %s", as->parms[0].items->data);
3860 MapPartIdIntoName(pnum, part);
3861 fprintf(STDOUT, " partition %s\n", part);
3863 fprintf(STDOUT, "\n");
3869 SyncServer(struct cmd_syndesc *as, void *arock)
3871 afs_int32 pnum, code; /* part name */
3877 tserver = GetServer(as->parms[0].items->data);
3879 fprintf(STDERR, "vos: host '%s' not found in host table\n",
3880 as->parms[0].items->data);
3883 if (as->parms[1].items) {
3884 pnum = volutil_GetPartitionID(as->parms[1].items->data);
3886 fprintf(STDERR, "vos: could not interpret partition name '%s'\n",
3887 as->parms[1].items->data);
3890 if (!IsPartValid(pnum, tserver, &code)) { /*check for validity of the partition */
3892 PrintError("", code);
3895 "vos : partition %s does not exist on the server\n",
3896 as->parms[1].items->data);
3904 if (as->parms[2].items) {
3905 flags |= 2; /* don't update */
3907 code = UV_SyncServer(tserver, pnum, flags, 0 /*unused */ );
3909 PrintDiagnostics("syncserv", code);
3913 MapPartIdIntoName(pnum, part);
3914 fprintf(STDOUT, "Server %s partition %s synchronized with VLDB\n",
3915 as->parms[0].items->data, part);
3917 fprintf(STDOUT, "Server %s synchronized with VLDB\n",
3918 as->parms[0].items->data);
3924 VolumeInfoCmd(char *name)
3926 struct nvldbentry entry;
3929 /* The vlserver will handle names with the .readonly
3930 * and .backup extension as well as volume ids.
3932 vcode = VLDB_GetEntryByName(name, &entry);
3934 PrintError("", vcode);
3937 MapHostToNetwork(&entry);
3938 EnumerateEntry(&entry);
3940 /* Defect #3027: grubby check to handle locked volume.
3941 * If VLOP_ALLOPERS is set, the entry is locked.
3942 * Leave this routine as is, but put in correct check.
3944 PrintLocked(entry.flags);
3950 VolumeZap(struct cmd_syndesc *as, void *arock)
3952 struct nvldbentry entry;
3953 afs_uint32 volid, zapbackupid = 0, backupid = 0;
3954 afs_int32 code, server, part, err;
3956 if (as->parms[3].items) {
3957 /* force flag is on, use the other version */
3958 return NukeVolume(as);
3961 if (as->parms[4].items) {
3965 volid = vsu_GetVolumeID(as->parms[2].items->data, cstruct, &err);
3968 PrintError("", err);
3970 fprintf(STDERR, "vos: can't find volume '%s'\n",
3971 as->parms[2].items->data);
3974 part = volutil_GetPartitionID(as->parms[1].items->data);
3976 fprintf(STDERR, "vos: could not interpret partition name '%s'\n",
3977 as->parms[1].items->data);
3980 server = GetServer(as->parms[0].items->data);
3982 fprintf(STDERR, "vos: host '%s' not found in host table\n",
3983 as->parms[0].items->data);
3986 if (!IsPartValid(part, server, &code)) { /*check for validity of the partition */
3988 PrintError("", code);
3991 "vos : partition %s does not exist on the server\n",
3992 as->parms[1].items->data);
3995 code = VLDB_GetEntryByID(volid, -1, &entry);
3997 if (volid == entry.volumeId[RWVOL])
3998 backupid = entry.volumeId[BACKVOL];
4000 "Warning: Entry for volume number %lu exists in VLDB (but we're zapping it anyway!)\n",
4001 (unsigned long)volid);
4004 volintInfo *pntr = (volintInfo *) 0;
4007 code = UV_ListOneVolume(server, part, volid, &pntr);
4009 if (volid == pntr->parentID)
4010 backupid = pntr->backupID;
4016 code = UV_VolumeZap(server, part, backupid);
4018 PrintDiagnostics("zap", code);
4021 fprintf(STDOUT, "Backup Volume %lu deleted\n",
4022 (unsigned long)backupid);
4025 code = UV_VolumeZap(server, part, volid);
4027 PrintDiagnostics("zap", code);
4030 fprintf(STDOUT, "Volume %lu deleted\n", (unsigned long)volid);
4036 VolserStatus(struct cmd_syndesc *as, void *arock)
4040 transDebugInfo *pntr, *oldpntr;
4046 server = GetServer(as->parms[0].items->data);
4048 fprintf(STDERR, "vos: host '%s' not found in host table\n",
4049 as->parms[0].items->data);
4052 code = UV_VolserStatus(server, &pntr, &count);
4054 PrintDiagnostics("status", code);
4059 fprintf(STDOUT, "No active transactions on %s\n",
4060 as->parms[0].items->data);
4062 fprintf(STDOUT, "Total transactions: %d\n", count);
4064 for (i = 0; i < count; i++) {
4065 /*print out the relevant info */
4066 fprintf(STDOUT, "--------------------------------------\n");
4067 t = pntr->creationTime;
4068 fprintf(STDOUT, "transaction: %lu created: %s",
4069 (unsigned long)pntr->tid, ctime(&t));
4071 fprintf(STDOUT, "lastActiveTime: %s", ctime(&t));
4072 if (pntr->returnCode) {
4073 fprintf(STDOUT, "returnCode: %lu\n",
4074 (unsigned long)pntr->returnCode);
4077 fprintf(STDOUT, "attachFlags: ");
4078 switch (pntr->iflags) {
4080 fprintf(STDOUT, "offline ");
4083 fprintf(STDOUT, "busy ");
4086 fprintf(STDOUT, "readonly ");
4089 fprintf(STDOUT, "create ");
4092 fprintf(STDOUT, "create volid ");
4095 fprintf(STDOUT, "\n");
4098 fprintf(STDOUT, "volumeStatus: ");
4099 switch (pntr->vflags) {
4100 case VTDeleteOnSalvage:
4101 fprintf(STDOUT, "deleteOnSalvage ");
4102 case VTOutOfService:
4103 fprintf(STDOUT, "outOfService ");
4105 fprintf(STDOUT, "deleted ");
4107 fprintf(STDOUT, "\n");
4110 fprintf(STDOUT, "transactionFlags: ");
4111 fprintf(STDOUT, "delete\n");
4113 MapPartIdIntoName(pntr->partition, pname);
4114 fprintf(STDOUT, "volume: %lu partition: %s procedure: %s\n",
4115 (unsigned long)pntr->volid, pname, pntr->lastProcName);
4116 if (pntr->callValid) {
4117 t = pntr->lastReceiveTime;
4118 fprintf(STDOUT, "packetRead: %lu lastReceiveTime: %s",
4119 (unsigned long)pntr->readNext, ctime(&t));
4120 t = pntr->lastSendTime;
4121 fprintf(STDOUT, "packetSend: %lu lastSendTime: %s",
4122 (unsigned long)pntr->transmitNext, ctime(&t));
4125 fprintf(STDOUT, "--------------------------------------\n");
4126 fprintf(STDOUT, "\n");
4134 RenameVolume(struct cmd_syndesc *as, void *arock)
4136 afs_int32 code1, code2, code;
4137 struct nvldbentry entry;
4139 code1 = VLDB_GetEntryByName(as->parms[0].items->data, &entry);
4141 fprintf(STDERR, "vos: Could not find entry for volume %s\n",
4142 as->parms[0].items->data);
4145 code2 = VLDB_GetEntryByName(as->parms[1].items->data, &entry);
4146 if ((!code1) && (!code2)) { /*the newname already exists */
4147 fprintf(STDERR, "vos: volume %s already exists\n",
4148 as->parms[1].items->data);
4152 if (code1 && code2) {
4153 fprintf(STDERR, "vos: Could not find entry for volume %s or %s\n",
4154 as->parms[0].items->data, as->parms[1].items->data);
4157 if (!VolNameOK(as->parms[0].items->data)) {
4159 "Illegal volume name %s, should not end in .readonly or .backup\n",
4160 as->parms[0].items->data);
4163 if (!ISNAMEVALID(as->parms[1].items->data)) {
4165 "vos: the new volume name %s exceeds the size limit of %d\n",
4166 as->parms[1].items->data, VOLSER_OLDMAXVOLNAME - 10);
4169 if (!VolNameOK(as->parms[1].items->data)) {
4171 "Illegal volume name %s, should not end in .readonly or .backup\n",
4172 as->parms[1].items->data);
4175 if (IsNumeric(as->parms[1].items->data)) {
4176 fprintf(STDERR, "Illegal volume name %s, should not be a number\n",
4177 as->parms[1].items->data);
4180 MapHostToNetwork(&entry);
4182 UV_RenameVolume(&entry, as->parms[0].items->data,
4183 as->parms[1].items->data);
4185 PrintDiagnostics("rename", code);
4188 fprintf(STDOUT, "Renamed volume %s to %s\n", as->parms[0].items->data,
4189 as->parms[1].items->data);
4194 GetVolumeInfo(afs_uint32 volid, afs_uint32 *server, afs_int32 *part, afs_int32 *voltype,
4195 struct nvldbentry *rentry)
4200 vcode = VLDB_GetEntryByID(volid, -1, rentry);
4203 "Could not fetch the entry for volume %lu from VLDB \n",
4204 (unsigned long)volid);
4205 PrintError("", vcode);
4208 MapHostToNetwork(rentry);
4209 if (volid == rentry->volumeId[ROVOL]) {
4211 for (i = 0; i < rentry->nServers; i++) {
4212 if ((index == -1) && (rentry->serverFlags[i] & ITSROVOL)
4213 && !(rentry->serverFlags[i] & RO_DONTUSE))
4218 "RO volume is not found in VLDB entry for volume %lu\n",
4219 (unsigned long)volid);
4223 *server = rentry->serverNumber[index];
4224 *part = rentry->serverPartition[index];
4228 index = Lp_GetRwIndex(rentry);
4231 "RW Volume is not found in VLDB entry for volume %lu\n",
4232 (unsigned long)volid);
4235 if (volid == rentry->volumeId[RWVOL]) {
4237 *server = rentry->serverNumber[index];
4238 *part = rentry->serverPartition[index];
4241 if (volid == rentry->volumeId[BACKVOL]) {
4243 *server = rentry->serverNumber[index];
4244 *part = rentry->serverPartition[index];
4248 "unexpected volume type for volume %lu\n",
4249 (unsigned long)volid);
4254 DeleteEntry(struct cmd_syndesc *as, void *arock)
4256 afs_int32 apart = 0;
4259 struct VldbListByAttributes attributes;
4260 nbulkentries arrayEntries;
4261 struct nvldbentry *vllist;
4262 struct cmd_item *itp;
4265 char prefix[VOLSER_MAXVOLNAME + 1];
4267 afs_int32 totalBack = 0, totalFail = 0, err;
4269 if (as->parms[0].items) { /* -id */
4270 if (as->parms[1].items || as->parms[2].items || as->parms[3].items) {
4272 "You cannot use -server, -partition, or -prefix with the -id argument\n");
4275 for (itp = as->parms[0].items; itp; itp = itp->next) {
4276 avolid = vsu_GetVolumeID(itp->data, cstruct, &err);
4279 PrintError("", err);
4281 fprintf(STDERR, "vos: can't find volume '%s'\n",
4285 if (as->parms[4].items || as->parms[5].items) {
4286 /* -noexecute (hidden) or -dryrun */
4287 fprintf(STDOUT, "Would have deleted VLDB entry for %s \n",
4292 vcode = ubik_VL_DeleteEntry(cstruct, 0, avolid, RWVOL);
4294 fprintf(STDERR, "Could not delete entry for volume %s\n",
4297 "You must specify a RW volume name or ID "
4298 "(the entire VLDB entry will be deleted)\n");
4299 PrintError("", vcode);
4305 fprintf(STDOUT, "Deleted %d VLDB entries\n", totalBack);
4309 if (!as->parms[1].items && !as->parms[2].items && !as->parms[3].items) {
4310 fprintf(STDERR, "You must specify an option\n");
4314 /* Zero out search attributes */
4315 memset(&attributes, 0, sizeof(struct VldbListByAttributes));
4317 if (as->parms[1].items) { /* -prefix */
4318 strncpy(prefix, as->parms[1].items->data, VOLSER_MAXVOLNAME);
4320 if (!as->parms[2].items && !as->parms[3].items) { /* a single entry only */
4322 "You must provide -server with the -prefix argument\n");
4327 if (as->parms[2].items) { /* -server */
4329 aserver = GetServer(as->parms[2].items->data);
4331 fprintf(STDERR, "vos: server '%s' not found in host table\n",
4332 as->parms[2].items->data);
4335 attributes.server = ntohl(aserver);
4336 attributes.Mask |= VLLIST_SERVER;
4339 if (as->parms[3].items) { /* -partition */
4340 if (!as->parms[2].items) {
4342 "You must provide -server with the -partition argument\n");
4345 apart = volutil_GetPartitionID(as->parms[3].items->data);
4347 fprintf(STDERR, "vos: could not interpret partition name '%s'\n",
4348 as->parms[3].items->data);
4351 attributes.partition = apart;
4352 attributes.Mask |= VLLIST_PARTITION;
4355 /* Print status line of what we are doing */
4356 fprintf(STDOUT, "Deleting VLDB entries for ");
4357 if (as->parms[2].items) {
4358 fprintf(STDOUT, "server %s ", as->parms[2].items->data);
4360 if (as->parms[3].items) {
4362 MapPartIdIntoName(apart, pname);
4363 fprintf(STDOUT, "partition %s ", pname);
4366 fprintf(STDOUT, "which are prefixed with %s ", prefix);
4368 fprintf(STDOUT, "\n");
4371 /* Get all the VLDB entries on a server and/or partition */
4372 memset(&arrayEntries, 0, sizeof(arrayEntries));
4373 vcode = VLDB_ListAttributes(&attributes, &nentries, &arrayEntries);
4375 fprintf(STDERR, "Could not access the VLDB for attributes\n");
4376 PrintError("", vcode);
4380 /* Process each entry */
4381 for (j = 0; j < nentries; j++) {
4382 vllist = &arrayEntries.nbulkentries_val[j];
4384 /* It only deletes the RW volumes */
4385 if (strncmp(vllist->name, prefix, strlen(prefix))) {
4388 "Omitting to delete %s due to prefix %s mismatch\n",
4389 vllist->name, prefix);
4396 if (as->parms[4].items || as->parms[5].items) {
4397 /* -noexecute (hidden) or -dryrun */
4398 fprintf(STDOUT, "Would have deleted VLDB entry for %s \n",
4404 /* Only matches the RW volume name */
4405 avolid = vllist->volumeId[RWVOL];
4406 vcode = ubik_VL_DeleteEntry(cstruct, 0, avolid, RWVOL);
4408 fprintf(STDOUT, "Could not delete VLDB entry for %s\n",
4411 PrintError("", vcode);
4416 fprintf(STDOUT, "Deleted VLDB entry for %s \n", vllist->name);
4421 fprintf(STDOUT, "----------------------\n");
4423 "Total VLDB entries deleted: %lu; failed to delete: %lu\n",
4424 (unsigned long)totalBack, (unsigned long)totalFail);
4426 xdr_free((xdrproc_t) xdr_nbulkentries, &arrayEntries);
4432 CompareVldbEntryByName(const void *p1, const void *p2)
4434 struct nvldbentry *arg1, *arg2;
4436 arg1 = (struct nvldbentry *)p1;
4437 arg2 = (struct nvldbentry *)p2;
4438 return (strcmp(arg1->name, arg2->name));
4442 static int CompareVldbEntry(char *p1, char *p2)
4444 struct nvldbentry *arg1,*arg2;
4447 char comp1[100],comp2[100];
4448 char temp1[20],temp2[20];
4450 arg1 = (struct nvldbentry *)p1;
4451 arg2 = (struct nvldbentry *)p2;
4455 for(i = 0; i < arg1->nServers; i++)
4456 if(arg1->serverFlags[i] & ITSRWVOL) pos1 = i;
4457 for(i = 0; i < arg2->nServers; i++)
4458 if(arg2->serverFlags[i] & ITSRWVOL) pos2 = i;
4459 if(pos1 == -1 || pos2 == -1){
4463 sprintf(comp1,"%10u",arg1->serverNumber[pos1]);
4464 sprintf(comp2,"%10u",arg2->serverNumber[pos2]);
4465 sprintf(temp1,"%10u",arg1->serverPartition[pos1]);
4466 sprintf(temp2,"%10u",arg2->serverPartition[pos2]);
4467 strcat(comp1,temp1);
4468 strcat(comp2,temp2);
4469 strcat(comp1,arg1->name);
4470 strcat(comp1,arg2->name);
4471 return(strcmp(comp1,comp2));
4477 ListVLDB(struct cmd_syndesc *as, void *arock)
4482 struct VldbListByAttributes attributes;
4483 nbulkentries arrayEntries;
4484 struct nvldbentry *vllist, *tarray = 0, *ttarray;
4485 afs_int32 centries, nentries = 0;
4486 afs_int32 tarraysize = 0;
4487 afs_int32 parraysize;
4490 int quiet, sort, lock;
4491 afs_int32 thisindex, nextindex;
4495 attributes.Mask = 0;
4496 lock = (as->parms[3].items ? 1 : 0); /* -lock flag */
4497 quiet = (as->parms[4].items ? 1 : 0); /* -quit flag */
4498 sort = (as->parms[5].items ? 0 : 1); /* -nosort flag */
4500 /* If the volume name is given, Use VolumeInfoCmd to look it up
4501 * and not ListAttributes.
4503 if (as->parms[0].items) {
4506 "vos: illegal use of '-locked' switch, need to specify server and/or partition\n");
4509 code = VolumeInfoCmd(as->parms[0].items->data);
4511 PrintError("", code);
4517 /* Server specified */
4518 if (as->parms[1].items) {
4521 aserver = GetServer(as->parms[1].items->data);
4523 fprintf(STDERR, "vos: server '%s' not found in host table\n",
4524 as->parms[1].items->data);
4527 attributes.server = ntohl(aserver);
4528 attributes.Mask |= VLLIST_SERVER;
4531 /* Partition specified */
4532 if (as->parms[2].items) {
4533 apart = volutil_GetPartitionID(as->parms[2].items->data);
4535 fprintf(STDERR, "vos: could not interpret partition name '%s'\n",
4536 as->parms[2].items->data);
4539 attributes.partition = apart;
4540 attributes.Mask |= VLLIST_PARTITION;
4544 attributes.Mask |= VLLIST_FLAG;
4545 attributes.flag = VLOP_ALLOPERS;
4548 /* Print header information */
4550 MapPartIdIntoName(apart, pname);
4551 fprintf(STDOUT, "VLDB entries for %s %s%s%s %s\n",
4552 (as->parms[1].items ? "server" : "all"),
4553 (as->parms[1].items ? as->parms[1].items->data : "servers"),
4554 (as->parms[2].items ? " partition " : ""),
4555 (as->parms[2].items ? pname : ""),
4556 (lock ? "which are locked:" : ""));
4559 for (thisindex = 0; (thisindex != -1); thisindex = nextindex) {
4560 memset(&arrayEntries, 0, sizeof(arrayEntries));
4565 VLDB_ListAttributesN2(&attributes, 0, thisindex, ¢ries,
4566 &arrayEntries, &nextindex);
4567 if (vcode == RXGEN_OPCODE) {
4568 /* Vlserver not running with ListAttributesN2. Fall back */
4570 VLDB_ListAttributes(&attributes, ¢ries, &arrayEntries);
4574 fprintf(STDERR, "Could not access the VLDB for attributes\n");
4575 PrintError("", vcode);
4578 nentries += centries;
4580 /* We don't sort, so just print the entries now */
4582 for (j = 0; j < centries; j++) { /* process each entry */
4583 vllist = &arrayEntries.nbulkentries_val[j];
4584 MapHostToNetwork(vllist);
4585 EnumerateEntry(vllist);
4587 PrintLocked(vllist->flags);
4591 /* So we sort. First we must collect all the entries and keep
4594 else if (centries > 0) {
4596 /* malloc the first bulk entries array */
4597 tarraysize = centries * sizeof(struct nvldbentry);
4598 tarray = malloc(tarraysize);
4601 "Could not allocate enough space for the VLDB entries\n");
4604 memcpy((char*)tarray, arrayEntries.nbulkentries_val, tarraysize);
4606 /* Grow the tarray to keep the extra entries */
4607 parraysize = (centries * sizeof(struct nvldbentry));
4608 ttarray = realloc(tarray, tarraysize + parraysize);
4611 "Could not allocate enough space for the VLDB entries\n");
4617 memcpy(((char *)tarray) + tarraysize,
4618 (char *)arrayEntries.nbulkentries_val, parraysize);
4619 tarraysize += parraysize;
4623 /* Free the bulk array */
4624 xdr_free((xdrproc_t) xdr_nbulkentries, &arrayEntries);
4627 /* Here is where we now sort all the entries and print them */
4628 if (sort && (nentries > 0)) {
4629 qsort((char *)tarray, nentries, sizeof(struct nvldbentry),
4630 CompareVldbEntryByName);
4631 for (vllist = tarray, j = 0; j < nentries; j++, vllist++) {
4632 MapHostToNetwork(vllist);
4633 EnumerateEntry(vllist);
4635 PrintLocked(vllist->flags);
4641 fprintf(STDOUT, "\nTotal entries: %lu\n", (unsigned long)nentries);
4648 BackSys(struct cmd_syndesc *as, void *arock)
4651 afs_int32 apart = 0;
4652 afs_uint32 aserver = 0, aserver1;
4653 afs_int32 code, apart1;
4655 struct VldbListByAttributes attributes;
4656 nbulkentries arrayEntries;
4657 struct nvldbentry *vllist;
4661 int seenprefix, seenxprefix, exclude, ex, exp, noaction;
4662 afs_int32 totalBack = 0;
4663 afs_int32 totalFail = 0;
4667 struct cmd_item *ti;
4669 #ifndef HAVE_POSIX_REGEX
4673 memset(&attributes, 0, sizeof(struct VldbListByAttributes));
4674 attributes.Mask = 0;
4676 seenprefix = (as->parms[0].items ? 1 : 0);
4677 exclude = (as->parms[3].items ? 1 : 0);
4678 seenxprefix = (as->parms[4].items ? 1 : 0);
4679 noaction = (as->parms[5].items ? 1 : 0);
4681 if (as->parms[1].items) { /* -server */
4682 aserver = GetServer(as->parms[1].items->data);
4684 fprintf(STDERR, "vos: server '%s' not found in host table\n",
4685 as->parms[1].items->data);
4688 attributes.server = ntohl(aserver);
4689 attributes.Mask |= VLLIST_SERVER;
4692 if (as->parms[2].items) { /* -partition */
4693 apart = volutil_GetPartitionID(as->parms[2].items->data);
4695 fprintf(STDERR, "vos: could not interpret partition name '%s'\n",
4696 as->parms[2].items->data);
4699 attributes.partition = apart;
4700 attributes.Mask |= VLLIST_PARTITION;
4703 /* Check to make sure the prefix and xprefix expressions compile ok */
4705 for (ti = as->parms[0].items; ti; ti = ti->next) {
4706 if (strncmp(ti->data, "^", 1) == 0) {
4707 #ifdef HAVE_POSIX_REGEX
4711 code = regcomp(&re, ti->data, REG_NOSUB);
4713 regerror(code, &re, errbuf, sizeof errbuf);
4715 "Unrecognizable -prefix regular expression: '%s': %s\n",
4721 ccode = (char *)re_comp(ti->data);
4724 "Unrecognizable -prefix regular expression: '%s': %s\n",
4733 for (ti = as->parms[4].items; ti; ti = ti->next) {
4734 if (strncmp(ti->data, "^", 1) == 0) {
4735 #ifdef HAVE_POSIX_REGEX
4739 code = regcomp(&re, ti->data, REG_NOSUB);
4741 regerror(code, &re, errbuf, sizeof errbuf);
4743 "Unrecognizable -xprefix regular expression: '%s': %s\n",
4749 ccode = (char *)re_comp(ti->data);
4752 "Unrecognizable -xprefix regular expression: '%s': %s\n",
4761 memset(&arrayEntries, 0, sizeof(arrayEntries)); /* initialize to hint the stub to alloc space */
4762 vcode = VLDB_ListAttributes(&attributes, &nentries, &arrayEntries);
4764 fprintf(STDERR, "Could not access the VLDB for attributes\n");
4765 PrintError("", vcode);
4769 if (as->parms[1].items || as->parms[2].items || verbose) {
4770 fprintf(STDOUT, "%s up volumes",
4771 (noaction ? "Would have backed" : "Backing"));
4773 if (as->parms[1].items) {
4774 fprintf(STDOUT, " on server %s", as->parms[1].items->data);
4775 } else if (as->parms[2].items) {
4776 fprintf(STDOUT, " for all servers");
4779 if (as->parms[2].items) {
4780 MapPartIdIntoName(apart, pname);
4781 fprintf(STDOUT, " partition %s", pname);
4784 if (seenprefix || (!seenprefix && seenxprefix)) {
4785 ti = (seenprefix ? as->parms[0].items : as->parms[4].items);
4786 ex = (seenprefix ? exclude : !exclude);
4787 exp = (strncmp(ti->data, "^", 1) == 0);
4788 fprintf(STDOUT, " which %smatch %s '%s'", (ex ? "do not " : ""),
4789 (exp ? "expression" : "prefix"), ti->data);
4790 for (ti = ti->next; ti; ti = ti->next) {
4791 exp = (strncmp(ti->data, "^", 1) == 0);
4792 printf(" %sor %s '%s'", (ex ? "n" : ""),
4793 (exp ? "expression" : "prefix"), ti->data);
4797 if (seenprefix && seenxprefix) {
4798 ti = as->parms[4].items;
4799 exp = (strncmp(ti->data, "^", 1) == 0);
4800 fprintf(STDOUT, " %swhich match %s '%s'",
4801 (exclude ? "adding those " : "removing those "),
4802 (exp ? "expression" : "prefix"), ti->data);
4803 for (ti = ti->next; ti; ti = ti->next) {
4804 exp = (strncmp(ti->data, "^", 1) == 0);
4805 printf(" or %s '%s'", (exp ? "expression" : "prefix"),
4809 fprintf(STDOUT, " .. ");
4811 fprintf(STDOUT, "\n");
4815 for (j = 0; j < nentries; j++) { /* process each vldb entry */
4816 vllist = &arrayEntries.nbulkentries_val[j];
4819 for (ti = as->parms[0].items; ti; ti = ti->next) {
4820 if (strncmp(ti->data, "^", 1) == 0) {
4821 #ifdef HAVE_POSIX_REGEX
4825 /* XXX -- should just do the compile once! */
4826 code = regcomp(&re, ti->data, REG_NOSUB);
4828 regerror(code, &re, errbuf, sizeof errbuf);
4830 "Error in -prefix regular expression: '%s': %s\n",
4834 match = (regexec(&re, vllist->name, 0, NULL, 0) == 0);
4837 ccode = (char *)re_comp(ti->data);
4840 "Error in -prefix regular expression: '%s': %s\n",
4844 match = (re_exec(vllist->name) == 1);
4848 (strncmp(vllist->name, ti->data, strlen(ti->data)) ==
4858 /* Without the -exclude flag: If it matches the prefix, then
4859 * check if we want to exclude any from xprefix.
4860 * With the -exclude flag: If it matches the prefix, then
4861 * check if we want to add any from xprefix.
4863 if (match && seenxprefix) {
4864 for (ti = as->parms[4].items; ti; ti = ti->next) {
4865 if (strncmp(ti->data, "^", 1) == 0) {
4866 #ifdef HAVE_POSIX_REGEX
4870 /* XXX -- should just do the compile once! */
4871 code = regcomp(&re, ti->data, REG_NOSUB);
4873 regerror(code, &re, errbuf, sizeof errbuf);
4875 "Error in -xprefix regular expression: '%s': %s\n",
4879 if (regexec(&re, vllist->name, 0, NULL, 0) == 0)
4883 ccode = (char *)re_comp(ti->data);
4886 "Error in -xprefix regular expression: '%s': %s\n",
4890 if (re_exec(vllist->name) == 1) {
4896 if (strncmp(vllist->name, ti->data, strlen(ti->data)) ==
4906 match = !match; /* -exclude will reverse the match */
4908 continue; /* Skip if no match */
4910 /* Print list of volumes to backup */
4912 fprintf(STDOUT, " %s\n", vllist->name);
4916 if (!(vllist->flags & RW_EXISTS)) {
4919 "Omitting to backup %s since RW volume does not exist \n",
4921 fprintf(STDOUT, "\n");
4927 avolid = vllist->volumeId[RWVOL];
4928 MapHostToNetwork(vllist);
4929 GetServerAndPart(vllist, RWVOL, &aserver1, &apart1, &previdx);
4930 if (aserver1 == -1 || apart1 == -1) {
4931 fprintf(STDOUT, "could not backup %s, invalid VLDB entry\n",
4937 same = VLDB_IsSameAddrs(aserver, aserver1, &error);
4940 "Failed to get info about server's %d address(es) from vlserver (err=%d); aborting call!\n",
4946 if ((aserver && !same) || (apart && (apart != apart1))) {
4949 "Omitting to backup %s since the RW is in a different location\n",
4955 time_t now = time(0);
4956 fprintf(STDOUT, "Creating backup volume for %s on %s",
4957 vllist->name, ctime(&now));
4961 code = UV_BackupVolume(aserver1, apart1, avolid);
4963 fprintf(STDOUT, "Could not backup %s\n", vllist->name);
4969 fprintf(STDOUT, "\n");
4971 } /* process each vldb entry */
4972 fprintf(STDOUT, "done\n");
4973 fprintf(STDOUT, "Total volumes backed up: %lu; failed to backup: %lu\n",
4974 (unsigned long)totalBack, (unsigned long)totalFail);
4976 xdr_free((xdrproc_t) xdr_nbulkentries, &arrayEntries);
4981 UnlockVLDB(struct cmd_syndesc *as, void *arock)
4984 afs_uint32 aserver = 0;
4987 struct VldbListByAttributes attributes;
4988 nbulkentries arrayEntries;
4989 struct nvldbentry *vllist;
4998 attributes.Mask = 0;
5000 if (as->parms[0].items) { /* server specified */
5001 aserver = GetServer(as->parms[0].items->data);
5003 fprintf(STDERR, "vos: server '%s' not found in host table\n",
5004 as->parms[0].items->data);
5007 attributes.server = ntohl(aserver);
5008 attributes.Mask |= VLLIST_SERVER;
5010 if (as->parms[1].items) { /* partition specified */
5011 apart = volutil_GetPartitionID(as->parms[1].items->data);
5013 fprintf(STDERR, "vos: could not interpret partition name '%s'\n",
5014 as->parms[1].items->data);
5017 if (!IsPartValid(apart, aserver, &code)) { /*check for validity of the partition */
5019 PrintError("", code);
5022 "vos : partition %s does not exist on the server\n",
5023 as->parms[1].items->data);
5026 attributes.partition = apart;
5027 attributes.Mask |= VLLIST_PARTITION;
5029 attributes.flag = VLOP_ALLOPERS;
5030 attributes.Mask |= VLLIST_FLAG;
5031 memset(&arrayEntries, 0, sizeof(arrayEntries)); /*initialize to hint the stub to alloc space */
5032 vcode = VLDB_ListAttributes(&attributes, &nentries, &arrayEntries);
5034 fprintf(STDERR, "Could not access the VLDB for attributes\n");
5035 PrintError("", vcode);
5038 for (j = 0; j < nentries; j++) { /* process each entry */
5039 vllist = &arrayEntries.nbulkentries_val[j];
5040 volid = vllist->volumeId[RWVOL];
5042 ubik_VL_ReleaseLock(cstruct, 0, volid, -1,
5043 LOCKREL_OPCODE | LOCKREL_AFSID |
5046 fprintf(STDERR, "Could not unlock entry for volume %s\n",
5048 PrintError("", vcode);
5053 MapPartIdIntoName(apart, pname);
5056 "Could not lock %lu VLDB entries of %lu locked entries\n",
5057 (unsigned long)totalE, (unsigned long)nentries);
5059 if (as->parms[0].items) {
5061 "Unlocked all the VLDB entries for volumes on server %s ",
5062 as->parms[0].items->data);
5063 if (as->parms[1].items) {
5064 MapPartIdIntoName(apart, pname);
5065 fprintf(STDOUT, "partition %s\n", pname);
5067 fprintf(STDOUT, "\n");
5069 } else if (as->parms[1].items) {
5070 MapPartIdIntoName(apart, pname);
5072 "Unlocked all the VLDB entries for volumes on partition %s on all servers\n",
5077 xdr_free((xdrproc_t) xdr_nbulkentries, &arrayEntries);
5082 PrintInt64Size(afs_uint64 in)
5086 static char output[16];
5088 SplitInt64(in,hi,lo);
5092 } else if (!(hi & 0xFFFFFC00)) {
5094 lo = (hi << 22) | (lo >> 10);
5095 } else if (!(hi & 0xFFF00000)) {
5097 lo = (hi << 12) | (lo >> 20);
5098 } else if (!(hi & 0xC0000000)) {
5100 lo = (hi << 2) | (lo >> 30);
5105 sprintf(output,"%u %s", lo, units);
5110 PartitionInfo(struct cmd_syndesc *as, void *arock)
5116 struct diskPartition64 partition;
5117 struct partList dummyPartList;
5119 int printSummary=0, sumPartitions=0;
5120 afs_uint64 sumFree, sumStorage;
5123 ZeroInt64(sumStorage);
5125 aserver = GetServer(as->parms[0].items->data);
5127 fprintf(STDERR, "vos: server '%s' not found in host table\n",
5128 as->parms[0].items->data);
5131 if (as->parms[1].items) {
5132 apart = volutil_GetPartitionID(as->parms[1].items->data);
5134 fprintf(STDERR, "vos: could not interpret partition name '%s'\n",
5135 as->parms[1].items->data);
5138 dummyPartList.partId[0] = apart;
5139 dummyPartList.partFlags[0] = PARTVALID;
5142 if (as->parms[2].items) {
5146 if (!IsPartValid(apart, aserver, &code)) { /*check for validity of the partition */
5148 PrintError("", code);
5151 "vos : partition %s does not exist on the server\n",
5152 as->parms[1].items->data);
5156 code = UV_ListPartitions(aserver, &dummyPartList, &cnt);
5158 PrintDiagnostics("listpart", code);
5162 for (i = 0; i < cnt; i++) {
5163 if (dummyPartList.partFlags[i] & PARTVALID) {
5164 MapPartIdIntoName(dummyPartList.partId[i], pname);
5165 code = UV_PartitionInfo64(aserver, pname, &partition);
5167 fprintf(STDERR, "Could not get information on partition %s\n",
5169 PrintError("", code);
5173 "Free space on partition %s: %" AFS_INT64_FMT " K blocks out of total %" AFS_INT64_FMT "\n",
5174 pname, partition.free, partition.minFree);
5176 AddUInt64(sumFree,partition.free,&sumFree);
5177 AddUInt64(sumStorage,partition.minFree,&sumStorage);
5182 "Summary: %s free out of ",
5183 PrintInt64Size(sumFree));
5185 "%s on %d partitions\n",
5186 PrintInt64Size(sumStorage),
5193 ChangeAddr(struct cmd_syndesc *as, void *arock)
5195 afs_int32 ip1, ip2, vcode;
5199 ip1 = GetServerNoresolve(as->parms[0].items->data);
5201 ip1 = GetServer(as->parms[0].items->data);
5203 fprintf(STDERR, "vos: invalid host address\n");
5207 if ((as->parms[1].items && as->parms[2].items)
5208 || (!as->parms[1].items && !as->parms[2].items)) {
5210 "vos: Must specify either '-newaddr <addr>' or '-remove' flag\n");
5214 if (as->parms[1].items) {
5216 ip2 = GetServerNoresolve(as->parms[1].items->data);
5218 ip2 = GetServer(as->parms[1].items->data);
5220 fprintf(STDERR, "vos: invalid host address\n");
5224 /* Play a trick here. If we are removing an address, ip1 will be -1
5225 * and ip2 will be the original address. This switch prevents an
5226 * older revision vlserver from removing the IP address.
5233 vcode = ubik_VL_ChangeAddr(cstruct, UBIK_CALL_NEW, ntohl(ip1), ntohl(ip2));
5235 char hoststr1[16], hoststr2[16];
5237 afs_inet_ntoa_r(ip2, hoststr2);
5238 fprintf(STDERR, "Could not remove server %s from the VLDB\n",
5240 if (vcode == VL_NOENT) {
5242 "vlserver does not support the remove flag or ");
5245 afs_inet_ntoa_r(ip1, hoststr1);
5246 afs_inet_ntoa_r(ip2, hoststr2);
5247 fprintf(STDERR, "Could not change server %s to server %s\n",
5248 hoststr1, hoststr2);
5250 PrintError("", vcode);
5255 fprintf(STDOUT, "Removed server %s from the VLDB\n",
5256 as->parms[0].items->data);
5258 fprintf(STDOUT, "Changed server %s to server %s\n",
5259 as->parms[0].items->data, as->parms[1].items->data);
5265 print_addrs(const bulkaddrs * addrs, afsUUID * m_uuid, int nentries,
5273 afsUUID_to_string(m_uuid, buf, sizeof(buf));
5274 printf("UUID: %s\n", buf);
5277 /* print out the list of all the server */
5278 addrp = (afs_uint32 *) addrs->bulkaddrs_val;
5279 for (i = 0; i < nentries; i++, addrp++) {
5280 *addrp = htonl(*addrp);
5283 printf("%s\n", afs_inet_ntoa_r(*addrp, hoststr));
5285 printf("%s\n", hostutil_GetNameByINet(*addrp));
5296 ListAddrs(struct cmd_syndesc *as, void *arock)
5298 afs_int32 vcode, m_uniq=0;
5299 afs_int32 i, printuuid = 0;
5300 struct VLCallBack vlcb;
5303 ListAddrByAttributes m_attrs;
5304 afsUUID m_uuid, askuuid;
5305 afs_int32 m_nentries;
5307 if (as->parms[0].items && as->parms[1].items) {
5308 fprintf(STDERR, "vos: Can't use the -uuid and -host flags together\n");
5312 memset(&m_attrs, 0, sizeof(struct ListAddrByAttributes));
5313 memset(&askuuid, 0, sizeof(afsUUID));
5314 if (as->parms[0].items) {
5316 if (afsUUID_from_string(as->parms[0].items->data, &askuuid) < 0) {
5317 fprintf(STDERR, "vos: invalid UUID '%s'\n",
5318 as->parms[0].items->data);
5321 m_attrs.Mask = VLADDR_UUID;
5322 m_attrs.uuid = askuuid;
5323 } else if (as->parms[1].items) {
5327 he = hostutil_GetHostByName((char *)as->parms[1].items->data);
5329 fprintf(STDERR, "vos: Can't get host info for '%s'\n",
5330 as->parms[1].items->data);
5333 memcpy(&saddr, he->h_addr, 4);
5334 m_attrs.Mask = VLADDR_IPADDR;
5335 m_attrs.ipaddr = ntohl(saddr);
5338 m_attrs.Mask = VLADDR_INDEX;
5341 if (as->parms[2].items) {
5345 memset(&m_addrs, 0, sizeof(bulkaddrs));
5346 memset(&vlcb, 0, sizeof(struct VLCallBack));
5349 ubik_VL_GetAddrs(cstruct, UBIK_CALL_NEW, 0, 0, &vlcb, &nentries,
5352 fprintf(STDERR, "vos: could not list the server addresses\n");
5353 PrintError("", vcode);
5357 for (i = 1, m_nentries = 0; nentries; i++) {
5360 xdr_free((xdrproc_t)xdr_bulkaddrs, &m_addrs); /* reset addr list */
5362 ubik_VL_GetAddrsU(cstruct, UBIK_CALL_NEW, &m_attrs, &m_uuid,
5363 &m_uniq, &m_nentries, &m_addrs);
5365 case 0: /* success */
5366 print_addrs(&m_addrs, &m_uuid, m_nentries, printuuid);
5371 if (m_attrs.Mask == VLADDR_UUID) {
5372 fprintf(STDERR, "vos: no entry for UUID '%s' found in VLDB\n",
5373 as->parms[0].items->data);
5375 } else if (m_attrs.Mask == VLADDR_IPADDR) {
5376 fprintf(STDERR, "vos: no entry for host '%s' [0x%08x] found in VLDB\n",
5377 as->parms[1].items->data, m_attrs.ipaddr);
5382 case VL_INDEXERANGE:
5383 vcode = 0; /* not an error, just means we're done */
5386 default: /* any other error */
5387 fprintf(STDERR, "vos: could not list the server addresses\n");
5388 PrintError("", vcode);
5392 /* if -uuid or -host, only list one response */
5393 if (as->parms[1].items || as->parms[0].items)
5398 xdr_free((xdrproc_t)xdr_bulkaddrs, &m_addrs);
5404 SetAddrs(struct cmd_syndesc *as, void *arock)
5409 afs_uint32 FS_HostAddrs_HBO[ADDRSPERSITE];
5411 memset(&m_addrs, 0, sizeof(bulkaddrs));
5412 memset(&askuuid, 0, sizeof(afsUUID));
5413 if (as->parms[0].items) {
5415 if (afsUUID_from_string(as->parms[0].items->data, &askuuid) < 0) {
5416 fprintf(STDERR, "vos: invalid UUID '%s'\n",
5417 as->parms[0].items->data);
5421 if (as->parms[1].items) {
5423 struct cmd_item *ti;
5427 for (ti = as->parms[1].items; ti && i < ADDRSPERSITE; ti = ti->next) {
5430 saddr = GetServerNoresolve(ti->data);
5432 saddr = GetServer(ti->data);
5435 fprintf(STDERR, "vos: Can't get host info for '%s'\n",
5439 /* Convert it to host byte order */
5440 FS_HostAddrs_HBO[i] = ntohl(saddr);
5443 m_addrs.bulkaddrs_len = i;
5444 m_addrs.bulkaddrs_val = FS_HostAddrs_HBO;
5447 vcode = ubik_VL_RegisterAddrs(cstruct, 0, &askuuid, 0, &m_addrs);
5450 if (vcode == VL_MULTIPADDR) {
5451 fprintf(STDERR, "vos: VL_RegisterAddrs rpc failed; The IP address exists on a different server; repair it\n");
5452 } else if (vcode == RXGEN_OPCODE) {
5453 fprintf(STDERR, "vlserver doesn't support VL_RegisterAddrs rpc; ignored\n");
5455 fprintf(STDERR, "vos: VL_RegisterAddrs rpc failed\n");
5457 PrintError("", vcode);
5461 fprintf(STDOUT, "vos: Changed UUID with addresses:\n");
5462 print_addrs(&m_addrs, &askuuid, m_addrs.bulkaddrs_len, 1);
5468 LockEntry(struct cmd_syndesc *as, void *arock)
5471 afs_int32 vcode, err;
5473 avolid = vsu_GetVolumeID(as->parms[0].items->data, cstruct, &err);
5476 PrintError("", err);
5478 fprintf(STDERR, "vos: can't find volume '%s'\n",
5479 as->parms[0].items->data);
5482 vcode = ubik_VL_SetLock(cstruct, 0, avolid, -1, VLOP_DELETE);
5484 fprintf(STDERR, "Could not lock VLDB entry for volume %s\n",
5485 as->parms[0].items->data);
5486 PrintError("", vcode);
5489 fprintf(STDOUT, "Locked VLDB entry for volume %s\n",
5490 as->parms[0].items->data);
5495 ConvertRO(struct cmd_syndesc *as, void *arock)
5497 afs_int32 partition = -1;
5500 afs_int32 code, i, same;
5501 struct nvldbentry entry, checkEntry, storeEntry;
5503 afs_int32 rwindex = 0;
5504 afs_uint32 rwserver = 0;
5505 afs_int32 rwpartition = 0;
5506 afs_int32 roindex = 0;
5507 afs_uint32 roserver = 0;
5508 afs_int32 ropartition = 0;
5510 struct rx_connection *aconn;
5513 server = GetServer(as->parms[0].items->data);
5515 fprintf(STDERR, "vos: host '%s' not found in host table\n",
5516 as->parms[0].items->data);
5519 partition = volutil_GetPartitionID(as->parms[1].items->data);
5520 if (partition < 0) {
5521 fprintf(STDERR, "vos: could not interpret partition name '%s'\n",
5522 as->parms[1].items->data);
5525 if (!IsPartValid(partition, server, &code)) {
5527 PrintError("", code);
5530 "vos : partition %s does not exist on the server\n",
5531 as->parms[1].items->data);
5534 volid = vsu_GetVolumeID(as->parms[2].items->data, cstruct, &code);
5537 PrintError("", code);
5539 fprintf(STDERR, "Unknown volume ID or name '%s'\n",
5540 as->parms[2].items->data);
5543 if (as->parms[3].items)
5546 memset(&entry, 0, sizeof(entry));
5547 vcode = VLDB_GetEntryByID(volid, -1, &entry);
5550 "Could not fetch the entry for volume %lu from VLDB\n",
5551 (unsigned long)volid);
5552 PrintError("convertROtoRW ", vcode);
5556 /* use RO volid even if user specified RW or BK volid */
5557 if (volid != entry.volumeId[ROVOL])
5558 volid = entry.volumeId[ROVOL];
5560 MapHostToNetwork(&entry);
5561 for (i = 0; i < entry.nServers; i++) {
5562 if (entry.serverFlags[i] & ITSRWVOL) {
5564 rwserver = entry.serverNumber[i];
5565 rwpartition = entry.serverPartition[i];
5568 } else if ((entry.serverFlags[i] & ITSROVOL) && !roserver) {
5569 same = VLDB_IsSameAddrs(server, entry.serverNumber[i], &code);
5572 "Failed to get info about server's %d address(es) from vlserver (err=%d); aborting call!\n",
5578 roserver = entry.serverNumber[i];
5579 ropartition = entry.serverPartition[i];
5586 fprintf(STDERR, "Warning: RO volume didn't exist in vldb!\n");
5588 if (roserver && (ropartition != partition)) {
5590 "Warning: RO volume should be in partition %d instead of %d (vldb)\n",
5591 ropartition, partition);
5596 "VLDB indicates that a RW volume exists already on %s in partition %s.\n",
5597 hostutil_GetNameByINet(rwserver),
5598 volutil_PartitionName(rwpartition));
5600 fprintf(STDERR, "Overwrite this VLDB entry? [y|n] (n)\n");
5602 while (!(dc == EOF || dc == '\n'))
5603 dc = getchar(); /* goto end of line */
5604 if ((c != 'y') && (c != 'Y')) {
5605 fprintf(STDERR, "aborted.\n");
5612 ubik_VL_SetLock(cstruct, 0, entry.volumeId[RWVOL], RWVOL,
5616 "Unable to lock volume %lu, code %d\n",
5617 (unsigned long)entry.volumeId[RWVOL],vcode);
5618 PrintError("", vcode);
5622 /* make sure the VLDB entry hasn't changed since we started */
5623 memset(&checkEntry, 0, sizeof(checkEntry));
5624 vcode = VLDB_GetEntryByID(volid, -1, &checkEntry);
5627 "Could not fetch the entry for volume %lu from VLDB\n",
5628 (unsigned long)volid);
5629 PrintError("convertROtoRW ", vcode);
5634 MapHostToNetwork(&checkEntry);
5635 entry.flags &= ~VLOP_ALLOPERS; /* clear any stale lock operation flags */
5636 entry.flags |= VLOP_MOVE; /* set to match SetLock operation above */
5637 if (memcmp(&entry, &checkEntry, sizeof(entry)) != 0) {
5639 "VLDB entry for volume %lu has changed; please reissue the command.\n",
5640 (unsigned long)volid);
5645 aconn = UV_Bind(server, AFSCONF_VOLUMEPORT);
5646 code = AFSVolConvertROtoRWvolume(aconn, partition, volid);
5649 "Converting RO volume %lu to RW volume failed with code %d\n",
5650 (unsigned long)volid, code);
5651 PrintError("convertROtoRW ", code);
5654 /* Update the VLDB to match what we did on disk as much as possible. */
5655 /* If the converted RO was in the VLDB, make it look like the new RW. */
5657 entry.serverFlags[roindex] = ITSRWVOL;
5659 /* Add a new site entry for the newly created RW. It's possible
5660 * (but unlikely) that we are already at MAXNSERVERS and that this
5661 * new site will invalidate the whole VLDB entry; however,
5662 * VLDB_ReplaceEntry will detect this and return VL_BADSERVER,
5663 * so we need no extra guard logic here.
5665 afs_int32 newrwindex = entry.nServers;
5667 entry.serverNumber[newrwindex] = server;
5668 entry.serverPartition[newrwindex] = partition;
5669 entry.serverFlags[newrwindex] = ITSRWVOL;
5671 entry.flags |= RW_EXISTS;
5672 entry.flags &= ~BACK_EXISTS;
5674 /* if the old RW was in the VLDB, remove it by decrementing the number */
5675 /* of servers, replacing the RW entry with the last entry, and zeroing */
5676 /* out the last entry. */
5679 if (rwindex != entry.nServers) {
5680 entry.serverNumber[rwindex] = entry.serverNumber[entry.nServers];
5681 entry.serverPartition[rwindex] =
5682 entry.serverPartition[entry.nServers];
5683 entry.serverFlags[rwindex] = entry.serverFlags[entry.nServers];
5684 entry.serverNumber[entry.nServers] = 0;
5685 entry.serverPartition[entry.nServers] = 0;
5686 entry.serverFlags[entry.nServers] = 0;
5689 entry.flags &= ~RO_EXISTS;
5690 for (i = 0; i < entry.nServers; i++) {
5691 if (entry.serverFlags[i] & ITSROVOL) {
5692 if (!(entry.serverFlags[i] & (RO_DONTUSE | NEW_REPSITE)))
5693 entry.flags |= RO_EXISTS;
5696 MapNetworkToHost(&entry, &storeEntry);
5698 VLDB_ReplaceEntry(entry.volumeId[RWVOL], RWVOL, &storeEntry,
5699 (LOCKREL_OPCODE | LOCKREL_AFSID |
5700 LOCKREL_TIMESTAMP));
5703 "Warning: volume converted, but vldb update failed with code %d!\n",
5708 vcode = UV_LockRelease(entry.volumeId[RWVOL]);
5711 "Unable to unlock volume %lu, code %d\n",
5712 (unsigned long)entry.volumeId[RWVOL],vcode);
5713 PrintError("", vcode);
5719 Sizes(struct cmd_syndesc *as, void *arock)
5723 afs_int32 apart, voltype, fromdate = 0, code, err, i;
5724 struct nvldbentry entry;
5725 volintSize vol_size;
5727 rx_SetRxDeadTime(60 * 10);
5728 for (i = 0; i < MAXSERVERS; i++) {
5729 struct rx_connection *rxConn = ubik_GetRPCConn(cstruct, i);
5732 rx_SetConnDeadTime(rxConn, rx_connDeadTime);
5733 if (rx_ServiceOf(rxConn))
5734 rx_ServiceOf(rxConn)->connDeadTime = rx_connDeadTime;
5737 avolid = vsu_GetVolumeID(as->parms[0].items->data, cstruct, &err);
5740 PrintError("", err);
5742 fprintf(STDERR, "vos: can't find volume '%s'\n",
5743 as->parms[0].items->data);
5747 if (as->parms[1].items || as->parms[2].items) {
5748 if (!as->parms[1].items || !as->parms[2].items) {
5750 "Must specify both -server and -partition options\n");
5753 aserver = GetServer(as->parms[2].items->data);
5755 fprintf(STDERR, "Invalid server name\n");
5758 apart = volutil_GetPartitionID(as->parms[1].items->data);
5760 fprintf(STDERR, "Invalid partition name\n");
5764 code = GetVolumeInfo(avolid, &aserver, &apart, &voltype, &entry);
5771 if (as->parms[4].items && strcmp(as->parms[4].items->data, "0")) {
5772 code = ktime_DateToInt32(as->parms[4].items->data, &fromdate);
5774 fprintf(STDERR, "vos: failed to parse date '%s' (error=%d))\n",
5775 as->parms[4].items->data, code);
5780 fprintf(STDOUT, "Volume: %s\n", as->parms[0].items->data);
5782 if (as->parms[3].items) { /* do the dump estimate */
5783 vol_size.dump_size = 0;
5784 code = UV_GetSize(avolid, aserver, apart, fromdate, &vol_size);
5786 PrintDiagnostics("size", code);
5789 /* presumably the size info is now gathered in pntr */
5790 /* now we display it */
5792 fprintf(STDOUT, "dump_size: %llu\n", vol_size.dump_size);
5801 EndTrans(struct cmd_syndesc *as, void *arock)
5804 afs_int32 code, tid, rcode;
5805 struct rx_connection *aconn;
5807 server = GetServer(as->parms[0].items->data);
5809 fprintf(STDERR, "vos: host '%s' not found in host table\n",
5810 as->parms[0].items->data);
5814 code = util_GetInt32(as->parms[1].items->data, &tid);
5816 fprintf(STDERR, "vos: bad integer specified for transaction ID.\n");
5820 aconn = UV_Bind(server, AFSCONF_VOLUMEPORT);
5821 code = AFSVolEndTrans(aconn, tid, &rcode);
5827 PrintDiagnostics("endtrans", code);
5835 PrintDiagnostics(char *astring, afs_int32 acode)
5837 if (acode == EACCES) {
5839 "You are not authorized to perform the 'vos %s' command (%d)\n",
5842 fprintf(STDERR, "Error in vos %s command.\n", astring);
5843 PrintError("", acode);
5851 win32_enableCrypt(void)
5858 /* Look up configuration parameters in Registry */
5859 code = RegOpenKeyEx(HKEY_LOCAL_MACHINE, AFSREG_CLT_SVC_PARAM_SUBKEY,
5860 0, (IsWow64()?KEY_WOW64_64KEY:0)|KEY_QUERY_VALUE, &parmKey);
5861 if (code != ERROR_SUCCESS) {
5862 dummyLen = sizeof(cryptall);
5863 RegQueryValueEx(parmKey, "SecurityLevel", NULL, NULL,
5864 (BYTE *) &cryptall, &dummyLen);
5866 RegCloseKey (parmKey);
5870 #endif /* AFS_NT40_ENV */
5873 MyBeforeProc(struct cmd_syndesc *as, void *arock)
5879 /* Initialize the ubik_client connection */
5880 rx_SetRxDeadTime(90);
5882 secFlags = AFSCONF_SECOPTS_FALLBACK_NULL;
5885 if (as->parms[12].items) /* if -cell specified */
5886 tcell = as->parms[12].items->data;
5888 if (as->parms[13].items)
5889 secFlags |= AFSCONF_SECOPTS_NOAUTH;
5891 if (as->parms[14].items) { /* -localauth specified */
5892 secFlags |= AFSCONF_SECOPTS_LOCALAUTH;
5893 confdir = AFSDIR_SERVER_ETC_DIRPATH;
5896 if (as->parms[16].items /* -encrypt specified */
5898 || win32_enableCrypt()
5899 #endif /* AFS_NT40_ENV */
5901 secFlags |= AFSCONF_SECOPTS_ALWAYSENCRYPT;
5903 if (as->parms[18].items) /* -config flag set */
5904 confdir = as->parms[18].items->data;
5906 if ((code = vsu_ClientInit(confdir, tcell, secFlags, UV_SetSecurity,
5908 fprintf(STDERR, "could not initialize VLDB library (code=%lu) \n",
5909 (unsigned long)code);
5913 if (as->parms[15].items) /* -verbose flag set */
5917 if (as->parms[17].items) /* -noresolve flag set */
5928 /* this sucks but it works for now.
5933 #include "AFS_component_version_number.c"
5936 main(int argc, char **argv)
5940 struct cmd_syndesc *ts;
5942 #ifdef AFS_AIX32_ENV
5944 * The following signal action for AIX is necessary so that in case of a
5945 * crash (i.e. core is generated) we can include the user's data section
5946 * in the core dump. Unfortunately, by default, only a partial core is
5947 * generated which, in many cases, isn't too useful.
5949 struct sigaction nsa;
5951 sigemptyset(&nsa.sa_mask);
5952 nsa.sa_handler = SIG_DFL;
5953 nsa.sa_flags = SA_FULLDUMP;
5954 sigaction(SIGSEGV, &nsa, NULL);
5957 confdir = AFSDIR_CLIENT_ETC_DIRPATH;
5959 cmd_SetBeforeProc(MyBeforeProc, NULL);
5961 ts = cmd_CreateSyntax("create", CreateVolume, NULL, "create a new volume");
5962 cmd_AddParm(ts, "-server", CMD_SINGLE, 0, "machine name");
5963 cmd_AddParm(ts, "-partition", CMD_SINGLE, 0, "partition name");
5964 cmd_AddParm(ts, "-name", CMD_SINGLE, 0, "volume name");
5965 cmd_AddParm(ts, "-maxquota", CMD_SINGLE, CMD_OPTIONAL,
5966 "initial quota (KB)");
5967 cmd_AddParm(ts, "-id", CMD_SINGLE, CMD_OPTIONAL, "volume ID");
5968 cmd_AddParm(ts, "-roid", CMD_SINGLE, CMD_OPTIONAL, "readonly volume ID");
5970 cmd_AddParm(ts, "-minquota", CMD_SINGLE, CMD_OPTIONAL, "");
5974 ts = cmd_CreateSyntax("remove", DeleteVolume, NULL, "delete a volume");
5975 cmd_AddParm(ts, "-server", CMD_SINGLE, CMD_OPTIONAL, "machine name");
5976 cmd_AddParm(ts, "-partition", CMD_SINGLE, CMD_OPTIONAL, "partition name");
5977 cmd_AddParm(ts, "-id", CMD_SINGLE, 0, "volume name or ID");
5981 ts = cmd_CreateSyntax("move", MoveVolume, NULL, "move a volume");
5982 cmd_AddParm(ts, "-id", CMD_SINGLE, 0, "volume name or ID");
5983 cmd_AddParm(ts, "-fromserver", CMD_SINGLE, 0, "machine name on source");
5984 cmd_AddParm(ts, "-frompartition", CMD_SINGLE, 0,
5985 "partition name on source");
5986 cmd_AddParm(ts, "-toserver", CMD_SINGLE, 0,
5987 "machine name on destination");
5988 cmd_AddParm(ts, "-topartition", CMD_SINGLE, 0,
5989 "partition name on destination");
5990 cmd_AddParm(ts, "-live", CMD_FLAG, CMD_OPTIONAL,
5991 "copy live volume without cloning");
5994 ts = cmd_CreateSyntax("copy", CopyVolume, NULL, "copy a volume");
5995 cmd_AddParm(ts, "-id", CMD_SINGLE, 0, "volume name or ID on source");
5996 cmd_AddParm(ts, "-fromserver", CMD_SINGLE, 0, "machine name on source");
5997 cmd_AddParm(ts, "-frompartition", CMD_SINGLE, 0,
5998 "partition name on source");
5999 cmd_AddParm(ts, "-toname", CMD_SINGLE, 0, "volume name on destination");
6000 cmd_AddParm(ts, "-toserver", CMD_SINGLE, 0,
6001 "machine name on destination");
6002 cmd_AddParm(ts, "-topartition", CMD_SINGLE, 0,
6003 "partition name on destination");
6004 cmd_AddParm(ts, "-offline", CMD_FLAG, CMD_OPTIONAL,
6005 "leave new volume offline");
6006 cmd_AddParm(ts, "-readonly", CMD_FLAG, CMD_OPTIONAL,
6007 "make new volume read-only");
6008 cmd_AddParm(ts, "-live", CMD_FLAG, CMD_OPTIONAL,
6009 "copy live volume without cloning");
6012 ts = cmd_CreateSyntax("shadow", ShadowVolume, NULL,
6013 "make or update a shadow volume");
6014 cmd_AddParm(ts, "-id", CMD_SINGLE, 0, "volume name or ID on source");
6015 cmd_AddParm(ts, "-fromserver", CMD_SINGLE, 0, "machine name on source");
6016 cmd_AddParm(ts, "-frompartition", CMD_SINGLE, 0,
6017 "partition name on source");
6018 cmd_AddParm(ts, "-toserver", CMD_SINGLE, 0,
6019 "machine name on destination");
6020 cmd_AddParm(ts, "-topartition", CMD_SINGLE, 0,
6021 "partition name on destination");
6022 cmd_AddParm(ts, "-toname", CMD_SINGLE, CMD_OPTIONAL,
6023 "volume name on destination");
6024 cmd_AddParm(ts, "-toid", CMD_SINGLE, CMD_OPTIONAL,
6025 "volume ID on destination");
6026 cmd_AddParm(ts, "-offline", CMD_FLAG, CMD_OPTIONAL,
6027 "leave shadow volume offline");
6028 cmd_AddParm(ts, "-readonly", CMD_FLAG, CMD_OPTIONAL,
6029 "make shadow volume read-only");
6030 cmd_AddParm(ts, "-live", CMD_FLAG, CMD_OPTIONAL,
6031 "copy live volume without cloning");
6032 cmd_AddParm(ts, "-incremental", CMD_FLAG, CMD_OPTIONAL,
6033 "do incremental update if target exists");
6036 ts = cmd_CreateSyntax("backup", BackupVolume, NULL,
6037 "make backup of a volume");
6038 cmd_AddParm(ts, "-id", CMD_SINGLE, 0, "volume name or ID");
6041 ts = cmd_CreateSyntax("clone", CloneVolume, NULL,
6042 "make clone of a volume");
6043 cmd_AddParm(ts, "-id", CMD_SINGLE, 0, "volume name or ID");
6044 cmd_AddParm(ts, "-server", CMD_SINGLE, CMD_OPTIONAL, "server");
6045 cmd_AddParm(ts, "-partition", CMD_SINGLE, CMD_OPTIONAL, "partition");
6046 cmd_AddParm(ts, "-toname", CMD_SINGLE, CMD_OPTIONAL,
6047 "volume name on destination");
6048 cmd_AddParm(ts, "-toid", CMD_SINGLE, CMD_OPTIONAL,
6049 "volume ID on destination");
6050 cmd_AddParm(ts, "-offline", CMD_FLAG, CMD_OPTIONAL,
6051 "leave clone volume offline");
6052 cmd_AddParm(ts, "-readonly", CMD_FLAG, CMD_OPTIONAL,
6053 "make clone volume read-only, not readwrite");
6054 cmd_AddParm(ts, "-readwrite", CMD_FLAG, CMD_OPTIONAL,
6055 "make clone volume readwrite, not read-only");
6058 ts = cmd_CreateSyntax("release", ReleaseVolume, NULL, "release a volume");
6059 cmd_AddParm(ts, "-id", CMD_SINGLE, 0, "volume name or ID");
6060 cmd_AddParm(ts, "-force", CMD_FLAG, CMD_OPTIONAL,
6061 "force a complete release");
6062 cmd_AddParm(ts, "-stayonline", CMD_FLAG, CMD_OPTIONAL,
6063 "release to cloned temp vol, then clone back to repsite RO");
6066 ts = cmd_CreateSyntax("dump", DumpVolumeCmd, NULL, "dump a volume");
6067 cmd_AddParm(ts, "-id", CMD_SINGLE, 0, "volume name or ID");
6068 cmd_AddParm(ts, "-time", CMD_SINGLE, CMD_OPTIONAL, "dump from time");
6069 cmd_AddParm(ts, "-file", CMD_SINGLE, CMD_OPTIONAL, "dump file");
6070 cmd_AddParm(ts, "-server", CMD_SINGLE, CMD_OPTIONAL, "server");
6071 cmd_AddParm(ts, "-partition", CMD_SINGLE, CMD_OPTIONAL, "partition");
6072 cmd_AddParm(ts, "-clone", CMD_FLAG, CMD_OPTIONAL,
6073 "dump a clone of the volume");
6074 cmd_AddParm(ts, "-omitdirs", CMD_FLAG, CMD_OPTIONAL,
6075 "omit unchanged directories from an incremental dump");
6078 ts = cmd_CreateSyntax("restore", RestoreVolumeCmd, NULL,
6079 "restore a volume");
6080 cmd_AddParm(ts, "-server", CMD_SINGLE, 0, "machine name");
6081 cmd_AddParm(ts, "-partition", CMD_SINGLE, 0, "partition name");
6082 cmd_AddParm(ts, "-name", CMD_SINGLE, 0, "name of volume to be restored");
6083 cmd_AddParm(ts, "-file", CMD_SINGLE, CMD_OPTIONAL, "dump file");
6084 cmd_AddParm(ts, "-id", CMD_SINGLE, CMD_OPTIONAL, "volume ID");
6085 cmd_AddParm(ts, "-overwrite", CMD_SINGLE, CMD_OPTIONAL,
6086 "abort | full | incremental");
6087 cmd_AddParm(ts, "-offline", CMD_FLAG, CMD_OPTIONAL,
6088 "leave restored volume offline");
6089 cmd_AddParm(ts, "-readonly", CMD_FLAG, CMD_OPTIONAL,
6090 "make restored volume read-only");
6091 cmd_AddParm(ts, "-creation", CMD_SINGLE, CMD_OPTIONAL,
6092 "dump | keep | new");
6093 cmd_AddParm(ts, "-lastupdate", CMD_SINGLE, CMD_OPTIONAL,
6094 "dump | keep | new");
6095 cmd_AddParm(ts, "-nodelete", CMD_FLAG, CMD_OPTIONAL,
6096 "do not delete old site when restoring to a new site");
6099 ts = cmd_CreateSyntax("unlock", LockReleaseCmd, NULL,
6100 "release lock on VLDB entry for a volume");
6101 cmd_AddParm(ts, "-id", CMD_SINGLE, 0, "volume name or ID");
6104 ts = cmd_CreateSyntax("changeloc", ChangeLocation, NULL,
6105 "change an RW volume's location in the VLDB");
6106 cmd_AddParm(ts, "-server", CMD_SINGLE, 0,
6107 "machine name for new location");
6108 cmd_AddParm(ts, "-partition", CMD_SINGLE, 0,
6109 "partition name for new location");
6110 cmd_AddParm(ts, "-id", CMD_SINGLE, 0, "volume name or ID");
6113 ts = cmd_CreateSyntax("addsite", AddSite, NULL, "add a replication site");
6114 cmd_AddParm(ts, "-server", CMD_SINGLE, 0, "machine name for new site");
6115 cmd_AddParm(ts, "-partition", CMD_SINGLE, 0,
6116 "partition name for new site");
6117 cmd_AddParm(ts, "-id", CMD_SINGLE, 0, "volume name or ID");
6118 cmd_AddParm(ts, "-roid", CMD_SINGLE, CMD_OPTIONAL, "volume name or ID for RO");
6119 cmd_AddParm(ts, "-valid", CMD_FLAG, CMD_OPTIONAL, "publish as an up-to-date site in VLDB");
6122 ts = cmd_CreateSyntax("remsite", RemoveSite, NULL,
6123 "remove a replication site");
6124 cmd_AddParm(ts, "-server", CMD_SINGLE, 0, "machine name");
6125 cmd_AddParm(ts, "-partition", CMD_SINGLE, 0, "partition name");
6126 cmd_AddParm(ts, "-id", CMD_SINGLE, 0, "volume name or ID");
6129 ts = cmd_CreateSyntax("listpart", ListPartitions, NULL, "list partitions");
6130 cmd_AddParm(ts, "-server", CMD_SINGLE, 0, "machine name");
6133 ts = cmd_CreateSyntax("listvol", ListVolumes, NULL,
6134 "list volumes on server (bypass VLDB)");
6135 cmd_AddParm(ts, "-server", CMD_SINGLE, 0, "machine name");
6136 cmd_AddParm(ts, "-partition", CMD_SINGLE, CMD_OPTIONAL, "partition name");
6137 cmd_AddParm(ts, "-fast", CMD_FLAG, CMD_OPTIONAL, "minimal listing");
6138 cmd_AddParm(ts, "-long", CMD_FLAG, CMD_OPTIONAL,
6139 "list all normal volume fields");
6140 cmd_AddParm(ts, "-quiet", CMD_FLAG, CMD_OPTIONAL,
6141 "generate minimal information");
6142 cmd_AddParm(ts, "-extended", CMD_FLAG, CMD_OPTIONAL,
6143 "list extended volume fields");
6144 cmd_AddParm(ts, "-format", CMD_FLAG, CMD_OPTIONAL,
6145 "machine readable format");
6148 ts = cmd_CreateSyntax("syncvldb", SyncVldb, NULL,
6149 "synchronize VLDB with server");
6150 cmd_AddParm(ts, "-server", CMD_SINGLE, CMD_OPTIONAL, "machine name");
6151 cmd_AddParm(ts, "-partition", CMD_SINGLE, CMD_OPTIONAL, "partition name");
6152 cmd_AddParm(ts, "-volume", CMD_SINGLE, CMD_OPTIONAL, "volume name or ID");
6153 cmd_AddParm(ts, "-dryrun", CMD_FLAG, CMD_OPTIONAL, "list what would be done, don't do it");
6156 ts = cmd_CreateSyntax("syncserv", SyncServer, NULL,
6157 "synchronize server with VLDB");
6158 cmd_AddParm(ts, "-server", CMD_SINGLE, 0, "machine name");
6159 cmd_AddParm(ts, "-partition", CMD_SINGLE, CMD_OPTIONAL, "partition name");
6160 cmd_AddParm(ts, "-dryrun", CMD_FLAG, CMD_OPTIONAL, "list what would be done, don't do it");
6163 ts = cmd_CreateSyntax("examine", ExamineVolume, NULL,
6164 "everything about the volume");
6165 cmd_AddParm(ts, "-id", CMD_SINGLE, 0, "volume name or ID");
6166 cmd_AddParm(ts, "-extended", CMD_FLAG, CMD_OPTIONAL,
6167 "list extended volume fields");
6168 cmd_AddParm(ts, "-format", CMD_FLAG, CMD_OPTIONAL,
6169 "machine readable format");
6171 cmd_CreateAlias(ts, "volinfo");
6173 ts = cmd_CreateSyntax("setfields", SetFields, NULL,
6174 "change volume info fields");
6175 cmd_AddParm(ts, "-id", CMD_SINGLE, 0, "volume name or ID");
6176 cmd_AddParm(ts, "-maxquota", CMD_SINGLE, CMD_OPTIONAL, "quota (KB)");
6177 cmd_AddParm(ts, "-clearuse", CMD_FLAG, CMD_OPTIONAL, "clear dayUse");
6178 cmd_AddParm(ts, "-clearVolUpCounter", CMD_FLAG, CMD_OPTIONAL, "clear volUpdateCounter");
6181 ts = cmd_CreateSyntax("offline", volOffline, NULL, "force the volume status to offline");
6182 cmd_AddParm(ts, "-server", CMD_SINGLE, 0, "server name");
6183 cmd_AddParm(ts, "-partition", CMD_SINGLE, 0, "partition name");
6184 cmd_AddParm(ts, "-id", CMD_SINGLE, 0, "volume name or ID");
6185 cmd_AddParm(ts, "-sleep", CMD_SINGLE, CMD_OPTIONAL, "seconds to sleep");
6186 cmd_AddParm(ts, "-busy", CMD_FLAG, CMD_OPTIONAL, "busy volume");
6189 ts = cmd_CreateSyntax("online", volOnline, NULL, "force the volume status to online");
6190 cmd_AddParm(ts, "-server", CMD_SINGLE, 0, "server name");
6191 cmd_AddParm(ts, "-partition", CMD_SINGLE, 0, "partition name");
6192 cmd_AddParm(ts, "-id", CMD_SINGLE, 0, "volume name or ID");
6195 ts = cmd_CreateSyntax("zap", VolumeZap, NULL,
6196 "delete the volume, don't bother with VLDB");
6197 cmd_AddParm(ts, "-server", CMD_SINGLE, 0, "machine name");
6198 cmd_AddParm(ts, "-partition", CMD_SINGLE, 0, "partition name");
6199 cmd_AddParm(ts, "-id", CMD_SINGLE, 0, "volume ID");
6200 cmd_AddParm(ts, "-force", CMD_FLAG, CMD_OPTIONAL,
6201 "force deletion of bad volumes");
6202 cmd_AddParm(ts, "-backup", CMD_FLAG, CMD_OPTIONAL,
6203 "also delete backup volume if one is found");
6206 ts = cmd_CreateSyntax("status", VolserStatus, NULL,
6207 "report on volser status");
6208 cmd_AddParm(ts, "-server", CMD_SINGLE, 0, "machine name");
6211 ts = cmd_CreateSyntax("rename", RenameVolume, NULL, "rename a volume");
6212 cmd_AddParm(ts, "-oldname", CMD_SINGLE, 0, "old volume name ");
6213 cmd_AddParm(ts, "-newname", CMD_SINGLE, 0, "new volume name ");
6216 ts = cmd_CreateSyntax("listvldb", ListVLDB, NULL,
6217 "list volumes in the VLDB");
6218 cmd_AddParm(ts, "-name", CMD_SINGLE, CMD_OPTIONAL, "volume name or ID");
6219 cmd_AddParm(ts, "-server", CMD_SINGLE, CMD_OPTIONAL, "machine name");
6220 cmd_AddParm(ts, "-partition", CMD_SINGLE, CMD_OPTIONAL, "partition name");
6221 cmd_AddParm(ts, "-locked", CMD_FLAG, CMD_OPTIONAL, "locked volumes only");
6222 cmd_AddParm(ts, "-quiet", CMD_FLAG, CMD_OPTIONAL,
6223 "generate minimal information");
6224 cmd_AddParm(ts, "-nosort", CMD_FLAG, CMD_OPTIONAL,
6225 "do not alphabetically sort the volume names");
6228 ts = cmd_CreateSyntax("backupsys", BackSys, NULL, "en masse backups");
6229 cmd_AddParm(ts, "-prefix", CMD_LIST, CMD_OPTIONAL,
6230 "common prefix on volume(s)");
6231 cmd_AddParm(ts, "-server", CMD_SINGLE, CMD_OPTIONAL, "machine name");
6232 cmd_AddParm(ts, "-partition", CMD_SINGLE, CMD_OPTIONAL, "partition name");
6233 cmd_AddParm(ts, "-exclude", CMD_FLAG, CMD_OPTIONAL,
6234 "exclude common prefix volumes");
6235 cmd_AddParm(ts, "-xprefix", CMD_LIST, CMD_OPTIONAL,
6236 "negative prefix on volume(s)");
6237 cmd_AddParm(ts, "-dryrun", CMD_FLAG, CMD_OPTIONAL, "list what would be done, don't do it");
6240 ts = cmd_CreateSyntax("delentry", DeleteEntry, NULL,
6241 "delete VLDB entry for a volume");
6242 cmd_AddParm(ts, "-id", CMD_LIST, CMD_OPTIONAL, "volume name or ID");
6243 cmd_AddParm(ts, "-prefix", CMD_SINGLE, CMD_OPTIONAL,
6244 "prefix of the volume whose VLDB entry is to be deleted");
6245 cmd_AddParm(ts, "-server", CMD_SINGLE, CMD_OPTIONAL, "machine name");
6246 cmd_AddParm(ts, "-partition", CMD_SINGLE, CMD_OPTIONAL, "partition name");
6247 cmd_AddParm(ts, "-noexecute", CMD_FLAG, CMD_OPTIONAL|CMD_HIDDEN, "");
6248 cmd_AddParm(ts, "-dryrun", CMD_FLAG, CMD_OPTIONAL,
6249 "list what would be done, don't do it");
6252 ts = cmd_CreateSyntax("partinfo", PartitionInfo, NULL,
6253 "list partition information");
6254 cmd_AddParm(ts, "-server", CMD_SINGLE, 0, "machine name");
6255 cmd_AddParm(ts, "-partition", CMD_SINGLE, CMD_OPTIONAL, "partition name");
6256 cmd_AddParm(ts, "-summary", CMD_FLAG, CMD_OPTIONAL,
6257 "print storage summary");
6260 ts = cmd_CreateSyntax("unlockvldb", UnlockVLDB, NULL,
6261 "unlock all the locked entries in the VLDB");
6262 cmd_AddParm(ts, "-server", CMD_SINGLE, CMD_OPTIONAL, "machine name");
6263 cmd_AddParm(ts, "-partition", CMD_SINGLE, CMD_OPTIONAL, "partition name");
6266 ts = cmd_CreateSyntax("lock", LockEntry, NULL,
6267 "lock VLDB entry for a volume");
6268 cmd_AddParm(ts, "-id", CMD_SINGLE, 0, "volume name or ID");
6271 ts = cmd_CreateSyntax("changeaddr", ChangeAddr, NULL,
6272 "change the IP address of a file server");
6273 cmd_AddParm(ts, "-oldaddr", CMD_SINGLE, 0, "original IP address");
6274 cmd_AddParm(ts, "-newaddr", CMD_SINGLE, CMD_OPTIONAL, "new IP address");
6275 cmd_AddParm(ts, "-remove", CMD_FLAG, CMD_OPTIONAL,
6276 "remove the IP address from the VLDB");
6279 ts = cmd_CreateSyntax("listaddrs", ListAddrs, NULL,
6280 "list the IP address of all file servers registered in the VLDB");
6281 cmd_AddParm(ts, "-uuid", CMD_SINGLE, CMD_OPTIONAL, "uuid of server");
6282 cmd_AddParm(ts, "-host", CMD_SINGLE, CMD_OPTIONAL, "address of host");
6283 cmd_AddParm(ts, "-printuuid", CMD_FLAG, CMD_OPTIONAL,
6284 "print uuid of hosts");
6287 ts = cmd_CreateSyntax("convertROtoRW", ConvertRO, NULL,
6288 "convert a RO volume into a RW volume (after loss of old RW volume)");
6289 cmd_AddParm(ts, "-server", CMD_SINGLE, 0, "machine name");
6290 cmd_AddParm(ts, "-partition", CMD_SINGLE, 0, "partition name");
6291 cmd_AddParm(ts, "-id", CMD_SINGLE, 0, "volume name or ID");
6292 cmd_AddParm(ts, "-force", CMD_FLAG, CMD_OPTIONAL, "don't ask");
6295 ts = cmd_CreateSyntax("size", Sizes, NULL,
6296 "obtain various sizes of the volume.");
6297 cmd_AddParm(ts, "-id", CMD_SINGLE, 0, "volume name or ID");
6298 cmd_AddParm(ts, "-partition", CMD_SINGLE, CMD_OPTIONAL, "partition name");
6299 cmd_AddParm(ts, "-server", CMD_SINGLE, CMD_OPTIONAL, "machine name");
6300 cmd_AddParm(ts, "-dump", CMD_FLAG, CMD_OPTIONAL,
6301 "Obtain the size of the dump");
6302 cmd_AddParm(ts, "-time", CMD_SINGLE, CMD_OPTIONAL, "dump from time");
6305 ts = cmd_CreateSyntax("endtrans", EndTrans, NULL,
6306 "end a volserver transaction");
6307 cmd_AddParm(ts, "-server", CMD_SINGLE, 0, "machine name");
6308 cmd_AddParm(ts, "-transaction", CMD_SINGLE, 0,
6312 ts = cmd_CreateSyntax("setaddrs", SetAddrs, NULL,
6313 "set the list of IP address for a given UUID in the VLDB");
6314 cmd_AddParm(ts, "-uuid", CMD_SINGLE, 0, "uuid of server");
6315 cmd_AddParm(ts, "-host", CMD_LIST, 0, "address of host");
6318 code = cmd_Dispatch(argc, argv);
6320 /* Shut down the ubik_client and rx connections */
6322 (void)ubik_ClientDestroy(cstruct);
6328 exit((code ? -1 : 0));