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)
228 afs_uint32 addr; /* in network byte order */
230 char hostname[MAXHOSTCHARS];
232 if ((addr = GetServerNoresolve(aname)) == 0) {
233 th = gethostbyname(aname);
236 memcpy(&addr, th->h_addr, sizeof(addr));
239 if (rx_IsLoopbackAddr(ntohl(addr))) { /* 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, 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(struct cmd_syndesc *as)
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(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? */
1582 int isSubEnum=0; /* Keep track whether sub enumerate called. */
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);
1674 VolumeStats_int(pntr, &entry, aserver, apart, voltype);
1676 if ((voltype == BACKVOL) && !(entry.flags & BACK_EXISTS)) {
1677 /* The VLDB says there is no backup volume yet we found one on disk */
1678 fprintf(STDERR, "Volume %s does not exist in VLDB\n",
1679 as->parms[0].items->data);
1688 } while (voltype == ROVOL);
1691 fprintf(STDERR, "Dump only information from VLDB\n\n");
1692 fprintf(STDOUT, "%s \n", entry.name); /* PostVolumeStats doesn't print name */
1696 PostVolumeStats(&entry);
1701 /*------------------------------------------------------------------------
1705 * Routine used to change the status of a single volume.
1708 * as : Ptr to parsed command line arguments.
1711 * 0 for a successful operation,
1712 * Otherwise, one of the ubik or VolServer error values.
1715 * Nothing interesting.
1719 *------------------------------------------------------------------------
1722 SetFields(struct cmd_syndesc *as, void *arock)
1724 struct nvldbentry entry;
1727 afs_int32 code, err;
1732 volid = vsu_GetVolumeID(as->parms[0].items->data, cstruct, &err); /* -id */
1735 PrintError("", err);
1737 fprintf(STDERR, "Unknown volume ID or name '%s'\n",
1738 as->parms[0].items->data);
1742 code = VLDB_GetEntryByID(volid, RWVOL, &entry);
1745 "Could not fetch the entry for volume number %lu from VLDB \n",
1746 (unsigned long)volid);
1749 MapHostToNetwork(&entry);
1751 GetServerAndPart(&entry, RWVOL, &aserver, &apart, &previdx);
1752 if (previdx == -1) {
1753 fprintf(STDERR, "Volume %s does not exist in VLDB\n\n",
1754 as->parms[0].items->data);
1758 init_volintInfo(&info);
1762 if (as->parms[1].items) {
1764 code = util_GetHumanInt32(as->parms[1].items->data, &info.maxquota);
1766 fprintf(STDERR, "invalid quota value\n");
1770 if (as->parms[2].items) {
1774 if (as->parms[3].items) {
1775 /* -clearVolUpCounter */
1778 code = UV_SetVolumeInfo(aserver, apart, volid, &info);
1781 "Could not update volume info fields for volume number %lu\n",
1782 (unsigned long)volid);
1786 /*------------------------------------------------------------------------
1790 * Brings a volume online.
1793 * as : Ptr to parsed command line arguments.
1796 * 0 for a successful operation,
1799 * Nothing interesting.
1803 *------------------------------------------------------------------------
1806 volOnline(struct cmd_syndesc *as, void *arock)
1809 afs_int32 partition;
1811 afs_int32 code, err = 0;
1813 server = GetServer(as->parms[0].items->data);
1815 fprintf(STDERR, "vos: server '%s' not found in host table\n",
1816 as->parms[0].items->data);
1820 partition = volutil_GetPartitionID(as->parms[1].items->data);
1821 if (partition < 0) {
1822 fprintf(STDERR, "vos: could not interpret partition name '%s'\n",
1823 as->parms[1].items->data);
1827 volid = vsu_GetVolumeID(as->parms[2].items->data, cstruct, &err); /* -id */
1830 PrintError("", err);
1832 fprintf(STDERR, "Unknown volume ID or name '%s'\n",
1833 as->parms[0].items->data);
1837 code = UV_SetVolume(server, partition, volid, ITOffline, 0 /*online */ ,
1840 fprintf(STDERR, "Failed to set volume. Code = %d\n", code);
1847 /*------------------------------------------------------------------------
1848 * PRIVATE volOffline
1851 * Brings a volume offline.
1854 * as : Ptr to parsed command line arguments.
1857 * 0 for a successful operation,
1860 * Nothing interesting.
1864 *------------------------------------------------------------------------
1867 volOffline(struct cmd_syndesc *as, void *arock)
1870 afs_int32 partition;
1872 afs_int32 code, err = 0;
1873 afs_int32 transflag, sleeptime, transdone;
1875 server = GetServer(as->parms[0].items->data);
1877 fprintf(STDERR, "vos: server '%s' not found in host table\n",
1878 as->parms[0].items->data);
1882 partition = volutil_GetPartitionID(as->parms[1].items->data);
1883 if (partition < 0) {
1884 fprintf(STDERR, "vos: could not interpret partition name '%s'\n",
1885 as->parms[1].items->data);
1889 volid = vsu_GetVolumeID(as->parms[2].items->data, cstruct, &err); /* -id */
1892 PrintError("", err);
1894 fprintf(STDERR, "Unknown volume ID or name '%s'\n",
1895 as->parms[0].items->data);
1899 transflag = (as->parms[4].items ? ITBusy : ITOffline);
1900 sleeptime = (as->parms[3].items ? atol(as->parms[3].items->data) : 0);
1901 transdone = (sleeptime ? 0 /*online */ : VTOutOfService);
1902 if (as->parms[4].items && !as->parms[3].items) {
1903 fprintf(STDERR, "-sleep option must be used with -busy flag\n");
1908 UV_SetVolume(server, partition, volid, transflag, transdone,
1911 fprintf(STDERR, "Failed to set volume. Code = %d\n", code);
1919 CreateVolume(struct cmd_syndesc *as, void *arock)
1923 afs_uint32 volid = 0, rovolid = 0, bkvolid = 0;
1924 afs_uint32 *arovolid;
1926 struct nvldbentry entry;
1930 arovolid = &rovolid;
1933 tserver = GetServer(as->parms[0].items->data);
1935 fprintf(STDERR, "vos: host '%s' not found in host table\n",
1936 as->parms[0].items->data);
1939 pnum = volutil_GetPartitionID(as->parms[1].items->data);
1941 fprintf(STDERR, "vos: could not interpret partition name '%s'\n",
1942 as->parms[1].items->data);
1945 if (!IsPartValid(pnum, tserver, &code)) { /*check for validity of the partition */
1947 PrintError("", code);
1950 "vos : partition %s does not exist on the server\n",
1951 as->parms[1].items->data);
1954 if (!ISNAMEVALID(as->parms[2].items->data)) {
1956 "vos: the name of the root volume %s exceeds the size limit of %d\n",
1957 as->parms[2].items->data, VOLSER_OLDMAXVOLNAME - 10);
1960 if (!VolNameOK(as->parms[2].items->data)) {
1962 "Illegal volume name %s, should not end in .readonly or .backup\n",
1963 as->parms[2].items->data);
1966 if (IsNumeric(as->parms[2].items->data)) {
1967 fprintf(STDERR, "Illegal volume name %s, should not be a number\n",
1968 as->parms[2].items->data);
1971 vcode = VLDB_GetEntryByName(as->parms[2].items->data, &entry);
1973 fprintf(STDERR, "Volume %s already exists\n",
1974 as->parms[2].items->data);
1975 PrintDiagnostics("create", code);
1979 if (as->parms[3].items) {
1980 code = util_GetHumanInt32(as->parms[3].items->data, "a);
1982 fprintf(STDERR, "vos: bad integer specified for quota.\n");
1987 if (as->parms[4].items) {
1988 if (!IsNumeric(as->parms[4].items->data)) {
1989 fprintf(STDERR, "vos: Given volume ID %s should be numeric.\n",
1990 as->parms[4].items->data);
1994 code = util_GetUInt32(as->parms[4].items->data, &volid);
1996 fprintf(STDERR, "vos: bad integer specified for volume ID.\n");
2001 if (as->parms[5].items) {
2002 if (!IsNumeric(as->parms[5].items->data)) {
2003 fprintf(STDERR, "vos: Given RO volume ID %s should be numeric.\n",
2004 as->parms[5].items->data);
2008 code = util_GetUInt32(as->parms[5].items->data, &rovolid);
2010 fprintf(STDERR, "vos: bad integer specified for volume ID.\n");
2020 UV_CreateVolume3(tserver, pnum, as->parms[2].items->data, quota, 0,
2021 0, 0, 0, &volid, arovolid, &bkvolid);
2023 PrintDiagnostics("create", code);
2026 MapPartIdIntoName(pnum, part);
2027 fprintf(STDOUT, "Volume %lu created on partition %s of %s\n",
2028 (unsigned long)volid, part, as->parms[0].items->data);
2035 DeleteAll(struct nvldbentry *entry)
2038 afs_int32 error, code, curserver, curpart;
2041 MapHostToNetwork(entry);
2043 for (i = 0; i < entry->nServers; i++) {
2044 curserver = entry->serverNumber[i];
2045 curpart = entry->serverPartition[i];
2046 if (entry->serverFlags[i] & ITSROVOL) {
2047 volid = entry->volumeId[ROVOL];
2049 volid = entry->volumeId[RWVOL];
2051 code = UV_DeleteVolume(curserver, curpart, volid);
2060 DeleteVolume(struct cmd_syndesc *as, void *arock)
2062 afs_int32 err, code = 0;
2063 afs_uint32 server = 0;
2064 afs_int32 partition = -1;
2069 if (as->parms[0].items) {
2070 server = GetServer(as->parms[0].items->data);
2072 fprintf(STDERR, "vos: server '%s' not found in host table\n",
2073 as->parms[0].items->data);
2078 if (as->parms[1].items) {
2079 partition = volutil_GetPartitionID(as->parms[1].items->data);
2080 if (partition < 0) {
2081 fprintf(STDERR, "vos: could not interpret partition name '%s'\n",
2082 as->parms[1].items->data);
2086 /* Check for validity of the partition */
2087 if (!IsPartValid(partition, server, &code)) {
2089 PrintError("", code);
2092 "vos : partition %s does not exist on the server\n",
2093 as->parms[1].items->data);
2099 volid = vsu_GetVolumeID(as->parms[2].items->data, cstruct, &err);
2101 fprintf(STDERR, "Can't find volume name '%s' in VLDB\n",
2102 as->parms[2].items->data);
2104 PrintError("", err);
2108 /* If the server or partition option are not complete, try to fill
2109 * them in from the VLDB entry.
2111 if ((partition == -1) || !server) {
2112 struct nvldbentry entry;
2114 code = VLDB_GetEntryByID(volid, -1, &entry);
2117 "Could not fetch the entry for volume %lu from VLDB\n",
2118 (unsigned long)volid);
2119 PrintError("", code);
2123 if (((volid == entry.volumeId[RWVOL]) && (entry.flags & RW_EXISTS))
2124 || ((volid == entry.volumeId[BACKVOL])
2125 && (entry.flags & BACK_EXISTS))) {
2126 idx = Lp_GetRwIndex(&entry);
2127 if ((idx == -1) || (server && (server != entry.serverNumber[idx]))
2128 || ((partition != -1)
2129 && (partition != entry.serverPartition[idx]))) {
2130 fprintf(STDERR, "VLDB: Volume '%s' no match\n",
2131 as->parms[2].items->data);
2134 } else if ((volid == entry.volumeId[ROVOL])
2135 && (entry.flags & RO_EXISTS)) {
2136 for (idx = -1, j = 0; j < entry.nServers; j++) {
2137 if (entry.serverFlags[j] != ITSROVOL)
2140 if (((server == 0) || (server == entry.serverNumber[j]))
2141 && ((partition == -1)
2142 || (partition == entry.serverPartition[j]))) {
2145 "VLDB: Volume '%s' matches more than one RO\n",
2146 as->parms[2].items->data);
2153 fprintf(STDERR, "VLDB: Volume '%s' no match\n",
2154 as->parms[2].items->data);
2158 fprintf(STDERR, "VLDB: Volume '%s' no match\n",
2159 as->parms[2].items->data);
2163 server = htonl(entry.serverNumber[idx]);
2164 partition = entry.serverPartition[idx];
2168 code = UV_DeleteVolume(server, partition, volid);
2170 PrintDiagnostics("remove", code);
2174 MapPartIdIntoName(partition, pname);
2175 fprintf(STDOUT, "Volume %lu on partition %s server %s deleted\n",
2176 (unsigned long)volid, pname, hostutil_GetNameByINet(server));
2180 #define TESTM 0 /* set for move space tests, clear for production */
2182 MoveVolume(struct cmd_syndesc *as, void *arock)
2186 afs_uint32 fromserver, toserver;
2187 afs_int32 frompart, topart;
2188 afs_int32 flags, code, err;
2189 char fromPartName[10], toPartName[10];
2191 struct diskPartition64 partition; /* for space check */
2194 volid = vsu_GetVolumeID(as->parms[0].items->data, cstruct, &err);
2197 PrintError("", err);
2199 fprintf(STDERR, "vos: can't find volume ID or name '%s'\n",
2200 as->parms[0].items->data);
2203 fromserver = GetServer(as->parms[1].items->data);
2204 if (fromserver == 0) {
2205 fprintf(STDERR, "vos: server '%s' not found in host table\n",
2206 as->parms[1].items->data);
2209 toserver = GetServer(as->parms[3].items->data);
2210 if (toserver == 0) {
2211 fprintf(STDERR, "vos: server '%s' not found in host table\n",
2212 as->parms[3].items->data);
2215 frompart = volutil_GetPartitionID(as->parms[2].items->data);
2217 fprintf(STDERR, "vos: could not interpret partition name '%s'\n",
2218 as->parms[2].items->data);
2221 if (!IsPartValid(frompart, fromserver, &code)) { /*check for validity of the partition */
2223 PrintError("", code);
2226 "vos : partition %s does not exist on the server\n",
2227 as->parms[2].items->data);
2230 topart = volutil_GetPartitionID(as->parms[4].items->data);
2232 fprintf(STDERR, "vos: could not interpret partition name '%s'\n",
2233 as->parms[4].items->data);
2236 if (!IsPartValid(topart, toserver, &code)) { /*check for validity of the partition */
2238 PrintError("", code);
2241 "vos : partition %s does not exist on the server\n",
2242 as->parms[4].items->data);
2247 if (as->parms[5].items) flags |= RV_NOCLONE;
2250 * check source partition for space to clone volume
2253 MapPartIdIntoName(topart, toPartName);
2254 MapPartIdIntoName(frompart, fromPartName);
2257 * check target partition for space to move volume
2260 code = UV_PartitionInfo64(toserver, toPartName, &partition);
2262 fprintf(STDERR, "vos: cannot access partition %s\n", toPartName);
2266 fprintf(STDOUT, "target partition %s free space %" AFS_INT64_FMT "\n", toPartName,
2269 p = (volintInfo *) 0;
2270 code = UV_ListOneVolume(fromserver, frompart, volid, &p);
2272 fprintf(STDERR, "vos:cannot access volume %lu\n",
2273 (unsigned long)volid);
2277 fprintf(STDOUT, "volume %lu size %d\n", (unsigned long)volid,
2279 if (partition.free <= p->size) {
2281 "vos: no space on target partition %s to move volume %lu\n",
2282 toPartName, (unsigned long)volid);
2289 fprintf(STDOUT, "size test - don't do move\n");
2293 /* successful move still not guaranteed but shoot for it */
2296 UV_MoveVolume2(volid, fromserver, frompart, toserver, topart, flags);
2298 PrintDiagnostics("move", code);
2301 MapPartIdIntoName(topart, toPartName);
2302 MapPartIdIntoName(frompart, fromPartName);
2303 fprintf(STDOUT, "Volume %lu moved from %s %s to %s %s \n",
2304 (unsigned long)volid, as->parms[1].items->data, fromPartName,
2305 as->parms[3].items->data, toPartName);
2311 CopyVolume(struct cmd_syndesc *as, void *arock)
2314 afs_uint32 fromserver, toserver;
2315 afs_int32 frompart, topart, code, err, flags;
2316 char fromPartName[10], toPartName[10], *tovolume;
2317 struct nvldbentry entry;
2318 struct diskPartition64 partition; /* for space check */
2321 volid = vsu_GetVolumeID(as->parms[0].items->data, cstruct, &err);
2324 PrintError("", err);
2326 fprintf(STDERR, "vos: can't find volume ID or name '%s'\n",
2327 as->parms[0].items->data);
2330 fromserver = GetServer(as->parms[1].items->data);
2331 if (fromserver == 0) {
2332 fprintf(STDERR, "vos: server '%s' not found in host table\n",
2333 as->parms[1].items->data);
2337 toserver = GetServer(as->parms[4].items->data);
2338 if (toserver == 0) {
2339 fprintf(STDERR, "vos: server '%s' not found in host table\n",
2340 as->parms[4].items->data);
2344 tovolume = as->parms[3].items->data;
2345 if (!ISNAMEVALID(tovolume)) {
2347 "vos: the name of the root volume %s exceeds the size limit of %d\n",
2348 tovolume, VOLSER_OLDMAXVOLNAME - 10);
2351 if (!VolNameOK(tovolume)) {
2353 "Illegal volume name %s, should not end in .readonly or .backup\n",
2357 if (IsNumeric(tovolume)) {
2358 fprintf(STDERR, "Illegal volume name %s, should not be a number\n",
2362 code = VLDB_GetEntryByName(tovolume, &entry);
2364 fprintf(STDERR, "Volume %s already exists\n", tovolume);
2365 PrintDiagnostics("copy", code);
2369 frompart = volutil_GetPartitionID(as->parms[2].items->data);
2371 fprintf(STDERR, "vos: could not interpret partition name '%s'\n",
2372 as->parms[2].items->data);
2375 if (!IsPartValid(frompart, fromserver, &code)) { /*check for validity of the partition */
2377 PrintError("", code);
2380 "vos : partition %s does not exist on the server\n",
2381 as->parms[2].items->data);
2385 topart = volutil_GetPartitionID(as->parms[5].items->data);
2387 fprintf(STDERR, "vos: could not interpret partition name '%s'\n",
2388 as->parms[5].items->data);
2391 if (!IsPartValid(topart, toserver, &code)) { /*check for validity of the partition */
2393 PrintError("", code);
2396 "vos : partition %s does not exist on the server\n",
2397 as->parms[5].items->data);
2402 if (as->parms[6].items) flags |= RV_OFFLINE;
2403 if (as->parms[7].items) flags |= RV_RDONLY;
2404 if (as->parms[8].items) flags |= RV_NOCLONE;
2406 MapPartIdIntoName(topart, toPartName);
2407 MapPartIdIntoName(frompart, fromPartName);
2410 * check target partition for space to move volume
2413 code = UV_PartitionInfo64(toserver, toPartName, &partition);
2415 fprintf(STDERR, "vos: cannot access partition %s\n", toPartName);
2419 fprintf(STDOUT, "target partition %s free space %" AFS_INT64_FMT "\n", toPartName,
2422 p = (volintInfo *) 0;
2423 code = UV_ListOneVolume(fromserver, frompart, volid, &p);
2425 fprintf(STDERR, "vos:cannot access volume %lu\n",
2426 (unsigned long)volid);
2430 if (partition.free <= p->size) {
2432 "vos: no space on target partition %s to copy volume %lu\n",
2433 toPartName, (unsigned long)volid);
2439 /* successful copy still not guaranteed but shoot for it */
2442 UV_CopyVolume2(volid, fromserver, frompart, tovolume, toserver,
2445 PrintDiagnostics("copy", code);
2448 MapPartIdIntoName(topart, toPartName);
2449 MapPartIdIntoName(frompart, fromPartName);
2450 fprintf(STDOUT, "Volume %lu copied from %s %s to %s on %s %s \n",
2451 (unsigned long)volid, as->parms[1].items->data, fromPartName,
2452 tovolume, as->parms[4].items->data, toPartName);
2459 ShadowVolume(struct cmd_syndesc *as, void *arock)
2461 afs_uint32 volid, tovolid;
2462 afs_uint32 fromserver, toserver;
2463 afs_int32 frompart, topart;
2464 afs_int32 code, err, flags;
2465 char fromPartName[10], toPartName[10], toVolName[32], *tovolume;
2466 struct diskPartition64 partition; /* for space check */
2469 p = (volintInfo *) 0;
2470 q = (volintInfo *) 0;
2472 volid = vsu_GetVolumeID(as->parms[0].items->data, cstruct, &err);
2475 PrintError("", err);
2477 fprintf(STDERR, "vos: can't find volume ID or name '%s'\n",
2478 as->parms[0].items->data);
2481 fromserver = GetServer(as->parms[1].items->data);
2482 if (fromserver == 0) {
2483 fprintf(STDERR, "vos: server '%s' not found in host table\n",
2484 as->parms[1].items->data);
2488 toserver = GetServer(as->parms[3].items->data);
2489 if (toserver == 0) {
2490 fprintf(STDERR, "vos: server '%s' not found in host table\n",
2491 as->parms[3].items->data);
2495 frompart = volutil_GetPartitionID(as->parms[2].items->data);
2497 fprintf(STDERR, "vos: could not interpret partition name '%s'\n",
2498 as->parms[2].items->data);
2501 if (!IsPartValid(frompart, fromserver, &code)) { /*check for validity of the partition */
2503 PrintError("", code);
2506 "vos : partition %s does not exist on the server\n",
2507 as->parms[2].items->data);
2511 topart = volutil_GetPartitionID(as->parms[4].items->data);
2513 fprintf(STDERR, "vos: could not interpret partition name '%s'\n",
2514 as->parms[4].items->data);
2517 if (!IsPartValid(topart, toserver, &code)) { /*check for validity of the partition */
2519 PrintError("", code);
2522 "vos : partition %s does not exist on the server\n",
2523 as->parms[4].items->data);
2527 if (as->parms[5].items) {
2528 tovolume = as->parms[5].items->data;
2529 if (!ISNAMEVALID(tovolume)) {
2531 "vos: the name of the root volume %s exceeds the size limit of %d\n",
2532 tovolume, VOLSER_OLDMAXVOLNAME - 10);
2535 if (!VolNameOK(tovolume)) {
2537 "Illegal volume name %s, should not end in .readonly or .backup\n",
2541 if (IsNumeric(tovolume)) {
2543 "Illegal volume name %s, should not be a number\n",
2548 /* use actual name of source volume */
2549 code = UV_ListOneVolume(fromserver, frompart, volid, &p);
2551 fprintf(STDERR, "vos:cannot access volume %lu\n",
2552 (unsigned long)volid);
2555 strcpy(toVolName, p->name);
2556 tovolume = toVolName;
2557 /* save p for size checks later */
2560 if (as->parms[6].items) {
2561 tovolid = vsu_GetVolumeID(as->parms[6].items->data, cstruct, &err);
2564 PrintError("", err);
2566 fprintf(STDERR, "vos: can't find volume ID or name '%s'\n",
2567 as->parms[6].items->data);
2573 tovolid = vsu_GetVolumeID(tovolume, cstruct, &err);
2576 PrintError("", err);
2578 fprintf(STDERR, "vos: can't find volume ID or name '%s'\n",
2587 if (as->parms[7].items) flags |= RV_OFFLINE;
2588 if (as->parms[8].items) flags |= RV_RDONLY;
2589 if (as->parms[9].items) flags |= RV_NOCLONE;
2590 if (as->parms[10].items) flags |= RV_CPINCR;
2592 MapPartIdIntoName(topart, toPartName);
2593 MapPartIdIntoName(frompart, fromPartName);
2596 * check target partition for space to move volume
2599 code = UV_PartitionInfo64(toserver, toPartName, &partition);
2601 fprintf(STDERR, "vos: cannot access partition %s\n", toPartName);
2605 fprintf(STDOUT, "target partition %s free space %" AFS_INT64_FMT "\n", toPartName,
2608 /* Don't do this again if we did it above */
2610 code = UV_ListOneVolume(fromserver, frompart, volid, &p);
2612 fprintf(STDERR, "vos:cannot access volume %lu\n",
2613 (unsigned long)volid);
2618 /* OK if this fails */
2619 code = UV_ListOneVolume(toserver, topart, tovolid, &q);
2621 /* Treat existing volume size as "free" */
2623 p->size = (q->size < p->size) ? p->size - q->size : 0;
2625 if (partition.free <= p->size) {
2627 "vos: no space on target partition %s to copy volume %lu\n",
2628 toPartName, (unsigned long)volid);
2636 /* successful copy still not guaranteed but shoot for it */
2639 UV_CopyVolume2(volid, fromserver, frompart, tovolume, toserver,
2640 topart, tovolid, flags);
2642 PrintDiagnostics("shadow", code);
2645 MapPartIdIntoName(topart, toPartName);
2646 MapPartIdIntoName(frompart, fromPartName);
2647 fprintf(STDOUT, "Volume %lu shadowed from %s %s to %s %s \n",
2648 (unsigned long)volid, as->parms[1].items->data, fromPartName,
2649 as->parms[3].items->data, toPartName);
2656 CloneVolume(struct cmd_syndesc *as, void *arock)
2658 afs_uint32 volid, cloneid;
2660 afs_int32 part, voltype;
2661 char partName[10], *volname;
2662 afs_int32 code, err, flags;
2663 struct nvldbentry entry;
2665 volid = vsu_GetVolumeID(as->parms[0].items->data, cstruct, &err);
2668 PrintError("", err);
2670 fprintf(STDERR, "vos: can't find volume ID or name '%s'\n",
2671 as->parms[0].items->data);
2675 if (as->parms[1].items || as->parms[2].items) {
2676 if (!as->parms[1].items || !as->parms[2].items) {
2678 "Must specify both -server and -partition options\n");
2681 server = GetServer(as->parms[1].items->data);
2683 fprintf(STDERR, "vos: server '%s' not found in host table\n",
2684 as->parms[1].items->data);
2687 part = volutil_GetPartitionID(as->parms[2].items->data);
2689 fprintf(STDERR, "vos: could not interpret partition name '%s'\n",
2690 as->parms[2].items->data);
2693 if (!IsPartValid(part, server, &code)) { /*check for validity of the partition */
2695 PrintError("", code);
2698 "vos : partition %s does not exist on the server\n",
2699 as->parms[2].items->data);
2703 code = GetVolumeInfo(volid, &server, &part, &voltype, &entry);
2709 if (as->parms[3].items) {
2710 volname = as->parms[3].items->data;
2711 if (strlen(volname) > VOLSER_OLDMAXVOLNAME - 1) {
2713 "vos: the name of the root volume %s exceeds the size limit of %d\n",
2714 volname, VOLSER_OLDMAXVOLNAME - 1);
2719 * In order that you be able to make clones of RO or BK, this
2720 * check must be omitted.
2722 if (!VolNameOK(volname)) {
2724 "Illegal volume name %s, should not end in .readonly or .backup\n",
2729 if (IsNumeric(volname)) {
2731 "Illegal volume name %s, should not be a number\n",
2738 if (as->parms[4].items) {
2739 cloneid = vsu_GetVolumeID(as->parms[4].items->data, cstruct, &err);
2742 PrintError("", err);
2744 fprintf(STDERR, "vos: can't find volume ID or name '%s'\n",
2745 as->parms[4].items->data);
2751 if (as->parms[5].items) flags |= RV_OFFLINE;
2752 if (as->parms[6].items) flags |= RV_RDONLY;
2756 UV_CloneVolume(server, part, volid, cloneid, volname, flags);
2759 PrintDiagnostics("clone", code);
2762 MapPartIdIntoName(part, partName);
2763 fprintf(STDOUT, "Created clone for volume %s\n",
2764 as->parms[0].items->data);
2771 BackupVolume(struct cmd_syndesc *as, void *arock)
2775 afs_int32 apart, vtype, code, err;
2776 struct nvldbentry entry;
2779 afs_uint32 buserver;
2780 afs_int32 bupart, butype;
2781 struct nvldbentry buentry;
2783 avolid = vsu_GetVolumeID(as->parms[0].items->data, cstruct, &err);
2786 PrintError("", err);
2788 fprintf(STDERR, "vos: can't find volume ID or name '%s'\n",
2789 as->parms[0].items->data);
2792 code = GetVolumeInfo(avolid, &aserver, &apart, &vtype, &entry);
2796 /* verify this is a readwrite volume */
2798 if (vtype != RWVOL) {
2799 fprintf(STDERR, "%s not RW volume\n", as->parms[0].items->data);
2803 /* is there a backup volume already? */
2805 if (entry.flags & BACK_EXISTS) {
2806 /* yep, where is it? */
2808 buvolid = entry.volumeId[BACKVOL];
2809 code = GetVolumeInfo(buvolid, &buserver, &bupart, &butype, &buentry);
2814 code = VLDB_IsSameAddrs(buserver, aserver, &err);
2817 "Failed to get info about server's %d address(es) from vlserver; aborting call!\n",
2823 "FATAL ERROR: backup volume %lu exists on server %lu\n",
2824 (unsigned long)buvolid, (unsigned long)buserver);
2829 /* nope, carry on */
2831 code = UV_BackupVolume(aserver, apart, avolid);
2834 PrintDiagnostics("backup", code);
2837 fprintf(STDOUT, "Created backup volume for %s \n",
2838 as->parms[0].items->data);
2843 ReleaseVolume(struct cmd_syndesc *as, void *arock)
2846 struct nvldbentry entry;
2849 afs_int32 apart, vtype, code, err;
2852 if (as->parms[1].items)
2854 avolid = vsu_GetVolumeID(as->parms[0].items->data, cstruct, &err);
2857 PrintError("", err);
2859 fprintf(STDERR, "vos: can't find volume '%s'\n",
2860 as->parms[0].items->data);
2863 code = GetVolumeInfo(avolid, &aserver, &apart, &vtype, &entry);
2867 if (vtype != RWVOL) {
2868 fprintf(STDERR, "%s not a RW volume\n", as->parms[0].items->data);
2872 if (!ISNAMEVALID(entry.name)) {
2874 "Volume name %s is too long, rename before releasing\n",
2879 code = UV_ReleaseVolume(avolid, aserver, apart, force);
2881 PrintDiagnostics("release", code);
2884 fprintf(STDOUT, "Released volume %s successfully\n",
2885 as->parms[0].items->data);
2890 DumpVolumeCmd(struct cmd_syndesc *as, void *arock)
2894 afs_int32 apart, voltype, fromdate = 0, code, err, i, flags;
2895 char filename[MAXPATHLEN];
2896 struct nvldbentry entry;
2898 rx_SetRxDeadTime(60 * 10);
2899 for (i = 0; i < MAXSERVERS; i++) {
2900 struct rx_connection *rxConn = ubik_GetRPCConn(cstruct, i);
2903 rx_SetConnDeadTime(rxConn, rx_connDeadTime);
2904 if (rxConn->service)
2905 rxConn->service->connDeadTime = rx_connDeadTime;
2908 avolid = vsu_GetVolumeID(as->parms[0].items->data, cstruct, &err);
2911 PrintError("", err);
2913 fprintf(STDERR, "vos: can't find volume '%s'\n",
2914 as->parms[0].items->data);
2918 if (as->parms[3].items || as->parms[4].items) {
2919 if (!as->parms[3].items || !as->parms[4].items) {
2921 "Must specify both -server and -partition options\n");
2924 aserver = GetServer(as->parms[3].items->data);
2926 fprintf(STDERR, "Invalid server name\n");
2929 apart = volutil_GetPartitionID(as->parms[4].items->data);
2931 fprintf(STDERR, "Invalid partition name\n");
2935 code = GetVolumeInfo(avolid, &aserver, &apart, &voltype, &entry);
2940 if (as->parms[1].items && strcmp(as->parms[1].items->data, "0")) {
2941 code = ktime_DateToInt32(as->parms[1].items->data, &fromdate);
2943 fprintf(STDERR, "vos: failed to parse date '%s' (error=%d))\n",
2944 as->parms[1].items->data, code);
2948 if (as->parms[2].items) {
2949 strcpy(filename, as->parms[2].items->data);
2951 strcpy(filename, "");
2954 flags = as->parms[6].items ? VOLDUMPV2_OMITDIRS : 0;
2956 if (as->parms[5].items) {
2958 UV_DumpClonedVolume(avolid, aserver, apart, fromdate,
2959 DumpFunction, filename, flags);
2962 UV_DumpVolume(avolid, aserver, apart, fromdate, DumpFunction,
2965 if ((code == RXGEN_OPCODE) && (as->parms[6].items)) {
2966 flags &= ~VOLDUMPV2_OMITDIRS;
2970 PrintDiagnostics("dump", code);
2973 if (strcmp(filename, ""))
2974 fprintf(STDERR, "Dumped volume %s in file %s\n",
2975 as->parms[0].items->data, filename);
2977 fprintf(STDERR, "Dumped volume %s in stdout \n",
2978 as->parms[0].items->data);
2992 RestoreVolumeCmd(struct cmd_syndesc *as, void *arock)
2994 afs_uint32 avolid, aparentid;
2996 afs_int32 apart, code, vcode, err;
2997 afs_int32 aoverwrite = ASK;
2998 afs_int32 acreation = 0, alastupdate = 0;
2999 int restoreflags = 0;
3000 int readonly = 0, offline = 0, voltype = RWVOL;
3002 char afilename[MAXPATHLEN], avolname[VOLSER_MAXVOLNAME + 1], apartName[10];
3003 char volname[VOLSER_MAXVOLNAME + 1];
3004 struct nvldbentry entry;
3009 if (as->parms[4].items) {
3010 avolid = vsu_GetVolumeID(as->parms[4].items->data, cstruct, &err);
3013 PrintError("", err);
3015 fprintf(STDERR, "vos: can't find volume '%s'\n",
3016 as->parms[4].items->data);
3022 if (as->parms[5].items) {
3023 if ((strcmp(as->parms[5].items->data, "a") == 0)
3024 || (strcmp(as->parms[5].items->data, "abort") == 0)) {
3026 } else if ((strcmp(as->parms[5].items->data, "f") == 0)
3027 || (strcmp(as->parms[5].items->data, "full") == 0)) {
3029 } else if ((strcmp(as->parms[5].items->data, "i") == 0)
3030 || (strcmp(as->parms[5].items->data, "inc") == 0)
3031 || (strcmp(as->parms[5].items->data, "increment") == 0)
3032 || (strcmp(as->parms[5].items->data, "incremental") == 0)) {
3035 fprintf(STDERR, "vos: %s is not a valid argument to -overwrite\n",
3036 as->parms[5].items->data);
3040 if (as->parms[6].items)
3042 if (as->parms[7].items) {
3047 if (as->parms[8].items) {
3048 if ((strcmp(as->parms[8].items->data, "d") == 0)
3049 || (strcmp(as->parms[8].items->data, "dump") == 0)) {
3050 acreation = TS_DUMP;
3051 } else if ((strcmp(as->parms[8].items->data, "k") == 0)
3052 || (strcmp(as->parms[8].items->data, "keep") == 0)) {
3053 acreation = TS_KEEP;
3054 } else if ((strcmp(as->parms[8].items->data, "n") == 0)
3055 || (strcmp(as->parms[8].items->data, "new") == 0)) {
3058 fprintf(STDERR, "vos: %s is not a valid argument to -creation\n",
3059 as->parms[8].items->data);
3064 if (as->parms[9].items) {
3065 if ((strcmp(as->parms[9].items->data, "d") == 0)
3066 || (strcmp(as->parms[9].items->data, "dump") == 0)) {
3067 alastupdate = TS_DUMP;
3068 } else if ((strcmp(as->parms[9].items->data, "k") == 0)
3069 || (strcmp(as->parms[9].items->data, "keep") == 0)) {
3070 alastupdate = TS_KEEP;
3071 } else if ((strcmp(as->parms[9].items->data, "n") == 0)
3072 || (strcmp(as->parms[9].items->data, "new") == 0)) {
3073 alastupdate = TS_NEW;
3075 fprintf(STDERR, "vos: %s is not a valid argument to -lastupdate\n",
3076 as->parms[9].items->data);
3081 aserver = GetServer(as->parms[0].items->data);
3083 fprintf(STDERR, "vos: server '%s' not found in host table\n",
3084 as->parms[0].items->data);
3087 apart = volutil_GetPartitionID(as->parms[1].items->data);
3089 fprintf(STDERR, "vos: could not interpret partition name '%s'\n",
3090 as->parms[1].items->data);
3093 if (!IsPartValid(apart, aserver, &code)) { /*check for validity of the partition */
3095 PrintError("", code);
3098 "vos : partition %s does not exist on the server\n",
3099 as->parms[1].items->data);
3102 strcpy(avolname, as->parms[2].items->data);
3103 if (!ISNAMEVALID(avolname)) {
3105 "vos: the name of the volume %s exceeds the size limit\n",
3109 if (!VolNameOK(avolname)) {
3111 "Illegal volume name %s, should not end in .readonly or .backup\n",
3115 if (as->parms[3].items) {
3116 strcpy(afilename, as->parms[3].items->data);
3117 if (!FileExists(afilename)) {
3118 fprintf(STDERR, "Can't access file %s\n", afilename);
3122 strcpy(afilename, "");
3125 /* Check if volume exists or not */
3127 vsu_ExtractName(volname, avolname);
3128 vcode = VLDB_GetEntryByName(volname, &entry);
3129 if (vcode) { /* no volume - do a full restore */
3130 restoreflags = RV_FULLRST;
3131 if ((aoverwrite == INC) || (aoverwrite == ABORT))
3133 "Volume does not exist; Will perform a full restore\n");
3136 else if ((!readonly && Lp_GetRwIndex(&entry) == -1) /* RW volume does not exist - do a full */
3137 ||(readonly && !Lp_ROMatch(0, 0, &entry))) { /* RO volume does not exist - do a full */
3138 restoreflags = RV_FULLRST;
3139 if ((aoverwrite == INC) || (aoverwrite == ABORT))
3141 "%s Volume does not exist; Will perform a full restore\n",
3142 readonly ? "RO" : "RW");
3145 avolid = entry.volumeId[voltype];
3146 } else if (entry.volumeId[voltype] != 0
3147 && entry.volumeId[voltype] != avolid) {
3148 avolid = entry.volumeId[voltype];
3150 aparentid = entry.volumeId[RWVOL];
3153 else { /* volume exists - do we do a full incremental or abort */
3155 afs_int32 Opart, Otype, vol_elsewhere = 0;
3156 struct nvldbentry Oentry;
3160 avolid = entry.volumeId[voltype];
3161 } else if (entry.volumeId[voltype] != 0
3162 && entry.volumeId[voltype] != avolid) {
3163 avolid = entry.volumeId[voltype];
3165 aparentid = entry.volumeId[RWVOL];
3167 /* A file name was specified - check if volume is on another partition */
3168 vcode = GetVolumeInfo(avolid, &Oserver, &Opart, &Otype, &Oentry);
3172 vcode = VLDB_IsSameAddrs(Oserver, aserver, &err);
3175 "Failed to get info about server's %d address(es) from vlserver (err=%d); aborting call!\n",
3179 if (!vcode || (Opart != apart))
3182 if (aoverwrite == ASK) {
3183 if (strcmp(afilename, "") == 0) { /* The file is from standard in */
3185 "Volume exists and no -overwrite option specified; Aborting restore command\n");
3189 /* Ask what to do */
3190 if (vol_elsewhere) {
3192 "The volume %s %u already exists on a different server/part\n",
3193 volname, entry.volumeId[voltype]);
3195 "Do you want to do a full restore or abort? [fa](a): ");
3198 "The volume %s %u already exists in the VLDB\n",
3199 volname, entry.volumeId[voltype]);
3201 "Do you want to do a full/incremental restore or abort? [fia](a): ");
3204 while (!(dc == EOF || dc == '\n'))
3205 dc = getchar(); /* goto end of line */
3206 if ((c == 'f') || (c == 'F'))
3208 else if ((c == 'i') || (c == 'I'))
3214 if (aoverwrite == ABORT) {
3215 fprintf(STDERR, "Volume exists; Aborting restore command\n");
3217 } else if (aoverwrite == FULL) {
3218 restoreflags = RV_FULLRST;
3220 "Volume exists; Will delete and perform full restore\n");
3221 } else if (aoverwrite == INC) {
3223 if (vol_elsewhere) {
3225 "%s volume %lu already exists on a different server/part; not allowed\n",
3226 readonly ? "RO" : "RW", (unsigned long)avolid);
3232 restoreflags |= RV_OFFLINE;
3234 restoreflags |= RV_RDONLY;
3236 switch (acreation) {
3238 restoreflags |= RV_CRDUMP;
3241 restoreflags |= RV_CRKEEP;
3244 restoreflags |= RV_CRNEW;
3247 if (aoverwrite == FULL)
3248 restoreflags |= RV_CRNEW;
3250 restoreflags |= RV_CRKEEP;
3253 switch (alastupdate) {
3255 restoreflags |= RV_LUDUMP;
3258 restoreflags |= RV_LUKEEP;
3261 restoreflags |= RV_LUNEW;
3264 restoreflags |= RV_LUDUMP;
3266 if (as->parms[10].items) {
3267 restoreflags |= RV_NODEL;
3272 UV_RestoreVolume2(aserver, apart, avolid, aparentid,
3273 avolname, restoreflags, WriteData, afilename);
3275 PrintDiagnostics("restore", code);
3278 MapPartIdIntoName(apart, apartName);
3281 * patch typo here - originally "parms[1]", should be "parms[0]"
3284 fprintf(STDOUT, "Restored volume %s on %s %s\n", avolname,
3285 as->parms[0].items->data, apartName);
3290 LockReleaseCmd(struct cmd_syndesc *as, void *arock)
3293 afs_int32 code, err;
3295 avolid = vsu_GetVolumeID(as->parms[0].items->data, cstruct, &err);
3298 PrintError("", err);
3300 fprintf(STDERR, "vos: can't find volume '%s'\n",
3301 as->parms[0].items->data);
3305 code = UV_LockRelease(avolid);
3307 PrintDiagnostics("unlock", code);
3310 fprintf(STDOUT, "Released lock on vldb entry for volume %s\n",
3311 as->parms[0].items->data);
3316 AddSite(struct cmd_syndesc *as, void *arock)
3320 afs_int32 apart, code, err, arovolid, valid = 0;
3321 char apartName[10], avolname[VOLSER_MAXVOLNAME + 1];
3323 vsu_ExtractName(avolname, as->parms[2].items->data);;
3324 avolid = vsu_GetVolumeID(avolname, cstruct, &err);
3327 PrintError("", err);
3329 fprintf(STDERR, "vos: can't find volume '%s'\n",
3330 as->parms[2].items->data);
3334 if (as->parms[3].items) {
3335 vsu_ExtractName(avolname, as->parms[3].items->data);
3336 arovolid = vsu_GetVolumeID(avolname, cstruct, &err);
3338 fprintf(STDERR, "vos: invalid ro volume id '%s'\n",
3339 as->parms[3].items->data);
3343 aserver = GetServer(as->parms[0].items->data);
3345 fprintf(STDERR, "vos: server '%s' not found in host table\n",
3346 as->parms[0].items->data);
3349 apart = volutil_GetPartitionID(as->parms[1].items->data);
3351 fprintf(STDERR, "vos: could not interpret partition name '%s'\n",
3352 as->parms[1].items->data);
3355 if (!IsPartValid(apart, aserver, &code)) { /*check for validity of the partition */
3357 PrintError("", code);
3360 "vos : partition %s does not exist on the server\n",
3361 as->parms[1].items->data);
3364 if (as->parms[4].items) {
3367 code = UV_AddSite2(aserver, apart, avolid, arovolid, valid);
3369 PrintDiagnostics("addsite", code);
3372 MapPartIdIntoName(apart, apartName);
3373 fprintf(STDOUT, "Added replication site %s %s for volume %s\n",
3374 as->parms[0].items->data, apartName, as->parms[2].items->data);
3379 RemoveSite(struct cmd_syndesc *as, void *arock)
3384 afs_int32 apart, code, err;
3385 char apartName[10], avolname[VOLSER_MAXVOLNAME + 1];
3387 vsu_ExtractName(avolname, as->parms[2].items->data);
3388 avolid = vsu_GetVolumeID(avolname, cstruct, &err);
3391 PrintError("", err);
3393 fprintf(STDERR, "vos: can't find volume '%s'\n",
3394 as->parms[2].items->data);
3397 aserver = GetServer(as->parms[0].items->data);
3399 fprintf(STDERR, "vos: server '%s' not found in host table\n",
3400 as->parms[0].items->data);
3403 apart = volutil_GetPartitionID(as->parms[1].items->data);
3405 fprintf(STDERR, "vos: could not interpret partition name '%s'\n",
3406 as->parms[1].items->data);
3410 *skip the partition validity check, since it is possible that the partition
3411 *has since been decomissioned.
3414 if (!IsPartValid(apart,aserver,&code)){
3415 if(code) PrintError("",code);
3416 else fprintf(STDERR,"vos : partition %s does not exist on the server\n",as->parms[1].items->data);
3420 code = UV_RemoveSite(aserver, apart, avolid);
3422 PrintDiagnostics("remsite", code);
3425 MapPartIdIntoName(apart, apartName);
3426 fprintf(STDOUT, "Removed replication site %s %s for volume %s\n",
3427 as->parms[0].items->data, apartName, as->parms[2].items->data);
3432 ChangeLocation(struct cmd_syndesc *as, void *arock)
3436 afs_int32 apart, code, err;
3439 avolid = vsu_GetVolumeID(as->parms[2].items->data, cstruct, &err);
3442 PrintError("", err);
3444 fprintf(STDERR, "vos: can't find volume '%s'\n",
3445 as->parms[2].items->data);
3448 aserver = GetServer(as->parms[0].items->data);
3450 fprintf(STDERR, "vos: server '%s' not found in host table\n",
3451 as->parms[0].items->data);
3454 apart = volutil_GetPartitionID(as->parms[1].items->data);
3456 fprintf(STDERR, "vos: could not interpret partition name '%s'\n",
3457 as->parms[1].items->data);
3460 if (!IsPartValid(apart, aserver, &code)) { /*check for validity of the partition */
3462 PrintError("", code);
3465 "vos : partition %s does not exist on the server\n",
3466 as->parms[1].items->data);
3469 code = UV_ChangeLocation(aserver, apart, avolid);
3471 PrintDiagnostics("addsite", code);
3474 MapPartIdIntoName(apart, apartName);
3475 fprintf(STDOUT, "Changed location to %s %s for volume %s\n",
3476 as->parms[0].items->data, apartName, as->parms[2].items->data);
3481 ListPartitions(struct cmd_syndesc *as, void *arock)
3485 struct partList dummyPartList;
3490 aserver = GetServer(as->parms[0].items->data);
3492 fprintf(STDERR, "vos: server '%s' not found in host table\n",
3493 as->parms[0].items->data);
3498 code = UV_ListPartitions(aserver, &dummyPartList, &cnt);
3500 PrintDiagnostics("listpart", code);
3504 fprintf(STDOUT, "The partitions on the server are:\n");
3505 for (i = 0; i < cnt; i++) {
3506 if (dummyPartList.partFlags[i] & PARTVALID) {
3507 memset(pname, 0, sizeof(pname));
3508 MapPartIdIntoName(dummyPartList.partId[i], pname);
3509 fprintf(STDOUT, " %10s ", pname);
3511 if ((i % 5) == 0 && (i != 0))
3512 fprintf(STDOUT, "\n");
3515 fprintf(STDOUT, "\n");
3516 fprintf(STDOUT, "Total: %d\n", total);
3522 CompareVolName(const void *p1, const void *p2)
3524 volintInfo *arg1, *arg2;
3526 arg1 = (volintInfo *) p1;
3527 arg2 = (volintInfo *) p2;
3528 return (strcmp(arg1->name, arg2->name));
3532 /*------------------------------------------------------------------------
3533 * PRIVATE XCompareVolName
3536 * Comparison routine for volume names coming from an extended
3540 * a_obj1P : Char ptr to first extended vol info object
3541 * a_obj1P : Char ptr to second extended vol info object
3544 * The value of strcmp() on the volume names within the passed
3545 * objects (i,e., -1, 0, or 1).
3548 * Passed to qsort() as the designated comparison routine.
3552 *------------------------------------------------------------------------*/
3555 XCompareVolName(const void *a_obj1P, const void *a_obj2P)
3556 { /*XCompareVolName */
3559 (((struct volintXInfo *)(a_obj1P))->name,
3560 ((struct volintXInfo *)(a_obj2P))->name));
3562 } /*XCompareVolName */
3565 CompareVolID(const void *p1, const void *p2)
3567 volintInfo *arg1, *arg2;
3569 arg1 = (volintInfo *) p1;
3570 arg2 = (volintInfo *) p2;
3571 if (arg1->volid == arg2->volid)
3573 if (arg1->volid > arg2->volid)
3580 /*------------------------------------------------------------------------
3581 * PRIVATE XCompareVolID
3584 * Comparison routine for volume IDs coming from an extended
3588 * a_obj1P : Char ptr to first extended vol info object
3589 * a_obj1P : Char ptr to second extended vol info object
3592 * The value of strcmp() on the volume names within the passed
3593 * objects (i,e., -1, 0, or 1).
3596 * Passed to qsort() as the designated comparison routine.
3600 *------------------------------------------------------------------------*/
3603 XCompareVolID(const void *a_obj1P, const void *a_obj2P)
3604 { /*XCompareVolID */
3606 afs_int32 id1, id2; /*Volume IDs we're comparing */
3608 id1 = ((struct volintXInfo *)(a_obj1P))->volid;
3609 id2 = ((struct volintXInfo *)(a_obj2P))->volid;
3617 } /*XCompareVolID */
3619 /*------------------------------------------------------------------------
3620 * PRIVATE ListVolumes
3623 * Routine used to list volumes, contacting the Volume Server
3624 * directly, bypassing the VLDB.
3627 * as : Ptr to parsed command line arguments.
3630 * 0 Successful operation
3633 * Nothing interesting.
3637 *------------------------------------------------------------------------*/
3640 ListVolumes(struct cmd_syndesc *as, void *arock)
3642 afs_int32 apart, int32list, fast;
3646 volintInfo *oldpntr = NULL;
3650 volintXInfo *xInfoP;
3651 volintXInfo *origxInfoP = NULL; /*Ptr to current/orig extended vol info */
3652 int wantExtendedInfo; /*Do we want extended vol info? */
3655 struct partList dummyPartList;
3663 if (as->parms[3].items)
3665 if (as->parms[4].items)
3669 if (as->parms[2].items)
3675 if (as->parms[5].items) {
3677 * We can't coexist with the fast flag.
3681 "vos: Can't use the -fast and -extended flags together\n");
3686 * We need to turn on ``long'' listings to get the full effect.
3688 wantExtendedInfo = 1;
3691 wantExtendedInfo = 0;
3692 if (as->parms[1].items) {
3693 apart = volutil_GetPartitionID(as->parms[1].items->data);
3695 fprintf(STDERR, "vos: could not interpret partition name '%s'\n",
3696 as->parms[1].items->data);
3699 dummyPartList.partId[0] = apart;
3700 dummyPartList.partFlags[0] = PARTVALID;
3703 aserver = GetServer(as->parms[0].items->data);
3705 fprintf(STDERR, "vos: server '%s' not found in host table\n",
3706 as->parms[0].items->data);
3711 if (!IsPartValid(apart, aserver, &code)) { /*check for validity of the partition */
3713 PrintError("", code);
3716 "vos : partition %s does not exist on the server\n",
3717 as->parms[1].items->data);
3721 code = UV_ListPartitions(aserver, &dummyPartList, &cnt);
3723 PrintDiagnostics("listvol", code);
3727 for (i = 0; i < cnt; i++) {
3728 if (dummyPartList.partFlags[i] & PARTVALID) {
3729 if (wantExtendedInfo)
3731 UV_XListVolumes(aserver, dummyPartList.partId[i], all,
3735 UV_ListVolumes(aserver, dummyPartList.partId[i], all,
3738 PrintDiagnostics("listvol", code);
3743 if (wantExtendedInfo) {
3744 origxInfoP = xInfoP;
3745 base = (char *)xInfoP;
3748 base = (char *)pntr;
3752 if (wantExtendedInfo)
3753 qsort(base, count, sizeof(volintXInfo), XCompareVolName);
3755 qsort(base, count, sizeof(volintInfo), CompareVolName);
3757 if (wantExtendedInfo)
3758 qsort(base, count, sizeof(volintXInfo), XCompareVolID);
3760 qsort(base, count, sizeof(volintInfo), CompareVolID);
3762 MapPartIdIntoName(dummyPartList.partId[i], pname);
3765 "Total number of volumes on server %s partition %s: %lu \n",
3766 as->parms[0].items->data, pname,
3767 (unsigned long)count);
3768 if (wantExtendedInfo) {
3769 if (as->parms[6].items)
3770 XDisplayVolumes2(aserver, dummyPartList.partId[i], origxInfoP,
3771 count, int32list, fast, quiet);
3773 XDisplayVolumes(aserver, dummyPartList.partId[i], origxInfoP,
3774 count, int32list, fast, quiet);
3777 xInfoP = (volintXInfo *) 0;
3779 if (as->parms[6].items)
3780 DisplayVolumes2(aserver, dummyPartList.partId[i], oldpntr,
3783 DisplayVolumes(aserver, dummyPartList.partId[i], oldpntr,
3784 count, int32list, fast, quiet);
3787 pntr = (volintInfo *) 0;
3795 SyncVldb(struct cmd_syndesc *as, void *arock)
3797 afs_int32 pnum = 0, code; /* part name */
3803 if (as->parms[0].items) {
3804 tserver = GetServer(as->parms[0].items->data);
3806 fprintf(STDERR, "vos: host '%s' not found in host table\n",
3807 as->parms[0].items->data);
3812 if (as->parms[1].items) {
3813 pnum = volutil_GetPartitionID(as->parms[1].items->data);
3815 fprintf(STDERR, "vos: could not interpret partition name '%s'\n",
3816 as->parms[1].items->data);
3819 if (!IsPartValid(pnum, tserver, &code)) { /*check for validity of the partition */
3821 PrintError("", code);
3824 "vos: partition %s does not exist on the server\n",
3825 as->parms[1].items->data);
3832 "The -partition option requires a -server option\n");
3837 if (as->parms[3].items) {
3838 flags |= 2; /* don't update */
3841 if (as->parms[2].items) {
3842 /* Synchronize an individual volume */
3843 volname = as->parms[2].items->data;
3844 code = UV_SyncVolume(tserver, pnum, volname, flags);
3848 "Without a -volume option, the -server option is required\n");
3851 code = UV_SyncVldb(tserver, pnum, flags, 0 /*unused */ );
3855 PrintDiagnostics("syncvldb", code);
3859 /* Print a summary of what we did */
3861 fprintf(STDOUT, "VLDB volume %s synchronized", volname);
3863 fprintf(STDOUT, "VLDB synchronized");
3865 fprintf(STDOUT, " with state of server %s", as->parms[0].items->data);
3868 MapPartIdIntoName(pnum, part);
3869 fprintf(STDOUT, " partition %s\n", part);
3871 fprintf(STDOUT, "\n");
3877 SyncServer(struct cmd_syndesc *as, void *arock)
3879 afs_int32 pnum, code; /* part name */
3884 tserver = GetServer(as->parms[0].items->data);
3886 fprintf(STDERR, "vos: host '%s' not found in host table\n",
3887 as->parms[0].items->data);
3890 if (as->parms[1].items) {
3891 pnum = volutil_GetPartitionID(as->parms[1].items->data);
3893 fprintf(STDERR, "vos: could not interpret partition name '%s'\n",
3894 as->parms[1].items->data);
3897 if (!IsPartValid(pnum, tserver, &code)) { /*check for validity of the partition */
3899 PrintError("", code);
3902 "vos : partition %s does not exist on the server\n",
3903 as->parms[1].items->data);
3911 if (as->parms[2].items) {
3912 flags |= 2; /* don't update */
3914 code = UV_SyncServer(tserver, pnum, flags, 0 /*unused */ );
3916 PrintDiagnostics("syncserv", code);
3920 MapPartIdIntoName(pnum, part);
3921 fprintf(STDOUT, "Server %s partition %s synchronized with VLDB\n",
3922 as->parms[0].items->data, part);
3924 fprintf(STDOUT, "Server %s synchronized with VLDB\n",
3925 as->parms[0].items->data);
3931 VolumeInfoCmd(char *name)
3933 struct nvldbentry entry;
3936 /* The vlserver will handle names with the .readonly
3937 * and .backup extension as well as volume ids.
3939 vcode = VLDB_GetEntryByName(name, &entry);
3941 PrintError("", vcode);
3944 MapHostToNetwork(&entry);
3945 EnumerateEntry(&entry);
3947 /* Defect #3027: grubby check to handle locked volume.
3948 * If VLOP_ALLOPERS is set, the entry is locked.
3949 * Leave this routine as is, but put in correct check.
3951 PrintLocked(entry.flags);
3957 VolumeZap(struct cmd_syndesc *as, void *arock)
3959 struct nvldbentry entry;
3960 afs_uint32 volid, zapbackupid = 0, backupid = 0;
3961 afs_int32 code, server, part, err;
3963 if (as->parms[3].items) {
3964 /* force flag is on, use the other version */
3965 return NukeVolume(as);
3968 if (as->parms[4].items) {
3972 volid = vsu_GetVolumeID(as->parms[2].items->data, cstruct, &err);
3975 PrintError("", err);
3977 fprintf(STDERR, "vos: can't find volume '%s'\n",
3978 as->parms[2].items->data);
3981 part = volutil_GetPartitionID(as->parms[1].items->data);
3983 fprintf(STDERR, "vos: could not interpret partition name '%s'\n",
3984 as->parms[1].items->data);
3987 server = GetServer(as->parms[0].items->data);
3989 fprintf(STDERR, "vos: host '%s' not found in host table\n",
3990 as->parms[0].items->data);
3993 if (!IsPartValid(part, server, &code)) { /*check for validity of the partition */
3995 PrintError("", code);
3998 "vos : partition %s does not exist on the server\n",
3999 as->parms[1].items->data);
4002 code = VLDB_GetEntryByID(volid, -1, &entry);
4004 if (volid == entry.volumeId[RWVOL])
4005 backupid = entry.volumeId[BACKVOL];
4007 "Warning: Entry for volume number %lu exists in VLDB (but we're zapping it anyway!)\n",
4008 (unsigned long)volid);
4011 volintInfo *pntr = (volintInfo *) 0;
4014 code = UV_ListOneVolume(server, part, volid, &pntr);
4016 if (volid == pntr->parentID)
4017 backupid = pntr->backupID;
4023 code = UV_VolumeZap(server, part, backupid);
4025 PrintDiagnostics("zap", code);
4028 fprintf(STDOUT, "Backup Volume %lu deleted\n",
4029 (unsigned long)backupid);
4032 code = UV_VolumeZap(server, part, volid);
4034 PrintDiagnostics("zap", code);
4037 fprintf(STDOUT, "Volume %lu deleted\n", (unsigned long)volid);
4043 VolserStatus(struct cmd_syndesc *as, void *arock)
4047 transDebugInfo *pntr, *oldpntr;
4053 server = GetServer(as->parms[0].items->data);
4055 fprintf(STDERR, "vos: host '%s' not found in host table\n",
4056 as->parms[0].items->data);
4059 code = UV_VolserStatus(server, &pntr, &count);
4061 PrintDiagnostics("status", code);
4066 fprintf(STDOUT, "No active transactions on %s\n",
4067 as->parms[0].items->data);
4069 fprintf(STDOUT, "Total transactions: %d\n", count);
4071 for (i = 0; i < count; i++) {
4072 /*print out the relevant info */
4073 fprintf(STDOUT, "--------------------------------------\n");
4074 t = pntr->creationTime;
4075 fprintf(STDOUT, "transaction: %lu created: %s",
4076 (unsigned long)pntr->tid, ctime(&t));
4078 fprintf(STDOUT, "lastActiveTime: %s", ctime(&t));
4079 if (pntr->returnCode) {
4080 fprintf(STDOUT, "returnCode: %lu\n",
4081 (unsigned long)pntr->returnCode);
4084 fprintf(STDOUT, "attachFlags: ");
4085 switch (pntr->iflags) {
4087 fprintf(STDOUT, "offline ");
4090 fprintf(STDOUT, "busy ");
4093 fprintf(STDOUT, "readonly ");
4096 fprintf(STDOUT, "create ");
4099 fprintf(STDOUT, "create volid ");
4102 fprintf(STDOUT, "\n");
4105 fprintf(STDOUT, "volumeStatus: ");
4106 switch (pntr->vflags) {
4107 case VTDeleteOnSalvage:
4108 fprintf(STDOUT, "deleteOnSalvage ");
4109 case VTOutOfService:
4110 fprintf(STDOUT, "outOfService ");
4112 fprintf(STDOUT, "deleted ");
4114 fprintf(STDOUT, "\n");
4117 fprintf(STDOUT, "transactionFlags: ");
4118 fprintf(STDOUT, "delete\n");
4120 MapPartIdIntoName(pntr->partition, pname);
4121 fprintf(STDOUT, "volume: %lu partition: %s procedure: %s\n",
4122 (unsigned long)pntr->volid, pname, pntr->lastProcName);
4123 if (pntr->callValid) {
4124 t = pntr->lastReceiveTime;
4125 fprintf(STDOUT, "packetRead: %lu lastReceiveTime: %s",
4126 (unsigned long)pntr->readNext, ctime(&t));
4127 t = pntr->lastSendTime;
4128 fprintf(STDOUT, "packetSend: %lu lastSendTime: %s",
4129 (unsigned long)pntr->transmitNext, ctime(&t));
4132 fprintf(STDOUT, "--------------------------------------\n");
4133 fprintf(STDOUT, "\n");
4141 RenameVolume(struct cmd_syndesc *as, void *arock)
4143 afs_int32 code1, code2, code;
4144 struct nvldbentry entry;
4146 code1 = VLDB_GetEntryByName(as->parms[0].items->data, &entry);
4148 fprintf(STDERR, "vos: Could not find entry for volume %s\n",
4149 as->parms[0].items->data);
4152 code2 = VLDB_GetEntryByName(as->parms[1].items->data, &entry);
4153 if ((!code1) && (!code2)) { /*the newname already exists */
4154 fprintf(STDERR, "vos: volume %s already exists\n",
4155 as->parms[1].items->data);
4159 if (code1 && code2) {
4160 fprintf(STDERR, "vos: Could not find entry for volume %s or %s\n",
4161 as->parms[0].items->data, as->parms[1].items->data);
4164 if (!VolNameOK(as->parms[0].items->data)) {
4166 "Illegal volume name %s, should not end in .readonly or .backup\n",
4167 as->parms[0].items->data);
4170 if (!ISNAMEVALID(as->parms[1].items->data)) {
4172 "vos: the new volume name %s exceeds the size limit of %d\n",
4173 as->parms[1].items->data, VOLSER_OLDMAXVOLNAME - 10);
4176 if (!VolNameOK(as->parms[1].items->data)) {
4178 "Illegal volume name %s, should not end in .readonly or .backup\n",
4179 as->parms[1].items->data);
4182 if (IsNumeric(as->parms[1].items->data)) {
4183 fprintf(STDERR, "Illegal volume name %s, should not be a number\n",
4184 as->parms[1].items->data);
4187 MapHostToNetwork(&entry);
4189 UV_RenameVolume(&entry, as->parms[0].items->data,
4190 as->parms[1].items->data);
4192 PrintDiagnostics("rename", code);
4195 fprintf(STDOUT, "Renamed volume %s to %s\n", as->parms[0].items->data,
4196 as->parms[1].items->data);
4201 GetVolumeInfo(afs_uint32 volid, afs_uint32 *server, afs_int32 *part, afs_int32 *voltype,
4202 struct nvldbentry *rentry)
4207 vcode = VLDB_GetEntryByID(volid, -1, rentry);
4210 "Could not fetch the entry for volume %lu from VLDB \n",
4211 (unsigned long)volid);
4212 PrintError("", vcode);
4215 MapHostToNetwork(rentry);
4216 if (volid == rentry->volumeId[ROVOL]) {
4218 for (i = 0; i < rentry->nServers; i++) {
4219 if ((index == -1) && (rentry->serverFlags[i] & ITSROVOL)
4220 && !(rentry->serverFlags[i] & RO_DONTUSE))
4225 "RO volume is not found in VLDB entry for volume %lu\n",
4226 (unsigned long)volid);
4230 *server = rentry->serverNumber[index];
4231 *part = rentry->serverPartition[index];
4235 index = Lp_GetRwIndex(rentry);
4238 "RW Volume is not found in VLDB entry for volume %lu\n",
4239 (unsigned long)volid);
4242 if (volid == rentry->volumeId[RWVOL]) {
4244 *server = rentry->serverNumber[index];
4245 *part = rentry->serverPartition[index];
4248 if (volid == rentry->volumeId[BACKVOL]) {
4250 *server = rentry->serverNumber[index];
4251 *part = rentry->serverPartition[index];
4255 "unexpected volume type for volume %lu\n",
4256 (unsigned long)volid);
4261 DeleteEntry(struct cmd_syndesc *as, void *arock)
4263 afs_int32 apart = 0;
4266 struct VldbListByAttributes attributes;
4267 nbulkentries arrayEntries;
4268 struct nvldbentry *vllist;
4269 struct cmd_item *itp;
4272 char prefix[VOLSER_MAXVOLNAME + 1];
4274 afs_int32 totalBack = 0, totalFail = 0, err;
4276 if (as->parms[0].items) { /* -id */
4277 if (as->parms[1].items || as->parms[2].items || as->parms[3].items) {
4279 "You cannot use -server, -partition, or -prefix with the -id argument\n");
4282 for (itp = as->parms[0].items; itp; itp = itp->next) {
4283 avolid = vsu_GetVolumeID(itp->data, cstruct, &err);
4286 PrintError("", err);
4288 fprintf(STDERR, "vos: can't find volume '%s'\n",
4292 if (as->parms[4].items) { /* -noexecute */
4293 fprintf(STDOUT, "Would have deleted VLDB entry for %s \n",
4298 vcode = ubik_VL_DeleteEntry(cstruct, 0, avolid, RWVOL);
4300 fprintf(STDERR, "Could not delete entry for volume %s\n",
4303 "You must specify a RW volume name or ID "
4304 "(the entire VLDB entry will be deleted)\n");
4305 PrintError("", vcode);
4311 fprintf(STDOUT, "Deleted %d VLDB entries\n", totalBack);
4315 if (!as->parms[1].items && !as->parms[2].items && !as->parms[3].items) {
4316 fprintf(STDERR, "You must specify an option\n");
4320 /* Zero out search attributes */
4321 memset(&attributes, 0, sizeof(struct VldbListByAttributes));
4323 if (as->parms[1].items) { /* -prefix */
4324 strncpy(prefix, as->parms[1].items->data, VOLSER_MAXVOLNAME);
4326 if (!as->parms[2].items && !as->parms[3].items) { /* a single entry only */
4328 "You must provide -server with the -prefix argument\n");
4333 if (as->parms[2].items) { /* -server */
4335 aserver = GetServer(as->parms[2].items->data);
4337 fprintf(STDERR, "vos: server '%s' not found in host table\n",
4338 as->parms[2].items->data);
4341 attributes.server = ntohl(aserver);
4342 attributes.Mask |= VLLIST_SERVER;
4345 if (as->parms[3].items) { /* -partition */
4346 if (!as->parms[2].items) {
4348 "You must provide -server with the -partition argument\n");
4351 apart = volutil_GetPartitionID(as->parms[3].items->data);
4353 fprintf(STDERR, "vos: could not interpret partition name '%s'\n",
4354 as->parms[3].items->data);
4357 attributes.partition = apart;
4358 attributes.Mask |= VLLIST_PARTITION;
4361 /* Print status line of what we are doing */
4362 fprintf(STDOUT, "Deleting VLDB entries for ");
4363 if (as->parms[2].items) {
4364 fprintf(STDOUT, "server %s ", as->parms[2].items->data);
4366 if (as->parms[3].items) {
4368 MapPartIdIntoName(apart, pname);
4369 fprintf(STDOUT, "partition %s ", pname);
4372 fprintf(STDOUT, "which are prefixed with %s ", prefix);
4374 fprintf(STDOUT, "\n");
4377 /* Get all the VLDB entries on a server and/or partition */
4378 memset(&arrayEntries, 0, sizeof(arrayEntries));
4379 vcode = VLDB_ListAttributes(&attributes, &nentries, &arrayEntries);
4381 fprintf(STDERR, "Could not access the VLDB for attributes\n");
4382 PrintError("", vcode);
4386 /* Process each entry */
4387 for (j = 0; j < nentries; j++) {
4388 vllist = &arrayEntries.nbulkentries_val[j];
4390 /* It only deletes the RW volumes */
4391 if (strncmp(vllist->name, prefix, strlen(prefix))) {
4394 "Omitting to delete %s due to prefix %s mismatch\n",
4395 vllist->name, prefix);
4402 if (as->parms[4].items) { /* -noexecute */
4403 fprintf(STDOUT, "Would have deleted VLDB entry for %s \n",
4409 /* Only matches the RW volume name */
4410 avolid = vllist->volumeId[RWVOL];
4411 vcode = ubik_VL_DeleteEntry(cstruct, 0, avolid, RWVOL);
4413 fprintf(STDOUT, "Could not delete VDLB entry for %s\n",
4416 PrintError("", vcode);
4421 fprintf(STDOUT, "Deleted VLDB entry for %s \n", vllist->name);
4426 fprintf(STDOUT, "----------------------\n");
4428 "Total VLDB entries deleted: %lu; failed to delete: %lu\n",
4429 (unsigned long)totalBack, (unsigned long)totalFail);
4430 if (arrayEntries.nbulkentries_val)
4431 free(arrayEntries.nbulkentries_val);
4437 CompareVldbEntryByName(const void *p1, const void *p2)
4439 struct nvldbentry *arg1, *arg2;
4441 arg1 = (struct nvldbentry *)p1;
4442 arg2 = (struct nvldbentry *)p2;
4443 return (strcmp(arg1->name, arg2->name));
4447 static int CompareVldbEntry(char *p1, char *p2)
4449 struct nvldbentry *arg1,*arg2;
4452 char comp1[100],comp2[100];
4453 char temp1[20],temp2[20];
4455 arg1 = (struct nvldbentry *)p1;
4456 arg2 = (struct nvldbentry *)p2;
4460 for(i = 0; i < arg1->nServers; i++)
4461 if(arg1->serverFlags[i] & ITSRWVOL) pos1 = i;
4462 for(i = 0; i < arg2->nServers; i++)
4463 if(arg2->serverFlags[i] & ITSRWVOL) pos2 = i;
4464 if(pos1 == -1 || pos2 == -1){
4468 sprintf(comp1,"%10u",arg1->serverNumber[pos1]);
4469 sprintf(comp2,"%10u",arg2->serverNumber[pos2]);
4470 sprintf(temp1,"%10u",arg1->serverPartition[pos1]);
4471 sprintf(temp2,"%10u",arg2->serverPartition[pos2]);
4472 strcat(comp1,temp1);
4473 strcat(comp2,temp2);
4474 strcat(comp1,arg1->name);
4475 strcat(comp1,arg2->name);
4476 return(strcmp(comp1,comp2));
4482 ListVLDB(struct cmd_syndesc *as, void *arock)
4488 struct VldbListByAttributes attributes;
4489 nbulkentries arrayEntries;
4490 struct nvldbentry *vllist, *tarray = 0, *ttarray;
4491 afs_int32 centries, nentries = 0;
4492 afs_int32 tarraysize = 0;
4493 afs_int32 parraysize;
4496 int quiet, sort, lock;
4497 afs_int32 thisindex, nextindex;
4502 attributes.Mask = 0;
4503 lock = (as->parms[3].items ? 1 : 0); /* -lock flag */
4504 quiet = (as->parms[4].items ? 1 : 0); /* -quit flag */
4505 sort = (as->parms[5].items ? 0 : 1); /* -nosort flag */
4507 /* If the volume name is given, Use VolumeInfoCmd to look it up
4508 * and not ListAttributes.
4510 if (as->parms[0].items) {
4513 "vos: illegal use of '-locked' switch, need to specify server and/or partition\n");
4516 code = VolumeInfoCmd(as->parms[0].items->data);
4518 PrintError("", code);
4524 /* Server specified */
4525 if (as->parms[1].items) {
4526 aserver = GetServer(as->parms[1].items->data);
4528 fprintf(STDERR, "vos: server '%s' not found in host table\n",
4529 as->parms[1].items->data);
4532 attributes.server = ntohl(aserver);
4533 attributes.Mask |= VLLIST_SERVER;
4536 /* Partition specified */
4537 if (as->parms[2].items) {
4538 apart = volutil_GetPartitionID(as->parms[2].items->data);
4540 fprintf(STDERR, "vos: could not interpret partition name '%s'\n",
4541 as->parms[2].items->data);
4544 attributes.partition = apart;
4545 attributes.Mask |= VLLIST_PARTITION;
4549 attributes.Mask |= VLLIST_FLAG;
4550 attributes.flag = VLOP_ALLOPERS;
4553 /* Print header information */
4555 MapPartIdIntoName(apart, pname);
4556 fprintf(STDOUT, "VLDB entries for %s %s%s%s %s\n",
4557 (as->parms[1].items ? "server" : "all"),
4558 (as->parms[1].items ? as->parms[1].items->data : "servers"),
4559 (as->parms[2].items ? " partition " : ""),
4560 (as->parms[2].items ? pname : ""),
4561 (lock ? "which are locked:" : ""));
4564 for (thisindex = 0; (thisindex != -1); thisindex = nextindex) {
4565 memset(&arrayEntries, 0, sizeof(arrayEntries));
4570 VLDB_ListAttributesN2(&attributes, 0, thisindex, ¢ries,
4571 &arrayEntries, &nextindex);
4572 if (vcode == RXGEN_OPCODE) {
4573 /* Vlserver not running with ListAttributesN2. Fall back */
4575 VLDB_ListAttributes(&attributes, ¢ries, &arrayEntries);
4579 fprintf(STDERR, "Could not access the VLDB for attributes\n");
4580 PrintError("", vcode);
4583 nentries += centries;
4585 /* We don't sort, so just print the entries now */
4587 for (j = 0; j < centries; j++) { /* process each entry */
4588 vllist = &arrayEntries.nbulkentries_val[j];
4589 MapHostToNetwork(vllist);
4590 EnumerateEntry(vllist);
4592 PrintLocked(vllist->flags);
4596 /* So we sort. First we must collect all the entries and keep
4599 else if (centries > 0) {
4601 /* steal away the first bulk entries array */
4602 tarray = (struct nvldbentry *)arrayEntries.nbulkentries_val;
4603 tarraysize = centries * sizeof(struct nvldbentry);
4604 arrayEntries.nbulkentries_val = 0;
4606 /* Grow the tarray to keep the extra entries */
4607 parraysize = (centries * sizeof(struct nvldbentry));
4609 (struct nvldbentry *)realloc(tarray,
4610 tarraysize + parraysize);
4613 "Could not allocate enough space for the VLDB entries\n");
4619 memcpy(((char *)tarray) + tarraysize,
4620 (char *)arrayEntries.nbulkentries_val, parraysize);
4621 tarraysize += parraysize;
4625 /* Free the bulk array */
4626 if (arrayEntries.nbulkentries_val) {
4627 free(arrayEntries.nbulkentries_val);
4628 arrayEntries.nbulkentries_val = 0;
4632 /* Here is where we now sort all the entries and print them */
4633 if (sort && (nentries > 0)) {
4634 qsort((char *)tarray, nentries, sizeof(struct nvldbentry),
4635 CompareVldbEntryByName);
4636 for (vllist = tarray, j = 0; j < nentries; j++, vllist++) {
4637 MapHostToNetwork(vllist);
4638 EnumerateEntry(vllist);
4640 PrintLocked(vllist->flags);
4646 fprintf(STDOUT, "\nTotal entries: %lu\n", (unsigned long)nentries);
4653 BackSys(struct cmd_syndesc *as, void *arock)
4656 afs_int32 apart = 0;
4657 afs_uint32 aserver = 0, aserver1;
4658 afs_int32 code, apart1;
4660 struct VldbListByAttributes attributes;
4661 nbulkentries arrayEntries;
4662 struct nvldbentry *vllist;
4666 int seenprefix, seenxprefix, exclude, ex, exp, noaction;
4667 afs_int32 totalBack = 0;
4668 afs_int32 totalFail = 0;
4672 struct cmd_item *ti;
4674 #ifndef HAVE_POSIX_REGEX
4678 memset(&attributes, 0, sizeof(struct VldbListByAttributes));
4679 attributes.Mask = 0;
4681 seenprefix = (as->parms[0].items ? 1 : 0);
4682 exclude = (as->parms[3].items ? 1 : 0);
4683 seenxprefix = (as->parms[4].items ? 1 : 0);
4684 noaction = (as->parms[5].items ? 1 : 0);
4686 if (as->parms[1].items) { /* -server */
4687 aserver = GetServer(as->parms[1].items->data);
4689 fprintf(STDERR, "vos: server '%s' not found in host table\n",
4690 as->parms[1].items->data);
4693 attributes.server = ntohl(aserver);
4694 attributes.Mask |= VLLIST_SERVER;
4697 if (as->parms[2].items) { /* -partition */
4698 apart = volutil_GetPartitionID(as->parms[2].items->data);
4700 fprintf(STDERR, "vos: could not interpret partition name '%s'\n",
4701 as->parms[2].items->data);
4704 attributes.partition = apart;
4705 attributes.Mask |= VLLIST_PARTITION;
4708 /* Check to make sure the prefix and xprefix expressions compile ok */
4710 for (ti = as->parms[0].items; ti; ti = ti->next) {
4711 if (strncmp(ti->data, "^", 1) == 0) {
4712 #ifdef HAVE_POSIX_REGEX
4716 code = regcomp(&re, ti->data, REG_NOSUB);
4718 regerror(code, &re, errbuf, sizeof errbuf);
4720 "Unrecognizable -prefix regular expression: '%s': %s\n",
4726 ccode = (char *)re_comp(ti->data);
4729 "Unrecognizable -prefix regular expression: '%s': %s\n",
4738 for (ti = as->parms[4].items; ti; ti = ti->next) {
4739 if (strncmp(ti->data, "^", 1) == 0) {
4740 #ifdef HAVE_POSIX_REGEX
4744 code = regcomp(&re, ti->data, REG_NOSUB);
4746 regerror(code, &re, errbuf, sizeof errbuf);
4748 "Unrecognizable -xprefix regular expression: '%s': %s\n",
4754 ccode = (char *)re_comp(ti->data);
4757 "Unrecognizable -xprefix regular expression: '%s': %s\n",
4766 memset(&arrayEntries, 0, sizeof(arrayEntries)); /* initialize to hint the stub to alloc space */
4767 vcode = VLDB_ListAttributes(&attributes, &nentries, &arrayEntries);
4769 fprintf(STDERR, "Could not access the VLDB for attributes\n");
4770 PrintError("", vcode);
4774 if (as->parms[1].items || as->parms[2].items || verbose) {
4775 fprintf(STDOUT, "%s up volumes",
4776 (noaction ? "Would have backed" : "Backing"));
4778 if (as->parms[1].items) {
4779 fprintf(STDOUT, " on server %s", as->parms[1].items->data);
4780 } else if (as->parms[2].items) {
4781 fprintf(STDOUT, " for all servers");
4784 if (as->parms[2].items) {
4785 MapPartIdIntoName(apart, pname);
4786 fprintf(STDOUT, " partition %s", pname);
4789 if (seenprefix || (!seenprefix && seenxprefix)) {
4790 ti = (seenprefix ? as->parms[0].items : as->parms[4].items);
4791 ex = (seenprefix ? exclude : !exclude);
4792 exp = (strncmp(ti->data, "^", 1) == 0);
4793 fprintf(STDOUT, " which %smatch %s '%s'", (ex ? "do not " : ""),
4794 (exp ? "expression" : "prefix"), ti->data);
4795 for (ti = ti->next; ti; ti = ti->next) {
4796 exp = (strncmp(ti->data, "^", 1) == 0);
4797 printf(" %sor %s '%s'", (ex ? "n" : ""),
4798 (exp ? "expression" : "prefix"), ti->data);
4802 if (seenprefix && seenxprefix) {
4803 ti = as->parms[4].items;
4804 exp = (strncmp(ti->data, "^", 1) == 0);
4805 fprintf(STDOUT, " %swhich match %s '%s'",
4806 (exclude ? "adding those " : "removing those "),
4807 (exp ? "expression" : "prefix"), ti->data);
4808 for (ti = ti->next; ti; ti = ti->next) {
4809 exp = (strncmp(ti->data, "^", 1) == 0);
4810 printf(" or %s '%s'", (exp ? "expression" : "prefix"),
4814 fprintf(STDOUT, " .. ");
4816 fprintf(STDOUT, "\n");
4820 for (j = 0; j < nentries; j++) { /* process each vldb entry */
4821 vllist = &arrayEntries.nbulkentries_val[j];
4824 for (ti = as->parms[0].items; ti; ti = ti->next) {
4825 if (strncmp(ti->data, "^", 1) == 0) {
4826 #ifdef HAVE_POSIX_REGEX
4830 /* XXX -- should just do the compile once! */
4831 code = regcomp(&re, ti->data, REG_NOSUB);
4833 regerror(code, &re, errbuf, sizeof errbuf);
4835 "Error in -prefix regular expression: '%s': %s\n",
4839 match = (regexec(&re, vllist->name, 0, NULL, 0) == 0);
4842 ccode = (char *)re_comp(ti->data);
4845 "Error in -prefix regular expression: '%s': %s\n",
4849 match = (re_exec(vllist->name) == 1);
4853 (strncmp(vllist->name, ti->data, strlen(ti->data)) ==
4863 /* Without the -exclude flag: If it matches the prefix, then
4864 * check if we want to exclude any from xprefix.
4865 * With the -exclude flag: If it matches the prefix, then
4866 * check if we want to add any from xprefix.
4868 if (match && seenxprefix) {
4869 for (ti = as->parms[4].items; ti; ti = ti->next) {
4870 if (strncmp(ti->data, "^", 1) == 0) {
4871 #ifdef HAVE_POSIX_REGEX
4875 /* XXX -- should just do the compile once! */
4876 code = regcomp(&re, ti->data, REG_NOSUB);
4878 regerror(code, &re, errbuf, sizeof errbuf);
4880 "Error in -xprefix regular expression: '%s': %s\n",
4884 if (regexec(&re, vllist->name, 0, NULL, 0) == 0)
4888 ccode = (char *)re_comp(ti->data);
4891 "Error in -xprefix regular expression: '%s': %s\n",
4895 if (re_exec(vllist->name) == 1) {
4901 if (strncmp(vllist->name, ti->data, strlen(ti->data)) ==
4911 match = !match; /* -exclude will reverse the match */
4913 continue; /* Skip if no match */
4915 /* Print list of volumes to backup */
4917 fprintf(STDOUT, " %s\n", vllist->name);
4921 if (!(vllist->flags & RW_EXISTS)) {
4924 "Omitting to backup %s since RW volume does not exist \n",
4926 fprintf(STDOUT, "\n");
4932 avolid = vllist->volumeId[RWVOL];
4933 MapHostToNetwork(vllist);
4934 GetServerAndPart(vllist, RWVOL, &aserver1, &apart1, &previdx);
4935 if (aserver1 == -1 || apart1 == -1) {
4936 fprintf(STDOUT, "could not backup %s, invalid VLDB entry\n",
4942 same = VLDB_IsSameAddrs(aserver, aserver1, &error);
4945 "Failed to get info about server's %d address(es) from vlserver (err=%d); aborting call!\n",
4951 if ((aserver && !same) || (apart && (apart != apart1))) {
4954 "Omitting to backup %s since the RW is in a different location\n",
4960 time_t now = time(0);
4961 fprintf(STDOUT, "Creating backup volume for %s on %s",
4962 vllist->name, ctime(&now));
4966 code = UV_BackupVolume(aserver1, apart1, avolid);
4968 fprintf(STDOUT, "Could not backup %s\n", vllist->name);
4974 fprintf(STDOUT, "\n");
4976 } /* process each vldb entry */
4977 fprintf(STDOUT, "done\n");
4978 fprintf(STDOUT, "Total volumes backed up: %lu; failed to backup: %lu\n",
4979 (unsigned long)totalBack, (unsigned long)totalFail);
4981 if (arrayEntries.nbulkentries_val)
4982 free(arrayEntries.nbulkentries_val);
4987 UnlockVLDB(struct cmd_syndesc *as, void *arock)
4990 afs_uint32 aserver = 0;
4993 struct VldbListByAttributes attributes;
4994 nbulkentries arrayEntries;
4995 struct nvldbentry *vllist;
5004 attributes.Mask = 0;
5006 if (as->parms[0].items) { /* server specified */
5007 aserver = GetServer(as->parms[0].items->data);
5009 fprintf(STDERR, "vos: server '%s' not found in host table\n",
5010 as->parms[0].items->data);
5013 attributes.server = ntohl(aserver);
5014 attributes.Mask |= VLLIST_SERVER;
5016 if (as->parms[1].items) { /* partition specified */
5017 apart = volutil_GetPartitionID(as->parms[1].items->data);
5019 fprintf(STDERR, "vos: could not interpret partition name '%s'\n",
5020 as->parms[1].items->data);
5023 if (!IsPartValid(apart, aserver, &code)) { /*check for validity of the partition */
5025 PrintError("", code);
5028 "vos : partition %s does not exist on the server\n",
5029 as->parms[1].items->data);
5032 attributes.partition = apart;
5033 attributes.Mask |= VLLIST_PARTITION;
5035 attributes.flag = VLOP_ALLOPERS;
5036 attributes.Mask |= VLLIST_FLAG;
5037 memset(&arrayEntries, 0, sizeof(arrayEntries)); /*initialize to hint the stub to alloc space */
5038 vcode = VLDB_ListAttributes(&attributes, &nentries, &arrayEntries);
5040 fprintf(STDERR, "Could not access the VLDB for attributes\n");
5041 PrintError("", vcode);
5044 for (j = 0; j < nentries; j++) { /* process each entry */
5045 vllist = &arrayEntries.nbulkentries_val[j];
5046 volid = vllist->volumeId[RWVOL];
5048 ubik_VL_ReleaseLock(cstruct, 0, volid, -1,
5049 LOCKREL_OPCODE | LOCKREL_AFSID |
5052 fprintf(STDERR, "Could not unlock entry for volume %s\n",
5054 PrintError("", vcode);
5059 MapPartIdIntoName(apart, pname);
5062 "Could not lock %lu VLDB entries of %lu locked entries\n",
5063 (unsigned long)totalE, (unsigned long)nentries);
5065 if (as->parms[0].items) {
5067 "Unlocked all the VLDB entries for volumes on server %s ",
5068 as->parms[0].items->data);
5069 if (as->parms[1].items) {
5070 MapPartIdIntoName(apart, pname);
5071 fprintf(STDOUT, "partition %s\n", pname);
5073 fprintf(STDOUT, "\n");
5075 } else if (as->parms[1].items) {
5076 MapPartIdIntoName(apart, pname);
5078 "Unlocked all the VLDB entries for volumes on partition %s on all servers\n",
5083 if (arrayEntries.nbulkentries_val)
5084 free(arrayEntries.nbulkentries_val);
5089 PrintInt64Size(afs_uint64 in)
5093 static char output[16];
5095 SplitInt64(in,hi,lo);
5099 } else if (!(hi & 0xFFFFFC00)) {
5101 lo = (hi << 22) | (lo >> 10);
5102 } else if (!(hi & 0xFFF00000)) {
5104 lo = (hi << 12) | (lo >> 20);
5105 } else if (!(hi & 0xC0000000)) {
5107 lo = (hi << 2) | (lo >> 30);
5112 sprintf(output,"%u %s", lo, units);
5117 PartitionInfo(struct cmd_syndesc *as, void *arock)
5123 struct diskPartition64 partition;
5124 struct partList dummyPartList;
5126 int printSummary=0, sumPartitions=0;
5127 afs_uint64 sumFree, sumStorage;
5130 ZeroInt64(sumStorage);
5132 aserver = GetServer(as->parms[0].items->data);
5134 fprintf(STDERR, "vos: server '%s' not found in host table\n",
5135 as->parms[0].items->data);
5138 if (as->parms[1].items) {
5139 apart = volutil_GetPartitionID(as->parms[1].items->data);
5141 fprintf(STDERR, "vos: could not interpret partition name '%s'\n",
5142 as->parms[1].items->data);
5145 dummyPartList.partId[0] = apart;
5146 dummyPartList.partFlags[0] = PARTVALID;
5149 if (as->parms[2].items) {
5153 if (!IsPartValid(apart, aserver, &code)) { /*check for validity of the partition */
5155 PrintError("", code);
5158 "vos : partition %s does not exist on the server\n",
5159 as->parms[1].items->data);
5163 code = UV_ListPartitions(aserver, &dummyPartList, &cnt);
5165 PrintDiagnostics("listpart", code);
5169 for (i = 0; i < cnt; i++) {
5170 if (dummyPartList.partFlags[i] & PARTVALID) {
5171 MapPartIdIntoName(dummyPartList.partId[i], pname);
5172 code = UV_PartitionInfo64(aserver, pname, &partition);
5174 fprintf(STDERR, "Could not get information on partition %s\n",
5176 PrintError("", code);
5180 "Free space on partition %s: %" AFS_INT64_FMT " K blocks out of total %" AFS_INT64_FMT "\n",
5181 pname, partition.free, partition.minFree);
5183 AddUInt64(sumFree,partition.free,&sumFree);
5184 AddUInt64(sumStorage,partition.minFree,&sumStorage);
5189 "Summary: %s free out of ",
5190 PrintInt64Size(sumFree));
5192 "%s on %d partitions\n",
5193 PrintInt64Size(sumStorage),
5200 ChangeAddr(struct cmd_syndesc *as, void *arock)
5202 afs_int32 ip1, ip2, vcode;
5206 ip1 = GetServerNoresolve(as->parms[0].items->data);
5208 ip1 = GetServer(as->parms[0].items->data);
5210 fprintf(STDERR, "vos: invalid host address\n");
5214 if ((as->parms[1].items && as->parms[2].items)
5215 || (!as->parms[1].items && !as->parms[2].items)) {
5217 "vos: Must specify either '-newaddr <addr>' or '-remove' flag\n");
5221 if (as->parms[1].items) {
5223 ip2 = GetServerNoresolve(as->parms[1].items->data);
5225 ip2 = GetServer(as->parms[1].items->data);
5227 fprintf(STDERR, "vos: invalid host address\n");
5231 /* Play a trick here. If we are removing an address, ip1 will be -1
5232 * and ip2 will be the original address. This switch prevents an
5233 * older revision vlserver from removing the IP address.
5240 vcode = ubik_VL_ChangeAddr(cstruct, UBIK_CALL_NEW, ntohl(ip1), ntohl(ip2));
5242 char hoststr1[16], hoststr2[16];
5244 afs_inet_ntoa_r(ip2, hoststr2);
5245 fprintf(STDERR, "Could not remove server %s from the VLDB\n",
5247 if (vcode == VL_NOENT) {
5249 "vlserver does not support the remove flag or ");
5252 afs_inet_ntoa_r(ip1, hoststr1);
5253 afs_inet_ntoa_r(ip2, hoststr2);
5254 fprintf(STDERR, "Could not change server %s to server %s\n",
5255 hoststr1, hoststr2);
5257 PrintError("", vcode);
5262 fprintf(STDOUT, "Removed server %s from the VLDB\n",
5263 as->parms[0].items->data);
5265 fprintf(STDOUT, "Changed server %s to server %s\n",
5266 as->parms[0].items->data, as->parms[1].items->data);
5272 print_addrs(const bulkaddrs * addrs, afsUUID * m_uuid, int nentries,
5275 afs_int32 vcode, m_uniq=0;
5279 ListAddrByAttributes m_attrs;
5280 afs_int32 m_nentries;
5281 afs_uint32 *m_addrp;
5282 afs_int32 base, index;
5286 afsUUID_to_string(m_uuid, buf, sizeof(buf));
5287 printf("UUID: %s\n", buf);
5290 /* print out the list of all the server */
5291 addrp = (afs_uint32 *) addrs->bulkaddrs_val;
5292 for (i = 0; i < nentries; i++, addrp++) {
5293 /* If it is a multihomed address, then we will need to
5294 * get the addresses for this multihomed server from
5295 * the vlserver and print them.
5297 if (((*addrp & 0xff000000) == 0xff000000) && ((*addrp) & 0xffff)) {
5298 /* Get the list of multihomed fileservers */
5299 base = (*addrp >> 16) & 0xff;
5300 index = (*addrp) & 0xffff;
5302 if ((base >= 0) && (base <= VL_MAX_ADDREXTBLKS) && (index >= 1)
5303 && (index <= VL_MHSRV_PERBLK)) {
5304 m_attrs.Mask = VLADDR_INDEX;
5305 m_attrs.index = (base * VL_MHSRV_PERBLK) + index;
5307 m_addrs.bulkaddrs_val = 0;
5308 m_addrs.bulkaddrs_len = 0;
5310 ubik_VL_GetAddrsU(cstruct, 0, &m_attrs, m_uuid,
5311 &m_uniq, &m_nentries,
5315 "vos: could not list the multi-homed server addresses\n");
5316 PrintError("", vcode);
5319 /* Print the list */
5320 m_addrp = (afs_uint32 *) m_addrs.bulkaddrs_val;
5321 for (j = 0; j < m_nentries; j++, m_addrp++) {
5322 *m_addrp = htonl(*m_addrp);
5325 printf("%s ", afs_inet_ntoa_r(*m_addrp, hoststr));
5327 printf("%s ", hostutil_GetNameByINet(*m_addrp));
5331 printf("<unknown>\n");
5340 /* Otherwise, it is a non-multihomed entry and contains
5341 * the IP address of the server - print it.
5343 *addrp = htonl(*addrp);
5346 printf("%s\n", afs_inet_ntoa_r(*addrp, hoststr));
5348 printf("%s\n", hostutil_GetNameByINet(*addrp));
5359 ListAddrs(struct cmd_syndesc *as, void *arock)
5361 afs_int32 vcode, m_uniq=0;
5362 afs_int32 i, printuuid = 0;
5363 struct VLCallBack vlcb;
5366 ListAddrByAttributes m_attrs;
5367 afsUUID m_uuid, askuuid;
5368 afs_int32 m_nentries;
5370 memset(&m_attrs, 0, sizeof(struct ListAddrByAttributes));
5371 m_attrs.Mask = VLADDR_INDEX;
5373 memset(&m_addrs, 0, sizeof(bulkaddrs));
5374 memset(&askuuid, 0, sizeof(afsUUID));
5375 if (as->parms[0].items) {
5377 if (afsUUID_from_string(as->parms[0].items->data, &askuuid) < 0) {
5378 fprintf(STDERR, "vos: invalid UUID '%s'\n",
5379 as->parms[0].items->data);
5382 m_attrs.Mask = VLADDR_UUID;
5383 m_attrs.uuid = askuuid;
5385 if (as->parms[1].items) {
5389 he = hostutil_GetHostByName((char *)as->parms[1].items->data);
5391 fprintf(STDERR, "vos: Can't get host info for '%s'\n",
5392 as->parms[1].items->data);
5395 memcpy(&saddr, he->h_addr, 4);
5396 m_attrs.Mask = VLADDR_IPADDR;
5397 m_attrs.ipaddr = ntohl(saddr);
5399 if (as->parms[2].items) {
5403 m_addrs.bulkaddrs_val = 0;
5404 m_addrs.bulkaddrs_len = 0;
5407 ubik_VL_GetAddrs(cstruct, UBIK_CALL_NEW, 0, 0, &vlcb, &nentries,
5410 fprintf(STDERR, "vos: could not list the server addresses\n");
5411 PrintError("", vcode);
5416 m_addrs.bulkaddrs_val = 0;
5417 m_addrs.bulkaddrs_len = 0;
5423 ubik_VL_GetAddrsU(cstruct, UBIK_CALL_NEW, &m_attrs, &m_uuid,
5424 &m_uniq, &m_nentries, &m_addrs);
5426 if (vcode == VL_NOENT) {
5427 if (m_attrs.Mask == VLADDR_UUID) {
5428 fprintf(STDERR, "vos: no entry for UUID '%s' found in VLDB\n",
5429 as->parms[0].items->data);
5431 } else if (m_attrs.Mask == VLADDR_IPADDR) {
5432 fprintf(STDERR, "vos: no entry for host '%s' [0x%08x] found in VLDB\n",
5433 as->parms[1].items->data, m_attrs.ipaddr);
5442 if (vcode == VL_INDEXERANGE) {
5447 fprintf(STDERR, "vos: could not list the server addresses\n");
5448 PrintError("", vcode);
5452 print_addrs(&m_addrs, &m_uuid, m_nentries, printuuid);
5455 if ((as->parms[1].items) || (as->parms[0].items) || (i > nentries))
5464 SetAddrs(struct cmd_syndesc *as, void *arock)
5469 afs_uint32 FS_HostAddrs_HBO[ADDRSPERSITE];
5471 memset(&m_addrs, 0, sizeof(bulkaddrs));
5472 memset(&askuuid, 0, sizeof(afsUUID));
5473 if (as->parms[0].items) {
5475 if (afsUUID_from_string(as->parms[0].items->data, &askuuid) < 0) {
5476 fprintf(STDERR, "vos: invalid UUID '%s'\n",
5477 as->parms[0].items->data);
5481 if (as->parms[1].items) {
5483 struct cmd_item *ti;
5487 for (ti = as->parms[1].items; ti && i < ADDRSPERSITE; ti = ti->next) {
5490 saddr = GetServerNoresolve(ti->data);
5492 saddr = GetServer(ti->data);
5495 fprintf(STDERR, "vos: Can't get host info for '%s'\n",
5499 /* Convert it to host byte order */
5500 FS_HostAddrs_HBO[i] = ntohl(saddr);
5503 m_addrs.bulkaddrs_len = i;
5504 m_addrs.bulkaddrs_val = FS_HostAddrs_HBO;
5507 vcode = ubik_VL_RegisterAddrs(cstruct, 0, &askuuid, 0, &m_addrs);
5510 if (vcode == VL_MULTIPADDR) {
5511 fprintf(STDERR, "vos: VL_RegisterAddrs rpc failed; The IP address exists on a different server; repair it\n");
5512 PrintError("", vcode);
5514 } else if (vcode == RXGEN_OPCODE) {
5515 fprintf(STDERR, "vlserver doesn't support VL_RegisterAddrs rpc; ignored\n");
5516 PrintError("", vcode);
5521 fprintf(STDOUT, "vos: Changed UUID with addresses:\n");
5522 print_addrs(&m_addrs, &askuuid, m_addrs.bulkaddrs_len, 1);
5528 LockEntry(struct cmd_syndesc *as, void *arock)
5531 afs_int32 vcode, err;
5533 avolid = vsu_GetVolumeID(as->parms[0].items->data, cstruct, &err);
5536 PrintError("", err);
5538 fprintf(STDERR, "vos: can't find volume '%s'\n",
5539 as->parms[0].items->data);
5542 vcode = ubik_VL_SetLock(cstruct, 0, avolid, -1, VLOP_DELETE);
5544 fprintf(STDERR, "Could not lock VLDB entry for volume %s\n",
5545 as->parms[0].items->data);
5546 PrintError("", vcode);
5549 fprintf(STDOUT, "Locked VLDB entry for volume %s\n",
5550 as->parms[0].items->data);
5555 ConvertRO(struct cmd_syndesc *as, void *arock)
5557 afs_int32 partition = -1;
5560 afs_int32 code, i, same;
5561 struct nvldbentry entry, storeEntry;
5563 afs_int32 rwindex = 0;
5564 afs_uint32 rwserver = 0;
5565 afs_int32 rwpartition = 0;
5566 afs_int32 roindex = 0;
5567 afs_uint32 roserver = 0;
5568 afs_int32 ropartition = 0;
5570 struct rx_connection *aconn;
5573 server = GetServer(as->parms[0].items->data);
5575 fprintf(STDERR, "vos: host '%s' not found in host table\n",
5576 as->parms[0].items->data);
5579 partition = volutil_GetPartitionID(as->parms[1].items->data);
5580 if (partition < 0) {
5581 fprintf(STDERR, "vos: could not interpret partition name '%s'\n",
5582 as->parms[1].items->data);
5585 if (!IsPartValid(partition, server, &code)) {
5587 PrintError("", code);
5590 "vos : partition %s does not exist on the server\n",
5591 as->parms[1].items->data);
5594 volid = vsu_GetVolumeID(as->parms[2].items->data, cstruct, &code);
5597 PrintError("", code);
5599 fprintf(STDERR, "Unknown volume ID or name '%s'\n",
5600 as->parms[0].items->data);
5603 if (as->parms[3].items)
5606 vcode = VLDB_GetEntryByID(volid, -1, &entry);
5609 "Could not fetch the entry for volume %lu from VLDB\n",
5610 (unsigned long)volid);
5611 PrintError("convertROtoRW", code);
5615 /* use RO volid even if user specified RW or BK volid */
5617 if (volid != entry.volumeId[ROVOL])
5618 volid = entry.volumeId[ROVOL];
5620 MapHostToNetwork(&entry);
5621 for (i = 0; i < entry.nServers; i++) {
5622 if (entry.serverFlags[i] & ITSRWVOL) {
5624 rwserver = entry.serverNumber[i];
5625 rwpartition = entry.serverPartition[i];
5627 if (entry.serverFlags[i] & ITSROVOL) {
5628 same = VLDB_IsSameAddrs(server, entry.serverNumber[i], &code);
5631 "Failed to get info about server's %d address(es) from vlserver (err=%d); aborting call!\n",
5637 roserver = entry.serverNumber[i];
5638 ropartition = entry.serverPartition[i];
5644 fprintf(STDERR, "Warning: RO volume didn't exist in vldb!\n");
5646 if (ropartition != partition) {
5648 "Warning: RO volume should be in partition %d instead of %d (vldb)\n",
5649 ropartition, partition);
5654 "VLDB indicates that a RW volume exists already on %s in partition %s.\n",
5655 hostutil_GetNameByINet(rwserver),
5656 volutil_PartitionName(rwpartition));
5658 fprintf(STDERR, "Overwrite this VLDB entry? [y|n] (n)\n");
5660 while (!(dc == EOF || dc == '\n'))
5661 dc = getchar(); /* goto end of line */
5662 if ((c != 'y') && (c != 'Y')) {
5663 fprintf(STDERR, "aborted.\n");
5670 ubik_VL_SetLock(cstruct, 0, entry.volumeId[RWVOL], RWVOL,
5672 aconn = UV_Bind(server, AFSCONF_VOLUMEPORT);
5673 code = AFSVolConvertROtoRWvolume(aconn, partition, volid);
5676 "Converting RO volume %lu to RW volume failed with code %d\n",
5677 (unsigned long)volid, code);
5678 PrintError("convertROtoRW ", code);
5681 entry.serverFlags[roindex] = ITSRWVOL;
5682 entry.flags |= RW_EXISTS;
5683 entry.flags &= ~BACK_EXISTS;
5686 if (rwindex != entry.nServers) {
5687 entry.serverNumber[rwindex] = entry.serverNumber[entry.nServers];
5688 entry.serverPartition[rwindex] =
5689 entry.serverPartition[entry.nServers];
5690 entry.serverFlags[rwindex] = entry.serverFlags[entry.nServers];
5691 entry.serverNumber[entry.nServers] = 0;
5692 entry.serverPartition[entry.nServers] = 0;
5693 entry.serverFlags[entry.nServers] = 0;
5696 entry.flags &= ~RO_EXISTS;
5697 for (i = 0; i < entry.nServers; i++) {
5698 if (entry.serverFlags[i] & ITSROVOL) {
5699 if (!(entry.serverFlags[i] & (RO_DONTUSE | NEW_REPSITE)))
5700 entry.flags |= RO_EXISTS;
5703 MapNetworkToHost(&entry, &storeEntry);
5705 VLDB_ReplaceEntry(entry.volumeId[RWVOL], RWVOL, &storeEntry,
5706 (LOCKREL_OPCODE | LOCKREL_AFSID |
5707 LOCKREL_TIMESTAMP));
5710 "Warning: volume converted, but vldb update failed with code %d!\n",
5713 vcode = UV_LockRelease(entry.volumeId[RWVOL]);
5715 PrintDiagnostics("unlock", vcode);
5721 Sizes(struct cmd_syndesc *as, void *arock)
5725 afs_int32 apart, voltype, fromdate = 0, code, err, i;
5726 struct nvldbentry entry;
5727 volintSize vol_size;
5729 rx_SetRxDeadTime(60 * 10);
5730 for (i = 0; i < MAXSERVERS; i++) {
5731 struct rx_connection *rxConn = ubik_GetRPCConn(cstruct, i);
5734 rx_SetConnDeadTime(rxConn, rx_connDeadTime);
5735 if (rxConn->service)
5736 rxConn->service->connDeadTime = rx_connDeadTime;
5739 avolid = vsu_GetVolumeID(as->parms[0].items->data, cstruct, &err);
5742 PrintError("", err);
5744 fprintf(STDERR, "vos: can't find volume '%s'\n",
5745 as->parms[0].items->data);
5749 if (as->parms[1].items || as->parms[2].items) {
5750 if (!as->parms[1].items || !as->parms[2].items) {
5752 "Must specify both -server and -partition options\n");
5755 aserver = GetServer(as->parms[2].items->data);
5757 fprintf(STDERR, "Invalid server name\n");
5760 apart = volutil_GetPartitionID(as->parms[1].items->data);
5762 fprintf(STDERR, "Invalid partition name\n");
5766 code = GetVolumeInfo(avolid, &aserver, &apart, &voltype, &entry);
5773 if (as->parms[4].items && strcmp(as->parms[4].items->data, "0")) {
5774 code = ktime_DateToInt32(as->parms[4].items->data, &fromdate);
5776 fprintf(STDERR, "vos: failed to parse date '%s' (error=%d))\n",
5777 as->parms[4].items->data, code);
5782 fprintf(STDOUT, "Volume: %s\n", as->parms[0].items->data);
5784 if (as->parms[3].items) { /* do the dump estimate */
5785 #ifdef AFS_64BIT_ENV
5786 vol_size.dump_size = 0;
5788 FillInt64(vol_size.dump_size,0, 1);
5790 code = UV_GetSize(avolid, aserver, apart, fromdate, &vol_size);
5792 PrintDiagnostics("size", code);
5795 /* presumably the size info is now gathered in pntr */
5796 /* now we display it */
5798 fprintf(STDOUT, "dump_size: %llu\n", vol_size.dump_size);
5807 EndTrans(struct cmd_syndesc *as, void *arock)
5810 afs_int32 code, tid, rcode;
5811 struct rx_connection *aconn;
5813 server = GetServer(as->parms[0].items->data);
5815 fprintf(STDERR, "vos: host '%s' not found in host table\n",
5816 as->parms[0].items->data);
5820 code = util_GetInt32(as->parms[1].items->data, &tid);
5822 fprintf(STDERR, "vos: bad integer specified for transaction ID.\n");
5826 aconn = UV_Bind(server, AFSCONF_VOLUMEPORT);
5827 code = AFSVolEndTrans(aconn, tid, &rcode);
5833 PrintDiagnostics("endtrans", code);
5841 PrintDiagnostics(char *astring, afs_int32 acode)
5843 if (acode == EACCES) {
5845 "You are not authorized to perform the 'vos %s' command (%d)\n",
5848 fprintf(STDERR, "Error in vos %s command.\n", astring);
5849 PrintError("", acode);
5857 win32_enableCrypt(void)
5864 /* Look up configuration parameters in Registry */
5865 code = RegOpenKeyEx(HKEY_LOCAL_MACHINE, AFSREG_CLT_SVC_PARAM_SUBKEY,
5866 0, (IsWow64()?KEY_WOW64_64KEY:0)|KEY_QUERY_VALUE, &parmKey);
5867 if (code != ERROR_SUCCESS) {
5868 dummyLen = sizeof(cryptall);
5869 RegQueryValueEx(parmKey, "SecurityLevel", NULL, NULL,
5870 (BYTE *) &cryptall, &dummyLen);
5872 RegCloseKey (parmKey);
5876 #endif /* AFS_NT40_ENV */
5879 MyBeforeProc(struct cmd_syndesc *as, void *arock)
5885 /* Initialize the ubik_client connection */
5886 rx_SetRxDeadTime(90);
5887 cstruct = (struct ubik_client *)0;
5891 if (as->parms[12].items) /* if -cell specified */
5892 tcell = as->parms[12].items->data;
5893 if (as->parms[14].items) /* -serverauth specified */
5895 if (as->parms[16].items /* -encrypt specified */
5897 || win32_enableCrypt()
5898 #endif /* AFS_NT40_ENV */
5902 vsu_ClientInit((as->parms[13].items != 0), confdir, tcell, sauth,
5903 &cstruct, UV_SetSecurity))) {
5904 fprintf(STDERR, "could not initialize VLDB library (code=%lu) \n",
5905 (unsigned long)code);
5909 if (as->parms[15].items) /* -verbose flag set */
5913 if (as->parms[17].items) /* -noresolve flag set */
5923 /* this sucks but it works for now.
5928 #include "AFS_component_version_number.c"
5931 main(int argc, char **argv)
5935 struct cmd_syndesc *ts;
5937 #ifdef AFS_AIX32_ENV
5939 * The following signal action for AIX is necessary so that in case of a
5940 * crash (i.e. core is generated) we can include the user's data section
5941 * in the core dump. Unfortunately, by default, only a partial core is
5942 * generated which, in many cases, isn't too useful.
5944 struct sigaction nsa;
5946 sigemptyset(&nsa.sa_mask);
5947 nsa.sa_handler = SIG_DFL;
5948 nsa.sa_flags = SA_FULLDUMP;
5949 sigaction(SIGSEGV, &nsa, NULL);
5952 confdir = AFSDIR_CLIENT_ETC_DIRPATH;
5954 cmd_SetBeforeProc(MyBeforeProc, NULL);
5956 ts = cmd_CreateSyntax("create", CreateVolume, NULL, "create a new volume");
5957 cmd_AddParm(ts, "-server", CMD_SINGLE, 0, "machine name");
5958 cmd_AddParm(ts, "-partition", CMD_SINGLE, 0, "partition name");
5959 cmd_AddParm(ts, "-name", CMD_SINGLE, 0, "volume name");
5960 cmd_AddParm(ts, "-maxquota", CMD_SINGLE, CMD_OPTIONAL,
5961 "initial quota (KB)");
5962 cmd_AddParm(ts, "-id", CMD_SINGLE, CMD_OPTIONAL, "volume ID");
5963 cmd_AddParm(ts, "-roid", CMD_SINGLE, CMD_OPTIONAL, "readonly volume ID");
5965 cmd_AddParm(ts, "-minquota", CMD_SINGLE, CMD_OPTIONAL, "");
5969 ts = cmd_CreateSyntax("remove", DeleteVolume, NULL, "delete a volume");
5970 cmd_AddParm(ts, "-server", CMD_SINGLE, CMD_OPTIONAL, "machine name");
5971 cmd_AddParm(ts, "-partition", CMD_SINGLE, CMD_OPTIONAL, "partition name");
5972 cmd_AddParm(ts, "-id", CMD_SINGLE, 0, "volume name or ID");
5976 ts = cmd_CreateSyntax("move", MoveVolume, NULL, "move a volume");
5977 cmd_AddParm(ts, "-id", CMD_SINGLE, 0, "volume name or ID");
5978 cmd_AddParm(ts, "-fromserver", CMD_SINGLE, 0, "machine name on source");
5979 cmd_AddParm(ts, "-frompartition", CMD_SINGLE, 0,
5980 "partition name on source");
5981 cmd_AddParm(ts, "-toserver", CMD_SINGLE, 0,
5982 "machine name on destination");
5983 cmd_AddParm(ts, "-topartition", CMD_SINGLE, 0,
5984 "partition name on destination");
5985 cmd_AddParm(ts, "-live", CMD_FLAG, CMD_OPTIONAL,
5986 "copy live volume without cloning");
5989 ts = cmd_CreateSyntax("copy", CopyVolume, NULL, "copy a volume");
5990 cmd_AddParm(ts, "-id", CMD_SINGLE, 0, "volume name or ID on source");
5991 cmd_AddParm(ts, "-fromserver", CMD_SINGLE, 0, "machine name on source");
5992 cmd_AddParm(ts, "-frompartition", CMD_SINGLE, 0,
5993 "partition name on source");
5994 cmd_AddParm(ts, "-toname", CMD_SINGLE, 0, "volume name on destination");
5995 cmd_AddParm(ts, "-toserver", CMD_SINGLE, 0,
5996 "machine name on destination");
5997 cmd_AddParm(ts, "-topartition", CMD_SINGLE, 0,
5998 "partition name on destination");
5999 cmd_AddParm(ts, "-offline", CMD_FLAG, CMD_OPTIONAL,
6000 "leave new volume offline");
6001 cmd_AddParm(ts, "-readonly", CMD_FLAG, CMD_OPTIONAL,
6002 "make new volume read-only");
6003 cmd_AddParm(ts, "-live", CMD_FLAG, CMD_OPTIONAL,
6004 "copy live volume without cloning");
6007 ts = cmd_CreateSyntax("shadow", ShadowVolume, NULL,
6008 "make or update a shadow volume");
6009 cmd_AddParm(ts, "-id", CMD_SINGLE, 0, "volume name or ID on source");
6010 cmd_AddParm(ts, "-fromserver", CMD_SINGLE, 0, "machine name on source");
6011 cmd_AddParm(ts, "-frompartition", CMD_SINGLE, 0,
6012 "partition name on source");
6013 cmd_AddParm(ts, "-toserver", CMD_SINGLE, 0,
6014 "machine name on destination");
6015 cmd_AddParm(ts, "-topartition", CMD_SINGLE, 0,
6016 "partition name on destination");
6017 cmd_AddParm(ts, "-toname", CMD_SINGLE, CMD_OPTIONAL,
6018 "volume name on destination");
6019 cmd_AddParm(ts, "-toid", CMD_SINGLE, CMD_OPTIONAL,
6020 "volume ID on destination");
6021 cmd_AddParm(ts, "-offline", CMD_FLAG, CMD_OPTIONAL,
6022 "leave shadow volume offline");
6023 cmd_AddParm(ts, "-readonly", CMD_FLAG, CMD_OPTIONAL,
6024 "make shadow volume read-only");
6025 cmd_AddParm(ts, "-live", CMD_FLAG, CMD_OPTIONAL,
6026 "copy live volume without cloning");
6027 cmd_AddParm(ts, "-incremental", CMD_FLAG, CMD_OPTIONAL,
6028 "do incremental update if target exists");
6031 ts = cmd_CreateSyntax("backup", BackupVolume, NULL,
6032 "make backup of a volume");
6033 cmd_AddParm(ts, "-id", CMD_SINGLE, 0, "volume name or ID");
6036 ts = cmd_CreateSyntax("clone", CloneVolume, NULL,
6037 "make clone of a volume");
6038 cmd_AddParm(ts, "-id", CMD_SINGLE, 0, "volume name or ID");
6039 cmd_AddParm(ts, "-server", CMD_SINGLE, CMD_OPTIONAL, "server");
6040 cmd_AddParm(ts, "-partition", CMD_SINGLE, CMD_OPTIONAL, "partition");
6041 cmd_AddParm(ts, "-toname", CMD_SINGLE, CMD_OPTIONAL,
6042 "volume name on destination");
6043 cmd_AddParm(ts, "-toid", CMD_SINGLE, CMD_OPTIONAL,
6044 "volume ID on destination");
6045 cmd_AddParm(ts, "-offline", CMD_FLAG, CMD_OPTIONAL,
6046 "leave clone volume offline");
6047 cmd_AddParm(ts, "-readonly", CMD_FLAG, CMD_OPTIONAL,
6048 "make clone volume read-only, not readwrite");
6051 ts = cmd_CreateSyntax("release", ReleaseVolume, NULL, "release a volume");
6052 cmd_AddParm(ts, "-id", CMD_SINGLE, 0, "volume name or ID");
6053 cmd_AddParm(ts, "-force", CMD_FLAG, CMD_OPTIONAL,
6054 "force a complete release");
6057 ts = cmd_CreateSyntax("dump", DumpVolumeCmd, NULL, "dump a volume");
6058 cmd_AddParm(ts, "-id", CMD_SINGLE, 0, "volume name or ID");
6059 cmd_AddParm(ts, "-time", CMD_SINGLE, CMD_OPTIONAL, "dump from time");
6060 cmd_AddParm(ts, "-file", CMD_SINGLE, CMD_OPTIONAL, "dump file");
6061 cmd_AddParm(ts, "-server", CMD_SINGLE, CMD_OPTIONAL, "server");
6062 cmd_AddParm(ts, "-partition", CMD_SINGLE, CMD_OPTIONAL, "partition");
6063 cmd_AddParm(ts, "-clone", CMD_FLAG, CMD_OPTIONAL,
6064 "dump a clone of the volume");
6065 cmd_AddParm(ts, "-omitdirs", CMD_FLAG, CMD_OPTIONAL,
6066 "omit unchanged directories from an incremental dump");
6069 ts = cmd_CreateSyntax("restore", RestoreVolumeCmd, NULL,
6070 "restore a volume");
6071 cmd_AddParm(ts, "-server", CMD_SINGLE, 0, "machine name");
6072 cmd_AddParm(ts, "-partition", CMD_SINGLE, 0, "partition name");
6073 cmd_AddParm(ts, "-name", CMD_SINGLE, 0, "name of volume to be restored");
6074 cmd_AddParm(ts, "-file", CMD_SINGLE, CMD_OPTIONAL, "dump file");
6075 cmd_AddParm(ts, "-id", CMD_SINGLE, CMD_OPTIONAL, "volume ID");
6076 cmd_AddParm(ts, "-overwrite", CMD_SINGLE, CMD_OPTIONAL,
6077 "abort | full | incremental");
6078 cmd_AddParm(ts, "-offline", CMD_FLAG, CMD_OPTIONAL,
6079 "leave restored volume offline");
6080 cmd_AddParm(ts, "-readonly", CMD_FLAG, CMD_OPTIONAL,
6081 "make restored volume read-only");
6082 cmd_AddParm(ts, "-creation", CMD_SINGLE, CMD_OPTIONAL,
6083 "dump | keep | new");
6084 cmd_AddParm(ts, "-lastupdate", CMD_SINGLE, CMD_OPTIONAL,
6085 "dump | keep | new");
6086 cmd_AddParm(ts, "-nodelete", CMD_FLAG, CMD_OPTIONAL,
6087 "do not delete old site when restoring to a new site");
6090 ts = cmd_CreateSyntax("unlock", LockReleaseCmd, NULL,
6091 "release lock on VLDB entry for a volume");
6092 cmd_AddParm(ts, "-id", CMD_SINGLE, 0, "volume name or ID");
6095 ts = cmd_CreateSyntax("changeloc", ChangeLocation, NULL,
6096 "change an RW volume's location in the VLDB");
6097 cmd_AddParm(ts, "-server", CMD_SINGLE, 0,
6098 "machine name for new location");
6099 cmd_AddParm(ts, "-partition", CMD_SINGLE, 0,
6100 "partition name for new location");
6101 cmd_AddParm(ts, "-id", CMD_SINGLE, 0, "volume name or ID");
6104 ts = cmd_CreateSyntax("addsite", AddSite, NULL, "add a replication site");
6105 cmd_AddParm(ts, "-server", CMD_SINGLE, 0, "machine name for new site");
6106 cmd_AddParm(ts, "-partition", CMD_SINGLE, 0,
6107 "partition name for new site");
6108 cmd_AddParm(ts, "-id", CMD_SINGLE, 0, "volume name or ID");
6109 cmd_AddParm(ts, "-roid", CMD_SINGLE, CMD_OPTIONAL, "volume name or ID for RO");
6110 cmd_AddParm(ts, "-valid", CMD_FLAG, CMD_OPTIONAL, "publish as an up-to-date site in VLDB");
6113 ts = cmd_CreateSyntax("remsite", RemoveSite, NULL,
6114 "remove a replication site");
6115 cmd_AddParm(ts, "-server", CMD_SINGLE, 0, "machine name");
6116 cmd_AddParm(ts, "-partition", CMD_SINGLE, 0, "partition name");
6117 cmd_AddParm(ts, "-id", CMD_SINGLE, 0, "volume name or ID");
6120 ts = cmd_CreateSyntax("listpart", ListPartitions, NULL, "list partitions");
6121 cmd_AddParm(ts, "-server", CMD_SINGLE, 0, "machine name");
6124 ts = cmd_CreateSyntax("listvol", ListVolumes, NULL,
6125 "list volumes on server (bypass VLDB)");
6126 cmd_AddParm(ts, "-server", CMD_SINGLE, 0, "machine name");
6127 cmd_AddParm(ts, "-partition", CMD_SINGLE, CMD_OPTIONAL, "partition name");
6128 cmd_AddParm(ts, "-fast", CMD_FLAG, CMD_OPTIONAL, "minimal listing");
6129 cmd_AddParm(ts, "-long", CMD_FLAG, CMD_OPTIONAL,
6130 "list all normal volume fields");
6131 cmd_AddParm(ts, "-quiet", CMD_FLAG, CMD_OPTIONAL,
6132 "generate minimal information");
6133 cmd_AddParm(ts, "-extended", CMD_FLAG, CMD_OPTIONAL,
6134 "list extended volume fields");
6135 cmd_AddParm(ts, "-format", CMD_FLAG, CMD_OPTIONAL,
6136 "machine readable format");
6139 ts = cmd_CreateSyntax("syncvldb", SyncVldb, NULL,
6140 "synchronize VLDB with server");
6141 cmd_AddParm(ts, "-server", CMD_SINGLE, CMD_OPTIONAL, "machine name");
6142 cmd_AddParm(ts, "-partition", CMD_SINGLE, CMD_OPTIONAL, "partition name");
6143 cmd_AddParm(ts, "-volume", CMD_SINGLE, CMD_OPTIONAL, "volume name or ID");
6144 cmd_AddParm(ts, "-dryrun", CMD_FLAG, CMD_OPTIONAL, "report without updating");
6147 ts = cmd_CreateSyntax("syncserv", SyncServer, NULL,
6148 "synchronize server with VLDB");
6149 cmd_AddParm(ts, "-server", CMD_SINGLE, 0, "machine name");
6150 cmd_AddParm(ts, "-partition", CMD_SINGLE, CMD_OPTIONAL, "partition name");
6151 cmd_AddParm(ts, "-dryrun", CMD_FLAG, CMD_OPTIONAL, "report without updating");
6154 ts = cmd_CreateSyntax("examine", ExamineVolume, NULL,
6155 "everything about the volume");
6156 cmd_AddParm(ts, "-id", CMD_SINGLE, 0, "volume name or ID");
6157 cmd_AddParm(ts, "-extended", CMD_FLAG, CMD_OPTIONAL,
6158 "list extended volume fields");
6159 cmd_AddParm(ts, "-format", CMD_FLAG, CMD_OPTIONAL,
6160 "machine readable format");
6162 cmd_CreateAlias(ts, "volinfo");
6164 ts = cmd_CreateSyntax("setfields", SetFields, NULL,
6165 "change volume info fields");
6166 cmd_AddParm(ts, "-id", CMD_SINGLE, 0, "volume name or ID");
6167 cmd_AddParm(ts, "-maxquota", CMD_SINGLE, CMD_OPTIONAL, "quota (KB)");
6168 cmd_AddParm(ts, "-clearuse", CMD_FLAG, CMD_OPTIONAL, "clear dayUse");
6169 cmd_AddParm(ts, "-clearVolUpCounter", CMD_FLAG, CMD_OPTIONAL, "clear volUpdateCounter");
6172 ts = cmd_CreateSyntax("offline", volOffline, NULL, "force the volume status to offline");
6173 cmd_AddParm(ts, "-server", CMD_SINGLE, 0, "server name");
6174 cmd_AddParm(ts, "-partition", CMD_SINGLE, 0, "partition name");
6175 cmd_AddParm(ts, "-id", CMD_SINGLE, 0, "volume name or ID");
6176 cmd_AddParm(ts, "-sleep", CMD_SINGLE, CMD_OPTIONAL, "seconds to sleep");
6177 cmd_AddParm(ts, "-busy", CMD_FLAG, CMD_OPTIONAL, "busy volume");
6180 ts = cmd_CreateSyntax("online", volOnline, NULL, "force the volume status to online");
6181 cmd_AddParm(ts, "-server", CMD_SINGLE, 0, "server name");
6182 cmd_AddParm(ts, "-partition", CMD_SINGLE, 0, "partition name");
6183 cmd_AddParm(ts, "-id", CMD_SINGLE, 0, "volume name or ID");
6186 ts = cmd_CreateSyntax("zap", VolumeZap, NULL,
6187 "delete the volume, don't bother with VLDB");
6188 cmd_AddParm(ts, "-server", CMD_SINGLE, 0, "machine name");
6189 cmd_AddParm(ts, "-partition", CMD_SINGLE, 0, "partition name");
6190 cmd_AddParm(ts, "-id", CMD_SINGLE, 0, "volume ID");
6191 cmd_AddParm(ts, "-force", CMD_FLAG, CMD_OPTIONAL,
6192 "force deletion of bad volumes");
6193 cmd_AddParm(ts, "-backup", CMD_FLAG, CMD_OPTIONAL,
6194 "also delete backup volume if one is found");
6197 ts = cmd_CreateSyntax("status", VolserStatus, NULL,
6198 "report on volser status");
6199 cmd_AddParm(ts, "-server", CMD_SINGLE, 0, "machine name");
6202 ts = cmd_CreateSyntax("rename", RenameVolume, NULL, "rename a volume");
6203 cmd_AddParm(ts, "-oldname", CMD_SINGLE, 0, "old volume name ");
6204 cmd_AddParm(ts, "-newname", CMD_SINGLE, 0, "new volume name ");
6207 ts = cmd_CreateSyntax("listvldb", ListVLDB, NULL,
6208 "list volumes in the VLDB");
6209 cmd_AddParm(ts, "-name", CMD_SINGLE, CMD_OPTIONAL, "volume name or ID");
6210 cmd_AddParm(ts, "-server", CMD_SINGLE, CMD_OPTIONAL, "machine name");
6211 cmd_AddParm(ts, "-partition", CMD_SINGLE, CMD_OPTIONAL, "partition name");
6212 cmd_AddParm(ts, "-locked", CMD_FLAG, CMD_OPTIONAL, "locked volumes only");
6213 cmd_AddParm(ts, "-quiet", CMD_FLAG, CMD_OPTIONAL,
6214 "generate minimal information");
6215 cmd_AddParm(ts, "-nosort", CMD_FLAG, CMD_OPTIONAL,
6216 "do not alphabetically sort the volume names");
6219 ts = cmd_CreateSyntax("backupsys", BackSys, NULL, "en masse backups");
6220 cmd_AddParm(ts, "-prefix", CMD_LIST, CMD_OPTIONAL,
6221 "common prefix on volume(s)");
6222 cmd_AddParm(ts, "-server", CMD_SINGLE, CMD_OPTIONAL, "machine name");
6223 cmd_AddParm(ts, "-partition", CMD_SINGLE, CMD_OPTIONAL, "partition name");
6224 cmd_AddParm(ts, "-exclude", CMD_FLAG, CMD_OPTIONAL,
6225 "exclude common prefix volumes");
6226 cmd_AddParm(ts, "-xprefix", CMD_LIST, CMD_OPTIONAL,
6227 "negative prefix on volume(s)");
6228 cmd_AddParm(ts, "-dryrun", CMD_FLAG, CMD_OPTIONAL, "no action");
6231 ts = cmd_CreateSyntax("delentry", DeleteEntry, NULL,
6232 "delete VLDB entry for a volume");
6233 cmd_AddParm(ts, "-id", CMD_LIST, CMD_OPTIONAL, "volume name or ID");
6234 cmd_AddParm(ts, "-prefix", CMD_SINGLE, CMD_OPTIONAL,
6235 "prefix of the volume whose VLDB entry is to be deleted");
6236 cmd_AddParm(ts, "-server", CMD_SINGLE, CMD_OPTIONAL, "machine name");
6237 cmd_AddParm(ts, "-partition", CMD_SINGLE, CMD_OPTIONAL, "partition name");
6238 cmd_AddParm(ts, "-noexecute", CMD_FLAG, CMD_OPTIONAL,
6242 ts = cmd_CreateSyntax("partinfo", PartitionInfo, NULL,
6243 "list partition information");
6244 cmd_AddParm(ts, "-server", CMD_SINGLE, 0, "machine name");
6245 cmd_AddParm(ts, "-partition", CMD_SINGLE, CMD_OPTIONAL, "partition name");
6246 cmd_AddParm(ts, "-summary", CMD_FLAG, CMD_OPTIONAL,
6247 "print storage summary");
6250 ts = cmd_CreateSyntax("unlockvldb", UnlockVLDB, NULL,
6251 "unlock all the locked entries in the VLDB");
6252 cmd_AddParm(ts, "-server", CMD_SINGLE, CMD_OPTIONAL, "machine name");
6253 cmd_AddParm(ts, "-partition", CMD_SINGLE, CMD_OPTIONAL, "partition name");
6256 ts = cmd_CreateSyntax("lock", LockEntry, NULL,
6257 "lock VLDB entry for a volume");
6258 cmd_AddParm(ts, "-id", CMD_SINGLE, 0, "volume name or ID");
6261 ts = cmd_CreateSyntax("changeaddr", ChangeAddr, NULL,
6262 "change the IP address of a file server");
6263 cmd_AddParm(ts, "-oldaddr", CMD_SINGLE, 0, "original IP address");
6264 cmd_AddParm(ts, "-newaddr", CMD_SINGLE, CMD_OPTIONAL, "new IP address");
6265 cmd_AddParm(ts, "-remove", CMD_FLAG, CMD_OPTIONAL,
6266 "remove the IP address from the VLDB");
6269 ts = cmd_CreateSyntax("listaddrs", ListAddrs, NULL,
6270 "list the IP address of all file servers registered in the VLDB");
6271 cmd_AddParm(ts, "-uuid", CMD_SINGLE, CMD_OPTIONAL, "uuid of server");
6272 cmd_AddParm(ts, "-host", CMD_SINGLE, CMD_OPTIONAL, "address of host");
6273 cmd_AddParm(ts, "-printuuid", CMD_FLAG, CMD_OPTIONAL,
6274 "print uuid of hosts");
6277 ts = cmd_CreateSyntax("convertROtoRW", ConvertRO, NULL,
6278 "convert a RO volume into a RW volume (after loss of old RW volume)");
6279 cmd_AddParm(ts, "-server", CMD_SINGLE, 0, "machine name");
6280 cmd_AddParm(ts, "-partition", CMD_SINGLE, 0, "partition name");
6281 cmd_AddParm(ts, "-id", CMD_SINGLE, 0, "volume name or ID");
6282 cmd_AddParm(ts, "-force", CMD_FLAG, CMD_OPTIONAL, "don't ask");
6285 ts = cmd_CreateSyntax("size", Sizes, NULL,
6286 "obtain various sizes of the volume.");
6287 cmd_AddParm(ts, "-id", CMD_SINGLE, 0, "volume name or ID");
6288 cmd_AddParm(ts, "-partition", CMD_SINGLE, CMD_OPTIONAL, "partition name");
6289 cmd_AddParm(ts, "-server", CMD_SINGLE, CMD_OPTIONAL, "machine name");
6290 cmd_AddParm(ts, "-dump", CMD_FLAG, CMD_OPTIONAL,
6291 "Obtain the size of the dump");
6292 cmd_AddParm(ts, "-time", CMD_SINGLE, CMD_OPTIONAL, "dump from time");
6295 ts = cmd_CreateSyntax("endtrans", EndTrans, NULL,
6296 "end a volserver transaction");
6297 cmd_AddParm(ts, "-server", CMD_SINGLE, 0, "machine name");
6298 cmd_AddParm(ts, "-transaction", CMD_SINGLE, 0,
6302 ts = cmd_CreateSyntax("setaddrs", SetAddrs, NULL,
6303 "set the list of IP address for a given UUID in the VLDB");
6304 cmd_AddParm(ts, "-uuid", CMD_SINGLE, 0, "uuid of server");
6305 cmd_AddParm(ts, "-host", CMD_LIST, 0, "address of host");
6308 code = cmd_Dispatch(argc, argv);
6310 /* Shut down the ubik_client and rx connections */
6312 (void)ubik_ClientDestroy(cstruct);
6318 exit((code ? -1 : 0));