2 * Copyright 2000, International Business Machines Corporation and others.
5 * This software has been released under the terms of the IBM Public
6 * License. For details, see the LICENSE file in the top-level source
7 * directory or online at http://www.openafs.org/dl/license10.html
10 #include <afsconfig.h>
11 #include <afs/param.h>
15 #ifdef IGNORE_SOME_GCC_WARNINGS
16 # pragma GCC diagnostic warning "-Wimplicit-function-declaration"
19 #include <sys/types.h>
28 #include <WINNT/afsreg.h>
33 #include <netinet/in.h>
34 #include <arpa/inet.h>
38 #include <sys/statfs.h>
46 #include <rx/rx_globals.h>
48 #include <afs/vlserver.h>
49 #include <afs/cellconfig.h>
51 #include <afs/afsutil.h>
53 #include <afs/afsint.h>
58 #include <afs/ihandle.h>
59 #include <afs/vnode.h>
60 #include <afs/volume.h>
61 #include <afs/com_err.h>
68 #include "volser_internal.h"
69 #include "volser_prototypes.h"
70 #include "vsutils_prototypes.h"
71 #include "lockprocs_prototypes.h"
73 #ifdef HAVE_POSIX_REGEX
77 /* Local Prototypes */
78 int PrintDiagnostics(char *astring, afs_int32 acode);
79 int GetVolumeInfo(afs_uint32 volid, afs_uint32 *server, afs_int32 *part,
80 afs_int32 *voltype, struct uvldbentry *rentry);
92 #define COMMONPARMS cmd_Seek(ts, 12);\
93 cmd_AddParm(ts, "-cell", CMD_SINGLE, CMD_OPTIONAL, "cell name");\
94 cmd_AddParm(ts, "-noauth", CMD_FLAG, CMD_OPTIONAL, "don't authenticate");\
95 cmd_AddParm(ts, "-localauth",CMD_FLAG,CMD_OPTIONAL,"use server tickets");\
96 cmd_AddParm(ts, "-verbose", CMD_FLAG, CMD_OPTIONAL, "verbose");\
97 cmd_AddParm(ts, "-encrypt", CMD_FLAG, CMD_OPTIONAL, "encrypt commands");\
98 cmd_AddParm(ts, "-noresolve", CMD_FLAG, CMD_OPTIONAL, "don't resolve addresses"); \
100 #define ERROR_EXIT(code) do { \
106 struct rx_connection *tconn;
108 extern struct ubik_client *cstruct;
111 static struct tqHead busyHead, notokHead;
114 qInit(struct tqHead *ahead)
116 memset(ahead, 0, sizeof(struct tqHead));
122 qPut(struct tqHead *ahead, afs_uint32 volid)
126 elem = (struct tqElem *)malloc(sizeof(struct tqElem));
127 elem->next = ahead->next;
135 qGet(struct tqHead *ahead, afs_uint32 *volid)
139 if (ahead->count <= 0)
141 *volid = ahead->next->volid;
143 ahead->next = tmp->next;
149 /* returns 1 if <filename> exists else 0 */
151 FileExists(char *filename)
157 code = usd_Open(filename, USD_OPEN_RDONLY, 0, &ufd);
161 code = USD_IOCTL(ufd, USD_IOCTL_GETSIZE, &size);
169 /* returns 1 if <name> doesnot end in .readonly or .backup, else 0 */
171 VolNameOK(char *name)
175 total = strlen(name);
176 if (!strcmp(&name[total - 9], ".readonly")) {
178 } else if (!strcmp(&name[total - 7], ".backup")) {
185 /* return 1 if name is a number else 0 */
187 IsNumeric(char *name)
196 for (i = 0; i < len; i++) {
197 if (*ptr < '0' || *ptr > '9') {
209 * Parse a server dotted address and return the address in network byte order
212 GetServerNoresolve(char *aname)
218 code = sscanf(aname, "%d.%d.%d.%d", &b1, &b2, &b3, &b4);
220 addr = (b1 << 24) | (b2 << 16) | (b3 << 8) | b4;
221 addr = htonl(addr); /* convert to network byte order */
227 * Parse a server name/address and return the address in network byte order
230 GetServer(char *aname)
233 afs_uint32 addr; /* in network byte order */
235 char hostname[MAXHOSTCHARS];
237 if ((addr = GetServerNoresolve(aname)) == 0) {
238 th = gethostbyname(aname);
241 memcpy(&addr, th->h_addr, sizeof(addr));
244 if (rx_IsLoopbackAddr(ntohl(addr))) { /* local host */
245 code = gethostname(hostname, MAXHOSTCHARS);
248 th = gethostbyname(hostname);
251 memcpy(&addr, th->h_addr, sizeof(addr));
258 GetVolumeType(char *aname)
261 if (!strcmp(aname, "ro"))
263 else if (!strcmp(aname, "rw"))
265 else if (!strcmp(aname, "bk"))
272 IsPartValid(afs_int32 partId, afs_uint32 server, afs_int32 *code)
274 struct partList dummyPartList;
280 *code = UV_ListPartitions(server, &dummyPartList, &cnt);
283 for (i = 0; i < cnt; i++) {
284 if (dummyPartList.partFlags[i] & PARTVALID)
285 if (dummyPartList.partId[i] == partId)
293 /*sends the contents of file associated with <fd> and <blksize> to Rx Stream
294 * associated with <call> */
296 SendFile(usd_handle_t ufd, struct rx_call *call, long blksize)
298 char *buffer = (char *)0;
303 buffer = (char *)malloc(blksize);
305 fprintf(STDERR, "malloc failed\n");
309 while (!error && !done) {
310 #ifndef AFS_NT40_ENV /* NT csn't select on non-socket fd's */
313 FD_SET((intptr_t)(ufd->handle), &in);
314 /* don't timeout if read blocks */
315 #if defined(AFS_PTHREAD_ENV)
316 select(((intptr_t)(ufd->handle)) + 1, &in, 0, 0, 0);
318 IOMGR_Select(((intptr_t)(ufd->handle)) + 1, &in, 0, 0, 0);
321 error = USD_READ(ufd, buffer, blksize, &nbytes);
323 fprintf(STDERR, "File system read failed: %s\n",
324 afs_error_message(error));
331 if (rx_Write(call, buffer, nbytes) != nbytes) {
341 /* function invoked by UV_RestoreVolume, reads the data from rx_trx_stream and
342 * writes it out to the volume. */
344 WriteData(struct rx_call *call, void *rock)
346 char *filename = (char *) rock;
349 afs_int32 error, code;
351 afs_hyper_t filesize, currOffset;
357 if (!filename || !*filename) {
358 usd_StandardInput(&ufd);
362 code = usd_Open(filename, USD_OPEN_RDONLY, 0, &ufd);
365 code = USD_IOCTL(ufd, USD_IOCTL_GETBLKSIZE, &blksize);
368 fprintf(STDERR, "Could not access file '%s': %s\n", filename,
369 afs_error_message(code));
373 /* test if we have a valid dump */
374 hset64(filesize, 0, 0);
375 USD_SEEK(ufd, filesize, SEEK_END, &currOffset);
376 hset64(filesize, hgethi(currOffset), hgetlo(currOffset)-sizeof(afs_uint32));
377 USD_SEEK(ufd, filesize, SEEK_SET, &currOffset);
378 USD_READ(ufd, (char *)&buffer, sizeof(afs_uint32), &got);
379 if ((got != sizeof(afs_uint32)) || (ntohl(buffer) != DUMPENDMAGIC)) {
380 fprintf(STDERR, "Signature missing from end of file '%s'\n", filename);
384 /* rewind, we are done */
385 hset64(filesize, 0, 0);
386 USD_SEEK(ufd, filesize, SEEK_SET, &currOffset);
388 code = SendFile(ufd, call, blksize);
395 code = USD_CLOSE(ufd);
397 fprintf(STDERR, "Could not close dump file %s\n",
398 (filename && *filename) ? filename : "STDOUT");
406 /* Receive data from <call> stream into file associated
407 * with <fd> <blksize>
410 ReceiveFile(usd_handle_t ufd, struct rx_call *call, long blksize)
414 afs_uint32 bytesleft, w;
417 buffer = (char *)malloc(blksize);
419 fprintf(STDERR, "memory allocation failed\n");
423 while ((bytesread = rx_Read(call, buffer, blksize)) > 0) {
424 for (bytesleft = bytesread; bytesleft; bytesleft -= w) {
425 #ifndef AFS_NT40_ENV /* NT csn't select on non-socket fd's */
428 FD_SET((intptr_t)(ufd->handle), &out);
429 /* don't timeout if write blocks */
430 #if defined(AFS_PTHREAD_ENV)
431 select(((intptr_t)(ufd->handle)) + 1, &out, 0, 0, 0);
433 IOMGR_Select(((intptr_t)(ufd->handle)) + 1, 0, &out, 0, 0);
437 USD_WRITE(ufd, &buffer[bytesread - bytesleft], bytesleft, &w);
439 fprintf(STDERR, "File system write failed: %s\n",
440 afs_error_message(error));
453 DumpFunction(struct rx_call *call, void *rock)
455 char *filename = (char *)rock;
456 usd_handle_t ufd; /* default is to stdout */
457 afs_int32 error = 0, code;
462 /* Open the output file */
463 if (!filename || !*filename) {
464 usd_StandardOutput(&ufd);
469 usd_Open(filename, USD_OPEN_CREATE | USD_OPEN_RDWR, 0666, &ufd);
473 code = USD_IOCTL(ufd, USD_IOCTL_SETSIZE, &size);
476 code = USD_IOCTL(ufd, USD_IOCTL_GETBLKSIZE, &blksize);
479 fprintf(STDERR, "Could not create file '%s': %s\n", filename,
480 afs_error_message(code));
481 ERROR_EXIT(VOLSERBADOP);
485 code = ReceiveFile(ufd, call, blksize);
490 /* Close the output file */
492 code = USD_CLOSE(ufd);
494 fprintf(STDERR, "Could not close dump file %s\n",
495 (filename && *filename) ? filename : "STDIN");
505 DisplayFormat(volintInfo *pntr, afs_uint32 server, afs_int32 part,
506 int *totalOK, int *totalNotOK, int *totalBusy, int fast,
507 int longlist, int disp)
513 fprintf(STDOUT, "%-10lu\n", (unsigned long)pntr->volid);
514 } else if (longlist) {
515 if (pntr->status == VOK) {
516 fprintf(STDOUT, "%-32s ", pntr->name);
517 fprintf(STDOUT, "%10lu ", (unsigned long)pntr->volid);
519 fprintf(STDOUT, "RW ");
521 fprintf(STDOUT, "RO ");
523 fprintf(STDOUT, "BK ");
524 fprintf(STDOUT, "%10d K ", pntr->size);
525 if (pntr->inUse == 1) {
526 fprintf(STDOUT, "On-line");
529 fprintf(STDOUT, "Off-line");
532 if (pntr->needsSalvaged == 1)
533 fprintf(STDOUT, "**needs salvage**");
534 fprintf(STDOUT, "\n");
535 MapPartIdIntoName(part, pname);
536 fprintf(STDOUT, " %s %s \n", hostutil_GetNameByINet(server),
538 fprintf(STDOUT, " RWrite %10lu ROnly %10lu Backup %10lu \n",
539 (unsigned long)pntr->parentID,
540 (unsigned long)pntr->cloneID,
541 (unsigned long)pntr->backupID);
542 fprintf(STDOUT, " MaxQuota %10d K \n", pntr->maxquota);
543 t = pntr->creationDate;
544 fprintf(STDOUT, " Creation %s",
547 fprintf(STDOUT, " Copy %s",
550 t = pntr->backupDate;
552 fprintf(STDOUT, " Backup Never\n");
554 fprintf(STDOUT, " Backup %s",
557 t = pntr->accessDate;
559 fprintf(STDOUT, " Last Access %s",
562 t = pntr->updateDate;
564 fprintf(STDOUT, " Last Update Never\n");
566 fprintf(STDOUT, " Last Update %s",
569 " %d accesses in the past day (i.e., vnode references)\n",
571 } else if (pntr->status == VBUSY) {
573 qPut(&busyHead, pntr->volid);
575 fprintf(STDOUT, "**** Volume %lu is busy ****\n",
576 (unsigned long)pntr->volid);
579 qPut(¬okHead, pntr->volid);
581 fprintf(STDOUT, "**** Could not attach volume %lu ****\n",
582 (unsigned long)pntr->volid);
584 fprintf(STDOUT, "\n");
585 } else { /* default listing */
586 if (pntr->status == VOK) {
587 fprintf(STDOUT, "%-32s ", pntr->name);
588 fprintf(STDOUT, "%10lu ", (unsigned long)pntr->volid);
590 fprintf(STDOUT, "RW ");
592 fprintf(STDOUT, "RO ");
594 fprintf(STDOUT, "BK ");
595 fprintf(STDOUT, "%10d K ", pntr->size);
596 if (pntr->inUse == 1) {
597 fprintf(STDOUT, "On-line");
600 fprintf(STDOUT, "Off-line");
603 if (pntr->needsSalvaged == 1)
604 fprintf(STDOUT, "**needs salvage**");
605 fprintf(STDOUT, "\n");
606 } else if (pntr->status == VBUSY) {
608 qPut(&busyHead, pntr->volid);
610 fprintf(STDOUT, "**** Volume %lu is busy ****\n",
611 (unsigned long)pntr->volid);
614 qPut(¬okHead, pntr->volid);
616 fprintf(STDOUT, "**** Could not attach volume %lu ****\n",
617 (unsigned long)pntr->volid);
622 /*------------------------------------------------------------------------
623 * PRIVATE XDisplayFormat
626 * Display the contents of one extended volume info structure.
629 * a_xInfoP : Ptr to extended volume info struct to print.
630 * a_servID : Server ID to print.
631 * a_partID : Partition ID to print.
632 * a_totalOKP : Ptr to total-OK counter.
633 * a_totalNotOKP : Ptr to total-screwed counter.
634 * a_totalBusyP : Ptr to total-busy counter.
635 * a_fast : Fast listing?
636 * a_int32 : Int32 listing?
637 * a_showProblems : Show volume problems?
643 * Nothing interesting.
647 *------------------------------------------------------------------------*/
650 XDisplayFormat(volintXInfo *a_xInfoP, afs_uint32 a_servID, afs_int32 a_partID,
651 int *a_totalOKP, int *a_totalNotOKP, int *a_totalBusyP,
652 int a_fast, int a_int32, int a_showProblems)
653 { /*XDisplayFormat */
661 fprintf(STDOUT, "%-10lu\n", (unsigned long)a_xInfoP->volid);
662 } else if (a_int32) {
664 * Fully-detailed listing.
666 if (a_xInfoP->status == VOK) {
668 * Volume's status is OK - all the fields are valid.
670 fprintf(STDOUT, "%-32s ", a_xInfoP->name);
671 fprintf(STDOUT, "%10lu ", (unsigned long)a_xInfoP->volid);
672 if (a_xInfoP->type == 0)
673 fprintf(STDOUT, "RW ");
674 if (a_xInfoP->type == 1)
675 fprintf(STDOUT, "RO ");
676 if (a_xInfoP->type == 2)
677 fprintf(STDOUT, "BK ");
678 fprintf(STDOUT, "%10d K used ", a_xInfoP->size);
679 fprintf(STDOUT, "%d files ", a_xInfoP->filecount);
680 if (a_xInfoP->inUse == 1) {
681 fprintf(STDOUT, "On-line");
684 fprintf(STDOUT, "Off-line");
687 fprintf(STDOUT, "\n");
688 MapPartIdIntoName(a_partID, pname);
689 fprintf(STDOUT, " %s %s \n", hostutil_GetNameByINet(a_servID),
691 fprintf(STDOUT, " RWrite %10lu ROnly %10lu Backup %10lu \n",
692 (unsigned long)a_xInfoP->parentID,
693 (unsigned long)a_xInfoP->cloneID,
694 (unsigned long)a_xInfoP->backupID);
695 fprintf(STDOUT, " MaxQuota %10d K \n", a_xInfoP->maxquota);
697 t = a_xInfoP->creationDate;
698 fprintf(STDOUT, " Creation %s",
701 t = a_xInfoP->copyDate;
702 fprintf(STDOUT, " Copy %s",
705 t = a_xInfoP->backupDate;
707 fprintf(STDOUT, " Backup Never\n");
709 fprintf(STDOUT, " Backup %s",
712 t = a_xInfoP->accessDate;
714 fprintf(STDOUT, " Last Access %s",
717 t = a_xInfoP->updateDate;
719 fprintf(STDOUT, " Last Update Never\n");
721 fprintf(STDOUT, " Last Update %s",
724 " %d accesses in the past day (i.e., vnode references)\n",
728 * Print all the read/write and authorship stats.
730 fprintf(STDOUT, "\n Raw Read/Write Stats\n");
732 " |-------------------------------------------|\n");
734 " | Same Network | Diff Network |\n");
736 " |----------|----------|----------|----------|\n");
738 " | Total | Auth | Total | Auth |\n");
740 " |----------|----------|----------|----------|\n");
741 fprintf(STDOUT, "Reads | %8d | %8d | %8d | %8d |\n",
742 a_xInfoP->stat_reads[VOLINT_STATS_SAME_NET],
743 a_xInfoP->stat_reads[VOLINT_STATS_SAME_NET_AUTH],
744 a_xInfoP->stat_reads[VOLINT_STATS_DIFF_NET],
745 a_xInfoP->stat_reads[VOLINT_STATS_DIFF_NET_AUTH]);
746 fprintf(STDOUT, "Writes | %8d | %8d | %8d | %8d |\n",
747 a_xInfoP->stat_writes[VOLINT_STATS_SAME_NET],
748 a_xInfoP->stat_writes[VOLINT_STATS_SAME_NET_AUTH],
749 a_xInfoP->stat_writes[VOLINT_STATS_DIFF_NET],
750 a_xInfoP->stat_writes[VOLINT_STATS_DIFF_NET_AUTH]);
752 " |-------------------------------------------|\n\n");
755 " Writes Affecting Authorship\n");
757 " |-------------------------------------------|\n");
759 " | File Authorship | Directory Authorship|\n");
761 " |----------|----------|----------|----------|\n");
763 " | Same | Diff | Same | Diff |\n");
765 " |----------|----------|----------|----------|\n");
766 fprintf(STDOUT, "0-60 sec | %8d | %8d | %8d | %8d |\n",
767 a_xInfoP->stat_fileSameAuthor[VOLINT_STATS_TIME_IDX_0],
768 a_xInfoP->stat_fileDiffAuthor[VOLINT_STATS_TIME_IDX_0],
769 a_xInfoP->stat_dirSameAuthor[VOLINT_STATS_TIME_IDX_0],
770 a_xInfoP->stat_dirDiffAuthor[VOLINT_STATS_TIME_IDX_0]);
771 fprintf(STDOUT, "1-10 min | %8d | %8d | %8d | %8d |\n",
772 a_xInfoP->stat_fileSameAuthor[VOLINT_STATS_TIME_IDX_1],
773 a_xInfoP->stat_fileDiffAuthor[VOLINT_STATS_TIME_IDX_1],
774 a_xInfoP->stat_dirSameAuthor[VOLINT_STATS_TIME_IDX_1],
775 a_xInfoP->stat_dirDiffAuthor[VOLINT_STATS_TIME_IDX_1]);
776 fprintf(STDOUT, "10min-1hr | %8d | %8d | %8d | %8d |\n",
777 a_xInfoP->stat_fileSameAuthor[VOLINT_STATS_TIME_IDX_2],
778 a_xInfoP->stat_fileDiffAuthor[VOLINT_STATS_TIME_IDX_2],
779 a_xInfoP->stat_dirSameAuthor[VOLINT_STATS_TIME_IDX_2],
780 a_xInfoP->stat_dirDiffAuthor[VOLINT_STATS_TIME_IDX_2]);
781 fprintf(STDOUT, "1hr-1day | %8d | %8d | %8d | %8d |\n",
782 a_xInfoP->stat_fileSameAuthor[VOLINT_STATS_TIME_IDX_3],
783 a_xInfoP->stat_fileDiffAuthor[VOLINT_STATS_TIME_IDX_3],
784 a_xInfoP->stat_dirSameAuthor[VOLINT_STATS_TIME_IDX_3],
785 a_xInfoP->stat_dirDiffAuthor[VOLINT_STATS_TIME_IDX_3]);
786 fprintf(STDOUT, "1day-1wk | %8d | %8d | %8d | %8d |\n",
787 a_xInfoP->stat_fileSameAuthor[VOLINT_STATS_TIME_IDX_4],
788 a_xInfoP->stat_fileDiffAuthor[VOLINT_STATS_TIME_IDX_4],
789 a_xInfoP->stat_dirSameAuthor[VOLINT_STATS_TIME_IDX_4],
790 a_xInfoP->stat_dirDiffAuthor[VOLINT_STATS_TIME_IDX_4]);
791 fprintf(STDOUT, "> 1wk | %8d | %8d | %8d | %8d |\n",
792 a_xInfoP->stat_fileSameAuthor[VOLINT_STATS_TIME_IDX_5],
793 a_xInfoP->stat_fileDiffAuthor[VOLINT_STATS_TIME_IDX_5],
794 a_xInfoP->stat_dirSameAuthor[VOLINT_STATS_TIME_IDX_5],
795 a_xInfoP->stat_dirDiffAuthor[VOLINT_STATS_TIME_IDX_5]);
797 " |-------------------------------------------|\n");
798 } /*Volume status OK */
799 else if (a_xInfoP->status == VBUSY) {
801 qPut(&busyHead, a_xInfoP->volid);
803 fprintf(STDOUT, "**** Volume %lu is busy ****\n",
804 (unsigned long)a_xInfoP->volid);
808 qPut(¬okHead, a_xInfoP->volid);
810 fprintf(STDOUT, "**** Could not attach volume %lu ****\n",
811 (unsigned long)a_xInfoP->volid);
812 } /*Screwed volume */
813 fprintf(STDOUT, "\n");
819 if (a_xInfoP->status == VOK) {
820 fprintf(STDOUT, "%-32s ", a_xInfoP->name);
821 fprintf(STDOUT, "%10lu ", (unsigned long)a_xInfoP->volid);
822 if (a_xInfoP->type == 0)
823 fprintf(STDOUT, "RW ");
824 if (a_xInfoP->type == 1)
825 fprintf(STDOUT, "RO ");
826 if (a_xInfoP->type == 2)
827 fprintf(STDOUT, "BK ");
828 fprintf(STDOUT, "%10d K ", a_xInfoP->size);
829 if (a_xInfoP->inUse == 1) {
830 fprintf(STDOUT, "On-line");
833 fprintf(STDOUT, "Off-line");
836 fprintf(STDOUT, "\n");
838 else if (a_xInfoP->status == VBUSY) {
840 qPut(&busyHead, a_xInfoP->volid);
842 fprintf(STDOUT, "**** Volume %lu is busy ****\n",
843 (unsigned long)a_xInfoP->volid);
847 qPut(¬okHead, a_xInfoP->volid);
849 fprintf(STDOUT, "**** Could not attach volume %lu ****\n",
850 (unsigned long)a_xInfoP->volid);
851 } /*Screwed volume */
852 } /*Default listing */
853 } /*XDisplayFormat */
855 /*------------------------------------------------------------------------
856 * PRIVATE XDisplayFormat2
859 * Display the formated contents of one extended volume info structure.
862 * a_xInfoP : Ptr to extended volume info struct to print.
863 * a_servID : Server ID to print.
864 * a_partID : Partition ID to print.
865 * a_totalOKP : Ptr to total-OK counter.
866 * a_totalNotOKP : Ptr to total-screwed counter.
867 * a_totalBusyP : Ptr to total-busy counter.
868 * a_fast : Fast listing?
869 * a_int32 : Int32 listing?
870 * a_showProblems : Show volume problems?
876 * Nothing interesting.
880 *------------------------------------------------------------------------*/
883 XDisplayFormat2(volintXInfo *a_xInfoP, afs_uint32 a_servID, afs_int32 a_partID,
884 int *a_totalOKP, int *a_totalNotOKP, int *a_totalBusyP,
885 int a_fast, int a_int32, int a_showProblems)
886 { /*XDisplayFormat */
892 fprintf(STDOUT, "vold_id\t%-10lu\n", (unsigned long)a_xInfoP->volid);
893 } else if (a_int32) {
895 * Fully-detailed listing.
897 if (a_xInfoP->status == VOK) {
899 * Volume's status is OK - all the fields are valid.
902 static long server_cache = -1, partition_cache = -1;
903 static char hostname[256], address[32], pname[16];
904 int i,ai[] = {VOLINT_STATS_TIME_IDX_0,VOLINT_STATS_TIME_IDX_1,VOLINT_STATS_TIME_IDX_2,
905 VOLINT_STATS_TIME_IDX_3,VOLINT_STATS_TIME_IDX_4,VOLINT_STATS_TIME_IDX_5};
907 if (a_servID != server_cache) {
911 strcpy(hostname, hostutil_GetNameByINet(a_servID));
912 strcpy(address, inet_ntoa(s));
913 server_cache = a_servID;
915 if (a_partID != partition_cache) {
916 MapPartIdIntoName(a_partID, pname);
917 partition_cache = a_partID;
920 fprintf(STDOUT, "name\t\t%s\n", a_xInfoP->name);
921 fprintf(STDOUT, "id\t\t%lu\n", afs_printable_uint32_lu(a_xInfoP->volid));
922 fprintf(STDOUT, "serv\t\t%s\t%s\n", address, hostname);
923 fprintf(STDOUT, "part\t\t%s\n", pname);
924 fprintf(STDOUT, "status\t\tOK\n");
925 fprintf(STDOUT, "backupID\t%lu\n",
926 afs_printable_uint32_lu(a_xInfoP->backupID));
927 fprintf(STDOUT, "parentID\t%lu\n",
928 afs_printable_uint32_lu(a_xInfoP->parentID));
929 fprintf(STDOUT, "cloneID\t\t%lu\n",
930 afs_printable_uint32_lu(a_xInfoP->cloneID));
931 fprintf(STDOUT, "inUse\t\t%s\n", a_xInfoP->inUse ? "Y" : "N");
932 switch (a_xInfoP->type) {
934 fprintf(STDOUT, "type\t\tRW\n");
937 fprintf(STDOUT, "type\t\tRO\n");
940 fprintf(STDOUT, "type\t\tBK\n");
943 fprintf(STDOUT, "type\t\t?\n");
946 t = a_xInfoP->creationDate;
947 fprintf(STDOUT, "creationDate\t%-9lu\t%s",
948 afs_printable_uint32_lu(a_xInfoP->creationDate),
951 t = a_xInfoP->accessDate;
952 fprintf(STDOUT, "accessDate\t%-9lu\t%s",
953 afs_printable_uint32_lu(a_xInfoP->accessDate),
956 t = a_xInfoP->updateDate;
957 fprintf(STDOUT, "updateDate\t%-9lu\t%s",
958 afs_printable_uint32_lu(a_xInfoP->updateDate),
961 t = a_xInfoP->backupDate;
962 fprintf(STDOUT, "backupDate\t%-9lu\t%s",
963 afs_printable_uint32_lu(a_xInfoP->backupDate),
966 t = a_xInfoP->copyDate;
967 fprintf(STDOUT, "copyDate\t%-9lu\t%s",
968 afs_printable_uint32_lu(a_xInfoP->copyDate),
971 fprintf(STDOUT, "diskused\t%u\n", a_xInfoP->size);
972 fprintf(STDOUT, "maxquota\t%u\n", a_xInfoP->maxquota);
974 fprintf(STDOUT, "filecount\t%u\n", a_xInfoP->filecount);
975 fprintf(STDOUT, "dayUse\t\t%u\n", a_xInfoP->dayUse);
979 fprintf(STDOUT,"reads_same_net\t%8d\n",a_xInfoP->stat_reads[VOLINT_STATS_SAME_NET]);
980 fprintf(STDOUT,"reads_same_net_auth\t%8d\n",a_xInfoP->stat_reads[VOLINT_STATS_SAME_NET_AUTH]);
981 fprintf(STDOUT,"reads_diff_net\t%8d\n",a_xInfoP->stat_reads[VOLINT_STATS_DIFF_NET]);
982 fprintf(STDOUT,"reads_diff_net_auth\t%8d\n",a_xInfoP->stat_reads[VOLINT_STATS_DIFF_NET_AUTH]);
984 fprintf(STDOUT,"writes_same_net\t%8d\n",a_xInfoP->stat_writes[VOLINT_STATS_SAME_NET]);
985 fprintf(STDOUT,"writes_same_net_auth\t%8d\n",a_xInfoP->stat_writes[VOLINT_STATS_SAME_NET_AUTH]);
986 fprintf(STDOUT,"writes_diff_net\t%8d\n",a_xInfoP->stat_writes[VOLINT_STATS_DIFF_NET]);
987 fprintf(STDOUT,"writes_diff_net_auth\t%8d\n",a_xInfoP->stat_writes[VOLINT_STATS_DIFF_NET_AUTH]);
991 fprintf(STDOUT,"file_same_author_idx_%d\t%8d\n",i+1,a_xInfoP->stat_fileSameAuthor[ai[i]]);
992 fprintf(STDOUT,"file_diff_author_idx_%d\t%8d\n",i+1,a_xInfoP->stat_fileDiffAuthor[ai[i]]);
993 fprintf(STDOUT,"dir_same_author_idx_%d\t%8d\n",i+1,a_xInfoP->stat_dirSameAuthor[ai[i]]);
994 fprintf(STDOUT,"dir_dif_author_idx_%d\t%8d\n",i+1,a_xInfoP->stat_dirDiffAuthor[ai[i]]);
997 } /*Volume status OK */
998 else if (a_xInfoP->status == VBUSY) {
1000 qPut(&busyHead, a_xInfoP->volid);
1002 fprintf(STDOUT, "BUSY_VOL\t%lu\n",
1003 (unsigned long)a_xInfoP->volid);
1007 qPut(¬okHead, a_xInfoP->volid);
1009 fprintf(STDOUT, "COULD_NOT_ATTACH\t%lu\n",
1010 (unsigned long)a_xInfoP->volid);
1011 } /*Screwed volume */
1017 if (a_xInfoP->status == VOK) {
1018 fprintf(STDOUT, "name\t%-32s\n", a_xInfoP->name);
1019 fprintf(STDOUT, "volID\t%10lu\n", (unsigned long)a_xInfoP->volid);
1020 if (a_xInfoP->type == 0)
1021 fprintf(STDOUT, "type\tRW\n");
1022 if (a_xInfoP->type == 1)
1023 fprintf(STDOUT, "type\tRO\n");
1024 if (a_xInfoP->type == 2)
1025 fprintf(STDOUT, "type\tBK\n");
1026 fprintf(STDOUT, "size\t%10dK\n", a_xInfoP->size);
1028 fprintf(STDOUT, "inUse\t%d\n",a_xInfoP->inUse);
1029 if (a_xInfoP->inUse == 1)
1035 else if (a_xInfoP->status == VBUSY) {
1037 qPut(&busyHead, a_xInfoP->volid);
1039 fprintf(STDOUT, "VOLUME_BUSY\t%lu\n",
1040 (unsigned long)a_xInfoP->volid);
1044 qPut(¬okHead, a_xInfoP->volid);
1046 fprintf(STDOUT, "COULD_NOT_ATTACH_VOLUME\t%lu\n",
1047 (unsigned long)a_xInfoP->volid);
1048 } /*Screwed volume */
1049 } /*Default listing */
1050 } /*XDisplayFormat */
1053 DisplayFormat2(long server, long partition, volintInfo *pntr)
1055 static long server_cache = -1, partition_cache = -1;
1056 static char hostname[256], address[32], pname[16];
1059 if (server != server_cache) {
1063 strcpy(hostname, hostutil_GetNameByINet(server));
1064 strcpy(address, inet_ntoa(s));
1065 server_cache = server;
1067 if (partition != partition_cache) {
1068 MapPartIdIntoName(partition, pname);
1069 partition_cache = partition;
1072 if (pntr->status == VOK)
1073 fprintf(STDOUT, "name\t\t%s\n", pntr->name);
1075 fprintf(STDOUT, "id\t\t%lu\n",
1076 afs_printable_uint32_lu(pntr->volid));
1077 fprintf(STDOUT, "serv\t\t%s\t%s\n", address, hostname);
1078 fprintf(STDOUT, "part\t\t%s\n", pname);
1079 switch (pntr->status) {
1081 fprintf(STDOUT, "status\t\tOK\n");
1084 fprintf(STDOUT, "status\t\tBUSY\n");
1087 fprintf(STDOUT, "status\t\tUNATTACHABLE\n");
1090 fprintf(STDOUT, "backupID\t%lu\n",
1091 afs_printable_uint32_lu(pntr->backupID));
1092 fprintf(STDOUT, "parentID\t%lu\n",
1093 afs_printable_uint32_lu(pntr->parentID));
1094 fprintf(STDOUT, "cloneID\t\t%lu\n",
1095 afs_printable_uint32_lu(pntr->cloneID));
1096 fprintf(STDOUT, "inUse\t\t%s\n", pntr->inUse ? "Y" : "N");
1097 fprintf(STDOUT, "needsSalvaged\t%s\n", pntr->needsSalvaged ? "Y" : "N");
1098 /* 0xD3 is from afs/volume.h since I had trouble including the file */
1099 fprintf(STDOUT, "destroyMe\t%s\n", pntr->destroyMe == 0xD3 ? "Y" : "N");
1100 switch (pntr->type) {
1102 fprintf(STDOUT, "type\t\tRW\n");
1105 fprintf(STDOUT, "type\t\tRO\n");
1108 fprintf(STDOUT, "type\t\tBK\n");
1111 fprintf(STDOUT, "type\t\t?\n");
1114 t = pntr->creationDate;
1115 fprintf(STDOUT, "creationDate\t%-9lu\t%s",
1116 afs_printable_uint32_lu(pntr->creationDate),
1119 t = pntr->accessDate;
1120 fprintf(STDOUT, "accessDate\t%-9lu\t%s",
1121 afs_printable_uint32_lu(pntr->accessDate),
1124 t = pntr->updateDate;
1125 fprintf(STDOUT, "updateDate\t%-9lu\t%s",
1126 afs_printable_uint32_lu(pntr->updateDate),
1129 t = pntr->backupDate;
1130 fprintf(STDOUT, "backupDate\t%-9lu\t%s",
1131 afs_printable_uint32_lu(pntr->backupDate),
1135 fprintf(STDOUT, "copyDate\t%-9lu\t%s",
1136 afs_printable_uint32_lu(pntr->copyDate),
1139 fprintf(STDOUT, "flags\t\t%#lx\t(Optional)\n",
1140 afs_printable_uint32_lu(pntr->flags));
1141 fprintf(STDOUT, "diskused\t%u\n", pntr->size);
1142 fprintf(STDOUT, "maxquota\t%u\n", pntr->maxquota);
1143 fprintf(STDOUT, "minquota\t%lu\t(Optional)\n",
1144 afs_printable_uint32_lu(pntr->spare0));
1145 fprintf(STDOUT, "filecount\t%u\n", pntr->filecount);
1146 fprintf(STDOUT, "dayUse\t\t%u\n", pntr->dayUse);
1147 fprintf(STDOUT, "weekUse\t\t%lu\t(Optional)\n",
1148 afs_printable_uint32_lu(pntr->spare1));
1149 fprintf(STDOUT, "spare2\t\t%lu\t(Optional)\n",
1150 afs_printable_uint32_lu(pntr->spare2));
1151 fprintf(STDOUT, "spare3\t\t%lu\t(Optional)\n",
1152 afs_printable_uint32_lu(pntr->spare3));
1157 DisplayVolumes2(long server, long partition, volintInfo *pntr, long count)
1161 for (i = 0; i < count; i++) {
1162 fprintf(STDOUT, "BEGIN_OF_ENTRY\n");
1163 DisplayFormat2(server, partition, pntr);
1164 fprintf(STDOUT, "END_OF_ENTRY\n\n");
1171 DisplayVolumes(afs_uint32 server, afs_int32 part, volintInfo *pntr,
1172 afs_int32 count, afs_int32 longlist, afs_int32 fast,
1175 int totalOK, totalNotOK, totalBusy, i;
1176 afs_uint32 volid = 0;
1183 for (i = 0; i < count; i++) {
1184 DisplayFormat(pntr, server, part, &totalOK, &totalNotOK, &totalBusy,
1189 while (busyHead.count) {
1190 qGet(&busyHead, &volid);
1191 fprintf(STDOUT, "**** Volume %lu is busy ****\n",
1192 (unsigned long)volid);
1196 while (notokHead.count) {
1197 qGet(¬okHead, &volid);
1198 fprintf(STDOUT, "**** Could not attach volume %lu ****\n",
1199 (unsigned long)volid);
1203 fprintf(STDOUT, "\n");
1206 "Total volumes onLine %d ; Total volumes offLine %d ; Total busy %d\n\n",
1207 totalOK, totalNotOK, totalBusy);
1211 /*------------------------------------------------------------------------
1212 * PRIVATE XDisplayVolumes
1215 * Display extended volume information.
1218 * a_servID : Pointer to the Rx call we're performing.
1219 * a_partID : Partition for which we want the extended list.
1220 * a_xInfoP : Ptr to extended volume info.
1221 * a_count : Number of volume records contained above.
1222 * a_int32 : Int32 listing generated?
1223 * a_fast : Fast listing generated?
1224 * a_quiet : Quiet listing generated?
1230 * Nothing interesting.
1234 *------------------------------------------------------------------------*/
1237 XDisplayVolumes(afs_uint32 a_servID, afs_int32 a_partID, volintXInfo *a_xInfoP,
1238 afs_int32 a_count, afs_int32 a_int32, afs_int32 a_fast,
1240 { /*XDisplayVolumes */
1242 int totalOK; /*Total OK volumes */
1243 int totalNotOK; /*Total screwed volumes */
1244 int totalBusy; /*Total busy volumes */
1245 int i; /*Loop variable */
1246 afs_uint32 volid = 0; /*Current volume ID */
1249 * Initialize counters and (global!!) queues.
1258 * Display each volume in the list.
1260 for (i = 0; i < a_count; i++) {
1261 XDisplayFormat(a_xInfoP, a_servID, a_partID, &totalOK, &totalNotOK,
1262 &totalBusy, a_fast, a_int32, 0);
1267 * If any volumes were found to be busy or screwed, display them.
1270 while (busyHead.count) {
1271 qGet(&busyHead, &volid);
1272 fprintf(STDOUT, "**** Volume %lu is busy ****\n",
1273 (unsigned long)volid);
1277 while (notokHead.count) {
1278 qGet(¬okHead, &volid);
1279 fprintf(STDOUT, "**** Could not attach volume %lu ****\n",
1280 (unsigned long)volid);
1285 fprintf(STDOUT, "\n");
1288 "Total volumes: %d on-line, %d off-line, %d busyd\n\n",
1289 totalOK, totalNotOK, totalBusy);
1293 } /*XDisplayVolumes */
1295 /*------------------------------------------------------------------------
1296 * PRIVATE XDisplayVolumes2
1299 * Display extended formated volume information.
1302 * a_servID : Pointer to the Rx call we're performing.
1303 * a_partID : Partition for which we want the extended list.
1304 * a_xInfoP : Ptr to extended volume info.
1305 * a_count : Number of volume records contained above.
1306 * a_int32 : Int32 listing generated?
1307 * a_fast : Fast listing generated?
1308 * a_quiet : Quiet listing generated?
1314 * Nothing interesting.
1318 *------------------------------------------------------------------------*/
1321 XDisplayVolumes2(afs_uint32 a_servID, afs_int32 a_partID, volintXInfo *a_xInfoP,
1322 afs_int32 a_count, afs_int32 a_int32, afs_int32 a_fast,
1324 { /*XDisplayVolumes */
1326 int totalOK; /*Total OK volumes */
1327 int totalNotOK; /*Total screwed volumes */
1328 int totalBusy; /*Total busy volumes */
1329 int i; /*Loop variable */
1330 afs_uint32 volid = 0; /*Current volume ID */
1333 * Initialize counters and (global!!) queues.
1342 * Display each volume in the list.
1344 for (i = 0; i < a_count; i++) {
1345 fprintf(STDOUT, "BEGIN_OF_ENTRY\n");
1346 XDisplayFormat2(a_xInfoP, a_servID, a_partID, &totalOK, &totalNotOK,
1347 &totalBusy, a_fast, a_int32, 0);
1348 fprintf(STDOUT, "END_OF_ENTRY\n");
1353 * If any volumes were found to be busy or screwed, display them.
1356 while (busyHead.count) {
1357 qGet(&busyHead, &volid);
1358 fprintf(STDOUT, "BUSY_VOL\t%lu\n",
1359 (unsigned long)volid);
1363 while (notokHead.count) {
1364 qGet(¬okHead, &volid);
1365 fprintf(STDOUT, "COULD_NOT_ATTACH\t%lu\n",
1366 (unsigned long)volid);
1371 fprintf(STDOUT, "\n");
1374 "VOLUMES_ONLINE\t%d\nVOLUMES_OFFLINE\t%d\nVOLUMES_BUSY\t%d\n",
1375 totalOK, totalNotOK, totalBusy);
1379 } /*XDisplayVolumes2 */
1382 /* set <server> and <part> to the correct values depending on
1383 * <voltype> and <entry> */
1385 GetServerAndPart(struct uvldbentry *entry, int voltype, afs_uint32 *server,
1386 afs_int32 *part, int *previdx)
1388 int i, istart, vtype;
1393 /* Doesn't check for non-existance of backup volume */
1394 if ((voltype == RWVOL) || (voltype == BACKVOL)) {
1396 istart = 0; /* seach the entire entry */
1399 /* Seach from beginning of entry or pick up where we left off */
1400 istart = ((*previdx < 0) ? 0 : *previdx + 1);
1403 for (i = istart; i < entry->nServers && i < NMAXNSERVERS; i++) {
1404 if (entry->serverFlags[i] & vtype) {
1405 /* *uuid = entry->serverNumber[i]; */
1406 *server = entry->serverUnique[i];
1407 *part = entry->serverPartition[i];
1413 /* Didn't find any, return -1 */
1419 PrintLocked(afs_int32 aflags)
1421 afs_int32 flags = aflags & VLOP_ALLOPERS;
1424 fprintf(STDOUT, " Volume is currently LOCKED \n");
1426 if (flags & VLOP_MOVE) {
1427 fprintf(STDOUT, " Volume is locked for a move operation\n");
1429 if (flags & VLOP_RELEASE) {
1430 fprintf(STDOUT, " Volume is locked for a release operation\n");
1432 if (flags & VLOP_BACKUP) {
1433 fprintf(STDOUT, " Volume is locked for a backup operation\n");
1435 if (flags & VLOP_DELETE) {
1436 fprintf(STDOUT, " Volume is locked for a delete/misc operation\n");
1438 if (flags & VLOP_DUMP) {
1439 fprintf(STDOUT, " Volume is locked for a dump/restore operation\n");
1445 PostVolumeStats(struct uvldbentry *entry)
1447 SubEnumerateEntryU(entry);
1448 /* Check for VLOP_ALLOPERS */
1449 PrintLocked(entry->flags);
1453 /*------------------------------------------------------------------------
1454 * PRIVATE XVolumeStats
1457 * Display extended volume information.
1460 * a_xInfoP : Ptr to extended volume info.
1461 * a_entryP : Ptr to the volume's VLDB entry.
1462 * a_srvID : Server ID.
1463 * a_partID : Partition ID.
1464 * a_volType : Type of volume to print.
1470 * Nothing interesting.
1474 *------------------------------------------------------------------------*/
1477 XVolumeStats(volintXInfo *a_xInfoP, struct uvldbentry *a_entryP,
1478 afs_int32 a_srvID, afs_int32 a_partID, int a_volType)
1481 int totalOK, totalNotOK, totalBusy; /*Dummies - we don't really count here */
1483 XDisplayFormat(a_xInfoP, /*Ptr to extended volume info */
1484 a_srvID, /*Server ID to print */
1485 a_partID, /*Partition ID to print */
1486 &totalOK, /*Ptr to total-OK counter */
1487 &totalNotOK, /*Ptr to total-screwed counter */
1488 &totalBusy, /*Ptr to total-busy counter */
1489 0, /*Don't do a fast listing */
1490 1, /*Do a long listing */
1491 1); /*Show volume problems */
1497 VolumeStats_int(volintInfo *pntr, struct uvldbentry *entry, afs_uint32 server,
1498 afs_int32 part, int voltype)
1500 int totalOK, totalNotOK, totalBusy;
1502 DisplayFormat(pntr, server, part, &totalOK, &totalNotOK, &totalBusy, 0, 1,
1507 /* command to forcibly remove a volume */
1509 NukeVolume(struct cmd_syndesc *as)
1518 server = GetServer(tp = as->parms[0].items->data);
1520 fprintf(STDERR, "vos: server '%s' not found in host table\n", tp);
1524 partID = volutil_GetPartitionID(tp = as->parms[1].items->data);
1526 fprintf(STDERR, "vos: could not parse '%s' as a partition name", tp);
1530 volID = vsu_GetVolumeID(tp = as->parms[2].items->data, cstruct, &err);
1533 PrintError("", err);
1536 "vos: could not parse '%s' as a numeric volume ID", tp);
1541 "vos: forcibly removing all traces of volume %d, please wait...",
1544 code = UV_NukeVolume(server, partID, volID);
1546 fprintf(STDOUT, "done.\n");
1548 fprintf(STDOUT, "failed with code %d.\n", code);
1553 /*------------------------------------------------------------------------
1554 * PRIVATE ExamineVolume
1557 * Routine used to examine a single volume, contacting the VLDB as
1558 * well as the Volume Server.
1561 * as : Ptr to parsed command line arguments.
1564 * 0 for a successful operation,
1565 * Otherwise, one of the ubik or VolServer error values.
1568 * Nothing interesting.
1572 *------------------------------------------------------------------------
1575 ExamineVolume(struct cmd_syndesc *as, void *arock)
1577 struct uvldbentry entry;
1578 afs_int32 vcode = 0;
1579 volintInfo *pntr = (volintInfo *) 0;
1580 volintXInfo *xInfoP = (volintXInfo *) 0;
1582 afs_int32 code, err, error = 0;
1583 int voltype, foundserv = 0, foundentry = 0;
1587 int wantExtendedInfo; /*Do we want extended vol info? */
1588 int isSubEnum=0; /* Keep track whether sub enumerate called. */
1589 wantExtendedInfo = (as->parms[1].items ? 1 : 0); /* -extended */
1591 volid = vsu_GetVolumeID(as->parms[0].items->data, cstruct, &err); /* -id */
1594 PrintError("", err);
1596 fprintf(STDERR, "Unknown volume ID or name '%s'\n",
1597 as->parms[0].items->data);
1602 fprintf(STDOUT, "Fetching VLDB entry for %lu .. ",
1603 (unsigned long)volid);
1606 vcode = VLDB_GetEntryByIDU(volid, -1, &entry);
1609 "Could not fetch the entry for volume number %lu from VLDB \n",
1610 (unsigned long)volid);
1614 fprintf(STDOUT, "done\n");
1615 MapHostToNetworkU(&entry);
1617 if (entry.volumeId[RWVOL] == volid)
1619 else if (entry.volumeId[BACKVOL] == volid)
1621 else /* (entry.volumeId[ROVOL] == volid) */
1624 do { /* do {...} while (voltype == ROVOL) */
1625 /* Get the entry for the volume. If its a RW vol, get the RW entry.
1626 * It its a BK vol, get the RW entry (even if VLDB may say the BK doen't exist).
1627 * If its a RO vol, get the next RO entry.
1629 GetServerAndPart(&entry, ((voltype == ROVOL) ? ROVOL : RWVOL),
1630 &aserver, &apart, &previdx);
1631 if (previdx == -1) { /* searched all entries */
1633 fprintf(STDERR, "Volume %s does not exist in VLDB\n\n",
1634 as->parms[0].items->data);
1641 /* Get information about the volume from the server */
1643 fprintf(STDOUT, "Getting volume listing from the server %s .. ",
1644 hostutil_GetNameByINet(aserver));
1647 if (wantExtendedInfo)
1648 code = UV_XListOneVolume(aserver, apart, volid, &xInfoP);
1650 code = UV_ListOneVolume(aserver, apart, volid, &pntr);
1652 fprintf(STDOUT, "done\n");
1656 if (code == ENODEV) {
1657 if ((voltype == BACKVOL) && !(entry.flags & BACK_EXISTS)) {
1658 /* The VLDB says there is no backup volume and its not on disk */
1659 fprintf(STDERR, "Volume %s does not exist\n",
1660 as->parms[0].items->data);
1664 "Volume does not exist on server %s as indicated by the VLDB\n",
1665 hostutil_GetNameByINet(aserver));
1668 PrintDiagnostics("examine", code);
1670 fprintf(STDOUT, "\n");
1673 if (wantExtendedInfo)
1674 XVolumeStats(xInfoP, &entry, aserver, apart, voltype);
1675 else if (as->parms[2].items) {
1676 DisplayFormat2(aserver, apart, pntr);
1677 EnumerateEntryU(&entry);
1680 VolumeStats_int(pntr, &entry, aserver, apart, voltype);
1682 if ((voltype == BACKVOL) && !(entry.flags & BACK_EXISTS)) {
1683 /* The VLDB says there is no backup volume yet we found one on disk */
1684 fprintf(STDERR, "Volume %s does not exist in VLDB\n",
1685 as->parms[0].items->data);
1694 } while (voltype == ROVOL);
1697 fprintf(STDERR, "Dump only information from VLDB\n\n");
1698 fprintf(STDOUT, "%s \n", entry.name); /* PostVolumeStats doesn't print name */
1702 PostVolumeStats(&entry);
1707 /*------------------------------------------------------------------------
1711 * Routine used to change the status of a single volume.
1714 * as : Ptr to parsed command line arguments.
1717 * 0 for a successful operation,
1718 * Otherwise, one of the ubik or VolServer error values.
1721 * Nothing interesting.
1725 *------------------------------------------------------------------------
1728 SetFields(struct cmd_syndesc *as, void *arock)
1730 struct uvldbentry entry;
1733 afs_int32 code, err;
1738 volid = vsu_GetVolumeID(as->parms[0].items->data, cstruct, &err); /* -id */
1741 PrintError("", err);
1743 fprintf(STDERR, "Unknown volume ID or name '%s'\n",
1744 as->parms[0].items->data);
1748 code = VLDB_GetEntryByIDU(volid, RWVOL, &entry);
1751 "Could not fetch the entry for volume number %lu from VLDB \n",
1752 (unsigned long)volid);
1755 MapHostToNetworkU(&entry);
1757 GetServerAndPart(&entry, RWVOL, &aserver, &apart, &previdx);
1758 if (previdx == -1) {
1759 fprintf(STDERR, "Volume %s does not exist in VLDB\n\n",
1760 as->parms[0].items->data);
1764 init_volintInfo(&info);
1768 if (as->parms[1].items) {
1770 code = util_GetHumanInt32(as->parms[1].items->data, &info.maxquota);
1772 fprintf(STDERR, "invalid quota value\n");
1776 if (as->parms[2].items) {
1780 if (as->parms[3].items) {
1781 /* -clearVolUpCounter */
1784 code = UV_SetVolumeInfo(aserver, apart, volid, &info);
1787 "Could not update volume info fields for volume number %lu\n",
1788 (unsigned long)volid);
1792 /*------------------------------------------------------------------------
1796 * Brings a volume online.
1799 * as : Ptr to parsed command line arguments.
1802 * 0 for a successful operation,
1805 * Nothing interesting.
1809 *------------------------------------------------------------------------
1812 volOnline(struct cmd_syndesc *as, void *arock)
1815 afs_int32 partition;
1817 afs_int32 code, err = 0;
1819 server = GetServer(as->parms[0].items->data);
1821 fprintf(STDERR, "vos: server '%s' not found in host table\n",
1822 as->parms[0].items->data);
1826 partition = volutil_GetPartitionID(as->parms[1].items->data);
1827 if (partition < 0) {
1828 fprintf(STDERR, "vos: could not interpret partition name '%s'\n",
1829 as->parms[1].items->data);
1833 volid = vsu_GetVolumeID(as->parms[2].items->data, cstruct, &err); /* -id */
1836 PrintError("", err);
1838 fprintf(STDERR, "Unknown volume ID or name '%s'\n",
1839 as->parms[0].items->data);
1843 code = UV_SetVolume(server, partition, volid, ITOffline, 0 /*online */ ,
1846 fprintf(STDERR, "Failed to set volume. Code = %d\n", code);
1853 /*------------------------------------------------------------------------
1854 * PRIVATE volOffline
1857 * Brings a volume offline.
1860 * as : Ptr to parsed command line arguments.
1863 * 0 for a successful operation,
1866 * Nothing interesting.
1870 *------------------------------------------------------------------------
1873 volOffline(struct cmd_syndesc *as, void *arock)
1876 afs_int32 partition;
1878 afs_int32 code, err = 0;
1879 afs_int32 transflag, sleeptime, transdone;
1881 server = GetServer(as->parms[0].items->data);
1883 fprintf(STDERR, "vos: server '%s' not found in host table\n",
1884 as->parms[0].items->data);
1888 partition = volutil_GetPartitionID(as->parms[1].items->data);
1889 if (partition < 0) {
1890 fprintf(STDERR, "vos: could not interpret partition name '%s'\n",
1891 as->parms[1].items->data);
1895 volid = vsu_GetVolumeID(as->parms[2].items->data, cstruct, &err); /* -id */
1898 PrintError("", err);
1900 fprintf(STDERR, "Unknown volume ID or name '%s'\n",
1901 as->parms[0].items->data);
1905 transflag = (as->parms[4].items ? ITBusy : ITOffline);
1906 sleeptime = (as->parms[3].items ? atol(as->parms[3].items->data) : 0);
1907 transdone = (sleeptime ? 0 /*online */ : VTOutOfService);
1908 if (as->parms[4].items && !as->parms[3].items) {
1909 fprintf(STDERR, "-sleep option must be used with -busy flag\n");
1914 UV_SetVolume(server, partition, volid, transflag, transdone,
1917 fprintf(STDERR, "Failed to set volume. Code = %d\n", code);
1925 CreateVolume(struct cmd_syndesc *as, void *arock)
1929 afs_uint32 volid = 0, rovolid = 0, bkvolid = 0;
1930 afs_uint32 *arovolid;
1932 struct uvldbentry entry;
1936 arovolid = &rovolid;
1939 tserver = GetServer(as->parms[0].items->data);
1941 fprintf(STDERR, "vos: host '%s' not found in host table\n",
1942 as->parms[0].items->data);
1945 pnum = volutil_GetPartitionID(as->parms[1].items->data);
1947 fprintf(STDERR, "vos: could not interpret partition name '%s'\n",
1948 as->parms[1].items->data);
1951 if (!IsPartValid(pnum, tserver, &code)) { /*check for validity of the partition */
1953 PrintError("", code);
1956 "vos : partition %s does not exist on the server\n",
1957 as->parms[1].items->data);
1960 if (!ISNAMEVALID(as->parms[2].items->data)) {
1962 "vos: the name of the root volume %s exceeds the size limit of %d\n",
1963 as->parms[2].items->data, VOLSER_OLDMAXVOLNAME - 10);
1966 if (!VolNameOK(as->parms[2].items->data)) {
1968 "Illegal volume name %s, should not end in .readonly or .backup\n",
1969 as->parms[2].items->data);
1972 if (IsNumeric(as->parms[2].items->data)) {
1973 fprintf(STDERR, "Illegal volume name %s, should not be a number\n",
1974 as->parms[2].items->data);
1977 vcode = VLDB_GetEntryByNameU(as->parms[2].items->data, &entry);
1979 fprintf(STDERR, "Volume %s already exists\n",
1980 as->parms[2].items->data);
1981 PrintDiagnostics("create", code);
1985 if (as->parms[3].items) {
1986 code = util_GetHumanInt32(as->parms[3].items->data, "a);
1988 fprintf(STDERR, "vos: bad integer specified for quota.\n");
1993 if (as->parms[4].items) {
1994 if (!IsNumeric(as->parms[4].items->data)) {
1995 fprintf(STDERR, "vos: Given volume ID %s should be numeric.\n",
1996 as->parms[4].items->data);
2000 code = util_GetUInt32(as->parms[4].items->data, &volid);
2002 fprintf(STDERR, "vos: bad integer specified for volume ID.\n");
2007 if (as->parms[5].items) {
2008 if (!IsNumeric(as->parms[5].items->data)) {
2009 fprintf(STDERR, "vos: Given RO volume ID %s should be numeric.\n",
2010 as->parms[5].items->data);
2014 code = util_GetUInt32(as->parms[5].items->data, &rovolid);
2016 fprintf(STDERR, "vos: bad integer specified for volume ID.\n");
2026 UV_CreateVolume3(tserver, pnum, as->parms[2].items->data, quota, 0,
2027 0, 0, 0, &volid, arovolid, &bkvolid);
2029 PrintDiagnostics("create", code);
2032 MapPartIdIntoName(pnum, part);
2033 fprintf(STDOUT, "Volume %lu created on partition %s of %s\n",
2034 (unsigned long)volid, part, as->parms[0].items->data);
2041 DeleteAll(struct uvldbentry *entry)
2044 afs_int32 error, code, curserver, curpart;
2047 MapHostToNetworkU(entry);
2049 for (i = 0; i < entry->nServers; i++) {
2050 curserver = entry->serverUnique[i];
2051 curpart = entry->serverPartition[i];
2052 if (entry->serverFlags[i] & ITSROVOL) {
2053 volid = entry->volumeId[ROVOL];
2055 volid = entry->volumeId[RWVOL];
2057 code = UV_DeleteVolume(curserver, curpart, volid);
2066 DeleteVolume(struct cmd_syndesc *as, void *arock)
2068 afs_int32 err, code = 0;
2069 afs_uint32 server = 0;
2070 afs_int32 partition = -1;
2075 if (as->parms[0].items) {
2076 server = GetServer(as->parms[0].items->data);
2078 fprintf(STDERR, "vos: server '%s' not found in host table\n",
2079 as->parms[0].items->data);
2084 if (as->parms[1].items) {
2085 partition = volutil_GetPartitionID(as->parms[1].items->data);
2086 if (partition < 0) {
2087 fprintf(STDERR, "vos: could not interpret partition name '%s'\n",
2088 as->parms[1].items->data);
2092 /* Check for validity of the partition */
2093 if (!IsPartValid(partition, server, &code)) {
2095 PrintError("", code);
2098 "vos : partition %s does not exist on the server\n",
2099 as->parms[1].items->data);
2105 volid = vsu_GetVolumeID(as->parms[2].items->data, cstruct, &err);
2107 fprintf(STDERR, "Can't find volume name '%s' in VLDB\n",
2108 as->parms[2].items->data);
2110 PrintError("", err);
2114 /* If the server or partition option are not complete, try to fill
2115 * them in from the VLDB entry.
2117 if ((partition == -1) || !server) {
2118 struct uvldbentry entry;
2120 code = VLDB_GetEntryByIDU(volid, -1, &entry);
2123 "Could not fetch the entry for volume %lu from VLDB\n",
2124 (unsigned long)volid);
2125 PrintError("", code);
2129 if (((volid == entry.volumeId[RWVOL]) && (entry.flags & RW_EXISTS))
2130 || ((volid == entry.volumeId[BACKVOL])
2131 && (entry.flags & BACK_EXISTS))) {
2132 idx = Lp_GetRwIndexU(&entry);
2133 if ((idx == -1) || (server && (server != entry.serverUnique[idx]))
2134 || ((partition != -1)
2135 && (partition != entry.serverPartition[idx]))) {
2136 fprintf(STDERR, "VLDB: Volume '%s' no match\n",
2137 as->parms[2].items->data);
2140 } else if ((volid == entry.volumeId[ROVOL])
2141 && (entry.flags & RO_EXISTS)) {
2142 for (idx = -1, j = 0; j < entry.nServers; j++) {
2143 if (entry.serverFlags[j] != ITSROVOL)
2146 if (((server == 0) || (server == entry.serverUnique[j]))
2147 && ((partition == -1)
2148 || (partition == entry.serverPartition[j]))) {
2151 "VLDB: Volume '%s' matches more than one RO\n",
2152 as->parms[2].items->data);
2159 fprintf(STDERR, "VLDB: Volume '%s' no match\n",
2160 as->parms[2].items->data);
2164 fprintf(STDERR, "VLDB: Volume '%s' no match\n",
2165 as->parms[2].items->data);
2169 server = htonl(entry.serverUnique[idx]);
2170 partition = entry.serverPartition[idx];
2174 code = UV_DeleteVolume(server, partition, volid);
2176 PrintDiagnostics("remove", code);
2180 MapPartIdIntoName(partition, pname);
2181 fprintf(STDOUT, "Volume %lu on partition %s server %s deleted\n",
2182 (unsigned long)volid, pname, hostutil_GetNameByINet(server));
2186 #define TESTM 0 /* set for move space tests, clear for production */
2188 MoveVolume(struct cmd_syndesc *as, void *arock)
2192 afs_uint32 fromserver, toserver;
2193 afs_int32 frompart, topart;
2194 afs_int32 flags, code, err;
2195 char fromPartName[10], toPartName[10];
2197 struct diskPartition64 partition; /* for space check */
2200 volid = vsu_GetVolumeID(as->parms[0].items->data, cstruct, &err);
2203 PrintError("", err);
2205 fprintf(STDERR, "vos: can't find volume ID or name '%s'\n",
2206 as->parms[0].items->data);
2209 fromserver = GetServer(as->parms[1].items->data);
2210 if (fromserver == 0) {
2211 fprintf(STDERR, "vos: server '%s' not found in host table\n",
2212 as->parms[1].items->data);
2215 toserver = GetServer(as->parms[3].items->data);
2216 if (toserver == 0) {
2217 fprintf(STDERR, "vos: server '%s' not found in host table\n",
2218 as->parms[3].items->data);
2221 frompart = volutil_GetPartitionID(as->parms[2].items->data);
2223 fprintf(STDERR, "vos: could not interpret partition name '%s'\n",
2224 as->parms[2].items->data);
2227 if (!IsPartValid(frompart, fromserver, &code)) { /*check for validity of the partition */
2229 PrintError("", code);
2232 "vos : partition %s does not exist on the server\n",
2233 as->parms[2].items->data);
2236 topart = volutil_GetPartitionID(as->parms[4].items->data);
2238 fprintf(STDERR, "vos: could not interpret partition name '%s'\n",
2239 as->parms[4].items->data);
2242 if (!IsPartValid(topart, toserver, &code)) { /*check for validity of the partition */
2244 PrintError("", code);
2247 "vos : partition %s does not exist on the server\n",
2248 as->parms[4].items->data);
2253 if (as->parms[5].items) flags |= RV_NOCLONE;
2256 * check source partition for space to clone volume
2259 MapPartIdIntoName(topart, toPartName);
2260 MapPartIdIntoName(frompart, fromPartName);
2263 * check target partition for space to move volume
2266 code = UV_PartitionInfo64(toserver, toPartName, &partition);
2268 fprintf(STDERR, "vos: cannot access partition %s\n", toPartName);
2272 fprintf(STDOUT, "target partition %s free space %" AFS_INT64_FMT "\n", toPartName,
2275 p = (volintInfo *) 0;
2276 code = UV_ListOneVolume(fromserver, frompart, volid, &p);
2278 fprintf(STDERR, "vos:cannot access volume %lu\n",
2279 (unsigned long)volid);
2283 fprintf(STDOUT, "volume %lu size %d\n", (unsigned long)volid,
2285 if (partition.free <= p->size) {
2287 "vos: no space on target partition %s to move volume %lu\n",
2288 toPartName, (unsigned long)volid);
2295 fprintf(STDOUT, "size test - don't do move\n");
2299 /* successful move still not guaranteed but shoot for it */
2302 UV_MoveVolume2(volid, fromserver, frompart, toserver, topart, flags);
2304 PrintDiagnostics("move", code);
2307 MapPartIdIntoName(topart, toPartName);
2308 MapPartIdIntoName(frompart, fromPartName);
2309 fprintf(STDOUT, "Volume %lu moved from %s %s to %s %s \n",
2310 (unsigned long)volid, as->parms[1].items->data, fromPartName,
2311 as->parms[3].items->data, toPartName);
2317 CopyVolume(struct cmd_syndesc *as, void *arock)
2320 afs_uint32 fromserver, toserver;
2321 afs_int32 frompart, topart, code, err, flags;
2322 char fromPartName[10], toPartName[10], *tovolume;
2323 struct uvldbentry entry;
2324 struct diskPartition64 partition; /* for space check */
2327 volid = vsu_GetVolumeID(as->parms[0].items->data, cstruct, &err);
2330 PrintError("", err);
2332 fprintf(STDERR, "vos: can't find volume ID or name '%s'\n",
2333 as->parms[0].items->data);
2336 fromserver = GetServer(as->parms[1].items->data);
2337 if (fromserver == 0) {
2338 fprintf(STDERR, "vos: server '%s' not found in host table\n",
2339 as->parms[1].items->data);
2343 toserver = GetServer(as->parms[4].items->data);
2344 if (toserver == 0) {
2345 fprintf(STDERR, "vos: server '%s' not found in host table\n",
2346 as->parms[4].items->data);
2350 tovolume = as->parms[3].items->data;
2351 if (!ISNAMEVALID(tovolume)) {
2353 "vos: the name of the root volume %s exceeds the size limit of %d\n",
2354 tovolume, VOLSER_OLDMAXVOLNAME - 10);
2357 if (!VolNameOK(tovolume)) {
2359 "Illegal volume name %s, should not end in .readonly or .backup\n",
2363 if (IsNumeric(tovolume)) {
2364 fprintf(STDERR, "Illegal volume name %s, should not be a number\n",
2368 code = VLDB_GetEntryByNameU(tovolume, &entry);
2370 fprintf(STDERR, "Volume %s already exists\n", tovolume);
2371 PrintDiagnostics("copy", code);
2375 frompart = volutil_GetPartitionID(as->parms[2].items->data);
2377 fprintf(STDERR, "vos: could not interpret partition name '%s'\n",
2378 as->parms[2].items->data);
2381 if (!IsPartValid(frompart, fromserver, &code)) { /*check for validity of the partition */
2383 PrintError("", code);
2386 "vos : partition %s does not exist on the server\n",
2387 as->parms[2].items->data);
2391 topart = volutil_GetPartitionID(as->parms[5].items->data);
2393 fprintf(STDERR, "vos: could not interpret partition name '%s'\n",
2394 as->parms[5].items->data);
2397 if (!IsPartValid(topart, toserver, &code)) { /*check for validity of the partition */
2399 PrintError("", code);
2402 "vos : partition %s does not exist on the server\n",
2403 as->parms[5].items->data);
2408 if (as->parms[6].items) flags |= RV_OFFLINE;
2409 if (as->parms[7].items) flags |= RV_RDONLY;
2410 if (as->parms[8].items) flags |= RV_NOCLONE;
2412 MapPartIdIntoName(topart, toPartName);
2413 MapPartIdIntoName(frompart, fromPartName);
2416 * check target partition for space to move volume
2419 code = UV_PartitionInfo64(toserver, toPartName, &partition);
2421 fprintf(STDERR, "vos: cannot access partition %s\n", toPartName);
2425 fprintf(STDOUT, "target partition %s free space %" AFS_INT64_FMT "\n", toPartName,
2428 p = (volintInfo *) 0;
2429 code = UV_ListOneVolume(fromserver, frompart, volid, &p);
2431 fprintf(STDERR, "vos:cannot access volume %lu\n",
2432 (unsigned long)volid);
2436 if (partition.free <= p->size) {
2438 "vos: no space on target partition %s to copy volume %lu\n",
2439 toPartName, (unsigned long)volid);
2445 /* successful copy still not guaranteed but shoot for it */
2448 UV_CopyVolume2(volid, fromserver, frompart, tovolume, toserver,
2451 PrintDiagnostics("copy", code);
2454 MapPartIdIntoName(topart, toPartName);
2455 MapPartIdIntoName(frompart, fromPartName);
2456 fprintf(STDOUT, "Volume %lu copied from %s %s to %s on %s %s \n",
2457 (unsigned long)volid, as->parms[1].items->data, fromPartName,
2458 tovolume, as->parms[4].items->data, toPartName);
2465 ShadowVolume(struct cmd_syndesc *as, void *arock)
2467 afs_uint32 volid, tovolid;
2468 afs_uint32 fromserver, toserver;
2469 afs_int32 frompart, topart;
2470 afs_int32 code, err, flags;
2471 char fromPartName[10], toPartName[10], toVolName[32], *tovolume;
2472 struct diskPartition64 partition; /* for space check */
2475 p = (volintInfo *) 0;
2476 q = (volintInfo *) 0;
2478 volid = vsu_GetVolumeID(as->parms[0].items->data, cstruct, &err);
2481 PrintError("", err);
2483 fprintf(STDERR, "vos: can't find volume ID or name '%s'\n",
2484 as->parms[0].items->data);
2487 fromserver = GetServer(as->parms[1].items->data);
2488 if (fromserver == 0) {
2489 fprintf(STDERR, "vos: server '%s' not found in host table\n",
2490 as->parms[1].items->data);
2494 toserver = GetServer(as->parms[3].items->data);
2495 if (toserver == 0) {
2496 fprintf(STDERR, "vos: server '%s' not found in host table\n",
2497 as->parms[3].items->data);
2501 frompart = volutil_GetPartitionID(as->parms[2].items->data);
2503 fprintf(STDERR, "vos: could not interpret partition name '%s'\n",
2504 as->parms[2].items->data);
2507 if (!IsPartValid(frompart, fromserver, &code)) { /*check for validity of the partition */
2509 PrintError("", code);
2512 "vos : partition %s does not exist on the server\n",
2513 as->parms[2].items->data);
2517 topart = volutil_GetPartitionID(as->parms[4].items->data);
2519 fprintf(STDERR, "vos: could not interpret partition name '%s'\n",
2520 as->parms[4].items->data);
2523 if (!IsPartValid(topart, toserver, &code)) { /*check for validity of the partition */
2525 PrintError("", code);
2528 "vos : partition %s does not exist on the server\n",
2529 as->parms[4].items->data);
2533 if (as->parms[5].items) {
2534 tovolume = as->parms[5].items->data;
2535 if (!ISNAMEVALID(tovolume)) {
2537 "vos: the name of the root volume %s exceeds the size limit of %d\n",
2538 tovolume, VOLSER_OLDMAXVOLNAME - 10);
2541 if (!VolNameOK(tovolume)) {
2543 "Illegal volume name %s, should not end in .readonly or .backup\n",
2547 if (IsNumeric(tovolume)) {
2549 "Illegal volume name %s, should not be a number\n",
2554 /* use actual name of source volume */
2555 code = UV_ListOneVolume(fromserver, frompart, volid, &p);
2557 fprintf(STDERR, "vos:cannot access volume %lu\n",
2558 (unsigned long)volid);
2561 strcpy(toVolName, p->name);
2562 tovolume = toVolName;
2563 /* save p for size checks later */
2566 if (as->parms[6].items) {
2567 tovolid = vsu_GetVolumeID(as->parms[6].items->data, cstruct, &err);
2570 PrintError("", err);
2572 fprintf(STDERR, "vos: can't find volume ID or name '%s'\n",
2573 as->parms[6].items->data);
2579 tovolid = vsu_GetVolumeID(tovolume, cstruct, &err);
2582 PrintError("", err);
2584 fprintf(STDERR, "vos: can't find volume ID or name '%s'\n",
2593 if (as->parms[7].items) flags |= RV_OFFLINE;
2594 if (as->parms[8].items) flags |= RV_RDONLY;
2595 if (as->parms[9].items) flags |= RV_NOCLONE;
2596 if (as->parms[10].items) flags |= RV_CPINCR;
2598 MapPartIdIntoName(topart, toPartName);
2599 MapPartIdIntoName(frompart, fromPartName);
2602 * check target partition for space to move volume
2605 code = UV_PartitionInfo64(toserver, toPartName, &partition);
2607 fprintf(STDERR, "vos: cannot access partition %s\n", toPartName);
2611 fprintf(STDOUT, "target partition %s free space %" AFS_INT64_FMT "\n", toPartName,
2614 /* Don't do this again if we did it above */
2616 code = UV_ListOneVolume(fromserver, frompart, volid, &p);
2618 fprintf(STDERR, "vos:cannot access volume %lu\n",
2619 (unsigned long)volid);
2624 /* OK if this fails */
2625 code = UV_ListOneVolume(toserver, topart, tovolid, &q);
2627 /* Treat existing volume size as "free" */
2629 p->size = (q->size < p->size) ? p->size - q->size : 0;
2631 if (partition.free <= p->size) {
2633 "vos: no space on target partition %s to copy volume %lu\n",
2634 toPartName, (unsigned long)volid);
2642 /* successful copy still not guaranteed but shoot for it */
2645 UV_CopyVolume2(volid, fromserver, frompart, tovolume, toserver,
2646 topart, tovolid, flags);
2648 PrintDiagnostics("shadow", code);
2651 MapPartIdIntoName(topart, toPartName);
2652 MapPartIdIntoName(frompart, fromPartName);
2653 fprintf(STDOUT, "Volume %lu shadowed from %s %s to %s %s \n",
2654 (unsigned long)volid, as->parms[1].items->data, fromPartName,
2655 as->parms[3].items->data, toPartName);
2662 CloneVolume(struct cmd_syndesc *as, void *arock)
2664 afs_uint32 volid, cloneid;
2666 afs_int32 part, voltype;
2667 char partName[10], *volname;
2668 afs_int32 code, err, flags;
2669 struct uvldbentry entry;
2671 volid = vsu_GetVolumeID(as->parms[0].items->data, cstruct, &err);
2674 PrintError("", err);
2676 fprintf(STDERR, "vos: can't find volume ID or name '%s'\n",
2677 as->parms[0].items->data);
2681 if (as->parms[1].items || as->parms[2].items) {
2682 if (!as->parms[1].items || !as->parms[2].items) {
2684 "Must specify both -server and -partition options\n");
2687 server = GetServer(as->parms[1].items->data);
2689 fprintf(STDERR, "vos: server '%s' not found in host table\n",
2690 as->parms[1].items->data);
2693 part = volutil_GetPartitionID(as->parms[2].items->data);
2695 fprintf(STDERR, "vos: could not interpret partition name '%s'\n",
2696 as->parms[2].items->data);
2699 if (!IsPartValid(part, server, &code)) { /*check for validity of the partition */
2701 PrintError("", code);
2704 "vos : partition %s does not exist on the server\n",
2705 as->parms[2].items->data);
2709 code = GetVolumeInfo(volid, &server, &part, &voltype, &entry);
2715 if (as->parms[3].items) {
2716 volname = as->parms[3].items->data;
2717 if (strlen(volname) > VOLSER_OLDMAXVOLNAME - 1) {
2719 "vos: the name of the root volume %s exceeds the size limit of %d\n",
2720 volname, VOLSER_OLDMAXVOLNAME - 1);
2725 * In order that you be able to make clones of RO or BK, this
2726 * check must be omitted.
2728 if (!VolNameOK(volname)) {
2730 "Illegal volume name %s, should not end in .readonly or .backup\n",
2735 if (IsNumeric(volname)) {
2737 "Illegal volume name %s, should not be a number\n",
2744 if (as->parms[4].items) {
2745 cloneid = vsu_GetVolumeID(as->parms[4].items->data, cstruct, &err);
2748 PrintError("", err);
2750 fprintf(STDERR, "vos: can't find volume ID or name '%s'\n",
2751 as->parms[4].items->data);
2757 if (as->parms[5].items) flags |= RV_OFFLINE;
2758 if (as->parms[6].items) flags |= RV_RDONLY;
2762 UV_CloneVolume(server, part, volid, cloneid, volname, flags);
2765 PrintDiagnostics("clone", code);
2768 MapPartIdIntoName(part, partName);
2769 fprintf(STDOUT, "Created clone for volume %s\n",
2770 as->parms[0].items->data);
2777 BackupVolume(struct cmd_syndesc *as, void *arock)
2781 afs_int32 apart, vtype, code, err;
2782 struct uvldbentry entry;
2785 afs_uint32 buserver;
2786 afs_int32 bupart, butype;
2787 struct uvldbentry buentry;
2789 avolid = vsu_GetVolumeID(as->parms[0].items->data, cstruct, &err);
2792 PrintError("", err);
2794 fprintf(STDERR, "vos: can't find volume ID or name '%s'\n",
2795 as->parms[0].items->data);
2798 code = GetVolumeInfo(avolid, &aserver, &apart, &vtype, &entry);
2802 /* verify this is a readwrite volume */
2804 if (vtype != RWVOL) {
2805 fprintf(STDERR, "%s not RW volume\n", as->parms[0].items->data);
2809 /* is there a backup volume already? */
2811 if (entry.flags & BACK_EXISTS) {
2812 /* yep, where is it? */
2814 buvolid = entry.volumeId[BACKVOL];
2815 code = GetVolumeInfo(buvolid, &buserver, &bupart, &butype, &buentry);
2820 code = VLDB_IsSameAddrs(buserver, aserver, &err);
2823 "Failed to get info about server's %d address(es) from vlserver; aborting call!\n",
2829 "FATAL ERROR: backup volume %lu exists on server %lu\n",
2830 (unsigned long)buvolid, (unsigned long)buserver);
2835 /* nope, carry on */
2837 code = UV_BackupVolume(aserver, apart, avolid);
2840 PrintDiagnostics("backup", code);
2843 fprintf(STDOUT, "Created backup volume for %s \n",
2844 as->parms[0].items->data);
2849 ReleaseVolume(struct cmd_syndesc *as, void *arock)
2852 struct uvldbentry entry;
2855 afs_int32 apart, vtype, code, err;
2858 if (as->parms[1].items)
2860 avolid = vsu_GetVolumeID(as->parms[0].items->data, cstruct, &err);
2863 PrintError("", err);
2865 fprintf(STDERR, "vos: can't find volume '%s'\n",
2866 as->parms[0].items->data);
2869 code = GetVolumeInfo(avolid, &aserver, &apart, &vtype, &entry);
2873 if (vtype != RWVOL) {
2874 fprintf(STDERR, "%s not a RW volume\n", as->parms[0].items->data);
2878 if (!ISNAMEVALID(entry.name)) {
2880 "Volume name %s is too long, rename before releasing\n",
2885 code = UV_ReleaseVolume(avolid, aserver, apart, force);
2887 PrintDiagnostics("release", code);
2890 fprintf(STDOUT, "Released volume %s successfully\n",
2891 as->parms[0].items->data);
2896 DumpVolumeCmd(struct cmd_syndesc *as, void *arock)
2900 afs_int32 apart, voltype, fromdate = 0, code, err, i, flags;
2901 char filename[MAXPATHLEN];
2902 struct uvldbentry entry;
2904 rx_SetRxDeadTime(60 * 10);
2905 for (i = 0; i < MAXSERVERS; i++) {
2906 struct rx_connection *rxConn = ubik_GetRPCConn(cstruct, i);
2909 rx_SetConnDeadTime(rxConn, rx_connDeadTime);
2910 if (rxConn->service)
2911 rxConn->service->connDeadTime = rx_connDeadTime;
2914 avolid = vsu_GetVolumeID(as->parms[0].items->data, cstruct, &err);
2917 PrintError("", err);
2919 fprintf(STDERR, "vos: can't find volume '%s'\n",
2920 as->parms[0].items->data);
2924 if (as->parms[3].items || as->parms[4].items) {
2925 if (!as->parms[3].items || !as->parms[4].items) {
2927 "Must specify both -server and -partition options\n");
2930 aserver = GetServer(as->parms[3].items->data);
2932 fprintf(STDERR, "Invalid server name\n");
2935 apart = volutil_GetPartitionID(as->parms[4].items->data);
2937 fprintf(STDERR, "Invalid partition name\n");
2941 code = GetVolumeInfo(avolid, &aserver, &apart, &voltype, &entry);
2946 if (as->parms[1].items && strcmp(as->parms[1].items->data, "0")) {
2947 code = ktime_DateToInt32(as->parms[1].items->data, &fromdate);
2949 fprintf(STDERR, "vos: failed to parse date '%s' (error=%d))\n",
2950 as->parms[1].items->data, code);
2954 if (as->parms[2].items) {
2955 strcpy(filename, as->parms[2].items->data);
2957 strcpy(filename, "");
2960 flags = as->parms[6].items ? VOLDUMPV2_OMITDIRS : 0;
2962 if (as->parms[5].items) {
2964 UV_DumpClonedVolume(avolid, aserver, apart, fromdate,
2965 DumpFunction, filename, flags);
2968 UV_DumpVolume(avolid, aserver, apart, fromdate, DumpFunction,
2971 if ((code == RXGEN_OPCODE) && (as->parms[6].items)) {
2972 flags &= ~VOLDUMPV2_OMITDIRS;
2976 PrintDiagnostics("dump", code);
2979 if (strcmp(filename, ""))
2980 fprintf(STDERR, "Dumped volume %s in file %s\n",
2981 as->parms[0].items->data, filename);
2983 fprintf(STDERR, "Dumped volume %s in stdout \n",
2984 as->parms[0].items->data);
2998 RestoreVolumeCmd(struct cmd_syndesc *as, void *arock)
3000 afs_uint32 avolid, aparentid;
3002 afs_int32 apart, code, vcode, err;
3003 afs_int32 aoverwrite = ASK;
3004 afs_int32 acreation = 0, alastupdate = 0;
3005 int restoreflags = 0;
3006 int readonly = 0, offline = 0, voltype = RWVOL;
3007 char afilename[MAXPATHLEN], avolname[VOLSER_MAXVOLNAME + 1], apartName[10];
3008 char volname[VOLSER_MAXVOLNAME + 1];
3009 struct uvldbentry entry;
3012 if (as->parms[4].items) {
3013 avolid = vsu_GetVolumeID(as->parms[4].items->data, cstruct, &err);
3016 PrintError("", err);
3018 fprintf(STDERR, "vos: can't find volume '%s'\n",
3019 as->parms[4].items->data);
3025 if (as->parms[5].items) {
3026 if ((strcmp(as->parms[5].items->data, "a") == 0)
3027 || (strcmp(as->parms[5].items->data, "abort") == 0)) {
3029 } else if ((strcmp(as->parms[5].items->data, "f") == 0)
3030 || (strcmp(as->parms[5].items->data, "full") == 0)) {
3032 } else if ((strcmp(as->parms[5].items->data, "i") == 0)
3033 || (strcmp(as->parms[5].items->data, "inc") == 0)
3034 || (strcmp(as->parms[5].items->data, "increment") == 0)
3035 || (strcmp(as->parms[5].items->data, "incremental") == 0)) {
3038 fprintf(STDERR, "vos: %s is not a valid argument to -overwrite\n",
3039 as->parms[5].items->data);
3043 if (as->parms[6].items)
3045 if (as->parms[7].items) {
3050 if (as->parms[8].items) {
3051 if ((strcmp(as->parms[8].items->data, "d") == 0)
3052 || (strcmp(as->parms[8].items->data, "dump") == 0)) {
3053 acreation = TS_DUMP;
3054 } else if ((strcmp(as->parms[8].items->data, "k") == 0)
3055 || (strcmp(as->parms[8].items->data, "keep") == 0)) {
3056 acreation = TS_KEEP;
3057 } else if ((strcmp(as->parms[8].items->data, "n") == 0)
3058 || (strcmp(as->parms[8].items->data, "new") == 0)) {
3061 fprintf(STDERR, "vos: %s is not a valid argument to -creation\n",
3062 as->parms[8].items->data);
3067 if (as->parms[9].items) {
3068 if ((strcmp(as->parms[9].items->data, "d") == 0)
3069 || (strcmp(as->parms[9].items->data, "dump") == 0)) {
3070 alastupdate = TS_DUMP;
3071 } else if ((strcmp(as->parms[9].items->data, "k") == 0)
3072 || (strcmp(as->parms[9].items->data, "keep") == 0)) {
3073 alastupdate = TS_KEEP;
3074 } else if ((strcmp(as->parms[9].items->data, "n") == 0)
3075 || (strcmp(as->parms[9].items->data, "new") == 0)) {
3076 alastupdate = TS_NEW;
3078 fprintf(STDERR, "vos: %s is not a valid argument to -lastupdate\n",
3079 as->parms[9].items->data);
3084 aserver = GetServer(as->parms[0].items->data);
3086 fprintf(STDERR, "vos: server '%s' not found in host table\n",
3087 as->parms[0].items->data);
3090 apart = volutil_GetPartitionID(as->parms[1].items->data);
3092 fprintf(STDERR, "vos: could not interpret partition name '%s'\n",
3093 as->parms[1].items->data);
3096 if (!IsPartValid(apart, aserver, &code)) { /*check for validity of the partition */
3098 PrintError("", code);
3101 "vos : partition %s does not exist on the server\n",
3102 as->parms[1].items->data);
3105 strcpy(avolname, as->parms[2].items->data);
3106 if (!ISNAMEVALID(avolname)) {
3108 "vos: the name of the volume %s exceeds the size limit\n",
3112 if (!VolNameOK(avolname)) {
3114 "Illegal volume name %s, should not end in .readonly or .backup\n",
3118 if (as->parms[3].items) {
3119 strcpy(afilename, as->parms[3].items->data);
3120 if (!FileExists(afilename)) {
3121 fprintf(STDERR, "Can't access file %s\n", afilename);
3125 strcpy(afilename, "");
3128 /* Check if volume exists or not */
3130 vsu_ExtractName(volname, avolname);
3131 vcode = VLDB_GetEntryByNameU(volname, &entry);
3132 if (vcode) { /* no volume - do a full restore */
3133 restoreflags = RV_FULLRST;
3134 if ((aoverwrite == INC) || (aoverwrite == ABORT))
3136 "Volume does not exist; Will perform a full restore\n");
3139 else if ((!readonly && Lp_GetRwIndexU(&entry) == -1) /* RW volume does not exist - do a full */
3140 ||(readonly && !Lp_ROMatchU(0, 0, &entry))) { /* RO volume does not exist - do a full */
3141 restoreflags = RV_FULLRST;
3142 if ((aoverwrite == INC) || (aoverwrite == ABORT))
3144 "%s Volume does not exist; Will perform a full restore\n",
3145 readonly ? "RO" : "RW");
3148 avolid = entry.volumeId[voltype];
3149 } else if (entry.volumeId[voltype] != 0
3150 && entry.volumeId[voltype] != avolid) {
3151 avolid = entry.volumeId[voltype];
3153 aparentid = entry.volumeId[RWVOL];
3156 else { /* volume exists - do we do a full incremental or abort */
3158 afs_int32 Opart, Otype, vol_elsewhere = 0;
3159 struct uvldbentry Oentry;
3163 avolid = entry.volumeId[voltype];
3164 } else if (entry.volumeId[voltype] != 0
3165 && entry.volumeId[voltype] != avolid) {
3166 avolid = entry.volumeId[voltype];
3168 aparentid = entry.volumeId[RWVOL];
3170 /* A file name was specified - check if volume is on another partition */
3171 vcode = GetVolumeInfo(avolid, &Oserver, &Opart, &Otype, &Oentry);
3175 vcode = VLDB_IsSameAddrs(Oserver, aserver, &err);
3178 "Failed to get info about server's %d address(es) from vlserver (err=%d); aborting call!\n",
3182 if (!vcode || (Opart != apart))
3185 if (aoverwrite == ASK) {
3186 if (strcmp(afilename, "") == 0) { /* The file is from standard in */
3188 "Volume exists and no -overwrite option specified; Aborting restore command\n");
3192 /* Ask what to do */
3193 if (vol_elsewhere) {
3195 "The volume %s %u already exists on a different server/part\n",
3196 volname, entry.volumeId[voltype]);
3198 "Do you want to do a full restore or abort? [fa](a): ");
3201 "The volume %s %u already exists in the VLDB\n",
3202 volname, entry.volumeId[voltype]);
3204 "Do you want to do a full/incremental restore or abort? [fia](a): ");
3207 while (!(dc == EOF || dc == '\n'))
3208 dc = getchar(); /* goto end of line */
3209 if ((c == 'f') || (c == 'F'))
3211 else if ((c == 'i') || (c == 'I'))
3217 if (aoverwrite == ABORT) {
3218 fprintf(STDERR, "Volume exists; Aborting restore command\n");
3220 } else if (aoverwrite == FULL) {
3221 restoreflags = RV_FULLRST;
3223 "Volume exists; Will delete and perform full restore\n");
3224 } else if (aoverwrite == INC) {
3226 if (vol_elsewhere) {
3228 "%s volume %lu already exists on a different server/part; not allowed\n",
3229 readonly ? "RO" : "RW", (unsigned long)avolid);
3235 restoreflags |= RV_OFFLINE;
3237 restoreflags |= RV_RDONLY;
3239 switch (acreation) {
3241 restoreflags |= RV_CRDUMP;
3244 restoreflags |= RV_CRKEEP;
3247 restoreflags |= RV_CRNEW;
3250 if (aoverwrite == FULL)
3251 restoreflags |= RV_CRNEW;
3253 restoreflags |= RV_CRKEEP;
3256 switch (alastupdate) {
3258 restoreflags |= RV_LUDUMP;
3261 restoreflags |= RV_LUKEEP;
3264 restoreflags |= RV_LUNEW;
3267 restoreflags |= RV_LUDUMP;
3269 if (as->parms[10].items) {
3270 restoreflags |= RV_NODEL;
3275 UV_RestoreVolume2(aserver, apart, avolid, aparentid,
3276 avolname, restoreflags, WriteData, afilename);
3278 PrintDiagnostics("restore", code);
3281 MapPartIdIntoName(apart, apartName);
3284 * patch typo here - originally "parms[1]", should be "parms[0]"
3287 fprintf(STDOUT, "Restored volume %s on %s %s\n", avolname,
3288 as->parms[0].items->data, apartName);
3293 LockReleaseCmd(struct cmd_syndesc *as, void *arock)
3296 afs_int32 code, err;
3298 avolid = vsu_GetVolumeID(as->parms[0].items->data, cstruct, &err);
3301 PrintError("", err);
3303 fprintf(STDERR, "vos: can't find volume '%s'\n",
3304 as->parms[0].items->data);
3308 code = UV_LockRelease(avolid);
3310 PrintDiagnostics("unlock", code);
3313 fprintf(STDOUT, "Released lock on vldb entry for volume %s\n",
3314 as->parms[0].items->data);
3319 AddSite(struct cmd_syndesc *as, void *arock)
3323 afs_int32 apart, code, err, arovolid, valid = 0;
3324 char apartName[10], avolname[VOLSER_MAXVOLNAME + 1];
3326 vsu_ExtractName(avolname, as->parms[2].items->data);;
3327 avolid = vsu_GetVolumeID(avolname, cstruct, &err);
3330 PrintError("", err);
3332 fprintf(STDERR, "vos: can't find volume '%s'\n",
3333 as->parms[2].items->data);
3337 if (as->parms[3].items) {
3338 vsu_ExtractName(avolname, as->parms[3].items->data);
3339 arovolid = vsu_GetVolumeID(avolname, cstruct, &err);
3341 fprintf(STDERR, "vos: invalid ro volume id '%s'\n",
3342 as->parms[3].items->data);
3346 aserver = GetServer(as->parms[0].items->data);
3348 fprintf(STDERR, "vos: server '%s' not found in host table\n",
3349 as->parms[0].items->data);
3352 apart = volutil_GetPartitionID(as->parms[1].items->data);
3354 fprintf(STDERR, "vos: could not interpret partition name '%s'\n",
3355 as->parms[1].items->data);
3358 if (!IsPartValid(apart, aserver, &code)) { /*check for validity of the partition */
3360 PrintError("", code);
3363 "vos : partition %s does not exist on the server\n",
3364 as->parms[1].items->data);
3367 if (as->parms[4].items) {
3370 code = UV_AddSite2(aserver, apart, avolid, arovolid, valid);
3372 PrintDiagnostics("addsite", code);
3375 MapPartIdIntoName(apart, apartName);
3376 fprintf(STDOUT, "Added replication site %s %s for volume %s\n",
3377 as->parms[0].items->data, apartName, as->parms[2].items->data);
3382 RemoveSite(struct cmd_syndesc *as, void *arock)
3387 afs_int32 apart, code, err;
3388 char apartName[10], avolname[VOLSER_MAXVOLNAME + 1];
3390 vsu_ExtractName(avolname, as->parms[2].items->data);
3391 avolid = vsu_GetVolumeID(avolname, cstruct, &err);
3394 PrintError("", err);
3396 fprintf(STDERR, "vos: can't find volume '%s'\n",
3397 as->parms[2].items->data);
3400 aserver = GetServer(as->parms[0].items->data);
3402 fprintf(STDERR, "vos: server '%s' not found in host table\n",
3403 as->parms[0].items->data);
3406 apart = volutil_GetPartitionID(as->parms[1].items->data);
3408 fprintf(STDERR, "vos: could not interpret partition name '%s'\n",
3409 as->parms[1].items->data);
3413 *skip the partition validity check, since it is possible that the partition
3414 *has since been decomissioned.
3417 if (!IsPartValid(apart,aserver,&code)){
3418 if(code) PrintError("",code);
3419 else fprintf(STDERR,"vos : partition %s does not exist on the server\n",as->parms[1].items->data);
3423 code = UV_RemoveSite(aserver, apart, avolid);
3425 PrintDiagnostics("remsite", code);
3428 MapPartIdIntoName(apart, apartName);
3429 fprintf(STDOUT, "Removed replication site %s %s for volume %s\n",
3430 as->parms[0].items->data, apartName, as->parms[2].items->data);
3435 ChangeLocation(struct cmd_syndesc *as, void *arock)
3439 afs_int32 apart, code, err;
3442 avolid = vsu_GetVolumeID(as->parms[2].items->data, cstruct, &err);
3445 PrintError("", err);
3447 fprintf(STDERR, "vos: can't find volume '%s'\n",
3448 as->parms[2].items->data);
3451 aserver = GetServer(as->parms[0].items->data);
3453 fprintf(STDERR, "vos: server '%s' not found in host table\n",
3454 as->parms[0].items->data);
3457 apart = volutil_GetPartitionID(as->parms[1].items->data);
3459 fprintf(STDERR, "vos: could not interpret partition name '%s'\n",
3460 as->parms[1].items->data);
3463 if (!IsPartValid(apart, aserver, &code)) { /*check for validity of the partition */
3465 PrintError("", code);
3468 "vos : partition %s does not exist on the server\n",
3469 as->parms[1].items->data);
3472 code = UV_ChangeLocation(aserver, apart, avolid);
3474 PrintDiagnostics("addsite", code);
3477 MapPartIdIntoName(apart, apartName);
3478 fprintf(STDOUT, "Changed location to %s %s for volume %s\n",
3479 as->parms[0].items->data, apartName, as->parms[2].items->data);
3484 ListPartitions(struct cmd_syndesc *as, void *arock)
3488 struct partList dummyPartList;
3493 aserver = GetServer(as->parms[0].items->data);
3495 fprintf(STDERR, "vos: server '%s' not found in host table\n",
3496 as->parms[0].items->data);
3501 code = UV_ListPartitions(aserver, &dummyPartList, &cnt);
3503 PrintDiagnostics("listpart", code);
3507 fprintf(STDOUT, "The partitions on the server are:\n");
3508 for (i = 0; i < cnt; i++) {
3509 if (dummyPartList.partFlags[i] & PARTVALID) {
3510 memset(pname, 0, sizeof(pname));
3511 MapPartIdIntoName(dummyPartList.partId[i], pname);
3512 fprintf(STDOUT, " %10s ", pname);
3514 if ((i % 5) == 0 && (i != 0))
3515 fprintf(STDOUT, "\n");
3518 fprintf(STDOUT, "\n");
3519 fprintf(STDOUT, "Total: %d\n", total);
3525 CompareVolName(const void *p1, const void *p2)
3527 volintInfo *arg1, *arg2;
3529 arg1 = (volintInfo *) p1;
3530 arg2 = (volintInfo *) p2;
3531 return (strcmp(arg1->name, arg2->name));
3535 /*------------------------------------------------------------------------
3536 * PRIVATE XCompareVolName
3539 * Comparison routine for volume names coming from an extended
3543 * a_obj1P : Char ptr to first extended vol info object
3544 * a_obj1P : Char ptr to second extended vol info object
3547 * The value of strcmp() on the volume names within the passed
3548 * objects (i,e., -1, 0, or 1).
3551 * Passed to qsort() as the designated comparison routine.
3555 *------------------------------------------------------------------------*/
3558 XCompareVolName(const void *a_obj1P, const void *a_obj2P)
3559 { /*XCompareVolName */
3562 (((struct volintXInfo *)(a_obj1P))->name,
3563 ((struct volintXInfo *)(a_obj2P))->name));
3565 } /*XCompareVolName */
3568 CompareVolID(const void *p1, const void *p2)
3570 volintInfo *arg1, *arg2;
3572 arg1 = (volintInfo *) p1;
3573 arg2 = (volintInfo *) p2;
3574 if (arg1->volid == arg2->volid)
3576 if (arg1->volid > arg2->volid)
3583 /*------------------------------------------------------------------------
3584 * PRIVATE XCompareVolID
3587 * Comparison routine for volume IDs coming from an extended
3591 * a_obj1P : Char ptr to first extended vol info object
3592 * a_obj1P : Char ptr to second extended vol info object
3595 * The value of strcmp() on the volume names within the passed
3596 * objects (i,e., -1, 0, or 1).
3599 * Passed to qsort() as the designated comparison routine.
3603 *------------------------------------------------------------------------*/
3606 XCompareVolID(const void *a_obj1P, const void *a_obj2P)
3607 { /*XCompareVolID */
3609 afs_int32 id1, id2; /*Volume IDs we're comparing */
3611 id1 = ((struct volintXInfo *)(a_obj1P))->volid;
3612 id2 = ((struct volintXInfo *)(a_obj2P))->volid;
3620 } /*XCompareVolID */
3622 /*------------------------------------------------------------------------
3623 * PRIVATE ListVolumes
3626 * Routine used to list volumes, contacting the Volume Server
3627 * directly, bypassing the VLDB.
3630 * as : Ptr to parsed command line arguments.
3633 * 0 Successful operation
3636 * Nothing interesting.
3640 *------------------------------------------------------------------------*/
3643 ListVolumes(struct cmd_syndesc *as, void *arock)
3645 afs_int32 apart, int32list, fast;
3649 volintInfo *oldpntr = NULL;
3653 volintXInfo *xInfoP;
3654 volintXInfo *origxInfoP = NULL; /*Ptr to current/orig extended vol info */
3655 int wantExtendedInfo; /*Do we want extended vol info? */
3658 struct partList dummyPartList;
3666 if (as->parms[3].items)
3668 if (as->parms[4].items)