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"); \
82 #define ERROR_EXIT(code) do { \
88 struct rx_connection *tconn;
90 extern struct ubik_client *cstruct;
93 static struct tqHead busyHead, notokHead;
96 qInit(struct tqHead *ahead)
98 memset(ahead, 0, sizeof(struct tqHead));
104 qPut(struct tqHead *ahead, afs_uint32 volid)
108 elem = (struct tqElem *)malloc(sizeof(struct tqElem));
109 elem->next = ahead->next;
117 qGet(struct tqHead *ahead, afs_uint32 *volid)
121 if (ahead->count <= 0)
123 *volid = ahead->next->volid;
125 ahead->next = tmp->next;
131 /* returns 1 if <filename> exists else 0 */
133 FileExists(char *filename)
139 code = usd_Open(filename, USD_OPEN_RDONLY, 0, &ufd);
143 code = USD_IOCTL(ufd, USD_IOCTL_GETSIZE, &size);
151 /* returns 1 if <name> doesnot end in .readonly or .backup, else 0 */
153 VolNameOK(char *name)
158 total = strlen(name);
159 if (!strcmp(&name[total - 9], ".readonly")) {
161 } else if (!strcmp(&name[total - 7], ".backup")) {
168 /* return 1 if name is a number else 0 */
170 IsNumeric(char *name)
179 for (i = 0; i < len; i++) {
180 if (*ptr < '0' || *ptr > '9') {
192 * Parse a server dotted address and return the address in network byte order
195 GetServerNoresolve(char *aname)
201 code = sscanf(aname, "%d.%d.%d.%d", &b1, &b2, &b3, &b4);
203 addr = (b1 << 24) | (b2 << 16) | (b3 << 8) | b4;
204 addr = htonl(addr); /* convert to network byte order */
210 * Parse a server name/address and return the address in network byte order
213 GetServer(char *aname)
216 afs_uint32 addr; /* in network byte order */
218 char hostname[MAXHOSTCHARS];
220 if ((addr = GetServerNoresolve(aname)) == 0) {
221 th = gethostbyname(aname);
224 memcpy(&addr, th->h_addr, sizeof(addr));
227 if (rx_IsLoopbackAddr(ntohl(addr))) { /* local host */
228 code = gethostname(hostname, MAXHOSTCHARS);
231 th = gethostbyname(hostname);
234 memcpy(&addr, th->h_addr, sizeof(addr));
241 GetVolumeType(char *aname)
244 if (!strcmp(aname, "ro"))
246 else if (!strcmp(aname, "rw"))
248 else if (!strcmp(aname, "bk"))
255 IsPartValid(afs_int32 partId, afs_uint32 server, afs_int32 *code)
257 struct partList dummyPartList;
263 *code = UV_ListPartitions(server, &dummyPartList, &cnt);
266 for (i = 0; i < cnt; i++) {
267 if (dummyPartList.partFlags[i] & PARTVALID)
268 if (dummyPartList.partId[i] == partId)
276 /*sends the contents of file associated with <fd> and <blksize> to Rx Stream
277 * associated with <call> */
279 SendFile(usd_handle_t ufd, struct rx_call *call, long blksize)
281 char *buffer = (char *)0;
286 buffer = (char *)malloc(blksize);
288 fprintf(STDERR, "malloc failed\n");
292 while (!error && !done) {
293 #ifndef AFS_NT40_ENV /* NT csn't select on non-socket fd's */
296 FD_SET((intptr_t)(ufd->handle), &in);
297 /* don't timeout if read blocks */
298 #if defined(AFS_PTHREAD_ENV)
299 select(((intptr_t)(ufd->handle)) + 1, &in, 0, 0, 0);
301 IOMGR_Select(((intptr_t)(ufd->handle)) + 1, &in, 0, 0, 0);
304 error = USD_READ(ufd, buffer, blksize, &nbytes);
306 fprintf(STDERR, "File system read failed: %s\n",
307 afs_error_message(error));
314 if (rx_Write(call, buffer, nbytes) != nbytes) {
324 /* function invoked by UV_RestoreVolume, reads the data from rx_trx_stream and
325 * writes it out to the volume. */
327 WriteData(struct rx_call *call, void *rock)
329 char *filename = (char *) rock;
332 afs_int32 error, code;
334 afs_hyper_t filesize, currOffset;
340 if (!filename || !*filename) {
341 usd_StandardInput(&ufd);
345 code = usd_Open(filename, USD_OPEN_RDONLY, 0, &ufd);
348 code = USD_IOCTL(ufd, USD_IOCTL_GETBLKSIZE, &blksize);
351 fprintf(STDERR, "Could not access file '%s': %s\n", filename,
352 afs_error_message(code));
356 /* test if we have a valid dump */
357 hset64(filesize, 0, 0);
358 USD_SEEK(ufd, filesize, SEEK_END, &currOffset);
359 hset64(filesize, hgethi(currOffset), hgetlo(currOffset)-sizeof(afs_uint32));
360 USD_SEEK(ufd, filesize, SEEK_SET, &currOffset);
361 USD_READ(ufd, (char *)&buffer, sizeof(afs_uint32), &got);
362 if ((got != sizeof(afs_uint32)) || (ntohl(buffer) != DUMPENDMAGIC)) {
363 fprintf(STDERR, "Signature missing from end of file '%s'\n", filename);
367 /* rewind, we are done */
368 hset64(filesize, 0, 0);
369 USD_SEEK(ufd, filesize, SEEK_SET, &currOffset);
371 code = SendFile(ufd, call, blksize);
378 code = USD_CLOSE(ufd);
380 fprintf(STDERR, "Could not close dump file %s\n",
381 (filename && *filename) ? filename : "STDOUT");
389 /* Receive data from <call> stream into file associated
390 * with <fd> <blksize>
393 ReceiveFile(usd_handle_t ufd, struct rx_call *call, long blksize)
397 afs_uint32 bytesleft, w;
400 buffer = (char *)malloc(blksize);
402 fprintf(STDERR, "memory allocation failed\n");
406 while ((bytesread = rx_Read(call, buffer, blksize)) > 0) {
407 for (bytesleft = bytesread; bytesleft; bytesleft -= w) {
408 #ifndef AFS_NT40_ENV /* NT csn't select on non-socket fd's */
411 FD_SET((intptr_t)(ufd->handle), &out);
412 /* don't timeout if write blocks */
413 #if defined(AFS_PTHREAD_ENV)
414 select(((intptr_t)(ufd->handle)) + 1, &out, 0, 0, 0);
416 IOMGR_Select(((intptr_t)(ufd->handle)) + 1, 0, &out, 0, 0);
420 USD_WRITE(ufd, &buffer[bytesread - bytesleft], bytesleft, &w);
422 fprintf(STDERR, "File system write failed: %s\n",
423 afs_error_message(error));
436 DumpFunction(struct rx_call *call, void *rock)
438 char *filename = (char *)rock;
439 usd_handle_t ufd; /* default is to stdout */
440 afs_int32 error = 0, code;
445 /* Open the output file */
446 if (!filename || !*filename) {
447 usd_StandardOutput(&ufd);
452 usd_Open(filename, USD_OPEN_CREATE | USD_OPEN_RDWR, 0666, &ufd);
456 code = USD_IOCTL(ufd, USD_IOCTL_SETSIZE, &size);
459 code = USD_IOCTL(ufd, USD_IOCTL_GETBLKSIZE, &blksize);
462 fprintf(STDERR, "Could not create file '%s': %s\n", filename,
463 afs_error_message(code));
464 ERROR_EXIT(VOLSERBADOP);
468 code = ReceiveFile(ufd, call, blksize);
473 /* Close the output file */
475 code = USD_CLOSE(ufd);
477 fprintf(STDERR, "Could not close dump file %s\n",
478 (filename && *filename) ? filename : "STDIN");
488 DisplayFormat(volintInfo *pntr, afs_uint32 server, afs_int32 part,
489 int *totalOK, int *totalNotOK, int *totalBusy, int fast,
490 int longlist, int disp)
496 fprintf(STDOUT, "%-10lu\n", (unsigned long)pntr->volid);
497 } else if (longlist) {
498 if (pntr->status == VOK) {
499 fprintf(STDOUT, "%-32s ", pntr->name);
500 fprintf(STDOUT, "%10lu ", (unsigned long)pntr->volid);
502 fprintf(STDOUT, "RW ");
504 fprintf(STDOUT, "RO ");
506 fprintf(STDOUT, "BK ");
507 fprintf(STDOUT, "%10d K ", pntr->size);
508 if (pntr->inUse == 1) {
509 fprintf(STDOUT, "On-line");
512 fprintf(STDOUT, "Off-line");
515 if (pntr->needsSalvaged == 1)
516 fprintf(STDOUT, "**needs salvage**");
517 fprintf(STDOUT, "\n");
518 MapPartIdIntoName(part, pname);
519 fprintf(STDOUT, " %s %s \n", hostutil_GetNameByINet(server),
521 fprintf(STDOUT, " RWrite %10lu ROnly %10lu Backup %10lu \n",
522 (unsigned long)pntr->parentID,
523 (unsigned long)pntr->cloneID,
524 (unsigned long)pntr->backupID);
525 fprintf(STDOUT, " MaxQuota %10d K \n", pntr->maxquota);
526 t = pntr->creationDate;
527 fprintf(STDOUT, " Creation %s",
530 fprintf(STDOUT, " Copy %s",
533 t = pntr->backupDate;
535 fprintf(STDOUT, " Backup Never\n");
537 fprintf(STDOUT, " Backup %s",
540 t = pntr->accessDate;
542 fprintf(STDOUT, " Last Access %s",
545 t = pntr->updateDate;
547 fprintf(STDOUT, " Last Update Never\n");
549 fprintf(STDOUT, " Last Update %s",
552 " %d accesses in the past day (i.e., vnode references)\n",
554 } else if (pntr->status == VBUSY) {
556 qPut(&busyHead, pntr->volid);
558 fprintf(STDOUT, "**** Volume %lu is busy ****\n",
559 (unsigned long)pntr->volid);
562 qPut(¬okHead, pntr->volid);
564 fprintf(STDOUT, "**** Could not attach volume %lu ****\n",
565 (unsigned long)pntr->volid);
567 fprintf(STDOUT, "\n");
568 } else { /* default listing */
569 if (pntr->status == VOK) {
570 fprintf(STDOUT, "%-32s ", pntr->name);
571 fprintf(STDOUT, "%10lu ", (unsigned long)pntr->volid);
573 fprintf(STDOUT, "RW ");
575 fprintf(STDOUT, "RO ");
577 fprintf(STDOUT, "BK ");
578 fprintf(STDOUT, "%10d K ", pntr->size);
579 if (pntr->inUse == 1) {
580 fprintf(STDOUT, "On-line");
583 fprintf(STDOUT, "Off-line");
586 if (pntr->needsSalvaged == 1)
587 fprintf(STDOUT, "**needs salvage**");
588 fprintf(STDOUT, "\n");
589 } else if (pntr->status == VBUSY) {
591 qPut(&busyHead, pntr->volid);
593 fprintf(STDOUT, "**** Volume %lu is busy ****\n",
594 (unsigned long)pntr->volid);
597 qPut(¬okHead, pntr->volid);
599 fprintf(STDOUT, "**** Could not attach volume %lu ****\n",
600 (unsigned long)pntr->volid);
605 /*------------------------------------------------------------------------
606 * PRIVATE XDisplayFormat
609 * Display the contents of one extended volume info structure.
612 * a_xInfoP : Ptr to extended volume info struct to print.
613 * a_servID : Server ID to print.
614 * a_partID : Partition ID to print.
615 * a_totalOKP : Ptr to total-OK counter.
616 * a_totalNotOKP : Ptr to total-screwed counter.
617 * a_totalBusyP : Ptr to total-busy counter.
618 * a_fast : Fast listing?
619 * a_int32 : Int32 listing?
620 * a_showProblems : Show volume problems?
626 * Nothing interesting.
630 *------------------------------------------------------------------------*/
633 XDisplayFormat(volintXInfo *a_xInfoP, afs_uint32 a_servID, afs_int32 a_partID,
634 int *a_totalOKP, int *a_totalNotOKP, int *a_totalBusyP,
635 int a_fast, int a_int32, int a_showProblems)
636 { /*XDisplayFormat */
644 fprintf(STDOUT, "%-10lu\n", (unsigned long)a_xInfoP->volid);
645 } else if (a_int32) {
647 * Fully-detailed listing.
649 if (a_xInfoP->status == VOK) {
651 * Volume's status is OK - all the fields are valid.
653 fprintf(STDOUT, "%-32s ", a_xInfoP->name);
654 fprintf(STDOUT, "%10lu ", (unsigned long)a_xInfoP->volid);
655 if (a_xInfoP->type == 0)
656 fprintf(STDOUT, "RW ");
657 if (a_xInfoP->type == 1)
658 fprintf(STDOUT, "RO ");
659 if (a_xInfoP->type == 2)
660 fprintf(STDOUT, "BK ");
661 fprintf(STDOUT, "%10d K used ", a_xInfoP->size);
662 fprintf(STDOUT, "%d files ", a_xInfoP->filecount);
663 if (a_xInfoP->inUse == 1) {
664 fprintf(STDOUT, "On-line");
667 fprintf(STDOUT, "Off-line");
670 fprintf(STDOUT, "\n");
671 MapPartIdIntoName(a_partID, pname);
672 fprintf(STDOUT, " %s %s \n", hostutil_GetNameByINet(a_servID),
674 fprintf(STDOUT, " RWrite %10lu ROnly %10lu Backup %10lu \n",
675 (unsigned long)a_xInfoP->parentID,
676 (unsigned long)a_xInfoP->cloneID,
677 (unsigned long)a_xInfoP->backupID);
678 fprintf(STDOUT, " MaxQuota %10d K \n", a_xInfoP->maxquota);
680 t = a_xInfoP->creationDate;
681 fprintf(STDOUT, " Creation %s",
684 t = a_xInfoP->copyDate;
685 fprintf(STDOUT, " Copy %s",
688 t = a_xInfoP->backupDate;
690 fprintf(STDOUT, " Backup Never\n");
692 fprintf(STDOUT, " Backup %s",
695 t = a_xInfoP->accessDate;
697 fprintf(STDOUT, " Last Access %s",
700 t = a_xInfoP->updateDate;
702 fprintf(STDOUT, " Last Update Never\n");
704 fprintf(STDOUT, " Last Update %s",
707 " %d accesses in the past day (i.e., vnode references)\n",
711 * Print all the read/write and authorship stats.
713 fprintf(STDOUT, "\n Raw Read/Write Stats\n");
715 " |-------------------------------------------|\n");
717 " | Same Network | Diff Network |\n");
719 " |----------|----------|----------|----------|\n");
721 " | Total | Auth | Total | Auth |\n");
723 " |----------|----------|----------|----------|\n");
724 fprintf(STDOUT, "Reads | %8d | %8d | %8d | %8d |\n",
725 a_xInfoP->stat_reads[VOLINT_STATS_SAME_NET],
726 a_xInfoP->stat_reads[VOLINT_STATS_SAME_NET_AUTH],
727 a_xInfoP->stat_reads[VOLINT_STATS_DIFF_NET],
728 a_xInfoP->stat_reads[VOLINT_STATS_DIFF_NET_AUTH]);
729 fprintf(STDOUT, "Writes | %8d | %8d | %8d | %8d |\n",
730 a_xInfoP->stat_writes[VOLINT_STATS_SAME_NET],
731 a_xInfoP->stat_writes[VOLINT_STATS_SAME_NET_AUTH],
732 a_xInfoP->stat_writes[VOLINT_STATS_DIFF_NET],
733 a_xInfoP->stat_writes[VOLINT_STATS_DIFF_NET_AUTH]);
735 " |-------------------------------------------|\n\n");
738 " Writes Affecting Authorship\n");
740 " |-------------------------------------------|\n");
742 " | File Authorship | Directory Authorship|\n");
744 " |----------|----------|----------|----------|\n");
746 " | Same | Diff | Same | Diff |\n");
748 " |----------|----------|----------|----------|\n");
749 fprintf(STDOUT, "0-60 sec | %8d | %8d | %8d | %8d |\n",
750 a_xInfoP->stat_fileSameAuthor[VOLINT_STATS_TIME_IDX_0],
751 a_xInfoP->stat_fileDiffAuthor[VOLINT_STATS_TIME_IDX_0],
752 a_xInfoP->stat_dirSameAuthor[VOLINT_STATS_TIME_IDX_0],
753 a_xInfoP->stat_dirDiffAuthor[VOLINT_STATS_TIME_IDX_0]);
754 fprintf(STDOUT, "1-10 min | %8d | %8d | %8d | %8d |\n",
755 a_xInfoP->stat_fileSameAuthor[VOLINT_STATS_TIME_IDX_1],
756 a_xInfoP->stat_fileDiffAuthor[VOLINT_STATS_TIME_IDX_1],
757 a_xInfoP->stat_dirSameAuthor[VOLINT_STATS_TIME_IDX_1],
758 a_xInfoP->stat_dirDiffAuthor[VOLINT_STATS_TIME_IDX_1]);
759 fprintf(STDOUT, "10min-1hr | %8d | %8d | %8d | %8d |\n",
760 a_xInfoP->stat_fileSameAuthor[VOLINT_STATS_TIME_IDX_2],
761 a_xInfoP->stat_fileDiffAuthor[VOLINT_STATS_TIME_IDX_2],
762 a_xInfoP->stat_dirSameAuthor[VOLINT_STATS_TIME_IDX_2],
763 a_xInfoP->stat_dirDiffAuthor[VOLINT_STATS_TIME_IDX_2]);
764 fprintf(STDOUT, "1hr-1day | %8d | %8d | %8d | %8d |\n",
765 a_xInfoP->stat_fileSameAuthor[VOLINT_STATS_TIME_IDX_3],
766 a_xInfoP->stat_fileDiffAuthor[VOLINT_STATS_TIME_IDX_3],
767 a_xInfoP->stat_dirSameAuthor[VOLINT_STATS_TIME_IDX_3],
768 a_xInfoP->stat_dirDiffAuthor[VOLINT_STATS_TIME_IDX_3]);
769 fprintf(STDOUT, "1day-1wk | %8d | %8d | %8d | %8d |\n",
770 a_xInfoP->stat_fileSameAuthor[VOLINT_STATS_TIME_IDX_4],
771 a_xInfoP->stat_fileDiffAuthor[VOLINT_STATS_TIME_IDX_4],
772 a_xInfoP->stat_dirSameAuthor[VOLINT_STATS_TIME_IDX_4],
773 a_xInfoP->stat_dirDiffAuthor[VOLINT_STATS_TIME_IDX_4]);
774 fprintf(STDOUT, "> 1wk | %8d | %8d | %8d | %8d |\n",
775 a_xInfoP->stat_fileSameAuthor[VOLINT_STATS_TIME_IDX_5],
776 a_xInfoP->stat_fileDiffAuthor[VOLINT_STATS_TIME_IDX_5],
777 a_xInfoP->stat_dirSameAuthor[VOLINT_STATS_TIME_IDX_5],
778 a_xInfoP->stat_dirDiffAuthor[VOLINT_STATS_TIME_IDX_5]);
780 " |-------------------------------------------|\n");
781 } /*Volume status OK */
782 else if (a_xInfoP->status == VBUSY) {
784 qPut(&busyHead, a_xInfoP->volid);
786 fprintf(STDOUT, "**** Volume %lu is busy ****\n",
787 (unsigned long)a_xInfoP->volid);
791 qPut(¬okHead, a_xInfoP->volid);
793 fprintf(STDOUT, "**** Could not attach volume %lu ****\n",
794 (unsigned long)a_xInfoP->volid);
795 } /*Screwed volume */
796 fprintf(STDOUT, "\n");
802 if (a_xInfoP->status == VOK) {
803 fprintf(STDOUT, "%-32s ", a_xInfoP->name);
804 fprintf(STDOUT, "%10lu ", (unsigned long)a_xInfoP->volid);
805 if (a_xInfoP->type == 0)
806 fprintf(STDOUT, "RW ");
807 if (a_xInfoP->type == 1)
808 fprintf(STDOUT, "RO ");
809 if (a_xInfoP->type == 2)
810 fprintf(STDOUT, "BK ");
811 fprintf(STDOUT, "%10d K ", a_xInfoP->size);
812 if (a_xInfoP->inUse == 1) {
813 fprintf(STDOUT, "On-line");
816 fprintf(STDOUT, "Off-line");
819 fprintf(STDOUT, "\n");
821 else if (a_xInfoP->status == VBUSY) {
823 qPut(&busyHead, a_xInfoP->volid);
825 fprintf(STDOUT, "**** Volume %lu is busy ****\n",
826 (unsigned long)a_xInfoP->volid);
830 qPut(¬okHead, a_xInfoP->volid);
832 fprintf(STDOUT, "**** Could not attach volume %lu ****\n",
833 (unsigned long)a_xInfoP->volid);
834 } /*Screwed volume */
835 } /*Default listing */
836 } /*XDisplayFormat */
838 /*------------------------------------------------------------------------
839 * PRIVATE XDisplayFormat2
842 * Display the formated contents of one extended volume info structure.
845 * a_xInfoP : Ptr to extended volume info struct to print.
846 * a_servID : Server ID to print.
847 * a_partID : Partition ID to print.
848 * a_totalOKP : Ptr to total-OK counter.
849 * a_totalNotOKP : Ptr to total-screwed counter.
850 * a_totalBusyP : Ptr to total-busy counter.
851 * a_fast : Fast listing?
852 * a_int32 : Int32 listing?
853 * a_showProblems : Show volume problems?
859 * Nothing interesting.
863 *------------------------------------------------------------------------*/
866 XDisplayFormat2(volintXInfo *a_xInfoP, afs_uint32 a_servID, afs_int32 a_partID,
867 int *a_totalOKP, int *a_totalNotOKP, int *a_totalBusyP,
868 int a_fast, int a_int32, int a_showProblems)
869 { /*XDisplayFormat */
875 fprintf(STDOUT, "vold_id\t%-10lu\n", (unsigned long)a_xInfoP->volid);
876 } else if (a_int32) {
878 * Fully-detailed listing.
880 if (a_xInfoP->status == VOK) {
882 * Volume's status is OK - all the fields are valid.
885 static long server_cache = -1, partition_cache = -1;
886 static char hostname[256], address[32], pname[16];
887 int i,ai[] = {VOLINT_STATS_TIME_IDX_0,VOLINT_STATS_TIME_IDX_1,VOLINT_STATS_TIME_IDX_2,
888 VOLINT_STATS_TIME_IDX_3,VOLINT_STATS_TIME_IDX_4,VOLINT_STATS_TIME_IDX_5};
890 if (a_servID != server_cache) {
894 strcpy(hostname, hostutil_GetNameByINet(a_servID));
895 strcpy(address, inet_ntoa(s));
896 server_cache = a_servID;
898 if (a_partID != partition_cache) {
899 MapPartIdIntoName(a_partID, pname);
900 partition_cache = a_partID;
903 fprintf(STDOUT, "name\t\t%s\n", a_xInfoP->name);
904 fprintf(STDOUT, "id\t\t%lu\n", afs_printable_uint32_lu(a_xInfoP->volid));
905 fprintf(STDOUT, "serv\t\t%s\t%s\n", address, hostname);
906 fprintf(STDOUT, "part\t\t%s\n", pname);
907 fprintf(STDOUT, "status\t\tOK\n");
908 fprintf(STDOUT, "backupID\t%lu\n",
909 afs_printable_uint32_lu(a_xInfoP->backupID));
910 fprintf(STDOUT, "parentID\t%lu\n",
911 afs_printable_uint32_lu(a_xInfoP->parentID));
912 fprintf(STDOUT, "cloneID\t\t%lu\n",
913 afs_printable_uint32_lu(a_xInfoP->cloneID));
914 fprintf(STDOUT, "inUse\t\t%s\n", a_xInfoP->inUse ? "Y" : "N");
915 switch (a_xInfoP->type) {
917 fprintf(STDOUT, "type\t\tRW\n");
920 fprintf(STDOUT, "type\t\tRO\n");
923 fprintf(STDOUT, "type\t\tBK\n");
926 fprintf(STDOUT, "type\t\t?\n");
929 t = a_xInfoP->creationDate;
930 fprintf(STDOUT, "creationDate\t%-9lu\t%s",
931 afs_printable_uint32_lu(a_xInfoP->creationDate),
934 t = a_xInfoP->accessDate;
935 fprintf(STDOUT, "accessDate\t%-9lu\t%s",
936 afs_printable_uint32_lu(a_xInfoP->accessDate),
939 t = a_xInfoP->updateDate;
940 fprintf(STDOUT, "updateDate\t%-9lu\t%s",
941 afs_printable_uint32_lu(a_xInfoP->updateDate),
944 t = a_xInfoP->backupDate;
945 fprintf(STDOUT, "backupDate\t%-9lu\t%s",
946 afs_printable_uint32_lu(a_xInfoP->backupDate),
949 t = a_xInfoP->copyDate;
950 fprintf(STDOUT, "copyDate\t%-9lu\t%s",
951 afs_printable_uint32_lu(a_xInfoP->copyDate),
954 fprintf(STDOUT, "diskused\t%u\n", a_xInfoP->size);
955 fprintf(STDOUT, "maxquota\t%u\n", a_xInfoP->maxquota);
957 fprintf(STDOUT, "filecount\t%u\n", a_xInfoP->filecount);
958 fprintf(STDOUT, "dayUse\t\t%u\n", a_xInfoP->dayUse);
962 fprintf(STDOUT,"reads_same_net\t%8d\n",a_xInfoP->stat_reads[VOLINT_STATS_SAME_NET]);
963 fprintf(STDOUT,"reads_same_net_auth\t%8d\n",a_xInfoP->stat_reads[VOLINT_STATS_SAME_NET_AUTH]);
964 fprintf(STDOUT,"reads_diff_net\t%8d\n",a_xInfoP->stat_reads[VOLINT_STATS_DIFF_NET]);
965 fprintf(STDOUT,"reads_diff_net_auth\t%8d\n",a_xInfoP->stat_reads[VOLINT_STATS_DIFF_NET_AUTH]);
967 fprintf(STDOUT,"writes_same_net\t%8d\n",a_xInfoP->stat_writes[VOLINT_STATS_SAME_NET]);
968 fprintf(STDOUT,"writes_same_net_auth\t%8d\n",a_xInfoP->stat_writes[VOLINT_STATS_SAME_NET_AUTH]);
969 fprintf(STDOUT,"writes_diff_net\t%8d\n",a_xInfoP->stat_writes[VOLINT_STATS_DIFF_NET]);
970 fprintf(STDOUT,"writes_diff_net_auth\t%8d\n",a_xInfoP->stat_writes[VOLINT_STATS_DIFF_NET_AUTH]);
974 fprintf(STDOUT,"file_same_author_idx_%d\t%8d\n",i+1,a_xInfoP->stat_fileSameAuthor[ai[i]]);
975 fprintf(STDOUT,"file_diff_author_idx_%d\t%8d\n",i+1,a_xInfoP->stat_fileDiffAuthor[ai[i]]);
976 fprintf(STDOUT,"dir_same_author_idx_%d\t%8d\n",i+1,a_xInfoP->stat_dirSameAuthor[ai[i]]);
977 fprintf(STDOUT,"dir_dif_author_idx_%d\t%8d\n",i+1,a_xInfoP->stat_dirDiffAuthor[ai[i]]);
980 } /*Volume status OK */
981 else if (a_xInfoP->status == VBUSY) {
983 qPut(&busyHead, a_xInfoP->volid);
985 fprintf(STDOUT, "BUSY_VOL\t%lu\n",
986 (unsigned long)a_xInfoP->volid);
990 qPut(¬okHead, a_xInfoP->volid);
992 fprintf(STDOUT, "COULD_NOT_ATTACH\t%lu\n",
993 (unsigned long)a_xInfoP->volid);
994 } /*Screwed volume */
1000 if (a_xInfoP->status == VOK) {
1001 fprintf(STDOUT, "name\t%-32s\n", a_xInfoP->name);
1002 fprintf(STDOUT, "volID\t%10lu\n", (unsigned long)a_xInfoP->volid);
1003 if (a_xInfoP->type == 0)
1004 fprintf(STDOUT, "type\tRW\n");
1005 if (a_xInfoP->type == 1)
1006 fprintf(STDOUT, "type\tRO\n");
1007 if (a_xInfoP->type == 2)
1008 fprintf(STDOUT, "type\tBK\n");
1009 fprintf(STDOUT, "size\t%10dK\n", a_xInfoP->size);
1011 fprintf(STDOUT, "inUse\t%d\n",a_xInfoP->inUse);
1012 if (a_xInfoP->inUse == 1)
1018 else if (a_xInfoP->status == VBUSY) {
1020 qPut(&busyHead, a_xInfoP->volid);
1022 fprintf(STDOUT, "VOLUME_BUSY\t%lu\n",
1023 (unsigned long)a_xInfoP->volid);
1027 qPut(¬okHead, a_xInfoP->volid);
1029 fprintf(STDOUT, "COULD_NOT_ATTACH_VOLUME\t%lu\n",
1030 (unsigned long)a_xInfoP->volid);
1031 } /*Screwed volume */
1032 } /*Default listing */
1033 } /*XDisplayFormat */
1036 DisplayFormat2(long server, long partition, volintInfo *pntr)
1038 static long server_cache = -1, partition_cache = -1;
1039 static char hostname[256], address[32], pname[16];
1042 if (server != server_cache) {
1046 strcpy(hostname, hostutil_GetNameByINet(server));
1047 strcpy(address, inet_ntoa(s));
1048 server_cache = server;
1050 if (partition != partition_cache) {
1051 MapPartIdIntoName(partition, pname);
1052 partition_cache = partition;
1055 if (pntr->status == VOK)
1056 fprintf(STDOUT, "name\t\t%s\n", pntr->name);
1058 fprintf(STDOUT, "id\t\t%lu\n",
1059 afs_printable_uint32_lu(pntr->volid));
1060 fprintf(STDOUT, "serv\t\t%s\t%s\n", address, hostname);
1061 fprintf(STDOUT, "part\t\t%s\n", pname);
1062 switch (pntr->status) {
1064 fprintf(STDOUT, "status\t\tOK\n");
1067 fprintf(STDOUT, "status\t\tBUSY\n");
1070 fprintf(STDOUT, "status\t\tUNATTACHABLE\n");
1073 fprintf(STDOUT, "backupID\t%lu\n",
1074 afs_printable_uint32_lu(pntr->backupID));
1075 fprintf(STDOUT, "parentID\t%lu\n",
1076 afs_printable_uint32_lu(pntr->parentID));
1077 fprintf(STDOUT, "cloneID\t\t%lu\n",
1078 afs_printable_uint32_lu(pntr->cloneID));
1079 fprintf(STDOUT, "inUse\t\t%s\n", pntr->inUse ? "Y" : "N");
1080 fprintf(STDOUT, "needsSalvaged\t%s\n", pntr->needsSalvaged ? "Y" : "N");
1081 /* 0xD3 is from afs/volume.h since I had trouble including the file */
1082 fprintf(STDOUT, "destroyMe\t%s\n", pntr->destroyMe == 0xD3 ? "Y" : "N");
1083 switch (pntr->type) {
1085 fprintf(STDOUT, "type\t\tRW\n");
1088 fprintf(STDOUT, "type\t\tRO\n");
1091 fprintf(STDOUT, "type\t\tBK\n");
1094 fprintf(STDOUT, "type\t\t?\n");
1097 t = pntr->creationDate;
1098 fprintf(STDOUT, "creationDate\t%-9lu\t%s",
1099 afs_printable_uint32_lu(pntr->creationDate),
1102 t = pntr->accessDate;
1103 fprintf(STDOUT, "accessDate\t%-9lu\t%s",
1104 afs_printable_uint32_lu(pntr->accessDate),
1107 t = pntr->updateDate;
1108 fprintf(STDOUT, "updateDate\t%-9lu\t%s",
1109 afs_printable_uint32_lu(pntr->updateDate),
1112 t = pntr->backupDate;
1113 fprintf(STDOUT, "backupDate\t%-9lu\t%s",
1114 afs_printable_uint32_lu(pntr->backupDate),
1118 fprintf(STDOUT, "copyDate\t%-9lu\t%s",
1119 afs_printable_uint32_lu(pntr->copyDate),
1122 fprintf(STDOUT, "flags\t\t%#lx\t(Optional)\n",
1123 afs_printable_uint32_lu(pntr->flags));
1124 fprintf(STDOUT, "diskused\t%u\n", pntr->size);
1125 fprintf(STDOUT, "maxquota\t%u\n", pntr->maxquota);
1126 fprintf(STDOUT, "minquota\t%lu\t(Optional)\n",
1127 afs_printable_uint32_lu(pntr->spare0));
1128 fprintf(STDOUT, "filecount\t%u\n", pntr->filecount);
1129 fprintf(STDOUT, "dayUse\t\t%u\n", pntr->dayUse);
1130 fprintf(STDOUT, "weekUse\t\t%lu\t(Optional)\n",
1131 afs_printable_uint32_lu(pntr->spare1));
1132 fprintf(STDOUT, "spare2\t\t%lu\t(Optional)\n",
1133 afs_printable_uint32_lu(pntr->spare2));
1134 fprintf(STDOUT, "spare3\t\t%lu\t(Optional)\n",
1135 afs_printable_uint32_lu(pntr->spare3));
1140 DisplayVolumes2(long server, long partition, volintInfo *pntr, long count)
1144 for (i = 0; i < count; i++) {
1145 fprintf(STDOUT, "BEGIN_OF_ENTRY\n");
1146 DisplayFormat2(server, partition, pntr);
1147 fprintf(STDOUT, "END_OF_ENTRY\n\n");
1154 DisplayVolumes(afs_uint32 server, afs_int32 part, volintInfo *pntr,
1155 afs_int32 count, afs_int32 longlist, afs_int32 fast,
1158 int totalOK, totalNotOK, totalBusy, i;
1159 afs_uint32 volid = 0;
1166 for (i = 0; i < count; i++) {
1167 DisplayFormat(pntr, server, part, &totalOK, &totalNotOK, &totalBusy,
1172 while (busyHead.count) {
1173 qGet(&busyHead, &volid);
1174 fprintf(STDOUT, "**** Volume %lu is busy ****\n",
1175 (unsigned long)volid);
1179 while (notokHead.count) {
1180 qGet(¬okHead, &volid);
1181 fprintf(STDOUT, "**** Could not attach volume %lu ****\n",
1182 (unsigned long)volid);
1186 fprintf(STDOUT, "\n");
1189 "Total volumes onLine %d ; Total volumes offLine %d ; Total busy %d\n\n",
1190 totalOK, totalNotOK, totalBusy);
1194 /*------------------------------------------------------------------------
1195 * PRIVATE XDisplayVolumes
1198 * Display extended volume information.
1201 * a_servID : Pointer to the Rx call we're performing.
1202 * a_partID : Partition for which we want the extended list.
1203 * a_xInfoP : Ptr to extended volume info.
1204 * a_count : Number of volume records contained above.
1205 * a_int32 : Int32 listing generated?
1206 * a_fast : Fast listing generated?
1207 * a_quiet : Quiet listing generated?
1213 * Nothing interesting.
1217 *------------------------------------------------------------------------*/
1220 XDisplayVolumes(afs_uint32 a_servID, afs_int32 a_partID, volintXInfo *a_xInfoP,
1221 afs_int32 a_count, afs_int32 a_int32, afs_int32 a_fast,
1223 { /*XDisplayVolumes */
1225 int totalOK; /*Total OK volumes */
1226 int totalNotOK; /*Total screwed volumes */
1227 int totalBusy; /*Total busy volumes */
1228 int i; /*Loop variable */
1229 afs_uint32 volid = 0; /*Current volume ID */
1232 * Initialize counters and (global!!) queues.
1241 * Display each volume in the list.
1243 for (i = 0; i < a_count; i++) {
1244 XDisplayFormat(a_xInfoP, a_servID, a_partID, &totalOK, &totalNotOK,
1245 &totalBusy, a_fast, a_int32, 0);
1250 * If any volumes were found to be busy or screwed, display them.
1253 while (busyHead.count) {
1254 qGet(&busyHead, &volid);
1255 fprintf(STDOUT, "**** Volume %lu is busy ****\n",
1256 (unsigned long)volid);
1260 while (notokHead.count) {
1261 qGet(¬okHead, &volid);
1262 fprintf(STDOUT, "**** Could not attach volume %lu ****\n",
1263 (unsigned long)volid);
1268 fprintf(STDOUT, "\n");
1271 "Total volumes: %d on-line, %d off-line, %d busyd\n\n",
1272 totalOK, totalNotOK, totalBusy);
1276 } /*XDisplayVolumes */
1278 /*------------------------------------------------------------------------
1279 * PRIVATE XDisplayVolumes2
1282 * Display extended formated volume information.
1285 * a_servID : Pointer to the Rx call we're performing.
1286 * a_partID : Partition for which we want the extended list.
1287 * a_xInfoP : Ptr to extended volume info.
1288 * a_count : Number of volume records contained above.
1289 * a_int32 : Int32 listing generated?
1290 * a_fast : Fast listing generated?
1291 * a_quiet : Quiet listing generated?
1297 * Nothing interesting.
1301 *------------------------------------------------------------------------*/
1304 XDisplayVolumes2(afs_uint32 a_servID, afs_int32 a_partID, volintXInfo *a_xInfoP,
1305 afs_int32 a_count, afs_int32 a_int32, afs_int32 a_fast,
1307 { /*XDisplayVolumes */
1309 int totalOK; /*Total OK volumes */
1310 int totalNotOK; /*Total screwed volumes */
1311 int totalBusy; /*Total busy volumes */
1312 int i; /*Loop variable */
1313 afs_uint32 volid = 0; /*Current volume ID */
1316 * Initialize counters and (global!!) queues.
1325 * Display each volume in the list.
1327 for (i = 0; i < a_count; i++) {
1328 fprintf(STDOUT, "BEGIN_OF_ENTRY\n");
1329 XDisplayFormat2(a_xInfoP, a_servID, a_partID, &totalOK, &totalNotOK,
1330 &totalBusy, a_fast, a_int32, 0);
1331 fprintf(STDOUT, "END_OF_ENTRY\n");
1336 * If any volumes were found to be busy or screwed, display them.
1339 while (busyHead.count) {
1340 qGet(&busyHead, &volid);
1341 fprintf(STDOUT, "BUSY_VOL\t%lu\n",
1342 (unsigned long)volid);
1346 while (notokHead.count) {
1347 qGet(¬okHead, &volid);
1348 fprintf(STDOUT, "COULD_NOT_ATTACH\t%lu\n",
1349 (unsigned long)volid);
1354 fprintf(STDOUT, "\n");
1357 "VOLUMES_ONLINE\t%d\nVOLUMES_OFFLINE\t%d\nVOLUMES_BUSY\t%d\n",
1358 totalOK, totalNotOK, totalBusy);
1362 } /*XDisplayVolumes2 */
1365 /* set <server> and <part> to the correct values depending on
1366 * <voltype> and <entry> */
1368 GetServerAndPart(struct nvldbentry *entry, int voltype, afs_uint32 *server,
1369 afs_int32 *part, int *previdx)
1371 int i, istart, vtype;
1376 /* Doesn't check for non-existance of backup volume */
1377 if ((voltype == RWVOL) || (voltype == BACKVOL)) {
1379 istart = 0; /* seach the entire entry */
1382 /* Seach from beginning of entry or pick up where we left off */
1383 istart = ((*previdx < 0) ? 0 : *previdx + 1);
1386 for (i = istart; i < entry->nServers; i++) {
1387 if (entry->serverFlags[i] & vtype) {
1388 *server = entry->serverNumber[i];
1389 *part = entry->serverPartition[i];
1395 /* Didn't find any, return -1 */
1401 PrintLocked(afs_int32 aflags)
1403 afs_int32 flags = aflags & VLOP_ALLOPERS;
1406 fprintf(STDOUT, " Volume is currently LOCKED \n");
1408 if (flags & VLOP_MOVE) {
1409 fprintf(STDOUT, " Volume is locked for a move operation\n");
1411 if (flags & VLOP_RELEASE) {
1412 fprintf(STDOUT, " Volume is locked for a release operation\n");
1414 if (flags & VLOP_BACKUP) {
1415 fprintf(STDOUT, " Volume is locked for a backup operation\n");
1417 if (flags & VLOP_DELETE) {
1418 fprintf(STDOUT, " Volume is locked for a delete/misc operation\n");
1420 if (flags & VLOP_DUMP) {
1421 fprintf(STDOUT, " Volume is locked for a dump/restore operation\n");
1427 PostVolumeStats(struct nvldbentry *entry)
1429 SubEnumerateEntry(entry);
1430 /* Check for VLOP_ALLOPERS */
1431 PrintLocked(entry->flags);
1435 /*------------------------------------------------------------------------
1436 * PRIVATE XVolumeStats
1439 * Display extended volume information.
1442 * a_xInfoP : Ptr to extended volume info.
1443 * a_entryP : Ptr to the volume's VLDB entry.
1444 * a_srvID : Server ID.
1445 * a_partID : Partition ID.
1446 * a_volType : Type of volume to print.
1452 * Nothing interesting.
1456 *------------------------------------------------------------------------*/
1459 XVolumeStats(volintXInfo *a_xInfoP, struct nvldbentry *a_entryP,
1460 afs_int32 a_srvID, afs_int32 a_partID, int a_volType)
1463 int totalOK, totalNotOK, totalBusy; /*Dummies - we don't really count here */
1465 XDisplayFormat(a_xInfoP, /*Ptr to extended volume info */
1466 a_srvID, /*Server ID to print */
1467 a_partID, /*Partition ID to print */
1468 &totalOK, /*Ptr to total-OK counter */
1469 &totalNotOK, /*Ptr to total-screwed counter */
1470 &totalBusy, /*Ptr to total-busy counter */
1471 0, /*Don't do a fast listing */
1472 1, /*Do a long listing */
1473 1); /*Show volume problems */
1479 VolumeStats_int(volintInfo *pntr, struct nvldbentry *entry, afs_uint32 server,
1480 afs_int32 part, int voltype)
1482 int totalOK, totalNotOK, totalBusy;
1484 DisplayFormat(pntr, server, part, &totalOK, &totalNotOK, &totalBusy, 0, 1,
1489 /* command to forcibly remove a volume */
1491 NukeVolume(struct cmd_syndesc *as)
1500 server = GetServer(tp = as->parms[0].items->data);
1502 fprintf(STDERR, "vos: server '%s' not found in host table\n", tp);
1506 partID = volutil_GetPartitionID(tp = as->parms[1].items->data);
1508 fprintf(STDERR, "vos: could not parse '%s' as a partition name", tp);
1512 volID = vsu_GetVolumeID(tp = as->parms[2].items->data, cstruct, &err);
1515 PrintError("", err);
1518 "vos: could not parse '%s' as a numeric volume ID", tp);
1523 "vos: forcibly removing all traces of volume %d, please wait...",
1526 code = UV_NukeVolume(server, partID, volID);
1528 fprintf(STDOUT, "done.\n");
1530 fprintf(STDOUT, "failed with code %d.\n", code);
1535 /*------------------------------------------------------------------------
1536 * PRIVATE ExamineVolume
1539 * Routine used to examine a single volume, contacting the VLDB as
1540 * well as the Volume Server.
1543 * as : Ptr to parsed command line arguments.
1546 * 0 for a successful operation,
1547 * Otherwise, one of the ubik or VolServer error values.
1550 * Nothing interesting.
1554 *------------------------------------------------------------------------
1557 ExamineVolume(struct cmd_syndesc *as, void *arock)
1559 struct nvldbentry entry;
1560 afs_int32 vcode = 0;
1561 volintInfo *pntr = (volintInfo *) 0;
1562 volintXInfo *xInfoP = (volintXInfo *) 0;
1564 afs_int32 code, err, error = 0;
1565 int voltype, foundserv = 0, foundentry = 0;
1569 int wantExtendedInfo; /*Do we want extended vol info? */
1570 int isSubEnum=0; /* Keep track whether sub enumerate called. */
1571 wantExtendedInfo = (as->parms[1].items ? 1 : 0); /* -extended */
1573 volid = vsu_GetVolumeID(as->parms[0].items->data, cstruct, &err); /* -id */
1576 PrintError("", err);
1578 fprintf(STDERR, "Unknown volume ID or name '%s'\n",
1579 as->parms[0].items->data);
1584 fprintf(STDOUT, "Fetching VLDB entry for %lu .. ",
1585 (unsigned long)volid);
1588 vcode = VLDB_GetEntryByID(volid, -1, &entry);
1591 "Could not fetch the entry for volume number %lu from VLDB \n",
1592 (unsigned long)volid);
1596 fprintf(STDOUT, "done\n");
1597 MapHostToNetwork(&entry);
1599 if (entry.volumeId[RWVOL] == volid)
1601 else if (entry.volumeId[BACKVOL] == volid)
1603 else /* (entry.volumeId[ROVOL] == volid) */
1606 do { /* do {...} while (voltype == ROVOL) */
1607 /* Get the entry for the volume. If its a RW vol, get the RW entry.
1608 * It its a BK vol, get the RW entry (even if VLDB may say the BK doen't exist).
1609 * If its a RO vol, get the next RO entry.
1611 GetServerAndPart(&entry, ((voltype == ROVOL) ? ROVOL : RWVOL),
1612 &aserver, &apart, &previdx);
1613 if (previdx == -1) { /* searched all entries */
1615 fprintf(STDERR, "Volume %s does not exist in VLDB\n\n",
1616 as->parms[0].items->data);
1623 /* Get information about the volume from the server */
1625 fprintf(STDOUT, "Getting volume listing from the server %s .. ",
1626 hostutil_GetNameByINet(aserver));
1629 if (wantExtendedInfo)
1630 code = UV_XListOneVolume(aserver, apart, volid, &xInfoP);
1632 code = UV_ListOneVolume(aserver, apart, volid, &pntr);
1634 fprintf(STDOUT, "done\n");
1638 if (code == ENODEV) {
1639 if ((voltype == BACKVOL) && !(entry.flags & BACK_EXISTS)) {
1640 /* The VLDB says there is no backup volume and its not on disk */
1641 fprintf(STDERR, "Volume %s does not exist\n",
1642 as->parms[0].items->data);
1646 "Volume does not exist on server %s as indicated by the VLDB\n",
1647 hostutil_GetNameByINet(aserver));
1650 PrintDiagnostics("examine", code);
1652 fprintf(STDOUT, "\n");
1655 if (wantExtendedInfo)
1656 XVolumeStats(xInfoP, &entry, aserver, apart, voltype);
1657 else if (as->parms[2].items) {
1658 DisplayFormat2(aserver, apart, pntr);
1659 EnumerateEntry(&entry);
1662 VolumeStats_int(pntr, &entry, aserver, apart, voltype);
1664 if ((voltype == BACKVOL) && !(entry.flags & BACK_EXISTS)) {
1665 /* The VLDB says there is no backup volume yet we found one on disk */
1666 fprintf(STDERR, "Volume %s does not exist in VLDB\n",
1667 as->parms[0].items->data);
1676 } while (voltype == ROVOL);
1679 fprintf(STDERR, "Dump only information from VLDB\n\n");
1680 fprintf(STDOUT, "%s \n", entry.name); /* PostVolumeStats doesn't print name */
1684 PostVolumeStats(&entry);
1689 /*------------------------------------------------------------------------
1693 * Routine used to change the status of a single volume.
1696 * as : Ptr to parsed command line arguments.
1699 * 0 for a successful operation,
1700 * Otherwise, one of the ubik or VolServer error values.
1703 * Nothing interesting.
1707 *------------------------------------------------------------------------
1710 SetFields(struct cmd_syndesc *as, void *arock)
1712 struct nvldbentry entry;
1715 afs_int32 code, err;
1720 volid = vsu_GetVolumeID(as->parms[0].items->data, cstruct, &err); /* -id */
1723 PrintError("", err);
1725 fprintf(STDERR, "Unknown volume ID or name '%s'\n",
1726 as->parms[0].items->data);
1730 code = VLDB_GetEntryByID(volid, RWVOL, &entry);
1733 "Could not fetch the entry for volume number %lu from VLDB \n",
1734 (unsigned long)volid);
1737 MapHostToNetwork(&entry);
1739 GetServerAndPart(&entry, RWVOL, &aserver, &apart, &previdx);
1740 if (previdx == -1) {
1741 fprintf(STDERR, "Volume %s does not exist in VLDB\n\n",
1742 as->parms[0].items->data);
1746 init_volintInfo(&info);
1750 if (as->parms[1].items) {
1752 code = util_GetHumanInt32(as->parms[1].items->data, &info.maxquota);
1754 fprintf(STDERR, "invalid quota value\n");
1758 if (as->parms[2].items) {
1762 if (as->parms[3].items) {
1763 /* -clearVolUpCounter */
1766 code = UV_SetVolumeInfo(aserver, apart, volid, &info);
1769 "Could not update volume info fields for volume number %lu\n",
1770 (unsigned long)volid);
1774 /*------------------------------------------------------------------------
1778 * Brings a volume online.
1781 * as : Ptr to parsed command line arguments.
1784 * 0 for a successful operation,
1787 * Nothing interesting.
1791 *------------------------------------------------------------------------
1794 volOnline(struct cmd_syndesc *as, void *arock)
1797 afs_int32 partition;
1799 afs_int32 code, err = 0;
1801 server = GetServer(as->parms[0].items->data);
1803 fprintf(STDERR, "vos: server '%s' not found in host table\n",
1804 as->parms[0].items->data);
1808 partition = volutil_GetPartitionID(as->parms[1].items->data);
1809 if (partition < 0) {
1810 fprintf(STDERR, "vos: could not interpret partition name '%s'\n",
1811 as->parms[1].items->data);
1815 volid = vsu_GetVolumeID(as->parms[2].items->data, cstruct, &err); /* -id */
1818 PrintError("", err);
1820 fprintf(STDERR, "Unknown volume ID or name '%s'\n",
1821 as->parms[0].items->data);
1825 code = UV_SetVolume(server, partition, volid, ITOffline, 0 /*online */ ,
1828 fprintf(STDERR, "Failed to set volume. Code = %d\n", code);
1835 /*------------------------------------------------------------------------
1836 * PRIVATE volOffline
1839 * Brings a volume offline.
1842 * as : Ptr to parsed command line arguments.
1845 * 0 for a successful operation,
1848 * Nothing interesting.
1852 *------------------------------------------------------------------------
1855 volOffline(struct cmd_syndesc *as, void *arock)
1858 afs_int32 partition;
1860 afs_int32 code, err = 0;
1861 afs_int32 transflag, sleeptime, transdone;
1863 server = GetServer(as->parms[0].items->data);
1865 fprintf(STDERR, "vos: server '%s' not found in host table\n",
1866 as->parms[0].items->data);
1870 partition = volutil_GetPartitionID(as->parms[1].items->data);
1871 if (partition < 0) {
1872 fprintf(STDERR, "vos: could not interpret partition name '%s'\n",
1873 as->parms[1].items->data);
1877 volid = vsu_GetVolumeID(as->parms[2].items->data, cstruct, &err); /* -id */
1880 PrintError("", err);
1882 fprintf(STDERR, "Unknown volume ID or name '%s'\n",
1883 as->parms[0].items->data);
1887 transflag = (as->parms[4].items ? ITBusy : ITOffline);
1888 sleeptime = (as->parms[3].items ? atol(as->parms[3].items->data) : 0);
1889 transdone = (sleeptime ? 0 /*online */ : VTOutOfService);
1890 if (as->parms[4].items && !as->parms[3].items) {
1891 fprintf(STDERR, "-sleep option must be used with -busy flag\n");
1896 UV_SetVolume(server, partition, volid, transflag, transdone,
1899 fprintf(STDERR, "Failed to set volume. Code = %d\n", code);
1907 CreateVolume(struct cmd_syndesc *as, void *arock)
1911 afs_uint32 volid = 0, rovolid = 0, bkvolid = 0;
1912 afs_uint32 *arovolid;
1914 struct nvldbentry entry;
1918 arovolid = &rovolid;
1921 tserver = GetServer(as->parms[0].items->data);
1923 fprintf(STDERR, "vos: host '%s' not found in host table\n",
1924 as->parms[0].items->data);
1927 pnum = volutil_GetPartitionID(as->parms[1].items->data);
1929 fprintf(STDERR, "vos: could not interpret partition name '%s'\n",
1930 as->parms[1].items->data);
1933 if (!IsPartValid(pnum, tserver, &code)) { /*check for validity of the partition */
1935 PrintError("", code);
1938 "vos : partition %s does not exist on the server\n",
1939 as->parms[1].items->data);
1942 if (!ISNAMEVALID(as->parms[2].items->data)) {
1944 "vos: the name of the root volume %s exceeds the size limit of %d\n",
1945 as->parms[2].items->data, VOLSER_OLDMAXVOLNAME - 10);
1948 if (!VolNameOK(as->parms[2].items->data)) {
1950 "Illegal volume name %s, should not end in .readonly or .backup\n",
1951 as->parms[2].items->data);
1954 if (IsNumeric(as->parms[2].items->data)) {
1955 fprintf(STDERR, "Illegal volume name %s, should not be a number\n",
1956 as->parms[2].items->data);
1959 vcode = VLDB_GetEntryByName(as->parms[2].items->data, &entry);
1961 fprintf(STDERR, "Volume %s already exists\n",
1962 as->parms[2].items->data);
1963 PrintDiagnostics("create", code);
1967 if (as->parms[3].items) {
1968 code = util_GetHumanInt32(as->parms[3].items->data, "a);
1970 fprintf(STDERR, "vos: bad integer specified for quota.\n");
1975 if (as->parms[4].items) {
1976 if (!IsNumeric(as->parms[4].items->data)) {
1977 fprintf(STDERR, "vos: Given volume ID %s should be numeric.\n",
1978 as->parms[4].items->data);
1982 code = util_GetUInt32(as->parms[4].items->data, &volid);
1984 fprintf(STDERR, "vos: bad integer specified for volume ID.\n");
1989 if (as->parms[5].items) {
1990 if (!IsNumeric(as->parms[5].items->data)) {
1991 fprintf(STDERR, "vos: Given RO volume ID %s should be numeric.\n",
1992 as->parms[5].items->data);
1996 code = util_GetUInt32(as->parms[5].items->data, &rovolid);
1998 fprintf(STDERR, "vos: bad integer specified for volume ID.\n");
2008 UV_CreateVolume3(tserver, pnum, as->parms[2].items->data, quota, 0,
2009 0, 0, 0, &volid, arovolid, &bkvolid);
2011 PrintDiagnostics("create", code);
2014 MapPartIdIntoName(pnum, part);
2015 fprintf(STDOUT, "Volume %lu created on partition %s of %s\n",
2016 (unsigned long)volid, part, as->parms[0].items->data);
2023 DeleteAll(struct nvldbentry *entry)
2026 afs_int32 error, code, curserver, curpart;
2029 MapHostToNetwork(entry);
2031 for (i = 0; i < entry->nServers; i++) {
2032 curserver = entry->serverNumber[i];
2033 curpart = entry->serverPartition[i];
2034 if (entry->serverFlags[i] & ITSROVOL) {
2035 volid = entry->volumeId[ROVOL];
2037 volid = entry->volumeId[RWVOL];
2039 code = UV_DeleteVolume(curserver, curpart, volid);
2048 DeleteVolume(struct cmd_syndesc *as, void *arock)
2050 afs_int32 err, code = 0;
2051 afs_uint32 server = 0;
2052 afs_int32 partition = -1;
2057 if (as->parms[0].items) {
2058 server = GetServer(as->parms[0].items->data);
2060 fprintf(STDERR, "vos: server '%s' not found in host table\n",
2061 as->parms[0].items->data);
2066 if (as->parms[1].items) {
2067 partition = volutil_GetPartitionID(as->parms[1].items->data);
2068 if (partition < 0) {
2069 fprintf(STDERR, "vos: could not interpret partition name '%s'\n",
2070 as->parms[1].items->data);
2074 /* Check for validity of the partition */
2075 if (!IsPartValid(partition, server, &code)) {
2077 PrintError("", code);
2080 "vos : partition %s does not exist on the server\n",
2081 as->parms[1].items->data);
2087 volid = vsu_GetVolumeID(as->parms[2].items->data, cstruct, &err);
2089 fprintf(STDERR, "Can't find volume name '%s' in VLDB\n",
2090 as->parms[2].items->data);
2092 PrintError("", err);
2096 /* If the server or partition option are not complete, try to fill
2097 * them in from the VLDB entry.
2099 if ((partition == -1) || !server) {
2100 struct nvldbentry entry;
2102 code = VLDB_GetEntryByID(volid, -1, &entry);
2105 "Could not fetch the entry for volume %lu from VLDB\n",
2106 (unsigned long)volid);
2107 PrintError("", code);
2111 if (((volid == entry.volumeId[RWVOL]) && (entry.flags & RW_EXISTS))
2112 || ((volid == entry.volumeId[BACKVOL])
2113 && (entry.flags & BACK_EXISTS))) {
2114 idx = Lp_GetRwIndex(&entry);
2115 if ((idx == -1) || (server && (server != entry.serverNumber[idx]))
2116 || ((partition != -1)
2117 && (partition != entry.serverPartition[idx]))) {
2118 fprintf(STDERR, "VLDB: Volume '%s' no match\n",
2119 as->parms[2].items->data);
2122 } else if ((volid == entry.volumeId[ROVOL])
2123 && (entry.flags & RO_EXISTS)) {
2124 for (idx = -1, j = 0; j < entry.nServers; j++) {
2125 if (entry.serverFlags[j] != ITSROVOL)
2128 if (((server == 0) || (server == entry.serverNumber[j]))
2129 && ((partition == -1)
2130 || (partition == entry.serverPartition[j]))) {
2133 "VLDB: Volume '%s' matches more than one RO\n",
2134 as->parms[2].items->data);
2141 fprintf(STDERR, "VLDB: Volume '%s' no match\n",
2142 as->parms[2].items->data);
2146 fprintf(STDERR, "VLDB: Volume '%s' no match\n",
2147 as->parms[2].items->data);
2151 server = htonl(entry.serverNumber[idx]);
2152 partition = entry.serverPartition[idx];
2156 code = UV_DeleteVolume(server, partition, volid);
2158 PrintDiagnostics("remove", code);
2162 MapPartIdIntoName(partition, pname);
2163 fprintf(STDOUT, "Volume %lu on partition %s server %s deleted\n",
2164 (unsigned long)volid, pname, hostutil_GetNameByINet(server));
2168 #define TESTM 0 /* set for move space tests, clear for production */
2170 MoveVolume(struct cmd_syndesc *as, void *arock)
2174 afs_uint32 fromserver, toserver;
2175 afs_int32 frompart, topart;
2176 afs_int32 flags, code, err;
2177 char fromPartName[10], toPartName[10];
2179 struct diskPartition64 partition; /* for space check */
2182 volid = vsu_GetVolumeID(as->parms[0].items->data, cstruct, &err);
2185 PrintError("", err);
2187 fprintf(STDERR, "vos: can't find volume ID or name '%s'\n",
2188 as->parms[0].items->data);
2191 fromserver = GetServer(as->parms[1].items->data);
2192 if (fromserver == 0) {
2193 fprintf(STDERR, "vos: server '%s' not found in host table\n",
2194 as->parms[1].items->data);
2197 toserver = GetServer(as->parms[3].items->data);
2198 if (toserver == 0) {
2199 fprintf(STDERR, "vos: server '%s' not found in host table\n",
2200 as->parms[3].items->data);
2203 frompart = volutil_GetPartitionID(as->parms[2].items->data);
2205 fprintf(STDERR, "vos: could not interpret partition name '%s'\n",
2206 as->parms[2].items->data);
2209 if (!IsPartValid(frompart, fromserver, &code)) { /*check for validity of the partition */
2211 PrintError("", code);
2214 "vos : partition %s does not exist on the server\n",
2215 as->parms[2].items->data);
2218 topart = volutil_GetPartitionID(as->parms[4].items->data);
2220 fprintf(STDERR, "vos: could not interpret partition name '%s'\n",
2221 as->parms[4].items->data);
2224 if (!IsPartValid(topart, toserver, &code)) { /*check for validity of the partition */
2226 PrintError("", code);
2229 "vos : partition %s does not exist on the server\n",
2230 as->parms[4].items->data);
2235 if (as->parms[5].items) flags |= RV_NOCLONE;
2238 * check source partition for space to clone volume
2241 MapPartIdIntoName(topart, toPartName);
2242 MapPartIdIntoName(frompart, fromPartName);
2245 * check target partition for space to move volume
2248 code = UV_PartitionInfo64(toserver, toPartName, &partition);
2250 fprintf(STDERR, "vos: cannot access partition %s\n", toPartName);
2254 fprintf(STDOUT, "target partition %s free space %" AFS_INT64_FMT "\n", toPartName,
2257 p = (volintInfo *) 0;
2258 code = UV_ListOneVolume(fromserver, frompart, volid, &p);
2260 fprintf(STDERR, "vos:cannot access volume %lu\n",
2261 (unsigned long)volid);
2265 fprintf(STDOUT, "volume %lu size %d\n", (unsigned long)volid,
2267 if (partition.free <= p->size) {
2269 "vos: no space on target partition %s to move volume %lu\n",
2270 toPartName, (unsigned long)volid);
2277 fprintf(STDOUT, "size test - don't do move\n");
2281 /* successful move still not guaranteed but shoot for it */
2284 UV_MoveVolume2(volid, fromserver, frompart, toserver, topart, flags);
2286 PrintDiagnostics("move", code);
2289 MapPartIdIntoName(topart, toPartName);
2290 MapPartIdIntoName(frompart, fromPartName);
2291 fprintf(STDOUT, "Volume %lu moved from %s %s to %s %s \n",
2292 (unsigned long)volid, as->parms[1].items->data, fromPartName,
2293 as->parms[3].items->data, toPartName);
2299 CopyVolume(struct cmd_syndesc *as, void *arock)
2302 afs_uint32 fromserver, toserver;
2303 afs_int32 frompart, topart, code, err, flags;
2304 char fromPartName[10], toPartName[10], *tovolume;
2305 struct nvldbentry entry;
2306 struct diskPartition64 partition; /* for space check */
2309 volid = vsu_GetVolumeID(as->parms[0].items->data, cstruct, &err);
2312 PrintError("", err);
2314 fprintf(STDERR, "vos: can't find volume ID or name '%s'\n",
2315 as->parms[0].items->data);
2318 fromserver = GetServer(as->parms[1].items->data);
2319 if (fromserver == 0) {
2320 fprintf(STDERR, "vos: server '%s' not found in host table\n",
2321 as->parms[1].items->data);
2325 toserver = GetServer(as->parms[4].items->data);
2326 if (toserver == 0) {
2327 fprintf(STDERR, "vos: server '%s' not found in host table\n",
2328 as->parms[4].items->data);
2332 tovolume = as->parms[3].items->data;
2333 if (!ISNAMEVALID(tovolume)) {
2335 "vos: the name of the root volume %s exceeds the size limit of %d\n",
2336 tovolume, VOLSER_OLDMAXVOLNAME - 10);
2339 if (!VolNameOK(tovolume)) {
2341 "Illegal volume name %s, should not end in .readonly or .backup\n",
2345 if (IsNumeric(tovolume)) {
2346 fprintf(STDERR, "Illegal volume name %s, should not be a number\n",
2350 code = VLDB_GetEntryByName(tovolume, &entry);
2352 fprintf(STDERR, "Volume %s already exists\n", tovolume);
2353 PrintDiagnostics("copy", code);
2357 frompart = volutil_GetPartitionID(as->parms[2].items->data);
2359 fprintf(STDERR, "vos: could not interpret partition name '%s'\n",
2360 as->parms[2].items->data);
2363 if (!IsPartValid(frompart, fromserver, &code)) { /*check for validity of the partition */
2365 PrintError("", code);
2368 "vos : partition %s does not exist on the server\n",
2369 as->parms[2].items->data);
2373 topart = volutil_GetPartitionID(as->parms[5].items->data);
2375 fprintf(STDERR, "vos: could not interpret partition name '%s'\n",
2376 as->parms[5].items->data);
2379 if (!IsPartValid(topart, toserver, &code)) { /*check for validity of the partition */
2381 PrintError("", code);
2384 "vos : partition %s does not exist on the server\n",
2385 as->parms[5].items->data);
2390 if (as->parms[6].items) flags |= RV_OFFLINE;
2391 if (as->parms[7].items) flags |= RV_RDONLY;
2392 if (as->parms[8].items) flags |= RV_NOCLONE;
2394 MapPartIdIntoName(topart, toPartName);
2395 MapPartIdIntoName(frompart, fromPartName);
2398 * check target partition for space to move volume
2401 code = UV_PartitionInfo64(toserver, toPartName, &partition);
2403 fprintf(STDERR, "vos: cannot access partition %s\n", toPartName);
2407 fprintf(STDOUT, "target partition %s free space %" AFS_INT64_FMT "\n", toPartName,
2410 p = (volintInfo *) 0;
2411 code = UV_ListOneVolume(fromserver, frompart, volid, &p);
2413 fprintf(STDERR, "vos:cannot access volume %lu\n",
2414 (unsigned long)volid);
2418 if (partition.free <= p->size) {
2420 "vos: no space on target partition %s to copy volume %lu\n",
2421 toPartName, (unsigned long)volid);
2427 /* successful copy still not guaranteed but shoot for it */
2430 UV_CopyVolume2(volid, fromserver, frompart, tovolume, toserver,
2433 PrintDiagnostics("copy", code);
2436 MapPartIdIntoName(topart, toPartName);
2437 MapPartIdIntoName(frompart, fromPartName);
2438 fprintf(STDOUT, "Volume %lu copied from %s %s to %s on %s %s \n",
2439 (unsigned long)volid, as->parms[1].items->data, fromPartName,
2440 tovolume, as->parms[4].items->data, toPartName);
2447 ShadowVolume(struct cmd_syndesc *as, void *arock)
2449 afs_uint32 volid, tovolid;
2450 afs_uint32 fromserver, toserver;
2451 afs_int32 frompart, topart;
2452 afs_int32 code, err, flags;
2453 char fromPartName[10], toPartName[10], toVolName[32], *tovolume;
2454 struct diskPartition64 partition; /* for space check */
2457 p = (volintInfo *) 0;
2458 q = (volintInfo *) 0;
2460 volid = vsu_GetVolumeID(as->parms[0].items->data, cstruct, &err);
2463 PrintError("", err);
2465 fprintf(STDERR, "vos: can't find volume ID or name '%s'\n",
2466 as->parms[0].items->data);
2469 fromserver = GetServer(as->parms[1].items->data);
2470 if (fromserver == 0) {
2471 fprintf(STDERR, "vos: server '%s' not found in host table\n",
2472 as->parms[1].items->data);
2476 toserver = GetServer(as->parms[3].items->data);
2477 if (toserver == 0) {
2478 fprintf(STDERR, "vos: server '%s' not found in host table\n",
2479 as->parms[3].items->data);
2483 frompart = volutil_GetPartitionID(as->parms[2].items->data);
2485 fprintf(STDERR, "vos: could not interpret partition name '%s'\n",
2486 as->parms[2].items->data);
2489 if (!IsPartValid(frompart, fromserver, &code)) { /*check for validity of the partition */
2491 PrintError("", code);
2494 "vos : partition %s does not exist on the server\n",
2495 as->parms[2].items->data);
2499 topart = volutil_GetPartitionID(as->parms[4].items->data);
2501 fprintf(STDERR, "vos: could not interpret partition name '%s'\n",
2502 as->parms[4].items->data);
2505 if (!IsPartValid(topart, toserver, &code)) { /*check for validity of the partition */
2507 PrintError("", code);
2510 "vos : partition %s does not exist on the server\n",
2511 as->parms[4].items->data);
2515 if (as->parms[5].items) {
2516 tovolume = as->parms[5].items->data;
2517 if (!ISNAMEVALID(tovolume)) {
2519 "vos: the name of the root volume %s exceeds the size limit of %d\n",
2520 tovolume, VOLSER_OLDMAXVOLNAME - 10);
2523 if (!VolNameOK(tovolume)) {
2525 "Illegal volume name %s, should not end in .readonly or .backup\n",
2529 if (IsNumeric(tovolume)) {
2531 "Illegal volume name %s, should not be a number\n",
2536 /* use actual name of source volume */
2537 code = UV_ListOneVolume(fromserver, frompart, volid, &p);
2539 fprintf(STDERR, "vos:cannot access volume %lu\n",
2540 (unsigned long)volid);
2543 strcpy(toVolName, p->name);
2544 tovolume = toVolName;
2545 /* save p for size checks later */
2548 if (as->parms[6].items) {
2549 tovolid = vsu_GetVolumeID(as->parms[6].items->data, cstruct, &err);
2552 PrintError("", err);
2554 fprintf(STDERR, "vos: can't find volume ID or name '%s'\n",
2555 as->parms[6].items->data);
2561 tovolid = vsu_GetVolumeID(tovolume, cstruct, &err);
2564 PrintError("", err);
2566 fprintf(STDERR, "vos: can't find volume ID or name '%s'\n",
2575 if (as->parms[7].items) flags |= RV_OFFLINE;
2576 if (as->parms[8].items) flags |= RV_RDONLY;
2577 if (as->parms[9].items) flags |= RV_NOCLONE;
2578 if (as->parms[10].items) flags |= RV_CPINCR;
2580 MapPartIdIntoName(topart, toPartName);
2581 MapPartIdIntoName(frompart, fromPartName);
2584 * check target partition for space to move volume
2587 code = UV_PartitionInfo64(toserver, toPartName, &partition);
2589 fprintf(STDERR, "vos: cannot access partition %s\n", toPartName);
2593 fprintf(STDOUT, "target partition %s free space %" AFS_INT64_FMT "\n", toPartName,
2596 /* Don't do this again if we did it above */
2598 code = UV_ListOneVolume(fromserver, frompart, volid, &p);
2600 fprintf(STDERR, "vos:cannot access volume %lu\n",
2601 (unsigned long)volid);
2606 /* OK if this fails */
2607 code = UV_ListOneVolume(toserver, topart, tovolid, &q);
2609 /* Treat existing volume size as "free" */
2611 p->size = (q->size < p->size) ? p->size - q->size : 0;
2613 if (partition.free <= p->size) {
2615 "vos: no space on target partition %s to copy volume %lu\n",
2616 toPartName, (unsigned long)volid);
2624 /* successful copy still not guaranteed but shoot for it */
2627 UV_CopyVolume2(volid, fromserver, frompart, tovolume, toserver,
2628 topart, tovolid, flags);
2630 PrintDiagnostics("shadow", code);
2633 MapPartIdIntoName(topart, toPartName);
2634 MapPartIdIntoName(frompart, fromPartName);
2635 fprintf(STDOUT, "Volume %lu shadowed from %s %s to %s %s \n",
2636 (unsigned long)volid, as->parms[1].items->data, fromPartName,
2637 as->parms[3].items->data, toPartName);
2644 CloneVolume(struct cmd_syndesc *as, void *arock)
2646 afs_uint32 volid, cloneid;
2648 afs_int32 part, voltype;
2649 char partName[10], *volname;
2650 afs_int32 code, err, flags;
2651 struct nvldbentry entry;
2653 volid = vsu_GetVolumeID(as->parms[0].items->data, cstruct, &err);
2656 PrintError("", err);
2658 fprintf(STDERR, "vos: can't find volume ID or name '%s'\n",
2659 as->parms[0].items->data);
2663 if (as->parms[1].items || as->parms[2].items) {
2664 if (!as->parms[1].items || !as->parms[2].items) {
2666 "Must specify both -server and -partition options\n");
2669 server = GetServer(as->parms[1].items->data);
2671 fprintf(STDERR, "vos: server '%s' not found in host table\n",
2672 as->parms[1].items->data);
2675 part = volutil_GetPartitionID(as->parms[2].items->data);
2677 fprintf(STDERR, "vos: could not interpret partition name '%s'\n",
2678 as->parms[2].items->data);
2681 if (!IsPartValid(part, server, &code)) { /*check for validity of the partition */
2683 PrintError("", code);
2686 "vos : partition %s does not exist on the server\n",
2687 as->parms[2].items->data);
2691 code = GetVolumeInfo(volid, &server, &part, &voltype, &entry);
2697 if (as->parms[3].items) {
2698 volname = as->parms[3].items->data;
2699 if (strlen(volname) > VOLSER_OLDMAXVOLNAME - 1) {
2701 "vos: the name of the root volume %s exceeds the size limit of %d\n",
2702 volname, VOLSER_OLDMAXVOLNAME - 1);
2707 * In order that you be able to make clones of RO or BK, this
2708 * check must be omitted.
2710 if (!VolNameOK(volname)) {
2712 "Illegal volume name %s, should not end in .readonly or .backup\n",
2717 if (IsNumeric(volname)) {
2719 "Illegal volume name %s, should not be a number\n",
2726 if (as->parms[4].items) {
2727 cloneid = vsu_GetVolumeID(as->parms[4].items->data, cstruct, &err);
2730 PrintError("", err);
2732 fprintf(STDERR, "vos: can't find volume ID or name '%s'\n",
2733 as->parms[4].items->data);
2739 if (as->parms[5].items) flags |= RV_OFFLINE;
2740 if (as->parms[6].items) flags |= RV_RDONLY;
2744 UV_CloneVolume(server, part, volid, cloneid, volname, flags);
2747 PrintDiagnostics("clone", code);
2750 MapPartIdIntoName(part, partName);
2751 fprintf(STDOUT, "Created clone for volume %s\n",
2752 as->parms[0].items->data);
2759 BackupVolume(struct cmd_syndesc *as, void *arock)
2763 afs_int32 apart, vtype, code, err;
2764 struct nvldbentry entry;
2767 afs_uint32 buserver;
2768 afs_int32 bupart, butype;
2769 struct nvldbentry buentry;
2771 avolid = vsu_GetVolumeID(as->parms[0].items->data, cstruct, &err);
2774 PrintError("", err);
2776 fprintf(STDERR, "vos: can't find volume ID or name '%s'\n",
2777 as->parms[0].items->data);
2780 code = GetVolumeInfo(avolid, &aserver, &apart, &vtype, &entry);
2784 /* verify this is a readwrite volume */
2786 if (vtype != RWVOL) {
2787 fprintf(STDERR, "%s not RW volume\n", as->parms[0].items->data);
2791 /* is there a backup volume already? */
2793 if (entry.flags & BACK_EXISTS) {
2794 /* yep, where is it? */
2796 buvolid = entry.volumeId[BACKVOL];
2797 code = GetVolumeInfo(buvolid, &buserver, &bupart, &butype, &buentry);
2802 code = VLDB_IsSameAddrs(buserver, aserver, &err);
2805 "Failed to get info about server's %d address(es) from vlserver; aborting call!\n",
2811 "FATAL ERROR: backup volume %lu exists on server %lu\n",
2812 (unsigned long)buvolid, (unsigned long)buserver);
2817 /* nope, carry on */
2819 code = UV_BackupVolume(aserver, apart, avolid);
2822 PrintDiagnostics("backup", code);
2825 fprintf(STDOUT, "Created backup volume for %s \n",
2826 as->parms[0].items->data);
2831 ReleaseVolume(struct cmd_syndesc *as, void *arock)
2834 struct nvldbentry entry;
2837 afs_int32 apart, vtype, code, err;
2840 if (as->parms[1].items)
2842 avolid = vsu_GetVolumeID(as->parms[0].items->data, cstruct, &err);
2845 PrintError("", err);
2847 fprintf(STDERR, "vos: can't find volume '%s'\n",
2848 as->parms[0].items->data);
2851 code = GetVolumeInfo(avolid, &aserver, &apart, &vtype, &entry);
2855 if (vtype != RWVOL) {
2856 fprintf(STDERR, "%s not a RW volume\n", as->parms[0].items->data);
2860 if (!ISNAMEVALID(entry.name)) {
2862 "Volume name %s is too long, rename before releasing\n",
2867 code = UV_ReleaseVolume(avolid, aserver, apart, force);
2869 PrintDiagnostics("release", code);
2872 fprintf(STDOUT, "Released volume %s successfully\n",
2873 as->parms[0].items->data);
2878 DumpVolumeCmd(struct cmd_syndesc *as, void *arock)
2882 afs_int32 apart, voltype, fromdate = 0, code, err, i, flags;
2883 char filename[MAXPATHLEN];
2884 struct nvldbentry entry;
2886 rx_SetRxDeadTime(60 * 10);
2887 for (i = 0; i < MAXSERVERS; i++) {
2888 struct rx_connection *rxConn = ubik_GetRPCConn(cstruct, i);
2891 rx_SetConnDeadTime(rxConn, rx_connDeadTime);
2892 if (rxConn->service)
2893 rxConn->service->connDeadTime = rx_connDeadTime;
2896 avolid = vsu_GetVolumeID(as->parms[0].items->data, cstruct, &err);
2899 PrintError("", err);
2901 fprintf(STDERR, "vos: can't find volume '%s'\n",
2902 as->parms[0].items->data);
2906 if (as->parms[3].items || as->parms[4].items) {
2907 if (!as->parms[3].items || !as->parms[4].items) {
2909 "Must specify both -server and -partition options\n");
2912 aserver = GetServer(as->parms[3].items->data);
2914 fprintf(STDERR, "Invalid server name\n");
2917 apart = volutil_GetPartitionID(as->parms[4].items->data);
2919 fprintf(STDERR, "Invalid partition name\n");
2923 code = GetVolumeInfo(avolid, &aserver, &apart, &voltype, &entry);
2928 if (as->parms[1].items && strcmp(as->parms[1].items->data, "0")) {
2929 code = ktime_DateToInt32(as->parms[1].items->data, &fromdate);
2931 fprintf(STDERR, "vos: failed to parse date '%s' (error=%d))\n",
2932 as->parms[1].items->data, code);
2936 if (as->parms[2].items) {
2937 strcpy(filename, as->parms[2].items->data);
2939 strcpy(filename, "");
2942 flags = as->parms[6].items ? VOLDUMPV2_OMITDIRS : 0;
2944 if (as->parms[5].items) {
2946 UV_DumpClonedVolume(avolid, aserver, apart, fromdate,
2947 DumpFunction, filename, flags);
2950 UV_DumpVolume(avolid, aserver, apart, fromdate, DumpFunction,
2953 if ((code == RXGEN_OPCODE) && (as->parms[6].items)) {
2954 flags &= ~VOLDUMPV2_OMITDIRS;
2958 PrintDiagnostics("dump", code);
2961 if (strcmp(filename, ""))
2962 fprintf(STDERR, "Dumped volume %s in file %s\n",
2963 as->parms[0].items->data, filename);
2965 fprintf(STDERR, "Dumped volume %s in stdout \n",
2966 as->parms[0].items->data);
2980 RestoreVolumeCmd(struct cmd_syndesc *as, void *arock)
2982 afs_uint32 avolid, aparentid;
2984 afs_int32 apart, code, vcode, err;
2985 afs_int32 aoverwrite = ASK;
2986 afs_int32 acreation = 0, alastupdate = 0;
2987 int restoreflags = 0;
2988 int readonly = 0, offline = 0, voltype = RWVOL;
2989 char afilename[MAXPATHLEN], avolname[VOLSER_MAXVOLNAME + 1], apartName[10];
2990 char volname[VOLSER_MAXVOLNAME + 1];
2991 struct nvldbentry entry;
2994 if (as->parms[4].items) {
2995 avolid = vsu_GetVolumeID(as->parms[4].items->data, cstruct, &err);
2998 PrintError("", err);
3000 fprintf(STDERR, "vos: can't find volume '%s'\n",
3001 as->parms[4].items->data);
3007 if (as->parms[5].items) {
3008 if ((strcmp(as->parms[5].items->data, "a") == 0)
3009 || (strcmp(as->parms[5].items->data, "abort") == 0)) {
3011 } else if ((strcmp(as->parms[5].items->data, "f") == 0)
3012 || (strcmp(as->parms[5].items->data, "full") == 0)) {
3014 } else if ((strcmp(as->parms[5].items->data, "i") == 0)
3015 || (strcmp(as->parms[5].items->data, "inc") == 0)
3016 || (strcmp(as->parms[5].items->data, "increment") == 0)
3017 || (strcmp(as->parms[5].items->data, "incremental") == 0)) {
3020 fprintf(STDERR, "vos: %s is not a valid argument to -overwrite\n",
3021 as->parms[5].items->data);
3025 if (as->parms[6].items)
3027 if (as->parms[7].items) {
3032 if (as->parms[8].items) {
3033 if ((strcmp(as->parms[8].items->data, "d") == 0)
3034 || (strcmp(as->parms[8].items->data, "dump") == 0)) {
3035 acreation = TS_DUMP;
3036 } else if ((strcmp(as->parms[8].items->data, "k") == 0)
3037 || (strcmp(as->parms[8].items->data, "keep") == 0)) {
3038 acreation = TS_KEEP;
3039 } else if ((strcmp(as->parms[8].items->data, "n") == 0)
3040 || (strcmp(as->parms[8].items->data, "new") == 0)) {
3043 fprintf(STDERR, "vos: %s is not a valid argument to -creation\n",
3044 as->parms[8].items->data);
3049 if (as->parms[9].items) {
3050 if ((strcmp(as->parms[9].items->data, "d") == 0)
3051 || (strcmp(as->parms[9].items->data, "dump") == 0)) {
3052 alastupdate = TS_DUMP;
3053 } else if ((strcmp(as->parms[9].items->data, "k") == 0)
3054 || (strcmp(as->parms[9].items->data, "keep") == 0)) {
3055 alastupdate = TS_KEEP;
3056 } else if ((strcmp(as->parms[9].items->data, "n") == 0)
3057 || (strcmp(as->parms[9].items->data, "new") == 0)) {
3058 alastupdate = TS_NEW;
3060 fprintf(STDERR, "vos: %s is not a valid argument to -lastupdate\n",
3061 as->parms[9].items->data);
3066 aserver = GetServer(as->parms[0].items->data);
3068 fprintf(STDERR, "vos: server '%s' not found in host table\n",
3069 as->parms[0].items->data);
3072 apart = volutil_GetPartitionID(as->parms[1].items->data);
3074 fprintf(STDERR, "vos: could not interpret partition name '%s'\n",
3075 as->parms[1].items->data);
3078 if (!IsPartValid(apart, aserver, &code)) { /*check for validity of the partition */
3080 PrintError("", code);
3083 "vos : partition %s does not exist on the server\n",
3084 as->parms[1].items->data);
3087 strcpy(avolname, as->parms[2].items->data);
3088 if (!ISNAMEVALID(avolname)) {
3090 "vos: the name of the volume %s exceeds the size limit\n",
3094 if (!VolNameOK(avolname)) {
3096 "Illegal volume name %s, should not end in .readonly or .backup\n",
3100 if (as->parms[3].items) {
3101 strcpy(afilename, as->parms[3].items->data);
3102 if (!FileExists(afilename)) {
3103 fprintf(STDERR, "Can't access file %s\n", afilename);
3107 strcpy(afilename, "");
3110 /* Check if volume exists or not */
3112 vsu_ExtractName(volname, avolname);
3113 vcode = VLDB_GetEntryByName(volname, &entry);
3114 if (vcode) { /* no volume - do a full restore */
3115 restoreflags = RV_FULLRST;
3116 if ((aoverwrite == INC) || (aoverwrite == ABORT))
3118 "Volume does not exist; Will perform a full restore\n");
3121 else if ((!readonly && Lp_GetRwIndex(&entry) == -1) /* RW volume does not exist - do a full */
3122 ||(readonly && !Lp_ROMatch(0, 0, &entry))) { /* RO volume does not exist - do a full */
3123 restoreflags = RV_FULLRST;
3124 if ((aoverwrite == INC) || (aoverwrite == ABORT))
3126 "%s Volume does not exist; Will perform a full restore\n",
3127 readonly ? "RO" : "RW");
3130 avolid = entry.volumeId[voltype];
3131 } else if (entry.volumeId[voltype] != 0
3132 && entry.volumeId[voltype] != avolid) {
3133 avolid = entry.volumeId[voltype];
3135 aparentid = entry.volumeId[RWVOL];
3138 else { /* volume exists - do we do a full incremental or abort */
3140 afs_int32 Opart, Otype, vol_elsewhere = 0;
3141 struct nvldbentry Oentry;
3145 avolid = entry.volumeId[voltype];
3146 } else if (entry.volumeId[voltype] != 0
3147 && entry.volumeId[voltype] != avolid) {
3148 avolid = entry.volumeId[voltype];
3150 aparentid = entry.volumeId[RWVOL];
3152 /* A file name was specified - check if volume is on another partition */
3153 vcode = GetVolumeInfo(avolid, &Oserver, &Opart, &Otype, &Oentry);
3157 vcode = VLDB_IsSameAddrs(Oserver, aserver, &err);
3160 "Failed to get info about server's %d address(es) from vlserver (err=%d); aborting call!\n",
3164 if (!vcode || (Opart != apart))
3167 if (aoverwrite == ASK) {
3168 if (strcmp(afilename, "") == 0) { /* The file is from standard in */
3170 "Volume exists and no -overwrite option specified; Aborting restore command\n");
3174 /* Ask what to do */
3175 if (vol_elsewhere) {
3177 "The volume %s %u already exists on a different server/part\n",
3178 volname, entry.volumeId[voltype]);
3180 "Do you want to do a full restore or abort? [fa](a): ");
3183 "The volume %s %u already exists in the VLDB\n",
3184 volname, entry.volumeId[voltype]);
3186 "Do you want to do a full/incremental restore or abort? [fia](a): ");
3189 while (!(dc == EOF || dc == '\n'))
3190 dc = getchar(); /* goto end of line */
3191 if ((c == 'f') || (c == 'F'))
3193 else if ((c == 'i') || (c == 'I'))
3199 if (aoverwrite == ABORT) {
3200 fprintf(STDERR, "Volume exists; Aborting restore command\n");
3202 } else if (aoverwrite == FULL) {
3203 restoreflags = RV_FULLRST;
3205 "Volume exists; Will delete and perform full restore\n");
3206 } else if (aoverwrite == INC) {
3208 if (vol_elsewhere) {
3210 "%s volume %lu already exists on a different server/part; not allowed\n",
3211 readonly ? "RO" : "RW", (unsigned long)avolid);
3217 restoreflags |= RV_OFFLINE;
3219 restoreflags |= RV_RDONLY;
3221 switch (acreation) {
3223 restoreflags |= RV_CRDUMP;
3226 restoreflags |= RV_CRKEEP;
3229 restoreflags |= RV_CRNEW;
3232 if (aoverwrite == FULL)
3233 restoreflags |= RV_CRNEW;
3235 restoreflags |= RV_CRKEEP;
3238 switch (alastupdate) {
3240 restoreflags |= RV_LUDUMP;
3243 restoreflags |= RV_LUKEEP;
3246 restoreflags |= RV_LUNEW;
3249 restoreflags |= RV_LUDUMP;
3251 if (as->parms[10].items) {
3252 restoreflags |= RV_NODEL;
3257 UV_RestoreVolume2(aserver, apart, avolid, aparentid,
3258 avolname, restoreflags, WriteData, afilename);
3260 PrintDiagnostics("restore", code);
3263 MapPartIdIntoName(apart, apartName);
3266 * patch typo here - originally "parms[1]", should be "parms[0]"
3269 fprintf(STDOUT, "Restored volume %s on %s %s\n", avolname,
3270 as->parms[0].items->data, apartName);
3275 LockReleaseCmd(struct cmd_syndesc *as, void *arock)
3278 afs_int32 code, err;
3280 avolid = vsu_GetVolumeID(as->parms[0].items->data, cstruct, &err);
3283 PrintError("", err);
3285 fprintf(STDERR, "vos: can't find volume '%s'\n",
3286 as->parms[0].items->data);
3290 code = UV_LockRelease(avolid);
3292 PrintDiagnostics("unlock", code);
3295 fprintf(STDOUT, "Released lock on vldb entry for volume %s\n",
3296 as->parms[0].items->data);
3301 AddSite(struct cmd_syndesc *as, void *arock)
3305 afs_int32 apart, code, err, arovolid, valid = 0;
3306 char apartName[10], avolname[VOLSER_MAXVOLNAME + 1];
3308 vsu_ExtractName(avolname, as->parms[2].items->data);;
3309 avolid = vsu_GetVolumeID(avolname, cstruct, &err);
3312 PrintError("", err);
3314 fprintf(STDERR, "vos: can't find volume '%s'\n",
3315 as->parms[2].items->data);
3319 if (as->parms[3].items) {
3320 vsu_ExtractName(avolname, as->parms[3].items->data);
3321 arovolid = vsu_GetVolumeID(avolname, cstruct, &err);
3323 fprintf(STDERR, "vos: invalid ro volume id '%s'\n",
3324 as->parms[3].items->data);
3328 aserver = GetServer(as->parms[0].items->data);
3330 fprintf(STDERR, "vos: server '%s' not found in host table\n",
3331 as->parms[0].items->data);
3334 apart = volutil_GetPartitionID(as->parms[1].items->data);
3336 fprintf(STDERR, "vos: could not interpret partition name '%s'\n",
3337 as->parms[1].items->data);
3340 if (!IsPartValid(apart, aserver, &code)) { /*check for validity of the partition */
3342 PrintError("", code);
3345 "vos : partition %s does not exist on the server\n",
3346 as->parms[1].items->data);
3349 if (as->parms[4].items) {
3352 code = UV_AddSite2(aserver, apart, avolid, arovolid, valid);
3354 PrintDiagnostics("addsite", code);
3357 MapPartIdIntoName(apart, apartName);
3358 fprintf(STDOUT, "Added replication site %s %s for volume %s\n",
3359 as->parms[0].items->data, apartName, as->parms[2].items->data);
3364 RemoveSite(struct cmd_syndesc *as, void *arock)
3369 afs_int32 apart, code, err;
3370 char apartName[10], avolname[VOLSER_MAXVOLNAME + 1];
3372 vsu_ExtractName(avolname, as->parms[2].items->data);
3373 avolid = vsu_GetVolumeID(avolname, cstruct, &err);
3376 PrintError("", err);
3378 fprintf(STDERR, "vos: can't find volume '%s'\n",
3379 as->parms[2].items->data);
3382 aserver = GetServer(as->parms[0].items->data);
3384 fprintf(STDERR, "vos: server '%s' not found in host table\n",
3385 as->parms[0].items->data);
3388 apart = volutil_GetPartitionID(as->parms[1].items->data);
3390 fprintf(STDERR, "vos: could not interpret partition name '%s'\n",
3391 as->parms[1].items->data);
3395 *skip the partition validity check, since it is possible that the partition
3396 *has since been decomissioned.
3399 if (!IsPartValid(apart,aserver,&code)){
3400 if(code) PrintError("",code);
3401 else fprintf(STDERR,"vos : partition %s does not exist on the server\n",as->parms[1].items->data);
3405 code = UV_RemoveSite(aserver, apart, avolid);
3407 PrintDiagnostics("remsite", code);
3410 MapPartIdIntoName(apart, apartName);
3411 fprintf(STDOUT, "Removed replication site %s %s for volume %s\n",
3412 as->parms[0].items->data, apartName, as->parms[2].items->data);
3417 ChangeLocation(struct cmd_syndesc *as, void *arock)
3421 afs_int32 apart, code, err;
3424 avolid = vsu_GetVolumeID(as->parms[2].items->data, cstruct, &err);
3427 PrintError("", err);
3429 fprintf(STDERR, "vos: can't find volume '%s'\n",
3430 as->parms[2].items->data);
3433 aserver = GetServer(as->parms[0].items->data);
3435 fprintf(STDERR, "vos: server '%s' not found in host table\n",
3436 as->parms[0].items->data);
3439 apart = volutil_GetPartitionID(as->parms[1].items->data);
3441 fprintf(STDERR, "vos: could not interpret partition name '%s'\n",
3442 as->parms[1].items->data);
3445 if (!IsPartValid(apart, aserver, &code)) { /*check for validity of the partition */
3447 PrintError("", code);
3450 "vos : partition %s does not exist on the server\n",
3451 as->parms[1].items->data);
3454 code = UV_ChangeLocation(aserver, apart, avolid);
3456 PrintDiagnostics("addsite", code);
3459 MapPartIdIntoName(apart, apartName);
3460 fprintf(STDOUT, "Changed location to %s %s for volume %s\n",
3461 as->parms[0].items->data, apartName, as->parms[2].items->data);
3466 ListPartitions(struct cmd_syndesc *as, void *arock)
3470 struct partList dummyPartList;
3475 aserver = GetServer(as->parms[0].items->data);
3477 fprintf(STDERR, "vos: server '%s' not found in host table\n",
3478 as->parms[0].items->data);
3483 code = UV_ListPartitions(aserver, &dummyPartList, &cnt);
3485 PrintDiagnostics("listpart", code);
3489 fprintf(STDOUT, "The partitions on the server are:\n");
3490 for (i = 0; i < cnt; i++) {
3491 if (dummyPartList.partFlags[i] & PARTVALID) {
3492 memset(pname, 0, sizeof(pname));
3493 MapPartIdIntoName(dummyPartList.partId[i], pname);
3494 fprintf(STDOUT, " %10s ", pname);
3496 if ((i % 5) == 0 && (i != 0))
3497 fprintf(STDOUT, "\n");
3500 fprintf(STDOUT, "\n");
3501 fprintf(STDOUT, "Total: %d\n", total);
3507 CompareVolName(const void *p1, const void *p2)
3509 volintInfo *arg1, *arg2;
3511 arg1 = (volintInfo *) p1;
3512 arg2 = (volintInfo *) p2;
3513 return (strcmp(arg1->name, arg2->name));
3517 /*------------------------------------------------------------------------
3518 * PRIVATE XCompareVolName
3521 * Comparison routine for volume names coming from an extended
3525 * a_obj1P : Char ptr to first extended vol info object
3526 * a_obj1P : Char ptr to second extended vol info object
3529 * The value of strcmp() on the volume names within the passed
3530 * objects (i,e., -1, 0, or 1).
3533 * Passed to qsort() as the designated comparison routine.
3537 *------------------------------------------------------------------------*/
3540 XCompareVolName(const void *a_obj1P, const void *a_obj2P)
3541 { /*XCompareVolName */
3544 (((struct volintXInfo *)(a_obj1P))->name,
3545 ((struct volintXInfo *)(a_obj2P))->name));
3547 } /*XCompareVolName */
3550 CompareVolID(const void *p1, const void *p2)
3552 volintInfo *arg1, *arg2;
3554 arg1 = (volintInfo *) p1;
3555 arg2 = (volintInfo *) p2;
3556 if (arg1->volid == arg2->volid)
3558 if (arg1->volid > arg2->volid)
3565 /*------------------------------------------------------------------------
3566 * PRIVATE XCompareVolID
3569 * Comparison routine for volume IDs coming from an extended
3573 * a_obj1P : Char ptr to first extended vol info object
3574 * a_obj1P : Char ptr to second extended vol info object
3577 * The value of strcmp() on the volume names within the passed
3578 * objects (i,e., -1, 0, or 1).
3581 * Passed to qsort() as the designated comparison routine.
3585 *------------------------------------------------------------------------*/
3588 XCompareVolID(const void *a_obj1P, const void *a_obj2P)
3589 { /*XCompareVolID */
3591 afs_int32 id1, id2; /*Volume IDs we're comparing */
3593 id1 = ((struct volintXInfo *)(a_obj1P))->volid;
3594 id2 = ((struct volintXInfo *)(a_obj2P))->volid;
3602 } /*XCompareVolID */
3604 /*------------------------------------------------------------------------
3605 * PRIVATE ListVolumes
3608 * Routine used to list volumes, contacting the Volume Server
3609 * directly, bypassing the VLDB.
3612 * as : Ptr to parsed command line arguments.
3615 * 0 Successful operation
3618 * Nothing interesting.
3622 *------------------------------------------------------------------------*/
3625 ListVolumes(struct cmd_syndesc *as, void *arock)
3627 afs_int32 apart, int32list, fast;
3631 volintInfo *oldpntr = NULL;
3635 volintXInfo *xInfoP;
3636 volintXInfo *origxInfoP = NULL; /*Ptr to current/orig extended vol info */
3637 int wantExtendedInfo; /*Do we want extended vol info? */
3640 struct partList dummyPartList;
3648 if (as->parms[3].items)
3650 if (as->parms[4].items)
3654 if (as->parms[2].items)
3660 if (as->parms[5].items) {
3662 * We can't coexist with the fast flag.
3666 "vos: Can't use the -fast and -extended flags together\n");
3671 * We need to turn on ``long'' listings to get the full effect.
3673 wantExtendedInfo = 1;
3676 wantExtendedInfo = 0;
3677 if (as->parms[1].items) {
3678 apart = volutil_GetPartitionID(as->parms[1].items->data);
3680 fprintf(STDERR, "vos: could not interpret partition name '%s'\n",
3681 as->parms[1].items->data);
3684 dummyPartList.partId[0] = apart;
3685 dummyPartList.partFlags[0] = PARTVALID;
3688 aserver = GetServer(as->parms[0].items->data);
3690 fprintf(STDERR, "vos: server '%s' not found in host table\n",
3691 as->parms[0].items->data);
3696 if (!IsPartValid(apart, aserver, &code)) { /*check for validity of the partition */
3698 PrintError("", code);
3701 "vos : partition %s does not exist on the server\n",
3702 as->parms[1].items->data);
3706 code = UV_ListPartitions(aserver, &dummyPartList, &cnt);
3708 PrintDiagnostics("listvol", code);
3712 for (i = 0; i < cnt; i++) {
3713 if (dummyPartList.partFlags[i] & PARTVALID) {
3714 if (wantExtendedInfo)
3716 UV_XListVolumes(aserver, dummyPartList.partId[i], all,
3720 UV_ListVolumes(aserver, dummyPartList.partId[i], all,
3723 PrintDiagnostics("listvol", code);
3728 if (wantExtendedInfo) {
3729 origxInfoP = xInfoP;
3730 base = (char *)xInfoP;
3733 base = (char *)pntr;
3737 if (wantExtendedInfo)
3738 qsort(base, count, sizeof(volintXInfo), XCompareVolName);
3740 qsort(base, count, sizeof(volintInfo), CompareVolName);
3742 if (wantExtendedInfo)
3743 qsort(base, count, sizeof(volintXInfo), XCompareVolID);
3745 qsort(base, count, sizeof(volintInfo), CompareVolID);
3747 MapPartIdIntoName(dummyPartList.partId[i], pname);
3750 "Total number of volumes on server %s partition %s: %lu \n",
3751 as->parms[0].items->data, pname,
3752 (unsigned long)count);
3753 if (wantExtendedInfo) {
3754 if (as->parms[6].items)
3755 XDisplayVolumes2(aserver, dummyPartList.partId[i], origxInfoP,
3756 count, int32list, fast, quiet);
3758 XDisplayVolumes(aserver, dummyPartList.partId[i], origxInfoP,
3759 count, int32list, fast, quiet);
3762 xInfoP = (volintXInfo *) 0;
3764 if (as->parms[6].items)
3765 DisplayVolumes2(aserver, dummyPartList.partId[i], oldpntr,
3768 DisplayVolumes(aserver, dummyPartList.partId[i], oldpntr,
3769 count, int32list, fast, quiet);
3772 pntr = (volintInfo *) 0;
3780 SyncVldb(struct cmd_syndesc *as, void *arock)
3782 afs_int32 pnum = 0, code; /* part name */
3788 if (as->parms[0].items) {
3789 tserver = GetServer(as->parms[0].items->data);
3791 fprintf(STDERR, "vos: host '%s' not found in host table\n",
3792 as->parms[0].items->data);
3797 if (as->parms[1].items) {
3798 pnum = volutil_GetPartitionID(as->parms[1].items->data);
3800 fprintf(STDERR, "vos: could not interpret partition name '%s'\n",
3801 as->parms[1].items->data);
3804 if (!IsPartValid(pnum, tserver, &code)) { /*check for validity of the partition */
3806 PrintError("", code);
3809 "vos: partition %s does not exist on the server\n",
3810 as->parms[1].items->data);
3817 "The -partition option requires a -server option\n");
3822 if (as->parms[3].items) {
3823 flags |= 2; /* don't update */
3826 if (as->parms[2].items) {
3827 /* Synchronize an individual volume */
3828 volname = as->parms[2].items->data;
3829 code = UV_SyncVolume(tserver, pnum, volname, flags);
3833 "Without a -volume option, the -server option is required\n");
3836 code = UV_SyncVldb(tserver, pnum, flags, 0 /*unused */ );
3840 PrintDiagnostics("syncvldb", code);
3844 /* Print a summary of what we did */
3846 fprintf(STDOUT, "VLDB volume %s synchronized", volname);
3848 fprintf(STDOUT, "VLDB synchronized");
3850 fprintf(STDOUT, " with state of server %s", as->parms[0].items->data);
3853 MapPartIdIntoName(pnum, part);
3854 fprintf(STDOUT, " partition %s\n", part);
3856 fprintf(STDOUT, "\n");
3862 SyncServer(struct cmd_syndesc *as, void *arock)
3864 afs_int32 pnum, code; /* part name */
3869 tserver = GetServer(as->parms[0].items->data);
3871 fprintf(STDERR, "vos: host '%s' not found in host table\n",
3872 as->parms[0].items->data);
3875 if (as->parms[1].items) {
3876 pnum = volutil_GetPartitionID(as->parms[1].items->data);
3878 fprintf(STDERR, "vos: could not interpret partition name '%s'\n",
3879 as->parms[1].items->data);
3882 if (!IsPartValid(pnum, tserver, &code)) { /*check for validity of the partition */
3884 PrintError("", code);
3887 "vos : partition %s does not exist on the server\n",
3888 as->parms[1].items->data);
3896 if (as->parms[2].items) {
3897 flags |= 2; /* don't update */
3899 code = UV_SyncServer(tserver, pnum, flags, 0 /*unused */ );
3901 PrintDiagnostics("syncserv", code);
3905 MapPartIdIntoName(pnum, part);
3906 fprintf(STDOUT, "Server %s partition %s synchronized with VLDB\n",
3907 as->parms[0].items->data, part);
3909 fprintf(STDOUT, "Server %s synchronized with VLDB\n",
3910 as->parms[0].items->data);
3916 VolumeInfoCmd(char *name)
3918 struct nvldbentry entry;
3921 /* The vlserver will handle names with the .readonly
3922 * and .backup extension as well as volume ids.
3924 vcode = VLDB_GetEntryByName(name, &entry);
3926 PrintError("", vcode);
3929 MapHostToNetwork(&entry);
3930 EnumerateEntry(&entry);
3932 /* Defect #3027: grubby check to handle locked volume.
3933 * If VLOP_ALLOPERS is set, the entry is locked.
3934 * Leave this routine as is, but put in correct check.
3936 PrintLocked(entry.flags);
3942 VolumeZap(struct cmd_syndesc *as, void *arock)
3944 struct nvldbentry entry;
3945 afs_uint32 volid, zapbackupid = 0, backupid = 0;
3946 afs_int32 code, server, part, err;
3948 if (as->parms[3].items) {
3949 /* force flag is on, use the other version */
3950 return NukeVolume(as);
3953 if (as->parms[4].items) {
3957 volid = vsu_GetVolumeID(as->parms[2].items->data, cstruct, &err);
3960 PrintError("", err);
3962 fprintf(STDERR, "vos: can't find volume '%s'\n",
3963 as->parms[2].items->data);
3966 part = volutil_GetPartitionID(as->parms[1].items->data);
3968 fprintf(STDERR, "vos: could not interpret partition name '%s'\n",
3969 as->parms[1].items->data);
3972 server = GetServer(as->parms[0].items->data);
3974 fprintf(STDERR, "vos: host '%s' not found in host table\n",
3975 as->parms[0].items->data);
3978 if (!IsPartValid(part, server, &code)) { /*check for validity of the partition */
3980 PrintError("", code);
3983 "vos : partition %s does not exist on the server\n",
3984 as->parms[1].items->data);
3987 code = VLDB_GetEntryByID(volid, -1, &entry);
3989 if (volid == entry.volumeId[RWVOL])
3990 backupid = entry.volumeId[BACKVOL];
3992 "Warning: Entry for volume number %lu exists in VLDB (but we're zapping it anyway!)\n",
3993 (unsigned long)volid);
3996 volintInfo *pntr = (volintInfo *) 0;
3999 code = UV_ListOneVolume(server, part, volid, &pntr);
4001 if (volid == pntr->parentID)
4002 backupid = pntr->backupID;
4008 code = UV_VolumeZap(server, part, backupid);
4010 PrintDiagnostics("zap", code);
4013 fprintf(STDOUT, "Backup Volume %lu deleted\n",
4014 (unsigned long)backupid);
4017 code = UV_VolumeZap(server, part, volid);
4019 PrintDiagnostics("zap", code);
4022 fprintf(STDOUT, "Volume %lu deleted\n", (unsigned long)volid);
4028 VolserStatus(struct cmd_syndesc *as, void *arock)
4032 transDebugInfo *pntr, *oldpntr;
4038 server = GetServer(as->parms[0].items->data);
4040 fprintf(STDERR, "vos: host '%s' not found in host table\n",
4041 as->parms[0].items->data);
4044 code = UV_VolserStatus(server, &pntr, &count);
4046 PrintDiagnostics("status", code);
4051 fprintf(STDOUT, "No active transactions on %s\n",
4052 as->parms[0].items->data);
4054 fprintf(STDOUT, "Total transactions: %d\n", count);
4056 for (i = 0; i < count; i++) {
4057 /*print out the relevant info */
4058 fprintf(STDOUT, "--------------------------------------\n");
4059 t = pntr->creationTime;
4060 fprintf(STDOUT, "transaction: %lu created: %s",
4061 (unsigned long)pntr->tid, ctime(&t));
4063 fprintf(STDOUT, "lastActiveTime: %s", ctime(&t));
4064 if (pntr->returnCode) {
4065 fprintf(STDOUT, "returnCode: %lu\n",
4066 (unsigned long)pntr->returnCode);
4069 fprintf(STDOUT, "attachFlags: ");
4070 switch (pntr->iflags) {
4072 fprintf(STDOUT, "offline ");
4075 fprintf(STDOUT, "busy ");
4078 fprintf(STDOUT, "readonly ");
4081 fprintf(STDOUT, "create ");
4084 fprintf(STDOUT, "create volid ");
4087 fprintf(STDOUT, "\n");
4090 fprintf(STDOUT, "volumeStatus: ");
4091 switch (pntr->vflags) {
4092 case VTDeleteOnSalvage:
4093 fprintf(STDOUT, "deleteOnSalvage ");
4094 case VTOutOfService:
4095 fprintf(STDOUT, "outOfService ");
4097 fprintf(STDOUT, "deleted ");
4099 fprintf(STDOUT, "\n");
4102 fprintf(STDOUT, "transactionFlags: ");
4103 fprintf(STDOUT, "delete\n");
4105 MapPartIdIntoName(pntr->partition, pname);
4106 fprintf(STDOUT, "volume: %lu partition: %s procedure: %s\n",
4107 (unsigned long)pntr->volid, pname, pntr->lastProcName);
4108 if (pntr->callValid) {
4109 t = pntr->lastReceiveTime;
4110 fprintf(STDOUT, "packetRead: %lu lastReceiveTime: %s",
4111 (unsigned long)pntr->readNext, ctime(&t));
4112 t = pntr->lastSendTime;
4113 fprintf(STDOUT, "packetSend: %lu lastSendTime: %s",
4114 (unsigned long)pntr->transmitNext, ctime(&t));
4117 fprintf(STDOUT, "--------------------------------------\n");
4118 fprintf(STDOUT, "\n");
4126 RenameVolume(struct cmd_syndesc *as, void *arock)
4128 afs_int32 code1, code2, code;
4129 struct nvldbentry entry;
4131 code1 = VLDB_GetEntryByName(as->parms[0].items->data, &entry);
4133 fprintf(STDERR, "vos: Could not find entry for volume %s\n",
4134 as->parms[0].items->data);
4137 code2 = VLDB_GetEntryByName(as->parms[1].items->data, &entry);
4138 if ((!code1) && (!code2)) { /*the newname already exists */
4139 fprintf(STDERR, "vos: volume %s already exists\n",
4140 as->parms[1].items->data);
4144 if (code1 && code2) {
4145 fprintf(STDERR, "vos: Could not find entry for volume %s or %s\n",
4146 as->parms[0].items->data, as->parms[1].items->data);
4149 if (!VolNameOK(as->parms[0].items->data)) {
4151 "Illegal volume name %s, should not end in .readonly or .backup\n",
4152 as->parms[0].items->data);
4155 if (!ISNAMEVALID(as->parms[1].items->data)) {
4157 "vos: the new volume name %s exceeds the size limit of %d\n",
4158 as->parms[1].items->data, VOLSER_OLDMAXVOLNAME - 10);
4161 if (!VolNameOK(as->parms[1].items->data)) {
4163 "Illegal volume name %s, should not end in .readonly or .backup\n",
4164 as->parms[1].items->data);
4167 if (IsNumeric(as->parms[1].items->data)) {
4168 fprintf(STDERR, "Illegal volume name %s, should not be a number\n",
4169 as->parms[1].items->data);
4172 MapHostToNetwork(&entry);
4174 UV_RenameVolume(&entry, as->parms[0].items->data,
4175 as->parms[1].items->data);
4177 PrintDiagnostics("rename", code);
4180 fprintf(STDOUT, "Renamed volume %s to %s\n", as->parms[0].items->data,
4181 as->parms[1].items->data);
4186 GetVolumeInfo(afs_uint32 volid, afs_uint32 *server, afs_int32 *part, afs_int32 *voltype,
4187 struct nvldbentry *rentry)
4192 vcode = VLDB_GetEntryByID(volid, -1, rentry);
4195 "Could not fetch the entry for volume %lu from VLDB \n",
4196 (unsigned long)volid);
4197 PrintError("", vcode);
4200 MapHostToNetwork(rentry);
4201 if (volid == rentry->volumeId[ROVOL]) {
4203 for (i = 0; i < rentry->nServers; i++) {
4204 if ((index == -1) && (rentry->serverFlags[i] & ITSROVOL)
4205 && !(rentry->serverFlags[i] & RO_DONTUSE))
4210 "RO volume is not found in VLDB entry for volume %lu\n",
4211 (unsigned long)volid);
4215 *server = rentry->serverNumber[index];
4216 *part = rentry->serverPartition[index];
4220 index = Lp_GetRwIndex(rentry);
4223 "RW Volume is not found in VLDB entry for volume %lu\n",
4224 (unsigned long)volid);
4227 if (volid == rentry->volumeId[RWVOL]) {
4229 *server = rentry->serverNumber[index];
4230 *part = rentry->serverPartition[index];
4233 if (volid == rentry->volumeId[BACKVOL]) {
4235 *server = rentry->serverNumber[index];
4236 *part = rentry->serverPartition[index];
4240 "unexpected volume type for volume %lu\n",
4241 (unsigned long)volid);
4246 DeleteEntry(struct cmd_syndesc *as, void *arock)
4248 afs_int32 apart = 0;
4251 struct VldbListByAttributes attributes;
4252 nbulkentries arrayEntries;
4253 struct nvldbentry *vllist;
4254 struct cmd_item *itp;
4257 char prefix[VOLSER_MAXVOLNAME + 1];
4259 afs_int32 totalBack = 0, totalFail = 0, err;
4261 if (as->parms[0].items) { /* -id */
4262 if (as->parms[1].items || as->parms[2].items || as->parms[3].items) {
4264 "You cannot use -server, -partition, or -prefix with the -id argument\n");
4267 for (itp = as->parms[0].items; itp; itp = itp->next) {
4268 avolid = vsu_GetVolumeID(itp->data, cstruct, &err);
4271 PrintError("", err);
4273 fprintf(STDERR, "vos: can't find volume '%s'\n",
4277 if (as->parms[4].items || as->parms[5].items) {
4278 /* -noexecute (hidden) or -dryrun */
4279 fprintf(STDOUT, "Would have deleted VLDB entry for %s \n",
4284 vcode = ubik_VL_DeleteEntry(cstruct, 0, avolid, RWVOL);
4286 fprintf(STDERR, "Could not delete entry for volume %s\n",
4289 "You must specify a RW volume name or ID "
4290 "(the entire VLDB entry will be deleted)\n");
4291 PrintError("", vcode);
4297 fprintf(STDOUT, "Deleted %d VLDB entries\n", totalBack);
4301 if (!as->parms[1].items && !as->parms[2].items && !as->parms[3].items) {
4302 fprintf(STDERR, "You must specify an option\n");
4306 /* Zero out search attributes */
4307 memset(&attributes, 0, sizeof(struct VldbListByAttributes));
4309 if (as->parms[1].items) { /* -prefix */
4310 strncpy(prefix, as->parms[1].items->data, VOLSER_MAXVOLNAME);
4312 if (!as->parms[2].items && !as->parms[3].items) { /* a single entry only */
4314 "You must provide -server with the -prefix argument\n");
4319 if (as->parms[2].items) { /* -server */
4321 aserver = GetServer(as->parms[2].items->data);
4323 fprintf(STDERR, "vos: server '%s' not found in host table\n",
4324 as->parms[2].items->data);
4327 attributes.server = ntohl(aserver);
4328 attributes.Mask |= VLLIST_SERVER;
4331 if (as->parms[3].items) { /* -partition */
4332 if (!as->parms[2].items) {
4334 "You must provide -server with the -partition argument\n");
4337 apart = volutil_GetPartitionID(as->parms[3].items->data);
4339 fprintf(STDERR, "vos: could not interpret partition name '%s'\n",
4340 as->parms[3].items->data);
4343 attributes.partition = apart;
4344 attributes.Mask |= VLLIST_PARTITION;
4347 /* Print status line of what we are doing */
4348 fprintf(STDOUT, "Deleting VLDB entries for ");
4349 if (as->parms[2].items) {
4350 fprintf(STDOUT, "server %s ", as->parms[2].items->data);
4352 if (as->parms[3].items) {
4354 MapPartIdIntoName(apart, pname);
4355 fprintf(STDOUT, "partition %s ", pname);
4358 fprintf(STDOUT, "which are prefixed with %s ", prefix);
4360 fprintf(STDOUT, "\n");
4363 /* Get all the VLDB entries on a server and/or partition */
4364 memset(&arrayEntries, 0, sizeof(arrayEntries));
4365 vcode = VLDB_ListAttributes(&attributes, &nentries, &arrayEntries);
4367 fprintf(STDERR, "Could not access the VLDB for attributes\n");
4368 PrintError("", vcode);
4372 /* Process each entry */
4373 for (j = 0; j < nentries; j++) {
4374 vllist = &arrayEntries.nbulkentries_val[j];
4376 /* It only deletes the RW volumes */
4377 if (strncmp(vllist->name, prefix, strlen(prefix))) {
4380 "Omitting to delete %s due to prefix %s mismatch\n",
4381 vllist->name, prefix);
4388 if (as->parms[4].items || as->parms[5].items) {
4389 /* -noexecute (hidden) or -dryrun */
4390 fprintf(STDOUT, "Would have deleted VLDB entry for %s \n",
4396 /* Only matches the RW volume name */
4397 avolid = vllist->volumeId[RWVOL];
4398 vcode = ubik_VL_DeleteEntry(cstruct, 0, avolid, RWVOL);
4400 fprintf(STDOUT, "Could not delete VDLB entry for %s\n",
4403 PrintError("", vcode);
4408 fprintf(STDOUT, "Deleted VLDB entry for %s \n", vllist->name);
4413 fprintf(STDOUT, "----------------------\n");
4415 "Total VLDB entries deleted: %lu; failed to delete: %lu\n",
4416 (unsigned long)totalBack, (unsigned long)totalFail);
4418 xdr_free((xdrproc_t) xdr_nbulkentries, &arrayEntries);
4424 CompareVldbEntryByName(const void *p1, const void *p2)
4426 struct nvldbentry *arg1, *arg2;
4428 arg1 = (struct nvldbentry *)p1;
4429 arg2 = (struct nvldbentry *)p2;
4430 return (strcmp(arg1->name, arg2->name));
4434 static int CompareVldbEntry(char *p1, char *p2)
4436 struct nvldbentry *arg1,*arg2;
4439 char comp1[100],comp2[100];
4440 char temp1[20],temp2[20];
4442 arg1 = (struct nvldbentry *)p1;
4443 arg2 = (struct nvldbentry *)p2;
4447 for(i = 0; i < arg1->nServers; i++)
4448 if(arg1->serverFlags[i] & ITSRWVOL) pos1 = i;
4449 for(i = 0; i < arg2->nServers; i++)
4450 if(arg2->serverFlags[i] & ITSRWVOL) pos2 = i;
4451 if(pos1 == -1 || pos2 == -1){
4455 sprintf(comp1,"%10u",arg1->serverNumber[pos1]);
4456 sprintf(comp2,"%10u",arg2->serverNumber[pos2]);
4457 sprintf(temp1,"%10u",arg1->serverPartition[pos1]);
4458 sprintf(temp2,"%10u",arg2->serverPartition[pos2]);
4459 strcat(comp1,temp1);
4460 strcat(comp2,temp2);
4461 strcat(comp1,arg1->name);
4462 strcat(comp1,arg2->name);
4463 return(strcmp(comp1,comp2));
4469 ListVLDB(struct cmd_syndesc *as, void *arock)
4475 struct VldbListByAttributes attributes;
4476 nbulkentries arrayEntries;
4477 struct nvldbentry *vllist, *tarray = 0, *ttarray;
4478 afs_int32 centries, nentries = 0;
4479 afs_int32 tarraysize = 0;
4480 afs_int32 parraysize;
4483 int quiet, sort, lock;
4484 afs_int32 thisindex, nextindex;
4489 attributes.Mask = 0;
4490 lock = (as->parms[3].items ? 1 : 0); /* -lock flag */
4491 quiet = (as->parms[4].items ? 1 : 0); /* -quit flag */
4492 sort = (as->parms[5].items ? 0 : 1); /* -nosort flag */
4494 /* If the volume name is given, Use VolumeInfoCmd to look it up
4495 * and not ListAttributes.
4497 if (as->parms[0].items) {
4500 "vos: illegal use of '-locked' switch, need to specify server and/or partition\n");
4503 code = VolumeInfoCmd(as->parms[0].items->data);
4505 PrintError("", code);
4511 /* Server specified */
4512 if (as->parms[1].items) {
4513 aserver = GetServer(as->parms[1].items->data);
4515 fprintf(STDERR, "vos: server '%s' not found in host table\n",
4516 as->parms[1].items->data);
4519 attributes.server = ntohl(aserver);
4520 attributes.Mask |= VLLIST_SERVER;
4523 /* Partition specified */
4524 if (as->parms[2].items) {
4525 apart = volutil_GetPartitionID(as->parms[2].items->data);
4527 fprintf(STDERR, "vos: could not interpret partition name '%s'\n",
4528 as->parms[2].items->data);
4531 attributes.partition = apart;
4532 attributes.Mask |= VLLIST_PARTITION;
4536 attributes.Mask |= VLLIST_FLAG;
4537 attributes.flag = VLOP_ALLOPERS;
4540 /* Print header information */
4542 MapPartIdIntoName(apart, pname);
4543 fprintf(STDOUT, "VLDB entries for %s %s%s%s %s\n",
4544 (as->parms[1].items ? "server" : "all"),
4545 (as->parms[1].items ? as->parms[1].items->data : "servers"),
4546 (as->parms[2].items ? " partition " : ""),
4547 (as->parms[2].items ? pname : ""),
4548 (lock ? "which are locked:" : ""));
4551 for (thisindex = 0; (thisindex != -1); thisindex = nextindex) {
4552 memset(&arrayEntries, 0, sizeof(arrayEntries));
4557 VLDB_ListAttributesN2(&attributes, 0, thisindex, ¢ries,
4558 &arrayEntries, &nextindex);
4559 if (vcode == RXGEN_OPCODE) {
4560 /* Vlserver not running with ListAttributesN2. Fall back */
4562 VLDB_ListAttributes(&attributes, ¢ries, &arrayEntries);
4566 fprintf(STDERR, "Could not access the VLDB for attributes\n");
4567 PrintError("", vcode);
4570 nentries += centries;
4572 /* We don't sort, so just print the entries now */
4574 for (j = 0; j < centries; j++) { /* process each entry */
4575 vllist = &arrayEntries.nbulkentries_val[j];
4576 MapHostToNetwork(vllist);
4577 EnumerateEntry(vllist);
4579 PrintLocked(vllist->flags);
4583 /* So we sort. First we must collect all the entries and keep
4586 else if (centries > 0) {
4588 /* malloc the first bulk entries array */
4589 tarraysize = centries * sizeof(struct nvldbentry);
4590 tarray = malloc(tarraysize);
4593 "Could not allocate enough space for the VLDB entries\n");
4596 memcpy((char*)tarray, arrayEntries.nbulkentries_val, tarraysize);
4598 /* Grow the tarray to keep the extra entries */
4599 parraysize = (centries * sizeof(struct nvldbentry));
4601 (struct nvldbentry *)realloc(tarray,
4602 tarraysize + parraysize);
4605 "Could not allocate enough space for the VLDB entries\n");
4611 memcpy(((char *)tarray) + tarraysize,
4612 (char *)arrayEntries.nbulkentries_val, parraysize);
4613 tarraysize += parraysize;
4617 /* Free the bulk array */
4618 xdr_free((xdrproc_t) xdr_nbulkentries, &arrayEntries);
4621 /* Here is where we now sort all the entries and print them */
4622 if (sort && (nentries > 0)) {
4623 qsort((char *)tarray, nentries, sizeof(struct nvldbentry),
4624 CompareVldbEntryByName);
4625 for (vllist = tarray, j = 0; j < nentries; j++, vllist++) {
4626 MapHostToNetwork(vllist);
4627 EnumerateEntry(vllist);
4629 PrintLocked(vllist->flags);
4635 fprintf(STDOUT, "\nTotal entries: %lu\n", (unsigned long)nentries);
4642 BackSys(struct cmd_syndesc *as, void *arock)
4645 afs_int32 apart = 0;
4646 afs_uint32 aserver = 0, aserver1;
4647 afs_int32 code, apart1;
4649 struct VldbListByAttributes attributes;
4650 nbulkentries arrayEntries;
4651 struct nvldbentry *vllist;
4655 int seenprefix, seenxprefix, exclude, ex, exp, noaction;
4656 afs_int32 totalBack = 0;
4657 afs_int32 totalFail = 0;
4661 struct cmd_item *ti;
4663 #ifndef HAVE_POSIX_REGEX
4667 memset(&attributes, 0, sizeof(struct VldbListByAttributes));
4668 attributes.Mask = 0;
4670 seenprefix = (as->parms[0].items ? 1 : 0);
4671 exclude = (as->parms[3].items ? 1 : 0);
4672 seenxprefix = (as->parms[4].items ? 1 : 0);
4673 noaction = (as->parms[5].items ? 1 : 0);
4675 if (as->parms[1].items) { /* -server */
4676 aserver = GetServer(as->parms[1].items->data);
4678 fprintf(STDERR, "vos: server '%s' not found in host table\n",
4679 as->parms[1].items->data);
4682 attributes.server = ntohl(aserver);
4683 attributes.Mask |= VLLIST_SERVER;
4686 if (as->parms[2].items) { /* -partition */
4687 apart = volutil_GetPartitionID(as->parms[2].items->data);
4689 fprintf(STDERR, "vos: could not interpret partition name '%s'\n",
4690 as->parms[2].items->data);
4693 attributes.partition = apart;
4694 attributes.Mask |= VLLIST_PARTITION;
4697 /* Check to make sure the prefix and xprefix expressions compile ok */
4699 for (ti = as->parms[0].items; ti; ti = ti->next) {
4700 if (strncmp(ti->data, "^", 1) == 0) {
4701 #ifdef HAVE_POSIX_REGEX
4705 code = regcomp(&re, ti->data, REG_NOSUB);
4707 regerror(code, &re, errbuf, sizeof errbuf);
4709 "Unrecognizable -prefix regular expression: '%s': %s\n",
4715 ccode = (char *)re_comp(ti->data);
4718 "Unrecognizable -prefix regular expression: '%s': %s\n",
4727 for (ti = as->parms[4].items; ti; ti = ti->next) {
4728 if (strncmp(ti->data, "^", 1) == 0) {
4729 #ifdef HAVE_POSIX_REGEX
4733 code = regcomp(&re, ti->data, REG_NOSUB);
4735 regerror(code, &re, errbuf, sizeof errbuf);
4737 "Unrecognizable -xprefix regular expression: '%s': %s\n",
4743 ccode = (char *)re_comp(ti->data);
4746 "Unrecognizable -xprefix regular expression: '%s': %s\n",
4755 memset(&arrayEntries, 0, sizeof(arrayEntries)); /* initialize to hint the stub to alloc space */
4756 vcode = VLDB_ListAttributes(&attributes, &nentries, &arrayEntries);
4758 fprintf(STDERR, "Could not access the VLDB for attributes\n");
4759 PrintError("", vcode);
4763 if (as->parms[1].items || as->parms[2].items || verbose) {
4764 fprintf(STDOUT, "%s up volumes",
4765 (noaction ? "Would have backed" : "Backing"));
4767 if (as->parms[1].items) {
4768 fprintf(STDOUT, " on server %s", as->parms[1].items->data);
4769 } else if (as->parms[2].items) {
4770 fprintf(STDOUT, " for all servers");
4773 if (as->parms[2].items) {
4774 MapPartIdIntoName(apart, pname);
4775 fprintf(STDOUT, " partition %s", pname);
4778 if (seenprefix || (!seenprefix && seenxprefix)) {
4779 ti = (seenprefix ? as->parms[0].items : as->parms[4].items);
4780 ex = (seenprefix ? exclude : !exclude);
4781 exp = (strncmp(ti->data, "^", 1) == 0);
4782 fprintf(STDOUT, " which %smatch %s '%s'", (ex ? "do not " : ""),
4783 (exp ? "expression" : "prefix"), ti->data);
4784 for (ti = ti->next; ti; ti = ti->next) {
4785 exp = (strncmp(ti->data, "^", 1) == 0);
4786 printf(" %sor %s '%s'", (ex ? "n" : ""),
4787 (exp ? "expression" : "prefix"), ti->data);
4791 if (seenprefix && seenxprefix) {
4792 ti = as->parms[4].items;
4793 exp = (strncmp(ti->data, "^", 1) == 0);
4794 fprintf(STDOUT, " %swhich match %s '%s'",
4795 (exclude ? "adding those " : "removing those "),
4796 (exp ? "expression" : "prefix"), ti->data);
4797 for (ti = ti->next; ti; ti = ti->next) {
4798 exp = (strncmp(ti->data, "^", 1) == 0);
4799 printf(" or %s '%s'", (exp ? "expression" : "prefix"),
4803 fprintf(STDOUT, " .. ");
4805 fprintf(STDOUT, "\n");
4809 for (j = 0; j < nentries; j++) { /* process each vldb entry */
4810 vllist = &arrayEntries.nbulkentries_val[j];
4813 for (ti = as->parms[0].items; ti; ti = ti->next) {
4814 if (strncmp(ti->data, "^", 1) == 0) {
4815 #ifdef HAVE_POSIX_REGEX
4819 /* XXX -- should just do the compile once! */
4820 code = regcomp(&re, ti->data, REG_NOSUB);
4822 regerror(code, &re, errbuf, sizeof errbuf);
4824 "Error in -prefix regular expression: '%s': %s\n",
4828 match = (regexec(&re, vllist->name, 0, NULL, 0) == 0);
4831 ccode = (char *)re_comp(ti->data);
4834 "Error in -prefix regular expression: '%s': %s\n",
4838 match = (re_exec(vllist->name) == 1);
4842 (strncmp(vllist->name, ti->data, strlen(ti->data)) ==
4852 /* Without the -exclude flag: If it matches the prefix, then
4853 * check if we want to exclude any from xprefix.
4854 * With the -exclude flag: If it matches the prefix, then
4855 * check if we want to add any from xprefix.
4857 if (match && seenxprefix) {
4858 for (ti = as->parms[4].items; ti; ti = ti->next) {
4859 if (strncmp(ti->data, "^", 1) == 0) {
4860 #ifdef HAVE_POSIX_REGEX
4864 /* XXX -- should just do the compile once! */
4865 code = regcomp(&re, ti->data, REG_NOSUB);
4867 regerror(code, &re, errbuf, sizeof errbuf);
4869 "Error in -xprefix regular expression: '%s': %s\n",
4873 if (regexec(&re, vllist->name, 0, NULL, 0) == 0)
4877 ccode = (char *)re_comp(ti->data);
4880 "Error in -xprefix regular expression: '%s': %s\n",
4884 if (re_exec(vllist->name) == 1) {
4890 if (strncmp(vllist->name, ti->data, strlen(ti->data)) ==
4900 match = !match; /* -exclude will reverse the match */
4902 continue; /* Skip if no match */
4904 /* Print list of volumes to backup */
4906 fprintf(STDOUT, " %s\n", vllist->name);
4910 if (!(vllist->flags & RW_EXISTS)) {
4913 "Omitting to backup %s since RW volume does not exist \n",
4915 fprintf(STDOUT, "\n");
4921 avolid = vllist->volumeId[RWVOL];
4922 MapHostToNetwork(vllist);
4923 GetServerAndPart(vllist, RWVOL, &aserver1, &apart1, &previdx);
4924 if (aserver1 == -1 || apart1 == -1) {
4925 fprintf(STDOUT, "could not backup %s, invalid VLDB entry\n",
4931 same = VLDB_IsSameAddrs(aserver, aserver1, &error);
4934 "Failed to get info about server's %d address(es) from vlserver (err=%d); aborting call!\n",
4940 if ((aserver && !same) || (apart && (apart != apart1))) {
4943 "Omitting to backup %s since the RW is in a different location\n",
4949 time_t now = time(0);
4950 fprintf(STDOUT, "Creating backup volume for %s on %s",
4951 vllist->name, ctime(&now));
4955 code = UV_BackupVolume(aserver1, apart1, avolid);
4957 fprintf(STDOUT, "Could not backup %s\n", vllist->name);
4963 fprintf(STDOUT, "\n");
4965 } /* process each vldb entry */
4966 fprintf(STDOUT, "done\n");
4967 fprintf(STDOUT, "Total volumes backed up: %lu; failed to backup: %lu\n",
4968 (unsigned long)totalBack, (unsigned long)totalFail);
4970 xdr_free((xdrproc_t) xdr_nbulkentries, &arrayEntries);
4975 UnlockVLDB(struct cmd_syndesc *as, void *arock)
4978 afs_uint32 aserver = 0;
4981 struct VldbListByAttributes attributes;
4982 nbulkentries arrayEntries;
4983 struct nvldbentry *vllist;
4992 attributes.Mask = 0;
4994 if (as->parms[0].items) { /* server specified */
4995 aserver = GetServer(as->parms[0].items->data);
4997 fprintf(STDERR, "vos: server '%s' not found in host table\n",
4998 as->parms[0].items->data);
5001 attributes.server = ntohl(aserver);
5002 attributes.Mask |= VLLIST_SERVER;
5004 if (as->parms[1].items) { /* partition specified */
5005 apart = volutil_GetPartitionID(as->parms[1].items->data);
5007 fprintf(STDERR, "vos: could not interpret partition name '%s'\n",
5008 as->parms[1].items->data);
5011 if (!IsPartValid(apart, aserver, &code)) { /*check for validity of the partition */
5013 PrintError("", code);
5016 "vos : partition %s does not exist on the server\n",
5017 as->parms[1].items->data);
5020 attributes.partition = apart;
5021 attributes.Mask |= VLLIST_PARTITION;
5023 attributes.flag = VLOP_ALLOPERS;
5024 attributes.Mask |= VLLIST_FLAG;
5025 memset(&arrayEntries, 0, sizeof(arrayEntries)); /*initialize to hint the stub to alloc space */
5026 vcode = VLDB_ListAttributes(&attributes, &nentries, &arrayEntries);
5028 fprintf(STDERR, "Could not access the VLDB for attributes\n");
5029 PrintError("", vcode);
5032 for (j = 0; j < nentries; j++) { /* process each entry */
5033 vllist = &arrayEntries.nbulkentries_val[j];
5034 volid = vllist->volumeId[RWVOL];
5036 ubik_VL_ReleaseLock(cstruct, 0, volid, -1,
5037 LOCKREL_OPCODE | LOCKREL_AFSID |
5040 fprintf(STDERR, "Could not unlock entry for volume %s\n",
5042 PrintError("", vcode);
5047 MapPartIdIntoName(apart, pname);
5050 "Could not lock %lu VLDB entries of %lu locked entries\n",
5051 (unsigned long)totalE, (unsigned long)nentries);
5053 if (as->parms[0].items) {
5055 "Unlocked all the VLDB entries for volumes on server %s ",
5056 as->parms[0].items->data);
5057 if (as->parms[1].items) {
5058 MapPartIdIntoName(apart, pname);
5059 fprintf(STDOUT, "partition %s\n", pname);
5061 fprintf(STDOUT, "\n");
5063 } else if (as->parms[1].items) {
5064 MapPartIdIntoName(apart, pname);
5066 "Unlocked all the VLDB entries for volumes on partition %s on all servers\n",
5071 xdr_free((xdrproc_t) xdr_nbulkentries, &arrayEntries);
5076 PrintInt64Size(afs_uint64 in)
5080 static char output[16];
5082 SplitInt64(in,hi,lo);
5086 } else if (!(hi & 0xFFFFFC00)) {
5088 lo = (hi << 22) | (lo >> 10);
5089 } else if (!(hi & 0xFFF00000)) {
5091 lo = (hi << 12) | (lo >> 20);
5092 } else if (!(hi & 0xC0000000)) {
5094 lo = (hi << 2) | (lo >> 30);
5099 sprintf(output,"%u %s", lo, units);
5104 PartitionInfo(struct cmd_syndesc *as, void *arock)
5110 struct diskPartition64 partition;
5111 struct partList dummyPartList;
5113 int printSummary=0, sumPartitions=0;
5114 afs_uint64 sumFree, sumStorage;
5117 ZeroInt64(sumStorage);
5119 aserver = GetServer(as->parms[0].items->data);
5121 fprintf(STDERR, "vos: server '%s' not found in host table\n",
5122 as->parms[0].items->data);
5125 if (as->parms[1].items) {
5126 apart = volutil_GetPartitionID(as->parms[1].items->data);
5128 fprintf(STDERR, "vos: could not interpret partition name '%s'\n",
5129 as->parms[1].items->data);
5132 dummyPartList.partId[0] = apart;
5133 dummyPartList.partFlags[0] = PARTVALID;
5136 if (as->parms[2].items) {
5140 if (!IsPartValid(apart, aserver, &code)) { /*check for validity of the partition */
5142 PrintError("", code);
5145 "vos : partition %s does not exist on the server\n",
5146 as->parms[1].items->data);
5150 code = UV_ListPartitions(aserver, &dummyPartList, &cnt);
5152 PrintDiagnostics("listpart", code);
5156 for (i = 0; i < cnt; i++) {
5157 if (dummyPartList.partFlags[i] & PARTVALID) {
5158 MapPartIdIntoName(dummyPartList.partId[i], pname);
5159 code = UV_PartitionInfo64(aserver, pname, &partition);
5161 fprintf(STDERR, "Could not get information on partition %s\n",
5163 PrintError("", code);
5167 "Free space on partition %s: %" AFS_INT64_FMT " K blocks out of total %" AFS_INT64_FMT "\n",
5168 pname, partition.free, partition.minFree);
5170 AddUInt64(sumFree,partition.free,&sumFree);
5171 AddUInt64(sumStorage,partition.minFree,&sumStorage);
5176 "Summary: %s free out of ",
5177 PrintInt64Size(sumFree));
5179 "%s on %d partitions\n",
5180 PrintInt64Size(sumStorage),
5187 ChangeAddr(struct cmd_syndesc *as, void *arock)
5189 afs_int32 ip1, ip2, vcode;
5193 ip1 = GetServerNoresolve(as->parms[0].items->data);
5195 ip1 = GetServer(as->parms[0].items->data);
5197 fprintf(STDERR, "vos: invalid host address\n");
5201 if ((as->parms[1].items && as->parms[2].items)
5202 || (!as->parms[1].items && !as->parms[2].items)) {
5204 "vos: Must specify either '-newaddr <addr>' or '-remove' flag\n");
5208 if (as->parms[1].items) {
5210 ip2 = GetServerNoresolve(as->parms[1].items->data);
5212 ip2 = GetServer(as->parms[1].items->data);
5214 fprintf(STDERR, "vos: invalid host address\n");
5218 /* Play a trick here. If we are removing an address, ip1 will be -1
5219 * and ip2 will be the original address. This switch prevents an
5220 * older revision vlserver from removing the IP address.
5227 vcode = ubik_VL_ChangeAddr(cstruct, UBIK_CALL_NEW, ntohl(ip1), ntohl(ip2));
5229 char hoststr1[16], hoststr2[16];
5231 afs_inet_ntoa_r(ip2, hoststr2);
5232 fprintf(STDERR, "Could not remove server %s from the VLDB\n",
5234 if (vcode == VL_NOENT) {
5236 "vlserver does not support the remove flag or ");
5239 afs_inet_ntoa_r(ip1, hoststr1);
5240 afs_inet_ntoa_r(ip2, hoststr2);
5241 fprintf(STDERR, "Could not change server %s to server %s\n",
5242 hoststr1, hoststr2);
5244 PrintError("", vcode);
5249 fprintf(STDOUT, "Removed server %s from the VLDB\n",
5250 as->parms[0].items->data);
5252 fprintf(STDOUT, "Changed server %s to server %s\n",
5253 as->parms[0].items->data, as->parms[1].items->data);
5259 print_addrs(const bulkaddrs * addrs, afsUUID * m_uuid, int nentries,
5267 afsUUID_to_string(m_uuid, buf, sizeof(buf));
5268 printf("UUID: %s\n", buf);
5271 /* print out the list of all the server */
5272 addrp = (afs_uint32 *) addrs->bulkaddrs_val;
5273 for (i = 0; i < nentries; i++, addrp++) {
5274 *addrp = htonl(*addrp);
5277 printf("%s\n", afs_inet_ntoa_r(*addrp, hoststr));
5279 printf("%s\n", hostutil_GetNameByINet(*addrp));
5290 ListAddrs(struct cmd_syndesc *as, void *arock)
5292 afs_int32 vcode, m_uniq=0;
5293 afs_int32 i, printuuid = 0;
5294 struct VLCallBack vlcb;
5297 ListAddrByAttributes m_attrs;
5298 afsUUID m_uuid, askuuid;
5299 afs_int32 m_nentries;
5301 memset(&m_attrs, 0, sizeof(struct ListAddrByAttributes));
5302 m_attrs.Mask = VLADDR_INDEX;
5304 memset(&askuuid, 0, sizeof(afsUUID));
5305 if (as->parms[0].items) {
5307 if (afsUUID_from_string(as->parms[0].items->data, &askuuid) < 0) {
5308 fprintf(STDERR, "vos: invalid UUID '%s'\n",
5309 as->parms[0].items->data);
5312 m_attrs.Mask = VLADDR_UUID;
5313 m_attrs.uuid = askuuid;
5315 if (as->parms[1].items) {
5319 he = hostutil_GetHostByName((char *)as->parms[1].items->data);
5321 fprintf(STDERR, "vos: Can't get host info for '%s'\n",
5322 as->parms[1].items->data);
5325 memcpy(&saddr, he->h_addr, 4);
5326 m_attrs.Mask = VLADDR_IPADDR;
5327 m_attrs.ipaddr = ntohl(saddr);
5329 if (as->parms[2].items) {
5333 memset(&m_addrs, 0, sizeof(bulkaddrs));
5334 memset(&vlcb, 0, sizeof(struct VLCallBack));
5337 ubik_VL_GetAddrs(cstruct, UBIK_CALL_NEW, 0, 0, &vlcb, &nentries,
5340 fprintf(STDERR, "vos: could not list the server addresses\n");
5341 PrintError("", vcode);
5350 xdr_free((xdrproc_t)xdr_bulkaddrs, &m_addrs); /* reset addr list */
5352 ubik_VL_GetAddrsU(cstruct, UBIK_CALL_NEW, &m_attrs, &m_uuid,
5353 &m_uniq, &m_nentries, &m_addrs);
5355 if (vcode == VL_NOENT) {
5356 if (m_attrs.Mask == VLADDR_UUID) {
5357 fprintf(STDERR, "vos: no entry for UUID '%s' found in VLDB\n",
5358 as->parms[0].items->data);
5360 } else if (m_attrs.Mask == VLADDR_IPADDR) {
5361 fprintf(STDERR, "vos: no entry for host '%s' [0x%08x] found in VLDB\n",
5362 as->parms[1].items->data, m_attrs.ipaddr);
5371 if (vcode == VL_INDEXERANGE) {
5372 vcode = 0; /* not an error, just means we're done */
5377 fprintf(STDERR, "vos: could not list the server addresses\n");
5378 PrintError("", vcode);
5382 print_addrs(&m_addrs, &m_uuid, m_nentries, printuuid);
5385 if ((as->parms[1].items) || (as->parms[0].items) || (i > nentries))
5390 xdr_free((xdrproc_t)xdr_bulkaddrs, &m_addrs);
5396 SetAddrs(struct cmd_syndesc *as, void *arock)
5401 afs_uint32 FS_HostAddrs_HBO[ADDRSPERSITE];
5403 memset(&m_addrs, 0, sizeof(bulkaddrs));
5404 memset(&askuuid, 0, sizeof(afsUUID));
5405 if (as->parms[0].items) {
5407 if (afsUUID_from_string(as->parms[0].items->data, &askuuid) < 0) {
5408 fprintf(STDERR, "vos: invalid UUID '%s'\n",
5409 as->parms[0].items->data);
5413 if (as->parms[1].items) {
5415 struct cmd_item *ti;
5419 for (ti = as->parms[1].items; ti && i < ADDRSPERSITE; ti = ti->next) {
5422 saddr = GetServerNoresolve(ti->data);
5424 saddr = GetServer(ti->data);
5427 fprintf(STDERR, "vos: Can't get host info for '%s'\n",
5431 /* Convert it to host byte order */
5432 FS_HostAddrs_HBO[i] = ntohl(saddr);
5435 m_addrs.bulkaddrs_len = i;
5436 m_addrs.bulkaddrs_val = FS_HostAddrs_HBO;
5439 vcode = ubik_VL_RegisterAddrs(cstruct, 0, &askuuid, 0, &m_addrs);
5442 if (vcode == VL_MULTIPADDR) {
5443 fprintf(STDERR, "vos: VL_RegisterAddrs rpc failed; The IP address exists on a different server; repair it\n");
5444 PrintError("", vcode);
5446 } else if (vcode == RXGEN_OPCODE) {
5447 fprintf(STDERR, "vlserver doesn't support VL_RegisterAddrs rpc; ignored\n");
5448 PrintError("", vcode);
5453 fprintf(STDOUT, "vos: Changed UUID with addresses:\n");
5454 print_addrs(&m_addrs, &askuuid, m_addrs.bulkaddrs_len, 1);
5460 LockEntry(struct cmd_syndesc *as, void *arock)
5463 afs_int32 vcode, err;
5465 avolid = vsu_GetVolumeID(as->parms[0].items->data, cstruct, &err);
5468 PrintError("", err);
5470 fprintf(STDERR, "vos: can't find volume '%s'\n",
5471 as->parms[0].items->data);
5474 vcode = ubik_VL_SetLock(cstruct, 0, avolid, -1, VLOP_DELETE);
5476 fprintf(STDERR, "Could not lock VLDB entry for volume %s\n",
5477 as->parms[0].items->data);
5478 PrintError("", vcode);
5481 fprintf(STDOUT, "Locked VLDB entry for volume %s\n",
5482 as->parms[0].items->data);
5487 ConvertRO(struct cmd_syndesc *as, void *arock)
5489 afs_int32 partition = -1;
5492 afs_int32 code, i, same;
5493 struct nvldbentry entry, storeEntry;
5495 afs_int32 rwindex = 0;
5496 afs_uint32 rwserver = 0;
5497 afs_int32 rwpartition = 0;
5498 afs_int32 roindex = 0;
5499 afs_uint32 roserver = 0;
5500 afs_int32 ropartition = 0;
5502 struct rx_connection *aconn;
5505 server = GetServer(as->parms[0].items->data);
5507 fprintf(STDERR, "vos: host '%s' not found in host table\n",
5508 as->parms[0].items->data);
5511 partition = volutil_GetPartitionID(as->parms[1].items->data);
5512 if (partition < 0) {
5513 fprintf(STDERR, "vos: could not interpret partition name '%s'\n",
5514 as->parms[1].items->data);
5517 if (!IsPartValid(partition, server, &code)) {
5519 PrintError("", code);
5522 "vos : partition %s does not exist on the server\n",
5523 as->parms[1].items->data);
5526 volid = vsu_GetVolumeID(as->parms[2].items->data, cstruct, &code);
5529 PrintError("", code);
5531 fprintf(STDERR, "Unknown volume ID or name '%s'\n",
5532 as->parms[0].items->data);
5535 if (as->parms[3].items)
5538 vcode = VLDB_GetEntryByID(volid, -1, &entry);
5541 "Could not fetch the entry for volume %lu from VLDB\n",
5542 (unsigned long)volid);
5543 PrintError("convertROtoRW", code);
5547 /* use RO volid even if user specified RW or BK volid */
5549 if (volid != entry.volumeId[ROVOL])
5550 volid = entry.volumeId[ROVOL];
5552 MapHostToNetwork(&entry);
5553 for (i = 0; i < entry.nServers; i++) {
5554 if (entry.serverFlags[i] & ITSRWVOL) {
5556 rwserver = entry.serverNumber[i];
5557 rwpartition = entry.serverPartition[i];
5559 if (entry.serverFlags[i] & ITSROVOL) {
5560 same = VLDB_IsSameAddrs(server, entry.serverNumber[i], &code);
5563 "Failed to get info about server's %d address(es) from vlserver (err=%d); aborting call!\n",
5569 roserver = entry.serverNumber[i];
5570 ropartition = entry.serverPartition[i];
5576 fprintf(STDERR, "Warning: RO volume didn't exist in vldb!\n");
5578 if (ropartition != partition) {
5580 "Warning: RO volume should be in partition %d instead of %d (vldb)\n",
5581 ropartition, partition);
5586 "VLDB indicates that a RW volume exists already on %s in partition %s.\n",
5587 hostutil_GetNameByINet(rwserver),
5588 volutil_PartitionName(rwpartition));
5590 fprintf(STDERR, "Overwrite this VLDB entry? [y|n] (n)\n");
5592 while (!(dc == EOF || dc == '\n'))
5593 dc = getchar(); /* goto end of line */
5594 if ((c != 'y') && (c != 'Y')) {
5595 fprintf(STDERR, "aborted.\n");
5602 ubik_VL_SetLock(cstruct, 0, entry.volumeId[RWVOL], RWVOL,
5604 aconn = UV_Bind(server, AFSCONF_VOLUMEPORT);
5605 code = AFSVolConvertROtoRWvolume(aconn, partition, volid);
5608 "Converting RO volume %lu to RW volume failed with code %d\n",
5609 (unsigned long)volid, code);
5610 PrintError("convertROtoRW ", code);
5613 entry.serverFlags[roindex] = ITSRWVOL;
5614 entry.flags |= RW_EXISTS;
5615 entry.flags &= ~BACK_EXISTS;
5618 if (rwindex != entry.nServers) {
5619 entry.serverNumber[rwindex] = entry.serverNumber[entry.nServers];
5620 entry.serverPartition[rwindex] =
5621 entry.serverPartition[entry.nServers];
5622 entry.serverFlags[rwindex] = entry.serverFlags[entry.nServers];
5623 entry.serverNumber[entry.nServers] = 0;
5624 entry.serverPartition[entry.nServers] = 0;
5625 entry.serverFlags[entry.nServers] = 0;
5628 entry.flags &= ~RO_EXISTS;
5629 for (i = 0; i < entry.nServers; i++) {
5630 if (entry.serverFlags[i] & ITSROVOL) {
5631 if (!(entry.serverFlags[i] & (RO_DONTUSE | NEW_REPSITE)))
5632 entry.flags |= RO_EXISTS;
5635 MapNetworkToHost(&entry, &storeEntry);
5637 VLDB_ReplaceEntry(entry.volumeId[RWVOL], RWVOL, &storeEntry,
5638 (LOCKREL_OPCODE | LOCKREL_AFSID |
5639 LOCKREL_TIMESTAMP));
5642 "Warning: volume converted, but vldb update failed with code %d!\n",
5645 vcode = UV_LockRelease(entry.volumeId[RWVOL]);
5647 PrintDiagnostics("unlock", vcode);
5653 Sizes(struct cmd_syndesc *as, void *arock)
5657 afs_int32 apart, voltype, fromdate = 0, code, err, i;
5658 struct nvldbentry entry;
5659 volintSize vol_size;
5661 rx_SetRxDeadTime(60 * 10);
5662 for (i = 0; i < MAXSERVERS; i++) {
5663 struct rx_connection *rxConn = ubik_GetRPCConn(cstruct, i);
5666 rx_SetConnDeadTime(rxConn, rx_connDeadTime);
5667 if (rxConn->service)
5668 rxConn->service->connDeadTime = rx_connDeadTime;
5671 avolid = vsu_GetVolumeID(as->parms[0].items->data, cstruct, &err);
5674 PrintError("", err);
5676 fprintf(STDERR, "vos: can't find volume '%s'\n",
5677 as->parms[0].items->data);
5681 if (as->parms[1].items || as->parms[2].items) {
5682 if (!as->parms[1].items || !as->parms[2].items) {
5684 "Must specify both -server and -partition options\n");
5687 aserver = GetServer(as->parms[2].items->data);
5689 fprintf(STDERR, "Invalid server name\n");
5692 apart = volutil_GetPartitionID(as->parms[1].items->data);
5694 fprintf(STDERR, "Invalid partition name\n");
5698 code = GetVolumeInfo(avolid, &aserver, &apart, &voltype, &entry);
5705 if (as->parms[4].items && strcmp(as->parms[4].items->data, "0")) {
5706 code = ktime_DateToInt32(as->parms[4].items->data, &fromdate);
5708 fprintf(STDERR, "vos: failed to parse date '%s' (error=%d))\n",
5709 as->parms[4].items->data, code);
5714 fprintf(STDOUT, "Volume: %s\n", as->parms[0].items->data);
5716 if (as->parms[3].items) { /* do the dump estimate */
5717 vol_size.dump_size = 0;
5718 code = UV_GetSize(avolid, aserver, apart, fromdate, &vol_size);
5720 PrintDiagnostics("size", code);
5723 /* presumably the size info is now gathered in pntr */
5724 /* now we display it */
5726 fprintf(STDOUT, "dump_size: %llu\n", vol_size.dump_size);
5735 EndTrans(struct cmd_syndesc *as, void *arock)
5738 afs_int32 code, tid, rcode;
5739 struct rx_connection *aconn;
5741 server = GetServer(as->parms[0].items->data);
5743 fprintf(STDERR, "vos: host '%s' not found in host table\n",
5744 as->parms[0].items->data);
5748 code = util_GetInt32(as->parms[1].items->data, &tid);
5750 fprintf(STDERR, "vos: bad integer specified for transaction ID.\n");
5754 aconn = UV_Bind(server, AFSCONF_VOLUMEPORT);
5755 code = AFSVolEndTrans(aconn, tid, &rcode);
5761 PrintDiagnostics("endtrans", code);
5769 PrintDiagnostics(char *astring, afs_int32 acode)
5771 if (acode == EACCES) {
5773 "You are not authorized to perform the 'vos %s' command (%d)\n",
5776 fprintf(STDERR, "Error in vos %s command.\n", astring);
5777 PrintError("", acode);
5785 win32_enableCrypt(void)
5792 /* Look up configuration parameters in Registry */
5793 code = RegOpenKeyEx(HKEY_LOCAL_MACHINE, AFSREG_CLT_SVC_PARAM_SUBKEY,
5794 0, (IsWow64()?KEY_WOW64_64KEY:0)|KEY_QUERY_VALUE, &parmKey);
5795 if (code != ERROR_SUCCESS) {
5796 dummyLen = sizeof(cryptall);
5797 RegQueryValueEx(parmKey, "SecurityLevel", NULL, NULL,
5798 (BYTE *) &cryptall, &dummyLen);
5800 RegCloseKey (parmKey);
5804 #endif /* AFS_NT40_ENV */
5807 MyBeforeProc(struct cmd_syndesc *as, void *arock)
5813 /* Initialize the ubik_client connection */
5814 rx_SetRxDeadTime(90);
5815 cstruct = (struct ubik_client *)0;
5819 if (as->parms[12].items) /* if -cell specified */
5820 tcell = as->parms[12].items->data;
5821 if (as->parms[14].items) /* -serverauth specified */
5823 if (as->parms[16].items /* -encrypt specified */
5825 || win32_enableCrypt()
5826 #endif /* AFS_NT40_ENV */
5830 vsu_ClientInit((as->parms[13].items != 0), confdir, tcell, sauth,
5831 &cstruct, UV_SetSecurity))) {
5832 fprintf(STDERR, "could not initialize VLDB library (code=%lu) \n",
5833 (unsigned long)code);
5837 if (as->parms[15].items) /* -verbose flag set */
5841 if (as->parms[17].items) /* -noresolve flag set */
5851 /* this sucks but it works for now.
5856 #include "AFS_component_version_number.c"
5859 main(int argc, char **argv)
5863 struct cmd_syndesc *ts;
5865 #ifdef AFS_AIX32_ENV
5867 * The following signal action for AIX is necessary so that in case of a
5868 * crash (i.e. core is generated) we can include the user's data section
5869 * in the core dump. Unfortunately, by default, only a partial core is
5870 * generated which, in many cases, isn't too useful.
5872 struct sigaction nsa;
5874 sigemptyset(&nsa.sa_mask);
5875 nsa.sa_handler = SIG_DFL;
5876 nsa.sa_flags = SA_FULLDUMP;
5877 sigaction(SIGSEGV, &nsa, NULL);
5880 confdir = AFSDIR_CLIENT_ETC_DIRPATH;
5882 cmd_SetBeforeProc(MyBeforeProc, NULL);
5884 ts = cmd_CreateSyntax("create", CreateVolume, NULL, "create a new volume");
5885 cmd_AddParm(ts, "-server", CMD_SINGLE, 0, "machine name");
5886 cmd_AddParm(ts, "-partition", CMD_SINGLE, 0, "partition name");
5887 cmd_AddParm(ts, "-name", CMD_SINGLE, 0, "volume name");
5888 cmd_AddParm(ts, "-maxquota", CMD_SINGLE, CMD_OPTIONAL,
5889 "initial quota (KB)");
5890 cmd_AddParm(ts, "-id", CMD_SINGLE, CMD_OPTIONAL, "volume ID");
5891 cmd_AddParm(ts, "-roid", CMD_SINGLE, CMD_OPTIONAL, "readonly volume ID");
5893 cmd_AddParm(ts, "-minquota", CMD_SINGLE, CMD_OPTIONAL, "");
5897 ts = cmd_CreateSyntax("remove", DeleteVolume, NULL, "delete a volume");
5898 cmd_AddParm(ts, "-server", CMD_SINGLE, CMD_OPTIONAL, "machine name");
5899 cmd_AddParm(ts, "-partition", CMD_SINGLE, CMD_OPTIONAL, "partition name");
5900 cmd_AddParm(ts, "-id", CMD_SINGLE, 0, "volume name or ID");
5904 ts = cmd_CreateSyntax("move", MoveVolume, NULL, "move a volume");
5905 cmd_AddParm(ts, "-id", CMD_SINGLE, 0, "volume name or ID");
5906 cmd_AddParm(ts, "-fromserver", CMD_SINGLE, 0, "machine name on source");
5907 cmd_AddParm(ts, "-frompartition", CMD_SINGLE, 0,
5908 "partition name on source");
5909 cmd_AddParm(ts, "-toserver", CMD_SINGLE, 0,
5910 "machine name on destination");
5911 cmd_AddParm(ts, "-topartition", CMD_SINGLE, 0,
5912 "partition name on destination");
5913 cmd_AddParm(ts, "-live", CMD_FLAG, CMD_OPTIONAL,
5914 "copy live volume without cloning");
5917 ts = cmd_CreateSyntax("copy", CopyVolume, NULL, "copy a volume");
5918 cmd_AddParm(ts, "-id", CMD_SINGLE, 0, "volume name or ID on source");
5919 cmd_AddParm(ts, "-fromserver", CMD_SINGLE, 0, "machine name on source");
5920 cmd_AddParm(ts, "-frompartition", CMD_SINGLE, 0,
5921 "partition name on source");
5922 cmd_AddParm(ts, "-toname", CMD_SINGLE, 0, "volume name on destination");
5923 cmd_AddParm(ts, "-toserver", CMD_SINGLE, 0,
5924 "machine name on destination");
5925 cmd_AddParm(ts, "-topartition", CMD_SINGLE, 0,
5926 "partition name on destination");
5927 cmd_AddParm(ts, "-offline", CMD_FLAG, CMD_OPTIONAL,
5928 "leave new volume offline");
5929 cmd_AddParm(ts, "-readonly", CMD_FLAG, CMD_OPTIONAL,
5930 "make new volume read-only");
5931 cmd_AddParm(ts, "-live", CMD_FLAG, CMD_OPTIONAL,
5932 "copy live volume without cloning");
5935 ts = cmd_CreateSyntax("shadow", ShadowVolume, NULL,
5936 "make or update a shadow volume");
5937 cmd_AddParm(ts, "-id", CMD_SINGLE, 0, "volume name or ID on source");
5938 cmd_AddParm(ts, "-fromserver", CMD_SINGLE, 0, "machine name on source");
5939 cmd_AddParm(ts, "-frompartition", CMD_SINGLE, 0,
5940 "partition name on source");
5941 cmd_AddParm(ts, "-toserver", CMD_SINGLE, 0,
5942 "machine name on destination");
5943 cmd_AddParm(ts, "-topartition", CMD_SINGLE, 0,
5944 "partition name on destination");
5945 cmd_AddParm(ts, "-toname", CMD_SINGLE, CMD_OPTIONAL,
5946 "volume name on destination");
5947 cmd_AddParm(ts, "-toid", CMD_SINGLE, CMD_OPTIONAL,
5948 "volume ID on destination");
5949 cmd_AddParm(ts, "-offline", CMD_FLAG, CMD_OPTIONAL,
5950 "leave shadow volume offline");
5951 cmd_AddParm(ts, "-readonly", CMD_FLAG, CMD_OPTIONAL,
5952 "make shadow volume read-only");
5953 cmd_AddParm(ts, "-live", CMD_FLAG, CMD_OPTIONAL,
5954 "copy live volume without cloning");
5955 cmd_AddParm(ts, "-incremental", CMD_FLAG, CMD_OPTIONAL,
5956 "do incremental update if target exists");
5959 ts = cmd_CreateSyntax("backup", BackupVolume, NULL,
5960 "make backup of a volume");
5961 cmd_AddParm(ts, "-id", CMD_SINGLE, 0, "volume name or ID");
5964 ts = cmd_CreateSyntax("clone", CloneVolume, NULL,
5965 "make clone of a volume");
5966 cmd_AddParm(ts, "-id", CMD_SINGLE, 0, "volume name or ID");
5967 cmd_AddParm(ts, "-server", CMD_SINGLE, CMD_OPTIONAL, "server");
5968 cmd_AddParm(ts, "-partition", CMD_SINGLE, CMD_OPTIONAL, "partition");
5969 cmd_AddParm(ts, "-toname", CMD_SINGLE, CMD_OPTIONAL,
5970 "volume name on destination");
5971 cmd_AddParm(ts, "-toid", CMD_SINGLE, CMD_OPTIONAL,
5972 "volume ID on destination");
5973 cmd_AddParm(ts, "-offline", CMD_FLAG, CMD_OPTIONAL,
5974 "leave clone volume offline");
5975 cmd_AddParm(ts, "-readonly", CMD_FLAG, CMD_OPTIONAL,
5976 "make clone volume read-only, not readwrite");
5979 ts = cmd_CreateSyntax("release", ReleaseVolume, NULL, "release a volume");
5980 cmd_AddParm(ts, "-id", CMD_SINGLE, 0, "volume name or ID");
5981 cmd_AddParm(ts, "-force", CMD_FLAG, CMD_OPTIONAL,
5982 "force a complete release");
5985 ts = cmd_CreateSyntax("dump", DumpVolumeCmd, NULL, "dump a volume");
5986 cmd_AddParm(ts, "-id", CMD_SINGLE, 0, "volume name or ID");
5987 cmd_AddParm(ts, "-time", CMD_SINGLE, CMD_OPTIONAL, "dump from time");
5988 cmd_AddParm(ts, "-file", CMD_SINGLE, CMD_OPTIONAL, "dump file");
5989 cmd_AddParm(ts, "-server", CMD_SINGLE, CMD_OPTIONAL, "server");
5990 cmd_AddParm(ts, "-partition", CMD_SINGLE, CMD_OPTIONAL, "partition");
5991 cmd_AddParm(ts, "-clone", CMD_FLAG, CMD_OPTIONAL,
5992 "dump a clone of the volume");
5993 cmd_AddParm(ts, "-omitdirs", CMD_FLAG, CMD_OPTIONAL,
5994 "omit unchanged directories from an incremental dump");
5997 ts = cmd_CreateSyntax("restore", RestoreVolumeCmd, NULL,
5998 "restore a volume");
5999 cmd_AddParm(ts, "-server", CMD_SINGLE, 0, "machine name");
6000 cmd_AddParm(ts, "-partition", CMD_SINGLE, 0, "partition name");
6001 cmd_AddParm(ts, "-name", CMD_SINGLE, 0, "name of volume to be restored");
6002 cmd_AddParm(ts, "-file", CMD_SINGLE, CMD_OPTIONAL, "dump file");
6003 cmd_AddParm(ts, "-id", CMD_SINGLE, CMD_OPTIONAL, "volume ID");
6004 cmd_AddParm(ts, "-overwrite", CMD_SINGLE, CMD_OPTIONAL,
6005 "abort | full | incremental");
6006 cmd_AddParm(ts, "-offline", CMD_FLAG, CMD_OPTIONAL,
6007 "leave restored volume offline");
6008 cmd_AddParm(ts, "-readonly", CMD_FLAG, CMD_OPTIONAL,
6009 "make restored volume read-only");
6010 cmd_AddParm(ts, "-creation", CMD_SINGLE, CMD_OPTIONAL,
6011 "dump | keep | new");
6012 cmd_AddParm(ts, "-lastupdate", CMD_SINGLE, CMD_OPTIONAL,
6013 "dump | keep | new");
6014 cmd_AddParm(ts, "-nodelete", CMD_FLAG, CMD_OPTIONAL,
6015 "do not delete old site when restoring to a new site");
6018 ts = cmd_CreateSyntax("unlock", LockReleaseCmd, NULL,
6019 "release lock on VLDB entry for a volume");
6020 cmd_AddParm(ts, "-id", CMD_SINGLE, 0, "volume name or ID");
6023 ts = cmd_CreateSyntax("changeloc", ChangeLocation, NULL,
6024 "change an RW volume's location in the VLDB");
6025 cmd_AddParm(ts, "-server", CMD_SINGLE, 0,
6026 "machine name for new location");
6027 cmd_AddParm(ts, "-partition", CMD_SINGLE, 0,
6028 "partition name for new location");
6029 cmd_AddParm(ts, "-id", CMD_SINGLE, 0, "volume name or ID");
6032 ts = cmd_CreateSyntax("addsite", AddSite, NULL, "add a replication site");
6033 cmd_AddParm(ts, "-server", CMD_SINGLE, 0, "machine name for new site");
6034 cmd_AddParm(ts, "-partition", CMD_SINGLE, 0,
6035 "partition name for new site");
6036 cmd_AddParm(ts, "-id", CMD_SINGLE, 0, "volume name or ID");
6037 cmd_AddParm(ts, "-roid", CMD_SINGLE, CMD_OPTIONAL, "volume name or ID for RO");
6038 cmd_AddParm(ts, "-valid", CMD_FLAG, CMD_OPTIONAL, "publish as an up-to-date site in VLDB");
6041 ts = cmd_CreateSyntax("remsite", RemoveSite, NULL,
6042 "remove a replication site");
6043 cmd_AddParm(ts, "-server", CMD_SINGLE, 0, "machine name");
6044 cmd_AddParm(ts, "-partition", CMD_SINGLE, 0, "partition name");
6045 cmd_AddParm(ts, "-id", CMD_SINGLE, 0, "volume name or ID");
6048 ts = cmd_CreateSyntax("listpart", ListPartitions, NULL, "list partitions");
6049 cmd_AddParm(ts, "-server", CMD_SINGLE, 0, "machine name");
6052 ts = cmd_CreateSyntax("listvol", ListVolumes, NULL,
6053 "list volumes on server (bypass VLDB)");
6054 cmd_AddParm(ts, "-server", CMD_SINGLE, 0, "machine name");
6055 cmd_AddParm(ts, "-partition", CMD_SINGLE, CMD_OPTIONAL, "partition name");
6056 cmd_AddParm(ts, "-fast", CMD_FLAG, CMD_OPTIONAL, "minimal listing");
6057 cmd_AddParm(ts, "-long", CMD_FLAG, CMD_OPTIONAL,
6058 "list all normal volume fields");
6059 cmd_AddParm(ts, "-quiet", CMD_FLAG, CMD_OPTIONAL,
6060 "generate minimal information");
6061 cmd_AddParm(ts, "-extended", CMD_FLAG, CMD_OPTIONAL,
6062 "list extended volume fields");
6063 cmd_AddParm(ts, "-format", CMD_FLAG, CMD_OPTIONAL,
6064 "machine readable format");
6067 ts = cmd_CreateSyntax("syncvldb", SyncVldb, NULL,
6068 "synchronize VLDB with server");
6069 cmd_AddParm(ts, "-server", CMD_SINGLE, CMD_OPTIONAL, "machine name");
6070 cmd_AddParm(ts, "-partition", CMD_SINGLE, CMD_OPTIONAL, "partition name");
6071 cmd_AddParm(ts, "-volume", CMD_SINGLE, CMD_OPTIONAL, "volume name or ID");
6072 cmd_AddParm(ts, "-dryrun", CMD_FLAG, CMD_OPTIONAL, "list what would be done, don't do it");
6075 ts = cmd_CreateSyntax("syncserv", SyncServer, NULL,
6076 "synchronize server with VLDB");
6077 cmd_AddParm(ts, "-server", CMD_SINGLE, 0, "machine name");
6078 cmd_AddParm(ts, "-partition", CMD_SINGLE, CMD_OPTIONAL, "partition name");
6079 cmd_AddParm(ts, "-dryrun", CMD_FLAG, CMD_OPTIONAL, "list what would be done, don't do it");
6082 ts = cmd_CreateSyntax("examine", ExamineVolume, NULL,
6083 "everything about the volume");
6084 cmd_AddParm(ts, "-id", CMD_SINGLE, 0, "volume name or ID");
6085 cmd_AddParm(ts, "-extended", CMD_FLAG, CMD_OPTIONAL,
6086 "list extended volume fields");
6087 cmd_AddParm(ts, "-format", CMD_FLAG, CMD_OPTIONAL,
6088 "machine readable format");
6090 cmd_CreateAlias(ts, "volinfo");
6092 ts = cmd_CreateSyntax("setfields", SetFields, NULL,
6093 "change volume info fields");
6094 cmd_AddParm(ts, "-id", CMD_SINGLE, 0, "volume name or ID");
6095 cmd_AddParm(ts, "-maxquota", CMD_SINGLE, CMD_OPTIONAL, "quota (KB)");
6096 cmd_AddParm(ts, "-clearuse", CMD_FLAG, CMD_OPTIONAL, "clear dayUse");
6097 cmd_AddParm(ts, "-clearVolUpCounter", CMD_FLAG, CMD_OPTIONAL, "clear volUpdateCounter");
6100 ts = cmd_CreateSyntax("offline", volOffline, NULL, "force the volume status to offline");
6101 cmd_AddParm(ts, "-server", CMD_SINGLE, 0, "server name");
6102 cmd_AddParm(ts, "-partition", CMD_SINGLE, 0, "partition name");
6103 cmd_AddParm(ts, "-id", CMD_SINGLE, 0, "volume name or ID");
6104 cmd_AddParm(ts, "-sleep", CMD_SINGLE, CMD_OPTIONAL, "seconds to sleep");
6105 cmd_AddParm(ts, "-busy", CMD_FLAG, CMD_OPTIONAL, "busy volume");
6108 ts = cmd_CreateSyntax("online", volOnline, NULL, "force the volume status to online");
6109 cmd_AddParm(ts, "-server", CMD_SINGLE, 0, "server name");
6110 cmd_AddParm(ts, "-partition", CMD_SINGLE, 0, "partition name");
6111 cmd_AddParm(ts, "-id", CMD_SINGLE, 0, "volume name or ID");
6114 ts = cmd_CreateSyntax("zap", VolumeZap, NULL,
6115 "delete the volume, don't bother with VLDB");
6116 cmd_AddParm(ts, "-server", CMD_SINGLE, 0, "machine name");
6117 cmd_AddParm(ts, "-partition", CMD_SINGLE, 0, "partition name");
6118 cmd_AddParm(ts, "-id", CMD_SINGLE, 0, "volume ID");
6119 cmd_AddParm(ts, "-force", CMD_FLAG, CMD_OPTIONAL,
6120 "force deletion of bad volumes");
6121 cmd_AddParm(ts, "-backup", CMD_FLAG, CMD_OPTIONAL,
6122 "also delete backup volume if one is found");
6125 ts = cmd_CreateSyntax("status", VolserStatus, NULL,
6126 "report on volser status");
6127 cmd_AddParm(ts, "-server", CMD_SINGLE, 0, "machine name");
6130 ts = cmd_CreateSyntax("rename", RenameVolume, NULL, "rename a volume");
6131 cmd_AddParm(ts, "-oldname", CMD_SINGLE, 0, "old volume name ");
6132 cmd_AddParm(ts, "-newname", CMD_SINGLE, 0, "new volume name ");
6135 ts = cmd_CreateSyntax("listvldb", ListVLDB, NULL,
6136 "list volumes in the VLDB");
6137 cmd_AddParm(ts, "-name", CMD_SINGLE, CMD_OPTIONAL, "volume name or ID");
6138 cmd_AddParm(ts, "-server", CMD_SINGLE, CMD_OPTIONAL, "machine name");
6139 cmd_AddParm(ts, "-partition", CMD_SINGLE, CMD_OPTIONAL, "partition name");
6140 cmd_AddParm(ts, "-locked", CMD_FLAG, CMD_OPTIONAL, "locked volumes only");
6141 cmd_AddParm(ts, "-quiet", CMD_FLAG, CMD_OPTIONAL,
6142 "generate minimal information");
6143 cmd_AddParm(ts, "-nosort", CMD_FLAG, CMD_OPTIONAL,
6144 "do not alphabetically sort the volume names");
6147 ts = cmd_CreateSyntax("backupsys", BackSys, NULL, "en masse backups");
6148 cmd_AddParm(ts, "-prefix", CMD_LIST, CMD_OPTIONAL,
6149 "common prefix on volume(s)");
6150 cmd_AddParm(ts, "-server", CMD_SINGLE, CMD_OPTIONAL, "machine name");
6151 cmd_AddParm(ts, "-partition", CMD_SINGLE, CMD_OPTIONAL, "partition name");
6152 cmd_AddParm(ts, "-exclude", CMD_FLAG, CMD_OPTIONAL,
6153 "exclude common prefix volumes");
6154 cmd_AddParm(ts, "-xprefix", CMD_LIST, CMD_OPTIONAL,
6155 "negative prefix on volume(s)");
6156 cmd_AddParm(ts, "-dryrun", CMD_FLAG, CMD_OPTIONAL, "list what would be done, don't do it");
6159 ts = cmd_CreateSyntax("delentry", DeleteEntry, NULL,
6160 "delete VLDB entry for a volume");
6161 cmd_AddParm(ts, "-id", CMD_LIST, CMD_OPTIONAL, "volume name or ID");
6162 cmd_AddParm(ts, "-prefix", CMD_SINGLE, CMD_OPTIONAL,
6163 "prefix of the volume whose VLDB entry is to be deleted");
6164 cmd_AddParm(ts, "-server", CMD_SINGLE, CMD_OPTIONAL, "machine name");
6165 cmd_AddParm(ts, "-partition", CMD_SINGLE, CMD_OPTIONAL, "partition name");
6166 cmd_AddParm(ts, "-noexecute", CMD_FLAG, CMD_OPTIONAL|CMD_HIDDEN, "");
6167 cmd_AddParm(ts, "-dryrun", CMD_FLAG, CMD_OPTIONAL,
6168 "list what would be done, don't do it");
6171 ts = cmd_CreateSyntax("partinfo", PartitionInfo, NULL,
6172 "list partition information");
6173 cmd_AddParm(ts, "-server", CMD_SINGLE, 0, "machine name");
6174 cmd_AddParm(ts, "-partition", CMD_SINGLE, CMD_OPTIONAL, "partition name");
6175 cmd_AddParm(ts, "-summary", CMD_FLAG, CMD_OPTIONAL,
6176 "print storage summary");
6179 ts = cmd_CreateSyntax("unlockvldb", UnlockVLDB, NULL,
6180 "unlock all the locked entries in the VLDB");
6181 cmd_AddParm(ts, "-server", CMD_SINGLE, CMD_OPTIONAL, "machine name");
6182 cmd_AddParm(ts, "-partition", CMD_SINGLE, CMD_OPTIONAL, "partition name");
6185 ts = cmd_CreateSyntax("lock", LockEntry, NULL,
6186 "lock VLDB entry for a volume");
6187 cmd_AddParm(ts, "-id", CMD_SINGLE, 0, "volume name or ID");
6190 ts = cmd_CreateSyntax("changeaddr", ChangeAddr, NULL,
6191 "change the IP address of a file server");
6192 cmd_AddParm(ts, "-oldaddr", CMD_SINGLE, 0, "original IP address");
6193 cmd_AddParm(ts, "-newaddr", CMD_SINGLE, CMD_OPTIONAL, "new IP address");
6194 cmd_AddParm(ts, "-remove", CMD_FLAG, CMD_OPTIONAL,
6195 "remove the IP address from the VLDB");
6198 ts = cmd_CreateSyntax("listaddrs", ListAddrs, NULL,
6199 "list the IP address of all file servers registered in the VLDB");
6200 cmd_AddParm(ts, "-uuid", CMD_SINGLE, CMD_OPTIONAL, "uuid of server");
6201 cmd_AddParm(ts, "-host", CMD_SINGLE, CMD_OPTIONAL, "address of host");
6202 cmd_AddParm(ts, "-printuuid", CMD_FLAG, CMD_OPTIONAL,
6203 "print uuid of hosts");
6206 ts = cmd_CreateSyntax("convertROtoRW", ConvertRO, NULL,
6207 "convert a RO volume into a RW volume (after loss of old RW volume)");
6208 cmd_AddParm(ts, "-server", CMD_SINGLE, 0, "machine name");
6209 cmd_AddParm(ts, "-partition", CMD_SINGLE, 0, "partition name");
6210 cmd_AddParm(ts, "-id", CMD_SINGLE, 0, "volume name or ID");
6211 cmd_AddParm(ts, "-force", CMD_FLAG, CMD_OPTIONAL, "don't ask");
6214 ts = cmd_CreateSyntax("size", Sizes, NULL,
6215 "obtain various sizes of the volume.");
6216 cmd_AddParm(ts, "-id", CMD_SINGLE, 0, "volume name or ID");
6217 cmd_AddParm(ts, "-partition", CMD_SINGLE, CMD_OPTIONAL, "partition name");
6218 cmd_AddParm(ts, "-server", CMD_SINGLE, CMD_OPTIONAL, "machine name");
6219 cmd_AddParm(ts, "-dump", CMD_FLAG, CMD_OPTIONAL,
6220 "Obtain the size of the dump");
6221 cmd_AddParm(ts, "-time", CMD_SINGLE, CMD_OPTIONAL, "dump from time");
6224 ts = cmd_CreateSyntax("endtrans", EndTrans, NULL,
6225 "end a volserver transaction");
6226 cmd_AddParm(ts, "-server", CMD_SINGLE, 0, "machine name");
6227 cmd_AddParm(ts, "-transaction", CMD_SINGLE, 0,
6231 ts = cmd_CreateSyntax("setaddrs", SetAddrs, NULL,
6232 "set the list of IP address for a given UUID in the VLDB");
6233 cmd_AddParm(ts, "-uuid", CMD_SINGLE, 0, "uuid of server");
6234 cmd_AddParm(ts, "-host", CMD_LIST, 0, "address of host");
6237 code = cmd_Dispatch(argc, argv);
6239 /* Shut down the ubik_client and rx connections */
6241 (void)ubik_ClientDestroy(cstruct);
6247 exit((code ? -1 : 0));