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_uint32 *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_uint32 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_uint32 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_uint32 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_uint32 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_uint32 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_uint32 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_uint32 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_uint32 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_uint32 *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 PrintLocked(afs_int32 aflags)
1415 afs_int32 flags = aflags & VLOP_ALLOPERS;
1418 fprintf(STDOUT, " Volume is currently LOCKED \n");
1420 if (flags & VLOP_MOVE) {
1421 fprintf(STDOUT, " Volume is locked for a move operation\n");
1423 if (flags & VLOP_RELEASE) {
1424 fprintf(STDOUT, " Volume is locked for a release operation\n");
1426 if (flags & VLOP_BACKUP) {
1427 fprintf(STDOUT, " Volume is locked for a backup operation\n");
1429 if (flags & VLOP_DELETE) {
1430 fprintf(STDOUT, " Volume is locked for a delete/misc operation\n");
1432 if (flags & VLOP_DUMP) {
1433 fprintf(STDOUT, " Volume is locked for a dump/restore operation\n");
1439 PostVolumeStats(struct nvldbentry *entry)
1441 SubEnumerateEntry(entry);
1442 /* Check for VLOP_ALLOPERS */
1443 PrintLocked(entry->flags);
1447 /*------------------------------------------------------------------------
1448 * PRIVATE XVolumeStats
1451 * Display extended volume information.
1454 * a_xInfoP : Ptr to extended volume info.
1455 * a_entryP : Ptr to the volume's VLDB entry.
1456 * a_srvID : Server ID.
1457 * a_partID : Partition ID.
1458 * a_volType : Type of volume to print.
1464 * Nothing interesting.
1468 *------------------------------------------------------------------------*/
1471 XVolumeStats(volintXInfo *a_xInfoP, struct nvldbentry *a_entryP,
1472 afs_int32 a_srvID, afs_int32 a_partID, int a_volType)
1475 int totalOK, totalNotOK, totalBusy; /*Dummies - we don't really count here */
1477 XDisplayFormat(a_xInfoP, /*Ptr to extended volume info */
1478 a_srvID, /*Server ID to print */
1479 a_partID, /*Partition ID to print */
1480 &totalOK, /*Ptr to total-OK counter */
1481 &totalNotOK, /*Ptr to total-screwed counter */
1482 &totalBusy, /*Ptr to total-busy counter */
1483 0, /*Don't do a fast listing */
1484 1, /*Do a long listing */
1485 1); /*Show volume problems */
1491 VolumeStats_int(volintInfo *pntr, struct nvldbentry *entry, afs_uint32 server,
1492 afs_int32 part, int voltype)
1494 int totalOK, totalNotOK, totalBusy;
1496 DisplayFormat(pntr, server, part, &totalOK, &totalNotOK, &totalBusy, 0, 1,
1501 /* command to forcibly remove a volume */
1503 NukeVolume(register struct cmd_syndesc *as)
1505 register afs_int32 code;
1512 server = GetServer(tp = as->parms[0].items->data);
1514 fprintf(STDERR, "vos: server '%s' not found in host table\n", tp);
1518 partID = volutil_GetPartitionID(tp = as->parms[1].items->data);
1520 fprintf(STDERR, "vos: could not parse '%s' as a partition name", tp);
1524 volID = vsu_GetVolumeID(tp = as->parms[2].items->data, cstruct, &err);
1527 PrintError("", err);
1530 "vos: could not parse '%s' as a numeric volume ID", tp);
1535 "vos: forcibly removing all traces of volume %d, please wait...",
1538 code = UV_NukeVolume(server, partID, volID);
1540 fprintf(STDOUT, "done.\n");
1542 fprintf(STDOUT, "failed with code %d.\n", code);
1547 /*------------------------------------------------------------------------
1548 * PRIVATE ExamineVolume
1551 * Routine used to examine a single volume, contacting the VLDB as
1552 * well as the Volume Server.
1555 * as : Ptr to parsed command line arguments.
1558 * 0 for a successful operation,
1559 * Otherwise, one of the ubik or VolServer error values.
1562 * Nothing interesting.
1566 *------------------------------------------------------------------------
1569 ExamineVolume(register struct cmd_syndesc *as, void *arock)
1571 struct nvldbentry entry;
1572 afs_int32 vcode = 0;
1573 volintInfo *pntr = (volintInfo *) 0;
1574 volintXInfo *xInfoP = (volintXInfo *) 0;
1576 afs_int32 code, err, error = 0;
1577 int voltype, foundserv = 0, foundentry = 0;
1581 int wantExtendedInfo; /*Do we want extended vol info? */
1583 wantExtendedInfo = (as->parms[1].items ? 1 : 0); /* -extended */
1585 volid = vsu_GetVolumeID(as->parms[0].items->data, cstruct, &err); /* -id */
1588 PrintError("", err);
1590 fprintf(STDERR, "Unknown volume ID or name '%s'\n",
1591 as->parms[0].items->data);
1596 fprintf(STDOUT, "Fetching VLDB entry for %lu .. ",
1597 (unsigned long)volid);
1600 vcode = VLDB_GetEntryByID(volid, -1, &entry);
1603 "Could not fetch the entry for volume number %lu from VLDB \n",
1604 (unsigned long)volid);
1608 fprintf(STDOUT, "done\n");
1609 MapHostToNetwork(&entry);
1611 if (entry.volumeId[RWVOL] == volid)
1613 else if (entry.volumeId[BACKVOL] == volid)
1615 else /* (entry.volumeId[ROVOL] == volid) */
1618 do { /* do {...} while (voltype == ROVOL) */
1619 /* Get the entry for the volume. If its a RW vol, get the RW entry.
1620 * It its a BK vol, get the RW entry (even if VLDB may say the BK doen't exist).
1621 * If its a RO vol, get the next RO entry.
1623 GetServerAndPart(&entry, ((voltype == ROVOL) ? ROVOL : RWVOL),
1624 &aserver, &apart, &previdx);
1625 if (previdx == -1) { /* searched all entries */
1627 fprintf(STDERR, "Volume %s does not exist in VLDB\n\n",
1628 as->parms[0].items->data);
1635 /* Get information about the volume from the server */
1637 fprintf(STDOUT, "Getting volume listing from the server %s .. ",
1638 hostutil_GetNameByINet(aserver));
1641 if (wantExtendedInfo)
1642 code = UV_XListOneVolume(aserver, apart, volid, &xInfoP);
1644 code = UV_ListOneVolume(aserver, apart, volid, &pntr);
1646 fprintf(STDOUT, "done\n");
1650 if (code == ENODEV) {
1651 if ((voltype == BACKVOL) && !(entry.flags & BACK_EXISTS)) {
1652 /* The VLDB says there is no backup volume and its not on disk */
1653 fprintf(STDERR, "Volume %s does not exist\n",
1654 as->parms[0].items->data);
1658 "Volume does not exist on server %s as indicated by the VLDB\n",
1659 hostutil_GetNameByINet(aserver));
1662 PrintDiagnostics("examine", code);
1664 fprintf(STDOUT, "\n");
1667 if (wantExtendedInfo)
1668 XVolumeStats(xInfoP, &entry, aserver, apart, voltype);
1669 else if (as->parms[2].items) {
1670 DisplayFormat2(aserver, apart, pntr);
1671 EnumerateEntry(&entry);
1673 VolumeStats_int(pntr, &entry, aserver, apart, voltype);
1675 if ((voltype == BACKVOL) && !(entry.flags & BACK_EXISTS)) {
1676 /* The VLDB says there is no backup volume yet we found one on disk */
1677 fprintf(STDERR, "Volume %s does not exist in VLDB\n",
1678 as->parms[0].items->data);
1687 } while (voltype == ROVOL);
1690 fprintf(STDERR, "Dump only information from VLDB\n\n");
1691 fprintf(STDOUT, "%s \n", entry.name); /* PostVolumeStats doesn't print name */
1693 PostVolumeStats(&entry);
1698 /*------------------------------------------------------------------------
1702 * Routine used to change the status of a single volume.
1705 * as : Ptr to parsed command line arguments.
1708 * 0 for a successful operation,
1709 * Otherwise, one of the ubik or VolServer error values.
1712 * Nothing interesting.
1716 *------------------------------------------------------------------------
1719 SetFields(register struct cmd_syndesc *as, void *arock)
1721 struct nvldbentry entry;
1724 afs_int32 code, err;
1729 volid = vsu_GetVolumeID(as->parms[0].items->data, cstruct, &err); /* -id */
1732 PrintError("", err);
1734 fprintf(STDERR, "Unknown volume ID or name '%s'\n",
1735 as->parms[0].items->data);
1739 code = VLDB_GetEntryByID(volid, RWVOL, &entry);
1742 "Could not fetch the entry for volume number %lu from VLDB \n",
1743 (unsigned long)volid);
1746 MapHostToNetwork(&entry);
1748 GetServerAndPart(&entry, RWVOL, &aserver, &apart, &previdx);
1749 if (previdx == -1) {
1750 fprintf(STDERR, "Volume %s does not exist in VLDB\n\n",
1751 as->parms[0].items->data);
1755 init_volintInfo(&info);
1759 if (as->parms[1].items) {
1761 code = util_GetHumanInt32(as->parms[1].items->data, &info.maxquota);
1763 fprintf(STDERR, "invalid quota value\n");
1767 if (as->parms[2].items) {
1771 if (as->parms[3].items) {
1772 /* -clearVolUpCounter */
1775 code = UV_SetVolumeInfo(aserver, apart, volid, &info);
1778 "Could not update volume info fields for volume number %lu\n",
1779 (unsigned long)volid);
1783 /*------------------------------------------------------------------------
1787 * Brings a volume online.
1790 * as : Ptr to parsed command line arguments.
1793 * 0 for a successful operation,
1796 * Nothing interesting.
1800 *------------------------------------------------------------------------
1803 volOnline(register struct cmd_syndesc *as, void *arock)
1806 afs_int32 partition;
1808 afs_int32 code, err = 0;
1810 server = GetServer(as->parms[0].items->data);
1812 fprintf(STDERR, "vos: server '%s' not found in host table\n",
1813 as->parms[0].items->data);
1817 partition = volutil_GetPartitionID(as->parms[1].items->data);
1818 if (partition < 0) {
1819 fprintf(STDERR, "vos: could not interpret partition name '%s'\n",
1820 as->parms[1].items->data);
1824 volid = vsu_GetVolumeID(as->parms[2].items->data, cstruct, &err); /* -id */
1827 PrintError("", err);
1829 fprintf(STDERR, "Unknown volume ID or name '%s'\n",
1830 as->parms[0].items->data);
1834 code = UV_SetVolume(server, partition, volid, ITOffline, 0 /*online */ ,
1837 fprintf(STDERR, "Failed to set volume. Code = %d\n", code);
1844 /*------------------------------------------------------------------------
1845 * PRIVATE volOffline
1848 * Brings a volume offline.
1851 * as : Ptr to parsed command line arguments.
1854 * 0 for a successful operation,
1857 * Nothing interesting.
1861 *------------------------------------------------------------------------
1864 volOffline(register struct cmd_syndesc *as, void *arock)
1867 afs_int32 partition;
1869 afs_int32 code, err = 0;
1870 afs_int32 transflag, sleeptime, transdone;
1872 server = GetServer(as->parms[0].items->data);
1874 fprintf(STDERR, "vos: server '%s' not found in host table\n",
1875 as->parms[0].items->data);
1879 partition = volutil_GetPartitionID(as->parms[1].items->data);
1880 if (partition < 0) {
1881 fprintf(STDERR, "vos: could not interpret partition name '%s'\n",
1882 as->parms[1].items->data);
1886 volid = vsu_GetVolumeID(as->parms[2].items->data, cstruct, &err); /* -id */
1889 PrintError("", err);
1891 fprintf(STDERR, "Unknown volume ID or name '%s'\n",
1892 as->parms[0].items->data);
1896 transflag = (as->parms[4].items ? ITBusy : ITOffline);
1897 sleeptime = (as->parms[3].items ? atol(as->parms[3].items->data) : 0);
1898 transdone = (sleeptime ? 0 /*online */ : VTOutOfService);
1899 if (as->parms[4].items && !as->parms[3].items) {
1900 fprintf(STDERR, "-sleep option must be used with -busy flag\n");
1905 UV_SetVolume(server, partition, volid, transflag, transdone,
1908 fprintf(STDERR, "Failed to set volume. Code = %d\n", code);
1916 CreateVolume(register struct cmd_syndesc *as, void *arock)
1920 afs_uint32 volid = 0, rovolid = 0, bkvolid = 0;
1921 afs_uint32 *arovolid;
1923 struct nvldbentry entry;
1927 arovolid = &rovolid;
1930 tserver = GetServer(as->parms[0].items->data);
1932 fprintf(STDERR, "vos: host '%s' not found in host table\n",
1933 as->parms[0].items->data);
1936 pnum = volutil_GetPartitionID(as->parms[1].items->data);
1938 fprintf(STDERR, "vos: could not interpret partition name '%s'\n",
1939 as->parms[1].items->data);
1942 if (!IsPartValid(pnum, tserver, &code)) { /*check for validity of the partition */
1944 PrintError("", code);
1947 "vos : partition %s does not exist on the server\n",
1948 as->parms[1].items->data);
1951 if (!ISNAMEVALID(as->parms[2].items->data)) {
1953 "vos: the name of the root volume %s exceeds the size limit of %d\n",
1954 as->parms[2].items->data, VOLSER_OLDMAXVOLNAME - 10);
1957 if (!VolNameOK(as->parms[2].items->data)) {
1959 "Illegal volume name %s, should not end in .readonly or .backup\n",
1960 as->parms[2].items->data);
1963 if (IsNumeric(as->parms[2].items->data)) {
1964 fprintf(STDERR, "Illegal volume name %s, should not be a number\n",
1965 as->parms[2].items->data);
1968 vcode = VLDB_GetEntryByName(as->parms[2].items->data, &entry);
1970 fprintf(STDERR, "Volume %s already exists\n",
1971 as->parms[2].items->data);
1972 PrintDiagnostics("create", code);
1976 if (as->parms[3].items) {
1977 code = util_GetHumanInt32(as->parms[3].items->data, "a);
1979 fprintf(STDERR, "vos: bad integer specified for quota.\n");
1984 if (as->parms[4].items) {
1985 if (!IsNumeric(as->parms[4].items->data)) {
1986 fprintf(STDERR, "vos: Given volume ID %s should be numeric.\n",
1987 as->parms[4].items->data);
1991 code = util_GetUInt32(as->parms[4].items->data, &volid);
1993 fprintf(STDERR, "vos: bad integer specified for volume ID.\n");
1998 if (as->parms[5].items) {
1999 if (!IsNumeric(as->parms[5].items->data)) {
2000 fprintf(STDERR, "vos: Given RO volume ID %s should be numeric.\n",
2001 as->parms[5].items->data);
2005 code = util_GetUInt32(as->parms[5].items->data, &rovolid);
2007 fprintf(STDERR, "vos: bad integer specified for volume ID.\n");
2017 UV_CreateVolume3(tserver, pnum, as->parms[2].items->data, quota, 0,
2018 0, 0, 0, &volid, arovolid, &bkvolid);
2020 PrintDiagnostics("create", code);
2023 MapPartIdIntoName(pnum, part);
2024 fprintf(STDOUT, "Volume %lu created on partition %s of %s\n",
2025 (unsigned long)volid, part, as->parms[0].items->data);
2032 DeleteAll(struct nvldbentry *entry)
2035 afs_int32 error, code, curserver, curpart;
2038 MapHostToNetwork(entry);
2040 for (i = 0; i < entry->nServers; i++) {
2041 curserver = entry->serverNumber[i];
2042 curpart = entry->serverPartition[i];
2043 if (entry->serverFlags[i] & ITSROVOL) {
2044 volid = entry->volumeId[ROVOL];
2046 volid = entry->volumeId[RWVOL];
2048 code = UV_DeleteVolume(curserver, curpart, volid);
2057 DeleteVolume(struct cmd_syndesc *as, void *arock)
2059 afs_int32 err, code = 0;
2060 afs_uint32 server = 0;
2061 afs_int32 partition = -1;
2066 if (as->parms[0].items) {
2067 server = GetServer(as->parms[0].items->data);
2069 fprintf(STDERR, "vos: server '%s' not found in host table\n",
2070 as->parms[0].items->data);
2075 if (as->parms[1].items) {
2076 partition = volutil_GetPartitionID(as->parms[1].items->data);
2077 if (partition < 0) {
2078 fprintf(STDERR, "vos: could not interpret partition name '%s'\n",
2079 as->parms[1].items->data);
2083 /* Check for validity of the partition */
2084 if (!IsPartValid(partition, server, &code)) {
2086 PrintError("", code);
2089 "vos : partition %s does not exist on the server\n",
2090 as->parms[1].items->data);
2096 volid = vsu_GetVolumeID(as->parms[2].items->data, cstruct, &err);
2098 fprintf(STDERR, "Can't find volume name '%s' in VLDB\n",
2099 as->parms[2].items->data);
2101 PrintError("", err);
2105 /* If the server or partition option are not complete, try to fill
2106 * them in from the VLDB entry.
2108 if ((partition == -1) || !server) {
2109 struct nvldbentry entry;
2111 code = VLDB_GetEntryByID(volid, -1, &entry);
2114 "Could not fetch the entry for volume %lu from VLDB\n",
2115 (unsigned long)volid);
2116 PrintError("", code);
2120 if (((volid == entry.volumeId[RWVOL]) && (entry.flags & RW_EXISTS))
2121 || ((volid == entry.volumeId[BACKVOL])
2122 && (entry.flags & BACK_EXISTS))) {
2123 idx = Lp_GetRwIndex(&entry);
2124 if ((idx == -1) || (server && (server != entry.serverNumber[idx]))
2125 || ((partition != -1)
2126 && (partition != entry.serverPartition[idx]))) {
2127 fprintf(STDERR, "VLDB: Volume '%s' no match\n",
2128 as->parms[2].items->data);
2131 } else if ((volid == entry.volumeId[ROVOL])
2132 && (entry.flags & RO_EXISTS)) {
2133 for (idx = -1, j = 0; j < entry.nServers; j++) {
2134 if (entry.serverFlags[j] != ITSROVOL)
2137 if (((server == 0) || (server == entry.serverNumber[j]))
2138 && ((partition == -1)
2139 || (partition == entry.serverPartition[j]))) {
2142 "VLDB: Volume '%s' matches more than one RO\n",
2143 as->parms[2].items->data);
2150 fprintf(STDERR, "VLDB: Volume '%s' no match\n",
2151 as->parms[2].items->data);
2155 fprintf(STDERR, "VLDB: Volume '%s' no match\n",
2156 as->parms[2].items->data);
2160 server = htonl(entry.serverNumber[idx]);
2161 partition = entry.serverPartition[idx];
2165 code = UV_DeleteVolume(server, partition, volid);
2167 PrintDiagnostics("remove", code);
2171 MapPartIdIntoName(partition, pname);
2172 fprintf(STDOUT, "Volume %lu on partition %s server %s deleted\n",
2173 (unsigned long)volid, pname, hostutil_GetNameByINet(server));
2177 #define TESTM 0 /* set for move space tests, clear for production */
2179 MoveVolume(register struct cmd_syndesc *as, void *arock)
2183 afs_uint32 fromserver, toserver;
2184 afs_int32 frompart, topart;
2185 afs_int32 flags, code, err;
2186 char fromPartName[10], toPartName[10];
2188 struct diskPartition64 partition; /* for space check */
2191 volid = vsu_GetVolumeID(as->parms[0].items->data, cstruct, &err);
2194 PrintError("", err);
2196 fprintf(STDERR, "vos: can't find volume ID or name '%s'\n",
2197 as->parms[0].items->data);
2200 fromserver = GetServer(as->parms[1].items->data);
2201 if (fromserver == 0) {
2202 fprintf(STDERR, "vos: server '%s' not found in host table\n",
2203 as->parms[1].items->data);
2206 toserver = GetServer(as->parms[3].items->data);
2207 if (toserver == 0) {
2208 fprintf(STDERR, "vos: server '%s' not found in host table\n",
2209 as->parms[3].items->data);
2212 frompart = volutil_GetPartitionID(as->parms[2].items->data);
2214 fprintf(STDERR, "vos: could not interpret partition name '%s'\n",
2215 as->parms[2].items->data);
2218 if (!IsPartValid(frompart, fromserver, &code)) { /*check for validity of the partition */
2220 PrintError("", code);
2223 "vos : partition %s does not exist on the server\n",
2224 as->parms[2].items->data);
2227 topart = volutil_GetPartitionID(as->parms[4].items->data);
2229 fprintf(STDERR, "vos: could not interpret partition name '%s'\n",
2230 as->parms[4].items->data);
2233 if (!IsPartValid(topart, toserver, &code)) { /*check for validity of the partition */
2235 PrintError("", code);
2238 "vos : partition %s does not exist on the server\n",
2239 as->parms[4].items->data);
2244 if (as->parms[5].items) flags |= RV_NOCLONE;
2247 * check source partition for space to clone volume
2250 MapPartIdIntoName(topart, toPartName);
2251 MapPartIdIntoName(frompart, fromPartName);
2254 * check target partition for space to move volume
2257 code = UV_PartitionInfo64(toserver, toPartName, &partition);
2259 fprintf(STDERR, "vos: cannot access partition %s\n", toPartName);
2263 fprintf(STDOUT, "target partition %s free space %" AFS_INT64_FMT "\n", toPartName,
2266 p = (volintInfo *) 0;
2267 code = UV_ListOneVolume(fromserver, frompart, volid, &p);
2269 fprintf(STDERR, "vos:cannot access volume %lu\n",
2270 (unsigned long)volid);
2274 fprintf(STDOUT, "volume %lu size %d\n", (unsigned long)volid,
2276 if (partition.free <= p->size) {
2278 "vos: no space on target partition %s to move volume %lu\n",
2279 toPartName, (unsigned long)volid);
2286 fprintf(STDOUT, "size test - don't do move\n");
2290 /* successful move still not guaranteed but shoot for it */
2293 UV_MoveVolume2(volid, fromserver, frompart, toserver, topart, flags);
2295 PrintDiagnostics("move", code);
2298 MapPartIdIntoName(topart, toPartName);
2299 MapPartIdIntoName(frompart, fromPartName);
2300 fprintf(STDOUT, "Volume %lu moved from %s %s to %s %s \n",
2301 (unsigned long)volid, as->parms[1].items->data, fromPartName,
2302 as->parms[3].items->data, toPartName);
2308 CopyVolume(register struct cmd_syndesc *as, void *arock)
2311 afs_uint32 fromserver, toserver;
2312 afs_int32 frompart, topart, code, err, flags;
2313 char fromPartName[10], toPartName[10], *tovolume;
2314 struct nvldbentry entry;
2315 struct diskPartition64 partition; /* for space check */
2318 volid = vsu_GetVolumeID(as->parms[0].items->data, cstruct, &err);
2321 PrintError("", err);
2323 fprintf(STDERR, "vos: can't find volume ID or name '%s'\n",
2324 as->parms[0].items->data);
2327 fromserver = GetServer(as->parms[1].items->data);
2328 if (fromserver == 0) {
2329 fprintf(STDERR, "vos: server '%s' not found in host table\n",
2330 as->parms[1].items->data);
2334 toserver = GetServer(as->parms[4].items->data);
2335 if (toserver == 0) {
2336 fprintf(STDERR, "vos: server '%s' not found in host table\n",
2337 as->parms[4].items->data);
2341 tovolume = as->parms[3].items->data;
2342 if (!ISNAMEVALID(tovolume)) {
2344 "vos: the name of the root volume %s exceeds the size limit of %d\n",
2345 tovolume, VOLSER_OLDMAXVOLNAME - 10);
2348 if (!VolNameOK(tovolume)) {
2350 "Illegal volume name %s, should not end in .readonly or .backup\n",
2354 if (IsNumeric(tovolume)) {
2355 fprintf(STDERR, "Illegal volume name %s, should not be a number\n",
2359 code = VLDB_GetEntryByName(tovolume, &entry);
2361 fprintf(STDERR, "Volume %s already exists\n", tovolume);
2362 PrintDiagnostics("copy", code);
2366 frompart = volutil_GetPartitionID(as->parms[2].items->data);
2368 fprintf(STDERR, "vos: could not interpret partition name '%s'\n",
2369 as->parms[2].items->data);
2372 if (!IsPartValid(frompart, fromserver, &code)) { /*check for validity of the partition */
2374 PrintError("", code);
2377 "vos : partition %s does not exist on the server\n",
2378 as->parms[2].items->data);
2382 topart = volutil_GetPartitionID(as->parms[5].items->data);
2384 fprintf(STDERR, "vos: could not interpret partition name '%s'\n",
2385 as->parms[5].items->data);
2388 if (!IsPartValid(topart, toserver, &code)) { /*check for validity of the partition */
2390 PrintError("", code);
2393 "vos : partition %s does not exist on the server\n",
2394 as->parms[5].items->data);
2399 if (as->parms[6].items) flags |= RV_OFFLINE;
2400 if (as->parms[7].items) flags |= RV_RDONLY;
2401 if (as->parms[8].items) flags |= RV_NOCLONE;
2403 MapPartIdIntoName(topart, toPartName);
2404 MapPartIdIntoName(frompart, fromPartName);
2407 * check target partition for space to move volume
2410 code = UV_PartitionInfo64(toserver, toPartName, &partition);
2412 fprintf(STDERR, "vos: cannot access partition %s\n", toPartName);
2416 fprintf(STDOUT, "target partition %s free space %" AFS_INT64_FMT "\n", toPartName,
2419 p = (volintInfo *) 0;
2420 code = UV_ListOneVolume(fromserver, frompart, volid, &p);
2422 fprintf(STDERR, "vos:cannot access volume %lu\n",
2423 (unsigned long)volid);
2427 if (partition.free <= p->size) {
2429 "vos: no space on target partition %s to copy volume %lu\n",
2430 toPartName, (unsigned long)volid);
2436 /* successful copy still not guaranteed but shoot for it */
2439 UV_CopyVolume2(volid, fromserver, frompart, tovolume, toserver,
2442 PrintDiagnostics("copy", code);
2445 MapPartIdIntoName(topart, toPartName);
2446 MapPartIdIntoName(frompart, fromPartName);
2447 fprintf(STDOUT, "Volume %lu copied from %s %s to %s on %s %s \n",
2448 (unsigned long)volid, as->parms[1].items->data, fromPartName,
2449 tovolume, as->parms[4].items->data, toPartName);
2456 ShadowVolume(register struct cmd_syndesc *as, void *arock)
2458 afs_uint32 volid, tovolid;
2459 afs_uint32 fromserver, toserver;
2460 afs_int32 frompart, topart;
2461 afs_int32 code, err, flags;
2462 char fromPartName[10], toPartName[10], toVolName[32], *tovolume;
2463 struct diskPartition64 partition; /* for space check */
2466 p = (volintInfo *) 0;
2467 q = (volintInfo *) 0;
2469 volid = vsu_GetVolumeID(as->parms[0].items->data, cstruct, &err);
2472 PrintError("", err);
2474 fprintf(STDERR, "vos: can't find volume ID or name '%s'\n",
2475 as->parms[0].items->data);
2478 fromserver = GetServer(as->parms[1].items->data);
2479 if (fromserver == 0) {
2480 fprintf(STDERR, "vos: server '%s' not found in host table\n",
2481 as->parms[1].items->data);
2485 toserver = GetServer(as->parms[3].items->data);
2486 if (toserver == 0) {
2487 fprintf(STDERR, "vos: server '%s' not found in host table\n",
2488 as->parms[3].items->data);
2492 frompart = volutil_GetPartitionID(as->parms[2].items->data);
2494 fprintf(STDERR, "vos: could not interpret partition name '%s'\n",
2495 as->parms[2].items->data);
2498 if (!IsPartValid(frompart, fromserver, &code)) { /*check for validity of the partition */
2500 PrintError("", code);
2503 "vos : partition %s does not exist on the server\n",
2504 as->parms[2].items->data);
2508 topart = volutil_GetPartitionID(as->parms[4].items->data);
2510 fprintf(STDERR, "vos: could not interpret partition name '%s'\n",
2511 as->parms[4].items->data);
2514 if (!IsPartValid(topart, toserver, &code)) { /*check for validity of the partition */
2516 PrintError("", code);
2519 "vos : partition %s does not exist on the server\n",
2520 as->parms[4].items->data);
2524 if (as->parms[5].items) {
2525 tovolume = as->parms[5].items->data;
2526 if (!ISNAMEVALID(tovolume)) {
2528 "vos: the name of the root volume %s exceeds the size limit of %d\n",
2529 tovolume, VOLSER_OLDMAXVOLNAME - 10);
2532 if (!VolNameOK(tovolume)) {
2534 "Illegal volume name %s, should not end in .readonly or .backup\n",
2538 if (IsNumeric(tovolume)) {
2540 "Illegal volume name %s, should not be a number\n",
2545 /* use actual name of source volume */
2546 code = UV_ListOneVolume(fromserver, frompart, volid, &p);
2548 fprintf(STDERR, "vos:cannot access volume %lu\n",
2549 (unsigned long)volid);
2552 strcpy(toVolName, p->name);
2553 tovolume = toVolName;
2554 /* save p for size checks later */
2557 if (as->parms[6].items) {
2558 tovolid = vsu_GetVolumeID(as->parms[6].items->data, cstruct, &err);
2561 PrintError("", err);
2563 fprintf(STDERR, "vos: can't find volume ID or name '%s'\n",
2564 as->parms[6].items->data);
2570 tovolid = vsu_GetVolumeID(tovolume, cstruct, &err);
2573 PrintError("", err);
2575 fprintf(STDERR, "vos: can't find volume ID or name '%s'\n",
2584 if (as->parms[7].items) flags |= RV_OFFLINE;
2585 if (as->parms[8].items) flags |= RV_RDONLY;
2586 if (as->parms[9].items) flags |= RV_NOCLONE;
2587 if (as->parms[10].items) flags |= RV_CPINCR;
2589 MapPartIdIntoName(topart, toPartName);
2590 MapPartIdIntoName(frompart, fromPartName);
2593 * check target partition for space to move volume
2596 code = UV_PartitionInfo64(toserver, toPartName, &partition);
2598 fprintf(STDERR, "vos: cannot access partition %s\n", toPartName);
2602 fprintf(STDOUT, "target partition %s free space %" AFS_INT64_FMT "\n", toPartName,
2605 /* Don't do this again if we did it above */
2607 code = UV_ListOneVolume(fromserver, frompart, volid, &p);
2609 fprintf(STDERR, "vos:cannot access volume %lu\n",
2610 (unsigned long)volid);
2615 /* OK if this fails */
2616 code = UV_ListOneVolume(toserver, topart, tovolid, &q);
2618 /* Treat existing volume size as "free" */
2620 p->size = (q->size < p->size) ? p->size - q->size : 0;
2622 if (partition.free <= p->size) {
2624 "vos: no space on target partition %s to copy volume %lu\n",
2625 toPartName, (unsigned long)volid);
2633 /* successful copy still not guaranteed but shoot for it */
2636 UV_CopyVolume2(volid, fromserver, frompart, tovolume, toserver,
2637 topart, tovolid, flags);
2639 PrintDiagnostics("shadow", code);
2642 MapPartIdIntoName(topart, toPartName);
2643 MapPartIdIntoName(frompart, fromPartName);
2644 fprintf(STDOUT, "Volume %lu shadowed from %s %s to %s %s \n",
2645 (unsigned long)volid, as->parms[1].items->data, fromPartName,
2646 as->parms[3].items->data, toPartName);
2653 CloneVolume(register struct cmd_syndesc *as, void *arock)
2655 afs_uint32 volid, cloneid;
2657 afs_int32 part, voltype;
2658 char partName[10], *volname;
2659 afs_int32 code, err, flags;
2660 struct nvldbentry entry;
2662 volid = vsu_GetVolumeID(as->parms[0].items->data, cstruct, &err);
2665 PrintError("", err);
2667 fprintf(STDERR, "vos: can't find volume ID or name '%s'\n",
2668 as->parms[0].items->data);
2672 if (as->parms[1].items || as->parms[2].items) {
2673 if (!as->parms[1].items || !as->parms[2].items) {
2675 "Must specify both -server and -partition options\n");
2678 server = GetServer(as->parms[1].items->data);
2680 fprintf(STDERR, "vos: server '%s' not found in host table\n",
2681 as->parms[1].items->data);
2684 part = volutil_GetPartitionID(as->parms[2].items->data);
2686 fprintf(STDERR, "vos: could not interpret partition name '%s'\n",
2687 as->parms[2].items->data);
2690 if (!IsPartValid(part, server, &code)) { /*check for validity of the partition */
2692 PrintError("", code);
2695 "vos : partition %s does not exist on the server\n",
2696 as->parms[2].items->data);
2700 code = GetVolumeInfo(volid, &server, &part, &voltype, &entry);
2706 if (as->parms[3].items) {
2707 volname = as->parms[3].items->data;
2708 if (strlen(volname) > VOLSER_OLDMAXVOLNAME - 1) {
2710 "vos: the name of the root volume %s exceeds the size limit of %d\n",
2711 volname, VOLSER_OLDMAXVOLNAME - 1);
2716 * In order that you be able to make clones of RO or BK, this
2717 * check must be omitted.
2719 if (!VolNameOK(volname)) {
2721 "Illegal volume name %s, should not end in .readonly or .backup\n",
2726 if (IsNumeric(volname)) {
2728 "Illegal volume name %s, should not be a number\n",
2735 if (as->parms[4].items) {
2736 cloneid = vsu_GetVolumeID(as->parms[4].items->data, cstruct, &err);
2739 PrintError("", err);
2741 fprintf(STDERR, "vos: can't find volume ID or name '%s'\n",
2742 as->parms[4].items->data);
2748 if (as->parms[5].items) flags |= RV_OFFLINE;
2749 if (as->parms[6].items) flags |= RV_RDONLY;
2753 UV_CloneVolume(server, part, volid, cloneid, volname, flags);
2756 PrintDiagnostics("clone", code);
2759 MapPartIdIntoName(part, partName);
2760 fprintf(STDOUT, "Created clone for volume %s\n",
2761 as->parms[0].items->data);
2768 BackupVolume(register struct cmd_syndesc *as, void *arock)
2772 afs_int32 apart, vtype, code, err;
2773 struct nvldbentry entry;
2776 afs_uint32 buserver;
2777 afs_int32 bupart, butype;
2778 struct nvldbentry buentry;
2780 avolid = vsu_GetVolumeID(as->parms[0].items->data, cstruct, &err);
2783 PrintError("", err);
2785 fprintf(STDERR, "vos: can't find volume ID or name '%s'\n",
2786 as->parms[0].items->data);
2789 code = GetVolumeInfo(avolid, &aserver, &apart, &vtype, &entry);
2793 /* verify this is a readwrite volume */
2795 if (vtype != RWVOL) {
2796 fprintf(STDERR, "%s not RW volume\n", as->parms[0].items->data);
2800 /* is there a backup volume already? */
2802 if (entry.flags & BACK_EXISTS) {
2803 /* yep, where is it? */
2805 buvolid = entry.volumeId[BACKVOL];
2806 code = GetVolumeInfo(buvolid, &buserver, &bupart, &butype, &buentry);
2811 code = VLDB_IsSameAddrs(buserver, aserver, &err);
2814 "Failed to get info about server's %d address(es) from vlserver; aborting call!\n",
2820 "FATAL ERROR: backup volume %lu exists on server %lu\n",
2821 (unsigned long)buvolid, (unsigned long)buserver);
2826 /* nope, carry on */
2828 code = UV_BackupVolume(aserver, apart, avolid);
2831 PrintDiagnostics("backup", code);
2834 fprintf(STDOUT, "Created backup volume for %s \n",
2835 as->parms[0].items->data);
2840 ReleaseVolume(register struct cmd_syndesc *as, void *arock)
2843 struct nvldbentry entry;
2846 afs_int32 apart, vtype, code, err;
2849 if (as->parms[1].items)
2851 avolid = vsu_GetVolumeID(as->parms[0].items->data, cstruct, &err);
2854 PrintError("", err);
2856 fprintf(STDERR, "vos: can't find volume '%s'\n",
2857 as->parms[0].items->data);
2860 code = GetVolumeInfo(avolid, &aserver, &apart, &vtype, &entry);
2864 if (vtype != RWVOL) {
2865 fprintf(STDERR, "%s not a RW volume\n", as->parms[0].items->data);
2869 if (!ISNAMEVALID(entry.name)) {
2871 "Volume name %s is too long, rename before releasing\n",
2876 code = UV_ReleaseVolume(avolid, aserver, apart, force);
2878 PrintDiagnostics("release", code);
2881 fprintf(STDOUT, "Released volume %s successfully\n",
2882 as->parms[0].items->data);
2887 DumpVolumeCmd(register struct cmd_syndesc *as, void *arock)
2891 afs_int32 apart, voltype, fromdate = 0, code, err, i, flags;
2892 char filename[MAXPATHLEN];
2893 struct nvldbentry entry;
2895 rx_SetRxDeadTime(60 * 10);
2896 for (i = 0; i < MAXSERVERS; i++) {
2897 struct rx_connection *rxConn = ubik_GetRPCConn(cstruct, i);
2900 rx_SetConnDeadTime(rxConn, rx_connDeadTime);
2901 if (rxConn->service)
2902 rxConn->service->connDeadTime = rx_connDeadTime;
2905 avolid = vsu_GetVolumeID(as->parms[0].items->data, cstruct, &err);
2908 PrintError("", err);
2910 fprintf(STDERR, "vos: can't find volume '%s'\n",
2911 as->parms[0].items->data);
2915 if (as->parms[3].items || as->parms[4].items) {
2916 if (!as->parms[3].items || !as->parms[4].items) {
2918 "Must specify both -server and -partition options\n");
2921 aserver = GetServer(as->parms[3].items->data);
2923 fprintf(STDERR, "Invalid server name\n");
2926 apart = volutil_GetPartitionID(as->parms[4].items->data);
2928 fprintf(STDERR, "Invalid partition name\n");
2932 code = GetVolumeInfo(avolid, &aserver, &apart, &voltype, &entry);
2937 if (as->parms[1].items && strcmp(as->parms[1].items->data, "0")) {
2938 code = ktime_DateToInt32(as->parms[1].items->data, &fromdate);
2940 fprintf(STDERR, "vos: failed to parse date '%s' (error=%d))\n",
2941 as->parms[1].items->data, code);
2945 if (as->parms[2].items) {
2946 strcpy(filename, as->parms[2].items->data);
2948 strcpy(filename, "");
2951 flags = as->parms[6].items ? VOLDUMPV2_OMITDIRS : 0;
2953 if (as->parms[5].items) {
2955 UV_DumpClonedVolume(avolid, aserver, apart, fromdate,
2956 DumpFunction, filename, flags);
2959 UV_DumpVolume(avolid, aserver, apart, fromdate, DumpFunction,
2962 if ((code == RXGEN_OPCODE) && (as->parms[6].items)) {
2963 flags &= ~VOLDUMPV2_OMITDIRS;
2967 PrintDiagnostics("dump", code);
2970 if (strcmp(filename, ""))
2971 fprintf(STDERR, "Dumped volume %s in file %s\n",
2972 as->parms[0].items->data, filename);
2974 fprintf(STDERR, "Dumped volume %s in stdout \n",
2975 as->parms[0].items->data);
2989 RestoreVolumeCmd(register struct cmd_syndesc *as, void *arock)
2991 afs_uint32 avolid, aparentid;
2993 afs_int32 apart, code, vcode, err;
2994 afs_int32 aoverwrite = ASK;
2995 afs_int32 acreation = 0, alastupdate = 0;
2996 int restoreflags = 0;
2997 int readonly = 0, offline = 0, voltype = RWVOL;
2999 char afilename[MAXPATHLEN], avolname[VOLSER_MAXVOLNAME + 1], apartName[10];
3000 char volname[VOLSER_MAXVOLNAME + 1];
3001 struct nvldbentry entry;
3006 if (as->parms[4].items) {
3007 avolid = vsu_GetVolumeID(as->parms[4].items->data, cstruct, &err);
3010 PrintError("", err);
3012 fprintf(STDERR, "vos: can't find volume '%s'\n",
3013 as->parms[4].items->data);
3019 if (as->parms[5].items) {
3020 if ((strcmp(as->parms[5].items->data, "a") == 0)
3021 || (strcmp(as->parms[5].items->data, "abort") == 0)) {
3023 } else if ((strcmp(as->parms[5].items->data, "f") == 0)
3024 || (strcmp(as->parms[5].items->data, "full") == 0)) {
3026 } else if ((strcmp(as->parms[5].items->data, "i") == 0)
3027 || (strcmp(as->parms[5].items->data, "inc") == 0)
3028 || (strcmp(as->parms[5].items->data, "increment") == 0)
3029 || (strcmp(as->parms[5].items->data, "incremental") == 0)) {
3032 fprintf(STDERR, "vos: %s is not a valid argument to -overwrite\n",
3033 as->parms[5].items->data);
3037 if (as->parms[6].items)
3039 if (as->parms[7].items) {
3044 if (as->parms[8].items) {
3045 if ((strcmp(as->parms[8].items->data, "d") == 0)
3046 || (strcmp(as->parms[8].items->data, "dump") == 0)) {
3047 acreation = TS_DUMP;
3048 } else if ((strcmp(as->parms[8].items->data, "k") == 0)
3049 || (strcmp(as->parms[8].items->data, "keep") == 0)) {
3050 acreation = TS_KEEP;
3051 } else if ((strcmp(as->parms[8].items->data, "n") == 0)
3052 || (strcmp(as->parms[8].items->data, "new") == 0)) {
3055 fprintf(STDERR, "vos: %s is not a valid argument to -creation\n",
3056 as->parms[8].items->data);
3061 if (as->parms[9].items) {
3062 if ((strcmp(as->parms[9].items->data, "d") == 0)
3063 || (strcmp(as->parms[9].items->data, "dump") == 0)) {
3064 alastupdate = TS_DUMP;
3065 } else if ((strcmp(as->parms[9].items->data, "k") == 0)
3066 || (strcmp(as->parms[9].items->data, "keep") == 0)) {
3067 alastupdate = TS_KEEP;
3068 } else if ((strcmp(as->parms[9].items->data, "n") == 0)
3069 || (strcmp(as->parms[9].items->data, "new") == 0)) {
3070 alastupdate = TS_NEW;
3072 fprintf(STDERR, "vos: %s is not a valid argument to -lastupdate\n",
3073 as->parms[9].items->data);
3078 aserver = GetServer(as->parms[0].items->data);
3080 fprintf(STDERR, "vos: server '%s' not found in host table\n",
3081 as->parms[0].items->data);
3084 apart = volutil_GetPartitionID(as->parms[1].items->data);
3086 fprintf(STDERR, "vos: could not interpret partition name '%s'\n",
3087 as->parms[1].items->data);
3090 if (!IsPartValid(apart, aserver, &code)) { /*check for validity of the partition */
3092 PrintError("", code);
3095 "vos : partition %s does not exist on the server\n",
3096 as->parms[1].items->data);
3099 strcpy(avolname, as->parms[2].items->data);
3100 if (!ISNAMEVALID(avolname)) {
3102 "vos: the name of the volume %s exceeds the size limit\n",
3106 if (!VolNameOK(avolname)) {
3108 "Illegal volume name %s, should not end in .readonly or .backup\n",
3112 if (as->parms[3].items) {
3113 strcpy(afilename, as->parms[3].items->data);
3114 if (!FileExists(afilename)) {
3115 fprintf(STDERR, "Can't access file %s\n", afilename);
3119 strcpy(afilename, "");
3122 /* Check if volume exists or not */
3124 vsu_ExtractName(volname, avolname);
3125 vcode = VLDB_GetEntryByName(volname, &entry);
3126 if (vcode) { /* no volume - do a full restore */
3127 restoreflags = RV_FULLRST;
3128 if ((aoverwrite == INC) || (aoverwrite == ABORT))
3130 "Volume does not exist; Will perform a full restore\n");
3133 else if ((!readonly && Lp_GetRwIndex(&entry) == -1) /* RW volume does not exist - do a full */
3134 ||(readonly && !Lp_ROMatch(0, 0, &entry))) { /* RO volume does not exist - do a full */
3135 restoreflags = RV_FULLRST;
3136 if ((aoverwrite == INC) || (aoverwrite == ABORT))
3138 "%s Volume does not exist; Will perform a full restore\n",
3139 readonly ? "RO" : "RW");
3142 avolid = entry.volumeId[voltype];
3143 } else if (entry.volumeId[voltype] != 0
3144 && entry.volumeId[voltype] != avolid) {
3145 avolid = entry.volumeId[voltype];
3147 aparentid = entry.volumeId[RWVOL];
3150 else { /* volume exists - do we do a full incremental or abort */
3152 afs_int32 Opart, Otype, vol_elsewhere = 0;
3153 struct nvldbentry Oentry;
3157 avolid = entry.volumeId[voltype];
3158 } else if (entry.volumeId[voltype] != 0
3159 && entry.volumeId[voltype] != avolid) {
3160 avolid = entry.volumeId[voltype];
3162 aparentid = entry.volumeId[RWVOL];
3164 /* A file name was specified - check if volume is on another partition */
3165 vcode = GetVolumeInfo(avolid, &Oserver, &Opart, &Otype, &Oentry);
3169 vcode = VLDB_IsSameAddrs(Oserver, aserver, &err);
3172 "Failed to get info about server's %d address(es) from vlserver (err=%d); aborting call!\n",
3176 if (!vcode || (Opart != apart))
3179 if (aoverwrite == ASK) {
3180 if (strcmp(afilename, "") == 0) { /* The file is from standard in */
3182 "Volume exists and no -overwrite option specified; Aborting restore command\n");
3186 /* Ask what to do */
3187 if (vol_elsewhere) {
3189 "The volume %s %u already exists on a different server/part\n",
3190 volname, entry.volumeId[voltype]);
3192 "Do you want to do a full restore or abort? [fa](a): ");
3195 "The volume %s %u already exists in the VLDB\n",
3196 volname, entry.volumeId[voltype]);
3198 "Do you want to do a full/incremental restore or abort? [fia](a): ");
3201 while (!(dc == EOF || dc == '\n'))
3202 dc = getchar(); /* goto end of line */
3203 if ((c == 'f') || (c == 'F'))
3205 else if ((c == 'i') || (c == 'I'))
3211 if (aoverwrite == ABORT) {
3212 fprintf(STDERR, "Volume exists; Aborting restore command\n");
3214 } else if (aoverwrite == FULL) {
3215 restoreflags = RV_FULLRST;
3217 "Volume exists; Will delete and perform full restore\n");
3218 } else if (aoverwrite == INC) {
3220 if (vol_elsewhere) {
3222 "%s volume %lu already exists on a different server/part; not allowed\n",
3223 readonly ? "RO" : "RW", (unsigned long)avolid);
3229 restoreflags |= RV_OFFLINE;
3231 restoreflags |= RV_RDONLY;
3233 switch (acreation) {
3235 restoreflags |= RV_CRDUMP;
3238 restoreflags |= RV_CRKEEP;
3241 restoreflags |= RV_CRNEW;
3244 if (aoverwrite == FULL)
3245 restoreflags |= RV_CRNEW;
3247 restoreflags |= RV_CRKEEP;
3250 switch (alastupdate) {
3252 restoreflags |= RV_LUDUMP;
3255 restoreflags |= RV_LUKEEP;
3258 restoreflags |= RV_LUNEW;
3261 restoreflags |= RV_LUDUMP;
3263 if (as->parms[10].items) {
3264 restoreflags |= RV_NODEL;
3269 UV_RestoreVolume2(aserver, apart, avolid, aparentid,
3270 avolname, restoreflags, WriteData, afilename);
3272 PrintDiagnostics("restore", code);
3275 MapPartIdIntoName(apart, apartName);
3278 * patch typo here - originally "parms[1]", should be "parms[0]"
3281 fprintf(STDOUT, "Restored volume %s on %s %s\n", avolname,
3282 as->parms[0].items->data, apartName);
3287 LockReleaseCmd(register struct cmd_syndesc *as, void *arock)
3290 afs_int32 code, err;
3292 avolid = vsu_GetVolumeID(as->parms[0].items->data, cstruct, &err);
3295 PrintError("", err);
3297 fprintf(STDERR, "vos: can't find volume '%s'\n",
3298 as->parms[0].items->data);
3302 code = UV_LockRelease(avolid);
3304 PrintDiagnostics("unlock", code);
3307 fprintf(STDOUT, "Released lock on vldb entry for volume %s\n",
3308 as->parms[0].items->data);
3313 AddSite(register struct cmd_syndesc *as, void *arock)
3317 afs_int32 apart, code, err, arovolid, valid = 0;
3318 char apartName[10], avolname[VOLSER_MAXVOLNAME + 1];
3320 vsu_ExtractName(avolname, as->parms[2].items->data);;
3321 avolid = vsu_GetVolumeID(avolname, cstruct, &err);
3324 PrintError("", err);
3326 fprintf(STDERR, "vos: can't find volume '%s'\n",
3327 as->parms[2].items->data);
3331 if (as->parms[3].items) {
3332 vsu_ExtractName(avolname, as->parms[3].items->data);
3333 arovolid = vsu_GetVolumeID(avolname, cstruct, &err);
3335 fprintf(STDERR, "vos: invalid ro volume id '%s'\n",
3336 as->parms[3].items->data);
3340 aserver = GetServer(as->parms[0].items->data);
3342 fprintf(STDERR, "vos: server '%s' not found in host table\n",
3343 as->parms[0].items->data);
3346 apart = volutil_GetPartitionID(as->parms[1].items->data);
3348 fprintf(STDERR, "vos: could not interpret partition name '%s'\n",
3349 as->parms[1].items->data);
3352 if (!IsPartValid(apart, aserver, &code)) { /*check for validity of the partition */
3354 PrintError("", code);
3357 "vos : partition %s does not exist on the server\n",
3358 as->parms[1].items->data);
3361 if (as->parms[4].items) {
3364 code = UV_AddSite2(aserver, apart, avolid, arovolid, valid);
3366 PrintDiagnostics("addsite", code);
3369 MapPartIdIntoName(apart, apartName);
3370 fprintf(STDOUT, "Added replication site %s %s for volume %s\n",
3371 as->parms[0].items->data, apartName, as->parms[2].items->data);
3376 RemoveSite(register struct cmd_syndesc *as, void *arock)
3381 afs_int32 apart, code, err;
3382 char apartName[10], avolname[VOLSER_MAXVOLNAME + 1];
3384 vsu_ExtractName(avolname, as->parms[2].items->data);
3385 avolid = vsu_GetVolumeID(avolname, cstruct, &err);
3388 PrintError("", err);
3390 fprintf(STDERR, "vos: can't find volume '%s'\n",
3391 as->parms[2].items->data);
3394 aserver = GetServer(as->parms[0].items->data);
3396 fprintf(STDERR, "vos: server '%s' not found in host table\n",
3397 as->parms[0].items->data);
3400 apart = volutil_GetPartitionID(as->parms[1].items->data);
3402 fprintf(STDERR, "vos: could not interpret partition name '%s'\n",
3403 as->parms[1].items->data);
3407 *skip the partition validity check, since it is possible that the partition
3408 *has since been decomissioned.
3411 if (!IsPartValid(apart,aserver,&code)){
3412 if(code) PrintError("",code);
3413 else fprintf(STDERR,"vos : partition %s does not exist on the server\n",as->parms[1].items->data);
3417 code = UV_RemoveSite(aserver, apart, avolid);
3419 PrintDiagnostics("remsite", code);
3422 MapPartIdIntoName(apart, apartName);
3423 fprintf(STDOUT, "Removed replication site %s %s for volume %s\n",
3424 as->parms[0].items->data, apartName, as->parms[2].items->data);
3429 ChangeLocation(register struct cmd_syndesc *as, void *arock)
3433 afs_int32 apart, code, err;
3436 avolid = vsu_GetVolumeID(as->parms[2].items->data, cstruct, &err);
3439 PrintError("", err);
3441 fprintf(STDERR, "vos: can't find volume '%s'\n",
3442 as->parms[2].items->data);
3445 aserver = GetServer(as->parms[0].items->data);
3447 fprintf(STDERR, "vos: server '%s' not found in host table\n",
3448 as->parms[0].items->data);
3451 apart = volutil_GetPartitionID(as->parms[1].items->data);
3453 fprintf(STDERR, "vos: could not interpret partition name '%s'\n",
3454 as->parms[1].items->data);
3457 if (!IsPartValid(apart, aserver, &code)) { /*check for validity of the partition */
3459 PrintError("", code);
3462 "vos : partition %s does not exist on the server\n",
3463 as->parms[1].items->data);
3466 code = UV_ChangeLocation(aserver, apart, avolid);
3468 PrintDiagnostics("addsite", code);
3471 MapPartIdIntoName(apart, apartName);
3472 fprintf(STDOUT, "Changed location to %s %s for volume %s\n",
3473 as->parms[0].items->data, apartName, as->parms[2].items->data);
3478 ListPartitions(register struct cmd_syndesc *as, void *arock)
3482 struct partList dummyPartList;
3487 aserver = GetServer(as->parms[0].items->data);
3489 fprintf(STDERR, "vos: server '%s' not found in host table\n",
3490 as->parms[0].items->data);
3495 code = UV_ListPartitions(aserver, &dummyPartList, &cnt);
3497 PrintDiagnostics("listpart", code);
3501 fprintf(STDOUT, "The partitions on the server are:\n");
3502 for (i = 0; i < cnt; i++) {
3503 if (dummyPartList.partFlags[i] & PARTVALID) {
3504 memset(pname, 0, sizeof(pname));
3505 MapPartIdIntoName(dummyPartList.partId[i], pname);
3506 fprintf(STDOUT, " %10s ", pname);
3508 if ((i % 5) == 0 && (i != 0))
3509 fprintf(STDOUT, "\n");
3512 fprintf(STDOUT, "\n");
3513 fprintf(STDOUT, "Total: %d\n", total);
3519 CompareVolName(const void *p1, const void *p2)
3521 volintInfo *arg1, *arg2;
3523 arg1 = (volintInfo *) p1;
3524 arg2 = (volintInfo *) p2;
3525 return (strcmp(arg1->name, arg2->name));
3529 /*------------------------------------------------------------------------
3530 * PRIVATE XCompareVolName
3533 * Comparison routine for volume names coming from an extended
3537 * a_obj1P : Char ptr to first extended vol info object
3538 * a_obj1P : Char ptr to second extended vol info object
3541 * The value of strcmp() on the volume names within the passed
3542 * objects (i,e., -1, 0, or 1).
3545 * Passed to qsort() as the designated comparison routine.
3549 *------------------------------------------------------------------------*/
3552 XCompareVolName(const void *a_obj1P, const void *a_obj2P)
3553 { /*XCompareVolName */
3556 (((struct volintXInfo *)(a_obj1P))->name,
3557 ((struct volintXInfo *)(a_obj2P))->name));
3559 } /*XCompareVolName */
3562 CompareVolID(const void *p1, const void *p2)
3564 volintInfo *arg1, *arg2;
3566 arg1 = (volintInfo *) p1;
3567 arg2 = (volintInfo *) p2;
3568 if (arg1->volid == arg2->volid)
3570 if (arg1->volid > arg2->volid)
3577 /*------------------------------------------------------------------------
3578 * PRIVATE XCompareVolID
3581 * Comparison routine for volume IDs coming from an extended
3585 * a_obj1P : Char ptr to first extended vol info object
3586 * a_obj1P : Char ptr to second extended vol info object
3589 * The value of strcmp() on the volume names within the passed
3590 * objects (i,e., -1, 0, or 1).
3593 * Passed to qsort() as the designated comparison routine.
3597 *------------------------------------------------------------------------*/
3600 XCompareVolID(const void *a_obj1P, const void *a_obj2P)
3601 { /*XCompareVolID */
3603 afs_int32 id1, id2; /*Volume IDs we're comparing */
3605 id1 = ((struct volintXInfo *)(a_obj1P))->volid;
3606 id2 = ((struct volintXInfo *)(a_obj2P))->volid;
3614 } /*XCompareVolID */
3616 /*------------------------------------------------------------------------
3617 * PRIVATE ListVolumes
3620 * Routine used to list volumes, contacting the Volume Server
3621 * directly, bypassing the VLDB.
3624 * as : Ptr to parsed command line arguments.
3627 * 0 Successful operation
3630 * Nothing interesting.
3634 *------------------------------------------------------------------------*/
3637 ListVolumes(register struct cmd_syndesc *as, void *arock)
3639 afs_int32 apart, int32list, fast;
3643 volintInfo *oldpntr = NULL;
3647 volintXInfo *xInfoP;
3648 volintXInfo *origxInfoP = NULL; /*Ptr to current/orig extended vol info */
3649 int wantExtendedInfo; /*Do we want extended vol info? */
3652 struct partList dummyPartList;
3660 if (as->parms[3].items)
3662 if (as->parms[4].items)
3666 if (as->parms[2].items)
3672 if (as->parms[5].items) {
3674 * We can't coexist with the fast flag.
3678 "vos: Can't use the -fast and -extended flags together\n");
3683 * We need to turn on ``long'' listings to get the full effect.
3685 wantExtendedInfo = 1;
3688 wantExtendedInfo = 0;
3689 if (as->parms[1].items) {
3690 apart = volutil_GetPartitionID(as->parms[1].items->data);
3692 fprintf(STDERR, "vos: could not interpret partition name '%s'\n",
3693 as->parms[1].items->data);
3696 dummyPartList.partId[0] = apart;
3697 dummyPartList.partFlags[0] = PARTVALID;
3700 aserver = GetServer(as->parms[0].items->data);
3702 fprintf(STDERR, "vos: server '%s' not found in host table\n",
3703 as->parms[0].items->data);
3708 if (!IsPartValid(apart, aserver, &code)) { /*check for validity of the partition */
3710 PrintError("", code);
3713 "vos : partition %s does not exist on the server\n",
3714 as->parms[1].items->data);
3718 code = UV_ListPartitions(aserver, &dummyPartList, &cnt);
3720 PrintDiagnostics("listvol", code);
3724 for (i = 0; i < cnt; i++) {
3725 if (dummyPartList.partFlags[i] & PARTVALID) {
3726 if (wantExtendedInfo)
3728 UV_XListVolumes(aserver, dummyPartList.partId[i], all,
3732 UV_ListVolumes(aserver, dummyPartList.partId[i], all,
3735 PrintDiagnostics("listvol", code);
3740 if (wantExtendedInfo) {
3741 origxInfoP = xInfoP;
3742 base = (char *)xInfoP;
3745 base = (char *)pntr;
3749 if (wantExtendedInfo)
3750 qsort(base, count, sizeof(volintXInfo), XCompareVolName);
3752 qsort(base, count, sizeof(volintInfo), CompareVolName);
3754 if (wantExtendedInfo)
3755 qsort(base, count, sizeof(volintXInfo), XCompareVolID);
3757 qsort(base, count, sizeof(volintInfo), CompareVolID);
3759 MapPartIdIntoName(dummyPartList.partId[i], pname);
3762 "Total number of volumes on server %s partition %s: %lu \n",
3763 as->parms[0].items->data, pname,
3764 (unsigned long)count);
3765 if (wantExtendedInfo) {
3766 if (as->parms[6].items)
3767 XDisplayVolumes2(aserver, dummyPartList.partId[i], origxInfoP,
3768 count, int32list, fast, quiet);
3770 XDisplayVolumes(aserver, dummyPartList.partId[i], origxInfoP,
3771 count, int32list, fast, quiet);
3774 xInfoP = (volintXInfo *) 0;
3776 if (as->parms[6].items)
3777 DisplayVolumes2(aserver, dummyPartList.partId[i], oldpntr,
3780 DisplayVolumes(aserver, dummyPartList.partId[i], oldpntr,
3781 count, int32list, fast, quiet);
3784 pntr = (volintInfo *) 0;
3792 SyncVldb(register struct cmd_syndesc *as, void *arock)
3794 afs_int32 pnum = 0, code; /* part name */
3800 if (as->parms[0].items) {
3801 tserver = GetServer(as->parms[0].items->data);
3803 fprintf(STDERR, "vos: host '%s' not found in host table\n",
3804 as->parms[0].items->data);
3809 if (as->parms[1].items) {
3810 pnum = volutil_GetPartitionID(as->parms[1].items->data);
3812 fprintf(STDERR, "vos: could not interpret partition name '%s'\n",
3813 as->parms[1].items->data);
3816 if (!IsPartValid(pnum, tserver, &code)) { /*check for validity of the partition */
3818 PrintError("", code);
3821 "vos: partition %s does not exist on the server\n",
3822 as->parms[1].items->data);
3829 "The -partition option requires a -server option\n");
3834 if (as->parms[3].items) {
3835 flags |= 2; /* don't update */
3838 if (as->parms[2].items) {
3839 /* Synchronize an individual volume */
3840 volname = as->parms[2].items->data;
3841 code = UV_SyncVolume(tserver, pnum, volname, flags);
3845 "Without a -volume option, the -server option is required\n");
3848 code = UV_SyncVldb(tserver, pnum, flags, 0 /*unused */ );
3852 PrintDiagnostics("syncvldb", code);
3856 /* Print a summary of what we did */
3858 fprintf(STDOUT, "VLDB volume %s synchronized", volname);
3860 fprintf(STDOUT, "VLDB synchronized");
3862 fprintf(STDOUT, " with state of server %s", as->parms[0].items->data);
3865 MapPartIdIntoName(pnum, part);
3866 fprintf(STDOUT, " partition %s\n", part);
3868 fprintf(STDOUT, "\n");
3874 SyncServer(register struct cmd_syndesc *as, void *arock)
3876 afs_int32 pnum, code; /* part name */
3881 tserver = GetServer(as->parms[0].items->data);
3883 fprintf(STDERR, "vos: host '%s' not found in host table\n",
3884 as->parms[0].items->data);
3887 if (as->parms[1].items) {
3888 pnum = volutil_GetPartitionID(as->parms[1].items->data);
3890 fprintf(STDERR, "vos: could not interpret partition name '%s'\n",
3891 as->parms[1].items->data);
3894 if (!IsPartValid(pnum, tserver, &code)) { /*check for validity of the partition */
3896 PrintError("", code);
3899 "vos : partition %s does not exist on the server\n",
3900 as->parms[1].items->data);
3908 if (as->parms[2].items) {
3909 flags |= 2; /* don't update */
3911 code = UV_SyncServer(tserver, pnum, flags, 0 /*unused */ );
3913 PrintDiagnostics("syncserv", code);
3917 MapPartIdIntoName(pnum, part);
3918 fprintf(STDOUT, "Server %s partition %s synchronized with VLDB\n",
3919 as->parms[0].items->data, part);
3921 fprintf(STDOUT, "Server %s synchronized with VLDB\n",
3922 as->parms[0].items->data);
3928 VolumeInfoCmd(char *name)
3930 struct nvldbentry entry;
3933 /* The vlserver will handle names with the .readonly
3934 * and .backup extension as well as volume ids.
3936 vcode = VLDB_GetEntryByName(name, &entry);
3938 PrintError("", vcode);
3941 MapHostToNetwork(&entry);
3942 EnumerateEntry(&entry);
3944 /* Defect #3027: grubby check to handle locked volume.
3945 * If VLOP_ALLOPERS is set, the entry is locked.
3946 * Leave this routine as is, but put in correct check.
3948 PrintLocked(entry.flags);
3954 VolumeZap(register struct cmd_syndesc *as, void *arock)
3956 struct nvldbentry entry;
3957 afs_uint32 volid, zapbackupid = 0, backupid = 0;
3958 afs_int32 code, server, part, err;
3960 if (as->parms[3].items) {
3961 /* force flag is on, use the other version */
3962 return NukeVolume(as);
3965 if (as->parms[4].items) {
3969 volid = vsu_GetVolumeID(as->parms[2].items->data, cstruct, &err);
3972 PrintError("", err);
3974 fprintf(STDERR, "vos: can't find volume '%s'\n",
3975 as->parms[2].items->data);
3978 part = volutil_GetPartitionID(as->parms[1].items->data);
3980 fprintf(STDERR, "vos: could not interpret partition name '%s'\n",
3981 as->parms[1].items->data);
3984 server = GetServer(as->parms[0].items->data);
3986 fprintf(STDERR, "vos: host '%s' not found in host table\n",
3987 as->parms[0].items->data);
3990 if (!IsPartValid(part, server, &code)) { /*check for validity of the partition */
3992 PrintError("", code);
3995 "vos : partition %s does not exist on the server\n",
3996 as->parms[1].items->data);
3999 code = VLDB_GetEntryByID(volid, -1, &entry);
4001 if (volid == entry.volumeId[RWVOL])
4002 backupid = entry.volumeId[BACKVOL];
4004 "Warning: Entry for volume number %lu exists in VLDB (but we're zapping it anyway!)\n",
4005 (unsigned long)volid);
4008 volintInfo *pntr = (volintInfo *) 0;
4011 code = UV_ListOneVolume(server, part, volid, &pntr);
4013 if (volid == pntr->parentID)
4014 backupid = pntr->backupID;
4020 code = UV_VolumeZap(server, part, backupid);
4022 PrintDiagnostics("zap", code);
4025 fprintf(STDOUT, "Backup Volume %lu deleted\n",
4026 (unsigned long)backupid);
4029 code = UV_VolumeZap(server, part, volid);
4031 PrintDiagnostics("zap", code);
4034 fprintf(STDOUT, "Volume %lu deleted\n", (unsigned long)volid);
4040 VolserStatus(register struct cmd_syndesc *as, void *arock)
4044 transDebugInfo *pntr, *oldpntr;
4050 server = GetServer(as->parms[0].items->data);
4052 fprintf(STDERR, "vos: host '%s' not found in host table\n",
4053 as->parms[0].items->data);
4056 code = UV_VolserStatus(server, &pntr, &count);
4058 PrintDiagnostics("status", code);
4063 fprintf(STDOUT, "No active transactions on %s\n",
4064 as->parms[0].items->data);
4066 fprintf(STDOUT, "Total transactions: %d\n", count);
4068 for (i = 0; i < count; i++) {
4069 /*print out the relevant info */
4070 fprintf(STDOUT, "--------------------------------------\n");
4072 fprintf(STDOUT, "transaction: %lu created: %s",
4073 (unsigned long)pntr->tid, ctime(&t));
4074 if (pntr->returnCode) {
4075 fprintf(STDOUT, "returnCode: %lu\n",
4076 (unsigned long)pntr->returnCode);
4079 fprintf(STDOUT, "attachFlags: ");
4080 switch (pntr->iflags) {
4082 fprintf(STDOUT, "offline ");
4085 fprintf(STDOUT, "busy ");
4088 fprintf(STDOUT, "readonly ");
4091 fprintf(STDOUT, "create ");
4094 fprintf(STDOUT, "create volid ");
4097 fprintf(STDOUT, "\n");
4100 fprintf(STDOUT, "volumeStatus: ");
4101 switch (pntr->vflags) {
4102 case VTDeleteOnSalvage:
4103 fprintf(STDOUT, "deleteOnSalvage ");
4104 case VTOutOfService:
4105 fprintf(STDOUT, "outOfService ");
4107 fprintf(STDOUT, "deleted ");
4109 fprintf(STDOUT, "\n");
4112 fprintf(STDOUT, "transactionFlags: ");
4113 fprintf(STDOUT, "delete\n");
4115 MapPartIdIntoName(pntr->partition, pname);
4116 fprintf(STDOUT, "volume: %lu partition: %s procedure: %s\n",
4117 (unsigned long)pntr->volid, pname, pntr->lastProcName);
4118 if (pntr->callValid) {
4120 "packetRead: %lu lastReceiveTime: %d packetSend: %lu lastSendTime: %d\n",
4121 (unsigned long)pntr->readNext, pntr->lastReceiveTime,
4122 (unsigned long)pntr->transmitNext, pntr->lastSendTime);
4125 fprintf(STDOUT, "--------------------------------------\n");
4126 fprintf(STDOUT, "\n");
4134 RenameVolume(register struct cmd_syndesc *as, void *arock)
4136 afs_int32 code1, code2, code;
4137 struct nvldbentry entry;
4139 code1 = VLDB_GetEntryByName(as->parms[0].items->data, &entry);
4141 fprintf(STDERR, "vos: Could not find entry for volume %s\n",
4142 as->parms[0].items->data);
4145 code2 = VLDB_GetEntryByName(as->parms[1].items->data, &entry);
4146 if ((!code1) && (!code2)) { /*the newname already exists */
4147 fprintf(STDERR, "vos: volume %s already exists\n",
4148 as->parms[1].items->data);
4152 if (code1 && code2) {
4153 fprintf(STDERR, "vos: Could not find entry for volume %s or %s\n",
4154 as->parms[0].items->data, as->parms[1].items->data);
4157 if (!VolNameOK(as->parms[0].items->data)) {
4159 "Illegal volume name %s, should not end in .readonly or .backup\n",
4160 as->parms[0].items->data);
4163 if (!ISNAMEVALID(as->parms[1].items->data)) {
4165 "vos: the new volume name %s exceeds the size limit of %d\n",
4166 as->parms[1].items->data, VOLSER_OLDMAXVOLNAME - 10);
4169 if (!VolNameOK(as->parms[1].items->data)) {
4171 "Illegal volume name %s, should not end in .readonly or .backup\n",
4172 as->parms[1].items->data);
4175 if (IsNumeric(as->parms[1].items->data)) {
4176 fprintf(STDERR, "Illegal volume name %s, should not be a number\n",
4177 as->parms[1].items->data);
4180 MapHostToNetwork(&entry);
4182 UV_RenameVolume(&entry, as->parms[0].items->data,
4183 as->parms[1].items->data);
4185 PrintDiagnostics("rename", code);
4188 fprintf(STDOUT, "Renamed volume %s to %s\n", as->parms[0].items->data,
4189 as->parms[1].items->data);
4194 GetVolumeInfo(afs_uint32 volid, afs_uint32 *server, afs_int32 *part, afs_int32 *voltype,
4195 struct nvldbentry *rentry)
4200 vcode = VLDB_GetEntryByID(volid, -1, rentry);
4203 "Could not fetch the entry for volume %lu from VLDB \n",
4204 (unsigned long)volid);
4205 PrintError("", vcode);
4208 MapHostToNetwork(rentry);
4209 if (volid == rentry->volumeId[ROVOL]) {
4211 for (i = 0; i < rentry->nServers; i++) {
4212 if ((index == -1) && (rentry->serverFlags[i] & ITSROVOL)
4213 && !(rentry->serverFlags[i] & RO_DONTUSE))
4218 "RO volume is not found in VLDB entry for volume %lu\n",
4219 (unsigned long)volid);
4223 *server = rentry->serverNumber[index];
4224 *part = rentry->serverPartition[index];
4228 index = Lp_GetRwIndex(rentry);
4231 "RW Volume is not found in VLDB entry for volume %lu\n",
4232 (unsigned long)volid);
4235 if (volid == rentry->volumeId[RWVOL]) {
4237 *server = rentry->serverNumber[index];
4238 *part = rentry->serverPartition[index];
4241 if (volid == rentry->volumeId[BACKVOL]) {
4243 *server = rentry->serverNumber[index];
4244 *part = rentry->serverPartition[index];
4248 "unexpected volume type for volume %lu\n",
4249 (unsigned long)volid);
4254 DeleteEntry(register struct cmd_syndesc *as, void *arock)
4256 afs_int32 apart = 0;
4259 struct VldbListByAttributes attributes;
4260 nbulkentries arrayEntries;
4261 register struct nvldbentry *vllist;
4262 struct cmd_item *itp;
4265 char prefix[VOLSER_MAXVOLNAME + 1];
4267 afs_int32 totalBack = 0, totalFail = 0, err;
4269 if (as->parms[0].items) { /* -id */
4270 if (as->parms[1].items || as->parms[2].items || as->parms[3].items) {
4272 "You cannot use -server, -partition, or -prefix with the -id argument\n");
4275 for (itp = as->parms[0].items; itp; itp = itp->next) {
4276 avolid = vsu_GetVolumeID(itp->data, cstruct, &err);
4279 PrintError("", err);
4281 fprintf(STDERR, "vos: can't find volume '%s'\n",
4285 if (as->parms[4].items) { /* -noexecute */
4286 fprintf(STDOUT, "Would have deleted VLDB entry for %s \n",
4291 vcode = ubik_VL_DeleteEntry(cstruct, 0, avolid, RWVOL);
4293 fprintf(STDERR, "Could not delete entry for volume %s\n",
4296 "You must specify a RW volume name or ID "
4297 "(the entire VLDB entry will be deleted)\n");
4298 PrintError("", vcode);
4304 fprintf(STDOUT, "Deleted %d VLDB entries\n", totalBack);
4308 if (!as->parms[1].items && !as->parms[2].items && !as->parms[3].items) {
4309 fprintf(STDERR, "You must specify an option\n");
4313 /* Zero out search attributes */
4314 memset(&attributes, 0, sizeof(struct VldbListByAttributes));
4316 if (as->parms[1].items) { /* -prefix */
4317 strncpy(prefix, as->parms[1].items->data, VOLSER_MAXVOLNAME);
4319 if (!as->parms[2].items && !as->parms[3].items) { /* a single entry only */
4321 "You must provide -server with the -prefix argument\n");
4326 if (as->parms[2].items) { /* -server */
4328 aserver = GetServer(as->parms[2].items->data);
4330 fprintf(STDERR, "vos: server '%s' not found in host table\n",
4331 as->parms[2].items->data);
4334 attributes.server = ntohl(aserver);
4335 attributes.Mask |= VLLIST_SERVER;
4338 if (as->parms[3].items) { /* -partition */
4339 if (!as->parms[2].items) {
4341 "You must provide -server with the -partition argument\n");
4344 apart = volutil_GetPartitionID(as->parms[3].items->data);
4346 fprintf(STDERR, "vos: could not interpret partition name '%s'\n",
4347 as->parms[3].items->data);
4350 attributes.partition = apart;
4351 attributes.Mask |= VLLIST_PARTITION;
4354 /* Print status line of what we are doing */
4355 fprintf(STDOUT, "Deleting VLDB entries for ");
4356 if (as->parms[2].items) {
4357 fprintf(STDOUT, "server %s ", as->parms[2].items->data);
4359 if (as->parms[3].items) {
4361 MapPartIdIntoName(apart, pname);
4362 fprintf(STDOUT, "partition %s ", pname);
4365 fprintf(STDOUT, "which are prefixed with %s ", prefix);
4367 fprintf(STDOUT, "\n");
4370 /* Get all the VLDB entries on a server and/or partition */
4371 memset(&arrayEntries, 0, sizeof(arrayEntries));
4372 vcode = VLDB_ListAttributes(&attributes, &nentries, &arrayEntries);
4374 fprintf(STDERR, "Could not access the VLDB for attributes\n");
4375 PrintError("", vcode);
4379 /* Process each entry */
4380 for (j = 0; j < nentries; j++) {
4381 vllist = &arrayEntries.nbulkentries_val[j];
4383 /* It only deletes the RW volumes */
4384 if (strncmp(vllist->name, prefix, strlen(prefix))) {
4387 "Omitting to delete %s due to prefix %s mismatch\n",
4388 vllist->name, prefix);
4395 if (as->parms[4].items) { /* -noexecute */
4396 fprintf(STDOUT, "Would have deleted VLDB entry for %s \n",
4402 /* Only matches the RW volume name */
4403 avolid = vllist->volumeId[RWVOL];
4404 vcode = ubik_VL_DeleteEntry(cstruct, 0, avolid, RWVOL);
4406 fprintf(STDOUT, "Could not delete VDLB entry for %s\n",
4409 PrintError("", vcode);
4414 fprintf(STDOUT, "Deleted VLDB entry for %s \n", vllist->name);
4419 fprintf(STDOUT, "----------------------\n");
4421 "Total VLDB entries deleted: %lu; failed to delete: %lu\n",
4422 (unsigned long)totalBack, (unsigned long)totalFail);
4423 if (arrayEntries.nbulkentries_val)
4424 free(arrayEntries.nbulkentries_val);
4430 CompareVldbEntryByName(const void *p1, const void *p2)
4432 struct nvldbentry *arg1, *arg2;
4434 arg1 = (struct nvldbentry *)p1;
4435 arg2 = (struct nvldbentry *)p2;
4436 return (strcmp(arg1->name, arg2->name));
4440 static int CompareVldbEntry(char *p1, char *p2)
4442 struct nvldbentry *arg1,*arg2;
4445 char comp1[100],comp2[100];
4446 char temp1[20],temp2[20];
4448 arg1 = (struct nvldbentry *)p1;
4449 arg2 = (struct nvldbentry *)p2;
4453 for(i = 0; i < arg1->nServers; i++)
4454 if(arg1->serverFlags[i] & ITSRWVOL) pos1 = i;
4455 for(i = 0; i < arg2->nServers; i++)
4456 if(arg2->serverFlags[i] & ITSRWVOL) pos2 = i;
4457 if(pos1 == -1 || pos2 == -1){
4461 sprintf(comp1,"%10u",arg1->serverNumber[pos1]);
4462 sprintf(comp2,"%10u",arg2->serverNumber[pos2]);
4463 sprintf(temp1,"%10u",arg1->serverPartition[pos1]);
4464 sprintf(temp2,"%10u",arg2->serverPartition[pos2]);
4465 strcat(comp1,temp1);
4466 strcat(comp2,temp2);
4467 strcat(comp1,arg1->name);
4468 strcat(comp1,arg2->name);
4469 return(strcmp(comp1,comp2));
4475 ListVLDB(struct cmd_syndesc *as, void *arock)
4481 struct VldbListByAttributes attributes;
4482 nbulkentries arrayEntries;
4483 struct nvldbentry *vllist, *tarray = 0, *ttarray;
4484 afs_int32 centries, nentries = 0;
4485 afs_int32 tarraysize = 0;
4486 afs_int32 parraysize;
4489 int quiet, sort, lock;
4490 afs_int32 thisindex, nextindex;
4495 attributes.Mask = 0;
4496 lock = (as->parms[3].items ? 1 : 0); /* -lock flag */
4497 quiet = (as->parms[4].items ? 1 : 0); /* -quit flag */
4498 sort = (as->parms[5].items ? 0 : 1); /* -nosort flag */
4500 /* If the volume name is given, Use VolumeInfoCmd to look it up
4501 * and not ListAttributes.
4503 if (as->parms[0].items) {
4506 "vos: illegal use of '-locked' switch, need to specify server and/or partition\n");
4509 code = VolumeInfoCmd(as->parms[0].items->data);
4511 PrintError("", code);
4517 /* Server specified */
4518 if (as->parms[1].items) {
4519 aserver = GetServer(as->parms[1].items->data);
4521 fprintf(STDERR, "vos: server '%s' not found in host table\n",
4522 as->parms[1].items->data);
4525 attributes.server = ntohl(aserver);
4526 attributes.Mask |= VLLIST_SERVER;
4529 /* Partition specified */
4530 if (as->parms[2].items) {
4531 apart = volutil_GetPartitionID(as->parms[2].items->data);
4533 fprintf(STDERR, "vos: could not interpret partition name '%s'\n",
4534 as->parms[2].items->data);
4537 attributes.partition = apart;
4538 attributes.Mask |= VLLIST_PARTITION;
4542 attributes.Mask |= VLLIST_FLAG;
4543 attributes.flag = VLOP_ALLOPERS;
4546 /* Print header information */
4548 MapPartIdIntoName(apart, pname);
4549 fprintf(STDOUT, "VLDB entries for %s %s%s%s %s\n",
4550 (as->parms[1].items ? "server" : "all"),
4551 (as->parms[1].items ? as->parms[1].items->data : "servers"),
4552 (as->parms[2].items ? " partition " : ""),
4553 (as->parms[2].items ? pname : ""),
4554 (lock ? "which are locked:" : ""));
4557 for (thisindex = 0; (thisindex != -1); thisindex = nextindex) {
4558 memset(&arrayEntries, 0, sizeof(arrayEntries));
4563 VLDB_ListAttributesN2(&attributes, 0, thisindex, ¢ries,
4564 &arrayEntries, &nextindex);
4565 if (vcode == RXGEN_OPCODE) {
4566 /* Vlserver not running with ListAttributesN2. Fall back */
4568 VLDB_ListAttributes(&attributes, ¢ries, &arrayEntries);
4572 fprintf(STDERR, "Could not access the VLDB for attributes\n");
4573 PrintError("", vcode);
4576 nentries += centries;
4578 /* We don't sort, so just print the entries now */
4580 for (j = 0; j < centries; j++) { /* process each entry */
4581 vllist = &arrayEntries.nbulkentries_val[j];
4582 MapHostToNetwork(vllist);
4583 EnumerateEntry(vllist);
4585 PrintLocked(vllist->flags);
4589 /* So we sort. First we must collect all the entries and keep
4592 else if (centries > 0) {
4594 /* steal away the first bulk entries array */
4595 tarray = (struct nvldbentry *)arrayEntries.nbulkentries_val;
4596 tarraysize = centries * sizeof(struct nvldbentry);
4597 arrayEntries.nbulkentries_val = 0;
4599 /* Grow the tarray to keep the extra entries */
4600 parraysize = (centries * sizeof(struct nvldbentry));
4602 (struct nvldbentry *)realloc(tarray,
4603 tarraysize + parraysize);
4606 "Could not allocate enough space for the VLDB entries\n");
4612 memcpy(((char *)tarray) + tarraysize,
4613 (char *)arrayEntries.nbulkentries_val, parraysize);
4614 tarraysize += parraysize;
4618 /* Free the bulk array */
4619 if (arrayEntries.nbulkentries_val) {
4620 free(arrayEntries.nbulkentries_val);
4621 arrayEntries.nbulkentries_val = 0;
4625 /* Here is where we now sort all the entries and print them */
4626 if (sort && (nentries > 0)) {
4627 qsort((char *)tarray, nentries, sizeof(struct nvldbentry),
4628 CompareVldbEntryByName);
4629 for (vllist = tarray, j = 0; j < nentries; j++, vllist++) {
4630 MapHostToNetwork(vllist);
4631 EnumerateEntry(vllist);
4633 PrintLocked(vllist->flags);
4639 fprintf(STDOUT, "\nTotal entries: %lu\n", (unsigned long)nentries);
4646 BackSys(register struct cmd_syndesc *as, void *arock)
4649 afs_int32 apart = 0;
4650 afs_uint32 aserver = 0, aserver1;
4651 afs_int32 code, apart1;
4653 struct VldbListByAttributes attributes;
4654 nbulkentries arrayEntries;
4655 register struct nvldbentry *vllist;
4659 int seenprefix, seenxprefix, exclude, ex, exp, noaction;
4660 afs_int32 totalBack = 0;
4661 afs_int32 totalFail = 0;
4665 struct cmd_item *ti;
4667 #ifndef HAVE_POSIX_REGEX
4671 memset(&attributes, 0, sizeof(struct VldbListByAttributes));
4672 attributes.Mask = 0;
4674 seenprefix = (as->parms[0].items ? 1 : 0);
4675 exclude = (as->parms[3].items ? 1 : 0);
4676 seenxprefix = (as->parms[4].items ? 1 : 0);
4677 noaction = (as->parms[5].items ? 1 : 0);
4679 if (as->parms[1].items) { /* -server */
4680 aserver = GetServer(as->parms[1].items->data);
4682 fprintf(STDERR, "vos: server '%s' not found in host table\n",
4683 as->parms[1].items->data);
4686 attributes.server = ntohl(aserver);
4687 attributes.Mask |= VLLIST_SERVER;
4690 if (as->parms[2].items) { /* -partition */
4691 apart = volutil_GetPartitionID(as->parms[2].items->data);
4693 fprintf(STDERR, "vos: could not interpret partition name '%s'\n",
4694 as->parms[2].items->data);
4697 attributes.partition = apart;
4698 attributes.Mask |= VLLIST_PARTITION;
4701 /* Check to make sure the prefix and xprefix expressions compile ok */
4703 for (ti = as->parms[0].items; ti; ti = ti->next) {
4704 if (strncmp(ti->data, "^", 1) == 0) {
4705 #ifdef HAVE_POSIX_REGEX
4709 code = regcomp(&re, ti->data, REG_NOSUB);
4711 regerror(code, &re, errbuf, sizeof errbuf);
4713 "Unrecognizable -prefix regular expression: '%s': %s\n",
4719 ccode = (char *)re_comp(ti->data);
4722 "Unrecognizable -prefix regular expression: '%s': %s\n",
4731 for (ti = as->parms[4].items; ti; ti = ti->next) {
4732 if (strncmp(ti->data, "^", 1) == 0) {
4733 #ifdef HAVE_POSIX_REGEX
4737 code = regcomp(&re, ti->data, REG_NOSUB);
4739 regerror(code, &re, errbuf, sizeof errbuf);
4741 "Unrecognizable -xprefix regular expression: '%s': %s\n",
4747 ccode = (char *)re_comp(ti->data);
4750 "Unrecognizable -xprefix regular expression: '%s': %s\n",
4759 memset(&arrayEntries, 0, sizeof(arrayEntries)); /* initialize to hint the stub to alloc space */
4760 vcode = VLDB_ListAttributes(&attributes, &nentries, &arrayEntries);
4762 fprintf(STDERR, "Could not access the VLDB for attributes\n");
4763 PrintError("", vcode);
4767 if (as->parms[1].items || as->parms[2].items || verbose) {
4768 fprintf(STDOUT, "%s up volumes",
4769 (noaction ? "Would have backed" : "Backing"));
4771 if (as->parms[1].items) {
4772 fprintf(STDOUT, " on server %s", as->parms[1].items->data);
4773 } else if (as->parms[2].items) {
4774 fprintf(STDOUT, " for all servers");
4777 if (as->parms[2].items) {
4778 MapPartIdIntoName(apart, pname);
4779 fprintf(STDOUT, " partition %s", pname);
4782 if (seenprefix || (!seenprefix && seenxprefix)) {
4783 ti = (seenprefix ? as->parms[0].items : as->parms[4].items);
4784 ex = (seenprefix ? exclude : !exclude);
4785 exp = (strncmp(ti->data, "^", 1) == 0);
4786 fprintf(STDOUT, " which %smatch %s '%s'", (ex ? "do not " : ""),
4787 (exp ? "expression" : "prefix"), ti->data);
4788 for (ti = ti->next; ti; ti = ti->next) {
4789 exp = (strncmp(ti->data, "^", 1) == 0);
4790 printf(" %sor %s '%s'", (ex ? "n" : ""),
4791 (exp ? "expression" : "prefix"), ti->data);
4795 if (seenprefix && seenxprefix) {
4796 ti = as->parms[4].items;
4797 exp = (strncmp(ti->data, "^", 1) == 0);
4798 fprintf(STDOUT, " %swhich match %s '%s'",
4799 (exclude ? "adding those " : "removing those "),
4800 (exp ? "expression" : "prefix"), ti->data);
4801 for (ti = ti->next; ti; ti = ti->next) {
4802 exp = (strncmp(ti->data, "^", 1) == 0);
4803 printf(" or %s '%s'", (exp ? "expression" : "prefix"),
4807 fprintf(STDOUT, " .. ");
4809 fprintf(STDOUT, "\n");
4813 for (j = 0; j < nentries; j++) { /* process each vldb entry */
4814 vllist = &arrayEntries.nbulkentries_val[j];
4817 for (ti = as->parms[0].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 -prefix regular expression: '%s': %s\n",
4832 match = (regexec(&re, vllist->name, 0, NULL, 0) == 0);
4835 ccode = (char *)re_comp(ti->data);
4838 "Error in -prefix regular expression: '%s': %s\n",
4842 match = (re_exec(vllist->name) == 1);
4846 (strncmp(vllist->name, ti->data, strlen(ti->data)) ==
4856 /* Without the -exclude flag: If it matches the prefix, then
4857 * check if we want to exclude any from xprefix.
4858 * With the -exclude flag: If it matches the prefix, then
4859 * check if we want to add any from xprefix.
4861 if (match && seenxprefix) {
4862 for (ti = as->parms[4].items; ti; ti = ti->next) {
4863 if (strncmp(ti->data, "^", 1) == 0) {
4864 #ifdef HAVE_POSIX_REGEX
4868 /* XXX -- should just do the compile once! */
4869 code = regcomp(&re, ti->data, REG_NOSUB);
4871 regerror(code, &re, errbuf, sizeof errbuf);
4873 "Error in -xprefix regular expression: '%s': %s\n",
4877 if (regexec(&re, vllist->name, 0, NULL, 0) == 0)
4881 ccode = (char *)re_comp(ti->data);
4884 "Error in -xprefix regular expression: '%s': %s\n",
4888 if (re_exec(vllist->name) == 1) {
4894 if (strncmp(vllist->name, ti->data, strlen(ti->data)) ==
4904 match = !match; /* -exclude will reverse the match */
4906 continue; /* Skip if no match */
4908 /* Print list of volumes to backup */
4910 fprintf(STDOUT, " %s\n", vllist->name);
4914 if (!(vllist->flags & RW_EXISTS)) {
4917 "Omitting to backup %s since RW volume does not exist \n",
4919 fprintf(STDOUT, "\n");
4925 avolid = vllist->volumeId[RWVOL];
4926 MapHostToNetwork(vllist);
4927 GetServerAndPart(vllist, RWVOL, &aserver1, &apart1, &previdx);
4928 if (aserver1 == -1 || apart1 == -1) {
4929 fprintf(STDOUT, "could not backup %s, invalid VLDB entry\n",
4935 same = VLDB_IsSameAddrs(aserver, aserver1, &error);
4938 "Failed to get info about server's %d address(es) from vlserver (err=%d); aborting call!\n",
4944 if ((aserver && !same) || (apart && (apart != apart1))) {
4947 "Omitting to backup %s since the RW is in a different location\n",
4953 time_t now = time(0);
4954 fprintf(STDOUT, "Creating backup volume for %s on %s",
4955 vllist->name, ctime(&now));
4959 code = UV_BackupVolume(aserver1, apart1, avolid);
4961 fprintf(STDOUT, "Could not backup %s\n", vllist->name);
4967 fprintf(STDOUT, "\n");
4969 } /* process each vldb entry */
4970 fprintf(STDOUT, "done\n");
4971 fprintf(STDOUT, "Total volumes backed up: %lu; failed to backup: %lu\n",
4972 (unsigned long)totalBack, (unsigned long)totalFail);
4974 if (arrayEntries.nbulkentries_val)
4975 free(arrayEntries.nbulkentries_val);
4980 UnlockVLDB(register struct cmd_syndesc *as, void *arock)
4983 afs_uint32 aserver = 0;
4986 struct VldbListByAttributes attributes;
4987 nbulkentries arrayEntries;
4988 register struct nvldbentry *vllist;
4997 attributes.Mask = 0;
4999 if (as->parms[0].items) { /* server specified */
5000 aserver = GetServer(as->parms[0].items->data);
5002 fprintf(STDERR, "vos: server '%s' not found in host table\n",
5003 as->parms[0].items->data);
5006 attributes.server = ntohl(aserver);
5007 attributes.Mask |= VLLIST_SERVER;
5009 if (as->parms[1].items) { /* partition specified */
5010 apart = volutil_GetPartitionID(as->parms[1].items->data);
5012 fprintf(STDERR, "vos: could not interpret partition name '%s'\n",
5013 as->parms[1].items->data);
5016 if (!IsPartValid(apart, aserver, &code)) { /*check for validity of the partition */
5018 PrintError("", code);
5021 "vos : partition %s does not exist on the server\n",
5022 as->parms[1].items->data);
5025 attributes.partition = apart;
5026 attributes.Mask |= VLLIST_PARTITION;
5028 attributes.flag = VLOP_ALLOPERS;
5029 attributes.Mask |= VLLIST_FLAG;
5030 memset(&arrayEntries, 0, sizeof(arrayEntries)); /*initialize to hint the stub to alloc space */
5031 vcode = VLDB_ListAttributes(&attributes, &nentries, &arrayEntries);
5033 fprintf(STDERR, "Could not access the VLDB for attributes\n");
5034 PrintError("", vcode);
5037 for (j = 0; j < nentries; j++) { /* process each entry */
5038 vllist = &arrayEntries.nbulkentries_val[j];
5039 volid = vllist->volumeId[RWVOL];
5041 ubik_VL_ReleaseLock(cstruct, 0, volid, -1,
5042 LOCKREL_OPCODE | LOCKREL_AFSID |
5045 fprintf(STDERR, "Could not unlock entry for volume %s\n",
5047 PrintError("", vcode);
5052 MapPartIdIntoName(apart, pname);
5055 "Could not lock %lu VLDB entries of %lu locked entries\n",
5056 (unsigned long)totalE, (unsigned long)nentries);
5058 if (as->parms[0].items) {
5060 "Unlocked all the VLDB entries for volumes on server %s ",
5061 as->parms[0].items->data);
5062 if (as->parms[1].items) {
5063 MapPartIdIntoName(apart, pname);
5064 fprintf(STDOUT, "partition %s\n", pname);
5066 fprintf(STDOUT, "\n");
5068 } else if (as->parms[1].items) {
5069 MapPartIdIntoName(apart, pname);
5071 "Unlocked all the VLDB entries for volumes on partition %s on all servers\n",
5076 if (arrayEntries.nbulkentries_val)
5077 free(arrayEntries.nbulkentries_val);
5082 PrintInt64Size(afs_uint64 in)
5084 register afs_uint32 hi, lo;
5085 register char * units;
5086 static char output[16];
5088 SplitInt64(in,hi,lo);
5092 } else if (!(hi & 0xFFFFFC00)) {
5094 lo = (hi << 22) | (lo >> 10);
5095 } else if (!(hi & 0xFFF00000)) {
5097 lo = (hi << 12) | (lo >> 20);
5098 } else if (!(hi & 0xC0000000)) {
5100 lo = (hi << 2) | (lo >> 30);
5105 sprintf(output,"%u %s", lo, units);
5110 PartitionInfo(register struct cmd_syndesc *as, void *arock)
5116 struct diskPartition64 partition;
5117 struct partList dummyPartList;
5119 int printSummary=0, sumPartitions=0;
5120 afs_uint64 sumFree, sumStorage;
5123 ZeroInt64(sumStorage);
5125 aserver = GetServer(as->parms[0].items->data);
5127 fprintf(STDERR, "vos: server '%s' not found in host table\n",
5128 as->parms[0].items->data);
5131 if (as->parms[1].items) {
5132 apart = volutil_GetPartitionID(as->parms[1].items->data);
5134 fprintf(STDERR, "vos: could not interpret partition name '%s'\n",
5135 as->parms[1].items->data);
5138 dummyPartList.partId[0] = apart;
5139 dummyPartList.partFlags[0] = PARTVALID;
5142 if (as->parms[2].items) {
5146 if (!IsPartValid(apart, aserver, &code)) { /*check for validity of the partition */
5148 PrintError("", code);
5151 "vos : partition %s does not exist on the server\n",
5152 as->parms[1].items->data);
5156 code = UV_ListPartitions(aserver, &dummyPartList, &cnt);
5158 PrintDiagnostics("listpart", code);
5162 for (i = 0; i < cnt; i++) {
5163 if (dummyPartList.partFlags[i] & PARTVALID) {
5164 MapPartIdIntoName(dummyPartList.partId[i], pname);
5165 code = UV_PartitionInfo64(aserver, pname, &partition);
5167 fprintf(STDERR, "Could not get information on partition %s\n",
5169 PrintError("", code);
5173 "Free space on partition %s: %" AFS_INT64_FMT " K blocks out of total %" AFS_INT64_FMT "\n",
5174 pname, partition.free, partition.minFree);
5176 AddUInt64(sumFree,partition.free,&sumFree);
5177 AddUInt64(sumStorage,partition.minFree,&sumStorage);
5182 "Summary: %s free out of ",
5183 PrintInt64Size(sumFree));
5185 "%s on %d partitions\n",
5186 PrintInt64Size(sumStorage),
5193 ChangeAddr(register struct cmd_syndesc *as, void *arock)
5195 afs_int32 ip1, ip2, vcode;
5199 ip1 = GetServerNoresolve(as->parms[0].items->data);
5201 ip1 = GetServer(as->parms[0].items->data);
5203 fprintf(STDERR, "vos: invalid host address\n");
5207 if ((as->parms[1].items && as->parms[2].items)
5208 || (!as->parms[1].items && !as->parms[2].items)) {
5210 "vos: Must specify either '-newaddr <addr>' or '-remove' flag\n");
5214 if (as->parms[1].items) {
5216 ip2 = GetServerNoresolve(as->parms[1].items->data);
5218 ip2 = GetServer(as->parms[1].items->data);
5220 fprintf(STDERR, "vos: invalid host address\n");
5224 /* Play a trick here. If we are removing an address, ip1 will be -1
5225 * and ip2 will be the original address. This switch prevents an
5226 * older revision vlserver from removing the IP address.
5233 vcode = ubik_VL_ChangeAddr(cstruct, UBIK_CALL_NEW, ntohl(ip1), ntohl(ip2));
5235 char hoststr1[16], hoststr2[16];
5237 afs_inet_ntoa_r(ip2, hoststr2);
5238 fprintf(STDERR, "Could not remove server %s from the VLDB\n",
5240 if (vcode == VL_NOENT) {
5242 "vlserver does not support the remove flag or ");
5245 afs_inet_ntoa_r(ip1, hoststr1);
5246 afs_inet_ntoa_r(ip2, hoststr2);
5247 fprintf(STDERR, "Could not change server %s to server %s\n",
5248 hoststr1, hoststr2);
5250 PrintError("", vcode);
5255 fprintf(STDOUT, "Removed server %s from the VLDB\n",
5256 as->parms[0].items->data);
5258 fprintf(STDOUT, "Changed server %s to server %s\n",
5259 as->parms[0].items->data, as->parms[1].items->data);
5265 print_addrs(const bulkaddrs * addrs, afsUUID * m_uuid, int nentries,
5268 afs_int32 vcode, m_uniq=0;
5272 ListAddrByAttributes m_attrs;
5273 afs_int32 m_nentries;
5274 afs_uint32 *m_addrp;
5275 afs_int32 base, index;
5279 afsUUID_to_string(m_uuid, buf, sizeof(buf));
5280 printf("UUID: %s\n", buf);
5283 /* print out the list of all the server */
5284 addrp = (afs_uint32 *) addrs->bulkaddrs_val;
5285 for (i = 0; i < nentries; i++, addrp++) {
5286 /* If it is a multihomed address, then we will need to
5287 * get the addresses for this multihomed server from
5288 * the vlserver and print them.
5290 if (((*addrp & 0xff000000) == 0xff000000) && ((*addrp) & 0xffff)) {
5291 /* Get the list of multihomed fileservers */
5292 base = (*addrp >> 16) & 0xff;
5293 index = (*addrp) & 0xffff;
5295 if ((base >= 0) && (base <= VL_MAX_ADDREXTBLKS) && (index >= 1)
5296 && (index <= VL_MHSRV_PERBLK)) {
5297 m_attrs.Mask = VLADDR_INDEX;
5298 m_attrs.index = (base * VL_MHSRV_PERBLK) + index;
5300 m_addrs.bulkaddrs_val = 0;
5301 m_addrs.bulkaddrs_len = 0;
5303 ubik_VL_GetAddrsU(cstruct, 0, &m_attrs, m_uuid,
5304 &m_uniq, &m_nentries,
5308 "vos: could not list the multi-homed server addresses\n");
5309 PrintError("", vcode);
5312 /* Print the list */
5313 m_addrp = (afs_uint32 *) m_addrs.bulkaddrs_val;
5314 for (j = 0; j < m_nentries; j++, m_addrp++) {
5315 *m_addrp = htonl(*m_addrp);
5318 printf("%s ", afs_inet_ntoa_r(*m_addrp, hoststr));
5320 printf("%s ", hostutil_GetNameByINet(*m_addrp));
5324 printf("<unknown>\n");
5333 /* Otherwise, it is a non-multihomed entry and contains
5334 * the IP address of the server - print it.
5336 *addrp = htonl(*addrp);
5339 printf("%s\n", afs_inet_ntoa_r(*addrp, hoststr));
5341 printf("%s\n", hostutil_GetNameByINet(*addrp));
5352 ListAddrs(register struct cmd_syndesc *as, void *arock)
5354 afs_int32 vcode, m_uniq=0;
5355 afs_int32 i, printuuid = 0;
5356 struct VLCallBack vlcb;
5359 ListAddrByAttributes m_attrs;
5360 afsUUID m_uuid, askuuid;
5361 afs_int32 m_nentries;
5363 memset(&m_attrs, 0, sizeof(struct ListAddrByAttributes));
5364 m_attrs.Mask = VLADDR_INDEX;
5366 memset(&m_addrs, 0, sizeof(bulkaddrs));
5367 memset(&askuuid, 0, sizeof(afsUUID));
5368 if (as->parms[0].items) {
5370 if (afsUUID_from_string(as->parms[0].items->data, &askuuid) < 0) {
5371 fprintf(STDERR, "vos: invalid UUID '%s'\n",
5372 as->parms[0].items->data);
5375 m_attrs.Mask = VLADDR_UUID;
5376 m_attrs.uuid = askuuid;
5378 if (as->parms[1].items) {
5382 he = hostutil_GetHostByName((char *)as->parms[1].items->data);
5384 fprintf(STDERR, "vos: Can't get host info for '%s'\n",
5385 as->parms[1].items->data);
5388 memcpy(&saddr, he->h_addr, 4);
5389 m_attrs.Mask = VLADDR_IPADDR;
5390 m_attrs.ipaddr = ntohl(saddr);
5392 if (as->parms[2].items) {
5396 m_addrs.bulkaddrs_val = 0;
5397 m_addrs.bulkaddrs_len = 0;
5400 ubik_VL_GetAddrs(cstruct, UBIK_CALL_NEW, 0, 0, &vlcb, &nentries,
5403 fprintf(STDERR, "vos: could not list the server addresses\n");
5404 PrintError("", vcode);
5409 m_addrs.bulkaddrs_val = 0;
5410 m_addrs.bulkaddrs_len = 0;
5416 ubik_VL_GetAddrsU(cstruct, UBIK_CALL_NEW, &m_attrs, &m_uuid,
5417 &m_uniq, &m_nentries, &m_addrs);
5419 if (vcode == VL_NOENT) {
5420 if (m_attrs.Mask == VLADDR_UUID) {
5421 fprintf(STDERR, "vos: no entry for UUID '%s' found in VLDB\n",
5422 as->parms[0].items->data);
5424 } else if (m_attrs.Mask == VLADDR_IPADDR) {
5425 fprintf(STDERR, "vos: no entry for host '%s' [0x%08x] found in VLDB\n",
5426 as->parms[1].items->data, m_attrs.ipaddr);
5435 if (vcode == VL_INDEXERANGE) {
5440 fprintf(STDERR, "vos: could not list the server addresses\n");
5441 PrintError("", vcode);
5445 print_addrs(&m_addrs, &m_uuid, m_nentries, printuuid);
5448 if ((as->parms[1].items) || (as->parms[0].items) || (i > nentries))
5457 SetAddrs(register struct cmd_syndesc *as, void *arock)
5462 afs_uint32 FS_HostAddrs_HBO[ADDRSPERSITE];
5464 memset(&m_addrs, 0, sizeof(bulkaddrs));
5465 memset(&askuuid, 0, sizeof(afsUUID));
5466 if (as->parms[0].items) {
5468 if (afsUUID_from_string(as->parms[0].items->data, &askuuid) < 0) {
5469 fprintf(STDERR, "vos: invalid UUID '%s'\n",
5470 as->parms[0].items->data);
5474 if (as->parms[1].items) {
5476 struct cmd_item *ti;
5480 for (ti = as->parms[1].items; ti && i < ADDRSPERSITE; ti = ti->next) {
5483 saddr = GetServerNoresolve(ti->data);
5485 saddr = GetServer(ti->data);
5488 fprintf(STDERR, "vos: Can't get host info for '%s'\n",
5492 /* Convert it to host byte order */
5493 FS_HostAddrs_HBO[i] = ntohl(saddr);
5496 m_addrs.bulkaddrs_len = i;
5497 m_addrs.bulkaddrs_val = FS_HostAddrs_HBO;
5500 vcode = ubik_VL_RegisterAddrs(cstruct, 0, &askuuid, 0, &m_addrs);
5503 if (vcode == VL_MULTIPADDR) {
5504 fprintf(STDERR, "vos: VL_RegisterAddrs rpc failed; The IP address exists on a different server; repair it\n");
5505 PrintError("", vcode);
5507 } else if (vcode == RXGEN_OPCODE) {
5508 fprintf(STDERR, "vlserver doesn't support VL_RegisterAddrs rpc; ignored\n");
5509 PrintError("", vcode);
5514 fprintf(STDOUT, "vos: Changed UUID with addresses:\n");
5515 print_addrs(&m_addrs, &askuuid, m_addrs.bulkaddrs_len, 1);
5521 LockEntry(register struct cmd_syndesc *as, void *arock)
5524 afs_int32 vcode, err;
5526 avolid = vsu_GetVolumeID(as->parms[0].items->data, cstruct, &err);
5529 PrintError("", err);
5531 fprintf(STDERR, "vos: can't find volume '%s'\n",
5532 as->parms[0].items->data);
5535 vcode = ubik_VL_SetLock(cstruct, 0, avolid, -1, VLOP_DELETE);
5537 fprintf(STDERR, "Could not lock VLDB entry for volume %s\n",
5538 as->parms[0].items->data);
5539 PrintError("", vcode);
5542 fprintf(STDOUT, "Locked VLDB entry for volume %s\n",
5543 as->parms[0].items->data);
5548 ConvertRO(register struct cmd_syndesc *as, void *arock)
5550 afs_int32 partition = -1;
5553 afs_int32 code, i, same;
5554 struct nvldbentry entry, storeEntry;
5556 afs_int32 rwindex = 0;
5557 afs_uint32 rwserver = 0;
5558 afs_int32 rwpartition = 0;
5559 afs_int32 roindex = 0;
5560 afs_uint32 roserver = 0;
5561 afs_int32 ropartition = 0;
5563 struct rx_connection *aconn;
5566 server = GetServer(as->parms[0].items->data);
5568 fprintf(STDERR, "vos: host '%s' not found in host table\n",
5569 as->parms[0].items->data);
5572 partition = volutil_GetPartitionID(as->parms[1].items->data);
5573 if (partition < 0) {
5574 fprintf(STDERR, "vos: could not interpret partition name '%s'\n",
5575 as->parms[1].items->data);
5578 if (!IsPartValid(partition, server, &code)) {
5580 PrintError("", code);
5583 "vos : partition %s does not exist on the server\n",
5584 as->parms[1].items->data);
5587 volid = vsu_GetVolumeID(as->parms[2].items->data, cstruct, &code);
5590 PrintError("", code);
5592 fprintf(STDERR, "Unknown volume ID or name '%s'\n",
5593 as->parms[0].items->data);
5596 if (as->parms[3].items)
5599 vcode = VLDB_GetEntryByID(volid, -1, &entry);
5602 "Could not fetch the entry for volume %lu from VLDB\n",
5603 (unsigned long)volid);
5604 PrintError("convertROtoRW", code);
5608 /* use RO volid even if user specified RW or BK volid */
5610 if (volid != entry.volumeId[ROVOL])
5611 volid = entry.volumeId[ROVOL];
5613 MapHostToNetwork(&entry);
5614 for (i = 0; i < entry.nServers; i++) {
5615 if (entry.serverFlags[i] & ITSRWVOL) {
5617 rwserver = entry.serverNumber[i];
5618 rwpartition = entry.serverPartition[i];
5620 if (entry.serverFlags[i] & ITSROVOL) {
5621 same = VLDB_IsSameAddrs(server, entry.serverNumber[i], &code);
5624 "Failed to get info about server's %d address(es) from vlserver (err=%d); aborting call!\n",
5630 roserver = entry.serverNumber[i];
5631 ropartition = entry.serverPartition[i];
5637 fprintf(STDERR, "Warning: RO volume didn't exist in vldb!\n");
5639 if (ropartition != partition) {
5641 "Warning: RO volume should be in partition %d instead of %d (vldb)\n",
5642 ropartition, partition);
5647 "VLDB indicates that a RW volume exists already on %s in partition %s.\n",
5648 hostutil_GetNameByINet(rwserver),
5649 volutil_PartitionName(rwpartition));
5651 fprintf(STDERR, "Overwrite this VLDB entry? [y|n] (n)\n");
5653 while (!(dc == EOF || dc == '\n'))
5654 dc = getchar(); /* goto end of line */
5655 if ((c != 'y') && (c != 'Y')) {
5656 fprintf(STDERR, "aborted.\n");
5663 ubik_VL_SetLock(cstruct, 0, entry.volumeId[RWVOL], RWVOL,
5665 aconn = UV_Bind(server, AFSCONF_VOLUMEPORT);
5666 code = AFSVolConvertROtoRWvolume(aconn, partition, volid);
5669 "Converting RO volume %lu to RW volume failed with code %d\n",
5670 (unsigned long)volid, code);
5671 PrintError("convertROtoRW ", code);
5674 entry.serverFlags[roindex] = ITSRWVOL;
5675 entry.flags |= RW_EXISTS;
5676 entry.flags &= ~BACK_EXISTS;
5679 if (rwindex != entry.nServers) {
5680 entry.serverNumber[rwindex] = entry.serverNumber[entry.nServers];
5681 entry.serverPartition[rwindex] =
5682 entry.serverPartition[entry.nServers];
5683 entry.serverFlags[rwindex] = entry.serverFlags[entry.nServers];
5684 entry.serverNumber[entry.nServers] = 0;
5685 entry.serverPartition[entry.nServers] = 0;
5686 entry.serverFlags[entry.nServers] = 0;
5689 entry.flags &= ~RO_EXISTS;
5690 for (i = 0; i < entry.nServers; i++) {
5691 if (entry.serverFlags[i] & ITSROVOL) {
5692 if (!(entry.serverFlags[i] & (RO_DONTUSE | NEW_REPSITE)))
5693 entry.flags |= RO_EXISTS;
5696 MapNetworkToHost(&entry, &storeEntry);
5698 VLDB_ReplaceEntry(entry.volumeId[RWVOL], RWVOL, &storeEntry,
5699 (LOCKREL_OPCODE | LOCKREL_AFSID |
5700 LOCKREL_TIMESTAMP));
5703 "Warning: volume converted, but vldb update failed with code %d!\n",
5706 vcode = UV_LockRelease(entry.volumeId[RWVOL]);
5708 PrintDiagnostics("unlock", vcode);
5714 Sizes(register struct cmd_syndesc *as, void *arock)
5718 afs_int32 apart, voltype, fromdate = 0, code, err, i;
5719 struct nvldbentry entry;
5720 volintSize vol_size;
5722 rx_SetRxDeadTime(60 * 10);
5723 for (i = 0; i < MAXSERVERS; i++) {
5724 struct rx_connection *rxConn = ubik_GetRPCConn(cstruct, i);
5727 rx_SetConnDeadTime(rxConn, rx_connDeadTime);
5728 if (rxConn->service)
5729 rxConn->service->connDeadTime = rx_connDeadTime;
5732 avolid = vsu_GetVolumeID(as->parms[0].items->data, cstruct, &err);
5735 PrintError("", err);
5737 fprintf(STDERR, "vos: can't find volume '%s'\n",
5738 as->parms[0].items->data);
5742 if (as->parms[1].items || as->parms[2].items) {
5743 if (!as->parms[1].items || !as->parms[2].items) {
5745 "Must specify both -server and -partition options\n");
5748 aserver = GetServer(as->parms[2].items->data);
5750 fprintf(STDERR, "Invalid server name\n");
5753 apart = volutil_GetPartitionID(as->parms[1].items->data);
5755 fprintf(STDERR, "Invalid partition name\n");
5759 code = GetVolumeInfo(avolid, &aserver, &apart, &voltype, &entry);
5766 if (as->parms[4].items && strcmp(as->parms[4].items->data, "0")) {
5767 code = ktime_DateToInt32(as->parms[4].items->data, &fromdate);
5769 fprintf(STDERR, "vos: failed to parse date '%s' (error=%d))\n",
5770 as->parms[4].items->data, code);
5775 fprintf(STDOUT, "Volume: %s\n", as->parms[0].items->data);
5777 if (as->parms[3].items) { /* do the dump estimate */
5778 #ifdef AFS_64BIT_ENV
5779 vol_size.dump_size = 0;
5781 FillInt64(vol_size.dump_size,0, 1);
5783 code = UV_GetSize(avolid, aserver, apart, fromdate, &vol_size);
5785 PrintDiagnostics("size", code);
5788 /* presumably the size info is now gathered in pntr */
5789 /* now we display it */
5791 fprintf(STDOUT, "dump_size: %llu\n", vol_size.dump_size);
5800 EndTrans(register struct cmd_syndesc *as, void *arock)
5803 afs_int32 code, tid, rcode;
5804 struct rx_connection *aconn;
5806 server = GetServer(as->parms[0].items->data);
5808 fprintf(STDERR, "vos: host '%s' not found in host table\n",
5809 as->parms[0].items->data);
5813 code = util_GetInt32(as->parms[1].items->data, &tid);
5815 fprintf(STDERR, "vos: bad integer specified for transaction ID.\n");
5819 aconn = UV_Bind(server, AFSCONF_VOLUMEPORT);
5820 code = AFSVolEndTrans(aconn, tid, &rcode);
5826 PrintDiagnostics("endtrans", code);
5834 PrintDiagnostics(char *astring, afs_int32 acode)
5836 if (acode == EACCES) {
5838 "You are not authorized to perform the 'vos %s' command (%d)\n",
5841 fprintf(STDERR, "Error in vos %s command.\n", astring);
5842 PrintError("", acode);
5850 win32_enableCrypt(void)
5857 /* Look up configuration parameters in Registry */
5858 code = RegOpenKeyEx(HKEY_LOCAL_MACHINE, AFSREG_CLT_SVC_PARAM_SUBKEY,
5859 0, (IsWow64()?KEY_WOW64_64KEY:0)|KEY_QUERY_VALUE, &parmKey);
5860 if (code != ERROR_SUCCESS) {
5861 dummyLen = sizeof(cryptall);
5862 RegQueryValueEx(parmKey, "SecurityLevel", NULL, NULL,
5863 (BYTE *) &cryptall, &dummyLen);
5865 RegCloseKey (parmKey);
5869 #endif /* AFS_NT40_ENV */
5872 MyBeforeProc(struct cmd_syndesc *as, void *arock)
5874 register char *tcell;
5875 register afs_int32 code;
5876 register afs_int32 sauth;
5878 /* Initialize the ubik_client connection */
5879 rx_SetRxDeadTime(90);
5880 cstruct = (struct ubik_client *)0;
5884 if (as->parms[12].items) /* if -cell specified */
5885 tcell = as->parms[12].items->data;
5886 if (as->parms[14].items) /* -serverauth specified */
5888 if (as->parms[16].items /* -encrypt specified */
5890 || win32_enableCrypt()
5891 #endif /* AFS_NT40_ENV */
5895 vsu_ClientInit((as->parms[13].items != 0), confdir, tcell, sauth,
5896 &cstruct, UV_SetSecurity))) {
5897 fprintf(STDERR, "could not initialize VLDB library (code=%lu) \n",
5898 (unsigned long)code);
5902 if (as->parms[15].items) /* -verbose flag set */
5906 if (as->parms[17].items) /* -noresolve flag set */
5916 /* this sucks but it works for now.
5921 #include "AFS_component_version_number.c"
5924 main(int argc, char **argv)
5926 register afs_int32 code;
5928 register struct cmd_syndesc *ts;
5930 #ifdef AFS_AIX32_ENV
5932 * The following signal action for AIX is necessary so that in case of a
5933 * crash (i.e. core is generated) we can include the user's data section
5934 * in the core dump. Unfortunately, by default, only a partial core is
5935 * generated which, in many cases, isn't too useful.
5937 struct sigaction nsa;
5939 sigemptyset(&nsa.sa_mask);
5940 nsa.sa_handler = SIG_DFL;
5941 nsa.sa_flags = SA_FULLDUMP;
5942 sigaction(SIGSEGV, &nsa, NULL);
5945 confdir = AFSDIR_CLIENT_ETC_DIRPATH;
5947 cmd_SetBeforeProc(MyBeforeProc, NULL);
5949 ts = cmd_CreateSyntax("create", CreateVolume, NULL, "create a new volume");
5950 cmd_AddParm(ts, "-server", CMD_SINGLE, 0, "machine name");
5951 cmd_AddParm(ts, "-partition", CMD_SINGLE, 0, "partition name");
5952 cmd_AddParm(ts, "-name", CMD_SINGLE, 0, "volume name");
5953 cmd_AddParm(ts, "-maxquota", CMD_SINGLE, CMD_OPTIONAL,
5954 "initial quota (KB)");
5955 cmd_AddParm(ts, "-id", CMD_SINGLE, CMD_OPTIONAL, "volume ID");
5956 cmd_AddParm(ts, "-roid", CMD_SINGLE, CMD_OPTIONAL, "readonly volume ID");
5958 cmd_AddParm(ts, "-minquota", CMD_SINGLE, CMD_OPTIONAL, "");
5962 ts = cmd_CreateSyntax("remove", DeleteVolume, NULL, "delete a volume");
5963 cmd_AddParm(ts, "-server", CMD_SINGLE, CMD_OPTIONAL, "machine name");
5964 cmd_AddParm(ts, "-partition", CMD_SINGLE, CMD_OPTIONAL, "partition name");
5965 cmd_AddParm(ts, "-id", CMD_SINGLE, 0, "volume name or ID");
5969 ts = cmd_CreateSyntax("move", MoveVolume, NULL, "move a volume");
5970 cmd_AddParm(ts, "-id", CMD_SINGLE, 0, "volume name or ID");
5971 cmd_AddParm(ts, "-fromserver", CMD_SINGLE, 0, "machine name on source");
5972 cmd_AddParm(ts, "-frompartition", CMD_SINGLE, 0,
5973 "partition name on source");
5974 cmd_AddParm(ts, "-toserver", CMD_SINGLE, 0,
5975 "machine name on destination");
5976 cmd_AddParm(ts, "-topartition", CMD_SINGLE, 0,
5977 "partition name on destination");
5978 cmd_AddParm(ts, "-live", CMD_FLAG, CMD_OPTIONAL,
5979 "copy live volume without cloning");
5982 ts = cmd_CreateSyntax("copy", CopyVolume, NULL, "copy a volume");
5983 cmd_AddParm(ts, "-id", CMD_SINGLE, 0, "volume name or ID on source");
5984 cmd_AddParm(ts, "-fromserver", CMD_SINGLE, 0, "machine name on source");
5985 cmd_AddParm(ts, "-frompartition", CMD_SINGLE, 0,
5986 "partition name on source");
5987 cmd_AddParm(ts, "-toname", CMD_SINGLE, 0, "volume name on destination");
5988 cmd_AddParm(ts, "-toserver", CMD_SINGLE, 0,
5989 "machine name on destination");
5990 cmd_AddParm(ts, "-topartition", CMD_SINGLE, 0,
5991 "partition name on destination");
5992 cmd_AddParm(ts, "-offline", CMD_FLAG, CMD_OPTIONAL,
5993 "leave new volume offline");
5994 cmd_AddParm(ts, "-readonly", CMD_FLAG, CMD_OPTIONAL,
5995 "make new volume read-only");
5996 cmd_AddParm(ts, "-live", CMD_FLAG, CMD_OPTIONAL,
5997 "copy live volume without cloning");
6000 ts = cmd_CreateSyntax("shadow", ShadowVolume, NULL,
6001 "make or update a shadow volume");
6002 cmd_AddParm(ts, "-id", CMD_SINGLE, 0, "volume name or ID on source");
6003 cmd_AddParm(ts, "-fromserver", CMD_SINGLE, 0, "machine name on source");
6004 cmd_AddParm(ts, "-frompartition", CMD_SINGLE, 0,
6005 "partition name on source");
6006 cmd_AddParm(ts, "-toserver", CMD_SINGLE, 0,
6007 "machine name on destination");
6008 cmd_AddParm(ts, "-topartition", CMD_SINGLE, 0,
6009 "partition name on destination");
6010 cmd_AddParm(ts, "-toname", CMD_SINGLE, CMD_OPTIONAL,
6011 "volume name on destination");
6012 cmd_AddParm(ts, "-toid", CMD_SINGLE, CMD_OPTIONAL,
6013 "volume ID on destination");
6014 cmd_AddParm(ts, "-offline", CMD_FLAG, CMD_OPTIONAL,
6015 "leave shadow volume offline");
6016 cmd_AddParm(ts, "-readonly", CMD_FLAG, CMD_OPTIONAL,
6017 "make shadow volume read-only");
6018 cmd_AddParm(ts, "-live", CMD_FLAG, CMD_OPTIONAL,
6019 "copy live volume without cloning");
6020 cmd_AddParm(ts, "-incremental", CMD_FLAG, CMD_OPTIONAL,
6021 "do incremental update if target exists");
6024 ts = cmd_CreateSyntax("backup", BackupVolume, NULL,
6025 "make backup of a volume");
6026 cmd_AddParm(ts, "-id", CMD_SINGLE, 0, "volume name or ID");
6029 ts = cmd_CreateSyntax("clone", CloneVolume, NULL,
6030 "make clone of a volume");
6031 cmd_AddParm(ts, "-id", CMD_SINGLE, 0, "volume name or ID");
6032 cmd_AddParm(ts, "-server", CMD_SINGLE, CMD_OPTIONAL, "server");
6033 cmd_AddParm(ts, "-partition", CMD_SINGLE, CMD_OPTIONAL, "partition");
6034 cmd_AddParm(ts, "-toname", CMD_SINGLE, CMD_OPTIONAL,
6035 "volume name on destination");
6036 cmd_AddParm(ts, "-toid", CMD_SINGLE, CMD_OPTIONAL,
6037 "volume ID on destination");
6038 cmd_AddParm(ts, "-offline", CMD_FLAG, CMD_OPTIONAL,
6039 "leave clone volume offline");
6040 cmd_AddParm(ts, "-readonly", CMD_FLAG, CMD_OPTIONAL,
6041 "make clone volume read-only, not readwrite");
6044 ts = cmd_CreateSyntax("release", ReleaseVolume, NULL, "release a volume");
6045 cmd_AddParm(ts, "-id", CMD_SINGLE, 0, "volume name or ID");
6046 cmd_AddParm(ts, "-force", CMD_FLAG, CMD_OPTIONAL,
6047 "force a complete release");
6050 ts = cmd_CreateSyntax("dump", DumpVolumeCmd, NULL, "dump a volume");
6051 cmd_AddParm(ts, "-id", CMD_SINGLE, 0, "volume name or ID");
6052 cmd_AddParm(ts, "-time", CMD_SINGLE, CMD_OPTIONAL, "dump from time");
6053 cmd_AddParm(ts, "-file", CMD_SINGLE, CMD_OPTIONAL, "dump file");
6054 cmd_AddParm(ts, "-server", CMD_SINGLE, CMD_OPTIONAL, "server");
6055 cmd_AddParm(ts, "-partition", CMD_SINGLE, CMD_OPTIONAL, "partition");
6056 cmd_AddParm(ts, "-clone", CMD_FLAG, CMD_OPTIONAL,
6057 "dump a clone of the volume");
6058 cmd_AddParm(ts, "-omitdirs", CMD_FLAG, CMD_OPTIONAL,
6059 "omit unchanged directories from an incremental dump");
6062 ts = cmd_CreateSyntax("restore", RestoreVolumeCmd, NULL,
6063 "restore a volume");
6064 cmd_AddParm(ts, "-server", CMD_SINGLE, 0, "machine name");
6065 cmd_AddParm(ts, "-partition", CMD_SINGLE, 0, "partition name");
6066 cmd_AddParm(ts, "-name", CMD_SINGLE, 0, "name of volume to be restored");
6067 cmd_AddParm(ts, "-file", CMD_SINGLE, CMD_OPTIONAL, "dump file");
6068 cmd_AddParm(ts, "-id", CMD_SINGLE, CMD_OPTIONAL, "volume ID");
6069 cmd_AddParm(ts, "-overwrite", CMD_SINGLE, CMD_OPTIONAL,
6070 "abort | full | incremental");
6071 cmd_AddParm(ts, "-offline", CMD_FLAG, CMD_OPTIONAL,
6072 "leave restored volume offline");
6073 cmd_AddParm(ts, "-readonly", CMD_FLAG, CMD_OPTIONAL,
6074 "make restored volume read-only");
6075 cmd_AddParm(ts, "-creation", CMD_SINGLE, CMD_OPTIONAL,
6076 "dump | keep | new");
6077 cmd_AddParm(ts, "-lastupdate", CMD_SINGLE, CMD_OPTIONAL,
6078 "dump | keep | new");
6079 cmd_AddParm(ts, "-nodelete", CMD_FLAG, CMD_OPTIONAL,
6080 "do not delete old site when restoring to a new site");
6083 ts = cmd_CreateSyntax("unlock", LockReleaseCmd, NULL,
6084 "release lock on VLDB entry for a volume");
6085 cmd_AddParm(ts, "-id", CMD_SINGLE, 0, "volume name or ID");
6088 ts = cmd_CreateSyntax("changeloc", ChangeLocation, NULL,
6089 "change an RW volume's location in the VLDB");
6090 cmd_AddParm(ts, "-server", CMD_SINGLE, 0,
6091 "machine name for new location");
6092 cmd_AddParm(ts, "-partition", CMD_SINGLE, 0,
6093 "partition name for new location");
6094 cmd_AddParm(ts, "-id", CMD_SINGLE, 0, "volume name or ID");
6097 ts = cmd_CreateSyntax("addsite", AddSite, NULL, "add a replication site");
6098 cmd_AddParm(ts, "-server", CMD_SINGLE, 0, "machine name for new site");
6099 cmd_AddParm(ts, "-partition", CMD_SINGLE, 0,
6100 "partition name for new site");
6101 cmd_AddParm(ts, "-id", CMD_SINGLE, 0, "volume name or ID");
6102 cmd_AddParm(ts, "-roid", CMD_SINGLE, CMD_OPTIONAL, "volume name or ID for RO");
6103 cmd_AddParm(ts, "-valid", CMD_FLAG, CMD_OPTIONAL, "publish as an up-to-date site in VLDB");
6106 ts = cmd_CreateSyntax("remsite", RemoveSite, NULL,
6107 "remove a replication site");
6108 cmd_AddParm(ts, "-server", CMD_SINGLE, 0, "machine name");
6109 cmd_AddParm(ts, "-partition", CMD_SINGLE, 0, "partition name");
6110 cmd_AddParm(ts, "-id", CMD_SINGLE, 0, "volume name or ID");
6113 ts = cmd_CreateSyntax("listpart", ListPartitions, NULL, "list partitions");
6114 cmd_AddParm(ts, "-server", CMD_SINGLE, 0, "machine name");
6117 ts = cmd_CreateSyntax("listvol", ListVolumes, NULL,
6118 "list volumes on server (bypass VLDB)");
6119 cmd_AddParm(ts, "-server", CMD_SINGLE, 0, "machine name");
6120 cmd_AddParm(ts, "-partition", CMD_SINGLE, CMD_OPTIONAL, "partition name");
6121 cmd_AddParm(ts, "-fast", CMD_FLAG, CMD_OPTIONAL, "minimal listing");
6122 cmd_AddParm(ts, "-long", CMD_FLAG, CMD_OPTIONAL,
6123 "list all normal volume fields");
6124 cmd_AddParm(ts, "-quiet", CMD_FLAG, CMD_OPTIONAL,
6125 "generate minimal information");
6126 cmd_AddParm(ts, "-extended", CMD_FLAG, CMD_OPTIONAL,
6127 "list extended volume fields");
6128 cmd_AddParm(ts, "-format", CMD_FLAG, CMD_OPTIONAL,
6129 "machine readable format");
6132 ts = cmd_CreateSyntax("syncvldb", SyncVldb, NULL,
6133 "synchronize VLDB with server");
6134 cmd_AddParm(ts, "-server", CMD_SINGLE, CMD_OPTIONAL, "machine name");
6135 cmd_AddParm(ts, "-partition", CMD_SINGLE, CMD_OPTIONAL, "partition name");
6136 cmd_AddParm(ts, "-volume", CMD_SINGLE, CMD_OPTIONAL, "volume name or ID");
6137 cmd_AddParm(ts, "-dryrun", CMD_FLAG, CMD_OPTIONAL, "report without updating");
6140 ts = cmd_CreateSyntax("syncserv", SyncServer, NULL,
6141 "synchronize server with VLDB");
6142 cmd_AddParm(ts, "-server", CMD_SINGLE, 0, "machine name");
6143 cmd_AddParm(ts, "-partition", CMD_SINGLE, CMD_OPTIONAL, "partition name");
6144 cmd_AddParm(ts, "-dryrun", CMD_FLAG, CMD_OPTIONAL, "report without updating");
6147 ts = cmd_CreateSyntax("examine", ExamineVolume, NULL,
6148 "everything about the volume");
6149 cmd_AddParm(ts, "-id", CMD_SINGLE, 0, "volume name or ID");
6150 cmd_AddParm(ts, "-extended", CMD_FLAG, CMD_OPTIONAL,
6151 "list extended volume fields");
6152 cmd_AddParm(ts, "-format", CMD_FLAG, CMD_OPTIONAL,
6153 "machine readable format");
6155 cmd_CreateAlias(ts, "volinfo");
6157 ts = cmd_CreateSyntax("setfields", SetFields, NULL,
6158 "change volume info fields");
6159 cmd_AddParm(ts, "-id", CMD_SINGLE, 0, "volume name or ID");
6160 cmd_AddParm(ts, "-maxquota", CMD_SINGLE, CMD_OPTIONAL, "quota (KB)");
6161 cmd_AddParm(ts, "-clearuse", CMD_FLAG, CMD_OPTIONAL, "clear dayUse");
6162 cmd_AddParm(ts, "-clearVolUpCounter", CMD_FLAG, CMD_OPTIONAL, "clear volUpdateCounter");
6165 ts = cmd_CreateSyntax("offline", volOffline, NULL, "force the volume status to offline");
6166 cmd_AddParm(ts, "-server", CMD_SINGLE, 0, "server name");
6167 cmd_AddParm(ts, "-partition", CMD_SINGLE, 0, "partition name");
6168 cmd_AddParm(ts, "-id", CMD_SINGLE, 0, "volume name or ID");
6169 cmd_AddParm(ts, "-sleep", CMD_SINGLE, CMD_OPTIONAL, "seconds to sleep");
6170 cmd_AddParm(ts, "-busy", CMD_FLAG, CMD_OPTIONAL, "busy volume");
6173 ts = cmd_CreateSyntax("online", volOnline, NULL, "force the volume status to online");
6174 cmd_AddParm(ts, "-server", CMD_SINGLE, 0, "server name");
6175 cmd_AddParm(ts, "-partition", CMD_SINGLE, 0, "partition name");
6176 cmd_AddParm(ts, "-id", CMD_SINGLE, 0, "volume name or ID");
6179 ts = cmd_CreateSyntax("zap", VolumeZap, NULL,
6180 "delete the volume, don't bother with VLDB");
6181 cmd_AddParm(ts, "-server", CMD_SINGLE, 0, "machine name");
6182 cmd_AddParm(ts, "-partition", CMD_SINGLE, 0, "partition name");
6183 cmd_AddParm(ts, "-id", CMD_SINGLE, 0, "volume ID");
6184 cmd_AddParm(ts, "-force", CMD_FLAG, CMD_OPTIONAL,
6185 "force deletion of bad volumes");
6186 cmd_AddParm(ts, "-backup", CMD_FLAG, CMD_OPTIONAL,
6187 "also delete backup volume if one is found");
6190 ts = cmd_CreateSyntax("status", VolserStatus, NULL,
6191 "report on volser status");
6192 cmd_AddParm(ts, "-server", CMD_SINGLE, 0, "machine name");
6195 ts = cmd_CreateSyntax("rename", RenameVolume, NULL, "rename a volume");
6196 cmd_AddParm(ts, "-oldname", CMD_SINGLE, 0, "old volume name ");
6197 cmd_AddParm(ts, "-newname", CMD_SINGLE, 0, "new volume name ");
6200 ts = cmd_CreateSyntax("listvldb", ListVLDB, NULL,
6201 "list volumes in the VLDB");
6202 cmd_AddParm(ts, "-name", CMD_SINGLE, CMD_OPTIONAL, "volume name or ID");
6203 cmd_AddParm(ts, "-server", CMD_SINGLE, CMD_OPTIONAL, "machine name");
6204 cmd_AddParm(ts, "-partition", CMD_SINGLE, CMD_OPTIONAL, "partition name");
6205 cmd_AddParm(ts, "-locked", CMD_FLAG, CMD_OPTIONAL, "locked volumes only");
6206 cmd_AddParm(ts, "-quiet", CMD_FLAG, CMD_OPTIONAL,
6207 "generate minimal information");
6208 cmd_AddParm(ts, "-nosort", CMD_FLAG, CMD_OPTIONAL,
6209 "do not alphabetically sort the volume names");
6212 ts = cmd_CreateSyntax("backupsys", BackSys, NULL, "en masse backups");
6213 cmd_AddParm(ts, "-prefix", CMD_LIST, CMD_OPTIONAL,
6214 "common prefix on volume(s)");
6215 cmd_AddParm(ts, "-server", CMD_SINGLE, CMD_OPTIONAL, "machine name");
6216 cmd_AddParm(ts, "-partition", CMD_SINGLE, CMD_OPTIONAL, "partition name");
6217 cmd_AddParm(ts, "-exclude", CMD_FLAG, CMD_OPTIONAL,
6218 "exclude common prefix volumes");
6219 cmd_AddParm(ts, "-xprefix", CMD_LIST, CMD_OPTIONAL,
6220 "negative prefix on volume(s)");
6221 cmd_AddParm(ts, "-dryrun", CMD_FLAG, CMD_OPTIONAL, "no action");
6224 ts = cmd_CreateSyntax("delentry", DeleteEntry, NULL,
6225 "delete VLDB entry for a volume");
6226 cmd_AddParm(ts, "-id", CMD_LIST, CMD_OPTIONAL, "volume name or ID");
6227 cmd_AddParm(ts, "-prefix", CMD_SINGLE, CMD_OPTIONAL,
6228 "prefix of the volume whose VLDB entry is to be deleted");
6229 cmd_AddParm(ts, "-server", CMD_SINGLE, CMD_OPTIONAL, "machine name");
6230 cmd_AddParm(ts, "-partition", CMD_SINGLE, CMD_OPTIONAL, "partition name");
6231 cmd_AddParm(ts, "-noexecute", CMD_FLAG, CMD_OPTIONAL,
6235 ts = cmd_CreateSyntax("partinfo", PartitionInfo, NULL,
6236 "list partition information");
6237 cmd_AddParm(ts, "-server", CMD_SINGLE, 0, "machine name");
6238 cmd_AddParm(ts, "-partition", CMD_SINGLE, CMD_OPTIONAL, "partition name");
6239 cmd_AddParm(ts, "-summary", CMD_FLAG, CMD_OPTIONAL,
6240 "print storage summary");
6243 ts = cmd_CreateSyntax("unlockvldb", UnlockVLDB, NULL,
6244 "unlock all the locked entries in the VLDB");
6245 cmd_AddParm(ts, "-server", CMD_SINGLE, CMD_OPTIONAL, "machine name");
6246 cmd_AddParm(ts, "-partition", CMD_SINGLE, CMD_OPTIONAL, "partition name");
6249 ts = cmd_CreateSyntax("lock", LockEntry, NULL,
6250 "lock VLDB entry for a volume");
6251 cmd_AddParm(ts, "-id", CMD_SINGLE, 0, "volume name or ID");
6254 ts = cmd_CreateSyntax("changeaddr", ChangeAddr, NULL,
6255 "change the IP address of a file server");
6256 cmd_AddParm(ts, "-oldaddr", CMD_SINGLE, 0, "original IP address");
6257 cmd_AddParm(ts, "-newaddr", CMD_SINGLE, CMD_OPTIONAL, "new IP address");
6258 cmd_AddParm(ts, "-remove", CMD_FLAG, CMD_OPTIONAL,
6259 "remove the IP address from the VLDB");
6262 ts = cmd_CreateSyntax("listaddrs", ListAddrs, NULL,
6263 "list the IP address of all file servers registered in the VLDB");
6264 cmd_AddParm(ts, "-uuid", CMD_SINGLE, CMD_OPTIONAL, "uuid of server");
6265 cmd_AddParm(ts, "-host", CMD_SINGLE, CMD_OPTIONAL, "address of host");
6266 cmd_AddParm(ts, "-printuuid", CMD_FLAG, CMD_OPTIONAL,
6267 "print uuid of hosts");
6270 ts = cmd_CreateSyntax("convertROtoRW", ConvertRO, NULL,
6271 "convert a RO volume into a RW volume (after loss of old RW volume)");
6272 cmd_AddParm(ts, "-server", CMD_SINGLE, 0, "machine name");
6273 cmd_AddParm(ts, "-partition", CMD_SINGLE, 0, "partition name");
6274 cmd_AddParm(ts, "-id", CMD_SINGLE, 0, "volume name or ID");
6275 cmd_AddParm(ts, "-force", CMD_FLAG, CMD_OPTIONAL, "don't ask");
6278 ts = cmd_CreateSyntax("size", Sizes, NULL,
6279 "obtain various sizes of the volume.");
6280 cmd_AddParm(ts, "-id", CMD_SINGLE, 0, "volume name or ID");
6281 cmd_AddParm(ts, "-partition", CMD_SINGLE, CMD_OPTIONAL, "partition name");
6282 cmd_AddParm(ts, "-server", CMD_SINGLE, CMD_OPTIONAL, "machine name");
6283 cmd_AddParm(ts, "-dump", CMD_FLAG, CMD_OPTIONAL,
6284 "Obtain the size of the dump");
6285 cmd_AddParm(ts, "-time", CMD_SINGLE, CMD_OPTIONAL, "dump from time");
6288 ts = cmd_CreateSyntax("endtrans", EndTrans, NULL,
6289 "end a volserver transaction");
6290 cmd_AddParm(ts, "-server", CMD_SINGLE, 0, "machine name");
6291 cmd_AddParm(ts, "-transaction", CMD_SINGLE, 0,
6295 ts = cmd_CreateSyntax("setaddrs", SetAddrs, NULL,
6296 "set the list of IP address for a given UUID in the VLDB");
6297 cmd_AddParm(ts, "-uuid", CMD_SINGLE, 0, "uuid of server");
6298 cmd_AddParm(ts, "-host", CMD_LIST, 0, "address of host");
6301 code = cmd_Dispatch(argc, argv);
6303 /* Shut down the ubik_client and rx connections */
6305 (void)ubik_ClientDestroy(cstruct);
6311 exit((code ? -1 : 0));