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>
31 #include <rx/rx_globals.h>
33 #include <afs/vlserver.h>
34 #include <afs/cellconfig.h>
36 #include <afs/afsutil.h>
38 #include <afs/afsint.h>
43 #include <afs/ihandle.h>
44 #include <afs/vnode.h>
45 #include <afs/volume.h>
46 #include <afs/com_err.h>
50 #include "volser_internal.h"
51 #include "volser_prototypes.h"
52 #include "vsutils_prototypes.h"
53 #include "lockprocs_prototypes.h"
55 #ifdef HAVE_POSIX_REGEX
59 /* Local Prototypes */
60 int PrintDiagnostics(char *astring, afs_int32 acode);
61 int GetVolumeInfo(afs_uint32 volid, afs_uint32 *server, afs_int32 *part,
62 afs_int32 *voltype, struct nvldbentry *rentry);
74 #define COMMONPARMS cmd_Seek(ts, 12);\
75 cmd_AddParm(ts, "-cell", CMD_SINGLE, CMD_OPTIONAL, "cell name");\
76 cmd_AddParm(ts, "-noauth", CMD_FLAG, CMD_OPTIONAL, "don't authenticate");\
77 cmd_AddParm(ts, "-localauth",CMD_FLAG,CMD_OPTIONAL,"use server tickets");\
78 cmd_AddParm(ts, "-verbose", CMD_FLAG, CMD_OPTIONAL, "verbose");\
79 cmd_AddParm(ts, "-encrypt", CMD_FLAG, CMD_OPTIONAL, "encrypt commands");\
80 cmd_AddParm(ts, "-noresolve", CMD_FLAG, CMD_OPTIONAL, "don't resolve addresses"); \
81 cmd_AddParm(ts, "-config", CMD_SINGLE, CMD_OPTIONAL, "config location"); \
83 #define ERROR_EXIT(code) do { \
89 extern struct ubik_client *cstruct;
92 static struct tqHead busyHead, notokHead;
95 qInit(struct tqHead *ahead)
97 memset(ahead, 0, sizeof(struct tqHead));
103 qPut(struct tqHead *ahead, afs_uint32 volid)
107 elem = malloc(sizeof(struct tqElem));
108 elem->next = ahead->next;
116 qGet(struct tqHead *ahead, afs_uint32 *volid)
120 if (ahead->count <= 0)
122 *volid = ahead->next->volid;
124 ahead->next = tmp->next;
130 /* returns 1 if <filename> exists else 0 */
132 FileExists(char *filename)
138 code = usd_Open(filename, USD_OPEN_RDONLY, 0, &ufd);
142 code = USD_IOCTL(ufd, USD_IOCTL_GETSIZE, &size);
150 /* returns 1 if <name> doesnot end in .readonly or .backup, else 0 */
152 VolNameOK(char *name)
157 total = strlen(name);
158 if (!strcmp(&name[total - 9], ".readonly")) {
160 } else if (!strcmp(&name[total - 7], ".backup")) {
167 /* return 1 if name is a number else 0 */
169 IsNumeric(char *name)
178 for (i = 0; i < len; i++) {
179 if (*ptr < '0' || *ptr > '9') {
191 * Parse a server dotted address and return the address in network byte order
194 GetServerNoresolve(char *aname)
200 code = sscanf(aname, "%d.%d.%d.%d", &b1, &b2, &b3, &b4);
202 addr = (b1 << 24) | (b2 << 16) | (b3 << 8) | b4;
203 addr = htonl(addr); /* convert to network byte order */
209 * Parse a server name/address and return the address in network byte order
212 GetServer(char *aname)
215 afs_uint32 addr; /* in network byte order */
217 char hostname[MAXHOSTCHARS];
219 if ((addr = GetServerNoresolve(aname)) == 0) {
220 th = gethostbyname(aname);
223 memcpy(&addr, th->h_addr, sizeof(addr));
226 if (rx_IsLoopbackAddr(ntohl(addr))) { /* local host */
227 code = gethostname(hostname, MAXHOSTCHARS);
230 th = gethostbyname(hostname);
233 memcpy(&addr, th->h_addr, sizeof(addr));
240 GetVolumeType(char *aname)
243 if (!strcmp(aname, "ro"))
245 else if (!strcmp(aname, "rw"))
247 else if (!strcmp(aname, "bk"))
254 IsPartValid(afs_int32 partId, afs_uint32 server, afs_int32 *code)
256 struct partList dummyPartList;
262 *code = UV_ListPartitions(server, &dummyPartList, &cnt);
265 for (i = 0; i < cnt; i++) {
266 if (dummyPartList.partFlags[i] & PARTVALID)
267 if (dummyPartList.partId[i] == partId)
275 /*sends the contents of file associated with <fd> and <blksize> to Rx Stream
276 * associated with <call> */
278 SendFile(usd_handle_t ufd, struct rx_call *call, long blksize)
280 char *buffer = (char *)0;
285 buffer = malloc(blksize);
287 fprintf(STDERR, "malloc failed\n");
291 while (!error && !done) {
292 #ifndef AFS_NT40_ENV /* NT csn't select on non-socket fd's */
295 FD_SET((intptr_t)(ufd->handle), &in);
296 /* don't timeout if read blocks */
297 #if defined(AFS_PTHREAD_ENV)
298 select(((intptr_t)(ufd->handle)) + 1, &in, 0, 0, 0);
300 IOMGR_Select(((intptr_t)(ufd->handle)) + 1, &in, 0, 0, 0);
303 error = USD_READ(ufd, buffer, blksize, &nbytes);
305 fprintf(STDERR, "File system read failed: %s\n",
306 afs_error_message(error));
313 if (rx_Write(call, buffer, nbytes) != nbytes) {
323 /* function invoked by UV_RestoreVolume, reads the data from rx_trx_stream and
324 * writes it out to the volume. */
326 WriteData(struct rx_call *call, void *rock)
328 char *filename = (char *) rock;
331 afs_int32 error, code;
333 afs_int64 currOffset;
339 if (!filename || !*filename) {
340 usd_StandardInput(&ufd);
344 code = usd_Open(filename, USD_OPEN_RDONLY, 0, &ufd);
347 code = USD_IOCTL(ufd, USD_IOCTL_GETBLKSIZE, &blksize);
350 fprintf(STDERR, "Could not access file '%s': %s\n", filename,
351 afs_error_message(code));
355 /* test if we have a valid dump */
356 USD_SEEK(ufd, 0, SEEK_END, &currOffset);
357 USD_SEEK(ufd, currOffset - sizeof(afs_uint32), SEEK_SET, &currOffset);
358 USD_READ(ufd, (char *)&buffer, sizeof(afs_uint32), &got);
359 if ((got != sizeof(afs_uint32)) || (ntohl(buffer) != DUMPENDMAGIC)) {
360 fprintf(STDERR, "Signature missing from end of file '%s'\n", filename);
364 USD_SEEK(ufd, 0, SEEK_SET, &currOffset);
366 code = SendFile(ufd, call, blksize);
373 code = USD_CLOSE(ufd);
375 fprintf(STDERR, "Could not close dump file %s\n",
376 (filename && *filename) ? filename : "STDOUT");
384 /* Receive data from <call> stream into file associated
385 * with <fd> <blksize>
388 ReceiveFile(usd_handle_t ufd, struct rx_call *call, long blksize)
392 afs_uint32 bytesleft, w;
395 buffer = malloc(blksize);
397 fprintf(STDERR, "memory allocation failed\n");
401 while ((bytesread = rx_Read(call, buffer, blksize)) > 0) {
402 for (bytesleft = bytesread; bytesleft; bytesleft -= w) {
403 #ifndef AFS_NT40_ENV /* NT csn't select on non-socket fd's */
406 FD_SET((intptr_t)(ufd->handle), &out);
407 /* don't timeout if write blocks */
408 #if defined(AFS_PTHREAD_ENV)
409 select(((intptr_t)(ufd->handle)) + 1, &out, 0, 0, 0);
411 IOMGR_Select(((intptr_t)(ufd->handle)) + 1, 0, &out, 0, 0);
415 USD_WRITE(ufd, &buffer[bytesread - bytesleft], bytesleft, &w);
417 fprintf(STDERR, "File system write failed: %s\n",
418 afs_error_message(error));
431 DumpFunction(struct rx_call *call, void *rock)
433 char *filename = (char *)rock;
434 usd_handle_t ufd; /* default is to stdout */
435 afs_int32 error = 0, code;
440 /* Open the output file */
441 if (!filename || !*filename) {
442 usd_StandardOutput(&ufd);
447 usd_Open(filename, USD_OPEN_CREATE | USD_OPEN_RDWR, 0666, &ufd);
451 code = USD_IOCTL(ufd, USD_IOCTL_SETSIZE, &size);
454 code = USD_IOCTL(ufd, USD_IOCTL_GETBLKSIZE, &blksize);
457 fprintf(STDERR, "Could not create file '%s': %s\n", filename,
458 afs_error_message(code));
459 ERROR_EXIT(VOLSERBADOP);
463 code = ReceiveFile(ufd, call, blksize);
468 /* Close the output file */
470 code = USD_CLOSE(ufd);
472 fprintf(STDERR, "Could not close dump file %s\n",
473 (filename && *filename) ? filename : "STDIN");
483 DisplayFormat(volintInfo *pntr, afs_uint32 server, afs_int32 part,
484 int *totalOK, int *totalNotOK, int *totalBusy, int fast,
485 int longlist, int disp)
491 fprintf(STDOUT, "%-10lu\n", (unsigned long)pntr->volid);
492 } else if (longlist) {
493 if (pntr->status == VOK) {
494 fprintf(STDOUT, "%-32s ", pntr->name);
495 fprintf(STDOUT, "%10lu ", (unsigned long)pntr->volid);
497 fprintf(STDOUT, "RW ");
499 fprintf(STDOUT, "RO ");
501 fprintf(STDOUT, "BK ");
502 fprintf(STDOUT, "%10d K ", pntr->size);
503 if (pntr->inUse == 1) {
504 fprintf(STDOUT, "On-line");
507 fprintf(STDOUT, "Off-line");
510 if (pntr->needsSalvaged == 1)
511 fprintf(STDOUT, "**needs salvage**");
512 fprintf(STDOUT, "\n");
513 MapPartIdIntoName(part, pname);
514 fprintf(STDOUT, " %s %s \n", hostutil_GetNameByINet(server),
516 fprintf(STDOUT, " RWrite %10lu ROnly %10lu Backup %10lu \n",
517 (unsigned long)pntr->parentID,
518 (unsigned long)pntr->cloneID,
519 (unsigned long)pntr->backupID);
520 fprintf(STDOUT, " MaxQuota %10d K \n", pntr->maxquota);
521 t = pntr->creationDate;
522 fprintf(STDOUT, " Creation %s",
525 fprintf(STDOUT, " Copy %s",
528 t = pntr->backupDate;
530 fprintf(STDOUT, " Backup Never\n");
532 fprintf(STDOUT, " Backup %s",
535 t = pntr->accessDate;
537 fprintf(STDOUT, " Last Access %s",
540 t = pntr->updateDate;
542 fprintf(STDOUT, " Last Update Never\n");
544 fprintf(STDOUT, " Last Update %s",
547 " %d accesses in the past day (i.e., vnode references)\n",
549 } else if (pntr->status == VBUSY) {
551 qPut(&busyHead, pntr->volid);
553 fprintf(STDOUT, "**** Volume %lu is busy ****\n",
554 (unsigned long)pntr->volid);
557 qPut(¬okHead, pntr->volid);
559 fprintf(STDOUT, "**** Could not attach volume %lu ****\n",
560 (unsigned long)pntr->volid);
562 fprintf(STDOUT, "\n");
563 } else { /* default listing */
564 if (pntr->status == VOK) {
565 fprintf(STDOUT, "%-32s ", pntr->name);
566 fprintf(STDOUT, "%10lu ", (unsigned long)pntr->volid);
568 fprintf(STDOUT, "RW ");
570 fprintf(STDOUT, "RO ");
572 fprintf(STDOUT, "BK ");
573 fprintf(STDOUT, "%10d K ", pntr->size);
574 if (pntr->inUse == 1) {
575 fprintf(STDOUT, "On-line");
578 fprintf(STDOUT, "Off-line");
581 if (pntr->needsSalvaged == 1)
582 fprintf(STDOUT, "**needs salvage**");
583 fprintf(STDOUT, "\n");
584 } else if (pntr->status == VBUSY) {
586 qPut(&busyHead, pntr->volid);
588 fprintf(STDOUT, "**** Volume %lu is busy ****\n",
589 (unsigned long)pntr->volid);
592 qPut(¬okHead, pntr->volid);
594 fprintf(STDOUT, "**** Could not attach volume %lu ****\n",
595 (unsigned long)pntr->volid);
600 /*------------------------------------------------------------------------
601 * PRIVATE XDisplayFormat
604 * Display the contents of one extended volume info structure.
607 * a_xInfoP : Ptr to extended volume info struct to print.
608 * a_servID : Server ID to print.
609 * a_partID : Partition ID to print.
610 * a_totalOKP : Ptr to total-OK counter.
611 * a_totalNotOKP : Ptr to total-screwed counter.
612 * a_totalBusyP : Ptr to total-busy counter.
613 * a_fast : Fast listing?
614 * a_int32 : Int32 listing?
615 * a_showProblems : Show volume problems?
621 * Nothing interesting.
625 *------------------------------------------------------------------------*/
628 XDisplayFormat(volintXInfo *a_xInfoP, afs_uint32 a_servID, afs_int32 a_partID,
629 int *a_totalOKP, int *a_totalNotOKP, int *a_totalBusyP,
630 int a_fast, int a_int32, int a_showProblems)
631 { /*XDisplayFormat */
639 fprintf(STDOUT, "%-10lu\n", (unsigned long)a_xInfoP->volid);
640 } else if (a_int32) {
642 * Fully-detailed listing.
644 if (a_xInfoP->status == VOK) {
646 * Volume's status is OK - all the fields are valid.
648 fprintf(STDOUT, "%-32s ", a_xInfoP->name);
649 fprintf(STDOUT, "%10lu ", (unsigned long)a_xInfoP->volid);
650 if (a_xInfoP->type == 0)
651 fprintf(STDOUT, "RW ");
652 if (a_xInfoP->type == 1)
653 fprintf(STDOUT, "RO ");
654 if (a_xInfoP->type == 2)
655 fprintf(STDOUT, "BK ");
656 fprintf(STDOUT, "%10d K used ", a_xInfoP->size);
657 fprintf(STDOUT, "%d files ", a_xInfoP->filecount);
658 if (a_xInfoP->inUse == 1) {
659 fprintf(STDOUT, "On-line");
662 fprintf(STDOUT, "Off-line");
665 fprintf(STDOUT, "\n");
666 MapPartIdIntoName(a_partID, pname);
667 fprintf(STDOUT, " %s %s \n", hostutil_GetNameByINet(a_servID),
669 fprintf(STDOUT, " RWrite %10lu ROnly %10lu Backup %10lu \n",
670 (unsigned long)a_xInfoP->parentID,
671 (unsigned long)a_xInfoP->cloneID,
672 (unsigned long)a_xInfoP->backupID);
673 fprintf(STDOUT, " MaxQuota %10d K \n", a_xInfoP->maxquota);
675 t = a_xInfoP->creationDate;
676 fprintf(STDOUT, " Creation %s",
679 t = a_xInfoP->copyDate;
680 fprintf(STDOUT, " Copy %s",
683 t = a_xInfoP->backupDate;
685 fprintf(STDOUT, " Backup Never\n");
687 fprintf(STDOUT, " Backup %s",
690 t = a_xInfoP->accessDate;
692 fprintf(STDOUT, " Last Access %s",
695 t = a_xInfoP->updateDate;
697 fprintf(STDOUT, " Last Update Never\n");
699 fprintf(STDOUT, " Last Update %s",
702 " %d accesses in the past day (i.e., vnode references)\n",
706 * Print all the read/write and authorship stats.
708 fprintf(STDOUT, "\n Raw Read/Write Stats\n");
710 " |-------------------------------------------|\n");
712 " | Same Network | Diff Network |\n");
714 " |----------|----------|----------|----------|\n");
716 " | Total | Auth | Total | Auth |\n");
718 " |----------|----------|----------|----------|\n");
719 fprintf(STDOUT, "Reads | %8d | %8d | %8d | %8d |\n",
720 a_xInfoP->stat_reads[VOLINT_STATS_SAME_NET],
721 a_xInfoP->stat_reads[VOLINT_STATS_SAME_NET_AUTH],
722 a_xInfoP->stat_reads[VOLINT_STATS_DIFF_NET],
723 a_xInfoP->stat_reads[VOLINT_STATS_DIFF_NET_AUTH]);
724 fprintf(STDOUT, "Writes | %8d | %8d | %8d | %8d |\n",
725 a_xInfoP->stat_writes[VOLINT_STATS_SAME_NET],
726 a_xInfoP->stat_writes[VOLINT_STATS_SAME_NET_AUTH],
727 a_xInfoP->stat_writes[VOLINT_STATS_DIFF_NET],
728 a_xInfoP->stat_writes[VOLINT_STATS_DIFF_NET_AUTH]);
730 " |-------------------------------------------|\n\n");
733 " Writes Affecting Authorship\n");
735 " |-------------------------------------------|\n");
737 " | File Authorship | Directory Authorship|\n");
739 " |----------|----------|----------|----------|\n");
741 " | Same | Diff | Same | Diff |\n");
743 " |----------|----------|----------|----------|\n");
744 fprintf(STDOUT, "0-60 sec | %8d | %8d | %8d | %8d |\n",
745 a_xInfoP->stat_fileSameAuthor[VOLINT_STATS_TIME_IDX_0],
746 a_xInfoP->stat_fileDiffAuthor[VOLINT_STATS_TIME_IDX_0],
747 a_xInfoP->stat_dirSameAuthor[VOLINT_STATS_TIME_IDX_0],
748 a_xInfoP->stat_dirDiffAuthor[VOLINT_STATS_TIME_IDX_0]);
749 fprintf(STDOUT, "1-10 min | %8d | %8d | %8d | %8d |\n",
750 a_xInfoP->stat_fileSameAuthor[VOLINT_STATS_TIME_IDX_1],
751 a_xInfoP->stat_fileDiffAuthor[VOLINT_STATS_TIME_IDX_1],
752 a_xInfoP->stat_dirSameAuthor[VOLINT_STATS_TIME_IDX_1],
753 a_xInfoP->stat_dirDiffAuthor[VOLINT_STATS_TIME_IDX_1]);
754 fprintf(STDOUT, "10min-1hr | %8d | %8d | %8d | %8d |\n",
755 a_xInfoP->stat_fileSameAuthor[VOLINT_STATS_TIME_IDX_2],
756 a_xInfoP->stat_fileDiffAuthor[VOLINT_STATS_TIME_IDX_2],
757 a_xInfoP->stat_dirSameAuthor[VOLINT_STATS_TIME_IDX_2],
758 a_xInfoP->stat_dirDiffAuthor[VOLINT_STATS_TIME_IDX_2]);
759 fprintf(STDOUT, "1hr-1day | %8d | %8d | %8d | %8d |\n",
760 a_xInfoP->stat_fileSameAuthor[VOLINT_STATS_TIME_IDX_3],
761 a_xInfoP->stat_fileDiffAuthor[VOLINT_STATS_TIME_IDX_3],
762 a_xInfoP->stat_dirSameAuthor[VOLINT_STATS_TIME_IDX_3],
763 a_xInfoP->stat_dirDiffAuthor[VOLINT_STATS_TIME_IDX_3]);
764 fprintf(STDOUT, "1day-1wk | %8d | %8d | %8d | %8d |\n",
765 a_xInfoP->stat_fileSameAuthor[VOLINT_STATS_TIME_IDX_4],
766 a_xInfoP->stat_fileDiffAuthor[VOLINT_STATS_TIME_IDX_4],
767 a_xInfoP->stat_dirSameAuthor[VOLINT_STATS_TIME_IDX_4],
768 a_xInfoP->stat_dirDiffAuthor[VOLINT_STATS_TIME_IDX_4]);
769 fprintf(STDOUT, "> 1wk | %8d | %8d | %8d | %8d |\n",
770 a_xInfoP->stat_fileSameAuthor[VOLINT_STATS_TIME_IDX_5],
771 a_xInfoP->stat_fileDiffAuthor[VOLINT_STATS_TIME_IDX_5],
772 a_xInfoP->stat_dirSameAuthor[VOLINT_STATS_TIME_IDX_5],
773 a_xInfoP->stat_dirDiffAuthor[VOLINT_STATS_TIME_IDX_5]);
775 " |-------------------------------------------|\n");
776 } /*Volume status OK */
777 else if (a_xInfoP->status == VBUSY) {
779 qPut(&busyHead, a_xInfoP->volid);
781 fprintf(STDOUT, "**** Volume %lu is busy ****\n",
782 (unsigned long)a_xInfoP->volid);
786 qPut(¬okHead, a_xInfoP->volid);
788 fprintf(STDOUT, "**** Could not attach volume %lu ****\n",
789 (unsigned long)a_xInfoP->volid);
790 } /*Screwed volume */
791 fprintf(STDOUT, "\n");
797 if (a_xInfoP->status == VOK) {
798 fprintf(STDOUT, "%-32s ", a_xInfoP->name);
799 fprintf(STDOUT, "%10lu ", (unsigned long)a_xInfoP->volid);
800 if (a_xInfoP->type == 0)
801 fprintf(STDOUT, "RW ");
802 if (a_xInfoP->type == 1)
803 fprintf(STDOUT, "RO ");
804 if (a_xInfoP->type == 2)
805 fprintf(STDOUT, "BK ");
806 fprintf(STDOUT, "%10d K ", a_xInfoP->size);
807 if (a_xInfoP->inUse == 1) {
808 fprintf(STDOUT, "On-line");
811 fprintf(STDOUT, "Off-line");
814 fprintf(STDOUT, "\n");
816 else if (a_xInfoP->status == VBUSY) {
818 qPut(&busyHead, a_xInfoP->volid);
820 fprintf(STDOUT, "**** Volume %lu is busy ****\n",
821 (unsigned long)a_xInfoP->volid);
825 qPut(¬okHead, a_xInfoP->volid);
827 fprintf(STDOUT, "**** Could not attach volume %lu ****\n",
828 (unsigned long)a_xInfoP->volid);
829 } /*Screwed volume */
830 } /*Default listing */
831 } /*XDisplayFormat */
833 /*------------------------------------------------------------------------
834 * PRIVATE XDisplayFormat2
837 * Display the formated contents of one extended volume info structure.
840 * a_xInfoP : Ptr to extended volume info struct to print.
841 * a_servID : Server ID to print.
842 * a_partID : Partition ID to print.
843 * a_totalOKP : Ptr to total-OK counter.
844 * a_totalNotOKP : Ptr to total-screwed counter.
845 * a_totalBusyP : Ptr to total-busy counter.
846 * a_fast : Fast listing?
847 * a_int32 : Int32 listing?
848 * a_showProblems : Show volume problems?
854 * Nothing interesting.
858 *------------------------------------------------------------------------*/
861 XDisplayFormat2(volintXInfo *a_xInfoP, afs_uint32 a_servID, afs_int32 a_partID,
862 int *a_totalOKP, int *a_totalNotOKP, int *a_totalBusyP,
863 int a_fast, int a_int32, int a_showProblems)
864 { /*XDisplayFormat */
870 fprintf(STDOUT, "vold_id\t%-10lu\n", (unsigned long)a_xInfoP->volid);
871 } else if (a_int32) {
873 * Fully-detailed listing.
875 if (a_xInfoP->status == VOK) {
877 * Volume's status is OK - all the fields are valid.
880 static long server_cache = -1, partition_cache = -1;
881 static char hostname[256], address[32], pname[16];
882 int i,ai[] = {VOLINT_STATS_TIME_IDX_0,VOLINT_STATS_TIME_IDX_1,VOLINT_STATS_TIME_IDX_2,
883 VOLINT_STATS_TIME_IDX_3,VOLINT_STATS_TIME_IDX_4,VOLINT_STATS_TIME_IDX_5};
885 if (a_servID != server_cache) {
889 strcpy(hostname, hostutil_GetNameByINet(a_servID));
890 strcpy(address, inet_ntoa(s));
891 server_cache = a_servID;
893 if (a_partID != partition_cache) {
894 MapPartIdIntoName(a_partID, pname);
895 partition_cache = a_partID;
898 fprintf(STDOUT, "name\t\t%s\n", a_xInfoP->name);
899 fprintf(STDOUT, "id\t\t%lu\n", afs_printable_uint32_lu(a_xInfoP->volid));
900 fprintf(STDOUT, "serv\t\t%s\t%s\n", address, hostname);
901 fprintf(STDOUT, "part\t\t%s\n", pname);
902 fprintf(STDOUT, "status\t\tOK\n");
903 fprintf(STDOUT, "backupID\t%lu\n",
904 afs_printable_uint32_lu(a_xInfoP->backupID));
905 fprintf(STDOUT, "parentID\t%lu\n",
906 afs_printable_uint32_lu(a_xInfoP->parentID));
907 fprintf(STDOUT, "cloneID\t\t%lu\n",
908 afs_printable_uint32_lu(a_xInfoP->cloneID));
909 fprintf(STDOUT, "inUse\t\t%s\n", a_xInfoP->inUse ? "Y" : "N");
910 switch (a_xInfoP->type) {
912 fprintf(STDOUT, "type\t\tRW\n");
915 fprintf(STDOUT, "type\t\tRO\n");
918 fprintf(STDOUT, "type\t\tBK\n");
921 fprintf(STDOUT, "type\t\t?\n");
924 t = a_xInfoP->creationDate;
925 fprintf(STDOUT, "creationDate\t%-9lu\t%s",
926 afs_printable_uint32_lu(a_xInfoP->creationDate),
929 t = a_xInfoP->accessDate;
930 fprintf(STDOUT, "accessDate\t%-9lu\t%s",
931 afs_printable_uint32_lu(a_xInfoP->accessDate),
934 t = a_xInfoP->updateDate;
935 fprintf(STDOUT, "updateDate\t%-9lu\t%s",
936 afs_printable_uint32_lu(a_xInfoP->updateDate),
939 t = a_xInfoP->backupDate;
940 fprintf(STDOUT, "backupDate\t%-9lu\t%s",
941 afs_printable_uint32_lu(a_xInfoP->backupDate),
944 t = a_xInfoP->copyDate;
945 fprintf(STDOUT, "copyDate\t%-9lu\t%s",
946 afs_printable_uint32_lu(a_xInfoP->copyDate),
949 fprintf(STDOUT, "diskused\t%u\n", a_xInfoP->size);
950 fprintf(STDOUT, "maxquota\t%u\n", a_xInfoP->maxquota);
952 fprintf(STDOUT, "filecount\t%u\n", a_xInfoP->filecount);
953 fprintf(STDOUT, "dayUse\t\t%u\n", a_xInfoP->dayUse);
957 fprintf(STDOUT,"reads_same_net\t%8d\n",a_xInfoP->stat_reads[VOLINT_STATS_SAME_NET]);
958 fprintf(STDOUT,"reads_same_net_auth\t%8d\n",a_xInfoP->stat_reads[VOLINT_STATS_SAME_NET_AUTH]);
959 fprintf(STDOUT,"reads_diff_net\t%8d\n",a_xInfoP->stat_reads[VOLINT_STATS_DIFF_NET]);
960 fprintf(STDOUT,"reads_diff_net_auth\t%8d\n",a_xInfoP->stat_reads[VOLINT_STATS_DIFF_NET_AUTH]);
962 fprintf(STDOUT,"writes_same_net\t%8d\n",a_xInfoP->stat_writes[VOLINT_STATS_SAME_NET]);
963 fprintf(STDOUT,"writes_same_net_auth\t%8d\n",a_xInfoP->stat_writes[VOLINT_STATS_SAME_NET_AUTH]);
964 fprintf(STDOUT,"writes_diff_net\t%8d\n",a_xInfoP->stat_writes[VOLINT_STATS_DIFF_NET]);
965 fprintf(STDOUT,"writes_diff_net_auth\t%8d\n",a_xInfoP->stat_writes[VOLINT_STATS_DIFF_NET_AUTH]);
969 fprintf(STDOUT,"file_same_author_idx_%d\t%8d\n",i+1,a_xInfoP->stat_fileSameAuthor[ai[i]]);
970 fprintf(STDOUT,"file_diff_author_idx_%d\t%8d\n",i+1,a_xInfoP->stat_fileDiffAuthor[ai[i]]);
971 fprintf(STDOUT,"dir_same_author_idx_%d\t%8d\n",i+1,a_xInfoP->stat_dirSameAuthor[ai[i]]);
972 fprintf(STDOUT,"dir_dif_author_idx_%d\t%8d\n",i+1,a_xInfoP->stat_dirDiffAuthor[ai[i]]);
975 } /*Volume status OK */
976 else if (a_xInfoP->status == VBUSY) {
978 qPut(&busyHead, a_xInfoP->volid);
980 fprintf(STDOUT, "BUSY_VOL\t%lu\n",
981 (unsigned long)a_xInfoP->volid);
985 qPut(¬okHead, a_xInfoP->volid);
987 fprintf(STDOUT, "COULD_NOT_ATTACH\t%lu\n",
988 (unsigned long)a_xInfoP->volid);
989 } /*Screwed volume */
995 if (a_xInfoP->status == VOK) {
996 fprintf(STDOUT, "name\t%-32s\n", a_xInfoP->name);
997 fprintf(STDOUT, "volID\t%10lu\n", (unsigned long)a_xInfoP->volid);
998 if (a_xInfoP->type == 0)
999 fprintf(STDOUT, "type\tRW\n");
1000 if (a_xInfoP->type == 1)
1001 fprintf(STDOUT, "type\tRO\n");
1002 if (a_xInfoP->type == 2)
1003 fprintf(STDOUT, "type\tBK\n");
1004 fprintf(STDOUT, "size\t%10dK\n", a_xInfoP->size);
1006 fprintf(STDOUT, "inUse\t%d\n",a_xInfoP->inUse);
1007 if (a_xInfoP->inUse == 1)
1013 else if (a_xInfoP->status == VBUSY) {
1015 qPut(&busyHead, a_xInfoP->volid);
1017 fprintf(STDOUT, "VOLUME_BUSY\t%lu\n",
1018 (unsigned long)a_xInfoP->volid);
1022 qPut(¬okHead, a_xInfoP->volid);
1024 fprintf(STDOUT, "COULD_NOT_ATTACH_VOLUME\t%lu\n",
1025 (unsigned long)a_xInfoP->volid);
1026 } /*Screwed volume */
1027 } /*Default listing */
1028 } /*XDisplayFormat */
1031 DisplayFormat2(long server, long partition, volintInfo *pntr)
1033 static long server_cache = -1, partition_cache = -1;
1034 static char hostname[256], address[32], pname[16];
1037 if (server != server_cache) {
1041 strcpy(hostname, hostutil_GetNameByINet(server));
1042 strcpy(address, inet_ntoa(s));
1043 server_cache = server;
1045 if (partition != partition_cache) {
1046 MapPartIdIntoName(partition, pname);
1047 partition_cache = partition;
1050 if (pntr->status == VOK)
1051 fprintf(STDOUT, "name\t\t%s\n", pntr->name);
1053 fprintf(STDOUT, "id\t\t%lu\n",
1054 afs_printable_uint32_lu(pntr->volid));
1055 fprintf(STDOUT, "serv\t\t%s\t%s\n", address, hostname);
1056 fprintf(STDOUT, "part\t\t%s\n", pname);
1057 switch (pntr->status) {
1059 fprintf(STDOUT, "status\t\tOK\n");
1062 fprintf(STDOUT, "status\t\tBUSY\n");
1065 fprintf(STDOUT, "status\t\tUNATTACHABLE\n");
1068 fprintf(STDOUT, "backupID\t%lu\n",
1069 afs_printable_uint32_lu(pntr->backupID));
1070 fprintf(STDOUT, "parentID\t%lu\n",
1071 afs_printable_uint32_lu(pntr->parentID));
1072 fprintf(STDOUT, "cloneID\t\t%lu\n",
1073 afs_printable_uint32_lu(pntr->cloneID));
1074 fprintf(STDOUT, "inUse\t\t%s\n", pntr->inUse ? "Y" : "N");
1075 fprintf(STDOUT, "needsSalvaged\t%s\n", pntr->needsSalvaged ? "Y" : "N");
1076 /* 0xD3 is from afs/volume.h since I had trouble including the file */
1077 fprintf(STDOUT, "destroyMe\t%s\n", pntr->destroyMe == 0xD3 ? "Y" : "N");
1078 switch (pntr->type) {
1080 fprintf(STDOUT, "type\t\tRW\n");
1083 fprintf(STDOUT, "type\t\tRO\n");
1086 fprintf(STDOUT, "type\t\tBK\n");
1089 fprintf(STDOUT, "type\t\t?\n");
1092 t = pntr->creationDate;
1093 fprintf(STDOUT, "creationDate\t%-9lu\t%s",
1094 afs_printable_uint32_lu(pntr->creationDate),
1097 t = pntr->accessDate;
1098 fprintf(STDOUT, "accessDate\t%-9lu\t%s",
1099 afs_printable_uint32_lu(pntr->accessDate),
1102 t = pntr->updateDate;
1103 fprintf(STDOUT, "updateDate\t%-9lu\t%s",
1104 afs_printable_uint32_lu(pntr->updateDate),
1107 t = pntr->backupDate;
1108 fprintf(STDOUT, "backupDate\t%-9lu\t%s",
1109 afs_printable_uint32_lu(pntr->backupDate),
1113 fprintf(STDOUT, "copyDate\t%-9lu\t%s",
1114 afs_printable_uint32_lu(pntr->copyDate),
1117 fprintf(STDOUT, "flags\t\t%#lx\t(Optional)\n",
1118 afs_printable_uint32_lu(pntr->flags));
1119 fprintf(STDOUT, "diskused\t%u\n", pntr->size);
1120 fprintf(STDOUT, "maxquota\t%u\n", pntr->maxquota);
1121 fprintf(STDOUT, "minquota\t%lu\t(Optional)\n",
1122 afs_printable_uint32_lu(pntr->spare0));
1123 fprintf(STDOUT, "filecount\t%u\n", pntr->filecount);
1124 fprintf(STDOUT, "dayUse\t\t%u\n", pntr->dayUse);
1125 fprintf(STDOUT, "weekUse\t\t%lu\t(Optional)\n",
1126 afs_printable_uint32_lu(pntr->spare1));
1127 fprintf(STDOUT, "spare2\t\t%lu\t(Optional)\n",
1128 afs_printable_uint32_lu(pntr->spare2));
1129 fprintf(STDOUT, "spare3\t\t%lu\t(Optional)\n",
1130 afs_printable_uint32_lu(pntr->spare3));
1135 DisplayVolumes2(long server, long partition, volintInfo *pntr, long count)
1139 for (i = 0; i < count; i++) {
1140 fprintf(STDOUT, "BEGIN_OF_ENTRY\n");
1141 DisplayFormat2(server, partition, pntr);
1142 fprintf(STDOUT, "END_OF_ENTRY\n\n");
1149 DisplayVolumes(afs_uint32 server, afs_int32 part, volintInfo *pntr,
1150 afs_int32 count, afs_int32 longlist, afs_int32 fast,
1153 int totalOK, totalNotOK, totalBusy, i;
1154 afs_uint32 volid = 0;
1161 for (i = 0; i < count; i++) {
1162 DisplayFormat(pntr, server, part, &totalOK, &totalNotOK, &totalBusy,
1167 while (busyHead.count) {
1168 qGet(&busyHead, &volid);
1169 fprintf(STDOUT, "**** Volume %lu is busy ****\n",
1170 (unsigned long)volid);
1174 while (notokHead.count) {
1175 qGet(¬okHead, &volid);
1176 fprintf(STDOUT, "**** Could not attach volume %lu ****\n",
1177 (unsigned long)volid);
1181 fprintf(STDOUT, "\n");
1184 "Total volumes onLine %d ; Total volumes offLine %d ; Total busy %d\n\n",
1185 totalOK, totalNotOK, totalBusy);
1189 /*------------------------------------------------------------------------
1190 * PRIVATE XDisplayVolumes
1193 * Display extended volume information.
1196 * a_servID : Pointer to the Rx call we're performing.
1197 * a_partID : Partition for which we want the extended list.
1198 * a_xInfoP : Ptr to extended volume info.
1199 * a_count : Number of volume records contained above.
1200 * a_int32 : Int32 listing generated?
1201 * a_fast : Fast listing generated?
1202 * a_quiet : Quiet listing generated?
1208 * Nothing interesting.
1212 *------------------------------------------------------------------------*/
1215 XDisplayVolumes(afs_uint32 a_servID, afs_int32 a_partID, volintXInfo *a_xInfoP,
1216 afs_int32 a_count, afs_int32 a_int32, afs_int32 a_fast,
1218 { /*XDisplayVolumes */
1220 int totalOK; /*Total OK volumes */
1221 int totalNotOK; /*Total screwed volumes */
1222 int totalBusy; /*Total busy volumes */
1223 int i; /*Loop variable */
1224 afs_uint32 volid = 0; /*Current volume ID */
1227 * Initialize counters and (global!!) queues.
1236 * Display each volume in the list.
1238 for (i = 0; i < a_count; i++) {
1239 XDisplayFormat(a_xInfoP, a_servID, a_partID, &totalOK, &totalNotOK,
1240 &totalBusy, a_fast, a_int32, 0);
1245 * If any volumes were found to be busy or screwed, display them.
1248 while (busyHead.count) {
1249 qGet(&busyHead, &volid);
1250 fprintf(STDOUT, "**** Volume %lu is busy ****\n",
1251 (unsigned long)volid);
1255 while (notokHead.count) {
1256 qGet(¬okHead, &volid);
1257 fprintf(STDOUT, "**** Could not attach volume %lu ****\n",
1258 (unsigned long)volid);
1263 fprintf(STDOUT, "\n");
1266 "Total volumes: %d on-line, %d off-line, %d busyd\n\n",
1267 totalOK, totalNotOK, totalBusy);
1271 } /*XDisplayVolumes */
1273 /*------------------------------------------------------------------------
1274 * PRIVATE XDisplayVolumes2
1277 * Display extended formated volume information.
1280 * a_servID : Pointer to the Rx call we're performing.
1281 * a_partID : Partition for which we want the extended list.
1282 * a_xInfoP : Ptr to extended volume info.
1283 * a_count : Number of volume records contained above.
1284 * a_int32 : Int32 listing generated?
1285 * a_fast : Fast listing generated?
1286 * a_quiet : Quiet listing generated?
1292 * Nothing interesting.
1296 *------------------------------------------------------------------------*/
1299 XDisplayVolumes2(afs_uint32 a_servID, afs_int32 a_partID, volintXInfo *a_xInfoP,
1300 afs_int32 a_count, afs_int32 a_int32, afs_int32 a_fast,
1302 { /*XDisplayVolumes */
1304 int totalOK; /*Total OK volumes */
1305 int totalNotOK; /*Total screwed volumes */
1306 int totalBusy; /*Total busy volumes */
1307 int i; /*Loop variable */
1308 afs_uint32 volid = 0; /*Current volume ID */
1311 * Initialize counters and (global!!) queues.
1320 * Display each volume in the list.
1322 for (i = 0; i < a_count; i++) {
1323 fprintf(STDOUT, "BEGIN_OF_ENTRY\n");
1324 XDisplayFormat2(a_xInfoP, a_servID, a_partID, &totalOK, &totalNotOK,
1325 &totalBusy, a_fast, a_int32, 0);
1326 fprintf(STDOUT, "END_OF_ENTRY\n");
1331 * If any volumes were found to be busy or screwed, display them.
1334 while (busyHead.count) {
1335 qGet(&busyHead, &volid);
1336 fprintf(STDOUT, "BUSY_VOL\t%lu\n",
1337 (unsigned long)volid);
1341 while (notokHead.count) {
1342 qGet(¬okHead, &volid);
1343 fprintf(STDOUT, "COULD_NOT_ATTACH\t%lu\n",
1344 (unsigned long)volid);
1349 fprintf(STDOUT, "\n");
1352 "VOLUMES_ONLINE\t%d\nVOLUMES_OFFLINE\t%d\nVOLUMES_BUSY\t%d\n",
1353 totalOK, totalNotOK, totalBusy);
1357 } /*XDisplayVolumes2 */
1360 /* set <server> and <part> to the correct values depending on
1361 * <voltype> and <entry> */
1363 GetServerAndPart(struct nvldbentry *entry, int voltype, afs_uint32 *server,
1364 afs_int32 *part, int *previdx)
1366 int i, istart, vtype;
1371 /* Doesn't check for non-existance of backup volume */
1372 if ((voltype == RWVOL) || (voltype == BACKVOL)) {
1374 istart = 0; /* seach the entire entry */
1377 /* Seach from beginning of entry or pick up where we left off */
1378 istart = ((*previdx < 0) ? 0 : *previdx + 1);
1381 for (i = istart; i < entry->nServers; i++) {
1382 if (entry->serverFlags[i] & vtype) {
1383 *server = entry->serverNumber[i];
1384 *part = entry->serverPartition[i];
1390 /* Didn't find any, return -1 */
1396 PrintLocked(afs_int32 aflags)
1398 afs_int32 flags = aflags & VLOP_ALLOPERS;
1401 fprintf(STDOUT, " Volume is currently LOCKED \n");
1403 if (flags & VLOP_MOVE) {
1404 fprintf(STDOUT, " Volume is locked for a move operation\n");
1406 if (flags & VLOP_RELEASE) {
1407 fprintf(STDOUT, " Volume is locked for a release operation\n");
1409 if (flags & VLOP_BACKUP) {
1410 fprintf(STDOUT, " Volume is locked for a backup operation\n");
1412 if (flags & VLOP_DELETE) {
1413 fprintf(STDOUT, " Volume is locked for a delete/misc operation\n");
1415 if (flags & VLOP_DUMP) {
1416 fprintf(STDOUT, " Volume is locked for a dump/restore operation\n");
1422 PostVolumeStats(struct nvldbentry *entry)
1424 SubEnumerateEntry(entry);
1425 /* Check for VLOP_ALLOPERS */
1426 PrintLocked(entry->flags);
1430 /*------------------------------------------------------------------------
1431 * PRIVATE XVolumeStats
1434 * Display extended volume information.
1437 * a_xInfoP : Ptr to extended volume info.
1438 * a_entryP : Ptr to the volume's VLDB entry.
1439 * a_srvID : Server ID.
1440 * a_partID : Partition ID.
1441 * a_volType : Type of volume to print.
1447 * Nothing interesting.
1451 *------------------------------------------------------------------------*/
1454 XVolumeStats(volintXInfo *a_xInfoP, struct nvldbentry *a_entryP,
1455 afs_int32 a_srvID, afs_int32 a_partID, int a_volType)
1458 int totalOK, totalNotOK, totalBusy; /*Dummies - we don't really count here */
1460 XDisplayFormat(a_xInfoP, /*Ptr to extended volume info */
1461 a_srvID, /*Server ID to print */
1462 a_partID, /*Partition ID to print */
1463 &totalOK, /*Ptr to total-OK counter */
1464 &totalNotOK, /*Ptr to total-screwed counter */
1465 &totalBusy, /*Ptr to total-busy counter */
1466 0, /*Don't do a fast listing */
1467 1, /*Do a long listing */
1468 1); /*Show volume problems */
1474 VolumeStats_int(volintInfo *pntr, struct nvldbentry *entry, afs_uint32 server,
1475 afs_int32 part, int voltype)
1481 DisplayFormat(pntr, server, part, &totalOK, &totalNotOK, &totalBusy, 0, 1,
1486 /* command to forcibly remove a volume */
1488 NukeVolume(struct cmd_syndesc *as)
1497 server = GetServer(tp = as->parms[0].items->data);
1499 fprintf(STDERR, "vos: server '%s' not found in host table\n", tp);
1503 partID = volutil_GetPartitionID(tp = as->parms[1].items->data);
1505 fprintf(STDERR, "vos: could not parse '%s' as a partition name", tp);
1509 volID = vsu_GetVolumeID(tp = as->parms[2].items->data, cstruct, &err);
1512 PrintError("", err);
1515 "vos: could not parse '%s' as a numeric volume ID", tp);
1520 "vos: forcibly removing all traces of volume %d, please wait...",
1523 code = UV_NukeVolume(server, partID, volID);
1525 fprintf(STDOUT, "done.\n");
1527 fprintf(STDOUT, "failed with code %d.\n", code);
1532 /*------------------------------------------------------------------------
1533 * PRIVATE ExamineVolume
1536 * Routine used to examine a single volume, contacting the VLDB as
1537 * well as the Volume Server.
1540 * as : Ptr to parsed command line arguments.
1543 * 0 for a successful operation,
1544 * Otherwise, one of the ubik or VolServer error values.
1547 * Nothing interesting.
1551 *------------------------------------------------------------------------
1554 ExamineVolume(struct cmd_syndesc *as, void *arock)
1556 struct nvldbentry entry;
1557 afs_int32 vcode = 0;
1558 volintInfo *pntr = (volintInfo *) 0;
1559 volintXInfo *xInfoP = (volintXInfo *) 0;
1561 afs_int32 code, err, error = 0;
1562 int voltype, foundserv = 0, foundentry = 0;
1566 int wantExtendedInfo; /*Do we want extended vol info? */
1567 int isSubEnum=0; /* Keep track whether sub enumerate called. */
1568 wantExtendedInfo = (as->parms[1].items ? 1 : 0); /* -extended */
1570 volid = vsu_GetVolumeID(as->parms[0].items->data, cstruct, &err); /* -id */
1573 PrintError("", err);
1575 fprintf(STDERR, "Unknown volume ID or name '%s'\n",
1576 as->parms[0].items->data);
1581 fprintf(STDOUT, "Fetching VLDB entry for %lu .. ",
1582 (unsigned long)volid);
1585 vcode = VLDB_GetEntryByID(volid, -1, &entry);
1588 "Could not fetch the entry for volume number %lu from VLDB \n",
1589 (unsigned long)volid);
1593 fprintf(STDOUT, "done\n");
1594 MapHostToNetwork(&entry);
1596 if (entry.volumeId[RWVOL] == volid)
1598 else if (entry.volumeId[BACKVOL] == volid)
1600 else /* (entry.volumeId[ROVOL] == volid) */
1603 do { /* do {...} while (voltype == ROVOL) */
1604 /* Get the entry for the volume. If its a RW vol, get the RW entry.
1605 * It its a BK vol, get the RW entry (even if VLDB may say the BK doen't exist).
1606 * If its a RO vol, get the next RO entry.
1608 GetServerAndPart(&entry, ((voltype == ROVOL) ? ROVOL : RWVOL),
1609 &aserver, &apart, &previdx);
1610 if (previdx == -1) { /* searched all entries */
1612 fprintf(STDERR, "Volume %s does not exist in VLDB\n\n",
1613 as->parms[0].items->data);
1620 /* Get information about the volume from the server */
1622 fprintf(STDOUT, "Getting volume listing from the server %s .. ",
1623 hostutil_GetNameByINet(aserver));
1626 if (wantExtendedInfo)
1627 code = UV_XListOneVolume(aserver, apart, volid, &xInfoP);
1629 code = UV_ListOneVolume(aserver, apart, volid, &pntr);
1631 fprintf(STDOUT, "done\n");
1635 if (code == ENODEV) {
1636 if ((voltype == BACKVOL) && !(entry.flags & BACK_EXISTS)) {
1637 /* The VLDB says there is no backup volume and its not on disk */
1638 fprintf(STDERR, "Volume %s does not exist\n",
1639 as->parms[0].items->data);
1643 "Volume does not exist on server %s as indicated by the VLDB\n",
1644 hostutil_GetNameByINet(aserver));
1647 PrintDiagnostics("examine", code);
1649 fprintf(STDOUT, "\n");
1652 if (wantExtendedInfo)
1653 XVolumeStats(xInfoP, &entry, aserver, apart, voltype);
1654 else if (as->parms[2].items) {
1655 DisplayFormat2(aserver, apart, pntr);
1656 EnumerateEntry(&entry);
1659 VolumeStats_int(pntr, &entry, aserver, apart, voltype);
1661 if ((voltype == BACKVOL) && !(entry.flags & BACK_EXISTS)) {
1662 /* The VLDB says there is no backup volume yet we found one on disk */
1663 fprintf(STDERR, "Volume %s does not exist in VLDB\n",
1664 as->parms[0].items->data);
1673 } while (voltype == ROVOL);
1676 fprintf(STDERR, "Dump only information from VLDB\n\n");
1677 fprintf(STDOUT, "%s \n", entry.name); /* PostVolumeStats doesn't print name */
1681 PostVolumeStats(&entry);
1686 /*------------------------------------------------------------------------
1690 * Routine used to change the status of a single volume.
1693 * as : Ptr to parsed command line arguments.
1696 * 0 for a successful operation,
1697 * Otherwise, one of the ubik or VolServer error values.
1700 * Nothing interesting.
1704 *------------------------------------------------------------------------
1707 SetFields(struct cmd_syndesc *as, void *arock)
1709 struct nvldbentry entry;
1712 afs_int32 code, err;
1717 volid = vsu_GetVolumeID(as->parms[0].items->data, cstruct, &err); /* -id */
1720 PrintError("", err);
1722 fprintf(STDERR, "Unknown volume ID or name '%s'\n",
1723 as->parms[0].items->data);
1727 code = VLDB_GetEntryByID(volid, RWVOL, &entry);
1730 "Could not fetch the entry for volume number %lu from VLDB \n",
1731 (unsigned long)volid);
1734 MapHostToNetwork(&entry);
1736 GetServerAndPart(&entry, RWVOL, &aserver, &apart, &previdx);
1737 if (previdx == -1) {
1738 fprintf(STDERR, "Volume %s does not exist in VLDB\n\n",
1739 as->parms[0].items->data);
1743 init_volintInfo(&info);
1747 if (as->parms[1].items) {
1749 code = util_GetHumanInt32(as->parms[1].items->data, &info.maxquota);
1751 fprintf(STDERR, "invalid quota value\n");
1755 if (as->parms[2].items) {
1759 if (as->parms[3].items) {
1760 /* -clearVolUpCounter */
1763 code = UV_SetVolumeInfo(aserver, apart, volid, &info);
1766 "Could not update volume info fields for volume number %lu\n",
1767 (unsigned long)volid);
1771 /*------------------------------------------------------------------------
1775 * Brings a volume online.
1778 * as : Ptr to parsed command line arguments.
1781 * 0 for a successful operation,
1784 * Nothing interesting.
1788 *------------------------------------------------------------------------
1791 volOnline(struct cmd_syndesc *as, void *arock)
1794 afs_int32 partition;
1796 afs_int32 code, err = 0;
1798 server = GetServer(as->parms[0].items->data);
1800 fprintf(STDERR, "vos: server '%s' not found in host table\n",
1801 as->parms[0].items->data);
1805 partition = volutil_GetPartitionID(as->parms[1].items->data);
1806 if (partition < 0) {
1807 fprintf(STDERR, "vos: could not interpret partition name '%s'\n",
1808 as->parms[1].items->data);
1812 volid = vsu_GetVolumeID(as->parms[2].items->data, cstruct, &err); /* -id */
1815 PrintError("", err);
1817 fprintf(STDERR, "Unknown volume ID or name '%s'\n",
1818 as->parms[0].items->data);
1822 code = UV_SetVolume(server, partition, volid, ITOffline, 0 /*online */ ,
1825 fprintf(STDERR, "Failed to set volume. Code = %d\n", code);
1832 /*------------------------------------------------------------------------
1833 * PRIVATE volOffline
1836 * Brings a volume offline.
1839 * as : Ptr to parsed command line arguments.
1842 * 0 for a successful operation,
1845 * Nothing interesting.
1849 *------------------------------------------------------------------------
1852 volOffline(struct cmd_syndesc *as, void *arock)
1855 afs_int32 partition;
1857 afs_int32 code, err = 0;
1858 afs_int32 transflag, sleeptime, transdone;
1860 server = GetServer(as->parms[0].items->data);
1862 fprintf(STDERR, "vos: server '%s' not found in host table\n",
1863 as->parms[0].items->data);
1867 partition = volutil_GetPartitionID(as->parms[1].items->data);
1868 if (partition < 0) {
1869 fprintf(STDERR, "vos: could not interpret partition name '%s'\n",
1870 as->parms[1].items->data);
1874 volid = vsu_GetVolumeID(as->parms[2].items->data, cstruct, &err); /* -id */
1877 PrintError("", err);
1879 fprintf(STDERR, "Unknown volume ID or name '%s'\n",
1880 as->parms[0].items->data);
1884 transflag = (as->parms[4].items ? ITBusy : ITOffline);
1885 sleeptime = (as->parms[3].items ? atol(as->parms[3].items->data) : 0);
1886 transdone = ((sleeptime || as->parms[4].items) ? 0 /*online */ : VTOutOfService);
1887 if (as->parms[4].items && !as->parms[3].items) {
1888 fprintf(STDERR, "-sleep option must be used with -busy flag\n");
1893 UV_SetVolume(server, partition, volid, transflag, transdone,
1896 fprintf(STDERR, "Failed to set volume. Code = %d\n", code);
1904 CreateVolume(struct cmd_syndesc *as, void *arock)
1908 afs_uint32 volid = 0, rovolid = 0, bkvolid = 0;
1909 afs_uint32 *arovolid;
1911 struct nvldbentry entry;
1916 arovolid = &rovolid;
1919 tserver = GetServer(as->parms[0].items->data);
1921 fprintf(STDERR, "vos: host '%s' not found in host table\n",
1922 as->parms[0].items->data);
1925 pnum = volutil_GetPartitionID(as->parms[1].items->data);
1927 fprintf(STDERR, "vos: could not interpret partition name '%s'\n",
1928 as->parms[1].items->data);
1931 if (!IsPartValid(pnum, tserver, &code)) { /*check for validity of the partition */
1933 PrintError("", code);
1936 "vos : partition %s does not exist on the server\n",
1937 as->parms[1].items->data);
1940 if (!ISNAMEVALID(as->parms[2].items->data)) {
1942 "vos: the name of the root volume %s exceeds the size limit of %d\n",
1943 as->parms[2].items->data, VOLSER_OLDMAXVOLNAME - 10);
1946 if (!VolNameOK(as->parms[2].items->data)) {
1948 "Illegal volume name %s, should not end in .readonly or .backup\n",
1949 as->parms[2].items->data);
1952 if (IsNumeric(as->parms[2].items->data)) {
1953 fprintf(STDERR, "Illegal volume name %s, should not be a number\n",
1954 as->parms[2].items->data);
1957 vcode = VLDB_GetEntryByName(as->parms[2].items->data, &entry);
1959 fprintf(STDERR, "Volume %s already exists\n",
1960 as->parms[2].items->data);
1961 PrintDiagnostics("create", code);
1965 if (as->parms[3].items) {
1966 code = util_GetHumanInt32(as->parms[3].items->data, "a);
1968 fprintf(STDERR, "vos: bad integer specified for quota.\n");
1973 if (as->parms[4].items) {
1974 if (!IsNumeric(as->parms[4].items->data)) {
1975 fprintf(STDERR, "vos: Given volume ID %s should be numeric.\n",
1976 as->parms[4].items->data);
1980 code = util_GetUInt32(as->parms[4].items->data, &volid);
1982 fprintf(STDERR, "vos: bad integer specified for volume ID.\n");
1987 if (as->parms[5].items) {
1988 if (!IsNumeric(as->parms[5].items->data)) {
1989 fprintf(STDERR, "vos: Given RO volume ID %s should be numeric.\n",
1990 as->parms[5].items->data);
1994 code = util_GetUInt32(as->parms[5].items->data, &rovolid);
1996 fprintf(STDERR, "vos: bad integer specified for volume ID.\n");
2006 UV_CreateVolume3(tserver, pnum, as->parms[2].items->data, quota, 0,
2007 0, 0, 0, &volid, arovolid, &bkvolid);
2009 PrintDiagnostics("create", code);
2012 MapPartIdIntoName(pnum, part);
2013 fprintf(STDOUT, "Volume %lu created on partition %s of %s\n",
2014 (unsigned long)volid, part, as->parms[0].items->data);
2021 DeleteAll(struct nvldbentry *entry)
2024 afs_int32 error, code, curserver, curpart;
2027 MapHostToNetwork(entry);
2029 for (i = 0; i < entry->nServers; i++) {
2030 curserver = entry->serverNumber[i];
2031 curpart = entry->serverPartition[i];
2032 if (entry->serverFlags[i] & ITSROVOL) {
2033 volid = entry->volumeId[ROVOL];
2035 volid = entry->volumeId[RWVOL];
2037 code = UV_DeleteVolume(curserver, curpart, volid);
2046 DeleteVolume(struct cmd_syndesc *as, void *arock)
2048 afs_int32 err, code = 0;
2049 afs_uint32 server = 0;
2050 afs_int32 partition = -1;
2055 if (as->parms[0].items) {
2056 server = GetServer(as->parms[0].items->data);
2058 fprintf(STDERR, "vos: server '%s' not found in host table\n",
2059 as->parms[0].items->data);
2064 if (as->parms[1].items) {
2065 partition = volutil_GetPartitionID(as->parms[1].items->data);
2066 if (partition < 0) {
2067 fprintf(STDERR, "vos: could not interpret partition name '%s'\n",
2068 as->parms[1].items->data);
2072 /* Check for validity of the partition */
2073 if (!IsPartValid(partition, server, &code)) {
2075 PrintError("", code);
2078 "vos : partition %s does not exist on the server\n",
2079 as->parms[1].items->data);
2085 volid = vsu_GetVolumeID(as->parms[2].items->data, cstruct, &err);
2087 fprintf(STDERR, "Can't find volume name '%s' in VLDB\n",
2088 as->parms[2].items->data);
2090 PrintError("", err);
2094 /* If the server or partition option are not complete, try to fill
2095 * them in from the VLDB entry.
2097 if ((partition == -1) || !server) {
2098 struct nvldbentry entry;
2100 code = VLDB_GetEntryByID(volid, -1, &entry);
2103 "Could not fetch the entry for volume %lu from VLDB\n",
2104 (unsigned long)volid);
2105 PrintError("", code);
2109 if (((volid == entry.volumeId[RWVOL]) && (entry.flags & RW_EXISTS))
2110 || ((volid == entry.volumeId[BACKVOL])
2111 && (entry.flags & BACK_EXISTS))) {
2112 idx = Lp_GetRwIndex(&entry);
2113 if ((idx == -1) || (server && (server != entry.serverNumber[idx]))
2114 || ((partition != -1)
2115 && (partition != entry.serverPartition[idx]))) {
2116 fprintf(STDERR, "VLDB: Volume '%s' no match\n",
2117 as->parms[2].items->data);
2120 } else if ((volid == entry.volumeId[ROVOL])
2121 && (entry.flags & RO_EXISTS)) {
2122 for (idx = -1, j = 0; j < entry.nServers; j++) {
2123 if (entry.serverFlags[j] != ITSROVOL)
2126 if (((server == 0) || (server == entry.serverNumber[j]))
2127 && ((partition == -1)
2128 || (partition == entry.serverPartition[j]))) {
2131 "VLDB: Volume '%s' matches more than one RO\n",
2132 as->parms[2].items->data);
2139 fprintf(STDERR, "VLDB: Volume '%s' no match\n",
2140 as->parms[2].items->data);
2144 fprintf(STDERR, "VLDB: Volume '%s' no match\n",
2145 as->parms[2].items->data);
2149 server = htonl(entry.serverNumber[idx]);
2150 partition = entry.serverPartition[idx];
2154 code = UV_DeleteVolume(server, partition, volid);
2156 PrintDiagnostics("remove", code);
2160 MapPartIdIntoName(partition, pname);
2161 fprintf(STDOUT, "Volume %lu on partition %s server %s deleted\n",
2162 (unsigned long)volid, pname, hostutil_GetNameByINet(server));
2166 #define TESTM 0 /* set for move space tests, clear for production */
2168 MoveVolume(struct cmd_syndesc *as, void *arock)
2172 afs_uint32 fromserver, toserver;
2173 afs_int32 frompart, topart;
2174 afs_int32 flags, code, err;
2175 char fromPartName[10], toPartName[10];
2177 struct diskPartition64 partition; /* for space check */
2180 volid = vsu_GetVolumeID(as->parms[0].items->data, cstruct, &err);
2183 PrintError("", err);
2185 fprintf(STDERR, "vos: can't find volume ID or name '%s'\n",
2186 as->parms[0].items->data);
2189 fromserver = GetServer(as->parms[1].items->data);
2190 if (fromserver == 0) {
2191 fprintf(STDERR, "vos: server '%s' not found in host table\n",
2192 as->parms[1].items->data);
2195 toserver = GetServer(as->parms[3].items->data);
2196 if (toserver == 0) {
2197 fprintf(STDERR, "vos: server '%s' not found in host table\n",
2198 as->parms[3].items->data);
2201 frompart = volutil_GetPartitionID(as->parms[2].items->data);
2203 fprintf(STDERR, "vos: could not interpret partition name '%s'\n",
2204 as->parms[2].items->data);
2207 if (!IsPartValid(frompart, fromserver, &code)) { /*check for validity of the partition */
2209 PrintError("", code);
2212 "vos : partition %s does not exist on the server\n",
2213 as->parms[2].items->data);
2216 topart = volutil_GetPartitionID(as->parms[4].items->data);
2218 fprintf(STDERR, "vos: could not interpret partition name '%s'\n",
2219 as->parms[4].items->data);
2222 if (!IsPartValid(topart, toserver, &code)) { /*check for validity of the partition */
2224 PrintError("", code);
2227 "vos : partition %s does not exist on the server\n",
2228 as->parms[4].items->data);
2233 if (as->parms[5].items) flags |= RV_NOCLONE;
2236 * check source partition for space to clone volume
2239 MapPartIdIntoName(topart, toPartName);
2240 MapPartIdIntoName(frompart, fromPartName);
2243 * check target partition for space to move volume
2246 code = UV_PartitionInfo64(toserver, toPartName, &partition);
2248 fprintf(STDERR, "vos: cannot access partition %s\n", toPartName);
2252 fprintf(STDOUT, "target partition %s free space %" AFS_INT64_FMT "\n", toPartName,
2255 p = (volintInfo *) 0;
2256 code = UV_ListOneVolume(fromserver, frompart, volid, &p);
2258 fprintf(STDERR, "vos:cannot access volume %lu\n",
2259 (unsigned long)volid);
2263 fprintf(STDOUT, "volume %lu size %d\n", (unsigned long)volid,
2265 if (partition.free <= p->size) {
2267 "vos: no space on target partition %s to move volume %lu\n",
2268 toPartName, (unsigned long)volid);
2275 fprintf(STDOUT, "size test - don't do move\n");
2279 /* successful move still not guaranteed but shoot for it */
2282 UV_MoveVolume2(volid, fromserver, frompart, toserver, topart, flags);
2284 PrintDiagnostics("move", code);
2287 MapPartIdIntoName(topart, toPartName);
2288 MapPartIdIntoName(frompart, fromPartName);
2289 fprintf(STDOUT, "Volume %lu moved from %s %s to %s %s \n",
2290 (unsigned long)volid, as->parms[1].items->data, fromPartName,
2291 as->parms[3].items->data, toPartName);
2297 CopyVolume(struct cmd_syndesc *as, void *arock)
2300 afs_uint32 fromserver, toserver;
2301 afs_int32 frompart, topart, code, err, flags;
2302 char fromPartName[10], toPartName[10], *tovolume;
2303 struct nvldbentry entry;
2304 struct diskPartition64 partition; /* for space check */
2307 volid = vsu_GetVolumeID(as->parms[0].items->data, cstruct, &err);
2310 PrintError("", err);
2312 fprintf(STDERR, "vos: can't find volume ID or name '%s'\n",
2313 as->parms[0].items->data);
2316 fromserver = GetServer(as->parms[1].items->data);
2317 if (fromserver == 0) {
2318 fprintf(STDERR, "vos: server '%s' not found in host table\n",
2319 as->parms[1].items->data);
2323 toserver = GetServer(as->parms[4].items->data);
2324 if (toserver == 0) {
2325 fprintf(STDERR, "vos: server '%s' not found in host table\n",
2326 as->parms[4].items->data);
2330 tovolume = as->parms[3].items->data;
2331 if (!ISNAMEVALID(tovolume)) {
2333 "vos: the name of the root volume %s exceeds the size limit of %d\n",
2334 tovolume, VOLSER_OLDMAXVOLNAME - 10);
2337 if (!VolNameOK(tovolume)) {
2339 "Illegal volume name %s, should not end in .readonly or .backup\n",
2343 if (IsNumeric(tovolume)) {
2344 fprintf(STDERR, "Illegal volume name %s, should not be a number\n",
2348 code = VLDB_GetEntryByName(tovolume, &entry);
2350 fprintf(STDERR, "Volume %s already exists\n", tovolume);
2351 PrintDiagnostics("copy", code);
2355 frompart = volutil_GetPartitionID(as->parms[2].items->data);
2357 fprintf(STDERR, "vos: could not interpret partition name '%s'\n",
2358 as->parms[2].items->data);
2361 if (!IsPartValid(frompart, fromserver, &code)) { /*check for validity of the partition */
2363 PrintError("", code);
2366 "vos : partition %s does not exist on the server\n",
2367 as->parms[2].items->data);
2371 topart = volutil_GetPartitionID(as->parms[5].items->data);
2373 fprintf(STDERR, "vos: could not interpret partition name '%s'\n",
2374 as->parms[5].items->data);
2377 if (!IsPartValid(topart, toserver, &code)) { /*check for validity of the partition */
2379 PrintError("", code);
2382 "vos : partition %s does not exist on the server\n",
2383 as->parms[5].items->data);
2388 if (as->parms[6].items) flags |= RV_OFFLINE;
2389 if (as->parms[7].items) flags |= RV_RDONLY;
2390 if (as->parms[8].items) flags |= RV_NOCLONE;
2392 MapPartIdIntoName(topart, toPartName);
2393 MapPartIdIntoName(frompart, fromPartName);
2396 * check target partition for space to move volume
2399 code = UV_PartitionInfo64(toserver, toPartName, &partition);
2401 fprintf(STDERR, "vos: cannot access partition %s\n", toPartName);
2405 fprintf(STDOUT, "target partition %s free space %" AFS_INT64_FMT "\n", toPartName,
2408 p = (volintInfo *) 0;
2409 code = UV_ListOneVolume(fromserver, frompart, volid, &p);
2411 fprintf(STDERR, "vos:cannot access volume %lu\n",
2412 (unsigned long)volid);
2416 if (partition.free <= p->size) {
2418 "vos: no space on target partition %s to copy volume %lu\n",
2419 toPartName, (unsigned long)volid);
2425 /* successful copy still not guaranteed but shoot for it */
2428 UV_CopyVolume2(volid, fromserver, frompart, tovolume, toserver,
2431 PrintDiagnostics("copy", code);
2434 MapPartIdIntoName(topart, toPartName);
2435 MapPartIdIntoName(frompart, fromPartName);
2436 fprintf(STDOUT, "Volume %lu copied from %s %s to %s on %s %s \n",
2437 (unsigned long)volid, as->parms[1].items->data, fromPartName,
2438 tovolume, as->parms[4].items->data, toPartName);
2445 ShadowVolume(struct cmd_syndesc *as, void *arock)
2447 afs_uint32 volid, tovolid;
2448 afs_uint32 fromserver, toserver;
2449 afs_int32 frompart, topart;
2450 afs_int32 code, err, flags;
2451 char fromPartName[10], toPartName[10], toVolName[32], *tovolume;
2452 struct diskPartition64 partition; /* for space check */
2455 p = (volintInfo *) 0;
2456 q = (volintInfo *) 0;
2458 volid = vsu_GetVolumeID(as->parms[0].items->data, cstruct, &err);
2461 PrintError("", err);
2463 fprintf(STDERR, "vos: can't find volume ID or name '%s'\n",
2464 as->parms[0].items->data);
2467 fromserver = GetServer(as->parms[1].items->data);
2468 if (fromserver == 0) {
2469 fprintf(STDERR, "vos: server '%s' not found in host table\n",
2470 as->parms[1].items->data);
2474 toserver = GetServer(as->parms[3].items->data);
2475 if (toserver == 0) {
2476 fprintf(STDERR, "vos: server '%s' not found in host table\n",
2477 as->parms[3].items->data);
2481 frompart = volutil_GetPartitionID(as->parms[2].items->data);
2483 fprintf(STDERR, "vos: could not interpret partition name '%s'\n",
2484 as->parms[2].items->data);
2487 if (!IsPartValid(frompart, fromserver, &code)) { /*check for validity of the partition */
2489 PrintError("", code);
2492 "vos : partition %s does not exist on the server\n",
2493 as->parms[2].items->data);
2497 topart = volutil_GetPartitionID(as->parms[4].items->data);
2499 fprintf(STDERR, "vos: could not interpret partition name '%s'\n",
2500 as->parms[4].items->data);
2503 if (!IsPartValid(topart, toserver, &code)) { /*check for validity of the partition */
2505 PrintError("", code);
2508 "vos : partition %s does not exist on the server\n",
2509 as->parms[4].items->data);
2513 if (as->parms[5].items) {
2514 tovolume = as->parms[5].items->data;
2515 if (!ISNAMEVALID(tovolume)) {
2517 "vos: the name of the root volume %s exceeds the size limit of %d\n",
2518 tovolume, VOLSER_OLDMAXVOLNAME - 10);
2521 if (!VolNameOK(tovolume)) {
2523 "Illegal volume name %s, should not end in .readonly or .backup\n",
2527 if (IsNumeric(tovolume)) {
2529 "Illegal volume name %s, should not be a number\n",
2534 /* use actual name of source volume */
2535 code = UV_ListOneVolume(fromserver, frompart, volid, &p);
2537 fprintf(STDERR, "vos:cannot access volume %lu\n",
2538 (unsigned long)volid);
2541 strcpy(toVolName, p->name);
2542 tovolume = toVolName;
2543 /* save p for size checks later */
2546 if (as->parms[6].items) {
2547 tovolid = vsu_GetVolumeID(as->parms[6].items->data, cstruct, &err);
2550 PrintError("", err);
2552 fprintf(STDERR, "vos: can't find volume ID or name '%s'\n",
2553 as->parms[6].items->data);
2559 tovolid = vsu_GetVolumeID(tovolume, cstruct, &err);
2562 PrintError("", err);
2564 fprintf(STDERR, "vos: can't find volume ID or name '%s'\n",
2573 if (as->parms[7].items) flags |= RV_OFFLINE;
2574 if (as->parms[8].items) flags |= RV_RDONLY;
2575 if (as->parms[9].items) flags |= RV_NOCLONE;
2576 if (as->parms[10].items) flags |= RV_CPINCR;
2578 MapPartIdIntoName(topart, toPartName);
2579 MapPartIdIntoName(frompart, fromPartName);
2582 * check target partition for space to move volume
2585 code = UV_PartitionInfo64(toserver, toPartName, &partition);
2587 fprintf(STDERR, "vos: cannot access partition %s\n", toPartName);
2591 fprintf(STDOUT, "target partition %s free space %" AFS_INT64_FMT "\n", toPartName,
2594 /* Don't do this again if we did it above */
2596 code = UV_ListOneVolume(fromserver, frompart, volid, &p);
2598 fprintf(STDERR, "vos:cannot access volume %lu\n",
2599 (unsigned long)volid);
2604 /* OK if this fails */
2605 code = UV_ListOneVolume(toserver, topart, tovolid, &q);
2607 /* Treat existing volume size as "free" */
2609 p->size = (q->size < p->size) ? p->size - q->size : 0;
2611 if (partition.free <= p->size) {
2613 "vos: no space on target partition %s to copy volume %lu\n",
2614 toPartName, (unsigned long)volid);
2622 /* successful copy still not guaranteed but shoot for it */
2625 UV_CopyVolume2(volid, fromserver, frompart, tovolume, toserver,
2626 topart, tovolid, flags);
2628 PrintDiagnostics("shadow", code);
2631 MapPartIdIntoName(topart, toPartName);
2632 MapPartIdIntoName(frompart, fromPartName);
2633 fprintf(STDOUT, "Volume %lu shadowed from %s %s to %s %s \n",
2634 (unsigned long)volid, as->parms[1].items->data, fromPartName,
2635 as->parms[3].items->data, toPartName);
2642 CloneVolume(struct cmd_syndesc *as, void *arock)
2644 afs_uint32 volid, cloneid;
2646 afs_int32 part, voltype;
2647 char partName[10], *volname;
2648 afs_int32 code, err, flags;
2649 struct nvldbentry entry;
2651 volid = vsu_GetVolumeID(as->parms[0].items->data, cstruct, &err);
2654 PrintError("", err);
2656 fprintf(STDERR, "vos: can't find volume ID or name '%s'\n",
2657 as->parms[0].items->data);
2661 if (as->parms[1].items || as->parms[2].items) {
2662 if (!as->parms[1].items || !as->parms[2].items) {
2664 "Must specify both -server and -partition options\n");
2667 server = GetServer(as->parms[1].items->data);
2669 fprintf(STDERR, "vos: server '%s' not found in host table\n",
2670 as->parms[1].items->data);
2673 part = volutil_GetPartitionID(as->parms[2].items->data);
2675 fprintf(STDERR, "vos: could not interpret partition name '%s'\n",
2676 as->parms[2].items->data);
2679 if (!IsPartValid(part, server, &code)) { /*check for validity of the partition */
2681 PrintError("", code);
2684 "vos : partition %s does not exist on the server\n",
2685 as->parms[2].items->data);
2689 code = GetVolumeInfo(volid, &server, &part, &voltype, &entry);
2695 if (as->parms[3].items) {
2696 volname = as->parms[3].items->data;
2697 if (strlen(volname) > VOLSER_OLDMAXVOLNAME - 1) {
2699 "vos: the name of the root volume %s exceeds the size limit of %d\n",
2700 volname, VOLSER_OLDMAXVOLNAME - 1);
2705 * In order that you be able to make clones of RO or BK, this
2706 * check must be omitted.
2708 if (!VolNameOK(volname)) {
2710 "Illegal volume name %s, should not end in .readonly or .backup\n",
2715 if (IsNumeric(volname)) {
2717 "Illegal volume name %s, should not be a number\n",
2724 if (as->parms[4].items) {
2725 cloneid = vsu_GetVolumeID(as->parms[4].items->data, cstruct, &err);
2728 PrintError("", err);
2730 fprintf(STDERR, "vos: can't find volume ID or name '%s'\n",
2731 as->parms[4].items->data);
2737 if (as->parms[5].items) flags |= RV_OFFLINE;
2738 if (as->parms[6].items && as->parms[7].items) {
2739 fprintf(STDERR, "vos: cannot specify that a volume be -readwrite and -readonly\n");
2742 if (as->parms[6].items) flags |= RV_RDONLY;
2743 if (as->parms[7].items) flags |= RV_RWONLY;
2747 UV_CloneVolume(server, part, volid, cloneid, volname, flags);
2750 PrintDiagnostics("clone", code);
2753 MapPartIdIntoName(part, partName);
2754 fprintf(STDOUT, "Created clone for volume %s\n",
2755 as->parms[0].items->data);
2762 BackupVolume(struct cmd_syndesc *as, void *arock)
2766 afs_int32 apart, vtype, code, err;
2767 struct nvldbentry entry;
2770 afs_uint32 buserver;
2771 afs_int32 bupart, butype;
2772 struct nvldbentry buentry;
2774 avolid = vsu_GetVolumeID(as->parms[0].items->data, cstruct, &err);
2777 PrintError("", err);
2779 fprintf(STDERR, "vos: can't find volume ID or name '%s'\n",
2780 as->parms[0].items->data);
2783 code = GetVolumeInfo(avolid, &aserver, &apart, &vtype, &entry);
2787 /* verify this is a readwrite volume */
2789 if (vtype != RWVOL) {
2790 fprintf(STDERR, "%s not RW volume\n", as->parms[0].items->data);
2794 /* is there a backup volume already? */
2796 if (entry.flags & BACK_EXISTS) {
2797 /* yep, where is it? */
2799 buvolid = entry.volumeId[BACKVOL];
2800 code = GetVolumeInfo(buvolid, &buserver, &bupart, &butype, &buentry);
2805 code = VLDB_IsSameAddrs(buserver, aserver, &err);
2808 "Failed to get info about server's %d address(es) from vlserver; aborting call!\n",
2814 "FATAL ERROR: backup volume %lu exists on server %lu\n",
2815 (unsigned long)buvolid, (unsigned long)buserver);
2820 /* nope, carry on */
2822 code = UV_BackupVolume(aserver, apart, avolid);
2825 PrintDiagnostics("backup", code);
2828 fprintf(STDOUT, "Created backup volume for %s \n",
2829 as->parms[0].items->data);
2834 ReleaseVolume(struct cmd_syndesc *as, void *arock)
2837 struct nvldbentry entry;
2840 afs_int32 apart, vtype, code, err;
2844 if (as->parms[1].items)
2846 if (as->parms[2].items)
2848 avolid = vsu_GetVolumeID(as->parms[0].items->data, cstruct, &err);
2851 PrintError("", err);
2853 fprintf(STDERR, "vos: can't find volume '%s'\n",
2854 as->parms[0].items->data);
2857 code = GetVolumeInfo(avolid, &aserver, &apart, &vtype, &entry);
2861 if (vtype != RWVOL) {
2862 fprintf(STDERR, "%s not a RW volume\n", as->parms[0].items->data);
2866 if (!ISNAMEVALID(entry.name)) {
2868 "Volume name %s is too long, rename before releasing\n",
2873 code = UV_ReleaseVolume(avolid, aserver, apart, force, stayUp);
2876 PrintDiagnostics("release", code);
2879 fprintf(STDOUT, "Released volume %s successfully\n",
2880 as->parms[0].items->data);
2885 DumpVolumeCmd(struct cmd_syndesc *as, void *arock)
2889 afs_int32 apart, voltype, fromdate = 0, code, err, i, flags;
2890 char filename[MAXPATHLEN];
2891 struct nvldbentry entry;
2893 rx_SetRxDeadTime(60 * 10);
2894 for (i = 0; i < MAXSERVERS; i++) {
2895 struct rx_connection *rxConn = ubik_GetRPCConn(cstruct, i);
2898 rx_SetConnDeadTime(rxConn, rx_connDeadTime);
2899 if (rx_ServiceOf(rxConn))
2900 rx_ServiceOf(rxConn)->connDeadTime = rx_connDeadTime;
2903 avolid = vsu_GetVolumeID(as->parms[0].items->data, cstruct, &err);
2906 PrintError("", err);
2908 fprintf(STDERR, "vos: can't find volume '%s'\n",
2909 as->parms[0].items->data);
2913 if (as->parms[3].items || as->parms[4].items) {
2914 if (!as->parms[3].items || !as->parms[4].items) {
2916 "Must specify both -server and -partition options\n");
2919 aserver = GetServer(as->parms[3].items->data);
2921 fprintf(STDERR, "Invalid server name\n");
2924 apart = volutil_GetPartitionID(as->parms[4].items->data);
2926 fprintf(STDERR, "Invalid partition name\n");
2930 code = GetVolumeInfo(avolid, &aserver, &apart, &voltype, &entry);
2935 if (as->parms[1].items && strcmp(as->parms[1].items->data, "0")) {
2936 code = ktime_DateToInt32(as->parms[1].items->data, &fromdate);
2938 fprintf(STDERR, "vos: failed to parse date '%s' (error=%d))\n",
2939 as->parms[1].items->data, code);
2943 if (as->parms[2].items) {
2944 strcpy(filename, as->parms[2].items->data);
2946 strcpy(filename, "");
2949 flags = as->parms[6].items ? VOLDUMPV2_OMITDIRS : 0;
2951 if (as->parms[5].items) {
2953 UV_DumpClonedVolume(avolid, aserver, apart, fromdate,
2954 DumpFunction, filename, flags);
2957 UV_DumpVolume(avolid, aserver, apart, fromdate, DumpFunction,
2960 if ((code == RXGEN_OPCODE) && (as->parms[6].items)) {
2961 flags &= ~VOLDUMPV2_OMITDIRS;
2965 PrintDiagnostics("dump", code);
2968 if (strcmp(filename, ""))
2969 fprintf(STDERR, "Dumped volume %s in file %s\n",
2970 as->parms[0].items->data, filename);
2972 fprintf(STDERR, "Dumped volume %s in stdout \n",
2973 as->parms[0].items->data);
2987 RestoreVolumeCmd(struct cmd_syndesc *as, void *arock)
2989 afs_uint32 avolid, aparentid;
2991 afs_int32 apart, code, vcode, err;
2992 afs_int32 aoverwrite = ASK;
2993 afs_int32 acreation = 0, alastupdate = 0;
2994 int restoreflags = 0;
2995 int readonly = 0, offline = 0, voltype = RWVOL;
2996 char afilename[MAXPATHLEN], avolname[VOLSER_MAXVOLNAME + 1], apartName[10];
2997 char volname[VOLSER_MAXVOLNAME + 1];
2998 struct nvldbentry entry;
3001 if (as->parms[4].items) {
3002 avolid = vsu_GetVolumeID(as->parms[4].items->data, cstruct, &err);
3005 PrintError("", err);
3007 fprintf(STDERR, "vos: can't find volume '%s'\n",
3008 as->parms[4].items->data);
3014 if (as->parms[5].items) {
3015 if ((strcmp(as->parms[5].items->data, "a") == 0)
3016 || (strcmp(as->parms[5].items->data, "abort") == 0)) {
3018 } else if ((strcmp(as->parms[5].items->data, "f") == 0)
3019 || (strcmp(as->parms[5].items->data, "full") == 0)) {
3021 } else if ((strcmp(as->parms[5].items->data, "i") == 0)
3022 || (strcmp(as->parms[5].items->data, "inc") == 0)
3023 || (strcmp(as->parms[5].items->data, "increment") == 0)
3024 || (strcmp(as->parms[5].items->data, "incremental") == 0)) {
3027 fprintf(STDERR, "vos: %s is not a valid argument to -overwrite\n",
3028 as->parms[5].items->data);
3032 if (as->parms[6].items)
3034 if (as->parms[7].items) {
3039 if (as->parms[8].items) {
3040 if ((strcmp(as->parms[8].items->data, "d") == 0)
3041 || (strcmp(as->parms[8].items->data, "dump") == 0)) {
3042 acreation = TS_DUMP;
3043 } else if ((strcmp(as->parms[8].items->data, "k") == 0)
3044 || (strcmp(as->parms[8].items->data, "keep") == 0)) {
3045 acreation = TS_KEEP;
3046 } else if ((strcmp(as->parms[8].items->data, "n") == 0)
3047 || (strcmp(as->parms[8].items->data, "new") == 0)) {
3050 fprintf(STDERR, "vos: %s is not a valid argument to -creation\n",
3051 as->parms[8].items->data);
3056 if (as->parms[9].items) {
3057 if ((strcmp(as->parms[9].items->data, "d") == 0)
3058 || (strcmp(as->parms[9].items->data, "dump") == 0)) {
3059 alastupdate = TS_DUMP;
3060 } else if ((strcmp(as->parms[9].items->data, "k") == 0)
3061 || (strcmp(as->parms[9].items->data, "keep") == 0)) {
3062 alastupdate = TS_KEEP;
3063 } else if ((strcmp(as->parms[9].items->data, "n") == 0)
3064 || (strcmp(as->parms[9].items->data, "new") == 0)) {
3065 alastupdate = TS_NEW;
3067 fprintf(STDERR, "vos: %s is not a valid argument to -lastupdate\n",
3068 as->parms[9].items->data);
3073 aserver = GetServer(as->parms[0].items->data);
3075 fprintf(STDERR, "vos: server '%s' not found in host table\n",
3076 as->parms[0].items->data);
3079 apart = volutil_GetPartitionID(as->parms[1].items->data);
3081 fprintf(STDERR, "vos: could not interpret partition name '%s'\n",
3082 as->parms[1].items->data);
3085 if (!IsPartValid(apart, aserver, &code)) { /*check for validity of the partition */
3087 PrintError("", code);
3090 "vos : partition %s does not exist on the server\n",
3091 as->parms[1].items->data);
3094 strcpy(avolname, as->parms[2].items->data);
3095 if (!ISNAMEVALID(avolname)) {
3097 "vos: the name of the volume %s exceeds the size limit\n",
3101 if (!VolNameOK(avolname)) {
3103 "Illegal volume name %s, should not end in .readonly or .backup\n",
3107 if (as->parms[3].items) {
3108 strcpy(afilename, as->parms[3].items->data);
3109 if (!FileExists(afilename)) {
3110 fprintf(STDERR, "Can't access file %s\n", afilename);
3114 strcpy(afilename, "");
3117 /* Check if volume exists or not */
3119 vsu_ExtractName(volname, avolname);
3120 vcode = VLDB_GetEntryByName(volname, &entry);
3121 if (vcode) { /* no volume - do a full restore */
3122 restoreflags = RV_FULLRST;
3123 if ((aoverwrite == INC) || (aoverwrite == ABORT))
3125 "Volume does not exist; Will perform a full restore\n");
3128 else if ((!readonly && Lp_GetRwIndex(&entry) == -1) /* RW volume does not exist - do a full */
3129 ||(readonly && !Lp_ROMatch(0, 0, &entry))) { /* RO volume does not exist - do a full */
3130 restoreflags = RV_FULLRST;
3131 if ((aoverwrite == INC) || (aoverwrite == ABORT))
3133 "%s Volume does not exist; Will perform a full restore\n",
3134 readonly ? "RO" : "RW");
3137 avolid = entry.volumeId[voltype];
3138 } else if (entry.volumeId[voltype] != 0
3139 && entry.volumeId[voltype] != avolid) {
3140 avolid = entry.volumeId[voltype];
3142 aparentid = entry.volumeId[RWVOL];
3145 else { /* volume exists - do we do a full incremental or abort */
3147 afs_int32 Opart, Otype, vol_elsewhere = 0;
3148 struct nvldbentry Oentry;
3152 avolid = entry.volumeId[voltype];
3153 } else if (entry.volumeId[voltype] != 0
3154 && entry.volumeId[voltype] != avolid) {
3155 avolid = entry.volumeId[voltype];
3157 aparentid = entry.volumeId[RWVOL];
3159 /* A file name was specified - check if volume is on another partition */
3160 vcode = GetVolumeInfo(avolid, &Oserver, &Opart, &Otype, &Oentry);
3164 vcode = VLDB_IsSameAddrs(Oserver, aserver, &err);
3167 "Failed to get info about server's %d address(es) from vlserver (err=%d); aborting call!\n",
3171 if (!vcode || (Opart != apart))
3174 if (aoverwrite == ASK) {
3175 if (strcmp(afilename, "") == 0) { /* The file is from standard in */
3177 "Volume exists and no -overwrite option specified; Aborting restore command\n");
3181 /* Ask what to do */
3182 if (vol_elsewhere) {
3184 "The volume %s %u already exists on a different server/part\n",
3185 volname, entry.volumeId[voltype]);
3187 "Do you want to do a full restore or abort? [fa](a): ");
3190 "The volume %s %u already exists in the VLDB\n",
3191 volname, entry.volumeId[voltype]);
3193 "Do you want to do a full/incremental restore or abort? [fia](a): ");
3196 while (!(dc == EOF || dc == '\n'))
3197 dc = getchar(); /* goto end of line */
3198 if ((c == 'f') || (c == 'F'))
3200 else if ((c == 'i') || (c == 'I'))
3206 if (aoverwrite == ABORT) {
3207 fprintf(STDERR, "Volume exists; Aborting restore command\n");
3209 } else if (aoverwrite == FULL) {
3210 restoreflags = RV_FULLRST;
3212 "Volume exists; Will delete and perform full restore\n");
3213 } else if (aoverwrite == INC) {
3215 if (vol_elsewhere) {
3217 "%s volume %lu already exists on a different server/part; not allowed\n",
3218 readonly ? "RO" : "RW", (unsigned long)avolid);
3224 restoreflags |= RV_OFFLINE;
3226 restoreflags |= RV_RDONLY;
3228 switch (acreation) {
3230 restoreflags |= RV_CRDUMP;
3233 restoreflags |= RV_CRKEEP;
3236 restoreflags |= RV_CRNEW;
3239 if (aoverwrite == FULL)
3240 restoreflags |= RV_CRNEW;
3242 restoreflags |= RV_CRKEEP;
3245 switch (alastupdate) {
3247 restoreflags |= RV_LUDUMP;
3250 restoreflags |= RV_LUKEEP;
3253 restoreflags |= RV_LUNEW;
3256 restoreflags |= RV_LUDUMP;
3258 if (as->parms[10].items) {
3259 restoreflags |= RV_NODEL;
3264 UV_RestoreVolume2(aserver, apart, avolid, aparentid,
3265 avolname, restoreflags, WriteData, afilename);
3267 PrintDiagnostics("restore", code);
3270 MapPartIdIntoName(apart, apartName);
3273 * patch typo here - originally "parms[1]", should be "parms[0]"
3276 fprintf(STDOUT, "Restored volume %s on %s %s\n", avolname,
3277 as->parms[0].items->data, apartName);
3282 LockReleaseCmd(struct cmd_syndesc *as, void *arock)
3285 afs_int32 code, err;
3287 avolid = vsu_GetVolumeID(as->parms[0].items->data, cstruct, &err);
3290 PrintError("", err);
3292 fprintf(STDERR, "vos: can't find volume '%s'\n",
3293 as->parms[0].items->data);
3297 code = UV_LockRelease(avolid);
3299 PrintDiagnostics("unlock", code);
3302 fprintf(STDOUT, "Released lock on vldb entry for volume %s\n",
3303 as->parms[0].items->data);
3308 AddSite(struct cmd_syndesc *as, void *arock)
3312 afs_int32 apart, code, err, arovolid, valid = 0;
3313 char apartName[10], avolname[VOLSER_MAXVOLNAME + 1];
3315 vsu_ExtractName(avolname, as->parms[2].items->data);;
3316 avolid = vsu_GetVolumeID(avolname, cstruct, &err);
3319 PrintError("", err);
3321 fprintf(STDERR, "vos: can't find volume '%s'\n",
3322 as->parms[2].items->data);
3326 if (as->parms[3].items) {
3327 vsu_ExtractName(avolname, as->parms[3].items->data);
3328 arovolid = vsu_GetVolumeID(avolname, cstruct, &err);
3330 fprintf(STDERR, "vos: invalid ro volume id '%s'\n",
3331 as->parms[3].items->data);
3335 aserver = GetServer(as->parms[0].items->data);
3337 fprintf(STDERR, "vos: server '%s' not found in host table\n",
3338 as->parms[0].items->data);
3341 apart = volutil_GetPartitionID(as->parms[1].items->data);
3343 fprintf(STDERR, "vos: could not interpret partition name '%s'\n",
3344 as->parms[1].items->data);
3347 if (!IsPartValid(apart, aserver, &code)) { /*check for validity of the partition */
3349 PrintError("", code);
3352 "vos : partition %s does not exist on the server\n",
3353 as->parms[1].items->data);
3356 if (as->parms[4].items) {
3359 code = UV_AddSite2(aserver, apart, avolid, arovolid, valid);
3361 PrintDiagnostics("addsite", code);
3364 MapPartIdIntoName(apart, apartName);
3365 fprintf(STDOUT, "Added replication site %s %s for volume %s\n",
3366 as->parms[0].items->data, apartName, as->parms[2].items->data);
3371 RemoveSite(struct cmd_syndesc *as, void *arock)
3376 afs_int32 apart, code, err;
3377 char apartName[10], avolname[VOLSER_MAXVOLNAME + 1];
3379 vsu_ExtractName(avolname, as->parms[2].items->data);
3380 avolid = vsu_GetVolumeID(avolname, cstruct, &err);
3383 PrintError("", err);
3385 fprintf(STDERR, "vos: can't find volume '%s'\n",
3386 as->parms[2].items->data);
3389 aserver = GetServer(as->parms[0].items->data);
3391 fprintf(STDERR, "vos: server '%s' not found in host table\n",
3392 as->parms[0].items->data);
3395 apart = volutil_GetPartitionID(as->parms[1].items->data);
3397 fprintf(STDERR, "vos: could not interpret partition name '%s'\n",
3398 as->parms[1].items->data);
3402 *skip the partition validity check, since it is possible that the partition
3403 *has since been decomissioned.
3406 if (!IsPartValid(apart,aserver,&code)){
3407 if(code) PrintError("",code);
3408 else fprintf(STDERR,"vos : partition %s does not exist on the server\n",as->parms[1].items->data);
3412 code = UV_RemoveSite(aserver, apart, avolid);
3414 PrintDiagnostics("remsite", code);
3417 MapPartIdIntoName(apart, apartName);
3418 fprintf(STDOUT, "Removed replication site %s %s for volume %s\n",
3419 as->parms[0].items->data, apartName, as->parms[2].items->data);
3424 ChangeLocation(struct cmd_syndesc *as, void *arock)
3428 afs_int32 apart, code, err;
3431 avolid = vsu_GetVolumeID(as->parms[2].items->data, cstruct, &err);
3434 PrintError("", err);
3436 fprintf(STDERR, "vos: can't find volume '%s'\n",
3437 as->parms[2].items->data);
3440 aserver = GetServer(as->parms[0].items->data);
3442 fprintf(STDERR, "vos: server '%s' not found in host table\n",
3443 as->parms[0].items->data);
3446 apart = volutil_GetPartitionID(as->parms[1].items->data);
3448 fprintf(STDERR, "vos: could not interpret partition name '%s'\n",
3449 as->parms[1].items->data);
3452 if (!IsPartValid(apart, aserver, &code)) { /*check for validity of the partition */
3454 PrintError("", code);
3457 "vos : partition %s does not exist on the server\n",
3458 as->parms[1].items->data);
3461 code = UV_ChangeLocation(aserver, apart, avolid);
3463 PrintDiagnostics("changeloc", code);
3466 MapPartIdIntoName(apart, apartName);
3467 fprintf(STDOUT, "Changed location to %s %s for volume %s\n",
3468 as->parms[0].items->data, apartName, as->parms[2].items->data);
3473 ListPartitions(struct cmd_syndesc *as, void *arock)
3477 struct partList dummyPartList;
3482 aserver = GetServer(as->parms[0].items->data);
3484 fprintf(STDERR, "vos: server '%s' not found in host table\n",
3485 as->parms[0].items->data);
3490 code = UV_ListPartitions(aserver, &dummyPartList, &cnt);
3492 PrintDiagnostics("listpart", code);
3496 fprintf(STDOUT, "The partitions on the server are:\n");
3497 for (i = 0; i < cnt; i++) {
3498 if (dummyPartList.partFlags[i] & PARTVALID) {
3499 memset(pname, 0, sizeof(pname));
3500 MapPartIdIntoName(dummyPartList.partId[i], pname);
3501 fprintf(STDOUT, " %10s ", pname);
3503 if ((i % 5) == 0 && (i != 0))
3504 fprintf(STDOUT, "\n");
3507 fprintf(STDOUT, "\n");
3508 fprintf(STDOUT, "Total: %d\n", total);
3514 CompareVolName(const void *p1, const void *p2)
3516 volintInfo *arg1, *arg2;
3518 arg1 = (volintInfo *) p1;
3519 arg2 = (volintInfo *) p2;
3520 return (strcmp(arg1->name, arg2->name));
3524 /*------------------------------------------------------------------------
3525 * PRIVATE XCompareVolName
3528 * Comparison routine for volume names coming from an extended
3532 * a_obj1P : Char ptr to first extended vol info object
3533 * a_obj1P : Char ptr to second extended vol info object
3536 * The value of strcmp() on the volume names within the passed
3537 * objects (i,e., -1, 0, or 1).
3540 * Passed to qsort() as the designated comparison routine.
3544 *------------------------------------------------------------------------*/
3547 XCompareVolName(const void *a_obj1P, const void *a_obj2P)
3548 { /*XCompareVolName */
3551 (((struct volintXInfo *)(a_obj1P))->name,
3552 ((struct volintXInfo *)(a_obj2P))->name));
3554 } /*XCompareVolName */
3557 CompareVolID(const void *p1, const void *p2)
3559 volintInfo *arg1, *arg2;
3561 arg1 = (volintInfo *) p1;
3562 arg2 = (volintInfo *) p2;
3563 if (arg1->volid == arg2->volid)
3565 if (arg1->volid > arg2->volid)
3572 /*------------------------------------------------------------------------
3573 * PRIVATE XCompareVolID
3576 * Comparison routine for volume IDs coming from an extended
3580 * a_obj1P : Char ptr to first extended vol info object
3581 * a_obj1P : Char ptr to second extended vol info object
3584 * The value of strcmp() on the volume names within the passed
3585 * objects (i,e., -1, 0, or 1).
3588 * Passed to qsort() as the designated comparison routine.
3592 *------------------------------------------------------------------------*/
3595 XCompareVolID(const void *a_obj1P, const void *a_obj2P)
3596 { /*XCompareVolID */
3598 afs_int32 id1, id2; /*Volume IDs we're comparing */
3600 id1 = ((struct volintXInfo *)(a_obj1P))->volid;
3601 id2 = ((struct volintXInfo *)(a_obj2P))->volid;
3609 } /*XCompareVolID */
3611 /*------------------------------------------------------------------------
3612 * PRIVATE ListVolumes
3615 * Routine used to list volumes, contacting the Volume Server
3616 * directly, bypassing the VLDB.
3619 * as : Ptr to parsed command line arguments.
3622 * 0 Successful operation
3625 * Nothing interesting.
3629 *------------------------------------------------------------------------*/
3632 ListVolumes(struct cmd_syndesc *as, void *arock)
3634 afs_int32 apart, int32list, fast;
3638 volintInfo *oldpntr = NULL;
3642 volintXInfo *xInfoP;
3643 volintXInfo *origxInfoP = NULL; /*Ptr to current/orig extended vol info */
3644 int wantExtendedInfo; /*Do we want extended vol info? */
3647 struct partList dummyPartList;
3655 if (as->parms[3].items)
3657 if (as->parms[4].items)
3661 if (as->parms[2].items)
3667 if (as->parms[5].items) {
3669 * We can't coexist with the fast flag.
3673 "vos: Can't use the -fast and -extended flags together\n");
3678 * We need to turn on ``long'' listings to get the full effect.
3680 wantExtendedInfo = 1;
3683 wantExtendedInfo = 0;
3684 if (as->parms[1].items) {
3685 apart = volutil_GetPartitionID(as->parms[1].items->data);
3687 fprintf(STDERR, "vos: could not interpret partition name '%s'\n",
3688 as->parms[1].items->data);
3691 dummyPartList.partId[0] = apart;
3692 dummyPartList.partFlags[0] = PARTVALID;
3695 aserver = GetServer(as->parms[0].items->data);
3697 fprintf(STDERR, "vos: server '%s' not found in host table\n",
3698 as->parms[0].items->data);
3703 if (!IsPartValid(apart, aserver, &code)) { /*check for validity of the partition */
3705 PrintError("", code);
3708 "vos : partition %s does not exist on the server\n",
3709 as->parms[1].items->data);
3713 code = UV_ListPartitions(aserver, &dummyPartList, &cnt);
3715 PrintDiagnostics("listvol", code);
3719 for (i = 0; i < cnt; i++) {
3720 if (dummyPartList.partFlags[i] & PARTVALID) {
3721 if (wantExtendedInfo)
3723 UV_XListVolumes(aserver, dummyPartList.partId[i], all,
3727 UV_ListVolumes(aserver, dummyPartList.partId[i], all,
3730 PrintDiagnostics("listvol", code);
3733 if (wantExtendedInfo) {
3734 origxInfoP = xInfoP;
3735 base = (char *)xInfoP;
3738 base = (char *)pntr;
3742 if (wantExtendedInfo)
3743 qsort(base, count, sizeof(volintXInfo), XCompareVolName);
3745 qsort(base, count, sizeof(volintInfo), CompareVolName);
3747 if (wantExtendedInfo)
3748 qsort(base, count, sizeof(volintXInfo), XCompareVolID);
3750 qsort(base, count, sizeof(volintInfo), CompareVolID);
3752 MapPartIdIntoName(dummyPartList.partId[i], pname);
3755 "Total number of volumes on server %s partition %s: %lu \n",
3756 as->parms[0].items->data, pname,
3757 (unsigned long)count);
3758 if (wantExtendedInfo) {
3759 if (as->parms[6].items)
3760 XDisplayVolumes2(aserver, dummyPartList.partId[i], origxInfoP,
3761 count, int32list, fast, quiet);
3763 XDisplayVolumes(aserver, dummyPartList.partId[i], origxInfoP,
3764 count, int32list, fast, quiet);
3767 xInfoP = (volintXInfo *) 0;
3769 if (as->parms[6].items)
3770 DisplayVolumes2(aserver, dummyPartList.partId[i], oldpntr,
3773 DisplayVolumes(aserver, dummyPartList.partId[i], oldpntr,
3774 count, int32list, fast, quiet);
3777 pntr = (volintInfo *) 0;
3785 SyncVldb(struct cmd_syndesc *as, void *arock)
3787 afs_int32 pnum = 0, code; /* part name */
3794 if (as->parms[0].items) {
3795 tserver = GetServer(as->parms[0].items->data);
3797 fprintf(STDERR, "vos: host '%s' not found in host table\n",
3798 as->parms[0].items->data);
3803 if (as->parms[1].items) {
3804 pnum = volutil_GetPartitionID(as->parms[1].items->data);
3806 fprintf(STDERR, "vos: could not interpret partition name '%s'\n",
3807 as->parms[1].items->data);
3810 if (!IsPartValid(pnum, tserver, &code)) { /*check for validity of the partition */
3812 PrintError("", code);
3815 "vos: partition %s does not exist on the server\n",
3816 as->parms[1].items->data);
3823 "The -partition option requires a -server option\n");
3828 if (as->parms[3].items) {
3829 flags |= 2; /* don't update */
3832 if (as->parms[2].items) {
3833 /* Synchronize an individual volume */
3834 volname = as->parms[2].items->data;
3835 code = UV_SyncVolume(tserver, pnum, volname, flags);
3839 "Without a -volume option, the -server option is required\n");
3842 code = UV_SyncVldb(tserver, pnum, flags, 0 /*unused */ );
3846 PrintDiagnostics("syncvldb", code);
3850 /* Print a summary of what we did */
3852 fprintf(STDOUT, "VLDB volume %s synchronized", volname);
3854 fprintf(STDOUT, "VLDB synchronized");
3856 fprintf(STDOUT, " with state of server %s", as->parms[0].items->data);
3859 MapPartIdIntoName(pnum, part);
3860 fprintf(STDOUT, " partition %s\n", part);
3862 fprintf(STDOUT, "\n");
3868 SyncServer(struct cmd_syndesc *as, void *arock)
3870 afs_int32 pnum, code; /* part name */
3876 tserver = GetServer(as->parms[0].items->data);
3878 fprintf(STDERR, "vos: host '%s' not found in host table\n",
3879 as->parms[0].items->data);
3882 if (as->parms[1].items) {
3883 pnum = volutil_GetPartitionID(as->parms[1].items->data);
3885 fprintf(STDERR, "vos: could not interpret partition name '%s'\n",
3886 as->parms[1].items->data);
3889 if (!IsPartValid(pnum, tserver, &code)) { /*check for validity of the partition */
3891 PrintError("", code);
3894 "vos : partition %s does not exist on the server\n",
3895 as->parms[1].items->data);
3903 if (as->parms[2].items) {
3904 flags |= 2; /* don't update */
3906 code = UV_SyncServer(tserver, pnum, flags, 0 /*unused */ );
3908 PrintDiagnostics("syncserv", code);
3912 MapPartIdIntoName(pnum, part);
3913 fprintf(STDOUT, "Server %s partition %s synchronized with VLDB\n",
3914 as->parms[0].items->data, part);
3916 fprintf(STDOUT, "Server %s synchronized with VLDB\n",
3917 as->parms[0].items->data);
3923 VolumeInfoCmd(char *name)
3925 struct nvldbentry entry;
3928 /* The vlserver will handle names with the .readonly
3929 * and .backup extension as well as volume ids.
3931 vcode = VLDB_GetEntryByName(name, &entry);
3933 PrintError("", vcode);
3936 MapHostToNetwork(&entry);
3937 EnumerateEntry(&entry);
3939 /* Defect #3027: grubby check to handle locked volume.
3940 * If VLOP_ALLOPERS is set, the entry is locked.
3941 * Leave this routine as is, but put in correct check.
3943 PrintLocked(entry.flags);
3949 VolumeZap(struct cmd_syndesc *as, void *arock)
3951 struct nvldbentry entry;
3952 afs_uint32 volid, zapbackupid = 0, backupid = 0;
3953 afs_int32 code, server, part, err;
3955 if (as->parms[3].items) {
3956 /* force flag is on, use the other version */
3957 return NukeVolume(as);
3960 if (as->parms[4].items) {
3964 volid = vsu_GetVolumeID(as->parms[2].items->data, cstruct, &err);
3967 PrintError("", err);
3969 fprintf(STDERR, "vos: can't find volume '%s'\n",
3970 as->parms[2].items->data);
3973 part = volutil_GetPartitionID(as->parms[1].items->data);
3975 fprintf(STDERR, "vos: could not interpret partition name '%s'\n",
3976 as->parms[1].items->data);
3979 server = GetServer(as->parms[0].items->data);
3981 fprintf(STDERR, "vos: host '%s' not found in host table\n",
3982 as->parms[0].items->data);
3985 if (!IsPartValid(part, server, &code)) { /*check for validity of the partition */
3987 PrintError("", code);
3990 "vos : partition %s does not exist on the server\n",
3991 as->parms[1].items->data);
3994 code = VLDB_GetEntryByID(volid, -1, &entry);
3996 if (volid == entry.volumeId[RWVOL])
3997 backupid = entry.volumeId[BACKVOL];
3999 "Warning: Entry for volume number %lu exists in VLDB (but we're zapping it anyway!)\n",
4000 (unsigned long)volid);
4003 volintInfo *pntr = (volintInfo *) 0;
4006 code = UV_ListOneVolume(server, part, volid, &pntr);
4008 if (volid == pntr->parentID)
4009 backupid = pntr->backupID;
4015 code = UV_VolumeZap(server, part, backupid);
4017 PrintDiagnostics("zap", code);
4020 fprintf(STDOUT, "Backup Volume %lu deleted\n",
4021 (unsigned long)backupid);
4024 code = UV_VolumeZap(server, part, volid);
4026 PrintDiagnostics("zap", code);
4029 fprintf(STDOUT, "Volume %lu deleted\n", (unsigned long)volid);
4035 VolserStatus(struct cmd_syndesc *as, void *arock)
4039 transDebugInfo *pntr, *oldpntr;
4045 server = GetServer(as->parms[0].items->data);
4047 fprintf(STDERR, "vos: host '%s' not found in host table\n",
4048 as->parms[0].items->data);
4051 code = UV_VolserStatus(server, &pntr, &count);
4053 PrintDiagnostics("status", code);
4058 fprintf(STDOUT, "No active transactions on %s\n",
4059 as->parms[0].items->data);
4061 fprintf(STDOUT, "Total transactions: %d\n", count);
4063 for (i = 0; i < count; i++) {
4064 /*print out the relevant info */
4065 fprintf(STDOUT, "--------------------------------------\n");
4066 t = pntr->creationTime;
4067 fprintf(STDOUT, "transaction: %lu created: %s",
4068 (unsigned long)pntr->tid, ctime(&t));
4070 fprintf(STDOUT, "lastActiveTime: %s", ctime(&t));
4071 if (pntr->returnCode) {
4072 fprintf(STDOUT, "returnCode: %lu\n",
4073 (unsigned long)pntr->returnCode);
4076 fprintf(STDOUT, "attachFlags: ");
4077 switch (pntr->iflags) {
4079 fprintf(STDOUT, "offline ");
4082 fprintf(STDOUT, "busy ");
4085 fprintf(STDOUT, "readonly ");
4088 fprintf(STDOUT, "create ");
4091 fprintf(STDOUT, "create volid ");
4094 fprintf(STDOUT, "\n");
4097 fprintf(STDOUT, "volumeStatus: ");
4098 switch (pntr->vflags) {
4099 case VTDeleteOnSalvage:
4100 fprintf(STDOUT, "deleteOnSalvage ");
4101 case VTOutOfService:
4102 fprintf(STDOUT, "outOfService ");
4104 fprintf(STDOUT, "deleted ");
4106 fprintf(STDOUT, "\n");
4109 fprintf(STDOUT, "transactionFlags: ");
4110 fprintf(STDOUT, "delete\n");
4112 MapPartIdIntoName(pntr->partition, pname);
4113 fprintf(STDOUT, "volume: %lu partition: %s procedure: %s\n",
4114 (unsigned long)pntr->volid, pname, pntr->lastProcName);
4115 if (pntr->callValid) {
4116 t = pntr->lastReceiveTime;
4117 fprintf(STDOUT, "packetRead: %lu lastReceiveTime: %s",
4118 (unsigned long)pntr->readNext, ctime(&t));
4119 t = pntr->lastSendTime;
4120 fprintf(STDOUT, "packetSend: %lu lastSendTime: %s",
4121 (unsigned long)pntr->transmitNext, ctime(&t));
4124 fprintf(STDOUT, "--------------------------------------\n");
4125 fprintf(STDOUT, "\n");
4133 RenameVolume(struct cmd_syndesc *as, void *arock)
4135 afs_int32 code1, code2, code;
4136 struct nvldbentry entry;
4138 code1 = VLDB_GetEntryByName(as->parms[0].items->data, &entry);
4140 fprintf(STDERR, "vos: Could not find entry for volume %s\n",
4141 as->parms[0].items->data);
4144 code2 = VLDB_GetEntryByName(as->parms[1].items->data, &entry);
4145 if ((!code1) && (!code2)) { /*the newname already exists */
4146 fprintf(STDERR, "vos: volume %s already exists\n",
4147 as->parms[1].items->data);
4151 if (code1 && code2) {
4152 fprintf(STDERR, "vos: Could not find entry for volume %s or %s\n",
4153 as->parms[0].items->data, as->parms[1].items->data);
4156 if (!VolNameOK(as->parms[0].items->data)) {
4158 "Illegal volume name %s, should not end in .readonly or .backup\n",
4159 as->parms[0].items->data);
4162 if (!ISNAMEVALID(as->parms[1].items->data)) {
4164 "vos: the new volume name %s exceeds the size limit of %d\n",
4165 as->parms[1].items->data, VOLSER_OLDMAXVOLNAME - 10);
4168 if (!VolNameOK(as->parms[1].items->data)) {
4170 "Illegal volume name %s, should not end in .readonly or .backup\n",
4171 as->parms[1].items->data);
4174 if (IsNumeric(as->parms[1].items->data)) {
4175 fprintf(STDERR, "Illegal volume name %s, should not be a number\n",
4176 as->parms[1].items->data);
4179 MapHostToNetwork(&entry);
4181 UV_RenameVolume(&entry, as->parms[0].items->data,
4182 as->parms[1].items->data);
4184 PrintDiagnostics("rename", code);
4187 fprintf(STDOUT, "Renamed volume %s to %s\n", as->parms[0].items->data,
4188 as->parms[1].items->data);
4193 GetVolumeInfo(afs_uint32 volid, afs_uint32 *server, afs_int32 *part, afs_int32 *voltype,
4194 struct nvldbentry *rentry)
4199 vcode = VLDB_GetEntryByID(volid, -1, rentry);
4202 "Could not fetch the entry for volume %lu from VLDB \n",
4203 (unsigned long)volid);
4204 PrintError("", vcode);
4207 MapHostToNetwork(rentry);
4208 if (volid == rentry->volumeId[ROVOL]) {
4210 for (i = 0; i < rentry->nServers; i++) {
4211 if ((index == -1) && (rentry->serverFlags[i] & ITSROVOL)
4212 && !(rentry->serverFlags[i] & RO_DONTUSE))
4217 "RO volume is not found in VLDB entry for volume %lu\n",
4218 (unsigned long)volid);
4222 *server = rentry->serverNumber[index];
4223 *part = rentry->serverPartition[index];
4227 index = Lp_GetRwIndex(rentry);
4230 "RW Volume is not found in VLDB entry for volume %lu\n",
4231 (unsigned long)volid);
4234 if (volid == rentry->volumeId[RWVOL]) {
4236 *server = rentry->serverNumber[index];
4237 *part = rentry->serverPartition[index];
4240 if (volid == rentry->volumeId[BACKVOL]) {
4242 *server = rentry->serverNumber[index];
4243 *part = rentry->serverPartition[index];
4247 "unexpected volume type for volume %lu\n",
4248 (unsigned long)volid);
4253 DeleteEntry(struct cmd_syndesc *as, void *arock)
4255 afs_int32 apart = 0;
4258 struct VldbListByAttributes attributes;
4259 nbulkentries arrayEntries;
4260 struct nvldbentry *vllist;
4261 struct cmd_item *itp;
4264 char prefix[VOLSER_MAXVOLNAME + 1];
4266 afs_int32 totalBack = 0, totalFail = 0, err;
4268 if (as->parms[0].items) { /* -id */
4269 if (as->parms[1].items || as->parms[2].items || as->parms[3].items) {
4271 "You cannot use -server, -partition, or -prefix with the -id argument\n");
4274 for (itp = as->parms[0].items; itp; itp = itp->next) {
4275 avolid = vsu_GetVolumeID(itp->data, cstruct, &err);
4278 PrintError("", err);
4280 fprintf(STDERR, "vos: can't find volume '%s'\n",
4284 if (as->parms[4].items || as->parms[5].items) {
4285 /* -noexecute (hidden) or -dryrun */
4286 fprintf(STDOUT, "Would have deleted VLDB entry for %s \n",
4291 vcode = ubik_VL_DeleteEntry(cstruct, 0, avolid, RWVOL);
4293 fprintf(STDERR, "Could not delete entry for volume %s\n",
4296 "You must specify a RW volume name or ID "
4297 "(the entire VLDB entry will be deleted)\n");
4298 PrintError("", vcode);
4304 fprintf(STDOUT, "Deleted %d VLDB entries\n", totalBack);
4308 if (!as->parms[1].items && !as->parms[2].items && !as->parms[3].items) {
4309 fprintf(STDERR, "You must specify an option\n");
4313 /* Zero out search attributes */
4314 memset(&attributes, 0, sizeof(struct VldbListByAttributes));
4316 if (as->parms[1].items) { /* -prefix */
4317 strncpy(prefix, as->parms[1].items->data, VOLSER_MAXVOLNAME);
4319 if (!as->parms[2].items && !as->parms[3].items) { /* a single entry only */
4321 "You must provide -server with the -prefix argument\n");
4326 if (as->parms[2].items) { /* -server */
4328 aserver = GetServer(as->parms[2].items->data);
4330 fprintf(STDERR, "vos: server '%s' not found in host table\n",
4331 as->parms[2].items->data);
4334 attributes.server = ntohl(aserver);
4335 attributes.Mask |= VLLIST_SERVER;
4338 if (as->parms[3].items) { /* -partition */
4339 if (!as->parms[2].items) {
4341 "You must provide -server with the -partition argument\n");
4344 apart = volutil_GetPartitionID(as->parms[3].items->data);
4346 fprintf(STDERR, "vos: could not interpret partition name '%s'\n",
4347 as->parms[3].items->data);
4350 attributes.partition = apart;
4351 attributes.Mask |= VLLIST_PARTITION;
4354 /* Print status line of what we are doing */
4355 fprintf(STDOUT, "Deleting VLDB entries for ");
4356 if (as->parms[2].items) {
4357 fprintf(STDOUT, "server %s ", as->parms[2].items->data);
4359 if (as->parms[3].items) {
4361 MapPartIdIntoName(apart, pname);
4362 fprintf(STDOUT, "partition %s ", pname);
4365 fprintf(STDOUT, "which are prefixed with %s ", prefix);
4367 fprintf(STDOUT, "\n");
4370 /* Get all the VLDB entries on a server and/or partition */
4371 memset(&arrayEntries, 0, sizeof(arrayEntries));
4372 vcode = VLDB_ListAttributes(&attributes, &nentries, &arrayEntries);
4374 fprintf(STDERR, "Could not access the VLDB for attributes\n");
4375 PrintError("", vcode);
4379 /* Process each entry */
4380 for (j = 0; j < nentries; j++) {
4381 vllist = &arrayEntries.nbulkentries_val[j];
4383 /* It only deletes the RW volumes */
4384 if (strncmp(vllist->name, prefix, strlen(prefix))) {
4387 "Omitting to delete %s due to prefix %s mismatch\n",
4388 vllist->name, prefix);
4395 if (as->parms[4].items || as->parms[5].items) {
4396 /* -noexecute (hidden) or -dryrun */
4397 fprintf(STDOUT, "Would have deleted VLDB entry for %s \n",
4403 /* Only matches the RW volume name */
4404 avolid = vllist->volumeId[RWVOL];
4405 vcode = ubik_VL_DeleteEntry(cstruct, 0, avolid, RWVOL);
4407 fprintf(STDOUT, "Could not delete VLDB entry for %s\n",
4410 PrintError("", vcode);
4415 fprintf(STDOUT, "Deleted VLDB entry for %s \n", vllist->name);
4420 fprintf(STDOUT, "----------------------\n");
4422 "Total VLDB entries deleted: %lu; failed to delete: %lu\n",
4423 (unsigned long)totalBack, (unsigned long)totalFail);
4425 xdr_free((xdrproc_t) xdr_nbulkentries, &arrayEntries);
4431 CompareVldbEntryByName(const void *p1, const void *p2)
4433 struct nvldbentry *arg1, *arg2;
4435 arg1 = (struct nvldbentry *)p1;
4436 arg2 = (struct nvldbentry *)p2;
4437 return (strcmp(arg1->name, arg2->name));
4441 static int CompareVldbEntry(char *p1, char *p2)
4443 struct nvldbentry *arg1,*arg2;
4446 char comp1[100],comp2[100];
4447 char temp1[20],temp2[20];
4449 arg1 = (struct nvldbentry *)p1;
4450 arg2 = (struct nvldbentry *)p2;
4454 for(i = 0; i < arg1->nServers; i++)
4455 if(arg1->serverFlags[i] & ITSRWVOL) pos1 = i;
4456 for(i = 0; i < arg2->nServers; i++)
4457 if(arg2->serverFlags[i] & ITSRWVOL) pos2 = i;
4458 if(pos1 == -1 || pos2 == -1){
4462 sprintf(comp1,"%10u",arg1->serverNumber[pos1]);
4463 sprintf(comp2,"%10u",arg2->serverNumber[pos2]);
4464 sprintf(temp1,"%10u",arg1->serverPartition[pos1]);
4465 sprintf(temp2,"%10u",arg2->serverPartition[pos2]);
4466 strcat(comp1,temp1);
4467 strcat(comp2,temp2);
4468 strcat(comp1,arg1->name);
4469 strcat(comp1,arg2->name);
4470 return(strcmp(comp1,comp2));
4476 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;
4496 attributes.Mask = 0;
4497 lock = (as->parms[3].items ? 1 : 0); /* -lock flag */
4498 quiet = (as->parms[4].items ? 1 : 0); /* -quit flag */
4499 sort = (as->parms[5].items ? 0 : 1); /* -nosort flag */
4501 /* If the volume name is given, Use VolumeInfoCmd to look it up
4502 * and not ListAttributes.
4504 if (as->parms[0].items) {
4507 "vos: illegal use of '-locked' switch, need to specify server and/or partition\n");
4510 code = VolumeInfoCmd(as->parms[0].items->data);
4512 PrintError("", code);
4518 /* Server specified */
4519 if (as->parms[1].items) {
4520 aserver = GetServer(as->parms[1].items->data);
4522 fprintf(STDERR, "vos: server '%s' not found in host table\n",
4523 as->parms[1].items->data);
4526 attributes.server = ntohl(aserver);
4527 attributes.Mask |= VLLIST_SERVER;
4530 /* Partition specified */
4531 if (as->parms[2].items) {
4532 apart = volutil_GetPartitionID(as->parms[2].items->data);
4534 fprintf(STDERR, "vos: could not interpret partition name '%s'\n",
4535 as->parms[2].items->data);
4538 attributes.partition = apart;
4539 attributes.Mask |= VLLIST_PARTITION;
4543 attributes.Mask |= VLLIST_FLAG;
4544 attributes.flag = VLOP_ALLOPERS;
4547 /* Print header information */
4549 MapPartIdIntoName(apart, pname);
4550 fprintf(STDOUT, "VLDB entries for %s %s%s%s %s\n",
4551 (as->parms[1].items ? "server" : "all"),
4552 (as->parms[1].items ? as->parms[1].items->data : "servers"),
4553 (as->parms[2].items ? " partition " : ""),
4554 (as->parms[2].items ? pname : ""),
4555 (lock ? "which are locked:" : ""));
4558 for (thisindex = 0; (thisindex != -1); thisindex = nextindex) {
4559 memset(&arrayEntries, 0, sizeof(arrayEntries));
4564 VLDB_ListAttributesN2(&attributes, 0, thisindex, ¢ries,
4565 &arrayEntries, &nextindex);
4566 if (vcode == RXGEN_OPCODE) {
4567 /* Vlserver not running with ListAttributesN2. Fall back */
4569 VLDB_ListAttributes(&attributes, ¢ries, &arrayEntries);
4573 fprintf(STDERR, "Could not access the VLDB for attributes\n");
4574 PrintError("", vcode);
4577 nentries += centries;
4579 /* We don't sort, so just print the entries now */
4581 for (j = 0; j < centries; j++) { /* process each entry */
4582 vllist = &arrayEntries.nbulkentries_val[j];
4583 MapHostToNetwork(vllist);
4584 EnumerateEntry(vllist);
4586 PrintLocked(vllist->flags);
4590 /* So we sort. First we must collect all the entries and keep
4593 else if (centries > 0) {
4595 /* malloc the first bulk entries array */
4596 tarraysize = centries * sizeof(struct nvldbentry);
4597 tarray = malloc(tarraysize);
4600 "Could not allocate enough space for the VLDB entries\n");
4603 memcpy((char*)tarray, arrayEntries.nbulkentries_val, tarraysize);
4605 /* Grow the tarray to keep the extra entries */
4606 parraysize = (centries * sizeof(struct nvldbentry));
4607 ttarray = realloc(tarray, tarraysize + parraysize);
4610 "Could not allocate enough space for the VLDB entries\n");
4616 memcpy(((char *)tarray) + tarraysize,
4617 (char *)arrayEntries.nbulkentries_val, parraysize);
4618 tarraysize += parraysize;
4622 /* Free the bulk array */
4623 xdr_free((xdrproc_t) xdr_nbulkentries, &arrayEntries);
4626 /* Here is where we now sort all the entries and print them */
4627 if (sort && (nentries > 0)) {
4628 qsort((char *)tarray, nentries, sizeof(struct nvldbentry),
4629 CompareVldbEntryByName);
4630 for (vllist = tarray, j = 0; j < nentries; j++, vllist++) {
4631 MapHostToNetwork(vllist);
4632 EnumerateEntry(vllist);
4634 PrintLocked(vllist->flags);
4640 fprintf(STDOUT, "\nTotal entries: %lu\n", (unsigned long)nentries);
4647 BackSys(struct cmd_syndesc *as, void *arock)
4650 afs_int32 apart = 0;
4651 afs_uint32 aserver = 0, aserver1;
4652 afs_int32 code, apart1;
4654 struct VldbListByAttributes attributes;
4655 nbulkentries arrayEntries;
4656 struct nvldbentry *vllist;
4660 int seenprefix, seenxprefix, exclude, ex, exp, noaction;
4661 afs_int32 totalBack = 0;
4662 afs_int32 totalFail = 0;
4666 struct cmd_item *ti;
4668 #ifndef HAVE_POSIX_REGEX
4672 memset(&attributes, 0, sizeof(struct VldbListByAttributes));
4673 attributes.Mask = 0;
4675 seenprefix = (as->parms[0].items ? 1 : 0);
4676 exclude = (as->parms[3].items ? 1 : 0);
4677 seenxprefix = (as->parms[4].items ? 1 : 0);
4678 noaction = (as->parms[5].items ? 1 : 0);
4680 if (as->parms[1].items) { /* -server */
4681 aserver = GetServer(as->parms[1].items->data);
4683 fprintf(STDERR, "vos: server '%s' not found in host table\n",
4684 as->parms[1].items->data);
4687 attributes.server = ntohl(aserver);
4688 attributes.Mask |= VLLIST_SERVER;
4691 if (as->parms[2].items) { /* -partition */
4692 apart = volutil_GetPartitionID(as->parms[2].items->data);
4694 fprintf(STDERR, "vos: could not interpret partition name '%s'\n",
4695 as->parms[2].items->data);
4698 attributes.partition = apart;
4699 attributes.Mask |= VLLIST_PARTITION;
4702 /* Check to make sure the prefix and xprefix expressions compile ok */
4704 for (ti = as->parms[0].items; ti; ti = ti->next) {
4705 if (strncmp(ti->data, "^", 1) == 0) {
4706 #ifdef HAVE_POSIX_REGEX
4710 code = regcomp(&re, ti->data, REG_NOSUB);
4712 regerror(code, &re, errbuf, sizeof errbuf);
4714 "Unrecognizable -prefix regular expression: '%s': %s\n",
4720 ccode = (char *)re_comp(ti->data);
4723 "Unrecognizable -prefix regular expression: '%s': %s\n",
4732 for (ti = as->parms[4].items; ti; ti = ti->next) {
4733 if (strncmp(ti->data, "^", 1) == 0) {
4734 #ifdef HAVE_POSIX_REGEX
4738 code = regcomp(&re, ti->data, REG_NOSUB);
4740 regerror(code, &re, errbuf, sizeof errbuf);
4742 "Unrecognizable -xprefix regular expression: '%s': %s\n",
4748 ccode = (char *)re_comp(ti->data);
4751 "Unrecognizable -xprefix regular expression: '%s': %s\n",
4760 memset(&arrayEntries, 0, sizeof(arrayEntries)); /* initialize to hint the stub to alloc space */
4761 vcode = VLDB_ListAttributes(&attributes, &nentries, &arrayEntries);
4763 fprintf(STDERR, "Could not access the VLDB for attributes\n");
4764 PrintError("", vcode);
4768 if (as->parms[1].items || as->parms[2].items || verbose) {
4769 fprintf(STDOUT, "%s up volumes",
4770 (noaction ? "Would have backed" : "Backing"));
4772 if (as->parms[1].items) {
4773 fprintf(STDOUT, " on server %s", as->parms[1].items->data);
4774 } else if (as->parms[2].items) {
4775 fprintf(STDOUT, " for all servers");
4778 if (as->parms[2].items) {
4779 MapPartIdIntoName(apart, pname);
4780 fprintf(STDOUT, " partition %s", pname);
4783 if (seenprefix || (!seenprefix && seenxprefix)) {
4784 ti = (seenprefix ? as->parms[0].items : as->parms[4].items);
4785 ex = (seenprefix ? exclude : !exclude);
4786 exp = (strncmp(ti->data, "^", 1) == 0);
4787 fprintf(STDOUT, " which %smatch %s '%s'", (ex ? "do not " : ""),
4788 (exp ? "expression" : "prefix"), ti->data);
4789 for (ti = ti->next; ti; ti = ti->next) {
4790 exp = (strncmp(ti->data, "^", 1) == 0);
4791 printf(" %sor %s '%s'", (ex ? "n" : ""),
4792 (exp ? "expression" : "prefix"), ti->data);
4796 if (seenprefix && seenxprefix) {
4797 ti = as->parms[4].items;
4798 exp = (strncmp(ti->data, "^", 1) == 0);
4799 fprintf(STDOUT, " %swhich match %s '%s'",
4800 (exclude ? "adding those " : "removing those "),
4801 (exp ? "expression" : "prefix"), ti->data);
4802 for (ti = ti->next; ti; ti = ti->next) {
4803 exp = (strncmp(ti->data, "^", 1) == 0);
4804 printf(" or %s '%s'", (exp ? "expression" : "prefix"),
4808 fprintf(STDOUT, " .. ");
4810 fprintf(STDOUT, "\n");
4814 for (j = 0; j < nentries; j++) { /* process each vldb entry */
4815 vllist = &arrayEntries.nbulkentries_val[j];
4818 for (ti = as->parms[0].items; ti; ti = ti->next) {
4819 if (strncmp(ti->data, "^", 1) == 0) {
4820 #ifdef HAVE_POSIX_REGEX
4824 /* XXX -- should just do the compile once! */
4825 code = regcomp(&re, ti->data, REG_NOSUB);
4827 regerror(code, &re, errbuf, sizeof errbuf);
4829 "Error in -prefix regular expression: '%s': %s\n",
4833 match = (regexec(&re, vllist->name, 0, NULL, 0) == 0);
4836 ccode = (char *)re_comp(ti->data);
4839 "Error in -prefix regular expression: '%s': %s\n",
4843 match = (re_exec(vllist->name) == 1);
4847 (strncmp(vllist->name, ti->data, strlen(ti->data)) ==
4857 /* Without the -exclude flag: If it matches the prefix, then
4858 * check if we want to exclude any from xprefix.
4859 * With the -exclude flag: If it matches the prefix, then
4860 * check if we want to add any from xprefix.
4862 if (match && seenxprefix) {
4863 for (ti = as->parms[4].items; ti; ti = ti->next) {
4864 if (strncmp(ti->data, "^", 1) == 0) {
4865 #ifdef HAVE_POSIX_REGEX
4869 /* XXX -- should just do the compile once! */
4870 code = regcomp(&re, ti->data, REG_NOSUB);
4872 regerror(code, &re, errbuf, sizeof errbuf);
4874 "Error in -xprefix regular expression: '%s': %s\n",
4878 if (regexec(&re, vllist->name, 0, NULL, 0) == 0)
4882 ccode = (char *)re_comp(ti->data);
4885 "Error in -xprefix regular expression: '%s': %s\n",
4889 if (re_exec(vllist->name) == 1) {
4895 if (strncmp(vllist->name, ti->data, strlen(ti->data)) ==
4905 match = !match; /* -exclude will reverse the match */
4907 continue; /* Skip if no match */
4909 /* Print list of volumes to backup */
4911 fprintf(STDOUT, " %s\n", vllist->name);
4915 if (!(vllist->flags & RW_EXISTS)) {
4918 "Omitting to backup %s since RW volume does not exist \n",
4920 fprintf(STDOUT, "\n");
4926 avolid = vllist->volumeId[RWVOL];
4927 MapHostToNetwork(vllist);
4928 GetServerAndPart(vllist, RWVOL, &aserver1, &apart1, &previdx);
4929 if (aserver1 == -1 || apart1 == -1) {
4930 fprintf(STDOUT, "could not backup %s, invalid VLDB entry\n",
4936 same = VLDB_IsSameAddrs(aserver, aserver1, &error);
4939 "Failed to get info about server's %d address(es) from vlserver (err=%d); aborting call!\n",
4945 if ((aserver && !same) || (apart && (apart != apart1))) {
4948 "Omitting to backup %s since the RW is in a different location\n",
4954 time_t now = time(0);
4955 fprintf(STDOUT, "Creating backup volume for %s on %s",
4956 vllist->name, ctime(&now));
4960 code = UV_BackupVolume(aserver1, apart1, avolid);
4962 fprintf(STDOUT, "Could not backup %s\n", vllist->name);
4968 fprintf(STDOUT, "\n");
4970 } /* process each vldb entry */
4971 fprintf(STDOUT, "done\n");
4972 fprintf(STDOUT, "Total volumes backed up: %lu; failed to backup: %lu\n",
4973 (unsigned long)totalBack, (unsigned long)totalFail);
4975 xdr_free((xdrproc_t) xdr_nbulkentries, &arrayEntries);
4980 UnlockVLDB(struct cmd_syndesc *as, void *arock)
4983 afs_uint32 aserver = 0;
4986 struct VldbListByAttributes attributes;
4987 nbulkentries arrayEntries;
4988 struct nvldbentry *vllist;
4997 attributes.Mask = 0;
4999 if (as->parms[0].items) { /* server specified */
5000 aserver = GetServer(as->parms[0].items->data);
5002 fprintf(STDERR, "vos: server '%s' not found in host table\n",
5003 as->parms[0].items->data);
5006 attributes.server = ntohl(aserver);
5007 attributes.Mask |= VLLIST_SERVER;
5009 if (as->parms[1].items) { /* partition specified */
5010 apart = volutil_GetPartitionID(as->parms[1].items->data);
5012 fprintf(STDERR, "vos: could not interpret partition name '%s'\n",
5013 as->parms[1].items->data);
5016 if (!IsPartValid(apart, aserver, &code)) { /*check for validity of the partition */
5018 PrintError("", code);
5021 "vos : partition %s does not exist on the server\n",
5022 as->parms[1].items->data);
5025 attributes.partition = apart;
5026 attributes.Mask |= VLLIST_PARTITION;
5028 attributes.flag = VLOP_ALLOPERS;
5029 attributes.Mask |= VLLIST_FLAG;
5030 memset(&arrayEntries, 0, sizeof(arrayEntries)); /*initialize to hint the stub to alloc space */
5031 vcode = VLDB_ListAttributes(&attributes, &nentries, &arrayEntries);
5033 fprintf(STDERR, "Could not access the VLDB for attributes\n");
5034 PrintError("", vcode);
5037 for (j = 0; j < nentries; j++) { /* process each entry */
5038 vllist = &arrayEntries.nbulkentries_val[j];
5039 volid = vllist->volumeId[RWVOL];
5041 ubik_VL_ReleaseLock(cstruct, 0, volid, -1,
5042 LOCKREL_OPCODE | LOCKREL_AFSID |
5045 fprintf(STDERR, "Could not unlock entry for volume %s\n",
5047 PrintError("", vcode);
5052 MapPartIdIntoName(apart, pname);
5055 "Could not lock %lu VLDB entries of %lu locked entries\n",
5056 (unsigned long)totalE, (unsigned long)nentries);
5058 if (as->parms[0].items) {
5060 "Unlocked all the VLDB entries for volumes on server %s ",
5061 as->parms[0].items->data);
5062 if (as->parms[1].items) {
5063 MapPartIdIntoName(apart, pname);
5064 fprintf(STDOUT, "partition %s\n", pname);
5066 fprintf(STDOUT, "\n");
5068 } else if (as->parms[1].items) {
5069 MapPartIdIntoName(apart, pname);
5071 "Unlocked all the VLDB entries for volumes on partition %s on all servers\n",
5076 xdr_free((xdrproc_t) xdr_nbulkentries, &arrayEntries);
5081 PrintInt64Size(afs_uint64 in)
5085 static char output[16];
5087 SplitInt64(in,hi,lo);
5091 } else if (!(hi & 0xFFFFFC00)) {
5093 lo = (hi << 22) | (lo >> 10);
5094 } else if (!(hi & 0xFFF00000)) {
5096 lo = (hi << 12) | (lo >> 20);
5097 } else if (!(hi & 0xC0000000)) {
5099 lo = (hi << 2) | (lo >> 30);
5104 sprintf(output,"%u %s", lo, units);
5109 PartitionInfo(struct cmd_syndesc *as, void *arock)
5115 struct diskPartition64 partition;
5116 struct partList dummyPartList;
5118 int printSummary=0, sumPartitions=0;
5119 afs_uint64 sumFree, sumStorage;
5122 ZeroInt64(sumStorage);
5124 aserver = GetServer(as->parms[0].items->data);
5126 fprintf(STDERR, "vos: server '%s' not found in host table\n",
5127 as->parms[0].items->data);
5130 if (as->parms[1].items) {
5131 apart = volutil_GetPartitionID(as->parms[1].items->data);
5133 fprintf(STDERR, "vos: could not interpret partition name '%s'\n",
5134 as->parms[1].items->data);
5137 dummyPartList.partId[0] = apart;
5138 dummyPartList.partFlags[0] = PARTVALID;
5141 if (as->parms[2].items) {
5145 if (!IsPartValid(apart, aserver, &code)) { /*check for validity of the partition */
5147 PrintError("", code);
5150 "vos : partition %s does not exist on the server\n",
5151 as->parms[1].items->data);
5155 code = UV_ListPartitions(aserver, &dummyPartList, &cnt);
5157 PrintDiagnostics("listpart", code);
5161 for (i = 0; i < cnt; i++) {
5162 if (dummyPartList.partFlags[i] & PARTVALID) {
5163 MapPartIdIntoName(dummyPartList.partId[i], pname);
5164 code = UV_PartitionInfo64(aserver, pname, &partition);
5166 fprintf(STDERR, "Could not get information on partition %s\n",
5168 PrintError("", code);
5172 "Free space on partition %s: %" AFS_INT64_FMT " K blocks out of total %" AFS_INT64_FMT "\n",
5173 pname, partition.free, partition.minFree);
5175 AddUInt64(sumFree,partition.free,&sumFree);
5176 AddUInt64(sumStorage,partition.minFree,&sumStorage);
5181 "Summary: %s free out of ",
5182 PrintInt64Size(sumFree));
5184 "%s on %d partitions\n",
5185 PrintInt64Size(sumStorage),
5192 ChangeAddr(struct cmd_syndesc *as, void *arock)
5194 afs_int32 ip1, ip2, vcode;
5198 ip1 = GetServerNoresolve(as->parms[0].items->data);
5200 ip1 = GetServer(as->parms[0].items->data);
5202 fprintf(STDERR, "vos: invalid host address\n");
5206 if ((as->parms[1].items && as->parms[2].items)
5207 || (!as->parms[1].items && !as->parms[2].items)) {
5209 "vos: Must specify either '-newaddr <addr>' or '-remove' flag\n");
5213 if (as->parms[1].items) {
5215 ip2 = GetServerNoresolve(as->parms[1].items->data);
5217 ip2 = GetServer(as->parms[1].items->data);
5219 fprintf(STDERR, "vos: invalid host address\n");
5223 /* Play a trick here. If we are removing an address, ip1 will be -1
5224 * and ip2 will be the original address. This switch prevents an
5225 * older revision vlserver from removing the IP address.
5232 vcode = ubik_VL_ChangeAddr(cstruct, UBIK_CALL_NEW, ntohl(ip1), ntohl(ip2));
5234 char hoststr1[16], hoststr2[16];
5236 afs_inet_ntoa_r(ip2, hoststr2);
5237 fprintf(STDERR, "Could not remove server %s from the VLDB\n",
5239 if (vcode == VL_NOENT) {
5241 "vlserver does not support the remove flag or ");
5244 afs_inet_ntoa_r(ip1, hoststr1);
5245 afs_inet_ntoa_r(ip2, hoststr2);
5246 fprintf(STDERR, "Could not change server %s to server %s\n",
5247 hoststr1, hoststr2);
5249 PrintError("", vcode);
5254 fprintf(STDOUT, "Removed server %s from the VLDB\n",
5255 as->parms[0].items->data);
5257 fprintf(STDOUT, "Changed server %s to server %s\n",
5258 as->parms[0].items->data, as->parms[1].items->data);
5264 print_addrs(const bulkaddrs * addrs, afsUUID * m_uuid, int nentries,
5272 afsUUID_to_string(m_uuid, buf, sizeof(buf));
5273 printf("UUID: %s\n", buf);
5276 /* print out the list of all the server */
5277 addrp = (afs_uint32 *) addrs->bulkaddrs_val;
5278 for (i = 0; i < nentries; i++, addrp++) {
5279 *addrp = htonl(*addrp);
5282 printf("%s\n", afs_inet_ntoa_r(*addrp, hoststr));
5284 printf("%s\n", hostutil_GetNameByINet(*addrp));
5295 ListAddrs(struct cmd_syndesc *as, void *arock)
5297 afs_int32 vcode, m_uniq=0;
5298 afs_int32 i, printuuid = 0;
5299 struct VLCallBack vlcb;
5302 ListAddrByAttributes m_attrs;
5303 afsUUID m_uuid, askuuid;
5304 afs_int32 m_nentries;
5306 if (as->parms[0].items && as->parms[1].items) {
5307 fprintf(STDERR, "vos: Can't use the -uuid and -host flags together\n");
5311 memset(&m_attrs, 0, sizeof(struct ListAddrByAttributes));
5312 memset(&askuuid, 0, sizeof(afsUUID));
5313 if (as->parms[0].items) {
5315 if (afsUUID_from_string(as->parms[0].items->data, &askuuid) < 0) {
5316 fprintf(STDERR, "vos: invalid UUID '%s'\n",
5317 as->parms[0].items->data);
5320 m_attrs.Mask = VLADDR_UUID;
5321 m_attrs.uuid = askuuid;
5322 } else if (as->parms[1].items) {
5326 he = hostutil_GetHostByName((char *)as->parms[1].items->data);
5328 fprintf(STDERR, "vos: Can't get host info for '%s'\n",
5329 as->parms[1].items->data);
5332 memcpy(&saddr, he->h_addr, 4);
5333 m_attrs.Mask = VLADDR_IPADDR;
5334 m_attrs.ipaddr = ntohl(saddr);
5337 m_attrs.Mask = VLADDR_INDEX;
5340 if (as->parms[2].items) {
5344 memset(&m_addrs, 0, sizeof(bulkaddrs));
5345 memset(&vlcb, 0, sizeof(struct VLCallBack));
5348 ubik_VL_GetAddrs(cstruct, UBIK_CALL_NEW, 0, 0, &vlcb, &nentries,
5351 fprintf(STDERR, "vos: could not list the server addresses\n");
5352 PrintError("", vcode);
5356 for (i = 1, m_nentries = 0; nentries; i++) {
5359 xdr_free((xdrproc_t)xdr_bulkaddrs, &m_addrs); /* reset addr list */
5361 ubik_VL_GetAddrsU(cstruct, UBIK_CALL_NEW, &m_attrs, &m_uuid,
5362 &m_uniq, &m_nentries, &m_addrs);
5364 case 0: /* success */
5365 print_addrs(&m_addrs, &m_uuid, m_nentries, printuuid);
5370 if (m_attrs.Mask == VLADDR_UUID) {
5371 fprintf(STDERR, "vos: no entry for UUID '%s' found in VLDB\n",
5372 as->parms[0].items->data);
5374 } else if (m_attrs.Mask == VLADDR_IPADDR) {
5375 fprintf(STDERR, "vos: no entry for host '%s' [0x%08x] found in VLDB\n",
5376 as->parms[1].items->data, m_attrs.ipaddr);
5381 case VL_INDEXERANGE:
5382 vcode = 0; /* not an error, just means we're done */
5385 default: /* any other error */
5386 fprintf(STDERR, "vos: could not list the server addresses\n");
5387 PrintError("", vcode);
5391 /* if -uuid or -host, only list one response */
5392 if (as->parms[1].items || as->parms[0].items)
5397 xdr_free((xdrproc_t)xdr_bulkaddrs, &m_addrs);
5403 SetAddrs(struct cmd_syndesc *as, void *arock)
5408 afs_uint32 FS_HostAddrs_HBO[ADDRSPERSITE];
5410 memset(&m_addrs, 0, sizeof(bulkaddrs));
5411 memset(&askuuid, 0, sizeof(afsUUID));
5412 if (as->parms[0].items) {
5414 if (afsUUID_from_string(as->parms[0].items->data, &askuuid) < 0) {
5415 fprintf(STDERR, "vos: invalid UUID '%s'\n",
5416 as->parms[0].items->data);
5420 if (as->parms[1].items) {
5422 struct cmd_item *ti;
5426 for (ti = as->parms[1].items; ti && i < ADDRSPERSITE; ti = ti->next) {
5429 saddr = GetServerNoresolve(ti->data);
5431 saddr = GetServer(ti->data);
5434 fprintf(STDERR, "vos: Can't get host info for '%s'\n",
5438 /* Convert it to host byte order */
5439 FS_HostAddrs_HBO[i] = ntohl(saddr);
5442 m_addrs.bulkaddrs_len = i;
5443 m_addrs.bulkaddrs_val = FS_HostAddrs_HBO;
5446 vcode = ubik_VL_RegisterAddrs(cstruct, 0, &askuuid, 0, &m_addrs);
5449 if (vcode == VL_MULTIPADDR) {
5450 fprintf(STDERR, "vos: VL_RegisterAddrs rpc failed; The IP address exists on a different server; repair it\n");
5451 } else if (vcode == RXGEN_OPCODE) {
5452 fprintf(STDERR, "vlserver doesn't support VL_RegisterAddrs rpc; ignored\n");
5454 fprintf(STDERR, "vos: VL_RegisterAddrs rpc failed\n");
5456 PrintError("", vcode);
5460 fprintf(STDOUT, "vos: Changed UUID with addresses:\n");
5461 print_addrs(&m_addrs, &askuuid, m_addrs.bulkaddrs_len, 1);
5467 LockEntry(struct cmd_syndesc *as, void *arock)
5470 afs_int32 vcode, err;
5472 avolid = vsu_GetVolumeID(as->parms[0].items->data, cstruct, &err);
5475 PrintError("", err);
5477 fprintf(STDERR, "vos: can't find volume '%s'\n",
5478 as->parms[0].items->data);
5481 vcode = ubik_VL_SetLock(cstruct, 0, avolid, -1, VLOP_DELETE);
5483 fprintf(STDERR, "Could not lock VLDB entry for volume %s\n",
5484 as->parms[0].items->data);
5485 PrintError("", vcode);
5488 fprintf(STDOUT, "Locked VLDB entry for volume %s\n",
5489 as->parms[0].items->data);
5494 ConvertRO(struct cmd_syndesc *as, void *arock)
5496 afs_int32 partition = -1;
5499 afs_int32 code, i, same;
5500 struct nvldbentry entry, checkEntry, storeEntry;
5502 afs_int32 rwindex = 0;
5503 afs_uint32 rwserver = 0;
5504 afs_int32 rwpartition = 0;
5505 afs_int32 roindex = 0;
5506 afs_uint32 roserver = 0;
5507 afs_int32 ropartition = 0;
5509 struct rx_connection *aconn;
5512 server = GetServer(as->parms[0].items->data);
5514 fprintf(STDERR, "vos: host '%s' not found in host table\n",
5515 as->parms[0].items->data);
5518 partition = volutil_GetPartitionID(as->parms[1].items->data);
5519 if (partition < 0) {
5520 fprintf(STDERR, "vos: could not interpret partition name '%s'\n",
5521 as->parms[1].items->data);
5524 if (!IsPartValid(partition, server, &code)) {
5526 PrintError("", code);
5529 "vos : partition %s does not exist on the server\n",
5530 as->parms[1].items->data);
5533 volid = vsu_GetVolumeID(as->parms[2].items->data, cstruct, &code);
5536 PrintError("", code);
5538 fprintf(STDERR, "Unknown volume ID or name '%s'\n",
5539 as->parms[2].items->data);
5542 if (as->parms[3].items)
5545 memset(&entry, 0, sizeof(entry));
5546 vcode = VLDB_GetEntryByID(volid, -1, &entry);
5549 "Could not fetch the entry for volume %lu from VLDB\n",
5550 (unsigned long)volid);
5551 PrintError("convertROtoRW ", vcode);
5555 /* use RO volid even if user specified RW or BK volid */
5556 if (volid != entry.volumeId[ROVOL])
5557 volid = entry.volumeId[ROVOL];
5559 MapHostToNetwork(&entry);
5560 for (i = 0; i < entry.nServers; i++) {
5561 if (entry.serverFlags[i] & ITSRWVOL) {
5563 rwserver = entry.serverNumber[i];
5564 rwpartition = entry.serverPartition[i];
5567 } else if ((entry.serverFlags[i] & ITSROVOL) && !roserver) {
5568 same = VLDB_IsSameAddrs(server, entry.serverNumber[i], &code);
5571 "Failed to get info about server's %d address(es) from vlserver (err=%d); aborting call!\n",
5577 roserver = entry.serverNumber[i];
5578 ropartition = entry.serverPartition[i];
5585 fprintf(STDERR, "Warning: RO volume didn't exist in vldb!\n");
5587 if (ropartition != partition) {
5589 "Warning: RO volume should be in partition %d instead of %d (vldb)\n",
5590 ropartition, partition);
5595 "VLDB indicates that a RW volume exists already on %s in partition %s.\n",
5596 hostutil_GetNameByINet(rwserver),
5597 volutil_PartitionName(rwpartition));
5599 fprintf(STDERR, "Overwrite this VLDB entry? [y|n] (n)\n");
5601 while (!(dc == EOF || dc == '\n'))
5602 dc = getchar(); /* goto end of line */
5603 if ((c != 'y') && (c != 'Y')) {
5604 fprintf(STDERR, "aborted.\n");
5611 ubik_VL_SetLock(cstruct, 0, entry.volumeId[RWVOL], RWVOL,
5615 "Unable to lock volume %lu, code %d\n",
5616 (unsigned long)entry.volumeId[RWVOL],vcode);
5617 PrintError("", vcode);
5621 /* make sure the VLDB entry hasn't changed since we started */
5622 memset(&checkEntry, 0, sizeof(checkEntry));
5623 vcode = VLDB_GetEntryByID(volid, -1, &checkEntry);
5626 "Could not fetch the entry for volume %lu from VLDB\n",
5627 (unsigned long)volid);
5628 PrintError("convertROtoRW ", vcode);
5633 MapHostToNetwork(&checkEntry);
5634 entry.flags &= ~VLOP_ALLOPERS; /* clear any stale lock operation flags */
5635 entry.flags |= VLOP_MOVE; /* set to match SetLock operation above */
5636 if (memcmp(&entry, &checkEntry, sizeof(entry)) != 0) {
5638 "VLDB entry for volume %lu has changed; please reissue the command.\n",
5639 (unsigned long)volid);
5644 aconn = UV_Bind(server, AFSCONF_VOLUMEPORT);
5645 code = AFSVolConvertROtoRWvolume(aconn, partition, volid);
5648 "Converting RO volume %lu to RW volume failed with code %d\n",
5649 (unsigned long)volid, code);
5650 PrintError("convertROtoRW ", code);
5653 entry.serverFlags[roindex] = ITSRWVOL;
5654 entry.flags |= RW_EXISTS;
5655 entry.flags &= ~BACK_EXISTS;
5658 if (rwindex != entry.nServers) {
5659 entry.serverNumber[rwindex] = entry.serverNumber[entry.nServers];
5660 entry.serverPartition[rwindex] =
5661 entry.serverPartition[entry.nServers];
5662 entry.serverFlags[rwindex] = entry.serverFlags[entry.nServers];
5663 entry.serverNumber[entry.nServers] = 0;
5664 entry.serverPartition[entry.nServers] = 0;
5665 entry.serverFlags[entry.nServers] = 0;
5668 entry.flags &= ~RO_EXISTS;
5669 for (i = 0; i < entry.nServers; i++) {
5670 if (entry.serverFlags[i] & ITSROVOL) {
5671 if (!(entry.serverFlags[i] & (RO_DONTUSE | NEW_REPSITE)))
5672 entry.flags |= RO_EXISTS;
5675 MapNetworkToHost(&entry, &storeEntry);
5677 VLDB_ReplaceEntry(entry.volumeId[RWVOL], RWVOL, &storeEntry,
5678 (LOCKREL_OPCODE | LOCKREL_AFSID |
5679 LOCKREL_TIMESTAMP));
5682 "Warning: volume converted, but vldb update failed with code %d!\n",
5687 vcode = UV_LockRelease(entry.volumeId[RWVOL]);
5690 "Unable to unlock volume %lu, code %d\n",
5691 (unsigned long)entry.volumeId[RWVOL],vcode);
5692 PrintError("", vcode);
5698 Sizes(struct cmd_syndesc *as, void *arock)
5702 afs_int32 apart, voltype, fromdate = 0, code, err, i;
5703 struct nvldbentry entry;
5704 volintSize vol_size;
5706 rx_SetRxDeadTime(60 * 10);
5707 for (i = 0; i < MAXSERVERS; i++) {
5708 struct rx_connection *rxConn = ubik_GetRPCConn(cstruct, i);
5711 rx_SetConnDeadTime(rxConn, rx_connDeadTime);
5712 if (rx_ServiceOf(rxConn))
5713 rx_ServiceOf(rxConn)->connDeadTime = rx_connDeadTime;
5716 avolid = vsu_GetVolumeID(as->parms[0].items->data, cstruct, &err);
5719 PrintError("", err);
5721 fprintf(STDERR, "vos: can't find volume '%s'\n",
5722 as->parms[0].items->data);
5726 if (as->parms[1].items || as->parms[2].items) {
5727 if (!as->parms[1].items || !as->parms[2].items) {
5729 "Must specify both -server and -partition options\n");
5732 aserver = GetServer(as->parms[2].items->data);
5734 fprintf(STDERR, "Invalid server name\n");
5737 apart = volutil_GetPartitionID(as->parms[1].items->data);
5739 fprintf(STDERR, "Invalid partition name\n");
5743 code = GetVolumeInfo(avolid, &aserver, &apart, &voltype, &entry);
5750 if (as->parms[4].items && strcmp(as->parms[4].items->data, "0")) {
5751 code = ktime_DateToInt32(as->parms[4].items->data, &fromdate);
5753 fprintf(STDERR, "vos: failed to parse date '%s' (error=%d))\n",
5754 as->parms[4].items->data, code);
5759 fprintf(STDOUT, "Volume: %s\n", as->parms[0].items->data);
5761 if (as->parms[3].items) { /* do the dump estimate */
5762 vol_size.dump_size = 0;
5763 code = UV_GetSize(avolid, aserver, apart, fromdate, &vol_size);
5765 PrintDiagnostics("size", code);
5768 /* presumably the size info is now gathered in pntr */
5769 /* now we display it */
5771 fprintf(STDOUT, "dump_size: %llu\n", vol_size.dump_size);
5780 EndTrans(struct cmd_syndesc *as, void *arock)
5783 afs_int32 code, tid, rcode;
5784 struct rx_connection *aconn;
5786 server = GetServer(as->parms[0].items->data);
5788 fprintf(STDERR, "vos: host '%s' not found in host table\n",
5789 as->parms[0].items->data);
5793 code = util_GetInt32(as->parms[1].items->data, &tid);
5795 fprintf(STDERR, "vos: bad integer specified for transaction ID.\n");
5799 aconn = UV_Bind(server, AFSCONF_VOLUMEPORT);
5800 code = AFSVolEndTrans(aconn, tid, &rcode);
5806 PrintDiagnostics("endtrans", code);
5814 PrintDiagnostics(char *astring, afs_int32 acode)
5816 if (acode == EACCES) {
5818 "You are not authorized to perform the 'vos %s' command (%d)\n",
5821 fprintf(STDERR, "Error in vos %s command.\n", astring);
5822 PrintError("", acode);
5830 win32_enableCrypt(void)
5837 /* Look up configuration parameters in Registry */
5838 code = RegOpenKeyEx(HKEY_LOCAL_MACHINE, AFSREG_CLT_SVC_PARAM_SUBKEY,
5839 0, (IsWow64()?KEY_WOW64_64KEY:0)|KEY_QUERY_VALUE, &parmKey);
5840 if (code != ERROR_SUCCESS) {
5841 dummyLen = sizeof(cryptall);
5842 RegQueryValueEx(parmKey, "SecurityLevel", NULL, NULL,
5843 (BYTE *) &cryptall, &dummyLen);
5845 RegCloseKey (parmKey);
5849 #endif /* AFS_NT40_ENV */
5852 MyBeforeProc(struct cmd_syndesc *as, void *arock)
5858 /* Initialize the ubik_client connection */
5859 rx_SetRxDeadTime(90);
5861 secFlags = AFSCONF_SECOPTS_FALLBACK_NULL;
5864 if (as->parms[12].items) /* if -cell specified */
5865 tcell = as->parms[12].items->data;
5867 if (as->parms[13].items)
5868 secFlags |= AFSCONF_SECOPTS_NOAUTH;
5870 if (as->parms[14].items) { /* -localauth specified */
5871 secFlags |= AFSCONF_SECOPTS_LOCALAUTH;
5872 confdir = AFSDIR_SERVER_ETC_DIRPATH;
5875 if (as->parms[16].items /* -encrypt specified */
5877 || win32_enableCrypt()
5878 #endif /* AFS_NT40_ENV */
5880 secFlags |= AFSCONF_SECOPTS_ALWAYSENCRYPT;
5882 if (as->parms[18].items) /* -config flag set */
5883 confdir = as->parms[18].items->data;
5885 if ((code = vsu_ClientInit(confdir, tcell, secFlags, UV_SetSecurity,
5887 fprintf(STDERR, "could not initialize VLDB library (code=%lu) \n",
5888 (unsigned long)code);
5892 if (as->parms[15].items) /* -verbose flag set */
5896 if (as->parms[17].items) /* -noresolve flag set */
5907 /* this sucks but it works for now.
5912 #include "AFS_component_version_number.c"
5915 main(int argc, char **argv)
5919 struct cmd_syndesc *ts;
5921 #ifdef AFS_AIX32_ENV
5923 * The following signal action for AIX is necessary so that in case of a
5924 * crash (i.e. core is generated) we can include the user's data section
5925 * in the core dump. Unfortunately, by default, only a partial core is
5926 * generated which, in many cases, isn't too useful.
5928 struct sigaction nsa;
5930 sigemptyset(&nsa.sa_mask);
5931 nsa.sa_handler = SIG_DFL;
5932 nsa.sa_flags = SA_FULLDUMP;
5933 sigaction(SIGSEGV, &nsa, NULL);
5936 confdir = AFSDIR_CLIENT_ETC_DIRPATH;
5938 cmd_SetBeforeProc(MyBeforeProc, NULL);
5940 ts = cmd_CreateSyntax("create", CreateVolume, NULL, "create a new volume");
5941 cmd_AddParm(ts, "-server", CMD_SINGLE, 0, "machine name");
5942 cmd_AddParm(ts, "-partition", CMD_SINGLE, 0, "partition name");
5943 cmd_AddParm(ts, "-name", CMD_SINGLE, 0, "volume name");
5944 cmd_AddParm(ts, "-maxquota", CMD_SINGLE, CMD_OPTIONAL,
5945 "initial quota (KB)");
5946 cmd_AddParm(ts, "-id", CMD_SINGLE, CMD_OPTIONAL, "volume ID");
5947 cmd_AddParm(ts, "-roid", CMD_SINGLE, CMD_OPTIONAL, "readonly volume ID");
5949 cmd_AddParm(ts, "-minquota", CMD_SINGLE, CMD_OPTIONAL, "");
5953 ts = cmd_CreateSyntax("remove", DeleteVolume, NULL, "delete a volume");
5954 cmd_AddParm(ts, "-server", CMD_SINGLE, CMD_OPTIONAL, "machine name");
5955 cmd_AddParm(ts, "-partition", CMD_SINGLE, CMD_OPTIONAL, "partition name");
5956 cmd_AddParm(ts, "-id", CMD_SINGLE, 0, "volume name or ID");
5960 ts = cmd_CreateSyntax("move", MoveVolume, NULL, "move a volume");
5961 cmd_AddParm(ts, "-id", CMD_SINGLE, 0, "volume name or ID");
5962 cmd_AddParm(ts, "-fromserver", CMD_SINGLE, 0, "machine name on source");
5963 cmd_AddParm(ts, "-frompartition", CMD_SINGLE, 0,
5964 "partition name on source");
5965 cmd_AddParm(ts, "-toserver", CMD_SINGLE, 0,
5966 "machine name on destination");
5967 cmd_AddParm(ts, "-topartition", CMD_SINGLE, 0,
5968 "partition name on destination");
5969 cmd_AddParm(ts, "-live", CMD_FLAG, CMD_OPTIONAL,
5970 "copy live volume without cloning");
5973 ts = cmd_CreateSyntax("copy", CopyVolume, NULL, "copy a volume");
5974 cmd_AddParm(ts, "-id", CMD_SINGLE, 0, "volume name or ID on source");
5975 cmd_AddParm(ts, "-fromserver", CMD_SINGLE, 0, "machine name on source");
5976 cmd_AddParm(ts, "-frompartition", CMD_SINGLE, 0,
5977 "partition name on source");
5978 cmd_AddParm(ts, "-toname", CMD_SINGLE, 0, "volume name on destination");
5979 cmd_AddParm(ts, "-toserver", CMD_SINGLE, 0,
5980 "machine name on destination");
5981 cmd_AddParm(ts, "-topartition", CMD_SINGLE, 0,
5982 "partition name on destination");
5983 cmd_AddParm(ts, "-offline", CMD_FLAG, CMD_OPTIONAL,
5984 "leave new volume offline");
5985 cmd_AddParm(ts, "-readonly", CMD_FLAG, CMD_OPTIONAL,
5986 "make new volume read-only");
5987 cmd_AddParm(ts, "-live", CMD_FLAG, CMD_OPTIONAL,
5988 "copy live volume without cloning");
5991 ts = cmd_CreateSyntax("shadow", ShadowVolume, NULL,
5992 "make or update a shadow volume");
5993 cmd_AddParm(ts, "-id", CMD_SINGLE, 0, "volume name or ID on source");
5994 cmd_AddParm(ts, "-fromserver", CMD_SINGLE, 0, "machine name on source");
5995 cmd_AddParm(ts, "-frompartition", CMD_SINGLE, 0,
5996 "partition name on source");
5997 cmd_AddParm(ts, "-toserver", CMD_SINGLE, 0,
5998 "machine name on destination");
5999 cmd_AddParm(ts, "-topartition", CMD_SINGLE, 0,
6000 "partition name on destination");
6001 cmd_AddParm(ts, "-toname", CMD_SINGLE, CMD_OPTIONAL,
6002 "volume name on destination");
6003 cmd_AddParm(ts, "-toid", CMD_SINGLE, CMD_OPTIONAL,
6004 "volume ID on destination");
6005 cmd_AddParm(ts, "-offline", CMD_FLAG, CMD_OPTIONAL,
6006 "leave shadow volume offline");
6007 cmd_AddParm(ts, "-readonly", CMD_FLAG, CMD_OPTIONAL,
6008 "make shadow volume read-only");
6009 cmd_AddParm(ts, "-live", CMD_FLAG, CMD_OPTIONAL,
6010 "copy live volume without cloning");
6011 cmd_AddParm(ts, "-incremental", CMD_FLAG, CMD_OPTIONAL,
6012 "do incremental update if target exists");
6015 ts = cmd_CreateSyntax("backup", BackupVolume, NULL,
6016 "make backup of a volume");
6017 cmd_AddParm(ts, "-id", CMD_SINGLE, 0, "volume name or ID");
6020 ts = cmd_CreateSyntax("clone", CloneVolume, NULL,
6021 "make clone of a volume");
6022 cmd_AddParm(ts, "-id", CMD_SINGLE, 0, "volume name or ID");
6023 cmd_AddParm(ts, "-server", CMD_SINGLE, CMD_OPTIONAL, "server");
6024 cmd_AddParm(ts, "-partition", CMD_SINGLE, CMD_OPTIONAL, "partition");
6025 cmd_AddParm(ts, "-toname", CMD_SINGLE, CMD_OPTIONAL,
6026 "volume name on destination");
6027 cmd_AddParm(ts, "-toid", CMD_SINGLE, CMD_OPTIONAL,
6028 "volume ID on destination");
6029 cmd_AddParm(ts, "-offline", CMD_FLAG, CMD_OPTIONAL,
6030 "leave clone volume offline");
6031 cmd_AddParm(ts, "-readonly", CMD_FLAG, CMD_OPTIONAL,
6032 "make clone volume read-only, not readwrite");
6033 cmd_AddParm(ts, "-readwrite", CMD_FLAG, CMD_OPTIONAL,
6034 "make clone volume readwrite, not read-only");
6037 ts = cmd_CreateSyntax("release", ReleaseVolume, NULL, "release a volume");
6038 cmd_AddParm(ts, "-id", CMD_SINGLE, 0, "volume name or ID");
6039 cmd_AddParm(ts, "-force", CMD_FLAG, CMD_OPTIONAL,
6040 "force a complete release");
6041 cmd_AddParm(ts, "-stayonline", CMD_FLAG, CMD_OPTIONAL,
6042 "release to cloned temp vol, then clone back to repsite RO");
6045 ts = cmd_CreateSyntax("dump", DumpVolumeCmd, NULL, "dump a volume");
6046 cmd_AddParm(ts, "-id", CMD_SINGLE, 0, "volume name or ID");
6047 cmd_AddParm(ts, "-time", CMD_SINGLE, CMD_OPTIONAL, "dump from time");
6048 cmd_AddParm(ts, "-file", CMD_SINGLE, CMD_OPTIONAL, "dump file");
6049 cmd_AddParm(ts, "-server", CMD_SINGLE, CMD_OPTIONAL, "server");
6050 cmd_AddParm(ts, "-partition", CMD_SINGLE, CMD_OPTIONAL, "partition");
6051 cmd_AddParm(ts, "-clone", CMD_FLAG, CMD_OPTIONAL,
6052 "dump a clone of the volume");
6053 cmd_AddParm(ts, "-omitdirs", CMD_FLAG, CMD_OPTIONAL,
6054 "omit unchanged directories from an incremental dump");
6057 ts = cmd_CreateSyntax("restore", RestoreVolumeCmd, NULL,
6058 "restore a volume");
6059 cmd_AddParm(ts, "-server", CMD_SINGLE, 0, "machine name");
6060 cmd_AddParm(ts, "-partition", CMD_SINGLE, 0, "partition name");
6061 cmd_AddParm(ts, "-name", CMD_SINGLE, 0, "name of volume to be restored");
6062 cmd_AddParm(ts, "-file", CMD_SINGLE, CMD_OPTIONAL, "dump file");
6063 cmd_AddParm(ts, "-id", CMD_SINGLE, CMD_OPTIONAL, "volume ID");
6064 cmd_AddParm(ts, "-overwrite", CMD_SINGLE, CMD_OPTIONAL,
6065 "abort | full | incremental");
6066 cmd_AddParm(ts, "-offline", CMD_FLAG, CMD_OPTIONAL,
6067 "leave restored volume offline");
6068 cmd_AddParm(ts, "-readonly", CMD_FLAG, CMD_OPTIONAL,
6069 "make restored volume read-only");
6070 cmd_AddParm(ts, "-creation", CMD_SINGLE, CMD_OPTIONAL,
6071 "dump | keep | new");
6072 cmd_AddParm(ts, "-lastupdate", CMD_SINGLE, CMD_OPTIONAL,
6073 "dump | keep | new");
6074 cmd_AddParm(ts, "-nodelete", CMD_FLAG, CMD_OPTIONAL,
6075 "do not delete old site when restoring to a new site");
6078 ts = cmd_CreateSyntax("unlock", LockReleaseCmd, NULL,
6079 "release lock on VLDB entry for a volume");
6080 cmd_AddParm(ts, "-id", CMD_SINGLE, 0, "volume name or ID");
6083 ts = cmd_CreateSyntax("changeloc", ChangeLocation, NULL,
6084 "change an RW volume's location in the VLDB");
6085 cmd_AddParm(ts, "-server", CMD_SINGLE, 0,
6086 "machine name for new location");
6087 cmd_AddParm(ts, "-partition", CMD_SINGLE, 0,
6088 "partition name for new location");
6089 cmd_AddParm(ts, "-id", CMD_SINGLE, 0, "volume name or ID");
6092 ts = cmd_CreateSyntax("addsite", AddSite, NULL, "add a replication site");
6093 cmd_AddParm(ts, "-server", CMD_SINGLE, 0, "machine name for new site");
6094 cmd_AddParm(ts, "-partition", CMD_SINGLE, 0,
6095 "partition name for new site");
6096 cmd_AddParm(ts, "-id", CMD_SINGLE, 0, "volume name or ID");
6097 cmd_AddParm(ts, "-roid", CMD_SINGLE, CMD_OPTIONAL, "volume name or ID for RO");
6098 cmd_AddParm(ts, "-valid", CMD_FLAG, CMD_OPTIONAL, "publish as an up-to-date site in VLDB");
6101 ts = cmd_CreateSyntax("remsite", RemoveSite, NULL,
6102 "remove a replication site");
6103 cmd_AddParm(ts, "-server", CMD_SINGLE, 0, "machine name");
6104 cmd_AddParm(ts, "-partition", CMD_SINGLE, 0, "partition name");
6105 cmd_AddParm(ts, "-id", CMD_SINGLE, 0, "volume name or ID");
6108 ts = cmd_CreateSyntax("listpart", ListPartitions, NULL, "list partitions");
6109 cmd_AddParm(ts, "-server", CMD_SINGLE, 0, "machine name");
6112 ts = cmd_CreateSyntax("listvol", ListVolumes, NULL,
6113 "list volumes on server (bypass VLDB)");
6114 cmd_AddParm(ts, "-server", CMD_SINGLE, 0, "machine name");
6115 cmd_AddParm(ts, "-partition", CMD_SINGLE, CMD_OPTIONAL, "partition name");
6116 cmd_AddParm(ts, "-fast", CMD_FLAG, CMD_OPTIONAL, "minimal listing");
6117 cmd_AddParm(ts, "-long", CMD_FLAG, CMD_OPTIONAL,
6118 "list all normal volume fields");
6119 cmd_AddParm(ts, "-quiet", CMD_FLAG, CMD_OPTIONAL,
6120 "generate minimal information");
6121 cmd_AddParm(ts, "-extended", CMD_FLAG, CMD_OPTIONAL,
6122 "list extended volume fields");
6123 cmd_AddParm(ts, "-format", CMD_FLAG, CMD_OPTIONAL,
6124 "machine readable format");
6127 ts = cmd_CreateSyntax("syncvldb", SyncVldb, NULL,
6128 "synchronize VLDB with server");
6129 cmd_AddParm(ts, "-server", CMD_SINGLE, CMD_OPTIONAL, "machine name");
6130 cmd_AddParm(ts, "-partition", CMD_SINGLE, CMD_OPTIONAL, "partition name");
6131 cmd_AddParm(ts, "-volume", CMD_SINGLE, CMD_OPTIONAL, "volume name or ID");
6132 cmd_AddParm(ts, "-dryrun", CMD_FLAG, CMD_OPTIONAL, "list what would be done, don't do it");
6135 ts = cmd_CreateSyntax("syncserv", SyncServer, NULL,
6136 "synchronize server with VLDB");
6137 cmd_AddParm(ts, "-server", CMD_SINGLE, 0, "machine name");
6138 cmd_AddParm(ts, "-partition", CMD_SINGLE, CMD_OPTIONAL, "partition name");
6139 cmd_AddParm(ts, "-dryrun", CMD_FLAG, CMD_OPTIONAL, "list what would be done, don't do it");
6142 ts = cmd_CreateSyntax("examine", ExamineVolume, NULL,
6143 "everything about the volume");
6144 cmd_AddParm(ts, "-id", CMD_SINGLE, 0, "volume name or ID");
6145 cmd_AddParm(ts, "-extended", CMD_FLAG, CMD_OPTIONAL,
6146 "list extended volume fields");
6147 cmd_AddParm(ts, "-format", CMD_FLAG, CMD_OPTIONAL,
6148 "machine readable format");
6150 cmd_CreateAlias(ts, "volinfo");
6152 ts = cmd_CreateSyntax("setfields", SetFields, NULL,
6153 "change volume info fields");
6154 cmd_AddParm(ts, "-id", CMD_SINGLE, 0, "volume name or ID");
6155 cmd_AddParm(ts, "-maxquota", CMD_SINGLE, CMD_OPTIONAL, "quota (KB)");
6156 cmd_AddParm(ts, "-clearuse", CMD_FLAG, CMD_OPTIONAL, "clear dayUse");
6157 cmd_AddParm(ts, "-clearVolUpCounter", CMD_FLAG, CMD_OPTIONAL, "clear volUpdateCounter");
6160 ts = cmd_CreateSyntax("offline", volOffline, NULL, "force the volume status to offline");
6161 cmd_AddParm(ts, "-server", CMD_SINGLE, 0, "server name");
6162 cmd_AddParm(ts, "-partition", CMD_SINGLE, 0, "partition name");
6163 cmd_AddParm(ts, "-id", CMD_SINGLE, 0, "volume name or ID");
6164 cmd_AddParm(ts, "-sleep", CMD_SINGLE, CMD_OPTIONAL, "seconds to sleep");
6165 cmd_AddParm(ts, "-busy", CMD_FLAG, CMD_OPTIONAL, "busy volume");
6168 ts = cmd_CreateSyntax("online", volOnline, NULL, "force the volume status to online");
6169 cmd_AddParm(ts, "-server", CMD_SINGLE, 0, "server name");
6170 cmd_AddParm(ts, "-partition", CMD_SINGLE, 0, "partition name");
6171 cmd_AddParm(ts, "-id", CMD_SINGLE, 0, "volume name or ID");
6174 ts = cmd_CreateSyntax("zap", VolumeZap, NULL,
6175 "delete the volume, don't bother with VLDB");
6176 cmd_AddParm(ts, "-server", CMD_SINGLE, 0, "machine name");
6177 cmd_AddParm(ts, "-partition", CMD_SINGLE, 0, "partition name");
6178 cmd_AddParm(ts, "-id", CMD_SINGLE, 0, "volume ID");
6179 cmd_AddParm(ts, "-force", CMD_FLAG, CMD_OPTIONAL,
6180 "force deletion of bad volumes");
6181 cmd_AddParm(ts, "-backup", CMD_FLAG, CMD_OPTIONAL,
6182 "also delete backup volume if one is found");
6185 ts = cmd_CreateSyntax("status", VolserStatus, NULL,
6186 "report on volser status");
6187 cmd_AddParm(ts, "-server", CMD_SINGLE, 0, "machine name");
6190 ts = cmd_CreateSyntax("rename", RenameVolume, NULL, "rename a volume");
6191 cmd_AddParm(ts, "-oldname", CMD_SINGLE, 0, "old volume name ");
6192 cmd_AddParm(ts, "-newname", CMD_SINGLE, 0, "new volume name ");
6195 ts = cmd_CreateSyntax("listvldb", ListVLDB, NULL,
6196 "list volumes in the VLDB");
6197 cmd_AddParm(ts, "-name", CMD_SINGLE, CMD_OPTIONAL, "volume name or ID");
6198 cmd_AddParm(ts, "-server", CMD_SINGLE, CMD_OPTIONAL, "machine name");
6199 cmd_AddParm(ts, "-partition", CMD_SINGLE, CMD_OPTIONAL, "partition name");
6200 cmd_AddParm(ts, "-locked", CMD_FLAG, CMD_OPTIONAL, "locked volumes only");
6201 cmd_AddParm(ts, "-quiet", CMD_FLAG, CMD_OPTIONAL,
6202 "generate minimal information");
6203 cmd_AddParm(ts, "-nosort", CMD_FLAG, CMD_OPTIONAL,
6204 "do not alphabetically sort the volume names");
6207 ts = cmd_CreateSyntax("backupsys", BackSys, NULL, "en masse backups");
6208 cmd_AddParm(ts, "-prefix", CMD_LIST, CMD_OPTIONAL,
6209 "common prefix on volume(s)");
6210 cmd_AddParm(ts, "-server", CMD_SINGLE, CMD_OPTIONAL, "machine name");
6211 cmd_AddParm(ts, "-partition", CMD_SINGLE, CMD_OPTIONAL, "partition name");
6212 cmd_AddParm(ts, "-exclude", CMD_FLAG, CMD_OPTIONAL,
6213 "exclude common prefix volumes");
6214 cmd_AddParm(ts, "-xprefix", CMD_LIST, CMD_OPTIONAL,
6215 "negative prefix on volume(s)");
6216 cmd_AddParm(ts, "-dryrun", CMD_FLAG, CMD_OPTIONAL, "list what would be done, don't do it");
6219 ts = cmd_CreateSyntax("delentry", DeleteEntry, NULL,
6220 "delete VLDB entry for a volume");
6221 cmd_AddParm(ts, "-id", CMD_LIST, CMD_OPTIONAL, "volume name or ID");
6222 cmd_AddParm(ts, "-prefix", CMD_SINGLE, CMD_OPTIONAL,
6223 "prefix of the volume whose VLDB entry is to be deleted");
6224 cmd_AddParm(ts, "-server", CMD_SINGLE, CMD_OPTIONAL, "machine name");
6225 cmd_AddParm(ts, "-partition", CMD_SINGLE, CMD_OPTIONAL, "partition name");
6226 cmd_AddParm(ts, "-noexecute", CMD_FLAG, CMD_OPTIONAL|CMD_HIDDEN, "");
6227 cmd_AddParm(ts, "-dryrun", CMD_FLAG, CMD_OPTIONAL,
6228 "list what would be done, don't do it");
6231 ts = cmd_CreateSyntax("partinfo", PartitionInfo, NULL,
6232 "list partition information");
6233 cmd_AddParm(ts, "-server", CMD_SINGLE, 0, "machine name");
6234 cmd_AddParm(ts, "-partition", CMD_SINGLE, CMD_OPTIONAL, "partition name");
6235 cmd_AddParm(ts, "-summary", CMD_FLAG, CMD_OPTIONAL,
6236 "print storage summary");
6239 ts = cmd_CreateSyntax("unlockvldb", UnlockVLDB, NULL,
6240 "unlock all the locked entries in the VLDB");
6241 cmd_AddParm(ts, "-server", CMD_SINGLE, CMD_OPTIONAL, "machine name");
6242 cmd_AddParm(ts, "-partition", CMD_SINGLE, CMD_OPTIONAL, "partition name");
6245 ts = cmd_CreateSyntax("lock", LockEntry, NULL,
6246 "lock VLDB entry for a volume");
6247 cmd_AddParm(ts, "-id", CMD_SINGLE, 0, "volume name or ID");
6250 ts = cmd_CreateSyntax("changeaddr", ChangeAddr, NULL,
6251 "change the IP address of a file server");
6252 cmd_AddParm(ts, "-oldaddr", CMD_SINGLE, 0, "original IP address");
6253 cmd_AddParm(ts, "-newaddr", CMD_SINGLE, CMD_OPTIONAL, "new IP address");
6254 cmd_AddParm(ts, "-remove", CMD_FLAG, CMD_OPTIONAL,
6255 "remove the IP address from the VLDB");
6258 ts = cmd_CreateSyntax("listaddrs", ListAddrs, NULL,
6259 "list the IP address of all file servers registered in the VLDB");
6260 cmd_AddParm(ts, "-uuid", CMD_SINGLE, CMD_OPTIONAL, "uuid of server");
6261 cmd_AddParm(ts, "-host", CMD_SINGLE, CMD_OPTIONAL, "address of host");
6262 cmd_AddParm(ts, "-printuuid", CMD_FLAG, CMD_OPTIONAL,
6263 "print uuid of hosts");
6266 ts = cmd_CreateSyntax("convertROtoRW", ConvertRO, NULL,
6267 "convert a RO volume into a RW volume (after loss of old RW volume)");
6268 cmd_AddParm(ts, "-server", CMD_SINGLE, 0, "machine name");
6269 cmd_AddParm(ts, "-partition", CMD_SINGLE, 0, "partition name");
6270 cmd_AddParm(ts, "-id", CMD_SINGLE, 0, "volume name or ID");
6271 cmd_AddParm(ts, "-force", CMD_FLAG, CMD_OPTIONAL, "don't ask");
6274 ts = cmd_CreateSyntax("size", Sizes, NULL,
6275 "obtain various sizes of the volume.");
6276 cmd_AddParm(ts, "-id", CMD_SINGLE, 0, "volume name or ID");
6277 cmd_AddParm(ts, "-partition", CMD_SINGLE, CMD_OPTIONAL, "partition name");
6278 cmd_AddParm(ts, "-server", CMD_SINGLE, CMD_OPTIONAL, "machine name");
6279 cmd_AddParm(ts, "-dump", CMD_FLAG, CMD_OPTIONAL,
6280 "Obtain the size of the dump");
6281 cmd_AddParm(ts, "-time", CMD_SINGLE, CMD_OPTIONAL, "dump from time");
6284 ts = cmd_CreateSyntax("endtrans", EndTrans, NULL,
6285 "end a volserver transaction");
6286 cmd_AddParm(ts, "-server", CMD_SINGLE, 0, "machine name");
6287 cmd_AddParm(ts, "-transaction", CMD_SINGLE, 0,
6291 ts = cmd_CreateSyntax("setaddrs", SetAddrs, NULL,
6292 "set the list of IP address for a given UUID in the VLDB");
6293 cmd_AddParm(ts, "-uuid", CMD_SINGLE, 0, "uuid of server");
6294 cmd_AddParm(ts, "-host", CMD_LIST, 0, "address of host");
6297 code = cmd_Dispatch(argc, argv);
6299 /* Shut down the ubik_client and rx connections */
6301 (void)ubik_ClientDestroy(cstruct);
6307 exit((code ? -1 : 0));