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>
13 #ifdef IGNORE_SOME_GCC_WARNINGS
14 # pragma GCC diagnostic warning "-Wimplicit-function-declaration"
17 #include <sys/types.h>
26 #include <WINNT/afsreg.h>
31 #include <netinet/in.h>
32 #include <arpa/inet.h>
36 #include <sys/statfs.h>
44 #include <rx/rx_globals.h>
46 #include <afs/vlserver.h>
47 #include <afs/cellconfig.h>
49 #include <afs/afsutil.h>
51 #include <afs/afsint.h>
56 #include <afs/ihandle.h>
57 #include <afs/vnode.h>
58 #include <afs/volume.h>
59 #include <afs/com_err.h>
66 #include "volser_internal.h"
67 #include "volser_prototypes.h"
68 #include "vsutils_prototypes.h"
69 #include "lockprocs_prototypes.h"
71 #ifdef HAVE_POSIX_REGEX
75 /* Local Prototypes */
76 int PrintDiagnostics(char *astring, afs_int32 acode);
77 int GetVolumeInfo(afs_uint32 volid, afs_int32 *server, afs_int32 *part,
78 afs_int32 *voltype, struct nvldbentry *rentry);
90 #define COMMONPARMS cmd_Seek(ts, 12);\
91 cmd_AddParm(ts, "-cell", CMD_SINGLE, CMD_OPTIONAL, "cell name");\
92 cmd_AddParm(ts, "-noauth", CMD_FLAG, CMD_OPTIONAL, "don't authenticate");\
93 cmd_AddParm(ts, "-localauth",CMD_FLAG,CMD_OPTIONAL,"use server tickets");\
94 cmd_AddParm(ts, "-verbose", CMD_FLAG, CMD_OPTIONAL, "verbose");\
95 cmd_AddParm(ts, "-encrypt", CMD_FLAG, CMD_OPTIONAL, "encrypt commands");\
96 cmd_AddParm(ts, "-noresolve", CMD_FLAG, CMD_OPTIONAL, "don't resolve addresses"); \
98 #define ERROR_EXIT(code) {error=(code); goto error_exit;}
101 struct rx_connection *tconn;
103 extern struct ubik_client *cstruct;
106 static struct tqHead busyHead, notokHead;
109 qInit(struct tqHead *ahead)
111 memset(ahead, 0, sizeof(struct tqHead));
117 qPut(struct tqHead *ahead, afs_uint32 volid)
121 elem = (struct tqElem *)malloc(sizeof(struct tqElem));
122 elem->next = ahead->next;
130 qGet(struct tqHead *ahead, afs_uint32 *volid)
134 if (ahead->count <= 0)
136 *volid = ahead->next->volid;
138 ahead->next = tmp->next;
144 /* returns 1 if <filename> exists else 0 */
146 FileExists(char *filename)
152 code = usd_Open(filename, USD_OPEN_RDONLY, 0, &ufd);
156 code = USD_IOCTL(ufd, USD_IOCTL_GETSIZE, &size);
164 /* returns 1 if <name> doesnot end in .readonly or .backup, else 0 */
166 VolNameOK(char *name)
171 total = strlen(name);
172 if (!strcmp(&name[total - 9], ".readonly")) {
174 } else if (!strcmp(&name[total - 7], ".backup")) {
181 /* return 1 if name is a number else 0 */
183 IsNumeric(char *name)
191 for (i = 0; i < len; i++) {
192 if (*ptr < '0' || *ptr > '9') {
204 * Parse a server dotted address and return the address in network byte order
207 GetServerNoresolve(char *aname)
213 code = sscanf(aname, "%d.%d.%d.%d", &b1, &b2, &b3, &b4);
215 addr = (b1 << 24) | (b2 << 16) | (b3 << 8) | b4;
216 addr = htonl(addr); /* convert to network byte order */
222 * Parse a server name/address and return the address in network byte order
225 GetServer(char *aname)
227 register struct hostent *th;
228 afs_int32 addr; /* in network byte order */
229 register afs_int32 code;
230 char hostname[MAXHOSTCHARS];
232 if ((addr = GetServerNoresolve(aname)) == 0) {
233 th = gethostbyname(aname);
236 memcpy(&addr, th->h_addr, sizeof(addr));
239 if (addr == htonl(0x7f000001)) { /* local host */
240 code = gethostname(hostname, MAXHOSTCHARS);
243 th = gethostbyname(hostname);
246 memcpy(&addr, th->h_addr, sizeof(addr));
253 GetVolumeType(char *aname)
256 if (!strcmp(aname, "ro"))
258 else if (!strcmp(aname, "rw"))
260 else if (!strcmp(aname, "bk"))
267 IsPartValid(afs_int32 partId, afs_int32 server, afs_int32 *code)
269 struct partList dummyPartList;
275 *code = UV_ListPartitions(server, &dummyPartList, &cnt);
278 for (i = 0; i < cnt; i++) {
279 if (dummyPartList.partFlags[i] & PARTVALID)
280 if (dummyPartList.partId[i] == partId)
288 /*sends the contents of file associated with <fd> and <blksize> to Rx Stream
289 * associated with <call> */
291 SendFile(usd_handle_t ufd, register struct rx_call *call, long blksize)
293 char *buffer = (char *)0;
298 buffer = (char *)malloc(blksize);
300 fprintf(STDERR, "malloc failed\n");
304 while (!error && !done) {
305 #ifndef AFS_NT40_ENV /* NT csn't select on non-socket fd's */
308 FD_SET((intptr_t)(ufd->handle), &in);
309 /* don't timeout if read blocks */
310 #if defined(AFS_PTHREAD_ENV)
311 select(((intptr_t)(ufd->handle)) + 1, &in, 0, 0, 0);
313 IOMGR_Select(((intptr_t)(ufd->handle)) + 1, &in, 0, 0, 0);
316 error = USD_READ(ufd, buffer, blksize, &nbytes);
318 fprintf(STDERR, "File system read failed: %s\n",
319 afs_error_message(error));
326 if (rx_Write(call, buffer, nbytes) != nbytes) {
336 /* function invoked by UV_RestoreVolume, reads the data from rx_trx_stream and
337 * writes it out to the volume. */
339 WriteData(struct rx_call *call, void *rock)
341 char *filename = (char *) rock;
344 afs_int32 error, code;
346 afs_hyper_t filesize, currOffset;
352 if (!filename || !*filename) {
353 usd_StandardInput(&ufd);
357 code = usd_Open(filename, USD_OPEN_RDONLY, 0, &ufd);
360 code = USD_IOCTL(ufd, USD_IOCTL_GETBLKSIZE, &blksize);
363 fprintf(STDERR, "Could not access file '%s': %s\n", filename,
364 afs_error_message(code));
368 /* test if we have a valid dump */
369 hset64(filesize, 0, 0);
370 USD_SEEK(ufd, filesize, SEEK_END, &currOffset);
371 hset64(filesize, hgethi(currOffset), hgetlo(currOffset)-sizeof(afs_uint32));
372 USD_SEEK(ufd, filesize, SEEK_SET, &currOffset);
373 USD_READ(ufd, (char *)&buffer, sizeof(afs_uint32), &got);
374 if ((got != sizeof(afs_uint32)) || (ntohl(buffer) != DUMPENDMAGIC)) {
375 fprintf(STDERR, "Signature missing from end of file '%s'\n", filename);
379 /* rewind, we are done */
380 hset64(filesize, 0, 0);
381 USD_SEEK(ufd, filesize, SEEK_SET, &currOffset);
383 code = SendFile(ufd, call, blksize);
390 code = USD_CLOSE(ufd);
392 fprintf(STDERR, "Could not close dump file %s\n",
393 (filename && *filename) ? filename : "STDOUT");
401 /* Receive data from <call> stream into file associated
402 * with <fd> <blksize>
405 ReceiveFile(usd_handle_t ufd, struct rx_call *call, long blksize)
409 afs_uint32 bytesleft, w;
412 buffer = (char *)malloc(blksize);
414 fprintf(STDERR, "memory allocation failed\n");
418 while ((bytesread = rx_Read(call, buffer, blksize)) > 0) {
419 for (bytesleft = bytesread; bytesleft; bytesleft -= w) {
420 #ifndef AFS_NT40_ENV /* NT csn't select on non-socket fd's */
423 FD_SET((intptr_t)(ufd->handle), &out);
424 /* don't timeout if write blocks */
425 #if defined(AFS_PTHREAD_ENV)
426 select(((intptr_t)(ufd->handle)) + 1, &out, 0, 0, 0);
428 IOMGR_Select(((intptr_t)(ufd->handle)) + 1, 0, &out, 0, 0);
432 USD_WRITE(ufd, &buffer[bytesread - bytesleft], bytesleft, &w);
434 fprintf(STDERR, "File system write failed: %s\n",
435 afs_error_message(error));
448 DumpFunction(struct rx_call *call, void *rock)
450 char *filename = (char *)rock;
451 usd_handle_t ufd; /* default is to stdout */
452 afs_int32 error = 0, code;
457 /* Open the output file */
458 if (!filename || !*filename) {
459 usd_StandardOutput(&ufd);
464 usd_Open(filename, USD_OPEN_CREATE | USD_OPEN_RDWR, 0666, &ufd);
468 code = USD_IOCTL(ufd, USD_IOCTL_SETSIZE, &size);
471 code = USD_IOCTL(ufd, USD_IOCTL_GETBLKSIZE, &blksize);
474 fprintf(STDERR, "Could not create file '%s': %s\n", filename,
475 afs_error_message(code));
476 ERROR_EXIT(VOLSERBADOP);
480 code = ReceiveFile(ufd, call, blksize);
485 /* Close the output file */
487 code = USD_CLOSE(ufd);
489 fprintf(STDERR, "Could not close dump file %s\n",
490 (filename && *filename) ? filename : "STDIN");
500 DisplayFormat(volintInfo *pntr, afs_int32 server, afs_int32 part,
501 int *totalOK, int *totalNotOK, int *totalBusy, int fast,
502 int longlist, int disp)
508 fprintf(STDOUT, "%-10lu\n", (unsigned long)pntr->volid);
509 } else if (longlist) {
510 if (pntr->status == VOK) {
511 fprintf(STDOUT, "%-32s ", pntr->name);
512 fprintf(STDOUT, "%10lu ", (unsigned long)pntr->volid);
514 fprintf(STDOUT, "RW ");
516 fprintf(STDOUT, "RO ");
518 fprintf(STDOUT, "BK ");
519 fprintf(STDOUT, "%10d K ", pntr->size);
520 if (pntr->inUse == 1) {
521 fprintf(STDOUT, "On-line");
524 fprintf(STDOUT, "Off-line");
527 if (pntr->needsSalvaged == 1)
528 fprintf(STDOUT, "**needs salvage**");
529 fprintf(STDOUT, "\n");
530 MapPartIdIntoName(part, pname);
531 fprintf(STDOUT, " %s %s \n", hostutil_GetNameByINet(server),
533 fprintf(STDOUT, " RWrite %10lu ROnly %10lu Backup %10lu \n",
534 (unsigned long)pntr->parentID,
535 (unsigned long)pntr->cloneID,
536 (unsigned long)pntr->backupID);
537 fprintf(STDOUT, " MaxQuota %10d K \n", pntr->maxquota);
538 t = pntr->creationDate;
539 fprintf(STDOUT, " Creation %s",
542 fprintf(STDOUT, " Copy %s",
545 t = pntr->backupDate;
547 fprintf(STDOUT, " Backup Never\n");
549 fprintf(STDOUT, " Backup %s",
552 t = pntr->accessDate;
554 fprintf(STDOUT, " Last Access %s",
557 t = pntr->updateDate;
559 fprintf(STDOUT, " Last Update Never\n");
561 fprintf(STDOUT, " Last Update %s",
564 " %d accesses in the past day (i.e., vnode references)\n",
566 } else if (pntr->status == VBUSY) {
568 qPut(&busyHead, pntr->volid);
570 fprintf(STDOUT, "**** Volume %lu is busy ****\n",
571 (unsigned long)pntr->volid);
574 qPut(¬okHead, pntr->volid);
576 fprintf(STDOUT, "**** Could not attach volume %lu ****\n",
577 (unsigned long)pntr->volid);
579 fprintf(STDOUT, "\n");
580 } else { /* default listing */
581 if (pntr->status == VOK) {
582 fprintf(STDOUT, "%-32s ", pntr->name);
583 fprintf(STDOUT, "%10lu ", (unsigned long)pntr->volid);
585 fprintf(STDOUT, "RW ");
587 fprintf(STDOUT, "RO ");
589 fprintf(STDOUT, "BK ");
590 fprintf(STDOUT, "%10d K ", pntr->size);
591 if (pntr->inUse == 1) {
592 fprintf(STDOUT, "On-line");
595 fprintf(STDOUT, "Off-line");
598 if (pntr->needsSalvaged == 1)
599 fprintf(STDOUT, "**needs salvage**");
600 fprintf(STDOUT, "\n");
601 } else if (pntr->status == VBUSY) {
603 qPut(&busyHead, pntr->volid);
605 fprintf(STDOUT, "**** Volume %lu is busy ****\n",
606 (unsigned long)pntr->volid);
609 qPut(¬okHead, pntr->volid);
611 fprintf(STDOUT, "**** Could not attach volume %lu ****\n",
612 (unsigned long)pntr->volid);
617 /*------------------------------------------------------------------------
618 * PRIVATE XDisplayFormat
621 * Display the contents of one extended volume info structure.
624 * a_xInfoP : Ptr to extended volume info struct to print.
625 * a_servID : Server ID to print.
626 * a_partID : Partition ID to print.
627 * a_totalOKP : Ptr to total-OK counter.
628 * a_totalNotOKP : Ptr to total-screwed counter.
629 * a_totalBusyP : Ptr to total-busy counter.
630 * a_fast : Fast listing?
631 * a_int32 : Int32 listing?
632 * a_showProblems : Show volume problems?
638 * Nothing interesting.
642 *------------------------------------------------------------------------*/
645 XDisplayFormat(volintXInfo *a_xInfoP, afs_int32 a_servID, afs_int32 a_partID,
646 int *a_totalOKP, int *a_totalNotOKP, int *a_totalBusyP,
647 int a_fast, int a_int32, int a_showProblems)
648 { /*XDisplayFormat */
656 fprintf(STDOUT, "%-10lu\n", (unsigned long)a_xInfoP->volid);
657 } else if (a_int32) {
659 * Fully-detailed listing.
661 if (a_xInfoP->status == VOK) {
663 * Volume's status is OK - all the fields are valid.
665 fprintf(STDOUT, "%-32s ", a_xInfoP->name);
666 fprintf(STDOUT, "%10lu ", (unsigned long)a_xInfoP->volid);
667 if (a_xInfoP->type == 0)
668 fprintf(STDOUT, "RW ");
669 if (a_xInfoP->type == 1)
670 fprintf(STDOUT, "RO ");
671 if (a_xInfoP->type == 2)
672 fprintf(STDOUT, "BK ");
673 fprintf(STDOUT, "%10d K used ", a_xInfoP->size);
674 fprintf(STDOUT, "%d files ", a_xInfoP->filecount);
675 if (a_xInfoP->inUse == 1) {
676 fprintf(STDOUT, "On-line");
679 fprintf(STDOUT, "Off-line");
682 fprintf(STDOUT, "\n");
683 MapPartIdIntoName(a_partID, pname);
684 fprintf(STDOUT, " %s %s \n", hostutil_GetNameByINet(a_servID),
686 fprintf(STDOUT, " RWrite %10lu ROnly %10lu Backup %10lu \n",
687 (unsigned long)a_xInfoP->parentID,
688 (unsigned long)a_xInfoP->cloneID,
689 (unsigned long)a_xInfoP->backupID);
690 fprintf(STDOUT, " MaxQuota %10d K \n", a_xInfoP->maxquota);
692 t = a_xInfoP->creationDate;
693 fprintf(STDOUT, " Creation %s",
696 t = a_xInfoP->copyDate;
697 fprintf(STDOUT, " Copy %s",
700 t = a_xInfoP->backupDate;
702 fprintf(STDOUT, " Backup Never\n");
704 fprintf(STDOUT, " Backup %s",
707 t = a_xInfoP->accessDate;
709 fprintf(STDOUT, " Last Access %s",
712 t = a_xInfoP->updateDate;
714 fprintf(STDOUT, " Last Update Never\n");
716 fprintf(STDOUT, " Last Update %s",
719 " %d accesses in the past day (i.e., vnode references)\n",
723 * Print all the read/write and authorship stats.
725 fprintf(STDOUT, "\n Raw Read/Write Stats\n");
727 " |-------------------------------------------|\n");
729 " | Same Network | Diff Network |\n");
731 " |----------|----------|----------|----------|\n");
733 " | Total | Auth | Total | Auth |\n");
735 " |----------|----------|----------|----------|\n");
736 fprintf(STDOUT, "Reads | %8d | %8d | %8d | %8d |\n",
737 a_xInfoP->stat_reads[VOLINT_STATS_SAME_NET],
738 a_xInfoP->stat_reads[VOLINT_STATS_SAME_NET_AUTH],
739 a_xInfoP->stat_reads[VOLINT_STATS_DIFF_NET],
740 a_xInfoP->stat_reads[VOLINT_STATS_DIFF_NET_AUTH]);
741 fprintf(STDOUT, "Writes | %8d | %8d | %8d | %8d |\n",
742 a_xInfoP->stat_writes[VOLINT_STATS_SAME_NET],
743 a_xInfoP->stat_writes[VOLINT_STATS_SAME_NET_AUTH],
744 a_xInfoP->stat_writes[VOLINT_STATS_DIFF_NET],
745 a_xInfoP->stat_writes[VOLINT_STATS_DIFF_NET_AUTH]);
747 " |-------------------------------------------|\n\n");
750 " Writes Affecting Authorship\n");
752 " |-------------------------------------------|\n");
754 " | File Authorship | Directory Authorship|\n");
756 " |----------|----------|----------|----------|\n");
758 " | Same | Diff | Same | Diff |\n");
760 " |----------|----------|----------|----------|\n");
761 fprintf(STDOUT, "0-60 sec | %8d | %8d | %8d | %8d |\n",
762 a_xInfoP->stat_fileSameAuthor[VOLINT_STATS_TIME_IDX_0],
763 a_xInfoP->stat_fileDiffAuthor[VOLINT_STATS_TIME_IDX_0],
764 a_xInfoP->stat_dirSameAuthor[VOLINT_STATS_TIME_IDX_0],
765 a_xInfoP->stat_dirDiffAuthor[VOLINT_STATS_TIME_IDX_0]);
766 fprintf(STDOUT, "1-10 min | %8d | %8d | %8d | %8d |\n",
767 a_xInfoP->stat_fileSameAuthor[VOLINT_STATS_TIME_IDX_1],
768 a_xInfoP->stat_fileDiffAuthor[VOLINT_STATS_TIME_IDX_1],
769 a_xInfoP->stat_dirSameAuthor[VOLINT_STATS_TIME_IDX_1],
770 a_xInfoP->stat_dirDiffAuthor[VOLINT_STATS_TIME_IDX_1]);
771 fprintf(STDOUT, "10min-1hr | %8d | %8d | %8d | %8d |\n",
772 a_xInfoP->stat_fileSameAuthor[VOLINT_STATS_TIME_IDX_2],
773 a_xInfoP->stat_fileDiffAuthor[VOLINT_STATS_TIME_IDX_2],
774 a_xInfoP->stat_dirSameAuthor[VOLINT_STATS_TIME_IDX_2],
775 a_xInfoP->stat_dirDiffAuthor[VOLINT_STATS_TIME_IDX_2]);
776 fprintf(STDOUT, "1hr-1day | %8d | %8d | %8d | %8d |\n",
777 a_xInfoP->stat_fileSameAuthor[VOLINT_STATS_TIME_IDX_3],
778 a_xInfoP->stat_fileDiffAuthor[VOLINT_STATS_TIME_IDX_3],
779 a_xInfoP->stat_dirSameAuthor[VOLINT_STATS_TIME_IDX_3],
780 a_xInfoP->stat_dirDiffAuthor[VOLINT_STATS_TIME_IDX_3]);
781 fprintf(STDOUT, "1day-1wk | %8d | %8d | %8d | %8d |\n",
782 a_xInfoP->stat_fileSameAuthor[VOLINT_STATS_TIME_IDX_4],
783 a_xInfoP->stat_fileDiffAuthor[VOLINT_STATS_TIME_IDX_4],
784 a_xInfoP->stat_dirSameAuthor[VOLINT_STATS_TIME_IDX_4],
785 a_xInfoP->stat_dirDiffAuthor[VOLINT_STATS_TIME_IDX_4]);
786 fprintf(STDOUT, "> 1wk | %8d | %8d | %8d | %8d |\n",
787 a_xInfoP->stat_fileSameAuthor[VOLINT_STATS_TIME_IDX_5],
788 a_xInfoP->stat_fileDiffAuthor[VOLINT_STATS_TIME_IDX_5],
789 a_xInfoP->stat_dirSameAuthor[VOLINT_STATS_TIME_IDX_5],
790 a_xInfoP->stat_dirDiffAuthor[VOLINT_STATS_TIME_IDX_5]);
792 " |-------------------------------------------|\n");
793 } /*Volume status OK */
794 else if (a_xInfoP->status == VBUSY) {
796 qPut(&busyHead, a_xInfoP->volid);
798 fprintf(STDOUT, "**** Volume %lu is busy ****\n",
799 (unsigned long)a_xInfoP->volid);
803 qPut(¬okHead, a_xInfoP->volid);
805 fprintf(STDOUT, "**** Could not attach volume %lu ****\n",
806 (unsigned long)a_xInfoP->volid);
807 } /*Screwed volume */
808 fprintf(STDOUT, "\n");
814 if (a_xInfoP->status == VOK) {
815 fprintf(STDOUT, "%-32s ", a_xInfoP->name);
816 fprintf(STDOUT, "%10lu ", (unsigned long)a_xInfoP->volid);
817 if (a_xInfoP->type == 0)
818 fprintf(STDOUT, "RW ");
819 if (a_xInfoP->type == 1)
820 fprintf(STDOUT, "RO ");
821 if (a_xInfoP->type == 2)
822 fprintf(STDOUT, "BK ");
823 fprintf(STDOUT, "%10d K ", a_xInfoP->size);
824 if (a_xInfoP->inUse == 1) {
825 fprintf(STDOUT, "On-line");
828 fprintf(STDOUT, "Off-line");
831 fprintf(STDOUT, "\n");
833 else if (a_xInfoP->status == VBUSY) {
835 qPut(&busyHead, a_xInfoP->volid);
837 fprintf(STDOUT, "**** Volume %lu is busy ****\n",
838 (unsigned long)a_xInfoP->volid);
842 qPut(¬okHead, a_xInfoP->volid);
844 fprintf(STDOUT, "**** Could not attach volume %lu ****\n",
845 (unsigned long)a_xInfoP->volid);
846 } /*Screwed volume */
847 } /*Default listing */
848 } /*XDisplayFormat */
850 /*------------------------------------------------------------------------
851 * PRIVATE XDisplayFormat2
854 * Display the formated contents of one extended volume info structure.
857 * a_xInfoP : Ptr to extended volume info struct to print.
858 * a_servID : Server ID to print.
859 * a_partID : Partition ID to print.
860 * a_totalOKP : Ptr to total-OK counter.
861 * a_totalNotOKP : Ptr to total-screwed counter.
862 * a_totalBusyP : Ptr to total-busy counter.
863 * a_fast : Fast listing?
864 * a_int32 : Int32 listing?
865 * a_showProblems : Show volume problems?
871 * Nothing interesting.
875 *------------------------------------------------------------------------*/
878 XDisplayFormat2(volintXInfo *a_xInfoP, afs_int32 a_servID, afs_int32 a_partID,
879 int *a_totalOKP, int *a_totalNotOKP, int *a_totalBusyP,
880 int a_fast, int a_int32, int a_showProblems)
881 { /*XDisplayFormat */
887 fprintf(STDOUT, "vold_id\t%-10lu\n", (unsigned long)a_xInfoP->volid);
888 } else if (a_int32) {
890 * Fully-detailed listing.
892 if (a_xInfoP->status == VOK) {
894 * Volume's status is OK - all the fields are valid.
897 static long server_cache = -1, partition_cache = -1;
898 static char hostname[256], address[32], pname[16];
899 int i,ai[] = {VOLINT_STATS_TIME_IDX_0,VOLINT_STATS_TIME_IDX_1,VOLINT_STATS_TIME_IDX_2,
900 VOLINT_STATS_TIME_IDX_3,VOLINT_STATS_TIME_IDX_4,VOLINT_STATS_TIME_IDX_5};
902 if (a_servID != server_cache) {
906 strcpy(hostname, hostutil_GetNameByINet(a_servID));
907 strcpy(address, inet_ntoa(s));
908 server_cache = a_servID;
910 if (a_partID != partition_cache) {
911 MapPartIdIntoName(a_partID, pname);
912 partition_cache = a_partID;
915 fprintf(STDOUT, "name\t\t%s\n", a_xInfoP->name);
916 fprintf(STDOUT, "id\t\t%lu\n", afs_printable_uint32_lu(a_xInfoP->volid));
917 fprintf(STDOUT, "serv\t\t%s\t%s\n", address, hostname);
918 fprintf(STDOUT, "part\t\t%s\n", pname);
919 fprintf(STDOUT, "status\t\tOK\n");
920 fprintf(STDOUT, "backupID\t%lu\n",
921 afs_printable_uint32_lu(a_xInfoP->backupID));
922 fprintf(STDOUT, "parentID\t%lu\n",
923 afs_printable_uint32_lu(a_xInfoP->parentID));
924 fprintf(STDOUT, "cloneID\t\t%lu\n",
925 afs_printable_uint32_lu(a_xInfoP->cloneID));
926 fprintf(STDOUT, "inUse\t\t%s\n", a_xInfoP->inUse ? "Y" : "N");
927 switch (a_xInfoP->type) {
929 fprintf(STDOUT, "type\t\tRW\n");
932 fprintf(STDOUT, "type\t\tRO\n");
935 fprintf(STDOUT, "type\t\tBK\n");
938 fprintf(STDOUT, "type\t\t?\n");
941 t = a_xInfoP->creationDate;
942 fprintf(STDOUT, "creationDate\t%-9lu\t%s",
943 afs_printable_uint32_lu(a_xInfoP->creationDate),
946 t = a_xInfoP->accessDate;
947 fprintf(STDOUT, "accessDate\t%-9lu\t%s",
948 afs_printable_uint32_lu(a_xInfoP->accessDate),
951 t = a_xInfoP->updateDate;
952 fprintf(STDOUT, "updateDate\t%-9lu\t%s",
953 afs_printable_uint32_lu(a_xInfoP->updateDate),
956 t = a_xInfoP->backupDate;
957 fprintf(STDOUT, "backupDate\t%-9lu\t%s",
958 afs_printable_uint32_lu(a_xInfoP->backupDate),
961 t = a_xInfoP->copyDate;
962 fprintf(STDOUT, "copyDate\t%-9lu\t%s",
963 afs_printable_uint32_lu(a_xInfoP->copyDate),
966 fprintf(STDOUT, "diskused\t%u\n", a_xInfoP->size);
967 fprintf(STDOUT, "maxquota\t%u\n", a_xInfoP->maxquota);
969 fprintf(STDOUT, "filecount\t%u\n", a_xInfoP->filecount);
970 fprintf(STDOUT, "dayUse\t\t%u\n", a_xInfoP->dayUse);
974 fprintf(STDOUT,"reads_same_net\t%8d\n",a_xInfoP->stat_reads[VOLINT_STATS_SAME_NET]);
975 fprintf(STDOUT,"reads_same_net_auth\t%8d\n",a_xInfoP->stat_reads[VOLINT_STATS_SAME_NET_AUTH]);
976 fprintf(STDOUT,"reads_diff_net\t%8d\n",a_xInfoP->stat_reads[VOLINT_STATS_DIFF_NET]);
977 fprintf(STDOUT,"reads_diff_net_auth\t%8d\n",a_xInfoP->stat_reads[VOLINT_STATS_DIFF_NET_AUTH]);
979 fprintf(STDOUT,"writes_same_net\t%8d\n",a_xInfoP->stat_writes[VOLINT_STATS_SAME_NET]);
980 fprintf(STDOUT,"writes_same_net_auth\t%8d\n",a_xInfoP->stat_writes[VOLINT_STATS_SAME_NET_AUTH]);
981 fprintf(STDOUT,"writes_diff_net\t%8d\n",a_xInfoP->stat_writes[VOLINT_STATS_DIFF_NET]);
982 fprintf(STDOUT,"writes_diff_net_auth\t%8d\n",a_xInfoP->stat_writes[VOLINT_STATS_DIFF_NET_AUTH]);
986 fprintf(STDOUT,"file_same_author_idx_%d\t%8d\n",i+1,a_xInfoP->stat_fileSameAuthor[ai[i]]);
987 fprintf(STDOUT,"file_diff_author_idx_%d\t%8d\n",i+1,a_xInfoP->stat_fileDiffAuthor[ai[i]]);
988 fprintf(STDOUT,"dir_same_author_idx_%d\t%8d\n",i+1,a_xInfoP->stat_dirSameAuthor[ai[i]]);
989 fprintf(STDOUT,"dir_dif_author_idx_%d\t%8d\n",i+1,a_xInfoP->stat_dirDiffAuthor[ai[i]]);
992 } /*Volume status OK */
993 else if (a_xInfoP->status == VBUSY) {
995 qPut(&busyHead, a_xInfoP->volid);
997 fprintf(STDOUT, "BUSY_VOL\t%lu\n",
998 (unsigned long)a_xInfoP->volid);
1002 qPut(¬okHead, a_xInfoP->volid);
1004 fprintf(STDOUT, "COULD_NOT_ATTACH\t%lu\n",
1005 (unsigned long)a_xInfoP->volid);
1006 } /*Screwed volume */
1012 if (a_xInfoP->status == VOK) {
1013 fprintf(STDOUT, "name\t%-32s\n", a_xInfoP->name);
1014 fprintf(STDOUT, "volID\t%10lu\n", (unsigned long)a_xInfoP->volid);
1015 if (a_xInfoP->type == 0)
1016 fprintf(STDOUT, "type\tRW\n");
1017 if (a_xInfoP->type == 1)
1018 fprintf(STDOUT, "type\tRO\n");
1019 if (a_xInfoP->type == 2)
1020 fprintf(STDOUT, "type\tBK\n");
1021 fprintf(STDOUT, "size\t%10dK\n", a_xInfoP->size);
1023 fprintf(STDOUT, "inUse\t%d\n",a_xInfoP->inUse);
1024 if (a_xInfoP->inUse == 1)
1030 else if (a_xInfoP->status == VBUSY) {
1032 qPut(&busyHead, a_xInfoP->volid);
1034 fprintf(STDOUT, "VOLUME_BUSY\t%lu\n",
1035 (unsigned long)a_xInfoP->volid);
1039 qPut(¬okHead, a_xInfoP->volid);
1041 fprintf(STDOUT, "COULD_NOT_ATTACH_VOLUME\t%lu\n",
1042 (unsigned long)a_xInfoP->volid);
1043 } /*Screwed volume */
1044 } /*Default listing */
1045 } /*XDisplayFormat */
1048 DisplayFormat2(long server, long partition, volintInfo *pntr)
1050 static long server_cache = -1, partition_cache = -1;
1051 static char hostname[256], address[32], pname[16];
1054 if (server != server_cache) {
1058 strcpy(hostname, hostutil_GetNameByINet(server));
1059 strcpy(address, inet_ntoa(s));
1060 server_cache = server;
1062 if (partition != partition_cache) {
1063 MapPartIdIntoName(partition, pname);
1064 partition_cache = partition;
1067 if (pntr->status == VOK)
1068 fprintf(STDOUT, "name\t\t%s\n", pntr->name);
1070 fprintf(STDOUT, "id\t\t%lu\n",
1071 afs_printable_uint32_lu(pntr->volid));
1072 fprintf(STDOUT, "serv\t\t%s\t%s\n", address, hostname);
1073 fprintf(STDOUT, "part\t\t%s\n", pname);
1074 switch (pntr->status) {
1076 fprintf(STDOUT, "status\t\tOK\n");
1079 fprintf(STDOUT, "status\t\tBUSY\n");
1082 fprintf(STDOUT, "status\t\tUNATTACHABLE\n");
1085 fprintf(STDOUT, "backupID\t%lu\n",
1086 afs_printable_uint32_lu(pntr->backupID));
1087 fprintf(STDOUT, "parentID\t%lu\n",
1088 afs_printable_uint32_lu(pntr->parentID));
1089 fprintf(STDOUT, "cloneID\t\t%lu\n",
1090 afs_printable_uint32_lu(pntr->cloneID));
1091 fprintf(STDOUT, "inUse\t\t%s\n", pntr->inUse ? "Y" : "N");
1092 fprintf(STDOUT, "needsSalvaged\t%s\n", pntr->needsSalvaged ? "Y" : "N");
1093 /* 0xD3 is from afs/volume.h since I had trouble including the file */
1094 fprintf(STDOUT, "destroyMe\t%s\n", pntr->destroyMe == 0xD3 ? "Y" : "N");
1095 switch (pntr->type) {
1097 fprintf(STDOUT, "type\t\tRW\n");
1100 fprintf(STDOUT, "type\t\tRO\n");
1103 fprintf(STDOUT, "type\t\tBK\n");
1106 fprintf(STDOUT, "type\t\t?\n");
1109 t = pntr->creationDate;
1110 fprintf(STDOUT, "creationDate\t%-9lu\t%s",
1111 afs_printable_uint32_lu(pntr->creationDate),
1114 t = pntr->accessDate;
1115 fprintf(STDOUT, "accessDate\t%-9lu\t%s",
1116 afs_printable_uint32_lu(pntr->accessDate),
1119 t = pntr->updateDate;
1120 fprintf(STDOUT, "updateDate\t%-9lu\t%s",
1121 afs_printable_uint32_lu(pntr->updateDate),
1124 t = pntr->backupDate;
1125 fprintf(STDOUT, "backupDate\t%-9lu\t%s",
1126 afs_printable_uint32_lu(pntr->backupDate),
1130 fprintf(STDOUT, "copyDate\t%-9lu\t%s",
1131 afs_printable_uint32_lu(pntr->copyDate),
1134 fprintf(STDOUT, "flags\t\t%#lx\t(Optional)\n",
1135 afs_printable_uint32_lu(pntr->flags));
1136 fprintf(STDOUT, "diskused\t%u\n", pntr->size);
1137 fprintf(STDOUT, "maxquota\t%u\n", pntr->maxquota);
1138 fprintf(STDOUT, "minquota\t%lu\t(Optional)\n",
1139 afs_printable_uint32_lu(pntr->spare0));
1140 fprintf(STDOUT, "filecount\t%u\n", pntr->filecount);
1141 fprintf(STDOUT, "dayUse\t\t%u\n", pntr->dayUse);
1142 fprintf(STDOUT, "weekUse\t\t%lu\t(Optional)\n",
1143 afs_printable_uint32_lu(pntr->spare1));
1144 fprintf(STDOUT, "spare2\t\t%lu\t(Optional)\n",
1145 afs_printable_uint32_lu(pntr->spare2));
1146 fprintf(STDOUT, "spare3\t\t%lu\t(Optional)\n",
1147 afs_printable_uint32_lu(pntr->spare3));
1152 DisplayVolumes2(long server, long partition, volintInfo *pntr, long count)
1156 for (i = 0; i < count; i++) {
1157 fprintf(STDOUT, "BEGIN_OF_ENTRY\n");
1158 DisplayFormat2(server, partition, pntr);
1159 fprintf(STDOUT, "END_OF_ENTRY\n\n");
1166 DisplayVolumes(afs_int32 server, afs_int32 part, volintInfo *pntr,
1167 afs_int32 count, afs_int32 longlist, afs_int32 fast,
1170 int totalOK, totalNotOK, totalBusy, i;
1171 afs_uint32 volid = 0;
1178 for (i = 0; i < count; i++) {
1179 DisplayFormat(pntr, server, part, &totalOK, &totalNotOK, &totalBusy,
1184 while (busyHead.count) {
1185 qGet(&busyHead, &volid);
1186 fprintf(STDOUT, "**** Volume %lu is busy ****\n",
1187 (unsigned long)volid);
1191 while (notokHead.count) {
1192 qGet(¬okHead, &volid);
1193 fprintf(STDOUT, "**** Could not attach volume %lu ****\n",
1194 (unsigned long)volid);
1198 fprintf(STDOUT, "\n");
1201 "Total volumes onLine %d ; Total volumes offLine %d ; Total busy %d\n\n",
1202 totalOK, totalNotOK, totalBusy);
1206 /*------------------------------------------------------------------------
1207 * PRIVATE XDisplayVolumes
1210 * Display extended volume information.
1213 * a_servID : Pointer to the Rx call we're performing.
1214 * a_partID : Partition for which we want the extended list.
1215 * a_xInfoP : Ptr to extended volume info.
1216 * a_count : Number of volume records contained above.
1217 * a_int32 : Int32 listing generated?
1218 * a_fast : Fast listing generated?
1219 * a_quiet : Quiet listing generated?
1225 * Nothing interesting.
1229 *------------------------------------------------------------------------*/
1232 XDisplayVolumes(afs_int32 a_servID, afs_int32 a_partID, volintXInfo *a_xInfoP,
1233 afs_int32 a_count, afs_int32 a_int32, afs_int32 a_fast,
1235 { /*XDisplayVolumes */
1237 int totalOK; /*Total OK volumes */
1238 int totalNotOK; /*Total screwed volumes */
1239 int totalBusy; /*Total busy volumes */
1240 int i; /*Loop variable */
1241 afs_uint32 volid = 0; /*Current volume ID */
1244 * Initialize counters and (global!!) queues.
1253 * Display each volume in the list.
1255 for (i = 0; i < a_count; i++) {
1256 XDisplayFormat(a_xInfoP, a_servID, a_partID, &totalOK, &totalNotOK,
1257 &totalBusy, a_fast, a_int32, 0);
1262 * If any volumes were found to be busy or screwed, display them.
1265 while (busyHead.count) {
1266 qGet(&busyHead, &volid);
1267 fprintf(STDOUT, "**** Volume %lu is busy ****\n",
1268 (unsigned long)volid);
1272 while (notokHead.count) {
1273 qGet(¬okHead, &volid);
1274 fprintf(STDOUT, "**** Could not attach volume %lu ****\n",
1275 (unsigned long)volid);
1280 fprintf(STDOUT, "\n");
1283 "Total volumes: %d on-line, %d off-line, %d busyd\n\n",
1284 totalOK, totalNotOK, totalBusy);
1288 } /*XDisplayVolumes */
1290 /*------------------------------------------------------------------------
1291 * PRIVATE XDisplayVolumes2
1294 * Display extended formated volume information.
1297 * a_servID : Pointer to the Rx call we're performing.
1298 * a_partID : Partition for which we want the extended list.
1299 * a_xInfoP : Ptr to extended volume info.
1300 * a_count : Number of volume records contained above.
1301 * a_int32 : Int32 listing generated?
1302 * a_fast : Fast listing generated?
1303 * a_quiet : Quiet listing generated?
1309 * Nothing interesting.
1313 *------------------------------------------------------------------------*/
1316 XDisplayVolumes2(afs_int32 a_servID, afs_int32 a_partID, volintXInfo *a_xInfoP,
1317 afs_int32 a_count, afs_int32 a_int32, afs_int32 a_fast,
1319 { /*XDisplayVolumes */
1321 int totalOK; /*Total OK volumes */
1322 int totalNotOK; /*Total screwed volumes */
1323 int totalBusy; /*Total busy volumes */
1324 int i; /*Loop variable */
1325 afs_uint32 volid = 0; /*Current volume ID */
1328 * Initialize counters and (global!!) queues.
1337 * Display each volume in the list.
1339 for (i = 0; i < a_count; i++) {
1340 fprintf(STDOUT, "BEGIN_OF_ENTRY\n");
1341 XDisplayFormat2(a_xInfoP, a_servID, a_partID, &totalOK, &totalNotOK,
1342 &totalBusy, a_fast, a_int32, 0);
1343 fprintf(STDOUT, "END_OF_ENTRY\n");
1348 * If any volumes were found to be busy or screwed, display them.
1351 while (busyHead.count) {
1352 qGet(&busyHead, &volid);
1353 fprintf(STDOUT, "BUSY_VOL\t%lu\n",
1354 (unsigned long)volid);
1358 while (notokHead.count) {
1359 qGet(¬okHead, &volid);
1360 fprintf(STDOUT, "COULD_NOT_ATTACH\t%lu\n",
1361 (unsigned long)volid);
1366 fprintf(STDOUT, "\n");
1369 "VOLUMES_ONLINE\t%d\nVOLUMES_OFFLINE\t%d\nVOLUMES_BUSY\t%d\n",
1370 totalOK, totalNotOK, totalBusy);
1374 } /*XDisplayVolumes2 */
1377 /* set <server> and <part> to the correct values depending on
1378 * <voltype> and <entry> */
1380 GetServerAndPart(struct nvldbentry *entry, int voltype, afs_int32 *server,
1381 afs_int32 *part, int *previdx)
1383 int i, istart, vtype;
1388 /* Doesn't check for non-existance of backup volume */
1389 if ((voltype == RWVOL) || (voltype == BACKVOL)) {
1391 istart = 0; /* seach the entire entry */
1394 /* Seach from beginning of entry or pick up where we left off */
1395 istart = ((*previdx < 0) ? 0 : *previdx + 1);
1398 for (i = istart; i < entry->nServers; i++) {
1399 if (entry->serverFlags[i] & vtype) {
1400 *server = entry->serverNumber[i];
1401 *part = entry->serverPartition[i];
1407 /* Didn't find any, return -1 */
1413 PostVolumeStats(struct nvldbentry *entry)
1415 SubEnumerateEntry(entry);
1416 /* Check for VLOP_ALLOPERS */
1417 if (entry->flags & VLOP_ALLOPERS)
1418 fprintf(STDOUT, " Volume is currently LOCKED \n");
1422 /*------------------------------------------------------------------------
1423 * PRIVATE XVolumeStats
1426 * Display extended volume information.
1429 * a_xInfoP : Ptr to extended volume info.
1430 * a_entryP : Ptr to the volume's VLDB entry.
1431 * a_srvID : Server ID.
1432 * a_partID : Partition ID.
1433 * a_volType : Type of volume to print.
1439 * Nothing interesting.
1443 *------------------------------------------------------------------------*/
1446 XVolumeStats(volintXInfo *a_xInfoP, struct nvldbentry *a_entryP,
1447 afs_int32 a_srvID, afs_int32 a_partID, int a_volType)
1450 int totalOK, totalNotOK, totalBusy; /*Dummies - we don't really count here */
1452 XDisplayFormat(a_xInfoP, /*Ptr to extended volume info */
1453 a_srvID, /*Server ID to print */
1454 a_partID, /*Partition ID to print */
1455 &totalOK, /*Ptr to total-OK counter */
1456 &totalNotOK, /*Ptr to total-screwed counter */
1457 &totalBusy, /*Ptr to total-busy counter */
1458 0, /*Don't do a fast listing */
1459 1, /*Do a long listing */
1460 1); /*Show volume problems */
1466 VolumeStats_int(volintInfo *pntr, struct nvldbentry *entry, afs_int32 server,
1467 afs_int32 part, int voltype)
1469 int totalOK, totalNotOK, totalBusy;
1471 DisplayFormat(pntr, server, part, &totalOK, &totalNotOK, &totalBusy, 0, 1,
1476 /* command to forcibly remove a volume */
1478 NukeVolume(register struct cmd_syndesc *as)
1480 register afs_int32 code;
1487 server = GetServer(tp = as->parms[0].items->data);
1489 fprintf(STDERR, "vos: server '%s' not found in host table\n", tp);
1493 partID = volutil_GetPartitionID(tp = as->parms[1].items->data);
1495 fprintf(STDERR, "vos: could not parse '%s' as a partition name", tp);
1499 volID = vsu_GetVolumeID(tp = as->parms[2].items->data, cstruct, &err);
1502 PrintError("", err);
1505 "vos: could not parse '%s' as a numeric volume ID", tp);
1510 "vos: forcibly removing all traces of volume %d, please wait...",
1513 code = UV_NukeVolume(server, partID, volID);
1515 fprintf(STDOUT, "done.\n");
1517 fprintf(STDOUT, "failed with code %d.\n", code);
1522 /*------------------------------------------------------------------------
1523 * PRIVATE ExamineVolume
1526 * Routine used to examine a single volume, contacting the VLDB as
1527 * well as the Volume Server.
1530 * as : Ptr to parsed command line arguments.
1533 * 0 for a successful operation,
1534 * Otherwise, one of the ubik or VolServer error values.
1537 * Nothing interesting.
1541 *------------------------------------------------------------------------
1544 ExamineVolume(register struct cmd_syndesc *as, void *arock)
1546 struct nvldbentry entry;
1547 afs_int32 vcode = 0;
1548 volintInfo *pntr = (volintInfo *) 0;
1549 volintXInfo *xInfoP = (volintXInfo *) 0;
1551 afs_int32 code, err, error = 0;
1552 int voltype, foundserv = 0, foundentry = 0;
1553 afs_int32 aserver, apart;
1555 int wantExtendedInfo; /*Do we want extended vol info? */
1557 wantExtendedInfo = (as->parms[1].items ? 1 : 0); /* -extended */
1559 volid = vsu_GetVolumeID(as->parms[0].items->data, cstruct, &err); /* -id */
1562 PrintError("", err);
1564 fprintf(STDERR, "Unknown volume ID or name '%s'\n",
1565 as->parms[0].items->data);
1570 fprintf(STDOUT, "Fetching VLDB entry for %lu .. ",
1571 (unsigned long)volid);
1574 vcode = VLDB_GetEntryByID(volid, -1, &entry);
1577 "Could not fetch the entry for volume number %lu from VLDB \n",
1578 (unsigned long)volid);
1582 fprintf(STDOUT, "done\n");
1583 MapHostToNetwork(&entry);
1585 if (entry.volumeId[RWVOL] == volid)
1587 else if (entry.volumeId[BACKVOL] == volid)
1589 else /* (entry.volumeId[ROVOL] == volid) */
1592 do { /* do {...} while (voltype == ROVOL) */
1593 /* Get the entry for the volume. If its a RW vol, get the RW entry.
1594 * It its a BK vol, get the RW entry (even if VLDB may say the BK doen't exist).
1595 * If its a RO vol, get the next RO entry.
1597 GetServerAndPart(&entry, ((voltype == ROVOL) ? ROVOL : RWVOL),
1598 &aserver, &apart, &previdx);
1599 if (previdx == -1) { /* searched all entries */
1601 fprintf(STDERR, "Volume %s does not exist in VLDB\n\n",
1602 as->parms[0].items->data);
1609 /* Get information about the volume from the server */
1611 fprintf(STDOUT, "Getting volume listing from the server %s .. ",
1612 hostutil_GetNameByINet(aserver));
1615 if (wantExtendedInfo)
1616 code = UV_XListOneVolume(aserver, apart, volid, &xInfoP);
1618 code = UV_ListOneVolume(aserver, apart, volid, &pntr);
1620 fprintf(STDOUT, "done\n");
1624 if (code == ENODEV) {
1625 if ((voltype == BACKVOL) && !(entry.flags & BACK_EXISTS)) {
1626 /* The VLDB says there is no backup volume and its not on disk */
1627 fprintf(STDERR, "Volume %s does not exist\n",
1628 as->parms[0].items->data);
1632 "Volume does not exist on server %s as indicated by the VLDB\n",
1633 hostutil_GetNameByINet(aserver));
1636 PrintDiagnostics("examine", code);
1638 fprintf(STDOUT, "\n");
1641 if (wantExtendedInfo)
1642 XVolumeStats(xInfoP, &entry, aserver, apart, voltype);
1643 else if (as->parms[2].items) {
1644 DisplayFormat2(aserver, apart, pntr);
1645 EnumerateEntry(&entry);
1647 VolumeStats_int(pntr, &entry, aserver, apart, voltype);
1649 if ((voltype == BACKVOL) && !(entry.flags & BACK_EXISTS)) {
1650 /* The VLDB says there is no backup volume yet we found one on disk */
1651 fprintf(STDERR, "Volume %s does not exist in VLDB\n",
1652 as->parms[0].items->data);
1661 } while (voltype == ROVOL);
1664 fprintf(STDERR, "Dump only information from VLDB\n\n");
1665 fprintf(STDOUT, "%s \n", entry.name); /* PostVolumeStats doesn't print name */
1667 PostVolumeStats(&entry);
1672 /*------------------------------------------------------------------------
1676 * Routine used to change the status of a single volume.
1679 * as : Ptr to parsed command line arguments.
1682 * 0 for a successful operation,
1683 * Otherwise, one of the ubik or VolServer error values.
1686 * Nothing interesting.
1690 *------------------------------------------------------------------------
1693 SetFields(register struct cmd_syndesc *as, void *arock)
1695 struct nvldbentry entry;
1698 afs_int32 code, err;
1699 afs_int32 aserver, apart;
1702 volid = vsu_GetVolumeID(as->parms[0].items->data, cstruct, &err); /* -id */
1705 PrintError("", err);
1707 fprintf(STDERR, "Unknown volume ID or name '%s'\n",
1708 as->parms[0].items->data);
1712 code = VLDB_GetEntryByID(volid, RWVOL, &entry);
1715 "Could not fetch the entry for volume number %lu from VLDB \n",
1716 (unsigned long)volid);
1719 MapHostToNetwork(&entry);
1721 GetServerAndPart(&entry, RWVOL, &aserver, &apart, &previdx);
1722 if (previdx == -1) {
1723 fprintf(STDERR, "Volume %s does not exist in VLDB\n\n",
1724 as->parms[0].items->data);
1728 init_volintInfo(&info);
1732 if (as->parms[1].items) {
1734 code = util_GetHumanInt32(as->parms[1].items->data, &info.maxquota);
1736 fprintf(STDERR, "invalid quota value\n");
1740 if (as->parms[2].items) {
1744 if (as->parms[3].items) {
1745 /* -clearVolUpCounter */
1748 code = UV_SetVolumeInfo(aserver, apart, volid, &info);
1751 "Could not update volume info fields for volume number %lu\n",
1752 (unsigned long)volid);
1756 /*------------------------------------------------------------------------
1760 * Brings a volume online.
1763 * as : Ptr to parsed command line arguments.
1766 * 0 for a successful operation,
1769 * Nothing interesting.
1773 *------------------------------------------------------------------------
1776 volOnline(register struct cmd_syndesc *as, void *arock)
1778 afs_int32 server, partition;
1780 afs_int32 code, err = 0;
1782 server = GetServer(as->parms[0].items->data);
1784 fprintf(STDERR, "vos: server '%s' not found in host table\n",
1785 as->parms[0].items->data);
1789 partition = volutil_GetPartitionID(as->parms[1].items->data);
1790 if (partition < 0) {
1791 fprintf(STDERR, "vos: could not interpret partition name '%s'\n",
1792 as->parms[1].items->data);
1796 volid = vsu_GetVolumeID(as->parms[2].items->data, cstruct, &err); /* -id */
1799 PrintError("", err);
1801 fprintf(STDERR, "Unknown volume ID or name '%s'\n",
1802 as->parms[0].items->data);
1806 code = UV_SetVolume(server, partition, volid, ITOffline, 0 /*online */ ,
1809 fprintf(STDERR, "Failed to set volume. Code = %d\n", code);
1816 /*------------------------------------------------------------------------
1817 * PRIVATE volOffline
1820 * Brings a volume offline.
1823 * as : Ptr to parsed command line arguments.
1826 * 0 for a successful operation,
1829 * Nothing interesting.
1833 *------------------------------------------------------------------------
1836 volOffline(register struct cmd_syndesc *as, void *arock)
1838 afs_int32 server, partition;
1840 afs_int32 code, err = 0;
1841 afs_int32 transflag, sleeptime, transdone;
1843 server = GetServer(as->parms[0].items->data);
1845 fprintf(STDERR, "vos: server '%s' not found in host table\n",
1846 as->parms[0].items->data);
1850 partition = volutil_GetPartitionID(as->parms[1].items->data);
1851 if (partition < 0) {
1852 fprintf(STDERR, "vos: could not interpret partition name '%s'\n",
1853 as->parms[1].items->data);
1857 volid = vsu_GetVolumeID(as->parms[2].items->data, cstruct, &err); /* -id */
1860 PrintError("", err);
1862 fprintf(STDERR, "Unknown volume ID or name '%s'\n",
1863 as->parms[0].items->data);
1867 transflag = (as->parms[4].items ? ITBusy : ITOffline);
1868 sleeptime = (as->parms[3].items ? atol(as->parms[3].items->data) : 0);
1869 transdone = (sleeptime ? 0 /*online */ : VTOutOfService);
1870 if (as->parms[4].items && !as->parms[3].items) {
1871 fprintf(STDERR, "-sleep option must be used with -busy flag\n");
1876 UV_SetVolume(server, partition, volid, transflag, transdone,
1879 fprintf(STDERR, "Failed to set volume. Code = %d\n", code);
1887 CreateVolume(register struct cmd_syndesc *as, void *arock)
1891 afs_uint32 volid = 0, rovolid = 0, bkvolid = 0;
1892 afs_uint32 *arovolid;
1894 struct nvldbentry entry;
1898 arovolid = &rovolid;
1901 tserver = GetServer(as->parms[0].items->data);
1903 fprintf(STDERR, "vos: host '%s' not found in host table\n",
1904 as->parms[0].items->data);
1907 pnum = volutil_GetPartitionID(as->parms[1].items->data);
1909 fprintf(STDERR, "vos: could not interpret partition name '%s'\n",
1910 as->parms[1].items->data);
1913 if (!IsPartValid(pnum, tserver, &code)) { /*check for validity of the partition */
1915 PrintError("", code);
1918 "vos : partition %s does not exist on the server\n",
1919 as->parms[1].items->data);
1922 if (!ISNAMEVALID(as->parms[2].items->data)) {
1924 "vos: the name of the root volume %s exceeds the size limit of %d\n",
1925 as->parms[2].items->data, VOLSER_OLDMAXVOLNAME - 10);
1928 if (!VolNameOK(as->parms[2].items->data)) {
1930 "Illegal volume name %s, should not end in .readonly or .backup\n",
1931 as->parms[2].items->data);
1934 if (IsNumeric(as->parms[2].items->data)) {
1935 fprintf(STDERR, "Illegal volume name %s, should not be a number\n",
1936 as->parms[2].items->data);
1939 vcode = VLDB_GetEntryByName(as->parms[2].items->data, &entry);
1941 fprintf(STDERR, "Volume %s already exists\n",
1942 as->parms[2].items->data);
1943 PrintDiagnostics("create", code);
1947 if (as->parms[3].items) {
1948 code = util_GetHumanInt32(as->parms[3].items->data, "a);
1950 fprintf(STDERR, "vos: bad integer specified for quota.\n");
1955 if (as->parms[4].items) {
1956 if (!IsNumeric(as->parms[4].items->data)) {
1957 fprintf(STDERR, "vos: Given volume ID %s should be numeric.\n",
1958 as->parms[4].items->data);
1962 code = util_GetUInt32(as->parms[4].items->data, &volid);
1964 fprintf(STDERR, "vos: bad integer specified for volume ID.\n");
1969 if (as->parms[5].items) {
1970 if (!IsNumeric(as->parms[5].items->data)) {
1971 fprintf(STDERR, "vos: Given RO volume ID %s should be numeric.\n",
1972 as->parms[5].items->data);
1976 code = util_GetUInt32(as->parms[5].items->data, &rovolid);
1978 fprintf(STDERR, "vos: bad integer specified for volume ID.\n");
1988 UV_CreateVolume3(tserver, pnum, as->parms[2].items->data, quota, 0,
1989 0, 0, 0, &volid, arovolid, &bkvolid);
1991 PrintDiagnostics("create", code);
1994 MapPartIdIntoName(pnum, part);
1995 fprintf(STDOUT, "Volume %lu created on partition %s of %s\n",
1996 (unsigned long)volid, part, as->parms[0].items->data);
2003 DeleteAll(struct nvldbentry *entry)
2006 afs_int32 error, code, curserver, curpart;
2009 MapHostToNetwork(entry);
2011 for (i = 0; i < entry->nServers; i++) {
2012 curserver = entry->serverNumber[i];
2013 curpart = entry->serverPartition[i];
2014 if (entry->serverFlags[i] & ITSROVOL) {
2015 volid = entry->volumeId[ROVOL];
2017 volid = entry->volumeId[RWVOL];
2019 code = UV_DeleteVolume(curserver, curpart, volid);
2028 DeleteVolume(struct cmd_syndesc *as, void *arock)
2030 afs_int32 err, code = 0;
2031 afs_int32 server = 0, partition = -1;
2036 if (as->parms[0].items) {
2037 server = GetServer(as->parms[0].items->data);
2039 fprintf(STDERR, "vos: server '%s' not found in host table\n",
2040 as->parms[0].items->data);
2045 if (as->parms[1].items) {
2046 partition = volutil_GetPartitionID(as->parms[1].items->data);
2047 if (partition < 0) {
2048 fprintf(STDERR, "vos: could not interpret partition name '%s'\n",
2049 as->parms[1].items->data);
2053 /* Check for validity of the partition */
2054 if (!IsPartValid(partition, server, &code)) {
2056 PrintError("", code);
2059 "vos : partition %s does not exist on the server\n",
2060 as->parms[1].items->data);
2066 volid = vsu_GetVolumeID(as->parms[2].items->data, cstruct, &err);
2068 fprintf(STDERR, "Can't find volume name '%s' in VLDB\n",
2069 as->parms[2].items->data);
2071 PrintError("", err);
2075 /* If the server or partition option are not complete, try to fill
2076 * them in from the VLDB entry.
2078 if ((partition == -1) || !server) {
2079 struct nvldbentry entry;
2081 code = VLDB_GetEntryByID(volid, -1, &entry);
2084 "Could not fetch the entry for volume %lu from VLDB\n",
2085 (unsigned long)volid);
2086 PrintError("", code);
2090 if (((volid == entry.volumeId[RWVOL]) && (entry.flags & RW_EXISTS))
2091 || ((volid == entry.volumeId[BACKVOL])
2092 && (entry.flags & BACK_EXISTS))) {
2093 idx = Lp_GetRwIndex(&entry);
2094 if ((idx == -1) || (server && (server != entry.serverNumber[idx]))
2095 || ((partition != -1)
2096 && (partition != entry.serverPartition[idx]))) {
2097 fprintf(STDERR, "VLDB: Volume '%s' no match\n",
2098 as->parms[2].items->data);
2101 } else if ((volid == entry.volumeId[ROVOL])
2102 && (entry.flags & RO_EXISTS)) {
2103 for (idx = -1, j = 0; j < entry.nServers; j++) {
2104 if (entry.serverFlags[j] != ITSROVOL)
2107 if (((server == 0) || (server == entry.serverNumber[j]))
2108 && ((partition == -1)
2109 || (partition == entry.serverPartition[j]))) {
2112 "VLDB: Volume '%s' matches more than one RO\n",
2113 as->parms[2].items->data);
2120 fprintf(STDERR, "VLDB: Volume '%s' no match\n",
2121 as->parms[2].items->data);
2125 fprintf(STDERR, "VLDB: Volume '%s' no match\n",
2126 as->parms[2].items->data);
2130 server = htonl(entry.serverNumber[idx]);
2131 partition = entry.serverPartition[idx];
2135 code = UV_DeleteVolume(server, partition, volid);
2137 PrintDiagnostics("remove", code);
2141 MapPartIdIntoName(partition, pname);
2142 fprintf(STDOUT, "Volume %lu on partition %s server %s deleted\n",
2143 (unsigned long)volid, pname, hostutil_GetNameByINet(server));
2147 #define TESTM 0 /* set for move space tests, clear for production */
2149 MoveVolume(register struct cmd_syndesc *as, void *arock)
2153 afs_int32 fromserver, toserver, frompart, topart;
2154 afs_int32 flags, code, err;
2155 char fromPartName[10], toPartName[10];
2157 struct diskPartition64 partition; /* for space check */
2160 volid = vsu_GetVolumeID(as->parms[0].items->data, cstruct, &err);
2163 PrintError("", err);
2165 fprintf(STDERR, "vos: can't find volume ID or name '%s'\n",
2166 as->parms[0].items->data);
2169 fromserver = GetServer(as->parms[1].items->data);
2170 if (fromserver == 0) {
2171 fprintf(STDERR, "vos: server '%s' not found in host table\n",
2172 as->parms[1].items->data);
2175 toserver = GetServer(as->parms[3].items->data);
2176 if (toserver == 0) {
2177 fprintf(STDERR, "vos: server '%s' not found in host table\n",
2178 as->parms[3].items->data);
2181 frompart = volutil_GetPartitionID(as->parms[2].items->data);
2183 fprintf(STDERR, "vos: could not interpret partition name '%s'\n",
2184 as->parms[2].items->data);
2187 if (!IsPartValid(frompart, fromserver, &code)) { /*check for validity of the partition */
2189 PrintError("", code);
2192 "vos : partition %s does not exist on the server\n",
2193 as->parms[2].items->data);
2196 topart = volutil_GetPartitionID(as->parms[4].items->data);
2198 fprintf(STDERR, "vos: could not interpret partition name '%s'\n",
2199 as->parms[4].items->data);
2202 if (!IsPartValid(topart, toserver, &code)) { /*check for validity of the partition */
2204 PrintError("", code);
2207 "vos : partition %s does not exist on the server\n",
2208 as->parms[4].items->data);
2213 if (as->parms[5].items) flags |= RV_NOCLONE;
2216 * check source partition for space to clone volume
2219 MapPartIdIntoName(topart, toPartName);
2220 MapPartIdIntoName(frompart, fromPartName);
2223 * check target partition for space to move volume
2226 code = UV_PartitionInfo64(toserver, toPartName, &partition);
2228 fprintf(STDERR, "vos: cannot access partition %s\n", toPartName);
2232 fprintf(STDOUT, "target partition %s free space %" AFS_INT64_FMT "\n", toPartName,
2235 p = (volintInfo *) 0;
2236 code = UV_ListOneVolume(fromserver, frompart, volid, &p);
2238 fprintf(STDERR, "vos:cannot access volume %lu\n",
2239 (unsigned long)volid);
2243 fprintf(STDOUT, "volume %lu size %d\n", (unsigned long)volid,
2245 if (partition.free <= p->size) {
2247 "vos: no space on target partition %s to move volume %lu\n",
2248 toPartName, (unsigned long)volid);
2255 fprintf(STDOUT, "size test - don't do move\n");
2259 /* successful move still not guaranteed but shoot for it */
2262 UV_MoveVolume2(volid, fromserver, frompart, toserver, topart, flags);
2264 PrintDiagnostics("move", code);
2267 MapPartIdIntoName(topart, toPartName);
2268 MapPartIdIntoName(frompart, fromPartName);
2269 fprintf(STDOUT, "Volume %lu moved from %s %s to %s %s \n",
2270 (unsigned long)volid, as->parms[1].items->data, fromPartName,
2271 as->parms[3].items->data, toPartName);
2277 CopyVolume(register struct cmd_syndesc *as, void *arock)
2280 afs_int32 fromserver, toserver, frompart, topart, code, err, flags;
2281 char fromPartName[10], toPartName[10], *tovolume;
2282 struct nvldbentry entry;
2283 struct diskPartition64 partition; /* for space check */
2286 volid = vsu_GetVolumeID(as->parms[0].items->data, cstruct, &err);
2289 PrintError("", err);
2291 fprintf(STDERR, "vos: can't find volume ID or name '%s'\n",
2292 as->parms[0].items->data);
2295 fromserver = GetServer(as->parms[1].items->data);
2296 if (fromserver == 0) {
2297 fprintf(STDERR, "vos: server '%s' not found in host table\n",
2298 as->parms[1].items->data);
2302 toserver = GetServer(as->parms[4].items->data);
2303 if (toserver == 0) {
2304 fprintf(STDERR, "vos: server '%s' not found in host table\n",
2305 as->parms[4].items->data);
2309 tovolume = as->parms[3].items->data;
2310 if (!ISNAMEVALID(tovolume)) {
2312 "vos: the name of the root volume %s exceeds the size limit of %d\n",
2313 tovolume, VOLSER_OLDMAXVOLNAME - 10);
2316 if (!VolNameOK(tovolume)) {
2318 "Illegal volume name %s, should not end in .readonly or .backup\n",
2322 if (IsNumeric(tovolume)) {
2323 fprintf(STDERR, "Illegal volume name %s, should not be a number\n",
2327 code = VLDB_GetEntryByName(tovolume, &entry);
2329 fprintf(STDERR, "Volume %s already exists\n", tovolume);
2330 PrintDiagnostics("copy", code);
2334 frompart = volutil_GetPartitionID(as->parms[2].items->data);
2336 fprintf(STDERR, "vos: could not interpret partition name '%s'\n",
2337 as->parms[2].items->data);
2340 if (!IsPartValid(frompart, fromserver, &code)) { /*check for validity of the partition */
2342 PrintError("", code);
2345 "vos : partition %s does not exist on the server\n",
2346 as->parms[2].items->data);
2350 topart = volutil_GetPartitionID(as->parms[5].items->data);
2352 fprintf(STDERR, "vos: could not interpret partition name '%s'\n",
2353 as->parms[5].items->data);
2356 if (!IsPartValid(topart, toserver, &code)) { /*check for validity of the partition */
2358 PrintError("", code);
2361 "vos : partition %s does not exist on the server\n",
2362 as->parms[5].items->data);
2367 if (as->parms[6].items) flags |= RV_OFFLINE;
2368 if (as->parms[7].items) flags |= RV_RDONLY;
2369 if (as->parms[8].items) flags |= RV_NOCLONE;
2371 MapPartIdIntoName(topart, toPartName);
2372 MapPartIdIntoName(frompart, fromPartName);
2375 * check target partition for space to move volume
2378 code = UV_PartitionInfo64(toserver, toPartName, &partition);
2380 fprintf(STDERR, "vos: cannot access partition %s\n", toPartName);
2384 fprintf(STDOUT, "target partition %s free space %" AFS_INT64_FMT "\n", toPartName,
2387 p = (volintInfo *) 0;
2388 code = UV_ListOneVolume(fromserver, frompart, volid, &p);
2390 fprintf(STDERR, "vos:cannot access volume %lu\n",
2391 (unsigned long)volid);
2395 if (partition.free <= p->size) {
2397 "vos: no space on target partition %s to copy volume %lu\n",
2398 toPartName, (unsigned long)volid);
2404 /* successful copy still not guaranteed but shoot for it */
2407 UV_CopyVolume2(volid, fromserver, frompart, tovolume, toserver,
2410 PrintDiagnostics("copy", code);
2413 MapPartIdIntoName(topart, toPartName);
2414 MapPartIdIntoName(frompart, fromPartName);
2415 fprintf(STDOUT, "Volume %lu copied from %s %s to %s on %s %s \n",
2416 (unsigned long)volid, as->parms[1].items->data, fromPartName,
2417 tovolume, as->parms[4].items->data, toPartName);
2424 ShadowVolume(register struct cmd_syndesc *as, void *arock)
2426 afs_uint32 volid, tovolid;
2427 afs_int32 fromserver, toserver, frompart, topart;
2428 afs_int32 code, err, flags;
2429 char fromPartName[10], toPartName[10], toVolName[32], *tovolume;
2430 struct diskPartition64 partition; /* for space check */
2433 p = (volintInfo *) 0;
2434 q = (volintInfo *) 0;
2436 volid = vsu_GetVolumeID(as->parms[0].items->data, cstruct, &err);
2439 PrintError("", err);
2441 fprintf(STDERR, "vos: can't find volume ID or name '%s'\n",
2442 as->parms[0].items->data);
2445 fromserver = GetServer(as->parms[1].items->data);
2446 if (fromserver == 0) {
2447 fprintf(STDERR, "vos: server '%s' not found in host table\n",
2448 as->parms[1].items->data);
2452 toserver = GetServer(as->parms[3].items->data);
2453 if (toserver == 0) {
2454 fprintf(STDERR, "vos: server '%s' not found in host table\n",
2455 as->parms[3].items->data);
2459 frompart = volutil_GetPartitionID(as->parms[2].items->data);
2461 fprintf(STDERR, "vos: could not interpret partition name '%s'\n",
2462 as->parms[2].items->data);
2465 if (!IsPartValid(frompart, fromserver, &code)) { /*check for validity of the partition */
2467 PrintError("", code);
2470 "vos : partition %s does not exist on the server\n",
2471 as->parms[2].items->data);
2475 topart = volutil_GetPartitionID(as->parms[4].items->data);
2477 fprintf(STDERR, "vos: could not interpret partition name '%s'\n",
2478 as->parms[4].items->data);
2481 if (!IsPartValid(topart, toserver, &code)) { /*check for validity of the partition */
2483 PrintError("", code);
2486 "vos : partition %s does not exist on the server\n",
2487 as->parms[4].items->data);
2491 if (as->parms[5].items) {
2492 tovolume = as->parms[5].items->data;
2493 if (!ISNAMEVALID(tovolume)) {
2495 "vos: the name of the root volume %s exceeds the size limit of %d\n",
2496 tovolume, VOLSER_OLDMAXVOLNAME - 10);
2499 if (!VolNameOK(tovolume)) {
2501 "Illegal volume name %s, should not end in .readonly or .backup\n",
2505 if (IsNumeric(tovolume)) {
2507 "Illegal volume name %s, should not be a number\n",
2512 /* use actual name of source volume */
2513 code = UV_ListOneVolume(fromserver, frompart, volid, &p);
2515 fprintf(STDERR, "vos:cannot access volume %lu\n",
2516 (unsigned long)volid);
2519 strcpy(toVolName, p->name);
2520 tovolume = toVolName;
2521 /* save p for size checks later */
2524 if (as->parms[6].items) {
2525 tovolid = vsu_GetVolumeID(as->parms[6].items->data, cstruct, &err);
2528 PrintError("", err);
2530 fprintf(STDERR, "vos: can't find volume ID or name '%s'\n",
2531 as->parms[6].items->data);
2537 tovolid = vsu_GetVolumeID(tovolume, cstruct, &err);
2540 PrintError("", err);
2542 fprintf(STDERR, "vos: can't find volume ID or name '%s'\n",
2551 if (as->parms[7].items) flags |= RV_OFFLINE;
2552 if (as->parms[8].items) flags |= RV_RDONLY;
2553 if (as->parms[9].items) flags |= RV_NOCLONE;
2554 if (as->parms[10].items) flags |= RV_CPINCR;
2556 MapPartIdIntoName(topart, toPartName);
2557 MapPartIdIntoName(frompart, fromPartName);
2560 * check target partition for space to move volume
2563 code = UV_PartitionInfo64(toserver, toPartName, &partition);
2565 fprintf(STDERR, "vos: cannot access partition %s\n", toPartName);
2569 fprintf(STDOUT, "target partition %s free space %" AFS_INT64_FMT "\n", toPartName,
2572 /* Don't do this again if we did it above */
2574 code = UV_ListOneVolume(fromserver, frompart, volid, &p);
2576 fprintf(STDERR, "vos:cannot access volume %lu\n",
2577 (unsigned long)volid);
2582 /* OK if this fails */
2583 code = UV_ListOneVolume(toserver, topart, tovolid, &q);
2585 /* Treat existing volume size as "free" */
2587 p->size = (q->size < p->size) ? p->size - q->size : 0;
2589 if (partition.free <= p->size) {
2591 "vos: no space on target partition %s to copy volume %lu\n",
2592 toPartName, (unsigned long)volid);
2600 /* successful copy still not guaranteed but shoot for it */
2603 UV_CopyVolume2(volid, fromserver, frompart, tovolume, toserver,
2604 topart, tovolid, flags);
2606 PrintDiagnostics("shadow", code);
2609 MapPartIdIntoName(topart, toPartName);
2610 MapPartIdIntoName(frompart, fromPartName);
2611 fprintf(STDOUT, "Volume %lu shadowed from %s %s to %s %s \n",
2612 (unsigned long)volid, as->parms[1].items->data, fromPartName,
2613 as->parms[3].items->data, toPartName);
2620 CloneVolume(register struct cmd_syndesc *as, void *arock)
2622 afs_uint32 volid, cloneid;
2623 afs_int32 server, part, voltype;
2624 char partName[10], *volname;
2625 afs_int32 code, err, flags;
2626 struct nvldbentry entry;
2628 volid = vsu_GetVolumeID(as->parms[0].items->data, cstruct, &err);
2631 PrintError("", err);
2633 fprintf(STDERR, "vos: can't find volume ID or name '%s'\n",
2634 as->parms[0].items->data);
2638 if (as->parms[1].items || as->parms[2].items) {
2639 if (!as->parms[1].items || !as->parms[2].items) {
2641 "Must specify both -server and -partition options\n");
2644 server = GetServer(as->parms[1].items->data);
2646 fprintf(STDERR, "vos: server '%s' not found in host table\n",
2647 as->parms[1].items->data);
2650 part = volutil_GetPartitionID(as->parms[2].items->data);
2652 fprintf(STDERR, "vos: could not interpret partition name '%s'\n",
2653 as->parms[2].items->data);
2656 if (!IsPartValid(part, server, &code)) { /*check for validity of the partition */
2658 PrintError("", code);
2661 "vos : partition %s does not exist on the server\n",
2662 as->parms[2].items->data);
2666 code = GetVolumeInfo(volid, &server, &part, &voltype, &entry);
2672 if (as->parms[3].items) {
2673 volname = as->parms[3].items->data;
2674 if (strlen(volname) > VOLSER_OLDMAXVOLNAME - 1) {
2676 "vos: the name of the root volume %s exceeds the size limit of %d\n",
2677 volname, VOLSER_OLDMAXVOLNAME - 1);
2682 * In order that you be able to make clones of RO or BK, this
2683 * check must be omitted.
2685 if (!VolNameOK(volname)) {
2687 "Illegal volume name %s, should not end in .readonly or .backup\n",
2692 if (IsNumeric(volname)) {
2694 "Illegal volume name %s, should not be a number\n",
2701 if (as->parms[4].items) {
2702 cloneid = vsu_GetVolumeID(as->parms[4].items->data, cstruct, &err);
2705 PrintError("", err);
2707 fprintf(STDERR, "vos: can't find volume ID or name '%s'\n",
2708 as->parms[4].items->data);
2714 if (as->parms[5].items) flags |= RV_OFFLINE;
2715 if (as->parms[6].items) flags |= RV_RDONLY;
2719 UV_CloneVolume(server, part, volid, cloneid, volname, flags);
2722 PrintDiagnostics("clone", code);
2725 MapPartIdIntoName(part, partName);
2726 fprintf(STDOUT, "Created clone for volume %s\n",
2727 as->parms[0].items->data);
2734 BackupVolume(register struct cmd_syndesc *as, void *arock)
2737 afs_int32 aserver, apart, vtype, code, err;
2738 struct nvldbentry entry;
2741 afs_int32 buserver, bupart, butype;
2742 struct nvldbentry buentry;
2744 avolid = vsu_GetVolumeID(as->parms[0].items->data, cstruct, &err);
2747 PrintError("", err);
2749 fprintf(STDERR, "vos: can't find volume ID or name '%s'\n",
2750 as->parms[0].items->data);
2753 code = GetVolumeInfo(avolid, &aserver, &apart, &vtype, &entry);
2757 /* verify this is a readwrite volume */
2759 if (vtype != RWVOL) {
2760 fprintf(STDERR, "%s not RW volume\n", as->parms[0].items->data);
2764 /* is there a backup volume already? */
2766 if (entry.flags & BACK_EXISTS) {
2767 /* yep, where is it? */
2769 buvolid = entry.volumeId[BACKVOL];
2770 code = GetVolumeInfo(buvolid, &buserver, &bupart, &butype, &buentry);
2775 code = VLDB_IsSameAddrs(buserver, aserver, &err);
2778 "Failed to get info about server's %d address(es) from vlserver; aborting call!\n",
2784 "FATAL ERROR: backup volume %lu exists on server %lu\n",
2785 (unsigned long)buvolid, (unsigned long)buserver);
2790 /* nope, carry on */
2792 code = UV_BackupVolume(aserver, apart, avolid);
2795 PrintDiagnostics("backup", code);
2798 fprintf(STDOUT, "Created backup volume for %s \n",
2799 as->parms[0].items->data);
2804 ReleaseVolume(register struct cmd_syndesc *as, void *arock)
2807 struct nvldbentry entry;
2809 afs_int32 aserver, apart, vtype, code, err;
2812 if (as->parms[1].items)
2814 avolid = vsu_GetVolumeID(as->parms[0].items->data, cstruct, &err);
2817 PrintError("", err);
2819 fprintf(STDERR, "vos: can't find volume '%s'\n",
2820 as->parms[0].items->data);
2823 code = GetVolumeInfo(avolid, &aserver, &apart, &vtype, &entry);
2827 if (vtype != RWVOL) {
2828 fprintf(STDERR, "%s not a RW volume\n", as->parms[0].items->data);
2832 if (!ISNAMEVALID(entry.name)) {
2834 "Volume name %s is too long, rename before releasing\n",
2839 code = UV_ReleaseVolume(avolid, aserver, apart, force);
2841 PrintDiagnostics("release", code);
2844 fprintf(STDOUT, "Released volume %s successfully\n",
2845 as->parms[0].items->data);
2850 DumpVolumeCmd(register struct cmd_syndesc *as, void *arock)
2853 afs_int32 aserver, apart, voltype, fromdate = 0, code, err, i, flags;
2854 char filename[MAXPATHLEN];
2855 struct nvldbentry entry;
2857 rx_SetRxDeadTime(60 * 10);
2858 for (i = 0; i < MAXSERVERS; i++) {
2859 struct rx_connection *rxConn = ubik_GetRPCConn(cstruct, i);
2862 rx_SetConnDeadTime(rxConn, rx_connDeadTime);
2863 if (rxConn->service)
2864 rxConn->service->connDeadTime = rx_connDeadTime;
2867 avolid = vsu_GetVolumeID(as->parms[0].items->data, cstruct, &err);
2870 PrintError("", err);
2872 fprintf(STDERR, "vos: can't find volume '%s'\n",
2873 as->parms[0].items->data);
2877 if (as->parms[3].items || as->parms[4].items) {
2878 if (!as->parms[3].items || !as->parms[4].items) {
2880 "Must specify both -server and -partition options\n");
2883 aserver = GetServer(as->parms[3].items->data);
2885 fprintf(STDERR, "Invalid server name\n");
2888 apart = volutil_GetPartitionID(as->parms[4].items->data);
2890 fprintf(STDERR, "Invalid partition name\n");
2894 code = GetVolumeInfo(avolid, &aserver, &apart, &voltype, &entry);
2899 if (as->parms[1].items && strcmp(as->parms[1].items->data, "0")) {
2900 code = ktime_DateToInt32(as->parms[1].items->data, &fromdate);
2902 fprintf(STDERR, "vos: failed to parse date '%s' (error=%d))\n",
2903 as->parms[1].items->data, code);
2907 if (as->parms[2].items) {
2908 strcpy(filename, as->parms[2].items->data);
2910 strcpy(filename, "");
2913 flags = as->parms[6].items ? VOLDUMPV2_OMITDIRS : 0;
2915 if (as->parms[5].items) {
2917 UV_DumpClonedVolume(avolid, aserver, apart, fromdate,
2918 DumpFunction, filename, flags);
2921 UV_DumpVolume(avolid, aserver, apart, fromdate, DumpFunction,
2924 if ((code == RXGEN_OPCODE) && (as->parms[6].items)) {
2925 flags &= ~VOLDUMPV2_OMITDIRS;
2929 PrintDiagnostics("dump", code);
2932 if (strcmp(filename, ""))
2933 fprintf(STDERR, "Dumped volume %s in file %s\n",
2934 as->parms[0].items->data, filename);
2936 fprintf(STDERR, "Dumped volume %s in stdout \n",
2937 as->parms[0].items->data);
2951 RestoreVolumeCmd(register struct cmd_syndesc *as, void *arock)
2953 afs_uint32 avolid, aparentid;
2954 afs_int32 aserver, apart, code, vcode, err;
2955 afs_int32 aoverwrite = ASK;
2956 afs_int32 acreation = 0, alastupdate = 0;
2957 int restoreflags = 0;
2958 int readonly = 0, offline = 0, voltype = RWVOL;
2960 char afilename[MAXPATHLEN], avolname[VOLSER_MAXVOLNAME + 1], apartName[10];
2961 char volname[VOLSER_MAXVOLNAME + 1];
2962 struct nvldbentry entry;
2967 if (as->parms[4].items) {
2968 avolid = vsu_GetVolumeID(as->parms[4].items->data, cstruct, &err);
2971 PrintError("", err);
2973 fprintf(STDERR, "vos: can't find volume '%s'\n",
2974 as->parms[4].items->data);
2980 if (as->parms[5].items) {
2981 if ((strcmp(as->parms[5].items->data, "a") == 0)
2982 || (strcmp(as->parms[5].items->data, "abort") == 0)) {
2984 } else if ((strcmp(as->parms[5].items->data, "f") == 0)
2985 || (strcmp(as->parms[5].items->data, "full") == 0)) {
2987 } else if ((strcmp(as->parms[5].items->data, "i") == 0)
2988 || (strcmp(as->parms[5].items->data, "inc") == 0)
2989 || (strcmp(as->parms[5].items->data, "increment") == 0)
2990 || (strcmp(as->parms[5].items->data, "incremental") == 0)) {
2993 fprintf(STDERR, "vos: %s is not a valid argument to -overwrite\n",
2994 as->parms[5].items->data);
2998 if (as->parms[6].items)
3000 if (as->parms[7].items) {
3005 if (as->parms[8].items) {
3006 if ((strcmp(as->parms[8].items->data, "d") == 0)
3007 || (strcmp(as->parms[8].items->data, "dump") == 0)) {
3008 acreation = TS_DUMP;
3009 } else if ((strcmp(as->parms[8].items->data, "k") == 0)
3010 || (strcmp(as->parms[8].items->data, "keep") == 0)) {
3011 acreation = TS_KEEP;
3012 } else if ((strcmp(as->parms[8].items->data, "n") == 0)
3013 || (strcmp(as->parms[8].items->data, "new") == 0)) {
3016 fprintf(STDERR, "vos: %s is not a valid argument to -creation\n",
3017 as->parms[8].items->data);
3022 if (as->parms[9].items) {
3023 if ((strcmp(as->parms[9].items->data, "d") == 0)
3024 || (strcmp(as->parms[9].items->data, "dump") == 0)) {
3025 alastupdate = TS_DUMP;
3026 } else if ((strcmp(as->parms[9].items->data, "k") == 0)
3027 || (strcmp(as->parms[9].items->data, "keep") == 0)) {
3028 alastupdate = TS_KEEP;
3029 } else if ((strcmp(as->parms[9].items->data, "n") == 0)
3030 || (strcmp(as->parms[9].items->data, "new") == 0)) {
3031 alastupdate = TS_NEW;
3033 fprintf(STDERR, "vos: %s is not a valid argument to -lastupdate\n",
3034 as->parms[9].items->data);
3039 aserver = GetServer(as->parms[0].items->data);
3041 fprintf(STDERR, "vos: server '%s' not found in host table\n",
3042 as->parms[0].items->data);
3045 apart = volutil_GetPartitionID(as->parms[1].items->data);
3047 fprintf(STDERR, "vos: could not interpret partition name '%s'\n",
3048 as->parms[1].items->data);
3051 if (!IsPartValid(apart, aserver, &code)) { /*check for validity of the partition */
3053 PrintError("", code);
3056 "vos : partition %s does not exist on the server\n",
3057 as->parms[1].items->data);
3060 strcpy(avolname, as->parms[2].items->data);
3061 if (!ISNAMEVALID(avolname)) {
3063 "vos: the name of the volume %s exceeds the size limit\n",
3067 if (!VolNameOK(avolname)) {
3069 "Illegal volume name %s, should not end in .readonly or .backup\n",
3073 if (as->parms[3].items) {
3074 strcpy(afilename, as->parms[3].items->data);
3075 if (!FileExists(afilename)) {
3076 fprintf(STDERR, "Can't access file %s\n", afilename);
3080 strcpy(afilename, "");
3083 /* Check if volume exists or not */
3085 vsu_ExtractName(volname, avolname);
3086 vcode = VLDB_GetEntryByName(volname, &entry);
3087 if (vcode) { /* no volume - do a full restore */
3088 restoreflags = RV_FULLRST;
3089 if ((aoverwrite == INC) || (aoverwrite == ABORT))
3091 "Volume does not exist; Will perform a full restore\n");
3094 else if ((!readonly && Lp_GetRwIndex(&entry) == -1) /* RW volume does not exist - do a full */
3095 ||(readonly && !Lp_ROMatch(0, 0, &entry))) { /* RO volume does not exist - do a full */
3096 restoreflags = RV_FULLRST;
3097 if ((aoverwrite == INC) || (aoverwrite == ABORT))
3099 "%s Volume does not exist; Will perform a full restore\n",
3100 readonly ? "RO" : "RW");
3103 avolid = entry.volumeId[voltype];
3104 } else if (entry.volumeId[voltype] != 0
3105 && entry.volumeId[voltype] != avolid) {
3106 avolid = entry.volumeId[voltype];
3108 aparentid = entry.volumeId[RWVOL];
3111 else { /* volume exists - do we do a full incremental or abort */
3112 int Oserver, Opart, Otype, vol_elsewhere = 0;
3113 struct nvldbentry Oentry;
3117 avolid = entry.volumeId[voltype];
3118 } else if (entry.volumeId[voltype] != 0
3119 && entry.volumeId[voltype] != avolid) {
3120 avolid = entry.volumeId[voltype];
3122 aparentid = entry.volumeId[RWVOL];
3124 /* A file name was specified - check if volume is on another partition */
3125 vcode = GetVolumeInfo(avolid, &Oserver, &Opart, &Otype, &Oentry);
3129 vcode = VLDB_IsSameAddrs(Oserver, aserver, &err);
3132 "Failed to get info about server's %d address(es) from vlserver (err=%d); aborting call!\n",
3136 if (!vcode || (Opart != apart))
3139 if (aoverwrite == ASK) {
3140 if (strcmp(afilename, "") == 0) { /* The file is from standard in */
3142 "Volume exists and no -overwrite option specified; Aborting restore command\n");
3146 /* Ask what to do */
3147 if (vol_elsewhere) {
3149 "The volume %s %u already exists on a different server/part\n",
3150 volname, entry.volumeId[voltype]);
3152 "Do you want to do a full restore or abort? [fa](a): ");
3155 "The volume %s %u already exists in the VLDB\n",
3156 volname, entry.volumeId[voltype]);
3158 "Do you want to do a full/incremental restore or abort? [fia](a): ");
3161 while (!(dc == EOF || dc == '\n'))
3162 dc = getchar(); /* goto end of line */
3163 if ((c == 'f') || (c == 'F'))
3165 else if ((c == 'i') || (c == 'I'))
3171 if (aoverwrite == ABORT) {
3172 fprintf(STDERR, "Volume exists; Aborting restore command\n");
3174 } else if (aoverwrite == FULL) {
3175 restoreflags = RV_FULLRST;
3177 "Volume exists; Will delete and perform full restore\n");
3178 } else if (aoverwrite == INC) {
3180 if (vol_elsewhere) {
3182 "%s volume %lu already exists on a different server/part; not allowed\n",
3183 readonly ? "RO" : "RW", (unsigned long)avolid);
3189 restoreflags |= RV_OFFLINE;
3191 restoreflags |= RV_RDONLY;
3193 switch (acreation) {
3195 restoreflags |= RV_CRDUMP;
3198 restoreflags |= RV_CRKEEP;
3201 restoreflags |= RV_CRNEW;
3204 if (aoverwrite == FULL)
3205 restoreflags |= RV_CRNEW;
3207 restoreflags |= RV_CRKEEP;
3210 switch (alastupdate) {
3212 restoreflags |= RV_LUDUMP;
3215 restoreflags |= RV_LUKEEP;
3218 restoreflags |= RV_LUNEW;
3221 restoreflags |= RV_LUDUMP;
3223 if (as->parms[10].items) {
3224 restoreflags |= RV_NODEL;
3229 UV_RestoreVolume2(aserver, apart, avolid, aparentid,
3230 avolname, restoreflags, WriteData, afilename);
3232 PrintDiagnostics("restore", code);
3235 MapPartIdIntoName(apart, apartName);
3238 * patch typo here - originally "parms[1]", should be "parms[0]"
3241 fprintf(STDOUT, "Restored volume %s on %s %s\n", avolname,
3242 as->parms[0].items->data, apartName);
3247 LockReleaseCmd(register struct cmd_syndesc *as, void *arock)
3250 afs_int32 code, err;
3252 avolid = vsu_GetVolumeID(as->parms[0].items->data, cstruct, &err);
3255 PrintError("", err);
3257 fprintf(STDERR, "vos: can't find volume '%s'\n",
3258 as->parms[0].items->data);
3262 code = UV_LockRelease(avolid);
3264 PrintDiagnostics("unlock", code);
3267 fprintf(STDOUT, "Released lock on vldb entry for volume %s\n",
3268 as->parms[0].items->data);
3273 AddSite(register struct cmd_syndesc *as, void *arock)
3276 afs_int32 aserver, apart, code, err, arovolid, valid = 0;
3277 char apartName[10], avolname[VOLSER_MAXVOLNAME + 1];
3279 vsu_ExtractName(avolname, as->parms[2].items->data);;
3280 avolid = vsu_GetVolumeID(avolname, cstruct, &err);
3283 PrintError("", err);
3285 fprintf(STDERR, "vos: can't find volume '%s'\n",
3286 as->parms[2].items->data);
3290 if (as->parms[3].items) {
3291 vsu_ExtractName(avolname, as->parms[3].items->data);
3292 arovolid = vsu_GetVolumeID(avolname, cstruct, &err);
3294 fprintf(STDERR, "vos: invalid ro volume id '%s'\n",
3295 as->parms[3].items->data);
3299 aserver = GetServer(as->parms[0].items->data);
3301 fprintf(STDERR, "vos: server '%s' not found in host table\n",
3302 as->parms[0].items->data);
3305 apart = volutil_GetPartitionID(as->parms[1].items->data);
3307 fprintf(STDERR, "vos: could not interpret partition name '%s'\n",
3308 as->parms[1].items->data);
3311 if (!IsPartValid(apart, aserver, &code)) { /*check for validity of the partition */
3313 PrintError("", code);
3316 "vos : partition %s does not exist on the server\n",
3317 as->parms[1].items->data);
3320 if (as->parms[4].items) {
3323 code = UV_AddSite2(aserver, apart, avolid, arovolid, valid);
3325 PrintDiagnostics("addsite", code);
3328 MapPartIdIntoName(apart, apartName);
3329 fprintf(STDOUT, "Added replication site %s %s for volume %s\n",
3330 as->parms[0].items->data, apartName, as->parms[2].items->data);
3335 RemoveSite(register struct cmd_syndesc *as, void *arock)
3339 afs_int32 aserver, apart, code, err;
3340 char apartName[10], avolname[VOLSER_MAXVOLNAME + 1];
3342 vsu_ExtractName(avolname, as->parms[2].items->data);
3343 avolid = vsu_GetVolumeID(avolname, cstruct, &err);
3346 PrintError("", err);
3348 fprintf(STDERR, "vos: can't find volume '%s'\n",
3349 as->parms[2].items->data);
3352 aserver = GetServer(as->parms[0].items->data);
3354 fprintf(STDERR, "vos: server '%s' not found in host table\n",
3355 as->parms[0].items->data);
3358 apart = volutil_GetPartitionID(as->parms[1].items->data);
3360 fprintf(STDERR, "vos: could not interpret partition name '%s'\n",
3361 as->parms[1].items->data);
3365 *skip the partition validity check, since it is possible that the partition
3366 *has since been decomissioned.
3369 if (!IsPartValid(apart,aserver,&code)){
3370 if(code) PrintError("",code);
3371 else fprintf(STDERR,"vos : partition %s does not exist on the server\n",as->parms[1].items->data);
3375 code = UV_RemoveSite(aserver, apart, avolid);
3377 PrintDiagnostics("remsite", code);
3380 MapPartIdIntoName(apart, apartName);
3381 fprintf(STDOUT, "Removed replication site %s %s for volume %s\n",
3382 as->parms[0].items->data, apartName, as->parms[2].items->data);
3387 ChangeLocation(register struct cmd_syndesc *as, void *arock)
3390 afs_int32 aserver, apart, code, err;
3393 avolid = vsu_GetVolumeID(as->parms[2].items->data, cstruct, &err);
3396 PrintError("", err);
3398 fprintf(STDERR, "vos: can't find volume '%s'\n",
3399 as->parms[2].items->data);
3402 aserver = GetServer(as->parms[0].items->data);
3404 fprintf(STDERR, "vos: server '%s' not found in host table\n",
3405 as->parms[0].items->data);
3408 apart = volutil_GetPartitionID(as->parms[1].items->data);
3410 fprintf(STDERR, "vos: could not interpret partition name '%s'\n",
3411 as->parms[1].items->data);
3414 if (!IsPartValid(apart, aserver, &code)) { /*check for validity of the partition */
3416 PrintError("", code);
3419 "vos : partition %s does not exist on the server\n",
3420 as->parms[1].items->data);
3423 code = UV_ChangeLocation(aserver, apart, avolid);
3425 PrintDiagnostics("addsite", code);
3428 MapPartIdIntoName(apart, apartName);
3429 fprintf(STDOUT, "Changed location to %s %s for volume %s\n",
3430 as->parms[0].items->data, apartName, as->parms[2].items->data);
3435 ListPartitions(register struct cmd_syndesc *as, void *arock)
3437 afs_int32 aserver, code;
3438 struct partList dummyPartList;
3443 aserver = GetServer(as->parms[0].items->data);
3445 fprintf(STDERR, "vos: server '%s' not found in host table\n",
3446 as->parms[0].items->data);
3451 code = UV_ListPartitions(aserver, &dummyPartList, &cnt);
3453 PrintDiagnostics("listpart", code);
3457 fprintf(STDOUT, "The partitions on the server are:\n");
3458 for (i = 0; i < cnt; i++) {
3459 if (dummyPartList.partFlags[i] & PARTVALID) {
3460 memset(pname, 0, sizeof(pname));
3461 MapPartIdIntoName(dummyPartList.partId[i], pname);
3462 fprintf(STDOUT, " %10s ", pname);
3464 if ((i % 5) == 0 && (i != 0))
3465 fprintf(STDOUT, "\n");
3468 fprintf(STDOUT, "\n");
3469 fprintf(STDOUT, "Total: %d\n", total);
3475 CompareVolName(const void *p1, const void *p2)
3477 volintInfo *arg1, *arg2;
3479 arg1 = (volintInfo *) p1;
3480 arg2 = (volintInfo *) p2;
3481 return (strcmp(arg1->name, arg2->name));
3485 /*------------------------------------------------------------------------
3486 * PRIVATE XCompareVolName
3489 * Comparison routine for volume names coming from an extended
3493 * a_obj1P : Char ptr to first extended vol info object
3494 * a_obj1P : Char ptr to second extended vol info object
3497 * The value of strcmp() on the volume names within the passed
3498 * objects (i,e., -1, 0, or 1).
3501 * Passed to qsort() as the designated comparison routine.
3505 *------------------------------------------------------------------------*/
3508 XCompareVolName(const void *a_obj1P, const void *a_obj2P)
3509 { /*XCompareVolName */
3512 (((struct volintXInfo *)(a_obj1P))->name,
3513 ((struct volintXInfo *)(a_obj2P))->name));
3515 } /*XCompareVolName */
3518 CompareVolID(const void *p1, const void *p2)
3520 volintInfo *arg1, *arg2;
3522 arg1 = (volintInfo *) p1;
3523 arg2 = (volintInfo *) p2;
3524 if (arg1->volid == arg2->volid)
3526 if (arg1->volid > arg2->volid)
3533 /*------------------------------------------------------------------------
3534 * PRIVATE XCompareVolID
3537 * Comparison routine for volume IDs coming from an extended
3541 * a_obj1P : Char ptr to first extended vol info object
3542 * a_obj1P : Char ptr to second extended vol info object
3545 * The value of strcmp() on the volume names within the passed
3546 * objects (i,e., -1, 0, or 1).
3549 * Passed to qsort() as the designated comparison routine.
3553 *------------------------------------------------------------------------*/
3556 XCompareVolID(const void *a_obj1P, const void *a_obj2P)
3557 { /*XCompareVolID */
3559 afs_int32 id1, id2; /*Volume IDs we're comparing */
3561 id1 = ((struct volintXInfo *)(a_obj1P))->volid;
3562 id2 = ((struct volintXInfo *)(a_obj2P))->volid;
3570 } /*XCompareVolID */
3572 /*------------------------------------------------------------------------
3573 * PRIVATE ListVolumes
3576 * Routine used to list volumes, contacting the Volume Server
3577 * directly, bypassing the VLDB.
3580 * as : Ptr to parsed command line arguments.
3583 * 0 Successful operation
3586 * Nothing interesting.
3590 *------------------------------------------------------------------------*/
3593 ListVolumes(register struct cmd_syndesc *as, void *arock)
3595 afs_int32 apart, int32list, fast;
3596 afs_int32 aserver, code;
3598 volintInfo *oldpntr = NULL;
3602 volintXInfo *xInfoP;
3603 volintXInfo *origxInfoP = NULL; /*Ptr to current/orig extended vol info */
3604 int wantExtendedInfo; /*Do we want extended vol info? */
3607 struct partList dummyPartList;
3615 if (as->parms[3].items)
3617 if (as->parms[4].items)
3621 if (as->parms[2].items)
3627 if (as->parms[5].items) {
3629 * We can't coexist with the fast flag.
3633 "vos: Can't use the -fast and -extended flags together\n");
3638 * We need to turn on ``long'' listings to get the full effect.
3640 wantExtendedInfo = 1;
3643 wantExtendedInfo = 0;
3644 if (as->parms[1].items) {
3645 apart = volutil_GetPartitionID(as->parms[1].items->data);
3647 fprintf(STDERR, "vos: could not interpret partition name '%s'\n",
3648 as->parms[1].items->data);
3651 dummyPartList.partId[0] = apart;
3652 dummyPartList.partFlags[0] = PARTVALID;
3655 aserver = GetServer(as->parms[0].items->data);
3657 fprintf(STDERR, "vos: server '%s' not found in host table\n",
3658 as->parms[0].items->data);
3663 if (!IsPartValid(apart, aserver, &code)) { /*check for validity of the partition */
3665 PrintError("", code);
3668 "vos : partition %s does not exist on the server\n",
3669 as->parms[1].items->data);
3673 code = UV_ListPartitions(aserver, &dummyPartList, &cnt);
3675 PrintDiagnostics("listvol", code);
3679 for (i = 0; i < cnt; i++) {
3680 if (dummyPartList.partFlags[i] & PARTVALID) {
3681 if (wantExtendedInfo)
3683 UV_XListVolumes(aserver, dummyPartList.partId[i], all,
3687 UV_ListVolumes(aserver, dummyPartList.partId[i], all,
3690 PrintDiagnostics("listvol", code);
3695 if (wantExtendedInfo) {
3696 origxInfoP = xInfoP;
3697 base = (char *)xInfoP;
3700 base = (char *)pntr;
3704 if (wantExtendedInfo)
3705 qsort(base, count, sizeof(volintXInfo), XCompareVolName);
3707 qsort(base, count, sizeof(volintInfo), CompareVolName);
3709 if (wantExtendedInfo)
3710 qsort(base, count, sizeof(volintXInfo), XCompareVolID);
3712 qsort(base, count, sizeof(volintInfo), CompareVolID);
3714 MapPartIdIntoName(dummyPartList.partId[i], pname);
3717 "Total number of volumes on server %s partition %s: %lu \n",
3718 as->parms[0].items->data, pname,
3719 (unsigned long)count);
3720 if (wantExtendedInfo) {
3721 if (as->parms[6].items)
3722 XDisplayVolumes2(aserver, dummyPartList.partId[i], origxInfoP,
3723 count, int32list, fast, quiet);
3725 XDisplayVolumes(aserver, dummyPartList.partId[i], origxInfoP,
3726 count, int32list, fast, quiet);
3729 xInfoP = (volintXInfo *) 0;
3731 if (as->parms[6].items)
3732 DisplayVolumes2(aserver, dummyPartList.partId[i], oldpntr,
3735 DisplayVolumes(aserver, dummyPartList.partId[i], oldpntr,
3736 count, int32list, fast, quiet);
3739 pntr = (volintInfo *) 0;
3747 SyncVldb(register struct cmd_syndesc *as, void *arock)
3749 afs_int32 pnum = 0, code; /* part name */
3755 if (as->parms[0].items) {
3756 tserver = GetServer(as->parms[0].items->data);
3758 fprintf(STDERR, "vos: host '%s' not found in host table\n",
3759 as->parms[0].items->data);
3764 if (as->parms[1].items) {
3765 pnum = volutil_GetPartitionID(as->parms[1].items->data);
3767 fprintf(STDERR, "vos: could not interpret partition name '%s'\n",
3768 as->parms[1].items->data);
3771 if (!IsPartValid(pnum, tserver, &code)) { /*check for validity of the partition */
3773 PrintError("", code);
3776 "vos: partition %s does not exist on the server\n",
3777 as->parms[1].items->data);
3784 "The -partition option requires a -server option\n");
3789 if (as->parms[3].items) {
3790 flags |= 2; /* don't update */
3793 if (as->parms[2].items) {
3794 /* Synchronize an individual volume */
3795 volname = as->parms[2].items->data;
3796 code = UV_SyncVolume(tserver, pnum, volname, flags);
3800 "Without a -volume option, the -server option is required\n");
3803 code = UV_SyncVldb(tserver, pnum, flags, 0 /*unused */ );
3807 PrintDiagnostics("syncvldb", code);
3811 /* Print a summary of what we did */
3813 fprintf(STDOUT, "VLDB volume %s synchronized", volname);
3815 fprintf(STDOUT, "VLDB synchronized");
3817 fprintf(STDOUT, " with state of server %s", as->parms[0].items->data);
3820 MapPartIdIntoName(pnum, part);
3821 fprintf(STDOUT, " partition %s\n", part);
3823 fprintf(STDOUT, "\n");
3829 SyncServer(register struct cmd_syndesc *as, void *arock)
3831 afs_int32 pnum, code; /* part name */
3836 tserver = GetServer(as->parms[0].items->data);
3838 fprintf(STDERR, "vos: host '%s' not found in host table\n",
3839 as->parms[0].items->data);
3842 if (as->parms[1].items) {
3843 pnum = volutil_GetPartitionID(as->parms[1].items->data);
3845 fprintf(STDERR, "vos: could not interpret partition name '%s'\n",
3846 as->parms[1].items->data);
3849 if (!IsPartValid(pnum, tserver, &code)) { /*check for validity of the partition */
3851 PrintError("", code);
3854 "vos : partition %s does not exist on the server\n",
3855 as->parms[1].items->data);
3863 if (as->parms[2].items) {
3864 flags |= 2; /* don't update */
3866 code = UV_SyncServer(tserver, pnum, flags, 0 /*unused */ );
3868 PrintDiagnostics("syncserv", code);
3872 MapPartIdIntoName(pnum, part);
3873 fprintf(STDOUT, "Server %s partition %s synchronized with VLDB\n",
3874 as->parms[0].items->data, part);
3876 fprintf(STDOUT, "Server %s synchronized with VLDB\n",
3877 as->parms[0].items->data);
3883 VolumeInfoCmd(char *name)
3885 struct nvldbentry entry;
3888 /* The vlserver will handle names with the .readonly
3889 * and .backup extension as well as volume ids.
3891 vcode = VLDB_GetEntryByName(name, &entry);
3893 PrintError("", vcode);
3896 MapHostToNetwork(&entry);
3897 EnumerateEntry(&entry);
3899 /* Defect #3027: grubby check to handle locked volume.
3900 * If VLOP_ALLOPERS is set, the entry is locked.
3901 * Leave this routine as is, but put in correct check.
3903 if (entry.flags & VLOP_ALLOPERS)
3904 fprintf(STDOUT, " Volume is currently LOCKED \n");
3910 VolumeZap(register struct cmd_syndesc *as, void *arock)
3912 struct nvldbentry entry;
3913 afs_uint32 volid, zapbackupid = 0, backupid = 0;
3914 afs_int32 code, server, part, err;
3916 if (as->parms[3].items) {
3917 /* force flag is on, use the other version */
3918 return NukeVolume(as);
3921 if (as->parms[4].items) {
3925 volid = vsu_GetVolumeID(as->parms[2].items->data, cstruct, &err);
3928 PrintError("", err);
3930 fprintf(STDERR, "vos: can't find volume '%s'\n",
3931 as->parms[2].items->data);
3934 part = volutil_GetPartitionID(as->parms[1].items->data);
3936 fprintf(STDERR, "vos: could not interpret partition name '%s'\n",
3937 as->parms[1].items->data);
3940 server = GetServer(as->parms[0].items->data);
3942 fprintf(STDERR, "vos: host '%s' not found in host table\n",
3943 as->parms[0].items->data);
3946 if (!IsPartValid(part, server, &code)) { /*check for validity of the partition */
3948 PrintError("", code);
3951 "vos : partition %s does not exist on the server\n",
3952 as->parms[1].items->data);
3955 code = VLDB_GetEntryByID(volid, -1, &entry);
3957 if (volid == entry.volumeId[RWVOL])
3958 backupid = entry.volumeId[BACKVOL];
3960 "Warning: Entry for volume number %lu exists in VLDB (but we're zapping it anyway!)\n",
3961 (unsigned long)volid);
3964 volintInfo *pntr = (volintInfo *) 0;
3967 code = UV_ListOneVolume(server, part, volid, &pntr);
3969 if (volid == pntr->parentID)
3970 backupid = pntr->backupID;
3976 code = UV_VolumeZap(server, part, backupid);
3978 PrintDiagnostics("zap", code);
3981 fprintf(STDOUT, "Backup Volume %lu deleted\n",
3982 (unsigned long)backupid);
3985 code = UV_VolumeZap(server, part, volid);
3987 PrintDiagnostics("zap", code);
3990 fprintf(STDOUT, "Volume %lu deleted\n", (unsigned long)volid);
3996 VolserStatus(register struct cmd_syndesc *as, void *arock)
3998 afs_int32 server, code;
3999 transDebugInfo *pntr, *oldpntr;
4005 server = GetServer(as->parms[0].items->data);
4007 fprintf(STDERR, "vos: host '%s' not found in host table\n",
4008 as->parms[0].items->data);
4011 code = UV_VolserStatus(server, &pntr, &count);
4013 PrintDiagnostics("status", code);
4018 fprintf(STDOUT, "No active transactions on %s\n",
4019 as->parms[0].items->data);
4021 fprintf(STDOUT, "Total transactions: %d\n", count);
4023 for (i = 0; i < count; i++) {
4024 /*print out the relevant info */
4025 fprintf(STDOUT, "--------------------------------------\n");
4027 fprintf(STDOUT, "transaction: %lu created: %s",
4028 (unsigned long)pntr->tid, ctime(&t));
4029 if (pntr->returnCode) {
4030 fprintf(STDOUT, "returnCode: %lu\n",
4031 (unsigned long)pntr->returnCode);
4034 fprintf(STDOUT, "attachFlags: ");
4035 switch (pntr->iflags) {
4037 fprintf(STDOUT, "offline ");
4040 fprintf(STDOUT, "busy ");
4043 fprintf(STDOUT, "readonly ");
4046 fprintf(STDOUT, "create ");
4049 fprintf(STDOUT, "create volid ");
4052 fprintf(STDOUT, "\n");
4055 fprintf(STDOUT, "volumeStatus: ");
4056 switch (pntr->vflags) {
4057 case VTDeleteOnSalvage:
4058 fprintf(STDOUT, "deleteOnSalvage ");
4059 case VTOutOfService:
4060 fprintf(STDOUT, "outOfService ");
4062 fprintf(STDOUT, "deleted ");
4064 fprintf(STDOUT, "\n");
4067 fprintf(STDOUT, "transactionFlags: ");
4068 fprintf(STDOUT, "delete\n");
4070 MapPartIdIntoName(pntr->partition, pname);
4071 fprintf(STDOUT, "volume: %lu partition: %s procedure: %s\n",
4072 (unsigned long)pntr->volid, pname, pntr->lastProcName);
4073 if (pntr->callValid) {
4075 "packetRead: %lu lastReceiveTime: %d packetSend: %lu lastSendTime: %d\n",
4076 (unsigned long)pntr->readNext, pntr->lastReceiveTime,
4077 (unsigned long)pntr->transmitNext, pntr->lastSendTime);
4080 fprintf(STDOUT, "--------------------------------------\n");
4081 fprintf(STDOUT, "\n");
4089 RenameVolume(register struct cmd_syndesc *as, void *arock)
4091 afs_int32 code1, code2, code;
4092 struct nvldbentry entry;
4094 code1 = VLDB_GetEntryByName(as->parms[0].items->data, &entry);
4096 fprintf(STDERR, "vos: Could not find entry for volume %s\n",
4097 as->parms[0].items->data);
4100 code2 = VLDB_GetEntryByName(as->parms[1].items->data, &entry);
4101 if ((!code1) && (!code2)) { /*the newname already exists */
4102 fprintf(STDERR, "vos: volume %s already exists\n",
4103 as->parms[1].items->data);
4107 if (code1 && code2) {
4108 fprintf(STDERR, "vos: Could not find entry for volume %s or %s\n",
4109 as->parms[0].items->data, as->parms[1].items->data);
4112 if (!VolNameOK(as->parms[0].items->data)) {
4114 "Illegal volume name %s, should not end in .readonly or .backup\n",
4115 as->parms[0].items->data);
4118 if (!ISNAMEVALID(as->parms[1].items->data)) {
4120 "vos: the new volume name %s exceeds the size limit of %d\n",
4121 as->parms[1].items->data, VOLSER_OLDMAXVOLNAME - 10);
4124 if (!VolNameOK(as->parms[1].items->data)) {
4126 "Illegal volume name %s, should not end in .readonly or .backup\n",
4127 as->parms[1].items->data);
4130 if (IsNumeric(as->parms[1].items->data)) {
4131 fprintf(STDERR, "Illegal volume name %s, should not be a number\n",
4132 as->parms[1].items->data);
4135 MapHostToNetwork(&entry);
4137 UV_RenameVolume(&entry, as->parms[0].items->data,
4138 as->parms[1].items->data);
4140 PrintDiagnostics("rename", code);
4143 fprintf(STDOUT, "Renamed volume %s to %s\n", as->parms[0].items->data,
4144 as->parms[1].items->data);
4149 GetVolumeInfo(afs_uint32 volid, afs_int32 *server, afs_int32 *part, afs_int32 *voltype,
4150 struct nvldbentry *rentry)
4155 vcode = VLDB_GetEntryByID(volid, -1, rentry);
4158 "Could not fetch the entry for volume %lu from VLDB \n",
4159 (unsigned long)volid);
4160 PrintError("", vcode);
4163 MapHostToNetwork(rentry);
4164 if (volid == rentry->volumeId[ROVOL]) {
4166 for (i = 0; i < rentry->nServers; i++) {
4167 if ((index == -1) && (rentry->serverFlags[i] & ITSROVOL)
4168 && !(rentry->serverFlags[i] & RO_DONTUSE))
4173 "RO volume is not found in VLDB entry for volume %lu\n",
4174 (unsigned long)volid);
4178 *server = rentry->serverNumber[index];
4179 *part = rentry->serverPartition[index];
4183 index = Lp_GetRwIndex(rentry);
4186 "RW Volume is not found in VLDB entry for volume %lu\n",
4187 (unsigned long)volid);
4190 if (volid == rentry->volumeId[RWVOL]) {
4192 *server = rentry->serverNumber[index];
4193 *part = rentry->serverPartition[index];
4196 if (volid == rentry->volumeId[BACKVOL]) {
4198 *server = rentry->serverNumber[index];
4199 *part = rentry->serverPartition[index];
4203 "unexpected volume type for volume %lu\n",
4204 (unsigned long)volid);
4209 DeleteEntry(register struct cmd_syndesc *as, void *arock)
4211 afs_int32 apart = 0;
4214 struct VldbListByAttributes attributes;
4215 nbulkentries arrayEntries;
4216 register struct nvldbentry *vllist;
4217 struct cmd_item *itp;
4220 char prefix[VOLSER_MAXVOLNAME + 1];
4222 afs_int32 totalBack = 0, totalFail = 0, err;
4224 if (as->parms[0].items) { /* -id */
4225 if (as->parms[1].items || as->parms[2].items || as->parms[3].items) {
4227 "You cannot use -server, -partition, or -prefix with the -id argument\n");
4230 for (itp = as->parms[0].items; itp; itp = itp->next) {
4231 avolid = vsu_GetVolumeID(itp->data, cstruct, &err);
4234 PrintError("", err);
4236 fprintf(STDERR, "vos: can't find volume '%s'\n",
4240 if (as->parms[4].items) { /* -noexecute */
4241 fprintf(STDOUT, "Would have deleted VLDB entry for %s \n",
4246 vcode = ubik_VL_DeleteEntry(cstruct, 0, avolid, RWVOL);
4248 fprintf(STDERR, "Could not delete entry for volume %s\n",
4251 "You must specify a RW volume name or ID "
4252 "(the entire VLDB entry will be deleted)\n");
4253 PrintError("", vcode);
4259 fprintf(STDOUT, "Deleted %d VLDB entries\n", totalBack);
4263 if (!as->parms[1].items && !as->parms[2].items && !as->parms[3].items) {
4264 fprintf(STDERR, "You must specify an option\n");
4268 /* Zero out search attributes */
4269 memset(&attributes, 0, sizeof(struct VldbListByAttributes));
4271 if (as->parms[1].items) { /* -prefix */
4272 strncpy(prefix, as->parms[1].items->data, VOLSER_MAXVOLNAME);
4274 if (!as->parms[2].items && !as->parms[3].items) { /* a single entry only */
4276 "You must provide -server with the -prefix argument\n");
4281 if (as->parms[2].items) { /* -server */
4283 aserver = GetServer(as->parms[2].items->data);
4285 fprintf(STDERR, "vos: server '%s' not found in host table\n",
4286 as->parms[2].items->data);
4289 attributes.server = ntohl(aserver);
4290 attributes.Mask |= VLLIST_SERVER;
4293 if (as->parms[3].items) { /* -partition */
4294 if (!as->parms[2].items) {
4296 "You must provide -server with the -partition argument\n");
4299 apart = volutil_GetPartitionID(as->parms[3].items->data);
4301 fprintf(STDERR, "vos: could not interpret partition name '%s'\n",
4302 as->parms[3].items->data);
4305 attributes.partition = apart;
4306 attributes.Mask |= VLLIST_PARTITION;
4309 /* Print status line of what we are doing */
4310 fprintf(STDOUT, "Deleting VLDB entries for ");
4311 if (as->parms[2].items) {
4312 fprintf(STDOUT, "server %s ", as->parms[2].items->data);
4314 if (as->parms[3].items) {
4316 MapPartIdIntoName(apart, pname);
4317 fprintf(STDOUT, "partition %s ", pname);
4320 fprintf(STDOUT, "which are prefixed with %s ", prefix);
4322 fprintf(STDOUT, "\n");
4325 /* Get all the VLDB entries on a server and/or partition */
4326 memset(&arrayEntries, 0, sizeof(arrayEntries));
4327 vcode = VLDB_ListAttributes(&attributes, &nentries, &arrayEntries);
4329 fprintf(STDERR, "Could not access the VLDB for attributes\n");
4330 PrintError("", vcode);
4334 /* Process each entry */
4335 for (j = 0; j < nentries; j++) {
4336 vllist = &arrayEntries.nbulkentries_val[j];
4338 /* It only deletes the RW volumes */
4339 if (strncmp(vllist->name, prefix, strlen(prefix))) {
4342 "Omitting to delete %s due to prefix %s mismatch\n",
4343 vllist->name, prefix);
4350 if (as->parms[4].items) { /* -noexecute */
4351 fprintf(STDOUT, "Would have deleted VLDB entry for %s \n",
4357 /* Only matches the RW volume name */
4358 avolid = vllist->volumeId[RWVOL];
4359 vcode = ubik_VL_DeleteEntry(cstruct, 0, avolid, RWVOL);
4361 fprintf(STDOUT, "Could not delete VDLB entry for %s\n",
4364 PrintError("", vcode);
4369 fprintf(STDOUT, "Deleted VLDB entry for %s \n", vllist->name);
4374 fprintf(STDOUT, "----------------------\n");
4376 "Total VLDB entries deleted: %lu; failed to delete: %lu\n",
4377 (unsigned long)totalBack, (unsigned long)totalFail);
4378 if (arrayEntries.nbulkentries_val)
4379 free(arrayEntries.nbulkentries_val);
4385 CompareVldbEntryByName(const void *p1, const void *p2)
4387 struct nvldbentry *arg1, *arg2;
4389 arg1 = (struct nvldbentry *)p1;
4390 arg2 = (struct nvldbentry *)p2;
4391 return (strcmp(arg1->name, arg2->name));
4395 static int CompareVldbEntry(char *p1, char *p2)
4397 struct nvldbentry *arg1,*arg2;
4400 char comp1[100],comp2[100];
4401 char temp1[20],temp2[20];
4403 arg1 = (struct nvldbentry *)p1;
4404 arg2 = (struct nvldbentry *)p2;
4408 for(i = 0; i < arg1->nServers; i++)
4409 if(arg1->serverFlags[i] & ITSRWVOL) pos1 = i;
4410 for(i = 0; i < arg2->nServers; i++)
4411 if(arg2->serverFlags[i] & ITSRWVOL) pos2 = i;
4412 if(pos1 == -1 || pos2 == -1){
4416 sprintf(comp1,"%10u",arg1->serverNumber[pos1]);
4417 sprintf(comp2,"%10u",arg2->serverNumber[pos2]);
4418 sprintf(temp1,"%10u",arg1->serverPartition[pos1]);
4419 sprintf(temp2,"%10u",arg2->serverPartition[pos2]);
4420 strcat(comp1,temp1);
4421 strcat(comp2,temp2);
4422 strcat(comp1,arg1->name);
4423 strcat(comp1,arg2->name);
4424 return(strcmp(comp1,comp2));
4430 ListVLDB(struct cmd_syndesc *as, void *arock)
4433 afs_int32 aserver, code;
4435 struct VldbListByAttributes attributes;
4436 nbulkentries arrayEntries;
4437 struct nvldbentry *vllist, *tarray = 0, *ttarray;
4438 afs_int32 centries, nentries = 0;
4439 afs_int32 tarraysize = 0;
4440 afs_int32 parraysize;
4443 int quiet, sort, lock;
4444 afs_int32 thisindex, nextindex;
4449 attributes.Mask = 0;
4450 lock = (as->parms[3].items ? 1 : 0); /* -lock flag */
4451 quiet = (as->parms[4].items ? 1 : 0); /* -quit flag */
4452 sort = (as->parms[5].items ? 0 : 1); /* -nosort flag */
4454 /* If the volume name is given, Use VolumeInfoCmd to look it up
4455 * and not ListAttributes.
4457 if (as->parms[0].items) {
4460 "vos: illegal use of '-locked' switch, need to specify server and/or partition\n");
4463 code = VolumeInfoCmd(as->parms[0].items->data);
4465 PrintError("", code);
4471 /* Server specified */
4472 if (as->parms[1].items) {
4473 aserver = GetServer(as->parms[1].items->data);
4475 fprintf(STDERR, "vos: server '%s' not found in host table\n",
4476 as->parms[1].items->data);
4479 attributes.server = ntohl(aserver);
4480 attributes.Mask |= VLLIST_SERVER;
4483 /* Partition specified */
4484 if (as->parms[2].items) {
4485 apart = volutil_GetPartitionID(as->parms[2].items->data);
4487 fprintf(STDERR, "vos: could not interpret partition name '%s'\n",
4488 as->parms[2].items->data);
4491 attributes.partition = apart;
4492 attributes.Mask |= VLLIST_PARTITION;
4496 attributes.Mask |= VLLIST_FLAG;
4497 attributes.flag = VLOP_ALLOPERS;
4500 /* Print header information */
4502 MapPartIdIntoName(apart, pname);
4503 fprintf(STDOUT, "VLDB entries for %s %s%s%s %s\n",
4504 (as->parms[1].items ? "server" : "all"),
4505 (as->parms[1].items ? as->parms[1].items->data : "servers"),
4506 (as->parms[2].items ? " partition " : ""),
4507 (as->parms[2].items ? pname : ""),
4508 (lock ? "which are locked:" : ""));
4511 for (thisindex = 0; (thisindex != -1); thisindex = nextindex) {
4512 memset(&arrayEntries, 0, sizeof(arrayEntries));
4517 VLDB_ListAttributesN2(&attributes, 0, thisindex, ¢ries,
4518 &arrayEntries, &nextindex);
4519 if (vcode == RXGEN_OPCODE) {
4520 /* Vlserver not running with ListAttributesN2. Fall back */
4522 VLDB_ListAttributes(&attributes, ¢ries, &arrayEntries);
4526 fprintf(STDERR, "Could not access the VLDB for attributes\n");
4527 PrintError("", vcode);
4530 nentries += centries;
4532 /* We don't sort, so just print the entries now */
4534 for (j = 0; j < centries; j++) { /* process each entry */
4535 vllist = &arrayEntries.nbulkentries_val[j];
4536 MapHostToNetwork(vllist);
4537 EnumerateEntry(vllist);
4539 if (vllist->flags & VLOP_ALLOPERS)
4540 fprintf(STDOUT, " Volume is currently LOCKED \n");
4544 /* So we sort. First we must collect all the entries and keep
4547 else if (centries > 0) {
4549 /* steal away the first bulk entries array */
4550 tarray = (struct nvldbentry *)arrayEntries.nbulkentries_val;
4551 tarraysize = centries * sizeof(struct nvldbentry);
4552 arrayEntries.nbulkentries_val = 0;
4554 /* Grow the tarray to keep the extra entries */
4555 parraysize = (centries * sizeof(struct nvldbentry));
4557 (struct nvldbentry *)realloc(tarray,
4558 tarraysize + parraysize);
4561 "Could not allocate enough space for the VLDB entries\n");
4567 memcpy(((char *)tarray) + tarraysize,
4568 (char *)arrayEntries.nbulkentries_val, parraysize);
4569 tarraysize += parraysize;
4573 /* Free the bulk array */
4574 if (arrayEntries.nbulkentries_val) {
4575 free(arrayEntries.nbulkentries_val);
4576 arrayEntries.nbulkentries_val = 0;
4580 /* Here is where we now sort all the entries and print them */
4581 if (sort && (nentries > 0)) {
4582 qsort((char *)tarray, nentries, sizeof(struct nvldbentry),
4583 CompareVldbEntryByName);
4584 for (vllist = tarray, j = 0; j < nentries; j++, vllist++) {
4585 MapHostToNetwork(vllist);
4586 EnumerateEntry(vllist);
4588 if (vllist->flags & VLOP_ALLOPERS)
4589 fprintf(STDOUT, " Volume is currently LOCKED \n");
4595 fprintf(STDOUT, "\nTotal entries: %lu\n", (unsigned long)nentries);
4602 BackSys(register struct cmd_syndesc *as, void *arock)
4605 afs_int32 apart = 0;
4606 afs_int32 aserver = 0, code, aserver1, apart1;
4608 struct VldbListByAttributes attributes;
4609 nbulkentries arrayEntries;
4610 register struct nvldbentry *vllist;
4614 int seenprefix, seenxprefix, exclude, ex, exp, noaction;
4615 afs_int32 totalBack = 0;
4616 afs_int32 totalFail = 0;
4620 struct cmd_item *ti;
4622 #ifndef HAVE_POSIX_REGEX
4626 memset(&attributes, 0, sizeof(struct VldbListByAttributes));
4627 attributes.Mask = 0;
4629 seenprefix = (as->parms[0].items ? 1 : 0);
4630 exclude = (as->parms[3].items ? 1 : 0);
4631 seenxprefix = (as->parms[4].items ? 1 : 0);
4632 noaction = (as->parms[5].items ? 1 : 0);
4634 if (as->parms[1].items) { /* -server */
4635 aserver = GetServer(as->parms[1].items->data);
4637 fprintf(STDERR, "vos: server '%s' not found in host table\n",
4638 as->parms[1].items->data);
4641 attributes.server = ntohl(aserver);
4642 attributes.Mask |= VLLIST_SERVER;
4645 if (as->parms[2].items) { /* -partition */
4646 apart = volutil_GetPartitionID(as->parms[2].items->data);
4648 fprintf(STDERR, "vos: could not interpret partition name '%s'\n",
4649 as->parms[2].items->data);
4652 attributes.partition = apart;
4653 attributes.Mask |= VLLIST_PARTITION;
4656 /* Check to make sure the prefix and xprefix expressions compile ok */
4658 for (ti = as->parms[0].items; ti; ti = ti->next) {
4659 if (strncmp(ti->data, "^", 1) == 0) {
4660 #ifdef HAVE_POSIX_REGEX
4664 code = regcomp(&re, ti->data, REG_NOSUB);
4666 regerror(code, &re, errbuf, sizeof errbuf);
4668 "Unrecognizable -prefix regular expression: '%s': %s\n",
4674 ccode = (char *)re_comp(ti->data);
4677 "Unrecognizable -prefix regular expression: '%s': %s\n",
4686 for (ti = as->parms[4].items; ti; ti = ti->next) {
4687 if (strncmp(ti->data, "^", 1) == 0) {
4688 #ifdef HAVE_POSIX_REGEX
4692 code = regcomp(&re, ti->data, REG_NOSUB);
4694 regerror(code, &re, errbuf, sizeof errbuf);
4696 "Unrecognizable -xprefix regular expression: '%s': %s\n",
4702 ccode = (char *)re_comp(ti->data);
4705 "Unrecognizable -xprefix regular expression: '%s': %s\n",
4714 memset(&arrayEntries, 0, sizeof(arrayEntries)); /* initialize to hint the stub to alloc space */
4715 vcode = VLDB_ListAttributes(&attributes, &nentries, &arrayEntries);
4717 fprintf(STDERR, "Could not access the VLDB for attributes\n");
4718 PrintError("", vcode);
4722 if (as->parms[1].items || as->parms[2].items || verbose) {
4723 fprintf(STDOUT, "%s up volumes",
4724 (noaction ? "Would have backed" : "Backing"));
4726 if (as->parms[1].items) {
4727 fprintf(STDOUT, " on server %s", as->parms[1].items->data);
4728 } else if (as->parms[2].items) {
4729 fprintf(STDOUT, " for all servers");
4732 if (as->parms[2].items) {
4733 MapPartIdIntoName(apart, pname);
4734 fprintf(STDOUT, " partition %s", pname);
4737 if (seenprefix || (!seenprefix && seenxprefix)) {
4738 ti = (seenprefix ? as->parms[0].items : as->parms[4].items);
4739 ex = (seenprefix ? exclude : !exclude);
4740 exp = (strncmp(ti->data, "^", 1) == 0);
4741 fprintf(STDOUT, " which %smatch %s '%s'", (ex ? "do not " : ""),
4742 (exp ? "expression" : "prefix"), ti->data);
4743 for (ti = ti->next; ti; ti = ti->next) {
4744 exp = (strncmp(ti->data, "^", 1) == 0);
4745 printf(" %sor %s '%s'", (ex ? "n" : ""),
4746 (exp ? "expression" : "prefix"), ti->data);
4750 if (seenprefix && seenxprefix) {
4751 ti = as->parms[4].items;
4752 exp = (strncmp(ti->data, "^", 1) == 0);
4753 fprintf(STDOUT, " %swhich match %s '%s'",
4754 (exclude ? "adding those " : "removing those "),
4755 (exp ? "expression" : "prefix"), ti->data);
4756 for (ti = ti->next; ti; ti = ti->next) {
4757 exp = (strncmp(ti->data, "^", 1) == 0);
4758 printf(" or %s '%s'", (exp ? "expression" : "prefix"),
4762 fprintf(STDOUT, " .. ");
4764 fprintf(STDOUT, "\n");
4768 for (j = 0; j < nentries; j++) { /* process each vldb entry */
4769 vllist = &arrayEntries.nbulkentries_val[j];
4772 for (ti = as->parms[0].items; ti; ti = ti->next) {
4773 if (strncmp(ti->data, "^", 1) == 0) {
4774 #ifdef HAVE_POSIX_REGEX
4778 /* XXX -- should just do the compile once! */
4779 code = regcomp(&re, ti->data, REG_NOSUB);
4781 regerror(code, &re, errbuf, sizeof errbuf);
4783 "Error in -prefix regular expression: '%s': %s\n",
4787 match = (regexec(&re, vllist->name, 0, NULL, 0) == 0);
4790 ccode = (char *)re_comp(ti->data);
4793 "Error in -prefix regular expression: '%s': %s\n",
4797 match = (re_exec(vllist->name) == 1);
4801 (strncmp(vllist->name, ti->data, strlen(ti->data)) ==
4811 /* Without the -exclude flag: If it matches the prefix, then
4812 * check if we want to exclude any from xprefix.
4813 * With the -exclude flag: If it matches the prefix, then
4814 * check if we want to add any from xprefix.
4816 if (match && seenxprefix) {
4817 for (ti = as->parms[4].items; ti; ti = ti->next) {
4818 if (strncmp(ti->data, "^", 1) == 0) {
4819 #ifdef HAVE_POSIX_REGEX
4823 /* XXX -- should just do the compile once! */
4824 code = regcomp(&re, ti->data, REG_NOSUB);
4826 regerror(code, &re, errbuf, sizeof errbuf);
4828 "Error in -xprefix regular expression: '%s': %s\n",
4832 if (regexec(&re, vllist->name, 0, NULL, 0) == 0)
4836 ccode = (char *)re_comp(ti->data);
4839 "Error in -xprefix regular expression: '%s': %s\n",
4843 if (re_exec(vllist->name) == 1) {
4849 if (strncmp(vllist->name, ti->data, strlen(ti->data)) ==
4859 match = !match; /* -exclude will reverse the match */
4861 continue; /* Skip if no match */
4863 /* Print list of volumes to backup */
4865 fprintf(STDOUT, " %s\n", vllist->name);
4869 if (!(vllist->flags & RW_EXISTS)) {
4872 "Omitting to backup %s since RW volume does not exist \n",
4874 fprintf(STDOUT, "\n");
4880 avolid = vllist->volumeId[RWVOL];
4881 MapHostToNetwork(vllist);
4882 GetServerAndPart(vllist, RWVOL, &aserver1, &apart1, &previdx);
4883 if (aserver1 == -1 || apart1 == -1) {
4884 fprintf(STDOUT, "could not backup %s, invalid VLDB entry\n",
4890 same = VLDB_IsSameAddrs(aserver, aserver1, &error);
4893 "Failed to get info about server's %d address(es) from vlserver (err=%d); aborting call!\n",
4899 if ((aserver && !same) || (apart && (apart != apart1))) {
4902 "Omitting to backup %s since the RW is in a different location\n",
4908 time_t now = time(0);
4909 fprintf(STDOUT, "Creating backup volume for %s on %s",
4910 vllist->name, ctime(&now));
4914 code = UV_BackupVolume(aserver1, apart1, avolid);
4916 fprintf(STDOUT, "Could not backup %s\n", vllist->name);
4922 fprintf(STDOUT, "\n");
4924 } /* process each vldb entry */
4925 fprintf(STDOUT, "done\n");
4926 fprintf(STDOUT, "Total volumes backed up: %lu; failed to backup: %lu\n",
4927 (unsigned long)totalBack, (unsigned long)totalFail);
4929 if (arrayEntries.nbulkentries_val)
4930 free(arrayEntries.nbulkentries_val);
4935 UnlockVLDB(register struct cmd_syndesc *as, void *arock)
4938 afs_int32 aserver = 0;
4941 struct VldbListByAttributes attributes;
4942 nbulkentries arrayEntries;
4943 register struct nvldbentry *vllist;
4952 attributes.Mask = 0;
4954 if (as->parms[0].items) { /* server specified */
4955 aserver = GetServer(as->parms[0].items->data);
4957 fprintf(STDERR, "vos: server '%s' not found in host table\n",
4958 as->parms[0].items->data);
4961 attributes.server = ntohl(aserver);
4962 attributes.Mask |= VLLIST_SERVER;
4964 if (as->parms[1].items) { /* partition specified */
4965 apart = volutil_GetPartitionID(as->parms[1].items->data);
4967 fprintf(STDERR, "vos: could not interpret partition name '%s'\n",
4968 as->parms[1].items->data);
4971 if (!IsPartValid(apart, aserver, &code)) { /*check for validity of the partition */
4973 PrintError("", code);
4976 "vos : partition %s does not exist on the server\n",
4977 as->parms[1].items->data);
4980 attributes.partition = apart;
4981 attributes.Mask |= VLLIST_PARTITION;
4983 attributes.flag = VLOP_ALLOPERS;
4984 attributes.Mask |= VLLIST_FLAG;
4985 memset(&arrayEntries, 0, sizeof(arrayEntries)); /*initialize to hint the stub to alloc space */
4986 vcode = VLDB_ListAttributes(&attributes, &nentries, &arrayEntries);
4988 fprintf(STDERR, "Could not access the VLDB for attributes\n");
4989 PrintError("", vcode);
4992 for (j = 0; j < nentries; j++) { /* process each entry */
4993 vllist = &arrayEntries.nbulkentries_val[j];
4994 volid = vllist->volumeId[RWVOL];
4996 ubik_VL_ReleaseLock(cstruct, 0, volid, -1,
4997 LOCKREL_OPCODE | LOCKREL_AFSID |
5000 fprintf(STDERR, "Could not unlock entry for volume %s\n",
5002 PrintError("", vcode);
5007 MapPartIdIntoName(apart, pname);
5010 "Could not lock %lu VLDB entries of %lu locked entries\n",
5011 (unsigned long)totalE, (unsigned long)nentries);
5013 if (as->parms[0].items) {
5015 "Unlocked all the VLDB entries for volumes on server %s ",
5016 as->parms[0].items->data);
5017 if (as->parms[1].items) {
5018 MapPartIdIntoName(apart, pname);
5019 fprintf(STDOUT, "partition %s\n", pname);
5021 fprintf(STDOUT, "\n");
5023 } else if (as->parms[1].items) {
5024 MapPartIdIntoName(apart, pname);
5026 "Unlocked all the VLDB entries for volumes on partition %s on all servers\n",
5031 if (arrayEntries.nbulkentries_val)
5032 free(arrayEntries.nbulkentries_val);
5037 PrintInt64Size(afs_uint64 in)
5039 register afs_uint32 hi, lo;
5040 register char * units;
5041 static char output[16];
5043 SplitInt64(in,hi,lo);
5047 } else if (!(hi & 0xFFFFFC00)) {
5049 lo = (hi << 22) | (lo >> 10);
5050 } else if (!(hi & 0xFFF00000)) {
5052 lo = (hi << 12) | (lo >> 20);
5053 } else if (!(hi & 0xC0000000)) {
5055 lo = (hi << 2) | (lo >> 30);
5060 sprintf(output,"%u %s", lo, units);
5065 PartitionInfo(register struct cmd_syndesc *as, void *arock)
5068 afs_int32 aserver, code;
5070 struct diskPartition64 partition;
5071 struct partList dummyPartList;
5073 int printSummary=0, sumPartitions=0;
5074 afs_uint64 sumFree, sumStorage;
5077 ZeroInt64(sumStorage);
5079 aserver = GetServer(as->parms[0].items->data);
5081 fprintf(STDERR, "vos: server '%s' not found in host table\n",
5082 as->parms[0].items->data);
5085 if (as->parms[1].items) {
5086 apart = volutil_GetPartitionID(as->parms[1].items->data);
5088 fprintf(STDERR, "vos: could not interpret partition name '%s'\n",
5089 as->parms[1].items->data);
5092 dummyPartList.partId[0] = apart;
5093 dummyPartList.partFlags[0] = PARTVALID;
5096 if (as->parms[2].items) {
5100 if (!IsPartValid(apart, aserver, &code)) { /*check for validity of the partition */
5102 PrintError("", code);
5105 "vos : partition %s does not exist on the server\n",
5106 as->parms[1].items->data);
5110 code = UV_ListPartitions(aserver, &dummyPartList, &cnt);
5112 PrintDiagnostics("listpart", code);
5116 for (i = 0; i < cnt; i++) {
5117 if (dummyPartList.partFlags[i] & PARTVALID) {
5118 MapPartIdIntoName(dummyPartList.partId[i], pname);
5119 code = UV_PartitionInfo64(aserver, pname, &partition);
5121 fprintf(STDERR, "Could not get information on partition %s\n",
5123 PrintError("", code);
5127 "Free space on partition %s: %" AFS_INT64_FMT " K blocks out of total %" AFS_INT64_FMT "\n",
5128 pname, partition.free, partition.minFree);
5130 AddUInt64(sumFree,partition.free,&sumFree);
5131 AddUInt64(sumStorage,partition.minFree,&sumStorage);
5136 "Summary: %s free out of ",
5137 PrintInt64Size(sumFree));
5139 "%s on %d partitions\n",
5140 PrintInt64Size(sumStorage),
5147 ChangeAddr(register struct cmd_syndesc *as, void *arock)
5149 afs_int32 ip1, ip2, vcode;
5153 ip1 = GetServerNoresolve(as->parms[0].items->data);
5155 ip1 = GetServer(as->parms[0].items->data);
5157 fprintf(STDERR, "vos: invalid host address\n");
5161 if ((as->parms[1].items && as->parms[2].items)
5162 || (!as->parms[1].items && !as->parms[2].items)) {
5164 "vos: Must specify either '-newaddr <addr>' or '-remove' flag\n");
5168 if (as->parms[1].items) {
5170 ip2 = GetServerNoresolve(as->parms[1].items->data);
5172 ip2 = GetServer(as->parms[1].items->data);
5174 fprintf(STDERR, "vos: invalid host address\n");
5178 /* Play a trick here. If we are removing an address, ip1 will be -1
5179 * and ip2 will be the original address. This switch prevents an
5180 * older revision vlserver from removing the IP address.
5187 vcode = ubik_VL_ChangeAddr(cstruct, UBIK_CALL_NEW, ntohl(ip1), ntohl(ip2));
5189 char hoststr1[16], hoststr2[16];
5191 afs_inet_ntoa_r(ip2, hoststr2);
5192 fprintf(STDERR, "Could not remove server %s from the VLDB\n",
5194 if (vcode == VL_NOENT) {
5196 "vlserver does not support the remove flag or ");
5199 afs_inet_ntoa_r(ip1, hoststr1);
5200 afs_inet_ntoa_r(ip2, hoststr2);
5201 fprintf(STDERR, "Could not change server %s to server %s\n",
5202 hoststr1, hoststr2);
5204 PrintError("", vcode);
5209 fprintf(STDOUT, "Removed server %s from the VLDB\n",
5210 as->parms[0].items->data);
5212 fprintf(STDOUT, "Changed server %s to server %s\n",
5213 as->parms[0].items->data, as->parms[1].items->data);
5219 print_addrs(const bulkaddrs * addrs, afsUUID * m_uuid, int nentries,
5222 afs_int32 vcode, m_uniq=0;
5226 ListAddrByAttributes m_attrs;
5227 afs_int32 m_nentries, *m_addrp;
5228 afs_int32 base, index;
5232 afsUUID_to_string(m_uuid, buf, sizeof(buf));
5233 printf("UUID: %s\n", buf);
5236 /* print out the list of all the server */
5237 addrp = (afs_int32 *) addrs->bulkaddrs_val;
5238 for (i = 0; i < nentries; i++, addrp++) {
5239 /* If it is a multihomed address, then we will need to
5240 * get the addresses for this multihomed server from
5241 * the vlserver and print them.
5243 if (((*addrp & 0xff000000) == 0xff000000) && ((*addrp) & 0xffff)) {
5244 /* Get the list of multihomed fileservers */
5245 base = (*addrp >> 16) & 0xff;
5246 index = (*addrp) & 0xffff;
5248 if ((base >= 0) && (base <= VL_MAX_ADDREXTBLKS) && (index >= 1)
5249 && (index <= VL_MHSRV_PERBLK)) {
5250 m_attrs.Mask = VLADDR_INDEX;
5251 m_attrs.index = (base * VL_MHSRV_PERBLK) + index;
5253 m_addrs.bulkaddrs_val = 0;
5254 m_addrs.bulkaddrs_len = 0;
5256 ubik_VL_GetAddrsU(cstruct, 0, &m_attrs, m_uuid,
5257 &m_uniq, &m_nentries,
5261 "vos: could not list the multi-homed server addresses\n");
5262 PrintError("", vcode);
5265 /* Print the list */
5266 m_addrp = (afs_int32 *) m_addrs.bulkaddrs_val;
5267 for (j = 0; j < m_nentries; j++, m_addrp++) {
5268 *m_addrp = htonl(*m_addrp);
5271 printf("%s ", afs_inet_ntoa_r(*m_addrp, hoststr));
5273 printf("%s ", hostutil_GetNameByINet(*m_addrp));
5277 printf("<unknown>\n");
5286 /* Otherwise, it is a non-multihomed entry and contains
5287 * the IP address of the server - print it.
5289 *addrp = htonl(*addrp);
5292 printf("%s\n", afs_inet_ntoa_r(*addrp, hoststr));
5294 printf("%s\n", hostutil_GetNameByINet(*addrp));
5305 ListAddrs(register struct cmd_syndesc *as, void *arock)
5307 afs_int32 vcode, m_uniq=0;
5308 afs_int32 i, printuuid = 0;
5309 struct VLCallBack vlcb;
5312 ListAddrByAttributes m_attrs;
5313 afsUUID m_uuid, askuuid;
5314 afs_int32 m_nentries;
5316 memset(&m_attrs, 0, sizeof(struct ListAddrByAttributes));
5317 m_attrs.Mask = VLADDR_INDEX;
5319 memset(&m_addrs, 0, sizeof(bulkaddrs));
5320 memset(&askuuid, 0, sizeof(afsUUID));
5321 if (as->parms[0].items) {
5323 if (afsUUID_from_string(as->parms[0].items->data, &askuuid) < 0) {
5324 fprintf(STDERR, "vos: invalid UUID '%s'\n",
5325 as->parms[0].items->data);
5328 m_attrs.Mask = VLADDR_UUID;
5329 m_attrs.uuid = askuuid;
5331 if (as->parms[1].items) {
5335 he = hostutil_GetHostByName((char *)as->parms[1].items->data);
5337 fprintf(STDERR, "vos: Can't get host info for '%s'\n",
5338 as->parms[1].items->data);
5341 memcpy(&saddr, he->h_addr, 4);
5342 m_attrs.Mask = VLADDR_IPADDR;
5343 m_attrs.ipaddr = ntohl(saddr);
5345 if (as->parms[2].items) {
5349 m_addrs.bulkaddrs_val = 0;
5350 m_addrs.bulkaddrs_len = 0;
5353 ubik_VL_GetAddrs(cstruct, UBIK_CALL_NEW, 0, 0, &vlcb, &nentries,
5356 fprintf(STDERR, "vos: could not list the server addresses\n");
5357 PrintError("", vcode);
5362 m_addrs.bulkaddrs_val = 0;
5363 m_addrs.bulkaddrs_len = 0;
5369 ubik_VL_GetAddrsU(cstruct, UBIK_CALL_NEW, &m_attrs, &m_uuid,
5370 &m_uniq, &m_nentries, &m_addrs);
5372 if (vcode == VL_NOENT) {
5373 if (m_attrs.Mask == VLADDR_UUID) {
5374 fprintf(STDERR, "vos: no entry for UUID '%s' found in VLDB\n",
5375 as->parms[0].items->data);
5377 } else if (m_attrs.Mask == VLADDR_IPADDR) {
5378 fprintf(STDERR, "vos: no entry for host '%s' [0x%08x] found in VLDB\n",
5379 as->parms[1].items->data, m_attrs.ipaddr);
5388 if (vcode == VL_INDEXERANGE) {
5393 fprintf(STDERR, "vos: could not list the server addresses\n");
5394 PrintError("", vcode);
5398 print_addrs(&m_addrs, &m_uuid, m_nentries, printuuid);
5401 if ((as->parms[1].items) || (as->parms[0].items) || (i > nentries))
5410 SetAddrs(register struct cmd_syndesc *as, void *arock)
5415 afs_uint32 FS_HostAddrs_HBO[ADDRSPERSITE];
5417 memset(&m_addrs, 0, sizeof(bulkaddrs));
5418 memset(&askuuid, 0, sizeof(afsUUID));
5419 if (as->parms[0].items) {
5421 if (afsUUID_from_string(as->parms[0].items->data, &askuuid) < 0) {
5422 fprintf(STDERR, "vos: invalid UUID '%s'\n",
5423 as->parms[0].items->data);
5427 if (as->parms[1].items) {
5429 struct cmd_item *ti;
5434 for (ti = as->parms[1].items; ti && i < ADDRSPERSITE; ti = ti->next) {
5437 saddr = GetServerNoresolve(ti->data);
5439 saddr = GetServer(ti->data);
5442 fprintf(STDERR, "vos: Can't get host info for '%s'\n",
5446 /* Convert it to host byte order */
5447 FS_HostAddrs_HBO[i] = ntohl(saddr);
5450 m_addrs.bulkaddrs_len = i;
5451 m_addrs.bulkaddrs_val = FS_HostAddrs_HBO;
5454 vcode = ubik_VL_RegisterAddrs(cstruct, 0, &askuuid, 0, &m_addrs);
5457 if (vcode == VL_MULTIPADDR) {
5458 fprintf(STDERR, "vos: VL_RegisterAddrs rpc failed; The IP address exists on a different server; repair it\n");
5459 PrintError("", vcode);
5461 } else if (vcode == RXGEN_OPCODE) {
5462 fprintf(STDERR, "vlserver doesn't support VL_RegisterAddrs rpc; ignored\n");
5463 PrintError("", vcode);
5468 fprintf(STDOUT, "vos: Changed UUID with addresses:\n");
5469 print_addrs(&m_addrs, &askuuid, m_addrs.bulkaddrs_len, 1);
5475 LockEntry(register struct cmd_syndesc *as, void *arock)
5478 afs_int32 vcode, err;
5480 avolid = vsu_GetVolumeID(as->parms[0].items->data, cstruct, &err);
5483 PrintError("", err);
5485 fprintf(STDERR, "vos: can't find volume '%s'\n",
5486 as->parms[0].items->data);
5489 vcode = ubik_VL_SetLock(cstruct, 0, avolid, -1, VLOP_DELETE);
5491 fprintf(STDERR, "Could not lock VLDB entry for volume %s\n",
5492 as->parms[0].items->data);
5493 PrintError("", vcode);
5496 fprintf(STDOUT, "Locked VLDB entry for volume %s\n",
5497 as->parms[0].items->data);
5502 ConvertRO(register struct cmd_syndesc *as, void *arock)
5504 afs_int32 partition = -1;
5506 afs_int32 server, code, i, same;
5507 struct nvldbentry entry, storeEntry;
5509 afs_int32 rwindex = 0;
5510 afs_int32 rwserver = 0;
5511 afs_int32 rwpartition = 0;
5512 afs_int32 roindex = 0;
5513 afs_int32 roserver = 0;
5514 afs_int32 ropartition = 0;
5516 struct rx_connection *aconn;
5519 server = GetServer(as->parms[0].items->data);
5521 fprintf(STDERR, "vos: host '%s' not found in host table\n",
5522 as->parms[0].items->data);
5525 partition = volutil_GetPartitionID(as->parms[1].items->data);
5526 if (partition < 0) {
5527 fprintf(STDERR, "vos: could not interpret partition name '%s'\n",
5528 as->parms[1].items->data);
5531 if (!IsPartValid(partition, server, &code)) {
5533 PrintError("", code);
5536 "vos : partition %s does not exist on the server\n",
5537 as->parms[1].items->data);
5540 volid = vsu_GetVolumeID(as->parms[2].items->data, cstruct, &code);
5543 PrintError("", code);
5545 fprintf(STDERR, "Unknown volume ID or name '%s'\n",
5546 as->parms[0].items->data);
5549 if (as->parms[3].items)
5552 vcode = VLDB_GetEntryByID(volid, -1, &entry);
5555 "Could not fetch the entry for volume %lu from VLDB\n",
5556 (unsigned long)volid);
5557 PrintError("convertROtoRW", code);
5561 /* use RO volid even if user specified RW or BK volid */
5563 if (volid != entry.volumeId[ROVOL])
5564 volid = entry.volumeId[ROVOL];
5566 MapHostToNetwork(&entry);
5567 for (i = 0; i < entry.nServers; i++) {
5568 if (entry.serverFlags[i] & ITSRWVOL) {
5570 rwserver = entry.serverNumber[i];
5571 rwpartition = entry.serverPartition[i];
5573 if (entry.serverFlags[i] & ITSROVOL) {
5574 same = VLDB_IsSameAddrs(server, entry.serverNumber[i], &code);
5577 "Failed to get info about server's %d address(es) from vlserver (err=%d); aborting call!\n",
5583 roserver = entry.serverNumber[i];
5584 ropartition = entry.serverPartition[i];
5590 fprintf(STDERR, "Warning: RO volume didn't exist in vldb!\n");
5592 if (ropartition != partition) {
5594 "Warning: RO volume should be in partition %d instead of %d (vldb)\n",
5595 ropartition, partition);
5600 "VLDB indicates that a RW volume exists already on %s in partition %s.\n",
5601 hostutil_GetNameByINet(rwserver),
5602 volutil_PartitionName(rwpartition));
5604 fprintf(STDERR, "Overwrite this VLDB entry? [y|n] (n)\n");
5606 while (!(dc == EOF || dc == '\n'))
5607 dc = getchar(); /* goto end of line */
5608 if ((c != 'y') && (c != 'Y')) {
5609 fprintf(STDERR, "aborted.\n");
5616 ubik_VL_SetLock(cstruct, 0, entry.volumeId[RWVOL], RWVOL,
5618 aconn = UV_Bind(server, AFSCONF_VOLUMEPORT);
5619 code = AFSVolConvertROtoRWvolume(aconn, partition, volid);
5622 "Converting RO volume %lu to RW volume failed with code %d\n",
5623 (unsigned long)volid, code);
5624 PrintError("convertROtoRW ", code);
5627 entry.serverFlags[roindex] = ITSRWVOL;
5628 entry.flags |= RW_EXISTS;
5629 entry.flags &= ~BACK_EXISTS;
5632 if (rwindex != entry.nServers) {
5633 entry.serverNumber[rwindex] = entry.serverNumber[entry.nServers];
5634 entry.serverPartition[rwindex] =
5635 entry.serverPartition[entry.nServers];
5636 entry.serverFlags[rwindex] = entry.serverFlags[entry.nServers];
5637 entry.serverNumber[entry.nServers] = 0;
5638 entry.serverPartition[entry.nServers] = 0;
5639 entry.serverFlags[entry.nServers] = 0;
5642 entry.flags &= ~RO_EXISTS;
5643 for (i = 0; i < entry.nServers; i++) {
5644 if (entry.serverFlags[i] & ITSROVOL) {
5645 if (!(entry.serverFlags[i] & (RO_DONTUSE | NEW_REPSITE)))
5646 entry.flags |= RO_EXISTS;
5649 MapNetworkToHost(&entry, &storeEntry);
5651 VLDB_ReplaceEntry(entry.volumeId[RWVOL], RWVOL, &storeEntry,
5652 (LOCKREL_OPCODE | LOCKREL_AFSID |
5653 LOCKREL_TIMESTAMP));
5656 "Warning: volume converted, but vldb update failed with code %d!\n",
5659 vcode = UV_LockRelease(entry.volumeId[RWVOL]);
5661 PrintDiagnostics("unlock", vcode);
5667 Sizes(register struct cmd_syndesc *as, void *arock)
5670 afs_int32 aserver, apart, voltype, fromdate = 0, code, err, i;
5671 struct nvldbentry entry;
5672 volintSize vol_size;
5674 rx_SetRxDeadTime(60 * 10);
5675 for (i = 0; i < MAXSERVERS; i++) {
5676 struct rx_connection *rxConn = ubik_GetRPCConn(cstruct, i);
5679 rx_SetConnDeadTime(rxConn, rx_connDeadTime);
5680 if (rxConn->service)
5681 rxConn->service->connDeadTime = rx_connDeadTime;
5684 avolid = vsu_GetVolumeID(as->parms[0].items->data, cstruct, &err);
5687 PrintError("", err);
5689 fprintf(STDERR, "vos: can't find volume '%s'\n",
5690 as->parms[0].items->data);
5694 if (as->parms[1].items || as->parms[2].items) {
5695 if (!as->parms[1].items || !as->parms[2].items) {
5697 "Must specify both -server and -partition options\n");
5700 aserver = GetServer(as->parms[2].items->data);
5702 fprintf(STDERR, "Invalid server name\n");
5705 apart = volutil_GetPartitionID(as->parms[1].items->data);
5707 fprintf(STDERR, "Invalid partition name\n");
5711 code = GetVolumeInfo(avolid, &aserver, &apart, &voltype, &entry);
5718 if (as->parms[4].items && strcmp(as->parms[4].items->data, "0")) {
5719 code = ktime_DateToInt32(as->parms[4].items->data, &fromdate);
5721 fprintf(STDERR, "vos: failed to parse date '%s' (error=%d))\n",
5722 as->parms[4].items->data, code);
5727 fprintf(STDOUT, "Volume: %s\n", as->parms[0].items->data);
5729 if (as->parms[3].items) { /* do the dump estimate */
5730 #ifdef AFS_64BIT_ENV
5731 vol_size.dump_size = 0;
5733 FillInt64(vol_size.dump_size,0, 1);
5735 code = UV_GetSize(avolid, aserver, apart, fromdate, &vol_size);
5737 PrintDiagnostics("size", code);
5740 /* presumably the size info is now gathered in pntr */
5741 /* now we display it */
5743 fprintf(STDOUT, "dump_size: %llu\n", vol_size.dump_size);
5752 EndTrans(register struct cmd_syndesc *as, void *arock)
5754 afs_int32 server, code, tid, rcode;
5755 struct rx_connection *aconn;
5757 server = GetServer(as->parms[0].items->data);
5759 fprintf(STDERR, "vos: host '%s' not found in host table\n",
5760 as->parms[0].items->data);
5764 code = util_GetInt32(as->parms[1].items->data, &tid);
5766 fprintf(STDERR, "vos: bad integer specified for transaction ID.\n");
5770 aconn = UV_Bind(server, AFSCONF_VOLUMEPORT);
5771 code = AFSVolEndTrans(aconn, tid, &rcode);
5777 PrintDiagnostics("endtrans", code);
5785 PrintDiagnostics(char *astring, afs_int32 acode)
5787 if (acode == EACCES) {
5789 "You are not authorized to perform the 'vos %s' command (%d)\n",
5792 fprintf(STDERR, "Error in vos %s command.\n", astring);
5793 PrintError("", acode);
5801 win32_enableCrypt(void)
5808 /* Look up configuration parameters in Registry */
5809 code = RegOpenKeyEx(HKEY_LOCAL_MACHINE, AFSREG_CLT_SVC_PARAM_SUBKEY,
5810 0, (IsWow64()?KEY_WOW64_64KEY:0)|KEY_QUERY_VALUE, &parmKey);
5811 if (code != ERROR_SUCCESS) {
5812 dummyLen = sizeof(cryptall);
5813 RegQueryValueEx(parmKey, "SecurityLevel", NULL, NULL,
5814 (BYTE *) &cryptall, &dummyLen);
5816 RegCloseKey (parmKey);
5820 #endif /* AFS_NT40_ENV */
5823 MyBeforeProc(struct cmd_syndesc *as, void *arock)
5825 register char *tcell;
5826 register afs_int32 code;
5827 register afs_int32 sauth;
5829 /* Initialize the ubik_client connection */
5830 rx_SetRxDeadTime(90);
5831 cstruct = (struct ubik_client *)0;
5835 if (as->parms[12].items) /* if -cell specified */
5836 tcell = as->parms[12].items->data;
5837 if (as->parms[14].items) /* -serverauth specified */
5839 if (as->parms[16].items /* -encrypt specified */
5841 || win32_enableCrypt()
5842 #endif /* AFS_NT40_ENV */
5846 vsu_ClientInit((as->parms[13].items != 0), confdir, tcell, sauth,
5847 &cstruct, UV_SetSecurity))) {
5848 fprintf(STDERR, "could not initialize VLDB library (code=%lu) \n",
5849 (unsigned long)code);
5853 if (as->parms[15].items) /* -verbose flag set */
5857 if (as->parms[17].items) /* -noresolve flag set */
5867 /* this sucks but it works for now.
5872 #include "AFS_component_version_number.c"
5875 main(int argc, char **argv)
5877 register afs_int32 code;
5879 register struct cmd_syndesc *ts;
5881 #ifdef AFS_AIX32_ENV
5883 * The following signal action for AIX is necessary so that in case of a
5884 * crash (i.e. core is generated) we can include the user's data section
5885 * in the core dump. Unfortunately, by default, only a partial core is
5886 * generated which, in many cases, isn't too useful.
5888 struct sigaction nsa;
5890 sigemptyset(&nsa.sa_mask);
5891 nsa.sa_handler = SIG_DFL;
5892 nsa.sa_flags = SA_FULLDUMP;
5893 sigaction(SIGSEGV, &nsa, NULL);
5896 confdir = AFSDIR_CLIENT_ETC_DIRPATH;
5898 cmd_SetBeforeProc(MyBeforeProc, NULL);
5900 ts = cmd_CreateSyntax("create", CreateVolume, NULL, "create a new volume");
5901 cmd_AddParm(ts, "-server", CMD_SINGLE, 0, "machine name");
5902 cmd_AddParm(ts, "-partition", CMD_SINGLE, 0, "partition name");
5903 cmd_AddParm(ts, "-name", CMD_SINGLE, 0, "volume name");
5904 cmd_AddParm(ts, "-maxquota", CMD_SINGLE, CMD_OPTIONAL,
5905 "initial quota (KB)");
5906 cmd_AddParm(ts, "-id", CMD_SINGLE, CMD_OPTIONAL, "volume ID");
5907 cmd_AddParm(ts, "-roid", CMD_SINGLE, CMD_OPTIONAL, "readonly volume ID");
5909 cmd_AddParm(ts, "-minquota", CMD_SINGLE, CMD_OPTIONAL, "");
5913 ts = cmd_CreateSyntax("remove", DeleteVolume, NULL, "delete a volume");
5914 cmd_AddParm(ts, "-server", CMD_SINGLE, CMD_OPTIONAL, "machine name");
5915 cmd_AddParm(ts, "-partition", CMD_SINGLE, CMD_OPTIONAL, "partition name");
5916 cmd_AddParm(ts, "-id", CMD_SINGLE, 0, "volume name or ID");
5920 ts = cmd_CreateSyntax("move", MoveVolume, NULL, "move a volume");
5921 cmd_AddParm(ts, "-id", CMD_SINGLE, 0, "volume name or ID");
5922 cmd_AddParm(ts, "-fromserver", CMD_SINGLE, 0, "machine name on source");
5923 cmd_AddParm(ts, "-frompartition", CMD_SINGLE, 0,
5924 "partition name on source");
5925 cmd_AddParm(ts, "-toserver", CMD_SINGLE, 0,
5926 "machine name on destination");
5927 cmd_AddParm(ts, "-topartition", CMD_SINGLE, 0,
5928 "partition name on destination");
5929 cmd_AddParm(ts, "-live", CMD_FLAG, CMD_OPTIONAL,
5930 "copy live volume without cloning");
5933 ts = cmd_CreateSyntax("copy", CopyVolume, NULL, "copy a volume");
5934 cmd_AddParm(ts, "-id", CMD_SINGLE, 0, "volume name or ID on source");
5935 cmd_AddParm(ts, "-fromserver", CMD_SINGLE, 0, "machine name on source");
5936 cmd_AddParm(ts, "-frompartition", CMD_SINGLE, 0,
5937 "partition name on source");
5938 cmd_AddParm(ts, "-toname", CMD_SINGLE, 0, "volume name on destination");
5939 cmd_AddParm(ts, "-toserver", CMD_SINGLE, 0,
5940 "machine name on destination");
5941 cmd_AddParm(ts, "-topartition", CMD_SINGLE, 0,
5942 "partition name on destination");
5943 cmd_AddParm(ts, "-offline", CMD_FLAG, CMD_OPTIONAL,
5944 "leave new volume offline");
5945 cmd_AddParm(ts, "-readonly", CMD_FLAG, CMD_OPTIONAL,
5946 "make new volume read-only");
5947 cmd_AddParm(ts, "-live", CMD_FLAG, CMD_OPTIONAL,
5948 "copy live volume without cloning");
5951 ts = cmd_CreateSyntax("shadow", ShadowVolume, NULL,
5952 "make or update a shadow volume");
5953 cmd_AddParm(ts, "-id", CMD_SINGLE, 0, "volume name or ID on source");
5954 cmd_AddParm(ts, "-fromserver", CMD_SINGLE, 0, "machine name on source");
5955 cmd_AddParm(ts, "-frompartition", CMD_SINGLE, 0,
5956 "partition name on source");
5957 cmd_AddParm(ts, "-toserver", CMD_SINGLE, 0,
5958 "machine name on destination");
5959 cmd_AddParm(ts, "-topartition", CMD_SINGLE, 0,
5960 "partition name on destination");
5961 cmd_AddParm(ts, "-toname", CMD_SINGLE, CMD_OPTIONAL,
5962 "volume name on destination");
5963 cmd_AddParm(ts, "-toid", CMD_SINGLE, CMD_OPTIONAL,
5964 "volume ID on destination");
5965 cmd_AddParm(ts, "-offline", CMD_FLAG, CMD_OPTIONAL,
5966 "leave shadow volume offline");
5967 cmd_AddParm(ts, "-readonly", CMD_FLAG, CMD_OPTIONAL,
5968 "make shadow volume read-only");
5969 cmd_AddParm(ts, "-live", CMD_FLAG, CMD_OPTIONAL,
5970 "copy live volume without cloning");
5971 cmd_AddParm(ts, "-incremental", CMD_FLAG, CMD_OPTIONAL,
5972 "do incremental update if target exists");
5975 ts = cmd_CreateSyntax("backup", BackupVolume, NULL,
5976 "make backup of a volume");
5977 cmd_AddParm(ts, "-id", CMD_SINGLE, 0, "volume name or ID");
5980 ts = cmd_CreateSyntax("clone", CloneVolume, NULL,
5981 "make clone of a volume");
5982 cmd_AddParm(ts, "-id", CMD_SINGLE, 0, "volume name or ID");
5983 cmd_AddParm(ts, "-server", CMD_SINGLE, CMD_OPTIONAL, "server");
5984 cmd_AddParm(ts, "-partition", CMD_SINGLE, CMD_OPTIONAL, "partition");
5985 cmd_AddParm(ts, "-toname", CMD_SINGLE, CMD_OPTIONAL,
5986 "volume name on destination");
5987 cmd_AddParm(ts, "-toid", CMD_SINGLE, CMD_OPTIONAL,
5988 "volume ID on destination");
5989 cmd_AddParm(ts, "-offline", CMD_FLAG, CMD_OPTIONAL,
5990 "leave clone volume offline");
5991 cmd_AddParm(ts, "-readonly", CMD_FLAG, CMD_OPTIONAL,
5992 "make clone volume read-only, not readwrite");
5995 ts = cmd_CreateSyntax("release", ReleaseVolume, NULL, "release a volume");
5996 cmd_AddParm(ts, "-id", CMD_SINGLE, 0, "volume name or ID");
5997 cmd_AddParm(ts, "-force", CMD_FLAG, CMD_OPTIONAL,
5998 "force a complete release");
6001 ts = cmd_CreateSyntax("dump", DumpVolumeCmd, NULL, "dump a volume");
6002 cmd_AddParm(ts, "-id", CMD_SINGLE, 0, "volume name or ID");
6003 cmd_AddParm(ts, "-time", CMD_SINGLE, CMD_OPTIONAL, "dump from time");
6004 cmd_AddParm(ts, "-file", CMD_SINGLE, CMD_OPTIONAL, "dump file");
6005 cmd_AddParm(ts, "-server", CMD_SINGLE, CMD_OPTIONAL, "server");
6006 cmd_AddParm(ts, "-partition", CMD_SINGLE, CMD_OPTIONAL, "partition");
6007 cmd_AddParm(ts, "-clone", CMD_FLAG, CMD_OPTIONAL,
6008 "dump a clone of the volume");
6009 cmd_AddParm(ts, "-omitdirs", CMD_FLAG, CMD_OPTIONAL,
6010 "omit unchanged directories from an incremental dump");
6013 ts = cmd_CreateSyntax("restore", RestoreVolumeCmd, NULL,
6014 "restore a volume");
6015 cmd_AddParm(ts, "-server", CMD_SINGLE, 0, "machine name");
6016 cmd_AddParm(ts, "-partition", CMD_SINGLE, 0, "partition name");
6017 cmd_AddParm(ts, "-name", CMD_SINGLE, 0, "name of volume to be restored");
6018 cmd_AddParm(ts, "-file", CMD_SINGLE, CMD_OPTIONAL, "dump file");
6019 cmd_AddParm(ts, "-id", CMD_SINGLE, CMD_OPTIONAL, "volume ID");
6020 cmd_AddParm(ts, "-overwrite", CMD_SINGLE, CMD_OPTIONAL,
6021 "abort | full | incremental");
6022 cmd_AddParm(ts, "-offline", CMD_FLAG, CMD_OPTIONAL,
6023 "leave restored volume offline");
6024 cmd_AddParm(ts, "-readonly", CMD_FLAG, CMD_OPTIONAL,
6025 "make restored volume read-only");
6026 cmd_AddParm(ts, "-creation", CMD_SINGLE, CMD_OPTIONAL,
6027 "dump | keep | new");
6028 cmd_AddParm(ts, "-lastupdate", CMD_SINGLE, CMD_OPTIONAL,
6029 "dump | keep | new");
6030 cmd_AddParm(ts, "-nodelete", CMD_FLAG, CMD_OPTIONAL,
6031 "do not delete old site when restoring to a new site");
6034 ts = cmd_CreateSyntax("unlock", LockReleaseCmd, NULL,
6035 "release lock on VLDB entry for a volume");
6036 cmd_AddParm(ts, "-id", CMD_SINGLE, 0, "volume name or ID");
6039 ts = cmd_CreateSyntax("changeloc", ChangeLocation, NULL,
6040 "change an RW volume's location in the VLDB");
6041 cmd_AddParm(ts, "-server", CMD_SINGLE, 0,
6042 "machine name for new location");
6043 cmd_AddParm(ts, "-partition", CMD_SINGLE, 0,
6044 "partition name for new location");
6045 cmd_AddParm(ts, "-id", CMD_SINGLE, 0, "volume name or ID");
6048 ts = cmd_CreateSyntax("addsite", AddSite, NULL, "add a replication site");
6049 cmd_AddParm(ts, "-server", CMD_SINGLE, 0, "machine name for new site");
6050 cmd_AddParm(ts, "-partition", CMD_SINGLE, 0,
6051 "partition name for new site");
6052 cmd_AddParm(ts, "-id", CMD_SINGLE, 0, "volume name or ID");
6053 cmd_AddParm(ts, "-roid", CMD_SINGLE, CMD_OPTIONAL, "volume name or ID for RO");
6054 cmd_AddParm(ts, "-valid", CMD_FLAG, CMD_OPTIONAL, "publish as an up-to-date site in VLDB");
6057 ts = cmd_CreateSyntax("remsite", RemoveSite, NULL,
6058 "remove a replication site");
6059 cmd_AddParm(ts, "-server", CMD_SINGLE, 0, "machine name");
6060 cmd_AddParm(ts, "-partition", CMD_SINGLE, 0, "partition name");
6061 cmd_AddParm(ts, "-id", CMD_SINGLE, 0, "volume name or ID");
6064 ts = cmd_CreateSyntax("listpart", ListPartitions, NULL, "list partitions");
6065 cmd_AddParm(ts, "-server", CMD_SINGLE, 0, "machine name");
6068 ts = cmd_CreateSyntax("listvol", ListVolumes, NULL,
6069 "list volumes on server (bypass VLDB)");
6070 cmd_AddParm(ts, "-server", CMD_SINGLE, 0, "machine name");
6071 cmd_AddParm(ts, "-partition", CMD_SINGLE, CMD_OPTIONAL, "partition name");
6072 cmd_AddParm(ts, "-fast", CMD_FLAG, CMD_OPTIONAL, "minimal listing");
6073 cmd_AddParm(ts, "-long", CMD_FLAG, CMD_OPTIONAL,
6074 "list all normal volume fields");
6075 cmd_AddParm(ts, "-quiet", CMD_FLAG, CMD_OPTIONAL,
6076 "generate minimal information");
6077 cmd_AddParm(ts, "-extended", CMD_FLAG, CMD_OPTIONAL,
6078 "list extended volume fields");
6079 cmd_AddParm(ts, "-format", CMD_FLAG, CMD_OPTIONAL,
6080 "machine readable format");
6083 ts = cmd_CreateSyntax("syncvldb", SyncVldb, NULL,
6084 "synchronize VLDB with server");
6085 cmd_AddParm(ts, "-server", CMD_SINGLE, CMD_OPTIONAL, "machine name");
6086 cmd_AddParm(ts, "-partition", CMD_SINGLE, CMD_OPTIONAL, "partition name");
6087 cmd_AddParm(ts, "-volume", CMD_SINGLE, CMD_OPTIONAL, "volume name or ID");
6088 cmd_AddParm(ts, "-dryrun", CMD_FLAG, CMD_OPTIONAL, "report without updating");
6091 ts = cmd_CreateSyntax("syncserv", SyncServer, NULL,
6092 "synchronize server with VLDB");
6093 cmd_AddParm(ts, "-server", CMD_SINGLE, 0, "machine name");
6094 cmd_AddParm(ts, "-partition", CMD_SINGLE, CMD_OPTIONAL, "partition name");
6095 cmd_AddParm(ts, "-dryrun", CMD_FLAG, CMD_OPTIONAL, "report without updating");
6098 ts = cmd_CreateSyntax("examine", ExamineVolume, NULL,
6099 "everything about the volume");
6100 cmd_AddParm(ts, "-id", CMD_SINGLE, 0, "volume name or ID");
6101 cmd_AddParm(ts, "-extended", CMD_FLAG, CMD_OPTIONAL,
6102 "list extended volume fields");
6103 cmd_AddParm(ts, "-format", CMD_FLAG, CMD_OPTIONAL,
6104 "machine readable format");
6106 cmd_CreateAlias(ts, "volinfo");
6108 ts = cmd_CreateSyntax("setfields", SetFields, NULL,
6109 "change volume info fields");
6110 cmd_AddParm(ts, "-id", CMD_SINGLE, 0, "volume name or ID");
6111 cmd_AddParm(ts, "-maxquota", CMD_SINGLE, CMD_OPTIONAL, "quota (KB)");
6112 cmd_AddParm(ts, "-clearuse", CMD_FLAG, CMD_OPTIONAL, "clear dayUse");
6113 cmd_AddParm(ts, "-clearVolUpCounter", CMD_FLAG, CMD_OPTIONAL, "clear volUpdateCounter");
6116 ts = cmd_CreateSyntax("offline", volOffline, NULL, "force the volume status to offline");
6117 cmd_AddParm(ts, "-server", CMD_SINGLE, 0, "server name");
6118 cmd_AddParm(ts, "-partition", CMD_SINGLE, 0, "partition name");
6119 cmd_AddParm(ts, "-id", CMD_SINGLE, 0, "volume name or ID");
6120 cmd_AddParm(ts, "-sleep", CMD_SINGLE, CMD_OPTIONAL, "seconds to sleep");
6121 cmd_AddParm(ts, "-busy", CMD_FLAG, CMD_OPTIONAL, "busy volume");
6124 ts = cmd_CreateSyntax("online", volOnline, NULL, "force the volume status to online");
6125 cmd_AddParm(ts, "-server", CMD_SINGLE, 0, "server name");
6126 cmd_AddParm(ts, "-partition", CMD_SINGLE, 0, "partition name");
6127 cmd_AddParm(ts, "-id", CMD_SINGLE, 0, "volume name or ID");
6130 ts = cmd_CreateSyntax("zap", VolumeZap, NULL,
6131 "delete the volume, don't bother with VLDB");
6132 cmd_AddParm(ts, "-server", CMD_SINGLE, 0, "machine name");
6133 cmd_AddParm(ts, "-partition", CMD_SINGLE, 0, "partition name");
6134 cmd_AddParm(ts, "-id", CMD_SINGLE, 0, "volume ID");
6135 cmd_AddParm(ts, "-force", CMD_FLAG, CMD_OPTIONAL,
6136 "force deletion of bad volumes");
6137 cmd_AddParm(ts, "-backup", CMD_FLAG, CMD_OPTIONAL,
6138 "also delete backup volume if one is found");
6141 ts = cmd_CreateSyntax("status", VolserStatus, NULL,
6142 "report on volser status");
6143 cmd_AddParm(ts, "-server", CMD_SINGLE, 0, "machine name");
6146 ts = cmd_CreateSyntax("rename", RenameVolume, NULL, "rename a volume");
6147 cmd_AddParm(ts, "-oldname", CMD_SINGLE, 0, "old volume name ");
6148 cmd_AddParm(ts, "-newname", CMD_SINGLE, 0, "new volume name ");
6151 ts = cmd_CreateSyntax("listvldb", ListVLDB, NULL,
6152 "list volumes in the VLDB");
6153 cmd_AddParm(ts, "-name", CMD_SINGLE, CMD_OPTIONAL, "volume name or ID");
6154 cmd_AddParm(ts, "-server", CMD_SINGLE, CMD_OPTIONAL, "machine name");
6155 cmd_AddParm(ts, "-partition", CMD_SINGLE, CMD_OPTIONAL, "partition name");
6156 cmd_AddParm(ts, "-locked", CMD_FLAG, CMD_OPTIONAL, "locked volumes only");
6157 cmd_AddParm(ts, "-quiet", CMD_FLAG, CMD_OPTIONAL,
6158 "generate minimal information");
6159 cmd_AddParm(ts, "-nosort", CMD_FLAG, CMD_OPTIONAL,
6160 "do not alphabetically sort the volume names");
6163 ts = cmd_CreateSyntax("backupsys", BackSys, NULL, "en masse backups");
6164 cmd_AddParm(ts, "-prefix", CMD_LIST, CMD_OPTIONAL,
6165 "common prefix on volume(s)");
6166 cmd_AddParm(ts, "-server", CMD_SINGLE, CMD_OPTIONAL, "machine name");
6167 cmd_AddParm(ts, "-partition", CMD_SINGLE, CMD_OPTIONAL, "partition name");
6168 cmd_AddParm(ts, "-exclude", CMD_FLAG, CMD_OPTIONAL,
6169 "exclude common prefix volumes");
6170 cmd_AddParm(ts, "-xprefix", CMD_LIST, CMD_OPTIONAL,
6171 "negative prefix on volume(s)");
6172 cmd_AddParm(ts, "-dryrun", CMD_FLAG, CMD_OPTIONAL, "no action");
6175 ts = cmd_CreateSyntax("delentry", DeleteEntry, NULL,
6176 "delete VLDB entry for a volume");
6177 cmd_AddParm(ts, "-id", CMD_LIST, CMD_OPTIONAL, "volume name or ID");
6178 cmd_AddParm(ts, "-prefix", CMD_SINGLE, CMD_OPTIONAL,
6179 "prefix of the volume whose VLDB entry is to be deleted");
6180 cmd_AddParm(ts, "-server", CMD_SINGLE, CMD_OPTIONAL, "machine name");
6181 cmd_AddParm(ts, "-partition", CMD_SINGLE, CMD_OPTIONAL, "partition name");
6182 cmd_AddParm(ts, "-noexecute", CMD_FLAG, CMD_OPTIONAL,
6186 ts = cmd_CreateSyntax("partinfo", PartitionInfo, NULL,
6187 "list partition information");
6188 cmd_AddParm(ts, "-server", CMD_SINGLE, 0, "machine name");
6189 cmd_AddParm(ts, "-partition", CMD_SINGLE, CMD_OPTIONAL, "partition name");
6190 cmd_AddParm(ts, "-summary", CMD_FLAG, CMD_OPTIONAL,
6191 "print storage summary");
6194 ts = cmd_CreateSyntax("unlockvldb", UnlockVLDB, NULL,
6195 "unlock all the locked entries in the VLDB");
6196 cmd_AddParm(ts, "-server", CMD_SINGLE, CMD_OPTIONAL, "machine name");
6197 cmd_AddParm(ts, "-partition", CMD_SINGLE, CMD_OPTIONAL, "partition name");
6200 ts = cmd_CreateSyntax("lock", LockEntry, NULL,
6201 "lock VLDB entry for a volume");
6202 cmd_AddParm(ts, "-id", CMD_SINGLE, 0, "volume name or ID");
6205 ts = cmd_CreateSyntax("changeaddr", ChangeAddr, NULL,
6206 "change the IP address of a file server");
6207 cmd_AddParm(ts, "-oldaddr", CMD_SINGLE, 0, "original IP address");
6208 cmd_AddParm(ts, "-newaddr", CMD_SINGLE, CMD_OPTIONAL, "new IP address");
6209 cmd_AddParm(ts, "-remove", CMD_FLAG, CMD_OPTIONAL,
6210 "remove the IP address from the VLDB");
6213 ts = cmd_CreateSyntax("listaddrs", ListAddrs, NULL,
6214 "list the IP address of all file servers registered in the VLDB");
6215 cmd_AddParm(ts, "-uuid", CMD_SINGLE, CMD_OPTIONAL, "uuid of server");
6216 cmd_AddParm(ts, "-host", CMD_SINGLE, CMD_OPTIONAL, "address of host");
6217 cmd_AddParm(ts, "-printuuid", CMD_FLAG, CMD_OPTIONAL,
6218 "print uuid of hosts");
6221 ts = cmd_CreateSyntax("convertROtoRW", ConvertRO, NULL,
6222 "convert a RO volume into a RW volume (after loss of old RW volume)");
6223 cmd_AddParm(ts, "-server", CMD_SINGLE, 0, "machine name");
6224 cmd_AddParm(ts, "-partition", CMD_SINGLE, 0, "partition name");
6225 cmd_AddParm(ts, "-id", CMD_SINGLE, 0, "volume name or ID");
6226 cmd_AddParm(ts, "-force", CMD_FLAG, CMD_OPTIONAL, "don't ask");
6229 ts = cmd_CreateSyntax("size", Sizes, NULL,
6230 "obtain various sizes of the volume.");
6231 cmd_AddParm(ts, "-id", CMD_SINGLE, 0, "volume name or ID");
6232 cmd_AddParm(ts, "-partition", CMD_SINGLE, CMD_OPTIONAL, "partition name");
6233 cmd_AddParm(ts, "-server", CMD_SINGLE, CMD_OPTIONAL, "machine name");
6234 cmd_AddParm(ts, "-dump", CMD_FLAG, CMD_OPTIONAL,
6235 "Obtain the size of the dump");
6236 cmd_AddParm(ts, "-time", CMD_SINGLE, CMD_OPTIONAL, "dump from time");
6239 ts = cmd_CreateSyntax("endtrans", EndTrans, NULL,
6240 "end a volserver transaction");
6241 cmd_AddParm(ts, "-server", CMD_SINGLE, 0, "machine name");
6242 cmd_AddParm(ts, "-transaction", CMD_SINGLE, 0,
6246 ts = cmd_CreateSyntax("setaddrs", SetAddrs, NULL,
6247 "set the list of IP address for a given UUID in the VLDB");
6248 cmd_AddParm(ts, "-uuid", CMD_SINGLE, 0, "uuid of server");
6249 cmd_AddParm(ts, "-host", CMD_LIST, 0, "address of host");
6252 code = cmd_Dispatch(argc, argv);
6254 /* Shut down the ubik_client and rx connections */
6256 (void)ubik_ClientDestroy(cstruct);
6262 exit((code ? -1 : 0));