2 * Copyright 2000, International Business Machines Corporation and others.
5 * This software has been released under the terms of the IBM Public
6 * License. For details, see the LICENSE file in the top-level source
7 * directory or online at http://www.openafs.org/dl/license10.html
10 #include <afsconfig.h>
11 #include <afs/param.h>
15 #ifdef IGNORE_SOME_GCC_WARNINGS
16 # pragma GCC diagnostic warning "-Wimplicit-function-declaration"
20 #include <WINNT/afsreg.h>
24 #include <sys/statfs.h>
31 #include <rx/rx_globals.h>
33 #include <afs/vlserver.h>
34 #include <afs/cellconfig.h>
36 #include <afs/afsutil.h>
38 #include <afs/afsint.h>
43 #include <afs/ihandle.h>
44 #include <afs/vnode.h>
45 #include <afs/volume.h>
46 #include <afs/com_err.h>
50 #include "volser_internal.h"
51 #include "volser_prototypes.h"
52 #include "vsutils_prototypes.h"
53 #include "lockprocs_prototypes.h"
55 #ifdef HAVE_POSIX_REGEX
59 /* Local Prototypes */
60 int PrintDiagnostics(char *astring, afs_int32 acode);
61 int GetVolumeInfo(afs_uint32 volid, afs_uint32 *server, afs_int32 *part,
62 afs_int32 *voltype, struct nvldbentry *rentry);
74 #define COMMONPARMS cmd_Seek(ts, 12);\
75 cmd_AddParm(ts, "-cell", CMD_SINGLE, CMD_OPTIONAL, "cell name");\
76 cmd_AddParm(ts, "-noauth", CMD_FLAG, CMD_OPTIONAL, "don't authenticate");\
77 cmd_AddParm(ts, "-localauth",CMD_FLAG,CMD_OPTIONAL,"use server tickets");\
78 cmd_AddParm(ts, "-verbose", CMD_FLAG, CMD_OPTIONAL, "verbose");\
79 cmd_AddParm(ts, "-encrypt", CMD_FLAG, CMD_OPTIONAL, "encrypt commands");\
80 cmd_AddParm(ts, "-noresolve", CMD_FLAG, CMD_OPTIONAL, "don't resolve addresses"); \
81 cmd_AddParm(ts, "-config", CMD_SINGLE, CMD_OPTIONAL, "config location"); \
83 #define ERROR_EXIT(code) do { \
89 struct rx_connection *tconn;
91 extern struct ubik_client *cstruct;
94 static struct tqHead busyHead, notokHead;
97 qInit(struct tqHead *ahead)
99 memset(ahead, 0, sizeof(struct tqHead));
105 qPut(struct tqHead *ahead, afs_uint32 volid)
109 elem = (struct tqElem *)malloc(sizeof(struct tqElem));
110 elem->next = ahead->next;
118 qGet(struct tqHead *ahead, afs_uint32 *volid)
122 if (ahead->count <= 0)
124 *volid = ahead->next->volid;
126 ahead->next = tmp->next;
132 /* returns 1 if <filename> exists else 0 */
134 FileExists(char *filename)
140 code = usd_Open(filename, USD_OPEN_RDONLY, 0, &ufd);
144 code = USD_IOCTL(ufd, USD_IOCTL_GETSIZE, &size);
152 /* returns 1 if <name> doesnot end in .readonly or .backup, else 0 */
154 VolNameOK(char *name)
159 total = strlen(name);
160 if (!strcmp(&name[total - 9], ".readonly")) {
162 } else if (!strcmp(&name[total - 7], ".backup")) {
169 /* return 1 if name is a number else 0 */
171 IsNumeric(char *name)
180 for (i = 0; i < len; i++) {
181 if (*ptr < '0' || *ptr > '9') {
193 * Parse a server dotted address and return the address in network byte order
196 GetServerNoresolve(char *aname)
202 code = sscanf(aname, "%d.%d.%d.%d", &b1, &b2, &b3, &b4);
204 addr = (b1 << 24) | (b2 << 16) | (b3 << 8) | b4;
205 addr = htonl(addr); /* convert to network byte order */
211 * Parse a server name/address and return the address in network byte order
214 GetServer(char *aname)
217 afs_uint32 addr; /* in network byte order */
219 char hostname[MAXHOSTCHARS];
221 if ((addr = GetServerNoresolve(aname)) == 0) {
222 th = gethostbyname(aname);
225 memcpy(&addr, th->h_addr, sizeof(addr));
228 if (rx_IsLoopbackAddr(ntohl(addr))) { /* local host */
229 code = gethostname(hostname, MAXHOSTCHARS);
232 th = gethostbyname(hostname);
235 memcpy(&addr, th->h_addr, sizeof(addr));
242 GetVolumeType(char *aname)
245 if (!strcmp(aname, "ro"))
247 else if (!strcmp(aname, "rw"))
249 else if (!strcmp(aname, "bk"))
256 IsPartValid(afs_int32 partId, afs_uint32 server, afs_int32 *code)
258 struct partList dummyPartList;
264 *code = UV_ListPartitions(server, &dummyPartList, &cnt);
267 for (i = 0; i < cnt; i++) {
268 if (dummyPartList.partFlags[i] & PARTVALID)
269 if (dummyPartList.partId[i] == partId)
277 /*sends the contents of file associated with <fd> and <blksize> to Rx Stream
278 * associated with <call> */
280 SendFile(usd_handle_t ufd, struct rx_call *call, long blksize)
282 char *buffer = (char *)0;
287 buffer = (char *)malloc(blksize);
289 fprintf(STDERR, "malloc failed\n");
293 while (!error && !done) {
294 #ifndef AFS_NT40_ENV /* NT csn't select on non-socket fd's */
297 FD_SET((intptr_t)(ufd->handle), &in);
298 /* don't timeout if read blocks */
299 #if defined(AFS_PTHREAD_ENV)
300 select(((intptr_t)(ufd->handle)) + 1, &in, 0, 0, 0);
302 IOMGR_Select(((intptr_t)(ufd->handle)) + 1, &in, 0, 0, 0);
305 error = USD_READ(ufd, buffer, blksize, &nbytes);
307 fprintf(STDERR, "File system read failed: %s\n",
308 afs_error_message(error));
315 if (rx_Write(call, buffer, nbytes) != nbytes) {
325 /* function invoked by UV_RestoreVolume, reads the data from rx_trx_stream and
326 * writes it out to the volume. */
328 WriteData(struct rx_call *call, void *rock)
330 char *filename = (char *) rock;
333 afs_int32 error, code;
335 afs_int64 currOffset;
341 if (!filename || !*filename) {
342 usd_StandardInput(&ufd);
346 code = usd_Open(filename, USD_OPEN_RDONLY, 0, &ufd);
349 code = USD_IOCTL(ufd, USD_IOCTL_GETBLKSIZE, &blksize);
352 fprintf(STDERR, "Could not access file '%s': %s\n", filename,
353 afs_error_message(code));
357 /* test if we have a valid dump */
358 USD_SEEK(ufd, 0, SEEK_END, &currOffset);
359 USD_SEEK(ufd, currOffset - sizeof(afs_uint32), SEEK_SET, &currOffset);
360 USD_READ(ufd, (char *)&buffer, sizeof(afs_uint32), &got);
361 if ((got != sizeof(afs_uint32)) || (ntohl(buffer) != DUMPENDMAGIC)) {
362 fprintf(STDERR, "Signature missing from end of file '%s'\n", filename);
366 USD_SEEK(ufd, 0, SEEK_SET, &currOffset);
368 code = SendFile(ufd, call, blksize);
375 code = USD_CLOSE(ufd);
377 fprintf(STDERR, "Could not close dump file %s\n",
378 (filename && *filename) ? filename : "STDOUT");
386 /* Receive data from <call> stream into file associated
387 * with <fd> <blksize>
390 ReceiveFile(usd_handle_t ufd, struct rx_call *call, long blksize)
394 afs_uint32 bytesleft, w;
397 buffer = (char *)malloc(blksize);
399 fprintf(STDERR, "memory allocation failed\n");
403 while ((bytesread = rx_Read(call, buffer, blksize)) > 0) {
404 for (bytesleft = bytesread; bytesleft; bytesleft -= w) {
405 #ifndef AFS_NT40_ENV /* NT csn't select on non-socket fd's */
408 FD_SET((intptr_t)(ufd->handle), &out);
409 /* don't timeout if write blocks */
410 #if defined(AFS_PTHREAD_ENV)
411 select(((intptr_t)(ufd->handle)) + 1, &out, 0, 0, 0);
413 IOMGR_Select(((intptr_t)(ufd->handle)) + 1, 0, &out, 0, 0);
417 USD_WRITE(ufd, &buffer[bytesread - bytesleft], bytesleft, &w);
419 fprintf(STDERR, "File system write failed: %s\n",
420 afs_error_message(error));
433 DumpFunction(struct rx_call *call, void *rock)
435 char *filename = (char *)rock;
436 usd_handle_t ufd; /* default is to stdout */
437 afs_int32 error = 0, code;
442 /* Open the output file */
443 if (!filename || !*filename) {
444 usd_StandardOutput(&ufd);
449 usd_Open(filename, USD_OPEN_CREATE | USD_OPEN_RDWR, 0666, &ufd);
453 code = USD_IOCTL(ufd, USD_IOCTL_SETSIZE, &size);
456 code = USD_IOCTL(ufd, USD_IOCTL_GETBLKSIZE, &blksize);
459 fprintf(STDERR, "Could not create file '%s': %s\n", filename,
460 afs_error_message(code));
461 ERROR_EXIT(VOLSERBADOP);
465 code = ReceiveFile(ufd, call, blksize);
470 /* Close the output file */
472 code = USD_CLOSE(ufd);
474 fprintf(STDERR, "Could not close dump file %s\n",
475 (filename && *filename) ? filename : "STDIN");
485 DisplayFormat(volintInfo *pntr, afs_uint32 server, afs_int32 part,
486 int *totalOK, int *totalNotOK, int *totalBusy, int fast,
487 int longlist, int disp)
493 fprintf(STDOUT, "%-10lu\n", (unsigned long)pntr->volid);
494 } else if (longlist) {
495 if (pntr->status == VOK) {
496 fprintf(STDOUT, "%-32s ", pntr->name);
497 fprintf(STDOUT, "%10lu ", (unsigned long)pntr->volid);
499 fprintf(STDOUT, "RW ");
501 fprintf(STDOUT, "RO ");
503 fprintf(STDOUT, "BK ");
504 fprintf(STDOUT, "%10d K ", pntr->size);
505 if (pntr->inUse == 1) {
506 fprintf(STDOUT, "On-line");
509 fprintf(STDOUT, "Off-line");
512 if (pntr->needsSalvaged == 1)
513 fprintf(STDOUT, "**needs salvage**");
514 fprintf(STDOUT, "\n");
515 MapPartIdIntoName(part, pname);
516 fprintf(STDOUT, " %s %s \n", hostutil_GetNameByINet(server),
518 fprintf(STDOUT, " RWrite %10lu ROnly %10lu Backup %10lu \n",
519 (unsigned long)pntr->parentID,
520 (unsigned long)pntr->cloneID,
521 (unsigned long)pntr->backupID);
522 fprintf(STDOUT, " MaxQuota %10d K \n", pntr->maxquota);
523 t = pntr->creationDate;
524 fprintf(STDOUT, " Creation %s",
527 fprintf(STDOUT, " Copy %s",
530 t = pntr->backupDate;
532 fprintf(STDOUT, " Backup Never\n");
534 fprintf(STDOUT, " Backup %s",
537 t = pntr->accessDate;
539 fprintf(STDOUT, " Last Access %s",
542 t = pntr->updateDate;
544 fprintf(STDOUT, " Last Update Never\n");
546 fprintf(STDOUT, " Last Update %s",
549 " %d accesses in the past day (i.e., vnode references)\n",
551 } else if (pntr->status == VBUSY) {
553 qPut(&busyHead, pntr->volid);
555 fprintf(STDOUT, "**** Volume %lu is busy ****\n",
556 (unsigned long)pntr->volid);
559 qPut(¬okHead, pntr->volid);
561 fprintf(STDOUT, "**** Could not attach volume %lu ****\n",
562 (unsigned long)pntr->volid);
564 fprintf(STDOUT, "\n");
565 } else { /* default listing */
566 if (pntr->status == VOK) {
567 fprintf(STDOUT, "%-32s ", pntr->name);
568 fprintf(STDOUT, "%10lu ", (unsigned long)pntr->volid);
570 fprintf(STDOUT, "RW ");
572 fprintf(STDOUT, "RO ");
574 fprintf(STDOUT, "BK ");
575 fprintf(STDOUT, "%10d K ", pntr->size);
576 if (pntr->inUse == 1) {
577 fprintf(STDOUT, "On-line");
580 fprintf(STDOUT, "Off-line");
583 if (pntr->needsSalvaged == 1)
584 fprintf(STDOUT, "**needs salvage**");
585 fprintf(STDOUT, "\n");
586 } else if (pntr->status == VBUSY) {
588 qPut(&busyHead, pntr->volid);
590 fprintf(STDOUT, "**** Volume %lu is busy ****\n",
591 (unsigned long)pntr->volid);
594 qPut(¬okHead, pntr->volid);
596 fprintf(STDOUT, "**** Could not attach volume %lu ****\n",
597 (unsigned long)pntr->volid);
602 /*------------------------------------------------------------------------
603 * PRIVATE XDisplayFormat
606 * Display the contents of one extended volume info structure.
609 * a_xInfoP : Ptr to extended volume info struct to print.
610 * a_servID : Server ID to print.
611 * a_partID : Partition ID to print.
612 * a_totalOKP : Ptr to total-OK counter.
613 * a_totalNotOKP : Ptr to total-screwed counter.
614 * a_totalBusyP : Ptr to total-busy counter.
615 * a_fast : Fast listing?
616 * a_int32 : Int32 listing?
617 * a_showProblems : Show volume problems?
623 * Nothing interesting.
627 *------------------------------------------------------------------------*/
630 XDisplayFormat(volintXInfo *a_xInfoP, afs_uint32 a_servID, afs_int32 a_partID,
631 int *a_totalOKP, int *a_totalNotOKP, int *a_totalBusyP,
632 int a_fast, int a_int32, int a_showProblems)
633 { /*XDisplayFormat */
641 fprintf(STDOUT, "%-10lu\n", (unsigned long)a_xInfoP->volid);
642 } else if (a_int32) {
644 * Fully-detailed listing.
646 if (a_xInfoP->status == VOK) {
648 * Volume's status is OK - all the fields are valid.
650 fprintf(STDOUT, "%-32s ", a_xInfoP->name);
651 fprintf(STDOUT, "%10lu ", (unsigned long)a_xInfoP->volid);
652 if (a_xInfoP->type == 0)
653 fprintf(STDOUT, "RW ");
654 if (a_xInfoP->type == 1)
655 fprintf(STDOUT, "RO ");
656 if (a_xInfoP->type == 2)
657 fprintf(STDOUT, "BK ");
658 fprintf(STDOUT, "%10d K used ", a_xInfoP->size);
659 fprintf(STDOUT, "%d files ", a_xInfoP->filecount);
660 if (a_xInfoP->inUse == 1) {
661 fprintf(STDOUT, "On-line");
664 fprintf(STDOUT, "Off-line");
667 fprintf(STDOUT, "\n");
668 MapPartIdIntoName(a_partID, pname);
669 fprintf(STDOUT, " %s %s \n", hostutil_GetNameByINet(a_servID),
671 fprintf(STDOUT, " RWrite %10lu ROnly %10lu Backup %10lu \n",
672 (unsigned long)a_xInfoP->parentID,
673 (unsigned long)a_xInfoP->cloneID,
674 (unsigned long)a_xInfoP->backupID);
675 fprintf(STDOUT, " MaxQuota %10d K \n", a_xInfoP->maxquota);
677 t = a_xInfoP->creationDate;
678 fprintf(STDOUT, " Creation %s",
681 t = a_xInfoP->copyDate;
682 fprintf(STDOUT, " Copy %s",
685 t = a_xInfoP->backupDate;
687 fprintf(STDOUT, " Backup Never\n");
689 fprintf(STDOUT, " Backup %s",
692 t = a_xInfoP->accessDate;
694 fprintf(STDOUT, " Last Access %s",
697 t = a_xInfoP->updateDate;
699 fprintf(STDOUT, " Last Update Never\n");
701 fprintf(STDOUT, " Last Update %s",
704 " %d accesses in the past day (i.e., vnode references)\n",
708 * Print all the read/write and authorship stats.
710 fprintf(STDOUT, "\n Raw Read/Write Stats\n");
712 " |-------------------------------------------|\n");
714 " | Same Network | Diff Network |\n");
716 " |----------|----------|----------|----------|\n");
718 " | Total | Auth | Total | Auth |\n");
720 " |----------|----------|----------|----------|\n");
721 fprintf(STDOUT, "Reads | %8d | %8d | %8d | %8d |\n",
722 a_xInfoP->stat_reads[VOLINT_STATS_SAME_NET],
723 a_xInfoP->stat_reads[VOLINT_STATS_SAME_NET_AUTH],
724 a_xInfoP->stat_reads[VOLINT_STATS_DIFF_NET],
725 a_xInfoP->stat_reads[VOLINT_STATS_DIFF_NET_AUTH]);
726 fprintf(STDOUT, "Writes | %8d | %8d | %8d | %8d |\n",
727 a_xInfoP->stat_writes[VOLINT_STATS_SAME_NET],
728 a_xInfoP->stat_writes[VOLINT_STATS_SAME_NET_AUTH],
729 a_xInfoP->stat_writes[VOLINT_STATS_DIFF_NET],
730 a_xInfoP->stat_writes[VOLINT_STATS_DIFF_NET_AUTH]);
732 " |-------------------------------------------|\n\n");
735 " Writes Affecting Authorship\n");
737 " |-------------------------------------------|\n");
739 " | File Authorship | Directory Authorship|\n");
741 " |----------|----------|----------|----------|\n");
743 " | Same | Diff | Same | Diff |\n");
745 " |----------|----------|----------|----------|\n");
746 fprintf(STDOUT, "0-60 sec | %8d | %8d | %8d | %8d |\n",
747 a_xInfoP->stat_fileSameAuthor[VOLINT_STATS_TIME_IDX_0],
748 a_xInfoP->stat_fileDiffAuthor[VOLINT_STATS_TIME_IDX_0],
749 a_xInfoP->stat_dirSameAuthor[VOLINT_STATS_TIME_IDX_0],
750 a_xInfoP->stat_dirDiffAuthor[VOLINT_STATS_TIME_IDX_0]);
751 fprintf(STDOUT, "1-10 min | %8d | %8d | %8d | %8d |\n",
752 a_xInfoP->stat_fileSameAuthor[VOLINT_STATS_TIME_IDX_1],
753 a_xInfoP->stat_fileDiffAuthor[VOLINT_STATS_TIME_IDX_1],
754 a_xInfoP->stat_dirSameAuthor[VOLINT_STATS_TIME_IDX_1],
755 a_xInfoP->stat_dirDiffAuthor[VOLINT_STATS_TIME_IDX_1]);
756 fprintf(STDOUT, "10min-1hr | %8d | %8d | %8d | %8d |\n",
757 a_xInfoP->stat_fileSameAuthor[VOLINT_STATS_TIME_IDX_2],
758 a_xInfoP->stat_fileDiffAuthor[VOLINT_STATS_TIME_IDX_2],
759 a_xInfoP->stat_dirSameAuthor[VOLINT_STATS_TIME_IDX_2],
760 a_xInfoP->stat_dirDiffAuthor[VOLINT_STATS_TIME_IDX_2]);
761 fprintf(STDOUT, "1hr-1day | %8d | %8d | %8d | %8d |\n",
762 a_xInfoP->stat_fileSameAuthor[VOLINT_STATS_TIME_IDX_3],
763 a_xInfoP->stat_fileDiffAuthor[VOLINT_STATS_TIME_IDX_3],
764 a_xInfoP->stat_dirSameAuthor[VOLINT_STATS_TIME_IDX_3],
765 a_xInfoP->stat_dirDiffAuthor[VOLINT_STATS_TIME_IDX_3]);
766 fprintf(STDOUT, "1day-1wk | %8d | %8d | %8d | %8d |\n",
767 a_xInfoP->stat_fileSameAuthor[VOLINT_STATS_TIME_IDX_4],
768 a_xInfoP->stat_fileDiffAuthor[VOLINT_STATS_TIME_IDX_4],
769 a_xInfoP->stat_dirSameAuthor[VOLINT_STATS_TIME_IDX_4],
770 a_xInfoP->stat_dirDiffAuthor[VOLINT_STATS_TIME_IDX_4]);
771 fprintf(STDOUT, "> 1wk | %8d | %8d | %8d | %8d |\n",
772 a_xInfoP->stat_fileSameAuthor[VOLINT_STATS_TIME_IDX_5],
773 a_xInfoP->stat_fileDiffAuthor[VOLINT_STATS_TIME_IDX_5],
774 a_xInfoP->stat_dirSameAuthor[VOLINT_STATS_TIME_IDX_5],
775 a_xInfoP->stat_dirDiffAuthor[VOLINT_STATS_TIME_IDX_5]);
777 " |-------------------------------------------|\n");
778 } /*Volume status OK */
779 else if (a_xInfoP->status == VBUSY) {
781 qPut(&busyHead, a_xInfoP->volid);
783 fprintf(STDOUT, "**** Volume %lu is busy ****\n",
784 (unsigned long)a_xInfoP->volid);
788 qPut(¬okHead, a_xInfoP->volid);
790 fprintf(STDOUT, "**** Could not attach volume %lu ****\n",
791 (unsigned long)a_xInfoP->volid);
792 } /*Screwed volume */
793 fprintf(STDOUT, "\n");
799 if (a_xInfoP->status == VOK) {
800 fprintf(STDOUT, "%-32s ", a_xInfoP->name);
801 fprintf(STDOUT, "%10lu ", (unsigned long)a_xInfoP->volid);
802 if (a_xInfoP->type == 0)
803 fprintf(STDOUT, "RW ");
804 if (a_xInfoP->type == 1)
805 fprintf(STDOUT, "RO ");
806 if (a_xInfoP->type == 2)
807 fprintf(STDOUT, "BK ");
808 fprintf(STDOUT, "%10d K ", a_xInfoP->size);
809 if (a_xInfoP->inUse == 1) {
810 fprintf(STDOUT, "On-line");
813 fprintf(STDOUT, "Off-line");
816 fprintf(STDOUT, "\n");
818 else if (a_xInfoP->status == VBUSY) {
820 qPut(&busyHead, a_xInfoP->volid);
822 fprintf(STDOUT, "**** Volume %lu is busy ****\n",
823 (unsigned long)a_xInfoP->volid);
827 qPut(¬okHead, a_xInfoP->volid);
829 fprintf(STDOUT, "**** Could not attach volume %lu ****\n",
830 (unsigned long)a_xInfoP->volid);
831 } /*Screwed volume */
832 } /*Default listing */
833 } /*XDisplayFormat */
835 /*------------------------------------------------------------------------
836 * PRIVATE XDisplayFormat2
839 * Display the formated contents of one extended volume info structure.
842 * a_xInfoP : Ptr to extended volume info struct to print.
843 * a_servID : Server ID to print.
844 * a_partID : Partition ID to print.
845 * a_totalOKP : Ptr to total-OK counter.
846 * a_totalNotOKP : Ptr to total-screwed counter.
847 * a_totalBusyP : Ptr to total-busy counter.
848 * a_fast : Fast listing?
849 * a_int32 : Int32 listing?
850 * a_showProblems : Show volume problems?
856 * Nothing interesting.
860 *------------------------------------------------------------------------*/
863 XDisplayFormat2(volintXInfo *a_xInfoP, afs_uint32 a_servID, afs_int32 a_partID,
864 int *a_totalOKP, int *a_totalNotOKP, int *a_totalBusyP,
865 int a_fast, int a_int32, int a_showProblems)
866 { /*XDisplayFormat */
872 fprintf(STDOUT, "vold_id\t%-10lu\n", (unsigned long)a_xInfoP->volid);
873 } else if (a_int32) {
875 * Fully-detailed listing.
877 if (a_xInfoP->status == VOK) {
879 * Volume's status is OK - all the fields are valid.
882 static long server_cache = -1, partition_cache = -1;
883 static char hostname[256], address[32], pname[16];
884 int i,ai[] = {VOLINT_STATS_TIME_IDX_0,VOLINT_STATS_TIME_IDX_1,VOLINT_STATS_TIME_IDX_2,
885 VOLINT_STATS_TIME_IDX_3,VOLINT_STATS_TIME_IDX_4,VOLINT_STATS_TIME_IDX_5};
887 if (a_servID != server_cache) {
891 strcpy(hostname, hostutil_GetNameByINet(a_servID));
892 strcpy(address, inet_ntoa(s));
893 server_cache = a_servID;
895 if (a_partID != partition_cache) {
896 MapPartIdIntoName(a_partID, pname);
897 partition_cache = a_partID;
900 fprintf(STDOUT, "name\t\t%s\n", a_xInfoP->name);
901 fprintf(STDOUT, "id\t\t%lu\n", afs_printable_uint32_lu(a_xInfoP->volid));
902 fprintf(STDOUT, "serv\t\t%s\t%s\n", address, hostname);
903 fprintf(STDOUT, "part\t\t%s\n", pname);
904 fprintf(STDOUT, "status\t\tOK\n");
905 fprintf(STDOUT, "backupID\t%lu\n",
906 afs_printable_uint32_lu(a_xInfoP->backupID));
907 fprintf(STDOUT, "parentID\t%lu\n",
908 afs_printable_uint32_lu(a_xInfoP->parentID));
909 fprintf(STDOUT, "cloneID\t\t%lu\n",
910 afs_printable_uint32_lu(a_xInfoP->cloneID));
911 fprintf(STDOUT, "inUse\t\t%s\n", a_xInfoP->inUse ? "Y" : "N");
912 switch (a_xInfoP->type) {
914 fprintf(STDOUT, "type\t\tRW\n");
917 fprintf(STDOUT, "type\t\tRO\n");
920 fprintf(STDOUT, "type\t\tBK\n");
923 fprintf(STDOUT, "type\t\t?\n");
926 t = a_xInfoP->creationDate;
927 fprintf(STDOUT, "creationDate\t%-9lu\t%s",
928 afs_printable_uint32_lu(a_xInfoP->creationDate),
931 t = a_xInfoP->accessDate;
932 fprintf(STDOUT, "accessDate\t%-9lu\t%s",
933 afs_printable_uint32_lu(a_xInfoP->accessDate),
936 t = a_xInfoP->updateDate;
937 fprintf(STDOUT, "updateDate\t%-9lu\t%s",
938 afs_printable_uint32_lu(a_xInfoP->updateDate),
941 t = a_xInfoP->backupDate;
942 fprintf(STDOUT, "backupDate\t%-9lu\t%s",
943 afs_printable_uint32_lu(a_xInfoP->backupDate),
946 t = a_xInfoP->copyDate;
947 fprintf(STDOUT, "copyDate\t%-9lu\t%s",
948 afs_printable_uint32_lu(a_xInfoP->copyDate),
951 fprintf(STDOUT, "diskused\t%u\n", a_xInfoP->size);
952 fprintf(STDOUT, "maxquota\t%u\n", a_xInfoP->maxquota);
954 fprintf(STDOUT, "filecount\t%u\n", a_xInfoP->filecount);
955 fprintf(STDOUT, "dayUse\t\t%u\n", a_xInfoP->dayUse);
959 fprintf(STDOUT,"reads_same_net\t%8d\n",a_xInfoP->stat_reads[VOLINT_STATS_SAME_NET]);
960 fprintf(STDOUT,"reads_same_net_auth\t%8d\n",a_xInfoP->stat_reads[VOLINT_STATS_SAME_NET_AUTH]);
961 fprintf(STDOUT,"reads_diff_net\t%8d\n",a_xInfoP->stat_reads[VOLINT_STATS_DIFF_NET]);
962 fprintf(STDOUT,"reads_diff_net_auth\t%8d\n",a_xInfoP->stat_reads[VOLINT_STATS_DIFF_NET_AUTH]);
964 fprintf(STDOUT,"writes_same_net\t%8d\n",a_xInfoP->stat_writes[VOLINT_STATS_SAME_NET]);
965 fprintf(STDOUT,"writes_same_net_auth\t%8d\n",a_xInfoP->stat_writes[VOLINT_STATS_SAME_NET_AUTH]);
966 fprintf(STDOUT,"writes_diff_net\t%8d\n",a_xInfoP->stat_writes[VOLINT_STATS_DIFF_NET]);
967 fprintf(STDOUT,"writes_diff_net_auth\t%8d\n",a_xInfoP->stat_writes[VOLINT_STATS_DIFF_NET_AUTH]);
971 fprintf(STDOUT,"file_same_author_idx_%d\t%8d\n",i+1,a_xInfoP->stat_fileSameAuthor[ai[i]]);
972 fprintf(STDOUT,"file_diff_author_idx_%d\t%8d\n",i+1,a_xInfoP->stat_fileDiffAuthor[ai[i]]);
973 fprintf(STDOUT,"dir_same_author_idx_%d\t%8d\n",i+1,a_xInfoP->stat_dirSameAuthor[ai[i]]);
974 fprintf(STDOUT,"dir_dif_author_idx_%d\t%8d\n",i+1,a_xInfoP->stat_dirDiffAuthor[ai[i]]);
977 } /*Volume status OK */
978 else if (a_xInfoP->status == VBUSY) {
980 qPut(&busyHead, a_xInfoP->volid);
982 fprintf(STDOUT, "BUSY_VOL\t%lu\n",
983 (unsigned long)a_xInfoP->volid);
987 qPut(¬okHead, a_xInfoP->volid);
989 fprintf(STDOUT, "COULD_NOT_ATTACH\t%lu\n",
990 (unsigned long)a_xInfoP->volid);
991 } /*Screwed volume */
997 if (a_xInfoP->status == VOK) {
998 fprintf(STDOUT, "name\t%-32s\n", a_xInfoP->name);
999 fprintf(STDOUT, "volID\t%10lu\n", (unsigned long)a_xInfoP->volid);
1000 if (a_xInfoP->type == 0)
1001 fprintf(STDOUT, "type\tRW\n");
1002 if (a_xInfoP->type == 1)
1003 fprintf(STDOUT, "type\tRO\n");
1004 if (a_xInfoP->type == 2)
1005 fprintf(STDOUT, "type\tBK\n");
1006 fprintf(STDOUT, "size\t%10dK\n", a_xInfoP->size);
1008 fprintf(STDOUT, "inUse\t%d\n",a_xInfoP->inUse);
1009 if (a_xInfoP->inUse == 1)
1015 else if (a_xInfoP->status == VBUSY) {
1017 qPut(&busyHead, a_xInfoP->volid);
1019 fprintf(STDOUT, "VOLUME_BUSY\t%lu\n",
1020 (unsigned long)a_xInfoP->volid);
1024 qPut(¬okHead, a_xInfoP->volid);
1026 fprintf(STDOUT, "COULD_NOT_ATTACH_VOLUME\t%lu\n",
1027 (unsigned long)a_xInfoP->volid);
1028 } /*Screwed volume */
1029 } /*Default listing */
1030 } /*XDisplayFormat */
1033 DisplayFormat2(long server, long partition, volintInfo *pntr)
1035 static long server_cache = -1, partition_cache = -1;
1036 static char hostname[256], address[32], pname[16];
1039 if (server != server_cache) {
1043 strcpy(hostname, hostutil_GetNameByINet(server));
1044 strcpy(address, inet_ntoa(s));
1045 server_cache = server;
1047 if (partition != partition_cache) {
1048 MapPartIdIntoName(partition, pname);
1049 partition_cache = partition;
1052 if (pntr->status == VOK)
1053 fprintf(STDOUT, "name\t\t%s\n", pntr->name);
1055 fprintf(STDOUT, "id\t\t%lu\n",
1056 afs_printable_uint32_lu(pntr->volid));
1057 fprintf(STDOUT, "serv\t\t%s\t%s\n", address, hostname);
1058 fprintf(STDOUT, "part\t\t%s\n", pname);
1059 switch (pntr->status) {
1061 fprintf(STDOUT, "status\t\tOK\n");
1064 fprintf(STDOUT, "status\t\tBUSY\n");
1067 fprintf(STDOUT, "status\t\tUNATTACHABLE\n");
1070 fprintf(STDOUT, "backupID\t%lu\n",
1071 afs_printable_uint32_lu(pntr->backupID));
1072 fprintf(STDOUT, "parentID\t%lu\n",
1073 afs_printable_uint32_lu(pntr->parentID));
1074 fprintf(STDOUT, "cloneID\t\t%lu\n",
1075 afs_printable_uint32_lu(pntr->cloneID));
1076 fprintf(STDOUT, "inUse\t\t%s\n", pntr->inUse ? "Y" : "N");
1077 fprintf(STDOUT, "needsSalvaged\t%s\n", pntr->needsSalvaged ? "Y" : "N");
1078 /* 0xD3 is from afs/volume.h since I had trouble including the file */
1079 fprintf(STDOUT, "destroyMe\t%s\n", pntr->destroyMe == 0xD3 ? "Y" : "N");
1080 switch (pntr->type) {
1082 fprintf(STDOUT, "type\t\tRW\n");
1085 fprintf(STDOUT, "type\t\tRO\n");
1088 fprintf(STDOUT, "type\t\tBK\n");
1091 fprintf(STDOUT, "type\t\t?\n");
1094 t = pntr->creationDate;
1095 fprintf(STDOUT, "creationDate\t%-9lu\t%s",
1096 afs_printable_uint32_lu(pntr->creationDate),
1099 t = pntr->accessDate;
1100 fprintf(STDOUT, "accessDate\t%-9lu\t%s",
1101 afs_printable_uint32_lu(pntr->accessDate),
1104 t = pntr->updateDate;
1105 fprintf(STDOUT, "updateDate\t%-9lu\t%s",
1106 afs_printable_uint32_lu(pntr->updateDate),
1109 t = pntr->backupDate;
1110 fprintf(STDOUT, "backupDate\t%-9lu\t%s",
1111 afs_printable_uint32_lu(pntr->backupDate),
1115 fprintf(STDOUT, "copyDate\t%-9lu\t%s",
1116 afs_printable_uint32_lu(pntr->copyDate),
1119 fprintf(STDOUT, "flags\t\t%#lx\t(Optional)\n",
1120 afs_printable_uint32_lu(pntr->flags));
1121 fprintf(STDOUT, "diskused\t%u\n", pntr->size);
1122 fprintf(STDOUT, "maxquota\t%u\n", pntr->maxquota);
1123 fprintf(STDOUT, "minquota\t%lu\t(Optional)\n",
1124 afs_printable_uint32_lu(pntr->spare0));
1125 fprintf(STDOUT, "filecount\t%u\n", pntr->filecount);
1126 fprintf(STDOUT, "dayUse\t\t%u\n", pntr->dayUse);
1127 fprintf(STDOUT, "weekUse\t\t%lu\t(Optional)\n",
1128 afs_printable_uint32_lu(pntr->spare1));
1129 fprintf(STDOUT, "spare2\t\t%lu\t(Optional)\n",
1130 afs_printable_uint32_lu(pntr->spare2));
1131 fprintf(STDOUT, "spare3\t\t%lu\t(Optional)\n",
1132 afs_printable_uint32_lu(pntr->spare3));
1137 DisplayVolumes2(long server, long partition, volintInfo *pntr, long count)
1141 for (i = 0; i < count; i++) {
1142 fprintf(STDOUT, "BEGIN_OF_ENTRY\n");
1143 DisplayFormat2(server, partition, pntr);
1144 fprintf(STDOUT, "END_OF_ENTRY\n\n");
1151 DisplayVolumes(afs_uint32 server, afs_int32 part, volintInfo *pntr,
1152 afs_int32 count, afs_int32 longlist, afs_int32 fast,
1155 int totalOK, totalNotOK, totalBusy, i;
1156 afs_uint32 volid = 0;
1163 for (i = 0; i < count; i++) {
1164 DisplayFormat(pntr, server, part, &totalOK, &totalNotOK, &totalBusy,
1169 while (busyHead.count) {
1170 qGet(&busyHead, &volid);
1171 fprintf(STDOUT, "**** Volume %lu is busy ****\n",
1172 (unsigned long)volid);
1176 while (notokHead.count) {
1177 qGet(¬okHead, &volid);
1178 fprintf(STDOUT, "**** Could not attach volume %lu ****\n",
1179 (unsigned long)volid);
1183 fprintf(STDOUT, "\n");
1186 "Total volumes onLine %d ; Total volumes offLine %d ; Total busy %d\n\n",
1187 totalOK, totalNotOK, totalBusy);
1191 /*------------------------------------------------------------------------
1192 * PRIVATE XDisplayVolumes
1195 * Display extended volume information.
1198 * a_servID : Pointer to the Rx call we're performing.
1199 * a_partID : Partition for which we want the extended list.
1200 * a_xInfoP : Ptr to extended volume info.
1201 * a_count : Number of volume records contained above.
1202 * a_int32 : Int32 listing generated?
1203 * a_fast : Fast listing generated?
1204 * a_quiet : Quiet listing generated?
1210 * Nothing interesting.
1214 *------------------------------------------------------------------------*/
1217 XDisplayVolumes(afs_uint32 a_servID, afs_int32 a_partID, volintXInfo *a_xInfoP,
1218 afs_int32 a_count, afs_int32 a_int32, afs_int32 a_fast,
1220 { /*XDisplayVolumes */
1222 int totalOK; /*Total OK volumes */
1223 int totalNotOK; /*Total screwed volumes */
1224 int totalBusy; /*Total busy volumes */
1225 int i; /*Loop variable */
1226 afs_uint32 volid = 0; /*Current volume ID */
1229 * Initialize counters and (global!!) queues.
1238 * Display each volume in the list.
1240 for (i = 0; i < a_count; i++) {
1241 XDisplayFormat(a_xInfoP, a_servID, a_partID, &totalOK, &totalNotOK,
1242 &totalBusy, a_fast, a_int32, 0);
1247 * If any volumes were found to be busy or screwed, display them.
1250 while (busyHead.count) {
1251 qGet(&busyHead, &volid);
1252 fprintf(STDOUT, "**** Volume %lu is busy ****\n",
1253 (unsigned long)volid);
1257 while (notokHead.count) {
1258 qGet(¬okHead, &volid);
1259 fprintf(STDOUT, "**** Could not attach volume %lu ****\n",
1260 (unsigned long)volid);
1265 fprintf(STDOUT, "\n");
1268 "Total volumes: %d on-line, %d off-line, %d busyd\n\n",
1269 totalOK, totalNotOK, totalBusy);
1273 } /*XDisplayVolumes */
1275 /*------------------------------------------------------------------------
1276 * PRIVATE XDisplayVolumes2
1279 * Display extended formated volume information.
1282 * a_servID : Pointer to the Rx call we're performing.
1283 * a_partID : Partition for which we want the extended list.
1284 * a_xInfoP : Ptr to extended volume info.
1285 * a_count : Number of volume records contained above.
1286 * a_int32 : Int32 listing generated?
1287 * a_fast : Fast listing generated?
1288 * a_quiet : Quiet listing generated?
1294 * Nothing interesting.
1298 *------------------------------------------------------------------------*/
1301 XDisplayVolumes2(afs_uint32 a_servID, afs_int32 a_partID, volintXInfo *a_xInfoP,
1302 afs_int32 a_count, afs_int32 a_int32, afs_int32 a_fast,
1304 { /*XDisplayVolumes */
1306 int totalOK; /*Total OK volumes */
1307 int totalNotOK; /*Total screwed volumes */
1308 int totalBusy; /*Total busy volumes */
1309 int i; /*Loop variable */
1310 afs_uint32 volid = 0; /*Current volume ID */
1313 * Initialize counters and (global!!) queues.
1322 * Display each volume in the list.
1324 for (i = 0; i < a_count; i++) {
1325 fprintf(STDOUT, "BEGIN_OF_ENTRY\n");
1326 XDisplayFormat2(a_xInfoP, a_servID, a_partID, &totalOK, &totalNotOK,
1327 &totalBusy, a_fast, a_int32, 0);
1328 fprintf(STDOUT, "END_OF_ENTRY\n");
1333 * If any volumes were found to be busy or screwed, display them.
1336 while (busyHead.count) {
1337 qGet(&busyHead, &volid);
1338 fprintf(STDOUT, "BUSY_VOL\t%lu\n",
1339 (unsigned long)volid);
1343 while (notokHead.count) {
1344 qGet(¬okHead, &volid);
1345 fprintf(STDOUT, "COULD_NOT_ATTACH\t%lu\n",
1346 (unsigned long)volid);
1351 fprintf(STDOUT, "\n");
1354 "VOLUMES_ONLINE\t%d\nVOLUMES_OFFLINE\t%d\nVOLUMES_BUSY\t%d\n",
1355 totalOK, totalNotOK, totalBusy);
1359 } /*XDisplayVolumes2 */
1362 /* set <server> and <part> to the correct values depending on
1363 * <voltype> and <entry> */
1365 GetServerAndPart(struct nvldbentry *entry, int voltype, afs_uint32 *server,
1366 afs_int32 *part, int *previdx)
1368 int i, istart, vtype;
1373 /* Doesn't check for non-existance of backup volume */
1374 if ((voltype == RWVOL) || (voltype == BACKVOL)) {
1376 istart = 0; /* seach the entire entry */
1379 /* Seach from beginning of entry or pick up where we left off */
1380 istart = ((*previdx < 0) ? 0 : *previdx + 1);
1383 for (i = istart; i < entry->nServers; i++) {
1384 if (entry->serverFlags[i] & vtype) {
1385 *server = entry->serverNumber[i];
1386 *part = entry->serverPartition[i];
1392 /* Didn't find any, return -1 */
1398 PrintLocked(afs_int32 aflags)
1400 afs_int32 flags = aflags & VLOP_ALLOPERS;
1403 fprintf(STDOUT, " Volume is currently LOCKED \n");
1405 if (flags & VLOP_MOVE) {
1406 fprintf(STDOUT, " Volume is locked for a move operation\n");
1408 if (flags & VLOP_RELEASE) {
1409 fprintf(STDOUT, " Volume is locked for a release operation\n");
1411 if (flags & VLOP_BACKUP) {
1412 fprintf(STDOUT, " Volume is locked for a backup operation\n");
1414 if (flags & VLOP_DELETE) {
1415 fprintf(STDOUT, " Volume is locked for a delete/misc operation\n");
1417 if (flags & VLOP_DUMP) {
1418 fprintf(STDOUT, " Volume is locked for a dump/restore operation\n");
1424 PostVolumeStats(struct nvldbentry *entry)
1426 SubEnumerateEntry(entry);
1427 /* Check for VLOP_ALLOPERS */
1428 PrintLocked(entry->flags);
1432 /*------------------------------------------------------------------------
1433 * PRIVATE XVolumeStats
1436 * Display extended volume information.
1439 * a_xInfoP : Ptr to extended volume info.
1440 * a_entryP : Ptr to the volume's VLDB entry.
1441 * a_srvID : Server ID.
1442 * a_partID : Partition ID.
1443 * a_volType : Type of volume to print.
1449 * Nothing interesting.
1453 *------------------------------------------------------------------------*/
1456 XVolumeStats(volintXInfo *a_xInfoP, struct nvldbentry *a_entryP,
1457 afs_int32 a_srvID, afs_int32 a_partID, int a_volType)
1460 int totalOK, totalNotOK, totalBusy; /*Dummies - we don't really count here */
1462 XDisplayFormat(a_xInfoP, /*Ptr to extended volume info */
1463 a_srvID, /*Server ID to print */
1464 a_partID, /*Partition ID to print */
1465 &totalOK, /*Ptr to total-OK counter */
1466 &totalNotOK, /*Ptr to total-screwed counter */
1467 &totalBusy, /*Ptr to total-busy counter */
1468 0, /*Don't do a fast listing */
1469 1, /*Do a long listing */
1470 1); /*Show volume problems */
1476 VolumeStats_int(volintInfo *pntr, struct nvldbentry *entry, afs_uint32 server,
1477 afs_int32 part, int voltype)
1479 int totalOK, totalNotOK, totalBusy;
1481 DisplayFormat(pntr, server, part, &totalOK, &totalNotOK, &totalBusy, 0, 1,
1486 /* command to forcibly remove a volume */
1488 NukeVolume(struct cmd_syndesc *as)
1497 server = GetServer(tp = as->parms[0].items->data);
1499 fprintf(STDERR, "vos: server '%s' not found in host table\n", tp);
1503 partID = volutil_GetPartitionID(tp = as->parms[1].items->data);
1505 fprintf(STDERR, "vos: could not parse '%s' as a partition name", tp);
1509 volID = vsu_GetVolumeID(tp = as->parms[2].items->data, cstruct, &err);
1512 PrintError("", err);
1515 "vos: could not parse '%s' as a numeric volume ID", tp);
1520 "vos: forcibly removing all traces of volume %d, please wait...",
1523 code = UV_NukeVolume(server, partID, volID);
1525 fprintf(STDOUT, "done.\n");
1527 fprintf(STDOUT, "failed with code %d.\n", code);
1532 /*------------------------------------------------------------------------
1533 * PRIVATE ExamineVolume
1536 * Routine used to examine a single volume, contacting the VLDB as
1537 * well as the Volume Server.
1540 * as : Ptr to parsed command line arguments.
1543 * 0 for a successful operation,
1544 * Otherwise, one of the ubik or VolServer error values.
1547 * Nothing interesting.
1551 *------------------------------------------------------------------------
1554 ExamineVolume(struct cmd_syndesc *as, void *arock)
1556 struct nvldbentry entry;
1557 afs_int32 vcode = 0;
1558 volintInfo *pntr = (volintInfo *) 0;
1559 volintXInfo *xInfoP = (volintXInfo *) 0;
1561 afs_int32 code, err, error = 0;
1562 int voltype, foundserv = 0, foundentry = 0;
1566 int wantExtendedInfo; /*Do we want extended vol info? */
1567 int isSubEnum=0; /* Keep track whether sub enumerate called. */
1568 wantExtendedInfo = (as->parms[1].items ? 1 : 0); /* -extended */
1570 volid = vsu_GetVolumeID(as->parms[0].items->data, cstruct, &err); /* -id */
1573 PrintError("", err);
1575 fprintf(STDERR, "Unknown volume ID or name '%s'\n",
1576 as->parms[0].items->data);
1581 fprintf(STDOUT, "Fetching VLDB entry for %lu .. ",
1582 (unsigned long)volid);
1585 vcode = VLDB_GetEntryByID(volid, -1, &entry);
1588 "Could not fetch the entry for volume number %lu from VLDB \n",
1589 (unsigned long)volid);
1593 fprintf(STDOUT, "done\n");
1594 MapHostToNetwork(&entry);
1596 if (entry.volumeId[RWVOL] == volid)
1598 else if (entry.volumeId[BACKVOL] == volid)
1600 else /* (entry.volumeId[ROVOL] == volid) */
1603 do { /* do {...} while (voltype == ROVOL) */
1604 /* Get the entry for the volume. If its a RW vol, get the RW entry.
1605 * It its a BK vol, get the RW entry (even if VLDB may say the BK doen't exist).
1606 * If its a RO vol, get the next RO entry.
1608 GetServerAndPart(&entry, ((voltype == ROVOL) ? ROVOL : RWVOL),
1609 &aserver, &apart, &previdx);
1610 if (previdx == -1) { /* searched all entries */
1612 fprintf(STDERR, "Volume %s does not exist in VLDB\n\n",
1613 as->parms[0].items->data);
1620 /* Get information about the volume from the server */
1622 fprintf(STDOUT, "Getting volume listing from the server %s .. ",
1623 hostutil_GetNameByINet(aserver));
1626 if (wantExtendedInfo)
1627 code = UV_XListOneVolume(aserver, apart, volid, &xInfoP);
1629 code = UV_ListOneVolume(aserver, apart, volid, &pntr);
1631 fprintf(STDOUT, "done\n");
1635 if (code == ENODEV) {
1636 if ((voltype == BACKVOL) && !(entry.flags & BACK_EXISTS)) {
1637 /* The VLDB says there is no backup volume and its not on disk */
1638 fprintf(STDERR, "Volume %s does not exist\n",
1639 as->parms[0].items->data);
1643 "Volume does not exist on server %s as indicated by the VLDB\n",
1644 hostutil_GetNameByINet(aserver));
1647 PrintDiagnostics("examine", code);
1649 fprintf(STDOUT, "\n");
1652 if (wantExtendedInfo)
1653 XVolumeStats(xInfoP, &entry, aserver, apart, voltype);
1654 else if (as->parms[2].items) {
1655 DisplayFormat2(aserver, apart, pntr);
1656 EnumerateEntry(&entry);
1659 VolumeStats_int(pntr, &entry, aserver, apart, voltype);
1661 if ((voltype == BACKVOL) && !(entry.flags & BACK_EXISTS)) {
1662 /* The VLDB says there is no backup volume yet we found one on disk */
1663 fprintf(STDERR, "Volume %s does not exist in VLDB\n",
1664 as->parms[0].items->data);
1673 } while (voltype == ROVOL);
1676 fprintf(STDERR, "Dump only information from VLDB\n\n");
1677 fprintf(STDOUT, "%s \n", entry.name); /* PostVolumeStats doesn't print name */
1681 PostVolumeStats(&entry);
1686 /*------------------------------------------------------------------------
1690 * Routine used to change the status of a single volume.
1693 * as : Ptr to parsed command line arguments.
1696 * 0 for a successful operation,
1697 * Otherwise, one of the ubik or VolServer error values.
1700 * Nothing interesting.
1704 *------------------------------------------------------------------------
1707 SetFields(struct cmd_syndesc *as, void *arock)
1709 struct nvldbentry entry;
1712 afs_int32 code, err;
1717 volid = vsu_GetVolumeID(as->parms[0].items->data, cstruct, &err); /* -id */
1720 PrintError("", err);
1722 fprintf(STDERR, "Unknown volume ID or name '%s'\n",
1723 as->parms[0].items->data);
1727 code = VLDB_GetEntryByID(volid, RWVOL, &entry);
1730 "Could not fetch the entry for volume number %lu from VLDB \n",
1731 (unsigned long)volid);
1734 MapHostToNetwork(&entry);
1736 GetServerAndPart(&entry, RWVOL, &aserver, &apart, &previdx);
1737 if (previdx == -1) {
1738 fprintf(STDERR, "Volume %s does not exist in VLDB\n\n",
1739 as->parms[0].items->data);
1743 init_volintInfo(&info);
1747 if (as->parms[1].items) {
1749 code = util_GetHumanInt32(as->parms[1].items->data, &info.maxquota);
1751 fprintf(STDERR, "invalid quota value\n");
1755 if (as->parms[2].items) {
1759 if (as->parms[3].items) {
1760 /* -clearVolUpCounter */
1763 code = UV_SetVolumeInfo(aserver, apart, volid, &info);
1766 "Could not update volume info fields for volume number %lu\n",
1767 (unsigned long)volid);
1771 /*------------------------------------------------------------------------
1775 * Brings a volume online.
1778 * as : Ptr to parsed command line arguments.
1781 * 0 for a successful operation,
1784 * Nothing interesting.
1788 *------------------------------------------------------------------------
1791 volOnline(struct cmd_syndesc *as, void *arock)
1794 afs_int32 partition;
1796 afs_int32 code, err = 0;
1798 server = GetServer(as->parms[0].items->data);
1800 fprintf(STDERR, "vos: server '%s' not found in host table\n",
1801 as->parms[0].items->data);
1805 partition = volutil_GetPartitionID(as->parms[1].items->data);
1806 if (partition < 0) {
1807 fprintf(STDERR, "vos: could not interpret partition name '%s'\n",
1808 as->parms[1].items->data);
1812 volid = vsu_GetVolumeID(as->parms[2].items->data, cstruct, &err); /* -id */
1815 PrintError("", err);
1817 fprintf(STDERR, "Unknown volume ID or name '%s'\n",
1818 as->parms[0].items->data);
1822 code = UV_SetVolume(server, partition, volid, ITOffline, 0 /*online */ ,
1825 fprintf(STDERR, "Failed to set volume. Code = %d\n", code);
1832 /*------------------------------------------------------------------------
1833 * PRIVATE volOffline
1836 * Brings a volume offline.
1839 * as : Ptr to parsed command line arguments.
1842 * 0 for a successful operation,
1845 * Nothing interesting.
1849 *------------------------------------------------------------------------
1852 volOffline(struct cmd_syndesc *as, void *arock)
1855 afs_int32 partition;
1857 afs_int32 code, err = 0;
1858 afs_int32 transflag, sleeptime, transdone;
1860 server = GetServer(as->parms[0].items->data);
1862 fprintf(STDERR, "vos: server '%s' not found in host table\n",
1863 as->parms[0].items->data);
1867 partition = volutil_GetPartitionID(as->parms[1].items->data);
1868 if (partition < 0) {
1869 fprintf(STDERR, "vos: could not interpret partition name '%s'\n",
1870 as->parms[1].items->data);
1874 volid = vsu_GetVolumeID(as->parms[2].items->data, cstruct, &err); /* -id */
1877 PrintError("", err);
1879 fprintf(STDERR, "Unknown volume ID or name '%s'\n",
1880 as->parms[0].items->data);
1884 transflag = (as->parms[4].items ? ITBusy : ITOffline);
1885 sleeptime = (as->parms[3].items ? atol(as->parms[3].items->data) : 0);
1886 transdone = (sleeptime ? 0 /*online */ : VTOutOfService);
1887 if (as->parms[4].items && !as->parms[3].items) {
1888 fprintf(STDERR, "-sleep option must be used with -busy flag\n");
1893 UV_SetVolume(server, partition, volid, transflag, transdone,
1896 fprintf(STDERR, "Failed to set volume. Code = %d\n", code);
1904 CreateVolume(struct cmd_syndesc *as, void *arock)
1908 afs_uint32 volid = 0, rovolid = 0, bkvolid = 0;
1909 afs_uint32 *arovolid;
1911 struct nvldbentry entry;
1915 arovolid = &rovolid;
1918 tserver = GetServer(as->parms[0].items->data);
1920 fprintf(STDERR, "vos: host '%s' not found in host table\n",
1921 as->parms[0].items->data);
1924 pnum = volutil_GetPartitionID(as->parms[1].items->data);
1926 fprintf(STDERR, "vos: could not interpret partition name '%s'\n",
1927 as->parms[1].items->data);
1930 if (!IsPartValid(pnum, tserver, &code)) { /*check for validity of the partition */
1932 PrintError("", code);
1935 "vos : partition %s does not exist on the server\n",
1936 as->parms[1].items->data);
1939 if (!ISNAMEVALID(as->parms[2].items->data)) {
1941 "vos: the name of the root volume %s exceeds the size limit of %d\n",
1942 as->parms[2].items->data, VOLSER_OLDMAXVOLNAME - 10);
1945 if (!VolNameOK(as->parms[2].items->data)) {
1947 "Illegal volume name %s, should not end in .readonly or .backup\n",
1948 as->parms[2].items->data);
1951 if (IsNumeric(as->parms[2].items->data)) {
1952 fprintf(STDERR, "Illegal volume name %s, should not be a number\n",
1953 as->parms[2].items->data);
1956 vcode = VLDB_GetEntryByName(as->parms[2].items->data, &entry);
1958 fprintf(STDERR, "Volume %s already exists\n",
1959 as->parms[2].items->data);
1960 PrintDiagnostics("create", code);
1964 if (as->parms[3].items) {
1965 code = util_GetHumanInt32(as->parms[3].items->data, "a);
1967 fprintf(STDERR, "vos: bad integer specified for quota.\n");
1972 if (as->parms[4].items) {
1973 if (!IsNumeric(as->parms[4].items->data)) {
1974 fprintf(STDERR, "vos: Given volume ID %s should be numeric.\n",
1975 as->parms[4].items->data);
1979 code = util_GetUInt32(as->parms[4].items->data, &volid);
1981 fprintf(STDERR, "vos: bad integer specified for volume ID.\n");
1986 if (as->parms[5].items) {
1987 if (!IsNumeric(as->parms[5].items->data)) {
1988 fprintf(STDERR, "vos: Given RO volume ID %s should be numeric.\n",
1989 as->parms[5].items->data);
1993 code = util_GetUInt32(as->parms[5].items->data, &rovolid);
1995 fprintf(STDERR, "vos: bad integer specified for volume ID.\n");
2005 UV_CreateVolume3(tserver, pnum, as->parms[2].items->data, quota, 0,
2006 0, 0, 0, &volid, arovolid, &bkvolid);
2008 PrintDiagnostics("create", code);
2011 MapPartIdIntoName(pnum, part);
2012 fprintf(STDOUT, "Volume %lu created on partition %s of %s\n",
2013 (unsigned long)volid, part, as->parms[0].items->data);
2020 DeleteAll(struct nvldbentry *entry)
2023 afs_int32 error, code, curserver, curpart;
2026 MapHostToNetwork(entry);
2028 for (i = 0; i < entry->nServers; i++) {
2029 curserver = entry->serverNumber[i];
2030 curpart = entry->serverPartition[i];
2031 if (entry->serverFlags[i] & ITSROVOL) {
2032 volid = entry->volumeId[ROVOL];
2034 volid = entry->volumeId[RWVOL];
2036 code = UV_DeleteVolume(curserver, curpart, volid);
2045 DeleteVolume(struct cmd_syndesc *as, void *arock)
2047 afs_int32 err, code = 0;
2048 afs_uint32 server = 0;
2049 afs_int32 partition = -1;
2054 if (as->parms[0].items) {
2055 server = GetServer(as->parms[0].items->data);
2057 fprintf(STDERR, "vos: server '%s' not found in host table\n",
2058 as->parms[0].items->data);
2063 if (as->parms[1].items) {
2064 partition = volutil_GetPartitionID(as->parms[1].items->data);
2065 if (partition < 0) {
2066 fprintf(STDERR, "vos: could not interpret partition name '%s'\n",
2067 as->parms[1].items->data);
2071 /* Check for validity of the partition */
2072 if (!IsPartValid(partition, server, &code)) {
2074 PrintError("", code);
2077 "vos : partition %s does not exist on the server\n",
2078 as->parms[1].items->data);
2084 volid = vsu_GetVolumeID(as->parms[2].items->data, cstruct, &err);
2086 fprintf(STDERR, "Can't find volume name '%s' in VLDB\n",
2087 as->parms[2].items->data);
2089 PrintError("", err);
2093 /* If the server or partition option are not complete, try to fill
2094 * them in from the VLDB entry.
2096 if ((partition == -1) || !server) {
2097 struct nvldbentry entry;
2099 code = VLDB_GetEntryByID(volid, -1, &entry);
2102 "Could not fetch the entry for volume %lu from VLDB\n",
2103 (unsigned long)volid);
2104 PrintError("", code);
2108 if (((volid == entry.volumeId[RWVOL]) && (entry.flags & RW_EXISTS))
2109 || ((volid == entry.volumeId[BACKVOL])
2110 && (entry.flags & BACK_EXISTS))) {
2111 idx = Lp_GetRwIndex(&entry);
2112 if ((idx == -1) || (server && (server != entry.serverNumber[idx]))
2113 || ((partition != -1)
2114 && (partition != entry.serverPartition[idx]))) {
2115 fprintf(STDERR, "VLDB: Volume '%s' no match\n",
2116 as->parms[2].items->data);
2119 } else if ((volid == entry.volumeId[ROVOL])
2120 && (entry.flags & RO_EXISTS)) {
2121 for (idx = -1, j = 0; j < entry.nServers; j++) {
2122 if (entry.serverFlags[j] != ITSROVOL)
2125 if (((server == 0) || (server == entry.serverNumber[j]))
2126 && ((partition == -1)
2127 || (partition == entry.serverPartition[j]))) {
2130 "VLDB: Volume '%s' matches more than one RO\n",
2131 as->parms[2].items->data);
2138 fprintf(STDERR, "VLDB: Volume '%s' no match\n",
2139 as->parms[2].items->data);
2143 fprintf(STDERR, "VLDB: Volume '%s' no match\n",
2144 as->parms[2].items->data);
2148 server = htonl(entry.serverNumber[idx]);
2149 partition = entry.serverPartition[idx];
2153 code = UV_DeleteVolume(server, partition, volid);
2155 PrintDiagnostics("remove", code);
2159 MapPartIdIntoName(partition, pname);
2160 fprintf(STDOUT, "Volume %lu on partition %s server %s deleted\n",
2161 (unsigned long)volid, pname, hostutil_GetNameByINet(server));
2165 #define TESTM 0 /* set for move space tests, clear for production */
2167 MoveVolume(struct cmd_syndesc *as, void *arock)
2171 afs_uint32 fromserver, toserver;
2172 afs_int32 frompart, topart;
2173 afs_int32 flags, code, err;
2174 char fromPartName[10], toPartName[10];
2176 struct diskPartition64 partition; /* for space check */
2179 volid = vsu_GetVolumeID(as->parms[0].items->data, cstruct, &err);
2182 PrintError("", err);
2184 fprintf(STDERR, "vos: can't find volume ID or name '%s'\n",
2185 as->parms[0].items->data);
2188 fromserver = GetServer(as->parms[1].items->data);
2189 if (fromserver == 0) {
2190 fprintf(STDERR, "vos: server '%s' not found in host table\n",
2191 as->parms[1].items->data);
2194 toserver = GetServer(as->parms[3].items->data);
2195 if (toserver == 0) {
2196 fprintf(STDERR, "vos: server '%s' not found in host table\n",
2197 as->parms[3].items->data);
2200 frompart = volutil_GetPartitionID(as->parms[2].items->data);
2202 fprintf(STDERR, "vos: could not interpret partition name '%s'\n",
2203 as->parms[2].items->data);
2206 if (!IsPartValid(frompart, fromserver, &code)) { /*check for validity of the partition */
2208 PrintError("", code);
2211 "vos : partition %s does not exist on the server\n",
2212 as->parms[2].items->data);
2215 topart = volutil_GetPartitionID(as->parms[4].items->data);
2217 fprintf(STDERR, "vos: could not interpret partition name '%s'\n",
2218 as->parms[4].items->data);
2221 if (!IsPartValid(topart, toserver, &code)) { /*check for validity of the partition */
2223 PrintError("", code);
2226 "vos : partition %s does not exist on the server\n",
2227 as->parms[4].items->data);
2232 if (as->parms[5].items) flags |= RV_NOCLONE;
2235 * check source partition for space to clone volume
2238 MapPartIdIntoName(topart, toPartName);
2239 MapPartIdIntoName(frompart, fromPartName);
2242 * check target partition for space to move volume
2245 code = UV_PartitionInfo64(toserver, toPartName, &partition);
2247 fprintf(STDERR, "vos: cannot access partition %s\n", toPartName);
2251 fprintf(STDOUT, "target partition %s free space %" AFS_INT64_FMT "\n", toPartName,
2254 p = (volintInfo *) 0;
2255 code = UV_ListOneVolume(fromserver, frompart, volid, &p);
2257 fprintf(STDERR, "vos:cannot access volume %lu\n",
2258 (unsigned long)volid);
2262 fprintf(STDOUT, "volume %lu size %d\n", (unsigned long)volid,
2264 if (partition.free <= p->size) {
2266 "vos: no space on target partition %s to move volume %lu\n",
2267 toPartName, (unsigned long)volid);
2274 fprintf(STDOUT, "size test - don't do move\n");
2278 /* successful move still not guaranteed but shoot for it */
2281 UV_MoveVolume2(volid, fromserver, frompart, toserver, topart, flags);
2283 PrintDiagnostics("move", code);
2286 MapPartIdIntoName(topart, toPartName);
2287 MapPartIdIntoName(frompart, fromPartName);
2288 fprintf(STDOUT, "Volume %lu moved from %s %s to %s %s \n",
2289 (unsigned long)volid, as->parms[1].items->data, fromPartName,
2290 as->parms[3].items->data, toPartName);
2296 CopyVolume(struct cmd_syndesc *as, void *arock)
2299 afs_uint32 fromserver, toserver;
2300 afs_int32 frompart, topart, code, err, flags;
2301 char fromPartName[10], toPartName[10], *tovolume;
2302 struct nvldbentry entry;
2303 struct diskPartition64 partition; /* for space check */
2306 volid = vsu_GetVolumeID(as->parms[0].items->data, cstruct, &err);
2309 PrintError("", err);
2311 fprintf(STDERR, "vos: can't find volume ID or name '%s'\n",
2312 as->parms[0].items->data);
2315 fromserver = GetServer(as->parms[1].items->data);
2316 if (fromserver == 0) {
2317 fprintf(STDERR, "vos: server '%s' not found in host table\n",
2318 as->parms[1].items->data);
2322 toserver = GetServer(as->parms[4].items->data);
2323 if (toserver == 0) {
2324 fprintf(STDERR, "vos: server '%s' not found in host table\n",
2325 as->parms[4].items->data);
2329 tovolume = as->parms[3].items->data;
2330 if (!ISNAMEVALID(tovolume)) {
2332 "vos: the name of the root volume %s exceeds the size limit of %d\n",
2333 tovolume, VOLSER_OLDMAXVOLNAME - 10);
2336 if (!VolNameOK(tovolume)) {
2338 "Illegal volume name %s, should not end in .readonly or .backup\n",
2342 if (IsNumeric(tovolume)) {
2343 fprintf(STDERR, "Illegal volume name %s, should not be a number\n",
2347 code = VLDB_GetEntryByName(tovolume, &entry);
2349 fprintf(STDERR, "Volume %s already exists\n", tovolume);
2350 PrintDiagnostics("copy", code);
2354 frompart = volutil_GetPartitionID(as->parms[2].items->data);
2356 fprintf(STDERR, "vos: could not interpret partition name '%s'\n",
2357 as->parms[2].items->data);
2360 if (!IsPartValid(frompart, fromserver, &code)) { /*check for validity of the partition */
2362 PrintError("", code);
2365 "vos : partition %s does not exist on the server\n",
2366 as->parms[2].items->data);
2370 topart = volutil_GetPartitionID(as->parms[5].items->data);
2372 fprintf(STDERR, "vos: could not interpret partition name '%s'\n",
2373 as->parms[5].items->data);
2376 if (!IsPartValid(topart, toserver, &code)) { /*check for validity of the partition */
2378 PrintError("", code);
2381 "vos : partition %s does not exist on the server\n",
2382 as->parms[5].items->data);
2387 if (as->parms[6].items) flags |= RV_OFFLINE;
2388 if (as->parms[7].items) flags |= RV_RDONLY;
2389 if (as->parms[8].items) flags |= RV_NOCLONE;
2391 MapPartIdIntoName(topart, toPartName);
2392 MapPartIdIntoName(frompart, fromPartName);
2395 * check target partition for space to move volume
2398 code = UV_PartitionInfo64(toserver, toPartName, &partition);
2400 fprintf(STDERR, "vos: cannot access partition %s\n", toPartName);
2404 fprintf(STDOUT, "target partition %s free space %" AFS_INT64_FMT "\n", toPartName,
2407 p = (volintInfo *) 0;
2408 code = UV_ListOneVolume(fromserver, frompart, volid, &p);
2410 fprintf(STDERR, "vos:cannot access volume %lu\n",
2411 (unsigned long)volid);
2415 if (partition.free <= p->size) {
2417 "vos: no space on target partition %s to copy volume %lu\n",
2418 toPartName, (unsigned long)volid);
2424 /* successful copy still not guaranteed but shoot for it */
2427 UV_CopyVolume2(volid, fromserver, frompart, tovolume, toserver,
2430 PrintDiagnostics("copy", code);
2433 MapPartIdIntoName(topart, toPartName);
2434 MapPartIdIntoName(frompart, fromPartName);
2435 fprintf(STDOUT, "Volume %lu copied from %s %s to %s on %s %s \n",
2436 (unsigned long)volid, as->parms[1].items->data, fromPartName,
2437 tovolume, as->parms[4].items->data, toPartName);
2444 ShadowVolume(struct cmd_syndesc *as, void *arock)
2446 afs_uint32 volid, tovolid;
2447 afs_uint32 fromserver, toserver;
2448 afs_int32 frompart, topart;
2449 afs_int32 code, err, flags;
2450 char fromPartName[10], toPartName[10], toVolName[32], *tovolume;
2451 struct diskPartition64 partition; /* for space check */
2454 p = (volintInfo *) 0;
2455 q = (volintInfo *) 0;
2457 volid = vsu_GetVolumeID(as->parms[0].items->data, cstruct, &err);
2460 PrintError("", err);
2462 fprintf(STDERR, "vos: can't find volume ID or name '%s'\n",
2463 as->parms[0].items->data);
2466 fromserver = GetServer(as->parms[1].items->data);
2467 if (fromserver == 0) {
2468 fprintf(STDERR, "vos: server '%s' not found in host table\n",
2469 as->parms[1].items->data);
2473 toserver = GetServer(as->parms[3].items->data);
2474 if (toserver == 0) {
2475 fprintf(STDERR, "vos: server '%s' not found in host table\n",
2476 as->parms[3].items->data);
2480 frompart = volutil_GetPartitionID(as->parms[2].items->data);
2482 fprintf(STDERR, "vos: could not interpret partition name '%s'\n",
2483 as->parms[2].items->data);
2486 if (!IsPartValid(frompart, fromserver, &code)) { /*check for validity of the partition */
2488 PrintError("", code);
2491 "vos : partition %s does not exist on the server\n",
2492 as->parms[2].items->data);
2496 topart = volutil_GetPartitionID(as->parms[4].items->data);
2498 fprintf(STDERR, "vos: could not interpret partition name '%s'\n",
2499 as->parms[4].items->data);
2502 if (!IsPartValid(topart, toserver, &code)) { /*check for validity of the partition */
2504 PrintError("", code);
2507 "vos : partition %s does not exist on the server\n",
2508 as->parms[4].items->data);
2512 if (as->parms[5].items) {
2513 tovolume = as->parms[5].items->data;
2514 if (!ISNAMEVALID(tovolume)) {
2516 "vos: the name of the root volume %s exceeds the size limit of %d\n",
2517 tovolume, VOLSER_OLDMAXVOLNAME - 10);
2520 if (!VolNameOK(tovolume)) {
2522 "Illegal volume name %s, should not end in .readonly or .backup\n",
2526 if (IsNumeric(tovolume)) {
2528 "Illegal volume name %s, should not be a number\n",
2533 /* use actual name of source volume */
2534 code = UV_ListOneVolume(fromserver, frompart, volid, &p);
2536 fprintf(STDERR, "vos:cannot access volume %lu\n",
2537 (unsigned long)volid);
2540 strcpy(toVolName, p->name);
2541 tovolume = toVolName;
2542 /* save p for size checks later */
2545 if (as->parms[6].items) {
2546 tovolid = vsu_GetVolumeID(as->parms[6].items->data, cstruct, &err);
2549 PrintError("", err);
2551 fprintf(STDERR, "vos: can't find volume ID or name '%s'\n",
2552 as->parms[6].items->data);
2558 tovolid = vsu_GetVolumeID(tovolume, cstruct, &err);
2561 PrintError("", err);
2563 fprintf(STDERR, "vos: can't find volume ID or name '%s'\n",
2572 if (as->parms[7].items) flags |= RV_OFFLINE;
2573 if (as->parms[8].items) flags |= RV_RDONLY;
2574 if (as->parms[9].items) flags |= RV_NOCLONE;
2575 if (as->parms[10].items) flags |= RV_CPINCR;
2577 MapPartIdIntoName(topart, toPartName);
2578 MapPartIdIntoName(frompart, fromPartName);
2581 * check target partition for space to move volume
2584 code = UV_PartitionInfo64(toserver, toPartName, &partition);
2586 fprintf(STDERR, "vos: cannot access partition %s\n", toPartName);
2590 fprintf(STDOUT, "target partition %s free space %" AFS_INT64_FMT "\n", toPartName,
2593 /* Don't do this again if we did it above */
2595 code = UV_ListOneVolume(fromserver, frompart, volid, &p);
2597 fprintf(STDERR, "vos:cannot access volume %lu\n",
2598 (unsigned long)volid);
2603 /* OK if this fails */
2604 code = UV_ListOneVolume(toserver, topart, tovolid, &q);
2606 /* Treat existing volume size as "free" */
2608 p->size = (q->size < p->size) ? p->size - q->size : 0;
2610 if (partition.free <= p->size) {
2612 "vos: no space on target partition %s to copy volume %lu\n",
2613 toPartName, (unsigned long)volid);
2621 /* successful copy still not guaranteed but shoot for it */
2624 UV_CopyVolume2(volid, fromserver, frompart, tovolume, toserver,
2625 topart, tovolid, flags);
2627 PrintDiagnostics("shadow", code);
2630 MapPartIdIntoName(topart, toPartName);
2631 MapPartIdIntoName(frompart, fromPartName);
2632 fprintf(STDOUT, "Volume %lu shadowed from %s %s to %s %s \n",
2633 (unsigned long)volid, as->parms[1].items->data, fromPartName,
2634 as->parms[3].items->data, toPartName);
2641 CloneVolume(struct cmd_syndesc *as, void *arock)
2643 afs_uint32 volid, cloneid;
2645 afs_int32 part, voltype;
2646 char partName[10], *volname;
2647 afs_int32 code, err, flags;
2648 struct nvldbentry entry;
2650 volid = vsu_GetVolumeID(as->parms[0].items->data, cstruct, &err);
2653 PrintError("", err);
2655 fprintf(STDERR, "vos: can't find volume ID or name '%s'\n",
2656 as->parms[0].items->data);
2660 if (as->parms[1].items || as->parms[2].items) {
2661 if (!as->parms[1].items || !as->parms[2].items) {
2663 "Must specify both -server and -partition options\n");
2666 server = GetServer(as->parms[1].items->data);
2668 fprintf(STDERR, "vos: server '%s' not found in host table\n",
2669 as->parms[1].items->data);
2672 part = volutil_GetPartitionID(as->parms[2].items->data);
2674 fprintf(STDERR, "vos: could not interpret partition name '%s'\n",
2675 as->parms[2].items->data);
2678 if (!IsPartValid(part, server, &code)) { /*check for validity of the partition */
2680 PrintError("", code);
2683 "vos : partition %s does not exist on the server\n",
2684 as->parms[2].items->data);
2688 code = GetVolumeInfo(volid, &server, &part, &voltype, &entry);
2694 if (as->parms[3].items) {
2695 volname = as->parms[3].items->data;
2696 if (strlen(volname) > VOLSER_OLDMAXVOLNAME - 1) {
2698 "vos: the name of the root volume %s exceeds the size limit of %d\n",
2699 volname, VOLSER_OLDMAXVOLNAME - 1);
2704 * In order that you be able to make clones of RO or BK, this
2705 * check must be omitted.
2707 if (!VolNameOK(volname)) {
2709 "Illegal volume name %s, should not end in .readonly or .backup\n",
2714 if (IsNumeric(volname)) {
2716 "Illegal volume name %s, should not be a number\n",
2723 if (as->parms[4].items) {
2724 cloneid = vsu_GetVolumeID(as->parms[4].items->data, cstruct, &err);
2727 PrintError("", err);
2729 fprintf(STDERR, "vos: can't find volume ID or name '%s'\n",
2730 as->parms[4].items->data);
2736 if (as->parms[5].items) flags |= RV_OFFLINE;
2737 if (as->parms[6].items) flags |= RV_RDONLY;
2741 UV_CloneVolume(server, part, volid, cloneid, volname, flags);
2744 PrintDiagnostics("clone", code);
2747 MapPartIdIntoName(part, partName);
2748 fprintf(STDOUT, "Created clone for volume %s\n",
2749 as->parms[0].items->data);
2756 BackupVolume(struct cmd_syndesc *as, void *arock)
2760 afs_int32 apart, vtype, code, err;
2761 struct nvldbentry entry;
2764 afs_uint32 buserver;
2765 afs_int32 bupart, butype;
2766 struct nvldbentry buentry;
2768 avolid = vsu_GetVolumeID(as->parms[0].items->data, cstruct, &err);
2771 PrintError("", err);
2773 fprintf(STDERR, "vos: can't find volume ID or name '%s'\n",
2774 as->parms[0].items->data);
2777 code = GetVolumeInfo(avolid, &aserver, &apart, &vtype, &entry);
2781 /* verify this is a readwrite volume */
2783 if (vtype != RWVOL) {
2784 fprintf(STDERR, "%s not RW volume\n", as->parms[0].items->data);
2788 /* is there a backup volume already? */
2790 if (entry.flags & BACK_EXISTS) {
2791 /* yep, where is it? */
2793 buvolid = entry.volumeId[BACKVOL];
2794 code = GetVolumeInfo(buvolid, &buserver, &bupart, &butype, &buentry);
2799 code = VLDB_IsSameAddrs(buserver, aserver, &err);
2802 "Failed to get info about server's %d address(es) from vlserver; aborting call!\n",
2808 "FATAL ERROR: backup volume %lu exists on server %lu\n",
2809 (unsigned long)buvolid, (unsigned long)buserver);
2814 /* nope, carry on */
2816 code = UV_BackupVolume(aserver, apart, avolid);
2819 PrintDiagnostics("backup", code);
2822 fprintf(STDOUT, "Created backup volume for %s \n",
2823 as->parms[0].items->data);
2828 ReleaseVolume(struct cmd_syndesc *as, void *arock)
2831 struct nvldbentry entry;
2834 afs_int32 apart, vtype, code, err;
2837 if (as->parms[1].items)
2839 avolid = vsu_GetVolumeID(as->parms[0].items->data, cstruct, &err);
2842 PrintError("", err);
2844 fprintf(STDERR, "vos: can't find volume '%s'\n",
2845 as->parms[0].items->data);
2848 code = GetVolumeInfo(avolid, &aserver, &apart, &vtype, &entry);
2852 if (vtype != RWVOL) {
2853 fprintf(STDERR, "%s not a RW volume\n", as->parms[0].items->data);
2857 if (!ISNAMEVALID(entry.name)) {
2859 "Volume name %s is too long, rename before releasing\n",
2864 code = UV_ReleaseVolume(avolid, aserver, apart, force);
2866 PrintDiagnostics("release", code);
2869 fprintf(STDOUT, "Released volume %s successfully\n",
2870 as->parms[0].items->data);
2875 DumpVolumeCmd(struct cmd_syndesc *as, void *arock)
2879 afs_int32 apart, voltype, fromdate = 0, code, err, i, flags;
2880 char filename[MAXPATHLEN];
2881 struct nvldbentry entry;
2883 rx_SetRxDeadTime(60 * 10);
2884 for (i = 0; i < MAXSERVERS; i++) {
2885 struct rx_connection *rxConn = ubik_GetRPCConn(cstruct, i);
2888 rx_SetConnDeadTime(rxConn, rx_connDeadTime);
2889 if (rxConn->service)
2890 rxConn->service->connDeadTime = rx_connDeadTime;
2893 avolid = vsu_GetVolumeID(as->parms[0].items->data, cstruct, &err);
2896 PrintError("", err);
2898 fprintf(STDERR, "vos: can't find volume '%s'\n",
2899 as->parms[0].items->data);
2903 if (as->parms[3].items || as->parms[4].items) {
2904 if (!as->parms[3].items || !as->parms[4].items) {
2906 "Must specify both -server and -partition options\n");
2909 aserver = GetServer(as->parms[3].items->data);
2911 fprintf(STDERR, "Invalid server name\n");
2914 apart = volutil_GetPartitionID(as->parms[4].items->data);
2916 fprintf(STDERR, "Invalid partition name\n");
2920 code = GetVolumeInfo(avolid, &aserver, &apart, &voltype, &entry);
2925 if (as->parms[1].items && strcmp(as->parms[1].items->data, "0")) {
2926 code = ktime_DateToInt32(as->parms[1].items->data, &fromdate);
2928 fprintf(STDERR, "vos: failed to parse date '%s' (error=%d))\n",
2929 as->parms[1].items->data, code);
2933 if (as->parms[2].items) {
2934 strcpy(filename, as->parms[2].items->data);
2936 strcpy(filename, "");
2939 flags = as->parms[6].items ? VOLDUMPV2_OMITDIRS : 0;
2941 if (as->parms[5].items) {
2943 UV_DumpClonedVolume(avolid, aserver, apart, fromdate,
2944 DumpFunction, filename, flags);
2947 UV_DumpVolume(avolid, aserver, apart, fromdate, DumpFunction,
2950 if ((code == RXGEN_OPCODE) && (as->parms[6].items)) {
2951 flags &= ~VOLDUMPV2_OMITDIRS;
2955 PrintDiagnostics("dump", code);
2958 if (strcmp(filename, ""))
2959 fprintf(STDERR, "Dumped volume %s in file %s\n",
2960 as->parms[0].items->data, filename);
2962 fprintf(STDERR, "Dumped volume %s in stdout \n",
2963 as->parms[0].items->data);
2977 RestoreVolumeCmd(struct cmd_syndesc *as, void *arock)
2979 afs_uint32 avolid, aparentid;
2981 afs_int32 apart, code, vcode, err;
2982 afs_int32 aoverwrite = ASK;
2983 afs_int32 acreation = 0, alastupdate = 0;
2984 int restoreflags = 0;
2985 int readonly = 0, offline = 0, voltype = RWVOL;
2986 char afilename[MAXPATHLEN], avolname[VOLSER_MAXVOLNAME + 1], apartName[10];
2987 char volname[VOLSER_MAXVOLNAME + 1];
2988 struct nvldbentry entry;
2991 if (as->parms[4].items) {
2992 avolid = vsu_GetVolumeID(as->parms[4].items->data, cstruct, &err);
2995 PrintError("", err);
2997 fprintf(STDERR, "vos: can't find volume '%s'\n",
2998 as->parms[4].items->data);
3004 if (as->parms[5].items) {
3005 if ((strcmp(as->parms[5].items->data, "a") == 0)
3006 || (strcmp(as->parms[5].items->data, "abort") == 0)) {
3008 } else if ((strcmp(as->parms[5].items->data, "f") == 0)
3009 || (strcmp(as->parms[5].items->data, "full") == 0)) {
3011 } else if ((strcmp(as->parms[5].items->data, "i") == 0)
3012 || (strcmp(as->parms[5].items->data, "inc") == 0)
3013 || (strcmp(as->parms[5].items->data, "increment") == 0)
3014 || (strcmp(as->parms[5].items->data, "incremental") == 0)) {
3017 fprintf(STDERR, "vos: %s is not a valid argument to -overwrite\n",
3018 as->parms[5].items->data);
3022 if (as->parms[6].items)
3024 if (as->parms[7].items) {
3029 if (as->parms[8].items) {
3030 if ((strcmp(as->parms[8].items->data, "d") == 0)
3031 || (strcmp(as->parms[8].items->data, "dump") == 0)) {
3032 acreation = TS_DUMP;
3033 } else if ((strcmp(as->parms[8].items->data, "k") == 0)
3034 || (strcmp(as->parms[8].items->data, "keep") == 0)) {
3035 acreation = TS_KEEP;
3036 } else if ((strcmp(as->parms[8].items->data, "n") == 0)
3037 || (strcmp(as->parms[8].items->data, "new") == 0)) {
3040 fprintf(STDERR, "vos: %s is not a valid argument to -creation\n",
3041 as->parms[8].items->data);
3046 if (as->parms[9].items) {
3047 if ((strcmp(as->parms[9].items->data, "d") == 0)
3048 || (strcmp(as->parms[9].items->data, "dump") == 0)) {
3049 alastupdate = TS_DUMP;
3050 } else if ((strcmp(as->parms[9].items->data, "k") == 0)
3051 || (strcmp(as->parms[9].items->data, "keep") == 0)) {
3052 alastupdate = TS_KEEP;
3053 } else if ((strcmp(as->parms[9].items->data, "n") == 0)
3054 || (strcmp(as->parms[9].items->data, "new") == 0)) {
3055 alastupdate = TS_NEW;
3057 fprintf(STDERR, "vos: %s is not a valid argument to -lastupdate\n",
3058 as->parms[9].items->data);
3063 aserver = GetServer(as->parms[0].items->data);
3065 fprintf(STDERR, "vos: server '%s' not found in host table\n",
3066 as->parms[0].items->data);
3069 apart = volutil_GetPartitionID(as->parms[1].items->data);
3071 fprintf(STDERR, "vos: could not interpret partition name '%s'\n",
3072 as->parms[1].items->data);
3075 if (!IsPartValid(apart, aserver, &code)) { /*check for validity of the partition */
3077 PrintError("", code);
3080 "vos : partition %s does not exist on the server\n",
3081 as->parms[1].items->data);
3084 strcpy(avolname, as->parms[2].items->data);
3085 if (!ISNAMEVALID(avolname)) {
3087 "vos: the name of the volume %s exceeds the size limit\n",
3091 if (!VolNameOK(avolname)) {
3093 "Illegal volume name %s, should not end in .readonly or .backup\n",
3097 if (as->parms[3].items) {
3098 strcpy(afilename, as->parms[3].items->data);
3099 if (!FileExists(afilename)) {
3100 fprintf(STDERR, "Can't access file %s\n", afilename);
3104 strcpy(afilename, "");
3107 /* Check if volume exists or not */
3109 vsu_ExtractName(volname, avolname);
3110 vcode = VLDB_GetEntryByName(volname, &entry);
3111 if (vcode) { /* no volume - do a full restore */
3112 restoreflags = RV_FULLRST;
3113 if ((aoverwrite == INC) || (aoverwrite == ABORT))
3115 "Volume does not exist; Will perform a full restore\n");
3118 else if ((!readonly && Lp_GetRwIndex(&entry) == -1) /* RW volume does not exist - do a full */
3119 ||(readonly && !Lp_ROMatch(0, 0, &entry))) { /* RO volume does not exist - do a full */
3120 restoreflags = RV_FULLRST;
3121 if ((aoverwrite == INC) || (aoverwrite == ABORT))
3123 "%s Volume does not exist; Will perform a full restore\n",
3124 readonly ? "RO" : "RW");
3127 avolid = entry.volumeId[voltype];
3128 } else if (entry.volumeId[voltype] != 0
3129 && entry.volumeId[voltype] != avolid) {
3130 avolid = entry.volumeId[voltype];
3132 aparentid = entry.volumeId[RWVOL];
3135 else { /* volume exists - do we do a full incremental or abort */
3137 afs_int32 Opart, Otype, vol_elsewhere = 0;
3138 struct nvldbentry Oentry;
3142 avolid = entry.volumeId[voltype];
3143 } else if (entry.volumeId[voltype] != 0
3144 && entry.volumeId[voltype] != avolid) {
3145 avolid = entry.volumeId[voltype];
3147 aparentid = entry.volumeId[RWVOL];
3149 /* A file name was specified - check if volume is on another partition */
3150 vcode = GetVolumeInfo(avolid, &Oserver, &Opart, &Otype, &Oentry);
3154 vcode = VLDB_IsSameAddrs(Oserver, aserver, &err);
3157 "Failed to get info about server's %d address(es) from vlserver (err=%d); aborting call!\n",
3161 if (!vcode || (Opart != apart))
3164 if (aoverwrite == ASK) {
3165 if (strcmp(afilename, "") == 0) { /* The file is from standard in */
3167 "Volume exists and no -overwrite option specified; Aborting restore command\n");
3171 /* Ask what to do */
3172 if (vol_elsewhere) {
3174 "The volume %s %u already exists on a different server/part\n",
3175 volname, entry.volumeId[voltype]);
3177 "Do you want to do a full restore or abort? [fa](a): ");
3180 "The volume %s %u already exists in the VLDB\n",
3181 volname, entry.volumeId[voltype]);
3183 "Do you want to do a full/incremental restore or abort? [fia](a): ");
3186 while (!(dc == EOF || dc == '\n'))
3187 dc = getchar(); /* goto end of line */
3188 if ((c == 'f') || (c == 'F'))
3190 else if ((c == 'i') || (c == 'I'))
3196 if (aoverwrite == ABORT) {
3197 fprintf(STDERR, "Volume exists; Aborting restore command\n");
3199 } else if (aoverwrite == FULL) {
3200 restoreflags = RV_FULLRST;
3202 "Volume exists; Will delete and perform full restore\n");
3203 } else if (aoverwrite == INC) {
3205 if (vol_elsewhere) {
3207 "%s volume %lu already exists on a different server/part; not allowed\n",
3208 readonly ? "RO" : "RW", (unsigned long)avolid);
3214 restoreflags |= RV_OFFLINE;
3216 restoreflags |= RV_RDONLY;
3218 switch (acreation) {
3220 restoreflags |= RV_CRDUMP;
3223 restoreflags |= RV_CRKEEP;
3226 restoreflags |= RV_CRNEW;
3229 if (aoverwrite == FULL)
3230 restoreflags |= RV_CRNEW;
3232 restoreflags |= RV_CRKEEP;
3235 switch (alastupdate) {
3237 restoreflags |= RV_LUDUMP;
3240 restoreflags |= RV_LUKEEP;
3243 restoreflags |= RV_LUNEW;
3246 restoreflags |= RV_LUDUMP;
3248 if (as->parms[10].items) {
3249 restoreflags |= RV_NODEL;
3254 UV_RestoreVolume2(aserver, apart, avolid, aparentid,
3255 avolname, restoreflags, WriteData, afilename);
3257 PrintDiagnostics("restore", code);
3260 MapPartIdIntoName(apart, apartName);
3263 * patch typo here - originally "parms[1]", should be "parms[0]"
3266 fprintf(STDOUT, "Restored volume %s on %s %s\n", avolname,
3267 as->parms[0].items->data, apartName);
3272 LockReleaseCmd(struct cmd_syndesc *as, void *arock)
3275 afs_int32 code, err;
3277 avolid = vsu_GetVolumeID(as->parms[0].items->data, cstruct, &err);
3280 PrintError("", err);
3282 fprintf(STDERR, "vos: can't find volume '%s'\n",
3283 as->parms[0].items->data);
3287 code = UV_LockRelease(avolid);
3289 PrintDiagnostics("unlock", code);
3292 fprintf(STDOUT, "Released lock on vldb entry for volume %s\n",
3293 as->parms[0].items->data);
3298 AddSite(struct cmd_syndesc *as, void *arock)
3302 afs_int32 apart, code, err, arovolid, valid = 0;
3303 char apartName[10], avolname[VOLSER_MAXVOLNAME + 1];
3305 vsu_ExtractName(avolname, as->parms[2].items->data);;
3306 avolid = vsu_GetVolumeID(avolname, cstruct, &err);
3309 PrintError("", err);
3311 fprintf(STDERR, "vos: can't find volume '%s'\n",
3312 as->parms[2].items->data);
3316 if (as->parms[3].items) {
3317 vsu_ExtractName(avolname, as->parms[3].items->data);
3318 arovolid = vsu_GetVolumeID(avolname, cstruct, &err);
3320 fprintf(STDERR, "vos: invalid ro volume id '%s'\n",
3321 as->parms[3].items->data);
3325 aserver = GetServer(as->parms[0].items->data);
3327 fprintf(STDERR, "vos: server '%s' not found in host table\n",
3328 as->parms[0].items->data);
3331 apart = volutil_GetPartitionID(as->parms[1].items->data);
3333 fprintf(STDERR, "vos: could not interpret partition name '%s'\n",
3334 as->parms[1].items->data);
3337 if (!IsPartValid(apart, aserver, &code)) { /*check for validity of the partition */
3339 PrintError("", code);
3342 "vos : partition %s does not exist on the server\n",
3343 as->parms[1].items->data);
3346 if (as->parms[4].items) {
3349 code = UV_AddSite2(aserver, apart, avolid, arovolid, valid);
3351 PrintDiagnostics("addsite", code);
3354 MapPartIdIntoName(apart, apartName);
3355 fprintf(STDOUT, "Added replication site %s %s for volume %s\n",
3356 as->parms[0].items->data, apartName, as->parms[2].items->data);
3361 RemoveSite(struct cmd_syndesc *as, void *arock)
3366 afs_int32 apart, code, err;
3367 char apartName[10], avolname[VOLSER_MAXVOLNAME + 1];
3369 vsu_ExtractName(avolname, as->parms[2].items->data);
3370 avolid = vsu_GetVolumeID(avolname, cstruct, &err);
3373 PrintError("", err);
3375 fprintf(STDERR, "vos: can't find volume '%s'\n",
3376 as->parms[2].items->data);
3379 aserver = GetServer(as->parms[0].items->data);
3381 fprintf(STDERR, "vos: server '%s' not found in host table\n",
3382 as->parms[0].items->data);
3385 apart = volutil_GetPartitionID(as->parms[1].items->data);
3387 fprintf(STDERR, "vos: could not interpret partition name '%s'\n",
3388 as->parms[1].items->data);
3392 *skip the partition validity check, since it is possible that the partition
3393 *has since been decomissioned.
3396 if (!IsPartValid(apart,aserver,&code)){
3397 if(code) PrintError("",code);
3398 else fprintf(STDERR,"vos : partition %s does not exist on the server\n",as->parms[1].items->data);
3402 code = UV_RemoveSite(aserver, apart, avolid);
3404 PrintDiagnostics("remsite", code);
3407 MapPartIdIntoName(apart, apartName);
3408 fprintf(STDOUT, "Removed replication site %s %s for volume %s\n",
3409 as->parms[0].items->data, apartName, as->parms[2].items->data);
3414 ChangeLocation(struct cmd_syndesc *as, void *arock)
3418 afs_int32 apart, code, err;
3421 avolid = vsu_GetVolumeID(as->parms[2].items->data, cstruct, &err);
3424 PrintError("", err);
3426 fprintf(STDERR, "vos: can't find volume '%s'\n",
3427 as->parms[2].items->data);
3430 aserver = GetServer(as->parms[0].items->data);
3432 fprintf(STDERR, "vos: server '%s' not found in host table\n",
3433 as->parms[0].items->data);
3436 apart = volutil_GetPartitionID(as->parms[1].items->data);
3438 fprintf(STDERR, "vos: could not interpret partition name '%s'\n",
3439 as->parms[1].items->data);
3442 if (!IsPartValid(apart, aserver, &code)) { /*check for validity of the partition */
3444 PrintError("", code);
3447 "vos : partition %s does not exist on the server\n",
3448 as->parms[1].items->data);
3451 code = UV_ChangeLocation(aserver, apart, avolid);
3453 PrintDiagnostics("addsite", code);
3456 MapPartIdIntoName(apart, apartName);
3457 fprintf(STDOUT, "Changed location to %s %s for volume %s\n",
3458 as->parms[0].items->data, apartName, as->parms[2].items->data);
3463 ListPartitions(struct cmd_syndesc *as, void *arock)
3467 struct partList dummyPartList;
3472 aserver = GetServer(as->parms[0].items->data);
3474 fprintf(STDERR, "vos: server '%s' not found in host table\n",
3475 as->parms[0].items->data);
3480 code = UV_ListPartitions(aserver, &dummyPartList, &cnt);
3482 PrintDiagnostics("listpart", code);
3486 fprintf(STDOUT, "The partitions on the server are:\n");
3487 for (i = 0; i < cnt; i++) {
3488 if (dummyPartList.partFlags[i] & PARTVALID) {
3489 memset(pname, 0, sizeof(pname));
3490 MapPartIdIntoName(dummyPartList.partId[i], pname);
3491 fprintf(STDOUT, " %10s ", pname);
3493 if ((i % 5) == 0 && (i != 0))
3494 fprintf(STDOUT, "\n");
3497 fprintf(STDOUT, "\n");
3498 fprintf(STDOUT, "Total: %d\n", total);
3504 CompareVolName(const void *p1, const void *p2)
3506 volintInfo *arg1, *arg2;
3508 arg1 = (volintInfo *) p1;
3509 arg2 = (volintInfo *) p2;
3510 return (strcmp(arg1->name, arg2->name));
3514 /*------------------------------------------------------------------------
3515 * PRIVATE XCompareVolName
3518 * Comparison routine for volume names coming from an extended
3522 * a_obj1P : Char ptr to first extended vol info object
3523 * a_obj1P : Char ptr to second extended vol info object
3526 * The value of strcmp() on the volume names within the passed
3527 * objects (i,e., -1, 0, or 1).
3530 * Passed to qsort() as the designated comparison routine.
3534 *------------------------------------------------------------------------*/
3537 XCompareVolName(const void *a_obj1P, const void *a_obj2P)
3538 { /*XCompareVolName */
3541 (((struct volintXInfo *)(a_obj1P))->name,
3542 ((struct volintXInfo *)(a_obj2P))->name));
3544 } /*XCompareVolName */
3547 CompareVolID(const void *p1, const void *p2)
3549 volintInfo *arg1, *arg2;
3551 arg1 = (volintInfo *) p1;
3552 arg2 = (volintInfo *) p2;
3553 if (arg1->volid == arg2->volid)
3555 if (arg1->volid > arg2->volid)
3562 /*------------------------------------------------------------------------
3563 * PRIVATE XCompareVolID
3566 * Comparison routine for volume IDs coming from an extended
3570 * a_obj1P : Char ptr to first extended vol info object
3571 * a_obj1P : Char ptr to second extended vol info object
3574 * The value of strcmp() on the volume names within the passed
3575 * objects (i,e., -1, 0, or 1).
3578 * Passed to qsort() as the designated comparison routine.
3582 *------------------------------------------------------------------------*/
3585 XCompareVolID(const void *a_obj1P, const void *a_obj2P)
3586 { /*XCompareVolID */
3588 afs_int32 id1, id2; /*Volume IDs we're comparing */
3590 id1 = ((struct volintXInfo *)(a_obj1P))->volid;
3591 id2 = ((struct volintXInfo *)(a_obj2P))->volid;
3599 } /*XCompareVolID */
3601 /*------------------------------------------------------------------------
3602 * PRIVATE ListVolumes
3605 * Routine used to list volumes, contacting the Volume Server
3606 * directly, bypassing the VLDB.
3609 * as : Ptr to parsed command line arguments.
3612 * 0 Successful operation
3615 * Nothing interesting.
3619 *------------------------------------------------------------------------*/
3622 ListVolumes(struct cmd_syndesc *as, void *arock)
3624 afs_int32 apart, int32list, fast;
3628 volintInfo *oldpntr = NULL;
3632 volintXInfo *xInfoP;
3633 volintXInfo *origxInfoP = NULL; /*Ptr to current/orig extended vol info */
3634 int wantExtendedInfo; /*Do we want extended vol info? */
3637 struct partList dummyPartList;
3645 if (as->parms[3].items)
3647 if (as->parms[4].items)
3651 if (as->parms[2].items)
3657 if (as->parms[5].items) {
3659 * We can't coexist with the fast flag.
3663 "vos: Can't use the -fast and -extended flags together\n");
3668 * We need to turn on ``long'' listings to get the full effect.