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 extern struct ubik_client *cstruct;
92 static struct tqHead busyHead, notokHead;
95 qInit(struct tqHead *ahead)
97 memset(ahead, 0, sizeof(struct tqHead));
103 qPut(struct tqHead *ahead, afs_uint32 volid)
107 elem = (struct tqElem *)malloc(sizeof(struct tqElem));
108 elem->next = ahead->next;
116 qGet(struct tqHead *ahead, afs_uint32 *volid)
120 if (ahead->count <= 0)
122 *volid = ahead->next->volid;
124 ahead->next = tmp->next;
130 /* returns 1 if <filename> exists else 0 */
132 FileExists(char *filename)
138 code = usd_Open(filename, USD_OPEN_RDONLY, 0, &ufd);
142 code = USD_IOCTL(ufd, USD_IOCTL_GETSIZE, &size);
150 /* returns 1 if <name> doesnot end in .readonly or .backup, else 0 */
152 VolNameOK(char *name)
157 total = strlen(name);
158 if (!strcmp(&name[total - 9], ".readonly")) {
160 } else if (!strcmp(&name[total - 7], ".backup")) {
167 /* return 1 if name is a number else 0 */
169 IsNumeric(char *name)
178 for (i = 0; i < len; i++) {
179 if (*ptr < '0' || *ptr > '9') {
191 * Parse a server dotted address and return the address in network byte order
194 GetServerNoresolve(char *aname)
200 code = sscanf(aname, "%d.%d.%d.%d", &b1, &b2, &b3, &b4);
202 addr = (b1 << 24) | (b2 << 16) | (b3 << 8) | b4;
203 addr = htonl(addr); /* convert to network byte order */
209 * Parse a server name/address and return the address in network byte order
212 GetServer(char *aname)
215 afs_uint32 addr; /* in network byte order */
217 char hostname[MAXHOSTCHARS];
219 if ((addr = GetServerNoresolve(aname)) == 0) {
220 th = gethostbyname(aname);
223 memcpy(&addr, th->h_addr, sizeof(addr));
226 if (rx_IsLoopbackAddr(ntohl(addr))) { /* local host */
227 code = gethostname(hostname, MAXHOSTCHARS);
230 th = gethostbyname(hostname);
233 memcpy(&addr, th->h_addr, sizeof(addr));
240 GetVolumeType(char *aname)
243 if (!strcmp(aname, "ro"))
245 else if (!strcmp(aname, "rw"))
247 else if (!strcmp(aname, "bk"))
254 IsPartValid(afs_int32 partId, afs_uint32 server, afs_int32 *code)
256 struct partList dummyPartList;
262 *code = UV_ListPartitions(server, &dummyPartList, &cnt);
265 for (i = 0; i < cnt; i++) {
266 if (dummyPartList.partFlags[i] & PARTVALID)
267 if (dummyPartList.partId[i] == partId)
275 /*sends the contents of file associated with <fd> and <blksize> to Rx Stream
276 * associated with <call> */
278 SendFile(usd_handle_t ufd, struct rx_call *call, long blksize)
280 char *buffer = (char *)0;
285 buffer = (char *)malloc(blksize);
287 fprintf(STDERR, "malloc failed\n");
291 while (!error && !done) {
292 #ifndef AFS_NT40_ENV /* NT csn't select on non-socket fd's */
295 FD_SET((intptr_t)(ufd->handle), &in);
296 /* don't timeout if read blocks */
297 #if defined(AFS_PTHREAD_ENV)
298 select(((intptr_t)(ufd->handle)) + 1, &in, 0, 0, 0);
300 IOMGR_Select(((intptr_t)(ufd->handle)) + 1, &in, 0, 0, 0);
303 error = USD_READ(ufd, buffer, blksize, &nbytes);
305 fprintf(STDERR, "File system read failed: %s\n",
306 afs_error_message(error));
313 if (rx_Write(call, buffer, nbytes) != nbytes) {
323 /* function invoked by UV_RestoreVolume, reads the data from rx_trx_stream and
324 * writes it out to the volume. */
326 WriteData(struct rx_call *call, void *rock)
328 char *filename = (char *) rock;
331 afs_int32 error, code;
333 afs_int64 currOffset;
339 if (!filename || !*filename) {
340 usd_StandardInput(&ufd);
344 code = usd_Open(filename, USD_OPEN_RDONLY, 0, &ufd);
347 code = USD_IOCTL(ufd, USD_IOCTL_GETBLKSIZE, &blksize);
350 fprintf(STDERR, "Could not access file '%s': %s\n", filename,
351 afs_error_message(code));
355 /* test if we have a valid dump */
356 USD_SEEK(ufd, 0, SEEK_END, &currOffset);
357 USD_SEEK(ufd, currOffset - sizeof(afs_uint32), SEEK_SET, &currOffset);
358 USD_READ(ufd, (char *)&buffer, sizeof(afs_uint32), &got);
359 if ((got != sizeof(afs_uint32)) || (ntohl(buffer) != DUMPENDMAGIC)) {
360 fprintf(STDERR, "Signature missing from end of file '%s'\n", filename);
364 USD_SEEK(ufd, 0, SEEK_SET, &currOffset);
366 code = SendFile(ufd, call, blksize);
373 code = USD_CLOSE(ufd);
375 fprintf(STDERR, "Could not close dump file %s\n",
376 (filename && *filename) ? filename : "STDOUT");
384 /* Receive data from <call> stream into file associated
385 * with <fd> <blksize>
388 ReceiveFile(usd_handle_t ufd, struct rx_call *call, long blksize)
392 afs_uint32 bytesleft, w;
395 buffer = (char *)malloc(blksize);
397 fprintf(STDERR, "memory allocation failed\n");
401 while ((bytesread = rx_Read(call, buffer, blksize)) > 0) {
402 for (bytesleft = bytesread; bytesleft; bytesleft -= w) {
403 #ifndef AFS_NT40_ENV /* NT csn't select on non-socket fd's */
406 FD_SET((intptr_t)(ufd->handle), &out);
407 /* don't timeout if write blocks */
408 #if defined(AFS_PTHREAD_ENV)
409 select(((intptr_t)(ufd->handle)) + 1, &out, 0, 0, 0);
411 IOMGR_Select(((intptr_t)(ufd->handle)) + 1, 0, &out, 0, 0);
415 USD_WRITE(ufd, &buffer[bytesread - bytesleft], bytesleft, &w);
417 fprintf(STDERR, "File system write failed: %s\n",
418 afs_error_message(error));
431 DumpFunction(struct rx_call *call, void *rock)
433 char *filename = (char *)rock;
434 usd_handle_t ufd; /* default is to stdout */
435 afs_int32 error = 0, code;
440 /* Open the output file */
441 if (!filename || !*filename) {
442 usd_StandardOutput(&ufd);
447 usd_Open(filename, USD_OPEN_CREATE | USD_OPEN_RDWR, 0666, &ufd);
451 code = USD_IOCTL(ufd, USD_IOCTL_SETSIZE, &size);
454 code = USD_IOCTL(ufd, USD_IOCTL_GETBLKSIZE, &blksize);
457 fprintf(STDERR, "Could not create file '%s': %s\n", filename,
458 afs_error_message(code));
459 ERROR_EXIT(VOLSERBADOP);
463 code = ReceiveFile(ufd, call, blksize);
468 /* Close the output file */
470 code = USD_CLOSE(ufd);
472 fprintf(STDERR, "Could not close dump file %s\n",
473 (filename && *filename) ? filename : "STDIN");
483 DisplayFormat(volintInfo *pntr, afs_uint32 server, afs_int32 part,
484 int *totalOK, int *totalNotOK, int *totalBusy, int fast,
485 int longlist, int disp)
491 fprintf(STDOUT, "%-10lu\n", (unsigned long)pntr->volid);
492 } else if (longlist) {
493 if (pntr->status == VOK) {
494 fprintf(STDOUT, "%-32s ", pntr->name);
495 fprintf(STDOUT, "%10lu ", (unsigned long)pntr->volid);
497 fprintf(STDOUT, "RW ");
499 fprintf(STDOUT, "RO ");
501 fprintf(STDOUT, "BK ");
502 fprintf(STDOUT, "%10d K ", pntr->size);
503 if (pntr->inUse == 1) {
504 fprintf(STDOUT, "On-line");
507 fprintf(STDOUT, "Off-line");
510 if (pntr->needsSalvaged == 1)
511 fprintf(STDOUT, "**needs salvage**");
512 fprintf(STDOUT, "\n");
513 MapPartIdIntoName(part, pname);
514 fprintf(STDOUT, " %s %s \n", hostutil_GetNameByINet(server),
516 fprintf(STDOUT, " RWrite %10lu ROnly %10lu Backup %10lu \n",
517 (unsigned long)pntr->parentID,
518 (unsigned long)pntr->cloneID,
519 (unsigned long)pntr->backupID);
520 fprintf(STDOUT, " MaxQuota %10d K \n", pntr->maxquota);
521 t = pntr->creationDate;
522 fprintf(STDOUT, " Creation %s",
525 fprintf(STDOUT, " Copy %s",
528 t = pntr->backupDate;
530 fprintf(STDOUT, " Backup Never\n");
532 fprintf(STDOUT, " Backup %s",
535 t = pntr->accessDate;
537 fprintf(STDOUT, " Last Access %s",
540 t = pntr->updateDate;
542 fprintf(STDOUT, " Last Update Never\n");
544 fprintf(STDOUT, " Last Update %s",
547 " %d accesses in the past day (i.e., vnode references)\n",
549 } else if (pntr->status == VBUSY) {
551 qPut(&busyHead, pntr->volid);
553 fprintf(STDOUT, "**** Volume %lu is busy ****\n",
554 (unsigned long)pntr->volid);
557 qPut(¬okHead, pntr->volid);
559 fprintf(STDOUT, "**** Could not attach volume %lu ****\n",
560 (unsigned long)pntr->volid);
562 fprintf(STDOUT, "\n");
563 } else { /* default listing */
564 if (pntr->status == VOK) {
565 fprintf(STDOUT, "%-32s ", pntr->name);
566 fprintf(STDOUT, "%10lu ", (unsigned long)pntr->volid);
568 fprintf(STDOUT, "RW ");
570 fprintf(STDOUT, "RO ");
572 fprintf(STDOUT, "BK ");
573 fprintf(STDOUT, "%10d K ", pntr->size);
574 if (pntr->inUse == 1) {
575 fprintf(STDOUT, "On-line");
578 fprintf(STDOUT, "Off-line");
581 if (pntr->needsSalvaged == 1)
582 fprintf(STDOUT, "**needs salvage**");
583 fprintf(STDOUT, "\n");
584 } else if (pntr->status == VBUSY) {
586 qPut(&busyHead, pntr->volid);
588 fprintf(STDOUT, "**** Volume %lu is busy ****\n",
589 (unsigned long)pntr->volid);
592 qPut(¬okHead, pntr->volid);
594 fprintf(STDOUT, "**** Could not attach volume %lu ****\n",
595 (unsigned long)pntr->volid);
600 /*------------------------------------------------------------------------
601 * PRIVATE XDisplayFormat
604 * Display the contents of one extended volume info structure.
607 * a_xInfoP : Ptr to extended volume info struct to print.
608 * a_servID : Server ID to print.
609 * a_partID : Partition ID to print.
610 * a_totalOKP : Ptr to total-OK counter.
611 * a_totalNotOKP : Ptr to total-screwed counter.
612 * a_totalBusyP : Ptr to total-busy counter.
613 * a_fast : Fast listing?
614 * a_int32 : Int32 listing?
615 * a_showProblems : Show volume problems?
621 * Nothing interesting.
625 *------------------------------------------------------------------------*/
628 XDisplayFormat(volintXInfo *a_xInfoP, afs_uint32 a_servID, afs_int32 a_partID,
629 int *a_totalOKP, int *a_totalNotOKP, int *a_totalBusyP,
630 int a_fast, int a_int32, int a_showProblems)
631 { /*XDisplayFormat */
639 fprintf(STDOUT, "%-10lu\n", (unsigned long)a_xInfoP->volid);
640 } else if (a_int32) {
642 * Fully-detailed listing.
644 if (a_xInfoP->status == VOK) {
646 * Volume's status is OK - all the fields are valid.
648 fprintf(STDOUT, "%-32s ", a_xInfoP->name);
649 fprintf(STDOUT, "%10lu ", (unsigned long)a_xInfoP->volid);
650 if (a_xInfoP->type == 0)
651 fprintf(STDOUT, "RW ");
652 if (a_xInfoP->type == 1)
653 fprintf(STDOUT, "RO ");
654 if (a_xInfoP->type == 2)
655 fprintf(STDOUT, "BK ");
656 fprintf(STDOUT, "%10d K used ", a_xInfoP->size);
657 fprintf(STDOUT, "%d files ", a_xInfoP->filecount);
658 if (a_xInfoP->inUse == 1) {
659 fprintf(STDOUT, "On-line");
662 fprintf(STDOUT, "Off-line");
665 fprintf(STDOUT, "\n");
666 MapPartIdIntoName(a_partID, pname);
667 fprintf(STDOUT, " %s %s \n", hostutil_GetNameByINet(a_servID),
669 fprintf(STDOUT, " RWrite %10lu ROnly %10lu Backup %10lu \n",
670 (unsigned long)a_xInfoP->parentID,
671 (unsigned long)a_xInfoP->cloneID,
672 (unsigned long)a_xInfoP->backupID);
673 fprintf(STDOUT, " MaxQuota %10d K \n", a_xInfoP->maxquota);
675 t = a_xInfoP->creationDate;
676 fprintf(STDOUT, " Creation %s",
679 t = a_xInfoP->copyDate;
680 fprintf(STDOUT, " Copy %s",
683 t = a_xInfoP->backupDate;
685 fprintf(STDOUT, " Backup Never\n");
687 fprintf(STDOUT, " Backup %s",
690 t = a_xInfoP->accessDate;
692 fprintf(STDOUT, " Last Access %s",
695 t = a_xInfoP->updateDate;
697 fprintf(STDOUT, " Last Update Never\n");
699 fprintf(STDOUT, " Last Update %s",
702 " %d accesses in the past day (i.e., vnode references)\n",
706 * Print all the read/write and authorship stats.
708 fprintf(STDOUT, "\n Raw Read/Write Stats\n");
710 " |-------------------------------------------|\n");
712 " | Same Network | Diff Network |\n");
714 " |----------|----------|----------|----------|\n");
716 " | Total | Auth | Total | Auth |\n");
718 " |----------|----------|----------|----------|\n");
719 fprintf(STDOUT, "Reads | %8d | %8d | %8d | %8d |\n",
720 a_xInfoP->stat_reads[VOLINT_STATS_SAME_NET],
721 a_xInfoP->stat_reads[VOLINT_STATS_SAME_NET_AUTH],
722 a_xInfoP->stat_reads[VOLINT_STATS_DIFF_NET],
723 a_xInfoP->stat_reads[VOLINT_STATS_DIFF_NET_AUTH]);
724 fprintf(STDOUT, "Writes | %8d | %8d | %8d | %8d |\n",
725 a_xInfoP->stat_writes[VOLINT_STATS_SAME_NET],
726 a_xInfoP->stat_writes[VOLINT_STATS_SAME_NET_AUTH],
727 a_xInfoP->stat_writes[VOLINT_STATS_DIFF_NET],
728 a_xInfoP->stat_writes[VOLINT_STATS_DIFF_NET_AUTH]);
730 " |-------------------------------------------|\n\n");
733 " Writes Affecting Authorship\n");
735 " |-------------------------------------------|\n");
737 " | File Authorship | Directory Authorship|\n");
739 " |----------|----------|----------|----------|\n");
741 " | Same | Diff | Same | Diff |\n");
743 " |----------|----------|----------|----------|\n");
744 fprintf(STDOUT, "0-60 sec | %8d | %8d | %8d | %8d |\n",
745 a_xInfoP->stat_fileSameAuthor[VOLINT_STATS_TIME_IDX_0],
746 a_xInfoP->stat_fileDiffAuthor[VOLINT_STATS_TIME_IDX_0],
747 a_xInfoP->stat_dirSameAuthor[VOLINT_STATS_TIME_IDX_0],
748 a_xInfoP->stat_dirDiffAuthor[VOLINT_STATS_TIME_IDX_0]);
749 fprintf(STDOUT, "1-10 min | %8d | %8d | %8d | %8d |\n",
750 a_xInfoP->stat_fileSameAuthor[VOLINT_STATS_TIME_IDX_1],
751 a_xInfoP->stat_fileDiffAuthor[VOLINT_STATS_TIME_IDX_1],
752 a_xInfoP->stat_dirSameAuthor[VOLINT_STATS_TIME_IDX_1],
753 a_xInfoP->stat_dirDiffAuthor[VOLINT_STATS_TIME_IDX_1]);
754 fprintf(STDOUT, "10min-1hr | %8d | %8d | %8d | %8d |\n",
755 a_xInfoP->stat_fileSameAuthor[VOLINT_STATS_TIME_IDX_2],
756 a_xInfoP->stat_fileDiffAuthor[VOLINT_STATS_TIME_IDX_2],
757 a_xInfoP->stat_dirSameAuthor[VOLINT_STATS_TIME_IDX_2],
758 a_xInfoP->stat_dirDiffAuthor[VOLINT_STATS_TIME_IDX_2]);
759 fprintf(STDOUT, "1hr-1day | %8d | %8d | %8d | %8d |\n",
760 a_xInfoP->stat_fileSameAuthor[VOLINT_STATS_TIME_IDX_3],
761 a_xInfoP->stat_fileDiffAuthor[VOLINT_STATS_TIME_IDX_3],
762 a_xInfoP->stat_dirSameAuthor[VOLINT_STATS_TIME_IDX_3],
763 a_xInfoP->stat_dirDiffAuthor[VOLINT_STATS_TIME_IDX_3]);
764 fprintf(STDOUT, "1day-1wk | %8d | %8d | %8d | %8d |\n",
765 a_xInfoP->stat_fileSameAuthor[VOLINT_STATS_TIME_IDX_4],
766 a_xInfoP->stat_fileDiffAuthor[VOLINT_STATS_TIME_IDX_4],
767 a_xInfoP->stat_dirSameAuthor[VOLINT_STATS_TIME_IDX_4],
768 a_xInfoP->stat_dirDiffAuthor[VOLINT_STATS_TIME_IDX_4]);
769 fprintf(STDOUT, "> 1wk | %8d | %8d | %8d | %8d |\n",
770 a_xInfoP->stat_fileSameAuthor[VOLINT_STATS_TIME_IDX_5],
771 a_xInfoP->stat_fileDiffAuthor[VOLINT_STATS_TIME_IDX_5],
772 a_xInfoP->stat_dirSameAuthor[VOLINT_STATS_TIME_IDX_5],
773 a_xInfoP->stat_dirDiffAuthor[VOLINT_STATS_TIME_IDX_5]);
775 " |-------------------------------------------|\n");
776 } /*Volume status OK */
777 else if (a_xInfoP->status == VBUSY) {
779 qPut(&busyHead, a_xInfoP->volid);
781 fprintf(STDOUT, "**** Volume %lu is busy ****\n",
782 (unsigned long)a_xInfoP->volid);
786 qPut(¬okHead, a_xInfoP->volid);
788 fprintf(STDOUT, "**** Could not attach volume %lu ****\n",
789 (unsigned long)a_xInfoP->volid);
790 } /*Screwed volume */
791 fprintf(STDOUT, "\n");
797 if (a_xInfoP->status == VOK) {
798 fprintf(STDOUT, "%-32s ", a_xInfoP->name);
799 fprintf(STDOUT, "%10lu ", (unsigned long)a_xInfoP->volid);
800 if (a_xInfoP->type == 0)
801 fprintf(STDOUT, "RW ");
802 if (a_xInfoP->type == 1)
803 fprintf(STDOUT, "RO ");
804 if (a_xInfoP->type == 2)
805 fprintf(STDOUT, "BK ");
806 fprintf(STDOUT, "%10d K ", a_xInfoP->size);
807 if (a_xInfoP->inUse == 1) {
808 fprintf(STDOUT, "On-line");
811 fprintf(STDOUT, "Off-line");
814 fprintf(STDOUT, "\n");
816 else if (a_xInfoP->status == VBUSY) {
818 qPut(&busyHead, a_xInfoP->volid);
820 fprintf(STDOUT, "**** Volume %lu is busy ****\n",
821 (unsigned long)a_xInfoP->volid);
825 qPut(¬okHead, a_xInfoP->volid);
827 fprintf(STDOUT, "**** Could not attach volume %lu ****\n",
828 (unsigned long)a_xInfoP->volid);
829 } /*Screwed volume */
830 } /*Default listing */
831 } /*XDisplayFormat */
833 /*------------------------------------------------------------------------
834 * PRIVATE XDisplayFormat2
837 * Display the formated contents of one extended volume info structure.
840 * a_xInfoP : Ptr to extended volume info struct to print.
841 * a_servID : Server ID to print.
842 * a_partID : Partition ID to print.
843 * a_totalOKP : Ptr to total-OK counter.
844 * a_totalNotOKP : Ptr to total-screwed counter.
845 * a_totalBusyP : Ptr to total-busy counter.
846 * a_fast : Fast listing?
847 * a_int32 : Int32 listing?
848 * a_showProblems : Show volume problems?
854 * Nothing interesting.
858 *------------------------------------------------------------------------*/
861 XDisplayFormat2(volintXInfo *a_xInfoP, afs_uint32 a_servID, afs_int32 a_partID,
862 int *a_totalOKP, int *a_totalNotOKP, int *a_totalBusyP,
863 int a_fast, int a_int32, int a_showProblems)
864 { /*XDisplayFormat */
870 fprintf(STDOUT, "vold_id\t%-10lu\n", (unsigned long)a_xInfoP->volid);
871 } else if (a_int32) {
873 * Fully-detailed listing.
875 if (a_xInfoP->status == VOK) {
877 * Volume's status is OK - all the fields are valid.
880 static long server_cache = -1, partition_cache = -1;
881 static char hostname[256], address[32], pname[16];
882 int i,ai[] = {VOLINT_STATS_TIME_IDX_0,VOLINT_STATS_TIME_IDX_1,VOLINT_STATS_TIME_IDX_2,
883 VOLINT_STATS_TIME_IDX_3,VOLINT_STATS_TIME_IDX_4,VOLINT_STATS_TIME_IDX_5};
885 if (a_servID != server_cache) {
889 strcpy(hostname, hostutil_GetNameByINet(a_servID));
890 strcpy(address, inet_ntoa(s));
891 server_cache = a_servID;
893 if (a_partID != partition_cache) {
894 MapPartIdIntoName(a_partID, pname);
895 partition_cache = a_partID;
898 fprintf(STDOUT, "name\t\t%s\n", a_xInfoP->name);
899 fprintf(STDOUT, "id\t\t%lu\n", afs_printable_uint32_lu(a_xInfoP->volid));
900 fprintf(STDOUT, "serv\t\t%s\t%s\n", address, hostname);
901 fprintf(STDOUT, "part\t\t%s\n", pname);
902 fprintf(STDOUT, "status\t\tOK\n");
903 fprintf(STDOUT, "backupID\t%lu\n",
904 afs_printable_uint32_lu(a_xInfoP->backupID));
905 fprintf(STDOUT, "parentID\t%lu\n",
906 afs_printable_uint32_lu(a_xInfoP->parentID));
907 fprintf(STDOUT, "cloneID\t\t%lu\n",
908 afs_printable_uint32_lu(a_xInfoP->cloneID));
909 fprintf(STDOUT, "inUse\t\t%s\n", a_xInfoP->inUse ? "Y" : "N");
910 switch (a_xInfoP->type) {
912 fprintf(STDOUT, "type\t\tRW\n");
915 fprintf(STDOUT, "type\t\tRO\n");
918 fprintf(STDOUT, "type\t\tBK\n");
921 fprintf(STDOUT, "type\t\t?\n");
924 t = a_xInfoP->creationDate;
925 fprintf(STDOUT, "creationDate\t%-9lu\t%s",
926 afs_printable_uint32_lu(a_xInfoP->creationDate),
929 t = a_xInfoP->accessDate;
930 fprintf(STDOUT, "accessDate\t%-9lu\t%s",
931 afs_printable_uint32_lu(a_xInfoP->accessDate),
934 t = a_xInfoP->updateDate;
935 fprintf(STDOUT, "updateDate\t%-9lu\t%s",
936 afs_printable_uint32_lu(a_xInfoP->updateDate),
939 t = a_xInfoP->backupDate;
940 fprintf(STDOUT, "backupDate\t%-9lu\t%s",
941 afs_printable_uint32_lu(a_xInfoP->backupDate),
944 t = a_xInfoP->copyDate;
945 fprintf(STDOUT, "copyDate\t%-9lu\t%s",
946 afs_printable_uint32_lu(a_xInfoP->copyDate),
949 fprintf(STDOUT, "diskused\t%u\n", a_xInfoP->size);
950 fprintf(STDOUT, "maxquota\t%u\n", a_xInfoP->maxquota);
952 fprintf(STDOUT, "filecount\t%u\n", a_xInfoP->filecount);
953 fprintf(STDOUT, "dayUse\t\t%u\n", a_xInfoP->dayUse);
957 fprintf(STDOUT,"reads_same_net\t%8d\n",a_xInfoP->stat_reads[VOLINT_STATS_SAME_NET]);
958 fprintf(STDOUT,"reads_same_net_auth\t%8d\n",a_xInfoP->stat_reads[VOLINT_STATS_SAME_NET_AUTH]);
959 fprintf(STDOUT,"reads_diff_net\t%8d\n",a_xInfoP->stat_reads[VOLINT_STATS_DIFF_NET]);
960 fprintf(STDOUT,"reads_diff_net_auth\t%8d\n",a_xInfoP->stat_reads[VOLINT_STATS_DIFF_NET_AUTH]);
962 fprintf(STDOUT,"writes_same_net\t%8d\n",a_xInfoP->stat_writes[VOLINT_STATS_SAME_NET]);
963 fprintf(STDOUT,"writes_same_net_auth\t%8d\n",a_xInfoP->stat_writes[VOLINT_STATS_SAME_NET_AUTH]);
964 fprintf(STDOUT,"writes_diff_net\t%8d\n",a_xInfoP->stat_writes[VOLINT_STATS_DIFF_NET]);
965 fprintf(STDOUT,"writes_diff_net_auth\t%8d\n",a_xInfoP->stat_writes[VOLINT_STATS_DIFF_NET_AUTH]);
969 fprintf(STDOUT,"file_same_author_idx_%d\t%8d\n",i+1,a_xInfoP->stat_fileSameAuthor[ai[i]]);
970 fprintf(STDOUT,"file_diff_author_idx_%d\t%8d\n",i+1,a_xInfoP->stat_fileDiffAuthor[ai[i]]);
971 fprintf(STDOUT,"dir_same_author_idx_%d\t%8d\n",i+1,a_xInfoP->stat_dirSameAuthor[ai[i]]);
972 fprintf(STDOUT,"dir_dif_author_idx_%d\t%8d\n",i+1,a_xInfoP->stat_dirDiffAuthor[ai[i]]);
975 } /*Volume status OK */
976 else if (a_xInfoP->status == VBUSY) {
978 qPut(&busyHead, a_xInfoP->volid);
980 fprintf(STDOUT, "BUSY_VOL\t%lu\n",
981 (unsigned long)a_xInfoP->volid);
985 qPut(¬okHead, a_xInfoP->volid);
987 fprintf(STDOUT, "COULD_NOT_ATTACH\t%lu\n",
988 (unsigned long)a_xInfoP->volid);
989 } /*Screwed volume */
995 if (a_xInfoP->status == VOK) {
996 fprintf(STDOUT, "name\t%-32s\n", a_xInfoP->name);
997 fprintf(STDOUT, "volID\t%10lu\n", (unsigned long)a_xInfoP->volid);
998 if (a_xInfoP->type == 0)
999 fprintf(STDOUT, "type\tRW\n");
1000 if (a_xInfoP->type == 1)
1001 fprintf(STDOUT, "type\tRO\n");
1002 if (a_xInfoP->type == 2)
1003 fprintf(STDOUT, "type\tBK\n");
1004 fprintf(STDOUT, "size\t%10dK\n", a_xInfoP->size);
1006 fprintf(STDOUT, "inUse\t%d\n",a_xInfoP->inUse);
1007 if (a_xInfoP->inUse == 1)
1013 else if (a_xInfoP->status == VBUSY) {
1015 qPut(&busyHead, a_xInfoP->volid);
1017 fprintf(STDOUT, "VOLUME_BUSY\t%lu\n",
1018 (unsigned long)a_xInfoP->volid);
1022 qPut(¬okHead, a_xInfoP->volid);
1024 fprintf(STDOUT, "COULD_NOT_ATTACH_VOLUME\t%lu\n",
1025 (unsigned long)a_xInfoP->volid);
1026 } /*Screwed volume */
1027 } /*Default listing */
1028 } /*XDisplayFormat */
1031 DisplayFormat2(long server, long partition, volintInfo *pntr)
1033 static long server_cache = -1, partition_cache = -1;
1034 static char hostname[256], address[32], pname[16];
1037 if (server != server_cache) {
1041 strcpy(hostname, hostutil_GetNameByINet(server));
1042 strcpy(address, inet_ntoa(s));
1043 server_cache = server;
1045 if (partition != partition_cache) {
1046 MapPartIdIntoName(partition, pname);
1047 partition_cache = partition;
1050 if (pntr->status == VOK)
1051 fprintf(STDOUT, "name\t\t%s\n", pntr->name);
1053 fprintf(STDOUT, "id\t\t%lu\n",
1054 afs_printable_uint32_lu(pntr->volid));
1055 fprintf(STDOUT, "serv\t\t%s\t%s\n", address, hostname);
1056 fprintf(STDOUT, "part\t\t%s\n", pname);
1057 switch (pntr->status) {
1059 fprintf(STDOUT, "status\t\tOK\n");
1062 fprintf(STDOUT, "status\t\tBUSY\n");
1065 fprintf(STDOUT, "status\t\tUNATTACHABLE\n");
1068 fprintf(STDOUT, "backupID\t%lu\n",
1069 afs_printable_uint32_lu(pntr->backupID));
1070 fprintf(STDOUT, "parentID\t%lu\n",
1071 afs_printable_uint32_lu(pntr->parentID));
1072 fprintf(STDOUT, "cloneID\t\t%lu\n",
1073 afs_printable_uint32_lu(pntr->cloneID));
1074 fprintf(STDOUT, "inUse\t\t%s\n", pntr->inUse ? "Y" : "N");
1075 fprintf(STDOUT, "needsSalvaged\t%s\n", pntr->needsSalvaged ? "Y" : "N");
1076 /* 0xD3 is from afs/volume.h since I had trouble including the file */
1077 fprintf(STDOUT, "destroyMe\t%s\n", pntr->destroyMe == 0xD3 ? "Y" : "N");
1078 switch (pntr->type) {
1080 fprintf(STDOUT, "type\t\tRW\n");
1083 fprintf(STDOUT, "type\t\tRO\n");
1086 fprintf(STDOUT, "type\t\tBK\n");
1089 fprintf(STDOUT, "type\t\t?\n");
1092 t = pntr->creationDate;
1093 fprintf(STDOUT, "creationDate\t%-9lu\t%s",
1094 afs_printable_uint32_lu(pntr->creationDate),
1097 t = pntr->accessDate;
1098 fprintf(STDOUT, "accessDate\t%-9lu\t%s",
1099 afs_printable_uint32_lu(pntr->accessDate),
1102 t = pntr->updateDate;
1103 fprintf(STDOUT, "updateDate\t%-9lu\t%s",
1104 afs_printable_uint32_lu(pntr->updateDate),
1107 t = pntr->backupDate;
1108 fprintf(STDOUT, "backupDate\t%-9lu\t%s",
1109 afs_printable_uint32_lu(pntr->backupDate),
1113 fprintf(STDOUT, "copyDate\t%-9lu\t%s",
1114 afs_printable_uint32_lu(pntr->copyDate),
1117 fprintf(STDOUT, "flags\t\t%#lx\t(Optional)\n",
1118 afs_printable_uint32_lu(pntr->flags));
1119 fprintf(STDOUT, "diskused\t%u\n", pntr->size);
1120 fprintf(STDOUT, "maxquota\t%u\n", pntr->maxquota);
1121 fprintf(STDOUT, "minquota\t%lu\t(Optional)\n",
1122 afs_printable_uint32_lu(pntr->spare0));
1123 fprintf(STDOUT, "filecount\t%u\n", pntr->filecount);
1124 fprintf(STDOUT, "dayUse\t\t%u\n", pntr->dayUse);
1125 fprintf(STDOUT, "weekUse\t\t%lu\t(Optional)\n",
1126 afs_printable_uint32_lu(pntr->spare1));
1127 fprintf(STDOUT, "spare2\t\t%lu\t(Optional)\n",
1128 afs_printable_uint32_lu(pntr->spare2));
1129 fprintf(STDOUT, "spare3\t\t%lu\t(Optional)\n",
1130 afs_printable_uint32_lu(pntr->spare3));
1135 DisplayVolumes2(long server, long partition, volintInfo *pntr, long count)
1139 for (i = 0; i < count; i++) {
1140 fprintf(STDOUT, "BEGIN_OF_ENTRY\n");
1141 DisplayFormat2(server, partition, pntr);
1142 fprintf(STDOUT, "END_OF_ENTRY\n\n");
1149 DisplayVolumes(afs_uint32 server, afs_int32 part, volintInfo *pntr,
1150 afs_int32 count, afs_int32 longlist, afs_int32 fast,
1153 int totalOK, totalNotOK, totalBusy, i;
1154 afs_uint32 volid = 0;
1161 for (i = 0; i < count; i++) {
1162 DisplayFormat(pntr, server, part, &totalOK, &totalNotOK, &totalBusy,
1167 while (busyHead.count) {
1168 qGet(&busyHead, &volid);
1169 fprintf(STDOUT, "**** Volume %lu is busy ****\n",
1170 (unsigned long)volid);
1174 while (notokHead.count) {
1175 qGet(¬okHead, &volid);
1176 fprintf(STDOUT, "**** Could not attach volume %lu ****\n",
1177 (unsigned long)volid);
1181 fprintf(STDOUT, "\n");
1184 "Total volumes onLine %d ; Total volumes offLine %d ; Total busy %d\n\n",
1185 totalOK, totalNotOK, totalBusy);
1189 /*------------------------------------------------------------------------
1190 * PRIVATE XDisplayVolumes
1193 * Display extended volume information.
1196 * a_servID : Pointer to the Rx call we're performing.
1197 * a_partID : Partition for which we want the extended list.
1198 * a_xInfoP : Ptr to extended volume info.
1199 * a_count : Number of volume records contained above.
1200 * a_int32 : Int32 listing generated?
1201 * a_fast : Fast listing generated?
1202 * a_quiet : Quiet listing generated?
1208 * Nothing interesting.
1212 *------------------------------------------------------------------------*/
1215 XDisplayVolumes(afs_uint32 a_servID, afs_int32 a_partID, volintXInfo *a_xInfoP,
1216 afs_int32 a_count, afs_int32 a_int32, afs_int32 a_fast,
1218 { /*XDisplayVolumes */
1220 int totalOK; /*Total OK volumes */
1221 int totalNotOK; /*Total screwed volumes */
1222 int totalBusy; /*Total busy volumes */
1223 int i; /*Loop variable */
1224 afs_uint32 volid = 0; /*Current volume ID */
1227 * Initialize counters and (global!!) queues.
1236 * Display each volume in the list.
1238 for (i = 0; i < a_count; i++) {
1239 XDisplayFormat(a_xInfoP, a_servID, a_partID, &totalOK, &totalNotOK,
1240 &totalBusy, a_fast, a_int32, 0);
1245 * If any volumes were found to be busy or screwed, display them.
1248 while (busyHead.count) {
1249 qGet(&busyHead, &volid);
1250 fprintf(STDOUT, "**** Volume %lu is busy ****\n",
1251 (unsigned long)volid);
1255 while (notokHead.count) {
1256 qGet(¬okHead, &volid);
1257 fprintf(STDOUT, "**** Could not attach volume %lu ****\n",
1258 (unsigned long)volid);
1263 fprintf(STDOUT, "\n");
1266 "Total volumes: %d on-line, %d off-line, %d busyd\n\n",
1267 totalOK, totalNotOK, totalBusy);
1271 } /*XDisplayVolumes */
1273 /*------------------------------------------------------------------------
1274 * PRIVATE XDisplayVolumes2
1277 * Display extended formated volume information.
1280 * a_servID : Pointer to the Rx call we're performing.
1281 * a_partID : Partition for which we want the extended list.
1282 * a_xInfoP : Ptr to extended volume info.
1283 * a_count : Number of volume records contained above.
1284 * a_int32 : Int32 listing generated?
1285 * a_fast : Fast listing generated?
1286 * a_quiet : Quiet listing generated?
1292 * Nothing interesting.
1296 *------------------------------------------------------------------------*/
1299 XDisplayVolumes2(afs_uint32 a_servID, afs_int32 a_partID, volintXInfo *a_xInfoP,
1300 afs_int32 a_count, afs_int32 a_int32, afs_int32 a_fast,
1302 { /*XDisplayVolumes */
1304 int totalOK; /*Total OK volumes */
1305 int totalNotOK; /*Total screwed volumes */
1306 int totalBusy; /*Total busy volumes */
1307 int i; /*Loop variable */
1308 afs_uint32 volid = 0; /*Current volume ID */
1311 * Initialize counters and (global!!) queues.
1320 * Display each volume in the list.
1322 for (i = 0; i < a_count; i++) {
1323 fprintf(STDOUT, "BEGIN_OF_ENTRY\n");
1324 XDisplayFormat2(a_xInfoP, a_servID, a_partID, &totalOK, &totalNotOK,
1325 &totalBusy, a_fast, a_int32, 0);
1326 fprintf(STDOUT, "END_OF_ENTRY\n");
1331 * If any volumes were found to be busy or screwed, display them.
1334 while (busyHead.count) {
1335 qGet(&busyHead, &volid);
1336 fprintf(STDOUT, "BUSY_VOL\t%lu\n",
1337 (unsigned long)volid);
1341 while (notokHead.count) {
1342 qGet(¬okHead, &volid);
1343 fprintf(STDOUT, "COULD_NOT_ATTACH\t%lu\n",
1344 (unsigned long)volid);
1349 fprintf(STDOUT, "\n");
1352 "VOLUMES_ONLINE\t%d\nVOLUMES_OFFLINE\t%d\nVOLUMES_BUSY\t%d\n",
1353 totalOK, totalNotOK, totalBusy);
1357 } /*XDisplayVolumes2 */
1360 /* set <server> and <part> to the correct values depending on
1361 * <voltype> and <entry> */
1363 GetServerAndPart(struct nvldbentry *entry, int voltype, afs_uint32 *server,
1364 afs_int32 *part, int *previdx)
1366 int i, istart, vtype;
1371 /* Doesn't check for non-existance of backup volume */
1372 if ((voltype == RWVOL) || (voltype == BACKVOL)) {
1374 istart = 0; /* seach the entire entry */
1377 /* Seach from beginning of entry or pick up where we left off */
1378 istart = ((*previdx < 0) ? 0 : *previdx + 1);
1381 for (i = istart; i < entry->nServers; i++) {
1382 if (entry->serverFlags[i] & vtype) {
1383 *server = entry->serverNumber[i];
1384 *part = entry->serverPartition[i];
1390 /* Didn't find any, return -1 */
1396 PrintLocked(afs_int32 aflags)
1398 afs_int32 flags = aflags & VLOP_ALLOPERS;
1401 fprintf(STDOUT, " Volume is currently LOCKED \n");
1403 if (flags & VLOP_MOVE) {
1404 fprintf(STDOUT, " Volume is locked for a move operation\n");
1406 if (flags & VLOP_RELEASE) {
1407 fprintf(STDOUT, " Volume is locked for a release operation\n");
1409 if (flags & VLOP_BACKUP) {
1410 fprintf(STDOUT, " Volume is locked for a backup operation\n");
1412 if (flags & VLOP_DELETE) {
1413 fprintf(STDOUT, " Volume is locked for a delete/misc operation\n");
1415 if (flags & VLOP_DUMP) {
1416 fprintf(STDOUT, " Volume is locked for a dump/restore operation\n");
1422 PostVolumeStats(struct nvldbentry *entry)
1424 SubEnumerateEntry(entry);
1425 /* Check for VLOP_ALLOPERS */
1426 PrintLocked(entry->flags);
1430 /*------------------------------------------------------------------------
1431 * PRIVATE XVolumeStats
1434 * Display extended volume information.
1437 * a_xInfoP : Ptr to extended volume info.
1438 * a_entryP : Ptr to the volume's VLDB entry.
1439 * a_srvID : Server ID.
1440 * a_partID : Partition ID.
1441 * a_volType : Type of volume to print.
1447 * Nothing interesting.
1451 *------------------------------------------------------------------------*/
1454 XVolumeStats(volintXInfo *a_xInfoP, struct nvldbentry *a_entryP,
1455 afs_int32 a_srvID, afs_int32 a_partID, int a_volType)
1458 int totalOK, totalNotOK, totalBusy; /*Dummies - we don't really count here */
1460 XDisplayFormat(a_xInfoP, /*Ptr to extended volume info */
1461 a_srvID, /*Server ID to print */
1462 a_partID, /*Partition ID to print */
1463 &totalOK, /*Ptr to total-OK counter */
1464 &totalNotOK, /*Ptr to total-screwed counter */
1465 &totalBusy, /*Ptr to total-busy counter */
1466 0, /*Don't do a fast listing */
1467 1, /*Do a long listing */
1468 1); /*Show volume problems */
1474 VolumeStats_int(volintInfo *pntr, struct nvldbentry *entry, afs_uint32 server,
1475 afs_int32 part, int voltype)
1477 int totalOK, totalNotOK, totalBusy;
1479 DisplayFormat(pntr, server, part, &totalOK, &totalNotOK, &totalBusy, 0, 1,
1484 /* command to forcibly remove a volume */
1486 NukeVolume(struct cmd_syndesc *as)
1495 server = GetServer(tp = as->parms[0].items->data);
1497 fprintf(STDERR, "vos: server '%s' not found in host table\n", tp);
1501 partID = volutil_GetPartitionID(tp = as->parms[1].items->data);
1503 fprintf(STDERR, "vos: could not parse '%s' as a partition name", tp);
1507 volID = vsu_GetVolumeID(tp = as->parms[2].items->data, cstruct, &err);
1510 PrintError("", err);
1513 "vos: could not parse '%s' as a numeric volume ID", tp);
1518 "vos: forcibly removing all traces of volume %d, please wait...",
1521 code = UV_NukeVolume(server, partID, volID);
1523 fprintf(STDOUT, "done.\n");
1525 fprintf(STDOUT, "failed with code %d.\n", code);
1530 /*------------------------------------------------------------------------
1531 * PRIVATE ExamineVolume
1534 * Routine used to examine a single volume, contacting the VLDB as
1535 * well as the Volume Server.
1538 * as : Ptr to parsed command line arguments.
1541 * 0 for a successful operation,
1542 * Otherwise, one of the ubik or VolServer error values.
1545 * Nothing interesting.
1549 *------------------------------------------------------------------------
1552 ExamineVolume(struct cmd_syndesc *as, void *arock)
1554 struct nvldbentry entry;
1555 afs_int32 vcode = 0;
1556 volintInfo *pntr = (volintInfo *) 0;
1557 volintXInfo *xInfoP = (volintXInfo *) 0;
1559 afs_int32 code, err, error = 0;
1560 int voltype, foundserv = 0, foundentry = 0;
1564 int wantExtendedInfo; /*Do we want extended vol info? */
1565 int isSubEnum=0; /* Keep track whether sub enumerate called. */
1566 wantExtendedInfo = (as->parms[1].items ? 1 : 0); /* -extended */
1568 volid = vsu_GetVolumeID(as->parms[0].items->data, cstruct, &err); /* -id */
1571 PrintError("", err);
1573 fprintf(STDERR, "Unknown volume ID or name '%s'\n",
1574 as->parms[0].items->data);
1579 fprintf(STDOUT, "Fetching VLDB entry for %lu .. ",
1580 (unsigned long)volid);
1583 vcode = VLDB_GetEntryByID(volid, -1, &entry);
1586 "Could not fetch the entry for volume number %lu from VLDB \n",
1587 (unsigned long)volid);
1591 fprintf(STDOUT, "done\n");
1592 MapHostToNetwork(&entry);
1594 if (entry.volumeId[RWVOL] == volid)
1596 else if (entry.volumeId[BACKVOL] == volid)
1598 else /* (entry.volumeId[ROVOL] == volid) */
1601 do { /* do {...} while (voltype == ROVOL) */
1602 /* Get the entry for the volume. If its a RW vol, get the RW entry.
1603 * It its a BK vol, get the RW entry (even if VLDB may say the BK doen't exist).
1604 * If its a RO vol, get the next RO entry.
1606 GetServerAndPart(&entry, ((voltype == ROVOL) ? ROVOL : RWVOL),
1607 &aserver, &apart, &previdx);
1608 if (previdx == -1) { /* searched all entries */
1610 fprintf(STDERR, "Volume %s does not exist in VLDB\n\n",
1611 as->parms[0].items->data);
1618 /* Get information about the volume from the server */
1620 fprintf(STDOUT, "Getting volume listing from the server %s .. ",
1621 hostutil_GetNameByINet(aserver));
1624 if (wantExtendedInfo)
1625 code = UV_XListOneVolume(aserver, apart, volid, &xInfoP);
1627 code = UV_ListOneVolume(aserver, apart, volid, &pntr);
1629 fprintf(STDOUT, "done\n");
1633 if (code == ENODEV) {
1634 if ((voltype == BACKVOL) && !(entry.flags & BACK_EXISTS)) {
1635 /* The VLDB says there is no backup volume and its not on disk */
1636 fprintf(STDERR, "Volume %s does not exist\n",
1637 as->parms[0].items->data);
1641 "Volume does not exist on server %s as indicated by the VLDB\n",
1642 hostutil_GetNameByINet(aserver));
1645 PrintDiagnostics("examine", code);
1647 fprintf(STDOUT, "\n");
1650 if (wantExtendedInfo)
1651 XVolumeStats(xInfoP, &entry, aserver, apart, voltype);
1652 else if (as->parms[2].items) {
1653 DisplayFormat2(aserver, apart, pntr);
1654 EnumerateEntry(&entry);
1657 VolumeStats_int(pntr, &entry, aserver, apart, voltype);
1659 if ((voltype == BACKVOL) && !(entry.flags & BACK_EXISTS)) {
1660 /* The VLDB says there is no backup volume yet we found one on disk */
1661 fprintf(STDERR, "Volume %s does not exist in VLDB\n",
1662 as->parms[0].items->data);
1671 } while (voltype == ROVOL);
1674 fprintf(STDERR, "Dump only information from VLDB\n\n");
1675 fprintf(STDOUT, "%s \n", entry.name); /* PostVolumeStats doesn't print name */
1679 PostVolumeStats(&entry);
1684 /*------------------------------------------------------------------------
1688 * Routine used to change the status of a single volume.
1691 * as : Ptr to parsed command line arguments.
1694 * 0 for a successful operation,
1695 * Otherwise, one of the ubik or VolServer error values.
1698 * Nothing interesting.
1702 *------------------------------------------------------------------------
1705 SetFields(struct cmd_syndesc *as, void *arock)
1707 struct nvldbentry entry;
1710 afs_int32 code, err;
1715 volid = vsu_GetVolumeID(as->parms[0].items->data, cstruct, &err); /* -id */
1718 PrintError("", err);
1720 fprintf(STDERR, "Unknown volume ID or name '%s'\n",
1721 as->parms[0].items->data);
1725 code = VLDB_GetEntryByID(volid, RWVOL, &entry);
1728 "Could not fetch the entry for volume number %lu from VLDB \n",
1729 (unsigned long)volid);
1732 MapHostToNetwork(&entry);
1734 GetServerAndPart(&entry, RWVOL, &aserver, &apart, &previdx);
1735 if (previdx == -1) {
1736 fprintf(STDERR, "Volume %s does not exist in VLDB\n\n",
1737 as->parms[0].items->data);
1741 init_volintInfo(&info);
1745 if (as->parms[1].items) {
1747 code = util_GetHumanInt32(as->parms[1].items->data, &info.maxquota);
1749 fprintf(STDERR, "invalid quota value\n");
1753 if (as->parms[2].items) {
1757 if (as->parms[3].items) {
1758 /* -clearVolUpCounter */
1761 code = UV_SetVolumeInfo(aserver, apart, volid, &info);
1764 "Could not update volume info fields for volume number %lu\n",
1765 (unsigned long)volid);
1769 /*------------------------------------------------------------------------
1773 * Brings a volume online.
1776 * as : Ptr to parsed command line arguments.
1779 * 0 for a successful operation,
1782 * Nothing interesting.
1786 *------------------------------------------------------------------------
1789 volOnline(struct cmd_syndesc *as, void *arock)
1792 afs_int32 partition;
1794 afs_int32 code, err = 0;
1796 server = GetServer(as->parms[0].items->data);
1798 fprintf(STDERR, "vos: server '%s' not found in host table\n",
1799 as->parms[0].items->data);
1803 partition = volutil_GetPartitionID(as->parms[1].items->data);
1804 if (partition < 0) {
1805 fprintf(STDERR, "vos: could not interpret partition name '%s'\n",
1806 as->parms[1].items->data);
1810 volid = vsu_GetVolumeID(as->parms[2].items->data, cstruct, &err); /* -id */
1813 PrintError("", err);
1815 fprintf(STDERR, "Unknown volume ID or name '%s'\n",
1816 as->parms[0].items->data);
1820 code = UV_SetVolume(server, partition, volid, ITOffline, 0 /*online */ ,
1823 fprintf(STDERR, "Failed to set volume. Code = %d\n", code);
1830 /*------------------------------------------------------------------------
1831 * PRIVATE volOffline
1834 * Brings a volume offline.
1837 * as : Ptr to parsed command line arguments.
1840 * 0 for a successful operation,
1843 * Nothing interesting.
1847 *------------------------------------------------------------------------
1850 volOffline(struct cmd_syndesc *as, void *arock)
1853 afs_int32 partition;
1855 afs_int32 code, err = 0;
1856 afs_int32 transflag, sleeptime, transdone;
1858 server = GetServer(as->parms[0].items->data);
1860 fprintf(STDERR, "vos: server '%s' not found in host table\n",
1861 as->parms[0].items->data);
1865 partition = volutil_GetPartitionID(as->parms[1].items->data);
1866 if (partition < 0) {
1867 fprintf(STDERR, "vos: could not interpret partition name '%s'\n",
1868 as->parms[1].items->data);
1872 volid = vsu_GetVolumeID(as->parms[2].items->data, cstruct, &err); /* -id */
1875 PrintError("", err);
1877 fprintf(STDERR, "Unknown volume ID or name '%s'\n",
1878 as->parms[0].items->data);
1882 transflag = (as->parms[4].items ? ITBusy : ITOffline);
1883 sleeptime = (as->parms[3].items ? atol(as->parms[3].items->data) : 0);
1884 transdone = (sleeptime ? 0 /*online */ : VTOutOfService);
1885 if (as->parms[4].items && !as->parms[3].items) {
1886 fprintf(STDERR, "-sleep option must be used with -busy flag\n");
1891 UV_SetVolume(server, partition, volid, transflag, transdone,
1894 fprintf(STDERR, "Failed to set volume. Code = %d\n", code);
1902 CreateVolume(struct cmd_syndesc *as, void *arock)
1906 afs_uint32 volid = 0, rovolid = 0, bkvolid = 0;
1907 afs_uint32 *arovolid;
1909 struct nvldbentry entry;
1914 arovolid = &rovolid;
1917 tserver = GetServer(as->parms[0].items->data);
1919 fprintf(STDERR, "vos: host '%s' not found in host table\n",
1920 as->parms[0].items->data);
1923 pnum = volutil_GetPartitionID(as->parms[1].items->data);
1925 fprintf(STDERR, "vos: could not interpret partition name '%s'\n",
1926 as->parms[1].items->data);
1929 if (!IsPartValid(pnum, tserver, &code)) { /*check for validity of the partition */
1931 PrintError("", code);
1934 "vos : partition %s does not exist on the server\n",
1935 as->parms[1].items->data);
1938 if (!ISNAMEVALID(as->parms[2].items->data)) {
1940 "vos: the name of the root volume %s exceeds the size limit of %d\n",
1941 as->parms[2].items->data, VOLSER_OLDMAXVOLNAME - 10);
1944 if (!VolNameOK(as->parms[2].items->data)) {
1946 "Illegal volume name %s, should not end in .readonly or .backup\n",
1947 as->parms[2].items->data);
1950 if (IsNumeric(as->parms[2].items->data)) {
1951 fprintf(STDERR, "Illegal volume name %s, should not be a number\n",
1952 as->parms[2].items->data);
1955 vcode = VLDB_GetEntryByName(as->parms[2].items->data, &entry);
1957 fprintf(STDERR, "Volume %s already exists\n",
1958 as->parms[2].items->data);
1959 PrintDiagnostics("create", code);
1963 if (as->parms[3].items) {
1964 code = util_GetHumanInt32(as->parms[3].items->data, "a);
1966 fprintf(STDERR, "vos: bad integer specified for quota.\n");
1971 if (as->parms[4].items) {
1972 if (!IsNumeric(as->parms[4].items->data)) {
1973 fprintf(STDERR, "vos: Given volume ID %s should be numeric.\n",
1974 as->parms[4].items->data);
1978 code = util_GetUInt32(as->parms[4].items->data, &volid);
1980 fprintf(STDERR, "vos: bad integer specified for volume ID.\n");
1985 if (as->parms[5].items) {
1986 if (!IsNumeric(as->parms[5].items->data)) {
1987 fprintf(STDERR, "vos: Given RO volume ID %s should be numeric.\n",
1988 as->parms[5].items->data);
1992 code = util_GetUInt32(as->parms[5].items->data, &rovolid);
1994 fprintf(STDERR, "vos: bad integer specified for volume ID.\n");
2004 UV_CreateVolume3(tserver, pnum, as->parms[2].items->data, quota, 0,
2005 0, 0, 0, &volid, arovolid, &bkvolid);
2007 PrintDiagnostics("create", code);
2010 MapPartIdIntoName(pnum, part);
2011 fprintf(STDOUT, "Volume %lu created on partition %s of %s\n",
2012 (unsigned long)volid, part, as->parms[0].items->data);
2019 DeleteAll(struct nvldbentry *entry)
2022 afs_int32 error, code, curserver, curpart;
2025 MapHostToNetwork(entry);
2027 for (i = 0; i < entry->nServers; i++) {
2028 curserver = entry->serverNumber[i];
2029 curpart = entry->serverPartition[i];
2030 if (entry->serverFlags[i] & ITSROVOL) {
2031 volid = entry->volumeId[ROVOL];
2033 volid = entry->volumeId[RWVOL];
2035 code = UV_DeleteVolume(curserver, curpart, volid);
2044 DeleteVolume(struct cmd_syndesc *as, void *arock)
2046 afs_int32 err, code = 0;
2047 afs_uint32 server = 0;
2048 afs_int32 partition = -1;
2053 if (as->parms[0].items) {
2054 server = GetServer(as->parms[0].items->data);
2056 fprintf(STDERR, "vos: server '%s' not found in host table\n",
2057 as->parms[0].items->data);
2062 if (as->parms[1].items) {
2063 partition = volutil_GetPartitionID(as->parms[1].items->data);
2064 if (partition < 0) {
2065 fprintf(STDERR, "vos: could not interpret partition name '%s'\n",
2066 as->parms[1].items->data);
2070 /* Check for validity of the partition */
2071 if (!IsPartValid(partition, server, &code)) {
2073 PrintError("", code);
2076 "vos : partition %s does not exist on the server\n",
2077 as->parms[1].items->data);
2083 volid = vsu_GetVolumeID(as->parms[2].items->data, cstruct, &err);
2085 fprintf(STDERR, "Can't find volume name '%s' in VLDB\n",
2086 as->parms[2].items->data);
2088 PrintError("", err);
2092 /* If the server or partition option are not complete, try to fill
2093 * them in from the VLDB entry.
2095 if ((partition == -1) || !server) {
2096 struct nvldbentry entry;
2098 code = VLDB_GetEntryByID(volid, -1, &entry);
2101 "Could not fetch the entry for volume %lu from VLDB\n",
2102 (unsigned long)volid);
2103 PrintError("", code);
2107 if (((volid == entry.volumeId[RWVOL]) && (entry.flags & RW_EXISTS))
2108 || ((volid == entry.volumeId[BACKVOL])
2109 && (entry.flags & BACK_EXISTS))) {
2110 idx = Lp_GetRwIndex(&entry);
2111 if ((idx == -1) || (server && (server != entry.serverNumber[idx]))
2112 || ((partition != -1)
2113 && (partition != entry.serverPartition[idx]))) {
2114 fprintf(STDERR, "VLDB: Volume '%s' no match\n",
2115 as->parms[2].items->data);
2118 } else if ((volid == entry.volumeId[ROVOL])
2119 && (entry.flags & RO_EXISTS)) {
2120 for (idx = -1, j = 0; j < entry.nServers; j++) {
2121 if (entry.serverFlags[j] != ITSROVOL)
2124 if (((server == 0) || (server == entry.serverNumber[j]))
2125 && ((partition == -1)
2126 || (partition == entry.serverPartition[j]))) {
2129 "VLDB: Volume '%s' matches more than one RO\n",
2130 as->parms[2].items->data);
2137 fprintf(STDERR, "VLDB: Volume '%s' no match\n",
2138 as->parms[2].items->data);
2142 fprintf(STDERR, "VLDB: Volume '%s' no match\n",
2143 as->parms[2].items->data);
2147 server = htonl(entry.serverNumber[idx]);
2148 partition = entry.serverPartition[idx];
2152 code = UV_DeleteVolume(server, partition, volid);
2154 PrintDiagnostics("remove", code);
2158 MapPartIdIntoName(partition, pname);
2159 fprintf(STDOUT, "Volume %lu on partition %s server %s deleted\n",
2160 (unsigned long)volid, pname, hostutil_GetNameByINet(server));
2164 #define TESTM 0 /* set for move space tests, clear for production */
2166 MoveVolume(struct cmd_syndesc *as, void *arock)
2170 afs_uint32 fromserver, toserver;
2171 afs_int32 frompart, topart;
2172 afs_int32 flags, code, err;
2173 char fromPartName[10], toPartName[10];
2175 struct diskPartition64 partition; /* for space check */
2178 volid = vsu_GetVolumeID(as->parms[0].items->data, cstruct, &err);
2181 PrintError("", err);
2183 fprintf(STDERR, "vos: can't find volume ID or name '%s'\n",
2184 as->parms[0].items->data);
2187 fromserver = GetServer(as->parms[1].items->data);
2188 if (fromserver == 0) {
2189 fprintf(STDERR, "vos: server '%s' not found in host table\n",
2190 as->parms[1].items->data);
2193 toserver = GetServer(as->parms[3].items->data);
2194 if (toserver == 0) {
2195 fprintf(STDERR, "vos: server '%s' not found in host table\n",
2196 as->parms[3].items->data);
2199 frompart = volutil_GetPartitionID(as->parms[2].items->data);
2201 fprintf(STDERR, "vos: could not interpret partition name '%s'\n",
2202 as->parms[2].items->data);
2205 if (!IsPartValid(frompart, fromserver, &code)) { /*check for validity of the partition */
2207 PrintError("", code);
2210 "vos : partition %s does not exist on the server\n",
2211 as->parms[2].items->data);
2214 topart = volutil_GetPartitionID(as->parms[4].items->data);
2216 fprintf(STDERR, "vos: could not interpret partition name '%s'\n",
2217 as->parms[4].items->data);
2220 if (!IsPartValid(topart, toserver, &code)) { /*check for validity of the partition */
2222 PrintError("", code);
2225 "vos : partition %s does not exist on the server\n",
2226 as->parms[4].items->data);
2231 if (as->parms[5].items) flags |= RV_NOCLONE;
2234 * check source partition for space to clone volume
2237 MapPartIdIntoName(topart, toPartName);
2238 MapPartIdIntoName(frompart, fromPartName);
2241 * check target partition for space to move volume
2244 code = UV_PartitionInfo64(toserver, toPartName, &partition);
2246 fprintf(STDERR, "vos: cannot access partition %s\n", toPartName);
2250 fprintf(STDOUT, "target partition %s free space %" AFS_INT64_FMT "\n", toPartName,
2253 p = (volintInfo *) 0;
2254 code = UV_ListOneVolume(fromserver, frompart, volid, &p);
2256 fprintf(STDERR, "vos:cannot access volume %lu\n",
2257 (unsigned long)volid);
2261 fprintf(STDOUT, "volume %lu size %d\n", (unsigned long)volid,
2263 if (partition.free <= p->size) {
2265 "vos: no space on target partition %s to move volume %lu\n",
2266 toPartName, (unsigned long)volid);
2273 fprintf(STDOUT, "size test - don't do move\n");
2277 /* successful move still not guaranteed but shoot for it */
2280 UV_MoveVolume2(volid, fromserver, frompart, toserver, topart, flags);
2282 PrintDiagnostics("move", code);
2285 MapPartIdIntoName(topart, toPartName);
2286 MapPartIdIntoName(frompart, fromPartName);
2287 fprintf(STDOUT, "Volume %lu moved from %s %s to %s %s \n",
2288 (unsigned long)volid, as->parms[1].items->data, fromPartName,
2289 as->parms[3].items->data, toPartName);
2295 CopyVolume(struct cmd_syndesc *as, void *arock)
2298 afs_uint32 fromserver, toserver;
2299 afs_int32 frompart, topart, code, err, flags;
2300 char fromPartName[10], toPartName[10], *tovolume;
2301 struct nvldbentry entry;
2302 struct diskPartition64 partition; /* for space check */
2305 volid = vsu_GetVolumeID(as->parms[0].items->data, cstruct, &err);
2308 PrintError("", err);
2310 fprintf(STDERR, "vos: can't find volume ID or name '%s'\n",
2311 as->parms[0].items->data);
2314 fromserver = GetServer(as->parms[1].items->data);
2315 if (fromserver == 0) {
2316 fprintf(STDERR, "vos: server '%s' not found in host table\n",
2317 as->parms[1].items->data);
2321 toserver = GetServer(as->parms[4].items->data);
2322 if (toserver == 0) {
2323 fprintf(STDERR, "vos: server '%s' not found in host table\n",
2324 as->parms[4].items->data);
2328 tovolume = as->parms[3].items->data;
2329 if (!ISNAMEVALID(tovolume)) {
2331 "vos: the name of the root volume %s exceeds the size limit of %d\n",
2332 tovolume, VOLSER_OLDMAXVOLNAME - 10);
2335 if (!VolNameOK(tovolume)) {
2337 "Illegal volume name %s, should not end in .readonly or .backup\n",
2341 if (IsNumeric(tovolume)) {
2342 fprintf(STDERR, "Illegal volume name %s, should not be a number\n",
2346 code = VLDB_GetEntryByName(tovolume, &entry);
2348 fprintf(STDERR, "Volume %s already exists\n", tovolume);
2349 PrintDiagnostics("copy", code);
2353 frompart = volutil_GetPartitionID(as->parms[2].items->data);
2355 fprintf(STDERR, "vos: could not interpret partition name '%s'\n",
2356 as->parms[2].items->data);
2359 if (!IsPartValid(frompart, fromserver, &code)) { /*check for validity of the partition */
2361 PrintError("", code);
2364 "vos : partition %s does not exist on the server\n",
2365 as->parms[2].items->data);
2369 topart = volutil_GetPartitionID(as->parms[5].items->data);
2371 fprintf(STDERR, "vos: could not interpret partition name '%s'\n",
2372 as->parms[5].items->data);
2375 if (!IsPartValid(topart, toserver, &code)) { /*check for validity of the partition */
2377 PrintError("", code);
2380 "vos : partition %s does not exist on the server\n",
2381 as->parms[5].items->data);
2386 if (as->parms[6].items) flags |= RV_OFFLINE;
2387 if (as->parms[7].items) flags |= RV_RDONLY;
2388 if (as->parms[8].items) flags |= RV_NOCLONE;
2390 MapPartIdIntoName(topart, toPartName);
2391 MapPartIdIntoName(frompart, fromPartName);
2394 * check target partition for space to move volume
2397 code = UV_PartitionInfo64(toserver, toPartName, &partition);
2399 fprintf(STDERR, "vos: cannot access partition %s\n", toPartName);
2403 fprintf(STDOUT, "target partition %s free space %" AFS_INT64_FMT "\n", toPartName,
2406 p = (volintInfo *) 0;
2407 code = UV_ListOneVolume(fromserver, frompart, volid, &p);
2409 fprintf(STDERR, "vos:cannot access volume %lu\n",
2410 (unsigned long)volid);
2414 if (partition.free <= p->size) {
2416 "vos: no space on target partition %s to copy volume %lu\n",
2417 toPartName, (unsigned long)volid);
2423 /* successful copy still not guaranteed but shoot for it */
2426 UV_CopyVolume2(volid, fromserver, frompart, tovolume, toserver,
2429 PrintDiagnostics("copy", code);
2432 MapPartIdIntoName(topart, toPartName);
2433 MapPartIdIntoName(frompart, fromPartName);
2434 fprintf(STDOUT, "Volume %lu copied from %s %s to %s on %s %s \n",
2435 (unsigned long)volid, as->parms[1].items->data, fromPartName,
2436 tovolume, as->parms[4].items->data, toPartName);
2443 ShadowVolume(struct cmd_syndesc *as, void *arock)
2445 afs_uint32 volid, tovolid;
2446 afs_uint32 fromserver, toserver;
2447 afs_int32 frompart, topart;
2448 afs_int32 code, err, flags;
2449 char fromPartName[10], toPartName[10], toVolName[32], *tovolume;
2450 struct diskPartition64 partition; /* for space check */
2453 p = (volintInfo *) 0;
2454 q = (volintInfo *) 0;
2456 volid = vsu_GetVolumeID(as->parms[0].items->data, cstruct, &err);
2459 PrintError("", err);
2461 fprintf(STDERR, "vos: can't find volume ID or name '%s'\n",
2462 as->parms[0].items->data);
2465 fromserver = GetServer(as->parms[1].items->data);
2466 if (fromserver == 0) {
2467 fprintf(STDERR, "vos: server '%s' not found in host table\n",
2468 as->parms[1].items->data);
2472 toserver = GetServer(as->parms[3].items->data);
2473 if (toserver == 0) {
2474 fprintf(STDERR, "vos: server '%s' not found in host table\n",
2475 as->parms[3].items->data);
2479 frompart = volutil_GetPartitionID(as->parms[2].items->data);
2481 fprintf(STDERR, "vos: could not interpret partition name '%s'\n",
2482 as->parms[2].items->data);
2485 if (!IsPartValid(frompart, fromserver, &code)) { /*check for validity of the partition */
2487 PrintError("", code);
2490 "vos : partition %s does not exist on the server\n",
2491 as->parms[2].items->data);
2495 topart = volutil_GetPartitionID(as->parms[4].items->data);
2497 fprintf(STDERR, "vos: could not interpret partition name '%s'\n",
2498 as->parms[4].items->data);
2501 if (!IsPartValid(topart, toserver, &code)) { /*check for validity of the partition */
2503 PrintError("", code);
2506 "vos : partition %s does not exist on the server\n",
2507 as->parms[4].items->data);
2511 if (as->parms[5].items) {
2512 tovolume = as->parms[5].items->data;
2513 if (!ISNAMEVALID(tovolume)) {
2515 "vos: the name of the root volume %s exceeds the size limit of %d\n",
2516 tovolume, VOLSER_OLDMAXVOLNAME - 10);
2519 if (!VolNameOK(tovolume)) {
2521 "Illegal volume name %s, should not end in .readonly or .backup\n",
2525 if (IsNumeric(tovolume)) {
2527 "Illegal volume name %s, should not be a number\n",
2532 /* use actual name of source volume */
2533 code = UV_ListOneVolume(fromserver, frompart, volid, &p);
2535 fprintf(STDERR, "vos:cannot access volume %lu\n",
2536 (unsigned long)volid);
2539 strcpy(toVolName, p->name);
2540 tovolume = toVolName;
2541 /* save p for size checks later */
2544 if (as->parms[6].items) {
2545 tovolid = vsu_GetVolumeID(as->parms[6].items->data, cstruct, &err);
2548 PrintError("", err);
2550 fprintf(STDERR, "vos: can't find volume ID or name '%s'\n",
2551 as->parms[6].items->data);
2557 tovolid = vsu_GetVolumeID(tovolume, cstruct, &err);
2560 PrintError("", err);
2562 fprintf(STDERR, "vos: can't find volume ID or name '%s'\n",
2571 if (as->parms[7].items) flags |= RV_OFFLINE;
2572 if (as->parms[8].items) flags |= RV_RDONLY;
2573 if (as->parms[9].items) flags |= RV_NOCLONE;
2574 if (as->parms[10].items) flags |= RV_CPINCR;
2576 MapPartIdIntoName(topart, toPartName);
2577 MapPartIdIntoName(frompart, fromPartName);
2580 * check target partition for space to move volume
2583 code = UV_PartitionInfo64(toserver, toPartName, &partition);
2585 fprintf(STDERR, "vos: cannot access partition %s\n", toPartName);
2589 fprintf(STDOUT, "target partition %s free space %" AFS_INT64_FMT "\n", toPartName,
2592 /* Don't do this again if we did it above */
2594 code = UV_ListOneVolume(fromserver, frompart, volid, &p);
2596 fprintf(STDERR, "vos:cannot access volume %lu\n",
2597 (unsigned long)volid);
2602 /* OK if this fails */
2603 code = UV_ListOneVolume(toserver, topart, tovolid, &q);
2605 /* Treat existing volume size as "free" */
2607 p->size = (q->size < p->size) ? p->size - q->size : 0;
2609 if (partition.free <= p->size) {
2611 "vos: no space on target partition %s to copy volume %lu\n",
2612 toPartName, (unsigned long)volid);
2620 /* successful copy still not guaranteed but shoot for it */
2623 UV_CopyVolume2(volid, fromserver, frompart, tovolume, toserver,
2624 topart, tovolid, flags);
2626 PrintDiagnostics("shadow", code);
2629 MapPartIdIntoName(topart, toPartName);
2630 MapPartIdIntoName(frompart, fromPartName);
2631 fprintf(STDOUT, "Volume %lu shadowed from %s %s to %s %s \n",
2632 (unsigned long)volid, as->parms[1].items->data, fromPartName,
2633 as->parms[3].items->data, toPartName);
2640 CloneVolume(struct cmd_syndesc *as, void *arock)
2642 afs_uint32 volid, cloneid;
2644 afs_int32 part, voltype;
2645 char partName[10], *volname;
2646 afs_int32 code, err, flags;
2647 struct nvldbentry entry;
2649 volid = vsu_GetVolumeID(as->parms[0].items->data, cstruct, &err);
2652 PrintError("", err);
2654 fprintf(STDERR, "vos: can't find volume ID or name '%s'\n",
2655 as->parms[0].items->data);
2659 if (as->parms[1].items || as->parms[2].items) {
2660 if (!as->parms[1].items || !as->parms[2].items) {
2662 "Must specify both -server and -partition options\n");
2665 server = GetServer(as->parms[1].items->data);
2667 fprintf(STDERR, "vos: server '%s' not found in host table\n",
2668 as->parms[1].items->data);
2671 part = volutil_GetPartitionID(as->parms[2].items->data);
2673 fprintf(STDERR, "vos: could not interpret partition name '%s'\n",
2674 as->parms[2].items->data);
2677 if (!IsPartValid(part, server, &code)) { /*check for validity of the partition */
2679 PrintError("", code);
2682 "vos : partition %s does not exist on the server\n",
2683 as->parms[2].items->data);
2687 code = GetVolumeInfo(volid, &server, &part, &voltype, &entry);
2693 if (as->parms[3].items) {
2694 volname = as->parms[3].items->data;
2695 if (strlen(volname) > VOLSER_OLDMAXVOLNAME - 1) {
2697 "vos: the name of the root volume %s exceeds the size limit of %d\n",
2698 volname, VOLSER_OLDMAXVOLNAME - 1);
2703 * In order that you be able to make clones of RO or BK, this
2704 * check must be omitted.
2706 if (!VolNameOK(volname)) {
2708 "Illegal volume name %s, should not end in .readonly or .backup\n",
2713 if (IsNumeric(volname)) {
2715 "Illegal volume name %s, should not be a number\n",
2722 if (as->parms[4].items) {
2723 cloneid = vsu_GetVolumeID(as->parms[4].items->data, cstruct, &err);
2726 PrintError("", err);
2728 fprintf(STDERR, "vos: can't find volume ID or name '%s'\n",
2729 as->parms[4].items->data);
2735 if (as->parms[5].items) flags |= RV_OFFLINE;
2736 if (as->parms[6].items) flags |= RV_RDONLY;
2740 UV_CloneVolume(server, part, volid, cloneid, volname, flags);
2743 PrintDiagnostics("clone", code);
2746 MapPartIdIntoName(part, partName);
2747 fprintf(STDOUT, "Created clone for volume %s\n",
2748 as->parms[0].items->data);
2755 BackupVolume(struct cmd_syndesc *as, void *arock)
2759 afs_int32 apart, vtype, code, err;
2760 struct nvldbentry entry;
2763 afs_uint32 buserver;
2764 afs_int32 bupart, butype;
2765 struct nvldbentry buentry;
2767 avolid = vsu_GetVolumeID(as->parms[0].items->data, cstruct, &err);
2770 PrintError("", err);
2772 fprintf(STDERR, "vos: can't find volume ID or name '%s'\n",
2773 as->parms[0].items->data);
2776 code = GetVolumeInfo(avolid, &aserver, &apart, &vtype, &entry);
2780 /* verify this is a readwrite volume */
2782 if (vtype != RWVOL) {
2783 fprintf(STDERR, "%s not RW volume\n", as->parms[0].items->data);
2787 /* is there a backup volume already? */
2789 if (entry.flags & BACK_EXISTS) {
2790 /* yep, where is it? */
2792 buvolid = entry.volumeId[BACKVOL];
2793 code = GetVolumeInfo(buvolid, &buserver, &bupart, &butype, &buentry);
2798 code = VLDB_IsSameAddrs(buserver, aserver, &err);
2801 "Failed to get info about server's %d address(es) from vlserver; aborting call!\n",
2807 "FATAL ERROR: backup volume %lu exists on server %lu\n",
2808 (unsigned long)buvolid, (unsigned long)buserver);
2813 /* nope, carry on */
2815 code = UV_BackupVolume(aserver, apart, avolid);
2818 PrintDiagnostics("backup", code);
2821 fprintf(STDOUT, "Created backup volume for %s \n",
2822 as->parms[0].items->data);
2827 ReleaseVolume(struct cmd_syndesc *as, void *arock)
2830 struct nvldbentry entry;
2833 afs_int32 apart, vtype, code, err;
2836 if (as->parms[1].items)
2838 avolid = vsu_GetVolumeID(as->parms[0].items->data, cstruct, &err);
2841 PrintError("", err);
2843 fprintf(STDERR, "vos: can't find volume '%s'\n",
2844 as->parms[0].items->data);
2847 code = GetVolumeInfo(avolid, &aserver, &apart, &vtype, &entry);
2851 if (vtype != RWVOL) {
2852 fprintf(STDERR, "%s not a RW volume\n", as->parms[0].items->data);
2856 if (!ISNAMEVALID(entry.name)) {
2858 "Volume name %s is too long, rename before releasing\n",
2863 code = UV_ReleaseVolume(avolid, aserver, apart, force);
2865 PrintDiagnostics("release", code);
2868 fprintf(STDOUT, "Released volume %s successfully\n",
2869 as->parms[0].items->data);
2874 DumpVolumeCmd(struct cmd_syndesc *as, void *arock)
2878 afs_int32 apart, voltype, fromdate = 0, code, err, i, flags;
2879 char filename[MAXPATHLEN];
2880 struct nvldbentry entry;
2882 rx_SetRxDeadTime(60 * 10);
2883 for (i = 0; i < MAXSERVERS; i++) {
2884 struct rx_connection *rxConn = ubik_GetRPCConn(cstruct, i);
2887 rx_SetConnDeadTime(rxConn, rx_connDeadTime);
2888 if (rxConn->service)
2889 rxConn->service->connDeadTime = rx_connDeadTime;
2892 avolid = vsu_GetVolumeID(as->parms[0].items->data, cstruct, &err);
2895 PrintError("", err);
2897 fprintf(STDERR, "vos: can't find volume '%s'\n",
2898 as->parms[0].items->data);
2902 if (as->parms[3].items || as->parms[4].items) {
2903 if (!as->parms[3].items || !as->parms[4].items) {
2905 "Must specify both -server and -partition options\n");
2908 aserver = GetServer(as->parms[3].items->data);
2910 fprintf(STDERR, "Invalid server name\n");
2913 apart = volutil_GetPartitionID(as->parms[4].items->data);
2915 fprintf(STDERR, "Invalid partition name\n");
2919 code = GetVolumeInfo(avolid, &aserver, &apart, &voltype, &entry);
2924 if (as->parms[1].items && strcmp(as->parms[1].items->data, "0")) {
2925 code = ktime_DateToInt32(as->parms[1].items->data, &fromdate);
2927 fprintf(STDERR, "vos: failed to parse date '%s' (error=%d))\n",
2928 as->parms[1].items->data, code);
2932 if (as->parms[2].items) {
2933 strcpy(filename, as->parms[2].items->data);
2935 strcpy(filename, "");
2938 flags = as->parms[6].items ? VOLDUMPV2_OMITDIRS : 0;
2940 if (as->parms[5].items) {
2942 UV_DumpClonedVolume(avolid, aserver, apart, fromdate,
2943 DumpFunction, filename, flags);
2946 UV_DumpVolume(avolid, aserver, apart, fromdate, DumpFunction,
2949 if ((code == RXGEN_OPCODE) && (as->parms[6].items)) {
2950 flags &= ~VOLDUMPV2_OMITDIRS;
2954 PrintDiagnostics("dump", code);
2957 if (strcmp(filename, ""))
2958 fprintf(STDERR, "Dumped volume %s in file %s\n",
2959 as->parms[0].items->data, filename);
2961 fprintf(STDERR, "Dumped volume %s in stdout \n",
2962 as->parms[0].items->data);
2976 RestoreVolumeCmd(struct cmd_syndesc *as, void *arock)
2978 afs_uint32 avolid, aparentid;
2980 afs_int32 apart, code, vcode, err;
2981 afs_int32 aoverwrite = ASK;
2982 afs_int32 acreation = 0, alastupdate = 0;
2983 int restoreflags = 0;
2984 int readonly = 0, offline = 0, voltype = RWVOL;
2985 char afilename[MAXPATHLEN], avolname[VOLSER_MAXVOLNAME + 1], apartName[10];
2986 char volname[VOLSER_MAXVOLNAME + 1];
2987 struct nvldbentry entry;
2990 if (as->parms[4].items) {
2991 avolid = vsu_GetVolumeID(as->parms[4].items->data, cstruct, &err);
2994 PrintError("", err);
2996 fprintf(STDERR, "vos: can't find volume '%s'\n",
2997 as->parms[4].items->data);
3003 if (as->parms[5].items) {
3004 if ((strcmp(as->parms[5].items->data, "a") == 0)
3005 || (strcmp(as->parms[5].items->data, "abort") == 0)) {
3007 } else if ((strcmp(as->parms[5].items->data, "f") == 0)
3008 || (strcmp(as->parms[5].items->data, "full") == 0)) {
3010 } else if ((strcmp(as->parms[5].items->data, "i") == 0)
3011 || (strcmp(as->parms[5].items->data, "inc") == 0)
3012 || (strcmp(as->parms[5].items->data, "increment") == 0)
3013 || (strcmp(as->parms[5].items->data, "incremental") == 0)) {
3016 fprintf(STDERR, "vos: %s is not a valid argument to -overwrite\n",
3017 as->parms[5].items->data);
3021 if (as->parms[6].items)
3023 if (as->parms[7].items) {
3028 if (as->parms[8].items) {
3029 if ((strcmp(as->parms[8].items->data, "d") == 0)
3030 || (strcmp(as->parms[8].items->data, "dump") == 0)) {
3031 acreation = TS_DUMP;
3032 } else if ((strcmp(as->parms[8].items->data, "k") == 0)
3033 || (strcmp(as->parms[8].items->data, "keep") == 0)) {
3034 acreation = TS_KEEP;
3035 } else if ((strcmp(as->parms[8].items->data, "n") == 0)
3036 || (strcmp(as->parms[8].items->data, "new") == 0)) {
3039 fprintf(STDERR, "vos: %s is not a valid argument to -creation\n",
3040 as->parms[8].items->data);
3045 if (as->parms[9].items) {
3046 if ((strcmp(as->parms[9].items->data, "d") == 0)
3047 || (strcmp(as->parms[9].items->data, "dump") == 0)) {
3048 alastupdate = TS_DUMP;
3049 } else if ((strcmp(as->parms[9].items->data, "k") == 0)
3050 || (strcmp(as->parms[9].items->data, "keep") == 0)) {
3051 alastupdate = TS_KEEP;
3052 } else if ((strcmp(as->parms[9].items->data, "n") == 0)
3053 || (strcmp(as->parms[9].items->data, "new") == 0)) {
3054 alastupdate = TS_NEW;
3056 fprintf(STDERR, "vos: %s is not a valid argument to -lastupdate\n",
3057 as->parms[9].items->data);
3062 aserver = GetServer(as->parms[0].items->data);
3064 fprintf(STDERR, "vos: server '%s' not found in host table\n",
3065 as->parms[0].items->data);
3068 apart = volutil_GetPartitionID(as->parms[1].items->data);
3070 fprintf(STDERR, "vos: could not interpret partition name '%s'\n",
3071 as->parms[1].items->data);
3074 if (!IsPartValid(apart, aserver, &code)) { /*check for validity of the partition */
3076 PrintError("", code);
3079 "vos : partition %s does not exist on the server\n",
3080 as->parms[1].items->data);
3083 strcpy(avolname, as->parms[2].items->data);
3084 if (!ISNAMEVALID(avolname)) {
3086 "vos: the name of the volume %s exceeds the size limit\n",
3090 if (!VolNameOK(avolname)) {
3092 "Illegal volume name %s, should not end in .readonly or .backup\n",
3096 if (as->parms[3].items) {
3097 strcpy(afilename, as->parms[3].items->data);
3098 if (!FileExists(afilename)) {
3099 fprintf(STDERR, "Can't access file %s\n", afilename);
3103 strcpy(afilename, "");
3106 /* Check if volume exists or not */
3108 vsu_ExtractName(volname, avolname);
3109 vcode = VLDB_GetEntryByName(volname, &entry);
3110 if (vcode) { /* no volume - do a full restore */
3111 restoreflags = RV_FULLRST;
3112 if ((aoverwrite == INC) || (aoverwrite == ABORT))
3114 "Volume does not exist; Will perform a full restore\n");
3117 else if ((!readonly && Lp_GetRwIndex(&entry) == -1) /* RW volume does not exist - do a full */
3118 ||(readonly && !Lp_ROMatch(0, 0, &entry))) { /* RO volume does not exist - do a full */
3119 restoreflags = RV_FULLRST;
3120 if ((aoverwrite == INC) || (aoverwrite == ABORT))
3122 "%s Volume does not exist; Will perform a full restore\n",
3123 readonly ? "RO" : "RW");
3126 avolid = entry.volumeId[voltype];
3127 } else if (entry.volumeId[voltype] != 0
3128 && entry.volumeId[voltype] != avolid) {
3129 avolid = entry.volumeId[voltype];
3131 aparentid = entry.volumeId[RWVOL];
3134 else { /* volume exists - do we do a full incremental or abort */
3136 afs_int32 Opart, Otype, vol_elsewhere = 0;
3137 struct nvldbentry Oentry;
3141 avolid = entry.volumeId[voltype];
3142 } else if (entry.volumeId[voltype] != 0
3143 && entry.volumeId[voltype] != avolid) {
3144 avolid = entry.volumeId[voltype];
3146 aparentid = entry.volumeId[RWVOL];
3148 /* A file name was specified - check if volume is on another partition */
3149 vcode = GetVolumeInfo(avolid, &Oserver, &Opart, &Otype, &Oentry);
3153 vcode = VLDB_IsSameAddrs(Oserver, aserver, &err);
3156 "Failed to get info about server's %d address(es) from vlserver (err=%d); aborting call!\n",
3160 if (!vcode || (Opart != apart))
3163 if (aoverwrite == ASK) {
3164 if (strcmp(afilename, "") == 0) { /* The file is from standard in */
3166 "Volume exists and no -overwrite option specified; Aborting restore command\n");
3170 /* Ask what to do */
3171 if (vol_elsewhere) {
3173 "The volume %s %u already exists on a different server/part\n",
3174 volname, entry.volumeId[voltype]);
3176 "Do you want to do a full restore or abort? [fa](a): ");
3179 "The volume %s %u already exists in the VLDB\n",
3180 volname, entry.volumeId[voltype]);
3182 "Do you want to do a full/incremental restore or abort? [fia](a): ");
3185 while (!(dc == EOF || dc == '\n'))
3186 dc = getchar(); /* goto end of line */
3187 if ((c == 'f') || (c == 'F'))
3189 else if ((c == 'i') || (c == 'I'))
3195 if (aoverwrite == ABORT) {
3196 fprintf(STDERR, "Volume exists; Aborting restore command\n");
3198 } else if (aoverwrite == FULL) {
3199 restoreflags = RV_FULLRST;
3201 "Volume exists; Will delete and perform full restore\n");
3202 } else if (aoverwrite == INC) {
3204 if (vol_elsewhere) {
3206 "%s volume %lu already exists on a different server/part; not allowed\n",
3207 readonly ? "RO" : "RW", (unsigned long)avolid);
3213 restoreflags |= RV_OFFLINE;
3215 restoreflags |= RV_RDONLY;
3217 switch (acreation) {
3219 restoreflags |= RV_CRDUMP;
3222 restoreflags |= RV_CRKEEP;
3225 restoreflags |= RV_CRNEW;
3228 if (aoverwrite == FULL)
3229 restoreflags |= RV_CRNEW;
3231 restoreflags |= RV_CRKEEP;
3234 switch (alastupdate) {
3236 restoreflags |= RV_LUDUMP;
3239 restoreflags |= RV_LUKEEP;
3242 restoreflags |= RV_LUNEW;
3245 restoreflags |= RV_LUDUMP;
3247 if (as->parms[10].items) {
3248 restoreflags |= RV_NODEL;
3253 UV_RestoreVolume2(aserver, apart, avolid, aparentid,
3254 avolname, restoreflags, WriteData, afilename);
3256 PrintDiagnostics("restore", code);
3259 MapPartIdIntoName(apart, apartName);
3262 * patch typo here - originally "parms[1]", should be "parms[0]"
3265 fprintf(STDOUT, "Restored volume %s on %s %s\n", avolname,
3266 as->parms[0].items->data, apartName);
3271 LockReleaseCmd(struct cmd_syndesc *as, void *arock)
3274 afs_int32 code, err;
3276 avolid = vsu_GetVolumeID(as->parms[0].items->data, cstruct, &err);
3279 PrintError("", err);
3281 fprintf(STDERR, "vos: can't find volume '%s'\n",
3282 as->parms[0].items->data);
3286 code = UV_LockRelease(avolid);
3288 PrintDiagnostics("unlock", code);
3291 fprintf(STDOUT, "Released lock on vldb entry for volume %s\n",
3292 as->parms[0].items->data);
3297 AddSite(struct cmd_syndesc *as, void *arock)
3301 afs_int32 apart, code, err, arovolid, valid = 0;
3302 char apartName[10], avolname[VOLSER_MAXVOLNAME + 1];
3304 vsu_ExtractName(avolname, as->parms[2].items->data);;
3305 avolid = vsu_GetVolumeID(avolname, cstruct, &err);
3308 PrintError("", err);
3310 fprintf(STDERR, "vos: can't find volume '%s'\n",
3311 as->parms[2].items->data);
3315 if (as->parms[3].items) {
3316 vsu_ExtractName(avolname, as->parms[3].items->data);
3317 arovolid = vsu_GetVolumeID(avolname, cstruct, &err);
3319 fprintf(STDERR, "vos: invalid ro volume id '%s'\n",
3320 as->parms[3].items->data);
3324 aserver = GetServer(as->parms[0].items->data);
3326 fprintf(STDERR, "vos: server '%s' not found in host table\n",
3327 as->parms[0].items->data);
3330 apart = volutil_GetPartitionID(as->parms[1].items->data);
3332 fprintf(STDERR, "vos: could not interpret partition name '%s'\n",
3333 as->parms[1].items->data);
3336 if (!IsPartValid(apart, aserver, &code)) { /*check for validity of the partition */
3338 PrintError("", code);
3341 "vos : partition %s does not exist on the server\n",
3342 as->parms[1].items->data);
3345 if (as->parms[4].items) {
3348 code = UV_AddSite2(aserver, apart, avolid, arovolid, valid);
3350 PrintDiagnostics("addsite", code);
3353 MapPartIdIntoName(apart, apartName);
3354 fprintf(STDOUT, "Added replication site %s %s for volume %s\n",
3355 as->parms[0].items->data, apartName, as->parms[2].items->data);
3360 RemoveSite(struct cmd_syndesc *as, void *arock)
3365 afs_int32 apart, code, err;
3366 char apartName[10], avolname[VOLSER_MAXVOLNAME + 1];
3368 vsu_ExtractName(avolname, as->parms[2].items->data);
3369 avolid = vsu_GetVolumeID(avolname, cstruct, &err);
3372 PrintError("", err);
3374 fprintf(STDERR, "vos: can't find volume '%s'\n",
3375 as->parms[2].items->data);
3378 aserver = GetServer(as->parms[0].items->data);
3380 fprintf(STDERR, "vos: server '%s' not found in host table\n",
3381 as->parms[0].items->data);
3384 apart = volutil_GetPartitionID(as->parms[1].items->data);
3386 fprintf(STDERR, "vos: could not interpret partition name '%s'\n",
3387 as->parms[1].items->data);
3391 *skip the partition validity check, since it is possible that the partition
3392 *has since been decomissioned.
3395 if (!IsPartValid(apart,aserver,&code)){
3396 if(code) PrintError("",code);
3397 else fprintf(STDERR,"vos : partition %s does not exist on the server\n",as->parms[1].items->data);
3401 code = UV_RemoveSite(aserver, apart, avolid);
3403 PrintDiagnostics("remsite", code);
3406 MapPartIdIntoName(apart, apartName);
3407 fprintf(STDOUT, "Removed replication site %s %s for volume %s\n",
3408 as->parms[0].items->data, apartName, as->parms[2].items->data);
3413 ChangeLocation(struct cmd_syndesc *as, void *arock)
3417 afs_int32 apart, code, err;
3420 avolid = vsu_GetVolumeID(as->parms[2].items->data, cstruct, &err);
3423 PrintError("", err);
3425 fprintf(STDERR, "vos: can't find volume '%s'\n",
3426 as->parms[2].items->data);
3429 aserver = GetServer(as->parms[0].items->data);
3431 fprintf(STDERR, "vos: server '%s' not found in host table\n",
3432 as->parms[0].items->data);
3435 apart = volutil_GetPartitionID(as->parms[1].items->data);
3437 fprintf(STDERR, "vos: could not interpret partition name '%s'\n",
3438 as->parms[1].items->data);
3441 if (!IsPartValid(apart, aserver, &code)) { /*check for validity of the partition */
3443 PrintError("", code);
3446 "vos : partition %s does not exist on the server\n",
3447 as->parms[1].items->data);
3450 code = UV_ChangeLocation(aserver, apart, avolid);
3452 PrintDiagnostics("addsite", code);
3455 MapPartIdIntoName(apart, apartName);
3456 fprintf(STDOUT, "Changed location to %s %s for volume %s\n",
3457 as->parms[0].items->data, apartName, as->parms[2].items->data);
3462 ListPartitions(struct cmd_syndesc *as, void *arock)
3466 struct partList dummyPartList;
3471 aserver = GetServer(as->parms[0].items->data);
3473 fprintf(STDERR, "vos: server '%s' not found in host table\n",
3474 as->parms[0].items->data);
3479 code = UV_ListPartitions(aserver, &dummyPartList, &cnt);
3481 PrintDiagnostics("listpart", code);
3485 fprintf(STDOUT, "The partitions on the server are:\n");
3486 for (i = 0; i < cnt; i++) {
3487 if (dummyPartList.partFlags[i] & PARTVALID) {
3488 memset(pname, 0, sizeof(pname));
3489 MapPartIdIntoName(dummyPartList.partId[i], pname);
3490 fprintf(STDOUT, " %10s ", pname);
3492 if ((i % 5) == 0 && (i != 0))
3493 fprintf(STDOUT, "\n");
3496 fprintf(STDOUT, "\n");
3497 fprintf(STDOUT, "Total: %d\n", total);
3503 CompareVolName(const void *p1, const void *p2)
3505 volintInfo *arg1, *arg2;
3507 arg1 = (volintInfo *) p1;
3508 arg2 = (volintInfo *) p2;
3509 return (strcmp(arg1->name, arg2->name));
3513 /*------------------------------------------------------------------------
3514 * PRIVATE XCompareVolName
3517 * Comparison routine for volume names coming from an extended
3521 * a_obj1P : Char ptr to first extended vol info object
3522 * a_obj1P : Char ptr to second extended vol info object
3525 * The value of strcmp() on the volume names within the passed
3526 * objects (i,e., -1, 0, or 1).
3529 * Passed to qsort() as the designated comparison routine.
3533 *------------------------------------------------------------------------*/
3536 XCompareVolName(const void *a_obj1P, const void *a_obj2P)
3537 { /*XCompareVolName */
3540 (((struct volintXInfo *)(a_obj1P))->name,
3541 ((struct volintXInfo *)(a_obj2P))->name));
3543 } /*XCompareVolName */
3546 CompareVolID(const void *p1, const void *p2)
3548 volintInfo *arg1, *arg2;
3550 arg1 = (volintInfo *) p1;
3551 arg2 = (volintInfo *) p2;
3552 if (arg1->volid == arg2->volid)
3554 if (arg1->volid > arg2->volid)
3561 /*------------------------------------------------------------------------
3562 * PRIVATE XCompareVolID
3565 * Comparison routine for volume IDs coming from an extended
3569 * a_obj1P : Char ptr to first extended vol info object
3570 * a_obj1P : Char ptr to second extended vol info object
3573 * The value of strcmp() on the volume names within the passed
3574 * objects (i,e., -1, 0, or 1).
3577 * Passed to qsort() as the designated comparison routine.
3581 *------------------------------------------------------------------------*/
3584 XCompareVolID(const void *a_obj1P, const void *a_obj2P)
3585 { /*XCompareVolID */
3587 afs_int32 id1, id2; /*Volume IDs we're comparing */
3589 id1 = ((struct volintXInfo *)(a_obj1P))->volid;
3590 id2 = ((struct volintXInfo *)(a_obj2P))->volid;
3598 } /*XCompareVolID */
3600 /*------------------------------------------------------------------------
3601 * PRIVATE ListVolumes
3604 * Routine used to list volumes, contacting the Volume Server
3605 * directly, bypassing the VLDB.
3608 * as : Ptr to parsed command line arguments.
3611 * 0 Successful operation
3614 * Nothing interesting.
3618 *------------------------------------------------------------------------*/
3621 ListVolumes(struct cmd_syndesc *as, void *arock)
3623 afs_int32 apart, int32list, fast;
3627 volintInfo *oldpntr = NULL;
3631 volintXInfo *xInfoP;
3632 volintXInfo *origxInfoP = NULL; /*Ptr to current/orig extended vol info */
3633 int wantExtendedInfo; /*Do we want extended vol info? */
3636 struct partList dummyPartList;
3644 if (as->parms[3].items)
3646 if (as->parms[4].items)
3650 if (as->parms[2].items)
3656 if (as->parms[5].items) {
3658 * We can't coexist with the fast flag.
3662 "vos: Can't use the -fast and -extended flags together\n");
3667 * We need to turn on ``long'' listings to get the full effect.